create-ax-project 1.0.0

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.
Files changed (258) hide show
  1. package/README.md +374 -0
  2. package/bin/create.js +193 -0
  3. package/package.json +38 -0
  4. package/template/.claude/CLAUDE.md +7 -0
  5. package/template/.claude/commands/CLAUDE.md +0 -0
  6. package/template/.claude/commands/benchmark.md +103 -0
  7. package/template/.claude/commands/brainstorm.md +67 -0
  8. package/template/.claude/commands/checkpoint.md +93 -0
  9. package/template/.claude/commands/codex.md +107 -0
  10. package/template/.claude/commands/collaborate.md +85 -0
  11. package/template/.claude/commands/context.md +154 -0
  12. package/template/.claude/commands/deploy.md +102 -0
  13. package/template/.claude/commands/fork.md +142 -0
  14. package/template/.claude/commands/gemini.md +84 -0
  15. package/template/.claude/commands/handoff.md +80 -0
  16. package/template/.claude/commands/implement.md +82 -0
  17. package/template/.claude/commands/init-project.md +49 -0
  18. package/template/.claude/commands/next.md +125 -0
  19. package/template/.claude/commands/planning.md +69 -0
  20. package/template/.claude/commands/qa.md +81 -0
  21. package/template/.claude/commands/refactor.md +95 -0
  22. package/template/.claude/commands/research.md +60 -0
  23. package/template/.claude/commands/restore.md +113 -0
  24. package/template/.claude/commands/run-stage.md +78 -0
  25. package/template/.claude/commands/stages.md +109 -0
  26. package/template/.claude/commands/status.md +73 -0
  27. package/template/.claude/commands/tasks.md +80 -0
  28. package/template/.claude/commands/test.md +93 -0
  29. package/template/.claude/commands/ui-ux.md +61 -0
  30. package/template/.claude/commands/validate.md +174 -0
  31. package/template/.claude/hooks/CLAUDE.md +0 -0
  32. package/template/.claude/hooks/ai-selector.sh +223 -0
  33. package/template/.claude/hooks/auto-checkpoint.sh +187 -0
  34. package/template/.claude/hooks/output-validator.sh +289 -0
  35. package/template/.claude/hooks/post-stage.sh +123 -0
  36. package/template/.claude/hooks/pre-stage.sh +186 -0
  37. package/template/.claude/hooks/session-start.sh +90 -0
  38. package/template/.claude/hooks/statusline.sh +115 -0
  39. package/template/.claude/hooks/stop.sh +104 -0
  40. package/template/.claude/settings.json +149 -0
  41. package/template/.claude/skills/ai-collaboration/CLAUDE.md +0 -0
  42. package/template/.claude/skills/ai-collaboration/README.md +61 -0
  43. package/template/.claude/skills/ai-collaboration/debate.md +148 -0
  44. package/template/.claude/skills/ai-collaboration/parallel.md +96 -0
  45. package/template/.claude/skills/ai-collaboration/prompts/CLAUDE.md +107 -0
  46. package/template/.claude/skills/auto-checkpoint/CLAUDE.md +0 -0
  47. package/template/.claude/skills/auto-checkpoint/README.md +77 -0
  48. package/template/.claude/skills/auto-checkpoint/prompts/CLAUDE.md +113 -0
  49. package/template/.claude/skills/auto-checkpoint/rollback.md +152 -0
  50. package/template/.claude/skills/auto-checkpoint/trigger.md +122 -0
  51. package/template/.claude/skills/context-compression/CLAUDE.md +0 -0
  52. package/template/.claude/skills/context-compression/README.md +121 -0
  53. package/template/.claude/skills/context-compression/analyze.md +114 -0
  54. package/template/.claude/skills/context-compression/compress.md +175 -0
  55. package/template/.claude/skills/context-compression/prompts/CLAUDE.md +0 -0
  56. package/template/.claude/skills/context-compression/prompts/compression.md +172 -0
  57. package/template/.claude/skills/output-validator/CLAUDE.md +0 -0
  58. package/template/.claude/skills/output-validator/README.md +86 -0
  59. package/template/.claude/skills/output-validator/prompts/CLAUDE.md +119 -0
  60. package/template/.claude/skills/output-validator/validate.md +182 -0
  61. package/template/.claude/skills/smart-handoff/CLAUDE.md +0 -0
  62. package/template/.claude/skills/smart-handoff/README.md +59 -0
  63. package/template/.claude/skills/smart-handoff/extract.md +76 -0
  64. package/template/.claude/skills/smart-handoff/prompts/CLAUDE.md +86 -0
  65. package/template/.claude/skills/smart-handoff/summarize.md +94 -0
  66. package/template/.claude/skills/stage-transition/CLAUDE.md +0 -0
  67. package/template/.claude/skills/stage-transition/README.md +84 -0
  68. package/template/.claude/skills/stage-transition/handoff-gen.md +160 -0
  69. package/template/.claude/skills/stage-transition/prompts/CLAUDE.md +0 -0
  70. package/template/.claude/skills/stage-transition/prompts/transition.md +145 -0
  71. package/template/.claude/skills/stage-transition/validate.md +108 -0
  72. package/template/CLAUDE.md +528 -0
  73. package/template/config/CLAUDE.md +0 -0
  74. package/template/config/ai_benchmarking.yaml +184 -0
  75. package/template/config/ai_collaboration.yaml +159 -0
  76. package/template/config/ai_logging.yaml +129 -0
  77. package/template/config/auto_checkpoint.yaml +189 -0
  78. package/template/config/context.yaml +78 -0
  79. package/template/config/git.yaml +161 -0
  80. package/template/config/handoff_intelligence.yaml +229 -0
  81. package/template/config/implementation.yaml.template +181 -0
  82. package/template/config/mcp_fallbacks.yaml +252 -0
  83. package/template/config/memory_integration.yaml +200 -0
  84. package/template/config/model_enforcement.yaml +141 -0
  85. package/template/config/models.yaml +242 -0
  86. package/template/config/output_validation.yaml +352 -0
  87. package/template/config/pipeline.yaml +357 -0
  88. package/template/config/pipeline_forking.yaml +236 -0
  89. package/template/config/qa_logging.yaml +166 -0
  90. package/template/config/smart_rollback.yaml +209 -0
  91. package/template/config/stage_personas.yaml +354 -0
  92. package/template/config/workflow.yaml +54 -0
  93. package/template/scripts/CLAUDE.md +0 -0
  94. package/template/scripts/ai-benchmark.sh +272 -0
  95. package/template/scripts/codex-wrapper.sh +97 -0
  96. package/template/scripts/context-manager.sh +528 -0
  97. package/template/scripts/create-checkpoint.sh +116 -0
  98. package/template/scripts/gemini-wrapper.sh +96 -0
  99. package/template/scripts/init-project.sh +109 -0
  100. package/template/scripts/list-stages.sh +245 -0
  101. package/template/scripts/next-stage.sh +228 -0
  102. package/template/scripts/output-validate.sh +12 -0
  103. package/template/scripts/pipeline-fork.sh +293 -0
  104. package/template/scripts/pre-run-check.sh +361 -0
  105. package/template/scripts/restore-checkpoint.sh +247 -0
  106. package/template/scripts/run-stage.sh +139 -0
  107. package/template/scripts/show-status.sh +185 -0
  108. package/template/scripts/smart-handoff.sh +254 -0
  109. package/template/stages/01-brainstorm/CLAUDE.md +103 -0
  110. package/template/stages/01-brainstorm/HANDOFF.md +110 -0
  111. package/template/stages/01-brainstorm/HANDOFF.md.template +112 -0
  112. package/template/stages/01-brainstorm/README.md +97 -0
  113. package/template/stages/01-brainstorm/config.yaml +92 -0
  114. package/template/stages/01-brainstorm/inputs/.gitkeep +0 -0
  115. package/template/stages/01-brainstorm/inputs/CLAUDE.md +0 -0
  116. package/template/stages/01-brainstorm/inputs/project_brief.md +40 -0
  117. package/template/stages/01-brainstorm/outputs/.gitkeep +0 -0
  118. package/template/stages/01-brainstorm/outputs/CLAUDE.md +0 -0
  119. package/template/stages/01-brainstorm/outputs/ideas.md +159 -0
  120. package/template/stages/01-brainstorm/outputs/requirements_analysis.md +222 -0
  121. package/template/stages/01-brainstorm/prompts/CLAUDE.md +0 -0
  122. package/template/stages/01-brainstorm/prompts/collaboration.md +46 -0
  123. package/template/stages/01-brainstorm/prompts/ideation.md +62 -0
  124. package/template/stages/01-brainstorm/prompts/persona.md +73 -0
  125. package/template/stages/01-brainstorm/prompts/requirements.md +73 -0
  126. package/template/stages/01-brainstorm/prompts/validation.md +50 -0
  127. package/template/stages/01-brainstorm/templates/CLAUDE.md +0 -0
  128. package/template/stages/01-brainstorm/templates/ideas.md +91 -0
  129. package/template/stages/01-brainstorm/templates/requirements_analysis.md +129 -0
  130. package/template/stages/02-research/CLAUDE.md +101 -0
  131. package/template/stages/02-research/HANDOFF.md +158 -0
  132. package/template/stages/02-research/HANDOFF.md.template +102 -0
  133. package/template/stages/02-research/config.yaml +68 -0
  134. package/template/stages/02-research/inputs/.gitkeep +0 -0
  135. package/template/stages/02-research/outputs/.gitkeep +0 -0
  136. package/template/stages/02-research/outputs/CLAUDE.md +0 -0
  137. package/template/stages/02-research/outputs/feasibility_report.md +176 -0
  138. package/template/stages/02-research/outputs/tech_research.md +403 -0
  139. package/template/stages/02-research/prompts/CLAUDE.md +0 -0
  140. package/template/stages/02-research/prompts/collaboration.md +51 -0
  141. package/template/stages/02-research/prompts/feasibility.md +73 -0
  142. package/template/stages/02-research/prompts/market_analysis.md +58 -0
  143. package/template/stages/02-research/prompts/tech_stack.md +60 -0
  144. package/template/stages/02-research/prompts/validation.md +51 -0
  145. package/template/stages/02-research/templates/.gitkeep +0 -0
  146. package/template/stages/03-planning/CLAUDE.md +98 -0
  147. package/template/stages/03-planning/HANDOFF.md +168 -0
  148. package/template/stages/03-planning/HANDOFF.md.template +91 -0
  149. package/template/stages/03-planning/config.yaml +64 -0
  150. package/template/stages/03-planning/inputs/.gitkeep +0 -0
  151. package/template/stages/03-planning/outputs/.gitkeep +0 -0
  152. package/template/stages/03-planning/outputs/CLAUDE.md +0 -0
  153. package/template/stages/03-planning/outputs/architecture.md +400 -0
  154. package/template/stages/03-planning/outputs/implementation.yaml +209 -0
  155. package/template/stages/03-planning/outputs/project_plan.md +204 -0
  156. package/template/stages/03-planning/outputs/tech_stack.md +176 -0
  157. package/template/stages/03-planning/prompts/CLAUDE.md +0 -0
  158. package/template/stages/03-planning/prompts/architecture.md +62 -0
  159. package/template/stages/03-planning/prompts/collaboration.md +57 -0
  160. package/template/stages/03-planning/prompts/validation.md +59 -0
  161. package/template/stages/03-planning/templates/.gitkeep +0 -0
  162. package/template/stages/04-ui-ux/CLAUDE.md +88 -0
  163. package/template/stages/04-ui-ux/HANDOFF.md +165 -0
  164. package/template/stages/04-ui-ux/HANDOFF.md.template +92 -0
  165. package/template/stages/04-ui-ux/config.yaml +57 -0
  166. package/template/stages/04-ui-ux/inputs/.gitkeep +0 -0
  167. package/template/stages/04-ui-ux/outputs/.gitkeep +0 -0
  168. package/template/stages/04-ui-ux/outputs/CLAUDE.md +0 -0
  169. package/template/stages/04-ui-ux/outputs/design_system.md +449 -0
  170. package/template/stages/04-ui-ux/outputs/user_flows.md +321 -0
  171. package/template/stages/04-ui-ux/outputs/wireframes.md +241 -0
  172. package/template/stages/04-ui-ux/prompts/.gitkeep +0 -0
  173. package/template/stages/04-ui-ux/prompts/CLAUDE.md +0 -0
  174. package/template/stages/04-ui-ux/prompts/collaboration.md +56 -0
  175. package/template/stages/04-ui-ux/prompts/validation.md +54 -0
  176. package/template/stages/04-ui-ux/templates/.gitkeep +0 -0
  177. package/template/stages/05-task-management/CLAUDE.md +105 -0
  178. package/template/stages/05-task-management/HANDOFF.md +187 -0
  179. package/template/stages/05-task-management/HANDOFF.md.template +97 -0
  180. package/template/stages/05-task-management/config.yaml +81 -0
  181. package/template/stages/05-task-management/inputs/.gitkeep +0 -0
  182. package/template/stages/05-task-management/outputs/.gitkeep +0 -0
  183. package/template/stages/05-task-management/outputs/CLAUDE.md +0 -0
  184. package/template/stages/05-task-management/outputs/milestones.md +253 -0
  185. package/template/stages/05-task-management/outputs/sprint_plan.md +203 -0
  186. package/template/stages/05-task-management/outputs/tasks.md +402 -0
  187. package/template/stages/05-task-management/prompts/.gitkeep +0 -0
  188. package/template/stages/05-task-management/prompts/CLAUDE.md +0 -0
  189. package/template/stages/05-task-management/prompts/collaboration.md +54 -0
  190. package/template/stages/05-task-management/prompts/validation.md +66 -0
  191. package/template/stages/05-task-management/templates/CLAUDE.md +0 -0
  192. package/template/stages/05-task-management/templates/notion_integration.md +176 -0
  193. package/template/stages/05-task-management/templates/parallel_groups.yaml +153 -0
  194. package/template/stages/05-task-management/templates/task_schema.yaml +154 -0
  195. package/template/stages/06-implementation/CLAUDE.md +163 -0
  196. package/template/stages/06-implementation/HANDOFF.md +184 -0
  197. package/template/stages/06-implementation/HANDOFF.md.template +192 -0
  198. package/template/stages/06-implementation/config.yaml +62 -0
  199. package/template/stages/06-implementation/inputs/.gitkeep +0 -0
  200. package/template/stages/06-implementation/outputs/.gitkeep +0 -0
  201. package/template/stages/06-implementation/prompts/.gitkeep +0 -0
  202. package/template/stages/06-implementation/prompts/CLAUDE.md +0 -0
  203. package/template/stages/06-implementation/prompts/collaboration.md +64 -0
  204. package/template/stages/06-implementation/prompts/validation.md +65 -0
  205. package/template/stages/06-implementation/templates/.gitkeep +0 -0
  206. package/template/stages/07-refactoring/CLAUDE.md +180 -0
  207. package/template/stages/07-refactoring/HANDOFF.md +82 -0
  208. package/template/stages/07-refactoring/HANDOFF.md.template +97 -0
  209. package/template/stages/07-refactoring/config.yaml +68 -0
  210. package/template/stages/07-refactoring/inputs/.gitkeep +0 -0
  211. package/template/stages/07-refactoring/outputs/.gitkeep +0 -0
  212. package/template/stages/07-refactoring/outputs/refactoring_report.md +102 -0
  213. package/template/stages/07-refactoring/prompts/.gitkeep +0 -0
  214. package/template/stages/07-refactoring/prompts/CLAUDE.md +0 -0
  215. package/template/stages/07-refactoring/prompts/collaboration.md +71 -0
  216. package/template/stages/07-refactoring/prompts/validation.md +76 -0
  217. package/template/stages/07-refactoring/templates/.gitkeep +0 -0
  218. package/template/stages/08-qa/CLAUDE.md +93 -0
  219. package/template/stages/08-qa/HANDOFF.md +114 -0
  220. package/template/stages/08-qa/HANDOFF.md.template +96 -0
  221. package/template/stages/08-qa/config.yaml +56 -0
  222. package/template/stages/08-qa/inputs/.gitkeep +0 -0
  223. package/template/stages/08-qa/outputs/.gitkeep +0 -0
  224. package/template/stages/08-qa/outputs/qa_report.md +138 -0
  225. package/template/stages/08-qa/prompts/.gitkeep +0 -0
  226. package/template/stages/08-qa/prompts/CLAUDE.md +0 -0
  227. package/template/stages/08-qa/prompts/collaboration.md +65 -0
  228. package/template/stages/08-qa/prompts/validation.md +71 -0
  229. package/template/stages/08-qa/templates/.gitkeep +0 -0
  230. package/template/stages/09-testing/CLAUDE.md +124 -0
  231. package/template/stages/09-testing/HANDOFF.md +118 -0
  232. package/template/stages/09-testing/HANDOFF.md.template +113 -0
  233. package/template/stages/09-testing/config.yaml +65 -0
  234. package/template/stages/09-testing/inputs/.gitkeep +0 -0
  235. package/template/stages/09-testing/outputs/.gitkeep +0 -0
  236. package/template/stages/09-testing/outputs/test_report.md +146 -0
  237. package/template/stages/09-testing/prompts/.gitkeep +0 -0
  238. package/template/stages/09-testing/prompts/CLAUDE.md +0 -0
  239. package/template/stages/09-testing/prompts/collaboration.md +77 -0
  240. package/template/stages/09-testing/prompts/validation.md +83 -0
  241. package/template/stages/09-testing/templates/.gitkeep +0 -0
  242. package/template/stages/10-deployment/CLAUDE.md +117 -0
  243. package/template/stages/10-deployment/HANDOFF.md +141 -0
  244. package/template/stages/10-deployment/HANDOFF.md.template +148 -0
  245. package/template/stages/10-deployment/config.yaml +61 -0
  246. package/template/stages/10-deployment/inputs/.gitkeep +0 -0
  247. package/template/stages/10-deployment/outputs/.gitkeep +0 -0
  248. package/template/stages/10-deployment/prompts/.gitkeep +0 -0
  249. package/template/stages/10-deployment/prompts/CLAUDE.md +0 -0
  250. package/template/stages/10-deployment/prompts/collaboration.md +80 -0
  251. package/template/stages/10-deployment/prompts/validation.md +93 -0
  252. package/template/stages/10-deployment/templates/CLAUDE.md +0 -0
  253. package/template/stages/10-deployment/templates/github-actions-cd.yaml +118 -0
  254. package/template/stages/10-deployment/templates/github-actions-ci.yaml +136 -0
  255. package/template/state/progress.json.template +111 -0
  256. package/template/state/templates/CLAUDE.md +0 -0
  257. package/template/state/templates/handoff_base.md.template +187 -0
  258. package/template/state/templates/phase_state.md.template +97 -0
@@ -0,0 +1,97 @@
1
+ #!/bin/bash
2
+ # codex-wrapper.sh - tmux 기반 Codex CLI 래퍼
3
+ # ax-templates workflow pipeline
4
+ # tmux wait-for 채널 기반 동기화 방식 (폴링 없음, 즉시 반응)
5
+
6
+ SESSION_NAME="ax-codex"
7
+ CHANNEL="ax-codex-done-$$"
8
+ OUTPUT_FILE="/tmp/ax-codex-output-$$"
9
+ PROMPT="$1"
10
+ TIMEOUT="${2:-300}" # 기본 5분 타임아웃
11
+
12
+ # 색상 정의
13
+ RED='\033[0;31m'
14
+ GREEN='\033[0;32m'
15
+ YELLOW='\033[1;33m'
16
+ BLUE='\033[0;34m'
17
+ NC='\033[0m' # No Color
18
+
19
+ # 사용법
20
+ if [ -z "$PROMPT" ]; then
21
+ echo "사용법: $0 \"<prompt>\" [timeout_seconds]"
22
+ echo "예시: $0 \"이 함수를 리팩토링해줘\" 300"
23
+ exit 1
24
+ fi
25
+
26
+ # tmux 확인
27
+ if ! command -v tmux &> /dev/null; then
28
+ echo -e "${RED}오류:${NC} tmux가 설치되어 있지 않습니다."
29
+ echo "설치: brew install tmux (macOS) 또는 apt install tmux (Ubuntu)"
30
+ exit 1
31
+ fi
32
+
33
+ # Codex CLI 확인
34
+ if ! command -v codex &> /dev/null; then
35
+ echo -e "${YELLOW}경고:${NC} codex CLI가 설치되어 있지 않습니다."
36
+ echo "Codex CLI 없이 시뮬레이션 모드로 실행합니다."
37
+ echo ""
38
+ echo "[시뮬레이션] Codex 응답:"
39
+ echo "---"
40
+ echo "Codex CLI가 설치되면 실제 응답이 표시됩니다."
41
+ echo "프롬프트: $PROMPT"
42
+ exit 0
43
+ fi
44
+
45
+ # 임시 파일 정리
46
+ cleanup() {
47
+ rm -f "$OUTPUT_FILE"
48
+ }
49
+ trap cleanup EXIT
50
+
51
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
52
+ echo -e "${BLUE}🤖 Codex CLI 호출${NC}"
53
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
54
+ echo " 세션: $SESSION_NAME"
55
+ echo " 타임아웃: ${TIMEOUT}초"
56
+ echo ""
57
+
58
+ # tmux 세션 확인/생성
59
+ if ! tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
60
+ echo -e "${YELLOW}⚠${NC} 새 tmux 세션 생성: $SESSION_NAME"
61
+ tmux new-session -d -s "$SESSION_NAME"
62
+ sleep 1
63
+ fi
64
+
65
+ # 프롬프트 이스케이프
66
+ ESCAPED_PROMPT=$(printf '%s' "$PROMPT" | sed 's/"/\\"/g' | sed "s/'/'\\\\''/g")
67
+
68
+ # Codex CLI 실행 + 완료 시 채널에 시그널
69
+ # Issue #2, #13 해결: --full-auto 옵션 기본 추가
70
+ echo -e "${BLUE}Codex 호출 중... (--full-auto 모드)${NC}"
71
+ tmux send-keys -t "$SESSION_NAME" "codex --full-auto \"$ESCAPED_PROMPT\" 2>&1 | tee $OUTPUT_FILE; tmux wait-for -S $CHANNEL" Enter
72
+
73
+ # 타임아웃 처리를 위해 백그라운드 타이머
74
+ (sleep "$TIMEOUT" && tmux wait-for -S "$CHANNEL" 2>/dev/null) &
75
+ TIMER_PID=$!
76
+
77
+ # 채널 시그널 대기 (블로킹)
78
+ tmux wait-for "$CHANNEL"
79
+ kill $TIMER_PID 2>/dev/null || true
80
+
81
+ # 결과 출력
82
+ echo ""
83
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
84
+ echo -e "${GREEN}📄 Codex 응답:${NC}"
85
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
86
+
87
+ if [[ -f "$OUTPUT_FILE" ]]; then
88
+ cat "$OUTPUT_FILE"
89
+ else
90
+ echo -e "${RED}오류:${NC} 출력을 캡처하지 못했습니다."
91
+ exit 1
92
+ fi
93
+
94
+ echo ""
95
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
96
+ echo -e "${GREEN}✓${NC} Codex 호출 완료"
97
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@@ -0,0 +1,528 @@
1
+ #!/bin/bash
2
+ # context-manager.sh - 컨텍스트 상태 관리
3
+ # ax-templates workflow pipeline
4
+
5
+ set -e
6
+
7
+ PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
8
+ PROGRESS_FILE="$PROJECT_ROOT/state/progress.json"
9
+ CONTEXT_DIR="$PROJECT_ROOT/state/context"
10
+ SETTINGS_FILE="$PROJECT_ROOT/.claude/settings.json"
11
+
12
+ # 색상 정의
13
+ RED='\033[0;31m'
14
+ GREEN='\033[0;32m'
15
+ YELLOW='\033[1;33m'
16
+ BLUE='\033[0;34m'
17
+ CYAN='\033[0;36m'
18
+ WHITE='\033[1;37m'
19
+ GRAY='\033[0;90m'
20
+ NC='\033[0m' # No Color
21
+
22
+ # 기본값
23
+ WARNING_THRESHOLD=50000
24
+ LIMIT_THRESHOLD=80000
25
+
26
+ # 설정 파일에서 임계값 로드
27
+ if [ -f "$SETTINGS_FILE" ] && command -v jq &> /dev/null; then
28
+ WARNING_THRESHOLD=$(jq -r '.context.warning_threshold // 50000' "$SETTINGS_FILE")
29
+ LIMIT_THRESHOLD=$(jq -r '.context.limit_threshold // 80000' "$SETTINGS_FILE")
30
+ fi
31
+
32
+ # 컨텍스트 디렉토리 생성
33
+ mkdir -p "$CONTEXT_DIR"
34
+
35
+ # 옵션 처리
36
+ ACTION="status"
37
+ DESCRIPTION=""
38
+ RESTORE_FILE=""
39
+ OUTPUT_JSON=false
40
+
41
+ TRIGGER_LEVEL=""
42
+
43
+ while [[ "$#" -gt 0 ]]; do
44
+ case $1 in
45
+ --save) ACTION="save"; shift; DESCRIPTION="$1" ;;
46
+ --compress) ACTION="compress" ;;
47
+ --restore) ACTION="restore"; shift; RESTORE_FILE="$1" ;;
48
+ --list) ACTION="list" ;;
49
+ --clean) ACTION="clean" ;;
50
+ --json) OUTPUT_JSON=true ;;
51
+ --auto-compact) ACTION="auto_compact"; shift; TRIGGER_LEVEL="$1" ;;
52
+ *) if [ -z "$DESCRIPTION" ]; then DESCRIPTION="$1"; fi ;;
53
+ esac
54
+ shift 2>/dev/null || true
55
+ done
56
+
57
+ # 현재 스테이지 가져오기
58
+ get_current_stage() {
59
+ if [ -f "$PROGRESS_FILE" ] && command -v jq &> /dev/null; then
60
+ jq -r '.current_stage // "none"' "$PROGRESS_FILE"
61
+ else
62
+ echo "unknown"
63
+ fi
64
+ }
65
+
66
+ # 토큰 추정 (간단한 추정)
67
+ estimate_tokens() {
68
+ # 실제로는 대화 로그를 분석해야 하지만, 여기서는 placeholder
69
+ # 실제 구현에서는 Claude API나 로그 파일을 참조
70
+ echo "45000" # placeholder
71
+ }
72
+
73
+ # 진행률 바 생성
74
+ progress_bar() {
75
+ local percent=$1
76
+ local width=20
77
+ local filled=$((percent * width / 100))
78
+ local empty=$((width - filled))
79
+ printf "["
80
+ for ((i=0; i<filled; i++)); do printf "█"; done
81
+ for ((i=0; i<empty; i++)); do printf "░"; done
82
+ printf "]"
83
+ }
84
+
85
+ # 상태 표시
86
+ show_status() {
87
+ local CURRENT_STAGE=$(get_current_stage)
88
+ local ESTIMATED_TOKENS=$(estimate_tokens)
89
+ local PERCENT=$((ESTIMATED_TOKENS * 100 / LIMIT_THRESHOLD))
90
+
91
+ # 상태 결정
92
+ local STATUS_TEXT="정상"
93
+ local STATUS_COLOR=$GREEN
94
+ if [ "$ESTIMATED_TOKENS" -ge "$LIMIT_THRESHOLD" ]; then
95
+ STATUS_TEXT="한도 초과"
96
+ STATUS_COLOR=$RED
97
+ elif [ "$ESTIMATED_TOKENS" -ge "$WARNING_THRESHOLD" ]; then
98
+ STATUS_TEXT="경고"
99
+ STATUS_COLOR=$YELLOW
100
+ fi
101
+
102
+ if [ "$OUTPUT_JSON" = true ]; then
103
+ echo "{\"tokens\":$ESTIMATED_TOKENS,\"limit\":$LIMIT_THRESHOLD,\"warning\":$WARNING_THRESHOLD,\"stage\":\"$CURRENT_STAGE\",\"percent\":$PERCENT}"
104
+ return
105
+ fi
106
+
107
+ if [ "$ESTIMATED_TOKENS" -ge "$WARNING_THRESHOLD" ]; then
108
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
109
+ echo -e "⚠️ ${WHITE}Context Status${NC} - ${STATUS_COLOR}${STATUS_TEXT}${NC}"
110
+ else
111
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
112
+ echo -e "📊 ${WHITE}Context Status${NC}"
113
+ fi
114
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
115
+ echo ""
116
+ echo -e "토큰 사용량: ${CYAN}~${ESTIMATED_TOKENS}${NC} / ${LIMIT_THRESHOLD}"
117
+ echo -e "상태: $(progress_bar $PERCENT) ${PERCENT}% [${STATUS_COLOR}${STATUS_TEXT}${NC}]"
118
+ echo ""
119
+ echo "임계값:"
120
+ if [ "$ESTIMATED_TOKENS" -ge "$WARNING_THRESHOLD" ]; then
121
+ echo -e "• 경고 (${WARNING_THRESHOLD}): ${YELLOW}초과됨${NC}"
122
+ else
123
+ echo -e "• 경고 (${WARNING_THRESHOLD}): 여유 있음"
124
+ fi
125
+ echo -e "• 한도 (${LIMIT_THRESHOLD}): ~$((LIMIT_THRESHOLD - ESTIMATED_TOKENS)) 토큰 남음"
126
+ echo ""
127
+ echo -e "현재 스테이지: ${CYAN}$CURRENT_STAGE${NC}"
128
+
129
+ # 저장된 스냅샷 목록
130
+ if [ -d "$CONTEXT_DIR" ]; then
131
+ SNAPSHOTS=$(ls -1 "$CONTEXT_DIR"/state-*.md 2>/dev/null | wc -l | tr -d ' ')
132
+ if [ "$SNAPSHOTS" -gt 0 ]; then
133
+ echo ""
134
+ echo "[저장된 스냅샷]"
135
+ ls -1t "$CONTEXT_DIR"/state-*.md 2>/dev/null | head -3 | while read -r f; do
136
+ echo "• $(basename "$f")"
137
+ done
138
+ fi
139
+ fi
140
+
141
+ echo ""
142
+
143
+ # 경고 시 권장 조치
144
+ if [ "$ESTIMATED_TOKENS" -ge "$WARNING_THRESHOLD" ]; then
145
+ echo -e "${YELLOW}⚠️ 경고 임계값 초과!${NC}"
146
+ echo ""
147
+ echo "권장 조치:"
148
+ echo "1. /context --compress 로 압축"
149
+ echo "2. /context --save 후 /clear"
150
+ fi
151
+
152
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
153
+ }
154
+
155
+ # 스냅샷 저장
156
+ save_snapshot() {
157
+ local CURRENT_STAGE=$(get_current_stage)
158
+ local TIMESTAMP=$(date +%Y%m%d-%H%M)
159
+ local TIMESTAMP_READABLE=$(date "+%Y-%m-%d %H:%M")
160
+ local FILENAME="state-$TIMESTAMP.md"
161
+ local FILEPATH="$CONTEXT_DIR/$FILENAME"
162
+
163
+ if [ -z "$DESCRIPTION" ]; then
164
+ DESCRIPTION="컨텍스트 스냅샷"
165
+ fi
166
+
167
+ cat > "$FILEPATH" << EOF
168
+ # 작업 상태 저장 - $TIMESTAMP_READABLE
169
+
170
+ ## 설명
171
+ $DESCRIPTION
172
+
173
+ ## 현재 스테이지
174
+ $CURRENT_STAGE
175
+
176
+ ## 진행 상황
177
+ EOF
178
+
179
+ # progress.json에서 정보 추출
180
+ if [ -f "$PROGRESS_FILE" ] && command -v jq &> /dev/null; then
181
+ echo "" >> "$FILEPATH"
182
+ echo "### 스테이지 상태" >> "$FILEPATH"
183
+ jq -r '.stages | to_entries[] | "- \(.key): \(.value.status // "pending")"' "$PROGRESS_FILE" >> "$FILEPATH" 2>/dev/null || true
184
+ fi
185
+
186
+ cat >> "$FILEPATH" << EOF
187
+
188
+ ## 복구 지침
189
+ 1. 이 파일 읽기
190
+ 2. stages/$CURRENT_STAGE/CLAUDE.md 참조
191
+ 3. 작업 재개
192
+
193
+ ## 참조 파일
194
+ - state/progress.json
195
+ - stages/$CURRENT_STAGE/outputs/
196
+ EOF
197
+
198
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
199
+ echo -e "💾 ${WHITE}Context Snapshot Saved${NC}"
200
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
201
+ echo ""
202
+ echo -e "파일: ${CYAN}$FILEPATH${NC}"
203
+ echo -e "설명: $DESCRIPTION"
204
+ echo -e "스테이지: $CURRENT_STAGE"
205
+ echo ""
206
+ echo "[저장 내용]"
207
+ echo "✓ 현재 스테이지 정보"
208
+ echo "✓ 진행 상황"
209
+ echo "✓ 복구 지침"
210
+ echo ""
211
+ echo -e "복구: ${GREEN}/context --restore $FILENAME${NC}"
212
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
213
+ }
214
+
215
+ # 스냅샷 목록
216
+ list_snapshots() {
217
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
218
+ echo -e "📂 ${WHITE}Context Snapshots${NC}"
219
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
220
+ echo ""
221
+
222
+ if [ ! -d "$CONTEXT_DIR" ] || [ -z "$(ls -A "$CONTEXT_DIR"/*.md 2>/dev/null)" ]; then
223
+ echo -e " ${GRAY}저장된 스냅샷이 없습니다.${NC}"
224
+ echo ""
225
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
226
+ return
227
+ fi
228
+
229
+ printf " ${GRAY}%-25s %-15s %s${NC}\n" "파일" "크기" "수정일"
230
+ echo "─────────────────────────────────────────────────"
231
+
232
+ ls -1t "$CONTEXT_DIR"/*.md 2>/dev/null | while read -r f; do
233
+ SIZE=$(du -h "$f" | cut -f1)
234
+ MODIFIED=$(date -r "$f" "+%Y-%m-%d %H:%M" 2>/dev/null || stat -c %y "$f" 2>/dev/null | cut -d' ' -f1,2 | cut -d'.' -f1)
235
+ printf " %-25s %-15s %s\n" "$(basename "$f")" "$SIZE" "$MODIFIED"
236
+ done
237
+
238
+ echo ""
239
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
240
+ echo -e "복구: ${GREEN}/context --restore [filename]${NC}"
241
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
242
+ }
243
+
244
+ # 스냅샷 복구
245
+ restore_snapshot() {
246
+ local FILE="$RESTORE_FILE"
247
+
248
+ if [ -z "$FILE" ]; then
249
+ # 최신 스냅샷 찾기
250
+ FILE=$(ls -1t "$CONTEXT_DIR"/state-*.md 2>/dev/null | head -1)
251
+ if [ -z "$FILE" ]; then
252
+ echo -e "${RED}오류:${NC} 복구할 스냅샷이 없습니다."
253
+ exit 1
254
+ fi
255
+ FILE=$(basename "$FILE")
256
+ fi
257
+
258
+ local FILEPATH="$CONTEXT_DIR/$FILE"
259
+ if [ ! -f "$FILEPATH" ]; then
260
+ FILEPATH="$CONTEXT_DIR/state-$FILE"
261
+ fi
262
+ if [ ! -f "$FILEPATH" ]; then
263
+ echo -e "${RED}오류:${NC} 파일을 찾을 수 없습니다: $FILE"
264
+ echo " /context --list 로 목록을 확인하세요."
265
+ exit 1
266
+ fi
267
+
268
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
269
+ echo -e "📂 ${WHITE}Context Restore${NC}"
270
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
271
+ echo ""
272
+ echo -e "파일: ${CYAN}$(basename "$FILEPATH")${NC}"
273
+ echo ""
274
+ echo "[내용 미리보기]"
275
+ echo "─────────────────────────────────────────────────"
276
+ head -20 "$FILEPATH"
277
+ echo "..."
278
+ echo "─────────────────────────────────────────────────"
279
+ echo ""
280
+ echo "이 파일의 내용을 참조하여 작업을 계속하세요."
281
+ echo ""
282
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
283
+ }
284
+
285
+ # 압축 실행 (placeholder - 실제로는 AI가 처리)
286
+ compress_context() {
287
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
288
+ echo -e "🗜️ ${WHITE}Context Compression${NC}"
289
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
290
+ echo ""
291
+ echo "컨텍스트 압축을 실행합니다."
292
+ echo ""
293
+ echo "이 작업은 AI가 대화 내용을 분석하여:"
294
+ echo "• 핵심 결정사항 유지"
295
+ echo "• 긴 토론 요약"
296
+ echo "• 불필요한 내용 제거"
297
+ echo ""
298
+ echo "context-compression 스킬이 활성화됩니다."
299
+ echo ""
300
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
301
+ }
302
+
303
+ # 자동 컨텍스트 관리 (Statusline API 트리거)
304
+ auto_compact() {
305
+ local LEVEL="${TRIGGER_LEVEL:-warning}"
306
+ local TIMESTAMP=$(date +%Y%m%d-%H%M%S)
307
+ local SNAPSHOT_FILE="$CONTEXT_DIR/auto-snapshot-$TIMESTAMP.md"
308
+ local CURRENT_STAGE=$(get_current_stage)
309
+ local TRIGGER_FILE="$CONTEXT_DIR/auto-trigger.json"
310
+
311
+ # 트리거 정보 읽기
312
+ local REMAINING="50"
313
+ if [ -f "$TRIGGER_FILE" ]; then
314
+ REMAINING=$(jq -r '.remaining // 50' "$TRIGGER_FILE" 2>/dev/null || echo "50")
315
+ fi
316
+
317
+ echo ""
318
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
319
+ echo -e "🔄 ${WHITE}자동 컨텍스트 관리${NC}"
320
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
321
+ echo ""
322
+
323
+ if [ "$LEVEL" = "critical" ]; then
324
+ echo -e "${RED}⚠️ 크리티컬: 잔여 컨텍스트 40% 이하${NC}"
325
+ else
326
+ echo -e "${YELLOW}⚠️ 경고: 잔여 컨텍스트 50% 이하 (${REMAINING}%)${NC}"
327
+ fi
328
+ echo ""
329
+
330
+ # Step 1: 스냅샷 저장
331
+ echo "📸 스냅샷 저장 중..."
332
+
333
+ cat > "$SNAPSHOT_FILE" << EOF
334
+ # 자동 저장된 컨텍스트 스냅샷
335
+ - 저장 시간: $(date "+%Y-%m-%d %H:%M:%S")
336
+ - 현재 스테이지: $CURRENT_STAGE
337
+ - 트리거: 잔여 컨텍스트 ${REMAINING}% (레벨: $LEVEL)
338
+
339
+ ## 현재 진행 상황
340
+ EOF
341
+
342
+ # progress.json에서 스테이지 상태 추출
343
+ if [ -f "$PROGRESS_FILE" ] && command -v jq &> /dev/null; then
344
+ echo "" >> "$SNAPSHOT_FILE"
345
+ echo "### 스테이지 상태" >> "$SNAPSHOT_FILE"
346
+ jq -r '.stages | to_entries[] | select(.value.status != "pending") | "- \(.key): \(.value.status)"' "$PROGRESS_FILE" >> "$SNAPSHOT_FILE" 2>/dev/null || true
347
+
348
+ # 최근 체크포인트 정보
349
+ local CHECKPOINTS=$(jq -r '.checkpoints // [] | length' "$PROGRESS_FILE" 2>/dev/null || echo "0")
350
+ if [ "$CHECKPOINTS" -gt 0 ]; then
351
+ echo "" >> "$SNAPSHOT_FILE"
352
+ echo "### 체크포인트" >> "$SNAPSHOT_FILE"
353
+ echo "- 총 체크포인트: $CHECKPOINTS 개" >> "$SNAPSHOT_FILE"
354
+ jq -r '.checkpoints[-1] // empty | "- 최근: \(.name // .timestamp)"' "$PROGRESS_FILE" >> "$SNAPSHOT_FILE" 2>/dev/null || true
355
+ fi
356
+ fi
357
+
358
+ cat >> "$SNAPSHOT_FILE" << EOF
359
+
360
+ ## 복구 지침
361
+ 1. 이 파일 읽기
362
+ 2. stages/$CURRENT_STAGE/CLAUDE.md 참조
363
+ 3. stages/$CURRENT_STAGE/HANDOFF.md 참조 (있는 경우)
364
+ 4. 작업 재개
365
+
366
+ ## 참조 파일
367
+ - state/progress.json
368
+ - stages/$CURRENT_STAGE/outputs/
369
+ EOF
370
+
371
+ echo -e "${GREEN}✓${NC} 스냅샷 저장 완료: $(basename "$SNAPSHOT_FILE")"
372
+ echo ""
373
+
374
+ # progress.json에 스냅샷 기록
375
+ if [ -f "$PROGRESS_FILE" ] && command -v jq &> /dev/null; then
376
+ # context_snapshots 배열이 없으면 생성
377
+ local HAS_SNAPSHOTS=$(jq 'has("context_snapshots")' "$PROGRESS_FILE" 2>/dev/null || echo "false")
378
+ if [ "$HAS_SNAPSHOTS" = "false" ]; then
379
+ jq '. + {"context_snapshots": []}' "$PROGRESS_FILE" > "$PROGRESS_FILE.tmp" && mv "$PROGRESS_FILE.tmp" "$PROGRESS_FILE"
380
+ fi
381
+
382
+ # 스냅샷 정보 추가
383
+ jq ".context_snapshots += [{\"file\": \"$SNAPSHOT_FILE\", \"reason\": \"auto-${LEVEL}\", \"remaining\": $REMAINING, \"timestamp\": \"$(date -Iseconds)\"}]" \
384
+ "$PROGRESS_FILE" > "$PROGRESS_FILE.tmp" && mv "$PROGRESS_FILE.tmp" "$PROGRESS_FILE"
385
+ fi
386
+
387
+ # Step 2: 권장 조치 안내
388
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
389
+ if [ "$LEVEL" = "critical" ]; then
390
+ echo -e "${RED}⚠️ 컨텍스트 임계값 도달 (40% 이하)${NC}"
391
+ echo ""
392
+ echo -e "스냅샷이 자동 저장되었습니다: ${CYAN}$(basename "$SNAPSHOT_FILE")${NC}"
393
+ echo ""
394
+
395
+ # 사용자 확인 프롬프트
396
+ echo -e "${WHITE}컨텍스트를 초기화하시겠습니까?${NC}"
397
+ echo ""
398
+ echo " [y] /clear 실행 (스냅샷에서 복구 가능)"
399
+ echo " [c] /compact 실행 (대화 요약 후 계속)"
400
+ echo " [n] 취소 (수동으로 처리)"
401
+ echo ""
402
+ read -p "선택 [y/c/n]: " -n 1 -r CLEAR_CHOICE
403
+ echo ""
404
+ echo ""
405
+
406
+ case $CLEAR_CHOICE in
407
+ [Yy])
408
+ echo -e "${GREEN}✓${NC} /clear 실행 중..."
409
+ echo ""
410
+
411
+ # 복구 정보 저장
412
+ echo "{\"action\": \"clear\", \"snapshot\": \"$SNAPSHOT_FILE\", \"timestamp\": \"$(date -Iseconds)\"}" > "$CONTEXT_DIR/pending-clear.json"
413
+
414
+ # tmux를 통해 /clear 자동 실행
415
+ if [ -n "$TMUX" ]; then
416
+ # 현재 tmux 세션에서 실행
417
+ sleep 1
418
+ tmux send-keys "/clear" Enter
419
+ echo -e "${GREEN}✓${NC} /clear 명령이 전송되었습니다."
420
+ elif tmux list-sessions 2>/dev/null | grep -q "claude"; then
421
+ # claude 세션 찾아서 전송
422
+ CLAUDE_SESSION=$(tmux list-sessions 2>/dev/null | grep "claude" | head -1 | cut -d: -f1)
423
+ tmux send-keys -t "$CLAUDE_SESSION" "/clear" Enter
424
+ echo -e "${GREEN}✓${NC} /clear 명령이 '$CLAUDE_SESSION' 세션으로 전송되었습니다."
425
+ else
426
+ echo -e "${YELLOW}⚠️${NC} tmux 세션을 찾을 수 없습니다."
427
+ echo "다음 명령을 수동으로 실행하세요:"
428
+ echo -e "${CYAN}/clear${NC}"
429
+ fi
430
+
431
+ echo ""
432
+ echo "복구 시:"
433
+ echo -e "${CYAN}/context --restore $(basename "$SNAPSHOT_FILE")${NC}"
434
+ ;;
435
+ [Cc])
436
+ echo -e "${GREEN}✓${NC} /compact 실행 중..."
437
+ echo ""
438
+
439
+ # tmux를 통해 /compact 자동 실행
440
+ if [ -n "$TMUX" ]; then
441
+ sleep 1
442
+ tmux send-keys "/compact" Enter
443
+ echo -e "${GREEN}✓${NC} /compact 명령이 전송되었습니다."
444
+ elif tmux list-sessions 2>/dev/null | grep -q "claude"; then
445
+ CLAUDE_SESSION=$(tmux list-sessions 2>/dev/null | grep "claude" | head -1 | cut -d: -f1)
446
+ tmux send-keys -t "$CLAUDE_SESSION" "/compact" Enter
447
+ echo -e "${GREEN}✓${NC} /compact 명령이 '$CLAUDE_SESSION' 세션으로 전송되었습니다."
448
+ else
449
+ echo -e "${YELLOW}⚠️${NC} tmux 세션을 찾을 수 없습니다."
450
+ echo "다음 명령을 수동으로 실행하세요:"
451
+ echo -e "${CYAN}/compact${NC}"
452
+ fi
453
+ ;;
454
+ *)
455
+ echo "취소되었습니다. 수동으로 /clear 또는 /compact를 실행하세요."
456
+ ;;
457
+ esac
458
+ else
459
+ echo -e "${YELLOW}⚠️ /compact 실행을 권장합니다${NC}"
460
+ echo ""
461
+ echo "실행 후 자동으로 스냅샷에서 복구됩니다."
462
+ echo "저장된 스냅샷: $(basename "$SNAPSHOT_FILE")"
463
+ fi
464
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
465
+
466
+ # 터미널 벨 (알림)
467
+ echo -e "\a"
468
+ }
469
+
470
+ # 오래된 스냅샷 정리
471
+ clean_snapshots() {
472
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
473
+ echo -e "🧹 ${WHITE}Clean Old Snapshots${NC}"
474
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
475
+ echo ""
476
+
477
+ # 7일 이상 된 스냅샷 찾기
478
+ OLD_FILES=$(find "$CONTEXT_DIR" -name "state-*.md" -mtime +7 2>/dev/null)
479
+
480
+ if [ -z "$OLD_FILES" ]; then
481
+ echo "정리할 오래된 스냅샷이 없습니다."
482
+ else
483
+ echo "다음 파일이 삭제됩니다 (7일 이상):"
484
+ echo "$OLD_FILES" | while read -r f; do
485
+ echo " - $(basename "$f")"
486
+ done
487
+ echo ""
488
+ read -p "삭제하시겠습니까? [y/N] " -n 1 -r
489
+ echo
490
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
491
+ echo "$OLD_FILES" | xargs rm -f
492
+ echo -e "${GREEN}✓${NC} 정리 완료"
493
+ else
494
+ echo "취소되었습니다."
495
+ fi
496
+ fi
497
+
498
+ echo ""
499
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
500
+ }
501
+
502
+ # 메인 로직
503
+ case $ACTION in
504
+ status)
505
+ show_status
506
+ ;;
507
+ save)
508
+ save_snapshot
509
+ ;;
510
+ compress)
511
+ compress_context
512
+ ;;
513
+ restore)
514
+ restore_snapshot
515
+ ;;
516
+ list)
517
+ list_snapshots
518
+ ;;
519
+ clean)
520
+ clean_snapshots
521
+ ;;
522
+ auto_compact)
523
+ auto_compact
524
+ ;;
525
+ *)
526
+ show_status
527
+ ;;
528
+ esac