Skip to content

Commit 6326fbf

Browse files
catlog22claude
andcommitted
refactor: consolidate agent architecture and archive legacy templates
- Remove general-purpose agent in favor of universal-executor - Enhance workflow session completion with better state management - Improve context-gather with advanced filtering and validation - Archive legacy prompt templates for reference 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3670400 commit 6326fbf

File tree

4 files changed

+305
-73
lines changed

4 files changed

+305
-73
lines changed
File renamed without changes.

.claude/commands/workflow/session/complete.md

Lines changed: 107 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: complete
3-
description: Mark the active workflow session as complete and remove active flag
3+
description: Mark the active workflow session as complete, archive it with lessons learned, and remove active flag
44
examples:
55
- /workflow:session:complete
66
- /workflow:session:complete --detailed
@@ -9,7 +9,7 @@ examples:
99
# Complete Workflow Session (/workflow:session:complete)
1010

1111
## Overview
12-
Mark the currently active workflow session as complete, update its status, and remove the active flag marker.
12+
Mark the currently active workflow session as complete, analyze it for lessons learned, move it to the archive directory, and remove the active flag marker.
1313

1414
## Usage
1515
```bash
@@ -19,87 +19,129 @@ Mark the currently active workflow session as complete, update its status, and r
1919

2020
## Implementation Flow
2121

22-
### Step 1: Find Active Session
23-
```bash
24-
ls .workflow/.active-* 2>/dev/null | head -1
25-
```
22+
### Phase 1: Prepare for Archival (Minimal Manual Operations)
2623

27-
### Step 2: Get Session Name
28-
```bash
29-
basename .workflow/.active-WFS-session-name | sed 's/^\.active-//'
30-
```
24+
**Purpose**: Find active session, move to archive location, pass control to agent. Minimal operations.
3125

32-
### Step 3: Update Session Status
26+
#### Step 1.1: Find Active Session and Get Name
3327
```bash
34-
jq '.status = "completed"' .workflow/WFS-session/workflow-session.json > temp.json
35-
mv temp.json .workflow/WFS-session/workflow-session.json
36-
```
28+
# Find active marker
29+
bash(find .workflow/ -name ".active-*" -type f | head -1)
3730

38-
### Step 4: Add Completion Timestamp
39-
```bash
40-
jq '.completed_at = "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"' .workflow/WFS-session/workflow-session.json > temp.json
41-
mv temp.json .workflow/WFS-session/workflow-session.json
31+
# Extract session name from marker path
32+
bash(basename .workflow/.active-WFS-session-name | sed 's/^\.active-//')
4233
```
34+
**Output**: Session name `WFS-session-name`
4335

44-
### Step 5: Count Final Statistics
36+
#### Step 1.2: Move Session to Archive
4537
```bash
46-
find .workflow/WFS-session/.task/ -name "*.json" -type f 2>/dev/null | wc -l
47-
find .workflow/WFS-session/.summaries/ -name "*.md" -type f 2>/dev/null | wc -l
48-
```
38+
# Create archive directory if needed
39+
bash(mkdir -p .workflow/.archives/)
4940

50-
### Step 6: Remove Active Marker
51-
```bash
52-
rm .workflow/.active-WFS-session-name
41+
# Move session to archive location
42+
bash(mv .workflow/WFS-session-name .workflow/.archives/WFS-session-name)
5343
```
44+
**Result**: Session now at `.workflow/.archives/WFS-session-name/`
5445

55-
## Simple Bash Commands
46+
### Phase 2: Agent-Orchestrated Completion (All Data Processing)
5647

57-
### Basic Operations
58-
- **Find active session**: `find .workflow/ -name ".active-*" -type f`
59-
- **Get session name**: `basename marker | sed 's/^\.active-//'`
60-
- **Update status**: `jq '.status = "completed"' session.json > temp.json`
61-
- **Add timestamp**: `jq '.completed_at = "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"'`
62-
- **Count tasks**: `find .task/ -name "*.json" -type f | wc -l`
63-
- **Count completed**: `find .summaries/ -name "*.md" -type f 2>/dev/null | wc -l`
64-
- **Remove marker**: `rm .workflow/.active-session`
48+
**Purpose**: Agent analyzes archived session, generates metadata, updates manifest, and removes active marker.
6549

66-
### Completion Result
67-
```
68-
Session WFS-user-auth completed
69-
- Status: completed
70-
- Started: 2025-09-15T10:00:00Z
71-
- Completed: 2025-09-15T16:30:00Z
72-
- Duration: 6h 30m
73-
- Total tasks: 8
74-
- Completed tasks: 8
75-
- Success rate: 100%
50+
#### Agent Invocation
51+
52+
Invoke `universal-executor` agent to complete the archival process.
53+
54+
**Agent Task**:
7655
```
56+
Task(
57+
subagent_type="universal-executor",
58+
description="Complete session archival",
59+
prompt=`
60+
Complete workflow session archival. Session already moved to archive location.
61+
62+
## Context
63+
- Session: .workflow/.archives/WFS-session-name/
64+
- Active marker: .workflow/.active-WFS-session-name
65+
66+
## Tasks
67+
68+
1. **Extract session data** from workflow-session.json (session_id, description/topic, started_at/timestamp, completed_at, status)
69+
- If status != "completed", update it with timestamp
70+
71+
2. **Count files**: tasks (.task/*.json) and summaries (.summaries/*.md)
72+
73+
3. **Generate lessons**: Use gemini with ~/.claude/workflows/cli-templates/prompts/archive/analysis-simple.txt (fallback: analyze files directly)
74+
- Return: {successes, challenges, watch_patterns}
7775
78-
### Detailed Summary (--detailed flag)
76+
4. **Build archive entry**:
77+
- Calculate: duration_hours, success_rate, tags (3-5 keywords)
78+
- Construct complete JSON with session_id, description, archived_at, archive_path, metrics, tags, lessons
79+
80+
5. **Update manifest**: Initialize .workflow/.archives/manifest.json if needed, append entry
81+
82+
6. **Remove active marker**
83+
84+
7. **Return result**: {"status": "success", "session_id": "...", "archived_at": "...", "metrics": {...}, "lessons_summary": {...}}
85+
86+
## Error Handling
87+
- On failure: return {"status": "error", "task": "...", "message": "..."}
88+
- Do NOT remove marker if failed
89+
`
90+
)
7991
```
80-
Session Completion Summary:
81-
├── Session: WFS-user-auth
82-
├── Project: User authentication system
83-
├── Total time: 6h 30m
84-
├── Tasks completed: 8/8 (100%)
85-
├── Files generated: 24 files
86-
├── Summaries created: 8 summaries
87-
├── Status: All tasks completed successfully
88-
└── Location: .workflow/WFS-user-auth/
92+
93+
**Expected Output**:
94+
- Agent returns JSON result confirming successful archival
95+
- Display completion summary to user based on agent response
96+
97+
## Workflow Execution Strategy
98+
99+
### Two-Phase Approach (Optimized)
100+
101+
**Phase 1: Minimal Manual Setup** (2 simple operations)
102+
- Find active session and extract name
103+
- Move session to archive location
104+
- **No data extraction** - agent handles all data processing
105+
- **No counting** - agent does this from archive location
106+
- **Total**: 2 bash commands (find + move)
107+
108+
**Phase 2: Agent-Driven Completion** (1 agent invocation)
109+
- Extract all session data from archived location
110+
- Count tasks and summaries
111+
- Generate lessons learned analysis
112+
- Build complete archive metadata
113+
- Update manifest
114+
- Remove active marker
115+
- Return success/error result
116+
117+
## Quick Commands
118+
119+
```bash
120+
# Phase 1: Find and move
121+
bash(find .workflow/ -name ".active-*" -type f | head -1)
122+
bash(basename .workflow/.active-WFS-session-name | sed 's/^\.active-//')
123+
bash(mkdir -p .workflow/.archives/)
124+
bash(mv .workflow/WFS-session-name .workflow/.archives/WFS-session-name)
125+
126+
# Phase 2: Agent completes archival
127+
Task(subagent_type="universal-executor", description="Complete session archival", prompt=`...`)
89128
```
90129

91-
### Error Handling
130+
## Archive Query Commands
131+
132+
After archival, you can query the manifest:
133+
92134
```bash
93-
# No active session
94-
find .workflow/ -name ".active-*" -type f 2>/dev/null || echo "No active session found"
135+
# List all archived sessions
136+
jq '.archives[].session_id' .workflow/.archives/manifest.json
137+
138+
# Find sessions by keyword
139+
jq '.archives[] | select(.description | test("auth"; "i"))' .workflow/.archives/manifest.json
140+
141+
# Get specific session details
142+
jq '.archives[] | select(.session_id == "WFS-user-auth")' .workflow/.archives/manifest.json
95143

96-
# Incomplete tasks
97-
task_count=$(find .task/ -name "*.json" -type f | wc -l)
98-
summary_count=$(find .summaries/ -name "*.md" -type f 2>/dev/null | wc -l)
99-
test $task_count -eq $summary_count || echo "Warning: Not all tasks completed"
144+
# List all watch patterns across sessions
145+
jq '.archives[].lessons.watch_patterns[]' .workflow/.archives/manifest.json
100146
```
101147

102-
## Related Commands
103-
- `/workflow:session:list` - View all sessions including completed
104-
- `/workflow:session:start` - Start new session
105-
- `/workflow:status` - Check completion status before completing

.claude/commands/workflow/tools/context-gather.md

Lines changed: 115 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,19 @@ Execute complete context-search-agent workflow for implementation planning:
7676
3. **Analysis**: Extract keywords, determine scope, classify complexity
7777
7878
### Phase 2: Multi-Source Context Discovery
79-
Execute all 3 discovery tracks:
80-
- **Track 1**: Reference documentation (CLAUDE.md, architecture docs)
81-
- **Track 2**: Web examples (use Exa MCP for unfamiliar tech/APIs)
82-
- **Track 3**: Codebase analysis (5-layer discovery: files, content, patterns, deps, config/tests)
79+
Execute all 4 discovery tracks:
80+
- **Track 1**: Historical archive analysis (query manifest.json for lessons learned)
81+
- **Track 2**: Reference documentation (CLAUDE.md, architecture docs)
82+
- **Track 3**: Web examples (use Exa MCP for unfamiliar tech/APIs)
83+
- **Track 4**: Codebase analysis (5-layer discovery: files, content, patterns, deps, config/tests)
8384
8485
### Phase 3: Synthesis, Assessment & Packaging
8586
1. Apply relevance scoring and build dependency graph
86-
2. Synthesize 3-source data (docs > code > web)
87+
2. Synthesize 4-source data (archive > docs > code > web)
8788
3. Integrate brainstorm artifacts (if .brainstorming/ exists, read content)
8889
4. Perform conflict detection with risk assessment
89-
5. Generate and validate context-package.json
90+
5. **Inject historical conflicts** from archive analysis into conflict_detection
91+
6. Generate and validate context-package.json
9092
9193
## Output Requirements
9294
Complete context-package.json with:
@@ -95,7 +97,7 @@ Complete context-package.json with:
9597
- **assets**: {documentation[], source_code[], config[], tests[]} with relevance scores
9698
- **dependencies**: {internal[], external[]} with dependency graph
9799
- **brainstorm_artifacts**: {guidance_specification, role_analyses[], synthesis_output} with content
98-
- **conflict_detection**: {risk_level, risk_factors, affected_modules[], mitigation_strategy}
100+
- **conflict_detection**: {risk_level, risk_factors, affected_modules[], mitigation_strategy, historical_conflicts[]}
99101
100102
## Quality Validation
101103
Before completion verify:
@@ -141,7 +143,112 @@ Refer to `context-search-agent.md` Phase 3.7 for complete `context-package.json`
141143
- **assets**: Categorized files with relevance scores (documentation, source_code, config, tests)
142144
- **dependencies**: Internal and external dependency graphs
143145
- **brainstorm_artifacts**: Brainstorm documents with full content (if exists)
144-
- **conflict_detection**: Risk assessment with mitigation strategies
146+
- **conflict_detection**: Risk assessment with mitigation strategies and historical conflicts
147+
148+
## Historical Archive Analysis
149+
150+
### Track 1: Query Archive Manifest
151+
152+
The context-search-agent MUST perform historical archive analysis as Track 1 in Phase 2:
153+
154+
**Step 1: Check for Archive Manifest**
155+
```bash
156+
# Check if archive manifest exists
157+
if [[ -f .workflow/.archives/manifest.json ]]; then
158+
# Manifest available for querying
159+
fi
160+
```
161+
162+
**Step 2: Extract Task Keywords**
163+
```javascript
164+
// From current task description, extract key entities and operations
165+
const keywords = extractKeywords(task_description);
166+
// Examples: ["User", "model", "authentication", "JWT", "reporting"]
167+
```
168+
169+
**Step 3: Search Archive for Relevant Sessions**
170+
```javascript
171+
// Query manifest for sessions with matching tags or descriptions
172+
const relevantArchives = archives.filter(archive => {
173+
return archive.tags.some(tag => keywords.includes(tag)) ||
174+
keywords.some(kw => archive.description.toLowerCase().includes(kw.toLowerCase()));
175+
});
176+
```
177+
178+
**Step 4: Extract Watch Patterns**
179+
```javascript
180+
// For each relevant archive, check watch_patterns for applicability
181+
const historicalConflicts = [];
182+
183+
relevantArchives.forEach(archive => {
184+
archive.lessons.watch_patterns?.forEach(pattern => {
185+
// Check if pattern trigger matches current task
186+
if (isPatternRelevant(pattern.pattern, task_description)) {
187+
historicalConflicts.push({
188+
source_session: archive.session_id,
189+
pattern: pattern.pattern,
190+
action: pattern.action,
191+
files_to_check: pattern.related_files,
192+
archived_at: archive.archived_at
193+
});
194+
}
195+
});
196+
});
197+
```
198+
199+
**Step 5: Inject into Context Package**
200+
```json
201+
{
202+
"conflict_detection": {
203+
"risk_level": "medium",
204+
"risk_factors": ["..."],
205+
"affected_modules": ["..."],
206+
"mitigation_strategy": "...",
207+
"historical_conflicts": [
208+
{
209+
"source_session": "WFS-auth-feature",
210+
"pattern": "When modifying User model",
211+
"action": "Check reporting-service and auditing-service dependencies",
212+
"files_to_check": ["src/models/User.ts", "src/services/reporting.ts"],
213+
"archived_at": "2025-09-16T09:00:00Z"
214+
}
215+
]
216+
}
217+
}
218+
```
219+
220+
### Risk Level Escalation
221+
222+
If `historical_conflicts` array is not empty, minimum risk level should be "medium":
223+
224+
```javascript
225+
if (historicalConflicts.length > 0 && currentRisk === "low") {
226+
conflict_detection.risk_level = "medium";
227+
conflict_detection.risk_factors.push(
228+
`${historicalConflicts.length} historical conflict pattern(s) detected from past sessions`
229+
);
230+
}
231+
```
232+
233+
### Archive Query Algorithm
234+
235+
```markdown
236+
1. IF .workflow/.archives/manifest.json does NOT exist → Skip Track 1, continue to Track 2
237+
2. IF manifest exists:
238+
a. Load manifest.json
239+
b. Extract keywords from task_description (nouns, verbs, technical terms)
240+
c. Filter archives where:
241+
- ANY tag matches keywords (case-insensitive) OR
242+
- description contains keywords (case-insensitive substring match)
243+
d. For each relevant archive:
244+
- Read lessons.watch_patterns array
245+
- Check if pattern.pattern keywords overlap with task_description
246+
- If relevant: Add to historical_conflicts array
247+
e. IF historical_conflicts.length > 0:
248+
- Set risk_level = max(current_risk, "medium")
249+
- Add to risk_factors
250+
3. Continue to Track 2 (reference documentation)
251+
```
145252
146253
## Usage Examples
147254

0 commit comments

Comments
 (0)