@kabmo-labs/kabmo 0.28.0 → 0.29.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 (225) hide show
  1. package/bunfig.toml +6 -0
  2. package/dist/client/index.html +2 -2
  3. package/dist/client/index.js +481 -472
  4. package/dist/client/static/js/{index-xzvyrxya.js → index-43z47ngg.js} +1193 -1049
  5. package/dist/client/static/js/index-naa91727.css +1 -0
  6. package/dist/client/static/{manifest-q6h8k9e0.webmanifest → manifest-vdvdqpre.webmanifest} +1 -0
  7. package/package.json +3 -2
  8. package/public/manifest.webmanifest +1 -0
  9. package/src/client/components/common/ComposerTextarea.test.tsx +109 -0
  10. package/src/client/components/common/ComposerTextarea.tsx +6 -0
  11. package/src/client/components/common/ReloadPageButton.test.tsx +14 -0
  12. package/src/client/components/common/ReloadPageButton.tsx +11 -2
  13. package/src/client/components/common/diagram-viewer/read-block.test.ts +71 -0
  14. package/src/client/components/common/diagram-viewer/read-block.ts +40 -16
  15. package/src/client/components/common/file-icon/index.tsx +7 -1
  16. package/src/client/components/common/harness-glyph/brands.ts +7 -1
  17. package/src/client/components/common/image-viewer/index.tsx +37 -165
  18. package/src/client/components/common/picker-search/index.tsx +70 -0
  19. package/src/client/components/common/search-select/index.tsx +2 -7
  20. package/src/client/components/common/zoom-pan-stage/index.tsx +258 -0
  21. package/src/client/components/common/zoom-pan-stage/zoom-pan-stage.test.tsx +87 -0
  22. package/src/client/components/layout/session-sidebar/ClassicView.tsx +1 -1
  23. package/src/client/components/layout/session-sidebar/SessionListNotice.tsx +7 -3
  24. package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +4 -1
  25. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +12 -1
  26. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.test.tsx +82 -0
  27. package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +23 -3
  28. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +1 -0
  29. package/src/client/components/layout/session-sidebar/modern/index.tsx +1 -1
  30. package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +6 -4
  31. package/src/client/components/layout/session-sidebar/session-list-states.test.tsx +8 -0
  32. package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +25 -0
  33. package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +1 -1
  34. package/src/client/components/settings/Sidebar.tsx +6 -8
  35. package/src/client/components/settings/categories/HarnessSettings.tsx +4 -2
  36. package/src/client/components/settings/categories/PanelPluginSettings.tsx +2 -2
  37. package/src/client/components/settings/categories/PluginSettings.tsx +1 -1
  38. package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +3 -6
  39. package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +36 -0
  40. package/src/client/components/settings/categories/panel-plugins/Section.tsx +1 -3
  41. package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +18 -4
  42. package/src/client/components/settings/categories/plugin-settings/MarketplacePane.tsx +64 -61
  43. package/src/client/components/settings/categories/plugin-settings/SidebarList.tsx +15 -4
  44. package/src/client/components/settings/groups.test.tsx +2 -2
  45. package/src/client/components/workspace/chat-timeline/IrcNotice.test.tsx +55 -0
  46. package/src/client/components/workspace/chat-timeline/IrcNotice.tsx +71 -0
  47. package/src/client/components/workspace/chat-timeline/MessageItem.tsx +4 -1
  48. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +19 -0
  49. package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +8 -3
  50. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.search.test.tsx +72 -0
  51. package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +42 -15
  52. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +28 -0
  53. package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +28 -10
  54. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +47 -1
  55. package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +55 -5
  56. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +3 -2
  57. package/src/client/components/workspace/editor/FilePane.tsx +32 -0
  58. package/src/client/components/workspace/editor/Toolbar.tsx +4 -0
  59. package/src/client/components/workspace/editor/toolbar-clusters.test.ts +1 -0
  60. package/src/client/components/workspace/editor/toolbar-clusters.tsx +5 -2
  61. package/src/client/components/workspace/editor/viewers/CsvGrid.tsx +52 -5
  62. package/src/client/components/workspace/editor/viewers/DataGrid.tsx +227 -41
  63. package/src/client/components/workspace/editor/viewers/DrawioView.tsx +93 -0
  64. package/src/client/components/workspace/editor/viewers/GridRow.tsx +91 -0
  65. package/src/client/components/workspace/editor/viewers/GridToolbar.tsx +53 -0
  66. package/src/client/components/workspace/editor/viewers/SheetView.tsx +152 -57
  67. package/src/client/components/workspace/editor/viewers/dispatch.tsx +42 -9
  68. package/src/client/components/workspace/editor/viewers/drawio-pages.test.ts +80 -0
  69. package/src/client/components/workspace/editor/viewers/drawio-pages.ts +63 -0
  70. package/src/client/components/workspace/editor/viewers/grid.test.ts +296 -0
  71. package/src/client/components/workspace/editor/viewers/use-cell-edit.ts +64 -0
  72. package/src/client/components/workspace/editor/viewers/use-grid-interaction.ts +216 -0
  73. package/src/client/components/workspace/editor/viewers/viewers.test.ts +47 -2
  74. package/src/client/components/workspace/editor/viewers/workbook.ts +149 -0
  75. package/src/client/components/workspace/file-explorer/ArchiveModals.tsx +262 -0
  76. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +30 -6
  77. package/src/client/components/workspace/file-explorer/Modals.tsx +8 -3
  78. package/src/client/components/workspace/file-explorer/RootOverlays.tsx +60 -0
  79. package/src/client/components/workspace/file-explorer/RowLabel.tsx +6 -2
  80. package/src/client/components/workspace/file-explorer/TreeItem.tsx +39 -49
  81. package/src/client/components/workspace/file-explorer/TreeItemModals.tsx +80 -0
  82. package/src/client/components/workspace/file-explorer/index.tsx +53 -29
  83. package/src/client/components/workspace/file-explorer/selection.test.tsx +109 -0
  84. package/src/client/data/settings/omp-schema.json +169 -22
  85. package/src/client/glass.css +39 -14
  86. package/src/client/glass.test.ts +37 -0
  87. package/src/client/hooks/chat/composer/history.test.ts +267 -0
  88. package/src/client/hooks/chat/composer/history.ts +146 -0
  89. package/src/client/hooks/chat/timeline/ask-frames.test.ts +54 -0
  90. package/src/client/hooks/chat/timeline/ask-frames.ts +29 -1
  91. package/src/client/hooks/chat/timeline/timeline-rail.test.ts +34 -2
  92. package/src/client/hooks/chat/timeline/user-turns.ts +31 -2
  93. package/src/client/hooks/editor/file-editor-types.ts +15 -0
  94. package/src/client/hooks/editor/save-bytes.ts +79 -0
  95. package/src/client/hooks/editor/use-file-editor.test.ts +30 -0
  96. package/src/client/hooks/editor/use-file-editor.ts +53 -5
  97. package/src/client/hooks/editor/use-file-read.ts +21 -2
  98. package/src/client/hooks/editor/use-grid-selection.ts +160 -0
  99. package/src/client/hooks/models/use-harness-update.test.ts +35 -2
  100. package/src/client/hooks/models/use-harness-update.ts +49 -10
  101. package/src/client/hooks/workspace/diff-file.test.ts +72 -0
  102. package/src/client/hooks/workspace/diff-file.ts +12 -6
  103. package/src/client/hooks/workspace/file-archive.ts +220 -0
  104. package/src/client/hooks/workspace/file-clipboard.test.ts +4 -4
  105. package/src/client/hooks/workspace/file-clipboard.ts +37 -26
  106. package/src/client/hooks/workspace/file-selection.test.ts +67 -0
  107. package/src/client/hooks/workspace/file-selection.ts +156 -0
  108. package/src/client/hooks/workspace/file-tree-actions-clipboard.test.ts +5 -5
  109. package/src/client/hooks/workspace/file-tree-actions.ts +36 -8
  110. package/src/client/lib/editor/workbook-drafts.ts +42 -0
  111. package/src/client/lib/launch/file-handlers.ts +2 -2
  112. package/src/client/lib/scrollbar-activity.test.ts +21 -88
  113. package/src/client/lib/scrollbar-activity.ts +71 -73
  114. package/src/client/lib/scrollbar-events.ts +143 -0
  115. package/src/client/lib/scrollbar-input.test.ts +126 -0
  116. package/src/client/lib/scrollbar-probe.test-util.ts +107 -0
  117. package/src/client/tailwind.css +32 -1
  118. package/src/server/db.server.test.ts +50 -1
  119. package/src/server/db.server.ts +36 -3
  120. package/src/server/lib/chat/prompt-history.server.test.ts +92 -0
  121. package/src/server/lib/chat/prompt-history.server.ts +65 -0
  122. package/src/server/lib/chat/schema.server.ts +35 -0
  123. package/src/server/lib/db/schema.ts +3 -0
  124. package/src/server/lib/fs/archive.test.ts +139 -0
  125. package/src/server/lib/fs/archive.ts +259 -0
  126. package/src/server/lib/fs/git-diff.test.ts +26 -1
  127. package/src/server/lib/fs/git-diff.ts +43 -15
  128. package/src/server/lib/harness/launch-table.ts +19 -0
  129. package/src/server/lib/harness/provider-entry.ts +1 -1
  130. package/src/server/lib/harness/provider-file.server.ts +1 -1
  131. package/src/server/lib/harness/provider-sources.server.ts +2 -1
  132. package/src/server/lib/harness/provider-write.server.ts +2 -1
  133. package/src/server/lib/harness/update-job-store.ts +12 -0
  134. package/src/server/lib/harness/update-queue.server.ts +15 -10
  135. package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +5 -1
  136. package/src/server/lib/omp/rpc/frame-fold.test.ts +5 -1
  137. package/src/server/lib/omp/rpc/lifecycle.test.ts +4 -0
  138. package/src/server/lib/omp/session/auto-title.server.test.ts +4 -0
  139. package/src/server/lib/omp/session/delete.server.ts +1 -0
  140. package/src/server/lib/omp/session/goal-driver.test.ts +5 -1
  141. package/src/server/lib/omp/session/goal-settings.test.ts +5 -1
  142. package/src/server/lib/panels/auto-update.server.test.ts +5 -2
  143. package/src/server/lib/panels/git-update.server.test.ts +5 -2
  144. package/src/server/lib/panels/install.server.test.ts +5 -2
  145. package/src/server/lib/panels/remove.server.test.ts +5 -2
  146. package/src/server/routes/agent/command.ts +11 -0
  147. package/src/server/routes/agent/new.ts +5 -0
  148. package/src/server/routes/chat/index.ts +5 -0
  149. package/src/server/routes/chat/prompt-history.test.ts +67 -0
  150. package/src/server/routes/chat/prompt-history.ts +31 -0
  151. package/src/server/routes/chat/stream.test.ts +21 -0
  152. package/src/server/routes/chat/stream.ts +5 -0
  153. package/src/server/routes/fs/action-archive.test.ts +128 -0
  154. package/src/server/routes/fs/action-bulk.ts +106 -0
  155. package/src/server/routes/fs/action-save-bytes.test.ts +59 -0
  156. package/src/server/routes/fs/action-transfer.test.ts +26 -0
  157. package/src/server/routes/fs/action.ts +91 -11
  158. package/src/server/routes/fs/archive.ts +20 -0
  159. package/src/server/routes/fs/grant.test.ts +5 -2
  160. package/src/server/routes/fs/index.ts +2 -0
  161. package/src/server/routes/fs/scope.test.ts +6 -2
  162. package/src/server/routes/harness/import-action.ts +1 -1
  163. package/src/server/routes/harness/root.ts +6 -1
  164. package/src/server/routes/harness/summary.test.ts +50 -0
  165. package/src/server/routes/harness/update-status.ts +41 -2
  166. package/src/server/routes/harness/update.test.ts +56 -2
  167. package/src/server/routes/sessions/delete.test.ts +4 -0
  168. package/src/shared/lib/chat/ask-form/index.ts +39 -31
  169. package/src/shared/lib/chat/ask-form/labels.ts +46 -0
  170. package/src/shared/lib/chat/ask-form/tokens.ts +11 -2
  171. package/src/shared/lib/chat/ask-form.test.ts +57 -0
  172. package/src/shared/lib/chat/ask-questions.ts +31 -0
  173. package/src/shared/lib/chat/composer/history.test.ts +67 -0
  174. package/src/shared/lib/chat/composer/history.ts +61 -0
  175. package/src/shared/lib/chat/irc-notice.ts +42 -0
  176. package/src/shared/lib/chat/timeline/fork-anchor.test.ts +2 -0
  177. package/src/shared/lib/chat/todo/parser.ts +6 -4
  178. package/src/shared/lib/fs/archive.test.ts +101 -0
  179. package/src/shared/lib/fs/archive.ts +191 -0
  180. package/src/shared/lib/fs/clipboard.test.ts +32 -7
  181. package/src/shared/lib/fs/clipboard.ts +59 -14
  182. package/src/shared/lib/fs/csv.test.ts +50 -0
  183. package/src/shared/lib/fs/csv.ts +40 -0
  184. package/src/shared/lib/fs/document-kind.test.ts +13 -6
  185. package/src/shared/lib/fs/document-kind.ts +18 -6
  186. package/src/shared/lib/fs/file-kind-classify.test.ts +4 -0
  187. package/src/shared/lib/fs/file-kind.test.ts +2 -7
  188. package/src/shared/lib/fs/file-kind.ts +4 -2
  189. package/src/shared/lib/fs/grid-edit.test.ts +24 -0
  190. package/src/shared/lib/fs/grid-edit.ts +29 -0
  191. package/src/shared/lib/fs/grid-selection.test.ts +137 -0
  192. package/src/shared/lib/fs/grid-selection.ts +138 -0
  193. package/src/shared/lib/harness/brand-color.ts +5 -0
  194. package/src/shared/lib/harness/catalog.test.ts +22 -0
  195. package/src/shared/lib/harness/catalog.ts +12 -1
  196. package/src/shared/lib/harness/config-fields.test.ts +25 -0
  197. package/src/shared/lib/harness/config-fields.ts +33 -3
  198. package/src/shared/lib/harness/dialects.ts +1 -1
  199. package/src/shared/lib/harness/mcp-facts.ts +4 -0
  200. package/src/shared/lib/harness/provider-contracts.ts +109 -0
  201. package/src/shared/lib/harness/provider-facts.test.ts +2 -1
  202. package/src/shared/lib/harness/provider-facts.ts +24 -115
  203. package/src/shared/lib/harness/provider-lookup.ts +37 -0
  204. package/src/shared/lib/harness/providers.ts +2 -1
  205. package/src/shared/lib/harness/updates.ts +10 -0
  206. package/src/shared/lib/omp/session/mapper.test.ts +31 -0
  207. package/src/shared/lib/omp/session/mapper.ts +17 -0
  208. package/src/shared/lib/omp/session/messages-map-notice.test.ts +68 -0
  209. package/src/shared/lib/omp/session/messages-map.test.ts +1 -35
  210. package/src/shared/lib/omp/session/messages-map.ts +17 -0
  211. package/src/shared/lib/omp/session/wait.ts +10 -1
  212. package/src/shared/lib/settings/sections.ts +8 -4
  213. package/src/shared/lib/ui/picker-filter.test.ts +23 -0
  214. package/src/shared/lib/ui/picker-filter.ts +20 -0
  215. package/src/shared/types/chat.ts +4 -0
  216. package/src/shared/types/harness.ts +5 -1
  217. package/src/shared/types/omp/session.ts +18 -0
  218. package/src/shared/types/settings/state.ts +6 -6
  219. package/src/shared/types/todo.ts +3 -1
  220. package/src/test-support/file-actions.test-util.ts +4 -0
  221. package/src/test-support/file-archive.test-util.ts +41 -0
  222. package/src/test-support/file-clipboard.test-util.ts +9 -6
  223. package/src/test-support/harness-table.test-util.ts +2 -0
  224. package/src/test-support/preload.ts +46 -0
  225. package/dist/client/static/js/index-81f7berm.css +0 -1
@@ -21,6 +21,10 @@ import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
21
21
  import fs from 'fs';
22
22
  import path from 'path';
23
23
  import { deleteSession } from '@/server/routes/sessions/delete';
24
+ import { isolateDb, releaseDb } from '@/test-support/isolated-db';
25
+
26
+ beforeAll(isolateDb);
27
+ afterAll(releaseDb);
24
28
 
25
29
  /**
26
30
  * The 404 branch resolves the id by scanning the sessions directory, so the
@@ -22,6 +22,7 @@
22
22
 
23
23
  import type { AskQuestion } from '@/shared/lib/chat/ask-form/types';
24
24
  import { toQuestions, type DraftField, type DraftOption } from '@/shared/lib/chat/ask-form/fields';
25
+ import { IGNORED_INPUTS, readLabelTargets } from '@/shared/lib/chat/ask-form/labels';
25
26
  import {
26
27
  BLOCK,
27
28
  findChild,
@@ -36,34 +37,6 @@ import {
36
37
  type Token,
37
38
  } from '@/shared/lib/chat/ask-form/tokens';
38
39
 
39
- const IGNORED_INPUTS: Record<string, true> = {
40
- button: true,
41
- file: true,
42
- image: true,
43
- reset: true,
44
- submit: true,
45
- hidden: true,
46
- };
47
-
48
- /** Pre-pass: ids of controls, and the `<label for>` text that names them. */
49
- function readLabelTargets(tokens: Token[]): Map<string, string> {
50
- const ids = new Set<string>();
51
- for (const token of tokens) {
52
- if (token.kind !== 'open') continue;
53
- if (token.tag !== 'input' && token.tag !== 'select' && token.tag !== 'textarea') continue;
54
- if (token.attrs.id) ids.add(token.attrs.id);
55
- }
56
- const labels = new Map<string, string>();
57
- for (let index = 0; index < tokens.length; index += 1) {
58
- const token = tokens[index];
59
- if (token.kind !== 'open' || token.tag !== 'label' || token.selfClosing) continue;
60
- const target = token.attrs.for;
61
- if (!target || !ids.has(target) || labels.has(target)) continue;
62
- labels.set(target, textOf(tokens, index + 1, matchingClose(tokens, index, 'label')));
63
- }
64
- return labels;
65
- }
66
-
67
40
  /** Fields of one form, in document order, with the question text omp derives. */
68
41
  export function parseAskForm(html: string): AskQuestion[] {
69
42
  if (!html.trim()) return [];
@@ -84,7 +57,12 @@ export function parseAskForm(html: string): AskQuestion[] {
84
57
  };
85
58
 
86
59
  const addField = (field: DraftField) => {
60
+ // The text block immediately before a control is its caption (omp's
61
+ // `fieldQuestions`), so the pending inline run must be flushed BEFORE the
62
+ // field is built — flushing after left `<span>Which?</span><select>` with
63
+ // the control's own name as its question.
87
64
  flush();
65
+ field.caption = caption;
88
66
  fields.push(field);
89
67
  caption = '';
90
68
  };
@@ -104,7 +82,10 @@ export function parseAskForm(html: string): AskQuestion[] {
104
82
  const value = attrs.value ?? 'on';
105
83
  const option: DraftOption = {
106
84
  value,
107
- label: controlLabel(attrs, wrapping) || value || name,
85
+ // omp's fallback is the RAW `value` attribute, else the name — not the
86
+ // `on` default a valueless checkbox submits. Using `on` made a lone
87
+ // checkbox's question "on" while omp's dialog title was its name.
88
+ label: controlLabel(attrs, wrapping) || attrs.value || name,
108
89
  checked: 'checked' in attrs,
109
90
  disabled: 'disabled' in attrs,
110
91
  };
@@ -212,7 +193,12 @@ export function parseAskForm(html: string): AskQuestion[] {
212
193
  else if (tag === 'input') addInput(token.attrs, wrapping);
213
194
  continue;
214
195
  }
215
- const close = matchingClose(tokens, index, tag);
196
+ // An unclosed tag (`<span class="truncate">` written literally inside a
197
+ // code span) has no `</span>`; `matchingClose` then answers the end of the
198
+ // document, and walking to it re-walked every field after the enclosing
199
+ // block — the same question appeared twice and the frame could not be
200
+ // placed. Clamp to the range this walk owns.
201
+ const close = Math.min(matchingClose(tokens, index, tag), end);
216
202
  if (SKIPPED[tag]) {
217
203
  index = close;
218
204
  continue;
@@ -267,7 +253,20 @@ export function parseAskForm(html: string): AskQuestion[] {
267
253
  index = close;
268
254
  continue;
269
255
  }
270
- if (tag === 'ul' || tag === 'ol' || tag === 'pre' || tag === 'table') {
256
+ // A `<table>` of controls (a decision matrix) is LAYOUT: omp walks it, so
257
+ // the row's text captions the control and the field survives. Treating
258
+ // every table as prose dropped the fields entirely, and a tool call whose
259
+ // questions never parsed cannot claim its dialogs — the whole ask fell to
260
+ // the modal.
261
+ if (tag === 'table') {
262
+ settle();
263
+ if (hasControl(tokens, index + 1, close)) walk(index + 1, close, wrapping, depth, quiet);
264
+ else if (!quiet) caption = '';
265
+ settle();
266
+ index = close;
267
+ continue;
268
+ }
269
+ if (tag === 'ul' || tag === 'ol' || tag === 'pre') {
271
270
  settle();
272
271
  // A list of controls is layout; any other list is a block, which clears
273
272
  // the caption the next field would otherwise borrow.
@@ -280,6 +279,15 @@ export function parseAskForm(html: string): AskQuestion[] {
280
279
  index = close;
281
280
  continue;
282
281
  }
282
+ // Cell boundaries separate one cell's text from the next; without them
283
+ // every cell in a row ran together into one caption.
284
+ if (tag === 'td' || tag === 'th' || tag === 'tr') {
285
+ settle();
286
+ walk(index + 1, close, wrapping, depth, quiet);
287
+ settle();
288
+ index = close;
289
+ continue;
290
+ }
283
291
  if (tag === 'input') {
284
292
  addInput(token.attrs, wrapping);
285
293
  continue;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Controls Kabmo does not ask about, and the `<label for>` pre-pass that names
8
+ * the ones it does.
9
+ *
10
+ * A `<label for="id">` sits anywhere in the form, so its text cannot be read
11
+ * while walking — the control it names may come first. This collects those
12
+ * pairs up front, keyed by the control's id, and the walk consults the map when
13
+ * a control has no wrapping `<label>`. Split from `ask-form/index.ts` (which
14
+ * owns the walk) to keep that file under the repo's per-file ceiling.
15
+ */
16
+
17
+ import { matchingClose, textOf, type Token } from '@/shared/lib/chat/ask-form/tokens';
18
+
19
+ /** Input types that are never a question: chrome, or state the form carries. */
20
+ export const IGNORED_INPUTS: Record<string, true> = {
21
+ button: true,
22
+ file: true,
23
+ image: true,
24
+ reset: true,
25
+ submit: true,
26
+ hidden: true,
27
+ };
28
+
29
+ /** Ids of the controls in the token range, and the `<label for>` text naming them. */
30
+ export function readLabelTargets(tokens: Token[]): Map<string, string> {
31
+ const ids = new Set<string>();
32
+ for (const token of tokens) {
33
+ if (token.kind !== 'open') continue;
34
+ if (token.tag !== 'input' && token.tag !== 'select' && token.tag !== 'textarea') continue;
35
+ if (token.attrs.id) ids.add(token.attrs.id);
36
+ }
37
+ const labels = new Map<string, string>();
38
+ for (let index = 0; index < tokens.length; index += 1) {
39
+ const token = tokens[index];
40
+ if (token.kind !== 'open' || token.tag !== 'label' || token.selfClosing) continue;
41
+ const target = token.attrs.for;
42
+ if (!target || !ids.has(target) || labels.has(target)) continue;
43
+ labels.set(target, textOf(tokens, index + 1, matchingClose(tokens, index, 'label')));
44
+ }
45
+ return labels;
46
+ }
@@ -157,10 +157,19 @@ export function textOf(tokens: Token[], start: number, end: number): string {
157
157
  continue;
158
158
  }
159
159
  if (SKIPPED[tag]) {
160
- index = matchingClose(tokens, index, tag);
160
+ index = Math.min(matchingClose(tokens, index, tag), end);
161
+ continue;
162
+ }
163
+ // A control's CONTENT is not text: `<select>`'s options and a `<textarea>`'s
164
+ // value are answers, not the label around them. Skipping only the opening
165
+ // tag leaked every option label into a wrapping `<label>`'s text, so the
166
+ // question read "Akun … prod Akun client … tidak yakin" while omp's dialog
167
+ // title was "Akun … prod" — and the frame could not be claimed.
168
+ if (tag === 'input') continue;
169
+ if (tag === 'select' || tag === 'textarea') {
170
+ index = Math.min(matchingClose(tokens, index, tag), end);
161
171
  continue;
162
172
  }
163
- if (tag === 'input' || tag === 'select' || tag === 'textarea') continue;
164
173
  if (tag === 'br') parts.push('\n');
165
174
  else if (tag === 'img') parts.push(token.attrs.alt ?? '');
166
175
  else if (BLOCK[tag] || HEADING[tag]) parts.push(' ');
@@ -134,4 +134,61 @@ describe('parseAskForm', () => {
134
134
  const questions = parseAskForm(`<form><label>Yes <input type="radio" name="ok" value="yes"></label></form>`);
135
135
  expect(questions[0].question).toBe('Yes');
136
136
  });
137
+
138
+ // The question text is the key `splitAskFrames` matches a live dialog's title
139
+ // against. Every case below was measured against omp's own `fieldQuestions`
140
+ // (pi-tui `html-form/data.ts`) on a real session form; a divergence here is a
141
+ // dialog that cannot be claimed and falls to the modal.
142
+ test('a <label> wrapping a <select> names the question without the option text', () => {
143
+ const questions = parseAskForm(`<form>
144
+ <label>Akun yang dipakai di mobilebroadcast prod
145
+ <select name="account">
146
+ <option value="client">Akun client (punya client_id)</option>
147
+ <option value="internal">Akun Jatis / internal</option>
148
+ </select>
149
+ </label>
150
+ </form>`);
151
+
152
+ expect(questions[0].question).toBe('Akun yang dipakai di mobilebroadcast prod');
153
+ expect(questions[0].options.map((option) => option.label)).toEqual([
154
+ 'Akun client (punya client_id)',
155
+ 'Akun Jatis / internal',
156
+ ]);
157
+ });
158
+
159
+ test('inline text before a control captions it, with or without a <br>', () => {
160
+ const span = parseAskForm(`<form><span>Which database?</span><select name="db"><option>a</option><option>b</option></select></form>`);
161
+ const br = parseAskForm(`<form>Which one?<br><select name="pick"><option>a</option><option>b</option></select></form>`);
162
+
163
+ expect(span[0].question).toBe('Which database?');
164
+ expect(br[0].question).toBe('Which one?');
165
+ });
166
+
167
+ test('a table of controls is layout: its cell text captions the field', () => {
168
+ const questions = parseAskForm(`<form>
169
+ <table><tr><td>Pick one</td><td><select name="pick"><option>a</option><option>b</option></select></td></tr></table>
170
+ </form>`);
171
+
172
+ expect(questions).toHaveLength(1);
173
+ expect(questions[0]).toMatchObject({ id: 'pick', question: 'Pick one' });
174
+ });
175
+
176
+ test('an unclosed inline tag does not re-walk the rest of the form', () => {
177
+ // A model wrote `<span class="truncate">` literally inside a code span, so
178
+ // it never closes. Walking to the end of the document duplicated every
179
+ // field after it, and the duplicated question could not be placed.
180
+ const questions = parseAskForm(`<form>
181
+ <p>a \`<span class="truncate">\` b</p>
182
+ <fieldset><legend>Lokasi</legend><label><input type="radio" name="lokasi" value="a" checked> A</label></fieldset>
183
+ <label>D <input type="text" name="d"></label>
184
+ </form>`);
185
+
186
+ expect(questions.map((question) => question.id)).toEqual(['lokasi', 'd']);
187
+ expect(questions[0].options.map((option) => option.label)).toEqual(['A']);
188
+ });
189
+
190
+ test('a lone checkbox with no value asks its name, not the submitted "on"', () => {
191
+ const questions = parseAskForm(`<form><input type="checkbox" name="ok"> I agree</form>`);
192
+ expect(questions[0].question).toBe('ok');
193
+ });
137
194
  });
@@ -99,6 +99,37 @@ export function isAskToolCall(tool: ToolCallData): boolean {
99
99
  return name === 'ask' || tool.title === 'ask';
100
100
  }
101
101
 
102
+ /**
103
+ * Index of the question a dialog's OPTION LIST names, when its title does not.
104
+ *
105
+ * omp titles a per-field dialog with the question it derived, and Kabmo derives
106
+ * that text from the same form — but the two parsers can disagree on a shape
107
+ * neither was written for, and a title that matches nothing used to hand the
108
+ * frame to the modal. The offered rows are the same list either way, so they
109
+ * are the fallback key: the question's own options (minus the synthetic
110
+ * "Other" row) must be exactly the rows the dialog offers (minus omp's "Other"
111
+ * and multi-select "Done" rows), and there must be at least two of them.
112
+ */
113
+ export function askQuestionForOptions(questions: AskQuestion[], options: unknown): number {
114
+ if (!Array.isArray(options)) return -1;
115
+ const offered = new Set(
116
+ options
117
+ .filter((option): option is string => typeof option === 'string')
118
+ .map(normalizeAskText)
119
+ .filter((label) => label && !isOtherOption(label) && !/done selecting$/.test(label)),
120
+ );
121
+ if (offered.size < 2) return -1;
122
+ let best = -1;
123
+ for (let index = 0; index < questions.length; index += 1) {
124
+ const labels = questions[index].options
125
+ .map((option) => normalizeAskText(option.label))
126
+ .filter((label) => label && !isOtherOption(label));
127
+ if (labels.length < 2 || labels.length !== offered.size) continue;
128
+ if (labels.every((label) => offered.has(label))) best = index;
129
+ }
130
+ return best;
131
+ }
132
+
102
133
  /**
103
134
  * True for an ask omp has given up on — its dialog was withdrawn (a validation
104
135
  * failure, an abort), so no live frame can belong to it and its card renders no
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The composer's recall cursor: no wrap at either end, the draft restored on
8
+ * the way back down, and the caret rules that keep a multi-line draft's arrows
9
+ * ordinary.
10
+ */
11
+
12
+ import { describe, expect, test } from 'bun:test';
13
+ import { canRecallDown, canRecallUp, stepHistoryCursor } from '@/shared/lib/chat/composer/history';
14
+
15
+ describe('stepHistoryCursor', () => {
16
+ test('ArrowUp enters the newest entry from the draft', () => {
17
+ expect(stepHistoryCursor(3, -1, 'up')).toBe(0);
18
+ });
19
+
20
+ test('ArrowUp walks older and stops at the oldest entry', () => {
21
+ expect(stepHistoryCursor(3, 0, 'up')).toBe(1);
22
+ expect(stepHistoryCursor(3, 1, 'up')).toBe(2);
23
+ expect(stepHistoryCursor(3, 2, 'up')).toBeNull();
24
+ });
25
+
26
+ test('ArrowDown walks newer and returns to the draft', () => {
27
+ expect(stepHistoryCursor(3, 2, 'down')).toBe(1);
28
+ expect(stepHistoryCursor(3, 0, 'down')).toBe(-1);
29
+ });
30
+
31
+ test('ArrowDown from the draft is not a recall', () => {
32
+ expect(stepHistoryCursor(3, -1, 'down')).toBeNull();
33
+ });
34
+
35
+ test('an empty list recalls nothing', () => {
36
+ expect(stepHistoryCursor(0, -1, 'up')).toBeNull();
37
+ expect(stepHistoryCursor(0, 0, 'down')).toBeNull();
38
+ });
39
+ });
40
+
41
+ describe('canRecallUp', () => {
42
+ test('an empty draft recalls', () => {
43
+ expect(canRecallUp('', 0)).toBe(true);
44
+ });
45
+
46
+ test('the first line recalls', () => {
47
+ expect(canRecallUp('one line', 4)).toBe(true);
48
+ });
49
+
50
+ test('a caret below the first line moves the caret instead', () => {
51
+ expect(canRecallUp('first\nsecond', 8)).toBe(false);
52
+ });
53
+
54
+ test('a caret at the start of the second line still moves the caret', () => {
55
+ expect(canRecallUp('first\nsecond', 6)).toBe(false);
56
+ });
57
+ });
58
+
59
+ describe('canRecallDown', () => {
60
+ test('the last line recalls', () => {
61
+ expect(canRecallDown('first\nsecond', 12)).toBe(true);
62
+ });
63
+
64
+ test('a caret above the last line moves the caret instead', () => {
65
+ expect(canRecallDown('first\nsecond', 2)).toBe(false);
66
+ });
67
+ });
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The composer's prompt recall: which commands carry the operator's own words,
8
+ * and how the ArrowUp / ArrowDown cursor moves through the list.
9
+ *
10
+ * Shared because both ends need the same vocabulary: the server records a
11
+ * prompt when one of these commands enters, and the client walks the list it
12
+ * gets back. The cursor rules are pure so the boundaries (no wrap at either
13
+ * end, the draft restored past the newest entry) are testable without a
14
+ * textarea.
15
+ */
16
+
17
+ /**
18
+ * Commands whose `message` is text the operator typed in the composer.
19
+ *
20
+ * `prompt` is the ordinary send; `steer` and `follow_up` are the mid-run
21
+ * variants (Ctrl+Enter / Send Now); `abort_and_prompt` is the legacy steer the
22
+ * older clients still post. Everything else — `set_model`, `abort`, a mode
23
+ * request — carries no prompt.
24
+ */
25
+ export const RECALLABLE_COMMAND_TYPES: Record<string, true> = {
26
+ prompt: true,
27
+ steer: true,
28
+ follow_up: true,
29
+ abort_and_prompt: true,
30
+ };
31
+
32
+ export type HistoryDirection = 'up' | 'down';
33
+
34
+ /**
35
+ * The next cursor in a NEWEST-FIRST list, or `null` when the key must do
36
+ * nothing.
37
+ *
38
+ * `-1` is the draft the operator was typing: ArrowUp from there enters the
39
+ * list at its newest entry, ArrowDown from there is a plain caret move, and
40
+ * ArrowDown from the oldest entry walks back to the draft. Neither end wraps.
41
+ */
42
+ export function stepHistoryCursor(length: number, cursor: number, direction: HistoryDirection): number | null {
43
+ if (length <= 0) return null;
44
+ if (direction === 'up') return cursor + 1 < length ? cursor + 1 : null;
45
+ return cursor > -1 ? cursor - 1 : null;
46
+ }
47
+
48
+ /**
49
+ * Whether ArrowUp may recall instead of moving the caret: the caret has to be
50
+ * on the FIRST line, so a multi-line draft keeps its normal arrow behavior.
51
+ */
52
+ export function canRecallUp(text: string, caret: number | null): boolean {
53
+ const position = caret ?? text.length;
54
+ return !text.slice(0, position).includes('\n');
55
+ }
56
+
57
+ /** The mirror rule for ArrowDown: the caret has to be on the LAST line. */
58
+ export function canRecallDown(text: string, caret: number | null): boolean {
59
+ const position = caret ?? text.length;
60
+ return !text.slice(position).includes('\n');
61
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A peer (IRC) message omp injected into a session.
8
+ *
9
+ * Since 18.18.9 a message that ends a `wait` no longer rides in the wait's
10
+ * result (`CoordinationDetails.waited`): omp hands it to the recipient session,
11
+ * which injects it as a `customType: "irc:incoming"` turn whose content is the
12
+ * `<irc>` prompt envelope. `wait` itself now answers with
13
+ * `Wait interrupted by message.` and `details.interrupted: true`.
14
+ *
15
+ * The envelope is prompt text for the model, not a transcript row: rendered
16
+ * as-is it shows the reply instructions and the raw tag. The turn's `details`
17
+ * carries the sender and the body verbatim, so both transcript mappers read
18
+ * that instead, and a session recorded before 18.18.9 (whose wait result still
19
+ * carries `waited`) keeps rendering through the wait card.
20
+ */
21
+
22
+ import type { IrcMessageData } from '@/shared/types/omp/session';
23
+ import { isRecord } from '@/shared/lib/util/guards';
24
+
25
+ /** The `customType` omp stamps on an injected peer message. */
26
+ export const IRC_INCOMING_CUSTOM_TYPE = 'irc:incoming';
27
+
28
+ /** The peer message in a `details` object, or null when the shape is not one. */
29
+ export function ircMessageFromDetails(details: unknown): IrcMessageData | null {
30
+ if (!isRecord(details)) return null;
31
+ const from = typeof details.from === 'string' ? details.from.trim() : '';
32
+ const message = typeof details.message === 'string' ? details.message.trim() : '';
33
+ if (!from || !message) return null;
34
+ return {
35
+ ...(typeof details.id === 'string' && details.id ? { id: details.id } : {}),
36
+ from,
37
+ message,
38
+ ...(typeof details.replyTo === 'string' && details.replyTo ? { replyTo: details.replyTo } : {}),
39
+ ...(details.progress === true ? { progress: true } : {}),
40
+ ...(details.broadcast === true ? { broadcast: true } : {}),
41
+ };
42
+ }
@@ -32,6 +32,8 @@ describe('forkCapability', () => {
32
32
  expect(forkCapability('qwen')).toBe('none');
33
33
  expect(forkCapability('dsh')).toBe('none');
34
34
  expect(forkCapability('antigravity')).toBe('none');
35
+ expect(forkCapability('jcode')).toBe('none');
36
+ expect(forkCapability('grok')).toBe('none');
35
37
  });
36
38
  });
37
39
 
@@ -16,10 +16,12 @@
16
16
  *
17
17
  * Two shapes the summary can carry are handled here rather than in the card:
18
18
  *
19
- * - The status vocabulary is omp's own FIVE, not the three the card used to
20
- * know. `blocked` and `abandoned` are real (measured in the author's
21
- * sessions: 21 results mention a dropped task, 2 a blocked one), and a
22
- * parser that only understood three drew both as plain pending.
19
+ * - The status vocabulary is omp's own, not the three the card used to know.
20
+ * `abandoned` is real (measured in the author's sessions: 21 results
21
+ * mention a dropped task), and `blocked` was too until omp 18.19.0 removed
22
+ * it — the parser keeps both because it reads tool text, and sessions
23
+ * recorded before that pin still carry `(blocked: …)` lines. A parser that
24
+ * only understood three drew them as plain pending.
23
25
  * - A task whose content is an init-list entry rather than prose is recorded
24
26
  * that way by omp itself (see `./nested-phase`), so it is labelled by the
25
27
  * phase it names instead of being rendered as a JSON blob.
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The archive naming rules the dialog and the route both read.
8
+ *
9
+ * The suffix table is the one that decides whether a right-click offers
10
+ * Extract, so a `.tar.gz` read as `.gz` would unpack one gzip layer and leave a
11
+ * tarball behind. The default names are what the Compress dialog shows before
12
+ * the user types, and a wrong one (naming a multi-selection after its first
13
+ * file) hides what the archive holds.
14
+ */
15
+
16
+ import { describe, expect, test } from 'bun:test';
17
+ import {
18
+ archiveExtension,
19
+ archiveKindOf,
20
+ archiveKindLabel,
21
+ defaultArchiveDestination,
22
+ defaultArchiveName,
23
+ defaultExtractDestination,
24
+ isArchiveName,
25
+ commonParentDir,
26
+ stripArchiveSuffix,
27
+ } from '@/shared/lib/fs/archive';
28
+
29
+ const file = (path: string, name = path.split('/').pop() ?? path) => ({ path, name, kind: 'file' as const });
30
+
31
+ describe('archiveKindOf', () => {
32
+ test('reads the longest suffix first', () => {
33
+ expect(archiveKindOf('src.tar.gz')).toBe('tar.gz');
34
+ expect(archiveKindOf('src.tgz')).toBe('tar.gz');
35
+ expect(archiveKindOf('src.tar.bz2')).toBe('tar.bz2');
36
+ expect(archiveKindOf('src.tar.xz')).toBe('tar.xz');
37
+ expect(archiveKindOf('src.tar')).toBe('tar');
38
+ });
39
+
40
+ test('recognises every single-file compressor', () => {
41
+ expect(archiveKindOf('a.zip')).toBe('zip');
42
+ expect(archiveKindOf('a.7z')).toBe('7z');
43
+ expect(archiveKindOf('a.rar')).toBe('rar');
44
+ expect(archiveKindOf('a.gz')).toBe('gz');
45
+ expect(archiveKindOf('a.bz2')).toBe('bz2');
46
+ expect(archiveKindOf('a.xz')).toBe('xz');
47
+ });
48
+
49
+ test('is case-insensitive and rejects a normal file', () => {
50
+ expect(archiveKindOf('SRC.ZIP')).toBe('zip');
51
+ expect(archiveKindOf('main.ts')).toBeNull();
52
+ expect(archiveKindOf('zip')).toBeNull();
53
+ expect(isArchiveName('photo.ZIP')).toBe(true);
54
+ expect(isArchiveName('notes.md')).toBe(false);
55
+ });
56
+
57
+ test('labels the kind for the dialog', () => {
58
+ expect(archiveKindLabel('tar.gz')).toBe('TAR.GZ');
59
+ });
60
+ });
61
+
62
+ describe('stripArchiveSuffix', () => {
63
+ test('removes the whole archive suffix', () => {
64
+ expect(stripArchiveSuffix('src.tar.gz')).toBe('src');
65
+ expect(stripArchiveSuffix('src.zip')).toBe('src');
66
+ expect(stripArchiveSuffix('main.ts')).toBe('main.ts');
67
+ });
68
+ });
69
+
70
+ describe('defaultArchiveName', () => {
71
+ test('one file keeps its stem, one folder its own name', () => {
72
+ expect(defaultArchiveName([file('src/report.pdf', 'report.pdf')], 'zip')).toBe('report.zip');
73
+ expect(defaultArchiveName([{ path: 'src', name: 'src', kind: 'folder' }], 'tar.gz')).toBe('src.tar.gz');
74
+ });
75
+
76
+ test('a multi-selection takes the name of the folder that holds it', () => {
77
+ expect(defaultArchiveName([file('src/a.ts'), file('src/b.ts')], '7z')).toBe('src.7z');
78
+ // Different branches share the root, which is the common folder.
79
+ expect(defaultArchiveName([file('src/a.ts'), file('docs/b.md')], 'zip')).toBe('archive.zip');
80
+ });
81
+
82
+ test('format extension follows the chosen format', () => {
83
+ expect(archiveExtension('rar')).toBe('rar');
84
+ expect(archiveExtension('tar.gz')).toBe('tar.gz');
85
+ });
86
+ });
87
+
88
+ describe('commonParentDir and destinations', () => {
89
+ test('finds the deepest shared folder', () => {
90
+ expect(commonParentDir(['src/a.ts', 'src/b.ts'])).toBe('src');
91
+ expect(commonParentDir(['src/deep/a.ts', 'src/deep/b.ts'])).toBe('src/deep');
92
+ expect(commonParentDir(['src/a.ts', 'docs/b.md'])).toBe('.');
93
+ expect(commonParentDir([])).toBe('.');
94
+ });
95
+
96
+ test('compress lands beside the selection; extract lands in a stem folder', () => {
97
+ expect(defaultArchiveDestination([file('src/a.ts')])).toBe('src');
98
+ expect(defaultExtractDestination('src/bundle.zip')).toBe('src/bundle');
99
+ expect(defaultExtractDestination('bundle.tar.gz')).toBe('bundle');
100
+ });
101
+ });