@kabmo-labs/kabmo 0.13.0 → 0.14.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 (148) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +319 -319
  3. package/dist/client/static/js/index-bnrrw242.css +1 -0
  4. package/dist/client/static/js/{index-vzb1qz51.js → index-w6jx0h0p.js} +780 -780
  5. package/marketplace/plugins/command-runner/package.json +2 -2
  6. package/marketplace/plugins/command-runner/src/server/ring.test.ts +41 -0
  7. package/marketplace/plugins/command-runner/src/server/run-types.ts +6 -0
  8. package/marketplace/plugins/command-runner/src/server/runner-harness.ts +69 -0
  9. package/marketplace/plugins/command-runner/src/server/runner-path.test.ts +127 -0
  10. package/marketplace/plugins/command-runner/src/server/runner.test.ts +2 -72
  11. package/marketplace/plugins/command-runner/src/server/runner.ts +31 -3
  12. package/package.json +2 -2
  13. package/src/client/components/common/batch-selection/BatchActionBar.test.ts +42 -5
  14. package/src/client/components/common/batch-selection/BatchActionBar.tsx +57 -14
  15. package/src/client/components/common/code-surface/extensions.ts +7 -1
  16. package/src/client/components/common/code-surface/fold-placeholder.ts +43 -0
  17. package/src/client/components/common/session-row/StatusSlot.tsx +133 -0
  18. package/src/client/components/common/session-row/TrailingSlot.tsx +84 -0
  19. package/src/client/components/common/session-row/index.tsx +215 -0
  20. package/src/client/components/common/session-row/session-row.test.tsx +154 -0
  21. package/src/client/components/layout/session-sidebar/ClassicView.tsx +121 -0
  22. package/src/client/components/layout/session-sidebar/SessionsView.tsx +99 -112
  23. package/src/client/components/layout/session-sidebar/Toolbar.tsx +2 -2
  24. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +149 -0
  25. package/src/client/components/layout/session-sidebar/modern/FilterChips.tsx +150 -0
  26. package/src/client/components/layout/session-sidebar/modern/SearchField.tsx +75 -0
  27. package/src/client/components/layout/session-sidebar/modern/Skeleton.tsx +56 -0
  28. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +193 -0
  29. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +333 -0
  30. package/src/client/components/layout/session-sidebar/modern/index.tsx +147 -0
  31. package/src/client/components/layout/session-sidebar/modern/workspace-header.test.tsx +111 -0
  32. package/src/client/components/layout/session-sidebar/variant-props.ts +73 -0
  33. package/src/client/components/mobile/SessionSidebar.tsx +137 -146
  34. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +140 -0
  35. package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +3 -3
  36. package/src/client/components/mobile/mobile-session-sidebar/use-drawer.ts +104 -0
  37. package/src/client/components/settings/Modal.tsx +5 -27
  38. package/src/client/components/settings/Sidebar.tsx +1 -1
  39. package/src/client/components/settings/apply-side-effects.test.ts +102 -0
  40. package/src/client/components/settings/apply-side-effects.ts +90 -0
  41. package/src/client/components/settings/categories/AppearanceSettings.tsx +11 -1
  42. package/src/client/components/settings/categories/ChatSettings.test.tsx +121 -0
  43. package/src/client/components/settings/categories/ChatSettings.tsx +80 -15
  44. package/src/client/components/settings/categories/appearance-settings/SidebarStyleSection.tsx +157 -0
  45. package/src/client/components/settings/categories/chat-settings/ComposerStyleSection.tsx +177 -0
  46. package/src/client/components/settings/categories/chat-settings/LayoutSection.tsx +1 -1
  47. package/src/client/components/settings/categories/chat-settings/SidebarList.tsx +73 -0
  48. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +144 -0
  49. package/src/client/components/settings/categories/chat-settings/groups.test.ts +42 -0
  50. package/src/client/components/settings/categories/chat-settings/groups.ts +81 -0
  51. package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +1 -68
  52. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +7 -0
  53. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -0
  54. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +15 -5
  55. package/src/client/components/workspace/chat-timeline/MessageList.tsx +90 -41
  56. package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +13 -6
  57. package/src/client/components/workspace/chat-timeline/ThinkingSection.test.tsx +117 -0
  58. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +117 -75
  59. package/src/client/components/workspace/chat-timeline/ToolCallingSection.test.ts +28 -8
  60. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +48 -4
  61. package/src/client/components/workspace/chat-timeline/TurnRail.tsx +64 -0
  62. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +178 -0
  63. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -1
  64. package/src/client/components/workspace/chat-timeline/chat-input/ComposerNotice.tsx +50 -0
  65. package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +178 -0
  66. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +1 -1
  67. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +102 -122
  68. package/src/client/components/workspace/chat-timeline/chat-input/props.ts +7 -0
  69. package/src/client/components/workspace/chat-timeline/chat-input/styles/index.tsx +111 -0
  70. package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +181 -0
  71. package/src/client/components/workspace/chat-timeline/index.tsx +3 -0
  72. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +1 -0
  73. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/approval-gate.test.tsx +31 -0
  74. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +1 -1
  75. package/src/client/components/workspace/chat-timeline/tool-renderers/index.tsx +2 -2
  76. package/src/client/components/workspace/chat-timeline/tool-renderers/plugin-renderers.ts +6 -1
  77. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolBody.tsx +98 -0
  78. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolCardShell.tsx +3 -1
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/status-glyph.tsx +56 -0
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/toggle-label.ts +19 -0
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view.ts +132 -0
  82. package/src/client/components/workspace/chat-timeline/{ToolCallCard.plugin.test.ts → tool-renderers/styles/Card.plugin.test.ts} +3 -3
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Card.tsx +60 -0
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Compact.tsx +89 -0
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Minimal.tsx +72 -0
  86. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Trace.tsx +84 -0
  87. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/props.ts +22 -0
  88. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +153 -0
  89. package/src/client/components/workspace/diff-panel/folding.ts +6 -1
  90. package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +16 -2
  91. package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +86 -12
  92. package/src/client/components/workspace/model-dropdown/Item.tsx +56 -19
  93. package/src/client/components/workspace/model-dropdown/Panel.tsx +21 -13
  94. package/src/client/components/workspace/model-dropdown/Section.test.tsx +114 -4
  95. package/src/client/components/workspace/model-dropdown/Section.tsx +21 -9
  96. package/src/client/components/workspace/model-dropdown/groups.test.ts +164 -1
  97. package/src/client/components/workspace/model-dropdown/groups.ts +94 -17
  98. package/src/client/components/workspace/model-dropdown/index.tsx +27 -19
  99. package/src/client/data/settings/omp-schema.json +151 -6
  100. package/src/client/hooks/chat/composer/style.ts +66 -0
  101. package/src/client/hooks/chat/timeline/row-window-reveal.ts +130 -0
  102. package/src/client/hooks/chat/timeline/row-window.test.ts +35 -0
  103. package/src/client/hooks/chat/timeline/row-window.ts +59 -133
  104. package/src/client/hooks/chat/timeline/thinking-open.ts +67 -0
  105. package/src/client/hooks/chat/timeline/tool-render-mode.ts +65 -0
  106. package/src/client/hooks/settings/providers/login.ts +11 -2
  107. package/src/client/hooks/ui/window-event.ts +20 -4
  108. package/src/client/hooks/workspace/batch-archive-run.ts +47 -0
  109. package/src/client/hooks/workspace/batch-archive.test.ts +59 -0
  110. package/src/client/hooks/workspace/batch-archive.ts +78 -0
  111. package/src/client/hooks/workspace/sidebar-batch.ts +95 -0
  112. package/src/client/hooks/workspace/sidebar-style.ts +66 -0
  113. package/src/client/tailwind.css +111 -0
  114. package/src/server/index.ts +10 -134
  115. package/src/server/lib/lifecycle/after-listen.ts +178 -0
  116. package/src/server/lib/lifecycle/rejection-guard.test.ts +79 -0
  117. package/src/server/lib/lifecycle/rejection-guard.ts +74 -0
  118. package/src/server/lib/lifecycle/tls.test.ts +7 -7
  119. package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +131 -0
  120. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +46 -0
  121. package/src/server/lib/omp/rpc/frame-fold.test.ts +1 -100
  122. package/src/server/lib/omp/rpc/frame-fold.ts +13 -0
  123. package/src/server/lib/plugins/background.server.ts +17 -1
  124. package/src/server/lib/plugins/background.test.ts +33 -0
  125. package/src/server/routes/sessions/batch-archive.test.ts +113 -0
  126. package/src/server/routes/sessions/batch-archive.ts +80 -0
  127. package/src/server/routes/sessions/index.ts +4 -0
  128. package/src/shared/lib/chat/composer/style.test.ts +126 -0
  129. package/src/shared/lib/chat/composer/style.ts +171 -0
  130. package/src/shared/lib/chat/composer/tui-only.test.ts +3 -0
  131. package/src/shared/lib/chat/composer/tui-only.ts +5 -0
  132. package/src/shared/lib/chat/timeline/block-chrome.ts +129 -0
  133. package/src/shared/lib/chat/timeline/tool-render-mode.test.ts +51 -0
  134. package/src/shared/lib/chat/timeline/tool-render-mode.ts +74 -0
  135. package/src/shared/lib/chat/timeline/trace-groups.test.ts +132 -0
  136. package/src/shared/lib/chat/timeline/trace-groups.ts +95 -0
  137. package/src/shared/lib/settings/defaults.ts +6 -0
  138. package/src/shared/lib/workspace/session-focus.test.ts +93 -0
  139. package/src/shared/lib/workspace/session-focus.ts +71 -0
  140. package/src/shared/lib/workspace/session-state/store.ts +5 -0
  141. package/src/shared/lib/workspace/sidebar-filter-row.test.ts +73 -0
  142. package/src/shared/lib/workspace/sidebar-filter-row.ts +86 -0
  143. package/src/shared/lib/workspace/sidebar-style.test.ts +58 -0
  144. package/src/shared/lib/workspace/sidebar-style.ts +86 -0
  145. package/src/shared/types/omp/agent.ts +6 -0
  146. package/src/shared/types/settings/state.ts +31 -0
  147. package/dist/client/static/js/index-68w8h33q.css +0 -1
  148. package/src/client/components/workspace/chat-timeline/ToolCallCard.tsx +0 -194
@@ -49,7 +49,7 @@ export function AttachmentToolbar({ attachments, onFilesSelected, onRemove, mode
49
49
  {/* No separator and no second surface: the card is ONE colour, so the
50
50
  header, the draft and the toolbar read as one panel. A hairline over
51
51
  a tinted strip made the composer look like three stacked bars. */}
52
- <div className="flex items-center flex-wrap gap-1.5 px-3 py-2 text-ink/60">
52
+ <div className="composer-attach-row flex items-center flex-wrap gap-1.5 px-3 py-2 text-ink/60">
53
53
  <button
54
54
  onClick={() => fileInputRef.current?.click()}
55
55
  className="flex items-center justify-center hover:bg-ink/5 p-1 rounded transition-colors text-ink/60 hover:text-ink shrink-0"
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The composer's refusal strip: a send that the pipeline rejected, or a
8
+ * mode-command the child answered with an error.
9
+ *
10
+ * Both are the same question and share one row, because a user cannot act on
11
+ * two refusals at once and the strip sits directly above the draft they belong
12
+ * to. Split out of `ChatInput` for the per-file ceiling; it owns no state — the
13
+ * two messages and their two dismissers come from the caller.
14
+ */
15
+
16
+ import { AlertTriangle, X } from 'lucide-preact';
17
+
18
+ export interface ComposerNoticeProps {
19
+ /** The pipeline's refusal (unreadable attachment, refused send, …). */
20
+ notice: string | null;
21
+ /** The mode command's refusal, from the route or the extension. */
22
+ modeError?: string | null;
23
+ onDismissNotice: () => void;
24
+ onDismissModeError?: () => void;
25
+ }
26
+
27
+ export function ComposerNotice({
28
+ notice,
29
+ modeError,
30
+ onDismissNotice,
31
+ onDismissModeError,
32
+ }: ComposerNoticeProps) {
33
+ const message = notice || modeError;
34
+ if (!message) return null;
35
+
36
+ return (
37
+ <div className="flex items-start gap-1.5 bg-error/5 px-3 py-1.5 text-[11px] text-error">
38
+ <AlertTriangle size={11} className="mt-0.5 shrink-0" />
39
+ <span className="min-w-0 flex-1 break-words">{message}</span>
40
+ <button
41
+ type="button"
42
+ onClick={() => (notice ? onDismissNotice() : onDismissModeError?.())}
43
+ className="shrink-0 text-error/60 hover:text-error transition-colors"
44
+ title="Dismiss"
45
+ >
46
+ <X size={11} />
47
+ </button>
48
+ </div>
49
+ );
50
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The composer's five rows, built once and handed to `ComposerFrame`.
8
+ *
9
+ * Every row is ALWAYS constructed here — the frame decides only their ORDER,
10
+ * never whether they exist. That split is what makes "a style cannot drop a
11
+ * control" a property of the code rather than of a reviewer's attention.
12
+ *
13
+ * Split out of `ChatInput` for the per-file ceiling: the composer owns state
14
+ * (draft, attachments, expansion, compact, voice, pipeline) and this file owns
15
+ * the markup those states produce.
16
+ */
17
+
18
+ import type { ClipboardEvent, RefObject } from 'preact/compat';
19
+ import type { ComponentChildren } from 'preact';
20
+ import type { AIModelOption, Attachment } from '@/shared/types';
21
+ import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
22
+ import type { ComposerRow } from '@/shared/lib/chat/composer/style';
23
+ import type { ComposerModes } from '@/client/components/workspace/chat-timeline/chat-input/modes-props';
24
+ import type { ComposerPickerPlacement } from '@/client/components/common/ComposerPicker';
25
+ import { AttachmentToolbar } from '@/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar';
26
+ import { ComposerNotice } from '@/client/components/workspace/chat-timeline/chat-input/ComposerNotice';
27
+ import { ComposerTextarea } from '@/client/components/common/ComposerTextarea';
28
+ import { ComposerToolbar } from '@/client/components/workspace/chat-timeline/chat-input/Toolbar';
29
+ import { VoiceNotice } from '@/client/components/workspace/chat-timeline/chat-input/VoiceNotice';
30
+
31
+ export interface ComposerRowsInput {
32
+ /** Textarea sizing from `composerExpansion` (the style's own pixels are CSS). */
33
+ textareaClass: string;
34
+ wrapperClass: string;
35
+ pickerPlacement: ComposerPickerPlacement;
36
+
37
+ attachments: Attachment[];
38
+ onFilesSelected: (files: File[]) => void;
39
+ onRemoveAttachment: (id: string) => void;
40
+ modes?: ComposerModes;
41
+ onOpenGoal: () => void;
42
+ expanded?: boolean;
43
+ onToggleExpand?: () => void;
44
+ compact: boolean;
45
+ onExpandComposer: () => void;
46
+
47
+ notice: string | null;
48
+ dismissNotice: () => void;
49
+
50
+ value: string;
51
+ onChange: (value: string) => void;
52
+ submit: (options?: { steering?: boolean }) => void;
53
+ sendDisabled: boolean;
54
+ disabled: boolean;
55
+ appSettings?: Record<string, any>;
56
+ rootPath?: string | null;
57
+ enablePicker?: boolean;
58
+ placeholder?: string;
59
+ onPaste: (event: ClipboardEvent<HTMLTextAreaElement>) => void;
60
+ variant: 'desktop' | 'mobile';
61
+ textareaRef: RefObject<HTMLTextAreaElement>;
62
+ onTextareaReady: (element: HTMLTextAreaElement | null) => void;
63
+
64
+ voiceStatus: Parameters<typeof VoiceNotice>[0]['status'];
65
+ voiceError: string | null;
66
+
67
+ isMobile: boolean;
68
+ selectedModel: AIModelOption | null;
69
+ onSelectModel: (model: AIModelOption) => void;
70
+ thinkingLevels: string[];
71
+ currentThinking: string;
72
+ onSelectThinking: (level: string) => void;
73
+ onThinkingLevelChange?: (level: string) => void;
74
+ isGenerating: boolean;
75
+ chatRunning?: boolean;
76
+ onStop?: () => void;
77
+ accessMode?: ApprovalMode;
78
+ onSelectAccess?: (mode: ApprovalMode) => void;
79
+ showModel?: boolean;
80
+ showThinking?: boolean;
81
+ showAccess?: boolean;
82
+ voiceSupported?: boolean;
83
+ voiceListening?: boolean;
84
+ voiceBusy?: boolean;
85
+ onVoiceToggle?: () => void;
86
+ }
87
+
88
+ export function composerRows({
89
+ textareaClass,
90
+ wrapperClass,
91
+ pickerPlacement,
92
+ ...input
93
+ }: ComposerRowsInput): Record<ComposerRow, ComponentChildren> {
94
+ return {
95
+ attachments: (
96
+ <AttachmentToolbar
97
+ attachments={input.attachments}
98
+ onFilesSelected={input.onFilesSelected}
99
+ onRemove={input.onRemoveAttachment}
100
+ // The phone hosts the mode toggles here; the desktop keeps them in the
101
+ // bottom toolbar, which has room. `showAccess` gates both hosts.
102
+ modes={input.isMobile && input.showAccess ? input.modes : undefined}
103
+ onOpenGoal={input.onOpenGoal}
104
+ // Only the chat's own composer stretches; a caller that owns its size
105
+ // (the New Chat modal) gets no control and cannot be stretched.
106
+ expanded={input.onToggleExpand ? input.expanded : undefined}
107
+ onToggleExpand={input.onToggleExpand}
108
+ compact={input.compact}
109
+ onExpandComposer={input.onExpandComposer}
110
+ />
111
+ ),
112
+
113
+ notice: (
114
+ <ComposerNotice
115
+ notice={input.notice}
116
+ modeError={input.modes?.error}
117
+ onDismissNotice={input.dismissNotice}
118
+ onDismissModeError={input.modes?.clearError}
119
+ />
120
+ ),
121
+
122
+ // Not rendered at all while compact: the phone gives the transcript its
123
+ // height back by removing the box, not by shrinking it, and the attachment
124
+ // row then carries the "Type here" target that brings it back. A `h-0` box
125
+ // would keep a focusable element with no pixels.
126
+ draft: input.compact ? null : (
127
+ <ComposerTextarea
128
+ value={input.value}
129
+ onChange={input.onChange}
130
+ onSend={input.submit}
131
+ disabled={input.disabled}
132
+ appSettings={input.appSettings}
133
+ rootPath={input.rootPath}
134
+ enablePicker={input.enablePicker}
135
+ placement={pickerPlacement}
136
+ wrapperClassName={wrapperClass}
137
+ placeholder={input.placeholder}
138
+ className={`composer-draft w-full bg-transparent border-none focus:outline-none resize-none text-ink placeholder-ink/40 disabled:opacity-50 disabled:cursor-not-allowed ${textareaClass}`}
139
+ onPaste={input.onPaste}
140
+ variant={input.variant}
141
+ textareaRef={input.textareaRef}
142
+ onReady={input.onTextareaReady}
143
+ />
144
+ ),
145
+
146
+ // Dictation progress / failure, beside the toolbar that owns the mic.
147
+ voice: <VoiceNotice status={input.voiceStatus} error={input.voiceError} />,
148
+
149
+ toolbar: (
150
+ <ComposerToolbar
151
+ isMobile={input.isMobile}
152
+ selectedModel={input.selectedModel}
153
+ onSelectModel={input.onSelectModel}
154
+ thinkingLevels={input.thinkingLevels}
155
+ currentThinking={input.currentThinking}
156
+ onSelectThinking={input.onSelectThinking}
157
+ onThinkingLevelChange={input.onThinkingLevelChange}
158
+ isGenerating={input.isGenerating}
159
+ chatRunning={input.chatRunning}
160
+ onStop={input.onStop}
161
+ onSend={() => input.submit()}
162
+ sendDisabled={input.sendDisabled}
163
+ accessMode={input.accessMode}
164
+ onSelectAccess={input.onSelectAccess}
165
+ showModel={input.showModel}
166
+ showThinking={input.showThinking}
167
+ showAccess={input.showAccess}
168
+ modes={input.modes}
169
+ onOpenGoal={input.onOpenGoal}
170
+ voiceSupported={input.voiceSupported}
171
+ voiceListening={input.voiceListening}
172
+ voiceBusy={input.voiceBusy}
173
+ onVoiceToggle={input.onVoiceToggle}
174
+ text={input.value}
175
+ />
176
+ ),
177
+ };
178
+ }
@@ -107,7 +107,7 @@ export function ComposerToolbar({
107
107
  // footer read as a second, heavier bar under the draft. A 32px target
108
108
  // still clears the 28px minimum for a touch control while bringing the
109
109
  // row to 44px — the same height as the compact textarea above it.
110
- className="@container flex items-center justify-between rounded-b-[inherit] px-3 py-1.5"
110
+ className="composer-toolbar-row @container flex items-center justify-between rounded-b-[inherit] px-3 py-1.5"
111
111
  >
112
112
  <div className={`flex items-center min-w-0 ${isMobile ? 'space-x-1' : 'space-x-2'}`}>
113
113
  {showModel && (
@@ -1,25 +1,24 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
2
2
  import type { ClipboardEvent, SetStateAction } from 'preact/compat';
3
- import { AlertTriangle, X } from 'lucide-preact';
4
3
  import type { Attachment } from '@/shared/types';
5
- import { ComposerToolbar } from '@/client/components/workspace/chat-timeline/chat-input/Toolbar';
6
- import { VoiceNotice } from '@/client/components/workspace/chat-timeline/chat-input/VoiceNotice';
7
- import { ComposerTextarea } from '@/client/components/common/ComposerTextarea';
8
- import { usePublishComposerState } from '@/client/hooks/chat/composer/publish-state';
9
4
  import { useModelSelection } from '@/client/hooks/chat/composer/model-selection';
10
- import { AttachmentToolbar } from '@/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar';
11
5
  import { NO_PENDING_PICK } from '@/client/hooks/chat/timeline/deferred-model';
12
6
  import { CHAT_COMPOSER_MAX_LINES, useAutoGrow } from '@/client/hooks/chat/composer/auto-grow';
13
7
  import { useVoiceInput } from '@/client/hooks/chat/composer/voice-input';
14
8
  import { primeFileReads } from '@/client/hooks/chat/composer/file-reads';
15
9
  import { useComposerPipeline } from '@/client/hooks/chat/composer/pipeline';
10
+ import { usePublishComposerState } from '@/client/hooks/chat/composer/publish-state';
16
11
  import { DropOverlay } from '@/client/components/workspace/chat-timeline/chat-input/DropOverlay';
17
12
  import { GoalSurfaces } from '@/client/components/workspace/chat-timeline/chat-input/GoalSurfaces';
13
+ import { ComposerFrame } from '@/client/components/workspace/chat-timeline/chat-input/styles/index';
14
+ import { composerRows } from '@/client/components/workspace/chat-timeline/chat-input/ComposerRows';
18
15
  import { normalizeGoalBudget } from '@/shared/lib/omp/mode/budget';
19
16
  import { readKabmoSetting } from '@/shared/lib/settings/client';
20
17
  import { useKeyboardInset } from '@/client/hooks/ui/keyboard-inset';
21
18
  import { composerExpansion } from '@/client/components/workspace/chat-timeline/chat-input/expansion';
22
19
  import { useComposerCompact } from '@/client/hooks/chat/composer/compact';
20
+ import { useComposerStyle } from '@/client/hooks/chat/composer/style';
21
+ import { composerStyleLayout } from '@/shared/lib/chat/composer/style';
23
22
  import type { ChatInputProps } from '@/client/components/workspace/chat-timeline/chat-input/props';
24
23
 
25
24
  export function ChatInput({
@@ -55,9 +54,9 @@ export function ChatInput({
55
54
  deferredComposerPickRef = NO_PENDING_PICK,
56
55
  chatRunning,
57
56
  expandable = false,
57
+ hero = false,
58
58
  shrinkWhileReading = false,
59
59
  }: ChatInputProps) {
60
- const [internalAttachments, setInternalAttachments] = useState<Attachment[]>([]);
61
60
  // The Goal modal is owned here, not by the toolbar: the button is a toggle,
62
61
  // and the modal it opens needs the same `modes` slice the toolbar got.
63
62
  const [goalModalOpen, setGoalModalOpen] = useState(false);
@@ -80,20 +79,18 @@ export function ChatInput({
80
79
  onThinkingLevelChange,
81
80
  });
82
81
 
82
+ // Attachments: owned here when nobody else needs to read them (the New Chat
83
+ // modal), forwarded through the caller's setter when a dock does. The
84
+ // forward has to stay a state setter: evaluating a functional update here
85
+ // against the closed-over value would resurrect stale state (the async
86
+ // FileReader callback wiping the just-added image).
87
+ const [internalAttachments, setInternalAttachments] = useState<Attachment[]>([]);
83
88
  const attachments = externalAttachments !== undefined ? externalAttachments : internalAttachments;
84
89
  const setAttachments = (updater: SetStateAction<Attachment[]>) => {
85
- if (onAttachmentsChange) {
86
- // Forward the updater untouched: onAttachmentsChange is a state setter,
87
- // so functional updates stay functional. Evaluating them here against
88
- // the closure `attachments` would resurrect stale state (e.g. the async
89
- // FileReader callback wiping the just-added image).
90
- onAttachmentsChange(updater);
91
- } else {
92
- setInternalAttachments(updater);
93
- }
90
+ if (onAttachmentsChange) onAttachmentsChange(updater);
91
+ else setInternalAttachments(updater);
94
92
  };
95
93
 
96
-
97
94
  const handlePaste = (e: ClipboardEvent<HTMLTextAreaElement>) => {
98
95
  const clipboard = e.clipboardData;
99
96
  if (!clipboard) return;
@@ -158,6 +155,20 @@ export function ChatInput({
158
155
  });
159
156
  const layout = composerExpansion({ variant, expanded, isDragging, keyboardInset });
160
157
 
158
+ // The style only reorders rows and re-frames the card; every control below is
159
+ // rendered in every style. `hero` is the empty-chat state `stage` reacts to —
160
+ // the composer cannot see the transcript, so the caller says so, and the
161
+ // default (false) keeps the docked shape for a caller that does not care.
162
+ const style = useComposerStyle();
163
+ const styleLayout = composerStyleLayout({ style, hero });
164
+ // Position FIRST: `cardPositionClass` must not be cancelled by a later
165
+ // position utility (Tailwind resolves those by emission order regardless of
166
+ // class order, which is why `expansion.ts` keeps position in its own field).
167
+ // The style contributes NO class here — its pixels are `[data-composer-style]`
168
+ // rules in `tailwind.css`, because `rounded-md` beside `rounded-xl` lost.
169
+ const cardClass = `${layout.cardPositionClass} ${layout.cardClass} ${layout.cardLayoutClass}`;
170
+ const textareaClass = layout.textareaClass;
171
+
161
172
  // Growth: a modal composer states its own px bounds, the chat's docked one
162
173
  // grows to `CHAT_COMPOSER_MAX_LINES` lines. Either way it is measured only
163
174
  // while the layout does NOT own the height — a stretched composer is `h-full`
@@ -202,10 +213,13 @@ export function ChatInput({
202
213
  });
203
214
 
204
215
  return (
205
- <div
206
- ref={cardRef}
207
- className={`@container transition-colors flex flex-col ${layout.cardPositionClass} ${layout.cardClass} ${layout.cardLayoutClass} ${className}`}
216
+ <ComposerFrame
217
+ layout={styleLayout}
218
+ cardClass={cardClass}
208
219
  style={layout.style}
220
+ className={className}
221
+ cardRef={cardRef}
222
+ expanded={expanded}
209
223
  // focusin/focusout BUBBLE, unlike focus/blur: the card has to learn that
210
224
  // the textarea inside it was focused, and a capture-phase `onFocus` on
211
225
  // this element is not the same question (it fires for the card's own
@@ -228,110 +242,76 @@ export function ChatInput({
228
242
  // Press-time, not click-time — see `useComposerCompact` for why a click
229
243
  // never arrives in the compact state.
230
244
  onPointerDown={onCardPointerDown}
231
- {...dropProps}
232
- >
233
- <DropOverlay visible={isDragging} />
234
-
235
- {/* Goal mode strip describes the turn the next message will join. */}
236
- <GoalSurfaces
237
- modes={modes}
238
- running={chatRunning ?? isGenerating}
239
- open={goalModalOpen}
240
- defaultBudget={normalizeGoalBudget(readKabmoSetting<number>('goalDefaultBudget', appSettings))}
241
- onOpen={() => setGoalModalOpen(true)}
242
- onClose={() => setGoalModalOpen(false)}
243
- />
244
-
245
- <AttachmentToolbar
246
- attachments={attachments}
247
- onFilesSelected={(files) => acceptFiles(files)}
248
- onRemove={removeAttachment}
249
- // The phone hosts the mode toggles here; the desktop keeps them in the
250
- // bottom toolbar, which has room. `showAccess` gates both hosts.
251
- modes={isMobile && showAccess ? modes : undefined}
252
- onOpenGoal={() => setGoalModalOpen(true)}
253
- // Only the chat's own composer stretches; a caller that owns its size
254
- // (the New Chat modal) gets no control and cannot be stretched.
255
- expanded={expandable ? expanded : undefined}
256
- onToggleExpand={expandable ? () => setExpanded((prev) => !prev) : undefined}
257
- compact={compact}
258
- onExpandComposer={reopen}
259
- />
260
-
261
- {/* Refused plan/goal command notice. */}
262
- {(notice || modes?.error) && (
263
- <div className="flex items-start gap-1.5 bg-error/5 px-3 py-1.5 text-[11px] text-error">
264
- <AlertTriangle size={11} className="mt-0.5 shrink-0" />
265
- <span className="min-w-0 flex-1 break-words">{notice || modes?.error}</span>
266
- <button
267
- type="button"
268
- onClick={() => (notice ? dismissNotice() : modes?.clearError())}
269
- className="shrink-0 text-error/60 hover:text-error transition-colors"
270
- title="Dismiss"
271
- >
272
- <X size={11} />
273
- </button>
274
- </div>
275
- )}
276
-
277
- {/* Textarea. Not rendered at all while compact: the phone gives the
278
- transcript its height back by removing the box, not by shrinking it,
279
- and `AttachmentToolbar` then carries the "Type here" target that
280
- brings it back. Rendering it at `h-0` would keep a focusable element
281
- with no pixels, which is exactly the trap the `inert` rules elsewhere
282
- exist to avoid. */}
283
- {!compact && (
284
- <ComposerTextarea
285
- value={value}
286
- onChange={onChange}
287
- onSend={submit}
288
- disabled={disabled}
289
- appSettings={appSettings}
290
- rootPath={rootPath}
291
- enablePicker={enablePicker}
292
- placement={layout.pickerPlacement}
293
- wrapperClassName={layout.wrapperClass}
294
- placeholder={placeholder ?? (disabled ? "Please select a workspace above to start prompting..." : "@ for files/agents; / for commands and skills (Paste images/files here)")}
295
- className={`w-full bg-transparent border-none focus:outline-none resize-none text-ink placeholder-ink/40 disabled:opacity-50 disabled:cursor-not-allowed ${layout.textareaClass}`}
296
- onPaste={handlePaste}
297
- variant={variant}
298
- textareaRef={growRef}
299
- onReady={onTextareaReady}
300
- />
301
- )}
302
- {/* Dictation progress / failure, above the toolbar that owns the mic. */}
303
- <VoiceNotice status={voiceStatus} error={displayedVoiceError} />
245
+ dropProps={dropProps}
246
+ header={
247
+ <>
248
+ <DropOverlay visible={isDragging} />
304
249
 
305
- {/* Bottom Config Toolbar */}
306
- <ComposerToolbar
307
- isMobile={isMobile}
308
- selectedModel={selectedModel}
309
- onSelectModel={(model) => {
250
+ {/* Goal mode strip describes the turn the next message will join. It
251
+ is card chrome, not a row: it stays above the rows in every style. */}
252
+ <GoalSurfaces
253
+ modes={modes}
254
+ running={chatRunning ?? isGenerating}
255
+ open={goalModalOpen}
256
+ defaultBudget={normalizeGoalBudget(readKabmoSetting<number>('goalDefaultBudget', appSettings))}
257
+ onOpen={() => setGoalModalOpen(true)}
258
+ onClose={() => setGoalModalOpen(false)}
259
+ />
260
+ </>
261
+ }
262
+ rows={composerRows({
263
+ textareaClass,
264
+ wrapperClass: layout.wrapperClass,
265
+ pickerPlacement: layout.pickerPlacement,
266
+ attachments,
267
+ onFilesSelected: (files) => acceptFiles(files),
268
+ onRemoveAttachment: removeAttachment,
269
+ modes,
270
+ onOpenGoal: () => setGoalModalOpen(true),
271
+ expanded,
272
+ onToggleExpand: expandable ? () => setExpanded((prev) => !prev) : undefined,
273
+ compact,
274
+ onExpandComposer: reopen,
275
+ notice,
276
+ dismissNotice,
277
+ value,
278
+ onChange,
279
+ submit,
280
+ sendDisabled: disabled || (!value.trim() && attachments.length === 0),
281
+ disabled,
282
+ appSettings,
283
+ rootPath,
284
+ enablePicker,
285
+ placeholder: placeholder ?? (disabled ? "Please select a workspace above to start prompting..." : "@ for files/agents; / for commands and skills (Paste images/files here)"),
286
+ onPaste: handlePaste,
287
+ variant,
288
+ textareaRef: growRef,
289
+ onTextareaReady,
290
+ voiceStatus,
291
+ voiceError: displayedVoiceError,
292
+ isMobile,
293
+ selectedModel,
294
+ onSelectModel: (model) => {
310
295
  setSelectedModel(model);
311
296
  onModelChange?.(model.provider, model.id);
312
- }}
313
- thinkingLevels={thinkingLevels}
314
- currentThinking={currentThinking}
315
- onSelectThinking={selectThinking}
316
- onThinkingLevelChange={onThinkingLevelChange}
317
- isGenerating={isGenerating}
318
- chatRunning={chatRunning}
319
- onStop={onStop}
320
- onSend={() => submit()}
321
- sendDisabled={disabled || (!value.trim() && attachments.length === 0)}
322
- accessMode={accessMode}
323
- onSelectAccess={onAccessModeChange}
324
- showModel={showModel}
325
- showThinking={showThinking}
326
- showAccess={showAccess}
327
- modes={modes}
328
- onOpenGoal={() => setGoalModalOpen(true)}
329
- voiceSupported={voiceSupported}
330
- voiceListening={voiceListening}
331
- voiceBusy={voiceBusy}
332
- onVoiceToggle={handleVoiceToggle}
333
- text={value}
334
- />
335
- </div>
297
+ },
298
+ thinkingLevels,
299
+ currentThinking,
300
+ onSelectThinking: selectThinking,
301
+ onThinkingLevelChange,
302
+ isGenerating,
303
+ chatRunning,
304
+ onStop,
305
+ accessMode,
306
+ onSelectAccess: onAccessModeChange,
307
+ showModel,
308
+ showThinking,
309
+ showAccess,
310
+ voiceSupported,
311
+ voiceListening,
312
+ voiceBusy,
313
+ onVoiceToggle: handleVoiceToggle,
314
+ })}
315
+ />
336
316
  );
337
317
  }
@@ -98,6 +98,13 @@ export interface ChatInputProps {
98
98
  * form lives inside a panel that is already sized to the answers beside it.
99
99
  */
100
100
  expandable?: boolean;
101
+ /**
102
+ * The chat has no messages yet. Only the `stage` composer style reads it:
103
+ * an empty session draws a taller draft so the first prompt is not written
104
+ * into a 68px slot in the middle of a blank screen. Every other style — and
105
+ * every caller that omits it — draws the docked shape.
106
+ */
107
+ hero?: boolean;
101
108
  /**
102
109
  * The reader has scrolled back through the transcript. On a phone with an
103
110
  * empty draft the composer then gives its height back to the conversation
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The composer card's FRAME, as one component.
8
+ *
9
+ * Every style renders the same five rows — attachments, notice, draft, voice,
10
+ * toolbar — and the only thing that differs is their order
11
+ * (`composerStyleLayout().rows`). Rendering that order here, rather than with a
12
+ * second copy of the JSX per style, is what makes "no control can go missing"
13
+ * structural instead of a review checklist: a row absent from `rows` is a row
14
+ * this file never renders, and the table is asserted to contain all five.
15
+ *
16
+ * The card's POSITION and stretch semantics are not decided here: they come
17
+ * from `composerExpansion`, which already owns the two layout answers (phone
18
+ * takes the viewport, desktop grows in place), the keyboard inset and the
19
+ * popup placement. This file adds the style's own attributes and keeps the two
20
+ * surfaces that describe the CARD — the goal strip and the drag overlay — above
21
+ * every row, because they do not belong to a line of it.
22
+ *
23
+ * **The style's pixels are CSS, not classes** (`[data-composer-style]` in
24
+ * `tailwind.css`): two utilities of the same property resolve by emission
25
+ * order, so a style writing `rounded-md` beside the frame's `rounded-xl`
26
+ * rendered 12px (measured). The attributes below are the whole handshake.
27
+ */
28
+
29
+ import { Fragment } from 'preact';
30
+ import type { ComponentChildren } from 'preact';
31
+ import type { CSSProperties, RefObject } from 'preact/compat';
32
+ import type { FileDropProps } from '@/client/hooks/chat/composer/file-drop';
33
+ import type { ComposerRow, ComposerStyleLayout } from '@/shared/lib/chat/composer/style';
34
+
35
+ export interface ComposerFrameProps {
36
+ layout: ComposerStyleLayout;
37
+ /** Position, frame, radius, elevation — resolved by `composerExpansion`. */
38
+ cardClass: string;
39
+ /** The keyboard inset / safe-area padding, when the layout states one. */
40
+ style?: CSSProperties;
41
+ /** Extra classes from the caller (`ChatInput.className`). */
42
+ className?: string;
43
+ /** The card element: the compact hook, the keyboard inset and focus read it. */
44
+ cardRef: RefObject<HTMLDivElement>;
45
+ /**
46
+ * The card currently fills the viewport (the phone's stretched composer).
47
+ * Written as an attribute because a style's radius is plain CSS and would
48
+ * otherwise beat the expansion frame's `rounded-none` — measured: a stretched
49
+ * `glass` card kept a 20px radius over a `fixed inset-0` surface, showing the
50
+ * canvas at its corners.
51
+ */
52
+ expanded?: boolean;
53
+ /** Preact maps these to the bubble-phase events (`onFocusIn`/`onFocusOut`). */
54
+ onFocusIn: () => void;
55
+ onFocusOut: () => void;
56
+ onPointerDown: (event: PointerEvent) => void;
57
+ dropProps: FileDropProps;
58
+ /** Goal strip, drag overlay — above every row, in every style. */
59
+ header?: ComponentChildren;
60
+ rows: Record<ComposerRow, ComponentChildren>;
61
+ }
62
+
63
+ export function ComposerFrame({
64
+ layout,
65
+ cardClass,
66
+ style,
67
+ className = '',
68
+ cardRef,
69
+ expanded = false,
70
+ onFocusIn,
71
+ onFocusOut,
72
+ onPointerDown,
73
+ dropProps,
74
+ header,
75
+ rows,
76
+ }: ComposerFrameProps) {
77
+ return (
78
+ <div
79
+ ref={cardRef}
80
+ data-composer-style={layout.attributeValue}
81
+ data-composer-hero={layout.hero ? 'true' : undefined}
82
+ data-composer-expanded={expanded ? 'true' : undefined}
83
+ // NO position utility here: `cardClass` carries `cardPositionClass`, and
84
+ // Tailwind's position utilities are ordered `static, fixed, absolute,
85
+ // relative, sticky` — a `relative` written in this base list would WIN
86
+ // over the `fixed inset-0` a stretched phone composer adds (measured in
87
+ // `expansion.ts`).
88
+ className={`@container transition-colors flex flex-col ${cardClass} ${className}`}
89
+ style={style}
90
+ onFocusIn={onFocusIn}
91
+ onFocusOut={onFocusOut}
92
+ onPointerDown={onPointerDown}
93
+ {...dropProps}
94
+ >
95
+ {header}
96
+ {layout.promptGlyph && (
97
+ // The console style's prompt glyph: decoration that names the surface,
98
+ // so it is inert to the pointer and hidden from the accessibility tree.
99
+ <span
100
+ aria-hidden="true"
101
+ className="pointer-events-none absolute -top-5 left-2 font-mono text-[11px] text-ink/35"
102
+ >
103
+ omp ›
104
+ </span>
105
+ )}
106
+ {layout.rows.map((row) => (
107
+ <Fragment key={row}>{rows[row]}</Fragment>
108
+ ))}
109
+ </div>
110
+ );
111
+ }