codelantern-agent-cli 1.0.1 โ†’ 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,37 +1,59 @@
1
1
  # ๐Ÿฎ Code Lantern CLI (`codelantern-agent-cli`)
2
2
 
3
- > **Personal AI coding assistant for the terminal with multi-provider intelligence, portable skills, and ironclad safety.**
3
+ > **Personal AI coding assistant for the terminal with native OS credential storage, automatic key reuse, multi-provider intelligence, and ironclad safety.**
4
4
  > Terminal command: **`lantern`**
5
- > Published version: **`1.0.1`**
6
- > Default model: **`gemini-3.8-flash`** (Google Gemini)
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`)
7
8
 
8
- 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, OpenAI, Anthropic Claude, OpenRouter, or custom OpenAI-compatible endpointsโ€”with zero third-party agent dependencies.
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.
9
10
 
10
11
  ---
11
12
 
12
- ## โšก What's New in v1.0.1
13
-
14
- - ๐Ÿš€ **Fix "Step 1: thinking" Hang & Slowness**:
15
- - **Bounded Request & First-Token Timeouts (`TTFT`)**: Strict timeouts prevent indefinite network hangs with configurable `--timeout` (default: 60s) and `--first-token-timeout` (default: 30s).
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.
16
53
  - **Immediate Unbuffered Streaming**: Response tokens stream directly to stdout as they arrive.
17
- - **Real-Time Spinner Stages**: Spinner transitions transparently across `Connecting...`, `Waiting for first token...`, `Receiving response...`, and `Executing tool [name]...`. Stale thinking states are completely eliminated.
18
- - **Instant Cancellation (Ctrl+C)**: Pressing Ctrl+C aborts in-flight fetch and streaming requests instantly via linked `AbortController`, safely returning control to the prompt.
19
- - **Safe Backoff Retries**: Transient HTTP failures (429/503) retry with small, capped backoff. Non-idempotent mutating tools (file edits, bash execution) are never duplicated.
20
- - **Context Efficiency & Pruning**: Tool outputs exceeding 15KB are capped in session context, preventing memory bloat and preserving fast response times.
21
- - **Timing Diagnostics**: Pass `--timing` or use `/timing` to display live latency benchmarks for connection, first-token arrival, tool steps, and total turn duration.
22
- - ๐ŸŒ **Multi-Provider & Dynamic Model Architecture**:
23
- - **Google Gemini**: Native official `@google/genai` SDK with `gemini-3.8-flash` as default.
24
- - **OpenAI**: Native SSE streaming adapter supporting `gpt-4o`, `gpt-4o-mini`, `o1`, `o3-mini`, with function/tool calling.
25
- - **Anthropic Claude**: Native SSE streaming adapter supporting `claude-3-7-sonnet`, `claude-3-5-sonnet`, and `claude-3-5-haiku`.
26
- - **OpenRouter**: Access over 400 models dynamically via `https://openrouter.ai/api/v1` with dynamic catalog discovery.
27
- - **Custom OpenAI-Compatible Providers**: Configure custom endpoints (Ollama, vLLM, DeepSeek, LocalAI) via base URL, API key, and model ID.
28
- - **Secure AES-256-GCM Credential Vault**: Store provider API keys locally encrypted in `~/.codelantern/credentials.json` with machine-derived keys, or supply via standard environment variables (`GEMINI_API_KEY`, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `OPENROUTER_API_KEY`).
29
- - **Management Commands**: `lantern providers`, `lantern models`, `lantern keys`, and `/provider`, `/model` slash commands.
30
- - ๐Ÿงฉ **Portable Skills System (`SKILL.md`)**:
31
- - Import, enable, and use skills defined in portable `SKILL.md` format (YAML frontmatter + markdown instructions + references).
32
- - Discovered automatically from user directory (`~/.codelantern/skills/`) and project workspaces (`.codelantern/skills/`).
33
- - Install skills easily via local path or Git: `lantern skills add <path-or-git-url>`.
34
- - Transparent, non-intrusive keyword/intent matching automatically injects relevant domain instructions into system prompts without arbitrary script execution.
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.
35
57
 
36
58
  ---
37
59
 
@@ -42,115 +64,236 @@ Code Lantern CLI is a resilient, autonomous terminal coding assistant designed t
42
64
  | **Node.js** | `>= 18.0.0` (Node 20 or Node 22 LTS recommended) |
43
65
  | **npm** | `>= 9.0.0` |
44
66
  | **Operating Systems** | macOS 12+ (Apple Silicon `arm64` & Intel `x64`), Windows 10/11 (PowerShell & CMD), Linux |
45
- | **API Keys** | Any of: `GEMINI_API_KEY`, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `OPENROUTER_API_KEY`, or custom endpoint |
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 |
46
69
 
47
70
  ---
48
71
 
49
- ## ๐Ÿ“ฆ Installation
72
+ ## ๐Ÿ“ฆ Installation & Startup
50
73
 
51
- ### 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`**:
52
76
 
77
+ #### macOS & Linux:
78
+ ```bash
79
+ npm install -g codelantern-agent-cli
80
+ lantern --version
81
+ # Output: 1.0.1
82
+ ```
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)
53
93
  ```bash
54
94
  cd "my own cli"
55
95
 
56
96
  # 1. Install dependencies
57
97
  npm install
58
98
 
59
- # 2. Build the distribution bundle
99
+ # 2. Build production bundle
60
100
  npm run build
61
101
 
62
- # 3. Link globally for immediate use
102
+ # 3. Link globally for local testing
63
103
  npm link
64
- ```
65
104
 
66
- Verify your installation:
67
- ```bash
68
105
  lantern --version
69
- # Output: 1.0.1
106
+ # Output: 1.0.2
70
107
  ```
71
108
 
72
- ### Option B: Global Installation from npm
73
-
74
- Once published under `codelantern-agent-cli`:
75
-
76
- #### macOS & Linux:
109
+ ### Starting Code Lantern
110
+ Start interactive mode:
77
111
  ```bash
78
- npm install -g codelantern-agent-cli
79
- lantern --version
112
+ lantern
80
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
81
119
 
82
- #### Windows (PowerShell or Command Prompt):
83
- ```powershell
84
- npm install -g codelantern-agent-cli
85
- lantern --version
120
+ lantern (gemini) โฏ
86
121
  ```
87
- *npm automatically generates `lantern.cmd` and `lantern.ps1` executables on Windows.*
88
122
 
89
123
  ---
90
124
 
91
- ## ๐Ÿ”‘ Credential & Key Management
125
+ ## ๐Ÿ”‘ Secure API Key Storage & Automatic Reuse
92
126
 
93
- Code Lantern supports two secure methods for supplying API keys:
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.
94
128
 
95
- ### 1. Secure Local Vault (AES-256-GCM)
96
- Store encrypted keys on your local machine using `lantern keys set`:
129
+ ### One-Time Key Setup (Shell)
130
+
131
+ Run `lantern keys set <provider>`:
97
132
  ```bash
133
+ # Set Google Gemini API key
98
134
  lantern keys set gemini
135
+
136
+ # Set OpenRouter API key
137
+ lantern keys set openrouter
138
+
139
+ # Set OpenAI or Anthropic keys
99
140
  lantern keys set openai
100
141
  lantern keys set anthropic
101
- lantern keys set openrouter
102
142
  ```
103
- Keys are encrypted using AES-256-GCM with a machine-unique key derived from your host identity. Keys are never logged, committed, or transmitted except directly to the provider endpoint.
104
143
 
105
- ### 2. Environment Variables
106
- Standard environment variables take precedence when present:
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.
150
+ ```
151
+
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!
163
+
164
+ ### Viewing Configured Keys Safely
165
+ Inspect configured providers and their storage source without exposing secrets:
166
+ ```bash
167
+ lantern keys list
168
+ ```
169
+
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)
182
+ ```
183
+
184
+ ### Environment Variable Overrides
185
+ Environment variables take explicit precedence over stored credentials when present:
186
+
187
+ #### macOS / Linux (`zsh` or `bash`):
107
188
  ```bash
108
- export GEMINI_API_KEY="AIzaSy..."
189
+ export GEMINI_API_KEY="AIzaSyYourGeminiApiKeyHere"
190
+ export OPENROUTER_API_KEY="sk-or-v1-YourOpenRouterKeyHere"
109
191
  export OPENAI_API_KEY="sk-proj-..."
110
192
  export ANTHROPIC_API_KEY="sk-ant-..."
111
- export OPENROUTER_API_KEY="sk-or-v1-..."
112
193
  ```
113
194
 
114
- Inspect configured keys safely (masked):
115
- ```bash
116
- lantern keys list
195
+ #### Windows (PowerShell):
196
+ ```powershell
197
+ $env:GEMINI_API_KEY="AIzaSyYourGeminiApiKeyHere"
198
+ $env:OPENROUTER_API_KEY="sk-or-v1-YourOpenRouterKeyHere"
117
199
  ```
118
200
 
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.
217
+
119
218
  ---
120
219
 
121
- ## ๐ŸŒ Multi-Provider Management
220
+ ## ๐Ÿ”„ In-Session Provider & Model Switching
122
221
 
123
- ### Switch Active Provider and Models
124
- ```bash
125
- # List all configured providers
126
- lantern providers list
222
+ Code Lantern allows you to switch providers and models **from inside the running CLI** without exiting to your shell.
127
223
 
128
- # Set default provider
129
- lantern providers set-default openrouter
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`).
130
227
 
131
- # Test provider connectivity and latency
132
- lantern providers test openrouter
133
- lantern providers test gemini
228
+ ### In-Session Provider Commands (Inside Lantern)
134
229
 
135
- # Add a custom local Ollama or vLLM provider
136
- lantern providers add ollama --base-url http://localhost:11434/v1 --model llama3.2:latest
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 |
137
238
 
138
- # List available models for active provider
139
- lantern models list
239
+ ### In-Session Model Commands (Inside Lantern)
140
240
 
141
- # Query models for a specific provider
142
- lantern models list -p anthropic
143
- lantern models list -p openrouter
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 |
144
247
 
145
- # Set active default model
146
- lantern models set gemini-3.8-flash
147
- ```
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.
254
+
255
+ ---
256
+
257
+ ## ๐Ÿ’ป System Shell Commands Reference
258
+
259
+ Use these commands from your operating system shell (`bash`, `zsh`, `cmd`, `PowerShell`):
260
+
261
+ | Command | Action |
262
+ | :--- | :--- |
263
+ | **`lantern`** | Launch the interactive conversational REPL |
264
+ | **`lantern ask "<question>"`** | One-shot prompt execution with streaming response |
265
+ | **`lantern plan "<task>"`** | Read-only inspection and implementation plan |
266
+ | **`lantern resume [sessionId]`** | Resume the most recent or specified session |
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`) |
275
+ | **`lantern --help`** | View all CLI flags and options |
276
+ | **`lantern --version`** | Output version string (`1.0.2`) |
277
+
278
+ ### Global CLI Flags
279
+ - **`-p, --provider <provider>`**: Select provider (`gemini`, `openai`, `anthropic`, `openrouter`, or custom).
280
+ - **`-m, --model <id>`**: Override model ID (default: `gemini-3.8-flash`).
281
+ - **`-C, --cwd <path>`**: Set workspace directory for agent operations.
282
+ - **`-s, --session <id>`**: Use or resume a specific session ID.
283
+ - **`-a, --attach <files...>`**: Attach text files, images (`.png`, `.jpg`, `.webp`), or PDFs.
284
+ - **`--yolo`**: Skip interactive confirmation prompts for file edits and shell commands.
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.
148
291
 
149
292
  ---
150
293
 
151
294
  ## ๐Ÿงฉ Portable Skills System (`SKILL.md`)
152
295
 
153
- Code Lantern supports domain-specific skills using the standard `SKILL.md` format:
296
+ Code Lantern supports domain-specific skills using the portable `SKILL.md` format (YAML frontmatter + markdown instructions + references):
154
297
 
155
298
  ```markdown
156
299
  ---
@@ -161,16 +304,16 @@ description: Step-by-step architectural patterns for recreating technologies fro
161
304
  When designing and implementing systems from scratch, follow these patterns...
162
305
  ```
163
306
 
164
- ### Managing Skills
307
+ ### Managing Skills (From Shell)
165
308
  ```bash
166
309
  # List installed skills
167
310
  lantern skills list
168
311
 
169
- # Add a skill from a local folder or markdown file
170
- lantern skills add ./my-skill
312
+ # Add a skill from a local directory or markdown file
313
+ lantern skills add ./my-skill-folder
171
314
 
172
315
  # Add a skill directly from a Git repository
173
- lantern skills add https://github.com/example/coding-skills.git
316
+ lantern skills add https://github.com/example/skills-repo.git
174
317
 
175
318
  # Inspect skill instructions and reference documents
176
319
  lantern skills show build-your-own-x
@@ -185,9 +328,21 @@ lantern skills remove build-your-own-x
185
328
 
186
329
  ---
187
330
 
331
+ ## ๐Ÿ›ก๏ธ Safe Mode & Invariants
332
+
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:\*`).
340
+
341
+ ---
342
+
188
343
  ## ๐Ÿฉบ Diagnostics (`lantern doctor`)
189
344
 
190
- Run `lantern doctor` at any time to verify system health, network connectivity, latency, and keys:
345
+ Run `lantern doctor` at any time to verify system health, OS credential storage, network connectivity, latency, and keys:
191
346
 
192
347
  ```bash
193
348
  lantern doctor
@@ -201,77 +356,65 @@ Example output:
201
356
  โœ“ Node.js Runtime: v26.12.1 (compatible)
202
357
  โœ“ Active Provider: Google Gemini (gemini)
203
358
  โœ“ Active Model: gemini-3.8-flash
204
- โœ“ API Key (gemini): Configured [env] (AIza...W9q0)
205
- โœ“ Gemini API Auth: Verified (latency: 340ms)
206
- โœ“ Additional Providers: Configured (openrouter, openai)
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)
207
363
  โœ“ Git CLI: Available (git version 2.54.0)
208
364
  โœ“ Config File: ~/.codelantern/config.json (Timeout: 60000ms, TTFT: 30000ms)
209
- โœ“ Session Storage: ~/.codelantern/sessions (1 stored session(s))
210
- โœ“ Skills: 1 installed (build-your-own-x)
211
- โ„น MCP Servers: No external MCP servers configured (optional)
212
- โœ“ Project Instructions: Found (LANTERN.md) in /workspace
365
+ โœ“ Session Storage: ~/.codelantern/sessions (2 stored session(s))
366
+ โœ“ Skills: Cleanly loaded
367
+ โœ“ Project Instructions: Found (LANTERN.md)
213
368
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
214
369
  โœจ All systems healthy! Code Lantern CLI is ready to assist.
215
370
  ```
216
371
 
217
372
  ---
218
373
 
219
- ## ๐Ÿ“– Command Reference
220
-
221
- | Command | Action |
222
- | :--- | :--- |
223
- | **`lantern`** | Launch the interactive conversational REPL |
224
- | **`lantern ask "<question>"`** | One-shot prompt execution with streaming response |
225
- | **`lantern plan "<task>"`** | Read-only inspection and implementation plan |
226
- | **`lantern resume [sessionId]`** | Resume the most recent or specified session |
227
- | **`lantern sessions`** | List saved local sessions (`--export <id>`, `--delete <id>`) |
228
- | **`lantern providers`** | Manage AI providers (`list`, `set-default`, `test`, `add`, `remove`) |
229
- | **`lantern models`** | List and select models (`list`, `set`, `-p <provider>`, `-r`, `--json`) |
230
- | **`lantern keys`** | Manage encrypted API keys (`list`, `set`, `remove`) |
231
- | **`lantern skills`** | Manage portable skills (`list`, `show`, `add`, `enable`, `disable`, `remove`) |
232
- | **`lantern config`** | View or update configuration (`list`, `get`, `set`) |
233
- | **`lantern doctor`** | Diagnose environment, credentials, latency, and MCP health |
234
- | **`lantern mcp`** | Manage MCP servers (`list`, `add`, `remove`, `test`, `enable`, `disable`) |
235
- | **`lantern --help`** | View all CLI flags and options |
236
- | **`lantern --version`** | Output version string (`1.0.1`) |
237
-
238
- ### Global Flags
239
-
240
- - **`-p, --provider <provider>`**: Select provider (`gemini`, `openai`, `anthropic`, `openrouter`, or custom).
241
- - **`-m, --model <id>`**: Override model ID (default: `gemini-3.8-flash`).
242
- - **`-C, --cwd <path>`**: Set workspace directory for agent operations.
243
- - **`-s, --session <id>`**: Use or resume a specific session ID.
244
- - **`-a, --attach <files...>`**: Attach text files, images (`.png`, `.jpg`, `.webp`), or PDFs.
245
- - **`--yolo`**: Skip interactive confirmation prompts for file edits and shell commands.
246
- - **`--json`**: Output results formatted as JSON.
247
- - **`--timeout <ms>`**: Maximum total request duration (default: `60000`).
248
- - **`--first-token-timeout <ms>`**: Maximum wait time for initial response token (default: `30000`).
249
- - **`--timing`**: Display detailed execution and latency timing diagnostics.
250
- - **`--fast`**: Enable low-latency mode where supported.
251
- - **`--skill <skills...>`**: Explicitly activate one or more skills for the run.
374
+ ## ๐Ÿ”ง Troubleshooting Google Gemini Connectivity
252
375
 
253
- ---
254
-
255
- ## ๐Ÿ›ก๏ธ Safe Mode & Invariants
376
+ If you ever encounter connection difficulties, follow these steps:
256
377
 
257
- Code Lantern runs in **Safe Mode** by default:
258
- 1. **Interactive Unified Diffs**: Displays colored unified diffs showing exact deletions in red and additions in green before touching any file.
259
- 2. **Command Approvals**: Shows command line and working directory before running shell commands.
260
- 3. **Workspace Boundary**: Strict containment prevents path traversal (`../../`) or symlink escapes outside the workspace.
261
- 4. **Secret Firewall**: Blocks reading `.env`, `.env.*`, `*.pem`, `*.key`, `id_rsa`, or credential stores.
262
- 5. **Destructive Command Guard**: Rejects destructive system commands (e.g., `rm -rf /`, Windows `format c:`, `del /s /q c:\*`).
378
+ 1. **Verify Configured API Key**:
379
+ Run `lantern keys list` to ensure `gemini` is configured via your native OS credential store or environment:
380
+ ```bash
381
+ lantern keys list
382
+ ```
383
+ If unconfigured, store your key once:
384
+ ```bash
385
+ lantern keys set gemini
386
+ ```
387
+ 2. **Test Provider Connection**:
388
+ Test direct connectivity, authorization, and token latency:
389
+ ```bash
390
+ lantern keys test gemini
391
+ # or:
392
+ lantern providers test gemini
393
+ ```
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:
400
+ ```bash
401
+ lantern config set timeoutMs 120000
402
+ lantern config set firstTokenTimeoutMs 45000
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.
263
406
 
264
407
  ---
265
408
 
266
409
  ## ๐Ÿงช Automated Testing
267
410
 
268
- Code Lantern includes a comprehensive test suite covering security sandboxing, CRLF line endings, tool execution, session persistence, timeout handling, first-token limits, cancellation, AES-256 encryption, skills parsing, and provider registries:
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:
269
412
 
270
413
  ```bash
271
- # Run test suite (32 automated checks)
414
+ # Run test suite (61 automated checks)
272
415
  npm test
273
416
 
274
- # Run TypeScript typecheck
417
+ # Run TypeScript type check
275
418
  npm run lint
276
419
 
277
420
  # Build production bundle
@@ -280,33 +423,10 @@ npm run build
280
423
 
281
424
  ---
282
425
 
283
- ## ๐Ÿš€ npm Publishing Guide (v1.0.1)
284
-
285
- To publish `codelantern-agent-cli@1.0.1` to npm:
286
-
287
- 1. **Verify All Checks Pass**:
288
- ```bash
289
- npm test
290
- npm run lint
291
- npm run build
292
- ```
293
- 2. **Inspect Tarball Contents**:
294
- ```bash
295
- npm pack --dry-run
296
- ```
297
- *Verify that only `dist/`, `README.md`, and `LICENSE` are included.*
298
- 3. **Authenticate & Publish**:
299
- ```bash
300
- npm login
301
- npm publish --access public
302
- ```
303
-
304
- ---
305
-
306
426
  ## โš ๏ธ Platform Verification Notes
307
427
 
308
- - **macOS (Directly Verified)**: Developed, built, and verified on macOS (Apple Silicon arm64, Node v26) with all 32 automated tests passing and live provider connectivity verified.
309
- - **Windows (Architecturally Supported)**: Built with portable Node.js APIs (`path.normalize`, `path.sep`, `windowsHide: true`, CRLF handling, and Windows command guards). Direct testing on native Windows hardware or Windows CI is recommended upon deployment.
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`).
310
430
 
311
431
  ---
312
432