moi-computer 0.11.1-next.1 → 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 (43) hide show
  1. package/client/features/chat/chat-frames.ts +4 -5
  2. package/client/features/chat/chat-send.ts +13 -2
  3. package/client/features/chat/chat-store.ts +1 -3
  4. package/client/features/chat/composer/ModelPicker.tsx +40 -41
  5. package/client/features/chat/composer/model-order.ts +15 -0
  6. package/client/features/chat/group-turns.ts +1 -0
  7. package/client/features/chat/interleave-notices.ts +7 -11
  8. package/client/features/chat/tool-group/ToolCallGroup.tsx +1 -4
  9. package/client/features/chat/tool-group/format/codex.ts +4 -1
  10. package/client/features/chat/useChat.ts +5 -8
  11. package/dist/chunk-245wt82v.css +1 -0
  12. package/dist/{chunk-yc471zah.js → chunk-j7hh2ab4.js} +48 -48
  13. package/dist/{chunk-vwjeezeb.js → chunk-y8eyahwx.js} +1 -1
  14. package/dist/index.html +1 -1
  15. package/lib/format.ts +6 -5
  16. package/lib/types.ts +5 -2
  17. package/package.json +1 -1
  18. package/server/api.ts +1 -1
  19. package/server/bundler/applet-css.ts +1 -106
  20. package/server/harness/README.md +28 -39
  21. package/server/harness/codex/NOTES.md +222 -350
  22. package/server/harness/codex/adapter.ts +94 -45
  23. package/server/harness/codex/auth.ts +1 -3
  24. package/server/harness/codex/client.ts +169 -249
  25. package/server/harness/codex/discovery.ts +9 -17
  26. package/server/harness/codex/index.ts +2 -1
  27. package/server/harness/codex/pagination.ts +24 -0
  28. package/server/harness/codex/permissions.ts +31 -7
  29. package/server/harness/codex/probe.ts +10 -13
  30. package/server/harness/codex/session.ts +549 -136
  31. package/server/harness/codex/transport.ts +184 -0
  32. package/server/harness/debug.ts +1 -1
  33. package/server/web.ts +3 -0
  34. package/ui-components/alert-dialog.tsx +1 -1
  35. package/ui-components/alert.tsx +1 -1
  36. package/ui-components/avatar.tsx +1 -1
  37. package/ui-components/checkbox.tsx +2 -1
  38. package/ui-components/combobox.tsx +3 -1
  39. package/ui-components/field.tsx +1 -1
  40. package/ui-components/input-group.tsx +2 -2
  41. package/ui-components/radio-group.tsx +2 -1
  42. package/ui-components/switch.tsx +2 -1
  43. package/dist/chunk-6664vxpk.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:
package/server/web.ts CHANGED
@@ -84,6 +84,9 @@ function upgrade(server: Upgradable, req: Request, data: WsData) {
84
84
  export const app = Bun.serve<WsData>({
85
85
  port: PORT,
86
86
  hostname: process.env.HOST ?? '127.0.0.1',
87
+ // Agent startup/discovery can outlast Bun's 10s HTTP default. Allow the
88
+ // harness's 30s RPC timeout to return an error before the socket closes.
89
+ idleTimeout: 60,
87
90
  // HMR only in dev; prod serves prebuilt static assets (no bundler).
88
91
  development: prebuilt ? false : { hmr: true },
89
92
  routes: {
@@ -104,7 +104,7 @@ function AlertDialogTitle({
104
104
  <AlertDialogPrimitive.Title
105
105
  data-slot="alert-dialog-title"
106
106
  className={cn(
107
- 'text-base font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2',
107
+ 'text-base font-medium sm:group-data-[size=default]/alert-dialog-content:[:where([class~="group/alert-dialog-content"]):has([data-slot=alert-dialog-media])_&]:col-start-2',
108
108
  className
109
109
  )}
110
110
  {...props}
@@ -38,7 +38,7 @@ function AlertTitle({ className, ...props }: React.ComponentProps<'div'>) {
38
38
  <div
39
39
  data-slot="alert-title"
40
40
  className={cn(
41
- 'font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground',
41
+ 'font-medium [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [:where([class~="group/alert"]):has(>svg)_&]:col-start-2',
42
42
  className
43
43
  )}
44
44
  {...props}
@@ -79,7 +79,7 @@ function AvatarGroupCount({ className, ...props }: React.ComponentProps<'div'>)
79
79
  <div
80
80
  data-slot="avatar-group-count"
81
81
  className={cn(
82
- 'relative flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-sm text-muted-foreground ring-2 ring-background group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3',
82
+ 'relative flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-sm text-muted-foreground ring-2 ring-background [&>svg]:size-4 [:where([class~="group/avatar-group"]):has([data-size=lg])_&]:size-10 [:where([class~="group/avatar-group"]):has([data-size=lg])_&]:[&>svg]:size-5 [:where([class~="group/avatar-group"]):has([data-size=sm])_&]:size-6 [:where([class~="group/avatar-group"]):has([data-size=sm])_&]:[&>svg]:size-3',
83
83
  className
84
84
  )}
85
85
  {...props}
@@ -4,12 +4,13 @@ import { Checkbox as CheckboxPrimitive } from '@base-ui/react/checkbox'
4
4
  import { cn } from './utils'
5
5
  import { IconCheck } from '@tabler/icons-react'
6
6
 
7
+ // Enclosing-label resets must stay below the control's own focus/invalid styles.
7
8
  function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
8
9
  return (
9
10
  <CheckboxPrimitive.Root
10
11
  data-slot="checkbox"
11
12
  className={cn(
12
- 'peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-border after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary',
13
+ 'peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border transition-colors outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground [:where([class~="group/field"]):has(:disabled)_&]:opacity-50 [:where([class~="group/field-label"]):has(:focus-visible)_&]:not-data-checked:border-border [:where([class~="group/field-label"]):has(:focus-visible)_&]:data-checked:border-primary [:where([class~="group/field-label"]:has(:focus-visible))_&]:ring-0',
13
14
  className
14
15
  )}
15
16
  {...props}
@@ -60,7 +60,9 @@ function ComboboxInput({
60
60
  variant="ghost"
61
61
  render={<ComboboxTrigger />}
62
62
  data-slot="input-group-button"
63
- className="group-has-data-[slot=combobox-clear]/input-group:hidden data-pressed:bg-transparent"
63
+ className={
64
+ 'data-pressed:bg-transparent [:where([class~="group/input-group"]):has([data-slot=combobox-clear])_&]:hidden'
65
+ }
64
66
  disabled={disabled}
65
67
  />
66
68
  )}
@@ -124,7 +124,7 @@ function FieldDescription({ className, ...props }: React.ComponentProps<'p'>) {
124
124
  <p
125
125
  data-slot="field-description"
126
126
  className={cn(
127
- 'text-left text-sm leading-normal font-normal text-muted-foreground group-has-data-horizontal/field:text-balance [[data-variant=legend]+&]:-mt-1.5',
127
+ 'text-left text-sm leading-normal font-normal text-muted-foreground [:where([class~="group/field"]):has([data-horizontal])_&]:text-balance [[data-variant=legend]+&]:-mt-1.5',
128
128
  'last:mt-0 nth-last-2:-mt-1',
129
129
  '[&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary',
130
130
  className
@@ -30,9 +30,9 @@ const inputGroupAddonVariants = cva(
30
30
  'inline-start': 'order-first pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem]',
31
31
  'inline-end': 'order-last pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem]',
32
32
  'block-start':
33
- 'order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2',
33
+ 'order-first w-full justify-start px-2.5 pt-2 [.border-b]:pb-2 [:where([class~="group/input-group"]):has(>input)_&]:pt-2',
34
34
  'block-end':
35
- 'order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2'
35
+ 'order-last w-full justify-start px-2.5 pb-2 [.border-t]:pt-2 [:where([class~="group/input-group"]):has(>input)_&]:pb-2'
36
36
  }
37
37
  },
38
38
  defaultVariants: {
@@ -14,12 +14,13 @@ function RadioGroup({ className, ...props }: RadioGroupPrimitive.Props) {
14
14
  )
15
15
  }
16
16
 
17
+ // Enclosing-label resets must stay below the control's own focus/invalid styles.
17
18
  function RadioGroupItem({ className, ...props }: RadioPrimitive.Root.Props) {
18
19
  return (
19
20
  <RadioPrimitive.Root
20
21
  data-slot="radio-group-item"
21
22
  className={cn(
22
- 'group/radio-group-item peer relative flex aspect-square size-4 shrink-0 rounded-full border outline-none group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-border after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:data-checked:bg-primary',
23
+ 'group/radio-group-item peer relative flex aspect-square size-4 shrink-0 rounded-full border outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary [:where([class~="group/field-label"]):has(:focus-visible)_&]:not-data-checked:border-border [:where([class~="group/field-label"]):has(:focus-visible)_&]:data-checked:border-primary [:where([class~="group/field-label"]:has(:focus-visible))_&]:ring-0',
23
24
  className
24
25
  )}
25
26
  {...props}
@@ -5,12 +5,13 @@ import { cn } from './utils'
5
5
 
6
6
  type SwitchProps = SwitchPrimitive.Root.Props
7
7
 
8
+ // Enclosing-label resets must stay below the control's own focus/invalid styles.
8
9
  function Switch({ className, ...props }: SwitchProps) {
9
10
  return (
10
11
  <SwitchPrimitive.Root
11
12
  data-slot="switch"
12
13
  className={cn(
13
- 'peer relative inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-sm border border-transparent p-px transition-all outline-none group-has-[:focus-visible]/field-label:border-transparent group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-checked:bg-primary data-unchecked:bg-accent data-disabled:cursor-not-allowed data-disabled:opacity-50',
14
+ 'peer relative inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-sm border border-transparent p-px transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-checked:bg-primary data-unchecked:bg-accent data-disabled:cursor-not-allowed data-disabled:opacity-50 [:where([class~="group/field-label"]:has(:focus-visible))_&]:border-transparent [:where([class~="group/field-label"]:has(:focus-visible))_&]:ring-0',
14
15
  className
15
16
  )}
16
17
  {...props}