Skip to content

Commit b97c699

Browse files
authored
Merge pull request #43 from itsflaid/codex/openrouter-provider
Add OpenRouter as an MVP AI provider
2 parents 1c85b12 + 75053a2 commit b97c699

28 files changed

Lines changed: 1091 additions & 118 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ All notable changes to DevMap are documented in this file.
1212

1313
### Added
1414

15+
- OpenRouter provider support with interactive provider selection, API-key
16+
validation, streaming responses, and user-selected free or paid models
1517
- `ts-morph` analysis for JavaScript and TypeScript behind a normalized
1618
analyzer registry with heuristic and fallback analyzers
1719
- Lightweight `.devmap/index.json` and per-feature navigation maps for agents
1820

1921
### Changed
2022

23+
- `devmap init` defaults OpenRouter to `openrouter/free` on Enter and explains
24+
how to change the stored model with `devmap config model <model-id>`
2125
- Feature detection now separates documentation, landing UI, CLI commands,
2226
analysis, snapshot, and AI roles before assigning technical features
2327
- Generated agent guidance now uses index-first navigation and treats the full

PRD.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ Setup wizard. Runs once per machine/project.
265265

266266
- Ask for AI provider
267267
- Ask for API key
268+
- Ask for an OpenRouter model, defaulting to `openrouter/free` on Enter
268269
- Validate API key
269270
- Save global config to `~/.devmap/config.json`
270271
- Create `.devmap/` project folder if needed
@@ -459,7 +460,8 @@ JSON mode rules:
459460
- stdout contains exactly one valid JSON document
460461
- no ANSI colors, Markdown rendering, box drawing, or progress text
461462
- runtime errors use a stable `{ "status": "error", "error": "...", "hint": "..." }` shape
462-
- `init --json` is non-interactive and requires `GROQ_API_KEY` or existing config
463+
- `init --json` is non-interactive and requires `GROQ_API_KEY`,
464+
`OPENROUTER_API_KEY`, or existing config
463465
- AI responses are buffered instead of streamed
464466
- human-readable output remains the default
465467
- package-manager wrappers may still write their own warnings to stderr
@@ -579,16 +581,17 @@ For current project structure, use `.devmap/snapshot.json` if available.
579581

580582
## 11. AI Strategy
581583

582-
### MVP Provider
584+
### MVP Providers
583585

584-
**Groq only.**
586+
**Groq and OpenRouter.**
585587

586588
Reasons:
587589

588590
- Fast inference
589591
- Accessible globally
590592
- User provides their own API key
591593
- No DevMap backend required
594+
- OpenRouter users can choose any model their account can access
592595

593596
### Provider Abstraction
594597

@@ -631,6 +634,13 @@ Model availability changes over time. Before changing the default routing,
631634
verify the current Groq model list and lifecycle status. Preview models must
632635
not be used as a primary default for a public DevMap release.
633636

637+
OpenRouter setup asks for a model ID after validating the API key. Pressing
638+
Enter selects `openrouter/free`; entering another free or paid model stores
639+
that exact model as the user's preferred model. Explicit user selections take
640+
priority and are not replaced by DevMap's Groq routing chain. Users can change
641+
the selection later with `devmap config model <model-id>`; setting `auto` on
642+
OpenRouter restores the safe `openrouter/free` default.
643+
634644
### User API Key Principle
635645

636646
- Users provide their own API keys

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ AI features require a provider API key. DevMap uses Groq by default — analysis
257257
| OpenAI | Planned |
258258
| Gemini | Planned |
259259

260+
`devmap init` lets you choose Groq or OpenRouter with the arrow keys. For
261+
OpenRouter, pressing Enter at `OpenRouter model [openrouter/free]:` keeps the
262+
free router; typing another model ID uses that free or paid model instead.
263+
Change it later with `devmap config model <model-id>`.
264+
260265
API keys are stored locally:
261266

262267
```txt

docs/architecture.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,10 @@ All AI interactions go through a provider abstraction.
608608

609609
Commands should not call provider APIs directly.
610610

611-
### MVP Provider
612-
613-
* Groq
611+
### MVP Providers
612+
613+
* Groq
614+
* OpenRouter
614615

615616
### Future Providers
616617

@@ -649,15 +650,21 @@ on 2026-06-20. Recheck provider lifecycle status before publishing a release.
649650

650651
Users can override automatic routing with `devmap config model <model>`.
651652
Running `devmap config model auto` restores the defaults above.
653+
654+
OpenRouter does not use the Groq command-routing table. During `devmap init`,
655+
Enter accepts `openrouter/free`, while a typed model ID is stored and used
656+
exactly as the user selected it. Explicit OpenRouter model choices receive no
657+
hidden DevMap fallback. The OpenRouter adapter supports the provider's native
658+
ordered `models` request when a caller explicitly supplies fallbacks.
652659

653660
Raw provider errors should not be shown directly to users.
654661

655662
---
656663

657664
## Streaming AI Output
658665

659-
Groq chat completions use server-sent events for human-readable `analyze` and
660-
`ask` output. The provider adapter reconstructs the complete response while
666+
Groq and OpenRouter chat completions use server-sent events for human-readable
667+
`analyze` and `ask` output. Each provider adapter reconstructs the response while
661668
emitting incremental deltas to the output layer.
662669

663670
Terminal Markdown is buffered to paragraph boundaries before rendering. This

docs/commands.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ devmap init
4242

4343
### Responsibilities
4444

45-
* Confirm AI provider
46-
* Input API key or read environment variable
47-
* Validate API key
48-
* Save global configuration to `~/.devmap/config.json`
45+
* Confirm AI provider
46+
* Input API key or read environment variable
47+
* Validate API key
48+
* Ask for an OpenRouter model; Enter defaults to `openrouter/free`
49+
* Save global configuration to `~/.devmap/config.json`
4950
* Detect current project framework
5051
* Create `.devmap/`
5152
* Add `.devmap/` to `.gitignore`
@@ -582,6 +583,16 @@ devmap config model auto
582583
* `analyze` uses `openai/gpt-oss-20b`
583584
* `analyze --deep` uses `openai/gpt-oss-120b`
584585

586+
For OpenRouter, `devmap init` prompts with:
587+
588+
```txt
589+
OpenRouter model [openrouter/free]:
590+
```
591+
592+
Press Enter for the free router, or type any free or paid OpenRouter model ID.
593+
The typed model is stored as the primary choice and is not silently replaced.
594+
`devmap config model auto` restores `openrouter/free` for OpenRouter.
595+
585596
Automatic routing also uses ordered fallback chains:
586597

587598
* `ask`: `qwen/qwen3.6-27b`, `llama-3.3-70b-versatile`, then `openai/gpt-oss-20b`
@@ -646,8 +657,8 @@ Contract:
646657
* progress sections and Markdown rendering are omitted
647658
* AI responses are buffered instead of streamed
648659
* runtime failures return a JSON object with `status`, `error`, and optional `hint`
649-
* `init --json` never prompts and therefore requires `GROQ_API_KEY` or an
650-
existing API key
660+
* `init --json` never prompts and therefore requires `GROQ_API_KEY`,
661+
`OPENROUTER_API_KEY`, or an existing API key
651662
* package-manager wrapper warnings may appear on stderr and are not part of the
652663
DevMap JSON document
653664

docs/for-me-personal/PROGRESS.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ Terakhir diperbarui: 2026-06-20
44

55
## Update 2026-06-20
66

7+
### OpenRouter MVP Provider
8+
9+
- `devmap init` sekarang menampilkan selector panah untuk Groq dan OpenRouter.
10+
- Setup OpenRouter memvalidasi API key lalu meminta model dengan default
11+
`openrouter/free` ketika user langsung menekan Enter.
12+
- Model OpenRouter yang diketik user, baik gratis maupun berbayar, disimpan dan
13+
selalu diprioritaskan tanpa hidden fallback dari DevMap.
14+
- `devmap config model <model-id>` dapat mengganti pilihan; `auto` pada
15+
OpenRouter kembali ke `openrouter/free`.
16+
- `ask`, `analyze`, dan `doctor` sekarang memakai provider factory berdasarkan
17+
config, bukan membuat Groq client secara langsung.
18+
- OpenRouter completion, streaming SSE, usage normalization, validasi key, dan
19+
native ordered `models` request sudah memiliki regression tests.
20+
- Focused tests dan full CLI unit suite lulus dengan 116 test.
21+
722
### Standalone React Detection
823

924
- Framework detector sekarang mengenali standalone React dari dependency

docs/for-me-personal/TEST.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,43 @@ Ada beberapa versi DevMap yang dapat diuji:
1515
| npm link | CLI global sementara | Menguji command `devmap` dari folder mana pun |
1616
| CI/runtime | OS dan versi Node berbeda | Verifikasi lintas platform sebelum release |
1717

18+
## OpenRouter Provider
19+
20+
Focused automated tests:
21+
22+
```powershell
23+
pnpm --filter devmap exec tsx --test test/init-and-errors.test.ts test/openrouter-client.test.ts test/doctor.test.ts
24+
```
25+
26+
Manual source test sebaiknya dijalankan dari project fixture atau project luar,
27+
karena `init` menulis `.devmap/`, `DEVMAP.md`, dan kemungkinan `AGENTS.md`:
28+
29+
```powershell
30+
pnpm dev:cli -- init
31+
```
32+
33+
Expected interactive flow:
34+
35+
1. Pilih `OpenRouter` dengan tombol panah lalu tekan Enter.
36+
2. Masukkan OpenRouter API key; key tidak boleh dicetak ulang.
37+
3. Pada `OpenRouter model [openrouter/free]:`, tekan Enter untuk free router
38+
atau ketik model ID gratis/berbayar yang ingin diuji.
39+
4. Pastikan output menjelaskan command
40+
`devmap config model <model-id>` untuk mengganti model nanti.
41+
5. Jalankan `devmap doctor`, `devmap analyze`, dan `devmap ask` lalu pastikan
42+
provider serta model yang tampil sesuai config.
43+
44+
Non-interactive setup dapat memakai:
45+
46+
```powershell
47+
$env:OPENROUTER_API_KEY="your-key"
48+
pnpm dev:cli -- init --json
49+
Remove-Item Env:OPENROUTER_API_KEY
50+
```
51+
52+
Jangan simpan atau menyalin API key nyata ke repository, snapshot, output test,
53+
atau dokumentasi debugging.
54+
1855
## Ts-Morph Dan Agent Navigation
1956

2057
Focused tests:

docs/roadmap.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ adding AI on top. If the foundation is wrong, AI output will be wrong too.
3333
**Goal:** Users can understand projects faster with AI interpretation.
3434

3535
**Tasks:**
36-
- Groq integration with provider abstraction layer
36+
- Groq and OpenRouter integration through the provider abstraction layer
3737
- Prompt templates for analyze and ask
3838
- Context Builder — keyword search + file ranking
3939
- [x] Streaming output for human `analyze` and `ask` responses
@@ -87,12 +87,12 @@ accuracy must be near 100% or developers won't trust it.
8787
---
8888

8989
## Phase 5 — Multi-Provider
90-
**Goal:** Users can choose their preferred AI provider.
90+
**Goal:** Expand beyond the Groq and OpenRouter MVP providers.
9191

9292
**Tasks:**
9393
- OpenAI adapter (GPT-4o mini as default)
9494
- Gemini adapter (1.5 Flash as default)
95-
- Provider selection in `devmap init`
95+
- [x] Provider selection in `devmap init` for Groq and OpenRouter
9696
- Per-project provider override in `.devmap/config.json`
9797
- Provider-specific model recommendations
9898

packages/cli/README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Understand any codebase in minutes, not days.
44

5-
DevMap is a CLI that combines static analysis with optional Groq-powered
5+
DevMap is a CLI that combines static analysis with optional AI-powered
66
interpretation. It maps project structure, generates reusable context, and
77
answers focused questions without sending an entire repository to an AI model.
88

@@ -23,7 +23,7 @@ npx devmap --help
2323
## Requirements
2424

2525
- Node.js 18 or newer
26-
- A Groq API key for AI-powered analysis and answers
26+
- A Groq or OpenRouter API key for AI-powered analysis and answers
2727

2828
Static analysis still works when AI is not configured.
2929

@@ -39,18 +39,30 @@ devmap onboarding
3939
devmap doctor
4040
```
4141

42-
`devmap init` validates the Groq key, stores configuration locally, prepares
42+
`devmap init` selects a provider, validates its key, stores configuration locally, prepares
4343
`.devmap/`, generates `DEVMAP.md`, and integrates with `AGENTS.md` safely.
4444

45-
## Groq Setup
45+
## AI Provider Setup
4646

47-
Create a key at https://console.groq.com/keys, then either enter it during:
47+
Choose Groq or OpenRouter with the arrow keys during:
4848

4949
```bash
5050
devmap init
5151
```
5252

53-
Or provide it to the current shell before non-interactive setup:
53+
Groq keys are available at https://console.groq.com/keys. OpenRouter keys are
54+
available at https://openrouter.ai/keys.
55+
56+
For OpenRouter, DevMap prompts:
57+
58+
```txt
59+
OpenRouter model [openrouter/free]:
60+
```
61+
62+
Press Enter to use the free router, or type any free or paid OpenRouter model
63+
ID. The selected model is saved and used as the primary choice.
64+
65+
For non-interactive Groq setup:
5466

5567
```bash
5668
GROQ_API_KEY="your-key" devmap init
@@ -64,8 +76,15 @@ devmap init
6476
Remove-Item Env:GROQ_API_KEY
6577
```
6678

79+
For non-interactive OpenRouter setup:
80+
81+
```bash
82+
OPENROUTER_API_KEY="your-key" devmap init
83+
```
84+
6785
The key is stored locally in `~/.devmap/config.json`. Requests go directly from
68-
your machine to Groq. DevMap does not send the key to a DevMap-owned server.
86+
your machine to the selected provider. DevMap does not send the key to a
87+
DevMap-owned server.
6988

7089
## Commands
7190

@@ -81,11 +100,12 @@ devmap doctor
81100
devmap config model auto
82101
```
83102

84-
Automatic model routing uses a fast model for focused questions and larger
85-
models for architecture analysis. Override it with:
103+
Groq automatic routing uses a fast model for focused questions and larger
104+
models for architecture analysis. OpenRouter uses the model selected during
105+
init. Change either provider's model with:
86106

87107
```bash
88-
devmap config model <groq-model-id>
108+
devmap config model <model-id>
89109
devmap config model auto
90110
```
91111

@@ -131,7 +151,7 @@ support promise.
131151
## Privacy
132152

133153
- Project analysis runs locally before AI interpretation.
134-
- Full repository source is not sent to Groq.
154+
- Full repository source is not sent to the selected provider.
135155
- `ask` selects a small set of relevant files.
136156
- `.env` files and common generated directories are ignored.
137157
- API keys are stored locally and should never be committed.

packages/cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"developer-tools",
3131
"static-analysis",
3232
"architecture",
33-
"groq"
33+
"groq",
34+
"openrouter"
3435
],
3536
"author": "Muhammad Fadil",
3637
"license": "MIT",

0 commit comments

Comments
 (0)