1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Shared state for all command handlers
//!
//! Provides thread-local storage for the current archive that is shared
//! across all handler modules (archive, file, etc.)
//!
//! # ⚠️ TEMPORARY WORKAROUND IMPLEMENTATION
//!
//! **Status:** This is the ACTUAL state management implementation currently in use.
//!
//! **Why This Exists:** `unilang::ExecutionContext` does not yet support passing custom
//! state to command handlers. This thread-local storage is the workaround to share
//! archive state across handler function calls within a single CLI invocation or REPL
//! session. See Workaround comments in `main.rs` and `repl.rs` for context.
//!
//! **Trade-offs of Thread-Local Approach:**
//! - ✅ Works with current unilang API constraints
//! - ✅ Simple, no lifetime/borrow complexity
//! - ⚠️ Thread-isolated (each thread has separate state)
//! - ⚠️ Global mutable state (less explicit than passing through context)
//! - ⚠️ Architectural debt vs. specification design
//!
//! **Migration Path:** When `ExecutionContext` gains state support, pass the archive
//! through context in each handler and delete this module entirely.
//!
//! ## Architectural Validation (2025-01-25)
//!
//! Comprehensive exploration of unilang codebase confirms this approach is correct:
//!
//! - **`ExecutionContext` Status**: Currently empty placeholder struct with no fields
//! - **Unilang Philosophy**: Explicitly stateless by design per pipeline.rs docs
//! - **Use Case Fit**: Single-threaded REPL doesn't require cross-thread state sharing
//!
//! **Conclusion**: This thread-local pattern is the recommended approach given current
//! unilang API constraints. Delete this module once `ExecutionContext` supports state.
use RefCell;
use TemplateArchive;
thread_local!