@diffexai/diffex 0.2.4 → 0.2.6

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/dist/AGENTS.md +0 -11
  4. package/dist/core/agent-session.d.ts +0 -1
  5. package/dist/core/agent-session.js +3 -10
  6. package/dist/core/sdk.js +1 -1
  7. package/dist/core/system-prompt-production.d.ts +7 -0
  8. package/dist/core/system-prompt-production.js +102 -0
  9. package/dist/core/system-prompt.d.ts +2 -2
  10. package/dist/core/system-prompt.js +34 -35
  11. package/dist/core/tools/subagents.js +22 -9
  12. package/dist/modes/print-mode.js +12 -14
  13. package/dist/node_modules/@diffexai/diffex-agent-core/distribution-components.json +4 -4
  14. package/dist/node_modules/@diffexai/diffex-agent-core/distribution-files.json +1 -1
  15. package/dist/node_modules/@diffexai/diffex-agent-core/package.json +1 -1
  16. package/dist/node_modules/@diffexai/diffex-ai/dist/providers/data/.manifest.json +1 -1
  17. package/dist/node_modules/@diffexai/diffex-ai/dist/providers/data/amazon-bedrock.json +1 -1
  18. package/dist/node_modules/@diffexai/diffex-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  19. package/dist/node_modules/@diffexai/diffex-ai/dist/providers/data/fireworks.json +1 -1
  20. package/dist/node_modules/@diffexai/diffex-ai/dist/providers/data/mistral.json +1 -1
  21. package/dist/node_modules/@diffexai/diffex-ai/dist/providers/data/nvidia.json +1 -1
  22. package/dist/node_modules/@diffexai/diffex-ai/dist/providers/data/openrouter.json +1 -1
  23. package/dist/node_modules/@diffexai/diffex-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  24. package/dist/node_modules/@diffexai/diffex-ai/dist/providers/data/qwen-token-plan.json +1 -1
  25. package/dist/node_modules/@diffexai/diffex-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  26. package/dist/node_modules/@diffexai/diffex-ai/distribution-components.json +3 -3
  27. package/dist/node_modules/@diffexai/diffex-ai/distribution-files.json +11 -11
  28. package/dist/node_modules/@diffexai/diffex-ai/package.json +1 -1
  29. package/dist/node_modules/@diffexai/diffex-client/distribution-components.json +3 -3
  30. package/dist/node_modules/@diffexai/diffex-client/distribution-files.json +1 -1
  31. package/dist/node_modules/@diffexai/diffex-client/package.json +1 -1
  32. package/dist/node_modules/@diffexai/diffex-harness-state/distribution-components.json +2 -2
  33. package/dist/node_modules/@diffexai/diffex-harness-state/distribution-files.json +1 -1
  34. package/dist/node_modules/@diffexai/diffex-harness-state/package.json +1 -1
  35. package/dist/node_modules/@diffexai/diffex-protocol/distribution-components.json +2 -2
  36. package/dist/node_modules/@diffexai/diffex-protocol/distribution-files.json +1 -1
  37. package/dist/node_modules/@diffexai/diffex-protocol/package.json +1 -1
  38. package/dist/node_modules/@diffexai/diffex-telemetry/distribution-components.json +2 -2
  39. package/dist/node_modules/@diffexai/diffex-telemetry/distribution-files.json +1 -1
  40. package/dist/node_modules/@diffexai/diffex-telemetry/package.json +1 -1
  41. package/dist/node_modules/@diffexai/diffex-tui/distribution-components.json +2 -2
  42. package/dist/node_modules/@diffexai/diffex-tui/distribution-files.json +1 -1
  43. package/dist/node_modules/@diffexai/diffex-tui/package.json +1 -1
  44. package/dist/server/create-harness.js +1 -1
  45. package/distribution-components.json +11 -11
  46. package/distribution-files.json +49 -41
  47. package/npm-shrinkwrap.json +2 -2
  48. package/package.json +1 -31
  49. package/release/distribution-manifest.json +4 -4
  50. package/release/install-package-lock.json +5 -5
  51. package/release/install-package.json +2 -2
  52. package/docs/compaction.md +0 -401
  53. package/docs/containerization.md +0 -84
  54. package/docs/custom-provider.md +0 -774
  55. package/docs/environment-variables.md +0 -88
  56. package/docs/evolution.md +0 -90
  57. package/docs/extensions.md +0 -2982
  58. package/docs/images/interactive-mode.png +0 -0
  59. package/docs/images/tree-view.png +0 -0
  60. package/docs/installation.md +0 -118
  61. package/docs/json.md +0 -91
  62. package/docs/keybindings.md +0 -241
  63. package/docs/llama-cpp.md +0 -99
  64. package/docs/models.md +0 -565
  65. package/docs/packages.md +0 -232
  66. package/docs/prompt-templates.md +0 -96
  67. package/docs/providers.md +0 -317
  68. package/docs/quickstart.md +0 -161
  69. package/docs/rpc.md +0 -1647
  70. package/docs/sdk.md +0 -1332
  71. package/docs/security.md +0 -66
  72. package/docs/session-format.md +0 -438
  73. package/docs/sessions.md +0 -162
  74. package/docs/settings.md +0 -341
  75. package/docs/shell-aliases.md +0 -13
  76. package/docs/skills.md +0 -227
  77. package/docs/terminal-setup.md +0 -152
  78. package/docs/themes.md +0 -326
  79. package/docs/tmux.md +0 -63
  80. package/docs/tui.md +0 -940
  81. package/docs/usage.md +0 -434
package/docs/packages.md DELETED
@@ -1,232 +0,0 @@
1
- > Diffex can help you create Diffex packages. Ask it to bundle your extensions, skills, prompt templates, or themes.
2
-
3
- # Diffex Packages
4
-
5
- Diffex packages bundle extensions, skills, prompt templates, and themes so you can share them through npm or git. A package can declare resources in `package.json` under the compatibility `diffex` key, or use conventional directories.
6
-
7
- ## Table of Contents
8
-
9
- - [Install and Manage](#install-and-manage)
10
- - [Package Sources](#package-sources)
11
- - [Creating a Diffex Package](#creating-a-diffex-package)
12
- - [Package Structure](#package-structure)
13
- - [Dependencies](#dependencies)
14
- - [Package Filtering](#package-filtering)
15
- - [Enable and Disable Resources](#enable-and-disable-resources)
16
- - [Scope and Deduplication](#scope-and-deduplication)
17
-
18
- ## Install and Manage
19
-
20
- > **Security:** Diffex packages run with full system access. Extensions execute arbitrary code, and skills can instruct the model to perform any action including running executables. Review source code before installing third-party packages.
21
-
22
- ```bash
23
- diffex install npm:@foo/bar@1.0.0
24
- diffex install git:github.com/user/repo@v1
25
- diffex install https://github.com/user/repo # raw URLs work too
26
- diffex install /absolute/path/to/package
27
- diffex install ./relative/path/to/package
28
-
29
- diffex remove npm:@foo/bar
30
- diffex list # show installed packages from settings
31
- diffex update # update Diffex only
32
- diffex update --all # update Diffex, update packages, and reconcile pinned git refs
33
- diffex update --extensions # update packages and reconcile pinned git refs only
34
- diffex update --models # refresh model catalogs only
35
- diffex update --self # update Diffex only
36
- diffex update --self --force # reinstall Diffex even if current
37
- diffex update npm:@foo/bar # update one package
38
- diffex update --extension npm:@foo/bar
39
- ```
40
-
41
- These commands manage Diffex packages and `diffex update` can update the Diffex CLI installation. To uninstall Diffex itself, see [Quickstart](quickstart.md#uninstall).
42
-
43
- In an interactive terminal, `install` asks whether to install globally or for the current workspace and shows the settings and package-storage destinations plus the security implications. Workspace installation requires project trust; cancellation, an untrusted workspace, or an unwritable destination never falls back to global installation. In non-interactive environments, `install` retains its global default. Pass `-l` to choose workspace scope explicitly without a scope prompt.
44
-
45
- `remove` writes to user settings (`~/.diffex/agent/settings.json`) by default; use `-l` for project settings (`.diffex/settings.json`). Project settings can be shared with your team, and Diffex installs any missing packages automatically on startup after the project is trusted.
46
-
47
- To try a package without installing it, use `--extension` or `-e`. This installs to a temporary directory for the current run only:
48
-
49
- ```bash
50
- diffex -e npm:@foo/bar
51
- diffex -e git:github.com/user/repo
52
- ```
53
-
54
- ## Package Sources
55
-
56
- Diffex accepts three source types in settings and `diffex install`.
57
-
58
- ### npm
59
-
60
- ```
61
- npm:@scope/pkg@1.2.3
62
- npm:pkg
63
- ```
64
-
65
- - Versioned specs are pinned and skipped by package updates (`diffex update --extensions`, `diffex update --all`).
66
- - User installs go under `~/.diffex/agent/npm/`.
67
- - Project installs go under `.diffex/npm/`.
68
- - Set `npmCommand` in `settings.json` to pin npm package lookup and install operations to a specific wrapper command such as `mise` or `asdf`.
69
-
70
- Example:
71
-
72
- ```json
73
- {
74
- "npmCommand": ["mise", "exec", "node@20", "--", "npm"]
75
- }
76
- ```
77
-
78
- ### git
79
-
80
- ```
81
- git:github.com/user/repo@v1
82
- git:git@github.com:user/repo@v1
83
- https://github.com/user/repo@v1
84
- ssh://git@github.com/user/repo@v1
85
- ```
86
-
87
- - Without `git:` prefix, only protocol URLs are accepted (`https://`, `http://`, `ssh://`, `git://`).
88
- - With `git:` prefix, shorthand formats are accepted, including `github.com/user/repo` and `git@github.com:user/repo`.
89
- - HTTPS and SSH URLs are both supported.
90
- - SSH URLs use your configured SSH keys automatically (respects `~/.ssh/config`).
91
- - For non-interactive runs (for example CI), you can set `GIT_TERMINAL_PROMPT=0` to disable credential prompts and set `GIT_SSH_COMMAND` (for example `ssh -o BatchMode=yes -o ConnectTimeout=5`) to fail fast.
92
- - Refs are pinned tags or commits. `diffex update --extensions` and `diffex update --all` do not move them to newer refs, but they do reconcile an existing clone to the configured ref.
93
- - Use `diffex install git:host/user/repo@new-ref` to update settings and move an existing package to a new pinned ref.
94
- - Cloned to `~/.diffex/agent/git/<host>/<path>` (global) or `.diffex/git/<host>/<path>` (project).
95
- - When reconciliation changes the checkout, Diffex resets and cleans the clone, then runs `npm install` if `package.json` exists.
96
-
97
- **SSH examples:**
98
- ```bash
99
- # git@host:path shorthand (requires git: prefix)
100
- diffex install git:git@github.com:user/repo
101
-
102
- # ssh:// protocol format
103
- diffex install ssh://git@github.com/user/repo
104
-
105
- # With version ref
106
- diffex install git:git@github.com:user/repo@v1.0.0
107
- ```
108
-
109
- ### Local Paths
110
-
111
- ```
112
- /absolute/path/to/package
113
- ./relative/path/to/package
114
- ```
115
-
116
- Local paths point to files or directories on disk and are added to settings without copying. Relative paths are resolved against the settings file they appear in. If the path is a file, it loads as a single extension. If it is a directory, Diffex loads resources using package rules.
117
-
118
- ## Creating a Diffex Package
119
-
120
- Add a `diffex` manifest to `package.json` or use conventional directories. Include the `diffex-package` keyword for discoverability.
121
-
122
- ```json
123
- {
124
- "name": "my-package",
125
- "keywords": ["diffex-package"],
126
- "diffex": {
127
- "extensions": ["./extensions"],
128
- "skills": ["./skills"],
129
- "prompts": ["./prompts"],
130
- "themes": ["./themes"]
131
- }
132
- }
133
- ```
134
-
135
- Paths are relative to the package root. Arrays support glob patterns and `!exclusions`.
136
-
137
- ### Package Discovery Metadata
138
-
139
- Include the `diffex-package` keyword so Diffex packages are discoverable through [npm search](https://www.npmjs.com/search?q=keywords%3Adiffex-package). For compatibility with upstream package indexes, packages can also include optional `video` or `image` preview metadata:
140
-
141
- ```json
142
- {
143
- "name": "my-package",
144
- "keywords": ["diffex-package"],
145
- "diffex": {
146
- "extensions": ["./extensions"],
147
- "video": "https://example.com/demo.mp4",
148
- "image": "https://example.com/screenshot.png"
149
- }
150
- }
151
- ```
152
-
153
- - **video**: MP4 preview URL.
154
- - **image**: PNG, JPEG, GIF, or WebP preview URL.
155
-
156
- If both are set, upstream package indexes prefer the video.
157
-
158
- ## Package Structure
159
-
160
- ### Convention Directories
161
-
162
- If no `diffex` manifest is present, Diffex auto-discovers resources from these directories:
163
-
164
- - `extensions/` loads `.ts` and `.js` files
165
- - `skills/` recursively finds `SKILL.md` folders and loads top-level `.md` files as skills
166
- - `prompts/` loads `.md` files
167
- - `themes/` loads `.json` files
168
-
169
- ## Dependencies
170
-
171
- Third party runtime dependencies belong in `dependencies` in `package.json`. Dependencies that do not register extensions, skills, prompt templates, or themes also belong in `dependencies`. When Diffex installs a package from npm or git, it runs `npm install`, so those dependencies are installed automatically.
172
-
173
- Diffex bundles core packages for extensions and skills. If you import any of these, list them in `peerDependencies` with a `"*"` range and do not bundle them: `@diffexai/diffex-ai`, `@diffexai/diffex-agent-core`, `@diffexai/diffex`, `@diffexai/diffex-tui`, `typebox`.
174
-
175
- Other Diffex packages must be bundled in your tarball. Add them to `dependencies` and `bundledDependencies`, then reference their resources through `node_modules/` paths. Diffex loads packages with separate module roots, so separate installs do not collide or share modules.
176
-
177
- Example:
178
-
179
- ```json
180
- {
181
- "dependencies": {
182
- "shitty-extensions": "^1.0.1"
183
- },
184
- "bundledDependencies": ["shitty-extensions"],
185
- "diffex": {
186
- "extensions": ["extensions", "node_modules/shitty-extensions/extensions"],
187
- "skills": ["skills", "node_modules/shitty-extensions/skills"]
188
- }
189
- }
190
- ```
191
-
192
- ## Package Filtering
193
-
194
- Filter what a package loads using the object form in settings:
195
-
196
- ```json
197
- {
198
- "packages": [
199
- "npm:simple-pkg",
200
- {
201
- "source": "npm:my-package",
202
- "extensions": ["extensions/*.ts", "!extensions/legacy.ts"],
203
- "skills": [],
204
- "prompts": ["prompts/review.md"],
205
- "themes": ["+themes/legacy.json"]
206
- }
207
- ]
208
- }
209
- ```
210
-
211
- `+path` and `-path` are exact paths relative to the package root.
212
-
213
- - Omit a key to load all of that type.
214
- - Use `[]` to load none of that type.
215
- - `!pattern` excludes matches.
216
- - `+path` force-includes an exact path.
217
- - `-path` force-excludes an exact path.
218
- - Filters layer on top of the manifest. They narrow down what is already allowed.
219
-
220
- ## Enable and Disable Resources
221
-
222
- Use `diffex config` to enable or disable extensions, skills, prompt templates, and themes from installed packages and local directories. `diffex config` starts in global settings (`~/.diffex/agent/settings.json`); press Tab to switch between global and project-local modes. Use `diffex config -l` to start in project overrides (`.diffex/settings.json`) with inherited global resources dimmed. Interactive sessions also expose installed-skill inspection and toggles under **Installed skills** in `/settings`; use `/reload` after changing them.
223
-
224
- ## Scope and Deduplication
225
-
226
- Packages can appear in both global and project settings. If the same package appears in both, the project entry wins unless the project entry has `autoload: false`, in which case it is applied as a delta over the global entry. Project-installed skills take precedence over user and package skills with the same name. An installed skill also retains the unsuffixed name when it collides with an evolved skill. See [Skills](skills.md) for complete catalog and collision rules.
227
-
228
- Identity is determined by:
229
-
230
- - npm: package name
231
- - git: repository URL without ref
232
- - local: resolved absolute path
@@ -1,96 +0,0 @@
1
- > Diffex can create prompt templates. Ask it to build one for your workflow.
2
-
3
- # Prompt Templates
4
-
5
- Prompt templates are Markdown snippets that expand into full prompts. Type `/name` in the editor to invoke a template, where `name` is the filename without `.md`.
6
-
7
- ## Locations
8
-
9
- Diffex loads prompt templates from:
10
-
11
- - Global: `~/.diffex/agent/prompts/*.md`
12
- - Project: `.diffex/prompts/*.md` (only after the project is trusted)
13
- - Packages: `prompts/` directories or `diffex.prompts` entries in `package.json`
14
- - Settings: `prompts` array with files or directories
15
- - CLI: `--prompt-template <path>` (repeatable)
16
-
17
- Disable discovery with `--no-prompt-templates`.
18
-
19
- ## Format
20
-
21
- ```markdown
22
- ---
23
- description: Review staged git changes
24
- ---
25
- Review the staged changes (`git diff --cached`). Focus on:
26
- - Bugs and logic errors
27
- - Security issues
28
- - Error handling gaps
29
- ```
30
-
31
- - The filename becomes the command name. `review.md` becomes `/review`.
32
- - `description` is optional. If missing, the first non-empty line is used.
33
- - `argument-hint` is optional. When set, the hint is displayed before the description in the autocomplete dropdown.
34
-
35
- ### Argument Hints
36
-
37
- Use `argument-hint` in frontmatter to show expected arguments in autocomplete. Use `<angle brackets>` for required arguments and `[square brackets]` for optional ones:
38
-
39
- ```markdown
40
- ---
41
- description: Review PRs from URLs with structured issue and code analysis
42
- argument-hint: "<PR-URL>"
43
- ---
44
- ```
45
-
46
- This renders in the autocomplete dropdown as:
47
-
48
- ```
49
- → pr <PR-URL> — Review PRs from URLs with structured issue and code analysis
50
- is <issue> — Analyze GitHub issues (bugs or feature requests)
51
- wr [instructions] — Finish the current task end-to-end
52
- cl — Audit changelog entries before release
53
- ```
54
-
55
- ## Usage
56
-
57
- Type `/` followed by the template name in the editor. Autocomplete shows available templates with descriptions.
58
-
59
- ```
60
- /review # Expands review.md
61
- /component Button # Expands with argument
62
- /component Button "click handler" # Multiple arguments
63
- ```
64
-
65
- ## Arguments
66
-
67
- Templates support positional arguments, defaults, and simple slicing:
68
-
69
- - `$1`, `$2`, ... positional args
70
- - `$@` or `$ARGUMENTS` for all args joined
71
- - `${1:-default}` uses arg 1 when present/non-empty, otherwise `default`
72
- - `${@:-default}` or `${ARGUMENTS:-default}` uses all arguments when present/non-empty, otherwise `default`
73
- - `${@:N}` for args from the Nth position (1-indexed)
74
- - `${@:N:L}` for `L` args starting at N
75
-
76
- Example:
77
-
78
- ```markdown
79
- ---
80
- description: Create a component
81
- ---
82
- Create a React component named $1 with features: $@
83
- ```
84
-
85
- Default values are useful for optional arguments:
86
-
87
- ```markdown
88
- Summarize the current state in ${1:-7} bullet points.
89
- ```
90
-
91
- Usage: `/component Button "onClick handler" "disabled support"`
92
-
93
- ## Loading Rules
94
-
95
- - Template discovery in `prompts/` is non-recursive.
96
- - If you want templates in subdirectories, add them explicitly via `prompts` settings or a package manifest.
package/docs/providers.md DELETED
@@ -1,317 +0,0 @@
1
- # Providers
2
-
3
- Diffex supports subscription-based providers via OAuth and API key providers via environment variables or auth file. Built-in catalogs ship with Diffex; configured providers may refresh newer catalogs and cache them in `~/.diffex/agent/models-store.json` for offline use.
4
-
5
- ## Table of Contents
6
-
7
- - [Subscriptions](#subscriptions)
8
- - [API Keys](#api-keys)
9
- - [Auth File](#auth-file)
10
- - [Cloud Providers](#cloud-providers)
11
- - [llama.cpp](#llamacpp)
12
- - [Custom Providers](#custom-providers)
13
- - [Resolution Order](#resolution-order)
14
-
15
- ## Subscriptions
16
-
17
- Use `/login` in interactive mode, then select a provider:
18
-
19
- - ChatGPT Plus/Pro (Codex)
20
- - Claude Pro/Max
21
- - GitHub Copilot
22
- - xAI (Grok/X subscription)
23
- - OpenRouter (OAuth-minted API key billed from OpenRouter credits)
24
- - Radius
25
-
26
- Use `/logout` to clear credentials. Tokens are stored in `~/.diffex/agent/auth.json` and auto-refresh when expired. OpenRouter instead mints a user-controlled API key that does not expire automatically.
27
-
28
- ### OpenAI Codex
29
-
30
- - Requires ChatGPT Plus or Pro subscription
31
- - Officially endorsed by OpenAI: [Codex for OSS](https://developers.openai.com/community/codex-for-oss)
32
-
33
- ### Claude Pro/Max
34
-
35
- Anthropic subscription auth is active for Claude Pro/Max accounts. Third-party harness usage draws from [extra usage](https://claude.ai/settings/usage) and is billed per token, not against Claude plan limits.
36
-
37
- ### GitHub Copilot
38
-
39
- - Press Enter for github.com, or enter your GitHub Enterprise Server domain
40
- - If you get "model not supported", enable it in VS Code: Copilot Chat → model selector → select model → "Enable"
41
-
42
- ### xAI (Grok/X subscription)
43
-
44
- - Run `/login xai`, then select **Use a subscription**
45
- - `XAI_API_KEY` remains available through **Use an API key**
46
-
47
- ### OpenRouter
48
-
49
- - Run `/login openrouter`, then select **Sign in with OpenRouter** to open the OpenRouter PKCE authorization flow
50
- - The authorization creates a user-controlled OpenRouter API key billed from your OpenRouter credits
51
- - On remote/headless machines (e.g. over SSH) the browser cannot reach the loopback callback; paste the final redirect URL (or the authorization code) into the login prompt instead
52
- - `OPENROUTER_API_KEY` remains available through **Use an API key**
53
-
54
- ### Radius
55
-
56
- Radius is a dynamic `diffex-messages` gateway. `/login radius` stores OAuth tokens in `auth.json`; the gateway catalog is refreshed independently and cached in `models-store.json`. Custom Radius gateways can be declared in `models.json` with `"oauth": "radius"` and a gateway `baseUrl`.
57
-
58
- ## API Keys
59
-
60
- ### Environment Variables or Auth File
61
-
62
- Use `/login` in interactive mode and select a provider to store an API key in `auth.json`, or set credentials via environment variable:
63
-
64
- ```bash
65
- export ANTHROPIC_API_KEY=sk-ant-...
66
- diffex
67
- ```
68
-
69
- | Provider | Environment Variable | `auth.json` key |
70
- |----------|----------------------|------------------|
71
- | Anthropic | `ANTHROPIC_API_KEY` | `anthropic` |
72
- | Ant Ling | `ANT_LING_API_KEY` | `ant-ling` |
73
- | Azure OpenAI Responses | `AZURE_OPENAI_API_KEY` | `azure-openai-responses` |
74
- | OpenAI | `OPENAI_API_KEY` | `openai` |
75
- | DeepSeek | `DEEPSEEK_API_KEY` | `deepseek` |
76
- | NVIDIA NIM | `NVIDIA_API_KEY` | `nvidia` |
77
- | Google Gemini | `GEMINI_API_KEY` | `google` |
78
- | Amazon Bedrock | `AWS_BEARER_TOKEN_BEDROCK` | `amazon-bedrock` |
79
- | Mistral | `MISTRAL_API_KEY` | `mistral` |
80
- | Groq | `GROQ_API_KEY` | `groq` |
81
- | Cerebras | `CEREBRAS_API_KEY` | `cerebras` |
82
- | Cloudflare AI Gateway | `CLOUDFLARE_API_KEY` (+ `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_GATEWAY_ID`) | `cloudflare-ai-gateway` |
83
- | Cloudflare Workers AI | `CLOUDFLARE_API_KEY` (+ `CLOUDFLARE_ACCOUNT_ID`) | `cloudflare-workers-ai` |
84
- | xAI | `XAI_API_KEY` | `xai` |
85
- | OpenRouter | `OPENROUTER_API_KEY` | `openrouter` |
86
- | Vercel AI Gateway | `AI_GATEWAY_API_KEY` | `vercel-ai-gateway` |
87
- | ZAI Coding Plan (Global) | `ZAI_API_KEY` | `zai` |
88
- | ZAI Coding Plan (China) | `ZAI_CODING_CN_API_KEY` | `zai-coding-cn` |
89
- | OpenCode Zen | `OPENCODE_API_KEY` | `opencode` |
90
- | OpenCode Go | `OPENCODE_API_KEY` | `opencode-go` |
91
- | Radius | `RADIUS_API_KEY` | `radius` |
92
- | Hugging Face | `HF_TOKEN` | `huggingface` |
93
- | Fireworks | `FIREWORKS_API_KEY` | `fireworks` |
94
- | Together AI | `TOGETHER_API_KEY` | `together` |
95
- | Baseten | `BASETEN_API_KEY` | `baseten` |
96
- | Kimi For Coding | `KIMI_API_KEY` | `kimi-coding` |
97
- | MiniMax | `MINIMAX_API_KEY` | `minimax` |
98
- | MiniMax (China) | `MINIMAX_CN_API_KEY` | `minimax-cn` |
99
- | Qwen Token Plan (existing catalog) | `QWEN_TOKEN_PLAN_API_KEY` | `qwen-token-plan` |
100
- | Qwen Token Plan (Individual) | `QWEN_TOKEN_PLAN_API_KEY` | `qwen-token-plan-individual` |
101
- | Qwen Token Plan (China) | `QWEN_TOKEN_PLAN_CN_API_KEY` | `qwen-token-plan-cn` |
102
- | Xiaomi MiMo | `XIAOMI_API_KEY` | `xiaomi` |
103
- | Xiaomi MiMo Token Plan (China) | `XIAOMI_TOKEN_PLAN_CN_API_KEY` | `xiaomi-token-plan-cn` |
104
- | Xiaomi MiMo Token Plan (Amsterdam) | `XIAOMI_TOKEN_PLAN_AMS_API_KEY` | `xiaomi-token-plan-ams` |
105
- | Xiaomi MiMo Token Plan (Singapore) | `XIAOMI_TOKEN_PLAN_SGP_API_KEY` | `xiaomi-token-plan-sgp` |
106
-
107
- Reference for environment variables and `auth.json` keys: [`const envMap`](https://github.com/diffexai/diffex/blob/main/packages/ai/src/env-api-keys.ts) in [`packages/ai/src/env-api-keys.ts`](https://github.com/diffexai/diffex/blob/main/packages/ai/src/env-api-keys.ts).
108
-
109
- #### Auth File
110
-
111
- Store credentials in `~/.diffex/agent/auth.json`:
112
-
113
- ```json
114
- {
115
- "anthropic": { "type": "api_key", "key": "sk-ant-..." },
116
- "ant-ling": { "type": "api_key", "key": "..." },
117
- "openai": { "type": "api_key", "key": "sk-..." },
118
- "deepseek": { "type": "api_key", "key": "sk-..." },
119
- "nvidia": { "type": "api_key", "key": "nvapi-..." },
120
- "google": { "type": "api_key", "key": "..." },
121
- "opencode": { "type": "api_key", "key": "..." },
122
- "opencode-go": { "type": "api_key", "key": "..." },
123
- "together": { "type": "api_key", "key": "..." },
124
- "qwen-token-plan": { "type": "api_key", "key": "sk-sp-..." },
125
- "qwen-token-plan-individual": { "type": "api_key", "key": "sk-sp-..." },
126
- "qwen-token-plan-cn": { "type": "api_key", "key": "sk-sp-..." },
127
- "xiaomi": { "type": "api_key", "key": "..." },
128
- "xiaomi-token-plan-cn": { "type": "api_key", "key": "..." },
129
- "xiaomi-token-plan-ams": { "type": "api_key", "key": "..." },
130
- "xiaomi-token-plan-sgp": { "type": "api_key", "key": "..." }
131
- }
132
- ```
133
-
134
- `qwen-token-plan-individual` uses the same international endpoint and `QWEN_TOKEN_PLAN_API_KEY` as
135
- `qwen-token-plan`, but limits the picker to the models documented for Individual subscriptions. The existing
136
- provider keeps its broader catalog for backward compatibility. When using `auth.json`, store the
137
- credential under the provider you select; an environment variable is shared by both international providers.
138
-
139
- The file is created with `0600` permissions (user read/write only). Auth file credentials take priority over environment variables.
140
-
141
- API key credentials can also include provider-scoped environment values. These values are used before process environment variables when resolving the credential key, provider/model headers, and provider configuration such as Cloudflare account IDs, Azure OpenAI settings, Vertex project/location, Bedrock settings, `DIFFEX_CACHE_RETENTION`, and `HTTP_PROXY`/`HTTPS_PROXY`.
142
-
143
- ```json
144
- {
145
- "cloudflare-ai-gateway": {
146
- "type": "api_key",
147
- "key": "$CLOUDFLARE_API_KEY",
148
- "env": {
149
- "CLOUDFLARE_API_KEY": "...",
150
- "CLOUDFLARE_ACCOUNT_ID": "account-id",
151
- "CLOUDFLARE_GATEWAY_ID": "gateway-id"
152
- }
153
- }
154
- }
155
- ```
156
-
157
- Use this when Diffex should use different provider settings than the project shell environment.
158
-
159
- ### Key Resolution
160
-
161
- The `key` field supports command execution, environment interpolation, and literals:
162
-
163
- - **Shell command:** `"!command"` at the start executes the whole value as a command and uses stdout (cached for process lifetime)
164
- ```json
165
- { "type": "api_key", "key": "!security find-generic-password -ws 'anthropic'" }
166
- { "type": "api_key", "key": "!op read 'op://vault/item/credential'" }
167
- ```
168
- - **Environment interpolation:** `"$ENV_VAR"` or `"${ENV_VAR}"` uses the value of the named variable. Interpolation works inside larger literals.
169
- ```json
170
- { "type": "api_key", "key": "$MY_ANTHROPIC_KEY" }
171
- { "type": "api_key", "key": "${KEY_PREFIX}_${KEY_SUFFIX}" }
172
- ```
173
- `$FOO_BAR` is the variable `FOO_BAR`; use `${FOO}_BAR` when `BAR` is literal text. Missing environment variables make the value unresolved.
174
- - **Escapes:** `"$$"` emits a literal `"$"`; `"$!"` emits a literal `"!"` without triggering command execution.
175
- ```json
176
- { "type": "api_key", "key": "$$literal-dollar-prefix" }
177
- { "type": "api_key", "key": "$!literal-bang-prefix" }
178
- ```
179
- - **Literal value:** Used directly. Plain uppercase strings such as `MY_API_KEY` are literals; use `$MY_API_KEY` for environment variables.
180
- ```json
181
- { "type": "api_key", "key": "sk-ant-..." }
182
- { "type": "api_key", "key": "public" }
183
- ```
184
-
185
- OAuth credentials are also stored here after `/login` and managed automatically.
186
-
187
- ## Cloud Providers
188
-
189
- ### Azure OpenAI
190
-
191
- ```bash
192
- export AZURE_OPENAI_API_KEY=...
193
- export AZURE_OPENAI_BASE_URL=https://your-resource.ai.azure.com
194
- # also supported: https://your-resource.cognitiveservices.azure.com
195
- # also supported: https://your-resource.openai.azure.com
196
- # root endpoints are auto-normalized to /openai/v1
197
- # or use resource name instead of base URL
198
- export AZURE_OPENAI_RESOURCE_NAME=your-resource
199
-
200
- # Optional
201
- export AZURE_OPENAI_API_VERSION=2024-02-01
202
- export AZURE_OPENAI_DEPLOYMENT_NAME_MAP=gpt-4=my-gpt4,gpt-4o=my-gpt4o
203
- ```
204
-
205
- ### Amazon Bedrock
206
-
207
- Use `/login amazon-bedrock` to store a Bedrock API key, or configure one of the ambient AWS credential sources below:
208
-
209
- ```bash
210
- # Option 1: AWS Profile
211
- export AWS_PROFILE=your-profile
212
-
213
- # Option 2: IAM Keys
214
- export AWS_ACCESS_KEY_ID=AKIA...
215
- export AWS_SECRET_ACCESS_KEY=...
216
-
217
- # Option 3: Bearer Token
218
- export AWS_BEARER_TOKEN_BEDROCK=...
219
-
220
- # Optional region (defaults to us-east-1)
221
- export AWS_REGION=us-west-2
222
- ```
223
-
224
- Also supports ECS task roles (`AWS_CONTAINER_CREDENTIALS_*`) and IRSA (`AWS_WEB_IDENTITY_TOKEN_FILE`).
225
-
226
- ```bash
227
- diffex --provider amazon-bedrock --model us.anthropic.claude-sonnet-4-20250514-v1:0
228
- ```
229
-
230
- Prompt caching is enabled automatically for Claude models whose ID contains a recognizable model name (base models and system-defined inference profiles). For application inference profiles (whose ARNs don't contain the model name), set `AWS_BEDROCK_FORCE_CACHE=1` to enable cache points:
231
-
232
- ```bash
233
- export AWS_BEDROCK_FORCE_CACHE=1
234
- diffex --provider amazon-bedrock --model arn:aws:bedrock:us-east-1:123456789012:application-inference-profile/abc123
235
- ```
236
-
237
- If you are connecting to a Bedrock API proxy, the following environment variables can be used:
238
-
239
- ```bash
240
- # Set the URL for the Bedrock proxy (standard AWS SDK env var)
241
- export AWS_ENDPOINT_URL_BEDROCK_RUNTIME=https://my.corp.proxy/bedrock
242
-
243
- # Set if your proxy does not require authentication
244
- export AWS_BEDROCK_SKIP_AUTH=1
245
-
246
- # Set if your proxy only supports HTTP/1.1
247
- export AWS_BEDROCK_FORCE_HTTP1=1
248
- ```
249
-
250
- ### Cloudflare AI Gateway
251
-
252
- `CLOUDFLARE_API_KEY` can be set via `/login`. The account ID and gateway slug can be set as environment variables or in the API key credential's `env` object in `auth.json`.
253
-
254
- ```bash
255
- export CLOUDFLARE_API_KEY=... # or use /login
256
- export CLOUDFLARE_ACCOUNT_ID=...
257
- export CLOUDFLARE_GATEWAY_ID=... # create at dash.cloudflare.com → AI → AI Gateway
258
- diffex --provider cloudflare-ai-gateway --model "claude-sonnet-4-5"
259
- ```
260
-
261
- Routes to OpenAI, Anthropic, and Workers AI through Cloudflare AI Gateway. Workers AI uses the Unified API (`/compat`) and prefixed model IDs (`workers-ai/@cf/...`). OpenAI uses the OpenAI passthrough route (`/openai`) with native OpenAI model IDs such as `gpt-5.1`. Anthropic uses the Anthropic passthrough route (`/anthropic`) with native Anthropic model IDs such as `claude-sonnet-4-5`.
262
-
263
- AI Gateway authentication uses `CLOUDFLARE_API_KEY` as `cf-aig-authorization`. Upstream authentication can be one of:
264
-
265
- | Mode | Request auth | Upstream auth |
266
- |------|--------------|---------------|
267
- | Workers AI | Cloudflare token only | Cloudflare-native |
268
- | Unified billing | Cloudflare token only | Cloudflare handles upstream auth and deducts credits |
269
- | Stored BYOK | Cloudflare token only | Cloudflare injects provider keys stored in the AI Gateway dashboard |
270
- | Inline BYOK | Cloudflare token plus upstream `Authorization` header | The request supplies the upstream provider key |
271
-
272
- For normal Diffex usage, prefer unified billing or stored BYOK. Inline BYOK requires configuring an additional upstream `Authorization` header for the Cloudflare AI Gateway provider, for example via a `models.json` provider/model override.
273
-
274
- ### Cloudflare Workers AI
275
-
276
- `CLOUDFLARE_API_KEY` can be set via `/login`. `CLOUDFLARE_ACCOUNT_ID` can be set as an environment variable or in the API key credential's `env` object in `auth.json`.
277
-
278
- ```bash
279
- export CLOUDFLARE_API_KEY=... # or use /login
280
- export CLOUDFLARE_ACCOUNT_ID=...
281
- diffex --provider cloudflare-workers-ai --model "@cf/moonshotai/kimi-k2.6"
282
- ```
283
-
284
- Diffex automatically sets `x-session-affinity` for [prefix caching](https://developers.cloudflare.com/workers-ai/features/prompt-caching/) discounts.
285
-
286
- ### Google Vertex AI
287
-
288
- Uses Application Default Credentials:
289
-
290
- ```bash
291
- gcloud auth application-default login
292
- export GOOGLE_CLOUD_PROJECT=your-project
293
- export GOOGLE_CLOUD_LOCATION=us-central1
294
- ```
295
-
296
- Or set `GOOGLE_APPLICATION_CREDENTIALS` to a service account key file.
297
-
298
- ## llama.cpp
299
-
300
- Diffex supports the llama.cpp router server. Configure it with `/login llama.cpp`, manage loaded models with `/llama`, and select a loaded model with `/model`.
301
-
302
- See [llama.cpp](llama-cpp.md) for server setup, model directory layout, environment variables, and command usage.
303
-
304
- ## Custom Providers
305
-
306
- **Via models.json:** Add Ollama, LM Studio, vLLM, or any provider that speaks a supported API (OpenAI Completions, OpenAI Responses, Anthropic Messages, Google Generative AI). See [models.md](models.md).
307
-
308
- **Via extensions:** For providers that need custom API implementations or OAuth flows, create an extension. See [custom-provider.md](custom-provider.md) and [examples/extensions/custom-provider-gitlab-duo](../examples/extensions/custom-provider-gitlab-duo/).
309
-
310
- ## Resolution Order
311
-
312
- When resolving credentials for a provider:
313
-
314
- 1. CLI `--api-key` flag
315
- 2. `auth.json` entry (API key or OAuth token)
316
- 3. Environment variable
317
- 4. Custom provider keys from `models.json`