返回 CodeWhale
WEB.md
根目录 / docs / WEB.md
1 # Local browser client
2
3 > 阅读简体中文版:[zh_hans/WEB.md](zh_hans/WEB.md)。
4
5 `codewhale web` opens Codewhale's embedded browser client over the canonical
6 Runtime API. It is a local surface: the server always binds to
7 `127.0.0.1`, cannot be rebound to a LAN address, and cannot run with Runtime
8 authentication disabled.
9
10 ## Start it
11
12 From the workspace Codewhale should operate in, run:
13
14 ```bash
15 codewhale web
16 ```
17
18 The default address is `http://127.0.0.1:7878`. To avoid a local port
19 collision, choose another loopback port:
20
21 ```bash
22 codewhale web --port 8788
23 ```
24
25 Codewhale starts the Runtime API, serves the dependency-free client embedded
26 in the installed binary, prints a single-use launch URL, and asks the operating
27 system to open that URL in the default browser. If the browser does not open,
28 use the printed URL within ten minutes. Stop the process with `Ctrl+C`; the
29 browser session ends with it.
30
31 ## What the browser can do
32
33 The embedded client provides a responsive thread and search rail, Runtime-owned
34 session facts, transcript and tool receipts, and a composer. It can create,
35 select, rename, and archive threads; start or steer turns; interrupt work;
36 resolve approvals; and answer Runtime user-input requests.
37
38 New threads use the configured provider and model by default. Named custom
39 routes retain their exact `[providers.<name>]` identity when loading models
40 and creating threads, including when several routes share the `custom` kind.
41 Selecting a route for a new thread does not change the Runtime defaults.
42 Provider endpoints and credentials are configured on the server; this dialog
43 only selects an existing route and model.
44
45 The browser is another view of the same local Runtime. It does not create a
46 second cloud account, copy provider credentials into browser storage, or
47 weaken the configured approval and sandbox policies.
48
49 ## Serving the shared app build
50
51 `codewhale web` serves the embedded client by default. You can instead serve
52 the shared web app (the `apps/web` build from the `codewhale-app` repository)
53 from a directory on disk. This is opt-in; the embedded client remains the
54 default until the shared build reaches parity.
55
56 With Engine 0.10.5 or later, build the local Engine client from the root of
57 a `codewhale-app` checkout:
58
59 ```bash
60 npm run build:engine -w apps/web
61 ```
62
63 From the workspace where you want to use Codewhale, point the Engine at the
64 build's absolute path:
65
66 ```bash
67 CODEWHALE_WEB_DIST="/path/to/codewhale-app/apps/web/dist-engine" codewhale web
68 ```
69
70 If you have access to the App repository's Desktop workflow, you can also
71 download its `codewhale-web-dist-engine` artifact. Extract it and point
72 `CODEWHALE_WEB_DIST` at the directory containing `index.html`.
73
74 The directory must contain `index.html`, and neither the directory nor
75 `index.html` may be a symlink. When the variable is set to a valid directory,
76 startup prints a line naming the directory being served. When the variable is
77 unset or empty, the embedded client is served as before.
78
79 A set but invalid value is not ignored: `codewhale web` refuses to start and
80 prints the reason (the path is not a directory, is a symlink, or has no
81 `index.html`). Fix or unset the variable and run the command again.
82
83 When a Codewhale is already running (an open terminal session, for example),
84 `codewhale web` attaches to it, and that running Codewhale decides which
85 client is served from the environment it was started with. If the directory
86 you asked for is not the one it serves, the command stops and says so instead
87 of opening the other client: quit the running Codewhale and start
88 `codewhale web` again, or unset the variable. When the running Codewhale
89 serves a directory, the attach prints the same line naming it.
90
91 What is served from the directory:
92
93 - `index.html` at `/`, and for extensionless paths, so client-side routes such
94 as `/settings/plugins` load the app.
95 - `/plugin-host.html`, the document the app frames for plugin UI.
96 - `/widget-host.html`, the sandboxed widget frame. A build with a matching inline-script hash supports widget previews. The frame cannot access the network.
97 - `/static/*`, the build's hashed assets.
98
99 `/v1`, `/api` and `/__codewhale` stay reserved for the Runtime API and the
100 bootstrap exchange; the directory never shadows them. Other `.html` files,
101 unknown file types and non-`GET`/`HEAD` requests return `404`.
102
103 The authentication boundary above is unchanged. `codewhale web` requires
104 Runtime authentication, and the Engine refuses `--insecure` for web.
105
106 ## Authentication boundary
107
108 The browser-launch URL contains a random, short-lived, one-time bootstrap
109 capability. It never contains the Runtime bearer token. A loopback request
110 exchanges the capability for an `HttpOnly`, `SameSite=Strict`, process-local
111 session cookie and immediately invalidates the capability.
112
113 Reused, expired, malformed, and non-loopback bootstrap attempts fail closed.
114 The Runtime token is not placed in rendered HTML, browser storage, URL
115 queries or fragments, or browser-launch arguments. The one-time bootstrap
116 value is printed in the local terminal and briefly passes through the operating
117 system's browser launcher. It is single-use and expires after ten minutes, but
118 a hostile process already running as the same OS user remains inside the local
119 trust boundary.
120
121 Cookie-authenticated state-changing requests must also present the exact
122 local web origin. Cross-origin browser requests are rejected. Existing
123 explicit bearer and Runtime-token-header clients retain their normal Runtime
124 API behavior.
125
126 ## Local means local
127
128 `codewhale web` accepts only `--port`; there is no `--host` or insecure-auth
129 option on this command. Do not treat it as a public website or expose its port
130 directly through router forwarding, a public reverse proxy, or a tunnel.
131
132 The separate `codewhale app-server --mobile` and `--http` modes have different
133 deployment and authentication contracts. Read [RUNTIME_API.md](RUNTIME_API.md)
134 before operating either one, especially before selecting a non-loopback bind.
135
136 ## Troubleshooting
137
138 - If port `7878` is occupied, pass an unused `--port` value.
139 - If the browser does not open, copy the printed single-use bootstrap URL into
140 a browser on the same machine within ten minutes. Start `codewhale web` again
141 if that URL has already been used or expired.
142 - If the page loads but a provider is unavailable, inspect `codewhale doctor`
143 and `/provider`; the web command does not configure or move provider
144 credentials.
145 - If a session expired, stop and restart `codewhale web` to mint a new
146 process-local session. Reusing an old bootstrap URL is expected to fail.
147 - A new tab opened by typing the address is not signed in: the session's
148 request proof stays in the tab that opened it. Use that tab, duplicate it,
149 or restart `codewhale web`.
150
151 For integration endpoints, headers, events, and the complete web-session
152 contract, see [RUNTIME_API.md](RUNTIME_API.md).
153
153 lines MARKDOWN