t3code-session-manager 0.0.0-stage → 0.4.0
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 +138 -0
- package/LICENSE +21 -0
- package/README.md +660 -2
- package/README.pt.md +616 -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,398 @@
|
|
|
1
|
+
// t3sm update: look for a newer t3sm and install it with the update engine (src/ops/updater.ts: lock, journal, stop and
|
|
2
|
+
// restart the watcher, 120 s health check, rollback). Modes:
|
|
3
|
+
// --check read-only: installed, latest and its kind, source, automatic updates, last check, an interrupted
|
|
4
|
+
// update (with how to go back). No lock, nothing written. Offline: says so, exit 0.
|
|
5
|
+
// --auto on|off config.json `update.auto`, under the lock.
|
|
6
|
+
// --auto-run --yes the background watcher's child (src/ops/autoUpdate.ts): a patch or minor only, never a major.
|
|
7
|
+
// (none) what is new (a folder: the target tag's CHANGELOG.md; GitHub: after the install, from the installed
|
|
8
|
+
// one), then asks (a terminal) or needs --yes (exit 2 otherwise), then installs with a progress line
|
|
9
|
+
// per step. --dry-run stops before installing. --from <folder> / --source github choose the source;
|
|
10
|
+
// it is remembered only once the new version is in (the engine's rule).
|
|
11
|
+
// A git checkout or npx's cache only gets instructions; nothing is installed.
|
|
12
|
+
|
|
13
|
+
import { readFileSync } from "node:fs";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { stateDir } from "../../core/paths.js";
|
|
18
|
+
import { DEFAULT_SCHEDULE_MINUTES, loadConfig, saveConfig, updateAuto } from "../../core/config.js";
|
|
19
|
+
import { Journal } from "../../core/journal.js";
|
|
20
|
+
import { acquireLock } from "../../core/lock.js";
|
|
21
|
+
|
|
22
|
+
import { compareSemver, parseSemver } from "../../core/semver.js";
|
|
23
|
+
|
|
24
|
+
import { renderSections, sectionsBetween } from "../../core/changelog.js";
|
|
25
|
+
import { defaultUpdateSource, installKind, isRegistryInstall, ownPackageName, ownRepositoryUrl, updateRunner } from "../../ops/update.js";
|
|
26
|
+
import {
|
|
27
|
+
QUERY_TIMEOUT_MS, classify, newestRelease, parseReleaseSpec, readPendingUpdate, readUpdateState, releaseVersions, runUpdate, sourceProblem, watcherOps,
|
|
28
|
+
|
|
29
|
+
} from "../../ops/updater.js";
|
|
30
|
+
import { UPDATE_CHECK_RETRY_MS, autoTarget, requestUpdateRetry } from "../../ops/autoUpdate.js";
|
|
31
|
+
import { notifyOnce, systemNotifier, updateNotice, UPDATE_FAILED_REASON, } from "../../ops/notify.js";
|
|
32
|
+
import { recordUpdateOutcome } from "../../ops/syncStatus.js";
|
|
33
|
+
import { appendSyncLog } from "../../ops/sync.js";
|
|
34
|
+
import { defaultBinPath } from "../../ops/schedule.js";
|
|
35
|
+
import { stopWatcher } from "../../ops/watcherControl.js";
|
|
36
|
+
import { realClock, } from "../../ops/watch.js";
|
|
37
|
+
import { defaultRunner } from "../../t3/auth.js";
|
|
38
|
+
import { reportLockBusy } from "../locked.js";
|
|
39
|
+
import { parseFlags } from "./quarantine.js";
|
|
40
|
+
import { cliT, cliUi, confirm, langOf, usageLine, } from "../ui.js";
|
|
41
|
+
|
|
42
|
+
import { flagsOf } from "../flags.js";
|
|
43
|
+
import { callout, kv, panel } from "../../ui/components.js";
|
|
44
|
+
import { fitLine, noteLines, snugWidth, textLines } from "../screen.js";
|
|
45
|
+
import { renderMarkdown } from "./help.js";
|
|
46
|
+
import { shownText } from "../../plan/names.js";
|
|
47
|
+
import { realIsElevated, warnIfElevated } from "../../ops/elevated.js";
|
|
48
|
+
|
|
49
|
+
import { systemRoot } from "../../core/sysroot.js";
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
/** Errors runUpdate returns before journaling anything: nothing was attempted, nothing to report in status. */
|
|
80
|
+
const NOT_ATTEMPTED = new Set(["busy", "not-newer", "invalid-version", "no-source"]);
|
|
81
|
+
|
|
82
|
+
const describe = (s , lang = "en") =>
|
|
83
|
+
s.kind === "npm" ? `npm ${s.name}` : s.kind === "github" ? `GitHub ${s.repo}` : cliT(lang, "update.folder", { path: s.path });
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
export async function updateCommand(args , io , deps = {}) {
|
|
91
|
+
const spec = flagsOf("update");
|
|
92
|
+
const p = parseFlags(args, io, "update", spec.bool, spec.valued);
|
|
93
|
+
if (!p) return 2;
|
|
94
|
+
const has = (f ) => p.flags.has(f);
|
|
95
|
+
const from = p.values.get("--from");
|
|
96
|
+
const source = p.values.get("--source");
|
|
97
|
+
const auto = p.values.get("--auto");
|
|
98
|
+
const bad = (m ) => { io.stderr(`${m} Run \`t3sm update --help\`.\n`); return 2; };
|
|
99
|
+
if (source !== undefined && source !== "github" && source !== "npm") return bad(`--source takes npm or github (a checkout on this computer: --from <folder>), not ${JSON.stringify(source)}.`);
|
|
100
|
+
if (auto !== undefined && auto !== "on" && auto !== "off") return bad(`--auto takes on or off, not ${JSON.stringify(auto)}.`);
|
|
101
|
+
if (from !== undefined && source !== undefined) return bad("Use either --from or --source.");
|
|
102
|
+
const chooses = from !== undefined || source !== undefined;
|
|
103
|
+
if (has("--check") && (chooses || auto !== undefined || has("--auto-run") || has("--yes") || has("--dry-run"))) return bad("--check only looks: it takes no other option.");
|
|
104
|
+
if (auto !== undefined && (chooses || has("--auto-run"))) return bad("--auto on|off takes no other option than --dry-run (or --yes, which it does not need).");
|
|
105
|
+
if (has("--auto-run") && (chooses || has("--dry-run"))) return bad("--auto-run takes no other option than --yes.");
|
|
106
|
+
|
|
107
|
+
const root = deps.root ?? fileURLToPath(new URL("../../..", import.meta.url)).replace(/[\\/]+$/, "");
|
|
108
|
+
const home = deps.home ?? homedir();
|
|
109
|
+
const platform = deps.platform ?? process.platform;
|
|
110
|
+
const repoUrl = deps.repositoryUrl ?? ownRepositoryUrl();
|
|
111
|
+
const packageName = deps.packageName ?? ownPackageName();
|
|
112
|
+
const fromRegistry = deps.fromRegistry ?? isRegistryInstall(root);
|
|
113
|
+
const c = {
|
|
114
|
+
io, dir: stateDir(io.env, home), home, root, platform, deps, repoUrl, packageName,
|
|
115
|
+
run: deps.run ?? updateRunner(platform, io.env),
|
|
116
|
+
clock: deps.clock ?? realClock,
|
|
117
|
+
readVersion: deps.readVersion ?? (() => (JSON.parse(readFileSync(join(root, "package.json"), "utf8")) ).version),
|
|
118
|
+
defaultSource: defaultUpdateSource(repoUrl, { name: packageName, installed: fromRegistry }),
|
|
119
|
+
};
|
|
120
|
+
// The watcher's own child never warns: nobody reads its output.
|
|
121
|
+
if (!has("--auto-run")) await warnIfElevated(io, deps.elevated ?? (deps.home === undefined ? realIsElevated : async () => false), "update");
|
|
122
|
+
if (auto !== undefined) return setAuto(c, auto === "on", has("--dry-run"));
|
|
123
|
+
if (has("--check")) return check(c);
|
|
124
|
+
if (has("--auto-run")) {
|
|
125
|
+
if (!has("--yes")) { usageLine(io, "usage.autoRunYes"); return 2; }
|
|
126
|
+
return autoRun(c);
|
|
127
|
+
}
|
|
128
|
+
return manual(c, from !== undefined ? { kind: "folder", path: from } : source === "github" || source === "npm" ? source : null, has("--yes"), has("--dry-run"));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ---------- --auto on|off ----------
|
|
132
|
+
|
|
133
|
+
async function setAuto(c , on , dryRun ) {
|
|
134
|
+
const ui = cliUi(c.io);
|
|
135
|
+
if (dryRun) { c.io.stdout(`${ui.t(on ? "update.auto.wouldOn" : "update.auto.wouldOff")}\n`); return 0; }
|
|
136
|
+
// A preference toggle, like `projects unset`: the value itself is the confirmation, so no --yes is needed (and it is
|
|
137
|
+
// accepted). It changes an existing config.json only: t3sm start writes the first one, with the accounts.
|
|
138
|
+
const lock = await acquireLock(c.dir);
|
|
139
|
+
if (!lock) { reportLockBusy(c.io); return 0; }
|
|
140
|
+
try {
|
|
141
|
+
const config = await loadConfig(c.dir, c.home);
|
|
142
|
+
if (config === null) {
|
|
143
|
+
c.io.stderr(`${ui.t("update.auto.noConfig")}\n`);
|
|
144
|
+
return 1;
|
|
145
|
+
}
|
|
146
|
+
await saveConfig(c.dir, { ...config, update: { ...config.update, auto: on } }, c.home);
|
|
147
|
+
} finally {
|
|
148
|
+
await lock.release();
|
|
149
|
+
}
|
|
150
|
+
c.io.stdout(noteLines(ui.s, "ok", ui.t(on ? "update.auto.on" : "update.auto.off"), ui.width).join("\n") + "\n");
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ---------- --check ----------
|
|
155
|
+
|
|
156
|
+
function kindWords(ui , installed , latest ) {
|
|
157
|
+
const k = classify(installed, latest);
|
|
158
|
+
if (k === "major") return ui.t("update.kind.major");
|
|
159
|
+
if (k !== "none") return ui.t(k === "patch" ? "update.kind.patch" : "update.kind.minor");
|
|
160
|
+
return parseSemver(installed) !== null && compareSemver(latest, installed) < 0 ? ui.t("update.kind.newer", { installed }) : ui.t("update.kind.none");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** How to put `previous` back by hand (an interrupted update). */
|
|
164
|
+
function goBackHint(ui , p ) {
|
|
165
|
+
const r = parseReleaseSpec(p.previous.spec);
|
|
166
|
+
if (r === null) return null;
|
|
167
|
+
if (r.source.kind === "npm") return ui.t("update.goBackGithub", { version: r.version, command: `npm install -g ${r.source.name}@${r.version}` });
|
|
168
|
+
if (r.source.kind === "github") return ui.t("update.goBackGithub", { version: r.version, command: `npm install -g --install-links github:${r.source.repo}#v${r.version}` });
|
|
169
|
+
return ui.t("update.goBackFolder", { version: r.version, path: r.source.path });
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** What `t3sm update --check` found (read-only), for the screen. */
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
const OUTCOME_WORDS = {
|
|
180
|
+
installed: "update.outcome.installed", "rolled-back": "update.outcome.rolledBack", failed: "update.outcome.failed", interrupted: "update.outcome.interrupted",
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/** The check as aligned rows, then an interrupted update (with how to go back) and how to install a newer release. */
|
|
184
|
+
export function renderUpdateCheck(ui , v , width = ui.width) {
|
|
185
|
+
const { s, t } = ui;
|
|
186
|
+
const how = v.kind === "checkout" ? t("update.how.checkout", { path: v.root }) : v.kind === "npx" ? t("update.how.npx") : t("update.how.global");
|
|
187
|
+
const rows = [[t("update.label.installed"), `${v.installed} (${how})`]];
|
|
188
|
+
if (v.latest === null) rows.push([t("update.label.latest"), t("update.latest.unknown")]);
|
|
189
|
+
else {
|
|
190
|
+
rows.push([t("update.label.latest"), `${v.latest} (${kindWords(ui, v.installed, v.latest)}${v.skipped ? t("update.latest.skipped") : ""})`]);
|
|
191
|
+
if (v.auto !== null && v.auto !== v.latest) rows.push([t("update.label.auto"), t("update.auto.target", { version: v.auto, major: parseSemver(v.installed)?.[0] ?? 0 })]);
|
|
192
|
+
}
|
|
193
|
+
rows.push([t("update.label.source"), v.source === null ? t("update.source.unknown") : describe(v.source, ui.lang)]);
|
|
194
|
+
rows.push([t("update.label.automatic"), v.kind === "checkout" ? t("update.automatic.checkout") : v.kind === "npx" ? t("update.automatic.npx")
|
|
195
|
+
: v.automatic === undefined ? t("update.automatic.unknown") : v.automatic ? t("update.automatic.on") : t("update.automatic.off")]);
|
|
196
|
+
rows.push([t("update.label.lastCheck"), v.lastCheckAt === null ? t("status.never") : `${ui.f.date(v.lastCheckAt)} (${ui.f.ago(v.lastCheckAt)})`]);
|
|
197
|
+
if (v.lastUpdate) {
|
|
198
|
+
const u = v.lastUpdate;
|
|
199
|
+
const outcome = OUTCOME_WORDS[u.outcome] ? t(OUTCOME_WORDS[u.outcome] ) : shownText(u.outcome, 40);
|
|
200
|
+
rows.push([t("update.label.lastUpdate"), `${u.from} -> ${u.to}, ${outcome}${u.error ? ` (${shownText(u.error, 200)})` : ""}`]);
|
|
201
|
+
}
|
|
202
|
+
const out = kv(s, rows, width);
|
|
203
|
+
if (v.pending !== null) {
|
|
204
|
+
const hint = goBackHint(ui, v.pending);
|
|
205
|
+
out.push("", ...callout(s, {
|
|
206
|
+
kind: "warn", title: t(v.pending.interrupted ? "update.pending.interrupted" : "update.pending.running", { target: v.pending.target, at: ui.f.date(v.pending.startedAt) }),
|
|
207
|
+
body: hint ? textLines(s, hint, Math.max(1, width - 2)) : [],
|
|
208
|
+
}, width));
|
|
209
|
+
}
|
|
210
|
+
if (v.latest !== null && classify(v.installed, v.latest) !== "none" && v.kind === "global") out.push("", ...noteLines(s, "info", t("update.toInstall"), width));
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function check(c ) {
|
|
215
|
+
const kind = installKind(c.root);
|
|
216
|
+
const installed = c.readVersion();
|
|
217
|
+
const state = await readUpdateState(c.dir);
|
|
218
|
+
const source = state?.source ?? c.defaultSource;
|
|
219
|
+
const config = await loadConfig(c.dir, c.home).catch(() => undefined);
|
|
220
|
+
const versions = source === null ? null : await releaseVersions(source, c.run, c.platform);
|
|
221
|
+
const latest = versions === null ? null : newestRelease(versions);
|
|
222
|
+
const lastUpdate = (await new Journal(join(c.dir, "journal.jsonl")).readAll().catch(() => []))
|
|
223
|
+
.filter((e) => e.t === "update" && e.outcome !== "pending").at(-1);
|
|
224
|
+
const view = {
|
|
225
|
+
installed, kind, root: c.root, latest, skipped: latest !== null && (state?.skip ?? []).includes(latest),
|
|
226
|
+
auto: versions === null ? null : autoTarget(installed, versions, state?.skip ?? []),
|
|
227
|
+
source, automatic: config === undefined ? undefined : updateAuto(config), lastCheckAt: state?.lastCheckAt ?? null,
|
|
228
|
+
lastUpdate: lastUpdate && lastUpdate.t === "update" ? { from: lastUpdate.from, to: lastUpdate.to, outcome: lastUpdate.outcome, error: lastUpdate.error } : null,
|
|
229
|
+
pending: await readPendingUpdate(c.dir),
|
|
230
|
+
};
|
|
231
|
+
c.io.stdout(renderUpdateCheck(cliUi(c.io, { now: () => c.clock.now() }), view).join("\n") + "\n");
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ---------- the engine ----------
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* What runUpdate needs. The watcher is stopped by its own control (never by name) and started again through the
|
|
239
|
+
* scheduler entry, re-registered with config.json's interval (src/ops/updater.ts watcherOps).
|
|
240
|
+
*/
|
|
241
|
+
async function engine(c , installed , source , o = {}) {
|
|
242
|
+
let watcher = c.deps.watcher;
|
|
243
|
+
if (!watcher) {
|
|
244
|
+
const every = (await loadConfig(c.dir, c.home).catch(() => null))?.schedule.everyMinutes ?? DEFAULT_SCHEDULE_MINUTES;
|
|
245
|
+
watcher = watcherOps({
|
|
246
|
+
platform: c.platform, run: c.run, stateDir: c.dir, nodePath: process.execPath, binPath: defaultBinPath(), home: c.home,
|
|
247
|
+
everyMinutes: every, systemRoot: systemRoot(c.io.env),
|
|
248
|
+
// A restart follows every stop here: the stopped heartbeat says so (restart-lost if no successor comes).
|
|
249
|
+
stop: () => stopWatcher({ stateDir: c.dir, platform: c.platform, kill: (pid) => process.kill(pid), clock: realClock, intent: "restart" }),
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
stateDir: c.dir, installed, readInstalled: c.readVersion, run: c.run, platform: c.platform, clock: c.clock, watcher,
|
|
254
|
+
...(source !== undefined ? { source } : {}),
|
|
255
|
+
...(c.defaultSource !== null ? { defaultSource: c.defaultSource } : {}),
|
|
256
|
+
...(c.deps.readHeartbeat ? { readHeartbeat: c.deps.readHeartbeat } : {}),
|
|
257
|
+
...(c.deps.tmp ? { tmp: c.deps.tmp } : {}),
|
|
258
|
+
...(o.onStep ? { onStep: o.onStep } : {}),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** What status shows about the update (a failure needs attention until an update installs). Never throws. */
|
|
263
|
+
async function record(c , r ) {
|
|
264
|
+
if (r.outcome !== "installed" && NOT_ATTEMPTED.has(r.error ?? "")) return false;
|
|
265
|
+
await recordUpdateOutcome(c.dir, { outcome: r.outcome, from: r.from, to: r.to }, new Date(c.clock.now())).catch(() => { /* status only */ });
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// ---------- --auto-run (the watcher's child) ----------
|
|
270
|
+
|
|
271
|
+
async function autoRun(c ) {
|
|
272
|
+
if (installKind(c.root) !== "global") return 0; // a checkout or npx: never updated by itself
|
|
273
|
+
const config = await loadConfig(c.dir, c.home).catch(() => undefined);
|
|
274
|
+
if (config === undefined || !updateAuto(config)) return 0; // turned off since the watcher looked
|
|
275
|
+
const installed = c.readVersion();
|
|
276
|
+
const state = await readUpdateState(c.dir);
|
|
277
|
+
const source = state?.source ?? c.defaultSource;
|
|
278
|
+
if (source === null) return 0;
|
|
279
|
+
const versions = await releaseVersions(source, c.run, c.platform);
|
|
280
|
+
const target = versions === null ? null : autoTarget(installed, versions, state?.skip ?? []);
|
|
281
|
+
if (target === null) return 0; // nothing newer within this major: a major is never installed by itself
|
|
282
|
+
const r = await runUpdate(target, await engine(c, installed, state === null ? source : undefined));
|
|
283
|
+
if (r.error === "busy") {
|
|
284
|
+
// Another t3sm run holds the lock: the watcher's next check comes within the hour instead of tomorrow.
|
|
285
|
+
await appendSyncLog(c.dir, `${new Date(c.clock.now()).toISOString()} update busy to=${target}`).catch(() => {});
|
|
286
|
+
await requestUpdateRetry(c.dir, new Date(c.clock.now() + UPDATE_CHECK_RETRY_MS));
|
|
287
|
+
return 0;
|
|
288
|
+
}
|
|
289
|
+
const attempted = await record(c, r);
|
|
290
|
+
if (attempted) await appendSyncLog(c.dir, `${new Date(c.clock.now()).toISOString()} update ${r.outcome} from=${r.from} to=${r.to}`).catch(() => {});
|
|
291
|
+
if (attempted && r.outcome !== "installed") {
|
|
292
|
+
const notifier = c.deps.notifier ?? (c.deps.home === undefined ? systemNotifier(process.platform, defaultRunner) : undefined);
|
|
293
|
+
if (notifier) {
|
|
294
|
+
// Started by the watcher: the language comes from the env and config.json, as the cycle resolves it.
|
|
295
|
+
const n = updateNotice(r.outcome === "rolled-back" ? "rolled-back" : "failed", { from: r.from, to: r.to }, langOf(c.io, config?.language ?? null));
|
|
296
|
+
await notifyOnce({
|
|
297
|
+
stateDir: c.dir, mode: config?.notify ?? "attention", notifier, now: c.clock.now(), key: `${UPDATE_FAILED_REASON}:${r.to}`, title: n.title, body: n.body,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return r.outcome === "installed" || r.error === "busy" ? 0 : 1;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ---------- update (manual) ----------
|
|
305
|
+
|
|
306
|
+
const STEP = {
|
|
307
|
+
installing: "update.step.installing", restarting: "update.step.restarting", checking: "update.step.checking", "rolling-back": "update.step.rollingBack",
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
/** Release notes (English, from a CHANGELOG.md) drawn like a help topic: headings, bullets, wrapped. */
|
|
311
|
+
export function renderNotes(ui , sections , width = ui.width) {
|
|
312
|
+
return renderMarkdown(ui, renderSections(sections), width);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async function manual(c , choice , yes , dryRun ) {
|
|
316
|
+
const { io } = c;
|
|
317
|
+
const ui = cliUi(io);
|
|
318
|
+
const { s, t } = ui;
|
|
319
|
+
const say = (l ) => io.stdout(l.join("\n") + "\n");
|
|
320
|
+
const note = (tone , text ) => noteLines(s, tone, text, ui.width);
|
|
321
|
+
const cmd = (line ) => fitLine(" " + s("key", line), ui.width, 6);
|
|
322
|
+
const kind = installKind(c.root);
|
|
323
|
+
const installed = c.readVersion();
|
|
324
|
+
if (kind === "checkout") {
|
|
325
|
+
say([...note("info", t("update.checkout", { version: installed, path: c.root })), ...cmd(`git -C "${c.root}" pull`)]);
|
|
326
|
+
return 0;
|
|
327
|
+
}
|
|
328
|
+
if (kind === "npx") {
|
|
329
|
+
say([...note("info", t("update.npx", { version: installed })), ...cmd(`npm install -g ${c.packageName || "t3code-session-manager"}`), ...textLines(s, t("update.npxThen"), ui.width, 2)]);
|
|
330
|
+
return 0;
|
|
331
|
+
}
|
|
332
|
+
if (choice !== null && choice !== "github" && choice !== "npm") {
|
|
333
|
+
const why = sourceProblem(choice, c.platform);
|
|
334
|
+
if (why !== null) { io.stderr(`${why}\n`); return 2; }
|
|
335
|
+
}
|
|
336
|
+
if (!yes && !dryRun && !io.isTTY) {
|
|
337
|
+
io.stderr(`${t("update.needsYes")}\n`);
|
|
338
|
+
return 2;
|
|
339
|
+
}
|
|
340
|
+
const state = await readUpdateState(c.dir);
|
|
341
|
+
const source = choice === "github" ? defaultUpdateSource(c.repoUrl)
|
|
342
|
+
: choice === "npm" ? (c.packageName !== "" ? { kind: "npm" , name: c.packageName } : null)
|
|
343
|
+
: choice ?? state?.source ?? c.defaultSource;
|
|
344
|
+
if (source === null) {
|
|
345
|
+
io.stderr(`${t("update.noSource")}\n`);
|
|
346
|
+
return 1;
|
|
347
|
+
}
|
|
348
|
+
const versions = await releaseVersions(source, c.run, c.platform);
|
|
349
|
+
if (versions === null) {
|
|
350
|
+
io.stderr(`${t("update.lookupFailed", { source: describe(source, ui.lang), version: installed })}\n`);
|
|
351
|
+
return 1;
|
|
352
|
+
}
|
|
353
|
+
const latest = newestRelease(versions);
|
|
354
|
+
if (latest === null || classify(installed, latest) === "none") {
|
|
355
|
+
const older = latest !== null && parseSemver(installed) !== null && compareSemver(latest, installed) < 0;
|
|
356
|
+
say(note("ok", older ? t("update.newestOlder", { version: installed, source: describe(source, ui.lang), latest: latest }) : t("update.newest", { version: installed })));
|
|
357
|
+
return 0;
|
|
358
|
+
}
|
|
359
|
+
const level = classify(installed, latest);
|
|
360
|
+
const levelWord = t(level === "major" ? "update.level.major" : level === "minor" ? "update.level.minor" : "update.level.patch");
|
|
361
|
+
const head = `t3sm ${installed} -> ${latest} (${levelWord})`;
|
|
362
|
+
const body = [t("update.from", { source: describe(source, ui.lang) }), ...(level === "major" ? [t("update.majorNote")] : [])];
|
|
363
|
+
say(panel(s, { title: head, body, tone: level === "major" ? "warn" : "plain" }, snugWidth(head, body, ui.width)));
|
|
364
|
+
if (source.kind === "folder") {
|
|
365
|
+
const r = await c.run("git", ["-C", source.path, "show", `v${latest}:CHANGELOG.md`], { timeoutMs: QUERY_TIMEOUT_MS }).catch(() => null);
|
|
366
|
+
const sections = r !== null && r.code === 0 ? sectionsBetween(r.stdout, installed, latest) : [];
|
|
367
|
+
say(sections.length > 0 ? ["", ...fitLine(s("title", t("update.whatsNew")), ui.width), "", ...renderNotes(ui, sections)] : note("warn", t("update.noNotes", { version: latest })));
|
|
368
|
+
} else {
|
|
369
|
+
say(note("info", t("update.notesLater")));
|
|
370
|
+
}
|
|
371
|
+
if (dryRun) { say(["", ...note("ok", t("update.dryRun", { version: latest, source: describe(source, ui.lang) }))]); return 0; }
|
|
372
|
+
if (!yes) {
|
|
373
|
+
io.stdout("\n");
|
|
374
|
+
if (!(await confirm(io, t("update.confirm", { version: latest })))) { io.stdout(`${t("common.nothingChanged")}\n`); return 0; }
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const r = await runUpdate(latest, await engine(c, installed, source, { onStep: (st) => say(note("info", t(STEP[st], { to: latest, from: installed }))) }));
|
|
378
|
+
await record(c, r);
|
|
379
|
+
if (r.outcome === "installed") {
|
|
380
|
+
say(note("ok", t("update.updated", { from: installed, to: latest })));
|
|
381
|
+
// Installed, but the watcher could not be restarted into it (it did not stop, or the scheduler call failed).
|
|
382
|
+
if (r.error !== undefined) say(note("warn", t("update.notRestarted", { error: shownText(r.error, 300) })));
|
|
383
|
+
if (source.kind !== "folder") {
|
|
384
|
+
const text = (c.deps.readChangelog ?? (() => { try { return readFileSync(join(c.root, "CHANGELOG.md"), "utf8"); } catch { return null; } }))();
|
|
385
|
+
const sections = text === null ? [] : sectionsBetween(text, installed, latest);
|
|
386
|
+
say(sections.length > 0 ? ["", ...fitLine(s("title", t("update.whatsNew")), ui.width), "", ...renderNotes(ui, sections)] : note("info", t("update.whatsNewLater", { version: installed })));
|
|
387
|
+
}
|
|
388
|
+
return 0;
|
|
389
|
+
}
|
|
390
|
+
if (r.error === "busy") { reportLockBusy(io); return 0; }
|
|
391
|
+
if (r.error === "not-newer") { say(note("ok", t("update.notNewer", { version: r.from }))); return 0; }
|
|
392
|
+
if (r.outcome === "rolled-back") {
|
|
393
|
+
io.stderr(`${t("update.rolledBack", { to: latest, from: installed, error: shownText(r.error ?? t("update.noDetails"), 300) })}\n`);
|
|
394
|
+
return 1;
|
|
395
|
+
}
|
|
396
|
+
io.stderr(`${t("update.failed", { to: latest, error: shownText(r.error ?? t("update.unknownError"), 300), from: installed })}\n`);
|
|
397
|
+
return 1;
|
|
398
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ConfigError, NoPlanError } from "../core/config.js";
|
|
2
|
+
import { RpcError, ShapeError, T3AuthError, T3HttpError, T3Incompatible, T3NotRunning } from "../t3/errors.js";
|
|
3
|
+
import { InstanceHomeDrift } from "../ops/accounts.js";
|
|
4
|
+
import { ApplyRefusal } from "../apply/apply.js";
|
|
5
|
+
import { JournalWriteError } from "../ops/quarantine.js";
|
|
6
|
+
import { shownText } from "../plan/names.js";
|
|
7
|
+
import { lostContact, redactUnexpected } from "../ops/errorCodes.js";
|
|
8
|
+
import { panel } from "../ui/components.js";
|
|
9
|
+
import { wrapText } from "../ui/text.js";
|
|
10
|
+
import { helpCommand } from "./helpTopics.js";
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export { describeError, oneLine } from "../ops/errorCodes.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* What a screen says about an error: a title in the user's language (what happened), the detail (the error's own text,
|
|
17
|
+
* English, sanitised; none when the title says it all), what to do, and the `t3sm help` topic.
|
|
18
|
+
*/
|
|
19
|
+
export function errorParts(e , platform = process.platform) {
|
|
20
|
+
const help = helpCommand("errors");
|
|
21
|
+
if (e instanceof T3NotRunning) return { title: "error.t3Down.title", detail: null, todo: platform === "win32" ? "error.t3DownWin.todo" : "error.t3Down.todo", help: "t3sm doctor" };
|
|
22
|
+
if (e instanceof T3Incompatible || e instanceof ShapeError) return { title: "error.incompatible.title", detail: e.message, todo: "error.incompatible.todo", help };
|
|
23
|
+
if (e instanceof JournalWriteError) return { title: "error.journal.title", detail: e.message, todo: "error.journal.todo", help };
|
|
24
|
+
if (e instanceof NoPlanError) return { title: "error.noPlan.title", detail: null, todo: "error.noPlan.todo", help: "t3sm plan" };
|
|
25
|
+
if (e instanceof ConfigError || e instanceof InstanceHomeDrift || e instanceof ApplyRefusal) return { title: "error.config.title", detail: e.message, todo: "error.config.todo", help };
|
|
26
|
+
if (e instanceof T3AuthError) return { title: "error.auth.title", detail: `${e.message}${e.hint ? ` ${e.hint}` : ""}`, todo: "error.auth.todo", help };
|
|
27
|
+
if (lostContact(e)) return { title: "error.t3Lost.title", detail: e.message, todo: "error.t3Lost.todo", help: "t3sm doctor" };
|
|
28
|
+
if (e instanceof T3HttpError || e instanceof RpcError) return { title: "error.rejected.title", detail: e.message, todo: "error.rejected.todo", help };
|
|
29
|
+
return { title: "error.unexpected.title", detail: redactUnexpected(e instanceof Error ? e.message : String(e)), todo: "error.unexpected.todo", help: "t3sm doctor" };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The error as a panel: what happened (title and detail), what to do, and the command that helps. Exit codes: describeError. */
|
|
33
|
+
export function renderError(e , ui , platform = process.platform) {
|
|
34
|
+
const { s, t } = ui;
|
|
35
|
+
const width = Math.max(1, ui.width);
|
|
36
|
+
const p = errorParts(e, platform);
|
|
37
|
+
const inner = Math.max(1, width - 4);
|
|
38
|
+
const body = [];
|
|
39
|
+
// The detail keeps its own lines (a config error lists one problem per line, then the hint), without Markdown
|
|
40
|
+
// backticks; an indented line stays indented.
|
|
41
|
+
if (p.detail !== null) {
|
|
42
|
+
for (const raw of p.detail.split(/\r?\n/).slice(0, 40)) {
|
|
43
|
+
const line = shownText(raw.replace(/`([^`\n]+)`/g, "$1"), 2000);
|
|
44
|
+
if (!line.trim()) continue;
|
|
45
|
+
const indent = /^\s*/.exec(raw)?.[0].length ? " " : "";
|
|
46
|
+
body.push(...wrapText(line.trim(), Math.max(1, inner - indent.length)).map((l) => indent + l));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (body.length > 0) body.push("");
|
|
50
|
+
body.push(...wrapText(`${t("error.whatToDo")}: ${t(p.todo)}`, inner));
|
|
51
|
+
body.push(`${s.sym.arrow} ${s("key", p.help)}`);
|
|
52
|
+
return panel(s, { tone: "err", title: t(p.title), body }, width);
|
|
53
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Conversations that could not be imported (apply, sync), as a person can act on them: the project, the conversation
|
|
2
|
+
// (its title, never its id), why in words (never a reason code) and what to do, then one line with the `t3sm help`
|
|
3
|
+
// topics that explain the reasons. Titles and folders come from transcripts and T3 Code: untrusted, through shownText.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { shownText } from "../plan/names.js";
|
|
7
|
+
import { table, } from "../ui/components.js";
|
|
8
|
+
import { displayWidth } from "../ui/text.js";
|
|
9
|
+
import { reasonKind, helpTopicFor, } from "./helpTopics.js";
|
|
10
|
+
import { fitLine, flowAtoms, richAtoms } from "./screen.js";
|
|
11
|
+
|
|
12
|
+
import { folderName } from "./words.js";
|
|
13
|
+
|
|
14
|
+
/** Rows shown before "and N more" (and the failures whose titles are read). */
|
|
15
|
+
export const FAILURES_SHOWN = 20;
|
|
16
|
+
/** Narrower than this the failures are a list: four columns would cut the title or what to do. */
|
|
17
|
+
const TABLE_MIN = 100;
|
|
18
|
+
|
|
19
|
+
/** Why each kind of failure happened, and what to do about it. */
|
|
20
|
+
const WORDS = {
|
|
21
|
+
"not-imported": { why: "fail.why.notImported", todo: "fail.todo.notImported" },
|
|
22
|
+
"cwd-unreadable-in-t3": { why: "fail.why.cwdUnreadable", todo: "fail.todo.cwdUnreadable" },
|
|
23
|
+
"instance-unavailable": { why: "fail.why.instanceUnavailable", todo: "fail.todo.instanceUnavailable" },
|
|
24
|
+
"project-mismatch": { why: "fail.why.projectMismatch", todo: "fail.todo.projectMismatch" },
|
|
25
|
+
"no-reader": { why: "fail.why.noReader", todo: "fail.todo.noReader" },
|
|
26
|
+
"target-outside-accounts": { why: "fail.why.targetOutside", todo: "fail.todo.targetOutside" },
|
|
27
|
+
"target-exists": { why: "fail.why.targetExists", todo: "fail.todo.targetExists" },
|
|
28
|
+
"read-failed": { why: "fail.why.readFailed", todo: "fail.todo.readFailed" },
|
|
29
|
+
"write-failed": { why: "fail.why.writeFailed", todo: "fail.todo.writeFailed" },
|
|
30
|
+
"target-folder": { why: "fail.why.targetFolder", todo: "fail.todo.targetFolder" },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** The catalogue words for a reason code; a code t3sm does not know gets the general words. */
|
|
34
|
+
export function failureWords(reason ) {
|
|
35
|
+
const k = reasonKind(reason);
|
|
36
|
+
return k !== null ? WORDS[k] : { why: "fail.why.other", todo: "fail.todo.other" };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* "More help: t3sm help not-imported, cwd-unreadable, convert": the topics after one `t3sm help`, separated by commas
|
|
43
|
+
* (never "-" or "·", which an ASCII console would draw as a dash); a topic is never split.
|
|
44
|
+
*/
|
|
45
|
+
export function helpLine(ui , reasons , width = ui.width) {
|
|
46
|
+
const { s } = ui;
|
|
47
|
+
const topics = [...new Set(reasons.map(helpTopicFor))];
|
|
48
|
+
if (topics.length === 0) return [];
|
|
49
|
+
const atoms = [s("muted", s.sym.arrow), ...ui.t("common.moreHelp", { command: "" }).trim().split(/\s+/),
|
|
50
|
+
...topics.map((tp, i) => s("key", i === 0 ? `t3sm help ${tp}` : tp) + (i < topics.length - 1 ? s("muted", ",") : ""))];
|
|
51
|
+
return flowAtoms(atoms, width, 2);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The failures, titled ("could not be imported", or with `dry` "would fail to import"), at most FAILURES_SHOWN of
|
|
56
|
+
* them. A table when every column fits whole in a window of 100 columns or more; otherwise one entry per conversation
|
|
57
|
+
* ("project · title", then "why · what to do"), so nothing is ever cut. Then the help topics, on one line.
|
|
58
|
+
*/
|
|
59
|
+
export function failureTable(ui , failures , width = ui.width, o = {}) {
|
|
60
|
+
if (failures.length === 0) return [];
|
|
61
|
+
const { s, t } = ui;
|
|
62
|
+
const shown = failures.slice(0, FAILURES_SHOWN);
|
|
63
|
+
const rows = shown.map((f) => {
|
|
64
|
+
const w = failureWords(f.reason);
|
|
65
|
+
return {
|
|
66
|
+
project: shownText(folderName(f.projectRoot), 60),
|
|
67
|
+
conversation: f.title !== null && f.title.trim() !== "" ? shownText(f.title, 80) : t("common.untitled"),
|
|
68
|
+
// What to do may name a command (`t3sm apply`): the table shows it plain, the list keeps it whole.
|
|
69
|
+
why: t(w.why), todo: t(w.todo).replace(/`/g, ""), todoAtoms: richAtoms(s, t(w.todo)),
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
const out = fitLine(`${s("err", s.sym.err)} ${s("title", t(o.dry ? "fail.titleDry" : "fail.title", { n: failures.length }))}`, width, 2);
|
|
73
|
+
const cols = [
|
|
74
|
+
{ header: t("fail.col.project"), get: (r) => (r ).project },
|
|
75
|
+
{ header: t("fail.col.conversation"), get: (r) => (r ).conversation },
|
|
76
|
+
{ header: t("fail.col.why"), get: (r) => (r ).why },
|
|
77
|
+
{ header: t("fail.col.todo"), get: (r) => (r ).todo },
|
|
78
|
+
];
|
|
79
|
+
const natural = cols.reduce((a, c) => a + Math.max(displayWidth(c.header), ...rows.map((r) => displayWidth(c.get(r)))), 0) + 2 * (cols.length - 1);
|
|
80
|
+
if (width >= TABLE_MIN && natural <= width) out.push(...table(s, cols, rows, width));
|
|
81
|
+
else {
|
|
82
|
+
for (const r of rows) {
|
|
83
|
+
out.push(...fitLine(`${s("title", r.project)} ${s("muted", s.sym.sep)} ${r.conversation}`, width, 2));
|
|
84
|
+
out.push(...flowAtoms([...r.why.split(/\s+/), s("muted", s.sym.sep), ...r.todoAtoms], Math.max(1, width - 2), 2).map((l) => ` ${l}`));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (failures.length > shown.length) out.push(...fitLine(s("muted", `${s.sym.ellipsis} ${t("common.andMore", { n: failures.length - shown.length })} (t3sm runs)`), width));
|
|
88
|
+
out.push(...helpLine(ui, shown.map((f) => f.reason), width));
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// The options each command accepts, in one place: the commands' parsers read their lists from here, and a test checks
|
|
2
|
+
// that every option a help text shows (src/cli/help.en.ts, help.pt.ts) is one of them and that each one is documented.
|
|
3
|
+
// The global options (--lang, --no-color) are parsed by main for every command and are not repeated per command.
|
|
4
|
+
|
|
5
|
+
/** Options without a value, and options that take one (`--run <id>`), per command. */
|
|
6
|
+
export const FLAG_SPECS = {
|
|
7
|
+
doctor: { bool: ["--json", "--repair"], valued: [] },
|
|
8
|
+
scan: { bool: ["--json"], valued: [] },
|
|
9
|
+
plan: { bool: ["--json", "--allow-untested"], valued: [] },
|
|
10
|
+
accounts: { bool: ["--init", "--force", "--apply", "--yes", "--allow-untested", "--show-emails"], valued: ["--rename", "--color"] },
|
|
11
|
+
apply: { bool: ["--yes", "--allow-untested", "--quiet", "--dry-run", "--verbose"], valued: ["--plan", "--only"] },
|
|
12
|
+
quarantine: { bool: ["--yes", "--dry-run"], valued: [] },
|
|
13
|
+
dedupe: { bool: ["--yes", "--dry-run"], valued: ["--plan"] },
|
|
14
|
+
rollback: { bool: ["--yes", "--dry-run", "--instances", "--archive-threads", "--allow-untested"], valued: ["--run"] },
|
|
15
|
+
runs: { bool: ["--json"], valued: [] },
|
|
16
|
+
sync: { bool: ["--quiet", "--allow-untested", "--watch", "--dry-run", "--verbose"], valued: [] },
|
|
17
|
+
schedule: { bool: ["--watch", "--dry-run", "--yes"], valued: [] },
|
|
18
|
+
merge: { bool: ["--all", "--dry-run", "--yes", "--allow-untested"], valued: ["--session"] },
|
|
19
|
+
recover: { bool: ["--yes", "--dry-run", "--allow-untested"], valued: [] },
|
|
20
|
+
projects: { bool: ["--json", "--allow-untested", "--yes", "--dry-run", "--force", "--suggest"], valued: [] },
|
|
21
|
+
start: { bool: [], valued: [] },
|
|
22
|
+
update: { bool: ["--yes", "--dry-run", "--check", "--auto-run"], valued: ["--from", "--source", "--auto"] },
|
|
23
|
+
changelog: { bool: [], valued: ["--since"] },
|
|
24
|
+
organize: {
|
|
25
|
+
bool: ["--dry-run", "--yes", "--allow-untested", "--plain", "--no-delete", "--no-archive-folders"],
|
|
26
|
+
valued: ["--undo", "--only", "--auto-settle", "--history", "--min", "--no-pin"],
|
|
27
|
+
},
|
|
28
|
+
status: { bool: ["--json"], valued: [] },
|
|
29
|
+
help: { bool: [], valued: [] },
|
|
30
|
+
} ;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/** `t3sm projects` per subcommand (the table, set, unset, rename); together they are FLAG_SPECS.projects. */
|
|
35
|
+
export const PROJECTS_FLAGS = {
|
|
36
|
+
list: ["--json", "--allow-untested"],
|
|
37
|
+
set: ["--yes", "--dry-run", "--force", "--allow-untested"],
|
|
38
|
+
unset: ["--dry-run"],
|
|
39
|
+
rename: ["--suggest", "--yes", "--dry-run", "--allow-untested"],
|
|
40
|
+
} ;
|
|
41
|
+
|
|
42
|
+
/** Every option a command accepts (with and without a value). */
|
|
43
|
+
export const COMMAND_FLAGS = Object.fromEntries(
|
|
44
|
+
Object.entries(FLAG_SPECS).map(([k, v]) => [k, [...v.bool, ...v.valued]]),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
/** The options of every command, parsed by main. */
|
|
48
|
+
export const GLOBAL_FLAGS = ["--lang", "--no-color", "--help", "-h"];
|
|
49
|
+
|
|
50
|
+
/** A command's options as the mutable lists `parseFlags` takes. */
|
|
51
|
+
export function flagsOf(cmd ) {
|
|
52
|
+
return { bool: [...FLAG_SPECS[cmd].bool], valued: [...FLAG_SPECS[cmd].valued] };
|
|
53
|
+
}
|