t3code-session-manager 0.0.0-stage → 0.4.1
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/.claude-plugin/marketplace.json +21 -0
- package/.claude-plugin/plugin.json +19 -0
- package/CHANGELOG.md +149 -0
- package/LICENSE +21 -0
- package/README.md +661 -2
- package/README.pt.md +617 -0
- package/bin/entry.d.mts +2 -0
- package/bin/entry.mjs +19 -0
- package/bin/t3sm.mjs +44 -0
- package/commands/import.md +30 -0
- package/commands/organize.md +36 -0
- package/commands/status.md +24 -0
- package/commands/sync.md +26 -0
- package/dist/apply/apply.js +993 -0
- package/dist/apply/claudeWriter.js +168 -0
- package/dist/apply/copyTranscript.js +116 -0
- package/dist/apply/importer.js +697 -0
- package/dist/apply/materialize.js +335 -0
- package/dist/apply/waves.js +108 -0
- package/dist/assistant/core.js +295 -0
- package/dist/assistant/deps.js +256 -0
- package/dist/assistant/i18n.js +38 -0
- package/dist/assistant/messages.en.js +494 -0
- package/dist/assistant/messages.pt.js +495 -0
- package/dist/assistant/runner.js +64 -0
- package/dist/assistant/steps.js +1362 -0
- package/dist/build.json +1 -0
- package/dist/cli/applyScreen.js +158 -0
- package/dist/cli/commands/accounts.js +254 -0
- package/dist/cli/commands/apply.js +199 -0
- package/dist/cli/commands/changelog.js +61 -0
- package/dist/cli/commands/doctor.js +105 -0
- package/dist/cli/commands/help.js +158 -0
- package/dist/cli/commands/merge.js +224 -0
- package/dist/cli/commands/organize.js +872 -0
- package/dist/cli/commands/plan.js +161 -0
- package/dist/cli/commands/projects.js +430 -0
- package/dist/cli/commands/quarantine.js +203 -0
- package/dist/cli/commands/recover.js +230 -0
- package/dist/cli/commands/rollback.js +281 -0
- package/dist/cli/commands/scan.js +117 -0
- package/dist/cli/commands/schedule.js +288 -0
- package/dist/cli/commands/start.js +45 -0
- package/dist/cli/commands/status.js +615 -0
- package/dist/cli/commands/sync.js +336 -0
- package/dist/cli/commands/update.js +398 -0
- package/dist/cli/errors.js +53 -0
- package/dist/cli/failures.js +91 -0
- package/dist/cli/flags.js +53 -0
- package/dist/cli/help.en.js +549 -0
- package/dist/cli/help.pt.js +566 -0
- package/dist/cli/helpText.js +211 -0
- package/dist/cli/helpTopics.js +58 -0
- package/dist/cli/locked.js +12 -0
- package/dist/cli/main.js +155 -0
- package/dist/cli/screen.js +3 -0
- package/dist/cli/ui.js +111 -0
- package/dist/cli/words.js +2 -0
- package/dist/core/activity.js +16 -0
- package/dist/core/changelog.js +47 -0
- package/dist/core/config.js +530 -0
- package/dist/core/fsutil.js +171 -0
- package/dist/core/glob.js +34 -0
- package/dist/core/history.js +32 -0
- package/dist/core/journal.js +274 -0
- package/dist/core/lock.js +337 -0
- package/dist/core/mask.js +31 -0
- package/dist/core/paths.js +68 -0
- package/dist/core/pid.js +101 -0
- package/dist/core/run.js +4 -0
- package/dist/core/semver.js +18 -0
- package/dist/core/sysroot.js +29 -0
- package/dist/core/types.js +229 -0
- package/dist/core/uuid.js +29 -0
- package/dist/core/version.js +72 -0
- package/dist/help/convert.md +20 -0
- package/dist/help/convert.pt.md +21 -0
- package/dist/help/cwd-unreadable.md +22 -0
- package/dist/help/cwd-unreadable.pt.md +22 -0
- package/dist/help/decisions.md +20 -0
- package/dist/help/decisions.pt.md +20 -0
- package/dist/help/errors.md +20 -0
- package/dist/help/errors.pt.md +22 -0
- package/dist/help/held.md +20 -0
- package/dist/help/held.pt.md +20 -0
- package/dist/help/history.md +27 -0
- package/dist/help/history.pt.md +29 -0
- package/dist/help/instance-unavailable.md +18 -0
- package/dist/help/instance-unavailable.pt.md +19 -0
- package/dist/help/not-imported.md +19 -0
- package/dist/help/not-imported.pt.md +19 -0
- package/dist/help/orphaned.md +19 -0
- package/dist/help/orphaned.pt.md +19 -0
- package/dist/help/project-mismatch.md +15 -0
- package/dist/help/project-mismatch.pt.md +15 -0
- package/dist/help/t3-native.md +22 -0
- package/dist/help/t3-native.pt.md +22 -0
- package/dist/help/updates.md +26 -0
- package/dist/help/updates.pt.md +28 -0
- package/dist/help/watcher.md +24 -0
- package/dist/help/watcher.pt.md +25 -0
- package/dist/i18n/cli.js +41 -0
- package/dist/i18n/lang.js +55 -0
- package/dist/i18n/messages.en.js +1140 -0
- package/dist/i18n/messages.pt.js +1149 -0
- package/dist/i18n/words.js +12 -0
- package/dist/ops/accounts.js +170 -0
- package/dist/ops/autoUpdate.js +223 -0
- package/dist/ops/discoverAccounts.js +343 -0
- package/dist/ops/doctor.js +811 -0
- package/dist/ops/elevated.js +47 -0
- package/dist/ops/errorCodes.js +39 -0
- package/dist/ops/follow.js +558 -0
- package/dist/ops/merge.js +830 -0
- package/dist/ops/notify.js +249 -0
- package/dist/ops/plugin.js +92 -0
- package/dist/ops/projects.js +113 -0
- package/dist/ops/quarantine.js +415 -0
- package/dist/ops/rollback.js +868 -0
- package/dist/ops/schedule.js +464 -0
- package/dist/ops/successor.js +51 -0
- package/dist/ops/sync.js +859 -0
- package/dist/ops/syncStatus.js +290 -0
- package/dist/ops/update.js +273 -0
- package/dist/ops/updater.js +641 -0
- package/dist/ops/watch.js +676 -0
- package/dist/ops/watcherControl.js +212 -0
- package/dist/ops/watcherHealth.js +75 -0
- package/dist/organize/apply.js +495 -0
- package/dist/organize/history.js +192 -0
- package/dist/organize/plan.js +283 -0
- package/dist/organize/rename.js +58 -0
- package/dist/organize/sessions.js +100 -0
- package/dist/organize/titles.js +70 -0
- package/dist/organize/types.js +73 -0
- package/dist/plan/categories.js +104 -0
- package/dist/plan/dedupe.js +137 -0
- package/dist/plan/folders.js +82 -0
- package/dist/plan/names.js +93 -0
- package/dist/plan/ownership.js +316 -0
- package/dist/plan/planner.js +669 -0
- package/dist/plan/rehome.js +101 -0
- package/dist/plan/report.js +407 -0
- package/dist/sources/cache.js +89 -0
- package/dist/sources/claude.js +297 -0
- package/dist/sources/codex.js +496 -0
- package/dist/sources/flatten.js +23 -0
- package/dist/sources/jsonl.js +169 -0
- package/dist/sources/native.js +233 -0
- package/dist/sources/opencode.js +483 -0
- package/dist/sources/pi.js +133 -0
- package/dist/sources/registry.js +67 -0
- package/dist/sources/types.js +80 -0
- package/dist/t3/api.js +492 -0
- package/dist/t3/auth.js +248 -0
- package/dist/t3/compat.js +62 -0
- package/dist/t3/decode.js +408 -0
- package/dist/t3/errors.js +185 -0
- package/dist/t3/rpc.js +185 -0
- package/dist/t3/runtime.js +80 -0
- package/dist/ui/caps.js +56 -0
- package/dist/ui/components.js +202 -0
- package/dist/ui/layout.js +205 -0
- package/dist/ui/list.js +423 -0
- package/dist/ui/locale.js +73 -0
- package/dist/ui/organizePreview.js +72 -0
- package/dist/ui/progress.js +237 -0
- package/dist/ui/style.js +32 -0
- package/dist/ui/terminal.js +126 -0
- package/dist/ui/text.js +186 -0
- package/package.json +58 -4
- package/skills/t3code-sessions/SKILL.md +183 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { normalizeCwd, pathKey } from "../core/paths.js";
|
|
2
|
+
import { scanJsonl } from "../sources/jsonl.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const PATH_FIELDS = ["file_path", "path", "notebook_path", "cwd"] ;
|
|
7
|
+
// `cd <path>` at the start of a command or after ; & | ( or a newline; `cd /d` (cmd.exe) allowed; quoted or bare.
|
|
8
|
+
const CD_RE = /(?:^|[;&|(\n]\s*)cd\s+(?:\/[dD]\s+)?(?:"([^"]*)"|'([^']*)'|([^\s;&|"')]+))/g;
|
|
9
|
+
// PowerShell (tool `PowerShell`): `Set-Location [-Path | -LiteralPath] <path>` or `cd <path>`, any case.
|
|
10
|
+
const PS_CD_RE = /(?:^|[;&|({\n]\s*)(?:set-location|cd)\s+(?:-(?:literal)?path\s+)?(?:"([^"]*)"|'([^']*)'|([^\s;&|"')}]+))/gi;
|
|
11
|
+
// Git Bash on Windows spells a drive `/d/...`: the drive letter alone, then a slash or the end.
|
|
12
|
+
const GIT_BASH_DRIVE_RE = /^\/([A-Za-z])(\/.*)?$/;
|
|
13
|
+
|
|
14
|
+
/** A `cd` target as Windows reads it: Git Bash's `/d/work` is `D:/work`, `/c` is `C:/` (win32 only; elsewhere unchanged). */
|
|
15
|
+
function cdTarget(p , platform ) {
|
|
16
|
+
if (p === undefined || platform !== "win32") return p;
|
|
17
|
+
const m = GIT_BASH_DRIVE_RE.exec(p);
|
|
18
|
+
return m ? `${m[1] .toUpperCase()}:${m[2] ?? "/"}` : p;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isAbs(p , platform ) {
|
|
22
|
+
if (platform === "win32") return /^[A-Za-z]:[\\/]/.test(p) || p.startsWith("\\\\") || p.startsWith("//");
|
|
23
|
+
return p.startsWith("/");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const asObj = (v ) =>
|
|
27
|
+
v !== null && typeof v === "object" && !Array.isArray(v) ? (v ) : null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Guess which known project a transcript really worked on (used for sessions whose recorded folder is the home
|
|
31
|
+
* folder, which T3 refuses).
|
|
32
|
+
*
|
|
33
|
+
* What is counted: every absolute path found in the transcript, once per occurrence: record `cwd`, tool_use inputs
|
|
34
|
+
* (`file_path`, `path`, `notebook_path`, `cwd`), `cd <path>` in Bash commands (on Windows, Git Bash's `/d/...` is
|
|
35
|
+
* `D:/...`) and `Set-Location` / `cd <path>` in PowerShell commands. Relative paths are ignored.
|
|
36
|
+
* `total` = all those paths EXCEPT ones equal to the home folder exactly (the home cwd repeats on every record and
|
|
37
|
+
* would drown the share); paths merely inside home still count towards `total`. `hits` for a root = paths equal to
|
|
38
|
+
* or inside it, attributed to the deepest matching known root. The top root is returned when
|
|
39
|
+
* `hits >= minHits` (default 5) and `hits / total >= minShare` (default 0.6); a tie for the top gives null.
|
|
40
|
+
*/
|
|
41
|
+
export async function inferProjectRoot(
|
|
42
|
+
file ,
|
|
43
|
+
knownRoots ,
|
|
44
|
+
o ,
|
|
45
|
+
) {
|
|
46
|
+
const { platform } = o;
|
|
47
|
+
const minShare = o.minShare ?? 0.6;
|
|
48
|
+
const minHits = o.minHits ?? 5;
|
|
49
|
+
const homeKey = pathKey(o.home, platform);
|
|
50
|
+
const roots = new Map (); // key -> normalized root as given
|
|
51
|
+
for (const r of knownRoots) {
|
|
52
|
+
if (r !== "" && isAbs(r, platform)) roots.set(pathKey(r, platform), normalizeCwd(r, platform));
|
|
53
|
+
}
|
|
54
|
+
const keys = [...roots.keys()].sort((a, b) => b.length - a.length); // deepest first
|
|
55
|
+
const counts = new Map ();
|
|
56
|
+
let total = 0;
|
|
57
|
+
|
|
58
|
+
const add = (p ) => {
|
|
59
|
+
if (typeof p !== "string" || p === "" || !isAbs(p, platform)) return;
|
|
60
|
+
const k = pathKey(p, platform);
|
|
61
|
+
if (k === homeKey) return;
|
|
62
|
+
total++;
|
|
63
|
+
for (const r of keys) {
|
|
64
|
+
const prefix = r.endsWith("/") ? r : r + "/";
|
|
65
|
+
if (k === r || k.startsWith(prefix)) {
|
|
66
|
+
counts.set(r, (counts.get(r) ?? 0) + 1);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
await scanJsonl(file, {}, (rec) => {
|
|
73
|
+
add(rec["cwd"]);
|
|
74
|
+
const content = asObj(rec["message"])?.["content"];
|
|
75
|
+
if (!Array.isArray(content)) return;
|
|
76
|
+
for (const block of content) {
|
|
77
|
+
const b = asObj(block);
|
|
78
|
+
if (!b || b["type"] !== "tool_use") continue;
|
|
79
|
+
const input = asObj(b["input"]);
|
|
80
|
+
if (!input) continue;
|
|
81
|
+
for (const f of PATH_FIELDS) add(input[f]);
|
|
82
|
+
if (typeof input["command"] !== "string") continue;
|
|
83
|
+
if (b["name"] === "Bash") {
|
|
84
|
+
for (const m of input["command"].matchAll(CD_RE)) add(cdTarget(m[1] ?? m[2] ?? m[3], platform));
|
|
85
|
+
} else if (b["name"] === "PowerShell") {
|
|
86
|
+
for (const m of input["command"].matchAll(PS_CD_RE)) add(m[1] ?? m[2] ?? m[3]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
let best = null;
|
|
92
|
+
let bestN = 0;
|
|
93
|
+
let tie = false;
|
|
94
|
+
for (const [r, n] of counts) {
|
|
95
|
+
if (n > bestN) { best = r; bestN = n; tie = false; } else if (n === bestN) tie = true;
|
|
96
|
+
}
|
|
97
|
+
if (best === null || tie || total === 0) return null;
|
|
98
|
+
const share = bestN / total;
|
|
99
|
+
if (bestN < minHits || share < minShare) return null;
|
|
100
|
+
return { root: roots.get(best) , hits: bestN, total, share };
|
|
101
|
+
}
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
|
|
2
|
+
import { shownAccountName, shownText } from "./names.js";
|
|
3
|
+
import { cliT, makeCliUi, } from "../i18n/cli.js";
|
|
4
|
+
import { fitLine, snugWidth } from "../ui/layout.js";
|
|
5
|
+
import { DECISION_WORDS, folderName } from "../i18n/words.js";
|
|
6
|
+
|
|
7
|
+
import { callout, kv, panel, table as uiTable } from "../ui/components.js";
|
|
8
|
+
import { displayWidth, padStart, wrapText } from "../ui/text.js";
|
|
9
|
+
|
|
10
|
+
const HARNESSES = ["claude", "codex", "pi", "opencode"];
|
|
11
|
+
|
|
12
|
+
/** Human wording for every skip reason (what happened, and whether it is the user's to fix). */
|
|
13
|
+
export const SKIP_EXPLANATION = {
|
|
14
|
+
"already-in-t3": "already imported into T3 Code",
|
|
15
|
+
"cwd-missing": "the project folder no longer exists on disk",
|
|
16
|
+
"duplicate": "same session kept under another path (case variant); the other copy is imported",
|
|
17
|
+
"mirror-copy": "an identical or shorter mirror of a session kept in another account",
|
|
18
|
+
"backup-copy": "lives in a .bak backup folder",
|
|
19
|
+
"active": "modified in the last 10 minutes, so it may be in use; try again later",
|
|
20
|
+
"non-uuid-id": "the session id is not a UUID, which T3 Code cannot import",
|
|
21
|
+
"no-session-id": "the transcript carries no session id",
|
|
22
|
+
"subagent": "a sub-agent transcript, shown inside its parent session",
|
|
23
|
+
"compressed": "Codex compressed this session and converting compressed sessions is off (`codex.convertCompressed: false` in config.json)",
|
|
24
|
+
"too-large": "larger than 512 MiB once decompressed, too big to convert",
|
|
25
|
+
"only-hidden": "holds only hidden or system records, nothing to show",
|
|
26
|
+
"over-4gib": "larger than 4 GiB, too big to import",
|
|
27
|
+
"no-cwd": "no working directory recorded, so the project is unknown",
|
|
28
|
+
"cwd-unreadable": "the working directory could not be read from the transcript",
|
|
29
|
+
"excluded": "matches an `exclude` pattern, or an `organize.overrides` rule set to \"skip\", in config.json",
|
|
30
|
+
"harness-unavailable": "no T3 Code provider instance exists for this harness",
|
|
31
|
+
"compare-failed": "could not compare it with its duplicate (file busy); it will be retried on the next plan",
|
|
32
|
+
"converted": "a transcript t3sm converted from another agent's session; imported through that session",
|
|
33
|
+
"revision": "a merge revision t3sm wrote that was never merged; `t3sm merge` reuses or removes it",
|
|
34
|
+
"automated": "started by a script through the Agent SDK (automated); `organize.sessions.automated` is \"skip\" in config.json",
|
|
35
|
+
"temp-folder": "its folder is a temporary one; `organize.folders.temp` is \"skip\" in config.json",
|
|
36
|
+
"system-folder": "its folder is a system one (Windows, Program Files, AppData, /usr, ...); `organize.folders.system` is \"skip\" in config.json",
|
|
37
|
+
"t3-refused": "its folder is one T3 Code refuses to import (the home folder, Downloads, Documents/Codex, T3 Code's own); it is not moved to another project (`organize.folders` is \"skip\", or t3sm cannot copy Pi sessions)",
|
|
38
|
+
"undecided": "in a category whose question was never answered (see Decisions pending); run `t3sm start` to choose",
|
|
39
|
+
"orphaned-in-t3": "started in T3 Code, and its thread there was deleted, so T3 Code will not import it again; `organize.sessions.orphaned` is \"skip\" in config.json (set it to \"copy\", or answer the question in `t3sm start`, to bring it back as a copy)",
|
|
40
|
+
"t3-native-unknown": "started in T3 Code, but the transcript does not say which T3 thread it belongs to, so t3sm never copies it by itself; if T3 Code no longer shows it, bring it back with `t3sm recover <id>`",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** What each `organize.decided` question is about (plan.md's Decisions pending table). */
|
|
44
|
+
export const DECISION_LABEL = {
|
|
45
|
+
"home": "Conversations in the home folder",
|
|
46
|
+
"t3-refused": "Conversations in other folders T3 Code refuses (Downloads, Documents/Codex, T3 Code's own)",
|
|
47
|
+
"temp": "Conversations in temporary folders",
|
|
48
|
+
"system": "Conversations in system folders",
|
|
49
|
+
"automated": "Automated sessions, started by scripts through the Agent SDK",
|
|
50
|
+
"orphaned": "Conversations started in T3 Code whose thread was deleted",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Human wording for every plan note; a new PlanNote breaks compilation until it is described here. */
|
|
54
|
+
export const NOTE_EXPLANATION = {
|
|
55
|
+
"duplicate-in-window": "has a duplicate inside the activity window",
|
|
56
|
+
"diverged-fork": "diverged from a copy in another account; both histories are kept",
|
|
57
|
+
"label-only-in-mirror": "its title or tag lives only in a discarded mirror copy",
|
|
58
|
+
"truncated-over-32mib": "larger than 32 MiB; T3 Code reads only the first 32 MiB",
|
|
59
|
+
"continued-outside-t3": "continued outside T3 Code after it was imported",
|
|
60
|
+
"continued-after-rehome": "continued outside T3 Code after t3sm copied it into T3 Code (from a folder T3 Code refuses, or after its thread was deleted there); the copy in T3 Code does not include that work",
|
|
61
|
+
"remapped-cwd": "its working directory was remapped by a `remap` rule in config.json",
|
|
62
|
+
"in-t3-under-other-account": "already in T3 Code under another account; not imported a second time",
|
|
63
|
+
"in-t3-as-other-form": "already in T3 Code in its other form (a Codex thread, or a converted Claude thread); not imported a second time",
|
|
64
|
+
"started-in-t3": "started in T3 Code and its thread is still there (active or archived); nothing to import",
|
|
65
|
+
"recovered": "started in T3 Code and brought back by `t3sm recover`: its copy is in T3 Code; nothing to import",
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** Per-harness detail for a skip reason, shown under that reason when the plan skips sessions of that harness for it. */
|
|
69
|
+
export const SKIP_DETAIL = {
|
|
70
|
+
"duplicate": { codex: "a second rollout file for the same Codex session (for example a sub-agent copy); the other file is the one planned" },
|
|
71
|
+
};
|
|
72
|
+
const HARNESS_NAME = { claude: "Claude Code", codex: "Codex", pi: "Pi", opencode: "OpenCode" };
|
|
73
|
+
|
|
74
|
+
export const SKIP_REASONS = Object.keys(SKIP_EXPLANATION) ;
|
|
75
|
+
const NOTES = Object.keys(NOTE_EXPLANATION) ;
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
function zero (keys ) {
|
|
86
|
+
return Object.fromEntries(keys.map((k) => [k, 0])) ;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function summarize(plan ) {
|
|
90
|
+
const s = {
|
|
91
|
+
byAction: { import: 0, "convert-import": 0, skip: 0 },
|
|
92
|
+
byReason: zero(SKIP_REASONS), byHarness: zero(HARNESSES), byInstance: {}, notes: zero(NOTES),
|
|
93
|
+
};
|
|
94
|
+
for (const it of plan.items) {
|
|
95
|
+
s.byAction[it.action.kind] = (s.byAction[it.action.kind] ?? 0) + 1;
|
|
96
|
+
s.byHarness[it.session.harness]++;
|
|
97
|
+
if (it.action.kind === "skip") s.byReason[it.action.reason]++;
|
|
98
|
+
else s.byInstance[it.action.instanceId] = (s.byInstance[it.action.instanceId] ?? 0) + 1;
|
|
99
|
+
for (const n of it.notes) s.notes[n]++;
|
|
100
|
+
}
|
|
101
|
+
return s;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
/** Escapes markdown/HTML metacharacters in untrusted text (names, titles, warnings). */
|
|
112
|
+
const esc = (s ) =>
|
|
113
|
+
s.replace(/[\\<>&*_[\]`|]/g, (c) => (c === "<" ? "<" : c === ">" ? ">" : c === "&" ? "&" : `\\${c}`)).replace(/\r?\n/g, " ");
|
|
114
|
+
/** A table cell: a whole-cell code span only needs the pipe escaped; anything else is fully escaped. */
|
|
115
|
+
const cell = (s ) => (/^`[^`]*`$/.test(s) ? s.replace(/\|/g, "\\|") : esc(s));
|
|
116
|
+
const code = (s ) => "`" + s.replace(/`/g, "'") + "`";
|
|
117
|
+
|
|
118
|
+
function table(head , rows , numeric = true) {
|
|
119
|
+
return [
|
|
120
|
+
`| ${head.join(" | ")} |`,
|
|
121
|
+
`|${head.map((_, i) => (numeric && i > 0 ? " ---: " : " --- ")).join("|")}|`,
|
|
122
|
+
...rows.map((r) => `| ${r.map(cell).join(" | ")} |`),
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const pl = (n , one , many ) => `${n} ${n === 1 ? one : many}`;
|
|
127
|
+
const sessions = (n ) => pl(n, "session", "sessions");
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The plan's line about Codex compressed sessions it converts (convert-import items flagged `compressed`), or null when
|
|
131
|
+
* there are none: T3 Code cannot read them, so they continue as Claude threads, not Codex ones.
|
|
132
|
+
*/
|
|
133
|
+
export function compressedCodexLine(plan , lang = "en") {
|
|
134
|
+
const n = plan.items.filter((i) => i.action.kind === "convert-import" && i.session.harness === "codex" && i.session.flags?.includes("compressed")).length;
|
|
135
|
+
return n === 0 ? null : cliT(lang, "plan.compressed", { n });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* One line per project that receives rehomed conversations (convert-import items with `rehomeFrom`): the project's
|
|
140
|
+
* title when this plan creates it, else its folder.
|
|
141
|
+
*/
|
|
142
|
+
export function rehomeLines(plan , folder = (r) => r, lang = "en", title = (t) => t) {
|
|
143
|
+
const byRoot = new Map ();
|
|
144
|
+
for (const i of plan.items) if (i.action.kind === "convert-import" && i.action.rehomeFrom !== undefined) byRoot.set(i.action.projectRoot, (byRoot.get(i.action.projectRoot) ?? 0) + 1);
|
|
145
|
+
const titleOf = new Map(plan.projectsToCreate.map((p) => [p.root, p.title]));
|
|
146
|
+
return [...byRoot].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).map(([root, n]) =>
|
|
147
|
+
cliT(lang, "plan.rehome", { n, to: titleOf.has(root) ? title(titleOf.get(root) ) : folder(root) }));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Why a held project waits (spec §4.6): `waiting: <project> — '<conversation>' written <N> min ago; retried after 10
|
|
152
|
+
* min idle`. The conversation is its title, else its file name; under a minute (or ahead of `now`) is "just now".
|
|
153
|
+
*/
|
|
154
|
+
export function heldLine(h , project , now , o = {}) {
|
|
155
|
+
const lang = o.lang ?? "en";
|
|
156
|
+
// A title is untrusted text: no control, bidi or format characters (terminal escapes) and one line.
|
|
157
|
+
const name = shownText(h.title ?? (h.file.split(/[\\/]/).pop() || h.file), 120);
|
|
158
|
+
const min = Math.floor((now - Date.parse(h.modifiedAt)) / 60_000);
|
|
159
|
+
const ago = Number.isFinite(min) && min >= 1 ? cliT(lang, "sync.minAgo", { n: min }) : cliT(lang, "sync.justNow");
|
|
160
|
+
return cliT(lang, "sync.waiting", { project: shownText(project, 120), dash: o.dash ?? "—", name, ago });
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const KIND_LABEL = { import: "Import as is", "convert-import": "Convert, then import", skip: "Skip" };
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Every warning plan.md lists (markdown, escaped): the planner's own warnings, then the hints derived from the plan
|
|
167
|
+
* (mirror copies, backup copies, continued outside T3 Code, truncated, remapped, duplicates in the window). The
|
|
168
|
+
* terminal summary counts this same list, so both always agree.
|
|
169
|
+
*/
|
|
170
|
+
export function planWarnings(plan , sum = summarize(plan)) {
|
|
171
|
+
const warn = plan.warnings.map(esc);
|
|
172
|
+
if (plan.mirrorCopies.length > 0) warn.push(`${pl(plan.mirrorCopies.length, "mirror copy", "mirror copies")} present. Run ${code("t3sm dedupe")} before ${code("t3sm apply")} so T3 cannot import stale copies under the wrong account.`);
|
|
173
|
+
if (sum.byReason["backup-copy"] > 0) warn.push(`${sessions(sum.byReason["backup-copy"])} in .bak folders: ${code("t3sm quarantine")} moves them aside, reversibly.`);
|
|
174
|
+
// `t3sm merge` handles Claude sessions only; other harnesses get their own line each.
|
|
175
|
+
const continued = plan.items.filter((i) => i.notes?.includes("continued-outside-t3"));
|
|
176
|
+
const claudeContinued = continued.filter((i) => i.session.harness === "claude").length;
|
|
177
|
+
if (claudeContinued > 0) warn.push(`${sessions(claudeContinued)} continued outside T3 Code after import. The imported thread is stale; ${code("t3sm merge")} creates a revision thread with the new messages and archives the old one.`);
|
|
178
|
+
for (const h of HARNESSES.filter((x) => x !== "claude")) {
|
|
179
|
+
const n = continued.filter((i) => i.session.harness === h).length;
|
|
180
|
+
if (n === 0) continue;
|
|
181
|
+
const name = HARNESS_NAME[h];
|
|
182
|
+
warn.push(n === 1
|
|
183
|
+
? `1 ${name} session changed since it was imported; t3sm cannot merge ${name} sessions yet — continue it in ${name} or in its T3 Code thread.`
|
|
184
|
+
: `${n} ${name} sessions changed since they were imported; t3sm cannot merge ${name} sessions yet — continue them in ${name} or in their T3 Code thread.`);
|
|
185
|
+
}
|
|
186
|
+
// Copies from refused folders (spec §4.3, R11): never offered to `t3sm merge`.
|
|
187
|
+
if (sum.notes["continued-after-rehome"] > 0) warn.push(`${sessions(sum.notes["continued-after-rehome"])} changed after the import: continuations made outside T3 Code after the import are not included (a conversation t3sm copied into T3 Code).`);
|
|
188
|
+
if (sum.notes["truncated-over-32mib"] > 0) warn.push(`${sessions(sum.notes["truncated-over-32mib"])} larger than 32 MiB; T3 Code reads only the first 32 MiB of each.`);
|
|
189
|
+
if (sum.notes["remapped-cwd"] > 0) warn.push(`${sessions(sum.notes["remapped-cwd"])} with a working directory remapped by a ${code("remap")} rule in config.json; check the Project accounts table.`);
|
|
190
|
+
const elsewhere = plan.items.filter((i) => i.notes?.includes("in-t3-under-other-account"));
|
|
191
|
+
if (elsewhere.length > 0) {
|
|
192
|
+
const ex = elsewhere.slice(0, 10).map((i) => `${code(i.session.nativeId)} (${i.session.accountId ?? i.session.harness})`).join(", ");
|
|
193
|
+
warn.push(`${sessions(elsewhere.length)} already in T3 Code under another account, so not imported again: ${ex}${elsewhere.length > 10 ? ", ..." : ""}. If that account is wrong, archive that thread in T3 Code and run ${code("t3sm plan")} again.`);
|
|
194
|
+
}
|
|
195
|
+
const otherForm = plan.items.filter((i) => i.notes?.includes("in-t3-as-other-form"));
|
|
196
|
+
if (otherForm.length > 0) {
|
|
197
|
+
// A converted (compressed) session's other form is its Codex thread; a native one's is its converted Claude thread.
|
|
198
|
+
const ex = otherForm.slice(0, 10).map((i) => `${code(i.session.nativeId)} already in T3 Code as ${i.session.mode === "convert" ? "a Codex thread" : "a converted Claude thread"}`).join(", ");
|
|
199
|
+
warn.push(`${sessions(otherForm.length)} already in T3 Code in another form, so not imported a second time: ${ex}${otherForm.length > 10 ? ", ..." : ""}.`);
|
|
200
|
+
}
|
|
201
|
+
const mismatch = plan.items.filter((i) => i.session.flags?.includes("id-mismatch")); // a hand-made or older plan may lack flags
|
|
202
|
+
if (mismatch.length > 0) {
|
|
203
|
+
const ex = mismatch.slice(0, 5).map((i) => `${code(i.session.nativeId)} in ${code(i.session.file.path)}`).join(", ");
|
|
204
|
+
warn.push(`${sessions(mismatch.length)} whose file name differs from the session id inside; T3 Code imports each under the id inside (${ex}${mismatch.length > 5 ? ", ..." : ""}).`);
|
|
205
|
+
}
|
|
206
|
+
if (sum.notes["duplicate-in-window"] > 0) warn.push(`${sessions(sum.notes["duplicate-in-window"])} with a duplicate inside the activity window.`);
|
|
207
|
+
return warn;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function renderPlanMarkdown(plan , opts = {}) {
|
|
211
|
+
const limit = opts.listLimit ?? 20;
|
|
212
|
+
// Account names are masked at this sink too (an account named after its email), whatever the caller passed.
|
|
213
|
+
const names = Object.fromEntries(Object.entries({ ...Object.fromEntries(plan.instancesToCreate.map((i) => [i.id, i.displayName])), ...opts.names }).map(([k, v]) => [k, shownAccountName(v)]));
|
|
214
|
+
const nm = (id ) => (id === null ? "(none)" : names[id] !== undefined ? `${names[id]} (${id})` : id);
|
|
215
|
+
const sum = summarize(plan);
|
|
216
|
+
const L = [];
|
|
217
|
+
|
|
218
|
+
L.push(`# t3sm plan ${plan.runId}`, "", `Generated ${plan.createdAt} for T3 Code ${plan.t3Version}. Nothing has been written yet: review this, then run ${code("t3sm apply")}.`, "");
|
|
219
|
+
|
|
220
|
+
L.push("## Summary", "");
|
|
221
|
+
L.push(...table(["Action", "Sessions"], (Object.keys(KIND_LABEL) ).map((k) => [KIND_LABEL[k], String(sum.byAction[k] ?? 0)])), "");
|
|
222
|
+
const owner = (i ) => (i.action.kind === "skip" ? (i.session.accountId ?? "(no account)") : i.action.instanceId);
|
|
223
|
+
const accountIds = [...new Set(plan.items.map(owner))].sort();
|
|
224
|
+
const perAcct = accountIds.map((id) => {
|
|
225
|
+
const mine = plan.items.filter((i) => owner(i) === id);
|
|
226
|
+
const c = (k ) => mine.filter((i) => i.action.kind === k).length;
|
|
227
|
+
return [id === "(no account)" ? id : nm(id), String(c("import")), String(c("convert-import")), String(c("skip"))];
|
|
228
|
+
});
|
|
229
|
+
L.push(...table(["Account / instance", "Import", "Convert", "Skip"], perAcct), "");
|
|
230
|
+
L.push(...table(["Harness", "Sessions"], HARNESSES.filter((h) => sum.byHarness[h] > 0).map((h) => [h, String(sum.byHarness[h])])), "");
|
|
231
|
+
const zst = compressedCodexLine(plan);
|
|
232
|
+
if (zst !== null) L.push(zst, "");
|
|
233
|
+
const moved = rehomeLines({ ...plan, projectsToCreate: plan.projectsToCreate.map((p) => ({ ...p, title: esc(p.title) })) }, code);
|
|
234
|
+
if (moved.length > 0) L.push(...moved.map((m) => `- ${m}`), "");
|
|
235
|
+
|
|
236
|
+
const pending = plan.decisionsPending ?? [];
|
|
237
|
+
if (pending.length > 0) {
|
|
238
|
+
L.push("## Decisions pending", "", `These sessions are skipped until you choose what t3sm does with them. Run ${code("t3sm start")} to decide; your answers are saved in config.json (${code("organize")}).`, "");
|
|
239
|
+
L.push(...table(["Question", "Sessions", "Folders"], pending.map((d) => [`${DECISION_LABEL[d.key] ?? d.key} (${d.key})`, String(d.sessions), String(d.folders)])), "");
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
L.push("## Accounts", "");
|
|
243
|
+
if (plan.instancesToCreate.length === 0) L.push("No instances to create.", "");
|
|
244
|
+
else L.push(...table(["Instance id", "Name", "Home"], plan.instancesToCreate.map((i) => [code(i.id), shownAccountName(i.displayName), code(i.homePath)]), false), "");
|
|
245
|
+
if (plan.pinDefault) {
|
|
246
|
+
L.push(`T3 Code's default Claude instance ${code(plan.pinDefault.instanceId)} has no explicit home: \`t3sm apply\` pins it to ${code(plan.pinDefault.homePath)}, so a T3 Code started with CLAUDE_CONFIG_DIR set cannot move it.`, "");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
L.push(`## Projects to create (${plan.projectsToCreate.length})`, "");
|
|
250
|
+
if (plan.projectsToCreate.length === 0) L.push("None.", "");
|
|
251
|
+
else {
|
|
252
|
+
const acct = new Map(plan.projectAccounts.map((p) => [p.root, p]));
|
|
253
|
+
L.push(...table(["Project", "Root", "Account", "Source"], plan.projectsToCreate.map((p) => {
|
|
254
|
+
const a = acct.get(p.root);
|
|
255
|
+
return [p.title, code(p.root), nm(a?.accountId ?? p.defaultInstanceId), a?.source ?? "-"];
|
|
256
|
+
}), false), "");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
L.push("## Project accounts", "", "Which subscription each project opens by default. Review this table: it decides where new threads in T3 Code start.", "");
|
|
260
|
+
if (plan.projectAccounts.length === 0) L.push("None.", "");
|
|
261
|
+
else L.push(...table(["Project root", "Account", "Source"], plan.projectAccounts.map((p) => [code(p.root), nm(p.accountId), p.source]), false), "");
|
|
262
|
+
|
|
263
|
+
L.push("## Project defaults to set", "");
|
|
264
|
+
if (plan.projectDefaults.length === 0) L.push("None.", "");
|
|
265
|
+
else L.push(...table(["Project root", "Default instance"], plan.projectDefaults.map((p) => [code(p.root), nm(p.instanceId)]), false), "");
|
|
266
|
+
|
|
267
|
+
L.push("## Duplicates across accounts", "");
|
|
268
|
+
const rel = (r ) => plan.mirrorCopies.filter((m) => m.relation === r).length;
|
|
269
|
+
L.push(...table(["Relation", "Copies"], [
|
|
270
|
+
["identical (mirror)", String(rel("identical"))],
|
|
271
|
+
["prefix (shorter mirror)", String(rel("prefix"))],
|
|
272
|
+
["case-variant (same session, other path case)", String(sum.byReason.duplicate)],
|
|
273
|
+
["backup (.bak folders)", String(sum.byReason["backup-copy"])],
|
|
274
|
+
]), "");
|
|
275
|
+
const forks = plan.items.filter((i) => i.notes.includes("diverged-fork"));
|
|
276
|
+
L.push(`Diverged forks (both histories are kept and imported): ${forks.length}`, "");
|
|
277
|
+
for (const f of forks) L.push(`- ${code(f.session.nativeId)} (${f.session.harness}, ${f.session.accountId ?? "no account"})`);
|
|
278
|
+
if (forks.length) L.push("");
|
|
279
|
+
const labels = plan.items.filter((i) => i.notes.includes("label-only-in-mirror"));
|
|
280
|
+
L.push(`Label only in a mirror copy (the title or tag lives in the discarded copy): ${labels.length}`, "");
|
|
281
|
+
for (const f of labels) L.push(`- ${code(f.session.nativeId)} (${f.session.harness}, ${f.session.accountId ?? "no account"})`);
|
|
282
|
+
if (labels.length) L.push("");
|
|
283
|
+
|
|
284
|
+
L.push("## Warnings", "");
|
|
285
|
+
const warn = planWarnings(plan, sum);
|
|
286
|
+
if (warn.length === 0) L.push("None.", "");
|
|
287
|
+
else L.push(...warn.map((w) => `- ${w}`), "");
|
|
288
|
+
|
|
289
|
+
L.push("## Skipped by reason", "");
|
|
290
|
+
const skips = plan.items.filter((i) => i.action.kind === "skip");
|
|
291
|
+
const shown = SKIP_REASONS.filter((r) => sum.byReason[r] > 0);
|
|
292
|
+
if (shown.length === 0) L.push("Nothing skipped.", "");
|
|
293
|
+
else {
|
|
294
|
+
L.push(...table(["Reason", "Sessions"], shown.map((r) => [r, String(sum.byReason[r])])), "");
|
|
295
|
+
for (const r of shown) {
|
|
296
|
+
const mine = skips.filter((i) => i.action.reason === r);
|
|
297
|
+
const ex = SKIP_EXPLANATION[r];
|
|
298
|
+
L.push(`### ${r} (${mine.length})`, "", `${ex[0] .toUpperCase()}${ex.slice(1)}.`, "");
|
|
299
|
+
for (const [h, detail] of Object.entries(SKIP_DETAIL[r] ?? {}) ) {
|
|
300
|
+
if (mine.some((i) => i.session.harness === h)) L.push(`${HARNESS_NAME[h]}: ${detail}.`, "");
|
|
301
|
+
}
|
|
302
|
+
for (const i of mine.slice(0, limit)) L.push(`- ${code(i.session.nativeId)} · ${i.session.harness} · ${i.session.accountId ?? "no account"}${i.session.cwd ? ` · ${code(i.session.cwd)}` : ""}`);
|
|
303
|
+
if (mine.length > limit) L.push(`- ... and ${mine.length - limit} more (see plan.json)`);
|
|
304
|
+
L.push("");
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
L.push("## Residual limits", "",
|
|
309
|
+
"- T3 Code shows at most 200 visible messages per imported thread.",
|
|
310
|
+
"- Tool activity (commands, file edits) is not part of the imported timeline, only the conversation text.",
|
|
311
|
+
"- Imported threads show the import time as their last activity.", "");
|
|
312
|
+
return L.join("\n");
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Each skip reason's short name on screen (plan.md keeps the codes and the long explanations). */
|
|
316
|
+
export const SKIP_WORDS = {
|
|
317
|
+
"already-in-t3": "plan.skip.alreadyInT3", "cwd-missing": "plan.skip.cwdMissing", "duplicate": "plan.skip.duplicate",
|
|
318
|
+
"mirror-copy": "plan.skip.mirrorCopy", "backup-copy": "plan.skip.backupCopy", "active": "plan.skip.active",
|
|
319
|
+
"non-uuid-id": "plan.skip.nonUuidId", "no-session-id": "plan.skip.noSessionId", "subagent": "plan.skip.subagent",
|
|
320
|
+
"compressed": "plan.skip.compressed", "too-large": "plan.skip.tooLarge", "only-hidden": "plan.skip.onlyHidden",
|
|
321
|
+
"over-4gib": "plan.skip.over4gib", "no-cwd": "plan.skip.noCwd", "cwd-unreadable": "plan.skip.cwdUnreadable",
|
|
322
|
+
"excluded": "plan.skip.excluded", "harness-unavailable": "plan.skip.harnessUnavailable", "compare-failed": "plan.skip.compareFailed",
|
|
323
|
+
"converted": "plan.skip.converted", "revision": "plan.skip.revision", "automated": "plan.skip.automated",
|
|
324
|
+
"temp-folder": "plan.skip.tempFolder", "system-folder": "plan.skip.systemFolder", "t3-refused": "plan.skip.t3Refused",
|
|
325
|
+
"undecided": "plan.skip.undecided", "orphaned-in-t3": "plan.skip.orphanedInT3", "t3-native-unknown": "plan.skip.t3NativeUnknown",
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* The plan on screen: a panel with the counts aligned, the notes that matter (compressed Codex sessions, copies from
|
|
340
|
+
* refused folders, decisions pending, the default instance pin), the imports by account and the top skips as tables,
|
|
341
|
+
* then where the full report is and what to run next.
|
|
342
|
+
*/
|
|
343
|
+
export function renderTerminalSummary(plan , opts ) {
|
|
344
|
+
const ui = opts.ui ?? makeCliUi({ color: opts.color ? 1 : 0, unicode: true, isTTY: false, columns: 80 }, "en");
|
|
345
|
+
const { s, t, f } = ui;
|
|
346
|
+
const width = Math.max(1, ui.width);
|
|
347
|
+
const sum = summarize(plan);
|
|
348
|
+
const names = Object.fromEntries(Object.entries({ ...Object.fromEntries(plan.instancesToCreate.map((i) => [i.id, i.displayName])), ...opts.names }).map(([k, v]) => [k, shownAccountName(v)]));
|
|
349
|
+
const counts = [
|
|
350
|
+
[t("plan.label.import"), sum.byAction.import ?? 0],
|
|
351
|
+
[t("plan.label.convert"), sum.byAction["convert-import"] ?? 0],
|
|
352
|
+
[t("plan.label.skip"), sum.byAction.skip ?? 0],
|
|
353
|
+
[t("plan.label.instances"), plan.instancesToCreate.length],
|
|
354
|
+
[t("plan.label.projects"), plan.projectsToCreate.length],
|
|
355
|
+
[t("plan.label.mirrors"), plan.mirrorCopies.length],
|
|
356
|
+
[t("plan.label.warnings"), planWarnings(plan, sum).length],
|
|
357
|
+
];
|
|
358
|
+
const nw = Math.max(...counts.map(([, n]) => f.n(n).length));
|
|
359
|
+
const rows = counts.map(([k, n]) => [k, s("num", padStart(f.n(n), nw))]);
|
|
360
|
+
if (opts.held && opts.held.roots.length > 0) {
|
|
361
|
+
const h = opts.held;
|
|
362
|
+
rows.push([t("apply.dry.held"), `${t("apply.dry.heldValue", { n: h.roots.length, sessions: h.sessions })} (${h.roots.map((r) => shownText(folderName(r), 60)).join(", ")}; ${t("apply.notThisRun")})`]);
|
|
363
|
+
}
|
|
364
|
+
const body = kv(s, rows, Math.max(1, width - 4));
|
|
365
|
+
const title = `${t("plan.title", { runId: shownText(plan.runId, 40) })} ${s.sym.sep} ${t("plan.t3", { version: shownText(plan.t3Version, 40) })}`;
|
|
366
|
+
const out = panel(s, { title, body }, snugWidth(title, body, width));
|
|
367
|
+
|
|
368
|
+
const notes = [];
|
|
369
|
+
const zst = compressedCodexLine(plan, ui.lang);
|
|
370
|
+
if (zst !== null) notes.push(zst);
|
|
371
|
+
notes.push(...rehomeLines(plan, (r) => shownText(r, 80), ui.lang, (x) => shownText(x, 80)));
|
|
372
|
+
if (plan.pinDefault) notes.push(t("plan.pin", { instance: shownText(plan.pinDefault.instanceId, 40), home: shownText(plan.pinDefault.homePath, 120) }));
|
|
373
|
+
if (notes.length > 0) out.push("");
|
|
374
|
+
for (const n of notes) out.push(...fitLine(`${s("accent", s.sym.sep)} ${n}`, width, 2));
|
|
375
|
+
const pending = plan.decisionsPending ?? [];
|
|
376
|
+
if (pending.length > 0) {
|
|
377
|
+
const n = pending.reduce((a, d) => a + d.sessions, 0);
|
|
378
|
+
const parts = pending.map((d) => `${DECISION_WORDS[d.key] ? t(DECISION_WORDS[d.key] ) : shownText(d.key, 40)} ${f.n(d.sessions)}`).join(", ");
|
|
379
|
+
const [first = "", ...rest] = wrapText(t("plan.decisions", { n, parts }), Math.max(1, width - 2));
|
|
380
|
+
out.push("", ...callout(s, { kind: "needs-you", title: first, body: rest, command: "t3sm start" }, width));
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const inst = Object.entries(sum.byInstance).sort((a, c) => c[1] - a[1]).slice(0, 5);
|
|
384
|
+
const num = (r ) => f.n((r )[1]);
|
|
385
|
+
if (inst.length > 0) {
|
|
386
|
+
out.push("", ...uiTable(s, [
|
|
387
|
+
{ header: t("plan.col.account"), get: (r) => shownText(names[(r )[0]] ?? (r )[0], 60), priority: 5 },
|
|
388
|
+
{ header: t("plan.col.count"), get: num, align: "right", priority: 9 },
|
|
389
|
+
], inst, width));
|
|
390
|
+
}
|
|
391
|
+
const top = SKIP_REASONS.filter((r) => sum.byReason[r] > 0).sort((a, c) => sum.byReason[c] - sum.byReason[a]).slice(0, 3).map((r) => [r, sum.byReason[r]]);
|
|
392
|
+
if (top.length > 0) {
|
|
393
|
+
out.push("", ...uiTable(s, [
|
|
394
|
+
{ header: t("plan.col.reason"), get: (r) => t(SKIP_WORDS[(r )[0]]), priority: 5 },
|
|
395
|
+
{ header: t("plan.col.count"), get: num, align: "right", priority: 9 },
|
|
396
|
+
], top, width));
|
|
397
|
+
}
|
|
398
|
+
// A path is never cut: when it does not fit beside its label it stands on its own line, whole; only a window too narrow
|
|
399
|
+
// for it alone breaks it (without indentation, so the pieces still read as one path).
|
|
400
|
+
const report = t("plan.fullReport", { path: s("path", opts.planPath) });
|
|
401
|
+
const pathLines = displayWidth(opts.planPath) <= width ? [s("path", opts.planPath)] : wrapText(opts.planPath, width);
|
|
402
|
+
out.push("", ...(displayWidth(report) <= width ? [report] : [t("plan.fullReport", { path: "" }).trimEnd(), ...pathLines]));
|
|
403
|
+
out.push(...fitLine(plan.mirrorCopies.length > 0
|
|
404
|
+
? t("plan.nextDedupe", { dedupe: s("key", "t3sm dedupe"), apply: s("key", "t3sm apply") })
|
|
405
|
+
: t("plan.next", { command: s("key", "t3sm apply") }), width, 2));
|
|
406
|
+
return out.join("\n") + "\n";
|
|
407
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { atomicWrite } from "../core/fsutil.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const isNum = (v ) => typeof v === "number" && Number.isFinite(v);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The file times a discovery cache recorded (any cache version: the times do not depend on the result format).
|
|
21
|
+
* A missing or corrupt cache reads as empty. Never writes.
|
|
22
|
+
*/
|
|
23
|
+
export async function readCachedMtimes(file ) {
|
|
24
|
+
try {
|
|
25
|
+
const j = JSON.parse(await readFile(file, "utf8")) ;
|
|
26
|
+
if (j.entries === null || typeof j.entries !== "object") return [];
|
|
27
|
+
const out = [];
|
|
28
|
+
for (const [path, v] of Object.entries(j.entries )) {
|
|
29
|
+
const m = v !== null && typeof v === "object" ? (v ).mtimeMs : undefined;
|
|
30
|
+
if (isNum(m)) out.push({ path, mtimeMs: m });
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
} catch {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Per-harness discovery cache keyed by transcript path. `validate` must check every field of the
|
|
40
|
+
* result; an entry that fails it is rescanned rather than partially trusted.
|
|
41
|
+
*/
|
|
42
|
+
export function createDiscoveryCache (
|
|
43
|
+
file ,
|
|
44
|
+
version ,
|
|
45
|
+
validate ,
|
|
46
|
+
) {
|
|
47
|
+
let old = {};
|
|
48
|
+
let fresh = {};
|
|
49
|
+
/** The file was read, valid, and every entry in it was kept (so an unchanged pass may skip the write). */
|
|
50
|
+
let loaded = false;
|
|
51
|
+
return {
|
|
52
|
+
async load() {
|
|
53
|
+
old = {};
|
|
54
|
+
fresh = {};
|
|
55
|
+
loaded = false;
|
|
56
|
+
try {
|
|
57
|
+
const j = JSON.parse(await readFile(file, "utf8")) ;
|
|
58
|
+
if (j.version !== version || j.entries === null || typeof j.entries !== "object") return;
|
|
59
|
+
loaded = true;
|
|
60
|
+
for (const [k, v] of Object.entries(j.entries )) {
|
|
61
|
+
if (v === null || typeof v !== "object") { loaded = false; continue; }
|
|
62
|
+
const e = v ;
|
|
63
|
+
if (isNum(e.size) && isNum(e.mtimeMs) && validate(e.result)) {
|
|
64
|
+
old[k] = { size: e.size, mtimeMs: e.mtimeMs, result: e.result };
|
|
65
|
+
} else loaded = false; // dropped: the file must be rewritten without it
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
old = {};
|
|
69
|
+
loaded = false;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
get(path, size, mtimeMs) {
|
|
73
|
+
const hit = old[path];
|
|
74
|
+
return hit && hit.size === size && hit.mtimeMs === mtimeMs ? hit.result : undefined;
|
|
75
|
+
},
|
|
76
|
+
set(path, size, mtimeMs, result) {
|
|
77
|
+
fresh[path] = { size, mtimeMs, result };
|
|
78
|
+
},
|
|
79
|
+
async save() {
|
|
80
|
+
// Nothing scanned, nothing pruned: the file on disk already says the same (idle sync cycles write nothing).
|
|
81
|
+
const oldKeys = Object.keys(old);
|
|
82
|
+
const freshKeys = Object.keys(fresh);
|
|
83
|
+
const same = loaded && oldKeys.length === freshKeys.length
|
|
84
|
+
&& freshKeys.every((k) => old[k] !== undefined && old[k] .size === fresh[k] .size && old[k] .mtimeMs === fresh[k] .mtimeMs && old[k] .result === fresh[k] .result);
|
|
85
|
+
if (same) return;
|
|
86
|
+
await atomicWrite(file, JSON.stringify({ version, entries: fresh }));
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|