claude-rpc 1.7.4 → 1.8.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,145 @@
1
+ /* /settings — layered on dashboard.css (tokens, .page, .topbar, .brand). */
2
+
3
+ .settings .page { max-width: 860px; padding-bottom: 140px; }
4
+ .settings .topbar { margin-bottom: 28px; }
5
+
6
+ .set-card {
7
+ background: #fff; border: 2px solid var(--ink); box-shadow: var(--shadow);
8
+ padding: 22px 24px 24px; margin-bottom: 28px;
9
+ }
10
+ .set-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
11
+ .set-head h2 { font-family: var(--font-disp); font-size: 20px; font-weight: 700; }
12
+ .sub-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin: 22px 0 10px; padding-top: 18px; border-top: 2px dashed var(--paper-dark); }
13
+ .sub-head h3 { font-family: var(--font-mono); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
14
+ .set-hint { font-size: 13px; color: var(--ink-mute); }
15
+ .set-error {
16
+ background: #fff; border: 2px solid var(--rust); color: var(--rust);
17
+ padding: 12px 16px; margin-bottom: 24px; font-weight: 600;
18
+ }
19
+
20
+ /* Buttons */
21
+ .btn {
22
+ font-family: var(--font-mono); font-size: 12px; font-weight: 700;
23
+ padding: 8px 14px; background: #fff; color: var(--ink);
24
+ border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink);
25
+ transition: transform 0.1s, box-shadow 0.1s;
26
+ }
27
+ .btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
28
+ .btn:active:not(:disabled) { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
29
+ .btn:disabled { opacity: 0.4; cursor: default; }
30
+ .btn.primary { background: var(--ink); color: var(--paper); box-shadow: 2px 2px 0 var(--rust); }
31
+ .btn.primary:hover:not(:disabled) { box-shadow: 3px 3px 0 var(--rust); }
32
+ .btn.ghost { border-style: dashed; box-shadow: none; color: var(--ink-mute); margin-top: 10px; }
33
+ .btn.ghost:hover:not(:disabled) { color: var(--ink); box-shadow: none; transform: none; border-style: solid; }
34
+ .btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
35
+ .settings :focus-visible { outline: 3px solid var(--rust); outline-offset: 2px; }
36
+
37
+ /* Daemon */
38
+ .daemon-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
39
+ .daemon-text { flex: 1; min-width: 200px; }
40
+ .daemon-title { font-weight: 700; font-size: 15px; }
41
+ .daemon-sub { font-size: 13px; color: var(--ink-mute); }
42
+ .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper-dark); flex: none; }
43
+ .dot.up { background: var(--grass); }
44
+ .dot.wait { background: var(--tape); }
45
+ .dot.down { background: var(--rust); }
46
+ .log { margin-top: 16px; }
47
+ .log summary { font-family: var(--font-mono); font-size: 12px; font-weight: 700; cursor: pointer; color: var(--ink-mute); width: fit-content; }
48
+ .log pre {
49
+ margin-top: 10px; max-height: 260px; overflow: auto;
50
+ background: var(--ink); color: var(--paper); padding: 12px 14px;
51
+ font-family: var(--font-mono); font-size: 11.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
52
+ }
53
+
54
+ /* Segmented control (status tabs, privacy levels) */
55
+ .seg { display: inline-flex; flex-wrap: wrap; border: 2px solid var(--ink); background: #fff; }
56
+ .seg button {
57
+ font-family: var(--font-mono); font-size: 12px; font-weight: 700;
58
+ padding: 7px 12px; border-right: 2px solid var(--ink); color: var(--ink-mute);
59
+ }
60
+ .seg button:last-child { border-right: none; }
61
+ .seg button:hover { color: var(--ink); background: var(--paper); }
62
+ .seg button[aria-selected="true"], .seg button[aria-pressed="true"] { background: var(--tape); color: var(--ink); }
63
+
64
+ /* Card preview — shaped like the Discord activity row */
65
+ .preview {
66
+ display: grid; grid-template-columns: 64px 1fr; gap: 16px; align-items: center;
67
+ margin: 18px 0; padding: 16px; background: var(--paper); border: 2px dashed var(--ink-mute);
68
+ min-height: 100px;
69
+ }
70
+ .preview .avatar { width: 64px; height: 64px; background: var(--paper-dark); border: 2px solid var(--ink); overflow: hidden; }
71
+ .preview .avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
72
+ .pv-text { min-width: 0; }
73
+ .pv-app { font-weight: 700; font-size: 14px; }
74
+ .pv-details, .pv-state { font-size: 13px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
75
+ .pv-state { color: var(--ink-mute); }
76
+
77
+ /* Fields */
78
+ .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
79
+ .grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px 18px; }
80
+ .field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--ink-mute); min-width: 0; }
81
+ .settings input[type="text"], .settings input[type="number"], .settings input[type="url"], .settings select {
82
+ font: inherit; font-size: 14px; font-weight: 400; color: var(--ink);
83
+ background: #fff; border: 2px solid var(--ink); padding: 8px 10px; width: 100%; min-width: 0;
84
+ border-radius: 0;
85
+ }
86
+ .settings input::placeholder { color: var(--ink-faint); }
87
+ .unit { display: flex; align-items: center; gap: 8px; font-weight: 400; }
88
+ .unit input { width: 90px; }
89
+ .checks { display: flex; flex-direction: column; gap: 8px; justify-content: flex-end; }
90
+ .checks.row { flex-direction: row; flex-wrap: wrap; justify-content: flex-start; gap: 10px 28px; margin-top: 18px; }
91
+ .check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
92
+ .check input { width: 16px; height: 16px; accent-color: var(--ink); }
93
+
94
+ /* Insert-a-value picker */
95
+ .insert { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; font-size: 12px; font-weight: 600; color: var(--ink-mute); }
96
+ .insert select { width: auto; max-width: 220px; padding: 5px 8px; font-size: 13px; }
97
+ .insert code { font-family: var(--font-mono); background: var(--paper); padding: 1px 5px; border: 1px solid var(--paper-dark); }
98
+
99
+ /* Repeating rows: extra frames, buttons */
100
+ .rowlist { display: grid; gap: 8px; }
101
+ .frame-row, .button-row { display: grid; gap: 8px; align-items: center; }
102
+ .frame-row { grid-template-columns: 1fr 1fr 150px 34px; margin-bottom: 8px; }
103
+ .button-row { grid-template-columns: 1fr 1.6fr 34px; margin-bottom: 8px; }
104
+ .x {
105
+ width: 34px; height: 38px; font-size: 18px; line-height: 1; color: var(--ink-mute);
106
+ border: 2px solid transparent;
107
+ }
108
+ .x:hover { color: var(--rust); border-color: var(--rust); }
109
+ .empty { font-size: 13px; color: var(--ink-faint); padding: 4px 0; }
110
+
111
+ /* Privacy */
112
+ .ws-row { display: flex; align-items: center; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--paper-dark); }
113
+ .ws-row:last-child { border-bottom: none; }
114
+ .ws-meta { flex: 1; min-width: 0; }
115
+ .ws-name { font-weight: 700; }
116
+ .ws-path { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
117
+
118
+ .settings footer { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-mute); }
119
+
120
+ /* Save bar */
121
+ .savebar {
122
+ position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
123
+ display: flex; align-items: center; gap: 10px;
124
+ background: var(--tape); border: 2px solid var(--ink); box-shadow: var(--shadow);
125
+ padding: 10px 12px 10px 16px; max-width: calc(100vw - 32px); z-index: 10;
126
+ }
127
+ .savebar[hidden] { display: none; }
128
+ .save-msg { font-weight: 600; font-size: 13px; margin-right: 6px; }
129
+ .savebar.ok { background: #fff; }
130
+ .savebar.err { background: #fff; border-color: var(--rust); }
131
+ .savebar.err .save-msg { color: var(--rust); }
132
+
133
+ @media (max-width: 640px) {
134
+ .settings .page { padding: 20px 16px 140px; }
135
+ .set-card { padding: 16px; }
136
+ .grid2 { grid-template-columns: 1fr; }
137
+ .frame-row { grid-template-columns: 1fr 34px; padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--paper-dark); }
138
+ .frame-row input { grid-column: 1; }
139
+ .frame-row .x { grid-column: 2; grid-row: 1; }
140
+ .button-row { grid-template-columns: 1fr 34px; }
141
+ .button-row input { grid-column: 1; }
142
+ .button-row .x { grid-column: 2; grid-row: 1; }
143
+ .ws-row { flex-direction: column; align-items: stretch; gap: 8px; }
144
+ }
145
+ @media (prefers-reduced-motion: reduce) { .btn { transition: none; } }
@@ -0,0 +1,176 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+ <title>Claude · Settings</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com">
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;700&family=Space+Grotesk:wght@500;700&display=swap" rel="stylesheet">
10
+ <style>
11
+ {{STYLES}}</style>
12
+ </head>
13
+ <body class="settings">
14
+ <main class="page">
15
+
16
+ <header class="topbar">
17
+ <div class="brand">
18
+ <span class="mark">◆</span>
19
+ <span>Settings</span>
20
+ </div>
21
+ <div class="top-right">
22
+ <a class="wrapped-link" href="/">← Stats</a>
23
+ </div>
24
+ </header>
25
+
26
+ <div class="set-error" id="load-error" hidden></div>
27
+
28
+ <!-- ── Daemon ──────────────────────────────────────── -->
29
+ <section class="set-card" aria-labelledby="h-daemon">
30
+ <div class="set-head">
31
+ <h2 id="h-daemon">Daemon</h2>
32
+ <span class="set-hint">The background process that updates your Discord card.</span>
33
+ </div>
34
+ <div class="daemon-row">
35
+ <span class="dot" id="daemon-dot"></span>
36
+ <div class="daemon-text">
37
+ <div class="daemon-title" id="daemon-title">Checking…</div>
38
+ <div class="daemon-sub" id="daemon-sub"></div>
39
+ </div>
40
+ <div class="btn-row">
41
+ <button class="btn" id="daemon-start">Start</button>
42
+ <button class="btn" id="daemon-restart">Restart</button>
43
+ <button class="btn" id="daemon-stop">Stop</button>
44
+ </div>
45
+ </div>
46
+ <details class="log" id="log-details">
47
+ <summary>Log</summary>
48
+ <pre id="log" tabindex="0"></pre>
49
+ </details>
50
+ </section>
51
+
52
+ <!-- ── Card ────────────────────────────────────────── -->
53
+ <section class="set-card" aria-labelledby="h-card">
54
+ <div class="set-head">
55
+ <h2 id="h-card">Card</h2>
56
+ <span class="set-hint">What Discord shows for each thing Claude is doing.</span>
57
+ </div>
58
+ <div class="seg" id="status-tabs" role="tablist" aria-label="Status"></div>
59
+
60
+ <div class="preview" aria-live="polite">
61
+ <div class="avatar" id="pv-avatar"></div>
62
+ <div class="pv-text">
63
+ <div class="pv-app" id="pv-app"></div>
64
+ <div class="pv-details" id="pv-details"></div>
65
+ <div class="pv-state" id="pv-state"></div>
66
+ </div>
67
+ </div>
68
+
69
+ <div class="grid2">
70
+ <label class="field">Top line
71
+ <input type="text" id="f-details" autocomplete="off" />
72
+ </label>
73
+ <label class="field">Bottom line
74
+ <input type="text" id="f-state" autocomplete="off" />
75
+ </label>
76
+ <label class="field">Image
77
+ <input type="text" id="f-asset" autocomplete="off" placeholder="Image link or Discord asset key" />
78
+ </label>
79
+ <label class="field">Image hover text
80
+ <input type="text" id="f-hover" autocomplete="off" />
81
+ </label>
82
+ </div>
83
+ <div class="insert">
84
+ <label for="var-pick">Insert a live value</label>
85
+ <select id="var-pick"><option value="">Choose…</option></select>
86
+ <span class="set-hint">Adds it to the line you were last typing in, like <code>{project}</code>.</span>
87
+ </div>
88
+
89
+ <div class="sub-head">
90
+ <h3>Extra frames</h3>
91
+ <span class="set-hint">Shown in turn after the lines above. A frame is skipped while its condition is empty.</span>
92
+ </div>
93
+ <div id="frames"></div>
94
+ <button class="btn ghost" id="add-frame">+ Add frame</button>
95
+ </section>
96
+
97
+ <!-- ── Discord ─────────────────────────────────────── -->
98
+ <section class="set-card" aria-labelledby="h-discord">
99
+ <div class="set-head"><h2 id="h-discord">Discord</h2></div>
100
+ <div class="grid2">
101
+ <label class="field">App name
102
+ <input type="text" id="f-appName" autocomplete="off" />
103
+ </label>
104
+ <label class="field">Application ID
105
+ <input type="text" id="f-clientId" inputmode="numeric" autocomplete="off" />
106
+ </label>
107
+ <label class="field">Shown as
108
+ <select id="f-activityType">
109
+ <option value="0">Playing</option>
110
+ <option value="2">Listening to</option>
111
+ <option value="3">Watching</option>
112
+ <option value="5">Competing in</option>
113
+ </select>
114
+ </label>
115
+ <div class="checks">
116
+ <label class="check"><input type="checkbox" id="f-showElapsed" /> Show elapsed time</label>
117
+ <label class="check"><input type="checkbox" id="f-githubButton" /> Link public GitHub repos</label>
118
+ </div>
119
+ </div>
120
+ <div class="sub-head">
121
+ <h3>Buttons</h3>
122
+ <span class="set-hint">Up to 2. Only other people see them on your card.</span>
123
+ </div>
124
+ <div id="buttons"></div>
125
+ <button class="btn ghost" id="add-button">+ Add button</button>
126
+ </section>
127
+
128
+ <!-- ── Behaviour ───────────────────────────────────── -->
129
+ <section class="set-card" aria-labelledby="h-behaviour">
130
+ <div class="set-head"><h2 id="h-behaviour">Behaviour</h2></div>
131
+ <div class="grid3">
132
+ <label class="field">Rotate frames every
133
+ <span class="unit"><input type="number" id="f-rotation" min="5" step="1" /> sec</span>
134
+ </label>
135
+ <label class="field">Idle after
136
+ <span class="unit"><input type="number" id="f-idle" min="0" step="1" /> sec</span>
137
+ </label>
138
+ <label class="field">Clear card after
139
+ <span class="unit"><input type="number" id="f-stale" min="0" step="1" /> min</span>
140
+ </label>
141
+ <label class="field">"Just shipped" stays
142
+ <span class="unit"><input type="number" id="f-shipped" min="0" step="1" /> sec</span>
143
+ </label>
144
+ </div>
145
+ <div class="checks row">
146
+ <label class="check"><input type="checkbox" id="f-hideWhenStale" /> Hide the card when Claude Code is closed</label>
147
+ <label class="check"><input type="checkbox" id="f-notify" /> Desktop notification when Claude needs you</label>
148
+ </div>
149
+ </section>
150
+
151
+ <!-- ── Privacy ─────────────────────────────────────── -->
152
+ <section class="set-card" aria-labelledby="h-privacy">
153
+ <div class="set-head">
154
+ <h2 id="h-privacy">Privacy</h2>
155
+ <span class="set-hint">Per project. Changes apply right away.</span>
156
+ </div>
157
+ <div id="workspaces"></div>
158
+ </section>
159
+
160
+ <footer>
161
+ <span id="config-path"></span>
162
+ <span>127.0.0.1:{{PORT}} · <span id="version"></span></span>
163
+ </footer>
164
+ </main>
165
+
166
+ <!-- Sticky save bar: only visible with unsaved changes or a result to report -->
167
+ <div class="savebar" id="savebar" hidden>
168
+ <span class="save-msg" id="save-msg" role="status"></span>
169
+ <button class="btn" id="revert">Discard</button>
170
+ <button class="btn primary" id="save">Save</button>
171
+ </div>
172
+
173
+ <script>
174
+ {{SCRIPT}}</script>
175
+ </body>
176
+ </html>
@@ -17,7 +17,8 @@ import { exec } from 'node:child_process';
17
17
  import { ROUTES, JSON_HEADERS } from './routes.js';
18
18
  import { projectDrilldown, dayDetail } from './api.js';
19
19
  import { watchSources, addClient, removeClient } from './sse.js';
20
- import { buildHtml, buildWrappedHtml } from './page.js';
20
+ import { buildHtml, buildWrappedHtml, buildSettingsHtml } from './page.js';
21
+ import { writeAllowed } from './settings.js';
21
22
 
22
23
  const PORT = Number(process.env.CLAUDE_RPC_PORT) || 47474;
23
24
 
@@ -25,8 +26,10 @@ const PORT = Number(process.env.CLAUDE_RPC_PORT) || 47474;
25
26
  // (shown in the footer), which is fixed for the life of the process.
26
27
  const HTML = buildHtml({ port: PORT });
27
28
  const WRAPPED_HTML = buildWrappedHtml();
29
+ const SETTINGS_HTML = buildSettingsHtml({ port: PORT });
28
30
  const PAGES = new Map([
29
31
  ['/', HTML], ['/index.html', HTML],
32
+ ['/settings', SETTINGS_HTML], ['/settings.html', SETTINGS_HTML], // config, daemon, privacy
30
33
  ['/wrapped', WRAPPED_HTML], ['/wrapped.html', WRAPPED_HTML], // animated year-in-review
31
34
  ]);
32
35
 
@@ -85,8 +88,9 @@ function dispatch(req, res) {
85
88
  }
86
89
 
87
90
  // Static /api/* endpoints (state, wrapped, aggregate, insights, badge.svg,
88
- // card.svg, export.json, export.csv) — see routes.js.
91
+ // card.svg, export.json, export.csv, settings) — see routes.js.
89
92
  const handler = ROUTES.get(key);
93
+ if (handler && req.method === 'POST') return handleWrite(req, res, handler, query);
90
94
  if (handler) return handler(req, res, { query });
91
95
 
92
96
  const page = req.method === 'GET' && PAGES.get(path);
@@ -99,6 +103,31 @@ function dispatch(req, res) {
99
103
  res.writeHead(404).end('not found');
100
104
  }
101
105
 
106
+ const MAX_BODY_BYTES = 512 * 1024;
107
+
108
+ function handleWrite(req, res, handler, query) {
109
+ const fail = (code, error) => {
110
+ if (!res.headersSent) res.writeHead(code, JSON_HEADERS).end(JSON.stringify({ error }));
111
+ };
112
+ if (!writeAllowed(req.headers)) return fail(403, 'forbidden');
113
+ const chunks = [];
114
+ let size = 0;
115
+ req.on('data', (c) => {
116
+ size += c.length;
117
+ if (size > MAX_BODY_BYTES) { fail(413, 'request too large'); req.destroy(); return; }
118
+ chunks.push(c);
119
+ });
120
+ req.on('error', () => fail(400, 'bad request'));
121
+ req.on('end', async () => {
122
+ if (res.headersSent) return;
123
+ let body;
124
+ try { body = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}'); }
125
+ catch { return fail(400, 'body is not valid JSON'); }
126
+ try { await handler(req, res, { query, body }); }
127
+ catch { fail(500, 'internal error'); }
128
+ });
129
+ }
130
+
102
131
  const server = createServer((req, res) => {
103
132
  try {
104
133
  dispatch(req, res);
@@ -117,14 +146,45 @@ const server = createServer((req, res) => {
117
146
  // `claude-rpc serve`, or the tray and the Stats tab each spawning one. Say why
118
147
  // in one line and exit non-zero instead. Once listening, an 'error' is logged
119
148
  // and the dashboard keeps running (same policy as the floor).
120
- server.on('error', (e) => {
149
+ // `claude-rpc wrapped` / `settings` set CLAUDE_RPC_OPEN_PATH to land on that
150
+ // page instead of the dashboard.
151
+ const OPEN_PATH = process.env.CLAUDE_RPC_OPEN_PATH || '';
152
+
153
+ function openBrowser(url) {
154
+ if (process.env.CLAUDE_RPC_NO_OPEN) return;
155
+ const opener = process.platform === 'win32' ? `start "" "${url}"`
156
+ : process.platform === 'darwin' ? `open "${url}"`
157
+ : `xdg-open "${url}"`;
158
+ // windowsHide so the cmd.exe that runs `start` doesn't flash a console.
159
+ exec(opener, { windowsHide: true }, () => {});
160
+ }
161
+
162
+ // Is the thing already on our port a claude-rpc dashboard new enough to have
163
+ // the page we want? /api/settings exists on every build that serves /settings.
164
+ async function dashboardAlreadyUp(base) {
165
+ try {
166
+ const res = await fetch(`${base}/api/settings`, { signal: AbortSignal.timeout(1500) });
167
+ return res.ok && typeof (await res.json()).version === 'string';
168
+ } catch { return false; }
169
+ }
170
+
171
+ server.on('error', async (e) => {
121
172
  if (server.listening) {
122
173
  try { console.error('dashboard error:', e?.message || e); } catch { /* ignore */ }
123
174
  return;
124
175
  }
125
176
  const base = `http://127.0.0.1:${PORT}`;
177
+ // A dashboard is already running (another terminal, a previous `serve`):
178
+ // that's not a failure — open the page in it.
179
+ if (e?.code === 'EADDRINUSE' && await dashboardAlreadyUp(base)) {
180
+ console.log(`◆ Claude RPC dashboard is already running: ${base}${OPEN_PATH}`);
181
+ openBrowser(base + OPEN_PATH);
182
+ // Let the opener spawn before exiting.
183
+ setTimeout(() => process.exit(0), 300);
184
+ return;
185
+ }
126
186
  console.error(e?.code === 'EADDRINUSE'
127
- ? `✗ Port ${PORT} is already in use — a dashboard may already be running at ${base} (set CLAUDE_RPC_PORT to use another port).`
187
+ ? `✗ Port ${PORT} is in use by another program or an older claude-rpc dashboard — stop it, or set CLAUDE_RPC_PORT to use another port.`
128
188
  : `✗ Dashboard could not listen on 127.0.0.1:${PORT}: ${e?.message || e}`);
129
189
  process.exit(1);
130
190
  });
@@ -134,19 +194,10 @@ server.listen(PORT, '127.0.0.1', () => {
134
194
  // without leaving watchers behind.
135
195
  watchSources();
136
196
  const base = `http://127.0.0.1:${PORT}`;
137
- // `claude-rpc wrapped` sets CLAUDE_RPC_OPEN_PATH=/wrapped to land on the
138
- // animated year-in-review instead of the dashboard.
139
- const openPath = process.env.CLAUDE_RPC_OPEN_PATH || '';
140
- const url = base + openPath;
197
+ const url = base + OPEN_PATH;
141
198
  console.log(`◆ Claude RPC dashboard: ${base}`);
142
- console.log(` ${openPath ? 'opening ' + url + ' · ' : ''}Ctrl-C to stop.`);
143
- if (!process.env.CLAUDE_RPC_NO_OPEN) {
144
- const opener = process.platform === 'win32' ? `start "" "${url}"`
145
- : process.platform === 'darwin' ? `open "${url}"`
146
- : `xdg-open "${url}"`;
147
- // windowsHide so the cmd.exe that runs `start` doesn't flash a console.
148
- exec(opener, { windowsHide: true }, () => {});
149
- }
199
+ console.log(` ${OPEN_PATH ? 'opening ' + url + ' · ' : ''}Ctrl-C to stop.`);
200
+ openBrowser(url);
150
201
  });
151
202
 
152
203
  process.on('SIGINT', () => process.exit(0));
@@ -1,4 +1,5 @@
1
- // Composes the local web dashboard's two pages from six on-disk assets:
1
+ // Composes the local web dashboard's pages from on-disk assets (plus the
2
+ // settings.html / settings.css / settings.client.js trio for /settings):
2
3
  // assets/dashboard.html — scaffold with {{STYLES}} {{SCRIPT}} {{PORT}}
3
4
  // assets/dashboard.css — stylesheet
4
5
  // assets/dashboard.client.js — vanilla browser runtime (one IIFE)
@@ -11,7 +12,7 @@
11
12
  // them from disk in dev/npm and from the SEA blob in the packaged exe
12
13
  // (see src/server/assets.js + sea-config.json).
13
14
  //
14
- // Two exports: buildHtml({ port }) and buildWrappedHtml(). The server
15
+ // Exports buildHtml({ port }), buildWrappedHtml() and buildSettingsHtml(). The server
15
16
  // composes each once at startup and reuses the string for every request.
16
17
 
17
18
  import { loadAsset } from './assets.js';
@@ -22,6 +23,10 @@ const TEMPLATE = loadAsset('dashboard.html');
22
23
  const STYLES = loadAsset('dashboard.css');
23
24
  const SCRIPT = loadAsset('dashboard.client.js');
24
25
 
26
+ const SETTINGS_TEMPLATE = loadAsset('settings.html');
27
+ const SETTINGS_STYLES = loadAsset('settings.css');
28
+ const SETTINGS_SCRIPT = loadAsset('settings.client.js');
29
+
25
30
  const WRAPPED_TEMPLATE = loadAsset('wrapped.html');
26
31
  const WRAPPED_STYLES = loadAsset('wrapped.css');
27
32
  const WRAPPED_SCRIPT = loadAsset('wrapped.client.js');
@@ -44,4 +49,13 @@ function buildWrappedHtml() {
44
49
  .replace('{{SCRIPT}}', () => WRAPPED_SCRIPT);
45
50
  }
46
51
 
47
- export { buildHtml, buildWrappedHtml };
52
+ // /settings — config editor, daemon controls, per-project privacy. Shares the
53
+ // dashboard's stylesheet (tokens, type, buttons) and adds its own on top.
54
+ function buildSettingsHtml({ port }) {
55
+ return SETTINGS_TEMPLATE
56
+ .replace('{{STYLES}}', () => STYLES + '\n' + SETTINGS_STYLES)
57
+ .replace('{{SCRIPT}}', () => SETTINGS_SCRIPT)
58
+ .replaceAll('{{PORT}}', String(port));
59
+ }
60
+
61
+ export { buildHtml, buildWrappedHtml, buildSettingsHtml };
@@ -9,6 +9,7 @@ import { generateInsights } from '../insights.js';
9
9
  import { badgeSvg } from '../badge.js';
10
10
  import { renderCard } from '../card.js';
11
11
  import { snapshot, windowedAggregate, aggregateToCsv, wrappedData } from './api.js';
12
+ import { getSettings, saveSettings, daemonAction, getLog, listWorkspaces, setWorkspaceVisibility } from './settings.js';
12
13
 
13
14
  export const JSON_HEADERS = {
14
15
  'content-type': 'application/json',
@@ -89,3 +90,18 @@ ROUTES.set('GET /api/card.svg', (req, res, { query }) => {
89
90
  });
90
91
  res.end(svg);
91
92
  });
93
+
94
+ // ── Settings page (/settings) ───────────────────────────────────────────
95
+ // POST handlers receive the parsed JSON body as `body`; index.js has already
96
+ // checked the request is same-origin JSON before it gets here.
97
+ const sendJson = (res, obj) => {
98
+ res.writeHead(obj && obj.error ? 400 : 200, JSON_HEADERS);
99
+ res.end(JSON.stringify(obj));
100
+ };
101
+
102
+ ROUTES.set('GET /api/settings', (req, res) => sendJson(res, getSettings()));
103
+ ROUTES.set('POST /api/settings', (req, res, { body }) => sendJson(res, saveSettings(body)));
104
+ ROUTES.set('POST /api/daemon', async (req, res, { body }) => sendJson(res, await daemonAction(body && body.action)));
105
+ ROUTES.set('GET /api/log', (req, res) => sendJson(res, getLog()));
106
+ ROUTES.set('GET /api/workspaces', (req, res) => sendJson(res, listWorkspaces()));
107
+ ROUTES.set('POST /api/workspaces', (req, res, { body }) => sendJson(res, setWorkspaceVisibility(body)));