| 1 | import { modeHasAutoApproveTools, normalizeMode, normalizeToolApprovalMode, type Meta, type TabMeta } from "./types"; |
| 2 | import { sameSessionIdentity } from "./sessionIdentity"; |
| 3 | |
| 4 | export function metaFromTab(tab: TabMeta, existing?: Meta): Meta { |
| 5 | const cwd = tab.cwd || tab.workspaceRoot || existing?.cwd || ""; |
| 6 | const toolApprovalMode = normalizeToolApprovalMode( |
| 7 | tab.toolApprovalMode, |
| 8 | normalizeMode(tab.mode), |
| 9 | modeHasAutoApproveTools(tab.mode), |
| 10 | (tab.toolApprovalMode ?? "").trim() === "" ? existing?.toolApprovalMode : undefined, |
| 11 | ); |
| 12 | const autoApproveTools = toolApprovalMode === "danger-full-access"; |
| 13 | return { |
| 14 | label: tab.label || existing?.label || "", |
| 15 | ready: tab.ready, |
| 16 | runtime: tab.runtime, |
| 17 | startupErr: tab.startupErr, |
| 18 | historicalSource: tab.historicalSource, |
| 19 | eventChannel: existing?.eventChannel ?? "agent:event", |
| 20 | cwd, |
| 21 | workspaceRoot: tab.workspaceRoot || existing?.workspaceRoot || cwd, |
| 22 | workspaceName: tab.workspaceName || existing?.workspaceName, |
| 23 | workspacePath: tab.workspacePath || tab.workspaceRoot || existing?.workspacePath, |
| 24 | sessionPath: tab.sessionPath !== undefined ? tab.sessionPath : existing?.sessionPath, |
| 25 | session: tab.session !== undefined ? tab.session : existing?.session, |
| 26 | sessionRevision: tab.sessionRevision !== undefined ? tab.sessionRevision : existing?.sessionRevision, |
| 27 | sessionDigest: tab.sessionDigest !== undefined ? tab.sessionDigest : existing?.sessionDigest, |
| 28 | sessionGeneration: tab.sessionGeneration !== undefined ? tab.sessionGeneration : existing?.sessionGeneration, |
| 29 | gitBranch: tab.gitBranch || existing?.gitBranch, |
| 30 | imageInputEnabled: existing?.imageInputEnabled, |
| 31 | visionFallbackEnabled: existing?.visionFallbackEnabled, |
| 32 | autoApproveTools, |
| 33 | bypass: autoApproveTools, |
| 34 | collaborationMode: tab.collaborationMode ?? existing?.collaborationMode ?? "normal", |
| 35 | toolApprovalMode, |
| 36 | tokenMode: tab.tokenMode ?? existing?.tokenMode ?? "full", |
| 37 | agentPreset: tab.agentPreset ?? existing?.agentPreset, |
| 38 | qualityFloor: tab.qualityFloor ?? existing?.qualityFloor, |
| 39 | floorInferred: tab.floorInferred ?? existing?.floorInferred, |
| 40 | goal: tab.goal ?? existing?.goal, |
| 41 | goalStatus: tab.goalStatus ?? existing?.goalStatus, |
| 42 | goalView: tab.goalView ?? existing?.goalView, |
| 43 | canonicalTodos: sameSessionIdentity(tab, existing) ? existing?.canonicalTodos : undefined, |
| 44 | }; |
| 45 | } |
| 46 |