Skip to content

feat: per-workspace script management system#25

Open
lyx-tec wants to merge 1 commit into
mainfrom
feat/workspace-scripts
Open

feat: per-workspace script management system#25
lyx-tec wants to merge 1 commit into
mainfrom
feat/workspace-scripts

Conversation

@lyx-tec

@lyx-tec lyx-tec commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

Add a per-workspace script management system. Users can store shell scripts in workspace metadata, execute them from a quick-select picker, and manage them in a dedicated modal.

Implementation

Data Layer (workspace-scripts.ts)

  • Scripts stored in workspace.meta["scripts:list"] with full TypeScript typing via Go-side MetaTSType registration
  • WorkspaceScript fields: id, name, command, desc?, lastused? (Unix ms timestamp)
  • getScriptsFromWorkspace / saveScriptsToWorkspace / recordScriptRun — CRUD helpers
  • runScript(script, blockId?) — builds heredoc pipeline and injects into terminal
  • openScriptsPicker(blockId?) — unified entry point for both keyboard shortcut and context menu
  • Scripts sorted by lastused descending in the picker

Execution (buildHeredocCommand)

Scripts run via a heredoc → temp file → source → cleanup pipeline:

__WAVE_SCR_FILE=$(mktemp "${TMPDIR:-/tmp}/waveterm-script-XXXXXX")
cat << 'DELIM' > "$__WAVE_SCR_FILE"
<script content>
DELIM
. "$__WAVE_SCR_FILE"; rm -f "$__WAVE_SCR_FILE"
  • Uses POSIX . (dot) command instead of source for dash compatibility
  • Quoted heredoc delimiter prevents shell expansion in script body
  • __WAVE_SCR_FILE naming minimizes collision with user variables
  • Blocked on fish, cmd, PowerShell with a message modal

Script Picker (WorkspaceScriptsPicker)

  • Triggered by Ctrl+Shift+e (e for execute) or right-click "Run Script…" in terminal
  • Search input with magnifying glass icon (InputGroup pattern)
  • Arrow-key navigation + Enter to run; click or Enter with no selection runs first
  • Hover on list items reveals edit/delete buttons for inline management
  • Empty state shows scroll icon + "+ Add Script" button linking to management modal

Script Management Modal (WorkspaceScriptsModal)

  • Inline CRUD — editing replaces the card in-place, add form appears at list bottom
  • Card shows name, first-line command preview (truncated with ellipsis), and description
  • Hover reveals edit/delete action buttons; delete confirms via ConfirmModal
  • Escape: cancels form if editing, closes modal otherwise

Integration

  • Keyboard shortcut: keymodel.ts registers Ctrl:Shift:eopenScriptsPicker(), returns false if condition not met so the key event propagates
  • Context menu: term-model.ts:getContextMenuItems(blockId) — blockId explicitly threaded through to openScriptsPicker(blockId), avoiding getFocusedBlockId() mismatch on right-click
  • Workspace editor: ScriptsSection component with live preview card (green accent left border, modal-bg-color background, "+N more" clickable link)

Design Decisions

  • runScript returns { ok: boolean; reason?: string } — domain logic does not push modals; the caller (picker) decides how to surface errors
  • Shell detection is heuristic (term:localshellpath config) — fish detected by path matching, Windows cmd/PowerShell by path + platform check
  • buildHeredocCommand is module-private, not exported
  • ScriptRunResult interface is exported for callers to consume

Files Changed

File Change
pkg/waveobj/wtype.go Add WorkspaceScript struct + ScriptsList field
pkg/waveobj/wtypemeta.go Register scripts:list in MetaTSType
pkg/waveobj/metaconsts.go Auto-generated MetaKey_ScriptsList constant
frontend/types/gotypes.d.ts Auto-generated WorkspaceScript type + MetaType extension
frontend/app/workspace/workspace-scripts.ts Core helpers (new file)
frontend/app/modals/workspace-scripts-picker.{tsx,scss} Script picker modal (new files)
frontend/app/modals/workspace-scripts-modal.{tsx,scss} Script management modal (new files)
frontend/app/modals/modalregistry.tsx Register both modals
frontend/app/store/keymodel.ts Register Ctrl+Shift+e shortcut
frontend/app/view/term/term-model.ts Add "Run Script…" context menu item
frontend/app/view/term/term.tsx Pass blockId to getContextMenuItems
frontend/app/tab/workspaceeditor.{tsx,scss} Add ScriptsSection with live preview
frontend/app/tab/workspaceswitcherdetail.tsx Pass workspaceId to editor

Note: Auto-generated files (metaconsts.go, gotypes.d.ts) were regenerated via task generate after manual Go changes.

Add a script management system that lets users store, edit, and execute
shell scripts within a workspace context.

Key features:
- Scripts stored in workspace.meta['scripts:list'] (typed WorkspaceScript[])
- Script execution via heredoc → mktemp → source → rm pipeline,
  supporting bash/zsh/sh/dash (POSIX '.' dot command), with block on
  fish, cmd, and PowerShell
- Script Picker modal (Ctrl+Shift+e or right-click 'Run Script…') with
  search, keyboard navigation, inline delete, and '+ Add Script' entry
- Script Management modal with inline CRUD (edit-in-place, add-at-bottom)
- Workspace editor preview card showing first script with live WOS atom
- blockId explicitly threaded through right-click → picker → runScript
- Go-side MetaTSType registration for 'scripts:list' with auto-generated
  TypeScript types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant