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,1362 @@
|
|
|
1
|
+
// The eleven steps of the guided assistant. Each step starts with its header (the rail of the 11 steps), says what will
|
|
2
|
+
// happen in a few short lines, then asks; the long explanation is behind "?". A step never writes by itself: every write
|
|
3
|
+
// is one of t3sm's own commands, run through ctx.d.run only after an explicit "y" in the question right before it (write
|
|
4
|
+
// questions default to No). The exceptions, saving the assistant's language and the decisions / organize choices (the
|
|
5
|
+
// "organize" section), are config.json only: they go through ctx.d.saveLanguage and ctx.d.saveOrganize (under the
|
|
6
|
+
// lock), after a "y", except the decisions (step 5): each one is an explicit answer, saved right after the last one.
|
|
7
|
+
// The assistant never calls T3 Code's write API itself.
|
|
8
|
+
//
|
|
9
|
+
// The screens use the UI kit (src/ui/components.ts) at the terminal's width, at most 80 columns. Text from disk or T3
|
|
10
|
+
// Code (folders, titles, account names, a child's output) goes through shownText before it reaches the terminal.
|
|
11
|
+
|
|
12
|
+
import { DEFAULT_HISTORY, HISTORY_V2, organizeSettings, } from "../core/config.js";
|
|
13
|
+
|
|
14
|
+
import { isGlob, normalizeFolder, projectRows, } from "../ops/projects.js";
|
|
15
|
+
import { shownAccountName, shownText } from "../plan/names.js";
|
|
16
|
+
import { SKIP_REASONS, summarize } from "../plan/report.js";
|
|
17
|
+
import { expandHome, sameCwd, tildePath } from "../core/paths.js";
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
import { isShownMark } from "../organize/history.js";
|
|
21
|
+
import { reviewList, } from "../ui/list.js";
|
|
22
|
+
import { appHeader, callout, kv, panel, table, } from "../ui/components.js";
|
|
23
|
+
import { organizePreviewTable } from "../ui/organizePreview.js";
|
|
24
|
+
import { displayWidth, padStart, truncateEnd, truncateMiddle, wrapTo } from "../ui/text.js";
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
Back, Quit, Stop, TOTAL_STEPS, ask, askText, blank, glyphs, heading, lines, say, t, width,
|
|
29
|
+
|
|
30
|
+
} from "./core.js";
|
|
31
|
+
|
|
32
|
+
import { LOCK_BUSY_LINE } from "../cli/locked.js";
|
|
33
|
+
import { NOTHING_TO_CHANGE_MARKS } from "../cli/commands/projects.js";
|
|
34
|
+
import { checkName, checkWords } from "../cli/commands/doctor.js";
|
|
35
|
+
import { historyLine, previewWords } from "../cli/commands/organize.js";
|
|
36
|
+
import { flowAtoms, leadLines, snugWidth } from "../cli/screen.js";
|
|
37
|
+
|
|
38
|
+
/** `gated`: the step sent the user to the decisions before showing anything, so Back from there skips it (no bounce). */
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const NEXT = { to: "next" };
|
|
43
|
+
/** Projects per page of the plan's table: the summary, one page and the question fit 24 rows. */
|
|
44
|
+
const PAGE = 8;
|
|
45
|
+
const YES_WORDS = new Set(["y", "yes", "s", "sim"]);
|
|
46
|
+
const NO_WORDS = new Set(["n", "no", "não", "nao"]);
|
|
47
|
+
|
|
48
|
+
/** Named colours offered for an account (catalogue key, #RRGGBB). */
|
|
49
|
+
export const PALETTE = [
|
|
50
|
+
["colorBlue", "#2563EB"], ["colorGreen", "#16A34A"], ["colorOrange", "#EA580C"],
|
|
51
|
+
["colorPurple", "#7C3AED"], ["colorRed", "#DC2626"], ["colorTeal", "#0D9488"],
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
// allowUntested is kept for compatibility and is never set now (untested versions only warn).
|
|
55
|
+
const ut = (ctx ) => (ctx.allowUntested ? ["--allow-untested"] : []);
|
|
56
|
+
|
|
57
|
+
/** A folder for the screen: ~ for the home folder, sanitised, cut in the middle to `max` columns. */
|
|
58
|
+
function shown(ctx , folder , max = 40) {
|
|
59
|
+
return truncateMiddle(shownText(tildePath(folder, ctx.d.home)), max, ctx.s.sym.ellipsis);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A name from config.json or T3 Code (an account, a project), sanitised for the screen; never rewritten otherwise. */
|
|
63
|
+
export function nameOf(_ctx , s , max = 60) {
|
|
64
|
+
return shownText(s, max);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** An account's display name: like nameOf, with any email address in it masked (people name accounts after theirs). */
|
|
68
|
+
export function accountOf(_ctx , s , max = 60) {
|
|
69
|
+
return shownAccountName(s, max);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** `✓ text`, wrapped under its text: a short success line. */
|
|
73
|
+
function okLine(ctx , text ) {
|
|
74
|
+
const [first = "", ...rest] = wrapTo(text, Math.max(1, width(ctx) - 2));
|
|
75
|
+
lines(ctx, [`${ctx.s("ok", ctx.s.sym.ok)} ${ctx.s("title", first)}`, ...rest.map((l) => ` ${l}`)]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A number in the user's locale ("4 007" in Portuguese). */
|
|
79
|
+
const num = (ctx , n ) => ctx.f.n(n);
|
|
80
|
+
|
|
81
|
+
/** A body line of a panel: plain text, or a bullet (its symbol, then the text, which wraps under the text). */
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A panel as wide as its content needs (at most the screen). Its body is wrapped here, to the panel's inner width, so a
|
|
86
|
+
* bullet's continuation lines hang under its text (the panel itself would start them at the border).
|
|
87
|
+
*/
|
|
88
|
+
function box(ctx , o ) {
|
|
89
|
+
const w = width(ctx);
|
|
90
|
+
const inner = Math.max(1, w - 4);
|
|
91
|
+
// A bullet's text wraps in its own column, so every continuation line (a blank bullet's too) starts under the text.
|
|
92
|
+
const bulleted = (b ) => {
|
|
93
|
+
const pw = displayWidth(b.bullet) + 1;
|
|
94
|
+
return wrapTo(b.text, Math.max(1, inner - pw)).map((l, i) => (i === 0 ? `${b.bullet} ` : " ".repeat(pw)) + l);
|
|
95
|
+
};
|
|
96
|
+
const body = o.body.flatMap((b) => (typeof b === "string" ? wrapTo(b, inner) : bulleted(b)));
|
|
97
|
+
return panel(ctx.s, { ...o, body }, snugWidth(o.title, body, w));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Aligned `label value` rows for a panel body (the panel's border takes 4 columns). */
|
|
101
|
+
function rows(ctx , r ) {
|
|
102
|
+
return kv(ctx.s, r, Math.max(1, width(ctx) - 4));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Counts right-aligned in one column, so the numbers line up under each other. */
|
|
106
|
+
function counts(ctx , r ) {
|
|
107
|
+
const nw = Math.max(...r.map(([, n]) => num(ctx, n).length));
|
|
108
|
+
return r.map(([k, n, more]) => [k, ctx.s("num", padStart(num(ctx, n), nw)) + (more ? ` ${more}` : "")]);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Refuses (and ends the assistant, exit 0) when another t3sm run holds the lock right now. */
|
|
112
|
+
async function guardLock(ctx ) {
|
|
113
|
+
const h = await ctx.d.lockHolder();
|
|
114
|
+
if (h) { say(ctx, t(ctx, "lockedNow", { pid: h.pid })); throw new Stop(0); }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The journal `command` a run of `argv` writes (or null for a write journaled without a run-start, like an accounts
|
|
121
|
+
* change): a run that appeared meanwhile with another command belongs to another t3sm process (a sync), never to us.
|
|
122
|
+
*/
|
|
123
|
+
export function ownsRun(argv , command ) {
|
|
124
|
+
const c = command ?? "";
|
|
125
|
+
switch (argv[0]) {
|
|
126
|
+
case "apply": return argv.includes("--only") ? /^apply \S+ --only$/.test(c) : /^apply \S+$/.test(c);
|
|
127
|
+
case "quarantine": return c === "quarantine";
|
|
128
|
+
case "dedupe": return /^dedupe\b/.test(c);
|
|
129
|
+
case "rollback": return c === `rollback ${argv[argv.indexOf("--run") + 1] ?? ""}`;
|
|
130
|
+
case "projects": return c === "projects set";
|
|
131
|
+
case "organize": return c === "organize";
|
|
132
|
+
case "accounts": return command === null;
|
|
133
|
+
default: return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Runs a writing t3sm command (after the user's "y") and records it for the summary with the run id it journaled and
|
|
139
|
+
* how to undo it. The command prints its own screen (the progress bar, its result, its failures) as it runs. A command
|
|
140
|
+
* that found the lock taken (exit 0 with the lock-busy signal, or its line) did nothing: nothing is recorded, the
|
|
141
|
+
* assistant ends (exit 0). Exit 0 goes on; `tolerate` codes (5: some items failed) go on and are remembered; 130
|
|
142
|
+
* (Ctrl+C) and any other code end the assistant with that code.
|
|
143
|
+
*/
|
|
144
|
+
async function write(ctx , argv , what , o = {}) {
|
|
145
|
+
// busyReturns: a lock held by another run (before or during the command) is returned as `busy`, for the caller to retry.
|
|
146
|
+
const busy = { outcome: { code: 0, output: "", locked: true }, runId: null, busy: true };
|
|
147
|
+
if (o.busyReturns) { if (await ctx.d.lockHolder()) return busy; } else await guardLock(ctx);
|
|
148
|
+
const before = new Set((await ctx.d.runs()).map((r) => r.runId));
|
|
149
|
+
const outcome = await ctx.d.run(argv);
|
|
150
|
+
if (outcome.code === 0 && (outcome.locked === true || outcome.output.includes(LOCK_BUSY_LINE))) {
|
|
151
|
+
if (o.busyReturns) return busy;
|
|
152
|
+
say(ctx, t(ctx, "lockedRace"));
|
|
153
|
+
throw new Stop(0);
|
|
154
|
+
}
|
|
155
|
+
const fresh = (await ctx.d.runs()).filter((r) => !before.has(r.runId) && ownsRun(argv, r.command));
|
|
156
|
+
const runId = fresh.at(-1)?.runId ?? null;
|
|
157
|
+
const record = () => void ctx.done.push({ what, runId, undo: o.undo ? o.undo(runId) : null, ...(outcome.code !== 0 ? { partial: true } : {}) });
|
|
158
|
+
if (outcome.code !== 0 && !(o.tolerate ?? []).includes(outcome.code)) {
|
|
159
|
+
if (runId) record();
|
|
160
|
+
say(ctx, t(ctx, outcome.code === 130 ? "stepInterrupted" : "stepFailed", { code: outcome.code }));
|
|
161
|
+
throw new Stop(outcome.code);
|
|
162
|
+
}
|
|
163
|
+
ctx.worst = Math.max(ctx.worst, outcome.code);
|
|
164
|
+
record();
|
|
165
|
+
return { outcome, runId };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function buildPlan(ctx , key = "planBuilding") {
|
|
169
|
+
say(ctx, ctx.s("muted", t(ctx, key)));
|
|
170
|
+
ctx.plan = await ctx.d.plan(ctx.allowUntested, ctx.lang);
|
|
171
|
+
return ctx.plan;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const rowsOf = (p ) => projectRows(p.plan, p.names, null, p.config);
|
|
175
|
+
|
|
176
|
+
/** A write's symbol in the summaries: ✓ when it went through, ! when it ended with failures. */
|
|
177
|
+
const doneSym = (ctx , d ) => (d.partial ? ctx.s("warn", ctx.s.sym.warn) : ctx.s("ok", ctx.s.sym.ok));
|
|
178
|
+
|
|
179
|
+
/** The lines of "what this session did": each write with its run, and how to undo it. */
|
|
180
|
+
function didLines(ctx ) {
|
|
181
|
+
const out = [];
|
|
182
|
+
for (const d of ctx.done) {
|
|
183
|
+
out.push({ bullet: doneSym(ctx, d), text: d.runId ? t(ctx, "doneItemRun", { what: d.what, runId: d.runId }) : d.what });
|
|
184
|
+
if (d.undo) out.push({ bullet: " ", text: t(ctx, "doneUndoLine", { undo: d.undo }) });
|
|
185
|
+
}
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** "What this session did" as a panel: each write, its run id and how to undo it. Shown once (the last step, or any exit). */
|
|
190
|
+
export function summary(ctx ) {
|
|
191
|
+
ctx.summaryShown = true;
|
|
192
|
+
if (ctx.done.length === 0) { say(ctx, t(ctx, "doneNothing")); return; }
|
|
193
|
+
blank(ctx);
|
|
194
|
+
const body = didLines(ctx);
|
|
195
|
+
if (ctx.done.some((d) => d.runId !== null)) body.push("", t(ctx, "doneUndo"));
|
|
196
|
+
lines(ctx, box(ctx, { title: t(ctx, "doneHead"), body }));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** `--lang` given and config.json exists (now or since the plan): offers once to save the language there. */
|
|
200
|
+
async function offerLanguage(ctx ) {
|
|
201
|
+
if (ctx.langOffered || !ctx.langFromFlag) return;
|
|
202
|
+
const cfg = await ctx.d.config();
|
|
203
|
+
if (!cfg.exists) return;
|
|
204
|
+
ctx.langOffered = true;
|
|
205
|
+
if ((cfg.language ?? ctx.defaultLang) === ctx.lang) return; // the language t3sm would use anyway: nothing to save
|
|
206
|
+
if (!(await ask(ctx, t(ctx, "saveLangAsk"), { def: "n", help: t(ctx, "saveLangHelp"), back: false }))) return;
|
|
207
|
+
await guardLock(ctx);
|
|
208
|
+
if (!(await ctx.d.saveLanguage(ctx.lang))) { say(ctx, t(ctx, "lockedRace")); throw new Stop(0); }
|
|
209
|
+
ctx.done.push({ what: t(ctx, "didLanguage"), runId: null, undo: t(ctx, "undoLanguage") });
|
|
210
|
+
say(ctx, t(ctx, "langSaved"));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ---------------- 1 welcome ----------------
|
|
214
|
+
|
|
215
|
+
/** The steps a returning user sees as a checklist: ✓ done, ◉ next, ○ later (steps 3 to 11; 1 and 2 run every time). */
|
|
216
|
+
export function resumeChecklist(ctx , next ) {
|
|
217
|
+
const { s } = ctx;
|
|
218
|
+
const atoms = [];
|
|
219
|
+
for (let n = 3; n <= TOTAL_STEPS; n++) {
|
|
220
|
+
const title = t(ctx, `title${n}` );
|
|
221
|
+
const mark = n < next ? s("ok", s.sym.ok) : n === next ? s("accent", s.sym.cur) : s("muted", s.sym.ring);
|
|
222
|
+
atoms.push(`${mark}${" "}${n === next ? s("title", title.replace(/ /g, " ")) : title.replace(/ /g, " ")}${n < TOTAL_STEPS ? " " : ""}`);
|
|
223
|
+
}
|
|
224
|
+
return flowAtoms(atoms, Math.max(1, width(ctx) - 2), 0).map((l) => ` ${l.replace(/ /g, " ")}`.replace(/ +$/, ""));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** "y yes · n no · ...": a key stays with its word and a line never starts with the separator (a "-" without Unicode). */
|
|
228
|
+
function keyLegend(ctx ) {
|
|
229
|
+
const NB = "\u00a0";
|
|
230
|
+
const parts = ctx.m.welcomeKeys.split(" · ").map((x) => glyphs(ctx, x));
|
|
231
|
+
const atoms = parts.map((x, i) => x.replace(/ /g, NB) + (i < parts.length - 1 ? NB + ctx.s.sym.sep : ""));
|
|
232
|
+
return flowAtoms(atoms, width(ctx), 0).map((l) => ctx.s("muted", l.replace(/\u00a0/g, " ")));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export const welcome = async (ctx) => {
|
|
236
|
+
const about = await ctx.d.about().catch(() => null);
|
|
237
|
+
if (about) {
|
|
238
|
+
blank(ctx);
|
|
239
|
+
// The version is data (sanitised); the rule spans the screen.
|
|
240
|
+
lines(ctx, appHeader(ctx.s, { version: shownText(about.version, 20), subtitle: t(ctx, "appAccounts", { n: about.accounts }) }, width(ctx)));
|
|
241
|
+
}
|
|
242
|
+
heading(ctx, 1);
|
|
243
|
+
const r = ctx.resume;
|
|
244
|
+
if (r) {
|
|
245
|
+
say(ctx, t(ctx, "resumeHead"));
|
|
246
|
+
lines(ctx, resumeChecklist(ctx, r.step));
|
|
247
|
+
say(ctx, t(ctx, "resumeLast", { what: t(ctx, r.what, { n: r.n ?? 0 }) }));
|
|
248
|
+
say(ctx, t(ctx, "resumeNext", { n: r.step, title: t(ctx, `title${r.step}` ) }));
|
|
249
|
+
} else {
|
|
250
|
+
say(ctx, t(ctx, "welcomeBody"));
|
|
251
|
+
blank(ctx);
|
|
252
|
+
lines(ctx, box(ctx, { title: t(ctx, "welcomePanelTitle"), body: t(ctx, "welcomePanel").split("\n").map((l) => ({ bullet: ctx.s("accent", ctx.s.sym.sep), text: l })) }));
|
|
253
|
+
lines(ctx, keyLegend(ctx));
|
|
254
|
+
}
|
|
255
|
+
say(ctx, ctx.s("muted", t(ctx, "langSwitch")));
|
|
256
|
+
ctx.jumpTo = null;
|
|
257
|
+
ctx.pilotVerify = null;
|
|
258
|
+
if (r) {
|
|
259
|
+
// A returning user is asked one thing: continue where they were (y), or go through the steps again (n).
|
|
260
|
+
if (await ask(ctx, t(ctx, "resumeAsk", { n: r.step }), { def: "y", help: t(ctx, "resumeHelp"), back: false })) {
|
|
261
|
+
ctx.jumpTo = r.step;
|
|
262
|
+
ctx.pilotVerify = r.runId ?? null;
|
|
263
|
+
}
|
|
264
|
+
} else if (!(await ask(ctx, t(ctx, "welcomeAsk"), { def: "y", help: t(ctx, "welcomeHelp"), back: false }))) throw new Quit();
|
|
265
|
+
await offerLanguage(ctx);
|
|
266
|
+
return NEXT;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// ---------------- 2 check ----------------
|
|
270
|
+
|
|
271
|
+
const T3_DOWN = new Set(["t3-runtime", "t3-reachable"]);
|
|
272
|
+
|
|
273
|
+
/** What a doctor warning means for this user, decided by its check id and its structured data (never its English words). */
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* The relevance rule of each doctor warning (spec §5.4: "Worth knowing" only for things that matter to this user):
|
|
280
|
+
* - t3-version: never a callout; said once in the user's language (checkUntested).
|
|
281
|
+
* - instance-unpinned: hidden. The import pins the account's folder itself; there is nothing for the user to do.
|
|
282
|
+
* - t3sm-plugin (an outdated plugin): hidden here; the last step names the account and the update command.
|
|
283
|
+
* - harness:<agent> (from its data): unreadable files are always said, in words, with `t3sm scan` and the help topic.
|
|
284
|
+
* A missing instance for the agent is hidden here: whether it matters depends on whether any of that agent's sessions
|
|
285
|
+
* would be skipped for it, which only the plan knows; the plan step shows it then, with how many (planAgents). An
|
|
286
|
+
* agent with no sessions is never mentioned.
|
|
287
|
+
* - merge-pending (from its data): the sessions continued in a terminal, how many, a relative date and `t3sm merge`;
|
|
288
|
+
* the sessions with work on a side branch, and how to continue them.
|
|
289
|
+
* A check without data (an older doctor) is shown as doctor words it: the assistant never parses doctor's English.
|
|
290
|
+
* - backups-present, instances: shown, with the step that deals with them.
|
|
291
|
+
* - Any other warning: shown as doctor words it, with its fix.
|
|
292
|
+
* Doctor's words come from its catalogue parts (checkWords), in the user's language, as `t3sm doctor` shows them.
|
|
293
|
+
*/
|
|
294
|
+
export function relevance(ctx , c ) {
|
|
295
|
+
const w = checkWords(c, ctx.lang);
|
|
296
|
+
const msg = shownText(w.message, 600);
|
|
297
|
+
const fix = w.fix ? [t(ctx, "checkFix", { fix: shownText(w.fix, 600) })] : [];
|
|
298
|
+
if (c.id === "instance-unpinned") return { show: false, why: "the import pins it" };
|
|
299
|
+
if (c.id === "t3sm-plugin") return { show: false, why: "the last step offers the update" };
|
|
300
|
+
const d = c.data;
|
|
301
|
+
if (/^harness:/.test(c.id) && d && "harness" in d) {
|
|
302
|
+
// Unreadable files are always said; a missing instance only at the plan, which knows how many sessions it skips.
|
|
303
|
+
const name = AGENT_NAME[d.harness] ?? shownText(d.harness, 30);
|
|
304
|
+
if (d.readErrors > 0) return { show: true, body: [t(ctx, "checkReadErrors", { n: d.readErrors, name })] };
|
|
305
|
+
if (d.noInstance) return { show: false, why: "the plan step says it, only when sessions are skipped" };
|
|
306
|
+
}
|
|
307
|
+
if (c.id === "merge-pending" && d && "continued" in d) {
|
|
308
|
+
// The side branch first (continued in a terminal by hand); then the merge, which the command at the end is for.
|
|
309
|
+
const body = [];
|
|
310
|
+
if (d.sideBranch > 0) body.push(t(ctx, "checkSideBranch", { n: d.sideBranch }));
|
|
311
|
+
if (d.continued > 0) {
|
|
312
|
+
const when = Number.isNaN(Date.parse(d.at)) ? null : ctx.f.ago(d.at);
|
|
313
|
+
body.push(t(ctx, when ? "checkMerge" : "checkMergeNoDate", { n: d.continued, ago: when ?? "" }), t(ctx, "checkMergeWhy"));
|
|
314
|
+
}
|
|
315
|
+
if (body.length > 0) return { show: true, body, ...(d.continued > 0 ? { command: "t3sm merge" } : {}) };
|
|
316
|
+
}
|
|
317
|
+
if (c.id === "backups-present") return { show: true, body: [msg, t(ctx, "checkLater6")] };
|
|
318
|
+
if (c.id === "instances") return { show: true, body: [msg, t(ctx, "checkLater3")] };
|
|
319
|
+
return { show: true, body: [msg, ...fix] };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** The untested T3 Code version, from the check's own parts (an older doctor without them: its message's first word). */
|
|
323
|
+
function untestedVersion(c ) {
|
|
324
|
+
const v = c.say?.find((p) => p.key === "doctor.say.t3Version.untested")?.vars?.["version"];
|
|
325
|
+
return typeof v === "string" ? v : c.message.split(" ")[0] ?? "";
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** Every check as a compact grid: `✓ Node ! Backup folders ○ Pi sessions` (○: nothing to do here). */
|
|
329
|
+
function checkGrid(ctx , checks , hidden ) {
|
|
330
|
+
const { s } = ctx;
|
|
331
|
+
const cells = checks.map((c) => {
|
|
332
|
+
const sym = c.status === "fail" ? s("err", s.sym.err) : c.status === "warn" && !hidden.has(c) ? s("warn", s.sym.warn)
|
|
333
|
+
: c.status === "ok" ? s("ok", s.sym.ok) : s("muted", s.sym.ring);
|
|
334
|
+
return { sym, name: glyphs(ctx, checkName(ctx.ui, c.id)) };
|
|
335
|
+
});
|
|
336
|
+
const w = width(ctx);
|
|
337
|
+
const cw = Math.min(Math.max(...cells.map((c) => 2 + displayWidth(c.name))), Math.max(4, w - 2));
|
|
338
|
+
const per = Math.max(1, Math.floor((w - 2 + 3) / (cw + 3)));
|
|
339
|
+
const out = [];
|
|
340
|
+
for (let i = 0; i < cells.length; i += per) {
|
|
341
|
+
out.push((" " + cells.slice(i, i + per).map((c) => {
|
|
342
|
+
const name = truncateEnd(c.name, cw - 2, s.sym.ellipsis);
|
|
343
|
+
return `${c.sym} ${name}${" ".repeat(Math.max(0, cw - 2 - displayWidth(name)))}`;
|
|
344
|
+
}).join(" ")).replace(/ +$/, ""));
|
|
345
|
+
}
|
|
346
|
+
return out;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export const check = async (ctx) => {
|
|
350
|
+
heading(ctx, 2);
|
|
351
|
+
say(ctx, t(ctx, "checkIntro"));
|
|
352
|
+
let ids = [];
|
|
353
|
+
for (;;) {
|
|
354
|
+
say(ctx, ctx.s("muted", t(ctx, "checkRunning")));
|
|
355
|
+
const checks = await ctx.d.doctor();
|
|
356
|
+
if (checks.some((c) => c.status === "fail" && T3_DOWN.has(c.id))) {
|
|
357
|
+
lines(ctx, callout(ctx.s, { kind: "needs-you", title: t(ctx, "t3DownTitle"), body: [t(ctx, "t3Down")] }, width(ctx)));
|
|
358
|
+
if (await ask(ctx, t(ctx, "t3DownAsk"), { def: "y", help: t(ctx, "t3DownHelp") })) continue;
|
|
359
|
+
throw new Quit();
|
|
360
|
+
}
|
|
361
|
+
const fails = checks.filter((c) => c.status === "fail");
|
|
362
|
+
// An untested T3 Code version (same minor or not) is said once, in the user's language, instead of doctor's line.
|
|
363
|
+
const untested = checks.find((c) => c.id === "t3-version" && c.status === "warn");
|
|
364
|
+
const warns = checks.filter((c) => c.status === "warn" && c !== untested);
|
|
365
|
+
const judged = new Map(warns.map((c) => [c, relevance(ctx, c)] ));
|
|
366
|
+
const shownWarns = warns.filter((c) => judged.get(c) .show);
|
|
367
|
+
const hidden = new Set(warns.filter((c) => !judged.get(c) .show));
|
|
368
|
+
if (untested) hidden.add(untested);
|
|
369
|
+
ids = [...fails, ...shownWarns].map((c) => c.id);
|
|
370
|
+
const ok = checks.filter((c) => c.status === "ok" || hidden.has(c)).length;
|
|
371
|
+
const counted = checks.filter((c) => c.status !== "skip").length;
|
|
372
|
+
lines(ctx, leadLines(ctx.s, fails.length > 0
|
|
373
|
+
? { sym: ctx.s.sym.err, tone: "err", word: t(ctx, "checkProblems", { n: fails.length }), note: t(ctx, "checkPassed", { ok, n: counted }) }
|
|
374
|
+
: { sym: ctx.s.sym.ok, tone: "ok", word: t(ctx, shownWarns.length > 0 ? "checkReadyNotes" : "checkAllOk", { n: shownWarns.length }), note: t(ctx, "checkPassed", { ok, n: counted }) }, width(ctx)));
|
|
375
|
+
lines(ctx, checkGrid(ctx, checks, hidden));
|
|
376
|
+
if (fails.length > 0) {
|
|
377
|
+
blank(ctx);
|
|
378
|
+
say(ctx, t(ctx, "checkFailIntro"));
|
|
379
|
+
for (const c of fails) {
|
|
380
|
+
const w = checkWords(c, ctx.lang);
|
|
381
|
+
lines(ctx, callout(ctx.s, { kind: "needs-you", title: glyphs(ctx, checkName(ctx.ui, c.id)), body: [shownText(w.message, 600), ...(w.fix ? [t(ctx, "checkFix", { fix: shownText(w.fix, 600) })] : [])] }, width(ctx)));
|
|
382
|
+
}
|
|
383
|
+
say(ctx, t(ctx, "checkFailStop"));
|
|
384
|
+
throw new Stop(1);
|
|
385
|
+
}
|
|
386
|
+
if (untested) { blank(ctx); say(ctx, t(ctx, "checkUntested", { version: shownText(untestedVersion(untested), 60) })); }
|
|
387
|
+
if (shownWarns.length > 0) {
|
|
388
|
+
blank(ctx);
|
|
389
|
+
say(ctx, t(ctx, "checkWarnIntro"));
|
|
390
|
+
for (const c of shownWarns) {
|
|
391
|
+
const r = judged.get(c) ;
|
|
392
|
+
lines(ctx, callout(ctx.s, { kind: "warn", title: glyphs(ctx, checkName(ctx.ui, c.id)), body: r.body, ...(r.command ? { command: r.command } : {}) }, width(ctx)));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
if (ctx.jumpTo !== null) {
|
|
398
|
+
const step = ctx.jumpTo;
|
|
399
|
+
ctx.jumpTo = null;
|
|
400
|
+
ctx.fullDone = step >= 9;
|
|
401
|
+
return { to: "goto", step };
|
|
402
|
+
}
|
|
403
|
+
const help = t(ctx, "checkHelp") + (ids.length > 0 ? ` ${t(ctx, "checkIds", { ids: ids.join(", ") })}` : "");
|
|
404
|
+
if (!(await ask(ctx, t(ctx, "checkAsk"), { def: "y", help }))) throw new Quit();
|
|
405
|
+
return NEXT;
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
// ---------------- 3 accounts ----------------
|
|
409
|
+
|
|
410
|
+
async function ensureConfig(ctx ) {
|
|
411
|
+
if ((await ctx.d.config()).exists) return;
|
|
412
|
+
say(ctx, t(ctx, "accConfigFirst"));
|
|
413
|
+
await write(ctx, ["accounts", "--init"], t(ctx, "accConfigFirst"));
|
|
414
|
+
ctx.done.pop(); // part of the write the user just confirmed; the summary lists that write
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** A number from 1 to `max`; Enter is `def` when one is given. */
|
|
418
|
+
async function pickNumber(ctx , question , max , help , def ) {
|
|
419
|
+
for (;;) {
|
|
420
|
+
const a = await askText(ctx, question, { help });
|
|
421
|
+
if (a === "" && def !== undefined) return def;
|
|
422
|
+
const n = /^\d+$/.test(a) ? Number(a) : NaN;
|
|
423
|
+
if (n >= 1 && n <= max) return n;
|
|
424
|
+
say(ctx, t(ctx, "badNumber"));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
async function pickColor(ctx ) {
|
|
429
|
+
const names = Object.fromEntries(PALETTE.map(([k], i) => [`c${i + 1}`, ctx.m[k]]));
|
|
430
|
+
say(ctx, t(ctx, "accColors", names));
|
|
431
|
+
for (;;) {
|
|
432
|
+
const a = await askText(ctx, t(ctx, "accColorAsk"), { help: t(ctx, "accNamesHelp") });
|
|
433
|
+
if (a === "") return null;
|
|
434
|
+
const n = Number(a);
|
|
435
|
+
if (Number.isInteger(n) && n >= 1 && n <= PALETTE.length) { const [k, hex] = PALETTE[n - 1] ; return { hex, label: `${ctx.m[k]} ${hex}` }; }
|
|
436
|
+
if (n === 7) {
|
|
437
|
+
for (;;) {
|
|
438
|
+
const c = await askText(ctx, t(ctx, "accColorCustom"), { help: t(ctx, "accNamesHelp") });
|
|
439
|
+
if (/^#[0-9A-Fa-f]{6}$/.test(c)) return { hex: c.toUpperCase(), label: c.toUpperCase() };
|
|
440
|
+
say(ctx, t(ctx, "accColorBad"));
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
say(ctx, t(ctx, "badNumber"));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/** Where an account was found, in plain words. */
|
|
448
|
+
function foundFrom(ctx , r ) {
|
|
449
|
+
const word = (s ) => {
|
|
450
|
+
switch (s) {
|
|
451
|
+
case "default": return t(ctx, "via_default");
|
|
452
|
+
case "folder": return t(ctx, "via_folder");
|
|
453
|
+
case "shell-profile": return r.alias ? t(ctx, "via_shell", { alias: nameOf(ctx, r.alias, 40) }) : t(ctx, "via_shellNoAlias");
|
|
454
|
+
case "vscode-pin": return t(ctx, "via_vscode");
|
|
455
|
+
case "env": return t(ctx, "via_env");
|
|
456
|
+
case "t3-instance": return t(ctx, "via_t3");
|
|
457
|
+
case "config": return t(ctx, "via_config");
|
|
458
|
+
default: return nameOf(ctx, s, 40);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
return [...new Set(r.foundVia.map(word))].join(", ");
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** The accounts as a table: number, name, whether T3 Code has it, folder, email (masked). Where each was found goes under it. */
|
|
465
|
+
function accountTable(ctx , rs ) {
|
|
466
|
+
const { s } = ctx;
|
|
467
|
+
const cols = [
|
|
468
|
+
{ header: "#", get: (r) => String(rs.indexOf(r ) + 1), align: "right", priority: 10 },
|
|
469
|
+
{ header: t(ctx, "accColName"), get: (r) => accountOf(ctx, (r ).displayName, 40), priority: 9, min: 10 },
|
|
470
|
+
{ header: t(ctx, "accColT3"), get: (r) => ((r ).hasInstance ? `${s.sym.ok} ${t(ctx, "accYes")}` : `${s.sym.ring} ${t(ctx, "accNoInstance")}`), priority: 8 },
|
|
471
|
+
{ header: t(ctx, "accColFolder"), get: (r) => nameOf(ctx, (r ).home, 80), priority: 6, truncate: "middle", min: 12 },
|
|
472
|
+
{ header: t(ctx, "accColEmail"), get: (r) => ((r ).email ? nameOf(ctx, (r ).email , 60) : t(ctx, "accNoEmail")), priority: 4 },
|
|
473
|
+
];
|
|
474
|
+
return table(s, cols, rs, width(ctx));
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export const accounts = async (ctx) => {
|
|
478
|
+
heading(ctx, 3);
|
|
479
|
+
let rs = await ctx.d.accounts(ctx.allowUntested);
|
|
480
|
+
if (rs.length === 0) { say(ctx, t(ctx, "accNone")); throw new Stop(0); }
|
|
481
|
+
say(ctx, t(ctx, "accIntro", { n: rs.length }));
|
|
482
|
+
const show = () => {
|
|
483
|
+
blank(ctx);
|
|
484
|
+
lines(ctx, accountTable(ctx, rs));
|
|
485
|
+
// Where each account was found: free text, too long for a column, so one muted line each under the table.
|
|
486
|
+
for (const [i, r] of rs.entries()) say(ctx, ctx.s("muted", t(ctx, "accVia", { n: i + 1, via: foundFrom(ctx, r) })));
|
|
487
|
+
blank(ctx);
|
|
488
|
+
};
|
|
489
|
+
show();
|
|
490
|
+
const missing = rs.filter((r) => !r.hasInstance);
|
|
491
|
+
if (missing.length > 0) {
|
|
492
|
+
say(ctx, t(ctx, "accMissing", { n: missing.length, ids: missing.map((r) => nameOf(ctx, r.id, 40)).join(", ") }));
|
|
493
|
+
if (await ask(ctx, t(ctx, "accCreateAsk"), { def: "n", help: t(ctx, "accCreateHelp") })) {
|
|
494
|
+
await ensureConfig(ctx);
|
|
495
|
+
await write(ctx, ["accounts", "--apply", "--yes", ...ut(ctx)], t(ctx, "didInstances"), { undo: () => t(ctx, "undoInstances") });
|
|
496
|
+
rs = await ctx.d.accounts(ctx.allowUntested);
|
|
497
|
+
show();
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (await ask(ctx, t(ctx, "accNamesAsk"), { def: "y", help: t(ctx, "accNamesHelp") })) return NEXT;
|
|
501
|
+
for (;;) {
|
|
502
|
+
const r = rs[(await pickNumber(ctx, t(ctx, "accPick"), rs.length, t(ctx, "accNamesHelp"))) - 1] ;
|
|
503
|
+
if (!r.hasInstance) say(ctx, t(ctx, "accRenameNoInstance", { id: nameOf(ctx, r.id, 40) }));
|
|
504
|
+
else {
|
|
505
|
+
const name = (await askText(ctx, t(ctx, "accNameAsk", { id: nameOf(ctx, r.id, 40), name: accountOf(ctx, r.displayName, 40) }), { help: t(ctx, "accNamesHelp") })) || r.displayName;
|
|
506
|
+
const color = await pickColor(ctx);
|
|
507
|
+
const q = t(ctx, "accRenameAsk", { id: nameOf(ctx, r.id, 40), name: accountOf(ctx, name, 40), color: color ? t(ctx, "accRenameColor", { color: color.label }) : "" });
|
|
508
|
+
if (await ask(ctx, q, { def: "n", help: t(ctx, "accRenameHelp") })) {
|
|
509
|
+
await ensureConfig(ctx);
|
|
510
|
+
await write(ctx, ["accounts", "--rename", r.id, name, ...(color ? ["--color", color.hex] : []), ...ut(ctx)], t(ctx, "didRename", { id: nameOf(ctx, r.id, 40), name: accountOf(ctx, name, 40) }),
|
|
511
|
+
{ undo: (id) => (id ? t(ctx, "undoRename", { runId: id }) : null) });
|
|
512
|
+
rs = rs.map((x) => (x.id === r.id ? { ...x, displayName: name } : x));
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (!(await ask(ctx, t(ctx, "accMore"), { def: "n", help: t(ctx, "accNamesHelp") }))) return NEXT;
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// ---------------- 4 plan ----------------
|
|
520
|
+
|
|
521
|
+
const AGENT_NAME = { claude: "Claude Code", codex: "Codex", pi: "Pi", opencode: "OpenCode" };
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* The agents whose sessions this plan skips because T3 Code has no instance for them (skip reason
|
|
525
|
+
* harness-unavailable), with how many: the doctor's "no <agent> instance" warning, shown only when it matters.
|
|
526
|
+
*/
|
|
527
|
+
export function planAgents(p ) {
|
|
528
|
+
const by = new Map ();
|
|
529
|
+
for (const i of p.plan.items) if (i.action.kind === "skip" && i.action.reason === "harness-unavailable") by.set(i.session.harness, (by.get(i.session.harness) ?? 0) + 1);
|
|
530
|
+
return [...by.entries()].sort((a, b) => b[1] - a[1]).map(([harness, n]) => ({ harness, n }));
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** The plan's summary: a panel with the counts aligned (and the imports per account), then the notes that matter. */
|
|
534
|
+
function showSummary(ctx , p ) {
|
|
535
|
+
const sum = summarize(p.plan);
|
|
536
|
+
const imp = sum.byAction["import"] ?? 0;
|
|
537
|
+
const conv = sum.byAction["convert-import"] ?? 0;
|
|
538
|
+
const by = Object.entries(sum.byInstance).sort((a, b) => b[1] - a[1]);
|
|
539
|
+
// One column of numbers: the totals, then (with more than one account) the imports of each account under its own label.
|
|
540
|
+
const c = counts(ctx, [
|
|
541
|
+
[t(ctx, "planImport"), imp], [t(ctx, "planConvert"), conv], [t(ctx, "planSkip"), sum.byAction["skip"] ?? 0],
|
|
542
|
+
[t(ctx, "planNewProjects"), p.plan.projectsToCreate.length], [t(ctx, "planNewInstances"), p.plan.instancesToCreate.length],
|
|
543
|
+
...(by.length > 1 ? by.map(([id, n]) => [` ${accountOf(ctx, p.names[id] ?? id, 36)}`, n]) : []),
|
|
544
|
+
]);
|
|
545
|
+
if (by.length > 1) c.splice(5, 0, [t(ctx, "planByAccount"), ""]);
|
|
546
|
+
const body = rows(ctx, c);
|
|
547
|
+
blank(ctx);
|
|
548
|
+
lines(ctx, box(ctx, { title: t(ctx, "planHead"), body }));
|
|
549
|
+
if (conv > 0) say(ctx, t(ctx, "planConvertNote"));
|
|
550
|
+
const top = SKIP_REASONS.filter((r) => sum.byReason[r] > 0).sort((a, b) => sum.byReason[b] - sum.byReason[a]).slice(0, 3);
|
|
551
|
+
if (top.length > 0) say(ctx, t(ctx, "planTopSkips", { reasons: top.map((r) => `${ctx.m[`skip_${r}` ] ?? r} (${num(ctx, sum.byReason[r])})`).join(", ") }));
|
|
552
|
+
for (const a of planAgents(p)) {
|
|
553
|
+
const name = AGENT_NAME[a.harness] ?? nameOf(ctx, a.harness, 30);
|
|
554
|
+
lines(ctx, callout(ctx.s, { kind: "warn", title: t(ctx, "agentSkippedTitle", { name, n: a.n }), body: [t(ctx, "agentSkipped", { name })] }, width(ctx)));
|
|
555
|
+
}
|
|
556
|
+
if (imp + conv === 0) say(ctx, t(ctx, "planNothing"));
|
|
557
|
+
say(ctx, ctx.s("muted", t(ctx, "planReport", { path: shown(ctx, p.planPath, Math.max(10, width(ctx) - 16)) })));
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** Changes a project's account through `t3sm projects set` (the route, and the T3 Code default when it exists). */
|
|
561
|
+
async function changeAccount(ctx , row ) {
|
|
562
|
+
const p = ctx.plan ;
|
|
563
|
+
const folder = shown(ctx, row.folder, 60);
|
|
564
|
+
say(ctx, t(ctx, "planAccountFor", { folder }));
|
|
565
|
+
p.config.accounts.forEach((a, i) => say(ctx, ` ${i + 1}. ${accountOf(ctx, a.displayName, 40)} (${nameOf(ctx, a.id, 40)})`));
|
|
566
|
+
const acct = p.config.accounts[(await pickNumber(ctx, t(ctx, "planAccountAsk"), p.config.accounts.length, t(ctx, "planPageHelp"))) - 1] ;
|
|
567
|
+
// The undo puts back what config.json had: the folder's own route (its account), or no route at all.
|
|
568
|
+
const full = tildePath(row.folder, ctx.d.home);
|
|
569
|
+
const own = p.config.routes.find((r) => !isGlob(r.match) && sameCwd(r.match, row.folder))?.account ?? null;
|
|
570
|
+
const undoRoute = own ? t(ctx, "undoRouteBack", { folder: full, account: own }) : t(ctx, "undoRoute", { folder: full });
|
|
571
|
+
const name = accountOf(ctx, acct.displayName, 40);
|
|
572
|
+
if (!(await ask(ctx, t(ctx, "planRouteAsk", { folder, name, undo: undoRoute }), { def: "n", help: t(ctx, "planRouteHelp") }))) return false;
|
|
573
|
+
const { outcome } = await write(ctx, ["projects", "set", row.folder, acct.id, "--yes", ...ut(ctx)], t(ctx, "didRoute", { folder, name }),
|
|
574
|
+
{ undo: (id) => undoRoute + (id ? t(ctx, "undoT3Default", { runId: id }) : "") });
|
|
575
|
+
if (NOTHING_TO_CHANGE_MARKS.some((m) => outcome.output.includes(m))) { ctx.done.pop(); return false; } // nothing was written
|
|
576
|
+
await buildPlan(ctx, "planRouteSaved");
|
|
577
|
+
return true;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/** One page of the project table: number, project, account, why that account. */
|
|
581
|
+
function projectTable(ctx , page , start ) {
|
|
582
|
+
const cols = [
|
|
583
|
+
{ header: "#", get: (r) => String(start + page.indexOf(r ) + 1), align: "right", priority: 10 },
|
|
584
|
+
{ header: t(ctx, "colProject"), get: (r) => shown(ctx, (r ).folder, 60), priority: 9, truncate: "middle", min: 12 },
|
|
585
|
+
{ header: t(ctx, "colAccount"), get: (r) => accountOf(ctx, (r ).accountName, 30), priority: 8, min: 8 },
|
|
586
|
+
{ header: t(ctx, "colWhy"), get: (r) => t(ctx, `reason_${(r ).reason}` ), priority: 5 },
|
|
587
|
+
];
|
|
588
|
+
return table(ctx.s, cols, page, width(ctx));
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
export const plan = async (ctx) => {
|
|
592
|
+
heading(ctx, 4);
|
|
593
|
+
say(ctx, t(ctx, "planIntro"));
|
|
594
|
+
let p = await buildPlan(ctx);
|
|
595
|
+
showSummary(ctx, p);
|
|
596
|
+
for (let start = 0; ;) {
|
|
597
|
+
const rs = rowsOf(p);
|
|
598
|
+
if (rs.length === 0) return NEXT;
|
|
599
|
+
if (start === 0) { blank(ctx); say(ctx, t(ctx, "planTableIntro")); }
|
|
600
|
+
const page = rs.slice(start, start + PAGE);
|
|
601
|
+
lines(ctx, projectTable(ctx, page, start));
|
|
602
|
+
const last = start + PAGE >= rs.length;
|
|
603
|
+
if (rs.length > PAGE) say(ctx, ctx.s("muted", t(ctx, "planPage", { from: start + 1, to: start + page.length, total: rs.length })));
|
|
604
|
+
const a = (await askText(ctx, t(ctx, last ? "planLastAsk" : "planMoreAsk"), { help: t(ctx, "planPageHelp") })).toLowerCase();
|
|
605
|
+
// c, y and n (no change) all continue; Enter turns the page, or continues on the last one.
|
|
606
|
+
if (a === "c" || YES_WORDS.has(a) || NO_WORDS.has(a) || (a === "" && last)) return NEXT;
|
|
607
|
+
if (a === "") { start += PAGE; continue; }
|
|
608
|
+
const n = /^\d+$/.test(a) ? Number(a) : NaN;
|
|
609
|
+
if (!(n >= 1 && n <= rs.length)) { say(ctx, t(ctx, "badNumber")); continue; }
|
|
610
|
+
if (await changeAccount(ctx, rs[n - 1] )) { p = ctx.plan ; showSummary(ctx, p); start = 0; }
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
// ---------------- 5 decisions ----------------
|
|
615
|
+
|
|
616
|
+
/** The terminal for a review list: the assistant's own, whose input the lists share but never close. */
|
|
617
|
+
function listTerm(ctx ) {
|
|
618
|
+
return Object.create(ctx.d.term, { dispose: { value: undefined } }) ;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/** config.json "organize", under the lock, only after the "y" the caller just got. A held lock ends the assistant. */
|
|
622
|
+
async function saveSettings(ctx , patch , what , undo ) {
|
|
623
|
+
await guardLock(ctx);
|
|
624
|
+
if (!(await ctx.d.saveOrganize(patch))) { say(ctx, t(ctx, "lockedRace")); throw new Stop(0); }
|
|
625
|
+
ctx.done.push({ what, runId: null, undo });
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
const FOLDER_YES = (yes ) => (yes ? "rehome" : "skip");
|
|
630
|
+
const TEMP_YES = (yes ) => (yes ? "import" : "skip");
|
|
631
|
+
/** The questions the planner can leave pending, in the words the assistant asks them (the keys are `organize.decided`'s). */
|
|
632
|
+
const DECISIONS = {
|
|
633
|
+
home: { topic: "decHomeTopic", say: "decHomeSay", ask: "decHomeAsk", why: "decHomeWhy", setting: 'organize.folders.home ("rehome" | "import" | "skip")', yes: true, value: FOLDER_YES },
|
|
634
|
+
"t3-refused": { topic: "decRefusedTopic", say: "decRefusedSay", ask: "decRefusedAsk", why: "decRefusedWhy", setting: 'organize.folders["t3-refused"] ("rehome" | "import" | "skip")', yes: true, value: FOLDER_YES },
|
|
635
|
+
temp: { topic: "decTempTopic", say: "decTempSay", ask: "decTempAsk", why: "decTempWhy", setting: 'organize.folders.temp ("import" | "skip" | "rehome")', yes: false, value: TEMP_YES },
|
|
636
|
+
system: { topic: "decSystemTopic", say: "decSystemSay", ask: "decSystemAsk", why: "decSystemWhy", setting: 'organize.folders.system ("import" | "skip" | "rehome")', yes: false, value: TEMP_YES },
|
|
637
|
+
automated: { topic: "decAutoTopic", say: "decAutoSay", ask: "decAutoAsk", why: "decAutoWhy", setting: 'organize.sessions.automated ("import" | "skip")', yes: false, value: TEMP_YES },
|
|
638
|
+
orphaned: { topic: "decOrphanedTopic", say: "decOrphanedSay", ask: "decOrphanedAsk", why: "decOrphanedWhy", setting: 'organize.sessions.orphaned ("copy" | "skip")', yes: true, value: (yes) => (yes ? "copy" : "skip") },
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Pending questions are a gate: a step that has just built a fresh plan sends the user to the decisions step first when
|
|
643
|
+
* the plan has questions in DECISIONS that were not asked in this session, and the decisions step comes back to `from`.
|
|
644
|
+
* Null: nothing to ask. Without this, a returning user resumed at the import and the questions the plan found since last
|
|
645
|
+
* time were skipped (their conversations silently left out).
|
|
646
|
+
*/
|
|
647
|
+
export async function gateDecisions(ctx , from ) {
|
|
648
|
+
const pending = (ctx.plan?.plan.decisionsPending ?? []).filter((d) => Object.hasOwn(DECISIONS, d.key) && !ctx.asked.has(d.key));
|
|
649
|
+
if (pending.length === 0) return null;
|
|
650
|
+
blank(ctx);
|
|
651
|
+
lines(ctx, callout(ctx.s, { kind: "needs-you", title: t(ctx, "decisionsNewTitle", { n: pending.length }), body: [t(ctx, "decisionsNew", { n: pending.length })] }, width(ctx)));
|
|
652
|
+
ctx.returnTo = from;
|
|
653
|
+
return { to: "goto", step: 5, gated: true };
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/** Where the decisions step goes when it ends: back to the step that called the gate, else the next one. */
|
|
657
|
+
function afterDecisions(ctx ) {
|
|
658
|
+
const back = ctx.returnTo;
|
|
659
|
+
ctx.returnTo = null;
|
|
660
|
+
return back === null ? NEXT : { to: "goto", step: back };
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/** One group of moved conversations: the folder they came from, how many, and where the planner put them. */
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
function moveGroups(p ) {
|
|
667
|
+
const groups = new Map ();
|
|
668
|
+
for (const i of p.plan.items) {
|
|
669
|
+
if (i.action.kind !== "convert-import" || i.action.rehomeFrom === undefined) continue;
|
|
670
|
+
const g = groups.get(i.action.rehomeFrom) ?? { from: i.action.rehomeFrom, n: 0, to: new Map(), share: null, shared: 0 };
|
|
671
|
+
g.n++;
|
|
672
|
+
if (i.action.rehomeShare) {
|
|
673
|
+
g.shared++;
|
|
674
|
+
g.share = { hits: (g.share?.hits ?? 0) + i.action.rehomeShare.hits, total: (g.share?.total ?? 0) + i.action.rehomeShare.total };
|
|
675
|
+
}
|
|
676
|
+
g.to.set(i.action.projectRoot, (g.to.get(i.action.projectRoot) ?? 0) + 1);
|
|
677
|
+
groups.set(g.from, g);
|
|
678
|
+
}
|
|
679
|
+
return [...groups.values()].sort((a, b) => b.n - a.n || (a.from < b.from ? -1 : 1));
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
const OTHER_PROJECTS = 12;
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* After the answers are saved and the plan redone: shows where each group of copied conversations goes (inferred
|
|
686
|
+
* project or the General one), lets the user change a destination or leave a group out, and saves the changes as
|
|
687
|
+
* `organize.overrides` (folder -> `rehome:<root>` or `skip`). The names of the projects to create are only shown.
|
|
688
|
+
*/
|
|
689
|
+
async function moveReview(ctx ) {
|
|
690
|
+
const p = ctx.plan ;
|
|
691
|
+
const groups = moveGroups(p);
|
|
692
|
+
if (groups.length === 0) return;
|
|
693
|
+
const home = ctx.d.home;
|
|
694
|
+
const settings = organizeSettings(p.config, ctx.lang);
|
|
695
|
+
const generalTitle = ctx.lang === "pt" ? "Geral" : "General";
|
|
696
|
+
const general = p.plan.projectsToCreate.find((x) => x.title === generalTitle)?.root ?? expandHome(settings.generalFolder, home);
|
|
697
|
+
const isGeneral = (root ) => sameCwd(root, general);
|
|
698
|
+
const roots = new Set(groups.flatMap((g) => [...g.to.keys()]));
|
|
699
|
+
|
|
700
|
+
const created = p.plan.projectsToCreate.filter((x) => roots.has(x.root));
|
|
701
|
+
blank(ctx);
|
|
702
|
+
say(ctx, t(ctx, "decMoveIntro"));
|
|
703
|
+
if (created.length > 0) say(ctx, t(ctx, "decNames", { count: created.length, names: created.map((x) => `"${nameOf(ctx, x.title, 40)}"`).join(", ") }));
|
|
704
|
+
|
|
705
|
+
// Other projects a group could go to: the ones this plan imports into, busiest first.
|
|
706
|
+
const known = new Map ();
|
|
707
|
+
for (const i of p.plan.items) {
|
|
708
|
+
if ((i.action.kind !== "import" && i.action.kind !== "convert-import") || (i.action.kind === "convert-import" && i.action.rehomeFrom !== undefined)) continue;
|
|
709
|
+
known.set(i.action.projectRoot, (known.get(i.action.projectRoot) ?? 0) + 1);
|
|
710
|
+
}
|
|
711
|
+
const others = [...known.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).slice(0, OTHER_PROJECTS).map(([r]) => r);
|
|
712
|
+
|
|
713
|
+
const choiceAction = new Map ();
|
|
714
|
+
const items = groups.map((g, idx) => {
|
|
715
|
+
const dests = [...g.to.keys()];
|
|
716
|
+
const single = dests.length === 1 ? dests[0] : null;
|
|
717
|
+
const suggested = single === null ? t(ctx, "decChoiceSuggestedMixed")
|
|
718
|
+
: t(ctx, isGeneral(single) ? "decChoiceSuggestedGeneral" : "decChoiceSuggested", { path: shown(ctx, single, 50) });
|
|
719
|
+
const actions = new Map ([[suggested, null]]);
|
|
720
|
+
const add = (text , action ) => void (actions.has(text) || actions.set(text, action));
|
|
721
|
+
for (const r of others) if (single === null || !sameCwd(r, single)) add(shown(ctx, r, 60), `rehome:${tildePath(r, home)}`);
|
|
722
|
+
if (single === null || !isGeneral(single)) add(t(ctx, "decChoiceGeneral", { path: shown(ctx, general, 50) }), `rehome:${tildePath(general, home)}`);
|
|
723
|
+
add(t(ctx, "decChoiceSkip"), "skip");
|
|
724
|
+
choiceAction.set(String(idx), actions);
|
|
725
|
+
const project = single === null ? "" : (tildePath(single, home).split("/").filter((x) => x !== "").at(-1) ?? single);
|
|
726
|
+
const share = g.share !== null && g.shared === g.n && single !== null && !isGeneral(single) ? t(ctx, "decShare", { hits: g.share.hits, total: g.share.total, project: nameOf(ctx, project, 40) }) : null;
|
|
727
|
+
const where = single === null ? t(ctx, "decToMixed") : isGeneral(single) ? t(ctx, "decToGeneral", { path: shown(ctx, single, 50) }) : share !== null ? ` ${share}.` : t(ctx, "decToInferred", { path: shown(ctx, single, 50) });
|
|
728
|
+
const folder = shown(ctx, g.from, 50) + (sameCwd(g.from, home) ? ` ${t(ctx, "decHomeTag")}` : "");
|
|
729
|
+
const label = g.n === 1 ? t(ctx, "decRowOne", { folder }) : t(ctx, "decRowMany", { folder, n: g.n });
|
|
730
|
+
return {
|
|
731
|
+
id: String(idx), label, checked: true,
|
|
732
|
+
detail: t(ctx, sameCwd(g.from, home) ? "decWhyHome" : "decWhyRefused") + where,
|
|
733
|
+
editable: { prompt: t(ctx, "decEditPrompt"), value: suggested, choices: [...actions.keys()] },
|
|
734
|
+
};
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
blank(ctx);
|
|
738
|
+
const r = await reviewList(listTerm(ctx), { title: t(ctx, "decListTitle"), help: t(ctx, "decListHelp"), items, lang: ctx.lang });
|
|
739
|
+
const changes = [];
|
|
740
|
+
if (r.confirmed) {
|
|
741
|
+
r.items.forEach((it, idx) => {
|
|
742
|
+
const action = it.checked ? (choiceAction.get(it.id)?.get(it.editable?.value ?? "") ?? null) : "skip";
|
|
743
|
+
if (action !== null) changes.push({ match: tildePath(groups[idx] .from, home), action });
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
if (changes.length === 0) { say(ctx, t(ctx, "decMoveNone")); return; }
|
|
747
|
+
if (!(await ask(ctx, t(ctx, "decMoveSaveAsk"), { def: "n", help: t(ctx, "decMoveSaveHelp") }))) { say(ctx, t(ctx, "decMoveNotSaved")); return; }
|
|
748
|
+
const kept = (p.config.organize?.overrides ?? []).filter((o) => !changes.some((c) => sameCwd(expandHome(o.match, home), expandHome(c.match, home))));
|
|
749
|
+
await saveSettings(ctx, { overrides: [...kept, ...changes] }, t(ctx, "didOverrides"), t(ctx, "undoOverrides"));
|
|
750
|
+
say(ctx, t(ctx, "decMoveSaved"));
|
|
751
|
+
await buildPlan(ctx, "decReplan");
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/** Leaving the step with Back drops the gate's return point: a later normal visit must go on to the next step. */
|
|
755
|
+
export const decisions = async (ctx) => {
|
|
756
|
+
try { return await decisionsStep(ctx); } catch (e) { if (e instanceof Back) ctx.returnTo = null; throw e; }
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
const decisionsStep = async (ctx) => {
|
|
760
|
+
const p = ctx.plan ?? (await buildPlan(ctx));
|
|
761
|
+
const pending = (p.plan.decisionsPending ?? []).filter((d) => Object.hasOwn(DECISIONS, d.key));
|
|
762
|
+
if (pending.length === 0) return ctx.returnTo === null ? { to: "skip" } : afterDecisions(ctx);
|
|
763
|
+
heading(ctx, 5);
|
|
764
|
+
say(ctx, t(ctx, "decisionsIntro", { n: pending.length }));
|
|
765
|
+
const general = ctx.lang === "pt" ? "Geral" : "General";
|
|
766
|
+
const answers = new Map ();
|
|
767
|
+
for (const [i, d] of pending.entries()) {
|
|
768
|
+
const q = DECISIONS[d.key] ;
|
|
769
|
+
blank(ctx);
|
|
770
|
+
// One panel per question: what happened, then the default and where to change it later.
|
|
771
|
+
const body = [t(ctx, q.say, { sessions: d.sessions, folders: d.folders, general }), "", ...rows(ctx, [
|
|
772
|
+
[t(ctx, "decDefaultLabel"), t(ctx, q.why)], [t(ctx, "decLaterLabel"), q.setting],
|
|
773
|
+
])];
|
|
774
|
+
lines(ctx, box(ctx, { title: t(ctx, "decPanelTitle", { i: i + 1, n: pending.length, topic: t(ctx, q.topic) }), body }));
|
|
775
|
+
const help = t(ctx, "decHelp", { why: t(ctx, q.why), setting: q.setting, key: d.key });
|
|
776
|
+
answers.set(d.key, await ask(ctx, t(ctx, q.ask, { sessions: d.sessions, folders: d.folders }), { def: q.yes ? "y" : "n", help }));
|
|
777
|
+
ctx.asked.add(d.key);
|
|
778
|
+
}
|
|
779
|
+
const patch = { decided: pending.map((d) => d.key) };
|
|
780
|
+
for (const d of pending) {
|
|
781
|
+
const yes = answers.get(d.key) ;
|
|
782
|
+
if (d.key === "automated") patch.sessions = { ...patch.sessions, automated: DECISIONS[d.key] .value(yes) };
|
|
783
|
+
else if (d.key === "orphaned") patch.sessions = { ...patch.sessions, orphaned: DECISIONS[d.key] .value(yes) };
|
|
784
|
+
else patch.folders = { ...patch.folders, [d.key]: DECISIONS[d.key] .value(yes) };
|
|
785
|
+
}
|
|
786
|
+
// The answers are the decision: saved at once (config.json only, under the lock). A separate "save?" question with a
|
|
787
|
+
// default No left every conversation of the answered questions out of the import (0.3.0). q or b before the last
|
|
788
|
+
// answer leaves the loop above by its exception, so nothing is saved then.
|
|
789
|
+
blank(ctx);
|
|
790
|
+
await saveSettings(ctx, patch, t(ctx, "didDecisions"), t(ctx, "undoDecisions"));
|
|
791
|
+
okLine(ctx, t(ctx, "decSaved"));
|
|
792
|
+
await buildPlan(ctx, "decReplan");
|
|
793
|
+
if (answers.get("home") === true || answers.get("t3-refused") === true) await moveReview(ctx);
|
|
794
|
+
return afterDecisions(ctx);
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
// ---------------- 6 clean-up ----------------
|
|
798
|
+
|
|
799
|
+
export const cleanup = async (ctx) => {
|
|
800
|
+
const p = ctx.plan ?? (await buildPlan(ctx));
|
|
801
|
+
const gate = await gateDecisions(ctx, 6);
|
|
802
|
+
if (gate) return gate;
|
|
803
|
+
const c = await ctx.d.cleanupCounts(p.plan);
|
|
804
|
+
if (c.backupFolders === 0 && c.mirrorCopies === 0) return { to: "skip" };
|
|
805
|
+
heading(ctx, 6);
|
|
806
|
+
say(ctx, t(ctx, "cleanIntro"));
|
|
807
|
+
const found = [];
|
|
808
|
+
if (c.backupFolders > 0) found.push([t(ctx, "cleanBackupsLabel"), c.backupFolders, t(ctx, "cleanBackupsWhat", { n: c.backupFolders })]);
|
|
809
|
+
if (c.mirrorCopies > 0) found.push([t(ctx, "cleanMirrorsLabel"), c.mirrorCopies, t(ctx, "cleanMirrorsWhat", { n: c.mirrorCopies })]);
|
|
810
|
+
blank(ctx);
|
|
811
|
+
lines(ctx, box(ctx, { title: t(ctx, "cleanHead"), body: [...rows(ctx, counts(ctx, found)), "", t(ctx, "cleanReversible")] }));
|
|
812
|
+
const undo = (id) => (id ? t(ctx, "undoMove", { runId: id }) : null);
|
|
813
|
+
let moved = false;
|
|
814
|
+
if (c.backupFolders > 0 && (await ask(ctx, t(ctx, "cleanQuarantineAsk"), { def: "n", help: t(ctx, "cleanQuarantineHelp") }))) {
|
|
815
|
+
await write(ctx, ["quarantine", "--yes"], t(ctx, "didQuarantine"), { tolerate: [5], undo });
|
|
816
|
+
moved = true;
|
|
817
|
+
}
|
|
818
|
+
if (c.mirrorCopies > 0 && (await ask(ctx, t(ctx, "cleanDedupeAsk"), { def: "n", help: t(ctx, "cleanDedupeHelp") }))) {
|
|
819
|
+
await write(ctx, ["dedupe", "--yes"], t(ctx, "didDedupe"), { tolerate: [5], undo });
|
|
820
|
+
moved = true;
|
|
821
|
+
}
|
|
822
|
+
if (!moved) say(ctx, t(ctx, "cleanNoOk"));
|
|
823
|
+
else await buildPlan(ctx, "cleanRefreshing");
|
|
824
|
+
return NEXT;
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
// ---------------- 7 pilot ----------------
|
|
828
|
+
|
|
829
|
+
/** "Here is what I will do", with the counts aligned and how to undo it. */
|
|
830
|
+
function willDo(ctx , r ) {
|
|
831
|
+
blank(ctx);
|
|
832
|
+
lines(ctx, box(ctx, { title: t(ctx, "willHead"), body: rows(ctx, r) }));
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/** Asks whether the pilot looks right; on no, offers to undo that run, then stops with the next steps. */
|
|
836
|
+
async function verifyPilot(ctx , runId ) {
|
|
837
|
+
if (await ask(ctx, t(ctx, "pilotOkAsk"), { def: "y", help: t(ctx, "pilotOkHelp"), back: false })) return NEXT;
|
|
838
|
+
if (await ask(ctx, t(ctx, "pilotUndoAsk", { runId }), { def: "n", help: t(ctx, "pilotUndoHelp", { runId }), back: false })) {
|
|
839
|
+
await write(ctx, ["rollback", "--run", runId, "--yes", "--archive-threads", ...ut(ctx)], t(ctx, "didUndo"), { tolerate: [5] });
|
|
840
|
+
}
|
|
841
|
+
say(ctx, t(ctx, "pilotStopped"));
|
|
842
|
+
throw new Stop(0);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/** The suggested pilot projects as a table: number, project, conversations to import, account. */
|
|
846
|
+
function pilotTable(ctx , sugg ) {
|
|
847
|
+
const cols = [
|
|
848
|
+
{ header: "#", get: (r) => String(sugg.indexOf(r ) + 1), align: "right", priority: 10 },
|
|
849
|
+
{ header: t(ctx, "colProject"), get: (r) => shown(ctx, (r ).folder, 60), priority: 9, truncate: "middle", min: 12 },
|
|
850
|
+
{ header: t(ctx, "colConversations"), get: (r) => num(ctx, (r ).pending), align: "right", priority: 8 },
|
|
851
|
+
{ header: t(ctx, "colAccount"), get: (r) => accountOf(ctx, (r ).accountName, 30), priority: 5 },
|
|
852
|
+
];
|
|
853
|
+
return table(ctx.s, cols, sugg, width(ctx));
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
export const pilot = async (ctx) => {
|
|
857
|
+
heading(ctx, 7);
|
|
858
|
+
if (ctx.pilotVerify) {
|
|
859
|
+
// Back after a pilot (the user stopped at "Does it look right?" last time): check it before anything else.
|
|
860
|
+
const runId = ctx.pilotVerify;
|
|
861
|
+
ctx.pilotVerify = null;
|
|
862
|
+
say(ctx, t(ctx, "pilotCheckAgain", { runId }));
|
|
863
|
+
return verifyPilot(ctx, runId);
|
|
864
|
+
}
|
|
865
|
+
const p = ctx.plan ?? (await buildPlan(ctx));
|
|
866
|
+
const gate = await gateDecisions(ctx, 7);
|
|
867
|
+
if (gate) return gate;
|
|
868
|
+
const all = rowsOf(p).filter((r) => r.pending > 0);
|
|
869
|
+
if (all.length === 0) { say(ctx, t(ctx, "pilotNone")); return NEXT; }
|
|
870
|
+
const sugg = all.filter((r) => !r.held).sort((a, b) => a.pending - b.pending || a.folder.localeCompare(b.folder)).slice(0, 5);
|
|
871
|
+
say(ctx, t(ctx, "pilotIntro"));
|
|
872
|
+
if (sugg.length > 0) {
|
|
873
|
+
blank(ctx);
|
|
874
|
+
say(ctx, t(ctx, "pilotSuggest"));
|
|
875
|
+
lines(ctx, pilotTable(ctx, sugg));
|
|
876
|
+
}
|
|
877
|
+
let chosen = null;
|
|
878
|
+
while (!chosen) {
|
|
879
|
+
const a = await askText(ctx, t(ctx, "pilotAsk", { max: Math.max(1, sugg.length) }), { help: t(ctx, "pilotHelp") });
|
|
880
|
+
const l = a.toLowerCase();
|
|
881
|
+
if (NO_WORDS.has(l)) { say(ctx, t(ctx, "pilotSkipped")); return NEXT; }
|
|
882
|
+
if (YES_WORDS.has(l)) { say(ctx, t(ctx, "pilotBadAnswer")); continue; } // a yes is not a folder name
|
|
883
|
+
if (a === "" || /^\d+$/.test(a)) {
|
|
884
|
+
const n = a === "" ? 1 : Number(a);
|
|
885
|
+
if (n >= 1 && n <= sugg.length) chosen = sugg[n - 1] ;
|
|
886
|
+
else say(ctx, t(ctx, "pilotBadAnswer"));
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
const f = normalizeFolder(a, process.platform, ctx.d.home);
|
|
890
|
+
chosen = all.find((r) => sameCwd(r.folder, f)) ?? null;
|
|
891
|
+
if (!chosen) say(ctx, t(ctx, "pilotNotFound"));
|
|
892
|
+
}
|
|
893
|
+
const folder = shown(ctx, chosen.folder, 60);
|
|
894
|
+
say(ctx, ctx.s("muted", t(ctx, "pilotDry", { folder })));
|
|
895
|
+
const dry = await ctx.d.run(["apply", "--dry-run", "--only", chosen.folder, ...ut(ctx)]);
|
|
896
|
+
if (dry.code !== 0) { say(ctx, t(ctx, dry.code === 130 ? "stepInterrupted" : "stepFailed", { code: dry.code })); throw new Stop(dry.code); }
|
|
897
|
+
willDo(ctx, [
|
|
898
|
+
[t(ctx, "willProject"), folder],
|
|
899
|
+
[t(ctx, "willImport"), `${ctx.s("num", num(ctx, chosen.pending))} ${t(ctx, "willConversations", { n: chosen.pending })}`],
|
|
900
|
+
[t(ctx, "willAccount"), accountOf(ctx, chosen.accountName, 40)],
|
|
901
|
+
[t(ctx, "willUndo"), ctx.s("key", "t3sm rollback --run <id> --archive-threads")],
|
|
902
|
+
]);
|
|
903
|
+
if (!(await ask(ctx, t(ctx, "pilotApplyAsk", { folder }), { def: "n", help: t(ctx, "pilotApplyHelp") }))) { say(ctx, t(ctx, "pilotSkipped")); return NEXT; }
|
|
904
|
+
const { outcome, runId } = await write(ctx, ["apply", "--yes", "--only", chosen.folder, ...ut(ctx)], t(ctx, "didPilot", { folder }),
|
|
905
|
+
{ tolerate: [5], undo: (id) => (id ? t(ctx, "undoImport", { runId: id }) : null) });
|
|
906
|
+
if (runId === null) { say(ctx, t(ctx, "pilotNoRun")); return NEXT; }
|
|
907
|
+
blank(ctx);
|
|
908
|
+
if (outcome.code === 5) say(ctx, t(ctx, "pilotPartly"));
|
|
909
|
+
say(ctx, t(ctx, "pilotCheck", { folder, name: accountOf(ctx, chosen.accountName, 40) }));
|
|
910
|
+
return verifyPilot(ctx, runId);
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
// ---------------- 8 full import ----------------
|
|
914
|
+
|
|
915
|
+
export const full = async (ctx) => {
|
|
916
|
+
heading(ctx, 8);
|
|
917
|
+
say(ctx, t(ctx, "fullIntro"));
|
|
918
|
+
say(ctx, t(ctx, "fullChecklist"));
|
|
919
|
+
const p = await buildPlan(ctx, "fullRefreshing");
|
|
920
|
+
const gate = await gateDecisions(ctx, 8);
|
|
921
|
+
if (gate) return gate;
|
|
922
|
+
const rs = rowsOf(p).filter((r) => r.pending > 0);
|
|
923
|
+
if (rs.length === 0) { say(ctx, t(ctx, "fullNothing")); ctx.fullDone = true; return NEXT; }
|
|
924
|
+
const n = rs.reduce((a, r) => a + r.pending, 0);
|
|
925
|
+
const held = rs.filter((r) => r.held).length;
|
|
926
|
+
const c = counts(ctx, [[t(ctx, "willImport"), n, t(ctx, "willConversations", { n })], [t(ctx, "willInto"), rs.length, t(ctx, "willProjects", { n: rs.length })],
|
|
927
|
+
...(held > 0 ? [[t(ctx, "willHeld"), held, t(ctx, "willHeldWhat", { n: held })] ] : [])]);
|
|
928
|
+
willDo(ctx, [...c, [t(ctx, "willUndo"), ctx.s("key", "t3sm rollback --run <id> --archive-threads")]]);
|
|
929
|
+
if (!(await ask(ctx, t(ctx, "fullAsk"), { def: "n", help: t(ctx, "fullHelp") }))) { say(ctx, t(ctx, "fullDeclined")); return { to: "goto", step: 11 }; }
|
|
930
|
+
const { outcome, runId } = await write(ctx, ["apply", "--yes", ...ut(ctx)], t(ctx, "didFull"),
|
|
931
|
+
{ tolerate: [5], undo: (id) => (id ? t(ctx, "undoImport", { runId: id }) : null) });
|
|
932
|
+
// The command has just shown its result, why each held project waits and every failure (with the help topic): the
|
|
933
|
+
// assistant only says what that means for the next steps, and records what really happened.
|
|
934
|
+
blank(ctx);
|
|
935
|
+
// What the import really did, from its run (the plan above was before it): failures and the projects it held.
|
|
936
|
+
const run = runId === null ? undefined : (await ctx.d.runs()).find((r) => r.runId === runId);
|
|
937
|
+
if (outcome.code === 5) {
|
|
938
|
+
const failed = run?.counts.importFailed ?? 0;
|
|
939
|
+
const last = ctx.done.at(-1);
|
|
940
|
+
if (last && last.runId === runId) last.what = failed > 0 ? t(ctx, "didFullPartial", { n: failed }) : t(ctx, "didFullFailures");
|
|
941
|
+
say(ctx, t(ctx, "fullFailed"));
|
|
942
|
+
} else if ((run?.held ?? 0) > 0) {
|
|
943
|
+
// The import left projects in use for a later run (journaled on its run-end): never "All done" while some wait.
|
|
944
|
+
okLine(ctx, t(ctx, "fullOkHeld", { n: run .held }));
|
|
945
|
+
} else okLine(ctx, t(ctx, "fullOk"));
|
|
946
|
+
ctx.fullDone = true;
|
|
947
|
+
return NEXT;
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
// ---------------- 9 organize ----------------
|
|
951
|
+
|
|
952
|
+
const ALL_WORDS = new Set(["all", "tudo", "todo", "todas", "todos"]);
|
|
953
|
+
const NONE_WORDS = new Set(["none", "off", "nada", "nenhum", "nenhuma"]);
|
|
954
|
+
const AUTOMATED_WHY = "automated session (Agent SDK)";
|
|
955
|
+
|
|
956
|
+
/** T3 Code's own auto-settle accepts 1..90 days only (sidebarAutoSettleAfterDays). */
|
|
957
|
+
const T3_MAX_DAYS = 90;
|
|
958
|
+
|
|
959
|
+
/** The days answer (a number 1-3650, all, none) as days, "all" or "off"; Enter is `def`; null when not understood. */
|
|
960
|
+
export function parseDays(answer , def ) {
|
|
961
|
+
const a = answer.trim().toLowerCase();
|
|
962
|
+
if (a === "") return def;
|
|
963
|
+
if (ALL_WORDS.has(a)) return "all";
|
|
964
|
+
if (NONE_WORDS.has(a)) return "off";
|
|
965
|
+
const n = /^\d+$/.test(a) ? Number(a) : NaN;
|
|
966
|
+
return n >= 1 && n <= 3650 ? n : null;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/** The minimum per project (0-1000); Enter is `def`; null when not understood. */
|
|
970
|
+
export function parseMin(answer , def ) {
|
|
971
|
+
const a = answer.trim();
|
|
972
|
+
if (a === "") return def;
|
|
973
|
+
const n = /^\d+$/.test(a) ? Number(a) : NaN;
|
|
974
|
+
return n >= 0 && n <= 1000 ? n : null;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/** A rule in words: "the last 90 days, at least 10 per project", or "all of it". */
|
|
978
|
+
function ruleScope(ctx , r ) {
|
|
979
|
+
if (r.days === "all") return t(ctx, "organizeScopeAll");
|
|
980
|
+
return t(ctx, "organizeScopeRule", { scope: t(ctx, "organizeScopeDays", { d: r.days }), min: r.minPerProject });
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/** Asks the days (a number, all, none; Enter = `def`) and then the minimum. Null: the rule off. */
|
|
984
|
+
async function askNumbers(ctx , planned , def , help ) {
|
|
985
|
+
let days = null;
|
|
986
|
+
while (days === null) {
|
|
987
|
+
const shownDef = def === "all" ? t(ctx, "organizeScopeAll") : def === "off" ? t(ctx, "organizeT3Off") : String(def);
|
|
988
|
+
days = parseDays(await askText(ctx, t(ctx, "organizeHistoryDaysAsk", { def: shownDef }), { help }), def);
|
|
989
|
+
if (days === null) say(ctx, t(ctx, "organizeHistoryDaysBad"));
|
|
990
|
+
}
|
|
991
|
+
if (days === "off") return null;
|
|
992
|
+
if (days === "all") return { days, minPerProject: planned.minPerProject };
|
|
993
|
+
let min = null;
|
|
994
|
+
while (min === null) {
|
|
995
|
+
min = parseMin(await askText(ctx, t(ctx, "organizeHistoryMinAsk", { min: planned.minPerProject }), { help }), planned.minPerProject);
|
|
996
|
+
if (min === null) say(ctx, t(ctx, "organizeHistoryMinBad"));
|
|
997
|
+
}
|
|
998
|
+
return { days, minPerProject: min };
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* The history question (spec §5.2), with the rule the preview was planned with. On: Enter or y keeps it, n asks the days
|
|
1003
|
+
* (a number, all, none) and the minimum. Off in config.json: Enter or n keeps it off (one Enter, nothing more), y asks
|
|
1004
|
+
* the days and the minimum to turn it on with. Returns the rule chosen (null = off).
|
|
1005
|
+
*/
|
|
1006
|
+
async function askHistory(ctx , planned , off , c , was ) {
|
|
1007
|
+
const help = t(ctx, "organizeHistoryHelp2");
|
|
1008
|
+
const body = off ? [t(ctx, "organizeOffHistory"), t(ctx, "organizeHistoryNow", c)]
|
|
1009
|
+
: [t(ctx, "organizeHistoryNow", c), t(ctx, planned.days === "all" ? "organizeHistorySayAll" : "organizeHistorySay", { days: planned.days, min: planned.minPerProject })];
|
|
1010
|
+
if (c.kept > 0) body.push(t(ctx, "organizeHistoryKept", { kept: c.kept }));
|
|
1011
|
+
if (was !== undefined) body.push(t(ctx, "organizeHistoryWas", { was }));
|
|
1012
|
+
lines(ctx, box(ctx, { title: t(ctx, "organizeHistoryTitle"), body: [...body, "", ...rows(ctx, [[t(ctx, "decDefaultLabel"), t(ctx, off ? "organizeHistoryDefaultOff" : "organizeHistoryDefault")], [t(ctx, "willUndo"), "t3sm organize --undo"]])] }));
|
|
1013
|
+
if (off) {
|
|
1014
|
+
const on = await ask(ctx, t(ctx, "organizeHistoryAskOn", { days: planned.days === "all" ? t(ctx, "organizeScopeAll") : planned.days, min: planned.minPerProject }), { def: "n", help });
|
|
1015
|
+
return on ? askNumbers(ctx, planned, planned.days, help) : null;
|
|
1016
|
+
}
|
|
1017
|
+
const q = planned.days === "all" ? t(ctx, "organizeHistoryAskAll") : t(ctx, "organizeHistoryAsk2", { days: planned.days, min: planned.minPerProject });
|
|
1018
|
+
if (await ask(ctx, q, { def: "y", help })) return planned;
|
|
1019
|
+
return askNumbers(ctx, planned, planned.days, help);
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/** A 0.2 organize.history value in words ("every conversation visible", "the last 30 days visible", ...). */
|
|
1023
|
+
function wasWords(ctx , h ) {
|
|
1024
|
+
if (h === "all") return t(ctx, "organizeWasAll");
|
|
1025
|
+
if (h === "off") return t(ctx, "organizeWasOff");
|
|
1026
|
+
return t(ctx, "organizeWasDays", { d: Number(h.slice("days:".length)) });
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/** First run: no organize run of ours stands in the journal (so the projects to pin are confirmed one by one). */
|
|
1030
|
+
async function firstOrganize(ctx ) {
|
|
1031
|
+
return !(await ctx.d.runs()).some((r) => r.rolledBackBy === null && r.command === "organize" && (r.status === "ok" || r.status === "partial"));
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/** The projects t3sm would pin, as a review list: the ones left unmarked (their ids) are never pinned. */
|
|
1035
|
+
async function pinReview(ctx , pins , titles ) {
|
|
1036
|
+
const items = pins.map((a) => ({
|
|
1037
|
+
id: a.target, label: nameOf(ctx, titles.get(a.target) ?? a.target, 60), checked: true,
|
|
1038
|
+
detail: t(ctx, "organizePinDetail", { n: pins.length }),
|
|
1039
|
+
}));
|
|
1040
|
+
const r = await reviewList(listTerm(ctx), { title: t(ctx, "organizePinListTitle"), help: t(ctx, "organizePinListHelp"), items, lang: ctx.lang });
|
|
1041
|
+
return r.confirmed ? r.items.filter((i) => !i.checked).map((i) => i.id) : [];
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/** What organize would change, per project (before/after), and the history rule in words. */
|
|
1045
|
+
function showPreview(ctx , pv , rule ) {
|
|
1046
|
+
const w = width(ctx);
|
|
1047
|
+
const pw = previewWords(ctx.ui);
|
|
1048
|
+
const words = { ...pw, project: glyphs(ctx, pw.project), visible: glyphs(ctx, pw.visible), settled: glyphs(ctx, pw.settled), retitled: glyphs(ctx, pw.retitled), archived: glyphs(ctx, pw.archived), more: (n ) => glyphs(ctx, pw.more(n)) };
|
|
1049
|
+
const tbl = organizePreviewTable(ctx.s, ctx.f, pv.plan, words, w, { max: 8 });
|
|
1050
|
+
if (tbl.length === 0) return;
|
|
1051
|
+
blank(ctx);
|
|
1052
|
+
say(ctx, t(ctx, "organizePreviewHead"));
|
|
1053
|
+
lines(ctx, tbl);
|
|
1054
|
+
say(ctx, ctx.s("muted", glyphs(ctx, historyLine(ctx.ui, rule))));
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
export const organize = async (ctx) => {
|
|
1058
|
+
if (!ctx.fullDone) { heading(ctx, 9); say(ctx, t(ctx, "organizeNeedsFull")); return NEXT; }
|
|
1059
|
+
let pv = await ctx.d.organizePreview(ctx.allowUntested);
|
|
1060
|
+
if (pv === null) return { to: "skip" };
|
|
1061
|
+
heading(ctx, 9);
|
|
1062
|
+
say(ctx, t(ctx, "organizeIntro"));
|
|
1063
|
+
// A 0.2 organize.history ("all", "off", "days:N") was answered before the 0.3 rule (days and a minimum per project)
|
|
1064
|
+
// existed: its question is asked once more, planned with the 0.3 default, saying what the user had.
|
|
1065
|
+
// As the user had it: "all" gets the 0.3 default (90 days, at least 10); "days:N" those days, at least 10; "off" the
|
|
1066
|
+
// off variant (Enter keeps it off).
|
|
1067
|
+
const legacy = pv.legacyHistory;
|
|
1068
|
+
const legacyRule = legacy === "all" ? { ...DEFAULT_HISTORY }
|
|
1069
|
+
: legacy !== undefined && legacy !== "off" ? { days: Number(legacy.slice("days:".length)), minPerProject: DEFAULT_HISTORY.minPerProject } : null;
|
|
1070
|
+
if (legacyRule !== null) pv = (await ctx.d.organizePreview(ctx.allowUntested, legacyRule)) ?? pv;
|
|
1071
|
+
const histOff = legacy === "off" || (legacy === undefined && pv.off?.history === true);
|
|
1072
|
+
const planned = legacyRule ?? pv.history ?? { ...DEFAULT_HISTORY };
|
|
1073
|
+
// The preview first, before any question: what each project shows today and with t3sm's defaults.
|
|
1074
|
+
showPreview(ctx, pv, planned);
|
|
1075
|
+
if (pv.plan.actions.length === 0 && legacy === undefined) { say(ctx, t(ctx, "organizeNothing")); return NEXT; }
|
|
1076
|
+
const of = (k ) => pv .plan.actions.filter((a) => a.kind === k);
|
|
1077
|
+
|
|
1078
|
+
const patch = { decided: [] };
|
|
1079
|
+
const flags = [];
|
|
1080
|
+
/** "Here is what I will do": a count (aligned in one column) or words. */
|
|
1081
|
+
const will = [];
|
|
1082
|
+
const yn = (key , def , q , help , vars ) =>
|
|
1083
|
+
ask(ctx, t(ctx, q, vars), { def, help: t(ctx, help) }).then((yes) => { if (key !== "") patch.decided .push(key); return yes; });
|
|
1084
|
+
const part = (title , say , extra = []) => {
|
|
1085
|
+
blank(ctx);
|
|
1086
|
+
lines(ctx, callout(ctx.s, { kind: "info", title: t(ctx, title), body: [say, ...extra] }, width(ctx)));
|
|
1087
|
+
};
|
|
1088
|
+
|
|
1089
|
+
// History (spec §5.2): asked whenever the rule shows or settles anything; the counts come from a preview planned with
|
|
1090
|
+
// the rule chosen, so "Here is what I will do" says what organize will really do.
|
|
1091
|
+
/** The rule organize will run with: the answer, else what config.json says (null = off). */
|
|
1092
|
+
let rule = histOff ? null : planned;
|
|
1093
|
+
const historyAsked = legacy !== undefined || of("unsettle").length > 0 || of("settle").length > 0;
|
|
1094
|
+
const countsOf = (x ) => {
|
|
1095
|
+
// A mark of a thread already shown (history step 6) shows nothing again: counted apart (`kept`), so the approval
|
|
1096
|
+
// screen still names every write.
|
|
1097
|
+
const sh = x.plan.actions.filter((a) => a.kind === "unsettle" && !isShownMark(a));
|
|
1098
|
+
const kp = x.plan.actions.filter((a) => isShownMark(a));
|
|
1099
|
+
const st = x.plan.actions.filter((a) => a.kind === "settle");
|
|
1100
|
+
return { shown: sh.length, settled: st.length, kept: kp.length, p: new Set([...sh, ...st].map((a) => a.projectId)).size };
|
|
1101
|
+
};
|
|
1102
|
+
/** Where the history rows end in `will`: the kept row goes there once T3 Code's option is chosen. */
|
|
1103
|
+
let historyEnd = null;
|
|
1104
|
+
if (historyAsked) {
|
|
1105
|
+
blank(ctx);
|
|
1106
|
+
rule = await askHistory(ctx, planned, histOff, countsOf(pv), legacy === undefined ? undefined : wasWords(ctx, legacy));
|
|
1107
|
+
patch.history = rule ?? "off";
|
|
1108
|
+
patch.decided .push("history", HISTORY_V2);
|
|
1109
|
+
const same = rule !== null && rule.days === planned.days && rule.minPerProject === planned.minPerProject;
|
|
1110
|
+
if (rule !== null && !same) pv = (await ctx.d.organizePreview(ctx.allowUntested, rule)) ?? pv; // other numbers: plan them
|
|
1111
|
+
if (rule !== null) {
|
|
1112
|
+
const c = countsOf(pv);
|
|
1113
|
+
will.push([t(ctx, "organizeRowHistory"), ruleScope(ctx, rule)], [` ${t(ctx, "organizeRowShown")}`, c.shown], [` ${t(ctx, "organizeRowSettled")}`, c.settled]);
|
|
1114
|
+
historyEnd = will.length;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
const titles = of("title");
|
|
1119
|
+
if (titles.length > 0) {
|
|
1120
|
+
part("organizeTitlesTitle", t(ctx, "organizeTitlesSay", { n: titles.length }), pv.off?.titles ? [t(ctx, "organizeOffTitles", { n: titles.length })] : []);
|
|
1121
|
+
const yes = await yn("titles", pv.off?.titles ? "n" : "y", "organizeTitlesAsk", "organizeTitlesHelp", { n: titles.length });
|
|
1122
|
+
patch.titles = yes;
|
|
1123
|
+
if (yes) will.push([t(ctx, "organizeRowTitles"), titles.length]);
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
const automated = of("archive").filter((a) => a.reason === AUTOMATED_WHY);
|
|
1127
|
+
if (automated.length > 0) {
|
|
1128
|
+
part("organizeArchiveTitle", t(ctx, "organizeArchiveSay", { n: automated.length }), pv.off?.archiveAutomated ? [t(ctx, "organizeOffArchive", { n: automated.length })] : []);
|
|
1129
|
+
const yes = await yn("archiveAutomated", pv.off?.archiveAutomated ? "n" : "y", "organizeArchiveAsk", "organizeArchiveHelp", { n: automated.length });
|
|
1130
|
+
patch.archiveAutomated = yes;
|
|
1131
|
+
if (yes) will.push([t(ctx, "organizeRowArchive"), automated.length]);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
// Conversations of projects t3sm created in temp or system folders: archived by the same command, so asked and listed too.
|
|
1135
|
+
const folders = of("archive").filter((a) => a.reason !== AUTOMATED_WHY);
|
|
1136
|
+
if (folders.length > 0) {
|
|
1137
|
+
part("organizeFoldersTitle", t(ctx, "organizeFoldersSay", { n: folders.length }));
|
|
1138
|
+
if (await yn("", "y", "organizeFoldersAsk", "organizeFoldersHelp", { n: folders.length })) will.push([t(ctx, "organizeRowFolders"), folders.length]);
|
|
1139
|
+
else flags.push("--no-archive-folders");
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
const pins = of("pin");
|
|
1143
|
+
if (pins.length > 0) {
|
|
1144
|
+
part("organizePinTitle", t(ctx, "organizePinSay", { n: pins.length }), pv.off?.pinRecent ? [t(ctx, "organizeOffPin", { n: pins.length })] : []);
|
|
1145
|
+
const yes = await yn("pinRecent", pv.off?.pinRecent ? "n" : "y", "organizePinAsk", "organizePinHelp", { n: pins.length });
|
|
1146
|
+
patch.pinRecent = { enabled: yes };
|
|
1147
|
+
if (yes) {
|
|
1148
|
+
const titlesById = new Map(pv.projects.map((x) => [x.id, x.title] ));
|
|
1149
|
+
const left = (await firstOrganize(ctx)) ? await pinReview(ctx, pins, titlesById) : [];
|
|
1150
|
+
if (left.length > 0) flags.push("--no-pin", left.join(","));
|
|
1151
|
+
if (pins.length - left.length > 0) will.push([t(ctx, "organizeRowPin"), pins.length - left.length]);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
const del = of("project-delete");
|
|
1156
|
+
if (del.length > 0) {
|
|
1157
|
+
part("organizeDeleteTitle", t(ctx, "organizeDeleteSay", { n: del.length }));
|
|
1158
|
+
const yes = await yn("", "y", "organizeDeleteAsk", "organizeDeleteHelp", { n: del.length });
|
|
1159
|
+
if (yes) will.push([t(ctx, "organizeRowDelete"), del.length]);
|
|
1160
|
+
else flags.push("--no-delete");
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
// Separate from the parts above: T3 Code's own setting, for conversations started in T3 Code (spec §5.2). With a rule
|
|
1164
|
+
// of at most 90 days: let T3 Code put them away after the same days (default yes; n leaves it as it is, never off).
|
|
1165
|
+
// Otherwise T3 Code cannot follow: keep it, set it to 90 days, or turn it off (default keep). With the rule off: turn
|
|
1166
|
+
// it off? (default no). The order is safe: organize applies the history rule (unsettle, settle) before this setting.
|
|
1167
|
+
const days = pv.autoSettleDays;
|
|
1168
|
+
/** T3 Code's option as this run sets it (undefined: left as it is). */
|
|
1169
|
+
let t3Want ;
|
|
1170
|
+
if (days !== undefined) {
|
|
1171
|
+
const current = days === null ? t(ctx, "organizeT3Off") : t(ctx, "organizeT3After", { days });
|
|
1172
|
+
if (rule !== null && rule.days !== "all" && rule.days <= T3_MAX_DAYS) {
|
|
1173
|
+
if (days !== rule.days) {
|
|
1174
|
+
// "Like the rule above" only when the history question was just asked; otherwise the rule is named.
|
|
1175
|
+
part("organizeT3Title", t(ctx, historyAsked ? "organizeT3Say" : "organizeT3SayAlone", { current, days: rule.days }));
|
|
1176
|
+
if (await yn("", "y", "organizeT3Ask", "organizeT3Help", { days: rule.days, current })) {
|
|
1177
|
+
t3Want = rule.days;
|
|
1178
|
+
flags.push("--auto-settle", String(rule.days));
|
|
1179
|
+
will.push([t(ctx, "organizeRowT3"), t(ctx, "organizeValT3", { days: rule.days, current })]);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
} else if (rule !== null) {
|
|
1183
|
+
const scope = rule.days === "all" ? t(ctx, "organizeScopeAllHistory") : t(ctx, "organizeScopeDays", { d: rule.days });
|
|
1184
|
+
part("organizeT3Title", t(ctx, "organizeT3KeepSay", { scope, current }));
|
|
1185
|
+
// undefined: keep it as it is; a number: set it to that; null: off.
|
|
1186
|
+
const choices = [[t(ctx, "organizeT3ChoiceKeep", { current }), undefined]];
|
|
1187
|
+
if (days !== T3_MAX_DAYS) choices.push([t(ctx, "organizeT3ChoiceSet", { days: T3_MAX_DAYS }), T3_MAX_DAYS]);
|
|
1188
|
+
if (days !== null) choices.push([t(ctx, "organizeT3ChoiceOff"), null]);
|
|
1189
|
+
lines(ctx, choices.map(([label], i) => ` ${ctx.s("num", String(i + 1))} ${label}`));
|
|
1190
|
+
const n = await pickNumber(ctx, t(ctx, "organizeT3ChoiceAsk", { n: choices.length }), choices.length, t(ctx, "organizeT3KeepHelp", { current }), 1);
|
|
1191
|
+
const want = choices[n - 1] [1];
|
|
1192
|
+
if (want !== undefined) {
|
|
1193
|
+
t3Want = want;
|
|
1194
|
+
flags.push("--auto-settle", want === null ? "off" : String(want));
|
|
1195
|
+
will.push([t(ctx, "organizeRowT3"), want === null ? t(ctx, "organizeValT3Off", { current }) : t(ctx, "organizeValT3", { days: want, current })]);
|
|
1196
|
+
}
|
|
1197
|
+
} else if (days !== null) {
|
|
1198
|
+
part("organizeT3Title", t(ctx, "organizeSettleSay", { days }));
|
|
1199
|
+
if (await yn("", "n", "organizeSettleAsk", "organizeSettleHelp", {})) {
|
|
1200
|
+
t3Want = null;
|
|
1201
|
+
flags.push("--auto-settle", "off");
|
|
1202
|
+
will.push([t(ctx, "organizeRowT3"), t(ctx, "organizeValT3Off", { current })]);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
// The marks follow T3 Code's option as this run leaves it: a changed option is planned again (a dry run), so the
|
|
1208
|
+
// approval screen names the marks the run will write.
|
|
1209
|
+
if (t3Want !== undefined && t3Want !== days) pv = (await ctx.d.organizePreview(ctx.allowUntested, rule, t3Want)) ?? pv;
|
|
1210
|
+
const kept = countsOf(pv).kept;
|
|
1211
|
+
if (kept > 0 && rule !== null) {
|
|
1212
|
+
const row = [` ${t(ctx, "organizeRowKept")}`, kept];
|
|
1213
|
+
if (historyEnd !== null) will.splice(historyEnd, 0, row);
|
|
1214
|
+
else will.unshift([t(ctx, "organizeRowHistory"), ruleScope(ctx, rule)], row);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
blank(ctx);
|
|
1218
|
+
if (will.length === 0) {
|
|
1219
|
+
// The re-asked 0.2 history question answered "no rule" (kept off, or none) with nothing else chosen: the answer is
|
|
1220
|
+
// still saved (config.json only, like the decisions), so it is not asked again. Nothing changes in T3 Code.
|
|
1221
|
+
if (legacy !== undefined && rule === null) {
|
|
1222
|
+
await saveSettings(ctx, { history: "off", decided: ["history", HISTORY_V2] }, t(ctx, "didOrganizeSettings"), t(ctx, "undoOrganizeSettings"));
|
|
1223
|
+
okLine(ctx, t(ctx, "organizeHistoryOffSaved"));
|
|
1224
|
+
return NEXT;
|
|
1225
|
+
}
|
|
1226
|
+
say(ctx, t(ctx, "organizeNothingChosen"));
|
|
1227
|
+
return NEXT;
|
|
1228
|
+
}
|
|
1229
|
+
const nw = Math.max(...will.map(([, v]) => (typeof v === "number" ? num(ctx, v).length : 0)));
|
|
1230
|
+
const body = rows(ctx, [...will.map(([k, v]) => [k, typeof v === "number" ? ctx.s("num", padStart(num(ctx, v), nw)) : v]),
|
|
1231
|
+
[t(ctx, "willUndo"), ctx.s("key", "t3sm organize --undo")]]);
|
|
1232
|
+
lines(ctx, box(ctx, { title: t(ctx, "willHead"), body }));
|
|
1233
|
+
if (!(await ask(ctx, t(ctx, "organizeApplyAsk"), { def: "n", help: t(ctx, "organizeApplyHelp") }))) { say(ctx, t(ctx, "organizeDeclined")); return NEXT; }
|
|
1234
|
+
await saveSettings(ctx, patch, t(ctx, "didOrganizeSettings"), t(ctx, "undoOrganizeSettings"));
|
|
1235
|
+
const { outcome } = await write(ctx, ["organize", "--yes", ...flags, ...ut(ctx)], t(ctx, "didOrganize"),
|
|
1236
|
+
{ tolerate: [5], undo: (id) => (id ? t(ctx, "undoOrganize", { runId: id }) : null) });
|
|
1237
|
+
if (outcome.code === 5) say(ctx, t(ctx, "organizeFailed"));
|
|
1238
|
+
else okLine(ctx, t(ctx, "organizeOk"));
|
|
1239
|
+
return NEXT;
|
|
1240
|
+
};
|
|
1241
|
+
|
|
1242
|
+
// ---------------- 10 keep in sync ----------------
|
|
1243
|
+
|
|
1244
|
+
/** `schedule install --watch` while another run holds the lock: this many tries, this far apart. */
|
|
1245
|
+
export const SCHEDULE_TRIES = 3;
|
|
1246
|
+
export const SCHEDULE_RETRY_MS = 5000;
|
|
1247
|
+
|
|
1248
|
+
export const sync = async (ctx) => {
|
|
1249
|
+
heading(ctx, 10);
|
|
1250
|
+
if (!ctx.fullDone) { say(ctx, t(ctx, "syncNeedsFull")); return NEXT; }
|
|
1251
|
+
say(ctx, t(ctx, "syncIntro"));
|
|
1252
|
+
if (await ctx.d.scheduleInstalled()) { ctx.syncOn = true; okLine(ctx, t(ctx, "syncInstalled")); }
|
|
1253
|
+
else if (await ask(ctx, t(ctx, "syncAsk"), { def: "n", help: t(ctx, "syncHelp") })) {
|
|
1254
|
+
// install --watch takes the lock: a sync cycle holding it is waited for a few times before the user is told.
|
|
1255
|
+
let busy = true;
|
|
1256
|
+
for (let i = 0; i < SCHEDULE_TRIES && busy; i++) {
|
|
1257
|
+
if (i > 0) await (ctx.d.wait ?? ((ms ) => new Promise ((ok) => setTimeout(ok, ms))))(SCHEDULE_RETRY_MS);
|
|
1258
|
+
busy = (await write(ctx, ["schedule", "install", "--watch", "--yes"], t(ctx, "didSchedule"), { undo: () => t(ctx, "undoSchedule"), busyReturns: true })).busy === true;
|
|
1259
|
+
}
|
|
1260
|
+
if (busy) say(ctx, t(ctx, "syncBusy"));
|
|
1261
|
+
else ctx.syncOn = true;
|
|
1262
|
+
} else say(ctx, t(ctx, "syncSkipped"));
|
|
1263
|
+
blank(ctx);
|
|
1264
|
+
lines(ctx, callout(ctx.s, { kind: "info", title: t(ctx, "syncMergeTitle"), body: [t(ctx, "syncMerge")], command: "t3sm merge" }, width(ctx)));
|
|
1265
|
+
return NEXT;
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
// ---------------- 11 done ----------------
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Offers the t3sm plugin (the /t3sm commands inside T3 Code) in each configured Claude account that lacks it: what it adds,
|
|
1272
|
+
* how to remove it, then a y/N (default No) per account before the two `claude plugin` children run for that account.
|
|
1273
|
+
* An outdated one is only mentioned. A failed install is reported and never ends the assistant.
|
|
1274
|
+
*/
|
|
1275
|
+
async function offerPlugin(ctx ) {
|
|
1276
|
+
let rs;
|
|
1277
|
+
try { rs = await ctx.d.pluginAccounts(); } catch { return; } // optional extra: never in the way
|
|
1278
|
+
const shownRow = (r ) => ({ name: accountOf(ctx, r.displayName, 80), home: nameOf(ctx, r.home, 120) });
|
|
1279
|
+
for (const r of rs) if (r.state.state === "outdated") say(ctx, t(ctx, "pluginOutdated", shownRow(r)));
|
|
1280
|
+
const missing = rs.filter((r) => r.state.state === "missing");
|
|
1281
|
+
if (missing.length === 0) return;
|
|
1282
|
+
blank(ctx);
|
|
1283
|
+
lines(ctx, callout(ctx.s, { kind: "info", title: t(ctx, "pluginTitle"), body: [t(ctx, "pluginIntro")], command: "claude plugin uninstall t3sm@t3code-session-manager" }, width(ctx)));
|
|
1284
|
+
let declined = false;
|
|
1285
|
+
for (const r of missing) {
|
|
1286
|
+
const { name, home } = shownRow(r);
|
|
1287
|
+
if (!(await ask(ctx, t(ctx, "pluginAsk", { name, home }), { def: "n", help: t(ctx, "pluginHelp"), back: false }))) { declined = true; continue; }
|
|
1288
|
+
const res = await ctx.d.installPlugin(r.id);
|
|
1289
|
+
if (res.ok) {
|
|
1290
|
+
say(ctx, t(ctx, "pluginOk", { name }));
|
|
1291
|
+
ctx.done.push({ what: t(ctx, "didPlugin", { name }), runId: null, undo: t(ctx, "undoPlugin", { home }) });
|
|
1292
|
+
} else {
|
|
1293
|
+
const where = t(ctx, res.step === "install" ? "stepInstall" : res.step === "claude" ? "stepClaude" : "stepMarketplace");
|
|
1294
|
+
// The child's output is external text: every line goes through shownText, so no escape sequence reaches the terminal.
|
|
1295
|
+
const output = res.output.trim().split(/\r?\n/).slice(-6).map((l) => shownText(l, 200)).join("\n").slice(0, 600);
|
|
1296
|
+
say(ctx, t(ctx, "pluginFailed", { name, where, output, home }));
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
if (declined) say(ctx, t(ctx, "pluginSkipped"));
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
/** The last screen: one panel with what changed, how to undo it, and what happens next. */
|
|
1303
|
+
function donePanel(ctx ) {
|
|
1304
|
+
ctx.summaryShown = true;
|
|
1305
|
+
const { s } = ctx;
|
|
1306
|
+
const head = (k ) => s("title", t(ctx, k));
|
|
1307
|
+
const body = [head("doneChanged")];
|
|
1308
|
+
body.push(...(ctx.done.length > 0 ? ctx.done.map((d) => ({ bullet: doneSym(ctx, d), text: d.runId ? t(ctx, "doneItemRun", { what: d.what, runId: d.runId }) : d.what })) : [t(ctx, "doneNothing")]));
|
|
1309
|
+
const undos = ctx.done.filter((d) => d.undo !== null);
|
|
1310
|
+
if (undos.length > 0) {
|
|
1311
|
+
body.push("", head("doneHowUndo"), ...undos.map((d) => ({ bullet: s("accent", s.sym.sep), text: d.undo })));
|
|
1312
|
+
if (ctx.done.some((d) => d.runId !== null)) body.push(t(ctx, "doneUndo"));
|
|
1313
|
+
}
|
|
1314
|
+
body.push("", head("doneNext"));
|
|
1315
|
+
body.push(t(ctx, ctx.syncOn ? "doneNextSync" : ctx.fullDone ? "doneNextNoSync" : "doneNextImport"));
|
|
1316
|
+
body.push(...rows(ctx, [["t3sm status", t(ctx, "doneCmdStatus")], ["t3sm projects", t(ctx, "doneCmdProjects")], ["t3sm merge", t(ctx, "doneCmdMerge")]]));
|
|
1317
|
+
if (ctx.plan) body.push("", s("muted", t(ctx, "doneReport", { path: shown(ctx, ctx.plan.planPath, Math.max(10, width(ctx) - 20)) })));
|
|
1318
|
+
blank(ctx);
|
|
1319
|
+
lines(ctx, box(ctx, { title: t(ctx, "doneTitle"), tone: ctx.worst > 0 ? "warn" : "ok", body }));
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
export const done = async (ctx) => {
|
|
1323
|
+
heading(ctx, 11);
|
|
1324
|
+
await offerLanguage(ctx); // config.json may exist only since the plan step
|
|
1325
|
+
await offerPlugin(ctx);
|
|
1326
|
+
donePanel(ctx);
|
|
1327
|
+
say(ctx, t(ctx, "doneBye"));
|
|
1328
|
+
return NEXT;
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
export const STEPS = [welcome, check, accounts, plan, decisions, cleanup, pilot, full, organize, sync, done];
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Where a returning user is, from real state only (journal runs not rolled back, config.json and a plan, the
|
|
1335
|
+
* scheduler); null = from the start. Questions the newest plan still has unanswered -> the decisions. The newest full
|
|
1336
|
+
* import decides next: ok -> organize (when no organize run followed), else sync (or the summary when sync is
|
|
1337
|
+
* installed); partial or interrupted -> the full import again, saying so. A pilot -> its check in T3 Code. One kind of
|
|
1338
|
+
* clean-up done -> the clean-up step (the other kind may still wait), both -> the pilot.
|
|
1339
|
+
*/
|
|
1340
|
+
export function resumePoint(s ) {
|
|
1341
|
+
const live = s.runs.filter((r) => r.rolledBackBy === null);
|
|
1342
|
+
const ok = (r ) => r.status === "ok" || r.status === "partial";
|
|
1343
|
+
if (s.configExists && s.hasPlan && s.decisionsPending === true) return { step: 5, what: "resumeDecisions" };
|
|
1344
|
+
const lastFull = live.filter((r) => /^apply \S+$/.test(r.command ?? "")).at(-1);
|
|
1345
|
+
if (lastFull) {
|
|
1346
|
+
if (lastFull.status === "ok") {
|
|
1347
|
+
if (s.scheduleInstalled) return { step: 11, what: "resumeFullSync" };
|
|
1348
|
+
const organized = live.some((r) => ok(r) && r.command === "organize");
|
|
1349
|
+
return { step: organized ? 10 : 9, what: "resumeFull" };
|
|
1350
|
+
}
|
|
1351
|
+
if (lastFull.status === "partial") return { step: 8, what: "resumeFullPartial", n: lastFull.counts.importFailed };
|
|
1352
|
+
return { step: 8, what: "resumeFullInterrupted" };
|
|
1353
|
+
}
|
|
1354
|
+
const pilotRun = live.filter((r) => ok(r) && /^apply \S+ --only$/.test(r.command ?? "")).at(-1);
|
|
1355
|
+
if (pilotRun) return { step: 7, what: "resumePilot", runId: pilotRun.runId };
|
|
1356
|
+
const q = live.some((r) => ok(r) && /^quarantine\b/.test(r.command ?? ""));
|
|
1357
|
+
const d = live.some((r) => ok(r) && /^dedupe\b/.test(r.command ?? ""));
|
|
1358
|
+
if (q && d) return { step: 7, what: "resumeCleanup" };
|
|
1359
|
+
if (q || d) return { step: 6, what: "resumeCleanupPart" };
|
|
1360
|
+
if (s.configExists && s.hasPlan) return { step: 4, what: "resumeConfig" };
|
|
1361
|
+
return null;
|
|
1362
|
+
}
|