nex-code 0.3.0

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 ADDED
@@ -0,0 +1,687 @@
1
+ ```
2
+ ███╗ ██╗███████╗██╗ ██╗ ━ ██████╗ ██████╗ ██████╗ ███████╗
3
+ ████╗ ██║██╔════╝╚██╗██╔╝ ━ ██╔════╝██╔═══██╗██╔══██╗██╔════╝
4
+ ██╔██╗ ██║█████╗ ╚███╔╝ ━ ██║ ██║ ██║██║ ██║█████╗
5
+ ██║╚██╗██║██╔══╝ ██╔██╗ ━ ██║ ██║ ██║██║ ██║██╔══╝
6
+ ██║ ╚████║███████╗██╔╝ ██╗ ━ ╚██████╗╚██████╔╝██████╔╝███████╗
7
+ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ━ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
8
+ ```
9
+
10
+ <p align="center">
11
+ <b>Agentic coding CLI — like Claude Code, but open-source and multi-provider.</b><br>
12
+ Use OpenAI, Anthropic, Google Gemini, Ollama Cloud, or local models. Your choice.
13
+ </p>
14
+
15
+ <p align="center">
16
+ <a href="https://github.com/hybridpicker/nex-code/actions/workflows/ci.yml"><img src="https://github.com/hybridpicker/nex-code/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
17
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT"></a>
18
+ <img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg" alt="Node >= 18">
19
+ <img src="https://img.shields.io/badge/dependencies-2-green.svg" alt="Dependencies: 2">
20
+ <img src="https://img.shields.io/badge/tests-1780-blue.svg" alt="Tests: 1780">
21
+ </p>
22
+
23
+ ---
24
+
25
+ ## Quickstart
26
+
27
+ ```bash
28
+ git clone https://github.com/hybridpicker/nex-code.git
29
+ cd nex-code && npm install
30
+ cp .env.example .env # add at least one API key
31
+ npm start # or: npm link && nex-code
32
+ ```
33
+
34
+ That's it. You'll see the banner, your project context, and the `>` prompt. Start typing.
35
+
36
+ ---
37
+
38
+ ## Why nex-code?
39
+
40
+ | | nex-code | Claude Code | aider | Cursor |
41
+ |---|---|---|---|---|
42
+ | **Open-source** | MIT | Proprietary | Apache 2.0 | Proprietary |
43
+ | **Multi-provider** | 5 providers, swap at runtime | Anthropic only | Multi-provider | Multi-provider |
44
+ | **Free local models** | Ollama (no API key) | — | Ollama | — |
45
+ | **Runtime dependencies** | 2 (axios, dotenv) | Heavy | Heavy | Electron |
46
+ | **Test coverage** | 1780 tests, 90% coverage | — | — | — |
47
+ | **Tool tiers** | Auto-adapts tools per model | Fixed | Fixed | Fixed |
48
+ | **No lock-in** | `/model openai:gpt-4o` ↔ `/model local:llama3` | Anthropic only | Config change | Config change |
49
+
50
+ ---
51
+
52
+ ## Setup
53
+
54
+ ### Prerequisites
55
+ - Node.js 18+
56
+ - At least one API key **or** a local [Ollama](https://ollama.com/download) server
57
+
58
+ ### Installation
59
+
60
+ ```bash
61
+ git clone git@github.com:hybridpicker/nex-code.git
62
+ cd nex-code
63
+ npm install
64
+ cp .env.example .env
65
+ npm link
66
+ npm run install-hooks
67
+ ```
68
+
69
+ ### Configure a Provider
70
+
71
+ Add one or more API keys to `.env`:
72
+
73
+ ```bash
74
+ # Pick any — only one is required
75
+ OLLAMA_API_KEY=your-key # Ollama Cloud (Qwen3 Coder, DeepSeek R1, Devstral, Kimi K2.5, Llama 4, MiniMax M2.5, GLM 4.7)
76
+ OPENAI_API_KEY=your-key # OpenAI (GPT-4o, GPT-4.1, o1, o3, o4-mini)
77
+ ANTHROPIC_API_KEY=your-key # Anthropic (Claude Sonnet 4.6, Opus 4.6, Haiku 4.5)
78
+ GEMINI_API_KEY=your-key # Google Gemini (3.1 Pro Preview, 2.5 Pro/Flash, 2.0 Flash)
79
+ # No key needed for local Ollama — just have it running
80
+ ```
81
+
82
+ ### Verify
83
+
84
+ ```bash
85
+ cd ~/any-project
86
+ nex-code
87
+ ```
88
+
89
+ You should see the banner, your project context, and the `>` prompt.
90
+
91
+ ---
92
+
93
+ ## Usage
94
+
95
+ ```
96
+ > explain the main function in index.js
97
+ > add input validation to the createUser handler
98
+ > run the tests and fix any failures
99
+ > refactor this to use async/await instead of callbacks
100
+ ```
101
+
102
+ ### Try These Scenarios
103
+
104
+ **Understand an unfamiliar codebase:**
105
+ ```
106
+ > give me an overview of this project — architecture, key files, tech stack
107
+ > how does authentication work here? trace the flow from login to session
108
+ > find all API endpoints and list them with their HTTP methods
109
+ ```
110
+
111
+ **Fix bugs with context:**
112
+ ```
113
+ > the /users endpoint returns 500 — find the bug and fix it
114
+ > tests are failing in auth.test.js — figure out why and fix it
115
+ > there's a memory leak somewhere — profile the app and find it
116
+ ```
117
+
118
+ **Add features end-to-end:**
119
+ ```
120
+ > add rate limiting to all API routes (100 req/min per IP)
121
+ > add a /health endpoint that checks DB connectivity
122
+ > implement pagination for the GET /products endpoint
123
+ ```
124
+
125
+ **Refactor and improve:**
126
+ ```
127
+ > refactor the database queries to use a connection pool
128
+ > this function is 200 lines — break it into smaller functions
129
+ > migrate these callbacks to async/await
130
+ ```
131
+
132
+ **DevOps and CI:**
133
+ ```
134
+ > write a Dockerfile for this project
135
+ > set up GitHub Actions CI that runs tests on push
136
+ > add a pre-commit hook that runs linting
137
+ ```
138
+
139
+ **Multi-step autonomous work (YOLO mode):**
140
+ ```bash
141
+ nex-code -yolo
142
+ ```
143
+ ```
144
+ > read the entire src/ directory, run the tests, fix all failures, then commit
145
+ > add input validation to every POST endpoint, add tests, run them
146
+ > upgrade all dependencies to latest, fix any breaking changes, run tests
147
+ ```
148
+
149
+ The agent decides autonomously whether to use tools or just respond with text. Simple questions get direct answers. Coding tasks trigger the agentic tool loop.
150
+
151
+ ### YOLO Mode
152
+
153
+ Skip all confirmation prompts — file changes, dangerous commands, and tool permissions are auto-approved. The banner shows a `⚡ YOLO` indicator. Toggle at runtime with `/autoconfirm`.
154
+
155
+ ---
156
+
157
+ ## Providers & Models
158
+
159
+ Switch providers and models at runtime:
160
+
161
+ ```
162
+ /model # interactive model picker (arrow keys + Enter)
163
+ /model openai:gpt-4o # switch directly
164
+ /model anthropic:claude-sonnet
165
+ /model gemini:gemini-2.5-pro
166
+ /model local:llama3
167
+ /providers # see all available providers & models
168
+ ```
169
+
170
+ | Provider | Models | Env Variable |
171
+ |----------|--------|-------------|
172
+ | **ollama** | Qwen3 Coder, DeepSeek R1, Devstral, Kimi K2.5, MiniMax M2.5, GLM 4.7, Llama 4 | `OLLAMA_API_KEY` |
173
+ | **openai** | GPT-4o, GPT-4.1, o1, o3, o4-mini | `OPENAI_API_KEY` |
174
+ | **anthropic** | Claude Sonnet 4.6, Opus 4.6, Haiku 4.5, Sonnet 4.5, Sonnet 4 | `ANTHROPIC_API_KEY` |
175
+ | **gemini** | Gemini 3.1 Pro Preview, 2.5 Pro/Flash/Lite, 2.0 Flash/Lite | `GEMINI_API_KEY` |
176
+ | **local** | Any model on your local Ollama server | (none) |
177
+
178
+ Fallback chains let you auto-switch when a provider fails:
179
+ ```
180
+ /fallback anthropic,openai,local
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Commands
186
+
187
+ Type `/` to see inline suggestions as you type. Tab completion is supported for slash commands and file paths (type a path containing `/` and press Tab).
188
+
189
+ | Command | Description |
190
+ |---------|-------------|
191
+ | `/help` | Full help |
192
+ | `/model [spec]` | Show/switch model (e.g. `openai:gpt-4o`) |
193
+ | `/providers` | List all providers and models |
194
+ | `/fallback [chain]` | Show/set fallback chain |
195
+ | `/tokens` | Token usage and context budget |
196
+ | `/costs` | Session token costs |
197
+ | `/budget` | Show/set per-provider cost limits |
198
+ | `/clear` | Clear conversation |
199
+ | `/context` | Show project context |
200
+ | `/autoconfirm` | Toggle auto-confirm for file changes |
201
+ | `/save [name]` | Save current session |
202
+ | `/load <name>` | Load a saved session |
203
+ | `/sessions` | List saved sessions |
204
+ | `/resume` | Resume last session |
205
+ | `/remember <text>` | Save a memory (persists across sessions) |
206
+ | `/forget <key>` | Delete a memory |
207
+ | `/memory` | Show all memories |
208
+ | `/permissions` | Show tool permissions |
209
+ | `/allow <tool>` | Auto-allow a tool |
210
+ | `/deny <tool>` | Block a tool |
211
+ | `/plan [task]` | Plan mode (analyze before executing) |
212
+ | `/plans` | List saved plans |
213
+ | `/auto [level]` | Set autonomy: interactive/semi-auto/autonomous |
214
+ | `/commit [msg]` | Smart commit (analyze diff, suggest message) |
215
+ | `/diff` | Show current diff |
216
+ | `/branch [name]` | Create feature branch |
217
+ | `/mcp` | MCP servers and tools |
218
+ | `/hooks` | Show configured hooks |
219
+ | `/skills` | List, enable, disable skills |
220
+ | `/undo` | Undo last file change |
221
+ | `/redo` | Redo last undone change |
222
+ | `/history` | Show file change history |
223
+ | `/exit` | Quit |
224
+
225
+ ---
226
+
227
+ ## Tools
228
+
229
+ The agent has 17 built-in tools:
230
+
231
+ | Tool | Description |
232
+ |------|-------------|
233
+ | `bash` | Execute shell commands (90s timeout, 5MB buffer) |
234
+ | `read_file` | Read files with optional line range (binary detection) |
235
+ | `write_file` | Create or overwrite files (with diff preview + confirmation) |
236
+ | `edit_file` | Targeted text replacement (with diff preview + confirmation) |
237
+ | `patch_file` | Atomic multi-replacement in a single operation |
238
+ | `list_directory` | Tree view with depth control and glob filtering |
239
+ | `search_files` | Regex search across files (like grep) |
240
+ | `glob` | Fast file search by name/extension pattern |
241
+ | `grep` | Content search with regex and line numbers |
242
+ | `git_status` | Git working tree status |
243
+ | `git_diff` | Git diff with optional path filter |
244
+ | `git_log` | Git commit history with configurable count |
245
+ | `web_fetch` | Fetch content from a URL |
246
+ | `web_search` | Search the web via DuckDuckGo |
247
+ | `ask_user` | Ask the user a question and wait for input |
248
+ | `task_list` | Create and manage task lists for multi-step operations |
249
+ | `spawn_agents` | Run parallel sub-agents with auto model routing |
250
+
251
+ Additional tools can be added via [MCP servers](#mcp) or [Skills](#skills).
252
+
253
+ ---
254
+
255
+ ## Features
256
+
257
+ ### Compact Output
258
+ The agent loop uses a single spinner during tool execution, then prints compact 1-line summaries:
259
+ ```
260
+ ⠋ ▸ 3 tools: read_file, grep, edit_file
261
+ ✓ read_file src/app.js (45 lines)
262
+ ✓ grep TODO → 12 matches
263
+ ✗ edit_file src/x.js → old_text not found
264
+ ```
265
+
266
+ After multi-step tasks, a résumé and context-aware follow-up suggestions are shown:
267
+ ```
268
+ ── 3 steps · 8 tools · 2 files modified · 37s ──
269
+ 💡 /diff · /commit · /undo
270
+ ```
271
+ Step counts match between inline `── step N ──` markers and the résumé. Elapsed time is included. Read-heavy sessions (analysis, status checks) suggest `/save · /clear` instead.
272
+
273
+ When the model runs tools but produces no visible text, an automatic nudge forces it to summarize findings — preventing silent completions where the user sees nothing.
274
+
275
+ ### Response Quality
276
+ The system prompt enforces substantive responses: the model always presents findings as formatted text after using tools (users only see 1-line tool summaries). Responses use markdown with headers, bullet lists, and code blocks. The model states its approach before non-trivial tasks and summarizes results after completing work.
277
+
278
+ ### Streaming Output
279
+ Tokens appear live as the model generates them. Braille spinner during connection, then real-time line-by-line rendering via `StreamRenderer` with markdown formatting and syntax highlighting (JS, TS, Python, Go, Rust, CSS, HTML, and more).
280
+
281
+ ### Paste Detection
282
+ Automatic bracketed paste mode: pasting multi-line text into the prompt is detected and combined into a single input. A `[Pasted content — N lines]` indicator is shown with a preview of the first line. The user must press Enter to send — pasted content never auto-fires. The paste handler stores the combined text and waits for explicit submission.
283
+
284
+ ### Ctrl+C Cancellation
285
+ Pressing Ctrl+C during a running request immediately cancels the active HTTP stream and returns to the prompt:
286
+ - An `AbortController` signal flows from the SIGINT handler through the agent loop to the provider's HTTP request
287
+ - All providers (Ollama, OpenAI, Anthropic, Gemini, local) destroy the response stream on abort
288
+ - No EPIPE errors after cancellation (stdout writes are EPIPE-guarded)
289
+ - 3x rapid Ctrl+C force-exits the process
290
+
291
+ ### Diff Preview
292
+ Every file change is shown in Claude Code-style format before being applied:
293
+ - **Header**: `⏺ Update(file)` or `⏺ Create(file)` with relative path
294
+ - **Summary**: `⎿ Added N lines, removed M lines`
295
+ - **Numbered lines**: right-justified line numbers with red `-` / green `+` markers
296
+ - **Context**: 3 lines of surrounding context per change, multiple hunks separated by `···`
297
+ - OOM-safe: large diffs (>2000 lines) fall back to add/remove instead of LCS
298
+ - All changes require `[y/n]` confirmation (toggle with `/autoconfirm` or start with `-yolo`)
299
+
300
+ ### Auto-Context
301
+ On startup, the CLI reads your project and injects context into the system prompt:
302
+ - `package.json` — name, version, scripts, dependencies
303
+ - `README.md` — first 50 lines
304
+ - Git info — branch, status, recent commits
305
+ - `.gitignore` content
306
+
307
+ ### Context Engine
308
+ Automatic token management with compression when the context window gets full. Tracks token usage across system prompt, conversation, tool results, and tool definitions.
309
+
310
+ ### Safety Layer
311
+ Three tiers of protection:
312
+ - **Forbidden** (blocked): `rm -rf /`, `rm -rf .`, `mkfs`, `dd if=`, fork bombs, `curl|sh`, `cat .env`, `chmod 777`, reverse shells — 30+ patterns
313
+ - **Dangerous** (requires confirmation): `git push`, `npm publish`, `rm -rf`, `docker rm`, `sudo`, `ssh` — 14 patterns
314
+ - **SSH read-only safe list**: Common read-only SSH commands (`systemctl status`, `journalctl`, `tail`, `cat`, `git pull`, etc.) skip the dangerous-command confirmation
315
+ - **Path protection**: Sensitive paths (`.ssh/`, `.aws/`, `.env`, credentials) are blocked from file operations
316
+ - **Pre-push secret detection**: Git hook scans diffs for API keys, private keys, hardcoded secrets, SSH+IP patterns, and `.env` leaks before allowing push
317
+
318
+ ### Sessions
319
+ Save and restore conversations:
320
+ ```
321
+ /save my-feature
322
+ /load my-feature
323
+ /resume # resume last session
324
+ ```
325
+ Auto-save after every turn.
326
+
327
+ ### Memory
328
+ Persistent project memory that survives across sessions:
329
+ ```
330
+ /remember lang=TypeScript
331
+ /remember always use yarn instead of npm
332
+ /memory
333
+ /forget lang
334
+ ```
335
+
336
+ Also loads `NEX.md` from project root for project-level instructions.
337
+
338
+ ### Plan Mode
339
+ Analyze before executing — the agent creates a plan, you review and approve:
340
+ ```
341
+ /plan refactor the auth module
342
+ /plan status
343
+ /plan approve
344
+ /auto semi-auto # set autonomy level
345
+ ```
346
+
347
+ ### Undo / Redo
348
+ In-session undo/redo for all file changes (write, edit, patch):
349
+ ```
350
+ /undo # undo last file change
351
+ /redo # redo last undone change
352
+ /history # show file change history
353
+ ```
354
+ Undo stack holds up to 50 changes. `/clear` resets the history.
355
+
356
+ ### Task Management
357
+ Create structured task lists for complex multi-step operations:
358
+ ```
359
+ /tasks # show current task list
360
+ /tasks clear # clear all tasks
361
+ ```
362
+ The agent uses `task_list` to create, update, and track progress on tasks with dependency support.
363
+
364
+ When the agent creates a task list, a **live animated display** replaces the static output:
365
+ ```
366
+ ✽ Adding cost limit functions… (1m 35s · ↓ 2.6k tokens)
367
+ ⎿ ✔ Create cli/picker.js — Interactive Terminal Picker
368
+ ◼ Add cost limits to cli/costs.js
369
+ ◻ Add budget gate to cli/providers/registry.js
370
+ ◻ Update cli/index.js
371
+ ◻ Run tests
372
+ ```
373
+ - Animated spinner header with elapsed time and cumulative token count
374
+ - Per-task status icons: `✔` done, `◼` in progress, `◻` pending, `✗` failed
375
+ - Automatically pauses during text streaming and resumes during tool execution
376
+ - Falls back to the static `/tasks` view when no live display is active
377
+
378
+ ### Sub-Agents
379
+ Spawn parallel sub-agents for independent tasks:
380
+ - Up to 5 agents run simultaneously with their own conversation contexts
381
+ - File locking prevents concurrent writes to the same file
382
+ - Multi-progress display shows real-time status of each agent
383
+ - Good for: reading multiple files, analyzing separate modules, independent research
384
+
385
+ **Multi-Model Routing** — Sub-agents auto-select the best model per task based on complexity:
386
+ - **Read/search/list** tasks → fast models (essential tier)
387
+ - **Edit/fix/analyze** tasks → capable models (standard tier)
388
+ - **Refactor/implement/generate** tasks → most powerful models (full tier)
389
+
390
+ The LLM can also explicitly override with `model: "provider:model"` in the agent definition. When multiple providers are configured, the system prompt includes a routing table showing all available models and their tiers.
391
+
392
+ ### Git Intelligence
393
+ ```
394
+ /commit # analyze diff, suggest commit message
395
+ /commit feat: add login
396
+ /diff # show current diff summary
397
+ /branch my-feature # create and switch to branch
398
+ ```
399
+
400
+ ### Permissions
401
+ Control which tools the agent can use:
402
+ ```
403
+ /permissions # show current settings
404
+ /allow read_file # auto-allow without asking
405
+ /deny bash # block completely
406
+ ```
407
+
408
+ Persisted in `.nex/config.json`.
409
+
410
+ ### Cost Tracking
411
+ Track token usage and costs per provider:
412
+ ```
413
+ /costs
414
+ /costs reset
415
+ ```
416
+
417
+ ### Cost Limits
418
+ Set per-provider spending limits. When a provider exceeds its budget, calls automatically fall back to the next provider in the fallback chain:
419
+ ```
420
+ /budget # show all limits + current spend
421
+ /budget anthropic 5 # set $5 limit for Anthropic
422
+ /budget openai 10 # set $10 limit for OpenAI
423
+ /budget anthropic off # remove limit
424
+ ```
425
+
426
+ Limits are persisted in `.nex/config.json`. You can also set them directly:
427
+ ```json
428
+ // .nex/config.json
429
+ {
430
+ "costLimits": {
431
+ "anthropic": 5,
432
+ "openai": 10
433
+ }
434
+ }
435
+ ```
436
+
437
+ ### Open-Source Model Robustness
438
+
439
+ Four features that make Nex Code significantly more reliable with open-source models:
440
+
441
+ **Tool Call Retry with Schema Hints** — When a model sends malformed tool arguments, instead of a bare error, the agent sends back the expected JSON schema so the model can self-correct on the next loop iteration.
442
+
443
+ **Smart Argument Parsing** — 5 fallback strategies for parsing tool arguments: direct JSON, trailing comma/quote fixes, JSON extraction from surrounding text, unquoted key repair, and markdown code fence stripping (common with DeepSeek R1, Llama).
444
+
445
+ **Tool Argument Validation** — Validates arguments against tool schemas before execution. Auto-corrects similar parameter names (Levenshtein distance), fixes type mismatches (string↔number↔boolean), and provides "did you mean?" suggestions.
446
+
447
+ **Auto-Fix Engine** — Three layers of automatic error recovery that silently fix common tool failures:
448
+ - **Path auto-fix**: Wrong extension? Finds the right one (`.js` → `.ts`). File moved? Globs for it by basename. Double slashes, missing extensions — all auto-resolved.
449
+ - **Edit auto-fix**: Close match (≤5% Levenshtein distance) in `edit_file`/`patch_file` is auto-applied instead of erroring. Stacks with fuzzy whitespace matching.
450
+ - **Bash error hints**: Enriches error output with actionable hints — "command not found" → install suggestion, `MODULE_NOT_FOUND` → `npm install <pkg>`, port in use, syntax errors, TypeScript errors, test failures, and more.
451
+
452
+ **Tool Tiers** — Dynamically reduces the tool set based on model capability:
453
+ - **essential** (5 tools): bash, read_file, write_file, edit_file, list_directory
454
+ - **standard** (13 tools): + search_files, glob, grep, ask_user, git_status, git_diff, git_log, task_list
455
+ - **full** (17 tools): all tools
456
+
457
+ Models are auto-classified, or override per-model in `.nex/config.json`:
458
+ ```json
459
+ {
460
+ "toolTiers": {
461
+ "deepseek-r1": "essential",
462
+ "local:*": "essential",
463
+ "qwen3-coder": "full"
464
+ }
465
+ }
466
+ ```
467
+
468
+ Tiers are also used by sub-agent routing — when a sub-agent auto-selects a model, its tool set is filtered to match that model's tier.
469
+
470
+ ---
471
+
472
+ ## Skills
473
+
474
+ Extend Nex Code with project-specific knowledge, commands, and tools via `.nex/skills/`.
475
+
476
+ ### Prompt Skills (`.md`)
477
+ Drop a Markdown file and its content is injected into the system prompt:
478
+
479
+ ```markdown
480
+ <!-- .nex/skills/code-style.md -->
481
+ # Code Style
482
+ - Always use semicolons
483
+ - Prefer const over let
484
+ - Use TypeScript strict mode
485
+ ```
486
+
487
+ ### Script Skills (`.js`)
488
+ CommonJS modules that can provide instructions, slash commands, and tools:
489
+
490
+ ```javascript
491
+ // .nex/skills/deploy.js
492
+ module.exports = {
493
+ name: 'deploy',
494
+ description: 'Deployment helper',
495
+ instructions: 'When deploying, always run tests first...',
496
+ commands: [
497
+ { cmd: '/deploy', desc: 'Run deployment', handler: (args) => { /* ... */ } }
498
+ ],
499
+ tools: [
500
+ {
501
+ type: 'function',
502
+ function: { name: 'deploy_status', description: 'Check status', parameters: { type: 'object', properties: {} } },
503
+ execute: async (args) => 'deployed'
504
+ }
505
+ ]
506
+ };
507
+ ```
508
+
509
+ ### Management
510
+
511
+ ```
512
+ /skills # list loaded skills
513
+ /skills enable code-style # enable a skill
514
+ /skills disable code-style # disable a skill
515
+ ```
516
+
517
+ Skills are loaded on startup. All enabled by default. Disabled skills tracked in `.nex/config.json`.
518
+
519
+ ---
520
+
521
+ ## MCP
522
+
523
+ Connect external tool servers via the [Model Context Protocol](https://modelcontextprotocol.io):
524
+
525
+ ```json
526
+ // .nex/config.json
527
+ {
528
+ "mcpServers": {
529
+ "my-server": {
530
+ "command": "node",
531
+ "args": ["path/to/server.js"]
532
+ }
533
+ }
534
+ }
535
+ ```
536
+
537
+ ```
538
+ /mcp # show servers and tools
539
+ /mcp connect # connect all configured servers
540
+ /mcp disconnect # disconnect all
541
+ ```
542
+
543
+ MCP tools appear with the `mcp_` prefix and are available to the agent alongside built-in tools.
544
+
545
+ ---
546
+
547
+ ## Hooks
548
+
549
+ Run custom scripts on CLI events:
550
+
551
+ ```json
552
+ // .nex/config.json
553
+ {
554
+ "hooks": {
555
+ "pre-tool": ["echo 'before tool'"],
556
+ "post-tool": ["echo 'after tool'"],
557
+ "pre-commit": ["npm test"]
558
+ }
559
+ }
560
+ ```
561
+
562
+ Events: `pre-tool`, `post-tool`, `pre-commit`, `post-response`, `session-start`, `session-end`.
563
+
564
+ Or place executable scripts in `.nex/hooks/`:
565
+ ```
566
+ .nex/hooks/pre-tool
567
+ .nex/hooks/post-tool
568
+ ```
569
+
570
+ ---
571
+
572
+ ## Architecture
573
+
574
+ ```
575
+ bin/nex-code.js # Entrypoint (shebang, .env, startREPL)
576
+ cli/
577
+ ├── index.js # REPL + ~38 slash commands + history persistence + AbortController
578
+ ├── agent.js # Agentic loop + conversation state + compact output + résumé + abort handling
579
+ ├── providers/ # Multi-provider abstraction
580
+ │ ├── base.js # Abstract provider interface
581
+ │ ├── ollama.js # Ollama Cloud provider
582
+ │ ├── openai.js # OpenAI provider
583
+ │ ├── anthropic.js # Anthropic provider
584
+ │ ├── gemini.js # Google Gemini provider
585
+ │ ├── local.js # Local Ollama server
586
+ │ └── registry.js # Provider registry + model resolution + provider routing
587
+ ├── tools.js # 17 tool definitions + implementations + auto-fix engine
588
+ ├── sub-agent.js # Parallel sub-agent runner with file locking + model routing
589
+ ├── tasks.js # Task list management (create, update, render, onChange callbacks)
590
+ ├── skills.js # Skills system (prompt + script skills)
591
+ ├── mcp.js # MCP client (JSON-RPC over stdio)
592
+ ├── hooks.js # Hook system (pre/post events)
593
+ ├── context.js # Auto-context (package.json, git, README)
594
+ ├── context-engine.js # Token management + context compression
595
+ ├── session.js # Session persistence (.nex/sessions/)
596
+ ├── memory.js # Project memory (.nex/memory/ + NEX.md)
597
+ ├── permissions.js # Tool permission system
598
+ ├── planner.js # Plan mode + autonomy levels
599
+ ├── git.js # Git intelligence (commit, diff, branch)
600
+ ├── render.js # Markdown + syntax highlighting + StreamRenderer + EPIPE guard
601
+ ├── format.js # Tool call formatting, result formatting, compact summaries
602
+ ├── spinner.js # Spinner, MultiProgress, TaskProgress display components
603
+ ├── diff.js # LCS diff (Myers + Hirschberg) + colored output + side-by-side view
604
+ ├── fuzzy-match.js # Fuzzy text matching for edit auto-fix (Levenshtein, whitespace normalization)
605
+ ├── file-history.js # In-session undo/redo for file changes
606
+ ├── picker.js # Interactive terminal picker (model selection)
607
+ ├── costs.js # Token cost tracking + per-provider budget limits
608
+ ├── safety.js # Forbidden/dangerous pattern detection
609
+ ├── tool-validator.js # Tool argument validation + auto-correction
610
+ ├── tool-tiers.js # Dynamic tool set selection per model + model tier lookup
611
+ ├── ui.js # ANSI colors, banner + re-exports from format.js/spinner.js
612
+ ├── auto-fix.js # Path resolution, edit matching, bash error hints
613
+ ├── tool-retry.js # Malformed argument retry with schema hints
614
+ └── ollama.js # Backward-compatible wrapper
615
+ ```
616
+
617
+ ### Agentic Loop
618
+
619
+ ```
620
+ User Input --> [AbortController created]
621
+ |
622
+ [System Prompt + Context + Memory + Skills + Conversation]
623
+ |
624
+ [Filter tools by model tier (essential/standard/full)]
625
+ |
626
+ Provider API (streaming + abort signal) --> Text tokens --> rendered to terminal
627
+ | \--> Tool calls --> parse args (5 strategies)
628
+ | |
629
+ | [Validate against schema + auto-correct]
630
+ | |
631
+ | Execute (skill / MCP / built-in)
632
+ | |
633
+ | [Auto-fix: path resolution, edit matching, bash hints]
634
+ |
635
+ [Tool results added to history]
636
+ |
637
+ Loop until: no more tool calls OR 50 iterations OR Ctrl+C abort
638
+ ```
639
+
640
+ ---
641
+
642
+ ## .nex/ Directory
643
+
644
+ Project-local configuration and state (gitignored):
645
+
646
+ ```
647
+ .nex/
648
+ ├── config.json # Permissions, MCP servers, hooks, skills, cost limits
649
+ ├── sessions/ # Saved conversations
650
+ ├── memory/ # Persistent project knowledge
651
+ ├── plans/ # Saved plans
652
+ ├── hooks/ # Custom hook scripts
653
+ ├── skills/ # Skill files (.md and .js)
654
+ └── push-allowlist # False-positive allowlist for pre-push secret detection
655
+ ```
656
+
657
+ ---
658
+
659
+ ## Testing
660
+
661
+ ```bash
662
+ npm test # Run all tests with coverage
663
+ npm run test:watch # Watch mode
664
+ ```
665
+
666
+ 43 test suites, 1780 tests, 90% statement / 83% branch coverage.
667
+
668
+ CI runs on GitHub Actions (Node 18/20/22).
669
+
670
+ ---
671
+
672
+ ## Dependencies
673
+
674
+ 2 runtime dependencies:
675
+
676
+ ```json
677
+ {
678
+ "axios": "^1.7.0",
679
+ "dotenv": "^16.4.0"
680
+ }
681
+ ```
682
+
683
+ Everything else is Node.js built-in.
684
+
685
+ ## License
686
+
687
+ MIT