ccdeck 3.82.4 → 4.0.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.
- package/LICENSING.md +42 -4
- package/README.md +183 -72
- package/THIRD_PARTY_NOTICES.md +243 -17
- package/bin/cli/tui.js +58 -4
- package/bin/deck.js +27 -1
- package/dist/web/assets/AccountBridge-OQHT5qmS.js +1 -0
- package/dist/web/assets/AccountSection-BpIHPhF3.js +1 -0
- package/dist/web/assets/BrowserWatchModal-DBdt52v7.js +1 -0
- package/dist/web/assets/FeedbackConversations-BJjgXI0-.js +1 -0
- package/dist/web/assets/IntegrationModal-DQ0vEz4X.js +7 -0
- package/dist/web/assets/IntegrationSkeleton-JCPbqp96.js +1 -0
- package/dist/web/assets/RadioPanel-Be6AkrKl.js +1 -0
- package/dist/web/assets/StageShell-Dq0JOQhd.js +4 -0
- package/dist/web/assets/TrafficRadar-7jqJbhaK.js +8 -0
- package/dist/web/assets/UsageHistoryModal-ckawZGoe.js +1 -0
- package/dist/web/assets/addon-unicode-graphemes-DW3WJwyh.js +18 -0
- package/dist/web/assets/addon-web-links-BWjmmSgS.js +12 -0
- package/dist/web/assets/addon-webgl-CLK4R-_u.js +75 -0
- package/dist/web/assets/app-40gNTTfq.js +361 -0
- package/dist/web/assets/app-BRjYF6oD.css +1 -0
- package/dist/web/assets/{index-B-l-VxLm.js → index-XIY3yFiN.js} +1 -1
- package/dist/web/assets/inspector-status-pane-BV_m7eBv.js +1 -0
- package/dist/web/assets/screens-9_ivqfcF.js +12 -0
- package/dist/web/assets/screens-DUniTTbC.css +1 -0
- package/dist/web/assets/stage-board-NF_wgGRA.js +2 -0
- package/dist/web/assets/use-account-BUmI-A8e.js +1 -0
- package/dist/web/assets/xterm-4jYizCpg.js +27 -0
- package/dist/web/assets/xterm-sheet-6GBZ9nXN.css +32 -0
- package/dist/web/index.html +16 -6
- package/package.json +13 -1
- package/release-notes.json +67 -0
- package/src/server/account-client.mjs +196 -0
- package/src/server/account-connect.mjs +238 -0
- package/src/server/account-flag.mjs +106 -0
- package/src/server/account-projects.mjs +1 -1
- package/src/server/account-service.mjs +532 -0
- package/src/server/account-status.mjs +293 -0
- package/src/server/account-store.mjs +137 -0
- package/src/server/account-sync.mjs +473 -0
- package/src/server/account-token-store.mjs +216 -0
- package/src/server/account-ui-fields.mjs +126 -0
- package/src/server/account-watch.mjs +1 -1
- package/src/server/browser-watch-log.mjs +1 -1
- package/src/server/browser-watch-store.mjs +1 -1
- package/src/server/ccdeck-account-routes.mjs +252 -0
- package/src/server/ccusage-install.mjs +2 -2
- package/src/server/ccusage-registry.mjs +4 -4
- package/src/server/ccusage-session.mjs +11 -0
- package/src/server/claude-accounts.mjs +1 -1
- package/src/server/claude-recovery.mjs +9 -4
- package/src/server/claude-settings-catalog.mjs +6 -6
- package/src/server/claude-settings.mjs +1 -1
- package/src/server/codex-auto.mjs +1 -1
- package/src/server/codex-cost-usage.mjs +7 -2
- package/src/server/codex-live-checkpoint.mjs +24 -9
- package/src/server/codex-live-engine.mjs +14 -4
- package/src/server/codex-live-handoff.mjs +53 -9
- package/src/server/codex-names.mjs +49 -0
- package/src/server/codex-translate.mjs +1 -1
- package/src/server/codex-ultrafast.d.mts +3 -0
- package/src/server/codex-ultrafast.mjs +5 -0
- package/src/server/codex-watch.mjs +25 -0
- package/src/server/command-panel-engine.mjs +300 -0
- package/src/server/command-panel-platform.mjs +99 -0
- package/src/server/cswap-auto-choice.mjs +1 -1
- package/src/server/cswap-auto-loop.mjs +1 -1
- package/src/server/cswap-install.mjs +21 -40
- package/src/server/deck-home.mjs +6 -0
- package/src/server/deck-prefs.mjs +53 -1
- package/src/server/detach.mjs +1 -1
- package/src/server/engine-download.mjs +277 -0
- package/src/server/engine-install.mjs +378 -0
- package/src/server/engine-package.mjs +267 -0
- package/src/server/event-log.mjs +7 -1
- package/src/server/event-pipeline.mjs +29 -1
- package/src/server/ghostty-handoff.mjs +81 -0
- package/src/server/index.mjs +143 -5
- package/src/server/installer.mjs +4 -1
- package/src/server/integrations/jira-write-guard.mjs +14 -208
- package/src/server/integrations/store.mjs +37 -19
- package/src/server/integrations/write-guard.mjs +223 -0
- package/src/server/intel-cpu-temperature.mjs +26 -0
- package/src/server/lifecycle.mjs +69 -6
- package/src/server/log-replay.mjs +4 -0
- package/src/server/login-service.mjs +7 -1
- package/src/server/macmon.mjs +1 -1
- package/src/server/npm-latest.mjs +1 -1
- package/src/server/org-telemetry.mjs +1 -1
- package/src/server/output-watch.mjs +4 -1
- package/src/server/panel-provenance.mjs +390 -0
- package/src/server/pinned-build.mjs +14 -0
- package/src/server/prefs-refusal.mjs +8 -1
- package/src/server/prefs-routes.mjs +60 -11
- package/src/server/pro-engine-client.mjs +339 -0
- package/src/server/pro-engine-install.mjs +294 -0
- package/src/server/pro-engine-terminal.mjs +308 -0
- package/src/server/project-discovery.mjs +139 -0
- package/src/server/provider-session-name.mjs +58 -0
- package/src/server/quota-closes.mjs +1 -1
- package/src/server/quota-history.mjs +1 -1
- package/src/server/reports.mjs +86 -21
- package/src/server/request-gates.mjs +34 -5
- package/src/server/restart-note.mjs +1 -1
- package/src/server/seed-boundary.mjs +489 -0
- package/src/server/session-counts.mjs +244 -0
- package/src/server/session-deck-names.mjs +143 -0
- package/src/server/session-enrichment.mjs +43 -6
- package/src/server/session-name-route.mjs +73 -0
- package/src/server/session-summary.mjs +12 -1
- package/src/server/session-transcript-routes.mjs +167 -0
- package/src/server/swap-log.mjs +1 -1
- package/src/server/system-metrics.mjs +57 -0
- package/src/server/terminal-bridge.mjs +485 -0
- package/src/server/terminal-folder.mjs +61 -0
- package/src/server/terminal-js-routes.mjs +752 -0
- package/src/server/terminal-routes.mjs +553 -0
- package/src/server/terminal-sessions.mjs +759 -0
- package/src/server/terminal-socket.mjs +403 -0
- package/src/server/terminal-target.mjs +928 -0
- package/src/server/thermal-metrics.mjs +13 -9
- package/src/server/tmux-control.mjs +1319 -0
- package/src/server/tmux-download.mjs +220 -0
- package/src/server/tmux.mjs +542 -0
- package/src/server/token-redact.mjs +42 -3
- package/src/server/tool-audit-report.mjs +44 -6
- package/src/server/tool-audit-routes.mjs +12 -1
- package/src/server/tool-audit.mjs +42 -8
- package/src/server/traffic-radar-monitor.mjs +1 -1
- package/src/server/traffic-radar-permission.mjs +1 -1
- package/src/server/transcript-gate.mjs +1 -1
- package/src/server/transcript-scan.mjs +15 -7
- package/src/server/transcript-turns.mjs +154 -0
- package/src/server/tui-network.mjs +1 -0
- package/src/server/tui-view.mjs +28 -0
- package/src/server/utf8-carry.mjs +159 -0
- package/src/server/uv-bootstrap.mjs +2 -2
- package/src/server/windows-acl.mjs +158 -0
- package/src/server/ws-frames.mjs +690 -0
- package/dist/web/assets/BrowserWatchModal-CWVooKxD.js +0 -1
- package/dist/web/assets/IntegrationModal-DLX43RIK.js +0 -7
- package/dist/web/assets/RadioPanel-Cj6PjrvQ.js +0 -1
- package/dist/web/assets/TrafficRadar-Bq1YcuHB.js +0 -8
- package/dist/web/assets/UsageHistoryModal-CMSCca5_.js +0 -1
- package/dist/web/assets/app-BHxsMz3-.js +0 -358
- package/dist/web/assets/app-CbXmr9rC.css +0 -1
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// Where the device token is kept: the OS's own secret store where there is
|
|
2
|
+
// one, otherwise account.json at 0600.
|
|
3
|
+
//
|
|
4
|
+
// macOS the login Keychain, through /usr/bin/security -i
|
|
5
|
+
// Windows DPAPI (CurrentUser) through powershell.exe; the ciphertext is kept
|
|
6
|
+
// in account.json, which only this Windows user can decrypt
|
|
7
|
+
// Linux the Secret Service through secret-tool, when a session bus and
|
|
8
|
+
// the tool are both there
|
|
9
|
+
// any account.json, mode 0600 — the protection prefs.json gives the LAN
|
|
10
|
+
// private key (deck-prefs.mjs PREFS_MODE)
|
|
11
|
+
//
|
|
12
|
+
// THE SECRET IS NEVER ON A COMMAND LINE. Every platform's argv is readable by
|
|
13
|
+
// every other process on the machine through `ps` or /proc, so the token goes
|
|
14
|
+
// to each tool on its STDIN: `security -i` reads its commands from there,
|
|
15
|
+
// secret-tool reads the secret from there, and the PowerShell script reads the
|
|
16
|
+
// token from [Console]::In. The script itself rides in -EncodedCommand and
|
|
17
|
+
// holds no secret. account-token-store.test.ts mocks the runner on each
|
|
18
|
+
// platform and holds every argv to that.
|
|
19
|
+
//
|
|
20
|
+
// A KEYCHAIN THAT WILL NOT OPEN IS NOT A LOST TOKEN. Over ssh, or before the
|
|
21
|
+
// user has logged in at the console, macOS answers "User interaction is not
|
|
22
|
+
// allowed" — the condition cswap-admin.mjs knows as keychain_unavailable. That
|
|
23
|
+
// is reported as `locked`, the token is left where it is, and the service asks
|
|
24
|
+
// again later; only "not found" is `missing`.
|
|
25
|
+
//
|
|
26
|
+
// A WRITE THAT FAILS FALLS BACK TO THE FILE rather than leaving the deck with
|
|
27
|
+
// a token it cannot keep: a fresh token that dies with the process would cost
|
|
28
|
+
// the user a second approval in the browser.
|
|
29
|
+
import { spawn } from "node:child_process";
|
|
30
|
+
import { createHash } from "node:crypto";
|
|
31
|
+
import { accessSync, constants as fsConstants } from "node:fs";
|
|
32
|
+
import { delimiter, join } from "node:path";
|
|
33
|
+
import { deckDataDir } from "./deck-home.mjs";
|
|
34
|
+
import { DEVICE_TOKEN } from "./account-store.mjs";
|
|
35
|
+
|
|
36
|
+
/** The service name every backend files the token under. */
|
|
37
|
+
export const TOKEN_SERVICE = "ccdeck.account";
|
|
38
|
+
|
|
39
|
+
/** How long one call to a secret store may take. A Keychain prompt nobody can
|
|
40
|
+
* answer must not hold a connect open. */
|
|
41
|
+
const RUN_TIMEOUT_MS = 10_000;
|
|
42
|
+
const OUTPUT_MAX = 64 * 1024;
|
|
43
|
+
|
|
44
|
+
/** The account name a deck's token is filed under: one per data folder, so two
|
|
45
|
+
* CCDECK_HOMEs on one machine are two devices with two tokens. Hashed, so the
|
|
46
|
+
* folder's path is not written into the keychain's item list. */
|
|
47
|
+
export function tokenAccountName(home = deckDataDir()) {
|
|
48
|
+
return createHash("sha256").update(String(home)).digest("hex").slice(0, 16);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Run `cmd` with `args`, writing `input` to its stdin. Resolves to the exit
|
|
53
|
+
* code and what it printed; never rejects (a tool that cannot be started is
|
|
54
|
+
* code -1). No shell, a bounded wait, bounded output.
|
|
55
|
+
*/
|
|
56
|
+
export function runWithStdin(cmd, args, { input = "", timeout = RUN_TIMEOUT_MS } = {}) {
|
|
57
|
+
return new Promise(resolve => {
|
|
58
|
+
let stdout = "";
|
|
59
|
+
let stderr = "";
|
|
60
|
+
let done = false;
|
|
61
|
+
const finish = code => { if (!done) { done = true; clearTimeout(timer); resolve({ code, stdout, stderr }); } };
|
|
62
|
+
let child;
|
|
63
|
+
try {
|
|
64
|
+
child = spawn(cmd, args, { stdio: ["pipe", "pipe", "pipe"], windowsHide: true, shell: false });
|
|
65
|
+
} catch {
|
|
66
|
+
resolve({ code: -1, stdout: "", stderr: "spawn failed" });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const timer = setTimeout(() => { try { child.kill(); } catch { /* gone */ } finish(-1); }, timeout);
|
|
70
|
+
timer.unref?.();
|
|
71
|
+
child.stdout.setEncoding("utf8");
|
|
72
|
+
child.stderr.setEncoding("utf8");
|
|
73
|
+
child.stdout.on("data", c => { if (stdout.length < OUTPUT_MAX) stdout += c; });
|
|
74
|
+
child.stderr.on("data", c => { if (stderr.length < OUTPUT_MAX) stderr += c; });
|
|
75
|
+
child.on("error", () => finish(-1));
|
|
76
|
+
child.on("close", code => finish(typeof code === "number" ? code : -1));
|
|
77
|
+
child.stdin.on("error", () => {});
|
|
78
|
+
child.stdin.end(input);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Whether `cmd` is an executable on PATH. */
|
|
83
|
+
export function onPath(cmd, env = process.env) {
|
|
84
|
+
for (const dir of String(env.PATH ?? "").split(delimiter)) {
|
|
85
|
+
if (!dir) continue;
|
|
86
|
+
try { accessSync(join(dir, cmd), fsConstants.X_OK); return true; } catch { /* next */ }
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** PowerShell's -EncodedCommand: the script as UTF-16LE, base64. */
|
|
92
|
+
export function encodePowerShell(script) {
|
|
93
|
+
return Buffer.from(script, "utf16le").toString("base64");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const PS_PROTECT = [
|
|
97
|
+
"$ErrorActionPreference = 'Stop'",
|
|
98
|
+
"Add-Type -AssemblyName System.Security",
|
|
99
|
+
"$t = [Console]::In.ReadToEnd().Trim()",
|
|
100
|
+
"$c = [Security.Cryptography.ProtectedData]::Protect([Text.Encoding]::UTF8.GetBytes($t), $null, [Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
101
|
+
"[Console]::Out.Write([Convert]::ToBase64String($c))",
|
|
102
|
+
].join("\n");
|
|
103
|
+
|
|
104
|
+
const PS_UNPROTECT = [
|
|
105
|
+
"$ErrorActionPreference = 'Stop'",
|
|
106
|
+
"Add-Type -AssemblyName System.Security",
|
|
107
|
+
"$c = [Convert]::FromBase64String([Console]::In.ReadToEnd().Trim())",
|
|
108
|
+
"$b = [Security.Cryptography.ProtectedData]::Unprotect($c, $null, [Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
109
|
+
"[Console]::Out.Write([Text.Encoding]::UTF8.GetString($b))",
|
|
110
|
+
].join("\n");
|
|
111
|
+
|
|
112
|
+
const POWERSHELL_ARGS = script => ["-NoProfile", "-NonInteractive", "-EncodedCommand", encodePowerShell(script)];
|
|
113
|
+
|
|
114
|
+
/** macOS: the Keychain refusing because nobody can be asked — locked, or a
|
|
115
|
+
* session with no window server. errSecInteractionNotAllowed is -25308. */
|
|
116
|
+
function keychainLocked(stderr) {
|
|
117
|
+
return /interaction is not allowed|-25308|keychain is locked|could not be unlocked/i.test(stderr);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The token store for this machine. `run` and `which` are the suite's
|
|
122
|
+
* stand-ins; the product passes nothing.
|
|
123
|
+
*
|
|
124
|
+
* save(token) → the fields account.json keeps: { tokenStorage, token?, tokenCipher? }
|
|
125
|
+
* load(record) → { ok: true, token } | { ok: false, reason: "locked" | "missing" }
|
|
126
|
+
* remove(record) → forgets what save kept outside account.json (best effort)
|
|
127
|
+
*/
|
|
128
|
+
export function createTokenStore({
|
|
129
|
+
platform = process.platform,
|
|
130
|
+
env = process.env,
|
|
131
|
+
home = deckDataDir(),
|
|
132
|
+
run = runWithStdin,
|
|
133
|
+
which = cmd => onPath(cmd, env),
|
|
134
|
+
} = {}) {
|
|
135
|
+
const account = tokenAccountName(home);
|
|
136
|
+
const secretTool = () => platform === "linux" && !!env.DBUS_SESSION_BUS_ADDRESS && which("secret-tool");
|
|
137
|
+
|
|
138
|
+
/** Which backend a new token goes to. */
|
|
139
|
+
function backend() {
|
|
140
|
+
if (platform === "darwin") return "keychain";
|
|
141
|
+
if (platform === "win32") return "dpapi";
|
|
142
|
+
if (secretTool()) return "secret-service";
|
|
143
|
+
return "file";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const asFile = token => ({ tokenStorage: "file", token });
|
|
147
|
+
|
|
148
|
+
async function save(token) {
|
|
149
|
+
if (!DEVICE_TOKEN.test(String(token ?? ""))) throw new Error("not a device token");
|
|
150
|
+
const kind = backend();
|
|
151
|
+
if (kind === "keychain") {
|
|
152
|
+
const r = await run("/usr/bin/security", ["-i"], {
|
|
153
|
+
input: `add-generic-password -U -s ${TOKEN_SERVICE} -a ${account} -w ${token}\n`,
|
|
154
|
+
});
|
|
155
|
+
return r.code === 0 && !/security: |error/i.test(r.stderr) ? { tokenStorage: "keychain" } : asFile(token);
|
|
156
|
+
}
|
|
157
|
+
if (kind === "dpapi") {
|
|
158
|
+
const r = await run("powershell.exe", POWERSHELL_ARGS(PS_PROTECT), { input: token });
|
|
159
|
+
const cipher = r.stdout.trim();
|
|
160
|
+
return r.code === 0 && /^[A-Za-z0-9+/=]{16,4096}$/.test(cipher) ? { tokenStorage: "dpapi", tokenCipher: cipher } : asFile(token);
|
|
161
|
+
}
|
|
162
|
+
if (kind === "secret-service") {
|
|
163
|
+
const r = await run("secret-tool", ["store", "--label=ccdeck account", "service", TOKEN_SERVICE, "account", account], { input: token });
|
|
164
|
+
return r.code === 0 ? { tokenStorage: "secret-service" } : asFile(token);
|
|
165
|
+
}
|
|
166
|
+
return asFile(token);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function load(record) {
|
|
170
|
+
const storage = record?.tokenStorage;
|
|
171
|
+
if (storage === "file") {
|
|
172
|
+
return DEVICE_TOKEN.test(record.token ?? "") ? { ok: true, token: record.token } : { ok: false, reason: "missing" };
|
|
173
|
+
}
|
|
174
|
+
if (storage === "keychain") {
|
|
175
|
+
if (platform !== "darwin") return { ok: false, reason: "missing" };
|
|
176
|
+
const r = await run("/usr/bin/security", ["-i"], {
|
|
177
|
+
input: `find-generic-password -s ${TOKEN_SERVICE} -a ${account} -w\n`,
|
|
178
|
+
});
|
|
179
|
+
const token = r.stdout.trim().split(/\s+/).find(w => DEVICE_TOKEN.test(w));
|
|
180
|
+
if (token) return { ok: true, token };
|
|
181
|
+
if (keychainLocked(r.stderr) || r.code === -1) return { ok: false, reason: "locked" };
|
|
182
|
+
return { ok: false, reason: "missing" };
|
|
183
|
+
}
|
|
184
|
+
if (storage === "dpapi") {
|
|
185
|
+
if (platform !== "win32" || !record.tokenCipher) return { ok: false, reason: "missing" };
|
|
186
|
+
const r = await run("powershell.exe", POWERSHELL_ARGS(PS_UNPROTECT), { input: record.tokenCipher });
|
|
187
|
+
const token = r.stdout.trim();
|
|
188
|
+
if (r.code === 0 && DEVICE_TOKEN.test(token)) return { ok: true, token };
|
|
189
|
+
// A PowerShell that would not start is this machine, not the token.
|
|
190
|
+
return { ok: false, reason: r.code === -1 ? "locked" : "missing" };
|
|
191
|
+
}
|
|
192
|
+
if (storage === "secret-service") {
|
|
193
|
+
if (!secretTool()) return { ok: false, reason: "locked" };
|
|
194
|
+
const r = await run("secret-tool", ["lookup", "service", TOKEN_SERVICE, "account", account], { input: "" });
|
|
195
|
+
const token = r.stdout.trim();
|
|
196
|
+
if (r.code === 0 && DEVICE_TOKEN.test(token)) return { ok: true, token };
|
|
197
|
+
// Nothing found prints nothing and exits 1; a collection that will not
|
|
198
|
+
// unlock says why on stderr.
|
|
199
|
+
return { ok: false, reason: r.stderr.trim() || r.code === -1 ? "locked" : "missing" };
|
|
200
|
+
}
|
|
201
|
+
return { ok: false, reason: "missing" };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function remove(record) {
|
|
205
|
+
const storage = record?.tokenStorage;
|
|
206
|
+
if (storage === "keychain" && platform === "darwin") {
|
|
207
|
+
await run("/usr/bin/security", ["-i"], { input: `delete-generic-password -s ${TOKEN_SERVICE} -a ${account}\n` });
|
|
208
|
+
} else if (storage === "secret-service" && secretTool()) {
|
|
209
|
+
await run("secret-tool", ["clear", "service", TOKEN_SERVICE, "account", account], { input: "" });
|
|
210
|
+
}
|
|
211
|
+
// The file and DPAPI backends keep everything in account.json, which the
|
|
212
|
+
// caller rewrites without it.
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return { backend, save, load, remove };
|
|
216
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// The settings a ccdeck account may carry between this person's decks: schema
|
|
2
|
+
// 1's keys, what each may hold, and nothing else.
|
|
3
|
+
//
|
|
4
|
+
// AN ALLOWLIST, ENFORCED ON BOTH ENDS. The API refuses any other key by name
|
|
5
|
+
// (ValidationProblem, `errors["values.<key>"]`); this is the deck refusing to
|
|
6
|
+
// send one in the first place, so a page that posts something new to
|
|
7
|
+
// /api/account/ui cannot make the deck upload it. What the deck shows comes
|
|
8
|
+
// from the browser's localStorage; which localStorage key holds each of these
|
|
9
|
+
// is the page's business and lives in the web copy (src/web/account-ui-fields.ts).
|
|
10
|
+
// The two copies are held identical by account-ui-fields-mirror.test.ts — the
|
|
11
|
+
// pattern block-notify.mjs uses for a rule both runtimes need.
|
|
12
|
+
//
|
|
13
|
+
// EXPLICITLY NEVER SYNCED, so nobody adds them here by accident: anything in
|
|
14
|
+
// prefs.json (notifications, autoUpdate, reports, the accounts the deck signed
|
|
15
|
+
// in, the LAN section and its key), the tour marker, the layout and viewport,
|
|
16
|
+
// Claude FM and the radio, custom sounds, feedback drafts, removed nodes,
|
|
17
|
+
// panel internals and Browser Watch's state.
|
|
18
|
+
|
|
19
|
+
/** The schema these keys are. A write declares it; the API preserves keys of
|
|
20
|
+
* any newer schema this deck does not know. */
|
|
21
|
+
export const UI_SCHEMA = 1;
|
|
22
|
+
|
|
23
|
+
/** The choices each closed field takes, in the order the deck offers them. */
|
|
24
|
+
export const TEXT_SIZES = Object.freeze(["smallest", "smaller", "default", "larger", "largest"]);
|
|
25
|
+
export const DENSITIES = Object.freeze(["tightest", "tighter", "compact", "default", "comfortable"]);
|
|
26
|
+
export const HIDE_FINISHED_CHOICES = Object.freeze([0, 5, 15, 30, 60]);
|
|
27
|
+
|
|
28
|
+
/** A theme id the API takes. Whether this deck has that theme is the page's
|
|
29
|
+
* question (its catalog), never the server's. */
|
|
30
|
+
export const THEME_ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Every key, with its kind. `override: true` marks the one key a device keeps
|
|
34
|
+
* for itself in shared mode unless told otherwise — sound, because a laptop
|
|
35
|
+
* and a server want different answers.
|
|
36
|
+
*/
|
|
37
|
+
export const UI_FIELDS = Object.freeze([
|
|
38
|
+
Object.freeze({ key: "theme", kind: "theme" }),
|
|
39
|
+
Object.freeze({ key: "textSize", kind: "choice", choices: TEXT_SIZES }),
|
|
40
|
+
Object.freeze({ key: "density", kind: "choice", choices: DENSITIES }),
|
|
41
|
+
Object.freeze({ key: "panels.sessionList", kind: "bool" }),
|
|
42
|
+
Object.freeze({ key: "panels.accounts", kind: "bool" }),
|
|
43
|
+
Object.freeze({ key: "panels.detail", kind: "bool" }),
|
|
44
|
+
Object.freeze({ key: "panels.usage", kind: "bool" }),
|
|
45
|
+
Object.freeze({ key: "panels.machine", kind: "bool" }),
|
|
46
|
+
Object.freeze({ key: "singleKeyShortcuts", kind: "bool" }),
|
|
47
|
+
Object.freeze({ key: "hideFinishedAfter", kind: "minutes", choices: HIDE_FINISHED_CHOICES }),
|
|
48
|
+
Object.freeze({ key: "character", kind: "bool" }),
|
|
49
|
+
Object.freeze({ key: "sound", kind: "bool", override: true }),
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export const UI_KEYS = Object.freeze(UI_FIELDS.map(f => f.key));
|
|
53
|
+
|
|
54
|
+
/** The keys a device keeps for itself in shared mode by default. */
|
|
55
|
+
export const DEFAULT_OVERRIDES = Object.freeze(UI_FIELDS.filter(f => f.override).map(f => f.key));
|
|
56
|
+
|
|
57
|
+
const BY_KEY = new Map(UI_FIELDS.map(f => [f.key, f]));
|
|
58
|
+
|
|
59
|
+
/** Whether `value` is one `key` may hold. Unknown keys hold nothing. */
|
|
60
|
+
export function validUiValue(key, value) {
|
|
61
|
+
const field = BY_KEY.get(key);
|
|
62
|
+
if (!field) return false;
|
|
63
|
+
switch (field.kind) {
|
|
64
|
+
case "theme": return typeof value === "string" && THEME_ID.test(value);
|
|
65
|
+
case "choice": return typeof value === "string" && field.choices.includes(value);
|
|
66
|
+
case "minutes": return typeof value === "number" && field.choices.includes(value);
|
|
67
|
+
case "bool": return typeof value === "boolean";
|
|
68
|
+
default: return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The allowlisted part of `raw`: every known key with a value it may hold, and
|
|
74
|
+
* the names of what was refused — unknown keys and bad values alike — so a
|
|
75
|
+
* caller can say what it dropped. Never throws; anything that is not a plain
|
|
76
|
+
* object is no values at all.
|
|
77
|
+
*/
|
|
78
|
+
export function cleanUiValues(raw) {
|
|
79
|
+
const values = {};
|
|
80
|
+
const refused = [];
|
|
81
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { values, refused };
|
|
82
|
+
for (const key of Object.keys(raw)) {
|
|
83
|
+
if (validUiValue(key, raw[key])) values[key] = raw[key];
|
|
84
|
+
else refused.push(key);
|
|
85
|
+
}
|
|
86
|
+
return { values, refused };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Two value sets that hold the same keys with the same values. */
|
|
90
|
+
export function sameUiValues(a, b) {
|
|
91
|
+
const ak = Object.keys(a ?? {});
|
|
92
|
+
const bk = Object.keys(b ?? {});
|
|
93
|
+
return ak.length === bk.length && ak.every(k => Object.hasOwn(b, k) && b[k] === a[k]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** `values` split by where shared mode stores each key: the shared profile,
|
|
97
|
+
* or the device's own one for the override keys. */
|
|
98
|
+
export function splitByOverrides(values, overrides) {
|
|
99
|
+
const own = {};
|
|
100
|
+
const shared = {};
|
|
101
|
+
const keep = new Set(overrides ?? []);
|
|
102
|
+
for (const [k, v] of Object.entries(values ?? {})) (keep.has(k) ? own : shared)[k] = v;
|
|
103
|
+
return { own, shared };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* What a device shows for a settings binding (design 3.5, "Resolution on a
|
|
108
|
+
* device"): independent mode is its own profile; shared mode is the shared
|
|
109
|
+
* profile with the override keys taken from its own profile instead. A key
|
|
110
|
+
* with no value is absent, and the page leaves it alone.
|
|
111
|
+
*/
|
|
112
|
+
export function resolveUiValues({ mode, bound, own, overrides }) {
|
|
113
|
+
const boundValues = cleanUiValues(bound?.values).values;
|
|
114
|
+
if (mode !== "shared") return boundValues;
|
|
115
|
+
const ownValues = cleanUiValues(own?.values).values;
|
|
116
|
+
const out = { ...boundValues };
|
|
117
|
+
// The API's rule (UiSettingsSchema.Resolve in ccdeck-api): an override key is
|
|
118
|
+
// the device's own whatever the shared profile says — taken from the device
|
|
119
|
+
// profile when it has one, and absent (left alone on the device) when not.
|
|
120
|
+
// Never the shared value: that would hand a laptop's sound to a server.
|
|
121
|
+
for (const key of overrides ?? []) {
|
|
122
|
+
delete out[key];
|
|
123
|
+
if (Object.hasOwn(ownValues, key)) out[key] = ownValues[key];
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
@@ -76,7 +76,7 @@ function notifier() {
|
|
|
76
76
|
try { return JSON.parse(await readFile(path, "utf8")); } catch { return null; }
|
|
77
77
|
},
|
|
78
78
|
save: async records => {
|
|
79
|
-
await mkdir(dirname(path), { recursive: true });
|
|
79
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
80
80
|
await writeFileAtomic(path, `${JSON.stringify(records)}\n`);
|
|
81
81
|
},
|
|
82
82
|
});
|
|
@@ -97,7 +97,7 @@ export async function appendLog(episodes, home = claudeConfigDir(), deps = {}) {
|
|
|
97
97
|
if (!episodes.length) return;
|
|
98
98
|
const mk = deps.mkdir ?? mkdir;
|
|
99
99
|
const add = deps.appendFile ?? appendFile;
|
|
100
|
-
await mk(storeDir(home), { recursive: true });
|
|
100
|
+
await mk(storeDir(home), { recursive: true, mode: 0o700 });
|
|
101
101
|
const text = episodes.map(logBlock).join("\n") + "\n";
|
|
102
102
|
await rollIfFull(home, Buffer.byteLength(text, "utf8"), deps);
|
|
103
103
|
await add(logPath(home), text, "utf8");
|
|
@@ -415,7 +415,7 @@ async function writeNow(state, home, deps) {
|
|
|
415
415
|
// blank, while the episode archive — the file that exists BECAUSE an intruder
|
|
416
416
|
// can clear the browser's own history — is not written at all.
|
|
417
417
|
const mv = deps.rename ?? renameWithRetry;
|
|
418
|
-
await mk(storeDir(home), { recursive: true });
|
|
418
|
+
await mk(storeDir(home), { recursive: true, mode: 0o700 });
|
|
419
419
|
const body = JSON.stringify({
|
|
420
420
|
v: STORE_VERSION,
|
|
421
421
|
settings: normalise(state.settings),
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// The ccdeck account's local routes (design 4.8) — /api/account and the nine
|
|
2
|
+
// under it — and the `event: account` frames the open pages hear.
|
|
3
|
+
//
|
|
4
|
+
// GET /api/account the account, as the page draws it
|
|
5
|
+
// POST /api/account/connect { name } → a user code for the browser
|
|
6
|
+
// POST /api/account/connect/cancel
|
|
7
|
+
// POST /api/account/disconnect
|
|
8
|
+
// POST /api/account/ui { values, reason } what a person changed
|
|
9
|
+
// POST /api/account/ui/applied { revision, skipped? } a tab applied it
|
|
10
|
+
// GET /api/account/sync/preview this deck against the shared profile
|
|
11
|
+
// POST /api/account/sync/mode join or leave shared settings
|
|
12
|
+
// POST /api/account/sync/resolve { action: "use-latest" | "reapply" }
|
|
13
|
+
// POST /api/account/sync/upload { upload: true } to a different account
|
|
14
|
+
//
|
|
15
|
+
// and the account's feedback conversations (feedback-conversations design 4.4):
|
|
16
|
+
//
|
|
17
|
+
// GET /api/account/feedback/threads[?before=<cursor>] the list
|
|
18
|
+
// GET /api/account/feedback/threads/<id>[?before=<seq>] one conversation
|
|
19
|
+
// POST /api/account/feedback/threads a new one: JSON
|
|
20
|
+
// { kind, title, body }, or the dialog's form with its images
|
|
21
|
+
// POST /api/account/feedback/threads/<id>/replies { body }
|
|
22
|
+
// POST /api/account/feedback/threads/<id>/read { seq }
|
|
23
|
+
//
|
|
24
|
+
// A malformed id, cursor or item number is answered here and never leaves the
|
|
25
|
+
// deck. Every failure is `{ ok: false, reason }` (feedbackFailure below); the
|
|
26
|
+
// dialog words it.
|
|
27
|
+
//
|
|
28
|
+
// "ccdeck-account", not "account": account-routes.mjs is the CLAUDE accounts'
|
|
29
|
+
// routes — the logins this deck switches between — which are a different
|
|
30
|
+
// thing that happens to share the word.
|
|
31
|
+
//
|
|
32
|
+
// IMPORTED ONLY WHEN THE ACCOUNT IS ON. index.mjs reaches this module through
|
|
33
|
+
// a dynamic import() behind accountOn, so on a deck with the flag off it is
|
|
34
|
+
// never evaluated, and nor is anything it imports. The gates in front of the
|
|
35
|
+
// route table still run first: the two reads are in GUARDED_READS and every
|
|
36
|
+
// POST is a mutation, so only the deck's own page or a holder of its token
|
|
37
|
+
// gets here.
|
|
38
|
+
import { readBody, readBytes, send } from "./http-io.mjs";
|
|
39
|
+
import { MAX_REQUEST_BYTES, isMultipart, readFeedbackForm } from "./feedback-form.mjs";
|
|
40
|
+
import { createAccountService } from "./account-service.mjs";
|
|
41
|
+
import { sseClients, trayClients, writeSse } from "./sse-clients.mjs";
|
|
42
|
+
import { ringSnapshot } from "./event-ring.mjs";
|
|
43
|
+
import { connectEventTap } from "./event-pipeline.mjs";
|
|
44
|
+
import { machineReading } from "./system-metrics.mjs";
|
|
45
|
+
import { onBeforeShutdown } from "./lifecycle.mjs";
|
|
46
|
+
import { setDeviceTokens } from "./token-redact.mjs";
|
|
47
|
+
import { setupFacts } from "./activation.mjs";
|
|
48
|
+
import { deckProviders } from "./deck-scope.mjs";
|
|
49
|
+
import { heldPrefs } from "./prefs-state.mjs";
|
|
50
|
+
import { accountOn } from "./account-flag.mjs";
|
|
51
|
+
|
|
52
|
+
/** The bodies here are a name, a dozen settings and a revision. */
|
|
53
|
+
const BODY_LIMIT = 16 * 1024;
|
|
54
|
+
/** A feedback message is up to 10,000 characters, escaped: the API's own
|
|
55
|
+
* cap on its feedback device routes (FeedbackDeviceRequests.MaxBytes). */
|
|
56
|
+
export const FEEDBACK_JSON_LIMIT = 64 * 1024;
|
|
57
|
+
|
|
58
|
+
const FEEDBACK_PREFIX = "/api/account/feedback/threads";
|
|
59
|
+
const THREAD_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
60
|
+
const LIST_CURSOR = /^[A-Za-z0-9_-]{1,64}$/;
|
|
61
|
+
const ITEM_SEQ = /^(0|[1-9]\d{0,9})$/;
|
|
62
|
+
/** Each failure's status, by the reason the service gave (design 4.4). */
|
|
63
|
+
const FEEDBACK_STATUS = {
|
|
64
|
+
invalid: 400, not_found: 404, too_large: 413, too_many: 429, not_connected: 409, revoked: 409, unavailable: 502,
|
|
65
|
+
};
|
|
66
|
+
const TOO_LARGE = { ok: false, reason: "too_large" };
|
|
67
|
+
|
|
68
|
+
/** The page frames, never the desktop app's tray connections, which have no
|
|
69
|
+
* account to draw. */
|
|
70
|
+
function broadcastAccount(view) {
|
|
71
|
+
const frame = `event: account\ndata: ${JSON.stringify(view)}\n\n`;
|
|
72
|
+
for (const client of sseClients) {
|
|
73
|
+
if (!trayClients.has(client)) writeSse(client, frame);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Whether anything feeds this deck at all — Claude's hooks or the Codex
|
|
78
|
+
* watcher. Before the boot has said, the providers it was asked to watch. */
|
|
79
|
+
function captureOn() {
|
|
80
|
+
const s = setupFacts();
|
|
81
|
+
if (!s.codexWatch) {
|
|
82
|
+
const p = deckProviders();
|
|
83
|
+
return p.claude || p.codex;
|
|
84
|
+
}
|
|
85
|
+
return s.claudeHooks === "ok" || s.codexWatch === "on";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function jsonBody(req, res) {
|
|
89
|
+
const raw = await readBody(req, res, BODY_LIMIT).catch(() => null);
|
|
90
|
+
if (raw == null) return null;
|
|
91
|
+
if (raw === "") return {};
|
|
92
|
+
try {
|
|
93
|
+
const body = JSON.parse(raw);
|
|
94
|
+
return body && typeof body === "object" && !Array.isArray(body) ? body : null;
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A feedback answer from the service, sent: the API's body as it came, or
|
|
101
|
+
* the failure with the status its reason has. */
|
|
102
|
+
function sendFeedback(res, out, okStatus = 200) {
|
|
103
|
+
if (out.ok) return send(res, okStatus, out.body);
|
|
104
|
+
const { ok, reason, ...rest } = out;
|
|
105
|
+
return send(res, FEEDBACK_STATUS[reason] ?? 502, { ok: false, reason, ...rest });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const badRequest = res => send(res, 400, { ok: false, reason: "bad_request" });
|
|
109
|
+
|
|
110
|
+
/** A feedback route's JSON body, at most FEEDBACK_JSON_LIMIT bytes: an object,
|
|
111
|
+
* or null once it has been answered (too large) or is not one. */
|
|
112
|
+
async function feedbackJson(req, res) {
|
|
113
|
+
const bytes = await readBytes(req, res, FEEDBACK_JSON_LIMIT, TOO_LARGE).catch(() => null);
|
|
114
|
+
if (bytes == null) return null;
|
|
115
|
+
try {
|
|
116
|
+
const body = JSON.parse(bytes.length ? bytes.toString("utf8") : "{}");
|
|
117
|
+
return body && typeof body === "object" && !Array.isArray(body) ? body : null;
|
|
118
|
+
} catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Whether a request is one of the feedback routes. */
|
|
124
|
+
export function isFeedbackPath(path) {
|
|
125
|
+
return path === FEEDBACK_PREFIX || path.startsWith(`${FEEDBACK_PREFIX}/`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The five feedback routes. `path` is under FEEDBACK_PREFIX; the id and the
|
|
130
|
+
* cursors are checked before the service is asked anything.
|
|
131
|
+
*/
|
|
132
|
+
async function handleFeedback(service, req, res, url) {
|
|
133
|
+
const rest = url.pathname.slice(FEEDBACK_PREFIX.length);
|
|
134
|
+
const method = req.method;
|
|
135
|
+
if (rest === "") {
|
|
136
|
+
if (method === "GET") {
|
|
137
|
+
const before = url.searchParams.get("before");
|
|
138
|
+
if (before !== null && !LIST_CURSOR.test(before)) return badRequest(res);
|
|
139
|
+
return sendFeedback(res, await service.feedbackThreads({ before: before ?? undefined }));
|
|
140
|
+
}
|
|
141
|
+
if (method !== "POST") return send(res, 404, { error: "not found" });
|
|
142
|
+
const type = req.headers?.["content-type"];
|
|
143
|
+
if (isMultipart(type)) {
|
|
144
|
+
// Over the cap, readBytes has answered 413 too_large already.
|
|
145
|
+
const bytes = await readBytes(req, res, MAX_REQUEST_BYTES, TOO_LARGE).catch(() => null);
|
|
146
|
+
if (res.headersSent) return;
|
|
147
|
+
if (!bytes) return badRequest(res);
|
|
148
|
+
const form = await readFeedbackForm(bytes, type);
|
|
149
|
+
if (!form) return badRequest(res);
|
|
150
|
+
if (form.problems.length > 0) return send(res, 400, { ok: false, reason: "invalid", errors: { images: form.problems } });
|
|
151
|
+
return sendFeedback(res, await service.feedbackCreate({ fields: form.fields, images: form.images }), 201);
|
|
152
|
+
}
|
|
153
|
+
const body = await feedbackJson(req, res);
|
|
154
|
+
if (res.headersSent) return;
|
|
155
|
+
if (!body) return badRequest(res);
|
|
156
|
+
return sendFeedback(res, await service.feedbackCreate({ fields: body, images: [] }), 201);
|
|
157
|
+
}
|
|
158
|
+
const m = /^\/([^/]+)(\/replies|\/read)?$/.exec(rest);
|
|
159
|
+
if (!m) return send(res, 404, { error: "not found" });
|
|
160
|
+
const [, id, action] = m;
|
|
161
|
+
if (!THREAD_ID.test(id)) return badRequest(res);
|
|
162
|
+
if (!action) {
|
|
163
|
+
if (method !== "GET") return send(res, 404, { error: "not found" });
|
|
164
|
+
const before = url.searchParams.get("before");
|
|
165
|
+
if (before !== null && !ITEM_SEQ.test(before)) return badRequest(res);
|
|
166
|
+
return sendFeedback(res, await service.feedbackThread(id, { before: before === null ? undefined : Number(before) }));
|
|
167
|
+
}
|
|
168
|
+
if (method !== "POST") return send(res, 404, { error: "not found" });
|
|
169
|
+
const body = await feedbackJson(req, res);
|
|
170
|
+
if (res.headersSent) return;
|
|
171
|
+
if (!body) return badRequest(res);
|
|
172
|
+
if (action === "/replies") {
|
|
173
|
+
if (typeof body.body !== "string") return badRequest(res);
|
|
174
|
+
return sendFeedback(res, await service.feedbackReply(id, body.body), 201);
|
|
175
|
+
}
|
|
176
|
+
if (!Number.isInteger(body.seq) || body.seq < 0) return badRequest(res);
|
|
177
|
+
return sendFeedback(res, await service.feedbackRead(id, body.seq));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Build the service and start it. `deps` are startServer's `account` option,
|
|
182
|
+
* the suite's stand-ins (a token store that never touches a real keychain, a
|
|
183
|
+
* clock); the product passes nothing.
|
|
184
|
+
*/
|
|
185
|
+
export async function startAccountRoutes(deps = {}) {
|
|
186
|
+
const service = createAccountService({
|
|
187
|
+
prefs: () => heldPrefs.current(),
|
|
188
|
+
broadcast: broadcastAccount,
|
|
189
|
+
reading: machineReading,
|
|
190
|
+
ring: ringSnapshot,
|
|
191
|
+
connectTap: connectEventTap,
|
|
192
|
+
capture: captureOn,
|
|
193
|
+
registerShutdown: onBeforeShutdown,
|
|
194
|
+
setRedactions: setDeviceTokens,
|
|
195
|
+
enabled: () => accountOn(heldPrefs.current()),
|
|
196
|
+
...deps,
|
|
197
|
+
});
|
|
198
|
+
await service.start();
|
|
199
|
+
|
|
200
|
+
const notConnected = res => send(res, 409, { ok: false, error: "not_connected" });
|
|
201
|
+
|
|
202
|
+
async function handle(req, res, url) {
|
|
203
|
+
const path = url.pathname;
|
|
204
|
+
const method = req.method;
|
|
205
|
+
if (isFeedbackPath(path)) return handleFeedback(service, req, res, url);
|
|
206
|
+
if (method === "GET" && path === "/api/account") return send(res, 200, service.view());
|
|
207
|
+
if (method === "GET" && path === "/api/account/sync/preview") {
|
|
208
|
+
const out = await service.preview();
|
|
209
|
+
if (!out) return notConnected(res);
|
|
210
|
+
return send(res, out.error ? 502 : 200, out);
|
|
211
|
+
}
|
|
212
|
+
if (method !== "POST") return send(res, 404, { error: "not found" });
|
|
213
|
+
|
|
214
|
+
const body = await jsonBody(req, res);
|
|
215
|
+
if (res.headersSent) return;
|
|
216
|
+
if (!body) return send(res, 400, { ok: false, error: "bad_request" });
|
|
217
|
+
|
|
218
|
+
switch (path) {
|
|
219
|
+
case "/api/account/connect":
|
|
220
|
+
return send(res, 200, await service.connect(body.name));
|
|
221
|
+
case "/api/account/connect/cancel":
|
|
222
|
+
return send(res, 200, await service.cancelConnect());
|
|
223
|
+
case "/api/account/disconnect":
|
|
224
|
+
return send(res, 200, await service.disconnect());
|
|
225
|
+
case "/api/account/ui": {
|
|
226
|
+
const sync = await service.reportUi(body);
|
|
227
|
+
return sync ? send(res, 200, { sync }) : notConnected(res);
|
|
228
|
+
}
|
|
229
|
+
case "/api/account/ui/applied": {
|
|
230
|
+
const sync = await service.applied(body);
|
|
231
|
+
return sync ? send(res, 200, { sync }) : notConnected(res);
|
|
232
|
+
}
|
|
233
|
+
case "/api/account/sync/mode": {
|
|
234
|
+
const out = await service.setMode(body);
|
|
235
|
+
if (!out) return notConnected(res);
|
|
236
|
+
return send(res, out.error ? 409 : 200, out);
|
|
237
|
+
}
|
|
238
|
+
case "/api/account/sync/resolve": {
|
|
239
|
+
const sync = await service.resolve(body);
|
|
240
|
+
return sync ? send(res, 200, { sync }) : notConnected(res);
|
|
241
|
+
}
|
|
242
|
+
case "/api/account/sync/upload": {
|
|
243
|
+
const sync = await service.upload(body);
|
|
244
|
+
return sync ? send(res, 200, { sync }) : notConnected(res);
|
|
245
|
+
}
|
|
246
|
+
default:
|
|
247
|
+
return send(res, 404, { error: "not found" });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return { handle, service };
|
|
252
|
+
}
|
|
@@ -336,7 +336,7 @@ async function registryInstall(spec = "latest") {
|
|
|
336
336
|
|
|
337
337
|
function npmInstall(spec = "latest") {
|
|
338
338
|
return new Promise((resolve, reject) => {
|
|
339
|
-
mkdirSync(CACHE_DIR, { recursive: true });
|
|
339
|
+
mkdirSync(CACHE_DIR, { recursive: true, mode: 0o700 });
|
|
340
340
|
const { file, args, opts } = installSpec(spec);
|
|
341
341
|
const child = spawn(file, args, { windowsHide: true, ...opts });
|
|
342
342
|
let out = "", err = "", settled = false;
|
|
@@ -411,7 +411,7 @@ function updateCheckDue() {
|
|
|
411
411
|
// (Re)write the marker so its mtime marks "now" as the last check time.
|
|
412
412
|
export function touchMarker() {
|
|
413
413
|
try {
|
|
414
|
-
mkdirSync(CACHE_DIR, { recursive: true });
|
|
414
|
+
mkdirSync(CACHE_DIR, { recursive: true, mode: 0o700 });
|
|
415
415
|
writeFileSync(MARKER, String(Date.now()));
|
|
416
416
|
} catch { /* ignore */ }
|
|
417
417
|
}
|