moi-computer 0.9.0 → 0.9.1-next.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 (87) hide show
  1. package/client/assets/hermes.png +0 -0
  2. package/client/components/shared/IconGhost.tsx +15 -18
  3. package/client/components/ui/button.tsx +2 -2
  4. package/client/components/ui/hover-card.tsx +1 -1
  5. package/client/components/ui/popover.tsx +3 -1
  6. package/client/features/chat/ChatEmptyState.tsx +25 -7
  7. package/client/features/chat/ChatPanel.tsx +70 -28
  8. package/client/features/chat/ChatPopup.tsx +3 -2
  9. package/client/features/chat/ChatPromptBubbles.tsx +1 -1
  10. package/client/features/chat/MarkdownContent.tsx +1 -1
  11. package/client/features/chat/attachment-staging.ts +153 -0
  12. package/client/features/chat/chat-send.ts +55 -0
  13. package/client/features/chat/chat-store.ts +32 -8
  14. package/client/features/chat/composer/ChatComposer.tsx +190 -77
  15. package/client/features/chat/{ModelPicker.tsx → composer/ModelPicker.tsx} +29 -25
  16. package/client/features/chat/composer/banners/ComposerBanner.tsx +1 -1
  17. package/client/features/chat/composer/banners/WorkspaceAgentAvailabilityBanner.tsx +4 -13
  18. package/client/features/chat/{model-order.ts → composer/model-order.ts} +16 -0
  19. package/client/features/chat/composer/useWorkspaceComposerState.tsx +9 -4
  20. package/client/features/chat/tool-group/format/claude.ts +48 -0
  21. package/client/features/chat/tool-group/format/codex.ts +126 -0
  22. package/client/features/chat/tool-group/format/hermes.ts +68 -0
  23. package/client/features/chat/tool-group/format/index.ts +34 -0
  24. package/client/features/chat/tool-group/format/mcp.ts +64 -0
  25. package/client/features/chat/tool-group/format/openclaw.ts +116 -0
  26. package/client/features/chat/tool-group/format/shared.ts +49 -0
  27. package/client/features/chat/useChat.ts +5 -10
  28. package/client/features/drawings/DrawingLayer.tsx +49 -0
  29. package/client/features/drawings/DrawingToolbar.tsx +95 -0
  30. package/client/features/drawings/annotation-availability.ts +10 -0
  31. package/client/features/drawings/capture-element.ts +45 -0
  32. package/client/features/drawings/useChatAnnotation.ts +222 -0
  33. package/client/features/drawings/useDrawingLayer.ts +758 -0
  34. package/client/features/drawings/useViewBuilderSketch.ts +151 -0
  35. package/client/features/home/workspace-presentation.tsx +6 -2
  36. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +12 -6
  37. package/client/features/scratchpad/ScratchpadControls.tsx +19 -5
  38. package/client/features/views/ViewBuilder.tsx +224 -0
  39. package/client/features/views/api.ts +1 -0
  40. package/client/features/views/useViewBuilderActions.ts +24 -3
  41. package/client/features/views/useViewBuilderDrafts.ts +66 -0
  42. package/client/features/widgets/Widgets.tsx +23 -39
  43. package/client/features/workspace/CustomizePanel.tsx +1 -1
  44. package/client/features/workspace/WorkspaceScreen.tsx +157 -57
  45. package/client/features/workspace/WorkspaceTabs.tsx +3 -3
  46. package/client/features/workspace/useFitsSplitLayout.ts +14 -8
  47. package/client/index.css +8 -0
  48. package/client/store/ui.ts +19 -0
  49. package/client/theme.css +33 -8
  50. package/dist/chunk-3becmq75.js +81 -0
  51. package/dist/{chunk-kkj86722.js → chunk-6w6j9g4b.js} +78 -78
  52. package/dist/{chunk-xeyxk7ep.js → chunk-8ew39cvq.js} +4 -4
  53. package/dist/chunk-c8gtrjwp.js +1 -0
  54. package/dist/{chunk-2vaafjp4.js → chunk-pp62fnxh.js} +1 -1
  55. package/dist/{chunk-35fq49qa.js → chunk-sxc24vfp.js} +1 -1
  56. package/dist/{chunk-3b3rkjet.js → chunk-v964b5g7.js} +1 -1
  57. package/dist/chunk-zx33ts9d.css +1 -0
  58. package/dist/hermes-pznd63x9.png +0 -0
  59. package/dist/index.html +1 -1
  60. package/lib/format.ts +1 -1
  61. package/lib/themes.ts +8 -8
  62. package/lib/types.ts +8 -1
  63. package/lib/workspace-types.ts +2 -1
  64. package/package.json +2 -1
  65. package/server/api.ts +21 -2
  66. package/server/cli.ts +188 -3
  67. package/server/harness/README.md +64 -17
  68. package/server/harness/acp/adapter.ts +220 -0
  69. package/server/harness/acp/archived.ts +88 -0
  70. package/server/harness/acp/client.ts +328 -0
  71. package/server/harness/acp/discovery.ts +130 -0
  72. package/server/harness/acp/run-durations.ts +68 -0
  73. package/server/harness/acp/session.ts +788 -0
  74. package/server/harness/acp/wire.ts +132 -0
  75. package/server/harness/executable.ts +15 -1
  76. package/server/harness/hermes/NOTES.md +815 -0
  77. package/server/harness/hermes/discovery.ts +155 -0
  78. package/server/harness/hermes/index.ts +155 -0
  79. package/server/harness/hermes/models.ts +79 -0
  80. package/server/harness/registry.ts +3 -1
  81. package/server/view-builders.ts +4 -2
  82. package/server/workspace-import.ts +30 -1
  83. package/client/features/chat/tool-group/format.ts +0 -384
  84. package/client/features/views/ViewBuilderTab.tsx +0 -152
  85. package/dist/chunk-gt7n06ef.js +0 -1
  86. package/dist/chunk-ty1sqbmn.js +0 -80
  87. package/dist/chunk-yz6wd5vc.css +0 -1
@@ -0,0 +1,130 @@
1
+ // Session list, model catalog and home-card preview over ACP. Provider-agnostic.
2
+ import type { Model, SessionInfo } from '@/lib/types'
3
+
4
+ import { type AcpProviderConfig, type AcpSpawnContext } from './session'
5
+ import { acpSessionToSessionInfo } from './adapter'
6
+ import { archivedAcpSessions } from './archived'
7
+ import { getAcpClient, peekAcpClient } from './client'
8
+ import type { ListSessionsResponse, AcpModelInfo, AcpModelState, AcpNewSessionResult } from './wire'
9
+ import type { WorkspaceActivityPreview } from '../types'
10
+ import { debug } from '../../debug'
11
+
12
+ const PAGE_LIMIT = 5
13
+
14
+ // Sessions whose recorded cwd is this workspace, newest first. `cwd` filtering
15
+ // and cursor pagination are both server-side in ACP.
16
+ export async function listAcpSessions(
17
+ config: AcpProviderConfig,
18
+ ctx: AcpSpawnContext
19
+ ): Promise<SessionInfo[]> {
20
+ try {
21
+ const client = await getAcpClient(await config.spawn(ctx))
22
+ // Archiving is moi-side (see ./archived.ts) — the backend still lists the
23
+ // chat, so it is filtered here rather than by the agent.
24
+ const archived = await archivedAcpSessions(ctx.workspacePath)
25
+ const out: SessionInfo[] = []
26
+ let cursor: string | undefined
27
+ for (let page = 0; page < PAGE_LIMIT; page++) {
28
+ const res: ListSessionsResponse = await client.rpc('session/list', {
29
+ cwd: ctx.workspacePath,
30
+ ...(cursor ? { cursor } : {})
31
+ })
32
+ for (const entry of res.sessions ?? []) {
33
+ if (entry.sessionId && !archived.has(entry.sessionId)) {
34
+ out.push(acpSessionToSessionInfo(entry))
35
+ }
36
+ }
37
+ if (!res.nextCursor) break
38
+ cursor = res.nextCursor
39
+ }
40
+ return out.sort((a, b) => b.lastModified - a.lastModified)
41
+ } catch (err) {
42
+ debug(`${config.id} session/list failed: ${err instanceof Error ? err.message : String(err)}`)
43
+ return []
44
+ }
45
+ }
46
+
47
+ // Home-page card preview. Peek-only: ACP agents are slow to start (seconds),
48
+ // and this runs for every card on the home screen. With no live process the
49
+ // card simply omits the activity fields until the workspace is opened once.
50
+ export async function acpWorkspacePreview(
51
+ config: AcpProviderConfig,
52
+ ctx: AcpSpawnContext,
53
+ includeFirstUserMessage: boolean
54
+ ): Promise<WorkspaceActivityPreview> {
55
+ const client = await peekAcpClient(ctx.workspacePath)
56
+ if (!client) return {}
57
+ try {
58
+ const res: ListSessionsResponse = await client.rpc('session/list', { cwd: ctx.workspacePath })
59
+ const archived = await archivedAcpSessions(ctx.workspacePath)
60
+ const rows = (res.sessions ?? []).filter(s => s.sessionId && !archived.has(s.sessionId))
61
+ if (rows.length === 0) return {}
62
+ const newest = rows.reduce((a, b) =>
63
+ Date.parse(b.updatedAt ?? '') > Date.parse(a.updatedAt ?? '') ? b : a
64
+ )
65
+ const updated = Date.parse(newest.updatedAt ?? '')
66
+ // The oldest session's title stands in for its first user message — ACP
67
+ // exposes no message preview, and titles are generated from that message.
68
+ const oldest = rows.reduce((a, b) =>
69
+ Date.parse(b.updatedAt ?? '') < Date.parse(a.updatedAt ?? '') ? b : a
70
+ )
71
+ return {
72
+ ...(Number.isNaN(updated) ? {} : { updatedAt: updated }),
73
+ ...(includeFirstUserMessage && oldest.title ? { firstUserMessage: oldest.title } : {})
74
+ }
75
+ } catch {
76
+ return {}
77
+ }
78
+ }
79
+
80
+ // The model catalog arrives inline on `session/new`, so there is no standalone
81
+ // list RPC. Cache it per workspace: creating a session just to read models is
82
+ // wasteful, and an empty session is invisible to `session/list` anyway (agents
83
+ // skip zero-history rows).
84
+ const modelCatalogs = new Map<string, Promise<AcpModelState | undefined>>()
85
+
86
+ export function cacheAcpModelState(workspacePath: string, models: AcpModelState | undefined): void {
87
+ if (models?.availableModels?.length) {
88
+ modelCatalogs.set(workspacePath, Promise.resolve(models))
89
+ }
90
+ }
91
+
92
+ export function clearAcpModelCache(workspacePath: string): void {
93
+ modelCatalogs.delete(workspacePath)
94
+ }
95
+
96
+ export async function listAcpModels(
97
+ config: AcpProviderConfig,
98
+ ctx: AcpSpawnContext
99
+ ): Promise<Model[]> {
100
+ let cached: Promise<AcpModelState | undefined> | undefined = modelCatalogs.get(ctx.workspacePath)
101
+ if (!cached) {
102
+ cached = (async () => {
103
+ const client = await getAcpClient(await config.spawn(ctx))
104
+ const created = await client.rpc<AcpNewSessionResult>('session/new', {
105
+ cwd: ctx.workspacePath,
106
+ mcpServers: []
107
+ })
108
+ return created.models ?? undefined
109
+ })().catch(err => {
110
+ modelCatalogs.delete(ctx.workspacePath)
111
+ throw err
112
+ })
113
+ modelCatalogs.set(ctx.workspacePath, cached)
114
+ }
115
+ const mapModels =
116
+ config.mapModels ??
117
+ ((infos: AcpModelInfo[]): Model[] =>
118
+ infos.map(m => ({
119
+ value: m.modelId,
120
+ displayName: m.name ?? m.modelId,
121
+ ...(m.description ? { description: m.description } : {})
122
+ })))
123
+ try {
124
+ const state = await cached
125
+ return mapModels(state?.availableModels ?? [])
126
+ } catch (err) {
127
+ debug(`${config.id} model catalog failed: ${err instanceof Error ? err.message : String(err)}`)
128
+ return []
129
+ }
130
+ }
@@ -0,0 +1,68 @@
1
+ // Per-run durations for ACP sessions. ACP replays carry no timestamps, so a
2
+ // reloaded chat cannot compute how long each agent run took — but moi owns the
3
+ // prompt lifecycle live (`session/prompt`'s promise IS the run), so it records
4
+ // the durations itself and re-attaches them on replay. Without a recording the
5
+ // label falls back to a plain "Worked".
6
+ //
7
+ // Stored OUTSIDE the workspace in ONE global JSON file in moi's data dir
8
+ // (same choice, shape and locking as ./archived.ts), keyed by workspace path
9
+ // then session id, one entry per prompt run in prompt order:
10
+ // { "<workspacePath>": { "<sessionId>": [12100, 3400, …] } }
11
+ import { mkdir, rename } from 'node:fs/promises'
12
+ import { join } from 'node:path'
13
+
14
+ import { DATA_DIR } from '../../data-dir'
15
+
16
+ type Store = Record<string, Record<string, number[]>>
17
+
18
+ export const DEFAULT_RUN_DURATIONS_PATH = join(DATA_DIR, 'acp-run-durations.json')
19
+
20
+ let storePath = DEFAULT_RUN_DURATIONS_PATH
21
+
22
+ // Test seam: point the store at a scratch file (mirrors setArchivedSessionsPath).
23
+ export function setRunDurationsPath(path: string): void {
24
+ storePath = path
25
+ }
26
+
27
+ async function readStore(): Promise<Store> {
28
+ try {
29
+ const parsed = JSON.parse(await Bun.file(storePath).text())
30
+ return parsed && typeof parsed === 'object' ? (parsed as Store) : {}
31
+ } catch {
32
+ return {}
33
+ }
34
+ }
35
+
36
+ async function writeStore(store: Store): Promise<void> {
37
+ await mkdir(join(storePath, '..'), { recursive: true })
38
+ const tmp = `${storePath}.${process.pid}.tmp`
39
+ await Bun.write(tmp, JSON.stringify(store, null, 2))
40
+ await rename(tmp, storePath)
41
+ }
42
+
43
+ // Serialize read-modify-write so concurrent run completions can't clobber the
44
+ // single shared file.
45
+ let writeChain: Promise<unknown> = Promise.resolve()
46
+ function locked<T>(fn: () => Promise<T>): Promise<T> {
47
+ const run = writeChain.then(fn, fn)
48
+ writeChain = run.catch(() => {})
49
+ return run
50
+ }
51
+
52
+ export async function appendRunDuration(
53
+ workspacePath: string,
54
+ sessionId: string,
55
+ durationMs: number
56
+ ): Promise<void> {
57
+ if (!sessionId || !Number.isFinite(durationMs) || durationMs < 0) return
58
+ await locked(async () => {
59
+ const store = await readStore()
60
+ const sessions = (store[workspacePath] ??= {})
61
+ sessions[sessionId] = [...(sessions[sessionId] ?? []), Math.round(durationMs)]
62
+ await writeStore(store)
63
+ })
64
+ }
65
+
66
+ export async function runDurations(workspacePath: string, sessionId: string): Promise<number[]> {
67
+ return locked(async () => (await readStore())[workspacePath]?.[sessionId] ?? [])
68
+ }