claude-symphony 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -12
- package/assets/claude_symphony.webp +0 -0
- package/assets/claude_symphony_ascii.txt +8 -0
- package/bin/create.js +80 -69
- package/package.json +3 -2
- package/template/.claude/commands/benchmark.md +32 -32
- package/template/.claude/commands/brainstorm.md +33 -33
- package/template/.claude/commands/checkpoint.md +42 -42
- package/template/.claude/commands/codex.md +52 -52
- package/template/.claude/commands/collaborate.md +47 -47
- package/template/.claude/commands/context.md +77 -77
- package/template/.claude/commands/deploy.md +50 -50
- package/template/.claude/commands/fork.md +46 -46
- package/template/.claude/commands/gemini.md +43 -43
- package/template/.claude/commands/handoff.md +42 -42
- package/template/.claude/commands/implement.md +42 -42
- package/template/.claude/commands/init-project.md +25 -25
- package/template/.claude/commands/next.md +67 -67
- package/template/.claude/commands/planning.md +38 -38
- package/template/.claude/commands/qa.md +47 -47
- package/template/.claude/commands/refactor.md +50 -50
- package/template/.claude/commands/research.md +31 -31
- package/template/.claude/commands/restore.md +53 -53
- package/template/.claude/commands/run-stage.md +45 -45
- package/template/.claude/commands/stages.md +49 -49
- package/template/.claude/commands/status.md +41 -41
- package/template/.claude/commands/tasks.md +33 -33
- package/template/.claude/commands/test.md +45 -45
- package/template/.claude/commands/ui-ux.md +31 -31
- package/template/.claude/commands/validate.md +81 -81
- package/template/.claude/hooks/ai-selector.sh +39 -39
- package/template/.claude/hooks/auto-checkpoint.sh +30 -30
- package/template/.claude/hooks/output-validator.sh +45 -45
- package/template/.claude/hooks/post-stage.sh +28 -28
- package/template/.claude/hooks/pre-stage.sh +47 -47
- package/template/.claude/hooks/session-start.sh +27 -27
- package/template/.claude/hooks/statusline.sh +24 -24
- package/template/.claude/hooks/stop.sh +26 -26
- package/template/.claude/settings.json +32 -32
- package/template/.claude/skills/ai-collaboration/README.md +31 -31
- package/template/.claude/skills/ai-collaboration/debate.md +66 -66
- package/template/.claude/skills/ai-collaboration/parallel.md +34 -34
- package/template/.claude/skills/ai-collaboration/prompts/CLAUDE.md +59 -63
- package/template/.claude/skills/auto-checkpoint/README.md +46 -46
- package/template/.claude/skills/auto-checkpoint/prompts/CLAUDE.md +68 -72
- package/template/.claude/skills/auto-checkpoint/rollback.md +95 -95
- package/template/.claude/skills/auto-checkpoint/trigger.md +37 -37
- package/template/.claude/skills/context-compression/README.md +69 -69
- package/template/.claude/skills/context-compression/analyze.md +74 -74
- package/template/.claude/skills/context-compression/compress.md +103 -103
- package/template/.claude/skills/context-compression/prompts/compression.md +78 -78
- package/template/.claude/skills/output-validator/README.md +33 -33
- package/template/.claude/skills/output-validator/prompts/CLAUDE.md +74 -78
- package/template/.claude/skills/output-validator/validate.md +76 -76
- package/template/.claude/skills/smart-handoff/README.md +35 -35
- package/template/.claude/skills/smart-handoff/extract.md +42 -42
- package/template/.claude/skills/smart-handoff/prompts/CLAUDE.md +52 -54
- package/template/.claude/skills/smart-handoff/summarize.md +55 -55
- package/template/.claude/skills/stage-transition/README.md +50 -50
- package/template/.claude/skills/stage-transition/handoff-gen.md +89 -89
- package/template/.claude/skills/stage-transition/prompts/transition.md +74 -74
- package/template/.claude/skills/stage-transition/validate.md +41 -41
- package/template/CLAUDE.md +334 -335
- package/template/config/ai_benchmarking.yaml +22 -22
- package/template/config/ai_collaboration.yaml +18 -18
- package/template/config/ai_logging.yaml +50 -50
- package/template/config/auto_checkpoint.yaml +32 -32
- package/template/config/context.yaml +20 -20
- package/template/config/git.yaml +51 -51
- package/template/config/handoff_intelligence.yaml +23 -23
- package/template/config/mcp_fallbacks.yaml +71 -71
- package/template/config/memory_integration.yaml +23 -23
- package/template/config/model_enforcement.yaml +53 -53
- package/template/config/models.yaml +24 -24
- package/template/config/output_validation.yaml +44 -44
- package/template/config/pipeline.yaml +25 -25
- package/template/config/pipeline_forking.yaml +40 -40
- package/template/config/qa_logging.yaml +67 -67
- package/template/config/smart_rollback.yaml +48 -48
- package/template/config/stage_personas.yaml +154 -154
- package/template/config/workflow.yaml +16 -16
- package/template/scripts/ai-benchmark.sh +41 -41
- package/template/scripts/codex-wrapper.sh +32 -32
- package/template/scripts/context-manager.sh +136 -136
- package/template/scripts/create-checkpoint.sh +34 -34
- package/template/scripts/gemini-wrapper.sh +31 -31
- package/template/scripts/init-project.sh +40 -40
- package/template/scripts/list-stages.sh +30 -30
- package/template/scripts/next-stage.sh +67 -67
- package/template/scripts/output-validate.sh +2 -2
- package/template/scripts/pipeline-fork.sh +68 -68
- package/template/scripts/pre-run-check.sh +84 -84
- package/template/scripts/restore-checkpoint.sh +50 -50
- package/template/scripts/run-stage.sh +44 -44
- package/template/scripts/show-status.sh +30 -30
- package/template/scripts/smart-handoff.sh +70 -70
- package/template/stages/01-brainstorm/CLAUDE.md +70 -74
- package/template/stages/01-brainstorm/README.md +54 -54
- package/template/stages/01-brainstorm/config.yaml +18 -18
- package/template/stages/01-brainstorm/prompts/collaboration.md +24 -24
- package/template/stages/01-brainstorm/prompts/ideation.md +41 -41
- package/template/stages/01-brainstorm/prompts/persona.md +50 -50
- package/template/stages/01-brainstorm/prompts/requirements.md +55 -55
- package/template/stages/01-brainstorm/prompts/validation.md +28 -28
- package/template/stages/01-brainstorm/templates/ideas.md +47 -47
- package/template/stages/01-brainstorm/templates/requirements_analysis.md +61 -61
- package/template/stages/02-research/CLAUDE.md +72 -76
- package/template/stages/02-research/config.yaml +12 -12
- package/template/stages/02-research/prompts/collaboration.md +29 -29
- package/template/stages/02-research/prompts/feasibility.md +38 -38
- package/template/stages/02-research/prompts/market_analysis.md +29 -29
- package/template/stages/02-research/prompts/tech_stack.md +34 -34
- package/template/stages/02-research/prompts/validation.md +29 -29
- package/template/stages/03-planning/CLAUDE.md +88 -92
- package/template/stages/03-planning/config.yaml +10 -10
- package/template/stages/03-planning/prompts/architecture.md +43 -43
- package/template/stages/03-planning/prompts/collaboration.md +34 -34
- package/template/stages/03-planning/prompts/validation.md +34 -34
- package/template/stages/04-ui-ux/CLAUDE.md +68 -72
- package/template/stages/04-ui-ux/config.yaml +5 -5
- package/template/stages/04-ui-ux/prompts/collaboration.md +35 -35
- package/template/stages/04-ui-ux/prompts/validation.md +30 -30
- package/template/stages/05-task-management/CLAUDE.md +81 -85
- package/template/stages/05-task-management/config.yaml +17 -17
- package/template/stages/05-task-management/prompts/collaboration.md +30 -30
- package/template/stages/05-task-management/prompts/validation.md +33 -33
- package/template/stages/05-task-management/templates/notion_integration.md +70 -70
- package/template/stages/05-task-management/templates/parallel_groups.yaml +64 -64
- package/template/stages/05-task-management/templates/task_schema.yaml +33 -33
- package/template/stages/06-implementation/CLAUDE.md +117 -121
- package/template/stages/06-implementation/config.yaml +10 -10
- package/template/stages/06-implementation/prompts/collaboration.md +29 -29
- package/template/stages/06-implementation/prompts/validation.md +36 -36
- package/template/stages/07-refactoring/CLAUDE.md +120 -124
- package/template/stages/07-refactoring/config.yaml +11 -11
- package/template/stages/07-refactoring/prompts/collaboration.md +36 -36
- package/template/stages/07-refactoring/prompts/validation.md +40 -40
- package/template/stages/08-qa/CLAUDE.md +80 -84
- package/template/stages/08-qa/config.yaml +7 -7
- package/template/stages/08-qa/prompts/collaboration.md +34 -34
- package/template/stages/08-qa/prompts/validation.md +41 -41
- package/template/stages/09-testing/CLAUDE.md +86 -90
- package/template/stages/09-testing/config.yaml +10 -10
- package/template/stages/09-testing/prompts/collaboration.md +38 -38
- package/template/stages/09-testing/prompts/validation.md +41 -41
- package/template/stages/10-deployment/CLAUDE.md +86 -90
- package/template/stages/10-deployment/config.yaml +11 -11
- package/template/stages/10-deployment/prompts/collaboration.md +37 -37
- package/template/stages/10-deployment/prompts/validation.md +54 -54
- package/template/stages/10-deployment/templates/github-actions-cd.yaml +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
-
# context-manager.sh -
|
|
2
|
+
# context-manager.sh - Context state management
|
|
3
3
|
# claude-symphony workflow pipeline
|
|
4
4
|
|
|
5
5
|
set -e
|
|
@@ -9,7 +9,7 @@ PROGRESS_FILE="$PROJECT_ROOT/state/progress.json"
|
|
|
9
9
|
CONTEXT_DIR="$PROJECT_ROOT/state/context"
|
|
10
10
|
SETTINGS_FILE="$PROJECT_ROOT/.claude/settings.json"
|
|
11
11
|
|
|
12
|
-
#
|
|
12
|
+
# Color definitions
|
|
13
13
|
RED='\033[0;31m'
|
|
14
14
|
GREEN='\033[0;32m'
|
|
15
15
|
YELLOW='\033[1;33m'
|
|
@@ -19,20 +19,20 @@ WHITE='\033[1;37m'
|
|
|
19
19
|
GRAY='\033[0;90m'
|
|
20
20
|
NC='\033[0m' # No Color
|
|
21
21
|
|
|
22
|
-
#
|
|
22
|
+
# Defaults
|
|
23
23
|
WARNING_THRESHOLD=50000
|
|
24
24
|
LIMIT_THRESHOLD=80000
|
|
25
25
|
|
|
26
|
-
#
|
|
26
|
+
# Load thresholds from settings file
|
|
27
27
|
if [ -f "$SETTINGS_FILE" ] && command -v jq &> /dev/null; then
|
|
28
28
|
WARNING_THRESHOLD=$(jq -r '.context.warning_threshold // 50000' "$SETTINGS_FILE")
|
|
29
29
|
LIMIT_THRESHOLD=$(jq -r '.context.limit_threshold // 80000' "$SETTINGS_FILE")
|
|
30
30
|
fi
|
|
31
31
|
|
|
32
|
-
#
|
|
32
|
+
# Create context directory
|
|
33
33
|
mkdir -p "$CONTEXT_DIR"
|
|
34
34
|
|
|
35
|
-
#
|
|
35
|
+
# Option handling
|
|
36
36
|
ACTION="status"
|
|
37
37
|
DESCRIPTION=""
|
|
38
38
|
RESTORE_FILE=""
|
|
@@ -54,7 +54,7 @@ while [[ "$#" -gt 0 ]]; do
|
|
|
54
54
|
shift 2>/dev/null || true
|
|
55
55
|
done
|
|
56
56
|
|
|
57
|
-
#
|
|
57
|
+
# Get current stage
|
|
58
58
|
get_current_stage() {
|
|
59
59
|
if [ -f "$PROGRESS_FILE" ] && command -v jq &> /dev/null; then
|
|
60
60
|
jq -r '.current_stage // "none"' "$PROGRESS_FILE"
|
|
@@ -63,14 +63,14 @@ get_current_stage() {
|
|
|
63
63
|
fi
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
#
|
|
66
|
+
# Estimate tokens (simple estimation)
|
|
67
67
|
estimate_tokens() {
|
|
68
|
-
#
|
|
69
|
-
#
|
|
68
|
+
# In practice, conversation logs should be analyzed, but this is a placeholder
|
|
69
|
+
# Actual implementation would reference Claude API or log files
|
|
70
70
|
echo "45000" # placeholder
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
#
|
|
73
|
+
# Generate progress bar
|
|
74
74
|
progress_bar() {
|
|
75
75
|
local percent=$1
|
|
76
76
|
local width=20
|
|
@@ -82,20 +82,20 @@ progress_bar() {
|
|
|
82
82
|
printf "]"
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
#
|
|
85
|
+
# Show status
|
|
86
86
|
show_status() {
|
|
87
87
|
local CURRENT_STAGE=$(get_current_stage)
|
|
88
88
|
local ESTIMATED_TOKENS=$(estimate_tokens)
|
|
89
89
|
local PERCENT=$((ESTIMATED_TOKENS * 100 / LIMIT_THRESHOLD))
|
|
90
90
|
|
|
91
|
-
#
|
|
92
|
-
local STATUS_TEXT="
|
|
91
|
+
# Determine status
|
|
92
|
+
local STATUS_TEXT="Normal"
|
|
93
93
|
local STATUS_COLOR=$GREEN
|
|
94
94
|
if [ "$ESTIMATED_TOKENS" -ge "$LIMIT_THRESHOLD" ]; then
|
|
95
|
-
STATUS_TEXT="
|
|
95
|
+
STATUS_TEXT="Limit Exceeded"
|
|
96
96
|
STATUS_COLOR=$RED
|
|
97
97
|
elif [ "$ESTIMATED_TOKENS" -ge "$WARNING_THRESHOLD" ]; then
|
|
98
|
-
STATUS_TEXT="
|
|
98
|
+
STATUS_TEXT="Warning"
|
|
99
99
|
STATUS_COLOR=$YELLOW
|
|
100
100
|
fi
|
|
101
101
|
|
|
@@ -113,25 +113,25 @@ show_status() {
|
|
|
113
113
|
fi
|
|
114
114
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
115
115
|
echo ""
|
|
116
|
-
echo -e "
|
|
117
|
-
echo -e "
|
|
116
|
+
echo -e "Token usage: ${CYAN}~${ESTIMATED_TOKENS}${NC} / ${LIMIT_THRESHOLD}"
|
|
117
|
+
echo -e "Status: $(progress_bar $PERCENT) ${PERCENT}% [${STATUS_COLOR}${STATUS_TEXT}${NC}]"
|
|
118
118
|
echo ""
|
|
119
|
-
echo "
|
|
119
|
+
echo "Thresholds:"
|
|
120
120
|
if [ "$ESTIMATED_TOKENS" -ge "$WARNING_THRESHOLD" ]; then
|
|
121
|
-
echo -e "•
|
|
121
|
+
echo -e "• Warning (${WARNING_THRESHOLD}): ${YELLOW}Exceeded${NC}"
|
|
122
122
|
else
|
|
123
|
-
echo -e "•
|
|
123
|
+
echo -e "• Warning (${WARNING_THRESHOLD}): Within limit"
|
|
124
124
|
fi
|
|
125
|
-
echo -e "•
|
|
125
|
+
echo -e "• Limit (${LIMIT_THRESHOLD}): ~$((LIMIT_THRESHOLD - ESTIMATED_TOKENS)) tokens remaining"
|
|
126
126
|
echo ""
|
|
127
|
-
echo -e "
|
|
127
|
+
echo -e "Current stage: ${CYAN}$CURRENT_STAGE${NC}"
|
|
128
128
|
|
|
129
|
-
#
|
|
129
|
+
# List saved snapshots
|
|
130
130
|
if [ -d "$CONTEXT_DIR" ]; then
|
|
131
131
|
SNAPSHOTS=$(ls -1 "$CONTEXT_DIR"/state-*.md 2>/dev/null | wc -l | tr -d ' ')
|
|
132
132
|
if [ "$SNAPSHOTS" -gt 0 ]; then
|
|
133
133
|
echo ""
|
|
134
|
-
echo "[
|
|
134
|
+
echo "[Saved Snapshots]"
|
|
135
135
|
ls -1t "$CONTEXT_DIR"/state-*.md 2>/dev/null | head -3 | while read -r f; do
|
|
136
136
|
echo "• $(basename "$f")"
|
|
137
137
|
done
|
|
@@ -140,19 +140,19 @@ show_status() {
|
|
|
140
140
|
|
|
141
141
|
echo ""
|
|
142
142
|
|
|
143
|
-
#
|
|
143
|
+
# Recommended actions when warning
|
|
144
144
|
if [ "$ESTIMATED_TOKENS" -ge "$WARNING_THRESHOLD" ]; then
|
|
145
|
-
echo -e "${YELLOW}⚠️
|
|
145
|
+
echo -e "${YELLOW}⚠️ Warning threshold exceeded!${NC}"
|
|
146
146
|
echo ""
|
|
147
|
-
echo "
|
|
148
|
-
echo "1. /context --compress
|
|
149
|
-
echo "2. /context --save
|
|
147
|
+
echo "Recommended actions:"
|
|
148
|
+
echo "1. Compress with /context --compress"
|
|
149
|
+
echo "2. /context --save then /clear"
|
|
150
150
|
fi
|
|
151
151
|
|
|
152
152
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
#
|
|
155
|
+
# Save snapshot
|
|
156
156
|
save_snapshot() {
|
|
157
157
|
local CURRENT_STAGE=$(get_current_stage)
|
|
158
158
|
local TIMESTAMP=$(date +%Y%m%d-%H%M)
|
|
@@ -161,36 +161,36 @@ save_snapshot() {
|
|
|
161
161
|
local FILEPATH="$CONTEXT_DIR/$FILENAME"
|
|
162
162
|
|
|
163
163
|
if [ -z "$DESCRIPTION" ]; then
|
|
164
|
-
DESCRIPTION="
|
|
164
|
+
DESCRIPTION="Context snapshot"
|
|
165
165
|
fi
|
|
166
166
|
|
|
167
167
|
cat > "$FILEPATH" << EOF
|
|
168
|
-
#
|
|
168
|
+
# Work State Save - $TIMESTAMP_READABLE
|
|
169
169
|
|
|
170
|
-
##
|
|
170
|
+
## Description
|
|
171
171
|
$DESCRIPTION
|
|
172
172
|
|
|
173
|
-
##
|
|
173
|
+
## Current Stage
|
|
174
174
|
$CURRENT_STAGE
|
|
175
175
|
|
|
176
|
-
##
|
|
176
|
+
## Progress
|
|
177
177
|
EOF
|
|
178
178
|
|
|
179
|
-
# progress.json
|
|
179
|
+
# Extract info from progress.json
|
|
180
180
|
if [ -f "$PROGRESS_FILE" ] && command -v jq &> /dev/null; then
|
|
181
181
|
echo "" >> "$FILEPATH"
|
|
182
|
-
echo "###
|
|
182
|
+
echo "### Stage Status" >> "$FILEPATH"
|
|
183
183
|
jq -r '.stages | to_entries[] | "- \(.key): \(.value.status // "pending")"' "$PROGRESS_FILE" >> "$FILEPATH" 2>/dev/null || true
|
|
184
184
|
fi
|
|
185
185
|
|
|
186
186
|
cat >> "$FILEPATH" << EOF
|
|
187
187
|
|
|
188
|
-
##
|
|
189
|
-
1.
|
|
190
|
-
2. stages/$CURRENT_STAGE/CLAUDE.md
|
|
191
|
-
3.
|
|
188
|
+
## Recovery Instructions
|
|
189
|
+
1. Read this file
|
|
190
|
+
2. Reference stages/$CURRENT_STAGE/CLAUDE.md
|
|
191
|
+
3. Resume work
|
|
192
192
|
|
|
193
|
-
##
|
|
193
|
+
## Reference Files
|
|
194
194
|
- state/progress.json
|
|
195
195
|
- stages/$CURRENT_STAGE/outputs/
|
|
196
196
|
EOF
|
|
@@ -199,20 +199,20 @@ EOF
|
|
|
199
199
|
echo -e "💾 ${WHITE}Context Snapshot Saved${NC}"
|
|
200
200
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
201
201
|
echo ""
|
|
202
|
-
echo -e "
|
|
203
|
-
echo -e "
|
|
204
|
-
echo -e "
|
|
202
|
+
echo -e "File: ${CYAN}$FILEPATH${NC}"
|
|
203
|
+
echo -e "Description: $DESCRIPTION"
|
|
204
|
+
echo -e "Stage: $CURRENT_STAGE"
|
|
205
205
|
echo ""
|
|
206
|
-
echo "[
|
|
207
|
-
echo "✓
|
|
208
|
-
echo "✓
|
|
209
|
-
echo "✓
|
|
206
|
+
echo "[Saved Contents]"
|
|
207
|
+
echo "✓ Current stage info"
|
|
208
|
+
echo "✓ Progress status"
|
|
209
|
+
echo "✓ Recovery instructions"
|
|
210
210
|
echo ""
|
|
211
|
-
echo -e "
|
|
211
|
+
echo -e "Restore: ${GREEN}/context --restore $FILENAME${NC}"
|
|
212
212
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
#
|
|
215
|
+
# List snapshots
|
|
216
216
|
list_snapshots() {
|
|
217
217
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
218
218
|
echo -e "📂 ${WHITE}Context Snapshots${NC}"
|
|
@@ -220,13 +220,13 @@ list_snapshots() {
|
|
|
220
220
|
echo ""
|
|
221
221
|
|
|
222
222
|
if [ ! -d "$CONTEXT_DIR" ] || [ -z "$(ls -A "$CONTEXT_DIR"/*.md 2>/dev/null)" ]; then
|
|
223
|
-
echo -e " ${GRAY}
|
|
223
|
+
echo -e " ${GRAY}No saved snapshots.${NC}"
|
|
224
224
|
echo ""
|
|
225
225
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
226
226
|
return
|
|
227
227
|
fi
|
|
228
228
|
|
|
229
|
-
printf " ${GRAY}%-25s %-15s %s${NC}\n" "
|
|
229
|
+
printf " ${GRAY}%-25s %-15s %s${NC}\n" "File" "Size" "Modified"
|
|
230
230
|
echo "─────────────────────────────────────────────────"
|
|
231
231
|
|
|
232
232
|
ls -1t "$CONTEXT_DIR"/*.md 2>/dev/null | while read -r f; do
|
|
@@ -237,19 +237,19 @@ list_snapshots() {
|
|
|
237
237
|
|
|
238
238
|
echo ""
|
|
239
239
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
240
|
-
echo -e "
|
|
240
|
+
echo -e "Restore: ${GREEN}/context --restore [filename]${NC}"
|
|
241
241
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
#
|
|
244
|
+
# Restore snapshot
|
|
245
245
|
restore_snapshot() {
|
|
246
246
|
local FILE="$RESTORE_FILE"
|
|
247
247
|
|
|
248
248
|
if [ -z "$FILE" ]; then
|
|
249
|
-
#
|
|
249
|
+
# Find latest snapshot
|
|
250
250
|
FILE=$(ls -1t "$CONTEXT_DIR"/state-*.md 2>/dev/null | head -1)
|
|
251
251
|
if [ -z "$FILE" ]; then
|
|
252
|
-
echo -e "${RED}
|
|
252
|
+
echo -e "${RED}Error:${NC} No snapshot to restore."
|
|
253
253
|
exit 1
|
|
254
254
|
fi
|
|
255
255
|
FILE=$(basename "$FILE")
|
|
@@ -260,8 +260,8 @@ restore_snapshot() {
|
|
|
260
260
|
FILEPATH="$CONTEXT_DIR/state-$FILE"
|
|
261
261
|
fi
|
|
262
262
|
if [ ! -f "$FILEPATH" ]; then
|
|
263
|
-
echo -e "${RED}
|
|
264
|
-
echo " /context --list
|
|
263
|
+
echo -e "${RED}Error:${NC} File not found: $FILE"
|
|
264
|
+
echo " Check the list with /context --list."
|
|
265
265
|
exit 1
|
|
266
266
|
fi
|
|
267
267
|
|
|
@@ -269,38 +269,38 @@ restore_snapshot() {
|
|
|
269
269
|
echo -e "📂 ${WHITE}Context Restore${NC}"
|
|
270
270
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
271
271
|
echo ""
|
|
272
|
-
echo -e "
|
|
272
|
+
echo -e "File: ${CYAN}$(basename "$FILEPATH")${NC}"
|
|
273
273
|
echo ""
|
|
274
|
-
echo "[
|
|
274
|
+
echo "[Content Preview]"
|
|
275
275
|
echo "─────────────────────────────────────────────────"
|
|
276
276
|
head -20 "$FILEPATH"
|
|
277
277
|
echo "..."
|
|
278
278
|
echo "─────────────────────────────────────────────────"
|
|
279
279
|
echo ""
|
|
280
|
-
echo "
|
|
280
|
+
echo "Reference this file's contents to continue work."
|
|
281
281
|
echo ""
|
|
282
282
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
-
#
|
|
285
|
+
# Run compression (placeholder - actually handled by AI)
|
|
286
286
|
compress_context() {
|
|
287
287
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
288
288
|
echo -e "🗜️ ${WHITE}Context Compression${NC}"
|
|
289
289
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
290
290
|
echo ""
|
|
291
|
-
echo "
|
|
291
|
+
echo "Running context compression."
|
|
292
292
|
echo ""
|
|
293
|
-
echo "
|
|
294
|
-
echo "•
|
|
295
|
-
echo "•
|
|
296
|
-
echo "•
|
|
293
|
+
echo "This operation analyzes conversation content to:"
|
|
294
|
+
echo "• Preserve key decisions"
|
|
295
|
+
echo "• Summarize long discussions"
|
|
296
|
+
echo "• Remove unnecessary content"
|
|
297
297
|
echo ""
|
|
298
|
-
echo "context-compression
|
|
298
|
+
echo "The context-compression skill will be activated."
|
|
299
299
|
echo ""
|
|
300
300
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
-
#
|
|
303
|
+
# Auto context management (Statusline API trigger)
|
|
304
304
|
auto_compact() {
|
|
305
305
|
local LEVEL="${TRIGGER_LEVEL:-warning}"
|
|
306
306
|
local TIMESTAMP=$(date +%Y%m%d-%H%M%S)
|
|
@@ -308,7 +308,7 @@ auto_compact() {
|
|
|
308
308
|
local CURRENT_STAGE=$(get_current_stage)
|
|
309
309
|
local TRIGGER_FILE="$CONTEXT_DIR/auto-trigger.json"
|
|
310
310
|
|
|
311
|
-
#
|
|
311
|
+
# Read trigger info
|
|
312
312
|
local REMAINING="50"
|
|
313
313
|
if [ -f "$TRIGGER_FILE" ]; then
|
|
314
314
|
REMAINING=$(jq -r '.remaining // 50' "$TRIGGER_FILE" 2>/dev/null || echo "50")
|
|
@@ -316,182 +316,182 @@ auto_compact() {
|
|
|
316
316
|
|
|
317
317
|
echo ""
|
|
318
318
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
319
|
-
echo -e "🔄 ${WHITE}
|
|
319
|
+
echo -e "🔄 ${WHITE}Auto Context Management${NC}"
|
|
320
320
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
321
321
|
echo ""
|
|
322
322
|
|
|
323
323
|
if [ "$LEVEL" = "critical" ]; then
|
|
324
|
-
echo -e "${RED}⚠️
|
|
324
|
+
echo -e "${RED}⚠️ Critical: Remaining context below 40%${NC}"
|
|
325
325
|
else
|
|
326
|
-
echo -e "${YELLOW}⚠️
|
|
326
|
+
echo -e "${YELLOW}⚠️ Warning: Remaining context below 50% (${REMAINING}%)${NC}"
|
|
327
327
|
fi
|
|
328
328
|
echo ""
|
|
329
329
|
|
|
330
|
-
# Step 1:
|
|
331
|
-
echo "📸
|
|
330
|
+
# Step 1: Save snapshot
|
|
331
|
+
echo "📸 Saving snapshot..."
|
|
332
332
|
|
|
333
333
|
cat > "$SNAPSHOT_FILE" << EOF
|
|
334
|
-
#
|
|
335
|
-
-
|
|
336
|
-
-
|
|
337
|
-
-
|
|
334
|
+
# Auto-saved Context Snapshot
|
|
335
|
+
- Save time: $(date "+%Y-%m-%d %H:%M:%S")
|
|
336
|
+
- Current stage: $CURRENT_STAGE
|
|
337
|
+
- Trigger: Remaining context ${REMAINING}% (level: $LEVEL)
|
|
338
338
|
|
|
339
|
-
##
|
|
339
|
+
## Current Progress
|
|
340
340
|
EOF
|
|
341
341
|
|
|
342
|
-
# progress.json
|
|
342
|
+
# Extract stage status from progress.json
|
|
343
343
|
if [ -f "$PROGRESS_FILE" ] && command -v jq &> /dev/null; then
|
|
344
344
|
echo "" >> "$SNAPSHOT_FILE"
|
|
345
|
-
echo "###
|
|
345
|
+
echo "### Stage Status" >> "$SNAPSHOT_FILE"
|
|
346
346
|
jq -r '.stages | to_entries[] | select(.value.status != "pending") | "- \(.key): \(.value.status)"' "$PROGRESS_FILE" >> "$SNAPSHOT_FILE" 2>/dev/null || true
|
|
347
347
|
|
|
348
|
-
#
|
|
348
|
+
# Recent checkpoint info
|
|
349
349
|
local CHECKPOINTS=$(jq -r '.checkpoints // [] | length' "$PROGRESS_FILE" 2>/dev/null || echo "0")
|
|
350
350
|
if [ "$CHECKPOINTS" -gt 0 ]; then
|
|
351
351
|
echo "" >> "$SNAPSHOT_FILE"
|
|
352
|
-
echo "###
|
|
353
|
-
echo "-
|
|
354
|
-
jq -r '.checkpoints[-1] // empty | "-
|
|
352
|
+
echo "### Checkpoints" >> "$SNAPSHOT_FILE"
|
|
353
|
+
echo "- Total checkpoints: $CHECKPOINTS" >> "$SNAPSHOT_FILE"
|
|
354
|
+
jq -r '.checkpoints[-1] // empty | "- Recent: \(.name // .timestamp)"' "$PROGRESS_FILE" >> "$SNAPSHOT_FILE" 2>/dev/null || true
|
|
355
355
|
fi
|
|
356
356
|
fi
|
|
357
357
|
|
|
358
358
|
cat >> "$SNAPSHOT_FILE" << EOF
|
|
359
359
|
|
|
360
|
-
##
|
|
361
|
-
1.
|
|
362
|
-
2. stages/$CURRENT_STAGE/CLAUDE.md
|
|
363
|
-
3. stages/$CURRENT_STAGE/HANDOFF.md
|
|
364
|
-
4.
|
|
360
|
+
## Recovery Instructions
|
|
361
|
+
1. Read this file
|
|
362
|
+
2. Reference stages/$CURRENT_STAGE/CLAUDE.md
|
|
363
|
+
3. Reference stages/$CURRENT_STAGE/HANDOFF.md (if exists)
|
|
364
|
+
4. Resume work
|
|
365
365
|
|
|
366
|
-
##
|
|
366
|
+
## Reference Files
|
|
367
367
|
- state/progress.json
|
|
368
368
|
- stages/$CURRENT_STAGE/outputs/
|
|
369
369
|
EOF
|
|
370
370
|
|
|
371
|
-
echo -e "${GREEN}✓${NC}
|
|
371
|
+
echo -e "${GREEN}✓${NC} Snapshot saved: $(basename "$SNAPSHOT_FILE")"
|
|
372
372
|
echo ""
|
|
373
373
|
|
|
374
|
-
# progress.json
|
|
374
|
+
# Record snapshot in progress.json
|
|
375
375
|
if [ -f "$PROGRESS_FILE" ] && command -v jq &> /dev/null; then
|
|
376
|
-
# context_snapshots
|
|
376
|
+
# Create context_snapshots array if not exists
|
|
377
377
|
local HAS_SNAPSHOTS=$(jq 'has("context_snapshots")' "$PROGRESS_FILE" 2>/dev/null || echo "false")
|
|
378
378
|
if [ "$HAS_SNAPSHOTS" = "false" ]; then
|
|
379
379
|
jq '. + {"context_snapshots": []}' "$PROGRESS_FILE" > "$PROGRESS_FILE.tmp" && mv "$PROGRESS_FILE.tmp" "$PROGRESS_FILE"
|
|
380
380
|
fi
|
|
381
381
|
|
|
382
|
-
#
|
|
382
|
+
# Add snapshot info
|
|
383
383
|
jq ".context_snapshots += [{\"file\": \"$SNAPSHOT_FILE\", \"reason\": \"auto-${LEVEL}\", \"remaining\": $REMAINING, \"timestamp\": \"$(date -Iseconds)\"}]" \
|
|
384
384
|
"$PROGRESS_FILE" > "$PROGRESS_FILE.tmp" && mv "$PROGRESS_FILE.tmp" "$PROGRESS_FILE"
|
|
385
385
|
fi
|
|
386
386
|
|
|
387
|
-
# Step 2:
|
|
387
|
+
# Step 2: Guide recommended actions
|
|
388
388
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
389
389
|
if [ "$LEVEL" = "critical" ]; then
|
|
390
|
-
echo -e "${RED}⚠️
|
|
390
|
+
echo -e "${RED}⚠️ Context threshold reached (below 40%)${NC}"
|
|
391
391
|
echo ""
|
|
392
|
-
echo -e "
|
|
392
|
+
echo -e "Snapshot auto-saved: ${CYAN}$(basename "$SNAPSHOT_FILE")${NC}"
|
|
393
393
|
echo ""
|
|
394
394
|
|
|
395
|
-
#
|
|
396
|
-
echo -e "${WHITE}
|
|
395
|
+
# User confirmation prompt
|
|
396
|
+
echo -e "${WHITE}Would you like to clear the context?${NC}"
|
|
397
397
|
echo ""
|
|
398
|
-
echo " [y] /clear
|
|
399
|
-
echo " [c] /compact
|
|
400
|
-
echo " [n]
|
|
398
|
+
echo " [y] Run /clear (recoverable from snapshot)"
|
|
399
|
+
echo " [c] Run /compact (summarize and continue)"
|
|
400
|
+
echo " [n] Cancel (handle manually)"
|
|
401
401
|
echo ""
|
|
402
|
-
read -p "
|
|
402
|
+
read -p "Choice [y/c/n]: " -n 1 -r CLEAR_CHOICE
|
|
403
403
|
echo ""
|
|
404
404
|
echo ""
|
|
405
405
|
|
|
406
406
|
case $CLEAR_CHOICE in
|
|
407
407
|
[Yy])
|
|
408
|
-
echo -e "${GREEN}✓${NC} /clear
|
|
408
|
+
echo -e "${GREEN}✓${NC} Running /clear..."
|
|
409
409
|
echo ""
|
|
410
410
|
|
|
411
|
-
#
|
|
411
|
+
# Save recovery info
|
|
412
412
|
echo "{\"action\": \"clear\", \"snapshot\": \"$SNAPSHOT_FILE\", \"timestamp\": \"$(date -Iseconds)\"}" > "$CONTEXT_DIR/pending-clear.json"
|
|
413
413
|
|
|
414
|
-
#
|
|
414
|
+
# Auto-run /clear via tmux
|
|
415
415
|
if [ -n "$TMUX" ]; then
|
|
416
|
-
#
|
|
416
|
+
# Run in current tmux session
|
|
417
417
|
sleep 1
|
|
418
418
|
tmux send-keys "/clear" Enter
|
|
419
|
-
echo -e "${GREEN}✓${NC} /clear
|
|
419
|
+
echo -e "${GREEN}✓${NC} /clear command sent."
|
|
420
420
|
elif tmux list-sessions 2>/dev/null | grep -q "claude"; then
|
|
421
|
-
#
|
|
421
|
+
# Find and send to claude session
|
|
422
422
|
CLAUDE_SESSION=$(tmux list-sessions 2>/dev/null | grep "claude" | head -1 | cut -d: -f1)
|
|
423
423
|
tmux send-keys -t "$CLAUDE_SESSION" "/clear" Enter
|
|
424
|
-
echo -e "${GREEN}✓${NC} /clear
|
|
424
|
+
echo -e "${GREEN}✓${NC} /clear command sent to '$CLAUDE_SESSION' session."
|
|
425
425
|
else
|
|
426
|
-
echo -e "${YELLOW}⚠️${NC}
|
|
427
|
-
echo "
|
|
426
|
+
echo -e "${YELLOW}⚠️${NC} Cannot find tmux session."
|
|
427
|
+
echo "Please run the following command manually:"
|
|
428
428
|
echo -e "${CYAN}/clear${NC}"
|
|
429
429
|
fi
|
|
430
430
|
|
|
431
431
|
echo ""
|
|
432
|
-
echo "
|
|
432
|
+
echo "To restore:"
|
|
433
433
|
echo -e "${CYAN}/context --restore $(basename "$SNAPSHOT_FILE")${NC}"
|
|
434
434
|
;;
|
|
435
435
|
[Cc])
|
|
436
|
-
echo -e "${GREEN}✓${NC} /compact
|
|
436
|
+
echo -e "${GREEN}✓${NC} Running /compact..."
|
|
437
437
|
echo ""
|
|
438
438
|
|
|
439
|
-
#
|
|
439
|
+
# Auto-run /compact via tmux
|
|
440
440
|
if [ -n "$TMUX" ]; then
|
|
441
441
|
sleep 1
|
|
442
442
|
tmux send-keys "/compact" Enter
|
|
443
|
-
echo -e "${GREEN}✓${NC} /compact
|
|
443
|
+
echo -e "${GREEN}✓${NC} /compact command sent."
|
|
444
444
|
elif tmux list-sessions 2>/dev/null | grep -q "claude"; then
|
|
445
445
|
CLAUDE_SESSION=$(tmux list-sessions 2>/dev/null | grep "claude" | head -1 | cut -d: -f1)
|
|
446
446
|
tmux send-keys -t "$CLAUDE_SESSION" "/compact" Enter
|
|
447
|
-
echo -e "${GREEN}✓${NC} /compact
|
|
447
|
+
echo -e "${GREEN}✓${NC} /compact command sent to '$CLAUDE_SESSION' session."
|
|
448
448
|
else
|
|
449
|
-
echo -e "${YELLOW}⚠️${NC}
|
|
450
|
-
echo "
|
|
449
|
+
echo -e "${YELLOW}⚠️${NC} Cannot find tmux session."
|
|
450
|
+
echo "Please run the following command manually:"
|
|
451
451
|
echo -e "${CYAN}/compact${NC}"
|
|
452
452
|
fi
|
|
453
453
|
;;
|
|
454
454
|
*)
|
|
455
|
-
echo "
|
|
455
|
+
echo "Cancelled. Please run /clear or /compact manually."
|
|
456
456
|
;;
|
|
457
457
|
esac
|
|
458
458
|
else
|
|
459
|
-
echo -e "${YELLOW}⚠️ /compact
|
|
459
|
+
echo -e "${YELLOW}⚠️ Recommend running /compact${NC}"
|
|
460
460
|
echo ""
|
|
461
|
-
echo "
|
|
462
|
-
echo "
|
|
461
|
+
echo "Will auto-recover from snapshot after execution."
|
|
462
|
+
echo "Saved snapshot: $(basename "$SNAPSHOT_FILE")"
|
|
463
463
|
fi
|
|
464
464
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
465
465
|
|
|
466
|
-
#
|
|
466
|
+
# Terminal bell (notification)
|
|
467
467
|
echo -e "\a"
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
-
#
|
|
470
|
+
# Clean old snapshots
|
|
471
471
|
clean_snapshots() {
|
|
472
472
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
473
473
|
echo -e "🧹 ${WHITE}Clean Old Snapshots${NC}"
|
|
474
474
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
475
475
|
echo ""
|
|
476
476
|
|
|
477
|
-
#
|
|
477
|
+
# Find snapshots older than 7 days
|
|
478
478
|
OLD_FILES=$(find "$CONTEXT_DIR" -name "state-*.md" -mtime +7 2>/dev/null)
|
|
479
479
|
|
|
480
480
|
if [ -z "$OLD_FILES" ]; then
|
|
481
|
-
echo "
|
|
481
|
+
echo "No old snapshots to clean."
|
|
482
482
|
else
|
|
483
|
-
echo "
|
|
483
|
+
echo "The following files will be deleted (older than 7 days):"
|
|
484
484
|
echo "$OLD_FILES" | while read -r f; do
|
|
485
485
|
echo " - $(basename "$f")"
|
|
486
486
|
done
|
|
487
487
|
echo ""
|
|
488
|
-
read -p "
|
|
488
|
+
read -p "Delete? [y/N] " -n 1 -r
|
|
489
489
|
echo
|
|
490
490
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
491
491
|
echo "$OLD_FILES" | xargs rm -f
|
|
492
|
-
echo -e "${GREEN}✓${NC}
|
|
492
|
+
echo -e "${GREEN}✓${NC} Cleanup complete"
|
|
493
493
|
else
|
|
494
|
-
echo "
|
|
494
|
+
echo "Cancelled."
|
|
495
495
|
fi
|
|
496
496
|
fi
|
|
497
497
|
|
|
@@ -499,7 +499,7 @@ clean_snapshots() {
|
|
|
499
499
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
-
#
|
|
502
|
+
# Main logic
|
|
503
503
|
case $ACTION in
|
|
504
504
|
status)
|
|
505
505
|
show_status
|