@myrialabs/clopen 0.4.42 → 0.4.44

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.
@@ -23,6 +23,7 @@ import type {
23
23
  SuccessResultEvent,
24
24
  ErrorResultEvent,
25
25
  SystemInitEvent,
26
+ McpServerStatus,
26
27
  RateLimitEvent,
27
28
  RateLimitType,
28
29
  NotificationEvent,
@@ -928,14 +929,14 @@ class StreamManager extends EventEmitter {
928
929
  // Suppress the toast for "soft" statuses: `pending` (still
929
930
  // connecting) and `needs-auth` (server expects OAuth/credentials
930
931
  // configured in Settings → MCP). These are not errors — a scary
931
- // toast for them is confusing. (Status is the raw SDK string,
932
- // wider than the EngineOutput union, hence the cast.)
933
- const SOFT_STATUSES = new Set(['pending', 'needs-auth']);
932
+ // toast for them is confusing. `pending` is the common case since
933
+ // claude-agent-sdk 0.3.282 connects MCP servers in the background.
934
+ const SOFT_STATUSES = new Set<McpServerStatus['status']>(['pending', 'needs-auth']);
934
935
  const failedServers = initEvent.mcpServers.filter(
935
- s => s.status !== 'connected' && !SOFT_STATUSES.has(s.status as string)
936
+ s => s.status !== 'connected' && !SOFT_STATUSES.has(s.status)
936
937
  );
937
938
  initEvent.mcpServers
938
- .filter(s => SOFT_STATUSES.has(s.status as string))
939
+ .filter(s => SOFT_STATUSES.has(s.status))
939
940
  .forEach(s => debug.log('mcp', `MCP server "${s.name}" not ready (${s.status}) — suppressing toast`));
940
941
  failedServers.forEach(server => {
941
942
  debug.warn('mcp', `MCP server connection failed: ${server.name} (${server.status})`);
@@ -42,6 +42,7 @@ import type {
42
42
  DbEnvRole,
43
43
  DbEnvShape
44
44
  } from '$shared/types/db-client';
45
+ import { naturalCompare } from '$shared/utils/compare';
45
46
  import { debug } from '$shared/utils/logger';
46
47
 
47
48
  /** A value that is unmistakably a database connection string. */
@@ -396,7 +397,7 @@ export async function detectEnvUsage(input: {
396
397
 
397
398
  const keys = [...draft.keys.keys()].sort();
398
399
  const orderedFiles = [...draft.files].sort(
399
- (a, b) => envFilePrecedence(a) - envFilePrecedence(b) || a.localeCompare(b)
400
+ (a, b) => envFilePrecedence(a) - envFilePrecedence(b) || naturalCompare(a, b)
400
401
  );
401
402
  const isTemplateOnly = draft.liveFiles.length === 0;
402
403
  const where = orderedFiles[0] ?? [...draft.sources][0] ?? 'this project';
@@ -44,7 +44,7 @@ import type {
44
44
  TokenUsage,
45
45
  StopReason,
46
46
  } from '$shared/types/unified';
47
- import { toCanonicalToolName } from '$shared/types/unified';
47
+ import { toCanonicalToolName, toMcpServerStatus } from '$shared/types/unified';
48
48
 
49
49
  // ============================================================
50
50
  // Helper Mappers
@@ -390,9 +390,13 @@ export function convertSystemInit(msg: SDKSystemMessage): SystemInitEvent {
390
390
  model: msg.model || '',
391
391
  engine: 'claude-code',
392
392
  tools: msg.tools || [],
393
+ // `mcp_servers[].status` is a bare `string` on this payload, so it is
394
+ // narrowed, not cast: the cast this used to do named three states the CLI
395
+ // never emits and erased `pending`/`needs-auth`, the two that decide
396
+ // whether stream-manager raises a toast.
393
397
  mcpServers: (msg.mcp_servers || []).map(s => ({
394
398
  name: s.name || '',
395
- status: (s.status as 'connected' | 'disconnected' | 'error') || 'disconnected',
399
+ status: toMcpServerStatus(s.status),
396
400
  })),
397
401
  };
398
402
  }
@@ -32,8 +32,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
32
32
  type: 'claude-code',
33
33
  provider: 'anthropic',
34
34
  model: {
35
- id: 'claude-fable-5',
36
- name: 'Claude Fable 5',
35
+ id: 'claude-fable-5-1',
36
+ name: 'Claude Fable 5.1',
37
37
  },
38
38
  account: {
39
39
  id: 0,
@@ -75,8 +75,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
75
75
  type: 'claude-code',
76
76
  provider: 'anthropic',
77
77
  model: {
78
- id: 'claude-opus-5',
79
- name: 'Claude Opus 5',
78
+ id: 'claude-opus-5-5',
79
+ name: 'Claude Opus 5.5',
80
80
  },
81
81
  account: {
82
82
  id: 0,
@@ -109,8 +109,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
109
109
  structuredOutput: true,
110
110
  },
111
111
  cost: {
112
- input: 5,
113
- output: 25,
112
+ input: 4,
113
+ output: 20,
114
114
  },
115
115
  },
116
116
  {
@@ -118,8 +118,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
118
118
  type: 'claude-code',
119
119
  provider: 'anthropic',
120
120
  model: {
121
- id: 'claude-sonnet-5',
122
- name: 'Claude Sonnet 5',
121
+ id: 'claude-sonnet-5-5',
122
+ name: 'Claude Sonnet 5.5',
123
123
  },
124
124
  account: {
125
125
  id: 0,
@@ -152,8 +152,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
152
152
  structuredOutput: true,
153
153
  },
154
154
  cost: {
155
- input: 3,
156
- output: 15,
155
+ input: 2,
156
+ output: 10,
157
157
  },
158
158
  },
159
159
  {
@@ -199,6 +199,135 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
199
199
  output: 5,
200
200
  },
201
201
  },
202
+ {
203
+ engine: {
204
+ type: 'claude-code',
205
+ provider: 'anthropic',
206
+ model: {
207
+ id: 'claude-fable-5',
208
+ name: 'Claude Fable 5',
209
+ },
210
+ account: {
211
+ id: 0,
212
+ name: '',
213
+ },
214
+ },
215
+ limit: {
216
+ input: 1_000_000,
217
+ output: 128_000,
218
+ },
219
+ modalities: {
220
+ input: {
221
+ text: true,
222
+ image: true,
223
+ audio: false,
224
+ video: false,
225
+ pdf: true,
226
+ },
227
+ output: {
228
+ text: true,
229
+ image: false,
230
+ audio: false,
231
+ video: false,
232
+ pdf: false,
233
+ },
234
+ },
235
+ capabilities: {
236
+ reasoning: true,
237
+ tools: true,
238
+ structuredOutput: true,
239
+ },
240
+ cost: {
241
+ input: 10,
242
+ output: 50,
243
+ },
244
+ },
245
+ {
246
+ engine: {
247
+ type: 'claude-code',
248
+ provider: 'anthropic',
249
+ model: {
250
+ id: 'claude-opus-5',
251
+ name: 'Claude Opus 5',
252
+ },
253
+ account: {
254
+ id: 0,
255
+ name: '',
256
+ },
257
+ },
258
+ limit: {
259
+ input: 1_000_000,
260
+ output: 128_000,
261
+ },
262
+ modalities: {
263
+ input: {
264
+ text: true,
265
+ image: true,
266
+ audio: false,
267
+ video: false,
268
+ pdf: true,
269
+ },
270
+ output: {
271
+ text: true,
272
+ image: false,
273
+ audio: false,
274
+ video: false,
275
+ pdf: false,
276
+ },
277
+ },
278
+ capabilities: {
279
+ reasoning: true,
280
+ tools: true,
281
+ structuredOutput: true,
282
+ },
283
+ cost: {
284
+ input: 5,
285
+ output: 25,
286
+ },
287
+ },
288
+ {
289
+ engine: {
290
+ type: 'claude-code',
291
+ provider: 'anthropic',
292
+ model: {
293
+ id: 'claude-sonnet-5',
294
+ name: 'Claude Sonnet 5',
295
+ },
296
+ account: {
297
+ id: 0,
298
+ name: '',
299
+ },
300
+ },
301
+ limit: {
302
+ input: 1_000_000,
303
+ output: 128_000,
304
+ },
305
+ modalities: {
306
+ input: {
307
+ text: true,
308
+ image: true,
309
+ audio: false,
310
+ video: false,
311
+ pdf: true,
312
+ },
313
+ output: {
314
+ text: true,
315
+ image: false,
316
+ audio: false,
317
+ video: false,
318
+ pdf: false,
319
+ },
320
+ },
321
+ capabilities: {
322
+ reasoning: true,
323
+ tools: true,
324
+ structuredOutput: true,
325
+ },
326
+ cost: {
327
+ input: 3,
328
+ output: 15,
329
+ },
330
+ },
202
331
  {
203
332
  engine: {
204
333
  type: 'claude-code',
@@ -376,8 +505,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
376
505
  type: 'claude-code',
377
506
  provider: 'anthropic',
378
507
  model: {
379
- id: 'claude-sonnet-4-5',
380
- name: 'Claude Sonnet 4.5',
508
+ id: 'claude-opus-4-5',
509
+ name: 'Claude Opus 4.5',
381
510
  },
382
511
  account: {
383
512
  id: 0,
@@ -410,8 +539,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
410
539
  structuredOutput: true,
411
540
  },
412
541
  cost: {
413
- input: 3,
414
- output: 15,
542
+ input: 5,
543
+ output: 25,
415
544
  },
416
545
  },
417
546
  {
@@ -419,8 +548,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
419
548
  type: 'claude-code',
420
549
  provider: 'anthropic',
421
550
  model: {
422
- id: 'claude-opus-4-5',
423
- name: 'Claude Opus 4.5',
551
+ id: 'claude-sonnet-4-5',
552
+ name: 'Claude Sonnet 4.5',
424
553
  },
425
554
  account: {
426
555
  id: 0,
@@ -453,8 +582,8 @@ const CLAUDE_CODE_MODELS_BASE: EngineModel[] = [
453
582
  structuredOutput: true,
454
583
  },
455
584
  cost: {
456
- input: 5,
457
- output: 25,
585
+ input: 3,
586
+ output: 15,
458
587
  },
459
588
  },
460
589
  ];
@@ -4,13 +4,15 @@
4
4
  * Wraps the @anthropic-ai/claude-agent-sdk into the AIEngine interface.
5
5
  * SDK messages are converted to EngineOutput by ./message-converter.ts.
6
6
  *
7
- * Currently uses v1 query() API because v2 (unstable_v2_createSession) is
8
- * @alpha and lacks critical options required by Clopen:
9
- * - cwd (multi-project working directory)
10
- * - mcpServers, systemPrompt, settingSources
11
- * - forkSession, maxTurns, abortController, includePartialMessages
12
- * - outputFormat (needed by generateStructured)
13
- * When v2 SDKSessionOptions gains these, migrate streamQuery() to v2.
7
+ * query() is the only session entry point. The alternative this comment used to
8
+ * weigh — the @alpha v2 API (unstable_v2_createSession / unstable_v2_prompt) —
9
+ * was removed upstream in 0.3.142, before the version Clopen pins, so there is
10
+ * no migration pending. prewarm() (0.3.284, @alpha) parks a spare process to
11
+ * take start-up cost off the first message, but everything Clopen varies per
12
+ * stream is frozen at prewarm time — mcpServers (whose tool handlers are bound
13
+ * to the project), hooks, canUseTool, env (git identity) — so a spare is only
14
+ * reusable within one (project × profile × account × identity) and holds
15
+ * 230-260 MB while parked. Not adopted; see docs/lessons-learned.md §10.25.
14
16
  */
15
17
 
16
18
  import { loadEngineSdk } from '$backend/engine/sdk-loader';
@@ -9,10 +9,16 @@
9
9
  *
10
10
  * Presence in that table decides membership here: `gpt-5.3-codex`, `gpt-5.4`
11
11
  * and `gpt-5.4-mini` left it in the 0.147 bump and are dropped (the 5.4 pair
12
- * retires 2026-08-31). `gpt-5.3-codex-spark` is the deliberate exception — the
13
- * CLI also fetches account-entitled models from the server, so its absence from
14
- * the shipped table is not evidence of removal, and the docs still list it for
15
- * ChatGPT Pro.
12
+ * retires 2026-08-31). `gpt-5.2` and `gpt-5.3-codex-spark` are dropped too —
13
+ * both are gone from the shipped table and learn.chatgpt.com/docs/models no
14
+ * longer mentions either (the docs used to carve `-spark` out as a ChatGPT
15
+ * Pro-only exception, but that's no longer true).
16
+ *
17
+ * `gpt-daybreak-blue-latest`/`gpt-daybreak-red-latest` (specialized
18
+ * defensive/offensive cybersecurity-research variants) and
19
+ * `codex-auto-review` (an internal approval-review model) are in the shipped
20
+ * table but marked `visibility: "hide"` there, so they're deliberately left
21
+ * out of this picker too.
16
22
  *
17
23
  * Models tagged `requiresAuthMode` are filtered by the chat-input account
18
24
  * picker so the user can't pick a ChatGPT-only model while signed in with an
@@ -72,15 +78,13 @@ function codexModel(
72
78
 
73
79
  /** Ordered by the CLI's own `priority` field, so the picker matches Codex's. */
74
80
  export const CODEX_MODELS: EngineModel[] = [
81
+ codexModel('gpt-6-astra', 'GPT-6-Astra', codexReasoning(EFFORTS_TO_ULTRA, 'low')),
82
+ codexModel('gpt-6-sol', 'GPT-6-Sol', codexReasoning(EFFORTS_TO_ULTRA, 'medium')),
83
+ codexModel('gpt-6-luna', 'GPT-6-Luna', codexReasoning(EFFORTS_TO_MAX, 'medium')),
75
84
  codexModel('gpt-5.6-sol', 'GPT-5.6-Sol', codexReasoning(EFFORTS_TO_ULTRA, 'low')),
76
85
  codexModel('gpt-5.6-terra', 'GPT-5.6-Terra', codexReasoning(EFFORTS_TO_ULTRA, 'medium')),
77
86
  codexModel('gpt-5.6-luna', 'GPT-5.6-Luna', codexReasoning(EFFORTS_TO_MAX, 'medium')),
78
87
  codexModel('gpt-5.5', 'GPT-5.5', codexReasoning(EFFORTS_TO_XHIGH, 'medium')),
79
- codexModel('gpt-5.2', 'GPT-5.2', codexReasoning(EFFORTS_TO_XHIGH, 'medium')),
80
- codexModel('gpt-5.3-codex-spark', 'GPT-5.3 Codex Spark (ChatGPT Pro)', null, {
81
- image: false,
82
- requiresAuthMode: 'chatgpt',
83
- }),
84
88
  ];
85
89
 
86
90
  /**
@@ -50,7 +50,7 @@ import type {
50
50
  StopReason,
51
51
  AskUserQuestion,
52
52
  } from '$shared/types/unified';
53
- import { toCanonicalToolName } from '$shared/types/unified';
53
+ import { toCanonicalToolName, toMcpServerStatus } from '$shared/types/unified';
54
54
  import { resolveOpenCodeToolName } from '../../../mcp';
55
55
 
56
56
  // ============================================================
@@ -838,7 +838,7 @@ export function convertSystemInit(msg: SDKSystemMessage, state: QwenConverterSta
838
838
  tools: msg.tools || [],
839
839
  mcpServers: (msg.mcp_servers || []).map(s => ({
840
840
  name: s.name || '',
841
- status: (s.status as 'connected' | 'disconnected' | 'error') || 'disconnected',
841
+ status: toMcpServerStatus(s.status),
842
842
  })),
843
843
  };
844
844
  }
@@ -1509,6 +1509,61 @@ diffs. `/tmp`-installing the old and new versions side by side and diffing the
1509
1509
  `type: "…"` literals in each SDK's event declarations found every item above in
1510
1510
  minutes.
1511
1511
 
1512
+ **The September 2026 Claude pass (0.3.229 → 0.3.284) added one more trap, and
1513
+ it is the reverse of the stale-catalog item above.** Here the catalog was
1514
+ *right* and the binary was behind. `models.ts` listed `claude-opus-5-5`,
1515
+ `claude-sonnet-5-5` and `claude-fable-5-1`, but the CLI bundled with 0.3.229 is
1516
+ 2.1.229, whose embedded model table predates all three — so picking any of them
1517
+ failed inside the CLI with `Claude Code 2.1.229 does not support this model;
1518
+ version 2.1.280 or newer is required`. Nothing in Clopen could have caught it:
1519
+ the slugs are correct, the types compile, and the engine is installed and
1520
+ healthy. The rule that follows is bidirectional, because the SDK pin and the
1521
+ model catalog are one decision wearing two hats:
1522
+
1523
+ - Adding a model to `models.ts` is not done until the **pinned** SDK's bundled
1524
+ CLI knows the slug. `strings -a node_modules/@anthropic-ai/claude-agent-sdk-<platform>-<arch>/claude | grep -oE 'claude-(opus|sonnet|haiku|fable)-[0-9-]+' | sort -u`
1525
+ answers it in seconds, the same read `codex/models.ts` does for Codex.
1526
+ - Bumping the SDK is therefore a **model-availability change**, not only a type
1527
+ change, and belongs in the PR description as one. The Claude CLI ships as a
1528
+ platform package of the SDK (`engine-cli.ts` → `claudeCandidates`), so the two
1529
+ versions move together and cannot be bumped apart.
1530
+
1531
+ Two smaller findings from the same pass, both worth reusing:
1532
+
1533
+ - **An unchanged union is itself a result, but only if you diff for it.**
1534
+ `SDKMessage` was byte-identical across the 55 versions, which is what made the
1535
+ upgrade safe — not the clean compile. Diffing every type's *fields* (not just
1536
+ the member names) is what proved it: `Options` gained five optional entries,
1537
+ `Query` three methods, and the only removals anywhere were
1538
+ `Settings.policyHelpers` and two control requests, none referenced by Clopen.
1539
+ - **A cast at the SDK boundary erased the two states that decide a toast.** The
1540
+ `system:init` payload types `mcp_servers[].status` as a bare `string`, while
1541
+ the SDK *separately* exports a richer `McpServerStatus` for a different API
1542
+ surface — so the obvious `as 'connected' | 'disconnected' | 'error'` looked
1543
+ authoritative and was fiction. `pending` and `needs-auth` are not failures,
1544
+ and 0.3.282 made `pending` routine by connecting MCP servers in the
1545
+ background. Both the Claude and Qwen converters carried the same invented
1546
+ union; the vocabulary now lives once in `toMcpServerStatus`
1547
+ (`shared/types/unified/stream.ts`), for the same reason `resolveCodexEffort`
1548
+ does.
1549
+
1550
+ **`prewarm()` (0.3.284, `@alpha`) was evaluated and declined.** It parks a spare
1551
+ Claude Code process so process start, auth, tools, plugins and MCP handshakes
1552
+ come off the first message — but `claim()` can only set `cwd`,
1553
+ `additionalDirectories`, `model`, `permissionMode`, `maxThinkingTokens`, a
1554
+ settings overlay, `appendSystemPrompt`, `title`, `agents` and three named
1555
+ environment variables. Everything else is frozen at `prewarm()`, including the
1556
+ four things Clopen varies per stream: `mcpServers` (whose tool handlers are
1557
+ bound to a project via `mcpContext`), `hooks` (the PreToolUse permission hook is
1558
+ per project + profile), `canUseTool` (its closure captures the per-stream run),
1559
+ and `env` (git identity is not one of the three claimable variables). A spare is
1560
+ therefore only reusable inside one `(project × profile × account × identity)`
1561
+ and holds 230–260 MB while parked, which does not fit the low-spec/VPS target.
1562
+ If it is revisited: it needs a spare registry keyed on that tuple, a
1563
+ default-off setting, and a fallback that special-cases `option_not_applied` —
1564
+ that rejection means the session is **already running**, so the naive
1565
+ "fall back to `query()`" double-sends the prompt.
1566
+
1512
1567
  ---
1513
1568
 
1514
1569
  ### 10.26 One engine instance, many chats — per-stream state cannot live on it
@@ -1578,3 +1633,66 @@ What made this survive so long is that the contract doc *taught* it: invariant 2
1578
1633
  used to read "Streaming state lives on the instance … automatically isolated
1579
1634
  per-project". It was true about projects and silently wrong about chat sessions.
1580
1635
  When an invariant is scoped, write down what it does **not** cover.
1636
+
1637
+ ---
1638
+
1639
+ ### 10.27 A tool id is scoped to the SDK session that minted it
1640
+
1641
+ The Task Progress panel showed a plan that could never finish. Turn 1 created
1642
+ three tasks and completed them; turn 2 created two more and, as the user put it,
1643
+ "updated 1-2 instead of continuing from 4". The count settled at half done and
1644
+ stayed there.
1645
+
1646
+ `TodoWrite` sent a full snapshot per call, so reading it was "take the last
1647
+ one". The Task tools that replaced it (`TaskCreate` / `TaskUpdate`, SDK
1648
+ 0.3.142+) are deltas — one task per create, patched by `taskId` — so the panel
1649
+ replays them. The replay keyed tasks on a **single counter over the whole
1650
+ conversation**, on the assumption that the engine numbers tasks the same way.
1651
+ It does not. Clopen sends every turn with `forkSession: true`, so each turn runs
1652
+ under a fresh SDK session whose task store starts empty and **whose ids restart
1653
+ at 1**.
1654
+
1655
+ Reading it out of the database made the damage exact. In one real session turn 6
1656
+ created ten tasks (ids 1-10), turn 7 created seven more that the engine also
1657
+ numbered 1-7, and turn 9 three more numbered 1-3. The replay handed turn 7's
1658
+ creates the synthetic ids 11-17 while turn 7's updates still said 1-7 — so every
1659
+ later turn's status landed on **turn 6's rows**, and its own tasks never left
1660
+ `pending`. The panel read 10/20 = 50% forever, and the header named a turn-6
1661
+ task while the agent worked on a turn-9 one. Replaying that same session through
1662
+ the fix yields 3/3.
1663
+
1664
+ The engine had been saying so all along: across the whole database, every
1665
+ `TaskList` call answers `No tasks found`, each one issued in a turn *after*
1666
+ tasks were created. An empty store per fork is not an edge case, it is the
1667
+ normal shape.
1668
+
1669
+ So the id namespace is the SDK session, and the rules that follow are worth
1670
+ keeping for any future delta-keyed tool:
1671
+
1672
+ - **Key per session, not per conversation.** A create arriving under a new
1673
+ `message.sessionId` starts that session's list from scratch. The same
1674
+ reasoning as §10.23: an SDK session id is only meaningful to the engine that
1675
+ minted it, and so is anything numbered inside it.
1676
+ - **Only creates open a namespace; updates never do.** A turn that patches
1677
+ without creating is a continuation, and clearing on it would discard the list
1678
+ those patches refer to — the case if the engine ever persists its store
1679
+ across a fork.
1680
+ - **Prefer the id the engine reports over one you derive.** `TaskCreate`'s
1681
+ result reads `Task #4 created successfully: …`; parse it, and fall back to
1682
+ counting *within the namespace* only while the result is still in flight.
1683
+ The old counter was not wrong because counting is wrong, it was wrong because
1684
+ it counted across a boundary the ids do not cross.
1685
+ - **Do not invent a row for an id you never saw created.** The old `upsert`
1686
+ defaulted a missing subject to the id, so a stray patch entered the list as a
1687
+ task literally labelled `7` — reachable whenever the loaded message window
1688
+ opens partway through a turn. Skip it unless the patch names the task.
1689
+
1690
+ Two pieces of dead code hid the bug's surface. The replay read
1691
+ `item.result?.content` for `TaskList` snapshots, but that widget consumes the
1692
+ **raw** message list while `ToolUseBlock.result` is populated by the grouper
1693
+ that feeds the rendered list — across 2140 stored Task blocks, not one carries a
1694
+ `result`. And what it tried to parse (`{ tasks: [...] }`) is not a shape
1695
+ `TaskList` returns; its result is prose. A branch that cannot fire will not tell
1696
+ you its premise is wrong, so the replay lives in
1697
+ `frontend/utils/chat/task-progress.ts` now, behind unit tests that state each
1698
+ scenario, rather than inside a `$derived` where no test could reach it.
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  import fs from 'fs/promises';
11
+ import { naturalCompare } from '$shared/utils/compare';
11
12
  import { envFilePrecedence, isDotenvFileName, isTemplateEnvFile } from './keys';
12
13
 
13
14
  export interface DotenvFileEntry {
@@ -32,7 +33,7 @@ export async function listEnvFileEntries(projectRoot: string): Promise<DotenvFil
32
33
  (a, b) =>
33
34
  Number(a.isTemplate) - Number(b.isTemplate) ||
34
35
  envFilePrecedence(a.name) - envFilePrecedence(b.name) ||
35
- a.name.localeCompare(b.name)
36
+ naturalCompare(a.name, b.name)
36
37
  );
37
38
  }
38
39
 
@@ -2,6 +2,7 @@ import { join, extname } from 'path';
2
2
  import { readdir } from 'node:fs/promises';
3
3
  import { readFileWithEncoding, isTextFile } from '$shared/utils/file-type-detection';
4
4
 
5
+ import { naturalCompare } from '$shared/utils/compare';
5
6
  import { debug } from '$shared/utils/logger';
6
7
 
7
8
  // Return types
@@ -100,7 +101,7 @@ export async function buildFileTree(
100
101
  if (a.type !== b.type) {
101
102
  return a.type === 'directory' ? -1 : 1;
102
103
  }
103
- return a.name.localeCompare(b.name);
104
+ return naturalCompare(a.name, b.name);
104
105
  });
105
106
 
106
107
  return {
@@ -180,7 +181,7 @@ export async function listDirectoryContents(dirPath: string): Promise<FileTreeNo
180
181
  if (a.type !== b.type) {
181
182
  return a.type === 'directory' ? -1 : 1;
182
183
  }
183
- return a.name.localeCompare(b.name);
184
+ return naturalCompare(a.name, b.name);
184
185
  });
185
186
 
186
187
  return children;
@@ -288,7 +289,7 @@ export async function searchFiles(rootPath: string, query: string): Promise<File
288
289
  if (a.type !== b.type) {
289
290
  return a.type === 'directory' ? -1 : 1;
290
291
  }
291
- return a.name.localeCompare(b.name);
292
+ return naturalCompare(a.name, b.name);
292
293
  });
293
294
 
294
295
  // Limit results to prevent overwhelming the UI
@@ -2,6 +2,7 @@ import { join, extname } from 'path';
2
2
  import { readdir as fsReaddir } from 'node:fs/promises';
3
3
  import { existsSync } from 'fs';
4
4
 
5
+ import { naturalCompare } from '$shared/utils/compare';
5
6
  import { debug } from '$shared/utils/logger';
6
7
 
7
8
  // Cross-platform readdir using fs.promises
@@ -170,7 +171,7 @@ export async function handlePathBrowsing(path: string): Promise<PathBrowseData>
170
171
  if (a.type !== b.type) {
171
172
  return a.type === 'directory' ? -1 : 1;
172
173
  }
173
- return a.name.localeCompare(b.name);
174
+ return naturalCompare(a.name, b.name);
174
175
  });
175
176
 
176
177
  return {
@@ -35,6 +35,7 @@ import type {
35
35
  GitOperationState,
36
36
  GitReflogEntry
37
37
  } from '$shared/types/git';
38
+ import { naturalCompare } from '$shared/utils/compare';
38
39
  import { debug } from '$shared/utils/logger';
39
40
  import {
40
41
  assertSafeGitCommitMessage,
@@ -487,7 +488,7 @@ export class GitService {
487
488
  })
488
489
  );
489
490
  // Stable order for the UI (sorted by relPath).
490
- nestedResults.sort((a, b) => a.relPath.localeCompare(b.relPath));
491
+ nestedResults.sort((a, b) => naturalCompare(a.relPath, b.relPath));
491
492
  branchInfo.nested = nestedResults;
492
493
  }
493
494
  } catch (err) {
@@ -17,6 +17,7 @@
17
17
  */
18
18
 
19
19
  import type { SessionScopedChanges } from '$shared/types/database/schema';
20
+ import { naturalCompare } from '$shared/utils/compare';
20
21
  import { countLineChanges, isBinaryBuffer } from '$shared/utils/diff-calculator';
21
22
 
22
23
  export { isBinaryBuffer };
@@ -96,9 +97,9 @@ export async function buildTurnFiles(
96
97
  files.push({ path, status, insertions, deletions, isBinary, contentAvailable });
97
98
  }
98
99
 
99
- // Alphabetical: a turn's file list is read as a checklist, and a stable order
100
+ // Natural sort: a turn's file list is read as a checklist, and a stable order
100
101
  // is what lets the eye return to the same row after a refetch.
101
- files.sort((a, b) => a.path.localeCompare(b.path));
102
+ files.sort((a, b) => naturalCompare(a.path, b.path));
102
103
  return files;
103
104
  }
104
105
 
@@ -28,6 +28,7 @@ import type {
28
28
  SftpFileContent,
29
29
  SftpListing
30
30
  } from '$shared/types/ssh';
31
+ import { naturalCompare } from '$shared/utils/compare';
31
32
  import { debug } from '$shared/utils/logger';
32
33
 
33
34
  /** Largest file the inline text editor will open. Bigger files must be downloaded. */
@@ -480,7 +481,7 @@ export const sftpService = {
480
481
  const leftIsDir = left.type === 'directory' || left.targetType === 'directory';
481
482
  const rightIsDir = right.type === 'directory' || right.targetType === 'directory';
482
483
  if (leftIsDir !== rightIsDir) return leftIsDir ? -1 : 1;
483
- return left.name.localeCompare(right.name, undefined, { sensitivity: 'base' });
484
+ return naturalCompare(left.name, right.name);
484
485
  });
485
486
  return { path: resolved, entries };
486
487
  });
@@ -16,6 +16,7 @@ import path from 'path';
16
16
  import type { TreeMap } from '../snapshot/blob-store';
17
17
  import { execGit } from '../git/git-executor';
18
18
  import { resolveBinary } from '../utils/cli';
19
+ import { naturalCompare } from '$shared/utils/compare';
19
20
  import { debug } from '$shared/utils/logger';
20
21
  import { readBlobText } from './tree';
21
22
 
@@ -57,7 +58,7 @@ export function planMerge(base: TreeMap, source: TreeMap, target: TreeMap): Merg
57
58
 
58
59
  const entries: MergeEntry[] = [];
59
60
 
60
- for (const filePath of [...paths].sort()) {
61
+ for (const filePath of [...paths].sort(naturalCompare)) {
61
62
  const baseHash = base[filePath] ?? null;
62
63
  const sourceHash = source[filePath] ?? null;
63
64
  const targetHash = target[filePath] ?? null;
@@ -1 +1 @@
1
- import{s as _,_ as d,r as s,a as u}from"./main-CUyZAmqt.js";import{C as T,P as y,W as E,d as L,b as g,c as v,h as P,l as b,m as k,e as D,n as O,f as R,g as S,t as V}from"./main-CUyZAmqt.js";async function h(o,e={}){const i=e.loading===!1?void 0:_(o,e.loadingText??"Loading…"),[{Terminal:l},{FitAddon:c}]=await Promise.all([d(()=>import("./xterm-B-qIQCd3.js"),[]),d(()=>import("./addon-fit-DX4qG4td.js"),[])]).catch(r=>{throw i?.(),r}),a=new l({scrollback:e.scrollback??5e3,fontSize:e.fontSize??13,fontFamily:e.fontFamily??"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:e.lineHeight??1,cursorBlink:e.cursorBlink??!1,cursorStyle:e.cursorStyle??"block",disableStdin:e.stdin!==!0,allowProposedApi:!0,convertEol:!0,theme:s(e.theme),...e.cols?{cols:e.cols}:{},...e.rows?{rows:e.rows}:{},...e.terminalOptions??{}}),t=e.fit===!1?void 0:new c;if(t&&a.loadAddon(t),e.clipboard)try{const{ClipboardAddon:r}=await d(()=>import("./addon-clipboard-wHJhZAA4.js"),[]);a.loadAddon(new r)}catch{}if(e.webLinks)try{const{WebLinksAddon:r}=await d(()=>import("./addon-web-links-DIbG5aQx.js"),[]);a.loadAddon(new r)}catch{}if(e.unicode11)try{const{Unicode11Addon:r}=await d(()=>import("./addon-unicode11-Bt8F3D7-.js"),[]);a.loadAddon(new r),a.unicode.activeVersion="11"}catch{}for(const r of e.addons??[])a.loadAddon(r);if(a.open(o),e.ligatures)try{const{LigaturesAddon:r}=await d(()=>import("./addon-ligatures-DpDY8N_X.js"),[]);a.loadAddon(new r)}catch{}const m=t?u({resize:async()=>{}},a,t,{debounceMs:e.fitDebounceMs??100}):void 0;e.onReady?.(a),i?.();let n=!1;return{terminal:a,fitAddon:t,write:r=>a.write(r),clear:()=>{a.clear(),a.reset()},fit:()=>t?.fit(),setTheme:r=>{a.options.theme=s(r)},dispose(){n||(n=!0,m?.(),a.dispose())}}}export{T as ClientSession,y as PtyKitClient,E as WsCore,u as attachFit,L as darkTheme,g as defaultPersistence,v as draculaTheme,P as hostSocket,b as lightTheme,k as matrixTheme,D as mountTerminal,h as mountViewer,O as nordTheme,s as resolveTheme,_ as showLoadingOverlay,R as solarizedDarkTheme,S as solarizedLightTheme,V as themes};
1
+ import{s as _,_ as d,r as s,a as u}from"./main-DOkwqXRU.js";import{C as T,P as y,W as E,d as L,b as g,c as v,h as P,l as b,m as k,e as D,n as O,f as R,g as S,t as V}from"./main-DOkwqXRU.js";async function h(o,e={}){const i=e.loading===!1?void 0:_(o,e.loadingText??"Loading…"),[{Terminal:l},{FitAddon:c}]=await Promise.all([d(()=>import("./xterm-B-qIQCd3.js"),[]),d(()=>import("./addon-fit-DX4qG4td.js"),[])]).catch(r=>{throw i?.(),r}),a=new l({scrollback:e.scrollback??5e3,fontSize:e.fontSize??13,fontFamily:e.fontFamily??"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:e.lineHeight??1,cursorBlink:e.cursorBlink??!1,cursorStyle:e.cursorStyle??"block",disableStdin:e.stdin!==!0,allowProposedApi:!0,convertEol:!0,theme:s(e.theme),...e.cols?{cols:e.cols}:{},...e.rows?{rows:e.rows}:{},...e.terminalOptions??{}}),t=e.fit===!1?void 0:new c;if(t&&a.loadAddon(t),e.clipboard)try{const{ClipboardAddon:r}=await d(()=>import("./addon-clipboard-wHJhZAA4.js"),[]);a.loadAddon(new r)}catch{}if(e.webLinks)try{const{WebLinksAddon:r}=await d(()=>import("./addon-web-links-DIbG5aQx.js"),[]);a.loadAddon(new r)}catch{}if(e.unicode11)try{const{Unicode11Addon:r}=await d(()=>import("./addon-unicode11-Bt8F3D7-.js"),[]);a.loadAddon(new r),a.unicode.activeVersion="11"}catch{}for(const r of e.addons??[])a.loadAddon(r);if(a.open(o),e.ligatures)try{const{LigaturesAddon:r}=await d(()=>import("./addon-ligatures-DpDY8N_X.js"),[]);a.loadAddon(new r)}catch{}const m=t?u({resize:async()=>{}},a,t,{debounceMs:e.fitDebounceMs??100}):void 0;e.onReady?.(a),i?.();let n=!1;return{terminal:a,fitAddon:t,write:r=>a.write(r),clear:()=>{a.clear(),a.reset()},fit:()=>t?.fit(),setTheme:r=>{a.options.theme=s(r)},dispose(){n||(n=!0,m?.(),a.dispose())}}}export{T as ClientSession,y as PtyKitClient,E as WsCore,u as attachFit,L as darkTheme,g as defaultPersistence,v as draculaTheme,P as hostSocket,b as lightTheme,k as matrixTheme,D as mountTerminal,h as mountViewer,O as nordTheme,s as resolveTheme,_ as showLoadingOverlay,R as solarizedDarkTheme,S as solarizedLightTheme,V as themes};