moi-computer 0.8.0 → 0.9.0

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 (110) hide show
  1. package/client/api/workspace-keys.ts +1 -2
  2. package/client/app/AppRouter.tsx +10 -3
  3. package/client/app/routes/HomeRoute.tsx +1 -1
  4. package/client/app/shell/SidebarLayout.tsx +2 -14
  5. package/client/components/shared/Composer.tsx +20 -7
  6. package/client/components/shared/PanelHeader.tsx +8 -1
  7. package/client/components/ui/button.tsx +3 -3
  8. package/client/components/ui/dialog.tsx +1 -1
  9. package/client/components/ui/dropdown-menu.tsx +2 -2
  10. package/client/components/ui/hover-card.tsx +1 -1
  11. package/client/components/ui/popover.tsx +1 -1
  12. package/client/components/ui/resizable.tsx +40 -0
  13. package/client/features/chat/ChatEmptyState.tsx +9 -11
  14. package/client/features/chat/ChatPanel.tsx +76 -48
  15. package/client/features/chat/ChatPopup.tsx +16 -2
  16. package/client/features/chat/ChatPromptBubbles.tsx +6 -8
  17. package/client/features/chat/ChatSelector.tsx +24 -7
  18. package/client/features/chat/MarkdownContent.tsx +1 -1
  19. package/client/features/chat/ModelPicker.tsx +5 -4
  20. package/client/features/chat/TurnView.tsx +108 -13
  21. package/client/features/chat/api.ts +1 -18
  22. package/client/features/chat/chat-send.ts +2 -2
  23. package/client/features/chat/{ChatComposer.tsx → composer/ChatComposer.tsx} +6 -5
  24. package/client/features/chat/composer/banners/ChatErrorBanner.tsx +28 -0
  25. package/client/features/chat/composer/banners/ComposerBanner.tsx +30 -0
  26. package/client/features/chat/composer/banners/WorkspaceAgentAvailabilityBanner.tsx +91 -0
  27. package/client/features/{workspace → chat/composer/banners}/WorkspaceSkillUpdateBanner.tsx +9 -7
  28. package/client/features/chat/composer/useWorkspaceComposerState.tsx +74 -0
  29. package/client/features/{workspace → chat/composer}/useWorkspaceSkillUpdates.ts +1 -1
  30. package/client/features/chat/group-turns.ts +46 -28
  31. package/client/features/chat/interleave-notices.ts +84 -0
  32. package/client/features/chat/model-order.ts +9 -3
  33. package/client/features/chat/tool-group/TimelineRow.tsx +23 -11
  34. package/client/features/chat/tool-group/ToolCallGroup.tsx +38 -3
  35. package/client/features/chat/tool-group/format.ts +51 -10
  36. package/client/features/chat/useAppletChatMessage.ts +11 -16
  37. package/client/features/chat/useChat.ts +3 -7
  38. package/client/features/dev/ChatStatesPage.tsx +466 -0
  39. package/client/features/dev/DevIndexPage.tsx +52 -0
  40. package/client/features/dev/DevRoutes.tsx +6 -3
  41. package/client/features/dev/HarnessDebugPage.tsx +3 -3
  42. package/client/features/dev/chat-states-fixtures.ts +744 -0
  43. package/client/features/scratchpad/Scratchpad.tsx +4 -0
  44. package/client/features/scratchpad/scratch-session.ts +71 -0
  45. package/client/features/views/ViewBuilderTab.tsx +5 -4
  46. package/client/features/views/useViewBuilderActions.ts +2 -2
  47. package/client/features/workspace/WorkspaceLayoutContext.tsx +4 -2
  48. package/client/features/workspace/WorkspaceScreen.tsx +128 -146
  49. package/client/features/workspace/WorkspaceSplitLayout.tsx +111 -0
  50. package/client/features/workspace/api.ts +33 -8
  51. package/client/features/workspace/useFitsSplitLayout.ts +31 -5
  52. package/client/index.css +1 -1
  53. package/client/lib/flags.ts +4 -3
  54. package/client/runtime/useWorkspaceEvents.ts +18 -1
  55. package/client/store/ui.ts +5 -1
  56. package/dist/{chunk-0pcdwjkp.js → chunk-2vaafjp4.js} +1 -1
  57. package/dist/{chunk-9y2zbzqz.js → chunk-35fq49qa.js} +1 -1
  58. package/dist/{chunk-h9h8f176.js → chunk-3b3rkjet.js} +1 -1
  59. package/dist/chunk-gt7n06ef.js +1 -0
  60. package/dist/{chunk-r5ce5cdg.js → chunk-kkj86722.js} +75 -75
  61. package/dist/chunk-ty1sqbmn.js +80 -0
  62. package/dist/chunk-xeyxk7ep.js +10 -0
  63. package/dist/chunk-yz6wd5vc.css +1 -0
  64. package/dist/index.html +1 -1
  65. package/lib/format.ts +37 -7
  66. package/lib/themes.ts +2 -2
  67. package/lib/types.ts +38 -8
  68. package/lib/workspace-layout.ts +2 -2
  69. package/package.json +6 -4
  70. package/server/agent.ts +199 -0
  71. package/server/api.ts +36 -17
  72. package/server/bundler/build-applet.ts +35 -44
  73. package/server/cli-env.ts +2 -2
  74. package/server/cli.ts +39 -53
  75. package/server/constants.ts +8 -0
  76. package/server/control-client.ts +124 -0
  77. package/server/control.ts +2 -2
  78. package/server/env-apply.ts +4 -0
  79. package/server/harness/README.md +32 -12
  80. package/server/harness/claude-code/auth.ts +54 -0
  81. package/server/harness/claude-code/index.ts +6 -1
  82. package/server/harness/codex/adapter.ts +9 -1
  83. package/server/harness/codex/auth.ts +50 -0
  84. package/server/harness/codex/index.ts +6 -1
  85. package/server/harness/codex/session.ts +33 -14
  86. package/server/harness/openclaw/NOTES.md +619 -186
  87. package/server/harness/openclaw/adapter.ts +121 -54
  88. package/server/harness/openclaw/compat.ts +95 -0
  89. package/server/harness/openclaw/cron-view.ts +78 -0
  90. package/server/harness/openclaw/discovery.ts +145 -52
  91. package/server/harness/openclaw/gateway.ts +224 -36
  92. package/server/harness/openclaw/index.ts +56 -21
  93. package/server/harness/openclaw/session.ts +1002 -67
  94. package/server/harness/openclaw/strip.ts +71 -23
  95. package/server/harness/openclaw/thinking.ts +150 -0
  96. package/server/harness/types.ts +10 -5
  97. package/server/layout.ts +5 -2
  98. package/server/service.ts +2 -2
  99. package/workspace/.claude/skills/moi-workspace/SKILL.md +6 -6
  100. package/workspace/.claude/skills/moi-workspace/{DESIGN.md → references/DESIGN.md} +19 -9
  101. package/client/features/dev/PixelPainter.tsx +0 -94
  102. package/client/features/dev/PlaygroundPage.tsx +0 -69
  103. package/dist/chunk-0k7brsms.js +0 -9
  104. package/dist/chunk-dfs36zgc.js +0 -1
  105. package/dist/chunk-dtwxpxbg.js +0 -51
  106. package/dist/chunk-ga7t9qsk.js +0 -2
  107. package/dist/chunk-tey2nq7c.js +0 -31
  108. package/dist/chunk-z73xpsa0.js +0 -50
  109. package/dist/chunk-zzgredta.css +0 -1
  110. /package/workspace/.claude/skills/moi-workspace/{SCRATCHPAD.md → references/SCRATCHPAD.md} +0 -0
package/server/cli-env.ts CHANGED
@@ -9,7 +9,7 @@ import type { WorkspaceEntry, WorkspaceEnvView } from '@/lib/types'
9
9
 
10
10
  import pc from './cli-pc'
11
11
  import { columns } from './cli-ui'
12
- import { CONTROL_PORT } from './constants'
12
+ import { CONTROL_URL } from './constants'
13
13
  import { findWorkspaceForPath, listWorkspaces } from './registry'
14
14
  import { discoverDotenvKeys, resolveWorkspaceEnv } from './workspace-env'
15
15
 
@@ -170,7 +170,7 @@ export function notifyEnvChanged(path: string): Promise<boolean> {
170
170
  return new Promise(resolve => {
171
171
  let ws: WebSocket
172
172
  try {
173
- ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
173
+ ws = new WebSocket(CONTROL_URL)
174
174
  } catch {
175
175
  resolve(false)
176
176
  return
package/server/cli.ts CHANGED
@@ -40,7 +40,8 @@ import {
40
40
  resolveCwdWorkspace
41
41
  } from './cli-env'
42
42
  import { columns } from './cli-ui'
43
- import { CONTROL_PORT, PORT } from './constants'
43
+ import { CONTROL_HOST, CONTROL_PORT, CONTROL_URL, PORT } from './constants'
44
+ import { type ControlProbe, controlFailureMessage, probeControlServer } from './control-client'
44
45
  import { type OpenClawAgent, discoverOpenClawAgents } from './harness/openclaw/discovery'
45
46
  import { liftToWorkspaceRoot, registerWorkspace } from './registry'
46
47
  import { serverCwd } from './server-cwd'
@@ -83,22 +84,15 @@ import { provisionWorkspace } from './workspace-init'
83
84
  // ---- helpers ----------------------------------------------------------------
84
85
 
85
86
  async function isServerRunning(): Promise<boolean> {
86
- return new Promise(resolve => {
87
- const ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
88
- const timer = setTimeout(() => {
89
- ws.close()
90
- resolve(false)
91
- }, 600)
92
- ws.onopen = () => {
93
- clearTimeout(timer)
94
- ws.close()
95
- resolve(true)
96
- }
97
- ws.onerror = () => {
98
- clearTimeout(timer)
99
- resolve(false)
100
- }
101
- })
87
+ return (await probeControlServer()).status === 'running'
88
+ }
89
+
90
+ // Print why the control socket could not be opened, then exit. Classifies the
91
+ // failure first, so "no server is listening" and "the server is up but the
92
+ // address is unreachable" no longer read as the same problem.
93
+ async function exitControlUnreachable(): Promise<never> {
94
+ console.error(controlFailureMessage(await probeControlServer()))
95
+ process.exit(1)
102
96
  }
103
97
 
104
98
  async function waitForServer(timeoutMs = 10_000): Promise<boolean> {
@@ -112,7 +106,7 @@ async function waitForServer(timeoutMs = 10_000): Promise<boolean> {
112
106
 
113
107
  async function registerViaControl(absPath: string): Promise<string> {
114
108
  return new Promise((res, rej) => {
115
- const ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
109
+ const ws = new WebSocket(CONTROL_URL)
116
110
  ws.onopen = () => ws.send(JSON.stringify({ type: 'workspace:register', path: absPath }))
117
111
  ws.onmessage = event => {
118
112
  const data = JSON.parse(String(event.data))
@@ -121,7 +115,7 @@ async function registerViaControl(absPath: string): Promise<string> {
121
115
  res(data.id)
122
116
  }
123
117
  }
124
- ws.onerror = () => rej(new Error('Could not connect to control server'))
118
+ ws.onerror = () => void probeControlServer().then(p => rej(new Error(controlFailureMessage(p))))
125
119
  })
126
120
  }
127
121
 
@@ -486,7 +480,7 @@ const bundle = defineCommand({
486
480
  // Computed locally up front so it can ride along in the success output; the
487
481
  // agent reads this and knows to run `moi skill update`.
488
482
  const notice = await staleSkillNotice(path)
489
- const ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
483
+ const ws = new WebSocket(CONTROL_URL)
490
484
 
491
485
  ws.onopen = () =>
492
486
  ws.send(
@@ -567,10 +561,7 @@ const bundle = defineCommand({
567
561
  process.exit(failed.length > 0 ? 1 : 0)
568
562
  }
569
563
 
570
- ws.onerror = () => {
571
- console.error('Could not connect to control server. Is the main process running?')
572
- process.exit(1)
573
- }
564
+ ws.onerror = () => void exitControlUnreachable()
574
565
  }
575
566
  })
576
567
 
@@ -594,7 +585,7 @@ const builderSet = defineCommand({
594
585
  },
595
586
  run({ args }) {
596
587
  const path = resolve(args.dir)
597
- const ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
588
+ const ws = new WebSocket(CONTROL_URL)
598
589
  ws.onopen = () =>
599
590
  ws.send(
600
591
  JSON.stringify({
@@ -625,10 +616,7 @@ const builderSet = defineCommand({
625
616
  ws.close()
626
617
  process.exit(0)
627
618
  }
628
- ws.onerror = () => {
629
- console.error('Could not connect to control server. Is the main process running?')
630
- process.exit(1)
631
- }
619
+ ws.onerror = () => void exitControlUnreachable()
632
620
  }
633
621
  })
634
622
 
@@ -659,7 +647,7 @@ const refresh = defineCommand({
659
647
  process.exit(1)
660
648
  }
661
649
  const notice = await staleSkillNotice(process.cwd())
662
- const ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
650
+ const ws = new WebSocket(CONTROL_URL)
663
651
 
664
652
  ws.onopen = () => ws.send(JSON.stringify({ type: 'applets:refresh', only: args.only }))
665
653
 
@@ -678,10 +666,7 @@ const refresh = defineCommand({
678
666
  process.exit(0)
679
667
  }
680
668
 
681
- ws.onerror = () => {
682
- console.error('Could not connect to control server. Is the main process running?')
683
- process.exit(1)
684
- }
669
+ ws.onerror = () => void exitControlUnreachable()
685
670
  }
686
671
  })
687
672
 
@@ -720,7 +705,7 @@ const theme = defineCommand({
720
705
  async run({ args }) {
721
706
  const path = resolve(args.dir)
722
707
  const notice = await staleSkillNotice(path)
723
- const ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
708
+ const ws = new WebSocket(CONTROL_URL)
724
709
 
725
710
  ws.onopen = () =>
726
711
  ws.send(
@@ -834,10 +819,7 @@ const theme = defineCommand({
834
819
  process.exit(0)
835
820
  }
836
821
 
837
- ws.onerror = () => {
838
- console.error('Could not connect to control server. Is the main process running?')
839
- process.exit(1)
840
- }
822
+ ws.onerror = () => void exitControlUnreachable()
841
823
  }
842
824
  })
843
825
 
@@ -858,15 +840,24 @@ function versionMismatchNotice(serverVersion: string): string | null {
858
840
  const status = defineCommand({
859
841
  meta: { name: 'status', description: 'Show server status and registered workspaces' },
860
842
  async run() {
861
- const running = await isServerRunning()
843
+ const probe: ControlProbe = await probeControlServer()
862
844
  const notice = await staleSkillNotice(process.cwd())
863
845
 
864
- if (!running) {
846
+ if (probe.status === 'not-running') {
865
847
  console.log('\n' + pc.dim('○') + ' Server is ' + pc.bold('not running'))
866
848
  console.log(pc.dim(` cli version ${VERSION}`) + '\n')
867
849
  process.exit(0)
868
850
  }
869
851
 
852
+ // The dial failed for a reason other than an empty port, so the server may
853
+ // be up and healthy. Name the real obstacle instead of blaming the process.
854
+ if (probe.status === 'unreachable') {
855
+ console.log('\n' + pc.yellow('◆') + ' Server is ' + pc.bold('unreachable'))
856
+ console.log(pc.dim(` control port ${CONTROL_HOST}:${CONTROL_PORT} — ${probe.reason}`))
857
+ console.log(pc.dim(` cli version ${VERSION}`) + '\n')
858
+ process.exit(1)
859
+ }
860
+
870
861
  const info = await queryServerInfo()
871
862
  console.log(
872
863
  '\n' +
@@ -890,7 +881,7 @@ const status = defineCommand({
890
881
  if (mismatch) console.log('\n' + mismatch)
891
882
 
892
883
  await new Promise<void>((resolve, reject) => {
893
- const ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
884
+ const ws = new WebSocket(CONTROL_URL)
894
885
 
895
886
  ws.onopen = () => ws.send(JSON.stringify({ type: 'workspace:list' }))
896
887
 
@@ -904,7 +895,8 @@ const status = defineCommand({
904
895
  resolve()
905
896
  }
906
897
 
907
- ws.onerror = () => reject(new Error('Could not connect to control server'))
898
+ ws.onerror = () =>
899
+ void probeControlServer().then(p => reject(new Error(controlFailureMessage(p))))
908
900
  })
909
901
 
910
902
  if (notice) console.log(pc.yellow(notice) + '\n')
@@ -1207,7 +1199,7 @@ async function sendConfig(payload: {
1207
1199
  clearIcon?: boolean
1208
1200
  }) {
1209
1201
  const notice = await staleSkillNotice(payload.path)
1210
- const ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
1202
+ const ws = new WebSocket(CONTROL_URL)
1211
1203
  ws.onopen = () => ws.send(JSON.stringify({ type: 'config', ...payload }))
1212
1204
  ws.onmessage = event => {
1213
1205
  const res = JSON.parse(String(event.data))
@@ -1240,10 +1232,7 @@ async function sendConfig(payload: {
1240
1232
  ws.close()
1241
1233
  process.exit(0)
1242
1234
  }
1243
- ws.onerror = () => {
1244
- console.error('Could not connect to control server. Is the main process running?')
1245
- process.exit(1)
1246
- }
1235
+ ws.onerror = () => void exitControlUnreachable()
1247
1236
  }
1248
1237
 
1249
1238
  // A terse cheat sheet — one line per command — so an agent can grasp the
@@ -1482,7 +1471,7 @@ function sendControl(
1482
1471
  payload: Record<string, unknown>,
1483
1472
  onResult: (res: Record<string, unknown>) => void | Promise<void>
1484
1473
  ) {
1485
- const ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
1474
+ const ws = new WebSocket(CONTROL_URL)
1486
1475
  ws.onopen = () => ws.send(JSON.stringify(payload))
1487
1476
  ws.onmessage = async event => {
1488
1477
  const res = JSON.parse(String(event.data))
@@ -1499,10 +1488,7 @@ function sendControl(
1499
1488
  ws.close()
1500
1489
  process.exit(0)
1501
1490
  }
1502
- ws.onerror = () => {
1503
- console.error('Could not connect to control server. Is the main process running?')
1504
- process.exit(1)
1505
- }
1491
+ ws.onerror = () => void exitControlUnreachable()
1506
1492
  }
1507
1493
 
1508
1494
  function sendScratch(
@@ -1,3 +1,11 @@
1
1
  export const PORT = Number(process.env.PORT) || 13337
2
2
  // M=13, E=5, I=9 -> 13059
3
3
  export const CONTROL_PORT = 13059
4
+ // The address the control server binds AND the one every client dials — never
5
+ // the name `localhost`. Resolution of that name is not guaranteed: container
6
+ // images ship an /etc/hosts without a `localhost` entry (Bun's resolver, unlike
7
+ // glibc, does not special-case it), and where it does resolve it may prefer
8
+ // ::1 while the control server listens on IPv4 only. Bind and dial read this
9
+ // same constant so the two can never drift apart.
10
+ export const CONTROL_HOST = '127.0.0.1'
11
+ export const CONTROL_URL = `ws://${CONTROL_HOST}:${CONTROL_PORT}`
@@ -0,0 +1,124 @@
1
+ import { connect } from 'node:net'
2
+
3
+ import { CONTROL_HOST, CONTROL_PORT, CONTROL_URL } from './constants'
4
+
5
+ // Why the CLI probes the control port instead of just asking "did the socket
6
+ // open?": a failed dial has more than one cause, and they need different
7
+ // answers. Nothing listening means the server is not running (`moi start`).
8
+ // Anything else — the name or address not resolving, the host unreachable, a
9
+ // stranger squatting on the port — means the server may well be running and
10
+ // fine, and the fix is not to restart it. Bun's WebSocket collapses all of
11
+ // these into a single "Failed to connect" error, so the classification is
12
+ // recovered with a second probe at the TCP layer, where the real errno
13
+ // survives (`node:net` reports it; `Bun.connect` reports ECONNREFUSED for
14
+ // everything, so it cannot be used here).
15
+
16
+ export type ControlProbe =
17
+ // A control socket opened — the server is up.
18
+ | { status: 'running' }
19
+ // Connection refused: the port is free, so no server is listening.
20
+ | { status: 'not-running' }
21
+ // Anything else. `reason` names the actual failure for the user.
22
+ | { status: 'unreachable'; reason: string }
23
+
24
+ export type ControlProbeOptions = {
25
+ host?: string
26
+ port?: number
27
+ timeoutMs?: number
28
+ }
29
+
30
+ function closeQuietly(ws: WebSocket): void {
31
+ try {
32
+ ws.close()
33
+ } catch {}
34
+ }
35
+
36
+ // Re-dial the same address at the TCP layer to recover the errno the WebSocket
37
+ // error swallowed. Reaching this means the WebSocket already failed, so a
38
+ // successful TCP connect is itself a finding: something holds the control port
39
+ // but does not speak our protocol.
40
+ function classifyDialFailure(host: string, port: number, timeoutMs: number): Promise<ControlProbe> {
41
+ return new Promise(resolve => {
42
+ let settled = false
43
+ const settle = (probe: ControlProbe) => {
44
+ if (settled) return
45
+ settled = true
46
+ resolve(probe)
47
+ }
48
+ const socket = connect({ host, port })
49
+ socket.setTimeout(timeoutMs)
50
+ socket.on('connect', () => {
51
+ socket.destroy()
52
+ settle({
53
+ status: 'unreachable',
54
+ reason:
55
+ 'the port accepted a connection but refused the control WebSocket — another process may hold it'
56
+ })
57
+ })
58
+ socket.on('timeout', () => {
59
+ socket.destroy()
60
+ settle({ status: 'unreachable', reason: `no answer within ${timeoutMs}ms` })
61
+ })
62
+ socket.on('error', (err: NodeJS.ErrnoException) => {
63
+ socket.destroy()
64
+ if (err.code === 'ECONNREFUSED') {
65
+ settle({ status: 'not-running' })
66
+ return
67
+ }
68
+ if (err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN') {
69
+ settle({ status: 'unreachable', reason: `could not resolve "${host}" (${err.code})` })
70
+ return
71
+ }
72
+ settle({
73
+ status: 'unreachable',
74
+ reason: err.code ?? err.message
75
+ })
76
+ })
77
+ })
78
+ }
79
+
80
+ // Open a control socket and report what happened. The happy path is one
81
+ // WebSocket connect; the extra TCP probe only runs when that fails.
82
+ export function probeControlServer(options: ControlProbeOptions = {}): Promise<ControlProbe> {
83
+ const { host = CONTROL_HOST, port = CONTROL_PORT, timeoutMs = 1500 } = options
84
+ const url = host === CONTROL_HOST && port === CONTROL_PORT ? CONTROL_URL : `ws://${host}:${port}`
85
+ return new Promise(resolve => {
86
+ let settled = false
87
+ const settle = (probe: ControlProbe) => {
88
+ if (settled) return
89
+ settled = true
90
+ resolve(probe)
91
+ }
92
+ let ws: WebSocket
93
+ try {
94
+ ws = new WebSocket(url)
95
+ } catch (err) {
96
+ settle({ status: 'unreachable', reason: err instanceof Error ? err.message : String(err) })
97
+ return
98
+ }
99
+ const timer = setTimeout(() => {
100
+ closeQuietly(ws)
101
+ // A hung dial is not evidence of an absent server — say so rather than
102
+ // reporting it as "not running" the way a bare timeout used to.
103
+ void classifyDialFailure(host, port, timeoutMs).then(settle)
104
+ }, timeoutMs)
105
+ ws.onopen = () => {
106
+ clearTimeout(timer)
107
+ closeQuietly(ws)
108
+ settle({ status: 'running' })
109
+ }
110
+ ws.onerror = () => {
111
+ clearTimeout(timer)
112
+ void classifyDialFailure(host, port, timeoutMs).then(settle)
113
+ }
114
+ })
115
+ }
116
+
117
+ // The one-line explanation the CLI prints when a command could not reach the
118
+ // control server. `running` never reaches here.
119
+ export function controlFailureMessage(probe: ControlProbe): string {
120
+ if (probe.status === 'unreachable') {
121
+ return `Could not reach the control server at ${CONTROL_HOST}:${CONTROL_PORT} — ${probe.reason}. The server may still be running.`
122
+ }
123
+ return 'Could not connect to control server. Is the main process running?'
124
+ }
package/server/control.ts CHANGED
@@ -7,7 +7,7 @@ import { isParamsRecord } from '@/lib/workspace-tabs'
7
7
 
8
8
  import { clearAppletLog, getAppletLog, getAppletLogCount } from './applet-log'
9
9
  import { serializeWorkspaceBundle } from './bundle-queue'
10
- import { CONTROL_PORT, PORT } from './constants'
10
+ import { CONTROL_HOST, CONTROL_PORT, PORT } from './constants'
11
11
  import { applyEnvChanged } from './env-apply'
12
12
  import { callFunctionEphemeral, parseFunctionPath } from './functions'
13
13
  import { processIcon } from './icon'
@@ -63,7 +63,7 @@ async function resolveWorkspace(
63
63
 
64
64
  export const control = Bun.serve({
65
65
  port: CONTROL_PORT,
66
- hostname: '127.0.0.1',
66
+ hostname: CONTROL_HOST,
67
67
  fetch(req, server) {
68
68
  return server.upgrade(req)
69
69
  ? new Response(null, { status: 101 })
@@ -3,6 +3,7 @@
3
3
  // relayed over the control port — the workspace's processes must be reaped and
4
4
  // every connected client told to refetch. Both entry points call this so the
5
5
  // side effects can never drift apart.
6
+ import { agentStore } from './agent'
6
7
  import { publishEvent } from './events'
7
8
  import { restartWorker } from './functions'
8
9
  import { allHarnesses } from './harness/registry'
@@ -12,5 +13,8 @@ export function applyEnvChanged(workspace: { id: string; path: string }): void {
12
13
  // down idle agent sessions (busy ones keep their snapshot until turn end).
13
14
  restartWorker(workspace.path)
14
15
  for (const h of allHarnesses()) h.onEnvChanged?.(workspace.path)
16
+ // Env can carry credentials (ANTHROPIC_API_KEY, provider config) — drop the
17
+ // cached availability so the next agent snapshot re-probes.
18
+ agentStore.invalidate(workspace.id)
15
19
  publishEvent({ type: 'env:updated', workspaceId: workspace.id })
16
20
  }
@@ -118,13 +118,20 @@ Known gaps: runs with `bypassPermissions` only (no interactive approval
118
118
  flow), and effort/streaming changes require a teardown-and-resume because the
119
119
  SDK has no live setter for them.
120
120
 
121
- **OpenClaw — shipped, experimental.** Chat over the local gateway's WebSocket
122
- JSON-RPC: sessions seeded cold from `sessions.get` then updated from live
123
- `session.message` frames, abort via `sessions.abort`, per-turn usage (tokens +
124
- cost) into `TurnMeta`, optimistic user-echo rendezvous (the gateway echoes
125
- sends with lag), uploads materialized to file paths. Known gaps: no
126
- token-delta streaming (durable message rows only — deliberate v2 cut), no
127
- model/effort selection, and the gateway is the sole source of truth (no local
121
+ **OpenClaw — shipped.** Chat over the local gateway's WebSocket JSON-RPC
122
+ (wire protocol 4 — the 2026.7.x and 2026.6.x lines; protocol-3 gateways are
123
+ detected and surfaced, see `openclaw/compat.ts`): sessions seeded cold from
124
+ `sessions.get` then updated from live `session.message` frames (placed by the
125
+ transcript `seq` they carry, so a late row still renders in order), token-delta
126
+ previews from `chat` frames, live tool state + output from the tool stream
127
+ (`session.tool` and `agent`/tool are one payload split by audience — see
128
+ `openclaw/NOTES.md` §6 — and share one handler), run failures surfaced from the
129
+ frames that carry them, model/effort applied per send via `sessions.patch`,
130
+ abort via `sessions.abort`, per-turn usage (tokens + cost) into `TurnMeta`,
131
+ user-echo rendezvous by `<runId>:user` idempotency key (text fallback), uploads
132
+ materialized to file paths. The frame orders a live gateway produces are
133
+ replayed against the real session code by `openclaw/wire-replay.test.ts`. Known gaps: no rich vision blocks (string-only
134
+ `sessions.send`), and the gateway is the sole source of truth (no local
128
135
  persistence; cold restarts re-seed).
129
136
 
130
137
  **Codex — shipped, experimental.** Chat over `codex app-server` (stdio
@@ -148,6 +155,17 @@ approval flow (server→client approval requests are auto-accepted
148
155
  defensively), and images ride inline as data URLs only (no `localImage` path
149
156
  mode).
150
157
 
158
+ Workspace availability also checks provider authentication when a workspace is
159
+ given. Claude Code is probed with `claude auth status` under the effective
160
+ workspace env; `claude auth login` launches its browser sign-in from the composer. Codex
161
+ uses app-server `account/read` and returns a browser OAuth URL through
162
+ `account/login/start`. The server owns the recovery loop (`server/agent.ts`):
163
+ `GET /api/workspaces/:id/agent` serves a cached availability snapshot alongside
164
+ the model catalog, `POST .../auth/login` starts (or joins) the one ceremony per
165
+ workspace, and a server-side watch loop re-probes until the login lands or times
166
+ out, pushing `agent:updated` events to every tab. The composer renders that
167
+ state; it never polls.
168
+
151
169
  ## What a harness adapter must support
152
170
 
153
171
  The checklist below is distilled from what the Claude Code integration
@@ -222,7 +240,9 @@ doubles as the evaluation rubric for new harnesses.
222
240
  - Compaction trigger/observe.
223
241
  - Queued-message semantics: does the backend queue natively or must the
224
242
  server?
225
- - Health/auth status events.
243
+ - Push health/auth status events from the backend itself (the server watch
244
+ loop still discovers login completion by re-probing; a provider callback
245
+ would let `agent:updated` fire without polling anywhere).
226
246
 
227
247
  ## Capability comparison
228
248
 
@@ -234,10 +254,10 @@ Legend: ✅ supported · ⚠️ partial/workaround · ❌ missing.
234
254
  | Queue/steer mid-turn | ⚠️ queued next turn | ⚠️ | ✅ `turn/steer` into live turn |
235
255
  | Resume | ✅ | ✅ | ✅ + fork |
236
256
  | Interrupt | ✅ `interrupt()` | ✅ | ✅ `turn/interrupt` |
237
- | List models | ✅ `supportedModels()` | ❌ | ✅ `model/list` |
238
- | Live model switch | ✅ `setModel()` | ❌ | ✅ per-turn override |
239
- | Live effort switch | ❌ rebuild | ❌ | ✅ per-turn |
240
- | Token deltas | ✅ opt-in | ❌ (v2) | ✅ `item/*/delta` |
257
+ | List models | ✅ `supportedModels()` | ✅ `models.list` | ✅ `model/list` |
258
+ | Live model switch | ✅ `setModel()` | ✅ `sessions.patch` | ✅ per-turn override |
259
+ | Live effort switch | ❌ rebuild | ✅ `thinkingLevel` patch | ✅ per-turn |
260
+ | Token deltas | ✅ opt-in | ✅ `chat` frames | ✅ `item/*/delta` |
241
261
  | Images in input | ✅ base64 blocks | ⚠️ materialize to path | ✅ data URL or path |
242
262
  | Interactive approvals | ⚠️ (we bypass) | ✅ | ✅ server→client requests (we bypass) |
243
263
  | Session list/history API | ✅ `listSessions()` + jsonl | ✅ `sessions.get` | ✅ `thread/list`/`read` |
@@ -0,0 +1,54 @@
1
+ import type { HarnessAvailability, HarnessLogin } from '@/lib/types'
2
+
3
+ import { resolveWorkspaceEnv } from '../../workspace-env'
4
+ import { findHarnessExecutable } from '../executable'
5
+
6
+ function signedOut(reason: string): HarnessAvailability {
7
+ return {
8
+ available: false,
9
+ reason,
10
+ loginCommand: 'claude auth login'
11
+ }
12
+ }
13
+
14
+ // Claude Code 2.1.42+ exposes a stable JSON auth probe. Run it with the same
15
+ // workspace env as the actual Agent SDK subprocess so API-key and enterprise
16
+ // provider configuration are evaluated consistently with the eventual send.
17
+ export async function getClaudeAuthReadiness(workspacePath: string): Promise<HarnessAvailability> {
18
+ const executable = findHarnessExecutable('claude-code')
19
+ if (!executable) return signedOut('Claude is not installed')
20
+
21
+ try {
22
+ const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
23
+ const proc = Bun.spawn([executable, 'auth', 'status'], {
24
+ cwd: workspacePath,
25
+ env: { ...process.env, ...workspaceEnv },
26
+ stdin: 'ignore',
27
+ stdout: 'ignore',
28
+ stderr: 'ignore'
29
+ })
30
+ const timeout = setTimeout(() => proc.kill(), 5_000)
31
+ const exitCode = await proc.exited
32
+ clearTimeout(timeout)
33
+ return exitCode === 0
34
+ ? { available: true }
35
+ : signedOut('Claude is signed out. Sign in to send messages')
36
+ } catch {
37
+ return signedOut('Could not verify the Claude login')
38
+ }
39
+ }
40
+
41
+ export async function startClaudeLogin(workspacePath: string): Promise<HarnessLogin> {
42
+ const executable = findHarnessExecutable('claude-code')
43
+ if (!executable) throw new Error('Claude is not installed')
44
+
45
+ const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
46
+ Bun.spawn([executable, 'auth', 'login'], {
47
+ cwd: workspacePath,
48
+ env: { ...process.env, ...workspaceEnv },
49
+ stdin: 'ignore',
50
+ stdout: 'ignore',
51
+ stderr: 'ignore'
52
+ }).unref()
53
+ return {}
54
+ }
@@ -6,6 +6,7 @@ import type { McpServer } from '@/lib/types'
6
6
 
7
7
  import type { DiscoveredWorkspaceCandidate, Harness } from '../types'
8
8
  import { findHarnessExecutable, pathHarnessAvailability } from '../executable'
9
+ import { getClaudeAuthReadiness, startClaudeLogin } from './auth'
9
10
  import { isLinkedGitWorktree } from './git-worktree'
10
11
  import { getMcpStatus } from './mcp'
11
12
  import { getClaudeModels } from './models'
@@ -96,7 +97,11 @@ export const claudeCodeHarness: Harness = {
96
97
  // fields are ignored by the client) — pass it through unchanged.
97
98
  mcpStatus: async ws => (await getMcpStatus(ws.path)) as unknown as McpServer[],
98
99
  discoverWorkspaces,
99
- availability: async () => pathHarnessAvailability('claude-code'),
100
+ availability: async ws => {
101
+ const runtime = await pathHarnessAvailability('claude-code')
102
+ return runtime.available && ws ? getClaudeAuthReadiness(ws.path) : runtime
103
+ },
104
+ startLogin: ws => startClaudeLogin(ws.path),
100
105
 
101
106
  onEnvChanged: workspacePath => restartWorkspaceSessions(workspacePath),
102
107
  shutdown: () => killAllCCSessions(),
@@ -118,6 +118,11 @@ export type CodexModel = {
118
118
  additionalSpeedTiers?: string[]
119
119
  }
120
120
 
121
+ export function withCodexTurnDuration(turn: Turn, durationMs: number | null | undefined): Turn {
122
+ if (typeof durationMs !== 'number' || !Number.isFinite(durationMs) || durationMs < 0) return turn
123
+ return { ...turn, meta: { ...turn.meta, durationMs } }
124
+ }
125
+
121
126
  // ---- discovery mappings ------------------------------------------------------
122
127
 
123
128
  const CODEX_FAST_SERVICE_TIER = 'priority'
@@ -565,7 +570,10 @@ export function codexThreadToEvents(
565
570
  const part = t.parts.find(p => p.type === 'tool-call')
566
571
  if (sub && part?.type === 'tool-call') part.call.subagent = sub.record
567
572
  }
568
- events.push({ kind: 'turn', turn: t })
573
+ events.push({
574
+ kind: 'turn',
575
+ turn: t.role === 'assistant' ? withCodexTurnDuration(t, turn.durationMs) : t
576
+ })
569
577
  continue
570
578
  }
571
579
  const n = codexItemToNotice(item, thread.id)
@@ -0,0 +1,50 @@
1
+ import type { HarnessAvailability, HarnessLogin } from '@/lib/types'
2
+
3
+ import { getCodexClient } from './client'
4
+
5
+ export type CodexAccountResponse = {
6
+ account: unknown | null
7
+ requiresOpenaiAuth: boolean
8
+ }
9
+
10
+ type CodexLoginResponse = { type: string; authUrl?: string }
11
+
12
+ function needsCodexLogin(reason: string): HarnessAvailability {
13
+ return {
14
+ available: false,
15
+ reason,
16
+ loginCommand: 'codex login'
17
+ }
18
+ }
19
+
20
+ export function codexAccountReadiness(response: CodexAccountResponse): HarnessAvailability {
21
+ // Non-OpenAI model providers can run without a Codex account. For OpenAI,
22
+ // an account object is the app-server's authoritative logged-in signal.
23
+ if (!response.requiresOpenaiAuth || response.account) return { available: true }
24
+ return needsCodexLogin('Codex is signed out. Sign in to send messages')
25
+ }
26
+
27
+ export async function getCodexAuthReadiness(workspacePath: string): Promise<HarnessAvailability> {
28
+ try {
29
+ const client = await getCodexClient(workspacePath)
30
+ const account = await client.rpc<CodexAccountResponse>('account/read', { refreshToken: true })
31
+ return codexAccountReadiness(account)
32
+ } catch {
33
+ return needsCodexLogin('Could not verify the Codex login')
34
+ }
35
+ }
36
+
37
+ export async function startCodexLogin(workspacePath: string): Promise<HarnessLogin> {
38
+ const client = await getCodexClient(workspacePath)
39
+ const login = await client.rpc<CodexLoginResponse>('account/login/start', {
40
+ type: 'chatgpt',
41
+ useHostedLoginSuccessPage: true,
42
+ appBrand: 'codex'
43
+ })
44
+ if (login.type !== 'chatgpt' || !login.authUrl) {
45
+ throw new Error('Codex did not return a browser login URL')
46
+ }
47
+ const url = new URL(login.authUrl)
48
+ if (url.protocol !== 'https:') throw new Error('Codex returned an unsafe login URL')
49
+ return { url: url.toString() }
50
+ }
@@ -2,6 +2,7 @@
2
2
  // ../types.ts for the contract and ../README.md for the architecture.
3
3
  import type { Harness } from '../types'
4
4
  import { findHarnessExecutable, pathHarnessAvailability } from '../executable'
5
+ import { getCodexAuthReadiness, startCodexLogin } from './auth'
5
6
  import {
6
7
  archiveCodexSession,
7
8
  getCodexMcpStatus,
@@ -59,7 +60,11 @@ export const codexHarness: Harness = {
59
60
  listModels: ws => getCodexModels(ws.path),
60
61
  mcpStatus: ws => getCodexMcpStatus(ws.path),
61
62
  discoverWorkspaces: registeredPaths => discoverCodexWorkspaces(registeredPaths),
62
- availability: async () => pathHarnessAvailability('codex'),
63
+ availability: async ws => {
64
+ const runtime = await pathHarnessAvailability('codex')
65
+ return runtime.available && ws ? getCodexAuthReadiness(ws.path) : runtime
66
+ },
67
+ startLogin: ws => startCodexLogin(ws.path),
63
68
 
64
69
  onEnvChanged: workspacePath => killCodexWorkspace(workspacePath),
65
70
  shutdown: () => killAllCodexClients(),