moi-computer 0.3.1-next.0 → 0.3.1-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 (92) hide show
  1. package/client/api/workspace-keys.ts +2 -2
  2. package/client/app/AppRouter.tsx +0 -2
  3. package/client/app/shell/SidebarLayout.tsx +3 -16
  4. package/client/assets/openai.svg +1 -3
  5. package/client/components/shared/Composer.tsx +53 -2
  6. package/client/components/ui/button.tsx +1 -1
  7. package/client/components/ui/tooltip.tsx +12 -15
  8. package/client/features/chat/ChatComposer.tsx +25 -15
  9. package/client/features/chat/ChatPanel.tsx +5 -2
  10. package/client/features/chat/MarkdownContent.tsx +20 -2
  11. package/client/features/chat/ModelPicker.tsx +5 -3
  12. package/client/features/chat/TurnView.tsx +2 -2
  13. package/client/features/chat/chat-frames.ts +13 -6
  14. package/client/features/chat/chat-send.ts +1 -1
  15. package/client/features/chat/chat-store.ts +22 -17
  16. package/client/features/chat/tool-group/ToolOutput.tsx +4 -12
  17. package/client/features/chat/tool-group/format.ts +0 -6
  18. package/client/features/chat/useChat.ts +11 -2
  19. package/client/features/connectors/McpServerCards.tsx +95 -0
  20. package/client/features/connectors/api.ts +0 -11
  21. package/client/features/home/HomePage.tsx +33 -28
  22. package/client/features/home/api.ts +24 -12
  23. package/client/features/home/workspace-presentation.tsx +17 -15
  24. package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +243 -0
  25. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +95 -0
  26. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +230 -0
  27. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +35 -0
  28. package/client/features/home/workspace-setup/useWorkspaceImport.ts +61 -0
  29. package/client/features/settings/ConnectorsSettings.tsx +89 -0
  30. package/client/features/settings/SettingsLayout.tsx +2 -2
  31. package/client/features/settings/WorkspaceSettings.tsx +8 -4
  32. package/client/features/views/ViewBuilderTab.tsx +19 -15
  33. package/client/features/views/useViewBuilderActions.ts +1 -1
  34. package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -4
  35. package/client/features/workspace/WorkspaceScreen.tsx +11 -3
  36. package/client/features/workspace/api.ts +19 -1
  37. package/client/features/workspace/moi-context.ts +85 -0
  38. package/client/main.tsx +7 -4
  39. package/dist/{chunk-cs8vbert.js → chunk-1dfbr7n2.js} +2 -2
  40. package/dist/chunk-339jds4x.js +15 -0
  41. package/dist/chunk-3xsvsnhr.css +1 -0
  42. package/dist/{chunk-zpxrb1ce.js → chunk-anqmsbjt.js} +2 -2
  43. package/dist/chunk-hbvfb6sk.js +63 -0
  44. package/dist/{chunk-kxmvv1ax.js → chunk-qwm5f6qk.js} +1 -1
  45. package/dist/{chunk-axszxe4c.js → chunk-sxbfh73c.js} +1 -1
  46. package/dist/chunk-yp4srgqt.js +10 -0
  47. package/dist/index.html +1 -1
  48. package/dist/openai-ep9ht2pq.svg +1 -0
  49. package/lib/ids.ts +15 -0
  50. package/lib/moi-context.ts +170 -0
  51. package/lib/types.ts +29 -11
  52. package/lib/view-builder-directives.ts +16 -0
  53. package/lib/workspace-types.ts +12 -0
  54. package/package.json +2 -1
  55. package/server/api.ts +92 -30
  56. package/server/harness/README.md +25 -9
  57. package/server/harness/claude-code/NOTES.md +20 -6
  58. package/server/harness/claude-code/adapter.ts +2 -2
  59. package/server/harness/claude-code/git-worktree.ts +32 -0
  60. package/server/harness/claude-code/index.ts +32 -12
  61. package/server/harness/claude-code/mcp.ts +16 -65
  62. package/server/harness/claude-code/models.ts +3 -0
  63. package/server/harness/claude-code/session.ts +196 -61
  64. package/server/harness/codex/NOTES.md +41 -11
  65. package/server/harness/codex/adapter.ts +21 -7
  66. package/server/harness/codex/client.ts +33 -17
  67. package/server/harness/codex/discovery.ts +114 -0
  68. package/server/harness/codex/index.ts +9 -5
  69. package/server/harness/codex/probe.ts +4 -2
  70. package/server/harness/codex/session.ts +57 -5
  71. package/server/harness/executable.ts +82 -0
  72. package/server/harness/openclaw/adapter.ts +8 -1
  73. package/server/harness/openclaw/index.ts +8 -14
  74. package/server/harness/openclaw/session.ts +50 -10
  75. package/server/harness/openclaw/strip.ts +2 -2
  76. package/server/harness/shell-path.ts +79 -0
  77. package/server/harness/types.ts +22 -5
  78. package/server/registry.ts +57 -12
  79. package/server/view-builders.ts +3 -2
  80. package/server/web.ts +24 -8
  81. package/server/workspace-import.ts +45 -0
  82. package/workspace/.claude/skills/moi-workspace/SKILL.md +3 -3
  83. package/client/features/connectors/ConnectorsPage.tsx +0 -92
  84. package/client/features/connectors/McpMenu.tsx +0 -145
  85. package/client/features/home/CreateWorkspaceDialog.tsx +0 -130
  86. package/client/features/home/CreateWorkspaceDialogSteps.tsx +0 -234
  87. package/dist/chunk-4vf1t6v1.js +0 -10
  88. package/dist/chunk-b3ynfk4g.js +0 -62
  89. package/dist/chunk-b4b276wx.js +0 -15
  90. package/dist/chunk-npwq6jmr.css +0 -1
  91. package/dist/openai-h13pza4b.svg +0 -3
  92. package/lib/view-builder-meta.ts +0 -35
@@ -15,7 +15,7 @@ import type {
15
15
  } from '@/lib/format'
16
16
 
17
17
  import { ATTACHMENT_ONLY_PLACEHOLDER, splitAttachmentNote } from '@/lib/attachment-note'
18
- import { stripViewBuilderMeta } from '@/lib/view-builder-meta'
18
+ import { stripMoiContext } from '@/lib/moi-context'
19
19
 
20
20
  // Loose SDK message shape — we don't pull in the full SDK type tree; the
21
21
  // adapter tolerates missing fields. Reference: ./NOTES.md.
@@ -521,7 +521,7 @@ export class ClaudeAdapter {
521
521
  // file chips here — a reloaded bubble matches the live one
522
522
  // instead of leaking temp paths into it.
523
523
  const split = splitAttachmentNote(text)
524
- text = stripViewBuilderMeta(split.text)
524
+ text = stripMoiContext(split.text)
525
525
  for (const f of split.files) {
526
526
  parts.push({
527
527
  type: 'file',
@@ -0,0 +1,32 @@
1
+ // Detecting linked git worktrees so workspace discovery can skip them.
2
+ //
3
+ // Claude Code accumulates session history in every directory an agent ever ran
4
+ // in, including the throwaway checkouts created for worktree-isolated runs.
5
+ // Those derived directories shouldn't surface as importable workspaces in the
6
+ // discovery list, so we filter them out. moi doesn't support running inside a
7
+ // worktree yet — see docs/git-worktrees.md.
8
+ import { readFile } from 'node:fs/promises'
9
+ import { join } from 'node:path'
10
+
11
+ // A linked git worktree stores its `.git` as a *file* (not a directory) whose
12
+ // single line points into the primary repo: `gitdir: /repo/.git/worktrees/<id>`.
13
+ // Return true only for that shape. Submodules also use a `.git` file, but they
14
+ // point into `.git/modules/…`, so keying on the `worktrees` segment leaves
15
+ // submodule checkouts alone.
16
+ export function pointsIntoWorktrees(gitFileContents: string): boolean {
17
+ const match = /^gitdir:\s*(.+?)\s*$/m.exec(gitFileContents)
18
+ if (!match) return false
19
+ return /(?:^|[/\\])\.git[/\\]worktrees[/\\]/.test(match[1])
20
+ }
21
+
22
+ // Whether `dir` is a linked git worktree checkout. A normal repo keeps `.git`
23
+ // as a directory (so `readFile` fails with EISDIR → false); a non-repo has no
24
+ // `.git` at all (ENOENT → false). Any read error is treated as "not a
25
+ // worktree" so discovery fails open rather than hiding real workspaces.
26
+ export async function isLinkedGitWorktree(dir: string): Promise<boolean> {
27
+ try {
28
+ return pointsIntoWorktrees(await readFile(join(dir, '.git'), 'utf8'))
29
+ } catch {
30
+ return false
31
+ }
32
+ }
@@ -2,15 +2,17 @@
2
2
  // ../types.ts for the contract and ../README.md for the architecture.
3
3
  import { join } from 'node:path'
4
4
 
5
- import type { DiscoveredWorkspace, McpServer } from '@/lib/types'
5
+ import type { McpServer } from '@/lib/types'
6
6
 
7
- import type { Harness } from '../types'
7
+ import type { DiscoveredWorkspaceCandidate, Harness } from '../types'
8
+ import { pathHarnessAvailability } from '../executable'
9
+ import { isLinkedGitWorktree } from './git-worktree'
8
10
  import { getMcpStatus } from './mcp'
9
11
  import { getClaudeModels } from './models'
10
12
  import {
11
13
  SESSION_LIMITS,
12
14
  getCCDebugSnapshot,
13
- getCCRunningSessions,
15
+ getCCActiveSessions,
14
16
  interruptCCSession,
15
17
  killAllCCSessions,
16
18
  restartWorkspaceSessions,
@@ -38,7 +40,9 @@ function fmtAgo(ts: number, now: number): string {
38
40
  }
39
41
 
40
42
  // Discover directories with CC session history that aren't registered yet.
41
- async function discoverWorkspaces(registeredPaths: Set<string>): Promise<DiscoveredWorkspace[]> {
43
+ async function discoverWorkspaces(
44
+ registeredPaths: Set<string>
45
+ ): Promise<DiscoveredWorkspaceCandidate[]> {
42
46
  try {
43
47
  const { listSessions } = await import('@anthropic-ai/claude-agent-sdk')
44
48
  const sessions = await listSessions({})
@@ -51,7 +55,13 @@ async function discoverWorkspaces(registeredPaths: Set<string>): Promise<Discove
51
55
  if (info.isDirectory()) paths.add(s.cwd)
52
56
  } catch {}
53
57
  }
54
- return [...paths].map(path => ({ path, type: 'claude-code' as const }))
58
+ // Drop linked git worktrees — throwaway checkouts (e.g. worktree-isolated
59
+ // runs) that shouldn't surface as importable workspaces.
60
+ const candidates = [...paths]
61
+ const worktree = await Promise.all(candidates.map(isLinkedGitWorktree))
62
+ return candidates
63
+ .filter((_, i) => !worktree[i])
64
+ .map(path => ({ path, type: 'claude-code' as const }))
55
65
  } catch {
56
66
  return []
57
67
  }
@@ -69,7 +79,7 @@ export const claudeCodeHarness: Harness = {
69
79
 
70
80
  sendMessage: input => sendCCMessage(input),
71
81
  interrupt: (workspaceId, sessionId) => interruptCCSession(workspaceId, sessionId),
72
- runningSessions: () => getCCRunningSessions(),
82
+ activeSessions: () => getCCActiveSessions(),
73
83
 
74
84
  listSessions: ws => getSessions(ws.path),
75
85
  workspacePreview: (ws, includeFirstUserMessage) =>
@@ -78,8 +88,9 @@ export const claudeCodeHarness: Harness = {
78
88
  listModels: ws => getClaudeModels(ws.path),
79
89
  // The SDK's McpServerStatus is a superset of the UI's McpServer (extra
80
90
  // fields are ignored by the client) — pass it through unchanged.
81
- mcpStatus: async ws => (await getMcpStatus(ws.path, 'project')) as unknown as McpServer[],
91
+ mcpStatus: async ws => (await getMcpStatus(ws.path)) as unknown as McpServer[],
82
92
  discoverWorkspaces,
93
+ availability: async () => pathHarnessAvailability('claude-code'),
83
94
 
84
95
  onEnvChanged: workspacePath => restartWorkspaceSessions(workspacePath),
85
96
  shutdown: () => killAllCCSessions(),
@@ -87,7 +98,7 @@ export const claudeCodeHarness: Harness = {
87
98
 
88
99
  statusLines: now => {
89
100
  const cc = getCCDebugSnapshot()
90
- const busy = cc.sessions.filter(s => s.busy).length
101
+ const busy = cc.sessions.filter(s => s.activity !== 'idle').length
91
102
  const lines = [
92
103
  `live CC sessions ${cc.sessions.length}/${SESSION_LIMITS.maxLive} ` +
93
104
  `(${busy} busy, ${cc.sessions.length - busy} idle, ${cc.aliases} alias${cc.aliases === 1 ? '' : 'es'}, ` +
@@ -99,10 +110,19 @@ export const claudeCodeHarness: Harness = {
99
110
  }
100
111
  // Busiest / most-recently-active first.
101
112
  const sorted = [...cc.sessions].sort(
102
- (a, b) => Number(b.busy) - Number(a.busy) || b.lastActivityAt - a.lastActivityAt
113
+ (a, b) =>
114
+ Number(b.activity !== 'idle') - Number(a.activity !== 'idle') ||
115
+ b.lastActivityAt - a.lastActivityAt
103
116
  )
104
117
  for (const s of sorted) {
105
- const mark = s.busy ? '▶ busy' : s.closed ? '✗ closed' : '○ idle'
118
+ const mark =
119
+ s.activity === 'running'
120
+ ? '▶ busy'
121
+ : s.activity === 'requires-action'
122
+ ? '⏸ input'
123
+ : s.closed
124
+ ? '✗ closed'
125
+ : '○ idle'
106
126
  const bits = [
107
127
  mark.padEnd(8),
108
128
  `ws=${s.workspaceId}`,
@@ -110,13 +130,13 @@ export const claudeCodeHarness: Harness = {
110
130
  `model=${s.model ?? 'default'}`,
111
131
  `effort=${s.effort ?? 'default'}`,
112
132
  `stream=${s.stream ? 'on' : 'off'}`,
113
- `pending=${s.pendingTurns}`,
114
133
  `age=${fmtDuration(now - s.createdAt)}`,
115
134
  `lastActivity=${fmtAgo(s.lastActivityAt, now)}`
116
135
  ]
136
+ if (s.bgTasks > 0) bits.push(`bgTasks=${s.bgTasks}`)
117
137
  if (s.desiredEffort !== s.effort) bits.push(`desiredEffort=${s.desiredEffort ?? 'default'}`)
118
138
  if (s.desiredStream !== s.stream) bits.push(`desiredStream=${s.desiredStream ? 'on' : 'off'}`)
119
- if (!s.busy && !s.hasIdleTimer) bits.push('(no idle timer)')
139
+ if (s.activity === 'idle' && !s.hasIdleTimer) bits.push('(no idle timer)')
120
140
  let line = ' ' + bits.join(' ')
121
141
  if (s.lastUserText) line += `\n last: ${JSON.stringify(s.lastUserText)}`
122
142
  lines.push(line)
@@ -1,14 +1,8 @@
1
1
  import { query } from '@anthropic-ai/claude-agent-sdk'
2
- import type {
3
- McpServerConfig,
4
- McpServerStatus,
5
- SDKUserMessage
6
- } from '@anthropic-ai/claude-agent-sdk'
7
- import { join } from 'path'
2
+ import type { McpServerStatus, SDKUserMessage } from '@anthropic-ai/claude-agent-sdk'
8
3
 
9
4
  import { debugEnabled } from '../../debug'
10
-
11
- export type McpScope = 'user' | 'project'
5
+ import { requireHarnessExecutable } from '../executable'
12
6
 
13
7
  // MCP server status probing. Intentionally decoupled from agent chat runs
14
8
  // (cc-session.ts): connecting to MCP servers and reading their status is a
@@ -38,9 +32,9 @@ function isSettled(status: McpServerStatus[]): boolean {
38
32
  // attention (failed / needs-auth / still-pending) called out by name. The full
39
33
  // per-server dump (every `connected` line too) is opt-in via `moi start --debug`.
40
34
  // `connected`/`disabled` are the boring majority, so they're folded into counts.
41
- function logMcpStatus(scope: McpScope, status: McpServerStatus[]): void {
35
+ function logMcpStatus(status: McpServerStatus[]): void {
42
36
  if (debugEnabled) {
43
- console.log(`[mcp:${scope}]`, status.map(s => `${s.name}:${s.status}`).join(', '))
37
+ console.log('[mcp]', status.map(s => `${s.name}:${s.status}`).join(', '))
44
38
  return
45
39
  }
46
40
  const connected = status.filter(s => s.status === 'connected').length
@@ -49,41 +43,10 @@ function logMcpStatus(scope: McpScope, status: McpServerStatus[]): void {
49
43
  const parts = [`${connected} connected`]
50
44
  if (disabled) parts.push(`${disabled} disabled`)
51
45
  for (const s of attention) parts.push(`${s.status}: ${s.name}`)
52
- console.log(`[mcp:${scope}]`, parts.join(' · '))
53
- }
54
-
55
- function isRecord(value: unknown): value is Record<string, unknown> {
56
- return typeof value === 'object' && value !== null && !Array.isArray(value)
46
+ console.log('[mcp]', parts.join(' · '))
57
47
  }
58
48
 
59
- async function projectMcpServers(workspacePath: string): Promise<Record<string, McpServerConfig>> {
60
- const file = Bun.file(join(workspacePath, '.mcp.json'))
61
- if (!(await file.exists())) return {}
62
-
63
- const parsed = await file.json().catch(() => null)
64
- if (!isRecord(parsed) || !isRecord(parsed.mcpServers)) return {}
65
-
66
- const servers: Record<string, McpServerConfig> = {}
67
- for (const [name, config] of Object.entries(parsed.mcpServers)) {
68
- // The SDK owns the detailed MCP config union; here we only need to confirm
69
- // the project JSON declares an object keyed by server name before passing it
70
- // through unchanged.
71
- if (isRecord(config)) servers[name] = config as unknown as McpServerConfig
72
- }
73
- return servers
74
- }
75
-
76
- async function probeMcpStatus(workspacePath: string, scope: McpScope): Promise<McpServerStatus[]> {
77
- // Known gap, revisit: the project probe covers only `.mcp.json` (strict), and
78
- // the user probe runs from the server's cwd — so servers added via `claude
79
- // mcp add` (user scope) or `.claude/settings(.local).json` never appear in
80
- // the workspace connectors menu, even though chat sessions still load them
81
- // (cc-session runs with settingSources ['user','project']). Surfacing those
82
- // scopes here needs a per-workspace user+project probe without double-listing
83
- // servers across the menu and the /connectors page.
84
- const mcpServers = scope === 'project' ? await projectMcpServers(workspacePath) : undefined
85
- if (scope === 'project' && Object.keys(mcpServers ?? {}).length === 0) return []
86
-
49
+ async function probeMcpStatus(workspacePath: string): Promise<McpServerStatus[]> {
87
50
  // A prompt that never yields keeps the session alive without a model turn.
88
51
  let release!: () => void
89
52
  const done = new Promise<void>(r => (release = r))
@@ -98,9 +61,9 @@ async function probeMcpStatus(workspacePath: string, scope: McpScope): Promise<M
98
61
  prompt: keepAlive(),
99
62
  options: {
100
63
  cwd: workspacePath,
64
+ pathToClaudeCodeExecutable: requireHarnessExecutable('claude-code'),
101
65
  persistSession: false,
102
- settingSources: [scope],
103
- ...(mcpServers && { mcpServers, strictMcpConfig: true }),
66
+ settingSources: ['user', 'project'],
104
67
  env: { ...process.env, CLAUDECODE: undefined }
105
68
  }
106
69
  })
@@ -113,7 +76,7 @@ async function probeMcpStatus(workspacePath: string, scope: McpScope): Promise<M
113
76
  if (isSettled(status)) break
114
77
  await new Promise(r => setTimeout(r, POLL_INTERVAL_MS))
115
78
  }
116
- logMcpStatus(scope, status)
79
+ logMcpStatus(status)
117
80
  return status
118
81
  } finally {
119
82
  release()
@@ -150,33 +113,21 @@ const cache = new Map<string, CacheEntry>()
150
113
  // cheap insurance against parallel probes of the same workspace.
151
114
  const inflight = new Map<string, Promise<McpServerStatus[]>>()
152
115
 
153
- function cacheKey(scope: McpScope, workspacePath: string): string {
154
- return `${scope}:${workspacePath}`
155
- }
156
-
157
- export async function getMcpStatus(
158
- workspacePath: string,
159
- scope: McpScope = 'project'
160
- ): Promise<McpServerStatus[]> {
161
- const key = cacheKey(scope, workspacePath)
162
- const cached = cache.get(key)
116
+ export async function getMcpStatus(workspacePath: string): Promise<McpServerStatus[]> {
117
+ const cached = cache.get(workspacePath)
163
118
  if (cached && cached.expiresAt > Date.now()) return cached.status
164
119
 
165
- const existing = inflight.get(key)
120
+ const existing = inflight.get(workspacePath)
166
121
  if (existing) return existing
167
122
 
168
- const probe = probeMcpStatus(workspacePath, scope)
123
+ const probe = probeMcpStatus(workspacePath)
169
124
  .then(status => {
170
125
  const ttl = ttlFor(status)
171
- if (ttl > 0) cache.set(key, { status, expiresAt: Date.now() + ttl })
126
+ if (ttl > 0) cache.set(workspacePath, { status, expiresAt: Date.now() + ttl })
172
127
  return status
173
128
  })
174
- .finally(() => inflight.delete(key))
129
+ .finally(() => inflight.delete(workspacePath))
175
130
 
176
- inflight.set(key, probe)
131
+ inflight.set(workspacePath, probe)
177
132
  return probe
178
133
  }
179
-
180
- export async function getUserMcpStatus(): Promise<McpServerStatus[]> {
181
- return getMcpStatus(process.cwd(), 'user')
182
- }
@@ -1,6 +1,8 @@
1
1
  import { query } from '@anthropic-ai/claude-agent-sdk'
2
2
  import type { ModelInfo } from '@anthropic-ai/claude-agent-sdk'
3
3
 
4
+ import { requireHarnessExecutable } from '../executable'
5
+
4
6
  // Chat runs live in `cc-session.ts` (streaming-input sessions held per thread).
5
7
  // MCP status probing lives in `mcp.ts`. This module now only probes the agent
6
8
  // backend for the model list — spins up a throwaway `query()` and reads metadata.
@@ -13,6 +15,7 @@ async function fetchClaudeModels(cwd: string): Promise<ModelInfo[]> {
13
15
  prompt: '',
14
16
  options: {
15
17
  cwd,
18
+ pathToClaudeCodeExecutable: requireHarnessExecutable('claude-code'),
16
19
  persistSession: false,
17
20
  settingSources: ['user', 'project'],
18
21
  env: { ...process.env, CLAUDECODE: undefined }