@nexus-cortex/cli 4.33.0 → 4.34.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.
@@ -1,291 +0,0 @@
1
- # Nexus Cortex — User Guide
2
-
3
- The full headless workflow: the `cortex` CLI, the HTTP agent server, the REST API, sessions,
4
- PR review, deployment, and troubleshooting. For setup see the [README](../README.md); for
5
- internals see [Architecture](architecture.md).
6
-
7
- ## Install
8
-
9
- The simplest install is the `nexus-cortex` meta-package — it pulls in the `cortex` CLI and the
10
- HTTP server together:
11
-
12
- ```bash
13
- npm install -g nexus-cortex
14
- ```
15
-
16
- Prefer to install the components yourself? They're published individually:
17
-
18
- ```bash
19
- npm install -g @nexus-cortex/cli @nexus-cortex/server
20
- ```
21
-
22
- From source (`npm run build` auto-links the global commands):
23
-
24
- ```bash
25
- npm install && npm run build # multi-pass build, then links `cortex`
26
- npm run link # re-link any time (self-healing)
27
- ```
28
-
29
- ### Embed the library
30
-
31
- To drive the orchestrator in your own code instead of through the CLI:
32
-
33
- ```bash
34
- npm install @nexus-cortex/core @nexus-cortex/executors
35
- ```
36
- ```typescript
37
- import { CortexOrchestrator } from '@nexus-cortex/core';
38
-
39
- const cortex = new CortexOrchestrator({
40
- modelId: 'claude-sonnet-4-6',
41
- projectPath: process.cwd(),
42
- });
43
- const res = await cortex.processMessage({ role: 'user', content: 'Analyze this codebase' });
44
- ```
45
-
46
- ## The `cortex` CLI
47
-
48
- `cortex` is a headless command — one-shot or multi-turn natural-language queries, plus a
49
- full structured command set. The first query **auto-starts a local server**; it persists in
50
- the background and subsequent calls share one stateful session.
51
-
52
- ```bash
53
- # Simple query
54
- cortex "What is this project?"
55
-
56
- # Specific model
57
- cortex --model deepseek-v4-flash "Explain TypeScript generics"
58
-
59
- # Multi-turn (session persists automatically)
60
- cortex "Remember the launch code is FALCON-42"
61
- cortex "What was the launch code?"
62
-
63
- # JSON output for scripting and agent workflows
64
- cortex --json "List the npm scripts" | jq '.content[0].text'
65
-
66
- # Session management
67
- cortex --sessions # List all sessions
68
- cortex --stats # Current session stats
69
- cortex --new "Start a fresh conversation" # New session
70
- cortex --resume SESSION_ID "Continue here" # Resume a specific session
71
- cortex --quiet "Just the answer" # Response only, no metadata
72
- ```
73
-
74
- ### Autonomous agent (one-shot)
75
-
76
- `cortex agent` (alias `cortex run`) runs one task to completion and exits — fresh session,
77
- auto-approves tools (headless has no interactive approver), self-stops the server on idle.
78
- Point it at a throwaway/worktree/sandbox dir on a real repo.
79
-
80
- ```bash
81
- cortex agent "summarize the test gaps in this repo"
82
- cortex agent --cwd ./feature-branch "add a --version flag and run the tests"
83
- cortex run --json "fix the failing lint" | jq '.toolUses[].name'
84
- ```
85
-
86
- ### Command groups
87
-
88
- Run `cortex --help`, or `cortex <group> --help` for any group:
89
-
90
- | Group | What it does |
91
- |-------|--------------|
92
- | `cortex "<prompt>"` | One-shot query (`-m/--model`, `--system`, `--max-tokens`, `--json`) |
93
- | `cortex agent` / `run` | Autonomous one-shot agent (`--cwd`, `--json`) |
94
- | `models` | `list` / `info` / `search` / `compare` / `cost` / `providers` / `switch` |
95
- | `sessions` | `list` / `view` / `export` / `resume` / `checkpoints` / `stats` / `search` / `compact` |
96
- | `config` | `get` / `set` / `categories` / `category` / `reset` |
97
- | `mcp` | `list` / `status` / `tools` / `enable` / `disable` / `init` / `validate` / `edit` |
98
- | `permissions` | `mode` / `set` / `grant` / `revoke` / `policies` / `tools` / `auto-approve` |
99
- | `autoresearch` | `bench` / `experiment` / `evaluate` / `fix` / `list` |
100
- | `context` | `status` / `compact` / `boundaries` / `strategy` / `savings` |
101
- | `middleware` | `list` / `status` / `enable` / `disable` / `config` |
102
- | `artifact` | `list` / `status` / `restart` / `stop` |
103
- | `tmux` | `list` |
104
- | `tools` | `list` / `info` |
105
- | `cache` | `metrics` |
106
- | `system-messages` | `list` / `view` / `reload` |
107
- | `server` | `status` / `start` |
108
-
109
- ### Agent team usage
110
-
111
- The session ID enables multi-turn agent workflows:
112
-
113
- ```bash
114
- SESSION=$(cortex --quiet --json "Analyze test gaps" | jq -r '.sessionId')
115
- cortex --resume $SESSION "Now fix the top priority gap"
116
- cortex --resume $SESSION "Run the tests to verify"
117
- ```
118
-
119
- > **Interactive terminal UIs — Release 2.** A React/Ink chat UI (`neoncortex`), a Chalk UI
120
- > (`fuzzycortex`), the slash-command set, and a color-theme system ship in `@nexus-cortex/tui`
121
- > in the next release. Release 1 is headless-only.
122
-
123
- ## Running the HTTP server
124
-
125
- The server is a **stateful agent** — sequential requests share one persistent session with
126
- full conversation history, tool execution, and context management. No terminal UI required.
127
-
128
- ```bash
129
- # Production (uses DEFAULT_MODEL_ID from .env)
130
- cortex-server &
131
- # or, from source:
132
- node packages/server/dist/index.js &
133
-
134
- # Override model at launch
135
- DEFAULT_MODEL_ID=grok-4-1-fast-reasoning cortex-server &
136
-
137
- # Dev mode (auto-restart on code changes, auto-resumes session)
138
- cd packages/server && npm run dev
139
- ```
140
-
141
- Port 4000 = API server. The HTML dashboard (sandbox/tmux viewer, port 4001) is opt-in: set
142
- `ENABLE_DASHBOARD=true` — a master switch, so when off no second port is ever bound.
143
-
144
- ### Direct HTTP (curl)
145
-
146
- ```bash
147
- # Send a message
148
- curl -s http://localhost:4000/v1/messages \
149
- -H "Content-Type: application/json" \
150
- -d '{"model":"grok-4-1-fast-reasoning","messages":[{"role":"user","content":"Read package.json and tell me the version"}]}'
151
-
152
- # Multi-turn: the next request continues the same conversation
153
- curl -s http://localhost:4000/v1/messages \
154
- -H "Content-Type: application/json" \
155
- -d '{"model":"grok-4-1-fast-reasoning","messages":[{"role":"user","content":"What dependencies does it have?"}]}'
156
- ```
157
-
158
- ### Response fields
159
-
160
- | Field | Description |
161
- |-------|-------------|
162
- | `content[]` | Model text response |
163
- | `toolUses[]` | Tools called (name, input, result) |
164
- | `usage.inputTokens` | Total input tokens (reveals system message overhead) |
165
- | `usage.outputTokens` | Response size |
166
- | `usage.cache` | Cache hit rate and cost savings |
167
- | `metadata.toolCallIterations` | Tool round-trips |
168
-
169
- ### Session management API
170
-
171
- | Endpoint | Method | Description |
172
- |----------|--------|-------------|
173
- | `/sessions` | GET | List all sessions |
174
- | `/sessions/new` | POST | Start fresh session (old one saved) |
175
- | `/sessions/:id/stats` | GET | Token usage, turns, tool calls |
176
- | `/sessions/:id/messages` | GET | Full message history |
177
- | `/sessions/:id/model` | POST | Switch model mid-session |
178
- | `/sessions/:id/compaction` | POST | Trigger context compaction |
179
- | `/sessions/:id/cache/metrics` | GET | Cache hit rate and savings |
180
- | `/health` | GET | Server status and available models |
181
-
182
- Additional REST surfaces (run the server and `curl` them): `/tools`, `/permissions/*`,
183
- `/middleware/*`, `/config/*`, `/mcp/*`, `/system-messages/*`, and `/v1/approval-mode`.
184
- Session routes also include `export`, `DELETE`, `checkpoints`, `load`, `resume`, `context`,
185
- and `compaction/boundaries`.
186
-
187
- ### PR review API
188
-
189
- When the git/PR tools are configured (see [Architecture → Permission System](architecture.md)):
190
-
191
- | Endpoint | Method | Description |
192
- |----------|--------|-------------|
193
- | `/v1/pr/review` | POST | Run a PR review pipeline (`{repo, prNumber, options?}`) |
194
- | `/v1/pr/create` | POST | Drive PR creation in an isolated worktree (`{repo, branch?, description?}`) |
195
- | `/v1/pr/list` | GET | List open PRs (`?repo=owner/repo`) |
196
- | `/v1/pr/webhook` | POST | GitHub webhook — requires `GITHUB_WEBHOOK_SECRET` + a valid `X-Hub-Signature-256` (returns 401 if no secret is set) |
197
-
198
- ### Server lifecycle
199
-
200
- The server does **not** auto-shutdown after responses (unless `--idle-timeout` is set). Stop it explicitly:
201
-
202
- ```bash
203
- pkill -f "packages/server/dist/index.js" # or Ctrl+C if foreground
204
- ```
205
-
206
- **Session resume**: by default the server starts a **fresh** session on boot. Opt into resuming:
207
-
208
- | Variable | Default | Behavior |
209
- |----------|---------|----------|
210
- | `AUTO_RESUME` | `false` | `true` → resume the most recent session on startup |
211
- | `RESUME_SESSION_ID` | — | Resume a specific session by UUID (overrides `AUTO_RESUME`) |
212
-
213
- With `AUTO_RESUME=true`, `tsx watch` restarts (dev mode) seamlessly continue your conversation —
214
- code changes take effect without losing session state. Pair it with `SERVER_IDLE_TIMEOUT` for a
215
- "sleep when idle, resume on wake" daemon.
216
-
217
- ### Common launch variables
218
-
219
- | Variable | Default | Description |
220
- |----------|---------|-------------|
221
- | `DEFAULT_MODEL_ID` | `deepseek-v4-pro` | Model to use (any registry ID or alias) |
222
- | `PORT` | `4000` | Server port (falls back to the next free port if taken) |
223
- | `DEBUG` | `false` | Verbose logging (system messages, routes) |
224
- | `YOLO` | `false` | Auto-approve all tool executions (bypasses permissions) |
225
- | `CORTEX_MODE` | `persistent` | `stateless` for clean per-request sessions; `server` for HTTP-client mode |
226
- | `ENABLE_DASHBOARD` | `false` | Master switch for the sandbox/tmux web dashboard (binds `DASHBOARD_PORT`, default 4001) |
227
-
228
- Every variable is documented in [Configuration](configuration.md) and in `.env.example`. Run
229
- `cortex-server --help` for the server's own summary.
230
-
231
- ## Development
232
-
233
- ```bash
234
- npm run clean # Clean build artifacts
235
- npm run build # Build all packages (multi-pass; see Architecture)
236
- npm run typecheck # Type checking
237
- npm test # Run tests
238
- npm run test:ci # Tests with coverage
239
- npm run lint # Lint
240
- ```
241
-
242
- ### Dev workflow (stateful iteration)
243
-
244
- The recommended loop uses the server in dev mode with auto-resume:
245
-
246
- ```bash
247
- # Terminal 1: server with hot reload
248
- cd packages/server && npm run dev
249
-
250
- # Terminal 2: send messages (each builds on the last)
251
- cortex "Read the orchestrator and explain the tool loop"
252
- cortex "Now add logging before each tool call"
253
- cortex "Run the tests to verify"
254
- ```
255
-
256
- What survives restarts: **system-message edits** (read fresh each turn), **code changes**
257
- (tsx watch restarts + auto-resumes from JSONL), and **session state** (history, cache metrics,
258
- turn count restored from disk).
259
-
260
- ## Production deployment
261
-
262
- ```bash
263
- # Production server
264
- NODE_ENV=production PORT=4000 cortex-server
265
-
266
- # With PM2
267
- pm2 start packages/server/dist/index.js --name nexus-cortex
268
- ```
269
-
270
- ## Troubleshooting
271
-
272
- **Build errors** — clean and rebuild:
273
- ```bash
274
- npm run clean && npm run build
275
- ```
276
-
277
- **TypeScript errors** — `npm run typecheck`; ensure array accesses guard for `undefined`.
278
-
279
- **MCP server issues** — test the server manually and check config:
280
- ```bash
281
- npx -y @modelcontextprotocol/server-filesystem /path/to/dir
282
- cat .cortex/mcp_config.json
283
- ```
284
-
285
- **Missing API keys** — confirm the keys for the providers you use are set:
286
- ```bash
287
- echo $ANTHROPIC_API_KEY
288
- ```
289
-
290
- > `CORTEX.md` (project context) is generated on demand in your own project — run `/init` or
291
- > the `InitCortexContext` tool; it is not shipped with the package.