返回 DeepSeek-Reasonix
tab_runtime_snapshot.go
根目录 / desktop / tab_runtime_snapshot.go
1 package main
2
3 import "reasonix/internal/control"
4
5 // tabRuntimeSnapshot is a consistent under-a.mu copy of the per-tab fields
6 // that bound methods and rebuild paths need after releasing the lock.
7 type tabRuntimeSnapshot struct {
8 ctrl control.SessionAPI
9 sink *tabEventSink
10 label string
11 ready bool
12 readOnly bool
13 startupErr string
14 scope string
15 workspaceRoot string
16 sessionPath string
17 sessionID string
18 sessionGeneration uint64
19 topicID string
20 topicTitle string
21 sharedHostKey string
22 model string
23 effort *string
24 tokenMode, qualityFloor, mode string
25 goal, toolApprovalMode string
26 }
27
28 // normalizedTabRuntime is the internal, orthogonal runtime profile restored
29 // across controller rebuilds. Goal sidecars remain authoritative; legacyGoal is
30 // only a fallback for a running legacy Goal with no sidecar.
31 type normalizedTabRuntime struct {
32 collaborationMode, toolApprovalMode, tokenMode string
33 qualityFloor, legacyGoal string
34 }
35
36 // snapshotTabRuntimeLocked copies the racy per-tab fields. Callers must hold
37 // a.mu (read or write side); controller methods run only after unlocking.
38 func snapshotTabRuntimeLocked(tab *WorkspaceTab) tabRuntimeSnapshot {
39 if tab == nil {
40 return tabRuntimeSnapshot{}
41 }
42 return tabRuntimeSnapshot{
43 ctrl: tab.Ctrl, sink: tab.sink, label: tab.Label, ready: tab.Ready,
44 readOnly: tab.ReadOnly, startupErr: tab.StartupErr, scope: tab.Scope,
45 workspaceRoot: tab.WorkspaceRoot, sessionPath: tab.SessionPath, sessionID: tab.SessionID,
46 sessionGeneration: tab.SessionGeneration, topicID: tab.TopicID, topicTitle: tab.TopicTitle,
47 sharedHostKey: tab.SharedHostKey, model: tab.model, effort: cloneStringPtr(tab.effort),
48 tokenMode: currentTabTokenMode(tab), qualityFloor: tab.qualityFloor, mode: tab.mode,
49 goal: tab.goal, toolApprovalMode: tab.toolApprovalMode,
50 }
51 }
52
53 func (a *App) tabRuntimeSnapshot(tab *WorkspaceTab) tabRuntimeSnapshot {
54 if tab == nil {
55 return tabRuntimeSnapshot{}
56 }
57 a.mu.RLock()
58 defer a.mu.RUnlock()
59 return snapshotTabRuntimeLocked(tab)
60 }
61
61 lines GO