moi-computer 0.3.1-next.0 → 0.4.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 (99) hide show
  1. package/README.md +49 -12
  2. package/client/api/workspace-keys.ts +2 -2
  3. package/client/app/AppRouter.tsx +0 -2
  4. package/client/app/shell/SidebarLayout.tsx +3 -16
  5. package/client/assets/openai.svg +1 -3
  6. package/client/components/shared/Composer.tsx +53 -2
  7. package/client/components/ui/button.tsx +1 -1
  8. package/client/components/ui/tooltip.tsx +12 -15
  9. package/client/features/chat/ChatComposer.tsx +25 -15
  10. package/client/features/chat/ChatPanel.tsx +5 -2
  11. package/client/features/chat/MarkdownContent.tsx +20 -2
  12. package/client/features/chat/ModelPicker.tsx +5 -3
  13. package/client/features/chat/TurnView.tsx +2 -2
  14. package/client/features/chat/chat-frames.ts +13 -6
  15. package/client/features/chat/chat-send.ts +1 -1
  16. package/client/features/chat/chat-store.ts +22 -17
  17. package/client/features/chat/tool-group/ToolOutput.tsx +4 -12
  18. package/client/features/chat/tool-group/format.ts +22 -7
  19. package/client/features/chat/useChat.ts +11 -2
  20. package/client/features/connectors/McpServerCards.tsx +95 -0
  21. package/client/features/connectors/api.ts +0 -11
  22. package/client/features/dev/HarnessDebugPage.tsx +210 -74
  23. package/client/features/home/HomePage.tsx +33 -28
  24. package/client/features/home/api.ts +24 -12
  25. package/client/features/home/workspace-presentation.tsx +17 -15
  26. package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +243 -0
  27. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +95 -0
  28. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +230 -0
  29. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +35 -0
  30. package/client/features/home/workspace-setup/useWorkspaceImport.ts +61 -0
  31. package/client/features/settings/ConnectorsSettings.tsx +89 -0
  32. package/client/features/settings/SettingsLayout.tsx +2 -2
  33. package/client/features/settings/WorkspaceSettings.tsx +8 -4
  34. package/client/features/views/ViewBuilderTab.tsx +19 -15
  35. package/client/features/views/useViewBuilderActions.ts +1 -1
  36. package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -4
  37. package/client/features/workspace/WorkspaceScreen.tsx +11 -3
  38. package/client/features/workspace/api.ts +19 -1
  39. package/client/features/workspace/moi-context.ts +85 -0
  40. package/client/main.tsx +16 -5
  41. package/dist/chunk-19g80zc9.css +1 -0
  42. package/dist/{chunk-jen6xcm1.js → chunk-2vaafjp4.js} +1 -1
  43. package/dist/{chunk-vkvb3hjm.js → chunk-35fq49qa.js} +1 -1
  44. package/dist/chunk-69nhbjhy.js +50 -0
  45. package/dist/{chunk-axszxe4c.js → chunk-72atbmh3.js} +1 -1
  46. package/dist/{chunk-zpxrb1ce.js → chunk-7mkv2gr0.js} +2 -2
  47. package/dist/{chunk-cs8vbert.js → chunk-fh2mf6v9.js} +3 -3
  48. package/dist/chunk-gt7n06ef.js +1 -0
  49. package/dist/chunk-jwmc32rp.js +63 -0
  50. package/dist/chunk-kh24bstm.js +10 -0
  51. package/dist/chunk-sfa4mbmx.js +15 -0
  52. package/dist/index.html +1 -1
  53. package/dist/openai-ep9ht2pq.svg +1 -0
  54. package/lib/ids.ts +15 -0
  55. package/lib/moi-context.ts +170 -0
  56. package/lib/types.ts +29 -11
  57. package/lib/view-builder-directives.ts +16 -0
  58. package/lib/workspace-types.ts +12 -0
  59. package/package.json +2 -1
  60. package/server/api.ts +92 -30
  61. package/server/harness/README.md +25 -9
  62. package/server/harness/claude-code/NOTES.md +20 -6
  63. package/server/harness/claude-code/adapter.ts +2 -2
  64. package/server/harness/claude-code/git-worktree.ts +32 -0
  65. package/server/harness/claude-code/index.ts +33 -12
  66. package/server/harness/claude-code/mcp.ts +16 -65
  67. package/server/harness/claude-code/models.ts +3 -0
  68. package/server/harness/claude-code/session.ts +196 -61
  69. package/server/harness/codex/NOTES.md +41 -11
  70. package/server/harness/codex/adapter.ts +121 -16
  71. package/server/harness/codex/client.ts +67 -18
  72. package/server/harness/codex/discovery.ts +114 -0
  73. package/server/harness/codex/index.ts +10 -5
  74. package/server/harness/codex/probe.ts +4 -2
  75. package/server/harness/codex/session.ts +89 -13
  76. package/server/harness/executable.ts +82 -0
  77. package/server/harness/openclaw/adapter.ts +8 -1
  78. package/server/harness/openclaw/index.ts +8 -14
  79. package/server/harness/openclaw/session.ts +50 -10
  80. package/server/harness/openclaw/strip.ts +2 -2
  81. package/server/harness/shell-path.ts +79 -0
  82. package/server/harness/types.ts +22 -5
  83. package/server/registry.ts +57 -12
  84. package/server/view-builders.ts +3 -2
  85. package/server/web.ts +24 -8
  86. package/server/workspace-import.ts +45 -0
  87. package/workspace/.claude/skills/moi-workspace/SKILL.md +3 -3
  88. package/client/features/connectors/ConnectorsPage.tsx +0 -92
  89. package/client/features/connectors/McpMenu.tsx +0 -145
  90. package/client/features/home/CreateWorkspaceDialog.tsx +0 -130
  91. package/client/features/home/CreateWorkspaceDialogSteps.tsx +0 -234
  92. package/dist/chunk-4vf1t6v1.js +0 -10
  93. package/dist/chunk-6c8cwpzc.js +0 -1
  94. package/dist/chunk-b3ynfk4g.js +0 -62
  95. package/dist/chunk-b4b276wx.js +0 -15
  96. package/dist/chunk-kxmvv1ax.js +0 -48
  97. package/dist/chunk-npwq6jmr.css +0 -1
  98. package/dist/openai-h13pza4b.svg +0 -3
  99. package/lib/view-builder-meta.ts +0 -35
@@ -0,0 +1,89 @@
1
+ import type { ReactNode } from 'react'
2
+
3
+ import { IconPlugConnected } from '@tabler/icons-react'
4
+
5
+ import { Button } from '@/client/components/ui/button'
6
+ import {
7
+ McpServerCard,
8
+ McpServerCardSkeleton,
9
+ McpServerGrid,
10
+ sortMcpServers
11
+ } from '@/client/features/connectors/McpServerCards'
12
+ import { useWorkspaceMcp } from '@/client/features/connectors/api'
13
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
14
+
15
+ import { SettingsPage } from './SettingsLayout'
16
+
17
+ const CONNECTOR_SKELETONS = Array.from({ length: 4 }, (_, index) => index)
18
+
19
+ type ConnectorsContentProps = {
20
+ connectors: ReturnType<typeof useWorkspaceMcp>
21
+ }
22
+
23
+ function ConnectorsContent({ connectors }: ConnectorsContentProps) {
24
+ if (connectors.isPending) {
25
+ return (
26
+ <div role="status" aria-label="Loading connectors">
27
+ <McpServerGrid>
28
+ {CONNECTOR_SKELETONS.map(index => (
29
+ <McpServerCardSkeleton key={index} />
30
+ ))}
31
+ </McpServerGrid>
32
+ </div>
33
+ )
34
+ }
35
+
36
+ if (connectors.isError) {
37
+ return (
38
+ <ConnectorsState>
39
+ <p className="text-sm text-muted-foreground">Could not load connectors.</p>
40
+ <Button variant="outline" size="sm" onClick={() => connectors.refetch()}>
41
+ Retry
42
+ </Button>
43
+ </ConnectorsState>
44
+ )
45
+ }
46
+
47
+ if (connectors.data.length === 0) {
48
+ return (
49
+ <ConnectorsState>
50
+ <IconPlugConnected size={24} stroke={1.5} className="text-muted-foreground" />
51
+ <p className="text-sm text-foreground">No connectors configured.</p>
52
+ </ConnectorsState>
53
+ )
54
+ }
55
+
56
+ return (
57
+ <McpServerGrid>
58
+ {sortMcpServers(connectors.data).map(connector => (
59
+ <McpServerCard key={connector.name} server={connector} />
60
+ ))}
61
+ </McpServerGrid>
62
+ )
63
+ }
64
+
65
+ type ConnectorsStateProps = {
66
+ children: ReactNode
67
+ }
68
+
69
+ function ConnectorsState({ children }: ConnectorsStateProps) {
70
+ return (
71
+ <div className="flex min-h-48 flex-col items-center justify-center gap-3 rounded-xl border border-dashed border-border px-8 py-12 text-center">
72
+ {children}
73
+ </div>
74
+ )
75
+ }
76
+
77
+ export function ConnectorsSettings() {
78
+ const { workspaceId } = useWorkspaceLayoutCtx()
79
+ const connectors = useWorkspaceMcp(workspaceId, true)
80
+
81
+ return (
82
+ <SettingsPage
83
+ title="Connectors"
84
+ description="Connectors available to the agent in this workspace."
85
+ >
86
+ <ConnectorsContent connectors={connectors} />
87
+ </SettingsPage>
88
+ )
89
+ }
@@ -9,8 +9,8 @@ type SettingsPageProps = {
9
9
  export function SettingsPage({ title, description, children }: SettingsPageProps) {
10
10
  return (
11
11
  <div className="flex flex-col gap-6">
12
- <header className="flex flex-col gap-1">
13
- <h2 className="text-xl font-semibold tracking-tight">{title}</h2>
12
+ <header className="flex flex-col gap-0.5">
13
+ <h2 className="text-lg font-medium tracking-tight">{title}</h2>
14
14
  {description && <p className="text-sm text-muted-foreground">{description}</p>}
15
15
  </header>
16
16
  {children}
@@ -1,18 +1,20 @@
1
1
  import { useState } from 'react'
2
2
 
3
- import { IconKey, IconSettings, IconX } from '@tabler/icons-react'
3
+ import { IconKey, IconPlugConnected, IconSettings, IconX } from '@tabler/icons-react'
4
4
 
5
5
  import { Button } from '@/client/components/ui/button'
6
6
  import { Dialog, DialogClose, DialogContent, DialogTitle } from '@/client/components/ui/dialog'
7
7
  import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
8
8
 
9
+ import { ConnectorsSettings } from './ConnectorsSettings'
9
10
  import { EnvironmentSettings } from './EnvironmentSettings'
10
11
  import { GeneralSettings } from './GeneralSettings'
11
12
 
12
- type SettingsNav = 'general' | 'environment'
13
+ type SettingsNav = 'general' | 'connectors' | 'environment'
13
14
 
14
15
  const NAV: { id: SettingsNav; label: string; icon: typeof IconSettings }[] = [
15
16
  { id: 'general', label: 'General', icon: IconSettings },
17
+ { id: 'connectors', label: 'Connectors', icon: IconPlugConnected },
16
18
  { id: 'environment', label: 'Environment', icon: IconKey }
17
19
  ]
18
20
 
@@ -22,7 +24,7 @@ export function WorkspaceSettings() {
22
24
 
23
25
  return (
24
26
  <>
25
- <Tooltip delay={50}>
27
+ <Tooltip>
26
28
  <TooltipTrigger
27
29
  render={
28
30
  <Button
@@ -78,7 +80,9 @@ export function WorkspaceSettings() {
78
80
  }
79
81
  />
80
82
  <div className="px-8 py-7">
81
- {page === 'general' ? <GeneralSettings /> : <EnvironmentSettings />}
83
+ {page === 'general' && <GeneralSettings />}
84
+ {page === 'connectors' && <ConnectorsSettings />}
85
+ {page === 'environment' && <EnvironmentSettings />}
82
86
  </div>
83
87
  </div>
84
88
  </DialogContent>
@@ -1,14 +1,21 @@
1
1
  import { type FormEvent, type KeyboardEvent, useEffect, useRef, useState } from 'react'
2
2
 
3
- import { IconArrowUp, IconLoader2 } from '@tabler/icons-react'
3
+ import { IconLoader2 } from '@tabler/icons-react'
4
4
 
5
5
  import { Button } from '@/client/components/ui/button'
6
- import { Composer, ComposerFooter, ComposerTextarea } from '@/client/components/shared/Composer'
6
+ import {
7
+ canSubmitComposerAction,
8
+ Composer,
9
+ ComposerFooter,
10
+ ComposerSubmitButton,
11
+ ComposerTextarea
12
+ } from '@/client/components/shared/Composer'
7
13
  import { ModelPicker } from '@/client/features/chat/ModelPicker'
8
14
  import type { ViewBuilder } from '@/lib/types'
9
15
 
10
16
  type ViewBuilderTabProps = {
11
17
  builder: ViewBuilder
18
+ unavailableReason: string | null | undefined
12
19
  onSave: (requirements: string) => Promise<unknown>
13
20
  onSubmit: (requirements: string) => Promise<unknown>
14
21
  onOpenChat: () => void
@@ -17,6 +24,7 @@ type ViewBuilderTabProps = {
17
24
 
18
25
  export function ViewBuilderTab({
19
26
  builder,
27
+ unavailableReason,
20
28
  onSave,
21
29
  onSubmit,
22
30
  onOpenChat,
@@ -28,6 +36,8 @@ export function ViewBuilderTab({
28
36
  const composerRef = useRef<HTMLTextAreaElement>(null)
29
37
  const onSaveRef = useRef(onSave)
30
38
  onSaveRef.current = onSave
39
+ const hasRequirements = requirements.trim().length > 0
40
+ const canSubmit = canSubmitComposerAction(hasRequirements, submitting, unavailableReason)
31
41
 
32
42
  useEffect(() => {
33
43
  if (builder.status !== 'draft' || requirements === builder.input.requirements) return
@@ -44,7 +54,7 @@ export function ViewBuilderTab({
44
54
 
45
55
  const submit = async (event: FormEvent) => {
46
56
  event.preventDefault()
47
- if (!requirements.trim() || submitting) return
57
+ if (!canSubmit) return
48
58
  setSubmitting(true)
49
59
  try {
50
60
  await onSubmit(requirements)
@@ -88,18 +98,12 @@ export function ViewBuilderTab({
88
98
  />
89
99
  <ComposerFooter>
90
100
  <ModelPicker scope="workspace" />
91
- <Button
92
- type="submit"
93
- size="icon"
94
- disabled={!requirements.trim() || submitting}
95
- aria-label="Build view"
96
- >
97
- {submitting ? (
98
- <IconLoader2 stroke={1.5} className="animate-spin" />
99
- ) : (
100
- <IconArrowUp stroke={1.5} />
101
- )}
102
- </Button>
101
+ <ComposerSubmitButton
102
+ label="Build view"
103
+ hasContent={hasRequirements}
104
+ loading={submitting}
105
+ unavailableReason={unavailableReason}
106
+ />
103
107
  </ComposerFooter>
104
108
  </Composer>
105
109
  {saveError && (
@@ -54,7 +54,7 @@ export function useViewBuilderActions() {
54
54
  stream
55
55
  })
56
56
  } catch (error) {
57
- liveStore.getState().setProcessing(workspaceId, builder.sessionId, false)
57
+ liveStore.getState().setActivity(workspaceId, builder.sessionId, 'idle')
58
58
  liveStore
59
59
  .getState()
60
60
  .setError(
@@ -23,10 +23,9 @@ type WorkspaceLayoutContextValue = {
23
23
  // Custom workspace icon (base64 data URL), or null to use the provider icon.
24
24
  icon: string | null
25
25
  cwd: string | null
26
- // The agent backend (claude-code / openclaw …). Exposed here so
27
- // components like McpMenu read it from the shared layout query instead of
28
- // spawning their own observer (a second observer that remounts would trigger
29
- // `refetchOnMount` and clobber an in-flight optimistic layout update).
26
+ // The agent backend (claude-code / openclaw …). Exposed here so descendants
27
+ // can reuse the shared layout query instead of spawning another observer
28
+ // that could refetch on mount and clobber an optimistic layout update.
30
29
  provider: WorkspaceType | null
31
30
  // The workspace's registry id (the route param), so descendants can key
32
31
  // their own queries (e.g. the model picker) without prop-drilling.
@@ -14,7 +14,6 @@ import {
14
14
  import { ChatPanel } from '@/client/features/chat/ChatPanel'
15
15
  import { ChatPopup } from '@/client/features/chat/ChatPopup'
16
16
  import { CustomizePanel } from '@/client/features/workspace/CustomizePanel'
17
- import { McpMenu } from '@/client/features/connectors/McpMenu'
18
17
  import { AppletMount } from '@/client/features/applets/AppletMount'
19
18
  import { WidgetErrorBoundary } from '@/client/features/applets/WidgetErrorBoundary'
20
19
  import { Widgets } from '@/client/features/widgets/Widgets'
@@ -28,6 +27,7 @@ import { useView } from '@/client/features/applets/useApplet'
28
27
  import { ViewBuilderTab } from '@/client/features/views/ViewBuilderTab'
29
28
  import { useViewBuilderActions } from '@/client/features/views/useViewBuilderActions'
30
29
  import { useFitsSplitLayout } from '@/client/features/workspace/useFitsSplitLayout'
30
+ import { useWorkspaceAvailability } from '@/client/features/workspace/api'
31
31
  import { useWorkspaceTheme } from '@/client/features/workspace/useWorkspaceTheme'
32
32
  import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
33
33
  import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
@@ -157,7 +157,7 @@ type WorkspaceCustomizeActionProps = {
157
157
 
158
158
  function WorkspaceCustomizeAction({ active, onToggle }: WorkspaceCustomizeActionProps) {
159
159
  return (
160
- <Tooltip delay={50}>
160
+ <Tooltip>
161
161
  <TooltipTrigger
162
162
  render={
163
163
  <Button
@@ -274,6 +274,11 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
274
274
  dismissError
275
275
  } = useChat()
276
276
  const { layout, setLayout, name, icon, provider, workspaceId } = useWorkspaceLayoutCtx()
277
+ // Keep the composer read/write, but block sends when its agent executable is
278
+ // missing. The Send button explains how to install it.
279
+ const availability = useWorkspaceAvailability(workspaceId).data
280
+ const unavailableReason =
281
+ availability === undefined ? undefined : availability.available ? null : availability.reason
277
282
  const builderActions = useViewBuilderActions()
278
283
  const { ref: rowRef, fits: canUseSplit } = useFitsSplitLayout<HTMLDivElement>()
279
284
  const [widgetMode, setWidgetMode] = useState<WidgetMode>('idle')
@@ -524,6 +529,7 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
524
529
  processing={processing}
525
530
  error={error}
526
531
  onDismissError={dismissError}
532
+ unavailableReason={unavailableReason}
527
533
  send={send}
528
534
  stop={stop}
529
535
  onSwitchThread={switchThread}
@@ -540,6 +546,7 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
540
546
  processing={processing}
541
547
  error={error}
542
548
  onDismissError={dismissError}
549
+ unavailableReason={unavailableReason}
543
550
  send={send}
544
551
  stop={stop}
545
552
  onSwitchThread={switchThread}
@@ -588,7 +595,6 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
588
595
  setWidgetMode(widgetMode === 'customizing' ? 'idle' : 'customizing')
589
596
  }
590
597
  />
591
- <McpMenu />
592
598
  <WorkspaceSettings />
593
599
  {hasWorkspaceContent && canUseSplit && (
594
600
  <SectionControls
@@ -616,6 +622,7 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
616
622
  <ViewBuilderTab
617
623
  key={activeBuilder.id}
618
624
  builder={activeBuilder}
625
+ unavailableReason={unavailableReason}
619
626
  onSave={requirements => builderActions.save(activeBuilder.id, requirements)}
620
627
  onSubmit={requirements => {
621
628
  if (mode === 'fullscreen') setFloatingChatOpen(true)
@@ -669,6 +676,7 @@ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenPro
669
676
  processing={processing}
670
677
  error={error}
671
678
  onDismissError={dismissError}
679
+ unavailableReason={unavailableReason}
672
680
  send={send}
673
681
  stop={stop}
674
682
  onSwitchThread={switchThread}
@@ -3,7 +3,13 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
3
3
  import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
4
4
  import { WORKSPACE_RESOURCE_OPTIONS } from '@/client/api/query-options'
5
5
  import { workspaceKeys } from '@/client/api/workspace-keys'
6
- import type { ViewInfo, WidgetInfo, WorkspaceLayout, WorkspaceType } from '@/lib/types'
6
+ import type {
7
+ HarnessAvailability,
8
+ ViewInfo,
9
+ WidgetInfo,
10
+ WorkspaceLayout,
11
+ WorkspaceType
12
+ } from '@/lib/types'
7
13
 
8
14
  export type WorkspaceLayoutResponse = WorkspaceLayout & {
9
15
  cwd: string
@@ -20,6 +26,18 @@ export function useWorkspaceLayout(workspaceId: string) {
20
26
  })
21
27
  }
22
28
 
29
+ // Is the workspace's agent executable installed? Drives the Send button's
30
+ // disabled state and tooltip. Refetches on window focus so installing the
31
+ // missing runtime and returning to the tab unlocks the composer.
32
+ export function useWorkspaceAvailability(workspaceId: string) {
33
+ return useQuery<HarnessAvailability>({
34
+ queryKey: workspaceKeys.availability(workspaceId),
35
+ queryFn: () => requestJson(`/api/workspaces/${workspaceId}/availability`),
36
+ staleTime: 30_000,
37
+ refetchOnWindowFocus: true
38
+ })
39
+ }
40
+
23
41
  export function useWorkspaceWidgets(workspaceId: string) {
24
42
  return useQuery<WidgetInfo[]>({
25
43
  queryKey: workspaceKeys.widgets(workspaceId),
@@ -0,0 +1,85 @@
1
+ // Central assembly of the moi context sent with every chat message — the one
2
+ // place that snapshots the workspace's primary UI state (active tab, view
3
+ // titles) and drains queued one-shot directives. The structured `MoiContext`
4
+ // travels to the server as-is; harnesses render it (lib/moi-context.ts).
5
+ //
6
+ // Quick API:
7
+ //
8
+ // pushChatDirective(workspaceId, 'The user clicked "Sync now" on the stock-ticker widget.')
9
+ // Queue a one-shot instruction from anywhere in the app — event handlers,
10
+ // stores, non-React code. It rides the NEXT chat message's
11
+ // "# This message only" section and is delivered exactly once.
12
+ //
13
+ // useMoiUserMessageContext()
14
+ // Hook for the chat send path: returns a builder that snapshots ambient
15
+ // state (active tab, view title) and drains the directive queue. Call
16
+ // the builder only for a message that actually goes out.
17
+ //
18
+ // Adding a new ambient field (e.g. scratchpad selection): extend the
19
+ // `MoiContext` type and its renderer in lib/moi-context.ts, then supply
20
+ // the field in `useMoiUserMessageContext`'s builder below.
21
+ import { useCallback } from 'react'
22
+
23
+ import { useViewBuilders } from '@/client/features/views/api'
24
+ import { useWorkspaceViews } from '@/client/features/workspace/api'
25
+ import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
26
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
27
+ import type { MoiContext } from '@/lib/moi-context'
28
+ import type { ViewBuilder, ViewInfo, WorkspaceTabId } from '@/lib/types'
29
+
30
+ // One-shot directives queued per workspace, drained into the NEXT chat
31
+ // message's `# This message only` section. Module-level (not React state):
32
+ // contributors may not live under a workspace React tree, and the queue must
33
+ // survive re-renders without causing any.
34
+ const directiveQueues = new Map<string, string[]>()
35
+
36
+ // Queue a one-shot instruction for the next message sent from `workspaceId`.
37
+ // Write a complete sentence; it reaches the agent once and is not re-sent.
38
+ export function pushChatDirective(workspaceId: string, directive: string): void {
39
+ const queue = directiveQueues.get(workspaceId) ?? []
40
+ queue.push(directive)
41
+ directiveQueues.set(workspaceId, queue)
42
+ }
43
+
44
+ // Exported for unit tests; production code drains only via `useMoiUserMessageContext`.
45
+ export function drainChatDirectives(workspaceId: string): string[] {
46
+ const queue = directiveQueues.get(workspaceId) ?? []
47
+ directiveQueues.delete(workspaceId)
48
+ return queue
49
+ }
50
+
51
+ // The UI label of the active tab when it has one beyond its id: a view's
52
+ // configured title, or a builder's claimed title while the build runs.
53
+ // Undefined otherwise (the envelope then falls back to the id, like the tab
54
+ // bar).
55
+ export function activeTabTitle(
56
+ tab: WorkspaceTabId,
57
+ views: ViewInfo[] | undefined,
58
+ builders: ViewBuilder[] | undefined
59
+ ): string | undefined {
60
+ if (tab.startsWith('view:'))
61
+ return views?.find(v => v.id === tab.slice('view:'.length))?.config.title || undefined
62
+ if (tab.startsWith('view-builder:'))
63
+ return builders?.find(b => b.id === tab.slice('view-builder:'.length))?.title || undefined
64
+ return undefined
65
+ }
66
+
67
+ // Returns a builder that snapshots the workspace state at call time — invoke
68
+ // it when the message is actually sent, not at render. Draining the
69
+ // directive queue is part of the snapshot, so only call it for a message
70
+ // that will really go out.
71
+ export function useMoiUserMessageContext(): () => MoiContext {
72
+ const workspaceId = useWorkspaceId()
73
+ const { layout } = useWorkspaceLayoutCtx()
74
+ const views = useWorkspaceViews(workspaceId).data
75
+ const builders = useViewBuilders(workspaceId).data
76
+ const activeTab = layout.tabs.active
77
+ return useCallback(() => {
78
+ const directives = drainChatDirectives(workspaceId)
79
+ return {
80
+ activeTab,
81
+ tabTitle: activeTabTitle(activeTab, views, builders),
82
+ ...(directives.length > 0 ? { directives } : {})
83
+ }
84
+ }, [workspaceId, activeTab, views, builders])
85
+ }
package/client/main.tsx CHANGED
@@ -1,14 +1,23 @@
1
1
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
2
2
  import { Agentation } from 'agentation'
3
3
  import { createRoot } from 'react-dom/client'
4
- import { Router } from 'wouter'
4
+ import { Router, useRoute } from 'wouter'
5
5
 
6
+ import { TooltipProvider } from '@/client/components/ui/tooltip'
6
7
  import { installAppletErrorHook } from '@/client/features/applets/applet-log'
7
8
  import { initConnection } from '@/client/features/chat/chat-connection'
8
9
  import { AppRouter } from './app/AppRouter'
9
10
 
10
11
  const queryClient = new QueryClient()
11
12
 
13
+ // Agentation has no built-in route filter (checked v2.3.3 props), so gate the
14
+ // mount ourselves: the harness debug page is a raw log surface where the
15
+ // annotation toolbar just overlaps the panes.
16
+ function DevAgentation() {
17
+ const [onHarnessDebug] = useRoute('/dev/harness')
18
+ return onHarnessDebug ? null : <Agentation />
19
+ }
20
+
12
21
  // Open the single app-wide chat WebSocket once and hand it the query client so
13
22
  // live frames fold into the RQ transcript cache. Lives for the page's lifetime.
14
23
  initConnection(queryClient)
@@ -22,10 +31,12 @@ export function mount(el: HTMLElement) {
22
31
  function Root() {
23
32
  return (
24
33
  <QueryClientProvider client={queryClient}>
25
- <Router>
26
- <AppRouter />
27
- </Router>
28
- {process.env.NODE_ENV === 'development' && <Agentation />}
34
+ <TooltipProvider>
35
+ <Router>
36
+ <AppRouter />
37
+ </Router>
38
+ {process.env.NODE_ENV === 'development' && <DevAgentation />}
39
+ </TooltipProvider>
29
40
  </QueryClientProvider>
30
41
  )
31
42
  }