diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..ac71ce785 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: wavetermdev diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index c1715117d..397ce1c97 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -2,7 +2,8 @@ ## Project Rules -Read and follow all guidelines in [`.roo/rules/rules.md`](./.roo/rules/rules.md). +- See the overview of the project in `.kilocode/rules/overview.md` +- Read and follow all guidelines in `.kilocode/rules/rules.md` --- @@ -10,14 +11,36 @@ Read and follow all guidelines in [`.roo/rules/rules.md`](./.roo/rules/rules.md) This project uses a set of "skill" guides — focused how-to documents for common implementation tasks. When your task matches one of the descriptions below, **read the linked SKILL.md file before proceeding** and follow its instructions precisely. -| Skill | Description | -|-------|-------------| -| [add-config](./.kilocode/skills/add-config/SKILL.md) | Guide for adding new configuration settings to Wave Terminal. Use when adding a new setting to the configuration system, implementing a new config key, or adding user-customizable settings. | -| [add-rpc](./.kilocode/skills/add-rpc/SKILL.md) | Guide for adding new RPC calls to Wave Terminal. Use when implementing new RPC commands, adding server-client communication methods, or extending the RPC interface with new functionality. | -| [add-wshcmd](./.kilocode/skills/add-wshcmd/SKILL.md) | Guide for adding new wsh commands to Wave Terminal. Use when implementing new CLI commands, adding command-line functionality, or extending the wsh command interface. | -| [context-menu](./.kilocode/skills/context-menu/SKILL.md) | Guide for creating and displaying context menus in Wave Terminal. Use when implementing right-click menus, adding context menu items, creating submenus, or handling menu interactions with checkboxes and separators. | -| [create-view](./.kilocode/skills/create-view/SKILL.md) | Guide for implementing a new view type in Wave Terminal. Use when creating a new view component, implementing the ViewModel interface, registering a new view type in BlockRegistry, or adding a new content type to display within blocks. | -| [electron-api](./.kilocode/skills/electron-api/SKILL.md) | Guide for adding new Electron APIs to Wave Terminal. Use when implementing new frontend-to-electron communications via preload/IPC. | -| [wps-events](./.kilocode/skills/wps-events/SKILL.md) | Guide for working with Wave Terminal's WPS (Wave PubSub) event system. Use when implementing new event types, publishing events, subscribing to events, or adding asynchronous communication between components. | +| Skill | File | Description | +| ------------ | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| add-config | `.kilocode/skills/add-config/SKILL.md` | Guide for adding new configuration settings to Wave Terminal. Use when adding a new setting to the configuration system, implementing a new config key, or adding user-customizable settings. | +| add-rpc | `.kilocode/skills/add-rpc/SKILL.md` | Guide for adding new RPC calls to Wave Terminal. Use when implementing new RPC commands, adding server-client communication methods, or extending the RPC interface with new functionality. | +| add-wshcmd | `.kilocode/skills/add-wshcmd/SKILL.md` | Guide for adding new wsh commands to Wave Terminal. Use when implementing new CLI commands, adding command-line functionality, or extending the wsh command interface. | +| context-menu | `.kilocode/skills/context-menu/SKILL.md` | Guide for creating and displaying context menus in Wave Terminal. Use when implementing right-click menus, adding context menu items, creating submenus, or handling menu interactions with checkboxes and separators. | +| create-view | `.kilocode/skills/create-view/SKILL.md` | Guide for implementing a new view type in Wave Terminal. Use when creating a new view component, implementing the ViewModel interface, registering a new view type in BlockRegistry, or adding a new content type to display within blocks. | +| electron-api | `.kilocode/skills/electron-api/SKILL.md` | Guide for adding new Electron APIs to Wave Terminal. Use when implementing new frontend-to-electron communications via preload/IPC. | +| waveenv | `.kilocode/skills/waveenv/SKILL.md` | Guide for creating WaveEnv narrowings in Wave Terminal. Use when writing a named subset type of WaveEnv for a component tree, documenting environmental dependencies, or enabling mock environments for preview/test server usage. | +| wps-events | `.kilocode/skills/wps-events/SKILL.md` | Guide for working with Wave Terminal's WPS (Wave PubSub) event system. Use when implementing new event types, publishing events, subscribing to events, or adding asynchronous communication between components. | > **How skills work:** Each skill is a self-contained guide covering the exact files to edit, patterns to follow, and steps to take for a specific type of task in this codebase. If your task matches a skill's description, open that SKILL.md and treat it as your primary reference for the implementation. + +--- + +## Preview Server + +To run the standalone component preview (no Electron, no backend required): + +``` +task preview +``` + +This runs `cd frontend/preview && npx vite` and serves at **http://localhost:7007** (port configured in `frontend/preview/vite.config.ts`). + +To build a static preview: `task build:preview` + +**Do NOT use any of the following to start the preview — they all launch the full Electron app or serve the wrong content:** + +- `npm run dev` — runs `electron-vite dev`, launches Electron +- `npm run start` — also launches Electron +- `npx vite` from the repo root — uses the Electron-Vite config, not the preview app +- Serving the `dist/` directory — the preview app is never built there; it has its own build output diff --git a/.gitignore b/.gitignore index 161db5f19..baef317b7 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ out/ make/ artifacts/ mikework/ +aiplans/ manifests/ .env out @@ -38,3 +39,4 @@ test-results.xml docsite/ .kilo-format-temp-* +.ruvector/ diff --git a/.kilocode/skills/add-rpc/SKILL.md b/.kilocode/skills/add-rpc/SKILL.md index 8bed6ea6e..0bf5117f9 100644 --- a/.kilocode/skills/add-rpc/SKILL.md +++ b/.kilocode/skills/add-rpc/SKILL.md @@ -26,7 +26,7 @@ RPC commands in Wave Terminal follow these conventions: - **Method names** must end with `Command` - **First parameter** must be `context.Context` -- **Second parameter** (optional) is the command data structure +- **Remaining parameters** are a regular Go parameter list (zero or more typed args) - **Return values** can be either just an error, or one return value plus an error - **Streaming commands** return a channel instead of a direct value @@ -49,7 +49,7 @@ type WshRpcInterface interface { - Method name must end with `Command` - First parameter must be `ctx context.Context` -- Optional second parameter for input data +- Remaining parameters are a regular Go parameter list (zero or more) - Return either `error` or `(ReturnType, error)` - For streaming, return `chan RespOrErrorUnion[T]` diff --git a/.kilocode/skills/electron-api/SKILL.md b/.kilocode/skills/electron-api/SKILL.md index 57638b212..0014e82a5 100644 --- a/.kilocode/skills/electron-api/SKILL.md +++ b/.kilocode/skills/electron-api/SKILL.md @@ -7,11 +7,12 @@ description: Guide for adding new Electron APIs to Wave Terminal. Use when imple Electron APIs allow the frontend to call Electron main process functionality directly via IPC. -## Three Files to Edit +## Four Files to Edit 1. [`frontend/types/custom.d.ts`](frontend/types/custom.d.ts) - TypeScript [`ElectronApi`](frontend/types/custom.d.ts:82) type 2. [`emain/preload.ts`](emain/preload.ts) - Expose method via `contextBridge` 3. [`emain/emain-ipc.ts`](emain/emain-ipc.ts) - Implement IPC handler +4. [`frontend/preview/preview-electron-api.ts`](frontend/preview/preview-electron-api.ts) - Add a no-op stub to keep the `previewElectronApi` object in sync with the `ElectronApi` type ## Three Communication Patterns @@ -54,7 +55,15 @@ electron.ipcMain.handle("capture-screenshot", async (event, rect) => { }); ``` -### 4. Call from Frontend +### 4. Add Preview Stub + +In [`frontend/preview/preview-electron-api.ts`](frontend/preview/preview-electron-api.ts): + +```typescript +captureScreenshot: (_rect: Electron.Rectangle) => Promise.resolve(""), +``` + +### 5. Call from Frontend ```typescript import { getApi } from "@/store/global"; @@ -167,6 +176,7 @@ webContents.send("zoom-factor-change", newZoomFactor); - [ ] Include IPC channel name in comment - [ ] Expose in [`preload.ts`](emain/preload.ts) - [ ] Implement in [`emain-ipc.ts`](emain/emain-ipc.ts) +- [ ] Add no-op stub to [`preview-electron-api.ts`](frontend/preview/preview-electron-api.ts) - [ ] IPC channel names match exactly - [ ] **For sync**: Set `event.returnValue` (or browser hangs!) - [ ] Test end-to-end diff --git a/.kilocode/skills/waveenv/SKILL.md b/.kilocode/skills/waveenv/SKILL.md new file mode 100644 index 000000000..aabda6846 --- /dev/null +++ b/.kilocode/skills/waveenv/SKILL.md @@ -0,0 +1,130 @@ +--- +name: waveenv +description: Guide for creating WaveEnv narrowings in Wave Terminal. Use when writing a named subset type of WaveEnv for a component tree, documenting environmental dependencies, or enabling mock environments for preview/test server usage. +--- + +# WaveEnv Narrowing Skill + +## Purpose + +A WaveEnv narrowing creates a _named subset type_ of `WaveEnv` that: + +1. Documents exactly which parts of the environment a component tree actually uses. +2. Forms a type contract so callers and tests know what to provide. +3. Enables mocking in the preview/test server — you only need to implement what's listed. + +## When To Create One + +Create a narrowing whenever you are writing a component (or group of components) that you want to test in the preview server, or when you want to make the environmental dependencies of a component tree explicit. + +## Core Principle: Only Include What You Use + +**Only list the fields, methods, atoms, and keys that the component tree actually accesses.** If you don't call `wos`, don't include `wos`. If you only call one RPC command, only list that one command. The narrowing is a precise dependency declaration — not a copy of `WaveEnv`. + +## File Location + +- **Separate file** (preferred for shared/complex envs): name it `env.ts` next to the component, e.g. `frontend/app/block/blockenv.ts`. +- **Inline** (acceptable for small, single-file components): export the type directly from the component file, e.g. `WidgetsEnv` in `frontend/app/workspace/widgets.tsx`. + +## Imports Required + +```ts +import { + BlockMetaKeyAtomFnType, // only if you use getBlockMetaKeyAtom + ConnConfigKeyAtomFnType, // only if you use getConnConfigKeyAtom + SettingsKeyAtomFnType, // only if you use getSettingsKeyAtom + WaveEnv, + WaveEnvSubset, +} from "@/app/waveenv/waveenv"; +``` + +## The Shape + +```ts +export type MyEnv = WaveEnvSubset<{ + // --- Simple WaveEnv properties --- + // Copy the type verbatim from WaveEnv with WaveEnv["key"] syntax. + isDev: WaveEnv["isDev"]; + createBlock: WaveEnv["createBlock"]; + showContextMenu: WaveEnv["showContextMenu"]; + platform: WaveEnv["platform"]; + + // --- electron: list only the methods you call --- + electron: { + openExternal: WaveEnv["electron"]["openExternal"]; + }; + + // --- rpc: list only the commands you call --- + rpc: { + ActivityCommand: WaveEnv["rpc"]["ActivityCommand"]; + ConnEnsureCommand: WaveEnv["rpc"]["ConnEnsureCommand"]; + }; + + // --- atoms: list only the atoms you read --- + atoms: { + modalOpen: WaveEnv["atoms"]["modalOpen"]; + fullConfigAtom: WaveEnv["atoms"]["fullConfigAtom"]; + }; + + // --- wos: always take the whole thing, no sub-typing needed --- + wos: WaveEnv["wos"]; + + // --- services: list only the services you call; no method-level narrowing --- + services: { + block: WaveEnv["services"]["block"]; + workspace: WaveEnv["services"]["workspace"]; + }; + + // --- key-parameterized atom factories: enumerate the keys you use --- + getSettingsKeyAtom: SettingsKeyAtomFnType<"app:focusfollowscursor" | "window:magnifiedblockopacity">; + getBlockMetaKeyAtom: BlockMetaKeyAtomFnType<"view" | "frame:title" | "connection">; + getConnConfigKeyAtom: ConnConfigKeyAtomFnType<"conn:wshenabled">; + + // --- other atom helpers: copy verbatim --- + getConnStatusAtom: WaveEnv["getConnStatusAtom"]; + getLocalHostDisplayNameAtom: WaveEnv["getLocalHostDisplayNameAtom"]; +}>; +``` + +### Automatically Included Fields + +Every `WaveEnvSubset` automatically includes the mock fields — you never need to declare them: + +- `isMock: boolean` +- `mockSetWaveObj: (oref: string, obj: T) => void` +- `mockModels?: Map` + +### Rules for Each Section + +| Section | Pattern | Notes | +| -------------------------- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------------- | +| `electron` | `electron: { method: WaveEnv["electron"]["method"]; }` | List every method called; omit the rest. | +| `rpc` | `rpc: { Cmd: WaveEnv["rpc"]["Cmd"]; }` | List every RPC command called; omit the rest. | +| `atoms` | `atoms: { atom: WaveEnv["atoms"]["atom"]; }` | List every atom read; omit the rest. | +| `wos` | `wos: WaveEnv["wos"]` | Take the whole `wos` object (no sub-typing needed), but **only add it if `wos` is actually used**. | +| `services` | `services: { svc: WaveEnv["services"]["svc"]; }` | List each service used; take the whole service object (no method-level narrowing). | +| `getSettingsKeyAtom` | `SettingsKeyAtomFnType<"key1" \| "key2">` | Union all settings keys accessed. | +| `getBlockMetaKeyAtom` | `BlockMetaKeyAtomFnType<"key1" \| "key2">` | Union all block meta keys accessed. | +| `getConnConfigKeyAtom` | `ConnConfigKeyAtomFnType<"key1">` | Union all conn config keys accessed. | +| All other `WaveEnv` fields | `WaveEnv["fieldName"]` | Copy type verbatim. | + +## Using the Narrowed Type in Components + +```ts +import { useWaveEnv } from "@/app/waveenv/waveenv"; +import { MyEnv } from "./myenv"; + +const MyComponent = memo(() => { + const env = useWaveEnv(); + // TypeScript now enforces you only access what's in MyEnv. + const val = useAtomValue(env.getSettingsKeyAtom("app:focusfollowscursor")); + ... +}); +``` + +The generic parameter on `useWaveEnv()` casts the context to your narrowed type. The real production `WaveEnv` satisfies every narrowing; mock envs only need to implement the listed subset. + +## Real Examples + +- `BlockEnv` in `frontend/app/block/blockenv.ts` — complex narrowing with all section types, in a separate file. +- `WidgetsEnv` in `frontend/app/workspace/widgets.tsx` — smaller narrowing defined inline in the component file. diff --git a/.roo/rules/rules.md b/.roo/rules/rules.md index 7efa154ea..341d328f9 100644 --- a/.roo/rules/rules.md +++ b/.roo/rules/rules.md @@ -84,8 +84,7 @@ The full API is defined in custom.d.ts as type ElectronApi. - **CRITICAL: Completion format MUST be: "Done: [one-line description]"** - **Keep your Task Completed summaries VERY short** -- **No lengthy pre-completion summaries** - Do not provide detailed explanations of implementation before using attempt_completion -- **No recaps of changes** - Skip explaining what was done before completion +- **No double-summarization** - Put your summary ONLY inside attempt_completion. Do not write a summary in the message body AND then repeat it in attempt_completion. One summary, one place. - **Go directly to completion** - After making changes, proceed directly to attempt_completion without summarizing - The project is currently an un-released POC / MVP. Do not worry about backward compatibility when making changes - With React hooks, always complete all hook calls at the top level before any conditional returns (including jotai hook calls useAtom and useAtomValue); when a user explicitly tells you a function handles null inputs, trust them and stop trying to "protect" it with unnecessary checks or workarounds. diff --git a/README.md b/README.md index c2d4a661d..2b8e0637a 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,14 @@ Find more information in our [Contributions Guide](CONTRIBUTING.md), which inclu - [Ways to contribute](CONTRIBUTING.md#contributing-to-wave-terminal) - [Contribution guidelines](CONTRIBUTING.md#before-you-start) +### Sponsoring Wave ❤️ + +If Wave Terminal is useful to you or your company, consider sponsoring development. + +Sponsorship helps support the time spent building and maintaining the project. + +- https://github.com/sponsors/wavetermdev + ## License Wave Terminal is licensed under the Apache-2.0 License. For more information on our dependencies, see [here](./ACKNOWLEDGEMENTS.md). diff --git a/Taskfile.yml b/Taskfile.yml index c9aa8bc6a..106ac99e0 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,4 +1,4 @@ -# Copyright 2024, Command Line Inc. +# Copyright 2026, Command Line Inc. # SPDX-License-Identifier: Apache-2.0 version: "3" @@ -8,8 +8,8 @@ vars: BIN_DIR: "bin" VERSION: sh: node version.cjs - RMRF: '{{if eq OS "windows"}}powershell Remove-Item -Force -Recurse -ErrorAction SilentlyContinue{{else}}rm -rf{{end}}' - DATE: '{{if eq OS "windows"}}powershell Get-Date -UFormat{{else}}date{{end}}' + RMRF: '{{if eq OS "windows"}}powershell -NoProfile -NonInteractive Remove-Item -Force -Recurse -ErrorAction SilentlyContinue{{else}}rm -rf{{end}}' + DATE: '{{if eq OS "windows"}}powershell -NoProfile -NonInteractive Get-Date -UFormat{{else}}date{{end}}' ARTIFACTS_BUCKET: waveterm-github-artifacts/staging-w2 RELEASES_BUCKET: dl.waveterm.dev/releases-w2 WINGET_PACKAGE: CommandLine.Wave @@ -239,7 +239,7 @@ tasks: desc: Build the wavesrv component for Windows platforms (only generates artifacts for the current architecture). platforms: [windows] cmds: - - cmd: powershell -Command "Remove-Item -Force -ErrorAction SilentlyContinue -Path dist/bin/wavesrv*" + - cmd: powershell -NoProfile -NonInteractive -Command "Remove-Item -Force -ErrorAction SilentlyContinue -Path dist/bin/wavesrv*" ignore_error: true - task: build:server:internal vars: @@ -279,9 +279,21 @@ tasks: - cmd: rm -f dist/bin/wsh* platforms: [darwin, linux] ignore_error: true - - cmd: powershell -Command "Remove-Item -Force -ErrorAction SilentlyContinue -Path dist/bin/wsh*" + - cmd: powershell -NoProfile -NonInteractive -Command "Remove-Item -Force -ErrorAction SilentlyContinue -Path dist/bin/wsh*" platforms: [windows] ignore_error: true + - task: build:wsh:parallel + deps: + - go:mod:tidy + - generate + sources: + - "cmd/wsh/**/*.go" + - "pkg/**/*.go" + generates: + - "dist/bin/wsh*" + + build:wsh:parallel: + deps: - task: build:wsh:internal vars: GOOS: darwin @@ -314,14 +326,7 @@ tasks: vars: GOOS: windows GOARCH: arm64 - deps: - - go:mod:tidy - - generate - sources: - - "cmd/wsh/**/*.go" - - "pkg/**/*.go" - generates: - - "dist/bin/wsh*" + internal: true build:wsh:internal: vars: @@ -343,7 +348,7 @@ tasks: - cmd: "{{.RMRF}} dist/tsunamiscaffold" ignore_error: true - task: copyfiles:'tsunami/frontend/scaffold':'dist/tsunamiscaffold' - - cmd: '{{if eq OS "windows"}}powershell Copy-Item -Path tsunami/templates/empty-gomod.tmpl -Destination dist/tsunamiscaffold/go.mod{{else}}cp tsunami/templates/empty-gomod.tmpl dist/tsunamiscaffold/go.mod{{end}}' + - cmd: '{{if eq OS "windows"}}powershell -NoProfile -NonInteractive Copy-Item -Path tsunami/templates/empty-gomod.tmpl -Destination dist/tsunamiscaffold/go.mod{{else}}cp tsunami/templates/empty-gomod.tmpl dist/tsunamiscaffold/go.mod{{end}}' deps: - tsunami:scaffold sources: @@ -502,7 +507,7 @@ tasks: copyfiles:*:*: desc: Recursively copy directory and its contents. internal: true - cmd: '{{if eq OS "windows"}}powershell Copy-Item -Recurse -Force -Path {{index .MATCH 0}} -Destination {{index .MATCH 1}}{{else}}mkdir -p "$(dirname {{index .MATCH 1}})" && cp -r {{index .MATCH 0}} {{index .MATCH 1}}{{end}}' + cmd: '{{if eq OS "windows"}}powershell -NoProfile -NonInteractive Copy-Item -Recurse -Force -Path {{index .MATCH 0}} -Destination {{index .MATCH 1}}{{else}}mkdir -p "$(dirname {{index .MATCH 1}})" && cp -r {{index .MATCH 0}} {{index .MATCH 1}}{{end}}' clean: desc: clean make/dist directories @@ -555,7 +560,7 @@ tasks: - cmd: rm -f package.json platforms: [darwin, linux] ignore_error: true - - cmd: powershell -Command "Remove-Item -Force -ErrorAction SilentlyContinue -Path package.json" + - cmd: powershell -NoProfile -NonInteractive -Command "Remove-Item -Force -ErrorAction SilentlyContinue -Path package.json" platforms: [windows] ignore_error: true - npm --no-workspaces init -y --init-license Apache-2.0 @@ -601,18 +606,18 @@ tasks: cmds: - cmd: "{{.RMRF}} scaffold" ignore_error: true - - powershell New-Item -ItemType Directory -Force -Path scaffold - - powershell Copy-Item -Path ../templates/package.json.tmpl -Destination scaffold/package.json - - powershell -Command "Set-Location scaffold; npm install" - - powershell Move-Item -Path scaffold/node_modules -Destination scaffold/nm - - powershell Copy-Item -Recurse -Force -Path dist -Destination scaffold/ - - powershell New-Item -ItemType Directory -Force -Path scaffold/dist/tw - - powershell Copy-Item -Path '../templates/*.go.tmpl' -Destination scaffold/ - - powershell Copy-Item -Path ../templates/tailwind.css -Destination scaffold/ - - powershell Copy-Item -Path ../templates/gitignore.tmpl -Destination scaffold/.gitignore - - powershell Copy-Item -Path 'src/element/*.tsx' -Destination scaffold/dist/tw/ - - powershell Copy-Item -Path '../ui/*.go' -Destination scaffold/dist/tw/ - - powershell Copy-Item -Path ../engine/errcomponent.go -Destination scaffold/dist/tw/ + - powershell -NoProfile -NonInteractive New-Item -ItemType Directory -Force -Path scaffold + - powershell -NoProfile -NonInteractive Copy-Item -Path ../templates/package.json.tmpl -Destination scaffold/package.json + - powershell -NoProfile -NonInteractive -Command "Set-Location scaffold; npm install" + - powershell -NoProfile -NonInteractive Move-Item -Path scaffold/node_modules -Destination scaffold/nm + - powershell -NoProfile -NonInteractive Copy-Item -Recurse -Force -Path dist -Destination scaffold/ + - powershell -NoProfile -NonInteractive New-Item -ItemType Directory -Force -Path scaffold/dist/tw + - powershell -NoProfile -NonInteractive Copy-Item -Path '../templates/*.go.tmpl' -Destination scaffold/ + - powershell -NoProfile -NonInteractive Copy-Item -Path ../templates/tailwind.css -Destination scaffold/ + - powershell -NoProfile -NonInteractive Copy-Item -Path ../templates/gitignore.tmpl -Destination scaffold/.gitignore + - powershell -NoProfile -NonInteractive Copy-Item -Path 'src/element/*.tsx' -Destination scaffold/dist/tw/ + - powershell -NoProfile -NonInteractive Copy-Item -Path '../ui/*.go' -Destination scaffold/dist/tw/ + - powershell -NoProfile -NonInteractive Copy-Item -Path ../engine/errcomponent.go -Destination scaffold/dist/tw/ tsunami:build: desc: Build the tsunami binary. @@ -620,7 +625,7 @@ tasks: - cmd: rm -f bin/tsunami* platforms: [darwin, linux] ignore_error: true - - cmd: powershell -Command "Remove-Item -Force -ErrorAction SilentlyContinue -Path bin/tsunami*" + - cmd: powershell -NoProfile -NonInteractive -Command "Remove-Item -Force -ErrorAction SilentlyContinue -Path bin/tsunami*" platforms: [windows] ignore_error: true - mkdir -p bin diff --git a/aiprompts/wave-osc-16162.md b/aiprompts/wave-osc-16162.md index fe9c8c835..3b42d52eb 100644 --- a/aiprompts/wave-osc-16162.md +++ b/aiprompts/wave-osc-16162.md @@ -125,23 +125,22 @@ Reports the current state of the command line input buffer. **Data Type:** ```typescript { - inputempty?: boolean; // Whether the command line buffer is empty + buffer64: string; // Base64-encoded command line buffer contents + cursor: number; // ZLE cursor position within the decoded buffer } ``` -**When:** Sent during ZLE (Zsh Line Editor) hooks when buffer state changes -- `zle-line-init` - When line editor is initialized -- `zle-line-pre-redraw` - Before line is redrawn +**When:** Sent in response to Wave writing `^_Wr` (`\x1fWr`) into the PTY while ZLE is active -**Purpose:** Allows Wave Terminal to track the state of the command line input. Currently reports whether the buffer is empty, but may be extended to include additional input state information in the future. +**Purpose:** Allows Wave Terminal to synchronize the full command line buffer and cursor position in a single round trip. **Example:** ```bash -# When buffer is empty -I;{"inputempty":true} +# Empty buffer at cursor 0 +I;{"buffer64":"","cursor":0} -# When buffer has content -I;{"inputempty":false} +# Buffer contains "echo hello" and cursor is after "echo" +I;{"buffer64":"ZWNobyBoZWxsbw==","cursor":4} ``` ### R - Reset Alternate Buffer @@ -178,12 +177,12 @@ Here's the typical sequence during shell interaction: → A (prompt start) 3. User types command and presses Enter - → I;{"inputempty":false} (input no longer empty - sent as user types) + → Wave writes `^_Wr` + → I;{"buffer64":"...","cursor":...} (full ZLE readback) → C;{"cmd64":"..."} (command about to execute) 4. Command runs and completes → D;{"exitcode":} (exit status) - → I;{"inputempty":true} (input empty again) → A (next prompt start) 5. Repeat from step 3... @@ -193,7 +192,7 @@ Here's the typical sequence during shell interaction: - Shell integration is **disabled** when running inside tmux or screen (`TMUX`, `STY` environment variables, or `tmux*`/`screen*` TERM values) - Commands are base64-encoded in the C sequence to safely handle special characters, newlines, and control characters -- The I (input empty) command is only sent when the state changes (not on every keystroke) +- The I command is produced by a ZLE widget bound to `^_Wr` and returns the exact `BUFFER` contents plus `CURSOR` - The M (metadata) command is only sent once during the first precmd - The D (exit status) command is skipped during the first precmd (no previous command to report) @@ -212,4 +211,4 @@ This is sent: - During first precmd (after metadata) - In the `chpwd` hook (whenever directory changes) -The path is URL-encoded to safely handle special characters. \ No newline at end of file +The path is URL-encoded to safely handle special characters. diff --git a/cmd/generatego/main-generatego.go b/cmd/generatego/main-generatego.go index 74767a5bc..ab7e33843 100644 --- a/cmd/generatego/main-generatego.go +++ b/cmd/generatego/main-generatego.go @@ -24,14 +24,15 @@ func GenerateWshClient() error { fmt.Fprintf(os.Stderr, "generating wshclient file to %s\n", WshClientFileName) var buf strings.Builder gogen.GenerateBoilerplate(&buf, "wshclient", []string{ + "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes", + "github.com/wavetermdev/waveterm/pkg/baseds", "github.com/wavetermdev/waveterm/pkg/telemetry/telemetrydata", - "github.com/wavetermdev/waveterm/pkg/wshutil", - "github.com/wavetermdev/waveterm/pkg/wshrpc", - "github.com/wavetermdev/waveterm/pkg/wconfig", + "github.com/wavetermdev/waveterm/pkg/vdom", "github.com/wavetermdev/waveterm/pkg/waveobj", + "github.com/wavetermdev/waveterm/pkg/wconfig", "github.com/wavetermdev/waveterm/pkg/wps", - "github.com/wavetermdev/waveterm/pkg/vdom", - "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes", + "github.com/wavetermdev/waveterm/pkg/wshrpc", + "github.com/wavetermdev/waveterm/pkg/wshutil", }) wshDeclMap := wshrpc.GenerateWshCommandDeclMap() for _, key := range utilfn.GetOrderedMapKeys(wshDeclMap) { diff --git a/cmd/generatets/main-generatets.go b/cmd/generatets/main-generatets.go index 2202c781f..f282f9fa1 100644 --- a/cmd/generatets/main-generatets.go +++ b/cmd/generatets/main-generatets.go @@ -88,7 +88,14 @@ func generateServicesFile(tsTypesMap map[reflect.Type]string) error { fmt.Fprintf(&buf, "// Copyright 2026, Command Line Inc.\n") fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n") fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n") - fmt.Fprintf(&buf, "import * as WOS from \"./wos\";\n\n") + fmt.Fprintf(&buf, "import * as WOS from \"./wos\";\n") + fmt.Fprintf(&buf, "import type { WaveEnv } from \"@/app/waveenv/waveenv\";\n\n") + fmt.Fprintf(&buf, "function callBackendService(waveEnv: WaveEnv, service: string, method: string, args: any[], noUIContext?: boolean): Promise {\n") + fmt.Fprintf(&buf, " if (waveEnv != null) {\n") + fmt.Fprintf(&buf, " return waveEnv.callBackendService(service, method, args, noUIContext)\n") + fmt.Fprintf(&buf, " }\n") + fmt.Fprintf(&buf, " return WOS.callBackendService(service, method, args, noUIContext);\n") + fmt.Fprintf(&buf, "}\n\n") orderedKeys := utilfn.GetOrderedMapKeys(service.ServiceMap) for _, serviceName := range orderedKeys { serviceObj := service.ServiceMap[serviceName] @@ -96,6 +103,22 @@ func generateServicesFile(tsTypesMap map[reflect.Type]string) error { fmt.Fprint(&buf, svcStr) fmt.Fprint(&buf, "\n") } + fmt.Fprintf(&buf, "export const AllServiceTypes = {\n") + for _, serviceName := range orderedKeys { + serviceObj := service.ServiceMap[serviceName] + serviceType := reflect.TypeOf(serviceObj) + tsServiceName := serviceType.Elem().Name() + fmt.Fprintf(&buf, " %q: %sType,\n", serviceName, tsServiceName) + } + fmt.Fprintf(&buf, "};\n\n") + fmt.Fprintf(&buf, "export const AllServiceImpls = {\n") + for _, serviceName := range orderedKeys { + serviceObj := service.ServiceMap[serviceName] + serviceType := reflect.TypeOf(serviceObj) + tsServiceName := serviceType.Elem().Name() + fmt.Fprintf(&buf, " %q: %s,\n", serviceName, tsServiceName) + } + fmt.Fprintf(&buf, "};\n") written, err := utilfn.WriteFileIfDifferent(fileName, buf.Bytes()) if !written { fmt.Fprintf(os.Stderr, "no changes to %s\n", fileName) @@ -112,9 +135,17 @@ func generateWshClientApiFile(tsTypeMap map[reflect.Type]string) error { fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n") fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n") fmt.Fprintf(&buf, "import { WshClient } from \"./wshclient\";\n\n") + fmt.Fprintf(&buf, "export interface MockRpcClient {\n") + fmt.Fprintf(&buf, " mockWshRpcCall(client: WshClient, command: string, data: any, opts?: RpcOpts): Promise;\n") + fmt.Fprintf(&buf, " mockWshRpcStream(client: WshClient, command: string, data: any, opts?: RpcOpts): AsyncGenerator;\n") + fmt.Fprintf(&buf, "}\n\n") orderedKeys := utilfn.GetOrderedMapKeys(declMap) fmt.Fprintf(&buf, "// WshServerCommandToDeclMap\n") - fmt.Fprintf(&buf, "class RpcApiType {\n") + fmt.Fprintf(&buf, "export class RpcApiType {\n") + fmt.Fprintf(&buf, " mockClient: MockRpcClient = null;\n\n") + fmt.Fprintf(&buf, " setMockRpcClient(client: MockRpcClient): void {\n") + fmt.Fprintf(&buf, " this.mockClient = client;\n") + fmt.Fprintf(&buf, " }\n\n") for _, methodDecl := range orderedKeys { methodDecl := declMap[methodDecl] methodStr := tsgen.GenerateWshClientApiMethod(methodDecl, tsTypeMap) diff --git a/cmd/server/main-server.go b/cmd/server/main-server.go index 1dfcf0d82..70c8b3a00 100644 --- a/cmd/server/main-server.go +++ b/cmd/server/main-server.go @@ -343,6 +343,8 @@ func startupActivityUpdate(firstLaunch bool) { ClientArch: wavebase.ClientArch(), ClientOSRelease: wavebase.UnameKernelRelease(), ClientIsDev: wavebase.IsDevMode(), + ClientPackageType: wavebase.ClientPackageType(), + ClientMacOSVersion: wavebase.ClientMacOSVersion(), AutoUpdateChannel: autoUpdateChannel, AutoUpdateEnabled: autoUpdateEnabled, LocalShellType: shellType, @@ -571,7 +573,11 @@ func main() { blocklogger.InitBlockLogger() jobcontroller.InitJobController() blockcontroller.InitBlockController() - wcore.InitTabIndicatorStore() + err = wcore.InitBadgeStore() + if err != nil { + log.Printf("error initializing badge store: %v\n", err) + return + } go func() { defer func() { panichandler.PanicHandler("GetSystemSummary", recover()) diff --git a/cmd/wsh/cmd/wshcmd-badge.go b/cmd/wsh/cmd/wshcmd-badge.go new file mode 100644 index 000000000..590ed1e40 --- /dev/null +++ b/cmd/wsh/cmd/wshcmd-badge.go @@ -0,0 +1,129 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package cmd + +import ( + "fmt" + "runtime" + + "github.com/google/uuid" + "github.com/spf13/cobra" + "github.com/wavetermdev/waveterm/pkg/baseds" + "github.com/wavetermdev/waveterm/pkg/waveobj" + "github.com/wavetermdev/waveterm/pkg/wps" + "github.com/wavetermdev/waveterm/pkg/wshrpc" + "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" + "github.com/wavetermdev/waveterm/pkg/wshutil" +) + +var badgeCmd = &cobra.Command{ + Use: "badge [icon]", + Short: "set or clear a block badge", + Args: cobra.MaximumNArgs(1), + RunE: badgeRun, + PreRunE: preRunSetupRpcClient, +} + +var ( + badgeColor string + badgePriority float64 + badgeClear bool + badgeBeep bool + badgePid int +) + +func init() { + rootCmd.AddCommand(badgeCmd) + badgeCmd.Flags().StringVar(&badgeColor, "color", "", "badge color") + badgeCmd.Flags().Float64Var(&badgePriority, "priority", 10, "badge priority") + badgeCmd.Flags().BoolVar(&badgeClear, "clear", false, "clear the badge") + badgeCmd.Flags().BoolVar(&badgeBeep, "beep", false, "play system bell sound") + badgeCmd.Flags().IntVar(&badgePid, "pid", 0, "watch a pid and automatically clear the badge when it exits (default priority 5)") +} + +func badgeRun(cmd *cobra.Command, args []string) (rtnErr error) { + defer func() { + sendActivity("badge", rtnErr == nil) + }() + + if badgePid > 0 && runtime.GOOS == "windows" { + return fmt.Errorf("--pid flag is not supported on Windows") + } + if badgePid > 0 && !cmd.Flags().Changed("priority") { + badgePriority = 5 + } + + oref, err := resolveBlockArg() + if err != nil { + return fmt.Errorf("resolving block: %v", err) + } + if oref.OType != waveobj.OType_Block && oref.OType != waveobj.OType_Tab { + return fmt.Errorf("badge oref must be a block or tab (got %q)", oref.OType) + } + + var eventData baseds.BadgeEvent + eventData.ORef = oref.String() + + if badgeClear { + eventData.Clear = true + } else { + icon := "circle-small" + if len(args) > 0 { + icon = args[0] + } + badgeId, err := uuid.NewV7() + if err != nil { + return fmt.Errorf("generating badge id: %v", err) + } + eventData.Badge = &baseds.Badge{ + BadgeId: badgeId.String(), + Icon: icon, + Color: badgeColor, + Priority: badgePriority, + PidLinked: badgePid > 0, + } + } + + event := wps.WaveEvent{ + Event: wps.Event_Badge, + Scopes: []string{oref.String()}, + Data: eventData, + } + + err = wshclient.EventPublishCommand(RpcClient, event, &wshrpc.RpcOpts{NoResponse: true}) + if err != nil { + return fmt.Errorf("publishing badge event: %v", err) + } + + if badgeBeep { + err = wshclient.ElectronSystemBellCommand(RpcClient, &wshrpc.RpcOpts{Route: "electron"}) + if err != nil { + return fmt.Errorf("playing system bell: %v", err) + } + } + + if badgePid > 0 && eventData.Badge != nil { + conn := RpcContext.Conn + if conn == "" { + conn = wshrpc.LocalConnName + } + connRoute := wshutil.MakeConnectionRouteId(conn) + watchData := wshrpc.CommandBadgeWatchPidData{ + Pid: badgePid, + ORef: *oref, + BadgeId: eventData.Badge.BadgeId, + } + err = wshclient.BadgeWatchPidCommand(RpcClient, watchData, &wshrpc.RpcOpts{Route: connRoute}) + if err != nil { + return fmt.Errorf("watching pid: %v", err) + } + } + + if badgeClear { + fmt.Printf("badge cleared\n") + } else { + fmt.Printf("badge set\n") + } + return nil +} diff --git a/cmd/wsh/cmd/wshcmd-debugterm.go b/cmd/wsh/cmd/wshcmd-debugterm.go new file mode 100644 index 000000000..66346c460 --- /dev/null +++ b/cmd/wsh/cmd/wshcmd-debugterm.go @@ -0,0 +1,551 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package cmd + +import ( + "encoding/base64" + "encoding/hex" + "encoding/json" + "fmt" + "io" + "os" + "strconv" + "strings" + "unicode/utf8" + + "github.com/spf13/cobra" + "github.com/wavetermdev/waveterm/pkg/wshrpc" + "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" +) + +const ( + DebugTermModeHex = "hex" + DebugTermModeDecode = "decode" +) + +var debugTermCmd = &cobra.Command{ + Use: "debugterm", + Short: "inspect recent terminal output bytes", + RunE: debugTermRun, + PreRunE: debugTermPreRun, + DisableFlagsInUseLine: true, + Hidden: true, +} + +var ( + debugTermSize int64 + debugTermMode string + debugTermStdin bool + debugTermInput string +) + +func init() { + rootCmd.AddCommand(debugTermCmd) + debugTermCmd.Flags().Int64Var(&debugTermSize, "size", 1000, "number of terminal bytes to read") + debugTermCmd.Flags().StringVar(&debugTermMode, "mode", DebugTermModeHex, "output mode: hex or decode") + debugTermCmd.Flags().BoolVar(&debugTermStdin, "stdin", false, "read input from stdin instead of rpc call") + debugTermCmd.Flags().StringVar(&debugTermInput, "input", "", "read input from file instead of rpc call") +} + +func debugTermRun(cmd *cobra.Command, args []string) (rtnErr error) { + defer func() { + sendActivity("debugterm", rtnErr == nil) + }() + mode, err := getDebugTermMode() + if err != nil { + return err + } + if debugTermStdin { + stdinData, err := io.ReadAll(WrappedStdin) + if err != nil { + return fmt.Errorf("reading stdin: %w", err) + } + termData, err := parseDebugTermStdinData(stdinData) + if err != nil { + return err + } + if mode == DebugTermModeDecode { + WriteStdout("%s", formatDebugTermDecode(termData)) + } else { + WriteStdout("%s", formatDebugTermHex(termData)) + } + return nil + } + if debugTermInput != "" { + fileData, err := os.ReadFile(debugTermInput) + if err != nil { + return fmt.Errorf("reading input file: %w", err) + } + termData, err := parseDebugTermStdinData(fileData) + if err != nil { + return err + } + if mode == DebugTermModeDecode { + WriteStdout("%s", formatDebugTermDecode(termData)) + } else { + WriteStdout("%s", formatDebugTermHex(termData)) + } + return nil + } + if debugTermSize <= 0 { + return fmt.Errorf("size must be greater than 0") + } + fullORef, err := resolveBlockArg() + if err != nil { + return err + } + rtn, err := wshclient.DebugTermCommand(RpcClient, wshrpc.CommandDebugTermData{ + BlockId: fullORef.OID, + Size: debugTermSize, + }, &wshrpc.RpcOpts{Timeout: 2000}) + if err != nil { + return fmt.Errorf("reading terminal output: %w", err) + } + termData, err := base64.StdEncoding.DecodeString(rtn.Data64) + if err != nil { + return fmt.Errorf("decoding terminal output: %w", err) + } + var output string + if mode == DebugTermModeDecode { + output = formatDebugTermDecode(termData) + } else { + output = formatDebugTermHex(termData) + } + WriteStdout("%s", output) + return nil +} + +func debugTermPreRun(cmd *cobra.Command, args []string) error { + if debugTermStdin || debugTermInput != "" { + return nil + } + return preRunSetupRpcClient(cmd, args) +} + +func getDebugTermMode() (string, error) { + mode := strings.ToLower(debugTermMode) + if mode != DebugTermModeHex && mode != DebugTermModeDecode { + return "", fmt.Errorf("invalid mode %q (expected %q or %q)", debugTermMode, DebugTermModeHex, DebugTermModeDecode) + } + return mode, nil +} + +type debugTermStdinEntry struct { + Data string `json:"data"` +} + +func parseDebugTermStdinData(data []byte) ([]byte, error) { + trimmed := strings.TrimSpace(string(data)) + if len(trimmed) == 0 { + return data, nil + } + if trimmed[0] == '[' { + // try array of structs first + var structArr []debugTermStdinEntry + err := json.Unmarshal(data, &structArr) + if err == nil { + parts := make([]string, len(structArr)) + for i, entry := range structArr { + parts[i] = entry.Data + } + return []byte(strings.Join(parts, "")), nil + } + fmt.Fprintf(os.Stderr, "json read err %v\n", err) + // try array of strings + var strArr []string + err = json.Unmarshal(data, &strArr) + if err == nil { + return []byte(strings.Join(strArr, "")), nil + } + } + return data, nil +} + +func formatDebugTermHex(data []byte) string { + return hex.Dump(data) +} + +func parseCursorForwardN(seq []byte) (int, bool) { + if len(seq) < 3 || seq[len(seq)-1] != 'C' { + return 0, false + } + params := string(seq[2 : len(seq)-1]) + if params == "" { + return 1, true + } + n, err := strconv.Atoi(params) + if err != nil || n <= 0 { + return 0, false + } + return n, true +} + +// splitOnCRLFRuns splits s at the end of each run of \r and \n characters. +// Each segment includes its trailing CR/LF run. The last segment may have no such run. +func splitOnCRLFRuns(s string) []string { + var result []string + for len(s) > 0 { + // find start of next CR/LF run + i := 0 + for i < len(s) && s[i] != '\r' && s[i] != '\n' { + i++ + } + if i == len(s) { + break + } + // consume the CR/LF run + j := i + for j < len(s) && (s[j] == '\r' || s[j] == '\n') { + j++ + } + result = append(result, s[:j]) + s = s[j:] + } + if len(s) > 0 { + result = append(result, s) + } + return result +} + +func formatDebugTermDecode(data []byte) string { + if len(data) == 0 { + return "" + } + lines := make([]string, 0) + // textBuf accumulates text across CSI-C (cursor forward) sequences so consecutive + // "word CSI-C word" runs collapse into a single TXT line. The // NC annotation goes + // on the last segment only. + textBuf := "" + totalCSpaces := 0 + flushText := func() { + if textBuf == "" && totalCSpaces == 0 { + return + } + segs := splitOnCRLFRuns(textBuf) + if len(segs) == 0 { + segs = []string{textBuf} + } + for i, seg := range segs { + if i == len(segs)-1 && totalCSpaces > 0 { + lines = append(lines, fmt.Sprintf("TXT %s // %dC", strconv.Quote(seg), totalCSpaces)) + } else { + lines = append(lines, "TXT "+strconv.Quote(seg)) + } + } + textBuf = "" + totalCSpaces = 0 + } + for i := 0; i < len(data); { + b := data[i] + if b == 0x1b { + if i+1 >= len(data) { + flushText() + lines = append(lines, "ESC") + i++ + continue + } + next := data[i+1] + switch next { + case '[': + seq, end := consumeDebugTermCSI(data, i) + if n, ok := parseCursorForwardN(seq); ok { + textBuf += strings.Repeat(" ", n) + totalCSpaces += n + } else { + flushText() + lines = append(lines, formatDebugTermCSILine(seq)) + } + i = end + case ']': + flushText() + seq, end := consumeDebugTermOSC(data, i) + lines = append(lines, formatDebugTermOSCLine(seq)) + i = end + case 'P': + flushText() + seq, end := consumeDebugTermST(data, i) + lines = append(lines, "DCS "+strconv.QuoteToASCII(string(seq))) + i = end + case '^': + flushText() + seq, end := consumeDebugTermST(data, i) + lines = append(lines, "PM "+strconv.QuoteToASCII(string(seq))) + i = end + case '_': + flushText() + seq, end := consumeDebugTermST(data, i) + lines = append(lines, "APC "+strconv.QuoteToASCII(string(seq))) + i = end + default: + flushText() + seq := data[i : i+2] + lines = append(lines, "ESC "+strconv.QuoteToASCII(string(seq))) + i += 2 + } + continue + } + if b == 0x07 { + flushText() + lines = append(lines, "BEL") + i++ + continue + } + start, end := consumeDebugTermText(data, i) + if end > start { + textBuf += string(data[start:end]) + i = end + continue + } + flushText() + lines = append(lines, fmt.Sprintf("CTL 0x%02x", b)) + i++ + } + flushText() + return strings.Join(lines, "\n") + "\n" +} + +var csiCommandDescriptions = map[byte]string{ + '@': "insert character", + 'A': "cursor up", + 'B': "cursor down", + 'C': "cursor forward", + 'D': "cursor back", + 'E': "cursor next line", + 'F': "cursor prev line", + 'G': "cursor horizontal absolute", + 'H': "cursor position", + 'I': "cursor horizontal tab", + 'J': "erase display", + 'K': "erase line", + 'L': "insert line", + 'M': "delete line", + 'P': "delete character", + 'S': "scroll up", + 'T': "scroll down", + 'X': "erase character", + 'Z': "cursor backward tab", + 'a': "cursor horizontal relative", + 'b': "repeat character", + 'c': "device attributes", + 'd': "cursor vertical absolute", + 'e': "cursor vertical relative", + 'f': "horizontal vertical position", + 'g': "tab clear", + 'h': "set mode", + 'l': "reset mode", + 'm': "SGR", + 'n': "device status report", + 'r': "set scrolling region", + 's': "save cursor", + 'u': "restore cursor", +} + +var decModeDescriptions = map[string]string{ + "1": "application cursor keys", + "3": "132 column mode", + "6": "origin mode", + "7": "auto wrap", + "12": "blinking cursor", + "25": "show cursor", + "47": "alternate screen", + "1000": "mouse X10 tracking", + "1002": "mouse button events", + "1003": "mouse all events", + "1004": "focus events", + "1006": "SGR mouse mode", + "1049": "alt screen + save cursor", + "2004": "bracketed paste", + "2026": "synchronized output", +} + +var sgrSingleDescriptions = map[int]string{ + 0: "reset all", + 1: "bold", + 2: "dim", + 3: "italic", + 4: "underline", + 5: "blink", + 7: "reverse", + 8: "hidden", + 9: "strikethrough", + 21: "doubly underlined", + 22: "normal intensity", + 23: "not italic", + 24: "not underlined", + 25: "not blinking", + 27: "not reversed", + 28: "not hidden", + 29: "not strikethrough", + 39: "default fg", + 49: "default bg", +} + +func describeSGR(params string) string { + if params == "" { + return "reset all" + } + parts := strings.Split(params, ";") + if len(parts) >= 5 && parts[0] == "38" && parts[1] == "2" { + return fmt.Sprintf("fg rgb(%s,%s,%s)", parts[2], parts[3], parts[4]) + } + if len(parts) >= 5 && parts[0] == "48" && parts[1] == "2" { + return fmt.Sprintf("bg rgb(%s,%s,%s)", parts[2], parts[3], parts[4]) + } + if len(parts) == 3 && parts[0] == "38" && parts[1] == "5" { + return fmt.Sprintf("fg color256(%s)", parts[2]) + } + if len(parts) == 3 && parts[0] == "48" && parts[1] == "5" { + return fmt.Sprintf("bg color256(%s)", parts[2]) + } + if len(parts) != 1 { + return "" + } + n, err := strconv.Atoi(parts[0]) + if err != nil { + return "" + } + if desc, ok := sgrSingleDescriptions[n]; ok { + return desc + } + if n >= 30 && n <= 37 { + return fmt.Sprintf("fg ansi color %d", n-30) + } + if n >= 40 && n <= 47 { + return fmt.Sprintf("bg ansi color %d", n-40) + } + if n >= 90 && n <= 97 { + return fmt.Sprintf("fg bright color %d", n-90) + } + if n >= 100 && n <= 107 { + return fmt.Sprintf("bg bright color %d", n-100) + } + return "" +} + +func formatDebugTermCSILine(seq []byte) string { + // seq is the full sequence starting with ESC [ + if len(seq) < 3 { + return "CSI " + strconv.QuoteToASCII(string(seq)) + } + inner := seq[2:] + finalByte := inner[len(inner)-1] + params := string(inner[:len(inner)-1]) + + // DEC private mode: params starts with "?" and final byte is 'h' (set) or 'l' (reset) + if strings.HasPrefix(params, "?") && (finalByte == 'h' || finalByte == 'l') { + modeStr := params[1:] + var line string + if finalByte == 'h' { + line = "DEC SET " + modeStr + } else { + line = "DEC RST " + modeStr + } + if desc, ok := decModeDescriptions[modeStr]; ok { + line += " // " + desc + } + return line + } + + finalStr := string([]byte{finalByte}) + var line string + if params == "" { + line = "CSI " + finalStr + } else { + line = "CSI " + finalStr + " " + params + } + if finalByte == 'm' { + if desc := describeSGR(params); desc != "" { + line += " // " + desc + } + } else if desc, ok := csiCommandDescriptions[finalByte]; ok { + line += " // " + desc + } + return line +} + +func consumeDebugTermCSI(data []byte, start int) ([]byte, int) { + i := start + 2 + for i < len(data) { + if data[i] >= 0x40 && data[i] <= 0x7e { + return data[start : i+1], i + 1 + } + i++ + } + return data[start:], len(data) +} + +func formatDebugTermOSCLine(seq []byte) string { + // seq is the full sequence starting with ESC ] + if len(seq) < 3 { + return "OSC " + strconv.QuoteToASCII(string(seq)) + } + // strip ESC ] prefix + inner := string(seq[2:]) + // strip trailing BEL or ST (ESC \) + inner = strings.TrimSuffix(inner, "\x07") + inner = strings.TrimSuffix(inner, "\x1b\\") + // split code from data on first ; + if idx := strings.IndexByte(inner, ';'); idx >= 0 { + code := inner[:idx] + data := inner[idx+1:] + return "OSC " + code + " " + strconv.QuoteToASCII(data) + } + return "OSC " + strconv.QuoteToASCII(inner) +} + +func consumeDebugTermOSC(data []byte, start int) ([]byte, int) { + i := start + 2 + for i < len(data) { + if data[i] == 0x07 { + return data[start : i+1], i + 1 + } + if data[i] == 0x1b && i+1 < len(data) && data[i+1] == '\\' { + return data[start : i+2], i + 2 + } + i++ + } + return data[start:], len(data) +} + +func consumeDebugTermST(data []byte, start int) ([]byte, int) { + i := start + 2 + for i < len(data) { + if data[i] == 0x1b && i+1 < len(data) && data[i+1] == '\\' { + return data[start : i+2], i + 2 + } + i++ + } + return data[start:], len(data) +} + +func isDebugTermC0Control(b byte) bool { + return b < 0x20 || b == 0x7f +} + +func consumeDebugTermText(data []byte, i int) (start, end int) { + start = i + for i < len(data) { + b := data[i] + if b == 0x1b || b == 0x07 { + break + } + if b == '\n' || b == '\r' || b == '\t' { + i++ + continue + } + if isDebugTermC0Control(b) { + break + } + if b < 0x80 { + i++ + continue + } + _, sz := utf8.DecodeRune(data[i:]) + if sz == 1 { + break + } + i += sz + } + return start, i +} diff --git a/cmd/wsh/cmd/wshcmd-debugterm_test.go b/cmd/wsh/cmd/wshcmd-debugterm_test.go new file mode 100644 index 000000000..eba2caeb7 --- /dev/null +++ b/cmd/wsh/cmd/wshcmd-debugterm_test.go @@ -0,0 +1,100 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package cmd + +import ( + "strings" + "testing" +) + +func TestFormatDebugTermHex(t *testing.T) { + output := formatDebugTermHex([]byte("abc")) + if !strings.Contains(output, "61 62 63") { + t.Fatalf("unexpected hex output: %q", output) + } +} + +func TestFormatDebugTermDecode(t *testing.T) { + data := []byte("abc\x1b[31mred\x1b[0m\x07\x1b]0;title\x07\x00") + output := formatDebugTermDecode(data) + expected := []string{ + `TXT "abc"`, + `CSI m 31`, + `TXT "red"`, + `CSI m 0`, + `BEL`, + `OSC 0 "title"`, + `CTL 0x00`, + } + for _, line := range expected { + if !strings.Contains(output, line) { + t.Fatalf("missing decode line %q in output %q", line, output) + } + } +} + +func TestParseDebugTermStdinData(t *testing.T) { + data, err := parseDebugTermStdinData([]byte(`["abc","\u001b[31mred","\u001b[0m"]`)) + if err != nil { + t.Fatalf("parseDebugTermStdinData() error: %v", err) + } + output := formatDebugTermDecode(data) + expected := []string{ + `TXT "abc"`, + `CSI m 31`, + `TXT "red"`, + `CSI m 0`, + } + for _, line := range expected { + if !strings.Contains(output, line) { + t.Fatalf("missing decode line %q in output %q", line, output) + } + } +} + +func TestParseDebugTermStdinDataStructs(t *testing.T) { + data, err := parseDebugTermStdinData([]byte(`[{"data":"abc"},{"data":"\u001b[31mred"},{"data":"\u001b[0m"}]`)) + if err != nil { + t.Fatalf("parseDebugTermStdinData() error: %v", err) + } + output := formatDebugTermDecode(data) + expected := []string{ + `TXT "abc"`, + `CSI m 31`, + `TXT "red"`, + `CSI m 0`, + } + for _, line := range expected { + if !strings.Contains(output, line) { + t.Fatalf("missing decode line %q in output %q", line, output) + } + } +} + +func TestFormatDebugTermDecodeCursorForward(t *testing.T) { + // CSI C sequences collapse into adjacent text; all consecutive text+CSI-C runs merge into one TXT line. + // The run is split into separate TXT lines at CR/LF run boundaries; // NC appears on the last line. + data := []byte("hi\x1b[1Cworld\x1b[3Cfoo\r\nbar") + output := formatDebugTermDecode(data) + expected := []string{ + `TXT "hi world foo\r\n"`, + `TXT "bar" // 4C`, + } + for _, line := range expected { + if !strings.Contains(output, line) { + t.Fatalf("missing decode line %q in output:\n%s", line, output) + } + } +} + +func TestParseDebugTermStdinDataRaw(t *testing.T) { + raw := []byte("hello\x1b[31mworld") + data, err := parseDebugTermStdinData(raw) + if err != nil { + t.Fatalf("parseDebugTermStdinData() error: %v", err) + } + if string(data) != string(raw) { + t.Fatalf("expected raw passthrough, got %q", data) + } +} diff --git a/cmd/wsh/cmd/wshcmd-root.go b/cmd/wsh/cmd/wshcmd-root.go index 48a568d69..534ce0c31 100644 --- a/cmd/wsh/cmd/wshcmd-root.go +++ b/cmd/wsh/cmd/wshcmd-root.go @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 package cmd diff --git a/cmd/wsh/cmd/wshcmd-ssh.go b/cmd/wsh/cmd/wshcmd-ssh.go index 25dad3c09..4eb1d42a4 100644 --- a/cmd/wsh/cmd/wshcmd-ssh.go +++ b/cmd/wsh/cmd/wshcmd-ssh.go @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 package cmd @@ -7,6 +7,7 @@ import ( "fmt" "github.com/spf13/cobra" + "github.com/wavetermdev/waveterm/pkg/remote" "github.com/wavetermdev/waveterm/pkg/waveobj" "github.com/wavetermdev/waveterm/pkg/wconfig" "github.com/wavetermdev/waveterm/pkg/wshrpc" @@ -15,6 +16,8 @@ import ( var ( identityFiles []string + sshLogin string + sshPort string newBlock bool ) @@ -28,6 +31,8 @@ var sshCmd = &cobra.Command{ func init() { sshCmd.Flags().StringArrayVarP(&identityFiles, "identityfile", "i", []string{}, "add an identity file for publickey authentication") + sshCmd.Flags().StringVarP(&sshLogin, "login", "l", "", "set the remote login name") + sshCmd.Flags().StringVarP(&sshPort, "port", "p", "", "set the remote port") sshCmd.Flags().BoolVarP(&newBlock, "new", "n", false, "create a new terminal block with this connection") rootCmd.AddCommand(sshCmd) } @@ -38,6 +43,11 @@ func sshRun(cmd *cobra.Command, args []string) (rtnErr error) { }() sshArg := args[0] + var err error + sshArg, err = applySSHOverrides(sshArg, sshLogin, sshPort) + if err != nil { + return err + } blockId := RpcContext.BlockId if blockId == "" && !newBlock { return fmt.Errorf("cannot determine blockid (not in JWT)") @@ -91,10 +101,27 @@ func sshRun(cmd *cobra.Command, args []string) (rtnErr error) { waveobj.MetaKey_CmdCwd: nil, }, } - err := wshclient.SetMetaCommand(RpcClient, data, nil) + err = wshclient.SetMetaCommand(RpcClient, data, nil) if err != nil { return fmt.Errorf("setting connection in block: %w", err) } WriteStderr("switched connection to %q\n", sshArg) return nil } + +func applySSHOverrides(sshArg string, login string, port string) (string, error) { + if login == "" && port == "" { + return sshArg, nil + } + opts, err := remote.ParseOpts(sshArg) + if err != nil { + return "", err + } + if login != "" { + opts.SSHUser = login + } + if port != "" { + opts.SSHPort = port + } + return opts.String(), nil +} diff --git a/cmd/wsh/cmd/wshcmd-ssh_test.go b/cmd/wsh/cmd/wshcmd-ssh_test.go new file mode 100644 index 000000000..36da03746 --- /dev/null +++ b/cmd/wsh/cmd/wshcmd-ssh_test.go @@ -0,0 +1,75 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package cmd + +import "testing" + +func TestApplySSHOverrides(t *testing.T) { + tests := []struct { + name string + sshArg string + login string + port string + want string + wantErr bool + }{ + { + name: "no overrides preserves target", + sshArg: "root@bar.com:2022", + want: "root@bar.com:2022", + }, + { + name: "login override replaces parsed user", + sshArg: "root@bar.com", + login: "foo", + want: "foo@bar.com", + }, + { + name: "port override replaces parsed port", + sshArg: "root@bar.com:2022", + port: "2222", + want: "root@bar.com:2222", + }, + { + name: "both overrides replace parsed user and port", + sshArg: "root@bar.com:2022", + login: "foo", + port: "2200", + want: "foo@bar.com:2200", + }, + { + name: "login override adds user to bare host", + sshArg: "bar.com", + login: "foo", + want: "foo@bar.com", + }, + { + name: "port override adds port to bare host", + sshArg: "bar.com", + port: "2200", + want: "bar.com:2200", + }, + { + name: "invalid target returns parse error when override requested", + sshArg: "bad host", + login: "foo", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := applySSHOverrides(tt.sshArg, tt.login, tt.port) + if (err != nil) != tt.wantErr { + t.Fatalf("applySSHOverrides() error = %v, wantErr %v", err, tt.wantErr) + } + if tt.wantErr { + return + } + if got != tt.want { + t.Fatalf("applySSHOverrides() = %q, want %q", got, tt.want) + } + }) + } +} diff --git a/cmd/wsh/cmd/wshcmd-tabindicator.go b/cmd/wsh/cmd/wshcmd-tabindicator.go index f103ee943..c3fa499cf 100644 --- a/cmd/wsh/cmd/wshcmd-tabindicator.go +++ b/cmd/wsh/cmd/wshcmd-tabindicator.go @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 package cmd @@ -7,7 +7,9 @@ import ( "fmt" "os" + "github.com/google/uuid" "github.com/spf13/cobra" + "github.com/wavetermdev/waveterm/pkg/baseds" "github.com/wavetermdev/waveterm/pkg/waveobj" "github.com/wavetermdev/waveterm/pkg/wps" "github.com/wavetermdev/waveterm/pkg/wshrpc" @@ -16,28 +18,26 @@ import ( var tabIndicatorCmd = &cobra.Command{ Use: "tabindicator [icon]", - Short: "set or clear a tab indicator", + Short: "set or clear a tab indicator (deprecated: use 'wsh badge')", Args: cobra.MaximumNArgs(1), RunE: tabIndicatorRun, PreRunE: preRunSetupRpcClient, } var ( - tabIndicatorTabId string - tabIndicatorColor string - tabIndicatorPriority float64 - tabIndicatorClear bool - tabIndicatorPersistent bool - tabIndicatorBeep bool + tabIndicatorTabId string + tabIndicatorColor string + tabIndicatorPriority float64 + tabIndicatorClear bool + tabIndicatorBeep bool ) func init() { rootCmd.AddCommand(tabIndicatorCmd) tabIndicatorCmd.Flags().StringVar(&tabIndicatorTabId, "tabid", "", "tab id (defaults to WAVETERM_TABID)") tabIndicatorCmd.Flags().StringVar(&tabIndicatorColor, "color", "", "indicator color") - tabIndicatorCmd.Flags().Float64Var(&tabIndicatorPriority, "priority", 0, "indicator priority") + tabIndicatorCmd.Flags().Float64Var(&tabIndicatorPriority, "priority", 10, "indicator priority") tabIndicatorCmd.Flags().BoolVar(&tabIndicatorClear, "clear", false, "clear the indicator") - tabIndicatorCmd.Flags().BoolVar(&tabIndicatorPersistent, "persistent", false, "make indicator persistent (don't clear on focus)") tabIndicatorCmd.Flags().BoolVar(&tabIndicatorBeep, "beep", false, "play system bell sound") } @@ -46,6 +46,8 @@ func tabIndicatorRun(cmd *cobra.Command, args []string) (rtnErr error) { sendActivity("tabindicator", rtnErr == nil) }() + fmt.Fprintf(os.Stderr, "tabindicator is deprecated, use 'wsh badge' instead\n") + tabId := tabIndicatorTabId if tabId == "" { tabId = os.Getenv("WAVETERM_TABID") @@ -54,34 +56,39 @@ func tabIndicatorRun(cmd *cobra.Command, args []string) (rtnErr error) { return fmt.Errorf("no tab id specified (use --tabid or set WAVETERM_TABID)") } - var indicator *wshrpc.TabIndicator - if !tabIndicatorClear { + oref := waveobj.MakeORef(waveobj.OType_Tab, tabId) + + var eventData baseds.BadgeEvent + eventData.ORef = oref.String() + + if tabIndicatorClear { + eventData.Clear = true + } else { icon := "bell" if len(args) > 0 { icon = args[0] } - indicator = &wshrpc.TabIndicator{ - Icon: icon, - Color: tabIndicatorColor, - Priority: tabIndicatorPriority, - ClearOnFocus: !tabIndicatorPersistent, + badgeId, err := uuid.NewV7() + if err != nil { + return fmt.Errorf("generating badge id: %v", err) + } + eventData.Badge = &baseds.Badge{ + BadgeId: badgeId.String(), + Icon: icon, + Color: tabIndicatorColor, + Priority: tabIndicatorPriority, } - } - - eventData := wshrpc.TabIndicatorEventData{ - TabId: tabId, - Indicator: indicator, } event := wps.WaveEvent{ - Event: wps.Event_TabIndicator, - Scopes: []string{waveobj.MakeORef(waveobj.OType_Tab, tabId).String()}, + Event: wps.Event_Badge, + Scopes: []string{oref.String()}, Data: eventData, } err := wshclient.EventPublishCommand(RpcClient, event, &wshrpc.RpcOpts{NoResponse: true}) if err != nil { - return fmt.Errorf("publishing tab indicator event: %v", err) + return fmt.Errorf("publishing badge event: %v", err) } if tabIndicatorBeep { diff --git a/cmd/wsh/cmd/wshcmd-test.go b/cmd/wsh/cmd/wshcmd-test.go index 20ec59e86..24706a1fe 100644 --- a/cmd/wsh/cmd/wshcmd-test.go +++ b/cmd/wsh/cmd/wshcmd-test.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/spf13/cobra" + "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" ) var testCmd = &cobra.Command{ @@ -20,5 +21,10 @@ func init() { } func runTestCmd(cmd *cobra.Command, args []string) error { + rtn, err := wshclient.TestMultiArgCommand(RpcClient, "testarg", 42, true, nil) + if err != nil { + return err + } + WriteStdout("%s\n", rtn) return nil } diff --git a/docs/docs/claude-code.mdx b/docs/docs/claude-code.mdx new file mode 100644 index 000000000..d16b0f0b0 --- /dev/null +++ b/docs/docs/claude-code.mdx @@ -0,0 +1,131 @@ +--- +sidebar_position: 1.9 +id: "claude-code" +title: "Claude Code Integration" +--- + +import { VersionBadge } from "@site/src/components/versionbadge"; + +# Claude Code Tab Badges + +When you run multiple Claude Code sessions in parallel — one per feature, one per repo, a few long-running tasks — it gets hard to know which tabs need your attention without clicking through each one. Wave's badge system solves this: hooks in Claude Code write a small visual indicator to the tab header whenever something important happens, so you can see at a glance which sessions are waiting, done, or in trouble. + +:::info +tl;dr You can copy and paste this page directly into Claude Code and it will help you set everything up! +::: + +## How it works + +Claude Code supports [lifecycle hooks](https://code.claude.com/docs/en/hooks) — shell commands that run automatically at specific points in a session. Wave's `wsh badge` command sets or clears a visual indicator on the current block or tab. By wiring these together, you get ambient awareness across all your sessions without watching any of them. + +Badges auto-clear when you focus the block, so they're purely a "hey, look over here" signal. Once you click in and read what's happening, the badge disappears on its own. + +Wave already shows a bell icon when a terminal outputs a BEL character. These hooks complement that with semantic badges — *permission needed*, *done* — that survive across tab switches and work across splits. + +### Badge rollup + +If a tab has multiple terminals (block), Wave shows the highest-priority badge on the tab header. Ties at the same priority go to the earliest badge set, so the most urgent signal from any pane in the tab floats to the top. + +## Setup + +These hooks go in your global Claude Code settings so they apply to every session on your machine, not just one project. + +Add the following to `~/.claude/settings.json`. If you already have a `hooks` key, merge the entries in: + +```json +{ + "hooks": { + "Notification": [ + { + "matcher": "permission_prompt", + "hooks": [ + { + "type": "command", + "command": "wsh badge bell-exclamation --color '#e0b956' --priority 20 --beep" + } + ] + }, + { + "matcher": "elicitation_dialog", + "hooks": [ + { + "type": "command", + "command": "wsh badge message-question --color '#e0b956' --priority 20 --beep" + } + ] + } + ], + "Stop": [ + { + "hooks": [ + { + "type": "command", + "command": "wsh badge check --color '#58c142' --priority 10" + } + ] + } + ], + "PreToolUse": [ + { + "matcher": "AskUserQuestion", + "hooks": [ + { + "type": "command", + "command": "wsh badge message-question --color '#e0b956' --priority 20 --beep" + } + ] + } + ] + } +} +``` + +That's it. Restart any running Claude Code sessions for the hooks to take effect. + +:::warning Known Issue +There is a known issue in Claude Code where `Notification` hooks may be delayed by several seconds before firing. This delay is unrelated to Wave — it occurs in Claude Code itself. See [#5186](https://github.com/anthropics/claude-code/issues/5186) and [#19627](https://github.com/anthropics/claude-code/issues/19627) for details. +::: + +## What each hook does + +### Permission prompt — `bell-exclamation` gold, priority 20 + +Claude Code occasionally needs your approval before it can continue — to run a command, write a file outside the project, or use a tool that requires explicit permission. When it hits one of these, it stops and waits. Without a signal, you might not notice for minutes. + +This hook fires on the `permission_prompt` notification type and sets a high-priority gold badge with an audible beep. Priority 20 means it beats any other badge on that tab, so a waiting session always surfaces above a finished one. + +When you click into the tab and approve or deny the request, the badge clears automatically. + +### Session complete — `check` green, priority 10 + +When Claude Code finishes responding, this hook sets a green check badge. It's a low-key signal: glance at the tab bar, see which sessions are done, review their output in whatever order you like. + +### AskUserQuestion — `message-question` gold, priority 20 + +When Claude Code uses the `AskUserQuestion` tool, it's paused and waiting for you to respond before it can proceed. This `PreToolUse` hook fires just before that tool call and sets the same high-priority gold badge as the permission prompt. + +`PreToolUse` hooks can match any tool by name, so you can add badges for other tools as well — for example, to get a signal whenever Claude runs a shell command (`Bash`) or edits a file (`Edit`). Any tool name Claude Code supports can be used as a matcher. + +## Choosing your own icons and colors + +Icon names are [Font Awesome](https://fontawesome.com/icons) icon names without the `fa-` prefix. Colors are any valid CSS color — hex values, named colors, or anything else CSS accepts. + +Some icon and color ideas: + +| Situation | Icon | Color | +|-----------|------|-------| +| Custom high-priority alert | `triangle-exclamation` | `#FF453A` | +| Blocked / waiting on input | `hourglass-half` | `#FF9500` | +| Neutral / informational | `circle-info` | `#429DFF` | +| Background task running | `spinner` | `#00FFDB` | + +See the [`wsh badge` reference](/wsh-reference#badge) for all available flags. + +## Adjusting priorities + +Priority controls which badge wins when multiple blocks in a tab each have one. Higher numbers take precedence. The defaults above use: + +- **20** for permission prompts — always surfaces above everything else +- **10** for session complete — visible when nothing more urgent is active + +If you add more hooks, keep permission-blocking signals at the high end (15–25) and informational signals at the low end (5–10). \ No newline at end of file diff --git a/docs/docs/config.mdx b/docs/docs/config.mdx index 6cdd59cdf..ae83638ea 100644 --- a/docs/docs/config.mdx +++ b/docs/docs/config.mdx @@ -44,6 +44,7 @@ wsh editconfig | app:disablectrlshiftarrows | bool | Set to true to disable Ctrl+Shift block-navigation keybindings (`Arrow` and `h/j/k/l`) (defaults to false) | | app:disablectrlshiftdisplay | bool | Set to true to disable the Ctrl+Shift visual indicator display (defaults to false) | | app:focusfollowscursor | string | Controls whether block focus follows cursor movement: `"off"` (default), `"on"` (all blocks), or `"term"` (terminal blocks only) | +| app:tabbar | string | Controls the position of the tab bar: `"top"` (default) for a horizontal tab bar at the top of the window, or `"left"` for a vertical tab bar on the left side of the window | | ai:preset | string | the default AI preset to use | | ai:baseurl | string | Set the AI Base Url (must be OpenAI compatible) | | ai:apitoken | string | your AI api token | @@ -73,6 +74,7 @@ wsh editconfig | term:cursorblink | bool | when enabled, terminal cursor blinks (default false) | | term:bellsound | bool | when enabled, plays the system beep sound when the terminal bell (BEL character) is received (default false) | | term:bellindicator | bool | when enabled, shows a visual indicator in the tab when the terminal bell is received (default false) | +| term:osc52 | string | controls OSC 52 clipboard behavior: `always` (default, allows OSC 52 at any time) or `focus` (requires focused window and focused block) | | term:durable | bool | makes remote terminal sessions durable across network disconnects (defaults to false) | | editor:minimapenabled | bool | set to false to disable editor minimap | | editor:stickyscrollenabled | bool | enables monaco editor's stickyScroll feature (pinning headers of current context, e.g. class names, method names, etc.), defaults to false | @@ -80,6 +82,7 @@ wsh editconfig | editor:fontsize | float64 | set the font size for the editor (defaults to 12px) | | editor:inlinediff | bool | set to true to show diffs inline instead of side-by-side, false for side-by-side (defaults to undefined which uses Monaco's responsive behavior) | | preview:showhiddenfiles | bool | set to false to disable showing hidden files in the directory preview (defaults to true) | +| preview:defaultsort | string | sets the default sort column for directory preview. `"name"` (default) sorts alphabetically by name ascending; `"modtime"` sorts by last modified time descending (newest first) | | markdown:fontsize | float64 | font size for the normal text when rendering markdown in preview. headers are scaled up from this size, (default 14px) | | markdown:fixedfontsize | float64 | font size for the code blocks when rendering markdown in preview (default is 12px) | | web:openlinksinternally | bool | set to false to open web links in external browser | @@ -147,12 +150,14 @@ For reference, this is the current default configuration (v0.14.0): "telemetry:enabled": true, "term:bellsound": false, "term:bellindicator": false, + "term:osc52": "always", "term:cursor": "block", "term:cursorblink": false, "term:copyonselect": true, "term:durable": false, "waveai:showcloudmodes": true, - "waveai:defaultmode": "waveai@balanced" + "waveai:defaultmode": "waveai@balanced", + "preview:defaultsort": "name" } ``` diff --git a/docs/docs/releasenotes.mdx b/docs/docs/releasenotes.mdx index d2671ec3b..4d985607d 100644 --- a/docs/docs/releasenotes.mdx +++ b/docs/docs/releasenotes.mdx @@ -6,6 +6,57 @@ sidebar_position: 200 # Release Notes +### v0.14.2 — Mar 12, 2026 + +Wave v0.14.2 adds block/tab badges, directory preview improvements, and assorted bug fixes. + +**Block/Tab Badges:** + +- **Block Level Badges, Rolled up to Tabs** - Blocks can now display icon badges (with color and priority) that roll up and are visible in the tab bar for at-a-glance status +- **Bell Indicator Enabled by Default** - Terminal bell badge is now on by default, lighting up the block and tab when your terminal rings the bell (controlled with `term:bellindicator`) +- **`wsh badge`** - New `wsh badge` command to set or clear badges on blocks from the command line. Supports icons, colors, priorities, beep, and PID-linked badges that auto-clear when a process exits. Great for use with Claude Code hooks to surface notifications in the tab bar ([docs](https://docs.waveterm.dev/wsh-reference#badge)) + +**Other Changes:** + +- **Directory Preview Improvements** - Improved mod time formatting, zebra-striped rows, better default sort, YAML file support, and context menu improvements +- **Search Bar** - Clipboard and focus improvements in the search bar +- [bugfix] Fixed "New Window" hanging/not working on GNOME desktops +- [bugfix] Fixed "Save Session As..." (focused window tracking bug) +- [bugfix] Zoom change notifications were not being properly sent to all tabs (layout inconsistencies) +- Added a Release Notes link in the settings menu +- Working on anthropic-messages Wave AI backend (for native Claude integration) +- Lots of internal work on testing/mock infrastructure to enable quicker async AI edits +- Documention updates +- Package updates and dependency upgrades + +### v0.14.1 — Mar 3, 2026 + +Wave v0.14.1 fixes several high-impact terminal bugs (Claude Code scrolling, IME input) and adds new config options: focus-follows-cursor, cursor style customization, workspace-scoped widgets, and vim-style block navigation. + +**Terminal Improvements:** + +- **Claude Code Scroll Fix** - Fixed a long-standing bug that caused terminal windows to jump to the top unexpectedly, affecting many Claude Code users +- **IME Fix** - Fixed Korean/CJK input where characters were lost or stuck in composition and only committed on Space +- **Scroll Position Preserved on Resize** - Terminal now stays scrolled to the bottom across resizes when it was already at the bottom +- **Better Link Handling** - Terminal URLs now have improved context menus and tooltips for easier navigation +- **Terminal Scrollback Save** - New context menu item and `wsh` command to save terminal scrollback to a file + +**New Features:** + +- **Focus Follows Cursor** - New `app:focusfollowscursor` setting (off/on/term) for hover-based block focus +- **Terminal Cursor Style & Blink** - New settings for cursor style (block/bar/underline) and blink, configurable per-block +- **Tab Close Confirmation** - New `tab:confirmclose` setting to prompt before closing a tab +- **Workspace-Scoped Widgets** - New optional `workspaces` field in `widgets.json` to show/hide widgets per-workspace +- **Vim-Style Block Navigation** - Added Ctrl+Shift+H/J/K/L to navigate between blocks +- **New AI Providers** - Added Groq and NanoGPT as built-in AI provider presets + +**Other Changes:** + +- Fixed intermittant bugs with connection switching in terminal blocks +- Widgets.json schema improvements for better editor validation +- Package updates and dependency upgrades +- Internal code cleanup and refactoring + ### v0.14.0 — Feb 10, 2026 **Durable SSH Sessions and Enhanced Connection Monitoring** diff --git a/docs/docs/wsh-reference.mdx b/docs/docs/wsh-reference.mdx index 9dd8bc0b3..6ff8c2e8f 100644 --- a/docs/docs/wsh-reference.mdx +++ b/docs/docs/wsh-reference.mdx @@ -6,6 +6,7 @@ title: "wsh reference" import { Kbd } from "@site/src/components/kbd"; import { PlatformProvider, PlatformSelectorButton } from "@site/src/components/platformcontext"; +import { VersionBadge } from "@site/src/components/versionbadge"; @@ -23,6 +24,7 @@ You can open a preview block with the contents of any file or directory by runni ```sh wsh view [path] +wsh view -m [path] # opens in magnified block ``` You can use this command to easily preview images, markdown files, and directories. For code/text files this will open @@ -34,9 +36,29 @@ a codeedit block which you can use to quickly edit the file using Wave's embedde ```sh wsh edit [path] +wsh edit -m [path] # opens in magnified block ``` -This will open up codeedit for the specified file. This is useful for quickly editing files on a local or remote machine in our graphical editor. This command will wait until the file is closed before exiting (unlike `view`) so you can set your `$EDITOR` to `wsh editor` for a seamless experience. You can combine this with a `-m` flag to open the editor in magnified mode. +This will open up a codeedit block for the specified file. This is useful for quickly editing files on a local or remote machine in Wave's graphical editor. This command returns immediately after opening the block. + +For `$EDITOR` integration (e.g. with `git commit`), see [`wsh editor`](#editor) which blocks until the editor is closed. + +--- + +## editor + +```sh +wsh editor [path] +wsh editor -m [path] # opens in magnified block +``` + +This opens a codeedit block for the specified file and **blocks until the editor is closed**. This is useful for setting your `$EDITOR` environment variable so that CLI tools (e.g. `git commit`, `crontab -e`) open files in Wave's graphical editor: + +```sh +export EDITOR="wsh editor" +``` + +The file must already exist. Use `-m` to open the editor in magnified mode. --- @@ -241,6 +263,59 @@ Use `--print` to preview the metadata for any background configuration without a --- +## badge + + + +The `badge` command sets or clears a visual badge indicator on a block or tab header. + +```sh +wsh badge [icon] +wsh badge --clear +``` + +Badges are used to draw attention to a block or tab, such as indicating a process has completed or needs attention. If no icon is provided, it defaults to `circle-small`. Icon names are [Font Awesome](https://fontawesome.com/icons) icon names (without the `fa-` prefix). + +Flags: + +- `--color string` - set the badge color (CSS color name or hex) +- `--priority float` - set the badge priority (default 10; higher priority badges take precedence) +- `--clear` - remove the badge from the block or tab +- `--beep` - play the system bell sound when setting the badge +- `--pid int` - watch a PID and automatically clear the badge when it exits (sets default priority to 5) +- `-b, --block` - target a specific block or tab (same format as `getmeta`) + +Examples: + +```sh +# Set a default badge on the current block +wsh badge + +# Set a badge with a custom icon and color +wsh badge circle-check --color green + +# Set a high-priority badge on a specific block +wsh badge triangle-exclamation --color red --priority 20 -b 2 + +# Set a badge that clears when a process exits +wsh badge --pid 12345 + +# Play the bell and set a badge when done +wsh badge circle-check --beep + +# Clear the badge on the current block +wsh badge --clear + +# Clear the badge on a specific tab +wsh badge --clear -b tab +``` + +:::note +The `--pid` flag is not supported on Windows. +::: + +--- + ## run The `run` command creates a new terminal command block and executes a specified command within it. The command can be provided either as arguments after `--` or using the `-c` flag. Unless the `-x` or `-X` flags are passed, commands can be re-executed by pressing `Enter` once the command has finished running. diff --git a/docs/package.json b/docs/package.json index ebbcd9b1f..7288853b4 100644 --- a/docs/package.json +++ b/docs/package.json @@ -44,7 +44,7 @@ "@types/react-dom": "^18.3.0", "eslint": "^9.39", "eslint-config-prettier": "^10.1.8", - "eslint-plugin-mdx": "^3.6.2", + "eslint-plugin-mdx": "^3.7.0", "prettier": "^3.8.1", "prettier-plugin-jsdoc": "^1.8.0", "prettier-plugin-organize-imports": "^4.3.0", diff --git a/electron.vite.config.ts b/electron.vite.config.ts index 626c5e2e6..bf0956df6 100644 --- a/electron.vite.config.ts +++ b/electron.vite.config.ts @@ -159,6 +159,7 @@ export default defineConfig({ "**/go.mod", "**/go.sum", "**/*.md", + "**/*.mdx", "**/*.json", "emain/**", "**/*.txt", diff --git a/emain/emain-ipc.ts b/emain/emain-ipc.ts index aaf373643..09830b931 100644 --- a/emain/emain-ipc.ts +++ b/emain/emain-ipc.ts @@ -17,13 +17,14 @@ import { incrementTermCommandsRemote, incrementTermCommandsRun, incrementTermCommandsWsl, + setWasActive, } from "./emain-activity"; import { createBuilderWindow, getAllBuilderWindows, getBuilderWindowByWebContentsId } from "./emain-builder"; import { callWithOriginalXdgCurrentDesktopAsync, unamePlatform } from "./emain-platform"; import { getWaveTabViewByWebContentsId } from "./emain-tabview"; import { handleCtrlShiftState } from "./emain-util"; import { getWaveVersion } from "./emain-wavesrv"; -import { createNewWaveWindow, focusedWaveWindow, getWaveWindowByWebContentsId } from "./emain-window"; +import { createNewWaveWindow, getWaveWindowByWebContentsId } from "./emain-window"; import { ElectronWshClient } from "./emain-wsh"; const electronApp = electron.app; @@ -129,12 +130,18 @@ function getUrlInSession(session: Electron.Session, url: string): Promise { if (file.canceled) { + readStream.destroy(); return; } const writeStream = fs.createWriteStream(file.filePath); @@ -201,7 +209,7 @@ export function initIpcHandlers() { electron.ipcMain.on("webview-image-contextmenu", (event: electron.IpcMainEvent, payload: { src: string }) => { const menu = new electron.Menu(); - const win = getWaveWindowByWebContentsId(event.sender.hostWebContents.id); + const win = getWaveWindowByWebContentsId(event.sender.hostWebContents?.id); if (win == null) { return; } @@ -212,7 +220,12 @@ export function initIpcHandlers() { const resultP = getUrlInSession(event.sender.session, payload.src); resultP .then((result) => { - saveImageFileWithNativeDialog(result.fileName, result.mimeType, result.stream); + saveImageFileWithNativeDialog( + event.sender.hostWebContents, + result.fileName, + result.mimeType, + result.stream + ); }) .catch((e) => { console.log("error getting image", e); @@ -317,6 +330,10 @@ export function initIpcHandlers() { tabView?.setKeyboardChordMode(true); }); + electron.ipcMain.handle("set-is-active", () => { + setWasActive(true); + }); + const fac = new FastAverageColor(); electron.ipcMain.on("update-window-controls-overlay", async (event, rect: Dimensions) => { if (unamePlatform === "darwin") return; @@ -336,6 +353,7 @@ export function initIpcHandlers() { const png = PNG.sync.read(overlayBuffer); const color = fac.prepareResult(fac.getColorFromArray4(png.data)); const ww = getWaveWindowByWebContentsId(event.sender.id); + if (ww == null) return; ww.setTitleBarOverlay({ color: unamePlatform === "linux" ? color.rgba : "#00000000", symbolColor: color.isDark ? "white" : "black", @@ -472,7 +490,7 @@ export function initIpcHandlers() { }); electron.ipcMain.handle("save-text-file", async (event, fileName: string, content: string) => { - const ww = focusedWaveWindow; + const ww = electron.BrowserWindow.fromWebContents(event.sender); if (ww == null) { return false; } diff --git a/emain/emain-menu.ts b/emain/emain-menu.ts index 6685d7908..691e47544 100644 --- a/emain/emain-menu.ts +++ b/emain/emain-menu.ts @@ -9,7 +9,7 @@ import { focusedBuilderWindow, getBuilderWindowById } from "./emain-builder"; import { openBuilderWindow } from "./emain-ipc"; import { isDev, unamePlatform } from "./emain-platform"; import { clearTabCache } from "./emain-tabview"; -import { decreaseZoomLevel, increaseZoomLevel } from "./emain-util"; +import { decreaseZoomLevel, increaseZoomLevel, resetZoomLevel } from "./emain-util"; import { createNewWaveWindow, createWorkspace, @@ -227,7 +227,7 @@ function makeViewMenu( label: "Toggle DevTools", accelerator: devToolsAccel, click: (_, window) => { - let wc = getWindowWebContents(window) ?? webContents; + const wc = getWindowWebContents(window) ?? webContents; wc?.toggleDevTools(); }, }, @@ -238,8 +238,7 @@ function makeViewMenu( click: (_, window) => { const wc = getWindowWebContents(window) ?? webContents; if (wc) { - wc.setZoomFactor(1); - wc.send("zoom-factor-change", 1); + resetZoomLevel(wc); } }, }, diff --git a/emain/emain-tabview.ts b/emain/emain-tabview.ts index feb0f029c..753a53ade 100644 --- a/emain/emain-tabview.ts +++ b/emain/emain-tabview.ts @@ -15,6 +15,7 @@ import { handleCtrlShiftFocus, handleCtrlShiftState, increaseZoomLevel, + resetZoomLevel, shFrameNavHandler, shNavHandler, } from "./emain-util"; @@ -48,8 +49,7 @@ function handleWindowsMenuAccelerators( } if (checkKeyPressed(waveEvent, "Ctrl:0")) { - tabView.webContents.setZoomFactor(1); - tabView.webContents.send("zoom-factor-change", 1); + resetZoomLevel(tabView.webContents); return true; } @@ -109,6 +109,9 @@ function computeBgColor(fullConfig: FullConfigType): string { const wcIdToWaveTabMap = new Map(); export function getWaveTabViewByWebContentsId(webContentsId: number): WaveTabView { + if (webContentsId == null) { + return null; + } return wcIdToWaveTabMap.get(webContentsId); } @@ -154,20 +157,18 @@ export class WaveTabView extends WebContentsView { this.waveReadyPromise.then(() => { this.isWaveReady = true; }); - wcIdToWaveTabMap.set(this.webContents.id, this); + const wcId = this.webContents.id; + wcIdToWaveTabMap.set(wcId, this); if (isDevVite) { this.webContents.loadURL(`${process.env.ELECTRON_RENDERER_URL}/index.html`); } else { this.webContents.loadFile(path.join(getElectronAppBasePath(), "frontend", "index.html")); } this.webContents.on("destroyed", () => { - wcIdToWaveTabMap.delete(this.webContents.id); + wcIdToWaveTabMap.delete(wcId); removeWaveTabView(this.waveTabId); this.isDestroyed = true; }); - this.webContents.on("zoom-changed", (_event, zoomDirection) => { - this.webContents.send("zoom-factor-change", this.webContents.getZoomFactor()); - }); this.setBackgroundColor(computeBgColor(fullConfig)); } @@ -286,7 +287,6 @@ function checkAndEvictCache(): void { // Otherwise, sort by lastUsedTs return a.lastUsedTs - b.lastUsedTs; }); - const now = Date.now(); for (let i = 0; i < sorted.length - MaxCacheSize; i++) { tryEvictEntry(sorted[i].waveTabId); } @@ -316,6 +316,9 @@ export async function getOrCreateWebViewForTab(waveWindowId: string, tabId: stri tabView.webContents.on("will-frame-navigate", shFrameNavHandler); tabView.webContents.on("did-attach-webview", (event, wc) => { wc.setWindowOpenHandler((details) => { + if (wc == null || wc.isDestroyed() || tabView.webContents == null || tabView.webContents.isDestroyed()) { + return { action: "deny" }; + } tabView.webContents.send("webview-new-window", wc.id, details); return { action: "deny" }; }); @@ -339,9 +342,6 @@ export async function getOrCreateWebViewForTab(waveWindowId: string, tabId: stri } } }); - tabView.webContents.on("zoom-changed", (e) => { - tabView.webContents.send("zoom-changed"); - }); tabView.webContents.setWindowOpenHandler(({ url, frameName }) => { if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("file://")) { console.log("openExternal fallback", url); diff --git a/emain/emain-util.ts b/emain/emain-util.ts index b04fda0df..08f9c3413 100644 --- a/emain/emain-util.ts +++ b/emain/emain-util.ts @@ -12,16 +12,36 @@ const MinZoomLevel = 0.4; const MaxZoomLevel = 2.6; const ZoomDelta = 0.2; +// Note: Chromium automatically syncs zoom factor across all WebContents +// sharing the same origin/session, so we only need to notify renderers +// to update their CSS/state — not call setZoomFactor on each one. +// We broadcast to all WebContents (including devtools, webviews, etc.) but +// that is safe because "zoom-factor-change" is a custom app-defined event +// that only our renderers listen to; unrecognized IPC messages are ignored. +function broadcastZoomFactorChanged(newZoomFactor: number): void { + for (const wc of electron.webContents.getAllWebContents()) { + if (wc.isDestroyed()) { + continue; + } + wc.send("zoom-factor-change", newZoomFactor); + } +} + export function increaseZoomLevel(webContents: electron.WebContents): void { const newZoom = Math.min(MaxZoomLevel, webContents.getZoomFactor() + ZoomDelta); webContents.setZoomFactor(newZoom); - webContents.send("zoom-factor-change", newZoom); + broadcastZoomFactorChanged(newZoom); } export function decreaseZoomLevel(webContents: electron.WebContents): void { const newZoom = Math.max(MinZoomLevel, webContents.getZoomFactor() - ZoomDelta); webContents.setZoomFactor(newZoom); - webContents.send("zoom-factor-change", newZoom); + broadcastZoomFactorChanged(newZoom); +} + +export function resetZoomLevel(webContents: electron.WebContents): void { + webContents.setZoomFactor(1); + broadcastZoomFactorChanged(1); } export function getElectronExecPath(): string { diff --git a/emain/emain-window.ts b/emain/emain-window.ts index 576488579..9af50988f 100644 --- a/emain/emain-window.ts +++ b/emain/emain-window.ts @@ -16,12 +16,14 @@ import { setWasInFg, } from "./emain-activity"; import { log } from "./emain-log"; -import { getElectronAppBasePath, unamePlatform } from "./emain-platform"; +import { getElectronAppBasePath, isDev, unamePlatform } from "./emain-platform"; import { getOrCreateWebViewForTab, getWaveTabViewByWebContentsId, WaveTabView } from "./emain-tabview"; import { delay, ensureBoundsAreVisible, waveKeyToElectronKey } from "./emain-util"; import { ElectronWshClient } from "./emain-wsh"; import { updater } from "./updater"; +const DevInitTimeoutMs = 5000; + export type WindowOpts = { unamePlatform: NodeJS.Platform; isPrimaryStartupWindow?: boolean; @@ -138,6 +140,7 @@ export class WaveBrowserWindow extends BaseWindow { waveWindowId: string; workspaceId: string; allLoadedTabViews: Map; + allTabViewsCache: Map; // Cache for preserving tab views across workspace switches activeTabView: WaveTabView; private canClose: boolean; private deleteAllowed: boolean; @@ -217,6 +220,7 @@ export class WaveBrowserWindow extends BaseWindow { this.waveWindowId = waveWindow.oid; this.workspaceId = waveWindow.workspaceid; this.allLoadedTabViews = new Map(); + this.allTabViewsCache = new Map(); const winBoundsPoller = setInterval(() => { if (this.isDestroyed()) { clearInterval(winBoundsPoller); @@ -271,6 +275,7 @@ export class WaveBrowserWindow extends BaseWindow { if (getGlobalIsRelaunching()) { return; } + focusedWaveWindow = this; // eslint-disable-line @typescript-eslint/no-this-alias console.log("focus win", this.waveWindowId); fireAndForget(() => ClientService.FocusWindow(this.waveWindowId)); setWasInFg(true); @@ -350,6 +355,11 @@ export class WaveBrowserWindow extends BaseWindow { } tabView?.destroy(); } + // Also destroy any cached views + for (const tabView of this.allTabViewsCache.values()) { + tabView?.destroy(); + } + this.allTabViewsCache.clear(); } async switchWorkspace(workspaceId: string) { @@ -389,7 +399,7 @@ export class WaveBrowserWindow extends BaseWindow { private async initializeTab(tabView: WaveTabView, primaryStartupTab: boolean) { const clientId = await getClientId(); - await tabView.initPromise; + await this.awaitWithDevTimeout(tabView.initPromise, "initPromise", tabView.waveTabId); this.contentView.addChildView(tabView); const initOpts: WaveInitOpts = { tabId: tabView.waveTabId, @@ -410,10 +420,36 @@ export class WaveBrowserWindow extends BaseWindow { primaryStartupTab ? "(primary startup)" : "" ); tabView.webContents.send("wave-init", initOpts); - await tabView.waveReadyPromise; + await this.awaitWithDevTimeout(tabView.waveReadyPromise, "waveReadyPromise", tabView.waveTabId); console.log("wave-ready init time", Date.now() - startTime + "ms"); } + private async awaitWithDevTimeout(promise: Promise, name: string, tabId: string): Promise { + if (!isDev) { + return promise; + } + let timeoutHandle: ReturnType = null; + const timeoutPromise = new Promise((_, reject) => { + timeoutHandle = setTimeout(() => { + console.log( + `[dev] ${name} timed out after ${DevInitTimeoutMs}ms for tab ${tabId}, showing window for devtools` + ); + if (!this.isDestroyed() && !this.isVisible()) { + this.show(); + } + if (this.activeTabView?.webContents && !this.activeTabView.webContents.isDevToolsOpened()) { + this.activeTabView.webContents.openDevTools(); + } + reject(new Error(`[dev] ${name} timed out after ${DevInitTimeoutMs}ms`)); + }, DevInitTimeoutMs); + }); + try { + return await Promise.race([promise, timeoutPromise]); + } finally { + clearTimeout(timeoutHandle); + } + } + private async setTabViewIntoWindow(tabView: WaveTabView, tabInitialized: boolean, primaryStartupTab = false) { if (this.activeTabView == tabView) { return; @@ -575,8 +611,31 @@ export class WaveBrowserWindow extends BaseWindow { return; } console.log("processActionQueue switchworkspace newWs", newWs); - this.removeAllChildViews(); - console.log("destroyed all tabs", this.waveWindowId); + // Move current tab views to cache instead of destroying them + // This preserves terminal state (including alternate screen mode) across workspace switches + for (const [tabId, tabView] of this.allLoadedTabViews.entries()) { + if (!this.isDestroyed()) { + this.contentView.removeChildView(tabView); + } + // If tabId already in cache (edge case with rapid workspace switching), destroy the old cached view first + const existingCachedView = this.allTabViewsCache.get(tabId); + if (existingCachedView) { + existingCachedView.destroy(); + } + this.allTabViewsCache.set(tabId, tabView); + } + console.log( + "cached", + this.allLoadedTabViews.size, + "tabs for workspace", + this.workspaceId, + this.waveWindowId + ); + // Note: Cached views are kept alive indefinitely and only destroyed when: + // 1. The tab is explicitly closed by the user + // 2. The window is closed (via removeAllChildViews) + // This matches how traditional terminal apps work and prevents terminal state loss + this.workspaceId = entry.workspaceId; this.allLoadedTabViews = new Map(); tabId = newWs.activetabid; @@ -586,7 +645,18 @@ export class WaveBrowserWindow extends BaseWindow { if (tabId == null) { return; } - const [tabView, tabInitialized] = await getOrCreateWebViewForTab(this.waveWindowId, tabId); + // Check cache first to reuse existing tab views across workspace switches + let tabView = this.allTabViewsCache.get(tabId); + let tabInitialized = true; + if (tabView) { + console.log("reusing cached tab view", tabId, this.waveWindowId); + this.allTabViewsCache.delete(tabId); + if (!this.isDestroyed()) { + this.contentView.addChildView(tabView); + } + } else { + [tabView, tabInitialized] = await getOrCreateWebViewForTab(this.waveWindowId, tabId); + } const primaryStartupTabFlag = entry.op === "switchtab" ? (entry.primaryStartupTab ?? false) : false; await this.setTabViewIntoWindow(tabView, tabInitialized, primaryStartupTabFlag); } catch (e) { @@ -618,14 +688,20 @@ export class WaveBrowserWindow extends BaseWindow { console.log("cannot remove active tab", tabId, this.waveWindowId); return; } - const tabView = this.allLoadedTabViews.get(tabId); + let tabView = this.allLoadedTabViews.get(tabId); if (tabView == null) { - console.log("removeTabView -- tabView not found", tabId, this.waveWindowId); - // the tab was never loaded, so just return - return; + // Check cache - tab might be from a different workspace + tabView = this.allTabViewsCache.get(tabId); + if (tabView == null) { + console.log("removeTabView -- tabView not found in loaded or cache", tabId, this.waveWindowId); + return; + } + console.log("removeTabView -- removing from cache", tabId, this.waveWindowId); + this.allTabViewsCache.delete(tabId); + } else { + this.contentView.removeChildView(tabView); + this.allLoadedTabViews.delete(tabId); } - this.contentView.removeChildView(tabView); - this.allLoadedTabViews.delete(tabId); tabView.destroy(); } @@ -638,13 +714,16 @@ export class WaveBrowserWindow extends BaseWindow { export function getWaveWindowByTabId(tabId: string): WaveBrowserWindow { for (const ww of waveWindowMap.values()) { - if (ww.allLoadedTabViews.has(tabId)) { + if (ww.allLoadedTabViews.has(tabId) || ww.allTabViewsCache.has(tabId)) { return ww; } } } export function getWaveWindowByWebContentsId(webContentsId: number): WaveBrowserWindow { + if (webContentsId == null) { + return null; + } const tabView = getWaveTabViewByWebContentsId(webContentsId); if (tabView == null) { return null; diff --git a/emain/emain.ts b/emain/emain.ts index 79b0c2d0f..7a2b0a071 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -384,6 +384,10 @@ async function appMain() { electronApp.quit(); return; } + electronApp.on("second-instance", (_event, argv, workingDirectory) => { + console.log("second-instance event, argv:", argv, "workingDirectory:", workingDirectory); + fireAndForget(createNewWaveWindow); + }); try { await runWaveSrv(handleWSEvent); } catch (e) { diff --git a/emain/preload.ts b/emain/preload.ts index 7acdf2e73..823f99c4c 100644 --- a/emain/preload.ts +++ b/emain/preload.ts @@ -71,6 +71,7 @@ contextBridge.exposeInMainWorld("api", { setBuilderWindowAppId: (appId: string) => ipcRenderer.send("set-builder-window-appid", appId), doRefresh: () => ipcRenderer.send("do-refresh"), saveTextFile: (fileName: string, content: string) => ipcRenderer.invoke("save-text-file", fileName, content), + setIsActive: () => ipcRenderer.invoke("set-is-active"), }); // Custom event for "new-window" diff --git a/eslint.config.js b/eslint.config.js index 1c72e5f46..6e98b1d80 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -76,8 +76,9 @@ export default [ "@typescript-eslint/no-unused-vars": [ "warn", { - argsIgnorePattern: "^_$", - varsIgnorePattern: "^_$", + argsIgnorePattern: "^(_[a-zA-Z0-9_]*|e|get)$", + varsIgnorePattern: "^(_[a-zA-Z0-9_]*|dlog|e)$", + caughtErrorsIgnorePattern: "^(_[a-zA-Z0-9_]*|e)$", }, ], "prefer-const": "warn", @@ -88,6 +89,7 @@ export default [ { files: ["frontend/app/store/services.ts"], rules: { + "@typescript-eslint/no-unused-vars": "off", "prefer-rest-params": "off", }, }, diff --git a/frontend/app/aipanel/aipanel.tsx b/frontend/app/aipanel/aipanel.tsx index 46780455c..37c22709f 100644 --- a/frontend/app/aipanel/aipanel.tsx +++ b/frontend/app/aipanel/aipanel.tsx @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { handleWaveAIContextMenu } from "@/app/aipanel/aipanel-contextmenu"; @@ -6,8 +6,8 @@ import { waveAIHasSelection } from "@/app/aipanel/waveai-focus-utils"; import { ErrorBoundary } from "@/app/element/errorboundary"; import { atoms, getSettingsKeyAtom } from "@/app/store/global"; import { globalStore } from "@/app/store/jotaiStore"; +import { useTabModelMaybe } from "@/app/store/tab-model"; import { isBuilderWindow } from "@/app/store/windowtype"; -import { maybeUseTabModel } from "@/app/store/tab-model"; import { checkKeyPressed, keydownWrapper } from "@/util/keyutil"; import { isMacOS, isWindows } from "@/util/platformutil"; import { cn } from "@/util/util"; @@ -245,7 +245,11 @@ const ConfigChangeModeFixer = memo(() => { ConfigChangeModeFixer.displayName = "ConfigChangeModeFixer"; -const AIPanelComponentInner = memo(() => { +type AIPanelComponentInnerProps = { + roundTopLeft: boolean; +}; + +const AIPanelComponentInner = memo(({ roundTopLeft }: AIPanelComponentInnerProps) => { const [isDragOver, setIsDragOver] = useState(false); const [isReactDndDragOver, setIsReactDndDragOver] = useState(false); const [initialLoadDone, setInitialLoadDone] = useState(false); @@ -257,7 +261,7 @@ const AIPanelComponentInner = memo(() => { const focusFollowsCursorMode = jotai.useAtomValue(getSettingsKeyAtom("app:focusfollowscursor")) ?? "off"; const telemetryEnabled = jotai.useAtomValue(getSettingsKeyAtom("telemetry:enabled")) ?? false; const isPanelVisible = jotai.useAtomValue(model.getPanelVisibleAtom()); - const tabModel = maybeUseTabModel(); + const tabModel = useTabModelMaybe(); const defaultMode = jotai.useAtomValue(getSettingsKeyAtom("waveai:defaultmode")) ?? "waveai@balanced"; const aiModeConfigs = jotai.useAtomValue(model.aiModeConfigs); @@ -268,7 +272,7 @@ const AIPanelComponentInner = memo(() => { const { messages, sendMessage, status, setMessages, error, stop } = useChat({ transport: new DefaultChatTransport({ api: model.getUseChatEndpointUrl(), - prepareSendMessagesRequest: (opts) => { + prepareSendMessagesRequest: (_opts) => { const msg = model.getAndClearMessage(); const body: any = { msg, @@ -306,7 +310,7 @@ const AIPanelComponentInner = memo(() => { }; useEffect(() => { - globalStore.set(model.isAIStreaming, status == "streaming"); + globalStore.set(model.isAIStreaming, status === "streaming" || status === "submitted"); }, [status]); useEffect(() => { @@ -503,7 +507,7 @@ const AIPanelComponentInner = memo(() => { }, [drop]); const handleFocusCapture = useCallback( - (event: React.FocusEvent) => { + (_event: React.FocusEvent) => { // console.log("Wave AI focus capture", getElemAsStr(event.target)); model.requestWaveAIFocus(); }, @@ -554,6 +558,7 @@ const AIPanelComponentInner = memo(() => { isFocused ? "border-2 border-accent" : "border-2 border-transparent" )} style={{ + borderTopLeftRadius: roundTopLeft ? 10 : 0, borderTopRightRadius: model.inBuilder ? 0 : 10, borderBottomRightRadius: model.inBuilder ? 0 : 10, borderBottomLeftRadius: 10, @@ -607,10 +612,14 @@ const AIPanelComponentInner = memo(() => { AIPanelComponentInner.displayName = "AIPanelInner"; -const AIPanelComponent = () => { +type AIPanelComponentProps = { + roundTopLeft: boolean; +}; + +const AIPanelComponent = ({ roundTopLeft }: AIPanelComponentProps) => { return ( - + ); }; diff --git a/frontend/app/app.tsx b/frontend/app/app.tsx index 76ad55751..15b09785e 100644 --- a/frontend/app/app.tsx +++ b/frontend/app/app.tsx @@ -1,19 +1,21 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 +import { + clearBadgesForBlockOnFocus, + clearBadgesForTabOnFocus, + getBadgeAtom, + getBlockBadgeAtom, +} from "@/app/store/badge"; import { ClientModel } from "@/app/store/client-model"; import { GlobalModel } from "@/app/store/global-model"; import { getTabModelByTabId, TabModelContext } from "@/app/store/tab-model"; +import { WaveEnvContext } from "@/app/waveenv/waveenv"; +import { makeWaveEnvImpl } from "@/app/waveenv/waveenvimpl"; import { Workspace } from "@/app/workspace/workspace"; +import { getLayoutModelForStaticTab } from "@/layout/index"; import { ContextMenuModel } from "@/store/contextmenu"; -import { - atoms, - clearTabIndicatorFromFocus, - createBlock, - getSettingsPrefixAtom, - getTabIndicatorAtom, - globalStore, -} from "@/store/global"; +import { atoms, createBlock, getSettingsPrefixAtom, globalStore } from "@/store/global"; import { appHandleKeyDown, keyboardMouseDownHandler } from "@/store/keymodel"; import { getElemAsStr } from "@/util/focusutil"; import * as keyutil from "@/util/keyutil"; @@ -23,7 +25,7 @@ import clsx from "clsx"; import debug from "debug"; import { Provider, useAtomValue } from "jotai"; import "overlayscrollbars/overlayscrollbars.css"; -import { useEffect } from "react"; +import { useEffect, useRef } from "react"; import { DndProvider } from "react-dnd"; import { HTML5Backend } from "react-dnd-html5-backend"; import { AppBackground } from "./app-bg"; @@ -39,14 +41,17 @@ const focusLog = debug("wave:focus"); const App = ({ onFirstRender }: { onFirstRender: () => void }) => { const tabId = useAtomValue(atoms.staticTabId); + const waveEnvRef = useRef(makeWaveEnvImpl()); useEffect(() => { onFirstRender(); }, []); return ( - - - + + + + + ); }; @@ -103,7 +108,7 @@ async function handleContextMenu(e: React.MouseEvent) { if (!canPaste && !canCopy && !canCut && !clipboardURL) { return; } - let menu: ContextMenuItem[] = []; + const menu: ContextMenuItem[] = []; if (canCut) { menu.push({ label: "Cut", role: "cut" }); } @@ -200,36 +205,72 @@ function AppFocusHandler() { const AppKeyHandlers = () => { useEffect(() => { const staticKeyDownHandler = keyutil.keydownWrapper(appHandleKeyDown); + const staticMouseDownHandler = (e: MouseEvent) => { + keyboardMouseDownHandler(e); + GlobalModel.getInstance().setIsActive(); + }; document.addEventListener("keydown", staticKeyDownHandler); - document.addEventListener("mousedown", keyboardMouseDownHandler); + document.addEventListener("mousedown", staticMouseDownHandler); return () => { document.removeEventListener("keydown", staticKeyDownHandler); - document.removeEventListener("mousedown", keyboardMouseDownHandler); + document.removeEventListener("mousedown", staticMouseDownHandler); }; }, []); return null; }; -const TabIndicatorAutoClearing = () => { +const BadgeAutoClearing = () => { const tabId = useAtomValue(atoms.staticTabId); - const indicator = useAtomValue(getTabIndicatorAtom(tabId)); const documentHasFocus = useAtomValue(atoms.documentHasFocus); + const layoutModel = getLayoutModelForStaticTab(); + const focusedNode = useAtomValue(layoutModel.focusedNode); + const focusedBlockId = focusedNode?.data?.blockId; + const badge = useAtomValue(getBlockBadgeAtom(focusedBlockId)); + const tabTransientBadge = useAtomValue(getBadgeAtom(tabId != null ? `tab:${tabId}` : null)); + const prevFocusedBlockIdRef = useRef(null); + const prevDocHasFocusRef = useRef(false); + const prevTabDocHasFocusRef = useRef(false); useEffect(() => { - if (!indicator || !documentHasFocus || !indicator.clearonfocus) { + if (!focusedBlockId || !badge || !documentHasFocus) { + prevFocusedBlockIdRef.current = focusedBlockId; + prevDocHasFocusRef.current = documentHasFocus; return; } - + const focusSwitched = + prevFocusedBlockIdRef.current !== focusedBlockId || prevDocHasFocusRef.current !== documentHasFocus; + prevFocusedBlockIdRef.current = focusedBlockId; + prevDocHasFocusRef.current = documentHasFocus; + const delay = focusSwitched ? 500 : 3000; const timeoutId = setTimeout(() => { - const currentIndicator = globalStore.get(getTabIndicatorAtom(tabId)); - if (globalStore.get(atoms.documentHasFocus) && currentIndicator?.clearonfocus) { - clearTabIndicatorFromFocus(tabId); + if (!document.hasFocus()) { + return; + } + const currentFocusedNode = globalStore.get(layoutModel.focusedNode); + if (currentFocusedNode?.data?.blockId === focusedBlockId) { + clearBadgesForBlockOnFocus(focusedBlockId); } - }, 3000); + }, delay); + return () => clearTimeout(timeoutId); + }, [focusedBlockId, badge, documentHasFocus]); + useEffect(() => { + if (!tabId || !tabTransientBadge || !documentHasFocus) { + prevTabDocHasFocusRef.current = documentHasFocus; + return; + } + const focusSwitched = prevTabDocHasFocusRef.current !== documentHasFocus; + prevTabDocHasFocusRef.current = documentHasFocus; + const delay = focusSwitched ? 500 : 3000; + const timeoutId = setTimeout(() => { + if (!document.hasFocus()) { + return; + } + clearBadgesForTabOnFocus(tabId); + }, delay); return () => clearTimeout(timeoutId); - }, [tabId, indicator, documentHasFocus]); + }, [tabId, tabTransientBadge, documentHasFocus]); return null; }; @@ -261,7 +302,7 @@ const AppInner = () => { - + diff --git a/frontend/app/block/block.tsx b/frontend/app/block/block.tsx index 19a8529b1..126f20881 100644 --- a/frontend/app/block/block.tsx +++ b/frontend/app/block/block.tsx @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { @@ -9,26 +9,21 @@ import { FullSubBlockProps, SubBlockProps, } from "@/app/block/blocktypes"; +import type { TabModel } from "@/app/store/tab-model"; +import { useTabModel } from "@/app/store/tab-model"; import { AiFileDiffViewModel } from "@/app/view/aifilediff/aifilediff"; import { LauncherViewModel } from "@/app/view/launcher/launcher"; import { PreviewModel } from "@/app/view/preview/preview-model"; import { SysinfoViewModel } from "@/app/view/sysinfo/sysinfo"; import { TsunamiViewModel } from "@/app/view/tsunami/tsunami"; import { VDomModel } from "@/app/view/vdom/vdom-model"; +import { useWaveEnv, WaveEnv } from "@/app/waveenv/waveenv"; import { ErrorBoundary } from "@/element/errorboundary"; import { CenteredDiv } from "@/element/quickelems"; import { useDebouncedNodeInnerRect } from "@/layout/index"; import { counterInc } from "@/store/counters"; -import { - atoms, - getBlockComponentModel, - getSettingsKeyAtom, - registerBlockComponentModel, - unregisterBlockComponentModel, -} from "@/store/global"; -import type { TabModel } from "@/app/store/tab-model"; -import { useTabModel } from "@/app/store/tab-model"; -import { getWaveObjectAtom, makeORef, useWaveObjectValue } from "@/store/wos"; +import { getBlockComponentModel, registerBlockComponentModel, unregisterBlockComponentModel } from "@/store/global"; +import { makeORef } from "@/store/wos"; import { focusedBlockId, getElemAsStr } from "@/util/focusutil"; import { isBlank, useAtomValueSafe } from "@/util/util"; import { HelpViewModel } from "@/view/helpview/helpview"; @@ -41,6 +36,7 @@ import { memo, Suspense, useCallback, useEffect, useLayoutEffect, useMemo, useRe import { QuickTipsViewModel } from "../view/quicktipsview/quicktipsview"; import { WaveConfigViewModel } from "../view/waveconfig/waveconfig-model"; import "./block.scss"; +import { BlockEnv } from "./blockenv"; import { BlockFrame } from "./blockframe"; import { blockViewToIcon, blockViewToName } from "./blockutil"; @@ -59,12 +55,18 @@ BlockRegistry.set("tsunami", TsunamiViewModel); BlockRegistry.set("aifilediff", AiFileDiffViewModel); BlockRegistry.set("waveconfig", WaveConfigViewModel); -function makeViewModel(blockId: string, blockView: string, nodeModel: BlockNodeModel, tabModel: TabModel): ViewModel { +function makeViewModel( + blockId: string, + blockView: string, + nodeModel: BlockNodeModel, + tabModel: TabModel, + waveEnv: WaveEnv +): ViewModel { const ctor = BlockRegistry.get(blockView); if (ctor != null) { - return new ctor(blockId, nodeModel, tabModel); + return new ctor({ blockId, nodeModel, tabModel, waveEnv }); } - return makeDefaultViewModel(blockId, blockView); + return makeDefaultViewModel(blockView); } function getViewElem( @@ -84,18 +86,11 @@ function getViewElem( return ; } -function makeDefaultViewModel(blockId: string, viewType: string): ViewModel { - const blockDataAtom = getWaveObjectAtom(makeORef("block", blockId)); - let viewModel: ViewModel = { +function makeDefaultViewModel(viewType: string): ViewModel { + const viewModel: ViewModel = { viewType: viewType, - viewIcon: atom((get) => { - const blockData = get(blockDataAtom); - return blockViewToIcon(blockData?.meta?.view); - }), - viewName: atom((get) => { - const blockData = get(blockDataAtom); - return blockViewToName(blockData?.meta?.view); - }), + viewIcon: atom(blockViewToIcon(viewType)), + viewName: atom(blockViewToName(viewType)), preIconButton: atom(null), endIconButtons: atom(null), viewComponent: null, @@ -104,8 +99,9 @@ function makeDefaultViewModel(blockId: string, viewType: string): ViewModel { } const BlockPreview = memo(({ nodeModel, viewModel }: FullBlockProps) => { - const [blockData] = useWaveObjectValue(makeORef("block", nodeModel.blockId)); - if (!blockData) { + const waveEnv = useWaveEnv(); + const blockIsNull = useAtomValue(waveEnv.wos.isWaveObjectNullAtom(makeORef("block", nodeModel.blockId))); + if (blockIsNull) { return null; } return ( @@ -120,15 +116,17 @@ const BlockPreview = memo(({ nodeModel, viewModel }: FullBlockProps) => { }); const BlockSubBlock = memo(({ nodeModel, viewModel }: FullSubBlockProps) => { - const [blockData] = useWaveObjectValue(makeORef("block", nodeModel.blockId)); + const waveEnv = useWaveEnv(); + const blockIsNull = useAtomValue(waveEnv.wos.isWaveObjectNullAtom(makeORef("block", nodeModel.blockId))); + const blockView = useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "view")) ?? ""; const blockRef = useRef(null); const contentRef = useRef(null); const viewElem = useMemo( - () => getViewElem(nodeModel.blockId, blockRef, contentRef, blockData?.meta?.view, viewModel), - [nodeModel.blockId, blockData?.meta?.view, viewModel] + () => getViewElem(nodeModel.blockId, blockRef, contentRef, blockView, viewModel), + [nodeModel.blockId, blockView, viewModel] ); const noPadding = useAtomValueSafe(viewModel.noPadding); - if (!blockData) { + if (blockIsNull) { return null; } return ( @@ -142,18 +140,19 @@ const BlockSubBlock = memo(({ nodeModel, viewModel }: FullSubBlockProps) => { const BlockFull = memo(({ nodeModel, viewModel }: FullBlockProps) => { counterInc("render-BlockFull"); + const waveEnv = useWaveEnv(); const focusElemRef = useRef(null); const blockRef = useRef(null); const contentRef = useRef(null); const [blockClicked, setBlockClicked] = useState(false); - const [blockData] = useWaveObjectValue(makeORef("block", nodeModel.blockId)); + const blockView = useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "view")) ?? ""; const isFocused = useAtomValue(nodeModel.isFocused); const disablePointerEvents = useAtomValue(nodeModel.disablePointerEvents); const isResizing = useAtomValue(nodeModel.isResizing); const isMagnified = useAtomValue(nodeModel.isMagnified); const anyMagnified = useAtomValue(nodeModel.anyMagnified); - const modalOpen = useAtomValue(atoms.modalOpen); - const focusFollowsCursorMode = useAtomValue(getSettingsKeyAtom("app:focusfollowscursor")) ?? "off"; + const modalOpen = useAtomValue(waveEnv.atoms.modalOpen); + const focusFollowsCursorMode = useAtomValue(waveEnv.getSettingsKeyAtom("app:focusfollowscursor")) ?? "off"; const innerRect = useDebouncedNodeInnerRect(nodeModel); const noPadding = useAtomValueSafe(viewModel.noPadding); @@ -206,8 +205,8 @@ const BlockFull = memo(({ nodeModel, viewModel }: FullBlockProps) => { }, [innerRect, disablePointerEvents, blockContentOffset]); const viewElem = useMemo( - () => getViewElem(nodeModel.blockId, blockRef, contentRef, blockData?.meta?.view, viewModel), - [nodeModel.blockId, blockData?.meta?.view, viewModel] + () => getViewElem(nodeModel.blockId, blockRef, contentRef, blockView, viewModel), + [nodeModel.blockId, blockView, viewModel] ); const handleChildFocus = useCallback( @@ -233,7 +232,7 @@ const BlockFull = memo(({ nodeModel, viewModel }: FullBlockProps) => { (event: React.PointerEvent) => { const focusFollowsCursorEnabled = focusFollowsCursorMode === "on" || - (focusFollowsCursorMode === "term" && blockData?.meta?.view === "term"); + (focusFollowsCursorMode === "term" && blockView === "term"); if (!focusFollowsCursorEnabled || event.pointerType === "touch" || event.buttons > 0) { return; } @@ -250,7 +249,7 @@ const BlockFull = memo(({ nodeModel, viewModel }: FullBlockProps) => { }, [ focusFollowsCursorMode, - blockData?.meta?.view, + blockView, modalOpen, disablePointerEvents, isResizing, @@ -304,15 +303,16 @@ const BlockFull = memo(({ nodeModel, viewModel }: FullBlockProps) => { ); }); -const Block = memo((props: BlockProps) => { +const BlockInner = memo((props: BlockProps & { viewType: string }) => { counterInc("render-Block"); counterInc("render-Block-" + props.nodeModel?.blockId?.substring(0, 8)); const tabModel = useTabModel(); - const [blockData, loading] = useWaveObjectValue(makeORef("block", props.nodeModel.blockId)); + const waveEnv = useWaveEnv(); const bcm = getBlockComponentModel(props.nodeModel.blockId); let viewModel = bcm?.viewModel; - if (viewModel == null || viewModel.viewType != blockData?.meta?.view) { - viewModel = makeViewModel(props.nodeModel.blockId, blockData?.meta?.view, props.nodeModel, tabModel); + if (viewModel == null) { + // viewModel gets the full waveEnv + viewModel = makeViewModel(props.nodeModel.blockId, props.viewType, props.nodeModel, tabModel, waveEnv); registerBlockComponentModel(props.nodeModel.blockId, { viewModel }); } useEffect(() => { @@ -321,24 +321,33 @@ const Block = memo((props: BlockProps) => { viewModel?.dispose?.(); }; }, []); - if (loading || isBlank(props.nodeModel.blockId) || blockData == null) { - return null; - } if (props.preview) { return ; } return ; }); +BlockInner.displayName = "BlockInner"; -const SubBlock = memo((props: SubBlockProps) => { +const Block = memo((props: BlockProps) => { + const waveEnv = useWaveEnv(); + const isNull = useAtomValue(waveEnv.wos.isWaveObjectNullAtom(makeORef("block", props.nodeModel.blockId))); + const viewType = useAtomValue(waveEnv.getBlockMetaKeyAtom(props.nodeModel.blockId, "view")) ?? ""; + if (isNull || isBlank(props.nodeModel.blockId)) { + return null; + } + return ; +}); + +const SubBlockInner = memo((props: SubBlockProps & { viewType: string }) => { counterInc("render-Block"); - counterInc("render-Block-" + props.nodeModel?.blockId?.substring(0, 8)); + counterInc("render-Block-" + props.nodeModel.blockId?.substring(0, 8)); const tabModel = useTabModel(); - const [blockData, loading] = useWaveObjectValue(makeORef("block", props.nodeModel.blockId)); + const waveEnv = useWaveEnv(); const bcm = getBlockComponentModel(props.nodeModel.blockId); let viewModel = bcm?.viewModel; - if (viewModel == null || viewModel.viewType != blockData?.meta?.view) { - viewModel = makeViewModel(props.nodeModel.blockId, blockData?.meta?.view, props.nodeModel, tabModel); + if (viewModel == null) { + // viewModel gets the full waveEnv + viewModel = makeViewModel(props.nodeModel.blockId, props.viewType, props.nodeModel, tabModel, waveEnv); registerBlockComponentModel(props.nodeModel.blockId, { viewModel }); } useEffect(() => { @@ -347,10 +356,18 @@ const SubBlock = memo((props: SubBlockProps) => { viewModel?.dispose?.(); }; }, []); - if (loading || isBlank(props.nodeModel.blockId) || blockData == null) { + return ; +}); +SubBlockInner.displayName = "SubBlockInner"; + +const SubBlock = memo((props: SubBlockProps) => { + const waveEnv = useWaveEnv(); + const isNull = useAtomValue(waveEnv.wos.isWaveObjectNullAtom(makeORef("block", props.nodeModel.blockId))); + const viewType = useAtomValue(waveEnv.getBlockMetaKeyAtom(props.nodeModel.blockId, "view")) ?? ""; + if (isNull || isBlank(props.nodeModel.blockId)) { return null; } - return ; + return ; }); export { Block, SubBlock }; diff --git a/frontend/app/block/blockenv.ts b/frontend/app/block/blockenv.ts new file mode 100644 index 000000000..5166d0195 --- /dev/null +++ b/frontend/app/block/blockenv.ts @@ -0,0 +1,49 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { + BlockMetaKeyAtomFnType, + ConnConfigKeyAtomFnType, + SettingsKeyAtomFnType, + WaveEnv, + WaveEnvSubset, +} from "@/app/waveenv/waveenv"; + +export type BlockEnv = WaveEnvSubset<{ + getSettingsKeyAtom: SettingsKeyAtomFnType< + | "app:focusfollowscursor" + | "app:showoverlayblocknums" + | "window:magnifiedblockblurprimarypx" + | "window:magnifiedblockopacity" + >; + showContextMenu: WaveEnv["showContextMenu"]; + atoms: { + modalOpen: WaveEnv["atoms"]["modalOpen"]; + controlShiftDelayAtom: WaveEnv["atoms"]["controlShiftDelayAtom"]; + }; + electron: { + openExternal: WaveEnv["electron"]["openExternal"]; + }; + rpc: { + ActivityCommand: WaveEnv["rpc"]["ActivityCommand"]; + ConnEnsureCommand: WaveEnv["rpc"]["ConnEnsureCommand"]; + ConnDisconnectCommand: WaveEnv["rpc"]["ConnDisconnectCommand"]; + ConnConnectCommand: WaveEnv["rpc"]["ConnConnectCommand"]; + SetConnectionsConfigCommand: WaveEnv["rpc"]["SetConnectionsConfigCommand"]; + DismissWshFailCommand: WaveEnv["rpc"]["DismissWshFailCommand"]; + }; + wos: WaveEnv["wos"]; + getConnStatusAtom: WaveEnv["getConnStatusAtom"]; + getLocalHostDisplayNameAtom: WaveEnv["getLocalHostDisplayNameAtom"]; + getConnConfigKeyAtom: ConnConfigKeyAtomFnType<"conn:wshenabled" | "conn:moshenabled">; + getBlockMetaKeyAtom: BlockMetaKeyAtomFnType< + | "frame:text" + | "frame:activebordercolor" + | "frame:bordercolor" + | "view" + | "connection" + | "icon:color" + | "frame:title" + | "frame:icon" + >; +}>; diff --git a/frontend/app/block/blockframe-header.tsx b/frontend/app/block/blockframe-header.tsx index 70f28ff2f..319e9b4a4 100644 --- a/frontend/app/block/blockframe-header.tsx +++ b/frontend/app/block/blockframe-header.tsx @@ -10,30 +10,32 @@ import { } from "@/app/block/blockutil"; import { ConnectionButton } from "@/app/block/connectionbutton"; import { DurableSessionFlyover } from "@/app/block/durable-session-flyover"; -import { ContextMenuModel } from "@/app/store/contextmenu"; -import { recordTEvent, refocusNode, WOS } from "@/app/store/global"; +import { getBlockBadgeAtom } from "@/app/store/badge"; +import { recordTEvent, refocusNode } from "@/app/store/global"; import { globalStore } from "@/app/store/jotaiStore"; import { uxCloseBlock } from "@/app/store/keymodel"; -import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; +import { useWaveEnv } from "@/app/waveenv/waveenv"; import { IconButton } from "@/element/iconbutton"; import { NodeModel } from "@/layout/index"; import * as util from "@/util/util"; -import { cn } from "@/util/util"; +import { cn, makeIconClass } from "@/util/util"; import * as jotai from "jotai"; import * as React from "react"; +import { BlockEnv } from "./blockenv"; import { BlockFrameProps } from "./blocktypes"; function handleHeaderContextMenu( e: React.MouseEvent, blockId: string, viewModel: ViewModel, - nodeModel: NodeModel + nodeModel: NodeModel, + blockEnv: BlockEnv ) { e.preventDefault(); e.stopPropagation(); const magnified = globalStore.get(nodeModel.isMagnified); - let menu: ContextMenuItem[] = [ + const menu: ContextMenuItem[] = [ { label: magnified ? "Un-Magnify Block" : "Magnify Block", click: () => { @@ -57,19 +59,22 @@ function handleHeaderContextMenu( click: () => uxCloseBlock(blockId), } ); - ContextMenuModel.getInstance().showContextMenu(menu, e); + blockEnv.showContextMenu(menu, e); } type HeaderTextElemsProps = { viewModel: ViewModel; - blockData: Block; + blockId: string; preview: boolean; error?: Error; }; -const HeaderTextElems = React.memo(({ viewModel, blockData, preview, error }: HeaderTextElemsProps) => { +const HeaderTextElems = React.memo(({ viewModel, blockId, preview, error }: HeaderTextElemsProps) => { + const waveEnv = useWaveEnv(); + const frameTextAtom = waveEnv.getBlockMetaKeyAtom(blockId, "frame:text"); + const frameText = jotai.useAtomValue(frameTextAtom); let headerTextUnion = util.useAtomValueSafe(viewModel?.viewText); - headerTextUnion = blockData?.meta?.["frame:text"] ?? headerTextUnion; + headerTextUnion = frameText ?? headerTextUnion; const headerTextElems: React.ReactElement[] = []; if (typeof headerTextUnion === "string") { @@ -108,6 +113,7 @@ type HeaderEndIconsProps = { }; const HeaderEndIcons = React.memo(({ viewModel, nodeModel, blockId }: HeaderEndIconsProps) => { + const blockEnv = useWaveEnv(); const endIconButtons = util.useAtomValueSafe(viewModel?.endIconButtons); const magnified = jotai.useAtomValue(nodeModel.isMagnified); const ephemeral = jotai.useAtomValue(nodeModel.isEphemeral); @@ -123,7 +129,7 @@ const HeaderEndIcons = React.memo(({ viewModel, nodeModel, blockId }: HeaderEndI elemtype: "iconbutton", icon: "cog", title: "Settings", - click: (e) => handleHeaderContextMenu(e, blockId, viewModel, nodeModel), + click: (e) => handleHeaderContextMenu(e, blockId, viewModel, nodeModel, blockEnv), }; endIconsElem.push(); if (ephemeral) { @@ -170,37 +176,43 @@ const BlockFrame_Header = ({ changeConnModalAtom, error, }: BlockFrameProps & { changeConnModalAtom: jotai.PrimitiveAtom; error?: Error }) => { - const [blockData] = WOS.useWaveObjectValue(WOS.makeORef("block", nodeModel.blockId)); - let viewName = util.useAtomValueSafe(viewModel?.viewName) ?? blockViewToName(blockData?.meta?.view); - let viewIconUnion = util.useAtomValueSafe(viewModel?.viewIcon) ?? blockViewToIcon(blockData?.meta?.view); + const waveEnv = useWaveEnv(); + const metaView = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "view")); + const metaFrameTitle = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "frame:title")); + const metaFrameIcon = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "frame:icon")); + const metaConnection = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "connection")); + let viewName = util.useAtomValueSafe(viewModel?.viewName) ?? blockViewToName(metaView); + let viewIconUnion = util.useAtomValueSafe(viewModel?.viewIcon) ?? blockViewToIcon(metaView); const preIconButton = util.useAtomValueSafe(viewModel?.preIconButton); const useTermHeader = util.useAtomValueSafe(viewModel?.useTermHeader); const termConfigedDurable = util.useAtomValueSafe(viewModel?.termConfigedDurable); const hideViewName = util.useAtomValueSafe(viewModel?.hideViewName); + const badge = jotai.useAtomValue(getBlockBadgeAtom(useTermHeader ? nodeModel.blockId : null)); const magnified = jotai.useAtomValue(nodeModel.isMagnified); const prevMagifiedState = React.useRef(magnified); const manageConnection = util.useAtomValueSafe(viewModel?.manageConnection); + const iconColor = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "icon:color")); const dragHandleRef = preview ? null : nodeModel.dragHandleRef; - const isTerminalBlock = blockData?.meta?.view === "term"; - viewName = blockData?.meta?.["frame:title"] ?? viewName; - viewIconUnion = blockData?.meta?.["frame:icon"] ?? viewIconUnion; + const isTerminalBlock = metaView === "term"; + viewName = metaFrameTitle ?? viewName; + viewIconUnion = metaFrameIcon ?? viewIconUnion; React.useEffect(() => { if (magnified && !preview && !prevMagifiedState.current) { - RpcApi.ActivityCommand(TabRpcClient, { nummagnify: 1 }); + waveEnv.rpc.ActivityCommand(TabRpcClient, { nummagnify: 1 }); recordTEvent("action:magnify", { "block:view": viewName }); } prevMagifiedState.current = magnified; }, [magnified]); - const viewIconElem = getViewIconElem(viewIconUnion, blockData); + const viewIconElem = getViewIconElem(viewIconUnion, iconColor); return (
handleHeaderContextMenu(e, nodeModel.blockId, viewModel, nodeModel)} + onContextMenu={(e) => handleHeaderContextMenu(e, nodeModel.blockId, viewModel, nodeModel, waveEnv)} > {!useTermHeader && ( <> @@ -215,7 +227,7 @@ const BlockFrame_Header = ({ @@ -229,7 +241,12 @@ const BlockFrame_Header = ({ divClassName="iconbutton disabled text-[13px] ml-[-4px]" /> )} - + {useTermHeader && badge && ( +
+ +
+ )} +
); diff --git a/frontend/app/block/blockframe.tsx b/frontend/app/block/blockframe.tsx index 1ed88fb57..0b4abb755 100644 --- a/frontend/app/block/blockframe.tsx +++ b/frontend/app/block/blockframe.tsx @@ -6,30 +6,36 @@ import { BlockFrame_Header } from "@/app/block/blockframe-header"; import { blockViewToIcon, getViewIconElem } from "@/app/block/blockutil"; import { ConnStatusOverlay } from "@/app/block/connstatusoverlay"; import { ChangeConnectionBlockModal } from "@/app/modals/conntypeahead"; -import { atoms, getBlockComponentModel, getSettingsKeyAtom, globalStore, useBlockAtom, WOS } from "@/app/store/global"; +import { getBlockComponentModel, globalStore, useBlockAtom } from "@/app/store/global"; import { useTabModel } from "@/app/store/tab-model"; -import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; +import { useWaveEnv } from "@/app/waveenv/waveenv"; import { WorkspaceLayoutModel } from "@/app/workspace/workspace-layout-model"; import { ErrorBoundary } from "@/element/errorboundary"; import { NodeModel } from "@/layout/index"; +import { makeORef } from "@/store/wos"; import * as util from "@/util/util"; import { makeIconClass } from "@/util/util"; import { computeBgStyleFromMeta } from "@/util/waveutil"; import clsx from "clsx"; import * as jotai from "jotai"; import * as React from "react"; +import { BlockEnv } from "./blockenv"; import { BlockFrameProps } from "./blocktypes"; const BlockMask = React.memo(({ nodeModel }: { nodeModel: NodeModel }) => { + const waveEnv = useWaveEnv(); const tabModel = useTabModel(); const isFocused = jotai.useAtomValue(nodeModel.isFocused); const isEphemeral = jotai.useAtomValue(nodeModel.isEphemeral); const blockNum = jotai.useAtomValue(nodeModel.blockNum); - const isLayoutMode = jotai.useAtomValue(atoms.controlShiftDelayAtom); - const showOverlayBlockNums = jotai.useAtomValue(getSettingsKeyAtom("app:showoverlayblocknums")) ?? true; + const isLayoutMode = jotai.useAtomValue(waveEnv.atoms.controlShiftDelayAtom); + const showOverlayBlockNums = jotai.useAtomValue(waveEnv.getSettingsKeyAtom("app:showoverlayblocknums")) ?? true; const blockHighlight = jotai.useAtomValue(BlockModel.getInstance().getBlockHighlightAtom(nodeModel.blockId)); - const [blockData] = WOS.useWaveObjectValue(WOS.makeORef("block", nodeModel.blockId)); + const frameActiveBorderColor = jotai.useAtomValue( + waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "frame:activebordercolor") + ); + const frameBorderColor = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "frame:bordercolor")); const tabActiveBorderColor = jotai.useAtomValue(tabModel.getTabMetaAtom("bg:activebordercolor")); const tabBorderColor = jotai.useAtomValue(tabModel.getTabMetaAtom("bg:bordercolor")); const style: React.CSSProperties = {}; @@ -39,15 +45,15 @@ const BlockMask = React.memo(({ nodeModel }: { nodeModel: NodeModel }) => { if (tabActiveBorderColor) { style.borderColor = tabActiveBorderColor; } - if (blockData?.meta?.["frame:activebordercolor"]) { - style.borderColor = blockData.meta["frame:activebordercolor"]; + if (frameActiveBorderColor) { + style.borderColor = frameActiveBorderColor; } } else { if (tabBorderColor) { style.borderColor = tabBorderColor; } - if (blockData?.meta?.["frame:bordercolor"]) { - style.borderColor = blockData.meta["frame:bordercolor"]; + if (frameBorderColor) { + style.borderColor = frameBorderColor; } if (isEphemeral && !style.borderColor) { style.borderColor = "rgba(255, 255, 255, 0.7)"; @@ -87,11 +93,12 @@ const BlockMask = React.memo(({ nodeModel }: { nodeModel: NodeModel }) => { }); const BlockFrame_Default_Component = (props: BlockFrameProps) => { + const waveEnv = useWaveEnv(); const { nodeModel, viewModel, blockModel, preview, numBlocksInTab, children } = props; - const [blockData] = WOS.useWaveObjectValue(WOS.makeORef("block", nodeModel.blockId)); const isFocused = jotai.useAtomValue(nodeModel.isFocused); const aiPanelVisible = jotai.useAtomValue(WorkspaceLayoutModel.getInstance().panelVisibleAtom); - const viewIconUnion = util.useAtomValueSafe(viewModel?.viewIcon) ?? blockViewToIcon(blockData?.meta?.view); + const metaView = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "view")); + const viewIconUnion = util.useAtomValueSafe(viewModel?.viewIcon) ?? blockViewToIcon(metaView); const customBg = util.useAtomValueSafe(viewModel?.blockBg); const manageConnection = util.useAtomValueSafe(viewModel?.manageConnection); const changeConnModalAtom = useBlockAtom(nodeModel.blockId, "changeConn", () => { @@ -100,11 +107,13 @@ const BlockFrame_Default_Component = (props: BlockFrameProps) => { const connModalOpen = jotai.useAtomValue(changeConnModalAtom); const isMagnified = jotai.useAtomValue(nodeModel.isMagnified); const isEphemeral = jotai.useAtomValue(nodeModel.isEphemeral); - const [magnifiedBlockBlurAtom] = React.useState(() => getSettingsKeyAtom("window:magnifiedblockblurprimarypx")); + const [magnifiedBlockBlurAtom] = React.useState(() => waveEnv.getSettingsKeyAtom("window:magnifiedblockblurprimarypx")); const magnifiedBlockBlur = jotai.useAtomValue(magnifiedBlockBlurAtom); - const [magnifiedBlockOpacityAtom] = React.useState(() => getSettingsKeyAtom("window:magnifiedblockopacity")); + const [magnifiedBlockOpacityAtom] = React.useState(() => waveEnv.getSettingsKeyAtom("window:magnifiedblockopacity")); const magnifiedBlockOpacity = jotai.useAtomValue(magnifiedBlockOpacityAtom); const connBtnRef = React.useRef(null); + const connName = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "connection")); + const iconColor = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "icon:color")); const noHeader = util.useAtomValueSafe(viewModel?.noHeader); React.useEffect(() => { @@ -126,23 +135,20 @@ const BlockFrame_Default_Component = (props: BlockFrameProps) => { }, [manageConnection]); React.useEffect(() => { // on mount, if manageConnection, call ConnEnsure - if (!manageConnection || blockData == null || preview) { + if (!manageConnection || preview) { return; } - const connName = blockData?.meta?.connection; if (!util.isLocalConnName(connName)) { console.log("ensure conn", nodeModel.blockId, connName); - RpcApi.ConnEnsureCommand( - TabRpcClient, - { connname: connName, logblockid: nodeModel.blockId }, - { timeout: 60000 } - ).catch((e) => { - console.log("error ensuring connection", nodeModel.blockId, connName, e); - }); + waveEnv.rpc + .ConnEnsureCommand(TabRpcClient, { connname: connName, logblockid: nodeModel.blockId }, { timeout: 60000 }) + .catch((e) => { + console.log("error ensuring connection", nodeModel.blockId, connName, e); + }); } - }, [manageConnection, blockData]); + }, [manageConnection, connName]); - const viewIconElem = getViewIconElem(viewIconUnion, blockData); + const viewIconElem = getViewIconElem(viewIconUnion, iconColor); let innerStyle: React.CSSProperties = {}; if (!preview) { innerStyle = computeBgStyleFromMeta(customBg); @@ -203,11 +209,12 @@ const BlockFrame_Default_Component = (props: BlockFrameProps) => { const BlockFrame_Default = React.memo(BlockFrame_Default_Component) as typeof BlockFrame_Default_Component; const BlockFrame = React.memo((props: BlockFrameProps) => { + const waveEnv = useWaveEnv(); const tabModel = useTabModel(); const blockId = props.nodeModel.blockId; - const [blockData] = WOS.useWaveObjectValue(WOS.makeORef("block", blockId)); + const blockIsNull = jotai.useAtomValue(waveEnv.wos.isWaveObjectNullAtom(makeORef("block", blockId))); const numBlocks = jotai.useAtomValue(tabModel.tabNumBlocksAtom); - if (!blockId || !blockData) { + if (!blockId || blockIsNull) { return null; } return ; diff --git a/frontend/app/block/blockutil.tsx b/frontend/app/block/blockutil.tsx index 542f9f352..01346183a 100644 --- a/frontend/app/block/blockutil.tsx +++ b/frontend/app/block/blockutil.tsx @@ -66,7 +66,7 @@ export function processTitleString(titleString: string): React.ReactNode[] { const tagRegex = /<(\/)?([a-z]+)(?::([#a-z0-9@-]+))?>/g; let lastIdx = 0; let match; - let partsStack = [[]]; + const partsStack = [[]]; while ((match = tagRegex.exec(titleString)) != null) { const lastPart = partsStack[partsStack.length - 1]; const before = titleString.substring(lastIdx, match.index); @@ -98,7 +98,7 @@ export function processTitleString(titleString: string): React.ReactNode[] { if (!tagParam.match(colorRegex)) { continue; } - let children = []; + const children = []; const rtag = React.createElement("span", { key: match.index, style: { color: tagParam } }, children); lastPart.push(rtag); partsStack.push(children); @@ -112,7 +112,7 @@ export function processTitleString(titleString: string): React.ReactNode[] { partsStack.pop(); continue; } - let children = []; + const children = []; const rtag = React.createElement(tagName, { key: match.index }, children); lastPart.push(rtag); partsStack.push(children); @@ -123,12 +123,12 @@ export function processTitleString(titleString: string): React.ReactNode[] { return partsStack[0]; } -export function getBlockHeaderIcon(blockIcon: string, blockData: Block): React.ReactNode { +export function getBlockHeaderIcon(blockIcon: string, overrideIconColor?: string): React.ReactNode { let blockIconElem: React.ReactNode = null; if (util.isBlank(blockIcon)) { blockIcon = "square"; } - let iconColor = blockData?.meta?.["icon:color"]; + let iconColor = overrideIconColor; if (iconColor && !iconColor.match(colorRegex)) { iconColor = null; } @@ -145,17 +145,11 @@ export function getBlockHeaderIcon(blockIcon: string, blockData: Block): React.R export function getViewIconElem( viewIconUnion: string | IconButtonDecl, - blockData: Block, - iconColor?: string + overrideIconColor?: string ): React.ReactElement { if (viewIconUnion == null || typeof viewIconUnion === "string") { const viewIcon = viewIconUnion as string; - const style: React.CSSProperties = iconColor ? { color: iconColor, opacity: 1.0 } : {}; - return ( -
- {getBlockHeaderIcon(viewIcon, blockData)} -
- ); + return
{getBlockHeaderIcon(viewIcon, overrideIconColor)}
; } else { return ; } diff --git a/frontend/app/block/connectionbutton.tsx b/frontend/app/block/connectionbutton.tsx index c0a37659c..b700ea141 100644 --- a/frontend/app/block/connectionbutton.tsx +++ b/frontend/app/block/connectionbutton.tsx @@ -2,12 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 import { computeConnColorNum } from "@/app/block/blockutil"; -import { getConnStatusAtom, getLocalHostDisplayNameAtom, recordTEvent } from "@/app/store/global"; +import { recordTEvent } from "@/app/store/global"; +import { useWaveEnv } from "@/app/waveenv/waveenv"; import { IconButton } from "@/element/iconbutton"; import * as util from "@/util/util"; import * as jotai from "jotai"; import * as React from "react"; import DotsSvg from "../asset/dots-anim-4.svg"; +import { BlockEnv } from "./blockenv"; interface ConnectionButtonProps { connection: string; @@ -18,11 +20,11 @@ interface ConnectionButtonProps { export const ConnectionButton = React.memo( React.forwardRef( ({ connection, changeConnModalAtom, isTerminalBlock }: ConnectionButtonProps, ref) => { - const [connModalOpen, setConnModalOpen] = jotai.useAtom(changeConnModalAtom); + const waveEnv = useWaveEnv(); + const [_connModalOpen, setConnModalOpen] = jotai.useAtom(changeConnModalAtom); const isLocal = util.isLocalConnName(connection); - const connStatusAtom = getConnStatusAtom(connection); - const connStatus = jotai.useAtomValue(connStatusAtom); - const localName = jotai.useAtomValue(getLocalHostDisplayNameAtom()); + const connStatus = jotai.useAtomValue(waveEnv.getConnStatusAtom(connection)); + const localName = jotai.useAtomValue(waveEnv.getLocalHostDisplayNameAtom()); let showDisconnectedSlash = false; let connIconElem: React.ReactNode = null; const connColorNum = computeConnColorNum(connStatus); @@ -104,6 +106,15 @@ export const ConnectionButton = React.memo( const wshProblem = connection && !connStatus?.wshenabled && connStatus?.status == "connected"; const showNoWshButton = wshProblem && !isLocal; + // Add mosh status detection + const isMoshActive = connStatus?.moshactive; + const isMoshEnabled = connStatus?.moshenabled; + + // Update title text if mosh is active + if (isMoshActive) { + titleText = "Connected via Mosh to " + connection; + } + return ( <>
{ const [elapsedTime, setElapsedTime] = React.useState(""); + const waveEnv = useWaveEnv(); const handleDisconnect = React.useCallback(() => { - const prtn = RpcApi.ConnDisconnectCommand(TabRpcClient, connName, { timeout: 5000 }); + const prtn = waveEnv.rpc.ConnDisconnectCommand(TabRpcClient, connName, { timeout: 5000 }); prtn.catch((e) => console.log("error disconnecting", connName, e)); - }, [connName]); + }, [connName, waveEnv]); React.useEffect(() => { if (!connStatus.lastactivitybeforestalledtime) { @@ -118,15 +119,16 @@ export const ConnStatusOverlay = React.memo( viewModel: ViewModel; changeConnModalAtom: jotai.PrimitiveAtom; }) => { - const [blockData] = WOS.useWaveObjectValue(WOS.makeORef("block", nodeModel.blockId)); + const waveEnv = useWaveEnv(); + const connName = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(nodeModel.blockId, "connection")); const [connModalOpen] = jotai.useAtom(changeConnModalAtom); - const connName = blockData?.meta?.connection; - const connStatus = jotai.useAtomValue(getConnStatusAtom(connName)); - const isLayoutMode = jotai.useAtomValue(atoms.controlShiftDelayAtom); + const connStatus = jotai.useAtomValue(waveEnv.getConnStatusAtom(connName)); + const isLayoutMode = jotai.useAtomValue(waveEnv.atoms.controlShiftDelayAtom); const [overlayRefCallback, _, domRect] = useDimensionsWithCallbackRef(30); const width = domRect?.width; const [showError, setShowError] = React.useState(false); - const fullConfig = jotai.useAtomValue(atoms.fullConfigAtom); + const wshConfigEnabled = + jotai.useAtomValue(waveEnv.getConnConfigKeyAtom(connName, "conn:wshenabled")) ?? true; const [showWshError, setShowWshError] = React.useState(false); React.useEffect(() => { @@ -138,13 +140,13 @@ export const ConnStatusOverlay = React.memo( }, [width, connStatus, setShowError]); const handleTryReconnect = React.useCallback(() => { - const prtn = RpcApi.ConnConnectCommand( + const prtn = waveEnv.rpc.ConnConnectCommand( TabRpcClient, { host: connName, logblockid: nodeModel.blockId }, { timeout: 60000 } ); prtn.catch((e) => console.log("error reconnecting", connName, e)); - }, [connName, nodeModel.blockId]); + }, [connName, nodeModel.blockId, waveEnv]); const handleDisableWsh = React.useCallback(async () => { const metamaptype: unknown = { @@ -155,19 +157,34 @@ export const ConnStatusOverlay = React.memo( metamaptype: metamaptype, }; try { - await RpcApi.SetConnectionsConfigCommand(TabRpcClient, data); + await waveEnv.rpc.SetConnectionsConfigCommand(TabRpcClient, data); } catch (e) { console.log("problem setting connection config: ", e); } - }, [connName]); + }, [connName, waveEnv]); + + const handleDisableMosh = React.useCallback(async () => { + const metamaptype: unknown = { + "conn:moshenabled": false, + }; + const data: ConnConfigRequest = { + host: connName, + metamaptype: metamaptype, + }; + try { + await waveEnv.rpc.SetConnectionsConfigCommand(TabRpcClient, data); + } catch (e) { + console.log("problem setting connection config: ", e); + } + }, [connName, waveEnv]); const handleRemoveWshError = React.useCallback(async () => { try { - await RpcApi.DismissWshFailCommand(TabRpcClient, connName); + await waveEnv.rpc.DismissWshFailCommand(TabRpcClient, connName); } catch (e) { console.log("unable to dismiss wsh error: ", e); } - }, [connName]); + }, [connName, waveEnv]); let statusText = `Disconnected from "${connName}"`; let showReconnect = true; @@ -189,7 +206,8 @@ export const ConnStatusOverlay = React.memo( } const showIcon = connStatus.status != "connecting"; - const wshConfigEnabled = fullConfig?.connections?.[connName]?.["conn:wshenabled"] ?? true; + const moshConfigEnabled = + jotai.useAtomValue(waveEnv.getConnConfigKeyAtom(connName, "conn:moshenabled")) ?? false; React.useEffect(() => { const showWshErrorTemp = connStatus.status == "connected" && @@ -215,7 +233,7 @@ export const ConnStatusOverlay = React.memo( [showError, showWshError, connStatus.error, connStatus.wsherror] ); - let showStalled = connStatus.status == "connected" && connStatus.connhealthstatus == "stalled"; + const showStalled = connStatus.status == "connected" && connStatus.connhealthstatus == "stalled"; if (!showWshError && !showStalled && (isLayoutMode || connStatus.status == "connected" || connModalOpen)) { return null; } diff --git a/frontend/app/block/durable-session-flyover.tsx b/frontend/app/block/durable-session-flyover.tsx index 620c57731..7ab7fa0b1 100644 --- a/frontend/app/block/durable-session-flyover.tsx +++ b/frontend/app/block/durable-session-flyover.tsx @@ -1,8 +1,9 @@ // Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import { getApi, getConnStatusAtom, recordTEvent, WOS } from "@/app/store/global"; +import { recordTEvent } from "@/app/store/global"; import { TermViewModel } from "@/app/view/term/term-model"; +import { useWaveEnv } from "@/app/waveenv/waveenv"; import * as util from "@/util/util"; import { cn } from "@/util/util"; import { @@ -18,18 +19,19 @@ import { } from "@floating-ui/react"; import * as jotai from "jotai"; import { useEffect, useRef, useState } from "react"; +import { BlockEnv } from "./blockenv"; function isTermViewModel(viewModel: ViewModel): viewModel is TermViewModel { return viewModel?.viewType === "term"; } -function handleLearnMore() { - getApi().openExternal("https://docs.waveterm.dev/durable-sessions"); -} - function LearnMoreButton() { + const waveEnv = useWaveEnv(); return ( - ); @@ -194,7 +196,7 @@ function DurableEndedContent({ doneReason, startupError, viewModel, onClose }: D let titleText = "Durable Session (Ended)"; let descriptionText = "The durable session has ended. This block is still configured for durable sessions."; - let showRestartButton = true; + const showRestartButton = true; if (doneReason === "terminated") { titleText = "Durable Session (Ended, Exited)"; @@ -333,11 +335,11 @@ export function DurableSessionFlyover({ placement = "bottom", divClassName, }: DurableSessionFlyoverProps) { - const [blockData] = WOS.useWaveObjectValue(WOS.makeORef("block", blockId)); + const waveEnv = useWaveEnv(); + const connName = jotai.useAtomValue(waveEnv.getBlockMetaKeyAtom(blockId, "connection")); const termDurableStatus = util.useAtomValueSafe(viewModel?.termDurableStatus); const termConfigedDurable = util.useAtomValueSafe(viewModel?.termConfigedDurable); - const connName = blockData?.meta?.connection; - const connStatus = jotai.useAtomValue(getConnStatusAtom(connName)); + const connStatus = jotai.useAtomValue(waveEnv.getConnStatusAtom(connName)); const { color: durableIconColor, iconType: durableIconType } = getIconProps( termDurableStatus, diff --git a/frontend/app/element/search.tsx b/frontend/app/element/search.tsx index 031bcd97d..e09e8a107 100644 --- a/frontend/app/element/search.tsx +++ b/frontend/app/element/search.tsx @@ -26,6 +26,7 @@ const SearchComponent = ({ caseSensitive: caseSensitiveAtom, wholeWord: wholeWordAtom, isOpen: isOpenAtom, + focusInput: focusInputAtom, anchorRef, offsetX = 10, offsetY = 10, @@ -37,6 +38,8 @@ const SearchComponent = ({ const [search, setSearch] = useAtom(searchAtom); const [index, setIndex] = useAtom(indexAtom); const [numResults, setNumResults] = useAtom(numResultsAtom); + const [focusInputCounter, setFocusInputCounter] = useAtom(focusInputAtom); + const inputRef = useRef(null); const handleOpenChange = useCallback((open: boolean) => { setIsOpen(open); @@ -47,6 +50,7 @@ const SearchComponent = ({ setSearch(""); setIndex(0); setNumResults(0); + setFocusInputCounter(0); } }, [isOpen]); @@ -56,6 +60,15 @@ const SearchComponent = ({ onSearch?.(search); }, [search]); + // When activateSearch fires while already open, it increments focusInputCounter + // to signal this specific instance to grab focus (avoids global DOM queries). + useEffect(() => { + if (focusInputCounter > 0 && isOpen) { + inputRef.current?.focus(); + inputRef.current?.select(); + } + }, [focusInputCounter]); + const middleware: Middleware[] = []; const offsetCallback = useCallback( ({ rects }) => { @@ -146,6 +159,7 @@ const SearchComponent = ({
{text} diff --git a/frontend/app/modals/about.tsx b/frontend/app/modals/about.tsx index 51a54d3c8..08c0e2210 100644 --- a/frontend/app/modals/about.tsx +++ b/frontend/app/modals/about.tsx @@ -1,13 +1,16 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import Logo from "@/app/asset/logo.svg"; +import { OnboardingGradientBg } from "@/app/onboarding/onboarding-common"; import { modalsModel } from "@/app/store/modalmodel"; -import { Modal } from "./modal"; - +import { RpcApi } from "@/app/store/wshclientapi"; +import { TabRpcClient } from "@/app/store/wshrpcutil"; import { isDev } from "@/util/isdev"; -import { useState } from "react"; +import { fireAndForget } from "@/util/util"; +import { useEffect, useState } from "react"; import { getApi } from "../store/global"; +import { Modal } from "./modal"; interface AboutModalVProps { versionString: string; @@ -19,13 +22,14 @@ const AboutModalV = ({ versionString, updaterChannel, onClose }: AboutModalVProp const currentDate = new Date(); return ( - -
+ + +
Wave Terminal
- Open-Source AI-Native Terminal + Open-Source AI-Integrated Terminal
Built for Seamless Workflows
@@ -35,20 +39,20 @@ const AboutModalV = ({ versionString, updaterChannel, onClose }: AboutModalVProp
Update Channel: {updaterChannel}
-
+
- Github + GitHub Website @@ -56,9 +60,17 @@ const AboutModalV = ({ versionString, updaterChannel, onClose }: AboutModalVProp href="https://github.com/wavetermdev/waveterm/blob/main/ACKNOWLEDGEMENTS.md" target="_blank" rel="noopener" - className="inline-flex items-center px-4 py-2 rounded border border-border hover:bg-hoverbg transition-colors duration-200" + className="inline-flex items-center justify-center px-4 py-2 rounded border border-border hover:bg-hoverbg transition-colors duration-200" > - Acknowledgements + Open Source + + + Sponsor
@@ -76,6 +88,16 @@ const AboutModal = () => { const [updaterChannel] = useState(() => getApi().getUpdaterChannel()); const versionString = `${details.version} (${isDev() ? "dev-" : ""}${details.buildTime})`; + useEffect(() => { + fireAndForget(async () => { + RpcApi.RecordTEventCommand( + TabRpcClient, + { event: "action:other", props: { "action:type": "about" } }, + { noresponse: true } + ); + }); + }, []); + return ( { const hidden = connectionsConfig?.[conn]?.["display:hidden"] ?? false; const wshEnabled = connectionsConfig?.[conn]?.["conn:wshenabled"] ?? true; + const moshEnabled = connectionsConfig?.[conn]?.["conn:moshenabled"] ?? false; return conn.includes(connSelected) && !hidden && (wshEnabled || !filterOutNowsh); }); } diff --git a/frontend/app/modals/modalregistry.tsx b/frontend/app/modals/modalregistry.tsx index 53fabde06..88d19e732 100644 --- a/frontend/app/modals/modalregistry.tsx +++ b/frontend/app/modals/modalregistry.tsx @@ -4,6 +4,7 @@ import { MessageModal } from "@/app/modals/messagemodal"; import { NewInstallOnboardingModal } from "@/app/onboarding/onboarding"; import { UpgradeOnboardingModal } from "@/app/onboarding/onboarding-upgrade"; +import { UpgradeOnboardingPatch } from "@/app/onboarding/onboarding-upgrade-patch"; import { DeleteFileModal, PublishAppModal, RenameFileModal } from "@/builder/builder-apppanel"; import { SetSecretDialog } from "@/builder/tabs/builder-secrettab"; import { AboutModal } from "./about"; @@ -12,6 +13,7 @@ import { UserInputModal } from "./userinputmodal"; const modalRegistry: { [key: string]: React.ComponentType } = { [NewInstallOnboardingModal.displayName || "NewInstallOnboardingModal"]: NewInstallOnboardingModal, [UpgradeOnboardingModal.displayName || "UpgradeOnboardingModal"]: UpgradeOnboardingModal, + [UpgradeOnboardingPatch.displayName || "UpgradeOnboardingPatch"]: UpgradeOnboardingPatch, [UserInputModal.displayName || "UserInputModal"]: UserInputModal, [AboutModal.displayName || "AboutModal"]: AboutModal, [MessageModal.displayName || "MessageModal"]: MessageModal, diff --git a/frontend/app/modals/userinputmodal.tsx b/frontend/app/modals/userinputmodal.tsx index fc97a185e..a04518591 100644 --- a/frontend/app/modals/userinputmodal.tsx +++ b/frontend/app/modals/userinputmodal.tsx @@ -13,6 +13,7 @@ const UserInputModal = (userInputRequest: UserInputRequest) => { const [responseText, setResponseText] = useState(""); const [countdown, setCountdown] = useState(Math.floor(userInputRequest.timeoutms / 1000)); const checkboxRef = useRef(null); + const [capsLockOn, setCapsLockOn] = useState(false); const handleSendErrResponse = useCallback(() => { fireAndForget(() => @@ -73,11 +74,15 @@ const UserInputModal = (userInputRequest: UserInputRequest) => { handleSubmit(); return true; } - return false; + return false; }, [handleSendErrResponse, handleSubmit] ); + const handleCapsLockCheck = useCallback((e: React.KeyboardEvent) => { + setCapsLockOn(e.getModifierState("CapsLock") ?? false); + }, []); + const queryText = useMemo(() => { if (userInputRequest.markdown) { return ; @@ -97,10 +102,21 @@ const UserInputModal = (userInputRequest: UserInputRequest) => { maxLength={400} className="resize-none bg-panel rounded-md border border-border py-1.5 pl-4 min-h-[30px] text-inherit cursor-text focus:ring-2 focus:ring-accent focus:outline-none" autoFocus={true} - onKeyDown={(e) => keyutil.keydownWrapper(handleKeyDown)(e)} + onKeyDown={(e) => { + handleCapsLockCheck(e); + keyutil.keydownWrapper(handleKeyDown)(e); + }} + onKeyUp={handleCapsLockCheck} /> ); - }, [userInputRequest.responsetype, userInputRequest.publictext, responseText, handleKeyDown, setResponseText]); + }, [ + userInputRequest.responsetype, + userInputRequest.publictext, + responseText, + handleKeyDown, + setResponseText, + handleCapsLockCheck, + ]); const optionalCheckbox = useMemo(() => { if (userInputRequest.checkboxmsg == "") { @@ -115,7 +131,9 @@ const UserInputModal = (userInputRequest: UserInputRequest) => { className="accent-accent cursor-pointer" ref={checkboxRef} /> - +
); @@ -159,6 +177,9 @@ const UserInputModal = (userInputRequest: UserInputRequest) => {
{queryText} {inputBox} + {!userInputRequest.publictext && capsLockOn && ( +
Caps Lock is ON
+ )} {optionalCheckbox}
diff --git a/frontend/app/monaco/monaco-react.tsx b/frontend/app/monaco/monaco-react.tsx index c627c9430..ea295b185 100644 --- a/frontend/app/monaco/monaco-react.tsx +++ b/frontend/app/monaco/monaco-react.tsx @@ -56,6 +56,7 @@ export function MonacoCodeEditor({ text, readonly, language, onChange, onMount, return () => { sub.dispose(); if (onUnmountRef.current) onUnmountRef.current(); + editor.setModel(null); editor.dispose(); model.dispose(); console.log("[monaco] dispose model"); @@ -146,6 +147,7 @@ export function MonacoDiffViewer({ original, modified, language, path, options } diff.setModel({ original: originalModel, modified: modifiedModel }); return () => { + diff.setModel(null); diff.dispose(); originalModel.dispose(); modifiedModel.dispose(); diff --git a/frontend/app/onboarding/onboarding-common.tsx b/frontend/app/onboarding/onboarding-common.tsx index b91bf81fa..60711746e 100644 --- a/frontend/app/onboarding/onboarding-common.tsx +++ b/frontend/app/onboarding/onboarding-common.tsx @@ -1,4 +1,10 @@ // Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -export const CurrentOnboardingVersion = "v0.14.0"; +export const CurrentOnboardingVersion = "v0.14.3"; + +export function OnboardingGradientBg() { + return ( +
+ ); +} diff --git a/frontend/app/onboarding/onboarding-features.tsx b/frontend/app/onboarding/onboarding-features.tsx index 595a69938..b47bbc4e1 100644 --- a/frontend/app/onboarding/onboarding-features.tsx +++ b/frontend/app/onboarding/onboarding-features.tsx @@ -19,7 +19,7 @@ import { FakeLayout } from "./onboarding-layout"; type FeaturePageName = "waveai" | "durable" | "magnify" | "files"; -const WaveAIPage = ({ onNext, onSkip }: { onNext: () => void; onSkip: () => void }) => { +export const WaveAIPage = ({ onNext, onSkip }: { onNext: () => void; onSkip: () => void }) => { const isMac = isMacOS(); const shortcutKey = isMac ? "⌘-Shift-A" : "Alt-Shift-A"; const [fireClicked, setFireClicked] = useState(false); @@ -106,7 +106,7 @@ const WaveAIPage = ({ onNext, onSkip }: { onNext: () => void; onSkip: () => void ); }; -const MagnifyBlocksPage = ({ +export const MagnifyBlocksPage = ({ onNext, onSkip, onPrev, @@ -149,13 +149,13 @@ const MagnifyBlocksPage = ({ better view.

Use the magnify feature to work with complex outputs and large files more efficiently.

-

+

You can also magnify a block by clicking on the{" "} {" "} icon in the block header. -

+

A quick {shortcutKey}-M to magnify and another {shortcutKey}-M to unmagnify

@@ -172,11 +172,10 @@ const MagnifyBlocksPage = ({ ); }; -const FilesPage = ({ onFinish, onPrev }: { onFinish: () => void; onPrev?: () => void }) => { +export const FilesPage = ({ onFinish, onPrev }: { onFinish: () => void; onPrev?: () => void }) => { const [fireClicked, setFireClicked] = useState(false); const isMac = isMacOS(); const [commandIndex, setCommandIndex] = useState(0); - const [key, setKey] = useState(0); const handleFireClick = () => { setFireClicked(!fireClicked); @@ -200,7 +199,6 @@ const FilesPage = ({ onFinish, onPrev }: { onFinish: () => void; onPrev?: () => const handleCommandComplete = () => { setTimeout(() => { setCommandIndex((prev) => (prev + 1) % commands.length); - setKey((prev) => prev + 1); }, 2500); }; diff --git a/frontend/app/onboarding/onboarding-starask.tsx b/frontend/app/onboarding/onboarding-starask.tsx new file mode 100644 index 000000000..bb7678ab2 --- /dev/null +++ b/frontend/app/onboarding/onboarding-starask.tsx @@ -0,0 +1,122 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import Logo from "@/app/asset/logo.svg"; +import { Button } from "@/app/element/button"; +import { ClientModel } from "@/app/store/client-model"; +import * as WOS from "@/app/store/wos"; +import { RpcApi } from "@/app/store/wshclientapi"; +import { TabRpcClient } from "@/app/store/wshrpcutil"; + +type StarAskPageProps = { + onClose: () => void; + page?: string; +}; + +export function StarAskPage({ onClose, page = "upgrade" }: StarAskPageProps) { + const handleStarClick = async () => { + RpcApi.RecordTEventCommand( + TabRpcClient, + { + event: "onboarding:githubstar", + props: { "onboarding:githubstar": "star", "onboarding:page": page }, + }, + { noresponse: true } + ); + const clientId = ClientModel.getInstance().clientId; + await RpcApi.SetMetaCommand(TabRpcClient, { + oref: WOS.makeORef("client", clientId), + meta: { "onboarding:githubstar": true }, + }); + window.open(`https://github.com/wavetermdev/waveterm?ref=${page}`, "_blank"); + onClose(); + }; + + const handleAlreadyStarred = async () => { + RpcApi.RecordTEventCommand( + TabRpcClient, + { + event: "onboarding:githubstar", + props: { "onboarding:githubstar": "already", "onboarding:page": page }, + }, + { noresponse: true } + ); + const clientId = ClientModel.getInstance().clientId; + await RpcApi.SetMetaCommand(TabRpcClient, { + oref: WOS.makeORef("client", clientId), + meta: { "onboarding:githubstar": true }, + }); + onClose(); + }; + + const handleRepoLinkClick = () => { + RpcApi.RecordTEventCommand( + TabRpcClient, + { + event: "action:link", + props: { "action:type": "githubrepo", "onboarding:page": page }, + }, + { noresponse: true } + ); + window.open("https://github.com/wavetermdev/waveterm", "_blank"); + }; + + const handleMaybeLater = async () => { + RpcApi.RecordTEventCommand( + TabRpcClient, + { + event: "onboarding:githubstar", + props: { "onboarding:githubstar": "later", "onboarding:page": page }, + }, + { noresponse: true } + ); + const clientId = ClientModel.getInstance().clientId; + await RpcApi.SetMetaCommand(TabRpcClient, { + oref: WOS.makeORef("client", clientId), + meta: { "onboarding:githubstar": false }, + }); + onClose(); + }; + + return ( +
+
+
+ +
+
Support open-source. Star Wave. ⭐
+
+
+
+
+ Wave is free, open-source, and open-model. Stars help us stay visible against closed + alternatives. One click makes a difference. +
+
+ + + wavetermdev/waveterm + +
+
+
+
+
+ + + +
+
+
+ ); +} + diff --git a/frontend/app/onboarding/onboarding-upgrade-minor.tsx b/frontend/app/onboarding/onboarding-upgrade-minor.tsx index 58d80b564..b165c0ce7 100644 --- a/frontend/app/onboarding/onboarding-upgrade-minor.tsx +++ b/frontend/app/onboarding/onboarding-upgrade-minor.tsx @@ -1,10 +1,10 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import Logo from "@/app/asset/logo.svg"; import { Button } from "@/app/element/button"; import { FlexiModal } from "@/app/modals/modal"; -import { CurrentOnboardingVersion } from "@/app/onboarding/onboarding-common"; +import { CurrentOnboardingVersion, OnboardingGradientBg } from "@/app/onboarding/onboarding-common"; import { OnboardingFeatures } from "@/app/onboarding/onboarding-features"; import { ClientModel } from "@/app/store/client-model"; import { globalStore } from "@/app/store/global"; @@ -17,6 +17,84 @@ import { OverlayScrollbarsComponent } from "overlayscrollbars-react"; import { useEffect, useRef, useState } from "react"; import { debounce } from "throttle-debounce"; +type UpgradeMinorWelcomePageProps = { + onStarClick: () => void; + onAlreadyStarred: () => void; + onMaybeLater: () => void; +}; + +const UpgradeMinorWelcomePage = ({ onStarClick, onAlreadyStarred, onMaybeLater }: UpgradeMinorWelcomePageProps) => { + return ( +
+
+
+ +
+
Welcome to Wave v0.14!
+
+ +
+
+
+
+ + Wave AI +
+
+ + Durable SSH Sessions +
+
+
+

+ Wave AI is your terminal assistant with full context. It can read your terminal output, + analyze widgets, read and write files, and help you solve problems faster. +

+

+ New in v0.13: Wave AI now + supports local models and bring-your-own-key! Use Ollama, LM Studio, vLLM, OpenRouter, + or any OpenAI-compatible provider. +

+

+ New in v0.14: Durable SSH + sessions survive network drops, laptop sleep, and restarts — all without tmux or screen. +

+
+
+ +
+ +
+
Thanks for being an early Wave adopter! ⭐
+
+ A GitHub star shows your support for Wave (and open-source) and helps us reach more + developers. +
+
+
+
+
+
+ + + +
+
+
+ ); +}; + +UpgradeMinorWelcomePage.displayName = "UpgradeMinorWelcomePage"; + const UpgradeOnboardingMinor = () => { const modalRef = useRef(null); const [pageName, setPageName] = useState<"welcome" | "features">("welcome"); @@ -57,7 +135,7 @@ const UpgradeOnboardingMinor = () => { TabRpcClient, { event: "onboarding:githubstar", - props: { "onboarding:githubstar": "star" }, + props: { "onboarding:githubstar": "star", "onboarding:page": "minorupgrade" }, }, { noresponse: true } ); @@ -75,7 +153,7 @@ const UpgradeOnboardingMinor = () => { TabRpcClient, { event: "onboarding:githubstar", - props: { "onboarding:githubstar": "already" }, + props: { "onboarding:githubstar": "already", "onboarding:page": "minorupgrade" }, }, { noresponse: true } ); @@ -92,7 +170,7 @@ const UpgradeOnboardingMinor = () => { TabRpcClient, { event: "onboarding:githubstar", - props: { "onboarding:githubstar": "later" }, + props: { "onboarding:githubstar": "later", "onboarding:page": "minorupgrade" }, }, { noresponse: true } ); @@ -119,73 +197,11 @@ const UpgradeOnboardingMinor = () => { let pageComp: React.JSX.Element = null; if (pageName === "welcome") { pageComp = ( -
-
-
- -
-
Welcome to Wave v0.14!
-
- -
-
-
-
- - Wave AI -
-
- - Durable SSH Sessions -
-
-
-

- Wave AI is your terminal assistant with full context. It can read your terminal - output, analyze widgets, read and write files, and help you solve - problems faster. -

-

- New in v0.13: Wave AI now - supports local models and bring-your-own-key! Use Ollama, LM Studio, vLLM, - OpenRouter, or any OpenAI-compatible provider. -

-

- New in v0.14: Durable SSH - sessions survive network drops, laptop sleep, and restarts — all without tmux or - screen. -

-
-
- -
- -
-
Thanks for being an early Wave adopter! ⭐
-
- A GitHub star shows your support for Wave (and open-source) and helps us reach more - developers. -
-
-
-
-
-
- - - -
-
-
+ ); } else if (pageName === "features") { pageComp = ; @@ -200,7 +216,7 @@ const UpgradeOnboardingMinor = () => { return ( -
+
{pageComp}
); @@ -208,4 +224,4 @@ const UpgradeOnboardingMinor = () => { UpgradeOnboardingMinor.displayName = "UpgradeOnboardingMinor"; -export { UpgradeOnboardingMinor }; +export { UpgradeMinorWelcomePage, UpgradeOnboardingMinor }; diff --git a/frontend/app/onboarding/onboarding-upgrade-patch.tsx b/frontend/app/onboarding/onboarding-upgrade-patch.tsx index fc2a0ee3a..0eded88f1 100644 --- a/frontend/app/onboarding/onboarding-upgrade-patch.tsx +++ b/frontend/app/onboarding/onboarding-upgrade-patch.tsx @@ -4,7 +4,8 @@ import Logo from "@/app/asset/logo.svg"; import { Button } from "@/app/element/button"; import { FlexiModal } from "@/app/modals/modal"; -import { CurrentOnboardingVersion } from "@/app/onboarding/onboarding-common"; +import { CurrentOnboardingVersion, OnboardingGradientBg } from "@/app/onboarding/onboarding-common"; +import { StarAskPage } from "@/app/onboarding/onboarding-starask"; import { ClientModel } from "@/app/store/client-model"; import { globalStore } from "@/app/store/global"; import { disableGlobalKeybindings, enableGlobalKeybindings, globalRefocus } from "@/app/store/keymodel"; @@ -12,6 +13,7 @@ import { modalsModel } from "@/app/store/modalmodel"; import * as WOS from "@/app/store/wos"; import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; +import { useAtomValue } from "jotai"; import { OverlayScrollbarsComponent } from "overlayscrollbars-react"; import { useEffect, useRef, useState } from "react"; import { debounce } from "throttle-debounce"; @@ -21,6 +23,8 @@ import { UpgradeOnboardingModal_v0_12_3_Content } from "./onboarding-upgrade-v01 import { UpgradeOnboardingModal_v0_13_0_Content } from "./onboarding-upgrade-v0130"; import { UpgradeOnboardingModal_v0_13_1_Content } from "./onboarding-upgrade-v0131"; import { UpgradeOnboardingModal_v0_14_0_Content } from "./onboarding-upgrade-v0140"; +import { UpgradeOnboardingModal_v0_14_1_Content } from "./onboarding-upgrade-v0141"; +import { UpgradeOnboardingModal_v0_14_2_Content } from "./onboarding-upgrade-v0142"; interface VersionConfig { version: string; @@ -29,7 +33,67 @@ interface VersionConfig { nextText?: string; } -const versions: VersionConfig[] = [ +interface UpgradeOnboardingPatchProps { + isReleaseNotes?: boolean; +} + +interface UpgradeOnboardingFooterProps { + hasPrev: boolean; + hasNext: boolean; + prevText?: string; + nextText?: string; + onPrev?: () => void; + onNext?: () => void; + onClose: () => void; +} + +export function UpgradeOnboardingFooter({ + hasPrev, + hasNext, + prevText, + nextText, + onPrev, + onNext, + onClose, +}: UpgradeOnboardingFooterProps) { + return ( +
+
+
+ {hasPrev && ( +
+ +
+ )} +
+
+ +
+
+ {hasNext && ( +
+ +
+ )} +
+
+
+ ); +} + +export const UpgradeOnboardingVersions: VersionConfig[] = [ { version: "v0.12.1", content: () => , @@ -63,17 +127,32 @@ const versions: VersionConfig[] = [ version: "v0.14.0", content: () => , prevText: "Prev (v0.13.1)", + nextText: "Next (v0.14.1)", + }, + { + version: "v0.14.1", + content: () => , + prevText: "Prev (v0.14.0)", + nextText: "Next (v0.14.3)", + }, + { + version: "v0.14.3", + content: () => , + prevText: "Prev (v0.14.1)", }, ]; -const UpgradeOnboardingPatch = () => { +const UpgradeOnboardingPatch = ({ isReleaseNotes = false }: UpgradeOnboardingPatchProps) => { const modalRef = useRef(null); const [isCompact, setIsCompact] = useState(window.innerHeight < 800); - const [currentIndex, setCurrentIndex] = useState(versions.length - 1); + const [currentIndex, setCurrentIndex] = useState(UpgradeOnboardingVersions.length - 1); + const [showStarAsk, setShowStarAsk] = useState(false); + const clientData = useAtomValue(ClientModel.getInstance().clientAtom); + const alreadyStarred = clientData?.meta?.["onboarding:githubstar"] === true; - const currentVersion = versions[currentIndex]; + const currentVersion = UpgradeOnboardingVersions[currentIndex]; const hasPrev = currentIndex > 0; - const hasNext = currentIndex < versions.length - 1; + const hasNext = currentIndex < UpgradeOnboardingVersions.length - 1; const updateModalHeight = () => { const windowHeight = window.innerHeight; @@ -105,16 +184,32 @@ const UpgradeOnboardingPatch = () => { }; }, []); + const doClose = () => { + if (isReleaseNotes) { + modalsModel.popModal(); + } else { + globalStore.set(modalsModel.upgradeOnboardingOpen, false); + } + setTimeout(() => { + globalRefocus(); + }, 10); + }; + const handleClose = () => { + if (isReleaseNotes) { + doClose(); + return; + } const clientId = ClientModel.getInstance().clientId; RpcApi.SetMetaCommand(TabRpcClient, { oref: WOS.makeORef("client", clientId), meta: { "onboarding:lastversion": CurrentOnboardingVersion }, }); - globalStore.set(modalsModel.upgradeOnboardingOpen, false); - setTimeout(() => { - globalRefocus(); - }, 10); + if (alreadyStarred) { + doClose(); + } else { + setShowStarAsk(true); + } }; const paddingClass = isCompact ? "!py-3 !px-[30px]" : "!p-[30px]"; @@ -131,9 +226,23 @@ const UpgradeOnboardingPatch = () => { } }; + if (showStarAsk) { + return ( + + +
+ +
+
+ ); + } + return ( -
+
@@ -150,39 +259,15 @@ const UpgradeOnboardingPatch = () => { > {currentVersion.content()} -
-
-
- {hasPrev && ( -
- -
- )} -
-
- -
-
- {hasNext && ( -
- -
- )} -
-
-
+
diff --git a/frontend/app/onboarding/onboarding-upgrade-v0140.tsx b/frontend/app/onboarding/onboarding-upgrade-v0140.tsx index d2b7b1821..0102b691e 100644 --- a/frontend/app/onboarding/onboarding-upgrade-v0140.tsx +++ b/frontend/app/onboarding/onboarding-upgrade-v0140.tsx @@ -1,9 +1,10 @@ // Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import { getApi } from "@/app/store/global"; +import { useWaveEnv } from "@/app/waveenv/waveenv"; const UpgradeOnboardingModal_v0_14_0_Content = () => { + const waveEnv = useWaveEnv(); return (
@@ -22,7 +23,7 @@ const UpgradeOnboardingModal_v0_14_0_Content = () => {
Durable SSH Sessions{" "} + + +
+
+
+ +
+
+ +
+
+
Other Changes
+
+
    +
  • + [v0.14.3] [bugfix] Fixed a showstopper onboarding bug +
  • +
  • + Directory Preview - Improved mod time formatting, zebra-striped rows, + better default sort, and YAML file support +
  • +
  • + Search Bar - Clipboard and focus improvements +
  • +
  • [bugfix] Fixed "New Window" hanging on GNOME desktops
  • +
  • [bugfix] Fixed "Save Session As..." focused window tracking bug
  • +
+
+
+
+
+ ); +}; + +UpgradeOnboardingModal_v0_14_2_Content.displayName = "UpgradeOnboardingModal_v0_14_2_Content"; + +export { UpgradeOnboardingModal_v0_14_2_Content }; diff --git a/frontend/app/onboarding/onboarding-upgrade.tsx b/frontend/app/onboarding/onboarding-upgrade.tsx index 11a94ead7..7ab60878c 100644 --- a/frontend/app/onboarding/onboarding-upgrade.tsx +++ b/frontend/app/onboarding/onboarding-upgrade.tsx @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { ClientModel } from "@/app/store/client-model"; -import { atoms, globalStore } from "@/app/store/global"; +import { globalStore } from "@/app/store/global"; import { modalsModel } from "@/app/store/modalmodel"; import { useAtomValue } from "jotai"; import { useEffect, useRef } from "react"; diff --git a/frontend/app/onboarding/onboarding.tsx b/frontend/app/onboarding/onboarding.tsx index fc4c566ae..ba139e81d 100644 --- a/frontend/app/onboarding/onboarding.tsx +++ b/frontend/app/onboarding/onboarding.tsx @@ -1,12 +1,13 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import Logo from "@/app/asset/logo.svg"; import { Button } from "@/app/element/button"; import { FlexiModal } from "@/app/modals/modal"; +import { OnboardingGradientBg } from "@/app/onboarding/onboarding-common"; import { OnboardingFeatures } from "@/app/onboarding/onboarding-features"; import { ClientModel } from "@/app/store/client-model"; -import { atoms } from "@/app/store/global"; +import { useSettingsKeyAtom } from "@/app/store/global"; import { disableGlobalKeybindings, enableGlobalKeybindings, globalRefocus } from "@/app/store/keymodel"; import { modalsModel } from "@/app/store/modalmodel"; import * as WOS from "@/app/store/wos"; @@ -28,15 +29,37 @@ type PageName = "init" | "notelemetrystar" | "features"; const pageNameAtom: PrimitiveAtom = atom("init"); -const InitPage = ({ isCompact }: { isCompact: boolean }) => { - const settings = useAtomValue(atoms.settingsAtom); +const InitPage = ({ + isCompact, + telemetryUpdateFn, +}: { + isCompact: boolean; + telemetryUpdateFn: (value: boolean) => Promise; +}) => { + const telemetrySetting = useSettingsKeyAtom("telemetry:enabled"); const clientData = useAtomValue(ClientModel.getInstance().clientAtom); - const [telemetryEnabled, setTelemetryEnabled] = useState(!!settings["telemetry:enabled"]); + const [telemetryEnabled, setTelemetryEnabled] = useState(!!telemetrySetting); const setPageName = useSetAtom(pageNameAtom); + const handleStarClick = async () => { + RpcApi.RecordTEventCommand( + TabRpcClient, + { + event: "onboarding:githubstar", + props: { "onboarding:githubstar": "star", "onboarding:page": "init" }, + }, + { noresponse: true } + ); + const clientId = ClientModel.getInstance().clientId; + await RpcApi.SetMetaCommand(TabRpcClient, { + oref: WOS.makeORef("client", clientId), + meta: { "onboarding:githubstar": true }, + }); + }; + const acceptTos = () => { - if (!clientData.tosagreed) { - fireAndForget(services.ClientService.AgreeTos); + if (!clientData?.tosagreed) { + fireAndForget(() => services.ClientService.AgreeTos()); } if (telemetryEnabled) { WorkspaceLayoutModel.getInstance().setAIPanelVisible(true); @@ -46,7 +69,7 @@ const InitPage = ({ isCompact }: { isCompact: boolean }) => { const setTelemetry = (value: boolean) => { fireAndForget(() => - services.ClientService.TelemetryUpdate(value).then(() => { + telemetryUpdateFn(value).then(() => { setTelemetryEnabled(value); }) ); @@ -76,6 +99,7 @@ const InitPage = ({ isCompact }: { isCompact: boolean }) => { href="https://github.com/wavetermdev/waveterm?ref=install" rel="noopener" className="text-accent" + onClick={handleStarClick} > @@ -83,13 +107,14 @@ const InitPage = ({ isCompact }: { isCompact: boolean }) => {
Support us on GitHub
- We're open source and committed to providing a free terminal for individual - users. Please show your support by giving us a star on{" "} + We're open source, open-model, and committed to providing a free terminal + for individual users. Please show your support by giving us a star on{" "} Github (wavetermdev/waveterm) @@ -169,6 +194,14 @@ const NoTelemetryStarPage = ({ isCompact }: { isCompact: boolean }) => { const setPageName = useSetAtom(pageNameAtom); const handleStarClick = async () => { + RpcApi.RecordTEventCommand( + TabRpcClient, + { + event: "onboarding:githubstar", + props: { "onboarding:githubstar": "star", "onboarding:page": "notelemetry" }, + }, + { noresponse: true } + ); const clientId = ClientModel.getInstance().clientId; await RpcApi.SetMetaCommand(TabRpcClient, { oref: WOS.makeORef("client", clientId), @@ -179,6 +212,14 @@ const NoTelemetryStarPage = ({ isCompact }: { isCompact: boolean }) => { }; const handleMaybeLater = async () => { + RpcApi.RecordTEventCommand( + TabRpcClient, + { + event: "onboarding:githubstar", + props: { "onboarding:githubstar": "later", "onboarding:page": "notelemetry" }, + }, + { noresponse: true } + ); const clientId = ClientModel.getInstance().clientId; await RpcApi.SetMetaCommand(TabRpcClient, { oref: WOS.makeORef("client", clientId), @@ -284,7 +325,7 @@ const NewInstallOnboardingModal = () => { let pageComp: React.JSX.Element = null; switch (pageName) { case "init": - pageComp = ; + pageComp = services.ClientService.TelemetryUpdate(value)} />; break; case "notelemetrystar": pageComp = ; @@ -302,7 +343,7 @@ const NewInstallOnboardingModal = () => { return ( -
+
{pageComp}
); @@ -310,4 +351,4 @@ const NewInstallOnboardingModal = () => { NewInstallOnboardingModal.displayName = "NewInstallOnboardingModal"; -export { NewInstallOnboardingModal }; +export { InitPage, NewInstallOnboardingModal, NoTelemetryStarPage }; diff --git a/frontend/app/store/badge.ts b/frontend/app/store/badge.ts new file mode 100644 index 000000000..745a2eb4d --- /dev/null +++ b/frontend/app/store/badge.ts @@ -0,0 +1,267 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { RpcApi } from "@/app/store/wshclientapi"; +import { TabRpcClient } from "@/app/store/wshrpcutil"; +import { WaveEnv, WaveEnvSubset } from "@/app/waveenv/waveenv"; +import { fireAndForget, NullAtom } from "@/util/util"; +import { atom, Atom, PrimitiveAtom } from "jotai"; +import { v7 as uuidv7, version as uuidVersion } from "uuid"; +import { globalStore } from "./jotaiStore"; +import * as WOS from "./wos"; +import { waveEventSubscribeSingle } from "./wps"; + +export type BadgeEnv = WaveEnvSubset<{ + rpc: { + EventPublishCommand: WaveEnv["rpc"]["EventPublishCommand"]; + }; +}>; + +export type LoadBadgesEnv = WaveEnvSubset<{ + rpc: { + GetAllBadgesCommand: WaveEnv["rpc"]["GetAllBadgesCommand"]; + }; +}>; + +export type TabBadgesEnv = WaveEnvSubset<{ + wos: WaveEnv["wos"]; +}>; + +const BadgeMap = new Map>(); +const TabBadgeAtomCache = new Map>(); + +function publishBadgeEvent(eventData: WaveEvent, env?: BadgeEnv) { + if (env != null) { + fireAndForget(() => env.rpc.EventPublishCommand(TabRpcClient, eventData)); + } else { + fireAndForget(() => RpcApi.EventPublishCommand(TabRpcClient, eventData)); + } +} + +function clearBadgeInternal(oref: string, env?: BadgeEnv) { + const eventData: WaveEvent = { + event: "badge", + scopes: [oref], + data: { + oref: oref, + clear: true, + } as BadgeEvent, + }; + publishBadgeEvent(eventData, env); +} + +function clearBadgesForBlockOnFocus(blockId: string, env?: BadgeEnv) { + const oref = WOS.makeORef("block", blockId); + const badgeAtom = BadgeMap.get(oref); + const badge = badgeAtom != null ? globalStore.get(badgeAtom) : null; + if (badge != null && !badge.pidlinked) { + clearBadgeInternal(oref, env); + } +} + +function clearBadgesForTabOnFocus(tabId: string, env?: BadgeEnv) { + const oref = WOS.makeORef("tab", tabId); + const badgeAtom = BadgeMap.get(oref); + const badge = badgeAtom != null ? globalStore.get(badgeAtom) : null; + if (badge != null && !badge.pidlinked) { + clearBadgeInternal(oref, env); + } +} + +function clearAllBadges(env?: BadgeEnv) { + const eventData: WaveEvent = { + event: "badge", + scopes: [], + data: { + oref: "", + clearall: true, + } as BadgeEvent, + }; + publishBadgeEvent(eventData, env); +} + +function clearBadgesForTab(tabId: string, env?: BadgeEnv) { + const tabAtom = WOS.getWaveObjectAtom(WOS.makeORef("tab", tabId)); + const tab = globalStore.get(tabAtom); + const blockIds = (tab as Tab)?.blockids ?? []; + for (const blockId of blockIds) { + const oref = WOS.makeORef("block", blockId); + const badgeAtom = BadgeMap.get(oref); + if (badgeAtom != null && globalStore.get(badgeAtom) != null) { + clearBadgeInternal(oref, env); + } + } +} + +function getBadgeAtom(oref: string): PrimitiveAtom { + if (oref == null) { + return NullAtom as PrimitiveAtom; + } + let rtn = BadgeMap.get(oref); + if (rtn == null) { + rtn = atom(null) as PrimitiveAtom; + BadgeMap.set(oref, rtn); + } + return rtn; +} + +function getBlockBadgeAtom(blockId: string): Atom { + if (blockId == null) { + return NullAtom as Atom; + } + const oref = WOS.makeORef("block", blockId); + return getBadgeAtom(oref); +} + +function getTabBadgeAtom(tabId: string, env?: TabBadgesEnv): Atom { + if (tabId == null) { + return NullAtom as Atom; + } + let rtn = TabBadgeAtomCache.get(tabId); + if (rtn != null) { + return rtn; + } + const tabOref = WOS.makeORef("tab", tabId); + const tabBadgeAtom = getBadgeAtom(tabOref); + const tabAtom = env != null ? env.wos.getWaveObjectAtom(tabOref) : WOS.getWaveObjectAtom(tabOref); + rtn = atom((get) => { + const tab = get(tabAtom); + const blockIds = tab?.blockids ?? []; + const badges: Badge[] = []; + for (const blockId of blockIds) { + const badge = get(getBadgeAtom(WOS.makeORef("block", blockId))); + if (badge != null) { + badges.push(badge); + } + } + const tabBadge = get(tabBadgeAtom); + if (tabBadge != null) { + badges.push(tabBadge); + } + return sortBadgesForTab(badges); + }); + TabBadgeAtomCache.set(tabId, rtn); + return rtn; +} + +async function loadBadges(env?: LoadBadgesEnv) { + const rpc = env != null ? env.rpc : RpcApi; + const badges = await rpc.GetAllBadgesCommand(TabRpcClient); + if (badges == null) { + return; + } + for (const badgeEvent of badges) { + if (badgeEvent.oref == null) { + continue; + } + const curAtom = getBadgeAtom(badgeEvent.oref); + globalStore.set(curAtom, badgeEvent.badge ?? null); + } +} + +function setBadge(blockId: string, badge: Omit & { badgeid?: string }, env?: BadgeEnv) { + if (!badge.badgeid) { + badge = { ...badge, badgeid: uuidv7() }; + } else if (uuidVersion(badge.badgeid) !== 7) { + throw new Error(`setBadge: badgeid must be a v7 UUID, got version ${uuidVersion(badge.badgeid)}`); + } + const oref = WOS.makeORef("block", blockId); + const eventData: WaveEvent = { + event: "badge", + scopes: [oref], + data: { + oref: oref, + badge: badge, + } as BadgeEvent, + }; + publishBadgeEvent(eventData, env); +} + +function clearBadgeById(blockId: string, badgeId: string, env?: BadgeEnv) { + const oref = WOS.makeORef("block", blockId); + const eventData: WaveEvent = { + event: "badge", + scopes: [oref], + data: { + oref: oref, + clearbyid: badgeId, + } as BadgeEvent, + }; + publishBadgeEvent(eventData, env); +} + +function setupBadgesSubscription() { + waveEventSubscribeSingle({ + eventType: "badge", + handler: (event) => { + const data = event.data; + if (data?.clearall) { + for (const atom of BadgeMap.values()) { + globalStore.set(atom, null); + } + return; + } + if (data?.oref == null) { + return; + } + const curAtom = getBadgeAtom(data.oref); + if (data.clearbyid) { + const existing = globalStore.get(curAtom); + if (existing?.badgeid === data.clearbyid) { + globalStore.set(curAtom, null); + } + return; + } + if (data.clear) { + globalStore.set(curAtom, null); + return; + } + if (data.badge == null) { + return; + } + const existing = globalStore.get(curAtom); + if (existing == null || cmpBadge(data.badge, existing) > 0) { + globalStore.set(curAtom, data.badge); + } + }, + }); +} + +function cmpBadge(a: Badge, b: Badge): number { + if (a.priority !== b.priority) { + return a.priority > b.priority ? 1 : -1; + } + if (a.badgeid !== b.badgeid) { + return a.badgeid > b.badgeid ? 1 : -1; + } + return 0; +} + +function sortBadges(badges: Badge[]): Badge[] { + return [...badges].sort((a, b) => cmpBadge(b, a)); +} + +function sortBadgesForTab(badges: Badge[]): Badge[] { + return [...badges].sort((a, b) => { + if (a.priority !== b.priority) { + return b.priority - a.priority; + } + return a.badgeid < b.badgeid ? -1 : a.badgeid > b.badgeid ? 1 : 0; + }); +} + +export { + clearAllBadges, + clearBadgeById, + clearBadgesForBlockOnFocus, + clearBadgesForTab, + clearBadgesForTabOnFocus, + getBadgeAtom, + getBlockBadgeAtom, + getTabBadgeAtom, + loadBadges, + setBadge, + setupBadgesSubscription, + sortBadges, + sortBadgesForTab, +}; diff --git a/frontend/app/store/client-model.ts b/frontend/app/store/client-model.ts index 240dc6d03..4ae250f5b 100644 --- a/frontend/app/store/client-model.ts +++ b/frontend/app/store/client-model.ts @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc +// Copyright 2026, Command Line Inc // SPDX-License-Identifier: Apache-2.0 import * as WOS from "@/app/store/wos"; @@ -33,4 +33,4 @@ class ClientModel { } } -export { ClientModel }; \ No newline at end of file +export { ClientModel }; diff --git a/frontend/app/store/contextmenu.ts b/frontend/app/store/contextmenu.ts index 89e72c561..fdad72bd8 100644 --- a/frontend/app/store/contextmenu.ts +++ b/frontend/app/store/contextmenu.ts @@ -74,11 +74,11 @@ class ContextMenuModel { this.activeOpts = opts; const electronMenuItems = this._convertAndRegisterMenu(menu); - const workspace = globalStore.get(atoms.workspace); + const workspaceId = globalStore.get(atoms.workspaceId); let oid: string; - if (workspace != null) { - oid = workspace.oid; + if (workspaceId != null) { + oid = workspaceId; } else { oid = globalStore.get(atoms.builderId); } diff --git a/frontend/app/store/global-atoms.ts b/frontend/app/store/global-atoms.ts index ac36fcec8..01fe12800 100644 --- a/frontend/app/store/global-atoms.ts +++ b/frontend/app/store/global-atoms.ts @@ -9,14 +9,13 @@ import * as WOS from "./wos"; let atoms!: GlobalAtomsType; const blockComponentModelMap = new Map(); const ConnStatusMapAtom = atom(new Map>()); -const TabIndicatorMap = new Map>(); const orefAtomCache = new Map>>(); function initGlobalAtoms(initOpts: GlobalInitOptions) { const windowIdAtom = atom(initOpts.windowId) as PrimitiveAtom; const builderIdAtom = atom(initOpts.builderId) as PrimitiveAtom; const builderAppIdAtom = atom(null) as PrimitiveAtom; - setWaveWindowType(initOpts.builderId != null ? "builder" : "tab"); + setWaveWindowType(initOpts.isPreview ? "preview" : initOpts.builderId != null ? "builder" : "tab"); const uiContextAtom = atom((get) => { const uiContext: UIContext = { windowid: initOpts.windowId, @@ -44,12 +43,16 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) { console.log("failed to initialize zoomFactorAtom", e); } - const workspaceAtom: Atom = atom((get) => { + const workspaceIdAtom: Atom = atom((get) => { const windowData = WOS.getObjectValue(WOS.makeORef("window", get(windowIdAtom)), get); - if (windowData == null) { + return windowData?.workspaceid ?? null; + }); + const workspaceAtom: Atom = atom((get) => { + const workspaceId = get(workspaceIdAtom); + if (workspaceId == null) { return null; } - return WOS.getObjectValue(WOS.makeORef("workspace", windowData.workspaceid), get); + return WOS.getObjectValue(WOS.makeORef("workspace", workspaceId), get); }); const fullConfigAtom = atom(null) as PrimitiveAtom; const waveaiModeConfigAtom = atom(null) as PrimitiveAtom>; @@ -68,6 +71,10 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) { } return false; }) as Atom; + const hasConfigErrors = atom((get) => { + const fullConfig = get(fullConfigAtom); + return fullConfig?.configerrors != null && fullConfig.configerrors.length > 0; + }) as Atom; // this is *the* tab that this tabview represents. it should never change. const staticTabIdAtom: Atom = atom(initOpts.tabId); const controlShiftDelayAtom = atom(false); @@ -124,11 +131,13 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) { builderId: builderIdAtom, builderAppId: builderAppIdAtom, uiContext: uiContextAtom, + workspaceId: workspaceIdAtom, workspace: workspaceAtom, fullConfigAtom, waveaiModeConfigAtom, settingsAtom, hasCustomAIPresetsAtom, + hasConfigErrors, staticTabId: staticTabIdAtom, isFullScreen: isFullScreenAtom, zoomFactorAtom, @@ -154,4 +163,4 @@ function getApi(): ElectronApi { return (window as any).api; } -export { atoms, blockComponentModelMap, ConnStatusMapAtom, getAtoms, initGlobalAtoms, orefAtomCache, TabIndicatorMap }; +export { atoms, blockComponentModelMap, ConnStatusMapAtom, getAtoms, initGlobalAtoms, orefAtomCache }; diff --git a/frontend/app/store/global-model.ts b/frontend/app/store/global-model.ts index 804e3a18f..05e84e377 100644 --- a/frontend/app/store/global-model.ts +++ b/frontend/app/store/global-model.ts @@ -3,14 +3,18 @@ import * as WOS from "@/app/store/wos"; import { ClientModel } from "@/app/store/client-model"; +import { getApi } from "@/store/global"; +import * as util from "@/util/util"; import { atom, Atom } from "jotai"; class GlobalModel { private static instance: GlobalModel; + static readonly IsActiveThrottleMs = 5000; windowId: string; builderId: string; platform: NodeJS.Platform; + lastSetIsActiveTs = 0; windowDataAtom!: Atom; workspaceAtom!: Atom; @@ -47,6 +51,15 @@ class GlobalModel { return WOS.getObjectValue(WOS.makeORef("workspace", windowData.workspaceid), get); }); } + + setIsActive(): void { + const now = Date.now(); + if (now - this.lastSetIsActiveTs < GlobalModel.IsActiveThrottleMs) { + return; + } + this.lastSetIsActiveTs = now; + util.fireAndForget(() => getApi().setIsActive()); + } } -export { GlobalModel }; \ No newline at end of file +export { GlobalModel }; diff --git a/frontend/app/store/global.ts b/frontend/app/store/global.ts index 2cfb5945a..61db89988 100644 --- a/frontend/app/store/global.ts +++ b/frontend/app/store/global.ts @@ -25,27 +25,21 @@ import { isBlank, isLocalConnName, isWslConnName, + NullAtom, } from "@/util/util"; import { atom, Atom, PrimitiveAtom, useAtomValue } from "jotai"; -import { - atoms, - blockComponentModelMap, - ConnStatusMapAtom, - initGlobalAtoms, - orefAtomCache, - TabIndicatorMap, -} from "./global-atoms"; +import { setupBadgesSubscription } from "./badge"; +import { atoms, blockComponentModelMap, ConnStatusMapAtom, initGlobalAtoms, orefAtomCache } from "./global-atoms"; import { globalStore } from "./jotaiStore"; import { modalsModel } from "./modalmodel"; import { ClientService, ObjectService } from "./services"; +import { isPreviewWindow } from "./windowtype"; import * as WOS from "./wos"; import { getFileSubject, waveEventSubscribeSingle } from "./wps"; -let globalEnvironment: "electron" | "renderer"; let globalPrimaryTabStartup: boolean = false; function initGlobal(initOpts: GlobalInitOptions) { - globalEnvironment = initOpts.environment; globalPrimaryTabStartup = initOpts.primaryTabStartup ?? false; setPlatform(initOpts.platform); initGlobalAtoms(initOpts); @@ -103,12 +97,7 @@ function initGlobalWaveEventSubs(initOpts: WaveInitOpts) { globalStore.set(atoms.waveAIRateLimitInfoAtom, event.data); }, }); - waveEventSubscribeSingle({ - eventType: "tab:indicator", - handler: (event) => { - setTabIndicatorInternal(event.data.tabid, event.data.indicator); - }, - }); + setupBadgesSubscription(); } const blockCache = new Map>(); @@ -135,18 +124,14 @@ function getBlockMetaKeyAtom(blockId: string, key: T): return metaAtom; } metaAtom = atom((get) => { - let blockAtom = WOS.getWaveObjectAtom(WOS.makeORef("block", blockId)); - let blockData = get(blockAtom); + const blockAtom = WOS.getWaveObjectAtom(WOS.makeORef("block", blockId)); + const blockData = get(blockAtom); return blockData?.meta?.[key]; }); blockCache.set(metaAtomName, metaAtom); return metaAtom; } -function useBlockMetaKeyAtom(blockId: string, key: T): MetaType[T] { - return useAtomValue(getBlockMetaKeyAtom(blockId, key)); -} - function getOrefMetaKeyAtom(oref: string, key: T): Atom { const orefCache = getSingleOrefAtomCache(oref); const metaAtomName = "#meta-" + key; @@ -155,8 +140,8 @@ function getOrefMetaKeyAtom(oref: string, key: T): Ato return metaAtom; } metaAtom = atom((get) => { - let objAtom = WOS.getWaveObjectAtom(oref); - let objData = get(objAtom); + const objAtom = WOS.getWaveObjectAtom(oref); + const objData = get(objAtom); return objData?.meta?.[key]; }); orefCache.set(metaAtomName, metaAtom); @@ -168,14 +153,15 @@ function useOrefMetaKeyAtom(oref: string, key: T): Met } function getConnConfigKeyAtom(connName: string, key: T): Atom { - let connCache = getSingleConnAtomCache(connName); + if (isPreviewWindow()) return NullAtom as Atom; + const connCache = getSingleConnAtomCache(connName); const keyAtomName = "#conn-" + key; let keyAtom = connCache.get(keyAtomName); if (keyAtom != null) { return keyAtom; } keyAtom = atom((get) => { - let fullConfig = get(atoms.fullConfigAtom); + const fullConfig = get(atoms.fullConfigAtom); return fullConfig.connections?.[connName]?.[key]; }); connCache.set(keyAtomName, keyAtom); @@ -185,6 +171,7 @@ function getConnConfigKeyAtom(connName: string, ke const settingsAtomCache = new Map>(); function getOverrideConfigAtom(blockId: string, key: T): Atom { + if (isPreviewWindow()) return NullAtom as Atom; const blockCache = getSingleBlockAtomCache(blockId); const overrideAtomName = "#settingsoverride-" + key; let overrideAtom = blockCache.get(overrideAtomName); @@ -223,6 +210,7 @@ function useOverrideConfigAtom(blockId: string | n } function getSettingsKeyAtom(key: T): Atom { + if (isPreviewWindow()) return NullAtom as Atom; let settingsKeyAtom = settingsAtomCache.get(key) as Atom; if (settingsKeyAtom == null) { settingsKeyAtom = atom((get) => { @@ -242,6 +230,7 @@ function useSettingsKeyAtom(key: T): SettingsType[ } function getSettingsPrefixAtom(prefix: string): Atom { + if (isPreviewWindow()) return NullAtom as Atom; let settingsPrefixAtom = settingsAtomCache.get(prefix + ":"); if (settingsPrefixAtom == null) { // create a stable, closured reference to use as the deepCompareReturnPrev key @@ -335,13 +324,6 @@ function useBlockAtom(blockId: string, name: string, makeFn: () => Atom): return atom as Atom; } -function useBlockDataLoaded(blockId: string): boolean { - const loadedAtom = useBlockAtom(blockId, "block-loaded", () => { - return WOS.getWaveObjectLoadingAtom(WOS.makeORef("block", blockId)); - }); - return useAtomValue(loadedAtom); -} - /** * Safely read an atom value, returning null if the atom is null. */ @@ -565,6 +547,7 @@ function getAllBlockComponentModels(): BlockComponentModel[] { function getFocusedBlockId(): string { const layoutModel = getLayoutModelForStaticTab(); + if (layoutModel?.focusedNode == null) return null; const focusedLayoutNode = globalStore.get(layoutModel.focusedNode); return focusedLayoutNode?.data?.blockId; } @@ -602,17 +585,6 @@ async function loadConnStatus() { } } -async function loadTabIndicators() { - const tabIndicators = await RpcApi.GetAllTabIndicatorsCommand(TabRpcClient); - if (tabIndicators == null) { - return; - } - for (const [tabId, indicator] of Object.entries(tabIndicators)) { - const curAtom = getTabIndicatorAtom(tabId); - globalStore.set(curAtom, indicator); - } -} - function subscribeToConnEvents() { waveEventSubscribeSingle({ eventType: "connchange", @@ -623,7 +595,7 @@ function subscribeToConnEvents() { return; } console.log("connstatus update", connStatus); - let curAtom = getConnStatusAtom(connStatus.connection); + const curAtom = getConnStatusAtom(connStatus.connection); globalStore.set(curAtom, connStatus); } catch (e) { console.log("connchange error", e); @@ -632,33 +604,38 @@ function subscribeToConnEvents() { }); } +function makeDefaultConnStatus(conn: string): ConnStatus { + if (isLocalConnName(conn)) { + return { + connection: conn, + connected: true, + error: null, + status: "connected", + hasconnected: true, + activeconnnum: 0, + wshenabled: false, + moshenabled: false, + moshactive: false, + }; + } + return { + connection: conn, + connected: false, + error: null, + status: "disconnected", + hasconnected: false, + activeconnnum: 0, + wshenabled: false, + moshenabled: false, + moshactive: false, + }; +} + function getConnStatusAtom(conn: string): PrimitiveAtom { const connStatusMap = globalStore.get(ConnStatusMapAtom); let rtn = connStatusMap.get(conn); if (rtn == null) { - if (isLocalConnName(conn)) { - const connStatus: ConnStatus = { - connection: conn, - connected: true, - error: null, - status: "connected", - hasconnected: true, - activeconnnum: 0, - wshenabled: false, - }; - rtn = atom(connStatus); - } else { - const connStatus: ConnStatus = { - connection: conn, - connected: false, - error: null, - status: "disconnected", - hasconnected: false, - activeconnnum: 0, - wshenabled: false, - }; - rtn = atom(connStatus); - } + rtn = atom(makeDefaultConnStatus(conn)); const newConnStatusMap = new Map(connStatusMap); newConnStatusMap.set(conn, rtn); globalStore.set(ConnStatusMapAtom, newConnStatusMap); @@ -666,76 +643,6 @@ function getConnStatusAtom(conn: string): PrimitiveAtom { return rtn; } -function getTabIndicatorAtom(tabId: string): PrimitiveAtom { - let rtn = TabIndicatorMap.get(tabId); - if (rtn == null) { - rtn = atom(null) as PrimitiveAtom; - TabIndicatorMap.set(tabId, rtn); - } - return rtn; -} - -function setTabIndicatorInternal(tabId: string, indicator: TabIndicator) { - if (indicator == null) { - const indicatorAtom = getTabIndicatorAtom(tabId); - globalStore.set(indicatorAtom, null); - return; - } - const indicatorAtom = getTabIndicatorAtom(tabId); - const currentIndicator = globalStore.get(indicatorAtom); - if (currentIndicator == null) { - globalStore.set(indicatorAtom, indicator); - return; - } - if (indicator.priority >= currentIndicator.priority) { - if (indicator.clearonfocus && !currentIndicator.clearonfocus) { - indicator.persistentindicator = currentIndicator; - } - globalStore.set(indicatorAtom, indicator); - } -} - -function setTabIndicator(tabId: string, indicator: TabIndicator) { - setTabIndicatorInternal(tabId, indicator); - - const eventData: WaveEvent = { - event: "tab:indicator", - scopes: [WOS.makeORef("tab", tabId)], - data: { - tabid: tabId, - indicator: indicator, - }, - }; - fireAndForget(() => RpcApi.EventPublishCommand(TabRpcClient, eventData)); -} - -function clearTabIndicatorFromFocus(tabId: string) { - const indicatorAtom = getTabIndicatorAtom(tabId); - const currentIndicator = globalStore.get(indicatorAtom); - if (currentIndicator == null) { - return; - } - const persistentIndicator = currentIndicator.persistentindicator; - const eventData: WaveEvent = { - event: "tab:indicator", - scopes: [WOS.makeORef("tab", tabId)], - data: { - tabid: tabId, - indicator: persistentIndicator ?? null, - } as TabIndicatorEventData, - }; - fireAndForget(() => RpcApi.EventPublishCommand(TabRpcClient, eventData)); -} - -function clearAllTabIndicators() { - for (const [tabId, indicatorAtom] of TabIndicatorMap.entries()) { - const indicator = globalStore.get(indicatorAtom); - if (indicator != null) { - setTabIndicator(tabId, null); - } - } -} - function createTab() { getApi().createTab(); } @@ -745,18 +652,15 @@ function setActiveTab(tabId: string) { } function recordTEvent(event: string, props?: TEventProps) { + if (isPreviewWindow()) return; if (props == null) { props = {}; } RpcApi.RecordTEventCommand(TabRpcClient, { event, props }, { noresponse: true }); } -export { ConnStatusMapAtom, getAtoms, initGlobalAtoms, orefAtomCache, TabIndicatorMap, blockComponentModelMap } from "./global-atoms"; - export { atoms, - clearAllTabIndicators, - clearTabIndicatorFromFocus, createBlock, createBlockSplitHorizontally, createBlockSplitVertically, @@ -766,6 +670,7 @@ export { getApi, getBlockComponentModel, getBlockMetaKeyAtom, + getConnConfigKeyAtom, getBlockTermDurableAtom, getConnStatusAtom, getFocusedBlockId, @@ -776,7 +681,6 @@ export { getOverrideConfigAtom, getSettingsKeyAtom, getSettingsPrefixAtom, - getTabIndicatorAtom, getUserName, globalPrimaryTabStartup, globalStore, @@ -784,7 +688,7 @@ export { initGlobalWaveEventSubs, isDev, loadConnStatus, - loadTabIndicators, + makeDefaultConnStatus, openLink, readAtom, recordTEvent, @@ -794,13 +698,10 @@ export { setActiveTab, setNodeFocus, setPlatform, - setTabIndicator, subscribeToConnEvents, unregisterBlockComponentModel, useBlockAtom, useBlockCache, - useBlockDataLoaded, - useBlockMetaKeyAtom, useOrefMetaKeyAtom, useOverrideConfigAtom, useSettingsKeyAtom, diff --git a/frontend/app/store/keymodel.ts b/frontend/app/store/keymodel.ts index 94ed8bbdc..afa520911 100644 --- a/frontend/app/store/keymodel.ts +++ b/frontend/app/store/keymodel.ts @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { WaveAIModel } from "@/app/aipanel/waveai-model"; @@ -65,7 +65,7 @@ export function keyboardMouseDownHandler(e: MouseEvent) { } } -function getFocusedBlockInStaticTab() { +function getFocusedBlockInStaticTab(): string { const layoutModel = getLayoutModelForStaticTab(); const focusedNode = globalStore.get(layoutModel.focusedNode); return focusedNode.data?.blockId; @@ -129,11 +129,11 @@ function getStaticTabBlockCount(): number { } function simpleCloseStaticTab() { - const ws = globalStore.get(atoms.workspace); + const workspaceId = globalStore.get(atoms.workspaceId); const tabId = globalStore.get(atoms.staticTabId); const confirmClose = globalStore.get(getSettingsKeyAtom("tab:confirmclose")) ?? false; getApi() - .closeTab(ws.oid, tabId, confirmClose) + .closeTab(workspaceId, tabId, confirmClose) .then((didClose) => { if (didClose) { deleteLayoutModelForTab(tabId); @@ -419,7 +419,6 @@ function appHandleKeyDown(waveEvent: WaveKeyboardEvent): boolean { } const nativeEvent = (waveEvent as any).nativeEvent; if (lastHandledEvent != null && nativeEvent != null && lastHandledEvent === nativeEvent) { - console.log("lastHandledEvent return false"); return false; } lastHandledEvent = nativeEvent; @@ -491,7 +490,7 @@ function tryReinjectKey(event: WaveKeyboardEvent): boolean { function countTermBlocks(): number { const allBCMs = getAllBlockComponentModels(); let count = 0; - let gsGetBound = globalStore.get.bind(globalStore); + const gsGetBound = globalStore.get.bind(globalStore); for (const bcm of allBCMs) { const viewModel = bcm.viewModel; if (viewModel.viewType == "term" && viewModel.isBasicTerm?.(gsGetBound)) { @@ -696,7 +695,15 @@ function registerGlobalKeys() { return false; } if (bcm.viewModel.searchAtoms) { - globalStore.set(bcm.viewModel.searchAtoms.isOpen, true); + if (globalStore.get(bcm.viewModel.searchAtoms.isOpen)) { + // Already open — increment the focusInput counter so this block's + // SearchComponent focuses its own input (avoids a global DOM query + // that could target the wrong block when multiple searches are open). + const cur = globalStore.get(bcm.viewModel.searchAtoms.focusInput) as number; + globalStore.set(bcm.viewModel.searchAtoms.focusInput, cur + 1); + } else { + globalStore.set(bcm.viewModel.searchAtoms.isOpen, true); + } return true; } return false; diff --git a/frontend/app/store/services.ts b/frontend/app/store/services.ts index d9d7730e1..035834672 100644 --- a/frontend/app/store/services.ts +++ b/frontend/app/store/services.ts @@ -4,188 +4,233 @@ // generated by cmd/generate/main-generatets.go import * as WOS from "./wos"; +import type { WaveEnv } from "@/app/waveenv/waveenv"; + +function callBackendService(waveEnv: WaveEnv, service: string, method: string, args: any[], noUIContext?: boolean): Promise { + if (waveEnv != null) { + return waveEnv.callBackendService(service, method, args, noUIContext) + } + return WOS.callBackendService(service, method, args, noUIContext); +} // blockservice.BlockService (block) -class BlockServiceType { +export class BlockServiceType { + waveEnv: WaveEnv; + + constructor(waveEnv?: WaveEnv) { + this.waveEnv = waveEnv; + } + // queue a layout action to cleanup orphaned blocks in the tab // @returns object updates CleanupOrphanedBlocks(tabId: string): Promise { - return WOS.callBackendService("block", "CleanupOrphanedBlocks", Array.from(arguments)) + return callBackendService(this?.waveEnv, "block", "CleanupOrphanedBlocks", Array.from(arguments)) } GetControllerStatus(arg2: string): Promise { - return WOS.callBackendService("block", "GetControllerStatus", Array.from(arguments)) + return callBackendService(this?.waveEnv, "block", "GetControllerStatus", Array.from(arguments)) } // save the terminal state to a blockfile SaveTerminalState(blockId: string, state: string, stateType: string, ptyOffset: number, termSize: TermSize): Promise { - return WOS.callBackendService("block", "SaveTerminalState", Array.from(arguments)) + return callBackendService(this?.waveEnv, "block", "SaveTerminalState", Array.from(arguments)) } SaveWaveAiData(arg2: string, arg3: WaveAIPromptMessageType[]): Promise { - return WOS.callBackendService("block", "SaveWaveAiData", Array.from(arguments)) + return callBackendService(this?.waveEnv, "block", "SaveWaveAiData", Array.from(arguments)) } } export const BlockService = new BlockServiceType(); // clientservice.ClientService (client) -class ClientServiceType { +export class ClientServiceType { + waveEnv: WaveEnv; + + constructor(waveEnv?: WaveEnv) { + this.waveEnv = waveEnv; + } + // @returns object updates AgreeTos(): Promise { - return WOS.callBackendService("client", "AgreeTos", Array.from(arguments)) + return callBackendService(this?.waveEnv, "client", "AgreeTos", Array.from(arguments)) } FocusWindow(arg2: string): Promise { - return WOS.callBackendService("client", "FocusWindow", Array.from(arguments)) + return callBackendService(this?.waveEnv, "client", "FocusWindow", Array.from(arguments)) } GetAllConnStatus(): Promise { - return WOS.callBackendService("client", "GetAllConnStatus", Array.from(arguments)) + return callBackendService(this?.waveEnv, "client", "GetAllConnStatus", Array.from(arguments)) } GetClientData(): Promise { - return WOS.callBackendService("client", "GetClientData", Array.from(arguments)) + return callBackendService(this?.waveEnv, "client", "GetClientData", Array.from(arguments)) } GetTab(arg1: string): Promise { - return WOS.callBackendService("client", "GetTab", Array.from(arguments)) + return callBackendService(this?.waveEnv, "client", "GetTab", Array.from(arguments)) } TelemetryUpdate(arg2: boolean): Promise { - return WOS.callBackendService("client", "TelemetryUpdate", Array.from(arguments)) + return callBackendService(this?.waveEnv, "client", "TelemetryUpdate", Array.from(arguments)) } } export const ClientService = new ClientServiceType(); // objectservice.ObjectService (object) -class ObjectServiceType { +export class ObjectServiceType { + waveEnv: WaveEnv; + + constructor(waveEnv?: WaveEnv) { + this.waveEnv = waveEnv; + } + // @returns blockId (and object updates) CreateBlock(blockDef: BlockDef, rtOpts: RuntimeOpts): Promise { - return WOS.callBackendService("object", "CreateBlock", Array.from(arguments)) + return callBackendService(this?.waveEnv, "object", "CreateBlock", Array.from(arguments)) } // @returns object updates DeleteBlock(blockId: string): Promise { - return WOS.callBackendService("object", "DeleteBlock", Array.from(arguments)) + return callBackendService(this?.waveEnv, "object", "DeleteBlock", Array.from(arguments)) } // get wave object by oref GetObject(oref: string): Promise { - return WOS.callBackendService("object", "GetObject", Array.from(arguments)) + return callBackendService(this?.waveEnv, "object", "GetObject", Array.from(arguments)) } // @returns objects GetObjects(orefs: string[]): Promise { - return WOS.callBackendService("object", "GetObjects", Array.from(arguments)) + return callBackendService(this?.waveEnv, "object", "GetObjects", Array.from(arguments)) } // @returns object updates UpdateObject(waveObj: WaveObj, returnUpdates: boolean): Promise { - return WOS.callBackendService("object", "UpdateObject", Array.from(arguments)) + return callBackendService(this?.waveEnv, "object", "UpdateObject", Array.from(arguments)) } // @returns object updates UpdateObjectMeta(oref: string, meta: MetaType): Promise { - return WOS.callBackendService("object", "UpdateObjectMeta", Array.from(arguments)) - } - - // @returns object updates - UpdateTabName(tabId: string, name: string): Promise { - return WOS.callBackendService("object", "UpdateTabName", Array.from(arguments)) + return callBackendService(this?.waveEnv, "object", "UpdateObjectMeta", Array.from(arguments)) } } export const ObjectService = new ObjectServiceType(); // userinputservice.UserInputService (userinput) -class UserInputServiceType { +export class UserInputServiceType { + waveEnv: WaveEnv; + + constructor(waveEnv?: WaveEnv) { + this.waveEnv = waveEnv; + } + SendUserInputResponse(arg1: UserInputResponse): Promise { - return WOS.callBackendService("userinput", "SendUserInputResponse", Array.from(arguments)) + return callBackendService(this?.waveEnv, "userinput", "SendUserInputResponse", Array.from(arguments)) } } export const UserInputService = new UserInputServiceType(); // windowservice.WindowService (window) -class WindowServiceType { +export class WindowServiceType { + waveEnv: WaveEnv; + + constructor(waveEnv?: WaveEnv) { + this.waveEnv = waveEnv; + } + CloseWindow(windowId: string, fromElectron: boolean): Promise { - return WOS.callBackendService("window", "CloseWindow", Array.from(arguments)) + return callBackendService(this?.waveEnv, "window", "CloseWindow", Array.from(arguments)) } CreateWindow(winSize: WinSize, workspaceId: string): Promise { - return WOS.callBackendService("window", "CreateWindow", Array.from(arguments)) + return callBackendService(this?.waveEnv, "window", "CreateWindow", Array.from(arguments)) } GetWindow(windowId: string): Promise { - return WOS.callBackendService("window", "GetWindow", Array.from(arguments)) - } - - // move block to new window - // @returns object updates - MoveBlockToNewWindow(currentTabId: string, blockId: string): Promise { - return WOS.callBackendService("window", "MoveBlockToNewWindow", Array.from(arguments)) + return callBackendService(this?.waveEnv, "window", "GetWindow", Array.from(arguments)) } // set window position and size // @returns object updates SetWindowPosAndSize(windowId: string, pos: Point, size: WinSize): Promise { - return WOS.callBackendService("window", "SetWindowPosAndSize", Array.from(arguments)) + return callBackendService(this?.waveEnv, "window", "SetWindowPosAndSize", Array.from(arguments)) } SwitchWorkspace(windowId: string, workspaceId: string): Promise { - return WOS.callBackendService("window", "SwitchWorkspace", Array.from(arguments)) + return callBackendService(this?.waveEnv, "window", "SwitchWorkspace", Array.from(arguments)) } } export const WindowService = new WindowServiceType(); // workspaceservice.WorkspaceService (workspace) -class WorkspaceServiceType { +export class WorkspaceServiceType { + waveEnv: WaveEnv; + + constructor(waveEnv?: WaveEnv) { + this.waveEnv = waveEnv; + } + // @returns CloseTabRtn (and object updates) CloseTab(workspaceId: string, tabId: string, fromElectron: boolean): Promise { - return WOS.callBackendService("workspace", "CloseTab", Array.from(arguments)) + return callBackendService(this?.waveEnv, "workspace", "CloseTab", Array.from(arguments)) } // @returns tabId (and object updates) CreateTab(workspaceId: string, tabName: string, activateTab: boolean): Promise { - return WOS.callBackendService("workspace", "CreateTab", Array.from(arguments)) + return callBackendService(this?.waveEnv, "workspace", "CreateTab", Array.from(arguments)) } // @returns workspaceId CreateWorkspace(name: string, icon: string, color: string, applyDefaults: boolean): Promise { - return WOS.callBackendService("workspace", "CreateWorkspace", Array.from(arguments)) + return callBackendService(this?.waveEnv, "workspace", "CreateWorkspace", Array.from(arguments)) } // @returns object updates DeleteWorkspace(workspaceId: string): Promise { - return WOS.callBackendService("workspace", "DeleteWorkspace", Array.from(arguments)) + return callBackendService(this?.waveEnv, "workspace", "DeleteWorkspace", Array.from(arguments)) } // @returns colors GetColors(): Promise { - return WOS.callBackendService("workspace", "GetColors", Array.from(arguments)) + return callBackendService(this?.waveEnv, "workspace", "GetColors", Array.from(arguments)) } // @returns icons GetIcons(): Promise { - return WOS.callBackendService("workspace", "GetIcons", Array.from(arguments)) + return callBackendService(this?.waveEnv, "workspace", "GetIcons", Array.from(arguments)) } // @returns workspace GetWorkspace(workspaceId: string): Promise { - return WOS.callBackendService("workspace", "GetWorkspace", Array.from(arguments)) + return callBackendService(this?.waveEnv, "workspace", "GetWorkspace", Array.from(arguments)) } ListWorkspaces(): Promise { - return WOS.callBackendService("workspace", "ListWorkspaces", Array.from(arguments)) + return callBackendService(this?.waveEnv, "workspace", "ListWorkspaces", Array.from(arguments)) } // @returns object updates SetActiveTab(workspaceId: string, tabId: string): Promise { - return WOS.callBackendService("workspace", "SetActiveTab", Array.from(arguments)) - } - - // @returns object updates - UpdateTabIds(workspaceId: string, tabIds: string[]): Promise { - return WOS.callBackendService("workspace", "UpdateTabIds", Array.from(arguments)) + return callBackendService(this?.waveEnv, "workspace", "SetActiveTab", Array.from(arguments)) } // @returns object updates UpdateWorkspace(workspaceId: string, name: string, icon: string, color: string, applyDefaults: boolean): Promise { - return WOS.callBackendService("workspace", "UpdateWorkspace", Array.from(arguments)) + return callBackendService(this?.waveEnv, "workspace", "UpdateWorkspace", Array.from(arguments)) } } export const WorkspaceService = new WorkspaceServiceType(); +export const AllServiceTypes = { + "block": BlockServiceType, + "client": ClientServiceType, + "object": ObjectServiceType, + "userinput": UserInputServiceType, + "window": WindowServiceType, + "workspace": WorkspaceServiceType, +}; + +export const AllServiceImpls = { + "block": BlockService, + "client": ClientService, + "object": ObjectService, + "userinput": UserInputService, + "window": WindowService, + "workspace": WorkspaceService, +}; diff --git a/frontend/app/store/tab-model.ts b/frontend/app/store/tab-model.ts index ec5ab94c1..a86744082 100644 --- a/frontend/app/store/tab-model.ts +++ b/frontend/app/store/tab-model.ts @@ -1,24 +1,34 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 +import { WaveEnv, WaveEnvSubset } from "@/app/waveenv/waveenv"; import { atom, Atom, PrimitiveAtom } from "jotai"; import { createContext, useContext } from "react"; import { globalStore } from "./jotaiStore"; import * as WOS from "./wos"; +export type TabModelEnv = WaveEnvSubset<{ + wos: WaveEnv["wos"]; +}>; + const tabModelCache = new Map(); export const activeTabIdAtom = atom(null) as PrimitiveAtom; export class TabModel { tabId: string; + waveEnv: TabModelEnv; tabAtom: Atom; tabNumBlocksAtom: Atom; isTermMultiInput = atom(false) as PrimitiveAtom; metaCache: Map> = new Map(); - constructor(tabId: string) { + constructor(tabId: string, waveEnv?: TabModelEnv) { this.tabId = tabId; + this.waveEnv = waveEnv; this.tabAtom = atom((get) => { + if (this.waveEnv != null) { + return get(this.waveEnv.wos.getWaveObjectAtom(WOS.makeORef("tab", this.tabId))); + } return WOS.getObjectValue(WOS.makeORef("tab", this.tabId), get); }); this.tabNumBlocksAtom = atom((get) => { @@ -40,33 +50,42 @@ export class TabModel { } } -export function getTabModelByTabId(tabId: string): TabModel { - let model = tabModelCache.get(tabId); +export function getTabModelByTabId(tabId: string, waveEnv?: TabModelEnv): TabModel { + if (!waveEnv?.isMock) { + let model = tabModelCache.get(tabId); + if (model == null) { + model = new TabModel(tabId, waveEnv); + tabModelCache.set(tabId, model); + } + return model; + } + const key = `TabModel:${tabId}`; + let model = waveEnv.mockModels.get(key); if (model == null) { - model = new TabModel(tabId); - tabModelCache.set(tabId, model); + model = new TabModel(tabId, waveEnv); + waveEnv.mockModels.set(key, model); } return model; } -export function getActiveTabModel(): TabModel | null { +export function getActiveTabModel(waveEnv?: TabModelEnv): TabModel | null { const activeTabId = globalStore.get(activeTabIdAtom); if (activeTabId == null) { return null; } - return getTabModelByTabId(activeTabId); + return getTabModelByTabId(activeTabId, waveEnv); } export const TabModelContext = createContext(undefined); export function useTabModel(): TabModel { - const model = useContext(TabModelContext); - if (model == null) { + const ctxModel = useContext(TabModelContext); + if (ctxModel == null) { throw new Error("useTabModel must be used within a TabModelProvider"); } - return model; + return ctxModel; } -export function maybeUseTabModel(): TabModel { +export function useTabModelMaybe(): TabModel { return useContext(TabModelContext); } diff --git a/frontend/app/store/wos.ts b/frontend/app/store/wos.ts index 4ce339acd..72ca02275 100644 --- a/frontend/app/store/wos.ts +++ b/frontend/app/store/wos.ts @@ -3,12 +3,12 @@ // WaveObjectStore +import { isPreviewWindow } from "@/app/store/windowtype"; import { waveEventSubscribeSingle } from "@/app/store/wps"; import { getWebServerEndpoint } from "@/util/endpoints"; import { fetch } from "@/util/fetchutil"; import { fireAndForget } from "@/util/util"; import { atom, Atom, Getter, PrimitiveAtom, Setter, useAtomValue } from "jotai"; -import { useEffect } from "react"; import { globalStore } from "./jotaiStore"; import { ObjectService } from "./services"; @@ -20,8 +20,6 @@ type WaveObjectDataItemType = { type WaveObjectValue = { pendingPromise: Promise; dataAtom: PrimitiveAtom>; - refCount: number; - holdTime: number; }; function splitORef(oref: string): [string, string] { @@ -57,7 +55,19 @@ function makeORef(otype: string, oid: string): string { return `${otype}:${oid}`; } +const previewMockObjects: Map = new Map(); + +function mockObjectForPreview(oref: string, obj: T): void { + if (!isPreviewWindow()) { + throw new Error("mockObjectForPreview can only be called in a preview window"); + } + previewMockObjects.set(oref, obj); +} + function GetObject(oref: string): Promise { + if (isPreviewWindow()) { + return Promise.resolve((previewMockObjects.get(oref) as T) ?? null); + } return callBackendService("object", "GetObject", [oref], true); } @@ -105,7 +115,9 @@ function callBackendService(service: string, method: string, args: any[], noUICo const usp = new URLSearchParams(); usp.set("service", service); usp.set("method", method); - const url = getWebServerEndpoint() + "/wave/service?" + usp.toString(); + const webEndpoint = getWebServerEndpoint(); + if (webEndpoint == null) throw new Error(`cannot call ${methodName}: no web endpoint`); + const url = webEndpoint + "/wave/service?" + usp.toString(); const fetchPromise = fetch(url, { method: "POST", body: JSON.stringify(waveCall), @@ -136,12 +148,6 @@ function callBackendService(service: string, method: string, args: any[], noUICo const waveObjectValueCache = new Map>(); -function clearWaveObjectCache() { - waveObjectValueCache.clear(); -} - -const defaultHoldTime = 5000; // 5-seconds - function reloadWaveObject(oref: string): Promise { let wov = waveObjectValueCache.get(oref); if (wov === undefined) { @@ -156,7 +162,7 @@ function reloadWaveObject(oref: string): Promise { } function createWaveValueObject(oref: string, shouldFetch: boolean): WaveObjectValue { - const wov = { pendingPromise: null, dataAtom: null, refCount: 0, holdTime: Date.now() + 5000 }; + const wov = { pendingPromise: null, dataAtom: null }; wov.dataAtom = atom({ value: null, loading: true }); if (!shouldFetch) { return wov; @@ -195,7 +201,6 @@ function getWaveObjectValue(oref: string, createIfMissing = t function loadAndPinWaveObject(oref: string): Promise { const wov = getWaveObjectValue(oref); - wov.refCount++; if (wov.pendingPromise == null) { const dataValue = globalStore.get(wov.dataAtom); return Promise.resolve(dataValue.value); @@ -203,35 +208,48 @@ function loadAndPinWaveObject(oref: string): Promise { return wov.pendingPromise; } -function getWaveObjectAtom(oref: string): WritableWaveObjectAtom { +const waveObjectDerivedAtomCache = new Map>(); + +function getWaveObjectAtom(oref: string): Atom { + const cacheKey = oref + ":value"; + let cachedAtom = waveObjectDerivedAtomCache.get(cacheKey) as Atom; + if (cachedAtom != null) { + return cachedAtom; + } const wov = getWaveObjectValue(oref); - return atom( - (get) => get(wov.dataAtom).value, - (_get, set, value: T) => { - setObjectValue(value, set, true); - } - ); + cachedAtom = atom((get) => get(wov.dataAtom).value); + waveObjectDerivedAtomCache.set(cacheKey, cachedAtom); + return cachedAtom; } function getWaveObjectLoadingAtom(oref: string): Atom { + const cacheKey = oref + ":loading"; + let cachedAtom = waveObjectDerivedAtomCache.get(cacheKey) as Atom; + if (cachedAtom != null) { + return cachedAtom; + } const wov = getWaveObjectValue(oref); - return atom((get) => { + cachedAtom = atom((get) => { const dataValue = get(wov.dataAtom); - if (dataValue.loading) { - return null; - } return dataValue.loading; }); + waveObjectDerivedAtomCache.set(cacheKey, cachedAtom); + return cachedAtom; +} + +function isWaveObjectNullAtom(oref: string): Atom { + const cacheKey = oref + ":isnull"; + let cachedAtom = waveObjectDerivedAtomCache.get(cacheKey) as Atom; + if (cachedAtom != null) { + return cachedAtom; + } + cachedAtom = atom((get) => get(getWaveObjectAtom(oref)) == null); + waveObjectDerivedAtomCache.set(cacheKey, cachedAtom); + return cachedAtom; } function useWaveObjectValue(oref: string): [T, boolean] { const wov = getWaveObjectValue(oref); - useEffect(() => { - wov.refCount++; - return () => { - wov.refCount--; - }; - }, [oref]); const atomVal = useAtomValue(wov.dataAtom); return [atomVal.value, atomVal.loading]; } @@ -257,7 +275,6 @@ function updateWaveObject(update: WaveObjUpdate) { console.log("WaveObj updated", oref); globalStore.set(wov.dataAtom, { value: update.obj, loading: false }); } - wov.holdTime = Date.now() + defaultHoldTime; return; } @@ -267,15 +284,6 @@ function updateWaveObjects(vals: WaveObjUpdate[]) { } } -function cleanWaveObjectCache() { - const now = Date.now(); - for (const [oref, wov] of waveObjectValueCache) { - if (wov.refCount == 0 && wov.holdTime < now) { - waveObjectValueCache.delete(oref); - } - } -} - // gets the value of a WaveObject from the cache. // should provide getFn if it is available (e.g. inside of a jotai atom) // otherwise it will use the globalStore.get function @@ -308,13 +316,13 @@ function setObjectValue(value: T, setFn?: Setter, pushToServe export { callBackendService, - cleanWaveObjectCache, - clearWaveObjectCache, getObjectValue, getWaveObjectAtom, getWaveObjectLoadingAtom, + isWaveObjectNullAtom, loadAndPinWaveObject, makeORef, + mockObjectForPreview, reloadWaveObject, setObjectValue, splitORef, diff --git a/frontend/app/store/wps.ts b/frontend/app/store/wps.ts index 745734123..332d2ba0a 100644 --- a/frontend/app/store/wps.ts +++ b/frontend/app/store/wps.ts @@ -1,8 +1,9 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import type { WshClient } from "@/app/store/wshclient"; import { RpcApi } from "@/app/store/wshclientapi"; +import { isPreviewWindow } from "@/app/store/windowtype"; import { isBlank } from "@/util/util"; import { Subject } from "rxjs"; @@ -43,6 +44,9 @@ function wpsReconnectHandler() { } function updateWaveEventSub(eventType: string) { + if (isPreviewWindow()) { + return; + } const subjects = waveEventSubjects.get(eventType); if (subjects == null) { RpcApi.EventUnsubCommand(WpsRpcClient, eventType, { noresponse: true }); @@ -84,7 +88,7 @@ function waveEventSubscribeSingle(subscription: WaveEve function waveEventUnsubscribe(...unsubscribes: WaveEventUnsubscribe[]) { const eventTypeSet = new Set(); for (const unsubscribe of unsubscribes) { - let subjects = waveEventSubjects.get(unsubscribe.eventType); + const subjects = waveEventSubjects.get(unsubscribe.eventType); if (subjects == null) { return; } diff --git a/frontend/app/store/wshclientapi.ts b/frontend/app/store/wshclientapi.ts index 93276f1aa..d64f7f06b 100644 --- a/frontend/app/store/wshclientapi.ts +++ b/frontend/app/store/wshclientapi.ts @@ -5,855 +5,1072 @@ import { WshClient } from "./wshclient"; +export interface MockRpcClient { + mockWshRpcCall(client: WshClient, command: string, data: any, opts?: RpcOpts): Promise; + mockWshRpcStream(client: WshClient, command: string, data: any, opts?: RpcOpts): AsyncGenerator; +} + // WshServerCommandToDeclMap -class RpcApiType { +export class RpcApiType { + mockClient: MockRpcClient = null; + + setMockRpcClient(client: MockRpcClient): void { + this.mockClient = client; + } + // command "activity" [call] ActivityCommand(client: WshClient, data: ActivityUpdate, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "activity", data, opts); return client.wshRpcCall("activity", data, opts); } // command "aisendmessage" [call] AiSendMessageCommand(client: WshClient, data: AiMessageData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "aisendmessage", data, opts); return client.wshRpcCall("aisendmessage", data, opts); } // command "authenticate" [call] AuthenticateCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "authenticate", data, opts); return client.wshRpcCall("authenticate", data, opts); } // command "authenticatejobmanager" [call] AuthenticateJobManagerCommand(client: WshClient, data: CommandAuthenticateJobManagerData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "authenticatejobmanager", data, opts); return client.wshRpcCall("authenticatejobmanager", data, opts); } // command "authenticatejobmanagerverify" [call] AuthenticateJobManagerVerifyCommand(client: WshClient, data: CommandAuthenticateJobManagerData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "authenticatejobmanagerverify", data, opts); return client.wshRpcCall("authenticatejobmanagerverify", data, opts); } // command "authenticatetojobmanager" [call] AuthenticateToJobManagerCommand(client: WshClient, data: CommandAuthenticateToJobData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "authenticatetojobmanager", data, opts); return client.wshRpcCall("authenticatetojobmanager", data, opts); } // command "authenticatetoken" [call] AuthenticateTokenCommand(client: WshClient, data: CommandAuthenticateTokenData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "authenticatetoken", data, opts); return client.wshRpcCall("authenticatetoken", data, opts); } // command "authenticatetokenverify" [call] AuthenticateTokenVerifyCommand(client: WshClient, data: CommandAuthenticateTokenData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "authenticatetokenverify", data, opts); return client.wshRpcCall("authenticatetokenverify", data, opts); } + // command "badgewatchpid" [call] + BadgeWatchPidCommand(client: WshClient, data: CommandBadgeWatchPidData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "badgewatchpid", data, opts); + return client.wshRpcCall("badgewatchpid", data, opts); + } + // command "blockinfo" [call] BlockInfoCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "blockinfo", data, opts); return client.wshRpcCall("blockinfo", data, opts); } // command "blockjobstatus" [call] BlockJobStatusCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "blockjobstatus", data, opts); return client.wshRpcCall("blockjobstatus", data, opts); } // command "blockslist" [call] BlocksListCommand(client: WshClient, data: BlocksListRequest, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "blockslist", data, opts); return client.wshRpcCall("blockslist", data, opts); } // command "captureblockscreenshot" [call] CaptureBlockScreenshotCommand(client: WshClient, data: CommandCaptureBlockScreenshotData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "captureblockscreenshot", data, opts); return client.wshRpcCall("captureblockscreenshot", data, opts); } // command "checkgoversion" [call] CheckGoVersionCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "checkgoversion", null, opts); return client.wshRpcCall("checkgoversion", null, opts); } // command "connconnect" [call] ConnConnectCommand(client: WshClient, data: ConnRequest, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "connconnect", data, opts); return client.wshRpcCall("connconnect", data, opts); } // command "conndisconnect" [call] ConnDisconnectCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "conndisconnect", data, opts); return client.wshRpcCall("conndisconnect", data, opts); } // command "connensure" [call] ConnEnsureCommand(client: WshClient, data: ConnExtData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "connensure", data, opts); return client.wshRpcCall("connensure", data, opts); } // command "connlist" [call] ConnListCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "connlist", null, opts); return client.wshRpcCall("connlist", null, opts); } // command "connreinstallwsh" [call] ConnReinstallWshCommand(client: WshClient, data: ConnExtData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "connreinstallwsh", data, opts); return client.wshRpcCall("connreinstallwsh", data, opts); } // command "connserverinit" [call] ConnServerInitCommand(client: WshClient, data: CommandConnServerInitData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "connserverinit", data, opts); return client.wshRpcCall("connserverinit", data, opts); } // command "connstatus" [call] ConnStatusCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "connstatus", null, opts); return client.wshRpcCall("connstatus", null, opts); } // command "connupdatewsh" [call] ConnUpdateWshCommand(client: WshClient, data: RemoteInfo, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "connupdatewsh", data, opts); return client.wshRpcCall("connupdatewsh", data, opts); } // command "controlgetrouteid" [call] ControlGetRouteIdCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "controlgetrouteid", null, opts); return client.wshRpcCall("controlgetrouteid", null, opts); } // command "controllerappendoutput" [call] ControllerAppendOutputCommand(client: WshClient, data: CommandControllerAppendOutputData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "controllerappendoutput", data, opts); return client.wshRpcCall("controllerappendoutput", data, opts); } // command "controllerdestroy" [call] ControllerDestroyCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "controllerdestroy", data, opts); return client.wshRpcCall("controllerdestroy", data, opts); } // command "controllerinput" [call] ControllerInputCommand(client: WshClient, data: CommandBlockInputData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "controllerinput", data, opts); return client.wshRpcCall("controllerinput", data, opts); } // command "controllerresync" [call] ControllerResyncCommand(client: WshClient, data: CommandControllerResyncData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "controllerresync", data, opts); return client.wshRpcCall("controllerresync", data, opts); } // command "createblock" [call] CreateBlockCommand(client: WshClient, data: CommandCreateBlockData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "createblock", data, opts); return client.wshRpcCall("createblock", data, opts); } // command "createsubblock" [call] CreateSubBlockCommand(client: WshClient, data: CommandCreateSubBlockData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "createsubblock", data, opts); return client.wshRpcCall("createsubblock", data, opts); } + // command "debugterm" [call] + DebugTermCommand(client: WshClient, data: CommandDebugTermData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "debugterm", data, opts); + return client.wshRpcCall("debugterm", data, opts); + } + // command "deleteappfile" [call] DeleteAppFileCommand(client: WshClient, data: CommandDeleteAppFileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "deleteappfile", data, opts); return client.wshRpcCall("deleteappfile", data, opts); } // command "deleteblock" [call] DeleteBlockCommand(client: WshClient, data: CommandDeleteBlockData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "deleteblock", data, opts); return client.wshRpcCall("deleteblock", data, opts); } // command "deletebuilder" [call] DeleteBuilderCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "deletebuilder", data, opts); return client.wshRpcCall("deletebuilder", data, opts); } // command "deletesubblock" [call] DeleteSubBlockCommand(client: WshClient, data: CommandDeleteBlockData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "deletesubblock", data, opts); return client.wshRpcCall("deletesubblock", data, opts); } // command "dismisswshfail" [call] DismissWshFailCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "dismisswshfail", data, opts); return client.wshRpcCall("dismisswshfail", data, opts); } // command "dispose" [call] DisposeCommand(client: WshClient, data: CommandDisposeData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "dispose", data, opts); return client.wshRpcCall("dispose", data, opts); } // command "disposesuggestions" [call] DisposeSuggestionsCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "disposesuggestions", data, opts); return client.wshRpcCall("disposesuggestions", data, opts); } // command "electrondecrypt" [call] ElectronDecryptCommand(client: WshClient, data: CommandElectronDecryptData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "electrondecrypt", data, opts); return client.wshRpcCall("electrondecrypt", data, opts); } // command "electronencrypt" [call] ElectronEncryptCommand(client: WshClient, data: CommandElectronEncryptData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "electronencrypt", data, opts); return client.wshRpcCall("electronencrypt", data, opts); } // command "electronsystembell" [call] ElectronSystemBellCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "electronsystembell", null, opts); return client.wshRpcCall("electronsystembell", null, opts); } // command "eventpublish" [call] EventPublishCommand(client: WshClient, data: WaveEvent, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "eventpublish", data, opts); return client.wshRpcCall("eventpublish", data, opts); } // command "eventreadhistory" [call] EventReadHistoryCommand(client: WshClient, data: CommandEventReadHistoryData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "eventreadhistory", data, opts); return client.wshRpcCall("eventreadhistory", data, opts); } // command "eventrecv" [call] EventRecvCommand(client: WshClient, data: WaveEvent, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "eventrecv", data, opts); return client.wshRpcCall("eventrecv", data, opts); } // command "eventsub" [call] EventSubCommand(client: WshClient, data: SubscriptionRequest, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "eventsub", data, opts); return client.wshRpcCall("eventsub", data, opts); } // command "eventunsub" [call] EventUnsubCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "eventunsub", data, opts); return client.wshRpcCall("eventunsub", data, opts); } // command "eventunsuball" [call] EventUnsubAllCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "eventunsuball", null, opts); return client.wshRpcCall("eventunsuball", null, opts); } // command "fetchsuggestions" [call] FetchSuggestionsCommand(client: WshClient, data: FetchSuggestionsData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "fetchsuggestions", data, opts); return client.wshRpcCall("fetchsuggestions", data, opts); } // command "fileappend" [call] FileAppendCommand(client: WshClient, data: FileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "fileappend", data, opts); return client.wshRpcCall("fileappend", data, opts); } // command "filecopy" [call] FileCopyCommand(client: WshClient, data: CommandFileCopyData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filecopy", data, opts); return client.wshRpcCall("filecopy", data, opts); } // command "filecreate" [call] FileCreateCommand(client: WshClient, data: FileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filecreate", data, opts); return client.wshRpcCall("filecreate", data, opts); } // command "filedelete" [call] FileDeleteCommand(client: WshClient, data: CommandDeleteFileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filedelete", data, opts); return client.wshRpcCall("filedelete", data, opts); } // command "fileinfo" [call] FileInfoCommand(client: WshClient, data: FileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "fileinfo", data, opts); return client.wshRpcCall("fileinfo", data, opts); } // command "filejoin" [call] FileJoinCommand(client: WshClient, data: string[], opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filejoin", data, opts); return client.wshRpcCall("filejoin", data, opts); } // command "filelist" [call] FileListCommand(client: WshClient, data: FileListData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filelist", data, opts); return client.wshRpcCall("filelist", data, opts); } // command "fileliststream" [responsestream] FileListStreamCommand(client: WshClient, data: FileListData, opts?: RpcOpts): AsyncGenerator { + if (this.mockClient) return this.mockClient.mockWshRpcStream(client, "fileliststream", data, opts); return client.wshRpcStream("fileliststream", data, opts); } // command "filemkdir" [call] FileMkdirCommand(client: WshClient, data: FileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filemkdir", data, opts); return client.wshRpcCall("filemkdir", data, opts); } // command "filemove" [call] FileMoveCommand(client: WshClient, data: CommandFileCopyData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filemove", data, opts); return client.wshRpcCall("filemove", data, opts); } // command "fileread" [call] FileReadCommand(client: WshClient, data: FileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "fileread", data, opts); return client.wshRpcCall("fileread", data, opts); } // command "filereadstream" [responsestream] FileReadStreamCommand(client: WshClient, data: FileData, opts?: RpcOpts): AsyncGenerator { + if (this.mockClient) return this.mockClient.mockWshRpcStream(client, "filereadstream", data, opts); return client.wshRpcStream("filereadstream", data, opts); } // command "filerestorebackup" [call] FileRestoreBackupCommand(client: WshClient, data: CommandFileRestoreBackupData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filerestorebackup", data, opts); return client.wshRpcCall("filerestorebackup", data, opts); } // command "filewrite" [call] FileWriteCommand(client: WshClient, data: FileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "filewrite", data, opts); return client.wshRpcCall("filewrite", data, opts); } // command "findgitbash" [call] FindGitBashCommand(client: WshClient, data: boolean, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "findgitbash", data, opts); return client.wshRpcCall("findgitbash", data, opts); } // command "focuswindow" [call] FocusWindowCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "focuswindow", data, opts); return client.wshRpcCall("focuswindow", data, opts); } - // command "getalltabindicators" [call] - GetAllTabIndicatorsCommand(client: WshClient, opts?: RpcOpts): Promise<{[key: string]: TabIndicator}> { - return client.wshRpcCall("getalltabindicators", null, opts); + // command "getallbadges" [call] + GetAllBadgesCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getallbadges", null, opts); + return client.wshRpcCall("getallbadges", null, opts); } // command "getallvars" [call] GetAllVarsCommand(client: WshClient, data: CommandVarData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getallvars", data, opts); return client.wshRpcCall("getallvars", data, opts); } // command "getbuilderoutput" [call] GetBuilderOutputCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getbuilderoutput", data, opts); return client.wshRpcCall("getbuilderoutput", data, opts); } // command "getbuilderstatus" [call] GetBuilderStatusCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getbuilderstatus", data, opts); return client.wshRpcCall("getbuilderstatus", data, opts); } // command "getfocusedblockdata" [call] GetFocusedBlockDataCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getfocusedblockdata", null, opts); return client.wshRpcCall("getfocusedblockdata", null, opts); } // command "getfullconfig" [call] GetFullConfigCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getfullconfig", null, opts); return client.wshRpcCall("getfullconfig", null, opts); } // command "getjwtpublickey" [call] GetJwtPublicKeyCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getjwtpublickey", null, opts); return client.wshRpcCall("getjwtpublickey", null, opts); } // command "getmeta" [call] GetMetaCommand(client: WshClient, data: CommandGetMetaData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getmeta", data, opts); return client.wshRpcCall("getmeta", data, opts); } // command "getrtinfo" [call] GetRTInfoCommand(client: WshClient, data: CommandGetRTInfoData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getrtinfo", data, opts); return client.wshRpcCall("getrtinfo", data, opts); } // command "getsecrets" [call] GetSecretsCommand(client: WshClient, data: string[], opts?: RpcOpts): Promise<{[key: string]: string}> { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getsecrets", data, opts); return client.wshRpcCall("getsecrets", data, opts); } // command "getsecretslinuxstoragebackend" [call] GetSecretsLinuxStorageBackendCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getsecretslinuxstoragebackend", null, opts); return client.wshRpcCall("getsecretslinuxstoragebackend", null, opts); } // command "getsecretsnames" [call] GetSecretsNamesCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getsecretsnames", null, opts); return client.wshRpcCall("getsecretsnames", null, opts); } // command "gettab" [call] GetTabCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "gettab", data, opts); return client.wshRpcCall("gettab", data, opts); } // command "gettempdir" [call] GetTempDirCommand(client: WshClient, data: CommandGetTempDirData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "gettempdir", data, opts); return client.wshRpcCall("gettempdir", data, opts); } // command "getupdatechannel" [call] GetUpdateChannelCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getupdatechannel", null, opts); return client.wshRpcCall("getupdatechannel", null, opts); } // command "getvar" [call] GetVarCommand(client: WshClient, data: CommandVarData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getvar", data, opts); return client.wshRpcCall("getvar", data, opts); } // command "getwaveaichat" [call] GetWaveAIChatCommand(client: WshClient, data: CommandGetWaveAIChatData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getwaveaichat", data, opts); return client.wshRpcCall("getwaveaichat", data, opts); } // command "getwaveaimodeconfig" [call] GetWaveAIModeConfigCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getwaveaimodeconfig", null, opts); return client.wshRpcCall("getwaveaimodeconfig", null, opts); } // command "getwaveairatelimit" [call] GetWaveAIRateLimitCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "getwaveairatelimit", null, opts); return client.wshRpcCall("getwaveairatelimit", null, opts); } // command "jobcmdexited" [call] JobCmdExitedCommand(client: WshClient, data: CommandJobCmdExitedData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcmdexited", data, opts); return client.wshRpcCall("jobcmdexited", data, opts); } // command "jobcontrollerattachjob" [call] JobControllerAttachJobCommand(client: WshClient, data: CommandJobControllerAttachJobData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollerattachjob", data, opts); return client.wshRpcCall("jobcontrollerattachjob", data, opts); } // command "jobcontrollerconnectedjobs" [call] JobControllerConnectedJobsCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollerconnectedjobs", null, opts); return client.wshRpcCall("jobcontrollerconnectedjobs", null, opts); } // command "jobcontrollerdeletejob" [call] JobControllerDeleteJobCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollerdeletejob", data, opts); return client.wshRpcCall("jobcontrollerdeletejob", data, opts); } // command "jobcontrollerdetachjob" [call] JobControllerDetachJobCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollerdetachjob", data, opts); return client.wshRpcCall("jobcontrollerdetachjob", data, opts); } // command "jobcontrollerdisconnectjob" [call] JobControllerDisconnectJobCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollerdisconnectjob", data, opts); return client.wshRpcCall("jobcontrollerdisconnectjob", data, opts); } // command "jobcontrollerexitjob" [call] JobControllerExitJobCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollerexitjob", data, opts); return client.wshRpcCall("jobcontrollerexitjob", data, opts); } // command "jobcontrollergetalljobmanagerstatus" [call] JobControllerGetAllJobManagerStatusCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollergetalljobmanagerstatus", null, opts); return client.wshRpcCall("jobcontrollergetalljobmanagerstatus", null, opts); } // command "jobcontrollerlist" [call] JobControllerListCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollerlist", null, opts); return client.wshRpcCall("jobcontrollerlist", null, opts); } // command "jobcontrollerreconnectjob" [call] JobControllerReconnectJobCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollerreconnectjob", data, opts); return client.wshRpcCall("jobcontrollerreconnectjob", data, opts); } // command "jobcontrollerreconnectjobsforconn" [call] JobControllerReconnectJobsForConnCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollerreconnectjobsforconn", data, opts); return client.wshRpcCall("jobcontrollerreconnectjobsforconn", data, opts); } // command "jobcontrollerstartjob" [call] JobControllerStartJobCommand(client: WshClient, data: CommandJobControllerStartJobData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobcontrollerstartjob", data, opts); return client.wshRpcCall("jobcontrollerstartjob", data, opts); } // command "jobinput" [call] JobInputCommand(client: WshClient, data: CommandJobInputData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobinput", data, opts); return client.wshRpcCall("jobinput", data, opts); } // command "jobprepareconnect" [call] JobPrepareConnectCommand(client: WshClient, data: CommandJobPrepareConnectData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobprepareconnect", data, opts); return client.wshRpcCall("jobprepareconnect", data, opts); } // command "jobstartstream" [call] JobStartStreamCommand(client: WshClient, data: CommandJobStartStreamData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "jobstartstream", data, opts); return client.wshRpcCall("jobstartstream", data, opts); } // command "listallappfiles" [call] ListAllAppFilesCommand(client: WshClient, data: CommandListAllAppFilesData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "listallappfiles", data, opts); return client.wshRpcCall("listallappfiles", data, opts); } // command "listallapps" [call] ListAllAppsCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "listallapps", null, opts); return client.wshRpcCall("listallapps", null, opts); } // command "listalleditableapps" [call] ListAllEditableAppsCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "listalleditableapps", null, opts); return client.wshRpcCall("listalleditableapps", null, opts); } + // command "macosversion" [call] + MacOSVersionCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "macosversion", null, opts); + return client.wshRpcCall("macosversion", null, opts); + } + // command "makedraftfromlocal" [call] MakeDraftFromLocalCommand(client: WshClient, data: CommandMakeDraftFromLocalData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "makedraftfromlocal", data, opts); return client.wshRpcCall("makedraftfromlocal", data, opts); } // command "message" [call] MessageCommand(client: WshClient, data: CommandMessageData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "message", data, opts); return client.wshRpcCall("message", data, opts); } // command "networkonline" [call] NetworkOnlineCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "networkonline", null, opts); return client.wshRpcCall("networkonline", null, opts); } // command "notify" [call] NotifyCommand(client: WshClient, data: WaveNotificationOptions, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "notify", data, opts); return client.wshRpcCall("notify", data, opts); } // command "notifysystemresume" [call] NotifySystemResumeCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "notifysystemresume", null, opts); return client.wshRpcCall("notifysystemresume", null, opts); } // command "path" [call] PathCommand(client: WshClient, data: PathCommandData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "path", data, opts); return client.wshRpcCall("path", data, opts); } // command "publishapp" [call] PublishAppCommand(client: WshClient, data: CommandPublishAppData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "publishapp", data, opts); return client.wshRpcCall("publishapp", data, opts); } // command "readappfile" [call] ReadAppFileCommand(client: WshClient, data: CommandReadAppFileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "readappfile", data, opts); return client.wshRpcCall("readappfile", data, opts); } // command "recordtevent" [call] RecordTEventCommand(client: WshClient, data: TEvent, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "recordtevent", data, opts); return client.wshRpcCall("recordtevent", data, opts); } // command "remotedisconnectfromjobmanager" [call] RemoteDisconnectFromJobManagerCommand(client: WshClient, data: CommandRemoteDisconnectFromJobManagerData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotedisconnectfromjobmanager", data, opts); return client.wshRpcCall("remotedisconnectfromjobmanager", data, opts); } // command "remotefilecopy" [call] RemoteFileCopyCommand(client: WshClient, data: CommandFileCopyData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotefilecopy", data, opts); return client.wshRpcCall("remotefilecopy", data, opts); } // command "remotefiledelete" [call] RemoteFileDeleteCommand(client: WshClient, data: CommandDeleteFileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotefiledelete", data, opts); return client.wshRpcCall("remotefiledelete", data, opts); } // command "remotefileinfo" [call] RemoteFileInfoCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotefileinfo", data, opts); return client.wshRpcCall("remotefileinfo", data, opts); } // command "remotefilejoin" [call] RemoteFileJoinCommand(client: WshClient, data: string[], opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotefilejoin", data, opts); return client.wshRpcCall("remotefilejoin", data, opts); } // command "remotefilemove" [call] RemoteFileMoveCommand(client: WshClient, data: CommandFileCopyData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotefilemove", data, opts); return client.wshRpcCall("remotefilemove", data, opts); } // command "remotefilemultiinfo" [call] RemoteFileMultiInfoCommand(client: WshClient, data: CommandRemoteFileMultiInfoData, opts?: RpcOpts): Promise<{[key: string]: FileInfo}> { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotefilemultiinfo", data, opts); return client.wshRpcCall("remotefilemultiinfo", data, opts); } // command "remotefiletouch" [call] RemoteFileTouchCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotefiletouch", data, opts); return client.wshRpcCall("remotefiletouch", data, opts); } // command "remotegetinfo" [call] RemoteGetInfoCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotegetinfo", null, opts); return client.wshRpcCall("remotegetinfo", null, opts); } // command "remoteinstallrcfiles" [call] RemoteInstallRcFilesCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remoteinstallrcfiles", null, opts); return client.wshRpcCall("remoteinstallrcfiles", null, opts); } // command "remotelistentries" [responsestream] RemoteListEntriesCommand(client: WshClient, data: CommandRemoteListEntriesData, opts?: RpcOpts): AsyncGenerator { + if (this.mockClient) return this.mockClient.mockWshRpcStream(client, "remotelistentries", data, opts); return client.wshRpcStream("remotelistentries", data, opts); } // command "remotemkdir" [call] RemoteMkdirCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotemkdir", data, opts); return client.wshRpcCall("remotemkdir", data, opts); } // command "remotereconnecttojobmanager" [call] RemoteReconnectToJobManagerCommand(client: WshClient, data: CommandRemoteReconnectToJobManagerData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotereconnecttojobmanager", data, opts); return client.wshRpcCall("remotereconnecttojobmanager", data, opts); } // command "remotestartjob" [call] RemoteStartJobCommand(client: WshClient, data: CommandRemoteStartJobData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotestartjob", data, opts); return client.wshRpcCall("remotestartjob", data, opts); } // command "remotestreamcpudata" [responsestream] RemoteStreamCpuDataCommand(client: WshClient, opts?: RpcOpts): AsyncGenerator { + if (this.mockClient) return this.mockClient.mockWshRpcStream(client, "remotestreamcpudata", null, opts); return client.wshRpcStream("remotestreamcpudata", null, opts); } // command "remotestreamfile" [responsestream] RemoteStreamFileCommand(client: WshClient, data: CommandRemoteStreamFileData, opts?: RpcOpts): AsyncGenerator { + if (this.mockClient) return this.mockClient.mockWshRpcStream(client, "remotestreamfile", data, opts); return client.wshRpcStream("remotestreamfile", data, opts); } // command "remoteterminatejobmanager" [call] RemoteTerminateJobManagerCommand(client: WshClient, data: CommandRemoteTerminateJobManagerData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remoteterminatejobmanager", data, opts); return client.wshRpcCall("remoteterminatejobmanager", data, opts); } // command "remotewritefile" [call] RemoteWriteFileCommand(client: WshClient, data: FileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "remotewritefile", data, opts); return client.wshRpcCall("remotewritefile", data, opts); } // command "renameappfile" [call] RenameAppFileCommand(client: WshClient, data: CommandRenameAppFileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "renameappfile", data, opts); return client.wshRpcCall("renameappfile", data, opts); } // command "resolveids" [call] ResolveIdsCommand(client: WshClient, data: CommandResolveIdsData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "resolveids", data, opts); return client.wshRpcCall("resolveids", data, opts); } // command "restartbuilderandwait" [call] RestartBuilderAndWaitCommand(client: WshClient, data: CommandRestartBuilderAndWaitData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "restartbuilderandwait", data, opts); return client.wshRpcCall("restartbuilderandwait", data, opts); } // command "routeannounce" [call] RouteAnnounceCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "routeannounce", null, opts); return client.wshRpcCall("routeannounce", null, opts); } // command "routeunannounce" [call] RouteUnannounceCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "routeunannounce", null, opts); return client.wshRpcCall("routeunannounce", null, opts); } // command "sendtelemetry" [call] SendTelemetryCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "sendtelemetry", null, opts); return client.wshRpcCall("sendtelemetry", null, opts); } // command "setblockfocus" [call] SetBlockFocusCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "setblockfocus", data, opts); return client.wshRpcCall("setblockfocus", data, opts); } // command "setconfig" [call] SetConfigCommand(client: WshClient, data: SettingsType, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "setconfig", data, opts); return client.wshRpcCall("setconfig", data, opts); } // command "setconnectionsconfig" [call] SetConnectionsConfigCommand(client: WshClient, data: ConnConfigRequest, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "setconnectionsconfig", data, opts); return client.wshRpcCall("setconnectionsconfig", data, opts); } // command "setmeta" [call] SetMetaCommand(client: WshClient, data: CommandSetMetaData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "setmeta", data, opts); return client.wshRpcCall("setmeta", data, opts); } // command "setpeerinfo" [call] SetPeerInfoCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "setpeerinfo", data, opts); return client.wshRpcCall("setpeerinfo", data, opts); } // command "setrtinfo" [call] SetRTInfoCommand(client: WshClient, data: CommandSetRTInfoData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "setrtinfo", data, opts); return client.wshRpcCall("setrtinfo", data, opts); } // command "setsecrets" [call] SetSecretsCommand(client: WshClient, data: {[key: string]: string}, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "setsecrets", data, opts); return client.wshRpcCall("setsecrets", data, opts); } // command "setvar" [call] SetVarCommand(client: WshClient, data: CommandVarData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "setvar", data, opts); return client.wshRpcCall("setvar", data, opts); } // command "startbuilder" [call] StartBuilderCommand(client: WshClient, data: CommandStartBuilderData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "startbuilder", data, opts); return client.wshRpcCall("startbuilder", data, opts); } // command "startjob" [call] StartJobCommand(client: WshClient, data: CommandStartJobData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "startjob", data, opts); return client.wshRpcCall("startjob", data, opts); } // command "stopbuilder" [call] StopBuilderCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "stopbuilder", data, opts); return client.wshRpcCall("stopbuilder", data, opts); } // command "streamcpudata" [responsestream] StreamCpuDataCommand(client: WshClient, data: CpuDataRequest, opts?: RpcOpts): AsyncGenerator { + if (this.mockClient) return this.mockClient.mockWshRpcStream(client, "streamcpudata", data, opts); return client.wshRpcStream("streamcpudata", data, opts); } // command "streamdata" [call] StreamDataCommand(client: WshClient, data: CommandStreamData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "streamdata", data, opts); return client.wshRpcCall("streamdata", data, opts); } // command "streamdataack" [call] StreamDataAckCommand(client: WshClient, data: CommandStreamAckData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "streamdataack", data, opts); return client.wshRpcCall("streamdataack", data, opts); } // command "streamtest" [responsestream] StreamTestCommand(client: WshClient, opts?: RpcOpts): AsyncGenerator { + if (this.mockClient) return this.mockClient.mockWshRpcStream(client, "streamtest", null, opts); return client.wshRpcStream("streamtest", null, opts); } // command "streamwaveai" [responsestream] StreamWaveAiCommand(client: WshClient, data: WaveAIStreamRequest, opts?: RpcOpts): AsyncGenerator { + if (this.mockClient) return this.mockClient.mockWshRpcStream(client, "streamwaveai", data, opts); return client.wshRpcStream("streamwaveai", data, opts); } // command "termgetscrollbacklines" [call] TermGetScrollbackLinesCommand(client: WshClient, data: CommandTermGetScrollbackLinesData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "termgetscrollbacklines", data, opts); return client.wshRpcCall("termgetscrollbacklines", data, opts); } // command "test" [call] TestCommand(client: WshClient, data: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "test", data, opts); return client.wshRpcCall("test", data, opts); } + // command "testmultiarg" [call] + TestMultiArgCommand(client: WshClient, arg1: string, arg2: number, arg3: boolean, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "testmultiarg", { args: [arg1, arg2, arg3] }, opts); + return client.wshRpcCall("testmultiarg", { args: [arg1, arg2, arg3] }, opts); + } + + // command "updatetabname" [call] + UpdateTabNameCommand(client: WshClient, arg1: string, arg2: string, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "updatetabname", { args: [arg1, arg2] }, opts); + return client.wshRpcCall("updatetabname", { args: [arg1, arg2] }, opts); + } + + // command "updateworkspacetabids" [call] + UpdateWorkspaceTabIdsCommand(client: WshClient, arg1: string, arg2: string[], opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "updateworkspacetabids", { args: [arg1, arg2] }, opts); + return client.wshRpcCall("updateworkspacetabids", { args: [arg1, arg2] }, opts); + } + // command "vdomasyncinitiation" [call] VDomAsyncInitiationCommand(client: WshClient, data: VDomAsyncInitiationRequest, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "vdomasyncinitiation", data, opts); return client.wshRpcCall("vdomasyncinitiation", data, opts); } // command "vdomcreatecontext" [call] VDomCreateContextCommand(client: WshClient, data: VDomCreateContext, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "vdomcreatecontext", data, opts); return client.wshRpcCall("vdomcreatecontext", data, opts); } // command "vdomrender" [responsestream] VDomRenderCommand(client: WshClient, data: VDomFrontendUpdate, opts?: RpcOpts): AsyncGenerator { + if (this.mockClient) return this.mockClient.mockWshRpcStream(client, "vdomrender", data, opts); return client.wshRpcStream("vdomrender", data, opts); } // command "vdomurlrequest" [responsestream] VDomUrlRequestCommand(client: WshClient, data: VDomUrlRequestData, opts?: RpcOpts): AsyncGenerator { + if (this.mockClient) return this.mockClient.mockWshRpcStream(client, "vdomurlrequest", data, opts); return client.wshRpcStream("vdomurlrequest", data, opts); } // command "waitforroute" [call] WaitForRouteCommand(client: WshClient, data: CommandWaitForRouteData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "waitforroute", data, opts); return client.wshRpcCall("waitforroute", data, opts); } // command "waveaiaddcontext" [call] WaveAIAddContextCommand(client: WshClient, data: CommandWaveAIAddContextData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "waveaiaddcontext", data, opts); return client.wshRpcCall("waveaiaddcontext", data, opts); } // command "waveaienabletelemetry" [call] WaveAIEnableTelemetryCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "waveaienabletelemetry", null, opts); return client.wshRpcCall("waveaienabletelemetry", null, opts); } // command "waveaigettooldiff" [call] WaveAIGetToolDiffCommand(client: WshClient, data: CommandWaveAIGetToolDiffData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "waveaigettooldiff", data, opts); return client.wshRpcCall("waveaigettooldiff", data, opts); } // command "waveaitoolapprove" [call] WaveAIToolApproveCommand(client: WshClient, data: CommandWaveAIToolApproveData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "waveaitoolapprove", data, opts); return client.wshRpcCall("waveaitoolapprove", data, opts); } // command "wavefilereadstream" [call] WaveFileReadStreamCommand(client: WshClient, data: CommandWaveFileReadStreamData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "wavefilereadstream", data, opts); return client.wshRpcCall("wavefilereadstream", data, opts); } // command "waveinfo" [call] WaveInfoCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "waveinfo", null, opts); return client.wshRpcCall("waveinfo", null, opts); } // command "webselector" [call] WebSelectorCommand(client: WshClient, data: CommandWebSelectorData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "webselector", data, opts); return client.wshRpcCall("webselector", data, opts); } // command "workspacelist" [call] WorkspaceListCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "workspacelist", null, opts); return client.wshRpcCall("workspacelist", null, opts); } // command "writeappfile" [call] WriteAppFileCommand(client: WshClient, data: CommandWriteAppFileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "writeappfile", data, opts); return client.wshRpcCall("writeappfile", data, opts); } // command "writeappgofile" [call] WriteAppGoFileCommand(client: WshClient, data: CommandWriteAppGoFileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "writeappgofile", data, opts); return client.wshRpcCall("writeappgofile", data, opts); } // command "writeappsecretbindings" [call] WriteAppSecretBindingsCommand(client: WshClient, data: CommandWriteAppSecretBindingsData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "writeappsecretbindings", data, opts); return client.wshRpcCall("writeappsecretbindings", data, opts); } // command "writetempfile" [call] WriteTempFileCommand(client: WshClient, data: CommandWriteTempFileData, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "writetempfile", data, opts); return client.wshRpcCall("writetempfile", data, opts); } // command "wshactivity" [call] WshActivityCommand(client: WshClient, data: {[key: string]: number}, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "wshactivity", data, opts); return client.wshRpcCall("wshactivity", data, opts); } // command "wsldefaultdistro" [call] WslDefaultDistroCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "wsldefaultdistro", null, opts); return client.wshRpcCall("wsldefaultdistro", null, opts); } // command "wsllist" [call] WslListCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "wsllist", null, opts); return client.wshRpcCall("wsllist", null, opts); } // command "wslstatus" [call] WslStatusCommand(client: WshClient, opts?: RpcOpts): Promise { + if (this.mockClient) return this.mockClient.mockWshRpcCall(client, "wslstatus", null, opts); return client.wshRpcCall("wslstatus", null, opts); } diff --git a/frontend/app/tab/tab.scss b/frontend/app/tab/tab.scss index 3739752ee..ad10fc814 100644 --- a/frontend/app/tab/tab.scss +++ b/frontend/app/tab/tab.scss @@ -1,10 +1,10 @@ -// Copyright 2024, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 .tab { position: absolute; width: 130px; - height: calc(100% - 1px); + height: calc(100% - 3px); padding: 0 0 0 0; box-sizing: border-box; font-weight: bold; @@ -14,13 +14,12 @@ align-items: center; justify-content: center; - &::after { - content: ""; + .tab-divider { position: absolute; left: 0; width: 1px; height: 14px; - border-right: 1px solid rgb(from var(--main-text-color) r g b / 0.2); + background: rgb(from var(--main-text-color) r g b / 0.2); } .tab-inner { @@ -45,19 +44,11 @@ } .name { - color: var(--main-text-color); - } - - & + .tab::after, - &::after { - content: none; + color: rgba(255, 255, 255, 1); + font-weight: 600; } } - &:first-child::after { - content: none; - } - .name { position: absolute; top: 50%; @@ -81,21 +72,6 @@ } } - .tab-indicator { - position: absolute; - top: 50%; - left: 4px; - transform: translate3d(0, -50%, 0); - width: 20px; - height: 20px; - display: flex; - align-items: center; - justify-content: center; - z-index: var(--zindex-tab-name); - padding: 1px 2px; - transition: none !important; - } - .wave-button { position: absolute; top: 50%; @@ -118,11 +94,17 @@ } // Only apply hover effects when not in nohover mode. This prevents the previously-hovered tab from remaining hovered while a tab view is not mounted. +body:not(.nohover) .tab:hover + .tab, +body:not(.nohover) .tab.dragging + .tab { + .tab-divider { + display: none; + } +} + body:not(.nohover) .tab:hover, body:not(.nohover) .tab.dragging { - & + .tab::after, - &::after { - content: none; + .tab-divider { + display: none; } .tab-inner { @@ -157,53 +139,3 @@ body.nohover .tab.active .close { animation: expandWidthAndFadeIn 0.1s forwards; } -@keyframes jigglePinIcon { - 0% { - transform: rotate(0deg); - color: inherit; - } - 10% { - transform: rotate(-30deg); - color: rgb(255, 193, 7); - } - 20% { - transform: rotate(30deg); - color: rgb(255, 193, 7); - } - 30% { - transform: rotate(-30deg); - color: rgb(255, 193, 7); - } - 40% { - transform: rotate(30deg); - color: rgb(255, 193, 7); - } - 50% { - transform: rotate(-15deg); - color: rgb(255, 193, 7); - } - 60% { - transform: rotate(15deg); - color: rgb(255, 193, 7); - } - 70% { - transform: rotate(-15deg); - color: rgb(255, 193, 7); - } - 80% { - transform: rotate(15deg); - color: rgb(255, 193, 7); - } - 90% { - transform: rotate(0deg); - color: rgb(255, 193, 7); - } - 100% { - transform: rotate(0deg); - color: inherit; - } -} - -.pin.jiggling i { - animation: jigglePinIcon 0.5s ease-in-out; -} diff --git a/frontend/app/tab/tab.tsx b/frontend/app/tab/tab.tsx index 37a96ca52..7b2aa6856 100644 --- a/frontend/app/tab/tab.tsx +++ b/frontend/app/tab/tab.tsx @@ -1,37 +1,46 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import { - atoms, - clearAllTabIndicators, - clearTabIndicatorFromFocus, - getTabIndicatorAtom, - globalStore, - recordTEvent, - refocusNode, - setTabIndicator, -} from "@/app/store/global"; -import { RpcApi } from "@/app/store/wshclientapi"; +import { getTabBadgeAtom } from "@/app/store/badge"; +import { refocusNode } from "@/app/store/global"; import { TabRpcClient } from "@/app/store/wshrpcutil"; +import { WaveEnv, WaveEnvSubset, useWaveEnv } from "@/app/waveenv/waveenv"; import { Button } from "@/element/button"; -import { ContextMenuModel } from "@/store/contextmenu"; -import { fireAndForget, makeIconClass } from "@/util/util"; +import { validateCssColor } from "@/util/color-validator"; +import { fireAndForget } from "@/util/util"; import clsx from "clsx"; import { useAtomValue } from "jotai"; import { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react"; -import { ObjectService } from "../store/services"; -import { makeORef, useWaveObjectValue } from "../store/wos"; +import { makeORef } from "../store/wos"; +import { TabBadges } from "./tabbadges"; import "./tab.scss"; +import { buildTabContextMenu } from "./tabcontextmenu"; + +export type TabEnv = WaveEnvSubset<{ + rpc: { + ActivityCommand: WaveEnv["rpc"]["ActivityCommand"]; + SetConfigCommand: WaveEnv["rpc"]["SetConfigCommand"]; + SetMetaCommand: WaveEnv["rpc"]["SetMetaCommand"]; + UpdateTabNameCommand: WaveEnv["rpc"]["UpdateTabNameCommand"]; + }; + atoms: { + fullConfigAtom: WaveEnv["atoms"]["fullConfigAtom"]; + }; + wos: WaveEnv["wos"]; + getSettingsKeyAtom: WaveEnv["getSettingsKeyAtom"]; + showContextMenu: WaveEnv["showContextMenu"]; +}>; interface TabVProps { tabId: string; tabName: string; active: boolean; - isBeforeActive: boolean; + showDivider: boolean; isDragging: boolean; tabWidth: number; isNew: boolean; - indicator?: TabIndicator | null; + badges?: Badge[] | null; + flagColor?: string | null; onClick: () => void; onClose: (event: React.MouseEvent | null) => void; onDragStart: (event: React.MouseEvent) => void; @@ -46,11 +55,12 @@ const TabV = forwardRef((props, ref) => { tabId, tabName, active, - isBeforeActive, + showDivider, isDragging, tabWidth, isNew, - indicator, + badges, + flagColor, onClick, onClose, onDragStart, @@ -58,7 +68,10 @@ const TabV = forwardRef((props, ref) => { onRename, renameRef, } = props; - const [originalName, setOriginalName] = useState(tabName); + const MaxTabNameLength = 14; + const truncateTabName = (name: string) => [...(name ?? "")].slice(0, MaxTabNameLength).join(""); + const displayName = truncateTabName(tabName); + const [originalName, setOriginalName] = useState(displayName); const [isEditable, setIsEditable] = useState(false); const editableRef = useRef(null); @@ -68,7 +81,7 @@ const TabV = forwardRef((props, ref) => { useImperativeHandle(ref, () => tabRef.current as HTMLDivElement); useEffect(() => { - setOriginalName(tabName); + setOriginalName(truncateTabName(tabName)); }, [tabName]); useEffect(() => { @@ -144,8 +157,11 @@ const TabV = forwardRef((props, ref) => { event.preventDefault(); event.stopPropagation(); } else if (curLen >= 14 && !["Backspace", "Delete", "ArrowLeft", "ArrowRight"].includes(event.key)) { - event.preventDefault(); - event.stopPropagation(); + const selection = window.getSelection(); + if (!selection || selection.isCollapsed) { + event.preventDefault(); + event.stopPropagation(); + } } }; @@ -167,7 +183,6 @@ const TabV = forwardRef((props, ref) => { className={clsx("tab", { active, dragging: isDragging, - "before-active": isBeforeActive, "new-tab": isNew, })} onMouseDown={onDragStart} @@ -175,6 +190,7 @@ const TabV = forwardRef((props, ref) => { onContextMenu={onContextMenu} data-tab-id={tabId} > + {showDivider &&
}
((props, ref) => { onKeyDown={handleKeyDown} suppressContentEditableWarning={true} > - {tabName} + {displayName}
- {indicator && ( -
- -
- )} + - ); -}; - function strArrayIsEqual(a: string[], b: string[]) { // null check if (a == null && b == null) { @@ -150,25 +94,8 @@ function strArrayIsEqual(a: string[], b: string[]) { return true; } -function setIsEqual(a: Set | null, b: Set | null): boolean { - if (a == null && b == null) { - return true; - } - if (a == null || b == null) { - return false; - } - if (a.size !== b.size) { - return false; - } - for (const item of a) { - if (!b.has(item)) { - return false; - } - } - return true; -} - -const TabBar = memo(({ workspace }: TabBarProps) => { +const TabBar = memo(({ workspace, noTabs }: TabBarProps) => { + const env = useWaveEnv(); const [tabIds, setTabIds] = useState([]); const [dragStartPositions, setDragStartPositions] = useState([]); const [draggingTab, setDraggingTab] = useState(); @@ -193,19 +120,20 @@ const TabBar = memo(({ workspace }: TabBarProps) => { }); const osInstanceRef = useRef(null); const draggerLeftRef = useRef(null); - const draggerRightRef = useRef(null); + const rightContainerRef = useRef(null); const workspaceSwitcherRef = useRef(null); const waveAIButtonRef = useRef(null); const appMenuButtonRef = useRef(null); const tabWidthRef = useRef(TabDefaultWidth); const scrollableRef = useRef(false); - const updateStatusBannerRef = useRef(null); - const configErrorButtonRef = useRef(null); const prevAllLoadedRef = useRef(false); - const activeTabId = useAtomValue(atoms.staticTabId); - const isFullScreen = useAtomValue(atoms.isFullScreen); - const zoomFactor = useAtomValue(atoms.zoomFactorAtom); - const settings = useAtomValue(atoms.settingsAtom); + const activeTabId = useAtomValue(env.atoms.staticTabId); + const isFullScreen = useAtomValue(env.atoms.isFullScreen); + const zoomFactor = useAtomValue(env.atoms.zoomFactorAtom); + const showMenuBar = useAtomValue(env.getSettingsKeyAtom("window:showmenubar")); + const confirmClose = useAtomValue(env.getSettingsKeyAtom("tab:confirmclose")) ?? false; + const hideAiButton = useAtomValue(env.getSettingsKeyAtom("app:hideaibutton")); + const appUpdateStatus = useAtomValue(env.atoms.updaterStatusAtom); let prevDelta: number; let prevDragDirection: string; @@ -249,22 +177,24 @@ const TabBar = memo(({ workspace }: TabBarProps) => { const tabBar = tabBarRef.current; if (tabBar === null) return; + const getOuterWidth = (el: HTMLElement): number => { + const rect = el.getBoundingClientRect(); + const style = getComputedStyle(el); + return rect.width + parseFloat(style.marginLeft) + parseFloat(style.marginRight); + }; + const tabbarWrapperWidth = tabbarWrapperRef.current.getBoundingClientRect().width; const windowDragLeftWidth = draggerLeftRef.current.getBoundingClientRect().width; - const windowDragRightWidth = draggerRightRef.current?.getBoundingClientRect().width ?? 0; - const addBtnWidth = addBtnRef.current.getBoundingClientRect().width; - const updateStatusLabelWidth = updateStatusBannerRef.current?.getBoundingClientRect().width ?? 0; - const configErrorWidth = configErrorButtonRef.current?.getBoundingClientRect().width ?? 0; + const rightContainerWidth = rightContainerRef.current?.getBoundingClientRect().width ?? 0; + const addBtnWidth = getOuterWidth(addBtnRef.current); const appMenuButtonWidth = appMenuButtonRef.current?.getBoundingClientRect().width ?? 0; const workspaceSwitcherWidth = workspaceSwitcherRef.current?.getBoundingClientRect().width ?? 0; - const waveAIButtonWidth = waveAIButtonRef.current?.getBoundingClientRect().width ?? 0; + const waveAIButtonWidth = waveAIButtonRef.current != null ? getOuterWidth(waveAIButtonRef.current) : 0; const nonTabElementsWidth = windowDragLeftWidth + - windowDragRightWidth + + rightContainerWidth + addBtnWidth + - updateStatusLabelWidth + - configErrorWidth + appMenuButtonWidth + workspaceSwitcherWidth + waveAIButtonWidth; @@ -325,20 +255,23 @@ const TabBar = memo(({ workspace }: TabBarProps) => { saveTabsPositionDebounced(); }, [tabIds, newTabId, isFullScreen]); - const reinitVersion = useAtomValue(atoms.reinitVersion); + // update layout on reinit version + const reinitVersion = useAtomValue(env.atoms.reinitVersion); useEffect(() => { if (reinitVersion > 0) { setSizeAndPosition(); } }, [reinitVersion]); + // update layout on resize useEffect(() => { - window.addEventListener("resize", () => handleResizeTabs()); + window.addEventListener("resize", handleResizeTabs); return () => { - window.removeEventListener("resize", () => handleResizeTabs()); + window.removeEventListener("resize", handleResizeTabs); }; }, [handleResizeTabs]); + // update layout on changed tabIds, tabsLoaded, newTabId, hideAiButton, appUpdateStatus, or zoomFactor useEffect(() => { // Check if all tabs are loaded const allLoaded = tabIds.length > 0 && tabIds.every((id) => tabsLoaded[id]); @@ -349,7 +282,16 @@ const TabBar = memo(({ workspace }: TabBarProps) => { prevAllLoadedRef.current = true; } } - }, [tabIds, tabsLoaded, newTabId, saveTabsPosition]); + }, [ + tabIds, + tabsLoaded, + newTabId, + saveTabsPosition, + hideAiButton, + appUpdateStatus, + zoomFactor, + showMenuBar, + ]); const getDragDirection = (currentX: number) => { let dragDirection: string; @@ -502,12 +444,12 @@ const TabBar = memo(({ workspace }: TabBarProps) => { // Reset dragging state setDraggingTab(null); // Update workspace tab ids - fireAndForget(() => WorkspaceService.UpdateTabIds(workspace.oid, tabIds)); + fireAndForget(() => env.rpc.UpdateWorkspaceTabIdsCommand(TabRpcClient, workspace.oid, tabIds)); }), [] ); - const handleMouseUp = (event: MouseEvent) => { + const handleMouseUp = (_event: MouseEvent) => { const { tabIndex, dragged } = draggingTabDataRef.current; // Update the final position of the dragged tab @@ -566,7 +508,7 @@ const TabBar = memo(({ workspace }: TabBarProps) => { const handleSelectTab = (tabId: string) => { if (!draggingTabDataRef.current.dragged) { - setActiveTab(tabId); + env.electron.setActiveTab(tabId); } }; @@ -588,7 +530,7 @@ const TabBar = memo(({ workspace }: TabBarProps) => { ); const handleAddTab = () => { - createTab(); + env.electron.createTab(); tabsWrapperRef.current.style.setProperty("--tabs-wrapper-transition", "width 0.1s ease"); updateScrollDebounced(); @@ -598,10 +540,8 @@ const TabBar = memo(({ workspace }: TabBarProps) => { const handleCloseTab = (event: React.MouseEvent | null, tabId: string) => { event?.stopPropagation(); - const ws = globalStore.get(atoms.workspace); - const confirmClose = globalStore.get(getSettingsKeyAtom("tab:confirmclose")) ?? false; - getApi() - .closeTab(ws.oid, tabId, confirmClose) + env.electron + .closeTab(workspace.oid, tabId, confirmClose) .then((didClose) => { if (didClose) { tabsWrapperRef.current?.style.setProperty("--tabs-wrapper-transition", "width 0.3s ease"); @@ -623,30 +563,31 @@ const TabBar = memo(({ workspace }: TabBarProps) => { }); }, []); - const isBeforeActive = (tabId: string) => { - return tabIds.indexOf(tabId) === tabIds.indexOf(activeTabId) - 1; - }; + const activeTabIndex = tabIds.indexOf(activeTabId); function onEllipsisClick() { - getApi().showWorkspaceAppMenu(workspace.oid); + env.electron.showWorkspaceAppMenu(workspace.oid); } const tabsWrapperWidth = tabIds.length * tabWidthRef.current; - const showAppMenuButton = isWindows() || (!isMacOS() && !settings["window:showmenubar"]); + const showAppMenuButton = env.isWindows() || (!env.isMacOS() && !showMenuBar); // Calculate window drag left width based on platform and state let windowDragLeftWidth = 10; - if (isMacOS() && !isFullScreen) { + if (env.isMacOS() && !isFullScreen) { + const trafficLightsWidth = isMacOSTahoeOrLater() + ? MacOSTahoeTrafficLightsWidth + : MacOSTrafficLightsWidth; if (zoomFactor > 0) { - windowDragLeftWidth = 74 / zoomFactor; + windowDragLeftWidth = trafficLightsWidth / zoomFactor; } else { - windowDragLeftWidth = 74; + windowDragLeftWidth = trafficLightsWidth; } } // Calculate window drag right width - let windowDragRightWidth = 6; - if (isWindows()) { + let windowDragRightWidth = 12; + if (env.isWindows()) { if (zoomFactor > 0) { windowDragRightWidth = 139 / zoomFactor; } else { @@ -654,12 +595,6 @@ const TabBar = memo(({ workspace }: TabBarProps) => { } } - const addtabButtonDecl: IconButtonDecl = { - elemtype: "iconbutton", - icon: "plus", - click: handleAddTab, - title: "Add Tab", - }; return (
{ placement="bottom" hideOnClick divRef={workspaceSwitcherRef} - divClassName="flex items-center h-full" + divClassName="flex items-center" >
-
- {tabIds.map((tabId, index) => { - return ( - handleSelectTab(tabId)} - active={activeTabId === tabId} - onDragStart={(event) => handleDragStart(event, tabId, tabRefs.current[index])} - onClose={(event) => handleCloseTab(event, tabId)} - onLoaded={() => handleTabLoaded(tabId)} - isBeforeActive={isBeforeActive(tabId)} - isDragging={draggingTab === tabId} - tabWidth={tabWidthRef.current} - isNew={tabId === newTabId} - /> - ); - })} +
+ {!noTabs && + tabIds.map((tabId, index) => { + const isActive = activeTabId === tabId; + const showDivider = index !== 0 && !isActive && index !== activeTabIndex + 1; + return ( + handleSelectTab(tabId)} + active={isActive} + onDragStart={(event) => handleDragStart(event, tabId, tabRefs.current[index])} + onClose={(event) => handleCloseTab(event, tabId)} + onLoaded={() => handleTabLoaded(tabId)} + isDragging={draggingTab === tabId} + tabWidth={tabWidthRef.current} + isNew={tabId === newTabId} + /> + ); + })}
- -
- - + +
+
+
@@ -724,4 +675,4 @@ const TabBar = memo(({ workspace }: TabBarProps) => { ); }); -export { TabBar }; +export { TabBar, WaveAIButton }; diff --git a/frontend/app/tab/tabbarenv.ts b/frontend/app/tab/tabbarenv.ts new file mode 100644 index 000000000..e44b344b6 --- /dev/null +++ b/frontend/app/tab/tabbarenv.ts @@ -0,0 +1,36 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { SettingsKeyAtomFnType, WaveEnv, WaveEnvSubset } from "@/app/waveenv/waveenv"; + +export type TabBarEnv = WaveEnvSubset<{ + electron: { + createTab: WaveEnv["electron"]["createTab"]; + closeTab: WaveEnv["electron"]["closeTab"]; + setActiveTab: WaveEnv["electron"]["setActiveTab"]; + showWorkspaceAppMenu: WaveEnv["electron"]["showWorkspaceAppMenu"]; + installAppUpdate: WaveEnv["electron"]["installAppUpdate"]; + }; + rpc: { + ActivityCommand: WaveEnv["rpc"]["ActivityCommand"]; + SetConfigCommand: WaveEnv["rpc"]["SetConfigCommand"]; + SetMetaCommand: WaveEnv["rpc"]["SetMetaCommand"]; + UpdateTabNameCommand: WaveEnv["rpc"]["UpdateTabNameCommand"]; + UpdateWorkspaceTabIdsCommand: WaveEnv["rpc"]["UpdateWorkspaceTabIdsCommand"]; + }; + atoms: { + fullConfigAtom: WaveEnv["atoms"]["fullConfigAtom"]; + hasConfigErrors: WaveEnv["atoms"]["hasConfigErrors"]; + staticTabId: WaveEnv["atoms"]["staticTabId"]; + isFullScreen: WaveEnv["atoms"]["isFullScreen"]; + zoomFactorAtom: WaveEnv["atoms"]["zoomFactorAtom"]; + reinitVersion: WaveEnv["atoms"]["reinitVersion"]; + updaterStatusAtom: WaveEnv["atoms"]["updaterStatusAtom"]; + }; + wos: WaveEnv["wos"]; + getSettingsKeyAtom: SettingsKeyAtomFnType<"app:hideaibutton" | "app:tabbar" | "tab:confirmclose" | "window:showmenubar">; + showContextMenu: WaveEnv["showContextMenu"]; + mockSetWaveObj: WaveEnv["mockSetWaveObj"]; + isWindows: WaveEnv["isWindows"]; + isMacOS: WaveEnv["isMacOS"]; +}>; diff --git a/frontend/app/tab/tabcontent.tsx b/frontend/app/tab/tabcontent.tsx index 246334d1a..022f3ef8e 100644 --- a/frontend/app/tab/tabcontent.tsx +++ b/frontend/app/tab/tabcontent.tsx @@ -17,7 +17,7 @@ const tileGapSizeAtom = atom((get) => { return settings["window:tilegapsize"]; }); -const TabContent = React.memo(({ tabId }: { tabId: string }) => { +const TabContent = React.memo(({ tabId, noTopPadding }: { tabId: string; noTopPadding?: boolean }) => { const oref = useMemo(() => WOS.makeORef("tab", tabId), [tabId]); const loadingAtom = useMemo(() => WOS.getWaveObjectLoadingAtom(oref), [oref]); const tabLoading = useAtomValue(loadingAtom); @@ -67,7 +67,7 @@ const TabContent = React.memo(({ tabId }: { tabId: string }) => { } return ( -
+
{innerContent}
); diff --git a/frontend/app/tab/tabcontextmenu.ts b/frontend/app/tab/tabcontextmenu.ts new file mode 100644 index 000000000..5f70bc9b9 --- /dev/null +++ b/frontend/app/tab/tabcontextmenu.ts @@ -0,0 +1,110 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { getOrefMetaKeyAtom, globalStore, recordTEvent } from "@/app/store/global"; +import { TabRpcClient } from "@/app/store/wshrpcutil"; +import { fireAndForget } from "@/util/util"; +import { makeORef } from "../store/wos"; +import type { TabEnv } from "./tab"; + +const FlagColors: { label: string; value: string }[] = [ + { label: "Green", value: "#58C142" }, + { label: "Teal", value: "#00FFDB" }, + { label: "Blue", value: "#429DFF" }, + { label: "Purple", value: "#BF55EC" }, + { label: "Red", value: "#FF453A" }, + { label: "Orange", value: "#FF9500" }, + { label: "Yellow", value: "#FFE900" }, +]; + +export function buildTabBarContextMenu(env: TabEnv): ContextMenuItem[] { + const currentTabBar = globalStore.get(env.getSettingsKeyAtom("app:tabbar")) ?? "top"; + const tabBarSubmenu: ContextMenuItem[] = [ + { + label: "Top", + type: "checkbox", + checked: currentTabBar === "top", + click: () => fireAndForget(() => env.rpc.SetConfigCommand(TabRpcClient, { "app:tabbar": "top" })), + }, + { + label: "Left", + type: "checkbox", + checked: currentTabBar === "left", + click: () => fireAndForget(() => env.rpc.SetConfigCommand(TabRpcClient, { "app:tabbar": "left" })), + }, + ]; + return [{ label: "Tab Bar Position", type: "submenu", submenu: tabBarSubmenu }]; +} + +export function buildTabContextMenu( + id: string, + renameRef: React.RefObject<(() => void) | null>, + onClose: (event: React.MouseEvent | null) => void, + env: TabEnv +): ContextMenuItem[] { + const menu: ContextMenuItem[] = []; + menu.push( + { label: "Rename Tab", click: () => renameRef.current?.() }, + { + label: "Copy TabId", + click: () => fireAndForget(() => navigator.clipboard.writeText(id)), + }, + { type: "separator" } + ); + const tabORef = makeORef("tab", id); + const currentFlagColor = globalStore.get(getOrefMetaKeyAtom(tabORef, "tab:flagcolor")) ?? null; + const flagSubmenu: ContextMenuItem[] = [ + { + label: "None", + type: "checkbox", + checked: currentFlagColor == null, + click: () => + fireAndForget(() => + env.rpc.SetMetaCommand(TabRpcClient, { oref: tabORef, meta: { "tab:flagcolor": null } }) + ), + }, + ...FlagColors.map((fc) => ({ + label: fc.label, + type: "checkbox" as const, + checked: currentFlagColor === fc.value, + click: () => + fireAndForget(() => + env.rpc.SetMetaCommand(TabRpcClient, { oref: tabORef, meta: { "tab:flagcolor": fc.value } }) + ), + })), + ]; + menu.push({ label: "Flag Tab", type: "submenu", submenu: flagSubmenu }, { type: "separator" }); + const fullConfig = globalStore.get(env.atoms.fullConfigAtom); + const bgPresets: string[] = []; + for (const key in fullConfig?.presets ?? {}) { + if (key.startsWith("bg@") && fullConfig.presets[key] != null) { + bgPresets.push(key); + } + } + bgPresets.sort((a, b) => { + const aOrder = fullConfig.presets[a]["display:order"] ?? 0; + const bOrder = fullConfig.presets[b]["display:order"] ?? 0; + return aOrder - bOrder; + }); + if (bgPresets.length > 0) { + const submenu: ContextMenuItem[] = []; + const oref = makeORef("tab", id); + for (const presetName of bgPresets) { + // preset cannot be null (filtered above) + const preset = fullConfig.presets[presetName]; + submenu.push({ + label: preset["display:name"] ?? presetName, + click: () => + fireAndForget(async () => { + await env.rpc.SetMetaCommand(TabRpcClient, { oref, meta: preset }); + env.rpc.ActivityCommand(TabRpcClient, { settabtheme: 1 }, { noresponse: true }); + recordTEvent("action:settabtheme"); + }), + }); + } + menu.push({ label: "Backgrounds", type: "submenu", submenu }, { type: "separator" }); + } + menu.push(...buildTabBarContextMenu(env), { type: "separator" }); + menu.push({ label: "Close Tab", click: () => onClose(null) }); + return menu; +} diff --git a/frontend/app/tab/updatebanner.tsx b/frontend/app/tab/updatebanner.tsx index e14cc561b..b58955828 100644 --- a/frontend/app/tab/updatebanner.tsx +++ b/frontend/app/tab/updatebanner.tsx @@ -1,69 +1,62 @@ -import { Button } from "@/element/button"; -import { atoms, getApi } from "@/store/global"; +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { Tooltip } from "@/element/tooltip"; +import { WaveEnv, WaveEnvSubset, useWaveEnv } from "@/app/waveenv/waveenv"; import { useAtomValue } from "jotai"; -import { forwardRef, memo, useEffect, useState } from "react"; +import { memo, useCallback } from "react"; -const UpdateStatusBannerComponent = forwardRef((_, ref) => { - let appUpdateStatus = useAtomValue(atoms.updaterStatusAtom); - let [updateStatusMessage, setUpdateStatusMessage] = useState(); - const [dismissBannerTimeout, setDismissBannerTimeout] = useState(); +type UpdateBannerEnv = WaveEnvSubset<{ + electron: { + installAppUpdate: WaveEnv["electron"]["installAppUpdate"]; + }; + atoms: { + updaterStatusAtom: WaveEnv["atoms"]["updaterStatusAtom"]; + }; +}>; - useEffect(() => { - let message: string; - let dismissBanner = false; - switch (appUpdateStatus) { - case "ready": - message = "Update Available"; - break; - case "downloading": - message = "Downloading Update"; - break; - case "installing": - message = "Installing Update"; - break; - case "error": - message = "Updater Error: Try Checking Again"; - dismissBanner = true; - break; - default: - break; - } - setUpdateStatusMessage(message); +function getUpdateStatusMessage(status: string): string { + switch (status) { + case "ready": + return "Update"; + case "downloading": + return "Downloading"; + case "installing": + return "Installing"; + default: + return null; + } +} - // Clear any existing timeout - if (dismissBannerTimeout) { - clearTimeout(dismissBannerTimeout); - } +const UpdateStatusBannerComponent = () => { + const env = useWaveEnv(); + const appUpdateStatus = useAtomValue(env.atoms.updaterStatusAtom); + const updateStatusMessage = getUpdateStatusMessage(appUpdateStatus); - // If we want to dismiss the banner, set the new timeout, otherwise clear the state - if (dismissBanner) { - setDismissBannerTimeout( - setTimeout(() => { - setUpdateStatusMessage(null); - setDismissBannerTimeout(null); - }, 10000) - ); - } else { - setDismissBannerTimeout(null); - } - }, [appUpdateStatus]); + const onClick = useCallback(() => { + env.electron.installAppUpdate(); + }, [env]); - function onClick() { - getApi().installAppUpdate(); - } - if (updateStatusMessage) { - return ( - - ); + if (!updateStatusMessage) { + return null; } -}); -export const UpdateStatusBanner = memo(UpdateStatusBannerComponent) as typeof UpdateStatusBannerComponent; + const isReady = appUpdateStatus === "ready"; + const tooltipContent = isReady ? "Click to Install Update" : updateStatusMessage; + + return ( + + + {updateStatusMessage} + + ); +}; +UpdateStatusBannerComponent.displayName = "UpdateStatusBannerComponent"; + +export const UpdateStatusBanner = memo(UpdateStatusBannerComponent); diff --git a/frontend/app/tab/vtab.test.tsx b/frontend/app/tab/vtab.test.tsx new file mode 100644 index 000000000..b995b6a72 --- /dev/null +++ b/frontend/app/tab/vtab.test.tsx @@ -0,0 +1,63 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { renderToStaticMarkup } from "react-dom/server"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { VTab, VTabItem } from "./vtab"; + +const OriginalCss = globalThis.CSS; +const HexColorRegex = /^#([\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i; + +function renderVTab(tab: VTabItem): string { + return renderToStaticMarkup( + null} + onDragStart={() => null} + onDragOver={() => null} + onDrop={() => null} + onDragEnd={() => null} + /> + ); +} + +describe("VTab badges", () => { + beforeAll(() => { + globalThis.CSS = { + supports: (_property: string, value: string) => HexColorRegex.test(value), + } as typeof CSS; + }); + + afterAll(() => { + globalThis.CSS = OriginalCss; + }); + + it("renders shared badges and a validated flag badge", () => { + const markup = renderVTab({ + id: "tab-1", + name: "Build Logs", + badges: [{ badgeid: "badge-1", icon: "bell", color: "#f59e0b", priority: 2 }], + flagColor: "#429DFF", + }); + + expect(markup).toContain("#429DFF"); + expect(markup).toContain("#f59e0b"); + expect(markup).toContain("rounded-full"); + }); + + it("ignores invalid flag colors", () => { + const markup = renderVTab({ + id: "tab-2", + name: "Deploy", + badges: [{ badgeid: "badge-2", icon: "bell", color: "#4ade80", priority: 2 }], + flagColor: "definitely-not-a-color", + }); + + expect(markup).not.toContain("definitely-not-a-color"); + expect(markup).not.toContain("fa-flag"); + expect(markup).toContain("#4ade80"); + }); +}); diff --git a/frontend/app/tab/vtab.tsx b/frontend/app/tab/vtab.tsx new file mode 100644 index 000000000..7edd7b0f4 --- /dev/null +++ b/frontend/app/tab/vtab.tsx @@ -0,0 +1,221 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { validateCssColor } from "@/util/color-validator"; +import { cn } from "@/util/util"; +import { useCallback, useEffect, useRef, useState } from "react"; +import { TabBadges } from "./tabbadges"; + +const RenameFocusDelayMs = 50; + +export interface VTabItem { + id: string; + name: string; + badge?: Badge | null; + badges?: Badge[] | null; + flagColor?: string | null; +} + +interface VTabProps { + tab: VTabItem; + active: boolean; + showDivider?: boolean; + isDragging: boolean; + isReordering: boolean; + onSelect: () => void; + onClose?: () => void; + onRename?: (newName: string) => void; + onContextMenu?: (event: React.MouseEvent) => void; + onDragStart: (event: React.DragEvent) => void; + onDragOver: (event: React.DragEvent) => void; + onDrop: (event: React.DragEvent) => void; + onDragEnd: () => void; + onHoverChanged?: (isHovered: boolean) => void; + renameRef?: React.RefObject<(() => void) | null>; +} + +export function VTab({ + tab, + active, + showDivider = true, + isDragging, + isReordering, + onSelect, + onClose, + onRename, + onContextMenu, + onDragStart, + onDragOver, + onDrop, + onDragEnd, + onHoverChanged, + renameRef, +}: VTabProps) { + const [originalName, setOriginalName] = useState(tab.name); + const [isEditable, setIsEditable] = useState(false); + const editableRef = useRef(null); + const editableTimeoutRef = useRef(null); + const badges = tab.badges ?? (tab.badge ? [tab.badge] : null); + + const rawFlagColor = tab.flagColor; + let flagColor: string | null = null; + if (rawFlagColor) { + try { + validateCssColor(rawFlagColor); + flagColor = rawFlagColor; + } catch { + flagColor = null; + } + } + + useEffect(() => { + setOriginalName(tab.name); + }, [tab.name]); + + useEffect(() => { + return () => { + if (editableTimeoutRef.current) { + clearTimeout(editableTimeoutRef.current); + } + }; + }, []); + + const selectEditableText = useCallback(() => { + if (!editableRef.current) { + return; + } + editableRef.current.focus(); + const range = document.createRange(); + const selection = window.getSelection(); + if (!selection) { + return; + } + range.selectNodeContents(editableRef.current); + selection.removeAllRanges(); + selection.addRange(range); + }, []); + + const startRename = useCallback(() => { + if (onRename == null || isReordering) { + return; + } + if (editableTimeoutRef.current) { + clearTimeout(editableTimeoutRef.current); + } + setIsEditable(true); + editableTimeoutRef.current = setTimeout(() => { + selectEditableText(); + }, RenameFocusDelayMs); + }, [isReordering, onRename, selectEditableText]); + + if (renameRef != null) { + renameRef.current = startRename; + } + + const handleBlur = () => { + if (!editableRef.current) { + return; + } + const newText = editableRef.current.textContent?.trim() || originalName; + editableRef.current.textContent = newText; + setIsEditable(false); + if (newText !== originalName) { + onRename?.(newText); + } + }; + + const handleKeyDown: React.KeyboardEventHandler = (event) => { + if (!editableRef.current) { + return; + } + if (event.key === "Enter") { + event.preventDefault(); + event.stopPropagation(); + editableRef.current.blur(); + return; + } + if (event.key !== "Escape") { + return; + } + editableRef.current.textContent = originalName; + editableRef.current.blur(); + event.preventDefault(); + event.stopPropagation(); + }; + + return ( +
{ + event.stopPropagation(); + startRename(); + }} + onContextMenu={onContextMenu} + onDragStart={onDragStart} + onDragOver={onDragOver} + onDrop={onDrop} + onDragEnd={onDragEnd} + onMouseEnter={() => onHoverChanged?.(true)} + onMouseLeave={() => onHoverChanged?.(false)} + className={cn( + "group relative flex h-9 w-full shrink-0 cursor-pointer items-center pl-3 text-xs transition-colors select-none", + "whitespace-nowrap", + active ? "text-primary" : isReordering ? "text-secondary" : "text-secondary hover:text-primary", + isDragging && "opacity-50" + )} + > + {active && ( +
+ )} + {!active && !isReordering && ( +
+ )} +
+ +
+ {tab.name} +
+ {onClose && ( + + )} +
+ ); +} diff --git a/frontend/app/tab/vtabbar.tsx b/frontend/app/tab/vtabbar.tsx new file mode 100644 index 000000000..f8cbc751f --- /dev/null +++ b/frontend/app/tab/vtabbar.tsx @@ -0,0 +1,424 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { Tooltip } from "@/app/element/tooltip"; +import { getTabBadgeAtom } from "@/app/store/badge"; +import { makeORef } from "@/app/store/wos"; +import { TabRpcClient } from "@/app/store/wshrpcutil"; +import { useWaveEnv } from "@/app/waveenv/waveenv"; +import { WorkspaceLayoutModel } from "@/app/workspace/workspace-layout-model"; +import { validateCssColor } from "@/util/color-validator"; +import { cn, fireAndForget } from "@/util/util"; +import { useAtomValue } from "jotai"; +import { memo, useCallback, useEffect, useRef, useState } from "react"; +import { buildTabBarContextMenu, buildTabContextMenu } from "./tabcontextmenu"; +import { UpdateStatusBanner } from "./updatebanner"; +import { VTab, VTabItem } from "./vtab"; +import { VTabBarEnv } from "./vtabbarenv"; +import { WorkspaceSwitcher } from "./workspaceswitcher"; +export type { VTabItem } from "./vtab"; + +const VTabBarAIButton = memo(() => { + const env = useWaveEnv(); + const aiPanelOpen = useAtomValue(WorkspaceLayoutModel.getInstance().panelVisibleAtom); + const hideAiButton = useAtomValue(env.getSettingsKeyAtom("app:hideaibutton")); + + const onClick = () => { + const currentVisible = WorkspaceLayoutModel.getInstance().getAIPanelVisible(); + WorkspaceLayoutModel.getInstance().setAIPanelVisible(!currentVisible); + }; + + if (hideAiButton) { + return null; + } + + return ( + + + + ); +}); +VTabBarAIButton.displayName = "VTabBarAIButton"; + +const MacOSHeader = memo(() => { + const env = useWaveEnv(); + const isFullScreen = useAtomValue(env.atoms.isFullScreen); + return ( + <> + {!isFullScreen && ( +
+ )} +
+ + + + + +
+ + ); +}); +MacOSHeader.displayName = "MacOSHeader"; + +interface VTabBarProps { + workspace: Workspace; + className?: string; +} + +interface VTabWrapperProps { + tabId: string; + active: boolean; + showDivider: boolean; + isDragging: boolean; + isReordering: boolean; + hoverResetVersion: number; + index: number; + onSelect: () => void; + onClose: () => void; + onRename: (newName: string) => void; + onDragStart: (event: React.DragEvent) => void; + onDragOver: (event: React.DragEvent) => void; + onDrop: (event: React.DragEvent) => void; + onDragEnd: () => void; + onHoverChanged: (isHovered: boolean) => void; +} + +function VTabWrapper({ + tabId, + active, + showDivider, + isDragging, + isReordering, + hoverResetVersion, + onSelect, + onClose, + onRename, + onDragStart, + onDragOver, + onDrop, + onDragEnd, + onHoverChanged, +}: VTabWrapperProps) { + const env = useWaveEnv(); + const [tabData] = env.wos.useWaveObjectValue(makeORef("tab", tabId)); + const badges = useAtomValue(getTabBadgeAtom(tabId, env)); + const renameRef = useRef<(() => void) | null>(null); + + const rawFlagColor = tabData?.meta?.["tab:flagcolor"]; + let flagColor: string | null = null; + if (rawFlagColor) { + try { + validateCssColor(rawFlagColor); + flagColor = rawFlagColor; + } catch { + flagColor = null; + } + } + + const tab: VTabItem = { + id: tabId, + name: tabData?.name ?? "", + badges, + flagColor, + }; + + const handleContextMenu = useCallback( + (e: React.MouseEvent) => { + e.preventDefault(); + e.stopPropagation(); + const menu = buildTabContextMenu(tabId, renameRef, () => onClose(), env); + env.showContextMenu(menu, e); + }, + [tabId, onClose, env] + ); + + return ( + + ); +} + +export function VTabBar({ workspace, className }: VTabBarProps) { + const env = useWaveEnv(); + const activeTabId = useAtomValue(env.atoms.staticTabId); + const reinitVersion = useAtomValue(env.atoms.reinitVersion); + const documentHasFocus = useAtomValue(env.atoms.documentHasFocus); + const tabIds = workspace?.tabids ?? []; + + const [orderedTabIds, setOrderedTabIds] = useState(tabIds); + const [dragTabId, setDragTabId] = useState(null); + const [dropIndex, setDropIndex] = useState(null); + const [dropLineTop, setDropLineTop] = useState(null); + const [hoverResetVersion, setHoverResetVersion] = useState(0); + const [hoveredTabId, setHoveredTabId] = useState(null); + const [isNewTabHovered, setIsNewTabHovered] = useState(false); + const dragSourceRef = useRef(null); + const didResetHoverForDragRef = useRef(false); + const scrollContainerRef = useRef(null); + const scrollAnimFrameRef = useRef(null); + const scrollDirectionRef = useRef(0); + const scrollSpeedRef = useRef(0); + + useEffect(() => { + setOrderedTabIds(tabIds); + }, [workspace?.tabids]); + + useEffect(() => { + if (reinitVersion > 0) { + setOrderedTabIds(workspace?.tabids ?? []); + } + }, [reinitVersion]); + + useEffect(() => { + if (activeTabId == null || scrollContainerRef.current == null) { + return; + } + const el = scrollContainerRef.current.querySelector(`[data-tabid="${activeTabId}"]`); + el?.scrollIntoView({ block: "nearest" }); + }, [activeTabId]); + + useEffect(() => { + if (!documentHasFocus || activeTabId == null || scrollContainerRef.current == null) { + return; + } + const el = scrollContainerRef.current.querySelector(`[data-tabid="${activeTabId}"]`); + el?.scrollIntoView({ block: "nearest" }); + }, [documentHasFocus]); + + const stopScrollLoop = useCallback(() => { + if (scrollAnimFrameRef.current != null) { + cancelAnimationFrame(scrollAnimFrameRef.current); + scrollAnimFrameRef.current = null; + } + scrollDirectionRef.current = 0; + }, []); + + const startScrollLoop = useCallback(() => { + if (scrollAnimFrameRef.current != null) { + return; + } + const loop = () => { + const container = scrollContainerRef.current; + if (container == null || scrollDirectionRef.current === 0) { + scrollAnimFrameRef.current = null; + return; + } + container.scrollTop += scrollDirectionRef.current * scrollSpeedRef.current; + scrollAnimFrameRef.current = requestAnimationFrame(loop); + }; + scrollAnimFrameRef.current = requestAnimationFrame(loop); + }, []); + + const updateScrollFromDragY = useCallback( + (clientY: number) => { + const container = scrollContainerRef.current; + if (container == null) { + return; + } + const EdgeZone = 60; + const MaxScrollSpeed = 12; + const rect = container.getBoundingClientRect(); + const relY = clientY - rect.top; + const height = rect.height; + if (relY < EdgeZone) { + scrollDirectionRef.current = -1; + scrollSpeedRef.current = MaxScrollSpeed * (1 - relY / EdgeZone); + startScrollLoop(); + } else if (relY > height - EdgeZone) { + scrollDirectionRef.current = 1; + scrollSpeedRef.current = MaxScrollSpeed * (1 - (height - relY) / EdgeZone); + startScrollLoop(); + } else { + scrollDirectionRef.current = 0; + stopScrollLoop(); + } + }, + [startScrollLoop, stopScrollLoop] + ); + + const clearDragState = () => { + stopScrollLoop(); + if (dragSourceRef.current != null && !didResetHoverForDragRef.current) { + didResetHoverForDragRef.current = true; + setHoverResetVersion((version) => version + 1); + } + dragSourceRef.current = null; + setDragTabId(null); + setDropIndex(null); + setDropLineTop(null); + }; + + const reorder = (targetIndex: number) => { + const sourceTabId = dragSourceRef.current; + if (sourceTabId == null) { + return; + } + const sourceIndex = orderedTabIds.findIndex((id) => id === sourceTabId); + if (sourceIndex === -1) { + return; + } + const boundedTargetIndex = Math.max(0, Math.min(targetIndex, orderedTabIds.length)); + const adjustedTargetIndex = sourceIndex < boundedTargetIndex ? boundedTargetIndex - 1 : boundedTargetIndex; + if (sourceIndex === adjustedTargetIndex) { + return; + } + const nextTabIds = [...orderedTabIds]; + const [movedId] = nextTabIds.splice(sourceIndex, 1); + nextTabIds.splice(adjustedTargetIndex, 0, movedId); + setOrderedTabIds(nextTabIds); + fireAndForget(() => env.rpc.UpdateWorkspaceTabIdsCommand(TabRpcClient, workspace.oid, nextTabIds)); + }; + + const handleTabBarContextMenu = useCallback( + (e: React.MouseEvent) => { + e.preventDefault(); + const menu = buildTabBarContextMenu(env); + env.showContextMenu(menu, e); + }, + [env] + ); + + return ( +
+ {env.isMacOS() && } +
{ + event.preventDefault(); + updateScrollFromDragY(event.clientY); + if (event.target === event.currentTarget) { + setDropIndex(orderedTabIds.length); + setDropLineTop(event.currentTarget.scrollHeight); + } + }} + onDrop={(event) => { + event.preventDefault(); + if (dropIndex != null) { + reorder(dropIndex); + } + clearDragState(); + }} + > + {orderedTabIds.map((tabId, index) => { + const isActive = tabId === activeTabId; + const isHovered = tabId === hoveredTabId; + const isLast = index === orderedTabIds.length - 1; + const nextTabId = orderedTabIds[index + 1]; + const isNextActive = nextTabId === activeTabId; + const isNextHovered = nextTabId === hoveredTabId; + return ( + env.electron.setActiveTab(tabId)} + onClose={() => fireAndForget(() => env.electron.closeTab(workspace.oid, tabId, false))} + onRename={(newName) => + fireAndForget(() => env.rpc.UpdateTabNameCommand(TabRpcClient, tabId, newName)) + } + onDragStart={(event) => { + didResetHoverForDragRef.current = false; + dragSourceRef.current = tabId; + event.dataTransfer.effectAllowed = "move"; + event.dataTransfer.setData("text/plain", tabId); + setDragTabId(tabId); + setDropIndex(index); + setDropLineTop(event.currentTarget.offsetTop); + }} + onDragOver={(event) => { + event.preventDefault(); + const rect = event.currentTarget.getBoundingClientRect(); + const relativeY = event.clientY - rect.top; + const midpoint = event.currentTarget.offsetHeight / 2; + const insertBefore = relativeY < midpoint; + setDropIndex(insertBefore ? index : index + 1); + setDropLineTop( + insertBefore + ? event.currentTarget.offsetTop + : event.currentTarget.offsetTop + event.currentTarget.offsetHeight + ); + }} + onDrop={(event) => { + event.preventDefault(); + if (dropIndex != null) { + reorder(dropIndex); + } + clearDragState(); + }} + onDragEnd={clearDragState} + onHoverChanged={(isHovered) => setHoveredTabId(isHovered ? tabId : null)} + /> + ); + })} + {dragTabId != null && dropIndex != null && dropLineTop != null && ( +
+ )} +
+ +
+ ); +} diff --git a/frontend/app/tab/vtabbarenv.ts b/frontend/app/tab/vtabbarenv.ts new file mode 100644 index 000000000..253378077 --- /dev/null +++ b/frontend/app/tab/vtabbarenv.ts @@ -0,0 +1,41 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { SettingsKeyAtomFnType, WaveEnv, WaveEnvSubset } from "@/app/waveenv/waveenv"; + +export type VTabBarEnv = WaveEnvSubset<{ + electron: { + createTab: WaveEnv["electron"]["createTab"]; + closeTab: WaveEnv["electron"]["closeTab"]; + setActiveTab: WaveEnv["electron"]["setActiveTab"]; + deleteWorkspace: WaveEnv["electron"]["deleteWorkspace"]; + createWorkspace: WaveEnv["electron"]["createWorkspace"]; + switchWorkspace: WaveEnv["electron"]["switchWorkspace"]; + installAppUpdate: WaveEnv["electron"]["installAppUpdate"]; + }; + rpc: { + UpdateWorkspaceTabIdsCommand: WaveEnv["rpc"]["UpdateWorkspaceTabIdsCommand"]; + UpdateTabNameCommand: WaveEnv["rpc"]["UpdateTabNameCommand"]; + ActivityCommand: WaveEnv["rpc"]["ActivityCommand"]; + SetConfigCommand: WaveEnv["rpc"]["SetConfigCommand"]; + SetMetaCommand: WaveEnv["rpc"]["SetMetaCommand"]; + }; + atoms: { + staticTabId: WaveEnv["atoms"]["staticTabId"]; + fullConfigAtom: WaveEnv["atoms"]["fullConfigAtom"]; + reinitVersion: WaveEnv["atoms"]["reinitVersion"]; + documentHasFocus: WaveEnv["atoms"]["documentHasFocus"]; + workspace: WaveEnv["atoms"]["workspace"]; + updaterStatusAtom: WaveEnv["atoms"]["updaterStatusAtom"]; + isFullScreen: WaveEnv["atoms"]["isFullScreen"]; + }; + services: { + workspace: WaveEnv["services"]["workspace"]; + }; + wos: WaveEnv["wos"]; + showContextMenu: WaveEnv["showContextMenu"]; + getSettingsKeyAtom: SettingsKeyAtomFnType<"tab:confirmclose" | "app:tabbar" | "app:hideaibutton">; + mockSetWaveObj: WaveEnv["mockSetWaveObj"]; + isWindows: WaveEnv["isWindows"]; + isMacOS: WaveEnv["isMacOS"]; +}>; diff --git a/frontend/app/tab/workspaceswitcher.scss b/frontend/app/tab/workspaceswitcher.scss index f28a040dd..b8c5041ac 100644 --- a/frontend/app/tab/workspaceswitcher.scss +++ b/frontend/app/tab/workspaceswitcher.scss @@ -3,13 +3,14 @@ .workspace-switcher-button { display: flex; - height: 26px; + height: 22px; padding: 0px 12px; justify-content: flex-end; align-items: center; gap: 12px; border-radius: 6px; margin-right: 6px; + margin-bottom: 4px; box-sizing: border-box; background-color: rgb(from var(--main-text-color) r g b / 0.1) !important; diff --git a/frontend/app/tab/workspaceswitcher.tsx b/frontend/app/tab/workspaceswitcher.tsx index 7a253b81e..5cc17516e 100644 --- a/frontend/app/tab/workspaceswitcher.tsx +++ b/frontend/app/tab/workspaceswitcher.tsx @@ -1,6 +1,7 @@ -// Copyright 2025, Command Line +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 +import { useWaveEnv, WaveEnv, WaveEnvSubset } from "@/app/waveenv/waveenv"; import { ExpandableMenu, ExpandableMenuItem, @@ -18,13 +19,27 @@ import { OverlayScrollbarsComponent } from "overlayscrollbars-react"; import { CSSProperties, forwardRef, useCallback, useEffect } from "react"; import WorkspaceSVG from "../asset/workspace.svg"; import { IconButton } from "../element/iconbutton"; -import { atoms, getApi } from "../store/global"; -import { WorkspaceService } from "../store/services"; -import { getObjectValue, makeORef } from "../store/wos"; +import { globalStore } from "@/app/store/jotaiStore"; +import { makeORef } from "../store/wos"; import { waveEventSubscribeSingle } from "../store/wps"; import { WorkspaceEditor } from "./workspaceeditor"; import "./workspaceswitcher.scss"; +export type WorkspaceSwitcherEnv = WaveEnvSubset<{ + electron: { + deleteWorkspace: WaveEnv["electron"]["deleteWorkspace"]; + createWorkspace: WaveEnv["electron"]["createWorkspace"]; + switchWorkspace: WaveEnv["electron"]["switchWorkspace"]; + }; + atoms: { + workspace: WaveEnv["atoms"]["workspace"]; + }; + services: { + workspace: WaveEnv["services"]["workspace"]; + }; + wos: WaveEnv["wos"]; +}>; + type WorkspaceListEntry = { windowId: string; workspace: Workspace; @@ -35,23 +50,24 @@ const workspaceMapAtom = atom([]); const workspaceSplitAtom = splitAtom(workspaceMapAtom); const editingWorkspaceAtom = atom(); const WorkspaceSwitcher = forwardRef((_, ref) => { + const env = useWaveEnv(); const setWorkspaceList = useSetAtom(workspaceMapAtom); - const activeWorkspace = useAtomValueSafe(atoms.workspace); + const activeWorkspace = useAtomValueSafe(env.atoms.workspace); const workspaceList = useAtomValue(workspaceSplitAtom); const setEditingWorkspace = useSetAtom(editingWorkspaceAtom); const updateWorkspaceList = useCallback(async () => { - const workspaceList = await WorkspaceService.ListWorkspaces(); + const workspaceList = await env.services.workspace.ListWorkspaces(); if (!workspaceList) { return; } const newList: WorkspaceList = []; for (const entry of workspaceList) { // This just ensures that the atom exists for easier setting of the object - getObjectValue(makeORef("workspace", entry.workspaceid)); + globalStore.get(env.wos.getWaveObjectAtom(makeORef("workspace", entry.workspaceid))); newList.push({ windowId: entry.windowid, - workspace: await WorkspaceService.GetWorkspace(entry.workspaceid), + workspace: await env.services.workspace.GetWorkspace(entry.workspaceid), }); } setWorkspaceList(newList); @@ -71,7 +87,7 @@ const WorkspaceSwitcher = forwardRef((_, ref) => { }, []); const onDeleteWorkspace = useCallback((workspaceId: string) => { - getApi().deleteWorkspace(workspaceId); + env.electron.deleteWorkspace(workspaceId); }, []); const isActiveWorkspaceSaved = !!(activeWorkspace.name && activeWorkspace.icon); @@ -84,7 +100,7 @@ const WorkspaceSwitcher = forwardRef((_, ref) => { const saveWorkspace = () => { fireAndForget(async () => { - await WorkspaceService.UpdateWorkspace(activeWorkspace.oid, "", "", "", true); + await env.services.workspace.UpdateWorkspace(activeWorkspace.oid, "", "", "", true); await updateWorkspaceList(); setEditingWorkspace(activeWorkspace.oid); }); @@ -118,7 +134,7 @@ const WorkspaceSwitcher = forwardRef((_, ref) => {
{isActiveWorkspaceSaved ? ( - getApi().createWorkspace()}> + env.electron.createWorkspace()}> @@ -145,7 +161,8 @@ const WorkspaceSwitcherItem = ({ entryAtom: PrimitiveAtom; onDeleteWorkspace: (workspaceId: string) => void; }) => { - const activeWorkspace = useAtomValueSafe(atoms.workspace); + const env = useWaveEnv(); + const activeWorkspace = useAtomValueSafe(env.atoms.workspace); const [workspaceEntry, setWorkspaceEntry] = useAtom(entryAtom); const [editingWorkspace, setEditingWorkspace] = useAtom(editingWorkspaceAtom); @@ -156,7 +173,7 @@ const WorkspaceSwitcherItem = ({ setWorkspaceEntry({ ...workspaceEntry, workspace: newWorkspace }); if (newWorkspace.name != "") { fireAndForget(() => - WorkspaceService.UpdateWorkspace( + env.services.workspace.UpdateWorkspace( workspace.oid, newWorkspace.name, newWorkspace.icon, @@ -200,7 +217,7 @@ const WorkspaceSwitcherItem = ({ > { - getApi().switchWorkspace(workspace.oid); + env.electron.switchWorkspace(workspace.oid); // Create a fake escape key event to close the popover document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" })); }} diff --git a/frontend/app/theme.scss b/frontend/app/theme.scss index 92c931378..287a00410 100644 --- a/frontend/app/theme.scss +++ b/frontend/app/theme.scss @@ -14,8 +14,9 @@ --accent-color: rgb(88, 193, 66); --panel-bg-color: rgba(31, 33, 31, 0.5); --highlight-bg-color: rgba(255, 255, 255, 0.2); - --markdown-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, - "Apple Color Emoji", "Segoe UI Emoji"; + --markdown-font-family: + -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", + "Segoe UI Emoji"; --markdown-font-size: 14px; --markdown-fixed-font-size: 12px; --error-color: rgb(229, 77, 46); @@ -66,7 +67,6 @@ --zindex-layout-ephemeral-node: 9; --zindex-block-mask-inner: 10; --zindex-app-background: -1; - // z-indexes in xterm.css // xterm-helpers: 5 // xterm-helper-textarea: -5 @@ -76,7 +76,6 @@ // xterm-decoration-top-layer: 7 // xterm-decoration-overview-ruler: 8 // xterm-decoration-top: 2 - --zindex-xterm-viewport-overlay: 5; // Viewport contains the scrollbar // modal colors --modal-bg-color: #232323; diff --git a/frontend/app/treeview/treeview.test.ts b/frontend/app/treeview/treeview.test.ts new file mode 100644 index 000000000..c286be7a4 --- /dev/null +++ b/frontend/app/treeview/treeview.test.ts @@ -0,0 +1,46 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { buildVisibleRows, TreeNodeData } from "@/app/treeview/treeview"; +import { describe, expect, it } from "vitest"; + +function makeNodes(entries: TreeNodeData[]): Map { + return new Map(entries.map((entry) => [entry.id, entry])); +} + +describe("treeview visible rows", () => { + it("sorts directories before files and alphabetically", () => { + const nodes = makeNodes([ + { + id: "root", + isDirectory: true, + childrenStatus: "loaded", + childrenIds: ["c", "a", "b"], + }, + { id: "a", parentId: "root", isDirectory: false, label: "z-last.txt" }, + { id: "b", parentId: "root", isDirectory: true, label: "docs", childrenStatus: "loaded", childrenIds: [] }, + { id: "c", parentId: "root", isDirectory: false, label: "a-first.txt" }, + ]); + const rows = buildVisibleRows(nodes, ["root"], new Set(["root"])); + expect(rows.map((row) => row.id)).toEqual(["root", "b", "c", "a"]); + }); + + it("renders loading and capped synthetic rows", () => { + const nodes = makeNodes([ + { id: "root", isDirectory: true, childrenStatus: "loading" }, + { + id: "dir", + isDirectory: true, + childrenStatus: "capped", + childrenIds: ["f1"], + capInfo: { max: 1 }, + }, + { id: "f1", parentId: "dir", isDirectory: false, label: "one.txt" }, + ]); + const loadingRows = buildVisibleRows(nodes, ["root"], new Set(["root"])); + expect(loadingRows.map((row) => row.kind)).toEqual(["node", "loading"]); + + const cappedRows = buildVisibleRows(nodes, ["dir"], new Set(["dir"])); + expect(cappedRows.map((row) => row.kind)).toEqual(["node", "node", "capped"]); + }); +}); diff --git a/frontend/app/treeview/treeview.tsx b/frontend/app/treeview/treeview.tsx new file mode 100644 index 000000000..4481d2c68 --- /dev/null +++ b/frontend/app/treeview/treeview.tsx @@ -0,0 +1,522 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { makeIconClass } from "@/util/util"; +import { useVirtualizer } from "@tanstack/react-virtual"; +import clsx from "clsx"; +import React, { + CSSProperties, + KeyboardEvent, + MouseEvent, + forwardRef, + useEffect, + useImperativeHandle, + useMemo, + useRef, + useState, +} from "react"; + +type TreeNodeChildrenStatus = "unloaded" | "loading" | "loaded" | "error" | "capped"; + +export interface TreeNodeData { + id: string; + parentId?: string; + label?: string; + path?: string; + isDirectory: boolean; + mimeType?: string; + icon?: string; + isReadonly?: boolean; + notfound?: boolean; + staterror?: string; + childrenStatus?: TreeNodeChildrenStatus; + childrenIds?: string[]; + capInfo?: { max: number; totalKnown?: number }; +} + +interface FetchDirResult { + nodes: TreeNodeData[]; + capped?: boolean; + totalKnown?: number; +} + +export interface TreeViewVisibleRow { + id: string; + parentId?: string; + depth: number; + kind: "node" | "loading" | "error" | "capped"; + label: string; + isDirectory?: boolean; + isExpanded?: boolean; + hasChildren?: boolean; + icon?: string; + node?: TreeNodeData; +} + +export interface TreeViewProps { + rootIds: string[]; + initialNodes: Record; + fetchDir?: (id: string, limit: number) => Promise; + maxDirEntries?: number; + rowHeight?: number; + indentWidth?: number; + overscan?: number; + minWidth?: number; + maxWidth?: number; + width?: number | string; + height?: number | string; + className?: string; + onOpenFile?: (id: string, node: TreeNodeData) => void; + onSelectionChange?: (id: string, node: TreeNodeData) => void; +} + +export interface TreeViewRef { + scrollToId: (id: string) => void; +} + +const DefaultRowHeight = 24; +const DefaultIndentWidth = 16; +const DefaultOverscan = 10; +const ChevronWidth = 16; + +function normalizeLabel(node: TreeNodeData): string { + if (node.label?.trim()) { + return node.label; + } + const path = node.path ?? node.id; + const chunks = path.split("/").filter(Boolean); + return chunks[chunks.length - 1] ?? path; +} + +function sortIdsByNode(nodesById: Map, ids: string[]): string[] { + return [...ids].sort((leftId, rightId) => { + const left = nodesById.get(leftId); + const right = nodesById.get(rightId); + const leftDir = left?.isDirectory ? 0 : 1; + const rightDir = right?.isDirectory ? 0 : 1; + if (leftDir !== rightDir) { + return leftDir - rightDir; + } + const leftLabel = normalizeLabel(left ?? { id: leftId, isDirectory: false }).toLocaleLowerCase(); + const rightLabel = normalizeLabel(right ?? { id: rightId, isDirectory: false }).toLocaleLowerCase(); + if (leftLabel !== rightLabel) { + return leftLabel.localeCompare(rightLabel); + } + return leftId.localeCompare(rightId); + }); +} + +export function buildVisibleRows( + nodesById: Map, + rootIds: string[], + expandedIds: Set +): TreeViewVisibleRow[] { + const rows: TreeViewVisibleRow[] = []; + + const appendNode = (id: string, depth: number) => { + const node = nodesById.get(id); + if (node == null) { + return; + } + const childIds = node.childrenIds ?? []; + const hasChildren = node.isDirectory && (childIds.length > 0 || node.childrenStatus !== "loaded"); + const isExpanded = expandedIds.has(id); + rows.push({ + id, + parentId: node.parentId, + depth, + kind: "node", + label: normalizeLabel(node), + isDirectory: node.isDirectory, + isExpanded, + hasChildren, + icon: node.icon, + node, + }); + if (!isExpanded || !node.isDirectory) { + return; + } + const status = node.childrenStatus ?? "unloaded"; + if (status === "loading") { + rows.push({ + id: `${id}::__loading`, + parentId: id, + depth: depth + 1, + kind: "loading", + label: "Loading…", + }); + return; + } + if (status === "error") { + rows.push({ + id: `${id}::__error`, + parentId: id, + depth: depth + 1, + kind: "error", + label: node.staterror ? `Error: ${node.staterror}` : "Unable to load directory", + }); + return; + } + + const sortedChildren = sortIdsByNode(nodesById, childIds); + sortedChildren.forEach((childId) => appendNode(childId, depth + 1)); + if (status === "capped") { + const capMax = node.capInfo?.max ?? childIds.length; + rows.push({ + id: `${id}::__capped`, + parentId: id, + depth: depth + 1, + kind: "capped", + label: `Showing first ${capMax} entries`, + }); + } + }; + + sortIdsByNode(nodesById, rootIds).forEach((id) => appendNode(id, 0)); + return rows; +} + +function getNodeIcon(node: TreeNodeData, isExpanded: boolean): string { + if (node.notfound || node.staterror) { + return "triangle-exclamation"; + } + if (node.icon) { + return node.icon; + } + if (node.isDirectory) { + return isExpanded ? "folder-open" : "folder"; + } + const mime = node.mimeType ?? ""; + if (mime.startsWith("image/")) { + return "image"; + } + if (mime === "application/pdf") { + return "file-pdf"; + } + const extension = normalizeLabel(node).split(".").pop()?.toLocaleLowerCase(); + if (["js", "jsx", "ts", "tsx", "go", "py", "java", "c", "cpp", "h", "hpp", "json", "yaml", "yml"].includes(extension)) { + return "file-code"; + } + if (["md", "txt", "log"].includes(extension)) { + return "file-lines"; + } + return "file"; +} + +export const TreeView = forwardRef((props, ref) => { + const { + rootIds, + initialNodes, + fetchDir, + maxDirEntries = 500, + rowHeight = DefaultRowHeight, + indentWidth = DefaultIndentWidth, + overscan = DefaultOverscan, + minWidth = 100, + maxWidth = 400, + width = "100%", + height = 360, + className, + onOpenFile, + onSelectionChange, + } = props; + const [nodesById, setNodesById] = useState>( + () => + new Map( + Object.entries(initialNodes).map(([id, node]) => [id, { ...node, childrenStatus: node.childrenStatus ?? "unloaded" }]) + ) + ); + const [expandedIds, setExpandedIds] = useState>(new Set()); + const [selectedId, setSelectedId] = useState(rootIds[0]); + const scrollRef = useRef(null); + + useEffect(() => { + setNodesById( + new Map( + Object.entries(initialNodes).map(([id, node]) => [ + id, + { + ...node, + childrenStatus: node.childrenStatus ?? "unloaded", + }, + ]) + ) + ); + }, [initialNodes]); + + const visibleRows = useMemo(() => buildVisibleRows(nodesById, rootIds, expandedIds), [nodesById, rootIds, expandedIds]); + const idToIndex = useMemo( + () => new Map(visibleRows.map((row, index) => [row.id, index])), + [visibleRows] + ); + const virtualizer = useVirtualizer({ + count: visibleRows.length, + getScrollElement: () => scrollRef.current, + estimateSize: () => rowHeight, + overscan, + }); + + const commitSelection = (id: string) => { + const node = nodesById.get(id); + if (node == null) { + return; + } + setSelectedId(id); + onSelectionChange?.(id, node); + }; + + const scrollToId = (id: string) => { + const index = idToIndex.get(id); + if (index == null) { + return; + } + virtualizer.scrollToIndex(index, { align: "auto" }); + }; + + useImperativeHandle( + ref, + () => ({ + scrollToId, + }), + [idToIndex, virtualizer] + ); + + const loadChildren = async (id: string) => { + const currentNode = nodesById.get(id); + if (currentNode == null || !currentNode.isDirectory || currentNode.notfound || currentNode.staterror || fetchDir == null) { + return; + } + const status = currentNode.childrenStatus ?? "unloaded"; + if (status !== "unloaded") { + return; + } + setNodesById((prev) => { + const next = new Map(prev); + next.set(id, { ...currentNode, childrenStatus: "loading" }); + return next; + }); + try { + const result = await fetchDir(id, maxDirEntries); + setNodesById((prev) => { + const next = new Map(prev); + result.nodes.forEach((node) => { + const merged: TreeNodeData = { + ...node, + parentId: node.parentId ?? id, + childrenStatus: node.childrenStatus ?? (node.isDirectory ? "unloaded" : "loaded"), + }; + next.set(merged.id, merged); + }); + const childrenIds = sortIdsByNode( + next, + result.nodes.map((entry) => entry.id) + ); + const source = next.get(id) ?? currentNode; + next.set(id, { + ...source, + childrenIds, + childrenStatus: result.capped ? "capped" : "loaded", + capInfo: result.capped ? { max: maxDirEntries, totalKnown: result.totalKnown } : undefined, + }); + return next; + }); + } catch (error) { + setNodesById((prev) => { + const next = new Map(prev); + const source = next.get(id) ?? currentNode; + next.set(id, { + ...source, + childrenStatus: "error", + staterror: error instanceof Error ? error.message : "Unknown error", + }); + return next; + }); + } + }; + + const toggleExpand = (id: string) => { + const node = nodesById.get(id); + if (node == null || !node.isDirectory || node.notfound || node.staterror) { + return; + } + const expanded = expandedIds.has(id); + if (!expanded) { + loadChildren(id); + } + setExpandedIds((prev) => { + const next = new Set(prev); + if (expanded) { + next.delete(id); + } else { + next.add(id); + } + return next; + }); + scrollToId(id); + }; + + const selectVisibleNodeAt = (index: number) => { + if (index < 0 || index >= visibleRows.length) { + return; + } + const row = visibleRows[index]; + if (row.kind !== "node") { + return; + } + commitSelection(row.id); + scrollToId(row.id); + }; + + const onKeyDown = (event: KeyboardEvent) => { + const selectedIndex = selectedId != null ? idToIndex.get(selectedId) : undefined; + if (event.key === "ArrowDown") { + event.preventDefault(); + const nextIndex = (selectedIndex ?? -1) + 1; + for (let idx = nextIndex; idx < visibleRows.length; idx++) { + if (visibleRows[idx].kind === "node") { + selectVisibleNodeAt(idx); + break; + } + } + return; + } + if (event.key === "ArrowUp") { + event.preventDefault(); + const previousIndex = (selectedIndex ?? visibleRows.length) - 1; + for (let idx = previousIndex; idx >= 0; idx--) { + if (visibleRows[idx].kind === "node") { + selectVisibleNodeAt(idx); + break; + } + } + return; + } + const node = selectedId ? nodesById.get(selectedId) : null; + if (node == null) { + return; + } + if (event.key === "ArrowLeft") { + event.preventDefault(); + if (node.isDirectory && expandedIds.has(node.id)) { + toggleExpand(node.id); + return; + } + if (node.parentId != null) { + commitSelection(node.parentId); + scrollToId(node.parentId); + } + return; + } + if (event.key === "ArrowRight") { + event.preventDefault(); + if (node.isDirectory && !expandedIds.has(node.id)) { + toggleExpand(node.id); + return; + } + if (node.isDirectory && expandedIds.has(node.id) && node.childrenIds?.[0]) { + commitSelection(node.childrenIds[0]); + scrollToId(node.childrenIds[0]); + } + } + }; + + const containerStyle: CSSProperties = { + width, + minWidth, + maxWidth, + height, + }; + + return ( +
+
+
+ {virtualizer.getVirtualItems().map((virtualRow) => { + const row = visibleRows[virtualRow.index]; + if (row.kind === "node" && row.node == null) { + return null; + } + const selected = row.id === selectedId; + return ( +
row.kind === "node" && commitSelection(row.id)} + onDoubleClick={() => { + if (row.kind !== "node") { + return; + } + if (row.isDirectory) { + toggleExpand(row.id); + return; + } + if (row.node != null) { + onOpenFile?.(row.id, row.node); + } + }} + > +
+ {row.kind === "node" && row.isDirectory && row.hasChildren ? ( + + ) : ( + + )} +
+ {row.kind === "node" ? ( + <> + + + {row.label} + + + ) : ( + {row.label} + )} +
+ ); + })} +
+
+
+ ); +}); + +TreeView.displayName = "TreeView"; diff --git a/frontend/app/view/aifilediff/aifilediff.tsx b/frontend/app/view/aifilediff/aifilediff.tsx index dfd85f291..f7ca81706 100644 --- a/frontend/app/view/aifilediff/aifilediff.tsx +++ b/frontend/app/view/aifilediff/aifilediff.tsx @@ -1,13 +1,13 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import type { BlockNodeModel } from "@/app/block/blocktypes"; import type { TabModel } from "@/app/store/tab-model"; -import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; -import { base64ToString } from "@/util/util"; import { DiffViewer } from "@/app/view/codeeditor/diffviewer"; +import type { WaveEnv, WaveEnvSubset } from "@/app/waveenv/waveenv"; import { globalStore, WOS } from "@/store/global"; +import { base64ToString } from "@/util/util"; import * as jotai from "jotai"; import { useEffect } from "react"; @@ -17,10 +17,18 @@ type DiffData = { fileName: string; }; +export type AiFileDiffEnv = WaveEnvSubset<{ + rpc: { + WaveAIGetToolDiffCommand: WaveEnv["rpc"]["WaveAIGetToolDiffCommand"]; + }; + wos: WaveEnv["wos"]; +}>; + export class AiFileDiffViewModel implements ViewModel { blockId: string; nodeModel: BlockNodeModel; tabModel: TabModel; + env: AiFileDiffEnv; viewType = "aifilediff"; blockAtom: jotai.Atom; diffDataAtom: jotai.PrimitiveAtom; @@ -30,11 +38,12 @@ export class AiFileDiffViewModel implements ViewModel { viewName: jotai.Atom; viewText: jotai.Atom; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { + constructor({ blockId, nodeModel, tabModel, waveEnv }: ViewModelInitType) { this.blockId = blockId; this.nodeModel = nodeModel; this.tabModel = tabModel; - this.blockAtom = WOS.getWaveObjectAtom(`block:${blockId}`); + this.env = waveEnv as AiFileDiffEnv; + this.blockAtom = this.env.wos.getWaveObjectAtom(`block:${blockId}`); this.diffDataAtom = jotai.atom(null) as jotai.PrimitiveAtom; this.errorAtom = jotai.atom(null) as jotai.PrimitiveAtom; this.loadingAtom = jotai.atom(true); @@ -76,7 +85,7 @@ function AiFileDiffView({ blockId, model }: ViewComponentProps { // force a dependency on meta.url so we re-render the buttons when the url changes void (get(this.blockAtom)?.meta?.url || get(this.homepageUrl)); diff --git a/frontend/app/view/launcher/launcher.tsx b/frontend/app/view/launcher/launcher.tsx index f71f272aa..7b5a935f1 100644 --- a/frontend/app/view/launcher/launcher.tsx +++ b/frontend/app/view/launcher/launcher.tsx @@ -1,10 +1,10 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import type { BlockNodeModel } from "@/app/block/blocktypes"; -import type { TabModel } from "@/app/store/tab-model"; import logoUrl from "@/app/asset/logo.svg?url"; +import type { BlockNodeModel } from "@/app/block/blocktypes"; import { atoms, globalStore, replaceBlock } from "@/app/store/global"; +import type { TabModel } from "@/app/store/tab-model"; import { checkKeyPressed, keydownWrapper } from "@/util/keyutil"; import { isBlank, makeIconClass } from "@/util/util"; import clsx from "clsx"; @@ -35,7 +35,7 @@ export class LauncherViewModel implements ViewModel { containerSize = atom({ width: 0, height: 0 }); gridLayout: GridLayoutType = null; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { + constructor({ blockId, nodeModel, tabModel }: ViewModelInitType) { this.blockId = blockId; this.nodeModel = nodeModel; this.tabModel = tabModel; diff --git a/frontend/app/view/preview/directorypreview.scss b/frontend/app/view/preview/directorypreview.scss index c42ebf8d2..803e0036d 100644 --- a/frontend/app/view/preview/directorypreview.scss +++ b/frontend/app/view/preview/directorypreview.scss @@ -72,6 +72,17 @@ display: flex; justify-content: center; flex: 0 0 auto; + position: relative; + &::before { + content: ""; + position: absolute; + left: 50%; + top: 10%; + height: 80%; + width: 1px; + background-color: var(--border-color); + pointer-events: none; + } .dir-table-head-resize { cursor: col-resize; user-select: none; @@ -130,6 +141,10 @@ } } + &:nth-child(odd):not(.focused):not(:focus) { + background-color: rgba(255, 255, 255, 0.06); + } + &:hover:not(:focus):not(.focused) { background-color: var(--highlight-bg-color); } @@ -139,7 +154,7 @@ white-space: nowrap; padding: 0.25rem; cursor: default; - font-size: 0.8125rem; + font-size: 12px; flex: 0 0 auto; &.col-size { @@ -148,14 +163,17 @@ .dir-table-lastmod, .dir-table-modestr, - .dir-table-size, .dir-table-type { color: var(--secondary-text-color); margin-right: 12px; } - .dir-table-modestr { + .dir-table-modestr, + .dir-table-size, + .dir-table-lastmod { + color: var(--secondary-text-color); font-family: Hack; + font-size: 11px; } .dir-table-name { diff --git a/frontend/app/view/preview/preview-directory-utils.tsx b/frontend/app/view/preview/preview-directory-utils.tsx index 3c1457ce3..e278475ca 100644 --- a/frontend/app/view/preview/preview-directory-utils.tsx +++ b/frontend/app/view/preview/preview-directory-utils.tsx @@ -1,11 +1,9 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import { globalStore } from "@/app/store/global"; -import { RpcApi } from "@/app/store/wshclientapi"; +import { globalStore } from "@/app/store/jotaiStore"; import { TabRpcClient } from "@/app/store/wshrpcutil"; import { fireAndForget, isBlank } from "@/util/util"; -import { Column } from "@tanstack/react-table"; import dayjs from "dayjs"; import React from "react"; import { type PreviewModel } from "./preview-model"; @@ -40,23 +38,22 @@ export function getBestUnit(bytes: number, si = false, sigfig = 3): string { return `${parseFloat(value.toPrecision(sigfig))}${displaySuffixes[unit] ?? unit}`; } -export function getLastModifiedTime(unixMillis: number, column: Column): string { - const fileDatetime = dayjs(new Date(unixMillis)); - const nowDatetime = dayjs(new Date()); - - let datePortion: string; - if (nowDatetime.isSame(fileDatetime, "date")) { - datePortion = "Today"; - } else if (nowDatetime.subtract(1, "day").isSame(fileDatetime, "date")) { - datePortion = "Yesterday"; - } else { - datePortion = dayjs(fileDatetime).format("M/D/YY"); - } +function padDay(day: number) { + return String(day).padStart(2, " "); +} + +export function getLastModifiedTime(unixMillis: number): string { + const file = dayjs(unixMillis); + const now = dayjs(); + + const day = padDay(file.date()); + const time = file.format("HH:mm"); - if (column.getSize() > 120) { - return `${datePortion}, ${dayjs(fileDatetime).format("h:mm A")}`; + if (now.isSame(file, "year")) { + return `${file.format("MMM")} ${day} ${time}`; } - return datePortion; + + return `${file.format("YYYY-MM-DD")}`; } const iconRegex = /^[a-z0-9- ]+$/; @@ -97,7 +94,7 @@ export function handleRename( if (isDir) { srcuri += "/"; } - await RpcApi.FileMoveCommand(TabRpcClient, { + await model.env.rpc.FileMoveCommand(TabRpcClient, { srcuri, desturi: await model.formatRemoteUri(newPath, globalStore.get), }); @@ -123,7 +120,7 @@ export function handleFileDelete( fireAndForget(async () => { const formattedPath = await model.formatRemoteUri(path, globalStore.get); try { - await RpcApi.FileDeleteCommand(TabRpcClient, { + await model.env.rpc.FileDeleteCommand(TabRpcClient, { path: formattedPath, recursive, }); @@ -154,3 +151,60 @@ export function handleFileDelete( model.refreshCallback(); }); } + +export function makeDirectoryDefaultMenuItems(model: PreviewModel): ContextMenuItem[] { + const defaultSort = globalStore.get(model.env.getSettingsKeyAtom("preview:defaultsort")) ?? "name"; + const showHiddenFiles = globalStore.get(model.showHiddenFiles) ?? true; + return [ + { + label: "Directory Sort Order", + submenu: [ + { + label: "Name", + type: "checkbox", + checked: defaultSort === "name", + click: () => + fireAndForget(() => + model.env.rpc.SetConfigCommand(TabRpcClient, { "preview:defaultsort": "name" }) + ), + }, + { + label: "Last Modified", + type: "checkbox", + checked: defaultSort === "modtime", + click: () => + fireAndForget(() => + model.env.rpc.SetConfigCommand(TabRpcClient, { "preview:defaultsort": "modtime" }) + ), + }, + ], + }, + { + label: "Show Hidden Files", + submenu: [ + { + label: "On", + type: "checkbox", + checked: showHiddenFiles, + click: () => { + globalStore.set(model.showHiddenFiles, true); + fireAndForget(() => + model.env.rpc.SetConfigCommand(TabRpcClient, { "preview:showhiddenfiles": true }) + ); + }, + }, + { + label: "Off", + type: "checkbox", + checked: !showHiddenFiles, + click: () => { + globalStore.set(model.showHiddenFiles, false); + fireAndForget(() => + model.env.rpc.SetConfigCommand(TabRpcClient, { "preview:showhiddenfiles": false }) + ); + }, + }, + ], + }, + ]; +} diff --git a/frontend/app/view/preview/preview-directory.tsx b/frontend/app/view/preview/preview-directory.tsx index acbf06e3b..cdacd810b 100644 --- a/frontend/app/view/preview/preview-directory.tsx +++ b/frontend/app/view/preview/preview-directory.tsx @@ -1,9 +1,9 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { ContextMenuModel } from "@/app/store/contextmenu"; -import { atoms, getApi, globalStore } from "@/app/store/global"; -import { RpcApi } from "@/app/store/wshclientapi"; +import { useWaveEnv } from "@/app/waveenv/waveenv"; +import { globalStore } from "@/app/store/jotaiStore"; import { TabRpcClient } from "@/app/store/wshrpcutil"; import { checkKeyPressed, isCharacterKeyEvent } from "@/util/keyutil"; import { PLATFORM, PlatformMacOS } from "@/util/platformutil"; @@ -39,10 +39,12 @@ import { handleFileDelete, handleRename, isIconValid, + makeDirectoryDefaultMenuItems, mergeError, overwriteError, } from "./preview-directory-utils"; import { type PreviewModel } from "./preview-model"; +import type { PreviewEnv } from "./previewenv"; const PageJumpSize = 20; @@ -109,8 +111,10 @@ function DirectoryTable({ newFile, newDirectory, }: DirectoryTableProps) { + const env = useWaveEnv(); const searchActive = useAtomValue(model.directorySearchActive); - const fullConfig = useAtomValue(atoms.fullConfigAtom); + const fullConfig = useAtomValue(env.atoms.fullConfigAtom); + const defaultSort = useAtomValue(env.getSettingsKeyAtom("preview:defaultsort")) ?? "name"; const setErrorMsg = useSetAtom(model.errorMsgAtom); const getIconFromMimeType = useCallback( (mimeType: string): string => { @@ -158,9 +162,7 @@ function DirectoryTable({ sortingFn: "alphanumeric", }), columnHelper.accessor("modtime", { - cell: (info) => ( - {getLastModifiedTime(info.getValue(), info.column)} - ), + cell: (info) => {getLastModifiedTime(info.getValue())}, header: () => Last Modified, size: 91, minSize: 65, @@ -208,6 +210,8 @@ function DirectoryTable({ [model, setErrorMsg] ); + const initialSorting = defaultSort === "modtime" ? [{ id: "modtime", desc: true }] : [{ id: "name", desc: false }]; + const table = useReactTable({ data, columns, @@ -216,12 +220,7 @@ function DirectoryTable({ getCoreRowModel: getCoreRowModel(), initialState: { - sorting: [ - { - id: "name", - desc: false, - }, - ], + sorting: initialSorting, columnVisibility: { path: false, }, @@ -411,6 +410,13 @@ function TableBody({ ]; addOpenMenuItems(menu, conn, finfo); menu.push( + { + type: "separator", + }, + { + label: "Default Settings", + submenu: makeDirectoryDefaultMenuItems(model), + }, { type: "separator", }, @@ -493,15 +499,7 @@ type TableRowProps = { handleFileContextMenu: (e: any, finfo: FileInfo) => Promise; }; -const TableRow = React.forwardRef(function ({ - model, - row, - focusIndex, - setFocusIndex, - setSearch, - idx, - handleFileContextMenu, -}: TableRowProps) { +function TableRow({ model, row, focusIndex, setFocusIndex, setSearch, idx, handleFileContextMenu }: TableRowProps) { const dirPath = useAtomValue(model.statFilePath); const connection = useAtomValue(model.connection); @@ -552,7 +550,7 @@ const TableRow = React.forwardRef(function ({ ))}
); -}); +} const MemoizedTableBody = React.memo( TableBody, @@ -564,6 +562,7 @@ interface DirectoryPreviewProps { } function DirectoryPreview({ model }: DirectoryPreviewProps) { + const env = useWaveEnv(); const [searchText, setSearchText] = useState(""); const [focusIndex, setFocusIndex] = useState(0); const [unfilteredData, setUnfilteredData] = useState([]); @@ -590,7 +589,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) { fireAndForget(async () => { let entries: FileInfo[]; try { - const file = await RpcApi.FileReadCommand( + const file = await env.rpc.FileReadCommand( TabRpcClient, { info: { @@ -684,7 +683,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) { PLATFORM == PlatformMacOS && !blockData?.meta?.connection ) { - getApi().onQuicklook(selectedPath); + env.electron.onQuicklook(selectedPath); return true; } if (isCharacterKeyEvent(waveEvent)) { @@ -718,7 +717,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) { const handleDropCopy = useCallback( async (data: CommandFileCopyData, isDir: boolean) => { try { - await RpcApi.FileCopyCommand(TabRpcClient, data, { timeout: data.opts.timeout }); + await env.rpc.FileCopyCommand(TabRpcClient, data, { timeout: data.opts.timeout }); } catch (e) { console.warn("Copy failed:", e); const copyError = `${e}`; @@ -805,7 +804,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) { onSave: (newName: string) => { console.log(`newFile: ${newName}`); fireAndForget(async () => { - await RpcApi.FileCreateCommand( + await env.rpc.FileCreateCommand( TabRpcClient, { info: { @@ -826,7 +825,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) { onSave: (newName: string) => { console.log(`newDirectory: ${newName}`); fireAndForget(async () => { - await RpcApi.FileMkdirCommand(TabRpcClient, { + await env.rpc.FileMkdirCommand(TabRpcClient, { info: { path: await model.formatRemoteUri(`${dirPath}/${newName}`, globalStore.get), }, diff --git a/frontend/app/view/preview/preview-model.tsx b/frontend/app/view/preview/preview-model.tsx index ca85bba96..c523560db 100644 --- a/frontend/app/view/preview/preview-model.tsx +++ b/frontend/app/view/preview/preview-model.tsx @@ -1,13 +1,11 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { BlockNodeModel } from "@/app/block/blocktypes"; -import type { TabModel } from "@/app/store/tab-model"; import { ContextMenuModel } from "@/app/store/contextmenu"; -import { RpcApi } from "@/app/store/wshclientapi"; +import type { TabModel } from "@/app/store/tab-model"; import { TabRpcClient } from "@/app/store/wshrpcutil"; -import { getConnStatusAtom, getOverrideConfigAtom, getSettingsKeyAtom, globalStore, refocusNode } from "@/store/global"; -import * as services from "@/store/services"; +import { getOverrideConfigAtom, globalStore, refocusNode } from "@/store/global"; import * as WOS from "@/store/wos"; import { goHistory, goHistoryBack, goHistoryForward } from "@/util/historyutil"; import { checkKeyPressed } from "@/util/keyutil"; @@ -20,6 +18,8 @@ import { loadable } from "jotai/utils"; import type * as MonacoTypes from "monaco-editor"; import { createRef } from "react"; import { PreviewView } from "./preview"; +import { makeDirectoryDefaultMenuItems } from "./preview-directory-utils"; +import type { PreviewEnv } from "./previewenv"; // TODO drive this using config const BOOKMARKS: { label: string; path: string }[] = [ @@ -167,13 +167,15 @@ export class PreviewModel implements ViewModel { refreshCallback: () => void; directoryKeyDownHandler: (waveEvent: WaveKeyboardEvent) => boolean; codeEditKeyDownHandler: (waveEvent: WaveKeyboardEvent) => boolean; + env: PreviewEnv; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { + constructor({ blockId, nodeModel, tabModel, waveEnv }: ViewModelInitType) { this.viewType = "preview"; this.blockId = blockId; this.nodeModel = nodeModel; this.tabModel = tabModel; - let showHiddenFiles = globalStore.get(getSettingsKeyAtom("preview:showhiddenfiles")) ?? true; + this.env = waveEnv; + let showHiddenFiles = globalStore.get(this.env.getSettingsKeyAtom("preview:showhiddenfiles")) ?? true; this.showHiddenFiles = atom(showHiddenFiles); this.refreshVersion = atom(0); this.directorySearchActive = atom(false); @@ -183,7 +185,7 @@ export class PreviewModel implements ViewModel { this.openFileError = atom(null) as PrimitiveAtom; this.openFileModalGiveFocusRef = createRef(); this.manageConnection = atom(true); - this.blockAtom = WOS.getWaveObjectAtom(`block:${blockId}`); + this.blockAtom = this.env.wos.getWaveObjectAtom(`block:${blockId}`); this.markdownShowToc = atom(false); this.filterOutNowsh = atom(true); this.monacoRef = createRef(); @@ -335,6 +337,7 @@ export class PreviewModel implements ViewModel { { elemtype: "iconbutton", icon: showHiddenFiles ? "eye" : "eye-slash", + title: showHiddenFiles ? "Hide Hidden Files" : "Show Hidden Files", click: () => { globalStore.set(this.showHiddenFiles, (prev) => !prev); }, @@ -387,7 +390,7 @@ export class PreviewModel implements ViewModel { this.connection = atom>(async (get) => { const connName = get(this.blockAtom)?.meta?.connection; try { - await RpcApi.ConnEnsureCommand(TabRpcClient, { connname: connName }, { timeout: 60000 }); + await this.env.rpc.ConnEnsureCommand(TabRpcClient, { connname: connName }, { timeout: 60000 }); globalStore.set(this.connectionError, ""); } catch (e) { globalStore.set(this.connectionError, e as string); @@ -404,7 +407,7 @@ export class PreviewModel implements ViewModel { return null; } try { - const statFile = await RpcApi.FileInfoCommand(TabRpcClient, { + const statFile = await this.env.rpc.FileInfoCommand(TabRpcClient, { info: { path, }, @@ -434,7 +437,7 @@ export class PreviewModel implements ViewModel { return null; } try { - const file = await RpcApi.FileReadCommand(TabRpcClient, { + const file = await this.env.rpc.FileReadCommand(TabRpcClient, { info: { path, }, @@ -480,7 +483,7 @@ export class PreviewModel implements ViewModel { this.connStatus = atom((get) => { const blockData = get(this.blockAtom); const connName = blockData?.meta?.connection; - const connAtom = getConnStatusAtom(connName); + const connAtom = this.env.getConnStatusAtom(connName); return get(connAtom); }); @@ -584,7 +587,7 @@ export class PreviewModel implements ViewModel { return; } const blockOref = WOS.makeORef("block", this.blockId); - await services.ObjectService.UpdateObjectMeta(blockOref, updateMeta); + await this.env.services.object.UpdateObjectMeta(blockOref, updateMeta); // Clear the saved file buffers globalStore.set(this.fileContentSaved, null); @@ -620,7 +623,7 @@ export class PreviewModel implements ViewModel { } updateMeta.edit = false; const blockOref = WOS.makeORef("block", this.blockId); - await services.ObjectService.UpdateObjectMeta(blockOref, updateMeta); + await this.env.services.object.UpdateObjectMeta(blockOref, updateMeta); } async goHistoryForward() { @@ -632,13 +635,13 @@ export class PreviewModel implements ViewModel { } updateMeta.edit = false; const blockOref = WOS.makeORef("block", this.blockId); - await services.ObjectService.UpdateObjectMeta(blockOref, updateMeta); + await this.env.services.object.UpdateObjectMeta(blockOref, updateMeta); } async setEditMode(edit: boolean) { const blockMeta = globalStore.get(this.blockAtom)?.meta; const blockOref = WOS.makeORef("block", this.blockId); - await services.ObjectService.UpdateObjectMeta(blockOref, { ...blockMeta, edit }); + await this.env.services.object.UpdateObjectMeta(blockOref, { ...blockMeta, edit }); } async handleFileSave() { @@ -652,7 +655,7 @@ export class PreviewModel implements ViewModel { return; } try { - await RpcApi.FileWriteCommand(TabRpcClient, { + await this.env.rpc.FileWriteCommand(TabRpcClient, { info: { path: await this.formatRemoteUri(filePath, globalStore.get), }, @@ -697,7 +700,7 @@ export class PreviewModel implements ViewModel { } getSettingsMenuItems(): ContextMenuItem[] { - const defaultFontSize = globalStore.get(getSettingsKeyAtom("editor:fontsize")) ?? 12; + const defaultFontSize = globalStore.get(this.env.getSettingsKeyAtom("editor:fontsize")) ?? 12; const blockData = globalStore.get(this.blockAtom); const overrideFontSize = blockData?.meta?.["editor:fontsize"]; const menuItems: ContextMenuItem[] = []; @@ -731,68 +734,72 @@ export class PreviewModel implements ViewModel { }), }); menuItems.push({ type: "separator" }); - const fontSizeSubMenu: ContextMenuItem[] = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18].map( - (fontSize: number) => { - return { - label: fontSize.toString() + "px", - type: "checkbox", - checked: overrideFontSize == fontSize, - click: () => { - RpcApi.SetMetaCommand(TabRpcClient, { - oref: WOS.makeORef("block", this.blockId), - meta: { "editor:fontsize": fontSize }, - }); - }, - }; - } - ); - fontSizeSubMenu.unshift({ - label: "Default (" + defaultFontSize + "px)", - type: "checkbox", - checked: overrideFontSize == null, - click: () => { - RpcApi.SetMetaCommand(TabRpcClient, { - oref: WOS.makeORef("block", this.blockId), - meta: { "editor:fontsize": null }, - }); - }, - }); - menuItems.push({ - label: "Editor Font Size", - submenu: fontSizeSubMenu, - }); const finfo = jotaiLoadableValue(globalStore.get(this.loadableFileInfo), null); addOpenMenuItems(menuItems, globalStore.get(this.connectionImmediate), finfo); const loadableSV = globalStore.get(this.loadableSpecializedView); const wordWrapAtom = getOverrideConfigAtom(this.blockId, "editor:wordwrap"); const wordWrap = globalStore.get(wordWrapAtom) ?? false; - if (loadableSV.state == "hasData") { - if (loadableSV.data.specializedView == "codeedit") { - if (globalStore.get(this.newFileContent) != null) { - menuItems.push({ type: "separator" }); - menuItems.push({ - label: "Save File", - click: () => fireAndForget(this.handleFileSave.bind(this)), - }); - menuItems.push({ - label: "Revert File", - click: () => fireAndForget(this.handleFileRevert.bind(this)), - }); + menuItems.push({ type: "separator" }); + if (loadableSV.state == "hasData" && loadableSV.data.specializedView == "codeedit") { + const fontSizeSubMenu: ContextMenuItem[] = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18].map( + (fontSize: number) => { + return { + label: fontSize.toString() + "px", + type: "checkbox", + checked: overrideFontSize == fontSize, + click: () => { + this.env.rpc.SetMetaCommand(TabRpcClient, { + oref: WOS.makeORef("block", this.blockId), + meta: { "editor:fontsize": fontSize }, + }); + }, + }; } + ); + fontSizeSubMenu.unshift({ + label: "Default (" + defaultFontSize + "px)", + type: "checkbox", + checked: overrideFontSize == null, + click: () => { + this.env.rpc.SetMetaCommand(TabRpcClient, { + oref: WOS.makeORef("block", this.blockId), + meta: { "editor:fontsize": null }, + }); + }, + }); + menuItems.push({ + label: "Editor Font Size", + submenu: fontSizeSubMenu, + }); + if (globalStore.get(this.newFileContent) != null) { menuItems.push({ type: "separator" }); menuItems.push({ - label: "Word Wrap", - type: "checkbox", - checked: wordWrap, - click: () => - fireAndForget(async () => { - const blockOref = WOS.makeORef("block", this.blockId); - await services.ObjectService.UpdateObjectMeta(blockOref, { - "editor:wordwrap": !wordWrap, - }); - }), + label: "Save File", + click: () => fireAndForget(this.handleFileSave.bind(this)), + }); + menuItems.push({ + label: "Revert File", + click: () => fireAndForget(this.handleFileRevert.bind(this)), }); } + menuItems.push({ type: "separator" }); + menuItems.push({ + label: "Word Wrap", + type: "checkbox", + checked: wordWrap, + click: () => + fireAndForget(async () => { + const blockOref = WOS.makeORef("block", this.blockId); + await this.env.services.object.UpdateObjectMeta(blockOref, { + "editor:wordwrap": !wordWrap, + }); + }), + }); + } + if (loadableSV.state == "hasData" && loadableSV.data.specializedView == "directory") { + menuItems.push({ type: "separator" }); + menuItems.push({ label: "Default Settings", enabled: false }); + menuItems.push(...makeDirectoryDefaultMenuItems(this)); } return menuItems; } diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index 89eee74de..33188ae5b 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -1,10 +1,10 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { CenteredDiv } from "@/app/element/quickelems"; -import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; import { BlockHeaderSuggestionControl } from "@/app/suggestion/suggestion"; +import { useWaveEnv } from "@/app/waveenv/waveenv"; import { globalStore } from "@/store/global"; import { isBlank, makeConnRoute } from "@/util/util"; import { useAtom, useAtomValue, useSetAtom } from "jotai"; @@ -16,6 +16,7 @@ import { ErrorOverlay } from "./preview-error-overlay"; import { MarkdownPreview } from "./preview-markdown"; import type { PreviewModel } from "./preview-model"; import { StreamingPreview } from "./preview-streaming"; +import type { PreviewEnv } from "./previewenv"; export type SpecializedViewProps = { model: PreviewModel; @@ -64,6 +65,7 @@ const SpecializedView = memo(({ parentRef, model }: SpecializedViewProps) => { }); const fetchSuggestions = async ( + env: PreviewEnv, model: PreviewModel, query: string, reqContext: SuggestionRequestContext @@ -74,7 +76,7 @@ const fetchSuggestions = async ( route = null; } if (reqContext?.dispose) { - RpcApi.DisposeSuggestionsCommand(TabRpcClient, reqContext.widgetid, { noresponse: true, route: route }); + env.rpc.DisposeSuggestionsCommand(TabRpcClient, reqContext.widgetid, { noresponse: true, route: route }); return null; } const fileInfo = await globalStore.get(model.statFile); @@ -89,7 +91,7 @@ const fetchSuggestions = async ( reqnum: reqContext.reqnum, "file:connection": conn, }; - return await RpcApi.FetchSuggestionsCommand(TabRpcClient, sdata, { + return await env.rpc.FetchSuggestionsCommand(TabRpcClient, sdata, { route: route, }); }; @@ -104,6 +106,7 @@ function PreviewView({ contentRef: React.RefObject; model: PreviewModel; }) { + const env = useWaveEnv(); const connStatus = useAtomValue(model.connStatus); const [errorMsg, setErrorMsg] = useAtom(model.errorMsgAtom); const connection = useAtomValue(model.connectionImmediate); @@ -140,7 +143,7 @@ function PreviewView({ } }; const fetchSuggestionsFn = async (query, ctx) => { - return await fetchSuggestions(model, query, ctx); + return await fetchSuggestions(env, model, query, ctx); }; return ( diff --git a/frontend/app/view/preview/previewenv.ts b/frontend/app/view/preview/previewenv.ts new file mode 100644 index 000000000..464865a5d --- /dev/null +++ b/frontend/app/view/preview/previewenv.ts @@ -0,0 +1,34 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { SettingsKeyAtomFnType, WaveEnv, WaveEnvSubset } from "@/app/waveenv/waveenv"; + +export type PreviewEnv = WaveEnvSubset<{ + electron: { + onQuicklook: WaveEnv["electron"]["onQuicklook"]; + }; + rpc: { + ConnEnsureCommand: WaveEnv["rpc"]["ConnEnsureCommand"]; + FileInfoCommand: WaveEnv["rpc"]["FileInfoCommand"]; + FileReadCommand: WaveEnv["rpc"]["FileReadCommand"]; + FileWriteCommand: WaveEnv["rpc"]["FileWriteCommand"]; + FileMoveCommand: WaveEnv["rpc"]["FileMoveCommand"]; + FileDeleteCommand: WaveEnv["rpc"]["FileDeleteCommand"]; + SetConfigCommand: WaveEnv["rpc"]["SetConfigCommand"]; + SetMetaCommand: WaveEnv["rpc"]["SetMetaCommand"]; + FetchSuggestionsCommand: WaveEnv["rpc"]["FetchSuggestionsCommand"]; + DisposeSuggestionsCommand: WaveEnv["rpc"]["DisposeSuggestionsCommand"]; + FileCopyCommand: WaveEnv["rpc"]["FileCopyCommand"]; + FileCreateCommand: WaveEnv["rpc"]["FileCreateCommand"]; + FileMkdirCommand: WaveEnv["rpc"]["FileMkdirCommand"]; + }; + atoms: { + fullConfigAtom: WaveEnv["atoms"]["fullConfigAtom"]; + }; + services: { + object: WaveEnv["services"]["object"]; + }; + wos: WaveEnv["wos"]; + getSettingsKeyAtom: SettingsKeyAtomFnType<"preview:showhiddenfiles" | "editor:fontsize" | "preview:defaultsort">; + getConnStatusAtom: WaveEnv["getConnStatusAtom"]; +}>; diff --git a/frontend/app/view/quicktipsview/quicktipsview.tsx b/frontend/app/view/quicktipsview/quicktipsview.tsx index ec79e4e3f..c018fdca2 100644 --- a/frontend/app/view/quicktipsview/quicktipsview.tsx +++ b/frontend/app/view/quicktipsview/quicktipsview.tsx @@ -1,10 +1,10 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import type { BlockNodeModel } from "@/app/block/blocktypes"; -import type { TabModel } from "@/app/store/tab-model"; import { QuickTips } from "@/app/element/quicktips"; import { globalStore } from "@/app/store/global"; +import type { TabModel } from "@/app/store/tab-model"; import { Atom, atom, PrimitiveAtom } from "jotai"; class QuickTipsViewModel implements ViewModel { @@ -15,7 +15,7 @@ class QuickTipsViewModel implements ViewModel { showTocAtom: PrimitiveAtom; endIconButtons: Atom; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { + constructor({ blockId, nodeModel, tabModel }: ViewModelInitType) { this.blockId = blockId; this.nodeModel = nodeModel; this.tabModel = tabModel; diff --git a/frontend/app/view/sysinfo/sysinfo.tsx b/frontend/app/view/sysinfo/sysinfo.tsx index 2869f8ac1..30feead6c 100644 --- a/frontend/app/view/sysinfo/sysinfo.tsx +++ b/frontend/app/view/sysinfo/sysinfo.tsx @@ -1,9 +1,8 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import type { BlockNodeModel } from "@/app/block/blocktypes"; -import type { TabModel } from "@/app/store/tab-model"; -import { getConnStatusAtom, globalStore, WOS } from "@/store/global"; +import { globalStore } from "@/app/store/jotaiStore"; +import { makeORef } from "@/app/store/wos"; import * as util from "@/util/util"; import * as Plot from "@observablehq/plot"; import clsx from "clsx"; @@ -14,11 +13,22 @@ import * as React from "react"; import { useDimensionsWithExistingRef } from "@/app/hook/useDimensions"; import { waveEventSubscribeSingle } from "@/app/store/wps"; -import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; -import { atoms } from "@/store/global"; +import type { BlockMetaKeyAtomFnType, WaveEnv, WaveEnvSubset } from "@/app/waveenv/waveenv"; import { OverlayScrollbarsComponent, OverlayScrollbarsComponentRef } from "overlayscrollbars-react"; +export type SysinfoEnv = WaveEnvSubset<{ + rpc: { + EventReadHistoryCommand: WaveEnv["rpc"]["EventReadHistoryCommand"]; + SetMetaCommand: WaveEnv["rpc"]["SetMetaCommand"]; + }; + atoms: { + fullConfigAtom: WaveEnv["atoms"]["fullConfigAtom"]; + }; + getConnStatusAtom: WaveEnv["getConnStatusAtom"]; + getBlockMetaKeyAtom: BlockMetaKeyAtomFnType<"graph:numpoints" | "sysinfo:type" | "connection" | "count">; +}>; + const DefaultNumPoints = 120; type DataItem = { @@ -49,13 +59,13 @@ function defaultMemMeta(name: string, maxY: string): TimeSeriesMeta { } const PlotTypes: object = { - CPU: function (dataItem: DataItem): Array { + CPU: function (_dataItem: DataItem): Array { return ["cpu"]; }, - Mem: function (dataItem: DataItem): Array { + Mem: function (_dataItem: DataItem): Array { return ["mem:used"]; }, - "CPU + Mem": function (dataItem: DataItem): Array { + "CPU + Mem": function (_dataItem: DataItem): Array { return ["cpu", "mem:used"]; }, "All CPU": function (dataItem: DataItem): Array { @@ -94,9 +104,6 @@ function convertWaveEventToDataItem(event: Extract; termMode: jotai.Atom; htmlElemFocusRef: React.RefObject; blockId: string; @@ -117,13 +124,12 @@ class SysinfoViewModel implements ViewModel { plotMetaAtom: jotai.PrimitiveAtom>; endIconButtons: jotai.Atom; plotTypeSelectedAtom: jotai.Atom; + env: SysinfoEnv; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { - this.nodeModel = nodeModel; - this.tabModel = tabModel; + constructor({ blockId, waveEnv }: ViewModelInitType) { this.viewType = "sysinfo"; this.blockId = blockId; - this.blockAtom = WOS.getWaveObjectAtom(`block:${blockId}`); + this.env = waveEnv; this.addInitialDataAtom = jotai.atom(null, (get, set, points) => { const targetLen = get(this.numPoints) + 1; try { @@ -169,7 +175,7 @@ class SysinfoViewModel implements ViewModel { }); this.addContinuousDataAtom = jotai.atom(null, (get, set, newPoint) => { const targetLen = get(this.numPoints) + 1; - let data = get(this.dataAtom); + const data = get(this.dataAtom); try { const latestItemTs = newPoint?.ts ?? 0; const cutoffTs = latestItemTs - 1000 * targetLen; @@ -185,15 +191,14 @@ class SysinfoViewModel implements ViewModel { this.filterOutNowsh = jotai.atom(true); this.loadingAtom = jotai.atom(true); this.numPoints = jotai.atom((get) => { - const blockData = get(this.blockAtom); - const metaNumPoints = blockData?.meta?.["graph:numpoints"]; + const metaNumPoints = get(this.env.getBlockMetaKeyAtom(blockId, "graph:numpoints")); if (metaNumPoints == null || metaNumPoints <= 0) { return DefaultNumPoints; } return metaNumPoints; }); this.metrics = jotai.atom((get) => { - let plotType = get(this.plotTypeSelectedAtom); + const plotType = get(this.plotTypeSelectedAtom); const plotData = get(this.dataAtom); try { const metrics = PlotTypes[plotType](plotData[plotData.length - 1]); @@ -206,8 +211,7 @@ class SysinfoViewModel implements ViewModel { } }); this.plotTypeSelectedAtom = jotai.atom((get) => { - const blockData = get(this.blockAtom); - const plotType = blockData?.meta?.["sysinfo:type"]; + const plotType = get(this.env.getBlockMetaKeyAtom(blockId, "sysinfo:type")); if (plotType == null || typeof plotType != "string") { return "CPU"; } @@ -219,17 +223,15 @@ class SysinfoViewModel implements ViewModel { this.viewName = jotai.atom((get) => { return get(this.plotTypeSelectedAtom); }); - this.incrementCount = jotai.atom(null, async (get, set) => { - const meta = get(this.blockAtom).meta; - const count = meta.count ?? 0; - await RpcApi.SetMetaCommand(TabRpcClient, { - oref: WOS.makeORef("block", this.blockId), + this.incrementCount = jotai.atom(null, async (get, _set) => { + const count = get(this.env.getBlockMetaKeyAtom(blockId, "count")) ?? 0; + await this.env.rpc.SetMetaCommand(TabRpcClient, { + oref: makeORef("block", this.blockId), meta: { count: count + 1 }, }); }); this.connection = jotai.atom((get) => { - const blockData = get(this.blockAtom); - const connValue = blockData?.meta?.connection; + const connValue = get(this.env.getBlockMetaKeyAtom(blockId, "connection")); if (util.isBlank(connValue)) { return "local"; } @@ -238,9 +240,8 @@ class SysinfoViewModel implements ViewModel { this.dataAtom = jotai.atom([]); this.loadInitialData(); this.connStatus = jotai.atom((get) => { - const blockData = get(this.blockAtom); - const connName = blockData?.meta?.connection; - const connAtom = getConnStatusAtom(connName); + const connName = get(this.env.getBlockMetaKeyAtom(blockId, "connection")); + const connAtom = this.env.getConnStatusAtom(connName); return get(connAtom); }); } @@ -254,7 +255,7 @@ class SysinfoViewModel implements ViewModel { try { const numPoints = globalStore.get(this.numPoints); const connName = globalStore.get(this.connection); - const initialData = await RpcApi.EventReadHistoryCommand(TabRpcClient, { + const initialData = await this.env.rpc.EventReadHistoryCommand(TabRpcClient, { event: "sysinfo", scope: connName, maxitems: numPoints, @@ -262,7 +263,7 @@ class SysinfoViewModel implements ViewModel { if (initialData == null) { return; } - const newData = this.getDefaultData(); + this.getDefaultData(); const initialDataItems: DataItem[] = initialData.map(convertWaveEventToDataItem); // splice the initial data into the default data (replacing the newest points) //newData.splice(newData.length - initialDataItems.length, initialDataItems.length, ...initialDataItems); @@ -275,7 +276,7 @@ class SysinfoViewModel implements ViewModel { } getSettingsMenuItems(): ContextMenuItem[] { - const fullConfig = globalStore.get(atoms.fullConfigAtom); + const fullConfig = globalStore.get(this.env.atoms.fullConfigAtom); const termThemes = fullConfig?.termthemes ?? {}; const termThemeKeys = Object.keys(termThemes); const plotData = globalStore.get(this.dataAtom); @@ -296,8 +297,8 @@ class SysinfoViewModel implements ViewModel { type: "radio", checked: currentlySelected == plotType, click: async () => { - await RpcApi.SetMetaCommand(TabRpcClient, { - oref: WOS.makeORef("block", this.blockId), + await this.env.rpc.SetMetaCommand(TabRpcClient, { + oref: makeORef("block", this.blockId), meta: { "graph:metrics": dataTypes, "sysinfo:type": plotType }, }); }, @@ -326,7 +327,7 @@ class SysinfoViewModel implements ViewModel { } } -const plotColors = ["#58C142", "#FFC107", "#FF5722", "#2196F3", "#9C27B0", "#00BCD4", "#FFEB3B", "#795548"]; +const _plotColors = ["#58C142", "#FFC107", "#FF5722", "#2196F3", "#9C27B0", "#00BCD4", "#FFEB3B", "#795548"]; type SysinfoViewProps = { blockId: string; @@ -418,7 +419,7 @@ function SingleLinePlot({ const plotHeight = domRect?.height ?? 0; const plotWidth = domRect?.width ?? 0; const marks: Plot.Markish[] = []; - let decimalPlaces = yvalMeta?.decimalPlaces ?? 0; + const decimalPlaces = yvalMeta?.decimalPlaces ?? 0; let color = yvalMeta?.color; if (!color) { color = defaultColor; @@ -492,10 +493,10 @@ function SingleLinePlot({ Plot.pointerX({ x: "ts", y: yval, fill: color, r: 3, stroke: "var(--main-text-color)", strokeWidth: 1 }) ) ); - let maxY = resolveDomainBound(yvalMeta?.maxy, plotData[plotData.length - 1]) ?? 100; - let minY = resolveDomainBound(yvalMeta?.miny, plotData[plotData.length - 1]) ?? 0; - let maxX = plotData[plotData.length - 1].ts; - let minX = maxX - targetLen * 1000; + const maxY = resolveDomainBound(yvalMeta?.maxy, plotData[plotData.length - 1]) ?? 100; + const minY = resolveDomainBound(yvalMeta?.miny, plotData[plotData.length - 1]) ?? 0; + const maxX = plotData[plotData.length - 1].ts; + const minX = maxX - targetLen * 1000; const plot = Plot.plot({ axis: !sparkline, x: { @@ -549,7 +550,7 @@ const SysinfoViewInner = React.memo(({ model }: SysinfoViewProps) => { > {plotData && plotData.length > 0 && - yvals.map((yval, idx) => { + yvals.map((yval, _idx) => { return ( ({ + setRTInfoCommandMock: vi.fn().mockResolvedValue(undefined), +})); + +vi.mock("@/app/store/wshclientapi", () => ({ + RpcApi: { + SetRTInfoCommand: setRTInfoCommandMock, + }, +})); + +vi.mock("@/app/store/wshrpcutil", () => ({ + TabRpcClient: {}, +})); + +function makeTermWrap() { + return { + terminal: {}, + shellIntegrationStatusAtom: jotai.atom(null) as jotai.PrimitiveAtom<"ready" | "running-command" | null>, + lastCommandAtom: jotai.atom(null) as jotai.PrimitiveAtom, + shellInputBufferAtom: jotai.atom(null) as jotai.PrimitiveAtom, + shellInputCursorAtom: jotai.atom(null) as jotai.PrimitiveAtom, + } as any; +} + +describe("handleOsc16162Command input readback", () => { + beforeEach(() => { + vi.useFakeTimers(); + setRTInfoCommandMock.mockClear(); + }); + + afterEach(() => { + vi.runOnlyPendingTimers(); + vi.useRealTimers(); + }); + + it("updates shell input buffer and cursor from buffer64 payload", async () => { + const termWrap = makeTermWrap(); + const buffer = "echo hello λ"; + const buffer64 = stringToBase64(buffer); + + expect(handleOsc16162Command(`I;{"buffer64":"${buffer64}","cursor":4}`, "block-1", true, termWrap)).toBe(true); + + expect(globalStore.get(termWrap.shellInputBufferAtom)).toBe(buffer); + expect(globalStore.get(termWrap.shellInputCursorAtom)).toBe(4); + + await vi.runAllTimersAsync(); + + expect(setRTInfoCommandMock).toHaveBeenCalledWith( + {}, + { + oref: "block:block-1", + data: { + "shell:inputbuffer64": buffer64, + "shell:inputcursor": 4, + }, + } + ); + }); + + it("preserves empty buffer and cursor zero in runtime info", async () => { + const termWrap = makeTermWrap(); + + expect(handleOsc16162Command('I;{"buffer64":"","cursor":0}', "block-2", true, termWrap)).toBe(true); + + expect(globalStore.get(termWrap.shellInputBufferAtom)).toBe(""); + expect(globalStore.get(termWrap.shellInputCursorAtom)).toBe(0); + + await vi.runAllTimersAsync(); + + expect(setRTInfoCommandMock).toHaveBeenCalledWith( + {}, + { + oref: "block:block-2", + data: { + "shell:inputbuffer64": "", + "shell:inputcursor": 0, + }, + } + ); + }); + + it("ignores legacy inputempty payloads", async () => { + const termWrap = makeTermWrap(); + + expect(handleOsc16162Command('I;{"inputempty":false}', "block-3", true, termWrap)).toBe(true); + + expect(globalStore.get(termWrap.shellInputBufferAtom)).toBeNull(); + expect(globalStore.get(termWrap.shellInputCursorAtom)).toBeNull(); + + await vi.runAllTimersAsync(); + + expect(setRTInfoCommandMock).not.toHaveBeenCalled(); + }); +}); diff --git a/frontend/app/view/term/osc-handlers.ts b/frontend/app/view/term/osc-handlers.ts index dd8021ae1..713324c81 100644 --- a/frontend/app/view/term/osc-handlers.ts +++ b/frontend/app/view/term/osc-handlers.ts @@ -3,8 +3,15 @@ import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; -import { getApi, getBlockMetaKeyAtom, getBlockTermDurableAtom, globalStore, recordTEvent, WOS } from "@/store/global"; -import * as services from "@/store/services"; +import { + getApi, + getBlockMetaKeyAtom, + getBlockTermDurableAtom, + getOverrideConfigAtom, + globalStore, + recordTEvent, + WOS, +} from "@/store/global"; import { base64ToString, fireAndForget, isSshConnName, isWslConnName } from "@/util/util"; import debug from "debug"; import type { TermWrap } from "./termwrap"; @@ -33,7 +40,7 @@ type Osc16162Command = }; } | { command: "D"; data: { exitcode?: number } } - | { command: "I"; data: { inputempty?: boolean } } + | { command: "I"; data: { buffer64?: string; cursor?: number } } | { command: "R"; data: Record }; function checkCommandForTelemetry(decodedCmd: string) { @@ -78,7 +85,11 @@ function handleShellIntegrationCommandStart( rtInfo: ObjRTInfo // this is passed by reference and modified inside of this function ): void { rtInfo["shell:state"] = "running-command"; + rtInfo["shell:inputbuffer64"] = null; + rtInfo["shell:inputcursor"] = null; globalStore.set(termWrap.shellIntegrationStatusAtom, "running-command"); + globalStore.set(termWrap.shellInputBufferAtom, null); + globalStore.set(termWrap.shellInputCursorAtom, null); const connName = globalStore.get(getBlockMetaKeyAtom(blockId, "connection")) ?? ""; const isRemote = isSshConnName(connName); const isWsl = isWslConnName(connName); @@ -108,16 +119,41 @@ function handleShellIntegrationCommandStart( rtInfo["shell:lastcmdexitcode"] = null; } +function handleShellIntegrationInputReadback( + termWrap: TermWrap, + cmd: { command: "I"; data: { buffer64?: string; cursor?: number } }, + rtInfo: ObjRTInfo +): void { + const { buffer64, cursor } = cmd.data; + if (buffer64 == null || typeof cursor != "number" || !isFinite(cursor)) { + return; + } + let decodedBuffer: string; + try { + decodedBuffer = base64ToString(buffer64); + } catch (e) { + console.error("Error decoding shell input buffer64:", e); + return; + } + rtInfo["shell:inputbuffer64"] = buffer64; + rtInfo["shell:inputcursor"] = cursor; + globalStore.set(termWrap.shellInputBufferAtom, decodedBuffer); + globalStore.set(termWrap.shellInputCursorAtom, cursor); +} + // for xterm OSC handlers, we return true always because we "own" the OSC number. // even if data is invalid we don't want to propagate to other handlers. export function handleOsc52Command(data: string, blockId: string, loaded: boolean, termWrap: TermWrap): boolean { if (!loaded) { return true; } - const isBlockFocused = termWrap.nodeModel ? globalStore.get(termWrap.nodeModel.isFocused) : false; - if (!document.hasFocus() || !isBlockFocused) { - console.log("OSC 52: rejected, window or block not focused"); - return true; + const osc52Mode = globalStore.get(getOverrideConfigAtom(blockId, "term:osc52")) ?? "always"; + if (osc52Mode === "focus") { + const isBlockFocused = termWrap.nodeModel ? globalStore.get(termWrap.nodeModel.isFocused) : false; + if (!document.hasFocus() || !isBlockFocused) { + console.log("OSC 52: rejected, window or block not focused"); + return true; + } } if (!data || data.length === 0) { console.log("OSC 52: empty data received"); @@ -232,8 +268,9 @@ export function handleOsc7Command(data: string, blockId: string, loaded: boolean setTimeout(() => { fireAndForget(async () => { - await services.ObjectService.UpdateObjectMeta(WOS.makeORef("block", blockId), { - "cmd:cwd": pathPart, + await RpcApi.SetMetaCommand(TabRpcClient, { + oref: WOS.makeORef("block", blockId), + meta: { "cmd:cwd": pathPart }, }); const rtInfo = { "shell:hascurcwd": true }; @@ -320,12 +357,12 @@ export function handleOsc16162Command(data: string, blockId: string, loaded: boo } break; case "I": - if (cmd.data.inputempty != null) { - rtInfo["shell:inputempty"] = cmd.data.inputempty; - } + handleShellIntegrationInputReadback(termWrap, cmd, rtInfo); break; case "R": globalStore.set(termWrap.shellIntegrationStatusAtom, null); + globalStore.set(termWrap.shellInputBufferAtom, null); + globalStore.set(termWrap.shellInputCursorAtom, null); if (terminal.buffer.active.type === "alternate") { terminal.write("\x1b[?1049l"); } diff --git a/frontend/app/view/term/term-link-provider.ts b/frontend/app/view/term/term-link-provider.ts new file mode 100644 index 000000000..9f4d929a6 --- /dev/null +++ b/frontend/app/view/term/term-link-provider.ts @@ -0,0 +1,156 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { createBlock, globalStore, WOS } from "@/store/global"; +import { PLATFORM, PlatformMacOS } from "@/util/platformutil"; +import { fireAndForget } from "@/util/util"; +import type { IBufferRange, ILink, ILinkProvider, Terminal } from "@xterm/xterm"; + +// Matches file paths with optional line/col numbers: +// /absolute/path/file.ts +// ~/home/relative/file.ts +// ./relative/file.ts +// relative/file.ts (must contain / and end with known extension) +// file.ts:10 file.ts:10:5 (file.ts:42) +// at /path/file.js:10:5 (stack traces) +const FILE_PATH_REGEX = + /(?:^|[\s('"`:])((\/[\w.+\-@/]*[\w.+\-@])|(~\/[\w.+\-@/]*[\w.+\-@])|(\.\/?[\w.+\-@/]*[\w.+\-@])|([\w.+\-@]+(?:\/[\w.+\-@]+)+))(?::(\d+)(?::(\d+))?)?/g; + +// File extensions we recognize for bare relative paths (the ones without ./ prefix) +const KNOWN_EXTENSIONS = + /\.(ts|tsx|js|jsx|mjs|cjs|py|rb|go|rs|java|c|cpp|h|hpp|css|scss|less|html|json|yaml|yml|toml|md|txt|sh|bash|zsh|fish|lua|zig|swift|kt|scala|ex|exs|erl|hrl|vue|svelte|astro|sql|graphql|gql|proto|conf|cfg|ini|env|xml|csv|log)$/; + +// Well-known filenames without extensions (these need exact basename match, not dot-prefix) +const KNOWN_FILENAMES = /(^|\/)(Makefile|Dockerfile|Rakefile|Gemfile|Justfile|Vagrantfile|Procfile|Brewfile)$/; + +function getLineText(terminal: Terminal, lineNumber: number): string { + const buffer = terminal.buffer.active; + const line = buffer.getLine(lineNumber - 1); + if (!line) { + return ""; + } + return line.translateToString(true); +} + +function resolvePath(rawPath: string, cwd: string | undefined): string { + if (rawPath.startsWith("/")) { + return rawPath; + } + if (rawPath.startsWith("~/")) { + // Can't fully resolve ~ without knowing home dir, but pass through + // The preview block should handle ~ expansion + return rawPath; + } + if (cwd) { + const base = cwd.endsWith("/") ? cwd : cwd + "/"; + if (rawPath.startsWith("./")) { + return base + rawPath.slice(2); + } + return base + rawPath; + } + return rawPath; +} + +function getCwd(blockId: string): string | undefined { + const blockAtom = WOS.getWaveObjectAtom(`block:${blockId}`); + const blockData = globalStore.get(blockAtom); + return blockData?.meta?.["cmd:cwd"]; +} + +function getConnection(blockId: string): string | undefined { + const blockAtom = WOS.getWaveObjectAtom(`block:${blockId}`); + const blockData = globalStore.get(blockAtom); + return blockData?.meta?.connection; +} + +function openFileInPreview(filePath: string, blockId: string): void { + const connection = getConnection(blockId); + const meta: Record = { + view: "preview", + file: filePath, + }; + if (connection) { + meta.connection = connection; + } + const blockDef: BlockDef = { meta }; + fireAndForget(() => createBlock(blockDef)); +} + +export class FilePathLinkProvider implements ILinkProvider { + private blockId: string; + private terminal: Terminal; + + constructor(terminal: Terminal, blockId: string) { + this.terminal = terminal; + this.blockId = blockId; + } + + provideLinks(bufferLineNumber: number, callback: (links: ILink[] | undefined) => void): void { + const lineText = getLineText(this.terminal, bufferLineNumber); + if (!lineText) { + callback(undefined); + return; + } + + const links: ILink[] = []; + let match: RegExpExecArray | null; + FILE_PATH_REGEX.lastIndex = 0; + + while ((match = FILE_PATH_REGEX.exec(lineText)) !== null) { + const fullMatch = match[0]; + const pathPart = match[1]; + + // For bare relative paths (group 5), require a known file extension or filename + if (match[5] && !KNOWN_EXTENSIONS.test(match[5]) && !KNOWN_FILENAMES.test(match[5])) { + continue; + } + + // Calculate the start position (1-based column) + // The fullMatch may have a leading separator char that's not part of the path + const matchStart = match.index; + const pathStartInMatch = fullMatch.indexOf(pathPart); + const startX = matchStart + pathStartInMatch + 1; // 1-based + + // Include the line:col suffix in the link text for display + const lineNum = match[6]; + const colNum = match[7]; + let linkText = pathPart; + if (lineNum) { + linkText += ":" + lineNum; + if (colNum) { + linkText += ":" + colNum; + } + } + const endX = startX + linkText.length - 1; // 1-based, inclusive + + const range: IBufferRange = { + start: { x: startX, y: bufferLineNumber }, + end: { x: endX, y: bufferLineNumber }, + }; + + const blockId = this.blockId; + + links.push({ + range, + text: linkText, + decorations: { pointerCursor: true, underline: true }, + activate: (event: MouseEvent, text: string) => { + // Require Cmd (Mac) or Ctrl (other) to activate + const isModifierHeld = + PLATFORM === PlatformMacOS ? event.metaKey : event.ctrlKey; + if (!isModifierHeld) { + return; + } + // Strip line:col suffix for the file path + const colonIdx = text.indexOf(":"); + const filePath = colonIdx > 0 ? text.substring(0, colonIdx) : text; + const cwd = getCwd(blockId); + const resolved = resolvePath(filePath, cwd); + openFileInPreview(resolved, blockId); + }, + }); + } + + callback(links.length > 0 ? links : undefined); + } +} diff --git a/frontend/app/view/term/term-model.ts b/frontend/app/view/term/term-model.ts index de8a6b963..5e08a6a67 100644 --- a/frontend/app/view/term/term-model.ts +++ b/frontend/app/view/term/term-model.ts @@ -85,7 +85,7 @@ export class TermViewModel implements ViewModel { termConfigedDurable: jotai.Atom; searchAtoms?: SearchAtoms; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { + constructor({ blockId, nodeModel, tabModel }: ViewModelInitType) { this.viewType = "term"; this.blockId = blockId; this.tabModel = tabModel; @@ -738,10 +738,7 @@ export class TermViewModel implements ViewModel { } this.triggerRestartAtom(); await RpcApi.ControllerDestroyCommand(TabRpcClient, this.blockId); - const termsize = { - rows: this.termRef.current?.terminal?.rows, - cols: this.termRef.current?.terminal?.cols, - }; + const termsize = this.termRef.current?.getTermSize(); await RpcApi.ControllerResyncCommand(TabRpcClient, { tabid: globalStore.get(atoms.staticTabId), blockid: this.blockId, @@ -756,10 +753,7 @@ export class TermViewModel implements ViewModel { meta: { "term:durable": isDurable }, }); await RpcApi.ControllerDestroyCommand(TabRpcClient, this.blockId); - const termsize = { - rows: this.termRef.current?.terminal?.rows, - cols: this.termRef.current?.terminal?.cols, - }; + const termsize = this.termRef.current?.getTermSize(); await RpcApi.ControllerResyncCommand(TabRpcClient, { tabid: globalStore.get(atoms.staticTabId), blockid: this.blockId, diff --git a/frontend/app/view/term/term.scss b/frontend/app/view/term/term.scss index b96c4e18f..e69fc008f 100644 --- a/frontend/app/view/term/term.scss +++ b/frontend/app/view/term/term.scss @@ -59,8 +59,7 @@ min-height: 0; overflow: hidden; line-height: 1; - margin: 5px; - margin-left: 4px; + margin: 5px 1px 5px 4px; } .term-htmlelem { @@ -126,30 +125,12 @@ } } - // The 18px width is the width of the scrollbar plus the margin - .term-scrollbar-show-observer { - z-index: calc(var(--zindex-xterm-viewport-overlay) - 1); - position: absolute; - top: 0; - right: 0; - height: 100%; - width: 18px; - } - - .term-scrollbar-hide-observer { - z-index: calc(var(--zindex-xterm-viewport-overlay) + 1); - display: none; - position: absolute; - top: 0; - left: 0; - height: 100%; - width: calc(100% - 18px); - } - .terminal { + width: 100%; + .xterm-viewport { &::-webkit-scrollbar { - width: 6px; + width: 6px; /* this needs to match fitAddon.scrollbarWidth in termwrap.ts */ height: 6px; } @@ -158,24 +139,23 @@ } &::-webkit-scrollbar-thumb { - display: none; - background-color: var(--scrollbar-thumb-color); + background-color: transparent; border-radius: 4px; margin: 0 1px 0 1px; &:hover { - background-color: var(--scrollbar-thumb-hover-color); + background-color: var(--scrollbar-thumb-hover-color) !important; } &:active { - background-color: var(--scrollbar-thumb-active-color); + background-color: var(--scrollbar-thumb-active-color) !important; } } } &:hover { .xterm-viewport::-webkit-scrollbar-thumb { - display: block; + background-color: var(--scrollbar-thumb-color); } } } diff --git a/frontend/app/view/term/term.tsx b/frontend/app/view/term/term.tsx index 3591b8f2e..b16768890 100644 --- a/frontend/app/view/term/term.tsx +++ b/frontend/app/view/term/term.tsx @@ -354,18 +354,6 @@ const TerminalView = ({ blockId, model }: ViewComponentProps) => } }, [isMI, isBasicTerm, isFocused]); - const scrollbarHideObserverRef = React.useRef(null); - const onScrollbarShowObserver = React.useCallback(() => { - const termViewport = viewRef.current.getElementsByClassName("xterm-viewport")[0] as HTMLDivElement; - termViewport.style.zIndex = "var(--zindex-xterm-viewport-overlay)"; - scrollbarHideObserverRef.current.style.display = "block"; - }, []); - const onScrollbarHideObserver = React.useCallback(() => { - const termViewport = viewRef.current.getElementsByClassName("xterm-viewport")[0] as HTMLDivElement; - termViewport.style.zIndex = "auto"; - scrollbarHideObserverRef.current.style.display = "none"; - }, []); - const stickerConfig = { charWidth: 8, charHeight: 16, @@ -388,20 +376,13 @@ const TerminalView = ({ blockId, model }: ViewComponentProps) => return (
- {termBg &&
} + {termBg &&
} -
-
-
-
+
diff --git a/frontend/app/view/term/termwrap.ts b/frontend/app/view/term/termwrap.ts index 74a22bae0..b744eef08 100644 --- a/frontend/app/view/term/termwrap.ts +++ b/frontend/app/view/term/termwrap.ts @@ -2,26 +2,27 @@ // SPDX-License-Identifier: Apache-2.0 import type { BlockNodeModel } from "@/app/block/blocktypes"; +import { setBadge } from "@/app/store/badge"; import { getFileSubject } from "@/app/store/wps"; import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; import { - atoms, fetchWaveFile, getOverrideConfigAtom, getSettingsKeyAtom, globalStore, + isDev, openLink, - setTabIndicator, WOS, } from "@/store/global"; import * as services from "@/store/services"; import { PLATFORM, PlatformMacOS } from "@/util/platformutil"; -import { base64ToArray, fireAndForget } from "@/util/util"; +import { base64ToArray, base64ToString, fireAndForget } from "@/util/util"; import { SearchAddon } from "@xterm/addon-search"; import { SerializeAddon } from "@xterm/addon-serialize"; import { WebLinksAddon } from "@xterm/addon-web-links"; import { WebglAddon } from "@xterm/addon-webgl"; +import { ImageAddon } from "@xterm/addon-image"; import * as TermTypes from "@xterm/xterm"; import { Terminal } from "@xterm/xterm"; import debug from "debug"; @@ -34,6 +35,7 @@ import { handleOsc7Command, type ShellIntegrationStatus, } from "./osc-handlers"; +import { FilePathLinkProvider } from "./term-link-provider"; import { bufferLinesToText, createTempFileFromBlob, extractAllClipboardData, normalizeCursorStyle } from "./termutil"; const dlog = debug("wave:termwrap"); @@ -43,6 +45,7 @@ const TermCacheFileName = "cache:term:full"; const MinDataProcessedForCache = 100 * 1024; export const SupportsImageInput = true; const IMEDedupWindowMs = 20; +const MaxRepaintTransactionMs = 2000; // detect webgl support function detectWebGLSupport(): boolean { @@ -61,6 +64,7 @@ let loggedWebGL = false; type TermWrapOptions = { keydownHandler?: (e: KeyboardEvent) => boolean; useWebGl?: boolean; + useSixel?: boolean; sendDataHandler?: (data: string) => void; nodeModel?: BlockNodeModel; }; @@ -89,6 +93,8 @@ export class TermWrap { promptMarkers: TermTypes.IMarker[] = []; shellIntegrationStatusAtom: jotai.PrimitiveAtom; lastCommandAtom: jotai.PrimitiveAtom; + shellInputBufferAtom: jotai.PrimitiveAtom; + shellInputCursorAtom: jotai.PrimitiveAtom; nodeModel: BlockNodeModel; // this can be null hoveredLinkUri: string | null = null; onLinkHover?: (uri: string | null, mouseX: number, mouseY: number) => void; @@ -104,9 +110,23 @@ export class TermWrap { // xterm.js paste() method triggers onData event, which can cause duplicate sends lastPasteData: string = ""; lastPasteTime: number = 0; + + // for scrollToBottom support during a resize lastAtBottomTime: number = Date.now(); lastScrollAtBottom: boolean = true; cachedAtBottomForResize: boolean | null = null; + viewportScrollTop: number = 0; + + // dev only (for debugging) + recentWrites: { idx: number; data: string; ts: number }[] = []; + recentWritesCounter: number = 0; + + // for repaint transaction scrolling behavior + lastClearScrollbackTs: number = 0; + lastMode2026SetTs: number = 0; + lastMode2026ResetTs: number = 0; + inSyncTransaction: boolean = false; + inRepaintTransaction: boolean = false; constructor( tabId: string, @@ -127,9 +147,11 @@ export class TermWrap { this.promptMarkers = []; this.shellIntegrationStatusAtom = jotai.atom(null) as jotai.PrimitiveAtom; this.lastCommandAtom = jotai.atom(null) as jotai.PrimitiveAtom; + this.shellInputBufferAtom = jotai.atom(null) as jotai.PrimitiveAtom; + this.shellInputCursorAtom = jotai.atom(null) as jotai.PrimitiveAtom; this.terminal = new Terminal(options); this.fitAddon = new FitAddon(); - this.fitAddon.noScrollbar = PLATFORM === PlatformMacOS; + this.fitAddon.scrollbarWidth = 6; // this needs to match scrollbar width in term.scss this.serializeAddon = new SerializeAddon(); this.searchAddon = new SearchAddon(); this.terminal.loadAddon(this.searchAddon); @@ -177,6 +199,19 @@ export class TermWrap { loggedWebGL = true; } } + if (waveOptions.useSixel ?? true) { + try { + this.terminal.loadAddon( + new ImageAddon({ + enableSizeReports: true, + sixelSupport: true, + iipSupport: false, + }) + ); + } catch (e) { + console.error("failed to load image addon for sixel support", e); + } + } // Register OSC handlers this.terminal.parser.registerOscHandler(7, (data: string) => { return handleOsc7Command(data, this.blockId, this.loaded); @@ -187,6 +222,47 @@ export class TermWrap { this.terminal.parser.registerOscHandler(16162, (data: string) => { return handleOsc16162Command(data, this.blockId, this.loaded, this); }); + this.toDispose.push( + this.terminal.registerLinkProvider(new FilePathLinkProvider(this.terminal, this.blockId)) + ); + this.toDispose.push( + this.terminal.parser.registerCsiHandler({ final: "J" }, (params) => { + if (params[0] === 3) { + this.lastClearScrollbackTs = Date.now(); + if (this.inSyncTransaction) { + console.log("[termwrap] repaint transaction starting"); + this.inRepaintTransaction = true; + } + } + return false; + }) + ); + this.toDispose.push( + this.terminal.parser.registerCsiHandler({ prefix: "?", final: "h" }, (params) => { + if (params[0] === 2026) { + this.lastMode2026SetTs = Date.now(); + this.inSyncTransaction = true; + } + return false; + }) + ); + this.toDispose.push( + this.terminal.parser.registerCsiHandler({ prefix: "?", final: "l" }, (params) => { + if (params[0] === 2026) { + this.lastMode2026ResetTs = Date.now(); + this.inSyncTransaction = false; + const wasRepaint = this.inRepaintTransaction; + this.inRepaintTransaction = false; + if (wasRepaint && Date.now() - this.lastClearScrollbackTs <= MaxRepaintTransactionMs) { + setTimeout(() => { + console.log("[termwrap] repaint transaction complete, scrolling to bottom"); + this.terminal.scrollToBottom(); + }, 20); + } + } + return false; + }) + ); this.toDispose.push( this.terminal.onBell(() => { if (!this.loaded) { @@ -201,8 +277,7 @@ export class TermWrap { const bellIndicatorEnabled = globalStore.get(getOverrideConfigAtom(this.blockId, "term:bellindicator")) ?? false; if (bellIndicatorEnabled) { - const tabId = globalStore.get(atoms.staticTabId); - setTabIndicator(tabId, { icon: "bell", color: "#fbbf24", clearonfocus: true, priority: 1 }); + setBadge(this.blockId, { icon: "bell", color: "#fbbf24", priority: 1 }); } return true; }) @@ -231,9 +306,8 @@ export class TermWrap { }); const viewportElem = this.connectElem.querySelector(".xterm-viewport") as HTMLElement; if (viewportElem) { - const scrollHandler = () => { - const atBottom = viewportElem.scrollTop + viewportElem.clientHeight >= viewportElem.scrollHeight - 20; - this.setAtBottom(atBottom); + const scrollHandler = (e: any) => { + this.handleViewportScroll(viewportElem); }; viewportElem.addEventListener("scroll", scrollHandler); this.toDispose.push({ @@ -292,6 +366,12 @@ export class TermWrap { if (!globalStore.get(copyOnSelectAtom)) { return; } + // Don't copy-on-select when the search bar has focus — navigating + // search results changes the terminal selection programmatically. + const active = document.activeElement; + if (active != null && active.closest(".search-container") != null) { + return; + } const selectedText = this.terminal.getSelection(); if (selectedText.length > 0) { navigator.clipboard.writeText(selectedText); @@ -346,6 +426,19 @@ export class TermWrap { const lastCmd = rtInfo ? rtInfo["shell:lastcmd"] : null; globalStore.set(this.lastCommandAtom, lastCmd || null); + const inputBuffer64 = rtInfo ? rtInfo["shell:inputbuffer64"] : null; + if (inputBuffer64 == null) { + globalStore.set(this.shellInputBufferAtom, null); + } else { + try { + globalStore.set(this.shellInputBufferAtom, base64ToString(inputBuffer64)); + } catch (e) { + console.error("Error loading shell input buffer:", e); + globalStore.set(this.shellInputBufferAtom, null); + } + } + const inputCursor = rtInfo ? rtInfo["shell:inputcursor"] : null; + globalStore.set(this.shellInputCursorAtom, inputCursor == null ? null : inputCursor); } catch (e) { console.log("Error loading runtime info:", e); } @@ -416,6 +509,13 @@ export class TermWrap { } doTerminalWrite(data: string | Uint8Array, setPtyOffset?: number): Promise { + if (isDev() && this.loaded) { + const dataStr = data instanceof Uint8Array ? new TextDecoder().decode(data) : data; + this.recentWrites.push({ idx: this.recentWritesCounter++, ts: Date.now(), data: dataStr }); + if (this.recentWrites.length > 50) { + this.recentWrites.shift(); + } + } let resolve: () => void = null; let prtn = new Promise((presolve, _) => { resolve = presolve; @@ -433,6 +533,35 @@ export class TermWrap { return prtn; } + private getTerminalPixelSize(): { xpixel: number; ypixel: number } { + const screenElem = this.connectElem.querySelector(".xterm-screen") as HTMLElement | null; + const targetElem = screenElem ?? this.connectElem; + const rect = targetElem.getBoundingClientRect(); + return { + xpixel: Math.max(0, Math.floor(rect.width)), + ypixel: Math.max(0, Math.floor(rect.height)), + }; + } + + private areTermSizesEqual(a: TermSize, b: TermSize): boolean { + return ( + a.rows === b.rows && + a.cols === b.cols && + (a.xpixel ?? 0) === (b.xpixel ?? 0) && + (a.ypixel ?? 0) === (b.ypixel ?? 0) + ); + } + + getTermSize(): TermSize { + const { xpixel, ypixel } = this.getTerminalPixelSize(); + const termSize: TermSize = { rows: this.terminal.rows, cols: this.terminal.cols }; + if (xpixel > 0 && ypixel > 0) { + termSize.xpixel = xpixel; + termSize.ypixel = ypixel; + } + return termSize; + } + async loadInitialTerminalData(): Promise { const startTs = Date.now(); const zoneId = this.getZoneId(); @@ -441,7 +570,7 @@ export class TermWrap { if (cacheFile != null) { ptyOffset = cacheFile.meta["ptyoffset"] ?? 0; if (cacheData.byteLength > 0) { - const curTermSize: TermSize = { rows: this.terminal.rows, cols: this.terminal.cols }; + const curTermSize: TermSize = this.getTermSize(); const fileTermSize: TermSize = cacheFile.meta["termsize"]; let didResize = false; if ( @@ -469,7 +598,7 @@ export class TermWrap { async resyncController(reason: string) { dlog("resync controller", this.blockId, reason); - const rtOpts: RuntimeOpts = { termsize: { rows: this.terminal.rows, cols: this.terminal.cols } }; + const rtOpts: RuntimeOpts = { termsize: this.getTermSize() }; try { await RpcApi.ControllerResyncCommand(TabRpcClient, { tabid: this.tabId, @@ -498,25 +627,51 @@ export class TermWrap { return Date.now() - this.lastAtBottomTime <= 1000; } + handleViewportScroll(viewportElem: HTMLElement) { + const { scrollTop, scrollHeight, clientHeight } = viewportElem; + const atBottom = scrollTop + clientHeight >= scrollHeight - clientHeight * 0.5; + this.setAtBottom(atBottom); + const delta = this.viewportScrollTop - scrollTop; + if (isDev() && delta >= 500) { + console.log( + `[termwrap] large-scroll blockId=${this.blockId} delta=${Math.round(delta)}px scrollTop=${scrollTop} wasNearBottom=${atBottom}` + ); + } + this.viewportScrollTop = scrollTop; + } + handleResize() { - const oldRows = this.terminal.rows; - const oldCols = this.terminal.cols; + const oldTermSize = this.getTermSize(); const atBottom = this.cachedAtBottomForResize ?? this.wasRecentlyAtBottom(); if (!atBottom) { this.cachedAtBottomForResize = null; } this.fitAddon.fit(); - if (oldRows !== this.terminal.rows || oldCols !== this.terminal.cols) { - const termSize: TermSize = { rows: this.terminal.rows, cols: this.terminal.cols }; - RpcApi.ControllerInputCommand(TabRpcClient, { blockid: this.blockId, termsize: termSize }); + const newTermSize = this.getTermSize(); + if (!this.areTermSizesEqual(oldTermSize, newTermSize)) { + console.log( + "[termwrap] resize", + `${oldTermSize.rows}x${oldTermSize.cols}`, + "->", + `${newTermSize.rows}x${newTermSize.cols}`, + "atBottom:", + atBottom + ); + RpcApi.ControllerInputCommand(TabRpcClient, { blockid: this.blockId, termsize: newTermSize }); } - dlog("resize", `${this.terminal.rows}x${this.terminal.cols}`, `${oldRows}x${oldCols}`, this.hasResized); + dlog( + "resize", + `${newTermSize.rows}x${newTermSize.cols}`, + `${oldTermSize.rows}x${oldTermSize.cols}`, + this.hasResized + ); if (!this.hasResized) { this.hasResized = true; this.resyncController("initial resize"); } if (atBottom) { setTimeout(() => { + console.log("[termwrap] resize scroll-to-bottom"); this.cachedAtBottomForResize = null; this.terminal.scrollToBottom(); this.setAtBottom(true); @@ -529,7 +684,7 @@ export class TermWrap { return; } const serializedOutput = this.serializeAddon.serialize(); - const termSize: TermSize = { rows: this.terminal.rows, cols: this.terminal.cols }; + const termSize: TermSize = this.getTermSize(); console.log("idle timeout term", this.dataBytesProcessed, serializedOutput.length, termSize); fireAndForget(() => services.BlockService.SaveTerminalState(this.blockId, serializedOutput, "full", this.ptyOffset, termSize) diff --git a/frontend/app/view/tsunami/tsunami.tsx b/frontend/app/view/tsunami/tsunami.tsx index 14ca08574..c23cd7603 100644 --- a/frontend/app/view/tsunami/tsunami.tsx +++ b/frontend/app/view/tsunami/tsunami.tsx @@ -1,9 +1,7 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import { BlockNodeModel } from "@/app/block/blocktypes"; import { getApi, globalStore, WOS } from "@/app/store/global"; -import type { TabModel } from "@/app/store/tab-model"; import { waveEventSubscribeSingle } from "@/app/store/wps"; import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; @@ -21,8 +19,8 @@ class TsunamiViewModel extends WebViewModel { viewIcon: jotai.Atom; viewName: jotai.Atom; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { - super(blockId, nodeModel, tabModel); + constructor(initOpts: ViewModelInitType) { + super(initOpts); this.viewType = "tsunami"; this.isRestarting = jotai.atom(false); @@ -30,16 +28,16 @@ class TsunamiViewModel extends WebViewModel { this.hideNav = jotai.atom(true); // Set custom partition for tsunami WebView isolation - this.partitionOverride = jotai.atom(`tsunami:${blockId}`); + this.partitionOverride = jotai.atom(`tsunami:${this.blockId}`); this.shellProcFullStatus = jotai.atom(null) as jotai.PrimitiveAtom; - const initialShellProcStatus = services.BlockService.GetControllerStatus(blockId); + const initialShellProcStatus = services.BlockService.GetControllerStatus(this.blockId); initialShellProcStatus.then((rts) => { this.updateShellProcStatus(rts); }); this.shellProcStatusUnsubFn = waveEventSubscribeSingle({ eventType: "controllerstatus", - scope: WOS.makeORef("block", blockId), + scope: WOS.makeORef("block", this.blockId), handler: (event) => { this.updateShellProcStatus(event.data); }, @@ -61,7 +59,7 @@ class TsunamiViewModel extends WebViewModel { return meta?.title || "WaveApp"; }); const initialRTInfo = RpcApi.GetRTInfoCommand(TabRpcClient, { - oref: WOS.makeORef("block", blockId), + oref: WOS.makeORef("block", this.blockId), }); initialRTInfo.then((rtInfo) => { if (rtInfo && rtInfo["tsunami:appmeta"]) { @@ -70,7 +68,7 @@ class TsunamiViewModel extends WebViewModel { }); this.appMetaUnsubFn = waveEventSubscribeSingle({ eventType: "tsunami:updatemeta", - scope: WOS.makeORef("block", blockId), + scope: WOS.makeORef("block", this.blockId), handler: (event) => { globalStore.set(this.appMeta, event.data); }, diff --git a/frontend/app/view/vdom/vdom-model.tsx b/frontend/app/view/vdom/vdom-model.tsx index 4751ed1d2..77b01495e 100644 --- a/frontend/app/view/vdom/vdom-model.tsx +++ b/frontend/app/view/vdom/vdom-model.tsx @@ -1,9 +1,9 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { BlockNodeModel } from "@/app/block/blocktypes"; -import type { TabModel } from "@/app/store/tab-model"; import { getBlockMetaKeyAtom, globalStore, WOS } from "@/app/store/global"; +import type { TabModel } from "@/app/store/tab-model"; import { makeORef } from "@/app/store/wos"; import { waveEventSubscribeSingle } from "@/app/store/wps"; import { RpcResponseHelper, WshClient } from "@/app/store/wshclient"; @@ -140,7 +140,7 @@ export class VDomModel { hasBackendWork: boolean = false; noPadding: jotai.PrimitiveAtom; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { + constructor({ blockId, nodeModel, tabModel }: ViewModelInitType) { this.viewType = "vdom"; this.blockId = blockId; this.nodeModel = nodeModel; diff --git a/frontend/app/view/waveai/waveai.tsx b/frontend/app/view/waveai/waveai.tsx index 6d2dd8fc8..630f04726 100644 --- a/frontend/app/view/waveai/waveai.tsx +++ b/frontend/app/view/waveai/waveai.tsx @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { BlockNodeModel } from "@/app/block/blocktypes"; @@ -92,7 +92,7 @@ export class WaveAiModel implements ViewModel { cancel: boolean; aiWshClient: AiWshClient; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { + constructor({ blockId, nodeModel, tabModel }: ViewModelInitType) { this.blockId = blockId; this.nodeModel = nodeModel; this.tabModel = tabModel; diff --git a/frontend/app/view/waveconfig/waveconfig-model.ts b/frontend/app/view/waveconfig/waveconfig-model.ts index cd7d4e45e..94cd11444 100644 --- a/frontend/app/view/waveconfig/waveconfig-model.ts +++ b/frontend/app/view/waveconfig/waveconfig-model.ts @@ -1,17 +1,17 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { BlockNodeModel } from "@/app/block/blocktypes"; -import type { TabModel } from "@/app/store/tab-model"; -import { getApi, getBlockMetaKeyAtom, WOS } from "@/app/store/global"; +import { atoms, getApi, getBlockMetaKeyAtom, WOS } from "@/app/store/global"; import { globalStore } from "@/app/store/jotaiStore"; +import type { TabModel } from "@/app/store/tab-model"; import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; import { SecretsContent } from "@/app/view/waveconfig/secretscontent"; import { WaveConfigView } from "@/app/view/waveconfig/waveconfig"; import { isWindows } from "@/util/platformutil"; import { base64ToString, stringToBase64 } from "@/util/util"; -import { atom, type PrimitiveAtom } from "jotai"; +import { atom, type Atom, type PrimitiveAtom } from "jotai"; import type * as MonacoTypes from "monaco-editor"; import * as React from "react"; @@ -156,6 +156,7 @@ export class WaveConfigViewModel implements ViewModel { isMenuOpenAtom: PrimitiveAtom; presetsJsonExistsAtom: PrimitiveAtom; activeTabAtom: PrimitiveAtom<"visual" | "json">; + configErrorFilesAtom: Atom>; configDir: string; saveShortcut: string; editorRef: React.RefObject; @@ -170,7 +171,7 @@ export class WaveConfigViewModel implements ViewModel { storageBackendErrorAtom: PrimitiveAtom; secretValueRef: HTMLTextAreaElement | null = null; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { + constructor({ blockId, nodeModel, tabModel }: ViewModelInitType) { this.blockId = blockId; this.nodeModel = nodeModel; this.tabModel = tabModel; @@ -189,6 +190,14 @@ export class WaveConfigViewModel implements ViewModel { this.isMenuOpenAtom = atom(false); this.presetsJsonExistsAtom = atom(false); this.activeTabAtom = atom<"visual" | "json">("visual"); + this.configErrorFilesAtom = atom((get) => { + const fullConfig = get(atoms.fullConfigAtom); + const errorSet = new Set(); + for (const cerr of fullConfig?.configerrors ?? []) { + errorSet.add(cerr.file); + } + return errorSet; + }); this.editorRef = React.createRef(); this.secretNamesAtom = atom([]); diff --git a/frontend/app/view/waveconfig/waveconfig.tsx b/frontend/app/view/waveconfig/waveconfig.tsx index 4e515466f..00747ff3c 100644 --- a/frontend/app/view/waveconfig/waveconfig.tsx +++ b/frontend/app/view/waveconfig/waveconfig.tsx @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { Tooltip } from "@/app/element/tooltip"; +import { atoms } from "@/app/store/global"; import { globalStore } from "@/app/store/jotaiStore"; import { tryReinjectKey } from "@/app/store/keymodel"; import { CodeEditor } from "@/app/view/codeeditor/codeeditor"; @@ -21,6 +22,7 @@ const ConfigSidebar = memo(({ model }: ConfigSidebarProps) => { const [isMenuOpen, setIsMenuOpen] = useAtom(model.isMenuOpenAtom); const configFiles = model.getConfigFiles(); const deprecatedConfigFiles = model.getDeprecatedConfigFiles(); + const configErrorFiles = useAtomValue(model.configErrorFilesAtom); const handleFileSelect = (file: ConfigFile) => { model.loadFile(file); @@ -46,7 +48,12 @@ const ConfigSidebar = memo(({ model }: ConfigSidebarProps) => { selectedFile?.path === file.path ? "bg-accentbg text-primary" : "hover:bg-secondary/50" }`} > -
{file.name}
+
+
{file.name}
+ {configErrorFiles.has(file.path) && ( + + )} +
{file.description && (
{file.description} @@ -75,6 +82,9 @@ const ConfigSidebar = memo(({ model }: ConfigSidebarProps) => { > deprecated + {configErrorFiles.has(file.path) && ( + + )}
))} @@ -96,6 +106,8 @@ const WaveConfigView = memo(({ blockId, model }: ViewComponentProps { @@ -148,7 +160,8 @@ const WaveConfigView = memo(({ blockId, model }: ViewComponentProps +
+
{isMenuOpen && (
setIsMenuOpen(false)} /> )} @@ -284,6 +297,17 @@ const WaveConfigView = memo(({ blockId, model }: ViewComponentProps )}
+
+ {configErrors?.length > 0 && ( +
+ {configErrors.map((cerr, i) => ( +
+ Config Error: + {cerr.file}: {cerr.err} +
+ ))} +
+ )}
); }); diff --git a/frontend/app/view/webview/webview.test.tsx b/frontend/app/view/webview/webview.test.tsx new file mode 100644 index 000000000..99302dd2f --- /dev/null +++ b/frontend/app/view/webview/webview.test.tsx @@ -0,0 +1,20 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { renderToStaticMarkup } from "react-dom/server"; +import { describe, expect, it } from "vitest"; +import { getWebPreviewDisplayUrl, WebViewPreviewFallback } from "./webview"; + +describe("webview preview fallback", () => { + it("shows the requested URL", () => { + const markup = renderToStaticMarkup(); + + expect(markup).toContain("electron webview unavailable"); + expect(markup).toContain("https://waveterm.dev/docs"); + }); + + it("falls back to about:blank when no URL is available", () => { + expect(getWebPreviewDisplayUrl("")).toBe("about:blank"); + expect(getWebPreviewDisplayUrl(null)).toBe("about:blank"); + }); +}); diff --git a/frontend/app/view/webview/webview.tsx b/frontend/app/view/webview/webview.tsx index 7fa1671b2..3b10d4cce 100644 --- a/frontend/app/view/webview/webview.tsx +++ b/frontend/app/view/webview/webview.tsx @@ -1,12 +1,12 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { BlockNodeModel } from "@/app/block/blocktypes"; -import type { TabModel } from "@/app/store/tab-model"; import { Search, useSearch } from "@/app/element/search"; import { createBlock, getApi, getBlockMetaKeyAtom, getSettingsKeyAtom, openLink } from "@/app/store/global"; import { getSimpleControlShiftAtom } from "@/app/store/keymodel"; import { ObjectService } from "@/app/store/services"; +import type { TabModel } from "@/app/store/tab-model"; import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; import { @@ -14,6 +14,7 @@ import { SuggestionControlNoData, SuggestionControlNoResults, } from "@/app/suggestion/suggestion"; +import { MockBoundary } from "@/app/waveenv/mockboundary"; import { WOS, globalStore } from "@/store/global"; import { adaptFromReactOrNativeKeyEvent, checkKeyPressed } from "@/util/keyutil"; import { fireAndForget, useAtomValueSafe } from "@/util/util"; @@ -72,7 +73,7 @@ export class WebViewModel implements ViewModel { partitionOverride: PrimitiveAtom | null; userAgentType: Atom; - constructor(blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) { + constructor({ blockId, nodeModel, tabModel }: ViewModelInitType) { this.nodeModel = nodeModel; this.tabModel = tabModel; this.viewType = "web"; @@ -83,7 +84,7 @@ export class WebViewModel implements ViewModel { const defaultUrlAtom = getSettingsKeyAtom("web:defaulturl"); this.homepageUrl = atom((get) => { const defaultUrl = get(defaultUrlAtom); - const pinnedUrl = get(this.blockAtom).meta.pinnedurl; + const pinnedUrl = get(this.blockAtom)?.meta?.pinnedurl; return pinnedUrl ?? defaultUrl; }); this.urlWrapperClassName = atom(""); @@ -112,7 +113,7 @@ export class WebViewModel implements ViewModel { const refreshIcon = get(this.refreshIcon); const mediaPlaying = get(this.mediaPlaying); const mediaMuted = get(this.mediaMuted); - const url = currUrl ?? metaUrl ?? homepageUrl; + const url = currUrl ?? metaUrl ?? homepageUrl ?? ""; const rtn: HeaderElem[] = []; if (get(this.hideNav)) { return rtn; @@ -802,13 +803,35 @@ interface WebViewProps { initialSrc?: string; } +function getWebPreviewDisplayUrl(url?: string | null): string { + return url?.trim() || "about:blank"; +} + +function WebViewPreviewFallback({ url }: { url?: string | null }) { + const displayUrl = getWebPreviewDisplayUrl(url); + + return ( +
+
+
preview mock · electron webview unavailable
+
web widget placeholder
+
+ {displayUrl} +
+
+
+ ); +} + const WebView = memo(({ model, onFailLoad, blockRef, initialSrc }: WebViewProps) => { const blockData = useAtomValue(model.blockAtom); const defaultUrl = useAtomValue(model.homepageUrl); const defaultSearchAtom = getSettingsKeyAtom("web:defaultsearch"); const defaultSearch = useAtomValue(defaultSearchAtom); - let metaUrl = blockData?.meta?.url || defaultUrl; - metaUrl = model.ensureUrlScheme(metaUrl, defaultSearch); + let metaUrl = blockData?.meta?.url || defaultUrl || ""; + if (metaUrl) { + metaUrl = model.ensureUrlScheme(metaUrl, defaultSearch); + } const metaUrlRef = useRef(metaUrl); const zoomFactor = useAtomValue(getBlockMetaKeyAtom(model.blockId, "web:zoom")) || 1; const partitionOverride = useAtomValueSafe(model.partitionOverride); @@ -1055,19 +1078,21 @@ const WebView = memo(({ model, onFailLoad, blockRef, initialSrc }: WebViewProps) return ( - + }> + + {errorText && (
{errorText}
@@ -1079,4 +1104,4 @@ const WebView = memo(({ model, onFailLoad, blockRef, initialSrc }: WebViewProps) ); }); -export { WebView }; +export { getWebPreviewDisplayUrl, WebView, WebViewPreviewFallback }; diff --git a/frontend/app/waveenv/mockboundary.tsx b/frontend/app/waveenv/mockboundary.tsx new file mode 100644 index 000000000..4b05d28b7 --- /dev/null +++ b/frontend/app/waveenv/mockboundary.tsx @@ -0,0 +1,17 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { isPreviewWindow } from "@/app/store/windowtype"; +import React from "react"; + +type MockBoundaryProps = { + fallback: React.ReactNode; + children: React.ReactNode; +}; + +export function MockBoundary({ fallback, children }: MockBoundaryProps) { + if (isPreviewWindow()) { + return <>{fallback}; + } + return <>{children}; +} diff --git a/frontend/app/waveenv/waveenv.ts b/frontend/app/waveenv/waveenv.ts new file mode 100644 index 000000000..df1cb01c4 --- /dev/null +++ b/frontend/app/waveenv/waveenv.ts @@ -0,0 +1,93 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import type { AllServiceImpls } from "@/app/store/services"; +import { RpcApiType } from "@/app/store/wshclientapi"; +import { Atom, PrimitiveAtom } from "jotai"; +import React from "react"; + +export type BlockMetaKeyAtomFnType = ( + blockId: string, + key: T +) => Atom; + +export type ConnConfigKeyAtomFnType = ( + connName: string, + key: T +) => Atom; + +export type SettingsKeyAtomFnType = ( + key: T +) => Atom; + +type OmitNever = { + [K in keyof T as [T[K]] extends [never] ? never : K]: T[K]; +}; + +type Subset = OmitNever<{ + [K in keyof T]: K extends keyof U ? T[K] : never; +}>; + +type ComplexWaveEnvKeys = { + rpc: WaveEnv["rpc"]; + electron: WaveEnv["electron"]; + atoms: WaveEnv["atoms"]; + wos: WaveEnv["wos"]; + services: WaveEnv["services"]; +}; + +type WaveEnvMockFields = { + isMock: WaveEnv["isMock"]; + mockSetWaveObj: WaveEnv["mockSetWaveObj"]; + mockModels: WaveEnv["mockModels"]; +}; + +export type WaveEnvSubset = WaveEnvMockFields & + OmitNever<{ + [K in keyof T]: K extends keyof ComplexWaveEnvKeys + ? Subset + : K extends keyof WaveEnv + ? T[K] + : never; + }>; + +// default implementation for production is in ./waveenvimpl.ts +export type WaveEnv = { + isMock: boolean; + electron: ElectronApi; + rpc: RpcApiType; + platform: NodeJS.Platform; + isDev: () => boolean; + isWindows: () => boolean; + isMacOS: () => boolean; + atoms: GlobalAtomsType; + createBlock: (blockDef: BlockDef, magnified?: boolean, ephemeral?: boolean) => Promise; + services: typeof AllServiceImpls; + callBackendService: (service: string, method: string, args: any[], noUIContext?: boolean) => Promise; + showContextMenu: (menu: ContextMenuItem[], e: React.MouseEvent) => void; + getConnStatusAtom: (conn: string) => PrimitiveAtom; + getLocalHostDisplayNameAtom: () => Atom; + wos: { + getWaveObjectAtom: (oref: string) => Atom; + getWaveObjectLoadingAtom: (oref: string) => Atom; + isWaveObjectNullAtom: (oref: string) => Atom; + useWaveObjectValue: (oref: string) => [T, boolean]; + }; + getSettingsKeyAtom: SettingsKeyAtomFnType; + getBlockMetaKeyAtom: BlockMetaKeyAtomFnType; + getConnConfigKeyAtom: ConnConfigKeyAtomFnType; + + // the mock fields are only usable in the preview server (may be be null or throw errors in production) + mockSetWaveObj: (oref: string, obj: T) => void; + mockModels: Map; +}; + +export const WaveEnvContext = React.createContext(null); + +type EnvContract = { + [K in keyof T]?: T[K] extends (...args: any[]) => any ? T[K] : T[K] extends object ? EnvContract : T[K]; +}; + +export function useWaveEnv = WaveEnv>(): T { + return React.useContext(WaveEnvContext) as T; +} diff --git a/frontend/app/waveenv/waveenvimpl.ts b/frontend/app/waveenv/waveenvimpl.ts new file mode 100644 index 000000000..4f9e234ec --- /dev/null +++ b/frontend/app/waveenv/waveenvimpl.ts @@ -0,0 +1,54 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { ContextMenuModel } from "@/app/store/contextmenu"; +import { AllServiceImpls } from "@/app/store/services"; +import { + atoms, + createBlock, + getBlockMetaKeyAtom, + getConnConfigKeyAtom, + getConnStatusAtom, + getLocalHostDisplayNameAtom, + getSettingsKeyAtom, + isDev, + WOS, +} from "@/app/store/global"; +import { RpcApi } from "@/app/store/wshclientapi"; +import { WaveEnv } from "@/app/waveenv/waveenv"; +import { isMacOS, isWindows, PLATFORM } from "@/util/platformutil"; + +export function makeWaveEnvImpl(): WaveEnv { + return { + isMock: false, + electron: (window as any).api, + rpc: RpcApi, + getSettingsKeyAtom, + platform: PLATFORM, + isDev, + isWindows, + isMacOS, + atoms, + createBlock, + services: AllServiceImpls, + callBackendService: WOS.callBackendService, + showContextMenu: (menu: ContextMenuItem[], e: React.MouseEvent) => { + ContextMenuModel.getInstance().showContextMenu(menu, e); + }, + getConnStatusAtom, + getLocalHostDisplayNameAtom, + wos: { + getWaveObjectAtom: WOS.getWaveObjectAtom, + getWaveObjectLoadingAtom: WOS.getWaveObjectLoadingAtom, + isWaveObjectNullAtom: WOS.isWaveObjectNullAtom, + useWaveObjectValue: WOS.useWaveObjectValue, + }, + getBlockMetaKeyAtom, + getConnConfigKeyAtom, + + mockSetWaveObj: (_oref: string, _obj: T) => { + throw new Error("mockSetWaveObj is only available in the preview server"); + }, + mockModels: new Map(), + }; +} diff --git a/frontend/app/workspace/widgets.tsx b/frontend/app/workspace/widgets.tsx index 11067edcd..f3043e6d9 100644 --- a/frontend/app/workspace/widgets.tsx +++ b/frontend/app/workspace/widgets.tsx @@ -1,16 +1,15 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { Tooltip } from "@/app/element/tooltip"; -import { ContextMenuModel } from "@/app/store/contextmenu"; -import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; +import { useWaveEnv, WaveEnv, WaveEnvSubset } from "@/app/waveenv/waveenv"; import { shouldIncludeWidgetForWorkspace } from "@/app/workspace/widgetfilter"; -import { atoms, createBlock, isDev } from "@/store/global"; +import { modalsModel } from "@/store/modalmodel"; import { fireAndForget, isBlank, makeIconClass } from "@/util/util"; import { - FloatingPortal, autoUpdate, + FloatingPortal, offset, shift, useDismiss, @@ -21,6 +20,24 @@ import clsx from "clsx"; import { useAtomValue } from "jotai"; import { memo, useCallback, useEffect, useRef, useState } from "react"; +export type WidgetsEnv = WaveEnvSubset<{ + isDev: WaveEnv["isDev"]; + electron: { + openBuilder: WaveEnv["electron"]["openBuilder"]; + }; + rpc: { + ListAllAppsCommand: WaveEnv["rpc"]["ListAllAppsCommand"]; + }; + atoms: { + fullConfigAtom: WaveEnv["atoms"]["fullConfigAtom"]; + hasConfigErrors: WaveEnv["atoms"]["hasConfigErrors"]; + workspaceId: WaveEnv["atoms"]["workspaceId"]; + hasCustomAIPresetsAtom: WaveEnv["atoms"]["hasCustomAIPresetsAtom"]; + }; + createBlock: WaveEnv["createBlock"]; + showContextMenu: WaveEnv["showContextMenu"]; +}>; + function sortByDisplayOrder(wmap: { [key: string]: WidgetConfigType }): WidgetConfigType[] { if (wmap == null) { return []; @@ -32,12 +49,18 @@ function sortByDisplayOrder(wmap: { [key: string]: WidgetConfigType }): WidgetCo return wlist; } -async function handleWidgetSelect(widget: WidgetConfigType) { +type WidgetPropsType = { + widget: WidgetConfigType; + mode: "normal" | "compact" | "supercompact"; + env: WidgetsEnv; +}; + +async function handleWidgetSelect(widget: WidgetConfigType, env: WidgetsEnv) { const blockDef = widget.blockdef; - createBlock(blockDef, widget.magnified); + env.createBlock(blockDef, widget.magnified); } -const Widget = memo(({ widget, mode }: { widget: WidgetConfigType; mode: "normal" | "compact" | "supercompact" }) => { +const Widget = memo(({ widget, mode, env }: WidgetPropsType) => { const [isTruncated, setIsTruncated] = useState(false); const labelRef = useRef(null); @@ -60,7 +83,7 @@ const Widget = memo(({ widget, mode }: { widget: WidgetConfigType; mode: "normal mode === "supercompact" ? "text-sm" : "text-lg", widget["display:hidden"] && "hidden" )} - divOnClick={() => handleWidgetSelect(widget)} + divOnClick={() => handleWidgetSelect(widget, env)} >
@@ -85,71 +108,90 @@ function calculateGridSize(appCount: number): number { return 6; } -const AppsFloatingWindow = memo( - ({ - isOpen, - onClose, - referenceElement, - }: { - isOpen: boolean; - onClose: () => void; - referenceElement: HTMLElement; - }) => { - const [apps, setApps] = useState([]); - const [loading, setLoading] = useState(true); +function SettingsTooltipContent({ hasConfigErrors }: { hasConfigErrors: boolean }) { + if (!hasConfigErrors) { + return "Settings & Help"; + } + return ( +
+
Settings & Help
+
+ + Config Errors +
+
+ ); +} - const { refs, floatingStyles, context } = useFloating({ - open: isOpen, - onOpenChange: onClose, - placement: "left-start", - middleware: [offset(-2), shift({ padding: 12 })], - whileElementsMounted: autoUpdate, - elements: { - reference: referenceElement, - }, - }); +type FloatingWindowPropsType = { + isOpen: boolean; + onClose: () => void; + referenceElement: HTMLElement; + hasConfigErrors?: boolean; +}; + +const AppsFloatingWindow = memo(({ isOpen, onClose, referenceElement }: FloatingWindowPropsType) => { + const [apps, setApps] = useState([]); + const [loading, setLoading] = useState(true); + const env = useWaveEnv(); + + const { refs, floatingStyles, context } = useFloating({ + open: isOpen, + onOpenChange: onClose, + placement: "left-start", + middleware: [offset(-2), shift({ padding: 12 })], + whileElementsMounted: autoUpdate, + elements: { + reference: referenceElement, + }, + }); - const dismiss = useDismiss(context); - const { getFloatingProps } = useInteractions([dismiss]); + const dismiss = useDismiss(context); + const { getFloatingProps } = useInteractions([dismiss]); + const handleOpenBuilder = useCallback(() => { + env.electron.openBuilder(null); + onClose(); + }, [onClose, env]); - useEffect(() => { - if (!isOpen) return; - - const fetchApps = async () => { - setLoading(true); - try { - const allApps = await RpcApi.ListAllAppsCommand(TabRpcClient); - const localApps = allApps - .filter((app) => !app.appid.startsWith("draft/")) - .sort((a, b) => { - const aName = a.appid.replace(/^local\//, ""); - const bName = b.appid.replace(/^local\//, ""); - return aName.localeCompare(bName); - }); - setApps(localApps); - } catch (error) { - console.error("Failed to fetch apps:", error); - setApps([]); - } finally { - setLoading(false); - } - }; - - fetchApps(); - }, [isOpen]); + useEffect(() => { + if (!isOpen) return; + + const fetchApps = async () => { + setLoading(true); + try { + const allApps = await env.rpc.ListAllAppsCommand(TabRpcClient); + const localApps = allApps + .filter((app) => !app.appid.startsWith("draft/")) + .sort((a, b) => { + const aName = a.appid.replace(/^local\//, ""); + const bName = b.appid.replace(/^local\//, ""); + return aName.localeCompare(bName); + }); + setApps(localApps); + } catch (error) { + console.error("Failed to fetch apps:", error); + setApps([]); + } finally { + setLoading(false); + } + }; - if (!isOpen) return null; + fetchApps(); + }, [isOpen]); - const gridSize = calculateGridSize(apps.length); + if (!isOpen) return null; - return ( - -
+ const gridSize = calculateGridSize(apps.length); + + return ( + +
+
{loading ? (
@@ -182,7 +224,7 @@ const AppsFloatingWindow = memo( "tsunami:appid": app.appid, }, }; - createBlock(blockDef); + env.createBlock(blockDef); onClose(); }} > @@ -198,21 +240,22 @@ const AppsFloatingWindow = memo(
)}
- - ); - } -); + +
+
+ ); +}); const SettingsFloatingWindow = memo( - ({ - isOpen, - onClose, - referenceElement, - }: { - isOpen: boolean; - onClose: () => void; - referenceElement: HTMLElement; - }) => { + ({ isOpen, onClose, referenceElement, hasConfigErrors }: FloatingWindowPropsType) => { + const env = useWaveEnv(); const { refs, floatingStyles, context } = useFloating({ open: isOpen, onOpenChange: onClose, @@ -233,13 +276,14 @@ const SettingsFloatingWindow = memo( { icon: "gear", label: "Settings", + hasError: hasConfigErrors, onClick: () => { const blockDef: BlockDef = { meta: { view: "waveconfig", }, }; - createBlock(blockDef, false, true); + env.createBlock(blockDef, false, true); onClose(); }, }, @@ -252,7 +296,7 @@ const SettingsFloatingWindow = memo( view: "tips", }, }; - createBlock(blockDef, true, true); + env.createBlock(blockDef, true, true); onClose(); }, }, @@ -266,7 +310,15 @@ const SettingsFloatingWindow = memo( file: "secrets", }, }; - createBlock(blockDef, false, true); + env.createBlock(blockDef, false, true); + onClose(); + }, + }, + { + icon: "book-open", + label: "Release Notes", + onClick: () => { + modalsModel.pushModal("UpgradeOnboardingPatch", { isReleaseNotes: true }); onClose(); }, }, @@ -279,7 +331,7 @@ const SettingsFloatingWindow = memo( view: "help", }, }; - createBlock(blockDef); + env.createBlock(blockDef); onClose(); }, }, @@ -303,6 +355,9 @@ const SettingsFloatingWindow = memo(
{item.label}
+ {item.hasError && ( + + )}
))}
@@ -314,9 +369,11 @@ const SettingsFloatingWindow = memo( SettingsFloatingWindow.displayName = "SettingsFloatingWindow"; const Widgets = memo(() => { - const fullConfig = useAtomValue(atoms.fullConfigAtom); - const workspace = useAtomValue(atoms.workspace); - const hasCustomAIPresets = useAtomValue(atoms.hasCustomAIPresetsAtom); + const env = useWaveEnv(); + const fullConfig = useAtomValue(env.atoms.fullConfigAtom); + const hasConfigErrors = useAtomValue(env.atoms.hasConfigErrors); + const workspaceId = useAtomValue(env.atoms.workspaceId); + const hasCustomAIPresets = useAtomValue(env.atoms.hasCustomAIPresetsAtom); const [mode, setMode] = useState<"normal" | "compact" | "supercompact">("normal"); const containerRef = useRef(null); const measurementRef = useRef(null); @@ -328,7 +385,7 @@ const Widgets = memo(() => { if (!hasCustomAIPresets && key === "defwidget@ai") { return false; } - return shouldIncludeWidgetForWorkspace(widget, workspace?.oid); + return shouldIncludeWidgetForWorkspace(widget, workspaceId); }) ); const widgets = sortByDisplayOrder(filteredWidgets); @@ -396,31 +453,31 @@ const Widgets = memo(() => { file: "widgets.json", }, }; - await createBlock(blockDef, false, true); + await env.createBlock(blockDef, false, true); }); }, }, ]; - ContextMenuModel.getInstance().showContextMenu(menu, e); + env.showContextMenu(menu, e); }; return ( <>
{mode === "supercompact" ? ( <>
{widgets?.map((data, idx) => ( - + ))}
- {isDev() || featureWaveAppBuilder ? ( + {env.isDev() || featureWaveAppBuilder ? (
{ className="flex flex-col justify-center items-center w-full py-1.5 pr-0.5 text-secondary text-sm overflow-hidden rounded-sm hover:bg-hoverbg hover:text-white cursor-pointer" onClick={() => setIsSettingsOpen(!isSettingsOpen)} > - -
+ } + placement="left" + disable={isSettingsOpen} + > +
+ {hasConfigErrors && ( + + )}
@@ -449,10 +513,10 @@ const Widgets = memo(() => { ) : ( <> {widgets?.map((data, idx) => ( - + ))}
- {isDev() || featureWaveAppBuilder ? ( + {env.isDev() || featureWaveAppBuilder ? (
{ className="flex flex-col justify-center items-center w-full py-1.5 pr-0.5 text-secondary text-lg overflow-hidden rounded-sm hover:bg-hoverbg hover:text-white cursor-pointer" onClick={() => setIsSettingsOpen(!isSettingsOpen)} > - -
- + } + placement="left" + disable={isSettingsOpen} + > +
+
+ + {hasConfigErrors && ( + + )} +
+ {mode === "normal" && ( +
+ settings +
+ )}
)} - {isDev() ? ( + {env.isDev() ? (
{
) : null}
- {(isDev() || featureWaveAppBuilder) && appsButtonRef.current && ( + {(env.isDev() || featureWaveAppBuilder) && appsButtonRef.current && ( setIsAppsOpen(false)} @@ -506,6 +586,7 @@ const Widgets = memo(() => { isOpen={isSettingsOpen} onClose={() => setIsSettingsOpen(false)} referenceElement={settingsButtonRef.current} + hasConfigErrors={hasConfigErrors} /> )} @@ -514,7 +595,7 @@ const Widgets = memo(() => { className="flex flex-col w-12 py-1 -ml-1 select-none absolute -z-10 opacity-0 pointer-events-none" > {widgets?.map((data, idx) => ( - + ))}
@@ -523,7 +604,7 @@ const Widgets = memo(() => {
settings
- {isDev() ? ( + {env.isDev() ? (
@@ -531,7 +612,7 @@ const Widgets = memo(() => {
apps
) : null} - {isDev() ? ( + {env.isDev() ? (
maxWidth) return AIPanel_MinWidth; + return Math.max(AIPanel_MinWidth, Math.min(w, maxWidth)); +} class WorkspaceLayoutModel { private static instance: WorkspaceLayoutModel | null = null; aiPanelRef: ImperativePanelHandle | null; - panelGroupRef: ImperativePanelGroupHandle | null; + vtabPanelRef: ImperativePanelHandle | null; + outerPanelGroupRef: ImperativePanelGroupHandle | null; + innerPanelGroupRef: ImperativePanelGroupHandle | null; panelContainerRef: HTMLDivElement | null; aiPanelWrapperRef: HTMLDivElement | null; - inResize: boolean; // prevents recursive setLayout calls (setLayout triggers onLayout which calls setLayout) + panelVisibleAtom: jotai.PrimitiveAtom; + vtabVisibleAtom: jotai.PrimitiveAtom; + + private inResize: boolean; private aiPanelVisible: boolean; private aiPanelWidth: number | null; - private debouncedPersistWidth: (width: number) => void; + private vtabWidth: number; + private vtabVisible: boolean; private initialized: boolean = false; private transitionTimeoutRef: NodeJS.Timeout | null = null; private focusTimeoutRef: NodeJS.Timeout | null = null; - panelVisibleAtom: jotai.PrimitiveAtom; + private debouncedPersistAIWidth: (width: number) => void; + private debouncedPersistVTabWidth: (width: number) => void; private constructor() { this.aiPanelRef = null; - this.panelGroupRef = null; + this.vtabPanelRef = null; + this.outerPanelGroupRef = null; + this.innerPanelGroupRef = null; this.panelContainerRef = null; this.aiPanelWrapperRef = null; this.inResize = false; this.aiPanelVisible = false; this.aiPanelWidth = null; - this.panelVisibleAtom = jotai.atom(this.aiPanelVisible); + this.vtabWidth = VTabBar_DefaultWidth; + this.vtabVisible = false; + this.panelVisibleAtom = jotai.atom(false); + this.vtabVisibleAtom = jotai.atom(false); this.handleWindowResize = this.handleWindowResize.bind(this); - this.handlePanelLayout = this.handlePanelLayout.bind(this); + this.handleOuterPanelLayout = this.handleOuterPanelLayout.bind(this); + this.handleInnerPanelLayout = this.handleInnerPanelLayout.bind(this); - this.debouncedPersistWidth = debounce((width: number) => { + this.debouncedPersistAIWidth = debounce((width: number) => { try { RpcApi.SetMetaCommand(TabRpcClient, { oref: WOS.makeORef("tab", this.getTabId()), meta: { "waveai:panelwidth": width }, }); } catch (e) { - console.warn("Failed to persist panel width:", e); + console.warn("Failed to persist AI panel width:", e); + } + }, 300); + + this.debouncedPersistVTabWidth = debounce((width: number) => { + try { + RpcApi.SetMetaCommand(TabRpcClient, { + oref: WOS.makeORef("workspace", this.getWorkspaceId()), + meta: { "layout:vtabbarwidth": width }, + }); + } catch (e) { + console.warn("Failed to persist vtabbar width:", e); } }, 300); } @@ -68,79 +107,223 @@ class WorkspaceLayoutModel { return WorkspaceLayoutModel.instance; } - private initializeFromTabMeta(): void { + // ---- Meta / persistence helpers ---- + + private getTabId(): string { + return globalStore.get(atoms.staticTabId); + } + + private getWorkspaceId(): string { + return globalStore.get(atoms.workspace)?.oid ?? ""; + } + + private getPanelOpenAtom(): jotai.Atom { + return getOrefMetaKeyAtom(WOS.makeORef("tab", this.getTabId()), "waveai:panelopen"); + } + + private getPanelWidthAtom(): jotai.Atom { + return getOrefMetaKeyAtom(WOS.makeORef("tab", this.getTabId()), "waveai:panelwidth"); + } + + private getVTabBarWidthAtom(): jotai.Atom { + return getOrefMetaKeyAtom(WOS.makeORef("workspace", this.getWorkspaceId()), "layout:vtabbarwidth"); + } + + private initializeFromMeta(): void { if (this.initialized) return; this.initialized = true; - try { const savedVisible = globalStore.get(this.getPanelOpenAtom()); - const savedWidth = globalStore.get(this.getPanelWidthAtom()); - + const savedAIWidth = globalStore.get(this.getPanelWidthAtom()); + const savedVTabWidth = globalStore.get(this.getVTabBarWidthAtom()); if (savedVisible != null) { this.aiPanelVisible = savedVisible; globalStore.set(this.panelVisibleAtom, savedVisible); } - if (savedWidth != null) { - this.aiPanelWidth = savedWidth; + if (savedAIWidth != null) { + this.aiPanelWidth = savedAIWidth; + } + if (savedVTabWidth != null && savedVTabWidth > 0) { + this.vtabWidth = savedVTabWidth; } } catch (e) { console.warn("Failed to initialize from tab meta:", e); } } - private getTabId(): string { - return globalStore.get(atoms.staticTabId); + // ---- Resolved width getters (always clamped) ---- + + private getResolvedAIWidth(windowWidth: number): number { + this.initializeFromMeta(); + let w = this.aiPanelWidth; + if (w == null) { + w = Math.max(AIPanel_DefaultWidth, windowWidth * AIPanel_DefaultWidthRatio); + this.aiPanelWidth = w; + } + return clampAIPanelWidth(w, windowWidth); } - private getPanelOpenAtom(): jotai.Atom { - const tabORef = WOS.makeORef("tab", this.getTabId()); - return getOrefMetaKeyAtom(tabORef, "waveai:panelopen"); + private getResolvedVTabWidth(): number { + this.initializeFromMeta(); + return clampVTabWidth(this.vtabWidth); } - private getPanelWidthAtom(): jotai.Atom { - const tabORef = WOS.makeORef("tab", this.getTabId()); - return getOrefMetaKeyAtom(tabORef, "waveai:panelwidth"); + // ---- Core layout computation ---- + // All layout decisions flow through computeLayout. + // It takes the current state (visibility flags + stored px widths) + // and produces the two percentage arrays for the panel groups. + + private computeLayout(windowWidth: number): { outer: number[]; inner: number[] } { + const vtabW = this.vtabVisible ? this.getResolvedVTabWidth() : 0; + const aiW = this.aiPanelVisible ? this.getResolvedAIWidth(windowWidth) : 0; + const leftGroupW = vtabW + aiW; + + // outer: [leftGroupPct, contentPct] + const leftPct = windowWidth > 0 ? (leftGroupW / windowWidth) * 100 : 0; + const contentPct = Math.max(0, 100 - leftPct); + + // inner: [vtabPct, aiPanelPct] relative to leftGroupW + let vtabPct: number; + let aiPct: number; + if (leftGroupW > 0) { + vtabPct = (vtabW / leftGroupW) * 100; + aiPct = 100 - vtabPct; + } else { + vtabPct = 50; + aiPct = 50; + } + + return { outer: [leftPct, contentPct], inner: [vtabPct, aiPct] }; + } + + private commitLayouts(windowWidth: number): void { + if (!this.outerPanelGroupRef || !this.innerPanelGroupRef) return; + const { outer, inner } = this.computeLayout(windowWidth); + this.inResize = true; + this.outerPanelGroupRef.setLayout(outer); + this.innerPanelGroupRef.setLayout(inner); + this.inResize = false; + this.updateWrapperWidth(); + } + + // ---- Drag handlers ---- + // These convert the percentage-based callback from react-resizable-panels + // back into pixel widths, update stored state, then re-commit. + + handleOuterPanelLayout(sizes: number[]): void { + if (this.inResize) return; + const windowWidth = window.innerWidth; + const newLeftGroupPx = (sizes[0] / 100) * windowWidth; + + if (this.vtabVisible && this.aiPanelVisible) { + // vtab stays constant, aipanel absorbs the change + const vtabW = this.getResolvedVTabWidth(); + const newAIW = clampAIPanelWidth(newLeftGroupPx - vtabW, windowWidth); + this.aiPanelWidth = newAIW; + this.debouncedPersistAIWidth(newAIW); + } else if (this.vtabVisible) { + const clamped = clampVTabWidth(newLeftGroupPx); + this.vtabWidth = clamped; + this.debouncedPersistVTabWidth(clamped); + } else if (this.aiPanelVisible) { + const clamped = clampAIPanelWidth(newLeftGroupPx, windowWidth); + this.aiPanelWidth = clamped; + this.debouncedPersistAIWidth(clamped); + } + + this.commitLayouts(windowWidth); + } + + handleInnerPanelLayout(sizes: number[]): void { + if (this.inResize) return; + if (!this.vtabVisible || !this.aiPanelVisible) return; + + const windowWidth = window.innerWidth; + const vtabW = this.getResolvedVTabWidth(); + const aiW = this.getResolvedAIWidth(windowWidth); + const leftGroupW = vtabW + aiW; + + const newVTabW = (sizes[0] / 100) * leftGroupW; + const clampedVTab = clampVTabWidth(newVTabW); + const newAIW = clampAIPanelWidth(leftGroupW - clampedVTab, windowWidth); + + if (clampedVTab !== this.vtabWidth) { + this.vtabWidth = clampedVTab; + this.debouncedPersistVTabWidth(clampedVTab); + } + if (newAIW !== this.aiPanelWidth) { + this.aiPanelWidth = newAIW; + this.debouncedPersistAIWidth(newAIW); + } + + this.commitLayouts(windowWidth); + } + + handleWindowResize(): void { + this.commitLayouts(window.innerWidth); + } + + // ---- Registration & sync ---- + + syncVTabWidthFromMeta(): void { + const savedVTabWidth = globalStore.get(this.getVTabBarWidthAtom()); + if (savedVTabWidth != null && savedVTabWidth > 0 && savedVTabWidth !== this.vtabWidth) { + this.vtabWidth = savedVTabWidth; + this.commitLayouts(window.innerWidth); + } } registerRefs( aiPanelRef: ImperativePanelHandle, - panelGroupRef: ImperativePanelGroupHandle, + outerPanelGroupRef: ImperativePanelGroupHandle, + innerPanelGroupRef: ImperativePanelGroupHandle, panelContainerRef: HTMLDivElement, - aiPanelWrapperRef: HTMLDivElement + aiPanelWrapperRef: HTMLDivElement, + vtabPanelRef?: ImperativePanelHandle, + showLeftTabBar?: boolean ): void { this.aiPanelRef = aiPanelRef; - this.panelGroupRef = panelGroupRef; + this.vtabPanelRef = vtabPanelRef ?? null; + this.outerPanelGroupRef = outerPanelGroupRef; + this.innerPanelGroupRef = innerPanelGroupRef; this.panelContainerRef = panelContainerRef; this.aiPanelWrapperRef = aiPanelWrapperRef; - this.syncAIPanelRef(); - this.updateWrapperWidth(); + this.vtabVisible = showLeftTabBar ?? false; + globalStore.set(this.vtabVisibleAtom, this.vtabVisible); + this.syncPanelCollapse(); + this.commitLayouts(window.innerWidth); } - updateWrapperWidth(): void { - if (!this.aiPanelWrapperRef) { - return; + private syncPanelCollapse(): void { + if (this.aiPanelRef) { + if (this.aiPanelVisible) { + this.aiPanelRef.expand(); + } else { + this.aiPanelRef.collapse(); + } + } + if (this.vtabPanelRef) { + if (this.vtabVisible) { + this.vtabPanelRef.expand(); + } else { + this.vtabPanelRef.collapse(); + } } - const width = this.getAIPanelWidth(); - const clampedWidth = this.getClampedAIPanelWidth(width, window.innerWidth); - this.aiPanelWrapperRef.style.width = `${clampedWidth}px`; } + // ---- Transitions ---- + enableTransitions(duration: number): void { - if (!this.panelContainerRef) { - return; - } + if (!this.panelContainerRef) return; const panels = this.panelContainerRef.querySelectorAll("[data-panel]"); panels.forEach((panel: HTMLElement) => { panel.style.transition = "flex 0.2s ease-in-out"; }); - if (this.transitionTimeoutRef) { clearTimeout(this.transitionTimeoutRef); } this.transitionTimeoutRef = setTimeout(() => { - if (!this.panelContainerRef) { - return; - } + if (!this.panelContainerRef) return; const panels = this.panelContainerRef.querySelectorAll("[data-panel]"); panels.forEach((panel: HTMLElement) => { panel.style.transition = "none"; @@ -148,77 +331,54 @@ class WorkspaceLayoutModel { }, duration); } - handleWindowResize(): void { - if (!this.panelGroupRef) { - return; - } - const newWindowWidth = window.innerWidth; - const aiPanelPercentage = this.getAIPanelPercentage(newWindowWidth); - const mainContentPercentage = this.getMainContentPercentage(newWindowWidth); - this.inResize = true; - const layout = [aiPanelPercentage, mainContentPercentage]; - this.panelGroupRef.setLayout(layout); - this.inResize = false; - this.updateWrapperWidth(); + // ---- Wrapper width (AI panel inner content width) ---- + + updateWrapperWidth(): void { + if (!this.aiPanelWrapperRef) return; + const width = this.getResolvedAIWidth(window.innerWidth); + this.aiPanelWrapperRef.style.width = `${width}px`; } - handlePanelLayout(sizes: number[]): void { - // dlog("handlePanelLayout", "inResize:", this.inResize, "sizes:", sizes); - if (this.inResize) { - return; - } - if (!this.panelGroupRef) { - return; - } + // ---- Public getters ---- - const currentWindowWidth = window.innerWidth; - const aiPanelPixelWidth = (sizes[0] / 100) * currentWindowWidth; - this.handleAIPanelResize(aiPanelPixelWidth, currentWindowWidth); - const newPercentage = this.getAIPanelPercentage(currentWindowWidth); - const mainContentPercentage = 100 - newPercentage; - this.inResize = true; - const layout = [newPercentage, mainContentPercentage]; - this.panelGroupRef.setLayout(layout); - this.inResize = false; + getAIPanelVisible(): boolean { + this.initializeFromMeta(); + return this.aiPanelVisible; } - syncAIPanelRef(): void { - if (!this.aiPanelRef || !this.panelGroupRef) { - return; - } - - const currentWindowWidth = window.innerWidth; - const aiPanelPercentage = this.getAIPanelPercentage(currentWindowWidth); - const mainContentPercentage = this.getMainContentPercentage(currentWindowWidth); + getAIPanelWidth(): number { + return this.getResolvedAIWidth(window.innerWidth); + } - if (this.getAIPanelVisible()) { - this.aiPanelRef.expand(); - } else { - this.aiPanelRef.collapse(); - } + // ---- Initial percentage helpers (used by workspace.tsx for defaultSize) ---- - this.inResize = true; - const layout = [aiPanelPercentage, mainContentPercentage]; - this.panelGroupRef.setLayout(layout); - this.inResize = false; + getLeftGroupInitialPercentage(windowWidth: number, showLeftTabBar: boolean): number { + this.initializeFromMeta(); + const vtabW = showLeftTabBar && !isBuilderWindow() ? this.getResolvedVTabWidth() : 0; + const aiW = this.aiPanelVisible ? this.getResolvedAIWidth(windowWidth) : 0; + return ((vtabW + aiW) / windowWidth) * 100; } - getMaxAIPanelWidth(windowWidth: number): number { - return Math.floor(windowWidth * AIPANEL_MAXWIDTHRATIO); + getInnerVTabInitialPercentage(windowWidth: number, showLeftTabBar: boolean): number { + if (!showLeftTabBar || isBuilderWindow()) return 0; + this.initializeFromMeta(); + const vtabW = this.getResolvedVTabWidth(); + const aiW = this.aiPanelVisible ? this.getResolvedAIWidth(windowWidth) : 0; + const total = vtabW + aiW; + if (total === 0) return 50; + return (vtabW / total) * 100; } - getClampedAIPanelWidth(width: number, windowWidth: number): number { - const maxWidth = this.getMaxAIPanelWidth(windowWidth); - if (AIPANEL_MINWIDTH > maxWidth) { - return AIPANEL_MINWIDTH; - } - return Math.max(AIPANEL_MINWIDTH, Math.min(width, maxWidth)); + getInnerAIPanelInitialPercentage(windowWidth: number, showLeftTabBar: boolean): number { + this.initializeFromMeta(); + const vtabW = showLeftTabBar && !isBuilderWindow() ? this.getResolvedVTabWidth() : 0; + const aiW = this.aiPanelVisible ? this.getResolvedAIWidth(windowWidth) : 0; + const total = vtabW + aiW; + if (total === 0) return 50; + return (aiW / total) * 100; } - getAIPanelVisible(): boolean { - this.initializeFromTabMeta(); - return this.aiPanelVisible; - } + // ---- Toggle visibility ---- setAIPanelVisible(visible: boolean, opts?: { nofocus?: boolean }): void { if (this.focusTimeoutRef != null) { @@ -237,7 +397,8 @@ class WorkspaceLayoutModel { meta: { "waveai:panelopen": visible }, }); this.enableTransitions(250); - this.syncAIPanelRef(); + this.syncPanelCollapse(); + this.commitLayouts(window.innerWidth); if (visible) { if (!opts?.nofocus) { @@ -260,42 +421,13 @@ class WorkspaceLayoutModel { } } - getAIPanelWidth(): number { - this.initializeFromTabMeta(); - if (this.aiPanelWidth == null) { - this.aiPanelWidth = Math.max(AIPANEL_DEFAULTWIDTH, window.innerWidth * AIPANEL_DEFAULTWIDTHRATIO); - } - return this.aiPanelWidth; - } - - setAIPanelWidth(width: number): void { - this.aiPanelWidth = width; - this.updateWrapperWidth(); - this.debouncedPersistWidth(width); - } - - getAIPanelPercentage(windowWidth: number): number { - const isVisible = this.getAIPanelVisible(); - if (!isVisible) { - return 0; - } - const aiPanelWidth = this.getAIPanelWidth(); - const clampedWidth = this.getClampedAIPanelWidth(aiPanelWidth, windowWidth); - const percentage = (clampedWidth / windowWidth) * 100; - return Math.max(0, Math.min(percentage, 100)); - } - - getMainContentPercentage(windowWidth: number): number { - const aiPanelPercentage = this.getAIPanelPercentage(windowWidth); - return Math.max(0, 100 - aiPanelPercentage); - } - - handleAIPanelResize(width: number, windowWidth: number): void { - if (!this.getAIPanelVisible()) { - return; - } - const clampedWidth = this.getClampedAIPanelWidth(width, windowWidth); - this.setAIPanelWidth(clampedWidth); + setShowLeftTabBar(showLeftTabBar: boolean): void { + if (this.vtabVisible === showLeftTabBar) return; + this.vtabVisible = showLeftTabBar; + globalStore.set(this.vtabVisibleAtom, showLeftTabBar); + this.enableTransitions(250); + this.syncPanelCollapse(); + this.commitLayouts(window.innerWidth); } } diff --git a/frontend/app/workspace/workspace.tsx b/frontend/app/workspace/workspace.tsx index fb1d78668..988186a37 100644 --- a/frontend/app/workspace/workspace.tsx +++ b/frontend/app/workspace/workspace.tsx @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { AIPanel } from "@/app/aipanel/aipanel"; @@ -7,9 +7,11 @@ import { CenteredDiv } from "@/app/element/quickelems"; import { ModalsRenderer } from "@/app/modals/modalsrenderer"; import { TabBar } from "@/app/tab/tabbar"; import { TabContent } from "@/app/tab/tabcontent"; +import { VTabBar } from "@/app/tab/vtabbar"; import { Widgets } from "@/app/workspace/widgets"; import { WorkspaceLayoutModel } from "@/app/workspace/workspace-layout-model"; -import { atoms, getApi } from "@/store/global"; +import { atoms, getApi, getSettingsKeyAtom } from "@/store/global"; +import { isMacOS } from "@/util/platformutil"; import { useAtomValue } from "jotai"; import { memo, useEffect, useRef } from "react"; import { @@ -20,23 +22,60 @@ import { PanelResizeHandle, } from "react-resizable-panels"; +const MacOSTabBarSpacer = memo(() => { + return ( +
+ ); +}); +MacOSTabBarSpacer.displayName = "MacOSTabBarSpacer"; + const WorkspaceElem = memo(() => { const workspaceLayoutModel = WorkspaceLayoutModel.getInstance(); const tabId = useAtomValue(atoms.staticTabId); const ws = useAtomValue(atoms.workspace); - const initialAiPanelPercentage = workspaceLayoutModel.getAIPanelPercentage(window.innerWidth); - const panelGroupRef = useRef(null); + const tabBarPosition = useAtomValue(getSettingsKeyAtom("app:tabbar")) ?? "top"; + const showLeftTabBar = tabBarPosition === "left"; + const aiPanelVisible = useAtomValue(workspaceLayoutModel.panelVisibleAtom); + const vtabVisible = useAtomValue(workspaceLayoutModel.vtabVisibleAtom); + const windowWidth = window.innerWidth; + const leftGroupInitialPct = workspaceLayoutModel.getLeftGroupInitialPercentage(windowWidth, showLeftTabBar); + const innerVTabInitialPct = workspaceLayoutModel.getInnerVTabInitialPercentage(windowWidth, showLeftTabBar); + const innerAIPanelInitialPct = workspaceLayoutModel.getInnerAIPanelInitialPercentage(windowWidth, showLeftTabBar); + const outerPanelGroupRef = useRef(null); + const innerPanelGroupRef = useRef(null); const aiPanelRef = useRef(null); + const vtabPanelRef = useRef(null); const panelContainerRef = useRef(null); const aiPanelWrapperRef = useRef(null); + // showLeftTabBar is passed as a seed value only; subsequent changes are handled by setShowLeftTabBar below. + // Do NOT add showLeftTabBar as a dep here — re-registering refs on config changes would redundantly re-run commitLayouts. useEffect(() => { - if (aiPanelRef.current && panelGroupRef.current && panelContainerRef.current && aiPanelWrapperRef.current) { + if ( + aiPanelRef.current && + outerPanelGroupRef.current && + innerPanelGroupRef.current && + panelContainerRef.current && + aiPanelWrapperRef.current + ) { workspaceLayoutModel.registerRefs( aiPanelRef.current, - panelGroupRef.current, + outerPanelGroupRef.current, + innerPanelGroupRef.current, panelContainerRef.current, - aiPanelWrapperRef.current + aiPanelWrapperRef.current, + vtabPanelRef.current ?? undefined, + showLeftTabBar ); } }, []); @@ -46,39 +85,76 @@ const WorkspaceElem = memo(() => { getApi().setWaveAIOpen(isVisible); }, []); + useEffect(() => { + workspaceLayoutModel.setShowLeftTabBar(showLeftTabBar); + }, [showLeftTabBar]); + useEffect(() => { window.addEventListener("resize", workspaceLayoutModel.handleWindowResize); return () => window.removeEventListener("resize", workspaceLayoutModel.handleWindowResize); }, []); + useEffect(() => { + const handleFocus = () => workspaceLayoutModel.syncVTabWidthFromMeta(); + window.addEventListener("focus", handleFocus); + return () => window.removeEventListener("focus", handleFocus); + }, []); + + const innerHandleVisible = vtabVisible && aiPanelVisible; + const innerHandleClass = `bg-transparent hover:bg-zinc-500/20 transition-colors ${innerHandleVisible ? "w-0.5" : "w-0 pointer-events-none"}`; + const outerHandleVisible = vtabVisible || aiPanelVisible; + const outerHandleClass = `bg-transparent hover:bg-zinc-500/20 transition-colors ${outerHandleVisible ? "w-0.5" : "w-0 pointer-events-none"}`; + return (
- + {!(showLeftTabBar && isMacOS()) && } + {showLeftTabBar && isMacOS() && }
- -
- {tabId !== "" && } -
+ + + + {showLeftTabBar && } + + + +
+ {tabId !== "" && } +
+
+
- - + + {tabId === "" ? ( No Active Tab ) : (
- +
)} diff --git a/frontend/builder/builder-workspace.tsx b/frontend/builder/builder-workspace.tsx index 94a06fad8..aab14ff45 100644 --- a/frontend/builder/builder-workspace.tsx +++ b/frontend/builder/builder-workspace.tsx @@ -97,7 +97,7 @@ const BuilderWorkspace = memo(() => {
- + diff --git a/frontend/layout/lib/layoutAtom.ts b/frontend/layout/lib/layoutAtom.ts index 62890446d..e34cd3e20 100644 --- a/frontend/layout/lib/layoutAtom.ts +++ b/frontend/layout/lib/layoutAtom.ts @@ -4,7 +4,7 @@ import { WOS } from "@/app/store/global"; import { Atom, Getter } from "jotai"; -export function getLayoutStateAtomFromTab(tabAtom: Atom, get: Getter): WritableWaveObjectAtom { +export function getLayoutStateAtomFromTab(tabAtom: Atom, get: Getter): Atom { const tabData = get(tabAtom); if (!tabData) return; const layoutStateOref = WOS.makeORef("layout", tabData.layoutstate); diff --git a/frontend/layout/lib/layoutModel.ts b/frontend/layout/lib/layoutModel.ts index 14b0476c9..0741df9bc 100644 --- a/frontend/layout/lib/layoutModel.ts +++ b/frontend/layout/lib/layoutModel.ts @@ -4,6 +4,7 @@ import { FocusManager } from "@/app/store/focusManager"; import { getSettingsKeyAtom } from "@/app/store/global"; import { BlockService } from "@/app/store/services"; +import * as WOS from "@/app/store/wos"; import { atomWithThrottle, boundNumber, fireAndForget } from "@/util/util"; import { Atom, atom, Getter, PrimitiveAtom, Setter } from "jotai"; import { splitAtom } from "jotai/utils"; @@ -88,7 +89,7 @@ export class LayoutModel { /** * WaveObject atom for persistence */ - private waveObjectAtom: WritableWaveObjectAtom; + private waveObjectAtom: Atom; /** * Debounce timer for persistence */ @@ -587,7 +588,7 @@ export class LayoutModel { waveObj.leaforder = this.treeState.leafOrder; waveObj.pendingbackendactions = this.treeState.pendingBackendActions; - this.setter(this.waveObjectAtom, waveObj); + WOS.setObjectValue(waveObj, this.setter, true); this.persistDebounceTimer = null; }, 100); } diff --git a/frontend/layout/lib/utils.ts b/frontend/layout/lib/utils.ts index 96cb71ddb..e34819b16 100644 --- a/frontend/layout/lib/utils.ts +++ b/frontend/layout/lib/utils.ts @@ -74,10 +74,6 @@ export function setTransform( top: 0, left: 0, transform: translate, - WebkitTransform: translate, - MozTransform: translate, - msTransform: translate, - OTransform: translate, width: setSize ? `${widthRounded}px` : undefined, height: setSize ? `${heightRounded}px` : undefined, position: "absolute", diff --git a/frontend/layout/tests/layoutTree.test.ts b/frontend/layout/tests/layoutTree.test.ts index ec8b6465c..43350c02b 100644 --- a/frontend/layout/tests/layoutTree.test.ts +++ b/frontend/layout/tests/layoutTree.test.ts @@ -13,9 +13,11 @@ import { import { newLayoutTreeState } from "./model"; test("layoutTreeStateReducer - compute move", () => { - let treeState = newLayoutTreeState(newLayoutNode(undefined, undefined, undefined, { blockId: "root" })); - assert(treeState.rootNode.data!.blockId === "root", "root should have no children and should have data"); - let node1 = newLayoutNode(undefined, undefined, undefined, { blockId: "node1" }); + const nodeA = newLayoutNode(undefined, undefined, undefined, { blockId: "nodeA" }); + const node1 = newLayoutNode(undefined, undefined, undefined, { blockId: "node1" }); + const node2 = newLayoutNode(undefined, undefined, undefined, { blockId: "node2" }); + const treeState = newLayoutTreeState(newLayoutNode(undefined, undefined, [nodeA, node1, node2])); + assert(treeState.rootNode.children!.length === 3, "root should have three children"); let pendingAction = computeMoveNode(treeState, { type: LayoutTreeActionType.ComputeMove, nodeId: treeState.rootNode.id, @@ -29,12 +31,11 @@ test("layoutTreeStateReducer - compute move", () => { assert(insertOperation.insertAtRoot, "insert operation insertAtRoot should be true"); moveNode(treeState, insertOperation); assert( - treeState.rootNode.data === undefined && treeState.rootNode.children!.length === 2, - "root node should now have no data and should have two children" + treeState.rootNode.data === undefined && treeState.rootNode.children!.length === 3, + "root node should still have three children" ); assert(treeState.rootNode.children![1].data!.blockId === "node1", "root's second child should be node1"); - let node2 = newLayoutNode(undefined, undefined, undefined, { blockId: "node2" }); pendingAction = computeMoveNode(treeState, { type: LayoutTreeActionType.ComputeMove, nodeId: node1.id, @@ -48,15 +49,15 @@ test("layoutTreeStateReducer - compute move", () => { assert(!insertOperation2.insertAtRoot, "insert operation insertAtRoot should be false"); moveNode(treeState, insertOperation2); assert( - treeState.rootNode.data === undefined && treeState.rootNode.children!.length === 2, - "root node should still have three children" + treeState.rootNode.data === undefined && (treeState.rootNode.children!.length as number) === 2, + "root node should now have two children after node2 moved into node1" ); assert(treeState.rootNode.children![1].children!.length === 2, "root's second child should now have two children"); }); test("computeMove - noop action", () => { - let nodeToMove = newLayoutNode(undefined, undefined, undefined, { blockId: "nodeToMove" }); - let treeState = newLayoutTreeState( + const nodeToMove = newLayoutNode(undefined, undefined, undefined, { blockId: "nodeToMove" }); + const treeState = newLayoutTreeState( newLayoutNode(undefined, undefined, [ nodeToMove, newLayoutNode(undefined, undefined, undefined, { blockId: "otherNode" }), diff --git a/frontend/preview/index.html b/frontend/preview/index.html index cf9e957e3..4c5e76af8 100644 --- a/frontend/preview/index.html +++ b/frontend/preview/index.html @@ -5,6 +5,7 @@ Wave Preview Server + diff --git a/frontend/preview/mock/defaultconfig.ts b/frontend/preview/mock/defaultconfig.ts new file mode 100644 index 000000000..0c2ac11b3 --- /dev/null +++ b/frontend/preview/mock/defaultconfig.ts @@ -0,0 +1,22 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import mimetypesJson from "../../../pkg/wconfig/defaultconfig/mimetypes.json"; +import presetsJson from "../../../pkg/wconfig/defaultconfig/presets.json"; +import settingsJson from "../../../pkg/wconfig/defaultconfig/settings.json"; +import termthemesJson from "../../../pkg/wconfig/defaultconfig/termthemes.json"; +import waveaiJson from "../../../pkg/wconfig/defaultconfig/waveai.json"; +import widgetsJson from "../../../pkg/wconfig/defaultconfig/widgets.json"; + +export const DefaultFullConfig: FullConfigType = { + settings: settingsJson as SettingsType, + mimetypes: mimetypesJson as unknown as { [key: string]: MimeTypeConfigType }, + defaultwidgets: widgetsJson as unknown as { [key: string]: WidgetConfigType }, + widgets: {}, + presets: presetsJson as unknown as { [key: string]: MetaType }, + termthemes: termthemesJson as unknown as { [key: string]: TermThemeType }, + connections: {}, + bookmarks: {}, + waveai: waveaiJson as unknown as { [key: string]: AIModeConfigType }, + configerrors: [], +}; diff --git a/frontend/preview/mock/mockfilesystem.ts b/frontend/preview/mock/mockfilesystem.ts new file mode 100644 index 000000000..6652bbb3f --- /dev/null +++ b/frontend/preview/mock/mockfilesystem.ts @@ -0,0 +1,543 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { arrayToBase64 } from "@/util/util"; + +const MockHomePath = "/Users/mike"; +const MockDirMimeType = "directory"; +const MockDirMode = 0o040755; +const MockFileMode = 0o100644; +const MockDirectoryChunkSize = 128; +const MockFileChunkSize = 64 * 1024; +const MockBaseModTime = Date.parse("2026-03-10T09:00:00.000Z"); +const TinyPngBytes = Uint8Array.from([ + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x04, 0x00, 0x00, 0x00, 0xb5, 0x1c, 0x0c, + 0x02, 0x00, 0x00, 0x00, 0x0b, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0x63, 0xfc, 0xff, 0x1f, 0x00, + 0x03, 0x03, 0x01, 0xff, 0xa5, 0xf8, 0x8f, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, + 0xae, 0x42, 0x60, 0x82, +]); +const TinyJpegBytes = Uint8Array.from([ + 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, + 0x00, 0x01, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x03, 0x02, 0x02, 0x03, + 0x03, 0x03, 0x03, 0x04, 0x03, 0x03, 0x04, 0x05, 0x08, 0x05, 0x05, 0x04, 0x04, 0x05, 0x0a, 0x07, + 0x07, 0x06, 0x08, 0x0c, 0x0a, 0x0c, 0x0c, 0x0b, 0x0a, 0x0b, 0x0b, 0x0d, 0x0e, 0x12, 0x10, 0x0d, + 0x0e, 0x11, 0x0e, 0x0b, 0x0b, 0x10, 0x16, 0x10, 0x11, 0x13, 0x14, 0x15, 0x15, 0x15, 0x0c, 0x0f, + 0x17, 0x18, 0x16, 0x14, 0x18, 0x12, 0x14, 0x15, 0x14, 0xff, 0xc0, 0x00, 0x0b, 0x08, 0x00, 0x01, + 0x00, 0x01, 0x01, 0x01, 0x11, 0x00, 0xff, 0xc4, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xff, 0xc4, 0x00, 0x14, + 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xbf, 0xff, 0xd9, +]); + +type MockFsEntry = { + path: string; + dir: string; + name: string; + isdir: boolean; + mimetype: string; + modtime: number; + mode: number; + size: number; + readonly?: boolean; + supportsmkdir?: boolean; + content?: Uint8Array; +}; + +type MockFsEntryInput = { + path: string; + isdir?: boolean; + mimetype?: string; + readonly?: boolean; + content?: string | Uint8Array; +}; + +export type MockFilesystem = { + homePath: string; + fileCount: number; + directoryCount: number; + entryCount: number; + fileInfo: (data: FileData) => Promise; + fileRead: (data: FileData) => Promise; + fileList: (data: FileListData) => Promise; + fileJoin: (paths: string[]) => Promise; + fileReadStream: (data: FileData) => AsyncGenerator; + fileListStream: (data: FileListData) => AsyncGenerator; +}; + +function normalizeMockPath(path: string, basePath = MockHomePath): string { + if (path == null || path === "") { + return basePath; + } + if (path.startsWith("wsh://")) { + const url = new URL(path); + path = url.pathname.replace(/^\/+/, "/"); + } + if (path === "~") { + path = MockHomePath; + } else if (path.startsWith("~/")) { + path = MockHomePath + path.slice(1); + } + if (!path.startsWith("/")) { + path = `${basePath}/${path}`; + } + const parts = path.split("/"); + const resolvedParts: string[] = []; + for (const part of parts) { + if (!part || part === ".") { + continue; + } + if (part === "..") { + resolvedParts.pop(); + continue; + } + resolvedParts.push(part); + } + const resolvedPath = "/" + resolvedParts.join("/"); + return resolvedPath === "" ? "/" : resolvedPath; +} + +function getDirName(path: string): string { + if (path === "/") { + return "/"; + } + const idx = path.lastIndexOf("/"); + if (idx <= 0) { + return "/"; + } + return path.slice(0, idx); +} + +function getBaseName(path: string): string { + if (path === "/") { + return "/"; + } + const idx = path.lastIndexOf("/"); + return idx < 0 ? path : path.slice(idx + 1); +} + +function getMimeType(path: string, isdir: boolean): string { + if (isdir) { + return MockDirMimeType; + } + if (path.endsWith(".md")) { + return "text/markdown"; + } + if (path.endsWith(".json")) { + return "application/json"; + } + if (path.endsWith(".ts")) { + return "text/typescript"; + } + if (path.endsWith(".tsx")) { + return "text/tsx"; + } + if (path.endsWith(".js")) { + return "text/javascript"; + } + if (path.endsWith(".txt") || path.endsWith(".log") || path.endsWith(".bashrc") || path.endsWith(".zprofile")) { + return "text/plain"; + } + if (path.endsWith(".png")) { + return "image/png"; + } + if (path.endsWith(".jpg") || path.endsWith(".jpeg")) { + return "image/jpeg"; + } + if (path.endsWith(".pdf")) { + return "application/pdf"; + } + if (path.endsWith(".zip")) { + return "application/zip"; + } + if (path.endsWith(".dmg")) { + return "application/x-apple-diskimage"; + } + if (path.endsWith(".svg")) { + return "image/svg+xml"; + } + if (path.endsWith(".yaml") || path.endsWith(".yml")) { + return "application/yaml"; + } + return "application/octet-stream"; +} + +function makeContentBytes(content: string | Uint8Array): Uint8Array { + if (content instanceof Uint8Array) { + return content; + } + return new TextEncoder().encode(content); +} + +function makeMockFsInput(path: string, content?: string | Uint8Array, mimetype?: string): MockFsEntryInput { + return { path, content, mimetype }; +} + +function createMockFilesystemEntries(): MockFsEntryInput[] { + const entries: MockFsEntryInput[] = [ + { path: "/", isdir: true }, + { path: "/Users", isdir: true }, + { path: MockHomePath, isdir: true }, + { path: `${MockHomePath}/Desktop`, isdir: true }, + { path: `${MockHomePath}/Documents`, isdir: true }, + { path: `${MockHomePath}/Downloads`, isdir: true }, + { path: `${MockHomePath}/Pictures`, isdir: true }, + { path: `${MockHomePath}/Projects`, isdir: true }, + { path: `${MockHomePath}/waveterm`, isdir: true }, + { path: `${MockHomePath}/waveterm/docs`, isdir: true }, + { path: `${MockHomePath}/waveterm/images`, isdir: true }, + { path: `${MockHomePath}/.config`, isdir: true }, + makeMockFsInput( + `${MockHomePath}/.bashrc`, + `export PATH="$HOME/bin:$PATH"\nalias gs="git status -sb"\nexport WAVETERM_THEME="midnight"\n`, + "text/plain" + ), + makeMockFsInput(`${MockHomePath}/.gitconfig`), + makeMockFsInput(`${MockHomePath}/.zprofile`), + makeMockFsInput(`${MockHomePath}/todo.txt`), + makeMockFsInput(`${MockHomePath}/notes.txt`), + makeMockFsInput(`${MockHomePath}/shell-aliases`), + makeMockFsInput(`${MockHomePath}/archive.log`), + makeMockFsInput(`${MockHomePath}/session.txt`), + makeMockFsInput(`${MockHomePath}/Desktop/launch-plan.md`), + makeMockFsInput(`${MockHomePath}/Desktop/coffee.txt`), + makeMockFsInput(`${MockHomePath}/Desktop/daily-standup.txt`), + makeMockFsInput(`${MockHomePath}/Desktop/snippets.txt`), + makeMockFsInput(`${MockHomePath}/Desktop/terminal-theme.png`), + makeMockFsInput(`${MockHomePath}/Desktop/macos-shortcuts.txt`), + makeMockFsInput(`${MockHomePath}/Desktop/bug-scrub.txt`), + makeMockFsInput(`${MockHomePath}/Desktop/parking-receipt.pdf`), + makeMockFsInput(`${MockHomePath}/Desktop/demo-script.md`), + makeMockFsInput(`${MockHomePath}/Desktop/roadmap-draft.txt`), + makeMockFsInput(`${MockHomePath}/Desktop/pairing-notes.txt`), + makeMockFsInput(`${MockHomePath}/Desktop/wave-window.jpg`), + makeMockFsInput( + `${MockHomePath}/Documents/meeting-notes.md`, + `# File Preview Notes\n\n- Build a richer preview mock environment.\n- Add a fake filesystem rooted at \`${MockHomePath}\`.\n- Make markdown previews resolve relative assets.\n`, + "text/markdown" + ), + makeMockFsInput(`${MockHomePath}/Documents/architecture-overview.md`), + makeMockFsInput(`${MockHomePath}/Documents/release-checklist.md`), + makeMockFsInput(`${MockHomePath}/Documents/ideas.txt`), + makeMockFsInput(`${MockHomePath}/Documents/customer-feedback.txt`), + makeMockFsInput(`${MockHomePath}/Documents/cli-ux-notes.txt`), + makeMockFsInput(`${MockHomePath}/Documents/migration-plan.md`), + makeMockFsInput(`${MockHomePath}/Documents/design-review.md`), + makeMockFsInput(`${MockHomePath}/Documents/ops-runbook.md`), + makeMockFsInput(`${MockHomePath}/Documents/troubleshooting.txt`), + makeMockFsInput(`${MockHomePath}/Documents/preview-fixtures.txt`), + makeMockFsInput(`${MockHomePath}/Documents/backlog.txt`), + makeMockFsInput(`${MockHomePath}/Documents/feature-flags.yaml`), + makeMockFsInput(`${MockHomePath}/Documents/connections.csv`), + makeMockFsInput(`${MockHomePath}/Documents/ssh-hosts.txt`), + makeMockFsInput(`${MockHomePath}/Documents/notes-2026-03-01.md`), + makeMockFsInput(`${MockHomePath}/Documents/notes-2026-03-05.md`), + makeMockFsInput(`${MockHomePath}/Documents/notes-2026-03-09.md`), + makeMockFsInput(`${MockHomePath}/Downloads/waveterm-nightly.dmg`), + makeMockFsInput(`${MockHomePath}/Downloads/screenshot-pack.zip`), + makeMockFsInput(`${MockHomePath}/Downloads/cli-reference.pdf`), + makeMockFsInput(`${MockHomePath}/Downloads/ssh-cheatsheet.pdf`), + makeMockFsInput(`${MockHomePath}/Downloads/perf-trace.json`), + makeMockFsInput(`${MockHomePath}/Downloads/terminal-icons.zip`), + makeMockFsInput(`${MockHomePath}/Downloads/demo-data.csv`), + makeMockFsInput(`${MockHomePath}/Downloads/deploy-plan.txt`), + makeMockFsInput(`${MockHomePath}/Downloads/customer-audio.m4a`), + makeMockFsInput(`${MockHomePath}/Downloads/mock-shell-history.txt`), + makeMockFsInput(`${MockHomePath}/Downloads/design-assets.zip`), + makeMockFsInput(`${MockHomePath}/Downloads/old-preview-build.dmg`), + makeMockFsInput(`${MockHomePath}/Downloads/testing-samples.tar`), + makeMockFsInput(`${MockHomePath}/Downloads/workflow-failure.log`), + makeMockFsInput(`${MockHomePath}/Downloads/team-photo.jpg`), + makeMockFsInput(`${MockHomePath}/Downloads/preview-recording.mov`), + makeMockFsInput(`${MockHomePath}/Downloads/standup-notes.txt`), + makeMockFsInput(`${MockHomePath}/Downloads/metadata.json`), + makeMockFsInput(`${MockHomePath}/Pictures/beach-sunrise.png`, TinyPngBytes, "image/png"), + makeMockFsInput(`${MockHomePath}/Pictures/terminal-screenshot.jpg`, TinyJpegBytes, "image/jpeg"), + makeMockFsInput(`${MockHomePath}/Pictures/diagram.png`), + makeMockFsInput(`${MockHomePath}/Pictures/launch-party.jpg`), + makeMockFsInput(`${MockHomePath}/Pictures/icon-sketch.png`), + makeMockFsInput(`${MockHomePath}/Pictures/backgrounds-01.png`), + makeMockFsInput(`${MockHomePath}/Pictures/backgrounds-02.png`), + makeMockFsInput(`${MockHomePath}/Pictures/backgrounds-03.png`), + makeMockFsInput(`${MockHomePath}/Pictures/backgrounds-04.png`), + makeMockFsInput(`${MockHomePath}/Pictures/backgrounds-05.png`), + makeMockFsInput(`${MockHomePath}/Pictures/product-shot-01.jpg`), + makeMockFsInput(`${MockHomePath}/Pictures/product-shot-02.jpg`), + makeMockFsInput(`${MockHomePath}/Pictures/product-shot-03.jpg`), + makeMockFsInput(`${MockHomePath}/Pictures/product-shot-04.jpg`), + makeMockFsInput(`${MockHomePath}/Pictures/product-shot-05.jpg`), + makeMockFsInput(`${MockHomePath}/Pictures/ui-concept.png`), + makeMockFsInput(`${MockHomePath}/Projects/local.env`), + makeMockFsInput(`${MockHomePath}/Projects/db-migration.sql`), + makeMockFsInput(`${MockHomePath}/Projects/prompt-lab.txt`), + makeMockFsInput(`${MockHomePath}/Projects/ui-spikes.tsx`), + makeMockFsInput(`${MockHomePath}/Projects/file-browser.tsx`), + makeMockFsInput(`${MockHomePath}/Projects/mock-data.json`), + makeMockFsInput(`${MockHomePath}/Projects/preview-api.ts`), + makeMockFsInput(`${MockHomePath}/Projects/bug-181.txt`), + makeMockFsInput( + `${MockHomePath}/waveterm/README.md`, + `# Mock WaveTerm Repo\n\nThis fake repo exists only in the preview environment.\nIt gives file previews something realistic to browse.\n`, + "text/markdown" + ), + makeMockFsInput(`${MockHomePath}/waveterm/package.json`), + makeMockFsInput(`${MockHomePath}/waveterm/tsconfig.json`), + makeMockFsInput(`${MockHomePath}/waveterm/Taskfile.yml`), + makeMockFsInput(`${MockHomePath}/waveterm/preview-model.tsx`), + makeMockFsInput(`${MockHomePath}/waveterm/mockwaveenv.ts`), + makeMockFsInput(`${MockHomePath}/waveterm/vite.config.ts`), + makeMockFsInput(`${MockHomePath}/waveterm/CHANGELOG.md`), + makeMockFsInput( + `${MockHomePath}/waveterm/docs/preview-notes.md`, + `# Preview Mocking\n\nUse the preview server to iterate on file previews without Electron.\nRelative markdown assets should resolve through \`FileJoinCommand\`.\n`, + "text/markdown" + ), + makeMockFsInput(`${MockHomePath}/waveterm/docs/filesystem-rpc.md`), + makeMockFsInput(`${MockHomePath}/waveterm/docs/test-plan.md`), + makeMockFsInput(`${MockHomePath}/waveterm/docs/connections.md`), + makeMockFsInput(`${MockHomePath}/waveterm/docs/preview-gallery.md`), + makeMockFsInput(`${MockHomePath}/waveterm/docs/release-notes.md`), + makeMockFsInput(`${MockHomePath}/waveterm/images/wave-logo.png`, TinyPngBytes, "image/png"), + makeMockFsInput(`${MockHomePath}/waveterm/images/hero.png`), + makeMockFsInput(`${MockHomePath}/waveterm/images/avatar.jpg`), + makeMockFsInput(`${MockHomePath}/waveterm/images/icon-16.png`), + makeMockFsInput(`${MockHomePath}/waveterm/images/icon-32.png`), + makeMockFsInput(`${MockHomePath}/waveterm/images/splash.jpg`), + makeMockFsInput( + `${MockHomePath}/.config/settings.json`, + JSON.stringify( + { + "app:theme": "wave-dark", + "preview:lastpath": `${MockHomePath}/Documents/meeting-notes.md`, + "window:magnifiedblockopacity": 0.92, + }, + null, + 2 + ), + "application/json" + ), + makeMockFsInput(`${MockHomePath}/.config/preview-cache.json`), + makeMockFsInput(`${MockHomePath}/.config/recent-workspaces.json`), + makeMockFsInput(`${MockHomePath}/.config/telemetry.log`), + ]; + return entries; +} + +function buildEntries(): Map { + const inputs = createMockFilesystemEntries(); + const entries = new Map(); + const ensureDir = (path: string) => { + const normalizedPath = normalizeMockPath(path, "/"); + if (entries.has(normalizedPath)) { + return; + } + const dir = getDirName(normalizedPath); + if (normalizedPath !== "/") { + ensureDir(dir); + } + entries.set(normalizedPath, { + path: normalizedPath, + dir: normalizedPath === "/" ? "/" : dir, + name: normalizedPath === "/" ? "/" : getBaseName(normalizedPath), + isdir: true, + mimetype: MockDirMimeType, + modtime: MockBaseModTime + entries.size * 60000, + mode: MockDirMode, + size: 0, + supportsmkdir: true, + }); + }; + for (const input of inputs) { + const normalizedPath = normalizeMockPath(input.path, "/"); + const isdir = input.isdir ?? false; + const dir = getDirName(normalizedPath); + if (normalizedPath !== "/") { + ensureDir(dir); + } + const content = input.content == null ? undefined : makeContentBytes(input.content); + entries.set(normalizedPath, { + path: normalizedPath, + dir: normalizedPath === "/" ? "/" : dir, + name: normalizedPath === "/" ? "/" : getBaseName(normalizedPath), + isdir, + mimetype: input.mimetype ?? getMimeType(normalizedPath, isdir), + modtime: MockBaseModTime + entries.size * 60000, + mode: isdir ? MockDirMode : MockFileMode, + size: content?.byteLength ?? 0, + readonly: input.readonly, + supportsmkdir: isdir, + content, + }); + } + return entries; +} + +function toFileInfo(entry: MockFsEntry): FileInfo { + return { + path: entry.path, + dir: entry.dir, + name: entry.name, + size: entry.size, + mode: entry.mode, + modtime: entry.modtime, + isdir: entry.isdir, + supportsmkdir: entry.supportsmkdir, + mimetype: entry.mimetype, + readonly: entry.readonly, + }; +} + +function makeNotFoundInfo(path: string): FileInfo { + const normalizedPath = normalizeMockPath(path); + return { + path: normalizedPath, + dir: getDirName(normalizedPath), + name: getBaseName(normalizedPath), + notfound: true, + supportsmkdir: true, + }; +} + +function sliceEntries(entries: FileInfo[], opts?: FileListOpts): FileInfo[] { + let filteredEntries = entries; + if (!opts?.all) { + filteredEntries = filteredEntries.filter((entry) => entry.name != null && !entry.name.startsWith(".")); + } + const offset = Math.max(opts?.offset ?? 0, 0); + const end = opts?.limit != null && opts.limit >= 0 ? offset + opts.limit : undefined; + return filteredEntries.slice(offset, end); +} + +function joinPaths(paths: string[]): string { + if (paths.length === 0) { + return MockHomePath; + } + let currentPath = normalizeMockPath(paths[0]); + for (const part of paths.slice(1)) { + currentPath = normalizeMockPath(part, currentPath); + } + return currentPath; +} + +function getReadRange(data: FileData, size: number): { offset: number; end: number } { + const offset = Math.max(data?.at?.offset ?? 0, 0); + const end = data?.at?.size != null ? Math.min(offset + data.at.size, size) : size; + return { offset, end: Math.max(offset, end) }; +} + +export function makeMockFilesystem(): MockFilesystem { + const entries = buildEntries(); + const childrenByDir = new Map(); + for (const entry of entries.values()) { + if (entry.path === "/") { + continue; + } + if (!childrenByDir.has(entry.dir)) { + childrenByDir.set(entry.dir, []); + } + childrenByDir.get(entry.dir).push(entry); + } + for (const childEntries of childrenByDir.values()) { + childEntries.sort((a, b) => { + if (a.isdir !== b.isdir) { + return a.isdir ? -1 : 1; + } + return a.name.localeCompare(b.name); + }); + } + const getEntry = (path: string): MockFsEntry => { + return entries.get(normalizeMockPath(path)); + }; + const fileInfo = async (data: FileData): Promise => { + const entry = getEntry(data?.info?.path ?? MockHomePath); + if (!entry) { + return makeNotFoundInfo(data?.info?.path ?? MockHomePath); + } + return toFileInfo(entry); + }; + const fileRead = async (data: FileData): Promise => { + const info = await fileInfo(data); + if (info.notfound) { + return { info }; + } + const entry = getEntry(info.path); + if (entry.isdir) { + const childEntries = (childrenByDir.get(entry.path) ?? []).map((child) => toFileInfo(child)); + return { info, entries: childEntries }; + } + if (entry.content == null || entry.content.byteLength === 0) { + return { info }; + } + const { offset, end } = getReadRange(data, entry.content.byteLength); + return { + info, + data64: arrayToBase64(entry.content.slice(offset, end)), + at: { offset, size: end - offset }, + }; + }; + const fileList = async (data: FileListData): Promise => { + const dirPath = normalizeMockPath(data?.path ?? MockHomePath); + const entry = getEntry(dirPath); + if (entry == null || !entry.isdir) { + return []; + } + const dirEntries = (childrenByDir.get(dirPath) ?? []).map((child) => toFileInfo(child)); + return sliceEntries(dirEntries, data?.opts); + }; + const fileJoin = async (paths: string[]): Promise => { + const path = paths.length === 1 ? normalizeMockPath(paths[0]) : joinPaths(paths); + const entry = getEntry(path); + if (!entry) { + return makeNotFoundInfo(path); + } + return toFileInfo(entry); + }; + const fileReadStream = async function* (data: FileData): AsyncGenerator { + const info = await fileInfo(data); + yield { info }; + if (info.notfound) { + return; + } + const entry = getEntry(info.path); + if (entry.isdir) { + const dirEntries = (childrenByDir.get(entry.path) ?? []).map((child) => toFileInfo(child)); + for (let idx = 0; idx < dirEntries.length; idx += MockDirectoryChunkSize) { + yield { entries: dirEntries.slice(idx, idx + MockDirectoryChunkSize) }; + } + return; + } + if (entry.content == null || entry.content.byteLength === 0) { + return; + } + const { offset, end } = getReadRange(data, entry.content.byteLength); + for (let currentOffset = offset; currentOffset < end; currentOffset += MockFileChunkSize) { + const chunkEnd = Math.min(currentOffset + MockFileChunkSize, end); + yield { + data64: arrayToBase64(entry.content.slice(currentOffset, chunkEnd)), + at: { offset: currentOffset, size: chunkEnd - currentOffset }, + }; + } + }; + const fileListStream = async function* (data: FileListData): AsyncGenerator { + const fileInfos = await fileList(data); + for (let idx = 0; idx < fileInfos.length; idx += MockDirectoryChunkSize) { + yield { fileinfo: fileInfos.slice(idx, idx + MockDirectoryChunkSize) }; + } + }; + const fileCount = Array.from(entries.values()).filter((entry) => !entry.isdir).length; + const directoryCount = Array.from(entries.values()).filter((entry) => entry.isdir).length; + return { + homePath: MockHomePath, + fileCount, + directoryCount, + entryCount: entries.size, + fileInfo, + fileRead, + fileList, + fileJoin, + fileReadStream, + fileListStream, + }; +} + +export const DefaultMockFilesystem = makeMockFilesystem(); diff --git a/frontend/preview/mock/mockwaveenv.test.ts b/frontend/preview/mock/mockwaveenv.test.ts new file mode 100644 index 000000000..25aee2299 --- /dev/null +++ b/frontend/preview/mock/mockwaveenv.test.ts @@ -0,0 +1,96 @@ +import { base64ToArray, base64ToString } from "@/util/util"; +import { describe, expect, it, vi } from "vitest"; +import { DefaultMockFilesystem } from "./mockfilesystem"; + +const { showPreviewContextMenu } = vi.hoisted(() => ({ + showPreviewContextMenu: vi.fn(), +})); + +vi.mock("../preview-contextmenu", () => ({ + showPreviewContextMenu, +})); + +describe("makeMockWaveEnv", () => { + it("uses the preview context menu by default", async () => { + const { makeMockWaveEnv } = await import("./mockwaveenv"); + const env = makeMockWaveEnv(); + const menu = [{ label: "Open" }]; + const event = { stopPropagation: vi.fn() } as any; + + env.showContextMenu(menu, event); + + expect(showPreviewContextMenu).toHaveBeenCalledWith(menu, event); + }); + + it("provides a populated mock filesystem rooted at /Users/mike", () => { + expect(DefaultMockFilesystem.homePath).toBe("/Users/mike"); + expect(DefaultMockFilesystem.fileCount).toBeGreaterThanOrEqual(100); + expect(DefaultMockFilesystem.directoryCount).toBeGreaterThanOrEqual(10); + }); + + it("implements file info, read, list, and join commands", async () => { + const { makeMockWaveEnv } = await import("./mockwaveenv"); + const env = makeMockWaveEnv(); + + const bashrcInfo = await env.rpc.FileInfoCommand(null as any, { + info: { path: "wsh://local//Users/mike/.bashrc" }, + }); + expect(bashrcInfo.path).toBe("/Users/mike/.bashrc"); + expect(bashrcInfo.mimetype).toBe("text/plain"); + + const bashrcData = await env.rpc.FileReadCommand(null as any, { + info: { path: "wsh://local//Users/mike/.bashrc" }, + }); + expect(base64ToString(bashrcData.data64)).toContain('alias gs="git status -sb"'); + + const visibleHomeEntries = await env.rpc.FileListCommand(null as any, { + path: "/Users/mike", + }); + expect(visibleHomeEntries.some((entry) => entry.name === ".bashrc")).toBe(false); + expect(visibleHomeEntries.some((entry) => entry.name === "waveterm")).toBe(true); + + const allHomeEntries = await env.rpc.FileListCommand(null as any, { + path: "/Users/mike", + opts: { all: true }, + }); + expect(allHomeEntries.some((entry) => entry.name === ".bashrc")).toBe(true); + + const dirRead = await env.rpc.FileReadCommand(null as any, { + info: { path: "/Users/mike/waveterm" }, + }); + expect(dirRead.entries.some((entry) => entry.name === "docs" && entry.isdir)).toBe(true); + + const joined = await env.rpc.FileJoinCommand(null as any, [ + "wsh://local//Users/mike/Documents", + "../waveterm/docs", + "preview-notes.md", + ]); + expect(joined.path).toBe("/Users/mike/waveterm/docs/preview-notes.md"); + expect(joined.mimetype).toBe("text/markdown"); + }); + + it("implements file list and read stream commands", async () => { + const { makeMockWaveEnv } = await import("./mockwaveenv"); + const env = makeMockWaveEnv(); + + const listPackets: CommandRemoteListEntriesRtnData[] = []; + for await (const packet of env.rpc.FileListStreamCommand(null as any, { + path: "/Users/mike", + opts: { all: true, limit: 4 }, + })) { + listPackets.push(packet); + } + expect(listPackets).toHaveLength(1); + expect(listPackets[0].fileinfo).toHaveLength(4); + + const readPackets: FileData[] = []; + for await (const packet of env.rpc.FileReadStreamCommand(null as any, { + info: { path: "/Users/mike/Pictures/beach-sunrise.png" }, + })) { + readPackets.push(packet); + } + expect(readPackets[0].info?.path).toBe("/Users/mike/Pictures/beach-sunrise.png"); + const imageBytes = base64ToArray(readPackets[1].data64); + expect(Array.from(imageBytes.slice(0, 4))).toEqual([0x89, 0x50, 0x4e, 0x47]); + }); +}); diff --git a/frontend/preview/mock/mockwaveenv.ts b/frontend/preview/mock/mockwaveenv.ts new file mode 100644 index 000000000..5e787610e --- /dev/null +++ b/frontend/preview/mock/mockwaveenv.ts @@ -0,0 +1,435 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { makeDefaultConnStatus } from "@/app/store/global"; +import { globalStore } from "@/app/store/jotaiStore"; +import { AllServiceTypes } from "@/app/store/services"; +import { handleWaveEvent } from "@/app/store/wps"; +import { RpcApiType } from "@/app/store/wshclientapi"; +import { WaveEnv } from "@/app/waveenv/waveenv"; +import { PlatformMacOS, PlatformWindows } from "@/util/platformutil"; +import { Atom, atom, PrimitiveAtom, useAtomValue } from "jotai"; +import { DefaultFullConfig } from "./defaultconfig"; +import { DefaultMockFilesystem } from "./mockfilesystem"; +import { showPreviewContextMenu } from "../preview-contextmenu"; +import { previewElectronApi } from "./preview-electron-api"; + +// What works "out of the box" in the mock environment (no MockEnv overrides needed): +// +// RPC calls (handled in makeMockRpc): +// - rpc.EventPublishCommand -- dispatches to handleWaveEvent(); works when the subscriber +// is purely FE-based (registered via WPS on the frontend) +// - rpc.GetMetaCommand -- reads .meta from the mock WOS atom for the given oref +// - rpc.SetMetaCommand -- writes .meta to the mock WOS atom (null values delete keys) +// - rpc.SetConfigCommand -- merges settings into fullConfigAtom (null values delete keys) +// - rpc.UpdateTabNameCommand -- updates .name on the Tab WaveObj in the mock WOS +// - rpc.UpdateWorkspaceTabIdsCommand -- updates .tabids on the Workspace WaveObj in the mock WOS +// +// Any other RPC call falls through to a console.log and resolves null. +// Override specific calls via MockEnv.rpc (keys are the Command method names, e.g. "GetMetaCommand"). +// +// Backend service calls (handled in callBackendService): +// Any call falls through to a console.log and resolves null. +// Override specific calls via MockEnv.services: { Service: { Method: impl } } +// e.g. { "block": { "GetControllerStatus": (blockId) => myStatus } } + +type RpcOverrides = { + [K in keyof RpcApiType as K extends `${string}Command` ? K : never]?: ( + ...args: any[] + ) => Promise | AsyncGenerator; +}; + +type ServiceOverrides = { + [Service: string]: { + [Method: string]: (...args: any[]) => Promise; + }; +}; + +export type MockEnv = { + isDev?: boolean; + tabId?: string; + platform?: NodeJS.Platform; + settings?: Partial; + rpc?: RpcOverrides; + services?: ServiceOverrides; + atoms?: Partial; + electron?: Partial; + createBlock?: WaveEnv["createBlock"]; + showContextMenu?: WaveEnv["showContextMenu"]; + connStatus?: Record; + mockWaveObjs?: Record; +}; + +export type MockWaveEnv = WaveEnv & { mockEnv: MockEnv }; + +function mergeRecords(base: Record, overrides: Record): Record { + if (base == null && overrides == null) { + return undefined; + } + return { ...(base ?? {}), ...(overrides ?? {}) }; +} + +export function mergeMockEnv(base: MockEnv, overrides: MockEnv): MockEnv { + let mergedServices: ServiceOverrides; + if (base.services != null || overrides.services != null) { + mergedServices = {}; + for (const svc of Object.keys(base.services ?? {})) { + mergedServices[svc] = { ...(base.services[svc] ?? {}) }; + } + for (const svc of Object.keys(overrides.services ?? {})) { + mergedServices[svc] = { ...(mergedServices[svc] ?? {}), ...(overrides.services[svc] ?? {}) }; + } + } + return { + isDev: overrides.isDev ?? base.isDev, + tabId: overrides.tabId ?? base.tabId, + platform: overrides.platform ?? base.platform, + settings: mergeRecords(base.settings, overrides.settings), + rpc: mergeRecords(base.rpc as any, overrides.rpc as any) as RpcOverrides, + services: mergedServices, + atoms: overrides.atoms != null || base.atoms != null ? { ...base.atoms, ...overrides.atoms } : undefined, + electron: + overrides.electron != null || base.electron != null + ? { ...(base.electron ?? {}), ...(overrides.electron ?? {}) } + : undefined, + createBlock: overrides.createBlock ?? base.createBlock, + showContextMenu: overrides.showContextMenu ?? base.showContextMenu, + connStatus: mergeRecords(base.connStatus, overrides.connStatus), + mockWaveObjs: mergeRecords(base.mockWaveObjs, overrides.mockWaveObjs), + }; +} + +function makeMockSettingsKeyAtom( + settingsAtom: Atom, + overrides?: Partial +): WaveEnv["getSettingsKeyAtom"] { + const keyAtomCache = new Map>(); + return (key: T) => { + if (!keyAtomCache.has(key)) { + keyAtomCache.set( + key, + atom((get) => (overrides?.[key] !== undefined ? overrides[key] : get(settingsAtom)?.[key])) + ); + } + return keyAtomCache.get(key) as Atom; + }; +} + +function makeMockGlobalAtoms( + settingsOverrides: Partial, + atomOverrides: Partial, + tabId: string, + getWaveObjectAtom: (oref: string) => PrimitiveAtom +): GlobalAtomsType { + let fullConfig = DefaultFullConfig; + if (settingsOverrides) { + fullConfig = { + ...DefaultFullConfig, + settings: { ...DefaultFullConfig.settings, ...settingsOverrides }, + }; + } + const fullConfigAtom = atom(fullConfig) as PrimitiveAtom; + const settingsAtom = atom((get) => get(fullConfigAtom)?.settings ?? {}) as Atom; + const workspaceIdAtom: Atom = atomOverrides?.workspaceId ?? (atom(null as string) as Atom); + const workspaceAtom: Atom = atom((get) => { + const wsId = get(workspaceIdAtom); + if (wsId == null) { + return null; + } + return get(getWaveObjectAtom("workspace:" + wsId)); + }); + const defaults: GlobalAtomsType = { + builderId: atom(""), + builderAppId: atom("") as any, + uiContext: atom({ windowid: "", activetabid: tabId ?? "" } as UIContext), + workspaceId: workspaceIdAtom, + workspace: workspaceAtom, + fullConfigAtom, + waveaiModeConfigAtom: atom({}) as any, + settingsAtom, + hasCustomAIPresetsAtom: atom(false), + hasConfigErrors: atom((get) => { + const c = get(fullConfigAtom); + return c?.configerrors != null && c.configerrors.length > 0; + }), + staticTabId: atom(tabId ?? ""), + isFullScreen: atom(false) as any, + zoomFactorAtom: atom(1.0) as any, + controlShiftDelayAtom: atom(false) as any, + prefersReducedMotionAtom: atom(false), + documentHasFocus: atom(true) as any, + updaterStatusAtom: atom("up-to-date" as UpdaterStatus) as any, + modalOpen: atom(false) as any, + allConnStatus: atom([] as ConnStatus[]), + reinitVersion: atom(0) as any, + waveAIRateLimitInfoAtom: atom(null) as any, + }; + if (!atomOverrides) { + return defaults; + } + const merged = { ...defaults, ...atomOverrides }; + if (!atomOverrides.workspace) { + merged.workspace = workspaceAtom; + } + return merged; +} + +type MockWosFns = { + getWaveObjectAtom: (oref: string) => PrimitiveAtom; + mockSetWaveObj: (oref: string, obj: T) => void; + fullConfigAtom: PrimitiveAtom; +}; + +export function makeMockRpc(overrides: RpcOverrides, wos: MockWosFns): RpcApiType { + const callDispatchMap = new Map Promise>(); + const streamDispatchMap = new Map AsyncGenerator>(); + const setCallHandler = (command: string, fn: (...args: any[]) => Promise) => { + callDispatchMap.set(command, fn); + }; + const setStreamHandler = (command: string, fn: (...args: any[]) => AsyncGenerator) => { + streamDispatchMap.set(command, fn); + }; + setCallHandler("eventpublish", async (_client, data: WaveEvent) => { + console.log("[mock eventpublish]", data); + handleWaveEvent(data); + return null; + }); + setCallHandler("getmeta", async (_client, data: CommandGetMetaData) => { + const objAtom = wos.getWaveObjectAtom(data.oref); + const current = globalStore.get(objAtom) as WaveObj & { meta?: MetaType }; + return current?.meta ?? {}; + }); + setCallHandler("setmeta", async (_client, data: CommandSetMetaData) => { + const objAtom = wos.getWaveObjectAtom(data.oref); + const current = globalStore.get(objAtom) as WaveObj & { meta?: MetaType }; + const updatedMeta = { ...(current?.meta ?? {}) }; + for (const [key, value] of Object.entries(data.meta)) { + if (value === null) { + delete updatedMeta[key]; + } else { + (updatedMeta as any)[key] = value; + } + } + const updated = { ...current, meta: updatedMeta }; + wos.mockSetWaveObj(data.oref, updated); + return null; + }); + setCallHandler("updatetabname", async (_client, data: { args: [string, string] }) => { + const [tabId, newName] = data.args; + const tabORef = "tab:" + tabId; + const objAtom = wos.getWaveObjectAtom(tabORef); + const current = globalStore.get(objAtom) as Tab; + const updated = { ...current, name: newName }; + wos.mockSetWaveObj(tabORef, updated); + return null; + }); + setCallHandler("setconfig", async (_client, data: SettingsType) => { + const current = globalStore.get(wos.fullConfigAtom); + const updatedSettings = { ...(current?.settings ?? {}) }; + for (const [key, value] of Object.entries(data)) { + if (value === null) { + delete (updatedSettings as any)[key]; + } else { + (updatedSettings as any)[key] = value; + } + } + globalStore.set(wos.fullConfigAtom, { ...current, settings: updatedSettings as SettingsType }); + return null; + }); + setCallHandler("updateworkspacetabids", async (_client, data: { args: [string, string[]] }) => { + const [workspaceId, tabIds] = data.args; + const wsORef = "workspace:" + workspaceId; + const objAtom = wos.getWaveObjectAtom(wsORef); + const current = globalStore.get(objAtom) as Workspace; + const updated = { ...current, tabids: tabIds }; + wos.mockSetWaveObj(wsORef, updated); + return null; + }); + setCallHandler("fileinfo", async (_client, data: FileData) => DefaultMockFilesystem.fileInfo(data)); + setCallHandler("fileread", async (_client, data: FileData) => DefaultMockFilesystem.fileRead(data)); + setCallHandler("filelist", async (_client, data: FileListData) => DefaultMockFilesystem.fileList(data)); + setCallHandler("filejoin", async (_client, data: string[]) => DefaultMockFilesystem.fileJoin(data)); + setStreamHandler("filereadstream", async function* (_client, data: FileData) { + yield* DefaultMockFilesystem.fileReadStream(data); + }); + setStreamHandler("fileliststream", async function* (_client, data: FileListData) { + yield* DefaultMockFilesystem.fileListStream(data); + }); + if (overrides) { + for (const key of Object.keys(overrides) as (keyof RpcOverrides)[]) { + const cmdName = key.slice(0, -"Command".length).toLowerCase(); + if (cmdName === "filereadstream" || cmdName === "fileliststream") { + setStreamHandler(cmdName, overrides[key] as (...args: any[]) => AsyncGenerator); + } else { + setCallHandler(cmdName, overrides[key] as (...args: any[]) => Promise); + } + } + } + const rpc = new RpcApiType(); + rpc.setMockRpcClient({ + mockWshRpcCall(_client, command, data, _opts) { + const fn = callDispatchMap.get(command); + if (fn) { + return fn(_client, data, _opts); + } + console.log("[mock rpc call]", command, data); + return Promise.resolve(null); + }, + async *mockWshRpcStream(_client, command, data, _opts) { + const streamFn = streamDispatchMap.get(command); + if (streamFn) { + yield* streamFn(_client, data, _opts); + return; + } + const callFn = callDispatchMap.get(command); + if (callFn) { + yield await callFn(_client, data, _opts); + return; + } + console.log("[mock rpc stream]", command, data); + yield null; + }, + }); + return rpc; +} + +export function applyMockEnvOverrides(env: WaveEnv, newOverrides: MockEnv): MockWaveEnv { + const existing = (env as MockWaveEnv).mockEnv; + const merged = existing != null ? mergeMockEnv(existing, newOverrides) : newOverrides; + return makeMockWaveEnv(merged); +} + +export function makeMockWaveEnv(mockEnv?: MockEnv): MockWaveEnv { + const overrides: MockEnv = mockEnv ?? {}; + const platform = overrides.platform ?? PlatformMacOS; + const connStatusAtomCache = new Map>(); + const waveObjectValueAtomCache = new Map>(); + const waveObjectDerivedAtomCache = new Map>(); + const blockMetaKeyAtomCache = new Map>(); + const connConfigKeyAtomCache = new Map>(); + const getWaveObjectAtom = (oref: string): PrimitiveAtom => { + if (!waveObjectValueAtomCache.has(oref)) { + const obj = (overrides.mockWaveObjs?.[oref] ?? null) as T; + waveObjectValueAtomCache.set(oref, atom(obj) as PrimitiveAtom); + } + return waveObjectValueAtomCache.get(oref) as PrimitiveAtom; + }; + const atoms = makeMockGlobalAtoms(overrides.settings, overrides.atoms, overrides.tabId, getWaveObjectAtom); + const localHostDisplayNameAtom = atom((get) => { + const configValue = get(atoms.settingsAtom)?.["conn:localhostdisplayname"]; + if (configValue != null) { + return configValue; + } + return "user@localhost"; + }); + const mockWosFns: MockWosFns = { + getWaveObjectAtom, + fullConfigAtom: atoms.fullConfigAtom, + mockSetWaveObj: (oref: string, obj: T) => { + if (!waveObjectValueAtomCache.has(oref)) { + waveObjectValueAtomCache.set(oref, atom(null as WaveObj)); + } + globalStore.set(waveObjectValueAtomCache.get(oref), obj); + }, + }; + const env = { + isMock: true, + mockEnv: overrides, + electron: { + ...previewElectronApi, + getPlatform: () => platform, + openExternal: (url: string) => { + window.open(url, "_blank"); + }, + ...overrides.electron, + }, + rpc: makeMockRpc(overrides.rpc, mockWosFns), + atoms, + getSettingsKeyAtom: makeMockSettingsKeyAtom(atoms.settingsAtom, overrides.settings), + platform, + isDev: () => overrides.isDev ?? true, + isWindows: () => platform === PlatformWindows, + isMacOS: () => platform === PlatformMacOS, + createBlock: + overrides.createBlock ?? + ((blockDef: BlockDef, magnified?: boolean, ephemeral?: boolean) => { + console.log("[mock createBlock]", blockDef, { magnified, ephemeral }); + return Promise.resolve(crypto.randomUUID()); + }), + showContextMenu: + overrides.showContextMenu ?? showPreviewContextMenu, + getLocalHostDisplayNameAtom: () => { + return localHostDisplayNameAtom; + }, + getConnStatusAtom: (conn: string) => { + if (!connStatusAtomCache.has(conn)) { + const connStatus = overrides.connStatus?.[conn] ?? makeDefaultConnStatus(conn); + connStatusAtomCache.set(conn, atom(connStatus)); + } + return connStatusAtomCache.get(conn); + }, + wos: { + getWaveObjectAtom: mockWosFns.getWaveObjectAtom, + getWaveObjectLoadingAtom: (oref: string) => { + const cacheKey = oref + ":loading"; + if (!waveObjectDerivedAtomCache.has(cacheKey)) { + waveObjectDerivedAtomCache.set(cacheKey, atom(false)); + } + return waveObjectDerivedAtomCache.get(cacheKey) as Atom; + }, + isWaveObjectNullAtom: (oref: string) => { + const cacheKey = oref + ":isnull"; + if (!waveObjectDerivedAtomCache.has(cacheKey)) { + waveObjectDerivedAtomCache.set( + cacheKey, + atom((get) => get(env.wos.getWaveObjectAtom(oref)) == null) + ); + } + return waveObjectDerivedAtomCache.get(cacheKey) as Atom; + }, + useWaveObjectValue: (oref: string): [T, boolean] => { + const objAtom = env.wos.getWaveObjectAtom(oref); + return [useAtomValue(objAtom), false]; + }, + }, + getBlockMetaKeyAtom: (blockId: string, key: T) => { + const cacheKey = blockId + "#meta-" + key; + if (!blockMetaKeyAtomCache.has(cacheKey)) { + const metaAtom = atom((get) => { + const blockORef = "block:" + blockId; + const blockAtom = env.wos.getWaveObjectAtom(blockORef); + const blockData = get(blockAtom); + return blockData?.meta?.[key] as MetaType[T]; + }); + blockMetaKeyAtomCache.set(cacheKey, metaAtom); + } + return blockMetaKeyAtomCache.get(cacheKey) as Atom; + }, + getConnConfigKeyAtom: (connName: string, key: T) => { + const cacheKey = connName + "#conn-" + key; + if (!connConfigKeyAtomCache.has(cacheKey)) { + const keyAtom = atom((get) => { + const fullConfig = get(atoms.fullConfigAtom); + return fullConfig.connections?.[connName]?.[key]; + }); + connConfigKeyAtomCache.set(cacheKey, keyAtom); + } + return connConfigKeyAtomCache.get(cacheKey) as Atom; + }, + services: null as any, + callBackendService: (service: string, method: string, args: any[], noUIContext?: boolean) => { + const fn = overrides.services?.[service]?.[method]; + if (fn) { + return fn(...args); + } + console.log("[mock callBackendService]", service, method, args, noUIContext); + return Promise.resolve(null); + }, + mockSetWaveObj: mockWosFns.mockSetWaveObj, + mockModels: new Map(), + } as MockWaveEnv; + env.services = Object.fromEntries( + Object.entries(AllServiceTypes).map(([key, ServiceClass]) => [key, new ServiceClass(env)]) + ) as any; + return env; +} diff --git a/frontend/preview/mock/preview-electron-api.ts b/frontend/preview/mock/preview-electron-api.ts new file mode 100644 index 000000000..36c82f26d --- /dev/null +++ b/frontend/preview/mock/preview-electron-api.ts @@ -0,0 +1,68 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +const previewElectronApi: ElectronApi = { + getAuthKey: () => "", + getIsDev: () => false, + getCursorPoint: () => ({ x: 0, y: 0 }) as Electron.Point, + getPlatform: () => "darwin", + getEnv: (_varName: string) => "", + getUserName: () => "", + getHostName: () => "", + getDataDir: () => "", + getConfigDir: () => "", + getHomeDir: () => "", + getWebviewPreload: () => "", + getAboutModalDetails: () => ({}) as AboutModalDetails, + getZoomFactor: () => 1.0, + showWorkspaceAppMenu: (_workspaceId: string) => {}, + showBuilderAppMenu: (_builderId: string) => {}, + showContextMenu: (_workspaceId: string, _menu: ElectronContextMenuItem[]) => {}, + onContextMenuClick: (_callback: (id: string | null) => void) => {}, + onNavigate: (_callback: (url: string) => void) => {}, + onIframeNavigate: (_callback: (url: string) => void) => {}, + downloadFile: (_path: string) => {}, + openExternal: (_url: string) => {}, + onFullScreenChange: (_callback: (isFullScreen: boolean) => void) => {}, + onZoomFactorChange: (_callback: (zoomFactor: number) => void) => {}, + onUpdaterStatusChange: (_callback: (status: UpdaterStatus) => void) => {}, + getUpdaterStatus: () => "up-to-date", + getUpdaterChannel: () => "", + installAppUpdate: () => {}, + onMenuItemAbout: (_callback: () => void) => {}, + updateWindowControlsOverlay: (_rect: Dimensions) => {}, + onReinjectKey: (_callback: (waveEvent: WaveKeyboardEvent) => void) => {}, + setWebviewFocus: (_focusedId: number) => {}, + registerGlobalWebviewKeys: (_keys: string[]) => {}, + onControlShiftStateUpdate: (_callback: (state: boolean) => void) => {}, + createWorkspace: () => {}, + switchWorkspace: (_workspaceId: string) => {}, + deleteWorkspace: (_workspaceId: string) => {}, + setActiveTab: (_tabId: string) => {}, + createTab: () => {}, + closeTab: (_workspaceId: string, _tabId: string, _confirmClose: boolean) => Promise.resolve(false), + setWindowInitStatus: (_status: "ready" | "wave-ready") => {}, + onWaveInit: (_callback: (initOpts: WaveInitOpts) => void) => {}, + onBuilderInit: (_callback: (initOpts: BuilderInitOpts) => void) => {}, + sendLog: (_log: string) => {}, + onQuicklook: (_filePath: string) => {}, + openNativePath: (_filePath: string) => {}, + captureScreenshot: (_rect: Electron.Rectangle) => Promise.resolve(""), + setKeyboardChordMode: () => {}, + clearWebviewStorage: (_webContentsId: number) => Promise.resolve(), + setWaveAIOpen: (_isOpen: boolean) => {}, + closeBuilderWindow: () => {}, + incrementTermCommands: (_opts?: { isRemote?: boolean; isWsl?: boolean; isDurable?: boolean }) => {}, + nativePaste: () => {}, + openBuilder: (_appId?: string) => {}, + setBuilderWindowAppId: (_appId: string) => {}, + doRefresh: () => {}, + saveTextFile: (_fileName: string, _content: string) => Promise.resolve(false), + setIsActive: async () => {}, +}; + +function installPreviewElectronApi() { + (window as any).api = previewElectronApi; +} + +export { installPreviewElectronApi, previewElectronApi }; diff --git a/frontend/preview/mock/tabbar-mock.tsx b/frontend/preview/mock/tabbar-mock.tsx new file mode 100644 index 000000000..c4a811f6e --- /dev/null +++ b/frontend/preview/mock/tabbar-mock.tsx @@ -0,0 +1,173 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { globalStore } from "@/app/store/jotaiStore"; +import { useWaveEnv, WaveEnv, WaveEnvContext } from "@/app/waveenv/waveenv"; +import { applyMockEnvOverrides, MockWaveEnv } from "@/preview/mock/mockwaveenv"; +import { PlatformMacOS } from "@/util/platformutil"; +import { atom } from "jotai"; +import React, { useMemo, useRef } from "react"; + +type PreviewTabEntry = { + tabId: string; + tabName: string; + badges?: Badge[] | null; + flagColor?: string | null; +}; + +function badgeBlockId(tabId: string, badgeId: string): string { + return `${tabId}-badge-${badgeId}`; +} + +function makeTabWaveObj(tab: PreviewTabEntry): Tab { + const blockids = (tab.badges ?? []).map((b) => badgeBlockId(tab.tabId, b.badgeid)); + return { + otype: "tab", + oid: tab.tabId, + version: 1, + name: tab.tabName, + blockids, + meta: tab.flagColor ? { "tab:flagcolor": tab.flagColor } : {}, + } as Tab; +} + +function makeMockBadgeEvents(): BadgeEvent[] { + const events: BadgeEvent[] = []; + for (const tab of TabBarMockTabs) { + for (const badge of tab.badges ?? []) { + events.push({ oref: `block:${badgeBlockId(tab.tabId, badge.badgeid)}`, badge }); + } + } + return events; +} + +export const TabBarMockWorkspaceId = "preview-workspace-1"; + +export const TabBarMockTabs: PreviewTabEntry[] = [ + { tabId: "preview-tab-1", tabName: "Terminal" }, + { + tabId: "preview-tab-2", + tabName: "Build Logs", + badges: [ + { + badgeid: "01958000-0000-7000-0000-000000000001", + icon: "triangle-exclamation", + color: "#f59e0b", + priority: 2, + }, + ], + }, + { + tabId: "preview-tab-3", + tabName: "Deploy", + badges: [ + { badgeid: "01958000-0000-7000-0000-000000000002", icon: "circle-check", color: "#4ade80", priority: 3 }, + ], + flagColor: "#429dff", + }, + { + tabId: "preview-tab-4", + tabName: "A Very Long Tab Name To Show Truncation", + badges: [ + { badgeid: "01958000-0000-7000-0000-000000000003", icon: "bell", color: "#f87171", priority: 2 }, + { badgeid: "01958000-0000-7000-0000-000000000004", icon: "circle-small", color: "#fbbf24", priority: 1 }, + ], + }, + { tabId: "preview-tab-5", tabName: "Wave AI" }, + { tabId: "preview-tab-6", tabName: "Preview", flagColor: "#bf55ec" }, +]; + +function makeMockWorkspace(tabIds: string[]): Workspace { + return { + otype: "workspace", + oid: TabBarMockWorkspaceId, + version: 1, + name: "Preview Workspace", + tabids: tabIds, + activetabid: tabIds[1] ?? tabIds[0] ?? "", + meta: {}, + } as Workspace; +} + +export function makeTabBarMockEnv( + baseEnv: WaveEnv, + envRef: React.RefObject, + platform: NodeJS.Platform +): MockWaveEnv { + const initialTabIds = TabBarMockTabs.map((t) => t.tabId); + const mockWaveObjs: Record = { + [`workspace:${TabBarMockWorkspaceId}`]: makeMockWorkspace(initialTabIds), + }; + for (const tab of TabBarMockTabs) { + mockWaveObjs[`tab:${tab.tabId}`] = makeTabWaveObj(tab); + } + const env = applyMockEnvOverrides(baseEnv, { + tabId: TabBarMockTabs[1].tabId, + platform, + mockWaveObjs, + atoms: { + workspaceId: atom(TabBarMockWorkspaceId), + staticTabId: atom(TabBarMockTabs[1].tabId), + }, + rpc: { + GetAllBadgesCommand: () => Promise.resolve(makeMockBadgeEvents()), + }, + electron: { + createTab: () => { + const e = envRef.current; + if (e == null) return; + const newTabId = `preview-tab-${crypto.randomUUID()}`; + e.mockSetWaveObj(`tab:${newTabId}`, { + otype: "tab", + oid: newTabId, + version: 1, + name: "New Tab", + blockids: [], + meta: {}, + } as Tab); + const ws = globalStore.get(e.wos.getWaveObjectAtom(`workspace:${TabBarMockWorkspaceId}`)); + e.mockSetWaveObj(`workspace:${TabBarMockWorkspaceId}`, { + ...ws, + tabids: [...(ws.tabids ?? []), newTabId], + }); + globalStore.set(e.atoms.staticTabId as any, newTabId); + }, + closeTab: (_workspaceId: string, tabId: string) => { + const e = envRef.current; + if (e == null) return Promise.resolve(false); + const ws = globalStore.get(e.wos.getWaveObjectAtom(`workspace:${TabBarMockWorkspaceId}`)); + const newTabIds = (ws.tabids ?? []).filter((id) => id !== tabId); + if (newTabIds.length === 0) { + return Promise.resolve(false); + } + e.mockSetWaveObj(`workspace:${TabBarMockWorkspaceId}`, { ...ws, tabids: newTabIds }); + if (globalStore.get(e.atoms.staticTabId) === tabId) { + globalStore.set(e.atoms.staticTabId as any, newTabIds[0]); + } + return Promise.resolve(true); + }, + setActiveTab: (tabId: string) => { + const e = envRef.current; + if (e == null) return; + globalStore.set(e.atoms.staticTabId as any, tabId); + }, + showWorkspaceAppMenu: () => { + console.log("[preview] showWorkspaceAppMenu"); + }, + }, + }); + envRef.current = env; + return env; +} + +type TabBarMockEnvProviderProps = { + children: React.ReactNode; +}; + +export function TabBarMockEnvProvider({ children }: TabBarMockEnvProviderProps) { + const baseEnv = useWaveEnv(); + const envRef = useRef(null); + const tabEnv = useMemo(() => makeTabBarMockEnv(baseEnv, envRef, PlatformMacOS), []); + return {children}; +} +TabBarMockEnvProvider.displayName = "TabBarMockEnvProvider"; diff --git a/frontend/preview/preview-contextmenu.tsx b/frontend/preview/preview-contextmenu.tsx new file mode 100644 index 000000000..0be376c6b --- /dev/null +++ b/frontend/preview/preview-contextmenu.tsx @@ -0,0 +1,326 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { + autoUpdate, + flip, + FloatingPortal, + offset, + shift, + type Placement, + type VirtualElement, + useFloating, +} from "@floating-ui/react"; +import { cn } from "@/util/util"; +import { memo, useEffect, useMemo, useRef, useState } from "react"; + +type PreviewContextMenuState = { + items: ContextMenuItem[]; + x: number; + y: number; +}; + +type PreviewContextMenuPanelProps = { + items: ContextMenuItem[]; + point?: { x: number; y: number }; + referenceElement?: HTMLElement; + placement: Placement; + depth: number; + parentPath: number[]; + openPath: number[]; + setOpenPath: (path: number[]) => void; + closeMenu: () => void; +}; + +type PreviewContextMenuItemProps = { + item: ContextMenuItem; + itemPath: number[]; + depth: number; + parentPath: number[]; + openPath: number[]; + setOpenPath: (path: number[]) => void; + closeMenu: () => void; +}; + +let previewContextMenuListener: ((state: PreviewContextMenuState) => void) | null = null; +const previewContextMenuItemIds = new WeakMap(); + +function makeVirtualElement(x: number, y: number): VirtualElement { + return { + getBoundingClientRect() { + return { + x, + y, + width: 0, + height: 0, + top: y, + right: x, + bottom: y, + left: x, + toJSON: () => ({}), + } as DOMRect; + }, + }; +} + +function isPathOpen(openPath: number[], path: number[]): boolean { + if (path.length > openPath.length) { + return false; + } + return path.every((segment, index) => openPath[index] === segment); +} + +function getVisibleItems(items: ContextMenuItem[]): ContextMenuItem[] { + return items.filter((item) => item.visible !== false); +} + +function activateItem(item: ContextMenuItem, closeMenu: () => void): void { + closeMenu(); + item.click?.(); +} + +function getPreviewContextMenuItemId(item: ContextMenuItem): string { + const existingId = previewContextMenuItemIds.get(item); + if (existingId != null) { + return existingId; + } + const newId = crypto.randomUUID(); + previewContextMenuItemIds.set(item, newId); + return newId; +} + +const PreviewContextMenuItem = memo( + ({ item, itemPath, depth, parentPath, openPath, setOpenPath, closeMenu }: PreviewContextMenuItemProps) => { + const rowRef = useRef(null); + const submenuItems = getVisibleItems(item.submenu ?? []); + const hasSubmenu = submenuItems.length > 0; + const isDisabled = item.enabled === false; + const isHeader = item.type === "header"; + const isSeparator = item.type === "separator"; + const isChecked = item.type === "checkbox" || item.type === "radio" ? item.checked === true : false; + const isSubmenuOpen = hasSubmenu && isPathOpen(openPath, itemPath); + + if (isSeparator) { + return
; + } + + const handleMouseEnter = () => { + if (hasSubmenu) { + setOpenPath(itemPath); + return; + } + setOpenPath(parentPath); + }; + + const handleClick = (e: React.MouseEvent) => { + e.stopPropagation(); + if (isDisabled || isHeader) { + return; + } + if (hasSubmenu) { + setOpenPath(itemPath); + return; + } + activateItem(item, closeMenu); + }; + + return ( + <> +
+ {isHeader ? ( + {item.label} + ) : ( + <> + + {isChecked ? : null} + +
+ {item.label} + {item.sublabel ? {item.sublabel} : null} +
+ {hasSubmenu ? ( + + + + ) : null} + + )} +
+ {hasSubmenu && isSubmenuOpen && rowRef.current != null ? ( + + ) : null} + + ); + } +); + +PreviewContextMenuItem.displayName = "PreviewContextMenuItem"; + +const PreviewContextMenuPanel = memo( + ({ items, point, referenceElement, placement, depth, parentPath, openPath, setOpenPath, closeMenu }: PreviewContextMenuPanelProps) => { + const visibleItems = getVisibleItems(items); + const virtualReference = useMemo(() => { + if (point == null) { + return null; + } + return makeVirtualElement(point.x, point.y); + }, [point]); + const { refs, floatingStyles } = useFloating({ + open: true, + placement, + strategy: "fixed", + whileElementsMounted: autoUpdate, + middleware: [ + offset(depth === 0 ? 4 : { mainAxis: -4, crossAxis: -4 }), + flip({ padding: 8 }), + shift({ padding: 8 }), + ], + }); + + useEffect(() => { + if (referenceElement != null) { + refs.setReference(referenceElement); + return; + } + refs.setPositionReference(virtualReference); + }, [referenceElement, refs, virtualReference]); + + if (visibleItems.length === 0) { + return null; + } + + return ( +
+ {visibleItems.map((item, index) => ( + + ))} +
+ ); + } +); + +PreviewContextMenuPanel.displayName = "PreviewContextMenuPanel"; + +export function showPreviewContextMenu(menu: ContextMenuItem[], e: React.MouseEvent): void { + e.stopPropagation(); + e.preventDefault(); + previewContextMenuListener?.({ + items: menu, + x: e.clientX, + y: e.clientY, + }); +} + +export const PreviewContextMenu = memo(() => { + const [menuState, setMenuState] = useState(null); + const [openPath, setOpenPath] = useState([]); + const portalRef = useRef(null); + + const closeMenu = () => { + setMenuState(null); + setOpenPath([]); + }; + + useEffect(() => { + previewContextMenuListener = (state) => { + setMenuState(state); + setOpenPath([]); + }; + return () => { + previewContextMenuListener = null; + }; + }, []); + + useEffect(() => { + if (menuState == null) { + return; + } + + const handlePointerDown = (event: PointerEvent) => { + if (portalRef.current?.contains(event.target as Node)) { + return; + } + closeMenu(); + }; + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === "Escape") { + closeMenu(); + } + }; + + document.addEventListener("pointerdown", handlePointerDown, true); + document.addEventListener("keydown", handleKeyDown); + window.addEventListener("blur", closeMenu); + window.addEventListener("resize", closeMenu); + window.addEventListener("scroll", closeMenu, true); + return () => { + document.removeEventListener("pointerdown", handlePointerDown, true); + document.removeEventListener("keydown", handleKeyDown); + window.removeEventListener("blur", closeMenu); + window.removeEventListener("resize", closeMenu); + window.removeEventListener("scroll", closeMenu, true); + }; + }, [menuState]); + + if (menuState == null) { + return null; + } + + return ( + +
+ +
+
+ ); +}); + +PreviewContextMenu.displayName = "PreviewContextMenu"; diff --git a/frontend/preview/preview.tsx b/frontend/preview/preview.tsx index e481ed351..9ec47366a 100644 --- a/frontend/preview/preview.tsx +++ b/frontend/preview/preview.tsx @@ -2,11 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 import Logo from "@/app/asset/logo.svg"; -import { setWaveWindowType } from "@/app/store/windowtype"; +import { ErrorBoundary } from "@/app/element/errorboundary"; +import { getAtoms, initGlobalAtoms } from "@/app/store/global-atoms"; +import { GlobalModel } from "@/app/store/global-model"; +import { globalStore } from "@/app/store/jotaiStore"; +import { WaveEnvContext } from "@/app/waveenv/waveenv"; import { loadFonts } from "@/util/fontutil"; -import React, { lazy, Suspense } from "react"; +import { atom, Provider } from "jotai"; +import React, { lazy, Suspense, useRef } from "react"; import { createRoot } from "react-dom/client"; +import { makeMockWaveEnv } from "./mock/mockwaveenv"; +import { installPreviewElectronApi } from "./mock/preview-electron-api"; +import { PreviewContextMenu } from "./preview-contextmenu"; +import "overlayscrollbars/overlayscrollbars.css"; import "../app/app.scss"; // preview.css should come *after* app.scss (don't remove the newline above otherwise prettier will reorder these imports) @@ -83,6 +92,28 @@ function PreviewHeader({ previewName }: { previewName: string }) { ); } +function PreviewRoot() { + const waveEnvRef = useRef( + makeMockWaveEnv({ + atoms: { + uiContext: atom({ windowid: PreviewWindowId, activetabid: PreviewTabId } as UIContext), + staticTabId: atom(PreviewTabId), + workspaceId: atom(PreviewWorkspaceId), + }, + }) + ); + return ( + + + <> + + + + + + ); +} + function PreviewApp() { const params = new URLSearchParams(window.location.search); const previewName = params.get("preview"); @@ -93,10 +124,12 @@ function PreviewApp() { return ( <> -
- - - +
+ + + + +
); @@ -117,11 +150,32 @@ function PreviewApp() { return ; } +const PreviewTabId = crypto.randomUUID(); +const PreviewWindowId = crypto.randomUUID(); +const PreviewWorkspaceId = crypto.randomUUID(); +const PreviewClientId = crypto.randomUUID(); + function initPreview() { - setWaveWindowType("preview"); + installPreviewElectronApi(); + const initOpts = { + tabId: PreviewTabId, + windowId: PreviewWindowId, + clientId: PreviewClientId, + environment: "renderer", + platform: "darwin", + isPreview: true, + } as GlobalInitOptions; + initGlobalAtoms(initOpts); + globalStore.set(getAtoms().fullConfigAtom, {} as FullConfigType); + GlobalModel.getInstance().initialize(initOpts); loadFonts(); - const root = createRoot(document.getElementById("main")!); - root.render(); + const container = document.getElementById("main")!; + let root = (container as any).__reactRoot; + if (!root) { + root = createRoot(container); + (container as any).__reactRoot = root; + } + root.render(); } initPreview(); diff --git a/frontend/preview/previews/aifilediff.preview-util.ts b/frontend/preview/previews/aifilediff.preview-util.ts new file mode 100644 index 000000000..b3a54c845 --- /dev/null +++ b/frontend/preview/previews/aifilediff.preview-util.ts @@ -0,0 +1,37 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { stringToBase64 } from "@/util/util"; + +export const DefaultAiFileDiffChatId = "preview-aifilediff-chat"; +export const DefaultAiFileDiffToolCallId = "preview-aifilediff-toolcall"; +export const DefaultAiFileDiffFileName = "src/lib/greeting.ts"; + +export const DefaultAiFileDiffOriginal = `export function greet(name: string) { + return "Hello " + name; +} + +export function greetAll(names: string[]) { + return names.map(greet).join("\\n"); +} +`; + +export const DefaultAiFileDiffModified = `export function greet(name: string) { + const normalizedName = name.trim() || "friend"; + return \`Hello, \${normalizedName}!\`; +} + +export function greetAll(names: string[]) { + return names.map(greet).join("\\n"); +} +`; + +export function makeMockAiFileDiffResponse( + original = DefaultAiFileDiffOriginal, + modified = DefaultAiFileDiffModified +): CommandWaveAIGetToolDiffRtnData { + return { + originalcontents64: stringToBase64(original), + modifiedcontents64: stringToBase64(modified), + }; +} diff --git a/frontend/preview/previews/aifilediff.preview.test.ts b/frontend/preview/previews/aifilediff.preview.test.ts new file mode 100644 index 000000000..633b9f188 --- /dev/null +++ b/frontend/preview/previews/aifilediff.preview.test.ts @@ -0,0 +1,26 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { base64ToString } from "@/util/util"; +import { describe, expect, it } from "vitest"; +import { + DefaultAiFileDiffModified, + DefaultAiFileDiffOriginal, + makeMockAiFileDiffResponse, +} from "./aifilediff.preview-util"; + +describe("aifilediff preview helpers", () => { + it("encodes the default diff content for the mock rpc response", () => { + const response = makeMockAiFileDiffResponse(); + + expect(base64ToString(response.originalcontents64)).toBe(DefaultAiFileDiffOriginal); + expect(base64ToString(response.modifiedcontents64)).toBe(DefaultAiFileDiffModified); + }); + + it("accepts custom original and modified content", () => { + const response = makeMockAiFileDiffResponse("before", "after"); + + expect(base64ToString(response.originalcontents64)).toBe("before"); + expect(base64ToString(response.modifiedcontents64)).toBe("after"); + }); +}); diff --git a/frontend/preview/previews/aifilediff.preview.tsx b/frontend/preview/previews/aifilediff.preview.tsx new file mode 100644 index 000000000..3cd012576 --- /dev/null +++ b/frontend/preview/previews/aifilediff.preview.tsx @@ -0,0 +1,145 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { Block } from "@/app/block/block"; +import { globalStore } from "@/app/store/jotaiStore"; +import { getTabModelByTabId, TabModelContext } from "@/app/store/tab-model"; +import { useWaveEnv, WaveEnvContext } from "@/app/waveenv/waveenv"; +import type { NodeModel } from "@/layout/index"; +import { atom } from "jotai"; +import * as React from "react"; +import { applyMockEnvOverrides, MockWaveEnv } from "../mock/mockwaveenv"; +import { + DefaultAiFileDiffChatId, + DefaultAiFileDiffFileName, + DefaultAiFileDiffToolCallId, + makeMockAiFileDiffResponse, +} from "./aifilediff.preview-util"; + +const PreviewWorkspaceId = "preview-aifilediff-workspace"; +const PreviewTabId = "preview-aifilediff-tab"; +const PreviewNodeId = "preview-aifilediff-node"; +const PreviewBlockId = "preview-aifilediff-block"; + +function makeMockWorkspace(): Workspace { + return { + otype: "workspace", + oid: PreviewWorkspaceId, + version: 1, + name: "Preview Workspace", + tabids: [PreviewTabId], + activetabid: PreviewTabId, + meta: {}, + } as Workspace; +} + +function makeMockTab(): Tab { + return { + otype: "tab", + oid: PreviewTabId, + version: 1, + name: "AI File Diff Preview", + blockids: [PreviewBlockId], + meta: {}, + } as Tab; +} + +function makeMockBlock(): Block { + return { + otype: "block", + oid: PreviewBlockId, + version: 1, + meta: { + view: "aifilediff", + file: DefaultAiFileDiffFileName, + "aifilediff:chatid": DefaultAiFileDiffChatId, + "aifilediff:toolcallid": DefaultAiFileDiffToolCallId, + }, + } as Block; +} + +function makePreviewNodeModel(): NodeModel { + const isFocusedAtom = atom(true); + const isMagnifiedAtom = atom(false); + + return { + additionalProps: atom({} as any), + innerRect: atom({ width: "1000px", height: "640px" }), + blockNum: atom(1), + numLeafs: atom(1), + nodeId: PreviewNodeId, + blockId: PreviewBlockId, + addEphemeralNodeToLayout: () => {}, + animationTimeS: atom(0), + isResizing: atom(false), + isFocused: isFocusedAtom, + isMagnified: isMagnifiedAtom, + anyMagnified: atom(false), + isEphemeral: atom(false), + ready: atom(true), + disablePointerEvents: atom(false), + toggleMagnify: () => { + globalStore.set(isMagnifiedAtom, !globalStore.get(isMagnifiedAtom)); + }, + focusNode: () => { + globalStore.set(isFocusedAtom, true); + }, + onClose: () => {}, + dragHandleRef: { current: null }, + displayContainerRef: { current: null }, + }; +} + +function AiFileDiffPreviewInner() { + const baseEnv = useWaveEnv(); + const nodeModel = React.useMemo(() => makePreviewNodeModel(), []); + + const env = React.useMemo(() => { + const mockWaveObjs: Record = { + [`workspace:${PreviewWorkspaceId}`]: makeMockWorkspace(), + [`tab:${PreviewTabId}`]: makeMockTab(), + [`block:${PreviewBlockId}`]: makeMockBlock(), + }; + + return applyMockEnvOverrides(baseEnv, { + tabId: PreviewTabId, + mockWaveObjs, + atoms: { + workspaceId: atom(PreviewWorkspaceId), + staticTabId: atom(PreviewTabId), + }, + rpc: { + WaveAIGetToolDiffCommand: async (_client, data) => { + if ( + data.chatid !== DefaultAiFileDiffChatId || + data.toolcallid !== DefaultAiFileDiffToolCallId + ) { + return null; + } + return makeMockAiFileDiffResponse(); + }, + }, + }); + }, [baseEnv]); + + const tabModel = React.useMemo(() => getTabModelByTabId(PreviewTabId, env), [env]); + + return ( + + +
+
full aifilediff block (mock WOS + mock WaveAI diff RPC)
+
+
+ +
+
+
+
+
+ ); +} + +export function AiFileDiffPreview() { + return ; +} diff --git a/frontend/preview/previews/onboarding.preview.tsx b/frontend/preview/previews/onboarding.preview.tsx new file mode 100644 index 000000000..063320bbb --- /dev/null +++ b/frontend/preview/previews/onboarding.preview.tsx @@ -0,0 +1,113 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import Logo from "@/app/asset/logo.svg"; +import { InitPage, NoTelemetryStarPage } from "@/app/onboarding/onboarding"; +import { OnboardingGradientBg } from "@/app/onboarding/onboarding-common"; +import { DurableSessionPage } from "@/app/onboarding/onboarding-durable"; +import { FilesPage, MagnifyBlocksPage, WaveAIPage } from "@/app/onboarding/onboarding-features"; +import { StarAskPage } from "@/app/onboarding/onboarding-starask"; +import { UpgradeMinorWelcomePage } from "@/app/onboarding/onboarding-upgrade-minor"; +import { UpgradeOnboardingFooter, UpgradeOnboardingVersions } from "@/app/onboarding/onboarding-upgrade-patch"; + +function OnboardingModalWrapper({ width, children }: { width: string; children: React.ReactNode }) { + return ( +
+ +
{children}
+
+ ); +} + +function OnboardingFeaturesV() { + const noop = () => {}; + return ( +
+ + {}} /> + + + + + + + + + + + + + + + + +
+ ); +} + +function UpgradeOnboardingPatchV() { + const noop = () => {}; + return ( +
+ {UpgradeOnboardingVersions.map((version, idx) => { + const hasPrev = idx > 0; + const hasNext = idx < UpgradeOnboardingVersions.length - 1; + return ( + +
+
+ +
+
+ Wave {version.version} Update +
+
+
{version.content()}
+ +
+ ); + })} +
+ ); +} + +function UpgradeOnboardingMinorV() { + const noop = () => {}; + return ( + + + + ); +} + +function StarAskV() { + const noop = () => {}; + return ( + + + + ); +} + +export function OnboardingPreview() { + return ( +
+
Onboarding features
+ +
Onboarding minor upgrade
+ +
Onboarding star ask
+ +
Onboarding patch updates
+ +
+ ); +} diff --git a/frontend/preview/previews/sysinfo.preview-util.ts b/frontend/preview/previews/sysinfo.preview-util.ts new file mode 100644 index 000000000..b577d8607 --- /dev/null +++ b/frontend/preview/previews/sysinfo.preview-util.ts @@ -0,0 +1,61 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +export const DefaultSysinfoHistoryPoints = 140; +export const MockSysinfoConnection = "local"; + +const MockMemoryTotal = 32; +const MockCoreCount = 6; + +function clamp(value: number, minValue: number, maxValue: number): number { + return Math.min(maxValue, Math.max(minValue, value)); +} + +function round1(value: number): number { + return Math.round(value * 10) / 10; +} + +export function makeMockSysinfoEvent( + ts: number, + step: number, + scope = MockSysinfoConnection +): Extract { + const baseCpu = clamp(42 + 18 * Math.sin(step / 6) + 8 * Math.cos(step / 3.5), 8, 96); + const memUsed = clamp(12 + 4 * Math.sin(step / 10) + 2 * Math.cos(step / 7), 6, MockMemoryTotal - 4); + const memAvailable = clamp(MockMemoryTotal - memUsed + 1.5, 0, MockMemoryTotal); + const values: Record = { + cpu: round1(baseCpu), + "mem:total": MockMemoryTotal, + "mem:used": round1(memUsed), + "mem:free": round1(MockMemoryTotal - memUsed), + "mem:available": round1(memAvailable), + }; + + for (let i = 0; i < MockCoreCount; i++) { + const coreCpu = clamp(baseCpu + 10 * Math.sin(step / 4 + i) + i - 3, 2, 100); + values[`cpu:${i}`] = round1(coreCpu); + } + + return { + event: "sysinfo", + scopes: [scope], + data: { + ts, + values, + }, + }; +} + +export function makeMockSysinfoHistory( + numPoints = DefaultSysinfoHistoryPoints, + endTs = Date.now() +): Extract[] { + const history: Extract[] = []; + const startTs = endTs - (numPoints - 1) * 1000; + + for (let i = 0; i < numPoints; i++) { + history.push(makeMockSysinfoEvent(startTs + i * 1000, i)); + } + + return history; +} diff --git a/frontend/preview/previews/sysinfo.preview.test.ts b/frontend/preview/previews/sysinfo.preview.test.ts new file mode 100644 index 000000000..6e696ea2a --- /dev/null +++ b/frontend/preview/previews/sysinfo.preview.test.ts @@ -0,0 +1,31 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, it } from "vitest"; +import { DefaultSysinfoHistoryPoints, makeMockSysinfoEvent, makeMockSysinfoHistory } from "./sysinfo.preview-util"; + +describe("sysinfo preview helpers", () => { + it("creates sysinfo events with the expected metrics", () => { + const event = makeMockSysinfoEvent(1000, 3); + + expect(event.event).toBe("sysinfo"); + expect(event.scopes).toEqual(["local"]); + expect(event.data.ts).toBe(1000); + expect(event.data.values.cpu).toBeGreaterThanOrEqual(0); + expect(event.data.values.cpu).toBeLessThanOrEqual(100); + expect(event.data.values["mem:used"]).toBeGreaterThan(0); + expect(event.data.values["mem:total"]).toBeGreaterThan(event.data.values["mem:used"]); + expect(event.data.values["cpu:0"]).toBeTypeOf("number"); + }); + + it("creates evenly spaced sysinfo history", () => { + const history = makeMockSysinfoHistory(4, 4000); + + expect(history).toHaveLength(4); + expect(history.map((event) => event.data.ts)).toEqual([1000, 2000, 3000, 4000]); + }); + + it("uses the default history length", () => { + expect(makeMockSysinfoHistory()).toHaveLength(DefaultSysinfoHistoryPoints); + }); +}); diff --git a/frontend/preview/previews/sysinfo.preview.tsx b/frontend/preview/previews/sysinfo.preview.tsx new file mode 100644 index 000000000..ee4fadb9e --- /dev/null +++ b/frontend/preview/previews/sysinfo.preview.tsx @@ -0,0 +1,161 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { Block } from "@/app/block/block"; +import { globalStore } from "@/app/store/jotaiStore"; +import { getTabModelByTabId, TabModelContext } from "@/app/store/tab-model"; +import { handleWaveEvent } from "@/app/store/wps"; +import { useWaveEnv, WaveEnvContext } from "@/app/waveenv/waveenv"; +import type { NodeModel } from "@/layout/index"; +import { atom } from "jotai"; +import * as React from "react"; +import { applyMockEnvOverrides, MockWaveEnv } from "../mock/mockwaveenv"; +import { + DefaultSysinfoHistoryPoints, + makeMockSysinfoEvent, + makeMockSysinfoHistory, + MockSysinfoConnection, +} from "./sysinfo.preview-util"; + +const PreviewWorkspaceId = "preview-sysinfo-workspace"; +const PreviewTabId = "preview-sysinfo-tab"; +const PreviewNodeId = "preview-sysinfo-node"; +const PreviewBlockId = "preview-sysinfo-block"; + +function makeMockWorkspace(): Workspace { + return { + otype: "workspace", + oid: PreviewWorkspaceId, + version: 1, + name: "Preview Workspace", + tabids: [PreviewTabId], + activetabid: PreviewTabId, + meta: {}, + } as Workspace; +} + +function makeMockTab(): Tab { + return { + otype: "tab", + oid: PreviewTabId, + version: 1, + name: "Sysinfo Preview", + blockids: [PreviewBlockId], + meta: {}, + } as Tab; +} + +function makeMockBlock(): Block { + return { + otype: "block", + oid: PreviewBlockId, + version: 1, + meta: { + view: "sysinfo", + connection: MockSysinfoConnection, + "sysinfo:type": "CPU + Mem", + "graph:numpoints": 90, + }, + } as Block; +} + +function makePreviewNodeModel(): NodeModel { + const isFocusedAtom = atom(true); + const isMagnifiedAtom = atom(false); + + return { + additionalProps: atom({} as any), + innerRect: atom({ width: "920px", height: "560px" }), + blockNum: atom(1), + numLeafs: atom(2), + nodeId: PreviewNodeId, + blockId: PreviewBlockId, + addEphemeralNodeToLayout: () => {}, + animationTimeS: atom(0), + isResizing: atom(false), + isFocused: isFocusedAtom, + isMagnified: isMagnifiedAtom, + anyMagnified: atom(false), + isEphemeral: atom(false), + ready: atom(true), + disablePointerEvents: atom(false), + toggleMagnify: () => { + globalStore.set(isMagnifiedAtom, !globalStore.get(isMagnifiedAtom)); + }, + focusNode: () => { + globalStore.set(isFocusedAtom, true); + }, + onClose: () => {}, + dragHandleRef: { current: null }, + displayContainerRef: { current: null }, + }; +} + +function SysinfoPreviewInner() { + const baseEnv = useWaveEnv(); + const historyRef = React.useRef(makeMockSysinfoHistory()); + const nodeModel = React.useMemo(() => makePreviewNodeModel(), []); + + const env = React.useMemo(() => { + const mockWaveObjs: Record = { + [`workspace:${PreviewWorkspaceId}`]: makeMockWorkspace(), + [`tab:${PreviewTabId}`]: makeMockTab(), + [`block:${PreviewBlockId}`]: makeMockBlock(), + }; + + return applyMockEnvOverrides(baseEnv, { + tabId: PreviewTabId, + mockWaveObjs, + atoms: { + workspaceId: atom(PreviewWorkspaceId), + staticTabId: atom(PreviewTabId), + }, + rpc: { + EventReadHistoryCommand: async (_client, data) => { + if (data.event !== "sysinfo" || data.scope !== MockSysinfoConnection) { + return []; + } + const maxItems = data.maxitems ?? historyRef.current.length; + return historyRef.current.slice(-maxItems); + }, + }, + }); + }, [baseEnv]); + + const tabModel = React.useMemo(() => getTabModelByTabId(PreviewTabId, env), [env]); + + React.useEffect(() => { + let nextStep = historyRef.current.length; + let nextTs = (historyRef.current[historyRef.current.length - 1]?.data?.ts ?? Date.now()) + 1000; + const intervalId = window.setInterval(() => { + const nextEvent = makeMockSysinfoEvent(nextTs, nextStep); + historyRef.current = [...historyRef.current.slice(-(DefaultSysinfoHistoryPoints - 1)), nextEvent]; + handleWaveEvent(nextEvent); + nextStep++; + nextTs += 1000; + }, 1000); + + return () => { + window.clearInterval(intervalId); + }; + }, []); + + return ( + + +
+
full sysinfo block (mock WOS + FE-only WPS events)
+
+
+ +
+
+
+
+
+ ); +} + +export default function SysinfoPreview() { + return ; +} diff --git a/frontend/preview/previews/tab.preview.tsx b/frontend/preview/previews/tab.preview.tsx index 8be52ec77..11c888254 100644 --- a/frontend/preview/previews/tab.preview.tsx +++ b/frontend/preview/previews/tab.preview.tsx @@ -11,22 +11,57 @@ interface PreviewTabEntry { tabId: string; tabName: string; active: boolean; - isBeforeActive: boolean; + badges?: Badge[] | null; + flagColor?: string | null; } const tabDefs: PreviewTabEntry[] = [ - { tabId: "preview-tab-1", tabName: "Terminal", active: false, isBeforeActive: true }, - { tabId: "preview-tab-2", tabName: "My Tab", active: true, isBeforeActive: false }, - { tabId: "preview-tab-3", tabName: "T3", active: false, isBeforeActive: false }, + { tabId: "preview-tab-1", tabName: "Terminal", active: false }, + { + tabId: "preview-tab-2", + tabName: "My Tab", + active: true, + badges: [ + { badgeid: "b2", icon: "circle-check", color: "#4ade80", priority: 3 }, + { badgeid: "b1", icon: "circle-small", color: "#fbbf24", priority: 1 }, + { badgeid: "b3", icon: "circle-small", color: "red", priority: 1 }, + ], + }, + { + tabId: "preview-tab-2b", + tabName: "My Tab 2", + active: false, + badges: [ + { badgeid: "b2", icon: "bell", color: "#4ade80", priority: 3 }, + { badgeid: "b1", icon: "circle-small", color: "red", priority: 1 }, + ], + }, + { tabId: "preview-tab-3", tabName: "T3", active: false, flagColor: "#4ade80" }, + { + tabId: "preview-tab-4", + tabName: "1 Badge", + active: false, + badges: [{ badgeid: "b1", icon: "circle-small", color: "#fbbf24", priority: 1 }], + flagColor: "#fbbf24", + }, + { + tabId: "preview-tab-5", + tabName: "3 Badges", + active: false, + badges: [ + { badgeid: "b1", icon: "circle-small", color: "#fbbf24", priority: 1 }, + { badgeid: "b2", icon: "circle-check", color: "#4ade80", priority: 3 }, + { badgeid: "b3", icon: "triangle-exclamation", color: "#f87171", priority: 2 }, + { badgeid: "b4", icon: "bell", color: "#f87171", priority: 2 }, + ], + }, ]; export function TabPreview() { const [tabNames, setTabNames] = useState>( Object.fromEntries(tabDefs.map((t) => [t.tabId, t.tabName])) ); - const [activeTabId, setActiveTabId] = useState( - tabDefs.find((t) => t.active)?.tabId ?? tabDefs[0].tabId - ); + const [activeTabId, setActiveTabId] = useState(tabDefs.find((t) => t.active)?.tabId ?? tabDefs[0].tabId); const tabRefs = useRef>({}); // The real tabbar imperatively sets opacity: 1 and transform after calculating @@ -46,30 +81,31 @@ export function TabPreview() { {tabDefs.map((tab, index) => { const activeIndex = tabDefs.findIndex((t) => t.tabId === activeTabId); const isActive = tab.tabId === activeTabId; - const isBeforeActive = index === activeIndex - 1; + const showDivider = index !== 0 && !isActive && index !== activeIndex + 1; return ( - { - tabRefs.current[tab.tabId] = el; - }} - tabId={tab.tabId} - tabName={tabNames[tab.tabId]} - active={isActive} - isBeforeActive={isBeforeActive} - isDragging={false} - tabWidth={TAB_WIDTH} - isNew={false} - indicator={null} - onClick={() => setActiveTabId(tab.tabId)} - onClose={() => console.log("close", tab.tabId)} - onDragStart={() => {}} - onContextMenu={() => {}} - onRename={(newName) => { - console.log("rename", tab.tabId, newName); - setTabNames((prev) => ({ ...prev, [tab.tabId]: newName })); - }} - /> + { + tabRefs.current[tab.tabId] = el; + }} + tabId={tab.tabId} + tabName={tabNames[tab.tabId]} + active={isActive} + showDivider={showDivider} + isDragging={false} + tabWidth={TAB_WIDTH} + isNew={false} + badges={tab.badges ?? null} + flagColor={tab.flagColor ?? null} + onClick={() => setActiveTabId(tab.tabId)} + onClose={() => console.log("close", tab.tabId)} + onDragStart={() => {}} + onContextMenu={() => {}} + onRename={(newName) => { + console.log("rename", tab.tabId, newName); + setTabNames((prev) => ({ ...prev, [tab.tabId]: newName })); + }} + /> ); })}
diff --git a/frontend/preview/previews/tabbar.preview.tsx b/frontend/preview/previews/tabbar.preview.tsx new file mode 100644 index 000000000..f2ba2234b --- /dev/null +++ b/frontend/preview/previews/tabbar.preview.tsx @@ -0,0 +1,161 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { loadBadges, LoadBadgesEnv } from "@/app/store/badge"; +import { TabBar } from "@/app/tab/tabbar"; +import { TabBarEnv } from "@/app/tab/tabbarenv"; +import { useWaveEnv, WaveEnvContext } from "@/app/waveenv/waveenv"; +import { makeTabBarMockEnv, TabBarMockWorkspaceId } from "@/preview/mock/tabbar-mock"; +import { MockWaveEnv } from "@/preview/mock/mockwaveenv"; +import { PlatformLinux, PlatformMacOS, PlatformWindows } from "@/util/platformutil"; +import { useAtom, useAtomValue } from "jotai"; +import { CSSProperties, useEffect, useMemo, useRef, useState } from "react"; + +const MockConfigErrors: ConfigError[] = [ + { file: "~/.waveterm/config.json", err: 'unknown preset "bg@aurora"' }, + { file: "~/.waveterm/settings.json", err: "invalid color for tab theme" }, +]; + +export function TabBarPreview() { + const baseEnv = useWaveEnv(); + const envRef = useRef(null); + const [platform, setPlatform] = useState(PlatformMacOS); + + const tabEnv = useMemo(() => makeTabBarMockEnv(baseEnv, envRef, platform), [platform]); + + return ( + + + + ); +} + +type TabBarPreviewInnerProps = { + platform: NodeJS.Platform; + setPlatform: (platform: NodeJS.Platform) => void; +}; + +function TabBarPreviewInner({ platform, setPlatform }: TabBarPreviewInnerProps) { + const env = useWaveEnv(); + const loadBadgesEnv = useWaveEnv(); + const [showConfigErrors, setShowConfigErrors] = useState(false); + const [hideAiButton, setHideAiButton] = useState(false); + const [showMenuBar, setShowMenuBar] = useState(false); + const [isFullScreen, setIsFullScreen] = useAtom(env.atoms.isFullScreen); + const [zoomFactor, setZoomFactor] = useAtom(env.atoms.zoomFactorAtom); + const [fullConfig, setFullConfig] = useAtom(env.atoms.fullConfigAtom); + const [updaterStatus, setUpdaterStatus] = useAtom(env.atoms.updaterStatusAtom); + const workspace = useAtomValue(env.wos.getWaveObjectAtom(`workspace:${TabBarMockWorkspaceId}`)); + + useEffect(() => { + loadBadges(loadBadgesEnv); + }, []); + + useEffect(() => { + setFullConfig((prev) => ({ + ...(prev ?? ({} as FullConfigType)), + settings: { + ...(prev?.settings ?? {}), + "app:hideaibutton": hideAiButton, + "window:showmenubar": showMenuBar, + }, + configerrors: showConfigErrors ? MockConfigErrors : [], + })); + }, [hideAiButton, showMenuBar, setFullConfig, showConfigErrors]); + + return ( +
+
+ + + + + + + +
+ Double-click a tab name to rename it. Close/add buttons and drag reordering are fully functional. +
+
+ +
0 ? 1 / zoomFactor : 1 } as CSSProperties} + > + {workspace != null && } +
+ +
+ Tabs: {workspace?.tabids?.length ?? 0} · Config errors: {fullConfig?.configerrors?.length ?? 0} +
+
+ ); +} +TabBarPreviewInner.displayName = "TabBarPreviewInner"; diff --git a/frontend/preview/previews/treeview.preview.tsx b/frontend/preview/previews/treeview.preview.tsx new file mode 100644 index 000000000..65043ddda --- /dev/null +++ b/frontend/preview/previews/treeview.preview.tsx @@ -0,0 +1,97 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { TreeNodeData, TreeView } from "@/app/treeview/treeview"; +import { useMemo, useState } from "react"; + +const RootId = "workspace:/"; +const RootNode: TreeNodeData = { + id: RootId, + path: RootId, + label: "workspace", + isDirectory: true, + childrenStatus: "unloaded", +}; + +const DirectoryData: Record = { + [RootId]: [ + { id: "workspace:/src", path: "workspace:/src", label: "src", parentId: RootId, isDirectory: true }, + { id: "workspace:/docs", path: "workspace:/docs", label: "docs", parentId: RootId, isDirectory: true }, + { id: "workspace:/README.md", path: "workspace:/README.md", label: "README.md", parentId: RootId, isDirectory: false, mimeType: "text/markdown" }, + { id: "workspace:/package.json", path: "workspace:/package.json", label: "package.json", parentId: RootId, isDirectory: false, mimeType: "application/json" }, + ], + "workspace:/src": [ + { id: "workspace:/src/app", path: "workspace:/src/app", label: "app", parentId: "workspace:/src", isDirectory: true }, + { id: "workspace:/src/styles", path: "workspace:/src/styles", label: "styles", parentId: "workspace:/src", isDirectory: true }, + ...Array.from({ length: 200 }).map((_, idx) => ({ + id: `workspace:/src/file-${idx.toString().padStart(3, "0")}.tsx`, + path: `workspace:/src/file-${idx.toString().padStart(3, "0")}.tsx`, + label: `file-${idx.toString().padStart(3, "0")}.tsx`, + parentId: "workspace:/src", + isDirectory: false, + mimeType: "text/typescript", + })), + ], + "workspace:/src/app": [ + { id: "workspace:/src/app/main.tsx", path: "workspace:/src/app/main.tsx", label: "main.tsx", parentId: "workspace:/src/app", isDirectory: false, mimeType: "text/typescript" }, + { id: "workspace:/src/app/router.ts", path: "workspace:/src/app/router.ts", label: "router.ts", parentId: "workspace:/src/app", isDirectory: false, mimeType: "text/typescript" }, + ], + "workspace:/src/styles": [ + { id: "workspace:/src/styles/app.css", path: "workspace:/src/styles/app.css", label: "app.css", parentId: "workspace:/src/styles", isDirectory: false, mimeType: "text/css" }, + ], + "workspace:/docs": Array.from({ length: 25 }).map((_, idx) => ({ + id: `workspace:/docs/page-${idx + 1}.md`, + path: `workspace:/docs/page-${idx + 1}.md`, + label: `page-${idx + 1}.md`, + parentId: "workspace:/docs", + isDirectory: false, + mimeType: "text/markdown", + })), +}; + +export function TreeViewPreview() { + const [width, setWidth] = useState(260); + const [selection, setSelection] = useState(RootId); + const initialNodes = useMemo(() => ({ [RootId]: RootNode }), []); + + return ( +
+
+
Tree width: {width}px
+ setWidth(Number(event.target.value))} + className="mt-2 w-full cursor-pointer" + /> +
Selection: {selection}
+
+ { + await new Promise((resolve) => setTimeout(resolve, 220)); + const entries = DirectoryData[id] ?? []; + return { + nodes: entries.slice(0, limit), + capped: entries.length > limit, + totalKnown: entries.length, + }; + }} + onOpenFile={(id) => { + setSelection(`open:${id}`); + }} + onSelectionChange={(id) => { + setSelection(id); + }} + /> +
+ ); +} diff --git a/frontend/preview/previews/vtabbar.preview.tsx b/frontend/preview/previews/vtabbar.preview.tsx new file mode 100644 index 000000000..90b7907be --- /dev/null +++ b/frontend/preview/previews/vtabbar.preview.tsx @@ -0,0 +1,128 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { loadBadges, LoadBadgesEnv } from "@/app/store/badge"; +import { VTabBar } from "@/app/tab/vtabbar"; +import { VTabBarEnv } from "@/app/tab/vtabbarenv"; +import { useWaveEnv, WaveEnvContext } from "@/app/waveenv/waveenv"; +import { MockWaveEnv } from "@/preview/mock/mockwaveenv"; +import { makeTabBarMockEnv, TabBarMockWorkspaceId } from "@/preview/mock/tabbar-mock"; +import { PlatformLinux, PlatformMacOS, PlatformWindows } from "@/util/platformutil"; +import { useAtom, useAtomValue } from "jotai"; +import { useEffect, useMemo, useRef, useState } from "react"; + +export function VTabBarPreview() { + const baseEnv = useWaveEnv(); + const envRef = useRef(null); + const [platform, setPlatform] = useState(PlatformMacOS); + + const tabEnv = useMemo(() => makeTabBarMockEnv(baseEnv, envRef, platform), [platform]); + + return ( + + + + ); +} + +type VTabBarPreviewInnerProps = { + platform: NodeJS.Platform; + setPlatform: (platform: NodeJS.Platform) => void; +}; + +function VTabBarPreviewInner({ platform, setPlatform }: VTabBarPreviewInnerProps) { + const env = useWaveEnv(); + const loadBadgesEnv = useWaveEnv(); + const [hideAiButton, setHideAiButton] = useState(false); + const [isFullScreen, setIsFullScreen] = useAtom(env.atoms.isFullScreen); + const [fullConfig, setFullConfig] = useAtom(env.atoms.fullConfigAtom); + const [updaterStatus, setUpdaterStatus] = useAtom(env.atoms.updaterStatusAtom); + const [width, setWidth] = useState(220); + const workspace = useAtomValue(env.wos.getWaveObjectAtom(`workspace:${TabBarMockWorkspaceId}`)); + + useEffect(() => { + loadBadges(loadBadgesEnv); + }, []); + + useEffect(() => { + setFullConfig((prev) => ({ + ...(prev ?? ({} as FullConfigType)), + settings: { + ...(prev?.settings ?? {}), + "app:hideaibutton": hideAiButton, + }, + })); + }, [hideAiButton, setFullConfig]); + + return ( +
+
+ + + + + +
+ +
+
+ {workspace != null && } +
+
+
+ ); +} +VTabBarPreviewInner.displayName = "VTabBarPreviewInner"; diff --git a/frontend/preview/previews/web.preview.tsx b/frontend/preview/previews/web.preview.tsx new file mode 100644 index 000000000..56f9c215a --- /dev/null +++ b/frontend/preview/previews/web.preview.tsx @@ -0,0 +1,135 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { Block } from "@/app/block/block"; +import { globalStore } from "@/app/store/jotaiStore"; +import { getTabModelByTabId, TabModelContext } from "@/app/store/tab-model"; +import { mockObjectForPreview } from "@/app/store/wos"; +import { useWaveEnv, WaveEnvContext } from "@/app/waveenv/waveenv"; +import type { NodeModel } from "@/layout/index"; +import { atom } from "jotai"; +import * as React from "react"; +import { applyMockEnvOverrides, MockWaveEnv } from "../mock/mockwaveenv"; + +const PreviewWorkspaceId = "preview-web-workspace"; +const PreviewTabId = "preview-web-tab"; +const PreviewNodeId = "preview-web-node"; +const PreviewBlockId = "preview-web-block"; +const PreviewUrl = "https://waveterm.dev"; + +function makeMockWorkspace(): Workspace { + return { + otype: "workspace", + oid: PreviewWorkspaceId, + version: 1, + name: "Preview Workspace", + tabids: [PreviewTabId], + activetabid: PreviewTabId, + meta: {}, + } as Workspace; +} + +function makeMockTab(): Tab { + return { + otype: "tab", + oid: PreviewTabId, + version: 1, + name: "Web Preview", + blockids: [PreviewBlockId], + meta: {}, + } as Tab; +} + +function makeMockBlock(): Block { + return { + otype: "block", + oid: PreviewBlockId, + version: 1, + meta: { + view: "web", + url: PreviewUrl, + }, + } as Block; +} + +const previewWaveObjs: Record = { + [`workspace:${PreviewWorkspaceId}`]: makeMockWorkspace(), + [`tab:${PreviewTabId}`]: makeMockTab(), + [`block:${PreviewBlockId}`]: makeMockBlock(), +}; + +for (const [oref, obj] of Object.entries(previewWaveObjs)) { + mockObjectForPreview(oref, obj); +} + +function makePreviewNodeModel(): NodeModel { + const isFocusedAtom = atom(true); + const isMagnifiedAtom = atom(false); + + return { + additionalProps: atom({} as any), + innerRect: atom({ width: "1040px", height: "620px" }), + blockNum: atom(1), + numLeafs: atom(1), + nodeId: PreviewNodeId, + blockId: PreviewBlockId, + addEphemeralNodeToLayout: () => {}, + animationTimeS: atom(0), + isResizing: atom(false), + isFocused: isFocusedAtom, + isMagnified: isMagnifiedAtom, + anyMagnified: atom(false), + isEphemeral: atom(false), + ready: atom(true), + disablePointerEvents: atom(false), + toggleMagnify: () => { + globalStore.set(isMagnifiedAtom, !globalStore.get(isMagnifiedAtom)); + }, + focusNode: () => { + globalStore.set(isFocusedAtom, true); + }, + onClose: () => {}, + dragHandleRef: { current: null }, + displayContainerRef: { current: null }, + }; +} + +function WebPreviewInner() { + const baseEnv = useWaveEnv(); + const nodeModel = React.useMemo(() => makePreviewNodeModel(), []); + + const env = React.useMemo(() => { + return applyMockEnvOverrides(baseEnv, { + tabId: PreviewTabId, + mockWaveObjs: previewWaveObjs, + atoms: { + workspaceId: atom(PreviewWorkspaceId), + staticTabId: atom(PreviewTabId), + }, + settings: { + "web:defaultsearch": "https://www.google.com/search?q=%s", + }, + }); + }, [baseEnv]); + + const tabModel = React.useMemo(() => getTabModelByTabId(PreviewTabId, env), [env]); + + return ( + + +
+
full web block using preview mock fallback
+
+
+ +
+
+
+
+
+ ); +} + +export function WebPreview() { + return ; +} diff --git a/frontend/preview/previews/widgets.preview.tsx b/frontend/preview/previews/widgets.preview.tsx new file mode 100644 index 000000000..440ae03a6 --- /dev/null +++ b/frontend/preview/previews/widgets.preview.tsx @@ -0,0 +1,236 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { useWaveEnv, WaveEnv, WaveEnvContext } from "@/app/waveenv/waveenv"; +import { Widgets } from "@/app/workspace/widgets"; +import { atom, useAtom, useAtomValue } from "jotai"; +import { useRef } from "react"; +import { applyMockEnvOverrides } from "../mock/mockwaveenv"; + +const resizableHeightAtom = atom(250); +const hasConfigErrorsAtom = atom(false); +const isDevAtom = atom(true); +const mockVersionAtom = atom(0); + +function makeMockApp(name: string, icon: string, iconcolor: string): AppInfo { + return { + appid: `local/${name.toLowerCase().replace(/\s+/g, "-")}`, + modtime: 0, + manifest: { + appmeta: { title: name, shortdesc: "", icon, iconcolor }, + configschema: {}, + dataschema: {}, + secrets: {}, + }, + }; +} + +const mockApps: AppInfo[] = [ + makeMockApp("Weather", "cloud-sun", "#60a5fa"), + makeMockApp("Stocks", "chart-line", "#34d399"), + makeMockApp("Notes", "note-sticky", "#fbbf24"), + makeMockApp("Pomodoro", "clock", "#f87171"), + makeMockApp("GitHub PRs", "code-pull-request", "#a78bfa"), + makeMockApp("Server Monitor", "server", "#4ade80"), +]; + +const mockWidgets: { [key: string]: WidgetConfigType } = { + "defwidget@term": { + icon: "terminal", + color: "#4ade80", + label: "Terminal", + description: "Open a terminal", + "display:order": 0, + blockdef: { meta: { view: "term", controller: "shell" } }, + }, + "defwidget@editor": { + icon: "code", + color: "#60a5fa", + label: "Editor", + description: "Open a code editor", + "display:order": 1, + blockdef: { meta: { view: "codeeditor" } }, + }, + "defwidget@web": { + icon: "globe", + color: "#f472b6", + label: "Web", + description: "Open a web browser", + "display:order": 2, + blockdef: { meta: { view: "web", url: "https://waveterm.dev" } }, + }, + "defwidget@ai": { + icon: "sparkles", + color: "#a78bfa", + label: "AI", + description: "Open Wave AI", + "display:order": 3, + blockdef: { meta: { view: "waveai" } }, + }, + "defwidget@files": { + icon: "folder", + color: "#fbbf24", + label: "Files", + description: "Open file browser", + "display:order": 4, + blockdef: { meta: { view: "preview", connection: "local" } }, + }, + "defwidget@sysinfo": { + icon: "chart-line", + color: "#34d399", + label: "Sysinfo", + description: "Open system info", + "display:order": 5, + blockdef: { meta: { view: "sysinfo" } }, + }, +}; + +const fullConfigAtom = atom({ settings: {}, widgets: mockWidgets } as unknown as FullConfigType); + +function makeWidgetsEnv( + baseEnv: WaveEnv, + isDev: boolean, + hasCustomAIPresets: boolean, + apps?: AppInfo[], + atomOverrides?: Partial +) { + return applyMockEnvOverrides(baseEnv, { + isDev, + rpc: { ListAllAppsCommand: () => Promise.resolve(apps ?? []) }, + atoms: { + fullConfigAtom, + hasCustomAIPresetsAtom: atom(hasCustomAIPresets), + ...atomOverrides, + }, + }); +} + +function WidgetsScenario({ + label, + isDev = false, + hasCustomAIPresets = true, + height, + apps, +}: { + label: string; + isDev?: boolean; + hasCustomAIPresets?: boolean; + height?: number; + apps?: AppInfo[]; +}) { + const baseEnv = useWaveEnv(); + const envRef = useRef(null); + if (envRef.current == null) { + envRef.current = makeWidgetsEnv(baseEnv, isDev, hasCustomAIPresets, apps, { + hasConfigErrors: hasConfigErrorsAtom, + }); + } + + return ( +
+
{label}
+ +
+
+
+
+ +
+ +
+ ); +} + +function WidgetsResizable({ isDev }: { isDev: boolean }) { + const [height, setHeight] = useAtom(resizableHeightAtom); + const baseEnv = useWaveEnv(); + const envRef = useRef(null); + if (envRef.current == null) { + envRef.current = makeWidgetsEnv(baseEnv, isDev, true, mockApps, { hasConfigErrors: hasConfigErrorsAtom }); + } + + return ( +
+
+ compact/supercompact — resizable (height: {height}px) + setHeight(Number(e.target.value))} + className="cursor-pointer" + /> +
+ +
+
+
+
+ +
+ +
+ ); +} + +function PreviewControls() { + const [hasConfigErrors, setHasConfigErrors] = useAtom(hasConfigErrorsAtom); + const [isDev, setIsDev] = useAtom(isDevAtom); + const [, setMockVersion] = useAtom(mockVersionAtom); + + function applyAndBump(fn: () => void) { + fn(); + setMockVersion((v) => v + 1); + } + + return ( +
+ preview controls: + + +
+ ); +} + +export function WidgetsPreview() { + const isDev = useAtomValue(isDevAtom); + const mockVersion = useAtomValue(mockVersionAtom); + + return ( +
+ +
+
+ + + + +
+ +
+
+ ); +} diff --git a/frontend/preview/vite.config.ts b/frontend/preview/vite.config.ts index b42363aeb..8856c61b1 100644 --- a/frontend/preview/vite.config.ts +++ b/frontend/preview/vite.config.ts @@ -23,6 +23,9 @@ export default defineConfig({ react(), tailwindcss(), ], + build: { + minify: false, + }, server: { port: 7007, }, diff --git a/frontend/tailwindsetup.css b/frontend/tailwindsetup.css index b9f193382..ffe6ed471 100644 --- a/frontend/tailwindsetup.css +++ b/frontend/tailwindsetup.css @@ -1,7 +1,8 @@ -/* Copyright 2025, Command Line Inc. +/* Copyright 2026, Command Line Inc. SPDX-License-Identifier: Apache-2.0 */ @import "tailwindcss"; + @source "../node_modules/streamdown/dist/index.js"; @theme { @@ -75,6 +76,13 @@ --z-window-drag: 100; } +/* Applied when body.nohover is set — used to suppress hover effects during tab remount to prevent ghost-hover flicker */ +@custom-variant nohover { + body.nohover & { + @slot; + } +} + :root { --zoomfactor: 1; --zoomfactor-inv: 1; diff --git a/frontend/types/custom.d.ts b/frontend/types/custom.d.ts index 74180391c..9f7cb15ad 100644 --- a/frontend/types/custom.d.ts +++ b/frontend/types/custom.d.ts @@ -1,6 +1,7 @@ // Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 +import type { WaveEnv } from "@/app/waveenv/waveenv"; import { type Placement } from "@floating-ui/react"; import type * as jotai from "jotai"; import type * as rxjs from "rxjs"; @@ -10,11 +11,13 @@ declare global { builderId: jotai.Atom; // readonly (for builder mode) builderAppId: jotai.PrimitiveAtom; // app being edited in builder mode uiContext: jotai.Atom; // driven from windowId, tabId - workspace: jotai.Atom; // driven from WOS + workspaceId: jotai.Atom; // derived from window WOS object + workspace: jotai.Atom; // driven from workspaceId via WOS fullConfigAtom: jotai.PrimitiveAtom; // driven from WOS, settings -- updated via WebSocket waveaiModeConfigAtom: jotai.PrimitiveAtom>; // resolved AI mode configs -- updated via WebSocket settingsAtom: jotai.Atom; // derrived from fullConfig hasCustomAIPresetsAtom: jotai.Atom; // derived from fullConfig + hasConfigErrors: jotai.Atom; // derived from fullConfig staticTabId: jotai.Atom; isFullScreen: jotai.PrimitiveAtom; zoomFactorAtom: jotai.PrimitiveAtom; @@ -28,8 +31,6 @@ declare global { waveAIRateLimitInfoAtom: jotai.PrimitiveAtom; }; - type WritableWaveObjectAtom = jotai.WritableAtom; - type ThrottledValueAtom = jotai.WritableAtom], void>; type AtomWithThrottle = { @@ -59,6 +60,7 @@ declare global { environment: "electron" | "renderer"; primaryTabStartup?: boolean; builderId?: string; + isPreview?: boolean; }; type WaveInitOpts = { @@ -132,6 +134,7 @@ declare global { setBuilderWindowAppId: (appId: string) => void; // set-builder-window-appid doRefresh: () => void; // do-refresh saveTextFile: (fileName: string, content: string) => Promise; // save-text-file + setIsActive: () => Promise; // set-is-active }; type ElectronContextMenuItem = { @@ -275,6 +278,7 @@ declare global { resultsIndex: PrimitiveAtom; resultsCount: PrimitiveAtom; isOpen: PrimitiveAtom; + focusInput: PrimitiveAtom; regex?: PrimitiveAtom; caseSensitive?: PrimitiveAtom; wholeWord?: PrimitiveAtom; @@ -289,7 +293,14 @@ declare global { declare type ViewComponent = React.FC; - type ViewModelClass = new (blockId: string, nodeModel: BlockNodeModel, tabModel: TabModel) => ViewModel; + type ViewModelInitType = { + blockId: string; + nodeModel: BlockNodeModel; + tabModel: TabModel; + waveEnv: WaveEnv; + }; + + type ViewModelClass = new (initOpts: ViewModelInitType) => ViewModel; interface ViewModel { // The type of view, used for identifying and rendering the appropriate component. diff --git a/frontend/types/gotypes.d.ts b/frontend/types/gotypes.d.ts index 96f0ca266..d07ebf8b1 100644 --- a/frontend/types/gotypes.d.ts +++ b/frontend/types/gotypes.d.ts @@ -25,6 +25,7 @@ declare global { "ai:thinkinglevel"?: string; "ai:verbosity"?: string; "ai:endpoint"?: string; + "ai:proxyurl"?: string; "ai:azureapiversion"?: string; "ai:apitoken"?: string; "ai:apitokensecretname"?: string; @@ -107,6 +108,24 @@ declare global { iconcolor: string; }; + // baseds.Badge + type Badge = { + badgeid: string; + icon: string; + color?: string; + priority: number; + pidlinked?: boolean; + }; + + // baseds.BadgeEvent + type BadgeEvent = { + oref: string; + clear?: boolean; + clearall?: boolean; + clearbyid?: string; + badge?: Badge; + }; + // waveobj.Block type Block = WaveObj & { parentoref?: string; @@ -220,6 +239,13 @@ declare global { token: string; }; + // wshrpc.CommandBadgeWatchPidData + type CommandBadgeWatchPidData = { + pid: number; + oref: ORef; + badgeid: string; + }; + // wshrpc.CommandBlockInputData type CommandBlockInputData = { blockid: string; @@ -278,6 +304,18 @@ declare global { blockdef: BlockDef; }; + // wshrpc.CommandDebugTermData + type CommandDebugTermData = { + blockid: string; + size: number; + }; + + // wshrpc.CommandDebugTermRtnData + type CommandDebugTermRtnData = { + offset: number; + data64: string; + }; + // wshrpc.CommandDeleteAppFileData type CommandDeleteAppFileData = { appid: string; @@ -747,6 +785,7 @@ declare global { "conn:wshenabled"?: boolean; "conn:askbeforewshinstall"?: boolean; "conn:wshpath"?: string; + "conn:moshenabled"?: boolean; "conn:shellpath"?: string; "conn:ignoresshconfig"?: boolean; "display:hidden"?: boolean; @@ -793,6 +832,8 @@ declare global { status: string; connhealthstatus?: string; wshenabled: boolean; + moshenabled: boolean; + moshactive: boolean; connection: string; connected: boolean; hasconnected: boolean; @@ -1076,12 +1117,14 @@ declare global { "graph:numpoints"?: number; "graph:metrics"?: string[]; "sysinfo:type"?: string; + "tab:flagcolor"?: string; "bg:*"?: boolean; bg?: string; "bg:opacity"?: number; "bg:blendmode"?: string; "bg:bordercolor"?: string; "bg:activebordercolor"?: string; + "layout:vtabbarwidth"?: number; "waveai:panelopen"?: boolean; "waveai:panelwidth"?: number; "waveai:model"?: string; @@ -1106,6 +1149,7 @@ declare global { "term:conndebug"?: string; "term:bellsound"?: boolean; "term:bellindicator"?: boolean; + "term:osc52"?: string; "term:durable"?: boolean; "web:zoom"?: number; "web:hidenav"?: boolean; @@ -1157,7 +1201,8 @@ declare global { "shell:integration"?: boolean; "shell:omz"?: boolean; "shell:comp"?: string; - "shell:inputempty"?: boolean; + "shell:inputbuffer64"?: string; + "shell:inputcursor"?: number; "shell:lastcmd"?: string; "shell:lastcmdexitcode"?: number; "builder:layout"?: {[key: string]: number}; @@ -1265,6 +1310,7 @@ declare global { "app:disablectrlshiftarrows"?: boolean; "app:disablectrlshiftdisplay"?: boolean; "app:focusfollowscursor"?: string; + "app:tabbar"?: string; "feature:waveappbuilder"?: boolean; "ai:*"?: boolean; "ai:preset"?: string; @@ -1300,7 +1346,9 @@ declare global { "term:cursorblink"?: boolean; "term:bellsound"?: boolean; "term:bellindicator"?: boolean; + "term:osc52"?: string; "term:durable"?: boolean; + "term:closeonlasttermclose"?: boolean; "editor:minimapenabled"?: boolean; "editor:stickyscrollenabled"?: boolean; "editor:wordwrap"?: boolean; @@ -1318,6 +1366,7 @@ declare global { "markdown:fontsize"?: number; "markdown:fixedfontsize"?: number; "preview:showhiddenfiles"?: boolean; + "preview:defaultsort"?: string; "tab:preset"?: string; "tab:confirmclose"?: boolean; "widget:*"?: boolean; @@ -1347,6 +1396,7 @@ declare global { "conn:*"?: boolean; "conn:askbeforewshinstall"?: boolean; "conn:wshenabled"?: boolean; + "conn:moshenabled"?: boolean; "conn:localhostdisplayname"?: string; "debug:*"?: boolean; "debug:pprofport"?: number; @@ -1429,6 +1479,8 @@ declare global { "client:buildtime"?: string; "client:osrelease"?: string; "client:isdev"?: boolean; + "client:packagetype"?: string; + "client:macos"?: string; "cohort:month"?: string; "cohort:isoweek"?: string; "autoupdate:channel"?: string; @@ -1471,6 +1523,7 @@ declare global { "onboarding:feature"?: "waveai" | "durable" | "magnify" | "wsh"; "onboarding:version"?: string; "onboarding:githubstar"?: "already" | "star" | "later"; + "onboarding:page"?: string; "display:height"?: number; "display:width"?: number; "display:dpr"?: number; @@ -1526,6 +1579,8 @@ declare global { "client:buildtime"?: string; "client:osrelease"?: string; "client:isdev"?: boolean; + "client:packagetype"?: string; + "client:macos"?: string; "cohort:month"?: string; "cohort:isoweek"?: string; "autoupdate:channel"?: string; @@ -1549,25 +1604,12 @@ declare global { blockids: string[]; }; - // wshrpc.TabIndicator - type TabIndicator = { - icon: string; - color?: string; - priority: number; - clearonfocus?: boolean; - persistentindicator?: TabIndicator; - }; - - // wshrpc.TabIndicatorEventData - type TabIndicatorEventData = { - tabid: string; - indicator: TabIndicator; - }; - // waveobj.TermSize type TermSize = { rows: number; cols: number; + xpixel?: number; + ypixel?: number; }; // wconfig.TermThemeType diff --git a/frontend/types/waveevent.d.ts b/frontend/types/waveevent.d.ts index 81eec9bf9..c3e5bd782 100644 --- a/frontend/types/waveevent.d.ts +++ b/frontend/types/waveevent.d.ts @@ -6,7 +6,27 @@ declare global { // wps.WaveEvent - type WaveEventName = "blockclose" | "connchange" | "sysinfo" | "controllerstatus" | "builderstatus" | "builderoutput" | "waveobj:update" | "blockfile" | "config" | "userinput" | "route:down" | "route:up" | "workspace:update" | "waveai:ratelimit" | "waveapp:appgoupdated" | "tsunami:updatemeta" | "waveai:modeconfig" | "tab:indicator" | "block:jobstatus"; + type WaveEventName = + | "blockclose" + | "connchange" + | "sysinfo" + | "controllerstatus" + | "builderstatus" + | "builderoutput" + | "waveobj:update" + | "blockfile" + | "config" + | "userinput" + | "route:down" + | "route:up" + | "workspace:update" + | "waveai:ratelimit" + | "waveapp:appgoupdated" + | "tsunami:updatemeta" + | "waveai:modeconfig" + | "block:jobstatus" + | "badge" + ; type WaveEvent = { event: WaveEventName; @@ -32,8 +52,8 @@ declare global { { event: "waveapp:appgoupdated"; data?: null; } | { event: "tsunami:updatemeta"; data?: AppMeta; } | { event: "waveai:modeconfig"; data?: AIModeConfigUpdate; } | - { event: "tab:indicator"; data?: TabIndicatorEventData; } | - { event: "block:jobstatus"; data?: BlockJobStatusData; } + { event: "block:jobstatus"; data?: BlockJobStatusData; } | + { event: "badge"; data?: BadgeEvent; } ); } diff --git a/frontend/util/color-validator.test.ts b/frontend/util/color-validator.test.ts new file mode 100644 index 000000000..fccfbaca1 --- /dev/null +++ b/frontend/util/color-validator.test.ts @@ -0,0 +1,43 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +import { validateCssColor } from "./color-validator"; + +describe("validateCssColor", () => { + beforeEach(() => { + vi.stubGlobal("CSS", { + supports: (_property: string, value: string) => { + return [ + "red", + "#aabbcc", + "#aabbccdd", + "rgb(255, 0, 0)", + "rgba(255, 0, 0, 0.5)", + "hsl(120 100% 50%)", + "transparent", + "currentColor", + ].includes(value); + }, + }); + }); + + afterEach(() => { + vi.unstubAllGlobals(); + }); + + it("returns type for supported CSS color formats", () => { + expect(validateCssColor("red")).toBe("keyword"); + expect(validateCssColor("#aabbcc")).toBe("hex"); + expect(validateCssColor("#aabbccdd")).toBe("hex8"); + expect(validateCssColor("rgb(255, 0, 0)")).toBe("rgb"); + expect(validateCssColor("rgba(255, 0, 0, 0.5)")).toBe("rgba"); + expect(validateCssColor("hsl(120 100% 50%)")).toBe("hsl"); + expect(validateCssColor("transparent")).toBe("transparent"); + expect(validateCssColor("currentColor")).toBe("currentcolor"); + }); + + it("throws for invalid CSS colors", () => { + expect(() => validateCssColor(":not-a-color:")).toThrow("Invalid CSS color"); + expect(() => validateCssColor("#12")).toThrow("Invalid CSS color"); + expect(() => validateCssColor("rgb(255, 0)")).toThrow("Invalid CSS color"); + }); +}); diff --git a/frontend/util/color-validator.ts b/frontend/util/color-validator.ts new file mode 100644 index 000000000..6be4671e2 --- /dev/null +++ b/frontend/util/color-validator.ts @@ -0,0 +1,54 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +const HexColorRegex = /^#([\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i; +const FunctionalColorRegex = /^([a-z-]+)\(/i; +const NamedColorRegex = /^[a-z]+$/i; + +function isValidCssColor(color: string): boolean { + if (typeof CSS == "undefined" || typeof CSS.supports != "function") { + return false; + } + return CSS.supports("color", color); +} + +function getCssColorType(color: string): string { + const normalizedColor = color.toLowerCase(); + if (HexColorRegex.test(normalizedColor)) { + if (normalizedColor.length === 4) { + return "hex3"; + } + if (normalizedColor.length === 5) { + return "hex4"; + } + if (normalizedColor.length === 9) { + return "hex8"; + } + return "hex"; + } + if (normalizedColor === "transparent") { + return "transparent"; + } + if (normalizedColor === "currentcolor") { + return "currentcolor"; + } + const functionMatch = normalizedColor.match(FunctionalColorRegex); + if (functionMatch) { + return functionMatch[1]; + } + if (NamedColorRegex.test(normalizedColor)) { + return "keyword"; + } + return "color"; +} + +export function validateCssColor(color: string): string { + if (typeof color != "string") { + throw new Error(`Invalid CSS color: ${String(color)}`); + } + const normalizedColor = color.trim(); + if (normalizedColor === "" || !isValidCssColor(normalizedColor)) { + throw new Error(`Invalid CSS color: ${color}`); + } + return getCssColorType(normalizedColor); +} diff --git a/frontend/util/endpoints.ts b/frontend/util/endpoints.ts index 849c7a940..4c073a3af 100644 --- a/frontend/util/endpoints.ts +++ b/frontend/util/endpoints.ts @@ -1,12 +1,19 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 +import { isPreviewWindow } from "@/app/store/windowtype"; import { getEnv } from "./getenv"; import { lazy } from "./util"; export const WebServerEndpointVarName = "WAVE_SERVER_WEB_ENDPOINT"; export const WSServerEndpointVarName = "WAVE_SERVER_WS_ENDPOINT"; -export const getWebServerEndpoint = lazy(() => `http://${getEnv(WebServerEndpointVarName)}`); +export const getWebServerEndpoint = lazy(() => { + if (isPreviewWindow()) return null; + return `http://${getEnv(WebServerEndpointVarName)}`; +}); -export const getWSServerEndpoint = lazy(() => `ws://${getEnv(WSServerEndpointVarName)}`); +export const getWSServerEndpoint = lazy(() => { + if (isPreviewWindow()) return null; + return `ws://${getEnv(WSServerEndpointVarName)}`; +}); diff --git a/frontend/util/platformutil.ts b/frontend/util/platformutil.ts index 1a73fce55..92fc240b0 100644 --- a/frontend/util/platformutil.ts +++ b/frontend/util/platformutil.ts @@ -1,14 +1,28 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 export const PlatformMacOS = "darwin"; export const PlatformWindows = "win32"; +export const PlatformLinux = "linux"; export let PLATFORM: NodeJS.Platform = PlatformMacOS; +export let MacOSVersion: string = null; export function setPlatform(platform: NodeJS.Platform) { PLATFORM = platform; } +export function setMacOSVersion(version: string) { + MacOSVersion = version; +} + +export function isMacOSTahoeOrLater(): boolean { + if (!isMacOS() || MacOSVersion == null) { + return false; + } + const major = parseInt(MacOSVersion.split(".")[0], 10); + return major >= 16; +} + export function isMacOS(): boolean { return PLATFORM == PlatformMacOS; } diff --git a/frontend/util/util.ts b/frontend/util/util.ts index 2eea82f82..8c2d33058 100644 --- a/frontend/util/util.ts +++ b/frontend/util/util.ts @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0s import base64 from "base64-js"; @@ -108,7 +108,7 @@ function jsonDeepEqual(v1: any, v2: any): boolean { if (keys1.length !== keys2.length) { return false; } - for (let key of keys1) { + for (const key of keys1) { if (!jsonDeepEqual(v1[key], v2[key])) { return false; } @@ -534,6 +534,7 @@ export { makeExternLink, makeIconClass, mergeMeta, + NullAtom, parseDataUrl, sleep, sortByDisplayOrder, diff --git a/frontend/wave.ts b/frontend/wave.ts index c38016307..20ee2ba97 100644 --- a/frontend/wave.ts +++ b/frontend/wave.ts @@ -3,6 +3,7 @@ import { App } from "@/app/app"; import { loadMonaco } from "@/app/monaco/monaco-env"; +import { loadBadges } from "@/app/store/badge"; import { GlobalModel } from "@/app/store/global-model"; import { globalRefocus, @@ -25,13 +26,13 @@ import { initGlobal, initGlobalWaveEventSubs, loadConnStatus, - loadTabIndicators, subscribeToConnEvents, } from "@/store/global"; import { activeTabIdAtom } from "@/store/tab-model"; import * as WOS from "@/store/wos"; import { loadFonts } from "@/util/fontutil"; import { setKeyUtilPlatform } from "@/util/keyutil"; +import { isMacOS, setMacOSVersion } from "@/util/platformutil"; import { createElement } from "react"; import { createRoot } from "react-dom/client"; @@ -159,19 +160,23 @@ async function initWave(initOpts: WaveInitOpts) { const globalWS = initWshrpc(makeTabRouteId(initOpts.tabId)); (window as any).globalWS = globalWS; (window as any).TabRpcClient = TabRpcClient; - await loadConnStatus(); - await loadTabIndicators(); - initGlobalWaveEventSubs(initOpts); - subscribeToConnEvents(); // ensures client/window/workspace are loaded into the cache before rendering try { - const [client, waveWindow, initialTab] = await Promise.all([ + await loadConnStatus(); + await loadBadges(); + initGlobalWaveEventSubs(initOpts); + subscribeToConnEvents(); + if (isMacOS()) { + const macOSVersion = await RpcApi.MacOSVersionCommand(TabRpcClient); + setMacOSVersion(macOSVersion); + } + const [_client, waveWindow, initialTab] = await Promise.all([ WOS.loadAndPinWaveObject(WOS.makeORef("client", initOpts.clientId)), WOS.loadAndPinWaveObject(WOS.makeORef("window", initOpts.windowId)), WOS.loadAndPinWaveObject(WOS.makeORef("tab", initOpts.tabId)), ]); - const [ws, layoutState] = await Promise.all([ + const [ws, _layoutState] = await Promise.all([ WOS.loadAndPinWaveObject(WOS.makeORef("workspace", waveWindow.workspaceid)), WOS.reloadWaveObject(WOS.makeORef("layout", initialTab.layoutstate)), ]); @@ -193,7 +198,7 @@ async function initWave(initOpts: WaveInitOpts) { globalStore.set(atoms.waveaiModeConfigAtom, waveaiModeConfig.configs); console.log("Wave First Render"); let firstRenderResolveFn: () => void = null; - let firstRenderPromise = new Promise((resolve) => { + const firstRenderPromise = new Promise((resolve) => { firstRenderResolveFn = resolve; }); const reactElem = createElement(App, { onFirstRender: firstRenderResolveFn }, null); @@ -252,7 +257,7 @@ async function initBuilder(initOpts: BuilderInitOpts) { globalStore.set(atoms.builderAppId, appIdToUse); - const client = await WOS.loadAndPinWaveObject(WOS.makeORef("client", initOpts.clientId)); + const _client = await WOS.loadAndPinWaveObject(WOS.makeORef("client", initOpts.clientId)); registerBuilderGlobalKeys(); registerElectronReinjectKeyHandler(); @@ -265,7 +270,7 @@ async function initBuilder(initOpts: BuilderInitOpts) { console.log("Tsunami Builder First Render"); let firstRenderResolveFn: () => void = null; - let firstRenderPromise = new Promise((resolve) => { + const firstRenderPromise = new Promise((resolve) => { firstRenderResolveFn = resolve; }); const reactElem = createElement(BuilderApp, { initOpts, onFirstRender: firstRenderResolveFn }, null); diff --git a/go.mod b/go.mod index cc6e13a9e..bf6f92bab 100644 --- a/go.mod +++ b/go.mod @@ -24,38 +24,38 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/sashabaranov/go-openai v1.41.2 github.com/sawka/txwrap v0.2.0 - github.com/shirou/gopsutil/v4 v4.26.1 + github.com/shirou/gopsutil/v4 v4.26.2 github.com/skeema/knownhosts v1.3.1 github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/spf13/cobra v1.10.2 github.com/ubuntu/gowsl v0.0.0-20240906163211-049fd49bd93b github.com/wavetermdev/htmltoken v0.2.0 github.com/wavetermdev/waveterm/tsunami v0.12.3 - golang.org/x/crypto v0.48.0 + golang.org/x/crypto v0.49.0 golang.org/x/mod v0.33.0 - golang.org/x/sync v0.19.0 - golang.org/x/sys v0.41.0 - golang.org/x/term v0.40.0 - google.golang.org/api v0.267.0 + golang.org/x/sync v0.20.0 + golang.org/x/sys v0.42.0 + golang.org/x/term v0.41.0 + google.golang.org/api v0.269.0 ) require ( cloud.google.com/go v0.121.6 // indirect cloud.google.com/go/ai v0.8.0 // indirect - cloud.google.com/go/auth v0.18.1 // indirect + cloud.google.com/go/auth v0.18.2 // indirect cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect cloud.google.com/go/compute/metadata v0.9.0 // indirect cloud.google.com/go/longrunning v0.6.7 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/buger/jsonparser v1.1.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/ebitengine/purego v0.9.1 // indirect + github.com/ebitengine/purego v0.10.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/google/s2a-go v0.1.9 // indirect - github.com/googleapis/enterprise-certificate-proxy v0.3.11 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.12 // indirect github.com/googleapis/gax-go/v2 v2.17.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect @@ -76,13 +76,13 @@ require ( go.opentelemetry.io/otel v1.39.0 // indirect go.opentelemetry.io/otel/metric v1.39.0 // indirect go.opentelemetry.io/otel/trace v1.39.0 // indirect - golang.org/x/net v0.49.0 // indirect + golang.org/x/net v0.51.0 // indirect golang.org/x/oauth2 v0.35.0 // indirect - golang.org/x/text v0.34.0 // indirect + golang.org/x/text v0.35.0 // indirect golang.org/x/time v0.14.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260203192932-546029d2fa20 // indirect - google.golang.org/grpc v1.78.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260217215200-42d3e9bedb6d // indirect + google.golang.org/grpc v1.79.1 // indirect google.golang.org/protobuf v1.36.11 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 79dfa6a67..7928668ed 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ cloud.google.com/go v0.121.6 h1:waZiuajrI28iAf40cWgycWNgaXPO06dupuS+sgibK6c= cloud.google.com/go v0.121.6/go.mod h1:coChdst4Ea5vUpiALcYKXEpR1S9ZgXbhEzzMcMR66vI= cloud.google.com/go/ai v0.8.0 h1:rXUEz8Wp2OlrM8r1bfmpF2+VKqc1VJpafE3HgzRnD/w= cloud.google.com/go/ai v0.8.0/go.mod h1:t3Dfk4cM61sytiggo2UyGsDVW3RF1qGZaUKDrZFyqkE= -cloud.google.com/go/auth v0.18.1 h1:IwTEx92GFUo2pJ6Qea0EU3zYvKnTAeRCODxfA/G5UWs= -cloud.google.com/go/auth v0.18.1/go.mod h1:GfTYoS9G3CWpRA3Va9doKN9mjPGRS+v41jmZAhBzbrA= +cloud.google.com/go/auth v0.18.2 h1:+Nbt5Ev0xEqxlNjd6c+yYUeosQ5TtEUaNcN/3FozlaM= +cloud.google.com/go/auth v0.18.2/go.mod h1:xD+oY7gcahcu7G2SG2DsBerfFxgPAJz17zz2joOFF3M= cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc= cloud.google.com/go/auth/oauth2adapt v0.2.8/go.mod h1:XQ9y31RkqZCcwJWNSx2Xvric3RrU88hAYYbjDWYDL+c= cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs= @@ -24,22 +24,22 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMU github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cncf/xds/go v0.0.0-20251022180443-0feb69152e9f h1:Y8xYupdHxryycyPlc9Y+bSQAYZnetRJ70VMVKm5CKI0= -github.com/cncf/xds/go v0.0.0-20251022180443-0feb69152e9f/go.mod h1:HlzOvOjVBOfTGSRXRyY0OiCS/3J1akRGQQpRO/7zyF4= +github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5 h1:6xNmx7iTtyBRev0+D/Tv1FZd4SCg8axKApyNyRsAt/w= +github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5/go.mod h1:KdCmV+x/BuvyMxRnYBlmVaq4OLiKW6iRQfvC62cvdkI= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/ebitengine/purego v0.9.1 h1:a/k2f2HQU3Pi399RPW1MOaZyhKJL9w/xFpKAg4q1s0A= -github.com/ebitengine/purego v0.9.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= +github.com/ebitengine/purego v0.10.0 h1:QIw4xfpWT6GWTzaW5XEKy3HXoqrJGx1ijYHzTF0/ISU= +github.com/ebitengine/purego v0.10.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= -github.com/envoyproxy/go-control-plane v0.13.5-0.20251024222203-75eaa193e329 h1:K+fnvUM0VZ7ZFJf0n4L/BRlnsb9pL/GuDG6FqaH+PwM= -github.com/envoyproxy/go-control-plane/envoy v1.35.0 h1:ixjkELDE+ru6idPxcHLj8LBVc2bFP7iBytj353BoHUo= -github.com/envoyproxy/go-control-plane/envoy v1.35.0/go.mod h1:09qwbGVuSWWAyN5t/b3iyVfz5+z8QWGrzkoqm/8SbEs= -github.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfUKS7KJ7spH3d86P8= -github.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU= +github.com/envoyproxy/go-control-plane v0.14.0 h1:hbG2kr4RuFj222B6+7T83thSPqLjwBIfQawTkC++2HA= +github.com/envoyproxy/go-control-plane/envoy v1.36.0 h1:yg/JjO5E7ubRyKX3m07GF3reDNEnfOboJ0QySbH736g= +github.com/envoyproxy/go-control-plane/envoy v1.36.0/go.mod h1:ty89S1YCCVruQAm9OtKeEkQLTb+Lkz0k8v9W0Oxsv98= +github.com/envoyproxy/protoc-gen-validate v1.3.0 h1:TvGH1wof4H33rezVKWSpqKz5NXWg5VPuZ0uONDT6eb4= +github.com/envoyproxy/protoc-gen-validate v1.3.0/go.mod h1:HvYl7zwPa5mffgyeTUHA9zHIH36nmrm7oCbo4YKoSWA= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= @@ -68,8 +68,8 @@ github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0= github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/enterprise-certificate-proxy v0.3.11 h1:vAe81Msw+8tKUxi2Dqh/NZMz7475yUvmRIkXr4oN2ao= -github.com/googleapis/enterprise-certificate-proxy v0.3.11/go.mod h1:RFV7MUdlb7AgEq2v7FmMCfeSMCllAzWxFgRdusoGks8= +github.com/googleapis/enterprise-certificate-proxy v0.3.12 h1:Fg+zsqzYEs1ZnvmcztTYxhgCBsx3eEhEwQ1W/lHq/sQ= +github.com/googleapis/enterprise-certificate-proxy v0.3.12/go.mod h1:vqVt9yG9480NtzREnTlmGSBmFrA+bzb0yl0TxoBQXOg= github.com/googleapis/gax-go/v2 v2.17.0 h1:RksgfBpxqff0EZkDWYuz9q/uWsTVz+kf43LsZ1J6SMc= github.com/googleapis/gax-go/v2 v2.17.0/go.mod h1:mzaqghpQp4JDh3HvADwrat+6M3MOIDp5YKHhb9PAgDY= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= @@ -126,8 +126,8 @@ github.com/sashabaranov/go-openai v1.41.2 h1:vfPRBZNMpnqu8ELsclWcAvF19lDNgh1t6TV github.com/sashabaranov/go-openai v1.41.2/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg= github.com/sawka/txwrap v0.2.0 h1:V3LfvKVLULxcYSxdMguLwFyQFMEU9nFDJopg0ZkL+94= github.com/sawka/txwrap v0.2.0/go.mod h1:wwQ2SQiN4U+6DU/iVPhbvr7OzXAtgZlQCIGuvOswEfA= -github.com/shirou/gopsutil/v4 v4.26.1 h1:TOkEyriIXk2HX9d4isZJtbjXbEjf5qyKPAzbzY0JWSo= -github.com/shirou/gopsutil/v4 v4.26.1/go.mod h1:medLI9/UNAb0dOI9Q3/7yWSqKkj00u+1tgY8nvv41pc= +github.com/shirou/gopsutil/v4 v4.26.2 h1:X8i6sicvUFih4BmYIGT1m2wwgw2VG9YgrDTi7cIRGUI= +github.com/shirou/gopsutil/v4 v4.26.2/go.mod h1:LZ6ewCSkBqUpvSOf+LsTGnRinC6iaNUNMGBtDkJBaLQ= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8= @@ -171,48 +171,48 @@ go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs= go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18= go.opentelemetry.io/otel/sdk v1.39.0/go.mod h1:vDojkC4/jsTJsE+kh+LXYQlbL8CgrEcwmt1ENZszdJE= -go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM= -go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA= +go.opentelemetry.io/otel/sdk/metric v1.39.0 h1:cXMVVFVgsIf2YL6QkRF4Urbr/aMInf+2WKg+sEJTtB8= +go.opentelemetry.io/otel/sdk/metric v1.39.0/go.mod h1:xq9HEVH7qeX69/JnwEfp6fVq5wosJsY1mt4lLfYdVew= go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI= go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= -golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= -golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= +golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= +golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8= golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w= -golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= -golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= +golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo= +golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y= golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ= golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= -golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= -golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= +golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220721230656-c6bc011c0c49/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= -golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg= -golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM= -golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= -golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= +golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= +golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/term v0.41.0 h1:QCgPso/Q3RTJx2Th4bDLqML4W6iJiaXFq2/ftQF13YU= +golang.org/x/term v0.41.0/go.mod h1:3pfBgksrReYfZ5lvYM0kSO0LIkAl4Yl2bXOkKP7Ec2A= +golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= +golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI= golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= -google.golang.org/api v0.267.0 h1:w+vfWPMPYeRs8qH1aYYsFX68jMls5acWl/jocfLomwE= -google.golang.org/api v0.267.0/go.mod h1:Jzc0+ZfLnyvXma3UtaTl023TdhZu6OMBP9tJ+0EmFD0= +google.golang.org/api v0.269.0 h1:qDrTOxKUQ/P0MveH6a7vZ+DNHxJQjtGm/uvdbdGXCQg= +google.golang.org/api v0.269.0/go.mod h1:N8Wpcu23Tlccl0zSHEkcAZQKDLdquxK+l9r2LkwAauE= google.golang.org/genproto v0.0.0-20260128011058-8636f8732409 h1:VQZ/yAbAtjkHgH80teYd2em3xtIkkHd7ZhqfH2N9CsM= google.golang.org/genproto v0.0.0-20260128011058-8636f8732409/go.mod h1:rxKD3IEILWEu3P44seeNOAwZN4SaoKaQ/2eTg4mM6EM= google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 h1:merA0rdPeUV3YIIfHHcH4qBkiQAc1nfCKSI7lB4cV2M= google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409/go.mod h1:fl8J1IvUjCilwZzQowmw2b7HQB2eAuYBabMXzWurF+I= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260203192932-546029d2fa20 h1:Jr5R2J6F6qWyzINc+4AM8t5pfUz6beZpHp678GNrMbE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260203192932-546029d2fa20/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ= -google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc= -google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260217215200-42d3e9bedb6d h1:t/LOSXPJ9R0B6fnZNyALBRfZBH0Uy0gT+uR+SJ6syqQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260217215200-42d3e9bedb6d/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/grpc v1.79.1 h1:zGhSi45ODB9/p3VAawt9a+O/MULLl9dpizzNNpq7flY= +google.golang.org/grpc v1.79.1/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/package-lock.json b/package-lock.json index 630ff9ec1..4b1adca94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "waveterm", - "version": "0.14.0", + "version": "0.14.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "waveterm", - "version": "0.14.0", + "version": "0.14.3", "hasInstallScript": true, "license": "Apache-2.0", "workspaces": [ @@ -21,7 +21,9 @@ "@table-nav/core": "^0.0.7", "@table-nav/react": "^0.0.7", "@tanstack/react-table": "^8.21.3", + "@tanstack/react-virtual": "^3.13.19", "@xterm/addon-fit": "^0.10.0", + "@xterm/addon-image": "^0.9.0", "@xterm/addon-search": "^0.15.0", "@xterm/addon-serialize": "^0.13.0", "@xterm/addon-web-links": "^0.11.0", @@ -80,6 +82,7 @@ "tinycolor2": "^1.6.0", "unist-util-visit": "^5.1.0", "use-device-pixel-ratio": "^1.1.2", + "uuid": "^13.0.0", "winston": "^3.19.0", "ws": "^8.19.0", "yaml": "^2.7.1" @@ -87,7 +90,7 @@ "devDependencies": { "@eslint/js": "^9.39", "@rollup/plugin-node-resolve": "^16.0.3", - "@tailwindcss/vite": "^4.1.18", + "@tailwindcss/vite": "^4.2.1", "@types/color": "^4.2.0", "@types/css-tree": "^2", "@types/debug": "^4", @@ -105,19 +108,20 @@ "@types/ws": "^8", "@vitejs/plugin-react-swc": "4.2.3", "@vitest/coverage-istanbul": "^3.0.9", - "electron": "^40.4.1", + "electron": "^41.0.2", "electron-builder": "^26.8", "electron-vite": "^5.0", "eslint": "^9.39", "eslint-config-prettier": "^10.1.8", - "globals": "^17.3.0", + "globals": "^17.4.0", "node-abi": "^4.26.0", - "postcss": "^8.5.6", + "postcss": "^8.5.8", "prettier": "^3.8.1", "prettier-plugin-jsdoc": "^1.8.0", "prettier-plugin-organize-imports": "^4.3.0", "sass": "1.91.0", - "tailwindcss": "^4.1.18", + "sharp": "^0.34.5", + "tailwindcss": "^4.2.1", "tailwindcss-animate": "^1.0.7", "ts-node": "^10.9.2", "tslib": "^2.8.1", @@ -165,7 +169,7 @@ "@types/react-dom": "^18.3.0", "eslint": "^9.39", "eslint-config-prettier": "^10.1.8", - "eslint-plugin-mdx": "^3.6.2", + "eslint-plugin-mdx": "^3.7.0", "prettier": "^3.8.1", "prettier-plugin-jsdoc": "^1.8.0", "prettier-plugin-organize-imports": "^4.3.0", @@ -4551,9 +4555,9 @@ } }, "node_modules/@electron/asar/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.4.tgz", + "integrity": "sha512-twmL+S8+7yIsE9wsqgzU3E8/LumN3M3QELrBZ20OdmQ9jB2JvW5oZtBEmft84k/Gs5CG9mqtWc6Y9vW+JEzGxw==", "dev": true, "license": "ISC", "dependencies": { @@ -4809,24 +4813,37 @@ "node": ">=16.4" } }, + "node_modules/@electron/universal/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/@electron/universal/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.3.tgz", + "integrity": "sha512-fy6KJm2RawA5RcHkLa1z/ScpBeA762UF9KmZQxwIbDtRJrgLzM10depAiEQ+CXYcoiqW1/m96OAAoke2nE9EeA==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" } }, "node_modules/@electron/universal/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.7.tgz", + "integrity": "sha512-MOwgjc8tfrpn5QQEvjijjmDVtMw2oL88ugTevzxQnzRLm6l3fVEF2gzU0kYeYYKD8C66+IdGX6peJ4MyUlUnPg==", "dev": true, "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^5.0.2" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -4858,13 +4875,11 @@ } }, "node_modules/@emnapi/runtime": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.5.0.tgz", - "integrity": "sha512-97/BJ3iXHww3djw6hYIfErCZFee7qCtrneuLa20UXFCOTCfBM2cvQHjWJ2EG0s0MtdNwInarqCTz35i4wWXHsQ==", - "dev": true, + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.8.1.tgz", + "integrity": "sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg==", "license": "MIT", "optional": true, - "peer": true, "dependencies": { "tslib": "^2.4.0" } @@ -5585,20 +5600,28 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@img/colour": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.0.0.tgz", + "integrity": "sha512-A5P/LfWGFSl6nsckYtjw9da+19jB8hkJ6ACTGcDfEJ0aE+l2n2El7dsVM7UVHZQ9s2lmYMWlrS21YLy2IR1LUw==", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/@img/sharp-darwin-arm64": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.34.3.tgz", - "integrity": "sha512-ryFMfvxxpQRsgZJqBd4wsttYQbCxsJksrv9Lw/v798JcQ8+w84mBWuXwl+TT0WJ/WrYOLaYpwQXi3sA9nTIaIg==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.34.5.tgz", + "integrity": "sha512-imtQ3WMJXbMY4fxb/Ndp6HBTNVtWCUI0WdobyheGf5+ad6xX8VIDO8u2xE4qc/fr08CKG/7dDseFtn6M6g/r3w==", "cpu": [ "arm64" ], - "dev": true, "license": "Apache-2.0", "optional": true, "os": [ "darwin" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -5606,23 +5629,21 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-libvips-darwin-arm64": "1.2.0" + "@img/sharp-libvips-darwin-arm64": "1.2.4" } }, "node_modules/@img/sharp-darwin-x64": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.34.3.tgz", - "integrity": "sha512-yHpJYynROAj12TA6qil58hmPmAwxKKC7reUqtGLzsOHfP7/rniNGTL8tjWX6L3CTV4+5P4ypcS7Pp+7OB+8ihA==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.34.5.tgz", + "integrity": "sha512-YNEFAF/4KQ/PeW0N+r+aVVsoIY0/qxxikF2SWdp+NRkmMB7y9LBZAVqQ4yhGCm/H3H270OSykqmQMKLBhBJDEw==", "cpu": [ "x64" ], - "dev": true, "license": "Apache-2.0", "optional": true, "os": [ "darwin" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -5630,185 +5651,181 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-libvips-darwin-x64": "1.2.0" + "@img/sharp-libvips-darwin-x64": "1.2.4" } }, "node_modules/@img/sharp-libvips-darwin-arm64": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.2.0.tgz", - "integrity": "sha512-sBZmpwmxqwlqG9ueWFXtockhsxefaV6O84BMOrhtg/YqbTaRdqDE7hxraVE3y6gVM4eExmfzW4a8el9ArLeEiQ==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.2.4.tgz", + "integrity": "sha512-zqjjo7RatFfFoP0MkQ51jfuFZBnVE2pRiaydKJ1G/rHZvnsrHAOcQALIi9sA5co5xenQdTugCvtb1cuf78Vf4g==", "cpu": [ "arm64" ], - "dev": true, "license": "LGPL-3.0-or-later", "optional": true, "os": [ "darwin" ], - "peer": true, "funding": { "url": "https://opencollective.com/libvips" } }, "node_modules/@img/sharp-libvips-darwin-x64": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.2.0.tgz", - "integrity": "sha512-M64XVuL94OgiNHa5/m2YvEQI5q2cl9d/wk0qFTDVXcYzi43lxuiFTftMR1tOnFQovVXNZJ5TURSDK2pNe9Yzqg==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.2.4.tgz", + "integrity": "sha512-1IOd5xfVhlGwX+zXv2N93k0yMONvUlANylbJw1eTah8K/Jtpi15KC+WSiaX/nBmbm2HxRM1gZ0nSdjSsrZbGKg==", "cpu": [ "x64" ], - "dev": true, "license": "LGPL-3.0-or-later", "optional": true, "os": [ "darwin" ], - "peer": true, "funding": { "url": "https://opencollective.com/libvips" } }, "node_modules/@img/sharp-libvips-linux-arm": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.2.0.tgz", - "integrity": "sha512-mWd2uWvDtL/nvIzThLq3fr2nnGfyr/XMXlq8ZJ9WMR6PXijHlC3ksp0IpuhK6bougvQrchUAfzRLnbsen0Cqvw==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.2.4.tgz", + "integrity": "sha512-bFI7xcKFELdiNCVov8e44Ia4u2byA+l3XtsAj+Q8tfCwO6BQ8iDojYdvoPMqsKDkuoOo+X6HZA0s0q11ANMQ8A==", "cpu": [ "arm" ], - "dev": true, "license": "LGPL-3.0-or-later", "optional": true, "os": [ "linux" ], - "peer": true, "funding": { "url": "https://opencollective.com/libvips" } }, "node_modules/@img/sharp-libvips-linux-arm64": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.2.0.tgz", - "integrity": "sha512-RXwd0CgG+uPRX5YYrkzKyalt2OJYRiJQ8ED/fi1tq9WQW2jsQIn0tqrlR5l5dr/rjqq6AHAxURhj2DVjyQWSOA==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.2.4.tgz", + "integrity": "sha512-excjX8DfsIcJ10x1Kzr4RcWe1edC9PquDRRPx3YVCvQv+U5p7Yin2s32ftzikXojb1PIFc/9Mt28/y+iRklkrw==", "cpu": [ "arm64" ], - "dev": true, "license": "LGPL-3.0-or-later", "optional": true, "os": [ "linux" ], - "peer": true, "funding": { "url": "https://opencollective.com/libvips" } }, "node_modules/@img/sharp-libvips-linux-ppc64": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-ppc64/-/sharp-libvips-linux-ppc64-1.2.0.tgz", - "integrity": "sha512-Xod/7KaDDHkYu2phxxfeEPXfVXFKx70EAFZ0qyUdOjCcxbjqyJOEUpDe6RIyaunGxT34Anf9ue/wuWOqBW2WcQ==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-ppc64/-/sharp-libvips-linux-ppc64-1.2.4.tgz", + "integrity": "sha512-FMuvGijLDYG6lW+b/UvyilUWu5Ayu+3r2d1S8notiGCIyYU/76eig1UfMmkZ7vwgOrzKzlQbFSuQfgm7GYUPpA==", "cpu": [ "ppc64" ], - "dev": true, "license": "LGPL-3.0-or-later", "optional": true, "os": [ "linux" ], - "peer": true, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-riscv64": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-riscv64/-/sharp-libvips-linux-riscv64-1.2.4.tgz", + "integrity": "sha512-oVDbcR4zUC0ce82teubSm+x6ETixtKZBh/qbREIOcI3cULzDyb18Sr/Wcyx7NRQeQzOiHTNbZFF1UwPS2scyGA==", + "cpu": [ + "riscv64" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], "funding": { "url": "https://opencollective.com/libvips" } }, "node_modules/@img/sharp-libvips-linux-s390x": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.2.0.tgz", - "integrity": "sha512-eMKfzDxLGT8mnmPJTNMcjfO33fLiTDsrMlUVcp6b96ETbnJmd4uvZxVJSKPQfS+odwfVaGifhsB07J1LynFehw==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.2.4.tgz", + "integrity": "sha512-qmp9VrzgPgMoGZyPvrQHqk02uyjA0/QrTO26Tqk6l4ZV0MPWIW6LTkqOIov+J1yEu7MbFQaDpwdwJKhbJvuRxQ==", "cpu": [ "s390x" ], - "dev": true, "license": "LGPL-3.0-or-later", "optional": true, "os": [ "linux" ], - "peer": true, "funding": { "url": "https://opencollective.com/libvips" } }, "node_modules/@img/sharp-libvips-linux-x64": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.2.0.tgz", - "integrity": "sha512-ZW3FPWIc7K1sH9E3nxIGB3y3dZkpJlMnkk7z5tu1nSkBoCgw2nSRTFHI5pB/3CQaJM0pdzMF3paf9ckKMSE9Tg==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.2.4.tgz", + "integrity": "sha512-tJxiiLsmHc9Ax1bz3oaOYBURTXGIRDODBqhveVHonrHJ9/+k89qbLl0bcJns+e4t4rvaNBxaEZsFtSfAdquPrw==", "cpu": [ "x64" ], - "dev": true, "license": "LGPL-3.0-or-later", "optional": true, "os": [ "linux" ], - "peer": true, "funding": { "url": "https://opencollective.com/libvips" } }, "node_modules/@img/sharp-libvips-linuxmusl-arm64": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.2.0.tgz", - "integrity": "sha512-UG+LqQJbf5VJ8NWJ5Z3tdIe/HXjuIdo4JeVNADXBFuG7z9zjoegpzzGIyV5zQKi4zaJjnAd2+g2nna8TZvuW9Q==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.2.4.tgz", + "integrity": "sha512-FVQHuwx1IIuNow9QAbYUzJ+En8KcVm9Lk5+uGUQJHaZmMECZmOlix9HnH7n1TRkXMS0pGxIJokIVB9SuqZGGXw==", "cpu": [ "arm64" ], - "dev": true, "license": "LGPL-3.0-or-later", "optional": true, "os": [ "linux" ], - "peer": true, "funding": { "url": "https://opencollective.com/libvips" } }, "node_modules/@img/sharp-libvips-linuxmusl-x64": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.2.0.tgz", - "integrity": "sha512-SRYOLR7CXPgNze8akZwjoGBoN1ThNZoqpOgfnOxmWsklTGVfJiGJoC/Lod7aNMGA1jSsKWM1+HRX43OP6p9+6Q==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.2.4.tgz", + "integrity": "sha512-+LpyBk7L44ZIXwz/VYfglaX/okxezESc6UxDSoyo2Ks6Jxc4Y7sGjpgU9s4PMgqgjj1gZCylTieNamqA1MF7Dg==", "cpu": [ "x64" ], - "dev": true, "license": "LGPL-3.0-or-later", "optional": true, "os": [ "linux" ], - "peer": true, "funding": { "url": "https://opencollective.com/libvips" } }, "node_modules/@img/sharp-linux-arm": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.34.3.tgz", - "integrity": "sha512-oBK9l+h6KBN0i3dC8rYntLiVfW8D8wH+NPNT3O/WBHeW0OQWCjfWksLUaPidsrDKpJgXp3G3/hkmhptAW0I3+A==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.34.5.tgz", + "integrity": "sha512-9dLqsvwtg1uuXBGZKsxem9595+ujv0sJ6Vi8wcTANSFpwV/GONat5eCkzQo/1O6zRIkh0m/8+5BjrRr7jDUSZw==", "cpu": [ "arm" ], - "dev": true, "license": "Apache-2.0", "optional": true, "os": [ "linux" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -5816,23 +5833,21 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-libvips-linux-arm": "1.2.0" + "@img/sharp-libvips-linux-arm": "1.2.4" } }, "node_modules/@img/sharp-linux-arm64": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.34.3.tgz", - "integrity": "sha512-QdrKe3EvQrqwkDrtuTIjI0bu6YEJHTgEeqdzI3uWJOH6G1O8Nl1iEeVYRGdj1h5I21CqxSvQp1Yv7xeU3ZewbA==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.34.5.tgz", + "integrity": "sha512-bKQzaJRY/bkPOXyKx5EVup7qkaojECG6NLYswgktOZjaXecSAeCWiZwwiFf3/Y+O1HrauiE3FVsGxFg8c24rZg==", "cpu": [ "arm64" ], - "dev": true, "license": "Apache-2.0", "optional": true, "os": [ "linux" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -5840,23 +5855,21 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-libvips-linux-arm64": "1.2.0" + "@img/sharp-libvips-linux-arm64": "1.2.4" } }, "node_modules/@img/sharp-linux-ppc64": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-ppc64/-/sharp-linux-ppc64-0.34.3.tgz", - "integrity": "sha512-GLtbLQMCNC5nxuImPR2+RgrviwKwVql28FWZIW1zWruy6zLgA5/x2ZXk3mxj58X/tszVF69KK0Is83V8YgWhLA==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-ppc64/-/sharp-linux-ppc64-0.34.5.tgz", + "integrity": "sha512-7zznwNaqW6YtsfrGGDA6BRkISKAAE1Jo0QdpNYXNMHu2+0dTrPflTLNkpc8l7MUP5M16ZJcUvysVWWrMefZquA==", "cpu": [ "ppc64" ], - "dev": true, "license": "Apache-2.0", "optional": true, "os": [ "linux" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -5864,23 +5877,43 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-libvips-linux-ppc64": "1.2.0" + "@img/sharp-libvips-linux-ppc64": "1.2.4" + } + }, + "node_modules/@img/sharp-linux-riscv64": { + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-riscv64/-/sharp-linux-riscv64-0.34.5.tgz", + "integrity": "sha512-51gJuLPTKa7piYPaVs8GmByo7/U7/7TZOq+cnXJIHZKavIRHAP77e3N2HEl3dgiqdD/w0yUfiJnII77PuDDFdw==", + "cpu": [ + "riscv64" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-riscv64": "1.2.4" } }, "node_modules/@img/sharp-linux-s390x": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.34.3.tgz", - "integrity": "sha512-3gahT+A6c4cdc2edhsLHmIOXMb17ltffJlxR0aC2VPZfwKoTGZec6u5GrFgdR7ciJSsHT27BD3TIuGcuRT0KmQ==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.34.5.tgz", + "integrity": "sha512-nQtCk0PdKfho3eC5MrbQoigJ2gd1CgddUMkabUj+rBevs8tZ2cULOx46E7oyX+04WGfABgIwmMC0VqieTiR4jg==", "cpu": [ "s390x" ], - "dev": true, "license": "Apache-2.0", "optional": true, "os": [ "linux" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -5888,23 +5921,21 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-libvips-linux-s390x": "1.2.0" + "@img/sharp-libvips-linux-s390x": "1.2.4" } }, "node_modules/@img/sharp-linux-x64": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.34.3.tgz", - "integrity": "sha512-8kYso8d806ypnSq3/Ly0QEw90V5ZoHh10yH0HnrzOCr6DKAPI6QVHvwleqMkVQ0m+fc7EH8ah0BB0QPuWY6zJQ==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.34.5.tgz", + "integrity": "sha512-MEzd8HPKxVxVenwAa+JRPwEC7QFjoPWuS5NZnBt6B3pu7EG2Ge0id1oLHZpPJdn3OQK+BQDiw9zStiHBTJQQQQ==", "cpu": [ "x64" ], - "dev": true, "license": "Apache-2.0", "optional": true, "os": [ "linux" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -5912,23 +5943,21 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-libvips-linux-x64": "1.2.0" + "@img/sharp-libvips-linux-x64": "1.2.4" } }, "node_modules/@img/sharp-linuxmusl-arm64": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.34.3.tgz", - "integrity": "sha512-vAjbHDlr4izEiXM1OTggpCcPg9tn4YriK5vAjowJsHwdBIdx0fYRsURkxLG2RLm9gyBq66gwtWI8Gx0/ov+JKQ==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.34.5.tgz", + "integrity": "sha512-fprJR6GtRsMt6Kyfq44IsChVZeGN97gTD331weR1ex1c1rypDEABN6Tm2xa1wE6lYb5DdEnk03NZPqA7Id21yg==", "cpu": [ "arm64" ], - "dev": true, "license": "Apache-2.0", "optional": true, "os": [ "linux" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -5936,23 +5965,21 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-libvips-linuxmusl-arm64": "1.2.0" + "@img/sharp-libvips-linuxmusl-arm64": "1.2.4" } }, "node_modules/@img/sharp-linuxmusl-x64": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.34.3.tgz", - "integrity": "sha512-gCWUn9547K5bwvOn9l5XGAEjVTTRji4aPTqLzGXHvIr6bIDZKNTA34seMPgM0WmSf+RYBH411VavCejp3PkOeQ==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.34.5.tgz", + "integrity": "sha512-Jg8wNT1MUzIvhBFxViqrEhWDGzqymo3sV7z7ZsaWbZNDLXRJZoRGrjulp60YYtV4wfY8VIKcWidjojlLcWrd8Q==", "cpu": [ "x64" ], - "dev": true, "license": "Apache-2.0", "optional": true, "os": [ "linux" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -5960,22 +5987,20 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-libvips-linuxmusl-x64": "1.2.0" + "@img/sharp-libvips-linuxmusl-x64": "1.2.4" } }, "node_modules/@img/sharp-wasm32": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.34.3.tgz", - "integrity": "sha512-+CyRcpagHMGteySaWos8IbnXcHgfDn7pO2fiC2slJxvNq9gDipYBN42/RagzctVRKgxATmfqOSulgZv5e1RdMg==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.34.5.tgz", + "integrity": "sha512-OdWTEiVkY2PHwqkbBI8frFxQQFekHaSSkUIJkwzclWZe64O1X4UlUjqqqLaPbUpMOQk6FBu/HtlGXNblIs0huw==", "cpu": [ "wasm32" ], - "dev": true, "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT", "optional": true, - "peer": true, "dependencies": { - "@emnapi/runtime": "^1.4.4" + "@emnapi/runtime": "^1.7.0" }, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" @@ -5985,19 +6010,17 @@ } }, "node_modules/@img/sharp-win32-arm64": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.34.3.tgz", - "integrity": "sha512-MjnHPnbqMXNC2UgeLJtX4XqoVHHlZNd+nPt1kRPmj63wURegwBhZlApELdtxM2OIZDRv/DFtLcNhVbd1z8GYXQ==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.34.5.tgz", + "integrity": "sha512-WQ3AgWCWYSb2yt+IG8mnC6Jdk9Whs7O0gxphblsLvdhSpSTtmu69ZG1Gkb6NuvxsNACwiPV6cNSZNzt0KPsw7g==", "cpu": [ "arm64" ], - "dev": true, "license": "Apache-2.0 AND LGPL-3.0-or-later", "optional": true, "os": [ "win32" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -6006,19 +6029,17 @@ } }, "node_modules/@img/sharp-win32-ia32": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.34.3.tgz", - "integrity": "sha512-xuCdhH44WxuXgOM714hn4amodJMZl3OEvf0GVTm0BEyMeA2to+8HEdRPShH0SLYptJY1uBw+SCFP9WVQi1Q/cw==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.34.5.tgz", + "integrity": "sha512-FV9m/7NmeCmSHDD5j4+4pNI8Cp3aW+JvLoXcTUo0IqyjSfAZJ8dIUmijx1qaJsIiU+Hosw6xM5KijAWRJCSgNg==", "cpu": [ "ia32" ], - "dev": true, "license": "Apache-2.0 AND LGPL-3.0-or-later", "optional": true, "os": [ "win32" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -6027,19 +6048,17 @@ } }, "node_modules/@img/sharp-win32-x64": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.34.3.tgz", - "integrity": "sha512-OWwz05d++TxzLEv4VnsTz5CmZ6mI6S05sfQGEMrNrQcOEERbX46332IvE7pO/EUiw7jUrrS40z/M7kPyjfl04g==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.34.5.tgz", + "integrity": "sha512-+29YMsqY2/9eFEiW93eqWnuLcWcufowXewwSNIT6UwZdUUCrM3oFjMWH/Z6/TMmb4hlFenmfAVbpWeup2jryCw==", "cpu": [ "x64" ], - "dev": true, "license": "Apache-2.0 AND LGPL-3.0-or-later", "optional": true, "os": [ "win32" ], - "peer": true, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -6697,24 +6716,37 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/@npmcli/map-workspaces/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/@npmcli/map-workspaces/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.3.tgz", + "integrity": "sha512-fy6KJm2RawA5RcHkLa1z/ScpBeA762UF9KmZQxwIbDtRJrgLzM10depAiEQ+CXYcoiqW1/m96OAAoke2nE9EeA==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" } }, "node_modules/@npmcli/map-workspaces/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.7.tgz", + "integrity": "sha512-MOwgjc8tfrpn5QQEvjijjmDVtMw2oL88ugTevzxQnzRLm6l3fVEF2gzU0kYeYYKD8C66+IdGX6peJ4MyUlUnPg==", "dev": true, "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^5.0.2" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -8607,38 +8639,38 @@ } }, "node_modules/@tailwindcss/cli": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/cli/-/cli-4.1.18.tgz", - "integrity": "sha512-sMZ+lZbDyxwjD2E0L7oRUjJ01Ffjtme5OtjvvnC+cV4CEDcbqzbp25TCpxHj6kWLU9+DlqJOiNgSOgctC2aZmg==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/cli/-/cli-4.2.1.tgz", + "integrity": "sha512-b7MGn51IA80oSG+7fuAgzfQ+7pZBgjzbqwmiv6NO7/+a1sev32cGqnwhscT7h0EcAvMa9r7gjRylqOH8Xhc4DA==", "dev": true, "license": "MIT", "dependencies": { "@parcel/watcher": "^2.5.1", - "@tailwindcss/node": "4.1.18", - "@tailwindcss/oxide": "4.1.18", - "enhanced-resolve": "^5.18.3", + "@tailwindcss/node": "4.2.1", + "@tailwindcss/oxide": "4.2.1", + "enhanced-resolve": "^5.19.0", "mri": "^1.2.0", "picocolors": "^1.1.1", - "tailwindcss": "4.1.18" + "tailwindcss": "4.2.1" }, "bin": { "tailwindcss": "dist/index.mjs" } }, "node_modules/@tailwindcss/node": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.1.18.tgz", - "integrity": "sha512-DoR7U1P7iYhw16qJ49fgXUlry1t4CpXeErJHnQ44JgTSKMaZUdf17cfn5mHchfJ4KRBZRFA/Coo+MUF5+gOaCQ==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.2.1.tgz", + "integrity": "sha512-jlx6sLk4EOwO6hHe1oCGm1Q4AN/s0rSrTTPBGPM0/RQ6Uylwq17FuU8IeJJKEjtc6K6O07zsvP+gDO6MMWo7pg==", "dev": true, "license": "MIT", "dependencies": { - "@jridgewell/remapping": "^2.3.4", - "enhanced-resolve": "^5.18.3", + "@jridgewell/remapping": "^2.3.5", + "enhanced-resolve": "^5.19.0", "jiti": "^2.6.1", - "lightningcss": "1.30.2", + "lightningcss": "1.31.1", "magic-string": "^0.30.21", "source-map-js": "^1.2.1", - "tailwindcss": "4.1.18" + "tailwindcss": "4.2.1" } }, "node_modules/@tailwindcss/node/node_modules/jiti": { @@ -8652,33 +8684,33 @@ } }, "node_modules/@tailwindcss/oxide": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide/-/oxide-4.1.18.tgz", - "integrity": "sha512-EgCR5tTS5bUSKQgzeMClT6iCY3ToqE1y+ZB0AKldj809QXk1Y+3jB0upOYZrn9aGIzPtUsP7sX4QQ4XtjBB95A==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide/-/oxide-4.2.1.tgz", + "integrity": "sha512-yv9jeEFWnjKCI6/T3Oq50yQEOqmpmpfzG1hcZsAOaXFQPfzWprWrlHSdGPEF3WQTi8zu8ohC9Mh9J470nT5pUw==", "dev": true, "license": "MIT", "engines": { - "node": ">= 10" + "node": ">= 20" }, "optionalDependencies": { - "@tailwindcss/oxide-android-arm64": "4.1.18", - "@tailwindcss/oxide-darwin-arm64": "4.1.18", - "@tailwindcss/oxide-darwin-x64": "4.1.18", - "@tailwindcss/oxide-freebsd-x64": "4.1.18", - "@tailwindcss/oxide-linux-arm-gnueabihf": "4.1.18", - "@tailwindcss/oxide-linux-arm64-gnu": "4.1.18", - "@tailwindcss/oxide-linux-arm64-musl": "4.1.18", - "@tailwindcss/oxide-linux-x64-gnu": "4.1.18", - "@tailwindcss/oxide-linux-x64-musl": "4.1.18", - "@tailwindcss/oxide-wasm32-wasi": "4.1.18", - "@tailwindcss/oxide-win32-arm64-msvc": "4.1.18", - "@tailwindcss/oxide-win32-x64-msvc": "4.1.18" + "@tailwindcss/oxide-android-arm64": "4.2.1", + "@tailwindcss/oxide-darwin-arm64": "4.2.1", + "@tailwindcss/oxide-darwin-x64": "4.2.1", + "@tailwindcss/oxide-freebsd-x64": "4.2.1", + "@tailwindcss/oxide-linux-arm-gnueabihf": "4.2.1", + "@tailwindcss/oxide-linux-arm64-gnu": "4.2.1", + "@tailwindcss/oxide-linux-arm64-musl": "4.2.1", + "@tailwindcss/oxide-linux-x64-gnu": "4.2.1", + "@tailwindcss/oxide-linux-x64-musl": "4.2.1", + "@tailwindcss/oxide-wasm32-wasi": "4.2.1", + "@tailwindcss/oxide-win32-arm64-msvc": "4.2.1", + "@tailwindcss/oxide-win32-x64-msvc": "4.2.1" } }, "node_modules/@tailwindcss/oxide-android-arm64": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-android-arm64/-/oxide-android-arm64-4.1.18.tgz", - "integrity": "sha512-dJHz7+Ugr9U/diKJA0W6N/6/cjI+ZTAoxPf9Iz9BFRF2GzEX8IvXxFIi/dZBloVJX/MZGvRuFA9rqwdiIEZQ0Q==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-android-arm64/-/oxide-android-arm64-4.2.1.tgz", + "integrity": "sha512-eZ7G1Zm5EC8OOKaesIKuw77jw++QJ2lL9N+dDpdQiAB/c/B2wDh0QPFHbkBVrXnwNugvrbJFk1gK2SsVjwWReg==", "cpu": [ "arm64" ], @@ -8689,13 +8721,13 @@ "android" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-darwin-arm64": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-arm64/-/oxide-darwin-arm64-4.1.18.tgz", - "integrity": "sha512-Gc2q4Qhs660bhjyBSKgq6BYvwDz4G+BuyJ5H1xfhmDR3D8HnHCmT/BSkvSL0vQLy/nkMLY20PQ2OoYMO15Jd0A==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-arm64/-/oxide-darwin-arm64-4.2.1.tgz", + "integrity": "sha512-q/LHkOstoJ7pI1J0q6djesLzRvQSIfEto148ppAd+BVQK0JYjQIFSK3JgYZJa+Yzi0DDa52ZsQx2rqytBnf8Hw==", "cpu": [ "arm64" ], @@ -8706,13 +8738,13 @@ "darwin" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-darwin-x64": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-x64/-/oxide-darwin-x64-4.1.18.tgz", - "integrity": "sha512-FL5oxr2xQsFrc3X9o1fjHKBYBMD1QZNyc1Xzw/h5Qu4XnEBi3dZn96HcHm41c/euGV+GRiXFfh2hUCyKi/e+yw==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-x64/-/oxide-darwin-x64-4.2.1.tgz", + "integrity": "sha512-/f/ozlaXGY6QLbpvd/kFTro2l18f7dHKpB+ieXz+Cijl4Mt9AI2rTrpq7V+t04nK+j9XBQHnSMdeQRhbGyt6fw==", "cpu": [ "x64" ], @@ -8723,13 +8755,13 @@ "darwin" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-freebsd-x64": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-freebsd-x64/-/oxide-freebsd-x64-4.1.18.tgz", - "integrity": "sha512-Fj+RHgu5bDodmV1dM9yAxlfJwkkWvLiRjbhuO2LEtwtlYlBgiAT4x/j5wQr1tC3SANAgD+0YcmWVrj8R9trVMA==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-freebsd-x64/-/oxide-freebsd-x64-4.2.1.tgz", + "integrity": "sha512-5e/AkgYJT/cpbkys/OU2Ei2jdETCLlifwm7ogMC7/hksI2fC3iiq6OcXwjibcIjPung0kRtR3TxEITkqgn0TcA==", "cpu": [ "x64" ], @@ -8740,13 +8772,13 @@ "freebsd" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-linux-arm-gnueabihf": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm-gnueabihf/-/oxide-linux-arm-gnueabihf-4.1.18.tgz", - "integrity": "sha512-Fp+Wzk/Ws4dZn+LV2Nqx3IilnhH51YZoRaYHQsVq3RQvEl+71VGKFpkfHrLM/Li+kt5c0DJe/bHXK1eHgDmdiA==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm-gnueabihf/-/oxide-linux-arm-gnueabihf-4.2.1.tgz", + "integrity": "sha512-Uny1EcVTTmerCKt/1ZuKTkb0x8ZaiuYucg2/kImO5A5Y/kBz41/+j0gxUZl+hTF3xkWpDmHX+TaWhOtba2Fyuw==", "cpu": [ "arm" ], @@ -8757,81 +8789,93 @@ "linux" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-linux-arm64-gnu": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-gnu/-/oxide-linux-arm64-gnu-4.1.18.tgz", - "integrity": "sha512-S0n3jboLysNbh55Vrt7pk9wgpyTTPD0fdQeh7wQfMqLPM/Hrxi+dVsLsPrycQjGKEQk85Kgbx+6+QnYNiHalnw==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-gnu/-/oxide-linux-arm64-gnu-4.2.1.tgz", + "integrity": "sha512-CTrwomI+c7n6aSSQlsPL0roRiNMDQ/YzMD9EjcR+H4f0I1SQ8QqIuPnsVp7QgMkC1Qi8rtkekLkOFjo7OlEFRQ==", "cpu": [ "arm64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-linux-arm64-musl": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-musl/-/oxide-linux-arm64-musl-4.1.18.tgz", - "integrity": "sha512-1px92582HkPQlaaCkdRcio71p8bc8i/ap5807tPRDK/uw953cauQBT8c5tVGkOwrHMfc2Yh6UuxaH4vtTjGvHg==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-musl/-/oxide-linux-arm64-musl-4.2.1.tgz", + "integrity": "sha512-WZA0CHRL/SP1TRbA5mp9htsppSEkWuQ4KsSUumYQnyl8ZdT39ntwqmz4IUHGN6p4XdSlYfJwM4rRzZLShHsGAQ==", "cpu": [ "arm64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-linux-x64-gnu": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-gnu/-/oxide-linux-x64-gnu-4.1.18.tgz", - "integrity": "sha512-v3gyT0ivkfBLoZGF9LyHmts0Isc8jHZyVcbzio6Wpzifg/+5ZJpDiRiUhDLkcr7f/r38SWNe7ucxmGW3j3Kb/g==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-gnu/-/oxide-linux-x64-gnu-4.2.1.tgz", + "integrity": "sha512-qMFzxI2YlBOLW5PhblzuSWlWfwLHaneBE0xHzLrBgNtqN6mWfs+qYbhryGSXQjFYB1Dzf5w+LN5qbUTPhW7Y5g==", "cpu": [ "x64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-linux-x64-musl": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-musl/-/oxide-linux-x64-musl-4.1.18.tgz", - "integrity": "sha512-bhJ2y2OQNlcRwwgOAGMY0xTFStt4/wyU6pvI6LSuZpRgKQwxTec0/3Scu91O8ir7qCR3AuepQKLU/kX99FouqQ==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-musl/-/oxide-linux-x64-musl-4.2.1.tgz", + "integrity": "sha512-5r1X2FKnCMUPlXTWRYpHdPYUY6a1Ar/t7P24OuiEdEOmms5lyqjDRvVY1yy9Rmioh+AunQ0rWiOTPE8F9A3v5g==", "cpu": [ "x64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-wasm32-wasi": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-wasm32-wasi/-/oxide-wasm32-wasi-4.1.18.tgz", - "integrity": "sha512-LffYTvPjODiP6PT16oNeUQJzNVyJl1cjIebq/rWWBF+3eDst5JGEFSc5cWxyRCJ0Mxl+KyIkqRxk1XPEs9x8TA==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-wasm32-wasi/-/oxide-wasm32-wasi-4.2.1.tgz", + "integrity": "sha512-MGFB5cVPvshR85MTJkEvqDUnuNoysrsRxd6vnk1Lf2tbiqNlXpHYZqkqOQalydienEWOHHFyyuTSYRsLfxFJ2Q==", "bundleDependencies": [ "@napi-rs/wasm-runtime", "@emnapi/core", @@ -8847,81 +8891,21 @@ "license": "MIT", "optional": true, "dependencies": { - "@emnapi/core": "^1.7.1", - "@emnapi/runtime": "^1.7.1", + "@emnapi/core": "^1.8.1", + "@emnapi/runtime": "^1.8.1", "@emnapi/wasi-threads": "^1.1.0", - "@napi-rs/wasm-runtime": "^1.1.0", + "@napi-rs/wasm-runtime": "^1.1.1", "@tybys/wasm-util": "^0.10.1", - "tslib": "^2.4.0" + "tslib": "^2.8.1" }, "engines": { "node": ">=14.0.0" } }, - "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/core": { - "version": "1.7.1", - "dev": true, - "inBundle": true, - "license": "MIT", - "optional": true, - "dependencies": { - "@emnapi/wasi-threads": "1.1.0", - "tslib": "^2.4.0" - } - }, - "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/runtime": { - "version": "1.7.1", - "dev": true, - "inBundle": true, - "license": "MIT", - "optional": true, - "dependencies": { - "tslib": "^2.4.0" - } - }, - "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@emnapi/wasi-threads": { - "version": "1.1.0", - "dev": true, - "inBundle": true, - "license": "MIT", - "optional": true, - "dependencies": { - "tslib": "^2.4.0" - } - }, - "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@napi-rs/wasm-runtime": { - "version": "1.1.0", - "dev": true, - "inBundle": true, - "license": "MIT", - "optional": true, - "dependencies": { - "@emnapi/core": "^1.7.1", - "@emnapi/runtime": "^1.7.1", - "@tybys/wasm-util": "^0.10.1" - } - }, - "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/@tybys/wasm-util": { - "version": "0.10.1", - "dev": true, - "inBundle": true, - "license": "MIT", - "optional": true, - "dependencies": { - "tslib": "^2.4.0" - } - }, - "node_modules/@tailwindcss/oxide-wasm32-wasi/node_modules/tslib": { - "version": "2.8.1", - "dev": true, - "inBundle": true, - "license": "0BSD", - "optional": true - }, "node_modules/@tailwindcss/oxide-win32-arm64-msvc": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.1.18.tgz", - "integrity": "sha512-HjSA7mr9HmC8fu6bdsZvZ+dhjyGCLdotjVOgLA2vEqxEBZaQo9YTX4kwgEvPCpRh8o4uWc4J/wEoFzhEmjvPbA==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.2.1.tgz", + "integrity": "sha512-YlUEHRHBGnCMh4Nj4GnqQyBtsshUPdiNroZj8VPkvTZSoHsilRCwXcVKnG9kyi0ZFAS/3u+qKHBdDc81SADTRA==", "cpu": [ "arm64" ], @@ -8932,13 +8916,13 @@ "win32" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-win32-x64-msvc": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-x64-msvc/-/oxide-win32-x64-msvc-4.1.18.tgz", - "integrity": "sha512-bJWbyYpUlqamC8dpR7pfjA0I7vdF6t5VpUGMWRkXVE3AXgIZjYUYAK7II1GNaxR8J1SSrSrppRar8G++JekE3Q==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-x64-msvc/-/oxide-win32-x64-msvc-4.2.1.tgz", + "integrity": "sha512-rbO34G5sMWWyrN/idLeVxAZgAKWrn5LiR3/I90Q9MkA67s6T1oB0xtTe+0heoBvHSpbU9Mk7i6uwJnpo4u21XQ==", "cpu": [ "x64" ], @@ -8949,19 +8933,19 @@ "win32" ], "engines": { - "node": ">= 10" + "node": ">= 20" } }, "node_modules/@tailwindcss/vite": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/@tailwindcss/vite/-/vite-4.1.18.tgz", - "integrity": "sha512-jVA+/UpKL1vRLg6Hkao5jldawNmRo7mQYrZtNHMIVpLfLhDml5nMRUo/8MwoX2vNXvnaXNNMedrMfMugAVX1nA==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@tailwindcss/vite/-/vite-4.2.1.tgz", + "integrity": "sha512-TBf2sJjYeb28jD2U/OhwdW0bbOsxkWPwQ7SrqGf9sVcoYwZj7rkXljroBO9wKBut9XnmQLXanuDUeqQK0lGg/w==", "dev": true, "license": "MIT", "dependencies": { - "@tailwindcss/node": "4.1.18", - "@tailwindcss/oxide": "4.1.18", - "tailwindcss": "4.1.18" + "@tailwindcss/node": "4.2.1", + "@tailwindcss/oxide": "4.2.1", + "tailwindcss": "4.2.1" }, "peerDependencies": { "vite": "^5.2.0 || ^6 || ^7" @@ -8987,6 +8971,23 @@ "react-dom": ">=16.8" } }, + "node_modules/@tanstack/react-virtual": { + "version": "3.13.22", + "resolved": "https://registry.npmjs.org/@tanstack/react-virtual/-/react-virtual-3.13.22.tgz", + "integrity": "sha512-EaOrBBJLi3M0bTMQRjGkxLXRw7Gizwntoy5E2Q2UnSbML7Mo2a1P/Hfkw5tw9FLzK62bj34Jl6VNbQfRV6eJcA==", + "license": "MIT", + "dependencies": { + "@tanstack/virtual-core": "3.13.22" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", + "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, "node_modules/@tanstack/table-core": { "version": "8.21.3", "resolved": "https://registry.npmjs.org/@tanstack/table-core/-/table-core-8.21.3.tgz", @@ -9000,6 +9001,16 @@ "url": "https://github.com/sponsors/tannerlinsley" } }, + "node_modules/@tanstack/virtual-core": { + "version": "3.13.22", + "resolved": "https://registry.npmjs.org/@tanstack/virtual-core/-/virtual-core-3.13.22.tgz", + "integrity": "sha512-isuUGKsc5TAPDoHSbWTbl1SCil54zOS2MiWz/9GCWHPUQOvNTQx8qJEWC7UWR0lShhbK0Lmkcf0SZYxvch7G3g==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, "node_modules/@trysound/sax": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/@trysound/sax/-/sax-0.2.0.tgz", @@ -10119,45 +10130,6 @@ "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/balanced-match": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", - "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", - "dev": true, - "license": "MIT", - "engines": { - "node": "18 || 20 || >=22" - } - }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.3.tgz", - "integrity": "sha512-fy6KJm2RawA5RcHkLa1z/ScpBeA762UF9KmZQxwIbDtRJrgLzM10depAiEQ+CXYcoiqW1/m96OAAoke2nE9EeA==", - "dev": true, - "license": "MIT", - "dependencies": { - "balanced-match": "^4.0.2" - }, - "engines": { - "node": "18 || 20 || >=22" - } - }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { - "version": "10.2.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.2.tgz", - "integrity": "sha512-+G4CpNBxa5MprY+04MbgOw1v7So6n5JY166pFi9KfYwT78fxScCeSNQSNzp6dpPSW2rONOps6Ocam1wFhCgoVw==", - "dev": true, - "license": "BlueOak-1.0.0", - "dependencies": { - "brace-expansion": "^5.0.2" - }, - "engines": { - "node": "18 || 20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/@typescript-eslint/utils": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.56.1.tgz", @@ -10623,6 +10595,12 @@ "@xterm/xterm": "^5.0.0" } }, + "node_modules/@xterm/addon-image": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/@xterm/addon-image/-/addon-image-0.9.0.tgz", + "integrity": "sha512-oYWA8/QAr5/Emwl1xL7WCoOqeG3IZfpzEz/OVq1j4Oi9934TQmHiyubClikRf0D/jL3JNiNuz/Lsqx0kXQ02BA==", + "license": "MIT" + }, "node_modules/@xterm/addon-search": { "version": "0.15.0", "resolved": "https://registry.npmjs.org/@xterm/addon-search/-/addon-search-0.15.0.tgz", @@ -14517,9 +14495,9 @@ } }, "node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.4.tgz", + "integrity": "sha512-X07nttJQkwkfKfvTPG/KSnE2OMdcUCao6+eXF3wmnIQRn2aPAHH3VxDbDOdegkd6JbPsXqShpvEOHfAT+nCNwQ==", "dev": true, "license": "BSD-3-Clause", "engines": { @@ -14538,9 +14516,9 @@ } }, "node_modules/dir-compare/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.4.tgz", + "integrity": "sha512-twmL+S8+7yIsE9wsqgzU3E8/LumN3M3QELrBZ20OdmQ9jB2JvW5oZtBEmft84k/Gs5CG9mqtWc6Y9vW+JEzGxw==", "dev": true, "license": "ISC", "dependencies": { @@ -14852,9 +14830,9 @@ } }, "node_modules/electron": { - "version": "40.4.1", - "resolved": "https://registry.npmjs.org/electron/-/electron-40.4.1.tgz", - "integrity": "sha512-N1ZXybQZL8kYemO8vAeh9nrk4mSvqlAO8xs0QCHkXIvRnuB/7VGwEehjvQbsU5/f4bmTKpG+2GQERe/zmKpudQ==", + "version": "41.0.2", + "resolved": "https://registry.npmjs.org/electron/-/electron-41.0.2.tgz", + "integrity": "sha512-raotm/aO8kOs1jD8SI8ssJ7EKciQOY295AOOprl1TxW7B0At8m5Ae7qNU1xdMxofiHMR8cNEGi9PKD3U+yT/mA==", "dev": true, "hasInstallScript": true, "license": "MIT", @@ -15210,13 +15188,13 @@ } }, "node_modules/enhanced-resolve": { - "version": "5.18.3", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.18.3.tgz", - "integrity": "sha512-d4lC8xfavMeBjzGr2vECC3fsGXziXZQyJxD868h2M/mBI3PwAuODxAkLkq5HYuvrPYcUtiLzsTo8U3PgX3Ocww==", + "version": "5.19.0", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.19.0.tgz", + "integrity": "sha512-phv3E1Xl4tQOShqSte26C7Fl84EwUdZsyOuSSk9qtAGyyQs2s3jJzComh+Abf4g187lUUAvH+H26omrqia2aGg==", "license": "MIT", "dependencies": { "graceful-fs": "^4.2.4", - "tapable": "^2.2.0" + "tapable": "^2.3.0" }, "engines": { "node": ">=10.13.0" @@ -15284,6 +15262,7 @@ "version": "1.7.0", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz", "integrity": "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==", + "dev": true, "license": "MIT" }, "node_modules/es-object-atoms": { @@ -15522,9 +15501,9 @@ } }, "node_modules/eslint-mdx": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/eslint-mdx/-/eslint-mdx-3.6.2.tgz", - "integrity": "sha512-5hczn5iSSEcwtNtVXFwCKIk6iLEDaZpwc3vjYDl/B779OzaAAK/ou16J2xVdO6ecOLEO1WZqp7MRCQ/WsKDUig==", + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/eslint-mdx/-/eslint-mdx-3.7.0.tgz", + "integrity": "sha512-QpPdJ6EeFthHuIrfgnWneZgwwFNOLFj/nf2jg/tOTBoiUnqNTxUUpTGAn0ZFHYEh5htVVoe5kjvD02oKtxZGeA==", "dev": true, "license": "MIT", "dependencies": { @@ -15539,7 +15518,6 @@ "unified": "^11.0.5", "unified-engine": "^11.2.2", "unist-util-visit": "^5.0.0", - "uvu": "^0.5.6", "vfile": "^6.0.3" }, "engines": { @@ -15560,13 +15538,13 @@ } }, "node_modules/eslint-plugin-mdx": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-mdx/-/eslint-plugin-mdx-3.6.2.tgz", - "integrity": "sha512-RfMd5HYD/9+cqANhVWJbuBRg3huWUsAoGJNGmPsyiRD2X6BaG6bvt1omyk1ORlg81GK8ST7Ojt5fNAuwWhWU8A==", + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-mdx/-/eslint-plugin-mdx-3.7.0.tgz", + "integrity": "sha512-JXaaQPnKqyti/QSOSQDThLV1EemHm/Fe2l/nMKH0vmhvmABtN/yV/9+GtKgh8UTZwrwuTfQq1HW5eR8HXneNLA==", "dev": true, "license": "MIT", "dependencies": { - "eslint-mdx": "^3.6.2", + "eslint-mdx": "^3.7.0", "mdast-util-from-markdown": "^2.0.2", "mdast-util-mdx": "^3.0.0", "micromark-extension-mdxjs": "^3.0.0", @@ -15655,24 +15633,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint/node_modules/espree": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz", - "integrity": "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==", - "dev": true, - "license": "BSD-2-Clause", - "dependencies": { - "acorn": "^8.15.0", - "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.2.1" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, "node_modules/eslint/node_modules/file-entry-cache": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", @@ -15727,18 +15687,31 @@ } }, "node_modules/espree": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", - "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz", + "integrity": "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "acorn": "^8.9.0", + "acorn": "^8.15.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.1" + "eslint-visitor-keys": "^4.2.1" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/espree/node_modules/eslint-visitor-keys": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz", + "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" @@ -16440,9 +16413,9 @@ } }, "node_modules/filelist/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "version": "5.1.8", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.8.tgz", + "integrity": "sha512-7RN35vit8DeBclkofOVmBY0eDAZZQd1HzmukRdSyz95CRh8FT54eqnbj0krQr3mrHR6sfRyYkyhwBWjoV5uqlQ==", "dev": true, "license": "ISC", "dependencies": { @@ -16896,24 +16869,37 @@ "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", "license": "BSD-2-Clause" }, + "node_modules/glob/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/glob/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.3.tgz", + "integrity": "sha512-fy6KJm2RawA5RcHkLa1z/ScpBeA762UF9KmZQxwIbDtRJrgLzM10depAiEQ+CXYcoiqW1/m96OAAoke2nE9EeA==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" } }, "node_modules/glob/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.7.tgz", + "integrity": "sha512-MOwgjc8tfrpn5QQEvjijjmDVtMw2oL88ugTevzxQnzRLm6l3fVEF2gzU0kYeYYKD8C66+IdGX6peJ4MyUlUnPg==", "dev": true, "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^5.0.2" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -16966,9 +16952,9 @@ } }, "node_modules/globals": { - "version": "17.3.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-17.3.0.tgz", - "integrity": "sha512-yMqGUQVVCkD4tqjOJf3TnrvaaHDMYp4VlUSObbkIiuCPe/ofdMBFIAcBbCSRFWOnos6qRiTVStDwqPLUclaxIw==", + "version": "17.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-17.4.0.tgz", + "integrity": "sha512-hjrNztw/VajQwOLsMNT1cbJiH2muO3OROCHnbehc8eY5JyD2gqz4AcMHPqgaOR59DjgUjYAYLeH699g/eWi2jw==", "dev": true, "license": "MIT", "engines": { @@ -17092,9 +17078,9 @@ } }, "node_modules/gray-matter/node_modules/js-yaml": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", - "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "version": "3.14.2", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.2.tgz", + "integrity": "sha512-PMSmkqxr106Xa156c2M265Z+FTrPl+oxd/rgOQy2tijQeK5TxQ43psO1ZCwhVOSdnn+RzkzlRz/eY4BgJBYVpg==", "license": "MIT", "dependencies": { "argparse": "^1.0.7", @@ -19062,9 +19048,9 @@ } }, "node_modules/lightningcss": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.30.2.tgz", - "integrity": "sha512-utfs7Pr5uJyyvDETitgsaqSyjCb2qNRAtuqUeWIAKztsOYdcACf2KtARYXg2pSvhkt+9NfoaNY7fxjl6nuMjIQ==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.31.1.tgz", + "integrity": "sha512-l51N2r93WmGUye3WuFoN5k10zyvrVs0qfKBhyC5ogUQ6Ew6JUSswh78mbSO+IU3nTWsyOArqPCcShdQSadghBQ==", "dev": true, "license": "MPL-2.0", "dependencies": { @@ -19078,23 +19064,23 @@ "url": "https://opencollective.com/parcel" }, "optionalDependencies": { - "lightningcss-android-arm64": "1.30.2", - "lightningcss-darwin-arm64": "1.30.2", - "lightningcss-darwin-x64": "1.30.2", - "lightningcss-freebsd-x64": "1.30.2", - "lightningcss-linux-arm-gnueabihf": "1.30.2", - "lightningcss-linux-arm64-gnu": "1.30.2", - "lightningcss-linux-arm64-musl": "1.30.2", - "lightningcss-linux-x64-gnu": "1.30.2", - "lightningcss-linux-x64-musl": "1.30.2", - "lightningcss-win32-arm64-msvc": "1.30.2", - "lightningcss-win32-x64-msvc": "1.30.2" + "lightningcss-android-arm64": "1.31.1", + "lightningcss-darwin-arm64": "1.31.1", + "lightningcss-darwin-x64": "1.31.1", + "lightningcss-freebsd-x64": "1.31.1", + "lightningcss-linux-arm-gnueabihf": "1.31.1", + "lightningcss-linux-arm64-gnu": "1.31.1", + "lightningcss-linux-arm64-musl": "1.31.1", + "lightningcss-linux-x64-gnu": "1.31.1", + "lightningcss-linux-x64-musl": "1.31.1", + "lightningcss-win32-arm64-msvc": "1.31.1", + "lightningcss-win32-x64-msvc": "1.31.1" } }, "node_modules/lightningcss-android-arm64": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.30.2.tgz", - "integrity": "sha512-BH9sEdOCahSgmkVhBLeU7Hc9DWeZ1Eb6wNS6Da8igvUwAe0sqROHddIlvU06q3WyXVEOYDZ6ykBZQnjTbmo4+A==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.31.1.tgz", + "integrity": "sha512-HXJF3x8w9nQ4jbXRiNppBCqeZPIAfUo8zE/kOEGbW5NZvGc/K7nMxbhIr+YlFlHW5mpbg/YFPdbnCh1wAXCKFg==", "cpu": [ "arm64" ], @@ -19113,9 +19099,9 @@ } }, "node_modules/lightningcss-darwin-arm64": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.30.2.tgz", - "integrity": "sha512-ylTcDJBN3Hp21TdhRT5zBOIi73P6/W0qwvlFEk22fkdXchtNTOU4Qc37SkzV+EKYxLouZ6M4LG9NfZ1qkhhBWA==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.31.1.tgz", + "integrity": "sha512-02uTEqf3vIfNMq3h/z2cJfcOXnQ0GRwQrkmPafhueLb2h7mqEidiCzkE4gBMEH65abHRiQvhdcQ+aP0D0g67sg==", "cpu": [ "arm64" ], @@ -19134,9 +19120,9 @@ } }, "node_modules/lightningcss-darwin-x64": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.30.2.tgz", - "integrity": "sha512-oBZgKchomuDYxr7ilwLcyms6BCyLn0z8J0+ZZmfpjwg9fRVZIR5/GMXd7r9RH94iDhld3UmSjBM6nXWM2TfZTQ==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.31.1.tgz", + "integrity": "sha512-1ObhyoCY+tGxtsz1lSx5NXCj3nirk0Y0kB/g8B8DT+sSx4G9djitg9ejFnjb3gJNWo7qXH4DIy2SUHvpoFwfTA==", "cpu": [ "x64" ], @@ -19155,9 +19141,9 @@ } }, "node_modules/lightningcss-freebsd-x64": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.30.2.tgz", - "integrity": "sha512-c2bH6xTrf4BDpK8MoGG4Bd6zAMZDAXS569UxCAGcA7IKbHNMlhGQ89eRmvpIUGfKWNVdbhSbkQaWhEoMGmGslA==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.31.1.tgz", + "integrity": "sha512-1RINmQKAItO6ISxYgPwszQE1BrsVU5aB45ho6O42mu96UiZBxEXsuQ7cJW4zs4CEodPUioj/QrXW1r9pLUM74A==", "cpu": [ "x64" ], @@ -19176,9 +19162,9 @@ } }, "node_modules/lightningcss-linux-arm-gnueabihf": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.30.2.tgz", - "integrity": "sha512-eVdpxh4wYcm0PofJIZVuYuLiqBIakQ9uFZmipf6LF/HRj5Bgm0eb3qL/mr1smyXIS1twwOxNWndd8z0E374hiA==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.31.1.tgz", + "integrity": "sha512-OOCm2//MZJ87CdDK62rZIu+aw9gBv4azMJuA8/KB74wmfS3lnC4yoPHm0uXZ/dvNNHmnZnB8XLAZzObeG0nS1g==", "cpu": [ "arm" ], @@ -19197,13 +19183,16 @@ } }, "node_modules/lightningcss-linux-arm64-gnu": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.30.2.tgz", - "integrity": "sha512-UK65WJAbwIJbiBFXpxrbTNArtfuznvxAJw4Q2ZGlU8kPeDIWEX1dg3rn2veBVUylA2Ezg89ktszWbaQnxD/e3A==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.31.1.tgz", + "integrity": "sha512-WKyLWztD71rTnou4xAD5kQT+982wvca7E6QoLpoawZ1gP9JM0GJj4Tp5jMUh9B3AitHbRZ2/H3W5xQmdEOUlLg==", "cpu": [ "arm64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MPL-2.0", "optional": true, "os": [ @@ -19218,13 +19207,16 @@ } }, "node_modules/lightningcss-linux-arm64-musl": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.30.2.tgz", - "integrity": "sha512-5Vh9dGeblpTxWHpOx8iauV02popZDsCYMPIgiuw97OJ5uaDsL86cnqSFs5LZkG3ghHoX5isLgWzMs+eD1YzrnA==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.31.1.tgz", + "integrity": "sha512-mVZ7Pg2zIbe3XlNbZJdjs86YViQFoJSpc41CbVmKBPiGmC4YrfeOyz65ms2qpAobVd7WQsbW4PdsSJEMymyIMg==", "cpu": [ "arm64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MPL-2.0", "optional": true, "os": [ @@ -19239,13 +19231,16 @@ } }, "node_modules/lightningcss-linux-x64-gnu": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.30.2.tgz", - "integrity": "sha512-Cfd46gdmj1vQ+lR6VRTTadNHu6ALuw2pKR9lYq4FnhvgBc4zWY1EtZcAc6EffShbb1MFrIPfLDXD6Xprbnni4w==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.31.1.tgz", + "integrity": "sha512-xGlFWRMl+0KvUhgySdIaReQdB4FNudfUTARn7q0hh/V67PVGCs3ADFjw+6++kG1RNd0zdGRlEKa+T13/tQjPMA==", "cpu": [ "x64" ], "dev": true, + "libc": [ + "glibc" + ], "license": "MPL-2.0", "optional": true, "os": [ @@ -19260,13 +19255,16 @@ } }, "node_modules/lightningcss-linux-x64-musl": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.30.2.tgz", - "integrity": "sha512-XJaLUUFXb6/QG2lGIW6aIk6jKdtjtcffUT0NKvIqhSBY3hh9Ch+1LCeH80dR9q9LBjG3ewbDjnumefsLsP6aiA==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.31.1.tgz", + "integrity": "sha512-eowF8PrKHw9LpoZii5tdZwnBcYDxRw2rRCyvAXLi34iyeYfqCQNA9rmUM0ce62NlPhCvof1+9ivRaTY6pSKDaA==", "cpu": [ "x64" ], "dev": true, + "libc": [ + "musl" + ], "license": "MPL-2.0", "optional": true, "os": [ @@ -19281,9 +19279,9 @@ } }, "node_modules/lightningcss-win32-arm64-msvc": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.30.2.tgz", - "integrity": "sha512-FZn+vaj7zLv//D/192WFFVA0RgHawIcHqLX9xuWiQt7P0PtdFEVaxgF9rjM/IRYHQXNnk61/H/gb2Ei+kUQ4xQ==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.31.1.tgz", + "integrity": "sha512-aJReEbSEQzx1uBlQizAOBSjcmr9dCdL3XuC/6HLXAxmtErsj2ICo5yYggg1qOODQMtnjNQv2UHb9NpOuFtYe4w==", "cpu": [ "arm64" ], @@ -19302,9 +19300,9 @@ } }, "node_modules/lightningcss-win32-x64-msvc": { - "version": "1.30.2", - "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.30.2.tgz", - "integrity": "sha512-5g1yc73p+iAkid5phb4oVFMB45417DkRevRbt/El/gKXJk4jid+vPFF/AXbxn05Aky8PapwzZrdJShv5C0avjw==", + "version": "1.31.1", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.31.1.tgz", + "integrity": "sha512-I9aiFrbd7oYHwlnQDqr1Roz+fTz61oDDJX7n9tYF9FJymH1cIN1DtKw3iYt6b8WZgEjoNwVSncwF4wx/ZedMhw==", "cpu": [ "x64" ], @@ -19366,12 +19364,16 @@ } }, "node_modules/loader-runner": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-4.3.0.tgz", - "integrity": "sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==", + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-4.3.1.tgz", + "integrity": "sha512-IWqP2SCPhyVFTBtRcgMHdzlf9ul25NwaFx4wCEH/KjAXuuHY4yNjvPXsBokp8jCB936PyWRaPKUNh8NvylLp2Q==", "license": "MIT", "engines": { "node": ">=6.11.5" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" } }, "node_modules/loader-utils": { @@ -22417,16 +22419,16 @@ "license": "ISC" }, "node_modules/minimatch": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.0.tgz", - "integrity": "sha512-ugkC31VaVg9cF0DFVoADH12k6061zNZkZON+aX8AWsR9GhPcErkcMBceb6znR8wLERM2AkkOxy2nWRLpT9Jq5w==", + "version": "10.2.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.3.tgz", + "integrity": "sha512-Rwi3pnapEqirPSbWbrZaa6N3nmqq4Xer/2XooiOKyV3q12ML06f7MOuc5DVH8ONZIFhwIYQ3yzPH4nt7iWHaTg==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { "brace-expansion": "^5.0.2" }, "engines": { - "node": "20 || >=22" + "node": "18 || 20 || >=22" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -24223,9 +24225,9 @@ } }, "node_modules/postcss": { - "version": "8.5.6", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz", - "integrity": "sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==", + "version": "8.5.8", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.8.tgz", + "integrity": "sha512-OW/rX8O/jXnm82Ey1k44pObPtdblfiuWnrd8X7GJ7emImCOstunGbXUpp7HdBrFQX6rJzn3sPT397Wp5aCwCHg==", "funding": [ { "type": "opencollective", @@ -25820,9 +25822,9 @@ } }, "node_modules/prebuild-install/node_modules/tar-fs": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.3.tgz", - "integrity": "sha512-090nwYJDmlhwFwEW3QQl+vaNnxsO2yVsd45eTKRBzSzu+hlb1w2K9inVq5b0ngXuLVqQ4ApvsUHHnu/zQNkWAg==", + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz", + "integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==", "license": "MIT", "dependencies": { "chownr": "^1.1.1", @@ -28328,19 +28330,6 @@ "tslib": "^2.1.0" } }, - "node_modules/sade": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz", - "integrity": "sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==", - "dev": true, - "license": "MIT", - "dependencies": { - "mri": "^1.1.0" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -28486,9 +28475,9 @@ "license": "Apache-2.0" }, "node_modules/schema-utils": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-4.3.2.tgz", - "integrity": "sha512-Gn/JaSk/Mt9gYubxTtSn/QCV4em9mpAPiR1rqy/Ocu19u/G9J5WWdNoUT4SiV6mFC3y6cxyFcFwdzPM3FgxGAQ==", + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-4.3.3.tgz", + "integrity": "sha512-eflK8wEtyOE6+hsaRVPxvUKYCpRgzLqDTb8krvAsRIwOGlHoSgYLgBXoubGgLd2fT41/OUYdb48v4k4WWHQurA==", "license": "MIT", "dependencies": { "@types/json-schema": "^7.0.9", @@ -28901,17 +28890,16 @@ "license": "MIT" }, "node_modules/sharp": { - "version": "0.34.3", - "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.34.3.tgz", - "integrity": "sha512-eX2IQ6nFohW4DbvHIOLRB3MHFpYqaqvXd3Tp5e/T/dSH83fxaNJQRvDMhASmkNTsNTVF2/OOopzRCt7xokgPfg==", + "version": "0.34.5", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.34.5.tgz", + "integrity": "sha512-Ou9I5Ft9WNcCbXrU9cMgPBcCK8LiwLqcbywW3t4oDV37n1pzpuNLsYiAV8eODnjbtQlSDwZ2cUEeQz4E54Hltg==", + "devOptional": true, "hasInstallScript": true, "license": "Apache-2.0", - "optional": true, - "peer": true, "dependencies": { - "color": "^4.2.3", - "detect-libc": "^2.0.4", - "semver": "^7.7.2" + "@img/colour": "^1.0.0", + "detect-libc": "^2.1.2", + "semver": "^7.7.3" }, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" @@ -28920,37 +28908,38 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-darwin-arm64": "0.34.3", - "@img/sharp-darwin-x64": "0.34.3", - "@img/sharp-libvips-darwin-arm64": "1.2.0", - "@img/sharp-libvips-darwin-x64": "1.2.0", - "@img/sharp-libvips-linux-arm": "1.2.0", - "@img/sharp-libvips-linux-arm64": "1.2.0", - "@img/sharp-libvips-linux-ppc64": "1.2.0", - "@img/sharp-libvips-linux-s390x": "1.2.0", - "@img/sharp-libvips-linux-x64": "1.2.0", - "@img/sharp-libvips-linuxmusl-arm64": "1.2.0", - "@img/sharp-libvips-linuxmusl-x64": "1.2.0", - "@img/sharp-linux-arm": "0.34.3", - "@img/sharp-linux-arm64": "0.34.3", - "@img/sharp-linux-ppc64": "0.34.3", - "@img/sharp-linux-s390x": "0.34.3", - "@img/sharp-linux-x64": "0.34.3", - "@img/sharp-linuxmusl-arm64": "0.34.3", - "@img/sharp-linuxmusl-x64": "0.34.3", - "@img/sharp-wasm32": "0.34.3", - "@img/sharp-win32-arm64": "0.34.3", - "@img/sharp-win32-ia32": "0.34.3", - "@img/sharp-win32-x64": "0.34.3" + "@img/sharp-darwin-arm64": "0.34.5", + "@img/sharp-darwin-x64": "0.34.5", + "@img/sharp-libvips-darwin-arm64": "1.2.4", + "@img/sharp-libvips-darwin-x64": "1.2.4", + "@img/sharp-libvips-linux-arm": "1.2.4", + "@img/sharp-libvips-linux-arm64": "1.2.4", + "@img/sharp-libvips-linux-ppc64": "1.2.4", + "@img/sharp-libvips-linux-riscv64": "1.2.4", + "@img/sharp-libvips-linux-s390x": "1.2.4", + "@img/sharp-libvips-linux-x64": "1.2.4", + "@img/sharp-libvips-linuxmusl-arm64": "1.2.4", + "@img/sharp-libvips-linuxmusl-x64": "1.2.4", + "@img/sharp-linux-arm": "0.34.5", + "@img/sharp-linux-arm64": "0.34.5", + "@img/sharp-linux-ppc64": "0.34.5", + "@img/sharp-linux-riscv64": "0.34.5", + "@img/sharp-linux-s390x": "0.34.5", + "@img/sharp-linux-x64": "0.34.5", + "@img/sharp-linuxmusl-arm64": "0.34.5", + "@img/sharp-linuxmusl-x64": "0.34.5", + "@img/sharp-wasm32": "0.34.5", + "@img/sharp-win32-arm64": "0.34.5", + "@img/sharp-win32-ia32": "0.34.5", + "@img/sharp-win32-x64": "0.34.5" } }, "node_modules/sharp/node_modules/detect-libc": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.4.tgz", - "integrity": "sha512-3UDv+G9CsCKO1WKMGw9fwq/SWJYbI0c5Y7LU1AXYoDdbhE2AHQ6N6Nb34sG8Fj7T5APy8qXDCKuuIHd1BR0tVA==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "devOptional": true, "license": "Apache-2.0", - "optional": true, - "peer": true, "engines": { "node": ">=8" } @@ -29276,6 +29265,15 @@ "websocket-driver": "^0.7.4" } }, + "node_modules/sockjs/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/socks": { "version": "2.8.7", "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.7.tgz", @@ -29822,46 +29820,6 @@ "integrity": "sha512-e4hG1hRwoOdRb37cIMSgzNsxyzKfayW6VOflrwvR+/bzrkyxY/31WkbgnQpgtrNp1SdpJvpUAGTa/ZoiPNDuRQ==", "license": "MIT" }, - "node_modules/svgo": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/svgo/-/svgo-4.0.0.tgz", - "integrity": "sha512-VvrHQ+9uniE+Mvx3+C9IEe/lWasXCU0nXMY2kZeLrHNICuRiC8uMPyM14UEaMOFA5mhyQqEkB02VoQ16n3DLaw==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "dependencies": { - "commander": "^11.1.0", - "css-select": "^5.1.0", - "css-tree": "^3.0.1", - "css-what": "^6.1.0", - "csso": "^5.0.5", - "picocolors": "^1.1.1", - "sax": "^1.4.1" - }, - "bin": { - "svgo": "bin/svgo.js" - }, - "engines": { - "node": ">=16" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/svgo" - } - }, - "node_modules/svgo/node_modules/commander": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", - "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", - "dev": true, - "license": "MIT", - "optional": true, - "peer": true, - "engines": { - "node": ">=16" - } - }, "node_modules/swr": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/swr/-/swr-2.3.6.tgz", @@ -29876,9 +29834,9 @@ } }, "node_modules/synckit": { - "version": "0.11.11", - "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.11.11.tgz", - "integrity": "sha512-MeQTA1r0litLUf0Rp/iisCaL8761lKAZHaimlbGK4j0HysC4PLfqygQj9srcs0m2RdtDYnF8UuYyKpbjHYp7Jw==", + "version": "0.11.12", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.11.12.tgz", + "integrity": "sha512-Bh7QjT8/SuKUIfObSXNHNSK6WHo6J1tHCqJsuaFDP7gP0fkzSfTxI8y85JrppZ0h8l0maIgc2tfuZQ6/t3GtnQ==", "dev": true, "license": "MIT", "dependencies": { @@ -29908,9 +29866,9 @@ } }, "node_modules/tailwindcss": { - "version": "4.1.18", - "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.1.18.tgz", - "integrity": "sha512-4+Z+0yiYyEtUVCScyfHCxOYP06L5Ne+JiHhY2IjR2KWMIWhJOYZKLSGZaP5HkZ8+bY0cxfzwDE5uOmzFXyIwxw==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.2.1.tgz", + "integrity": "sha512-/tBrSQ36vCleJkAOsy9kbNTgaxvGbyOamC30PRePTQe/o1MFwEKHQk4Cn7BNGaPtjp+PuUrByJehM1hgxfq4sw==", "dev": true, "license": "MIT" }, @@ -29925,9 +29883,9 @@ } }, "node_modules/tapable": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.3.tgz", - "integrity": "sha512-ZL6DDuAlRlLGghwcfmSn9sK3Hr6ArtyudlSAiCqQ6IfE+b+HHbydbYDIG15IfS5do+7XQQBdBiubF/cV2dnDzg==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.3.0.tgz", + "integrity": "sha512-g9ljZiwki/LfxmQADO3dEY1CbpmXT5Hm2fJ+QaGKwSXUylMybePR7/67YW7jOrrvjEgL1Fmz5kzyAjWVWLlucg==", "license": "MIT", "engines": { "node": ">=6" @@ -29955,9 +29913,9 @@ } }, "node_modules/tar-fs": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.1.0.tgz", - "integrity": "sha512-5Mty5y/sOF1YWj1J6GiBodjlDc05CUR8PKXrsnFAiSG0xA+GHeWLovaZPYUDXkH/1iKRf2+M5+OrRgzC7O9b7w==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-3.1.1.tgz", + "integrity": "sha512-LZA0oaPOc2fVo82Txf3gw+AkEd38szODlptMYejQUhndHMLQ9M059uXR+AfS7DNo0NpINvSqDsvyaCrBVkptWg==", "license": "MIT", "dependencies": { "pump": "^3.0.0", @@ -30054,9 +30012,9 @@ } }, "node_modules/temp/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.4.tgz", + "integrity": "sha512-twmL+S8+7yIsE9wsqgzU3E8/LumN3M3QELrBZ20OdmQ9jB2JvW5oZtBEmft84k/Gs5CG9mqtWc6Y9vW+JEzGxw==", "dev": true, "license": "ISC", "peer": true, @@ -30101,9 +30059,9 @@ } }, "node_modules/terser-webpack-plugin": { - "version": "5.3.14", - "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.14.tgz", - "integrity": "sha512-vkZjpUjb6OMS7dhV+tILUW6BhpDR7P2L/aQSAv+Uwk+m8KATX9EccViHTJR2qDtACKPIYndLGCyl3FMo+r2LMw==", + "version": "5.3.16", + "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.16.tgz", + "integrity": "sha512-h9oBFCWrq78NyWWVcSwZarJkZ01c2AyGrzs1crmHZO3QUg9D61Wu4NPjBy69n7JqylFF5y+CsUZYmYEIZ3mR+Q==", "license": "MIT", "dependencies": { "@jridgewell/trace-mapping": "^0.3.25", @@ -30184,24 +30142,37 @@ "node": ">=18" } }, + "node_modules/test-exclude/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/test-exclude/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.3.tgz", + "integrity": "sha512-fy6KJm2RawA5RcHkLa1z/ScpBeA762UF9KmZQxwIbDtRJrgLzM10depAiEQ+CXYcoiqW1/m96OAAoke2nE9EeA==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" } }, "node_modules/test-exclude/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.7.tgz", + "integrity": "sha512-MOwgjc8tfrpn5QQEvjijjmDVtMw2oL88ugTevzxQnzRLm6l3fVEF2gzU0kYeYYKD8C66+IdGX6peJ4MyUlUnPg==", "dev": true, "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^5.0.2" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -31910,51 +31881,16 @@ } }, "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "license": "MIT", - "bin": { - "uuid": "dist/bin/uuid" - } - }, - "node_modules/uvu": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/uvu/-/uvu-0.5.6.tgz", - "integrity": "sha512-+g8ENReyr8YsOc6fv/NVJs2vFdHBnBNdfE49rshrTzDWOlUx4Gq7KOS2GD8eqhy2j+Ejq29+SbKH8yjkAqXqoA==", - "dev": true, + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-13.0.0.tgz", + "integrity": "sha512-XQegIaBTVUjSHliKqcnFqYypAd4S+WCYt5NIeRs6w/UAry7z8Y9j5ZwRRL4kzq9U3sD6v+85er9FvkEaBpji2w==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "license": "MIT", - "dependencies": { - "dequal": "^2.0.0", - "diff": "^5.0.0", - "kleur": "^4.0.3", - "sade": "^1.7.3" - }, "bin": { - "uvu": "bin.js" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/uvu/node_modules/diff": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", - "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/uvu/node_modules/kleur": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz", - "integrity": "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" + "uuid": "dist-node/bin/uuid" } }, "node_modules/v8-compile-cache-lib": { @@ -32520,9 +32456,9 @@ "license": "ISC" }, "node_modules/watchpack": { - "version": "2.4.4", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.4.tgz", - "integrity": "sha512-c5EGNOiyxxV5qmTtAB7rbiXxi1ooX1pQKMLX/MIabJjRA0SJBQOjKF+KSVfHkr9U1cADPon0mRiVe/riyaiDUA==", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.5.1.tgz", + "integrity": "sha512-Zn5uXdcFNIA1+1Ei5McRd+iRzfhENPCe7LeABkJtNulSxjma+l7ltNx55BWZkRlwRnpOgHqxnjyaDgJnNXnqzg==", "license": "MIT", "dependencies": { "glob-to-regexp": "^0.4.1", @@ -32566,9 +32502,9 @@ } }, "node_modules/webpack": { - "version": "5.101.3", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.101.3.tgz", - "integrity": "sha512-7b0dTKR3Ed//AD/6kkx/o7duS8H3f1a4w3BYpIriX4BzIhjkn4teo05cptsxvLesHFKK5KObnadmCHBwGc+51A==", + "version": "5.105.2", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.105.2.tgz", + "integrity": "sha512-dRXm0a2qcHPUBEzVk8uph0xWSjV/xZxenQQbLwnwP7caQCYpqG1qddwlyEkIDkYn0K8tvmcrZ+bOrzoQ3HxCDw==", "license": "MIT", "dependencies": { "@types/eslint-scope": "^3.7.7", @@ -32579,22 +32515,22 @@ "@webassemblyjs/wasm-parser": "^1.14.1", "acorn": "^8.15.0", "acorn-import-phases": "^1.0.3", - "browserslist": "^4.24.0", + "browserslist": "^4.28.1", "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^5.17.3", - "es-module-lexer": "^1.2.1", + "enhanced-resolve": "^5.19.0", + "es-module-lexer": "^2.0.0", "eslint-scope": "5.1.1", "events": "^3.2.0", "glob-to-regexp": "^0.4.1", "graceful-fs": "^4.2.11", "json-parse-even-better-errors": "^2.3.1", - "loader-runner": "^4.2.0", + "loader-runner": "^4.3.1", "mime-types": "^2.1.27", "neo-async": "^2.6.2", - "schema-utils": "^4.3.2", - "tapable": "^2.1.1", - "terser-webpack-plugin": "^5.3.11", - "watchpack": "^2.4.1", + "schema-utils": "^4.3.3", + "tapable": "^2.3.0", + "terser-webpack-plugin": "^5.3.16", + "watchpack": "^2.5.1", "webpack-sources": "^3.3.3" }, "bin": { @@ -32902,6 +32838,12 @@ "node": ">=10.13.0" } }, + "node_modules/webpack/node_modules/es-module-lexer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.0.0.tgz", + "integrity": "sha512-5POEcUuZybH7IdmGsD8wlf0AI55wMecM9rVBTI/qEAy2c1kTOm3DjFYjrBdI2K3BaJjJYfYFeRtM0t9ssnRuxw==", + "license": "MIT" + }, "node_modules/webpack/node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -33492,12 +33434,12 @@ "tailwind-merge": "^3.3.1" }, "devDependencies": { - "@tailwindcss/cli": "^4.1.18", - "@tailwindcss/vite": "^4.1.18", + "@tailwindcss/cli": "^4.2.1", + "@tailwindcss/vite": "^4.2.1", "@types/react": "^19", "@types/react-dom": "^19", "@vitejs/plugin-react-swc": "^4.2.3", - "tailwindcss": "^4.1.18", + "tailwindcss": "^4.2.1", "typescript": "^5.9.3", "vite": "^6.4.1" } diff --git a/package.json b/package.json index 67b347b7c..af0ad9a7b 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "productName": "Wave", "description": "Open-Source AI-Native Terminal Built for Seamless Workflows", "license": "Apache-2.0", - "version": "0.14.0", + "version": "0.14.3", "homepage": "https://waveterm.dev", "build": { "appId": "dev.commandline.waveterm" @@ -30,7 +30,7 @@ "devDependencies": { "@eslint/js": "^9.39", "@rollup/plugin-node-resolve": "^16.0.3", - "@tailwindcss/vite": "^4.1.18", + "@tailwindcss/vite": "^4.2.1", "@types/color": "^4.2.0", "@types/css-tree": "^2", "@types/debug": "^4", @@ -48,19 +48,20 @@ "@types/ws": "^8", "@vitejs/plugin-react-swc": "4.2.3", "@vitest/coverage-istanbul": "^3.0.9", - "electron": "^40.4.1", + "electron": "^41.0.2", "electron-builder": "^26.8", "electron-vite": "^5.0", "eslint": "^9.39", "eslint-config-prettier": "^10.1.8", - "globals": "^17.3.0", + "globals": "^17.4.0", "node-abi": "^4.26.0", - "postcss": "^8.5.6", + "postcss": "^8.5.8", "prettier": "^3.8.1", "prettier-plugin-jsdoc": "^1.8.0", "prettier-plugin-organize-imports": "^4.3.0", "sass": "1.91.0", - "tailwindcss": "^4.1.18", + "sharp": "^0.34.5", + "tailwindcss": "^4.2.1", "tailwindcss-animate": "^1.0.7", "ts-node": "^10.9.2", "tslib": "^2.8.1", @@ -81,7 +82,9 @@ "@table-nav/core": "^0.0.7", "@table-nav/react": "^0.0.7", "@tanstack/react-table": "^8.21.3", + "@tanstack/react-virtual": "^3.13.19", "@xterm/addon-fit": "^0.10.0", + "@xterm/addon-image": "^0.9.0", "@xterm/addon-search": "^0.15.0", "@xterm/addon-serialize": "^0.13.0", "@xterm/addon-web-links": "^0.11.0", @@ -140,6 +143,7 @@ "tinycolor2": "^1.6.0", "unist-util-visit": "^5.1.0", "use-device-pixel-ratio": "^1.1.2", + "uuid": "^13.0.0", "winston": "^3.19.0", "ws": "^8.19.0", "yaml": "^2.7.1" diff --git a/pkg/aiusechat/aiutil/aiutil.go b/pkg/aiusechat/aiutil/aiutil.go index 8918d3003..075dd58e7 100644 --- a/pkg/aiusechat/aiutil/aiutil.go +++ b/pkg/aiusechat/aiutil/aiutil.go @@ -11,6 +11,8 @@ import ( "encoding/hex" "encoding/json" "fmt" + "net/http" + "net/url" "strconv" "strings" "time" @@ -185,6 +187,24 @@ func JsonEncodeRequestBody(reqBody any) (bytes.Buffer, error) { return buf, nil } +func MakeHTTPClient(proxyURL string) (*http.Client, error) { + client := &http.Client{ + Timeout: 0, // rely on ctx; streaming can be long + } + if proxyURL == "" { + return client, nil + } + + pURL, err := url.Parse(proxyURL) + if err != nil { + return nil, fmt.Errorf("invalid proxy URL: %w", err) + } + client.Transport = &http.Transport{ + Proxy: http.ProxyURL(pURL), + } + return client, nil +} + func IsOpenAIReasoningModel(model string) bool { m := strings.ToLower(model) return CheckModelPrefix(m, "o1") || diff --git a/pkg/aiusechat/anthropic/anthropic-backend.go b/pkg/aiusechat/anthropic/anthropic-backend.go index 987b8c117..02070b1bf 100644 --- a/pkg/aiusechat/anthropic/anthropic-backend.go +++ b/pkg/aiusechat/anthropic/anthropic-backend.go @@ -10,16 +10,18 @@ import ( "errors" "fmt" "io" - "log" "net/http" "net/url" + "sort" "strings" "time" "github.com/google/uuid" "github.com/launchdarkly/eventsource" + "github.com/wavetermdev/waveterm/pkg/aiusechat/aiutil" "github.com/wavetermdev/waveterm/pkg/aiusechat/chatstore" "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" + "github.com/wavetermdev/waveterm/pkg/util/logutil" "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/web/sse" ) @@ -56,10 +58,11 @@ func (m *anthropicChatMessage) GetUsage() *uctypes.AIUsage { } return &uctypes.AIUsage{ - APIType: uctypes.APIType_AnthropicMessages, - Model: m.Usage.Model, - InputTokens: m.Usage.InputTokens, - OutputTokens: m.Usage.OutputTokens, + APIType: uctypes.APIType_AnthropicMessages, + Model: m.Usage.Model, + InputTokens: m.Usage.InputTokens, + OutputTokens: m.Usage.OutputTokens, + NativeWebSearchCount: m.Usage.NativeWebSearchCount, } } @@ -95,8 +98,9 @@ type anthropicMessageContentBlock struct { Name string `json:"name,omitempty"` Input interface{} `json:"input,omitempty"` - ToolUseDisplayName string `json:"toolusedisplayname,omitempty"` // internal field (cannot marshal to API, must be stripped) - ToolUseShortDescription string `json:"tooluseshortdescription,omitempty"` // internal field (cannot marshal to API, must be stripped) + ToolUseDisplayName string `json:"toolusedisplayname,omitempty"` // internal field (cannot marshal to API, must be stripped) + ToolUseShortDescription string `json:"tooluseshortdescription,omitempty"` // internal field (cannot marshal to API, must be stripped) + ToolUseData *uctypes.UIMessageDataToolUse `json:"toolusedata,omitempty"` // internal field (cannot marshal to API, must be stripped) // Tool result content ToolUseID string `json:"tool_use_id,omitempty"` @@ -154,6 +158,7 @@ func (b *anthropicMessageContentBlock) Clean() *anthropicMessageContentBlock { rtn.SourcePreviewUrl = "" rtn.ToolUseDisplayName = "" rtn.ToolUseShortDescription = "" + rtn.ToolUseData = nil if rtn.Source != nil { rtn.Source = rtn.Source.Clean() } @@ -177,10 +182,15 @@ type anthropicStreamRequest struct { Stream bool `json:"stream"` System []anthropicMessageContentBlock `json:"system,omitempty"` ToolChoice any `json:"tool_choice,omitempty"` - Tools []uctypes.ToolDefinition `json:"tools,omitempty"` + Tools []any `json:"tools,omitempty"` // *uctypes.ToolDefinition or *anthropicWebSearchTool Thinking *anthropicThinkingOpts `json:"thinking,omitempty"` } +type anthropicWebSearchTool struct { + Type string `json:"type"` // "web_search_20250305" + Name string `json:"name"` // "web_search" +} + type anthropicCacheControl struct { Type string `json:"type"` // "ephemeral" TTL string `json:"ttl"` // "5m" or "1h" @@ -228,8 +238,9 @@ type anthropicUsageType struct { CacheCreationInputTokens int `json:"cache_creation_input_tokens,omitempty"` CacheReadInputTokens int `json:"cache_read_input_tokens,omitempty"` - // internal field for Wave use (not sent to API) - Model string `json:"model,omitempty"` + // internal fields for Wave use (not sent to API) + Model string `json:"model,omitempty"` + NativeWebSearchCount int `json:"nativewebsearchcount,omitempty"` // for reference, but we dont keep thsese up to date or track them CacheCreation *anthropicCacheCreationType `json:"cache_creation,omitempty"` // breakdown of cached tokens by TTL @@ -290,14 +301,16 @@ type partialJSON struct { } type streamingState struct { - blockMap map[int]*blockState - toolCalls []uctypes.WaveToolCall - stopFromDelta string - msgID string - model string - stepStarted bool - rtnMessage *anthropicChatMessage - usage *anthropicUsageType + blockMap map[int]*blockState + toolCalls []uctypes.WaveToolCall + stopFromDelta string + msgID string + model string + stepStarted bool + rtnMessage *anthropicChatMessage + usage *anthropicUsageType + chatOpts uctypes.WaveChatOpts + webSearchCount int } func (p *partialJSON) Write(s string) { @@ -330,6 +343,20 @@ func (p *partialJSON) FinalObject() (json.RawMessage, error) { } } +// sanitizeHostnameInError removes the Wave cloud hostname from error messages +func sanitizeHostnameInError(err error) error { + if err == nil { + return nil + } + errStr := err.Error() + parsedURL, parseErr := url.Parse(uctypes.DefaultAIEndpoint) + if parseErr == nil && parsedURL.Host != "" && strings.Contains(errStr, parsedURL.Host) { + errStr = strings.ReplaceAll(errStr, uctypes.DefaultAIEndpoint, "AI service") + errStr = strings.ReplaceAll(errStr, parsedURL.Host, "host") + } + return fmt.Errorf("%s", errStr) +} + // makeThinkingOpts creates thinking options based on level and max tokens func makeThinkingOpts(thinkingLevel string, maxTokens int) *anthropicThinkingOpts { if thinkingLevel != uctypes.ThinkingLevelMedium && thinkingLevel != uctypes.ThinkingLevelHigh { @@ -373,13 +400,13 @@ func parseAnthropicHTTPError(resp *http.Response) error { // Try to parse as Anthropic error format first var eresp anthropicHTTPErrorResponse if err := json.Unmarshal(slurp, &eresp); err == nil && eresp.Error.Message != "" { - return fmt.Errorf("anthropic %s: %s", resp.Status, eresp.Error.Message) + return sanitizeHostnameInError(fmt.Errorf("anthropic %s: %s", resp.Status, eresp.Error.Message)) } // Try to parse as proxy error format var proxyErr uctypes.ProxyErrorResponse if err := json.Unmarshal(slurp, &proxyErr); err == nil && !proxyErr.Success && proxyErr.Error != "" { - return fmt.Errorf("anthropic %s: %s", resp.Status, proxyErr.Error) + return sanitizeHostnameInError(fmt.Errorf("anthropic %s: %s", resp.Status, proxyErr.Error)) } // Fall back to truncated raw response @@ -387,7 +414,7 @@ func parseAnthropicHTTPError(resp *http.Response) error { if msg == "" { msg = "unknown error" } - return fmt.Errorf("anthropic %s: %s", resp.Status, msg) + return sanitizeHostnameInError(fmt.Errorf("anthropic %s: %s", resp.Status, msg)) } func RunAnthropicChatStep( @@ -426,7 +453,7 @@ func RunAnthropicChatStep( // Validate continuation if provided if cont != nil { - if chatOpts.Config.Model != cont.Model { + if !uctypes.AreModelsCompatible(chat.APIType, chatOpts.Config.Model, cont.Model) { return nil, nil, nil, fmt.Errorf("cannot continue with a different model, model:%q, cont-model:%q", chatOpts.Config.Model, cont.Model) } } @@ -454,23 +481,14 @@ func RunAnthropicChatStep( return nil, nil, nil, err } - httpClient := &http.Client{ - Timeout: 0, // rely on ctx; streaming can be long - } - // Proxy support - if chatOpts.Config.ProxyURL != "" { - pURL, perr := url.Parse(chatOpts.Config.ProxyURL) - if perr != nil { - return nil, nil, nil, fmt.Errorf("invalid proxy URL: %w", perr) - } - httpClient.Transport = &http.Transport{ - Proxy: http.ProxyURL(pURL), - } + httpClient, err := aiutil.MakeHTTPClient(chatOpts.Config.ProxyURL) + if err != nil { + return nil, nil, nil, err } resp, err := httpClient.Do(req) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, sanitizeHostnameInError(err) } defer resp.Body.Close() @@ -508,7 +526,7 @@ func RunAnthropicChatStep( // Use eventsource decoder for proper SSE parsing decoder := eventsource.NewDecoder(resp.Body) - stopReason, rtnMessage := handleAnthropicStreamingResp(ctx, sse, decoder, cont) + stopReason, rtnMessage := handleAnthropicStreamingResp(ctx, sse, decoder, cont, chatOpts) return stopReason, rtnMessage, rateLimitInfo, nil } @@ -518,6 +536,7 @@ func handleAnthropicStreamingResp( sse *sse.SSEHandlerCh, decoder *eventsource.Decoder, cont *uctypes.WaveContinueResponse, + chatOpts uctypes.WaveChatOpts, ) (*uctypes.WaveStopReason, *anthropicChatMessage) { // Per-response state state := &streamingState{ @@ -527,6 +546,7 @@ func handleAnthropicStreamingResp( Role: "assistant", Content: []anthropicMessageContentBlock{}, }, + chatOpts: chatOpts, } var rtnStopReason *uctypes.WaveStopReason @@ -535,8 +555,10 @@ func handleAnthropicStreamingResp( defer func() { // Set usage in the returned message if state.usage != nil { - // Set model in usage for internal use state.usage.Model = state.model + if state.webSearchCount > 0 { + state.usage.NativeWebSearchCount = state.webSearchCount + } state.rtnMessage.Usage = state.usage } @@ -567,6 +589,13 @@ func handleAnthropicStreamingResp( // Normal end of stream break } + if sse.Err() != nil { + return &uctypes.WaveStopReason{ + Kind: uctypes.StopKindCanceled, + ErrorType: "client_disconnect", + ErrorText: "client disconnected", + }, extractPartialTextFromState(state) + } // transport error mid-stream _ = sse.AiMsgError(err.Error()) return &uctypes.WaveStopReason{ @@ -596,6 +625,37 @@ func handleAnthropicStreamingResp( return rtnStopReason, state.rtnMessage } +func extractPartialTextFromState(state *streamingState) *anthropicChatMessage { + var content []anthropicMessageContentBlock + for _, block := range state.rtnMessage.Content { + if block.Type == "text" && block.Text != "" { + content = append(content, block) + } + } + var partialIdx []int + for idx, st := range state.blockMap { + if st.kind == blockText && st.contentBlock != nil && st.contentBlock.Text != "" { + partialIdx = append(partialIdx, idx) + } + } + sort.Ints(partialIdx) + for _, idx := range partialIdx { + st := state.blockMap[idx] + if st.kind == blockText && st.contentBlock != nil && st.contentBlock.Text != "" { + content = append(content, *st.contentBlock) + } + } + if len(content) == 0 { + return nil + } + return &anthropicChatMessage{ + MessageId: state.rtnMessage.MessageId, + Role: "assistant", + Content: content, + Usage: state.rtnMessage.Usage, + } +} + // handleAnthropicEvent processes one SSE event block. It may emit SSE parts // and/or return a StopReason when the stream is complete. // @@ -610,6 +670,13 @@ func handleAnthropicEvent( state *streamingState, cont *uctypes.WaveContinueResponse, ) (stopFromDelta *string, final *uctypes.WaveStopReason) { + if err := sse.Err(); err != nil { + return nil, &uctypes.WaveStopReason{ + Kind: uctypes.StopKindCanceled, + ErrorType: "client_disconnect", + ErrorText: "client disconnected", + } + } eventName := event.Event() data := event.Data() switch eventName { @@ -702,6 +769,10 @@ func handleAnthropicEvent( } state.blockMap[idx] = st _ = sse.AiMsgToolInputStart(tcID, tName) + case "server_tool_use": + if ev.ContentBlock.Name == "web_search" { + state.webSearchCount++ + } default: // ignore other block types gracefully per Anthropic guidance :contentReference[oaicite:18]{index=18} } @@ -741,6 +812,7 @@ func handleAnthropicEvent( if st.kind == blockToolUse { st.accumJSON.Write(ev.Delta.PartialJSON) _ = sse.AiMsgToolInputDelta(st.toolCallID, ev.Delta.PartialJSON) + aiutil.SendToolProgress(st.toolCallID, st.toolName, st.accumJSON.Bytes(), state.chatOpts, sse, true) } case "signature_delta": // Accumulate signature for thinking blocks @@ -793,6 +865,7 @@ func handleAnthropicEvent( } } _ = sse.AiMsgToolInputAvailable(st.toolCallID, st.toolName, raw) + aiutil.SendToolProgress(st.toolCallID, st.toolName, raw, state.chatOpts, sse, false) state.toolCalls = append(state.toolCalls, uctypes.WaveToolCall{ ID: st.toolCallID, Name: st.toolName, @@ -807,6 +880,9 @@ func handleAnthropicEvent( } state.rtnMessage.Content = append(state.rtnMessage.Content, toolUseBlock) } + // extractPartialTextFromState reads blockMap for still-in-flight content, so remove completed blocks + // once they have been appended to rtnMessage.Content to avoid duplicate text on disconnect. + delete(state.blockMap, *ev.Index) return nil, nil case "message_delta": @@ -877,7 +953,7 @@ func handleAnthropicEvent( } default: - log.Printf("unknown anthropic event type: %s", eventName) + logutil.DevPrintf("unknown anthropic event type: %s", eventName) return nil, nil } } diff --git a/pkg/aiusechat/anthropic/anthropic-backend_test.go b/pkg/aiusechat/anthropic/anthropic-backend_test.go index 8d9acb78e..71e89bfb2 100644 --- a/pkg/aiusechat/anthropic/anthropic-backend_test.go +++ b/pkg/aiusechat/anthropic/anthropic-backend_test.go @@ -6,6 +6,7 @@ package anthropic import ( "testing" + "github.com/wavetermdev/waveterm/pkg/aiusechat/chatstore" "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" ) @@ -69,3 +70,97 @@ func TestConvertPartsToAnthropicBlocks_SkipsUnknownTypes(t *testing.T) { t.Errorf("expected second text 'Another valid text', got %v", block2.Text) } } + +func TestGetFunctionCallInputByToolCallId(t *testing.T) { + toolData := &uctypes.UIMessageDataToolUse{ToolCallId: "call-1", ToolName: "read_file", Status: uctypes.ToolUseStatusPending} + chat := uctypes.AIChat{ + NativeMessages: []uctypes.GenAIMessage{ + &anthropicChatMessage{ + MessageId: "m1", + Role: "assistant", + Content: []anthropicMessageContentBlock{ + {Type: "tool_use", ID: "call-1", Name: "read_file", Input: map[string]interface{}{"path": "/tmp/a"}, ToolUseData: toolData}, + }, + }, + }, + } + fnCall := GetFunctionCallInputByToolCallId(chat, "call-1") + if fnCall == nil { + t.Fatalf("expected function call input") + } + if fnCall.CallId != "call-1" || fnCall.Name != "read_file" { + t.Fatalf("unexpected function call input: %#v", fnCall) + } + if fnCall.Arguments != "{\"path\":\"/tmp/a\"}" { + t.Fatalf("unexpected arguments: %s", fnCall.Arguments) + } + if fnCall.ToolUseData == nil || fnCall.ToolUseData.ToolCallId != "call-1" { + t.Fatalf("expected tool use data") + } +} + +func TestUpdateAndRemoveToolUseCall(t *testing.T) { + chatID := "anthropic-test-tooluse" + chatstore.DefaultChatStore.Delete(chatID) + defer chatstore.DefaultChatStore.Delete(chatID) + + aiOpts := &uctypes.AIOptsType{ + APIType: uctypes.APIType_AnthropicMessages, + Model: "claude-sonnet-4-5", + APIVersion: AnthropicDefaultAPIVersion, + } + msg := &anthropicChatMessage{ + MessageId: "m1", + Role: "assistant", + Content: []anthropicMessageContentBlock{ + {Type: "text", Text: "start"}, + {Type: "tool_use", ID: "call-1", Name: "read_file", Input: map[string]interface{}{"path": "/tmp/a"}}, + }, + } + if err := chatstore.DefaultChatStore.PostMessage(chatID, aiOpts, msg); err != nil { + t.Fatalf("failed to seed chat: %v", err) + } + + newData := uctypes.UIMessageDataToolUse{ToolCallId: "call-1", ToolName: "read_file", Status: uctypes.ToolUseStatusCompleted} + if err := UpdateToolUseData(chatID, "call-1", newData); err != nil { + t.Fatalf("update failed: %v", err) + } + + chat := chatstore.DefaultChatStore.Get(chatID) + updated := chat.NativeMessages[0].(*anthropicChatMessage) + if updated.Content[1].ToolUseData == nil || updated.Content[1].ToolUseData.Status != uctypes.ToolUseStatusCompleted { + t.Fatalf("tool use data not updated") + } + + if err := RemoveToolUseCall(chatID, "call-1"); err != nil { + t.Fatalf("remove failed: %v", err) + } + chat = chatstore.DefaultChatStore.Get(chatID) + updated = chat.NativeMessages[0].(*anthropicChatMessage) + if len(updated.Content) != 1 || updated.Content[0].Type != "text" { + t.Fatalf("expected tool_use block removed, got %#v", updated.Content) + } +} + +func TestConvertToUIMessageIncludesToolUseData(t *testing.T) { + msg := &anthropicChatMessage{ + MessageId: "m1", + Role: "assistant", + Content: []anthropicMessageContentBlock{ + { + Type: "tool_use", + ID: "call-1", + Name: "read_file", + Input: map[string]interface{}{"path": "/tmp/a"}, + ToolUseData: &uctypes.UIMessageDataToolUse{ToolCallId: "call-1", ToolName: "read_file", Status: uctypes.ToolUseStatusPending}, + }, + }, + } + ui := msg.ConvertToUIMessage() + if ui == nil || len(ui.Parts) != 2 { + t.Fatalf("expected tool and data-tooluse parts, got %#v", ui) + } + if ui.Parts[0].Type != "tool-read_file" || ui.Parts[1].Type != "data-tooluse" { + t.Fatalf("unexpected part types: %#v", ui.Parts) + } +} diff --git a/pkg/aiusechat/anthropic/anthropic-convertmessage.go b/pkg/aiusechat/anthropic/anthropic-convertmessage.go index 7fec54b1a..552cc8080 100644 --- a/pkg/aiusechat/anthropic/anthropic-convertmessage.go +++ b/pkg/aiusechat/anthropic/anthropic-convertmessage.go @@ -13,10 +13,13 @@ import ( "log" "net/http" "regexp" + "slices" "strings" "github.com/google/uuid" + "github.com/wavetermdev/waveterm/pkg/aiusechat/chatstore" "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" + "github.com/wavetermdev/waveterm/pkg/util/logutil" "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/wavebase" ) @@ -119,24 +122,23 @@ func buildAnthropicHTTPRequest(ctx context.Context, msgs []anthropicInputMessage reqBody.System = systemBlocks } - if len(chatOpts.Tools) > 0 { - cleanedTools := make([]uctypes.ToolDefinition, len(chatOpts.Tools)) - for i, tool := range chatOpts.Tools { - cleanedTools[i] = *tool.Clean() - } - reqBody.Tools = cleanedTools + for _, tool := range chatOpts.Tools { + cleanedTool := tool.Clean() + reqBody.Tools = append(reqBody.Tools, cleanedTool) } for _, tool := range chatOpts.TabTools { - cleanedTool := *tool.Clean() + cleanedTool := tool.Clean() reqBody.Tools = append(reqBody.Tools, cleanedTool) } + if chatOpts.AllowNativeWebSearch { + reqBody.Tools = append(reqBody.Tools, &anthropicWebSearchTool{Type: "web_search_20250305", Name: "web_search"}) + } // Enable extended thinking based on level reqBody.Thinking = makeThinkingOpts(opts.ThinkingLevel, maxTokens) // pretty print json of anthropicMsgs if jsonStr, err := utilfn.MarshalIndentNoHTMLString(convertedMsgs, "", " "); err == nil { - log.Printf("system-prompt: %v\n", chatOpts.SystemPrompt) var toolNames []string for _, tool := range chatOpts.Tools { toolNames = append(toolNames, tool.Name) @@ -144,9 +146,12 @@ func buildAnthropicHTTPRequest(ctx context.Context, msgs []anthropicInputMessage for _, tool := range chatOpts.TabTools { toolNames = append(toolNames, tool.Name) } - log.Printf("tools: %s\n", strings.Join(toolNames, ", ")) - log.Printf("anthropicMsgs JSON:\n%s", jsonStr) - log.Printf("has-api-key: %v\n", opts.APIToken != "") + if chatOpts.AllowNativeWebSearch { + toolNames = append(toolNames, "web_search[server]") + } + logutil.DevPrintf("tools: %s\n", strings.Join(toolNames, ", ")) + logutil.DevPrintf("anthropicMsgs JSON:\n%s", jsonStr) + logutil.DevPrintf("has-api-key: %v\n", opts.APIToken != "") } var buf bytes.Buffer @@ -698,6 +703,13 @@ func (m *anthropicChatMessage) ConvertToUIMessage() *uctypes.UIMessage { ToolCallID: block.ID, Input: block.Input, }) + if block.ToolUseData != nil { + parts = append(parts, uctypes.UIMessagePart{ + Type: "data-tooluse", + ID: block.ID, + Data: *block.ToolUseData, + }) + } } default: // For now, skip all other types (will implement later) @@ -827,3 +839,102 @@ func ConvertAIChatToUIChat(aiChat uctypes.AIChat) (*uctypes.UIChat, error) { Messages: uiMessages, }, nil } + +func GetFunctionCallInputByToolCallId(aiChat uctypes.AIChat, toolCallId string) *uctypes.AIFunctionCallInput { + for _, genMsg := range aiChat.NativeMessages { + chatMsg, ok := genMsg.(*anthropicChatMessage) + if !ok { + continue + } + for _, block := range chatMsg.Content { + if block.Type != "tool_use" || block.ID != toolCallId { + continue + } + argsInput := block.Input + if argsInput == nil { + argsInput = map[string]interface{}{} + } + argsBytes, err := json.Marshal(argsInput) + if err != nil { + continue + } + return &uctypes.AIFunctionCallInput{ + CallId: block.ID, + Name: block.Name, + Arguments: string(argsBytes), + ToolUseData: block.ToolUseData, + } + } + } + return nil +} + +func UpdateToolUseData(chatId string, toolCallId string, toolUseData uctypes.UIMessageDataToolUse) error { + chat := chatstore.DefaultChatStore.Get(chatId) + if chat == nil { + return fmt.Errorf("chat not found: %s", chatId) + } + for _, genMsg := range chat.NativeMessages { + chatMsg, ok := genMsg.(*anthropicChatMessage) + if !ok { + continue + } + for i, block := range chatMsg.Content { + if block.Type != "tool_use" || block.ID != toolCallId { + continue + } + updatedMsg := &anthropicChatMessage{ + MessageId: chatMsg.MessageId, + Usage: chatMsg.Usage, + Role: chatMsg.Role, + Content: slices.Clone(chatMsg.Content), + } + updatedMsg.Content[i].ToolUseData = &toolUseData + aiOpts := &uctypes.AIOptsType{ + APIType: chat.APIType, + Model: chat.Model, + APIVersion: chat.APIVersion, + } + return chatstore.DefaultChatStore.PostMessage(chatId, aiOpts, updatedMsg) + } + } + return fmt.Errorf("tool call with ID %s not found in chat %s", toolCallId, chatId) +} + +func RemoveToolUseCall(chatId string, toolCallId string) error { + chat := chatstore.DefaultChatStore.Get(chatId) + if chat == nil { + return fmt.Errorf("chat not found: %s", chatId) + } + for _, genMsg := range chat.NativeMessages { + chatMsg, ok := genMsg.(*anthropicChatMessage) + if !ok { + continue + } + for i, block := range chatMsg.Content { + if block.Type != "tool_use" || block.ID != toolCallId { + continue + } + updatedMsg := &anthropicChatMessage{ + MessageId: chatMsg.MessageId, + Usage: chatMsg.Usage, + Role: chatMsg.Role, + Content: slices.Delete(slices.Clone(chatMsg.Content), i, i+1), + } + if len(updatedMsg.Content) == 0 { + chatstore.DefaultChatStore.RemoveMessage(chatId, chatMsg.MessageId) + } else { + aiOpts := &uctypes.AIOptsType{ + APIType: chat.APIType, + Model: chat.Model, + APIVersion: chat.APIVersion, + } + if err := chatstore.DefaultChatStore.PostMessage(chatId, aiOpts, updatedMsg); err != nil { + return err + } + } + return nil + } + } + return nil +} diff --git a/pkg/aiusechat/gemini/gemini-backend.go b/pkg/aiusechat/gemini/gemini-backend.go index 23a331ded..728df59a4 100644 --- a/pkg/aiusechat/gemini/gemini-backend.go +++ b/pkg/aiusechat/gemini/gemini-backend.go @@ -231,8 +231,9 @@ func RunGeminiChatStep( return nil, nil, nil, err } - httpClient := &http.Client{ - Timeout: 0, // rely on ctx; streaming can be long + httpClient, err := aiutil.MakeHTTPClient(chatOpts.Config.ProxyURL) + if err != nil { + return nil, nil, nil, err } resp, err := httpClient.Do(req) diff --git a/pkg/aiusechat/openai/openai-backend.go b/pkg/aiusechat/openai/openai-backend.go index dc9172341..dfb14b70d 100644 --- a/pkg/aiusechat/openai/openai-backend.go +++ b/pkg/aiusechat/openai/openai-backend.go @@ -528,18 +528,9 @@ func RunOpenAIChatStep( return nil, nil, nil, err } - httpClient := &http.Client{ - Timeout: 0, // rely on ctx; streaming can be long - } - // Proxy support - if chatOpts.Config.ProxyURL != "" { - pURL, perr := url.Parse(chatOpts.Config.ProxyURL) - if perr != nil { - return nil, nil, nil, fmt.Errorf("invalid proxy URL: %w", perr) - } - httpClient.Transport = &http.Transport{ - Proxy: http.ProxyURL(pURL), - } + httpClient, err := aiutil.MakeHTTPClient(chatOpts.Config.ProxyURL) + if err != nil { + return nil, nil, nil, err } resp, err := httpClient.Do(req) diff --git a/pkg/aiusechat/openaichat/openaichat-backend.go b/pkg/aiusechat/openaichat/openaichat-backend.go index 7b90aee67..635f33487 100644 --- a/pkg/aiusechat/openaichat/openaichat-backend.go +++ b/pkg/aiusechat/openaichat/openaichat-backend.go @@ -16,6 +16,7 @@ import ( "github.com/google/uuid" "github.com/launchdarkly/eventsource" + "github.com/wavetermdev/waveterm/pkg/aiusechat/aiutil" "github.com/wavetermdev/waveterm/pkg/aiusechat/chatstore" "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" "github.com/wavetermdev/waveterm/pkg/web/sse" @@ -60,7 +61,10 @@ func RunChatStep( return nil, nil, nil, err } - client := &http.Client{} + client, err := aiutil.MakeHTTPClient(chatOpts.Config.ProxyURL) + if err != nil { + return nil, nil, nil, err + } resp, err := client.Do(req) if err != nil { return nil, nil, nil, fmt.Errorf("request failed: %w", err) diff --git a/pkg/aiusechat/tools_readdir_test.go b/pkg/aiusechat/tools_readdir_test.go index 7560a73a4..7d91f7dfc 100644 --- a/pkg/aiusechat/tools_readdir_test.go +++ b/pkg/aiusechat/tools_readdir_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" + "github.com/wavetermdev/waveterm/pkg/util/fileutil" ) func TestReadDirCallback(t *testing.T) { @@ -64,16 +65,16 @@ func TestReadDirCallback(t *testing.T) { t.Errorf("Expected 3 entries, got %d", entryCount) } - entries, ok := resultMap["entries"].([]map[string]any) + entries, ok := resultMap["entries"].([]fileutil.DirEntryOut) if !ok { - t.Fatalf("entries is not a slice of maps") + t.Fatalf("entries is not a slice of DirEntryOut") } // Check that we have the expected entries foundFiles := 0 foundDirs := 0 for _, entry := range entries { - if entry["is_dir"].(bool) { + if entry.Dir { foundDirs++ } else { foundFiles++ @@ -208,12 +209,15 @@ func TestReadDirSortBeforeTruncate(t *testing.T) { } resultMap := result.(map[string]any) - entries := resultMap["entries"].([]map[string]any) + entries, ok := resultMap["entries"].([]fileutil.DirEntryOut) + if !ok { + t.Fatalf("entries is not a slice of DirEntryOut") + } // Count directories in the result dirCount := 0 for _, entry := range entries { - if entry["is_dir"].(bool) { + if entry.Dir { dirCount++ } } @@ -225,7 +229,7 @@ func TestReadDirSortBeforeTruncate(t *testing.T) { // First 3 entries should be directories for i := 0; i < 3; i++ { - if !entries[i]["is_dir"].(bool) { + if !entries[i].Dir { t.Errorf("Expected entry %d to be a directory, but it was a file", i) } } diff --git a/pkg/aiusechat/uctypes/uctypes.go b/pkg/aiusechat/uctypes/uctypes.go index 05fe469fc..d2b25bbc1 100644 --- a/pkg/aiusechat/uctypes/uctypes.go +++ b/pkg/aiusechat/uctypes/uctypes.go @@ -189,29 +189,6 @@ const ( ApprovalCanceled = "canceled" ) -type AIModeConfig struct { - Mode string `json:"mode"` - DisplayName string `json:"display:name"` - DisplayOrder float64 `json:"display:order,omitempty"` - DisplayIcon string `json:"display:icon"` - Provider string `json:"provider,omitempty"` - APIType string `json:"apitype"` - Model string `json:"model"` - ThinkingLevel string `json:"thinkinglevel"` - BaseURL string `json:"baseurl,omitempty"` - WaveAICloud bool `json:"waveaicloud,omitempty"` - APIVersion string `json:"apiversion,omitempty"` - APIToken string `json:"apitoken,omitempty"` - APITokenSecretName string `json:"apitokensecretname,omitempty"` - Premium bool `json:"premium"` - Description string `json:"description"` - Capabilities []string `json:"capabilities,omitempty"` -} - -func (c *AIModeConfig) HasCapability(cap string) bool { - return slices.Contains(c.Capabilities, cap) -} - // when updating this struct, also modify frontend/app/aipanel/aitypes.ts WaveUIDataTypes.tooluse type UIMessageDataToolUse struct { ToolCallId string `json:"toolcallid"` diff --git a/pkg/aiusechat/usechat-backend.go b/pkg/aiusechat/usechat-backend.go index cb380a457..37e2f432e 100644 --- a/pkg/aiusechat/usechat-backend.go +++ b/pkg/aiusechat/usechat-backend.go @@ -186,15 +186,18 @@ func (b *anthropicBackend) RunChatStep( cont *uctypes.WaveContinueResponse, ) (*uctypes.WaveStopReason, []uctypes.GenAIMessage, *uctypes.RateLimitInfo, error) { stopReason, msg, rateLimitInfo, err := anthropic.RunAnthropicChatStep(ctx, sseHandler, chatOpts, cont) + if msg == nil { + return stopReason, nil, rateLimitInfo, err + } return stopReason, []uctypes.GenAIMessage{msg}, rateLimitInfo, err } func (b *anthropicBackend) UpdateToolUseData(chatId string, toolCallId string, toolUseData uctypes.UIMessageDataToolUse) error { - return fmt.Errorf("UpdateToolUseData not implemented for anthropic backend") + return anthropic.UpdateToolUseData(chatId, toolCallId, toolUseData) } func (b *anthropicBackend) RemoveToolUseCall(chatId string, toolCallId string) error { - return fmt.Errorf("RemoveToolUseCall not implemented for anthropic backend") + return anthropic.RemoveToolUseCall(chatId, toolCallId) } func (b *anthropicBackend) ConvertToolResultsToNativeChatMessage(toolResults []uctypes.AIToolResult) ([]uctypes.GenAIMessage, error) { @@ -210,7 +213,7 @@ func (b *anthropicBackend) ConvertAIMessageToNativeChatMessage(message uctypes.A } func (b *anthropicBackend) GetFunctionCallInputByToolCallId(aiChat uctypes.AIChat, toolCallId string) *uctypes.AIFunctionCallInput { - return nil + return anthropic.GetFunctionCallInputByToolCallId(aiChat, toolCallId) } func (b *anthropicBackend) ConvertAIChatToUIChat(aiChat uctypes.AIChat) (*uctypes.UIChat, error) { diff --git a/pkg/aiusechat/usechat.go b/pkg/aiusechat/usechat.go index ca7587e33..a55a10060 100644 --- a/pkg/aiusechat/usechat.go +++ b/pkg/aiusechat/usechat.go @@ -123,6 +123,7 @@ func getWaveAISettings(premium bool, builderMode bool, rtInfo waveobj.ObjRTInfo, Verbosity: verbosity, AIMode: aiMode, Endpoint: baseUrl, + ProxyURL: config.ProxyURL, Capabilities: config.Capabilities, WaveAIPremium: config.WaveAIPremium, } diff --git a/pkg/aiusechat/usechat_mode_test.go b/pkg/aiusechat/usechat_mode_test.go index 98ef4074c..73959f958 100644 --- a/pkg/aiusechat/usechat_mode_test.go +++ b/pkg/aiusechat/usechat_mode_test.go @@ -25,3 +25,15 @@ func TestApplyProviderDefaultsGroq(t *testing.T) { t.Fatalf("expected API token secret name %q, got %q", GroqAPITokenSecretName, config.APITokenSecretName) } } + +func TestApplyProviderDefaultsKeepsProxyURL(t *testing.T) { + config := wconfig.AIModeConfigType{ + Provider: uctypes.AIProvider_OpenAI, + Model: "gpt-5-mini", + ProxyURL: "http://localhost:8080", + } + applyProviderDefaults(&config) + if config.ProxyURL != "http://localhost:8080" { + t.Fatalf("expected proxy URL to be preserved, got %q", config.ProxyURL) + } +} diff --git a/pkg/baseds/baseds.go b/pkg/baseds/baseds.go index 8ede22596..90b339506 100644 --- a/pkg/baseds/baseds.go +++ b/pkg/baseds/baseds.go @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 // used for shared datastructures @@ -12,3 +12,19 @@ type RpcInputChType struct { MsgBytes []byte IngressLinkId LinkId } + +type Badge struct { + BadgeId string `json:"badgeid"` // must be a uuidv7 + Icon string `json:"icon"` + Color string `json:"color,omitempty"` + Priority float64 `json:"priority"` + PidLinked bool `json:"pidlinked,omitempty"` +} + +type BadgeEvent struct { + ORef string `json:"oref"` + Clear bool `json:"clear,omitempty"` + ClearAll bool `json:"clearall,omitempty"` + ClearById string `json:"clearbyid,omitempty"` + Badge *Badge `json:"badge,omitempty"` +} diff --git a/pkg/blockcontroller/blockcontroller.go b/pkg/blockcontroller/blockcontroller.go index 524a66c10..75f1938e1 100644 --- a/pkg/blockcontroller/blockcontroller.go +++ b/pkg/blockcontroller/blockcontroller.go @@ -19,6 +19,7 @@ import ( "github.com/wavetermdev/waveterm/pkg/jobcontroller" "github.com/wavetermdev/waveterm/pkg/remote" "github.com/wavetermdev/waveterm/pkg/remote/conncontroller" + "github.com/wavetermdev/waveterm/pkg/util/ds" "github.com/wavetermdev/waveterm/pkg/util/shellutil" "github.com/wavetermdev/waveterm/pkg/wavebase" "github.com/wavetermdev/waveterm/pkg/waveobj" @@ -41,7 +42,7 @@ const ( ) const ( - DefaultTermMaxFileSize = 256 * 1024 + DefaultTermMaxFileSize = 2 * 1024 * 1024 DefaultHtmlMaxFileSize = 256 * 1024 MaxInitScriptSize = 50 * 1024 ) @@ -75,10 +76,17 @@ type Controller interface { // Registry for all controllers var ( - controllerRegistry = make(map[string]Controller) - registryLock sync.RWMutex + controllerRegistry = make(map[string]Controller) + registryLock sync.RWMutex + blockResyncMutexMap = ds.MakeSyncMap[*sync.Mutex]() ) +func getBlockResyncMutex(blockId string) *sync.Mutex { + return blockResyncMutexMap.GetOrCreate(blockId, func() *sync.Mutex { + return &sync.Mutex{} + }) +} + // Registry operations func getController(blockId string) Controller { registryLock.RLock() @@ -145,6 +153,10 @@ func ResyncController(ctx context.Context, tabId string, blockId string, rtOpts return fmt.Errorf("invalid tabId or blockId passed to ResyncController") } + mu := getBlockResyncMutex(blockId) + mu.Lock() + defer mu.Unlock() + blockData, err := wstore.DBMustGet[*waveobj.Block](ctx, blockId) if err != nil { return fmt.Errorf("error getting block: %w", err) diff --git a/pkg/blockcontroller/durableshellcontroller.go b/pkg/blockcontroller/durableshellcontroller.go index a208a3df7..d3481b172 100644 --- a/pkg/blockcontroller/durableshellcontroller.go +++ b/pkg/blockcontroller/durableshellcontroller.go @@ -163,7 +163,7 @@ func (dsc *DurableShellController) Start(ctx context.Context, blockMeta waveobj. if jobId == "" { log.Printf("block %q starting new durable shell\n", dsc.BlockId) - newJobId, err := dsc.startNewJob(ctx, blockMeta, dsc.ConnName) + newJobId, err := dsc.startNewJob(ctx, blockMeta, dsc.ConnName, rtOpts) if err != nil { return fmt.Errorf("failed to start new job: %w", err) } @@ -218,11 +218,14 @@ func (dsc *DurableShellController) SendInput(inputUnion *BlockInputUnion) error return jobcontroller.SendInput(context.Background(), data) } -func (dsc *DurableShellController) startNewJob(ctx context.Context, blockMeta waveobj.MetaMapType, connName string) (string, error) { +func (dsc *DurableShellController) startNewJob(ctx context.Context, blockMeta waveobj.MetaMapType, connName string, rtOpts *waveobj.RuntimeOpts) (string, error) { termSize := waveobj.TermSize{ Rows: shellutil.DefaultTermRows, Cols: shellutil.DefaultTermCols, } + if rtOpts != nil && rtOpts.TermSize.Rows > 0 && rtOpts.TermSize.Cols > 0 { + termSize = rtOpts.TermSize + } cmdStr := blockMeta.GetString(waveobj.MetaKey_Cmd, "") cwd := blockMeta.GetString(waveobj.MetaKey_CmdCwd, "") opts, err := remote.ParseOpts(connName) diff --git a/pkg/blockcontroller/shellcontroller.go b/pkg/blockcontroller/shellcontroller.go index a41022539..27937ab5e 100644 --- a/pkg/blockcontroller/shellcontroller.go +++ b/pkg/blockcontroller/shellcontroller.go @@ -18,6 +18,7 @@ import ( "github.com/wavetermdev/waveterm/pkg/blocklogger" "github.com/wavetermdev/waveterm/pkg/filestore" + "github.com/wavetermdev/waveterm/pkg/genconn" "github.com/wavetermdev/waveterm/pkg/panichandler" "github.com/wavetermdev/waveterm/pkg/remote" "github.com/wavetermdev/waveterm/pkg/remote/conncontroller" @@ -42,6 +43,7 @@ const ( ConnType_Local = "local" ConnType_Wsl = "wsl" ConnType_Ssh = "ssh" + ConnType_Mosh = "mosh" ) const ( @@ -320,15 +322,45 @@ func (sc *ShellController) run(logCtx context.Context, bdata *waveobj.Block, blo // [Include all the remaining private methods with bc replaced by sc] type ConnUnion struct { - ConnName string - ConnType string - SshConn *conncontroller.SSHConn - WslConn *wslconn.WslConn - WshEnabled bool - ShellPath string - ShellOpts []string - ShellType string - HomeDir string + ConnName string + ConnType string + SshConn *conncontroller.SSHConn + WslConn *wslconn.WslConn + WshEnabled bool + MoshEnabled bool + MoshActive bool // true when mosh is actually being used (not just enabled) + ShellPath string + ShellOpts []string + ShellType string + HomeDir string +} + +// autoDetectMosh probes for local mosh-client and remote mosh-server. +// Result is cached on the SSHConn so the probe only runs once per connection. +func autoDetectMosh(conn *conncontroller.SSHConn) bool { + if conn.MoshAutoDetected.Load() { + return conn.MoshAutoAvailable.Load() + } + // Mark as detected (even if probe fails) to avoid re-probing + defer conn.MoshAutoDetected.Store(true) + + // Check local mosh-client + if _, err := genconn.FindMoshClientBinary(); err != nil { + log.Printf("[mosh-auto] local mosh-client not found: %v\n", err) + return false + } + // Check remote mosh-server + client := conn.GetClient() + if client == nil { + return false + } + if err := genconn.CheckRemoteMoshServer(client); err != nil { + log.Printf("[mosh-auto] remote mosh-server not found on %s: %v\n", conn.GetName(), err) + return false + } + log.Printf("[mosh-auto] mosh available for %s (local client + remote server)\n", conn.GetName()) + conn.MoshAutoAvailable.Store(true) + return true } func (bc *ShellController) getConnUnion(logCtx context.Context, remoteName string, blockMeta waveobj.MetaMapType) (ConnUnion, error) { @@ -366,6 +398,23 @@ func (bc *ShellController) getConnUnion(logCtx context.Context, remoteName strin rtn.ConnType = ConnType_Ssh rtn.SshConn = conn rtn.WshEnabled = wshEnabled && conn.WshEnabled.Load() + + // Determine mosh enablement: explicit config > block meta > auto-detection + connConfig := wconfig.GetWatcher().GetFullConfig() + connSettings, connOk := connConfig.Connections[remoteName] + explicitlySet := false + if connOk && connSettings.ConnMoshEnabled != nil { + rtn.MoshEnabled = *connSettings.ConnMoshEnabled + explicitlySet = true + } + if blockMeta.GetBool("conn:moshenabled", false) { + rtn.MoshEnabled = true + explicitlySet = true + } + // Auto-detect mosh availability when not explicitly configured + if !explicitlySet { + rtn.MoshEnabled = autoDetectMosh(conn) + } } err := rtn.getRemoteInfoAndShellType(blockMeta) if err != nil { @@ -459,12 +508,29 @@ func (bc *ShellController) setupAndStartShellProcess(logCtx context.Context, rc } } else if connUnion.ConnType == ConnType_Ssh { conn := connUnion.SshConn - if !connUnion.WshEnabled { + + // Attempt mosh if enabled. Mosh only supports interactive shells (not one-off commands) + // because mosh-client requires a PTY and maintains its own terminal state. + if connUnion.MoshEnabled && bc.ControllerType == BlockController_Shell { + blocklogger.Infof(logCtx, "[conndebug] mosh enabled, attempting mosh connection to %s\n", conn.Opts.SSHHost) + moshShellProc, moshErr := shellexec.StartMoshShellProc(ctx, logCtx, rc.TermSize, conn) + if moshErr != nil { + blocklogger.Infof(logCtx, "[conndebug] mosh failed, falling back to SSH: %v\n", moshErr) + bc.writeMutedMessageToTerminal("[mosh unavailable: " + moshErr.Error() + ", using SSH]") + // Fall through to normal SSH below + } else { + blocklogger.Infof(logCtx, "[conndebug] mosh connection established\n") + bc.writeMutedMessageToTerminal("[connected via mosh]") + shellProc = moshShellProc + } + } + + if !connUnion.WshEnabled && shellProc == nil { shellProc, err = shellexec.StartRemoteShellProcNoWsh(ctx, rc.TermSize, cmdStr, cmdOpts, conn) if err != nil { return nil, err } - } else { + } else if shellProc == nil { sockName := conn.GetDomainSocketName() rpcContext := wshrpc.RpcContext{ ProcRoute: true, @@ -647,6 +713,45 @@ func (union *ConnUnion) getRemoteInfoAndShellType(blockMeta waveobj.MetaMapType) return nil } +func isLastShellBlockInWorkspace(ctx context.Context, blockId string) bool { + tabId, err := wstore.DBFindTabForBlockId(ctx, blockId) + if err != nil || tabId == "" { + return false + } + workspaceId, err := wstore.DBFindWorkspaceForTabId(ctx, tabId) + if err != nil || workspaceId == "" { + return false + } + workspace, err := wstore.DBGet[*waveobj.Workspace](ctx, workspaceId) + if err != nil || workspace == nil { + return false + } + shellBlockCount := 0 + for _, wsTabId := range workspace.TabIds { + tab, err := wstore.DBGet[*waveobj.Tab](ctx, wsTabId) + if err != nil { + return false + } + if tab == nil { + continue + } + for _, wsBlockId := range tab.BlockIds { + block, err := wstore.DBGet[*waveobj.Block](ctx, wsBlockId) + if err != nil { + return false + } + if block == nil { + continue + } + controller := block.Meta.GetString(waveobj.MetaKey_Controller, "") + if controller == BlockController_Shell || controller == BlockController_Cmd { + shellBlockCount++ + } + } + } + return shellBlockCount == 1 +} + func checkCloseOnExit(blockId string, exitCode int) { ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout) defer cancelFn() @@ -657,10 +762,19 @@ func checkCloseOnExit(blockId string, exitCode int) { } closeOnExit := blockData.Meta.GetBool(waveobj.MetaKey_CmdCloseOnExit, false) closeOnExitForce := blockData.Meta.GetBool(waveobj.MetaKey_CmdCloseOnExitForce, false) + defaultDelayMs := 2000.0 if !closeOnExitForce && !(closeOnExit && exitCode == 0) { - return + // Check global setting: close when last terminal exits + settings := wconfig.GetWatcher().GetFullConfig().Settings + if !settings.TermCloseOnLastTermClose { + return + } + if !isLastShellBlockInWorkspace(ctx, blockId) { + return + } + defaultDelayMs = 0 } - delayMs := blockData.Meta.GetFloat(waveobj.MetaKey_CmdCloseOnExitDelay, 2000) + delayMs := blockData.Meta.GetFloat(waveobj.MetaKey_CmdCloseOnExitDelay, defaultDelayMs) if delayMs < 0 { delayMs = 0 } @@ -884,7 +998,7 @@ func updateTermSize(shellProc *shellexec.ShellProc, blockId string, termSize wav if err != nil { log.Printf("error setting pty size: %v\n", err) } - err = shellProc.Cmd.SetSize(termSize.Rows, termSize.Cols) + err = shellProc.Cmd.SetSize(termSize) if err != nil { log.Printf("error setting pty size: %v\n", err) } diff --git a/pkg/eventbus/eventbus.go b/pkg/eventbus/eventbus.go index f2570e10f..377f1503d 100644 --- a/pkg/eventbus/eventbus.go +++ b/pkg/eventbus/eventbus.go @@ -9,11 +9,9 @@ import ( "log" "os" "sync" - "time" ) const ( - WSEvent_ElectronNewWindow = "electron:newwindow" WSEvent_ElectronCloseWindow = "electron:closewindow" WSEvent_ElectronUpdateActiveTab = "electron:updateactivetab" WSEvent_Rpc = "rpc" @@ -48,33 +46,6 @@ func UnregisterWSChannel(connId string) { delete(wsMap, connId) } -func getWindowWatchesForWindowId(windowId string) []*WindowWatchData { - globalLock.Lock() - defer globalLock.Unlock() - var watches []*WindowWatchData - for _, wdata := range wsMap { - if wdata.RouteId == windowId { - watches = append(watches, wdata) - } - } - return watches -} - -// TODO fix busy wait -- but we need to wait until a new window connects back with a websocket -// returns true if the window is connected -func BusyWaitForWindowId(windowId string, timeout time.Duration) bool { - endTime := time.Now().Add(timeout) - for { - if len(getWindowWatchesForWindowId(windowId)) > 0 { - return true - } - if time.Now().After(endTime) { - return false - } - time.Sleep(20 * time.Millisecond) - } -} - func SendEventToElectron(event WSEventType) { barr, err := json.Marshal(event) if err != nil { diff --git a/pkg/genconn/mosh-impl.go b/pkg/genconn/mosh-impl.go new file mode 100644 index 000000000..55a793700 --- /dev/null +++ b/pkg/genconn/mosh-impl.go @@ -0,0 +1,328 @@ +// Copyright 2025, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package genconn + +import ( + "bytes" + "fmt" + "io" + "log" + "os" + "os/exec" + "path/filepath" + "regexp" + "runtime" + "strings" + "sync" + + "golang.org/x/crypto/ssh" +) + +const ( + MoshDefaultColorDepth = 256 + MoshDefaultLocale = "LANG=en_US.UTF-8" + MoshConnectPrefix = "MOSH CONNECT" +) + +var _ ShellClient = (*MoshShellClient)(nil) + +// MoshShellClient wraps the local mosh-client binary to provide a Mosh connection. +// SSH is used to start mosh-server on the remote, then a local mosh-client process +// is spawned to handle the terminal I/O over UDP/SSP. +type MoshShellClient struct { + sshClient *ssh.Client + remoteHost string +} + +// MakeMoshShellClient creates a new Mosh shell client +func MakeMoshShellClient(sshClient *ssh.Client, remoteHost string) *MoshShellClient { + return &MoshShellClient{ + sshClient: sshClient, + remoteHost: remoteHost, + } +} + +func (c *MoshShellClient) MakeProcessController(cmdSpec CommandSpec) (ShellProcessController, error) { + // First check if mosh-server is available on remote + log.Printf("MOSH: Checking for remote mosh-server\n") + if err := CheckRemoteMoshServer(c.sshClient); err != nil { + return nil, fmt.Errorf("mosh-server not available on %s: %w", c.remoteHost, err) + } + + // Find local mosh-client binary + log.Printf("MOSH: Finding local mosh-client binary\n") + moshClientPath, err := FindMoshClientBinary() + if err != nil { + return nil, fmt.Errorf("mosh-client not found on local machine (remote: %s): %w", c.remoteHost, err) + } + log.Printf("MOSH: Found mosh-client at %s\n", moshClientPath) + + // Create SSH session to start mosh-server + log.Printf("MOSH: Creating SSH session to start mosh-server\n") + session, err := c.sshClient.NewSession() + if err != nil { + return nil, fmt.Errorf("failed to create SSH session: %w", err) + } + defer session.Close() + + // Capture stdout from mosh-server + var stdout bytes.Buffer + session.Stdout = &stdout + + // Run mosh-server new command + moshServerCmd := fmt.Sprintf("mosh-server new -s -c %d -l %s", MoshDefaultColorDepth, MoshDefaultLocale) + log.Printf("MOSH: Running: %s\n", moshServerCmd) + if err := session.Run(moshServerCmd); err != nil { + return nil, fmt.Errorf("failed to start mosh-server: %w", err) + } + + // Parse MOSH CONNECT line + output := stdout.String() + log.Printf("MOSH: Server output: %s\n", output) + port, key, err := ParseMoshConnectLine(output) + if err != nil { + return nil, fmt.Errorf("failed to parse mosh-server output: %w", err) + } + log.Printf("MOSH: Parsed connection - port: %s, key length: %d\n", port, len(key)) + + // Create local mosh-client command + cmd := exec.Command(moshClientPath, c.remoteHost, port) + cmd.Env = append(os.Environ(), fmt.Sprintf("MOSH_KEY=%s", key)) + + log.Printf("MOSH: Created mosh-client command: %s %s %s\n", moshClientPath, c.remoteHost, port) + + return &MoshProcessController{ + cmd: cmd, + lock: &sync.Mutex{}, + once: &sync.Once{}, + }, nil +} + +// MoshProcessController implements ShellProcessController for Mosh connections +type MoshProcessController struct { + cmd *exec.Cmd + lock *sync.Mutex + once *sync.Once + stdinPiped bool + stdoutPiped bool + stderrPiped bool + waitErr error + started bool +} + +// GetCmd returns the underlying exec.Cmd for PTY wrapping. +// This is used by shellexec to start the mosh-client with a local PTY. +func (m *MoshProcessController) GetCmd() *exec.Cmd { + return m.cmd +} + +// Start begins execution of the mosh-client command +func (m *MoshProcessController) Start() error { + m.lock.Lock() + defer m.lock.Unlock() + + if m.started { + return fmt.Errorf("command already started") + } + + if err := m.cmd.Start(); err != nil { + return fmt.Errorf("failed to start mosh-client: %w", err) + } + + m.started = true + log.Printf("MOSH: Process started successfully\n") + return nil +} + +// Wait waits for the mosh-client command to complete +func (m *MoshProcessController) Wait() error { + m.once.Do(func() { + m.waitErr = m.cmd.Wait() + if m.waitErr != nil { + log.Printf("MOSH: Process wait error: %v\n", m.waitErr) + } else { + log.Printf("MOSH: Process completed successfully\n") + } + }) + return m.waitErr +} + +// Kill terminates the mosh-client command +func (m *MoshProcessController) Kill() { + m.lock.Lock() + defer m.lock.Unlock() + + if m.cmd == nil { + return + } + process := m.cmd.Process + if process == nil { + return + } + log.Printf("MOSH: Killing process\n") + process.Kill() +} + +func (m *MoshProcessController) StdinPipe() (io.WriteCloser, error) { + m.lock.Lock() + defer m.lock.Unlock() + + if m.started { + return nil, fmt.Errorf("command already started") + } + if m.stdinPiped { + return nil, fmt.Errorf("stdin already piped") + } + + m.stdinPiped = true + return m.cmd.StdinPipe() +} + +func (m *MoshProcessController) StdoutPipe() (io.Reader, error) { + m.lock.Lock() + defer m.lock.Unlock() + + if m.started { + return nil, fmt.Errorf("command already started") + } + if m.stdoutPiped { + return nil, fmt.Errorf("stdout already piped") + } + + m.stdoutPiped = true + stdout, err := m.cmd.StdoutPipe() + if err != nil { + return nil, err + } + return stdout, nil +} + +func (m *MoshProcessController) StderrPipe() (io.Reader, error) { + m.lock.Lock() + defer m.lock.Unlock() + + if m.started { + return nil, fmt.Errorf("command already started") + } + if m.stderrPiped { + return nil, fmt.Errorf("stderr already piped") + } + + m.stderrPiped = true + stderr, err := m.cmd.StderrPipe() + if err != nil { + return nil, err + } + return stderr, nil +} + +// ParseMoshConnectLine parses "MOSH CONNECT " from mosh-server output +// Returns (port string, key string, error) +func ParseMoshConnectLine(output string) (string, string, error) { + // Look for "MOSH CONNECT " in the output + re := regexp.MustCompile(`MOSH CONNECT (\d+) ([A-Za-z0-9+/=]+)`) + matches := re.FindStringSubmatch(output) + if len(matches) != 3 { + return "", "", fmt.Errorf("could not find MOSH CONNECT line in output") + } + + port := matches[1] + key := matches[2] + + if port == "" || key == "" { + return "", "", fmt.Errorf("invalid MOSH CONNECT line: port or key is empty") + } + + return port, key, nil +} + +// FindMoshClientBinary finds the mosh-client binary on the local system +// Checks: PATH, then platform-specific paths. +// Exported for auto-detection probing from shellcontroller. +func FindMoshClientBinary() (string, error) { + // First try to find in PATH + path, err := exec.LookPath("mosh-client") + if err == nil { + return path, nil + } + + // Platform-specific fallback paths + var searchPaths []string + + switch runtime.GOOS { + case "windows": + // Windows: check scoop, chocolatey, and common install locations + homeDir, err := os.UserHomeDir() + if err == nil { + searchPaths = append(searchPaths, + filepath.Join(homeDir, "scoop", "shims", "mosh-client.exe"), + filepath.Join(homeDir, "scoop", "apps", "mosh", "current", "mosh-client.exe"), + ) + } + searchPaths = append(searchPaths, + "C:\\ProgramData\\chocolatey\\bin\\mosh-client.exe", + "C:\\Program Files\\mosh\\mosh-client.exe", + "C:\\Program Files (x86)\\mosh\\mosh-client.exe", + ) + + case "darwin": + // macOS: check homebrew paths + searchPaths = append(searchPaths, + "/usr/local/bin/mosh-client", + "/opt/homebrew/bin/mosh-client", + "/opt/local/bin/mosh-client", // MacPorts + ) + + case "linux": + // Linux: check standard paths + searchPaths = append(searchPaths, + "/usr/bin/mosh-client", + "/usr/local/bin/mosh-client", + "/opt/bin/mosh-client", + ) + + default: + // Other Unix-like systems + searchPaths = append(searchPaths, + "/usr/bin/mosh-client", + "/usr/local/bin/mosh-client", + ) + } + + // Check each path + for _, path := range searchPaths { + if _, err := os.Stat(path); err == nil { + return path, nil + } + } + + return "", fmt.Errorf("mosh-client binary not found in PATH or common locations") +} + +// CheckRemoteMoshServer checks if mosh-server is available on remote via SSH. +// Exported so that auto-detection logic in shellcontroller can probe without starting a full mosh session. +func CheckRemoteMoshServer(client *ssh.Client) error { + session, err := client.NewSession() + if err != nil { + return fmt.Errorf("failed to create SSH session: %w", err) + } + defer session.Close() + + // Try to find mosh-server + var stdout bytes.Buffer + session.Stdout = &stdout + + // Use 'command -v' which is POSIX-compliant + if err := session.Run("command -v mosh-server"); err != nil { + return fmt.Errorf("mosh-server not found on remote host (try: apt install mosh / yum install mosh / brew install mosh)") + } + + moshServerPath := strings.TrimSpace(stdout.String()) + if moshServerPath == "" { + return fmt.Errorf("mosh-server not found on remote host") + } + + log.Printf("MOSH: Found mosh-server on remote at: %s\n", moshServerPath) + return nil +} diff --git a/pkg/genconn/mosh-impl_test.go b/pkg/genconn/mosh-impl_test.go new file mode 100644 index 000000000..3113c5fbf --- /dev/null +++ b/pkg/genconn/mosh-impl_test.go @@ -0,0 +1,394 @@ +// Copyright 2025, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package genconn + +import ( + "os" + "os/exec" + "path/filepath" + "runtime" + "sync" + "testing" +) + +func TestParseMoshConnectLine(t *testing.T) { + tests := []struct { + name string + input string + wantPort string + wantKey string + wantErr bool + }{ + { + name: "valid single line output", + input: "MOSH CONNECT 60001 AbCdEf123456==", + wantPort: "60001", + wantKey: "AbCdEf123456==", + wantErr: false, + }, + { + name: "valid multi-line output with noise", + input: `mosh-server (mosh 1.4.0) +Copyright 2012 Keith Winstein + +MOSH CONNECT 60001 AbCdEf123456==`, + wantPort: "60001", + wantKey: "AbCdEf123456==", + wantErr: false, + }, + { + name: "valid output with trailing newline", + input: `MOSH CONNECT 60001 AbCdEf123456== +`, + wantPort: "60001", + wantKey: "AbCdEf123456==", + wantErr: false, + }, + { + name: "valid output with debug messages", + input: `[debug] Starting mosh-server +[info] Listening on port 60001 +MOSH CONNECT 60001 AbCdEf123456== +[info] Connection established`, + wantPort: "60001", + wantKey: "AbCdEf123456==", + wantErr: false, + }, + { + name: "port at lower boundary", + input: "MOSH CONNECT 60000 key==", + wantPort: "60000", + wantKey: "key==", + wantErr: false, + }, + { + name: "port at upper boundary", + input: "MOSH CONNECT 61000 key==", + wantPort: "61000", + wantKey: "key==", + wantErr: false, + }, + { + name: "large port number", + input: "MOSH CONNECT 65535 key==", + wantPort: "65535", + wantKey: "key==", + wantErr: false, + }, + { + name: "key with plus and slash characters", + input: "MOSH CONNECT 60001 ABC+def/123==", + wantPort: "60001", + wantKey: "ABC+def/123==", + wantErr: false, + }, + { + name: "key with various padding", + input: "MOSH CONNECT 60001 ABCdef=", + wantPort: "60001", + wantKey: "ABCdef=", + wantErr: false, + }, + { + name: "key without padding", + input: "MOSH CONNECT 60001 ABCdefGHI", + wantPort: "60001", + wantKey: "ABCdefGHI", + wantErr: false, + }, + { + name: "missing MOSH CONNECT line", + input: "some random output\nwithout MOSH CONNECT", + wantPort: "", + wantKey: "", + wantErr: true, + }, + { + name: "empty output", + input: "", + wantPort: "", + wantKey: "", + wantErr: true, + }, + { + name: "malformed line - missing port and key", + input: "MOSH CONNECT", + wantPort: "", + wantKey: "", + wantErr: true, + }, + { + name: "malformed line - missing key", + input: "MOSH CONNECT 60001", + wantPort: "", + wantKey: "", + wantErr: true, + }, + { + name: "malformed line - missing port", + input: "MOSH CONNECT AbCdEf123456==", + wantPort: "", + wantKey: "", + wantErr: true, + }, + { + name: "malformed line - non-numeric port", + input: "MOSH CONNECT abc AbCdEf123456==", + wantPort: "", + wantKey: "", + wantErr: true, + }, + { + name: "partial match - MOSH only", + input: "MOSH server starting...", + wantPort: "", + wantKey: "", + wantErr: true, + }, + { + name: "partial match - CONNECT only", + input: "CONNECT to server", + wantPort: "", + wantKey: "", + wantErr: true, + }, + { + name: "extra whitespace", + input: "MOSH CONNECT 60001 AbCdEf123456==", + wantPort: "", + wantKey: "", + wantErr: true, + }, + { + name: "case sensitivity - lowercase", + input: "mosh connect 60001 AbCdEf123456==", + wantPort: "", + wantKey: "", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + port, key, err := ParseMoshConnectLine(tt.input) + + if tt.wantErr { + if err == nil { + t.Errorf("ParseMoshConnectLine() expected error but got none") + } + return + } + + if err != nil { + t.Errorf("ParseMoshConnectLine() unexpected error: %v", err) + return + } + + if port != tt.wantPort { + t.Errorf("ParseMoshConnectLine() port = %v, want %v", port, tt.wantPort) + } + + if key != tt.wantKey { + t.Errorf("ParseMoshConnectLine() key = %v, want %v", key, tt.wantKey) + } + }) + } +} + +func TestFindMoshClientBinary(t *testing.T) { + // Test 1: Check if function returns without error when mosh-client is in PATH + t.Run("find in PATH", func(t *testing.T) { + // Try to find mosh-client in PATH + pathMosh, pathErr := exec.LookPath("mosh-client") + if pathErr == nil { + // mosh-client is available in PATH + foundPath, err := FindMoshClientBinary() + if err != nil { + t.Errorf("FindMoshClientBinary() error = %v, expected to find mosh-client at %s", err, pathMosh) + return + } + if foundPath == "" { + t.Error("FindMoshClientBinary() returned empty path when mosh-client is in PATH") + } + t.Logf("Found mosh-client at: %s", foundPath) + } else { + t.Skip("mosh-client not in PATH, skipping PATH test") + } + }) + + // Test 2: Check platform-specific paths + t.Run("platform specific paths", func(t *testing.T) { + // This test verifies the function checks platform-specific paths + // We'll create a temporary directory structure to test path checking + tempDir := t.TempDir() + + var testBinaryPath string + switch runtime.GOOS { + case "windows": + testBinaryPath = filepath.Join(tempDir, "mosh-client.exe") + default: + testBinaryPath = filepath.Join(tempDir, "mosh-client") + } + + // Create a mock mosh-client binary + f, err := os.Create(testBinaryPath) + if err != nil { + t.Fatalf("Failed to create test binary: %v", err) + } + f.Close() + + // Make it executable on Unix-like systems + if runtime.GOOS != "windows" { + if err := os.Chmod(testBinaryPath, 0755); err != nil { + t.Fatalf("Failed to chmod test binary: %v", err) + } + } + + // The function won't find our temp binary since it's not in the hardcoded paths, + // but we can verify the function runs without panicking + _, err = FindMoshClientBinary() + // We expect an error if mosh-client is not installed system-wide + if err == nil { + t.Log("mosh-client found on system") + } else { + t.Logf("mosh-client not found (expected in test environment): %v", err) + } + }) + + // Test 3: Verify error message is descriptive + t.Run("descriptive error message", func(t *testing.T) { + // Temporarily modify PATH to exclude mosh-client + originalPath := os.Getenv("PATH") + os.Setenv("PATH", "") + defer os.Setenv("PATH", originalPath) + + _, err := FindMoshClientBinary() + if err == nil { + // If no error, mosh-client was found in hardcoded paths + t.Log("mosh-client found in hardcoded paths") + return + } + + expectedSubstring := "mosh-client binary not found" + if !containsSubstring(err.Error(), expectedSubstring) { + t.Errorf("Error message doesn't contain expected substring.\nGot: %v\nWant substring: %v", err.Error(), expectedSubstring) + } + }) +} + +func TestMoshShellClientImplementsInterface(t *testing.T) { + // Compile-time check that MoshShellClient implements ShellClient + var _ ShellClient = (*MoshShellClient)(nil) + t.Log("MoshShellClient correctly implements ShellClient interface") +} + +func TestMoshProcessControllerStateManagement(t *testing.T) { + // Create a mock command (we won't actually execute it) + cmd := exec.Command("echo", "test") + + mpc := &MoshProcessController{ + cmd: cmd, + lock: &sync.Mutex{}, + once: &sync.Once{}, + } + + // Test initial state + if mpc.started { + t.Error("MoshProcessController should not be started initially") + } + + // Test pipe methods before start + t.Run("pipes before start", func(t *testing.T) { + // These should work before Start() is called + stdin, err := mpc.StdinPipe() + if err != nil { + t.Errorf("StdinPipe() before start failed: %v", err) + } + if stdin == nil { + t.Error("StdinPipe() returned nil pipe") + } + + stdout, err := mpc.StdoutPipe() + if err != nil { + t.Errorf("StdoutPipe() before start failed: %v", err) + } + if stdout == nil { + t.Error("StdoutPipe() returned nil pipe") + } + + stderr, err := mpc.StderrPipe() + if err != nil { + t.Errorf("StderrPipe() before start failed: %v", err) + } + if stderr == nil { + t.Error("StderrPipe() returned nil pipe") + } + }) + + // Test duplicate pipe calls + t.Run("duplicate pipes", func(t *testing.T) { + cmd2 := exec.Command("echo", "test") + mpc2 := &MoshProcessController{ + cmd: cmd2, + lock: &sync.Mutex{}, + once: &sync.Once{}, + } + + _, err := mpc2.StdinPipe() + if err != nil { + t.Fatalf("First StdinPipe() failed: %v", err) + } + + _, err = mpc2.StdinPipe() + if err == nil { + t.Error("Second StdinPipe() should return error") + } + }) + + // Test Kill on nil process + t.Run("kill nil process", func(t *testing.T) { + mpc3 := &MoshProcessController{ + cmd: nil, + lock: &sync.Mutex{}, + once: &sync.Once{}, + } + // Should not panic + mpc3.Kill() + }) +} + +func TestMakeMoshShellClient(t *testing.T) { + // Test that MakeMoshShellClient creates a properly initialized client + // Note: We can't create a real SSH client without a connection, + // but we can verify the constructor works with nil (for structure testing) + remoteHost := "test.example.com" + + client := MakeMoshShellClient(nil, remoteHost) + + if client == nil { + t.Fatal("MakeMoshShellClient returned nil") + } + + if client.remoteHost != remoteHost { + t.Errorf("remoteHost = %v, want %v", client.remoteHost, remoteHost) + } + + if client.sshClient != nil { + t.Error("sshClient should be nil when passed nil") + } +} + +// Helper function to check if a string contains a substring +func containsSubstring(s, substr string) bool { + return len(s) >= len(substr) && (s == substr || len(s) > len(substr) && findSubstring(s, substr)) +} + +func findSubstring(s, substr string) bool { + for i := 0; i <= len(s)-len(substr); i++ { + if s[i:i+len(substr)] == substr { + return true + } + } + return false +} diff --git a/pkg/gogen/gogen.go b/pkg/gogen/gogen.go index 25b511de3..bc3662a67 100644 --- a/pkg/gogen/gogen.go +++ b/pkg/gogen/gogen.go @@ -75,12 +75,7 @@ func GenerateMetaMapConsts(buf *strings.Builder, constPrefix string, rtype refle func GenMethod_Call(buf *strings.Builder, methodDecl *wshrpc.WshRpcMethodDecl) { fmt.Fprintf(buf, "// command %q, wshserver.%s\n", methodDecl.Command, methodDecl.MethodName) - var dataType string - dataVarName := "nil" - if methodDecl.CommandDataType != nil { - dataType = ", data " + methodDecl.CommandDataType.String() - dataVarName = "data" - } + dataType, dataVarName := getWshMethodDataParamsAndExpr(methodDecl) returnType := "error" respName := "_" tParamVal := "any" @@ -101,12 +96,7 @@ func GenMethod_Call(buf *strings.Builder, methodDecl *wshrpc.WshRpcMethodDecl) { func GenMethod_ResponseStream(buf *strings.Builder, methodDecl *wshrpc.WshRpcMethodDecl) { fmt.Fprintf(buf, "// command %q, wshserver.%s\n", methodDecl.Command, methodDecl.MethodName) - var dataType string - dataVarName := "nil" - if methodDecl.CommandDataType != nil { - dataType = ", data " + methodDecl.CommandDataType.String() - dataVarName = "data" - } + dataType, dataVarName := getWshMethodDataParamsAndExpr(methodDecl) respType := "any" if methodDecl.DefaultResponseDataType != nil { respType = methodDecl.DefaultResponseDataType.String() @@ -115,3 +105,27 @@ func GenMethod_ResponseStream(buf *strings.Builder, methodDecl *wshrpc.WshRpcMet fmt.Fprintf(buf, "\treturn sendRpcRequestResponseStreamHelper[%s](w, %q, %s, opts)\n", respType, methodDecl.Command, dataVarName) fmt.Fprintf(buf, "}\n\n") } + +func getWshMethodDataParamsAndExpr(methodDecl *wshrpc.WshRpcMethodDecl) (string, string) { + dataTypes := methodDecl.GetCommandDataTypes() + if len(dataTypes) == 0 { + return "", "nil" + } + if len(dataTypes) == 1 { + return ", data " + dataTypes[0].String(), "data" + } + var paramBuilder strings.Builder + var argBuilder strings.Builder + for idx, dataType := range dataTypes { + argName := fmt.Sprintf("arg%d", idx+1) + paramBuilder.WriteString(", ") + paramBuilder.WriteString(argName) + paramBuilder.WriteString(" ") + paramBuilder.WriteString(dataType.String()) + if idx > 0 { + argBuilder.WriteString(", ") + } + argBuilder.WriteString(argName) + } + return paramBuilder.String(), fmt.Sprintf("wshrpc.MultiArg{Args: []any{%s}}", argBuilder.String()) +} diff --git a/pkg/gogen/gogen_test.go b/pkg/gogen/gogen_test.go new file mode 100644 index 000000000..2965d26f1 --- /dev/null +++ b/pkg/gogen/gogen_test.go @@ -0,0 +1,46 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package gogen + +import ( + "reflect" + "strings" + "testing" + + "github.com/wavetermdev/waveterm/pkg/wshrpc" +) + +func TestGetWshMethodDataParamsAndExpr_MultiArg(t *testing.T) { + methodDecl := &wshrpc.WshRpcMethodDecl{ + CommandDataTypes: []reflect.Type{ + reflect.TypeOf(""), + reflect.TypeOf(0), + }, + } + params, expr := getWshMethodDataParamsAndExpr(methodDecl) + if params != ", arg1 string, arg2 int" { + t.Fatalf("unexpected params: %q", params) + } + if expr != "wshrpc.MultiArg{Args: []any{arg1, arg2}}" { + t.Fatalf("unexpected expr: %q", expr) + } +} + +func TestGenMethodCall_MultiArg(t *testing.T) { + methodDecl := &wshrpc.WshRpcMethodDecl{ + Command: "test", + CommandType: wshrpc.RpcType_Call, + MethodName: "TestCommand", + CommandDataTypes: []reflect.Type{reflect.TypeOf(""), reflect.TypeOf(0)}, + } + var sb strings.Builder + GenMethod_Call(&sb, methodDecl) + out := sb.String() + if !strings.Contains(out, "func TestCommand(w *wshutil.WshRpc, arg1 string, arg2 int, opts *wshrpc.RpcOpts) error {") { + t.Fatalf("generated method missing multi-arg signature:\n%s", out) + } + if !strings.Contains(out, "sendRpcRequestCallHelper[any](w, \"test\", wshrpc.MultiArg{Args: []any{arg1, arg2}}, opts)") { + t.Fatalf("generated method missing MultiArg payload:\n%s", out) + } +} diff --git a/pkg/jobmanager/jobcmd.go b/pkg/jobmanager/jobcmd.go index 8adfabefc..84a2ffc7b 100644 --- a/pkg/jobmanager/jobcmd.go +++ b/pkg/jobmanager/jobcmd.go @@ -13,6 +13,7 @@ import ( "time" "github.com/creack/pty" + "github.com/wavetermdev/waveterm/pkg/util/ptyutil" "github.com/wavetermdev/waveterm/pkg/util/unixutil" "github.com/wavetermdev/waveterm/pkg/waveobj" "github.com/wavetermdev/waveterm/pkg/wshrpc" @@ -59,7 +60,7 @@ func MakeJobCmd(jobId string, cmdDef CmdDef) (*JobCmd, error) { ecmd.Env = append(ecmd.Env, fmt.Sprintf("%s=%s", key, val)) } } - cmdPty, err := pty.StartWithSize(ecmd, &pty.Winsize{Rows: uint16(cmdDef.TermSize.Rows), Cols: uint16(cmdDef.TermSize.Cols)}) + cmdPty, err := pty.StartWithSize(ecmd, ptyutil.WinsizeFromTermSize(cmdDef.TermSize)) if err != nil { return nil, fmt.Errorf("failed to start command: %w", err) } @@ -156,13 +157,13 @@ func (jm *JobCmd) setTermSize_withlock(termSize waveobj.TermSize) error { if jm.cmdPty == nil { return fmt.Errorf("no active pty") } - if jm.termSize.Rows == termSize.Rows && jm.termSize.Cols == termSize.Cols { + if jm.termSize.Rows == termSize.Rows && + jm.termSize.Cols == termSize.Cols && + jm.termSize.XPixel == termSize.XPixel && + jm.termSize.YPixel == termSize.YPixel { return nil } - err := pty.Setsize(jm.cmdPty, &pty.Winsize{ - Rows: uint16(termSize.Rows), - Cols: uint16(termSize.Cols), - }) + err := pty.Setsize(jm.cmdPty, ptyutil.WinsizeFromTermSize(termSize)) if err != nil { return fmt.Errorf("error setting terminal size: %w", err) } diff --git a/pkg/remote/conncontroller/conncontroller.go b/pkg/remote/conncontroller/conncontroller.go index a24a78900..9479f19bc 100644 --- a/pkg/remote/conncontroller/conncontroller.go +++ b/pkg/remote/conncontroller/conncontroller.go @@ -80,6 +80,10 @@ type SSHConn struct { Status string ConnHealthStatus string WshEnabled *atomic.Bool + MoshEnabled *atomic.Bool + MoshActive *atomic.Bool // true when mosh is actively used for shell I/O + MoshAutoDetected *atomic.Bool // true after auto-detection probe has run + MoshAutoAvailable *atomic.Bool // true if both local mosh-client and remote mosh-server were found Opts *remote.SSHOpts Client *ssh.Client DomainSockName string // if "", then no domain socket @@ -150,6 +154,8 @@ func (conn *SSHConn) DeriveConnStatus() wshrpc.ConnStatus { ActiveConnNum: conn.ActiveConnNum, Error: conn.Error, WshEnabled: conn.WshEnabled.Load(), + MoshEnabled: conn.MoshEnabled.Load(), + MoshActive: conn.MoshActive.Load(), WshError: conn.WshError, NoWshReason: conn.NoWshReason, WshVersion: conn.WshVersion, @@ -1075,6 +1081,10 @@ func getConnInternal(opts *remote.SSHOpts, createIfNotExists bool) *SSHConn { Status: Status_Init, ConnHealthStatus: ConnHealthStatus_Good, WshEnabled: &atomic.Bool{}, + MoshEnabled: &atomic.Bool{}, + MoshActive: &atomic.Bool{}, + MoshAutoDetected: &atomic.Bool{}, + MoshAutoAvailable: &atomic.Bool{}, Opts: opts, } clientControllerMap[*opts] = rtn diff --git a/pkg/remote/connparse/connparse.go b/pkg/remote/connparse/connparse.go index 349003aaf..a4b8e99c3 100644 --- a/pkg/remote/connparse/connparse.go +++ b/pkg/remote/connparse/connparse.go @@ -92,10 +92,13 @@ func GetConnNameFromContext(ctx context.Context) (string, error) { // ParseURI parses a connection URI and returns the connection type, host/path, and parameters. func ParseURI(uri string) (*Connection, error) { + isWshShorthand := strings.HasPrefix(uri, "//") split := strings.SplitN(uri, "://", 2) var scheme string var rest string - if len(split) > 1 { + if isWshShorthand { + rest = strings.TrimPrefix(uri, "//") + } else if len(split) > 1 { scheme = split[0] rest = strings.TrimPrefix(split[1], "//") } else { @@ -131,8 +134,7 @@ func ParseURI(uri string) (*Connection, error) { if scheme == "" { scheme = ConnectionTypeWsh addPrecedingSlash = false - if len(rest) != len(uri) { - // This accounts for when the uri starts with "//", which would get trimmed in the first split. + if isWshShorthand { parseWshPath() } else if strings.HasPrefix(rest, "/~") { host = wshrpc.LocalConnName diff --git a/pkg/remote/connparse/connparse_test.go b/pkg/remote/connparse/connparse_test.go index e883ef3fb..82a36387b 100644 --- a/pkg/remote/connparse/connparse_test.go +++ b/pkg/remote/connparse/connparse_test.go @@ -81,8 +81,9 @@ func TestParseURI_WSHRemoteShorthand(t *testing.T) { if c.Path != expected { t.Fatalf("expected path to be \"%q\", got \"%q\"", expected, c.Path) } - if c.Host != "conn" { - t.Fatalf("expected host to be empty, got \"%q\"", c.Host) + expected = "conn" + if c.Host != expected { + t.Fatalf("expected host to be \"%q\", got \"%q\"", expected, c.Host) } expected = "wsh" if c.Scheme != expected { diff --git a/pkg/service/objectservice/objectservice.go b/pkg/service/objectservice/objectservice.go index 8d6dc1569..0eb228181 100644 --- a/pkg/service/objectservice/objectservice.go +++ b/pkg/service/objectservice/objectservice.go @@ -72,23 +72,6 @@ func (svc *ObjectService) GetObjects(orefStrArr []string) ([]waveobj.WaveObj, er return wstore.DBSelectORefs(ctx, orefArr) } -func (svc *ObjectService) UpdateTabName_Meta() tsgenmeta.MethodMeta { - return tsgenmeta.MethodMeta{ - ArgNames: []string{"uiContext", "tabId", "name"}, - } -} - -func (svc *ObjectService) UpdateTabName(uiContext waveobj.UIContext, tabId, name string) (waveobj.UpdatesRtnType, error) { - ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout) - defer cancelFn() - ctx = waveobj.ContextWithUpdates(ctx) - err := wstore.UpdateTabName(ctx, tabId, name) - if err != nil { - return nil, fmt.Errorf("error updating tab name: %w", err) - } - return waveobj.ContextGetUpdatesRtn(ctx), nil -} - func (svc *ObjectService) CreateBlock_Meta() tsgenmeta.MethodMeta { return tsgenmeta.MethodMeta{ ArgNames: []string{"uiContext", "blockDef", "rtOpts"}, diff --git a/pkg/service/windowservice/windowservice.go b/pkg/service/windowservice/windowservice.go index f94151e58..81713312f 100644 --- a/pkg/service/windowservice/windowservice.go +++ b/pkg/service/windowservice/windowservice.go @@ -6,10 +6,8 @@ package windowservice import ( "context" "fmt" - "log" "time" - "github.com/wavetermdev/waveterm/pkg/eventbus" "github.com/wavetermdev/waveterm/pkg/panichandler" "github.com/wavetermdev/waveterm/pkg/tsgen/tsgenmeta" "github.com/wavetermdev/waveterm/pkg/waveobj" @@ -82,63 +80,6 @@ func (ws *WindowService) SetWindowPosAndSize(ctx context.Context, windowId strin return waveobj.ContextGetUpdatesRtn(ctx), nil } -func (svc *WindowService) MoveBlockToNewWindow_Meta() tsgenmeta.MethodMeta { - return tsgenmeta.MethodMeta{ - Desc: "move block to new window", - ArgNames: []string{"ctx", "currentTabId", "blockId"}, - } -} - -func (svc *WindowService) MoveBlockToNewWindow(ctx context.Context, currentTabId string, blockId string) (waveobj.UpdatesRtnType, error) { - log.Printf("MoveBlockToNewWindow(%s, %s)", currentTabId, blockId) - ctx = waveobj.ContextWithUpdates(ctx) - tab, err := wstore.DBMustGet[*waveobj.Tab](ctx, currentTabId) - if err != nil { - return nil, fmt.Errorf("error getting tab: %w", err) - } - log.Printf("tab.BlockIds[%s]: %v", tab.OID, tab.BlockIds) - var foundBlock bool - for _, tabBlockId := range tab.BlockIds { - if tabBlockId == blockId { - foundBlock = true - break - } - } - if !foundBlock { - return nil, fmt.Errorf("block not found in current tab") - } - newWindow, err := wcore.CreateWindow(ctx, nil, "") - if err != nil { - return nil, fmt.Errorf("error creating window: %w", err) - } - ws, err := wcore.GetWorkspace(ctx, newWindow.WorkspaceId) - if err != nil { - return nil, fmt.Errorf("error getting workspace: %w", err) - } - err = wstore.MoveBlockToTab(ctx, currentTabId, ws.ActiveTabId, blockId) - if err != nil { - return nil, fmt.Errorf("error moving block to tab: %w", err) - } - eventbus.SendEventToElectron(eventbus.WSEventType{ - EventType: eventbus.WSEvent_ElectronNewWindow, - Data: newWindow.OID, - }) - windowCreated := eventbus.BusyWaitForWindowId(newWindow.OID, 2*time.Second) - if !windowCreated { - return nil, fmt.Errorf("new window not created") - } - wcore.QueueLayoutActionForTab(ctx, currentTabId, waveobj.LayoutActionData{ - ActionType: wcore.LayoutActionDataType_Remove, - BlockId: blockId, - }) - wcore.QueueLayoutActionForTab(ctx, ws.ActiveTabId, waveobj.LayoutActionData{ - ActionType: wcore.LayoutActionDataType_Insert, - BlockId: blockId, - Focused: true, - }) - return waveobj.ContextGetUpdatesRtn(ctx), nil -} - func (svc *WindowService) SwitchWorkspace_Meta() tsgenmeta.MethodMeta { return tsgenmeta.MethodMeta{ ArgNames: []string{"ctx", "windowId", "workspaceId"}, diff --git a/pkg/service/workspaceservice/workspaceservice.go b/pkg/service/workspaceservice/workspaceservice.go index c0d5072a4..1d7b116bd 100644 --- a/pkg/service/workspaceservice/workspaceservice.go +++ b/pkg/service/workspaceservice/workspaceservice.go @@ -6,7 +6,6 @@ package workspaceservice import ( "context" "fmt" - "log" "time" "github.com/wavetermdev/waveterm/pkg/blockcontroller" @@ -165,24 +164,6 @@ func (svc *WorkspaceService) CreateTab(workspaceId string, tabName string, activ return tabId, updates, nil } -func (svc *WorkspaceService) UpdateTabIds_Meta() tsgenmeta.MethodMeta { - return tsgenmeta.MethodMeta{ - ArgNames: []string{"uiContext", "workspaceId", "tabIds"}, - } -} - -func (svc *WorkspaceService) UpdateTabIds(uiContext waveobj.UIContext, workspaceId string, tabIds []string) (waveobj.UpdatesRtnType, error) { - log.Printf("UpdateTabIds %s %v\n", workspaceId, tabIds) - ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout) - defer cancelFn() - ctx = waveobj.ContextWithUpdates(ctx) - err := wcore.UpdateWorkspaceTabIds(ctx, workspaceId, tabIds) - if err != nil { - return nil, fmt.Errorf("error updating workspace tab ids: %w", err) - } - return waveobj.ContextGetUpdatesRtn(ctx), nil -} - func (svc *WorkspaceService) SetActiveTab_Meta() tsgenmeta.MethodMeta { return tsgenmeta.MethodMeta{ ArgNames: []string{"workspaceId", "tabId"}, diff --git a/pkg/shellexec/conninterface.go b/pkg/shellexec/conninterface.go index f17a83c21..31a559780 100644 --- a/pkg/shellexec/conninterface.go +++ b/pkg/shellexec/conninterface.go @@ -14,7 +14,9 @@ import ( "github.com/creack/pty" "github.com/wavetermdev/waveterm/pkg/panichandler" + "github.com/wavetermdev/waveterm/pkg/util/ptyutil" "github.com/wavetermdev/waveterm/pkg/util/unixutil" + "github.com/wavetermdev/waveterm/pkg/waveobj" "github.com/wavetermdev/waveterm/pkg/wsl" "golang.org/x/crypto/ssh" ) @@ -29,7 +31,7 @@ type ConnInterface interface { StdinPipe() (io.WriteCloser, error) StdoutPipe() (io.ReadCloser, error) StderrPipe() (io.ReadCloser, error) - SetSize(w int, h int) error + SetSize(termSize waveobj.TermSize) error pty.Pty } @@ -133,12 +135,8 @@ func (cw CmdWrap) StderrPipe() (io.ReadCloser, error) { return cw.Cmd.StderrPipe() } -func (cw CmdWrap) SetSize(w int, h int) error { - err := pty.Setsize(cw.Pty, &pty.Winsize{Rows: uint16(w), Cols: uint16(h)}) - if err != nil { - return err - } - return nil +func (cw CmdWrap) SetSize(termSize waveobj.TermSize) error { + return pty.Setsize(cw.Pty, ptyutil.WinsizeFromTermSize(termSize)) } type SessionWrap struct { @@ -221,8 +219,8 @@ func (sw SessionWrap) StderrPipe() (io.ReadCloser, error) { return io.NopCloser(stderrReader), nil } -func (sw SessionWrap) SetSize(h int, w int) error { - return sw.Session.WindowChange(h, w) +func (sw SessionWrap) SetSize(termSize waveobj.TermSize) error { + return sw.Session.WindowChange(termSize.Rows, termSize.Cols) } type WslCmdWrap struct { @@ -263,6 +261,6 @@ func (wcw WslCmdWrap) KillGraceful(timeout time.Duration) { * SetSize does nothing for WslCmdWrap as there * is no pty to manage. **/ -func (wcw WslCmdWrap) SetSize(w int, h int) error { +func (wcw WslCmdWrap) SetSize(termSize waveobj.TermSize) error { return nil } diff --git a/pkg/shellexec/shellexec.go b/pkg/shellexec/shellexec.go index 4850eee1b..da9edb221 100644 --- a/pkg/shellexec/shellexec.go +++ b/pkg/shellexec/shellexec.go @@ -21,10 +21,12 @@ import ( "github.com/creack/pty" "github.com/wavetermdev/waveterm/pkg/blocklogger" + "github.com/wavetermdev/waveterm/pkg/genconn" "github.com/wavetermdev/waveterm/pkg/jobcontroller" "github.com/wavetermdev/waveterm/pkg/panichandler" "github.com/wavetermdev/waveterm/pkg/remote/conncontroller" "github.com/wavetermdev/waveterm/pkg/util/pamparse" + "github.com/wavetermdev/waveterm/pkg/util/ptyutil" "github.com/wavetermdev/waveterm/pkg/util/shellutil" "github.com/wavetermdev/waveterm/pkg/wavebase" "github.com/wavetermdev/waveterm/pkg/waveobj" @@ -165,7 +167,7 @@ func StartWslShellProcNoWsh(ctx context.Context, termSize waveobj.TermSize, cmdS if termSize.Rows <= 0 || termSize.Cols <= 0 { return nil, fmt.Errorf("invalid term size: %v", termSize) } - cmdPty, err := pty.StartWithSize(ecmd, &pty.Winsize{Rows: uint16(termSize.Rows), Cols: uint16(termSize.Cols)}) + cmdPty, err := pty.StartWithSize(ecmd, ptyutil.WinsizeFromTermSize(termSize)) if err != nil { return nil, err } @@ -283,7 +285,7 @@ func StartWslShellProc(ctx context.Context, termSize waveobj.TermSize, cmdStr st return nil, fmt.Errorf("invalid term size: %v", termSize) } shellutil.AddTokenSwapEntry(cmdOpts.SwapToken) - cmdPty, err := pty.StartWithSize(ecmd, &pty.Winsize{Rows: uint16(termSize.Rows), Cols: uint16(termSize.Cols)}) + cmdPty, err := pty.StartWithSize(ecmd, ptyutil.WinsizeFromTermSize(termSize)) if err != nil { return nil, err } @@ -334,6 +336,54 @@ func StartRemoteShellProcNoWsh(ctx context.Context, termSize waveobj.TermSize, c return &ShellProc{Cmd: sessionWrap, ConnName: conn.GetName(), CloseOnce: &sync.Once{}, DoneCh: make(chan any)}, nil } +// StartMoshShellProc starts a mosh-client process that connects to a remote server. +// SSH is used to start mosh-server, then mosh-client is spawned locally with a PTY. +// The SSH connection remains alive for wsh features (file ops, RPC). +func StartMoshShellProc(ctx context.Context, logCtx context.Context, termSize waveobj.TermSize, conn *conncontroller.SSHConn) (*ShellProc, error) { + client := conn.GetClient() + if client == nil { + return nil, fmt.Errorf("ssh client not connected") + } + conn.Infof(logCtx, "MOSH: Starting mosh shell process\n") + + // Create MoshShellClient and start mosh-server via SSH + moshClient := genconn.MakeMoshShellClient(client, conn.Opts.SSHHost) + + // MakeProcessController starts mosh-server via SSH and prepares the local mosh-client command. + // It validates remote mosh-server, finds local mosh-client, starts mosh-server, + // parses MOSH CONNECT output, and creates the exec.Cmd. + moshProc, err := moshClient.MakeProcessController(genconn.CommandSpec{}) + if err != nil { + return nil, fmt.Errorf("failed to create mosh process: %w", err) + } + + // Extract the underlying exec.Cmd from MoshProcessController + moshCtrl, ok := moshProc.(*genconn.MoshProcessController) + if !ok { + return nil, fmt.Errorf("unexpected mosh process controller type") + } + ecmd := moshCtrl.GetCmd() + + if termSize.Rows == 0 || termSize.Cols == 0 { + termSize.Rows = shellutil.DefaultTermRows + termSize.Cols = shellutil.DefaultTermCols + } + if termSize.Rows <= 0 || termSize.Cols <= 0 { + return nil, fmt.Errorf("invalid term size: %v", termSize) + } + + // Start mosh-client with a local PTY (same pattern as StartLocalShellProc) + cmdPty, err := pty.StartWithSize(ecmd, &pty.Winsize{Rows: uint16(termSize.Rows), Cols: uint16(termSize.Cols)}) + if err != nil { + return nil, fmt.Errorf("failed to start mosh-client with PTY: %w", err) + } + + cmdWrap := MakeCmdWrap(ecmd, cmdPty, true) + conn.Infof(logCtx, "MOSH: mosh-client started with PTY (pid=%d)\n", ecmd.Process.Pid) + + return &ShellProc{Cmd: cmdWrap, ConnName: conn.GetName(), CloseOnce: &sync.Once{}, DoneCh: make(chan any)}, nil +} + func StartRemoteShellProc(ctx context.Context, logCtx context.Context, termSize waveobj.TermSize, cmdStr string, cmdOpts CommandOptsType, conn *conncontroller.SSHConn) (*ShellProc, error) { if cmdOpts.SwapToken == nil { return nil, fmt.Errorf("SwapToken is required in CommandOptsType") @@ -684,7 +734,7 @@ func StartLocalShellProc(logCtx context.Context, termSize waveobj.TermSize, cmdS return nil, fmt.Errorf("invalid term size: %v", termSize) } shellutil.AddTokenSwapEntry(cmdOpts.SwapToken) - cmdPty, err := pty.StartWithSize(ecmd, &pty.Winsize{Rows: uint16(termSize.Rows), Cols: uint16(termSize.Cols)}) + cmdPty, err := pty.StartWithSize(ecmd, ptyutil.WinsizeFromTermSize(termSize)) if err != nil { return nil, err } @@ -702,7 +752,7 @@ func RunSimpleCmdInPty(ecmd *exec.Cmd, termSize waveobj.TermSize) ([]byte, error if termSize.Rows <= 0 || termSize.Cols <= 0 { return nil, fmt.Errorf("invalid term size: %v", termSize) } - cmdPty, err := pty.StartWithSize(ecmd, &pty.Winsize{Rows: uint16(termSize.Rows), Cols: uint16(termSize.Cols)}) + cmdPty, err := pty.StartWithSize(ecmd, ptyutil.WinsizeFromTermSize(termSize)) if err != nil { cmdPty.Close() return nil, err diff --git a/pkg/telemetry/telemetrydata/telemetrydata.go b/pkg/telemetry/telemetrydata/telemetrydata.go index 463be152b..222ebfbae 100644 --- a/pkg/telemetry/telemetrydata/telemetrydata.go +++ b/pkg/telemetry/telemetrydata/telemetrydata.go @@ -29,6 +29,7 @@ var ValidEventNames = map[string]bool{ "action:other": true, "action:term": true, "action:termdurable": true, + "action:link": true, "wsh:run": true, @@ -75,6 +76,8 @@ type TEventUserProps struct { ClientBuildTime string `json:"client:buildtime,omitempty"` ClientOSRelease string `json:"client:osrelease,omitempty"` ClientIsDev bool `json:"client:isdev,omitempty"` + ClientPackageType string `json:"client:packagetype,omitempty"` + ClientMacOSVersion string `json:"client:macos,omitempty"` CohortMonth string `json:"cohort:month,omitempty"` CohortISOWeek string `json:"cohort:isoweek,omitempty"` @@ -126,15 +129,16 @@ type TEventProps struct { WshCmd string `json:"wsh:cmd,omitempty"` WshHadError bool `json:"wsh:haderror,omitempty"` - ConnType string `json:"conn:conntype,omitempty"` - ConnWshErrorCode string `json:"conn:wsherrorcode,omitempty"` - ConnErrorCode string `json:"conn:errorcode,omitempty"` - ConnSubErrorCode string `json:"conn:suberrorcode,omitempty"` - ConnContextError bool `json:"conn:contexterror,omitempty"` + ConnType string `json:"conn:conntype,omitempty"` + ConnWshErrorCode string `json:"conn:wsherrorcode,omitempty"` + ConnErrorCode string `json:"conn:errorcode,omitempty"` + ConnSubErrorCode string `json:"conn:suberrorcode,omitempty"` + ConnContextError bool `json:"conn:contexterror,omitempty"` OnboardingFeature string `json:"onboarding:feature,omitempty" tstype:"\"waveai\" | \"durable\" | \"magnify\" | \"wsh\""` OnboardingVersion string `json:"onboarding:version,omitempty"` OnboardingGithubStar string `json:"onboarding:githubstar,omitempty" tstype:"\"already\" | \"star\" | \"later\""` + OnboardingPage string `json:"onboarding:page,omitempty"` DisplayHeight int `json:"display:height,omitempty"` DisplayWidth int `json:"display:width,omitempty"` diff --git a/pkg/tsgen/tsgen.go b/pkg/tsgen/tsgen.go index 23bc2f7b8..89c782c59 100644 --- a/pkg/tsgen/tsgen.go +++ b/pkg/tsgen/tsgen.go @@ -54,7 +54,6 @@ var ExtraTypes = []any{ waveobj.ObjRTInfo{}, uctypes.RateLimitInfo{}, wconfig.AIModeConfigUpdate{}, - wshrpc.TabIndicatorEventData{}, wshrpc.BlockJobStatusData{}, } @@ -413,7 +412,7 @@ func GenerateMethodSignature(serviceName string, method reflect.Method, meta tsg } func GenerateMethodBody(serviceName string, method reflect.Method, meta tsgenmeta.MethodMeta) string { - return fmt.Sprintf(" return WOS.callBackendService(%q, %q, Array.from(arguments))\n", serviceName, method.Name) + return fmt.Sprintf(" return callBackendService(this?.waveEnv, %q, %q, Array.from(arguments))\n", serviceName, method.Name) } func GenerateServiceClass(serviceName string, serviceObj any, tsTypesMap map[reflect.Type]string) string { @@ -421,9 +420,13 @@ func GenerateServiceClass(serviceName string, serviceObj any, tsTypesMap map[ref var sb strings.Builder tsServiceName := serviceType.Elem().Name() sb.WriteString(fmt.Sprintf("// %s (%s)\n", serviceType.Elem().String(), serviceName)) - sb.WriteString("class ") + sb.WriteString("export class ") sb.WriteString(tsServiceName + "Type") sb.WriteString(" {\n") + sb.WriteString(" waveEnv: WaveEnv;\n\n") + sb.WriteString(" constructor(waveEnv?: WaveEnv) {\n") + sb.WriteString(" this.waveEnv = waveEnv;\n") + sb.WriteString(" }\n\n") isFirst := true for midx := 0; midx < serviceType.NumMethod(); midx++ { method := serviceType.Method(midx) @@ -464,17 +467,14 @@ func generateWshClientApiMethod_ResponseStream(methodDecl *wshrpc.WshRpcMethodDe if methodDecl.DefaultResponseDataType != nil { respType, _ = TypeToTSType(methodDecl.DefaultResponseDataType, tsTypesMap) } - dataName := "null" - if methodDecl.CommandDataType != nil { - dataName = "data" - } + methodSigDataParams, dataName := getTsWshMethodDataParamsAndExpr(methodDecl, tsTypesMap) genRespType := fmt.Sprintf("AsyncGenerator<%s, void, boolean>", respType) - if methodDecl.CommandDataType != nil { - cmdDataTsName, _ := TypeToTSType(methodDecl.CommandDataType, tsTypesMap) - sb.WriteString(fmt.Sprintf(" %s(client: WshClient, data: %s, opts?: RpcOpts): %s {\n", methodDecl.MethodName, cmdDataTsName, genRespType)) - } else { + if methodSigDataParams == "" { sb.WriteString(fmt.Sprintf(" %s(client: WshClient, opts?: RpcOpts): %s {\n", methodDecl.MethodName, genRespType)) + } else { + sb.WriteString(fmt.Sprintf(" %s(client: WshClient, %s, opts?: RpcOpts): %s {\n", methodDecl.MethodName, methodSigDataParams, genRespType)) } + sb.WriteString(fmt.Sprintf(" if (this.mockClient) return this.mockClient.mockWshRpcStream(client, %q, %s, opts);\n", methodDecl.Command, dataName)) sb.WriteString(fmt.Sprintf(" return client.wshRpcStream(%q, %s, opts);\n", methodDecl.Command, dataName)) sb.WriteString(" }\n") return sb.String() @@ -488,22 +488,42 @@ func generateWshClientApiMethod_Call(methodDecl *wshrpc.WshRpcMethodDecl, tsType rtnTypeName, _ := TypeToTSType(methodDecl.DefaultResponseDataType, tsTypesMap) rtnType = fmt.Sprintf("Promise<%s>", rtnTypeName) } - dataName := "null" - if methodDecl.CommandDataType != nil { - dataName = "data" - } - if methodDecl.CommandDataType != nil { - cmdDataTsName, _ := TypeToTSType(methodDecl.CommandDataType, tsTypesMap) - sb.WriteString(fmt.Sprintf(" %s(client: WshClient, data: %s, opts?: RpcOpts): %s {\n", methodDecl.MethodName, cmdDataTsName, rtnType)) - } else { + methodSigDataParams, dataName := getTsWshMethodDataParamsAndExpr(methodDecl, tsTypesMap) + if methodSigDataParams == "" { sb.WriteString(fmt.Sprintf(" %s(client: WshClient, opts?: RpcOpts): %s {\n", methodDecl.MethodName, rtnType)) + } else { + sb.WriteString(fmt.Sprintf(" %s(client: WshClient, %s, opts?: RpcOpts): %s {\n", methodDecl.MethodName, methodSigDataParams, rtnType)) } - methodBody := fmt.Sprintf(" return client.wshRpcCall(%q, %s, opts);\n", methodDecl.Command, dataName) - sb.WriteString(methodBody) + sb.WriteString(fmt.Sprintf(" if (this.mockClient) return this.mockClient.mockWshRpcCall(client, %q, %s, opts);\n", methodDecl.Command, dataName)) + sb.WriteString(fmt.Sprintf(" return client.wshRpcCall(%q, %s, opts);\n", methodDecl.Command, dataName)) sb.WriteString(" }\n") return sb.String() } +func getTsWshMethodDataParamsAndExpr(methodDecl *wshrpc.WshRpcMethodDecl, tsTypesMap map[reflect.Type]string) (string, string) { + dataTypes := methodDecl.GetCommandDataTypes() + if len(dataTypes) == 0 { + return "", "null" + } + if len(dataTypes) == 1 { + cmdDataTsName, _ := TypeToTSType(dataTypes[0], tsTypesMap) + return fmt.Sprintf("data: %s", cmdDataTsName), "data" + } + var methodParamBuilder strings.Builder + var argBuilder strings.Builder + for idx, dataType := range dataTypes { + if idx > 0 { + methodParamBuilder.WriteString(", ") + argBuilder.WriteString(", ") + } + argName := fmt.Sprintf("arg%d", idx+1) + cmdDataTsName, _ := TypeToTSType(dataType, tsTypesMap) + methodParamBuilder.WriteString(fmt.Sprintf("%s: %s", argName, cmdDataTsName)) + argBuilder.WriteString(argName) + } + return methodParamBuilder.String(), fmt.Sprintf("{ args: [%s] }", argBuilder.String()) +} + func GenerateWaveObjTypes(tsTypesMap map[reflect.Type]string) { for _, typeUnion := range TypeUnions { GenerateTSTypeUnion(typeUnion, tsTypesMap) diff --git a/pkg/tsgen/tsgen_wshclientapi_test.go b/pkg/tsgen/tsgen_wshclientapi_test.go new file mode 100644 index 000000000..2839a8be4 --- /dev/null +++ b/pkg/tsgen/tsgen_wshclientapi_test.go @@ -0,0 +1,28 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package tsgen + +import ( + "reflect" + "strings" + "testing" + + "github.com/wavetermdev/waveterm/pkg/wshrpc" +) + +func TestGenerateWshClientApiMethodCall_MultiArg(t *testing.T) { + methodDecl := &wshrpc.WshRpcMethodDecl{ + Command: "test", + CommandType: wshrpc.RpcType_Call, + MethodName: "TestCommand", + CommandDataTypes: []reflect.Type{reflect.TypeOf(""), reflect.TypeOf(0)}, + } + out := GenerateWshClientApiMethod(methodDecl, map[reflect.Type]string{}) + if !strings.Contains(out, "TestCommand(client: WshClient, arg1: string, arg2: number, opts?: RpcOpts): Promise {") { + t.Fatalf("generated method missing multi-arg signature:\n%s", out) + } + if !strings.Contains(out, "return client.wshRpcCall(\"test\", { args: [arg1, arg2] }, opts);") { + t.Fatalf("generated method missing MultiArg payload:\n%s", out) + } +} diff --git a/pkg/tsgen/tsgenevent.go b/pkg/tsgen/tsgenevent.go index b232d517c..6e1c08e98 100644 --- a/pkg/tsgen/tsgenevent.go +++ b/pkg/tsgen/tsgenevent.go @@ -10,6 +10,7 @@ import ( "strconv" "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" + "github.com/wavetermdev/waveterm/pkg/baseds" "github.com/wavetermdev/waveterm/pkg/blockcontroller" "github.com/wavetermdev/waveterm/pkg/userinput" "github.com/wavetermdev/waveterm/pkg/waveobj" @@ -38,8 +39,8 @@ var WaveEventDataTypes = map[string]reflect.Type{ wps.Event_WaveAppAppGoUpdated: nil, wps.Event_TsunamiUpdateMeta: reflect.TypeOf(wshrpc.AppMeta{}), wps.Event_AIModeConfig: reflect.TypeOf(wconfig.AIModeConfigUpdate{}), - wps.Event_TabIndicator: reflect.TypeOf(wshrpc.TabIndicatorEventData{}), wps.Event_BlockJobStatus: reflect.TypeOf(wshrpc.BlockJobStatusData{}), + wps.Event_Badge: reflect.TypeOf(baseds.BadgeEvent{}), } func getWaveEventDataTSType(eventName string, tsTypesMap map[reflect.Type]string) string { @@ -66,12 +67,9 @@ func GenerateWaveEventTypes(tsTypesMap map[reflect.Type]string) string { var buf bytes.Buffer buf.WriteString("// wps.WaveEvent\n") - buf.WriteString("type WaveEventName = ") - for idx, eventName := range wps.AllEvents { - if idx > 0 { - buf.WriteString(" | ") - } - buf.WriteString(strconv.Quote(eventName)) + buf.WriteString("type WaveEventName =\n") + for _, eventName := range wps.AllEvents { + buf.WriteString(fmt.Sprintf(" | %s\n", strconv.Quote(eventName))) } buf.WriteString(";\n\n") buf.WriteString("type WaveEvent = {\n") diff --git a/pkg/util/ds/syncmap.go b/pkg/util/ds/syncmap.go index a422343ac..99b4095ef 100644 --- a/pkg/util/ds/syncmap.go +++ b/pkg/util/ds/syncmap.go @@ -62,3 +62,14 @@ func (sm *SyncMap[T]) TestAndSet(key string, newValue T, testFn func(T, bool) bo } return false } + +func (sm *SyncMap[T]) GetOrCreate(key string, createFn func() T) T { + sm.lock.Lock() + defer sm.lock.Unlock() + if v, ok := sm.m[key]; ok { + return v + } + v := createFn() + sm.m[key] = v + return v +} diff --git a/pkg/util/fileutil/fileutil.go b/pkg/util/fileutil/fileutil.go index 85f48077a..a26409e5e 100644 --- a/pkg/util/fileutil/fileutil.go +++ b/pkg/util/fileutil/fileutil.go @@ -14,10 +14,8 @@ import ( "path/filepath" "regexp" "strings" - "time" "github.com/wavetermdev/waveterm/pkg/wavebase" - "github.com/wavetermdev/waveterm/pkg/wshrpc" ) func FixPath(path string) (string, error) { @@ -145,13 +143,21 @@ func DetectMimeTypeWithDirEnt(path string, dirEnt fs.DirEntry) string { return "" } -func AddMimeTypeToFileInfo(path string, fileInfo *wshrpc.FileInfo) { - if fileInfo == nil { - return +func AtomicWriteFile(fileName string, data []byte, perm os.FileMode) error { + tmpFileName := fileName + TempFileSuffix + if err := os.WriteFile(tmpFileName, data, perm); err != nil { + if removeErr := os.Remove(tmpFileName); removeErr != nil && !os.IsNotExist(removeErr) { + return fmt.Errorf("failed to write temp file %q: %w (also failed to remove temp file: %v)", tmpFileName, err, removeErr) + } + return err } - if fileInfo.MimeType == "" { - fileInfo.MimeType = DetectMimeType(path, ToFsFileInfo(fileInfo), false) + if err := os.Rename(tmpFileName, fileName); err != nil { + if removeErr := os.Remove(tmpFileName); removeErr != nil && !os.IsNotExist(removeErr) { + return fmt.Errorf("failed to rename temp file %q to %q: %w (also failed to remove temp file: %v)", tmpFileName, fileName, err, removeErr) + } + return err } + return nil } var ( @@ -203,56 +209,8 @@ func IsInitScriptPath(input string) bool { return true } -type FsFileInfo struct { - NameInternal string - ModeInternal os.FileMode - SizeInternal int64 - ModTimeInternal int64 - IsDirInternal bool -} - -func (f FsFileInfo) Name() string { - return f.NameInternal -} - -func (f FsFileInfo) Size() int64 { - return f.SizeInternal -} - -func (f FsFileInfo) Mode() os.FileMode { - return f.ModeInternal -} - -func (f FsFileInfo) ModTime() time.Time { - return time.Unix(0, f.ModTimeInternal) -} - -func (f FsFileInfo) IsDir() bool { - return f.IsDirInternal -} - -func (f FsFileInfo) Sys() interface{} { - return nil -} - -var _ fs.FileInfo = FsFileInfo{} - -// ToFsFileInfo converts wshrpc.FileInfo to FsFileInfo. -// It panics if fi is nil. -func ToFsFileInfo(fi *wshrpc.FileInfo) FsFileInfo { - if fi == nil { - panic("ToFsFileInfo: nil FileInfo") - } - return FsFileInfo{ - NameInternal: fi.Name, - ModeInternal: fi.Mode, - SizeInternal: fi.Size, - ModTimeInternal: fi.ModTime, - IsDirInternal: fi.IsDir, - } -} - const ( + TempFileSuffix = ".tmp" MaxEditFileSize = 5 * 1024 * 1024 // 5MB ) diff --git a/pkg/util/fileutil/fileutil_test.go b/pkg/util/fileutil/fileutil_test.go new file mode 100644 index 000000000..c3441523d --- /dev/null +++ b/pkg/util/fileutil/fileutil_test.go @@ -0,0 +1,45 @@ +package fileutil + +import ( + "os" + "path/filepath" + "testing" +) + +func TestAtomicWriteFile(t *testing.T) { + tmpDir := t.TempDir() + fileName := filepath.Join(tmpDir, "settings.json") + + err := AtomicWriteFile(fileName, []byte(`{"key":"value"}`), 0644) + if err != nil { + t.Fatalf("AtomicWriteFile failed: %v", err) + } + + data, err := os.ReadFile(fileName) + if err != nil { + t.Fatalf("ReadFile failed: %v", err) + } + if string(data) != `{"key":"value"}` { + t.Fatalf("unexpected file contents: %q", string(data)) + } + if _, err := os.Stat(fileName + TempFileSuffix); !os.IsNotExist(err) { + t.Fatalf("temporary file should not exist, stat err: %v", err) + } +} + +func TestAtomicWriteFileRenameErrorCleansTempFile(t *testing.T) { + tmpDir := t.TempDir() + fileName := filepath.Join(tmpDir, "settings.json") + + if err := os.Mkdir(fileName, 0755); err != nil { + t.Fatalf("Mkdir failed: %v", err) + } + + err := AtomicWriteFile(fileName, []byte(`{"key":"value"}`), 0644) + if err == nil { + t.Fatalf("AtomicWriteFile expected error") + } + if _, statErr := os.Stat(fileName + TempFileSuffix); !os.IsNotExist(statErr) { + t.Fatalf("temporary file should be removed on rename error, stat err: %v", statErr) + } +} diff --git a/pkg/util/fileutil/mimetypes.go b/pkg/util/fileutil/mimetypes.go index f6baafad8..dade9f2c9 100644 --- a/pkg/util/fileutil/mimetypes.go +++ b/pkg/util/fileutil/mimetypes.go @@ -842,6 +842,7 @@ var StaticMimeTypeMap = map[string]string{ ".xspf": "application/xspf+xml", ".mxml": "application/xv+xml", ".yaml": "application/x-yaml", + ".yml": "application/x-yaml", ".yang": "application/yang", ".yin": "application/yin+xml", ".zip": "application/zip", diff --git a/pkg/util/ptyutil/ptyutil.go b/pkg/util/ptyutil/ptyutil.go new file mode 100644 index 000000000..7b62107a8 --- /dev/null +++ b/pkg/util/ptyutil/ptyutil.go @@ -0,0 +1,30 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package ptyutil + +import ( + "github.com/creack/pty" + "github.com/wavetermdev/waveterm/pkg/waveobj" +) + +const maxUint16 = int(^uint16(0)) + +func toWinsizeDimension(v int) uint16 { + if v <= 0 { + return 0 + } + if v > maxUint16 { + return uint16(maxUint16) + } + return uint16(v) +} + +func WinsizeFromTermSize(termSize waveobj.TermSize) *pty.Winsize { + return &pty.Winsize{ + Rows: toWinsizeDimension(termSize.Rows), + Cols: toWinsizeDimension(termSize.Cols), + X: toWinsizeDimension(termSize.XPixel), + Y: toWinsizeDimension(termSize.YPixel), + } +} diff --git a/pkg/util/shellutil/shellintegration/zsh_zshrc.sh b/pkg/util/shellutil/shellintegration/zsh_zshrc.sh index 07d2df9a4..8617c32a2 100644 --- a/pkg/util/shellutil/shellintegration/zsh_zshrc.sh +++ b/pkg/util/shellutil/shellintegration/zsh_zshrc.sh @@ -18,8 +18,13 @@ if [[ -n ${_comps+x} ]]; then source <(wsh completion zsh) fi -# fix history (macos) -if [[ "$HISTFILE" == "$WAVETERM_ZDOTDIR/.zsh_history" ]]; then +# per-block independent history +if [[ -n "$WAVETERM_BLOCKID" ]]; then + _waveterm_hist_dir="$HOME/.waveterm/shell/zsh/history/$WAVETERM_BLOCKID" + [[ -d "$_waveterm_hist_dir" ]] || mkdir -p "$_waveterm_hist_dir" + HISTFILE="$_waveterm_hist_dir/.zsh_history" + unset _waveterm_hist_dir +elif [[ "$HISTFILE" == "$WAVETERM_ZDOTDIR/.zsh_history" ]]; then HISTFILE="$HOME/.zsh_history" fi @@ -110,33 +115,22 @@ _waveterm_si_preexec() { fi } -typeset -g WAVETERM_SI_INPUTEMPTY=1 - -_waveterm_si_inputempty() { +_waveterm_si_inputreadback() { _waveterm_si_blocked && return - - local current_empty=1 - if [[ -n "$BUFFER" ]]; then - current_empty=0 - fi - - if (( current_empty != WAVETERM_SI_INPUTEMPTY )); then - WAVETERM_SI_INPUTEMPTY=$current_empty - if (( current_empty )); then - printf '\033]16162;I;{"inputempty":true}\007' - else - printf '\033]16162;I;{"inputempty":false}\007' - fi - fi + local buffer64 cursor + # base64 may wrap lines on some platforms, so strip newlines before embedding JSON + buffer64=$(printf '%s' "$BUFFER" | base64 2>/dev/null | tr -d '\n\r') + cursor=$CURSOR + zle -I + printf '\033]16162;I;{"buffer64":"%s","cursor":%d}\007' "$buffer64" "$cursor" } -autoload -Uz add-zle-hook-widget 2>/dev/null -if (( $+functions[add-zle-hook-widget] )); then - add-zle-hook-widget zle-line-init _waveterm_si_inputempty - add-zle-hook-widget zle-line-pre-redraw _waveterm_si_inputempty -fi +zle -N _waveterm_si_inputreadback +bindkey -M emacs '^_Wr' _waveterm_si_inputreadback 2>/dev/null +bindkey -M viins '^_Wr' _waveterm_si_inputreadback 2>/dev/null +bindkey -M vicmd '^_Wr' _waveterm_si_inputreadback 2>/dev/null autoload -U add-zsh-hook add-zsh-hook precmd _waveterm_si_precmd add-zsh-hook preexec _waveterm_si_preexec -add-zsh-hook chpwd _waveterm_si_osc7 \ No newline at end of file +add-zsh-hook chpwd _waveterm_si_osc7 diff --git a/pkg/util/shellutil/shellutil.go b/pkg/util/shellutil/shellutil.go index e6f6c21f3..b1b195b06 100644 --- a/pkg/util/shellutil/shellutil.go +++ b/pkg/util/shellutil/shellutil.go @@ -301,6 +301,42 @@ func HasWaveZshHistory() (bool, int64) { return true, fileInfo.Size() } +func GetBlockZshHistoryDir(blockId string) string { + zshDir := GetLocalZshZDotDir() + return filepath.Join(zshDir, "history", blockId) +} + +func CleanupBlockZshHistory(blockId string) error { + histDir := GetBlockZshHistoryDir(blockId) + err := os.RemoveAll(histDir) + if err != nil && !os.IsNotExist(err) { + return fmt.Errorf("error removing block history dir %s: %w", histDir, err) + } + log.Printf("cleaned up block zsh history dir: %s\n", histDir) + return nil +} + +// getPerBlockHistoryFiles returns a list of per-block .zsh_history file paths +func getPerBlockHistoryFiles() []string { + zshDir := GetLocalZshZDotDir() + historyBaseDir := filepath.Join(zshDir, "history") + entries, err := os.ReadDir(historyBaseDir) + if err != nil { + return nil + } + var files []string + for _, entry := range entries { + if !entry.IsDir() { + continue + } + histFile := filepath.Join(historyBaseDir, entry.Name(), ZshHistoryFileName) + if _, err := os.Stat(histFile); err == nil { + files = append(files, histFile) + } + } + return files +} + func IsExtendedZshHistoryFile(fileName string) (bool, error) { file, err := os.Open(fileName) if err != nil { @@ -550,29 +586,34 @@ func FixupWaveZshHistory() error { return nil } - hasHistory, size := HasWaveZshHistory() - if !hasHistory { - return nil + homeDir, err := os.UserHomeDir() + if err != nil { + return fmt.Errorf("error getting home directory: %w", err) } + realHistFile := filepath.Join(homeDir, ".zsh_history") + + // Collect all history files to merge (legacy wave history + per-block histories) + var histFilesToMerge []string + // Check for legacy wave zsh history file zshDir := GetLocalZshZDotDir() waveHistFile := filepath.Join(zshDir, ZshHistoryFileName) - - if size == 0 { - err := os.Remove(waveHistFile) - if err != nil { - log.Printf("error removing wave zsh history file %s: %v\n", waveHistFile, err) - } - return nil + if fileInfo, err := os.Stat(waveHistFile); err == nil && fileInfo.Size() > 0 { + histFilesToMerge = append(histFilesToMerge, waveHistFile) + } else if err == nil && fileInfo.Size() == 0 { + // remove empty file + os.Remove(waveHistFile) } - log.Printf("merging wave zsh history %s into ~/.zsh_history\n", waveHistFile) + // Collect per-block history files + perBlockFiles := getPerBlockHistoryFiles() + histFilesToMerge = append(histFilesToMerge, perBlockFiles...) - homeDir, err := os.UserHomeDir() - if err != nil { - return fmt.Errorf("error getting home directory: %w", err) + if len(histFilesToMerge) == 0 { + return nil } - realHistFile := filepath.Join(homeDir, ".zsh_history") + + log.Printf("merging %d wave zsh history file(s) into ~/.zsh_history\n", len(histFilesToMerge)) isExtended, err := IsExtendedZshHistoryFile(realHistFile) if err != nil { @@ -584,7 +625,12 @@ func FixupWaveZshHistory() error { hasExtendedStr = "true" } - quotedWaveHistFile := utilfn.ShellQuote(waveHistFile, true, -1) + // Build fc -RI commands for each history file + var fcCommands string + for _, hf := range histFilesToMerge { + quotedFile := utilfn.ShellQuote(hf, true, -1) + fcCommands += fmt.Sprintf("\t\tfc -RI %s\n", quotedFile) + } script := fmt.Sprintf(` HISTFILE=~/.zsh_history @@ -593,11 +639,10 @@ func FixupWaveZshHistory() error { has_extended_history=%s [[ $has_extended_history == true ]] && setopt EXTENDED_HISTORY fc -RI - fc -RI %s - fc -W - `, hasExtendedStr, quotedWaveHistFile) +%s fc -W + `, hasExtendedStr, fcCommands) - ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second) + ctx, cancelFn := context.WithTimeout(context.Background(), 10*time.Second) defer cancelFn() cmd := exec.CommandContext(ctx, "zsh", "-f", "-i", "-c", script) @@ -610,11 +655,27 @@ func FixupWaveZshHistory() error { return fmt.Errorf("error executing zsh history fixup script: %w, output: %s", err, string(output)) } - err = os.Remove(waveHistFile) - if err != nil { - log.Printf("error removing wave zsh history file %s: %v\n", waveHistFile, err) + // Clean up merged history files + for _, hf := range histFilesToMerge { + err = os.Remove(hf) + if err != nil { + log.Printf("error removing wave zsh history file %s: %v\n", hf, err) + } } - log.Printf("successfully merged wave zsh history %s into ~/.zsh_history\n", waveHistFile) + + // Remove empty per-block history directories + historyBaseDir := filepath.Join(zshDir, "history") + entries, err := os.ReadDir(historyBaseDir) + if err == nil { + for _, entry := range entries { + if entry.IsDir() { + blockDir := filepath.Join(historyBaseDir, entry.Name()) + os.Remove(blockDir) // only removes if empty + } + } + } + + log.Printf("successfully merged %d wave zsh history file(s) into ~/.zsh_history\n", len(histFilesToMerge)) return nil } diff --git a/pkg/util/unixutil/unixutil_unix.go b/pkg/util/unixutil/unixutil_unix.go index 23a9e9e7b..f47a0e0f3 100644 --- a/pkg/util/unixutil/unixutil_unix.go +++ b/pkg/util/unixutil/unixutil_unix.go @@ -68,3 +68,15 @@ func SignalTerm(pid int) error { func SignalHup(pid int) error { return syscall.Kill(pid, syscall.SIGHUP) } + +func IsPidRunning(pid int) bool { + if pid <= 0 { + return false + } + err := syscall.Kill(pid, 0) + // EPERM means no permission, but it exists (ESRCH is not found) + if err == nil || err == syscall.EPERM { + return true + } + return false +} diff --git a/pkg/util/unixutil/unixutil_windows.go b/pkg/util/unixutil/unixutil_windows.go index 15352a043..5c7f72aba 100644 --- a/pkg/util/unixutil/unixutil_windows.go +++ b/pkg/util/unixutil/unixutil_windows.go @@ -40,3 +40,7 @@ func SignalTerm(pid int) error { func SignalHup(pid int) error { return nil } + +func IsPidRunning(pid int) bool { + return false +} diff --git a/pkg/wavebase/wavebase.go b/pkg/wavebase/wavebase.go index 822451ebb..f24a22674 100644 --- a/pkg/wavebase/wavebase.go +++ b/pkg/wavebase/wavebase.go @@ -346,6 +346,46 @@ func ClientArch() string { return fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH) } +func ClientPackageType() string { + if os.Getenv("SNAP") != "" { + return "snap" + } + if os.Getenv("APPIMAGE") != "" { + return "appimage" + } + return "" +} + +var macOSVersionOnce = &sync.Once{} +var cachedMacOSVersion string + +var macOSVersionRegex = regexp.MustCompile(`^(\d+\.\d+(?:\.\d+)?)`) + +func internalMacOSVersion() string { + ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) + defer cancelFn() + out, err := exec.CommandContext(ctx, "sw_vers", "-productVersion").Output() + if err != nil { + return "" + } + versionStr := strings.TrimSpace(string(out)) + m := macOSVersionRegex.FindStringSubmatch(versionStr) + if len(m) < 2 { + return "" + } + return m[1] +} + +func ClientMacOSVersion() string { + if runtime.GOOS != "darwin" { + return "" + } + macOSVersionOnce.Do(func() { + cachedMacOSVersion = internalMacOSVersion() + }) + return cachedMacOSVersion +} + var releaseRegex = regexp.MustCompile(`^(\d+\.\d+\.\d+)`) var osReleaseOnce = &sync.Once{} var osRelease string diff --git a/pkg/waveobj/metaconsts.go b/pkg/waveobj/metaconsts.go index 8399340cf..7028d050b 100644 --- a/pkg/waveobj/metaconsts.go +++ b/pkg/waveobj/metaconsts.go @@ -89,6 +89,8 @@ const ( MetaKey_SysinfoType = "sysinfo:type" + MetaKey_TabFlagColor = "tab:flagcolor" + MetaKey_BgClear = "bg:*" MetaKey_Bg = "bg" MetaKey_BgOpacity = "bg:opacity" @@ -96,6 +98,8 @@ const ( MetaKey_BgBorderColor = "bg:bordercolor" MetaKey_BgActiveBorderColor = "bg:activebordercolor" + MetaKey_LayoutVTabBarWidth = "layout:vtabbarwidth" + MetaKey_WaveAiPanelOpen = "waveai:panelopen" MetaKey_WaveAiPanelWidth = "waveai:panelwidth" MetaKey_WaveAiModel = "waveai:model" @@ -121,6 +125,7 @@ const ( MetaKey_TermConnDebug = "term:conndebug" MetaKey_TermBellSound = "term:bellsound" MetaKey_TermBellIndicator = "term:bellindicator" + MetaKey_TermOsc52 = "term:osc52" MetaKey_TermDurable = "term:durable" MetaKey_WebZoom = "web:zoom" diff --git a/pkg/waveobj/objrtinfo.go b/pkg/waveobj/objrtinfo.go index a7b35bbd8..778e42e16 100644 --- a/pkg/waveobj/objrtinfo.go +++ b/pkg/waveobj/objrtinfo.go @@ -15,7 +15,8 @@ type ObjRTInfo struct { ShellIntegration bool `json:"shell:integration,omitempty"` ShellOmz bool `json:"shell:omz,omitempty"` ShellComp string `json:"shell:comp,omitempty"` - ShellInputEmpty bool `json:"shell:inputempty,omitempty"` + ShellInputBuffer64 *string `json:"shell:inputbuffer64,omitempty"` + ShellInputCursor *int `json:"shell:inputcursor,omitempty"` ShellLastCmd string `json:"shell:lastcmd,omitempty"` ShellLastCmdExitCode int `json:"shell:lastcmdexitcode,omitempty"` diff --git a/pkg/waveobj/wtype.go b/pkg/waveobj/wtype.go index 0ac9e92eb..1ce3690cd 100644 --- a/pkg/waveobj/wtype.go +++ b/pkg/waveobj/wtype.go @@ -368,6 +368,8 @@ func AllWaveObjTypes() []reflect.Type { } type TermSize struct { - Rows int `json:"rows"` - Cols int `json:"cols"` + Rows int `json:"rows"` + Cols int `json:"cols"` + XPixel int `json:"xpixel,omitempty"` + YPixel int `json:"ypixel,omitempty"` } diff --git a/pkg/waveobj/wtypemeta.go b/pkg/waveobj/wtypemeta.go index da7389236..027ff3eff 100644 --- a/pkg/waveobj/wtypemeta.go +++ b/pkg/waveobj/wtypemeta.go @@ -92,6 +92,7 @@ type MetaTSType struct { SysinfoType string `json:"sysinfo:type,omitempty"` // for tabs + TabFlagColor string `json:"tab:flagcolor,omitempty"` BgClear bool `json:"bg:*,omitempty"` Bg string `json:"bg,omitempty"` BgOpacity float64 `json:"bg:opacity,omitempty"` @@ -99,6 +100,9 @@ type MetaTSType struct { BgBorderColor string `json:"bg:bordercolor,omitempty"` // frame:bordercolor BgActiveBorderColor string `json:"bg:activebordercolor,omitempty"` // frame:activebordercolor + // for workspace + LayoutVTabBarWidth int `json:"layout:vtabbarwidth,omitempty"` + // for tabs+waveai WaveAiPanelOpen bool `json:"waveai:panelopen,omitempty"` WaveAiPanelWidth int `json:"waveai:panelwidth,omitempty"` @@ -125,6 +129,7 @@ type MetaTSType struct { TermConnDebug string `json:"term:conndebug,omitempty"` // null, info, debug TermBellSound *bool `json:"term:bellsound,omitempty"` TermBellIndicator *bool `json:"term:bellindicator,omitempty"` + TermOsc52 string `json:"term:osc52,omitempty"` TermDurable *bool `json:"term:durable,omitempty"` WebZoom float64 `json:"web:zoom,omitempty"` diff --git a/pkg/wconfig/defaultconfig/settings.json b/pkg/wconfig/defaultconfig/settings.json index 75782a8c3..8ed6af723 100644 --- a/pkg/wconfig/defaultconfig/settings.json +++ b/pkg/wconfig/defaultconfig/settings.json @@ -4,6 +4,7 @@ "ai:maxtokens": 4000, "ai:timeoutms": 60000, "app:defaultnewblock": "term", + "app:tabbar": "top", "app:confirmquit": true, "app:hideaibutton": false, "app:disablectrlshiftarrows": false, @@ -21,7 +22,7 @@ "window:maxtabcachesize": 10, "window:nativetitlebar": true, "window:magnifiedblockopacity": 0.6, - "window:magnifiedblocksize": 0.9, + "window:magnifiedblocksize": 0.95, "window:magnifiedblockblurprimarypx": 10, "window:fullscreenonlaunch": false, "window:magnifiedblockblursecondarypx": 2, @@ -29,11 +30,13 @@ "window:savelastwindow": true, "telemetry:enabled": true, "term:bellsound": false, - "term:bellindicator": false, + "term:bellindicator": true, + "term:osc52": "always", "term:cursor": "block", "term:cursorblink": false, "term:copyonselect": true, "term:durable": false, "waveai:showcloudmodes": true, - "waveai:defaultmode": "waveai@balanced" + "waveai:defaultmode": "waveai@balanced", + "preview:defaultsort": "name" } diff --git a/pkg/wconfig/metaconsts.go b/pkg/wconfig/metaconsts.go index 52dfa4514..f2328a3a0 100644 --- a/pkg/wconfig/metaconsts.go +++ b/pkg/wconfig/metaconsts.go @@ -17,6 +17,7 @@ const ( ConfigKey_AppDisableCtrlShiftArrows = "app:disablectrlshiftarrows" ConfigKey_AppDisableCtrlShiftDisplay = "app:disablectrlshiftdisplay" ConfigKey_AppFocusFollowsCursor = "app:focusfollowscursor" + ConfigKey_AppTabBar = "app:tabbar" ConfigKey_FeatureWaveAppBuilder = "feature:waveappbuilder" @@ -56,7 +57,9 @@ const ( ConfigKey_TermCursorBlink = "term:cursorblink" ConfigKey_TermBellSound = "term:bellsound" ConfigKey_TermBellIndicator = "term:bellindicator" + ConfigKey_TermOsc52 = "term:osc52" ConfigKey_TermDurable = "term:durable" + ConfigKey_TermCloseOnLastTermClose = "term:closeonlasttermclose" ConfigKey_EditorMinimapEnabled = "editor:minimapenabled" ConfigKey_EditorStickyScrollEnabled = "editor:stickyscrollenabled" @@ -79,6 +82,7 @@ const ( ConfigKey_MarkdownFixedFontSize = "markdown:fixedfontsize" ConfigKey_PreviewShowHiddenFiles = "preview:showhiddenfiles" + ConfigKey_PreviewDefaultSort = "preview:defaultsort" ConfigKey_TabPreset = "tab:preset" ConfigKey_TabConfirmClose = "tab:confirmclose" @@ -113,6 +117,7 @@ const ( ConfigKey_ConnClear = "conn:*" ConfigKey_ConnAskBeforeWshInstall = "conn:askbeforewshinstall" ConfigKey_ConnWshEnabled = "conn:wshenabled" + ConfigKey_ConnMoshEnabled = "conn:moshenabled" ConfigKey_ConnLocalHostnameDisplay = "conn:localhostdisplayname" ConfigKey_DebugClear = "debug:*" diff --git a/pkg/wconfig/settingsconfig.go b/pkg/wconfig/settingsconfig.go index a2626230f..60f6d50db 100644 --- a/pkg/wconfig/settingsconfig.go +++ b/pkg/wconfig/settingsconfig.go @@ -14,7 +14,9 @@ import ( "reflect" "sort" "strings" + "sync" + "github.com/wavetermdev/waveterm/pkg/util/fileutil" "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/wavebase" "github.com/wavetermdev/waveterm/pkg/waveobj" @@ -25,6 +27,8 @@ const SettingsFile = "settings.json" const ConnectionsFile = "connections.json" const ProfilesFile = "profiles.json" +var configWriteLock sync.Mutex + const AnySchema = ` { "type": "object", @@ -64,6 +68,7 @@ type SettingsType struct { AppDisableCtrlShiftArrows bool `json:"app:disablectrlshiftarrows,omitempty"` AppDisableCtrlShiftDisplay bool `json:"app:disablectrlshiftdisplay,omitempty"` AppFocusFollowsCursor string `json:"app:focusfollowscursor,omitempty" jsonschema:"enum=off,enum=on,enum=term"` + AppTabBar string `json:"app:tabbar,omitempty" jsonschema:"enum=top,enum=left"` FeatureWaveAppBuilder bool `json:"feature:waveappbuilder,omitempty"` @@ -103,7 +108,9 @@ type SettingsType struct { TermCursorBlink *bool `json:"term:cursorblink,omitempty"` TermBellSound *bool `json:"term:bellsound,omitempty"` TermBellIndicator *bool `json:"term:bellindicator,omitempty"` + TermOsc52 string `json:"term:osc52,omitempty" jsonschema:"enum=focus,enum=always"` TermDurable *bool `json:"term:durable,omitempty"` + TermCloseOnLastTermClose bool `json:"term:closeonlasttermclose,omitempty"` EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"` EditorStickyScrollEnabled bool `json:"editor:stickyscrollenabled,omitempty"` @@ -125,7 +132,8 @@ type SettingsType struct { MarkdownFontSize float64 `json:"markdown:fontsize,omitempty"` MarkdownFixedFontSize float64 `json:"markdown:fixedfontsize,omitempty"` - PreviewShowHiddenFiles *bool `json:"preview:showhiddenfiles,omitempty"` + PreviewShowHiddenFiles *bool `json:"preview:showhiddenfiles,omitempty"` + PreviewDefaultSort string `json:"preview:defaultsort,omitempty" jsonschema:"enum=name,enum=modtime"` TabPreset string `json:"tab:preset,omitempty"` TabConfirmClose bool `json:"tab:confirmclose,omitempty"` @@ -160,6 +168,7 @@ type SettingsType struct { ConnClear bool `json:"conn:*,omitempty"` ConnAskBeforeWshInstall *bool `json:"conn:askbeforewshinstall,omitempty"` ConnWshEnabled bool `json:"conn:wshenabled,omitempty"` + ConnMoshEnabled bool `json:"conn:moshenabled,omitempty"` ConnLocalHostnameDisplay *string `json:"conn:localhostdisplayname,omitempty"` DebugClear bool `json:"debug:*,omitempty"` @@ -284,6 +293,7 @@ type AIModeConfigType struct { ThinkingLevel string `json:"ai:thinkinglevel,omitempty" jsonschema:"enum=low,enum=medium,enum=high"` Verbosity string `json:"ai:verbosity,omitempty" jsonschema:"enum=low,enum=medium,enum=high,description=Text verbosity level (OpenAI Responses API only)"` Endpoint string `json:"ai:endpoint,omitempty"` + ProxyURL string `json:"ai:proxyurl,omitempty"` AzureAPIVersion string `json:"ai:azureapiversion,omitempty"` APIToken string `json:"ai:apitoken,omitempty"` APITokenSecretName string `json:"ai:apitokensecretname,omitempty"` @@ -316,6 +326,7 @@ type ConnKeywords struct { ConnWshEnabled *bool `json:"conn:wshenabled,omitempty"` ConnAskBeforeWshInstall *bool `json:"conn:askbeforewshinstall,omitempty"` ConnWshPath string `json:"conn:wshpath,omitempty"` + ConnMoshEnabled *bool `json:"conn:moshenabled,omitempty"` ConnShellPath string `json:"conn:shellpath,omitempty"` ConnIgnoreSshConfig *bool `json:"conn:ignoresshconfig,omitempty"` @@ -502,13 +513,16 @@ func ReadWaveHomeConfigFile(fileName string) (waveobj.MetaMapType, []ConfigError } func WriteWaveHomeConfigFile(fileName string, m waveobj.MetaMapType) error { + configWriteLock.Lock() + defer configWriteLock.Unlock() + configDirAbsPath := wavebase.GetWaveConfigDir() fullFileName := filepath.Join(configDirAbsPath, fileName) barr, err := jsonMarshalConfigInOrder(m) if err != nil { return err } - return os.WriteFile(fullFileName, barr, 0644) + return fileutil.AtomicWriteFile(fullFileName, barr, 0644) } // simple merge that overwrites diff --git a/pkg/wcore/badge.go b/pkg/wcore/badge.go new file mode 100644 index 000000000..a60ecb8fc --- /dev/null +++ b/pkg/wcore/badge.go @@ -0,0 +1,152 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package wcore + +import ( + "log" + "sync" + + "github.com/wavetermdev/waveterm/pkg/baseds" + "github.com/wavetermdev/waveterm/pkg/util/utilfn" + "github.com/wavetermdev/waveterm/pkg/waveobj" + "github.com/wavetermdev/waveterm/pkg/wps" + "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" +) + +// BadgeStore is an in-memory store for transient badges. +// Badges are not persisted and are cleared on restart. +// Values are stored by value (not pointer) to prevent external mutation. +type BadgeStore struct { + lock *sync.Mutex + transient map[string]baseds.Badge // keyed by oref string +} + +var globalBadgeStore = &BadgeStore{ + lock: &sync.Mutex{}, + transient: make(map[string]baseds.Badge), +} + +// InitBadgeStore subscribes to incoming badge events. +func InitBadgeStore() error { + log.Printf("initializing badge store\n") + + rpcClient := wshclient.GetBareRpcClient() + rpcClient.EventListener.On(wps.Event_Badge, handleBadgeEvent) + wshclient.EventSubCommand(rpcClient, wps.SubscriptionRequest{ + Event: wps.Event_Badge, + AllScopes: true, + }, nil) + + return nil +} + +func handleBadgeEvent(event *wps.WaveEvent) { + if event.Event != wps.Event_Badge { + return + } + var data baseds.BadgeEvent + err := utilfn.ReUnmarshal(&data, event.Data) + if err != nil { + log.Printf("badge store: error unmarshaling BadgeEvent: %v\n", err) + return + } + if data.ClearAll { + clearAllBadges() + return + } + if data.ORef == "" { + log.Printf("badge store: received badge event with empty oref\n") + return + } + oref, err := waveobj.ParseORef(data.ORef) + if err != nil { + log.Printf("badge store: error parsing oref %q: %v\n", data.ORef, err) + return + } + if oref.OType != waveobj.OType_Block && oref.OType != waveobj.OType_Tab { + log.Printf("badge store: can only handle block/tab orefs") + return + } + + setBadge(oref, data) +} + +// cmpBadge compares two badges by priority then by badgeid (both descending). +// Returns 1 if a > b, -1 if a < b, 0 if equal. +func cmpBadge(a, b baseds.Badge) int { + if a.Priority != b.Priority { + if a.Priority > b.Priority { + return 1 + } + return -1 + } + if a.BadgeId != b.BadgeId { + if a.BadgeId > b.BadgeId { + return 1 + } + return -1 + } + return 0 +} + +// setBadge updates the in-memory transient map. +func setBadge(oref waveobj.ORef, data baseds.BadgeEvent) { + globalBadgeStore.lock.Lock() + defer globalBadgeStore.lock.Unlock() + + orefStr := oref.String() + if orefStr == "" { + return + } + + if data.ClearById != "" { + existing, ok := globalBadgeStore.transient[orefStr] + if !ok || existing.BadgeId != data.ClearById { + return + } + delete(globalBadgeStore.transient, orefStr) + log.Printf("badge store: badge cleared by id: oref=%s id=%s\n", orefStr, data.ClearById) + return + } + if data.Clear { + delete(globalBadgeStore.transient, orefStr) + log.Printf("badge store: badge cleared: oref=%s\n", orefStr) + return + } + if data.Badge == nil { + return + } + incoming := *data.Badge + existing, hasExisting := globalBadgeStore.transient[orefStr] + if !hasExisting || cmpBadge(incoming, existing) > 0 { + globalBadgeStore.transient[orefStr] = incoming + log.Printf("badge store: badge set: oref=%s badge=%+v\n", orefStr, incoming) + } +} + +// clearAllBadges removes all badges from the transient store. +func clearAllBadges() { + globalBadgeStore.lock.Lock() + defer globalBadgeStore.lock.Unlock() + + count := len(globalBadgeStore.transient) + globalBadgeStore.transient = make(map[string]baseds.Badge) + log.Printf("badge store: cleared all %d badges\n", count) +} + +// GetAllBadges returns a snapshot of all currently active badges. +func GetAllBadges() []baseds.BadgeEvent { + globalBadgeStore.lock.Lock() + defer globalBadgeStore.lock.Unlock() + + result := make([]baseds.BadgeEvent, 0, len(globalBadgeStore.transient)) + for orefStr, badge := range globalBadgeStore.transient { + b := badge // copy + result = append(result, baseds.BadgeEvent{ + ORef: orefStr, + Badge: &b, + }) + } + return result +} diff --git a/pkg/wcore/block.go b/pkg/wcore/block.go index d9f484df8..38147a031 100644 --- a/pkg/wcore/block.go +++ b/pkg/wcore/block.go @@ -14,6 +14,7 @@ import ( "github.com/wavetermdev/waveterm/pkg/panichandler" "github.com/wavetermdev/waveterm/pkg/telemetry" "github.com/wavetermdev/waveterm/pkg/telemetry/telemetrydata" + "github.com/wavetermdev/waveterm/pkg/util/shellutil" "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/waveobj" "github.com/wavetermdev/waveterm/pkg/wps" @@ -170,6 +171,10 @@ func DeleteBlock(ctx context.Context, blockId string, recursive bool) error { if err != nil { return fmt.Errorf("error deleting block: %w", err) } + // Clean up per-block zsh history directory + if cleanupErr := shellutil.CleanupBlockZshHistory(blockId); cleanupErr != nil { + log.Printf("error cleaning up block zsh history for %s: %v\n", blockId, cleanupErr) + } log.Printf("DeleteBlock: parentBlockCount: %d", parentBlockCount) parentORef := waveobj.ParseORefNoErr(block.ParentORef) diff --git a/pkg/wcore/tabindicator.go b/pkg/wcore/tabindicator.go deleted file mode 100644 index ba737b045..000000000 --- a/pkg/wcore/tabindicator.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2025, Command Line Inc. -// SPDX-License-Identifier: Apache-2.0 - -package wcore - -import ( - "log" - "sync" - - "github.com/wavetermdev/waveterm/pkg/util/utilfn" - "github.com/wavetermdev/waveterm/pkg/wps" - "github.com/wavetermdev/waveterm/pkg/wshrpc" - "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" -) - -type TabIndicatorStore struct { - lock *sync.Mutex - indicators map[string]*wshrpc.TabIndicator -} - -var globalTabIndicatorStore = &TabIndicatorStore{ - lock: &sync.Mutex{}, - indicators: make(map[string]*wshrpc.TabIndicator), -} - -func InitTabIndicatorStore() { - log.Printf("initializing tab indicator store\n") - rpcClient := wshclient.GetBareRpcClient() - rpcClient.EventListener.On(wps.Event_TabIndicator, handleTabIndicatorEvent) - wshclient.EventSubCommand(rpcClient, wps.SubscriptionRequest{ - Event: wps.Event_TabIndicator, - AllScopes: true, - }, nil) -} - -func handleTabIndicatorEvent(event *wps.WaveEvent) { - if event.Event != wps.Event_TabIndicator { - return - } - var data wshrpc.TabIndicatorEventData - err := utilfn.ReUnmarshal(&data, event.Data) - if err != nil { - log.Printf("error unmarshaling TabIndicatorEventData: %v\n", err) - return - } - setTabIndicator(data.TabId, data.Indicator) -} - -func setTabIndicator(tabId string, indicator *wshrpc.TabIndicator) { - globalTabIndicatorStore.lock.Lock() - defer globalTabIndicatorStore.lock.Unlock() - if indicator == nil { - delete(globalTabIndicatorStore.indicators, tabId) - log.Printf("tab indicator cleared: tabId=%s\n", tabId) - return - } - currentIndicator := globalTabIndicatorStore.indicators[tabId] - if currentIndicator == nil { - globalTabIndicatorStore.indicators[tabId] = indicator - log.Printf("tab indicator set: tabId=%s indicator=%v\n", tabId, indicator) - return - } - if indicator.Priority >= currentIndicator.Priority { - if indicator.ClearOnFocus && !currentIndicator.ClearOnFocus { - indicator.PersistentIndicator = currentIndicator - } - globalTabIndicatorStore.indicators[tabId] = indicator - log.Printf("tab indicator updated: tabId=%s indicator=%v\n", tabId, indicator) - } else { - log.Printf("tab indicator not updated (lower priority): tabId=%s currentPriority=%v newPriority=%v\n", tabId, currentIndicator.Priority, indicator.Priority) - } -} - -func GetTabIndicator(tabId string) *wshrpc.TabIndicator { - globalTabIndicatorStore.lock.Lock() - defer globalTabIndicatorStore.lock.Unlock() - return globalTabIndicatorStore.indicators[tabId] -} - -func GetAllTabIndicators() map[string]*wshrpc.TabIndicator { - globalTabIndicatorStore.lock.Lock() - defer globalTabIndicatorStore.lock.Unlock() - result := make(map[string]*wshrpc.TabIndicator) - for tabId, indicator := range globalTabIndicatorStore.indicators { - result[tabId] = indicator - } - return result -} diff --git a/pkg/wps/wpstypes.go b/pkg/wps/wpstypes.go index 352f05e2d..0077ec9d5 100644 --- a/pkg/wps/wpstypes.go +++ b/pkg/wps/wpstypes.go @@ -32,8 +32,8 @@ const ( Event_WaveAppAppGoUpdated = "waveapp:appgoupdated" // type: none Event_TsunamiUpdateMeta = "tsunami:updatemeta" // type: wshrpc.AppMeta Event_AIModeConfig = "waveai:modeconfig" // type: wconfig.AIModeConfigUpdate - Event_TabIndicator = "tab:indicator" // type: wshrpc.TabIndicatorEventData Event_BlockJobStatus = "block:jobstatus" // type: wshrpc.BlockJobStatusData + Event_Badge = "badge" // type: baseds.BadgeEvent ) var AllEvents []string = []string{ @@ -54,8 +54,8 @@ var AllEvents []string = []string{ Event_WaveAppAppGoUpdated, Event_TsunamiUpdateMeta, Event_AIModeConfig, - Event_TabIndicator, Event_BlockJobStatus, + Event_Badge, } type WaveEvent struct { diff --git a/pkg/wshrpc/wshclient/wshclient.go b/pkg/wshrpc/wshclient/wshclient.go index 68ac9a160..103089144 100644 --- a/pkg/wshrpc/wshclient/wshclient.go +++ b/pkg/wshrpc/wshclient/wshclient.go @@ -6,14 +6,15 @@ package wshclient import ( + "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" + "github.com/wavetermdev/waveterm/pkg/baseds" "github.com/wavetermdev/waveterm/pkg/telemetry/telemetrydata" - "github.com/wavetermdev/waveterm/pkg/wshutil" - "github.com/wavetermdev/waveterm/pkg/wshrpc" - "github.com/wavetermdev/waveterm/pkg/wconfig" + "github.com/wavetermdev/waveterm/pkg/vdom" "github.com/wavetermdev/waveterm/pkg/waveobj" + "github.com/wavetermdev/waveterm/pkg/wconfig" "github.com/wavetermdev/waveterm/pkg/wps" - "github.com/wavetermdev/waveterm/pkg/vdom" - "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" + "github.com/wavetermdev/waveterm/pkg/wshrpc" + "github.com/wavetermdev/waveterm/pkg/wshutil" ) // command "activity", wshserver.ActivityCommand @@ -64,6 +65,12 @@ func AuthenticateTokenVerifyCommand(w *wshutil.WshRpc, data wshrpc.CommandAuthen return resp, err } +// command "badgewatchpid", wshserver.BadgeWatchPidCommand +func BadgeWatchPidCommand(w *wshutil.WshRpc, data wshrpc.CommandBadgeWatchPidData, opts *wshrpc.RpcOpts) error { + _, err := sendRpcRequestCallHelper[any](w, "badgewatchpid", data, opts) + return err +} + // command "blockinfo", wshserver.BlockInfoCommand func BlockInfoCommand(w *wshutil.WshRpc, data string, opts *wshrpc.RpcOpts) (*wshrpc.BlockInfoData, error) { resp, err := sendRpcRequestCallHelper[*wshrpc.BlockInfoData](w, "blockinfo", data, opts) @@ -184,6 +191,12 @@ func CreateSubBlockCommand(w *wshutil.WshRpc, data wshrpc.CommandCreateSubBlockD return resp, err } +// command "debugterm", wshserver.DebugTermCommand +func DebugTermCommand(w *wshutil.WshRpc, data wshrpc.CommandDebugTermData, opts *wshrpc.RpcOpts) (*wshrpc.CommandDebugTermRtnData, error) { + resp, err := sendRpcRequestCallHelper[*wshrpc.CommandDebugTermRtnData](w, "debugterm", data, opts) + return resp, err +} + // command "deleteappfile", wshserver.DeleteAppFileCommand func DeleteAppFileCommand(w *wshutil.WshRpc, data wshrpc.CommandDeleteAppFileData, opts *wshrpc.RpcOpts) error { _, err := sendRpcRequestCallHelper[any](w, "deleteappfile", data, opts) @@ -380,9 +393,9 @@ func FocusWindowCommand(w *wshutil.WshRpc, data string, opts *wshrpc.RpcOpts) er return err } -// command "getalltabindicators", wshserver.GetAllTabIndicatorsCommand -func GetAllTabIndicatorsCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) (map[string]*wshrpc.TabIndicator, error) { - resp, err := sendRpcRequestCallHelper[map[string]*wshrpc.TabIndicator](w, "getalltabindicators", nil, opts) +// command "getallbadges", wshserver.GetAllBadgesCommand +func GetAllBadgesCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) ([]baseds.BadgeEvent, error) { + resp, err := sendRpcRequestCallHelper[[]baseds.BadgeEvent](w, "getallbadges", nil, opts) return resp, err } @@ -602,6 +615,12 @@ func ListAllEditableAppsCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) ([]wshr return resp, err } +// command "macosversion", wshserver.MacOSVersionCommand +func MacOSVersionCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) (string, error) { + resp, err := sendRpcRequestCallHelper[string](w, "macosversion", nil, opts) + return resp, err +} + // command "makedraftfromlocal", wshserver.MakeDraftFromLocalCommand func MakeDraftFromLocalCommand(w *wshutil.WshRpc, data wshrpc.CommandMakeDraftFromLocalData, opts *wshrpc.RpcOpts) (*wshrpc.CommandMakeDraftFromLocalRtnData, error) { resp, err := sendRpcRequestCallHelper[*wshrpc.CommandMakeDraftFromLocalRtnData](w, "makedraftfromlocal", data, opts) @@ -902,6 +921,24 @@ func TestCommand(w *wshutil.WshRpc, data string, opts *wshrpc.RpcOpts) error { return err } +// command "testmultiarg", wshserver.TestMultiArgCommand +func TestMultiArgCommand(w *wshutil.WshRpc, arg1 string, arg2 int, arg3 bool, opts *wshrpc.RpcOpts) (string, error) { + resp, err := sendRpcRequestCallHelper[string](w, "testmultiarg", wshrpc.MultiArg{Args: []any{arg1, arg2, arg3}}, opts) + return resp, err +} + +// command "updatetabname", wshserver.UpdateTabNameCommand +func UpdateTabNameCommand(w *wshutil.WshRpc, arg1 string, arg2 string, opts *wshrpc.RpcOpts) error { + _, err := sendRpcRequestCallHelper[any](w, "updatetabname", wshrpc.MultiArg{Args: []any{arg1, arg2}}, opts) + return err +} + +// command "updateworkspacetabids", wshserver.UpdateWorkspaceTabIdsCommand +func UpdateWorkspaceTabIdsCommand(w *wshutil.WshRpc, arg1 string, arg2 []string, opts *wshrpc.RpcOpts) error { + _, err := sendRpcRequestCallHelper[any](w, "updateworkspacetabids", wshrpc.MultiArg{Args: []any{arg1, arg2}}, opts) + return err +} + // command "vdomasyncinitiation", wshserver.VDomAsyncInitiationCommand func VDomAsyncInitiationCommand(w *wshutil.WshRpc, data vdom.VDomAsyncInitiationRequest, opts *wshrpc.RpcOpts) error { _, err := sendRpcRequestCallHelper[any](w, "vdomasyncinitiation", data, opts) diff --git a/pkg/wshrpc/wshremote/wshremote.go b/pkg/wshrpc/wshremote/wshremote.go index 530c83626..35dc92d5b 100644 --- a/pkg/wshrpc/wshremote/wshremote.go +++ b/pkg/wshrpc/wshremote/wshremote.go @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 package wshremote @@ -12,10 +12,16 @@ import ( "os" "path/filepath" "sync" + "time" + "github.com/wavetermdev/waveterm/pkg/baseds" + "github.com/wavetermdev/waveterm/pkg/panichandler" "github.com/wavetermdev/waveterm/pkg/suggestion" + "github.com/wavetermdev/waveterm/pkg/util/unixutil" "github.com/wavetermdev/waveterm/pkg/wavebase" + "github.com/wavetermdev/waveterm/pkg/wps" "github.com/wavetermdev/waveterm/pkg/wshrpc" + "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" "github.com/wavetermdev/waveterm/pkg/wshutil" ) @@ -131,3 +137,39 @@ func (impl *ServerImpl) getWshPath() (string, error) { } return wshPath, nil } + +func (impl *ServerImpl) BadgeWatchPidCommand(ctx context.Context, data wshrpc.CommandBadgeWatchPidData) error { + if data.Pid <= 0 { + return fmt.Errorf("invalid pid: %d", data.Pid) + } + if data.ORef.IsEmpty() { + return fmt.Errorf("oref is required") + } + if data.BadgeId == "" { + return fmt.Errorf("badgeid is required") + } + go func() { + defer func() { + panichandler.PanicHandler("BadgeWatchPidCommand", recover()) + }() + for { + time.Sleep(time.Second) + if unixutil.IsPidRunning(data.Pid) { + continue + } + orefStr := data.ORef.String() + event := wps.WaveEvent{ + Event: wps.Event_Badge, + Scopes: []string{orefStr}, + Data: baseds.BadgeEvent{ + ORef: orefStr, + ClearById: data.BadgeId, + }, + } + wshclient.EventPublishCommand(impl.RpcClient, event, nil) + log.Printf("BadgeWatchPidCommand: pid %d gone, cleared badge %s for oref %s\n", data.Pid, data.BadgeId, orefStr) + return + } + }() + return nil +} diff --git a/pkg/wshrpc/wshremote/wshremote_file.go b/pkg/wshrpc/wshremote/wshremote_file.go index 015e976b3..9b6c411f2 100644 --- a/pkg/wshrpc/wshremote/wshremote_file.go +++ b/pkg/wshrpc/wshremote/wshremote_file.go @@ -13,6 +13,7 @@ import ( "log" "os" "path/filepath" + "sort" "strings" "time" @@ -57,6 +58,17 @@ func (impl *ServerImpl) remoteStreamFileDir(ctx context.Context, path string, by if err != nil { return fmt.Errorf("cannot open dir %q: %w", path, err) } + sort.Slice(innerFilesEntries, func(i, j int) bool { + iInfo, iErr := innerFilesEntries[i].Info() + jInfo, jErr := innerFilesEntries[j].Info() + if iErr != nil { + return false + } + if jErr != nil { + return true + } + return iInfo.ModTime().After(jInfo.ModTime()) + }) if byteRange.All { if len(innerFilesEntries) > wshrpc.MaxDirSize { innerFilesEntries = innerFilesEntries[:wshrpc.MaxDirSize] diff --git a/pkg/wshrpc/wshrpcmeta.go b/pkg/wshrpc/wshrpcmeta.go index 848de3453..f3d6e3f4e 100644 --- a/pkg/wshrpc/wshrpcmeta.go +++ b/pkg/wshrpc/wshrpcmeta.go @@ -15,10 +15,14 @@ type WshRpcMethodDecl struct { Command string CommandType string MethodName string - CommandDataType reflect.Type + CommandDataTypes []reflect.Type DefaultResponseDataType reflect.Type } +func (decl *WshRpcMethodDecl) GetCommandDataTypes() []reflect.Type { + return decl.CommandDataTypes +} + var contextRType = reflect.TypeOf((*context.Context)(nil)).Elem() var wshRpcInterfaceRType = reflect.TypeOf((*WshRpcInterface)(nil)).Elem() @@ -75,11 +79,11 @@ func generateWshCommandDecl(method reflect.Method) *WshRpcMethodDecl { decl.Command = strings.ToLower(cmdStr) decl.CommandType = getWshCommandType(method) decl.MethodName = method.Name - var cdataType reflect.Type - if method.Type.NumIn() > 1 { - cdataType = method.Type.In(1) + var cdataTypes []reflect.Type + for idx := 1; idx < method.Type.NumIn(); idx++ { + cdataTypes = append(cdataTypes, method.Type.In(idx)) } - decl.CommandDataType = cdataType + decl.CommandDataTypes = cdataTypes decl.DefaultResponseDataType = getWshMethodResponseType(decl.CommandType, method) return decl } diff --git a/pkg/wshrpc/wshrpcmeta_test.go b/pkg/wshrpc/wshrpcmeta_test.go new file mode 100644 index 000000000..4479c52b1 --- /dev/null +++ b/pkg/wshrpc/wshrpcmeta_test.go @@ -0,0 +1,50 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package wshrpc + +import ( + "context" + "reflect" + "testing" +) + +type testRpcInterfaceForDecls interface { + NoArgCommand(ctx context.Context) error + OneArgCommand(ctx context.Context, data string) error + TwoArgCommand(ctx context.Context, arg1 string, arg2 int) error +} + +func TestGenerateWshCommandDecl_MultiArgs(t *testing.T) { + rtype := reflect.TypeOf((*testRpcInterfaceForDecls)(nil)).Elem() + method, ok := rtype.MethodByName("TwoArgCommand") + if !ok { + t.Fatalf("TwoArgCommand method not found") + } + decl := generateWshCommandDecl(method) + if decl.Command != "twoarg" { + t.Fatalf("expected command twoarg, got %q", decl.Command) + } + if len(decl.CommandDataTypes) != 2 { + t.Fatalf("expected 2 command data types, got %d", len(decl.CommandDataTypes)) + } + if decl.CommandDataTypes[0].Kind() != reflect.String || decl.CommandDataTypes[1].Kind() != reflect.Int { + t.Fatalf("unexpected command data types: %#v", decl.CommandDataTypes) + } + if len(decl.GetCommandDataTypes()) != 2 { + t.Fatalf("expected helper to return two command data types") + } +} + +func TestGenerateWshCommandDeclMap_TestMultiArgCommand(t *testing.T) { + decl := GenerateWshCommandDeclMap()["testmultiarg"] + if decl == nil { + t.Fatalf("expected testmultiarg command declaration") + } + if decl.MethodName != "TestMultiArgCommand" { + t.Fatalf("expected TestMultiArgCommand method name, got %q", decl.MethodName) + } + if len(decl.GetCommandDataTypes()) != 3 { + t.Fatalf("expected 3 command args, got %d", len(decl.GetCommandDataTypes())) + } +} diff --git a/pkg/wshrpc/wshrpctypes.go b/pkg/wshrpc/wshrpctypes.go index eefd7fabd..0a50f8d1e 100644 --- a/pkg/wshrpc/wshrpctypes.go +++ b/pkg/wshrpc/wshrpctypes.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" + "github.com/wavetermdev/waveterm/pkg/baseds" "github.com/wavetermdev/waveterm/pkg/telemetry/telemetrydata" "github.com/wavetermdev/waveterm/pkg/vdom" "github.com/wavetermdev/waveterm/pkg/waveobj" @@ -23,10 +24,14 @@ type RespOrErrorUnion[T any] struct { Error error } +type MultiArg struct { + Args []any `json:"args"` +} + // Instructions for adding a new RPC call // * methods must end with Command // * methods must take context as their first parameter -// * methods may take up to one parameter, and may return either just an error, or one return value plus an error +// * methods may take additional typed parameters, and may return either just an error, or one return value plus an error // * after modifying WshRpcInterface, run `task generate` to regnerate bindings type WshRpcInterface interface { @@ -69,13 +74,16 @@ type WshRpcInterface interface { StreamWaveAiCommand(ctx context.Context, request WaveAIStreamRequest) chan RespOrErrorUnion[WaveAIPacketType] StreamCpuDataCommand(ctx context.Context, request CpuDataRequest) chan RespOrErrorUnion[TimeSeriesData] TestCommand(ctx context.Context, data string) error + TestMultiArgCommand(ctx context.Context, arg1 string, arg2 int, arg3 bool) (string, error) SetConfigCommand(ctx context.Context, data MetaSettingsType) error SetConnectionsConfigCommand(ctx context.Context, data ConnConfigRequest) error GetFullConfigCommand(ctx context.Context) (wconfig.FullConfigType, error) GetWaveAIModeConfigCommand(ctx context.Context) (wconfig.AIModeConfigUpdate, error) BlockInfoCommand(ctx context.Context, blockId string) (*BlockInfoData, error) + DebugTermCommand(ctx context.Context, data CommandDebugTermData) (*CommandDebugTermRtnData, error) BlocksListCommand(ctx context.Context, data BlocksListRequest) ([]BlocksListEntry, error) WaveInfoCommand(ctx context.Context) (*WaveInfoData, error) + MacOSVersionCommand(ctx context.Context) (string, error) WshActivityCommand(ct context.Context, data map[string]int) error ActivityCommand(ctx context.Context, data ActivityUpdate) error RecordTEventCommand(ctx context.Context, data telemetrydata.TEvent) error @@ -87,7 +95,9 @@ type WshRpcInterface interface { FetchSuggestionsCommand(ctx context.Context, data FetchSuggestionsData) (*FetchSuggestionsResponse, error) DisposeSuggestionsCommand(ctx context.Context, widgetId string) error GetTabCommand(ctx context.Context, tabId string) (*waveobj.Tab, error) - GetAllTabIndicatorsCommand(ctx context.Context) (map[string]*TabIndicator, error) + UpdateTabNameCommand(ctx context.Context, tabId string, newName string) error + UpdateWorkspaceTabIdsCommand(ctx context.Context, workspaceId string, tabIds []string) error + GetAllBadgesCommand(ctx context.Context) ([]baseds.BadgeEvent, error) // connection functions ConnStatusCommand(ctx context.Context) ([]ConnStatus, error) @@ -117,6 +127,7 @@ type WshRpcInterface interface { RemoteReconnectToJobManagerCommand(ctx context.Context, data CommandRemoteReconnectToJobManagerData) (*CommandRemoteReconnectToJobManagerRtnData, error) RemoteDisconnectFromJobManagerCommand(ctx context.Context, data CommandRemoteDisconnectFromJobManagerData) error RemoteTerminateJobManagerCommand(ctx context.Context, data CommandRemoteTerminateJobManagerData) error + BadgeWatchPidCommand(ctx context.Context, data CommandBadgeWatchPidData) error // emain WebSelectorCommand(ctx context.Context, data CommandWebSelectorData) ([]string, error) @@ -446,6 +457,8 @@ type ConnStatus struct { Status string `json:"status"` ConnHealthStatus string `json:"connhealthstatus,omitempty"` WshEnabled bool `json:"wshenabled"` + MoshEnabled bool `json:"moshenabled"` + MoshActive bool `json:"moshactive"` Connection string `json:"connection"` Connected bool `json:"connected"` HasConnected bool `json:"hasconnected"` // true if it has *ever* connected successfully @@ -579,6 +592,16 @@ type CommandVarResponseData struct { Exists bool `json:"exists"` } +type CommandDebugTermData struct { + BlockId string `json:"blockid"` + Size int64 `json:"size"` +} + +type CommandDebugTermRtnData struct { + Offset int64 `json:"offset"` + Data64 string `json:"data64"` +} + type PathCommandData struct { PathType string `json:"pathtype"` Open bool `json:"open"` @@ -858,17 +881,10 @@ type WaveFileInfo struct { Meta FileMeta `json:"meta"` } -type TabIndicator struct { - Icon string `json:"icon"` - Color string `json:"color,omitempty"` - Priority float64 `json:"priority"` - ClearOnFocus bool `json:"clearonfocus,omitempty"` - PersistentIndicator *TabIndicator `json:"persistentindicator,omitempty"` -} - -type TabIndicatorEventData struct { - TabId string `json:"tabid"` - Indicator *TabIndicator `json:"indicator"` +type CommandBadgeWatchPidData struct { + Pid int `json:"pid"` + ORef waveobj.ORef `json:"oref"` + BadgeId string `json:"badgeid"` } type BlockJobStatusData struct { @@ -884,13 +900,13 @@ type BlockJobStatusData struct { } type FocusedBlockData struct { - BlockId string `json:"blockid"` - ViewType string `json:"viewtype"` - Controller string `json:"controller"` - ConnName string `json:"connname"` - BlockMeta waveobj.MetaMapType `json:"blockmeta"` - TermJobStatus *BlockJobStatusData `json:"termjobstatus,omitempty"` - ConnStatus *ConnStatus `json:"connstatus,omitempty"` - TermShellIntegrationStatus string `json:"termshellintegrationstatus,omitempty"` - TermLastCommand string `json:"termlastcommand,omitempty"` + BlockId string `json:"blockid"` + ViewType string `json:"viewtype"` + Controller string `json:"controller"` + ConnName string `json:"connname"` + BlockMeta waveobj.MetaMapType `json:"blockmeta"` + TermJobStatus *BlockJobStatusData `json:"termjobstatus,omitempty"` + ConnStatus *ConnStatus `json:"connstatus,omitempty"` + TermShellIntegrationStatus string `json:"termshellintegrationstatus,omitempty"` + TermLastCommand string `json:"termlastcommand,omitempty"` } diff --git a/pkg/wshrpc/wshrpctypes_const.go b/pkg/wshrpc/wshrpctypes_const.go index 51a25f147..5e8901641 100644 --- a/pkg/wshrpc/wshrpctypes_const.go +++ b/pkg/wshrpc/wshrpctypes_const.go @@ -8,7 +8,7 @@ const ( // MaxFileSize is the maximum file size that can be read MaxFileSize = 50 * 1024 * 1024 // 50M // MaxDirSize is the maximum number of entries that can be read in a directory - MaxDirSize = 1024 + MaxDirSize = 5000 // FileChunkSize is the size of the file chunk to read FileChunkSize = 64 * 1024 // DirChunkSize is the size of the directory chunk to read diff --git a/pkg/wshrpc/wshserver/wshserver.go b/pkg/wshrpc/wshserver/wshserver.go index ff6a0eae8..b9d320f69 100644 --- a/pkg/wshrpc/wshserver/wshserver.go +++ b/pkg/wshrpc/wshserver/wshserver.go @@ -22,6 +22,7 @@ import ( "github.com/skratchdot/open-golang/open" "github.com/wavetermdev/waveterm/pkg/aiusechat" + "github.com/wavetermdev/waveterm/pkg/baseds" "github.com/wavetermdev/waveterm/pkg/aiusechat/chatstore" "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" "github.com/wavetermdev/waveterm/pkg/blockcontroller" @@ -81,6 +82,16 @@ func (ws *WshServer) TestCommand(ctx context.Context, data string) error { return nil } +func (ws *WshServer) TestMultiArgCommand(ctx context.Context, arg1 string, arg2 int, arg3 bool) (string, error) { + defer func() { + panichandler.PanicHandler("TestMultiArgCommand", recover()) + }() + rpcSource := wshutil.GetRpcSourceFromContext(ctx) + rtn := fmt.Sprintf("src:%s arg1:%q arg2:%d arg3:%t", rpcSource, arg1, arg2, arg3) + log.Printf("TESTMULTI %s\n", rtn) + return rtn, nil +} + // for testing func (ws *WshServer) MessageCommand(ctx context.Context, data wshrpc.CommandMessageData) error { log.Printf("MESSAGE: %s\n", data.Message) @@ -149,6 +160,26 @@ func (ws *WshServer) GetMetaCommand(ctx context.Context, data wshrpc.CommandGetM return waveobj.GetMeta(obj), nil } +func (ws *WshServer) UpdateTabNameCommand(ctx context.Context, tabId string, newName string) error { + oref := waveobj.ORef{OType: waveobj.OType_Tab, OID: tabId} + err := wstore.UpdateTabName(ctx, tabId, newName) + if err != nil { + return fmt.Errorf("error updating tab name: %w", err) + } + wcore.SendWaveObjUpdate(oref) + return nil +} + +func (ws *WshServer) UpdateWorkspaceTabIdsCommand(ctx context.Context, workspaceId string, tabIds []string) error { + oref := waveobj.ORef{OType: waveobj.OType_Workspace, OID: workspaceId} + err := wcore.UpdateWorkspaceTabIds(ctx, workspaceId, tabIds) + if err != nil { + return fmt.Errorf("error updating workspace tab ids: %w", err) + } + wcore.SendWaveObjUpdate(oref) + return nil +} + func (ws *WshServer) SetMetaCommand(ctx context.Context, data wshrpc.CommandSetMetaData) error { log.Printf("SetMetaCommand: %s | %v\n", data.ORef, data.Meta) oref := data.ORef @@ -807,6 +838,36 @@ func (ws *WshServer) BlockInfoCommand(ctx context.Context, blockId string) (*wsh }, nil } +func (ws *WshServer) DebugTermCommand(ctx context.Context, data wshrpc.CommandDebugTermData) (*wshrpc.CommandDebugTermRtnData, error) { + if data.BlockId == "" { + return nil, fmt.Errorf("blockid is required") + } + if data.Size <= 0 { + return nil, fmt.Errorf("size must be greater than 0") + } + waveFile, err := filestore.WFS.Stat(ctx, data.BlockId, wavebase.BlockFile_Term) + if err == fs.ErrNotExist { + return &wshrpc.CommandDebugTermRtnData{}, nil + } + if err != nil { + return nil, fmt.Errorf("error statting term file: %w", err) + } + readSize := data.Size + dataLength := waveFile.DataLength() + if readSize > dataLength { + readSize = dataLength + } + readOffset := waveFile.Size - readSize + readOffset, readData, err := filestore.WFS.ReadAt(ctx, data.BlockId, wavebase.BlockFile_Term, readOffset, readSize) + if err != nil { + return nil, fmt.Errorf("error reading term file: %w", err) + } + return &wshrpc.CommandDebugTermRtnData{ + Offset: readOffset, + Data64: base64.StdEncoding.EncodeToString(readData), + }, nil +} + func (ws *WshServer) WaveInfoCommand(ctx context.Context) (*wshrpc.WaveInfoData, error) { return &wshrpc.WaveInfoData{ Version: wavebase.WaveVersion, @@ -817,6 +878,10 @@ func (ws *WshServer) WaveInfoCommand(ctx context.Context) (*wshrpc.WaveInfoData, }, nil } +func (ws *WshServer) MacOSVersionCommand(ctx context.Context) (string, error) { + return wavebase.ClientMacOSVersion(), nil +} + // BlocksListCommand returns every block visible in the requested // scope (current workspace by default). func (ws *WshServer) BlocksListCommand( @@ -1407,8 +1472,8 @@ func (ws *WshServer) GetTabCommand(ctx context.Context, tabId string) (*waveobj. return tab, nil } -func (ws *WshServer) GetAllTabIndicatorsCommand(ctx context.Context) (map[string]*wshrpc.TabIndicator, error) { - return wcore.GetAllTabIndicators(), nil +func (ws *WshServer) GetAllBadgesCommand(ctx context.Context) ([]baseds.BadgeEvent, error) { + return wcore.GetAllBadges(), nil } func (ws *WshServer) GetSecretsCommand(ctx context.Context, names []string) (map[string]string, error) { diff --git a/pkg/wshutil/wshadapter.go b/pkg/wshutil/wshadapter.go index a91bb4568..db7f7c20b 100644 --- a/pkg/wshutil/wshadapter.go +++ b/pkg/wshutil/wshadapter.go @@ -14,6 +14,7 @@ import ( ) var WshCommandDeclMap = wshrpc.GenerateWshCommandDeclMap() +var multiArgRType = reflect.TypeOf(wshrpc.MultiArg{}) func findCmdMethod(impl any, cmd string) *reflect.Method { rtype := reflect.TypeOf(impl) @@ -53,19 +54,15 @@ func noImplHandler(handler *RpcResponseHandler) bool { return true } -func recodeCommandData(command string, data any) (any, error) { - // only applies to initial command packet - if command == "" { +func recodeCommandData(command string, data any, commandDataType reflect.Type) (any, error) { + if command == "" || commandDataType == nil { return data, nil } methodDecl := WshCommandDeclMap[command] if methodDecl == nil { return data, fmt.Errorf("command %q not found", command) } - if methodDecl.CommandDataType == nil { - return data, nil - } - commandDataPtr := reflect.New(methodDecl.CommandDataType).Interface() + commandDataPtr := reflect.New(commandDataType).Interface() if data != nil { err := utilfn.ReUnmarshal(commandDataPtr, data) if err != nil { @@ -103,13 +100,37 @@ func serverImplAdapter(impl any) func(*RpcResponseHandler) bool { implMethod := reflect.ValueOf(impl).MethodByName(rmethod.Name) var callParams []reflect.Value callParams = append(callParams, reflect.ValueOf(handler.Context())) - if methodDecl.CommandDataType != nil { - cmdData, err := recodeCommandData(cmd, handler.GetCommandRawData()) + commandDataTypes := methodDecl.GetCommandDataTypes() + if len(commandDataTypes) == 1 { + cmdData, err := recodeCommandData(cmd, handler.GetCommandRawData(), commandDataTypes[0]) if err != nil { handler.SendResponseError(err) return true } callParams = append(callParams, reflect.ValueOf(cmdData)) + } else if len(commandDataTypes) > 1 { + multiArgAny, err := recodeCommandData(cmd, handler.GetCommandRawData(), multiArgRType) + if err != nil { + handler.SendResponseError(err) + return true + } + multiArg, ok := multiArgAny.(wshrpc.MultiArg) + if !ok { + handler.SendResponseError(fmt.Errorf("command %q invalid multi arg payload", cmd)) + return true + } + if len(multiArg.Args) != len(commandDataTypes) { + handler.SendResponseError(fmt.Errorf("command %q expected %d args, got %d", cmd, len(commandDataTypes), len(multiArg.Args))) + return true + } + for idx, commandDataType := range commandDataTypes { + cmdData, err := recodeCommandData(cmd, multiArg.Args[idx], commandDataType) + if err != nil { + handler.SendResponseError(err) + return true + } + callParams = append(callParams, reflect.ValueOf(cmdData)) + } } if methodDecl.CommandType == wshrpc.RpcType_Call { rtnVals := implMethod.Call(callParams) diff --git a/pkg/wstore/wstore.go b/pkg/wstore/wstore.go index 03ed297bb..76d271a71 100644 --- a/pkg/wstore/wstore.go +++ b/pkg/wstore/wstore.go @@ -8,7 +8,6 @@ import ( "fmt" "sync" - "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/wavebase" "github.com/wavetermdev/waveterm/pkg/waveobj" ) @@ -74,31 +73,3 @@ func UpdateObjectMeta(ctx context.Context, oref waveobj.ORef, meta waveobj.MetaM return nil }) } - -func MoveBlockToTab(ctx context.Context, currentTabId string, newTabId string, blockId string) error { - return WithTx(ctx, func(tx *TxWrap) error { - block, _ := DBGet[*waveobj.Block](tx.Context(), blockId) - if block == nil { - return fmt.Errorf("block not found: %q", blockId) - } - currentTab, _ := DBGet[*waveobj.Tab](tx.Context(), currentTabId) - if currentTab == nil { - return fmt.Errorf("current tab not found: %q", currentTabId) - } - newTab, _ := DBGet[*waveobj.Tab](tx.Context(), newTabId) - if newTab == nil { - return fmt.Errorf("new tab not found: %q", newTabId) - } - blockIdx := utilfn.FindStringInSlice(currentTab.BlockIds, blockId) - if blockIdx == -1 { - return fmt.Errorf("block not found in current tab: %q", blockId) - } - currentTab.BlockIds = utilfn.RemoveElemFromSlice(currentTab.BlockIds, blockId) - newTab.BlockIds = append(newTab.BlockIds, blockId) - block.ParentORef = waveobj.MakeORef(waveobj.OType_Tab, newTabId).String() - DBUpdate(tx.Context(), block) - DBUpdate(tx.Context(), currentTab) - DBUpdate(tx.Context(), newTab) - return nil - }) -} diff --git a/pkg/wstore/wstore_rtinfo.go b/pkg/wstore/wstore_rtinfo.go index 912a3ccac..e3d6ef9f8 100644 --- a/pkg/wstore/wstore_rtinfo.go +++ b/pkg/wstore/wstore_rtinfo.go @@ -22,6 +22,13 @@ func setFieldValue(fieldValue reflect.Value, value any) { return } + if fieldValue.Kind() == reflect.Pointer { + ptrValue := reflect.New(fieldValue.Type().Elem()) + setFieldValue(ptrValue.Elem(), value) + fieldValue.Set(ptrValue) + return + } + if valueStr, ok := value.(string); ok && fieldValue.Kind() == reflect.String { fieldValue.SetString(valueStr) return diff --git a/schema/settings.json b/schema/settings.json index ad4cd8315..0f703e2f4 100644 --- a/schema/settings.json +++ b/schema/settings.json @@ -43,6 +43,13 @@ "term" ] }, + "app:tabbar": { + "type": "string", + "enum": [ + "top", + "left" + ] + }, "feature:waveappbuilder": { "type": "boolean" }, @@ -151,9 +158,19 @@ "term:bellindicator": { "type": "boolean" }, + "term:osc52": { + "type": "string", + "enum": [ + "focus", + "always" + ] + }, "term:durable": { "type": "boolean" }, + "term:closeonlasttermclose": { + "type": "boolean" + }, "editor:minimapenabled": { "type": "boolean" }, @@ -205,6 +222,13 @@ "preview:showhiddenfiles": { "type": "boolean" }, + "preview:defaultsort": { + "type": "string", + "enum": [ + "name", + "modtime" + ] + }, "tab:preset": { "type": "string" }, diff --git a/schema/waveai.json b/schema/waveai.json index d917cdcda..7279777a4 100644 --- a/schema/waveai.json +++ b/schema/waveai.json @@ -20,6 +20,7 @@ "enum": [ "wave", "google", + "groq", "openrouter", "nanogpt", "openai", @@ -59,6 +60,9 @@ "ai:endpoint": { "type": "string" }, + "ai:proxyurl": { + "type": "string" + }, "ai:azureapiversion": { "type": "string" }, diff --git a/tsconfig.json b/tsconfig.json index cb02488e6..3ef02e067 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,7 +22,8 @@ "@/store/*": ["frontend/app/store/*"], "@/view/*": ["frontend/app/view/*"], "@/element/*": ["frontend/app/element/*"], - "@/shadcn/*": ["frontend/app/shadcn/*"] + "@/shadcn/*": ["frontend/app/shadcn/*"], + "@/preview/*": ["frontend/preview/*"] }, "lib": ["dom", "dom.iterable", "es6"], "allowJs": true, diff --git a/tsunami/app/defaultclient.go b/tsunami/app/defaultclient.go index e033bfd2a..1359f0f58 100644 --- a/tsunami/app/defaultclient.go +++ b/tsunami/app/defaultclient.go @@ -64,6 +64,13 @@ func SendAsyncInitiation() error { return engine.GetDefaultClient().SendAsyncInitiation() } +func TermWrite(ref *vdom.VDomRef, data string) error { + if ref == nil || !ref.HasCurrent.Load() { + return nil + } + return engine.GetDefaultClient().SendTermWrite(ref.RefId, data) +} + func ConfigAtom[T any](name string, defaultValue T, meta *AtomMeta) Atom[T] { fullName := "$config." + name client := engine.GetDefaultClient() @@ -155,7 +162,7 @@ func DeepCopy[T any](v T) T { // If the ref is nil or not current, the operation is ignored. // This function must be called within a component context. func QueueRefOp(ref *vdom.VDomRef, op vdom.VDomRefOperation) { - if ref == nil || !ref.HasCurrent { + if ref == nil || !ref.HasCurrent.Load() { return } if op.RefId == "" { diff --git a/tsunami/app/hooks.go b/tsunami/app/hooks.go index 6b6ebbd36..54418a00e 100644 --- a/tsunami/app/hooks.go +++ b/tsunami/app/hooks.go @@ -31,6 +31,38 @@ func UseVDomRef() *vdom.VDomRef { return refVal } +// TermRef wraps a VDomRef and implements io.Writer by forwarding writes to the terminal. +type TermRef struct { + *vdom.VDomRef +} + +// Write implements io.Writer by sending data to the terminal via TermWrite. +func (tr *TermRef) Write(p []byte) (n int, err error) { + if tr.VDomRef == nil || !tr.VDomRef.HasCurrent.Load() { + return 0, fmt.Errorf("TermRef not current") + } + err = TermWrite(tr.VDomRef, string(p)) + if err != nil { + return 0, err + } + return len(p), nil +} + +// TermSize returns the current terminal size, or nil if not yet set. +func (tr *TermRef) TermSize() *vdom.VDomTermSize { + if tr.VDomRef == nil { + return nil + } + return tr.VDomRef.TermSize +} + +// UseTermRef returns a TermRef that can be passed as a ref to "wave:term" elements +// and also implements io.Writer for writing directly to the terminal. +func UseTermRef() *TermRef { + ref := UseVDomRef() + return &TermRef{VDomRef: ref} +} + // UseRef is the tsunami analog to React's useRef hook. // It provides a mutable ref object that persists across re-renders. // Unlike UseVDomRef, this is not tied to DOM elements but holds arbitrary values. diff --git a/tsunami/cmd/main-tsunami.go b/tsunami/cmd/main-tsunami.go index 6399aa6d5..f8b85f3e4 100644 --- a/tsunami/cmd/main-tsunami.go +++ b/tsunami/cmd/main-tsunami.go @@ -41,14 +41,22 @@ func validateEnvironmentVars(opts *build.BuildOpts) error { if scaffoldPath == "" { return fmt.Errorf("%s environment variable must be set", EnvTsunamiScaffoldPath) } + absScaffoldPath, err := filepath.Abs(scaffoldPath) + if err != nil { + return fmt.Errorf("failed to resolve %s to absolute path: %w", EnvTsunamiScaffoldPath, err) + } sdkReplacePath := os.Getenv(EnvTsunamiSdkReplacePath) if sdkReplacePath == "" { return fmt.Errorf("%s environment variable must be set", EnvTsunamiSdkReplacePath) } + absSdkReplacePath, err := filepath.Abs(sdkReplacePath) + if err != nil { + return fmt.Errorf("failed to resolve %s to absolute path: %w", EnvTsunamiSdkReplacePath, err) + } - opts.ScaffoldPath = scaffoldPath - opts.SdkReplacePath = sdkReplacePath + opts.ScaffoldPath = absScaffoldPath + opts.SdkReplacePath = absSdkReplacePath // NodePath is optional if nodePath := os.Getenv(EnvTsunamiNodePath); nodePath != "" { diff --git a/tsunami/engine/clientimpl.go b/tsunami/engine/clientimpl.go index 79c760e98..ac9cb2910 100644 --- a/tsunami/engine/clientimpl.go +++ b/tsunami/engine/clientimpl.go @@ -5,6 +5,7 @@ package engine import ( "context" + "encoding/base64" "encoding/json" "fmt" "io/fs" @@ -304,6 +305,18 @@ func (c *ClientImpl) SendAsyncInitiation() error { return c.SendSSEvent(ssEvent{Event: "asyncinitiation", Data: nil}) } +func (c *ClientImpl) SendTermWrite(refId string, data string) error { + payload := rpctypes.TermWritePacket{ + RefId: refId, + Data64: base64.StdEncoding.EncodeToString([]byte(data)), + } + jsonData, err := json.Marshal(payload) + if err != nil { + return err + } + return c.SendSSEvent(ssEvent{Event: "termwrite", Data: jsonData}) +} + func makeNullRendered() *rpctypes.RenderedElem { return &rpctypes.RenderedElem{WaveId: uuid.New().String(), Tag: vdom.WaveNullTag} } diff --git a/tsunami/engine/render.go b/tsunami/engine/render.go index 29c39c9cb..87750f874 100644 --- a/tsunami/engine/render.go +++ b/tsunami/engine/render.go @@ -5,6 +5,7 @@ package engine import ( "fmt" + "log" "reflect" "unicode" @@ -247,12 +248,6 @@ func convertPropsToVDom(props map[string]any) map[string]any { vdomProps[k] = vdomFuncPtr continue } - if vdomRef, ok := v.(vdom.VDomRef); ok { - // ensure Type is set on all VDomRefs - vdomRef.Type = vdom.ObjectType_Ref - vdomProps[k] = vdomRef - continue - } if vdomRefPtr, ok := v.(*vdom.VDomRef); ok { if vdomRefPtr == nil { continue // handle typed-nil @@ -263,6 +258,10 @@ func convertPropsToVDom(props map[string]any) map[string]any { continue } val := reflect.ValueOf(v) + if val.Type() == reflect.TypeOf(vdom.VDomRef{}) { + log.Printf("warning: VDomRef passed as non-pointer for prop %q (VDomRef contains atomics and must be passed as *VDomRef); dropping prop\n", k) + continue + } if val.Kind() == reflect.Func { // convert go functions passed to event handlers to VDomFuncs vdomProps[k] = vdom.VDomFunc{Type: vdom.ObjectType_Func} diff --git a/tsunami/engine/rootelem.go b/tsunami/engine/rootelem.go index 1d8b93808..787be044e 100644 --- a/tsunami/engine/rootelem.go +++ b/tsunami/engine/rootelem.go @@ -443,9 +443,11 @@ func (r *RootElem) UpdateRef(updateRef rpctypes.VDomRefUpdate) { if !ok { return } - ref.HasCurrent = updateRef.HasCurrent + ref.HasCurrent.Store(updateRef.HasCurrent) ref.Position = updateRef.Position - r.addRenderWork(waveId) + if updateRef.TermSize != nil { + ref.TermSize = updateRef.TermSize + } } func (r *RootElem) QueueRefOp(op vdom.VDomRefOperation) { diff --git a/tsunami/engine/serverhandlers.go b/tsunami/engine/serverhandlers.go index 5c5325610..1e7bc94fd 100644 --- a/tsunami/engine/serverhandlers.go +++ b/tsunami/engine/serverhandlers.go @@ -18,6 +18,7 @@ import ( "github.com/wavetermdev/waveterm/tsunami/rpctypes" "github.com/wavetermdev/waveterm/tsunami/util" + "github.com/wavetermdev/waveterm/tsunami/vdom" ) const SSEKeepAliveDuration = 5 * time.Second @@ -83,6 +84,7 @@ func (h *httpHandlers) registerHandlers(mux *http.ServeMux, opts handlerOpts) { mux.HandleFunc("/api/schemas", h.handleSchemas) mux.HandleFunc("/api/manifest", h.handleManifest(opts.ManifestFile)) mux.HandleFunc("/api/modalresult", h.handleModalResult) + mux.HandleFunc("/api/terminput", h.handleTermInput) mux.HandleFunc("/dyn/", h.handleDynContent) // Add handler for static files at /static/ path @@ -392,6 +394,48 @@ func (h *httpHandlers) handleModalResult(w http.ResponseWriter, r *http.Request) json.NewEncoder(w).Encode(map[string]any{"success": true}) } +func (h *httpHandlers) handleTermInput(w http.ResponseWriter, r *http.Request) { + defer func() { + panicErr := util.PanicHandler("handleTermInput", recover()) + if panicErr != nil { + http.Error(w, fmt.Sprintf("internal server error: %v", panicErr), http.StatusInternalServerError) + } + }() + + setNoCacheHeaders(w) + + if r.Method != http.MethodPost { + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + return + } + + body, err := io.ReadAll(r.Body) + if err != nil { + http.Error(w, fmt.Sprintf("failed to read request body: %v", err), http.StatusBadRequest) + return + } + + var event vdom.VDomEvent + if err := json.Unmarshal(body, &event); err != nil { + http.Error(w, fmt.Sprintf("failed to parse JSON: %v", err), http.StatusBadRequest) + return + } + if strings.TrimSpace(event.WaveId) == "" { + http.Error(w, "waveid is required", http.StatusBadRequest) + return + } + if event.TermInput == nil { + http.Error(w, "terminput is required", http.StatusBadRequest) + return + } + + h.renderLock.Lock() + h.Client.Root.Event(event, h.Client.GlobalEventHandler) + h.renderLock.Unlock() + + w.WriteHeader(http.StatusNoContent) +} + func (h *httpHandlers) handleDynContent(w http.ResponseWriter, r *http.Request) { defer func() { panicErr := util.PanicHandler("handleDynContent", recover()) diff --git a/tsunami/frontend/package.json b/tsunami/frontend/package.json index fd1e80180..f3faa7040 100644 --- a/tsunami/frontend/package.json +++ b/tsunami/frontend/package.json @@ -27,12 +27,12 @@ "tailwind-merge": "^3.3.1" }, "devDependencies": { - "@tailwindcss/cli": "^4.1.18", - "@tailwindcss/vite": "^4.1.18", + "@tailwindcss/cli": "^4.2.1", + "@tailwindcss/vite": "^4.2.1", "@types/react": "^19", "@types/react-dom": "^19", "@vitejs/plugin-react-swc": "^4.2.3", - "tailwindcss": "^4.1.18", + "tailwindcss": "^4.2.1", "typescript": "^5.9.3", "vite": "^6.4.1" } diff --git a/tsunami/frontend/src/element/tsunamiterm.tsx b/tsunami/frontend/src/element/tsunamiterm.tsx new file mode 100644 index 000000000..603d4b188 --- /dev/null +++ b/tsunami/frontend/src/element/tsunamiterm.tsx @@ -0,0 +1,157 @@ +import { FitAddon } from "@xterm/addon-fit"; +import { Terminal } from "@xterm/xterm"; +import "@xterm/xterm/css/xterm.css"; +import * as React from "react"; + +import { base64ToArray } from "@/util/base64"; + +export type TsunamiTermElem = HTMLDivElement & { + __termWrite: (data64: string) => void; + __termFocus: () => void; + __termSize: () => VDomTermSize | null; +}; + +type TsunamiTermProps = React.HTMLAttributes & { + onData?: (data: string | null, termsize: VDomTermSize | null) => void; + termFontSize?: number; + termFontFamily?: string; + termScrollback?: number; +}; + +const TsunamiTerm = React.forwardRef(function TsunamiTerm(props, ref) { + const { onData, termFontSize, termFontFamily, termScrollback, ...outerProps } = props; + const outerRef = React.useRef(null); + const termRef = React.useRef(null); + const terminalRef = React.useRef(null); + const onDataRef = React.useRef(onData); + onDataRef.current = onData; + + const setOuterRef = React.useCallback( + (elem: TsunamiTermElem) => { + outerRef.current = elem; + if (elem != null) { + elem.__termWrite = (data64: string) => { + if (data64 == null || data64 === "") { + return; + } + try { + terminalRef.current?.write(base64ToArray(data64)); + } catch (error) { + console.error("Failed to write to terminal:", error); + } + }; + elem.__termFocus = () => { + terminalRef.current?.focus(); + }; + elem.__termSize = () => { + const terminal = terminalRef.current; + if (terminal == null) { + return null; + } + return { rows: terminal.rows, cols: terminal.cols }; + }; + } + if (typeof ref === "function") { + ref(elem); + return; + } + if (ref != null) { + ref.current = elem; + } + }, + [ref] + ); + + React.useEffect(() => { + if (termRef.current == null) { + return; + } + const terminal = new Terminal({ + convertEol: false, + ...(termFontSize != null ? { fontSize: termFontSize } : {}), + ...(termFontFamily != null ? { fontFamily: termFontFamily } : {}), + ...(termScrollback != null ? { scrollback: termScrollback } : {}), + }); + const fitAddon = new FitAddon(); + terminal.loadAddon(fitAddon); + terminal.open(termRef.current); + fitAddon.fit(); + terminalRef.current = terminal; + + const onDataDisposable = terminal.onData((data) => { + if (onDataRef.current == null) { + return; + } + onDataRef.current(data, null); + }); + const onResizeDisposable = terminal.onResize((size) => { + if (onDataRef.current == null) { + return; + } + onDataRef.current(null, { rows: size.rows, cols: size.cols }); + }); + if (onDataRef.current != null) { + onDataRef.current(null, { rows: terminal.rows, cols: terminal.cols }); + } + + const resizeObserver = new ResizeObserver(() => { + fitAddon.fit(); + }); + if (outerRef.current != null) { + resizeObserver.observe(outerRef.current); + } + + return () => { + resizeObserver.disconnect(); + onResizeDisposable.dispose(); + onDataDisposable.dispose(); + terminal.dispose(); + terminalRef.current = null; + }; + }, []); + + React.useEffect(() => { + const terminal = terminalRef.current; + if (terminal == null) { + return; + } + if (termFontSize != null) { + terminal.options.fontSize = termFontSize; + } + if (termFontFamily != null) { + terminal.options.fontFamily = termFontFamily; + } + if (termScrollback != null) { + terminal.options.scrollback = termScrollback; + } + }, [termFontSize, termFontFamily, termScrollback]); + + const handleFocus = React.useCallback( + (e: React.FocusEvent) => { + terminalRef.current?.focus(); + outerProps.onFocus?.(e); + }, + [outerProps.onFocus] + ); + + const handleBlur = React.useCallback( + (e: React.FocusEvent) => { + terminalRef.current?.blur(); + outerProps.onBlur?.(e); + }, + [outerProps.onBlur] + ); + + return ( +
} + onFocus={handleFocus} + onBlur={handleBlur} + > +
+
+ ); +}); + +export { TsunamiTerm }; diff --git a/tsunami/frontend/src/model/model-utils.ts b/tsunami/frontend/src/model/model-utils.ts index 9ea4d9298..da14252a6 100644 --- a/tsunami/frontend/src/model/model-utils.ts +++ b/tsunami/frontend/src/model/model-utils.ts @@ -1,6 +1,8 @@ // Copyright 2025, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 +import type { TsunamiTermElem } from "@/element/tsunamiterm"; + const TextTag = "#text"; // TODO support binding @@ -79,6 +81,22 @@ export function restoreVDomElems(backendUpdate: VDomBackendUpdate) { }); } +export function isTsunamiTermElem(elem: HTMLElement): elem is TsunamiTermElem { + return elem != null && typeof (elem as TsunamiTermElem).__termWrite === "function"; +} + +export function applyTermOp(elem: TsunamiTermElem, termOp: VDomRefOperation) { + const { op, params } = termOp; + if (op === "termwrite") { + const data64 = params?.[0]; + if (typeof data64 === "string" && data64 !== "") { + elem.__termWrite(data64); + } + } else if (op === "focus") { + elem.__termFocus(); + } +} + export function applyCanvasOp(canvas: HTMLCanvasElement, canvasOp: VDomRefOperation, refStore: Map) { const ctx = canvas.getContext("2d"); if (!ctx) { diff --git a/tsunami/frontend/src/model/tsunami-model.tsx b/tsunami/frontend/src/model/tsunami-model.tsx index 61857dbeb..cc83104b8 100644 --- a/tsunami/frontend/src/model/tsunami-model.tsx +++ b/tsunami/frontend/src/model/tsunami-model.tsx @@ -9,7 +9,7 @@ import { getOrCreateClientId } from "@/util/clientid"; import { adaptFromReactOrNativeKeyEvent } from "@/util/keyutil"; import { PLATFORM, PlatformMacOS } from "@/util/platformutil"; import { getDefaultStore } from "jotai"; -import { applyCanvasOp, restoreVDomElems } from "./model-utils"; +import { applyCanvasOp, applyTermOp, isTsunamiTermElem, restoreVDomElems } from "./model-utils"; const dlog = debug("wave:vdom"); @@ -236,6 +236,25 @@ export class TsunamiModel { } }); + this.serverEventSource.addEventListener("termwrite", (event: MessageEvent) => { + try { + const packet = JSON.parse(event.data); + if (packet?.refid == null || packet?.data64 == null) { + return; + } + const refOp: VDomRefOperation = { refid: packet.refid, op: "termwrite", params: [packet.data64] }; + const elem = this.getRefElem(refOp.refid); + if (elem == null) { + return; + } + if (isTsunamiTermElem(elem)) { + applyTermOp(elem, refOp); + } + } catch (e) { + console.error("Failed to parse termwrite event:", e); + } + }); + this.serverEventSource.addEventListener("error", (event) => { console.error("SSE connection error:", event); }); @@ -319,6 +338,12 @@ export class TsunamiModel { boundingclientrect: ref.elem.getBoundingClientRect(), }; } + if (isTsunamiTermElem(ref.elem)) { + const termsize = ref.elem.__termSize(); + if (termsize != null) { + ru.termsize = termsize; + } + } updates.push(ru); ref.updated = false; } @@ -606,6 +631,10 @@ export class TsunamiModel { applyCanvasOp(elem, refOp, this.refOutputStore); continue; } + if (isTsunamiTermElem(elem)) { + applyTermOp(elem, refOp); + continue; + } if (refOp.op == "focus") { if (elem == null) { this.addErrorMessage(`Could not focus ref with id ${refOp.refid}: elem is null`); @@ -718,8 +747,7 @@ export class TsunamiModel { vdomEvent.globaleventtype = fnDecl.globalevent; } const needsAsync = - propName == "onSubmit" || - (propName == "onChange" && (e.target as HTMLInputElement)?.type === "file"); + propName == "onSubmit" || (propName == "onChange" && (e.target as HTMLInputElement)?.type === "file"); if (needsAsync) { asyncAnnotateEvent(vdomEvent, propName, e) .then(() => { diff --git a/tsunami/frontend/src/types/vdom.d.ts b/tsunami/frontend/src/types/vdom.d.ts index 485ada680..2ca0f7386 100644 --- a/tsunami/frontend/src/types/vdom.d.ts +++ b/tsunami/frontend/src/types/vdom.d.ts @@ -33,6 +33,18 @@ type VDomElem = { text?: string; }; +// vdom.VDomTermSize +type VDomTermSize = { + rows: number; + cols: number; +}; + +// vdom.VDomTermInputData +type VDomTermInputData = { + termsize?: VDomTermSize; + data?: string; +}; + // vdom.VDomEvent type VDomEvent = { waveid: string; @@ -46,6 +58,7 @@ type VDomEvent = { keydata?: VDomKeyboardEvent; mousedata?: VDomPointerData; formdata?: VDomFormData; + terminput?: VDomTermInputData; }; // vdom.VDomFrontendUpdate @@ -103,7 +116,6 @@ type VDomRef = { type: "ref"; refid: string; trackposition?: boolean; - position?: VDomRefPosition; hascurrent?: boolean; }; @@ -130,6 +142,7 @@ type VDomRefUpdate = { refid: string; hascurrent: boolean; position?: VDomRefPosition; + termsize?: VDomTermSize; }; // rpctypes.VDomRenderContext diff --git a/tsunami/frontend/src/vdom.tsx b/tsunami/frontend/src/vdom.tsx index 37de4c0f1..a51e11919 100644 --- a/tsunami/frontend/src/vdom.tsx +++ b/tsunami/frontend/src/vdom.tsx @@ -7,8 +7,9 @@ import * as jotai from "jotai"; import * as React from "react"; import { twMerge } from "tailwind-merge"; -import { AlertModal, ConfirmModal } from "@/element/modals"; import { Markdown } from "@/element/markdown"; +import { AlertModal, ConfirmModal } from "@/element/modals"; +import { TsunamiTerm } from "@/element/tsunamiterm"; import { getTextChildren } from "@/model/model-utils"; import type { TsunamiModel } from "@/model/tsunami-model"; import { RechartsTag } from "@/recharts/recharts"; @@ -30,6 +31,7 @@ type VDomReactTagType = (props: { elem: VDomElem; model: TsunamiModel }) => Reac const WaveTagMap: Record = { "wave:markdown": WaveMarkdown, + "wave:term": WaveTerm, }; const AllowedSimpleTags: { [tagName: string]: boolean } = { @@ -278,6 +280,46 @@ function WaveMarkdown({ elem, model }: { elem: VDomElem; model: TsunamiModel }) ); } +async function sendTermInputEvent(event: VDomEvent) { + const response = await fetch("/api/terminput", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(event), + }); + if (!response.ok) { + throw new Error(`terminal input request failed: ${response.status} ${response.statusText}`); + } +} + +function WaveTerm({ elem, model }: { elem: VDomElem; model: TsunamiModel }) { + const props = useVDom(model, elem); + const hasOnData = props.onData != null; + const onData = React.useCallback( + (data: string | null, termsize: VDomTermSize | null) => { + const terminput: VDomTermInputData = {}; + if (data != null) { + terminput.data = data; + } + if (termsize != null) { + terminput.termsize = termsize; + } + const event: VDomEvent = { + waveid: elem.waveid, + eventtype: "onData", + terminput: terminput, + }; + sendTermInputEvent(event).catch((error) => { + console.error("Failed to send terminal input:", error); + }); + }, + [elem.waveid] + ); + const termProps = { ...props, onData: hasOnData ? onData : undefined }; + return ; +} + function StyleTag({ elem, model }: { elem: VDomElem; model: TsunamiModel }) { const styleText = getTextChildren(elem); if (styleText == null) { diff --git a/tsunami/rpctypes/protocoltypes.go b/tsunami/rpctypes/protocoltypes.go index f2728f0bb..bad88a874 100644 --- a/tsunami/rpctypes/protocoltypes.go +++ b/tsunami/rpctypes/protocoltypes.go @@ -166,6 +166,7 @@ type VDomRefUpdate struct { RefId string `json:"refid"` HasCurrent bool `json:"hascurrent"` Position *vdom.VDomRefPosition `json:"position,omitempty"` + TermSize *vdom.VDomTermSize `json:"termsize,omitempty"` } type VDomBackendOpts struct { @@ -206,3 +207,8 @@ type ModalResult struct { ModalId string `json:"modalid"` // ID of the modal Confirm bool `json:"confirm"` // true = confirmed/ok, false = cancelled } + +type TermWritePacket struct { + RefId string `json:"refid"` + Data64 string `json:"data64"` +} diff --git a/tsunami/templates/package.json.tmpl b/tsunami/templates/package.json.tmpl index a21451064..c8d88dae8 100644 --- a/tsunami/templates/package.json.tmpl +++ b/tsunami/templates/package.json.tmpl @@ -10,7 +10,7 @@ "email": "info@commandline.dev" }, "dependencies": { - "@tailwindcss/cli": "^4.1.13", - "tailwindcss": "^4.1.13" + "@tailwindcss/cli": "^4.2.1", + "tailwindcss": "^4.2.1" } } diff --git a/tsunami/vdom/vdom_types.go b/tsunami/vdom/vdom_types.go index d20a02ac3..58725e401 100644 --- a/tsunami/vdom/vdom_types.go +++ b/tsunami/vdom/vdom_types.go @@ -1,8 +1,13 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 package vdom +import ( + "encoding/json" + "sync/atomic" +) + const TextTag = "#text" const WaveTextTag = "wave:text" const WaveNullTag = "wave:null" @@ -36,8 +41,42 @@ type VDomRef struct { Type string `json:"type" tstype:"\"ref\""` RefId string `json:"refid"` TrackPosition bool `json:"trackposition,omitempty"` - Position *VDomRefPosition `json:"position,omitempty"` - HasCurrent bool `json:"hascurrent,omitempty"` + Position *VDomRefPosition `json:"-"` + HasCurrent atomic.Bool `json:"-"` + TermSize *VDomTermSize `json:"-"` +} + +func (r *VDomRef) MarshalJSON() ([]byte, error) { + type vdomRefAlias struct { + Type string `json:"type"` + RefId string `json:"refid"` + TrackPosition bool `json:"trackposition,omitempty"` + HasCurrent bool `json:"hascurrent,omitempty"` + } + return json.Marshal(vdomRefAlias{ + Type: r.Type, + RefId: r.RefId, + TrackPosition: r.TrackPosition, + HasCurrent: r.HasCurrent.Load(), + }) +} + +func (r *VDomRef) UnmarshalJSON(data []byte) error { + type vdomRefAlias struct { + Type string `json:"type"` + RefId string `json:"refid"` + TrackPosition bool `json:"trackposition,omitempty"` + HasCurrent bool `json:"hascurrent,omitempty"` + } + var alias vdomRefAlias + if err := json.Unmarshal(data, &alias); err != nil { + return err + } + r.Type = alias.Type + r.RefId = alias.RefId + r.TrackPosition = alias.TrackPosition + r.HasCurrent.Store(alias.HasCurrent) + return nil } type VDomSimpleRef[T any] struct { @@ -62,18 +101,29 @@ type VDomRefPosition struct { BoundingClientRect DomRect `json:"boundingclientrect"` } +type VDomTermInputData struct { + TermSize *VDomTermSize `json:"termsize,omitempty"` + Data string `json:"data,omitempty"` +} + +type VDomTermSize struct { + Rows int `json:"rows"` + Cols int `json:"cols"` +} + type VDomEvent struct { WaveId string `json:"waveid"` EventType string `json:"eventtype"` // usually the prop name (e.g. onClick, onKeyDown) GlobalEventType string `json:"globaleventtype,omitempty"` - TargetValue string `json:"targetvalue,omitempty"` // set for onChange events on input/textarea/select + TargetValue string `json:"targetvalue,omitempty"` // set for onChange events on input/textarea/select TargetChecked bool `json:"targetchecked,omitempty"` // set for onChange events on checkbox/radio inputs - TargetName string `json:"targetname,omitempty"` // target element's name attribute - TargetId string `json:"targetid,omitempty"` // target element's id attribute - TargetFiles []VDomFileData `json:"targetfiles,omitempty"` // set for onChange events on file inputs - KeyData *VDomKeyboardEvent `json:"keydata,omitempty"` // set for onKeyDown events - MouseData *VDomPointerData `json:"mousedata,omitempty"` // set for onClick, onMouseDown, onMouseUp, onDoubleClick events - FormData *VDomFormData `json:"formdata,omitempty"` // set for onSubmit events on forms + TargetName string `json:"targetname,omitempty"` // target element's name attribute + TargetId string `json:"targetid,omitempty"` // target element's id attribute + TargetFiles []VDomFileData `json:"targetfiles,omitempty"` // set for onChange events on file inputs + KeyData *VDomKeyboardEvent `json:"keydata,omitempty"` // set for onKeyDown events + MouseData *VDomPointerData `json:"mousedata,omitempty"` // set for onClick, onMouseDown, onMouseUp, onDoubleClick events + FormData *VDomFormData `json:"formdata,omitempty"` // set for onSubmit events on forms + TermInput *VDomTermInputData `json:"terminput,omitempty"` // set for onData events on wave:term elements } type VDomKeyboardEvent struct { @@ -115,13 +165,13 @@ type VDomPointerData struct { } type VDomFormData struct { - Action string `json:"action,omitempty"` - Method string `json:"method"` - Enctype string `json:"enctype"` - FormId string `json:"formid,omitempty"` - FormName string `json:"formname,omitempty"` - Fields map[string][]string `json:"fields"` - Files map[string][]VDomFileData `json:"files"` + Action string `json:"action,omitempty"` + Method string `json:"method"` + Enctype string `json:"enctype"` + FormId string `json:"formid,omitempty"` + FormName string `json:"formname,omitempty"` + Fields map[string][]string `json:"fields"` + Files map[string][]VDomFileData `json:"files"` } func (f *VDomFormData) GetField(fieldName string) string {