lacy 1.8.11 → 1.8.13
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.
- package/.claude/settings.local.json +26 -0
- package/.github/FUNDING.yml +3 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +49 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +28 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +17 -0
- package/.github/SECURITY.md +32 -0
- package/.github/assets/logo-horizontal-dark.png +0 -0
- package/.github/assets/logo-horizontal-dark.svg +17 -0
- package/.github/assets/logo-horizontal.png +0 -0
- package/.github/assets/logo-horizontal.svg +17 -0
- package/.github/assets/logo.png +0 -0
- package/.github/assets/logo.svg +12 -0
- package/.github/assets/social-preview.png +0 -0
- package/.github/assets/social-preview.svg +50 -0
- package/.github/dependabot.yml +21 -0
- package/.github/workflows/ci.yml +80 -0
- package/.github/workflows/dependabot-auto-merge.yml +32 -0
- package/CHANGELOG.md +366 -0
- package/CLAUDE.md +340 -0
- package/CONTRIBUTING.md +141 -0
- package/LICENSE +110 -0
- package/README.md +201 -31
- package/RELEASING.md +148 -0
- package/STYLE.md +202 -0
- package/assets/hero.jpeg +0 -0
- package/assets/mode-indicators.jpeg +0 -0
- package/assets/real-time-indicator.jpeg +0 -0
- package/assets/supported-tools.jpeg +0 -0
- package/bin/lacy +1028 -0
- package/docs/ADDING-BACKENDS.md +124 -0
- package/docs/DEVTO-ARTICLE.md +94 -0
- package/docs/DOCS.md +68 -0
- package/docs/GROWTH-STRATEGY.md +119 -0
- package/docs/HN-RESPONSES.md +122 -0
- package/docs/LAUNCH-COPY-FINAL.md +105 -0
- package/docs/MARKETING.md +411 -0
- package/docs/NATURAL_LANGUAGE_DETECTION.md +204 -0
- package/docs/UGC_VIDEO_SCRIPT.md +114 -0
- package/docs/articles/devto-how-i-made-my-terminal-understand-english.md +117 -0
- package/docs/demo-color-transition.gif +0 -0
- package/docs/demo-full.gif +0 -0
- package/docs/demo-indicator.gif +0 -0
- package/docs/launch-thread-may6.sh +158 -0
- package/docs/videos/README.md +189 -0
- package/docs/videos/generate_frames.py +510 -0
- package/docs/videos/generate_frames_v2.py +729 -0
- package/docs/videos/generate_short.py +328 -0
- package/docs/videos/generate_short_v2.py +526 -0
- package/docs/videos/lacy-shell-demo-v2.mp4 +0 -0
- package/docs/videos/lacy-shell-demo.mp4 +0 -0
- package/docs/videos/lacy-shell-short-v2.mp4 +0 -0
- package/docs/videos/lacy-shell-short.mp4 +0 -0
- package/install.sh +1009 -0
- package/lacy.plugin.bash +75 -0
- package/lacy.plugin.fish +43 -0
- package/lacy.plugin.zsh +65 -0
- package/lib/animations.zsh +3 -0
- package/lib/bash/completions.bash +40 -0
- package/lib/bash/execute.bash +233 -0
- package/lib/bash/init.bash +40 -0
- package/lib/bash/keybindings.bash +134 -0
- package/lib/bash/prompt.bash +85 -0
- package/lib/commands/info.sh +25 -0
- package/lib/config.zsh +3 -0
- package/lib/constants.zsh +3 -0
- package/lib/core/animations.sh +271 -0
- package/lib/core/commands.sh +297 -0
- package/lib/core/config.sh +340 -0
- package/lib/core/constants.sh +366 -0
- package/lib/core/context.sh +260 -0
- package/lib/core/detection.sh +417 -0
- package/lib/core/mcp.sh +741 -0
- package/lib/core/modes.sh +123 -0
- package/lib/core/preheat.sh +496 -0
- package/lib/core/spinner.sh +174 -0
- package/lib/core/telemetry.sh +99 -0
- package/lib/detection.zsh +3 -0
- package/lib/execute.zsh +3 -0
- package/lib/fish/config.fish +66 -0
- package/lib/fish/detection.fish +90 -0
- package/lib/fish/execute.fish +105 -0
- package/lib/fish/keybindings.fish +42 -0
- package/lib/fish/prompt.fish +30 -0
- package/lib/keybindings.zsh +3 -0
- package/lib/mcp.zsh +3 -0
- package/lib/modes.zsh +3 -0
- package/lib/preheat.zsh +3 -0
- package/lib/prompt.zsh +3 -0
- package/lib/spinner.zsh +3 -0
- package/lib/zsh/completions.zsh +60 -0
- package/lib/zsh/execute.zsh +294 -0
- package/lib/zsh/init.zsh +26 -0
- package/lib/zsh/keybindings.zsh +551 -0
- package/lib/zsh/prompt.zsh +90 -0
- package/package.json +42 -27
- package/packages/lacy/README.md +61 -0
- package/packages/lacy/commands/info.sh +25 -0
- package/{index.mjs → packages/lacy/index.mjs} +247 -20
- package/packages/lacy/package-lock.json +71 -0
- package/packages/lacy/package.json +42 -0
- package/script/release.ts +487 -0
- package/squirrel.toml +36 -0
- package/tests/test_bash.bash +163 -0
- package/tests/test_core.sh +607 -0
- package/tests/test_gemini.sh +119 -0
- package/tests/test_gemini_mcp.sh +126 -0
- package/tests/test_preheat_server.zsh +446 -0
- package/uninstall.sh +52 -0
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Mission
|
|
6
|
+
|
|
7
|
+
Enable developers to talk directly to their shell.
|
|
8
|
+
|
|
9
|
+
## Project Overview
|
|
10
|
+
|
|
11
|
+
Lacy Shell is a shell plugin (ZSH and Bash 4+) that detects natural language and routes it to an AI coding agent. Commands execute normally. Natural language goes to the AI. No context switching required.
|
|
12
|
+
|
|
13
|
+
**Install location:** `~/.lacy`
|
|
14
|
+
**Package name:** `lacy` (npm)
|
|
15
|
+
|
|
16
|
+
## Installation Methods
|
|
17
|
+
|
|
18
|
+
| Method | Command |
|
|
19
|
+
| -------- | -------------------------------------------- |
|
|
20
|
+
| curl | `curl -fsSL https://lacy.sh/install \| bash` |
|
|
21
|
+
| npx | `npx lacy` |
|
|
22
|
+
| Homebrew | `brew install lacymorrow/tap/lacy` |
|
|
23
|
+
|
|
24
|
+
## Visual Feedback
|
|
25
|
+
|
|
26
|
+
**Real-time indicator** (left of prompt) changes color as you type:
|
|
27
|
+
|
|
28
|
+
- **Green (34)** = will execute in shell
|
|
29
|
+
- **Magenta (200)** = will go to AI agent
|
|
30
|
+
|
|
31
|
+
**First-word syntax highlighting** (ZSH only, via `region_highlight`):
|
|
32
|
+
|
|
33
|
+
- First word is highlighted **green bold** for shell commands, **magenta bold** for agent queries
|
|
34
|
+
- Updates on every `zle-line-pre-redraw` (accounts for leading whitespace)
|
|
35
|
+
|
|
36
|
+
**Mode indicator** shows current mode:
|
|
37
|
+
|
|
38
|
+
- ZSH: right prompt (`RPS1`) — `SHELL` (green) / `AGENT` (magenta) / `AUTO` (blue)
|
|
39
|
+
- Bash: PS1 badge — `SHELL` / `AGENT` / `AUTO` with matching colors
|
|
40
|
+
|
|
41
|
+
**Ghost text suggestions** (ZSH only, via `POSTDISPLAY`):
|
|
42
|
+
|
|
43
|
+
- After a reroute candidate fails and the agent responds, a suggestion appears as gray ghost text on the next empty prompt
|
|
44
|
+
- Right arrow or Tab accepts the suggestion into BUFFER
|
|
45
|
+
- Typing any character clears it; autosuggestions resumes normally
|
|
46
|
+
|
|
47
|
+
## Auto Mode Logic
|
|
48
|
+
|
|
49
|
+
In AUTO mode, routing is determined by:
|
|
50
|
+
|
|
51
|
+
1. **Agent words** (~150 common conversational words like `perfect`, `thanks`, `yes`, `no`, `explain`, `why`) → Agent (always, even single-word). Defined in `LACY_AGENT_WORDS` in `lib/core/constants.sh`.
|
|
52
|
+
2. **Shell reserved words** (`do`, `done`, `then`, `else`, `elif`, `fi`, `esac`, `in`, `select`, `function`, `coproc`, `{`, `}`, `!`, `[[`) → Agent (Layer 1 — these pass `command -v` but are never standalone commands)
|
|
53
|
+
3. First word is valid command → Shell
|
|
54
|
+
4. Single word, not a command → Shell (typo, let it error)
|
|
55
|
+
5. Multiple words, first not a command → Agent (natural language)
|
|
56
|
+
6. Valid command + NL arguments → Shell first, then agent on failure (post-execution reroute, silent)
|
|
57
|
+
|
|
58
|
+
Rule 2 detail: Shell reserved words pass `command -v` but are never valid as the first token of a standalone invocation. When a user types "do we have X" or "in the codebase", they mean natural language. List defined in `LACY_SHELL_RESERVED_WORDS` in `lib/core/constants.sh`. See `docs/NATURAL_LANGUAGE_DETECTION.md` for full spec.
|
|
59
|
+
|
|
60
|
+
Rule 6 detail: When a valid command receives NL arguments and fails (exit non-zero, code < 128), the error output is analyzed. If it matches a known error pattern AND has NL markers in the input, the command silently reroutes to the agent. No user-facing hint — just auto-reroute. Only active in auto mode.
|
|
61
|
+
|
|
62
|
+
Examples:
|
|
63
|
+
|
|
64
|
+
- `ls -la` → Shell (valid command)
|
|
65
|
+
- `what files are here` → Agent (agent word "what")
|
|
66
|
+
- `do we have a way to uninstall?` → Agent (reserved word "do")
|
|
67
|
+
- `in the codebase where is auth?` → Agent (reserved word "in")
|
|
68
|
+
- `cd..` → Shell (single word typo)
|
|
69
|
+
- `fix the bug` → Agent (multi-word natural language)
|
|
70
|
+
- `kill the process on localhost:3000` → Shell → Agent (4 bare words, "the" marker, fails)
|
|
71
|
+
- `go ahead and fix the tests` → Shell → Agent ("ahead" marker, "unknown command" error)
|
|
72
|
+
- `make sure the tests pass` → Shell → Agent ("sure" marker, "No rule to make target" error)
|
|
73
|
+
- `kill -9 my baby` → Shell only (2 bare words, below threshold)
|
|
74
|
+
- `echo the quick brown fox` → Shell only (succeeds, no reroute)
|
|
75
|
+
- `!rm -rf` → Shell (emergency bypass with `!` prefix)
|
|
76
|
+
|
|
77
|
+
## Canonical Functions
|
|
78
|
+
|
|
79
|
+
### `lacy_shell_classify_input(input)` — The Single Source of Truth
|
|
80
|
+
|
|
81
|
+
**File:** `lib/core/detection.sh`
|
|
82
|
+
|
|
83
|
+
All input classification MUST go through this function. It returns one of three strings:
|
|
84
|
+
|
|
85
|
+
- `"shell"` → route to shell (indicator: green)
|
|
86
|
+
- `"agent"` → route to AI agent (indicator: magenta)
|
|
87
|
+
- `"neutral"` → no routing decision yet (indicator: gray)
|
|
88
|
+
|
|
89
|
+
**Mode-aware behavior:**
|
|
90
|
+
|
|
91
|
+
1. **Empty input** → returns mode color (`shell`/`agent`) in locked modes, `neutral` in auto
|
|
92
|
+
2. **Shell mode** → always returns `shell` (after empty check)
|
|
93
|
+
3. **Agent mode** → always returns `agent` (after empty check)
|
|
94
|
+
4. **Auto mode** → applies detection heuristics
|
|
95
|
+
|
|
96
|
+
**Why this matters:**
|
|
97
|
+
|
|
98
|
+
- The indicator, execution, and highlighting ALL call this function
|
|
99
|
+
- Never create parallel detection logic — always extend this function
|
|
100
|
+
- The empty-input behavior ensures the indicator shows the correct mode color when idle
|
|
101
|
+
|
|
102
|
+
**Consumers:**
|
|
103
|
+
|
|
104
|
+
- ZSH: `keybindings.zsh:lacy_shell_update_input_indicator()` — real-time indicator color
|
|
105
|
+
- ZSH: `execute.zsh:lacy_shell_smart_accept_line()` — execution routing
|
|
106
|
+
- ZSH: `keybindings.zsh:lacy_shell_update_first_word_highlight()` — syntax highlighting
|
|
107
|
+
- Bash: `execute.bash:lacy_shell_smart_accept_line_bash()` — execution routing
|
|
108
|
+
|
|
109
|
+
### `lacy_shell_detect_natural_language(input, output, exit_code)` — Layer 2 Post-Execution
|
|
110
|
+
|
|
111
|
+
**File:** `lib/core/detection.sh`
|
|
112
|
+
|
|
113
|
+
Analyzes a failed shell command's output to detect natural language. Returns 0 if NL detected, 1 otherwise. Both criteria must match:
|
|
114
|
+
|
|
115
|
+
1. **Error pattern** — output contains a known shell error from `LACY_SHELL_ERROR_PATTERNS`
|
|
116
|
+
2. **NL signal** — second word is in `LACY_NL_MARKERS`, OR 5+ words with parse/syntax error
|
|
117
|
+
|
|
118
|
+
Minimum 2 words required. See `docs/NATURAL_LANGUAGE_DETECTION.md` for full algorithm.
|
|
119
|
+
|
|
120
|
+
### `_lacy_build_query_context(query)` — Terminal Context for Agent Queries
|
|
121
|
+
|
|
122
|
+
**File:** `lib/core/context.sh`
|
|
123
|
+
|
|
124
|
+
Prepends delta-based terminal context (cwd, git branch, exit code, recent commands, terminal output) to agent queries. Only includes what changed since the last query — zero overhead when nothing changed.
|
|
125
|
+
|
|
126
|
+
**Format:** `[cwd: /path] [git: branch] [exit: 1] [recent: cmd1 | cmd2] <query>`
|
|
127
|
+
|
|
128
|
+
**With terminal output** (tmux, screen, iTerm2, Terminal.app):
|
|
129
|
+
```
|
|
130
|
+
[cwd: /path] [exit: 1] [recent: npm test]
|
|
131
|
+
[terminal-output]
|
|
132
|
+
npm ERR! Test failed. See above for more details.
|
|
133
|
+
[/terminal-output]
|
|
134
|
+
why did that fail?
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Delta tracking:**
|
|
138
|
+
|
|
139
|
+
- CWD and git branch: compared against last-sent values, skipped if unchanged. Detached HEAD shows short commit hash instead of literal "HEAD"
|
|
140
|
+
- Exit code: only included when non-zero AND a shell command ran since the last query
|
|
141
|
+
- Recent commands: explicit ring buffer (max 10), not `fc`/`history` (avoids agent queries leaking)
|
|
142
|
+
- Terminal output: lazy screen capture via terminal/multiplexer API at query time (tmux, screen, iTerm2, Terminal.app). Stripped of ANSI escapes, capped at 50 lines (configurable via `context.output_lines`). tmux/screen checked first since terminal emulator APIs return wrong content inside multiplexers.
|
|
143
|
+
- Counters reset after each agent query — next query starts fresh
|
|
144
|
+
|
|
145
|
+
**Hook chain:**
|
|
146
|
+
|
|
147
|
+
1. `accept-line` routes to "shell" → `_lacy_ctx_mark_command($BUFFER)` records the command
|
|
148
|
+
2. `precmd` fires → `_lacy_ctx_on_precmd($?)` captures exit code (only if `_LACY_CTX_REAL_CMD` flag is set)
|
|
149
|
+
3. User types agent query → `_lacy_build_query_context()` builds delta, sets `_LACY_CTX_RESULT`, resets counters
|
|
150
|
+
4. `/new` session → `_lacy_ctx_reset()` clears all state so next query sends full context
|
|
151
|
+
|
|
152
|
+
**Why result variable, not stdout:** The function modifies global state (resets counters). Using `$()` subshell would lose those resets. `_LACY_CTX_RESULT` avoids the fork entirely.
|
|
153
|
+
|
|
154
|
+
## Plugin Coexistence (zsh-autosuggestions)
|
|
155
|
+
|
|
156
|
+
Lacy shares two ZLE resources with `zsh-autosuggestions` (and potentially `zsh-syntax-highlighting`). Mishandling either causes visible bugs. Full design rationale is documented in the header of `lib/zsh/keybindings.zsh`.
|
|
157
|
+
|
|
158
|
+
### `region_highlight` — tagged entries with `memo=lacy`
|
|
159
|
+
|
|
160
|
+
Multiple plugins write highlight specs to the `region_highlight` array. Lacy adds first-word coloring (green/magenta) and ghost text styling. These entries are tagged with `memo=lacy` (ZSH 5.8+ feature) so they can be selectively removed on each redraw without destroying highlights from other plugins.
|
|
161
|
+
|
|
162
|
+
**Rule:** Never use `region_highlight=()`. Always filter: `region_highlight=("${(@)region_highlight:#*memo=lacy*}")`. Always append `memo=lacy` to any highlight entry Lacy creates.
|
|
163
|
+
|
|
164
|
+
### `POSTDISPLAY` — suppressing autosuggestions during ghost text
|
|
165
|
+
|
|
166
|
+
Both Lacy (reroute ghost text) and autosuggestions (history suggestions) write to `POSTDISPLAY`. When Lacy's ghost text is active (BUFFER empty), call `_zsh_autosuggest_clear` before setting `POSTDISPLAY` to prevent autosuggestions from overwriting it. When the user starts typing, Lacy clears its ghost text and autosuggestions resumes normally.
|
|
167
|
+
|
|
168
|
+
### Right arrow / Tab — no dot prefix on fallback widgets
|
|
169
|
+
|
|
170
|
+
Lacy's `_lacy_forward_char_or_accept` and `_lacy_expand_or_accept` widgets check for Lacy ghost text first. On fallback, they call `zle forward-char` (not `zle .forward-char`). The dot prefix bypasses widget wrapping, which would skip autosuggestions' accept-suggestion behavior. Without the dot, autosuggestions' wrapper fires and right arrow / tab accept its suggestions normally.
|
|
171
|
+
|
|
172
|
+
## Supported AI CLI Tools
|
|
173
|
+
|
|
174
|
+
| Tool | Command | Prompt Flag |
|
|
175
|
+
| -------- | ---------------------- | ------------ |
|
|
176
|
+
| lash (recommended) | `lash run -c "query"` | `-c` |
|
|
177
|
+
| claude | `claude -p "query"` | `-p` |
|
|
178
|
+
| opencode | `opencode run -c "query"` | `-c` |
|
|
179
|
+
| gemini | `gemini --resume -p "query"` | `-p` |
|
|
180
|
+
| codex | `codex exec resume --last "query"` | positional |
|
|
181
|
+
| hermes | `hermes chat -q "query"` | `-q` |
|
|
182
|
+
| copilot | `copilot -p "query"` | `-p` |
|
|
183
|
+
| goose | `goose run -t "query"` | `-t` |
|
|
184
|
+
| amp | `amp -x "query"` | `-x` |
|
|
185
|
+
| aider | `aider --no-auto-commits --message "query"` | `--message` |
|
|
186
|
+
| custom | user-defined command | user-defined |
|
|
187
|
+
|
|
188
|
+
lash is the recommended default — it's an opencode fork built by the same author. Website: lash.lacy.sh. During onboarding, lacy offers to install lash if no AI CLI tool is detected.
|
|
189
|
+
|
|
190
|
+
All tools handle their own authentication - no API keys needed from lacy.
|
|
191
|
+
|
|
192
|
+
## Architecture
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
~/.lacy/
|
|
196
|
+
├── lacy.plugin.zsh # Entry point (ZSH)
|
|
197
|
+
├── lacy.plugin.bash # Entry point (Bash 4+)
|
|
198
|
+
├── config.yaml # User configuration
|
|
199
|
+
├── install.sh # Installer (bash + npx fallback)
|
|
200
|
+
├── uninstall.sh # Uninstaller
|
|
201
|
+
├── bin/
|
|
202
|
+
│ └── lacy # Standalone CLI (no Node required)
|
|
203
|
+
└── lib/
|
|
204
|
+
├── core/ # Shared modules (Bash 4+ and ZSH)
|
|
205
|
+
│ ├── constants.sh # Colors, timeouts, paths, detection arrays
|
|
206
|
+
│ ├── config.sh # YAML config, API key management
|
|
207
|
+
│ ├── modes.sh # Mode state (shell/agent/auto)
|
|
208
|
+
│ ├── spinner.sh # Loading spinner with shimmer text effect
|
|
209
|
+
│ ├── mcp.sh # Multi-tool routing (LACY_TOOL_CMD registry)
|
|
210
|
+
│ ├── preheat.sh # Agent preheating (background server, session reuse)
|
|
211
|
+
│ ├── context.sh # Delta-based terminal context for agent queries
|
|
212
|
+
│ ├── detection.sh # classify_input(), has_nl_markers(), detect_natural_language()
|
|
213
|
+
│ └── commands.sh # Shared command implementations (mode, tool, session, quit)
|
|
214
|
+
├── zsh/
|
|
215
|
+
│ ├── keybindings.zsh # Ctrl+Space toggle, indicator, first-word region_highlight
|
|
216
|
+
│ ├── prompt.zsh # Prompt with indicator, mode in right prompt
|
|
217
|
+
│ └── execute.zsh # Execution routing, reroute candidate logic
|
|
218
|
+
├── bash/
|
|
219
|
+
│ ├── init.bash # Bash adapter init (sources core + bash modules)
|
|
220
|
+
│ ├── keybindings.bash # Macro-based Enter override, Ctrl+Space toggle
|
|
221
|
+
│ ├── prompt.bash # Mode badge in PS1
|
|
222
|
+
│ └── execute.bash # Execution routing, reroute candidate logic
|
|
223
|
+
└── *.zsh # Backward-compat wrappers → lib/core/ or lib/zsh/
|
|
224
|
+
|
|
225
|
+
packages/lacy/ # npm package for interactive installer
|
|
226
|
+
├── package.json
|
|
227
|
+
├── index.mjs # @clack/prompts based installer
|
|
228
|
+
└── README.md
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## CLI (standalone, no Node required)
|
|
232
|
+
|
|
233
|
+
After installation, `~/.lacy/bin` is added to `$PATH`, making the `lacy` command available:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
lacy setup # Interactive settings (tool, mode, config) — fancy Node UI if available
|
|
237
|
+
lacy status # Show installation status
|
|
238
|
+
lacy doctor # Diagnose common issues
|
|
239
|
+
lacy update # Pull latest changes
|
|
240
|
+
lacy uninstall # Remove Lacy Shell — fancy Node UI if available
|
|
241
|
+
lacy reinstall # Fresh installation
|
|
242
|
+
lacy config # Show config
|
|
243
|
+
lacy config edit # Open config in $EDITOR
|
|
244
|
+
lacy install # Install (delegates to npx or curl installer)
|
|
245
|
+
lacy version # Show version
|
|
246
|
+
lacy help # Show all commands
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Source: `bin/lacy` (pure bash, zero dependencies)
|
|
250
|
+
|
|
251
|
+
**Hybrid Node delegation:** `setup`, `install`, and `uninstall` try `npx lacy@latest` first for the rich @clack/prompts UI, then fall back to bash if Node is unavailable. Set `LACY_NO_NODE=1` to force bash-only mode.
|
|
252
|
+
|
|
253
|
+
### Testing locally
|
|
254
|
+
|
|
255
|
+
`bin/lacy` delegates to `npx lacy@latest` which downloads the **published** npm package, not the local code. To test local changes to `packages/lacy/index.mjs`:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
# Run the local Node installer/menu directly
|
|
259
|
+
node packages/lacy/index.mjs # already-installed dashboard
|
|
260
|
+
node packages/lacy/index.mjs setup # same dashboard
|
|
261
|
+
node packages/lacy/index.mjs --help # help text
|
|
262
|
+
|
|
263
|
+
# Or force the bash fallback (skips npx entirely)
|
|
264
|
+
LACY_NO_NODE=1 bin/lacy setup
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Key Commands
|
|
268
|
+
|
|
269
|
+
- `mode [shell|agent|auto]` - Switch modes
|
|
270
|
+
- `mode` - Show current mode and color legend
|
|
271
|
+
- `tool` - Show active AI tool and available tools
|
|
272
|
+
- `tool set <name>` - Set AI tool (lash, claude, opencode, gemini, codex, hermes, copilot, goose, amp, aider, custom, auto) — persists to config.yaml
|
|
273
|
+
- `tool set custom "cmd"` - Set a custom command as the AI tool
|
|
274
|
+
- `/new` / `/reset` / `/clear` - Start a new conversation session
|
|
275
|
+
- `/resume` - Resume the last saved session
|
|
276
|
+
- `ask "question"` - Direct query to agent
|
|
277
|
+
- `quit` / `stop` / `exit` - Exit lacy shell
|
|
278
|
+
- `Ctrl+Space` - Toggle between modes
|
|
279
|
+
- `Ctrl+C` (2x) - Quit
|
|
280
|
+
|
|
281
|
+
Leading-slash commands (e.g. `/new`) are intercepted before shell execution and routed to the session handler. The slash is stripped and matched against known session commands.
|
|
282
|
+
|
|
283
|
+
## Key Files
|
|
284
|
+
|
|
285
|
+
- `lib/core/constants.sh` - Colors, paths, `LACY_AGENT_WORDS`, `LACY_SHELL_RESERVED_WORDS`, `LACY_NL_MARKERS`, `LACY_SHELL_ERROR_PATTERNS`
|
|
286
|
+
- `lib/core/detection.sh` - **`lacy_shell_classify_input()`** (canonical), `lacy_shell_has_nl_markers()`, `lacy_shell_detect_natural_language()`
|
|
287
|
+
- `lib/core/mcp.sh` - `_lacy_run_tool_cmd()` safe executor, `lacy_tool_cmd()` registry, `lacy_shell_query_agent()` routing
|
|
288
|
+
- `lib/core/context.sh` - `_lacy_build_query_context()` delta-based terminal context, `_lacy_ctx_mark_command()`, `_lacy_ctx_on_precmd()`
|
|
289
|
+
- `lib/core/config.sh` - `agent_tools.active` parsing → `LACY_ACTIVE_TOOL`
|
|
290
|
+
- `lib/core/spinner.sh` - Braille spinner + shimmer "Thinking" animation during AI queries
|
|
291
|
+
- `lib/core/preheat.sh` - Background server (lash/opencode) + session reuse (claude), `lacy_session_new()`, `lacy_session_resume()`
|
|
292
|
+
- `lib/core/commands.sh` - Shared command implementations: mode, tool, session, quit (portable Bash 4+/ZSH)
|
|
293
|
+
- `lib/zsh/execute.zsh` - `lacy_shell_tool()` command, routing logic, reroute candidates, slash-command interception
|
|
294
|
+
- `lib/zsh/keybindings.zsh` - Real-time indicator logic, first-word `region_highlight`
|
|
295
|
+
- `install.sh` - Bash installer with npx fallback, interactive menu
|
|
296
|
+
- `packages/lacy/index.mjs` - Node installer with @clack/prompts
|
|
297
|
+
- `docs/NATURAL_LANGUAGE_DETECTION.md` - Shared spec for NL detection (synced with lash)
|
|
298
|
+
|
|
299
|
+
## Configuration
|
|
300
|
+
|
|
301
|
+
Config file: `~/.lacy/config.yaml`
|
|
302
|
+
|
|
303
|
+
```yaml
|
|
304
|
+
agent_tools:
|
|
305
|
+
active: claude # or lash, opencode, gemini, codex, hermes, copilot, goose, amp, aider, custom, empty for auto
|
|
306
|
+
# custom_command: "your-command -flags" # used when active: custom
|
|
307
|
+
|
|
308
|
+
api_keys:
|
|
309
|
+
openai: "sk-..." # Only needed if no CLI tool
|
|
310
|
+
anthropic: "sk-..."
|
|
311
|
+
|
|
312
|
+
modes:
|
|
313
|
+
default: auto
|
|
314
|
+
# Preheat: keep agents warm between queries
|
|
315
|
+
# preheat:
|
|
316
|
+
# eager: false # Start background server on plugin load
|
|
317
|
+
# server_port: 4096 # Port for background server
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**Preheating:** lash/opencode use a background server (`lash serve`) to eliminate cold-start. Claude uses `--resume SESSION_ID` for conversation continuity. Other tools have no preheating.
|
|
321
|
+
|
|
322
|
+
## Development Notes
|
|
323
|
+
|
|
324
|
+
- Install path changed from `~/.lacy-shell` to `~/.lacy`
|
|
325
|
+
- Repo (`lib/`) and install dir (`~/.lacy/lib/`) are separate copies — changes must be applied to both
|
|
326
|
+
- Prompt capture is deferred to first `precmd`/`PROMPT_COMMAND` so user's shell profile loads first
|
|
327
|
+
- Indicator only updates when type changes (avoids flickering)
|
|
328
|
+
- Colors: Green=34, Magenta=200, Blue=75, Gray=238
|
|
329
|
+
- Use `print -P` (not `echo`) for colored output in ZSH — `%F{...}%f` escapes need `print -P`
|
|
330
|
+
- Use `printf '\e[38;5;Nm...\e[0m'` for colored output in Bash
|
|
331
|
+
- Installer uses `printf` instead of `echo -e` for portability
|
|
332
|
+
- Node installer falls back to bash if npm package not available
|
|
333
|
+
|
|
334
|
+
### Bash adapter notes
|
|
335
|
+
|
|
336
|
+
- **Enter key**: Can't use `bind -x` directly on `\C-m` — it replaces accept-line entirely, so shell commands never submit. Instead, bind classification to a hidden key (`\C-x\C-l`) and make `\C-m` a macro: `"\C-x\C-l\C-j"` (classify, then accept-line)
|
|
337
|
+
- **Spinner**: Background `{ ... } &` jobs dump their source on exit via bash's `[N] Done ...` notification. Fix: `disown` the PID immediately after starting; use `kill` + `sleep` instead of `wait` for cleanup
|
|
338
|
+
- **No real-time indicator**: Bash can't redraw PS1 on keystroke (no `zle-line-pre-redraw` equivalent). Mode badge in PS1 updates on each prompt cycle only
|
|
339
|
+
- **Ctrl+Space**: Uses macro `"\C-a\C-k _lacy_mode_toggle_\C-j"` — types hidden command and submits, so PROMPT_COMMAND can update PS1
|
|
340
|
+
- **macOS default bash is 3.2** — adapter requires 4+ and shows a clear error if version is too old. Users install modern bash via `brew install bash`
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Contributing to Lacy
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing to Lacy! This guide will help you get started.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
- **ZSH** or **Bash 4+** (macOS ships with Bash 3.2 -- install Bash 4+ via `brew install bash`)
|
|
10
|
+
- **Git** (for development; not required for end-user installation)
|
|
11
|
+
- An AI CLI tool for testing agent routing (Claude Code, Lash, Gemini CLI, etc.)
|
|
12
|
+
|
|
13
|
+
### Development Setup
|
|
14
|
+
|
|
15
|
+
1. **Fork and clone** the repository:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/<your-username>/lacy.git
|
|
19
|
+
cd lacy
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
2. **Symlink for development** instead of using the installed copy:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Back up your installed copy if you have one
|
|
26
|
+
mv ~/.lacy ~/.lacy.bak
|
|
27
|
+
|
|
28
|
+
# Symlink repo to install path
|
|
29
|
+
ln -s "$(pwd)" ~/.lacy
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
3. **Source the plugin** in your shell:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# ZSH
|
|
36
|
+
source ~/.lacy/lacy.plugin.zsh
|
|
37
|
+
|
|
38
|
+
# Bash 4+
|
|
39
|
+
source ~/.lacy/lacy.plugin.bash
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
4. **Open a new terminal** to test your changes. After editing files, open a fresh shell to reload.
|
|
43
|
+
|
|
44
|
+
### Project Structure
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
lib/
|
|
48
|
+
core/ # Shared modules (Bash 4+ and ZSH)
|
|
49
|
+
constants.sh # Colors, detection arrays, error patterns
|
|
50
|
+
config.sh # YAML config parsing
|
|
51
|
+
detection.sh # Input classification (the core algorithm)
|
|
52
|
+
modes.sh # Mode state management
|
|
53
|
+
context.sh # Terminal context for agent queries
|
|
54
|
+
commands.sh # Built-in command implementations
|
|
55
|
+
spinner.sh # Loading animation
|
|
56
|
+
mcp.sh # AI tool routing
|
|
57
|
+
preheat.sh # Agent warm-up
|
|
58
|
+
zsh/ # ZSH-specific modules
|
|
59
|
+
bash/ # Bash 4+ adapter modules
|
|
60
|
+
bin/lacy # Standalone CLI (pure bash)
|
|
61
|
+
packages/lacy/ # npm package (interactive installer)
|
|
62
|
+
tests/ # Test scripts
|
|
63
|
+
docs/ # Documentation and specs
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Making Changes
|
|
67
|
+
|
|
68
|
+
### Branching
|
|
69
|
+
|
|
70
|
+
Create a feature branch from `main`:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
git checkout -b feat/your-feature
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Code Style
|
|
77
|
+
|
|
78
|
+
- Shell scripts should be compatible with **Bash 4+** (for `lib/core/`) or **ZSH** (for `lib/zsh/`)
|
|
79
|
+
- Use `printf` instead of `echo -e` for portability
|
|
80
|
+
- Use `print -P` for colored output in ZSH (`%F{N}%f` escapes)
|
|
81
|
+
- Use `printf '\e[38;5;Nm...\e[0m'` for colored output in Bash
|
|
82
|
+
- Keep functions focused and well-named
|
|
83
|
+
- Use conventional commit messages: `feat:`, `fix:`, `chore:`, `docs:`
|
|
84
|
+
|
|
85
|
+
### Key Design Principles
|
|
86
|
+
|
|
87
|
+
- **Single source of truth**: All input classification goes through `lacy_shell_classify_input()` in `lib/core/detection.sh`. Never create parallel detection logic.
|
|
88
|
+
- **Plugin coexistence**: Lacy shares ZLE resources with `zsh-autosuggestions` and `zsh-syntax-highlighting`. Always tag `region_highlight` entries with `memo=lacy`. Never clear `region_highlight` with `region_highlight=()`.
|
|
89
|
+
- **No Node dependency at runtime**: The shell plugin and CLI (`bin/lacy`) must work without Node.js installed. Node is only used for the optional interactive installer.
|
|
90
|
+
- **Bash/ZSH portability**: Core modules in `lib/core/` must work in both Bash 4+ and ZSH.
|
|
91
|
+
|
|
92
|
+
### Testing
|
|
93
|
+
|
|
94
|
+
Run the test suite in both shells:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
bash tests/test_core.sh
|
|
98
|
+
zsh tests/test_core.sh
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
For Bash-specific tests:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
bash tests/test_bash.bash
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Manual testing is also important. Open a fresh shell and verify:
|
|
108
|
+
|
|
109
|
+
- Mode switching works (`mode shell`, `mode agent`, `mode auto`, `Ctrl+Space`)
|
|
110
|
+
- Input classification is correct (commands stay green, natural language turns magenta)
|
|
111
|
+
- Agent routing works for your change
|
|
112
|
+
- No regressions in normal shell command execution
|
|
113
|
+
|
|
114
|
+
## Submitting a Pull Request
|
|
115
|
+
|
|
116
|
+
1. **Test your changes** in both ZSH and Bash 4+ when modifying `lib/core/` code
|
|
117
|
+
2. **Commit** with a conventional commit message:
|
|
118
|
+
```bash
|
|
119
|
+
git commit -m "feat: add support for fish shell"
|
|
120
|
+
```
|
|
121
|
+
3. **Push** your branch and open a PR against `main`
|
|
122
|
+
4. **Describe** what your PR does and why. Include before/after behavior if applicable.
|
|
123
|
+
5. **Link** any related issues
|
|
124
|
+
|
|
125
|
+
## Reporting Bugs
|
|
126
|
+
|
|
127
|
+
Open an issue with:
|
|
128
|
+
|
|
129
|
+
- Your shell and version (`echo $SHELL && $SHELL --version`)
|
|
130
|
+
- Your OS (`uname -a`)
|
|
131
|
+
- Steps to reproduce
|
|
132
|
+
- Expected vs. actual behavior
|
|
133
|
+
- Output of `lacy doctor` if applicable
|
|
134
|
+
|
|
135
|
+
## Feature Requests
|
|
136
|
+
|
|
137
|
+
Open an issue describing the feature, the problem it solves, and how you'd expect it to work. Discussion is welcome before implementation.
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
By contributing, you agree that your contributions will be licensed under the [MIT License](LICENSE).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2025 Lacy Morrow
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|