Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Agent 笔记:项目菜单独立移除最近记录

状态:已实现

## 先说结论

标题栏项目菜单的最近项目每行都提供 X,只从最近列表移除记录,不打开项目、不删除目录,也不关闭菜单。当前项目行的 X 继续关闭项目,并保留最近记录。目录已经不存在时,该行不能打开,但 X 仍可用。

## 问题

项目菜单原来仅为当前项目绘制关闭按钮,最近项目没有直接移除入口。若将缺失项目整行禁用,后续加入的移除按钮也会一起失去交互能力。

## 决策

最近项目复用 Core(共享 Rust 规则层)的现有最近项目移除动作和持久化路径。行内 X 使用独立命中区与对应的本地化提示,移除动作优先于行打开动作,防止同一次点击又触发打开。

缺失项目继续灰显且禁止打开,移除按钮保持可点击。正确做法是分别处理行激活和 X;不要在父容器上禁用全部子控件。

## 考虑过的备选方案

- 只在右键菜单提供移除:入口不直观,无法满足项目菜单直接删除记录的操作。
- 点击 X 后关闭整个菜单:连续整理最近记录时需要反复展开,现有列表更新已能原位呈现结果。

## 后果

用户可以直接整理存在或缺失目录的最近记录。两个区段的 X 有不同含义,因此分别使用“关闭项目”和“从最近项目移除”的提示;删除文件不属于这个入口。

## 验证

- `scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestProjectMenuRemoves|TestProjectMenuWheel' -count=1 -timeout=45s`:回归测试先确认缺少 X 时失败;修复后验证记录持久化、目录保留、菜单保留及当前项目关闭。
- `scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' ./internal/workbench -run TestVisualProjectMenuRemove -count=1 -timeout=45s`:使用真实临时目录生成中英文、明暗主题截图,检查存在与缺失两种最近记录。输出由 `LITHE_VISUAL_OUTPUT_DIR` 指定。

## 适用范围

- `desktop/internal/workbench/chrome_view.go`
- `desktop/internal/workbench/project_menu_test.go`
- `shared/platform-feature-matrix/features/workspace-open-switch.json`
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Agent 笔记:可选 CLI 注册与单文件编辑

状态:已实现

## 先说结论

Lithe 默认不向用户的命令行环境注册命令。用户在设置的“通用 > CLI”卡片明确点击后,才创建用户级启动器并修改显示的配置来源。命令打开文件夹时沿用完整项目流程;打开文件时使用独立的文本编辑窗口,任何插件都不创建或激活,文件的父目录也不会因此成为工作区。

## 问题

将普通文件当成项目打开,会启动与临时编辑无关的插件、索引和 Git 观察。安装时自动修改 PATH 又会影响用户的 shell 配置;只保存一个“已注册”偏好无法判断实际配置有没有被删除、改写或指向旧安装。

## 决策

- Core(共享 Rust 规则层)解析启动参数、根据原生文件类型选择模式,并给出单文件模式允许的命令。桌面端只做路径观察、进程启动和界面呈现。单文件窗口借用既有文档与标签生命周期,不调用项目打开流程;父目录只是文件位置,不进行项目恢复、信任确认、递归搜索或插件上下文绑定。
- 单文件模式保留内置语法高亮、文本编辑、查找替换、保存、编码与换行选择和单个文档的外部变更观察。项目侧栏、Git、运行、调试、测试及预览网页不呈现。终端默认关闭,由用户点击后才创建,使用当前文件所在目录,复用现有终端标签、分隔条及进程清理;隐藏面板保留会话,关闭标签或窗口释放 shell。单文件窗口不恢复或改写项目面板布局。双 Shift 和查找动作只列出允许的动作,不读取父目录。关闭全部文件后仍保持单文件空态。
- 顶栏显示当前文件名与“单文件模式”,通过 ⓘ 解释边界。“以项目打开所在文件夹”使用当前选中文件的父目录,在另一窗口进入正常的项目信任和插件流程,保留原编辑窗口。
- CLI 卡片直接读取默认 shell 配置与启动器内容。macOS zsh 使用 `.zshrc`(尊重 `ZDOTDIR`),bash 使用实际登录配置,fish 使用自身配置;Windows 编辑当前用户注册表 PATH,保留其原生字符串类型,并有界广播环境变更。已有终端需重新打开。
- 打开页面只读,注册、修复和移除都来自明确按钮。Unix 来源使用带标记的配置块,Windows 只编辑匹配目录项;保留其他内容。写入前核对文件内容、来源目录和符号链接目标;读取后被外部改写则拒绝覆盖。Windows 注册表核对与单值写入间仍受外部进程竞争限制,不宣称跨进程事务。
- 启动器只位于系统用户配置目录的 `Lithe/cli/bin`,指向应用当前可执行文件。它是用户运行状态,由 CLI 注册管理器持有,不进入 app bundle 或 Windows 安装目录,不影响签名和增量更新的源基线。应用移动后允许显式修复完整的 Lithe 启动器格式,不覆盖其他命令。移除注册后删除属于 Lithe 的启动器。

正确做法:`lithe notes.go` 只打开该文件,随后用户明确点击“以项目打开所在文件夹”才在新窗口创建项目服务。不要因为已知文件父目录而调用项目初始化,再在界面上隐藏面板;那样仍然付出了插件和目录观察的开销。

## 考虑过的备选方案

- 安装或首次启动时自动写 PATH:违背默认不注册的要求,也无法让用户审阅修改目标。
- 在单文件窗口创建项目并禁用部分插件:项目管线仍会创建目录观察和恢复状态,无法保证任何插件都不激活。
- 只注册全局系统目录中的符号链接:Windows 与 Unix 所需权限不同,还可能要求管理员权限。用户级启动器可以保持显式注册且不修改安装资源。
- 在当前窗口将单文件直接升级为项目:会混合两种服务生命周期,产生插件初始化与未保存文档处理的隐含转换。使用正常项目新窗口复用已有完整流程,代价是多一个窗口。

## 后果

临时文件不再启动项目服务;命令可移除、可回读,并能发现外部改动。单文件模式也因此没有插件语言智能和项目预览;需要这些功能时必须明确打开所在文件夹。每次 CLI 调用会短暂启动一个只处理参数和路径的父进程,再脱离终端创建 GUI(图形界面)子进程,不保留 shell 管道或后台 shell。

## 验证

- `scripts/desktop/desktop-go.sh test ./cmd/lithe ./internal/cli ./internal/core ./internal/workbench -run 'TestCLI|TestStandalone|TestDesktopStartupMakesInstalledPluginSettingsReachable' -count=1 -timeout=90s`:链接同一 Core 检出,验证真实文件类型、共享 fixture、真实临时 shell 配置的注册/修复/移除/冲突保护和独立编辑保存。
- `scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' ./internal/settingswindow ./internal/workbench -run 'TestVisualCLISettings|TestVisualStandalone' -count=1 -timeout=90s`:生成明暗主题、中英文的真实渲染截图。通过 `LITHE_VISUAL_OUTPUT_DIR` 指定本工作树的输出目录。
- `scripts/desktop/verify/verify-runtime-bundle-immutability.sh`:检查两个桌面平台的发行目录只读边界。
- Windows 规则可以在 macOS 上以平台参数验证;注册表写入、环境广播与 cmd/PowerShell 调用仍需 Windows 原生环境验收,交叉编译不替代该验收。

## 适用范围

- `desktop/cmd/lithe/`
- `desktop/internal/cli/`
- `desktop/internal/core/cli.go`
- `desktop/internal/workbench/standalone.go`
- `desktop/internal/settingswindow/cli_view.go`
- `shared/platform-feature-matrix/features/cli-single-file-mode.json`
10 changes: 10 additions & 0 deletions desktop/cmd/lithe/detach_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !windows

package main

import (
"os/exec"
"syscall"
)

func detachGUI(cmd *exec.Cmd) { cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true} }
10 changes: 10 additions & 0 deletions desktop/cmd/lithe/detach_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"os/exec"
"syscall"
)

func detachGUI(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: 0x00000008 | syscall.CREATE_NEW_PROCESS_GROUP}
}
103 changes: 84 additions & 19 deletions desktop/cmd/lithe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
package main

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"time"

"github.com/1lck/Lithe-IDEA/desktop"
"github.com/1lck/Lithe-IDEA/desktop/internal/core"
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/1lck/Lithe-IDEA/desktop/internal/installedpackage"
"github.com/1lck/Lithe-IDEA/desktop/internal/loginenv"
"github.com/1lck/Lithe-IDEA/desktop/internal/logstore"
"github.com/1lck/Lithe-IDEA/desktop/internal/store"
Expand All @@ -20,23 +25,50 @@ func main() {
// AppKit needs the process's main thread for the application and its windows. Pin the
// main goroutine before any setup that can yield, so the scheduler cannot move it.
runtime.LockOSThread()
client := core.NewClient()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
launch, err := client.PlanCLILaunch(ctx, os.Args[1:])
cancel()
if err != nil {
fail(err)
}
switch launch.Action {
case "help":
fmt.Println(i18n.Shared(i18n.Detect([]string{os.Getenv("LC_ALL"), os.Getenv("LC_MESSAGES"), os.Getenv("LANG")}), "desktop.cli.usage"))
return
case "version":
fmt.Println(desktop.Version())
return
}
path, file, err := commandLineTarget(client, launch.Path)
if err != nil {
fail(err)
}
if launch.Detach {
if err := launchGUI(path); err != nil {
fail(err)
}
return
}
// An app started from Finder or the Dock gets only the system PATH; take the login shell's
// before Core starts the threads that read the environment.
refreshLoginEnvironment := loginenv.Activate()
// before any project services start. The CLI requests above are synchronous pure rules.
var refreshLoginEnvironment func()
if !file {
refreshLoginEnvironment = loginenv.Activate()
}
preferences, err := store.Open()
if err != nil {
fail(err)
}
client := core.NewClient()
if refreshLoginEnvironment != nil {
go refreshLoginEnvironment()
}
version := desktop.Version()
options := workbench.DesktopOptions(client, preferences, version)
// A project folder given on the command line is opened when the window starts; a worktree's
// "Open in New Window" starts the client that way.
if folder := commandLineFolder(os.Args[1:]); folder != "" {
options.OpenPath = folder
if file {
options.OpenFile = path
} else {
options.OpenPath = path
}
// A log that cannot be opened leaves the client without its log window instead of
// keeping it from starting; the window says so when the log is asked for.
Expand All @@ -61,19 +93,52 @@ func main() {
}
}

// commandLineFolder is the first argument that names an existing folder, made absolute; empty when
// there is none.
func commandLineFolder(args []string) string {
for _, arg := range args {
abs, err := filepath.Abs(arg)
if err != nil {
continue
}
if info, err := os.Stat(abs); err == nil && info.IsDir() {
return abs
}
// commandLineTarget observes the native file type; Core selects the session policy.
func commandLineTarget(client *core.Client, path string) (string, bool, error) {
if path == "" {
return "", false, nil
}
abs, err := filepath.Abs(path)
if err != nil {
return "", false, err
}
abs, err = filepath.EvalSymlinks(abs)
if err != nil {
return "", false, err
}
info, err := os.Stat(abs)
if err != nil {
return "", false, err
}
kind := "other"
if info.IsDir() {
kind = "directory"
} else if info.Mode().IsRegular() {
kind = "file"
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
target, err := client.CLIOpenTarget(ctx, kind)
return abs, target.Mode == "file", err
}

// The shell launcher exits after starting the GUI, without a shell subprocess or
// inherited terminal streams. The child receives an absolute path and no --cli.
func launchGUI(path string) error {
executable, err := installedpackage.Executable()
if err != nil {
return err
}
args := []string{}
if path != "" {
args = []string{"--", path}
}
cmd := exec.Command(executable, args...)
detachGUI(cmd)
if err := cmd.Start(); err != nil {
return err
}
return ""
return cmd.Process.Release()
}

// fail reports an error that keeps the client from starting or running and exits.
Expand Down
31 changes: 31 additions & 0 deletions desktop/cmd/lithe/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"os"
"path/filepath"
"testing"

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
)

func TestCLIClassifiesActualFileAndFolder(t *testing.T) {
root := t.TempDir()
path := filepath.Join(root, "-中文 file.txt")
if err := os.WriteFile(path, []byte("text"), 0600); err != nil {
t.Fatal(err)
}
client := core.NewClient()
for _, test := range []struct {
path string
file bool
}{{root, false}, {path, true}} {
actual, file, err := commandLineTarget(client, test.path)
expected, resolveErr := filepath.EvalSymlinks(test.path)
if err != nil || resolveErr != nil || actual != expected || file != test.file {
t.Fatalf("classify %q: %q %v %v", test.path, actual, file, err)
}
}
if _, _, err := commandLineTarget(client, filepath.Join(root, "missing")); err == nil {
t.Fatal("missing target accepted")
}
}
4 changes: 4 additions & 0 deletions desktop/internal/cli/limits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package cli

// Shell configuration and launcher snapshots share Core's bounded text budget.
const maximumSourceBytes = 1 << 20
Loading
Loading