@callstack/apex 0.2.1 → 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 CHANGED
@@ -1,65 +1,232 @@
1
1
  # Apex CLI
2
2
 
3
- Configures the AI coding assistants installed on your machine to use
4
- [Callstack Apex](https://apex.callstack.com/) — an OpenAI-compatible endpoint
5
- serving the `callstack/Apex` model.
3
+ Configures the AI coding assistants on your machine to use
4
+ [Callstack Apex](https://apex.callstack.com/) (`callstack/Apex`).
6
5
 
7
- ## Install
6
+ `apex init` detects the assistants on your machine, lets you pick which ones to configure,
7
+ shows every change it wants to make, and only then writes. Nothing changes until you say so.
8
8
 
9
- ```sh
10
- curl -fsSL https://apex.callstack.ai/install.sh | sh
11
- ```
12
-
13
- This checks for Node.js 18+ and then runs `npx @callstack/apex init` for you.
9
+ ## Install
14
10
 
15
- If you already have Node.js, you can skip the script entirely:
11
+ Requires Node.js 22+ and npm. Nothing to install first:
16
12
 
17
13
  ```sh
18
14
  npx @callstack/apex init
19
15
  ```
20
16
 
21
- ## What `init` does
17
+ An npx run leaves no `apex` command behind, so after setup it offers to install the same version
18
+ globally (`npm install -g @callstack/apex`), which is what makes `apex undo` and `apex run codex`
19
+ work later; the rest of this README uses that short form. Say no, or run non-interactively, and
20
+ every next step Apex CLI prints is spelled `npx @callstack/apex …` instead. Uninstalling does not
21
+ undo your configs, so run `apex undo` first if you want them back.
22
22
 
23
- It detects which of these are installed and writes (or updates) their config
24
- to point at Apex, backing up any existing file first (`<file>.bak-<timestamp>`):
23
+ ## Commands
25
24
 
26
- | Assistant | Config written |
27
- | --- | --- |
28
- | Claude Code | `~/.claude/settings.json` |
29
- | Codex | `~/.codex/config.toml`, `~/.codex/callstack_ai.config.toml` |
30
- | OpenCode | `~/.config/opencode/opencode.json` (v1 or v2 format, auto-detected), `~/.local/share/opencode/auth.json` (if absent, v1 only) |
31
- | pi | `~/.pi/agent/models.json` |
32
- | Cursor | manual steps (GUI-only, printed to the terminal) |
33
- | VS Code + GitHub Copilot | manual steps (GUI-only, printed to the terminal) |
34
- | Vercel AI SDK / Eve | `.env` in the current project, if it depends on `ai`/`eve` |
25
+ | Command | What it does | Writes by default? |
26
+ | --- | --- | --- |
27
+ | `apex detect [--json]` | Finds assistants on `PATH`, in config directories and in macOS `/Applications`; shows what would change | No, never |
28
+ | `apex init` | Interactive setup: multiselect of detected assistants, colourised change preview, confirmation | Only after you confirm |
29
+ | `apex init --no-interactive` | Prints the plan without asking questions | No |
30
+ | `apex init --apply` | Writes the planned changes without asking | Yes |
31
+ | `apex undo` | Reverts the most recent Apex CLI setup, with the same preview and confirmation | Only after you confirm |
32
+ | `apex undo --list` | Shows recorded setups and which are already undone (`--json` prints the journal) | No |
33
+ | `apex run <assistant> [-- <args>]` | Launches the assistant with the gateway, model and credentials in the child environment | No |
34
+ | `apex completion <zsh\|bash\|fish>` | Prints a shell completion script | No |
35
35
 
36
- You'll be prompted for your Apex API key (input hidden), or pass it directly:
36
+ Each command accepts only its own flags, and `--help` and the shell completions list exactly those:
37
37
 
38
- ```sh
39
- npx @callstack/apex init --api-key sk-XXX
40
- # or
41
- APEX_API_KEY=sk-XXX npx @callstack/apex init --yes
42
- ```
38
+ | Command | Flags |
39
+ | --- | --- |
40
+ | `init` | `--assistants <ids>`, `--no-interactive`, `--apply`, `--no-diff`, `--json`, `--help` |
41
+ | `detect` | `--json`, `--help` |
42
+ | `undo` | `--no-interactive`, `--apply`, `--no-diff`, `--json`, `--list`, `--help` |
43
43
 
44
- Other flags: `--dry-run` (show changes without writing), `--only <ids>` /
45
- `--skip <ids>` (comma-separated, see `apex list` for ids).
44
+ `apex init --wat` fails fast, and so does a flag in the wrong command
45
+ (`apex detect --no-diff`). Only `--apply` writes, so there is no "preview *and* write" to argue
46
+ about. `--assistants <ids>` is a comma list of `opencode`, `codex`,
47
+ `claude`, `pi`, `cursor`, `copilot`, `ai-sdk`.
46
48
 
47
- ## Commands
49
+ Non-interactive callers (`--no-interactive`, `--json`, pipes, CI) never get a prompt and never
50
+ have files changed unless they also pass `--apply`. `--json` prints a machine-readable plan with
51
+ `mode`, `applied`, `appliedPaths`, per-file `changes` and `nextSteps` instead of the human UI. If a
52
+ write fails halfway through a batch, the payload still reports what already landed plus the `error`,
53
+ and the exit code is 1.
54
+
55
+ ### Shell completion
48
56
 
49
57
  ```sh
50
- apex init # detect + configure
51
- apex list # show which assistants are detected, without changing anything
58
+ apex completion zsh > "${fpath[1]}/_apex" # then rehash
59
+ apex completion bash >> ~/.bashrc # then source ~/.bashrc
60
+ apex completion fish > ~/.config/fish/completions/apex.fish
52
61
  ```
53
62
 
54
- ## Security
55
-
56
- Your Apex API key is written locally to config files under your home
57
- directory (and, for JS projects, to a local `.env`). Never commit these
58
- files or share the key. Rotate it if you suspect it leaked.
59
-
60
- ## Local development
63
+ ## What a review looks like
61
64
 
62
- ```sh
63
- npm link
64
- apex --help
65
65
  ```
66
+ ┌────────────────────────────────────────────────────────────────────────────┐
67
+ │ Apex CLI · Configure callstack/Apex for your favorite harness │
68
+ │ │
69
+ │ Nothing is written until you confirm. │
70
+ └────────────────────────────────────────────────────────────────────────────┘
71
+ │
72
+ ◆ Set up callstack/Apex for which assistants? (space toggles, enter confirms)
73
+ │ OpenCode, Codex
74
+ │
75
+ ◇ Set up callstack/Apex for which assistants? (space toggles, enter confirms)
76
+ │ OpenCode, Codex
77
+
78
+
79
+ Planned changes:
80
+
81
+ Update ~/.config/opencode/opencode.json
82
+ --- ~/.config/opencode/opencode.json
83
+ +++ ~/.config/opencode/opencode.json
84
+ @@ -1,4 +1,19 @@
85
+ {
86
+ // keep this comment
87
+ - "theme": "dark"
88
+ + "theme": "dark",
89
+ + "provider": {
90
+ + "callstack.ai": { … }
91
+ + }
92
+ }
93
+
94
+ Create ~/.codex/callstack_ai.config.toml
95
+ --- /dev/null
96
+ +++ ~/.codex/callstack_ai.config.toml
97
+ @@ -0,0 +1,10 @@
98
+ +model_provider = "callstack_ai"
99
+
100
+ Existing files get a .apex-backup-<id> copy first. (dimmed)
101
+ │
102
+ ◇ Apply these changes?
103
+ ✔ ~/.config/opencode/opencode.json backup: opencode.json.apex-backup-b4c42657
104
+
105
+
106
+ Environment
107
+
108
+ ✓ CALLSTACK_AUTH_TOKEN is set in this shell
109
+ Apex CLI never reads, stores or logs the key itself.
110
+
111
+
112
+ Use these commands to run callstack/Apex with your selected harnesses:
113
+
114
+ apex run opencode opencode --model callstack.ai/callstack/Apex (dimmed)
115
+ apex run codex codex --profile callstack_ai
116
+
117
+ ...or pick "callstack/Apex" from the UI when setting up manually.
118
+ For more instructions, visit:
119
+ https://app.notion.com/p/callstack/Apex-how-to-use-it-36d5d027c0f880e99d03d1c37a77382f
120
+
121
+ If you want to undo the changes, run apex undo
122
+ ```
123
+ `Environment` only shows the `export CALLSTACK_AUTH_TOKEN=…` line while the variable is missing; once
124
+ it is set you get a green `✓ CALLSTACK_AUTH_TOKEN is set in this shell` instead. The closing block shows
125
+ what each `apex run` expands to, links the guide (the URL is never folded, so it stays clickable), and
126
+ mentions `apex undo` only when something was actually written.
127
+
128
+ The diff is the change list: it only shows the lines that actually move, paths are shortened to
129
+ `~/…`, and values under keys like `apiKey`, `token` or `secret` are redacted, so a preview can be
130
+ pasted into a ticket safely. A file Apex CLI created diffs from `/dev/null`, and one it is deleting
131
+ diffs to `/dev/null`. `--no-diff` swaps the diff for one `+ key value` row per setting.
132
+
133
+ ## Reversing changes
134
+
135
+ `apex undo` re-applies the inverse of the last setup, named by the time it ran: files Apex CLI
136
+ created are deleted, files it edited go back to their pre-setup bytes. It only touches a file whose current content still hashes
137
+ to what Apex CLI wrote; anything you edited afterwards is left alone and reported. A setup whose
138
+ remaining files can only be left alone does not block the older ones: the next `apex undo` moves on
139
+ to the most recent setup that still has something to restore. Restores create
140
+ their own backup first, so an undo is itself reversible. Apex CLI records each batch in
141
+ `$APEX_STATE_DIR/journal.json` (default `~/.local/state/apex/journal.json`, mode `0600`); the last
142
+ 20 batches are kept. Deleting the journal only forgets the history, it never changes a config.
143
+
144
+ ## Integrations
145
+
146
+ | Assistant | Configuration | Behavior |
147
+ | --- | --- | --- |
148
+ | OpenCode | `~/.config/opencode/opencode.json` or `.jsonc` | Adds `provider.callstack.ai`, OpenAI-compatible transport, model and environment-key reference; preserves the default model. A config already in OpenCode 2's `providers` format gets the v2 entry instead, and you add the key with `/connect`. |
149
+ | Codex 0.134.0+ | `~/.codex/callstack_ai.config.toml` | Adds a self-contained Responses API provider/profile; leaves base config and default model untouched. |
150
+ | Claude Code | `~/.claude/settings.json` | Merges attribution flag only; use `apex run claude` for gateway credentials and model selection. |
151
+ | Pi | `~/.pi/agent/models.json` | Adds `providers.callstack` with Chat Completions, Apex and `$CALLSTACK_AUTH_TOKEN`; preserves other models. Requires a Pi version supporting `$VAR` key interpolation. |
152
+ | Cursor | Guided setup | Prints endpoint, API-key and custom-model steps; does not modify private editor storage. |
153
+ | VS Code / Copilot | Guided setup | Detects VS Code, not whether Copilot is installed; prints custom-endpoint steps and model JSON, retaining the editor-generated secret reference. |
154
+ | Vercel AI SDK / Eve | Guided setup | Detected from the `package.json` in the directory you run Apex CLI from (`ai`, `@ai-sdk/openai` or `eve`); prints the connector snippet, which reads the key from `CALLSTACK_AUTH_TOKEN`, and the Eve context-window setting. Nothing is written into the project. |
155
+
156
+ OpenCode, Pi, Codex and the Copilot model JSON also declare what Apex can do, in each tool's own
157
+ fields: a 262,144-token context window, 16,384 output tokens, tool calling, image input, and the
158
+ `none`/`low`/`medium`/`xhigh` reasoning efforts (default `medium`). Cursor and Claude Code have no
159
+ such fields for a custom model.
160
+
161
+ Respects `XDG_CONFIG_HOME`, `CODEX_HOME`, `CLAUDE_CONFIG_DIR`, `PI_CODING_AGENT_DIR`,
162
+ `XDG_STATE_HOME`/`APEX_STATE_DIR`, and Windows `APPDATA`. Project-specific settings and custom
163
+ `OPENCODE_CONFIG` files are not modified and may override global configuration. A new OpenCode
164
+ config is written in the v1 format, which OpenCode 2 also reads. Older Codex
165
+ releases using inline `[profiles]` need a manual migration or a newer Codex release.
166
+
167
+ Windows: file configuration supports Windows paths, but `apex run` refuses `.cmd`/`.bat` shims to
168
+ avoid shell interpolation; launch the configured assistant directly or use WSL.
169
+
170
+ ## Authentication
171
+
172
+ Provide `CALLSTACK_AUTH_TOKEN` through your shell or a secret manager. Apex CLI never prompts for,
173
+ logs, stores or validates the key, and never writes it to a config file; configs only reference it.
174
+ A hidden prompt keeps it out of your shell history:
175
+
176
+ ```bash
177
+ read -r -s -p 'Callstack API key: ' CALLSTACK_AUTH_TOKEN; echo
178
+ export CALLSTACK_AUTH_TOKEN
179
+ apex run codex
180
+ ```
181
+
182
+ Other launchers: `apex run opencode`, `apex run claude`, `apex run pi`, `apex run codex -- --help`.
183
+ Launchers pass extra arguments through unchanged (without a shell), can be overridden by explicit
184
+ user arguments, and never run `init`. `apex run claude` sets the gateway URL, token, attribution
185
+ flag and model aliases in the child process only, leaving your default Claude provider alone.
186
+
187
+ ## Safety and recovery
188
+
189
+ Apex CLI will not break what you already have.
190
+
191
+ - It shows every change first, and writes nothing until you say yes. If you script it, only
192
+ `--apply` writes.
193
+ - It copies a file next to itself before it edits that file, so you can always put the old one back.
194
+ - It keeps your comments, your other settings, and your default model.
195
+ - It never asks for your API key, writes it down, or sends it anywhere. You keep it in
196
+ `CALLSTACK_AUTH_TOKEN`, and the CLI prints `<redacted>` wherever a secret would show.
197
+ - If a config file is broken, set up another way, or a link to somewhere else, Apex CLI stops and
198
+ tells you. It does not overwrite it.
199
+ - `apex undo` gives your old setup back. It only touches files that still match what Apex CLI wrote.
200
+
201
+ How that works underneath:
202
+
203
+ - Previews print paths and key/value changes, never secrets.
204
+ - All selected configurations are parsed before any write. Malformed files, conflicting Codex
205
+ profile keys and symlinked files or directories are refused, and one bad assistant blocks the
206
+ whole batch instead of half-applying it.
207
+ - JSON/JSONC edits preserve comments and unrelated keys. The Callstack endpoint is set to the
208
+ documented one. A key the assistant already has (in OpenCode's own key store, or in Pi's
209
+ `models.json`, where Apex CLI 0.2 put them) is kept, so upgrading never leaves an assistant
210
+ without a key; otherwise the config references `CALLSTACK_AUTH_TOKEN`.
211
+ - Writes use same-directory temporary files plus rename with mode `0600` (new directories `0700`),
212
+ and abort if the file changed on disk between planning and saving. This is not a lock or a
213
+ multi-file transaction: a later I/O failure can leave earlier writes applied. `apex undo`
214
+ cleans that up.
215
+ - Backups and newly created files are printed with every save. To recover by hand, close the
216
+ assistant and restore the printed `*.apex-backup-<id>` file over its config after reviewing any
217
+ intervening edits. Backups can contain previous secrets.
218
+ - No shell startup file is ever edited. The CLI makes no API requests and cannot verify your
219
+ key or gateway access; launch a configured assistant to test the connection.
220
+
221
+ ## Configuration references
222
+
223
+ - Official Codex advanced configuration: `https://developers.openai.com/codex/config-advanced/`
224
+ (separate profile files for 0.134.0+; provider is placed in that profile).
225
+ - OpenCode v1 configuration: `https://dev.opencode.ai/docs/config/`
226
+ (JSONC and `{env:VARIABLE}` support).
227
+ - Pi custom models: `https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/docs/models.md`
228
+ (`$VARIABLE` key interpolation; bare uppercase names are literals in current docs).
229
+
230
+ ## Contributing
231
+
232
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
package/bin/apex.js CHANGED
@@ -1,4 +1,13 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
2
+ import { existsSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ import { fileURLToPath, pathToFileURL } from 'node:url';
3
5
 
4
- require('../src/cli.js').main(process.argv.slice(2));
6
+ const dist = join(dirname(fileURLToPath(import.meta.url)), '..', 'dist', 'cli.js');
7
+
8
+ if (!existsSync(dist)) {
9
+ process.stderr.write('Missing dist/cli.js bundle. Run `npm run build` first.\n');
10
+ process.exit(1);
11
+ }
12
+
13
+ await import(pathToFileURL(dist).href);