|
| 1 | +# Mobile Terminal Paste/Upload Implementation Plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | +
|
| 5 | +**Goal:** Add two mobile terminal actions: paste from clipboard and upload files/images from the device picker. |
| 6 | + |
| 7 | +**Architecture:** Keep the existing terminal upload pipeline in `use-paste-drop-upload`, but extend it with explicit entry points for clipboard reads and file picker uploads. `MobileTerminalInputBar` owns the visible buttons and emits user intent; `XtermHost` wires those intents to workspace-scoped upload helpers and disables the controls while uploads are in flight. Desktop terminal behavior stays unchanged. |
| 8 | + |
| 9 | +**Tech Stack:** React, TypeScript, Jotai, browser Clipboard API, browser file input, Vitest, Testing Library. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +### Task 1: Add mobile toolbar actions and wiring hooks |
| 14 | + |
| 15 | +**Files:** |
| 16 | +- Modify: `packages/web/src/features/terminal-panel/mobile/mobile-terminal-input-bar.tsx` |
| 17 | +- Modify: `packages/web/src/features/terminal-panel/views/shared/xterm-host.tsx` |
| 18 | +- Test: `packages/web/src/features/terminal-panel/mobile/mobile-terminal-input-bar.test.tsx` |
| 19 | + |
| 20 | +- [ ] **Step 1: Write the failing test** |
| 21 | + |
| 22 | +Add assertions that the mobile input bar renders two new buttons labeled `Paste` and `Upload`, and that clicking them invokes dedicated callbacks instead of terminal key handlers. |
| 23 | + |
| 24 | +```tsx |
| 25 | +it("renders paste and upload actions and dispatches their callbacks", () => { |
| 26 | + const onPaste = vi.fn(); |
| 27 | + const onUpload = vi.fn(); |
| 28 | + |
| 29 | + render( |
| 30 | + <MobileTerminalInputBar |
| 31 | + ctrlMode="off" |
| 32 | + shiftArmed={false} |
| 33 | + labels={labels} |
| 34 | + onKeyPress={vi.fn()} |
| 35 | + onCtrlTap={vi.fn()} |
| 36 | + onCtrlLongPress={vi.fn()} |
| 37 | + onShiftTap={vi.fn()} |
| 38 | + onPaste={onPaste} |
| 39 | + onUpload={onUpload} |
| 40 | + /> |
| 41 | + ); |
| 42 | + |
| 43 | + fireEvent.click(screen.getByRole("button", { name: "Paste" })); |
| 44 | + fireEvent.click(screen.getByRole("button", { name: "Upload" })); |
| 45 | + |
| 46 | + expect(onPaste).toHaveBeenCalledTimes(1); |
| 47 | + expect(onUpload).toHaveBeenCalledTimes(1); |
| 48 | +}); |
| 49 | +``` |
| 50 | + |
| 51 | +- [ ] **Step 2: Run the test to verify it fails** |
| 52 | + |
| 53 | +Run: `pnpm vitest packages/web/src/features/terminal-panel/mobile/mobile-terminal-input-bar.test.tsx -t "renders paste and upload actions and dispatches their callbacks" -v` |
| 54 | + |
| 55 | +Expected: fail because the props and buttons do not exist yet. |
| 56 | + |
| 57 | +- [ ] **Step 3: Write the minimal implementation** |
| 58 | + |
| 59 | +Add `onPaste` and `onUpload` props to `MobileTerminalInputBar`, render two leading action buttons in the mobile bar, and forward clicks to the callbacks. In `xterm-host.tsx`, pass handlers that will be implemented in the next task. |
| 60 | + |
| 61 | +```tsx |
| 62 | +interface MobileTerminalInputBarProps { |
| 63 | + // existing props... |
| 64 | + onPaste: () => void; |
| 65 | + onUpload: () => void; |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +- [ ] **Step 4: Run the test to verify it passes** |
| 70 | + |
| 71 | +Run: `pnpm vitest packages/web/src/features/terminal-panel/mobile/mobile-terminal-input-bar.test.tsx -v` |
| 72 | + |
| 73 | +Expected: pass, with the new buttons appearing before the terminal key group. |
| 74 | + |
| 75 | +- [ ] **Step 5: Commit** |
| 76 | + |
| 77 | +```bash |
| 78 | +git add packages/web/src/features/terminal-panel/mobile/mobile-terminal-input-bar.tsx packages/web/src/features/terminal-panel/mobile/mobile-terminal-input-bar.test.tsx packages/web/src/features/terminal-panel/views/shared/xterm-host.tsx |
| 79 | +git commit -m "feat: add mobile terminal paste and upload actions" |
| 80 | +``` |
| 81 | + |
| 82 | +### Task 2: Implement clipboard paste and file-picker upload flows |
| 83 | + |
| 84 | +**Files:** |
| 85 | +- Modify: `packages/web/src/features/terminal-panel/uploads/use-paste-drop-upload.ts` |
| 86 | +- Modify: `packages/web/src/features/terminal-panel/views/shared/xterm-host.tsx` |
| 87 | +- Test: `packages/web/src/features/terminal-panel/uploads/use-paste-drop-upload.test.tsx` |
| 88 | +- Test: `packages/web/src/features/terminal-panel/__tests__/xterm-host.test.tsx` |
| 89 | + |
| 90 | +- [ ] **Step 1: Write the failing test** |
| 91 | + |
| 92 | +Add coverage for two new helpers: |
| 93 | +- a clipboard path that reads `ClipboardItem`s or text and uploads image files when present |
| 94 | +- a file-picker path that uploads selected files and then writes the quoted terminal command back into the PTY |
| 95 | + |
| 96 | +```ts |
| 97 | +it("uploads clipboard image files when paste is requested", async () => { |
| 98 | + // mock navigator.clipboard.read() to return an image ClipboardItem |
| 99 | + // assert uploadFiles receives a File and sendTextToTerminal gets the quoted path |
| 100 | +}); |
| 101 | + |
| 102 | +it("uploads files selected from the picker when upload is requested", async () => { |
| 103 | + // mock an <input type=\"file\"> selection and assert the same upload path is used |
| 104 | +}); |
| 105 | +``` |
| 106 | + |
| 107 | +- [ ] **Step 2: Run the tests to verify they fail** |
| 108 | + |
| 109 | +Run: |
| 110 | +`pnpm vitest packages/web/src/features/terminal-panel/uploads/use-paste-drop-upload.test.tsx packages/web/src/features/terminal-panel/__tests__/xterm-host.test.tsx -v` |
| 111 | + |
| 112 | +Expected: fail because the new public helpers and host wiring do not exist yet. |
| 113 | + |
| 114 | +- [ ] **Step 3: Write the minimal implementation** |
| 115 | + |
| 116 | +Extend `use-paste-drop-upload` with explicit methods for: |
| 117 | +- reading clipboard files/text from a user gesture |
| 118 | +- uploading an arbitrary `File[]` |
| 119 | + |
| 120 | +Keep the existing paste/drop DOM listeners intact for desktop and non-mobile surfaces. In `xterm-host.tsx`, wire the new mobile buttons to the new helpers and add a hidden file input or equivalent picker flow scoped to mobile only. |
| 121 | + |
| 122 | +```ts |
| 123 | +// shape only; keep existing uploadFiles/quoteShellSingle flow |
| 124 | +type UploadSource = "clipboard" | "picker"; |
| 125 | +``` |
| 126 | + |
| 127 | +- [ ] **Step 4: Run the tests to verify they pass** |
| 128 | + |
| 129 | +Run: |
| 130 | +`pnpm vitest packages/web/src/features/terminal-panel/uploads/use-paste-drop-upload.test.tsx packages/web/src/features/terminal-panel/__tests__/xterm-host.test.tsx -v` |
| 131 | + |
| 132 | +Expected: pass, with clipboard and picker uploads both producing quoted terminal insertions and error toasts on failure. |
| 133 | + |
| 134 | +- [ ] **Step 5: Commit** |
| 135 | + |
| 136 | +```bash |
| 137 | +git add packages/web/src/features/terminal-panel/uploads/use-paste-drop-upload.ts packages/web/src/features/terminal-panel/views/shared/xterm-host.tsx packages/web/src/features/terminal-panel/uploads/use-paste-drop-upload.test.tsx packages/web/src/features/terminal-panel/__tests__/xterm-host.test.tsx |
| 138 | +git commit -m "feat: wire mobile terminal clipboard and file upload" |
| 139 | +``` |
| 140 | + |
| 141 | +### Task 3: Add labels, polish layout, and verify mobile behavior |
| 142 | + |
| 143 | +**Files:** |
| 144 | +- Modify: `packages/web/src/locales/en.json` |
| 145 | +- Modify: `packages/web/src/locales/zh.json` |
| 146 | +- Modify: `packages/web/src/styles/components.css` |
| 147 | +- Test: `packages/web/src/features/terminal-panel/mobile/mobile-terminal-input-bar.test.tsx` |
| 148 | + |
| 149 | +- [ ] **Step 1: Write the failing test** |
| 150 | + |
| 151 | +Extend the mobile input bar test to assert the new action buttons are present, readable, and do not collapse the existing terminal key order on narrow layouts. |
| 152 | + |
| 153 | +```ts |
| 154 | +expect(screen.getByRole("button", { name: "Paste" })).toBeInTheDocument(); |
| 155 | +expect(screen.getByRole("button", { name: "Upload" })).toBeInTheDocument(); |
| 156 | +``` |
| 157 | + |
| 158 | +- [ ] **Step 2: Run the test to verify it fails** |
| 159 | + |
| 160 | +Run: `pnpm vitest packages/web/src/features/terminal-panel/mobile/mobile-terminal-input-bar.test.tsx -v` |
| 161 | + |
| 162 | +Expected: fail until the labels and layout styles are added. |
| 163 | + |
| 164 | +- [ ] **Step 3: Write the minimal implementation** |
| 165 | + |
| 166 | +Add localized labels for the two actions in `en.json` and `zh.json`, then update `components.css` so the two action buttons read as a separate group from the terminal keys without shrinking the existing soft-key row. |
| 167 | + |
| 168 | +- [ ] **Step 4: Run the tests to verify they pass** |
| 169 | + |
| 170 | +Run: `pnpm vitest packages/web/src/features/terminal-panel/mobile/mobile-terminal-input-bar.test.tsx packages/web/src/features/terminal-panel/uploads/use-paste-drop-upload.test.tsx packages/web/src/features/terminal-panel/__tests__/xterm-host.test.tsx -v` |
| 171 | + |
| 172 | +Expected: pass, and the mobile bar should still fit on small screens with horizontal scrolling for the terminal keys. |
| 173 | + |
| 174 | +- [ ] **Step 5: Commit** |
| 175 | + |
| 176 | +```bash |
| 177 | +git add packages/web/src/locales/en.json packages/web/src/locales/zh.json packages/web/src/styles/components.css packages/web/src/features/terminal-panel/mobile/mobile-terminal-input-bar.test.tsx |
| 178 | +git commit -m "feat: polish mobile terminal paste and upload actions" |
| 179 | +``` |
| 180 | + |
0 commit comments