@kabmo-labs/kabmo 0.13.0 → 0.14.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 (133) 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-vzb1qz51.js → index-nfsg1jpt.js} +779 -779
  4. package/dist/client/static/js/index-tsgy3gd1.css +1 -0
  5. package/package.json +1 -1
  6. package/src/client/components/common/batch-selection/BatchActionBar.test.ts +42 -5
  7. package/src/client/components/common/batch-selection/BatchActionBar.tsx +57 -14
  8. package/src/client/components/common/code-surface/extensions.ts +7 -1
  9. package/src/client/components/common/code-surface/fold-placeholder.ts +43 -0
  10. package/src/client/components/common/session-row/StatusSlot.tsx +133 -0
  11. package/src/client/components/common/session-row/TrailingSlot.tsx +84 -0
  12. package/src/client/components/common/session-row/index.tsx +205 -0
  13. package/src/client/components/common/session-row/session-row.test.tsx +144 -0
  14. package/src/client/components/layout/session-sidebar/ClassicView.tsx +121 -0
  15. package/src/client/components/layout/session-sidebar/SessionsView.tsx +99 -112
  16. package/src/client/components/layout/session-sidebar/Toolbar.tsx +2 -2
  17. package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +149 -0
  18. package/src/client/components/layout/session-sidebar/modern/FilterChips.tsx +150 -0
  19. package/src/client/components/layout/session-sidebar/modern/SearchField.tsx +75 -0
  20. package/src/client/components/layout/session-sidebar/modern/Skeleton.tsx +55 -0
  21. package/src/client/components/layout/session-sidebar/modern/WorkspaceHeader.tsx +184 -0
  22. package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +333 -0
  23. package/src/client/components/layout/session-sidebar/modern/index.tsx +147 -0
  24. package/src/client/components/layout/session-sidebar/variant-props.ts +73 -0
  25. package/src/client/components/mobile/SessionSidebar.tsx +137 -146
  26. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +140 -0
  27. package/src/client/components/mobile/mobile-session-sidebar/Toolbar.tsx +3 -3
  28. package/src/client/components/mobile/mobile-session-sidebar/use-drawer.ts +104 -0
  29. package/src/client/components/settings/Modal.tsx +5 -27
  30. package/src/client/components/settings/Sidebar.tsx +1 -1
  31. package/src/client/components/settings/apply-side-effects.test.ts +102 -0
  32. package/src/client/components/settings/apply-side-effects.ts +90 -0
  33. package/src/client/components/settings/categories/AppearanceSettings.tsx +11 -1
  34. package/src/client/components/settings/categories/ChatSettings.test.tsx +121 -0
  35. package/src/client/components/settings/categories/ChatSettings.tsx +80 -15
  36. package/src/client/components/settings/categories/appearance-settings/SidebarStyleSection.tsx +157 -0
  37. package/src/client/components/settings/categories/chat-settings/ComposerStyleSection.tsx +177 -0
  38. package/src/client/components/settings/categories/chat-settings/LayoutSection.tsx +1 -1
  39. package/src/client/components/settings/categories/chat-settings/SidebarList.tsx +73 -0
  40. package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +144 -0
  41. package/src/client/components/settings/categories/chat-settings/groups.test.ts +42 -0
  42. package/src/client/components/settings/categories/chat-settings/groups.ts +81 -0
  43. package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +1 -68
  44. package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +7 -0
  45. package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -0
  46. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +14 -5
  47. package/src/client/components/workspace/chat-timeline/MessageList.tsx +90 -41
  48. package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +13 -6
  49. package/src/client/components/workspace/chat-timeline/ThinkingSection.tsx +108 -67
  50. package/src/client/components/workspace/chat-timeline/ToolCallingSection.test.ts +28 -8
  51. package/src/client/components/workspace/chat-timeline/ToolCallingSection.tsx +48 -4
  52. package/src/client/components/workspace/chat-timeline/TurnRail.tsx +64 -0
  53. package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +158 -0
  54. package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -1
  55. package/src/client/components/workspace/chat-timeline/chat-input/ComposerNotice.tsx +50 -0
  56. package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +178 -0
  57. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +1 -1
  58. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +102 -122
  59. package/src/client/components/workspace/chat-timeline/chat-input/props.ts +7 -0
  60. package/src/client/components/workspace/chat-timeline/chat-input/styles/index.tsx +111 -0
  61. package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +181 -0
  62. package/src/client/components/workspace/chat-timeline/index.tsx +3 -0
  63. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +1 -0
  64. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/approval-gate.test.tsx +31 -0
  65. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +1 -1
  66. package/src/client/components/workspace/chat-timeline/tool-renderers/index.tsx +2 -2
  67. package/src/client/components/workspace/chat-timeline/tool-renderers/plugin-renderers.ts +6 -1
  68. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolBody.tsx +98 -0
  69. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ToolCardShell.tsx +3 -1
  70. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/status-glyph.tsx +56 -0
  71. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/toggle-label.ts +19 -0
  72. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/tool-view.ts +132 -0
  73. package/src/client/components/workspace/chat-timeline/{ToolCallCard.plugin.test.ts → tool-renderers/styles/Card.plugin.test.ts} +3 -3
  74. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Card.tsx +60 -0
  75. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Compact.tsx +89 -0
  76. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Minimal.tsx +72 -0
  77. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Trace.tsx +84 -0
  78. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/props.ts +22 -0
  79. package/src/client/components/workspace/chat-timeline/tool-renderers/styles/styles.test.tsx +153 -0
  80. package/src/client/components/workspace/diff-panel/folding.ts +6 -1
  81. package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +86 -12
  82. package/src/client/components/workspace/model-dropdown/Item.tsx +56 -19
  83. package/src/client/components/workspace/model-dropdown/Panel.tsx +21 -13
  84. package/src/client/components/workspace/model-dropdown/Section.test.tsx +114 -4
  85. package/src/client/components/workspace/model-dropdown/Section.tsx +21 -9
  86. package/src/client/components/workspace/model-dropdown/groups.test.ts +164 -1
  87. package/src/client/components/workspace/model-dropdown/groups.ts +94 -17
  88. package/src/client/components/workspace/model-dropdown/index.tsx +27 -19
  89. package/src/client/data/settings/omp-schema.json +151 -6
  90. package/src/client/hooks/chat/composer/style.ts +66 -0
  91. package/src/client/hooks/chat/timeline/tool-render-mode.ts +65 -0
  92. package/src/client/hooks/settings/providers/login.ts +11 -2
  93. package/src/client/hooks/ui/window-event.ts +20 -4
  94. package/src/client/hooks/workspace/batch-archive-run.ts +47 -0
  95. package/src/client/hooks/workspace/batch-archive.test.ts +59 -0
  96. package/src/client/hooks/workspace/batch-archive.ts +78 -0
  97. package/src/client/hooks/workspace/sidebar-batch.ts +95 -0
  98. package/src/client/hooks/workspace/sidebar-style.ts +66 -0
  99. package/src/client/tailwind.css +111 -0
  100. package/src/server/index.ts +10 -134
  101. package/src/server/lib/lifecycle/after-listen.ts +178 -0
  102. package/src/server/lib/lifecycle/rejection-guard.test.ts +79 -0
  103. package/src/server/lib/lifecycle/rejection-guard.ts +74 -0
  104. package/src/server/lib/lifecycle/tls.test.ts +7 -7
  105. package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +131 -0
  106. package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +46 -0
  107. package/src/server/lib/omp/rpc/frame-fold.test.ts +1 -100
  108. package/src/server/lib/omp/rpc/frame-fold.ts +13 -0
  109. package/src/server/lib/plugins/background.server.ts +17 -1
  110. package/src/server/lib/plugins/background.test.ts +33 -0
  111. package/src/server/routes/sessions/batch-archive.test.ts +113 -0
  112. package/src/server/routes/sessions/batch-archive.ts +80 -0
  113. package/src/server/routes/sessions/index.ts +4 -0
  114. package/src/shared/lib/chat/composer/style.test.ts +126 -0
  115. package/src/shared/lib/chat/composer/style.ts +171 -0
  116. package/src/shared/lib/chat/composer/tui-only.test.ts +3 -0
  117. package/src/shared/lib/chat/composer/tui-only.ts +5 -0
  118. package/src/shared/lib/chat/timeline/block-chrome.ts +129 -0
  119. package/src/shared/lib/chat/timeline/tool-render-mode.test.ts +51 -0
  120. package/src/shared/lib/chat/timeline/tool-render-mode.ts +74 -0
  121. package/src/shared/lib/chat/timeline/trace-groups.test.ts +120 -0
  122. package/src/shared/lib/chat/timeline/trace-groups.ts +68 -0
  123. package/src/shared/lib/settings/defaults.ts +6 -0
  124. package/src/shared/lib/workspace/session-focus.test.ts +93 -0
  125. package/src/shared/lib/workspace/session-focus.ts +71 -0
  126. package/src/shared/lib/workspace/sidebar-filter-row.test.ts +73 -0
  127. package/src/shared/lib/workspace/sidebar-filter-row.ts +86 -0
  128. package/src/shared/lib/workspace/sidebar-style.test.ts +58 -0
  129. package/src/shared/lib/workspace/sidebar-style.ts +86 -0
  130. package/src/shared/types/omp/agent.ts +6 -0
  131. package/src/shared/types/settings/state.ts +31 -0
  132. package/dist/client/static/js/index-68w8h33q.css +0 -1
  133. package/src/client/components/workspace/chat-timeline/ToolCallCard.tsx +0 -194
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The archive summary's contract.
8
+ *
9
+ * A batch archive has no dialog, so this sentence is the ONLY report the user
10
+ * gets: it must name both what was archived and what was refused (a bare count
11
+ * cannot be reconciled against the list), and it must choose the right tone so
12
+ * a partial failure is not dressed as success.
13
+ */
14
+
15
+ import { describe, expect, test } from 'bun:test';
16
+ import { archiveOutcomeMessage, type BatchArchiveOutcome } from '@/client/hooks/workspace/batch-archive';
17
+
18
+ function outcome(partial: Partial<BatchArchiveOutcome>): BatchArchiveOutcome {
19
+ return { archived: [], refused: [], ...partial };
20
+ }
21
+
22
+ describe('archiveOutcomeMessage', () => {
23
+ test('nothing changed reports nothing', () => {
24
+ expect(archiveOutcomeMessage(outcome({}))).toBeNull();
25
+ });
26
+
27
+ test('a clean run is a success and counts the sessions', () => {
28
+ expect(archiveOutcomeMessage(outcome({ archived: ['a', 'b', 'c'] })))
29
+ .toEqual({ message: 'Archived 3 sessions.', tone: 'success' });
30
+ });
31
+
32
+ test('one archived session is singular', () => {
33
+ expect(archiveOutcomeMessage(outcome({ archived: ['a'] })))
34
+ .toEqual({ message: 'Archived 1 session.', tone: 'success' });
35
+ });
36
+
37
+ test('a partial refusal names both counts and is not dressed as success', () => {
38
+ const report = archiveOutcomeMessage(outcome({
39
+ archived: ['a', 'b'],
40
+ refused: [{ id: 'new-1', error: 'This chat has not been created yet.' }],
41
+ }));
42
+ expect(report?.message).toContain('Archived 2 sessions');
43
+ expect(report?.message).toContain('1 refused');
44
+ expect(report?.tone).toBe('error');
45
+ });
46
+
47
+ test('an all-refused run is an error and names the refusal count', () => {
48
+ const report = archiveOutcomeMessage(outcome({
49
+ refused: [{ id: 'new-1', error: 'This chat has not been created yet.' }],
50
+ }));
51
+ expect(report?.message).toBe('1 session could not be archived.');
52
+ expect(report?.tone).toBe('error');
53
+ });
54
+
55
+ test('a request-level failure reports the server reason', () => {
56
+ expect(archiveOutcomeMessage(outcome({ error: 'Could not archive (HTTP 500).' })))
57
+ .toEqual({ message: 'Could not archive (HTTP 500).', tone: 'error' });
58
+ });
59
+ });
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The batch archive verb, and the sentence a finished run reports.
8
+ *
9
+ * Archive is the reversible sibling of delete, so it has no confirmation
10
+ * dialog: the bar's Archive acts on the selection and the outcome is summarised
11
+ * as one toast. The server still answers per-id verdicts — a pending `new-…`
12
+ * chat cannot be archived — so the summary must name both what was archived and
13
+ * what was refused rather than reporting a bare count the user cannot reconcile
14
+ * against the list.
15
+ */
16
+
17
+ export interface BatchArchiveRefusal {
18
+ id: string;
19
+ error: string;
20
+ code?: string;
21
+ }
22
+
23
+ export interface BatchArchiveOutcome {
24
+ archived: string[];
25
+ refused: BatchArchiveRefusal[];
26
+ /** Set only when the request itself failed (network, 4xx, 5xx). */
27
+ error?: string;
28
+ }
29
+
30
+ const EMPTY: BatchArchiveOutcome = { archived: [], refused: [] };
31
+
32
+ async function postBatch(url: string, ids: readonly string[]): Promise<BatchArchiveOutcome> {
33
+ try {
34
+ const res = await fetch(url, {
35
+ method: 'POST',
36
+ headers: { 'content-type': 'application/json' },
37
+ body: JSON.stringify({ ids }),
38
+ });
39
+ const body = (await res.json().catch(() => null)) as Partial<BatchArchiveOutcome> | null;
40
+ if (!res.ok) {
41
+ return { ...EMPTY, error: body?.error || `Could not archive (HTTP ${res.status}).` };
42
+ }
43
+ return {
44
+ archived: Array.isArray(body?.archived) ? body.archived : [],
45
+ refused: Array.isArray(body?.refused) ? body.refused : [],
46
+ };
47
+ } catch (error) {
48
+ return { ...EMPTY, error: error instanceof Error ? error.message : 'Could not reach the server.' };
49
+ }
50
+ }
51
+
52
+ /** Archive sessions in one request. Pending `new-…` ids are refused by the server. */
53
+ export function archiveSessionsBatch(ids: readonly string[]): Promise<BatchArchiveOutcome> {
54
+ return postBatch('/api/sessions/batch-archive', ids);
55
+ }
56
+
57
+ /**
58
+ * The one line a finished archive run reports, for a toast. Null when the run
59
+ * changed nothing and has nothing to say.
60
+ */
61
+ export function archiveOutcomeMessage(
62
+ outcome: BatchArchiveOutcome,
63
+ ): { message: string; tone: 'success' | 'error' } | null {
64
+ if (outcome.error) return { message: outcome.error, tone: 'error' };
65
+ const archived = outcome.archived.length;
66
+ const refused = outcome.refused.length;
67
+ if (archived === 0 && refused === 0) return null;
68
+ if (refused === 0) {
69
+ return { message: `Archived ${archived} ${archived === 1 ? 'session' : 'sessions'}.`, tone: 'success' };
70
+ }
71
+ if (archived === 0) {
72
+ return { message: `${refused} ${refused === 1 ? 'session' : 'sessions'} could not be archived.`, tone: 'error' };
73
+ }
74
+ return {
75
+ message: `Archived ${archived} ${archived === 1 ? 'session' : 'sessions'}; ${refused} refused.`,
76
+ tone: 'error',
77
+ };
78
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The batch machine, wired once for both sidebars.
8
+ *
9
+ * `useBatchSelection` and `useBatchDeleteRun` are the state; this joins them to
10
+ * the list that is actually on screen, because three facts have to be computed
11
+ * the same way by the desktop dock and the phone drawer or the bar claims
12
+ * something the user cannot act on:
13
+ *
14
+ * - **the scope folder** — the workspace a SESSION batch belongs to, found in
15
+ * the RENDERED list (a folder that was deleted under the selection is not a
16
+ * scope);
17
+ * - **what is available** — every workspace id in workspace mode, the scope
18
+ * folder's offerable rows in session mode, nothing otherwise;
19
+ * - **what is selected** — `liveSelection`, so an id that vanished from the
20
+ * list is neither counted nor sent to the server.
21
+ *
22
+ * The binding object it returns is the shape both category components read
23
+ * (`BatchBinding`), so a row cannot grow a checkbox in one layout and not the
24
+ * other.
25
+ */
26
+
27
+ import { useCallback } from 'preact/hooks';
28
+ import { useBatchSelection } from '@/client/hooks/workspace/batch-selection';
29
+ import { useBatchDeleteRun } from '@/client/hooks/workspace/batch-delete-run';
30
+ import { useBatchArchiveRun } from '@/client/hooks/workspace/batch-archive-run';
31
+ import { liveSelection, selectableSessionIds } from '@/shared/lib/workspace/batch-select';
32
+ import type { BatchSelectionHandle } from '@/client/hooks/workspace/batch-selection';
33
+ import type { BatchDeleteRun } from '@/client/hooks/workspace/batch-delete-run';
34
+ import type { BatchArchiveRun } from '@/client/hooks/workspace/batch-archive-run';
35
+ import type { BatchBinding } from '@/client/components/common/batch-selection/types';
36
+ import type { WorkspaceFolderData } from '@/shared/types';
37
+
38
+ export interface SidebarBatch {
39
+ /** The raw selection handle, for the bar's select-all/unselect-all and end. */
40
+ selection: BatchSelectionHandle;
41
+ /** The same machine's delete run, for the bar and the confirmation dialog. */
42
+ deleteRun: BatchDeleteRun;
43
+ /** The same machine's archive run, for the bar's Archive action. */
44
+ archiveRun: BatchArchiveRun;
45
+ /** Present only while a mode is active. */
46
+ binding: BatchBinding | undefined;
47
+ /** The workspace a session batch is scoped to, or null. */
48
+ scopeFolder: WorkspaceFolderData | null;
49
+ /** Ids the bar may act on right now. */
50
+ available: string[];
51
+ /** Ids actually selected, pruned against `available`. */
52
+ selected: string[];
53
+ /** The toolbar/chip Select control: toggles workspace mode. */
54
+ toggleWorkspaceSelection: () => void;
55
+ }
56
+
57
+ export function useSidebarBatch(
58
+ folders: WorkspaceFolderData[],
59
+ showArchived: boolean,
60
+ refresh: () => void,
61
+ ): SidebarBatch {
62
+ const selection = useBatchSelection();
63
+ const deleteRun = useBatchDeleteRun(refresh);
64
+ const archiveRun = useBatchArchiveRun(refresh);
65
+
66
+ const scopeFolder = selection.scopeFolderId === null
67
+ ? null
68
+ : folders.find((folder) => folder.id === selection.scopeFolderId) ?? null;
69
+
70
+ const available = selection.mode === 'workspace'
71
+ ? folders.map((folder) => String(folder.id))
72
+ : selection.mode === 'session'
73
+ ? selectableSessionIds(scopeFolder?.sessions ?? [], showArchived)
74
+ : [];
75
+ const selected = liveSelection(selection.selected, available);
76
+
77
+ const binding: BatchBinding | undefined = selection.mode
78
+ ? {
79
+ mode: selection.mode,
80
+ scopeFolderId: selection.scopeFolderId,
81
+ selected: selection.selected,
82
+ toggle: selection.toggle,
83
+ selectAllOf: selection.selectAllOf,
84
+ unselectAllOf: selection.unselectAllOf,
85
+ summaryOf: selection.summaryOf,
86
+ }
87
+ : undefined;
88
+
89
+ const toggleWorkspaceSelection = useCallback(() => {
90
+ if (selection.mode === 'workspace') selection.end();
91
+ else selection.begin('workspace');
92
+ }, [selection]);
93
+
94
+ return { selection, deleteRun, archiveRun, binding, scopeFolder, available, selected, toggleWorkspaceSelection };
95
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The one reader/writer of the session sidebar's style.
8
+ *
9
+ * A style picks a Preact component tree (`SessionsView`'s switch), so something
10
+ * in JavaScript must re-render when it changes — `appSettings` is a boot-time
11
+ * prop and would only show a new style after a reload. The settings modal calls
12
+ * `applySidebarStyle` when the value moves, which announces
13
+ * `omp:sidebar-style-changed`; `useSidebarStyle` is the single subscriber and
14
+ * the two sidebars (desktop dock, phone drawer) are its only consumers.
15
+ *
16
+ * The initial value comes from the primed settings snapshot
17
+ * (`primeKabmoSettings` in `main.tsx`), so a mounted sidebar draws the stored
18
+ * style on its first render — no flash of the other variant.
19
+ */
20
+
21
+ import { useState } from 'preact/hooks';
22
+ import { readKabmoSetting } from '@/shared/lib/settings/client';
23
+ import { useKabmoEvent } from '@/client/hooks/ui/window-event';
24
+ import type { SettingsState } from '@/shared/types';
25
+ import {
26
+ resolveSidebarStyle,
27
+ type SidebarStyle,
28
+ } from '@/shared/lib/workspace/sidebar-style';
29
+
30
+ /**
31
+ * `app_settings` key holding the style (in the `kabmo_settings` blob).
32
+ *
33
+ * `satisfies keyof SettingsState` because the key and the field name must be
34
+ * the same string for persistence to work at all — renaming the field without
35
+ * this line would leave the setting silently unsaved.
36
+ */
37
+ export const SIDEBAR_STYLE_SETTING_KEY = 'sidebarStyle' satisfies keyof SettingsState;
38
+
39
+ /** Window event carrying the resolved style as `detail`. */
40
+ export const SIDEBAR_STYLE_CHANGED_EVENT = 'omp:sidebar-style-changed';
41
+
42
+ /** The stored style, resolved against what this build can draw. */
43
+ export function currentSidebarStyle(appSettings?: Record<string, any>): SidebarStyle {
44
+ return resolveSidebarStyle(readKabmoSetting<unknown>(SIDEBAR_STYLE_SETTING_KEY, appSettings));
45
+ }
46
+
47
+ /**
48
+ * Announce a new style. Called by the settings modal when the value changes —
49
+ * the persisted copy is written by the modal's own `writeKabmoSettings`, so
50
+ * this function only has to make the mounted sidebar re-render.
51
+ */
52
+ export function applySidebarStyle(style: unknown): void {
53
+ if (typeof window === 'undefined') return;
54
+ window.dispatchEvent(
55
+ new CustomEvent(SIDEBAR_STYLE_CHANGED_EVENT, { detail: resolveSidebarStyle(style) }),
56
+ );
57
+ }
58
+
59
+ /** The style the sidebar should draw, kept live across settings edits. */
60
+ export function useSidebarStyle(): SidebarStyle {
61
+ const [style, setStyle] = useState<SidebarStyle>(() => currentSidebarStyle());
62
+ useKabmoEvent(SIDEBAR_STYLE_CHANGED_EVENT, (event) => {
63
+ setStyle(resolveSidebarStyle((event as CustomEvent<unknown>).detail));
64
+ });
65
+ return style;
66
+ }
@@ -326,6 +326,117 @@
326
326
  margin-inline: auto;
327
327
  }
328
328
 
329
+ /* ---- Composer style -------------------------------------------------------
330
+ *
331
+ * The composer's style states ORDER and STRUCTURE in JavaScript
332
+ * (`shared/lib/chat/composer/style.ts`) and its PIXELS here, keyed by two
333
+ * attributes the card carries. The split is not stylistic: Tailwind resolves
334
+ * two utilities of the same property by the order its RULES were emitted, so a
335
+ * style writing `rounded-md` into the same element as the expansion frame's
336
+ * `rounded-xl` rendered 12px regardless of class order (measured on `console`).
337
+ * These rules are plain CSS, unlayered, so they beat both utilities.
338
+ *
339
+ * `classic` states nothing: it is the shipped card, and every rule below is an
340
+ * OVERRIDE of it.
341
+ */
342
+ [data-composer-style="calm"] {
343
+ border-radius: 1rem; /* rounded-2xl */
344
+ }
345
+ [data-composer-style="calm"] .composer-attach-row {
346
+ padding-bottom: 0.25rem;
347
+ }
348
+ [data-composer-style="calm"] .composer-toolbar-row {
349
+ padding-bottom: 0.375rem;
350
+ }
351
+ [data-composer-style="calm"] .composer-draft {
352
+ padding-inline: 0.875rem;
353
+ padding-top: 0.875rem;
354
+ }
355
+
356
+ [data-composer-style="console"] {
357
+ border-radius: 0.375rem; /* rounded-md */
358
+ }
359
+ [data-composer-style="console"] .composer-draft {
360
+ font-family: 'Fira Code', ui-monospace, SFMono-Regular, monospace;
361
+ font-size: 12.5px;
362
+ }
363
+ [data-composer-style="console"] .composer-attach-row,
364
+ [data-composer-style="console"] .composer-toolbar-row {
365
+ padding-bottom: 0.25rem;
366
+ }
367
+
368
+ /* `glass` — a translucent capsule. The ONE style that departs from the paper
369
+ * identity in `DESIGN.md` §4 (flat, opaque, zero gradients), and it is here
370
+ * because it was asked for as a choice, not because the default changed.
371
+ *
372
+ * Everything is still a TOKEN: no raw hex, no chroma. The frosted surface is
373
+ * `--theme-paper` at 58%, the sheen is `--theme-ink` at 3–5%, so every palette
374
+ * in the catalog moves this card with it. That is also why the source render's
375
+ * "coloured glow behind send" is NOT reproduced: chroma is reserved for
376
+ * `--theme-error` (`DESIGN.md` §1), and a style is not a licence to break it.
377
+ *
378
+ * The blur has nothing to blur in the DOCKED state — the card sits below the
379
+ * transcript in normal flow, over the canvas — so there it reads as frosted
380
+ * paper. It has a real subject when the phone STRETCHES the composer over the
381
+ * transcript (`fixed inset-0`), which is the state the effect was drawn for.
382
+ */
383
+ [data-composer-style="glass"] {
384
+ border-radius: 1.25rem;
385
+ border-color: color-mix(in srgb, var(--theme-ink) 12%, transparent);
386
+ background-color: color-mix(in srgb, var(--theme-paper) 58%, transparent);
387
+ background-image: linear-gradient(
388
+ 180deg,
389
+ color-mix(in srgb, var(--theme-ink) 5%, transparent) 0%,
390
+ color-mix(in srgb, var(--theme-ink) 1.5%, transparent) 38%,
391
+ transparent 100%
392
+ );
393
+ backdrop-filter: blur(16px) saturate(1.15);
394
+ -webkit-backdrop-filter: blur(16px) saturate(1.15);
395
+ box-shadow: 0 1px 0 0 color-mix(in srgb, var(--theme-ink) 6%, transparent);
396
+ }
397
+ [data-composer-style="glass"] .composer-attach-row {
398
+ padding-bottom: 0.25rem;
399
+ }
400
+ [data-composer-style="glass"] .composer-toolbar-row {
401
+ padding-bottom: 0.5rem;
402
+ }
403
+ [data-composer-style="glass"] .composer-draft {
404
+ padding-inline: 1rem;
405
+ padding-top: 0.875rem;
406
+ }
407
+ /* A browser without `backdrop-filter` gets an opaque card rather than a
408
+ * half-transparent one with nothing behind the blur: a 58% paper card over the
409
+ * canvas is legible, a 58% card over the transcript is not. */
410
+ @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
411
+ [data-composer-style="glass"] {
412
+ background-color: var(--theme-paper);
413
+ }
414
+ }
415
+
416
+ /* A card that FILLS the viewport has no corners. The style rules above set a
417
+ * radius as plain CSS, so they beat the expansion frame's own `rounded-none`
418
+ * (measured: a stretched `glass` card kept 20px over a `fixed inset-0` surface,
419
+ * showing the canvas at its corners — and `console` kept 6px the same way).
420
+ * One rule, after every style, stated once. */
421
+ [data-composer-style][data-composer-expanded="true"] {
422
+ border-radius: 0;
423
+ }
424
+
425
+ /* `stage` differs ONLY while the chat is still empty, and only in the card and
426
+ * the draft: a taller, softer frame so the first prompt is not written into a
427
+ * 68px slot in the middle of a blank screen. `hero` is written by the composer
428
+ * from the transcript's own length. */
429
+ [data-composer-hero="true"] {
430
+ border-radius: 1rem;
431
+ border-color: color-mix(in srgb, var(--theme-ink) 15%, transparent);
432
+ }
433
+ [data-composer-hero="true"] .composer-draft {
434
+ min-height: 132px;
435
+ padding-inline: 1rem;
436
+ padding-block: 0.875rem;
437
+ }
438
+
439
+
329
440
  /* Markdown rendered output (marked) — mirrors the previous react-markdown
330
441
  * component styling with semantic tags. */
331
442
  :root {
@@ -9,28 +9,20 @@ import { resolveRunPassword } from '@/server/lib/auth/env-password';
9
9
  import { readHandoverFromStdin } from '@/shared/lib/auth/handover';
10
10
  import { ssrRoutes } from '@/server/plugins/ssr';
11
11
  import { setListener } from '@/server/lib/lifecycle/listener';
12
- import { getDatabasePath, getDb } from '@/server/db.server';
13
- import { compactChatOverlayRows } from '@/server/lib/db/compact-chat-overlay';
12
+ import { getDatabasePath } from '@/server/db.server';
14
13
  import { logDetectedRegistry } from '@/server/lib/models/detected-registry.server';
15
14
  import { ompStartupError, ompStartupLogLines } from '@/server/lib/omp/core/startup';
16
15
  import { readInstanceRecord, removeInstanceRecord, writeInstanceRecord } from '@/server/lib/lifecycle/instance';
17
16
  import { resolveLaunchMode } from '@/server/lib/lifecycle/launch-mode';
18
17
  import { isTrayEnabledByArgv } from '@/server/lib/lifecycle/argv-flags';
19
- import { ensureTray } from '@/server/lib/tray/runtime.server';
20
- import { packageDir } from '@/server/lib/fs/package-root';
21
18
  import { acquirePortLock, claimPort, PortInUseError } from '@/server/lib/lifecycle/port-guard';
22
19
  import { ensureTlsCertificate, isTlsEnabledByArgv } from '@/server/lib/lifecycle/tls';
23
20
  import { SHELL_ROUTE } from '@/server/lib/lifecycle/shell-route';
24
21
  import { isMockMode } from '@/server/mock.server';
25
22
  import { migrateLegacyDataDir } from '@/server/lib/lifecycle/paths';
26
- import { stopDiscoveryRootsWatch, syncDiscoveryRootsWatch } from '@/server/lib/omp/config/roots-watch.server';
27
- import { installMemoryMaintenance, stopMemoryMaintenance } from '@/server/lib/lifecycle/memory';
28
- import { startScheduleRuntime, stopScheduleRuntime } from '@/server/lib/schedule/runtime.server';
29
- import { startWaitingRuntime, stopWaitingRuntime } from '@/server/lib/waiting/runtime.server';
30
23
  import { seedDefaultMarketplace } from '@/server/lib/panels/seed.server';
31
- import { syncBundledPlugins } from '@/server/lib/panels/sync.server';
32
- import { startPanelAutoUpdate } from '@/server/lib/panels/auto-update.server';
33
- import { disposeAllPluginsOnShutdown, loadPluginServers } from '@/server/lib/plugins/loader.server';
24
+ import { installRejectionGuard } from '@/server/lib/lifecycle/rejection-guard';
25
+ import { installShutdownHandlers, runAfterListenTasks } from '@/server/lib/lifecycle/after-listen';
34
26
 
35
27
  // A pre-rename install keeps its database, login and sessions: the data
36
28
  // directory is moved into place before ANYTHING reads a path under it. This is
@@ -38,6 +30,11 @@ import { disposeAllPluginsOnShutdown, loadPluginServers } from '@/server/lib/plu
38
30
  // instance record and the SQLite file all live there.
39
31
  migrateLegacyDataDir();
40
32
 
33
+ // Before anything starts a timer, a plugin or a socket: a rejection from code we
34
+ // do not own (a marketplace plugin's own background loop) must be REPORTED, not
35
+ // allowed to exit a process that hosts every live session. See the module.
36
+ installRejectionGuard();
37
+
41
38
  // Refuse to run without a resolvable omp binary — before the listener opens and
42
39
  // before the first request can reach a route that shells out to it. The database
43
40
  // is opened lazily by getDb(), so this exits without touching it.
@@ -223,126 +220,5 @@ await logDetectedRegistry();
223
220
 
224
221
  console.log(`[kabmo] listening on ${tlsOptions ? 'https' : 'http'}://${host}:${port}`);
225
222
 
226
- /**
227
- * One-time rewrite of the overlay rows written before `overlayRowsForOmpSession`
228
- * existed. Deliberately HERE and NOT inside `getDb()`: the test suite reaches
229
- * `getDb()` in real mode, and opening a database must not launch a rewrite of
230
- * every mirrored conversation (measured: a `bun test` run compacted a live one).
231
- * Marker-keyed, so from the second start it is one indexed SELECT.
232
- */
233
- try {
234
- await compactChatOverlayRows(await getDb());
235
- } catch (error) {
236
- console.error('[chat-overlay] compaction skipped:', error);
237
- }
238
-
239
- /**
240
- * Watch the skill/command roots omp reads, so a SKILL.md written by anything
241
- * other than Kabmo (a hand edit, `git pull`, the skills CLI, another
242
- * agent) reaches the live sessions without a restart. See the module — the
243
- * refresh itself is `/reload-plugins`, this only decides when.
244
- */
245
- try {
246
- await syncDiscoveryRootsWatch();
247
- } catch (error) {
248
- console.error('[discovery-watch] watcher setup skipped:', error);
249
- }
250
-
251
- /**
252
- * The scheduled-task clock. Started after the listener is up and the watchers
253
- * are attached, so a task that fires early cannot race the schema or the
254
- * discovery roots; the runtime's own first tick is delayed for the same reason.
255
- * Idempotent, and anchored on `globalThis` — a `bun --hot` reload must not
256
- * leave a second interval running.
257
- */
258
- startScheduleRuntime();
259
-
260
- /**
261
- * The waiting-prompt clock: a prompt held until another session finishes. Same
262
- * shape and the same placement — after the listener and the watchers, because
263
- * the first sweep may spawn an omp child.
264
- */
265
- startWaitingRuntime();
266
-
267
- /**
268
- * Bring installed BUNDLED plugins up to the copy this package ships.
269
- *
270
- * A Kabmo update replaces the store and leaves the install — it is a
271
- * copied directory of ordinary files — so this is the only thing that notices.
272
- * An install Kabmo wrote is compared by CONTENT, so a shipped fix applies even
273
- * when its version did not move; a directory of unknown provenance keeps the
274
- * version gate, and git clones are skipped, so a plugin the user installed from
275
- * a URL is never overwritten by a store entry that happens to share its id.
276
- *
277
- * BEFORE the server halves load, and that order is the whole point: a plugin's
278
- * server half is `import()`ed from its BUILT bundle, so whichever copy is on
279
- * disk when that import runs is the code this process runs until it restarts.
280
- * Running the sync second meant the boot that shipped a fix loaded the OLD
281
- * bundle (measured: a boot logging `synced command-runner 1.0.1 → 1.0.2` had
282
- * already loaded the 1.0.1 half, so the panel kept spawning with the pre-fix
283
- * environment until a manual restart). Syncing first makes the boot that
284
- * installs a fix the boot that runs it.
285
- */
286
- try {
287
- const synced = await syncBundledPlugins();
288
- for (const item of synced.updated) {
289
- // A content-only sync has no version to show, and printing `1.0.0 → 1.0.0`
290
- // would read as a no-op when a shipped fix actually landed.
291
- const span = item.contentOnly ? `${item.to} (content changed, version unchanged)` : `${item.from} → ${item.to}`;
292
- console.log(`[kabmo] plugins: synced ${item.pluginId} ${span}`);
293
- if (item.warning) console.error(`[plugins] ${item.pluginId}: rebuild after sync failed — ${item.warning}`);
294
- }
295
- for (const failure of synced.failed) console.error(`[plugins] ${failure.pluginId}: bundled sync failed — ${failure.error}`);
296
- } catch (error) {
297
- console.error('[plugins] bundled sync skipped:', error);
298
- }
299
-
300
- /**
301
- * The plugin platform's server half. After the listener is up, the scheduled-task
302
- * clock exists — a plugin's own schedules register with that runtime — and the
303
- * bundled sync above, so the module imported here is the copy this package
304
- * ships. Never throws: one broken plugin must not stop the boot, and its reason
305
- * is reported here and by `GET /api/plugins`.
306
- */
307
- try {
308
- const result = await loadPluginServers();
309
- if (result.loaded.length > 0) {
310
- console.log(`[kabmo] plugins: ${result.loaded.length} server half(s) loaded (${result.loaded.join(', ')})`);
311
- }
312
- for (const failure of result.errors) console.error(`[plugins] ${failure.pluginId}: ${failure.reason}`);
313
- } catch (error) {
314
- console.error('[plugins] server halves skipped:', error);
315
- }
316
-
317
- /** The git-plugin freshness clock. Opt-in, started after the plugin platform so
318
- * its first pass sees the installed plugins; the setting is re-read each pass. */
319
- startPanelAutoUpdate();
320
-
321
- /**
322
- * The tray icon, when `--tray` was passed (`serve --tray`, or the login entry
323
- * the CLI writes for `--startup`). After the listener is up, because the config
324
- * carries the URL the icon opens. Never throws: a machine with no tray client
325
- * (Linux without yad/zenity) reports why and keeps serving.
326
- */
327
- if (isTrayEnabledByArgv()) {
328
- const result = ensureTray({ port, host, tls: Boolean(tlsOptions), pkgRoot: packageDir() });
329
- if (result.started) console.log('[kabmo] tray: icon shown');
330
- else console.log(`[kabmo] tray: not shown — ${result.reason}`);
331
- }
332
-
333
- // A full collection past the ceiling, never a schedule (`lib/lifecycle/memory.ts`).
334
- installMemoryMaintenance();
335
-
336
- for (const signal of ['SIGTERM', 'SIGINT'] as const) {
337
- process.once(signal, () => {
338
- stopDiscoveryRootsWatch();
339
- stopMemoryMaintenance();
340
- stopScheduleRuntime();
341
- stopWaitingRuntime();
342
- void app.stop();
343
- // Plugins own children and listeners nothing else releases, and a detached
344
- // child outlives its parent — so this is awaited BEFORE the exit. It is
345
- // bounded internally, so a plugin that hangs cannot hold the port.
346
- void disposeAllPluginsOnShutdown().finally(() => process.exit(0));
347
- });
348
- }
223
+ await runAfterListenTasks({ port, host, tls: Boolean(tlsOptions) });
224
+ installShutdownHandlers(() => void app.stop());