promptune 0.1.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 (76) hide show
  1. promptune-0.1.0/LICENSE +21 -0
  2. promptune-0.1.0/PKG-INFO +651 -0
  3. promptune-0.1.0/README.md +602 -0
  4. promptune-0.1.0/promptune/__init__.py +3 -0
  5. promptune-0.1.0/promptune/__main__.py +5 -0
  6. promptune-0.1.0/promptune/cli.py +1082 -0
  7. promptune-0.1.0/promptune/config.py +284 -0
  8. promptune-0.1.0/promptune/context/__init__.py +107 -0
  9. promptune-0.1.0/promptune/context/collectors.py +358 -0
  10. promptune-0.1.0/promptune/context/ranker.py +86 -0
  11. promptune-0.1.0/promptune/context/sanitizer.py +88 -0
  12. promptune-0.1.0/promptune/daemon/__init__.py +4 -0
  13. promptune-0.1.0/promptune/daemon/clipboard.py +168 -0
  14. promptune-0.1.0/promptune/daemon/daemon.py +365 -0
  15. promptune-0.1.0/promptune/daemon/hotkey.py +243 -0
  16. promptune-0.1.0/promptune/daemon/ipc.py +157 -0
  17. promptune-0.1.0/promptune/daemon/launchagent.py +107 -0
  18. promptune-0.1.0/promptune/daemon/notify.py +56 -0
  19. promptune-0.1.0/promptune/daemon/platform/__init__.py +136 -0
  20. promptune-0.1.0/promptune/daemon/platform/base.py +120 -0
  21. promptune-0.1.0/promptune/daemon/platform/linux_service.py +192 -0
  22. promptune-0.1.0/promptune/daemon/platform/linux_wayland.py +320 -0
  23. promptune-0.1.0/promptune/daemon/platform/linux_x11.py +223 -0
  24. promptune-0.1.0/promptune/daemon/platform/macos.py +92 -0
  25. promptune-0.1.0/promptune/daemon/prewarm.py +143 -0
  26. promptune-0.1.0/promptune/dedup.py +103 -0
  27. promptune-0.1.0/promptune/engine.py +372 -0
  28. promptune-0.1.0/promptune/formatter.py +167 -0
  29. promptune-0.1.0/promptune/gate.py +71 -0
  30. promptune-0.1.0/promptune/history.py +305 -0
  31. promptune-0.1.0/promptune/hooks/__init__.py +41 -0
  32. promptune-0.1.0/promptune/hooks/claude_code.py +107 -0
  33. promptune-0.1.0/promptune/hooks/codex.py +91 -0
  34. promptune-0.1.0/promptune/mcp/__init__.py +1 -0
  35. promptune-0.1.0/promptune/mcp/server.py +112 -0
  36. promptune-0.1.0/promptune/meta_prompt.py +149 -0
  37. promptune-0.1.0/promptune/pqs.py +121 -0
  38. promptune-0.1.0/promptune/preferences.py +138 -0
  39. promptune-0.1.0/promptune/providers/__init__.py +57 -0
  40. promptune-0.1.0/promptune/providers/anthropic.py +52 -0
  41. promptune-0.1.0/promptune/providers/local.py +90 -0
  42. promptune-0.1.0/promptune/providers/openai.py +53 -0
  43. promptune-0.1.0/promptune/providers/openrouter.py +72 -0
  44. promptune-0.1.0/promptune/scorer.py +550 -0
  45. promptune-0.1.0/promptune/setup.py +359 -0
  46. promptune-0.1.0/promptune/shell.py +241 -0
  47. promptune-0.1.0/promptune/templates.py +135 -0
  48. promptune-0.1.0/promptune/tier0.py +440 -0
  49. promptune-0.1.0/promptune/tui.py +319 -0
  50. promptune-0.1.0/promptune.egg-info/PKG-INFO +651 -0
  51. promptune-0.1.0/promptune.egg-info/SOURCES.txt +74 -0
  52. promptune-0.1.0/promptune.egg-info/dependency_links.txt +1 -0
  53. promptune-0.1.0/promptune.egg-info/entry_points.txt +2 -0
  54. promptune-0.1.0/promptune.egg-info/requires.txt +30 -0
  55. promptune-0.1.0/promptune.egg-info/top_level.txt +1 -0
  56. promptune-0.1.0/pyproject.toml +127 -0
  57. promptune-0.1.0/setup.cfg +4 -0
  58. promptune-0.1.0/tests/test_cli.py +1861 -0
  59. promptune-0.1.0/tests/test_config.py +419 -0
  60. promptune-0.1.0/tests/test_dedup.py +205 -0
  61. promptune-0.1.0/tests/test_engine.py +591 -0
  62. promptune-0.1.0/tests/test_formatter.py +211 -0
  63. promptune-0.1.0/tests/test_gate.py +252 -0
  64. promptune-0.1.0/tests/test_history.py +231 -0
  65. promptune-0.1.0/tests/test_install.py +294 -0
  66. promptune-0.1.0/tests/test_main.py +27 -0
  67. promptune-0.1.0/tests/test_meta_prompt.py +97 -0
  68. promptune-0.1.0/tests/test_polish.py +180 -0
  69. promptune-0.1.0/tests/test_pqs.py +180 -0
  70. promptune-0.1.0/tests/test_preferences.py +150 -0
  71. promptune-0.1.0/tests/test_scorer.py +235 -0
  72. promptune-0.1.0/tests/test_setup.py +679 -0
  73. promptune-0.1.0/tests/test_shell.py +332 -0
  74. promptune-0.1.0/tests/test_templates.py +233 -0
  75. promptune-0.1.0/tests/test_tier0.py +270 -0
  76. promptune-0.1.0/tests/test_tui.py +900 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kayumuzzaman
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,651 @@
1
+ Metadata-Version: 2.4
2
+ Name: promptune
3
+ Version: 0.1.0
4
+ Summary: Terminal prompt enhancer for macOS and Linux
5
+ Author: kayumuzzaman
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/kayumuzzaman/promptune
8
+ Project-URL: Repository, https://github.com/kayumuzzaman/promptune
9
+ Keywords: prompt,cli,ai,terminal
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: MacOS
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: click>=8.0
26
+ Requires-Dist: rich>=13.0
27
+ Requires-Dist: prompt-toolkit>=3.0
28
+ Requires-Dist: anthropic>=0.40.0
29
+ Requires-Dist: openai>=1.0
30
+ Requires-Dist: httpx>=0.27.0
31
+ Requires-Dist: tomli>=2.0; python_version < "3.11"
32
+ Requires-Dist: readchar>=4.0
33
+ Requires-Dist: pyobjc-framework-Quartz>=10.0; sys_platform == "darwin"
34
+ Requires-Dist: pyobjc-framework-ApplicationServices>=10.0; sys_platform == "darwin"
35
+ Requires-Dist: pyobjc-framework-Cocoa>=10.0; sys_platform == "darwin"
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest>=8.0; extra == "dev"
38
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
39
+ Requires-Dist: pytest-mock>=3.14; extra == "dev"
40
+ Requires-Dist: ruff>=0.8.0; extra == "dev"
41
+ Requires-Dist: mypy>=1.13; extra == "dev"
42
+ Provides-Extra: linux-daemon
43
+ Requires-Dist: python-xlib>=0.33; extra == "linux-daemon"
44
+ Requires-Dist: dbus-next>=0.2.3; extra == "linux-daemon"
45
+ Requires-Dist: evdev>=1.7.0; extra == "linux-daemon"
46
+ Provides-Extra: mcp
47
+ Requires-Dist: mcp>=1.0; extra == "mcp"
48
+ Dynamic: license-file
49
+
50
+ # Promptune
51
+
52
+ An intelligent AI prompt enhancer. Write a rough prompt, let Promptune analyze and improve it using rule-based, local, or cloud AI — then review the result in a rich TUI before using it.
53
+
54
+ Promptune runs **locally**. Tier 0 (rule-based) needs no API key and no network. Local and cloud tiers are opt-in.
55
+
56
+ ## Contents
57
+
58
+ - [Features](#features)
59
+ - [How It Works](#how-it-works)
60
+ - [Ways to Use Promptune](#ways-to-use-promptune)
61
+ - [Compatibility](#compatibility)
62
+ - [Installation](#installation)
63
+ - [Quick Start](#quick-start)
64
+ - [CLI Commands](#cli-commands)
65
+ - [MCP Server Setup](#mcp-server-setup)
66
+ - [Auto-Enhance in AI Coding Tools](#auto-enhance-in-ai-coding-tools)
67
+ - [Shell Integration](#shell-integration)
68
+ - [System-Wide Daemon](#system-wide-daemon)
69
+ - [Configuration](#configuration)
70
+ - [Supported Providers](#supported-providers)
71
+ - [Development](#development)
72
+ - [Roadmap](#roadmap)
73
+
74
+ ## Features
75
+
76
+ - **Zero-config first run**: works instantly — no setup needed for Tier 0 rule-based enhancement
77
+ - **3-tier enhancement**: deterministic rules (free, instant) → local LLM → cloud API
78
+ - **Quality scoring (PQS)**: 7-dimension prompt analysis with before/after comparison
79
+ - **Context-aware**: auto-detects git branch, tech stack, shell history, and environment
80
+ - **Provider-flexible**: Claude, OpenAI, OpenRouter, or any OpenAI-compatible local LLM
81
+ - **Rich TUI**: side-by-side diff with Accept/Edit/Reject workflow
82
+ - **System-wide daemon**: background hotkey daemon (Ctrl+Shift+E) — enhances selected text in any macOS or Linux app
83
+ - **Shell integration**: Ctrl+E widget for Zsh, Bash, and Fish — enhances prompts inline
84
+ - **MCP server**: exposes `enhance` and `score` tools to any MCP client (Claude Code, Cursor, Codex)
85
+ - **Auto-enhance hook**: intercepts low-quality prompts in AI coding tools, enhances them, and silently injects the enhanced prompt as context
86
+ - **Provider-specific formatting**: auto-selects XML, Markdown, or Plain based on target model
87
+ - **Interactive setup wizard**: guided config init with provider selection and masked API key input
88
+ - **Semantic deduplication**: detects near-duplicate prompts and returns cached results instantly
89
+ - **Preference learning**: learns from accept/reject/edit decisions to skip disliked rules automatically
90
+ - **Team templates**: `.prompts/` directory with intent/domain matching and variable injection
91
+ - **Enhancement history**: SQLite-backed history with statistics and acceptance tracking
92
+ - **System health check**: `promptune doctor` verifies config, tiers, shell, and hook status
93
+ - Configurable enhancement styles: minimal, balanced, detailed
94
+ - TOML-based configuration
95
+
96
+ ## How It Works
97
+
98
+ Every entry point funnels a raw prompt through the same routing engine and returns an enhanced prompt plus a quality score.
99
+
100
+ ```
101
+ raw prompt
102
+
103
+
104
+ ┌─────────────────┐ cache hit
105
+ │ 1. Dedup check │ ──────────────► return cached enhancement (instant)
106
+ └─────────────────┘
107
+ │ miss
108
+
109
+ ┌─────────────────┐
110
+ │ 2. Tier 0 rules │ 9 deterministic rewrite rules (free, offline, ~0 ms)
111
+ └─────────────────┘
112
+
113
+
114
+ ┌─────────────────┐ score ≥ 70
115
+ │ 3. Re-score PQS │ ──────────────► done — return Tier 0 result
116
+ └─────────────────┘
117
+ │ score < 70 (and max_tier allows)
118
+
119
+ ┌─────────────────┐ fails / unavailable
120
+ │ 4. Tier 1 local │ ──────────────┐
121
+ └─────────────────┘ │ graceful fallback
122
+ │ still weak ▼
123
+ ▼ (drop to tier below)
124
+ ┌─────────────────┐
125
+ │ 5. Tier 2 cloud │ Claude / OpenAI / OpenRouter
126
+ └─────────────────┘
127
+
128
+
129
+ context injection · preference filtering · template match · provider formatting
130
+
131
+
132
+ enhanced prompt + before/after PQS
133
+ ```
134
+
135
+ **Tiers**
136
+
137
+ | Tier | Engine | Cost | Needs |
138
+ |------|--------|------|-------|
139
+ | 0 | 9-rule deterministic rewrite engine | Free, instant, offline | Nothing |
140
+ | 1 | Local LLM (Ollama / any OpenAI-compatible) | Free, local | `[local_llm] enabled = true` |
141
+ | 2 | Cloud API | Paid | Provider API key |
142
+
143
+ The router always tries the cheapest tier first and **degrades gracefully** — if a tier fails or is unavailable, it falls back to the tier below. `max_tier` (config) caps how far it climbs; `--tier N` forces one tier.
144
+
145
+ **Quality Score (PQS)** rates a prompt 0–100 across 7 dimensions (specificity, clarity, structure, actionability, context, completeness, conciseness) and drives both the routing decision and the auto-enhance gate.
146
+
147
+ ## Ways to Use Promptune
148
+
149
+ Five surfaces, one engine. Pick whichever fits your workflow:
150
+
151
+ | Way | Trigger | Best for |
152
+ |-----|---------|----------|
153
+ | **CLI** | `promptune enhance "..."` | Scripting, one-offs, piping |
154
+ | **Shell widget** | **Ctrl+E** in your terminal | Enhancing the command line you're typing |
155
+ | **System daemon** | **Ctrl+Shift+E** anywhere | Enhancing selected text in any app (browser, editor, chat) |
156
+ | **MCP server** | Ask your AI tool to enhance/score | Inside Claude Code, Cursor, Codex, or any MCP client |
157
+ | **Auto-enhance hook** | Automatic on prompt submit | Upgrading weak prompts in tools that expose a hook (Claude Code, Codex) |
158
+
159
+ Not every AI tool can auto-trigger Promptune. See [Auto-Enhance in AI Coding Tools](#auto-enhance-in-ai-coding-tools) for the per-tool support matrix.
160
+
161
+ ## Compatibility
162
+
163
+ The **CLI runs in every terminal and OS** — it's a plain Python program. The convenience integrations are constrained not by your terminal emulator but by your **shell** (the inline widget) and your **OS** (the system daemon).
164
+
165
+ | Surface | macOS | Linux | Windows | Requirements |
166
+ |---------|:-----:|:-----:|:-------:|--------------|
167
+ | **CLI** (`enhance` / `score` / `doctor` …) | ✅ | ✅ | ✅ | Python 3.9+; any terminal emulator |
168
+ | **Interactive TUI** (Accept/Edit/Reject) | ✅ | ✅ | ✅ | a real TTY (ANSI) — degrades in pipes |
169
+ | **Shell widget** (Ctrl+E inline) | ✅ | ✅ | ⚠️ via WSL / Git Bash | **zsh / bash / fish** only — ❌ Warp, PowerShell, nushell, cmd |
170
+ | **System daemon** (Ctrl+Shift+E global) | ✅ | ✅ X11 / Wayland | ❌ | macOS: Accessibility grant · Linux X11: `xclip` + `xdotool` · Wayland: `wl-clipboard` + `ydotool` + `input` group |
171
+ | **Auto-enhance hook** (silent gate) | ✅ | ✅ | ✅ | tool exposing a `UserPromptSubmit` hook → **Claude Code, Codex** |
172
+ | **MCP server** | ✅ | ✅ | ✅ | any MCP client (Claude Code, Cursor, Codex …) |
173
+
174
+ **Terminal emulators:** the CLI, TUI, and widget work in iTerm2, kitty, Alacritty, GNOME Terminal, Windows Terminal, tmux, and over SSH. The one explicit exception is the **Ctrl+E widget in Warp**, which Warp's input model doesn't support (`promptune doctor` flags it and points you to `promptune enhance`).
175
+
176
+ > `promptune doctor` reports exactly what's available on your machine — tiers, shell-widget compatibility, daemon permissions, and the auto-enhance hook per detected tool.
177
+
178
+ ## Installation
179
+
180
+ ### Recommended — pipx (macOS + Linux)
181
+
182
+ ```bash
183
+ pipx install promptune # or: python3 -m pip install --user promptune
184
+ promptune config init
185
+ ```
186
+
187
+ Verify with `promptune --version`, then `promptune doctor`.
188
+
189
+ ### Optional extras
190
+
191
+ Install **with** the extras you want — use one of these *instead of* the base command above:
192
+
193
+ ```bash
194
+ pipx install "promptune[mcp]" # + MCP server (enables `promptune mcp`)
195
+ pipx install "promptune[mcp,linux-daemon]" # + MCP and Linux system-daemon support
196
+ ```
197
+
198
+ Already installed plain `promptune`? Add the deps to the existing pipx venv instead (a second `pipx install` is a no-op):
199
+
200
+ ```bash
201
+ pipx inject promptune "mcp>=1.0" # MCP server
202
+ pipx inject promptune python-xlib dbus-next evdev # Linux daemon
203
+ ```
204
+
205
+ The Linux system-wide hotkey daemon also needs OS tools:
206
+
207
+ ```bash
208
+ sudo apt install xclip xdotool # X11
209
+ sudo apt install wl-clipboard ydotool # Wayland (+ add yourself to the 'input' group)
210
+ ```
211
+
212
+ ### One-line installer (macOS + Linux)
213
+
214
+ ```bash
215
+ curl -fsSL https://raw.githubusercontent.com/kayumuzzaman/promptune/main/install.sh | bash
216
+ ```
217
+
218
+ Or inspect before running:
219
+
220
+ ```bash
221
+ curl -fsSL https://raw.githubusercontent.com/kayumuzzaman/promptune/main/install.sh -o install.sh
222
+ bash install.sh
223
+ ```
224
+
225
+ ### For development
226
+
227
+ ```bash
228
+ git clone https://github.com/kayumuzzaman/promptune.git
229
+ cd promptune
230
+ pip install -e ".[dev]"
231
+ ```
232
+
233
+ ## Quick Start
234
+
235
+ ```bash
236
+ # 1. Interactive setup wizard — provider, API key, shell widget, AI-tool hooks + MCP
237
+ promptune config init
238
+
239
+ # 2. Enhance a prompt
240
+ promptune enhance "make a todo app"
241
+
242
+ # 3. Set up the shell widget (Zsh/Bash/Fish)
243
+ echo 'eval "$(promptune shell-init)"' >> ~/.zshrc
244
+ source ~/.zshrc
245
+
246
+ # 4. Verify everything
247
+ promptune doctor
248
+ ```
249
+
250
+ Now press **Ctrl+E** in your terminal to enhance the current line.
251
+
252
+ > `promptune config init` also detects installed AI coding tools (Claude Code, Codex CLI, …) and offers to install the [auto-enhance hook](#auto-enhance-in-ai-coding-tools) and register the [MCP server](#mcp-server-setup) for you. Both are optional.
253
+
254
+ _The setup wizard:_
255
+
256
+ ![promptune config init walkthrough](docs/assets/option-settings.gif)
257
+
258
+ ## CLI Commands
259
+
260
+ Run `promptune --help` for the full list, or `promptune <command> --help` for any command.
261
+
262
+ ### `promptune enhance`
263
+
264
+ Enhance a prompt using AI. Opens a TUI with Accept/Edit/Reject workflow by default.
265
+
266
+ _With `--no-tui`, the enhanced prompt prints straight to stdout — pipe it anywhere:_
267
+
268
+ ![promptune enhance --no-tui in a shell](docs/assets/option-a.gif)
269
+
270
+ ```bash
271
+ # Basic — opens TUI with before/after comparison
272
+ promptune enhance "make a todo app"
273
+
274
+ # Override provider for this command
275
+ promptune enhance -p openai "optimize this SQL query"
276
+
277
+ # Override enhancement style
278
+ promptune enhance -s detailed "build a payment system"
279
+
280
+ # Force a specific tier (0=rules only, 1=local LLM, 2=cloud API)
281
+ promptune enhance --tier 0 "fix the login bug"
282
+
283
+ # Force output format
284
+ promptune enhance --format markdown "explain kubernetes networking"
285
+
286
+ # Skip TUI, print enhanced prompt directly to stdout
287
+ promptune enhance --no-tui "add dark mode to my react app"
288
+
289
+ # Get structured JSON output
290
+ promptune enhance --json "write unit tests for the auth module"
291
+
292
+ # Pipe input
293
+ echo "build a REST API" | promptune enhance --no-tui
294
+
295
+ # Enhance and copy to clipboard (macOS)
296
+ promptune enhance --no-tui "refactor the user service" | pbcopy
297
+
298
+ # Combine flags
299
+ promptune enhance -p openrouter -s detailed --format xml --no-tui "design a caching layer"
300
+ ```
301
+
302
+ **All flags:**
303
+
304
+ | Flag | Short | Description |
305
+ |------|-------|-------------|
306
+ | `--provider` | `-p` | Override default provider (claude, openai, openrouter) |
307
+ | `--style` | `-s` | Override enhancement style (minimal, balanced, detailed) |
308
+ | `--tier` | | Force specific tier: 0 (rules only), 1 (local LLM), 2 (cloud API) |
309
+ | `--format` | | Force output format: xml, markdown, plain |
310
+ | `--no-tui` | | Print result directly to stdout, skip interactive TUI |
311
+ | `--json` | | Output structured JSON with scores, tier, latency |
312
+
313
+ ### `promptune score`
314
+
315
+ Score a prompt across 7 quality dimensions (0–100 PQS) without enhancing it — shows a per-dimension breakdown and actionable suggestions.
316
+
317
+ ```bash
318
+ promptune score "make a todo app"
319
+ promptune score --json "build a REST API with JWT auth"
320
+ echo "add dark mode" | promptune score
321
+ ```
322
+
323
+ ### `promptune config`
324
+
325
+ Manage configuration.
326
+
327
+ ```bash
328
+ promptune config init # interactive setup wizard
329
+ promptune config --set-key claude sk-ant-your-key-here # set a provider API key
330
+ promptune config --set-tier 2 # set max enhancement tier
331
+ promptune config --reset # reset config to defaults
332
+ promptune config show # show current configuration
333
+ promptune config path # print config file path
334
+ ```
335
+
336
+ ### `promptune shell-init`
337
+
338
+ Output the shell widget script. Auto-detects shell, or specify one. See [Shell Integration](#shell-integration).
339
+
340
+ ```bash
341
+ eval "$(promptune shell-init)" # auto-detect shell
342
+ eval "$(promptune shell-init --shell bash)" # force a shell
343
+ eval "$(promptune shell-init --key 'alt+e')" # custom keybinding
344
+ eval "$(promptune shell-init --key 'ctrl+x ctrl+e')"
345
+ ```
346
+
347
+ ### `promptune doctor`
348
+
349
+ Run a system health check — verifies Python version, config, tier availability, shell widget compatibility, and the auto-enhance hook / MCP status for each detected AI tool.
350
+
351
+ ```bash
352
+ promptune doctor
353
+ ```
354
+
355
+ ### `promptune history`
356
+
357
+ View enhancement history stored in SQLite.
358
+
359
+ ```bash
360
+ promptune history # recent entries
361
+ promptune history --n 50 # last 50 entries
362
+ promptune history --stats # acceptance rate, score improvements
363
+ promptune history --clear # clear all history
364
+ promptune history --preferences # show learned preferences
365
+ ```
366
+
367
+ ### `promptune daemon`
368
+
369
+ Background daemon for system-wide prompt enhancement. See [System-Wide Daemon](#system-wide-daemon).
370
+
371
+ ```bash
372
+ promptune daemon start --foreground # run in foreground (debugging)
373
+ promptune daemon start # run as background process
374
+ promptune daemon status # check status
375
+ promptune daemon stop # stop
376
+ promptune daemon setup # grant permissions / install deps
377
+ promptune daemon diagnose # run diagnostics
378
+ promptune daemon install # install system service (systemd / LaunchAgent)
379
+ promptune daemon uninstall # remove system service
380
+ promptune daemon purge # remove all daemon files
381
+ promptune daemon install-login-item # legacy macOS-only
382
+ promptune daemon uninstall-login-item # legacy macOS-only
383
+ ```
384
+
385
+ ### `promptune mcp`
386
+
387
+ Start the MCP server (stdio transport). See [MCP Server Setup](#mcp-server-setup).
388
+
389
+ ```bash
390
+ promptune mcp
391
+ ```
392
+
393
+ ### `promptune local-llm-status`
394
+
395
+ Check local LLM (Ollama) connectivity.
396
+
397
+ ```bash
398
+ promptune local-llm-status
399
+ ```
400
+
401
+ ### `promptune version`
402
+
403
+ ```bash
404
+ promptune version
405
+ ```
406
+
407
+ ## MCP Server Setup
408
+
409
+ Promptune ships an [MCP](https://modelcontextprotocol.io) server (`promptune mcp`, stdio transport) that exposes two tools to any MCP-compatible AI tool:
410
+
411
+ _Claude Code calling the `enhance` tool, then acting on the refined prompt:_
412
+
413
+ ![promptune MCP tool inside Claude Code](docs/assets/option-b.gif)
414
+
415
+ | Tool | Arguments | Returns |
416
+ |------|-----------|---------|
417
+ | `enhance_prompt` | `prompt` (str), `style` = `balanced`, `tier` = `-1` (auto), `output_format` = `auto` | Enhanced prompt, tier used, before/after scores |
418
+ | `score_prompt_quality` | `prompt` (str) | Total PQS, detected intent, per-dimension breakdown + suggestions |
419
+
420
+ Requires the MCP extra:
421
+
422
+ ```bash
423
+ pip install "promptune[mcp]"
424
+ ```
425
+
426
+ ### Option A — automatic (recommended)
427
+
428
+ `promptune config init` detects installed AI tools and offers to register the MCP server for you (written to `~/.claude/settings.json`). Verify with `promptune doctor`.
429
+
430
+ ### Option B — Claude Code (manual)
431
+
432
+ ```bash
433
+ claude mcp add promptune -- promptune mcp
434
+ ```
435
+
436
+ Or add it directly to `~/.claude/settings.json` (or a project `.mcp.json`):
437
+
438
+ ```json
439
+ {
440
+ "mcpServers": {
441
+ "promptune": {
442
+ "command": "promptune",
443
+ "args": ["mcp"]
444
+ }
445
+ }
446
+ }
447
+ ```
448
+
449
+ ### Option C — Cursor / Codex / other MCP clients
450
+
451
+ Point your client's MCP config at the same command. Generic shape:
452
+
453
+ ```json
454
+ {
455
+ "mcpServers": {
456
+ "promptune": {
457
+ "command": "promptune",
458
+ "args": ["mcp"]
459
+ }
460
+ }
461
+ }
462
+ ```
463
+
464
+ If `promptune` is not on the tool's `PATH`, use the absolute path (find it with `which promptune`).
465
+
466
+ ### Using it
467
+
468
+ Once registered, ask your AI assistant naturally — e.g. *"score this prompt"* or *"enhance this prompt before we start"* — and it will call the `score_prompt_quality` / `enhance_prompt` tools.
469
+
470
+ ## Auto-Enhance in AI Coding Tools
471
+
472
+ The auto-enhance hook intercepts prompts you submit in an AI coding tool, and when a prompt looks weak it enhances it and silently injects the improved version into the conversation as context — no clipboard, no manual paste.
473
+
474
+ _A weak prompt silently enhanced and injected inside Codex (`!` bypasses):_
475
+
476
+ ![promptune auto-enhance gate inside Codex](docs/assets/option-c.gif)
477
+
478
+ ### Which tools auto-trigger?
479
+
480
+ Promptune integrates with AI coding tools two ways: an **auto-enhance hook** (fires automatically on every prompt you submit inside the tool's interactive session) and the **MCP server** (the model calls Promptune on request — never automatic). A tool can only auto-trigger if it exposes a `UserPromptSubmit` hook *and* Promptune ships an installer for it.
481
+
482
+ | Tool | Auto-trigger on prompt submit? | How |
483
+ |------|-------------------------------|-----|
484
+ | **Claude Code** | ✅ Yes | `UserPromptSubmit` hook in `~/.claude/settings.json` |
485
+ | **Codex CLI** | ✅ Yes | `UserPromptSubmit` hook in `~/.codex/hooks.json` |
486
+ | **Cursor / other MCP clients** | ❌ No | Use the [MCP server](#mcp-server-setup) (ask the tool to enhance) or run `promptune enhance` manually and paste/pipe the result |
487
+
488
+ > **Note on injection vs. replacement:** the gate does **not** literally replace or overwrite the prompt text you typed — neither Claude Code nor Codex allows a hook to do that. Instead it **injects the enhanced prompt as additional context alongside your original**, so the model receives both and acts on the enhanced version automatically. The `!` bypass prefix still sends your prompt through raw, with no enhancement and no injection.
489
+
490
+ **How it works** — the installer adds a `UserPromptSubmit` hook (to `~/.claude/settings.json` for Claude Code, or `~/.codex/hooks.json` for Codex CLI) that pipes each submitted prompt into `promptune gate`. Both tools use the same hook shape and pass the prompt in the same `prompt` field, so the one gate works for both. The gate:
491
+
492
+ 1. Skips if auto-enhance is disabled.
493
+ 2. Skips if the prompt starts with the **bypass prefix** (`!` by default).
494
+ 3. Skips prompts shorter than `min_words`.
495
+ 4. Scores the prompt; if PQS ≥ `threshold`, lets it through unchanged.
496
+ 5. Otherwise enhances it and injects the enhanced prompt into the model's context via the hook's `additionalContext` output (exit 0, the prompt proceeds), so the model acts on the enhanced version automatically — no clipboard, no paste.
497
+
498
+ ### Install
499
+
500
+ Run the wizard and accept the auto-enhance prompt when it detects your tool (Claude Code, Codex CLI, …):
501
+
502
+ ```bash
503
+ promptune config init
504
+ ```
505
+
506
+ Verify — `doctor` prints an Auto-enhance status line per detected tool (Claude Code when `~/.claude/` exists, Codex when `~/.codex/` exists):
507
+
508
+ ```bash
509
+ promptune doctor # shows: Auto-enhance ✓ <tool> (threshold: NN)
510
+ ```
511
+
512
+ ### Manual (Claude Code)
513
+
514
+ Add to `~/.claude/settings.json`:
515
+
516
+ ```json
517
+ {
518
+ "hooks": {
519
+ "UserPromptSubmit": [
520
+ {
521
+ "matcher": "",
522
+ "hooks": [
523
+ { "type": "command", "command": "promptune gate" }
524
+ ]
525
+ }
526
+ ]
527
+ }
528
+ }
529
+ ```
530
+
531
+ ### Manual (Codex CLI)
532
+
533
+ Add to `~/.codex/hooks.json` (same shape — Codex's `UserPromptSubmit` payload uses the same `prompt` field):
534
+
535
+ ```json
536
+ {
537
+ "hooks": {
538
+ "UserPromptSubmit": [
539
+ {
540
+ "matcher": "",
541
+ "hooks": [
542
+ { "type": "command", "command": "promptune gate" }
543
+ ]
544
+ }
545
+ ]
546
+ }
547
+ }
548
+ ```
549
+
550
+ ### Tune it
551
+
552
+ ```toml
553
+ [auto_enhance]
554
+ enabled = true # master switch
555
+ threshold = 40 # enhance prompts scoring below this PQS
556
+ min_words = 5 # ignore very short prompts
557
+ bypass_prefix = "!" # prefix a prompt with this to skip enhancement
558
+ ```
559
+
560
+ Type `!just do exactly this` to bypass on a per-prompt basis.
561
+
562
+ ## Shell Integration
563
+
564
+ Add the widget to your shell rc file, then press **Ctrl+E** to enhance the line you're typing in place. Works in Zsh, Bash, and Fish.
565
+
566
+ ```bash
567
+ # Zsh — ~/.zshrc
568
+ eval "$(promptune shell-init)"
569
+
570
+ # Bash — ~/.bashrc
571
+ eval "$(promptune shell-init --shell bash)"
572
+
573
+ # Fish — ~/.config/fish/config.fish
574
+ promptune shell-init --shell fish | source
575
+ ```
576
+
577
+ Rebind the key with `--key` (e.g. `--key 'alt+e'`). The widget talks to the running daemon over a Unix socket when available, so enhancements stay fast.
578
+
579
+ ## System-Wide Daemon
580
+
581
+ The daemon registers a global hotkey (**Ctrl+Shift+E** by default) that enhances **selected text in any application** — copy is simulated, the selection is enhanced, and the result is pasted back. Supported on macOS (CGEventTap) and Linux (X11 and Wayland).
582
+
583
+ ```bash
584
+ promptune daemon setup # grant Accessibility (macOS) / install deps (Linux)
585
+ promptune daemon start # start in the background
586
+ promptune daemon install # auto-start at login (LaunchAgent / systemd)
587
+ promptune daemon status # confirm it's running
588
+ ```
589
+
590
+ On Linux, install the platform tools the daemon shells out to (`xclip`/`xdotool` for X11, `wl-clipboard`/`ydotool` for Wayland); `promptune daemon diagnose` reports what's missing.
591
+
592
+ Daemon behavior (hotkey, clipboard settle time, notifications, Ollama pre-warm) is configured under `[daemon]` in the config file.
593
+
594
+ ## Configuration
595
+
596
+ Config lives at `~/.config/promptune/config.toml`. Create and edit it interactively with `promptune config init`, or see `config.example.toml` for every option with defaults.
597
+
598
+ **Resolution order:** CLI flags > environment variables > config file > defaults
599
+
600
+ Environment variables: `PROMPTUNE_PROVIDER`, `PROMPTUNE_STYLE`
601
+
602
+ Key sections:
603
+
604
+ | Section | Controls |
605
+ |---------|----------|
606
+ | `[provider]` | Default provider, per-provider model, format style |
607
+ | `[api_keys]` | Claude / OpenAI / OpenRouter keys |
608
+ | `[enhancement]` | `max_tier`, default style, dedup, preference learning |
609
+ | `[local_llm]` | Ollama / OpenAI-compatible host + model (Tier 1) |
610
+ | `[context]` | Git / shell-history / stack-detection toggles |
611
+ | `[history]` | SQLite history location + size |
612
+ | `[tui]` | TUI display options |
613
+ | `[daemon]` | Global hotkey + daemon behavior |
614
+ | `[auto_enhance]` | Hook threshold, min words, bypass prefix |
615
+
616
+ ## Supported Providers
617
+
618
+ | Provider | SDK | Config Key |
619
+ |----------|-----|-----------|
620
+ | Claude | `anthropic` | `[api_keys] claude = "sk-ant-..."` |
621
+ | OpenAI | `openai` | `[api_keys] openai = "sk-..."` |
622
+ | OpenRouter | `httpx` | `[api_keys] openrouter = "sk-or-..."` |
623
+ | Local LLM | OpenAI-compatible | `[local_llm] host = "http://localhost:11434"` |
624
+
625
+ ## Development
626
+
627
+ ```bash
628
+ pip install -e ".[dev]"
629
+
630
+ # Full check (lint + types + tests), as CI runs it
631
+ ruff check . && mypy promptune/ && pytest -m "not linux" --cov=promptune --cov-report=term-missing
632
+
633
+ # Tests only
634
+ pytest -m "not linux" -v
635
+ ```
636
+
637
+ CI runs on Linux (Python 3.12 and 3.13). macOS-only daemon tests self-skip there, and `-m "not linux"` excludes the real-hardware X11/Wayland integration tests. Coverage gate: ≥ 89%.
638
+
639
+ ## Roadmap
640
+
641
+ - [x] Phase 1: Core CLI, providers, TUI, shell integration (Zsh/Bash/Fish)
642
+ - [x] Phase 1.1: 3-tier enhancement, quality scoring, context fingerprinting, SQLite history
643
+ - [x] Phase 1.2: Interactive config setup wizard
644
+ - [x] Enhancement Phase: Preference learning, semantic deduplication, team templates, Ollama auto-check
645
+ - [x] Phase 2: OS-level hotkey daemon (macOS) — system-wide Ctrl+Shift+E
646
+ - [x] Phase 3: Linux hotkey daemon — X11 and Wayland support via platform abstraction
647
+ - [x] MCP server, auto-enhance gate, AI-tool hooks, `score` command
648
+
649
+ ## License
650
+
651
+ MIT