diff --git a/desktop/internal/core/remote_helpers.go b/desktop/internal/core/remote_helpers.go index 377a73418..b4cb7ef0d 100644 --- a/desktop/internal/core/remote_helpers.go +++ b/desktop/internal/core/remote_helpers.go @@ -3,6 +3,8 @@ package core import ( "context" "encoding/json" + "strconv" + "strings" ) // Connection window helpers: Core parses a quick-connect address, asks OpenSSH what it would use @@ -253,9 +255,77 @@ type RemoteWorkspaceTrustOf struct { // RemoteWorkspaceTrustState is the remote trust document as Core reads it, and the trust of the // workspace the request named. type RemoteWorkspaceTrustState struct { - Storage RemoteWorkspaceTrustStorage `json:"storage"` - ProjectCodeAllowed bool `json:"projectCodeAllowed"` - WorkspaceTrust *RemoteWorkspaceTrustOf `json:"workspaceTrust"` + Document RemoteWorkspaceTrustDocument `json:"document"` + Storage RemoteWorkspaceTrustStorage `json:"storage"` + ProjectCodeAllowed bool `json:"projectCodeAllowed"` + WorkspaceTrust *RemoteWorkspaceTrustOf `json:"workspaceTrust"` +} + +// RemoteWorkspaceTrustDocument is the validated remote trust document: the decisions of every +// connection target, sorted by target. +type RemoteWorkspaceTrustDocument struct { + Version int `json:"version"` + Targets []RemoteWorkspaceTrustTarget `json:"targets"` +} + +// The lists of one target's decisions, as RemoteWorkspaceTrustRevoke names them. +const ( + RemoteTrustTrustedWorkspaces = "trustedWorkspaces" + RemoteTrustDistrustedWorkspaces = "distrustedWorkspaces" + RemoteTrustTrustedLocations = "trustedLocations" +) + +// RemoteWorkspaceTrustTarget is the decisions on the workspaces of one connection target. Target +// is Core's key of the connection, passed back as it is; Label is the connection name shown with +// it, empty when no decision gave one. Each list holds sorted, distinct host real paths. +type RemoteWorkspaceTrustTarget struct { + Target json.RawMessage `json:"target"` + Label string `json:"label,omitempty"` + TrustedWorkspaces []string `json:"trustedWorkspaces,omitempty"` + DistrustedWorkspaces []string `json:"distrustedWorkspaces,omitempty"` + TrustedLocations []string `json:"trustedLocations,omitempty"` +} + +// Place is the route of the target's hops, outermost first: "destination:port" for an SSH hop, +// with the User option in front when the destination names no user, and "engine:container" for +// a container, joined by " → ". It is empty for a target it cannot read. +func (t RemoteWorkspaceTrustTarget) Place() string { + var target struct { + Hops []struct { + SSH *struct { + Destination string `json:"destination"` + Port *uint16 `json:"port"` + PortOption string `json:"portOption"` + User string `json:"user"` + } `json:"ssh"` + Container *struct { + Engine string `json:"engine"` + Container string `json:"container"` + } `json:"container"` + } `json:"hops"` + } + if json.Unmarshal(t.Target, &target) != nil { + return "" + } + hops := make([]string, 0, len(target.Hops)) + for _, hop := range target.Hops { + switch { + case hop.SSH != nil: + place := hop.SSH.Destination + if hop.SSH.User != "" && !strings.Contains(place, "@") { + place = hop.SSH.User + "@" + place + } + if hop.SSH.Port != nil { + place += ":" + strconv.Itoa(int(*hop.SSH.Port)) + } else if hop.SSH.PortOption != "" { + place += ":" + hop.SSH.PortOption + } + hops = append(hops, place) + case hop.Container != nil: + hops = append(hops, hop.Container.Engine+":"+hop.Container.Container) + } + } + return strings.Join(hops, " → ") } // RemoteWorkspaceTrust reads document, the remote trust source or nil, and, when sessionID is @@ -282,11 +352,21 @@ type RemoteWorkspaceTrustDecision struct { Label string `json:"label,omitempty"` } -// RemoteWorkspaceTrustPublication is the outcome of a decision. Document is the text to publish, -// nil when the decision changed nothing. +// RemoteWorkspaceTrustPublication is the outcome of a decision or a removal. Document is the text +// to publish, nil when the edit changed nothing; Decisions is the document after the edit. type RemoteWorkspaceTrustPublication struct { - Changed bool `json:"changed"` - Document *string `json:"document"` + Changed bool `json:"changed"` + Document *string `json:"document"` + Decisions RemoteWorkspaceTrustDocument `json:"decisions"` +} + +// RemoteWorkspaceTrustRevoke removes Path from the List (RemoteTrustTrustedWorkspaces, +// RemoteTrustDistrustedWorkspaces or RemoteTrustTrustedLocations) of Target's decisions, as +// RemoteWorkspaceTrustState listed them. It needs no open connection. +type RemoteWorkspaceTrustRevoke struct { + Target json.RawMessage `json:"target"` + List string `json:"list"` + Path string `json:"path"` } // EditRemoteWorkspaceTrust records decision in document, the remote trust source or nil. A @@ -299,3 +379,14 @@ func (c *Client) EditRemoteWorkspaceTrust(ctx context.Context, document *string, }{document, decision}, &publication) return publication, err } + +// RevokeRemoteWorkspaceTrust removes one entry from document, the remote trust source or nil. +// Removing an absent entry changes nothing; a target left without entries is dropped. +func (c *Client) RevokeRemoteWorkspaceTrust(ctx context.Context, document *string, revoke RemoteWorkspaceTrustRevoke) (RemoteWorkspaceTrustPublication, error) { + var publication RemoteWorkspaceTrustPublication + err := c.Execute(ctx, "remote.editWorkspaceTrust", struct { + Document *string `json:"document"` + Revoke RemoteWorkspaceTrustRevoke `json:"revoke"` + }{document, revoke}, &publication) + return publication, err +} diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 86120e7de..4c26057b7 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -2634,10 +2634,22 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.trustedLocations.empty": "No trusted locations. Lithe asks before opening each project you haven't trusted.", "desktop.trustedLocations.folders": "Trusted Folders", "desktop.trustedLocations.foldersHelp": "Projects anywhere inside these folders open trusted without asking, except the ones you chose to keep in safe mode. Changes take effect when you click Apply or OK.", - "desktop.trustedLocations.keywords": "trust trusted safe mode folder location workspace project", + "desktop.trustedLocations.keywords": "trust trusted safe mode folder location workspace project remote ssh host container", "desktop.trustedLocations.listFull": "This trust list is full (256 entries). Remove one before adding another.", "desktop.trustedLocations.pendingAdd": "To add", "desktop.trustedLocations.pendingRemove": "To remove", + "desktop.trustedLocations.remote": "Remote Workspaces", + "desktop.trustedLocations.remoteConflict": "The remote trust records changed elsewhere and were read again. Click Apply once more; the removals that still name a record were kept.", + "desktop.trustedLocations.remoteDamaged": "The remote trust records (toolchains/remote-trust.json in the settings folder) cannot be read. Repair or remove the file before removing records.", + "desktop.trustedLocations.remoteDistrusted": "Safe mode", + "desktop.trustedLocations.remoteEmpty": "No remote folder has a trust record. Lithe asks before opening a host folder you haven’t decided on.", + "desktop.trustedLocations.remoteFailed": "Could not remove the records: {reason}", + "desktop.trustedLocations.remoteHelp": "Folders on hosts you trusted or chose to keep in safe mode, recorded per connection and kept only on this machine. A record here never applies to local projects or to other hosts. After a record is removed, opening the folder asks again. Changes take effect when you click Apply or OK; a remote workspace that is already open keeps its trust until it is opened again.", + "desktop.trustedLocations.remoteLocation": "Trusted location", + "desktop.trustedLocations.remoteRemove": "Remove This Record", + "desktop.trustedLocations.remoteTarget": "remote workspace trust", + "desktop.trustedLocations.remoteTrusted": "Trusted", + "desktop.trustedLocations.remoteUnnamed": "Unnamed connection", "desktop.trustedLocations.remove": "Stop Trusting This Folder", "desktop.trustedLocations.rootLocation": "A disk or filesystem root cannot be a trusted location: it would trust every project on that disk.", "desktop.trustedLocations.target": "trusted locations", @@ -6268,10 +6280,22 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.trustedLocations.empty": "没有可信位置。打开尚未信任的项目时会先询问。", "desktop.trustedLocations.folders": "可信文件夹", "desktop.trustedLocations.foldersHelp": "这些文件夹内任意层级的项目都直接以信任方式打开,不再询问;你选择保持安全模式的项目除外。点击“应用”或“确定”后生效。", - "desktop.trustedLocations.keywords": "信任 可信 安全模式 文件夹 位置 工作区 项目", + "desktop.trustedLocations.keywords": "信任 可信 安全模式 文件夹 位置 工作区 项目 远程 主机 容器", "desktop.trustedLocations.listFull": "信任列表已满(最多 256 项),请先删除一项再添加。", "desktop.trustedLocations.pendingAdd": "待添加", "desktop.trustedLocations.pendingRemove": "待删除", + "desktop.trustedLocations.remote": "远程工作区", + "desktop.trustedLocations.remoteConflict": "远程工作区的信任记录在别处被修改过,已重新读取。请再点击一次“应用”;仍然对应现有记录的删除草稿已保留。", + "desktop.trustedLocations.remoteDamaged": "无法读取远程工作区的信任记录(设置目录中的 toolchains/remote-trust.json)。修复或删除这个文件之前不能删除记录。", + "desktop.trustedLocations.remoteDistrusted": "安全模式", + "desktop.trustedLocations.remoteEmpty": "还没有远程文件夹的信任记录。打开尚未决定的主机文件夹时会先询问。", + "desktop.trustedLocations.remoteFailed": "无法删除记录:{reason}", + "desktop.trustedLocations.remoteHelp": "你在主机上信任或选择保持安全模式的文件夹,按连接分别记录,只保存在本机;这里的记录不会作用于本机项目或其他主机。删除一条记录后,下次打开该文件夹会再次询问。点击“应用”或“确定”后生效;已经打开的远程工作区要重新打开后才按新的记录处理。", + "desktop.trustedLocations.remoteLocation": "可信位置", + "desktop.trustedLocations.remoteRemove": "删除此记录", + "desktop.trustedLocations.remoteTarget": "远程工作区信任", + "desktop.trustedLocations.remoteTrusted": "已信任", + "desktop.trustedLocations.remoteUnnamed": "未命名连接", "desktop.trustedLocations.remove": "不再信任此文件夹", "desktop.trustedLocations.rootLocation": "磁盘或文件系统的根目录不能作为可信位置,否则会信任该磁盘上的所有项目。", "desktop.trustedLocations.target": "可信位置", diff --git a/desktop/internal/remoteconn/trust.go b/desktop/internal/remoteconn/trust.go index 114690ab4..7d9e2ab25 100644 --- a/desktop/internal/remoteconn/trust.go +++ b/desktop/internal/remoteconn/trust.go @@ -21,6 +21,7 @@ import ( type TrustKernel interface { RemoteWorkspaceTrust(ctx context.Context, document *string, sessionID, workspace string) (core.RemoteWorkspaceTrustState, error) EditRemoteWorkspaceTrust(ctx context.Context, document *string, decision core.RemoteWorkspaceTrustDecision) (core.RemoteWorkspaceTrustPublication, error) + RevokeRemoteWorkspaceTrust(ctx context.Context, document *string, revoke core.RemoteWorkspaceTrustRevoke) (core.RemoteWorkspaceTrustPublication, error) } // Trust is the remote trust document with the bytes it was read from, and the trust of the @@ -78,19 +79,65 @@ func (t Trust) Decide(ctx context.Context, kernel TrustKernel, decision core.Rem } publication, err := kernel.EditRemoteWorkspaceTrust(ctx, text, decision) if err != nil { - var coreErr *core.Error - if errors.As(err, &coreErr) && coreErr.Code == core.CodeParseFailed { - err = errors.Join(ErrDamaged, err) - } - return false, err + return false, trustEditError(err) } if !publication.Changed { return false, nil } if publication.Document == nil { - return false, errors.New("remoteconn: Core changed the trust decisions without a document") + return false, errNoTrustDocument + } + return t.publish(ctx, *publication.Document) +} + +// Revoke removes each entry of revokes, in order, from the bytes t was read from, and publishes +// the result once when any removal changed it; after is the document it leads to. Nothing is +// written when Core refuses a removal or when none changes anything. A file changed since t was +// read fails with ErrConflict and writes nothing; committed reports that the new document reached +// the disk even when a later step failed. Revoking needs no open connection. +func (t Trust) Revoke(ctx context.Context, kernel TrustKernel, revokes []core.RemoteWorkspaceTrustRevoke) (after core.RemoteWorkspaceTrustDocument, committed bool, err error) { + if t.root == "" { + return t.State.Document, false, ErrUnavailable + } + text, err := t.file.Text() + if err != nil { + return t.State.Document, false, errors.Join(ErrDamaged, err) } - committed, err = t.file.Replace(ctx, []byte(*publication.Document), func() error { return t.file.Verify(ctx) }) + after, changed := t.State.Document, false + for _, revoke := range revokes { + publication, err := kernel.RevokeRemoteWorkspaceTrust(ctx, text, revoke) + if err != nil { + return t.State.Document, false, trustEditError(err) + } + after = publication.Decisions + if publication.Changed { + if publication.Document == nil { + return t.State.Document, false, errNoTrustDocument + } + text, changed = publication.Document, true + } + } + if !changed { + return after, false, nil + } + committed, err = t.publish(ctx, *text) + return after, committed, err +} + +var errNoTrustDocument = errors.New("remoteconn: Core changed the trust decisions without a document") + +// trustEditError marks Core's refusal to decode the stored document as ErrDamaged. +func trustEditError(err error) error { + var coreErr *core.Error + if errors.As(err, &coreErr) && coreErr.Code == core.CodeParseFailed { + return errors.Join(ErrDamaged, err) + } + return err +} + +// publish replaces the file with document, against the bytes t was read from. +func (t Trust) publish(ctx context.Context, document string) (committed bool, err error) { + committed, err = t.file.Replace(ctx, []byte(document), func() error { return t.file.Verify(ctx) }) if errors.Is(err, configfile.ErrConflict) { err = errors.Join(ErrConflict, err) } diff --git a/desktop/internal/remoteconn/trust_test.go b/desktop/internal/remoteconn/trust_test.go index 5d253d52e..115a85ca1 100644 --- a/desktop/internal/remoteconn/trust_test.go +++ b/desktop/internal/remoteconn/trust_test.go @@ -56,3 +56,68 @@ func TestRemoteTrustReadsWithoutWritingAndRefusesAClosedSession(t *testing.T) { t.Fatalf("a refused decision created %s: %v", root, err) } } + +// Revoking needs no connection: it removes the named records, drops a target left empty and +// writes once; removals that name nothing write nothing, and a file changed since it was read +// is refused with ErrConflict. +func TestRemoteTrustRevokeRemovesRecordsWithoutAConnection(t *testing.T) { + ctx := testContext(t) + kernel := core.NewClient() + root := filepath.Join(t.TempDir(), "preferences") + file := filepath.Join(root, "toolchains", "remote-trust.json") + if err := os.MkdirAll(filepath.Dir(file), 0o700); err != nil { + t.Fatal(err) + } + devbox := `{"hops":[{"ssh":{"destination":"devbox","port":2222,"user":"dev"}}]}` + lab := `{"hops":[{"ssh":{"destination":"lab"}},{"container":{"engine":"docker","program":"docker","container":"web"}}]}` + seed := `{"version":1,"targets":[` + + `{"target":` + devbox + `,"label":"Dev box","trustedWorkspaces":["/srv/app"],"distrustedWorkspaces":["/srv/tmp"]},` + + `{"target":` + lab + `,"trustedLocations":["/work"]}]}` + if err := os.WriteFile(file, []byte(seed), 0o600); err != nil { + t.Fatal(err) + } + trust, err := ReadTrust(ctx, kernel, root, "", "") + if err != nil { + t.Fatal(err) + } + targets := trust.State.Document.Targets + if len(targets) != 2 { + t.Fatalf("targets = %d", len(targets)) + } + if place := targets[0].Place(); targets[0].Label != "Dev box" || place != "dev@devbox:2222" { + t.Fatalf("first target: label set = %v, place matches = %v", targets[0].Label != "", place == "dev@devbox:2222") + } + if place := targets[1].Place(); place != "lab → docker:web" { + t.Fatalf("second target place matches = %v", place == "lab → docker:web") + } + + absent := []core.RemoteWorkspaceTrustRevoke{{Target: targets[0].Target, List: core.RemoteTrustTrustedLocations, Path: "/srv"}} + after, committed, err := trust.Revoke(ctx, kernel, absent) + if err != nil || committed || len(after.Targets) != 2 { + t.Fatalf("absent removal: committed = %v, targets = %d, err = %v", committed, len(after.Targets), err) + } + if text, _ := os.ReadFile(file); string(text) != seed { + t.Fatal("a removal that names no record rewrote the file") + } + + after, committed, err = trust.Revoke(ctx, kernel, []core.RemoteWorkspaceTrustRevoke{ + {Target: targets[0].Target, List: core.RemoteTrustDistrustedWorkspaces, Path: "/srv/tmp"}, + {Target: targets[1].Target, List: core.RemoteTrustTrustedLocations, Path: "/work"}, + }) + if err != nil || !committed { + t.Fatalf("removal: committed = %v, err = %v", committed, err) + } + if len(after.Targets) != 1 || len(after.Targets[0].TrustedWorkspaces) != 1 || len(after.Targets[0].DistrustedWorkspaces) != 0 { + t.Fatalf("after removal: targets = %d", len(after.Targets)) + } + reread, err := ReadTrust(ctx, kernel, root, "", "") + if err != nil || len(reread.State.Document.Targets) != 1 || reread.State.Document.Targets[0].Label != "Dev box" { + t.Fatalf("re-read: targets = %d, err = %v", len(reread.State.Document.Targets), err) + } + + // trust still holds the bytes read before the removal: writing against them is refused. + _, committed, err = trust.Revoke(ctx, kernel, []core.RemoteWorkspaceTrustRevoke{{Target: targets[0].Target, List: core.RemoteTrustTrustedWorkspaces, Path: "/srv/app"}}) + if !errors.Is(err, ErrConflict) || committed { + t.Fatalf("stale removal: committed = %v, conflict = %v", committed, errors.Is(err, ErrConflict)) + } +} diff --git a/desktop/internal/settingswindow/build_apply.go b/desktop/internal/settingswindow/build_apply.go index 0a3e16d0f..e9d097c3b 100644 --- a/desktop/internal/settingswindow/build_apply.go +++ b/desktop/internal/settingswindow/build_apply.go @@ -14,9 +14,10 @@ import ( // open with its drafts; Cancel writes nothing. const ( - applyToolchain = "toolchain:" - applyLocations = "locations:" - applyStepping = "stepping:" + applyToolchain = "toolchain:" + applyLocations = "locations:" + applyRemoteTrust = "remote-trust:" + applyStepping = "stepping:" ) // buildApply is the footer's write of the Build drafts. Only the window thread uses it. @@ -51,6 +52,10 @@ func (w *window) buildDrafts(language i18n.Language) (count int, targets []strin count += n targets = append(targets, i18n.Shared(language, "desktop.trustedLocations.target")) } + if n := t.remote.drafts(); n > 0 { + count += n + targets = append(targets, i18n.Shared(language, "desktop.trustedLocations.remoteTarget")) + } } if pending := w.steppingPending(); len(pending) > 0 { count += len(pending) @@ -80,6 +85,10 @@ func (w *window) startApply(close bool) { t.locations.readFailed = nil a.steps = append(a.steps, applyLocations) } + if t.remote.drafts() > 0 { + t.remote.readFailed = nil + a.steps = append(a.steps, applyRemoteTrust) + } } for _, id := range w.steppingPending() { a.steps = append(a.steps, applyStepping+id) @@ -125,6 +134,14 @@ func (w *window) advanceApply(toolchainFailed error, stepping steppingResult) { if w.toolchains.locations.saving { return } + case a.running == applyRemoteTrust: + if toolchainFailed != nil { + w.stopApply(toolchainFailed) + return + } + if w.toolchains.remote.saving { + return + } case strings.HasPrefix(a.running, applyStepping): if !stepping.done { return @@ -170,6 +187,28 @@ func (w *window) advanceApply(toolchainFailed error, stepping steppingResult) { } continue } + if step == applyRemoteTrust { + remote := w.toolchains.remote + if remote.busy() { + return + } + if !remote.loaded || remote.stale { + // A write failed and left the records stale: read them again and write the removals + // that still name a record. + if remote.readFailed != nil { + w.stopApply(remote.readFailed) + return + } + remote.beginLoad() + return + } + a.steps = a.steps[1:] + if remote.beginSave() { + a.running = step + return + } + continue + } a.steps = a.steps[1:] if w.beginSteppingApply(strings.TrimPrefix(step, applyStepping)) { a.running = step diff --git a/desktop/internal/settingswindow/remote_trust_state.go b/desktop/internal/settingswindow/remote_trust_state.go new file mode 100644 index 000000000..200c1f805 --- /dev/null +++ b/desktop/internal/settingswindow/remote_trust_state.go @@ -0,0 +1,253 @@ +package settingswindow + +import ( + "context" + "errors" + "slices" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteconn" + "github.com/vivaui/viva/ui" +) + +// RemoteTrustLoader reads the trust decisions this machine keeps on remote workspaces, per +// connection target, and removes them. Save removes each entry, in order, against the bytes the +// records were read from and re-reads them. All calls run off the window thread. Neither call +// needs an open connection. +type RemoteTrustLoader interface { + LoadRemoteTrust(context.Context) (remoteconn.Trust, error) + SaveRemoteTrust(context.Context, remoteconn.Trust, []core.RemoteWorkspaceTrustRevoke) (remoteconn.Trust, error) +} + +// remoteTrustState is the Remote Workspaces card of the Trusted Locations page: the records Core +// read from the remote trust document (toolchains/remote-trust.json in the preference directory), +// the removals not applied yet and the requests that read and write them. Only the window thread +// touches the fields; each request is an Effect whose key changes when it is made, taken at the +// start of a paint. +// +// The document is its own file, written by project windows when a remote folder is trusted or +// kept in safe mode, so a write here is checked against the bytes it was read from and refused +// with remoteconn.ErrConflict when a project window wrote in between; the card reads the records +// again and keeps the removals that still name one. +type remoteTrustState struct { + loader RemoteTrustLoader + + loadEffect *ui.EffectState[remoteconn.Trust, int] + loadKey int + loading bool + loaded bool + // stale asks for a re-read before the card shows or writes again. + stale bool + readFailed error + source remoteconn.Trust + + // revokes are the removals in the order the user made them. + revokes []core.RemoteWorkspaceTrustRevoke + + saveEffect *ui.EffectState[remoteconn.Trust, int] + saveKey int + saveSource remoteconn.Trust + saveRevokes []core.RemoteWorkspaceTrustRevoke + saving bool + // failed is the last write's error. + failed error +} + +// remoteTrustEntry is one record of a target: a folder in one of its three lists. +type remoteTrustEntry struct { + list string + path string + revoked bool +} + +// remoteTrustGroup is a connection target's records, in the order the card lists them. +type remoteTrustGroup struct { + target core.RemoteWorkspaceTrustTarget + entries []remoteTrustEntry +} + +func newRemoteTrustState(loader ToolchainLoader) *remoteTrustState { + r := &remoteTrustState{} + remote, ok := loader.(RemoteTrustLoader) + if !ok { + return r + } + r.loader = remote + r.loadEffect = ui.NewEffect[remoteconn.Trust, int](func(ctx context.Context) (remoteconn.Trust, error) { + return remote.LoadRemoteTrust(ctx) + }) + r.saveEffect = ui.NewEffect[remoteconn.Trust, int](func(ctx context.Context) (remoteconn.Trust, error) { + return remote.SaveRemoteTrust(ctx, r.saveSource, r.saveRevokes) + }) + return r +} + +func (r *remoteTrustState) available() bool { return r != nil && r.loader != nil } + +func (r *remoteTrustState) busy() bool { return r.available() && (r.loading || r.saving) } + +// ensureLoaded reads the records when the card shows and there are none, or they went stale. +func (r *remoteTrustState) ensureLoaded() { + if !r.available() || r.busy() || r.readFailed != nil { + return + } + if !r.loaded || r.stale { + r.beginLoad() + } +} + +func (r *remoteTrustState) beginLoad() { + r.loadKey++ + r.loading, r.readFailed = true, nil +} + +// reload reads the records again; the removals that still name one stay. +func (r *remoteTrustState) reload() { + if !r.available() || r.busy() { + return + } + r.failed = nil + r.beginLoad() +} + +// toggle drafts removing the record, or drops the draft that already removes it. +func (r *remoteTrustState) toggle(target core.RemoteWorkspaceTrustTarget, list, path string) { + if !r.available() || !r.loaded || r.busy() { + return + } + r.failed = nil + revoke := core.RemoteWorkspaceTrustRevoke{Target: target.Target, List: list, Path: path} + if index := slices.IndexFunc(r.revokes, func(other core.RemoteWorkspaceTrustRevoke) bool { return sameRevoke(other, revoke) }); index >= 0 { + r.revokes = slices.Delete(r.revokes, index, index+1) + return + } + r.revokes = append(r.revokes, revoke) +} + +// sameRevoke compares targets as Core wrote them; the card passes them back unchanged. +func sameRevoke(a, b core.RemoteWorkspaceTrustRevoke) bool { + return a.List == b.List && a.Path == b.Path && string(a.Target) == string(b.Target) +} + +// groups are the card's records: each target in Core's order, its trusted workspaces, then the +// ones kept in safe mode, then its trusted locations, each marked when a removal is drafted. +func (r *remoteTrustState) groups() []remoteTrustGroup { + if !r.available() || !r.loaded { + return nil + } + targets := r.source.State.Document.Targets + groups := make([]remoteTrustGroup, 0, len(targets)) + for _, target := range targets { + group := remoteTrustGroup{target: target} + for _, list := range []struct { + name string + paths []string + }{ + {core.RemoteTrustTrustedWorkspaces, target.TrustedWorkspaces}, + {core.RemoteTrustDistrustedWorkspaces, target.DistrustedWorkspaces}, + {core.RemoteTrustTrustedLocations, target.TrustedLocations}, + } { + for _, path := range list.paths { + revoke := core.RemoteWorkspaceTrustRevoke{Target: target.Target, List: list.name, Path: path} + revoked := slices.ContainsFunc(r.revokes, func(other core.RemoteWorkspaceTrustRevoke) bool { return sameRevoke(other, revoke) }) + group.entries = append(group.entries, remoteTrustEntry{list: list.name, path: path, revoked: revoked}) + } + } + groups = append(groups, group) + } + return groups +} + +func (r *remoteTrustState) drafts() int { + if !r.available() { + return 0 + } + return len(r.revokes) +} + +// keepListed drops the removals whose record the records just read no longer hold. +func (r *remoteTrustState) keepListed() { + r.revokes = slices.DeleteFunc(r.revokes, func(revoke core.RemoteWorkspaceTrustRevoke) bool { + for _, group := range r.groups() { + if string(group.target.Target) != string(revoke.Target) { + continue + } + for _, entry := range group.entries { + if entry.list == revoke.List && entry.path == revoke.Path { + return false + } + } + } + return true + }) +} + +// beginSave writes the removals against the records they were made on. Stale records are read +// again first; the caller tries again once that read is taken. +func (r *remoteTrustState) beginSave() bool { + if !r.available() || !r.loaded || r.stale || r.busy() || r.drafts() == 0 { + return false + } + r.saveSource, r.saveRevokes = r.source, slices.Clone(r.revokes) + r.saveKey++ + r.saving, r.failed = true, nil + return true +} + +// take applies the card's finished requests and reports a write that failed, so the footer's +// apply stops. +func (r *remoteTrustState) take() (saveFailed error) { + if !r.available() { + return nil + } + if source, err, ok := r.loadEffect.Take(); ok { + r.loading = false + if err != nil { + r.readFailed = err + } else { + r.source, r.loaded, r.stale = source, true, false + r.keepListed() + } + } + if source, err, ok := r.saveEffect.Take(); ok { + r.saving = false + switch { + case err != nil: + // A project window may have decided on a remote folder meanwhile + // (remoteconn.ErrConflict), or the write reached the disk before a later step failed: + // read the records again and keep the removals that still name one. + r.failed, r.stale, saveFailed = err, true, err + default: + r.source, r.loaded, r.stale = source, true, false + r.revokes = nil + } + } + return saveFailed +} + +// remoteTrustFailureMessage says why the records could not be read or written. Core's message +// may name host paths; it is shown, and the loader logs only its code. +func remoteTrustFailureMessage(language i18n.Language, err error) string { + switch { + case errors.Is(err, remoteconn.ErrConflict): + return i18n.Shared(language, "desktop.trustedLocations.remoteConflict") + case errors.Is(err, remoteconn.ErrDamaged): + return i18n.Shared(language, "desktop.trustedLocations.remoteDamaged") + } + return i18n.SharedFormat(language, "desktop.trustedLocations.remoteFailed", map[string]string{"reason": err.Error()}) +} + +// declare keeps the requests that are out alive in every paint, so leaving the page does not +// cancel a write. +func (r *remoteTrustState) declare(c ui.C) { + if !r.available() { + return + } + if r.loadKey != 0 { + ui.Effect(c.Part("remote-trust-load"), r.loadEffect, r.loadKey) + } + if r.saveKey != 0 { + ui.Effect(c.Part("remote-trust-save"), r.saveEffect, r.saveKey) + } +} diff --git a/desktop/internal/settingswindow/remote_trust_state_test.go b/desktop/internal/settingswindow/remote_trust_state_test.go new file mode 100644 index 000000000..de0756c5e --- /dev/null +++ b/desktop/internal/settingswindow/remote_trust_state_test.go @@ -0,0 +1,272 @@ +package settingswindow + +import ( + "context" + "encoding/json" + "errors" + "slices" + "sync" + "sync/atomic" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteconn" + "github.com/vivaui/viva/gfx" +) + +// fakeRemoteTrustLoader keeps remote trust records the way Core edits them: a removal takes the +// path out of the target's list and drops a target left empty, and a removal naming nothing +// changes nothing. A write made on records other than the ones it holds is refused with +// remoteconn.ErrConflict, as a file changed since it was read is. +type fakeRemoteTrustLoader struct { + fakeLocationsLoader + trustMu sync.Mutex + document core.RemoteWorkspaceTrustDocument + // trustLoads and trustSaves count the requests; the window makes them on effect goroutines. + trustLoads atomic.Int32 + trustSaves atomic.Int32 +} + +func (f *fakeRemoteTrustLoader) LoadRemoteTrust(context.Context) (remoteconn.Trust, error) { + f.trustLoads.Add(1) + f.trustMu.Lock() + defer f.trustMu.Unlock() + return remoteconn.Trust{State: core.RemoteWorkspaceTrustState{Document: cloneTrustDocument(f.document)}}, nil +} + +func (f *fakeRemoteTrustLoader) SaveRemoteTrust(_ context.Context, source remoteconn.Trust, revokes []core.RemoteWorkspaceTrustRevoke) (remoteconn.Trust, error) { + f.trustSaves.Add(1) + f.trustMu.Lock() + defer f.trustMu.Unlock() + if trustText(source.State.Document) != trustText(f.document) { + return source, remoteconn.ErrConflict + } + for _, revoke := range revokes { + f.document = revokeTrust(f.document, revoke) + } + return remoteconn.Trust{State: core.RemoteWorkspaceTrustState{Document: cloneTrustDocument(f.document)}}, nil +} + +func (f *fakeRemoteTrustLoader) set(targets ...core.RemoteWorkspaceTrustTarget) { + f.trustMu.Lock() + defer f.trustMu.Unlock() + f.document = core.RemoteWorkspaceTrustDocument{Version: 1, Targets: targets} +} + +func (f *fakeRemoteTrustLoader) stored() core.RemoteWorkspaceTrustDocument { + f.trustMu.Lock() + defer f.trustMu.Unlock() + return cloneTrustDocument(f.document) +} + +func trustText(document core.RemoteWorkspaceTrustDocument) string { + text, err := json.Marshal(document) + if err != nil { + panic(err) + } + return string(text) +} + +func cloneTrustDocument(document core.RemoteWorkspaceTrustDocument) core.RemoteWorkspaceTrustDocument { + var clone core.RemoteWorkspaceTrustDocument + if err := json.Unmarshal([]byte(trustText(document)), &clone); err != nil { + panic(err) + } + return clone +} + +func revokeTrust(document core.RemoteWorkspaceTrustDocument, revoke core.RemoteWorkspaceTrustRevoke) core.RemoteWorkspaceTrustDocument { + targets := document.Targets[:0:0] + for _, target := range document.Targets { + if string(target.Target) == string(revoke.Target) { + drop := func(paths []string) []string { + return slices.DeleteFunc(slices.Clone(paths), func(path string) bool { return path == revoke.Path }) + } + switch revoke.List { + case core.RemoteTrustTrustedWorkspaces: + target.TrustedWorkspaces = drop(target.TrustedWorkspaces) + case core.RemoteTrustDistrustedWorkspaces: + target.DistrustedWorkspaces = drop(target.DistrustedWorkspaces) + case core.RemoteTrustTrustedLocations: + target.TrustedLocations = drop(target.TrustedLocations) + } + if len(target.TrustedWorkspaces)+len(target.DistrustedWorkspaces)+len(target.TrustedLocations) == 0 { + continue + } + } + targets = append(targets, target) + } + document.Targets = targets + return document +} + +const ( + devboxTarget = `{"hops":[{"ssh":{"destination":"devbox","port":2222,"user":"dev"}}]}` + labTarget = `{"hops":[{"ssh":{"destination":"lab"}},{"container":{"engine":"docker","program":"docker","container":"web"}}]}` +) + +func devboxRecords() core.RemoteWorkspaceTrustTarget { + return core.RemoteWorkspaceTrustTarget{ + Target: json.RawMessage(devboxTarget), + Label: "Dev box", + TrustedWorkspaces: []string{"/srv/app"}, + DistrustedWorkspaces: []string{"/srv/tmp"}, + } +} + +func labRecords() core.RemoteWorkspaceTrustTarget { + return core.RemoteWorkspaceTrustTarget{Target: json.RawMessage(labTarget), TrustedLocations: []string{"/work"}} +} + +// remoteTrustWindow opens a settings window on the Trusted Locations page with loader and waits +// for both cards. +func remoteTrustWindow(t *testing.T, loader *fakeRemoteTrustLoader) (*window, *windowDriver, *remoteTrustState) { + t.Helper() + w := newWindow(NewController(Options{Toolchains: loader}), Values{}) + w.sess.page = pageTrustedLocations + d := openWindow(t, w) + r := w.toolchains.remote + d.until("the remote trust records to load", func() bool { + return r.loaded && !r.busy() && w.toolchains.locations.loaded && !w.toolchains.locations.busy() + }) + d.pump() + return w, d, r +} + +// removeRemoteRecords clicks the remove buttons of the listed rows, counted from 0 in the order +// the card draws them. A removed row keeps its height, so the other buttons stay where they were. +func (d *windowDriver) removeRemoteRecords(rows ...int) { + d.t.Helper() + label := i18n.Shared(d.w.marketLanguage(), "desktop.trustedLocations.remoteRemove") + var buttons []gfx.Hit + for _, hit := range d.driver.Snapshot().Hits { + if hit.Label == label && !hit.IsLabel && !hit.Backdrop && !hit.ID.IsZero() { + buttons = append(buttons, hit) + } + } + for _, row := range rows { + if row >= len(buttons) { + d.t.Fatalf("row %d has no remove button (%d buttons)", row, len(buttons)) + } + d.clickHit(buttons[row]) + } + d.pump() +} + +func revokedEntries(r *remoteTrustState) (revoked []string) { + for _, group := range r.groups() { + for _, entry := range group.entries { + if entry.revoked { + revoked = append(revoked, entry.list+" "+entry.path) + } + } + } + return revoked +} + +// The card names each connection by its label, or by its host when it has none, and lists its +// records under it. Opening the page writes nothing; a removal is a draft marked in the list that +// can be undone, and Apply writes it. +func TestRemoteTrustRecordsAreListedDraftedAndApplied(t *testing.T) { + loader := &fakeRemoteTrustLoader{} + loader.set(devboxRecords(), labRecords()) + w, d, r := remoteTrustWindow(t, loader) + for _, shown := range []string{"Dev box", "dev@devbox:2222", "lab → docker:web", "/srv/app", "/srv/tmp", "/work", + en("desktop.trustedLocations.remoteTrusted"), en("desktop.trustedLocations.remoteDistrusted"), en("desktop.trustedLocations.remoteLocation")} { + if !d.text(shown) { + t.Fatalf("the card does not show an expected text (%d chars)", len(shown)) + } + } + if loader.trustSaves.Load() != 0 { + t.Fatal("opening the page wrote the remote trust records") + } + + // The rows are drawn in order: the first button removes /srv/app, the second /srv/tmp. + d.clickHit(d.first(en("desktop.trustedLocations.remoteRemove"))) + d.pump() + if got := revokedEntries(r); !slices.Equal(got, []string{core.RemoteTrustTrustedWorkspaces + " /srv/app"}) || r.drafts() != 1 { + t.Fatalf("revoked = %d entries, drafts = %d", len(got), r.drafts()) + } + if !d.text(en("desktop.trustedLocations.pendingRemove")) { + t.Fatal("the removal is not tagged") + } + d.click(en("desktop.buildSettings.undoChange")) + d.pump() + if r.drafts() != 0 { + t.Fatalf("drafts after undo = %d", r.drafts()) + } + + d.removeRemoteRecords(1, 2) + d.applyBuild() + if w.apply.failed != nil { + t.Fatalf("apply failed: %v", w.apply.failed) + } + stored := loader.stored() + if len(stored.Targets) != 1 || !slices.Equal(stored.Targets[0].TrustedWorkspaces, []string{"/srv/app"}) || len(stored.Targets[0].DistrustedWorkspaces) != 0 { + t.Fatalf("stored targets = %d", len(stored.Targets)) + } + if r.drafts() != 0 || len(r.groups()) != 1 { + t.Fatalf("after apply: drafts = %d, groups = %d", r.drafts(), len(r.groups())) + } + if d.text("lab → docker:web") { + t.Fatal("the emptied connection is still listed") + } +} + +// A project window that changes the records while removals are drafted makes Apply fail with a +// conflict: the card reads the records again, keeps the removals that still name one and drops +// the rest, and the next Apply writes them. +func TestRemoteTrustConflictReadsAgainAndKeepsTheListedRemovals(t *testing.T) { + loader := &fakeRemoteTrustLoader{} + loader.set(devboxRecords(), labRecords()) + w, d, r := remoteTrustWindow(t, loader) + d.removeRemoteRecords(1, 2) + + // Elsewhere: /work is no longer trusted and another folder is. + changed := labRecords() + changed.TrustedLocations = nil + changed.TrustedWorkspaces = []string{"/work/api"} + loader.set(devboxRecords(), changed) + before := loader.trustLoads.Load() + d.applyBuild() + if !errors.Is(w.apply.failed, remoteconn.ErrConflict) { + t.Fatalf("footer failure is a conflict = %v", errors.Is(w.apply.failed, remoteconn.ErrConflict)) + } + d.until("the records to be read again", func() bool { return loader.trustLoads.Load() > before && r.loaded && !r.busy() && !r.stale }) + d.pump() + if got := revokedEntries(r); !slices.Equal(got, []string{core.RemoteTrustDistrustedWorkspaces + " /srv/tmp"}) || r.drafts() != 1 { + t.Fatalf("after the re-read: revoked = %d entries, drafts = %d", len(got), r.drafts()) + } + if !d.showsWrapped(en("desktop.trustedLocations.remoteConflict")) { + t.Fatal("the conflict is not on the page") + } + + d.applyBuild() + if w.apply.failed != nil { + t.Fatalf("second apply failed: %v", w.apply.failed) + } + stored := loader.stored() + if len(stored.Targets) != 2 || len(stored.Targets[0].DistrustedWorkspaces) != 0 || !slices.Equal(stored.Targets[1].TrustedWorkspaces, []string{"/work/api"}) { + t.Fatalf("stored targets = %d", len(stored.Targets)) + } + if r.failed != nil || r.drafts() != 0 { + t.Fatalf("after the second apply: failed = %v, drafts = %d", r.failed != nil, r.drafts()) + } +} + +// Without records the card says so; a loader that keeps no remote records shows no card. +func TestRemoteTrustCardShowsOnlyWithALoader(t *testing.T) { + loader := &fakeRemoteTrustLoader{} + loader.set() + _, d, _ := remoteTrustWindow(t, loader) + if !d.showsWrapped(en("desktop.trustedLocations.remoteEmpty")) || !d.text(en("desktop.trustedLocations.remote")) { + t.Fatal("the empty remote card is not shown") + } + + local := &fakeLocationsLoader{} + _, d, _ = locationsWindow(t, local, pageTrustedLocations) + if d.text(en("desktop.trustedLocations.remote")) { + t.Fatal("a loader without remote records shows the remote card") + } +} diff --git a/desktop/internal/settingswindow/toolchains_state.go b/desktop/internal/settingswindow/toolchains_state.go index 24b9f31ef..74e0668a4 100644 --- a/desktop/internal/settingswindow/toolchains_state.go +++ b/desktop/internal/settingswindow/toolchains_state.go @@ -390,6 +390,9 @@ type toolchainState struct { // locations is the Trusted Locations page, which writes the same catalog file. locations *trustedLocationsState + // remote is the Remote Workspaces card of the same page. Its document is a file of its own, + // so busy() does not include its requests. + remote *remoteTrustState // The list's query and the page's selection. query string @@ -409,6 +412,7 @@ func newToolchainState(loader ToolchainLoader) *toolchainState { viewer, _ := loader.(ToolchainViewer) t.view, t.search = newToolchainProjection(viewer), newToolchainProjection(viewer) t.locations = newTrustedLocationsState(t, loader) + t.remote = newRemoteTrustState(loader) if loader == nil { return t } @@ -680,6 +684,9 @@ func (t *toolchainState) take() (saveFailed error) { if err := t.locations.take(); err != nil && saveFailed == nil { saveFailed = err } + if err := t.remote.take(); err != nil && saveFailed == nil { + saveFailed = err + } t.view.take() t.search.take() return saveFailed @@ -743,6 +750,7 @@ func (t *toolchainState) declare(c ui.C) { ui.Effect(c, t.runtimeEffect, t.runtimeKey) } t.locations.declare(c) + t.remote.declare(c) t.view.declare(c.Part("toolchain-view")) t.search.declare(c.Part("toolchain-search")) } diff --git a/desktop/internal/settingswindow/trusted_locations_view.go b/desktop/internal/settingswindow/trusted_locations_view.go index ee203c08b..70be4c3ad 100644 --- a/desktop/internal/settingswindow/trusted_locations_view.go +++ b/desktop/internal/settingswindow/trusted_locations_view.go @@ -4,6 +4,7 @@ import ( "errors" "path/filepath" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/icons" "github.com/vivaui/viva/app" @@ -16,13 +17,132 @@ import ( // Core checks at once and the footer's Apply writes with the other Build drafts. func (w *window) trustedLocationsPage(c ui.C) { l := w.toolchains.locations + remote := w.toolchains.remote language := w.marketLanguage() l.ensureLoaded() + remote.ensureLoaded() w.pageScroll(c, pageTrustedLocations, func() { - w.card(c, i18n.Shared(language, "desktop.trustedLocations.folders"), i18n.Shared(language, "desktop.trustedLocations.foldersHelp"), func() { - w.trustedLocationsList(c.Part("list"), language, l) + if l.available() { + w.card(c, i18n.Shared(language, "desktop.trustedLocations.folders"), i18n.Shared(language, "desktop.trustedLocations.foldersHelp"), func() { + w.trustedLocationsList(c.Part("list"), language, l) + }) + w.trustedLocationsNotices(c.Part("notices"), language, l) + } + if remote.available() { + w.card(c.Part("remote"), i18n.Shared(language, "desktop.trustedLocations.remote"), i18n.Shared(language, "desktop.trustedLocations.remoteHelp"), func() { + w.remoteTrustList(c.Part("remote-list"), language, remote) + }) + w.remoteTrustNotices(c.Part("remote-notices"), language, remote) + } + }) +} + +// remoteTrustList is each connection's records under its name and host: the folders trusted, +// kept in safe mode and trusted as locations, each with the button that removes it, marked when a +// draft removes it. Nothing here adds a record: a remote folder is decided on when it opens. +func (w *window) remoteTrustList(c ui.C, language i18n.Language, r *remoteTrustState) { + p := &w.pal + if !r.loaded { + if r.readFailed == nil { + ui.Row(c).FillWidth().Height(28).Items(ui.Center).Children(func() { + ui.Text(c, i18n.Shared(language, "desktop.toolchains.loading")).FontSize(12).Color(p.muted) + }) + } + return + } + busy := r.busy() + groups := r.groups() + if len(groups) == 0 { + ui.Row(c).FillWidth().MinHeight(28).PadY(4).Items(ui.Center).Children(func() { + ui.Wrap(c, i18n.Shared(language, "desktop.trustedLocations.remoteEmpty")).FontSize(12).Color(p.muted).Grow(1).Shrink(1).MinWidth(0) + }) + return + } + for index, group := range groups { + g := c.Key(string(group.target.Target)) + if index > 0 { + ui.Row(g.Part("gap")).FillWidth().Height(1).Shrink(0).Background(p.line) + } + place := group.target.Place() + name := group.target.Label + if name == "" { + name, place = place, "" + } + if name == "" { + name = i18n.Shared(language, "desktop.trustedLocations.remoteUnnamed") + } + ui.Row(g.Part("head")).FillWidth().MinWidth(0).Height(28).Gap(8).Items(ui.Center).Children(func() { + ui.Icon(g, icons.Server).Size(14, 14).Color(p.muted).Shrink(0) + ui.Text(g, name).FontSize(12).Weight(gfx.WeightSemibold).Color(p.text).Shrink(1).MinWidth(0).Ellipsis() + if place != "" { + ui.Text(g.Part("place"), place).FontSize(12).Mono().Color(p.muted).Grow(1).Shrink(1).MinWidth(0).Ellipsis() + } }) - w.trustedLocationsNotices(c.Part("notices"), language, l) + for _, entry := range group.entries { + k := g.Key(entry.list + "\x00" + entry.path) + ui.Row(k).FillWidth().MinWidth(0).Height(28).PadLeft(22).Gap(8).Items(ui.Center).Children(func() { + words := p.text + if entry.revoked { + words = p.subtle + } + switch entry.list { + case core.RemoteTrustDistrustedWorkspaces: + w.tag(k.Part("kind"), tagWarn, i18n.Shared(language, "desktop.trustedLocations.remoteDistrusted")) + case core.RemoteTrustTrustedLocations: + w.tag(k.Part("kind"), tagBlue, i18n.Shared(language, "desktop.trustedLocations.remoteLocation")) + default: + w.tag(k.Part("kind"), tagGreen, i18n.Shared(language, "desktop.trustedLocations.remoteTrusted")) + } + // The tooltip shows a path the row's width cuts; it needs an element with an identity. + path := k.Part("path") + ui.Row(path).Grow(1).Shrink(1).MinWidth(0).Items(ui.Center). + HitWith(ui.ID(path), entry.path, gfx.HitOptions{Role: gfx.RoleGroup}).Tooltip(entry.path).Children(func() { + ui.Text(path, entry.path).FontSize(12).Mono().Color(words).Grow(1).Shrink(1).MinWidth(0).Ellipsis() + }) + if entry.revoked { + w.tag(k.Part("mark"), tagErr, i18n.Shared(language, "desktop.trustedLocations.pendingRemove")) + if w.button(k.Part("undo"), buttonLinkSmall, i18n.Shared(language, "desktop.buildSettings.undoChange"), busy) { + r.toggle(group.target, entry.list, entry.path) + } + return + } + if w.iconButton(k.Part("remove"), icons.X, i18n.Shared(language, "desktop.trustedLocations.remoteRemove"), busy) { + r.toggle(group.target, entry.list, entry.path) + } + }) + } + } +} + +// remoteTrustNotices are the read's and the write's failures, and the write that is out. +func (w *window) remoteTrustNotices(c ui.C, language i18n.Language, r *remoteTrustState) { + if r.readFailed == nil && r.failed == nil && !r.saving { + return + } + ui.Column(c).FillWidth().Shrink(0).Gap(8).Children(func() { + if r.readFailed != nil { + message := remoteTrustFailureMessage(language, r.readFailed) + w.box(c.Part("load-failed"), boxErr, func(words gfx.Color) { + boxIcon(c, icons.CircleX, words) + boxText(c, message, words) + if w.button(c.Part("load-retry"), buttonSmall, i18n.Shared(language, "desktop.toolchains.reload"), r.busy()) { + r.reload() + } + }) + } + if r.failed != nil { + message := remoteTrustFailureMessage(language, r.failed) + w.box(c.Part("failed"), boxErr, func(words gfx.Color) { + boxIcon(c, icons.CircleX, words) + boxText(c, message, words) + }) + } + if r.saving { + w.box(c.Part("busy"), boxInfo, func(words gfx.Color) { + boxIcon(c, icons.Clock, words) + boxText(c, i18n.Shared(language, "desktop.toolchains.saving"), words) + }) + } }) } diff --git a/desktop/internal/settingswindow/trusted_locations_visual_test.go b/desktop/internal/settingswindow/trusted_locations_visual_test.go index de897f79a..5e163c55c 100644 --- a/desktop/internal/settingswindow/trusted_locations_visual_test.go +++ b/desktop/internal/settingswindow/trusted_locations_visual_test.go @@ -3,16 +3,20 @@ package settingswindow import ( + "encoding/json" "os" "path/filepath" "testing" + "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/vivaui/viva/headless" ) -// TestVisualTrustedLocations renders the Trusted Locations page under Tools: the saved list, then a draft that adds a folder, one that removes a folder and Core's refusal -// of a filesystem root. The folders are fictional; the loader is the tests' fake. +// TestVisualTrustedLocations renders the Trusted Locations page under Tools: the saved list with +// the remote workspace records under their connections, then a draft that adds a folder, one that +// removes a folder, Core's refusal of a filesystem root and a removed remote record. The folders +// and hosts are fictional; the loader is the tests' fake. func TestVisualTrustedLocations(t *testing.T) { out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") if out == "" { @@ -29,8 +33,17 @@ func TestVisualTrustedLocations(t *testing.T) { for _, language := range []i18n.Language{i18n.English, i18n.Chinese} { for _, theme := range []string{"dark", "light"} { t.Run(language.Code()+"/"+theme, func(t *testing.T) { - loader := &fakeLocationsLoader{} - loader.set(work, studies) + loader := &fakeRemoteTrustLoader{} + loader.fakeLocationsLoader.set(work, studies) + loader.set(core.RemoteWorkspaceTrustTarget{ + Target: json.RawMessage(`{"hops":[{"ssh":{"destination":"build.example.com","user":"dev"}}]}`), + Label: "Build server", + TrustedWorkspaces: []string{"/home/dev/services/api"}, + DistrustedWorkspaces: []string{"/home/dev/downloads/sample"}, + }, core.RemoteWorkspaceTrustTarget{ + Target: json.RawMessage(`{"hops":[{"ssh":{"destination":"lab.example.com","port":2222}},{"container":{"engine":"docker","program":"docker","container":"web"}}]}`), + TrustedLocations: []string{"/workspace"}, + }) w := newWindow(NewController(Options{ Text: func() *i18n.Messages { return i18n.For(language) }, Language: func() i18n.Language { return language }, SystemLanguage: language, SystemDark: func() bool { return theme == "dark" }, @@ -43,8 +56,8 @@ func TestVisualTrustedLocations(t *testing.T) { } t.Cleanup(session.Close) d := &windowDriver{t: t, w: w, driver: session.Driver()} - l := w.toolchains.locations - d.until("the trusted folders to load", func() bool { return l.loaded && !l.busy() }) + l, r := w.toolchains.locations, w.toolchains.remote + d.until("the trusted folders to load", func() bool { return l.loaded && !l.busy() && r.loaded && !r.busy() }) d.pump() shot := func(state string) { t.Helper() @@ -54,13 +67,14 @@ func TestVisualTrustedLocations(t *testing.T) { } // Pump paints only what was invalidated, so wait for the list's first folder to be // on the screen. - d.until("the saved list to be painted", func() bool { return d.text(work) }) + d.until("the saved list to be painted", func() bool { return d.text(work) && d.text("Build server") }) shot("list") d.changeLocation(l, sandbox, true) d.changeLocation(l, studies, false) d.changeLocation(l, "/", true) - if l.drafts() != 2 || l.refused == nil { - t.Fatalf("drafts = %d, refused = %v", l.drafts(), l.refused) + d.removeRemoteRecords(1) + if l.drafts() != 2 || l.refused == nil || r.drafts() != 1 { + t.Fatalf("drafts = %d, refused = %v, remote drafts = %d", l.drafts(), l.refused, r.drafts()) } shot("drafts") }) diff --git a/desktop/internal/settingswindow/window_view.go b/desktop/internal/settingswindow/window_view.go index 205f20c31..fa5fbd35a 100644 --- a/desktop/internal/settingswindow/window_view.go +++ b/desktop/internal/settingswindow/window_view.go @@ -326,7 +326,7 @@ func (w *window) navTrailing(c ui.C, r row) { dot(c, 7, w.bp.accent) } case r.page == pageTrustedLocations: - if w.toolchains.locations.drafts() > 0 { + if w.toolchains.locations.drafts() > 0 || w.toolchains.remote.drafts() > 0 { dot(c, 7, w.bp.accent) } } @@ -381,7 +381,7 @@ func (w *window) content(c ui.C) { w.debuggersPage(c) case w.sess.page == pageConsole: w.consolePage(c) - case w.sess.page == pageTrustedLocations && w.toolchains.locations.available(): + case w.sess.page == pageTrustedLocations && (w.toolchains.locations.available() || w.toolchains.remote.available()): w.trustedLocationsPage(c) case w.sess.page == pageTerminal && w.ctrl.opts.TerminalShells != nil: w.terminalPage(c) diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 6cfda9971..8ebf4cc12 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -229,6 +229,7 @@ type Kernel interface { RemoteMottyHosts(ctx context.Context, configDirectory string, document *string) (core.RemoteMottyHosts, error) RemoteWorkspaceTrust(ctx context.Context, document *string, sessionID, workspace string) (core.RemoteWorkspaceTrustState, error) EditRemoteWorkspaceTrust(ctx context.Context, document *string, decision core.RemoteWorkspaceTrustDecision) (core.RemoteWorkspaceTrustPublication, error) + RevokeRemoteWorkspaceTrust(ctx context.Context, document *string, revoke core.RemoteWorkspaceTrustRevoke) (core.RemoteWorkspaceTrustPublication, error) RemoteRunTerminal(ctx context.Context, sessionID string, open core.RemoteTerminalOpen, events core.RemoteTerminalEvents) (core.RemoteTerminalExit, error) RemoteRunWatch(ctx context.Context, sessionID, root string, excludeNames []string, events core.RemoteWatchEvents) error RemoteTerminalWrite(ctx context.Context, sessionID string, terminalID uint64, data []byte) (bool, error) diff --git a/desktop/internal/workbench/git.go b/desktop/internal/workbench/git.go index 1d58d5a78..0c3844276 100644 --- a/desktop/internal/workbench/git.go +++ b/desktop/internal/workbench/git.go @@ -24,7 +24,7 @@ type gitState struct { // (remoteRepositoryAbove). remoteAbove bool status core.GitStatus - err error + err error // tree is the same answer indexed for the project tree, which colors the rows of the // changed paths. It is rebuilt whenever the status is replaced. tree treeStatus diff --git a/desktop/internal/workbench/settings_toolchains.go b/desktop/internal/workbench/settings_toolchains.go index ace6741e5..743fa7cfc 100644 --- a/desktop/internal/workbench/settings_toolchains.go +++ b/desktop/internal/workbench/settings_toolchains.go @@ -6,6 +6,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginruntime" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteconn" "github.com/1lck/Lithe-IDEA/desktop/internal/toolchain" ) @@ -102,6 +103,24 @@ func (s settingsToolchains) SaveTrustedLocations(ctx context.Context, locations return updated, nil } +// LoadRemoteTrust reads the trust decisions this machine keeps on remote workspaces. It needs no +// connection; Core's message may name host paths, so only its code is logged. +func (s settingsToolchains) LoadRemoteTrust(ctx context.Context) (trust remoteconn.Trust, err error) { + defer func() { s.recordFailure(ctx, "remote_trust_settings_load", documentLogError(err)) }() + return remoteconn.ReadTrust(ctx, s.app.kernel, s.app.globalToolchainRoot(), "", "") +} + +// SaveRemoteTrust removes the drafted records against the bytes trust was read from and reads +// them again. A remote workspace that is open keeps the trust it opened with until it opens again. +func (s settingsToolchains) SaveRemoteTrust(ctx context.Context, trust remoteconn.Trust, revokes []core.RemoteWorkspaceTrustRevoke) (updated remoteconn.Trust, err error) { + ctx = s.app.performedIn(ctx, "remote.workspaceTrust.revoke", surfaceButton) + defer func() { s.recordFailure(ctx, "remote_trust_settings_save", documentLogError(err)) }() + if _, _, err := trust.Revoke(ctx, s.app.kernel, revokes); err != nil { + return trust, err + } + return remoteconn.ReadTrust(ctx, s.app.kernel, s.app.globalToolchainRoot(), "", "") +} + // settingsToolchains is the settings window's adapter onto the workbench: it // reads the open project's enabled plugin manifests and writes explicit // directory pins. All calls run on the settings window's background worker. diff --git a/docs/assets/trusted-locations/README.md b/docs/assets/trusted-locations/README.md index 98f18b23f..9b1555509 100644 --- a/docs/assets/trusted-locations/README.md +++ b/docs/assets/trusted-locations/README.md @@ -1,11 +1,12 @@ # 可信位置设置页(#2207)无头测试截图 -来自生产 Viva Page 的无头渲染。可信文件夹列表由测试的假加载器提供,路径都是虚构的;不读写真实的偏好目录,也不调用真实 Core。截图覆盖深色与浅色主题、中文与英文界面,用于确认: +来自生产 Viva Page 的无头渲染。可信文件夹列表和远程工作区的信任记录由测试的假加载器提供,路径和主机都是虚构的;不读写真实的偏好目录,也不调用真实 Core。截图覆盖深色与浅色主题、中文与英文界面,用于确认: - “构建、执行、部署”目录页多出“可信位置”一行,显示可信文件夹数量; - 可信位置页按保存顺序列出文件夹,长路径用等宽字体并在悬停时显示完整路径; - 待添加和待删除的文件夹分别带标签和“撤销修改”,底栏显示未应用的项数和写入目标; -- Core 拒绝把文件系统根目录设为可信位置时,提示显示在列表下方,其他草稿保留。 +- Core 拒绝把文件系统根目录设为可信位置时,提示显示在列表下方,其他草稿保留; +- 2026-11-21 起(#2231 S04)页面下方多出“远程工作区”卡片:按连接分组,标题是连接名和主机(没有连接名时用主机和跳转链),每条记录带“已信任”“安全模式”“可信位置”标签和删除按钮;删除是草稿,带“待删除”和“撤销修改”,底栏写入目标多出“远程工作区信任”。 截图不代表 macOS/Windows 原生窗口验收。 diff --git a/docs/assets/trusted-locations/trusted-locations-drafts-dark-en.png b/docs/assets/trusted-locations/trusted-locations-drafts-dark-en.png index b53d20075..3c1d0c8e5 100644 Binary files a/docs/assets/trusted-locations/trusted-locations-drafts-dark-en.png and b/docs/assets/trusted-locations/trusted-locations-drafts-dark-en.png differ diff --git a/docs/assets/trusted-locations/trusted-locations-drafts-dark-zh-Hans.png b/docs/assets/trusted-locations/trusted-locations-drafts-dark-zh-Hans.png index 284ec5e74..7f677e5eb 100644 Binary files a/docs/assets/trusted-locations/trusted-locations-drafts-dark-zh-Hans.png and b/docs/assets/trusted-locations/trusted-locations-drafts-dark-zh-Hans.png differ diff --git a/docs/assets/trusted-locations/trusted-locations-drafts-light-en.png b/docs/assets/trusted-locations/trusted-locations-drafts-light-en.png index 25b3318ad..8fac0522f 100644 Binary files a/docs/assets/trusted-locations/trusted-locations-drafts-light-en.png and b/docs/assets/trusted-locations/trusted-locations-drafts-light-en.png differ diff --git a/docs/assets/trusted-locations/trusted-locations-drafts-light-zh-Hans.png b/docs/assets/trusted-locations/trusted-locations-drafts-light-zh-Hans.png index 6d62589e1..a404f9d08 100644 Binary files a/docs/assets/trusted-locations/trusted-locations-drafts-light-zh-Hans.png and b/docs/assets/trusted-locations/trusted-locations-drafts-light-zh-Hans.png differ diff --git a/docs/assets/trusted-locations/trusted-locations-list-dark-en.png b/docs/assets/trusted-locations/trusted-locations-list-dark-en.png index f662693bb..76c4442b7 100644 Binary files a/docs/assets/trusted-locations/trusted-locations-list-dark-en.png and b/docs/assets/trusted-locations/trusted-locations-list-dark-en.png differ diff --git a/docs/assets/trusted-locations/trusted-locations-list-dark-zh-Hans.png b/docs/assets/trusted-locations/trusted-locations-list-dark-zh-Hans.png index dccfca5b7..db27e9a4f 100644 Binary files a/docs/assets/trusted-locations/trusted-locations-list-dark-zh-Hans.png and b/docs/assets/trusted-locations/trusted-locations-list-dark-zh-Hans.png differ diff --git a/docs/assets/trusted-locations/trusted-locations-list-light-en.png b/docs/assets/trusted-locations/trusted-locations-list-light-en.png index e2367029e..599deb260 100644 Binary files a/docs/assets/trusted-locations/trusted-locations-list-light-en.png and b/docs/assets/trusted-locations/trusted-locations-list-light-en.png differ diff --git a/docs/assets/trusted-locations/trusted-locations-list-light-zh-Hans.png b/docs/assets/trusted-locations/trusted-locations-list-light-zh-Hans.png index 89c0d9f6e..55753529a 100644 Binary files a/docs/assets/trusted-locations/trusted-locations-list-light-zh-Hans.png and b/docs/assets/trusted-locations/trusted-locations-list-light-zh-Hans.png differ diff --git a/shared/i18n/features/trusted-locations.json b/shared/i18n/features/trusted-locations.json index 8001855b6..52e345020 100644 --- a/shared/i18n/features/trusted-locations.json +++ b/shared/i18n/features/trusted-locations.json @@ -91,12 +91,99 @@ "platforms": [ "desktop" ] + }, + { + "id": "desktop.trustedLocations.remote", + "description": "Trusted Locations page: title of the card listing the trust records of folders on remote hosts", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteHelp", + "description": "Trusted Locations page: help behind the info glyph of the remote trust records", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteEmpty", + "description": "Trusted Locations page: shown in the remote card when no remote folder has a trust record", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteTrusted", + "description": "Trusted Locations page: tag of a remote folder whose project code may run", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteDistrusted", + "description": "Trusted Locations page: tag of a remote folder kept in safe mode", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteLocation", + "description": "Trusted Locations page: tag of a remote folder whose workspaces at any depth open trusted", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteUnnamed", + "description": "Trusted Locations page: title of a connection whose trust records carry no name and whose host cannot be shown", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteRemove", + "description": "Trusted Locations page: tip and accessible label of the button that removes one remote trust record", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteTarget", + "description": "Settings footer: where Apply writes the remote trust record drafts, joined into the list of targets; lowercase in English", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteConflict", + "description": "Trusted Locations page: a project window changed the remote trust records while removals were drafted", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteDamaged", + "description": "Trusted Locations page: the remote trust document in the preference directory cannot be read; do not translate the file name", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.trustedLocations.remoteFailed", + "description": "Trusted Locations page: removing remote trust records failed for another reason; reason is the error", + "platforms": [ + "desktop" + ], + "parameters": { + "reason": "string" + } } ], "locales": { "en-US": { "desktop.trustedLocations.title": "Trusted Locations", - "desktop.trustedLocations.keywords": "trust trusted safe mode folder location workspace project", + "desktop.trustedLocations.keywords": "trust trusted safe mode folder location workspace project remote ssh host container", "desktop.trustedLocations.target": "trusted locations", "desktop.trustedLocations.folders": "Trusted Folders", "desktop.trustedLocations.foldersHelp": "Projects anywhere inside these folders open trusted without asking, except the ones you chose to keep in safe mode. Changes take effect when you click Apply or OK.", @@ -107,11 +194,23 @@ "desktop.trustedLocations.pendingAdd": "To add", "desktop.trustedLocations.pendingRemove": "To remove", "desktop.trustedLocations.rootLocation": "A disk or filesystem root cannot be a trusted location: it would trust every project on that disk.", - "desktop.trustedLocations.listFull": "This trust list is full (256 entries). Remove one before adding another." + "desktop.trustedLocations.listFull": "This trust list is full (256 entries). Remove one before adding another.", + "desktop.trustedLocations.remote": "Remote Workspaces", + "desktop.trustedLocations.remoteHelp": "Folders on hosts you trusted or chose to keep in safe mode, recorded per connection and kept only on this machine. A record here never applies to local projects or to other hosts. After a record is removed, opening the folder asks again. Changes take effect when you click Apply or OK; a remote workspace that is already open keeps its trust until it is opened again.", + "desktop.trustedLocations.remoteEmpty": "No remote folder has a trust record. Lithe asks before opening a host folder you haven’t decided on.", + "desktop.trustedLocations.remoteTrusted": "Trusted", + "desktop.trustedLocations.remoteDistrusted": "Safe mode", + "desktop.trustedLocations.remoteLocation": "Trusted location", + "desktop.trustedLocations.remoteUnnamed": "Unnamed connection", + "desktop.trustedLocations.remoteRemove": "Remove This Record", + "desktop.trustedLocations.remoteTarget": "remote workspace trust", + "desktop.trustedLocations.remoteConflict": "The remote trust records changed elsewhere and were read again. Click Apply once more; the removals that still name a record were kept.", + "desktop.trustedLocations.remoteDamaged": "The remote trust records (toolchains/remote-trust.json in the settings folder) cannot be read. Repair or remove the file before removing records.", + "desktop.trustedLocations.remoteFailed": "Could not remove the records: {reason}" }, "zh-CN": { "desktop.trustedLocations.title": "可信位置", - "desktop.trustedLocations.keywords": "信任 可信 安全模式 文件夹 位置 工作区 项目", + "desktop.trustedLocations.keywords": "信任 可信 安全模式 文件夹 位置 工作区 项目 远程 主机 容器", "desktop.trustedLocations.target": "可信位置", "desktop.trustedLocations.folders": "可信文件夹", "desktop.trustedLocations.foldersHelp": "这些文件夹内任意层级的项目都直接以信任方式打开,不再询问;你选择保持安全模式的项目除外。点击“应用”或“确定”后生效。", @@ -122,7 +221,19 @@ "desktop.trustedLocations.pendingAdd": "待添加", "desktop.trustedLocations.pendingRemove": "待删除", "desktop.trustedLocations.rootLocation": "磁盘或文件系统的根目录不能作为可信位置,否则会信任该磁盘上的所有项目。", - "desktop.trustedLocations.listFull": "信任列表已满(最多 256 项),请先删除一项再添加。" + "desktop.trustedLocations.listFull": "信任列表已满(最多 256 项),请先删除一项再添加。", + "desktop.trustedLocations.remote": "远程工作区", + "desktop.trustedLocations.remoteHelp": "你在主机上信任或选择保持安全模式的文件夹,按连接分别记录,只保存在本机;这里的记录不会作用于本机项目或其他主机。删除一条记录后,下次打开该文件夹会再次询问。点击“应用”或“确定”后生效;已经打开的远程工作区要重新打开后才按新的记录处理。", + "desktop.trustedLocations.remoteEmpty": "还没有远程文件夹的信任记录。打开尚未决定的主机文件夹时会先询问。", + "desktop.trustedLocations.remoteTrusted": "已信任", + "desktop.trustedLocations.remoteDistrusted": "安全模式", + "desktop.trustedLocations.remoteLocation": "可信位置", + "desktop.trustedLocations.remoteUnnamed": "未命名连接", + "desktop.trustedLocations.remoteRemove": "删除此记录", + "desktop.trustedLocations.remoteTarget": "远程工作区信任", + "desktop.trustedLocations.remoteConflict": "远程工作区的信任记录在别处被修改过,已重新读取。请再点击一次“应用”;仍然对应现有记录的删除草稿已保留。", + "desktop.trustedLocations.remoteDamaged": "无法读取远程工作区的信任记录(设置目录中的 toolchains/remote-trust.json)。修复或删除这个文件之前不能删除记录。", + "desktop.trustedLocations.remoteFailed": "无法删除记录:{reason}" } } } diff --git a/shared/platform-feature-matrix/features/workspace-trusted-locations.json b/shared/platform-feature-matrix/features/workspace-trusted-locations.json index 2558b7474..5cfcb9811 100644 --- a/shared/platform-feature-matrix/features/workspace-trusted-locations.json +++ b/shared/platform-feature-matrix/features/workspace-trusted-locations.json @@ -2,7 +2,7 @@ "id": "workspace-trusted-locations", "area": "工作区", "group": "工作区生命周期", - "capability": "设置 › 工具 › 可信位置:查看、添加和删除可信文件夹,由 Core 校验并原子写入本机工具链目录", + "capability": "设置 › 工具 › 可信位置:查看、添加和删除可信文件夹,由 Core 校验并原子写入本机工具链目录;按连接列出并删除远程工作区的信任记录", "macos": { "implementationStatus": "implemented", "verificationStatus": "pending", @@ -14,7 +14,12 @@ "desktop/internal/toolchain/catalog.go", "desktop/internal/toolchain/trusted_locations_test.go", "desktop/internal/workbench/settings_toolchains.go", - "docs/assets/trusted-locations/README.md" + "docs/assets/trusted-locations/README.md", + "desktop/internal/settingswindow/remote_trust_state.go", + "desktop/internal/settingswindow/remote_trust_state_test.go", + "desktop/internal/remoteconn/trust.go", + "desktop/internal/remoteconn/trust_test.go", + "desktop/internal/core/remote_helpers.go" ] }, "windows": { @@ -27,10 +32,15 @@ "desktop/internal/settingswindow/build_apply.go", "desktop/internal/toolchain/catalog.go", "desktop/internal/toolchain/trusted_locations_test.go", - "desktop/internal/workbench/settings_toolchains.go" + "desktop/internal/workbench/settings_toolchains.go", + "desktop/internal/settingswindow/remote_trust_state.go", + "desktop/internal/settingswindow/remote_trust_state_test.go", + "desktop/internal/remoteconn/trust.go", + "desktop/internal/remoteconn/trust_test.go", + "desktop/internal/core/remote_helpers.go" ] }, "owner": "Workspace", - "verification": "打开设置 › 工具 › 可信位置,按保存顺序列出偏好目录 toolchains/global.json 中的 trustedLocations,打开页面不创建也不改写该文件。点“添加文件夹…”选择一个文件夹,列表末尾出现带“待添加”标签的行;点某行的删除按钮,该行变灰并显示“待删除”;“撤销修改”恢复原位置;选择磁盘或文件系统根目录时列表下方显示拒绝原因,其他草稿保留。底栏显示未应用项数和“写入 可信位置”;点“应用”或“确定”后文件只写一次,重新读取后标记消失。此后在已添加文件夹内任意层级打开一个没有信任记录的项目,直接以信任方式打开;在已删除文件夹中的项目重新询问。另一处写入(如工具链页或信任对话框)改变文件后,应用前会先重新读取再写入,不覆盖对方的改动。Windows 上路径使用反斜杠显示。", - "notes": "2026-11-21(#2207):Core 的 toolchains.editCatalog 新增 trustedLocations 字段(Lithe-IDEA/Lithe-core-rust#144),拒绝根目录(plugin.toolchain.rootLocation)和超过 256 项(plugin.toolchain.trustListFull)。桌面端每次只向 Core 提交一项改动,草稿由 Core 预演;与工具链页共用同一个目录文件,写入互相标记过期,应用时先写工具链再写可信位置。两个平台共用同一实现,只有无头测试与截图,尚未在两个平台做真实应用验收。远程工作区的可信条目由 #2231 R1 跟进。 2026-11-21:页面从“构建、执行、部署”移到“工具”,构建目录页不再列出可信位置和可信文件夹数量;可信文件夹只在打开本页时读取。自动化:TestToolsGroupHoldsTerminalSearchConsoleAndTrustedLocations、TestBuildDirectoryListsOnlyItsOwnPages。" + "verification": "打开设置 › 工具 › 可信位置,按保存顺序列出偏好目录 toolchains/global.json 中的 trustedLocations,打开页面不创建也不改写该文件。点“添加文件夹…”选择一个文件夹,列表末尾出现带“待添加”标签的行;点某行的删除按钮,该行变灰并显示“待删除”;“撤销修改”恢复原位置;选择磁盘或文件系统根目录时列表下方显示拒绝原因,其他草稿保留。底栏显示未应用项数和“写入 可信位置”;点“应用”或“确定”后文件只写一次,重新读取后标记消失。此后在已添加文件夹内任意层级打开一个没有信任记录的项目,直接以信任方式打开;在已删除文件夹中的项目重新询问。另一处写入(如工具链页或信任对话框)改变文件后,应用前会先重新读取再写入,不覆盖对方的改动。Windows 上路径使用反斜杠显示。 远程工作区:信任或以安全模式打开过主机文件夹后,本页下方的“远程工作区”卡片按连接分组列出记录,标题是连接名和主机(无连接名时为主机与跳转链),每条记录带“已信任”“安全模式”或“可信位置”标签;打开页面不改写偏好目录的 toolchains/remote-trust.json,也不需要连接主机。点某条记录的删除按钮显示“待删除”和“撤销修改”,底栏写入目标出现“远程工作区信任”;应用后文件只写一次,连接的最后一条记录删除后整组消失。此后在该主机重新打开这个文件夹会再次询问是否信任;已经打开的远程工作区保持原来的信任直到重新打开。删除草稿期间另一个项目窗口改了记录时,应用失败并提示已重新读取,仍对应现有记录的删除保留,再点“应用”写入。本机项目不受远程记录影响。", + "notes": "2026-11-21(#2207):Core 的 toolchains.editCatalog 新增 trustedLocations 字段(Lithe-IDEA/Lithe-core-rust#144),拒绝根目录(plugin.toolchain.rootLocation)和超过 256 项(plugin.toolchain.trustListFull)。桌面端每次只向 Core 提交一项改动,草稿由 Core 预演;与工具链页共用同一个目录文件,写入互相标记过期,应用时先写工具链再写可信位置。两个平台共用同一实现,只有无头测试与截图,尚未在两个平台做真实应用验收。远程工作区的信任记录见下文 S04。 2026-11-21:页面从“构建、执行、部署”移到“工具”,构建目录页不再列出可信位置和可信文件夹数量;可信文件夹只在打开本页时读取。自动化:TestToolsGroupHoldsTerminalSearchConsoleAndTrustedLocations、TestBuildDirectoryListsOnlyItsOwnPages。 2026-11-21(#2231 S04):本页新增“远程工作区”卡片,读取和删除都走 Core 的 remote.workspaceTrust / remote.editWorkspaceTrust(revoke 不需要会话),按读取时的字节校验写入,冲突报 remoteconn.ErrConflict 后重新读取并保留仍有效的删除草稿;本页不新增远程记录(打开主机文件夹时决定)。远程记录与本机可信位置互不混用。两个平台共用同一实现,只有无头测试与截图。自动化:TestRemoteTrustRecordsAreListedDraftedAndApplied、TestRemoteTrustConflictReadsAgainAndKeepsTheListedRemovals、TestRemoteTrustCardShowsOnlyWithALoader、TestRemoteTrustRevokeRemovesRecordsWithoutAConnection。" }