moi-computer 0.5.1 → 0.5.2-next.1

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/client/app/shell/SidebarLayout.tsx +1 -1
  2. package/client/components/shared/Composer.tsx +12 -3
  3. package/client/components/ui/dropdown-menu.tsx +1 -4
  4. package/client/components/ui/popover.tsx +11 -4
  5. package/client/components/ui/slider.tsx +70 -0
  6. package/client/components/ui/tooltip.tsx +1 -1
  7. package/client/features/applets/applet-cache.ts +10 -1
  8. package/client/features/applets/useApplet.ts +1 -1
  9. package/client/features/chat/ChatComposer.tsx +9 -13
  10. package/client/features/chat/ChatPanel.tsx +8 -8
  11. package/client/features/chat/ModelPicker.tsx +295 -116
  12. package/client/features/chat/TurnView.tsx +1 -1
  13. package/client/features/chat/chat-send.ts +15 -5
  14. package/client/features/chat/chat-store.ts +9 -22
  15. package/client/features/chat/model-order.ts +50 -28
  16. package/client/features/chat/useChat.ts +20 -11
  17. package/client/features/settings/IconPicker.tsx +2 -2
  18. package/client/features/views/api.ts +1 -0
  19. package/client/features/views/useViewBuilderActions.ts +4 -2
  20. package/client/features/workspace/WorkspaceScreen.tsx +2 -1
  21. package/client/features/workspace/WorkspaceSkillUpdateBanner.tsx +2 -2
  22. package/client/index.css +5 -3
  23. package/client/store/ui.ts +11 -1
  24. package/dist/chunk-94m3q9ce.js +1 -0
  25. package/dist/{chunk-v797g6ap.js → chunk-bcrkdhwe.js} +1 -1
  26. package/dist/{chunk-7bzpmtxp.js → chunk-jvhvme3z.js} +1 -1
  27. package/dist/chunk-k9dcnd73.js +27 -0
  28. package/dist/{chunk-jg6ezptn.js → chunk-kfw1qwqe.js} +2 -2
  29. package/dist/chunk-pk11vfzs.js +9 -0
  30. package/dist/{chunk-5vaevt8z.js → chunk-r2bqaege.js} +1 -1
  31. package/dist/{chunk-h3evrtyp.js → chunk-tzz101ea.js} +1 -1
  32. package/dist/chunk-xwhya7kb.js +1 -0
  33. package/dist/chunk-y4g8j7mv.css +1 -0
  34. package/dist/{chunk-m9qja0nx.js → chunk-zs4mte79.js} +1 -1
  35. package/dist/index.html +1 -1
  36. package/lib/types.ts +14 -5
  37. package/package.json +1 -1
  38. package/server/api.ts +13 -4
  39. package/server/applets.ts +49 -7
  40. package/server/harness/claude-code/models.ts +25 -2
  41. package/server/harness/claude-code/session.ts +28 -5
  42. package/server/harness/codex/adapter.ts +27 -2
  43. package/server/harness/codex/client.ts +33 -4
  44. package/server/harness/codex/session.ts +13 -4
  45. package/server/harness/types.ts +3 -2
  46. package/server/thread-config.ts +11 -7
  47. package/server/web.ts +3 -0
  48. package/workspace/.claude/skills/moi-workspace/DESIGN.md +38 -42
  49. package/workspace/.claude/skills/moi-workspace/SKILL.md +1 -1
  50. package/dist/chunk-4tcmvefj.js +0 -1
  51. package/dist/chunk-gc2smzc9.js +0 -27
  52. package/dist/chunk-h0hk61pm.js +0 -9
  53. package/dist/chunk-k5sjx9s5.js +0 -1
  54. package/dist/chunk-s7za1qsv.css +0 -1
package/lib/types.ts CHANGED
@@ -231,6 +231,9 @@ export type ClientMessage =
231
231
  // Omitted means the SDK default. Unlike model, the SDK has no live setter,
232
232
  // so a change forces the live session to resume (see server/cc-session.ts).
233
233
  effort?: string
234
+ // Opt into the selected model's faster processing mode. Omitted inherits
235
+ // the provider configuration; false explicitly disables a stored default.
236
+ fastMode?: boolean
234
237
  // Opt into live token-by-token streaming for this turn. Omitted/false runs
235
238
  // the current whole-block behavior. Only honored for providers that report
236
239
  // `supportsStreaming` (Claude Code); ignored otherwise. Like effort, a
@@ -258,11 +261,12 @@ export type SessionInfo = {
258
261
  // Per-thread agent settings, persisted server-side in one global file in moi's
259
262
  // data dir (NOT in the workspace), exposed via GET/PUT
260
263
  // /api/workspaces/:id/sessions/:sessionId/config. A thread reopens with the same
261
- // model/effort it last ran with; a brand-new thread is seeded from the workspace
262
- // defaults (`WorkspaceLayout.selectedModel`/`selectedEffort`).
264
+ // model/effort/Fast mode it last ran with; a brand-new thread is seeded from the
265
+ // corresponding workspace defaults.
263
266
  export type ThreadConfig = {
264
267
  model?: string
265
268
  effort?: string
269
+ fastMode?: boolean
266
270
  }
267
271
 
268
272
  // App-wide settings, persisted server-side as `settings.json` in moi's data
@@ -508,12 +512,15 @@ export type WorkspaceLayout = {
508
512
  // the transcript records the *resolved* id (e.g. `claude-sonnet-4-6`), which
509
513
  // doesn't map back to these aliases — hence we persist the pick here.
510
514
  //
511
- // This (and `selectedEffort`) is the *workspace default*: the value the picker
512
- // edits when no thread is open, and the seed a brand-new thread copies. Once a
513
- // thread exists it carries its own per-thread override (see `ThreadConfig`).
515
+ // This (with `selectedEffort` and `selectedFastMode`) is the *workspace
516
+ // default*: the value the picker edits when no thread is open, and the seed a
517
+ // brand-new thread copies. Once a thread exists it carries its own per-thread
518
+ // override (see `ThreadConfig`).
514
519
  selectedModel?: string
515
520
  // Reasoning-effort default for new threads (a `supportedEffortLevels` value).
516
521
  selectedEffort?: string
522
+ // Fast-mode default for new threads. Undefined inherits the provider setting.
523
+ selectedFastMode?: boolean
517
524
  theme?: {
518
525
  font: import('./themes').FontTheme
519
526
  primary?: string
@@ -599,6 +606,8 @@ export type Model = {
599
606
  supportedEffortLevels?: string[]
600
607
  supportsAdaptiveThinking?: boolean
601
608
  supportsFastMode?: boolean
609
+ // Provider-resolved default when moi has no stored Fast-mode preference.
610
+ defaultFastMode?: boolean
602
611
  supportsAutoMode?: boolean
603
612
  }
604
613
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moi-computer",
3
- "version": "0.5.1",
3
+ "version": "0.5.2-next.1",
4
4
  "description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
5
5
  "license": "Elastic-2.0",
6
6
  "type": "module",
package/server/api.ts CHANGED
@@ -229,6 +229,7 @@ one.post('/view-builders/:builderId/submit', async c => {
229
229
  optimisticId?: string
230
230
  model?: string
231
231
  effort?: string
232
+ fastMode?: boolean
232
233
  stream?: boolean
233
234
  availableIcons?: unknown
234
235
  }>()
@@ -267,6 +268,7 @@ one.post('/view-builders/:builderId/submit', async c => {
267
268
  optimisticId: body.optimisticId,
268
269
  model: typeof body.model === 'string' ? body.model : undefined,
269
270
  effort: typeof body.effort === 'string' ? body.effort : undefined,
271
+ fastMode: typeof body.fastMode === 'boolean' ? body.fastMode : undefined,
270
272
  stream: body.stream === true ? true : undefined,
271
273
  agentId: ws.agentId
272
274
  })
@@ -444,10 +446,10 @@ one.get('/sessions/:sessionId/events', async c => {
444
446
  return c.json(await harnessFor(ws).sessionEvents(ws, c.req.param('sessionId')))
445
447
  })
446
448
 
447
- // Per-thread agent settings (model + reasoning effort). GET returns the stored
448
- // config ({} for threads that never overrode the workspace defaults); PUT patches
449
- // it (a field as `null` clears it, omitted leaves it). The change takes effect on
450
- // the thread's next message — see ClientMessage/effort handling in cc-session.
449
+ // Per-thread agent settings (model, reasoning effort, and Fast mode). GET
450
+ // returns the stored config ({} for threads that never overrode the workspace
451
+ // defaults); PUT patches it (a field as `null` clears it, omitted leaves it).
452
+ // The change takes effect on the thread's next message.
451
453
  one.get('/sessions/:sessionId/config', async c => {
452
454
  return c.json(await getThreadConfig(c.get('ws').path, c.req.param('sessionId')))
453
455
  })
@@ -467,6 +469,13 @@ one.put('/sessions/:sessionId/config', async c => {
467
469
  }
468
470
  patch[key] = value
469
471
  }
472
+ if ('fastMode' in record) {
473
+ const value = record.fastMode
474
+ if (value !== null && typeof value !== 'boolean') {
475
+ return c.text('fastMode must be a boolean or null', 400)
476
+ }
477
+ patch.fastMode = value
478
+ }
470
479
  return c.json(await saveThreadConfig(c.get('ws').path, c.req.param('sessionId'), patch))
471
480
  })
472
481
 
package/server/applets.ts CHANGED
@@ -7,8 +7,9 @@
7
7
  //
8
8
  // Each applet builds into its OWN directory `.build/<kind>/<name>/`, holding a
9
9
  // fixed `index.js` entry plus any code chunks and bundled assets (hashed
10
- // images/fonts). The client dynamic-imports `<name>/index.js`; assets and
11
- // chunks resolve module-relative from there. `.js` files carry the
10
+ // images/fonts). The client dynamic-imports that entry at `<name>/module` — an
11
+ // extensionless alias, see `ENTRY_ROUTE_FILE` — and assets and chunks resolve
12
+ // module-relative from there. `.js` files carry the
12
13
  // `%%MOI_APPLET_API_BASE%%` sentinel (for RPC + `fileUrl`), swapped to the real
13
14
  // `/api/workspaces/<id>` base when served — so the on-disk bundle is
14
15
  // workspace-agnostic.
@@ -271,12 +272,21 @@ const HASHED_FILE_RE = /^chunk-[0-9a-z]+\.\w+$|-[0-9a-f]{6,}\.\w+$/i
271
272
  // prefix — substituted for the build-time sentinel in every `.js` so RPC and
272
273
  // `fileUrl` calls hit the right workspace. Assets stream untouched.
273
274
  //
275
+ // `file` is the ON-DISK name (the route's extensionless entry alias is already
276
+ // mapped back to `index.js` by `parseAppletTail`), so the content-type and
277
+ // sentinel-swap decisions below key off the real `.js` — do not switch them to
278
+ // the requested url, or the entry would ship as `application/octet-stream` and
279
+ // fail the browser's module MIME check.
280
+ //
274
281
  // Caching turns on the hashed-vs-stable split. A content-hashed chunk/asset gets
275
282
  // a new url whenever its bytes change, so it's cached forever. The `index.js`
276
283
  // entry (and anything not recognizably hashed) lives at ONE url across rebuilds,
277
284
  // so a shared cache (e.g. Cloudflare) that stored it once would hand back a
278
285
  // STALE copy after the next `moi bundle` — it gets an ETag (size+mtime) +
279
- // `no-cache` instead, so an unchanged file costs a 304 and a rebuilt one busts.
286
+ // `private, no-cache` instead, so an unchanged file costs a 304 and a rebuilt
287
+ // one busts. `private` keeps it out of any shared cache that would store it
288
+ // anyway, and is the one directive Cloudflare preserves when its Browser Cache
289
+ // TTL rewrites the header (see `ENTRY_ROUTE_FILE` for the rest of that story).
280
290
  export async function serveApplet(
281
291
  kind: AppletKind,
282
292
  name: string,
@@ -306,7 +316,7 @@ export async function serveApplet(
306
316
  cache = { 'Cache-Control': IMMUTABLE_CACHE }
307
317
  } else {
308
318
  const etag = `"${bunFile.size}-${Math.trunc(bunFile.lastModified)}"`
309
- cache = { ETag: etag, 'Cache-Control': 'no-cache' }
319
+ cache = { ETag: etag, 'Cache-Control': 'private, no-cache' }
310
320
  if (ifNoneMatch === etag) return new Response(null, { status: 304, headers: cache })
311
321
  }
312
322
 
@@ -329,8 +339,36 @@ export function apiBaseFor(id: string): string {
329
339
  return `/api/workspaces/${id}`
330
340
  }
331
341
 
342
+ // The entry's real name in the bundle dir (`.build/<kind>/<name>/index.js`).
343
+ const ENTRY_DISK_FILE = 'index.js'
344
+
345
+ // …and the url the client asks for it at: `…/<segment>/<name>/module`. The route
346
+ // name and the disk name differ ON PURPOSE, and the reason is proxies.
347
+ //
348
+ // Cloudflare — which sits between many users and their moi, usually as a tunnel
349
+ // — decides whether a response is cache-eligible from the url's FILE EXTENSION,
350
+ // not from its content type, and `JS` is on its default cached-extension list.
351
+ // Once a response is cache-eligible, the zone's Browser Cache TTL applies, and
352
+ // that setting overrides the origin's `Cache-Control` on the way to the browser
353
+ // whenever the origin's freshness is lower than the TTL. Its default is 4 hours
354
+ // on every plan, so our `no-cache` came back to the browser as `max-age=14400`.
355
+ // The entry lives at ONE url across rebuilds, so that rewrite pinned a stale
356
+ // bundle in the user's browser for hours: no revalidation, so the ETag never got
357
+ // a chance to bust it, and `?v` couldn't either (it's an in-memory counter that
358
+ // resets to 0 on reload, landing right back on the poisoned url).
359
+ //
360
+ // An extensionless path isn't cache-eligible by default, so it reaches the
361
+ // browser with the headers we actually sent. Chunks and assets keep their
362
+ // extensions deliberately — they're content-hashed and WANT the edge cache.
363
+ // The build only ever emits `index.js`, `chunk-<hash>.js` and hashed assets, so
364
+ // this name can never collide with a real bundle file. Mirrors `appletUrl` in
365
+ // `client/features/applets/applet-cache.ts`.
366
+ const ENTRY_ROUTE_FILE = 'module'
367
+
332
368
  // Split an applet file request `…/<segment>/<name>/<file>` into name + file. A
333
- // bare `…/<segment>/<name>` (or legacy `…/<name>.js`) targets the entry.
369
+ // bare `…/<segment>/<name>` (or legacy `…/<name>.js`) targets the entry, as does
370
+ // the extensionless `…/<name>/module` alias. `file` is always the on-disk name,
371
+ // so `serveApplet` never has to know the route spelling.
334
372
  export function parseAppletTail(
335
373
  url: string,
336
374
  id: string,
@@ -338,8 +376,12 @@ export function parseAppletTail(
338
376
  ): { name: string; file: string } {
339
377
  const tail = new URL(url).pathname.split(`/api/workspaces/${id}/${segment}/`)[1] ?? ''
340
378
  const slash = tail.indexOf('/')
341
- if (slash === -1) return { name: tail.replace(/\.js$/, ''), file: 'index.js' }
342
- return { name: tail.slice(0, slash), file: tail.slice(slash + 1) }
379
+ if (slash === -1) return { name: tail.replace(/\.js$/, ''), file: ENTRY_DISK_FILE }
380
+ const file = tail.slice(slash + 1)
381
+ return {
382
+ name: tail.slice(0, slash),
383
+ file: file === ENTRY_ROUTE_FILE ? ENTRY_DISK_FILE : file
384
+ }
343
385
  }
344
386
 
345
387
  // Extensions `fileUrl()` may stream from the workspace. Media + image/doc
@@ -1,6 +1,8 @@
1
- import { query } from '@anthropic-ai/claude-agent-sdk'
1
+ import { query, resolveSettings } from '@anthropic-ai/claude-agent-sdk'
2
2
  import type { ModelInfo } from '@anthropic-ai/claude-agent-sdk'
3
3
 
4
+ import type { Model } from '@/lib/types'
5
+
4
6
  import { requireHarnessExecutable } from '../executable'
5
7
 
6
8
  // Chat runs live in `cc-session.ts` (streaming-input sessions held per thread).
@@ -31,7 +33,7 @@ async function fetchClaudeModels(cwd: string): Promise<ModelInfo[]> {
31
33
  // it so a later request can retry instead of caching the rejection forever.
32
34
  let claudeModelsPromise: Promise<ModelInfo[]> | null = null
33
35
 
34
- export function getClaudeModels(cwd: string): Promise<ModelInfo[]> {
36
+ function getCachedClaudeModels(cwd: string): Promise<ModelInfo[]> {
35
37
  if (!claudeModelsPromise) {
36
38
  claudeModelsPromise = fetchClaudeModels(cwd).catch(err => {
37
39
  claudeModelsPromise = null
@@ -40,3 +42,24 @@ export function getClaudeModels(cwd: string): Promise<ModelInfo[]> {
40
42
  }
41
43
  return claudeModelsPromise
42
44
  }
45
+
46
+ export function withClaudeFastModeDefault(
47
+ models: readonly ModelInfo[],
48
+ defaultFastMode: boolean
49
+ ): Model[] {
50
+ return models.map(model =>
51
+ model.supportsFastMode ? { ...model, defaultFastMode } : { ...model }
52
+ )
53
+ }
54
+
55
+ export async function getClaudeModels(cwd: string): Promise<Model[]> {
56
+ const [models, settings] = await Promise.all([
57
+ getCachedClaudeModels(cwd),
58
+ resolveSettings({ cwd, settingSources: ['user', 'project'] })
59
+ ])
60
+ const defaultFastMode =
61
+ settings.effective.fastModePerSessionOptIn === true
62
+ ? false
63
+ : settings.effective.fastMode === true
64
+ return withClaudeFastModeDefault(models, defaultFastMode)
65
+ }
@@ -140,6 +140,9 @@ type LiveSession = {
140
140
  // idle TTL — tearing down the subprocess would kill its background children.
141
141
  bgTasks: Set<string>
142
142
  model: string | undefined
143
+ // Fast mode is a live flag setting. Undefined clears moi's override and
144
+ // inherits the provider configuration.
145
+ fastMode: boolean | undefined
143
146
  // Reasoning effort the query was created with. The SDK has no live setter for
144
147
  // it (unlike setModel), so a change tears the session down and resumes.
145
148
  effort: string | undefined
@@ -208,6 +211,7 @@ export type CCDebugSession = {
208
211
  workspaceId: string
209
212
  sessionId: string
210
213
  model: string | undefined
214
+ fastMode: boolean | undefined
211
215
  effort: string | undefined
212
216
  desiredEffort: string | undefined
213
217
  stream: boolean
@@ -229,6 +233,7 @@ export function getCCDebugSnapshot(): { sessions: CCDebugSession[]; aliases: num
229
233
  workspaceId: s.workspaceId,
230
234
  sessionId: s.sessionId,
231
235
  model: s.model,
236
+ fastMode: s.fastMode,
232
237
  effort: s.effort,
233
238
  desiredEffort: s.desiredEffort,
234
239
  stream: s.stream,
@@ -383,12 +388,16 @@ async function consume(s: LiveSession) {
383
388
  }
384
389
  // Seed the thread's config from what it actually ran with — but only if
385
390
  // it has none yet, so an explicit user PUT (or a migrated temp-id edit)
386
- // always wins. A default run (no model/effort) leaves no file and falls
387
- // back to the workspace defaults.
388
- if ((s.model || s.effort) && !(await hasThreadConfig(s.workspacePath, s.sessionId))) {
391
+ // always wins. A default run leaves no file and falls back to the
392
+ // workspace defaults.
393
+ if (
394
+ (s.model || s.effort || s.fastMode !== undefined) &&
395
+ !(await hasThreadConfig(s.workspacePath, s.sessionId))
396
+ ) {
389
397
  await saveThreadConfig(s.workspacePath, s.sessionId, {
390
398
  model: s.model,
391
- effort: s.effort
399
+ effort: s.effort,
400
+ fastMode: s.fastMode
392
401
  })
393
402
  }
394
403
  }
@@ -514,6 +523,7 @@ function createLiveSession(input: {
514
523
  isNew: boolean
515
524
  model: string | undefined
516
525
  effort: string | undefined
526
+ fastMode: boolean | undefined
517
527
  // Live token streaming (`includePartialMessages`). Only enabled when the
518
528
  // client opts in; off leaves the query byte-for-byte as before.
519
529
  stream: boolean
@@ -544,6 +554,7 @@ function createLiveSession(input: {
544
554
  // is valid for the model; the SDK silently downgrades otherwise. Cast because
545
555
  // the SDK under-types the union (no 'xhigh') vs our pass-through string.
546
556
  ...(input.effort ? { effort: input.effort as Options['effort'] } : {}),
557
+ ...(input.fastMode !== undefined ? { settings: { fastMode: input.fastMode } } : {}),
547
558
  // Emit `stream_event` partial-message frames so the adapter can surface a
548
559
  // live token-by-token preview. Off = unchanged behavior (whole blocks only).
549
560
  includePartialMessages: input.stream,
@@ -568,6 +579,7 @@ function createLiveSession(input: {
568
579
  sawStateEvents: false,
569
580
  bgTasks: new Set(),
570
581
  model: input.model,
582
+ fastMode: input.fastMode,
571
583
  effort: input.effort,
572
584
  desiredEffort: input.effort,
573
585
  stream: input.stream,
@@ -581,7 +593,7 @@ function createLiveSession(input: {
581
593
  }
582
594
  sessions.set(recKey(session.workspaceId, session.sessionId), session)
583
595
  debug(
584
- `cc create ${input.isNew ? 'new' : 'resume'} ws=${input.workspaceId} session=${input.sessionId} model=${input.model ?? 'default'} effort=${input.effort ?? 'default'} live=${sessions.size}`
596
+ `cc create ${input.isNew ? 'new' : 'resume'} ws=${input.workspaceId} session=${input.sessionId} model=${input.model ?? 'default'} effort=${input.effort ?? 'default'} fast=${input.fastMode ?? 'default'} live=${sessions.size}`
585
597
  )
586
598
  void consume(session)
587
599
  return session
@@ -600,6 +612,7 @@ export async function sendCCMessage(input: {
600
612
  optimisticId?: string
601
613
  model?: string
602
614
  effort?: string
615
+ fastMode?: boolean
603
616
  stream?: boolean
604
617
  // Structured moi context (lib/moi-context.ts), rendered here and injected
605
618
  // as a leading system-reminder text block; the display parts never see it.
@@ -654,6 +667,15 @@ export async function sendCCMessage(input: {
654
667
  // silently lose the message and hang the spinner).
655
668
  if (s.closed) s = undefined
656
669
  }
670
+ if (s && input.fastMode !== s.fastMode) {
671
+ try {
672
+ await s.q.applyFlagSettings({ fastMode: input.fastMode ?? null })
673
+ s.fastMode = input.fastMode
674
+ } catch (err) {
675
+ console.error('[cc-session] applyFlagSettings failed', err)
676
+ }
677
+ if (s.closed) s = undefined
678
+ }
657
679
  if (s) {
658
680
  // Effort/streaming can't change on a running query; record the request so
659
681
  // the session rebuilds once its turns drain (see the `result` handler).
@@ -671,6 +693,7 @@ export async function sendCCMessage(input: {
671
693
  isNew: input.isNew,
672
694
  model: input.model,
673
695
  effort: input.effort,
696
+ fastMode: input.fastMode,
674
697
  stream: wantStream,
675
698
  // The agent only sees secrets scoped to the 'agent' sink (plus .env).
676
699
  workspaceEnv: await resolveWorkspaceEnv(input.workspacePath)
@@ -112,10 +112,23 @@ export type CodexModel = {
112
112
  supportedReasoningEfforts?: { reasoningEffort: string; description?: string }[]
113
113
  defaultReasoningEffort?: string
114
114
  isDefault?: boolean
115
+ serviceTiers?: { id: string; name: string; description: string }[]
116
+ defaultServiceTier?: string | null
117
+ // Older app-server versions advertised Fast mode through this field.
118
+ additionalSpeedTiers?: string[]
115
119
  }
116
120
 
117
121
  // ---- discovery mappings ------------------------------------------------------
118
122
 
123
+ const CODEX_FAST_SERVICE_TIER = 'priority'
124
+
125
+ export function codexServiceTierForFastMode(
126
+ fastMode: boolean | undefined
127
+ ): typeof CODEX_FAST_SERVICE_TIER | null | undefined {
128
+ if (fastMode === undefined) return undefined
129
+ return fastMode ? CODEX_FAST_SERVICE_TIER : null
130
+ }
131
+
119
132
  // `thread/list.preview` snippets come from the raw first user message — on
120
133
  // the pre-0.135 fallback path that text carries the appended context envelope,
121
134
  // so previews strip it like transcript turns do. Loose variant: previews are
@@ -164,9 +177,15 @@ export function selectCodexWorkspacePreview(
164
177
  }
165
178
  }
166
179
 
167
- export function codexModelToModel(m: CodexModel): Model {
180
+ export function codexModelToModel(m: CodexModel, configuredServiceTier?: string | null): Model {
168
181
  const efforts = (m.supportedReasoningEfforts ?? []).map(e => e.reasoningEffort)
169
182
  const displayName = m.displayName.replace(/^GPT-/, '').replaceAll('-', ' ')
183
+ const supportsFastMode =
184
+ (m.serviceTiers ?? []).some(tier => tier.id === CODEX_FAST_SERVICE_TIER) ||
185
+ (m.additionalSpeedTiers ?? []).includes('fast')
186
+ // The effective user/project config governs omitted wire values. A null
187
+ // config value leaves the model catalog's default in charge.
188
+ const defaultServiceTier = configuredServiceTier ?? m.defaultServiceTier
170
189
  return {
171
190
  value: m.id,
172
191
  resolvedModel: m.model,
@@ -178,7 +197,13 @@ export function codexModelToModel(m: CodexModel): Model {
178
197
  ? { description: `${displayName} · ${m.description}` }
179
198
  : { description: displayName }),
180
199
  supportsEffort: efforts.length > 0,
181
- ...(efforts.length > 0 ? { supportedEffortLevels: efforts } : {})
200
+ ...(efforts.length > 0 ? { supportedEffortLevels: efforts } : {}),
201
+ ...(supportsFastMode
202
+ ? {
203
+ supportsFastMode: true,
204
+ defaultFastMode: defaultServiceTier === CODEX_FAST_SERVICE_TIER
205
+ }
206
+ : {})
182
207
  }
183
208
  }
184
209
 
@@ -340,15 +340,16 @@ export async function getCodexWorkspacePreview(
340
340
  }
341
341
 
342
342
  // Account-wide model catalog (identical for every workspace); cached like the
343
- // Claude list in agent.ts, cleared on failure so a later call can retry.
344
- let codexModelsPromise: Promise<Model[]> | null = null
343
+ // Claude list in agent.ts, cleared on failure so a later call can retry. Keep
344
+ // the raw catalog cached because the effective service tier is cwd-scoped.
345
+ let codexModelsPromise: Promise<CodexModel[]> | null = null
345
346
 
346
- export function getCodexModels(workspacePath: string): Promise<Model[]> {
347
+ function getCachedCodexModels(workspacePath: string): Promise<CodexModel[]> {
347
348
  if (!codexModelsPromise) {
348
349
  codexModelsPromise = (async () => {
349
350
  const client = await getCodexClient(workspacePath)
350
351
  const res = await client.rpc<{ data?: CodexModel[] }>('model/list', {})
351
- return (res.data ?? []).filter(m => !m.hidden).map(codexModelToModel)
352
+ return res.data ?? []
352
353
  })().catch(err => {
353
354
  codexModelsPromise = null
354
355
  throw err
@@ -357,6 +358,34 @@ export function getCodexModels(workspacePath: string): Promise<Model[]> {
357
358
  return codexModelsPromise
358
359
  }
359
360
 
361
+ async function getCodexConfiguredServiceTier(
362
+ workspacePath: string
363
+ ): Promise<string | null | undefined> {
364
+ try {
365
+ const client = await getCodexClient(workspacePath)
366
+ const res = await client.rpc<{ config?: { service_tier?: string | null } }>('config/read', {
367
+ cwd: workspacePath,
368
+ includeLayers: false
369
+ })
370
+ return res.config?.service_tier
371
+ } catch (err) {
372
+ debug(
373
+ `codex config/read failed cwd=${workspacePath}: ${err instanceof Error ? err.message : String(err)}`
374
+ )
375
+ return undefined
376
+ }
377
+ }
378
+
379
+ export async function getCodexModels(workspacePath: string): Promise<Model[]> {
380
+ const [models, configuredServiceTier] = await Promise.all([
381
+ getCachedCodexModels(workspacePath),
382
+ getCodexConfiguredServiceTier(workspacePath)
383
+ ])
384
+ return models
385
+ .filter(model => !model.hidden)
386
+ .map(model => codexModelToModel(model, configuredServiceTier))
387
+ }
388
+
360
389
  // MCP servers as Codex sees them (from ~/.codex/config.toml), for the
361
390
  // connectors UI. `authStatus` "notLoggedIn" means an OAuth server awaiting
362
391
  // login; anything else that returned at all is reachable.
@@ -31,6 +31,7 @@ import {
31
31
  type CodexTokenUsage,
32
32
  type CodexTurn,
33
33
  type SubagentReplay,
34
+ codexServiceTierForFastMode,
34
35
  codexItemToNotice,
35
36
  codexItemToTurn,
36
37
  codexThreadToEvents
@@ -502,6 +503,7 @@ export async function sendCodexMessage(input: {
502
503
  optimisticId?: string
503
504
  model?: string
504
505
  effort?: string
506
+ fastMode?: boolean
505
507
  stream?: boolean
506
508
  // Structured moi context (lib/moi-context.ts), rendered here. Servers
507
509
  // >= 0.135 take it via `additionalContext` (never enters userMessage
@@ -515,6 +517,7 @@ export async function sendCodexMessage(input: {
515
517
  if (!input.content && uploads.length === 0) return
516
518
  const { input: userInput, parts } = await buildUserInput(input.content, uploads)
517
519
  if (userInput.length === 0) return
520
+ const serviceTier = codexServiceTierForFastMode(input.fastMode)
518
521
 
519
522
  let rec: SessionRecord
520
523
  try {
@@ -524,7 +527,8 @@ export async function sendCodexMessage(input: {
524
527
  cwd: input.workspacePath,
525
528
  sandbox: SANDBOX_MODE,
526
529
  approvalPolicy: APPROVAL_POLICY,
527
- ...(input.model ? { model: input.model } : {})
530
+ ...(input.model ? { model: input.model } : {}),
531
+ ...(serviceTier !== undefined ? { serviceTier } : {})
528
532
  })
529
533
  const realId = started.thread.id
530
534
  if (realId !== input.sessionId) {
@@ -542,10 +546,14 @@ export async function sendCodexMessage(input: {
542
546
  sessionId: realId,
543
547
  client
544
548
  })
545
- if ((input.model || input.effort) && !(await hasThreadConfig(input.workspacePath, realId))) {
549
+ if (
550
+ (input.model || input.effort || input.fastMode !== undefined) &&
551
+ !(await hasThreadConfig(input.workspacePath, realId))
552
+ ) {
546
553
  await saveThreadConfig(input.workspacePath, realId, {
547
554
  model: input.model,
548
- effort: input.effort
555
+ effort: input.effort,
556
+ fastMode: input.fastMode
549
557
  })
550
558
  }
551
559
  } else {
@@ -610,7 +618,8 @@ export async function sendCodexMessage(input: {
610
618
  // thinking — 'auto' tends to emit one short blob near the end.
611
619
  summary: 'detailed',
612
620
  ...(input.model ? { model: input.model } : {}),
613
- ...(input.effort ? { effort: input.effort } : {})
621
+ ...(input.effort ? { effort: input.effort } : {}),
622
+ ...(serviceTier !== undefined ? { serviceTier } : {})
614
623
  }
615
624
  if (rec.activeTurnId) {
616
625
  // A turn is running — steer the new input into it. If the turn ended
@@ -15,8 +15,8 @@ import type {
15
15
  } from '@/lib/types'
16
16
 
17
17
  // The superset of what any backend needs to accept a user message; harnesses
18
- // ignore fields they don't support (e.g. OpenClaw ignores model/effort/stream,
19
- // only OpenClaw reads agentId).
18
+ // ignore fields they don't support (e.g. OpenClaw ignores
19
+ // model/effort/Fast-mode/stream, only OpenClaw reads agentId).
20
20
  export type SendMessageInput = {
21
21
  workspaceId: string
22
22
  workspacePath: string
@@ -29,6 +29,7 @@ export type SendMessageInput = {
29
29
  optimisticId?: string
30
30
  model?: string
31
31
  effort?: string
32
+ fastMode?: boolean
32
33
  stream?: boolean
33
34
  // Structured moi context (lib/moi-context.ts). Each harness renders and
34
35
  // injects it its own way: Claude Code as a leading system-reminder text
@@ -5,10 +5,10 @@ import type { ThreadConfig } from '@/lib/types'
5
5
 
6
6
  import { DATA_DIR } from './data-dir'
7
7
 
8
- // Per-thread model/effort overrides for chat threads. Stored OUTSIDE the user's
9
- // workspace (no repo churn) in ONE global JSON file in moi's data dir, alongside
10
- // the workspace registry. Keyed by workspace path then sessionId:
11
- // { "<workspacePath>": { "<sessionId>": { model?, effort? } } }
8
+ // Per-thread model/effort/Fast-mode overrides for chat threads. Stored OUTSIDE
9
+ // the user's workspace (no repo churn) in ONE global JSON file in moi's data
10
+ // dir, alongside the workspace registry. Keyed by workspace path then sessionId:
11
+ // { "<workspacePath>": { "<sessionId>": { model?, effort?, fastMode? } } }
12
12
  // Path (not registry id) is the key so config survives re-registration and lines
13
13
  // up with the SDK's path-based session storage.
14
14
 
@@ -16,6 +16,7 @@ import { DATA_DIR } from './data-dir'
16
16
  export type ThreadConfigPatch = {
17
17
  model?: string | null
18
18
  effort?: string | null
19
+ fastMode?: boolean | null
19
20
  }
20
21
 
21
22
  type Store = Record<string, Record<string, ThreadConfig>>
@@ -31,11 +32,12 @@ function clean(cfg: ThreadConfig | undefined): ThreadConfig {
31
32
  const out: ThreadConfig = {}
32
33
  if (typeof cfg?.model === 'string') out.model = cfg.model
33
34
  if (typeof cfg?.effort === 'string') out.effort = cfg.effort
35
+ if (typeof cfg?.fastMode === 'boolean') out.fastMode = cfg.fastMode
34
36
  return out
35
37
  }
36
38
 
37
39
  function isEmpty(cfg: ThreadConfig): boolean {
38
- return cfg.model === undefined && cfg.effort === undefined
40
+ return cfg.model === undefined && cfg.effort === undefined && cfg.fastMode === undefined
39
41
  }
40
42
 
41
43
  async function readStore(): Promise<Store> {
@@ -76,8 +78,8 @@ export async function hasThreadConfig(workspacePath: string, sessionId: string):
76
78
  }
77
79
 
78
80
  // Merge a patch over the stored config and write it back. `null` clears a field,
79
- // `undefined` leaves it untouched, a string sets it. An emptied entry is dropped
80
- // to keep the file tidy. Returns the merged config.
81
+ // `undefined` leaves it untouched, and a typed value sets it. An emptied entry
82
+ // is dropped to keep the file tidy. Returns the merged config.
81
83
  export async function saveThreadConfig(
82
84
  workspacePath: string,
83
85
  sessionId: string,
@@ -93,6 +95,8 @@ export async function saveThreadConfig(
93
95
  if (value === null) delete next[key]
94
96
  else next[key] = value
95
97
  }
98
+ if (patch.fastMode === null) delete next.fastMode
99
+ else if (patch.fastMode !== undefined) next.fastMode = patch.fastMode
96
100
  if (isEmpty(next)) delete threads[sessionId]
97
101
  else threads[sessionId] = next
98
102
  if (Object.keys(threads).length === 0) delete store[workspacePath]
package/server/web.ts CHANGED
@@ -29,6 +29,7 @@ function isClientMessage(value: unknown): value is ClientMessage {
29
29
  optimisticId?: unknown
30
30
  model?: unknown
31
31
  effort?: unknown
32
+ fastMode?: unknown
32
33
  stream?: unknown
33
34
  context?: unknown
34
35
  attachments?: unknown
@@ -43,6 +44,7 @@ function isClientMessage(value: unknown): value is ClientMessage {
43
44
  (v.optimisticId === undefined || typeof v.optimisticId === 'string') &&
44
45
  (v.model === undefined || typeof v.model === 'string') &&
45
46
  (v.effort === undefined || typeof v.effort === 'string') &&
47
+ (v.fastMode === undefined || typeof v.fastMode === 'boolean') &&
46
48
  (v.stream === undefined || typeof v.stream === 'boolean') &&
47
49
  (v.context === undefined || isMoiContext(v.context)) &&
48
50
  (v.attachments === undefined ||
@@ -151,6 +153,7 @@ export const app = Bun.serve<WsData>({
151
153
  optimisticId: data.optimisticId,
152
154
  model: data.model,
153
155
  effort: data.effort,
156
+ fastMode: data.fastMode,
154
157
  stream: data.stream,
155
158
  context: data.context,
156
159
  agentId: workspace.agentId