@hegemonart/get-design-done 1.33.0 → 1.33.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 (47) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +49 -0
  4. package/README.md +4 -0
  5. package/SKILL.md +1 -0
  6. package/agents/design-authority-watcher.md +4 -0
  7. package/connections/connections.md +2 -0
  8. package/connections/openrouter.md +86 -0
  9. package/hooks/budget-enforcer.ts +103 -0
  10. package/package.json +5 -2
  11. package/reference/gdd-runtime-audit.md +111 -0
  12. package/reference/gdd-threat-model.md +399 -0
  13. package/reference/openrouter-tier-mapping.md +98 -0
  14. package/reference/prices.openrouter.md +26 -0
  15. package/reference/registry.json +28 -0
  16. package/scripts/lib/authority-watcher/index.cjs +147 -0
  17. package/scripts/lib/budget-enforcer.cjs +16 -0
  18. package/scripts/lib/openrouter/catalog-fetcher.cjs +326 -0
  19. package/scripts/lib/peer-cli/acp-client.cjs +9 -1
  20. package/scripts/lib/peer-cli/asp-client.cjs +10 -1
  21. package/scripts/lib/peer-cli/sanitize-env.cjs +198 -0
  22. package/scripts/lib/redact.cjs +20 -1
  23. package/scripts/lib/tier-resolver-openrouter.cjs +343 -0
  24. package/scripts/lib/transports/ws.cjs +67 -3
  25. package/sdk/event-stream/types.ts +24 -2
  26. package/sdk/mcp/gdd-state/schemas/add_blocker.schema.json +2 -0
  27. package/sdk/mcp/gdd-state/schemas/add_decision.schema.json +1 -0
  28. package/sdk/mcp/gdd-state/schemas/add_must_have.schema.json +1 -0
  29. package/sdk/mcp/gdd-state/schemas/checkpoint.schema.json +1 -0
  30. package/sdk/mcp/gdd-state/schemas/frontmatter_update.schema.json +1 -1
  31. package/sdk/mcp/gdd-state/schemas/get.schema.json +2 -1
  32. package/sdk/mcp/gdd-state/schemas/probe_connections.schema.json +2 -0
  33. package/sdk/mcp/gdd-state/schemas/resolve_blocker.schema.json +1 -0
  34. package/sdk/mcp/gdd-state/server.js +137 -48
  35. package/sdk/mcp/gdd-state/tools/add_blocker.ts +2 -0
  36. package/sdk/mcp/gdd-state/tools/add_decision.ts +2 -0
  37. package/sdk/mcp/gdd-state/tools/add_must_have.ts +2 -0
  38. package/sdk/mcp/gdd-state/tools/checkpoint.ts +2 -0
  39. package/sdk/mcp/gdd-state/tools/frontmatter_update.ts +2 -0
  40. package/sdk/mcp/gdd-state/tools/get.ts +2 -0
  41. package/sdk/mcp/gdd-state/tools/probe_connections.ts +2 -0
  42. package/sdk/mcp/gdd-state/tools/resolve_blocker.ts +2 -0
  43. package/sdk/mcp/gdd-state/tools/set_status.ts +2 -0
  44. package/sdk/mcp/gdd-state/tools/shared.ts +117 -7
  45. package/sdk/mcp/gdd-state/tools/transition_stage.ts +2 -0
  46. package/sdk/mcp/gdd-state/tools/update_progress.ts +2 -0
  47. package/skills/openrouter-status/SKILL.md +86 -0
@@ -0,0 +1,399 @@
1
+ # GDD Runtime Threat Model (STRIDE)
2
+
3
+ > Phase 33.5 · SEC-01 · STRIDE pass over GDD's **own** runtime attack surface.
4
+ > Generated against branch `phase/33-5-runtime-security`, HEAD `5374bed`.
5
+
6
+ ## Scope
7
+
8
+ This document models the security posture of **GDD's own runtime** — the
9
+ multi-MCP-server, peer-CLI-spawning, WebSocket-emitting SDK that grew across
10
+ Phases 20–27 without a formalized security model. It does **NOT** model the
11
+ user code that GDD audits; the safety floor for *audited user code* is Phase
12
+ 14.5's concern. This is the equivalent threat model for GDD's *own* moving
13
+ parts: the hooks that run on every session start, the two MCP servers that
14
+ read and mutate `STATE.md`, the broker that spawns peer CLIs, the WebSocket
15
+ transport that streams the event bus, and the issue-reporter that reaches the
16
+ network through `gh`.
17
+
18
+ **STRIDE** is the Microsoft threat taxonomy used throughout: **S**poofing
19
+ (pretending to be someone/something you are not), **T**ampering (unauthorized
20
+ modification of data or code), **R**epudiation (denying an action with no
21
+ audit trail), **I**nformation disclosure (leaking data to the wrong party),
22
+ **D**enial of service (exhausting a resource so legitimate use fails), and
23
+ **E**levation of privilege (gaining capabilities you were not granted).
24
+
25
+ Each of the five in-scope components below gets a fixed five-part treatment:
26
+ **Assets** (what an attacker wants), **Entry points** (the untrusted-input
27
+ boundary), **STRIDE threats** (which categories apply), **Current mitigations**
28
+ (citing **real shipped code** — file + line + behavior), and **Residual risks**
29
+ (threats current code does **not** fully cover, each routed to the Phase 33.5
30
+ plan that closes it). Out of scope per CONTEXT: rewriting the issue-reporter
31
+ network model — it is **documented** here as already-mitigated, not
32
+ re-engineered.
33
+
34
+ ## Trust boundaries
35
+
36
+ The runtime crosses four trust boundaries. On the untrusted side of each sits
37
+ input that an attacker (or a compromised peer / config author / network host)
38
+ controls; the table names what crosses the line.
39
+
40
+ | Boundary | Untrusted side | What crosses |
41
+ | --- | --- | --- |
42
+ | WS event-stream server `←` client | A WebSocket client on the network (LAN/internet if bound wide) | The HTTP `Upgrade` request + `Authorization: Bearer` header |
43
+ | gdd-state MCP `←` environment / config / tool input | Whoever sets `GDD_STATE_PATH` or supplies a tool-call payload, or authors `.design/config.json` | The `GDD_STATE_PATH` env value + the JSON tool-input payloads |
44
+ | Peer-CLI broker `↔` spawned child | A spawned peer CLI (Codex / Gemini / Cursor / Copilot / Qwen) and its stdout stream | The child's stdout JSON frames + the parent env handed to the child |
45
+ | Outbound call sites `↔` external host | The remote HTTP host / GitHub / Figma the call reaches | The outbound request payload + whatever the remote returns |
46
+ | OpenRouter catalog fetch `→` openrouter.ai | The OpenRouter `/models` API host (and any MITM on the path) | The `Authorization: Bearer <OPENROUTER_API_KEY>` request header + the untrusted `/models` JSON the host returns |
47
+
48
+ The event payloads that traverse the bus (and therefore the WS transport and
49
+ any persisted JSONL) are scrubbed at serialize time — see Component 4's
50
+ `redact.cjs` mitigation, which is the cross-cutting information-disclosure
51
+ control for the whole bus.
52
+
53
+ ---
54
+
55
+ ## Component 1 — Hooks (SessionStart update-check + budget/context-monitor)
56
+
57
+ The hooks run automatically: `SessionStart` fires the update-check on every
58
+ session, and the budget / context-monitor hook runs on tool-use to enforce
59
+ spend and context ceilings. They execute with the user's full shell privileges
60
+ inside the user's repo, with no sandbox.
61
+
62
+ - **Assets:** The user's shell + filesystem (the hook runs as the user); the
63
+ integrity of the budget/context accounting the monitor maintains; the
64
+ network reachability of the update-check's outbound call.
65
+ - **Entry points:** The update-check's outbound HTTP fetch and whatever it
66
+ parses from the response (a version string / changelog); the hook's read of
67
+ `.design/config.json` (a malicious or malformed config is untrusted input);
68
+ the tool-use payload the budget monitor inspects.
69
+ - **STRIDE threats:**
70
+ - **Spoofing:** A spoofed update endpoint (DNS/MITM) could feed a forged
71
+ "latest version" response to the update-check.
72
+ - **Tampering:** A malformed `.design/config.json` could try to corrupt the
73
+ budget/context accounting or flip the monitor's thresholds.
74
+ - **Repudiation:** Hook actions are largely silent — limited audit trail of
75
+ what a SessionStart hook did or why a budget veto fired.
76
+ - **Information disclosure:** The update-check's User-Agent / outbound
77
+ request reveals that GDD is in use; a verbose hook could echo env into logs.
78
+ - **Denial of service:** A hung or slow update endpoint could stall session
79
+ start if the fetch were unbounded.
80
+ - **Elevation of privilege:** The hook already runs at full user privilege —
81
+ the residual concern is a config-driven path or command injection lifting
82
+ *attacker* input to that privilege level.
83
+ - **Current mitigations:** The update-check is **advisory** — it informs of a
84
+ newer version and never auto-installs or executes downloaded code, so a
85
+ spoofed version string cannot achieve code execution. The budget /
86
+ context-monitor reads config defensively (missing file / malformed JSON /
87
+ missing key are tolerated, mirroring the issue-reporter kill-switch's
88
+ config-tolerance contract in `scripts/lib/issue-reporter/kill-switch.cjs`).
89
+ Hooks emit through the event bus, which is redacted by `redact.cjs` at
90
+ serialize time (see Component 4), so secrets in hook telemetry are scrubbed.
91
+ - **Residual risks:** The update-check's outbound egress is one of the
92
+ cross-cutting call sites that currently has **no machine-readable allowlist
93
+ and no CI gate** asserting it is the only network touch a hook makes →
94
+ audited + allowlisted in **33.5-02** and gated in **33.5-04**. (The shell
95
+ hook `hooks/update-check.sh` is `.sh`, outside the `.js`-family static
96
+ scanner's scope, so it is **documented** in the **33.5-02** audit report
97
+ rather than hard-gated.)
98
+
99
+ ---
100
+
101
+ ## Component 2 — MCP servers (gdd-state: 11 mutating tools / gdd-mcp: read)
102
+
103
+ Two MCP servers expose GDD state to an MCP client: **gdd-state**
104
+ (`sdk/mcp/gdd-state/`) with **11 mutating tools** — `add_blocker`,
105
+ `add_decision`, `add_must_have`, `checkpoint`, `frontmatter_update`, `get`,
106
+ `probe_connections`, `resolve_blocker`, `set_status`, `transition_stage`,
107
+ `update_progress` — and **gdd-mcp** (`sdk/mcp/gdd-mcp/`) with read tools. The
108
+ mutating server is the higher-value target because it writes `STATE.md`.
109
+
110
+ - **Assets:** The integrity of `STATE.md` (the project's source of truth for
111
+ position, decisions, blockers, stage); the event stream the mutations emit;
112
+ the filesystem region the server is allowed to write.
113
+ - **Entry points:** The `GDD_STATE_PATH` environment variable (which redirects
114
+ *where the server reads/writes*); the JSON tool-input payloads for all 11
115
+ mutating tools; the `.design/STATE.md` file content the server parses.
116
+ - **STRIDE threats:**
117
+ - **Spoofing:** A tool caller could impersonate a legitimate pipeline stage
118
+ and drive `transition_stage` / `set_status` without authorization.
119
+ - **Tampering:** Crafted tool inputs could write hostile content into
120
+ `STATE.md`, or `GDD_STATE_PATH` could redirect writes onto an unintended
121
+ file (path traversal).
122
+ - **Repudiation:** Without a complete mutation audit trail, a hostile or
123
+ buggy mutation is hard to attribute — partly addressed by the event
124
+ emissions below.
125
+ - **Information disclosure:** A `get` against a traversed path could read a
126
+ file outside the intended `.design/` boundary.
127
+ - **Denial of service:** A JSON-bomb (deeply nested object / multi-megabyte
128
+ string field) in a tool payload could exhaust memory/CPU during parse.
129
+ - **Elevation of privilege:** Path traversal via `GDD_STATE_PATH` plus an
130
+ absent boundary check effectively elevates a tool caller's reach to any
131
+ file the process can write.
132
+ - **Current mitigations:** Every mutation emits a `state.mutation` /
133
+ `state.transition` event through `emitStateMutation()` / `emitStateTransition()`
134
+ (`sdk/mcp/gdd-state/tools/shared.ts` lines 91–140), giving a partial audit
135
+ trail (anti-repudiation). Handlers **never throw to the harness** — every
136
+ error funnels through `errorResponse()` → `toToolError()` into a structured
137
+ `{success:false,error}` (shared.ts lines 28–31, 148–151), so a malformed
138
+ input degrades to a clean error instead of a crash. Each of the 11 tools
139
+ already ships a JSON input schema under `sdk/mcp/gdd-state/schemas/`. State
140
+ events are redacted by `redact.cjs` at serialize time (Component 4).
141
+ - **Residual risks:** `resolveStatePath()` (`sdk/mcp/gdd-state/tools/shared.ts`
142
+ lines 60–64) honors `GDD_STATE_PATH` with **no path-traversal guard** — it
143
+ returns the override verbatim, so `..` escape / absolute-outside / symlink
144
+ escape are unchecked. The tool schemas exist but carry **no payload-size cap**
145
+ (no JSON-bomb guard) and are not uniformly tightened
146
+ (`additionalProperties:false` + `maxLength`). Path traversal + JSON-bomb +
147
+ un-tightened schemas are all closed by **33.5-03** (path-traversal guard +
148
+ payload cap + all 11 schemas tightened).
149
+
150
+ ---
151
+
152
+ ## Component 3 — Peer-CLI broker (acp-client + asp-client child spawn)
153
+
154
+ The broker spawns peer CLIs over stdio: `scripts/lib/peer-cli/acp-client.cjs`
155
+ (ACP-protocol peers) and `scripts/lib/peer-cli/asp-client.cjs` (Codex
156
+ app-server protocol). Both fork a local child process and exchange
157
+ line-delimited JSON over its stdio. The child is **untrusted** — it is a
158
+ third-party CLI whose stdout the broker parses.
159
+
160
+ - **Assets:** GDD's process environment — specifically `ANTHROPIC_API_KEY`,
161
+ `GH_TOKEN`, and any `GDD_*` / provider secret in `process.env`; the broker's
162
+ memory/availability; the integrity of the JSON protocol exchange.
163
+ - **Entry points:** The child's **stdout** (untrusted JSON frames the broker
164
+ must parse); the **environment handed to the child** at spawn time; the
165
+ `opts.command` / `opts.args` the broker is asked to launch.
166
+ - **STRIDE threats:**
167
+ - **Spoofing:** A misbehaving peer could emit forged protocol replies /
168
+ request IDs to confuse the correlation map.
169
+ - **Tampering:** A peer could stream malformed frames attempting to corrupt
170
+ the broker's line-buffer / pending-request state.
171
+ - **Repudiation:** Limited record of exactly what env a given child was
172
+ handed at spawn.
173
+ - **Information disclosure:** **The headline risk** — the child inherits
174
+ GDD's full environment, so a hostile or compromised peer reads
175
+ `ANTHROPIC_API_KEY` / `GH_TOKEN` straight out of `process.env`.
176
+ - **Denial of service:** A peer that never emits a newline could force the
177
+ broker to buffer unbounded stdout until memory exhaustion.
178
+ - **Elevation of privilege:** Inherited secrets let a peer act *as GDD*
179
+ against GDD's providers — using GDD's keys for the peer's own ends.
180
+ - **Current mitigations:** `acp-client.cjs` caps an un-terminated stdout line
181
+ at **`MAX_LINE_BYTES = 16 * 1024 * 1024`** (16 MiB; defined line 62, enforced
182
+ lines 166–176 — a peer that emits 16 MiB without a newline gets its active
183
+ prompt rejected as a protocol violation). This is a real **DoS guard** on the
184
+ untrusted stdout channel. The broker uses plain `spawn` with **no shell**
185
+ (acp-client.cjs lines 106–113, `windowsHide: true`), avoiding shell-injection
186
+ on the command path. Per-request correlation via a pending-id map bounds the
187
+ protocol state machine.
188
+ - **Residual risks:** Both clients default the child's environment to the
189
+ **full `process.env`** when `opts.env` is absent — `acp-client.cjs` line 102
190
+ (`const env = opts.env && typeof opts.env === 'object' ? opts.env :
191
+ process.env;`) and `asp-client.cjs` line 122 (when `opts.env` is absent no
192
+ `spawnOptions.env` is set, so the child inherits the parent's `process.env` by
193
+ Node default). This leaks GDD's `ANTHROPIC_API_KEY` / `GH_TOKEN` / `GDD_*` to
194
+ every spawned peer. Closed by **33.5-04** (allowlist-forward, default-deny env
195
+ sandbox via a shared `sanitize-env` helper applied to both clients; secrets
196
+ are never forwarded unless explicitly allowlisted in `.design/config.json`).
197
+
198
+ ---
199
+
200
+ ## Component 4 — WebSocket event-stream transport (scripts/lib/transports/ws.cjs)
201
+
202
+ `scripts/lib/transports/ws.cjs` exposes the event-stream bus over WebSocket:
203
+ one JSON event per text frame, with optional replay of a tail file to each new
204
+ connection. It is an **optional dependency** (`ws`) — absent installs render an
205
+ install hint instead of starting. When running, it is a network listener.
206
+
207
+ - **Assets:** The **event stream itself** (every `state.mutation` /
208
+ `state.transition` / pipeline event, which can carry payload detail); the
209
+ listening socket; the Bearer token that authorizes a connection.
210
+ - **Entry points:** The HTTP **`Upgrade` request** from any client that can
211
+ reach the bound socket, and specifically its `Authorization: Bearer <token>`
212
+ header; the `tailFrom` replay file path.
213
+ - **STRIDE threats:**
214
+ - **Spoofing:** A client without the token attempting to subscribe to the
215
+ live event stream.
216
+ - **Tampering:** N/A for inbound (the transport is push-only to clients) —
217
+ the concern is read access, not write.
218
+ - **Repudiation:** No per-connection identity beyond the shared token, so
219
+ individual subscribers are not distinguishable in an audit.
220
+ - **Information disclosure:** **The headline risk** — an unauthorized
221
+ subscriber would receive the entire live event stream, including any
222
+ sensitive payload detail, if it could reach the socket and pass auth.
223
+ - **Denial of service:** Many connections / a slow consumer could pressure
224
+ the server (mitigated in part by fire-and-forget, no-queue backpressure).
225
+ - **Elevation of privilege:** A network-reachable listener turns a
226
+ local-only observability feature into a remotely-reachable data source.
227
+ - **Current mitigations:** **Bearer-token auth is enforced on every upgrade**:
228
+ `ws.cjs` lines 110–116 reject any upgrade whose header is missing or where
229
+ the supplied token does not match the expected `Bearer` value, returning an `HTTP/1.1 401 Unauthorized` and a
230
+ socket destroy. The token **must be ≥8 chars** — `startServer` throws a
231
+ `TypeError` if `opts.token.length < 8` (line 74), preventing trivially weak
232
+ tokens. Backpressure is **fire-and-forget with no queue** (lines 91–108):
233
+ events for a non-OPEN socket are dropped, bounding memory under a slow
234
+ consumer. Cross-cutting for the whole bus: **`redact.cjs`** deep-walks every
235
+ event payload at serialize time (`scripts/lib/redact.cjs` — `redact()` lines
236
+ 95–116, `redactString()` lines 75–83) and scrubs **8 secret patterns** (pem,
237
+ jwt, anthropic `sk-ant-`, stripe `sk_live_`, slack `xox[baprs]`, github_pat
238
+ `ghp_`, aws `AKIA`, generic `sk-`), so secrets in event payloads are masked
239
+ before they ever reach a WS subscriber or hit disk. This `redact.cjs` scrub is
240
+ the runtime's primary information-disclosure control across **all** components
241
+ that emit events.
242
+ - **Residual risks:**
243
+ - The server binds to **all interfaces (`0.0.0.0`)** by default —
244
+ `httpServer.listen(opts.port, ...)` (line 145) passes **no host argument**,
245
+ so on a multi-homed / LAN host the token-protected stream is reachable
246
+ off-box. The token compare uses `!==` (line 112), which is
247
+ **timing-unsafe**. Both closed by **33.5-03** (default bind `127.0.0.1` +
248
+ opt-in remote via `event_stream.bind_host` / `GDD_WS_BIND_HOST` + a CI gate
249
+ that fails if the default config would bind `0.0.0.0`; upgrade the compare to
250
+ `crypto.timingSafeEqual`).
251
+ - `redact.cjs` is **missing three modern token formats**: Gemini / GCP
252
+ `AIza…`, GitHub fine-grained `github_pat_…`, and GitHub server / oauth /
253
+ user / refresh `gh[sour]_…`. A payload carrying one of these would leak
254
+ through the scrub onto the stream and disk. Closed by **33.5-05** (add the
255
+ three patterns + a synthetic-secret fuzz test asserting zero leak).
256
+
257
+ ---
258
+
259
+ ## Component 5 — Issue-reporter outbound (gh CLI only)
260
+
261
+ `scripts/lib/issue-reporter/` is the only first-party feature that intentionally
262
+ reaches the network. It assembles a bug report and submits it through the user's
263
+ **`gh` CLI**. **This network model is already mitigated and is DOCUMENTED here,
264
+ not re-engineered** (CONTEXT Out-of-scope: rewriting the issue-reporter network
265
+ model).
266
+
267
+ - **Assets:** The user's GitHub identity (via the local `gh` auth); the content
268
+ of the submitted report (which must not carry the user's secrets or
269
+ unintended PII); the integrity of the destination repo.
270
+ - **Entry points:** The user-invoked report flow (the body / title assembled
271
+ from local state); the `.design/config.json` and the env that gate whether the
272
+ reporter runs at all.
273
+ - **STRIDE threats:**
274
+ - **Spoofing:** A forged destination could try to receive reports — mitigated
275
+ by the frozen destination below.
276
+ - **Tampering:** Attempting to redirect submissions to an attacker repo by
277
+ injecting a destination override.
278
+ - **Repudiation:** Submissions flow through `gh` under the user's identity,
279
+ which is itself the attribution record.
280
+ - **Information disclosure:** **The headline risk** — a report could exfiltrate
281
+ secrets / PII embedded in local state if the payload were not scrubbed.
282
+ - **Denial of service:** Not a meaningful vector — submission is a
283
+ user-initiated, one-shot CLI call.
284
+ - **Elevation of privilege:** Using the user's `gh` credentials beyond the
285
+ single sanctioned submit.
286
+ - **Current mitigations (ALREADY shipped — documented, no change here):**
287
+ - **Outbound is via the `gh` CLI ONLY.** `gh-submit.cjs` wraps
288
+ `gh issue create --repo <DESTINATION_REPO> --title … --body-file …` and is
289
+ explicit that "the user's gh CLI is the sole outbound primitive. No HTTP-S
290
+ URL literals, no global fetch primitive, no plugin-side credentials" (D-05).
291
+ There is no raw HTTP egress in this subtree.
292
+ - **Frozen destination.** `destination.cjs` is an `Object.freeze`-d module —
293
+ the single source of truth for the destination repo, with **no env-var
294
+ lookup, no config override, no flag override**. A static CI gate asserts it
295
+ is the only file under the report-issue tree that contains the destination
296
+ literal, so a redirect attempt fails the build.
297
+ - **Kill-switch (dual-surface).** `kill-switch.cjs` disables the reporter via
298
+ **either** the env var `GDD_DISABLE_ISSUE_REPORTER === '1'` **or** the config
299
+ `.design/config.json` `{ "issue_reporter": false }`; either surface alone is
300
+ sufficient, and config is read tolerantly (missing file / malformed JSON /
301
+ missing key are safe).
302
+ - Payloads pass through privacy-diff / consent-prompt machinery before
303
+ submission, and event telemetry is redacted by `redact.cjs` (Component 4).
304
+ - **Residual risks:** The issue-reporter's **own** network model has no residual
305
+ this phase changes — it is intentionally documented as complete. The only
306
+ cross-cutting residual touching it is the **lack of a machine-readable
307
+ outbound allowlist + CI gate** that proves `gh-submit` is the sole egress in
308
+ this subtree at a tree-wide level: closed by **33.5-02** (the canonical
309
+ outbound-network allowlist data, which lists `scripts/lib/issue-reporter/**`
310
+ as an allowed egress glob) and **33.5-04** (the `scan:outbound` CI gate that
311
+ fails on any active-egress site not under an allowlisted glob).
312
+
313
+ ---
314
+
315
+ ## Component 6 — OpenRouter catalog fetcher (scripts/lib/openrouter/catalog-fetcher.cjs)
316
+
317
+ > Added in Phase 33.6 (OR-01, CONTEXT D-06). This is the runtime's **first
318
+ > plugin-side outbound REST client** — the issue-reporter (Component 5) reaches
319
+ > the network only through the user's `gh` CLI, and the WS transport (Component
320
+ > 4) is a *server*, not an outbound client. The catalog fetcher is the first
321
+ > first-party code to open an outbound HTTP request to a third-party host
322
+ > directly, which is why it lands only after the 33.5 audited baseline and the
323
+ > `scan:outbound` gate (33.5-04) are in place.
324
+
325
+ `scripts/lib/openrouter/catalog-fetcher.cjs` performs a read-only GET to the
326
+ OpenRouter model catalog (`https://openrouter.ai/api/v1/models`) through an
327
+ **injectable `fetchImpl`** (default global `fetch`), maps the response into the
328
+ `.design/cache/openrouter-models.json` cache shape, and writes it atomically.
329
+ The live fetch is opt-in — gated on `OPENROUTER_API_KEY` being present at
330
+ runtime; absent it, the fetcher returns cached-if-any-else-null and tier
331
+ resolution falls back to the native provider.
332
+
333
+ - **Assets:** The **`OPENROUTER_API_KEY`** (a billable provider credential) and
334
+ the integrity of the cached catalog the tier-resolver later trusts.
335
+ - **Entry points:** The **`/models` JSON the OpenRouter host returns** (untrusted
336
+ remote input the fetcher must parse), and the `OPENROUTER_BASE_URL` env (an
337
+ operator-supplied endpoint override).
338
+ - **STRIDE threats:**
339
+ - **Spoofing:** A spoofed `/models` endpoint (DNS/MITM, or a hostile
340
+ `OPENROUTER_BASE_URL`) could feed a forged catalog.
341
+ - **Tampering:** A malformed/oversized `/models` body could try to corrupt the
342
+ cache the resolver reads, or smuggle unexpected fields downstream.
343
+ - **Information disclosure:** **The headline risk** — leaking the
344
+ `OPENROUTER_API_KEY` by persisting it to the cache, logging it, or sending it
345
+ to an unintended host.
346
+ - **Denial of service:** A hung or slow host could stall the fetch; a giant
347
+ catalog could pressure memory.
348
+ - **Elevation of privilege:** A forged catalog could steer tier resolution to
349
+ an attacker-chosen model id.
350
+ - **Current mitigations:** The key is read from **`OPENROUTER_API_KEY` env only**,
351
+ sent **solely** as an `Authorization: Bearer` request header, and is **never
352
+ persisted to the cache nor written to any log seam** — the cache shape carries
353
+ only `id`/`name`/`context_length`/`pricing`, and the mapper keeps **only** those
354
+ fields, dropping everything else (the `/models` body is **mapped, never
355
+ eval'd**). The cache write is **atomic** (per-pid temp + rename) into the
356
+ **gitignored** `.design/cache/`, so a partial/corrupt fetch can't leave a
357
+ half-written catalog and the cache never enters git history. The fetcher
358
+ **never throws** (D-08): no key / fetch failure / parse failure all degrade to
359
+ cached-if-any-else-null, bounding the DoS surface, and retries are **bounded**
360
+ (max 3 attempts) on a jittered-backoff curve with `rate-guard` awareness.
361
+ Egress is **allowlisted** via `scripts/lib/openrouter/**` in
362
+ `scripts/security/outbound-allowlist.json` — the only sanctioned outbound site
363
+ in that subtree — so the 33.5 `scan:outbound` gate proves no un-approved egress
364
+ crept in. The **injectable `fetchImpl`** keeps the default `npm test` suite
365
+ hermetic (D-07) — no live network — and there is **no new HTTP dependency**
366
+ (global `fetch` + `sdk/primitives` only — D-10), avoiding both a new supply-chain
367
+ surface and the gate's `axios`/`node-fetch`/`undici` package patterns.
368
+ - **Residual risks:** None this phase leaves open. The catalog is advisory data
369
+ consumed by the tier-resolver heuristic (33.6-02), which already clamps to
370
+ GDD's `opus`/`sonnet`/`haiku` vocabulary and supports user overrides, so a
371
+ forged catalog cannot escalate beyond model-id selection within that bounded
372
+ set; a future hardening could pin the OpenRouter TLS cert or sign the cache,
373
+ but neither is required for the current trust model.
374
+
375
+ ---
376
+
377
+ ## Residual-risk → closing-plan map
378
+
379
+ Every residual risk identified above is routed to the Phase 33.5 plan (or
380
+ policy doc) that closes it. No residual is left unmapped. This table is the
381
+ spine the phase closeout (33.5-06) uses to prove completeness.
382
+
383
+ | Residual risk | Component | Closing plan |
384
+ | --- | --- | --- |
385
+ | WS binds `0.0.0.0` by default (`listen` line 145, no host) + timing-unsafe `!==` token compare (line 112) | WebSocket transport | **33.5-03** |
386
+ | `GDD_STATE_PATH` path traversal (no guard, shared.ts 60–64) + no payload-size cap + un-tightened tool schemas | gdd-state MCP | **33.5-03** |
387
+ | Full `process.env` (incl. `ANTHROPIC_API_KEY` / `GH_TOKEN`) leaks to spawned peers (acp 102 / asp 122) | Peer-CLI broker | **33.5-04** |
388
+ | Outbound egress sites have no machine-readable allowlist + no CI gate | cross-cutting (hooks update-check, figma-extract, issue-reporter, e2e) | **33.5-02** (allowlist) + **33.5-04** (scan gate) |
389
+ | Secret-scan misses Gemini `AIza…` / GitHub fine-grained `github_pat_…` / GitHub server `gh[sour]_…` tokens | redact.cjs | **33.5-05** |
390
+ | No published vulnerability-disclosure policy | project | **33.5-06** (SECURITY.md) |
391
+
392
+ ### Already-mitigated (documented, NOT re-engineered)
393
+
394
+ | Already-mitigated surface | Component | Evidence |
395
+ | --- | --- | --- |
396
+ | Outbound via `gh` CLI only; frozen destination; dual-surface kill-switch | Issue-reporter | `gh-submit.cjs` (`gh issue create` only), `destination.cjs` (`Object.freeze`, no override), `kill-switch.cjs` (env + `.design/config.json`) |
397
+ | Bearer-token auth on every WS upgrade + ≥8-char token rule | WebSocket transport | `ws.cjs` 110–116 (401 on mismatch) + line 74 (`length < 8` → `TypeError`) |
398
+ | 16 MiB un-newlined-stdout DoS cap on untrusted peer output | Peer-CLI broker | `acp-client.cjs` `MAX_LINE_BYTES` line 62, enforced 166–176 |
399
+ | Deep-walk secret scrub of every event payload at serialize time | cross-cutting (event bus) | `redact.cjs` `redact()` 95–116 / `redactString()` 75–83, 8 patterns |
@@ -0,0 +1,98 @@
1
+ # OpenRouter Tier-Mapping Heuristic
2
+
3
+ How `scripts/lib/tier-resolver-openrouter.cjs` maps GDD's tier vocabulary onto a
4
+ dynamic OpenRouter catalog model id. This document is the human-readable companion
5
+ to that adapter; the adapter's `resolve(tier, opts)` is the canonical, executable
6
+ source of the mapping. Phase 33.6, decision D-03 (heuristic + override), D-04
7
+ (tier vocabulary), D-08 (graceful-null → native fallback).
8
+
9
+ ## What it maps
10
+
11
+ The plugin speaks one tier vocabulary everywhere a model tier is named in
12
+ frontmatter or config: `opus`, `sonnet`, `haiku` — the same `VALID_TIERS` the
13
+ Phase-26 `tier-resolver.cjs` enforces. OpenRouter, by contrast, exposes a flat
14
+ catalog of provider-prefixed model ids (`anthropic/claude-opus-4-7`,
15
+ `meta-llama/llama-3.1-8b-instruct`, `qwen/qwen-2.5-72b-instruct`, …). The adapter
16
+ bridges the two by assigning each GDD tier to one internal capability bucket and
17
+ then picking the catalog id that best fits that bucket.
18
+
19
+ The ROADMAP's SC#4 names the buckets `high` / `medium` / `low`; those are the
20
+ heuristic's INTERNAL labels. They map one-to-one to the public tiers (D-04):
21
+
22
+ - `opus` ← HIGH bucket
23
+ - `sonnet` ← MEDIUM bucket
24
+ - `haiku` ← LOW bucket
25
+
26
+ The adapter's public `resolve(tier)` always speaks `opus` / `sonnet` / `haiku`;
27
+ `high` / `medium` / `low` never leak across the API boundary.
28
+
29
+ ## The buckets
30
+
31
+ - **opus (HIGH) = top-tier closed.** The most capable closed-vendor model in the
32
+ catalog — the priciest premium id from a closed namespace. This is the
33
+ "spare-no-expense, hardest reasoning" slot.
34
+ - **sonnet (MEDIUM) = mid / top-open.** A capable model that sits below the opus
35
+ pick — typically the mid-priced closed model, or the strongest open model when
36
+ no second closed tier is present. The everyday workhorse slot.
37
+ - **haiku (LOW) = cheap open.** The cheapest capable OPEN model — the
38
+ fast/inexpensive slot for high-volume, low-stakes calls.
39
+
40
+ ## The signals
41
+
42
+ The heuristic is computed from fields already present on each catalog model, so it
43
+ stays deterministic for a fixed catalog (no clock, no randomness — important so the
44
+ 33.6-04 golden baseline is stable):
45
+
46
+ - **Namespace (closed vs open).** The id prefix before the `/` names the vendor.
47
+ `anthropic`, `openai`, `google` are treated as CLOSED (premium, frontier).
48
+ `meta-llama`, `qwen`, `mistralai`, `deepseek` are treated as OPEN (commodity,
49
+ cheap). The closed/open split is the primary axis: opus and sonnet prefer closed,
50
+ haiku requires open.
51
+ - **Pricing.** Each model carries `pricing.prompt` / `pricing.completion` as string
52
+ decimals (USD per token). Parsed to Number, the completion price is the tie-break:
53
+ highest completion price wins the opus slot; lowest completion price wins the
54
+ haiku slot. Models with unparseable or missing pricing sort last.
55
+ - **Context length.** `context_length` is a secondary capability signal used only to
56
+ break a pricing tie (longer context is treated as more capable).
57
+
58
+ For the canonical fixture catalog (closed `anthropic/claude-opus-4-7` +
59
+ `anthropic/claude-sonnet-4-7`, open `meta-llama/llama-3.1-70b-instruct`,
60
+ `meta-llama/llama-3.1-8b-instruct`, `qwen/qwen-2.5-72b-instruct`) the heuristic
61
+ resolves opus → `anthropic/claude-opus-4-7` (top closed, highest completion price),
62
+ sonnet → `anthropic/claude-sonnet-4-7` (mid closed), and haiku →
63
+ `meta-llama/llama-3.1-8b-instruct` (cheapest open).
64
+
65
+ ## The override escape hatch
66
+
67
+ The heuristic is a sensible default, not a straitjacket. A user can pin any tier to
68
+ an exact catalog id via `.design/config.json`:
69
+
70
+ ```
71
+ {
72
+ "openrouter_tier_overrides": {
73
+ "opus": "anthropic/claude-opus-4-7",
74
+ "haiku": "meta-llama/llama-3.1-8b-instruct"
75
+ }
76
+ }
77
+ ```
78
+
79
+ An override **wins** over the heuristic: when `openrouter_tier_overrides[tier]` is a
80
+ non-empty string, the adapter returns it verbatim — even if that id is not present
81
+ in the live catalog (the user's explicit choice is honored over catalog membership).
82
+ Tests inject the same map via `opts.overrides` instead of reading the live config
83
+ file, so the override path is exercised hermetically. The config read is best-effort:
84
+ a missing file, a missing key, or corrupt JSON degrades to an empty override map
85
+ rather than throwing.
86
+
87
+ ## The graceful-null contract
88
+
89
+ OpenRouter is opt-in ALONGSIDE native provider auth — never OpenRouter-only (D-08).
90
+ When no catalog is available (no cache, an empty `models[]`, or a `readCatalog` that
91
+ returns null) AND no override applies to the requested tier, `resolve` returns
92
+ `null`. A `null` is not an error: it is the signal that the caller (the router /
93
+ budget-enforcer, wired in 33.6-03) should fall back to the native provider via the
94
+ existing `scripts/lib/tier-resolver.cjs` fallback chain. The adapter NEVER throws —
95
+ an unknown tier, a missing config, a corrupt cache, or garbage options all degrade to
96
+ `null` (or to an override when one applies). This keeps OpenRouter a strictly
97
+ additive capability: turning it off, or having it fail to fetch, can never break a
98
+ resolution that would have succeeded natively.
@@ -0,0 +1,26 @@
1
+ # OpenRouter — Catalog-Derived Price Snapshot
2
+
3
+ **Phase 33.6 (v1.33.6).** This file is a **catalog-derived snapshot** of OpenRouter per-model prices — it is **generated from** `.design/cache/openrouter-models.json` (the dynamic catalog fetched by `scripts/lib/openrouter/catalog-fetcher.cjs`), **not** a hand-maintained authority. The **live source of truth is the dynamic catalog**; this table is a derived, illustrative view that can go stale between catalog fetches.
4
+
5
+ Unlike the per-runtime tables under `reference/prices/` (Phase 26 D-08, hand-curated authority with provenance), OpenRouter's prices live in the upstream `/models` response and are refreshed on the 24h TTL. To inspect the current resolved prices, run `/gdd:openrouter-status` or read the cache directly. For the tier→model resolution heuristic see `reference/openrouter-tier-mapping.md`.
6
+
7
+ OpenRouter quotes prices **per token** (USD), for `prompt` (input) and `completion` (output) separately.
8
+
9
+ ## Representative sample (per token, USD)
10
+
11
+ Derived from the fixture catalog at `test/fixtures/baselines/phase-33-6/openrouter-catalog.json` (a snapshot mirror of the cache shape). Actual live prices come from the catalog at fetch time.
12
+
13
+ | model id | prompt $/tok | completion $/tok |
14
+ |----------|--------------|------------------|
15
+ | `anthropic/claude-opus-4-7` | 0.000015 | 0.000075 |
16
+ | `anthropic/claude-sonnet-4-7` | 0.000003 | 0.000015 |
17
+ | `meta-llama/llama-3.1-70b-instruct` | 0.00000052 | 0.00000075 |
18
+ | `meta-llama/llama-3.1-8b-instruct` | 0.00000002 | 0.00000005 |
19
+ | `qwen/qwen-2.5-72b-instruct` | 0.00000038 | 0.0000004 |
20
+
21
+ ## Notes
22
+
23
+ - **Derived view, not authority.** Do not hand-edit prices here to "fix" cost math — fix the catalog fetch instead. This file documents the *shape* and *source* of OpenRouter pricing for the registry round-trip and for human reference.
24
+ - **Per-token vs per-1M.** The native runtime tables (`reference/prices/<runtime>.md`) quote `input_per_1m` / `output_per_1m`; OpenRouter's catalog quotes per-token. Multiply by 1,000,000 to compare (e.g. `anthropic/claude-opus-4-7` ≈ $15 input / $75 output per 1M tokens).
25
+ - **Cost telemetry.** When a model is resolved via the OpenRouter adapter, the cost row tags `provider: openrouter` (Phase 33.6-03, SC#6) — see `scripts/lib/budget-enforcer.cjs#buildCostEventPayload`.
26
+ - **Drift.** The authority-watcher diffs the catalog weekly and surfaces `deprecated`/`withdrawn` models matching a configured `openrouter_tier_overrides` pin (SC#8) — see `scripts/lib/authority-watcher/index.cjs#diffOpenRouterCatalog`.
@@ -860,6 +860,34 @@
860
860
  "type": "meta-rules",
861
861
  "phase": 30,
862
862
  "description": "Phase 30 triage gate catalogue — locally-fixable failure modes (id/pattern/diagnosis/remedy/severity, with optional propose_report whitelist flag per D-11) consulted by scripts/lib/issue-reporter/triage-matcher.cjs before the report-issue consent prompt (D-07/D-11)."
863
+ },
864
+ {
865
+ "name": "gdd-threat-model",
866
+ "path": "reference/gdd-threat-model.md",
867
+ "type": "heuristic",
868
+ "phase": 33.5,
869
+ "description": "Phase 33.5 STRIDE threat model of GDD's own runtime attack surface — hooks, the gdd-state + gdd-mcp MCP servers, the peer-CLI broker, the WebSocket event-stream transport, and issue-reporter outbound; maps each residual risk to the 33.5 plan that closes it."
870
+ },
871
+ {
872
+ "name": "gdd-runtime-audit",
873
+ "path": "reference/gdd-runtime-audit.md",
874
+ "type": "heuristic",
875
+ "phase": 33.5,
876
+ "description": "Phase 33.5 static security audit of GDD's shipped runtime surface (hooks/scripts/sdk/bin) — outbound-network call sites, secret-handling sites, and external-input surfaces; human-readable companion to scripts/security/outbound-allowlist.json (the canonical active-egress allowlist the 33.5-04 scan-outbound-network.cjs gate consumes) and reference/gdd-threat-model.md."
877
+ },
878
+ {
879
+ "name": "openrouter-tier-mapping",
880
+ "path": "reference/openrouter-tier-mapping.md",
881
+ "type": "heuristic",
882
+ "phase": 33.6,
883
+ "description": "Phase 33.6 OpenRouter tier-mapping heuristic — maps GDD opus/sonnet/haiku onto OpenRouter catalog ids via closed-vs-open + pricing buckets (high/medium/low), with the .design/config.json#openrouter_tier_overrides escape hatch (override wins) and graceful-null → native fallback."
884
+ },
885
+ {
886
+ "name": "prices-openrouter",
887
+ "path": "reference/prices.openrouter.md",
888
+ "type": "data",
889
+ "phase": 33.6,
890
+ "description": "Phase 33.6 catalog-derived OpenRouter price sub-table — per-model prompt/completion $/tok snapshot of .design/cache/openrouter-models.json; derived view, the dynamic catalog is the source of truth (D-11 registry round-trip)."
863
891
  }
864
892
  ]
865
893
  }