@clagentic/console 1.8.0 → 1.9.0-beta.2

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 (64) hide show
  1. package/bin/cli.js +12 -1
  2. package/lib/agents.js +13 -3
  3. package/lib/build-sha.json +2 -2
  4. package/lib/cli/ipc-subcommands.js +40 -4
  5. package/lib/daemon.js +25 -1
  6. package/lib/generated/claude-model-catalog.json +180 -0
  7. package/lib/model-catalog.js +202 -0
  8. package/lib/model-families.js +243 -0
  9. package/lib/project-connection.js +30 -5
  10. package/lib/project-loop.js +46 -2
  11. package/lib/project-sessions.js +133 -21
  12. package/lib/project-user-message.js +70 -3
  13. package/lib/project.js +11 -1
  14. package/lib/public/app.js +14 -4
  15. package/lib/public/css/base.css +14 -0
  16. package/lib/public/css/home-hub.css +28 -8
  17. package/lib/public/css/icon-strip.css +17 -0
  18. package/lib/public/css/menus.css +67 -0
  19. package/lib/public/css/messages.css +11 -0
  20. package/lib/public/css/mobile-nav.css +22 -0
  21. package/lib/public/css/server-settings.css +72 -0
  22. package/lib/public/css/sidebar.css +15 -0
  23. package/lib/public/css/title-bar.css +10 -1
  24. package/lib/public/index.html +4 -0
  25. package/lib/public/modules/activity-latch.js +159 -0
  26. package/lib/public/modules/activity-state.js +157 -0
  27. package/lib/public/modules/app-connection.js +10 -4
  28. package/lib/public/modules/app-favicon.js +88 -1
  29. package/lib/public/modules/app-home-hub.js +14 -11
  30. package/lib/public/modules/app-loop-ui.js +90 -2
  31. package/lib/public/modules/app-messages.js +117 -28
  32. package/lib/public/modules/app-panels.js +184 -56
  33. package/lib/public/modules/app-projects.js +28 -8
  34. package/lib/public/modules/app-rate-limit.js +14 -2
  35. package/lib/public/modules/model-families.js +230 -0
  36. package/lib/public/modules/project-settings.js +1 -0
  37. package/lib/public/modules/scheduler.js +5 -0
  38. package/lib/public/modules/server-settings.js +14 -12
  39. package/lib/public/modules/settings-defaults.js +151 -41
  40. package/lib/public/modules/sidebar-mobile.js +32 -22
  41. package/lib/public/modules/sidebar-projects.js +42 -14
  42. package/lib/public/modules/sidebar-sessions.js +168 -48
  43. package/lib/public/modules/tools.js +22 -12
  44. package/lib/sdk-bridge.js +389 -35
  45. package/lib/sdk-message-processor.js +215 -7
  46. package/lib/sdk-skill-discovery.js +46 -6
  47. package/lib/sdk-slash-enrichment.js +5 -2
  48. package/lib/server-hub-sessions.js +70 -0
  49. package/lib/server.js +79 -22
  50. package/lib/session-activity.js +289 -0
  51. package/lib/sessions.js +104 -3
  52. package/lib/smtp.js +10 -1
  53. package/lib/terminal-manager.js +40 -0
  54. package/lib/utils.js +44 -0
  55. package/lib/ws-schema.js +17 -0
  56. package/lib/yoke/adapters/claude-worker.js +6 -2
  57. package/lib/yoke/adapters/claude.js +384 -88
  58. package/lib/yoke/adapters/codex.js +239 -31
  59. package/package.json +2 -2
  60. package/scripts/check-test-count.js +397 -0
  61. package/scripts/generate-model-catalog.js +337 -0
  62. package/scripts/test-file-completion-reporter.js +43 -0
  63. package/lib/model-context-windows.js +0 -65
  64. package/lib/public/modules/model-context-windows.js +0 -62
package/bin/cli.js CHANGED
@@ -33,7 +33,7 @@ var { forkDaemon, devMode, setDaemonWatcherOpts } = require("../lib/cli/daemon-l
33
33
  var { setup, promptRestoreProjects, showMainMenu } = require("../lib/cli/menus");
34
34
  var { getLocalIP } = require("../lib/cli/net-detect");
35
35
  var { log, a, sym } = require("../lib/cli/tui");
36
- var { handleShutdown, handleRestart, handleAdd, handleRemove, handleList } = require("../lib/cli/ipc-subcommands");
36
+ var { handleShutdown, handleRestart, handleAdd, handleRemove, handleList, handleActivityDiagnostics } = require("../lib/cli/ipc-subcommands");
37
37
 
38
38
  var args = process.argv.slice(2);
39
39
 
@@ -69,6 +69,7 @@ var noRestart = false;
69
69
  var addPath = null;
70
70
  var removePath = null;
71
71
  var listMode = false;
72
+ var activityDiagnosticsMode = false;
72
73
  var dangerouslySkipPermissions = false;
73
74
  var headlessMode = false;
74
75
  var watchMode = false;
@@ -118,6 +119,8 @@ for (var i = 0; i < args.length; i++) {
118
119
  i++;
119
120
  } else if (args[i] === "--list") {
120
121
  listMode = true;
122
+ } else if (args[i] === "--activity-diagnostics") {
123
+ activityDiagnosticsMode = true;
121
124
  } else if (args[i] === "--headless") {
122
125
  headlessMode = true;
123
126
  autoYes = true;
@@ -132,6 +135,7 @@ for (var i = 0; i < args.length; i++) {
132
135
  console.log(" clagentic-console --add <path> Add a project to the running daemon");
133
136
  console.log(" clagentic-console --remove <path> Remove a project from the running daemon");
134
137
  console.log(" clagentic-console --list List registered projects");
138
+ console.log(" clagentic-console --activity-diagnostics Print activity-divergence probe totals as JSON (agent-readable)");
135
139
  console.log(" clagentic-console release list-betas List promotable beta versions (maintainer/release-engineering)");
136
140
  console.log("");
137
141
  console.log("Options:");
@@ -149,6 +153,7 @@ for (var i = 0; i < args.length; i++) {
149
153
  console.log(" --add <path> Add a project directory (use '.' for current)");
150
154
  console.log(" --remove <path> Remove a project directory");
151
155
  console.log(" --list List all registered projects");
156
+ console.log(" --activity-diagnostics Print activity-divergence probe totals as JSON");
152
157
  console.log(" --headless Start daemon and exit immediately (implies --yes)");
153
158
  console.log(" --multi-user Start in multi-user mode (use with --yes for headless)");
154
159
  console.log(" --os-users Enable OS-level user isolation (Linux, requires root + --multi-user)");
@@ -194,6 +199,12 @@ if (listMode) {
194
199
  return;
195
200
  }
196
201
 
202
+ // --- Handle --activity-diagnostics before anything else ---
203
+ if (activityDiagnosticsMode) {
204
+ handleActivityDiagnostics();
205
+ return;
206
+ }
207
+
197
208
  // --multi-user / --os-users are now handled in the main entry flow (setup wizard or repeat run)
198
209
  // Flags are parsed above and applied during forkDaemon()
199
210
 
package/lib/agents.js CHANGED
@@ -83,6 +83,12 @@ function slugifyAgentName(name) {
83
83
  // enforcement in the query setup path.
84
84
  //
85
85
  // agentName: the agent identity string (e.g. "agentic-director").
86
+ // globalAgentsDir: optional override of AGENTS_SOURCE_DIR. On a shared
87
+ // multi-user daemon, callers resolve the SESSION OWNER's home
88
+ // (os-users.getLinuxUserHome(linuxUser)) and pass
89
+ // path.join(thatHome, ".claude", "agents") here so the on-disk agent
90
+ // definition is read from the invoking user's own home, not the daemon
91
+ // process's REAL_HOME (lr-3ccc78 twin of the skill-discovery fix).
86
92
  // Returns: string[] of tool names if the tools field is a valid JSON array,
87
93
  // null if the file is absent, the frontmatter is missing, or the
88
94
  // tools field cannot be parsed.
@@ -90,11 +96,12 @@ function slugifyAgentName(name) {
90
96
  // Failures are silent (logged at debug level) — callers treat null as "no
91
97
  // restriction from this source" and fall through to whatever the SDK applies
92
98
  // via claudeOpts.agent.
93
- function readAgentToolsFromFile(agentName) {
99
+ function readAgentToolsFromFile(agentName, globalAgentsDir) {
94
100
  if (!agentName || typeof agentName !== "string") return null;
95
101
  var slug = slugifyAgentName(agentName);
96
102
  if (!slug) return null;
97
- var filePath = path.join(AGENTS_SOURCE_DIR, slug + ".md");
103
+ var baseDir = (typeof globalAgentsDir === "string" && globalAgentsDir) ? globalAgentsDir : AGENTS_SOURCE_DIR;
104
+ var filePath = path.join(baseDir, slug + ".md");
98
105
  var raw;
99
106
  try {
100
107
  raw = fs.readFileSync(filePath, "utf8");
@@ -256,7 +263,10 @@ function _readAgentsFromDir(agentsDir) {
256
263
  return results;
257
264
  }
258
265
 
259
- // _globalAgentsDir is an optional override used in tests; callers must not pass it.
266
+ // _globalAgentsDir is an optional override of the global agents directory.
267
+ // Tests use it to point at a fixture dir; production callers on a shared
268
+ // multi-user daemon pass the session owner's own ~/.claude/agents (see
269
+ // readAgentToolsFromFile above, lr-3ccc78).
260
270
  function readProjectAgents(projectDir, _globalAgentsDir) {
261
271
  if (!projectDir || typeof projectDir !== "string") return [];
262
272
 
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "1d6a911981fd6f0b6219b23fd65678ab4646f372",
3
- "writtenAt": "2026-07-25T11:51:34.846Z"
2
+ "sha": "99208748c957f643a44ee6fab76a8fc1891f3b1b",
3
+ "writtenAt": "2026-08-27T22:24:59.717Z"
4
4
  }
@@ -1,10 +1,15 @@
1
1
  // lib/cli/ipc-subcommands.js
2
2
  //
3
3
  // One-shot IPC subcommand handlers for bin/cli.js: --shutdown, --restart,
4
- // --add <path>, --remove <path>, --list. Each of these talks to the running
5
- // daemon over the Unix socket and exits the process directly (they never
6
- // return control to the caller) — extracted verbatim from bin/cli.js
7
- // (lr-4e49 Part 1), no behavior change.
4
+ // --add <path>, --remove <path>, --list, --activity-diagnostics. Each of
5
+ // these talks to the running daemon over the Unix socket and exits the
6
+ // process directly (they never return control to the caller) —
7
+ // --shutdown/--restart/--add/--remove/--list extracted verbatim from
8
+ // bin/cli.js (lr-4e49 Part 1), no behavior change.
9
+ // --activity-diagnostics added by lr-8b476f: the only agent-readable
10
+ // (Bash+Read, no browser/WS/devtools) retrieval path for the lr-58c813
11
+ // server-side activity-divergence probe. Prints raw JSON to stdout so a
12
+ // read-only crew agent can run this directly.
8
13
 
9
14
  var fs = require("fs");
10
15
  var path = require("path");
@@ -177,10 +182,41 @@ function handleList() {
177
182
  });
178
183
  }
179
184
 
185
+ // lr-8b476f: prints the activity-divergence probe totals (same data
186
+ // process_stats's WS response folds in, see lib/daemon.js's
187
+ // "get_activity_diagnostics" IPC case) as raw JSON to stdout. This is the
188
+ // retrieval path for a read-only crew agent (Bash+Read only, no browser,
189
+ // no WS client, no devtools): `clagentic-console --activity-diagnostics`.
190
+ function handleActivityDiagnostics() {
191
+ var diagConfig = loadConfig();
192
+ isDaemonAliveAsync(diagConfig).then(function (alive) {
193
+ if (!alive) {
194
+ console.error("No running daemon. Start with: npx @clagentic/console");
195
+ process.exit(1);
196
+ }
197
+ sendIPCCommand(socketPath(), { cmd: "get_activity_diagnostics" }).then(function (res) {
198
+ if (!res.ok) {
199
+ console.error("Failed: " + (res.error || "unknown error"));
200
+ process.exit(1);
201
+ return;
202
+ }
203
+ // Raw JSON to stdout — the point is machine readability, not a
204
+ // human-formatted summary (contrast handleList's formatted output).
205
+ console.log(JSON.stringify({
206
+ activeLiveCount: res.activeLiveCount,
207
+ activityDivergenceCount: res.activityDivergenceCount,
208
+ activityDivergenceRecentSamples: res.activityDivergenceRecentSamples,
209
+ }, null, 2));
210
+ process.exit(0);
211
+ });
212
+ });
213
+ }
214
+
180
215
  module.exports = {
181
216
  handleShutdown: handleShutdown,
182
217
  handleRestart: handleRestart,
183
218
  handleAdd: handleAdd,
184
219
  handleRemove: handleRemove,
185
220
  handleList: handleList,
221
+ handleActivityDiagnostics: handleActivityDiagnostics,
186
222
  };
package/lib/daemon.js CHANGED
@@ -31,7 +31,7 @@ var usersModule = require("./users");
31
31
  var { createWorktree, removeWorktree, isWorktree } = require("./worktree");
32
32
  var { isWorktreeSlug, scanAndRegisterWorktrees, rescanWorktrees, cleanupWorktreesForParent, getFilteredRemovedProjects, registerWorktreeSlug, unregisterWorktreeSlug } = require("./daemon-projects");
33
33
  var { validateCloneUrl, buildCloneArgs } = require("./clone-validate");
34
- var { DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiveCount } = require("./sdk-bridge");
34
+ var { DEFAULT_MEM_AVAILABLE_MIN_MB, DEFAULT_TOKENS_PER_MB_HEADROOM, getActiveLiveCount, buildActivityDiagnosticsResponse } = require("./sdk-bridge");
35
35
  var { startMemoryHighWatcher, checkAppliedMemoryCeiling } = require("./memory-limits");
36
36
  var { createDrain } = require("./drain");
37
37
  var { shedMemory } = require("./memory-shed");
@@ -1553,6 +1553,30 @@ var ipc = createIPCServer(socketPath(), function (msg) {
1553
1553
  uptime: process.uptime(),
1554
1554
  };
1555
1555
 
1556
+ // lr-8b476f: agent-readable counterpart to the WS-only process_stats
1557
+ // handler (lib/project-sessions.js:668-709). Reads the same shared
1558
+ // module-level counter (lib/sdk-bridge.js) that process_stats already
1559
+ // folds into its response via getMemoryStats() — buildActivityDiagnosticsResponse
1560
+ // is unit-tested directly (test/activity-diagnostics-retrieval-lr-8b476f.test.js),
1561
+ // since daemon.js has no module.exports and cannot be required
1562
+ // in-process without binding real sockets/HTTP servers.
1563
+ //
1564
+ // Read-only, mutates nothing. Gated the same way every other IPC
1565
+ // command on this socket is gated: CONFIG_DIR (containing daemon.sock)
1566
+ // is chmod 0700 (ensureConfigDir, lib/config.js), so only the daemon's
1567
+ // own OS user can connect at all — no new auth surface is introduced,
1568
+ // and none is copied from process_stats's WS gap (lr-2016fe) either,
1569
+ // since this is a different transport with its own (stricter, OS-level)
1570
+ // gate rather than an unaudited role check.
1571
+ //
1572
+ // Samples carry no session-identifying field, matching process_stats's
1573
+ // BOBBIE-remediated shape exactly (lib/sdk-bridge.js
1574
+ // _recordActivityDivergenceIfAny) — this command reads the SAME
1575
+ // samples, so nothing new is exposed by adding this second retrieval
1576
+ // path.
1577
+ case "get_activity_diagnostics":
1578
+ return buildActivityDiagnosticsResponse();
1579
+
1556
1580
  case "set_pin": {
1557
1581
  config.pinHash = msg.pinHash || null;
1558
1582
  relay.setAuthToken(config.pinHash);
@@ -0,0 +1,180 @@
1
+ {
2
+ "generatedAt": "2026-07-31T16:37:55.539Z",
3
+ "source": "deprecations-page",
4
+ "models": [
5
+ {
6
+ "id": "claude-1.0",
7
+ "displayName": "claude-1.0",
8
+ "createdAt": null,
9
+ "status": "retired"
10
+ },
11
+ {
12
+ "id": "claude-1.1",
13
+ "displayName": "claude-1.1",
14
+ "createdAt": null,
15
+ "status": "retired"
16
+ },
17
+ {
18
+ "id": "claude-1.2",
19
+ "displayName": "claude-1.2",
20
+ "createdAt": null,
21
+ "status": "retired"
22
+ },
23
+ {
24
+ "id": "claude-1.3",
25
+ "displayName": "claude-1.3",
26
+ "createdAt": null,
27
+ "status": "retired"
28
+ },
29
+ {
30
+ "id": "claude-2.0",
31
+ "displayName": "claude-2.0",
32
+ "createdAt": null,
33
+ "status": "retired"
34
+ },
35
+ {
36
+ "id": "claude-2.1",
37
+ "displayName": "claude-2.1",
38
+ "createdAt": null,
39
+ "status": "retired"
40
+ },
41
+ {
42
+ "id": "claude-3-5-haiku-20241022",
43
+ "displayName": "claude-3-5-haiku-20241022",
44
+ "createdAt": null,
45
+ "status": "retired"
46
+ },
47
+ {
48
+ "id": "claude-3-5-sonnet-20240620",
49
+ "displayName": "claude-3-5-sonnet-20240620",
50
+ "createdAt": null,
51
+ "status": "retired"
52
+ },
53
+ {
54
+ "id": "claude-3-5-sonnet-20241022",
55
+ "displayName": "claude-3-5-sonnet-20241022",
56
+ "createdAt": null,
57
+ "status": "retired"
58
+ },
59
+ {
60
+ "id": "claude-3-7-sonnet-20250219",
61
+ "displayName": "claude-3-7-sonnet-20250219",
62
+ "createdAt": null,
63
+ "status": "retired"
64
+ },
65
+ {
66
+ "id": "claude-3-haiku-20240307",
67
+ "displayName": "claude-3-haiku-20240307",
68
+ "createdAt": null,
69
+ "status": "retired"
70
+ },
71
+ {
72
+ "id": "claude-3-opus-20240229",
73
+ "displayName": "claude-3-opus-20240229",
74
+ "createdAt": null,
75
+ "status": "retired"
76
+ },
77
+ {
78
+ "id": "claude-3-sonnet-20240229",
79
+ "displayName": "claude-3-sonnet-20240229",
80
+ "createdAt": null,
81
+ "status": "retired"
82
+ },
83
+ {
84
+ "id": "claude-fable-5",
85
+ "displayName": "claude-fable-5",
86
+ "createdAt": null,
87
+ "status": "active"
88
+ },
89
+ {
90
+ "id": "claude-haiku-4-5-20251001",
91
+ "displayName": "claude-haiku-4-5-20251001",
92
+ "createdAt": null,
93
+ "status": "active"
94
+ },
95
+ {
96
+ "id": "claude-instant-1.0",
97
+ "displayName": "claude-instant-1.0",
98
+ "createdAt": null,
99
+ "status": "retired"
100
+ },
101
+ {
102
+ "id": "claude-instant-1.1",
103
+ "displayName": "claude-instant-1.1",
104
+ "createdAt": null,
105
+ "status": "retired"
106
+ },
107
+ {
108
+ "id": "claude-instant-1.2",
109
+ "displayName": "claude-instant-1.2",
110
+ "createdAt": null,
111
+ "status": "retired"
112
+ },
113
+ {
114
+ "id": "claude-opus-4-1-20250805",
115
+ "displayName": "claude-opus-4-1-20250805",
116
+ "createdAt": null,
117
+ "status": "deprecated"
118
+ },
119
+ {
120
+ "id": "claude-opus-4-20250514",
121
+ "displayName": "claude-opus-4-20250514",
122
+ "createdAt": null,
123
+ "status": "retired"
124
+ },
125
+ {
126
+ "id": "claude-opus-4-5-20251101",
127
+ "displayName": "claude-opus-4-5-20251101",
128
+ "createdAt": null,
129
+ "status": "active"
130
+ },
131
+ {
132
+ "id": "claude-opus-4-6",
133
+ "displayName": "claude-opus-4-6",
134
+ "createdAt": null,
135
+ "status": "active"
136
+ },
137
+ {
138
+ "id": "claude-opus-4-7",
139
+ "displayName": "claude-opus-4-7",
140
+ "createdAt": null,
141
+ "status": "active"
142
+ },
143
+ {
144
+ "id": "claude-opus-4-8",
145
+ "displayName": "claude-opus-4-8",
146
+ "createdAt": null,
147
+ "status": "active"
148
+ },
149
+ {
150
+ "id": "claude-opus-5",
151
+ "displayName": "claude-opus-5",
152
+ "createdAt": null,
153
+ "status": "active"
154
+ },
155
+ {
156
+ "id": "claude-sonnet-4-20250514",
157
+ "displayName": "claude-sonnet-4-20250514",
158
+ "createdAt": null,
159
+ "status": "retired"
160
+ },
161
+ {
162
+ "id": "claude-sonnet-4-5-20250929",
163
+ "displayName": "claude-sonnet-4-5-20250929",
164
+ "createdAt": null,
165
+ "status": "active"
166
+ },
167
+ {
168
+ "id": "claude-sonnet-4-6",
169
+ "displayName": "claude-sonnet-4-6",
170
+ "createdAt": null,
171
+ "status": "active"
172
+ },
173
+ {
174
+ "id": "claude-sonnet-5",
175
+ "displayName": "claude-sonnet-5",
176
+ "createdAt": null,
177
+ "status": "active"
178
+ }
179
+ ]
180
+ }
@@ -0,0 +1,202 @@
1
+ /**
2
+ * model-catalog.js — loads the release-time-generated Claude model catalog
3
+ * and merges it into a live vendor model list. (lr-f22787)
4
+ *
5
+ * DESIGN (operator-approved, see PR body for lr-f22787):
6
+ *
7
+ * The Claude Agent SDK's live enumeration (stream.supportedModels()) only
8
+ * ever reports the current alias set (default/opus/sonnet/haiku/fable) — see
9
+ * lib/yoke/adapters/claude.js's enrichment comments and
10
+ * test/model-picker-no-free-text-lr-f22787.test.js for the full empirical
11
+ * trail. There is no runtime path to a list of older, still-runnable
12
+ * versioned IDs (e.g. claude-opus-4-5). GET https://api.anthropic.com/v1/models
13
+ * DOES enumerate them, but requires an API key — which this project's
14
+ * runtime is never allowed to hold (OAuth-only, workspace rule 17: no
15
+ * Anthropic SDK / API-key calls at runtime). So the catalog is generated
16
+ * ONCE per release, in CI, using a repo-secret API key that never leaves
17
+ * CI, and committed as lib/generated/claude-model-catalog.json — shipped
18
+ * inside the npm package like lib/themes/*.json.
19
+ *
20
+ * This module is the read + merge side only. It never makes a network call
21
+ * and never touches ANTHROPIC_API_KEY (that only exists in the GitHub
22
+ * Actions release workflow — see .github/workflows/release.yml).
23
+ *
24
+ * RETIRED MODELS (lr-d3817f, REVERSES the original lr-f22787 decision
25
+ * below): the generator is still ADDITIVE — each release's catalog is a
26
+ * union of the freshly-fetched /v1/models response with whatever was
27
+ * already committed, never a drop of an entry the vendor stopped listing.
28
+ * The committed file is allowed to accumulate retired history so past
29
+ * releases stay diffable/auditable. But the PICKER must never show a
30
+ * retired entry, in any state, on any surface. The original lr-f22787
31
+ * rationale ("shown-but-disabled beats silently vanishing") was never
32
+ * something the operator asked for — the corrected spec (lr-d3817f) is
33
+ * that a fully-retired model (one that provably cannot run) is simply
34
+ * filtered out before it ever reaches a render function. See
35
+ * filterSelectableCatalogModels below, which is the enforcement point.
36
+ *
37
+ * PICKER BEHAVIOR FOR RETIRED/DEPRECATED (lr-d3817f, corrected): the
38
+ * committed catalog carries a per-entry `status` field
39
+ * ("active"/"deprecated"/"retired"/"unknown" — populated by
40
+ * scripts/generate-model-catalog.js from the deprecations page's own
41
+ * three-state "Current state" column, the natural source of truth, rather
42
+ * than an invented heuristic).
43
+ * - status "retired": excluded entirely by filterSelectableCatalogModels
44
+ * — never merged into the live picker list, on any surface, in any
45
+ * state (collapsed or expanded).
46
+ * - status "deprecated": marked isDeprecated:true via applyRetiredMarking,
47
+ * still fully selectable — a deprecated model still runs (it just has a
48
+ * retirement date on the horizon), so filtering it would be
49
+ * overcautious; the marker itself is the appropriate signal. The
50
+ * operator's spec named retired, not deprecated, for exclusion.
51
+ * - status "active"/"unknown"/absent: no marking, no filtering. "unknown"
52
+ * (a status string the deprecations-page parser didn't recognize) fails
53
+ * open — the alternative (treat unknown as retired-and-filtered) would
54
+ * risk hiding a model that is actually fine, on the strength of a
55
+ * parser hiccup this codebase can't verify either way.
56
+ *
57
+ * MISSING SECRET / FETCH FAILURE (PR body point (b)): loadClaudeModelCatalog
58
+ * never throws and never returns an empty list on a read/parse failure — it
59
+ * falls back to whatever was last committed. The catalog can only ever go
60
+ * stale, never empty; the picker must never regress to "no options."
61
+ */
62
+
63
+ var fs = require("fs");
64
+ var path = require("path");
65
+
66
+ var CATALOG_PATH = path.join(__dirname, "generated", "claude-model-catalog.json");
67
+
68
+ /**
69
+ * Read the committed/generated catalog file. Never throws.
70
+ * @returns {{ ok: boolean, models: Array<{id,displayName,createdAt}>, generatedAt: string|null, source: string|null, reason?: string }}
71
+ */
72
+ function loadClaudeModelCatalog() {
73
+ var raw;
74
+ try {
75
+ raw = fs.readFileSync(CATALOG_PATH, "utf8");
76
+ } catch (e) {
77
+ // No catalog shipped at all (should not happen once the seed file is
78
+ // committed, but a corrupted install or a future path change must
79
+ // degrade to "no catalog entries to merge," never a thrown error that
80
+ // could break warmup/model listing entirely).
81
+ return { ok: false, models: [], generatedAt: null, source: null, reason: "missing" };
82
+ }
83
+
84
+ var parsed;
85
+ try {
86
+ parsed = JSON.parse(raw);
87
+ } catch (e) {
88
+ return { ok: false, models: [], generatedAt: null, source: null, reason: "invalid" };
89
+ }
90
+
91
+ if (!parsed || !Array.isArray(parsed.models)) {
92
+ return { ok: false, models: [], generatedAt: null, source: null, reason: "invalid" };
93
+ }
94
+
95
+ return {
96
+ ok: true,
97
+ models: parsed.models,
98
+ generatedAt: parsed.generatedAt || null,
99
+ source: parsed.source || null,
100
+ };
101
+ }
102
+
103
+ /**
104
+ * Merge the generated catalog into a live vendor model list.
105
+ *
106
+ * @param {Array<string|object>} liveModels - the vendor's live-reported list
107
+ * (e.g. from stream.supportedModels() — normally just the alias set).
108
+ * @param {Array<{id:string,displayName?:string,status?:string}>} catalogModels - entries
109
+ * from loadClaudeModelCatalog().models.
110
+ * @returns {Array<object>} liveModels followed by any catalog entries whose
111
+ * id is not already present in liveModels (by value/id), each tagged
112
+ * { value, displayName, fromCatalog: true, status } so callers/UI can
113
+ * mark them (PR body point (c): shown, never hidden — the "Older models"
114
+ * disclosure already covers the visual distinction via isLatest tiering
115
+ * upstream; applyRetiredMarking below adds the retired/deprecated marker
116
+ * on top of that using the carried-through status field).
117
+ */
118
+ function mergeModelCatalog(liveModels, catalogModels) {
119
+ var live = liveModels || [];
120
+ var catalog = catalogModels || [];
121
+
122
+ var seen = {};
123
+ for (var i = 0; i < live.length; i++) {
124
+ var entry = live[i];
125
+ var value = (entry && typeof entry === "object") ? (entry.value || "") : String(entry || "");
126
+ if (value) seen[value] = true;
127
+ }
128
+
129
+ var merged = live.slice();
130
+ for (var j = 0; j < catalog.length; j++) {
131
+ var c = catalog[j];
132
+ if (!c || !c.id || seen[c.id]) continue;
133
+ seen[c.id] = true;
134
+ merged.push({
135
+ value: c.id,
136
+ displayName: c.displayName || c.id,
137
+ fromCatalog: true,
138
+ status: c.status || "unknown",
139
+ });
140
+ }
141
+ return merged;
142
+ }
143
+
144
+ /**
145
+ * Apply the deprecated marking described in this module's header comment
146
+ * ("PICKER BEHAVIOR FOR RETIRED/DEPRECATED"). Pure and additive: only ever
147
+ * ADDS isDeprecated onto entries that already carry a `status` field from
148
+ * mergeModelCatalog — never removes an entry, never touches entries with no
149
+ * status field at all (e.g. a live vendor entry that went through
150
+ * mergeModelCatalog untouched, which has no `status` key — see
151
+ * mergeModelCatalog above, only catalog-sourced entries get one).
152
+ *
153
+ * lr-d3817f: this used to also mark status:"retired" entries isRetired/
154
+ * disabled instead of filtering them. That decision is reversed — a retired
155
+ * entry is now removed entirely by filterSelectableCatalogModels (below)
156
+ * BEFORE this function runs, so applyRetiredMarking never sees one in
157
+ * practice. It still no-ops safely on a stray "retired" status (e.g. a
158
+ * caller that skips the filter) rather than mismarking it as deprecated.
159
+ *
160
+ * @param {Array<object>} models - output of mergeModelCatalog (or any list
161
+ * of model objects, some of which may carry a `status` field).
162
+ * @returns {Array<object>} the SAME entries, each with isDeprecated added
163
+ * when status is "deprecated".
164
+ */
165
+ function applyRetiredMarking(models) {
166
+ var list = models || [];
167
+ return list.map(function (m) {
168
+ if (!m || typeof m !== "object" || !m.status) return m;
169
+ if (m.status === "deprecated") {
170
+ return Object.assign({}, m, { isDeprecated: true });
171
+ }
172
+ return m;
173
+ });
174
+ }
175
+
176
+ /**
177
+ * Remove status:"retired" catalog entries before they ever reach a picker
178
+ * surface (lr-d3817f). A retired model provably cannot run; the corrected
179
+ * spec is that it appears NOWHERE — not shown-and-disabled, not in the
180
+ * expanded "Older models" tier, not on any surface. This must run on the
181
+ * CATALOG list (before mergeModelCatalog), not on the merged live+catalog
182
+ * list, so a live vendor entry (which never carries a `status` field) is
183
+ * never accidentally filtered.
184
+ *
185
+ * @param {Array<{id:string,status?:string}>} catalogModels - entries from
186
+ * loadClaudeModelCatalog().models.
187
+ * @returns {Array<object>} the same entries, minus any with status:"retired".
188
+ */
189
+ function filterSelectableCatalogModels(catalogModels) {
190
+ var list = catalogModels || [];
191
+ return list.filter(function (m) {
192
+ return !(m && m.status === "retired");
193
+ });
194
+ }
195
+
196
+ module.exports = {
197
+ CATALOG_PATH: CATALOG_PATH,
198
+ loadClaudeModelCatalog: loadClaudeModelCatalog,
199
+ mergeModelCatalog: mergeModelCatalog,
200
+ applyRetiredMarking: applyRetiredMarking,
201
+ filterSelectableCatalogModels: filterSelectableCatalogModels,
202
+ };