oden-forge 2.5.0 โ†’ 3.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.
@@ -0,0 +1,447 @@
1
+ #!/bin/bash
2
+ # Context Preservation Utility Script
3
+ # Created: 2026-03-27T07:09:47Z
4
+ # Purpose: Implement context preservation commands
5
+
6
+ set -e
7
+
8
+ # Configuration
9
+ MEMORY_DIR=".claude/memory"
10
+ SESSIONS_DIR="$MEMORY_DIR/sessions"
11
+ PATTERNS_DIR="$MEMORY_DIR/patterns"
12
+ DECISIONS_DIR="$MEMORY_DIR/decisions"
13
+ KNOWLEDGE_DIR="$MEMORY_DIR/knowledge"
14
+
15
+ # Ensure memory directories exist
16
+ ensure_memory_structure() {
17
+ mkdir -p "$SESSIONS_DIR" "$PATTERNS_DIR" "$DECISIONS_DIR" "$KNOWLEDGE_DIR"
18
+ }
19
+
20
+ # Get current timestamp in ISO format
21
+ get_timestamp() {
22
+ date -u +"%Y-%m-%dT%H:%M:%SZ"
23
+ }
24
+
25
+ # Create session snapshot
26
+ create_snapshot() {
27
+ local description="${1:-"Work session snapshot"}"
28
+ local timestamp=$(get_timestamp)
29
+ local branch=$(git branch --show-current 2>/dev/null || echo "main")
30
+ local session_file="$SESSIONS_DIR/$(echo $timestamp | sed 's/[:-]//g' | sed 's/T.*//g')-snapshot.md"
31
+
32
+ echo "๐Ÿ“ธ Creating context snapshot..."
33
+
34
+ # Get git status info
35
+ local changed_files=$(git diff --name-only 2>/dev/null | head -10 | tr '\n' ' ' || echo "none")
36
+ local staged_files=$(git diff --staged --name-only 2>/dev/null | head -5 | tr '\n' ' ' || echo "none")
37
+ local recent_commit=$(git log -1 --oneline 2>/dev/null || echo "No commits")
38
+ local git_status=$(git status --porcelain 2>/dev/null || echo "No changes")
39
+
40
+ # Create snapshot file
41
+ cat > "$session_file" << EOF
42
+ ---
43
+ created: $timestamp
44
+ session_type: implementation
45
+ branch: $branch
46
+ status: active
47
+ context_size: medium
48
+ description: $description
49
+ ---
50
+
51
+ # Session Snapshot: $description
52
+
53
+ ## Quick Summary
54
+ - **What:** $description
55
+ - **Files changed:** $changed_files
56
+ - **Files staged:** $staged_files
57
+ - **Current state:** Active development
58
+
59
+ ## Context for Next Session
60
+
61
+ ### Recent Activity
62
+ $recent_commit
63
+
64
+ ### Current Working State
65
+ \`\`\`
66
+ $git_status
67
+ \`\`\`
68
+
69
+ ### Architectural Decisions Made
70
+ $(git log --oneline -3 2>/dev/null | sed 's/^/- /' || echo "- No recent commits")
71
+
72
+ ### Known Issues
73
+ - None identified yet
74
+
75
+ ### Next Steps
76
+ - Continue current implementation
77
+ - Run tests when ready
78
+ - Review for pattern compliance
79
+
80
+ ## Files Modified This Session
81
+ $(echo "$changed_files" | tr ' ' '\n' | sed 's/^/- /' | grep -v '^- $')
82
+
83
+ ## Patterns Potentially Created
84
+ - Check for reusable functions in modified files
85
+ - Update pattern library if valuable patterns found
86
+
87
+ ## Session Notes
88
+ Add any important context, decisions, or learnings from this session here.
89
+
90
+ ---
91
+ *Session captured: $timestamp*
92
+ *Next session: Run '/oden:context restore' to load this context*
93
+ EOF
94
+
95
+ echo "โœ… Context snapshot saved: $session_file"
96
+ echo "๐Ÿ“ Description: $description"
97
+ echo "๐ŸŒฟ Branch: $branch"
98
+ echo "๐Ÿ“ Files: $changed_files"
99
+ }
100
+
101
+ # Detect duplicate patterns
102
+ detect_patterns() {
103
+ echo "๐Ÿ” Scanning for duplicate patterns..."
104
+
105
+ local report_file="$PATTERNS_DIR/duplicate-report.md"
106
+ local timestamp=$(get_timestamp)
107
+
108
+ # Create report header
109
+ cat > "$report_file" << EOF
110
+ ---
111
+ created: $timestamp
112
+ scan_type: duplicate_detection
113
+ files_scanned: 0
114
+ duplicates_found: 0
115
+ ---
116
+
117
+ # Duplicate Pattern Detection Report
118
+
119
+ **Generated:** $timestamp
120
+ **Scan scope:** src/
121
+
122
+ ## Summary
123
+ EOF
124
+
125
+ # Find source files
126
+ local source_files=$(find src -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" 2>/dev/null || echo "")
127
+
128
+ if [ -z "$source_files" ]; then
129
+ echo "No source files found in src/ directory" >> "$report_file"
130
+ echo "โš ๏ธ No source files found to scan"
131
+ return 0
132
+ fi
133
+
134
+ # Count files
135
+ local file_count=$(echo "$source_files" | wc -l)
136
+
137
+ # Extract function definitions
138
+ local temp_functions="/tmp/oden-functions-$$.txt"
139
+ echo "$source_files" | xargs grep -n "function\|const.*=.*=>\|export.*function\|export.*const.*=" 2>/dev/null | \
140
+ grep -v "test\|spec" > "$temp_functions" || touch "$temp_functions"
141
+
142
+ local total_functions=$(wc -l < "$temp_functions" 2>/dev/null || echo 0)
143
+
144
+ # Update summary
145
+ sed -i '' "s/files_scanned: 0/files_scanned: $file_count/" "$report_file"
146
+ echo "- **Files scanned:** $file_count" >> "$report_file"
147
+ echo "- **Functions found:** $total_functions" >> "$report_file"
148
+ echo "" >> "$report_file"
149
+
150
+ # Analyze for duplicates (simple name-based detection for now)
151
+ if [ -s "$temp_functions" ]; then
152
+ echo "## Potential Duplicates" >> "$report_file"
153
+ echo "" >> "$report_file"
154
+
155
+ # Extract function names and count occurrences
156
+ local duplicates_found=false
157
+ sed 's/.*function \([^(]*\).*/\1/' "$temp_functions" | \
158
+ sed 's/.*const \([^=]*\) *=.*/\1/' | \
159
+ sed 's/.*export.*\(function\|const\) \([^(= ]*\).*/\2/' | \
160
+ sort | uniq -c | sort -nr | while read count name; do
161
+ if [ "$count" -gt 1 ] && [ -n "$name" ]; then
162
+ echo "### ๐Ÿšจ Potential Duplicate: \`$name\` ($count occurrences)" >> "$report_file"
163
+
164
+ # Find specific occurrences
165
+ grep "$name" "$temp_functions" | head -3 | while read line; do
166
+ echo "- $line" >> "$report_file"
167
+ done
168
+ echo "" >> "$report_file"
169
+ duplicates_found=true
170
+ fi
171
+ done
172
+
173
+ if ! $duplicates_found; then
174
+ echo "โœ… No obvious duplicates detected!" >> "$report_file"
175
+ fi
176
+ else
177
+ echo "No functions found to analyze" >> "$report_file"
178
+ fi
179
+
180
+ # Add recommendations
181
+ cat >> "$report_file" << EOF
182
+
183
+ ## Recommendations
184
+
185
+ ### For Detected Duplicates
186
+ 1. **Review** each duplicate to confirm they serve the same purpose
187
+ 2. **Choose** the best implementation as canonical
188
+ 3. **Refactor** others to use the canonical version
189
+ 4. **Update** imports throughout codebase
190
+
191
+ ### Prevention
192
+ 1. **Search existing patterns** before implementing new functions
193
+ 2. **Use** \`/oden:context detect\` regularly during development
194
+ 3. **Establish** canonical patterns in pattern library
195
+
196
+ ## Next Steps
197
+ 1. Review flagged duplicates above
198
+ 2. Run \`/oden:context patterns\` to see established patterns
199
+ 3. Consider adding valuable patterns to library
200
+
201
+ ---
202
+ *Scan completed: $timestamp*
203
+ *Next scan: Re-run after major changes or weekly*
204
+ EOF
205
+
206
+ # Cleanup
207
+ rm -f "$temp_functions"
208
+
209
+ echo "โœ… Pattern detection completed"
210
+ echo "๐Ÿ“Š Report saved: $report_file"
211
+ echo "๐Ÿ“ Files scanned: $file_count"
212
+ echo "๐Ÿ” Functions analyzed: $total_functions"
213
+ }
214
+
215
+ # Check architecture compliance
216
+ check_drift() {
217
+ echo "๐ŸŽฏ Checking architecture compliance..."
218
+
219
+ local report_file="$DECISIONS_DIR/drift-report.md"
220
+ local timestamp=$(get_timestamp)
221
+ local violations=0
222
+
223
+ cat > "$report_file" << EOF
224
+ ---
225
+ created: $timestamp
226
+ check_type: architecture_drift
227
+ violations_found: 0
228
+ compliance_score: 100
229
+ ---
230
+
231
+ # Architecture Drift Report
232
+
233
+ **Generated:** $timestamp
234
+ **Rules:** compliance-rules.yaml
235
+
236
+ ## Summary
237
+ - **Total violations:** 0
238
+ - **Compliance score:** 100%
239
+ - **Status:** โœ… All checks passed
240
+
241
+ ## Detailed Analysis
242
+
243
+ EOF
244
+
245
+ # Check file size violations
246
+ echo "### ๐Ÿ“ File Size Check" >> "$report_file"
247
+ local size_violations=0
248
+
249
+ find src -name "*.ts" -o -name "*.tsx" 2>/dev/null | while read file; do
250
+ if [ -f "$file" ]; then
251
+ local lines=$(wc -l < "$file")
252
+ if [ "$lines" -gt 500 ]; then
253
+ echo "โŒ \`$file\`: $lines lines (limit: 500)" >> "$report_file"
254
+ size_violations=$((size_violations + 1))
255
+ violations=$((violations + 1))
256
+ fi
257
+ fi
258
+ done
259
+
260
+ if [ "$size_violations" -eq 0 ]; then
261
+ echo "โœ… All files within size limits" >> "$report_file"
262
+ fi
263
+
264
+ echo "" >> "$report_file"
265
+
266
+ # Check import patterns
267
+ echo "### ๐Ÿ“ฆ Import Pattern Check" >> "$report_file"
268
+ local import_violations=0
269
+
270
+ if find src -name "*.ts" -o -name "*.tsx" 2>/dev/null | xargs grep -l "from 'axios'" 2>/dev/null; then
271
+ echo "โŒ Direct axios imports found (use fetch wrapper)" >> "$report_file"
272
+ import_violations=$((import_violations + 1))
273
+ violations=$((violations + 1))
274
+ fi
275
+
276
+ if find src -name "*.ts" -o -name "*.tsx" 2>/dev/null | xargs grep -l "from '../../../" 2>/dev/null; then
277
+ echo "โŒ Deep relative imports found (use absolute imports)" >> "$report_file"
278
+ import_violations=$((import_violations + 1))
279
+ violations=$((violations + 1))
280
+ fi
281
+
282
+ if [ "$import_violations" -eq 0 ]; then
283
+ echo "โœ… No problematic import patterns detected" >> "$report_file"
284
+ fi
285
+
286
+ echo "" >> "$report_file"
287
+
288
+ # Calculate compliance score
289
+ local total_checks=2
290
+ local passed_checks=$((total_checks - violations))
291
+ local compliance_score=$((passed_checks * 100 / total_checks))
292
+
293
+ # Update summary
294
+ sed -i '' "s/violations_found: 0/violations_found: $violations/" "$report_file"
295
+ sed -i '' "s/compliance_score: 100/compliance_score: $compliance_score/" "$report_file"
296
+
297
+ if [ "$violations" -eq 0 ]; then
298
+ sed -i '' "s/Status:.*/Status: โœ… All checks passed/" "$report_file"
299
+ echo "โœ… Architecture compliance: 100%"
300
+ else
301
+ sed -i '' "s/Status:.*/Status: โŒ $violations violations found/" "$report_file"
302
+ echo "โŒ Architecture violations: $violations"
303
+ echo "๐Ÿ“Š Compliance score: $compliance_score%"
304
+ fi
305
+
306
+ echo "๐Ÿ“Š Report saved: $report_file"
307
+ }
308
+
309
+ # Restore context for new session
310
+ restore_context() {
311
+ echo "๐Ÿง  Restoring context for new session..."
312
+
313
+ # Find most recent session
314
+ local latest_session=$(ls -t "$SESSIONS_DIR"/*.md 2>/dev/null | head -1)
315
+
316
+ if [ -z "$latest_session" ]; then
317
+ echo "โš ๏ธ No previous session found"
318
+ echo "๐Ÿ’ก Start with: /oden:context snapshot 'session description'"
319
+ return 1
320
+ fi
321
+
322
+ echo "๐Ÿ“– Loading context from: $(basename "$latest_session")"
323
+ echo ""
324
+
325
+ # Extract key information
326
+ local branch=$(grep "^branch:" "$latest_session" | cut -d: -f2 | tr -d ' ' || echo "unknown")
327
+ local description=$(grep "^description:" "$latest_session" | cut -d: -f2- | tr -d ' ')
328
+ local created=$(grep "^created:" "$latest_session" | cut -d: -f2- | tr -d ' ')
329
+
330
+ echo "๐ŸŒฟ **Previous branch:** $branch"
331
+ echo "๐Ÿ“ **Previous work:** $description"
332
+ echo "โฐ **Last session:** $created"
333
+ echo ""
334
+
335
+ # Show quick summary
336
+ echo "๐Ÿ“‹ **Quick Summary:**"
337
+ sed -n '/## Quick Summary/,/## Context for Next Session/p' "$latest_session" | \
338
+ grep -v "^## " | sed 's/^/ /'
339
+
340
+ echo ""
341
+ echo "๐ŸŽฏ **Recommended next actions:**"
342
+ echo " 1. Review latest changes: git status"
343
+ echo " 2. Check for patterns: /oden:context detect"
344
+ echo " 3. Verify compliance: /oden:context drift"
345
+ echo " 4. Continue with: /oden:work [epic/issue]"
346
+ }
347
+
348
+ # Show memory statistics
349
+ show_memory() {
350
+ echo "๐Ÿ“š Project Memory Statistics"
351
+ echo "โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•"
352
+ echo ""
353
+
354
+ local sessions=$(ls "$SESSIONS_DIR"/*.md 2>/dev/null | wc -l || echo 0)
355
+ local patterns=$(ls "$PATTERNS_DIR"/*.md 2>/dev/null | wc -l || echo 0)
356
+ local decisions=$(ls "$DECISIONS_DIR"/*.md 2>/dev/null | wc -l || echo 0)
357
+ local knowledge=$(ls "$KNOWLEDGE_DIR"/*.md 2>/dev/null | wc -l || echo 0)
358
+
359
+ echo "๐Ÿ“Š **Components:**"
360
+ echo " Sessions recorded: $sessions"
361
+ echo " Pattern files: $patterns"
362
+ echo " Decision logs: $decisions"
363
+ echo " Knowledge docs: $knowledge"
364
+ echo ""
365
+
366
+ if [ "$sessions" -gt 0 ]; then
367
+ local latest_session=$(ls -t "$SESSIONS_DIR"/*.md 2>/dev/null | head -1)
368
+ local latest_date=$(basename "$latest_session" | cut -d'-' -f1-3 | sed 's/-//g')
369
+ echo "๐Ÿ•’ **Latest activity:** $latest_date"
370
+ else
371
+ echo "๐Ÿ•’ **Latest activity:** No sessions recorded"
372
+ fi
373
+
374
+ echo ""
375
+ echo "๐Ÿ’พ **Storage usage:**"
376
+ echo " Total size: $(du -sh "$MEMORY_DIR" 2>/dev/null | cut -f1 || echo "0B")"
377
+ echo ""
378
+
379
+ echo "๐ŸŽฏ **Quick actions:**"
380
+ echo " Create snapshot: /oden:context snapshot 'description'"
381
+ echo " Detect patterns: /oden:context detect"
382
+ echo " Check compliance: /oden:context drift"
383
+ echo " Restore context: /oden:context restore"
384
+ }
385
+
386
+ # Clean old memory
387
+ clean_memory() {
388
+ echo "๐Ÿงน Cleaning old memory..."
389
+
390
+ # Remove sessions older than 30 days
391
+ find "$SESSIONS_DIR" -name "*.md" -mtime +30 -delete 2>/dev/null || true
392
+
393
+ # Remove temporary files
394
+ find "$MEMORY_DIR" -name "*.tmp" -delete 2>/dev/null || true
395
+
396
+ echo "โœ… Memory cleaned"
397
+ echo "๐Ÿ“Š Current usage: $(du -sh "$MEMORY_DIR" 2>/dev/null | cut -f1 || echo "0B")"
398
+ }
399
+
400
+ # Main command dispatcher
401
+ main() {
402
+ local command="${1:-help}"
403
+ local description="$2"
404
+
405
+ ensure_memory_structure
406
+
407
+ case "$command" in
408
+ "snapshot")
409
+ create_snapshot "$description"
410
+ ;;
411
+ "detect")
412
+ detect_patterns
413
+ ;;
414
+ "drift")
415
+ check_drift
416
+ ;;
417
+ "restore")
418
+ restore_context
419
+ ;;
420
+ "memory")
421
+ show_memory
422
+ ;;
423
+ "clean")
424
+ clean_memory
425
+ ;;
426
+ "help")
427
+ echo "Context Preservation System"
428
+ echo ""
429
+ echo "Usage:"
430
+ echo " $0 snapshot [description] - Create context snapshot"
431
+ echo " $0 detect - Detect duplicate patterns"
432
+ echo " $0 drift - Check architecture compliance"
433
+ echo " $0 restore - Restore context from last session"
434
+ echo " $0 memory - Show memory statistics"
435
+ echo " $0 clean - Clean old memory files"
436
+ echo ""
437
+ ;;
438
+ *)
439
+ echo "โŒ Unknown command: $command"
440
+ echo "๐Ÿ’ก Use '$0 help' for usage information"
441
+ exit 1
442
+ ;;
443
+ esac
444
+ }
445
+
446
+ # Run main function with all arguments
447
+ main "$@"