ompchamber 1.0.0 → 1.1.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 (64) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/static/css/index.b859cc1cc5.css +2 -0
  3. package/dist/client/static/js/async/{5b.0d6ae50fe8.js → 5b.a5ccbc19dc.js} +2 -2
  4. package/dist/client/static/js/index.6e065017eb.js +33 -0
  5. package/package.json +1 -1
  6. package/src/client/components/common/ComposerPicker.tsx +16 -4
  7. package/src/client/components/common/ComposerTextarea.tsx +1 -0
  8. package/src/client/components/layout/RightActivityBar.tsx +1 -1
  9. package/src/client/components/layout/desktop-layout/ResizeHandle.tsx +2 -2
  10. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +13 -2
  11. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +107 -56
  12. package/src/client/components/layout/desktop-layout/index.tsx +25 -96
  13. package/src/client/components/layout/desktop-layout/resizer/index.tsx +79 -118
  14. package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +140 -0
  15. package/src/client/components/layout/session-sidebar/Header.tsx +1 -1
  16. package/src/client/components/layout/session-sidebar/SessionItem.tsx +26 -12
  17. package/src/client/components/layout/session-sidebar/SubagentList.tsx +6 -4
  18. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +3 -0
  19. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -0
  20. package/src/client/components/workspace/chat-timeline/SubagentView.tsx +3 -1
  21. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +23 -3
  22. package/src/client/components/workspace/chat-timeline/index.tsx +3 -0
  23. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Goal.tsx +3 -3
  24. package/src/client/components/workspace/model-dropdown/groups.ts +35 -2
  25. package/src/client/components/workspace/model-dropdown/index.tsx +48 -7
  26. package/src/client/components/workspace/model-dropdown/use-catalog.ts +28 -4
  27. package/src/client/hooks/chat/composer/index.ts +28 -8
  28. package/src/client/hooks/chat/timeline/actions.ts +24 -3
  29. package/src/client/hooks/chat/timeline/deferred-model.test.ts +219 -0
  30. package/src/client/hooks/chat/timeline/deferred-model.ts +92 -0
  31. package/src/client/hooks/chat/timeline/index.ts +13 -1
  32. package/src/client/hooks/chat/timeline/send.ts +16 -5
  33. package/src/client/hooks/workspace/available-width.ts +33 -0
  34. package/src/client/hooks/workspace/panel-widths.ts +34 -37
  35. package/src/server/lib/models/preferences.server.ts +110 -0
  36. package/src/server/lib/models/registry.server.ts +206 -0
  37. package/src/server/lib/omp/rpc/utility.ts +7 -1
  38. package/src/server/lib/queue/delivery.server.test.ts +203 -0
  39. package/src/server/lib/queue/delivery.server.ts +38 -8
  40. package/src/server/routes/models/root.ts +88 -215
  41. package/src/server/routes/settings/commands.ts +59 -18
  42. package/src/shared/lib/chat/composer/client.ts +17 -8
  43. package/src/shared/lib/chat/composer/commands.ts +290 -0
  44. package/src/shared/lib/chat/composer/composer.test.ts +157 -0
  45. package/src/shared/lib/chat/composer/filter.ts +21 -7
  46. package/src/shared/lib/chat/composer/trigger.ts +109 -20
  47. package/src/shared/lib/models/preferences.test.ts +131 -0
  48. package/src/shared/lib/models/preferences.ts +88 -0
  49. package/src/shared/lib/models/provider-models.ts +8 -1
  50. package/src/shared/lib/omp/subagent/label.test.ts +94 -0
  51. package/src/shared/lib/omp/subagent/label.ts +84 -0
  52. package/src/shared/lib/workspace/panel-widths.test.ts +113 -18
  53. package/src/shared/lib/workspace/panel-widths.ts +161 -30
  54. package/src/shared/lib/workspace/right-panels.ts +50 -11
  55. package/src/shared/lib/workspace/session-state/store.ts +3 -0
  56. package/src/shared/types/chat.ts +38 -65
  57. package/src/shared/types/index.ts +1 -0
  58. package/src/shared/types/models.ts +101 -0
  59. package/src/shared/types/omp/subagent.ts +4 -0
  60. package/src/shared/types/settings/command.ts +13 -0
  61. package/dist/client/static/css/index.e880517fcd.css +0 -2
  62. package/dist/client/static/js/index.0de15c5e17.js +0 -33
  63. /package/dist/client/static/js/async/{5b.0d6ae50fe8.js.LICENSE.txt → 5b.a5ccbc19dc.js.LICENSE.txt} +0 -0
  64. /package/dist/client/static/js/{index.0de15c5e17.js.LICENSE.txt → index.6e065017eb.js.LICENSE.txt} +0 -0
@@ -8,6 +8,7 @@ import { AttachmentToolbar } from '@/client/components/workspace/chat-timeline/c
8
8
  import { selectableThinkingLevels } from '@/shared/lib/models/thinking-levels';
9
9
  import { fetchModelsData, subscribeModelsUpdated } from '@/shared/lib/models/client';
10
10
  import { resolveThinkingLevel, selectionFor } from '@/client/components/workspace/chat-timeline/chat-input/selection';
11
+ import { NO_PENDING_PICK } from '@/client/hooks/chat/timeline/deferred-model';
11
12
 
12
13
  export function ChatInput({
13
14
  value,
@@ -31,6 +32,12 @@ export function ChatInput({
31
32
  /** Written on every model/thinking pick so the send path can snapshot the
32
33
  * selection into queued items without lifting ChatInput state. */
33
34
  composerModelRef,
35
+ /** A pick the user made while a turn was streaming, still waiting for the
36
+ * next prompt. While set, the session's own model must NOT be adopted over
37
+ * it — the composer shows what the next prompt will actually run. Omitted
38
+ * by composers that never stream (the New Chat modal), where there is
39
+ * nothing to defer and adoption must behave as before. */
40
+ deferredComposerPickRef = NO_PENDING_PICK,
34
41
  }: {
35
42
  value: string;
36
43
  onChange: (v: string) => void;
@@ -58,6 +65,7 @@ export function ChatInput({
58
65
  */
59
66
  variant?: 'desktop' | 'mobile';
60
67
  composerModelRef: { current: { provider: string; modelId: string; thinkingLevel: string } | null };
68
+ deferredComposerPickRef?: { current: { provider?: string; modelId?: string; thinkingLevel?: string } | null };
61
69
  }) {
62
70
  const [internalAttachments, setInternalAttachments] = useState<Attachment[]>([]);
63
71
 
@@ -102,12 +110,18 @@ export function ChatInput({
102
110
  // this effect re-runs right after a spawn (sessionModel changes while the
103
111
  // session's own thinking_level_change entry is not readable yet), and any
104
112
  // concrete fallback here claims a level the run never used.
113
+ //
114
+ // A pick still waiting for the next prompt wins: the session's model is what
115
+ // the RUNNING turn uses, and adopting it would erase the user's choice from
116
+ // the composer even though it is what the next prompt will run with.
105
117
  useEffect(() => {
106
118
  if (!sessionModel?.provider || !sessionModel.modelId) return;
119
+ if (deferredComposerPickRef.current) return;
107
120
  let active = true;
108
121
  fetchModelsData()
109
122
  .then((data) => {
110
123
  if (!active || !sessionModel) return;
124
+ if (deferredComposerPickRef.current) return;
111
125
  const match = (data.modelList || []).find(
112
126
  (m) => m.id === sessionModel.modelId && m.provider === sessionModel.provider
113
127
  );
@@ -119,18 +133,21 @@ export function ChatInput({
119
133
  return () => {
120
134
  active = false;
121
135
  };
122
- }, [sessionModel?.provider, sessionModel?.modelId]);
136
+ }, [sessionModel?.provider, sessionModel?.modelId, deferredComposerPickRef]);
123
137
 
124
138
  // Adopt the active session's last-used thinking level. Runs after the model
125
139
  // sync effect above so it overrides the catalog default for this session.
140
+ // Same rule as the model: a pick waiting for the next prompt is not
141
+ // overridden by the level the running turn recorded.
126
142
  useEffect(() => {
127
143
  if (!sessionThinkingLevel) return;
144
+ if (deferredComposerPickRef.current?.thinkingLevel) return;
128
145
  setSelectedModel(prev => {
129
146
  if (!prev) return prev;
130
147
  const level = resolveThinkingLevel(prev.thinkingLevels, sessionThinkingLevel, prev.thinkingLevel);
131
148
  return level === prev.thinkingLevel ? prev : { ...prev, thinkingLevel: level };
132
149
  });
133
- }, [sessionThinkingLevel]);
150
+ }, [sessionThinkingLevel, deferredComposerPickRef]);
134
151
 
135
152
  // Sync selected model from server and event listener
136
153
  useEffect(() => {
@@ -139,6 +156,9 @@ export function ChatInput({
139
156
  try {
140
157
  const data = await fetchModelsData();
141
158
  if (!active) return;
159
+ // A pick waiting for the next prompt owns the composer's selection:
160
+ // every branch below would replace it with a session/catalog default.
161
+ if (deferredComposerPickRef.current) return;
142
162
  if (Array.isArray(data.modelList) && data.modelList.length > 0) {
143
163
  // 1. The active session's last-used model is authoritative; even when
144
164
  // it is missing from the catalog, never replace it with the default.
@@ -183,7 +203,7 @@ export function ChatInput({
183
203
  active = false;
184
204
  unsubscribe();
185
205
  };
186
- }, []);
206
+ }, [deferredComposerPickRef]);
187
207
 
188
208
  // Thinking Dropdown State - Reactive with selectedModel
189
209
  const thinkingLevels = useMemo(() => {
@@ -75,6 +75,7 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
75
75
  accessMode,
76
76
  handleAccessModeChange,
77
77
  composerModelRef,
78
+ deferredComposerPickRef,
78
79
  extensionDialogs,
79
80
  resolveExtensionDialog,
80
81
  respondToExtensionUi,
@@ -180,6 +181,7 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
180
181
  accessMode={accessMode}
181
182
  onAccessModeChange={handleAccessModeChange}
182
183
  composerModelRef={composerModelRef}
184
+ deferredComposerPickRef={deferredComposerPickRef}
183
185
  sessionModel={typeof sessionData?.model === 'object' ? sessionData.model : null}
184
186
  sessionThinkingLevel={sessionData?.thinkingLevel}
185
187
  generatingVerb={generatingVerb}
@@ -263,6 +265,7 @@ export function ChatTimeline({ className = '', appSettings = {}, onSessionTitle,
263
265
  accessMode={accessMode}
264
266
  onAccessModeChange={handleAccessModeChange}
265
267
  composerModelRef={composerModelRef}
268
+ deferredComposerPickRef={deferredComposerPickRef}
266
269
  sessionModel={typeof sessionData?.model === 'object' ? sessionData.model : null}
267
270
  sessionThinkingLevel={sessionData?.thinkingLevel}
268
271
  variant={variant}
@@ -124,9 +124,9 @@ export function Goal({ tool }: { tool: ToolCallData }) {
124
124
  {payload.summary && (
125
125
  <div>
126
126
  <span className="text-[10px] font-mono text-ink/45 uppercase tracking-wider">Summary</span>
127
- <p className="mt-0.5 font-sans text-[12px] text-ink font-medium leading-relaxed">
128
- {payload.summary}
129
- </p>
127
+ <div className="mt-0.5 rounded border border-ink/6 bg-ink/[0.03] p-2">
128
+ <MarkdownRenderer content={payload.summary} className="font-medium" />
129
+ </div>
130
130
  </div>
131
131
  )}
132
132
 
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
1
6
  import type { AIModelOption } from '@/shared/types';
2
7
  import { modelKey } from '@/shared/lib/models/identity';
3
8
 
@@ -13,6 +18,25 @@ export interface ModelPickerGroups {
13
18
  index: Record<string, number>;
14
19
  }
15
20
 
21
+ /**
22
+ * Models named by an ordered key list, in that order.
23
+ *
24
+ * The order is the point: RECENT means "most recently used first", and the
25
+ * catalog's own order is alphabetical by name — so reading recents off a flag
26
+ * (the previous `isRecent`) could not express the ranking at all, and a
27
+ * re-picked model never moved back to the top.
28
+ */
29
+ function modelsInKeyOrder(models: AIModelOption[], keys: readonly string[]): AIModelOption[] {
30
+ if (keys.length === 0) return [];
31
+ const byKey = new Map(models.map((model) => [modelKey(model), model]));
32
+ const ordered: AIModelOption[] = [];
33
+ for (const key of keys) {
34
+ const match = byKey.get(key);
35
+ if (match) ordered.push(match);
36
+ }
37
+ return ordered;
38
+ }
39
+
16
40
  /**
17
41
  * All derived picker state in one place: search filtering, the favorites/recent
18
42
  * rails, the per-provider grouping, and the flattened key→index map the
@@ -21,11 +45,16 @@ export interface ModelPickerGroups {
21
45
  * Keying `index` on the composite identity matters — the same model id is served
22
46
  * by several providers, so an id-only key collapsed their rows onto one index
23
47
  * and hovering one highlighted every other provider's row.
48
+ *
49
+ * A row never appears twice: a favorite that is also recent is only listed under
50
+ * FAVORITES, and neither rail repeats the row in its provider section.
24
51
  */
25
52
  export function buildPickerGroups(
26
53
  models: AIModelOption[],
27
54
  search: string,
28
55
  collapsedSections: Record<string, boolean>,
56
+ favoriteKeys: readonly string[],
57
+ recentKeys: readonly string[],
29
58
  ): ModelPickerGroups {
30
59
  const query = search.trim().toLowerCase();
31
60
  const filtered = query
@@ -37,8 +66,12 @@ export function buildPickerGroups(
37
66
  )
38
67
  : models;
39
68
 
40
- const favorites = filtered.filter(m => m.isFavorite);
41
- const recent = filtered.filter(m => m.isRecent && !m.isFavorite);
69
+ // The rails are ordered by the stored key lists, not by the catalog order.
70
+ // A search narrows them like every other section — a starred model that does
71
+ // not match the query must not sit above the results.
72
+ const favorites = modelsInKeyOrder(filtered, favoriteKeys);
73
+ const favoriteSet = new Set(favoriteKeys);
74
+ const recent = modelsInKeyOrder(filtered, recentKeys).filter(m => !favoriteSet.has(modelKey(m)));
42
75
 
43
76
  const byProvider: Record<string, AIModelOption[]> = {};
44
77
  for (const model of filtered) {
@@ -1,13 +1,14 @@
1
1
  import type { TargetedMouseEvent } from 'preact';
2
2
  import { useMemo, useRef, useState } from 'preact/hooks';
3
3
  import { ChevronDown, Sparkles } from 'lucide-preact';
4
- import type { AIModelOption } from '@/shared/types';
4
+ import type { AIModelOption, ModelPreferences } from '@/shared/types';
5
5
  import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
6
6
  import { invalidateModelsCache } from '@/shared/lib/models/client';
7
7
  import { ModelDropdownPanel } from '@/client/components/workspace/model-dropdown/Panel';
8
8
  import { useModelCatalog } from '@/client/components/workspace/model-dropdown/use-catalog';
9
9
  import { buildPickerGroups } from '@/client/components/workspace/model-dropdown/groups';
10
10
  import { modelKey } from '@/shared/lib/models/identity';
11
+ import { RECENT_MODELS_LIMIT, filterKnownKeys, readModelPreferences, recordRecentKey, toggleFavoriteKey } from '@/shared/lib/models/preferences';
11
12
 
12
13
  interface ModelDropdownProps {
13
14
  selectedModel?: AIModelOption;
@@ -29,7 +30,15 @@ export function ModelDropdown({
29
30
  const [focusedIndex, setFocusedIndex] = useState<number>(-1);
30
31
  const [hoveredModel, setHoveredModel] = useState<AIModelOption | null>(null);
31
32
  const [collapsedSections, setCollapsedSections] = useState<Record<string, boolean>>({});
32
- const { models, isLoading, setModels, selectedModel, setSelectedModel } = useModelCatalog(externalSelectedModel);
33
+ const {
34
+ models,
35
+ isLoading,
36
+ setModels,
37
+ selectedModel,
38
+ setSelectedModel,
39
+ preferences,
40
+ applyPreferences,
41
+ } = useModelCatalog(externalSelectedModel);
33
42
 
34
43
  const containerRef = useRef<HTMLDivElement>(null);
35
44
  useOnClickOutside(containerRef, () => {
@@ -46,8 +55,8 @@ export function ModelDropdown({
46
55
  visibleFlatList,
47
56
  index: modelIndex,
48
57
  } = useMemo(
49
- () => buildPickerGroups(models, search, collapsedSections),
50
- [models, search, collapsedSections],
58
+ () => buildPickerGroups(models, search, collapsedSections, preferences.favorites, preferences.recentKeys),
59
+ [models, search, collapsedSections, preferences],
51
60
  );
52
61
 
53
62
  const selectedModelKey = modelKey(selectedModel);
@@ -70,17 +79,40 @@ export function ModelDropdown({
70
79
  setCollapsedSections(prev => ({ ...prev, [section]: !prev[section] }));
71
80
  };
72
81
 
82
+ /**
83
+ * Flip one row's star. The optimistic stamp and the rollback both go through
84
+ * the preference pair — the flag on a row is derived state, so patching the
85
+ * row alone would be undone by the next `applyModelPreferences` (every reload
86
+ * re-stamps rows from the store).
87
+ */
73
88
  const handleToggleFavorite = async (model: AIModelOption, e: TargetedMouseEvent<HTMLElement>) => {
74
89
  e.stopPropagation();
75
90
  const key = modelKey(model);
76
- setModels(prev => prev.map(m => modelKey(m) === key ? { ...m, isFavorite: !m.isFavorite } : m));
91
+ const previous = preferences;
92
+ const optimistic: ModelPreferences = {
93
+ ...previous,
94
+ favorites: toggleFavoriteKey(previous.favorites, key),
95
+ };
96
+ applyPreferences(optimistic);
77
97
  try {
78
- await fetch('/api/models', {
98
+ const response = await fetch('/api/models', {
79
99
  method: 'POST',
80
100
  headers: { 'Content-Type': 'application/json' },
81
101
  body: JSON.stringify({ actionType: 'toggleFavorite', provider: model.provider, modelId: model.id }),
82
102
  });
83
- } catch {}
103
+ if (!response.ok) throw new Error(`toggleFavorite failed: ${response.status}`);
104
+ const data = await response.json() as { modelPreferences?: unknown };
105
+ // The server is the authority on the resulting list — it also drops keys
106
+ // the registry no longer serves. An absent/malformed payload keeps the
107
+ // optimistic list rather than blanking the rail.
108
+ if (data.modelPreferences) {
109
+ applyPreferences(readModelPreferences(data.modelPreferences));
110
+ }
111
+ } catch {
112
+ // A failed write must not leave the star lit: the next reload would show
113
+ // it unlit anyway, so the rollback keeps the panel honest immediately.
114
+ applyPreferences(previous);
115
+ }
84
116
  };
85
117
 
86
118
  const cycleThinkingLevel = (model: AIModelOption) => {
@@ -125,6 +157,15 @@ export function ModelDropdown({
125
157
  onSelectModel?.(model);
126
158
  setIsOpen(false);
127
159
  setHoveredModel(null);
160
+ // Move the pick to the top of RECENT straight away — the server records it
161
+ // alongside the selection, and waiting for the round trip would leave the
162
+ // rail stale until the next full reload. Same rules as the server's write:
163
+ // pruned to the models the registry serves, de-duplicated, capped.
164
+ const known = new Set(models.map(modelKey));
165
+ applyPreferences({
166
+ favorites: filterKnownKeys(preferences.favorites, known),
167
+ recentKeys: recordRecentKey(filterKnownKeys(preferences.recentKeys, known), modelKey(model), RECENT_MODELS_LIMIT),
168
+ });
128
169
  try {
129
170
  await fetch('/api/models', {
130
171
  method: 'POST',
@@ -1,6 +1,11 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
2
- import type { AIModelOption, ModelEntry } from '@/shared/types';
2
+ import type { AIModelOption, ModelEntry, ModelPreferences } from '@/shared/types';
3
3
  import { fetchModelsData, subscribeModelsUpdated } from '@/shared/lib/models/client';
4
+ import {
5
+ EMPTY_MODEL_PREFERENCES,
6
+ applyModelPreferences,
7
+ readModelPreferences,
8
+ } from '@/shared/lib/models/preferences';
4
9
 
5
10
  function toOption(m: ModelEntry): AIModelOption {
6
11
  const ladder = Array.isArray(m.thinkingLevels) ? m.thinkingLevels : [];
@@ -28,6 +33,10 @@ export interface ModelCatalogState {
28
33
  setModels: (updater: (prev: AIModelOption[]) => AIModelOption[]) => void;
29
34
  selectedModel: AIModelOption | null;
30
35
  setSelectedModel: (model: AIModelOption | null) => void;
36
+ /** Favorite + recent rails, ordered by the stored key lists. */
37
+ preferences: ModelPreferences;
38
+ /** Merge a server-returned preference pair into the rails. */
39
+ applyPreferences: (preferences: ModelPreferences) => void;
31
40
  }
32
41
 
33
42
  /**
@@ -42,11 +51,17 @@ export interface ModelCatalogState {
42
51
  * An externally-driven selection (the composer's session model) always wins over
43
52
  * the API's own default — it is read through a ref so a thinking-level change
44
53
  * flowing back through the prop does not re-arm the fetch.
54
+ *
55
+ * Favorites arrive as a key list, never as a flag on the registry rows: the
56
+ * registry is a read-only view of omp's config, so the only place a star can
57
+ * live is the preference store. The rows are stamped from it here, which is why
58
+ * a toggle must go through {@link applyPreferences} rather than patching a row.
45
59
  */
46
60
  export function useModelCatalog(externalSelectedModel?: AIModelOption): ModelCatalogState {
47
61
  const [models, setModelsState] = useState<AIModelOption[]>([]);
48
62
  const [isLoading, setIsLoading] = useState(true);
49
63
  const [selectedModel, setSelectedModel] = useState<AIModelOption | null>(externalSelectedModel ?? null);
64
+ const [preferences, setPreferences] = useState<ModelPreferences>(EMPTY_MODEL_PREFERENCES);
50
65
 
51
66
  const externalSelectedRef = useRef(externalSelectedModel);
52
67
  externalSelectedRef.current = externalSelectedModel;
@@ -56,11 +71,18 @@ export function useModelCatalog(externalSelectedModel?: AIModelOption): ModelCat
56
71
  setModelsState(updater);
57
72
  }, []);
58
73
 
74
+ const applyPreferences = useCallback((next: ModelPreferences) => {
75
+ setPreferences(next);
76
+ setModelsState(prev => applyModelPreferences(prev, next));
77
+ }, []);
78
+
59
79
  const load = useCallback(async () => {
60
80
  try {
61
81
  const data = await fetchModelsData();
62
82
  if (Array.isArray(data.modelList) && data.modelList.length > 0) {
63
- const realModels = data.modelList.map(toOption);
83
+ const prefs = readModelPreferences(data.modelPreferences);
84
+ const realModels = applyModelPreferences(data.modelList.map(toOption), prefs);
85
+ setPreferences(prefs);
64
86
  // Keep a thinking level the user already picked, but only when it is
65
87
  // still a real level of this model's ladder (legacy mock values like
66
88
  // 'Default'/'High' must not be preserved).
@@ -76,7 +98,9 @@ export function useModelCatalog(externalSelectedModel?: AIModelOption): ModelCat
76
98
  if (match) setSelectedModel(match);
77
99
  }
78
100
  } else if (Array.isArray(data.models) && data.models.length > 0) {
79
- setModelsState(data.models);
101
+ const prefs = readModelPreferences(data.modelPreferences);
102
+ setPreferences(prefs);
103
+ setModelsState(applyModelPreferences(data.models, prefs));
80
104
  }
81
105
  if (data.selectedModel && !externalSelectedRef.current) {
82
106
  setSelectedModel(data.selectedModel);
@@ -107,5 +131,5 @@ export function useModelCatalog(externalSelectedModel?: AIModelOption): ModelCat
107
131
  ));
108
132
  }, [externalSelectedModel]);
109
133
 
110
- return { models, isLoading, setModels, selectedModel, setSelectedModel };
134
+ return { models, isLoading, setModels, selectedModel, setSelectedModel, preferences, applyPreferences };
111
135
  }
@@ -42,7 +42,18 @@ function isComposingInput(native: Event): boolean {
42
42
  );
43
43
  }
44
44
 
45
- /** Orchestrates the composer `@`-agent / `/`-command autocomplete flow. */
45
+ /**
46
+ * Whether the popup may open for this trigger. oh-my-pi only shows the command
47
+ * popup once the slash token has a real match — a bare `/`, a `/tmp/fo` path,
48
+ * or a completed `/retry ` must not cover the composer with an empty list.
49
+ * Mentions keep their own rule: the empty state tells the user what `@` accepts.
50
+ */
51
+ function shouldOpen(trigger: ComposerTrigger | null, matches: ComposerMatchItem[]): boolean {
52
+ if (!trigger) return false;
53
+ return trigger.kind === 'mention' || matches.length > 0;
54
+ }
55
+
56
+ /** Orchestrates the composer `@`-mention / `/`-command autocomplete flow. */
46
57
  export function useComposerTrigger(options: UseComposerTriggerOptions): ComposerTriggerController {
47
58
  const { value, setValue, textareaRef, disabled = false, rootPath } = options;
48
59
 
@@ -54,8 +65,8 @@ export function useComposerTrigger(options: UseComposerTriggerOptions): Composer
54
65
  const { items, loading, error } = useComposerItems(trigger?.kind ?? null, rootPath ?? null);
55
66
 
56
67
  const matches = useMemo(
57
- () => filterComposerItems(items, trigger?.query ?? ''),
58
- [items, trigger?.query],
68
+ () => (trigger ? filterComposerItems(items, trigger) : []),
69
+ [items, trigger],
59
70
  );
60
71
 
61
72
  const clampedIndex = matches.length > 0
@@ -66,6 +77,8 @@ export function useComposerTrigger(options: UseComposerTriggerOptions): Composer
66
77
 
67
78
  const optionId = useCallback((index: number) => `${listboxId}-option-${index}`, [listboxId]);
68
79
 
80
+ const open = shouldOpen(trigger, matches);
81
+
69
82
  const close = useCallback(() => {
70
83
  setTrigger(null);
71
84
  setActiveIndexState(0);
@@ -112,15 +125,22 @@ export function useComposerTrigger(options: UseComposerTriggerOptions): Composer
112
125
  const next = insertToken(value, trigger, tokenForItem(item));
113
126
  pendingCaretRef.current = next.caret;
114
127
  setValue(next.value);
115
- close();
128
+ // Re-query instead of closing: oh-my-pi reopens on the accepted text, so
129
+ // `/fast` → `/fast ` immediately offers its subcommands and the collapsed
130
+ // `/skill:` row expands into the individual skills. `shouldOpen` keeps a
131
+ // completed command from leaving an empty popup behind.
132
+ setTrigger(detectComposerTrigger(next.value, next.caret));
133
+ setActiveIndexState(0);
116
134
  },
117
- [value, trigger, setValue, close],
135
+ [value, trigger, setValue],
118
136
  );
119
137
 
120
138
  const handleKeyDown = useCallback(
121
139
  (e: TargetedKeyboardEvent<HTMLTextAreaElement>): boolean => {
122
140
  if (composingRef.current || e.keyCode === 229) return false;
123
- if (!trigger) return false;
141
+ // A closed popup owns nothing: `/tmp/fo` must keep Enter/Tab meaning send
142
+ // and indent rather than being swallowed by an invisible list.
143
+ if (!trigger || !open) return false;
124
144
 
125
145
  if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
126
146
  e.preventDefault();
@@ -147,7 +167,7 @@ export function useComposerTrigger(options: UseComposerTriggerOptions): Composer
147
167
 
148
168
  return false;
149
169
  },
150
- [trigger, matches, clampedIndex, selectItem, close],
170
+ [trigger, open, matches, clampedIndex, selectItem, close],
151
171
  );
152
172
 
153
173
  useLayoutEffect(() => {
@@ -163,7 +183,7 @@ export function useComposerTrigger(options: UseComposerTriggerOptions): Composer
163
183
 
164
184
  return {
165
185
  trigger,
166
- isOpen: trigger !== null,
186
+ isOpen: open,
167
187
  matches,
168
188
  loading,
169
189
  error,
@@ -16,6 +16,7 @@ import type { Dispatch, SetStateAction } from 'preact/compat';
16
16
  import type { Attachment, ChatMessageData, OmpAgentHandle, QueuedMessageModel } from '@/shared/types';
17
17
  import type { QueuedMessage } from '@/client/components/workspace/chat-timeline/QueueList';
18
18
  import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
19
+ import { applyComposerPick, consumeComposerPick, stashComposerPick, type DeferredModelStore } from '@/client/hooks/chat/timeline/deferred-model';
19
20
 
20
21
  export interface ChatTimelineActionsDeps {
21
22
  inputValue: string;
@@ -48,6 +49,9 @@ export interface ChatTimelineActionsDeps {
48
49
  /** Live composer model/thinking mirror, snapshotted onto queued items so
49
50
  * auto-delivery replays the exact settings. */
50
51
  composerModelRef: { current: { provider: string; modelId: string; thinkingLevel: string } | null };
52
+ /** Picks made while a turn streams: held back so they cannot re-target the
53
+ * in-flight answer, then pushed onto the session before the next prompt. */
54
+ deferredComposerPickRef: DeferredModelStore;
51
55
  /** Global access-control mode, snapshotted onto queued items. */
52
56
  accessModeRef: { current: ApprovalMode };
53
57
  setSearchParams: (fn: (prev: URLSearchParams) => URLSearchParams, opts?: { replace?: boolean }) => void;
@@ -89,6 +93,7 @@ export function useChatTimelineActions(deps: ChatTimelineActionsDeps): ChatTimel
89
93
  pendingComposerModelRef,
90
94
  pendingThinkingLevelRef,
91
95
  composerModelRef,
96
+ deferredComposerPickRef,
92
97
  accessModeRef,
93
98
  setSearchParams,
94
99
  } = deps;
@@ -285,16 +290,32 @@ export function useChatTimelineActions(deps: ChatTimelineActionsDeps): ChatTimel
285
290
  pendingThinkingLevelRef.current = level;
286
291
  return;
287
292
  }
293
+ // A pick made mid-run is intent for the NEXT prompt: pushing it now would
294
+ // re-target the turn already streaming (omp applies set_thinking_level to
295
+ // the running turn's next LLM call).
296
+ if (isGenerating) {
297
+ stashComposerPick(deferredComposerPickRef, { thinkingLevel: level });
298
+ return;
299
+ }
300
+ consumeComposerPick(deferredComposerPickRef, { thinkingLevel: level });
288
301
  void ompAgent.setThinkingLevel(level);
289
- }, [isOmpSession, ompAgent, pendingThinkingLevelRef]);
302
+ }, [isGenerating, isOmpSession, ompAgent, pendingThinkingLevelRef, deferredComposerPickRef]);
290
303
 
291
304
  const handleModelChange = useCallback((provider: string, modelId: string) => {
292
305
  if (!isOmpSession) {
293
306
  pendingComposerModelRef.current = { provider, modelId };
294
307
  return;
295
308
  }
296
- void ompAgent.setModel(provider, modelId);
297
- }, [isOmpSession, ompAgent, pendingComposerModelRef]);
309
+ // Same rule as the thinking pick: a mid-run model change is held back so
310
+ // the answer being streamed finishes on the model it started with, and is
311
+ // applied right before the next prompt this composer sends.
312
+ if (isGenerating) {
313
+ stashComposerPick(deferredComposerPickRef, { provider, modelId });
314
+ return;
315
+ }
316
+ consumeComposerPick(deferredComposerPickRef, { provider, modelId });
317
+ void applyComposerPick(ompAgent, { provider, modelId });
318
+ }, [isGenerating, isOmpSession, ompAgent, pendingComposerModelRef, deferredComposerPickRef]);
298
319
 
299
320
  return {
300
321
  handleSend,