@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
@@ -81,7 +81,23 @@ export function createPluginBackground(pluginId: string, now = Date.now()): {
81
81
  // The start runs HERE, at declaration: a service that needed the loader to
82
82
  // begin would be a service that does not exist for the first tick, and the
83
83
  // ordering between "started" and "scheduled" would depend on the loader.
84
- void service.start();
84
+ //
85
+ // Its RETURNED promise is contained, because a service is plugin code and a
86
+ // rejection nobody holds is fatal to the whole server. A synchronous throw
87
+ // still propagates (the loader reports a plugin that cannot load); only the
88
+ // async half is caught, and it is reported under the plugin's own name
89
+ // rather than swallowed.
90
+ //
91
+ // This catches a plugin that `return`s its promise. It does NOT catch one
92
+ // that starts a floating `async` IIFE inside `start()` — measured, the
93
+ // stats plugin's sampler does exactly that, so its `SQLITE_IOERR_VNODE`
94
+ // never reached this line. The process boundary handles that case
95
+ // (`installRejectionGuard`, called from the entry).
96
+ void Promise.resolve(service.start()).catch((error) => {
97
+ console.error(
98
+ `[plugins] ${pluginId}: service "${id}" failed — ${error instanceof Error ? error.message : String(error)}`,
99
+ );
100
+ });
85
101
  },
86
102
  schedule(id, spec, run) {
87
103
  if (typeof run !== 'function') throw new Error(`schedule "${id}" has no run()`);
@@ -44,6 +44,39 @@ describe('background', () => {
44
44
  expect(handle.services[0]?.id).toBe('poller');
45
45
  });
46
46
 
47
+ test('a service that rejects is reported, not left to kill the process', async () => {
48
+ // Measured failure this pins: the stats plugin's sampler re-reads its
49
+ // interval from the database, and a data directory that vanished under it
50
+ // produced `SQLITE_IOERR_VNODE` from a floating promise — Bun exits 1 on an
51
+ // unhandled rejection, so one plugin's background loop took the whole server
52
+ // (and every session in it) down. The rejection must be logged instead.
53
+ const rejections: unknown[] = [];
54
+ const onRejection = (reason: unknown) => void rejections.push(reason);
55
+ process.on('unhandledRejection', onRejection);
56
+ const errors: string[] = [];
57
+ const originalError = console.error;
58
+ console.error = (...args: unknown[]) => void errors.push(args.map(String).join(' '));
59
+ try {
60
+ const { api } = createPluginBackground('alpha');
61
+ api.service('sampler', { start: async () => { throw new Error('disk I/O error'); } });
62
+ // One macrotask is enough for the rejection to settle and be handled.
63
+ await new Promise((resolve) => setTimeout(resolve, 0));
64
+ } finally {
65
+ console.error = originalError;
66
+ process.off('unhandledRejection', onRejection);
67
+ }
68
+ expect(rejections).toEqual([]);
69
+ expect(errors).toHaveLength(1);
70
+ expect(errors[0]).toContain('alpha');
71
+ expect(errors[0]).toContain('sampler');
72
+ expect(errors[0]).toContain('disk I/O error');
73
+ });
74
+
75
+ test('a service that throws synchronously still refuses to load the plugin', () => {
76
+ const { api } = createPluginBackground('alpha');
77
+ expect(() => api.service('broken', { start: () => { throw new Error('no start'); } })).toThrow('no start');
78
+ });
79
+
47
80
  test('a schedule resolves its next fire with Kabmo own grammar', () => {
48
81
  const { api, handle } = createPluginBackground('alpha', 1_000_000);
49
82
  api.schedule('sweep', '5m', () => {});
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The batch archive route's contract.
8
+ *
9
+ * These are request-shape and verdict checks: a malformed body must be refused
10
+ * before anything is written, a valid id must actually land in
11
+ * `archived_sessions`, and the two "not a real session" cases (a pending
12
+ * `new-…` chat and a traversal id) must be per-id refusals while the rest of
13
+ * the batch still runs.
14
+ */
15
+
16
+ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
17
+ import { batchArchiveSessions } from '@/server/routes/sessions/batch-archive';
18
+ import { getDb } from '@/server/db.server';
19
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
20
+
21
+ beforeAll(async () => {
22
+ // This suite reaches the database: `batchArchiveSessions` resolves `getDb()`.
23
+ await isolateDb();
24
+ });
25
+
26
+ afterAll(async () => {
27
+ await releaseDb();
28
+ });
29
+
30
+ function post(body: unknown, url = 'http://localhost/api/sessions/batch-archive'): Promise<Response> {
31
+ return batchArchiveSessions({
32
+ request: new Request(url, {
33
+ method: 'POST',
34
+ headers: { 'content-type': 'application/json' },
35
+ body: JSON.stringify(body),
36
+ }),
37
+ params: {},
38
+ } as never) as Promise<Response>;
39
+ }
40
+
41
+ async function isArchived(id: string): Promise<boolean> {
42
+ const db = await getDb();
43
+ return Boolean(await db.get('SELECT session_id FROM archived_sessions WHERE session_id = ?', [id]));
44
+ }
45
+
46
+ describe('batchArchiveSessions request shape', () => {
47
+ test('a wrong verb is a 405', async () => {
48
+ const res = (await batchArchiveSessions({
49
+ request: new Request('http://localhost/api/sessions/batch-archive', { method: 'DELETE' }),
50
+ params: {},
51
+ } as never)) as Response;
52
+ expect(res.status).toBe(405);
53
+ });
54
+
55
+ test('a non-array ids field is a 400', async () => {
56
+ const res = await post({ ids: 'a' });
57
+ expect(res.status).toBe(400);
58
+ expect(await res.json()).toMatchObject({ error: 'ids must be an array of session ids' });
59
+ });
60
+
61
+ test('an empty selection is a 400 rather than a no-op success', async () => {
62
+ const res = await post({ ids: [] });
63
+ expect(res.status).toBe(400);
64
+ });
65
+
66
+ test('an over-long selection is refused', async () => {
67
+ const ids = Array.from({ length: 501 }, (_, index) => `s-${index}`);
68
+ const res = await post({ ids });
69
+ expect(res.status).toBe(400);
70
+ });
71
+ });
72
+
73
+ describe('batchArchiveSessions verdicts', () => {
74
+ test('a valid id is archived and the row exists', async () => {
75
+ const res = await post({ ids: ['session-a'] });
76
+ expect(res.status).toBe(200);
77
+ const body = await res.json() as { success: boolean; archived: string[]; refused: unknown[] };
78
+ expect(body.success).toBe(true);
79
+ expect(body.archived).toEqual(['session-a']);
80
+ expect(body.refused).toEqual([]);
81
+ expect(await isArchived('session-a')).toBe(true);
82
+ });
83
+
84
+ test('archiving is idempotent — the same id twice is one row', async () => {
85
+ await post({ ids: ['session-b', 'session-b'] });
86
+ const db = await getDb();
87
+ const rows = await db.all('SELECT session_id FROM archived_sessions WHERE session_id = ?', ['session-b']);
88
+ expect(rows).toHaveLength(1);
89
+ });
90
+
91
+ test('a pending chat is refused per id while the rest still archives', async () => {
92
+ const res = await post({ ids: ['new-1758800000000', 'session-c'] });
93
+ expect(res.status).toBe(200);
94
+ const body = await res.json() as {
95
+ success: boolean;
96
+ archived: string[];
97
+ refused: { id: string; code?: string }[];
98
+ };
99
+ expect(body.success).toBe(false);
100
+ expect(body.archived).toEqual(['session-c']);
101
+ expect(body.refused.map((entry) => entry.id)).toEqual(['new-1758800000000']);
102
+ expect(body.refused[0].code).toBe('session_pending');
103
+ expect(await isArchived('new-1758800000000')).toBe(false);
104
+ expect(await isArchived('session-c')).toBe(true);
105
+ });
106
+
107
+ test('a traversal id is refused without touching the tree', async () => {
108
+ const res = await post({ ids: ['..'] });
109
+ const body = await res.json() as { archived: string[]; refused: { code?: string }[] };
110
+ expect(body.archived).toEqual([]);
111
+ expect(body.refused[0].code).toBe('invalid_id');
112
+ });
113
+ });
@@ -0,0 +1,80 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * POST /api/sessions/batch-archive — archive several sessions in one request.
8
+ *
9
+ * The sidebar's session batch mode is one user action over N rows, so it is one
10
+ * request: a client loop would pay N round trips and republish the sidebar N
11
+ * times for a single click.
12
+ *
13
+ * Archiving is the reversible sibling of delete — the row moves between the
14
+ * sidebar's archive view and its normal list, and the transcript is untouched
15
+ * (see `archiveSession`). It therefore needs no busy-child check and no
16
+ * destructive confirmation; the only refusals are the two "this id names
17
+ * something other than a real session" cases the single verbs already share:
18
+ * a pending `new-…` chat (there is no transcript to archive yet) and an id that
19
+ * is not one path segment.
20
+ *
21
+ * A refusal is a verdict, never an abort: a batch holding one pending chat
22
+ * still archives the rest, and the caller is told which ids survived and why.
23
+ */
24
+
25
+ import { json } from '@/server/lib/remix-compat';
26
+ import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
27
+ import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
28
+ import { getDb } from '@/server/db.server';
29
+ import { isSinglePathSegment } from '@/server/lib/fs/path-segment';
30
+ import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
31
+
32
+ /** One request cannot carry an unbounded selection. */
33
+ const MAX_BATCH = 500;
34
+
35
+ export async function batchArchiveSessions({ request }: ActionFunctionArgs) {
36
+ if (request.method !== 'POST') {
37
+ return methodNotAllowed({ request, params: {} });
38
+ }
39
+
40
+ const parsed = await parseJsonBody<{ ids?: unknown }>(request);
41
+ if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
42
+
43
+ const raw = parsed.body.ids;
44
+ if (!Array.isArray(raw) || raw.some((id) => typeof id !== 'string' || id.length === 0)) {
45
+ return json({ error: 'ids must be an array of session ids' }, { status: 400 });
46
+ }
47
+ const ids = [...new Set(raw as string[])];
48
+ if (ids.length === 0) return json({ error: 'No sessions selected' }, { status: 400 });
49
+ if (ids.length > MAX_BATCH) {
50
+ return json({ error: `At most ${MAX_BATCH} sessions can be archived at once.` }, { status: 400 });
51
+ }
52
+
53
+ const db = await getDb();
54
+ const archived: string[] = [];
55
+ const refused: { id: string; error: string; code?: string }[] = [];
56
+
57
+ for (const id of ids) {
58
+ // The same two "names something other than the session it appears to"
59
+ // refusals the single verbs use: a pending chat has no transcript, and an
60
+ // id that is not one path segment cannot name a session.
61
+ if (id.startsWith('new-')) {
62
+ refused.push({ id, error: 'This chat has not been created yet.', code: 'session_pending' });
63
+ continue;
64
+ }
65
+ if (!isSinglePathSegment(id)) {
66
+ refused.push({ id, error: 'Invalid session id', code: 'invalid_id' });
67
+ continue;
68
+ }
69
+ // Idempotent: `session_id` is the primary key, so a session already
70
+ // archived stays archived and the row is not duplicated.
71
+ await db.run('INSERT OR IGNORE INTO archived_sessions (session_id) VALUES (?)', [id]);
72
+ archived.push(id);
73
+ }
74
+
75
+ // Archiving moves sessions between the sidebar's archive view and its normal
76
+ // list, so the structure changed — one republish covers the whole batch.
77
+ if (archived.length > 0) emitRealtimeSignal('sidebar-structure');
78
+
79
+ return json({ success: refused.length === 0, archived, refused });
80
+ }
@@ -15,6 +15,7 @@ import { listSubagents, readSubagentTranscript } from '@/server/routes/sessions/
15
15
  import { cancelSubagent, steerSubagent } from '@/server/routes/sessions/subagent-control';
16
16
  import { deleteSession } from '@/server/routes/sessions/delete';
17
17
  import { batchDeleteSessions } from '@/server/routes/sessions/batch-delete';
18
+ import { batchArchiveSessions } from '@/server/routes/sessions/batch-archive';
18
19
 
19
20
  export const sessionsBindings: HandlerBinding[] = [
20
21
  ...bindingsFor(sessionsList, '/api/sessions/list'),
@@ -22,6 +23,9 @@ export const sessionsBindings: HandlerBinding[] = [
22
23
  // batch route is POST while `:sessionId` answers DELETE, so an id route
23
24
  // winning the match would turn every batch into a 405.
24
25
  { method: 'POST', path: '/api/sessions/batch-delete', handler: batchDeleteSessions },
26
+ // The archive batch is static too, and must be registered before the
27
+ // `:sessionId` routes for the same reason as batch-delete.
28
+ { method: 'POST', path: '/api/sessions/batch-archive', handler: batchArchiveSessions },
25
29
  ...bindingsFor(sessionsFolder, '/api/sessions/:sessionId'),
26
30
  // DELETE-only on the same path the folder loader answers GET on: mounting it
27
31
  // through `actionBindings` would register a 405 GET fallback that Elysia
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { describe, expect, test } from 'bun:test';
7
+ import {
8
+ COMPOSER_STYLES,
9
+ COMPOSER_STYLE_COPY,
10
+ DEFAULT_COMPOSER_STYLE,
11
+ composerStyleLayout,
12
+ isComposerStyle,
13
+ resolveComposerStyle,
14
+ type ComposerRow,
15
+ } from '@/shared/lib/chat/composer/style';
16
+
17
+ /**
18
+ * Every row the composer renders. The list is EXHAUSTIVE BY CONTRACT: a style
19
+ * that omits one is a style that drops a control the user cannot get back —
20
+ * the worst case being the access-mode selector, which decides whether a turn
21
+ * may write to disk.
22
+ */
23
+ const EVERY_ROW: readonly ComposerRow[] = ['attachments', 'notice', 'draft', 'voice', 'toolbar'];
24
+
25
+ describe('composer style table', () => {
26
+ test('every style renders every row exactly once', () => {
27
+ for (const style of COMPOSER_STYLES) {
28
+ for (const hero of [false, true]) {
29
+ const { rows } = composerStyleLayout({ style, hero });
30
+ expect(new Set(rows)).toEqual(new Set(EVERY_ROW));
31
+ expect(rows.length).toBe(EVERY_ROW.length);
32
+ }
33
+ }
34
+ });
35
+
36
+ test('every style has copy in the settings control', () => {
37
+ for (const style of COMPOSER_STYLES) {
38
+ expect(COMPOSER_STYLE_COPY[style].label.length).toBeGreaterThan(0);
39
+ expect(COMPOSER_STYLE_COPY[style].description.length).toBeGreaterThan(20);
40
+ }
41
+ });
42
+
43
+ test('the wireframe lists only rows the renderer draws', () => {
44
+ for (const style of COMPOSER_STYLES) {
45
+ const { wire } = composerStyleLayout({ style, hero: false });
46
+ expect(wire.length).toBeGreaterThan(0);
47
+ for (const row of wire) expect(['chip', 'draft', 'controls']).toContain(row);
48
+ }
49
+ });
50
+
51
+ test('the draft is above the toolbar in every style', () => {
52
+ // The one ordering invariant that is not cosmetic: the box a user types
53
+ // into must not sit under the row of controls it belongs to.
54
+ for (const style of COMPOSER_STYLES) {
55
+ const { rows } = composerStyleLayout({ style, hero: false });
56
+ expect(rows.indexOf('draft')).toBeLessThan(rows.indexOf('toolbar'));
57
+ }
58
+ });
59
+
60
+ test('the notice stays attached to the draft it refuses', () => {
61
+ // A refusal rendered above the attachment row would read as a complaint
62
+ // about the file rather than about the send.
63
+ for (const style of COMPOSER_STYLES) {
64
+ const { rows } = composerStyleLayout({ style, hero: false });
65
+ expect(Math.abs(rows.indexOf('notice') - rows.indexOf('draft'))).toBe(1);
66
+ }
67
+ });
68
+
69
+ test('only the console style draws a mono rail and a prompt glyph', () => {
70
+ for (const style of COMPOSER_STYLES) {
71
+ const layout = composerStyleLayout({ style, hero: false });
72
+ const console = style === 'console';
73
+ expect(layout.toolbarTone).toBe(console ? 'rail' : 'plain');
74
+ expect(layout.promptGlyph).toBe(console);
75
+ }
76
+ });
77
+
78
+ test('stage alone reacts to an empty chat, and only through the hero attribute', () => {
79
+ const docked = composerStyleLayout({ style: 'stage', hero: false });
80
+ const hero = composerStyleLayout({ style: 'stage', hero: true });
81
+ // Same rows: the hero state may never add or drop a control.
82
+ expect(hero.rows).toEqual(docked.rows);
83
+ // The pixel difference is CSS's, keyed by this attribute — see the
84
+ // `[data-composer-hero]` rules in `tailwind.css`.
85
+ expect(hero.hero).toBe(true);
86
+ expect(docked.hero).toBe(false);
87
+
88
+ for (const style of COMPOSER_STYLES.filter((s) => s !== 'stage')) {
89
+ expect(composerStyleLayout({ style, hero: true }).hero).toBe(false);
90
+ }
91
+ });
92
+
93
+ test('glass keeps the classic row order — it changes the surface, not the order', () => {
94
+ expect(composerStyleLayout({ style: 'glass', hero: false }).rows).toEqual(
95
+ composerStyleLayout({ style: 'classic', hero: false }).rows,
96
+ );
97
+ expect(composerStyleLayout({ style: 'glass', hero: false }).toolbarTone).toBe('plain');
98
+ expect(composerStyleLayout({ style: 'glass', hero: false }).promptGlyph).toBe(false);
99
+ });
100
+
101
+ test('calm and console move the draft above the attachment chips', () => {
102
+ for (const style of ['calm', 'console'] as const) {
103
+ const { rows } = composerStyleLayout({ style, hero: false });
104
+ expect(rows.indexOf('draft')).toBeLessThan(rows.indexOf('attachments'));
105
+ }
106
+ expect(composerStyleLayout({ style: 'classic', hero: false }).rows.indexOf('attachments')).toBe(0);
107
+ });
108
+ });
109
+
110
+ describe('composer style resolution', () => {
111
+ test('the shipped default is classic, so an upgrade rearranges nothing', () => {
112
+ expect(DEFAULT_COMPOSER_STYLE).toBe('classic');
113
+ expect(resolveComposerStyle(undefined)).toBe('classic');
114
+ });
115
+
116
+ test('a stored style this build draws is returned unchanged', () => {
117
+ for (const style of COMPOSER_STYLES) expect(resolveComposerStyle(style)).toBe(style);
118
+ });
119
+
120
+ test('a value from another build falls back rather than rendering nothing', () => {
121
+ expect(resolveComposerStyle('neon')).toBe('classic');
122
+ expect(resolveComposerStyle(null)).toBe('classic');
123
+ expect(resolveComposerStyle(7)).toBe('classic');
124
+ expect(isComposerStyle('neon')).toBe(false);
125
+ });
126
+ });
@@ -0,0 +1,171 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * What the chat composer LOOKS like, as one of four styles.
8
+ *
9
+ * This is a PRESENTATION choice over one composer, not four composers: every
10
+ * style renders the same controls — the paperclip, the attachment chips, the
11
+ * compact "Type here" target, the stretch control, plan/goal, the notice
12
+ * strip, the draft with its `@`/`/` picker, the dictation notice, the model,
13
+ * thinking and access selectors, plugin actions, voice, stop and send. What
14
+ * changes is the ORDER of the rows and the frame around them.
15
+ *
16
+ * That constraint is the module's reason to exist. A style that could omit a
17
+ * control would be a style that can silently drop the access mode — the one
18
+ * setting that decides whether a turn may write to disk. So the table below
19
+ * names ROWS, never controls: there is no field here that can remove one.
20
+ *
21
+ * - `classic` — chrome above the draft, controls below it. The shipped card.
22
+ * - `calm` — the draft leads; chips and controls sit under it in one
23
+ * quieter rail.
24
+ * - `console` — a mono status rail under the box, with an `omp ›` prompt
25
+ * glyph. The workbench reading of the same controls.
26
+ * - `stage` — `classic` inside a chat, a wider hero card while the session
27
+ * is still empty (see `hero`).
28
+ *
29
+ * Copy lives here with the names; the pixels live with the components that
30
+ * draw them (`chat-input/expansion.ts`, `chat-input/index.tsx`), so neither
31
+ * file restates the other's fact.
32
+ */
33
+
34
+ export type ComposerStyle = 'classic' | 'calm' | 'console' | 'stage' | 'glass';
35
+
36
+ /**
37
+ * Every style, in the order the settings control lists them: the cards that
38
+ * keep today's reading order first, then the two that move it, then the one
39
+ * that changes the SURFACE rather than the order.
40
+ */
41
+ export const COMPOSER_STYLES = ['classic', 'calm', 'console', 'stage', 'glass'] as const;
42
+
43
+ /**
44
+ * The style a document with no stored preference renders at. It is the shape
45
+ * Kabmo has always drawn, so an upgrade rearranges nothing.
46
+ */
47
+ export const DEFAULT_COMPOSER_STYLE: ComposerStyle = 'classic';
48
+
49
+ export function isComposerStyle(value: unknown): value is ComposerStyle {
50
+ return value === 'classic' || value === 'calm' || value === 'console' || value === 'stage' || value === 'glass';
51
+ }
52
+
53
+ /**
54
+ * The style to APPLY for a stored value. Anything this build cannot draw — a
55
+ * value from a newer build, a corrupted blob, `undefined` on a fresh install —
56
+ * falls back to the default rather than to a style no component knows.
57
+ */
58
+ export function resolveComposerStyle(value: unknown): ComposerStyle {
59
+ return isComposerStyle(value) ? value : DEFAULT_COMPOSER_STYLE;
60
+ }
61
+
62
+ export interface ComposerStyleCopy {
63
+ label: string;
64
+ /** One line under the label: the TRADEOFF, not the aesthetic. */
65
+ description: string;
66
+ }
67
+
68
+ export const COMPOSER_STYLE_COPY: Record<ComposerStyle, ComposerStyleCopy> = {
69
+ classic: {
70
+ label: 'Classic',
71
+ description: 'Chrome above the draft, controls below it. Every control visible at once — the densest and the most predictable.',
72
+ },
73
+ calm: {
74
+ label: 'Calm',
75
+ description: 'The draft leads, chips and controls sit under it in one quieter rail. Same controls, less chrome above the typing line.',
76
+ },
77
+ console: {
78
+ label: 'Console',
79
+ description: 'A monospace status rail under the box, with an omp prompt glyph. Reads like the rest of the telemetry UI.',
80
+ },
81
+ stage: {
82
+ label: 'Stage',
83
+ description: 'Classic once a chat is running; a wider, taller card while the session is still empty.',
84
+ },
85
+ glass: {
86
+ label: 'Glass',
87
+ description: 'A translucent capsule: the card is frosted paper over whatever sits behind it, with the draft and controls on one surface. Same controls, softer edge.',
88
+ },
89
+ };
90
+
91
+ /**
92
+ * A row of the composer card, in render order. Rows own the pieces that must
93
+ * stay next to each other (the notice belongs to the draft it refuses), and
94
+ * every one of them is always drawn.
95
+ */
96
+ export type ComposerRow =
97
+ | 'attachments'
98
+ | 'notice'
99
+ | 'draft'
100
+ | 'voice'
101
+ | 'toolbar';
102
+
103
+ /** One bar of the settings card's miniature wireframe. */
104
+ export type ComposerWireRow = 'chip' | 'draft' | 'controls';
105
+
106
+ export interface ComposerStyleLayout {
107
+ /** Rows in render order. Every row is rendered; none is optional. */
108
+ rows: readonly ComposerRow[];
109
+ /** Wireframe for the settings card — the same order, drawn small. */
110
+ wire: readonly ComposerWireRow[];
111
+ /**
112
+ * `rail` renders the control row as a monospace status line. The CONTROLS
113
+ * are the same; only the typography and the separators change.
114
+ */
115
+ toolbarTone: 'plain' | 'rail';
116
+ /** Draw the `omp ›` prompt glyph at the card's leading edge. */
117
+ promptGlyph: boolean;
118
+ /** Read by CSS only, through `[data-composer-style]`. */
119
+ attributeValue: ComposerStyle;
120
+ /** Read by CSS only, through `[data-composer-hero]`. */
121
+ hero: boolean;
122
+ }
123
+
124
+ export interface ComposerStyleInput {
125
+ style: ComposerStyle;
126
+ /** Whether the session is still empty; only `stage` reads it. */
127
+ hero: boolean;
128
+ }
129
+
130
+ /**
131
+ * The layout for a style.
132
+ *
133
+ * A pure table: same inputs, same shape, no DOM and no settings read — which is
134
+ * what makes it testable and what lets the renderer stay a loop over `rows`.
135
+ *
136
+ * **It states ORDER and STRUCTURE only, never a Tailwind size.** A style table
137
+ * that wrote `rounded-md` or `min-h-[132px]` would be a table that loses to the
138
+ * expansion frame's own `rounded-xl` / `min-h-[68px]`: Tailwind resolves two
139
+ * utilities of the same property by the order the rules were EMITTED in, not by
140
+ * the order the classes appear in `className`. Measured on the console style,
141
+ * `rounded-xl rounded-md` rendered 12px. The pixels therefore live in CSS,
142
+ * keyed by the attributes below — the same split `data-chat-width` already uses
143
+ * for the chat column.
144
+ */
145
+ export function composerStyleLayout({ style, hero }: ComposerStyleInput): ComposerStyleLayout {
146
+ const base = { attributeValue: style, hero: style === 'stage' && hero };
147
+
148
+ switch (style) {
149
+ case 'calm':
150
+ return { ...base, rows: ['draft', 'notice', 'attachments', 'voice', 'toolbar'], wire: ['draft', 'chip', 'controls'], toolbarTone: 'plain', promptGlyph: false };
151
+
152
+ case 'console':
153
+ return { ...base, rows: ['notice', 'draft', 'attachments', 'voice', 'toolbar'], wire: ['draft', 'chip', 'controls'], toolbarTone: 'rail', promptGlyph: true };
154
+
155
+ // The hero card is the only difference, and only while empty: a taller
156
+ // draft so the first prompt is not written into a 68px slot in the middle
157
+ // of a blank screen. Everything else is `classic`.
158
+ case 'stage':
159
+ return { ...base, rows: ['attachments', 'notice', 'draft', 'voice', 'toolbar'], wire: ['chip', 'draft', 'controls'], toolbarTone: 'plain', promptGlyph: false };
160
+
161
+ // `glass` is a SURFACE, not an order: it keeps `classic`'s rows and changes
162
+ // only the frame (translucency, blur, a sheen). Stated here rather than
163
+ // implied by the default arm so the intent survives the next style.
164
+ case 'glass':
165
+ return { ...base, rows: ['attachments', 'notice', 'draft', 'voice', 'toolbar'], wire: ['chip', 'draft', 'controls'], toolbarTone: 'plain', promptGlyph: false };
166
+
167
+ case 'classic':
168
+ default:
169
+ return { ...base, rows: ['attachments', 'notice', 'draft', 'voice', 'toolbar'], wire: ['chip', 'draft', 'controls'], toolbarTone: 'plain', promptGlyph: false };
170
+ }
171
+ }
@@ -45,6 +45,9 @@ describe('isTuiOnlySlashCommand', () => {
45
45
  expect(isTuiOnlySlashCommand('/q')).toBe(true);
46
46
  expect(isTuiOnlySlashCommand('/status')).toBe(true);
47
47
  expect(isTuiOnlySlashCommand('/rewind')).toBe(true);
48
+ // `hub` and its 18.14.0 alias `subagents` are the same TUI-only entry.
49
+ expect(isTuiOnlySlashCommand('/hub')).toBe(true);
50
+ expect(isTuiOnlySlashCommand('/subagents')).toBe(true);
48
51
  });
49
52
 
50
53
  test('lets every command omp answers over RPC through', () => {
@@ -77,6 +77,11 @@ export const TUI_ONLY_SLASH_COMMANDS: Record<string, true> = {
77
77
  agents: true,
78
78
  git: true,
79
79
  hub: true,
80
+ // omp 18.14.0 added `subagents` as an ALIAS of the TUI-only `hub`. The guard
81
+ // is keyed on names, so without this row the alias reached the model as
82
+ // literal text — measured on 18.14.0: `/subagents` is absent from
83
+ // `available_commands_update` and `handleTui` is its only handler.
84
+ subagents: true,
80
85
  branch: true,
81
86
  rewind: true,
82
87
  fork: true,