codelantern-agent-cli 1.0.0 โ†’ 1.0.2

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/README.md CHANGED
@@ -1,27 +1,59 @@
1
1
  # ๐Ÿฎ Code Lantern CLI (`codelantern-agent-cli`)
2
2
 
3
- > **Personal AI coding assistant for the terminal powered directly by the Google Gemini API.**
4
- > Cross-platform terminal command: **`lantern`**
5
- > Default model: **`gemini-3.8-flash`**
3
+ > **Personal AI coding assistant for the terminal with native OS credential storage, automatic key reuse, multi-provider intelligence, and ironclad safety.**
4
+ > Terminal command: **`lantern`**
5
+ > Package: **`codelantern-agent-cli`**
6
+ > Release status: **`1.0.1` published on npm** | **`1.0.2` prepared locally**
7
+ > Default provider: **Google Gemini** (`gemini-3.8-flash`)
6
8
 
7
- Code Lantern CLI is an autonomous terminal coding assistant designed to help you inspect, build, edit, and troubleshoot codebases directly from your shell. It calls Google's official Gemini API directly using `@google/genai`โ€”it does not depend on Antigravity, Codex, or Gemini CLI being installed.
9
+ Code Lantern CLI is a resilient, autonomous terminal coding assistant designed to help you inspect, build, edit, and troubleshoot codebases directly from your shell. It connects directly to your chosen AI providersโ€”Google Gemini, OpenRouter, OpenAI, Anthropic Claude, or custom OpenAI-compatible endpointsโ€”with zero third-party agent dependencies.
8
10
 
9
11
  ---
10
12
 
11
- ## โšก Key Highlights
12
-
13
- - **Direct Gemini Connection**: Native integration with Google's `@google/genai` TypeScript SDK using `gemini-3.8-flash` by default.
14
- - **Cross-Platform Architecture**: Engineered to run consistently on **macOS** (both Apple Silicon M-series and Intel x86_64) and **Windows** (Command Prompt, PowerShell, Windows Terminal), as well as Linux.
15
- - **Safe Mode with Diff Previews**: Inspects before modifying. Shows colored unified patch diffs (`+ added`, `- removed`) and command previews before requesting interactive approval.
16
- - **Deliberate YOLO Mode (`--yolo`)**: Auto-approves operations when explicitly requested, while maintaining strict workspace containment and secret shielding boundaries.
17
- - **Read-Only Plan Mode (`lantern plan`)**: Formulates comprehensive, step-by-step implementation plans without mutating files or running shell commands.
18
- - **Piped Unix / PowerShell Workflows**: Pipe test failures, git diffs, or files into Lantern:
19
- - macOS/Linux: `npm test 2>&1 | lantern "diagnose error"`
20
- - Windows PowerShell: `Get-Content error.log | lantern "how do I fix this?"`
21
- - **Context Awareness**: Respects `.gitignore`, ignores vendor and build trees (`node_modules`, `dist`, `.git`), detects `LANTERN.md` / `GEMINI.md` project rules, and renders ASCII file trees.
22
- - **Security Sandbox**: Rejects path traversal (`../../`) and symlink escapes. Masks `.env` files, private keys, and scrubs API tokens from transcripts and logs.
23
- - **Model Context Protocol (MCP)**: Native stdio client integration via `@modelcontextprotocol/sdk` to dynamically expose external database, API, and tool servers to Gemini.
24
- - **Rich Terminal Experience**: Streaming responses, syntax-highlighted markdown, animated spinners, multiline prompt input (`\`), command history, and slash commands.
13
+ ## โšก What's New in v1.0.2
14
+
15
+ - ๐Ÿš€ **Connection & Request Lifecycle Resilience (Google Gemini Hang Resolution)**:
16
+ - **Identified Root Cause**: In `@google/genai`, the client uses an internal Undici dispatcher configured with disabled header/body timeouts (`headersTimeout: 0, bodyTimeout: 0`). The previous implementation did not pass `abortSignal` or `httpOptions.timeout` to `client.models.generateContentStream`, nor did it bound the connection promise. Any stalled socket, proxy delay, or handshake freeze caused the application to await `generateContentStream` indefinitely while the spinner remained frozen at `Connecting to Google Gemini (gemini-3.8-flash)...`.
17
+ - **End-to-End Signal & Timeout Propagation**: Propagates a unified abort signal through credential resolution, provider initialization, network connection, streaming token consumption, and tool execution.
18
+ - **Bounded Connection Setup**: Introduces `connectTimeoutMs` (default: 15s or bounded by `timeoutMs`) using provider-level `withTimeoutRace` so that connection stalls or socket hangs abort promptly and cleanly.
19
+ - **Real Progress Stages**: Real-time spinner dynamically transitions through:
20
+ - `Resolving credentials for <provider>...`
21
+ - `Connecting to <provider> (<model>)...`
22
+ - `Waiting for first token from <provider> (<model>)...`
23
+ - `Receiving streaming response...`
24
+ - `Executing tool <name>...`
25
+ - **Zero Stuck Spinners**: Empty text chunks or function-call-only responses unconditionally stop the spinner immediately upon arrival.
26
+ - **Actionable Diagnostics**: Clear, specific error formatting for timeouts, cancellations, 401/403 authentication failures, 404 model access issues, and 429 rate limits without leaking API keys.
27
+ - **Safe Retries**: Only safe transient network errors (503, connection resets) retry with capped exponential backoff. Previously executed tool operations are never repeated.
28
+ - ๐Ÿ” **Persistent Native OS Credential Storage & Automatic Reuse**:
29
+ - **Native OS Stores**: Keys are securely saved directly into your operating system's native credential vault:
30
+ - **macOS**: Apple Keychain via native Keychain Services.
31
+ - **Windows**: Windows Credential Manager.
32
+ - **One-Time Key Setup**: Enter an API key once per provider (`lantern keys set <provider>` or on prompt when first switching). Lantern securely remembers it and automatically reuses it across all future CLI sessions, requests, model queries, and provider switches. You never have to re-paste keys on every start.
33
+ - **Zero Plaintext Storage**: Keys are never stored in plaintext in `credentials.json`, config files, transcripts, logs, or command arguments.
34
+ - **Prebuilt Cross-Platform Engine**: Uses `@napi-rs/keyring` (prebuilt N-API binaries, no Python/node-gyp/C++ toolchain required during `npm install -g`) with native CLI fallbacks (`/usr/bin/security` on macOS, PowerShell Win32 API on Windows).
35
+ - **Explicit Environment Overrides**: Environment variables (`GEMINI_API_KEY`, `OPENROUTER_API_KEY`, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`) continue to take explicit precedence over stored credentials.
36
+ - **Seamless Crash-Safe Migration**: Automatically inspects and migrates existing keys from legacy `~/.codelantern/credentials.json` into your native OS credential store, verifies retrieval, and cleans up legacy material safely without data loss.
37
+ - **Masked Input Prompts**: Interactive key entry is masked (`*`) so secrets are never echoed on your terminal screen.
38
+ - ๐Ÿ”„ **In-Session Provider & Model Switching**:
39
+ - Switch providers and models **directly inside the running CLI** without restarting or exiting to the shell.
40
+ - `/provider` โ€” View configured providers and interactively select one.
41
+ - `/provider <name>` โ€” Switch the running session immediately (e.g. `/provider openrouter`, `/provider gemini`). Reuses the saved key automatically; asks only if no key is stored.
42
+ - `/provider default <name>` โ€” Set a provider as your persistent default and activate it immediately.
43
+ - `/model` โ€” Live discovery of usable models from the active provider with interactive selection.
44
+ - `/model <model-id>` โ€” Switch the active session to any valid model ID.
45
+ - `/model default <model-id>` โ€” Save a model as your persistent default.
46
+ - Real-time prompt indicator reflects the active provider (e.g. `lantern (openrouter) โฏ `).
47
+ - Preserves entire conversation history across provider and model switches.
48
+ - ๐ŸŽฏ **Capability Classification & Safety Guardrails**:
49
+ - Distinguishes **Interactive Coding Models** (tools + chat + streaming) from **Chat-Only Models** and **Specialized Models** (Embeddings, Image generation, Audio/Speech, Batch-only).
50
+ - Rejects attempts to select incompatible specialized models (such as `text-embedding-3-small` or `dall-e-3`) with clear explanations and offers compatible coding alternatives.
51
+ - ๐Ÿš€ **Performance & Hang Elimination**:
52
+ - **Bounded Request & First-Token Timeouts (`TTFT`)**: Configurable `--timeout` (default: 60s) and `--first-token-timeout` (default: 30s) eliminate indefinite network stalls.
53
+ - **Immediate Unbuffered Streaming**: Response tokens stream directly to stdout as they arrive.
54
+ - **Real-Time Spinner Stages**: Spinner transitions dynamically across `Connecting...`, `Waiting for first token...`, `Receiving response...`, and `Executing tool [name]...`.
55
+ - **Instant Cancellation (Ctrl+C)**: Pressing Ctrl+C aborts in-flight requests instantly via linked `AbortController`, cleanly returning to the prompt.
56
+ - **Safe Backoff Retries**: Transient HTTP failures (429/503) retry with small, capped backoff. Mutating tools (file edits, bash execution) are never duplicated.
25
57
 
26
58
  ---
27
59
 
@@ -32,330 +64,369 @@ Code Lantern CLI is an autonomous terminal coding assistant designed to help you
32
64
  | **Node.js** | `>= 18.0.0` (Node 20 or Node 22 LTS recommended) |
33
65
  | **npm** | `>= 9.0.0` |
34
66
  | **Operating Systems** | macOS 12+ (Apple Silicon `arm64` & Intel `x64`), Windows 10/11 (PowerShell & CMD), Linux |
35
- | **API Key** | Google Gemini API Key ([Get one free at Google AI Studio](https://aistudio.google.com/app/apikey)) |
67
+ | **Native Storage** | macOS Keychain (built-in) or Windows Credential Manager (built-in) |
68
+ | **API Keys** | Any of: `GEMINI_API_KEY`, `OPENROUTER_API_KEY`, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, or custom endpoint |
36
69
 
37
70
  ---
38
71
 
39
- ## ๐Ÿ“ฆ Installation
72
+ ## ๐Ÿ“ฆ Installation & Startup
40
73
 
41
- ### Option A: Local Development Installation
74
+ ### Option A: Global Installation from npm
75
+ The current published version on the npm registry is **`1.0.1`**:
42
76
 
43
- Clone or open the project folder in your terminal:
77
+ #### macOS & Linux:
78
+ ```bash
79
+ npm install -g codelantern-agent-cli
80
+ lantern --version
81
+ # Output: 1.0.1
82
+ ```
44
83
 
84
+ #### Windows (PowerShell or Command Prompt):
85
+ ```powershell
86
+ npm install -g codelantern-agent-cli
87
+ lantern --version
88
+ # Output: 1.0.1
89
+ ```
90
+ *npm automatically generates `lantern.cmd` and `lantern.ps1` wrappers on Windows, placing them in your npm global PATH.*
91
+
92
+ ### Option B: Local Source Installation (v1.0.2)
45
93
  ```bash
46
94
  cd "my own cli"
47
95
 
48
96
  # 1. Install dependencies
49
97
  npm install
50
98
 
51
- # 2. Build the executable
99
+ # 2. Build production bundle
52
100
  npm run build
53
101
 
54
- # 3. Link the 'lantern' command globally
102
+ # 3. Link globally for local testing
55
103
  npm link
56
- ```
57
-
58
- Verify your installation:
59
104
 
60
- ```bash
61
105
  lantern --version
62
- # Output: 1.0.0
106
+ # Output: 1.0.2
63
107
  ```
64
108
 
65
- ### Option B: Global Installation after Publishing to npm
66
-
67
- Once published to npm under `codelantern-agent-cli`:
68
-
69
- #### On macOS / Linux:
109
+ ### Starting Code Lantern
110
+ Start interactive mode:
70
111
  ```bash
71
- npm install -g codelantern-agent-cli
72
- lantern --version
112
+ lantern
73
113
  ```
114
+ You will be greeted with the banner showing your active provider, model, workspace, and security mode:
115
+ ```text
116
+ ๐Ÿฎ Code Lantern CLI v1.0.2
117
+ Provider: Google Gemini (gemini) | Model: gemini-3.8-flash | Workspace: /path/to/project
118
+ Status: SAFE MODE (Approval Prompts) | Type /help for commands
74
119
 
75
- #### On Windows (PowerShell or Command Prompt):
76
- ```powershell
77
- npm install -g codelantern-agent-cli
78
- lantern --version
120
+ lantern (gemini) โฏ
79
121
  ```
80
- *npm automatically generates `lantern.cmd` and `lantern.ps1` wrappers on Windows, placing them in your npm global PATH.*
81
122
 
82
123
  ---
83
124
 
84
- ## ๐Ÿ”‘ Gemini API Key Configuration
125
+ ## ๐Ÿ”‘ Secure API Key Storage & Automatic Reuse
85
126
 
86
- Code Lantern CLI reads your API key from the standard environment variable `GEMINI_API_KEY`.
127
+ Code Lantern uses a zero-plaintext credential model. You enter your API key once per provider, and Lantern securely stores it in your OS credential store and reuses it automatically across all future commands and sessions.
87
128
 
88
- ### macOS / Linux (`zsh` or `bash`)
129
+ ### One-Time Key Setup (Shell)
89
130
 
90
- Add to `~/.zshrc` or `~/.bashrc`:
131
+ Run `lantern keys set <provider>`:
91
132
  ```bash
92
- export GEMINI_API_KEY="AIzaSyYourActualGeminiApiKeyHere"
133
+ # Set Google Gemini API key
134
+ lantern keys set gemini
135
+
136
+ # Set OpenRouter API key
137
+ lantern keys set openrouter
138
+
139
+ # Set OpenAI or Anthropic keys
140
+ lantern keys set openai
141
+ lantern keys set anthropic
93
142
  ```
94
- Or set it for the current session:
95
- ```bash
96
- export GEMINI_API_KEY="AIzaSyYourActualGeminiApiKeyHere"
143
+
144
+ Lantern prompts for your key with a masked input prompt (`*`). As you type, nothing is displayed in plaintext.
145
+ Once entered, Lantern verifies that the key can be retrieved from your native OS store and saves it:
146
+ ```text
147
+ Enter API key for 'gemini': ***************************************
148
+ โœ“ Successfully saved API key for 'gemini' to macOS Keychain (AIza...W9q0)
149
+ Lantern will automatically reuse this key in future sessions and commands.
97
150
  ```
98
151
 
99
- ### Windows (PowerShell)
152
+ ### In-Session Automatic Key Entry
153
+ If you launch Lantern or switch to a provider that does not yet have a stored key:
154
+ 1. Lantern prompts you right inside the terminal:
155
+ ```text
156
+ ๐Ÿฎ No API key configured for OpenRouter (openrouter).
157
+ Lantern will securely save this key to your macOS Keychain so you never have to re-enter it.
158
+ Enter API key for 'openrouter': *******************************************************
159
+ โœ“ Saved key for 'OpenRouter' to macOS Keychain (sk-o...097d)
160
+ ```
161
+ 2. Lantern saves it to your OS credential store, tests connectivity, and proceeds immediately.
162
+ 3. Every future run, model listing, or session switch reuses that key automatically without prompting again!
100
163
 
101
- For the current session:
102
- ```powershell
103
- $env:GEMINI_API_KEY="AIzaSyYourActualGeminiApiKeyHere"
164
+ ### Viewing Configured Keys Safely
165
+ Inspect configured providers and their storage source without exposing secrets:
166
+ ```bash
167
+ lantern keys list
104
168
  ```
105
169
 
106
- Persistently for user environment:
107
- ```powershell
108
- [System.Environment]::SetEnvironmentVariable('GEMINI_API_KEY', 'AIzaSyYourActualGeminiApiKeyHere', 'User')
170
+ Example output:
171
+ ```text
172
+ ๐Ÿฎ Configured Provider API Keys
173
+ Storage: macOS Keychain
174
+ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
175
+ Provider Source Masked Key
176
+ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
177
+ gemini [macOS Keychain] AIza...W9q0
178
+ openai none (not configured)
179
+ anthropic none (not configured)
180
+ openrouter [env: OPENROUTER_API_KEY] sk-o...097d
181
+ custom none (not configured)
109
182
  ```
110
183
 
111
- ### Windows (Command Prompt `cmd.exe`)
184
+ ### Environment Variable Overrides
185
+ Environment variables take explicit precedence over stored credentials when present:
112
186
 
113
- For current session:
114
- ```cmd
115
- set GEMINI_API_KEY=AIzaSyYourActualGeminiApiKeyHere
187
+ #### macOS / Linux (`zsh` or `bash`):
188
+ ```bash
189
+ export GEMINI_API_KEY="AIzaSyYourGeminiApiKeyHere"
190
+ export OPENROUTER_API_KEY="sk-or-v1-YourOpenRouterKeyHere"
191
+ export OPENAI_API_KEY="sk-proj-..."
192
+ export ANTHROPIC_API_KEY="sk-ant-..."
116
193
  ```
117
194
 
118
- Persistently:
119
- ```cmd
120
- setx GEMINI_API_KEY "AIzaSyYourActualGeminiApiKeyHere"
195
+ #### Windows (PowerShell):
196
+ ```powershell
197
+ $env:GEMINI_API_KEY="AIzaSyYourGeminiApiKeyHere"
198
+ $env:OPENROUTER_API_KEY="sk-or-v1-YourOpenRouterKeyHere"
121
199
  ```
122
200
 
123
- > **Security Note:** Code Lantern never prints, commits, logs, or saves your raw API key in session transcripts.
201
+ ### Replacing or Removing Keys
202
+ - **To replace an existing key**: Simply run `lantern keys set <provider>` again. The new key overwrites the old entry in your OS credential store.
203
+ - **To remove a stored key**:
204
+ ```bash
205
+ lantern keys remove gemini
206
+ # Output: โœ“ Removed stored key for 'gemini' from macOS Keychain
207
+ ```
208
+
209
+ ### Automatic Legacy Migration
210
+ If you previously had keys saved in the legacy `~/.codelantern/credentials.json` format:
211
+ 1. Lantern automatically detects the file upon startup or credential lookup.
212
+ 2. It decrypts the legacy payload in-memory without displaying or logging it.
213
+ 3. It saves the key to your native OS credential store and verifies retrieval.
214
+ 4. Only after successful verification, the provider entry is purged from the legacy file.
215
+ 5. If Lantern is interrupted, remaining keys are preserved for safe retry on the next run.
216
+ 6. Once all keys are migrated, the obsolete file is safely deleted.
124
217
 
125
218
  ---
126
219
 
127
- ## ๐Ÿฉบ Diagnostics (`lantern doctor`)
220
+ ## ๐Ÿ”„ In-Session Provider & Model Switching
128
221
 
129
- Run `lantern doctor` at any time to verify your environment, API key validity, git availability, and MCP servers:
222
+ Code Lantern allows you to switch providers and models **from inside the running CLI** without exiting to your shell.
130
223
 
131
- ```bash
132
- lantern doctor
133
- ```
224
+ > **Important Distinction**:
225
+ > - **In-Session Slash Commands** (prefixed with `/`) are typed **inside Lantern** at the `lantern (...) โฏ` prompt.
226
+ > - **System Shell Commands** (prefixed with `lantern`) are typed in your standard terminal (`bash`, `zsh`, `cmd`, `pwsh`).
134
227
 
135
- Example output:
136
- ```text
137
- ๐Ÿฎ Code Lantern Doctor โ€” Diagnostics
138
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
139
- โœ“ Platform / OS: macOS (Apple Silicon)
140
- โœ“ Node.js Runtime: v26.12.1 (compatible)
141
- โœ“ GEMINI_API_KEY: Found (AIza...W9q0)
142
- โœ“ Gemini API Auth: Verified (contacted 'gemini-3.8-flash')
143
- โœ“ Git CLI: Available (git version 2.54.0)
144
- โœ“ Config File: ~/.codelantern/config.json (Model: gemini-3.8-flash)
145
- โœ“ Session Storage: ~/.codelantern/sessions (0 stored session(s))
146
- โ„น MCP Configuration: No external MCP servers configured (optional)
147
- โœ“ Project Instructions: Found (LANTERN.md) in /workspace
148
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
149
- โœจ All systems healthy! Code Lantern CLI is ready to assist.
150
- ```
228
+ ### In-Session Provider Commands (Inside Lantern)
229
+
230
+ | In-Session Command | What It Does |
231
+ | :--- | :--- |
232
+ | **`/provider`** | Lists configured providers with status and lets you select one interactively |
233
+ | **`/provider openrouter`** | Switches current session to OpenRouter immediately (reuses saved key automatically) |
234
+ | **`/provider gemini`** | Switches current session to Google Gemini immediately (reuses saved key automatically) |
235
+ | **`/provider openai`** | Switches current session to OpenAI immediately |
236
+ | **`/provider anthropic`** | Switches current session to Anthropic Claude immediately |
237
+ | **`/provider default openrouter`** | Saves OpenRouter as persistent default in config and activates it immediately |
238
+
239
+ ### In-Session Model Commands (Inside Lantern)
240
+
241
+ | In-Session Command | What It Does |
242
+ | :--- | :--- |
243
+ | **`/model`** | Queries active provider API for available models and displays an interactive selection menu |
244
+ | **`/model gemini-2.5-pro`** | Switches current session to `gemini-2.5-pro` |
245
+ | **`/model anthropic/claude-3.7-sonnet`** | Switches current session to Claude 3.7 Sonnet (on OpenRouter) |
246
+ | **`/model default <model-id>`** | Saves model as persistent default in config and activates it immediately |
247
+
248
+ ### Capability Classification & Discovery
249
+ When listing models via `/model`, Lantern separates models into clear categories:
250
+
251
+ 1. **Interactive Coding Models**: Models that support text chat, streaming, and tool execution (function calling). Examples: `gemini-3.8-flash`, `gpt-4o`, `claude-3-7-sonnet`, `anthropic/claude-3.7-sonnet`.
252
+ 2. **Chat-Only Models**: Models that support streaming conversation, but lack tool/function calling. Lantern warns you that file editing and command execution will be unavailable.
253
+ 3. **Specialized Models**: Non-coding models such as Embeddings (`text-embedding-3-small`), Image Generation (`dall-e-3`), Speech/Audio (`whisper-1`), and Batch-only (`*:batch`). Lantern cleanly rejects attempts to use specialized models for interactive coding and offers compatible models.
151
254
 
152
255
  ---
153
256
 
154
- ## ๐Ÿ“– Command Reference
257
+ ## ๐Ÿ’ป System Shell Commands Reference
258
+
259
+ Use these commands from your operating system shell (`bash`, `zsh`, `cmd`, `PowerShell`):
155
260
 
156
261
  | Command | Action |
157
262
  | :--- | :--- |
158
263
  | **`lantern`** | Launch the interactive conversational REPL |
159
- | **`lantern ask "<question>"`** | One-shot prompt execution with streaming answer |
160
- | **`lantern plan "<task>"`** | Read-only inspection & implementation plan |
264
+ | **`lantern ask "<question>"`** | One-shot prompt execution with streaming response |
265
+ | **`lantern plan "<task>"`** | Read-only inspection and implementation plan |
161
266
  | **`lantern resume [sessionId]`** | Resume the most recent or specified session |
162
- | **`lantern sessions`** | List saved local sessions |
163
- | **`lantern sessions --export <id>`** | Export session transcript to Markdown or JSON |
164
- | **`lantern sessions --delete <id>`** | Delete a saved session by ID |
165
- | **`lantern config`** | View active configuration |
166
- | **`lantern config set <key> <val>`** | Update a configuration setting |
167
- | **`lantern doctor`** | Diagnose environment, credentials, and connectivity |
168
- | **`lantern mcp`** | Manage configured MCP servers (`list`, `add`, `remove`, `test`) |
267
+ | **`lantern sessions`** | List saved local sessions (`--export <id>`, `--delete <id>`) |
268
+ | **`lantern providers`** | Shell management for providers (`list`, `set-default`, `test`, `add`, `remove`) |
269
+ | **`lantern models`** | Shell management for models (`list`, `set`, `-p <provider>`, `-r`, `--json`) |
270
+ | **`lantern keys`** | Manage OS-stored API keys (`list`, `set`, `remove`) |
271
+ | **`lantern skills`** | Manage portable skills (`list`, `show`, `add`, `enable`, `disable`, `remove`) |
272
+ | **`lantern config`** | View or update configuration (`list`, `get`, `set`) |
273
+ | **`lantern doctor`** | Diagnose environment, credentials, latency, and MCP health |
274
+ | **`lantern mcp`** | Manage MCP servers (`list`, `add`, `remove`, `test`, `enable`, `disable`) |
169
275
  | **`lantern --help`** | View all CLI flags and options |
170
- | **`lantern --version`** | Output version string |
171
-
172
- ### Global Options
276
+ | **`lantern --version`** | Output version string (`1.0.2`) |
173
277
 
278
+ ### Global CLI Flags
279
+ - **`-p, --provider <provider>`**: Select provider (`gemini`, `openai`, `anthropic`, `openrouter`, or custom).
174
280
  - **`-m, --model <id>`**: Override model ID (default: `gemini-3.8-flash`).
175
281
  - **`-C, --cwd <path>`**: Set workspace directory for agent operations.
176
282
  - **`-s, --session <id>`**: Use or resume a specific session ID.
177
283
  - **`-a, --attach <files...>`**: Attach text files, images (`.png`, `.jpg`, `.webp`), or PDFs.
178
284
  - **`--yolo`**: Skip interactive confirmation prompts for file edits and shell commands.
179
285
  - **`--json`**: Output results formatted as JSON.
286
+ - **`--timeout <ms>`**: Maximum total request duration (default: `60000`).
287
+ - **`--first-token-timeout <ms>`**: Maximum wait time for initial response token (default: `30000`).
288
+ - **`--timing`**: Display detailed execution and latency timing diagnostics.
289
+ - **`--fast`**: Enable low-latency mode where supported.
290
+ - **`--skill <skills...>`**: Explicitly activate one or more skills for the run.
180
291
 
181
292
  ---
182
293
 
183
- ## ๐Ÿ’ก Usage Examples
184
-
185
- ### 1. Interactive Shell
186
-
187
- ```bash
188
- lantern
189
- ```
190
-
191
- Inside the interactive REPL:
192
- - Type your question or task naturally.
193
- - Use `\` at the end of a line for multiline continuation.
194
- - Enclose multiline code blocks inside `""" ... """`.
195
- - Press `Up`/`Down` arrows to navigate previous prompt history.
196
- - Available slash commands:
197
- - `/help` โ€” List available commands and tools.
198
- - `/clear` โ€” Clear terminal screen.
199
- - `/status` โ€” View workspace, model, token count, and active session ID.
200
- - `/model [id]` โ€” Switch model on the fly (e.g. `/model gemini-3.8-flash`).
201
- - `/plan [on|off]` โ€” Toggle read-only plan mode.
202
- - `/yolo [on|off]` โ€” Toggle YOLO mode for the session.
203
- - `/sessions` โ€” List saved sessions.
204
- - `/history` โ€” Print recent conversation turns.
205
- - `/export [md|json]` โ€” Export current session transcript.
206
- - `/exit` or `/quit` โ€” Save session and exit.
207
-
208
- ### 2. One-Shot Question with File Attachment
209
-
210
- ```bash
211
- lantern ask "Refactor this component to use React hooks" --attach src/components/UserProfile.tsx
212
- ```
294
+ ## ๐Ÿงฉ Portable Skills System (`SKILL.md`)
213
295
 
214
- ### 3. Read-Only Planning Mode
296
+ Code Lantern supports domain-specific skills using the portable `SKILL.md` format (YAML frontmatter + markdown instructions + references):
215
297
 
216
- ```bash
217
- lantern plan "Design an authentication system using JWT tokens with refresh cookies"
298
+ ```markdown
299
+ ---
300
+ name: build-your-own-x
301
+ description: Step-by-step architectural patterns for recreating technologies from scratch
302
+ ---
303
+ # Build Your Own X Instructions
304
+ When designing and implementing systems from scratch, follow these patterns...
218
305
  ```
219
306
 
220
- ### 4. Piped Standard Input
221
-
307
+ ### Managing Skills (From Shell)
222
308
  ```bash
223
- # macOS / Linux
224
- cat build.log | lantern "Summarize the root cause of these compiler errors"
225
-
226
- # Windows PowerShell
227
- Get-Content build.log | lantern "Summarize the root cause of these compiler errors"
228
- ```
309
+ # List installed skills
310
+ lantern skills list
229
311
 
230
- ---
231
-
232
- ## ๐Ÿ›ก๏ธ Approval & YOLO Modes
312
+ # Add a skill from a local directory or markdown file
313
+ lantern skills add ./my-skill-folder
233
314
 
234
- Code Lantern defaults to **Safe Mode**.
315
+ # Add a skill directly from a Git repository
316
+ lantern skills add https://github.com/example/skills-repo.git
235
317
 
236
- ### Safe Mode (Default)
318
+ # Inspect skill instructions and reference documents
319
+ lantern skills show build-your-own-x
237
320
 
238
- 1. **Before Editing Files**: Displays an ANSI color-coded patch diff showing exact removals in red and additions in green:
239
- ```text
240
- Approve this action? [y/N / (a)ll-yolo]:
241
- ```
242
- 2. **Before Creating Files**: Displays a line-numbered preview of the file.
243
- 3. **Before Executing Shell Commands**: Displays the exact command and working directory.
321
+ # Enable or disable skills
322
+ lantern skills enable build-your-own-x
323
+ lantern skills disable build-your-own-x
244
324
 
245
- ### YOLO Mode (`--yolo`)
246
-
247
- Run Lantern with `--yolo` or enter `yolo` / `a` at an approval prompt to auto-approve safe modifications for that execution:
248
- ```bash
249
- lantern --yolo ask "Run npm test and fix failing assertions"
325
+ # Remove a skill
326
+ lantern skills remove build-your-own-x
250
327
  ```
251
328
 
252
- ### Unconditional Safety Invariants
253
-
254
- - **Strict Workspace Containment**: Lantern cannot read, edit, or execute outside your workspace directory. Path traversal attempts (`../../`) and symlink escapes are rejected.
255
- - **Secret Shielding**: `.env`, `.env.*`, `*.pem`, `*.key`, `id_rsa`, and credential JSON files are blocked from reading or being sent to Gemini.
256
- - **Destructive Command Firewall**: Destructive system commands (e.g. `rm -rf /`, `mkfs`, Windows `format c:`, `del /s /q c:\*`) are strictly blocked across all platforms.
257
- - **Token Redaction**: Any API keys detected in text are automatically masked before saving or displaying.
258
-
259
329
  ---
260
330
 
261
- ## ๐Ÿ”Œ Model Context Protocol (MCP)
262
-
263
- Connect external tool servers using the official Model Context Protocol stdio transport:
264
-
265
- ```bash
266
- # Add SQLite database MCP server
267
- lantern mcp add sqlite npx -y @modelcontextprotocol/server-sqlite ./data.db
268
-
269
- # Test server connection and inspect exposed tools
270
- lantern mcp test sqlite
271
-
272
- # List configured MCP servers
273
- lantern mcp list
274
-
275
- # Disable or enable a server
276
- lantern mcp disable sqlite
277
- lantern mcp enable sqlite
331
+ ## ๐Ÿ›ก๏ธ Safe Mode & Invariants
278
332
 
279
- # Remove a server
280
- lantern mcp remove sqlite
281
- ```
333
+ Code Lantern runs in **Safe Mode** by default:
334
+ 1. **Interactive Unified Diffs**: Displays colored unified diffs showing exact deletions in red and additions in green before modifying any file.
335
+ 2. **Command Approvals**: Shows exact command line and working directory before executing shell commands.
336
+ 3. **Workspace Boundary**: Strict containment prevents path traversal (`../../`) or symlink escapes outside the workspace.
337
+ 4. **Secret Firewall**: Blocks reading `.env`, `.env.*`, `*.pem`, `*.key`, `id_rsa`, or credential stores.
338
+ 5. **Key Redaction**: Dynamic and pattern-based redaction ensures API keys are never leaked in error messages, logs, transcripts, or HTTP diagnostics.
339
+ 6. **Destructive Command Guard**: Rejects destructive system commands (e.g., `rm -rf /`, Windows `format c:`, `del /s /q c:\*`).
282
340
 
283
341
  ---
284
342
 
285
- ## โš™๏ธ Configuration & Project Instructions
343
+ ## ๐Ÿฉบ Diagnostics (`lantern doctor`)
286
344
 
287
- Configurations are persisted in `~/.codelantern/config.json` (or `%USERPROFILE%\.codelantern\config.json` on Windows):
345
+ Run `lantern doctor` at any time to verify system health, OS credential storage, network connectivity, latency, and keys:
288
346
 
289
347
  ```bash
290
- # View configuration
291
- lantern config
292
-
293
- # Update settings
294
- lantern config set defaultModel gemini-3.8-flash
295
- lantern config set maxSteps 30
296
- lantern config set temperature 0.2
348
+ lantern doctor
297
349
  ```
298
350
 
299
- ### Project Instructions (`LANTERN.md`)
300
-
301
- Place a `LANTERN.md` (or `GEMINI.md`) file in your project root to provide persistent instructions to Code Lantern:
302
-
303
- ```markdown
304
- # Project Instructions
305
- - Codebase language: TypeScript (NodeNext modules)
306
- - Run `npm test` before concluding file edits
307
- - Keep imports organized alphabetically
351
+ Example output:
352
+ ```text
353
+ ๐Ÿฎ Code Lantern Doctor โ€” Diagnostics
354
+ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
355
+ โœ“ Platform / OS: macOS (Apple Silicon)
356
+ โœ“ Node.js Runtime: v26.12.1 (compatible)
357
+ โœ“ Active Provider: Google Gemini (gemini)
358
+ โœ“ Active Model: gemini-3.8-flash
359
+ โœ“ Credential Storage: macOS Keychain
360
+ โœ“ API Key (gemini): Configured [macOS Keychain] (AIza...W9q0)
361
+ โœ“ Provider Auth & Ping: Verified (295ms latency)
362
+ โœ“ Additional Providers: Configured (openrouter)
363
+ โœ“ Git CLI: Available (git version 2.54.0)
364
+ โœ“ Config File: ~/.codelantern/config.json (Timeout: 60000ms, TTFT: 30000ms)
365
+ โœ“ Session Storage: ~/.codelantern/sessions (2 stored session(s))
366
+ โœ“ Skills: Cleanly loaded
367
+ โœ“ Project Instructions: Found (LANTERN.md)
368
+ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
369
+ โœจ All systems healthy! Code Lantern CLI is ready to assist.
308
370
  ```
309
371
 
310
372
  ---
311
373
 
312
- ## ๐Ÿš€ npm Release Checklist
374
+ ## ๐Ÿ”ง Troubleshooting Google Gemini Connectivity
313
375
 
314
- To publish `codelantern-agent-cli` to npm:
376
+ If you ever encounter connection difficulties, follow these steps:
315
377
 
316
- 1. **Ensure Tests Pass**:
378
+ 1. **Verify Configured API Key**:
379
+ Run `lantern keys list` to ensure `gemini` is configured via your native OS credential store or environment:
317
380
  ```bash
318
- npm test
319
- npm run lint
320
- npm run build
381
+ lantern keys list
321
382
  ```
322
- 2. **Verify Pack Contents**:
383
+ If unconfigured, store your key once:
323
384
  ```bash
324
- npm pack --dry-run
385
+ lantern keys set gemini
325
386
  ```
326
- *Verify that only `dist/`, `README.md`, and `LICENSE` are included. Ensure no `.env`, `.codelantern/`, or test files are listed.*
327
- 3. **Log in to npm**:
387
+ 2. **Test Provider Connection**:
388
+ Test direct connectivity, authorization, and token latency:
328
389
  ```bash
329
- npm login
390
+ lantern keys test gemini
391
+ # or:
392
+ lantern providers test gemini
330
393
  ```
331
- 4. **Publish**:
394
+ 3. **Switch Model if Needed**:
395
+ If a particular model is unavailable or restricted on your account:
396
+ - Inside interactive session: type `/model` to browse models, or `/model gemini-2.5-flash` to switch immediately.
397
+ - From shell: `lantern models set gemini-2.5-flash`
398
+ 4. **Adjust Timeout Limits**:
399
+ If your network has high latency or is behind a strict proxy, increase the timeout limits:
332
400
  ```bash
333
- npm publish --access public
401
+ lantern config set timeoutMs 120000
402
+ lantern config set firstTokenTimeoutMs 45000
334
403
  ```
404
+ 5. **Instant Cancellation**:
405
+ Pressing **Ctrl+C** at any time during credential resolution, connection setup, first-token waiting, streaming, or tool execution immediately stops the request and cleanly returns to your prompt.
335
406
 
336
407
  ---
337
408
 
338
- ## ๐Ÿงช Testing
409
+ ## ๐Ÿงช Automated Testing
339
410
 
340
- Run the automated cross-platform test suite:
411
+ Code Lantern includes a comprehensive test suite covering security sandboxing, CRLF line endings, tool execution, session persistence, timeout handling, first-token limits, cancellation, OS credential storage, automatic key reuse, provider isolation, env var overrides, crash-safe migration, secret redaction, in-session switching, slash commands, and the Gemini request lifecycle:
341
412
 
342
413
  ```bash
414
+ # Run test suite (61 automated checks)
343
415
  npm test
344
- ```
345
-
346
- Run TypeScript compilation check:
347
416
 
348
- ```bash
417
+ # Run TypeScript type check
349
418
  npm run lint
419
+
420
+ # Build production bundle
421
+ npm run build
350
422
  ```
351
423
 
352
424
  ---
353
425
 
354
- ## โš ๏ธ Known Limitations & Platform Notes
426
+ ## โš ๏ธ Platform Verification Notes
355
427
 
356
- - **Directly Tested Platform**: Built and fully tested on **macOS (Apple Silicon arm64, Node v26)** with all 23 automated unit and integration tests passing.
357
- - **Windows Platform**: Designed with standard Node.js APIs (`path.normalize`, `path.sep`, `windowsHide`, CRLF normalization, command guard patterns). Physical hardware testing on Windows 10/11 is recommended upon clone or CI run.
358
- - **Terminal Colors**: A modern terminal emulator with ANSI color support (macOS Terminal, iTerm2, Windows Terminal, VS Code Integrated Terminal) is recommended.
428
+ - **macOS (Directly Verified)**: Developed, built, and verified on macOS (Apple Silicon arm64, Node v26) with all 61 automated tests passing, native macOS Keychain integration verified, and live provider connectivity verified.
429
+ - **Windows (Architecturally Supported)**: Built with portable Node.js APIs (`path.normalize`, `path.sep`, `windowsHide: true`, CRLF handling, Windows Credential Manager integration, and Windows command guards). Direct testing on native Windows hardware was not performed in this session; Windows verification relies on the automated Windows CI workflow (`.github/workflows/ci.yml`).
359
430
 
360
431
  ---
361
432