Skip to content

feat: 添加本地命令支持,可在桌面端执行本地命令 - #974

Open
fengpanhe wants to merge 1 commit into
spacering-net:mainfrom
fengpanhe:feat_local_cmd
Open

fengpanhe wants to merge 1 commit into
spacering-net:mainfrom
fengpanhe:feat_local_cmd

Conversation

@fengpanhe

@fengpanhe fengpanhe commented Oct 16, 2026 •

Copy link
Copy Markdown

Local commands (local:) and global commands

Summary

  • Add a local: command prefix so a folder command runs on the machine running the codeg desktop app instead of the folder's host. This lets a remote project launch local tools (e.g. open the remote dir in a local editor). No DB schema change and no server-side change — old remote codeg-server builds work as-is.
    • New desktop-only Tauri command run_local_command (src-tauri/src/commands/local_command.rs), registered in lib.rs, not exposed in the web router, so it can only ever run on the user's own machine. It spawns detached through the user's login shell ($SHELL -l -c 'eval "$CODEG_CMD"') with stdio nulled.
    • Injects CODEG_FOLDER_PATH (the folder's absolute path, remote path in remote mode) and CODEG_REMOTE_HOST (remote server host, empty for local projects).
    • Frontend: runLocalCommand in api.ts always uses the local shell transport; src/lib/local-command.ts parses the prefix and resolves the host; the command dropdown runs local: commands directly (no terminal tab) and shows an error in pure-web mode.
    • Example:
      • local: zed ssh://user@$CODEG_REMOTE_HOST$CODEG_FOLDER_PATH.
      • local: code --new-window --remote ssh-remote+devbox $CODEG_FOLDER_PATH
  • Add global commands ("show in all folders"): a per-command toggle in the manage dialog. Global commands are stored in client localStorage (src/lib/global-commands.ts), use negative ids to stay distinct from DB primary keys, and show in every folder/worktree/remote connection with a 🌐 marker. This fixes commands disappearing when switching folders or worktrees (folder commands are keyed by folder_id, and every worktree is a separate folder).
  • Fix: storedCommandId in terminal-context.tsx rejected ids < 0, so a running global command (negative id) read as "not running" after reload — now accepts any safe integer.
  • i18n: new keys across all 10 languages (localUnavailable, localRunFailed, globalCommand, localCommandHint, globalLabel, globalHint).

Notes / risks

  • Trust boundary: in remote mode the command list lives on the remote server; local: commands run on the user's machine only on an explicit click, never automatically.
  • A local: command selected as a work_task preflight still runs on the remote host as-is — don't use it that way.
  • Pure-web mode cannot run local commands (shows "desktop app only").

Test plan

  • pnpm vitest run for affected suites — 36 files / 357 tests pass, including new local-command.test.ts, global-commands.test.ts, and extended command-dropdown.test.tsx (local exec, web refusal, global command runs in a folder with none of its own).
  • tsc --noEmit, eslint, prettier --check — clean.
  • cargo check (desktop) and cargo check --no-default-features --features server-bin — pass; local_command Rust unit tests pass (incl. a real spawn verifying both env vars).
  • Manual: in a remote-desktop window, add local: <editor> "ssh://user@$CODEG_REMOTE_HOST$CODEG_FOLDER_PATH" and confirm it opens on the local machine.
  • Manual: toggle "show in all folders", switch folders/worktrees, confirm the command persists.

Files

22 files, +707 / −24: backend 3 (new local_command.rs), frontend components 3, context 1, api.ts, 2 new libs (+2 tests), i18n 10.

### 可选正文(补充说明)
新增 `local:` 前缀的命令,可在桌面应用中直接在本机执行,而非项目主机。支持多语言国际化,新增全局命令功能,命令可在所有文件夹中显示,同时适配 Tauri 桌面端实现本地命令执行逻辑,新增相关测试和类型定义。
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