@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,149 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Reading a workbook into the grid's shape, and writing an edited one back.
8
+ *
9
+ * SheetJS (`xlsx`) rather than `read-excel-file`, which this viewer used before
10
+ * `.xls` was supported. The legacy format is an OLE2 compound file holding BIFF
11
+ * records, and `read-excel-file` reads only the ZIP-based OOXML formats — so
12
+ * supporting `.xls` at all means a BIFF reader, and SheetJS is the maintained
13
+ * one. The package is installed from SheetJS's own distribution
14
+ * (`cdn.sheetjs.com`, 0.20.3) because the copy on npm is a stale 0.18.5 with
15
+ * published advisories. Measured cost: 376 KB minified in the client bundle
16
+ * (`bun build --minify`), against 55 KB for the reader it replaces — a 2.7%
17
+ * increase on a 13.8 MB bundle that the local server hands over, and the price
18
+ * of opening `.xls` at all.
19
+ *
20
+ * `raw: false` is what makes a cell read like the spreadsheet shows it: the
21
+ * reader returns the cell's FORMATTED text (`w`), so a date is the file's own
22
+ * date format and a currency keeps its symbol, instead of a serial number the
23
+ * grid would have to re-format. A formula's cached value is what comes back,
24
+ * which is what Excel shows too.
25
+ *
26
+ * **The reader's own workbook is kept**, not just the display rows. An edit
27
+ * writes ONE cell into that workbook and the save serializes it, so every sheet
28
+ * and every cell the user did not touch keeps its value, formula and number
29
+ * format. Rebuilding a workbook from the display rows would silently drop all
30
+ * of it.
31
+ *
32
+ * The read is bounded by the same row and column caps as the CSV grid: a grid
33
+ * is a DOM surface, and an unbounded sheet would mount a table the browser
34
+ * cannot lay out. The caller is told the result was cut (`truncated`) rather
35
+ * than shown a silently short sheet. The CAP is display-only — the workbook
36
+ * behind it is whole, so saving an edit never drops the rows past the cap.
37
+ */
38
+
39
+ import * as XLSX from 'xlsx';
40
+ import { MAX_CSV_COLUMNS, MAX_CSV_ROWS } from '@/shared/lib/fs/csv';
41
+
42
+ /** One sheet as the grid draws it: a name and its rows of display text. */
43
+ export interface WorkbookSheet {
44
+ name: string;
45
+ rows: string[][];
46
+ /** The sheet held more rows or columns than the caps allow. */
47
+ truncated: boolean;
48
+ }
49
+
50
+ /** The container a workbook was read from, and the one it is written back as. */
51
+ export type WorkbookFormat = 'xlsx' | 'xlsm' | 'xls';
52
+
53
+ export interface LoadedWorkbook {
54
+ /** The reader's workbook, kept so an edit can be written back losslessly. */
55
+ book: XLSX.WorkBook;
56
+ sheets: WorkbookSheet[];
57
+ format: WorkbookFormat;
58
+ }
59
+
60
+ /** The container a path names. Anything else is treated as the modern format. */
61
+ export function workbookFormatFor(path: string): WorkbookFormat {
62
+ const extension = path.slice(path.lastIndexOf('.') + 1).toLowerCase();
63
+ if (extension === 'xls') return 'xls';
64
+ if (extension === 'xlsm') return 'xlsm';
65
+ return 'xlsx';
66
+ }
67
+
68
+ export async function readWorkbook(bytes: ArrayBuffer, path: string): Promise<LoadedWorkbook> {
69
+ const book = XLSX.read(new Uint8Array(bytes), { type: 'array', cellDates: true, bookVBA: true });
70
+
71
+ const sheets = book.SheetNames.map((name) => {
72
+ const sheet = book.Sheets[name];
73
+ const ref = sheet?.['!ref'];
74
+ if (!sheet || !ref) return { name, rows: [], truncated: false };
75
+
76
+ const bounds = XLSX.utils.decode_range(ref);
77
+ const lastRow = Math.min(bounds.e.r, MAX_CSV_ROWS);
78
+ const lastCol = Math.min(bounds.e.c, MAX_CSV_COLUMNS - 1);
79
+ const rows = XLSX.utils.sheet_to_json<string[]>(sheet, {
80
+ header: 1,
81
+ raw: false,
82
+ defval: '',
83
+ blankrows: true,
84
+ range: { s: { r: 0, c: 0 }, e: { r: lastRow, c: lastCol } },
85
+ });
86
+
87
+ return {
88
+ name,
89
+ rows: rows.map((row) => row.map((cell) => (cell == null ? '' : String(cell)))),
90
+ truncated: bounds.e.r > MAX_CSV_ROWS || bounds.e.c >= MAX_CSV_COLUMNS,
91
+ };
92
+ });
93
+
94
+ return { book, sheets, format: workbookFormatFor(path) };
95
+ }
96
+
97
+ /**
98
+ * Write one cell into the reader's workbook.
99
+ *
100
+ * `row` and `col` are ABSOLUTE sheet coordinates (0-based), not the grid's data
101
+ * rows: the grid's first data row is the sheet's row 1, because row 0 is drawn
102
+ * as the header strip.
103
+ *
104
+ * A numeric-looking value becomes a number, which is what typing `3` into a
105
+ * spreadsheet does; everything else is text. The cell's style and number format
106
+ * are kept, and its formula is dropped — the user replaced the formula's result
107
+ * with a literal, and keeping `f` would make Excel recompute over the new value.
108
+ */
109
+ export function setWorkbookCell(
110
+ book: XLSX.WorkBook,
111
+ sheetName: string,
112
+ row: number,
113
+ col: number,
114
+ value: string,
115
+ ): void {
116
+ const sheet = book.Sheets[sheetName];
117
+ if (!sheet) return;
118
+ const address = XLSX.utils.encode_cell({ r: row, c: col });
119
+ const previous = sheet[address] as XLSX.CellObject | undefined;
120
+ const numeric = value !== '' && /^-?\d+(\.\d+)?$/.test(value);
121
+ const cell: XLSX.CellObject = numeric
122
+ ? { t: 'n', v: Number(value) }
123
+ : { t: 's', v: value };
124
+ if (previous?.s) cell.s = previous.s;
125
+ if (previous?.z) cell.z = previous.z;
126
+ sheet[address] = cell;
127
+
128
+ // A cell written past the sheet's recorded range would be dropped by the
129
+ // writer, so the range grows with the edit.
130
+ const ref = sheet['!ref'];
131
+ if (ref) {
132
+ const bounds = XLSX.utils.decode_range(ref);
133
+ bounds.e.r = Math.max(bounds.e.r, row);
134
+ bounds.e.c = Math.max(bounds.e.c, col);
135
+ sheet['!ref'] = XLSX.utils.encode_range(bounds);
136
+ }
137
+ }
138
+
139
+ /** Serialize the edited workbook back into its own container. */
140
+ export function writeWorkbook(book: XLSX.WorkBook, format: WorkbookFormat): Uint8Array {
141
+ const bytes = XLSX.write(book, {
142
+ type: 'array',
143
+ bookType: format,
144
+ cellDates: true,
145
+ compression: true,
146
+ bookVBA: format === 'xlsm',
147
+ }) as ArrayBuffer;
148
+ return new Uint8Array(bytes);
149
+ }
@@ -0,0 +1,262 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The two archive dialogs: Compress to… and Extract…
8
+ *
9
+ * Both portal to `<body>` (the composer's backdrop-filter trap lives elsewhere,
10
+ * but the rule is the same: a `fixed` overlay must not be sized by an ancestor)
11
+ * and both show the server's refusal INLINE, because the field that caused it
12
+ * is still on screen. The format list is the server's availability answer;
13
+ * a format whose binary is missing is listed disabled with the reason, so the
14
+ * user sees the machine's limit instead of a failure after submitting.
15
+ */
16
+
17
+ import { createPortal } from 'preact/compat';
18
+ import type { FormEvent } from 'preact/compat';
19
+ import { archiveKindLabel, archiveKindOf, type ArchiveFormat } from '@/shared/lib/fs/archive';
20
+ import type { ClipboardTarget } from '@/client/hooks/workspace/file-clipboard';
21
+ import type { FileArchive } from '@/client/hooks/workspace/file-archive';
22
+
23
+ export interface ArchiveFormatOption {
24
+ id: ArchiveFormat;
25
+ label: string;
26
+ extension: string;
27
+ available: boolean;
28
+ tool: string;
29
+ }
30
+
31
+ interface ShellProps {
32
+ title: string;
33
+ /** What is being acted on, one line. */
34
+ subject: string;
35
+ error: string | null;
36
+ busy: boolean;
37
+ submitLabel: string;
38
+ busyLabel: string;
39
+ onSubmit: (event: FormEvent) => void;
40
+ onCancel: () => void;
41
+ children: preact.ComponentChildren;
42
+ }
43
+
44
+ function ArchiveDialogShell({ title, subject, error, busy, submitLabel, busyLabel, onSubmit, onCancel, children }: ShellProps) {
45
+ return createPortal(
46
+ <div className="fixed inset-0 modal-scrim z-[100] flex items-center justify-center p-4 backdrop-blur-sm">
47
+ <form onSubmit={onSubmit} className="glass-overlay bg-paper rounded shadow-xl p-4 w-full max-w-sm border border-ink/10 font-sans">
48
+ <h3 className="font-semibold text-ink mb-1 text-sm">{title}</h3>
49
+ <p className="text-[11px] text-ink/50 mb-3 break-words">{subject}</p>
50
+ {children}
51
+ {error && <p className="text-[11px] text-error mb-2">{error}</p>}
52
+ <div className="flex justify-end space-x-2 mt-3">
53
+ <button
54
+ type="button"
55
+ onClick={onCancel}
56
+ className="px-3 py-1.5 text-xs text-ink hover:bg-ink/5 rounded transition-colors"
57
+ disabled={busy}
58
+ >
59
+ Cancel
60
+ </button>
61
+ <button
62
+ type="submit"
63
+ className="px-3 py-1.5 text-xs bg-ink text-canvas rounded hover:bg-ink/90 transition-colors flex items-center"
64
+ disabled={busy}
65
+ >
66
+ {busy ? busyLabel : submitLabel}
67
+ </button>
68
+ </div>
69
+ </form>
70
+ </div>,
71
+ document.body,
72
+ );
73
+ }
74
+
75
+ export interface CompressDialogProps {
76
+ entries: readonly ClipboardTarget[];
77
+ format: ArchiveFormat;
78
+ name: string;
79
+ destination: string;
80
+ formats: readonly ArchiveFormatOption[];
81
+ error: string | null;
82
+ busy: boolean;
83
+ onFormatChange: (format: ArchiveFormat) => void;
84
+ onNameChange: (name: string) => void;
85
+ onDestinationChange: (destination: string) => void;
86
+ onCancel: () => void;
87
+ onSubmit: () => void;
88
+ }
89
+
90
+ export function CompressDialog({
91
+ entries,
92
+ format,
93
+ name,
94
+ destination,
95
+ formats,
96
+ error,
97
+ busy,
98
+ onFormatChange,
99
+ onNameChange,
100
+ onDestinationChange,
101
+ onCancel,
102
+ onSubmit,
103
+ }: CompressDialogProps) {
104
+ const names = entries.slice(0, 4).map((entry) => entry.name).join(', ');
105
+ const more = entries.length > 4 ? ` +${entries.length - 4} more` : '';
106
+ return (
107
+ <ArchiveDialogShell
108
+ title={`Compress ${entries.length === 1 ? entries[0]!.name : `${entries.length} items`}`}
109
+ subject={`${names}${more}`}
110
+ error={error}
111
+ busy={busy}
112
+ submitLabel="Compress"
113
+ busyLabel="Compressing..."
114
+ onCancel={onCancel}
115
+ onSubmit={(event) => {
116
+ event.preventDefault();
117
+ onSubmit();
118
+ }}
119
+ >
120
+ <label className="block text-[10px] uppercase tracking-wide text-ink/40 mb-1" htmlFor="archive-format">
121
+ Format
122
+ </label>
123
+ <select
124
+ id="archive-format"
125
+ value={format}
126
+ onChange={(event) => onFormatChange(event.currentTarget.value as ArchiveFormat)}
127
+ className="w-full bg-paper border border-ink/20 rounded px-2 py-1.5 text-xs font-mono focus:outline-none focus:border-ink mb-3"
128
+ >
129
+ {formats.map((option) => (
130
+ <option key={option.id} value={option.id} disabled={!option.available}>
131
+ {option.label}
132
+ {option.available ? '' : ` — ${option.tool} not installed`}
133
+ </option>
134
+ ))}
135
+ </select>
136
+
137
+ <label className="block text-[10px] uppercase tracking-wide text-ink/40 mb-1" htmlFor="archive-name">
138
+ Archive name
139
+ </label>
140
+ <input
141
+ id="archive-name"
142
+ autoFocus
143
+ type="text"
144
+ value={name}
145
+ onChange={(event) => onNameChange(event.currentTarget.value)}
146
+ aria-label="Archive name"
147
+ className={`w-full bg-paper border rounded px-2 py-1.5 text-xs font-mono focus:outline-none mb-3 ${
148
+ error ? 'border-error' : 'border-ink/20 focus:border-ink'
149
+ }`}
150
+ />
151
+
152
+ <label className="block text-[10px] uppercase tracking-wide text-ink/40 mb-1" htmlFor="archive-destination">
153
+ Destination folder
154
+ </label>
155
+ <input
156
+ id="archive-destination"
157
+ type="text"
158
+ value={destination}
159
+ onChange={(event) => onDestinationChange(event.currentTarget.value)}
160
+ aria-label="Archive destination"
161
+ className="w-full bg-paper border border-ink/20 rounded px-2 py-1.5 text-xs font-mono focus:outline-none focus:border-ink"
162
+ />
163
+ </ArchiveDialogShell>
164
+ );
165
+ }
166
+
167
+ export interface ExtractDialogProps {
168
+ archive: ClipboardTarget;
169
+ /** The detected archive kind, shown so the user knows what will unpack. */
170
+ kindLabel: string;
171
+ destination: string;
172
+ error: string | null;
173
+ busy: boolean;
174
+ onDestinationChange: (destination: string) => void;
175
+ onCancel: () => void;
176
+ onSubmit: () => void;
177
+ }
178
+
179
+ export function ExtractDialog({
180
+ archive,
181
+ kindLabel,
182
+ destination,
183
+ error,
184
+ busy,
185
+ onDestinationChange,
186
+ onCancel,
187
+ onSubmit,
188
+ }: ExtractDialogProps) {
189
+ return (
190
+ <ArchiveDialogShell
191
+ title={`Extract ${archive.name}`}
192
+ subject={`${kindLabel} archive · extracts into a folder`}
193
+ error={error}
194
+ busy={busy}
195
+ submitLabel="Extract"
196
+ busyLabel="Extracting..."
197
+ onCancel={onCancel}
198
+ onSubmit={(event) => {
199
+ event.preventDefault();
200
+ onSubmit();
201
+ }}
202
+ >
203
+ <label className="block text-[10px] uppercase tracking-wide text-ink/40 mb-1" htmlFor="extract-destination">
204
+ Extract to folder
205
+ </label>
206
+ <input
207
+ id="extract-destination"
208
+ autoFocus
209
+ type="text"
210
+ value={destination}
211
+ onChange={(event) => onDestinationChange(event.currentTarget.value)}
212
+ aria-label="Extract destination"
213
+ className={`w-full bg-paper border rounded px-2 py-1.5 text-xs font-mono focus:outline-none ${
214
+ error ? 'border-error' : 'border-ink/20 focus:border-ink'
215
+ }`}
216
+ />
217
+ </ArchiveDialogShell>
218
+ );
219
+ }
220
+
221
+ /**
222
+ * Both archive dialogs, driven by the panel's one `useFileArchive` handle.
223
+ *
224
+ * The panel renders this once, beside the tree: the draft, the format list and
225
+ * the busy flag all live in the hook, so the overlay is a pure projection and
226
+ * the panel does not grow two 20-line prop blocks.
227
+ */
228
+ export function ArchiveOverlays({ archive }: { archive: FileArchive }) {
229
+ if (archive.compress) {
230
+ return (
231
+ <CompressDialog
232
+ entries={archive.compress.entries}
233
+ format={archive.compress.format}
234
+ name={archive.compress.name}
235
+ destination={archive.compress.destination}
236
+ formats={archive.formats}
237
+ error={archive.error}
238
+ busy={archive.busy}
239
+ onFormatChange={archive.setFormat}
240
+ onNameChange={archive.setName}
241
+ onDestinationChange={archive.setCompressDestination}
242
+ onCancel={archive.cancel}
243
+ onSubmit={archive.submitCompress}
244
+ />
245
+ );
246
+ }
247
+ if (archive.extract) {
248
+ return (
249
+ <ExtractDialog
250
+ archive={archive.extract.archive}
251
+ kindLabel={archiveKindLabel(archiveKindOf(archive.extract.archive.name) ?? 'zip')}
252
+ destination={archive.extract.destination}
253
+ error={archive.error}
254
+ busy={archive.busy}
255
+ onDestinationChange={archive.setExtractDestination}
256
+ onCancel={archive.cancel}
257
+ onSubmit={archive.submitExtract}
258
+ />
259
+ );
260
+ }
261
+ return null;
262
+ }
@@ -29,7 +29,7 @@
29
29
 
30
30
  import { createPortal } from 'preact/compat';
31
31
  import type { ReactNode, RefObject } from 'preact/compat';
32
- import { ChevronDown, ChevronRight, ClipboardPaste, Copy, CopyPlus, Edit2, ExternalLink, Eye, FilePlus, FolderPlus, GitCompare, History, Scissors, Trash2 } from 'lucide-preact';
32
+ import { Archive, ChevronDown, ChevronRight, ClipboardPaste, Copy, CopyPlus, Edit2, ExternalLink, Eye, FilePlus, FolderPlus, GitCompare, History, PackageOpen, Scissors, Trash2 } from 'lucide-preact';
33
33
 
34
34
  interface ContextMenuProps {
35
35
  x: number;
@@ -44,6 +44,10 @@ interface ContextMenuProps {
44
44
  foldable?: boolean;
45
45
  /** True while a transfer is in flight; the acting rows disable on it. */
46
46
  busy: boolean;
47
+ /** How many rows the transfer and archive verbs act on. */
48
+ selectionCount: number;
49
+ /** True when the target row is an archive the Extract flow understands. */
50
+ isArchive: boolean;
47
51
  onAction: (actionType: string) => void;
48
52
  menuRef?: RefObject<HTMLDivElement>;
49
53
  }
@@ -59,9 +63,25 @@ const SEPARATOR_PX = 9;
59
63
  const PADDING_PX = 8;
60
64
 
61
65
  /** The rows this target offers, in order — the menu's single source of truth. */
62
- function buildRows(options: { isFolder: boolean; hasGitStatus?: boolean; pasteLabel: string | null; busy: boolean; chainLabel?: boolean; foldable?: boolean }): MenuEntry[] {
63
- const { isFolder, hasGitStatus, pasteLabel, busy, chainLabel, foldable } = options;
66
+ function buildRows(options: { isFolder: boolean; hasGitStatus?: boolean; pasteLabel: string | null; busy: boolean; chainLabel?: boolean; foldable?: boolean; selectionCount: number; isArchive: boolean }): MenuEntry[] {
67
+ const { isFolder, hasGitStatus, pasteLabel, busy, chainLabel, foldable, selectionCount, isArchive } = options;
64
68
  const entries: MenuEntry[] = [];
69
+ const many = selectionCount > 1;
70
+ const count = selectionCount === 1 ? '' : ` ${selectionCount} items`;
71
+
72
+ // A multi-selection is a different object from a row: View, Rename,
73
+ // Duplicate and History all name ONE entry, and offering them for five rows
74
+ // would silently act on the row that was right-clicked. The menu says what
75
+ // the selection can actually do.
76
+ if (many) {
77
+ entries.push({ kind: 'item', id: 'cut', label: `Cut${count}`, icon: <Scissors size={13} className="text-ink/60" />, disabled: busy });
78
+ entries.push({ kind: 'item', id: 'copy', label: `Copy${count}`, icon: <Copy size={13} className="text-ink/60" />, disabled: busy });
79
+ entries.push({ kind: 'separator' });
80
+ entries.push({ kind: 'item', id: 'compress', label: `Compress${count} to…`, icon: <Archive size={13} className="text-ink/60" />, disabled: busy });
81
+ entries.push({ kind: 'separator' });
82
+ entries.push({ kind: 'item', id: 'delete', label: `Delete${count}`, icon: <Trash2 size={13} className="text-error" />, tone: 'text-error' });
83
+ return entries;
84
+ }
65
85
 
66
86
  if (isFolder) {
67
87
  entries.push({ kind: 'item', id: 'new_file', label: 'New File', icon: <FilePlus size={13} className="text-ink/60" /> });
@@ -78,6 +98,9 @@ function buildRows(options: { isFolder: boolean; hasGitStatus?: boolean; pasteLa
78
98
  entries.push({ kind: 'separator' });
79
99
  } else {
80
100
  entries.push({ kind: 'item', id: 'view', label: 'View', icon: <Eye size={13} className="text-ink/60" /> });
101
+ if (isArchive) {
102
+ entries.push({ kind: 'item', id: 'extract', label: 'Extract…', icon: <PackageOpen size={13} className="text-ink/60" />, disabled: busy });
103
+ }
81
104
  if (hasGitStatus) {
82
105
  entries.push({ kind: 'item', id: 'diff', label: 'Open in Diff Panel', icon: <GitCompare size={13} className="text-warning" />, tone: 'font-medium' });
83
106
  }
@@ -86,6 +109,7 @@ function buildRows(options: { isFolder: boolean; hasGitStatus?: boolean; pasteLa
86
109
 
87
110
  entries.push({ kind: 'item', id: 'cut', label: 'Cut', icon: <Scissors size={13} className="text-ink/60" />, disabled: busy });
88
111
  entries.push({ kind: 'item', id: 'copy', label: 'Copy', icon: <Copy size={13} className="text-ink/60" />, disabled: busy });
112
+ entries.push({ kind: 'item', id: 'compress', label: 'Compress to…', icon: <Archive size={13} className="text-ink/60" />, disabled: busy });
89
113
  entries.push({ kind: 'item', id: 'duplicate', label: 'Duplicate', icon: <CopyPlus size={13} className="text-ink/60" />, disabled: busy });
90
114
  if (pasteLabel) {
91
115
  entries.push({ kind: 'item', id: 'paste', label: pasteLabel, icon: <ClipboardPaste size={13} className="text-ink/60" />, disabled: busy });
@@ -113,9 +137,9 @@ function menuHeightOf(entries: MenuEntry[]): number {
113
137
  return items * ROW_PX + separators * SEPARATOR_PX + PADDING_PX;
114
138
  }
115
139
 
116
- export function FileContextMenu({ x, y, isFolder, hasGitStatus, pasteLabel, chainLabel, foldable, busy, onAction, menuRef }: ContextMenuProps) {
117
- const menuWidth = 190;
118
- const entries = buildRows({ isFolder, hasGitStatus, pasteLabel, busy, chainLabel, foldable });
140
+ export function FileContextMenu({ x, y, isFolder, hasGitStatus, pasteLabel, chainLabel, foldable, busy, selectionCount, isArchive, onAction, menuRef }: ContextMenuProps) {
141
+ const menuWidth = 210;
142
+ const entries = buildRows({ isFolder, hasGitStatus, pasteLabel, busy, chainLabel, foldable, selectionCount, isArchive });
119
143
  const menuHeight = menuHeightOf(entries);
120
144
 
121
145
  const posX = typeof window !== 'undefined' ? Math.max(10, Math.min(x, window.innerWidth - menuWidth - 12)) : x;
@@ -85,17 +85,22 @@ interface DeleteModalProps {
85
85
  /** The row's label, when it differs from the path (a collapsed chain). */
86
86
  displayName?: string;
87
87
  isFolder: boolean;
88
+ /** How many entries the confirmation removes; 1 for the row's own dialog. */
89
+ count?: number;
88
90
  isLoading: boolean;
89
91
  onCancel: () => void;
90
92
  onConfirm: () => void;
91
93
  }
92
94
 
93
- export function FileDeleteModal({ fileName, displayName, isFolder, isLoading, onCancel, onConfirm }: DeleteModalProps) {
95
+ export function FileDeleteModal({ fileName, displayName, isFolder, count = 1, isLoading, onCancel, onConfirm }: DeleteModalProps) {
96
+ const multiple = count > 1;
94
97
  return createPortal(
95
98
  <div className="fixed inset-0 modal-scrim z-[100] flex items-center justify-center p-4 backdrop-blur-sm">
96
99
  <div className="glass-overlay bg-paper rounded shadow-xl p-4 w-full max-w-sm border border-ink/10 font-sans">
97
- <h3 className="font-semibold text-ink mb-2 text-sm">Delete {isFolder ? 'Folder' : 'File'}</h3>
98
- <p className="text-xs text-ink/70 mb-4">Are you sure you want to delete <span className="font-mono bg-canvas px-1 rounded">{fileName}</span>? This action cannot be undone.</p>
100
+ <h3 className="font-semibold text-ink mb-2 text-sm">Delete {multiple ? `${count} Items` : isFolder ? 'Folder' : 'File'}</h3>
101
+ <p className="text-xs text-ink/70 mb-4">
102
+ Are you sure you want to delete {multiple ? <>the {count} selected entries</> : <span className="font-mono bg-canvas px-1 rounded">{fileName}</span>}? This action cannot be undone.
103
+ </p>
99
104
  {/* A collapsed chain row is LABELLED `com/java/app/package` but its path
100
105
  is the deepest directory, and that is what gets deleted. Naming only
101
106
  the label would promise a removal of four directories and perform
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Files panel's ROOT-level overlays: the background's context menu and the
8
+ * New File / New Folder dialog it opens.
9
+ *
10
+ * Split out of `index.tsx` because the panel owns far too much state to also
11
+ * keep this markup inline, and because both pieces are pure projection of the
12
+ * root menu's state and the `useFileCreate` handle — no behaviour lives here.
13
+ */
14
+
15
+ import type { RefObject } from 'preact/compat';
16
+ import { RootContextMenu } from '@/client/components/workspace/file-explorer/RootMenu';
17
+ import { FileCreateModal } from '@/client/components/workspace/file-explorer/Modals';
18
+ import type { FileCreate } from '@/client/hooks/workspace/file-create';
19
+
20
+ export interface RootOverlaysProps {
21
+ menu: { x: number; y: number } | null;
22
+ menuRef: RefObject<HTMLDivElement>;
23
+ /** The clipboard label the root's Paste row shows, or null when it cannot land. */
24
+ pasteLabel: string | null;
25
+ busy: boolean;
26
+ /** A root menu action id; the panel closes the menu and dispatches. */
27
+ onAction: (action: string) => void;
28
+ /** The root's own create flow. */
29
+ create: FileCreate;
30
+ }
31
+
32
+ export function RootOverlays({ menu, menuRef, pasteLabel, busy, onAction, create }: RootOverlaysProps) {
33
+ return (
34
+ <>
35
+ {menu && (
36
+ <RootContextMenu
37
+ x={menu.x}
38
+ y={menu.y}
39
+ menuRef={menuRef}
40
+ pasteLabel={pasteLabel}
41
+ busy={busy}
42
+ onAction={onAction}
43
+ />
44
+ )}
45
+
46
+ {create.open && (
47
+ <FileCreateModal
48
+ folderPath="."
49
+ kind={create.kind}
50
+ value={create.name}
51
+ error={create.error}
52
+ isLoading={create.busy}
53
+ onChange={create.setName}
54
+ onCancel={create.closeDialog}
55
+ onSubmit={create.submit}
56
+ />
57
+ )}
58
+ </>
59
+ );
60
+ }
@@ -24,14 +24,18 @@ interface TreeRowLabelProps {
24
24
  isOpen: boolean;
25
25
  /** Git-ignored entries render faded rather than being hidden. */
26
26
  ignored: boolean;
27
+ /** The row is part of the panel's marked set. */
28
+ selected?: boolean;
27
29
  /** This file's own change, when it has one. */
28
30
  gitStatus: { colorClass: string; label: string; charStatus: string } | null;
29
31
  /** The roll-up a folder wears instead: one dot, its tone from the changes. */
30
32
  folderStatus: FolderGitStatusInfo | null | undefined;
31
33
  }
32
34
 
33
- export function TreeRowLabel({ name, path, isFolder, isOpen, ignored, gitStatus, folderStatus }: TreeRowLabelProps) {
34
- const tone = gitStatus ? gitStatus.colorClass : folderStatus ? folderStatus.colorClass : ignored ? 'text-ink/40' : '';
35
+ export function TreeRowLabel({ name, path, isFolder, isOpen, ignored, selected, gitStatus, folderStatus }: TreeRowLabelProps) {
36
+ const tone = selected
37
+ ? 'text-ink font-semibold'
38
+ : gitStatus ? gitStatus.colorClass : folderStatus ? folderStatus.colorClass : ignored ? 'text-ink/40' : '';
35
39
  return (
36
40
  <>
37
41
  {isFolder ? (