@legioncodeinc/rflectr 0.1.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.
Files changed (69) hide show
  1. package/.markdown-link-check.json +7 -0
  2. package/AGENTS.md +169 -0
  3. package/LICENSE +661 -0
  4. package/README.md +612 -0
  5. package/assets/733630021_1421561133353555_3999689754075308337_n.jpg +0 -0
  6. package/assets/github-home-image.png +0 -0
  7. package/assets/og-image.jpg +0 -0
  8. package/assets/og-image.png +0 -0
  9. package/assets/og-image.psd +0 -0
  10. package/assets/rflectr-no-bg.png +0 -0
  11. package/assets/vertex-models.example.json +14 -0
  12. package/dist/cli.js +15708 -0
  13. package/library/README.md +39 -0
  14. package/library/issues/README.md +46 -0
  15. package/library/issues/backlog/README.md +26 -0
  16. package/library/issues/completed/README.md +13 -0
  17. package/library/issues/in-work/README.md +13 -0
  18. package/library/knowledge/README.md +34 -0
  19. package/library/knowledge/private/README.md +40 -0
  20. package/library/knowledge/private/ai/README.md +8 -0
  21. package/library/knowledge/private/ai/model-discovery-classification.md +81 -0
  22. package/library/knowledge/private/ai/translation-layer.md +88 -0
  23. package/library/knowledge/private/architecture/README.md +10 -0
  24. package/library/knowledge/private/architecture/launch-flow-claude.md +93 -0
  25. package/library/knowledge/private/architecture/system-overview.md +108 -0
  26. package/library/knowledge/private/auth/README.md +9 -0
  27. package/library/knowledge/private/auth/oauth-device-flows.md +95 -0
  28. package/library/knowledge/private/data/README.md +8 -0
  29. package/library/knowledge/private/data/preferences-config.md +87 -0
  30. package/library/knowledge/private/data/provider-registry.md +126 -0
  31. package/library/knowledge/private/infrastructure/README.md +7 -0
  32. package/library/knowledge/private/infrastructure/server-gateway.md +87 -0
  33. package/library/knowledge/private/integrations/README.md +8 -0
  34. package/library/knowledge/private/integrations/harnesses.md +87 -0
  35. package/library/knowledge/private/integrations/local-proxy.md +82 -0
  36. package/library/knowledge/private/security/README.md +9 -0
  37. package/library/knowledge/private/security/credential-storage.md +129 -0
  38. package/library/knowledge/private/standards/documentation-framework.md +154 -0
  39. package/library/knowledge/public/README.md +49 -0
  40. package/library/knowledge/public/faqs/README.md +7 -0
  41. package/library/knowledge/public/faqs/troubleshooting.md +92 -0
  42. package/library/knowledge/public/guides/README.md +13 -0
  43. package/library/knowledge/public/guides/ai-agents.md +273 -0
  44. package/library/knowledge/public/guides/api-server.md +108 -0
  45. package/library/knowledge/public/guides/claude-desktop.md +382 -0
  46. package/library/knowledge/public/guides/codex.md +296 -0
  47. package/library/knowledge/public/guides/gemini-cli.md +105 -0
  48. package/library/knowledge/public/guides/model-compatibility.md +80 -0
  49. package/library/knowledge/public/guides/providers.md +90 -0
  50. package/library/knowledge/public/overview/README.md +7 -0
  51. package/library/knowledge/public/overview/what-is-rflectr.md +71 -0
  52. package/library/notes/README.md +21 -0
  53. package/library/requirements/README.md +51 -0
  54. package/library/requirements/backlog/README.md +30 -0
  55. package/library/requirements/completed/README.md +14 -0
  56. package/library/requirements/completed/prd-001-cli-core-launch-orchestration/prd-001-cli-core-launch-orchestration-index.md +205 -0
  57. package/library/requirements/completed/prd-001-cli-core-launch-orchestration/qa/.gitkeep +0 -0
  58. package/library/requirements/completed/prd-002-provider-registry/qa/.gitkeep +0 -0
  59. package/library/requirements/completed/prd-003-model-discovery-classification/qa/.gitkeep +0 -0
  60. package/library/requirements/completed/prd-004-translation-layer/qa/.gitkeep +0 -0
  61. package/library/requirements/completed/prd-005-local-proxy-catalog-routing/qa/.gitkeep +0 -0
  62. package/library/requirements/completed/prd-007-oauth-device-flows/qa/.gitkeep +0 -0
  63. package/library/requirements/completed/prd-011-claude-desktop-integration/qa/.gitkeep +0 -0
  64. package/library/requirements/in-work/README.md +19 -0
  65. package/library/requirements/reports/README.md +31 -0
  66. package/package.json +84 -0
  67. package/scripts/refresh-models-dev-cache.mjs +34 -0
  68. package/test-proxy.ts +19 -0
  69. package/test-split.js +1 -0
@@ -0,0 +1,273 @@
1
+ # AI Agents & Automation
2
+
3
+ > Category: Guide | Version: 1.0 | Date: June 2026 | Status: Active
4
+
5
+ rflectr is built so **AI agents** (scripts, CI, alef-agent, Cursor subagents, …) can launch Claude Code, OpenAI Codex, or Google Gemini CLI against your provider registry **without interactive wizards**, with **clean machine-readable stdout** when needed.
6
+
7
+ For the full machine-readable reference — including your live provider/model list — run:
8
+
9
+ ```bash
10
+ rflectr --ai
11
+ rflectr --ai --install # install SKILL.md to agent skill dirs
12
+ ```
13
+
14
+ ---
15
+
16
+ ## Quick reference
17
+
18
+ | Goal | Command |
19
+ |---|---|
20
+ | Agent reference | `rflectr --ai` |
21
+ | Install agent skill | `rflectr --ai --install` |
22
+ | Claude one-shot (text) | `rflectr claude --provider <id> --model <id> -p "prompt"` |
23
+ | Claude NDJSON stream | `rflectr claude --provider <id> --model <id> -p "…" --output-format stream-json` |
24
+ | Codex one-shot (text) | `rflectr codex --provider <id> --model <id> exec "prompt"` |
25
+ | Codex JSONL events | `rflectr codex --provider <id> --model <id> exec --json "prompt"` |
26
+ | Gemini one-shot (text) | `rflectr gemini --provider <id> --model <id> -p "prompt"` |
27
+ | Gemini NDJSON stream | `rflectr gemini --provider <id> --model <id> -p "…" -o stream-json` |
28
+ | Model slug | `--model zen__deepseek-v4-flash-free` (= `--provider zen --model deepseek-v4-flash-free`) |
29
+ | List providers/models | `rflectr providers list` or read `~/.rflectr/providers.json` |
30
+
31
+ ---
32
+
33
+ ## Boot flags (`--provider` / `--model`)
34
+
35
+ rflectr consumes these flags **before** spawning the child. They are **not** passed through.
36
+
37
+ | Flag | Purpose |
38
+ |---|---|
39
+ | `--provider <id>` | Registry provider id (`groq`, `google`, `zen`, `go`, …). |
40
+ | `--model <id>` | Model id from that provider's cache. |
41
+ | `--model <provider>__<model-id>` | Slug form — provider embedded in the model string. |
42
+
43
+ ### When the wizard is skipped
44
+
45
+ - **Claude (`rflectr claude`):** both `--provider` and `--model` set, **or** print mode (`-p` / `--print`) with saved prefs from a prior interactive launch.
46
+ - **Codex (`rflectr codex`):** both flags set, **or** non-interactive args (`exec` or a positional prompt) with saved prefs.
47
+ - **Gemini (`rflectr gemini`):** both flags set, **or** non-interactive args (`-p`, `-i`, or a positional query) with saved prefs.
48
+
49
+ > In CI / headless loops, **always pass `--provider` and `--model`** — never rely on saved prefs alone.
50
+
51
+ ### Examples
52
+
53
+ ```bash
54
+ # Claude — explicit boot
55
+ rflectr claude --provider groq --model llama-3.3-70b-versatile -p "Summarize README.md"
56
+ # Claude — slug
57
+ rflectr claude --model zen__deepseek-v4-flash-free -p "Review this diff"
58
+
59
+ # Codex — explicit boot
60
+ rflectr codex --provider openai --model gpt-5.4 exec "implement feature X"
61
+ # Codex — slug
62
+ rflectr codex --model zen__deepseek-v4-flash-free exec "fix the test"
63
+
64
+ # Gemini — explicit boot
65
+ rflectr gemini --provider google --model gemini-2.5-flash -p "Review this file"
66
+ # Gemini — slug
67
+ rflectr gemini --model zen__deepseek-v4-flash-free -p "Refactor the module"
68
+ ```
69
+
70
+ ---
71
+
72
+ ## Clean stdout for NDJSON / JSONL
73
+
74
+ When an agent parses **every line on stdout as JSON**, rflectr must not print boot UI (intro, spinner, proxy banners) on stdout. It detects machine-readable mode and **suppresses all boot UI on stdout** — messages still go to **stderr**.
75
+
76
+ | Agent | Trigger | Child output |
77
+ |---|---|---|
78
+ | Claude | `-p` + `--output-format stream-json` or `json` | NDJSON (one object per line) |
79
+ | Claude | `-p` + `--input-format stream-json` | NDJSON |
80
+ | Codex | `exec --json` | JSONL event stream |
81
+ | Gemini | `-p` + `-o stream-json` or `json` | NDJSON |
82
+
83
+ > **Claude `--verbose`** is required by Claude Code for `stream-json` in print mode. rflectr **auto-adds `--verbose`** when it's missing.
84
+
85
+ **Verify clean stdout:**
86
+
87
+ ```bash
88
+ rflectr claude --provider zen --model deepseek-v4-flash-free \
89
+ -p "PONG" --output-format stream-json 2>/dev/null \
90
+ | node -e "process.stdin.on('data',d=>d.toString().split('\n').filter(Boolean).forEach(l=>JSON.parse(l))); console.log('ok')"
91
+ ```
92
+
93
+ Interactive TTY launches (`rflectr claude` with no `-p`) still show the normal human UI.
94
+
95
+ ---
96
+
97
+ ## Codex sandbox (network for shell tools)
98
+
99
+ `rflectr codex` defaults to **`danger-full-access`** — written into the launch profile (`sandbox = "danger-full-access"`) and passed on spawn as `-s danger-full-access` (needed on macOS even when in the profile). This lets Codex shell tools reach the network (`curl`, `nlm`, npm, MCP CLIs).
100
+
101
+ ```bash
102
+ rflectr codex -s workspace-write exec "task" # override for one session
103
+ rflectr codex --dangerously-bypass-approvals-and-sandbox exec "x" # bypass entirely (Codex flag)
104
+ ```
105
+
106
+ `rflectr codex-app` does **not** change your personal `~/.codex/config.toml` sandbox. See [Codex § Sandbox](codex.md#sandbox-and-network-cli).
107
+
108
+ ---
109
+
110
+ ## Provider discovery
111
+
112
+ **Machine-readable catalog (recommended for agents):**
113
+
114
+ ```text
115
+ ~/.rflectr/providers.json
116
+ → providers[].id
117
+ → providers[].modelsCache.models[].id
118
+ → providers[].enabled
119
+ ```
120
+
121
+ ```bash
122
+ rflectr providers refresh-models # refresh all stale lists
123
+ rflectr providers refresh-models groq # refresh one provider
124
+ ```
125
+
126
+ **Built-in cloud providers** (not in `providers.json`): `zen` and `go`, both requiring `OPENCODE_API_KEY`.
127
+
128
+ **Preview without launching:**
129
+
130
+ ```bash
131
+ rflectr claude --dry-run --provider groq --model llama-3.3-70b-versatile
132
+ rflectr codex --config --provider zen --model deepseek-v4-flash-free
133
+ ```
134
+
135
+ ---
136
+
137
+ ## Tool calling & MCP
138
+
139
+ **Claude Code** — pass tool flags **after** rflectr's boot flags (they go to Claude):
140
+
141
+ ```bash
142
+ rflectr claude --provider google --model gemini-2.5-flash \
143
+ -p "How many notebooks?" \
144
+ --output-format stream-json \
145
+ --allowed-tools mcp__notebooklm-mcp__notebook_list
146
+ ```
147
+
148
+ **Codex** — MCP servers come from your Codex config (`~/.codex/config.toml`), not rflectr. With default `danger-full-access`, network-blocked MCP/CLI errors should be resolved; MCP must still be configured in Codex.
149
+
150
+ ---
151
+
152
+ ## Multi-model agent loops
153
+
154
+ ```bash
155
+ for model in llama-3.3-70b-versatile mixtral-8x7b-32768; do
156
+ rflectr claude --provider groq --model "$model" -p "Same prompt for all models"
157
+ done
158
+
159
+ for model in deepseek-v4-flash-free qwen3.6-plus-free; do
160
+ rflectr codex --provider zen --model "$model" exec --json "Same task"
161
+ done
162
+
163
+ for model in gemini-2.5-flash gemini-2.5-pro; do
164
+ rflectr gemini --provider google --model "$model" -p "Same task"
165
+ done
166
+ ```
167
+
168
+ Boot flags use **single-model launch** (the favorites catalog is skipped) — better for one-shot jobs. Use `rflectr models` + interactive launch for mid-session `/model` switching.
169
+
170
+ ---
171
+
172
+ ## Zen / Go cloud providers
173
+
174
+ For Claude `-p` and Codex `exec` against OpenCode Zen or Go:
175
+
176
+ - Pass `--provider zen` or `--provider go` explicitly in agent configs.
177
+ - Ensure `OPENCODE_API_KEY` is in the environment or OS keychain (rflectr resolves it before launch).
178
+
179
+ ---
180
+
181
+ ## Codex proxy notes (DeepSeek / reasoning models)
182
+
183
+ Non-OpenAI models routed through rflectr's Codex proxy use the Responses API adapter. **Reasoning content** from thinking models (e.g. DeepSeek) is round-tripped on tool loops, so turn 2+ doesn't fail with missing `reasoning_content`.
184
+
185
+ ---
186
+
187
+ ## alef-agent integration
188
+
189
+ alef-agent shells out to CLI backends and parses **NDJSON/JSONL on stdout**. Use rflectr as the **wrapper executable** with boot flags prepended.
190
+
191
+ **Claude backend (stream-json):**
192
+
193
+ ```bash
194
+ rflectr claude --provider <id> --model <id> -p "<prompt>" \
195
+ --output-format stream-json [--verbose] \
196
+ [--max-turns, --permission-mode, --allowed-tools, …]
197
+ ```
198
+
199
+ **Codex backend (exec --json):**
200
+
201
+ ```bash
202
+ rflectr codex --provider <id> --model <id> exec --json "<prompt>" [codex flags]
203
+ ```
204
+
205
+ **Gemini backend (stream-json):**
206
+
207
+ ```bash
208
+ rflectr gemini --provider <id> --model <id> -p "<prompt>" -o stream-json [gemini flags]
209
+ ```
210
+
211
+ ### Checklist
212
+
213
+ 1. **Executable:** `rflectr` on `PATH` (`npm link` after dev builds).
214
+ 2. **Always set** `--provider` + `--model` (or a slug on `--model`).
215
+ 3. **Claude:** use `--output-format stream-json`; rflectr adds `--verbose` if needed.
216
+ 4. **Codex:** use `exec --json` — **not** `-p` (in Codex, `-p` means profile).
217
+ 5. **Gemini:** use `-o stream-json` or `-o json` with `-p`.
218
+ 6. **Parse stdout only** — boot/errors go to stderr in machine-readable mode.
219
+ 7. **Codex network:** the default sandbox is already full access; no extra `-s` needed.
220
+ 8. **Discovery:** run `rflectr --ai` or read `providers.json` to populate model lists.
221
+ 9. **Skill:** `rflectr --ai --install` drops `rflectr-cli/SKILL.md` into agent skill dirs.
222
+
223
+ ### Stdout contract
224
+
225
+ ```text
226
+ stderr → rflectr boot/errors (safe to log; ignore for parsing)
227
+ stdout → child NDJSON/JSONL only (when stream-json / exec --json)
228
+ exit → rflectr exit code (non-zero on launch/config errors)
229
+ ```
230
+
231
+ The full alef section is also embedded at the bottom of `rflectr --ai`.
232
+
233
+ ---
234
+
235
+ ## Agent rules of thumb
236
+
237
+ **Do:**
238
+
239
+ - Run `rflectr --ai` when unsure.
240
+ - Use `--provider` + `--model` for every headless invocation.
241
+ - Use Claude `-p` / Codex `exec` for one-shots that must exit.
242
+ - Read `providers.json` for authoritative model ids.
243
+ - Send machine-readable flags so stdout stays parseable.
244
+
245
+ **Don't:**
246
+
247
+ - Rely on interactive wizards in CI or agent loops.
248
+ - Pass `--provider` / `--model` to Claude/Codex/Gemini directly — rflectr consumes them.
249
+ - Use Codex `-p` for print mode (it's `--profile` in Codex).
250
+ - Expect the favorites catalog in print/exec mode — use explicit boot flags.
251
+ - Edit `~/.claude/settings.json`, `~/.gemini/config/config.json`, or `~/.codex/config.toml` from rflectr — it uses env + temporary overlays.
252
+
253
+ ---
254
+
255
+ ## Troubleshooting (agents)
256
+
257
+ | Symptom | Fix |
258
+ |---|---|
259
+ | JSON parse error on first stdout lines | Missing `--output-format stream-json` (Claude) or `exec --json` (Codex). |
260
+ | `Print mode requires --provider and --model` | Add boot flags, or run interactive once to save prefs. |
261
+ | `requires an interactive terminal` (Codex) | Add `--provider` and `--model`. |
262
+ | Zen/Go "Not logged in" | Set `OPENCODE_API_KEY`; pass `--provider zen` explicitly. |
263
+ | Codex shell network blocked | Should be default; confirm `rflectr codex --config` shows `sandbox = "danger-full-access"`. |
264
+ | DeepSeek tool loop 400 | Update rflectr — reasoning round-trip fix in the Codex proxy. |
265
+ | Stale overlay after crash | `rflectr codex --restore`. |
266
+
267
+ See [Troubleshooting](../faqs/troubleshooting.md) for general rflectr issues.
268
+
269
+ ---
270
+
271
+ ## Related guides
272
+
273
+ - [Codex](codex.md) · [Gemini CLI](gemini-cli.md) · [Providers](providers.md) · [Troubleshooting](../faqs/troubleshooting.md)
@@ -0,0 +1,108 @@
1
+ # API Server
2
+
3
+ > Category: Guide | Version: 1.0 | Date: June 2026 | Status: Active
4
+
5
+ `rflectr server` runs a local gateway that bridges your model backends (OpenCode Zen, Go, registry providers, or Vertex AI) to any client that speaks the Anthropic or OpenAI API. Both formats are served on one port.
6
+
7
+ ---
8
+
9
+ ## Start the server
10
+
11
+ ```bash
12
+ rflectr server # registry / Zen / Go providers
13
+ rflectr server --vertex # Claude on Google Vertex AI via gcloud ADC
14
+ ```
15
+
16
+ The server runs an interactive wizard (password setup, which providers to expose, optional favorites-only catalog, discovery-id masking) and then listens. Default port: **17645**.
17
+
18
+ ```text
19
+ Rflectr server running
20
+ Anthropic: http://127.0.0.1:17645/anthropic
21
+ OpenAI: http://127.0.0.1:17645/openai/v1
22
+ Network (en0):
23
+ Anthropic: http://192.168.68.70:17645/anthropic
24
+ OpenAI: http://192.168.68.70:17645/openai/v1
25
+ API key: saved, rotate with `rflectr server --setup`
26
+ Catalog: favorite models only
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Reading the model catalog
32
+
33
+ On startup the server prints every exposed model with **two identifiers**:
34
+
35
+ ```text
36
+ Google Gemini
37
+ gemini-3.5-flash
38
+ anthropic: anthropic-google__gemini-3.5-flash
39
+ openai: gemini-3.5-flash
40
+
41
+ OpenCode Go
42
+ Kimi K2.7 Code
43
+ anthropic: anthropic-go__kimi-k2.7-code
44
+ openai: kimi-k2.7-code
45
+ ```
46
+
47
+ | Identifier | Use it when your client expects… |
48
+ |---|---|
49
+ | `anthropic:` | Anthropic-format requests (Anthropic SDK, Claude Code, Claude Desktop). |
50
+ | `openai:` | OpenAI-format requests (OpenAI SDK, OpenAI-compatible extensions). |
51
+
52
+ ---
53
+
54
+ ## Endpoints
55
+
56
+ | Method + path | Purpose |
57
+ |---|---|
58
+ | `GET /health` | Liveness check. |
59
+ | `GET /anthropic/v1/models` · `GET /openai/v1/models` | List exposed models. |
60
+ | `POST /anthropic/v1/messages` | Anthropic Messages relay. |
61
+ | `POST /openai/v1/chat/completions` | OpenAI Chat Completions relay. |
62
+
63
+ Base URLs for clients:
64
+
65
+ - **Anthropic:** `http://127.0.0.1:17645/anthropic`
66
+ - **OpenAI:** `http://127.0.0.1:17645/openai/v1`
67
+
68
+ > ⚠️ **Do not append `/v1` to the Anthropic base URL** — the Anthropic SDK adds API paths itself.
69
+
70
+ ---
71
+
72
+ ## Connecting a client
73
+
74
+ Most OpenAI-compatible tools just need a base URL and (optionally) the server password as the API key. Example — **[THE AI Counsel](https://github.com/legioncodeinc/the-ai-counsel)**:
75
+
76
+ 1. Open **Settings → LLM API Keys → Custom OpenAI-Compatible Endpoint**.
77
+ 2. **Display Name:** anything descriptive (e.g. `Rflectr Server`).
78
+ 3. **Base URL:**
79
+ - Same machine: `http://127.0.0.1:17645/openai/v1`
80
+ - Another device on your LAN: `http://<server-ip>:17645/openai/v1` (use an IP printed at startup).
81
+ 4. **API Key:** the server password if one is set, otherwise leave empty.
82
+ 5. Click **Connect** to fetch the gateway's models.
83
+
84
+ ---
85
+
86
+ ## Vertex AI mode
87
+
88
+ `rflectr server --vertex` exposes Claude on Google Vertex AI using your local `gcloud` Application Default Credentials — no OpenCode key needed.
89
+
90
+ | Env var | Purpose |
91
+ |---|---|
92
+ | `ANTHROPIC_VERTEX_PROJECT_ID` or `GOOGLE_CLOUD_PROJECT` | Your GCP project. |
93
+ | `GOOGLE_CLOUD_LOCATION` or `CLOUD_ML_REGION` | Region (default `global`). |
94
+
95
+ Optional model catalog override: `~/.rflectr/vertex-models.json` (see `assets/vertex-models.example.json`).
96
+
97
+ ---
98
+
99
+ ## Auth
100
+
101
+ - **Local mode:** any non-empty bearer token / `x-api-key` works.
102
+ - **Network mode:** the wizard sets a **server password** — it's the only gate once the port is reachable beyond localhost, so treat it as a secret.
103
+
104
+ ---
105
+
106
+ ## Related guides
107
+
108
+ - [Claude Desktop setup](claude-desktop.md) (uses this gateway) · [Providers](providers.md) · [Troubleshooting](../faqs/troubleshooting.md)