moi-computer 0.11.1-next.0 → 0.11.1-next.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 (211) hide show
  1. package/client/AGENTS.md +2 -2
  2. package/client/components/ui/button.tsx +1 -53
  3. package/client/components/ui/collapsible.tsx +1 -15
  4. package/client/components/ui/dialog.tsx +1 -58
  5. package/client/components/ui/dropdown-menu.tsx +1 -254
  6. package/client/components/ui/hover-card.tsx +1 -44
  7. package/client/components/ui/input.tsx +1 -21
  8. package/client/components/ui/popover.tsx +1 -88
  9. package/client/components/ui/resizable.tsx +1 -40
  10. package/client/components/ui/skeleton.tsx +1 -13
  11. package/client/components/ui/slider.tsx +1 -70
  12. package/client/components/ui/spinner.tsx +1 -18
  13. package/client/components/ui/switch.tsx +1 -23
  14. package/client/components/ui/tabs.tsx +1 -0
  15. package/client/components/ui/textarea.tsx +1 -18
  16. package/client/components/ui/tooltip.tsx +1 -51
  17. package/client/features/chat/ChatPanel.tsx +6 -6
  18. package/client/features/chat/ChatPopup.tsx +3 -4
  19. package/client/features/chat/TurnView.tsx +5 -4
  20. package/client/features/chat/api.ts +5 -14
  21. package/client/features/chat/chat-frames.ts +9 -7
  22. package/client/features/chat/chat-send.ts +13 -2
  23. package/client/features/chat/chat-store.ts +1 -3
  24. package/client/features/chat/composer/ChatComposer.tsx +5 -1
  25. package/client/features/chat/composer/ModelPicker.tsx +44 -44
  26. package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
  27. package/client/features/chat/composer/model-order.ts +15 -0
  28. package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
  29. package/client/features/chat/group-turns.ts +12 -0
  30. package/client/features/chat/interleave-notices.ts +7 -11
  31. package/client/features/chat/session-view.ts +53 -0
  32. package/client/features/chat/tool-group/ToolCallGroup.tsx +1 -4
  33. package/client/features/chat/tool-group/format/codex.ts +4 -1
  34. package/client/features/chat/useChat.ts +10 -9
  35. package/client/features/dev/ChatStatesPage.tsx +3 -1
  36. package/client/features/dev/DevIndexPage.tsx +5 -0
  37. package/client/features/dev/DevRoutes.tsx +2 -0
  38. package/client/features/dev/HarnessDebugPage.tsx +1 -1
  39. package/client/features/dev/UiComponentPreviews.tsx +834 -0
  40. package/client/features/dev/UiComponentsPage.tsx +60 -0
  41. package/client/features/home/WorkspacePreview.tsx +1 -1
  42. package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
  43. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
  44. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
  45. package/client/features/settings/SettingsLayout.tsx +1 -1
  46. package/client/features/settings/WorkspaceSettings.tsx +4 -1
  47. package/client/features/views/ViewManager.tsx +14 -9
  48. package/client/features/widgets/WidgetFrame.tsx +1 -1
  49. package/client/features/widgets/Widgets.tsx +1 -3
  50. package/client/features/workspace/WorkspaceScreen.tsx +5 -1
  51. package/client/features/workspace/WorkspaceSplitLayout.tsx +6 -1
  52. package/client/features/workspace/api.ts +2 -4
  53. package/client/index.css +22 -29
  54. package/dist/chunk-245wt82v.css +1 -0
  55. package/dist/{chunk-tny85yt2.js → chunk-4s15axjs.js} +2 -2
  56. package/dist/{chunk-c9pjqx9m.js → chunk-53a7pxcz.js} +1 -1
  57. package/dist/{chunk-104m57qw.js → chunk-87thzbtw.js} +2 -2
  58. package/dist/chunk-a6jad1a6.js +1 -0
  59. package/dist/chunk-dghwstd2.js +9 -0
  60. package/dist/chunk-eg120aca.js +1 -0
  61. package/dist/{chunk-v7wr1df4.js → chunk-j3wvxjr7.js} +1 -1
  62. package/dist/chunk-j7hh2ab4.js +70 -0
  63. package/dist/chunk-w482ew2c.js +546 -0
  64. package/dist/chunk-y8eyahwx.js +1 -0
  65. package/dist/index.html +1 -1
  66. package/lib/format.ts +55 -6
  67. package/lib/themes.ts +6 -6
  68. package/lib/types.ts +10 -9
  69. package/package.json +12 -5
  70. package/registry.json +643 -0
  71. package/server/agent.ts +1 -1
  72. package/server/api.ts +26 -30
  73. package/server/applets.ts +30 -29
  74. package/server/bundler/applet-css.ts +7 -107
  75. package/server/bundler/build-applet.ts +5 -1
  76. package/server/bundler/build-worker.ts +178 -0
  77. package/server/cli-ui-components.ts +28 -33
  78. package/server/cli.ts +6 -11
  79. package/server/data-dir.ts +1 -1
  80. package/server/harness/README.md +41 -48
  81. package/server/harness/acp/NOTES.md +426 -0
  82. package/server/harness/acp/discovery.ts +27 -30
  83. package/server/harness/acp/model-state.ts +57 -0
  84. package/server/harness/acp/session.ts +18 -6
  85. package/server/harness/claude-code/NOTES.md +47 -12
  86. package/server/harness/claude-code/cli.ts +40 -0
  87. package/server/harness/claude-code/index.ts +11 -5
  88. package/server/harness/claude-code/models.ts +72 -19
  89. package/server/harness/claude-code/session.ts +408 -299
  90. package/server/harness/codex/NOTES.md +222 -350
  91. package/server/harness/codex/adapter.ts +94 -45
  92. package/server/harness/codex/auth.ts +1 -3
  93. package/server/harness/codex/client.ts +169 -249
  94. package/server/harness/codex/discovery.ts +9 -17
  95. package/server/harness/codex/index.ts +2 -1
  96. package/server/harness/codex/pagination.ts +24 -0
  97. package/server/harness/codex/permissions.ts +31 -7
  98. package/server/harness/codex/probe.ts +10 -13
  99. package/server/harness/codex/session.ts +549 -136
  100. package/server/harness/codex/transport.ts +184 -0
  101. package/server/harness/debug.ts +1 -1
  102. package/server/harness/hermes/NOTES.md +18 -0
  103. package/server/harness/hermes/discovery.ts +20 -0
  104. package/server/harness/hermes/index.ts +9 -0
  105. package/server/harness/hermes/models.ts +28 -8
  106. package/server/harness/types.ts +4 -2
  107. package/server/moi-scaffold.ts +1 -1
  108. package/server/preview.ts +3 -1
  109. package/server/registry.ts +63 -41
  110. package/server/tldraw-package.d.ts +4 -0
  111. package/server/ui-components.ts +101 -434
  112. package/server/view-builders.ts +2 -1
  113. package/server/web.ts +12 -5
  114. package/server/workspace-env.ts +3 -2
  115. package/tsconfig.json +0 -1
  116. package/ui-components/accordion.tsx +71 -0
  117. package/ui-components/alert-dialog.tsx +165 -0
  118. package/ui-components/alert.tsx +68 -0
  119. package/ui-components/attachment.tsx +195 -0
  120. package/ui-components/avatar.tsx +90 -0
  121. package/ui-components/badge.tsx +49 -0
  122. package/ui-components/button-group.tsx +78 -0
  123. package/ui-components/button.tsx +55 -0
  124. package/ui-components/calendar.tsx +180 -0
  125. package/ui-components/card.tsx +84 -0
  126. package/ui-components/carousel.tsx +235 -0
  127. package/ui-components/chart.tsx +338 -0
  128. package/ui-components/checkbox.tsx +28 -0
  129. package/ui-components/collapsible.tsx +15 -0
  130. package/ui-components/combobox.tsx +267 -0
  131. package/ui-components/context-menu.tsx +244 -0
  132. package/ui-components/dialog.tsx +138 -0
  133. package/ui-components/docs/accordion.md +463 -0
  134. package/ui-components/docs/alert-dialog.md +481 -0
  135. package/ui-components/docs/alert.md +301 -0
  136. package/ui-components/docs/attachment.md +689 -0
  137. package/ui-components/docs/avatar.md +495 -0
  138. package/ui-components/docs/badge.md +258 -0
  139. package/ui-components/docs/button-group.md +879 -0
  140. package/ui-components/docs/button.md +26 -0
  141. package/ui-components/docs/calendar.md +862 -0
  142. package/ui-components/docs/card.md +265 -0
  143. package/ui-components/docs/carousel.md +627 -0
  144. package/ui-components/docs/chart.md +1256 -0
  145. package/ui-components/docs/checkbox.md +477 -0
  146. package/ui-components/docs/collapsible.md +446 -0
  147. package/ui-components/docs/combobox.md +1003 -0
  148. package/ui-components/docs/context-menu.md +860 -0
  149. package/ui-components/docs/data-table.md +1580 -0
  150. package/ui-components/docs/date-picker.md +614 -0
  151. package/ui-components/docs/dialog.md +414 -0
  152. package/ui-components/docs/drawer.md +51 -0
  153. package/ui-components/docs/dropdown-menu.md +1000 -0
  154. package/ui-components/docs/field.md +1192 -0
  155. package/ui-components/docs/hover-card.md +275 -0
  156. package/ui-components/docs/input-group.md +866 -0
  157. package/ui-components/docs/input.md +456 -0
  158. package/ui-components/docs/label.md +295 -0
  159. package/ui-components/docs/pagination.md +416 -0
  160. package/ui-components/docs/popover.md +348 -0
  161. package/ui-components/docs/progress.md +214 -0
  162. package/ui-components/docs/radio-group.md +389 -0
  163. package/ui-components/docs/resizable.md +265 -0
  164. package/ui-components/docs/select.md +616 -0
  165. package/ui-components/docs/separator.md +216 -0
  166. package/ui-components/docs/skeleton.md +205 -0
  167. package/ui-components/docs/slider.md +226 -0
  168. package/ui-components/docs/spinner.md +332 -0
  169. package/ui-components/docs/switch.md +236 -0
  170. package/ui-components/docs/table.md +551 -0
  171. package/ui-components/docs/tabs.md +379 -0
  172. package/ui-components/docs/textarea.md +187 -0
  173. package/ui-components/docs/toggle-group.md +370 -0
  174. package/ui-components/docs/toggle.md +91 -0
  175. package/ui-components/docs/tooltip.md +290 -0
  176. package/ui-components/drawer.tsx +213 -0
  177. package/ui-components/dropdown-menu.tsx +263 -0
  178. package/ui-components/field.tsx +224 -0
  179. package/ui-components/hover-card.tsx +46 -0
  180. package/ui-components/input-group.tsx +146 -0
  181. package/ui-components/input.tsx +20 -0
  182. package/ui-components/label.tsx +17 -0
  183. package/ui-components/pagination.tsx +124 -0
  184. package/ui-components/popover.tsx +81 -0
  185. package/ui-components/progress.tsx +63 -0
  186. package/ui-components/radio-group.tsx +38 -0
  187. package/ui-components/resizable.tsx +40 -0
  188. package/ui-components/scoped-portal.tsx +31 -0
  189. package/ui-components/select.tsx +195 -0
  190. package/ui-components/separator.tsx +18 -0
  191. package/ui-components/skeleton.tsx +15 -0
  192. package/ui-components/slider.tsx +75 -0
  193. package/ui-components/spinner.tsx +20 -0
  194. package/ui-components/switch.tsx +27 -0
  195. package/ui-components/table.tsx +86 -0
  196. package/ui-components/tabs.tsx +75 -0
  197. package/ui-components/textarea.tsx +17 -0
  198. package/ui-components/toggle-group.tsx +85 -0
  199. package/ui-components/toggle.tsx +42 -0
  200. package/ui-components/tooltip.tsx +61 -0
  201. package/ui-components/utils.ts +8 -0
  202. package/workspace/.claude/skills/moi-workspace/SKILL.md +11 -20
  203. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +4 -3
  204. package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
  205. package/dist/chunk-59zf0m6n.js +0 -1
  206. package/dist/chunk-bj3akjs2.js +0 -1
  207. package/dist/chunk-j2w2vak4.js +0 -546
  208. package/dist/chunk-k2r9c95m.js +0 -10
  209. package/dist/chunk-kmbxhgwv.js +0 -1
  210. package/dist/chunk-p1yqa71k.js +0 -83
  211. package/dist/chunk-r5xrenjy.css +0 -1
@@ -0,0 +1,184 @@
1
+ // Newline JSON-RPC only. Workspace/process policy lives in client.ts; keeping
2
+ // framing separate lets tests exercise the same transport with in-memory pipes.
3
+ import { codexServerRequestResponse } from './permissions'
4
+
5
+ export type Json = Record<string, unknown>
6
+ export type NotificationListener = (method: string, params: Json) => void
7
+
8
+ export class CodexRpcError extends Error {
9
+ constructor(
10
+ message: string,
11
+ readonly code: number,
12
+ readonly data?: unknown
13
+ ) {
14
+ super(message)
15
+ this.name = 'CodexRpcError'
16
+ }
17
+ }
18
+
19
+ export type CodexTransport = {
20
+ rpc: <T>(method: string, params?: Json) => Promise<T>
21
+ notify: (method: string, params?: Json) => void
22
+ onNotification: (listener: NotificationListener) => () => void
23
+ isAlive: () => boolean
24
+ close: (error?: Error) => void
25
+ }
26
+
27
+ type TransportOptions = {
28
+ stdout: ReadableStream<Uint8Array>
29
+ write: (line: string) => void | Promise<void>
30
+ stop: () => void
31
+ tap?: (direction: 'send' | 'recv', frame: Json) => void
32
+ timeoutMs?: number
33
+ }
34
+
35
+ export function createCodexTransport(options: TransportOptions): CodexTransport {
36
+ let alive = true
37
+ let nextId = 1
38
+ const listeners = new Set<NotificationListener>()
39
+ const pending = new Map<
40
+ number,
41
+ {
42
+ resolve: (value: unknown) => void
43
+ reject: (error: Error) => void
44
+ timer: Timer
45
+ }
46
+ >()
47
+ const reader = options.stdout.getReader()
48
+
49
+ function fanout(method: string, params: Json) {
50
+ for (const listener of listeners) {
51
+ try {
52
+ listener(method, params)
53
+ } catch (error) {
54
+ console.error('[codex] notification listener threw', error)
55
+ }
56
+ }
57
+ }
58
+
59
+ function close(
60
+ error = new Error('Codex disconnected. Send another message to resume this chat.')
61
+ ) {
62
+ if (!alive) return
63
+ alive = false
64
+ for (const request of pending.values()) {
65
+ clearTimeout(request.timer)
66
+ request.reject(error)
67
+ }
68
+ pending.clear()
69
+ fanout('__exit', { message: error.message })
70
+ listeners.clear()
71
+ void reader.cancel().catch(() => {})
72
+ try {
73
+ options.stop()
74
+ } catch {
75
+ /* The process may already have exited. */
76
+ }
77
+ }
78
+
79
+ function send(frame: Json) {
80
+ if (!alive) throw new Error('Codex app-server is not running')
81
+ options.tap?.('send', frame)
82
+ // Bun's flush can be asynchronous; observe failures instead of leaving an
83
+ // unhandled rejection and waiting for every RPC to time out independently.
84
+ try {
85
+ const written = options.write(JSON.stringify(frame) + '\n')
86
+ if (written)
87
+ void written.catch(error =>
88
+ close(error instanceof Error ? error : new Error(String(error)))
89
+ )
90
+ } catch (error) {
91
+ close(error instanceof Error ? error : new Error(String(error)))
92
+ }
93
+ }
94
+
95
+ function rpc<T>(method: string, params: Json = {}): Promise<T> {
96
+ if (!alive) return Promise.reject(new Error('Codex app-server is not running'))
97
+ const id = nextId++
98
+ return new Promise<T>((resolve, reject) => {
99
+ const timer = setTimeout(() => {
100
+ pending.delete(id)
101
+ reject(new Error(`Codex request timed out: ${method}`))
102
+ }, options.timeoutMs ?? 30_000)
103
+ // Register before writing: a synchronous response must find its waiter.
104
+ pending.set(id, { resolve: resolve as (value: unknown) => void, reject, timer })
105
+ send({ jsonrpc: '2.0', id, method, params })
106
+ })
107
+ }
108
+
109
+ function handleLine(line: string) {
110
+ if (!line.trim()) return
111
+ let parsed: unknown
112
+ try {
113
+ parsed = JSON.parse(line)
114
+ } catch {
115
+ return
116
+ }
117
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return
118
+ const msg = parsed as Json
119
+ options.tap?.('recv', msg)
120
+ if (typeof msg.method === 'string') {
121
+ const params =
122
+ msg.params && typeof msg.params === 'object' && !Array.isArray(msg.params)
123
+ ? (msg.params as Json)
124
+ : {}
125
+ if ('id' in msg) {
126
+ if (typeof msg.id !== 'string' && typeof msg.id !== 'number') return
127
+ send({ jsonrpc: '2.0', id: msg.id, ...codexServerRequestResponse(msg.method, params) })
128
+ } else fanout(msg.method, params)
129
+ return
130
+ }
131
+ if (typeof msg.id !== 'number') return
132
+ const request = pending.get(msg.id)
133
+ if (!request) return
134
+ pending.delete(msg.id)
135
+ clearTimeout(request.timer)
136
+ if (msg.error && typeof msg.error === 'object') {
137
+ const error = msg.error as Json
138
+ request.reject(
139
+ new CodexRpcError(
140
+ typeof error.message === 'string' ? error.message : 'Codex request failed',
141
+ typeof error.code === 'number' ? error.code : -32603,
142
+ error.data
143
+ )
144
+ )
145
+ } else request.resolve(msg.result)
146
+ }
147
+
148
+ void (async () => {
149
+ const decoder = new TextDecoder()
150
+ let buffer = ''
151
+ try {
152
+ while (alive) {
153
+ const { done, value } = await reader.read()
154
+ if (done) break
155
+ buffer += decoder.decode(value, { stream: true })
156
+ let start = 0
157
+ let end: number
158
+ while ((end = buffer.indexOf('\n', start)) >= 0) {
159
+ handleLine(buffer.slice(start, end))
160
+ start = end + 1
161
+ }
162
+ buffer = buffer.slice(start)
163
+ }
164
+ if (alive) handleLine(buffer + decoder.decode())
165
+ } catch (error) {
166
+ close(error instanceof Error ? error : new Error(String(error)))
167
+ } finally {
168
+ close()
169
+ }
170
+ })()
171
+
172
+ return {
173
+ rpc,
174
+ notify: (method, params = {}) => send({ jsonrpc: '2.0', method, params }),
175
+ onNotification(listener) {
176
+ listeners.add(listener)
177
+ return () => {
178
+ listeners.delete(listener)
179
+ }
180
+ },
181
+ isAlive: () => alive,
182
+ close
183
+ }
184
+ }
@@ -1,4 +1,4 @@
1
- // Shared debug taps for the /playground/harness page.
1
+ // Shared debug taps for /dev/harness.
2
2
  //
3
3
  // Two channels of ring buffers, kept module-global so they survive session
4
4
  // teardowns and process-client restarts:
@@ -182,6 +182,24 @@ what moi's current backends expose — it already carries `cwd`, `git_branch`,
182
182
  `git_repo_root`, `parent_session_id`, per-session token counts and
183
183
  `estimated_cost_usd`/`actual_cost_usd`.
184
184
 
185
+ #### 3.2.2 The default model rides on `currentModelId`, and the catalog is cached
186
+
187
+ `session/new` also returns `currentModelId` — the model Hermes resolves from
188
+ the profile's `config.yaml` (`model.default` + `model.provider`, rewritten by
189
+ `hermes model`). `./models.ts` maps it onto a synthetic `default` row with
190
+ `resolvedModel`, the same convention the Claude and Codex harnesses use, so
191
+ the picker preselects the model a promptless chat would actually run.
192
+ Verified against v0.20.0 (`xai-oauth:grok-build-0.1`, 67 raw rows).
193
+
194
+ The catalog only ever arrives on `session/new`, and every such call persists a
195
+ zero-message row in `state.db` that `hermes sessions list` shows as a blank
196
+ entry (moi's own list hides them). So the state is cached per workspace
197
+ (`../acp/model-state.ts`): the first picker snapshot opens one throwaway
198
+ session, every real chat start refreshes the cache from its own `session/new`,
199
+ and the cache is stamped with the mtimes of the profile's `config.yaml` and
200
+ `.env` (`hermesConfigFingerprint`) so a default changed outside moi is
201
+ rediscovered on the next snapshot instead of on every one.
202
+
185
203
  ### 3.3 The prompt stream
186
204
 
187
205
  `session/prompt` streams `session/update` notifications and resolves with
@@ -153,3 +153,23 @@ export async function resolveHermesProfile(
153
153
  }
154
154
  return profiles.find(p => p.path === workspacePath) ?? null
155
155
  }
156
+
157
+ // Version stamp for the profile inputs that decide its default model:
158
+ // config.yaml (`model.default`, rewritten by `hermes model`) and .env
159
+ // (provider keys, which gate which entries the catalog lists at all). Mtimes,
160
+ // not contents — the ACP session reports the real resolved state, this only
161
+ // says when to ask again. A missing file stamps as such, so creating it later
162
+ // still counts as a change.
163
+ export async function hermesConfigFingerprint(home: string | null): Promise<string | undefined> {
164
+ if (!home) return undefined
165
+ const stamps = await Promise.all(
166
+ ['config.yaml', '.env'].map(async file => {
167
+ try {
168
+ return String((await stat(join(home, file))).mtimeMs)
169
+ } catch {
170
+ return 'missing'
171
+ }
172
+ })
173
+ )
174
+ return stamps.join(' ')
175
+ }
@@ -26,6 +26,7 @@ import { getAcpProcessInfo, killAcpWorkspace, killAllAcpClients } from '../acp/c
26
26
  import {
27
27
  DEFAULT_PROFILE,
28
28
  discoverHermesProfiles,
29
+ hermesConfigFingerprint,
29
30
  profileHomeFromWorkspace,
30
31
  resolveHermesProfile
31
32
  } from './discovery'
@@ -42,6 +43,14 @@ const config: AcpProviderConfig = {
42
43
  provider: 'hermes',
43
44
  noPromptModeId: NO_PROMPT_MODE,
44
45
  mapModels: hermesModels,
46
+ // The profile's default model (`currentModelId` on `session/new`) follows
47
+ // config.yaml, which `hermes model` and hand edits change while moi runs.
48
+ // Stamp the cache with the config mtimes so such a change is picked up on
49
+ // the next snapshot without opening a throwaway session every time.
50
+ modelStateFingerprint: async ctx => {
51
+ const profile = await resolveHermesProfile(ctx.workspacePath, ctx.agentId)
52
+ return hermesConfigFingerprint(profile?.home ?? profileHomeFromWorkspace(ctx.workspacePath))
53
+ },
45
54
  supportsImages: true,
46
55
  async spawn(ctx) {
47
56
  const bin = findHarnessExecutable('hermes')
@@ -15,10 +15,11 @@
15
15
  // in `description` alone, which is why the group comes from that field.
16
16
  import type { Model } from '@/lib/types'
17
17
 
18
- import type { AcpModelInfo } from '../acp/wire'
18
+ import type { AcpModelInfo, AcpModelState } from '../acp/wire'
19
19
 
20
20
  const PROVIDER_PREFIX = /^Provider:\s*/
21
- // Hermes marks the model it would pick itself; moi tracks its own selection.
21
+ // This is display cleanup only. The default comes from structured
22
+ // `currentModelId`, never by inferring it from this suffix.
22
23
  const CURRENT_SUFFIX = /\s*•\s*current$/
23
24
 
24
25
  function providerOf(description: string | undefined): string | undefined {
@@ -65,15 +66,34 @@ function hermesModel(info: AcpModelInfo): Model {
65
66
  // — for the same endpoint and model. Both spellings work, so keep the first
66
67
  // and drop rows the picker would render as an exact duplicate. Keyed on
67
68
  // `providerId` where there is one, since both spellings normalize to it.
68
- export function hermesModels(infos: AcpModelInfo[]): Model[] {
69
- const seen = new Set<string>()
69
+ export function hermesModels(state: AcpModelState): Model[] {
70
+ const seen = new Map<string, number>()
70
71
  const out: Model[] = []
71
- for (const info of infos) {
72
+ for (const info of state.availableModels ?? []) {
72
73
  const model = hermesModel(info)
73
74
  const key = `${model.providerId ?? model.group ?? ''} ${model.displayName}`
74
- if (seen.has(key)) continue
75
- seen.add(key)
75
+ const existingIndex = seen.get(key)
76
+ if (existingIndex !== undefined) {
77
+ // If Hermes names a duplicate spelling as current, retain that exact id
78
+ // so the structured default can resolve to a visible picker row.
79
+ if (info.modelId === state.currentModelId) out[existingIndex] = model
80
+ continue
81
+ }
82
+ seen.set(key, out.length)
76
83
  out.push(model)
77
84
  }
78
- return out
85
+
86
+ if (!state.currentModelId) return out
87
+ const currentIndex = out.findIndex(model => model.value === state.currentModelId)
88
+ if (currentIndex === -1) return out
89
+
90
+ out[currentIndex] = { ...out[currentIndex], resolvedModel: state.currentModelId }
91
+ return [
92
+ {
93
+ value: 'default',
94
+ resolvedModel: state.currentModelId,
95
+ displayName: 'Default (from Hermes)'
96
+ },
97
+ ...out
98
+ ]
79
99
  }
@@ -72,6 +72,8 @@ export type DiscoveredWorkspaceCandidate = {
72
72
  type: WorkspaceType
73
73
  }
74
74
 
75
+ export type HarnessWorkspace = Pick<WorkspaceEntry, 'id' | 'path' | 'type' | 'agentId'>
76
+
75
77
  export type Harness = {
76
78
  id: WorkspaceType
77
79
  capabilities: HarnessCapabilities
@@ -104,9 +106,9 @@ export type Harness = {
104
106
  discoverWorkspaces?(registeredPaths: Set<string>): Promise<DiscoveredWorkspaceCandidate[]>
105
107
  // Without a workspace, only check whether the runtime is installed. With a
106
108
  // workspace, also check provider state such as authentication.
107
- availability?(ws?: WorkspaceEntry): Promise<HarnessAvailability>
109
+ availability?(ws?: HarnessWorkspace): Promise<HarnessAvailability>
108
110
  // Optional recovery flow the host can start without a terminal.
109
- startLogin?(ws: WorkspaceEntry): Promise<HarnessLogin>
111
+ startLogin?(ws: HarnessWorkspace): Promise<HarnessLogin>
110
112
 
111
113
  // -- host integration hooks -------------------------------------------------
112
114
  // Env is frozen at spawn everywhere; this reaps idle sessions/processes so
@@ -20,7 +20,7 @@ export const MOI_PACKAGE_JSON = {
20
20
  // Base UI primitives and the cn() stack, so one install at workspace
21
21
  // creation covers the common path. Component-specific deps (recharts,
22
22
  // embla, …) stay agent-installed on demand — `add` prints them.
23
- '@base-ui/react': '^1.2.0',
23
+ '@base-ui/react': '^1.8.0',
24
24
  'class-variance-authority': '^0.7.1',
25
25
  clsx: '^2.1.1',
26
26
  'tailwind-merge': '^3.3.1'
package/server/preview.ts CHANGED
@@ -61,7 +61,9 @@ export async function serveWorkspaceImagePreview(
61
61
  .resize(PREVIEW_MAX_EDGE, PREVIEW_MAX_EDGE, { fit: 'inside', withoutEnlargement: true })
62
62
  .webp({ quality: 80 })
63
63
  .toBuffer()
64
- return new Response(data, { headers: { ...headers, 'Content-Type': 'image/webp' } })
64
+ return new Response(new Uint8Array(data), {
65
+ headers: { ...headers, 'Content-Type': 'image/webp' }
66
+ })
65
67
  } catch {
66
68
  // Undecodable (corrupt, or an unsupported codec despite the extension) —
67
69
  // there's no preview to show; the client hides the <img> on error.
@@ -1,4 +1,4 @@
1
- import { mkdir } from 'node:fs/promises'
1
+ import { rename, rm } from 'node:fs/promises'
2
2
  import { homedir } from 'node:os'
3
3
  import { join, resolve, sep } from 'path'
4
4
 
@@ -43,8 +43,23 @@ async function readRegistry(): Promise<WorkspaceEntry[]> {
43
43
  }
44
44
 
45
45
  async function writeRegistry(entries: WorkspaceEntry[]): Promise<void> {
46
- await mkdir(join(_registryPath, '..'), { recursive: true })
47
- await Bun.write(_registryPath, JSON.stringify(entries, null, 2))
46
+ const temporaryPath = `${_registryPath}.${crypto.randomUUID()}.tmp`
47
+ try {
48
+ await Bun.write(temporaryPath, JSON.stringify(entries, null, 2))
49
+ await rename(temporaryPath, _registryPath)
50
+ } finally {
51
+ await rm(temporaryPath, { force: true })
52
+ }
53
+ }
54
+
55
+ // Lock the whole read-modify-write operation, including validation. Atomic
56
+ // replacement keeps readers safe; the queue keeps concurrent writers safe.
57
+ let writeChain: Promise<unknown> = Promise.resolve()
58
+
59
+ function locked<T>(operation: () => Promise<T>): Promise<T> {
60
+ const run = writeChain.then(operation)
61
+ writeChain = run.catch(() => {})
62
+ return run
48
63
  }
49
64
 
50
65
  export type RegisterOptions = {
@@ -90,26 +105,28 @@ export async function registerWorkspace(
90
105
  absPath: string,
91
106
  opts: RegisterOptions = {}
92
107
  ): Promise<WorkspaceEntry> {
93
- const normalPath = resolve(absPath)
94
- const entries = await readRegistry()
95
- if (opts.id) {
96
- const error = workspaceIdError(entries, normalPath, opts.id)
97
- if (error) throw new Error(error)
98
- }
99
- const existing = entries.find(e => e.path === normalPath)
100
- if (existing) return existing
101
- const entry: WorkspaceEntry = {
102
- id: opts.id ?? newWorkspaceId(),
103
- path: normalPath,
104
- addedAt: new Date().toISOString(),
105
- ...(opts.type ? { type: opts.type } : {}),
106
- ...(opts.name ? { name: opts.name } : {}),
107
- ...(opts.agentId ? { agentId: opts.agentId } : {}),
108
- ...(opts.isDefault ? { isDefault: opts.isDefault } : {}),
109
- ...(opts.lastRunAt ? { lastRunAt: opts.lastRunAt } : {})
110
- }
111
- await writeRegistry([entry, ...entries])
112
- return withDisplayPath(entry)
108
+ return locked(async () => {
109
+ const normalPath = resolve(absPath)
110
+ const entries = await readRegistry()
111
+ if (opts.id) {
112
+ const error = workspaceIdError(entries, normalPath, opts.id)
113
+ if (error) throw new Error(error)
114
+ }
115
+ const existing = entries.find(e => e.path === normalPath)
116
+ if (existing) return existing
117
+ const entry: WorkspaceEntry = {
118
+ id: opts.id ?? newWorkspaceId(),
119
+ path: normalPath,
120
+ addedAt: new Date().toISOString(),
121
+ ...(opts.type ? { type: opts.type } : {}),
122
+ ...(opts.name ? { name: opts.name } : {}),
123
+ ...(opts.agentId ? { agentId: opts.agentId } : {}),
124
+ ...(opts.isDefault ? { isDefault: opts.isDefault } : {}),
125
+ ...(opts.lastRunAt ? { lastRunAt: opts.lastRunAt } : {})
126
+ }
127
+ await writeRegistry([entry, ...entries])
128
+ return withDisplayPath(entry)
129
+ })
113
130
  }
114
131
 
115
132
  export async function getWorkspace(id: string): Promise<WorkspaceEntry | null> {
@@ -118,11 +135,13 @@ export async function getWorkspace(id: string): Promise<WorkspaceEntry | null> {
118
135
  }
119
136
 
120
137
  export async function removeWorkspace(id: string): Promise<boolean> {
121
- const entries = await readRegistry()
122
- const next = entries.filter(e => e.id !== id)
123
- if (next.length === entries.length) return false
124
- await writeRegistry(next)
125
- return true
138
+ return locked(async () => {
139
+ const entries = await readRegistry()
140
+ const next = entries.filter(e => e.id !== id)
141
+ if (next.length === entries.length) return false
142
+ await writeRegistry(next)
143
+ return true
144
+ })
126
145
  }
127
146
 
128
147
  export async function listWorkspaces(): Promise<WorkspaceEntry[]> {
@@ -131,19 +150,22 @@ export async function listWorkspaces(): Promise<WorkspaceEntry[]> {
131
150
  }
132
151
 
133
152
  export async function reorderWorkspaces(ids: string[]): Promise<WorkspaceEntry[]> {
134
- const entries = await readRegistry()
135
- if (ids.length !== entries.length) throw new Error('Workspace order must include every workspace')
136
-
137
- const unique = new Set(ids)
138
- if (unique.size !== ids.length) throw new Error('Workspace order contains duplicate ids')
139
-
140
- const byId = new Map(entries.map(e => [e.id, e]))
141
- const next = ids.map(id => byId.get(id))
142
- if (next.some(e => !e)) throw new Error('Workspace order contains unknown ids')
143
-
144
- const ordered = next as WorkspaceEntry[]
145
- await writeRegistry(ordered)
146
- return ordered.map(withDisplayPath)
153
+ return locked(async () => {
154
+ const entries = await readRegistry()
155
+ if (ids.length !== entries.length)
156
+ throw new Error('Workspace order must include every workspace')
157
+
158
+ const unique = new Set(ids)
159
+ if (unique.size !== ids.length) throw new Error('Workspace order contains duplicate ids')
160
+
161
+ const byId = new Map(entries.map(e => [e.id, e]))
162
+ const next = ids.map(id => byId.get(id))
163
+ if (next.some(e => !e)) throw new Error('Workspace order contains unknown ids')
164
+
165
+ const ordered = next as WorkspaceEntry[]
166
+ await writeRegistry(ordered)
167
+ return ordered.map(withDisplayPath)
168
+ })
147
169
  }
148
170
 
149
171
  // Resolve a path to the registered workspace that *contains* it: the entry
@@ -0,0 +1,4 @@
1
+ declare module 'tldraw/package.json' {
2
+ const packageJson: { version: string }
3
+ export default packageJson
4
+ }