@yanzc/claude-pro 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,332 @@
1
+ // The 后台会话 of the web console: sessions that run inside the console's own process, each an App with no terminal
2
+ // (what it prints goes to the console's live view), instead of a claude-pro process (and a supervisor) of their own
3
+ // in a hidden window. One process for all of them, as DeepSeek Harness runs its sessions: about 90 MB less per
4
+ // session. What a session owns in the process (background shells, REPL interpreters, browser tabs) is kept apart by
5
+ // its config.owner (see tools/bash.js, code.js, browser.js).
6
+ //
7
+ // New code (a change of the source, an update, the Restart tool, /restart) can only be loaded by a new process, so
8
+ // the console restarts with all its sessions at once, when none of them is working: each leaves its state (as a
9
+ // supervised session does, see App.restartState) in a hand-over file, and the next process takes them all up again
10
+ // with the same ids, so that open pages carry on. /cd needs no new code: that session alone starts again, at once.
11
+ // The sessions running are also listed in a file, so that a console that went away without a hand-over (a crash, a
12
+ // kill) brings them back when it starts again.
13
+
14
+ import fs from 'node:fs';
15
+ import path from 'node:path';
16
+ import { PassThrough, Writable } from 'node:stream';
17
+ import { CONFIG_DIR, INSTALL_DIR, VERSION, APP_NAME } from '../config.js';
18
+ import { runSelfCheck, watchSource, reloadTiming, RESTART_EXIT_CODE, MAX_RESTARTS, RESTART_WINDOW_MS } from '../restart.js';
19
+ import { installedByNpm, installedVersion, isNewer } from '../updater.js';
20
+ import { listPeers } from '../peers.js';
21
+ import { REMOTE_WIDTH } from '../remote.js';
22
+
23
+ export const rosterFile = () => path.join(CONFIG_DIR, 'web-running.json');
24
+ export const handoffFile = () => path.join(CONFIG_DIR, 'web-handoff.json');
25
+ const errorLog = () => path.join(CONFIG_DIR, 'web-errors.log');
26
+ export const hostTiming = { idleMs: 30 * 60_000, emptyQuietMs: 2000, recheckMs: 5000, handoffMaxAgeMs: 10 * 60_000, startMs: 20_000 };
27
+
28
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
29
+ const alive = (pid) => { try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; } };
30
+ const readJson = (file) => { try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return null; } };
31
+ function writeJson(file, data) {
32
+ fs.mkdirSync(path.dirname(file), { recursive: true });
33
+ const tmp = `${file}.${process.pid}.tmp`;
34
+ fs.writeFileSync(tmp, JSON.stringify(data), { mode: 0o600 });
35
+ fs.renameSync(tmp, file);
36
+ }
37
+
38
+ // The streams an App takes for its terminal: keys nobody types, and output nobody reads (HeadlessScreen draws
39
+ // nothing anyway), as wide as the live view lays things out.
40
+ function noTerminal() {
41
+ const stdin = new PassThrough();
42
+ stdin.isTTY = false;
43
+ stdin.setRawMode = () => stdin;
44
+ const stdout = new Writable({ write(_chunk, _enc, cb) { cb(); } });
45
+ Object.assign(stdout, { isTTY: false, columns: REMOTE_WIDTH, rows: 40 });
46
+ return { stdin, stdout };
47
+ }
48
+
49
+ export class SessionHost {
50
+ // `restartProcess()`: a new console process takes over (the hand-over file is written), and this one ends.
51
+ constructor({ restartProcess = () => {} } = {}) {
52
+ this.apps = new Set();
53
+ this.restartProcess = restartProcess;
54
+ this.requests = new Map(); // app -> the restart it asked for ({reason, then, continueTurn}), until all are idle
55
+ this.told = new Map(); // app -> whom it was last told its restart waits for
56
+ this.source = null; // a change of the program's source not loaded yet: {key, inTurn, quietAt, update}
57
+ this.failed = null; // the key of the change whose new code did not start (said once)
58
+ this.restarting = false;
59
+ this.checking = false;
60
+ this.updating = false;
61
+ this.recovering = false;
62
+ this.launching = 0; // sessions starting (a /cd starts one again under the same id)
63
+ this.startedAt = Date.now();
64
+ this.restartTimes = []; // when the console restarted lately (carried over by the hand-over): a loop is refused
65
+ this.timer = null;
66
+ this.watcher = null;
67
+ this.rosterTimer = setInterval(() => this.saveRoster(), 60_000); // (the model of each, which changes in between)
68
+ this.rosterTimer.unref();
69
+ this.idleSince = new Map(); // app -> since when nothing has gone on in it and no page has watched it
70
+ this.reapTimer = setInterval(() => this.reap(), 60_000);
71
+ this.reapTimer.unref();
72
+ }
73
+
74
+ get size() { return this.apps.size; }
75
+
76
+ beginUpdate() {
77
+ if (this.updating || this.restarting || this.checking || this.recovering || this.launching || [...this.apps].some((app) => !this.ready(app))) return false;
78
+ this.updating = true;
79
+ return true;
80
+ }
81
+
82
+ endUpdate(restart) {
83
+ this.updating = false;
84
+ if (restart) this.requestHandover();
85
+ else this.check();
86
+ }
87
+
88
+ log(e, what = '') {
89
+ try { fs.appendFileSync(errorLog(), `${new Date().toISOString()} ${what}${what ? ': ' : ''}${e?.stack || e}\n`); } catch { /* nowhere to say it */ }
90
+ }
91
+
92
+ // A session: new in `cwd`, a saved one (`resumeFile`, `resumeId`), or one taken up again (`restart`: the state it
93
+ // left). Resolves with its App once the console's page can reach it.
94
+ async launch({ cwd, restart = null, resumeFile = null, resumeId = null, initialChoices = null }) {
95
+ this.launching++;
96
+ try {
97
+ return await this.startApp({ cwd, restart, resumeFile, resumeId, initialChoices });
98
+ } finally {
99
+ this.launching--;
100
+ this.check();
101
+ }
102
+ }
103
+
104
+ async startApp({ cwd, restart, resumeFile, resumeId, initialChoices }) {
105
+ const { App } = await import('../ui/repl.js');
106
+ const flags = initialChoices ? { initialChoices } : {};
107
+ if (restart) flags.restart = restart;
108
+ else if (resumeFile) Object.assign(flags, { resumeFile, resumeId });
109
+ const { stdin, stdout } = noTerminal();
110
+ const app = new App({ flags, cwd, stdin, stdout, host: this });
111
+ this.apps.add(app);
112
+ const ended = app.start('').catch((e) => {
113
+ this.log(e, `session in ${cwd}`);
114
+ try { app.exit(1); } catch { /* half started */ }
115
+ });
116
+ ended.finally(() => {
117
+ this.apps.delete(app);
118
+ this.requests.delete(app);
119
+ this.told.delete(app);
120
+ this.idleSince.delete(app);
121
+ if (!this.restarting) { this.saveRoster(); this.check(); }
122
+ });
123
+ // up: its runtime exists (its peer server, which the page talks to, comes before it)
124
+ const until = Date.now() + hostTiming.startMs;
125
+ while (!app.runtime && !app.exiting && Date.now() < until) await sleep(50);
126
+ this.saveRoster();
127
+ return app;
128
+ }
129
+
130
+ // A session nobody works in or looks at for a while is put away: opening the conversation (or sending to it) takes
131
+ // it up again in a tenth of a second, so the page does not tell running and saved conversations apart, and what
132
+ // the console holds is what is in use. Not one that works, asks, has something queued or running in the background,
133
+ // or waits for a restart.
134
+ reap(now = Date.now()) {
135
+ if (this.restarting) return;
136
+ for (const app of this.apps) {
137
+ if (app.exiting || !app.runtime) continue;
138
+ const busy = app.working() || this.requests.has(app) || app.liveFeed?.active;
139
+ if (busy || !this.idleSince.has(app)) { this.idleSince.set(app, now); continue; }
140
+ if (now - this.idleSince.get(app) >= hostTiming.idleMs) {
141
+ try {
142
+ if (!app.flushUnsavedConversation()) continue;
143
+ this.idleSince.delete(app);
144
+ app.exit(0);
145
+ } catch (e) { this.log(e, 'put away'); }
146
+ }
147
+ }
148
+ }
149
+
150
+ // /cd in one session: it alone starts again, in the new directory, with the state it left.
151
+ relaunch(app, state) {
152
+ app.exit(RESTART_EXIT_CODE, { restart: true });
153
+ this.launch({ cwd: state.cwd, restart: state }).catch((e) => this.log(e, 'relaunch'));
154
+ }
155
+
156
+ // The sessions the page reaches through peer servers (see peers.js), by id: waited for while the console takes
157
+ // them up again (a hand-over, a start after a crash), so that an open page does not take one for gone.
158
+ async waitForPeer(peerId, ms = 8000) {
159
+ const until = Date.now() + ms;
160
+ for (;;) {
161
+ const peer = listPeers().find((p) => p.id === peerId);
162
+ if (peer) return peer;
163
+ if (!(this.recovering || this.launching || Date.now() - this.startedAt < 30_000) || Date.now() > until) return null;
164
+ await sleep(200);
165
+ }
166
+ }
167
+
168
+ // ---------------------------------------------------------------- the list of sessions, and bringing them back
169
+
170
+ saveRoster() {
171
+ if (this.restarting) return;
172
+ const sessions = [...this.apps].filter((a) => !a.exiting && a.store).map((a) => ({
173
+ sessionId: a.store.id,
174
+ sessionFile: a.store.file,
175
+ cwd: a.cwd,
176
+ peerId: a.peers?.id || null,
177
+ peerName: a.peers?.name || a.sessionName || null,
178
+ modelOverride: a.runtime?.config.modelOverride ?? null,
179
+ effortOverride: a.runtime?.config.effortOverride ?? null,
180
+ used: a.inUse(),
181
+ }));
182
+ try { writeJson(rosterFile(), { pid: process.pid, at: Date.now(), sessions }); } catch (e) { this.log(e, 'roster'); }
183
+ }
184
+
185
+ // At the start of the console: the sessions the console before it handed over, or else those it was running when
186
+ // it went away without a word.
187
+ async recover() {
188
+ this.recovering = true;
189
+ try {
190
+ let states = null;
191
+ const handoff = readJson(handoffFile());
192
+ try { fs.rmSync(handoffFile(), { force: true }); } catch { /* read once anyway */ }
193
+ if (handoff && Array.isArray(handoff.states) && Date.now() - handoff.at < hostTiming.handoffMaxAgeMs) {
194
+ states = handoff.states;
195
+ this.restartTimes = (handoff.restarts || []).filter(Number.isFinite);
196
+ } else {
197
+ const roster = readJson(rosterFile());
198
+ if (roster && roster.pid !== process.pid && !alive(roster.pid) && Array.isArray(roster.sessions)) {
199
+ states = roster.sessions.map((s) => ({ ...s, reason: 'the web console started again', restarts: [] }));
200
+ }
201
+ }
202
+ for (const state of states || []) {
203
+ if (!state || typeof state.cwd !== 'string' || !fs.existsSync(state.cwd)) continue;
204
+ await this.launch({ cwd: state.cwd, restart: state }).catch((e) => this.log(e, 'recover'));
205
+ }
206
+ } finally {
207
+ this.recovering = false;
208
+ this.saveRoster();
209
+ this.check();
210
+ }
211
+ }
212
+
213
+ // ---------------------------------------------------------------- new code: the console restarts
214
+
215
+ // Follow the program's source, as a supervised session does (App.startSourceWatch): a change made while a session
216
+ // works is its work, loaded when the sessions are idle; one made while all are idle is loaded once the source has
217
+ // been left alone for a few minutes (a few seconds when there is no session to restart).
218
+ watch() {
219
+ // (the page too: the server serves the page it started with, so that page and API always match)
220
+ this.watcher = watchSource(INSTALL_DIR, () => this.noteChange());
221
+ }
222
+
223
+ noteChange({ now = false } = {}) {
224
+ const disk = installedVersion();
225
+ const update = installedByNpm() && disk !== VERSION && isNewer(disk, VERSION) ? disk : null;
226
+ const inTurn = [...this.apps].some((a) => a.isTurnRunning());
227
+ const quiet = this.apps.size ? reloadTiming.quietMs + Math.random() * reloadTiming.spreadMs : hostTiming.emptyQuietMs;
228
+ this.source = { key: `${Date.now()}`, inTurn: inTurn || Boolean(this.source?.inTurn) || now, update, quietAt: Date.now() + quiet };
229
+ this.check();
230
+ }
231
+
232
+ // A newer console (another version) was started: this one gives way once its sessions are idle.
233
+ requestHandover() { this.noteChange({ now: true }); }
234
+
235
+ // A session asks for a restart (the Restart tool, /restart, an update): done when all sessions are idle.
236
+ restartFor(app, request) {
237
+ this.requests.set(app, request || {});
238
+ this.check();
239
+ }
240
+
241
+ restartWaits(app) { return this.requests.has(app); }
242
+
243
+ // Ready for the restart: not working (a turn, a question open, something queued, a background shell or agent). The
244
+ // session that asked is ready once its turn is over: what it queued goes along, and it said what may be stopped.
245
+ ready(app) {
246
+ if (app.exiting) return true;
247
+ if (!app.runtime) return false; // still starting
248
+ if (this.requests.has(app)) return !app.isTurnRunning() && !app.dialogs.length;
249
+ return !app.working() && !app.reloading && !app.restartRequest;
250
+ }
251
+
252
+ check() {
253
+ if (this.restarting || this.checking || this.updating || this.launching || this.recovering) return;
254
+ clearTimeout(this.timer);
255
+ const sourceDue = this.source && this.source.key !== this.failed;
256
+ if (!this.requests.size && !sourceDue) return;
257
+ if (!this.requests.size && !this.source.inTurn && !this.source.update && Date.now() < this.source.quietAt) {
258
+ this.timer = setTimeout(() => this.check(), this.source.quietAt - Date.now() + 50);
259
+ this.timer.unref?.();
260
+ return;
261
+ }
262
+ const busy = [...this.apps].filter((a) => !this.ready(a));
263
+ if (busy.length) {
264
+ const names = busy.map((a) => `@${a.peerLabel()}`).join(', ');
265
+ for (const app of this.requests.keys()) {
266
+ if (this.told.get(app) === names) continue;
267
+ this.told.set(app, names);
268
+ app.notice(`The restart waits until ${names} ${busy.length === 1 ? 'is' : 'are'} idle: the web console restarts all its sessions together.`);
269
+ }
270
+ // a turn's end checks again (App.maybeAutoReload); a background shell or agent that ends does not
271
+ this.timer = setTimeout(() => this.check(), hostTiming.recheckMs);
272
+ this.timer.unref?.();
273
+ return;
274
+ }
275
+ this.restart().catch((e) => { this.restarting = false; this.log(e, 'restart'); });
276
+ }
277
+
278
+ async restart() {
279
+ this.checking = true;
280
+ let check;
281
+ try { check = await runSelfCheck(); } finally { this.checking = false; }
282
+ if (!check.ok) {
283
+ this.failed = this.source?.key ?? null;
284
+ const asked = [...this.requests.keys()];
285
+ this.requests.clear();
286
+ for (const app of this.apps) {
287
+ app.notice(`The new code of ${APP_NAME} does not start, so the web console was not restarted${asked.includes(app) ? ' (as this session asked)' : ''}:\n${check.output.split('\n').slice(0, 12).join('\n')}\nFix it; the restart follows by itself (or run /restart).`, 'warn');
288
+ }
289
+ return;
290
+ }
291
+ if (this.launching || this.recovering || [...this.apps].some((a) => !this.ready(a))) { this.check(); return; } // something started meanwhile
292
+ const now = Date.now();
293
+ this.restartTimes = this.restartTimes.filter((t) => now - t < RESTART_WINDOW_MS);
294
+ if (this.restartTimes.length >= MAX_RESTARTS) {
295
+ this.failed = this.source?.key ?? null;
296
+ this.requests.clear();
297
+ for (const app of this.apps) app.notice(`The web console restarted ${this.restartTimes.length} times in the last ${Math.round(RESTART_WINDOW_MS / 60_000)} minutes, so it does not restart again by itself now: that looks like a loop. A change after that window loads it, or /restart once it has passed.`, 'warn');
298
+ return;
299
+ }
300
+ this.restarting = true;
301
+ clearTimeout(this.timer);
302
+ const why = this.source?.update ? `updated to ${APP_NAME} ${this.source.update}` : this.source ? 'source changed' : '';
303
+ const asked = [...this.requests.values()][0];
304
+ const states = [];
305
+ for (const app of this.apps) {
306
+ if (app.exiting) continue;
307
+ const own = this.requests.get(app);
308
+ // the others: why the console restarted (a change of the source, or what another session asked for)
309
+ const request = own || { reason: why || `web console restarted${asked?.reason ? ` (${asked.reason})` : ''}` };
310
+ try { states.push(app.restartState(request, { counts: Boolean(own) })); } catch (e) { this.log(e, 'restart state'); }
311
+ }
312
+ try {
313
+ writeJson(handoffFile(), { at: now, states, restarts: [...this.restartTimes, now] });
314
+ } catch (e) {
315
+ this.restarting = false;
316
+ this.requests.clear();
317
+ for (const app of this.apps) app.notice(`Could not restart the web console: ${e.message}`, 'warn');
318
+ return;
319
+ }
320
+ for (const app of [...this.apps]) {
321
+ try { app.exit(RESTART_EXIT_CODE, { restart: true }); } catch (e) { this.log(e, 'exit'); }
322
+ }
323
+ this.restartProcess();
324
+ }
325
+
326
+ close() {
327
+ clearTimeout(this.timer);
328
+ clearInterval(this.rosterTimer);
329
+ clearInterval(this.reapTimer);
330
+ this.watcher?.close();
331
+ }
332
+ }
@@ -0,0 +1,67 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content">
6
+ <meta name="robots" content="noindex">
7
+ <title>登录 · claude-pro 控制台</title>
8
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg">
9
+ <style>
10
+ :root { color-scheme: light dark; }
11
+ *, *::before, *::after { box-sizing: border-box; }
12
+ body { margin: 0; min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 16px; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei UI", "PingFang SC", sans-serif; background: #f6f7f9; color: #111827; }
13
+ main { width: min(430px, 100%); background: #fff; border: 1px solid #e3e6eb; border-radius: 16px; padding: 28px 24px 24px; box-shadow: 0 10px 34px rgba(0, 0, 0, .07); overflow-wrap: anywhere; }
14
+ .logo { display: block; width: 44px; height: 44px; border-radius: 12px; margin-bottom: 14px; box-shadow: 0 6px 18px rgba(194, 88, 54, .28); }
15
+ h1 { font-size: 20px; margin: 0 0 4px; }
16
+ p { margin: 0 0 18px; color: #6b7280; font-size: 13.5px; }
17
+ input[type=password] { width: 100%; box-sizing: border-box; padding: 11px 13px; border: 1px solid #cfd4dc; border-radius: 10px; font: inherit; background: transparent; color: inherit; outline: none; }
18
+ input[type=password]:focus { border-color: #d97757; box-shadow: 0 0 0 3px rgba(217, 119, 87, .18); }
19
+ label.remember { display: flex; align-items: center; gap: 8px; margin: 12px 0 16px; font-size: 13.5px; color: #374151; }
20
+ button { width: 100%; padding: 11px; border: 0; border-radius: 10px; background: #d97757; color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
21
+ button:disabled { opacity: .6; }
22
+ .error { min-height: 20px; margin-top: 10px; color: #dc2626; font-size: 13.5px; }
23
+ @media (max-width: 860px) {
24
+ input[type=password] { font-size: 16px; }
25
+ label.remember { min-height: 44px; margin: 4px 0 8px; }
26
+ }
27
+ @media (prefers-color-scheme: dark) {
28
+ body { background: #0f1115; color: #e5e7eb; }
29
+ main { background: #171a21; border-color: #2a2f3a; }
30
+ input[type=password] { border-color: #3a404d; }
31
+ label.remember { color: #cbd0d8; }
32
+ p { color: #9aa1ad; }
33
+ }
34
+ </style>
35
+ </head>
36
+ <body>
37
+ <main>
38
+ <img class="logo" src="/favicon.svg" alt="claude-pro" width="44" height="44">
39
+ <h1>claude-pro 控制台</h1>
40
+ <p>这是一台电脑上的 claude-pro。输入在 claude-pro 里设置的远程访问密码。</p>
41
+ <form id="f">
42
+ <input type="password" id="pw" placeholder="密码" autocomplete="current-password" autofocus required>
43
+ <label class="remember"><input type="checkbox" id="remember" checked> 记住这台设备 30 天</label>
44
+ <button type="submit" id="go">登录</button>
45
+ <div class="error" id="err"></div>
46
+ </form>
47
+ </main>
48
+ <script>
49
+ document.getElementById("f").addEventListener("submit", async (e) => {
50
+ e.preventDefault();
51
+ const go = document.getElementById("go"), err = document.getElementById("err");
52
+ go.disabled = true;
53
+ err.textContent = "";
54
+ try {
55
+ const res = await fetch("/__login", { method: "POST", headers: { "content-type": "application/json" }, credentials: "same-origin", body: JSON.stringify({ password: document.getElementById("pw").value, remember: document.getElementById("remember").checked }) });
56
+ const data = await res.json().catch(() => ({}));
57
+ if (res.ok) { location.replace("/"); return; }
58
+ err.textContent = data.error || ("登录失败 (" + res.status + ")");
59
+ } catch (ex) {
60
+ err.textContent = "连不上:" + ex.message;
61
+ } finally {
62
+ go.disabled = false;
63
+ }
64
+ });
65
+ </script>
66
+ </body>
67
+ </html>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><linearGradient id="g" x1="8" y1="4" x2="56" y2="60" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#E58C6B"/><stop offset="1" stop-color="#BC4C2A"/></linearGradient></defs><rect width="64" height="64" rx="15" fill="url(#g)"/><path d="M43 20.8A15 15 0 1 0 43 43.2" fill="none" stroke="#fff" stroke-width="7.5" stroke-linecap="round"/><path d="M47 24L49 30L55 32L49 34L47 40L45 34L39 32L45 30Z" fill="#fff"/></svg>
@@ -0,0 +1,44 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, interactive-widget=resizes-content">
6
+ <title>claude-pro 控制台</title>
7
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg">
8
+ <link rel="stylesheet" href="/app.css">
9
+ <script src="/app.js" defer></script>
10
+ </head>
11
+ <body>
12
+ <div class="app">
13
+ <aside class="side" id="sideDrawer">
14
+ <div class="brand"><img class="brand-logo" src="/favicon.svg" alt="" width="28" height="28"><strong>claude-pro</strong><span class="brand-tag">CONSOLE</span><span class="brand-release"><span class="brand-ver" id="brandVersion"></span><button type="button" class="brand-update hidden" id="brandUpdate" aria-label="更新">↑</button></span></div>
15
+ <a class="side-new" href="#/new" data-nav="new"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="12" cy="12" r="9"/><path d="M12 8v8M8 12h8"/></svg>新会话</a>
16
+ <div class="ws-head"><span>工作区</span><span class="ws-tools"><button type="button" class="drawer-close" id="drawerClose" aria-label="关闭菜单"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="m6 6 12 12M18 6 6 18"/></svg></button><button type="button" id="wsSearchBtn" title="搜索会话"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg></button><button type="button" id="wsRefresh" title="刷新"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-3-6.7L21 8"/><path d="M21 3v5h-5"/></svg></button><button type="button" id="wsAddDir" title="添加工作区" aria-label="添加工作区"><svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><path d="M12 10.5v5M9.5 13h5"/></svg></button></span></div>
17
+ <input type="search" class="ws-search hidden" id="wsSearch" placeholder="搜索会话或目录…">
18
+ <div class="ws" id="ws"><div class="ws-empty">正在加载…</div></div>
19
+ <!-- settings and the other pages: in the menu of the account, at the bottom -->
20
+ <div class="user-menu hidden" id="userMenu">
21
+ <nav class="side-nav" id="nav">
22
+ <a href="#/providers" data-nav="providers"><svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="16" rx="3"/><path d="M9 9h6v6H9zM9 1v3M15 1v3M9 20v3M15 20v3M20 9h3M20 14h3M1 9h3M1 14h3"/></svg>模型与供应商</a>
23
+ <a href="#/extensions" data-nav="extensions"><svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2v4M12 18v4M4.9 4.9l2.8 2.8M16.3 16.3l2.8 2.8M2 12h4M18 12h4M4.9 19.1l2.8-2.8M16.3 7.7l2.8-2.8"/><circle cx="12" cy="12" r="3"/></svg>扩展</a>
24
+ <a href="#/remote" data-nav="remote"><svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="7" y="2" width="10" height="20" rx="2"/><path d="M11 18h2"/></svg>远程访问</a>
25
+ <a href="#/settings" data-nav="settings"><svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 21v-7M4 10V3M12 21v-9M12 8V3M20 21v-5M20 12V3M1 14h6M9 8h6M17 16h6"/></svg>设置</a>
26
+ <div class="menu-sep"></div>
27
+ <a href="#/overview" data-nav="overview"><svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="9" rx="1.5"/><rect x="14" y="3" width="7" height="5" rx="1.5"/><rect x="14" y="12" width="7" height="9" rx="1.5"/><rect x="3" y="16" width="7" height="5" rx="1.5"/></svg>概览</a>
28
+ <a href="#/sessions" data-nav="sessions"><svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"/></svg>全部会话与回收站</a>
29
+ <a href="#/memory" data-nav="memory"><svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20V3H6.5A2.5 2.5 0 0 0 4 5.5z"/><path d="M4 19.5A2.5 2.5 0 0 0 6.5 22H20v-5"/></svg>记忆与指令</a>
30
+ <a href="#/usage" data-nav="usage"><svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21h18M7 17V11M12 17V6M17 17v-4"/></svg>用量</a>
31
+ <div class="menu-sep hidden" id="repoSep"></div>
32
+ <a href="#" class="hidden" id="repoLink" target="_blank" rel="noopener"><svg viewBox="0 0 24 24" width="17" height="17" fill="currentColor" aria-hidden="true"><path d="M12 2a10 10 0 0 0-3.16 19.49c.5.09.68-.22.68-.48v-1.7c-2.78.6-3.37-1.34-3.37-1.34-.45-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.6.07-.6 1 .07 1.53 1.03 1.53 1.03.9 1.52 2.34 1.08 2.91.83.09-.65.35-1.09.63-1.34-2.22-.25-4.55-1.11-4.55-4.94 0-1.09.39-1.98 1.03-2.68-.1-.25-.45-1.27.1-2.64 0 0 .84-.27 2.75 1.02a9.6 9.6 0 0 1 5 0c1.91-1.29 2.75-1.02 2.75-1.02.55 1.37.2 2.39.1 2.64.64.7 1.03 1.59 1.03 2.68 0 3.84-2.34 4.68-4.57 4.93.36.31.68.92.68 1.85v2.74c0 .27.18.58.69.48A10 10 0 0 0 12 2z"/></svg>GitHub 仓库</a>
33
+ </nav>
34
+ <div class="remote-links hidden" id="remoteLinks"><a href="/__cp/computers">切换电脑</a><button type="button" id="logoutBtn">退出登录</button></div>
35
+ </div>
36
+ <div class="side-foot"><button type="button" class="side-me" id="sideMe" title="设置与更多" aria-haspopup="menu" aria-expanded="false"><span class="side-me-icon" aria-hidden="true"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg></span><span class="side-user">设置</span><svg class="side-caret" viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 15 6-6 6 6"/></svg></button><button type="button" class="icon-btn theme-icon" id="themeToggle" title="浅色 / 深色" aria-label="切换浅色 / 深色"><svg class="sun" viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg><svg class="moon" viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg></button></div>
37
+ </aside>
38
+ <button type="button" class="mobile-menu" id="menuBtn" aria-label="菜单" aria-controls="sideDrawer" aria-expanded="false"><svg viewBox="0 0 24 24" width="19" height="19" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"/></svg></button>
39
+ <div class="side-backdrop" id="sideBackdrop" aria-hidden="true"></div>
40
+ <main class="main" id="main"><div class="page"><div class="empty">正在加载…</div></div></main>
41
+ </div>
42
+ <div class="tip hidden" id="tip"></div>
43
+ </body>
44
+ </html>