moi-computer 0.4.0 → 0.4.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 (123) hide show
  1. package/README.md +41 -5
  2. package/bin/moi.mjs +11 -0
  3. package/client/api/workspace-keys.ts +1 -0
  4. package/client/app/AppRouter.tsx +5 -1
  5. package/client/app/routes/WorkspaceRoute.tsx +9 -5
  6. package/client/app/shell/SidebarLayout.tsx +9 -7
  7. package/client/components/shared/BottomPanel.tsx +24 -5
  8. package/client/components/shared/Composer.tsx +1 -1
  9. package/client/components/shared/PanelHeader.tsx +1 -1
  10. package/client/components/ui/button.tsx +5 -5
  11. package/client/components/ui/dropdown-menu.tsx +6 -6
  12. package/client/components/ui/hover-card.tsx +1 -1
  13. package/client/components/ui/input.tsx +1 -1
  14. package/client/components/ui/popover.tsx +1 -1
  15. package/client/components/ui/skeleton.tsx +1 -1
  16. package/client/components/ui/textarea.tsx +1 -1
  17. package/client/components/ui/tooltip.tsx +1 -1
  18. package/client/features/applets/applet-cache.ts +20 -1
  19. package/client/features/applets/applet-log.ts +10 -30
  20. package/client/features/applets/applet-runtime.ts +272 -0
  21. package/client/features/applets/useApplet.ts +36 -10
  22. package/client/features/chat/ChatComposer.tsx +1 -1
  23. package/client/features/chat/ChatEmptyState.tsx +186 -0
  24. package/client/features/chat/ChatPanel.tsx +95 -54
  25. package/client/features/chat/ChatPopup.tsx +3 -13
  26. package/client/features/chat/ChatPromptBubbles.tsx +74 -0
  27. package/client/features/chat/MarkdownContent.tsx +15 -3
  28. package/client/features/chat/ModelPicker.tsx +1 -1
  29. package/client/features/chat/TurnView.tsx +6 -17
  30. package/client/features/chat/chat-send.ts +26 -1
  31. package/client/features/chat/tool-group/CodeBlock.tsx +1 -1
  32. package/client/features/chat/tool-group/ReadImagePreview.tsx +1 -1
  33. package/client/features/chat/tool-group/SubagentCard.tsx +1 -1
  34. package/client/features/chat/tool-group/TimelineRow.tsx +4 -4
  35. package/client/features/chat/tool-group/ToolCallGroup.tsx +12 -5
  36. package/client/features/chat/tool-group/ToolOutput.tsx +2 -2
  37. package/client/features/chat/tool-group/format.ts +3 -3
  38. package/client/features/chat/useAppletChatMessage.ts +69 -0
  39. package/client/features/chat/useChat.ts +49 -14
  40. package/client/features/chat/useStickToBottom.ts +11 -1
  41. package/client/features/connectors/McpServerCards.tsx +3 -3
  42. package/client/features/dev/HarnessDebugPage.tsx +4 -4
  43. package/client/features/dev/PixelPainter.tsx +1 -1
  44. package/client/features/dev/PlaygroundPage.tsx +1 -1
  45. package/client/features/dev/ToolCallsPage.tsx +2 -2
  46. package/client/features/home/HomePage.tsx +17 -14
  47. package/client/features/home/WorkspacePreview.tsx +12 -13
  48. package/client/features/home/api.ts +8 -5
  49. package/client/features/home/workspace-presentation.tsx +1 -1
  50. package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +1 -1
  51. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +21 -8
  52. package/client/features/scratchpad/Scratchpad.tsx +41 -2
  53. package/client/features/scratchpad/ScratchpadControls.tsx +13 -13
  54. package/client/features/scratchpad/useScratchpadSnapshot.tsx +1 -1
  55. package/client/features/settings/EnvironmentSettings.tsx +1 -1
  56. package/client/features/settings/IconPicker.tsx +11 -11
  57. package/client/features/settings/SettingsLayout.tsx +1 -1
  58. package/client/features/settings/WorkspaceSettings.tsx +2 -2
  59. package/client/features/settings/api.ts +33 -1
  60. package/client/features/widgets/HiddenPanel.tsx +4 -3
  61. package/client/features/widgets/Widgets.tsx +1 -0
  62. package/client/features/workspace/CustomizePanel.tsx +96 -82
  63. package/client/features/workspace/WorkspaceScreen.tsx +129 -107
  64. package/client/features/workspace/WorkspaceSkillUpdateBanner.tsx +91 -0
  65. package/client/features/workspace/WorkspaceTabs.tsx +1 -1
  66. package/client/features/workspace/api.ts +52 -0
  67. package/client/features/workspace/moi-context.ts +63 -17
  68. package/client/features/workspace/tab-resolution.ts +75 -0
  69. package/client/features/workspace/useWorkspaceNavigation.ts +128 -0
  70. package/client/features/workspace/useWorkspaceSkillUpdates.ts +160 -0
  71. package/client/index.css +10 -15
  72. package/client/lib/app-icon-registry.ts +77 -70
  73. package/client/lib/rate-limit.ts +77 -0
  74. package/client/runtime/useWorkspaceEvents.ts +15 -2
  75. package/client/runtime/workspace-theme.ts +115 -0
  76. package/client/store/ui.ts +42 -17
  77. package/client/theme.css +20 -15
  78. package/dist/{chunk-fh2mf6v9.js → chunk-3m1xe1j3.js} +94 -94
  79. package/dist/chunk-5vaevt8z.js +2 -0
  80. package/dist/{chunk-69nhbjhy.js → chunk-7bzpmtxp.js} +4 -4
  81. package/dist/chunk-h0hk61pm.js +9 -0
  82. package/dist/{chunk-35fq49qa.js → chunk-h3evrtyp.js} +1 -1
  83. package/dist/chunk-k5sjx9s5.js +1 -0
  84. package/dist/{chunk-2vaafjp4.js → chunk-m9qja0nx.js} +1 -1
  85. package/dist/chunk-s7za1qsv.css +1 -0
  86. package/dist/{chunk-72atbmh3.js → chunk-tcfa3vt3.js} +1 -1
  87. package/dist/chunk-v797g6ap.js +51 -0
  88. package/dist/chunk-xyrw8318.js +27 -0
  89. package/dist/index.html +1 -1
  90. package/lib/app-icons.ts +73 -0
  91. package/lib/moi-context.ts +104 -3
  92. package/lib/themes.ts +83 -45
  93. package/lib/types.ts +44 -9
  94. package/lib/workspace-tabs.ts +48 -0
  95. package/package.json +4 -1
  96. package/server/api.ts +57 -5
  97. package/server/app-settings.ts +65 -0
  98. package/server/applets.ts +132 -22
  99. package/server/bundler/build-applet.ts +74 -16
  100. package/server/cli.ts +144 -17
  101. package/server/control.ts +53 -7
  102. package/server/data-dir.ts +1 -1
  103. package/server/events.ts +1 -1
  104. package/server/functions-worker.ts +15 -1
  105. package/server/functions.ts +51 -6
  106. package/server/layout.ts +9 -14
  107. package/server/moi-scaffold.ts +37 -3
  108. package/server/registry.ts +1 -1
  109. package/server/skill-update.ts +47 -0
  110. package/server/skill-version.ts +2 -11
  111. package/server/tabs.ts +59 -0
  112. package/server/theme.ts +8 -14
  113. package/server/view-builders.ts +6 -2
  114. package/workspace/.claude/skills/moi-workspace/DESIGN.md +265 -107
  115. package/workspace/.claude/skills/moi-workspace/SKILL.md +85 -11
  116. package/client/features/workspace/useWorkspaceTheme.ts +0 -82
  117. package/dist/chunk-19g80zc9.css +0 -1
  118. package/dist/chunk-7mkv2gr0.js +0 -2
  119. package/dist/chunk-gt7n06ef.js +0 -1
  120. package/dist/chunk-jwmc32rp.js +0 -63
  121. package/dist/chunk-kh24bstm.js +0 -10
  122. package/dist/chunk-sfa4mbmx.js +0 -15
  123. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +0 -22
@@ -10,10 +10,13 @@
10
10
  // stores, non-React code. It rides the NEXT chat message's
11
11
  // "# This message only" section and is delivered exactly once.
12
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.
13
+ // useMoiUserMessageContext({ activeTab, appletParams })
14
+ // Hook for the chat send path: takes the workspace's live tab address
15
+ // (from useWorkspaceNavigation, threaded through useChat) and returns a
16
+ // builder that resolves the tab's title and params, drains the directive
17
+ // queue, and accepts per-message extras — directives, and the applet
18
+ // attribution when the message came from applet UI rather than the
19
+ // composer. Call the builder only for a message that actually goes out.
17
20
  //
18
21
  // Adding a new ambient field (e.g. scratchpad selection): extend the
19
22
  // `MoiContext` type and its renderer in lib/moi-context.ts, then supply
@@ -23,8 +26,7 @@ import { useCallback } from 'react'
23
26
  import { useViewBuilders } from '@/client/features/views/api'
24
27
  import { useWorkspaceViews } from '@/client/features/workspace/api'
25
28
  import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
26
- import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
27
- import type { MoiContext } from '@/lib/moi-context'
29
+ import type { MoiAppletMessage, MoiContext } from '@/lib/moi-context'
28
30
  import type { ViewBuilder, ViewInfo, WorkspaceTabId } from '@/lib/types'
29
31
 
30
32
  // One-shot directives queued per workspace, drained into the NEXT chat
@@ -48,6 +50,35 @@ export function drainChatDirectives(workspaceId: string): string[] {
48
50
  return queue
49
51
  }
50
52
 
53
+ // Drain queued directives and append instructions explicitly attached to the
54
+ // message being sent. Keeping the latter out of the queue ties them to that
55
+ // exact send while preserving queued directives from other UI actions.
56
+ export function takeChatDirectives(
57
+ workspaceId: string,
58
+ messageDirectives: readonly string[] = []
59
+ ): string[] {
60
+ return [...drainChatDirectives(workspaceId), ...messageDirectives]
61
+ }
62
+
63
+ // The workspace's live tab address, owned by useWorkspaceNavigation and passed
64
+ // down through useChat. The URL is the truth for which tab is active, and
65
+ // navigation state is the truth for what the view is rendering with.
66
+ export type WorkspaceTabAddress = {
67
+ activeTab: WorkspaceTabId
68
+ appletParams: Record<string, unknown>
69
+ }
70
+
71
+ // The params the envelope should report, or undefined when there are none
72
+ // worth reporting: views are the only tabs with addressable state, and an
73
+ // empty record says nothing.
74
+ export function envelopeTabParams(
75
+ activeTab: WorkspaceTabId,
76
+ appletParams: Record<string, unknown>
77
+ ): Record<string, unknown> | undefined {
78
+ if (!activeTab.startsWith('view:')) return undefined
79
+ return Object.keys(appletParams).length > 0 ? appletParams : undefined
80
+ }
81
+
51
82
  // The UI label of the active tab when it has one beyond its id: a view's
52
83
  // configured title, or a builder's claimed title while the build runs.
53
84
  // Undefined otherwise (the envelope then falls back to the id, like the tab
@@ -64,22 +95,37 @@ export function activeTabTitle(
64
95
  return undefined
65
96
  }
66
97
 
98
+ // Per-message extras the send path supplies — everything else in the envelope
99
+ // is ambient state the builder snapshots for itself.
100
+ export type MoiUserMessageOptions = {
101
+ directives?: readonly string[]
102
+ // Present when applet UI sent this message instead of the user typing it.
103
+ applet?: MoiAppletMessage
104
+ }
105
+
67
106
  // Returns a builder that snapshots the workspace state at call time — invoke
68
107
  // it when the message is actually sent, not at render. Draining the
69
108
  // directive queue is part of the snapshot, so only call it for a message
70
109
  // that will really go out.
71
- export function useMoiUserMessageContext(): () => MoiContext {
110
+ export function useMoiUserMessageContext({
111
+ activeTab,
112
+ appletParams
113
+ }: WorkspaceTabAddress): (options?: MoiUserMessageOptions) => MoiContext {
72
114
  const workspaceId = useWorkspaceId()
73
- const { layout } = useWorkspaceLayoutCtx()
74
115
  const views = useWorkspaceViews(workspaceId).data
75
116
  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])
117
+ return useCallback(
118
+ (options: MoiUserMessageOptions = {}) => {
119
+ const directives = takeChatDirectives(workspaceId, options.directives ?? [])
120
+ const tabParams = envelopeTabParams(activeTab, appletParams)
121
+ return {
122
+ activeTab,
123
+ tabTitle: activeTabTitle(activeTab, views, builders),
124
+ ...(tabParams ? { tabParams } : {}),
125
+ ...(options.applet ? { applet: options.applet } : {}),
126
+ ...(directives.length > 0 ? { directives } : {})
127
+ }
128
+ },
129
+ [workspaceId, activeTab, appletParams, views, builders]
130
+ )
85
131
  }
@@ -0,0 +1,75 @@
1
+ // Pure tab-state derivation for the workspace screen. The URL is the live
2
+ // truth for the active tab (`/workspace/:id/<tab>`); the persisted layout
3
+ // keeps the open set and the saved DEFAULT tab (`tabs.active`). These helpers
4
+ // turn (URL segment + layout + what actually exists) into the rendered state.
5
+ import type { ViewBuilder, ViewInfo, WorkspaceTabId, WorkspaceTabsState } from '@/lib/types'
6
+ import { parseWorkspaceTab, viewBuilderIdFromTab, viewIdFromTab } from '@/lib/workspace-tabs'
7
+ import { createDefaultWorkspaceTabs } from '@/lib/workspace-layout'
8
+
9
+ const DEFAULT_TABS = createDefaultWorkspaceTabs()
10
+
11
+ export function normalizeTabsState(tabs: WorkspaceTabsState | undefined): WorkspaceTabsState {
12
+ if (!tabs || !Array.isArray(tabs.open)) return DEFAULT_TABS
13
+ const open = tabs.open.filter((tab, index, all) => all.indexOf(tab) === index)
14
+ if (open.length === 0) return DEFAULT_TABS
15
+ return { open, active: open.includes(tabs.active) ? tabs.active : open[0] }
16
+ }
17
+
18
+ // Whether a tab id points at something that exists: static tabs always do,
19
+ // view/builder tabs only while their view or builder is around.
20
+ export function tabAvailable(tab: WorkspaceTabId, views: ViewInfo[], builders: ViewBuilder[]) {
21
+ if (tab === 'agent' || tab === 'widgets' || tab === 'scratchpad') return true
22
+ const builderId = viewBuilderIdFromTab(tab)
23
+ if (builderId) return builders.some(builder => builder.id === builderId)
24
+ const viewId = viewIdFromTab(tab)
25
+ return viewId ? views.some(v => v.id === viewId) : false
26
+ }
27
+
28
+ // The effective open set: persisted open tabs filtered to what exists, falling
29
+ // back to the defaults when nothing survives.
30
+ export function effectiveOpenTabs(
31
+ tabs: WorkspaceTabsState,
32
+ views: ViewInfo[],
33
+ builders: ViewBuilder[]
34
+ ): WorkspaceTabId[] {
35
+ const open = tabs.open.filter(tab => tabAvailable(tab, views, builders))
36
+ return open.length > 0 ? open : DEFAULT_TABS.open
37
+ }
38
+
39
+ // Whether a URL segment that lost its redirect is worth reporting as a stale
40
+ // link (see the journaling in useWorkspaceNavigation). Only two shapes qualify:
41
+ // a view tab — `resolveActiveTab` honors every view that exists, so losing the
42
+ // redirect means it is gone — and a segment that isn't a tab id at all. The two
43
+ // deliberate exclusions are the routine redirects, not broken links: the agent
44
+ // tab bounces whenever split mode docks it as a column, and a view-builder tab
45
+ // bounces the moment its build finishes and the screen swaps in the real view.
46
+ export function isStaleTabLink(urlTab: string | null | undefined): urlTab is string {
47
+ if (!urlTab) return false
48
+ const requested = parseWorkspaceTab(urlTab)
49
+ return requested === null || viewIdFromTab(requested) !== null
50
+ }
51
+
52
+ // The active tab for a URL-requested tab id: the request wins when it names an
53
+ // available tab (a requested tab missing from the open set is honored — the
54
+ // screen auto-adds it, like openTab does), EXCEPT the agent tab in split mode,
55
+ // which is the docked column there, not a workspace tab. Anything else — bare
56
+ // URL, unknown or unavailable tab — resolves to the saved default run through
57
+ // the same availability fallbacks as before.
58
+ export function resolveActiveTab(
59
+ requested: WorkspaceTabId | null,
60
+ tabs: WorkspaceTabsState,
61
+ views: ViewInfo[],
62
+ builders: ViewBuilder[],
63
+ split: boolean
64
+ ): WorkspaceTabId {
65
+ if (
66
+ requested !== null &&
67
+ tabAvailable(requested, views, builders) &&
68
+ !(split && requested === 'agent')
69
+ ) {
70
+ return requested
71
+ }
72
+ const open = effectiveOpenTabs(tabs, views, builders)
73
+ const visible = split ? open.filter(tab => tab !== 'agent') : open
74
+ return visible.includes(tabs.active) ? tabs.active : (visible[0] ?? 'agent')
75
+ }
@@ -0,0 +1,128 @@
1
+ // The workspace's tab address: which tab the URL names, how to navigate
2
+ // elsewhere, and the persistence that keeps a bare `/workspace/:id` landing
3
+ // somewhere sensible. The URL is the live truth for the active tab; the
4
+ // persisted layout keeps the open set and the saved DEFAULT (`tabs.active`).
5
+ //
6
+ // Everything that merely reacts to navigation stays with the screen: tab-bar
7
+ // policy (close, reorder, availability pruning), view-builder lifecycle, the
8
+ // applet-runtime `focusTab` subscription, and the `moi tab focus` subscription.
9
+ // They all route through the `navigateToTab` returned here, so every origin —
10
+ // tab click, applet, CLI — shares one code path.
11
+ import { useCallback, useEffect, useMemo, useRef } from 'react'
12
+
13
+ import { useLocation, useParams } from 'wouter'
14
+ import { useHistoryState } from 'wouter/use-browser-location'
15
+
16
+ import { reportAppletError } from '@/client/features/applets/applet-log'
17
+ import {
18
+ isStaleTabLink,
19
+ normalizeTabsState,
20
+ resolveActiveTab
21
+ } from '@/client/features/workspace/tab-resolution'
22
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
23
+ import type { ViewBuilder, ViewInfo, WorkspaceTabId, WorkspaceTabsState } from '@/lib/types'
24
+ import {
25
+ parseWorkspaceTab,
26
+ readAppletParams,
27
+ viewIdFromTab,
28
+ workspaceTabPath
29
+ } from '@/lib/workspace-tabs'
30
+
31
+ type UseWorkspaceNavigationOptions = {
32
+ // What exists right now — a URL naming anything else falls back to the
33
+ // default, the same way a stale bookmark does.
34
+ views: ViewInfo[]
35
+ builders: ViewBuilder[]
36
+ // Split mode docks the chat in its own column, so the agent tab is not a
37
+ // navigable tab there.
38
+ split: boolean
39
+ }
40
+
41
+ export function useWorkspaceNavigation({ views, builders, split }: UseWorkspaceNavigationOptions) {
42
+ const { layout, setLayout, workspaceId } = useWorkspaceLayoutCtx()
43
+ const [, navigate] = useLocation()
44
+ // The tab id is the route's wildcard segment, read from the matched route
45
+ // instead of threaded down as a prop — so the pattern stays in AppRouter and
46
+ // can't drift from a second copy here.
47
+ const urlTab = useParams()['*'] ?? null
48
+ // Applet params ride navigation state; anything malformed reads as {}. A
49
+ // stateless navigation (plain tab click) clears it, so views mount empty.
50
+ const historyState = useHistoryState<unknown>()
51
+ const appletParams = useMemo(() => readAppletParams(historyState), [historyState])
52
+
53
+ const tabsState = normalizeTabsState(layout.tabs)
54
+ // Mirror for the effects below: a debounced layout PUT can still be in flight
55
+ // when a `workspace:updated` refetch lands, so reading the render-time value
56
+ // could persist a stale open set (and resurrect a just-closed tab).
57
+ const tabsStateRef = useRef(tabsState)
58
+ tabsStateRef.current = tabsState
59
+
60
+ const requestedTab = parseWorkspaceTab(urlTab)
61
+ const activeTab = resolveActiveTab(requestedTab, tabsState, views, builders, split)
62
+ const urlTabHonored = requestedTab !== null && requestedTab === activeTab
63
+
64
+ // Every tab switch is a replace-navigation — never push, so Back leaves the
65
+ // workspace instead of walking tab history.
66
+ const navigateToTab = useCallback(
67
+ (tab: WorkspaceTabId, params?: Record<string, unknown>) => {
68
+ navigate(workspaceTabPath(workspaceId, tab), {
69
+ replace: true,
70
+ // Only a focus navigation carries params; omitting the key clears
71
+ // history state, which is how a plain tab click resets them.
72
+ ...(params ? { state: { appletParams: params } } : {})
73
+ })
74
+ },
75
+ [navigate, workspaceId]
76
+ )
77
+
78
+ const setTabs = useCallback(
79
+ (tabs: WorkspaceTabsState) => {
80
+ tabsStateRef.current = tabs
81
+ setLayout({ tabs })
82
+ },
83
+ [setLayout]
84
+ )
85
+
86
+ // Keep the URL honest. One redirect covers every case: a bare
87
+ // /workspace/:id, an unknown or dead tab, and the agent tab while split mode
88
+ // hides it.
89
+ useEffect(() => {
90
+ if (urlTab === activeTab) return
91
+ // A URL that named a view and didn't get it is a stale link — a deleted
92
+ // view, an old bookmark, a `focusTab` the agent wrote against a view it
93
+ // later renamed. The agent can't see the redirect happen, so journal it
94
+ // for `moi debug logs`.
95
+ if (isStaleTabLink(urlTab)) reportDeadTab(workspaceId, urlTab, activeTab)
96
+ navigateToTab(activeTab)
97
+ }, [activeTab, navigateToTab, urlTab, workspaceId])
98
+
99
+ // Navigating IS the tab switch, so persist its effects through the same write
100
+ // path as before: the saved default follows the URL, and a URL-navigated tab
101
+ // missing from the open set is auto-added. Only an honored URL writes —
102
+ // redirects settle into an honored URL first, which is what stops this and
103
+ // the redirect effect above from ping-ponging.
104
+ useEffect(() => {
105
+ if (!urlTabHonored) return
106
+ const current = tabsStateRef.current
107
+ const open = current.open.includes(activeTab) ? current.open : [...current.open, activeTab]
108
+ if (open === current.open && current.active === activeTab) return
109
+ setTabs({ open, active: activeTab })
110
+ }, [activeTab, setTabs, urlTabHonored])
111
+
112
+ return { tabsState, activeTab, appletParams, navigateToTab, setTabs }
113
+ }
114
+
115
+ // Journal a stale link (see `isStaleTabLink` for which URLs qualify).
116
+ // Attributed to the view when the dead id names one — that's the file the agent
117
+ // would fix, and the entry then clears the moment a view by that name builds.
118
+ // A malformed segment names no applet and lands unattributed. The journal's own
119
+ // dedup keeps a redirect loop to a single line.
120
+ function reportDeadTab(workspaceId: string, urlTab: string, activeTab: WorkspaceTabId): void {
121
+ const requested = parseWorkspaceTab(urlTab)
122
+ const viewId = requested ? viewIdFromTab(requested) : null
123
+ reportAppletError(workspaceId, {
124
+ source: 'runtime',
125
+ ...(viewId ? { kind: 'view' as const, name: viewId } : {}),
126
+ message: `Tab "${urlTab}" does not exist in this workspace — the URL redirected to "${activeTab}". A link, bookmark, or focusTab call is pointing at a tab that was deleted or renamed.`
127
+ })
128
+ }
@@ -0,0 +1,160 @@
1
+ import { useCallback, useEffect, useState } from 'react'
2
+
3
+ import { useAppSettings, useSaveAppSettings } from '@/client/features/settings/api'
4
+ import { useUpdateWorkspaceSkills, useWorkspaceSkills } from '@/client/features/workspace/api'
5
+
6
+ import type {
7
+ WorkspaceSkillUpdateAction,
8
+ WorkspaceSkillUpdateBannerProps
9
+ } from './WorkspaceSkillUpdateBanner'
10
+
11
+ type VisitPhase = 'idle' | 'active' | 'dismissed'
12
+
13
+ type VisitState = {
14
+ workspaceId: string
15
+ phase: VisitPhase
16
+ pendingAction: WorkspaceSkillUpdateAction | null
17
+ error: string | null
18
+ }
19
+
20
+ export type WorkspaceSkillUpdates = {
21
+ bannerProps: WorkspaceSkillUpdateBannerProps | null
22
+ }
23
+
24
+ function initialVisitState(workspaceId: string): VisitState {
25
+ return {
26
+ workspaceId,
27
+ phase: 'idle',
28
+ pendingAction: null,
29
+ error: null
30
+ }
31
+ }
32
+
33
+ export function shouldShowWorkspaceSkillUpdateBanner(input: {
34
+ updateAvailable: boolean
35
+ autoUpdateEnabled: boolean
36
+ phase: VisitPhase
37
+ }): boolean {
38
+ return (
39
+ input.phase === 'active' ||
40
+ (input.phase === 'idle' && input.updateAvailable && !input.autoUpdateEnabled)
41
+ )
42
+ }
43
+
44
+ export function shouldAutomaticallyUpdateWorkspaceSkills(input: {
45
+ updateAvailable: boolean
46
+ autoUpdateEnabled: boolean
47
+ updatePending: boolean
48
+ phase: VisitPhase
49
+ }): boolean {
50
+ return (
51
+ input.updateAvailable &&
52
+ input.autoUpdateEnabled &&
53
+ !input.updatePending &&
54
+ input.phase === 'idle'
55
+ )
56
+ }
57
+
58
+ export function useWorkspaceSkillUpdates(workspaceId: string): WorkspaceSkillUpdates {
59
+ const skills = useWorkspaceSkills(workspaceId)
60
+ const {
61
+ isPending: updatePending,
62
+ mutate: updateSkills,
63
+ reset: resetUpdate
64
+ } = useUpdateWorkspaceSkills(workspaceId)
65
+ // The auto-update flag is an app setting (server-side, shared across
66
+ // clients). Until it loads, neither prompt nor auto-update — acting on the
67
+ // default would flash the banner or skip an enabled auto-update.
68
+ const settings = useAppSettings()
69
+ const { mutate: saveSettings } = useSaveAppSettings()
70
+ const settingsReady = settings.data !== undefined
71
+ const autoUpdateEnabled = settings.data?.autoUpdateSkills ?? false
72
+ const enableAutoUpdate = useCallback(
73
+ () => saveSettings({ autoUpdateSkills: true }),
74
+ [saveSettings]
75
+ )
76
+ const [visit, setVisit] = useState<VisitState>(() => initialVisitState(workspaceId))
77
+ const currentVisit = visit.workspaceId === workspaceId ? visit : initialVisitState(workspaceId)
78
+
79
+ useEffect(() => {
80
+ setVisit(initialVisitState(workspaceId))
81
+ resetUpdate()
82
+ }, [workspaceId, resetUpdate])
83
+
84
+ const onUpdate = useCallback(
85
+ (action: WorkspaceSkillUpdateAction) => {
86
+ if (updatePending) return
87
+ if (action === 'auto') enableAutoUpdate()
88
+ setVisit({
89
+ workspaceId,
90
+ phase: 'active',
91
+ pendingAction: action,
92
+ error: null
93
+ })
94
+ updateSkills(undefined, {
95
+ onSuccess: () => {
96
+ setVisit(state =>
97
+ state.workspaceId === workspaceId
98
+ ? { ...state, phase: 'dismissed', pendingAction: null, error: null }
99
+ : state
100
+ )
101
+ },
102
+ onError: error => {
103
+ setVisit(state =>
104
+ state.workspaceId === workspaceId && state.phase !== 'dismissed'
105
+ ? { ...state, phase: 'active', pendingAction: null, error: error.message }
106
+ : state
107
+ )
108
+ }
109
+ })
110
+ },
111
+ [enableAutoUpdate, updatePending, updateSkills, workspaceId]
112
+ )
113
+
114
+ const updateAvailable = skills.data?.updateAvailable ?? false
115
+
116
+ useEffect(() => {
117
+ if (
118
+ settingsReady &&
119
+ shouldAutomaticallyUpdateWorkspaceSkills({
120
+ updateAvailable,
121
+ autoUpdateEnabled,
122
+ updatePending,
123
+ phase: currentVisit.phase
124
+ })
125
+ ) {
126
+ onUpdate('auto')
127
+ }
128
+ }, [
129
+ autoUpdateEnabled,
130
+ currentVisit.phase,
131
+ onUpdate,
132
+ settingsReady,
133
+ updateAvailable,
134
+ updatePending
135
+ ])
136
+
137
+ const visible =
138
+ settingsReady &&
139
+ shouldShowWorkspaceSkillUpdateBanner({
140
+ updateAvailable,
141
+ autoUpdateEnabled,
142
+ phase: currentVisit.phase
143
+ })
144
+ return {
145
+ bannerProps: visible
146
+ ? {
147
+ error: currentVisit.error,
148
+ pendingAction: currentVisit.pendingAction,
149
+ onUpdate,
150
+ onDismiss: () => {
151
+ setVisit(state =>
152
+ state.workspaceId === workspaceId
153
+ ? { ...state, phase: 'dismissed', pendingAction: null, error: null }
154
+ : state
155
+ )
156
+ }
157
+ }
158
+ : null
159
+ }
160
+ }
package/client/index.css CHANGED
@@ -17,20 +17,22 @@
17
17
  --background: oklch(1 0 0);
18
18
  --foreground: oklch(0.145 0 0);
19
19
  --card: oklch(1 0 0);
20
- --card-foreground: oklch(0.145 0 0);
20
+ --card-foreground: var(--foreground);
21
21
  --popover: oklch(1 0 0);
22
- --popover-foreground: oklch(0.145 0 0);
22
+ --popover-foreground: var(--foreground);
23
23
  --primary: oklch(0.205 0 0);
24
24
  --primary-foreground: oklch(0.985 0 0);
25
25
  --muted: oklch(0.97 0 0);
26
26
  --muted-foreground: oklch(0.64 0 0);
27
27
  --accent: oklch(0 0 0 / 0.07);
28
- --accent-foreground: oklch(0.205 0 0);
28
+ --accent-foreground: var(--foreground);
29
29
  --destructive: oklch(0.58 0.22 27);
30
30
  --border: oklch(0 0 0 / 0.07);
31
31
  --input: oklch(0.922 0 0);
32
32
  --ring: oklch(0.708 0 0);
33
- --radius: 1rem;
33
+ --radius: 0.625rem;
34
+ --sans: ui-sans-serif, system-ui, sans-serif;
35
+ --mono: ui-monospace, monospace;
34
36
 
35
37
  /* Workspace page layout — single source of truth for the widget/chat panel.
36
38
  Read by routes/workspace/[id].tsx; don't hardcode equivalents. (The app
@@ -58,29 +60,22 @@
58
60
  --background: oklch(0.145 0 0);
59
61
  --foreground: oklch(0.985 0 0);
60
62
  --card: oklch(0.205 0 0);
61
- --card-foreground: oklch(0.985 0 0);
63
+ --card-foreground: var(--foreground);
62
64
  --popover: oklch(0.205 0 0);
63
- --popover-foreground: oklch(0.985 0 0);
65
+ --popover-foreground: var(--foreground);
64
66
  --primary: oklch(0.985 0 0);
65
67
  --primary-foreground: oklch(0.205 0 0);
66
68
  --muted: oklch(0.269 0 0);
67
69
  --muted-foreground: oklch(0.708 0 0);
68
70
  --accent: oklch(1 0 0 / 0.1);
69
- --accent-foreground: oklch(0.985 0 0);
71
+ --accent-foreground: var(--foreground);
70
72
  --destructive: oklch(0.58 0.22 27);
71
73
  --border: oklch(1 0 0 / 0.1);
72
74
  --input: oklch(0.35 0 0);
73
75
  --ring: oklch(0.556 0 0);
74
76
  }
75
77
 
76
- /* Font vars are NOT inline so Tailwind generates var(--font-*) references,
77
- allowing runtime overrides via document.documentElement.style.setProperty */
78
- @theme {
79
- --font-sans: ui-sans-serif, system-ui, sans-serif;
80
- --font-mono: ui-monospace, monospace;
81
- }
82
-
83
- /* Color/radius/shadow tokens — shared with widget bundles via theme.css */
78
+ /* Font/color/radius/shadow tokens — shared with applet bundles via theme.css */
84
79
  @import './theme.css';
85
80
 
86
81
  /* Dragged card floats above all others */