ccdeck 3.46.0 → 3.47.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.
Files changed (54) hide show
  1. package/README.md +72 -43
  2. package/bin/cli/startup.js +23 -0
  3. package/bin/deck.js +32 -1
  4. package/dist/web/assets/BrowserWatchModal-Bau0ttnH.js +1 -0
  5. package/dist/web/assets/IntegrationModal-8tTi25gA.js +6 -0
  6. package/dist/web/assets/{RadioPanel-biw_BbZq.js → RadioPanel-DbmJJPsz.js} +1 -1
  7. package/dist/web/assets/TrafficRadar-CPjAXd5e.js +8 -0
  8. package/dist/web/assets/{UsageHistoryModal-Bd-JRAa4.js → UsageHistoryModal-qfmvXdWJ.js} +1 -1
  9. package/dist/web/assets/app-BFFG6Wz8.js +321 -0
  10. package/dist/web/assets/app-DfcfHvcX.css +1 -0
  11. package/dist/web/assets/claude-settings-index-1Qg1AUda.js +1 -0
  12. package/dist/web/assets/{index-DmENqVdt.js → index-Ca87aJP9.js} +1 -1
  13. package/dist/web/index.html +3 -3
  14. package/package.json +1 -1
  15. package/release-notes.json +30 -0
  16. package/src/server/ccusage-install.mjs +58 -1
  17. package/src/server/ccusage-registry.mjs +289 -0
  18. package/src/server/ccusage-runner.mjs +9 -2
  19. package/src/server/claude-accounts.mjs +21 -0
  20. package/src/server/claude-login.mjs +21 -3
  21. package/src/server/claude-settings-catalog.d.mts +37 -0
  22. package/src/server/claude-settings-catalog.mjs +169 -0
  23. package/src/server/claude-settings-docs.mjs +109 -0
  24. package/src/server/claude-settings-index.json +251 -0
  25. package/src/server/claude-settings-routes.mjs +46 -0
  26. package/src/server/claude-settings.mjs +406 -0
  27. package/src/server/cli-arrival.mjs +64 -0
  28. package/src/server/index.mjs +18 -2
  29. package/src/server/integrations/proxy.mjs +11 -2
  30. package/src/server/integrations/routes.mjs +6 -4
  31. package/src/server/quota-close-watch.mjs +81 -0
  32. package/src/server/quota-closes.mjs +181 -0
  33. package/src/server/quota-history.mjs +8 -1
  34. package/src/server/quota-shape.mjs +12 -0
  35. package/src/server/quota.mjs +28 -1
  36. package/src/server/request-gates.mjs +3 -1
  37. package/src/server/tool-audit-operations.mjs +30 -10
  38. package/src/server/tool-audit-report.mjs +79 -7
  39. package/src/server/tool-audit-routes.mjs +1 -1
  40. package/src/server/tool-audit-skills.mjs +8 -3
  41. package/src/server/tool-audit.mjs +55 -5
  42. package/src/server/traffic-radar-capture.mjs +3 -3
  43. package/src/server/traffic-radar-config.mjs +10 -3
  44. package/src/server/traffic-radar-monitor.mjs +8 -5
  45. package/src/server/traffic-radar-permission.mjs +162 -0
  46. package/src/server/traffic-radar-platform.mjs +9 -3
  47. package/src/server/traffic-radar-routes.mjs +8 -18
  48. package/src/server/traffic-radar-service.mjs +76 -92
  49. package/src/server/usage-routes.mjs +14 -2
  50. package/dist/web/assets/BrowserWatchModal-CoX9FIUE.js +0 -1
  51. package/dist/web/assets/IntegrationModal-B1ypkK-E.js +0 -5
  52. package/dist/web/assets/TrafficRadar-nhtFoYVv.js +0 -8
  53. package/dist/web/assets/app-BlRY6EME.css +0 -1
  54. package/dist/web/assets/app-DhGvSH7o.js +0 -319
@@ -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, resolveEntry,
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` — or null when that cannot be read. `orgUuid` is "" for a
57
- * login with no organization, as claude-swap normalises it.
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
+ }
@@ -0,0 +1,109 @@
1
+ // The keys Claude Code documents, read out of its settings reference page
2
+ // (https://code.claude.com/docs/en/settings-reference.md) — the source for
3
+ // claude-settings-index.json (scripts/claude-settings-index.mjs).
4
+ //
5
+ // THE PAGE IS READ, NOT TRUSTED. It is Markdown written for people, so every
6
+ // field is taken from one fixed shape — a `### \`key\`` heading, then its
7
+ // "Type" and "Default" bullets — and a key whose shape does not match keeps
8
+ // what could be read and nothing guessed. The settings index table at the top
9
+ // of the page names each key's topic, scope and anchor.
10
+ //
11
+ // FACTS, NOT THE PAGE'S WORDS. The reference is Anthropic's, all rights
12
+ // reserved, so what is kept is what a key is — its name, topic, scope, the
13
+ // kind of value it takes, its choices, a literal default, the version that
14
+ // added it — and never a sentence of its description. The deck links to the
15
+ // page for those (Settings › Claude Code).
16
+
17
+ const ENTRY_HEADING = /^### `([A-Za-z][\w.]*)`\s*$/gm;
18
+ const INDEX_ROW = /^\| \[`([^`]+)`\]\(#([^)]*)\) \| .*? \| ([^|]+?) \| ([^|]+?) \|$/gm;
19
+
20
+ /** The bullet `* **Name**: text` of an entry, as the page wrote it, or null. */
21
+ function bullet(body, name) {
22
+ const m = new RegExp(`^\\* \\*\\*${name}\\*\\*: (.*)$`, "m").exec(body);
23
+ return m ? m[1].trim() : null;
24
+ }
25
+
26
+ /** A Default bullet that is a value rather than a sentence: one code span,
27
+ * or the word "unset". Anything worded is left to the page. */
28
+ function literalDefault(text) {
29
+ if (text === "unset") return "unset";
30
+ const m = /^`([^`]{1,40})`$/.exec(text ?? "");
31
+ return m ? m[1] : null;
32
+ }
33
+
34
+ /** What kind of value a Type bullet describes, in the deck's four words. */
35
+ function kindOf(type) {
36
+ const t = (type ?? "").toLowerCase();
37
+ if (t.startsWith("boolean")) return "boolean";
38
+ if (t.startsWith("string, one of")) return "choice";
39
+ if (t.startsWith("number") || t.startsWith("integer")) return "number";
40
+ if (t.startsWith("string")) return "text";
41
+ return "structured";
42
+ }
43
+
44
+ /** The quoted values listed under a "string, one of" Type bullet. */
45
+ function choices(body) {
46
+ const at = body.search(/^\* \*\*Type\*\*: string, one of/m);
47
+ if (at < 0) return [];
48
+ const out = [];
49
+ for (const line of body.slice(at).split("\n").slice(1)) {
50
+ const m = /^ {2}\* `"([^"`]+)"`/.exec(line);
51
+ if (m) out.push(m[1]);
52
+ else if (!/^ {2,}/.test(line)) break;
53
+ }
54
+ return out;
55
+ }
56
+
57
+ /** The lowest "Requires Claude Code vX" an entry names, or null. */
58
+ function since(body) {
59
+ const versions = [...body.matchAll(/[Rr]equires Claude Code v(\d+\.\d+\.\d+)/g)].map(m => m[1]);
60
+ if (!versions.length) return null;
61
+ return versions.sort((a, b) => {
62
+ const x = a.split(".").map(Number), y = b.split(".").map(Number);
63
+ return x[0] - y[0] || x[1] - y[1] || x[2] - y[2];
64
+ })[0];
65
+ }
66
+
67
+ /** The page's anchor for a heading, as its own links spell it, for a key the
68
+ * index table does not link. */
69
+ export function anchorFor(key) {
70
+ return key.toLowerCase().replace(/\./g, "-").replace(/[^a-z0-9-]+/g, "");
71
+ }
72
+
73
+ /**
74
+ * Every documented key, in the page's order: its topic, scope and anchor from
75
+ * the index table, and from its own entry the kind of value it holds, the
76
+ * choices for a choice, a literal default, and the lowest Claude Code version
77
+ * the entry names. Keys whose scope is "Global config" live in ~/.claude.json
78
+ * and not in settings.json.
79
+ */
80
+ export function parseSettingsReference(markdown) {
81
+ const topics = new Map();
82
+ for (const m of markdown.matchAll(INDEX_ROW)) topics.set(m[1], { anchor: m[2], topic: m[3].trim(), scope: m[4].trim() });
83
+ const headings = [...markdown.matchAll(ENTRY_HEADING)];
84
+ const keys = [];
85
+ headings.forEach((m, i) => {
86
+ const key = m[1];
87
+ const end = i + 1 < headings.length ? headings[i + 1].index : markdown.length;
88
+ let body = markdown.slice(m.index + m[0].length, end);
89
+ const section = body.search(/^## /m);
90
+ if (section >= 0) body = body.slice(0, section);
91
+ const type = bullet(body, "Type");
92
+ const row = topics.get(key);
93
+ const options = choices(body);
94
+ // "One of" a list of words rather than of fixed strings — a model name, a
95
+ // duration — is a string to type, not a choice.
96
+ const kind = kindOf(type) === "choice" && !options.length ? "text" : kindOf(type);
97
+ keys.push({
98
+ key,
99
+ topic: row?.topic ?? null,
100
+ scope: row?.scope ?? null,
101
+ kind,
102
+ ...(kind === "choice" ? { options } : {}),
103
+ default: literalDefault(bullet(body, "Default")),
104
+ since: since(body),
105
+ anchor: row?.anchor ?? anchorFor(key),
106
+ });
107
+ });
108
+ return { keys };
109
+ }