ccdeck 3.46.0 → 3.48.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/README.md +99 -46
- package/bin/cli/commands.js +17 -9
- package/bin/cli/help.js +9 -4
- package/bin/cli/second-start.js +4 -2
- package/bin/cli/startup.js +26 -2
- package/bin/cli/tui.js +544 -0
- package/bin/deck.js +32 -1
- package/dist/web/assets/{BrowserWatchModal-CoX9FIUE.js → BrowserWatchModal-DuopT2Oa.js} +1 -1
- package/dist/web/assets/IntegrationModal-CszT-tts.js +7 -0
- package/dist/web/assets/{RadioPanel-biw_BbZq.js → RadioPanel-Cn3WvPUG.js} +1 -1
- package/dist/web/assets/TrafficRadar-DZA8XSi7.js +8 -0
- package/dist/web/assets/UsageHistoryModal-MgZJLXbF.js +1 -0
- package/dist/web/assets/app-DjlHxWHg.css +1 -0
- package/dist/web/assets/app-F1xryJpn.js +321 -0
- package/dist/web/assets/claude-settings-index-1Qg1AUda.js +1 -0
- package/dist/web/assets/{index-DmENqVdt.js → index-BK9avF1k.js} +1 -1
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/release-notes.json +58 -2
- package/src/server/args.mjs +1 -0
- package/src/server/ccusage-install.mjs +58 -1
- package/src/server/ccusage-registry.mjs +289 -0
- package/src/server/ccusage-runner.mjs +9 -2
- package/src/server/claude-accounts.mjs +21 -0
- package/src/server/claude-login.mjs +21 -3
- package/src/server/claude-settings-catalog.d.mts +37 -0
- package/src/server/claude-settings-catalog.mjs +169 -0
- package/src/server/claude-settings-docs.mjs +109 -0
- package/src/server/claude-settings-index.json +251 -0
- package/src/server/claude-settings-routes.mjs +46 -0
- package/src/server/claude-settings.mjs +406 -0
- package/src/server/cli-arrival.mjs +64 -0
- package/src/server/cli-lines.mjs +46 -0
- package/src/server/gpu-metrics.mjs +78 -0
- package/src/server/index.mjs +18 -2
- package/src/server/integrations/jira-move.mjs +239 -0
- package/src/server/integrations/jira.mjs +30 -8
- package/src/server/integrations/proxy.mjs +14 -6
- package/src/server/integrations/routes.mjs +25 -9
- package/src/server/quota-close-watch.mjs +81 -0
- package/src/server/quota-closes.mjs +181 -0
- package/src/server/quota-history.mjs +8 -1
- package/src/server/quota-shape.mjs +12 -0
- package/src/server/quota.mjs +28 -1
- package/src/server/request-gates.mjs +3 -1
- package/src/server/system-metrics.mjs +4 -0
- package/src/server/term.mjs +14 -5
- package/src/server/tool-audit-operations.mjs +30 -10
- package/src/server/tool-audit-report.mjs +79 -7
- package/src/server/tool-audit-routes.mjs +1 -1
- package/src/server/tool-audit-skills.mjs +8 -3
- package/src/server/tool-audit.mjs +55 -5
- package/src/server/traffic-radar-capture.mjs +3 -3
- package/src/server/traffic-radar-config.mjs +10 -3
- package/src/server/traffic-radar-monitor.mjs +8 -5
- package/src/server/traffic-radar-permission.mjs +162 -0
- package/src/server/traffic-radar-platform.mjs +9 -3
- package/src/server/traffic-radar-routes.mjs +8 -18
- package/src/server/traffic-radar-service.mjs +76 -92
- package/src/server/tui-screen.mjs +110 -0
- package/src/server/tui-view.mjs +1072 -0
- package/src/server/usage-routes.mjs +14 -2
- package/src/server/way-back.mjs +27 -0
- package/dist/web/assets/IntegrationModal-B1ypkK-E.js +0 -5
- package/dist/web/assets/TrafficRadar-nhtFoYVv.js +0 -8
- package/dist/web/assets/UsageHistoryModal-Bd-JRAa4.js +0 -1
- package/dist/web/assets/app-BlRY6EME.css +0 -1
- package/dist/web/assets/app-DhGvSH7o.js +0 -319
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// ccusage fetched straight from the npm registry, for a machine with no npm.
|
|
2
|
+
//
|
|
3
|
+
// The managed install in ccusage-install.mjs is `npm install ccusage --prefix`,
|
|
4
|
+
// and the fallback after it is `npx -y ccusage@latest`. Both need Node's npm,
|
|
5
|
+
// and the desktop app is the one way of running this deck that never needed
|
|
6
|
+
// Node at all: it runs the deck on its own Electron binary. Reproduced on a
|
|
7
|
+
// clean Windows VM with the 3.46.0 app and no Node: the boot logged
|
|
8
|
+
// `'"npm.cmd"' is not recognized`, the npx fallback failed the same way, and the
|
|
9
|
+
// Usage panel never had anything from ccusage to show — on the machine of a
|
|
10
|
+
// first-time user, which is the one that judges the tool.
|
|
11
|
+
//
|
|
12
|
+
// What npm would have done here is small enough to do without it. ccusage 20
|
|
13
|
+
// has no dependencies. Its package is a cli.js that runs a native binary, and
|
|
14
|
+
// that binary ships as one optional dependency per platform
|
|
15
|
+
// (`@ccusage/ccusage-<platform>-<arch>`, a few MB, no install scripts). So this
|
|
16
|
+
// asks the registry for the two packages, checks each tarball against the
|
|
17
|
+
// sha512 the registry publishes for it, which is the check npm itself makes, and
|
|
18
|
+
// unpacks them into the same directory npm would have produced, so
|
|
19
|
+
// resolveEntry, nativeCcusage and cli.js find everything where they always have.
|
|
20
|
+
//
|
|
21
|
+
// Nothing is installed anywhere but the deck's own cache directory, and no
|
|
22
|
+
// package script is run, because npm would not run one for these two either.
|
|
23
|
+
import { createHash } from "node:crypto";
|
|
24
|
+
import { existsSync } from "node:fs";
|
|
25
|
+
import { mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
26
|
+
import path from "node:path";
|
|
27
|
+
import { gunzip } from "node:zlib";
|
|
28
|
+
import { promisify } from "node:util";
|
|
29
|
+
|
|
30
|
+
const gunzipAsync = promisify(gunzip);
|
|
31
|
+
|
|
32
|
+
/** The registry this asks, unless the environment names another. npm exports
|
|
33
|
+
* `npm_config_registry` to everything it runs, and a user who set it by hand
|
|
34
|
+
* has said where their packages come from. */
|
|
35
|
+
export function registryBase(env = process.env) {
|
|
36
|
+
const named = String(env.npm_config_registry ?? env.NPM_CONFIG_REGISTRY ?? "").trim();
|
|
37
|
+
return (named || "https://registry.npmjs.org").replace(/\/+$/, "");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** ccusage's platform package for this machine, named the way its cli.js names
|
|
41
|
+
* it, or null on a platform ccusage publishes no binary for. */
|
|
42
|
+
export function nativePackageName(platform = process.platform, arch = process.arch) {
|
|
43
|
+
if (!["darwin", "linux", "win32"].includes(platform)) return null;
|
|
44
|
+
if (arch !== "x64" && arch !== "arm64") return null;
|
|
45
|
+
return `@ccusage/ccusage-${platform}-${arch}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Bigger than either package by an order of magnitude, and a stop for a
|
|
49
|
+
* registry or proxy that answers with something that is not a package. */
|
|
50
|
+
const MAX_TARBALL_BYTES = 64 << 20;
|
|
51
|
+
|
|
52
|
+
// A dist-tag or an exact version. Anything else would be put into a URL path.
|
|
53
|
+
const SPEC = /^[0-9A-Za-z][0-9A-Za-z.+-]*$/;
|
|
54
|
+
|
|
55
|
+
async function getJson(url, { fetch, signal }) {
|
|
56
|
+
const res = await fetch(url, { headers: { accept: "application/json" }, signal });
|
|
57
|
+
if (!res.ok) throw new Error(`${url} answered ${res.status}`);
|
|
58
|
+
return res.json();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The registry's record of one version of one package: its version, where its
|
|
63
|
+
* tarball is, the integrity string that tarball has to match, and its optional
|
|
64
|
+
* dependencies. `spec` is a dist-tag ("latest") or an exact version.
|
|
65
|
+
*/
|
|
66
|
+
export async function packageVersion(name, spec, { fetch = globalThis.fetch, base = registryBase(), signal } = {}) {
|
|
67
|
+
if (!SPEC.test(String(spec))) throw new Error(`not a version or tag: ${spec}`);
|
|
68
|
+
// A scoped name keeps its `@` and has its `/` escaped, which is how the
|
|
69
|
+
// registry spells it in a path.
|
|
70
|
+
const url = `${base}/${name.replace("/", "%2F")}/${spec}`;
|
|
71
|
+
const doc = await getJson(url, { fetch, signal });
|
|
72
|
+
const tarball = doc?.dist?.tarball;
|
|
73
|
+
const integrity = doc?.dist?.integrity;
|
|
74
|
+
if (typeof doc?.version !== "string" || typeof tarball !== "string" || typeof integrity !== "string") {
|
|
75
|
+
throw new Error(`${url} did not describe a package version`);
|
|
76
|
+
}
|
|
77
|
+
if (!/^https?:\/\//.test(tarball)) throw new Error(`${name}@${doc.version} has no usable tarball URL`);
|
|
78
|
+
return { name, version: doc.version, tarball, integrity, optional: doc.optionalDependencies ?? {} };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Whether `bytes` are what `integrity` says, by the sha512 entries in it.
|
|
83
|
+
*
|
|
84
|
+
* An integrity string is space-separated `<algo>-<base64>` entries. Only sha512
|
|
85
|
+
* is accepted: the registry publishes it for every package this fetches, and a
|
|
86
|
+
* record that offers only something weaker is not one to trust a binary to.
|
|
87
|
+
*/
|
|
88
|
+
export function integrityMatches(bytes, integrity) {
|
|
89
|
+
const wanted = String(integrity ?? "").split(/\s+/)
|
|
90
|
+
.filter(e => e.startsWith("sha512-"))
|
|
91
|
+
.map(e => e.slice("sha512-".length).split("?")[0]);
|
|
92
|
+
if (!wanted.length) return false;
|
|
93
|
+
const got = createHash("sha512").update(bytes).digest("base64");
|
|
94
|
+
return wanted.includes(got);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function download(pkg, { fetch, signal }) {
|
|
98
|
+
const res = await fetch(pkg.tarball, { signal });
|
|
99
|
+
if (!res.ok) throw new Error(`${pkg.tarball} answered ${res.status}`);
|
|
100
|
+
const declared = Number(res.headers?.get?.("content-length"));
|
|
101
|
+
if (declared > MAX_TARBALL_BYTES) throw new Error(`${pkg.name}@${pkg.version} is ${declared} bytes, more than a ccusage package should be`);
|
|
102
|
+
const bytes = Buffer.from(await res.arrayBuffer());
|
|
103
|
+
if (bytes.length > MAX_TARBALL_BYTES) throw new Error(`${pkg.name}@${pkg.version} is ${bytes.length} bytes, more than a ccusage package should be`);
|
|
104
|
+
if (!integrityMatches(bytes, pkg.integrity)) {
|
|
105
|
+
throw new Error(`${pkg.name}@${pkg.version} does not match the integrity the registry published for it`);
|
|
106
|
+
}
|
|
107
|
+
return bytes;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const text = (buf, start, len) => {
|
|
111
|
+
const raw = buf.subarray(start, start + len);
|
|
112
|
+
const end = raw.indexOf(0);
|
|
113
|
+
return raw.subarray(0, end === -1 ? raw.length : end).toString("utf8");
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const octal = (buf, start, len) => {
|
|
117
|
+
if (buf[start] & 0x80) throw new Error("tar entry uses a size encoding no npm package needs");
|
|
118
|
+
const s = text(buf, start, len).trim();
|
|
119
|
+
return s ? parseInt(s, 8) : 0;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/** The `path` record out of a pax extended header, or null. */
|
|
123
|
+
function paxPath(body) {
|
|
124
|
+
for (const line of body.toString("utf8").split("\n")) {
|
|
125
|
+
const m = /^\d+ path=(.*)$/.exec(line);
|
|
126
|
+
if (m) return m[1];
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The entries of an uncompressed tar archive: `{ name, mode, type, body }`.
|
|
133
|
+
*
|
|
134
|
+
* Only what npm tarballs use: ustar headers with their prefix field, pax `path`
|
|
135
|
+
* records and GNU long names. Everything is read out of one buffer that has
|
|
136
|
+
* already passed the integrity check, so a truncated archive is the one
|
|
137
|
+
* malformation worth naming.
|
|
138
|
+
*
|
|
139
|
+
* Exported for tests.
|
|
140
|
+
*/
|
|
141
|
+
export function* tarEntries(buf) {
|
|
142
|
+
let off = 0;
|
|
143
|
+
let longName = null;
|
|
144
|
+
while (off + 512 <= buf.length) {
|
|
145
|
+
const head = buf.subarray(off, off + 512);
|
|
146
|
+
if (head.every(b => b === 0)) return;
|
|
147
|
+
const size = octal(head, 124, 12);
|
|
148
|
+
const type = head[156] ? String.fromCharCode(head[156]) : "0";
|
|
149
|
+
const prefix = text(head, 257, 6).startsWith("ustar") ? text(head, 345, 155) : "";
|
|
150
|
+
const start = off + 512;
|
|
151
|
+
if (start + size > buf.length) throw new Error("the package archive is truncated");
|
|
152
|
+
const body = buf.subarray(start, start + size);
|
|
153
|
+
off = start + Math.ceil(size / 512) * 512;
|
|
154
|
+
if (type === "x" || type === "L") { longName = type === "x" ? paxPath(body) : text(body, 0, body.length); continue; }
|
|
155
|
+
if (type === "g") continue;
|
|
156
|
+
const short = text(head, 0, 100);
|
|
157
|
+
const name = longName ?? (prefix ? `${prefix}/${short}` : short);
|
|
158
|
+
longName = null;
|
|
159
|
+
yield { name, mode: octal(head, 100, 8), type, body };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Unpack an npm tarball into `dest`, without its top directory (`package/` in
|
|
165
|
+
* every tarball npm publishes).
|
|
166
|
+
*
|
|
167
|
+
* Regular files and directories only. npm drops links out of a package too,
|
|
168
|
+
* and a link is the one entry that could make a later write land outside
|
|
169
|
+
* `dest`. Every name is also checked to stay inside `dest`: a `..`, a drive
|
|
170
|
+
* letter or a colon, which on Windows names a stream of another file, fails the
|
|
171
|
+
* whole unpack rather than skipping one entry, because a package that contains
|
|
172
|
+
* one of those is not one to run.
|
|
173
|
+
*
|
|
174
|
+
* Exported for tests.
|
|
175
|
+
*/
|
|
176
|
+
export async function unpack(tgz, dest) {
|
|
177
|
+
const tar = await gunzipAsync(tgz);
|
|
178
|
+
const root = path.resolve(dest);
|
|
179
|
+
await mkdir(root, { recursive: true });
|
|
180
|
+
for (const entry of tarEntries(tar)) {
|
|
181
|
+
if (entry.type !== "0" && entry.type !== "5") continue;
|
|
182
|
+
const parts = entry.name.replace(/\\/g, "/").split("/").filter(p => p && p !== ".");
|
|
183
|
+
parts.shift();
|
|
184
|
+
if (!parts.length) continue;
|
|
185
|
+
if (parts.some(p => p === ".." || p.includes(":"))) {
|
|
186
|
+
throw new Error(`the package archive names a path outside itself: ${entry.name}`);
|
|
187
|
+
}
|
|
188
|
+
const target = path.resolve(root, ...parts);
|
|
189
|
+
if (!target.startsWith(root + path.sep)) {
|
|
190
|
+
throw new Error(`the package archive names a path outside itself: ${entry.name}`);
|
|
191
|
+
}
|
|
192
|
+
if (entry.type === "5") { await mkdir(target, { recursive: true }); continue; }
|
|
193
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
194
|
+
// An executable bit is kept, as npm keeps it. ccusage's cli.js would set it
|
|
195
|
+
// on the native binary anyway before running it, but a copy that looks
|
|
196
|
+
// like npm's is one nothing downstream has to know about. Windows has no
|
|
197
|
+
// such bit and ignores the mode.
|
|
198
|
+
await writeFile(target, entry.body, { mode: entry.mode & 0o111 ? 0o755 : 0o644 });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Put ccusage `spec` and this platform's native package into `pkgDir`, the
|
|
204
|
+
* directory npm would have made `node_modules/ccusage`.
|
|
205
|
+
*
|
|
206
|
+
* The native package goes INSIDE it, under `pkgDir/node_modules/@ccusage/…`,
|
|
207
|
+
* where Node's resolution from cli.js finds it first. That keeps the whole
|
|
208
|
+
* install one directory, so it is swapped in with one rename: a run that starts
|
|
209
|
+
* while this works sees the old copy or the new one, never half of each.
|
|
210
|
+
*
|
|
211
|
+
* Built in a sibling directory and renamed into place. If the old copy cannot
|
|
212
|
+
* be moved aside — on Windows, a ccusage.exe still running out of it — the new
|
|
213
|
+
* one is thrown away and the old one stays, which is the same outcome as an npm
|
|
214
|
+
* update that failed, and the next check tries again.
|
|
215
|
+
*
|
|
216
|
+
* Resolves to the version installed. `fetch` and `platform`/`arch` are
|
|
217
|
+
* injectable for tests.
|
|
218
|
+
*/
|
|
219
|
+
export async function fetchCcusage({
|
|
220
|
+
spec = "latest",
|
|
221
|
+
pkgDir,
|
|
222
|
+
fetch = globalThis.fetch,
|
|
223
|
+
base = registryBase(),
|
|
224
|
+
platform = process.platform,
|
|
225
|
+
arch = process.arch,
|
|
226
|
+
timeoutMs = 120_000,
|
|
227
|
+
} = {}) {
|
|
228
|
+
if (typeof fetch !== "function") throw new Error("this Node has no fetch");
|
|
229
|
+
const nativeName = nativePackageName(platform, arch);
|
|
230
|
+
if (!nativeName) throw new Error(`ccusage publishes no build for ${platform}-${arch}`);
|
|
231
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
232
|
+
const opts = { fetch, base, signal };
|
|
233
|
+
|
|
234
|
+
const main = await packageVersion("ccusage", spec, opts);
|
|
235
|
+
const nativeSpec = main.optional[nativeName];
|
|
236
|
+
if (typeof nativeSpec !== "string" || !SPEC.test(nativeSpec)) {
|
|
237
|
+
throw new Error(`ccusage@${main.version} names no exact ${nativeName} version`);
|
|
238
|
+
}
|
|
239
|
+
const native = await packageVersion(nativeName, nativeSpec, opts);
|
|
240
|
+
const [mainTgz, nativeTgz] = await Promise.all([download(main, opts), download(native, opts)]);
|
|
241
|
+
|
|
242
|
+
const stamp = `${process.pid}-${Date.now()}`;
|
|
243
|
+
const staging = `${pkgDir}.fetching-${stamp}`;
|
|
244
|
+
const old = `${pkgDir}.old-${stamp}`;
|
|
245
|
+
try {
|
|
246
|
+
await unpack(mainTgz, staging);
|
|
247
|
+
await unpack(nativeTgz, path.join(staging, "node_modules", ...nativeName.split("/")));
|
|
248
|
+
await mkdir(path.dirname(pkgDir), { recursive: true });
|
|
249
|
+
const hadOld = existsSync(pkgDir);
|
|
250
|
+
if (hadOld) await renameSoon(pkgDir, old);
|
|
251
|
+
try {
|
|
252
|
+
await renameSoon(staging, pkgDir);
|
|
253
|
+
} catch (err) {
|
|
254
|
+
if (hadOld) await renameSoon(old, pkgDir).catch(() => {});
|
|
255
|
+
throw err;
|
|
256
|
+
}
|
|
257
|
+
// Only once the new copy is in place: until then `old` is the copy to put back.
|
|
258
|
+
if (hadOld) await rm(old, { recursive: true, force: true, maxRetries: 10, retryDelay: 25 }).catch(() => {});
|
|
259
|
+
} finally {
|
|
260
|
+
await rm(staging, { recursive: true, force: true }).catch(() => {});
|
|
261
|
+
}
|
|
262
|
+
return main.version;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* `rename`, given a moment when Windows says the file is busy.
|
|
267
|
+
*
|
|
268
|
+
* A freshly written ccusage.exe is opened by the antivirus scanner before
|
|
269
|
+
* anything else gets to it, and while it is open its directory cannot be
|
|
270
|
+
* renamed. That is a hold of a moment, not a refusal, and npm's own file system
|
|
271
|
+
* layer retries the same three codes for the same reason.
|
|
272
|
+
*/
|
|
273
|
+
async function renameSoon(from, to, tries = 8) {
|
|
274
|
+
for (let i = 1; ; i++) {
|
|
275
|
+
try {
|
|
276
|
+
return await rename(from, to);
|
|
277
|
+
} catch (err) {
|
|
278
|
+
if (i >= tries || !["EPERM", "EACCES", "EBUSY"].includes(err?.code)) throw err;
|
|
279
|
+
await new Promise(r => setTimeout(r, 50 * i));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** The version the registry calls `latest`, for the daily update check on a
|
|
285
|
+
* machine with no `npm view` to ask. */
|
|
286
|
+
export async function latestCcusage({ fetch = globalThis.fetch, base = registryBase(), timeoutMs = 30_000 } = {}) {
|
|
287
|
+
const { version } = await packageVersion("ccusage", "latest", { fetch, base, signal: AbortSignal.timeout(timeoutMs) });
|
|
288
|
+
return version;
|
|
289
|
+
}
|
|
@@ -12,8 +12,8 @@ import { existsSync } from "node:fs";
|
|
|
12
12
|
import { killTree, pathLookup, spawnSpec } from "./exec.mjs";
|
|
13
13
|
import { note, stamp, tagged } from "./ccusage-failure.mjs";
|
|
14
14
|
import {
|
|
15
|
-
discardDamagedInstall, installsDisabled, lastInstallError, maybeBackgroundUpdate,
|
|
16
|
-
startInstall, touchMarker, winShim,
|
|
15
|
+
discardDamagedInstall, installsDisabled, lastInstallError, maybeBackgroundUpdate, npmAvailable,
|
|
16
|
+
resolveEntry, startInstall, touchMarker, winShim,
|
|
17
17
|
} from "./ccusage-install.mjs";
|
|
18
18
|
|
|
19
19
|
const TIMEOUT_MS = 90_000;
|
|
@@ -158,6 +158,13 @@ async function getRunner() {
|
|
|
158
158
|
await startInstall("latest");
|
|
159
159
|
resolved = resolveEntry();
|
|
160
160
|
if (resolved) { touchMarker(); return { kind: "node", entry: resolved.entry }; }
|
|
161
|
+
// No npm means no npx, so there is no fallback to hand back. The install that
|
|
162
|
+
// just failed was the registry download, and its own account is the whole
|
|
163
|
+
// story: an npx run here would only fail again with "npx is not recognized"
|
|
164
|
+
// and the modal would lead with that instead.
|
|
165
|
+
if (!npmAvailable()) {
|
|
166
|
+
throw tagged("fetch_failed", lastInstallError() ?? "ccusage could not be downloaded from the npm registry");
|
|
167
|
+
}
|
|
161
168
|
// npm unavailable / offline → fall back to npx, carrying WHY the managed
|
|
162
169
|
// install is not here. Without that the modal can only describe the fallback,
|
|
163
170
|
// and the fallback is the second thing that failed.
|
|
@@ -753,6 +753,27 @@ export async function activeAccountUsage() {
|
|
|
753
753
|
};
|
|
754
754
|
}
|
|
755
755
|
|
|
756
|
+
/**
|
|
757
|
+
* What claude-swap last collected for every account it manages: the two small
|
|
758
|
+
* files activeAccountUsage reads, under the same identity guard, and nothing
|
|
759
|
+
* else — no CLI, no verdicts, no repair. The record of how full each window was
|
|
760
|
+
* at its reset (quota-close-watch.mjs) reads this on a timer, and a timer must
|
|
761
|
+
* not start what a look at the accounts panel does.
|
|
762
|
+
*/
|
|
763
|
+
export async function storedUsageReadings() {
|
|
764
|
+
const root = backupRoot();
|
|
765
|
+
const seq = await readSequence(root);
|
|
766
|
+
if (!seq?.accounts || typeof seq.accounts !== "object") return [];
|
|
767
|
+
const rows = await readUsageRows(root);
|
|
768
|
+
return Object.entries(seq.accounts).flatMap(([num, acct]) => {
|
|
769
|
+
const row = rows[num];
|
|
770
|
+
const fetchedAt = rowIsFor(row, acct) ? observedMs(row.fetchedAt) : null;
|
|
771
|
+
return row?.lastGood && fetchedAt != null
|
|
772
|
+
? [{ email: acct.email, organizationUuid: acct.organizationUuid ?? "", lastGood: row.lastGood, fetchedAt }]
|
|
773
|
+
: [];
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
|
|
756
777
|
/**
|
|
757
778
|
* Ask claude-swap to collect now, if its own schedule agrees.
|
|
758
779
|
*
|
|
@@ -23,6 +23,7 @@ import { readFile, stat } from "node:fs/promises";
|
|
|
23
23
|
import { homedir } from "node:os";
|
|
24
24
|
import { posix, win32 } from "node:path";
|
|
25
25
|
import { claudeConfigDir } from "./claude-dir.mjs";
|
|
26
|
+
import { claudePlanToken } from "./depth-facts.mjs";
|
|
26
27
|
|
|
27
28
|
async function exists(path, statFile) {
|
|
28
29
|
try { await statFile(path); return true; } catch { return false; }
|
|
@@ -51,10 +52,26 @@ export async function claudeGlobalConfigPath({
|
|
|
51
52
|
// The last answer, and the file it was read from: path, mtime and size.
|
|
52
53
|
let _last = null;
|
|
53
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The plan of a signed-in account, as claudePlanToken names it ("max-20x",
|
|
57
|
+
* "pro"…), or null when `oauthAccount` does not say one it knows.
|
|
58
|
+
*
|
|
59
|
+
* Claude Code keeps the plan in two places: `subscriptionType` and
|
|
60
|
+
* `rateLimitTier` beside the token in .credentials.json, and
|
|
61
|
+
* `organizationType` ("claude_max") and `organizationRateLimitTier`
|
|
62
|
+
* ("default_claude_max_20x") here. This is the one every platform has: on
|
|
63
|
+
* macOS the token, and the two fields beside it, are in the Keychain.
|
|
64
|
+
*/
|
|
65
|
+
export function planOfAccount(oauth) {
|
|
66
|
+
const type = typeof oauth?.organizationType === "string" ? oauth.organizationType.trim().replace(/^claude_/i, "") : "";
|
|
67
|
+
return claudePlanToken({ subscriptionType: type, rateLimitTier: oauth?.organizationRateLimitTier }) ?? null;
|
|
68
|
+
}
|
|
69
|
+
|
|
54
70
|
/**
|
|
55
71
|
* Who Claude Code is signed in as — `{ email, orgUuid }` from the config's
|
|
56
|
-
* `oauthAccount
|
|
57
|
-
* login with no organization, as
|
|
72
|
+
* `oauthAccount`, and `plan` when planOfAccount can say it — or null when that
|
|
73
|
+
* cannot be read. `orgUuid` is "" for a login with no organization, as
|
|
74
|
+
* claude-swap normalises it.
|
|
58
75
|
*/
|
|
59
76
|
export async function readLiveLogin({
|
|
60
77
|
env = process.env, home = homedir(), platform = process.platform, statFile = stat, read = readFile,
|
|
@@ -65,8 +82,9 @@ export async function readLiveLogin({
|
|
|
65
82
|
if (_last?.path === path && _last.mtimeMs === st.mtimeMs && _last.size === st.size) return _last.login;
|
|
66
83
|
const oauth = JSON.parse(String(await read(path, "utf8")).replace(/^/, ""))?.oauthAccount;
|
|
67
84
|
const email = typeof oauth?.emailAddress === "string" ? oauth.emailAddress : "";
|
|
85
|
+
const plan = planOfAccount(oauth);
|
|
68
86
|
const login = email
|
|
69
|
-
? { email, orgUuid: typeof oauth.organizationUuid === "string" ? oauth.organizationUuid : "" }
|
|
87
|
+
? { email, orgUuid: typeof oauth.organizationUuid === "string" ? oauth.organizationUuid : "", ...(plan && { plan }) }
|
|
70
88
|
: null;
|
|
71
89
|
_last = { path, mtimeMs: st.mtimeMs, size: st.size, login };
|
|
72
90
|
return login;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type ClaudeSettingGroup = "sessions" | "memory" | "git" | "terminal" | "updates";
|
|
2
|
+
export type ClaudeSettingKind = "switch" | "choice" | "days" | "allowTool" | "attribution";
|
|
3
|
+
|
|
4
|
+
export interface ClaudeSettingOption {
|
|
5
|
+
value: string | null;
|
|
6
|
+
label: string;
|
|
7
|
+
/** A value in the file that means the same as this option. */
|
|
8
|
+
also?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ClaudeSettingOverride {
|
|
12
|
+
env: string;
|
|
13
|
+
when: "on" | "off";
|
|
14
|
+
effect: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ClaudeSettingEntry {
|
|
18
|
+
id: string;
|
|
19
|
+
key: string;
|
|
20
|
+
group: ClaudeSettingGroup;
|
|
21
|
+
kind: ClaudeSettingKind;
|
|
22
|
+
label: string;
|
|
23
|
+
note: string;
|
|
24
|
+
keywords: readonly string[];
|
|
25
|
+
since?: string;
|
|
26
|
+
overrides?: readonly ClaudeSettingOverride[];
|
|
27
|
+
legacy?: boolean;
|
|
28
|
+
unset?: boolean | number;
|
|
29
|
+
tool?: string;
|
|
30
|
+
options?: readonly (ClaudeSettingOption | number)[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const CLAUDE_SETTINGS_DOCS: string;
|
|
34
|
+
export const CLAUDE_SETTING_GROUPS: readonly { id: ClaudeSettingGroup; title: string }[];
|
|
35
|
+
export const CLAUDE_SETTINGS: readonly ClaudeSettingEntry[];
|
|
36
|
+
export function claudeSettingById(id: string): ClaudeSettingEntry | undefined;
|
|
37
|
+
export function daysLabel(days: number): string;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// Settings › Claude Code: the Claude Code settings the deck offers a control
|
|
2
|
+
// for, in its own words, and how each one is written to the user's
|
|
3
|
+
// settings.json.
|
|
4
|
+
//
|
|
5
|
+
// ONE TABLE FOR BOTH ENDS. The server checks every write against it
|
|
6
|
+
// (claude-settings.mjs) and the page draws one row per entry and indexes them
|
|
7
|
+
// for search (ClaudeCodeSettings.tsx, settings-search.ts), so a row can never
|
|
8
|
+
// offer a value the server would refuse, and a key the server does not know
|
|
9
|
+
// is never written.
|
|
10
|
+
//
|
|
11
|
+
// A SHORT LIST ON PURPOSE. Claude Code reads some two hundred and fifty keys
|
|
12
|
+
// (claude-settings-index.json lists them all, read-only). These are the ones
|
|
13
|
+
// a person running several sessions from the deck is likely to want and is
|
|
14
|
+
// unlikely to have found: plain switches and choices whose every value is
|
|
15
|
+
// safe to write. Permission modes, hooks, sandboxing, credentials and anything
|
|
16
|
+
// shaped as an object stay out, because a wrong press there is not undone by
|
|
17
|
+
// pressing again.
|
|
18
|
+
//
|
|
19
|
+
// THE DEFAULT IS AN ABSENT KEY. Choosing the value Claude Code uses when the
|
|
20
|
+
// key is unset removes the key rather than writing that value, so the file
|
|
21
|
+
// keeps only what the person changed, and a later change of default in Claude
|
|
22
|
+
// Code reaches them.
|
|
23
|
+
//
|
|
24
|
+
// ONLY A ROW THAT DOES WHAT IT SAYS. A key whose effect depends on the model
|
|
25
|
+
// is not here: `effortLevel` in the user file is ignored by Opus 5.5 and every
|
|
26
|
+
// model after it, which read `modelSettings` instead, and
|
|
27
|
+
// `alwaysThinkingEnabled: false` does nothing on a model that always thinks.
|
|
28
|
+
// Both are better changed where Claude Code shows the model, with /effort and
|
|
29
|
+
// /model.
|
|
30
|
+
|
|
31
|
+
export const CLAUDE_SETTINGS_DOCS = "https://code.claude.com/docs/en/settings-reference";
|
|
32
|
+
|
|
33
|
+
/** The captions the rows are drawn under, in the order they are drawn. */
|
|
34
|
+
export const CLAUDE_SETTING_GROUPS = [
|
|
35
|
+
{ id: "sessions", title: "Your sessions" },
|
|
36
|
+
{ id: "memory", title: "Memory and history" },
|
|
37
|
+
{ id: "git", title: "Git" },
|
|
38
|
+
{ id: "terminal", title: "Terminal" },
|
|
39
|
+
{ id: "updates", title: "Updates" },
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* kind:
|
|
44
|
+
* switch a Boolean key; `unset` is what Claude Code does without it
|
|
45
|
+
* choice a string key from `options`; `null` is the absent key
|
|
46
|
+
* days a whole number of days from `options`
|
|
47
|
+
* allowTool a bare tool name in permissions.deny; on is "not denied"
|
|
48
|
+
* attribution `attribution: false` when off, the key absent when on
|
|
49
|
+
*
|
|
50
|
+
* since: the oldest Claude Code that reads the value the row writes. Older
|
|
51
|
+
* ones ignore it, or for `attribution: false` skip the whole settings file
|
|
52
|
+
* over it, so the row is not written while the version cannot be read.
|
|
53
|
+
*
|
|
54
|
+
* overrides: environment variables Claude Code's reference says outrank the
|
|
55
|
+
* key, each with the value that does (`on`: 1, true, yes; `off`: 0, false,
|
|
56
|
+
* no) and what it makes of the row. Read from the `env` block of the files
|
|
57
|
+
* the deck reads, and from the deck's own environment.
|
|
58
|
+
*
|
|
59
|
+
* legacy: a value an older Claude Code kept in ~/.claude.json still applies
|
|
60
|
+
* while no settings file sets the key.
|
|
61
|
+
*/
|
|
62
|
+
export const CLAUDE_SETTINGS = [
|
|
63
|
+
{
|
|
64
|
+
id: "crossSessionInbound", key: "crossSessionInbound", group: "sessions", kind: "choice", since: "2.1.224",
|
|
65
|
+
label: "Messages from other sessions",
|
|
66
|
+
note: "What a session does when another of your Claude Code sessions sends it a message.",
|
|
67
|
+
options: [
|
|
68
|
+
{ value: null, label: "Claude Code decides" },
|
|
69
|
+
{ value: "accept", label: "Accept" },
|
|
70
|
+
{ value: "hold", label: "Ask me first" },
|
|
71
|
+
{ value: "refuse", label: "Refuse" },
|
|
72
|
+
],
|
|
73
|
+
keywords: ["peers", "cross-session", "sendmessage", "inbox", "other sessions", "messaging"],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "listAgents", key: "permissions.deny", tool: "ListAgents", group: "sessions", kind: "allowTool", since: "2.1.224",
|
|
77
|
+
label: "Let sessions find each other",
|
|
78
|
+
note: "On, Claude can list your other sessions, with each one's folder and whether it is busy. Off adds a deny rule for ListAgents.",
|
|
79
|
+
keywords: ["listagents", "peers", "see other sessions", "privacy", "isolation", "list agents"],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "isolatePeerMachines", key: "isolatePeerMachines", group: "sessions", kind: "switch", unset: false, since: "2.1.224",
|
|
83
|
+
label: "Ask before messaging other machines",
|
|
84
|
+
note: "Claude asks you before a message leaves this computer for a session on another machine or in the cloud.",
|
|
85
|
+
keywords: ["remote control", "cloud", "cross-machine", "approval"],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: "autoMemoryEnabled", key: "autoMemoryEnabled", group: "memory", kind: "switch", unset: true,
|
|
89
|
+
label: "Auto memory",
|
|
90
|
+
note: "Claude keeps notes it learns while working and reads them in later sessions. Off, it does neither.",
|
|
91
|
+
overrides: [
|
|
92
|
+
{ env: "CLAUDE_CODE_DISABLE_AUTO_MEMORY", when: "on", effect: "Off" },
|
|
93
|
+
{ env: "CLAUDE_CODE_DISABLE_AUTO_MEMORY", when: "off", effect: "On" },
|
|
94
|
+
],
|
|
95
|
+
keywords: ["memory", "remember", "notes", "memory.md"],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: "autoCompactEnabled", key: "autoCompactEnabled", group: "memory", kind: "switch", unset: true,
|
|
99
|
+
label: "Compact automatically",
|
|
100
|
+
note: "Claude summarizes a long conversation when it nears the context limit, so the session can go on.",
|
|
101
|
+
overrides: [{ env: "DISABLE_AUTO_COMPACT", when: "on", effect: "Off" }],
|
|
102
|
+
keywords: ["compact", "context", "summarize", "context window"],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: "cleanupPeriodDays", key: "cleanupPeriodDays", group: "memory", kind: "days", unset: 30,
|
|
106
|
+
label: "Keep conversations",
|
|
107
|
+
note: "Older conversations are deleted without a message and leave the resume list.",
|
|
108
|
+
options: [7, 14, 30, 90, 180, 365, 3650],
|
|
109
|
+
keywords: ["transcripts", "history", "retention", "delete", "resume", "cleanup"],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: "fileCheckpointingEnabled", key: "fileCheckpointingEnabled", group: "memory", kind: "switch", unset: true,
|
|
113
|
+
label: "Checkpoints for rewind",
|
|
114
|
+
note: "Claude keeps a copy of each file before editing it, so a change can be rewound.",
|
|
115
|
+
overrides: [{ env: "CLAUDE_CODE_DISABLE_FILE_CHECKPOINTING", when: "on", effect: "Off" }],
|
|
116
|
+
keywords: ["rewind", "checkpoint", "restore", "revert"],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "attribution", key: "attribution", group: "git", kind: "attribution", since: "2.1.281",
|
|
120
|
+
label: "Credit Claude in commits and pull requests",
|
|
121
|
+
note: "Off, Claude adds no Co-Authored-By line to commits and no attribution line to pull requests.",
|
|
122
|
+
keywords: ["co-authored-by", "co-author", "trailer", "generated with", "commit message", "pull request", "attribution"],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: "spinnerTipsEnabled", key: "spinnerTipsEnabled", group: "terminal", kind: "switch", unset: true,
|
|
126
|
+
label: "Tips while Claude works",
|
|
127
|
+
note: "The tip under the spinner while a turn is running.",
|
|
128
|
+
keywords: ["spinner", "tips", "hints"],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: "showTurnDuration", key: "showTurnDuration", group: "terminal", kind: "switch", unset: true, legacy: true,
|
|
132
|
+
label: "Show how long a turn took",
|
|
133
|
+
note: "The line after each turn that says how long Claude worked.",
|
|
134
|
+
keywords: ["duration", "time", "timer"],
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: "prefersReducedMotion", key: "prefersReducedMotion", group: "terminal", kind: "switch", unset: false,
|
|
138
|
+
label: "Reduce motion",
|
|
139
|
+
note: "Fewer animations in the terminal, such as the spinner, shimmer and flash effects.",
|
|
140
|
+
keywords: ["animation", "motion", "accessibility", "spinner"],
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: "autoUpdatesChannel", key: "autoUpdatesChannel", group: "updates", kind: "choice",
|
|
144
|
+
label: "Update channel",
|
|
145
|
+
note: "Stable follows a version about a week old and skips releases with major regressions.",
|
|
146
|
+
overrides: [
|
|
147
|
+
{ env: "DISABLE_UPDATES", when: "on", effect: "Updates are off" },
|
|
148
|
+
{ env: "DISABLE_AUTOUPDATER", when: "on", effect: "Background updates are off" },
|
|
149
|
+
],
|
|
150
|
+
options: [
|
|
151
|
+
// `claude install latest` writes the default out, so it reads as this.
|
|
152
|
+
{ value: null, label: "Latest", also: "latest" },
|
|
153
|
+
{ value: "stable", label: "Stable" },
|
|
154
|
+
],
|
|
155
|
+
keywords: ["updates", "release channel", "stable", "latest", "version"],
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
/** The entry for an id, or undefined for any id the table does not hold. */
|
|
160
|
+
export function claudeSettingById(id) {
|
|
161
|
+
return CLAUDE_SETTINGS.find(entry => entry.id === id);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The label a `days` row shows for a number of days. */
|
|
165
|
+
export function daysLabel(days) {
|
|
166
|
+
if (days === 3650) return "10 years";
|
|
167
|
+
if (days === 365) return "1 year";
|
|
168
|
+
return days === 1 ? "1 day" : `${days} days`;
|
|
169
|
+
}
|