@alsdd/t3-import 0.1.7-alsd.2 → 0.1.7-alsd.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +14 -5
- package/dist/cli.js +5 -5
- package/dist/cli.js.map +1 -1
- package/dist/target/importer.js +2 -2
- package/dist/target/importer.js.map +1 -1
- package/dist/target/replace.js +2 -2
- package/dist/target/replace.js.map +1 -1
- package/dist/target/runtimeControl.d.ts +13 -2
- package/dist/target/runtimeControl.js +67 -19
- package/dist/target/runtimeControl.js.map +1 -1
- package/dist/target/schema.d.ts +2 -0
- package/dist/target/schema.js +11 -1
- package/dist/target/schema.js.map +1 -1
- package/dist/target/sync.js +4 -4
- package/dist/target/sync.js.map +1 -1
- package/dist/target/windowsDesktop.d.ts +20 -0
- package/dist/target/windowsDesktop.js +135 -0
- package/dist/target/windowsDesktop.js.map +1 -0
- package/dist/tui.js +91 -33
- package/dist/tui.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { win32 } from "node:path";
|
|
5
|
+
import { safetyError } from "../core/errors.js";
|
|
6
|
+
const execute = promisify(execFile);
|
|
7
|
+
// Restart Manager is queried only for ownership; it is never asked to stop apps.
|
|
8
|
+
const ownership = String.raw `
|
|
9
|
+
Add-Type -TypeDefinition @'
|
|
10
|
+
using System;
|
|
11
|
+
using System.Runtime.InteropServices;
|
|
12
|
+
using System.Runtime.InteropServices.ComTypes;
|
|
13
|
+
using System.Text;
|
|
14
|
+
public static class T3FileOwners {
|
|
15
|
+
[StructLayout(LayoutKind.Sequential)] public struct Unique { public uint pid; public System.Runtime.InteropServices.ComTypes.FILETIME started; }
|
|
16
|
+
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] public struct Info {
|
|
17
|
+
public Unique process;
|
|
18
|
+
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)] public string name;
|
|
19
|
+
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)] public string service;
|
|
20
|
+
public uint type, status, session;
|
|
21
|
+
[MarshalAs(UnmanagedType.Bool)] public bool restartable;
|
|
22
|
+
}
|
|
23
|
+
[DllImport("rstrtmgr.dll", CharSet=CharSet.Unicode)] static extern int RmStartSession(out uint h, uint flags, StringBuilder key);
|
|
24
|
+
[DllImport("rstrtmgr.dll", CharSet=CharSet.Unicode)] static extern int RmRegisterResources(uint h, uint files, string[] names, uint apps, Unique[] processes, uint services, string[] serviceNames);
|
|
25
|
+
[DllImport("rstrtmgr.dll")] static extern int RmGetList(uint h, out uint needed, ref uint count, [In,Out] Info[] apps, ref uint reasons);
|
|
26
|
+
[DllImport("rstrtmgr.dll")] static extern int RmEndSession(uint h);
|
|
27
|
+
static void Check(int code) { if(code!=0) throw new System.ComponentModel.Win32Exception(code); }
|
|
28
|
+
public static uint[] Get(string path) {
|
|
29
|
+
uint h; Check(RmStartSession(out h,0,new StringBuilder(33)));
|
|
30
|
+
try {
|
|
31
|
+
Check(RmRegisterResources(h,1,new[]{path},0,null,0,null));
|
|
32
|
+
uint needed=0,count=0,reasons=0; int code=RmGetList(h,out needed,ref count,null,ref reasons);
|
|
33
|
+
if(code==0) return new uint[0];
|
|
34
|
+
if(code!=234) Check(code);
|
|
35
|
+
// Bound retries if process ownership changes while querying.
|
|
36
|
+
for(int attempt=0;attempt<3;attempt++) {
|
|
37
|
+
count=needed; var apps=new Info[count]; code=RmGetList(h,out needed,ref count,apps,ref reasons);
|
|
38
|
+
if(code==234) continue; Check(code);
|
|
39
|
+
var result=new uint[count]; for(int i=0;i<count;i++) result[i]=apps[i].process.pid;
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
throw new Exception("File ownership changed during inspection");
|
|
43
|
+
} finally { RmEndSession(h); }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
'@
|
|
47
|
+
`;
|
|
48
|
+
const helpers = String.raw `
|
|
49
|
+
function ProcessInfo([int]$Id) {
|
|
50
|
+
$p=Get-CimInstance Win32_Process -Filter ('ProcessId='+$Id)
|
|
51
|
+
if($null -eq $p){throw 'Process no longer exists'}
|
|
52
|
+
return $p
|
|
53
|
+
}
|
|
54
|
+
function SameProcess($p,$started) { return $p.CreationDate.ToUniversalTime().ToString('o') -eq $started }
|
|
55
|
+
function OwnerSid($p) { $v=Invoke-CimMethod -InputObject $p -MethodName GetOwnerSid; if($v.ReturnValue -ne 0){throw 'Cannot verify process owner'}; return $v.Sid }
|
|
56
|
+
function AssertSession($p,$sid,$session) {
|
|
57
|
+
$self=Get-Process -Id $PID
|
|
58
|
+
if($p.SessionId -le 0 -or $p.SessionId -ne $self.SessionId -or $p.SessionId -ne $session -or (OwnerSid $p) -ne $sid -or $sid -ne [Security.Principal.WindowsIdentity]::GetCurrent().User.Value){throw 'Run t3-import in the same Windows desktop session and user as T3; SSH and other sessions cannot restore its window safely'}
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
export async function powershell(script) {
|
|
62
|
+
const { stdout } = await execute("powershell.exe", ["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(`$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; [Console]::OutputEncoding=New-Object Text.UTF8Encoding($false); $OutputEncoding=[Console]::OutputEncoding; ${script}`, "utf16le").toString("base64")], { timeout: 20_000, maxBuffer: 128 * 1024, windowsHide: true });
|
|
63
|
+
return stdout.trim();
|
|
64
|
+
}
|
|
65
|
+
function payload(value) {
|
|
66
|
+
// Input is data inside an encoded JSON document, never PowerShell source.
|
|
67
|
+
return `$v=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${Buffer.from(JSON.stringify(value)).toString("base64")}'))|ConvertFrom-Json;`;
|
|
68
|
+
}
|
|
69
|
+
export async function windowsFileOwners(databasePath, run = powershell) {
|
|
70
|
+
const owners = JSON.parse(await run(payload({ db: databasePath }) + ownership + "ConvertTo-Json -InputObject @([T3FileOwners]::Get($v.db)) -Compress"));
|
|
71
|
+
if (!Array.isArray(owners) || !owners.every((pid) => Number.isSafeInteger(pid) && pid > 0))
|
|
72
|
+
throw safetyError("Invalid Windows file ownership report.");
|
|
73
|
+
return owners;
|
|
74
|
+
}
|
|
75
|
+
export async function discoverWindowsDesktop(paths, runtimePid, run = powershell) {
|
|
76
|
+
// Refuse unsupported locations before starting PowerShell or compiling native probes.
|
|
77
|
+
const normalized = (path) => win32.resolve(path).toLowerCase();
|
|
78
|
+
const home = normalized(win32.join(homedir(), ".t3"));
|
|
79
|
+
const state = win32.join(home, "userdata");
|
|
80
|
+
if (normalized(paths.t3Home) !== home || normalized(paths.stateDir) !== state)
|
|
81
|
+
throw safetyError("Custom T3 homes require manual maintenance.");
|
|
82
|
+
const database = normalized(paths.dbPath);
|
|
83
|
+
if (win32.dirname(database) !== state || !["statev2.sqlite", "state.sqlite"].includes(win32.basename(database)))
|
|
84
|
+
throw safetyError("Custom database paths require manual maintenance.");
|
|
85
|
+
if (!(await windowsFileOwners(paths.dbPath, run)).includes(runtimePid))
|
|
86
|
+
throw safetyError("The recorded runtime does not own the selected database.");
|
|
87
|
+
const result = JSON.parse(await run(payload({ db: paths.dbPath, home: paths.t3Home, stateDir: paths.stateDir, runtimePid }) + helpers + String.raw `
|
|
88
|
+
$runtime=ProcessInfo $v.runtimePid; $p=$runtime; $visited=@{}
|
|
89
|
+
while($null -ne $p -and -not $visited.ContainsKey([int]$p.ProcessId)) {
|
|
90
|
+
$visited[[int]$p.ProcessId]=$true
|
|
91
|
+
if([IO.Path]::GetFileName($p.ExecutablePath) -match '^T3 Code(?: \([A-Za-z]+\))?\.exe$' -and (Get-Process -Id $p.ProcessId).MainWindowHandle -ne 0){break}
|
|
92
|
+
$p=Get-CimInstance Win32_Process -Filter ('ProcessId='+$p.ParentProcessId)
|
|
93
|
+
}
|
|
94
|
+
if($null -eq $p -or (Get-Process -Id $p.ProcessId).MainWindowHandle -eq 0){throw 'No owning T3 Desktop window found'}
|
|
95
|
+
$sid=OwnerSid $p; AssertSession $p $sid $p.SessionId
|
|
96
|
+
if((OwnerSid $runtime) -ne $sid -or $runtime.SessionId -ne $p.SessionId){throw 'Runtime and desktop ownership disagree'}
|
|
97
|
+
# Replaying arbitrary argv or a development Electron launcher is unsupported.
|
|
98
|
+
if($p.CommandLine.Trim().Trim('"') -ine $p.ExecutablePath){throw 'Custom T3 launch arguments require manual maintenance'}
|
|
99
|
+
$asar=Join-Path (Split-Path $p.ExecutablePath) 'resources\app.asar'
|
|
100
|
+
if(-not (Test-Path -LiteralPath $asar -PathType Leaf)){throw 'Packaged T3 installation could not be verified'}
|
|
101
|
+
[pscustomobject]@{pid=[int]$p.ProcessId;started=$p.CreationDate.ToUniversalTime().ToString('o');executable=$p.ExecutablePath;sha256=(Get-FileHash -LiteralPath $p.ExecutablePath -Algorithm SHA256).Hash;sessionId=[int]$p.SessionId;ownerSid=$sid;runtimePid=[int]$runtime.ProcessId;runtimeStarted=$runtime.CreationDate.ToUniversalTime().ToString('o')}|ConvertTo-Json -Compress
|
|
102
|
+
`));
|
|
103
|
+
if (!Number.isSafeInteger(result.pid) || result.pid <= 0 || !Number.isSafeInteger(result.runtimePid) || result.runtimePid !== runtimePid || !result.started || !result.runtimeStarted || !/^[a-f0-9]{64}$/iu.test(result.sha256) || !result.ownerSid || !result.executable || result.sessionId <= 0)
|
|
104
|
+
throw safetyError("Invalid Windows desktop ownership report.");
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
export function sameWindowsDesktop(a, b) {
|
|
108
|
+
return a !== undefined && ["pid", "started", "executable", "sha256", "sessionId", "ownerSid", "runtimePid", "runtimeStarted"].every((key) => a[key] === b[key]);
|
|
109
|
+
}
|
|
110
|
+
export async function closeWindowsDesktop(desktop, run = powershell) {
|
|
111
|
+
await run(payload(desktop) + helpers + String.raw `
|
|
112
|
+
$p=ProcessInfo $v.pid; AssertSession $p $v.ownerSid $v.sessionId
|
|
113
|
+
$runtime=ProcessInfo $v.runtimePid
|
|
114
|
+
if(-not (SameProcess $p $v.started) -or -not (SameProcess $runtime $v.runtimeStarted) -or $p.ExecutablePath -ine $v.executable -or (Get-FileHash -LiteralPath $v.executable -Algorithm SHA256).Hash -ine $v.sha256){throw 'Desktop identity changed before close'}
|
|
115
|
+
if(-not (Get-Process -Id $v.pid).CloseMainWindow()){throw 'T3 did not accept the normal window close request'}
|
|
116
|
+
`);
|
|
117
|
+
}
|
|
118
|
+
export async function windowsDesktopStopped(desktop, run = powershell) {
|
|
119
|
+
return await run(payload(desktop) + String.raw `
|
|
120
|
+
$remaining=@(Get-Process -Id $v.pid,$v.runtimePid -ErrorAction SilentlyContinue)
|
|
121
|
+
if($remaining.Count -eq 0){'true'}else{'false'}
|
|
122
|
+
`) === "true";
|
|
123
|
+
}
|
|
124
|
+
export async function startWindowsDesktop(desktop, run = powershell) {
|
|
125
|
+
await run(payload(desktop) + helpers + String.raw `
|
|
126
|
+
$self=ProcessInfo $PID; AssertSession $self $v.ownerSid $v.sessionId
|
|
127
|
+
if((Get-FileHash -LiteralPath $v.executable -Algorithm SHA256).Hash -ine $v.sha256){throw 'The T3 executable changed during maintenance; reopen it manually'}
|
|
128
|
+
$existing=Get-CimInstance Win32_Process|Where-Object {$_.ExecutablePath -ieq $v.executable -and $_.SessionId -eq $v.sessionId}
|
|
129
|
+
if(-not $existing){Start-Process -FilePath $v.executable -WorkingDirectory (Split-Path $v.executable)|Out-Null}
|
|
130
|
+
`);
|
|
131
|
+
}
|
|
132
|
+
export function windowsRecoveryCommand(desktop) {
|
|
133
|
+
return `Start-Process -FilePath '${desktop.executable.replaceAll("'", "''")}'`;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=windowsDesktop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"windowsDesktop.js","sourceRoot":"","sources":["../../src/target/window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AC,CAAC,CAAC,GAA2B,CAAC,KAAK,CAAC,CAAC,GAA2B,CAAC,CAAC,CAAC;AAClN,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAAuB,EAAE,MAAwB,UAAU;IACnG,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;EAKjD,CAAC,CAAC;AACJ,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAAuB,EAAE,MAAwB,UAAU;IACrG,OAAO,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,GAAG,CAAA;;;EAG9C,CAAC,KAAK,MAAM,CAAC;AACf,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAAuB,EAAE,MAAwB,UAAU;IACnG,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;EAKjD,CAAC,CAAC;AACJ,CAAC;AACD,MAAM,UAAU,sBAAsB,CAAC,OAAuB;IAC5D,OAAO,4BAA4B,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AACjF,CAAC"}
|
package/dist/tui.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import Database from "better-sqlite3";
|
|
4
4
|
import { Box, Text, useApp, useInput } from "ink";
|
|
5
5
|
import { sourceAdapter } from "./sources/index.js";
|
|
6
6
|
import { compactThreadForImport, importConversations } from "./target/importer.js";
|
|
7
7
|
import { inspectConversationSync, syncConversations } from "./target/sync.js";
|
|
8
8
|
import { listProviderInstances } from "./target/config.js";
|
|
9
|
-
import { inspectRuntimeStatus } from "./target/runtimeControl.js";
|
|
9
|
+
import { inspectRuntimeStatus, runtimeOwnerLabel } from "./target/runtimeControl.js";
|
|
10
10
|
import { runtimeActivityText } from "./target/runtimeActivity.js";
|
|
11
11
|
import { launchT3Code } from "./target/launch.js";
|
|
12
12
|
import { resetT3RebuildableCache } from "./target/cache.js";
|
|
@@ -59,8 +59,10 @@ export function helpTextForScreen(screen, searching = false) {
|
|
|
59
59
|
if (searching)
|
|
60
60
|
return "Type to search Backspace delete Enter apply Esc cancel";
|
|
61
61
|
if (screen === "threads")
|
|
62
|
-
return "↑/↓ or j/k move Space select a all / search Enter
|
|
63
|
-
if (screen === "
|
|
62
|
+
return "↑/↓ or j/k move Space select a all / search Enter review v view Esc back/quit q quit";
|
|
63
|
+
if (screen === "workspace")
|
|
64
|
+
return "↑/↓ or j/k move Enter choose v all conversations Esc back/quit q quit";
|
|
65
|
+
if (screen === "source" || screen === "provider" || screen === "destination")
|
|
64
66
|
return "↑/↓ or j/k move Enter choose Esc back/quit q quit";
|
|
65
67
|
if (screen === "review")
|
|
66
68
|
return "Enter confirm Esc back q quit";
|
|
@@ -77,20 +79,22 @@ export function selectionMarker(isSelected, isDisabled) {
|
|
|
77
79
|
return "⊘";
|
|
78
80
|
return isSelected ? "◉" : "○";
|
|
79
81
|
}
|
|
80
|
-
function Menu({ items, index, selected, disabled }) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
function Menu({ items, index, selected, disabled, maxVisible = items.length }) {
|
|
83
|
+
const start = Math.max(0, Math.min(index - Math.floor(maxVisible / 2), items.length - maxVisible));
|
|
84
|
+
return _jsxs(Box, { flexDirection: "column", children: [items.slice(start, start + maxVisible).map((item, offset) => {
|
|
85
|
+
const itemIndex = start + offset;
|
|
86
|
+
const isDisabled = disabled?.has(itemIndex) ?? false;
|
|
87
|
+
return _jsxs(Text, { dimColor: isDisabled, ...(itemIndex === index && !isDisabled ? { color: "cyan" } : {}), children: [itemIndex === index ? "›" : " ", " ", selected ? selectionMarker(selected.has(itemIndex), isDisabled) : "", " ", item] }, `${itemIndex}:${item}`);
|
|
88
|
+
}), items.length > maxVisible ? _jsxs(Text, { dimColor: true, children: ["Rows ", start + 1, " to ", Math.min(start + maxVisible, items.length), " of ", items.length] }) : null] });
|
|
85
89
|
}
|
|
86
90
|
export function StartT3Prompt({ index }) {
|
|
87
91
|
return _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, children: "Start T3 Code now?" }), _jsx(Menu, { items: ["Yes", "No"], index: index }), _jsx(Text, { dimColor: true, children: "Press Enter to confirm." })] });
|
|
88
92
|
}
|
|
89
93
|
export function ReplacementReview({ workspace, selections, previews, counts, resetCache, }) {
|
|
90
94
|
const taskWord = counts.tasks === 1 ? "task" : "tasks";
|
|
91
|
-
return _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, children: "Review replacement" }), _jsxs(Text, { children: ["Workspace: ", workspace] }), _jsx(Box, { marginTop: 1, flexDirection: "column", children: selections.map((selection) => {
|
|
95
|
+
return _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, children: "Review replacement" }), _jsxs(Text, { children: ["Workspace: ", workspace ?? "Multiple workspaces"] }), _jsx(Box, { marginTop: 1, flexDirection: "column", children: selections.map((selection) => {
|
|
92
96
|
const preview = previews.get(selection.conversation.summary.id);
|
|
93
|
-
return _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: selection.conversation.summary.title }), _jsxs(Text, { children: ["Old T3 task: ", preview?.oldThreadId] }), _jsxs(Text, { children: ["New T3 task: ", preview?.newThreadId] })] }, `replacement-review:${selection.conversation.summary.id}`);
|
|
97
|
+
return _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: selection.conversation.summary.title }), !workspace ? _jsxs(Text, { children: ["Working directory: ", selection.conversation.summary.workspace] }) : null, _jsxs(Text, { children: ["Old T3 task: ", preview?.oldThreadId] }), _jsxs(Text, { children: ["New T3 task: ", preview?.newThreadId] })] }, `replacement-review:${selection.conversation.summary.id}`);
|
|
94
98
|
}) }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsxs(Text, { children: ["The new ", taskWord, " will contain:"] }), _jsxs(Text, { children: [" ", counts.turns, " turns \u00B7 ", counts.events, " events \u00B7 ", counts.attachments, " attachments"] })] }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsxs(Text, { children: ["The provider, model, and resume connection will transfer to the new ", taskWord, "."] }), _jsxs(Text, { children: ["The old ", taskWord, " will disappear from T3 but remain in its event history."] })] }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { children: "When you confirm, t3-import will automatically:" }), _jsx(Text, { children: " \u2022 Create a verified backup of the T3 database" }), _jsxs(Text, { children: [" ", resetCache ? "• Back up and reset T3's UI cache" : "• Keep T3's existing UI cache (--no-cache-reset)"] })] }), _jsx(Text, { color: "yellow", children: "T3 must remain closed." }), _jsx(Text, { bold: true, children: "Press Enter to replace, or Escape to cancel." })] });
|
|
95
99
|
}
|
|
96
100
|
export function conversationStatusText(preview, checking) {
|
|
@@ -182,6 +186,8 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
182
186
|
const [source, setSource] = useState(initialSource ?? "codex");
|
|
183
187
|
const [summaries, setSummaries] = useState([]);
|
|
184
188
|
const [workspace, setWorkspace] = useState();
|
|
189
|
+
const [browseMode, setBrowseMode] = useState("workspace");
|
|
190
|
+
const initialWorkspaceApplied = useRef(false);
|
|
185
191
|
const [provider, setProvider] = useState(initialProvider);
|
|
186
192
|
const [destinationChoices, setDestinationChoices] = useState([]);
|
|
187
193
|
const [destinationError, setDestinationError] = useState();
|
|
@@ -213,9 +219,14 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
213
219
|
const workspaces = useMemo(() => [...new Map(summaries.map((summary) => [summary.workspace.toLowerCase(), summary.workspace])).values()], [summaries]);
|
|
214
220
|
const providers = useMemo(() => listProviderInstances(paths, source), [paths, source]);
|
|
215
221
|
const visibleThreads = useMemo(() => summaries
|
|
216
|
-
.filter((summary) => !workspace || summary.workspace.toLowerCase() === workspace.toLowerCase())
|
|
222
|
+
.filter((summary) => browseMode === "recent" || !workspace || summary.workspace.toLowerCase() === workspace.toLowerCase())
|
|
223
|
+
.toSorted((a, b) => b.updatedAt.localeCompare(a.updatedAt))
|
|
217
224
|
.filter((summary) => mode !== "replace" || !replacePreviews.has(summary.id) || replacePreviews.get(summary.id)?.previouslyImported)
|
|
218
|
-
.filter((summary) => !query || summary.title.toLowerCase().includes(query.toLowerCase()) || summary.id.includes(query)), [mode, query, replacePreviews, summaries, workspace]);
|
|
225
|
+
.filter((summary) => !query || summary.title.toLowerCase().includes(query.toLowerCase()) || summary.workspace.toLowerCase().includes(query.toLowerCase()) || summary.id.includes(query)), [browseMode, mode, query, replacePreviews, summaries, workspace]);
|
|
226
|
+
const destinationWorkspace = useMemo(() => {
|
|
227
|
+
const roots = [...new Map(preparedImports.map(({ conversation }) => [canonicalPath(conversation.summary.workspace), conversation.summary.workspace])).values()];
|
|
228
|
+
return roots.length === 1 ? roots[0] : undefined;
|
|
229
|
+
}, [preparedImports]);
|
|
219
230
|
const operationFor = useCallback((summary) => {
|
|
220
231
|
const preview = syncPreviews.get(summary.id);
|
|
221
232
|
const replacement = replacePreviews.get(summary.id);
|
|
@@ -298,6 +309,19 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
298
309
|
});
|
|
299
310
|
}, [initialSource, paths]);
|
|
300
311
|
useEffect(() => { checkRuntime(); }, [checkRuntime]);
|
|
312
|
+
useEffect(() => {
|
|
313
|
+
initialWorkspaceApplied.current = false;
|
|
314
|
+
setSummaries([]);
|
|
315
|
+
setWorkspace(undefined);
|
|
316
|
+
setBrowseMode("workspace");
|
|
317
|
+
setQuery("");
|
|
318
|
+
setSelected(new Set());
|
|
319
|
+
setConversations(new Map());
|
|
320
|
+
setSyncPreviews(new Map());
|
|
321
|
+
setReplacePreviews(new Map());
|
|
322
|
+
setInspectionErrors(new Map());
|
|
323
|
+
setPendingStatuses(0);
|
|
324
|
+
}, [source, paths]);
|
|
301
325
|
useEffect(() => {
|
|
302
326
|
if (screen !== "workspace")
|
|
303
327
|
return;
|
|
@@ -306,11 +330,16 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
306
330
|
sourceAdapter(source).discover({}).then((items) => {
|
|
307
331
|
if (cancelled)
|
|
308
332
|
return;
|
|
309
|
-
|
|
310
|
-
const
|
|
333
|
+
const unique = new Map();
|
|
334
|
+
for (const item of items)
|
|
335
|
+
if (!unique.has(item.id))
|
|
336
|
+
unique.set(item.id, item);
|
|
337
|
+
setSummaries([...unique.values()]);
|
|
338
|
+
const selectedWorkspace = initialWorkspace && !initialWorkspaceApplied.current
|
|
311
339
|
? items.find((item) => item.workspace.toLowerCase() === initialWorkspace.toLowerCase())?.workspace
|
|
312
340
|
: undefined;
|
|
313
341
|
if (selectedWorkspace) {
|
|
342
|
+
initialWorkspaceApplied.current = true;
|
|
314
343
|
setWorkspace(selectedWorkspace);
|
|
315
344
|
setProvider(initialProvider ?? providers[0]);
|
|
316
345
|
// An explicit --workspace bypasses the chooser and its navigation history.
|
|
@@ -323,24 +352,22 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
323
352
|
return () => { cancelled = true; };
|
|
324
353
|
}, [screen, source]);
|
|
325
354
|
useEffect(() => {
|
|
326
|
-
if (screen !== "threads" || !workspace)
|
|
355
|
+
if (screen !== "threads" || (browseMode === "workspace" && !workspace))
|
|
327
356
|
return;
|
|
328
357
|
let cancelled = false;
|
|
329
|
-
const items = summaries.filter((summary) => summary.workspace.toLowerCase() === workspace.toLowerCase())
|
|
358
|
+
const items = summaries.filter((summary) => (browseMode === "recent" || summary.workspace.toLowerCase() === workspace.toLowerCase())
|
|
359
|
+
&& !conversations.has(summary.id));
|
|
330
360
|
const queue = [...items];
|
|
361
|
+
setInspectionErrors((current) => { const next = new Map(current); for (const item of items)
|
|
362
|
+
next.delete(item.id); return next; });
|
|
331
363
|
setPendingStatuses(items.length);
|
|
332
|
-
setSelected(new Set());
|
|
333
|
-
setConversations(new Map());
|
|
334
|
-
setSyncPreviews(new Map());
|
|
335
|
-
setReplacePreviews(new Map());
|
|
336
|
-
setInspectionErrors(new Map());
|
|
337
364
|
const worker = async () => {
|
|
338
365
|
while (!cancelled) {
|
|
339
366
|
const summary = queue.shift();
|
|
340
367
|
if (!summary)
|
|
341
368
|
return;
|
|
342
369
|
try {
|
|
343
|
-
const conversation = await sourceAdapter(source).load(summary, { workspace });
|
|
370
|
+
const conversation = await sourceAdapter(source).load(summary, { workspace: summary.workspace });
|
|
344
371
|
const preview = mode === "replace" ? undefined : await inspectConversationSync(conversation, paths);
|
|
345
372
|
const replacement = mode === "replace" || preview?.status === "history-diverged"
|
|
346
373
|
? await inspectConversationReplacement(conversation, paths)
|
|
@@ -353,7 +380,7 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
353
380
|
if (replacement)
|
|
354
381
|
setReplacePreviews((current) => new Map(current).set(summary.id, replacement));
|
|
355
382
|
setSummaries((current) => current.map((item) => item.id === summary.id
|
|
356
|
-
? { ...item, title: conversation.summary.title,
|
|
383
|
+
? { ...item, title: conversation.summary.title, status: conversation.summary.status }
|
|
357
384
|
: item));
|
|
358
385
|
}
|
|
359
386
|
catch (cause) {
|
|
@@ -368,12 +395,19 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
368
395
|
};
|
|
369
396
|
void Promise.all(Array.from({ length: Math.min(3, items.length) }, () => worker()));
|
|
370
397
|
return () => { cancelled = true; };
|
|
371
|
-
}, [mode, paths, screen, source, workspace]);
|
|
398
|
+
}, [browseMode, mode, paths, screen, source, workspace]);
|
|
372
399
|
useEffect(() => {
|
|
373
|
-
if (screen !== "destination"
|
|
400
|
+
if (screen !== "destination")
|
|
374
401
|
return;
|
|
402
|
+
if (!destinationWorkspace) {
|
|
403
|
+
setDestinationChoices([{ label: "Use each conversation's workspace project (default)" }]);
|
|
404
|
+
setDestinationError(undefined);
|
|
405
|
+
setDestinationOptions({});
|
|
406
|
+
setIndex(0);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
375
409
|
try {
|
|
376
|
-
setDestinationChoices(discoverTuiDestinations(paths,
|
|
410
|
+
setDestinationChoices(discoverTuiDestinations(paths, destinationWorkspace));
|
|
377
411
|
setDestinationError(undefined);
|
|
378
412
|
setDestinationOptions({});
|
|
379
413
|
setIndex(0);
|
|
@@ -382,7 +416,7 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
382
416
|
setDestinationError(cause instanceof Error ? cause.message : String(cause));
|
|
383
417
|
setDestinationChoices([]);
|
|
384
418
|
}
|
|
385
|
-
}, [paths, screen,
|
|
419
|
+
}, [paths, screen, destinationWorkspace]);
|
|
386
420
|
const move = (delta, length) => setIndex((current) => length === 0 ? 0 : (current + delta + length) % length);
|
|
387
421
|
useInput((input, key) => {
|
|
388
422
|
if (screen === "running" || screen === "maintenance")
|
|
@@ -404,7 +438,7 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
404
438
|
checkRuntime();
|
|
405
439
|
return;
|
|
406
440
|
}
|
|
407
|
-
if (screen === "blocked" && input === "s" && runtime?.activity.status === "idle" && runtime
|
|
441
|
+
if (screen === "blocked" && input === "s" && runtime?.activity.status === "idle" && runtimeOwnerLabel(runtime) && onPauseRuntime) {
|
|
408
442
|
setScreen("pause-confirm");
|
|
409
443
|
return;
|
|
410
444
|
}
|
|
@@ -426,6 +460,24 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
426
460
|
}
|
|
427
461
|
return;
|
|
428
462
|
}
|
|
463
|
+
if (input === "v" && (screen === "workspace" || screen === "threads")) {
|
|
464
|
+
if (screen === "workspace" && summaries.length > 0) {
|
|
465
|
+
setBrowseMode("recent");
|
|
466
|
+
setProvider(initialProvider ?? providers[0]);
|
|
467
|
+
navigate("threads");
|
|
468
|
+
}
|
|
469
|
+
else if (screen === "threads" && browseMode === "workspace") {
|
|
470
|
+
setBrowseMode("recent");
|
|
471
|
+
setIndex(0);
|
|
472
|
+
}
|
|
473
|
+
else if (screen === "threads") {
|
|
474
|
+
setBrowseMode("workspace");
|
|
475
|
+
setScreen("workspace");
|
|
476
|
+
setIndex(0);
|
|
477
|
+
setScreenHistory((history) => history.at(-1) === "workspace" ? history.slice(0, -1) : history);
|
|
478
|
+
}
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
429
481
|
if (key.upArrow || input === "k") {
|
|
430
482
|
move(-1, screen === "source" ? sourceNames.length : screen === "result" ? 2 : screen === "workspace" ? workspaces.length : screen === "provider" ? providers.length : screen === "destination" ? destinationChoices.length : visibleThreads.length);
|
|
431
483
|
return;
|
|
@@ -460,6 +512,7 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
460
512
|
return;
|
|
461
513
|
}
|
|
462
514
|
if (screen === "workspace" && key.return && workspaces[index]) {
|
|
515
|
+
setBrowseMode("workspace");
|
|
463
516
|
setWorkspace(workspaces[index]);
|
|
464
517
|
setProvider(initialProvider ?? providers[0]);
|
|
465
518
|
navigate("threads");
|
|
@@ -497,8 +550,13 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
497
550
|
next.add(id); return next; });
|
|
498
551
|
return;
|
|
499
552
|
}
|
|
500
|
-
if (key.return
|
|
501
|
-
const
|
|
553
|
+
if (key.return) {
|
|
554
|
+
const focused = visibleThreads[index];
|
|
555
|
+
const selection = selected.size > 0 ? selected : focused && canSelect(focused) ? new Set([focused.id]) : new Set();
|
|
556
|
+
if (!selection.size)
|
|
557
|
+
return;
|
|
558
|
+
setSelected(selection);
|
|
559
|
+
const chosen = summaries.filter((summary) => selection.has(summary.id));
|
|
502
560
|
const imports = [];
|
|
503
561
|
const syncs = [];
|
|
504
562
|
const replacements = [];
|
|
@@ -580,7 +638,7 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
580
638
|
if ((screen === "launch-error" || screen === "error") && key.return)
|
|
581
639
|
app.exit();
|
|
582
640
|
});
|
|
583
|
-
return _jsxs(Box, { flexDirection: "column", paddingX: 1, children: [_jsx(Text, { bold: true, color: "cyan", children: "t3-import" }), _jsxs(Text, { dimColor: true, children: ["Target: ", paths.dbPath] }), managedService ? _jsxs(Text, { color: "yellow", children: ["Paused
|
|
641
|
+
return _jsxs(Box, { flexDirection: "column", paddingX: 1, children: [_jsx(Text, { bold: true, color: "cyan", children: "t3-import" }), _jsxs(Text, { dimColor: true, children: ["Target: ", paths.dbPath] }), managedService ? _jsxs(Text, { color: "yellow", children: ["Paused runtime: ", managedService, ". It will restart automatically when you exit."] }) : null, _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [screen === "preflight" && _jsx(Text, { children: "Checking whether T3 is running\u2026" }), screen === "blocked" && _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, color: "red", children: "T3 is running" }), _jsxs(Text, { children: ["Close T3 before importing, syncing, or replacing", runtime?.pid ? ` (detected PID ${runtime.pid})` : "", "."] }), runtime?.activity ? _jsx(Text, { children: runtimeActivityText(runtime.activity) }) : null, runtime?.activity.warnings.map((warning) => _jsx(Text, { color: "yellow", children: warning }, warning)), runtime && runtimeOwnerLabel(runtime) ? _jsxs(Text, { children: ["Runtime owner: ", runtimeOwnerLabel(runtime)] }) : _jsx(Text, { dimColor: true, children: runtime?.managementUnavailable }), runtime?.origin ? _jsxs(Text, { dimColor: true, children: ["Runtime: ", runtime.origin] }) : null, maintenanceError ? _jsx(Text, { color: "red", children: maintenanceError }) : null, runtime?.activity.status === "idle" && runtimeOwnerLabel(runtime) && onPauseRuntime ? _jsx(Text, { children: "Press s to pause T3 and continue. It will restart automatically on exit." }) : null, _jsx(Text, { children: "Press r or Enter to check again, or q to quit." })] }), screen === "pause-confirm" && _jsxs(_Fragment, { children: [_jsxs(Text, { bold: true, children: ["Pause ", runtime ? runtimeOwnerLabel(runtime) : "T3", " for maintenance?"] }), _jsx(Text, { children: "T3 and T3 Connect clients will disconnect until this command exits." }), _jsx(Text, { children: "The same T3 runtime will restart after success, cancellation, or error." }), _jsx(Text, { children: "Activity is checked again before stopping and before database writes." }), _jsx(Text, { children: "Press Enter to pause, Escape to go back, or q to quit." })] }), screen === "maintenance" && _jsx(Text, { children: "Pausing the idle T3 runtime and verifying that it has stopped\u2026" }), screen === "source" && _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, children: "Choose a source" }), _jsx(Menu, { items: sourceNames.map(sourceLabel), index: index })] }), screen === "workspace" && _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, children: "Choose a workspace" }), summaries.length === 0 ? _jsxs(Text, { children: ["Discovering ", source, " conversations\u2026"] }) : _jsx(Menu, { items: workspaces, index: index, maxVisible: 10 })] }), screen === "provider" && _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, children: "Choose a T3 provider instance" }), _jsx(Menu, { items: providers, index: index })] }), screen === "destination" && _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, children: "Choose a T3 destination for new imports" }), _jsx(Text, { dimColor: true, children: "Available choices preserve the source working directory." }), destinationError ? _jsx(Text, { color: "red", children: destinationError }) : destinationChoices.length ? _jsx(Menu, { items: destinationChoices.map((choice) => choice.label), index: index }) : _jsx(Text, { children: "Checking available destinations\u2026" })] }), screen === "threads" && _jsxs(_Fragment, { children: [_jsxs(Text, { bold: true, children: [mode === "sync" ? "Select conversations to sync" : mode === "replace" ? "Select conversations to replace" : "Select conversations", " \u2014 ", browseMode === "recent" ? "All conversations · most recent first" : workspace] }), searching || query ? _jsxs(Text, { color: "yellow", children: ["Search: ", query, _jsx(Text, { dimColor: true, children: "_" })] }) : null, _jsx(Menu, { items: visibleThreads.map((item) => {
|
|
584
642
|
const syncText = conversationStatusText(syncPreviews.get(item.id), checkingStatuses);
|
|
585
643
|
const replacement = replacePreviews.get(item.id);
|
|
586
644
|
const status = mode === "replace"
|
|
@@ -589,6 +647,6 @@ export function ImportTui({ paths, initialSource, initialWorkspace, initialProvi
|
|
|
589
647
|
? "history changed · replace available"
|
|
590
648
|
: syncText;
|
|
591
649
|
return `${item.title} ${status}`;
|
|
592
|
-
}), index: index, selected: selectedVisible, disabled: disabledVisible }), mode !== "replace" ? _jsxs(Text, { dimColor: true, children: ["New: ", statusCounts.new, " · To sync: ", statusCounts.syncable, " · Current: ", statusCounts.current, " · Active only: ", statusCounts.active, " · Conflicts: ", statusCounts.conflicts, " · Unavailable: ", statusCounts.unavailable] }) : null, visibleThreads[index] ? _jsx(ConversationStatusDetails, { preview: syncPreviews.get(visibleThreads[index].id), replacement: replacePreviews.get(visibleThreads[index].id), checking: checkingStatuses, error: inspectionErrors.get(visibleThreads[index].id), mode: mode }) : null, pendingStatuses > 0 ? _jsxs(Text, { dimColor: true, children: ["Checking ", pendingStatuses, " conversation", pendingStatuses === 1 ? "" : "s", "\u2026"] }) : null, visibleThreads.length === 0 && _jsx(Text, { color: "yellow", children: "No matching conversations." })] }), screen === "review" && _jsx(_Fragment, { children: preparedReplacements.length ? _jsx(_Fragment, { children: _jsx(ReplacementReview, { workspace: workspace, selections: preparedReplacements, previews: replacePreviews, counts: replacementPreview, resetCache: resetCache }) }) : _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, children: "Review changes" }), _jsxs(Text, { children: ["Source: ", source, " \u00B7 Workspace: ", workspace] }), preparedImports.length ? _jsxs(_Fragment, { children: [_jsxs(Text, { children: ["Source working directory: ",
|
|
650
|
+
}), index: index, selected: selectedVisible, disabled: disabledVisible, maxVisible: 8 }), _jsxs(Text, { children: ["Selected: ", selected.size, selected.size ? " · Enter reviews selected conversations" : " · Enter reviews highlighted conversation; Space selects for a batch"] }), browseMode === "recent" && visibleThreads[index] ? _jsxs(Text, { dimColor: true, children: ["Working directory: ", visibleThreads[index].workspace] }) : null, mode !== "replace" ? _jsxs(Text, { dimColor: true, children: ["New: ", statusCounts.new, " · To sync: ", statusCounts.syncable, " · Current: ", statusCounts.current, " · Active only: ", statusCounts.active, " · Conflicts: ", statusCounts.conflicts, " · Unavailable: ", statusCounts.unavailable] }) : null, visibleThreads[index] ? _jsx(ConversationStatusDetails, { preview: syncPreviews.get(visibleThreads[index].id), replacement: replacePreviews.get(visibleThreads[index].id), checking: checkingStatuses, error: inspectionErrors.get(visibleThreads[index].id), mode: mode }) : null, pendingStatuses > 0 ? _jsxs(Text, { dimColor: true, children: ["Checking ", pendingStatuses, " conversation", pendingStatuses === 1 ? "" : "s", "\u2026"] }) : null, visibleThreads.length === 0 && _jsx(Text, { color: "yellow", children: "No matching conversations." })] }), screen === "review" && _jsx(_Fragment, { children: preparedReplacements.length ? _jsx(_Fragment, { children: _jsx(ReplacementReview, { workspace: browseMode === "recent" ? undefined : workspace, selections: preparedReplacements, previews: replacePreviews, counts: replacementPreview, resetCache: resetCache }) }) : _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, children: "Review changes" }), _jsxs(Text, { children: ["Source: ", source, " \u00B7 Workspace: ", destinationWorkspace ?? (browseMode === "recent" ? "Multiple workspaces" : workspace)] }), preparedImports.length ? _jsxs(_Fragment, { children: [_jsxs(Text, { children: ["Source working directory: ", destinationWorkspace ?? "Each selected conversation keeps its own directory"] }), _jsxs(Text, { children: ["Effective T3 working directory: ", destinationWorkspace ?? "Each selected conversation keeps its own directory"] }), _jsxs(Text, { children: ["Destination: ", destinationChoices.find((choice) => JSON.stringify(choice.options ?? {}) === JSON.stringify(destinationOptions))?.label ?? "Use workspace project automatically"] })] }) : null, _jsxs(Text, { children: ["New tasks: ", importPreview.tasks, " \u00B7 synchronized tasks: ", syncPreview.tasks] }), _jsxs(Text, { children: ["Imported turns: ", importPreview.turns, " \u00B7 added turns: ", syncPreview.turns, " \u00B7 adopted turns: ", syncPreview.adopted] }), _jsxs(Text, { children: ["Messages: ", importPreview.messages, " \u00B7 activities: ", importPreview.activities, " \u00B7 attachments: ", importPreview.attachments] }), _jsxs(Text, { children: ["Title updates: ", syncPreview.titles] }), [...preparedImports, ...preparedSync].map((selection) => _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { bold: true, children: selection.conversation.summary.title }), browseMode === "recent" ? _jsxs(Text, { children: ["Working directory: ", selection.conversation.summary.workspace] }) : null, _jsx(ConversationStatusDetails, { preview: syncPreviews.get(selection.conversation.summary.id), checking: false, mode: mode, review: true })] }, selection.conversation.summary.id)), preparedImports.length ? _jsxs(Text, { children: ["Provider for new tasks: ", provider] }) : null, resetCache ? _jsx(Text, { children: "T3 IndexedDB cache: back up and reset after successful changes" }) : _jsx(Text, { children: "T3 IndexedDB cache: keep existing cache" }), _jsx(Text, { color: "yellow", children: "T3 must remain closed. A verified backup will be created before database changes." }), _jsx(Text, { bold: true, children: "Press Enter to continue, Escape to go back." })] }) }), screen === "running" && _jsx(Text, { children: "Backing up and reconciling conversations\u2026" }), screen === "result" && (result || syncResult || replaceResult) && _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, color: "green", children: "Complete" }), result ? _jsxs(Text, { children: ["Import backup: ", result.backup ?? "not needed"] }) : null, result?.results.map((item) => _jsxs(Text, { children: [item.status === "imported" ? "✓" : "•", " ", item.title, " \u2014 ", item.status, ", ", item.turns, " turns, ", item.events, " events"] }, `import:${item.threadId}`)), syncResult ? _jsxs(Text, { children: ["Sync backup: ", syncResult.backup ?? "not needed"] }) : null, syncResult?.results.map((item) => _jsxs(Text, { children: [item.status === "synced" ? "✓" : "•", " ", item.title, " \u2014 ", item.status, ", ", item.turnsAdded, " added, ", item.turnsAdopted, " adopted, ", item.events, " events"] }, `sync:${item.sourceKey}`)), replaceResult ? _jsxs(Text, { children: ["Replacement backup: ", replaceResult.backup ?? "not needed"] }) : null, replaceResult?.results.map((item) => _jsxs(Text, { children: [item.status === "replaced" ? "✓" : "•", " ", item.title, " \u2014 ", item.status, item.oldThreadId ? `, old ${item.oldThreadId}` : "", item.newThreadId ? `, new ${item.newThreadId}` : "", ", ", item.turns, " turns, ", item.events, " events"] }, `replace:${item.sourceKey}`)), (replaceResult?.cache ?? syncResult?.cache ?? result?.cache) ? _jsxs(Text, { children: ["Cache backup: ", (replaceResult?.cache ?? syncResult?.cache ?? result?.cache)?.backup ?? "cache not found"] }) : null, cacheWarning ? _jsx(Text, { color: "yellow", children: cacheWarning }) : null, managedService ? _jsxs(Text, { children: ["Press Enter or q to exit and restore ", managedService, "."] }) : _jsx(StartT3Prompt, { index: index })] }), screen === "launching" && _jsx(Text, { children: "Starting T3 Code\u2026" }), screen === "launch-error" && _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, color: "red", children: "Could not start T3 Code" }), _jsx(Text, { children: launchError }), _jsx(Text, { dimColor: true, children: "Press Enter to exit and start it manually." })] }), screen === "error" && _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, color: "red", children: "Operation failed" }), _jsx(Text, { children: error }), _jsx(Text, { dimColor: true, children: "Press Enter to exit." })] })] }), helpTextForScreen(screen, searching) ? _jsx(Box, { marginTop: 1, children: _jsx(Help, { screen: screen, searching: searching }) }) : null] });
|
|
593
651
|
}
|
|
594
652
|
//# sourceMappingURL=tui.js.map
|