| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "reasonix/internal/boot" |
| 5 | "reasonix/internal/config" |
| 6 | "reasonix/internal/control" |
| 7 | "reasonix/internal/worktree" |
| 8 | ) |
| 9 | |
| 10 | // Retired quality-floor compatibility. Old callers and persisted values remain |
| 11 | // readable, while every live session uses standard execution. |
| 12 | |
| 13 | // SetQualityFloor validates a legacy value for the active tab. |
| 14 | func (a *App) SetQualityFloor(floor string) error { |
| 15 | return a.SetQualityFloorForTab("", floor) |
| 16 | } |
| 17 | |
| 18 | // SetQualityFloorForTab validates a legacy value and target tab without |
| 19 | // changing runtime state, rebuilding a controller, or starting a turn. |
| 20 | func (a *App) SetQualityFloorForTab(tabID, floor string) error { |
| 21 | _, err := control.NormalizeQualityFloor(floor) |
| 22 | if err != nil { |
| 23 | return err |
| 24 | } |
| 25 | tab := a.tabByID(tabID) |
| 26 | if tab == nil { |
| 27 | return a.workspaceNotReadyErr(nil) |
| 28 | } |
| 29 | return nil |
| 30 | } |
| 31 | |
| 32 | func (a *App) validateRemoteQualityFloor(tabID, floor string) error { |
| 33 | if _, err := control.NormalizeQualityFloor(floor); err != nil { |
| 34 | return err |
| 35 | } |
| 36 | _, _, _, err := a.remoteTabCommandTarget(tabID) |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | // derivedFloor retains the wire shape while keeping worktree isolation |
| 41 | // independent from the retired quality setting. |
| 42 | type derivedFloor struct { |
| 43 | floor string |
| 44 | inferred bool |
| 45 | isolated bool |
| 46 | } |
| 47 | |
| 48 | // derivedQualityFloor always reports standard and separately reports whether |
| 49 | // the tab uses a managed worktree. |
| 50 | func derivedQualityFloor(tab *WorkspaceTab) derivedFloor { |
| 51 | if tab == nil { |
| 52 | return derivedFloor{floor: control.QualityFloorStandard} |
| 53 | } |
| 54 | isolated := worktree.IsManagedPath(tab.WorkspaceRoot, config.DeliveryWorktreeDir()) |
| 55 | return derivedFloor{floor: control.QualityFloorStandard, isolated: isolated} |
| 56 | } |
| 57 | |
| 58 | // tabQualityFloor returns the only value written by new clients. Its arguments |
| 59 | // remain for compatibility with the session-creation call sites. |
| 60 | func tabQualityFloor(string, string) string { |
| 61 | return control.QualityFloorStandard |
| 62 | } |
| 63 | |
| 64 | // applyTabQualityFloorToController validates legacy input, then pins the live |
| 65 | // controller to the standard compatibility value. |
| 66 | func applyTabQualityFloorToController(ctrl control.SessionAPI, floor string) { |
| 67 | if ctrl == nil { |
| 68 | return |
| 69 | } |
| 70 | if _, err := control.NormalizeQualityFloor(floor); err != nil { |
| 71 | return |
| 72 | } |
| 73 | _ = ctrl.SetQualityFloor(control.QualityFloorStandard) |
| 74 | } |
| 75 | |
| 76 | // currentTabTokenMode returns the fixed dual-write compatibility label. |
| 77 | func currentTabTokenMode(tab *WorkspaceTab) string { |
| 78 | return tokenModeForFloor(derivedQualityFloor(tab).floor) |
| 79 | } |
| 80 | |
| 81 | // currentTabAgentPreset returns the role label derived from the quality floor. |
| 82 | func currentTabAgentPreset(tab *WorkspaceTab) string { |
| 83 | return agentPresetForFloor(derivedQualityFloor(tab).floor) |
| 84 | } |
| 85 | |
| 86 | // tokenModeForFloor and agentPresetForFloor map an already-derived floor onto |
| 87 | // the compat labels, so callers holding a derivedFloor skip the path math. |
| 88 | func tokenModeForFloor(_ string) string { |
| 89 | return boot.TokenModeFull |
| 90 | } |
| 91 | |
| 92 | func agentPresetForFloor(_ string) string { |
| 93 | return boot.AgentPresetStandard |
| 94 | } |
| 95 | |
| 96 | // qualityFloorSafe reads the recorded floor; nil-safe for lookups. |
| 97 | func (t *WorkspaceTab) qualityFloorSafe() string { |
| 98 | if t == nil { |
| 99 | return "" |
| 100 | } |
| 101 | return t.qualityFloor |
| 102 | } |
| 103 |