Repository navigation
feat(cli): 再次启动把路径交给已在运行的 Lithe - #2548
Conversation
Lithe 已在运行时,lithe <路径>、访达或 Dock 再次启动不再新开进程:新进程按 Core planLaunch 的 handOff 用 Viva singleinstance 把解析后的绝对路径交给运行副本,然后在建窗口、日志和插件之前退出。运行副本把窗口带到前台,经 Core 二次校验、重新观察路径后,文件夹按“打开项目的位置”打开(已打开的切过去),文件开单文件标签。找不到运行副本才自己启动。 - 实例名包含用户数据目录;开发构建再加可执行文件路径和修改时间,不交给安装版或旧构建 - --new-window 另开进程;单文件窗口“以项目打开所在文件夹”改用它 - LaunchInbox 在窗口就绪前最多排队 16 个启动,随事件循环结束释放认领 - 访达交来的文件夹按项目打开(原来被拒绝),提示落在当前显示的标签上 - 修复单文件标签与项目标签的标签栏 key 冲突、showing() 误匹配单文件标签 - 固定 Core 744d2f5(Lithe-IDEA/Lithe-core-rust#235),合入后换 main 提交 - 新增 Agent Note 与功能矩阵条目 cli-launch-handoff Closes #2545
# Conflicts: # scripts/desktop/build-desktop-core.sh
There was a problem hiding this comment.
Devin Review found 2 potential issues.
4 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| if open := s.showing(path); open != nil { | ||
| s.activate(open) | ||
| return | ||
| } | ||
| target := s.active | ||
| if index := slices.IndexFunc(s.list, func(a *App) bool { return !a.documentOnly }); target.documentOnly && index >= 0 { | ||
| target = s.list[index] | ||
| s.activate(target) | ||
| } | ||
| target.openProject(path) |
There was a problem hiding this comment.
🟡 Repeated launches duplicate project windows
With the New Window setting, openLaunchTarget opens a fresh window on every CLI launch of the same second project. It searches only the original window, so it never finds the project opened by the previous launch.
Learn more
The CLI sends normal launches to the process that owns the claim, not necessarily the process that owns the requested project; see main. The receiving process looks for the project in its own tabs. When another project is open and the user selected New Window, openProject calls launchClient to start a separate process with --new-window. That process does not claim or register its project with the receiver. Subsequent launches of the same project therefore repeat the New Window action. The same routing gap exists if the primary was started in single-file mode and has no project tab.
Example: Leave Project A open in the primary and choose New Window in settings. Run lithe ~/code/beta and let Beta finish opening. Run the same command again; it starts a second Beta window instead of activating the first one.
Recommended fix: Let the launch receiver discover and activate projects in all live windows it opens on behalf of handoffs. Register those windows and remove their registrations on close, or host them in the claiming process. Keep explicit lithe --new-window launches separate.
Was this helpful? React with 👍 or 👎 to provide feedback.
| claim, primary, claimErr = singleinstance.SingleInstance( | ||
| cli.InstanceID(preferences.Dir(), build), cli.HandOffArgs(path), inbox.Receive) | ||
| if claimErr == nil && !primary { | ||
| return |
There was a problem hiding this comment.
🟥 Windows handoff trusts unverified pipe servers
On Windows, SingleInstance sends the absolute launch path without verifying who owns the pipe server. Another local program that owns the expected pipe can read the path and acknowledge it without opening anything.
Was this helpful? React with 👍 or 👎 to provide feedback.
关联 Issue / Linked issue
planLaunch的newWindow、handOff与日志来源launch)singleinstance的两项已知限制)PR 类型 / Type
改动说明 / What changes
背景 / Why
Lithe 已在运行时,在终端执行
lithe <文件夹>/lithe <文件>,或从访达、Dock 再次启动,都会新开一个进程和窗口:现在的做法:不带
--new-window的启动先把路径交给同一份用户数据上已在运行的 Lithe(下称“运行副本”),由运行副本把窗口带到前台并打开;找不到运行副本时,新进程才自己启动。这与 VS Code、IDEA 命令行的默认行为一致。改动 / Changes
启动与交接
desktop/cmd/lithe/main.goplanLaunch返回handOff时,用 Viva 的app/singleinstance认领实例。没能成为运行副本的进程,在创建窗口、日志、插件和登录 shell 之前退出。app.background.operation_failed(operation=single_instance_claim)。Run()返回后释放认领。--new-window和-- <路径>,不再只传路径。desktop/internal/cli/launch.goTarget:取绝对路径、去掉符号链接,再观察路径类型。它由原来的cmd/lithe里的commandLineTarget搬过来。Observe:观察路径类型。InstanceID:由应用 id 和用户数据目录store.Dir()组成;开发构建再加DevelopmentBuild(),即可执行文件的路径和修改时间。HandOffArgs:生成交给运行副本的参数-- <绝对路径>。desktop/internal/core/cli.go:CLILaunch增加NewWindow、HandOff两个字段,测试按 Core 共享 fixture 校验。运行副本里的处理
desktop/internal/workbench/launch_handoff.goLaunchInbox在窗口就绪前最多排队 16 个启动,超出的丢弃。认领只释放一次。PlanCLILaunch再校验一次,不是交接请求的参数(比如带--new-window)会被拒绝;cli.Target重新观察路径;openLaunchTarget打开。openLaunchTarget按路径类型打开:openProject,遵守“打开项目的位置”设置。当前显示的是单文件标签时,改用第一个项目标签打开。app.goOptions.Launches把收件箱接进工作台。PlanCLILaunch。surfaceLaunch。RunApplication返回后关闭收件箱。顺带修复:交接路径会用到的既有问题
交接会让单文件标签和项目标签出现在同一个窗口,下面这些问题因此会直接暴露出来:
window_sessions.godocument:<序号>。showing()原来会把单文件标签当成某个项目标签匹配,现在跳过单文件标签。system_document.goopenLaunchTarget,按项目打开。project_open_destination.go:单文件窗口里的“以项目打开所在文件夹”改为exe --new-window -- <路径>。它本来就要另开进程,不能被交接回当前窗口。规则、依赖与文档
scripts/desktop/build-desktop-core.sh:PINNED_CORE_REVISION固定到 Core main 的add378d,即 feat(cli): 启动计划给出 newWindow 与 handOff,再次启动交给已在运行的副本 Lithe-IDEA/Lithe-core-rust#235 的合入提交。它的父提交是 main 原来固定的58cc3fc([Bug] ctrl+shift+f打开全局搜索,打开搜到的文件标签之后,搜索结果消失了 #233),所以合并 main 时两边的固定版本都被包含在内。desktop/go.mod/go.sum:补github.com/Microsoft/go-winio(indirect)。这是 Vivasingleinstance在 Windows 上建命名管道用的依赖;原来缺少go.sum条目,Windows 编译会失败。shared/i18n/features/cli-single-file.json和生成的shared.generated.go:lithe --help的中英用法加入[--new-window],并说明交接行为。新增 Agent Note
.agents/notes/implemented/feature/2026-11-30-cli-launch-hands-off-to-running-copy.md,内容包括:原 CLI Note 的“后果”一节加了指向它的链接。
删除
desktop/cmd/lithe/main_test.go:它测的commandLineTarget已搬到cli.Target,用例改为internal/cli里的TestTargetClassifiesActualFileAndFolder,覆盖范围不变。不在本 PR 范围内 / Out of scope
singleinstance的两项限制,已在 singleinstance:Unix 按路径删 socket 会删掉后来者的认领,Windows 不核对管道服务端所有者 Lithe-IDEA/Lithe-viva#84 记录,按规则在 Viva fork 修复,Lithe 不在应用层绕过:Close和清理残留 socket 时按路径删除文件,几乎同时的两次启动可能各自成为运行副本。--new-window进程不认领实例。 运行副本退出后,如果还有--new-window另开的进程在运行,下一次启动会成为新的运行副本。这一点已写进 Note。pending。类型专属:feat
多平台对齐
singleinstance按平台实现(Unix socket / 命名管道)。Windows 只做过singleinstance包的交叉编译和go mod verify,原生验收待做,功能矩阵记为pending。platform-specific),理由:范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/cli-launch-handoff.json:implemented/pending;./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh(validated 231 platform capabilities),以及./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD(matrix change gate passed)。.artifacts/下生成的矩阵视图。插件归属 / Plugin ownership
develop-lithe第三节的自查命令,结果为空。UI 验证 / UI evidence
N/A:没有布局、控件、样式或菜单变化。交接打开文件夹或文件时,用的都是现有的项目标签、单文件标签和“打开项目的位置”流程。参数被拒绝或路径失效时,复用现有的打开失败通知(
Errors.OpenFailed)。唯一改动的文案是终端里lithe --help的用法说明。窗口来到前台属于整机行为,原生验收见“不在本 PR 范围内”。统一日志系统 / Structured logging
app.action.performed,action=app.launch.handOff,surface=launch。launch这个取值由 feat(cli): 启动计划给出 newWindow 与 handOff,再次启动交给已在运行的副本 Lithe-IDEA/Lithe-core-rust#235 加入rust/logging/events/app.json。app.notification.operation_failed(operation=launch_handoff)。app.background.operation_failed(operation=launch_handoff)。app.background.operation_failed(operation=single_instance_claim)。documentLogError去掉PathError里的路径,再写入error字段;被丢弃的启动只记一条失败,不带参数。Windows 与 macOS 共用这份 Go 代码,用的是同一套日志。
界面文案 / i18n
lithe --help用法的中英词条已在shared/i18n/features/cli-single-file.json更新,运行了node scripts/i18n/generate-i18n.mjs并提交了生成结果。node scripts/i18n/verify-app-language-localization.mjs和node scripts/i18n/generate-i18n.mjs --check,都通过。逻辑归属 / Logic placement
application.cli.planLaunch决定(handOff、newWindow),共享 fixture 先于桌面接入(feat(cli): 启动计划给出 newWindow 与 handOff,再次启动交给已在运行的副本 Lithe-IDEA/Lithe-core-rust#235)。运行副本收到参数后也交给 Core 再校验一次。桌面端只做 socket/管道、路径观察和打开。cmd/lithe里的路径观察搬到internal/cli,供启动与交接共用。性能与内存 / Performance and memory
a.background后台任务里执行(有kernelCallTimeout上限),窗口线程只做最后的打开。planLaunch和路径观察之后就退出,不再创建窗口、插件和登录 shell,比原来每次完整启动轻得多。go-winio只在 Windows 上编译进来。设置 / Settings
N/A:没有新增或修改设置。交接打开文件夹时遵守已有的“打开项目的位置”设置。
插件契约 / Plugin contract
N/A:不涉及插件契约、能力版本、插件函数协议或宿主方法。Core 侧只改了应用 CLI 规则
application.cli.planLaunch和日志目录,不属于插件协议。即便如此,PINNED_CORE_REVISION仍已升到包含该改动的 Core main 提交add378d。发行包与资源 / Bundle and resources
~/Library/Application Support/viva/,Linux 是/run/user/<uid>/viva/。它由 Viva 创建和删除,崩溃残留由下一次启动清理。./scripts/desktop/verify/verify-runtime-bundle-immutability.sh,通过。docs/ci-builds.md:没有新增构建期的下载、解压、生成或缓存资源。无用代码与重构 / Dead code and refactoring
commandLineTarget之后不再使用的cmd/lithe/main_test.go已删除。验证 / Verification
add378d,所链接的 Core 检出与它内容完全相同):desktop-go.sh vet ./...、desktop-go.sh test -count=1 ./...scripts/desktop/desktop-go.sh test -count=1 ./...(链接 Core 744d2f5,rebase 到 main 510f121 之前)desktop-go.sh vet ./cmd/lithe ./internal/cli ./internal/core ./internal/workbenchdesktop-go.sh test ./cmd/lithe ./internal/cli ./internal/core ./internal/workbench -run 'TestTarget|TestInstanceID|TestHandOffArgs|TestCLI|TestLaunchInbox|TestHandedLaunches|TestSystemDocumentFolder|TestStandalone' -count=1-race -vTestHandedLaunchesOpenInTheRunningWindow,竞态模式),其余 ≤0.03snode scripts/i18n/generate-i18n.mjs --check、node scripts/i18n/verify-app-language-localization.mjs./scripts/agent-notes/verify-agent-notes.sh./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh、verify-platform-feature-matrix-change.sh origin/main HEAD./scripts/desktop/verify/verify-runtime-bundle-immutability.shdevelop-lithe第三节插件归属自查rgapp/singleinstance:GOOS=windows GOARCH=amd64 go build、GOOS=linux go build,以及go mod verifygo.sum之前 Windows 编译失败)cargo test -p lithe-core-rules、cargo test -p lithe-diagnostics、log-events --check、cargo fmt --check、cargo clippy未能执行的检查和原因:
lithe <路径>时窗口来到前台,以及访达再次打开。这些需要 macOS 整机验收,本次没有启动 Lithe 应用;单元和工作台测试只覆盖收件箱之后的部分。singleinstance包(windows/amd64、linux/amd64)并运行了go mod verify。提交前确认 / Final checks
main创建,目标分支main。add378d。