Commit 2dd58c0
feat(ai): Improve CX Linux native model integration and CLI UX
* Add cx ai download command for model management
- Implement AICommand with download subcommand
- Downloads cortex-linux-7b model from HuggingFace
- Supports --force and --verbose flags
- Verifies download size and provides user feedback
- Integrates LlamaCppProvider for native inference
* feat(ai): improve CX Linux model integration and UX
- Add 'ai' as top-level CLI command (wezterm ai download)
- Fix broken symlink handling in model download (use absolute symlinks)
- Add stderr suppression for clean output (RAII guard pattern)
- Change provider priority: Claude > OpenAI > Ollama > CXLinux
- Add user-friendly messages for model status
* fix(cli): clean up verbose output and add model loading message
* style: apply cargo fmt formatting
* fix: use correct HuggingFace repo ShreemJ/cortex-linux-7b
* fix: code quality improvements for AI integration
- Fix sampling logic: use nanosecond-seeded LCG for non-deterministic output
- Add BSL 1.1 license headers to llamacpp.rs, ai.rs, ask.rs
- Update branding from cortex-linux-7b to cxlinux-ai-7b
- Replace deprecated dirs_next with dirs crate
- Add #[cfg(unix)] guards for cross-platform compatibility
- Optimize EOS detection in generation loop
- Add llama-cpp-2 build deps for Fedora, Alpine, Arch, SUSE
- Create shared model_utils.rs to eliminate code duplication
* chore: update unsafe impl comment and format imports
- Replace safety comment with intent-focused explanation for Send+Sync
- Reformat model_utils imports to satisfy rustfmt
* fix: critical llamacpp provider improvements
- Security: Replace unsafe /tmp fallback with $HOME/.cache
- Reliability: Fix download path mismatch (symlink/copy to expected location)
- Correctness: Add accumulator to detect split end-markers
- Runtime: Replace block_in_place with spawn_blocking for single-threaded compatibility
- Config: Add TODO for temperature support (API limitation)
- Tests: Update for Result types and simplify format_prompt test
* fix: remove TODO comment for temperature (not implemented)
* Fix temperature sampling, stderr handling, and token validation
- Apply temperature via LlamaSampler::temp() in LlamaCppProvider::generate()
- Drop StderrGuard after context creation to restore stderr before token generation
- Add token count validation before batch creation to prevent context overflow
- Update test_format_prompt to properly exercise format_prompt implementation
Fixes #687
* Refactor: improve safety, error handling, and code quality
- Remove unsafe Send/Sync impls (Arc already provides these traits)
- Fix max_tokens overflow by limiting to remaining context slots
- Apply rustfmt to test code for consistency
- Replace eprintln! with log::debug! for structured logging
- Propagate errors when --local is used instead of silent fallback
- Update comments to WHY-only with 'CX Terminal:' prefix
- Fix prompt validation to use >= 2048 and limit generation to available slots
References: #687
* Fix async runtime safety and improve error handling
- Replace block_in_place with spawn_blocking in chat_completion_stream
to prevent panics on single-threaded Tokio runtimes
- Add proper error checking for dup/dup2 syscalls in stderr redirection
to avoid invalid file descriptors and ensure safe cleanup
- Convert WHAT/HOW comments to WHY-only intent comments
- Add 'CX Terminal:' prefix to CX-specific behavior notes
References: #687
* Fix symlink handling and improve model compatibility
- Detect and remove stale symlinks before creating new ones
to prevent failures with broken symlink paths
- Remove hardcoded GPU layers (with_n_gpu_layers) to support CPU-only systems
- Increase context window from 2048 to 4096 tokens to align with GUI
- Update all related validation and batch size limits to 4096
References: #687
* refactor: Apply rustfmt and improve code quality
- Run cargo +nightly fmt on symlink creation block (llamacpp.rs:147-165)
- Update stderr restore comment for clarity (ask.rs:321)
- Add comprehensive test coverage for query_local function
- Test missing model error handling
- Test stderr suppression in verbose/non-verbose modes
- Test command structure and cloning
- Test output format handling
The rustfmt changes ensure proper formatting of the #[cfg(unix)]
conditional compilation block while keeping AIError::ApiError error
mapping semantically unchanged.
The comment update better explains that stderr is restored to make
inference errors visible, not just because model loading is complete.
The new tests provide targeted coverage for query_local code paths
to improve overall test coverage toward the 95%+ project requirement.
* fix: Improve token limits, error hints, and workspace dependencies
- Reserve 512 tokens for response generation in context window check
Previously allowed up to 4095 prompt tokens, leaving only 1 token
for response. Now enforces max 3584 prompt tokens (4096 - 512).
- Track local model failures for accurate error hints
Added local_attempted flag to distinguish between:
- Model not installed (suggest cx ai download)
- Model failed to load (suggest cloud providers)
- Cloud API not configured (generic message)
- Centralize AI dependencies in workspace
Moved llama-cpp-2 and hf-hub to [workspace.dependencies] in root
Cargo.toml for consistent version management across cx-terminal
and cx-terminal-gui packages.
- Use workspace references for dirs and tokio in wezterm/Cargo.toml
Replaces direct version specifications with workspace references
to ensure consistency across the workspace.
Addresses CodeRabbit review feedback and improves user experience
when AI backends are unavailable or fail to initialize.
* style: Apply rustfmt whitespace formatting to llamacpp.rs
Minor whitespace adjustments from cargo +nightly fmt run.
* refactor: Address code review feedback
Cache Directory Consistency:
- Aligned model_utils.rs fallback to match llamacpp.rs
- Now tries dirs::cache_dir(), then $HOME/.cache, then /tmp
- Ensures model lookups use same location across components
RNG Quality Improvement:
- Replaced poor-quality LCG with RandomState hasher
- Uses hash of token position for better randomness
- Removed 'better RNG recommended' comment
- Improves token generation quality
Memory Optimization:
- Replaced unbounded accumulator with 20-char sliding window
- Reduces memory usage for long responses
- Still catches end markers split across tokens
- More efficient for max-length generation
Command Name Verification:
- Confirmed 'cx' is correct (not 'wezterm')
- Used consistently across ask_patterns, shortcuts, etc.
* fix: Add missing BuildHasher trait import
* style: Run cargo fmt
---------
Co-authored-by: ShreeJejurikar <shreemj8@gmail.com>
Co-authored-by: Suyash Dongre <109069262+Suyashd999@users.noreply.github.com>
Co-authored-by: Jingzhou Gary Xue <your.email@example.com>1 parent 31163fe commit 2dd58c0
12 files changed
Lines changed: 1619 additions & 66 deletions
File tree
- wezterm-gui
- src/ai
- wezterm
- src
- cli
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
130 | 134 | | |
131 | 135 | | |
132 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
| 51 | + | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| |||
84 | 88 | | |
85 | 89 | | |
86 | 90 | | |
87 | | - | |
88 | | - | |
89 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
92 | 104 | | |
93 | 105 | | |
94 | 106 | | |
95 | 107 | | |
96 | | - | |
97 | | - | |
98 | | - | |
| 108 | + | |
99 | 109 | | |
100 | | - | |
101 | 110 | | |
102 | | - | |
103 | 111 | | |
104 | | - | |
105 | | - | |
| 112 | + | |
| 113 | + | |
106 | 114 | | |
107 | 115 | | |
108 | 116 | | |
| |||
123 | 131 | | |
124 | 132 | | |
125 | 133 | | |
126 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
127 | 138 | | |
128 | 139 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 140 | + | |
133 | 141 | | |
134 | 142 | | |
135 | 143 | | |
136 | | - | |
| 144 | + | |
| 145 | + | |
137 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
138 | 151 | | |
139 | | - | |
140 | 152 | | |
141 | | - | |
142 | | - | |
| 153 | + | |
| 154 | + | |
143 | 155 | | |
144 | 156 | | |
145 | 157 | | |
| |||
151 | 163 | | |
152 | 164 | | |
153 | 165 | | |
| 166 | + | |
154 | 167 | | |
155 | 168 | | |
156 | 169 | | |
157 | 170 | | |
158 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
159 | 175 | | |
160 | 176 | | |
161 | 177 | | |
| |||
187 | 203 | | |
188 | 204 | | |
189 | 205 | | |
| 206 | + | |
190 | 207 | | |
191 | 208 | | |
| 209 | + | |
192 | 210 | | |
193 | 211 | | |
194 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
104 | 110 | | |
105 | 111 | | |
106 | 112 | | |
| |||
0 commit comments