Skip to content
Draft
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
Expand Up @@ -23,10 +23,17 @@
- **运行时与 Shell 发现**:网络调用在平台工作线程运行,界面读取缓存;发现有数量、数据和时间限制,取消或切换工作区后丢弃旧结果,失败不发布部分结果或本机回退。Shell 从远端登录环境、`/etc/shells` 和文件权限发现,旧服务缺目标权限时再查询链接真实路径;本机终端设置里的可执行文件路径不作为远程默认值。
- **资源生命周期**:Git 临时索引和源文件快照在远端临时目录或 Git common directory,由单次操作清理;探测、可执行文件与搜索缓存保存在客户端内存并按连接隔离。服务的 socket、锁和日志身份同时包含会话键与二进制 SHA-256,版本号相同但内容变化时不复用旧常驻进程。以上资源不跨工作树复制,运行时不写安装资源,不改变签名和 Sparkle delta 基线。
- **构建与插件运行**:构建扫描、工具探测、构建进程和报告读取使用原工作区的主机身份,stdout/stderr 分别增量解码。插件只部署经过原安装来源复核的包,异平台变体必须同版本、同声明且不增加批准程序;复用市场校验和下载器,不向小型服务引入包管理或语言引擎。目标文件通过带 SHA-256 的分块上传原子发布,普通文件只读、可执行文件只读可执行,可写状态位于远端用户目录。快照清理捕获原连接,在 Core 销毁进程后执行。
- **桌面缓存与同平台包**:异平台 ZIP 以索引 SHA-256 命名,保存在系统用户缓存目录,有总容量和文件数上限,复用时重新验哈希。同平台安装包先复制到私有临时目录,检查安装审批记录绑定的文件名、大小、内容和执行位,再复核清单。缺少新校验值的旧市场安装包走已批准来源的 ZIP 路径。缓存与快照均独立于安装目录和构建检出。
- **上传不互相拖住**:上传表只登记和移除身份,不把文件打开、写入、同步、发布或删除放在全局锁里。每个文件独立同步,同一上传的并发操作返回 `BUSY`;断线、取消和到期先标记取消,由仍在执行的工作线程保管并最终删除暂存文件。一个慢文件不能阻止另一个文件完成,释放动作也不能等慢文件的锁。
- **stdio 与启动**:语言、构建和 VCS 提供者复用 Core 的协议引擎,远程通道保留有界输入输出与原连接。异步部署、工具探测和启动在工作线程进行,启动期间保留有界文档快照与文件变更,停止后到达的会话先销毁再删除包。仅映射协议定义的 URI 和 VCS 路径字段,参数、文本与插件自定义值保持原样。依赖本机原生集成的 Java 仍明确拒绝,不能伪装成通用 stdio 已支持。
- **常驻服务启动只允许一个代理创建进程**:daemon 的存活锁只能防止同时服务,不能阻止竞争失败的启动进程在旧会话关闭后接管锁。代理在启动前先取得同一身份的 `.start` 文件锁,再检查 socket,已有服务就复用;锁覆盖创建进程至 socket 可连接,等待使用原有启动期限。`.start` 位于远端用户私有状态目录的 `run/`,进程关闭文件即释放锁,文件本身保留,避免删除后不同代理锁住不同 inode;它属于远端会话协调状态,不可跨工作树复用,不写安装包,不影响代码签名或 Sparkle delta。验证启动锁互斥、期限、释放及并发连接收到关闭确认后服务确实退出,不用延长测试超时掩盖残留进程。
- **断线与会话结束不同**:常驻会话仅断线时保留终端和进程供重连;非驻留连接断开、显式关闭会话或空闲到期时,迟到发布的资源必须由创建者清理。结束标记在清理现有资源表之前设置,否则慢启动可能在清理后才出现,尤其是常驻会话不能再把它当成“等待重连”的合法资源。
- **插件工作区身份**:远程上下文使用连接身份和主机平台,沿用按插件隔离的 rootID。宿主只在单独授权的 `workspace/getHostPaths` 中返回对应的 Linux 路径;常规上下文和目录列表不含主机路径或客户端占位目录。插件后端在客户端启动,保留工作区关闭时的取消。同一连接身份、主机目录和平台重连时沿用原上下文版本;任一变化时递增 generation,将订阅和句柄按过期版本释放。本机工具链发现排除远程占位目录。
- **插件文件读取边界**:宿主校验调用者的 rootID 和上下文版本,通过 Core 传入当前工作区绑定。远端服务从打开的根目录逐级使用目录描述符定位,拒绝跟随子路径中的符号链接。读取最多 128 KiB,目录分页游标绑定到根、路径和上下文版本。Core 只在完整读取时返回内容哈希。
- **语言服务器设置**:远程 `systemCommand` 启动和运行中的设置刷新使用同一个读取入口。全局设置留在客户端,项目设置通过启动时捕获的连接读取。重连会撤销旧语言服务器会话及其诊断,迟到的读取结果不会进入新会话。这样项目设置始终来自项目所在的主机。
- **构建选项读取**:插件查询构建选项时,从原连接读取项目里的团队配置,再由 Core 应用该远程工作区在客户端保存的个人覆盖。客户端占位目录只作为个人偏好的存储键。工作区关闭或连接更换后丢弃旧结果,避免把错误当成缺失配置后继续执行。
- **插件终端**:受信任的远程项目里,确认框显示连接、程序、参数和远端工作目录。确认只对当时的连接有效,重连后需要重新发起请求。程序复用已有的远端伪终端,工作目录由远端服务从项目根目录逐级打开并拒绝跟随子路径中的符号链接。环境变量在远端登录环境上应用,关闭标签后由原会话回收进程。
- **插件发起远端运行**:启动前和远端确认启动后都复核信任、工作区世代和连接身份。确认后的进程由 Run 窗口持有,后端请求结束不影响运行。关闭工作区或更换连接时取消原进程,等远端进程回收后在原会话释放临时文件。这样旧请求不会跨到重连后的主机,也不会在本机进程记录里混入远端 PID。工具版本探测和启动都用目录描述符限定在同一工作区。

### 正确做法

Expand Down Expand Up @@ -65,13 +72,18 @@
- 新增适配覆盖:远端 PTY、按主机探测环境、Git 文件与进程 I/O、搜索索引与 Shift+Shift 的文件及内容查询。真实服务 fixture 已覆盖状态、暂存、分页历史、设置来源、worktree 创建和管理、克隆、保留无关暂存的选择文件提交,以及未保存缓冲区的行历史;不能据此把完整真实 SSH 产品流程标为已验收。
- 文件树新建、复制、重命名、移到主机废纸篓和普通删除已接入;外部修改监听覆盖文件树与文档,真实 SSH 的原生 watcher 仍需产品验收。
- 构建 I/O、工具与状态目录适配,以及通用插件部署和 stdio 提供者接入已有实现与 fixture;真实 SSH 的完整构建、插件启动与取消链路仍待验收。
- 插件的文件名和文本搜索在远端服务中执行,每页有整次遍历、字节和时间预算。游标记录原连接和已返回结果的摘要。插件监听复用工作台的递归监听,每个订阅独立合并事件,发生缺口或重连时请求重扫。
- 本机后端解析远程语言服务器时,只接收目标平台和远端工具安装信息。Core 验证回答中的工具 ID 后,直接使用远端选定的路径和环境启动。私有远端目录与打包资源的生命周期由远端部署负责。
- 每次连接或重连都在原会话上提交 Core 按语义版本选出的当前安装版本,禁用的插件也保留其当前版本。本机可用于回滚的旧版本不进入远端保留清单。清单读取或版本选择失败时跳过清理。远端服务在发布或复用部署时取得会话共享锁,等会话进程停止后释放。只有取得独占锁才移除已卸载或升级的版本,避免另一个工作区失去仍在使用的文件。
- 连接在工作区关闭后仍保留,直到 App 退出。
- 代价:主机调用增加往返时间,远端无有效工具或连接中断时必须明确失败;缓存与长期资源都需要保留原连接身份,不能复用本机路径命中的结果。
- 当前限制:Git 原子写入仍保留 8 MiB 上限;新分块上传仅用于已批准插件文件,不代表 Git 大文件临时内容已经接入。

## 验证

- 在 Core 仓库运行 `cargo test -p lithe-remote`:协议、服务端与客户端的 Linux 真实服务测试。
- 在 Core 仓库运行 `cargo test -p lithe-remote --all-features --test run_directories`,验证完整发布、多个会话复用、按清单回收无租约版本和服务强制退出后回收废弃暂存目录。桌面端的 `TestSweepRemoteDeploymentsKeepsOnlyCurrentVersions` 检查版本排序、保留禁用插件和本机回滚包。
- 在桌面端运行 `./scripts/desktop/desktop-go.sh test ./internal/pluginservice ./internal/workbench`:覆盖元数据、路径权限边界,以及连接、重连与关闭时的上下文生命周期;真实 SSH 和 Windows 原生验收仍待完成。
- `./scripts/desktop/verify/verify-runtime-bundle-immutability.sh`。
- `./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh`。
- `./scripts/agent-notes/verify-agent-notes.sh`。
Expand Down
24 changes: 21 additions & 3 deletions desktop/internal/buildprefs/documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,31 @@ type Documents struct {
// Read reads the team document from the project and the local document from the data
// store. A document that exists but is not valid JSON is an error, not an empty document.
func Read(ctx context.Context, preferences *store.Store, root string) (Documents, error) {
return read(preferences, root, func() ([]byte, bool, error) {
snapshot, err := configfile.Capture(ctx, root, TeamFile, buildOptionsMaximumBytes)
return snapshot.Bytes(), snapshot.Exists(), err
})
}

// ReadRemote reads the team document from a captured workspace connection.
// The client root is used solely as a key into the client's preference store.
func ReadRemote(ctx context.Context, preferences *store.Store, root string, readConfiguration func(context.Context, string, int64) (*string, error)) (Documents, error) {
return read(preferences, root, func() ([]byte, bool, error) {
team, err := readConfiguration(ctx, TeamFile, buildOptionsMaximumBytes)
if err != nil || team == nil {
return nil, false, err
}
return []byte(*team), true, nil
})
}

func read(preferences *store.Store, root string, readTeam func() ([]byte, bool, error)) (Documents, error) {
docs := Documents{Team: emptyTeam, Local: EmptyLocal}
snapshot, err := configfile.Capture(ctx, root, TeamFile, buildOptionsMaximumBytes)
team, exists, err := readTeam()
if err != nil {
return docs, err
}
if snapshot.Exists() {
team := snapshot.Bytes()
if exists {
if !json.Valid(team) {
return docs, errors.New(TeamFile + ": invalid JSON")
}
Expand Down
104 changes: 104 additions & 0 deletions desktop/internal/buildprocess/remote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package buildprocess

import (
"context"
"errors"
"fmt"

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

// RemoteRunner streams a process on the workspace's captured connection.
type RemoteRunner interface {
RunRemoteProcess(context.Context, core.RemoteProcessOpen, core.RemoteProcessEvents) (core.RemoteProcessExit, error)
}

// StartRemote waits for the host to start the process. The startup request may
// cancel it until then. The lifetime context owns the running process.
func StartRemote(ctx, lifetime context.Context, host RemoteRunner, spec core.RemoteProcessOpen, output func(Stream, string)) (*RemoteProcess, error) {
return StartRemoteBytes(ctx, lifetime, host, spec, func(stream string, data []byte) {
if output != nil {
output(Stream(stream), string(data))
}
})
}

// StartRemoteBytes starts the same owned process, preserving stdout and
// stderr as bytes for framed protocols.
func StartRemoteBytes(ctx, lifetime context.Context, host RemoteRunner, spec core.RemoteProcessOpen, output func(string, []byte)) (*RemoteProcess, error) {
lifetime, cancel := context.WithCancel(lifetime)
stopStartup := context.AfterFunc(ctx, cancel)
defer stopStartup()
if err := ctx.Err(); err != nil {
cancel()
return nil, err
}
process := &RemoteProcess{cancel: cancel, done: make(chan struct{})}
started := make(chan struct{})
go func() {
defer close(process.done)
defer cancel()
exit, err := host.RunRemoteProcess(lifetime, spec, core.RemoteProcessEvents{
Started: func(processID uint64, _ int) {
process.ID = processID
stopStartup()
close(started)
},
Output: output,
})
process.err = err
if err == nil && (exit.Signal != nil || exit.ExitCode == nil || *exit.ExitCode != 0) {
process.err = &RemoteExit{Status: exit}
}
}()
select {
case <-started:
return process, nil
case <-process.done:
select {
case <-started:
return process, nil
default:
if process.err == nil {
return nil, errors.New("remote process exited without a start event")
}
return nil, process.err
}
}
}

// RemoteProcess owns a Core call. Its PID is never a local process ID.
type RemoteProcess struct {
// ID addresses this process on its captured remote session only.
ID uint64
cancel context.CancelFunc
done chan struct{}
err error
}

func (p *RemoteProcess) Wait() error { <-p.done; return p.err }
func (p *RemoteProcess) Stop() { p.cancel() }
func (p *RemoteProcess) Kill() { p.cancel() }
func (p *RemoteProcess) Pid() int { return 0 }

// RemoteExit is the status reported by the process's host.
type RemoteExit struct {
Status core.RemoteProcessExit
}

func (e *RemoteExit) ExitCode() int {
if e.Status.ExitCode == nil {
return -1
}
return *e.Status.ExitCode
}

func (e *RemoteExit) Error() string {
if e.Status.ExitCode != nil {
return fmt.Sprintf("remote process exited with code %d", *e.Status.ExitCode)
}
if e.Status.Signal != nil {
return fmt.Sprintf("remote process ended with signal %d", *e.Status.Signal)
}
return "remote process ended without an exit status"
}
32 changes: 20 additions & 12 deletions desktop/internal/core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,25 @@ type BuildProviderRequest struct {
// BuildPlan is either a command plan or a provider request. A provider plan has
// no Arguments; the plugin owns the build semantics.
type BuildPlan struct {
BuildSystemID string `json:"buildSystemID"`
Root string `json:"root"`
Arguments []string `json:"arguments"`
Environment map[string]string `json:"environment"`
WorkingDirectory string `json:"workingDirectory"`
Execution string `json:"execution"`
OptionFingerprint string `json:"optionFingerprint"`
Output string `json:"output,omitempty"`
Decoder string `json:"decoder,omitempty"`
ExecutesProjectCode bool `json:"executesProjectCode,omitempty"`
MayUseNetwork bool `json:"mayUseNetwork,omitempty"`
Provider *BuildProviderRequest `json:"provider,omitempty"`
// RequiredPackagePaths is the preflight response for a remote model
// command with package inputs and no deployed plugin directory yet.
RequiredPackagePaths []string `json:"requiredPackagePaths,omitempty"`
BuildSystemID string `json:"buildSystemID"`
Root string `json:"root"`
Arguments []string `json:"arguments"`
Environment map[string]string `json:"environment"`
WorkingDirectory string `json:"workingDirectory"`
Execution string `json:"execution"`
OptionFingerprint string `json:"optionFingerprint"`
Output string `json:"output,omitempty"`
Decoder string `json:"decoder,omitempty"`
ExecutesProjectCode bool `json:"executesProjectCode,omitempty"`
MayUseNetwork bool `json:"mayUseNetwork,omitempty"`
Provider *BuildProviderRequest `json:"provider,omitempty"`
// Results is set only for a test plan that declares a structured report.
Results *struct {
Decoder string `json:"decoder"`
} `json:"results,omitempty"`
}

// BuildDecodeModelRequest decodes a static or command model, or the result a
Expand Down Expand Up @@ -264,6 +271,7 @@ type BuildLaunch struct {
Arguments []string `json:"arguments"`
WorkingDirectory string `json:"workingDirectory"`
Environment map[string]string `json:"environment"`
Placement ProcessPlacement `json:"placement,omitempty"`
OutputEncoding string `json:"outputEncoding,omitempty"`
}

Expand Down
29 changes: 26 additions & 3 deletions desktop/internal/core/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,36 @@ type DebugEvent struct {
Result *DebugOperationResult `json:"result,omitempty"`
Breakpoint *DebugBreakpoint `json:"breakpoint,omitempty"`
// Capabilities is set on the `capabilities` event: what the adapter negotiated.
Capabilities *DebugCapabilities `json:"capabilities,omitempty"`
// StartDebugging is set on the `startDebuggingRequested` event.
Capabilities *DebugCapabilities `json:"capabilities,omitempty"`
RequestID string `json:"requestId,omitempty"`
StartDebugging *DebugStartDebugging `json:"request,omitempty"`
StartDebugging *DebugStartDebugging `json:"-"`
RunInTerminal *DebugRunInTerminal `json:"-"`
ChildSessionID string `json:"childSessionId,omitempty"`
}

// UnmarshalJSON decodes the request shared by both reverse-event variants.
func (e *DebugEvent) UnmarshalJSON(data []byte) error {
type eventFields DebugEvent
var wire struct {
eventFields
Request json.RawMessage `json:"request"`
}
if err := json.Unmarshal(data, &wire); err != nil {
return err
}
*e = DebugEvent(wire.eventFields)
if len(wire.Request) == 0 {
return nil
}
switch e.Type {
case "startDebuggingRequested":
return json.Unmarshal(wire.Request, &e.StartDebugging)
case "runInTerminalRequested":
return json.Unmarshal(wire.Request, &e.RunInTerminal)
}
return nil
}

// DebugOperationResult is the typed terminal data of one inspect or execute
// operation. Kind is Core's result tag; only the matching fields are set.
type DebugOperationResult struct {
Expand Down
28 changes: 28 additions & 0 deletions desktop/internal/core/debug_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@ type DebugStartDebugging struct {
Configuration map[string]any `json:"configuration"`
}

// DebugRunInTerminal is an adapter's request to run the debuggee in a terminal.
type DebugRunInTerminal struct {
Title string `json:"title"`
RemoteDirectory *string `json:"remoteDirectory"`
Args []string `json:"args"`
Environment []struct {
Name string `json:"name"`
Value *string `json:"value"`
} `json:"environment"`
}

// DebugRunInTerminalResponse reports the debuggee PID or a launch failure to Core.
// A zero PID is a failure and message explains it to the adapter.
func (c *Client) DebugRunInTerminalResponse(ctx context.Context, sessionID, requestID string, pid int64, message string) (DebugUpdate, error) {
var update DebugUpdate
payload := struct {
SessionID string `json:"sessionId"`
RequestID string `json:"requestId"`
Success bool `json:"success"`
ProcessID int64 `json:"processId,omitempty"`
Message string `json:"message,omitempty"`
}{sessionID, requestID, pid != 0, pid, message}
if err := c.Execute(ctx, "debug.runInTerminalResponse", payload, &update); err != nil {
return DebugUpdate{}, err
}
return update, nil
}

// DebugStartDebuggingResponse answers one startDebuggingRequested event: the
// host reports whether it opened the child session, and Core replies to the
// adapter with the original request sequence.
Expand Down
Loading
Loading