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,615 @@
|
|
|
1
|
+
// `t3sm status`: the one place that says whether t3sm needs you. Strictly read-only: no lock, no journal write, no
|
|
2
|
+
// discovery cache, no T3 Code (it never connects, and never probes the network; "T3 Code is not running" comes from
|
|
3
|
+
// T3's own runtime file and its pid). Reads <state>/sync-status.json (the watcher's heartbeat and what each sync cycle
|
|
4
|
+
// recorded), logs/sync.log, the journal, the newest plan, update.json / update.pending.json, the lock file and the
|
|
5
|
+
// install's package.json / build stamp.
|
|
6
|
+
//
|
|
7
|
+
// It leads with one level: "ok" (all good), "needs-you" (with the count) or "working" (a run holds the lock), then the
|
|
8
|
+
// items, every needs-you item before every info item, each with the command that settles it (spec §5.5). Info items
|
|
9
|
+
// never raise the level. Exit 0, or 10 when the level is "needs-you"; a usage error is 2.
|
|
10
|
+
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { readFile, stat } from "node:fs/promises";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { DEFAULT_SCHEDULE_MINUTES, loadConfig } from "../../core/config.js";
|
|
15
|
+
import { expandHome, stateDir } from "../../core/paths.js";
|
|
16
|
+
import { describePlugin, packageVersion as ownVersion, readPluginState, } from "../../ops/plugin.js";
|
|
17
|
+
|
|
18
|
+
import { cliT, cliUi, } from "../ui.js";
|
|
19
|
+
import { fitLine, leadLines } from "../screen.js";
|
|
20
|
+
import { DECISION_WORDS } from "../words.js";
|
|
21
|
+
import { callout, kv } from "../../ui/components.js";
|
|
22
|
+
import { wrapText } from "../../ui/text.js";
|
|
23
|
+
import { Journal, organizeFailures } from "../../core/journal.js";
|
|
24
|
+
import { lockInfo } from "../../core/lock.js";
|
|
25
|
+
import { compareSemver, parseSemver } from "../../core/semver.js";
|
|
26
|
+
import { installChangedAt, installRoot, installStamp, } from "../../core/version.js";
|
|
27
|
+
|
|
28
|
+
import { REPEATED_FAILURES, readSyncStatus, readUpdateFailure, recordsUndecided, updateFailureText, } from "../../ops/syncStatus.js";
|
|
29
|
+
import { pidAlive, readHeartbeat } from "../../ops/watch.js";
|
|
30
|
+
import { watcherHealth, } from "../../ops/watcherHealth.js";
|
|
31
|
+
import { classify, readPendingUpdate, readUpdateState } from "../../ops/updater.js";
|
|
32
|
+
import { listRuns } from "../../ops/rollback.js";
|
|
33
|
+
import { readServerRuntime, } from "../../t3/runtime.js";
|
|
34
|
+
import { shownAccountName, shownText } from "../../plan/names.js";
|
|
35
|
+
import { parseFlags } from "./quarantine.js";
|
|
36
|
+
import { latestPlan, readPlan } from "./apply.js";
|
|
37
|
+
import { attentionText } from "../../ops/notify.js";
|
|
38
|
+
import { FLAG_SPECS } from "../flags.js";
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
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
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
/** The exit code when something needs the user (so scripts and notifications can tell "needs you" from an error). */
|
|
95
|
+
export const NEEDS_YOU_EXIT = 10;
|
|
96
|
+
|
|
97
|
+
const MIN = 60_000;
|
|
98
|
+
const DAY = 24 * 60 * MIN;
|
|
99
|
+
/** An install this recent is mentioned (info) with the way to read what changed. */
|
|
100
|
+
const RECENT_INSTALL_MS = 7 * DAY;
|
|
101
|
+
/** Titles named in one item at most. */
|
|
102
|
+
const NAMES_SHOWN = 3;
|
|
103
|
+
/** Caps for an item's text and command (shownText cuts the middle). */
|
|
104
|
+
const ITEM_TEXT_MAX = 400;
|
|
105
|
+
const ITEM_COMMAND_MAX = 120;
|
|
106
|
+
|
|
107
|
+
/** "just now", "5 min ago", "2 hours ago", "3 days ago"; a future time reads "in 7 min" (Portuguese: "há 5 min", "daqui a 7 min"). */
|
|
108
|
+
export function relative(ms , lang = "en") {
|
|
109
|
+
const future = ms < 0;
|
|
110
|
+
const m = Math.floor(Math.abs(ms) / MIN);
|
|
111
|
+
if (m < 1) return cliT(lang, future ? "status.rel.inUnderMinute" : "status.rel.justNow");
|
|
112
|
+
const t = m < 60 ? cliT(lang, "status.rel.minutes", { n: m })
|
|
113
|
+
: m < 24 * 60 ? cliT(lang, "status.rel.hours", { n: Math.floor(m / 60) })
|
|
114
|
+
: cliT(lang, "status.rel.days", { n: Math.floor(m / (24 * 60)) });
|
|
115
|
+
return cliT(lang, future ? "status.rel.in" : "status.rel.ago", { time: t });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** "today", "yesterday", "3 days ago" (whole days elapsed). */
|
|
119
|
+
export function relativeDay(ms , lang = "en") {
|
|
120
|
+
const d = Math.floor(Math.max(0, ms) / DAY);
|
|
121
|
+
return cliT(lang, d === 0 ? "status.day.today" : d === 1 ? "status.day.yesterday" : "status.day.daysAgo", { n: d });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The words of one language an item is told in: the catalogue, relative times and a short list of names. */
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
function words(lang ) {
|
|
128
|
+
return {
|
|
129
|
+
lang,
|
|
130
|
+
t: (key, vars = {}) => cliT(lang, key, vars),
|
|
131
|
+
ago: (ms) => relative(ms, lang),
|
|
132
|
+
day: (ms) => relativeDay(ms, lang),
|
|
133
|
+
list: (names) => {
|
|
134
|
+
const shown = names.slice(0, NAMES_SHOWN).join(", ");
|
|
135
|
+
return names.length > NAMES_SHOWN ? cliT(lang, "status.andMore", { names: shown, n: names.length - NAMES_SHOWN }) : shown;
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const EN_WORDS = words("en");
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
/** An item's text as a function of the language: English is the --json `text`, the screen tells it in the user's language. */
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
/** Each item's `say`, beside the item rather than on it: --json carries only the English `text`. */
|
|
147
|
+
const SAYS = new WeakMap ();
|
|
148
|
+
function withSay (i , say ) {
|
|
149
|
+
if (say) SAYS.set(i, say);
|
|
150
|
+
return i;
|
|
151
|
+
}
|
|
152
|
+
const sayOf = (i ) => SAYS.get(i);
|
|
153
|
+
|
|
154
|
+
function item(level , key , say , command , text = say(EN_WORDS)) {
|
|
155
|
+
return withSay({ level, key, text, command }, say);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The "conversations wait for your decision" item. --json keeps the question keys ("automated 2", byte-identical); the
|
|
160
|
+
* screen names each question in words ("automated sessions 2").
|
|
161
|
+
*/
|
|
162
|
+
export function undecidedItem(decisionsPending ) {
|
|
163
|
+
const questions = Object.entries(decisionsPending);
|
|
164
|
+
const n = questions.reduce((a, [, x]) => a + x, 0);
|
|
165
|
+
const parts = questions.map(([k, x]) => `${shownText(k, 40)} ${x}`).join(", ");
|
|
166
|
+
const said = (w ) => questions.map(([k, x]) => `${DECISION_WORDS[k] ? w.t(DECISION_WORDS[k]) : shownText(k, 40)} ${x}`).join(", ");
|
|
167
|
+
return item("needs-you", "undecided", (w) => w.t("status.undecided", { n, parts: said(w) }), "t3sm start", EN_WORDS.t("status.undecided", { n, parts }));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** An item told by one catalogue entry (the screen registry and tests build reports with it). */
|
|
171
|
+
export function sayingItem(level , key , msg , vars , command ) {
|
|
172
|
+
return item(level, key, (w) => w.t(msg, vars), command);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const time = (s ) => (typeof s === "string" && Number.isFinite(Date.parse(s)) ? Date.parse(s) : null);
|
|
176
|
+
const str = (v ) => (typeof v === "string" ? v : null);
|
|
177
|
+
|
|
178
|
+
/** When a run id (newRunId: `YYYYMMDD-HHMMSS-xxxx`, UTC) was made; null for any other id. */
|
|
179
|
+
export function runIdTime(runId ) {
|
|
180
|
+
const m = /^(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})/.exec(runId);
|
|
181
|
+
if (!m) return null;
|
|
182
|
+
const t = Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3]), Number(m[4]), Number(m[5]), Number(m[6]));
|
|
183
|
+
return Number.isFinite(t) ? t : null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The home folder shown as ~ (an import failure's reason may name a file). */
|
|
187
|
+
function maskHome(s , home ) {
|
|
188
|
+
const h = home.replace(/[\\/]+$/, "");
|
|
189
|
+
if (h === "") return s;
|
|
190
|
+
const variants = [...new Set([h, h.replace(/\\/g, "/"), h.replace(/\//g, "\\")])].map((v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
191
|
+
return s.replace(new RegExp(`(?:${variants.join("|")})(?=[\\\\/]|\\b|$)`, "gi"), "~");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
async function lastLogLine(dir ) {
|
|
197
|
+
let text ;
|
|
198
|
+
try { text = await readFile(join(dir, "logs", "sync.log"), "utf8"); } catch { return null; }
|
|
199
|
+
const line = text.split("\n").map((l) => l.trim()).filter((l) => l !== "").pop();
|
|
200
|
+
const m = line ? /^(\S+) (\S+)(.*)$/.exec(line) : null;
|
|
201
|
+
if (!m || time(m[1]) === null) return null;
|
|
202
|
+
const run = /\brun=(\S+)/.exec(m[3] )?.[1];
|
|
203
|
+
const pending = /\bpending=(\d+)/.exec(m[3] )?.[1];
|
|
204
|
+
return { at: m[1] , outcome: m[2] , runId: run && run !== "-" ? run : null, pending: pending ? Number(pending) : null, rest: m[3] .trim() };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** What sync.log records when a watcher stops at start-up, before its first heartbeat (src/cli/commands/sync.ts). */
|
|
208
|
+
const START_FAILURES = new Set(["startup-error", "socket-dir-unsafe"]);
|
|
209
|
+
|
|
210
|
+
async function newestPlan(dir ) {
|
|
211
|
+
try {
|
|
212
|
+
const p = await latestPlan(dir);
|
|
213
|
+
return p === null ? null : await readPlan(p);
|
|
214
|
+
} catch { return null; }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const sessionKey = (harness , nativeId ) => `${harness}:${nativeId}`;
|
|
218
|
+
|
|
219
|
+
/** Plan skip reasons that are failures themselves: such a session still counts as failing to import. */
|
|
220
|
+
const FAILURE_SKIPS = new Set(["compare-failed"]);
|
|
221
|
+
|
|
222
|
+
/** Sessions whose import failed in two or more runs since they were last imported, grouped by reason. */
|
|
223
|
+
function repeatedFailures(entries ) {
|
|
224
|
+
const failing = new Map ();
|
|
225
|
+
for (const e of entries) {
|
|
226
|
+
if (e.t === "imported") failing.delete(sessionKey(e.harness, e.nativeId));
|
|
227
|
+
else if (e.t === "import-failed") {
|
|
228
|
+
const k = sessionKey(e.harness, e.nativeId);
|
|
229
|
+
const f = failing.get(k) ?? { harness: e.harness, nativeId: e.nativeId, reason: e.reason, runs: new Set () };
|
|
230
|
+
f.reason = e.reason;
|
|
231
|
+
f.runs.add(e.runId);
|
|
232
|
+
failing.set(k, f);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const byReason = new Map ();
|
|
236
|
+
for (const f of failing.values()) {
|
|
237
|
+
if (f.runs.size < 2) continue;
|
|
238
|
+
const list = byReason.get(f.reason) ?? [];
|
|
239
|
+
list.push({ harness: f.harness, nativeId: f.nativeId });
|
|
240
|
+
byReason.set(f.reason, list);
|
|
241
|
+
}
|
|
242
|
+
return byReason;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function watcherItems(h , t3Running , now ) {
|
|
246
|
+
const restart = "t3sm schedule restart";
|
|
247
|
+
switch (h.state) {
|
|
248
|
+
case "none": return [];
|
|
249
|
+
case "stopped": {
|
|
250
|
+
const ago = now - (time(h.stoppedAt) ?? now);
|
|
251
|
+
return [item("info", "watcher-stopped", (w) => w.t("status.watcher.stopped", { ago: w.ago(ago) }), null)];
|
|
252
|
+
}
|
|
253
|
+
case "restart-lost": {
|
|
254
|
+
const ago = now - (time(h.stoppedAt) ?? now);
|
|
255
|
+
return [item("needs-you", "watcher-not-running", (w) => w.t("status.watcher.restartLost", { ago: w.ago(ago) }), restart)];
|
|
256
|
+
}
|
|
257
|
+
case "gone": {
|
|
258
|
+
const last = h.lastCycleAt === null ? null : now - (time(h.lastCycleAt) ?? now);
|
|
259
|
+
return [item("needs-you", "watcher-not-running", (w) => w.t("status.watcher.gone", { pid: h.pid, last: last === null ? w.t("status.never") : w.ago(last) }), restart)];
|
|
260
|
+
}
|
|
261
|
+
case "no-version":
|
|
262
|
+
return [item("needs-you", "watcher-stale-version", (w) => w.t("status.watcher.noVersion", { pid: h.pid }), restart)];
|
|
263
|
+
case "no-stamp":
|
|
264
|
+
return [item("needs-you", "watcher-stale-version", (w) => w.t("status.watcher.noStamp", { pid: h.pid, version: h.version }), restart)];
|
|
265
|
+
case "stale-version":
|
|
266
|
+
return [item("needs-you", "watcher-stale-version", (w) => w.t(h.rebuilt ? "status.watcher.staleRebuilt" : "status.watcher.staleVersion", { pid: h.pid, version: h.version, installed: h.installed }), restart)];
|
|
267
|
+
case "running": {
|
|
268
|
+
const out = [];
|
|
269
|
+
if (!h.fresh && t3Running) {
|
|
270
|
+
const last = h.lastCycleAt === null ? null : now - (time(h.lastCycleAt) ?? now);
|
|
271
|
+
out.push(item("needs-you", "watcher-late", (w) => (last === null ? w.t("status.watcher.lateNoCycle", { pid: h.pid }) : w.t("status.watcher.late", { pid: h.pid, ago: w.ago(last) })), restart));
|
|
272
|
+
}
|
|
273
|
+
const pending = h.pendingVersion;
|
|
274
|
+
if (pending !== null) out.push(item("info", "watcher-switching", (w) => w.t("status.watcher.switching", { version: pending }), null));
|
|
275
|
+
return out;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export async function collectStatus(dir , home , d ) {
|
|
281
|
+
const now = d.now();
|
|
282
|
+
let plugin = [];
|
|
283
|
+
try {
|
|
284
|
+
plugin = await Promise.all((await d.accounts()).map(async (a) => {
|
|
285
|
+
const s = await d.pluginState(a.home);
|
|
286
|
+
return { account: shownText(a.id, 40), ...(a.name ? { name: shownAccountName(a.name) } : {}), state: s.state, version: s.state === "missing" ? null : s.version };
|
|
287
|
+
}));
|
|
288
|
+
} catch { plugin = []; }
|
|
289
|
+
const fields = await readSyncStatus(dir);
|
|
290
|
+
const hb = await readHeartbeat(dir);
|
|
291
|
+
const alive = hb !== null && !hb.stoppedAt && d.pidAlive(hb.pid);
|
|
292
|
+
const result = hb && hb.lastResult && typeof hb.lastResult === "object" ? hb.lastResult : null;
|
|
293
|
+
// A config.json that cannot be used is a need of its own: every sync (and the watcher, at start-up) stops on it.
|
|
294
|
+
let config = null;
|
|
295
|
+
let configError = null;
|
|
296
|
+
try { config = await loadConfig(dir, home); } catch (e) { configError = (e instanceof Error ? e.message : String(e)).split(/\r?\n/)[0] ; }
|
|
297
|
+
const entries = await new Journal(join(dir, "journal.jsonl")).readAll().catch(() => [] );
|
|
298
|
+
const plan = await newestPlan(dir);
|
|
299
|
+
|
|
300
|
+
const fromHb = hb && time(hb.lastCycleAt) !== null
|
|
301
|
+
? { at: hb.lastCycleAt , outcome: str(result?.["outcome"]) ?? "unknown", runId: str(result?.["runId"]), pending: result?.["outcome"] === "over-limit" && typeof result["pending"] === "number" ? result["pending"] : null }
|
|
302
|
+
: null;
|
|
303
|
+
const fromLog = await lastLogLine(dir);
|
|
304
|
+
const seen = fromHb && fromLog ? (time(fromLog.at) > time(fromHb.at) ? fromLog : fromHb) : fromHb ?? fromLog;
|
|
305
|
+
|
|
306
|
+
// Only the per-cycle field: each cycle that looked replaces it, so a stopped watcher's old result is never shown.
|
|
307
|
+
const waiting = fields.held.map((h) => ({ project: shownText(h.project, 120), title: h.title === null ? null : shownText(h.title, 120), modifiedAt: h.modifiedAt, since: h.since ?? h.modifiedAt }));
|
|
308
|
+
|
|
309
|
+
let pendingImports = null;
|
|
310
|
+
if (seen && seen.pending !== null) pendingImports = { count: seen.pending, source: "sync", at: seen.at };
|
|
311
|
+
else if (plan) pendingImports = { count: plan.items.filter((i) => i.action.kind !== "skip").length, source: "plan", at: plan.createdAt };
|
|
312
|
+
|
|
313
|
+
// Undecided: whichever looked last, the last cycle or the newest plan; the plan whenever no cycle can have recorded
|
|
314
|
+
// them (a 0.2.1 watcher, without a version, never writes `undecided`; nor does a file no cycle wrote it into).
|
|
315
|
+
const planAt = plan ? time(plan.createdAt) : null;
|
|
316
|
+
const cycleAt = seen ? time(seen.at) : null;
|
|
317
|
+
const cycleRecords = (await recordsUndecided(dir)) && !(hb !== null && (typeof hb.version !== "string" || parseSemver(hb.version) === null));
|
|
318
|
+
const fromPlan = plan !== null && (!cycleRecords || (planAt !== null && (cycleAt === null || planAt > cycleAt)));
|
|
319
|
+
const decisionsPending = fromPlan
|
|
320
|
+
? Object.fromEntries((plan .decisionsPending ?? []).filter((q) => q.sessions > 0).map((q) => [q.key, q.sessions]))
|
|
321
|
+
: fields.undecided;
|
|
322
|
+
|
|
323
|
+
const runs = listRuns(entries);
|
|
324
|
+
const orgRuns = runs.filter((r) => r.command === "organize");
|
|
325
|
+
const org = orgRuns[orgRuns.length - 1];
|
|
326
|
+
const lastOrganize = org ? { runId: org.runId, at: org.at, changes: org.counts.organized, reverted: org.counts.organizeReverted, rolledBackBy: org.rolledBackBy } : null;
|
|
327
|
+
|
|
328
|
+
const rt = await d.readRuntime(home).catch(() => null);
|
|
329
|
+
const t3Running = rt !== null && d.pidAlive(rt.pid);
|
|
330
|
+
const next = alive ? time(hb?.nextCycleAt) : null;
|
|
331
|
+
|
|
332
|
+
const health = watcherHealth(hb, { now, pidAlive: d.pidAlive, install: d.installStamp, everyMinutes: config?.schedule.everyMinutes ?? DEFAULT_SCHEDULE_MINUTES });
|
|
333
|
+
const stale = health.state === "no-version" || health.state === "no-stamp" || health.state === "stale-version" || (health.state === "running" && !health.fresh && t3Running);
|
|
334
|
+
|
|
335
|
+
const lock = await lockInfo(dir).catch(() => null);
|
|
336
|
+
const runInProgress = lock && d.pidAlive(lock.pid) ? { pid: lock.pid, startedAt: lock.startedAt } : null;
|
|
337
|
+
|
|
338
|
+
// ---------- updates ----------
|
|
339
|
+
const installed = d.packageVersion;
|
|
340
|
+
// Unknown versions (not release versions) cannot be compared: the record is still shown.
|
|
341
|
+
const notReached = (to ) => parseSemver(installed) === null || parseSemver(to) === null || compareSemver(installed, to) < 0;
|
|
342
|
+
const recorded = await readUpdateFailure(dir);
|
|
343
|
+
const failure = recorded && notReached(recorded.to) ? recorded : null;
|
|
344
|
+
const updateState = await readUpdateState(dir);
|
|
345
|
+
const available = updateState?.available && parseSemver(updateState.available) !== null && notReached(updateState.available) ? updateState.available : null;
|
|
346
|
+
const lastUpdate = [...entries].reverse().find((e) => e.t === "update" && e.outcome === "installed"
|
|
347
|
+
&& typeof e.from === "string" && typeof e.to === "string" && parseSemver(e.from) !== null && parseSemver(e.to) !== null);
|
|
348
|
+
const installedAt = lastUpdate ? runIdTime(lastUpdate.runId) : null;
|
|
349
|
+
const lastInstalled = lastUpdate ? { from: lastUpdate.from, to: lastUpdate.to, at: installedAt === null ? null : new Date(installedAt).toISOString() } : null;
|
|
350
|
+
const pending = await readPendingUpdate(dir);
|
|
351
|
+
|
|
352
|
+
// ---------- items, in the order of spec §5.5 ----------
|
|
353
|
+
const items = [];
|
|
354
|
+
const na = fields.needsAttention;
|
|
355
|
+
items.push(...watcherItems(health, t3Running, now));
|
|
356
|
+
// A watcher that stopped at start-up never wrote a heartbeat: the clean stop before it (or nothing) would read as
|
|
357
|
+
// "All good". sync.log's last line says it, when it is newer than anything the heartbeat records.
|
|
358
|
+
const hbLatest = hb === null ? null : Math.max(...[hb.startedAt, hb.lastCycleAt, hb.stoppedAt].map((x) => time(x) ?? -Infinity));
|
|
359
|
+
if (fromLog && START_FAILURES.has(fromLog.outcome) && !alive && (hbLatest === null || time(fromLog.at) > hbLatest)
|
|
360
|
+
&& !(configError !== null && /\bConfigError\b/.test(fromLog.rest ?? ""))) {
|
|
361
|
+
const ago = now - time(fromLog.at) ;
|
|
362
|
+
const name = shownText(/\b(\w*Error)\b/.exec(fromLog.rest ?? "")?.[1] ?? "Error", 40);
|
|
363
|
+
items.push(fromLog.outcome === "socket-dir-unsafe"
|
|
364
|
+
? item("needs-you", "watcher-cannot-start", (w) => w.t("status.watcher.socketUnsafe", { ago: w.ago(ago) }), "t3sm doctor")
|
|
365
|
+
: item("needs-you", "watcher-cannot-start", (w) => w.t("status.watcher.cannotStart", { ago: w.ago(ago), name }), "t3sm doctor"));
|
|
366
|
+
}
|
|
367
|
+
if (configError !== null) {
|
|
368
|
+
const error = shownText(maskHome(configError, home), 200);
|
|
369
|
+
items.push(item("needs-you", "config-error", (w) => w.t("status.configError", { error }), "t3sm doctor"));
|
|
370
|
+
}
|
|
371
|
+
if (fields.failures >= REPEATED_FAILURES || na?.reason === "repeated-failures") {
|
|
372
|
+
const n = fields.failures;
|
|
373
|
+
items.push(item("needs-you", "sync-failing", (w) => (n >= REPEATED_FAILURES ? w.t("status.syncFailing.count", { n }) : w.t("status.syncFailing.repeated")), "t3sm doctor"));
|
|
374
|
+
}
|
|
375
|
+
// What only a cycle can see (T3 Code's answers): shown as sync recorded it, with its own command.
|
|
376
|
+
if (na && (na.reason === "t3-incompatible" || na.reason === "signed-out")) {
|
|
377
|
+
items.push(item("needs-you", `attention:${na.reason}`, (w) => shownText(attentionText(na, w.lang), 300), shownText(na.command, 200), shownText(na.detail, 300)));
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (failure && failure.outcome === "rolled-back") {
|
|
381
|
+
// Rolled back: the previous version was reinstalled and is running, so t3sm recovered by itself. Worth knowing
|
|
382
|
+
// (which version runs, and that the automatic check skips the bad one), never a need. The notification was sent
|
|
383
|
+
// once by the update itself.
|
|
384
|
+
const running = parseSemver(installed) !== null ? installed : failure.from;
|
|
385
|
+
items.push(item("info", "update-rolled-back", (w) => w.t("status.update.rolledBackInfo", { to: failure.to, installed: running }), "t3sm update --check"));
|
|
386
|
+
}
|
|
387
|
+
else if (failure) {
|
|
388
|
+
const key = failure.outcome === "interrupted" ? "status.update.interrupted" : "status.update.failed";
|
|
389
|
+
items.push(item("needs-you", "update-failed", (w) => w.t(key, { from: failure.from, to: failure.to }), "t3sm update --check", updateFailureText(failure)));
|
|
390
|
+
}
|
|
391
|
+
// A run holding the lock hides the attempt only when it may be that update itself: the update takes the lock before it
|
|
392
|
+
// writes the attempt, so a lock taken after the attempt started belongs to another run (the attempt's own died).
|
|
393
|
+
else if (pending && !pending.interrupted && notReached(pending.target)
|
|
394
|
+
&& (runInProgress === null || (time(runInProgress.startedAt) ?? -Infinity) > (time(pending.startedAt) ?? Infinity))
|
|
395
|
+
&& !entries.some((e) => e.t === "update" && e.runId === pending.runId && e.outcome !== "pending")) {
|
|
396
|
+
// An attempt on disk that nobody is running and that never recorded an outcome: it was interrupted.
|
|
397
|
+
const v = { from: pending.previous.version, to: pending.target };
|
|
398
|
+
items.push(item("needs-you", "update-interrupted", (w) => w.t("status.update.interrupted", v), "t3sm update --check"));
|
|
399
|
+
}
|
|
400
|
+
if (available) {
|
|
401
|
+
// Announced only (spec §5.3: a major release is never installed by itself, and it never needs you).
|
|
402
|
+
const major = classify(installed, available) === "major";
|
|
403
|
+
items.push(major
|
|
404
|
+
? item("info", "update-major", (w) => w.t("status.update.major", { version: available }), "t3sm update")
|
|
405
|
+
: item("info", "update-available", (w) => w.t("status.update.available", { version: available }), "t3sm update"));
|
|
406
|
+
}
|
|
407
|
+
if (lastUpdate && installedAt !== null && now - installedAt <= RECENT_INSTALL_MS && lastUpdate.to === installed) {
|
|
408
|
+
const to = lastUpdate.to;
|
|
409
|
+
const since = now - installedAt;
|
|
410
|
+
items.push(item("info", "update-installed", (w) => w.t("status.update.installed", { version: to, day: w.day(since) }), "t3sm changelog"));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const questions = Object.entries(decisionsPending);
|
|
414
|
+
const undecided = questions.reduce((a, [, n]) => a + n, 0);
|
|
415
|
+
if (undecided > 0) {
|
|
416
|
+
items.push(undecidedItem(decisionsPending));
|
|
417
|
+
}
|
|
418
|
+
if (na?.reason === "over-limit") items.push(item("needs-you", "attention:over-limit", (w) => shownText(attentionText(na, w.lang), 300), shownText(na.command, 200), shownText(na.detail, 300)));
|
|
419
|
+
|
|
420
|
+
// Sessions are named by their project folder (the plan knows it; a folder name, never its path) and a short id.
|
|
421
|
+
const folders = new Map ();
|
|
422
|
+
for (const i of plan?.items ?? []) {
|
|
423
|
+
const s = i.session ;
|
|
424
|
+
const folder = typeof s?.cwd === "string" ? s.cwd.split(/[\\/]+/).filter((x) => x !== "").pop() : undefined;
|
|
425
|
+
if (s && typeof s.harness === "string" && typeof s.nativeId === "string" && folder) folders.set(sessionKey(s.harness, s.nativeId), folder);
|
|
426
|
+
}
|
|
427
|
+
const nameOf = (harness , nativeId ) => {
|
|
428
|
+
const id = `${shownText(harness, 20)} ${shownText(nativeId.slice(0, 8), 8)}`;
|
|
429
|
+
const f = folders.get(sessionKey(harness, nativeId));
|
|
430
|
+
return f !== undefined ? `${shownText(f, 60)} (${id})` : id;
|
|
431
|
+
};
|
|
432
|
+
// The plan's items with a readable session (plan.json is read as written, item by item it may hold anything).
|
|
433
|
+
const planItems = (plan?.items ?? []).filter((i) => i && typeof i === "object" && i.session && typeof i.session.harness === "string"
|
|
434
|
+
&& typeof i.session.nativeId === "string" && i.action && typeof i.action === "object");
|
|
435
|
+
// Only sessions the newest plan still tries to import (one deleted since, or no plan at all, is nothing to act on). A
|
|
436
|
+
// session it skips for a reason other than a failure (started in T3 Code, already in T3 Code, in use, ...) is not
|
|
437
|
+
// failing now, whatever earlier runs journaled: the plan's own item says why it stays out.
|
|
438
|
+
const inPlan = new Set(planItems
|
|
439
|
+
.filter((i) => i.action.kind !== "skip" || FAILURE_SKIPS.has(i.action.reason))
|
|
440
|
+
.map((i) => sessionKey(i.session.harness, i.session.nativeId)));
|
|
441
|
+
for (const [reason, all] of repeatedFailures(entries)) {
|
|
442
|
+
const sessions = all.filter((x) => inPlan.has(sessionKey(x.harness, x.nativeId)));
|
|
443
|
+
if (sessions.length === 0) continue;
|
|
444
|
+
const why = shownText(maskHome(reason, home), 120);
|
|
445
|
+
const names = sessions.map((s) => nameOf(s.harness, s.nativeId));
|
|
446
|
+
items.push(item("needs-you", `import-failing:${why}`, (w) => w.t("status.importFailing", { n: sessions.length, why, names: w.list(names) }), "t3sm doctor"));
|
|
447
|
+
}
|
|
448
|
+
const skipped = (reason ) => planItems
|
|
449
|
+
.filter((i) => i.action.kind === "skip" && i.action.reason === reason)
|
|
450
|
+
.map((i) => nameOf(i.session.harness, i.session.nativeId));
|
|
451
|
+
const orphaned = skipped("orphaned-in-t3");
|
|
452
|
+
if (orphaned.length > 0) {
|
|
453
|
+
items.push(item("info", "orphaned-in-t3", (w) => w.t("status.orphaned", { n: orphaned.length, names: w.list(orphaned) }), null));
|
|
454
|
+
}
|
|
455
|
+
const unknown = skipped("t3-native-unknown");
|
|
456
|
+
if (unknown.length > 0) {
|
|
457
|
+
items.push(item("info", "t3-native-unknown", (w) => w.t("status.nativeUnknown", { n: unknown.length, names: w.list(unknown) }), null));
|
|
458
|
+
}
|
|
459
|
+
for (const c of fields.followConflicts ?? []) {
|
|
460
|
+
// No resolve command yet (ruling): name both conversations and how to choose by hand.
|
|
461
|
+
const v = { original: shownText(c.originalTitle, 80), copy: shownText(c.copyTitle, 80) };
|
|
462
|
+
items.push(item("needs-you", `follow-conflict:${shownText(c.copyId, 80)}`, (w) => w.t("status.followConflict", v), null));
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
for (const w of waiting) {
|
|
466
|
+
const title = w.title === null ? null : shownText(w.title, 80);
|
|
467
|
+
const project = w.project;
|
|
468
|
+
const since = now - (time(w.since) ?? now);
|
|
469
|
+
items.push(item("info", `held:${project}`, (x) => (title === null ? x.t("status.heldUntitled", { project, ago: x.ago(since) }) : x.t("status.held", { project, title, ago: x.ago(since) })), null));
|
|
470
|
+
}
|
|
471
|
+
if (fields.heldRehome > 0) {
|
|
472
|
+
const n = fields.heldRehome;
|
|
473
|
+
items.push(item("needs-you", "held-rehome", (w) => w.t("status.heldRehome", { n }), "t3sm start"));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// Organize failures of the last organize run: the newest `organize` run (even one with nothing to change), or a newer
|
|
477
|
+
// run of any command that journaled organize entries (sync, journaled as `sync <runId>`, organizes what it imported
|
|
478
|
+
// and carries follow settles; `projects rename` writes project titles). Only that run's failures count.
|
|
479
|
+
const organizedIn = new Set(entries.filter((e) => e.t === "organize-change" || e.t === "organize-failed").map((e) => e.runId));
|
|
480
|
+
const lastOrg = [...runs].reverse().find((r) => r.command === "organize" || organizedIn.has(r.runId));
|
|
481
|
+
const orgFailed = lastOrg && lastOrg.rolledBackBy === null ? organizeFailures(entries, lastOrg.runId) : [];
|
|
482
|
+
if (lastOrg && orgFailed.length > 0) {
|
|
483
|
+
const kinds = new Map ();
|
|
484
|
+
for (const f of orgFailed) kinds.set(f.kind, (kinds.get(f.kind) ?? 0) + 1);
|
|
485
|
+
const byKind = [...kinds].map(([k, n]) => `${n} ${k}`).join(", ");
|
|
486
|
+
const v = { n: orgFailed.length, runId: shownText(lastOrg.runId, 60), kinds: byKind, error: shownText(maskHome(orgFailed[0] .error, home), 120) };
|
|
487
|
+
items.push(item("needs-you", "organize-failed", (w) => w.t("status.organizeFailed", v), "t3sm organize"));
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// Every text and command once more through shownText (no control, bidi or format characters; one line; capped).
|
|
491
|
+
const clean = (i ) => withSay({ level: i.level, key: shownText(i.key, 120), text: shownText(i.text, ITEM_TEXT_MAX), command: i.command === null ? null : shownText(i.command, ITEM_COMMAND_MAX) }, sayOf(i));
|
|
492
|
+
const ordered = [...items.filter((i) => i.level === "needs-you"), ...items.filter((i) => i.level === "info")].map(clean);
|
|
493
|
+
const level = ordered.some((i) => i.level === "needs-you") ? "needs-you" : runInProgress ? "working" : "ok";
|
|
494
|
+
|
|
495
|
+
return {
|
|
496
|
+
version: 2,
|
|
497
|
+
ran: true,
|
|
498
|
+
level,
|
|
499
|
+
items: ordered,
|
|
500
|
+
needsAttention: na && { ...na, detail: shownText(na.detail, 300), command: shownText(na.command, 200) },
|
|
501
|
+
waiting,
|
|
502
|
+
heldRehome: fields.heldRehome,
|
|
503
|
+
decisionsPending,
|
|
504
|
+
pendingImports,
|
|
505
|
+
lastSync: seen ? { at: seen.at, outcome: seen.outcome, runId: seen.runId } : null,
|
|
506
|
+
nextSync: next !== null ? { at: new Date(next).toISOString(), source: "watcher" } : null,
|
|
507
|
+
watcher: hb ? { running: alive, pid: hb.pid, version: typeof hb.version === "string" && parseSemver(hb.version) !== null ? hb.version : null, stale } : null,
|
|
508
|
+
update: { installed, available, failure, lastInstalled },
|
|
509
|
+
runInProgress,
|
|
510
|
+
lastOrganize,
|
|
511
|
+
plugin,
|
|
512
|
+
t3Code: { running: t3Running, version: t3Running ? rt .serverVersion : null },
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* The screen: one lead line (all good, needs you with the count, or working), the needs-you items as callouts with
|
|
518
|
+
* their command, then the info items, then the details as aligned label-value rows; in `ui`'s language and width.
|
|
519
|
+
*/
|
|
520
|
+
export function renderStatus(r , o ) {
|
|
521
|
+
const { ui } = o;
|
|
522
|
+
const { s, t } = ui;
|
|
523
|
+
const width = Math.max(1, ui.width);
|
|
524
|
+
const w = words(ui.lang);
|
|
525
|
+
const age = (iso ) => { const x = time(iso); return x === null ? t("status.unknownTime") : w.ago(o.now - x); };
|
|
526
|
+
const out = [];
|
|
527
|
+
|
|
528
|
+
const needs = r.items.filter((i) => i.level === "needs-you");
|
|
529
|
+
const info = r.items.filter((i) => i.level === "info");
|
|
530
|
+
if (r.level === "needs-you") out.push(...leadLines(s, { sym: s.sym.warn, tone: "warn", word: t("status.needsYou", { n: needs.length }) }, width));
|
|
531
|
+
else if (r.level === "working") {
|
|
532
|
+
out.push(...leadLines(s, { sym: s.sym.dot, tone: "accent", word: t("status.working"), note: t("status.workingNote", { pid: r.runInProgress .pid, age: age(r.runInProgress .startedAt) }) }, width));
|
|
533
|
+
} else out.push(...leadLines(s, { sym: s.sym.ok, tone: "ok", word: t("status.allGood"), note: t("status.allGoodNote") }, width));
|
|
534
|
+
// Sanitized here too: a report is not always built by collectStatus. An item without words of its own (a detail a
|
|
535
|
+
// sync cycle recorded) keeps its English text. The sentence is wrapped so nothing is cut: its first line is the
|
|
536
|
+
// callout's title, the rest its body.
|
|
537
|
+
const say = (kind , i ) => {
|
|
538
|
+
const sayer = sayOf(i);
|
|
539
|
+
const text = shownText(sayer ? sayer(w) : i.text, ITEM_TEXT_MAX);
|
|
540
|
+
const [first = "", ...rest] = wrapText(text, Math.max(1, width - 2));
|
|
541
|
+
out.push("", ...callout(s, { kind, title: first, body: rest, ...(i.command !== null ? { command: shownText(i.command, ITEM_COMMAND_MAX) } : {}) }, width));
|
|
542
|
+
};
|
|
543
|
+
for (const i of needs) say("needs-you", i);
|
|
544
|
+
if (info.length > 0) {
|
|
545
|
+
out.push("", ...fitLine(s("muted", t("status.worthKnowing")), width));
|
|
546
|
+
for (const i of info) say("info", i);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const rows = [];
|
|
550
|
+
if (r.pendingImports) {
|
|
551
|
+
const p = r.pendingImports;
|
|
552
|
+
rows.push([t("status.label.pending"), p.count === 0 ? t("status.pending.none")
|
|
553
|
+
: p.source === "plan" ? t("status.pending.fromPlan", { n: p.count, age: age(p.at) }) : t("status.pending.sessions", { n: p.count })]);
|
|
554
|
+
}
|
|
555
|
+
const ls = r.lastSync;
|
|
556
|
+
rows.push([t("status.label.lastSync"), ls
|
|
557
|
+
? ls.runId ? t("status.lastSync.valueRun", { age: age(ls.at), outcome: shownText(ls.outcome, 40), runId: shownText(ls.runId, 60) }) : t("status.lastSync.value", { age: age(ls.at), outcome: shownText(ls.outcome, 40) })
|
|
558
|
+
: t("status.lastSync.never")]);
|
|
559
|
+
if (r.nextSync) rows.push([t("status.label.nextSync"), t("status.nextSync.value", { when: w.ago(o.now - Date.parse(r.nextSync.at)) })]);
|
|
560
|
+
if (r.watcher) {
|
|
561
|
+
const wt = r.watcher;
|
|
562
|
+
// Not running: the short word. What it means and what to do is the item above (or its stop was clean).
|
|
563
|
+
rows.push([t("status.label.watcher"), !wt.running ? t("status.watcher.notRunningShort")
|
|
564
|
+
: wt.version === null ? t("status.watcher.running", { pid: wt.pid }) : t("status.watcher.runningVersion", { pid: wt.pid, version: shownText(wt.version, 20) })]);
|
|
565
|
+
}
|
|
566
|
+
rows.push([t("status.label.t3sm"), shownText(r.update.installed, 20)]);
|
|
567
|
+
if (r.lastOrganize) {
|
|
568
|
+
const l = r.lastOrganize;
|
|
569
|
+
rows.push([t("status.label.lastOrganize"), t("status.organize.value", { runId: shownText(l.runId, 60), age: age(l.at), n: l.changes })
|
|
570
|
+
+ (l.reverted ? t("status.organize.undone", { n: l.reverted }) : "")
|
|
571
|
+
+ (l.rolledBackBy ? t("status.organize.rolledBack", { runId: shownText(l.rolledBackBy, 60) }) : "")]);
|
|
572
|
+
}
|
|
573
|
+
if (r.plugin.length > 0) {
|
|
574
|
+
const state = (p ) =>
|
|
575
|
+
describePlugin(p.state === "missing" ? { state: "missing" } : { state: p.state, version: p.version ?? "unknown" }, o.version, ui.lang);
|
|
576
|
+
// By the account's display name (its id only when it has none); --json keeps the id.
|
|
577
|
+
const plugins = r.plugin.map((p) => `${p.name !== undefined ? shownAccountName(p.name) : shownText(p.account, 60)}: ${state(p)}`).join("; ");
|
|
578
|
+
rows.push([t("status.label.plugin"), r.plugin.some((p) => p.state === "missing") ? t("status.plugin.offer", { plugins }) : plugins]);
|
|
579
|
+
}
|
|
580
|
+
rows.push([t("status.label.t3Code"), r.t3Code.running ? t("status.t3.running", { version: shownText(r.t3Code.version ?? t("status.t3.unknownVersion"), 40) }) : t("status.t3.notRunning")]);
|
|
581
|
+
out.push("", ...kv(s, rows, width));
|
|
582
|
+
return out.join("\n") + "\n";
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
export async function statusCommand(args , io , deps = {}) {
|
|
586
|
+
const p = parseFlags(args, io, "status", [...FLAG_SPECS.status.bool]);
|
|
587
|
+
if (!p) return 2;
|
|
588
|
+
const json = p.flags.has("--json");
|
|
589
|
+
const now = deps.now ?? Date.now;
|
|
590
|
+
const ui = cliUi(io, { now });
|
|
591
|
+
const home = deps.home ?? homedir();
|
|
592
|
+
const dir = stateDir(io.env, home);
|
|
593
|
+
try { await stat(dir); } catch {
|
|
594
|
+
io.stdout(json ? JSON.stringify({ version: 2, ran: false }, null, 2) + "\n" : `${ui.t("status.notRun")}\n`);
|
|
595
|
+
return 0;
|
|
596
|
+
}
|
|
597
|
+
const version = deps.packageVersion ?? ownVersion();
|
|
598
|
+
const report = await collectStatus(dir, home, {
|
|
599
|
+
home, now, pidAlive: deps.pidAlive ?? pidAlive, readRuntime: deps.readRuntime ?? readServerRuntime, packageVersion: version,
|
|
600
|
+
accounts: deps.accounts ?? (async () => {
|
|
601
|
+
const c = await loadConfig(dir, home).catch(() => null);
|
|
602
|
+
return c ? c.accounts.map((a) => ({ id: a.id, home: expandHome(a.home, home), name: a.displayName })) : [{ id: "default", home: join(home, ".claude"), name: "~/.claude" }];
|
|
603
|
+
}),
|
|
604
|
+
pluginState: deps.pluginState ?? ((h) => readPluginState(h, version)),
|
|
605
|
+
installStamp: deps.installStamp ?? ((root) => {
|
|
606
|
+
const r = root ?? installRoot();
|
|
607
|
+
try { return { ...installStamp(r), changedAtMs: installChangedAt(r) }; } catch { return null; }
|
|
608
|
+
}),
|
|
609
|
+
});
|
|
610
|
+
const code = report.level === "needs-you" ? NEEDS_YOU_EXIT : 0;
|
|
611
|
+
// --json keeps its keys: the plugin entries by account id only (the display name is for the screen).
|
|
612
|
+
if (json) { io.stdout(JSON.stringify({ ...report, plugin: report.plugin.map(({ name: _n, ...p }) => p) }, null, 2) + "\n"); return code; }
|
|
613
|
+
io.stdout(renderStatus(report, { ui, now: now(), version }));
|
|
614
|
+
return code;
|
|
615
|
+
}
|