@kabmo-labs/kabmo 0.28.0 → 0.30.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 (232) 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-5vjbp04s.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-palette.test.ts +72 -0
  86. package/src/client/glass.css +39 -14
  87. package/src/client/glass.test.ts +28 -67
  88. package/src/client/hooks/chat/composer/history.test.ts +267 -0
  89. package/src/client/hooks/chat/composer/history.ts +146 -0
  90. package/src/client/hooks/chat/timeline/ask-frames.test.ts +54 -0
  91. package/src/client/hooks/chat/timeline/ask-frames.ts +29 -1
  92. package/src/client/hooks/chat/timeline/timeline-rail.test.ts +34 -2
  93. package/src/client/hooks/chat/timeline/user-turns.ts +31 -2
  94. package/src/client/hooks/editor/file-editor-types.ts +15 -0
  95. package/src/client/hooks/editor/save-bytes.ts +79 -0
  96. package/src/client/hooks/editor/use-dirty-tracking.test.ts +73 -0
  97. package/src/client/hooks/editor/use-dirty-tracking.ts +96 -0
  98. package/src/client/hooks/editor/use-file-cache.ts +1 -0
  99. package/src/client/hooks/editor/use-file-editor.test.ts +30 -0
  100. package/src/client/hooks/editor/use-file-editor.ts +20 -17
  101. package/src/client/hooks/editor/use-file-read.ts +21 -2
  102. package/src/client/hooks/editor/use-grid-selection.ts +160 -0
  103. package/src/client/hooks/models/use-harness-update.test.ts +35 -2
  104. package/src/client/hooks/models/use-harness-update.ts +49 -10
  105. package/src/client/hooks/workspace/diff-file.test.ts +72 -0
  106. package/src/client/hooks/workspace/diff-file.ts +12 -6
  107. package/src/client/hooks/workspace/file-archive.ts +220 -0
  108. package/src/client/hooks/workspace/file-clipboard.test.ts +4 -4
  109. package/src/client/hooks/workspace/file-clipboard.ts +37 -26
  110. package/src/client/hooks/workspace/file-selection.test.ts +67 -0
  111. package/src/client/hooks/workspace/file-selection.ts +156 -0
  112. package/src/client/hooks/workspace/file-tree-actions-clipboard.test.ts +5 -5
  113. package/src/client/hooks/workspace/file-tree-actions.ts +36 -8
  114. package/src/client/lib/editor/workbook-drafts.ts +42 -0
  115. package/src/client/lib/launch/file-handlers.ts +2 -2
  116. package/src/client/lib/scrollbar-activity.test.ts +21 -88
  117. package/src/client/lib/scrollbar-activity.ts +71 -73
  118. package/src/client/lib/scrollbar-events.ts +143 -0
  119. package/src/client/lib/scrollbar-input.test.ts +126 -0
  120. package/src/client/lib/scrollbar-probe.test-util.ts +107 -0
  121. package/src/client/tailwind.css +32 -1
  122. package/src/server/db.server.test.ts +50 -1
  123. package/src/server/db.server.ts +36 -3
  124. package/src/server/lib/chat/prompt-history.server.test.ts +92 -0
  125. package/src/server/lib/chat/prompt-history.server.ts +65 -0
  126. package/src/server/lib/chat/schema.server.ts +35 -0
  127. package/src/server/lib/db/schema.ts +3 -0
  128. package/src/server/lib/fs/archive.test.ts +198 -0
  129. package/src/server/lib/fs/archive.ts +278 -0
  130. package/src/server/lib/fs/git-diff.test.ts +26 -1
  131. package/src/server/lib/fs/git-diff.ts +43 -15
  132. package/src/server/lib/harness/launch-table.ts +19 -0
  133. package/src/server/lib/harness/provider-entry.ts +1 -1
  134. package/src/server/lib/harness/provider-file.server.ts +1 -1
  135. package/src/server/lib/harness/provider-sources.server.ts +2 -1
  136. package/src/server/lib/harness/provider-write.server.ts +2 -1
  137. package/src/server/lib/harness/update-job-store.ts +12 -0
  138. package/src/server/lib/harness/update-queue.server.ts +15 -10
  139. package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +5 -1
  140. package/src/server/lib/omp/rpc/frame-fold.test.ts +5 -1
  141. package/src/server/lib/omp/rpc/lifecycle.test.ts +4 -0
  142. package/src/server/lib/omp/session/auto-title.server.test.ts +4 -0
  143. package/src/server/lib/omp/session/delete.server.ts +1 -0
  144. package/src/server/lib/omp/session/goal-driver.test.ts +5 -1
  145. package/src/server/lib/omp/session/goal-settings.test.ts +5 -1
  146. package/src/server/lib/panels/auto-update.server.test.ts +5 -2
  147. package/src/server/lib/panels/git-update.server.test.ts +5 -2
  148. package/src/server/lib/panels/install.server.test.ts +5 -2
  149. package/src/server/lib/panels/remove.server.test.ts +5 -2
  150. package/src/server/routes/agent/command.ts +11 -0
  151. package/src/server/routes/agent/new.ts +5 -0
  152. package/src/server/routes/chat/index.ts +5 -0
  153. package/src/server/routes/chat/prompt-history.test.ts +67 -0
  154. package/src/server/routes/chat/prompt-history.ts +31 -0
  155. package/src/server/routes/chat/stream.test.ts +21 -0
  156. package/src/server/routes/chat/stream.ts +5 -0
  157. package/src/server/routes/fs/action-archive.test.ts +128 -0
  158. package/src/server/routes/fs/action-bulk.ts +106 -0
  159. package/src/server/routes/fs/action-save-bytes.test.ts +59 -0
  160. package/src/server/routes/fs/action-transfer.test.ts +26 -0
  161. package/src/server/routes/fs/action.ts +91 -11
  162. package/src/server/routes/fs/archive.ts +20 -0
  163. package/src/server/routes/fs/grant.test.ts +5 -2
  164. package/src/server/routes/fs/index.ts +2 -0
  165. package/src/server/routes/fs/scope.test.ts +6 -2
  166. package/src/server/routes/harness/import-action.ts +1 -1
  167. package/src/server/routes/harness/root.ts +6 -1
  168. package/src/server/routes/harness/summary.test.ts +50 -0
  169. package/src/server/routes/harness/update-status.ts +41 -2
  170. package/src/server/routes/harness/update.test.ts +56 -2
  171. package/src/server/routes/sessions/delete.test.ts +4 -0
  172. package/src/shared/lib/chat/ask-form/index.ts +39 -31
  173. package/src/shared/lib/chat/ask-form/labels.ts +46 -0
  174. package/src/shared/lib/chat/ask-form/tokens.ts +11 -2
  175. package/src/shared/lib/chat/ask-form.test.ts +57 -0
  176. package/src/shared/lib/chat/ask-questions.ts +31 -0
  177. package/src/shared/lib/chat/composer/history.test.ts +67 -0
  178. package/src/shared/lib/chat/composer/history.ts +61 -0
  179. package/src/shared/lib/chat/irc-notice.ts +42 -0
  180. package/src/shared/lib/chat/timeline/fork-anchor.test.ts +2 -0
  181. package/src/shared/lib/chat/todo/parser.ts +6 -4
  182. package/src/shared/lib/fs/archive.test.ts +101 -0
  183. package/src/shared/lib/fs/archive.ts +191 -0
  184. package/src/shared/lib/fs/clipboard.test.ts +32 -7
  185. package/src/shared/lib/fs/clipboard.ts +59 -14
  186. package/src/shared/lib/fs/csv.test.ts +50 -0
  187. package/src/shared/lib/fs/csv.ts +40 -0
  188. package/src/shared/lib/fs/document-kind.test.ts +13 -6
  189. package/src/shared/lib/fs/document-kind.ts +18 -6
  190. package/src/shared/lib/fs/file-kind-classify.test.ts +4 -0
  191. package/src/shared/lib/fs/file-kind.test.ts +2 -7
  192. package/src/shared/lib/fs/file-kind.ts +4 -2
  193. package/src/shared/lib/fs/grid-edit.test.ts +24 -0
  194. package/src/shared/lib/fs/grid-edit.ts +29 -0
  195. package/src/shared/lib/fs/grid-selection.test.ts +137 -0
  196. package/src/shared/lib/fs/grid-selection.ts +138 -0
  197. package/src/shared/lib/harness/brand-color.ts +5 -0
  198. package/src/shared/lib/harness/catalog.test.ts +22 -0
  199. package/src/shared/lib/harness/catalog.ts +12 -1
  200. package/src/shared/lib/harness/config-fields.test.ts +25 -0
  201. package/src/shared/lib/harness/config-fields.ts +33 -3
  202. package/src/shared/lib/harness/dialects.ts +1 -1
  203. package/src/shared/lib/harness/mcp-facts.ts +4 -0
  204. package/src/shared/lib/harness/provider-contracts.ts +109 -0
  205. package/src/shared/lib/harness/provider-facts.test.ts +2 -1
  206. package/src/shared/lib/harness/provider-facts.ts +24 -115
  207. package/src/shared/lib/harness/provider-lookup.ts +37 -0
  208. package/src/shared/lib/harness/providers.ts +2 -1
  209. package/src/shared/lib/harness/updates.ts +10 -0
  210. package/src/shared/lib/icons/tint-hues.generated.ts +14 -13
  211. package/src/shared/lib/omp/session/mapper.test.ts +31 -0
  212. package/src/shared/lib/omp/session/mapper.ts +17 -0
  213. package/src/shared/lib/omp/session/messages-map-notice.test.ts +68 -0
  214. package/src/shared/lib/omp/session/messages-map.test.ts +1 -35
  215. package/src/shared/lib/omp/session/messages-map.ts +17 -0
  216. package/src/shared/lib/omp/session/wait.ts +10 -1
  217. package/src/shared/lib/settings/sections.ts +8 -4
  218. package/src/shared/lib/ui/picker-filter.test.ts +23 -0
  219. package/src/shared/lib/ui/picker-filter.ts +20 -0
  220. package/src/shared/types/chat.ts +4 -0
  221. package/src/shared/types/harness.ts +5 -1
  222. package/src/shared/types/omp/session.ts +18 -0
  223. package/src/shared/types/settings/state.ts +6 -6
  224. package/src/shared/types/todo.ts +3 -1
  225. package/src/test-support/file-actions.test-util.ts +4 -0
  226. package/src/test-support/file-archive.test-util.ts +41 -0
  227. package/src/test-support/file-clipboard.test-util.ts +9 -6
  228. package/src/test-support/file-editor.test-util.ts +3 -2
  229. package/src/test-support/glass-css.ts +30 -0
  230. package/src/test-support/harness-table.test-util.ts +2 -0
  231. package/src/test-support/preload.ts +46 -0
  232. package/dist/client/static/js/index-81f7berm.css +0 -1
@@ -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
+ });
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Archive names, formats and destinations — the facts BOTH ends need.
8
+ *
9
+ * The Files panel decides which menu rows to offer (Extract only on an archive,
10
+ * Compress on any selection) and which name a new archive should take; the
11
+ * server decides which binary runs and refuses what cannot be written. Keeping
12
+ * the suffix table, the format list and the default names in one module is what
13
+ * stops the dialog from offering `.zip` while the route expects `.7z`.
14
+ *
15
+ * The compress list is intentionally shorter than the extract list: extracting
16
+ * a `.rar` only needs a reader, while creating one needs the proprietary `rar`
17
+ * binary, which most machines do not ship. The dialog reports the formats the
18
+ * server can actually run.
19
+ */
20
+
21
+ /** A format the Compress dialog can write. */
22
+ export type ArchiveFormat = 'zip' | '7z' | 'rar' | 'tar' | 'tar.gz';
23
+
24
+ /** Every archive spelling the Extract menu recognises. */
25
+ export type ArchiveKind =
26
+ | 'zip'
27
+ | '7z'
28
+ | 'rar'
29
+ | 'tar'
30
+ | 'tar.gz'
31
+ | 'tar.bz2'
32
+ | 'tar.xz'
33
+ | 'gz'
34
+ | 'bz2'
35
+ | 'xz';
36
+
37
+ export interface ArchiveFormatInfo {
38
+ id: ArchiveFormat;
39
+ /** What the dialog shows. */
40
+ label: string;
41
+ /** The suffix the default name takes, without a dot. */
42
+ extension: string;
43
+ }
44
+
45
+ export const COMPRESS_FORMATS: readonly ArchiveFormatInfo[] = [
46
+ { id: 'zip', label: 'ZIP', extension: 'zip' },
47
+ { id: '7z', label: '7Z', extension: '7z' },
48
+ { id: 'rar', label: 'RAR', extension: 'rar' },
49
+ { id: 'tar', label: 'TAR', extension: 'tar' },
50
+ { id: 'tar.gz', label: 'TAR.GZ', extension: 'tar.gz' },
51
+ ];
52
+
53
+ /** Suffix → kind, longest first so `.tar.gz` is not read as `.gz`. */
54
+ const KIND_SUFFIXES: ReadonlyArray<readonly [string, ArchiveKind]> = [
55
+ ['.tar.gz', 'tar.gz'],
56
+ ['.tar.bz2', 'tar.bz2'],
57
+ ['.tar.xz', 'tar.xz'],
58
+ ['.tgz', 'tar.gz'],
59
+ ['.tbz2', 'tar.bz2'],
60
+ ['.txz', 'tar.xz'],
61
+ ['.tar', 'tar'],
62
+ ['.zip', 'zip'],
63
+ ['.7z', '7z'],
64
+ ['.rar', 'rar'],
65
+ ['.gz', 'gz'],
66
+ ['.bz2', 'bz2'],
67
+ ['.xz', 'xz'],
68
+ ];
69
+
70
+ /** The archive kind `name` is spelled as, or null when it is not one. */
71
+ export function archiveKindOf(name: string): ArchiveKind | null {
72
+ const lower = name.toLowerCase();
73
+ for (const [suffix, kind] of KIND_SUFFIXES) {
74
+ if (lower.endsWith(suffix)) return kind;
75
+ }
76
+ return null;
77
+ }
78
+
79
+ /** Whether a row is an archive the panel can offer Extract for. */
80
+ export function isArchiveName(name: string): boolean {
81
+ return archiveKindOf(name) !== null;
82
+ }
83
+
84
+ /** The format entry for an id, or undefined for an unknown id. */
85
+ export function archiveFormatInfo(format: string): ArchiveFormatInfo | undefined {
86
+ return COMPRESS_FORMATS.find((entry) => entry.id === format);
87
+ }
88
+
89
+ /** The extension a format's file name ends with, without the dot. */
90
+ export function archiveExtension(format: ArchiveFormat): string {
91
+ return archiveFormatInfo(format)?.extension ?? 'zip';
92
+ }
93
+
94
+ /** The name with any recognised archive suffix removed (`a.tar.gz` → `a`). */
95
+ export function stripArchiveSuffix(name: string): string {
96
+ const lower = name.toLowerCase();
97
+ for (const [suffix] of KIND_SUFFIXES) {
98
+ if (lower.endsWith(suffix)) return name.slice(0, -suffix.length);
99
+ }
100
+ return name;
101
+ }
102
+
103
+ /** The folder part of a relative POSIX path, `.` at the top. */
104
+ export function parentDirOf(path: string): string {
105
+ const cut = path.lastIndexOf('/');
106
+ return cut === -1 ? '.' : path.slice(0, cut) || '.';
107
+ }
108
+
109
+ /** The last segment of a relative POSIX path. */
110
+ export function baseNameOf(path: string): string {
111
+ const cut = path.lastIndexOf('/');
112
+ return cut === -1 ? path : path.slice(cut + 1);
113
+ }
114
+
115
+ /**
116
+ * The deepest folder that contains every path.
117
+ *
118
+ * A compress runs with that folder as its working directory, so every argument
119
+ * is a clean relative name rather than a `../` climb — which is also the rule
120
+ * the server enforces. Paths from different branches therefore share `.` and
121
+ * the archive sits at the listing root.
122
+ */
123
+ export function commonParentDir(paths: readonly string[]): string {
124
+ if (paths.length === 0) return '.';
125
+ const split = paths.map((path) => parentDirOf(path).split('/').filter((segment) => segment !== '.'));
126
+ let shared = split[0] ?? [];
127
+ for (const segments of split.slice(1)) {
128
+ let index = 0;
129
+ while (index < shared.length && index < segments.length && shared[index] === segments[index]) index += 1;
130
+ shared = shared.slice(0, index);
131
+ }
132
+ return shared.length === 0 ? '.' : shared.join('/');
133
+ }
134
+
135
+ export interface ArchiveNameSource {
136
+ path: string;
137
+ name: string;
138
+ kind: 'file' | 'folder';
139
+ }
140
+
141
+ /**
142
+ * The name a Compress dialog proposes.
143
+ *
144
+ * One file keeps its stem (`report.pdf` → `report.zip`), one folder its own
145
+ * name (`src` → `src.zip`), and a multi-selection takes the name of the folder
146
+ * they live in — naming the archive after the first arbitrary file would hide
147
+ * what it holds.
148
+ */
149
+ export function defaultArchiveName(entries: readonly ArchiveNameSource[], format: ArchiveFormat): string {
150
+ const extension = archiveExtension(format);
151
+ if (entries.length === 1) {
152
+ const entry = entries[0]!;
153
+ // A file's own extension is dropped too: `report.pdf` compresses to
154
+ // `report.zip`, not `report.pdf.zip`, which reads as an archive of a PDF
155
+ // renamed twice.
156
+ const withoutArchive = stripArchiveSuffix(entry.name);
157
+ const dot = withoutArchive.lastIndexOf('.');
158
+ const stem = entry.kind === 'folder'
159
+ ? entry.name
160
+ : dot > 0 ? withoutArchive.slice(0, dot) : withoutArchive;
161
+ return `${stem || 'archive'}.${extension}`;
162
+ }
163
+ const common = commonParentDir(entries.map((entry) => entry.path));
164
+ const folder = baseNameOf(common);
165
+ return `${folder === '.' || folder === '' ? 'archive' : folder}.${extension}`;
166
+ }
167
+
168
+ /**
169
+ * The destination a Compress dialog proposes: the folder the selection lives
170
+ * in, which is where the archive appears beside it.
171
+ */
172
+ export function defaultArchiveDestination(entries: readonly ArchiveNameSource[]): string {
173
+ return commonParentDir(entries.map((entry) => entry.path));
174
+ }
175
+
176
+ /**
177
+ * The folder an Extract dialog proposes: a sibling of the archive named after
178
+ * its stem (`src.zip` → `src`). Extracting in place is the same call with `.`
179
+ * typed in the field, so the default never scatters files beside the archive.
180
+ */
181
+ export function defaultExtractDestination(archivePath: string): string {
182
+ const parent = parentDirOf(archivePath);
183
+ const stem = stripArchiveSuffix(baseNameOf(archivePath));
184
+ if (!stem) return parent;
185
+ return parent === '.' ? stem : `${parent}/${stem}`;
186
+ }
187
+
188
+ /** The display name of an archive kind, for the dialog's subtitle. */
189
+ export function archiveKindLabel(kind: ArchiveKind): string {
190
+ return kind.toUpperCase();
191
+ }