返回 CodeWhale
REMOTE_SETUP_DESIGN.md
根目录 / docs / rfcs / REMOTE_SETUP_DESIGN.md
1 # `codewhale remote-setup` - Tailscale-first design
2
3 Status: **design / revision**. This RFC revises the earlier cloud-first
4 `remote-setup` plan. Keep the accurate implementation work already present:
5 `codewhale remote-setup` exists today as a generate-only bundle wizard for
6 cloud plus chat bridge deployments, and `--apply` is still not implemented.
7
8 ## Goal
9
10 Give users a guided, education-forward way to reach a local-first Codewhale
11 runtime from another surface without accidentally publishing their agent.
12
13 Default posture:
14
15 1. **Local-first by default.**
16 2. **Tailnet-private when remote.**
17 3. **Public only when explicitly chosen.**
18
19 The wizard should ask:
20
21 > How do you want to reach Codewhale?
22
23 and offer these paths, in this order:
24
25 1. This machine only (localhost)
26 2. Private devices with Tailscale (**Recommended**)
27 3. Telegram bot
28 4. Feishu/Lark bot
29 5. Weixin personal bridge
30 6. Public webhook / Funnel (**Advanced**)
31
32 The recommended remote answer is Tailscale Serve with the backend still bound
33 to `127.0.0.1`. Tailscale supplies device identity and encrypted transport.
34 Tailscale Funnel is public internet exposure and must stay advanced.
35
36 ## Current implementation checkpoint
37
38 ### `/setup` → Remote runtime step (#3409)
39
40 The setup wizard's `RemoteRuntime` card presents exactly four modes, each with a
41 status derived from observable state — never from intent:
42
43 | mode | status source |
44 |------|---------------|
45 | this machine only | always `ready`; nothing is exposed and nothing to configure |
46 | runtime API | presence (never value) of `CODEWHALE_RUNTIME_TOKEN` / `DEEPSEEK_RUNTIME_TOKEN` |
47 | phone on your network | `disabled` unless `CODEWHALE_RUNTIME_HOST` is set, because the shipped unit binds loopback |
48 | chat app | per-bridge `secret_keys` presence from `remote_setup::registry` |
49
50 Contract for that step:
51
52 - **Secret values are never read or rendered.** Only variable *names* and
53 set/unset are used, so a hostile token cannot reach the UI or the persisted
54 step result.
55 - **`R` renders a plan preview in memory** through `remote_setup::bundle::render_bundle`
56 with every secret replaced by `<redacted>`. It never calls `write_bundle`,
57 never runs a provisioning command, and creates no files.
58 - **Missing tokens/config are `NeedsAction`, never blocking.** Local-only is the
59 default and settles the step in one key, so a user who wants no remote access
60 is finished immediately. `/setup`'s report and `doctor` inherit the recorded
61 status verbatim.
62
63 Verified against the codebase:
64
65 - `codewhale app-server --http` is the canonical HTTP/SSE runtime API entrypoint.
66 It delegates to the mature `serve --http` implementation.
67 - `codewhale app-server --mobile` is real and serves the phone control page at
68 `/mobile`.
69 - `--host`, `--port`, `--workers`, `--auth-token`, `--insecure-no-auth`, and
70 repeatable `--cors-origin` exist on `app-server --http` / `--mobile`.
71 - `--mobile` is loopback-only: without `--host` it binds `127.0.0.1`, and a
72 non-loopback `--mobile` bind is rejected at startup (no TLS or verified
73 overlay boundary yet).
74 - `/health` and `/v1/runtime/info` are public bootstrap/supervision endpoints.
75 `/v1/*` control routes require the runtime bearer token unless auth is
76 explicitly disabled on a trusted loopback bind.
77 - `codewhale doctor --json` exists as the machine-readable local diagnostic.
78 - `codewhale remote-setup` exists, but today it is generate-only. Its current
79 matrix is cloud target (`lighthouse`, `azure`, `digitalocean`) x bridge
80 (`feishu`, `telegram`) x provider registry. It does **not** yet model
81 localhost, Tailscale, Weixin, or Funnel as first-class choices.
82 - Telegram and Feishu bridge validators exist as `npm run validate:config`.
83 Weixin currently has `npm run check`, but no validate-config script.
84
85 Accuracy note for the Tailscale recommendation: the requested setup uses
86 `app-server --http`, but the current runtime serves `/mobile` only in mobile
87 mode. This RFC keeps the target command shape for the recommended loopback
88 runtime, and documents the verified current-binary variant when the mobile page
89 is required:
90
91 ```bash
92 # With CODEWHALE_RUNTIME_TOKEN exported (see "Common runtime base").
93 # Runtime API only, verified:
94 codewhale app-server --http --host 127.0.0.1 --port 7878
95
96 # Runtime API plus /mobile, verified:
97 codewhale app-server --mobile --host 127.0.0.1 --port 7878
98 ```
99
100 ## Common runtime base
101
102 Every path starts from the same local runtime trust boundary.
103
104 The runtime reads its token from the exported `CODEWHALE_RUNTIME_TOKEN`. Every
105 command below leaves out `--auth-token` on purpose: a command-line argument is
106 visible to other local users in the process list, and the environment is not.
107 Under a service manager, supply the token with an environment file, not with an
108 argument. The validation `curl` calls hand the header over through a file
109 descriptor for the same reason; that form needs bash or zsh and curl 7.55 or
110 newer.
111
112 ```bash
113 CODEWHALE_RUNTIME_TOKEN="$(openssl rand -hex 32)"
114 export CODEWHALE_RUNTIME_TOKEN
115
116 codewhale app-server --http \
117 --host 127.0.0.1 \
118 --port 7878
119 ```
120
121 For the current binary, use `--mobile --host 127.0.0.1` instead of `--http` if
122 the path needs the built-in `/mobile` page.
123
124 Doctor-style local validation:
125
126 ```bash
127 codewhale doctor --json
128 curl -fsS http://127.0.0.1:7878/health
129 curl -fsS \
130 -H @<(printf 'Authorization: Bearer %s\n' "$CODEWHALE_RUNTIME_TOKEN") \
131 http://127.0.0.1:7878/v1/runtime/info
132 ```
133
134 Runtime mental model:
135
136 - Exposed by Codewhale: only the address it binds. The recommended bind is
137 `127.0.0.1:7878`.
138 - Auth token: `CODEWHALE_RUNTIME_TOKEN`, passed as `Authorization: Bearer ...`
139 by clients and bridges. Legacy `DEEPSEEK_RUNTIME_TOKEN` remains a fallback.
140 - Provider secrets: stay in runtime configuration, not in bridge env files.
141 - Bridge secrets: stay in transport-specific env files.
142
143 ## Guided flow
144
145 ### 1. This machine only (localhost)
146
147 Use this when the TUI, SDK, browser, or local script runs on the same machine as
148 Codewhale.
149
150 Setup:
151
152 ```bash
153 CODEWHALE_RUNTIME_TOKEN="$(openssl rand -hex 32)"
154 export CODEWHALE_RUNTIME_TOKEN
155
156 codewhale app-server --http \
157 --host 127.0.0.1 \
158 --port 7878
159 ```
160
161 Env template:
162
163 ```env
164 CODEWHALE_RUNTIME_URL=http://127.0.0.1:7878
165 CODEWHALE_RUNTIME_TOKEN=<same value used to start app-server>
166 ```
167
168 Validation:
169
170 ```bash
171 codewhale doctor --json
172 curl -fsS http://127.0.0.1:7878/health
173 curl -fsS \
174 -H @<(printf 'Authorization: Bearer %s\n' "$CODEWHALE_RUNTIME_TOKEN") \
175 http://127.0.0.1:7878/v1/runtime/info
176 ```
177
178 Trust boundary:
179
180 - Exposed: loopback only.
181 - Not exposed: LAN, tailnet, or public internet.
182 - Token used: `CODEWHALE_RUNTIME_TOKEN` for control routes; local `/health` and
183 `/v1/runtime/info` are public bootstrap endpoints.
184
185 ### 2. Private devices with Tailscale (Recommended)
186
187 Use this to reach Codewhale from your phone or laptop without opening a LAN or
188 public port. Tailscale authenticates devices in your tailnet; Codewhale still
189 binds to localhost.
190
191 Target setup to feature in the wizard:
192
193 ```bash
194 CODEWHALE_RUNTIME_TOKEN="$(openssl rand -hex 32)"
195 export CODEWHALE_RUNTIME_TOKEN
196
197 codewhale app-server --http \
198 --host 127.0.0.1 \
199 --port 7878
200
201 tailscale serve --bg --https=443 localhost:7878
202 ```
203
204 Then open the Tailscale Serve URL from a phone or laptop in the same tailnet.
205 For the current binary's mobile page, start Codewhale with the verified mobile
206 variant:
207
208 ```bash
209 codewhale app-server --mobile \
210 --host 127.0.0.1 \
211 --port 7878
212 ```
213
214 Then open (put the token in the URL **fragment**, not a query param — the
215 `/mobile` page reads it from `location.hash`, and a fragment is never sent to
216 the Tailscale serving layer or to any proxy log):
217
218 ```text
219 https://<machine>.<tailnet>.ts.net/mobile#token=<CODEWHALE_RUNTIME_TOKEN>
220 ```
221
222 Env template:
223
224 ```env
225 CODEWHALE_RUNTIME_URL=http://127.0.0.1:7878
226 CODEWHALE_RUNTIME_TOKEN=<openssl-rand-hex-32>
227 TAILSCALE_SERVE_TARGET=localhost:7878
228 TAILSCALE_SERVE_URL=https://<machine>.<tailnet>.ts.net
229 ```
230
231 Validation:
232
233 ```bash
234 codewhale doctor --json
235 curl -fsS http://127.0.0.1:7878/health
236 curl -fsS https://<machine>.<tailnet>.ts.net/health
237 curl -fsS \
238 -H @<(printf 'Authorization: Bearer %s\n' "$CODEWHALE_RUNTIME_TOKEN") \
239 https://<machine>.<tailnet>.ts.net/v1/runtime/info
240 tailscale serve status
241 ```
242
243 Trust boundary:
244
245 - Exposed: an HTTPS endpoint reachable by devices authorized in your tailnet.
246 - Not exposed: the raw Codewhale listener; it stays on `127.0.0.1`.
247 - Token used: Tailscale identity gates network reachability; Codewhale still
248 uses `CODEWHALE_RUNTIME_TOKEN` for runtime control.
249 - Caveat: Tailscale Serve is private to the tailnet. Tailscale Funnel is public
250 internet exposure and belongs only in the advanced path below.
251
252 ### 3. Telegram bot
253
254 Use this when a Telegram DM should control a local Codewhale runtime. The bridge
255 uses Telegram Bot API long polling, so it does not require a public webhook URL
256 or inbound port.
257
258 Setup:
259
260 ```bash
261 CODEWHALE_RUNTIME_TOKEN="$(openssl rand -hex 32)"
262 export CODEWHALE_RUNTIME_TOKEN
263
264 codewhale app-server --http \
265 --host 127.0.0.1 \
266 --port 7878
267
268 cd integrations/telegram-bridge
269 npm install --omit=dev
270 cp .env.example .env
271 $EDITOR .env
272 npm run validate:config -- \
273 --env .env \
274 --workspace-root "$PWD/../.." \
275 --check-filesystem
276 npm start
277 ```
278
279 Env template:
280
281 ```env
282 TELEGRAM_BOT_TOKEN=replace-with-botfather-token
283
284 CODEWHALE_RUNTIME_URL=http://127.0.0.1:7878
285 CODEWHALE_RUNTIME_TOKEN=<same value used to start app-server>
286 CODEWHALE_WORKSPACE=/path/to/workspace
287 # Optional override; leave blank to inherit the runtime's configured provider/model.
288 CODEWHALE_MODEL=
289 CODEWHALE_MODE=agent
290 CODEWHALE_ALLOW_SHELL=true # grants shell execution from the bridge; set false for text-only chat
291 CODEWHALE_TRUST_MODE=false
292 CODEWHALE_AUTO_APPROVE=false
293
294 TELEGRAM_CHAT_ALLOWLIST=
295 TELEGRAM_ALLOW_UNLISTED=false
296 TELEGRAM_ALLOW_GROUPS=false
297 ```
298
299 First pairing:
300
301 ```bash
302 # Temporarily in .env:
303 TELEGRAM_ALLOW_UNLISTED=true
304 ```
305
306 DM the bot `/status`, copy the returned `chat_id` or `user_id` into
307 `TELEGRAM_CHAT_ALLOWLIST`, then set `TELEGRAM_ALLOW_UNLISTED=false` and restart
308 the bridge.
309
310 Validation:
311
312 ```bash
313 codewhale doctor --json
314 curl -fsS http://127.0.0.1:7878/health
315 npm run validate:config -- \
316 --env .env \
317 --workspace-root "$PWD/../.." \
318 --check-filesystem
319 ```
320
321 Trust boundary:
322
323 - Exposed: no inbound Codewhale port. Telegram sees messages sent to the bot.
324 - Not exposed: Codewhale remains on `127.0.0.1`; provider keys stay in the
325 runtime env, not the Telegram env.
326 - Tokens used: `TELEGRAM_BOT_TOKEN` for Telegram, `CODEWHALE_RUNTIME_TOKEN` for
327 bridge-to-runtime calls, and `TELEGRAM_CHAT_ALLOWLIST` for user/chat gating.
328 - Caveat: direct messages are the intended MVP control surface. Group control is
329 off unless `TELEGRAM_ALLOW_GROUPS=true`.
330
331 ### 4. Feishu/Lark bot
332
333 Use this when a Feishu or Lark chat should control the local runtime. The bridge
334 uses the Lark/Feishu long-connection SDK, so the first version does not need a
335 public webhook URL.
336
337 Setup:
338
339 ```bash
340 CODEWHALE_RUNTIME_TOKEN="$(openssl rand -hex 32)"
341 export CODEWHALE_RUNTIME_TOKEN
342
343 codewhale app-server --http \
344 --host 127.0.0.1 \
345 --port 7878
346
347 cd integrations/feishu-bridge
348 npm install --omit=dev
349 cp .env.example .env
350 $EDITOR .env
351 npm run validate:config -- \
352 --env .env \
353 --workspace-root "$PWD/../.." \
354 --check-filesystem
355 npm start
356 ```
357
358 Env template:
359
360 ```env
361 FEISHU_APP_ID=cli_xxxxxxxxxxxxxxxx
362 FEISHU_APP_SECRET=replace-with-app-secret
363 FEISHU_DOMAIN=feishu # international Lark users: set to "lark"
364
365 CODEWHALE_RUNTIME_URL=http://127.0.0.1:7878
366 CODEWHALE_RUNTIME_TOKEN=<same value used to start app-server>
367 CODEWHALE_WORKSPACE=/path/to/workspace
368 # Optional override; leave blank to inherit the runtime's configured provider/model.
369 CODEWHALE_MODEL=
370 CODEWHALE_MODE=agent
371 CODEWHALE_ALLOW_SHELL=true # grants shell execution from the bridge; set false for text-only chat
372 CODEWHALE_TRUST_MODE=false
373 CODEWHALE_AUTO_APPROVE=false
374
375 CODEWHALE_CHAT_ALLOWLIST=
376 CODEWHALE_ALLOW_UNLISTED=false
377 FEISHU_ALLOW_GROUPS=false
378 ```
379
380 First pairing:
381
382 Temporarily set `CODEWHALE_ALLOW_UNLISTED=true`, message the app once, copy the
383 logged open id into `CODEWHALE_CHAT_ALLOWLIST`, then set
384 `CODEWHALE_ALLOW_UNLISTED=false` and restart the bridge.
385
386 Validation:
387
388 ```bash
389 codewhale doctor --json
390 curl -fsS http://127.0.0.1:7878/health
391 npm run validate:config -- \
392 --env .env \
393 --workspace-root "$PWD/../.." \
394 --check-filesystem
395 ```
396
397 Trust boundary:
398
399 - Exposed: no inbound Codewhale port. Feishu/Lark sees messages sent to the app.
400 - Not exposed: Codewhale remains on `127.0.0.1`; provider keys stay in runtime
401 config.
402 - Tokens used: `FEISHU_APP_ID` / `FEISHU_APP_SECRET` for the platform,
403 `CODEWHALE_RUNTIME_TOKEN` for bridge-to-runtime calls, and
404 `CODEWHALE_CHAT_ALLOWLIST` for chat gating.
405 - Caveat: group control is off unless explicitly enabled.
406
407 ### 5. Weixin personal bridge
408
409 Use this when a personal Weixin account should control the local runtime by QR
410 login. This is not a public account webhook. The bridge initiates long polling
411 and does not need a public port.
412
413 Setup:
414
415 ```bash
416 CODEWHALE_RUNTIME_TOKEN="$(openssl rand -hex 32)"
417 export CODEWHALE_RUNTIME_TOKEN
418
419 codewhale app-server --http \
420 --host 127.0.0.1 \
421 --port 7878
422
423 cd integrations/weixin-bridge
424 npm install --omit=dev
425 cp .env.example .env
426 $EDITOR .env
427 npm run check
428 npm start
429 ```
430
431 Env template:
432
433 ```env
434 CODEWHALE_RUNTIME_URL=http://127.0.0.1:7878
435 CODEWHALE_RUNTIME_TOKEN=<same value used to start app-server>
436 CODEWHALE_WORKSPACE=/path/to/workspace
437 # Optional override; leave blank to inherit the runtime's configured provider/model.
438 CODEWHALE_MODEL=
439 CODEWHALE_MODE=agent
440 CODEWHALE_ALLOW_SHELL=true # grants shell execution from the bridge; set false for text-only chat
441 CODEWHALE_TRUST_MODE=false
442 CODEWHALE_AUTO_APPROVE=false
443
444 WEXIN_CHAT_ALLOWLIST=
445 WEXIN_ALLOW_UNLISTED=false
446 WEXIN_STATE_DIR=/var/lib/codewhale-weixin-bot-bridge
447 ```
448
449 First pairing:
450
451 Set `WEXIN_ALLOW_UNLISTED=true`, start the bridge, scan the QR code, send
452 `/status`, copy the returned `user_id` into `WEXIN_CHAT_ALLOWLIST`, then set
453 `WEXIN_ALLOW_UNLISTED=false` and restart the bridge.
454
455 Validation:
456
457 ```bash
458 codewhale doctor --json
459 curl -fsS http://127.0.0.1:7878/health
460 npm run check
461 ```
462
463 Trust boundary:
464
465 - Exposed: no inbound Codewhale port. The personal Weixin session and the
466 bridge state directory become sensitive local state.
467 - Not exposed: Codewhale remains on `127.0.0.1`; provider keys stay in runtime
468 config.
469 - Tokens used: the scanned Weixin login/session state for platform access,
470 `CODEWHALE_RUNTIME_TOKEN` for bridge-to-runtime calls, and
471 `WEXIN_CHAT_ALLOWLIST` for user gating.
472 - Caveat: this is a personal-account bridge. Treat the host and state directory
473 like a logged-in phone session.
474
475 ### 6. Public webhook / Funnel (Advanced)
476
477 Use this only when the user explicitly chooses public internet reachability,
478 understands that the URL can be reached outside the tailnet, and has a reason
479 that Tailscale Serve or long polling cannot satisfy.
480
481 Preferred advanced pattern:
482
483 ```bash
484 CODEWHALE_RUNTIME_TOKEN="$(openssl rand -hex 32)"
485 export CODEWHALE_RUNTIME_TOKEN
486
487 codewhale app-server --mobile \
488 --host 127.0.0.1 \
489 --port 7878
490
491 tailscale funnel --bg --https=443 localhost:7878
492 ```
493
494 Env template:
495
496 ```env
497 CODEWHALE_RUNTIME_URL=https://<public-name>
498 CODEWHALE_RUNTIME_TOKEN=<openssl-rand-hex-32>
499 PUBLIC_EXPOSURE_ACK=true
500 ```
501
502 Validation:
503
504 ```bash
505 codewhale doctor --json
506 curl -fsS http://127.0.0.1:7878/health
507 curl -fsS https://<public-name>/health
508 curl -fsS \
509 -H @<(printf 'Authorization: Bearer %s\n' "$CODEWHALE_RUNTIME_TOKEN") \
510 https://<public-name>/v1/runtime/info
511 tailscale funnel status
512 ```
513
514 Trust boundary:
515
516 - Exposed: a public HTTPS endpoint, not just your tailnet.
517 - Not exposed by Codewhale directly: the backend still binds to `127.0.0.1`,
518 but the fronting layer makes selected routes reachable from the internet.
519 - Token used: `CODEWHALE_RUNTIME_TOKEN` remains mandatory for control routes.
520 - Caveat: public does not mean safe. Do not use `--insecure-no-auth`, do not bind
521 Codewhale to `0.0.0.0`, and do not call this the default.
522
523 ## Cloud/VPS posture
524
525 Cloud/VPS is a placement choice, not a trust model. The old RFC's cloud work is
526 still useful, but it should sit behind the same reachability choices:
527
528 - A VPS can run the runtime bound to `127.0.0.1`.
529 - Recommended remote access from personal devices is still Tailscale Serve.
530 - Bot bridges should use long polling / long connection where available, keeping
531 the runtime localhost-only on the host.
532 - SSH tunnels remain acceptable for ad hoc validation:
533
534 ```bash
535 ssh -L 7878:127.0.0.1:7878 <host>
536 ```
537
538 Public inbound listeners, public webhooks, and Tailscale Funnel are advanced
539 choices, not the default cloud path.
540
541 ## Prior art: Hermes Agent (reference only - do not copy)
542
543 Nous Research's Hermes Agent validates the table-driven part of this design.
544 Use it for ideas; keep Codewhale's style: Rust core, local runtime, zero-dep
545 Node bridges where possible, and plain-text replies.
546
547 - `gateway/platform_registry.py` maps to our `BridgeSpec` / access-path
548 registry: one row per platform, with setup hints, required env, validation,
549 and adapter factory.
550 - `gateway/pairing.py` maps to our allowlist / first-pairing flow.
551
552 Telegram hardening carried forward from the original RFC:
553
554 | Edge case | In Hermes | In our Telegram bridge |
555 |---|---|---|
556 | 409 polling conflict | `_looks_like_polling_conflict` | done - poll loop backs off and warns |
557 | 429 `retry_after` | rate-limit handling | done - `telegramApi` honors `parameters.retry_after` |
558 | Forum General topic id handling | send/typing split | done - omit `message_thread_id` when id is 1 on send |
559 | Stale reply anchor after restart | retry without anchor | sidestepped - no `reply_to_message_id` |
560 | Network/connect timeout retry | network error detection | partial - generic poll-loop backoff |
561 | Text batching / progress edit | progress-edit tests | deferred - plain periodic chunks |
562 | MarkdownV2 escaping | escaping helpers | deferred - plain text |
563 | Webhook mode | webhook adapter | out of default scope - long polling first |
564
565 ## Design principle: table-driven, like `ProviderSpec`
566
567 The provider registry is the model to preserve: adding a provider is one row.
568 Apply the same idea to access paths, bridges, and cloud placements so the matrix
569 grows by data.
570
571 ```text
572 AccessPath x Placement x BridgeSpec + ProviderSpec
573 ---------- --------- ---------- ------------
574 localhost local none deepseek / openai / ...
575 tailscale local/vps none provider lives in runtime.env
576 telegram local/vps telegram bridge is pure transport
577 feishu local/vps feishu bridge is pure transport
578 weixin local/vps weixin bridge is pure transport
579 funnel local/vps optional explicit public exposure
580 ```
581
582 Clean separation:
583
584 - **Provider = runtime env.** The runtime resolves provider/model/API key from
585 `CODEWHALE_PROVIDER`, provider key vars, and the provider registry. Bridges do
586 not need provider keys.
587 - **Access path = reachability.** Localhost, Tailscale Serve, chat long polling,
588 and Funnel are separate choices with different trust boundaries.
589 - **Bridge = transport.** A chat bridge forwards allowed chat messages to
590 `http://127.0.0.1:7878` with `CODEWHALE_RUNTIME_TOKEN`.
591 - **Cloud = where it runs and where secrets live.** It is not permission to
592 open port 7878.
593
594 ## Proposed command surface
595
596 Current flags are verified for the generate-only cloud/bridge wizard:
597
598 | Flag | Current status |
599 |---|---|
600 | `--cloud <lighthouse|azure|digitalocean>` | verified |
601 | `--bridge <telegram|feishu>` | verified |
602 | `--provider <slug>` | verified, provider registry-backed |
603 | `--out <dir>` | verified |
604 | `--generate-only` | verified |
605 | `--apply` | verified flag, but not implemented |
606 | `--yes` | verified flag |
607 | `--non-interactive` | verified flag |
608
609 Proposed Tailscale-first revision:
610
611 | Flag | Meaning |
612 |---|---|
613 | `--access <localhost|tailscale|telegram|feishu|weixin|funnel>` | Skip the reachability prompt. |
614 | `--placement <local|vps|lighthouse|azure|digitalocean>` | Where the runtime runs; default local. |
615 | `--bridge <telegram|feishu|weixin>` | Optional when `--access` implies a bridge. |
616 | `--provider <slug>` | Provider slug; validated against the existing provider registry. |
617 | `--out <dir>` | Bundle output dir. |
618 | `--generate-only` | Emit commands/env/runbook, do not provision. Default. |
619 | `--apply` | Future cloud CLI provisioning, behind confirmation. Still not implemented. |
620 | `--yes` | Skip final confirmation gates where safe for CI/non-interactive use. |
621 | `--non-interactive` | Fail instead of prompting for missing required values. |
622
623 The first prompt should be the reachability question, not the cloud question.
624 Tailscale should be visually marked as recommended.
625
626 ## Generated bundle
627
628 The current bundle model stays useful. Extend it so the generated runbook is
629 access-path-first.
630
631 Files:
632
633 - `runtime.env` - provider and runtime config:
634
635 ```env
636 CODEWHALE_PROVIDER=openai
637 OPENAI_API_KEY=replace-with-provider-key
638 # Optional override; leave blank to inherit the runtime's configured provider/model.
639 CODEWHALE_MODEL=
640 CODEWHALE_RUNTIME_TOKEN=<random>
641 CODEWHALE_RUNTIME_PORT=7878
642 CODEWHALE_RUNTIME_WORKERS=2
643 RUST_LOG=info
644 ```
645
646 - `<bridge>.env` - transport only when a bridge is selected:
647
648 ```env
649 CODEWHALE_RUNTIME_URL=http://127.0.0.1:7878
650 CODEWHALE_RUNTIME_TOKEN=<same random token>
651 CODEWHALE_WORKSPACE=/opt/whalebro
652 # Optional override; leave blank to inherit the runtime's configured provider/model.
653 CODEWHALE_MODEL=
654 CODEWHALE_MODE=agent
655 CODEWHALE_ALLOW_SHELL=true # grants shell execution from the bridge; set false for text-only chat
656 CODEWHALE_TRUST_MODE=false
657 CODEWHALE_AUTO_APPROVE=false
658 ```
659
660 - `codewhale-runtime.service`
661 - optional `codewhale-<bridge>.service`
662 - optional cloud artifacts: `cloud-init.yaml`, `provision.sh`, `cnb.yml`, or
663 cloud-specific runbook steps
664 - `RUNBOOK.md` with:
665 - exact setup commands
666 - env template
667 - doctor-style validation
668 - first-pairing steps for bridges
669 - trust-boundary summary
670 - explicit "public exposure acknowledged" section for Funnel/webhook modes
671
672 ## Auto-provision
673
674 Preserve the original safety model:
675
676 - `--generate-only` is the default.
677 - `--apply` is explicit and is not implemented today.
678 - Every command is rendered before execution.
679 - Secrets are not passed through shell history or argv.
680 - Cloud CLIs are placement helpers, not permission to open runtime ports.
681
682 Existing cloud target design remains accurate:
683
684 - Tencent Lighthouse: native plus systemd, env-file secrets, CNB-oriented plan.
685 - Azure VM: Docker image plus Key Vault, managed identity at boot.
686 - DigitalOcean Droplet: native plus systemd, env-file secrets, `doctl` plan.
687
688 All cloud plans should bind Codewhale to `127.0.0.1` and then layer one of the
689 reachability paths above.
690
691 ## Namespace migration: `DEEPSEEK_*` to `CODEWHALE_*`
692
693 Carry forward the convention already used in code: read `CODEWHALE_X` first,
694 fall back to `DEEPSEEK_X` where compatibility is needed.
695
696 Touch list from the original RFC remains valid:
697
698 1. Bridges: read `CODEWHALE_X ?? DEEPSEEK_X` for runtime URL/token, workspace,
699 model, mode, shell/trust/approval flags, allowlists, and timeouts. Templates
700 should emit `CODEWHALE_*`.
701 2. Deploy units: prefer `/etc/codewhale/*.env`; keep legacy path reads only for
702 compatibility where needed.
703 3. `.env.example` files and `config.example.toml`: lead with `CODEWHALE_*`,
704 document legacy aliases.
705 4. Drop DeepSeek-shaped defaults in bridge templates except where DeepSeek is
706 explicitly the chosen provider. Provider choice belongs in `runtime.env`.
707
708 ## Tests
709
710 Existing bundle tests should stay:
711
712 - Every cloud / bridge / provider triple renders.
713 - Runtime and bridge env files share the same `CODEWHALE_RUNTIME_TOKEN`.
714 - Env files lead with `CODEWHALE_*`.
715 - Generated runbooks are non-empty and list the provision plan.
716 - Provision plans are command data and are not executed in tests.
717
718 New tests for this revision:
719
720 - Every `AccessPath` row has setup commands, env template, validation commands,
721 and trust-boundary copy.
722 - Tailscale is the recommended remote path in prompt ordering.
723 - Funnel/webhook mode requires an explicit advanced/public acknowledgement.
724 - `/mobile` docs use `app-server --mobile --host 127.0.0.1` for current binary
725 behavior, or clearly mark any `--http` plus `/mobile` path as proposed.
726 - Weixin can be documented before it is in the `remote-setup` registry, but the
727 wizard must mark it proposed until a `BridgeSpec` row and validation story
728 exist.
729
730 ## Suggested sequencing
731
732 1. Revise the RFC and runbook copy to be Tailscale-first.
733 2. Add an access-path registry above the existing cloud/bridge/provider tables.
734 3. Add localhost and Tailscale generate-only bundles.
735 4. Add Weixin as a `BridgeSpec` row or explicitly hide it behind "proposed" in
736 the wizard until registry and validation support land.
737 5. Rework cloud bundles so placement is second and reachability is first.
738 6. Add Funnel/webhook only as an advanced path with explicit public-exposure
739 acknowledgement.
740 7. Implement `--apply` last, after generate-only output is reviewed.
741
742 ## Command verification ledger
743
744 Verified against Codewhale code/docs in this worktree:
745
746 - `CODEWHALE_RUNTIME_TOKEN=TOKEN codewhale app-server --http --host 127.0.0.1 --port 7878`
747 - `CODEWHALE_RUNTIME_TOKEN=TOKEN codewhale app-server --mobile --host 127.0.0.1 --port 7878`
748 - `codewhale doctor --json`
749 - `curl /health` and authenticated `curl /v1/runtime/info`
750 - `npm run validate:config` for Telegram and Feishu bridges
751 - `npm run check` for the Weixin bridge
752 - Existing `remote-setup` generate-only flags listed above
753
754 Marked proposed or external:
755
756 - `codewhale remote-setup --access ...` and access-path registry
757 - first-class Tailscale, localhost, Weixin, and Funnel choices in the wizard
758 - `--apply` execution
759 - Tailscale CLI commands (`tailscale serve ...`, `tailscale funnel ...`) are
760 external Tailscale commands. They are the intended RFC examples, but they are
761 not Codewhale CLI flags.
762
762 lines MARKDOWN