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,211 @@
|
|
|
1
|
+
// The one renderer of t3sm's help: the usage overview, each command's help and the global options (src/cli/help.en.ts
|
|
2
|
+
// and help.pt.ts), styled with the UI kit and fitted to the window. The texts keep a small fixed shape (see help.en.ts);
|
|
3
|
+
// this file reads it: the usage forms as commands, headings in bold, options and commands as a two-column list whose
|
|
4
|
+
// descriptions wrap under their column (stacked under the option on a narrow window), paragraphs and bullets wrapped,
|
|
5
|
+
// `backticks` as commands. Nothing is ever cut: what does not fit wraps.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import { displayWidth } from "../ui/text.js";
|
|
10
|
+
import { fitLine, richAtoms, wrapAtoms } from "./screen.js";
|
|
11
|
+
import * as en from "./help.en.js";
|
|
12
|
+
import * as pt from "./help.pt.js";
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export const HELP_TEXTS = {
|
|
17
|
+
en: { usage: en.USAGE, global: en.GLOBAL, commands: en.COMMANDS },
|
|
18
|
+
pt: { usage: pt.USAGE, global: pt.GLOBAL, commands: pt.COMMANDS },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** A command's help text and the global options, in `lang`; null for an unknown command. */
|
|
22
|
+
export function commandHelp(name , lang ) {
|
|
23
|
+
const h = HELP_TEXTS[lang];
|
|
24
|
+
return Object.hasOwn(h.commands, name) ? h.commands[name] + h.global : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The usage overview and the global options, in `lang`. */
|
|
28
|
+
export function usageHelp(lang ) {
|
|
29
|
+
return HELP_TEXTS[lang].usage + HELP_TEXTS[lang].global;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const OPTION_HEADINGS = new Set(["Options:", "Opções:"]);
|
|
33
|
+
const USAGE_RE = /^(Usage|Uso):/;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const indentOf = (l ) => /^ */.exec(l) [0].length;
|
|
44
|
+
|
|
45
|
+
function parseItems(lines ) {
|
|
46
|
+
const items = [];
|
|
47
|
+
for (const l of lines) {
|
|
48
|
+
if (indentOf(l) === 2) {
|
|
49
|
+
const m = /^ {2}(.+?)(?: {2,}(\S.*))?$/.exec(l) ;
|
|
50
|
+
const col = m[2] !== undefined ? l.length - m[2].length : null;
|
|
51
|
+
items.push({ term: m[1] .trim(), col, desc: m[2] !== undefined ? [{ pre: false, text: m[2] }] : [] });
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const it = items.at(-1);
|
|
55
|
+
if (!it) continue;
|
|
56
|
+
const trimmed = l.trim();
|
|
57
|
+
// A continued line with aligned columns inside (status --help's JSON keys) is kept as it is.
|
|
58
|
+
if (/\S {2,}\S/.test(trimmed)) it.desc.push({ pre: true, line: l });
|
|
59
|
+
else {
|
|
60
|
+
const last = it.desc.at(-1);
|
|
61
|
+
if (last && !last.pre) last.text += " " + trimmed;
|
|
62
|
+
else it.desc.push({ pre: false, text: trimmed });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return items;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function parseHelp(text ) {
|
|
69
|
+
const blocks = [];
|
|
70
|
+
for (const raw of text.replace(/\r\n/g, "\n").split(/\n[ \t]*\n/)) {
|
|
71
|
+
const lines = raw.split("\n").filter((l) => l.trim() !== "");
|
|
72
|
+
if (lines.length === 0) continue;
|
|
73
|
+
const first = lines[0] ;
|
|
74
|
+
const rest = lines.slice(1);
|
|
75
|
+
const m = USAGE_RE.exec(first);
|
|
76
|
+
if (m) {
|
|
77
|
+
blocks.push({ kind: "usage", label: m[0], forms: [first.slice(m[0].length).trim(), ...rest.map((l) => l.trim())].filter((f) => f !== "") });
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const indentedRest = rest.length > 0 && indentOf(first) === 0 && rest.every((l) => indentOf(l) >= 2);
|
|
81
|
+
if (indentedRest && /^t3sm /.test(first) && !rest.some((l) => /\S {2,}\S/.test(l.trim()))) {
|
|
82
|
+
blocks.push({ kind: "form", heading: first, body: rest.map((l) => l.trim()) });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (indentedRest && indentOf(rest[0] ) === 2 && !/^ {2}- /.test(rest[0] )) {
|
|
86
|
+
blocks.push({ kind: "items", heading: first, items: parseItems(rest) });
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
blocks.push({ kind: "para", lines });
|
|
90
|
+
}
|
|
91
|
+
return blocks;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Every `--option` a help text offers: in its usage forms and in its Options list (prose mentions are not offers). */
|
|
95
|
+
export function helpFlags(text ) {
|
|
96
|
+
const out = new Set ();
|
|
97
|
+
const add = (s ) => { for (const m of s.matchAll(/(?<![\w-])--[a-z][a-z-]*/g)) out.add(m[0]); };
|
|
98
|
+
for (const b of parseHelp(text)) {
|
|
99
|
+
if (b.kind === "usage") b.forms.forEach(add);
|
|
100
|
+
else if (b.kind === "items" && OPTION_HEADINGS.has(b.heading)) b.items.forEach((i) => add(i.term));
|
|
101
|
+
}
|
|
102
|
+
return [...out];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const rtrim = (l ) => l.replace(/ +$/, "");
|
|
106
|
+
|
|
107
|
+
/** A paragraph's lines with "- " bullets: the text wrapped to `width`, each bullet hanging under its text. */
|
|
108
|
+
function paragraph(ui , lines , width , indent = 0) {
|
|
109
|
+
const { s } = ui;
|
|
110
|
+
const out = [];
|
|
111
|
+
const parts = [];
|
|
112
|
+
for (const l of lines) {
|
|
113
|
+
const b = /^\s*- (.*)$/.exec(l);
|
|
114
|
+
if (b) { parts.push({ bullet: true, text: b[1] }); continue; }
|
|
115
|
+
const last = parts.at(-1);
|
|
116
|
+
if (last && (last.bullet ? indentOf(l) >= 4 : true)) last.text += " " + l.trim();
|
|
117
|
+
else parts.push({ bullet: false, text: l.trim() });
|
|
118
|
+
}
|
|
119
|
+
const pad = " ".repeat(indent);
|
|
120
|
+
for (const p of parts) {
|
|
121
|
+
const atoms = richAtoms(s, p.text);
|
|
122
|
+
if (!p.bullet) { for (const l of wrapAtoms(atoms, width - indent, width - indent)) out.push(pad + l); continue; }
|
|
123
|
+
const lead = `${pad} ${s.sym.bullet} `;
|
|
124
|
+
const hang = displayWidth(lead);
|
|
125
|
+
wrapAtoms(atoms, width - hang, width - hang).forEach((l, i) => out.push((i === 0 ? s("muted", lead) : " ".repeat(hang)) + l));
|
|
126
|
+
}
|
|
127
|
+
return out.map(rtrim);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function renderItems(ui , b , width ) {
|
|
131
|
+
const { s } = ui;
|
|
132
|
+
const out = fitLine(s("title", b.heading), width);
|
|
133
|
+
const cols = b.items.map((i) => i.col).filter((c) => c !== null);
|
|
134
|
+
// The column the text was laid out for: the one most items use.
|
|
135
|
+
const count = new Map ();
|
|
136
|
+
for (const c of cols) count.set(c, (count.get(c) ?? 0) + 1);
|
|
137
|
+
const col = [...count.entries()].sort((x, y) => y[1] - x[1] || x[0] - y[0])[0]?.[0] ?? 4;
|
|
138
|
+
const wide = width >= 60 && col <= Math.floor(width / 2);
|
|
139
|
+
for (const it of b.items) {
|
|
140
|
+
const term = it.term;
|
|
141
|
+
const termLines = (w ) => (displayWidth(term) <= w ? [term] : fitLine(term, w));
|
|
142
|
+
if (it.desc.length === 0) { for (const l of termLines(width - 2)) out.push(" " + s("key", l)); continue; }
|
|
143
|
+
const descCol = wide ? col : 4;
|
|
144
|
+
let firstRoom ;
|
|
145
|
+
if (wide && 2 + displayWidth(term) + 2 <= width - 10) {
|
|
146
|
+
// On the term's line, at the column (or right after a term wider than it), then under the column.
|
|
147
|
+
const start = Math.max(col, 2 + displayWidth(term) + 2);
|
|
148
|
+
firstRoom = width - start;
|
|
149
|
+
let first = true;
|
|
150
|
+
for (const seg of it.desc) {
|
|
151
|
+
if (seg.pre) { pushPre(out, seg.line, it.col ?? col, descCol, width); first = false; continue; }
|
|
152
|
+
wrapAtoms(richAtoms(s, seg.text), first ? firstRoom : width - descCol, width - descCol).forEach((l, i) => {
|
|
153
|
+
if (first && i === 0) out.push(rtrim(" " + s("key", term) + " ".repeat(start - 2 - displayWidth(term)) + l));
|
|
154
|
+
else out.push(rtrim(" ".repeat(descCol) + l));
|
|
155
|
+
});
|
|
156
|
+
first = false;
|
|
157
|
+
}
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
for (const l of termLines(width - 2)) out.push(" " + s("key", l));
|
|
161
|
+
for (const seg of it.desc) {
|
|
162
|
+
if (seg.pre) { pushPre(out, seg.line, it.col ?? col, descCol, width); continue; }
|
|
163
|
+
for (const l of wrapAtoms(richAtoms(s, seg.text), width - descCol, width - descCol)) out.push(rtrim(" ".repeat(descCol) + l));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** A continued line with aligned columns, moved from the text's column to `descCol` (its own alignment kept), fitted. */
|
|
170
|
+
function pushPre(out , line , srcCol , descCol , width ) {
|
|
171
|
+
const rel = Math.max(0, indentOf(line) - srcCol);
|
|
172
|
+
const text = " ".repeat(descCol + rel) + line.trim();
|
|
173
|
+
if (displayWidth(text) <= width) { out.push(text); return; }
|
|
174
|
+
// Too wide: the aligned head (" key ") stays as it is, the rest wraps under its own column.
|
|
175
|
+
const m = /^(\s*\S+ {2,})(\S.*)$/.exec(text);
|
|
176
|
+
const head = m ? displayWidth(m[1] ) : width;
|
|
177
|
+
if (!m || head > width - 12) { out.push(...fitLine(text, width, 2)); return; }
|
|
178
|
+
wrapAtoms(m[2] .split(/ +/), width - head, width - head).forEach((l, i) => out.push((i === 0 ? m[1] : " ".repeat(head)) + l));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function renderUsage(ui , b , width ) {
|
|
182
|
+
const { s } = ui;
|
|
183
|
+
const label = b.label + " ";
|
|
184
|
+
const lw = displayWidth(label);
|
|
185
|
+
const out = [];
|
|
186
|
+
const beside = lw <= Math.floor(width / 3);
|
|
187
|
+
if (!beside) out.push(s("title", b.label));
|
|
188
|
+
const ind = beside ? lw : 2;
|
|
189
|
+
b.forms.forEach((f, n) => {
|
|
190
|
+
const atoms = f.split(/ +/).map((a) => s("key", a));
|
|
191
|
+
wrapAtoms(atoms, width - ind, width - ind - 2).forEach((l, i) => {
|
|
192
|
+
if (i === 0) out.push(rtrim((beside && n === 0 ? s("title", b.label) + " " : " ".repeat(ind)) + l));
|
|
193
|
+
else out.push(rtrim(" ".repeat(ind + 2) + l));
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** A help text (or several, concatenated) as styled lines that fit `width`. */
|
|
200
|
+
export function renderHelpText(ui , text , width = ui.width) {
|
|
201
|
+
const w = Math.max(20, width);
|
|
202
|
+
const out = [];
|
|
203
|
+
for (const b of parseHelp(text)) {
|
|
204
|
+
if (out.length > 0) out.push("");
|
|
205
|
+
if (b.kind === "usage") out.push(...renderUsage(ui, b, w));
|
|
206
|
+
else if (b.kind === "items") out.push(...renderItems(ui, b, w));
|
|
207
|
+
else if (b.kind === "form") out.push(...fitLine(ui.s("key", b.heading), w), ...paragraph(ui, b.body, w, 2));
|
|
208
|
+
else out.push(...paragraph(ui, b.lines, w));
|
|
209
|
+
}
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Which `t3sm help <topic>` explains a reason a screen shows (a failed import, a held project, an undecided question,
|
|
2
|
+
// an error). The topics themselves are docs/help/<topic>.md and <topic>.pt.md (shipped in dist/help, read by
|
|
3
|
+
// src/cli/commands/help.ts); test/cli/help.test.ts checks that every topic named here exists in both languages.
|
|
4
|
+
// Screens print "t3sm help <topic>" instead of pointing at a docs file the user does not have.
|
|
5
|
+
|
|
6
|
+
/** Every topic a screen may name. */
|
|
7
|
+
export const HELP_TOPICS = [
|
|
8
|
+
"not-imported", "t3-native", "orphaned", "held", "decisions", "history", "updates", "watcher", "cwd-unreadable",
|
|
9
|
+
"instance-unavailable", "project-mismatch", "convert", "errors",
|
|
10
|
+
] ;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/** The kinds of import failure: FailReason, and ConvertFailReason without its detail ("read-failed: ..."). */
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const KINDS = new Set ([
|
|
18
|
+
"not-imported", "cwd-unreadable-in-t3", "instance-unavailable", "project-mismatch", "no-reader", "target-outside-accounts",
|
|
19
|
+
"target-exists", "read-failed", "write-failed", "target-folder",
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
/** The kind of an import failure's reason ("convert: read-failed: x" -> "read-failed"); null for any other reason. */
|
|
23
|
+
export function reasonKind(reason ) {
|
|
24
|
+
const k = reason.trim().replace(/^convert: /, "").replace(/:.*$/, "");
|
|
25
|
+
return KINDS.has(k) ? (k ) : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const KIND_TOPIC = {
|
|
29
|
+
"not-imported": "not-imported", "cwd-unreadable-in-t3": "cwd-unreadable", "instance-unavailable": "instance-unavailable",
|
|
30
|
+
"project-mismatch": "project-mismatch", "no-reader": "convert", "target-outside-accounts": "convert", "target-exists": "convert",
|
|
31
|
+
"read-failed": "convert", "write-failed": "convert", "target-folder": "convert",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The topic for a reason code: an import failure (`not-imported`, `cwd-unreadable-in-t3`, a conversion's `read-failed:
|
|
36
|
+
* ...`), a skip or plan reason (`orphaned-in-t3`, `t3-native-unknown`, `undecided`, `project-in-use`), or a status area
|
|
37
|
+
* (`watcher`, `update-failed`, `history`). Anything unknown gets the general "errors" topic.
|
|
38
|
+
*/
|
|
39
|
+
export function helpTopicFor(reason ) {
|
|
40
|
+
const kind = reasonKind(reason);
|
|
41
|
+
if (kind !== null) return KIND_TOPIC[kind];
|
|
42
|
+
const r = reason.trim();
|
|
43
|
+
if (r === "cwd-unreadable" || r === "no-cwd") return "cwd-unreadable";
|
|
44
|
+
if (r === "harness-unavailable") return "instance-unavailable";
|
|
45
|
+
if (r === "orphaned-in-t3" || r === "orphaned") return "orphaned";
|
|
46
|
+
if (r === "t3-native-unknown" || r === "t3-native") return "t3-native";
|
|
47
|
+
if (r === "held" || r === "project-in-use" || r === "active" || r === "in-use") return "held";
|
|
48
|
+
if (r === "undecided" || r === "decisions") return "decisions";
|
|
49
|
+
if (r === "history" || r.startsWith("history:")) return "history";
|
|
50
|
+
if (r === "updates" || r.startsWith("update")) return "updates";
|
|
51
|
+
if (r === "watcher" || r.startsWith("watcher") || r === "sync-failing") return "watcher";
|
|
52
|
+
return "errors";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The command that opens the topic. */
|
|
56
|
+
export function helpCommand(reason ) {
|
|
57
|
+
return `t3sm help ${helpTopicFor(reason)}`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// What a writing command does when another t3sm run holds the lock: it writes nothing, says so and exits 0. The line
|
|
2
|
+
// and the structured signal (Io.onLockBusy, used by the guided assistant) live here, in one place.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const LOCK_BUSY_LINE = "Another t3sm run is in progress.";
|
|
7
|
+
|
|
8
|
+
/** Prints LOCK_BUSY_LINE (unless `quiet`) and tells the caller through io.onLockBusy. The command then returns 0. */
|
|
9
|
+
export function reportLockBusy(io , quiet = false) {
|
|
10
|
+
if (!quiet) io.stdout(`${LOCK_BUSY_LINE}\n`);
|
|
11
|
+
io.onLockBusy?.();
|
|
12
|
+
}
|
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { describeError, renderError } from "./errors.js";
|
|
4
|
+
import { resolveLang, } from "../assistant/i18n.js";
|
|
5
|
+
import { loadConfig } from "../core/config.js";
|
|
6
|
+
import { stateDir } from "../core/paths.js";
|
|
7
|
+
import { detectCaps, } from "../ui/caps.js";
|
|
8
|
+
import { cliUi, parseGlobalFlags, unknownOption, usageLine } from "./ui.js";
|
|
9
|
+
import { scanCommand } from "./commands/scan.js";
|
|
10
|
+
import { planCommand } from "./commands/plan.js";
|
|
11
|
+
import { accountsCommand } from "./commands/accounts.js";
|
|
12
|
+
import { applyCommand } from "./commands/apply.js";
|
|
13
|
+
import { dedupeCommand, quarantineCommand } from "./commands/quarantine.js";
|
|
14
|
+
import { rollbackCommand, runsCommand } from "./commands/rollback.js";
|
|
15
|
+
import { syncCommand } from "./commands/sync.js";
|
|
16
|
+
import { scheduleCommand } from "./commands/schedule.js";
|
|
17
|
+
import { doctorCommand } from "./commands/doctor.js";
|
|
18
|
+
import { mergeCommand } from "./commands/merge.js";
|
|
19
|
+
import { recoverCommand } from "./commands/recover.js";
|
|
20
|
+
import { projectsCommand } from "./commands/projects.js";
|
|
21
|
+
import { startCommand } from "./commands/start.js";
|
|
22
|
+
import { updateCommand } from "./commands/update.js";
|
|
23
|
+
import { changelogCommand } from "./commands/changelog.js";
|
|
24
|
+
import { organizeCommand } from "./commands/organize.js";
|
|
25
|
+
import { statusCommand } from "./commands/status.js";
|
|
26
|
+
import { helpCommand } from "./commands/help.js";
|
|
27
|
+
import { commandHelp, renderHelpText, usageHelp } from "./helpText.js";
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
/** Later tasks register their commands here. */
|
|
51
|
+
export const commands = {
|
|
52
|
+
doctor: (a, io) => doctorCommand(a, io),
|
|
53
|
+
scan: (a, io) => scanCommand(a, io),
|
|
54
|
+
plan: (a, io) => planCommand(a, io),
|
|
55
|
+
accounts: (a, io) => accountsCommand(a, io),
|
|
56
|
+
apply: (a, io) => applyCommand(a, io),
|
|
57
|
+
quarantine: (a, io) => quarantineCommand(a, io),
|
|
58
|
+
dedupe: (a, io) => dedupeCommand(a, io),
|
|
59
|
+
rollback: (a, io) => rollbackCommand(a, io),
|
|
60
|
+
runs: (a, io) => runsCommand(a, io),
|
|
61
|
+
sync: (a, io) => syncCommand(a, io),
|
|
62
|
+
schedule: (a, io) => scheduleCommand(a, io),
|
|
63
|
+
merge: (a, io) => mergeCommand(a, io),
|
|
64
|
+
recover: (a, io) => recoverCommand(a, io),
|
|
65
|
+
projects: (a, io) => projectsCommand(a, io),
|
|
66
|
+
start: (a, io) => startCommand(a, io, { main }),
|
|
67
|
+
update: (a, io) => updateCommand(a, io),
|
|
68
|
+
changelog: (a, io) => changelogCommand(a, io),
|
|
69
|
+
organize: (a, io) => organizeCommand(a, io),
|
|
70
|
+
status: (a, io) => statusCommand(a, io),
|
|
71
|
+
help: (a, io) => helpCommand(a, io),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** A help text (src/cli/help.en.ts, help.pt.ts) in the Io's language, styled and fitted to its width. */
|
|
75
|
+
function printHelp(io , text ) {
|
|
76
|
+
const ui = cliUi(io);
|
|
77
|
+
io.stdout(renderHelpText(ui, text(ui.lang)).join("\n") + "\n");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function readVersion() {
|
|
81
|
+
const url = new URL("../../package.json", import.meta.url);
|
|
82
|
+
return (JSON.parse(readFileSync(url, "utf8")) ).version;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** An error as the error panel (what happened, what to do, the command that helps), in the Io's language; its exit code. */
|
|
86
|
+
function report(e , io ) {
|
|
87
|
+
const { code } = describeError(e);
|
|
88
|
+
io.stderr(renderError(e, cliUi(io)).join("\n") + "\n");
|
|
89
|
+
return code;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** config.json "language" of the state folder, or null (missing or unreadable config: doctor reports that). */
|
|
93
|
+
async function configLanguage(env ) {
|
|
94
|
+
const home = homedir();
|
|
95
|
+
return loadConfig(stateDir(env, home), home).then((c) => c?.language ?? null, () => null);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The Io a command runs with: its language and capabilities resolved once. `start` gets only the flag (it resolves the
|
|
100
|
+
* language itself, with the config of its own home). --no-color also sets NO_COLOR, so every command and child honours it.
|
|
101
|
+
*/
|
|
102
|
+
async function withUi(io , g , command ) {
|
|
103
|
+
const env = g.noColor ? { ...io.env, NO_COLOR: "1" } : io.env;
|
|
104
|
+
const out = process.stdout;
|
|
105
|
+
const detected = io.caps ?? detectCaps(env, process.platform, {
|
|
106
|
+
isTTY: io.isTTY, columns: io.isTTY ? out.columns : undefined,
|
|
107
|
+
hasColors: io.isTTY && typeof out.hasColors === "function" ? (n) => out.hasColors(n) : undefined,
|
|
108
|
+
});
|
|
109
|
+
const caps = g.noColor ? { ...detected, color: 0 } : detected;
|
|
110
|
+
const flag = g.lang ?? io.langFlag;
|
|
111
|
+
const lang = command === "start" ? (g.lang ?? io.lang) : g.lang ?? io.lang ?? resolveLang(null, env, await configLanguage(env));
|
|
112
|
+
return { ...io, env, caps, ...(lang ? { lang } : {}), ...(flag ? { langFlag: flag } : {}) };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function main(rawArgv , io ) {
|
|
116
|
+
// The global options (--lang, --no-color) are parsed here, once, and taken out of argv.
|
|
117
|
+
const g = parseGlobalFlags(rawArgv);
|
|
118
|
+
if ("error" in g) { io.stderr(g.error); return 2; }
|
|
119
|
+
const argv = g.rest;
|
|
120
|
+
// Plain `t3sm` on a terminal: the guided assistant. Not on a terminal: the usage, as always.
|
|
121
|
+
if (argv.length === 0 && io.isTTY) {
|
|
122
|
+
const uio = await withUi(io, g, "start");
|
|
123
|
+
try { return await commands["start"] ([], uio); } catch (e) { return report(e, uio); }
|
|
124
|
+
}
|
|
125
|
+
const i = argv.findIndex((a) => !a.startsWith("-"));
|
|
126
|
+
const lead = i === -1 ? argv : argv.slice(0, i);
|
|
127
|
+
for (const f of lead) {
|
|
128
|
+
if (f === "-h" || f === "--help" || f === "-v" || f === "--version") continue;
|
|
129
|
+
unknownOption(await withUi(io, g, "help"), f, null);
|
|
130
|
+
return 2;
|
|
131
|
+
}
|
|
132
|
+
if (i === -1) {
|
|
133
|
+
if (lead.includes("-v") || lead.includes("--version")) io.stdout(`${readVersion()}\n`);
|
|
134
|
+
else printHelp(await withUi(io, g, "help"), usageHelp);
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
const name = argv[i] ;
|
|
138
|
+
const wantsHelp = lead.includes("-h") || lead.includes("--help") || argv.slice(i + 1).some((a) => a === "-h" || a === "--help");
|
|
139
|
+
if (wantsHelp && commandHelp(name, "en") !== null) {
|
|
140
|
+
printHelp(await withUi(io, g, "help"), (lang) => commandHelp(name, lang) );
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
const handler = Object.hasOwn(commands, name) ? commands[name] : undefined;
|
|
144
|
+
if (!handler) {
|
|
145
|
+
usageLine(await withUi(io, g, "help"), "common.unknownCommand", { name });
|
|
146
|
+
return 2;
|
|
147
|
+
}
|
|
148
|
+
const uio = await withUi(io, g, name);
|
|
149
|
+
try {
|
|
150
|
+
// Everything after the command name, including flags (but the global ones), goes to the handler.
|
|
151
|
+
return await handler(argv.slice(i + 1), uio);
|
|
152
|
+
} catch (e) {
|
|
153
|
+
return report(e, uio);
|
|
154
|
+
}
|
|
155
|
+
}
|
package/dist/cli/ui.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// What every command prints with: the language, its catalogue, the style (colour and symbols), the locale formatter
|
|
2
|
+
// and the width, from the Io that `main` set up once (`Io.lang`, `Io.caps`: the global --lang and --no-color). Also the
|
|
3
|
+
// one parser of those global flags, and the one yes/no confirmation every writing command asks through.
|
|
4
|
+
//
|
|
5
|
+
// An Io without `lang` (a test, or a caller that bypasses main) is English; without `caps`, the capabilities are
|
|
6
|
+
// detected from its env and isTTY. --json, plan.md, journal.jsonl and logs/sync.log never go through here.
|
|
7
|
+
|
|
8
|
+
import { isLang, resolveLang, } from "../assistant/i18n.js";
|
|
9
|
+
import { detectCaps, } from "../ui/caps.js";
|
|
10
|
+
|
|
11
|
+
import { cliT, makeCliUi, } from "../i18n/cli.js";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// The catalogues live in src/i18n/cli.ts (ops/ and plan/ use them without importing the CLI); re-exported here.
|
|
15
|
+
export { CLI_CATALOGUES, cliT, isCliKey, makeCliUi, } from "../i18n/cli.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The language of an Io for something that depends on it beyond text (the General folder's default name): main's
|
|
19
|
+
* `Io.lang`, else resolved from the Io's env and config.json "language" (a direct call that bypassed main).
|
|
20
|
+
*/
|
|
21
|
+
export function langOf(io , configLang ) {
|
|
22
|
+
return io.lang ?? resolveLang(null, io.env, configLang);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The capabilities of an Io:what main resolved, else detected from its env and isTTY (colour only on a TTY). */
|
|
26
|
+
export function capsOfIo(io , platform = process.platform) {
|
|
27
|
+
return io.caps ?? detectCaps(io.env, platform, { isTTY: io.isTTY });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function cliUi(io , o = {}) {
|
|
31
|
+
return makeCliUi(capsOfIo(io, o.platform), io.lang ?? "en", o.now ?? Date.now);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The Io's stdout as the progress bar's terminal: its width (read again at every frame on a TTY, the window can be
|
|
36
|
+
* resized), its capabilities, and writes to io.stdout. Keys and line input are not part of it (never asked here).
|
|
37
|
+
*/
|
|
38
|
+
export function ioTerm(io , ui ) {
|
|
39
|
+
const caps = ui.s.caps;
|
|
40
|
+
return {
|
|
41
|
+
isTTY: io.isTTY,
|
|
42
|
+
get columns() { return (io.isTTY ? process.stdout.columns : undefined) || caps.columns || 80; },
|
|
43
|
+
rows: 24,
|
|
44
|
+
color: caps.color > 0,
|
|
45
|
+
caps,
|
|
46
|
+
unicode: caps.unicode,
|
|
47
|
+
write: (s) => io.stdout(s),
|
|
48
|
+
onKey: () => () => undefined,
|
|
49
|
+
setRaw: () => undefined,
|
|
50
|
+
readLine: async () => null,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The global options, anywhere on the command line: `--lang en|pt` (or `--lang=pt`) and `--no-color`. They are taken
|
|
58
|
+
* out of argv, so no command has to know them. `--` ends them: it and everything after it go to the command as they
|
|
59
|
+
* are. An invalid --lang is a usage error, worded in English (the language is not known yet).
|
|
60
|
+
*/
|
|
61
|
+
export function parseGlobalFlags(argv ) {
|
|
62
|
+
let lang = null;
|
|
63
|
+
let noColor = false;
|
|
64
|
+
const rest = [];
|
|
65
|
+
for (let i = 0; i < argv.length; i++) {
|
|
66
|
+
const a = argv[i] ;
|
|
67
|
+
if (a === "--") { rest.push(...argv.slice(i)); break; }
|
|
68
|
+
if (a === "--no-color") { noColor = true; continue; }
|
|
69
|
+
if (a === "--lang" || a.startsWith("--lang=")) {
|
|
70
|
+
const v = a === "--lang" ? argv[++i] : a.slice("--lang=".length);
|
|
71
|
+
if (!isLang(v)) return { error: "--lang must be en or pt. Run `t3sm --help`.\n" };
|
|
72
|
+
lang = v;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
rest.push(a);
|
|
76
|
+
}
|
|
77
|
+
return { lang, noColor, rest };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A usage error or a refusal, on stderr in the Io's language (the caller returns exit 2). */
|
|
81
|
+
export function usageLine(io , key , vars = {}) {
|
|
82
|
+
io.stderr(`${cliT(io.lang ?? "en", key, vars)}\n`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** "Unknown option: <a>. Run t3sm <command> --help." in the Io's language. */
|
|
86
|
+
export function unknownOption(io , option , command ) {
|
|
87
|
+
usageLine(io, "common.unknownOption", { option, help: command === null ? "t3sm --help" : `t3sm ${command} --help` });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const YES = new Set(["yes", "y"]);
|
|
91
|
+
const YES_PT = new Set(["sim", "s"]);
|
|
92
|
+
|
|
93
|
+
function isYes(io , answer ) {
|
|
94
|
+
const a = answer.trim().toLowerCase();
|
|
95
|
+
return YES.has(a) || ((io.lang ?? "en") === "pt" && YES_PT.has(a));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The yes/no question of every writing command: "<question> Type yes to continue: " ("Escreve sim para continuar: "
|
|
100
|
+
* in Portuguese). Only yes / y (and in Portuguese sim / s) go ahead; Enter, anything else, Ctrl+C or closed input is no.
|
|
101
|
+
*/
|
|
102
|
+
export async function confirm(io , question ) {
|
|
103
|
+
return isYes(io, await io.prompt(`${question} ${cliT(io.lang ?? "en", "confirm.typeYes")}`));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** confirm, with d (details) as a third answer. */
|
|
107
|
+
export async function confirmOrDetails(io , question ) {
|
|
108
|
+
const a = await io.prompt(`${question} ${cliT(io.lang ?? "en", "confirm.typeYesOrDetails")}`);
|
|
109
|
+
if (a.trim().toLowerCase() === "d") return "details";
|
|
110
|
+
return isYes(io, a) ? "yes" : "no";
|
|
111
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The two time windows every part of t3sm judges transcripts by. One definition each.
|
|
2
|
+
|
|
3
|
+
/** A transcript written within this long is in use: never bumped, imported, converted or rewritten this run. */
|
|
4
|
+
export const ACTIVE_WINDOW_MS = 600_000;
|
|
5
|
+
/** T3's importer window: transcripts modified in the last 30 days are eligible (S2 §3). */
|
|
6
|
+
export const IMPORT_WINDOW_MS = 30 * 86_400_000;
|
|
7
|
+
|
|
8
|
+
/** Written within ACTIVE_WINDOW_MS of `now` (any future time counts as recent). */
|
|
9
|
+
export function isActive(mtimeMs , now ) {
|
|
10
|
+
return now - mtimeMs < ACTIVE_WINDOW_MS;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Inside T3's importer window as seen at `now` (a future time passes this check; T3 itself skips the future). */
|
|
14
|
+
export function inImportWindow(mtimeMs , now ) {
|
|
15
|
+
return now - mtimeMs <= IMPORT_WINDOW_MS;
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// CHANGELOG.md (Keep a Changelog): the `## [X.Y.Z] - YYYY-MM-DD` release sections, for `t3sm changelog` and for what
|
|
2
|
+
// `t3sm update` shows before and after an update. `## [Unreleased]` and anything that is not a release version are left
|
|
3
|
+
// out; a section runs until the next `## ` heading.
|
|
4
|
+
|
|
5
|
+
import { compareSemver, parseSemver } from "./semver.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/** The release sections of a CHANGELOG, in file order. */
|
|
17
|
+
export function changelogSections(text ) {
|
|
18
|
+
const out = [];
|
|
19
|
+
let cur = null;
|
|
20
|
+
const close = () => { if (cur) out.push({ version: cur.version, heading: cur.heading, body: cur.lines.join("\n").trim() }); cur = null; };
|
|
21
|
+
for (const line of text.replace(/\r\n/g, "\n").split("\n")) {
|
|
22
|
+
if (line.startsWith("## ")) {
|
|
23
|
+
close();
|
|
24
|
+
const v = /^## \[([^\]]+)\]/.exec(line)?.[1];
|
|
25
|
+
const p = v === undefined ? null : parseSemver(v);
|
|
26
|
+
if (p !== null) cur = { version: p.join("."), heading: line.trimEnd(), lines: [] };
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
// Link references (`[0.3.0]: https://...`, usually after the last section) belong to no section.
|
|
30
|
+
if (/^\[[^\]]+\]:\s/.test(line)) continue;
|
|
31
|
+
cur?.lines.push(line);
|
|
32
|
+
}
|
|
33
|
+
close();
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The sections of the versions newer than `after` and at most `upTo` (inclusive), newest first. */
|
|
38
|
+
export function sectionsBetween(text , after , upTo ) {
|
|
39
|
+
return changelogSections(text)
|
|
40
|
+
.filter((s) => compareSemver(s.version, after) > 0 && compareSemver(s.version, upTo) <= 0)
|
|
41
|
+
.sort((a, b) => compareSemver(b.version, a.version));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The sections as printed: heading, blank line, body, blank line between sections. */
|
|
45
|
+
export function renderSections(sections ) {
|
|
46
|
+
return sections.map((s) => `${s.heading}\n\n${s.body}\n`).join("\n");
|
|
47
|
+
}
|