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,161 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { resolveLang } from "../../assistant/i18n.js";
|
|
3
|
+
import { mkdir } from "node:fs/promises";
|
|
4
|
+
import { stat } from "node:fs/promises";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
import { expandHome, normalizeCwd, sameCwd, stateDir, tildePath } from "../../core/paths.js";
|
|
8
|
+
import { DEFAULT_ID, assertDefaultInstanceHome, defaultClaudeHome } from "../../ops/accounts.js";
|
|
9
|
+
import { loadConfig, saveConfig, defaultConfig } from "../../core/config.js";
|
|
10
|
+
import { resolveAccountsWithSources } from "../../ops/discoverAccounts.js";
|
|
11
|
+
import { atomicWrite } from "../../core/fsutil.js";
|
|
12
|
+
import { Journal, newRunId } from "../../core/journal.js";
|
|
13
|
+
import { buildPlan } from "../../plan/planner.js";
|
|
14
|
+
import { renderPlanMarkdown, renderTerminalSummary } from "../../plan/report.js";
|
|
15
|
+
import { connectT3, instancesFromConfig, } from "../../t3/api.js";
|
|
16
|
+
import { allAdapters } from "../../sources/registry.js";
|
|
17
|
+
|
|
18
|
+
import { RUN_IN_PROGRESS_NOTE, discoverAll, makeEnv, runInProgress } from "./scan.js";
|
|
19
|
+
import { FLAG_SPECS } from "../flags.js";
|
|
20
|
+
|
|
21
|
+
import { cliUi, unknownOption } from "../ui.js";
|
|
22
|
+
import { shownAccountName } from "../../plan/names.js";
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export async function isDir(p ) {
|
|
35
|
+
try { return (await stat(p)).isDirectory(); } catch { return false; }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
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
|
+
/** Read-only against T3 (an already connected api): read T3's state, discover sessions, build the plan. */
|
|
65
|
+
export async function freshPlan(api , o ) {
|
|
66
|
+
const dir = stateDir(o.env, o.home);
|
|
67
|
+
const [projects, threads, providers, t3cfg] = await Promise.all([api.listProjects(), api.listThreads(), api.providerInstances(), api.getConfig()]);
|
|
68
|
+
const instances = instancesFromConfig(t3cfg);
|
|
69
|
+
|
|
70
|
+
let config = await loadConfig(dir, o.home);
|
|
71
|
+
if (config === null) {
|
|
72
|
+
const r = await resolveAccountsWithSources(o.home, instances, o.env);
|
|
73
|
+
config = defaultConfig(r.accounts);
|
|
74
|
+
if (o.missingConfig === "save") {
|
|
75
|
+
await saveConfig(dir, config, o.home);
|
|
76
|
+
const where = (h ) => {
|
|
77
|
+
const f = r.found.find((x) => sameCwd(x.home, h));
|
|
78
|
+
return f && f.sources.length > 0 ? f.sources.join(", ") : "folder";
|
|
79
|
+
};
|
|
80
|
+
const list = config.accounts.map((a) => `\n ${a.id} ${tildePath(a.home, o.home)} (found via ${where(a.home)})`).join("");
|
|
81
|
+
o.onNotice?.(`No config found: detected ${config.accounts.length} account(s) and saved ${join(dir, "config.json")}:${list}\nEdit it if an account is missing or wrong, then run \`t3sm plan\` again.`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Before any discovery: T3's default Claude instance must read the config's ~/.claude account (by home, any id).
|
|
86
|
+
const accountHomes = config.accounts.map((a) => expandHome(a.home, o.home));
|
|
87
|
+
assertDefaultInstanceHome(providers, accountHomes, o.home, process.platform, t3cfg.settings.providerInstances);
|
|
88
|
+
|
|
89
|
+
const io = { env: o.env } ;
|
|
90
|
+
const { sessions } = await discoverAll(o.adapters ?? allAdapters(), { ...makeEnv(io, o.home, config, o.now), readOnly: o.readOnly ?? false });
|
|
91
|
+
const journal = await new Journal(join(dir, "journal.jsonl")).readAll();
|
|
92
|
+
const runId = o.runId ?? newRunId(new Date(o.now()));
|
|
93
|
+
const plan = await buildPlan({
|
|
94
|
+
sessions, config, journal, now: o.now(), runId, home: o.home,
|
|
95
|
+
t3: { version: api.version, projects, threads, instances, providers },
|
|
96
|
+
existsDir: o.existsDir ?? isDir, lang: o.lang ?? resolveLang(null, o.env, config.language),
|
|
97
|
+
...(o.recover ? { recover: o.recover } : {}),
|
|
98
|
+
});
|
|
99
|
+
// Implicit default instance (no settings entry) + a config account for ~/.claude: apply pins it there.
|
|
100
|
+
const defHome = defaultClaudeHome(o.home);
|
|
101
|
+
const implicit = providers.some((p) => p.instanceId === DEFAULT_ID && p.driver === "claudeAgent") && !Object.hasOwn(t3cfg.settings.providerInstances, DEFAULT_ID);
|
|
102
|
+
plan.pinDefault = implicit && accountHomes.some((h) => sameCwd(h, defHome))
|
|
103
|
+
? { instanceId: DEFAULT_ID, homePath: normalizeCwd(defHome) } : null;
|
|
104
|
+
const names = {};
|
|
105
|
+
for (const a of config.accounts) names[a.id] = shownAccountName(a.displayName);
|
|
106
|
+
for (const i of instances) names[i.id] ??= shownAccountName(i.displayName);
|
|
107
|
+
return { plan, config, projects, names };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function planCommand(args , io , deps = {}) {
|
|
111
|
+
const known = new Set (FLAG_SPECS.plan.bool);
|
|
112
|
+
const bad = args.find((a) => !known.has(a));
|
|
113
|
+
if (bad !== undefined) {
|
|
114
|
+
unknownOption(io, bad, "plan");
|
|
115
|
+
return 2;
|
|
116
|
+
}
|
|
117
|
+
const json = args.includes("--json");
|
|
118
|
+
const home = deps.home ?? homedir();
|
|
119
|
+
const now = deps.now ?? Date.now;
|
|
120
|
+
const dir = stateDir(io.env, home);
|
|
121
|
+
const connect = deps.connect ?? connectT3;
|
|
122
|
+
if (await runInProgress(dir)) io.stderr(`${RUN_IN_PROGRESS_NOTE}\n`);
|
|
123
|
+
const { plan, names, planPath } = await writeFreshPlan(io, { ...deps, home, now, connect }, args.includes("--allow-untested"));
|
|
124
|
+
if (json) io.stdout(JSON.stringify(planForJson(plan), null, 2) + "\n");
|
|
125
|
+
else {
|
|
126
|
+
io.stdout(renderTerminalSummary(plan, { planPath, names, ui: cliUi(io, { now }) }));
|
|
127
|
+
}
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The plan as `--json` prints it: a copy whose account display names are masked (shownAccountName); plan.json keeps them. */
|
|
132
|
+
export function planForJson(plan ) {
|
|
133
|
+
return { ...plan, instancesToCreate: plan.instancesToCreate.map((i) => ({ ...i, displayName: shownAccountName(i.displayName, 200) })) };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* What `t3sm plan` does, without printing the summary: connect (read-only), build a fresh plan, write
|
|
138
|
+
* runs/<runId>/plan.md and plan.json (and config.json on the first run). Shared with the guided assistant.
|
|
139
|
+
*/
|
|
140
|
+
export async function writeFreshPlan(io , deps , allowUntested ) {
|
|
141
|
+
const home = deps.home ?? homedir();
|
|
142
|
+
const now = deps.now ?? Date.now;
|
|
143
|
+
const dir = stateDir(io.env, home);
|
|
144
|
+
const connect = deps.connect ?? connectT3;
|
|
145
|
+
// Connect first: with T3 down (exit 3, thrown, mapped in main) nothing is written.
|
|
146
|
+
const api = await connect(home, { allowUntested, manageProviders: false, onNotice: (l) => io.stderr(`${l}\n`) });
|
|
147
|
+
try {
|
|
148
|
+
const fresh = await freshPlan(api, {
|
|
149
|
+
home, env: io.env, now, adapters: deps.adapters, existsDir: deps.existsDir, lang: deps.lang ?? io.lang, missingConfig: "save", onNotice: (l) => io.stderr(`${l}\n`),
|
|
150
|
+
});
|
|
151
|
+
const runDir = join(dir, "runs", fresh.plan.runId);
|
|
152
|
+
await mkdir(runDir, { recursive: true });
|
|
153
|
+
const planPath = join(runDir, "plan.md");
|
|
154
|
+
// plan.md first, plan.json last: apply reads plan.json, so its presence means the run is complete.
|
|
155
|
+
await atomicWrite(planPath, renderPlanMarkdown(fresh.plan, { names: fresh.names }));
|
|
156
|
+
await atomicWrite(join(runDir, "plan.json"), JSON.stringify(fresh.plan, null, 2) + "\n");
|
|
157
|
+
return { ...fresh, planPath };
|
|
158
|
+
} finally {
|
|
159
|
+
await api.close();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
// t3sm projects: which account each project folder uses, and the supported way to change it.
|
|
2
|
+
// projects [--json] read-only table (T3 Code down: local columns only, exit 0)
|
|
3
|
+
// projects set "<folder>" <account> exact-folder route in config.json; the T3 project's default (journaled)
|
|
4
|
+
// projects unset "<folder>" removes that route (T3 Code unchanged)
|
|
5
|
+
// projects rename --suggest clean titles for t3sm's projects still named as t3sm named them (journaled
|
|
6
|
+
// organize changes: `t3sm organize --undo` reverts them)
|
|
7
|
+
// set: --dry-run, or no --yes on a non-terminal: exit 0 / 2 before any write.
|
|
8
|
+
// Otherwise: lock -> recoverPendingMtimes -> read T3 (optional) -> confirm -> config.json -> T3 default (journaled run).
|
|
9
|
+
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
|
|
13
|
+
import { expandHome, sameCwd, stateDir, tildePath } from "../../core/paths.js";
|
|
14
|
+
import { displayWidth } from "../../ui/text.js";
|
|
15
|
+
import { ConfigError, defaultConfig, loadConfig, organizeSettings, routeAccount, saveConfig } from "../../core/config.js";
|
|
16
|
+
import { Journal, newRunId, recoverPendingMtimes } from "../../core/journal.js";
|
|
17
|
+
import { acquireLock } from "../../core/lock.js";
|
|
18
|
+
import { applyProjectDefaults } from "../../ops/accounts.js";
|
|
19
|
+
import { resolveAccounts } from "../../ops/discoverAccounts.js";
|
|
20
|
+
import { isGlob, normalizeFolder, otherFoldersChanged, projectRows, setRoute, unsetRoute, } from "../../ops/projects.js";
|
|
21
|
+
import { latestPlan, readPlan } from "./apply.js";
|
|
22
|
+
import { buildPlan } from "../../plan/planner.js";
|
|
23
|
+
import { allAdapters } from "../../sources/registry.js";
|
|
24
|
+
|
|
25
|
+
import { connectT3, } from "../../t3/api.js";
|
|
26
|
+
import { T3NotRunning } from "../../t3/errors.js";
|
|
27
|
+
import { freshPlan, isDir } from "./plan.js";
|
|
28
|
+
import { parseFlags } from "./quarantine.js";
|
|
29
|
+
import { cliT, cliUi, confirm, isCliKey, langOf, usageLine } from "../ui.js";
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
import { bulletLines, fitLine, noteLines, tableOrBlocks, textLines } from "../screen.js";
|
|
33
|
+
import { discoverAll, makeEnv } from "./scan.js";
|
|
34
|
+
import { reportLockBusy } from "../locked.js";
|
|
35
|
+
import { applyOrganize } from "../../organize/apply.js";
|
|
36
|
+
import { suggestProjectTitles } from "../../organize/rename.js";
|
|
37
|
+
|
|
38
|
+
import { resolveGeneralFolder } from "../../plan/categories.js";
|
|
39
|
+
import { shownAccountName, shownText } from "../../plan/names.js";
|
|
40
|
+
import { connectForOrganize, noticeOnce } from "./organize.js";
|
|
41
|
+
import { PROJECTS_FLAGS } from "../flags.js";
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
const USAGE_HINT = "Run `t3sm projects --help`.";
|
|
55
|
+
/** How `projects set` starts its line when config.json and T3 Code already say so (nothing written), in each language. */
|
|
56
|
+
export const NOTHING_TO_CHANGE_MARKS = [cliT("en", "projects.nothingToChange"), cliT("pt", "projects.nothingToChange")];
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
export async function projectsCommand(args , io , deps = {}) {
|
|
61
|
+
const sub = args[0] === "set" || args[0] === "unset" || args[0] === "rename" ? args[0] : null;
|
|
62
|
+
const rest = sub ? args.slice(1) : args;
|
|
63
|
+
const positional = rest.filter((a) => !a.startsWith("--"));
|
|
64
|
+
const flags = rest.filter((a) => a.startsWith("--"));
|
|
65
|
+
const allowed = [...PROJECTS_FLAGS[sub ?? "list"]];
|
|
66
|
+
const p = parseFlags(flags, io, "projects", allowed);
|
|
67
|
+
if (!p) return 2;
|
|
68
|
+
const want = sub === "set" ? 2 : sub === "unset" ? 1 : 0;
|
|
69
|
+
if (positional.length !== want || (sub === "rename" && !p.flags.has("--suggest"))) {
|
|
70
|
+
io.stderr(sub === "set" ? `Usage: t3sm projects set "<folder>" <account>. ${USAGE_HINT}\n`
|
|
71
|
+
: sub === "rename" ? `Usage: t3sm projects rename --suggest [--yes | --dry-run]. ${USAGE_HINT}\n`
|
|
72
|
+
: sub === "unset" ? `Usage: t3sm projects unset "<folder>". ${USAGE_HINT}\n`
|
|
73
|
+
: `Unknown argument: ${positional[0]}. ${USAGE_HINT}\n`);
|
|
74
|
+
return 2;
|
|
75
|
+
}
|
|
76
|
+
const home = deps.home ?? homedir();
|
|
77
|
+
const c = { io, home, now: deps.now ?? Date.now, dir: stateDir(io.env, home), connect: deps.connect ?? connectT3, deps, allowUntested: p.flags.has("--allow-untested"), platform: deps.platform ?? process.platform };
|
|
78
|
+
try {
|
|
79
|
+
if (sub === "set") return await setProject(c, positional[0] , positional[1] , p.flags);
|
|
80
|
+
if (sub === "unset") return await unsetProject(c, positional[0] , p.flags.has("--dry-run"));
|
|
81
|
+
if (sub === "rename") return await renameProjects(c, p.flags);
|
|
82
|
+
return await listProjects(c, p.flags.has("--json"));
|
|
83
|
+
} catch (e) {
|
|
84
|
+
if (e instanceof ConfigError) { io.stderr(`${e.message}\n`); return 2; }
|
|
85
|
+
throw e;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ---------------- list ----------------
|
|
90
|
+
|
|
91
|
+
async function listProjects(c , json ) {
|
|
92
|
+
let rows ;
|
|
93
|
+
let offline = false;
|
|
94
|
+
let api = null;
|
|
95
|
+
try {
|
|
96
|
+
api = await c.connect(c.home, { allowUntested: c.allowUntested, manageProviders: false, onNotice: (l) => c.io.stderr(`${l}\n`) });
|
|
97
|
+
} catch (e) {
|
|
98
|
+
if (!(e instanceof T3NotRunning)) throw e;
|
|
99
|
+
}
|
|
100
|
+
if (api) {
|
|
101
|
+
try {
|
|
102
|
+
// Read-only: no config.json saved, no discovery cache written.
|
|
103
|
+
const f = await freshPlan(api, { home: c.home, env: c.io.env, now: c.now, adapters: c.deps.adapters, existsDir: c.deps.existsDir, missingConfig: "memory", readOnly: true });
|
|
104
|
+
rows = projectRows(f.plan, f.names, f.projects, f.config);
|
|
105
|
+
} finally {
|
|
106
|
+
await api.close();
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
offline = true;
|
|
110
|
+
const { plan, config } = await offlinePlan(c);
|
|
111
|
+
rows = projectRows(plan, Object.fromEntries(config.accounts.map((a) => [a.id, shownAccountName(a.displayName)])), null, config);
|
|
112
|
+
}
|
|
113
|
+
if (json) { c.io.stdout(JSON.stringify(rows, null, 2) + "\n"); return 0; }
|
|
114
|
+
c.io.stdout(renderProjects(cliUi(c.io), rows, offline, undefined, c.home).join("\n") + "\n");
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* T3 Code not running: the plan built against an empty T3 Code (nothing read from it). Account and reason are the same
|
|
120
|
+
* as with T3 Code; "pending" counts the sessions found, since what T3 Code already holds is unknown.
|
|
121
|
+
*/
|
|
122
|
+
async function offlinePlan(c ) {
|
|
123
|
+
const config = (await loadConfig(c.dir, c.home)) ?? defaultConfig(await resolveAccounts(c.home, [], c.io.env));
|
|
124
|
+
const { sessions } = await discoverAll(c.deps.adapters ?? allAdapters(), { ...makeEnv(c.io, c.home, config, c.now), readOnly: true });
|
|
125
|
+
const journal = await new Journal(join(c.dir, "journal.jsonl")).readAll().catch(() => []);
|
|
126
|
+
const plan = await buildPlan({
|
|
127
|
+
sessions, config, journal, now: c.now(), runId: "offline", home: c.home, existsDir: c.deps.existsDir ?? isDir,
|
|
128
|
+
t3: {
|
|
129
|
+
version: "-", projects: [], threads: [],
|
|
130
|
+
instances: config.accounts.map((a) => ({ id: a.id, driver: "claudeAgent" , displayName: a.displayName, accentColor: a.accentColor, homePath: expandHome(a.home, c.home), environment: [] })),
|
|
131
|
+
// Assume T3 Code's own Codex and Pi instances exist, so their sessions count too.
|
|
132
|
+
providers: [{ instanceId: "codex", driver: "codex" }, { instanceId: "pi", driver: "pi" }],
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
return { plan, config };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Every project folder t3sm knows as a table: the folder (cut in the middle), the account new threads start on and why,
|
|
140
|
+
* the sessions waiting, whether it is in T3 Code and whether a session of it is in use; then what the reasons mean and
|
|
141
|
+
* how to change an account. With T3 Code closed, a note first and the columns this machine can fill.
|
|
142
|
+
*/
|
|
143
|
+
export function renderProjects(ui , rows , offline , width = ui.width, home ) {
|
|
144
|
+
const { s, t, f } = ui;
|
|
145
|
+
// The short columns keep their full width (min = natural): the folder is the one that is cut, in the middle.
|
|
146
|
+
const fit = (header , cells ) => Math.max(displayWidth(header), ...cells.map(displayWidth));
|
|
147
|
+
const out = [];
|
|
148
|
+
if (offline) out.push(...noteLines(s, "warn", t("projects.offline"), width), "");
|
|
149
|
+
if (rows.length === 0) { out.push(...noteLines(s, "ok", t("projects.none"), width)); return out; }
|
|
150
|
+
const yesNo = (b ) => t(b ? "projects.yes" : "projects.no");
|
|
151
|
+
const inT3 = (x ) => (x === null ? "-" : x === "yes" ? t("projects.yes") : x === "no" ? t("projects.no") : t("projects.archived"));
|
|
152
|
+
const folder = (r ) => shownText(home ? tildePath(r.folder, home) : r.folder, 300);
|
|
153
|
+
const account = (r ) => shownText(r.accountName, 60);
|
|
154
|
+
// The reason in words (the --json keeps the code).
|
|
155
|
+
const why = (r ) => { const k = `projects.why.${r.reason.replace(/-([a-z])/g, (_m, c ) => c.toUpperCase())}`; return isCliKey(k) ? t(k) : shownText(r.reason, 30); };
|
|
156
|
+
const col = (header , get , priority , extra = {}) =>
|
|
157
|
+
({ header, get: (r) => get(r ), priority, min: fit(header, rows.map(get)), ...extra });
|
|
158
|
+
const cols = [
|
|
159
|
+
col(t("projects.col.folder"), folder, 9, { truncate: "middle", min: 16 }),
|
|
160
|
+
col(t("projects.col.account"), account, 8),
|
|
161
|
+
col(t("projects.col.reason"), why, 4),
|
|
162
|
+
col(t(offline ? "projects.col.sessions" : "projects.col.pending"), (r) => f.n(r.pending), 7, { align: "right" }),
|
|
163
|
+
...(offline ? [] : [col(t("projects.col.inT3"), (r) => inT3(r.inT3), 5)]),
|
|
164
|
+
col(t("projects.col.inUse"), (r) => yesNo(r.held), 3),
|
|
165
|
+
];
|
|
166
|
+
// A table while every column fits (the folder cut in the middle); narrower, one block per project, nothing dropped.
|
|
167
|
+
out.push(...tableOrBlocks(s, cols, rows, width, { allowMin: true }), "");
|
|
168
|
+
out.push(...textLines(s, t("projects.reasons"), width));
|
|
169
|
+
out.push(...noteLines(s, "info", t("projects.change"), width));
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ---------------- set / unset ----------------
|
|
174
|
+
|
|
175
|
+
async function requireConfig(c ) {
|
|
176
|
+
const cfg = await loadConfig(c.dir, c.home);
|
|
177
|
+
if (cfg === null) throw new ConfigError(`${join(c.dir, "config.json")} not found. Run \`t3sm plan\` (or \`t3sm accounts --init\`) first.`);
|
|
178
|
+
return cfg;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const nameOf = (cfg , id , lang = "en") => (id ? ((n) => (n === undefined ? id : shownAccountName(n)))(cfg.accounts.find((a) => a.id === id)?.displayName) : cliT(lang, "projects.noneAccount"));
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
/** The T3 project for `folder` and the instance of `account` (null when either is missing). Read-only. */
|
|
186
|
+
async function t3PartOf(api , cfg , home , folder , account ) {
|
|
187
|
+
const project = (await api.listProjects()).find((p) => !p.deleted && sameCwd(p.workspaceRoot, folder));
|
|
188
|
+
if (!project) return "no-project";
|
|
189
|
+
const acct = cfg.accounts.find((a) => a.id === account) ;
|
|
190
|
+
const inst = (await api.providerInstances()).find((i) => i.driver === "claudeAgent" && i.homePath !== null && sameCwd(i.homePath, expandHome(acct.home, home)));
|
|
191
|
+
if (!inst) return "no-instance";
|
|
192
|
+
const cur = project.defaultModelSelection?.instanceId;
|
|
193
|
+
return { api, project, instanceId: inst.instanceId, current: typeof cur === "string" ? cur : null };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function setProject(c , rawFolder , account , flags ) {
|
|
197
|
+
const { io } = c;
|
|
198
|
+
const dry = flags.has("--dry-run");
|
|
199
|
+
const yes = flags.has("--yes");
|
|
200
|
+
const cfg = await requireConfig(c);
|
|
201
|
+
if (!cfg.accounts.some((a) => a.id === account)) {
|
|
202
|
+
throw new ConfigError(cliT(io.lang ?? "en", "projects.noAccount", { account: JSON.stringify(account), known: cfg.accounts.map((a) => a.id).join(", ") }));
|
|
203
|
+
}
|
|
204
|
+
const folder = normalizeFolder(rawFolder, c.platform, c.home);
|
|
205
|
+
if (!flags.has("--force") && !(await (c.deps.existsDir ?? isDir)(folder))) {
|
|
206
|
+
throw new ConfigError(cliT(io.lang ?? "en", "projects.noFolder", { folder }));
|
|
207
|
+
}
|
|
208
|
+
if (!dry && !yes && !io.isTTY) {
|
|
209
|
+
io.stderr(`${cliT(io.lang ?? "en", "projects.needsYes")}\n`);
|
|
210
|
+
return 2;
|
|
211
|
+
}
|
|
212
|
+
const ui = cliUi(io);
|
|
213
|
+
const tt = ui.t;
|
|
214
|
+
const name = (id ) => nameOf(cfg, id, ui.lang);
|
|
215
|
+
const say = (l ) => io.stdout(l.join("\n") + "\n");
|
|
216
|
+
const r = setRoute(cfg, folder, account);
|
|
217
|
+
const routeLine = (would ) => r.previous === null
|
|
218
|
+
? tt(would ? "projects.route.wouldAdd" : "projects.route.add", { folder, name: name(account), account })
|
|
219
|
+
: tt(would ? "projects.route.wouldChange" : "projects.route.change", { folder, name: name(account), account, was: name(r.before) });
|
|
220
|
+
const describeT3 = (t , would ) => {
|
|
221
|
+
if (t === null) return tt("projects.t3.down");
|
|
222
|
+
if (t === "no-project") return tt("projects.t3.noProject");
|
|
223
|
+
if (t === "no-instance") return tt("projects.t3.noInstance", { name: name(account) });
|
|
224
|
+
if (t.current === t.instanceId) return null;
|
|
225
|
+
return tt(would ? "projects.t3.wouldSet" : "projects.t3.set", { title: shownText(t.project.title, 60), name: name(account), was: name(t.current) });
|
|
226
|
+
};
|
|
227
|
+
const keep = tt("projects.keep", { name: name(account) });
|
|
228
|
+
/** Refuses (exit 2) when the new routes would change any other known folder's account; returns the "unknown folder" note. */
|
|
229
|
+
const check = async (api ) => {
|
|
230
|
+
const known = await knownRoots(c, api);
|
|
231
|
+
const roots = [...known.roots, ...cfg.routes.filter((x) => !isGlob(x.match)).map((x) => x.match)];
|
|
232
|
+
if (routeAccount(folder, r.config) !== account) throw new ConfigError(tt("projects.stillNot", { folder, name: name(account) }));
|
|
233
|
+
const others = otherFoldersChanged(cfg, r.config, roots, folder);
|
|
234
|
+
if (others.length > 0) throw new ConfigError(othersRefusal(others, ui.lang));
|
|
235
|
+
if (!known.read || known.roots.some((x) => sameCwd(x, folder))) return null;
|
|
236
|
+
return tt("projects.unknownFolder", { folder });
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
if (dry) {
|
|
240
|
+
let t = null;
|
|
241
|
+
let note = null;
|
|
242
|
+
const api = await connectOrNull(c);
|
|
243
|
+
try {
|
|
244
|
+
if (api) t = await t3PartOf(api, cfg, c.home, folder, account);
|
|
245
|
+
note = await check(api);
|
|
246
|
+
} finally { await api?.close(); }
|
|
247
|
+
const t3Line = describeT3(t, true);
|
|
248
|
+
say([
|
|
249
|
+
...(note ? noteLines(ui.s, "warn", note, ui.width) : []),
|
|
250
|
+
...noteLines(ui.s, "info", r.changed ? routeLine(true) : tt("projects.route.already"), ui.width),
|
|
251
|
+
...(t3Line ? noteLines(ui.s, "info", t3Line, ui.width) : []),
|
|
252
|
+
...noteLines(ui.s, "ok", tt("projects.dryRun"), ui.width),
|
|
253
|
+
]);
|
|
254
|
+
return 0;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const lock = await acquireLock(c.dir);
|
|
258
|
+
if (!lock) { reportLockBusy(io); return 0; }
|
|
259
|
+
try {
|
|
260
|
+
const j = new Journal(join(c.dir, "journal.jsonl"));
|
|
261
|
+
const rec = await recoverPendingMtimes(j);
|
|
262
|
+
if (rec.restored.length > 0) io.stderr(`${tt("apply.recovered", { n: rec.restored.length })}\n`);
|
|
263
|
+
const api = await connectOrNull(c);
|
|
264
|
+
try {
|
|
265
|
+
const t = api ? await t3PartOf(api, cfg, c.home, folder, account) : null;
|
|
266
|
+
const note = await check(api);
|
|
267
|
+
if (note) say(noteLines(ui.s, "warn", note, ui.width));
|
|
268
|
+
const t3Write = t !== null && typeof t === "object" && t.current !== t.instanceId ? t : null;
|
|
269
|
+
if (!r.changed && t3Write === null) { say(noteLines(ui.s, "ok", tt("projects.already", { folder, name: name(account) }), ui.width)); return 0; }
|
|
270
|
+
const lines = [...(r.changed ? [routeLine(false)] : []), ...(describeT3(t, false) ? [describeT3(t, false) ] : [])];
|
|
271
|
+
if (!yes) {
|
|
272
|
+
say([...fitLine(ui.s("title", tt("projects.willDo")), ui.width), ...lines.flatMap((l) => bulletLines(ui.s, l, ui.width)), ""]);
|
|
273
|
+
if (!(await confirm(io, tt("projects.confirmSet")))) { io.stdout(`${tt("common.nothingChanged")}\n`); return 0; }
|
|
274
|
+
}
|
|
275
|
+
if (r.changed) await saveConfig(c.dir, r.config, c.home);
|
|
276
|
+
let runId = null;
|
|
277
|
+
if (t3Write) {
|
|
278
|
+
runId = newRunId(new Date(c.now()));
|
|
279
|
+
await j.append({ t: "run-start", runId, at: new Date(c.now()).toISOString(), command: "projects set" });
|
|
280
|
+
try {
|
|
281
|
+
await applyProjectDefaults(t3Write.api, [{ projectId: t3Write.project.id, instanceId: t3Write.instanceId }], j, runId);
|
|
282
|
+
} catch (e) {
|
|
283
|
+
await j.append({ t: "run-end", runId, at: new Date(c.now()).toISOString(), status: "aborted" }).catch(() => {});
|
|
284
|
+
throw e;
|
|
285
|
+
}
|
|
286
|
+
await j.append({ t: "run-end", runId, at: new Date(c.now()).toISOString(), status: "ok" });
|
|
287
|
+
}
|
|
288
|
+
const done = [...(r.changed ? [r.previous === null ? tt("projects.added", { folder, name: name(account) }) : tt("projects.changed", { folder, name: name(account), was: name(r.before) })] : [])];
|
|
289
|
+
if (t3Write && runId) done.push(tt("projects.t3.done", { title: shownText(t3Write.project.title, 60), name: name(account), runId }));
|
|
290
|
+
else { const l = describeT3(t, false); if (l) done.push(l); }
|
|
291
|
+
say([...done.flatMap((l) => noteLines(ui.s, "ok", l, ui.width)), ...textLines(ui.s, keep, ui.width, 2)]);
|
|
292
|
+
return 0;
|
|
293
|
+
} finally {
|
|
294
|
+
await api?.close();
|
|
295
|
+
}
|
|
296
|
+
} finally {
|
|
297
|
+
await lock.release();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Project folders t3sm knows: T3 Code's projects (when connected) and the latest plan's project table. `read`: at least
|
|
303
|
+
* one of the two could be read. Read-only.
|
|
304
|
+
*/
|
|
305
|
+
async function knownRoots(c , api ) {
|
|
306
|
+
const roots = [];
|
|
307
|
+
let read = false;
|
|
308
|
+
if (api) { roots.push(...(await api.listProjects()).filter((p) => !p.deleted).map((p) => p.workspaceRoot)); read = true; }
|
|
309
|
+
try {
|
|
310
|
+
const p = await latestPlan(c.dir);
|
|
311
|
+
if (p !== null) { roots.push(...(await readPlan(p)).projectAccounts.map((x) => x.root)); read = true; }
|
|
312
|
+
} catch { /* an unreadable plan is not this command's problem */ }
|
|
313
|
+
return { roots, read };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** A T3 session, or null when T3 Code is not running (every other error is thrown: exit 4, 1, ...). */
|
|
317
|
+
async function connectOrNull(c ) {
|
|
318
|
+
try {
|
|
319
|
+
return await c.connect(c.home, { allowUntested: c.allowUntested, manageProviders: false, onNotice: (l) => c.io.stderr(`${l}\n`) });
|
|
320
|
+
} catch (e) {
|
|
321
|
+
if (e instanceof T3NotRunning) return null;
|
|
322
|
+
throw e;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async function unsetProject(c , rawFolder , dry ) {
|
|
327
|
+
const cfg = await requireConfig(c);
|
|
328
|
+
const folder = normalizeFolder(rawFolder, c.platform, c.home);
|
|
329
|
+
const r = unsetRoute(cfg, folder);
|
|
330
|
+
const ui = cliUi(c.io);
|
|
331
|
+
const say = (tone , text ) => c.io.stdout(noteLines(ui.s, tone, text, ui.width).join("\n") + "\n");
|
|
332
|
+
if (r.removed === null) { say("ok", ui.t("projects.unset.none", { folder })); return 0; }
|
|
333
|
+
const name = nameOf(cfg, r.removed, ui.lang);
|
|
334
|
+
if (dry) { say("info", ui.t("projects.unset.would", { folder, name })); say("ok", ui.t("projects.dryRun")); return 0; }
|
|
335
|
+
await saveConfig(c.dir, r.config, c.home);
|
|
336
|
+
say("ok", ui.t("projects.unset.done", { folder, name }));
|
|
337
|
+
return 0;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ---------------- rename --suggest ----------------
|
|
341
|
+
|
|
342
|
+
/** The renames to propose, read from T3 Code and the journal (read-only). */
|
|
343
|
+
async function renamePlan(c , api , j ) {
|
|
344
|
+
const cfg = (await loadConfig(c.dir, c.home)) ?? defaultConfig([]);
|
|
345
|
+
const lang = langOf(c.io, cfg.language);
|
|
346
|
+
const projects = await api.listProjects();
|
|
347
|
+
const platform = c.platform;
|
|
348
|
+
return suggestProjectTitles(projects, await j.readAll(), {
|
|
349
|
+
maxLength: organizeSettings(cfg, lang).names.maxLength, platform,
|
|
350
|
+
generalFolder: resolveGeneralFolder(cfg, lang, projects.map((p) => p.workspaceRoot), { platform, home: c.home }),
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** The refusal when a new route would move other folders to another account; folders are untrusted text (shownText). */
|
|
355
|
+
export function othersRefusal(others , lang = "en") {
|
|
356
|
+
return cliT(lang, "projects.others", { folders: others.map((x) => shownText(x, 120)).join(", ") });
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** A title in quotes, as the rename list shows it; untrusted text, so no control characters (shownText). */
|
|
360
|
+
const q = (t ) => `'${shownText(t, 60)}'`;
|
|
361
|
+
|
|
362
|
+
/** The renames, one per line ('before' -> 'after', the arrows aligned), or the line that says there is none. */
|
|
363
|
+
export function renameLines(ui , actions , width = ui.width) {
|
|
364
|
+
const { s, t } = ui;
|
|
365
|
+
if (actions.length === 0) return noteLines(s, "ok", t("projects.rename.none"), width);
|
|
366
|
+
const w = Math.max(...actions.map((a) => displayWidth(q(a.previous))));
|
|
367
|
+
const out = noteLines(s, "info", t("projects.rename.head", { n: actions.length }), width);
|
|
368
|
+
for (const a of actions) out.push(...bulletLines(s, `${q(a.previous)}${" ".repeat(w - displayWidth(q(a.previous)))} -> ${q(a.next)}`, width));
|
|
369
|
+
return out;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
async function renameProjects(c , flags ) {
|
|
373
|
+
const { io } = c;
|
|
374
|
+
const dry = flags.has("--dry-run");
|
|
375
|
+
const yes = flags.has("--yes");
|
|
376
|
+
if (!dry && !yes && !io.isTTY) { usageLine(io, "common.needsYesT3"); return 2; }
|
|
377
|
+
const j = new Journal(join(c.dir, "journal.jsonl"));
|
|
378
|
+
const onNotice = noticeOnce(io);
|
|
379
|
+
// Organize commands: any T3 Code version, one warning (ruling R18).
|
|
380
|
+
const connect = () => connectForOrganize(c.connect, c.home, c.allowUntested, onNotice);
|
|
381
|
+
|
|
382
|
+
const ui = cliUi(io, { now: c.now });
|
|
383
|
+
const say = (l ) => io.stdout(l.join("\n") + "\n");
|
|
384
|
+
if (dry) {
|
|
385
|
+
const api = await connect();
|
|
386
|
+
try {
|
|
387
|
+
const actions = await renamePlan(c, api, j);
|
|
388
|
+
say(renameLines(ui, actions));
|
|
389
|
+
if (actions.length > 0) say(["", ...noteLines(ui.s, "info", ui.t("projects.rename.dry"), ui.width)]);
|
|
390
|
+
} finally {
|
|
391
|
+
await api.close();
|
|
392
|
+
}
|
|
393
|
+
return 0;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const lock = await acquireLock(c.dir);
|
|
397
|
+
if (!lock) { reportLockBusy(io); return 0; }
|
|
398
|
+
try {
|
|
399
|
+
const rec = await recoverPendingMtimes(j);
|
|
400
|
+
if (rec.restored.length > 0) io.stderr(`${ui.t("apply.recovered", { n: rec.restored.length })}\n`);
|
|
401
|
+
const api = await connect();
|
|
402
|
+
try {
|
|
403
|
+
const actions = await renamePlan(c, api, j);
|
|
404
|
+
say(renameLines(ui, actions));
|
|
405
|
+
if (actions.length === 0) return 0;
|
|
406
|
+
if (!yes) {
|
|
407
|
+
io.stdout("\n");
|
|
408
|
+
if (!(await confirm(io, ui.t("projects.confirmRename")))) { io.stdout(`${ui.t("common.nothingChanged")}\n`); return 0; }
|
|
409
|
+
}
|
|
410
|
+
const runId = newRunId(new Date(c.now()));
|
|
411
|
+
const counts = { archive: 0, title: 0, unsettle: 0, settle: 0, pin: 0, unpin: 0, "project-delete": 0, "project-title": actions.length, "auto-settle": 0 };
|
|
412
|
+
const r = await applyOrganize({ runId, actions, counts, byProject: [] }, {
|
|
413
|
+
api, journal: j, runId, now: c.now, command: "projects rename", allowUntested: true, onNotice, // organizeGate already spoke
|
|
414
|
+
});
|
|
415
|
+
const out = [];
|
|
416
|
+
for (const f of r.failed) out.push(...noteLines(ui.s, "err", ui.t("projects.rename.failed", { from: q(f.action.previous), to: q(f.action.next), error: shownText(f.error, 200) }), ui.width));
|
|
417
|
+
const parts = [r.done > 0 ? ui.t("projects.rename.done", { n: r.done }) : ui.t("organize.madeNone")];
|
|
418
|
+
if (r.skippedChanged > 0) parts.push(ui.t("projects.rename.leftAlone", { n: r.skippedChanged }));
|
|
419
|
+
if (r.failed.length > 0) parts.push(ui.t("organize.failedCount", { n: r.failed.length }));
|
|
420
|
+
if (r.done > 0) parts.push(ui.t("organize.runUndo", { runId }));
|
|
421
|
+
out.push(...noteLines(ui.s, r.failed.length > 0 ? "warn" : "ok", parts.join(" "), ui.width));
|
|
422
|
+
say(out);
|
|
423
|
+
return r.failed.length > 0 ? 5 : 0;
|
|
424
|
+
} finally {
|
|
425
|
+
await api.close();
|
|
426
|
+
}
|
|
427
|
+
} finally {
|
|
428
|
+
await lock.release();
|
|
429
|
+
}
|
|
430
|
+
}
|