shellmate-cli 3.0.0__tar.gz

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 (112) hide show
  1. shellmate_cli-3.0.0/LICENSE +21 -0
  2. shellmate_cli-3.0.0/MANIFEST.in +8 -0
  3. shellmate_cli-3.0.0/PKG-INFO +352 -0
  4. shellmate_cli-3.0.0/README.md +311 -0
  5. shellmate_cli-3.0.0/pyproject.toml +69 -0
  6. shellmate_cli-3.0.0/setup.cfg +4 -0
  7. shellmate_cli-3.0.0/shellmate/__init__.py +0 -0
  8. shellmate_cli-3.0.0/shellmate/adapters/__init__.py +67 -0
  9. shellmate_cli-3.0.0/shellmate/adapters/bash_adapter.sh +7 -0
  10. shellmate_cli-3.0.0/shellmate/adapters/ble_adapter.sh +350 -0
  11. shellmate_cli-3.0.0/shellmate/adapters/powershell_adapter.ps1 +417 -0
  12. shellmate_cli-3.0.0/shellmate/adapters/powershell_predictor.ps1 +97 -0
  13. shellmate_cli-3.0.0/shellmate/adapters/zsh_adapter.zsh +8 -0
  14. shellmate_cli-3.0.0/shellmate/agents/__init__.py +23 -0
  15. shellmate_cli-3.0.0/shellmate/agents/base.py +248 -0
  16. shellmate_cli-3.0.0/shellmate/agents/chain_patterns.yaml +98 -0
  17. shellmate_cli-3.0.0/shellmate/agents/command_chain.py +322 -0
  18. shellmate_cli-3.0.0/shellmate/agents/context_gatherer.py +175 -0
  19. shellmate_cli-3.0.0/shellmate/agents/environment.py +363 -0
  20. shellmate_cli-3.0.0/shellmate/agents/librarian.py +502 -0
  21. shellmate_cli-3.0.0/shellmate/agents/query.py +415 -0
  22. shellmate_cli-3.0.0/shellmate/agents/repomix_backend.py +171 -0
  23. shellmate_cli-3.0.0/shellmate/agents/watcher.py +266 -0
  24. shellmate_cli-3.0.0/shellmate/cache/__init__.py +0 -0
  25. shellmate_cli-3.0.0/shellmate/cache/semantic_cache.py +41 -0
  26. shellmate_cli-3.0.0/shellmate/cli/__init__.py +0 -0
  27. shellmate_cli-3.0.0/shellmate/cli/commands/__init__.py +27 -0
  28. shellmate_cli-3.0.0/shellmate/cli/commands/analyze.py +5 -0
  29. shellmate_cli-3.0.0/shellmate/cli/commands/config.py +319 -0
  30. shellmate_cli-3.0.0/shellmate/cli/commands/configure.py +118 -0
  31. shellmate_cli-3.0.0/shellmate/cli/commands/disable.py +11 -0
  32. shellmate_cli-3.0.0/shellmate/cli/commands/enable.py +49 -0
  33. shellmate_cli-3.0.0/shellmate/cli/commands/init.py +412 -0
  34. shellmate_cli-3.0.0/shellmate/cli/commands/install.py +242 -0
  35. shellmate_cli-3.0.0/shellmate/cli/commands/migrate.py +147 -0
  36. shellmate_cli-3.0.0/shellmate/cli/commands/status.py +31 -0
  37. shellmate_cli-3.0.0/shellmate/cli/commands/uninstall.py +78 -0
  38. shellmate_cli-3.0.0/shellmate/cli/main.py +114 -0
  39. shellmate_cli-3.0.0/shellmate/cli/parser.py +184 -0
  40. shellmate_cli-3.0.0/shellmate/cli/version.py +1 -0
  41. shellmate_cli-3.0.0/shellmate/completion/__init__.py +4 -0
  42. shellmate_cli-3.0.0/shellmate/completion/bash_adapter.py +145 -0
  43. shellmate_cli-3.0.0/shellmate/config/__init__.py +33 -0
  44. shellmate_cli-3.0.0/shellmate/config/credentials.py +120 -0
  45. shellmate_cli-3.0.0/shellmate/config/defaults.py +88 -0
  46. shellmate_cli-3.0.0/shellmate/config/manager.py +94 -0
  47. shellmate_cli-3.0.0/shellmate/config/paths.py +77 -0
  48. shellmate_cli-3.0.0/shellmate/config/secrets.py +66 -0
  49. shellmate_cli-3.0.0/shellmate/daemon/__init__.py +0 -0
  50. shellmate_cli-3.0.0/shellmate/daemon/lifecycle.py +308 -0
  51. shellmate_cli-3.0.0/shellmate/daemon/observability.py +82 -0
  52. shellmate_cli-3.0.0/shellmate/daemon/pipeline.py +119 -0
  53. shellmate_cli-3.0.0/shellmate/daemon/server.py +605 -0
  54. shellmate_cli-3.0.0/shellmate/daemon/session.py +170 -0
  55. shellmate_cli-3.0.0/shellmate/daemon/startup_ui.py +43 -0
  56. shellmate_cli-3.0.0/shellmate/environment/__init__.py +0 -0
  57. shellmate_cli-3.0.0/shellmate/environment/detector.py +130 -0
  58. shellmate_cli-3.0.0/shellmate/ipc/__init__.py +0 -0
  59. shellmate_cli-3.0.0/shellmate/ipc/client.py +210 -0
  60. shellmate_cli-3.0.0/shellmate/ipc/ps_client.py +190 -0
  61. shellmate_cli-3.0.0/shellmate/orchestration/__init__.py +3 -0
  62. shellmate_cli-3.0.0/shellmate/orchestration/analysis_graph.py +1274 -0
  63. shellmate_cli-3.0.0/shellmate/orchestration/state.py +35 -0
  64. shellmate_cli-3.0.0/shellmate/parser/__init__.py +0 -0
  65. shellmate_cli-3.0.0/shellmate/parser/command_parser.py +111 -0
  66. shellmate_cli-3.0.0/shellmate/plugins/__init__.py +0 -0
  67. shellmate_cli-3.0.0/shellmate/plugins/base.py +80 -0
  68. shellmate_cli-3.0.0/shellmate/plugins/loader.py +41 -0
  69. shellmate_cli-3.0.0/shellmate/providers/__init__.py +0 -0
  70. shellmate_cli-3.0.0/shellmate/providers/base.py +97 -0
  71. shellmate_cli-3.0.0/shellmate/providers/groq_command_guide.py +108 -0
  72. shellmate_cli-3.0.0/shellmate/providers/groq_provider.py +127 -0
  73. shellmate_cli-3.0.0/shellmate/providers/groq_supervisor.py +78 -0
  74. shellmate_cli-3.0.0/shellmate/providers/openrouter_provider.py +149 -0
  75. shellmate_cli-3.0.0/shellmate/providers/router.py +272 -0
  76. shellmate_cli-3.0.0/shellmate/providers/validate_keys.py +98 -0
  77. shellmate_cli-3.0.0/shellmate/providers/xai_provider.py +142 -0
  78. shellmate_cli-3.0.0/shellmate/rules/__init__.py +0 -0
  79. shellmate_cli-3.0.0/shellmate/rules/catastrophic.yaml +96 -0
  80. shellmate_cli-3.0.0/shellmate/rules/catastrophic_matcher.py +167 -0
  81. shellmate_cli-3.0.0/shellmate/rules/definitions/__init__.py +0 -0
  82. shellmate_cli-3.0.0/shellmate/rules/definitions/file_deletion.yaml +54 -0
  83. shellmate_cli-3.0.0/shellmate/rules/definitions/filesystem.yaml +43 -0
  84. shellmate_cli-3.0.0/shellmate/rules/definitions/network_execution.yaml +46 -0
  85. shellmate_cli-3.0.0/shellmate/rules/definitions/permissions.yaml +54 -0
  86. shellmate_cli-3.0.0/shellmate/rules/definitions/process_control.yaml +37 -0
  87. shellmate_cli-3.0.0/shellmate/rules/definitions/system_destruction.yaml +67 -0
  88. shellmate_cli-3.0.0/shellmate/rules/engine.py +200 -0
  89. shellmate_cli-3.0.0/shellmate/sanitizer/__init__.py +0 -0
  90. shellmate_cli-3.0.0/shellmate/sanitizer/typo_detector.py +114 -0
  91. shellmate_cli-3.0.0/shellmate/ui/__init__.py +10 -0
  92. shellmate_cli-3.0.0/shellmate/ui/analysis.py +164 -0
  93. shellmate_cli-3.0.0/shellmate/ui/annotations.py +232 -0
  94. shellmate_cli-3.0.0/shellmate/ui/banner.py +49 -0
  95. shellmate_cli-3.0.0/shellmate/ui/progress.py +126 -0
  96. shellmate_cli-3.0.0/shellmate/ui/runtime/__init__.py +15 -0
  97. shellmate_cli-3.0.0/shellmate/ui/runtime/console_factory.py +65 -0
  98. shellmate_cli-3.0.0/shellmate/ui/runtime/live_scene.py +116 -0
  99. shellmate_cli-3.0.0/shellmate/ui/runtime/motion_policy.py +69 -0
  100. shellmate_cli-3.0.0/shellmate/ui/runtime/tokens.py +47 -0
  101. shellmate_cli-3.0.0/shellmate/ui/scenes/__init__.py +24 -0
  102. shellmate_cli-3.0.0/shellmate/ui/scenes/enable.py +316 -0
  103. shellmate_cli-3.0.0/shellmate/ui/scenes/help.py +53 -0
  104. shellmate_cli-3.0.0/shellmate/ui/scenes/stages.py +128 -0
  105. shellmate_cli-3.0.0/shellmate/ui/scenes/status.py +181 -0
  106. shellmate_cli-3.0.0/shellmate/ui/status.py +3 -0
  107. shellmate_cli-3.0.0/shellmate_cli.egg-info/PKG-INFO +352 -0
  108. shellmate_cli-3.0.0/shellmate_cli.egg-info/SOURCES.txt +110 -0
  109. shellmate_cli-3.0.0/shellmate_cli.egg-info/dependency_links.txt +1 -0
  110. shellmate_cli-3.0.0/shellmate_cli.egg-info/entry_points.txt +3 -0
  111. shellmate_cli-3.0.0/shellmate_cli.egg-info/requires.txt +23 -0
  112. shellmate_cli-3.0.0/shellmate_cli.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ShellMate Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ include shellmate/adapters/*.sh
2
+ include shellmate/adapters/*.zsh
3
+ include shellmate/adapters/*.ps1
4
+ include shellmate/rules/*.yaml
5
+ include shellmate/rules/definitions/*.yaml
6
+ include shellmate/agents/*.yaml
7
+ include LICENSE
8
+ include README.md
@@ -0,0 +1,352 @@
1
+ Metadata-Version: 2.4
2
+ Name: shellmate-cli
3
+ Version: 3.0.0
4
+ Summary: Intelligent shell autocomplete with consequence preview
5
+ Author: ShellMate Contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/sayan-does/shellmate
8
+ Project-URL: Repository, https://github.com/sayan-does/shellmate
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Environment :: Console
17
+ Classifier: Topic :: Utilities
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: click>=8.0
22
+ Requires-Dist: pyyaml>=6.0
23
+ Requires-Dist: aiohttp>=3.9.0
24
+ Requires-Dist: groq>=0.4.0
25
+ Requires-Dist: openai>=1.0.0
26
+ Requires-Dist: numpy>=1.24.0
27
+ Requires-Dist: langgraph>=1.2.0
28
+ Requires-Dist: langchain-core>=1.4.0
29
+ Requires-Dist: rich>=13.0.0
30
+ Requires-Dist: psutil>=5.9.0
31
+ Requires-Dist: watchdog>=4.0.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: build; extra == "dev"
34
+ Requires-Dist: twine; extra == "dev"
35
+ Requires-Dist: pytest; extra == "dev"
36
+ Requires-Dist: pytest-asyncio; extra == "dev"
37
+ Provides-Extra: windows-test
38
+ Requires-Dist: pywinpty>=2.0.0; sys_platform == "win32" and extra == "windows-test"
39
+ Requires-Dist: pyte>=0.8.1; extra == "windows-test"
40
+ Dynamic: license-file
41
+
42
+ # ShellMate
43
+
44
+ Intelligent shell autocomplete with consequence preview.
45
+
46
+ **Version:** 3.0.0
47
+ **Package:** [`shellmate-cli`](https://pypi.org/project/shellmate-cli/)
48
+ **License:** MIT
49
+ **Python:** 3.10+
50
+
51
+ ShellMate watches what you type and shows **inline risk annotations** before you press Enter. A background daemon analyzes commands with deterministic rules, an exact-match cache, and a LangGraph pipeline that pulls project context plus Groq / OpenRouter / Grok (xAI) for AI risk and remediation.
52
+
53
+ ## How it works
54
+
55
+ ```
56
+ You type in the shell
57
+ → ble.sh (Linux/WSL) or PSReadLine (Windows) adapter
58
+ → IPC to daemon (TCP 127.0.0.1:9823)
59
+ → LangGraph analysis pipeline
60
+ → Inline annotation / confirmation gate
61
+ ```
62
+
63
+ 1. **Instant catastrophic check** — local YAML rules (`rules/catastrophic.yaml`), no API.
64
+ 2. **Debounced partial analysis** — after a short pause while typing.
65
+ 3. **Full analysis** — rules → cache → AI + context agents when risk is unclear.
66
+
67
+ ## Installation
68
+
69
+ ### From PyPI
70
+
71
+ ```bash
72
+ pip install shellmate-cli
73
+ ```
74
+
75
+ ### From source
76
+
77
+ ```bash
78
+ git clone https://github.com/sayan-does/shellmate.git
79
+ cd shellmate
80
+ pip install -e .
81
+ ```
82
+
83
+ ## Quick start
84
+
85
+ ### 1. Prerequisites
86
+
87
+ | Platform | Required |
88
+ |----------|----------|
89
+ | Linux / WSL | [ble.sh](https://github.com/akinomyoga/ble.sh) (e.g. under `~/.local/share/blesh/ble.sh`) |
90
+ | Windows | PowerShell with PSReadLine |
91
+ | All | At least one of `GROQ_API_KEY`, `OPENROUTER_API_KEY`, or `XAI_API_KEY` |
92
+
93
+ ### 2. Install hooks and configure keys
94
+
95
+ ```bash
96
+ sm install # copy adapter → ~/.shellmate/adapters/ and append RC/profile hook
97
+ sm config # select provider (Groq / OpenRouter / Grok xAI), paste API key
98
+ ```
99
+
100
+ Dry-run without changing files:
101
+
102
+ ```bash
103
+ sm install --dry-run
104
+ ```
105
+
106
+ ### 3. Start the daemon
107
+
108
+ ```bash
109
+ sm enable
110
+ ```
111
+
112
+ Starts the daemon for the current directory (Watcher, Librarian, and other agents). Check with `sm status`.
113
+
114
+ ### 4. Type normally
115
+
116
+ Inline annotations appear under the line as you type. Catastrophic commands require a second Enter to confirm.
117
+
118
+ ### 5. Stop / remove
119
+
120
+ ```bash
121
+ sm disable # stop daemon
122
+ sm uninstall # remove shell hooks (keeps config)
123
+ ```
124
+
125
+ ## Autocomplete features
126
+
127
+ ShellMate’s main UX is **in-shell autocomplete annotations** (not a separate `sm -a` command). Adapters hook ble.sh or PSReadLine and talk to the daemon over IPC.
128
+
129
+ ### Two-phase typing feedback
130
+
131
+ | Phase | Latency | What happens |
132
+ |-------|---------|--------------|
133
+ | **1 — Instant** | <10ms, no API | `/instant-check` against `rules/catastrophic.yaml`. Blocking commands get an immediate annotation. |
134
+ | **2 — Debounced** | ~300ms after you pause | `/analyze-partial` runs the analysis pipeline and **replaces** the annotation in place with risk + badges. |
135
+
136
+ ```bash
137
+ $ git push --force
138
+ [!] rewrites history [PROD] BH
139
+
140
+ $ rm -rf /
141
+ [!] BLOCKING - Type again to confirm
142
+ ```
143
+
144
+ ### Consequence preview (Tab × 2)
145
+
146
+ 1. **First Tab** — completion / ghost-text suggestion
147
+ 2. **Second Tab** — accept suggestion and show a **consequence preview** below the prompt:
148
+
149
+ ```text
150
+ → Force-pushes and rewrites remote history
151
+ → Reversible: No | remote: origin/main
152
+ → Safe alt: git push --force-with-lease
153
+ ```
154
+
155
+ On HIGH / CRITICAL / blocking severity, Enter is gated until you confirm again.
156
+
157
+ | Platform | Completion surface |
158
+ |----------|-------------------|
159
+ | Linux / WSL (ble.sh) | Tab bound to ShellMate complete widget |
160
+ | PowerShell 7.2+ | PSReadLine predictor (`powershell_predictor.ps1`) when available |
161
+ | PowerShell 5.1 | Tab handler ghost-text fallback |
162
+
163
+ ### Double-Enter confirmation
164
+
165
+ Dangerous commands do not run on the first Enter:
166
+
167
+ 1. First Enter → blocked; annotation asks you to confirm
168
+ 2. Second Enter (same command) → allowed
169
+
170
+ Applies to catastrophic instant matches and to HIGH/CRITICAL consequence previews.
171
+
172
+ ### Annotation badges
173
+
174
+ Short inline text under the command (ASCII-safe on all platforms):
175
+
176
+ | Kind | Examples |
177
+ |------|----------|
178
+ | Risk | `[OK]` `[i]` `[!]` `[!!]` `[X]` |
179
+ | Environment | `[PROD]` `[STAGE]` `[DEV]` `[CI]` |
180
+ | Time | `BH` (business hours) · `AH` (after hours) |
181
+ | Chain / consequence | `[BROKEN]` `[ESCALATION]` `[IRREVERSIBLE]` |
182
+
183
+ ### Bracket syntax
184
+
185
+ Typed as part of the command line; adapters/daemon strip and honor them:
186
+
187
+ | Syntax | Purpose | Example |
188
+ |--------|---------|---------|
189
+ | `[?…]` | Ask a question about the command | `docker rm $(docker ps -aq) [?why dangerous]` |
190
+ | `[!…]` | Directive to the analyzer | `rm -rf /tmp [!force]` |
191
+ | `[@key=value]` | Override context (e.g. environment) | `git reset --hard [@env=production]` |
192
+
193
+ ### Surfaces
194
+
195
+ | Adapter | Shell | Role |
196
+ |---------|-------|------|
197
+ | `ble_adapter.sh` | bash/zsh + ble.sh | Primary Linux/WSL autocomplete |
198
+ | `powershell_adapter.ps1` | PowerShell + PSReadLine | Primary Windows autocomplete |
199
+ | `powershell_predictor.ps1` | PowerShell 7.2+ | Optional ghost-text predictor |
200
+ | `bash_adapter.sh` / `zsh_adapter.zsh` | — | Deprecated stubs |
201
+
202
+ Requires at least one of `GROQ_API_KEY`, `OPENROUTER_API_KEY`, or `XAI_API_KEY` for AI annotations and consequence previews. Instant catastrophic checks still use local rules.
203
+
204
+ ## CLI
205
+
206
+ | Command | Description |
207
+ |---------|-------------|
208
+ | `sm install` | Install shell hooks (bash/zsh → ble adapter, PowerShell → PS adapter) |
209
+ | `sm uninstall` | Remove shell hooks |
210
+ | `sm config` | Configure API keys and settings |
211
+ | `sm enable` | Start daemon (autocomplete mode) |
212
+ | `sm disable` | Stop daemon and clean session |
213
+ | `sm status` | Daemon, agents, providers, credentials |
214
+ | `sm --help` | Help |
215
+ | `sm --version` | Version |
216
+ | `sm --no-color <cmd>` | Plain text output |
217
+
218
+ ### `sm config` usages
219
+
220
+ ```bash
221
+ sm config # validate existing keys; select provider → paste key
222
+ sm config --show # masked credentials
223
+ sm config provider risk_analysis xai grok-3-mini # set provider role
224
+ sm config cache.max_entries 200 # YAML override (dotted key)
225
+ ```
226
+
227
+ Interactive setup asks you to pick Groq, OpenRouter, or Grok (xAI), then paste the key. Existing keys are checked against the provider API.
228
+ ### Exit codes
229
+
230
+ | Code | Meaning |
231
+ |------|---------|
232
+ | 0 | Success |
233
+ | 2 | Usage error |
234
+ | 3 | Temporary error (e.g. interrupt) |
235
+ | 4 | Internal error |
236
+
237
+ ## Shell adapters
238
+
239
+ See [Autocomplete features](#autocomplete-features) for behavior. `sm install` copies the ble or PowerShell adapter into `~/.shellmate/adapters/` and appends a source line to your RC / profile.
240
+
241
+ ## Architecture
242
+
243
+ ### Analysis pipeline
244
+
245
+ Defined in `shellmate/orchestration/analysis_graph.py` (LangGraph `StateGraph`):
246
+
247
+ ```mermaid
248
+ flowchart TD
249
+ START([start]) --> sanitize --> parse --> command_chain --> rules --> cache
250
+ cache -->|early exit| format
251
+ cache -->|needs AI| supervisor
252
+ supervisor -->|gather context| context_worker
253
+ supervisor -->|env only| env_context
254
+ context_worker --> risk_analyzer
255
+ env_context --> risk_analyzer
256
+ risk_analyzer --> consequence_builder --> remediation --> command_guide --> format
257
+ format --> query
258
+ query --> END([end])
259
+ ```
260
+
261
+ | Node | Role |
262
+ |------|------|
263
+ | `sanitize` / `parse` | Typo / syntax checks; tokenize |
264
+ | `command_chain` | Multi-step / chain pattern detection |
265
+ | `rules` | YAML rules under `shellmate/rules/definitions/` |
266
+ | `cache` | Exact-match in-memory cache (no FAISS) |
267
+ | `supervisor` | Groq (or heuristic) decides context needs |
268
+ | `context_worker` / `env_context` | Parallel agent queries or env-only path |
269
+ | `risk_analyzer` | Groq risk assessment |
270
+ | `consequence_builder` | Structured consequence preview |
271
+ | `remediation` | OpenRouter safer alternatives |
272
+ | `command_guide` | Groq “what you meant” guide |
273
+ | `format` / `query` | Final payload; optional `[?…]` query handling |
274
+
275
+ **Early exits** (skip AI): sanitizer correction, high-confidence rule match, cache hit.
276
+
277
+ ### Agents (daemon)
278
+
279
+ Started with `sm enable`:
280
+
281
+ | Agent | Purpose |
282
+ |-------|---------|
283
+ | Watcher | OS, shell, git, tech-stack snapshot |
284
+ | Librarian | Project file index + search |
285
+ | Environment | Environment / staging signals |
286
+ | CommandChain | Chain-pattern analysis |
287
+ | Query | Answers `[?…]` queries |
288
+
289
+ Repomix-style pack search runs alongside Librarian in the context worker when needed.
290
+
291
+ ### Providers
292
+
293
+ | Stage | Default | Fallback |
294
+ |-------|---------|----------|
295
+ | Supervisor / risk / guide | Groq | Grok (xAI) / heuristic |
296
+ | Remediation | OpenRouter | Grok (xAI) / Groq guide / generic text |
297
+
298
+ Configure **at least one** of Groq, OpenRouter, or Grok (xAI). Groq covers risk analysis, supervisor routing, and command guide; OpenRouter covers remediation; xAI can cover both risk and remediation. Instant catastrophic gating still uses local rules either way.
299
+ ## Configuration
300
+
301
+ ### Directories
302
+
303
+ | Purpose | Linux / macOS | Windows |
304
+ |---------|---------------|---------|
305
+ | Config + `.env` | `~/.config/shellmate` | `%APPDATA%\ShellMate` |
306
+ | State / sessions / logs | `~/.local/state/shellmate` | `%LOCALAPPDATA%\ShellMate` |
307
+ | Cache dir | `~/.cache/shellmate` | `%LOCALAPPDATA%\ShellMate\cache` |
308
+ | Installed adapters | `~/.shellmate/adapters/` | `%USERPROFILE%\.shellmate\adapters\` |
309
+
310
+ Credentials file: `<config_dir>/.env` (permissions restricted on Unix).
311
+
312
+ ### Environment variables
313
+
314
+ | Variable | Required | Purpose |
315
+ |----------|----------|---------|
316
+ | `GROQ_API_KEY` | At least one of Groq / OpenRouter / xAI | Risk analysis, supervisor, command guide |
317
+ | `OPENROUTER_API_KEY` | At least one of Groq / OpenRouter / xAI | Remediation alternatives |
318
+ | `XAI_API_KEY` | At least one of Groq / OpenRouter / xAI | Risk analysis and remediation via Grok |
319
+ | `CONTEXT7_API_KEY` | No | Optional docs lookup |
320
+ | `GROQ_SUPERVISOR_MODEL` | No | Override supervisor model (default `qwen/qwen3.8-27b`) |
321
+ | `XAI_MODEL` | No | Override Grok model (default `grok-3-mini`) |
322
+
323
+ Optional YAML overrides live in `<config_dir>/config.yaml`.
324
+
325
+ ## Requirements
326
+
327
+ - Python 3.10+
328
+ - ble.sh (Linux/WSL) or PowerShell + PSReadLine (Windows)
329
+ - At least one of `GROQ_API_KEY`, `OPENROUTER_API_KEY`, or `XAI_API_KEY` (Groq + OpenRouter recommended for full risk + remediation)
330
+
331
+ ### Dependencies (authoritative: `pyproject.toml`)
332
+
333
+ - `click`, `rich`, `pyyaml` — CLI / UI
334
+ - `langgraph`, `langchain-core` — orchestration
335
+ - `groq`, `openai`, `aiohttp` — providers
336
+ - `psutil`, `watchdog` — runtime monitoring
337
+ - `numpy` — declared runtime dependency
338
+
339
+ ## Development
340
+
341
+ ```bash
342
+ git clone https://github.com/sayan-does/shellmate.git
343
+ cd shellmate
344
+ pip install -e ".[dev]"
345
+ python -m build
346
+ ```
347
+
348
+ CI builds and smoke-tests the wheel on Python 3.10–3.12. Publishing runs on `v*` tags via Trusted Publishing (`.github/workflows/publish.yml`).
349
+
350
+ ## License
351
+
352
+ MIT
@@ -0,0 +1,311 @@
1
+ # ShellMate
2
+
3
+ Intelligent shell autocomplete with consequence preview.
4
+
5
+ **Version:** 3.0.0
6
+ **Package:** [`shellmate-cli`](https://pypi.org/project/shellmate-cli/)
7
+ **License:** MIT
8
+ **Python:** 3.10+
9
+
10
+ ShellMate watches what you type and shows **inline risk annotations** before you press Enter. A background daemon analyzes commands with deterministic rules, an exact-match cache, and a LangGraph pipeline that pulls project context plus Groq / OpenRouter / Grok (xAI) for AI risk and remediation.
11
+
12
+ ## How it works
13
+
14
+ ```
15
+ You type in the shell
16
+ → ble.sh (Linux/WSL) or PSReadLine (Windows) adapter
17
+ → IPC to daemon (TCP 127.0.0.1:9823)
18
+ → LangGraph analysis pipeline
19
+ → Inline annotation / confirmation gate
20
+ ```
21
+
22
+ 1. **Instant catastrophic check** — local YAML rules (`rules/catastrophic.yaml`), no API.
23
+ 2. **Debounced partial analysis** — after a short pause while typing.
24
+ 3. **Full analysis** — rules → cache → AI + context agents when risk is unclear.
25
+
26
+ ## Installation
27
+
28
+ ### From PyPI
29
+
30
+ ```bash
31
+ pip install shellmate-cli
32
+ ```
33
+
34
+ ### From source
35
+
36
+ ```bash
37
+ git clone https://github.com/sayan-does/shellmate.git
38
+ cd shellmate
39
+ pip install -e .
40
+ ```
41
+
42
+ ## Quick start
43
+
44
+ ### 1. Prerequisites
45
+
46
+ | Platform | Required |
47
+ |----------|----------|
48
+ | Linux / WSL | [ble.sh](https://github.com/akinomyoga/ble.sh) (e.g. under `~/.local/share/blesh/ble.sh`) |
49
+ | Windows | PowerShell with PSReadLine |
50
+ | All | At least one of `GROQ_API_KEY`, `OPENROUTER_API_KEY`, or `XAI_API_KEY` |
51
+
52
+ ### 2. Install hooks and configure keys
53
+
54
+ ```bash
55
+ sm install # copy adapter → ~/.shellmate/adapters/ and append RC/profile hook
56
+ sm config # select provider (Groq / OpenRouter / Grok xAI), paste API key
57
+ ```
58
+
59
+ Dry-run without changing files:
60
+
61
+ ```bash
62
+ sm install --dry-run
63
+ ```
64
+
65
+ ### 3. Start the daemon
66
+
67
+ ```bash
68
+ sm enable
69
+ ```
70
+
71
+ Starts the daemon for the current directory (Watcher, Librarian, and other agents). Check with `sm status`.
72
+
73
+ ### 4. Type normally
74
+
75
+ Inline annotations appear under the line as you type. Catastrophic commands require a second Enter to confirm.
76
+
77
+ ### 5. Stop / remove
78
+
79
+ ```bash
80
+ sm disable # stop daemon
81
+ sm uninstall # remove shell hooks (keeps config)
82
+ ```
83
+
84
+ ## Autocomplete features
85
+
86
+ ShellMate’s main UX is **in-shell autocomplete annotations** (not a separate `sm -a` command). Adapters hook ble.sh or PSReadLine and talk to the daemon over IPC.
87
+
88
+ ### Two-phase typing feedback
89
+
90
+ | Phase | Latency | What happens |
91
+ |-------|---------|--------------|
92
+ | **1 — Instant** | &lt;10ms, no API | `/instant-check` against `rules/catastrophic.yaml`. Blocking commands get an immediate annotation. |
93
+ | **2 — Debounced** | ~300ms after you pause | `/analyze-partial` runs the analysis pipeline and **replaces** the annotation in place with risk + badges. |
94
+
95
+ ```bash
96
+ $ git push --force
97
+ [!] rewrites history [PROD] BH
98
+
99
+ $ rm -rf /
100
+ [!] BLOCKING - Type again to confirm
101
+ ```
102
+
103
+ ### Consequence preview (Tab × 2)
104
+
105
+ 1. **First Tab** — completion / ghost-text suggestion
106
+ 2. **Second Tab** — accept suggestion and show a **consequence preview** below the prompt:
107
+
108
+ ```text
109
+ → Force-pushes and rewrites remote history
110
+ → Reversible: No | remote: origin/main
111
+ → Safe alt: git push --force-with-lease
112
+ ```
113
+
114
+ On HIGH / CRITICAL / blocking severity, Enter is gated until you confirm again.
115
+
116
+ | Platform | Completion surface |
117
+ |----------|-------------------|
118
+ | Linux / WSL (ble.sh) | Tab bound to ShellMate complete widget |
119
+ | PowerShell 7.2+ | PSReadLine predictor (`powershell_predictor.ps1`) when available |
120
+ | PowerShell 5.1 | Tab handler ghost-text fallback |
121
+
122
+ ### Double-Enter confirmation
123
+
124
+ Dangerous commands do not run on the first Enter:
125
+
126
+ 1. First Enter → blocked; annotation asks you to confirm
127
+ 2. Second Enter (same command) → allowed
128
+
129
+ Applies to catastrophic instant matches and to HIGH/CRITICAL consequence previews.
130
+
131
+ ### Annotation badges
132
+
133
+ Short inline text under the command (ASCII-safe on all platforms):
134
+
135
+ | Kind | Examples |
136
+ |------|----------|
137
+ | Risk | `[OK]` `[i]` `[!]` `[!!]` `[X]` |
138
+ | Environment | `[PROD]` `[STAGE]` `[DEV]` `[CI]` |
139
+ | Time | `BH` (business hours) · `AH` (after hours) |
140
+ | Chain / consequence | `[BROKEN]` `[ESCALATION]` `[IRREVERSIBLE]` |
141
+
142
+ ### Bracket syntax
143
+
144
+ Typed as part of the command line; adapters/daemon strip and honor them:
145
+
146
+ | Syntax | Purpose | Example |
147
+ |--------|---------|---------|
148
+ | `[?…]` | Ask a question about the command | `docker rm $(docker ps -aq) [?why dangerous]` |
149
+ | `[!…]` | Directive to the analyzer | `rm -rf /tmp [!force]` |
150
+ | `[@key=value]` | Override context (e.g. environment) | `git reset --hard [@env=production]` |
151
+
152
+ ### Surfaces
153
+
154
+ | Adapter | Shell | Role |
155
+ |---------|-------|------|
156
+ | `ble_adapter.sh` | bash/zsh + ble.sh | Primary Linux/WSL autocomplete |
157
+ | `powershell_adapter.ps1` | PowerShell + PSReadLine | Primary Windows autocomplete |
158
+ | `powershell_predictor.ps1` | PowerShell 7.2+ | Optional ghost-text predictor |
159
+ | `bash_adapter.sh` / `zsh_adapter.zsh` | — | Deprecated stubs |
160
+
161
+ Requires at least one of `GROQ_API_KEY`, `OPENROUTER_API_KEY`, or `XAI_API_KEY` for AI annotations and consequence previews. Instant catastrophic checks still use local rules.
162
+
163
+ ## CLI
164
+
165
+ | Command | Description |
166
+ |---------|-------------|
167
+ | `sm install` | Install shell hooks (bash/zsh → ble adapter, PowerShell → PS adapter) |
168
+ | `sm uninstall` | Remove shell hooks |
169
+ | `sm config` | Configure API keys and settings |
170
+ | `sm enable` | Start daemon (autocomplete mode) |
171
+ | `sm disable` | Stop daemon and clean session |
172
+ | `sm status` | Daemon, agents, providers, credentials |
173
+ | `sm --help` | Help |
174
+ | `sm --version` | Version |
175
+ | `sm --no-color <cmd>` | Plain text output |
176
+
177
+ ### `sm config` usages
178
+
179
+ ```bash
180
+ sm config # validate existing keys; select provider → paste key
181
+ sm config --show # masked credentials
182
+ sm config provider risk_analysis xai grok-3-mini # set provider role
183
+ sm config cache.max_entries 200 # YAML override (dotted key)
184
+ ```
185
+
186
+ Interactive setup asks you to pick Groq, OpenRouter, or Grok (xAI), then paste the key. Existing keys are checked against the provider API.
187
+ ### Exit codes
188
+
189
+ | Code | Meaning |
190
+ |------|---------|
191
+ | 0 | Success |
192
+ | 2 | Usage error |
193
+ | 3 | Temporary error (e.g. interrupt) |
194
+ | 4 | Internal error |
195
+
196
+ ## Shell adapters
197
+
198
+ See [Autocomplete features](#autocomplete-features) for behavior. `sm install` copies the ble or PowerShell adapter into `~/.shellmate/adapters/` and appends a source line to your RC / profile.
199
+
200
+ ## Architecture
201
+
202
+ ### Analysis pipeline
203
+
204
+ Defined in `shellmate/orchestration/analysis_graph.py` (LangGraph `StateGraph`):
205
+
206
+ ```mermaid
207
+ flowchart TD
208
+ START([start]) --> sanitize --> parse --> command_chain --> rules --> cache
209
+ cache -->|early exit| format
210
+ cache -->|needs AI| supervisor
211
+ supervisor -->|gather context| context_worker
212
+ supervisor -->|env only| env_context
213
+ context_worker --> risk_analyzer
214
+ env_context --> risk_analyzer
215
+ risk_analyzer --> consequence_builder --> remediation --> command_guide --> format
216
+ format --> query
217
+ query --> END([end])
218
+ ```
219
+
220
+ | Node | Role |
221
+ |------|------|
222
+ | `sanitize` / `parse` | Typo / syntax checks; tokenize |
223
+ | `command_chain` | Multi-step / chain pattern detection |
224
+ | `rules` | YAML rules under `shellmate/rules/definitions/` |
225
+ | `cache` | Exact-match in-memory cache (no FAISS) |
226
+ | `supervisor` | Groq (or heuristic) decides context needs |
227
+ | `context_worker` / `env_context` | Parallel agent queries or env-only path |
228
+ | `risk_analyzer` | Groq risk assessment |
229
+ | `consequence_builder` | Structured consequence preview |
230
+ | `remediation` | OpenRouter safer alternatives |
231
+ | `command_guide` | Groq “what you meant” guide |
232
+ | `format` / `query` | Final payload; optional `[?…]` query handling |
233
+
234
+ **Early exits** (skip AI): sanitizer correction, high-confidence rule match, cache hit.
235
+
236
+ ### Agents (daemon)
237
+
238
+ Started with `sm enable`:
239
+
240
+ | Agent | Purpose |
241
+ |-------|---------|
242
+ | Watcher | OS, shell, git, tech-stack snapshot |
243
+ | Librarian | Project file index + search |
244
+ | Environment | Environment / staging signals |
245
+ | CommandChain | Chain-pattern analysis |
246
+ | Query | Answers `[?…]` queries |
247
+
248
+ Repomix-style pack search runs alongside Librarian in the context worker when needed.
249
+
250
+ ### Providers
251
+
252
+ | Stage | Default | Fallback |
253
+ |-------|---------|----------|
254
+ | Supervisor / risk / guide | Groq | Grok (xAI) / heuristic |
255
+ | Remediation | OpenRouter | Grok (xAI) / Groq guide / generic text |
256
+
257
+ Configure **at least one** of Groq, OpenRouter, or Grok (xAI). Groq covers risk analysis, supervisor routing, and command guide; OpenRouter covers remediation; xAI can cover both risk and remediation. Instant catastrophic gating still uses local rules either way.
258
+ ## Configuration
259
+
260
+ ### Directories
261
+
262
+ | Purpose | Linux / macOS | Windows |
263
+ |---------|---------------|---------|
264
+ | Config + `.env` | `~/.config/shellmate` | `%APPDATA%\ShellMate` |
265
+ | State / sessions / logs | `~/.local/state/shellmate` | `%LOCALAPPDATA%\ShellMate` |
266
+ | Cache dir | `~/.cache/shellmate` | `%LOCALAPPDATA%\ShellMate\cache` |
267
+ | Installed adapters | `~/.shellmate/adapters/` | `%USERPROFILE%\.shellmate\adapters\` |
268
+
269
+ Credentials file: `<config_dir>/.env` (permissions restricted on Unix).
270
+
271
+ ### Environment variables
272
+
273
+ | Variable | Required | Purpose |
274
+ |----------|----------|---------|
275
+ | `GROQ_API_KEY` | At least one of Groq / OpenRouter / xAI | Risk analysis, supervisor, command guide |
276
+ | `OPENROUTER_API_KEY` | At least one of Groq / OpenRouter / xAI | Remediation alternatives |
277
+ | `XAI_API_KEY` | At least one of Groq / OpenRouter / xAI | Risk analysis and remediation via Grok |
278
+ | `CONTEXT7_API_KEY` | No | Optional docs lookup |
279
+ | `GROQ_SUPERVISOR_MODEL` | No | Override supervisor model (default `qwen/qwen3.8-27b`) |
280
+ | `XAI_MODEL` | No | Override Grok model (default `grok-3-mini`) |
281
+
282
+ Optional YAML overrides live in `<config_dir>/config.yaml`.
283
+
284
+ ## Requirements
285
+
286
+ - Python 3.10+
287
+ - ble.sh (Linux/WSL) or PowerShell + PSReadLine (Windows)
288
+ - At least one of `GROQ_API_KEY`, `OPENROUTER_API_KEY`, or `XAI_API_KEY` (Groq + OpenRouter recommended for full risk + remediation)
289
+
290
+ ### Dependencies (authoritative: `pyproject.toml`)
291
+
292
+ - `click`, `rich`, `pyyaml` — CLI / UI
293
+ - `langgraph`, `langchain-core` — orchestration
294
+ - `groq`, `openai`, `aiohttp` — providers
295
+ - `psutil`, `watchdog` — runtime monitoring
296
+ - `numpy` — declared runtime dependency
297
+
298
+ ## Development
299
+
300
+ ```bash
301
+ git clone https://github.com/sayan-does/shellmate.git
302
+ cd shellmate
303
+ pip install -e ".[dev]"
304
+ python -m build
305
+ ```
306
+
307
+ CI builds and smoke-tests the wheel on Python 3.10–3.12. Publishing runs on `v*` tags via Trusted Publishing (`.github/workflows/publish.yml`).
308
+
309
+ ## License
310
+
311
+ MIT