turno-cli 0.0.0-stage → 0.1.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/CHANGELOG.md +30 -0
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/README.md +335 -2
- package/dist/accounts/audit.js +54 -0
- package/dist/accounts/builtin.js +214 -0
- package/dist/accounts/delegate.js +185 -0
- package/dist/accounts/registry.js +190 -0
- package/dist/agents/index.js +101 -0
- package/dist/agents/snippets.js +64 -0
- package/dist/cli/args.js +47 -0
- package/dist/cli/commands/accounts.js +216 -0
- package/dist/cli/commands/auto.js +44 -0
- package/dist/cli/commands/available.js +18 -0
- package/dist/cli/commands/browser.js +175 -0
- package/dist/cli/commands/complete.js +112 -0
- package/dist/cli/commands/completion.js +57 -0
- package/dist/cli/commands/config.js +168 -0
- package/dist/cli/commands/doctor.js +324 -0
- package/dist/cli/commands/exhausted.js +40 -0
- package/dist/cli/commands/handoff.js +118 -0
- package/dist/cli/commands/hook.js +63 -0
- package/dist/cli/commands/identity.js +114 -0
- package/dist/cli/commands/limit.js +102 -0
- package/dist/cli/commands/mcp.js +350 -0
- package/dist/cli/commands/mcpd.js +161 -0
- package/dist/cli/commands/migrate.js +176 -0
- package/dist/cli/commands/open.js +60 -0
- package/dist/cli/commands/profile.js +259 -0
- package/dist/cli/commands/resolve.js +23 -0
- package/dist/cli/commands/run.js +15 -0
- package/dist/cli/commands/secret.js +123 -0
- package/dist/cli/commands/session.js +36 -0
- package/dist/cli/commands/sessions.js +27 -0
- package/dist/cli/commands/setup.js +224 -0
- package/dist/cli/commands/status.js +101 -0
- package/dist/cli/commands/statusline.js +275 -0
- package/dist/cli/commands/ui.js +276 -0
- package/dist/cli/commands/undo.js +67 -0
- package/dist/cli/commands/update-check.js +22 -0
- package/dist/cli/commands/upgrade.js +162 -0
- package/dist/cli/commands/usage.js +167 -0
- package/dist/cli/commands/version.js +27 -0
- package/dist/cli/commands/which.js +28 -0
- package/dist/cli/group.js +50 -0
- package/dist/cli/io.js +22 -0
- package/dist/cli/launch.js +98 -0
- package/dist/cli/launchers.js +200 -0
- package/dist/cli/main.js +94 -0
- package/dist/cli/registry.js +77 -0
- package/dist/core/config-edit.js +42 -0
- package/dist/core/config.js +137 -0
- package/dist/core/exhausted.js +30 -0
- package/dist/core/journal.js +185 -0
- package/dist/core/manifest.js +177 -0
- package/dist/core/paths.js +54 -0
- package/dist/core/profiles.js +61 -0
- package/dist/core/ratelimit.js +39 -0
- package/dist/core/resolve.js +78 -0
- package/dist/core/secrets.js +44 -0
- package/dist/core/sessions.js +173 -0
- package/dist/core/toml-edit.js +152 -0
- package/dist/core/update.js +102 -0
- package/dist/core/version.js +109 -0
- package/dist/mcpd/cache.js +41 -0
- package/dist/mcpd/connectors.js +63 -0
- package/dist/mcpd/daemon.js +163 -0
- package/dist/mcpd/gateway.js +308 -0
- package/dist/mcpd/importer.js +160 -0
- package/dist/mcpd/instances.js +303 -0
- package/dist/mcpd/jsonrpc.js +19 -0
- package/dist/mcpd/launchd.js +86 -0
- package/dist/mcpd/peerpid.js +25 -0
- package/dist/mcpd/sync.js +208 -0
- package/dist/mcpd/upstream.js +232 -0
- package/dist/statusline/cost.js +135 -0
- package/dist/statusline/render.js +246 -0
- package/dist/ui/cmap.js +57 -0
- package/dist/ui/fonts.js +107 -0
- package/dist/ui/settings.js +69 -0
- package/dist/ui/terminal-id.js +30 -0
- package/dist/ui/terminals.js +163 -0
- package/package.json +69 -3
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { loadRegistry } from "../../accounts/registry.js";
|
|
2
|
+
import { loadConfig } from "../../core/config.js";
|
|
3
|
+
import { listJournals } from "../../core/journal.js";
|
|
4
|
+
import { loadManifest } from "../../core/manifest.js";
|
|
5
|
+
import { listProfiles } from "../../core/profiles.js";
|
|
6
|
+
import { NAMED_COLORS } from "../../statusline/render.js";
|
|
7
|
+
import { TERMINALS } from "../../ui/terminals.js";
|
|
8
|
+
import { COMMANDS, SECTIONS, expand } from "../registry.js";
|
|
9
|
+
/** Values a flag takes, completed after the flag. */
|
|
10
|
+
const FLAG_VALUES = {
|
|
11
|
+
"--terminal": [...TERMINALS.filter((t) => t.write).map((t) => t.id), "current", "all"],
|
|
12
|
+
"--browser": ["chrome", "default"],
|
|
13
|
+
"--profile": "profile",
|
|
14
|
+
"--channel": ["latest", "next"],
|
|
15
|
+
"--color": Object.keys(NAMED_COLORS).filter((c) => /^[a-z]+$/.test(c)),
|
|
16
|
+
};
|
|
17
|
+
function safe(f, fallback) {
|
|
18
|
+
try {
|
|
19
|
+
return f();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return fallback;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function values(kind, env) {
|
|
26
|
+
if (Array.isArray(kind))
|
|
27
|
+
return kind;
|
|
28
|
+
const profiles = () => safe(() => listProfiles(loadConfig(env), env), []);
|
|
29
|
+
switch (kind) {
|
|
30
|
+
case "profile":
|
|
31
|
+
return profiles();
|
|
32
|
+
case "profile-or-auto":
|
|
33
|
+
return [...profiles(), "auto"];
|
|
34
|
+
case "identity": {
|
|
35
|
+
const services = safe(() => Object.keys(loadRegistry(env).accounts), []);
|
|
36
|
+
let browsers = [];
|
|
37
|
+
try {
|
|
38
|
+
const { loadBrowser } = await import("./browser.js");
|
|
39
|
+
const mod = await loadBrowser();
|
|
40
|
+
browsers = mod ? mod.listIdentities(env).map((i) => `browser:${i.id}`) : [];
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
browsers = [];
|
|
44
|
+
}
|
|
45
|
+
return [...services, ...browsers];
|
|
46
|
+
}
|
|
47
|
+
case "server":
|
|
48
|
+
return safe(() => Object.keys(loadManifest(env).servers), []);
|
|
49
|
+
case "stamp":
|
|
50
|
+
return ["last", ...listJournals(env).filter((j) => j.manifest).map((j) => j.stamp)];
|
|
51
|
+
case "key": {
|
|
52
|
+
const { CONFIG_KEYS } = await import("./config.js");
|
|
53
|
+
return CONFIG_KEYS.flatMap((k) => (k.includes("<name>") ? profiles().map((p) => k.replace("<name>", p)) : [k]));
|
|
54
|
+
}
|
|
55
|
+
case "shell":
|
|
56
|
+
return ["zsh", "bash", "fish"];
|
|
57
|
+
case "terminal":
|
|
58
|
+
return FLAG_VALUES["--terminal"];
|
|
59
|
+
default:
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Candidates for the last word, given the words before it (both after `turno`). */
|
|
64
|
+
export async function complete(words, env) {
|
|
65
|
+
const cur = words[words.length - 1] ?? "";
|
|
66
|
+
const before = words.slice(0, -1);
|
|
67
|
+
const match = (list) => [...new Set(list)].filter((c) => c.startsWith(cur));
|
|
68
|
+
if (before.length === 0) {
|
|
69
|
+
const visible = SECTIONS.flatMap((s) => s.commands);
|
|
70
|
+
const profiles = safe(() => listProfiles(loadConfig(env), env), []);
|
|
71
|
+
return match([...visible, ...profiles]);
|
|
72
|
+
}
|
|
73
|
+
const [name, rest] = expand(before[0], before.slice(1));
|
|
74
|
+
const load = COMMANDS[name];
|
|
75
|
+
if (!load)
|
|
76
|
+
return []; // a profile: the rest belongs to claude
|
|
77
|
+
const cmd = (await load()).command;
|
|
78
|
+
let comp = cmd;
|
|
79
|
+
let args = rest;
|
|
80
|
+
if (cmd.subcommands) {
|
|
81
|
+
if (args.length === 0)
|
|
82
|
+
return match(Object.keys(cmd.subcommands));
|
|
83
|
+
comp = cmd.subcommands[args[0]] ?? {};
|
|
84
|
+
args = args.slice(1);
|
|
85
|
+
}
|
|
86
|
+
const prev = before[before.length - 1];
|
|
87
|
+
const flagValue = FLAG_VALUES[prev];
|
|
88
|
+
if (flagValue && comp.flags?.includes(prev))
|
|
89
|
+
return match(await values(flagValue, env));
|
|
90
|
+
if (cur.startsWith("-"))
|
|
91
|
+
return match(comp.flags ?? []);
|
|
92
|
+
const positionals = args.filter((a, i) => !a.startsWith("-") && !(i > 0 && FLAG_VALUES[args[i - 1]]));
|
|
93
|
+
const kinds = comp.args ?? [];
|
|
94
|
+
const kind = kinds[positionals.length] ?? (kinds[kinds.length - 1] === "profile" && kinds.length === 1 && name === "profile" ? "profile" : undefined);
|
|
95
|
+
if (!kind)
|
|
96
|
+
return [];
|
|
97
|
+
if (kind === "dir")
|
|
98
|
+
return [":dir"];
|
|
99
|
+
return match(await values(kind, env));
|
|
100
|
+
}
|
|
101
|
+
export const command = {
|
|
102
|
+
summary: "completion candidates for the shell scripts",
|
|
103
|
+
usage: "Usage: turno __complete -- <words...>",
|
|
104
|
+
hidden: true,
|
|
105
|
+
async run(args, io) {
|
|
106
|
+
const words = args[0] === "--" ? args.slice(1) : args;
|
|
107
|
+
for (const c of await complete(words.length ? words : [""], io.env))
|
|
108
|
+
io.out(c);
|
|
109
|
+
return 0;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=complete.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { fail } from "../io.js";
|
|
2
|
+
const ZSH = `#compdef turno
|
|
3
|
+
# turno completion for zsh. Load it with: source <(turno completion zsh)
|
|
4
|
+
_turno() {
|
|
5
|
+
local -a out
|
|
6
|
+
out=("\${(@f)$(turno __complete -- "\${(@)words[2,CURRENT]}" 2>/dev/null)}")
|
|
7
|
+
if [[ "\${out[1]}" == ":dir" ]]; then _files -/; return; fi
|
|
8
|
+
(( \${#out} )) && [[ -n "\${out[1]}" ]] && compadd -- "\${out[@]}"
|
|
9
|
+
}
|
|
10
|
+
compdef _turno turno
|
|
11
|
+
`;
|
|
12
|
+
const BASH = `# turno completion for bash. Load it with: source <(turno completion bash)
|
|
13
|
+
_turno() {
|
|
14
|
+
local IFS=$'\\n'
|
|
15
|
+
local out=($(turno __complete -- "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
16
|
+
if [[ "\${out[0]}" == ":dir" ]]; then
|
|
17
|
+
COMPREPLY=($(compgen -d -- "\${COMP_WORDS[COMP_CWORD]}"))
|
|
18
|
+
return
|
|
19
|
+
fi
|
|
20
|
+
COMPREPLY=("\${out[@]}")
|
|
21
|
+
}
|
|
22
|
+
complete -o default -F _turno turno
|
|
23
|
+
`;
|
|
24
|
+
const FISH = `# turno completion for fish. Load it with: turno completion fish | source
|
|
25
|
+
function __turno_complete
|
|
26
|
+
set -l words (commandline -opc) (commandline -ct)
|
|
27
|
+
set -e words[1]
|
|
28
|
+
set -l out (turno __complete -- $words 2>/dev/null)
|
|
29
|
+
if test "$out[1]" = ":dir"
|
|
30
|
+
__fish_complete_directories (commandline -ct)
|
|
31
|
+
return
|
|
32
|
+
end
|
|
33
|
+
printf '%s\\n' $out
|
|
34
|
+
end
|
|
35
|
+
complete -c turno -f -a '(__turno_complete)'
|
|
36
|
+
`;
|
|
37
|
+
export const SCRIPTS = { zsh: ZSH, bash: BASH, fish: FISH };
|
|
38
|
+
export const command = {
|
|
39
|
+
summary: "shell completion for commands, profiles, identities and config keys",
|
|
40
|
+
usage: [
|
|
41
|
+
"Usage: turno completion <zsh|bash|fish>",
|
|
42
|
+
"",
|
|
43
|
+
"Prints the completion script. To load it in every shell:",
|
|
44
|
+
" zsh echo 'source <(turno completion zsh)' >> ~/.zshrc",
|
|
45
|
+
" bash echo 'source <(turno completion bash)' >> ~/.bashrc",
|
|
46
|
+
" fish turno completion fish > ~/.config/fish/completions/turno.fish",
|
|
47
|
+
].join("\n"),
|
|
48
|
+
args: ["shell"],
|
|
49
|
+
async run(args, io) {
|
|
50
|
+
const script = SCRIPTS[args[0] ?? ""];
|
|
51
|
+
if (!script || args.length > 1)
|
|
52
|
+
return fail("usage: turno completion <zsh|bash|fish>");
|
|
53
|
+
io.out(script.trimEnd());
|
|
54
|
+
return 0;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=completion.js.map
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { parse } from "smol-toml";
|
|
4
|
+
import { loadRegistry } from "../../accounts/registry.js";
|
|
5
|
+
import { editConfig, migrationPending, readConfigText } from "../../core/config-edit.js";
|
|
6
|
+
import { loadConfig } from "../../core/config.js";
|
|
7
|
+
import { Journal } from "../../core/journal.js";
|
|
8
|
+
import { loadManifest } from "../../core/manifest.js";
|
|
9
|
+
import { paths, tildify } from "../../core/paths.js";
|
|
10
|
+
import { removeValue, setValue } from "../../core/toml-edit.js";
|
|
11
|
+
import { DRY_RUN, JSON_FLAG, bool, parseFlags, printJson } from "../args.js";
|
|
12
|
+
import { group } from "../group.js";
|
|
13
|
+
import { fail, paint } from "../io.js";
|
|
14
|
+
/** Keys `config set` may change; tables of their own have their own commands. */
|
|
15
|
+
const KEYS = {
|
|
16
|
+
system: "profile the plain claude command (~/.claude) is logged into",
|
|
17
|
+
default: "profile for folders without a rule",
|
|
18
|
+
fallback: "profile used while the assigned one is exhausted",
|
|
19
|
+
icons: "auto, nerd or unicode",
|
|
20
|
+
nerd_terminals: "terminals whose font draws Nerd icons",
|
|
21
|
+
update_check: "true or false: look for new turno releases once a day",
|
|
22
|
+
"open.chrome_dir": "folder of the isolated Chrome profiles",
|
|
23
|
+
"mcpd.port": "port of the MCP gateway",
|
|
24
|
+
"profiles.<name>.color": "status line pill color",
|
|
25
|
+
"profiles.<name>.browser": "chrome or default",
|
|
26
|
+
};
|
|
27
|
+
/** Split a dotted key into its table and key. */
|
|
28
|
+
export function splitKey(key) {
|
|
29
|
+
const allowed = Object.keys(KEYS).some((k) => new RegExp(`^${k.replace(/\./g, "\\.").replace("<name>", "[a-z0-9][a-z0-9_-]*")}$`).test(key));
|
|
30
|
+
if (!allowed)
|
|
31
|
+
fail(`unknown key '${key}'. Keys: ${Object.keys(KEYS).join(", ")}`);
|
|
32
|
+
const i = key.lastIndexOf(".");
|
|
33
|
+
return i < 0 ? { table: undefined, key } : { table: key.slice(0, i), key: key.slice(i + 1) };
|
|
34
|
+
}
|
|
35
|
+
/** A command-line value as TOML: booleans, integers and [a, b] lists, else a string. */
|
|
36
|
+
export function parseValue(raw) {
|
|
37
|
+
if (raw === "true" || raw === "false")
|
|
38
|
+
return raw === "true";
|
|
39
|
+
if (/^-?\d+$/.test(raw))
|
|
40
|
+
return Number(raw);
|
|
41
|
+
if (raw.startsWith("[")) {
|
|
42
|
+
try {
|
|
43
|
+
const v = parse(`v = ${raw}`).v;
|
|
44
|
+
if (Array.isArray(v) && v.every((x) => typeof x === "string"))
|
|
45
|
+
return v;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
/* fall through */
|
|
49
|
+
}
|
|
50
|
+
fail(`invalid list ${raw} (use ["a", "b"])`);
|
|
51
|
+
}
|
|
52
|
+
return raw;
|
|
53
|
+
}
|
|
54
|
+
function lookup(doc, key) {
|
|
55
|
+
return key.split(".").reduce((v, k) => (v && typeof v === "object" ? v[k] : undefined), doc);
|
|
56
|
+
}
|
|
57
|
+
async function path(args, io) {
|
|
58
|
+
const p = parseFlags(args, JSON_FLAG, 0);
|
|
59
|
+
const env = io.env;
|
|
60
|
+
const pp = paths(env);
|
|
61
|
+
const files = { config: pp.configFile, mcp: pp.mcpFile, accounts: pp.accountsFile, state: pp.state, backups: pp.backupsDir };
|
|
62
|
+
if (bool(p, "json")) {
|
|
63
|
+
printJson(io.out, Object.fromEntries(Object.entries(files).map(([k, v]) => [k, { path: tildify(v, env), exists: existsSync(v) }])));
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
for (const [k, v] of Object.entries(files))
|
|
67
|
+
io.out(`${k.padEnd(9)} ${tildify(v, env)}${existsSync(v) ? "" : paint(io, " (not there yet)", "2")}`);
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
async function get(args, io) {
|
|
71
|
+
const p = parseFlags(args, JSON_FLAG, 1);
|
|
72
|
+
const key = p.positionals[0];
|
|
73
|
+
const text = readConfigText(io.env);
|
|
74
|
+
loadConfig(io.env); // report a broken file before reading from it
|
|
75
|
+
const doc = parse(text);
|
|
76
|
+
const v = key ? lookup(doc, key) : doc;
|
|
77
|
+
if (v === undefined) {
|
|
78
|
+
if (!key)
|
|
79
|
+
return 0;
|
|
80
|
+
io.err(`${key} is not set`);
|
|
81
|
+
return 1;
|
|
82
|
+
}
|
|
83
|
+
if (bool(p, "json") || typeof v === "object")
|
|
84
|
+
printJson(io.out, v);
|
|
85
|
+
else
|
|
86
|
+
io.out(String(v));
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
async function set(args, io) {
|
|
90
|
+
const p = parseFlags(args, DRY_RUN, 2);
|
|
91
|
+
const [key, raw] = p.positionals;
|
|
92
|
+
if (!key || raw === undefined)
|
|
93
|
+
return fail("usage: turno config set <key> <value>");
|
|
94
|
+
const k = splitKey(key);
|
|
95
|
+
const dry = bool(p, "dry-run");
|
|
96
|
+
const journal = new Journal(io.env, `config set ${key}`, dry);
|
|
97
|
+
const { changed } = editConfig(io.env, journal, (t) => setValue(t, k.table, k.key, parseValue(raw)));
|
|
98
|
+
io.out(`${key} = ${JSON.stringify(parseValue(raw))}${changed ? "" : " (unchanged)"}${dry ? " (dry run)" : ""}`);
|
|
99
|
+
if (journal.hint())
|
|
100
|
+
io.out(journal.hint());
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
async function unset(args, io) {
|
|
104
|
+
const p = parseFlags(args, DRY_RUN, 1);
|
|
105
|
+
const key = p.positionals[0];
|
|
106
|
+
if (!key)
|
|
107
|
+
return fail("usage: turno config unset <key>");
|
|
108
|
+
const k = splitKey(key);
|
|
109
|
+
const journal = new Journal(io.env, `config unset ${key}`, bool(p, "dry-run"));
|
|
110
|
+
const { changed } = editConfig(io.env, journal, (t) => removeValue(t, k.table, k.key));
|
|
111
|
+
io.out(changed ? `${key} removed${bool(p, "dry-run") ? " (dry run)" : ""}` : `${key} was not set`);
|
|
112
|
+
if (journal.hint())
|
|
113
|
+
io.out(journal.hint());
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
async function edit(args, io) {
|
|
117
|
+
parseFlags(args, {}, 0);
|
|
118
|
+
if (migrationPending(io.env))
|
|
119
|
+
fail("run turno migrate first: it writes config.toml from the bash config");
|
|
120
|
+
const file = paths(io.env).configFile;
|
|
121
|
+
const editor = io.env.VISUAL || io.env.EDITOR || "vi";
|
|
122
|
+
const journal = new Journal(io.env, "config edit");
|
|
123
|
+
journal.save(file);
|
|
124
|
+
const r = spawnSync("/bin/sh", ["-c", `${editor} "$1"`, "sh", file], { stdio: "inherit", env: io.env });
|
|
125
|
+
journal.settle(file);
|
|
126
|
+
if (r.status !== 0)
|
|
127
|
+
io.err(`${editor} exited with ${r.status ?? r.signal}`);
|
|
128
|
+
return check([], io);
|
|
129
|
+
}
|
|
130
|
+
/** Parse config.toml, mcp.toml and accounts.toml; exit 1 when one is broken. */
|
|
131
|
+
async function check(args, io) {
|
|
132
|
+
parseFlags(args, {}, 0);
|
|
133
|
+
const pp = paths(io.env);
|
|
134
|
+
let failed = 0;
|
|
135
|
+
const one = (file, load) => {
|
|
136
|
+
if (!existsSync(file)) {
|
|
137
|
+
io.out(`${paint(io, "none", "2")} ${tildify(file, io.env)}`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
load();
|
|
142
|
+
io.out(`${paint(io, "ok ", "32")} ${tildify(file, io.env)}`);
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
failed++;
|
|
146
|
+
io.out(`${paint(io, "FAIL", "31")} ${err.message}`);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
one(pp.configFile, () => loadConfig(io.env));
|
|
150
|
+
one(pp.mcpFile, () => loadManifest(io.env));
|
|
151
|
+
one(pp.accountsFile, () => loadRegistry(io.env));
|
|
152
|
+
return failed ? 1 : 0;
|
|
153
|
+
}
|
|
154
|
+
export const command = group("config", "read and change config.toml without losing its comments; check every config file", {
|
|
155
|
+
path: { summary: "where each config and state file lives", synopsis: "[--json]", flags: ["--json"], run: path },
|
|
156
|
+
get: { summary: "print a value (the whole file as JSON without a key)", synopsis: "[key] [--json]", args: ["key"], flags: ["--json"], run: get },
|
|
157
|
+
set: { summary: "set a value; the file must still parse", synopsis: "<key> <value> [--dry-run]", args: ["key", "any"], flags: ["--dry-run"], run: set },
|
|
158
|
+
unset: { summary: "remove a value", synopsis: "<key> [--dry-run]", args: ["key"], flags: ["--dry-run"], run: unset },
|
|
159
|
+
edit: { summary: "open config.toml in $VISUAL or $EDITOR, then check it", run: edit },
|
|
160
|
+
check: { summary: "parse config.toml, mcp.toml and accounts.toml", run: check },
|
|
161
|
+
}, {
|
|
162
|
+
fallback: "path",
|
|
163
|
+
footer: `Keys:\n${Object.entries(KEYS)
|
|
164
|
+
.map(([k, d]) => ` ${k.padEnd(26)} ${d}`)
|
|
165
|
+
.join("\n")}\n\nProjects use turno profile assign; MCP servers live in mcp.toml (turno mcp).`,
|
|
166
|
+
});
|
|
167
|
+
export const CONFIG_KEYS = Object.keys(KEYS);
|
|
168
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, readlinkSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { loadRegistry } from "../../accounts/registry.js";
|
|
4
|
+
import { migrationPending } from "../../core/config-edit.js";
|
|
5
|
+
import { loadConfig } from "../../core/config.js";
|
|
6
|
+
import { loadManifest } from "../../core/manifest.js";
|
|
7
|
+
import { paths, profileDir, tildify } from "../../core/paths.js";
|
|
8
|
+
import { adapter, agentHub, agentProfileDir } from "../../agents/index.js";
|
|
9
|
+
import { agentOf, listProfiles } from "../../core/profiles.js";
|
|
10
|
+
import { availableUpdate } from "../../core/update.js";
|
|
11
|
+
import { packageInfo } from "../../core/version.js";
|
|
12
|
+
import { FALLBACK, checkFonts, userFontDir } from "../../ui/fonts.js";
|
|
13
|
+
import { currentStatusLine, isTurnoStatusLine } from "../../ui/settings.js";
|
|
14
|
+
import { JSON_FLAG, bool, parseFlags, printJson } from "../args.js";
|
|
15
|
+
import { paint } from "../io.js";
|
|
16
|
+
import { findOnPath } from "../launch.js";
|
|
17
|
+
import { MARKER, isGenerated, launcherName, launcherText } from "../launchers.js";
|
|
18
|
+
import { parse as parseToml } from "smol-toml";
|
|
19
|
+
/** Whether a file is the original bash claudio script rather than this CLI. */
|
|
20
|
+
export function isLegacyScript(file) {
|
|
21
|
+
try {
|
|
22
|
+
if (lstatSync(file).isSymbolicLink() && readlinkSync(file).endsWith(".js"))
|
|
23
|
+
return false;
|
|
24
|
+
const head = readFileSync(file, "utf8").slice(0, 400);
|
|
25
|
+
return head.startsWith("#!/bin/bash") && head.includes("turno");
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export async function mcpdStatus(env, config) {
|
|
32
|
+
const p = paths(env);
|
|
33
|
+
let port = config?.mcpd.port ?? 47821;
|
|
34
|
+
try {
|
|
35
|
+
const n = Number.parseInt(readFileSync(p.mcpdPort, "utf8").trim(), 10);
|
|
36
|
+
if (Number.isInteger(n) && n > 0)
|
|
37
|
+
port = n;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// no port file: the configured port
|
|
41
|
+
}
|
|
42
|
+
let token;
|
|
43
|
+
try {
|
|
44
|
+
token = readFileSync(p.mcpdToken, "utf8").trim();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return { level: "info", running: false, port, text: `mcpd: no token at ${tildify(p.mcpdToken, env)} (not started yet: turno mcp daemon start)` };
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const res = await fetch(`http://127.0.0.1:${port}/status`, {
|
|
51
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
52
|
+
signal: AbortSignal.timeout(2000),
|
|
53
|
+
});
|
|
54
|
+
if (!res.ok)
|
|
55
|
+
return { level: "warn", running: false, port, text: `mcpd on port ${port} answered HTTP ${res.status}` };
|
|
56
|
+
return { level: "ok", running: true, port, text: `mcpd reachable on port ${port}` };
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return { level: "info", running: false, port, text: `mcpd not reachable on port ${port} (turno mcp daemon start)` };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const repair = (name) => ({
|
|
63
|
+
label: `turno profile repair ${name}`,
|
|
64
|
+
run: async (io) => (await import("./setup.js")).setupProfiles([name], io),
|
|
65
|
+
});
|
|
66
|
+
function isLinkTo(path, target) {
|
|
67
|
+
try {
|
|
68
|
+
return lstatSync(path).isSymbolicLink() && readlinkSync(path) === target;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function lexists(path) {
|
|
75
|
+
try {
|
|
76
|
+
lstatSync(path);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Launcher, folder, hub links and command of a profile of another agent (ADR 0013). */
|
|
84
|
+
async function agentProfileChecks(name, agent, env) {
|
|
85
|
+
const a = adapter(agent);
|
|
86
|
+
const area = `profile ${name}`;
|
|
87
|
+
const out = [];
|
|
88
|
+
const launcher = join(paths(env).bin, launcherName(name, agent));
|
|
89
|
+
if (!existsSync(launcher))
|
|
90
|
+
out.push({ area, level: "fail", text: `profile ${name}: no launcher ${tildify(launcher, env)}`, fix: repair(name) });
|
|
91
|
+
else if (!isGenerated(launcher))
|
|
92
|
+
out.push({ area, level: "fail", text: `profile ${name}: ${tildify(launcher, env)} was not generated by turno` });
|
|
93
|
+
else if (readFileSync(launcher, "utf8") !== launcherText(name, env, agent))
|
|
94
|
+
out.push({ area, level: "warn", text: `profile ${name}: launcher is out of date`, fix: repair(name) });
|
|
95
|
+
else
|
|
96
|
+
out.push({ area, level: "ok", text: `profile ${name}: ${a.label} launcher ok` });
|
|
97
|
+
const dir = agentProfileDir(name, agent, env);
|
|
98
|
+
if (!existsSync(dir)) {
|
|
99
|
+
out.push({ area, level: "fail", text: `profile ${name}: ${tildify(dir, env)} does not exist`, fix: repair(name) });
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
const hub = agentHub(agent, env);
|
|
103
|
+
for (const item of [...a.sharedDirs, ...a.sharedFiles]) {
|
|
104
|
+
const path = join(dir, item);
|
|
105
|
+
const target = join(hub, item);
|
|
106
|
+
if (isLinkTo(path, target))
|
|
107
|
+
continue;
|
|
108
|
+
if (existsSync(path))
|
|
109
|
+
out.push({ area, level: "warn", text: `profile ${name}: ${item} is a local copy, not shared`, fix: repair(name) });
|
|
110
|
+
else if (existsSync(target))
|
|
111
|
+
out.push({ area, level: "warn", text: `profile ${name}: missing link for ${item}`, fix: repair(name) });
|
|
112
|
+
}
|
|
113
|
+
if (agent === "codex") {
|
|
114
|
+
let store;
|
|
115
|
+
try {
|
|
116
|
+
store = parseToml(readFileSync(join(dir, "config.toml"), "utf8")).cli_auth_credentials_store;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
store = undefined;
|
|
120
|
+
}
|
|
121
|
+
if (store !== "file")
|
|
122
|
+
out.push({ area, level: "warn", text: `profile ${name}: Codex may keep the login in the shared Keychain (cli_auth_credentials_store is not "file")`, fix: repair(name) });
|
|
123
|
+
}
|
|
124
|
+
if (!findOnPath(a.command, env))
|
|
125
|
+
out.push({ area, level: "warn", text: `profile ${name}: ${a.command} is not on PATH (${a.install})` });
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
/** Shared links and unclassified items of one profile folder. */
|
|
129
|
+
async function profileChecks(name, env) {
|
|
130
|
+
const { PER_ACCOUNT, SHARED_DIRS, SHARED_FILES } = await import("./setup.js");
|
|
131
|
+
const p = paths(env);
|
|
132
|
+
const dir = profileDir(name, env);
|
|
133
|
+
const out = [];
|
|
134
|
+
const area = `profile ${name}`;
|
|
135
|
+
const launcher = join(p.bin, `claude-${name}`);
|
|
136
|
+
if (!existsSync(launcher))
|
|
137
|
+
out.push({ area, level: "fail", text: `profile ${name}: no launcher ${tildify(launcher, env)}`, fix: repair(name) });
|
|
138
|
+
else if (!isGenerated(launcher))
|
|
139
|
+
out.push({ area, level: "fail", text: `profile ${name}: ${tildify(launcher, env)} was not generated by turno` });
|
|
140
|
+
else if (!readFileSync(launcher, "utf8").includes(MARKER))
|
|
141
|
+
out.push({ area, level: "warn", text: `profile ${name}: launcher from the bash claudio`, fix: repair(name) });
|
|
142
|
+
else
|
|
143
|
+
out.push({ area, level: "ok", text: `profile ${name}: launcher ok` });
|
|
144
|
+
if (!existsSync(dir)) {
|
|
145
|
+
out.push({ area, level: "fail", text: `profile ${name}: ${tildify(dir, env)} does not exist`, fix: repair(name) });
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
const shared = [...SHARED_DIRS, ...SHARED_FILES];
|
|
149
|
+
const problems = [];
|
|
150
|
+
for (const item of shared) {
|
|
151
|
+
const path = join(dir, item);
|
|
152
|
+
const target = join(p.hub, item);
|
|
153
|
+
if (isLinkTo(path, target))
|
|
154
|
+
continue;
|
|
155
|
+
if (existsSync(path))
|
|
156
|
+
problems.push(`${item} is a local copy, not shared`);
|
|
157
|
+
else if (existsSync(target))
|
|
158
|
+
problems.push(`missing link for ${item}`);
|
|
159
|
+
}
|
|
160
|
+
for (const pr of problems)
|
|
161
|
+
out.push({ area, level: "warn", text: `profile ${name}: ${pr}`, fix: repair(name) });
|
|
162
|
+
const known = new Set([...shared, ...PER_ACCOUNT]);
|
|
163
|
+
let entries = [];
|
|
164
|
+
try {
|
|
165
|
+
entries = readdirSync(dir).sort();
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
entries = [];
|
|
169
|
+
}
|
|
170
|
+
for (const item of entries) {
|
|
171
|
+
if (known.has(item) || !lexists(join(dir, item)))
|
|
172
|
+
continue;
|
|
173
|
+
if (/^(\.aside-|\.aparte-|\.claude\.json\.|history\.jsonl\.)/.test(item))
|
|
174
|
+
continue;
|
|
175
|
+
out.push({ area, level: "info", text: `profile ${name}: ${item} is new and unclassified: decide whether to share it` });
|
|
176
|
+
}
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
export async function collectChecks(env) {
|
|
180
|
+
const p = paths(env);
|
|
181
|
+
const checks = [];
|
|
182
|
+
const add = (area, level, text, fix) => checks.push({ area, level, text, ...(fix ? { fix } : {}) });
|
|
183
|
+
const major = Number(process.versions.node.split(".")[0]);
|
|
184
|
+
add("system", major >= 20 ? "ok" : "fail", `node ${process.versions.node}${major >= 20 ? "" : " (turno needs >= 20)"}`);
|
|
185
|
+
const claude = findOnPath("claude", env);
|
|
186
|
+
add("system", claude ? "ok" : "fail", claude ? `claude at ${tildify(claude, env)}` : "claude not found on PATH");
|
|
187
|
+
const chrome = env.TURNO_CHROME_APP || "/Applications/Google Chrome.app";
|
|
188
|
+
add("system", existsSync(chrome) ? "ok" : "warn", existsSync(chrome) ? "Google Chrome installed" : "Google Chrome not found: claude.ai links open in the default browser");
|
|
189
|
+
const { recordedVersion, finishUpgrade } = await import("./upgrade.js");
|
|
190
|
+
const version = packageInfo().version;
|
|
191
|
+
const recorded = recordedVersion(env);
|
|
192
|
+
if (recorded && recorded !== version) {
|
|
193
|
+
add("turno", "warn", `turno ${version} runs, but ${recorded} set up the launchers`, { label: "turno upgrade --finish", run: (io) => finishUpgrade(io) });
|
|
194
|
+
}
|
|
195
|
+
else
|
|
196
|
+
add("turno", "ok", `turno ${version}`);
|
|
197
|
+
const newer = availableUpdate(env);
|
|
198
|
+
if (newer)
|
|
199
|
+
add("turno", "info", `turno ${newer} is available (turno upgrade)`);
|
|
200
|
+
let config;
|
|
201
|
+
try {
|
|
202
|
+
config = loadConfig(env);
|
|
203
|
+
if (existsSync(p.configFile))
|
|
204
|
+
add("config", "ok", `${tildify(p.configFile, env)} parses`);
|
|
205
|
+
else if (migrationPending(env))
|
|
206
|
+
add("config", "info", `no ${tildify(p.configFile, env)} yet: turno migrate imports the bash config`);
|
|
207
|
+
else
|
|
208
|
+
add("config", "info", `no ${tildify(p.configFile, env)} (defaults)`);
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
add("config", "fail", err.message);
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const m = loadManifest(env);
|
|
215
|
+
if (existsSync(p.mcpFile))
|
|
216
|
+
add("config", "ok", `${tildify(p.mcpFile, env)} parses (${Object.keys(m.servers).length} servers)`);
|
|
217
|
+
else
|
|
218
|
+
add("config", "info", `no ${tildify(p.mcpFile, env)} yet (turno mcp import)`);
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
add("config", "fail", err.message);
|
|
222
|
+
}
|
|
223
|
+
if (existsSync(p.accountsFile)) {
|
|
224
|
+
try {
|
|
225
|
+
loadRegistry(env);
|
|
226
|
+
add("config", "ok", `${tildify(p.accountsFile, env)} parses`);
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
add("config", "fail", err.message);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (config) {
|
|
233
|
+
const profiles = listProfiles(config, env);
|
|
234
|
+
if (profiles.length === 0)
|
|
235
|
+
add("profiles", "info", "no profiles yet (turno profile add <name>)");
|
|
236
|
+
for (const name of profiles) {
|
|
237
|
+
const agent = agentOf(name, config);
|
|
238
|
+
checks.push(...(agent === "claude" ? await profileChecks(name, env) : await agentProfileChecks(name, agent, env)));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const legacyBin = join(p.bin, "claudio");
|
|
242
|
+
if (isLegacyScript(legacyBin))
|
|
243
|
+
add("turno", "info", `${tildify(legacyBin, env)} is still the bash claudio (the cutover points it at turno)`);
|
|
244
|
+
try {
|
|
245
|
+
const { bypassingServers } = await import("./mcp.js");
|
|
246
|
+
const b = await bypassingServers(env);
|
|
247
|
+
for (const s of b.plugins)
|
|
248
|
+
add("mcp", "info", `plugin server ${s.plugin}/${s.name} starts in every session (turno mcp doctor)`);
|
|
249
|
+
for (const d of b.direct)
|
|
250
|
+
add("mcp", "warn", `${d.name} runs outside mcpd (${d.inManifest ? "turno mcp sync" : "turno mcp import"})`);
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
/* a broken mcp.toml is reported above */
|
|
254
|
+
}
|
|
255
|
+
const settings = join(p.hub, "settings.json");
|
|
256
|
+
const line = currentStatusLine(settings);
|
|
257
|
+
if (isTurnoStatusLine(line))
|
|
258
|
+
add("look", "ok", "status line: turno statusline");
|
|
259
|
+
else
|
|
260
|
+
add("look", "info", `status line: ${line ? `\`${line.command}\`` : "none"} in ${tildify(settings, env)} (turno ui install)`);
|
|
261
|
+
const fontDir = userFontDir(env);
|
|
262
|
+
if (fontDir) {
|
|
263
|
+
const fonts = checkFonts(FALLBACK, fontDir);
|
|
264
|
+
const have = fonts.filter((f) => f.state === "installed").length;
|
|
265
|
+
if (have === fonts.length)
|
|
266
|
+
add("look", "ok", `font: ${FALLBACK.family} installed`);
|
|
267
|
+
else
|
|
268
|
+
add("look", "info", `font: ${FALLBACK.family} ${have}/${fonts.length} files in ${tildify(fontDir, env)} (turno ui install)`);
|
|
269
|
+
}
|
|
270
|
+
const mcpd = await mcpdStatus(env, config);
|
|
271
|
+
add("mcpd", mcpd.level, mcpd.text);
|
|
272
|
+
return checks;
|
|
273
|
+
}
|
|
274
|
+
function report(io, c) {
|
|
275
|
+
const tag = { ok: paint(io, "ok ", "32"), warn: paint(io, "warn", "33"), fail: paint(io, "FAIL", "31"), info: paint(io, "info", "2") }[c.level];
|
|
276
|
+
io.out(`${tag} ${c.text}${c.fix && c.level !== "ok" ? paint(io, ` [fix: ${c.fix.label}]`, "2") : ""}`);
|
|
277
|
+
}
|
|
278
|
+
export async function doctor(io, opts = {}) {
|
|
279
|
+
let checks = await collectChecks(io.env);
|
|
280
|
+
if (opts.fix) {
|
|
281
|
+
const fixes = new Map();
|
|
282
|
+
for (const c of checks)
|
|
283
|
+
if (c.fix && (c.level === "warn" || c.level === "fail"))
|
|
284
|
+
fixes.set(c.fix.label, c.fix);
|
|
285
|
+
for (const f of fixes.values()) {
|
|
286
|
+
if (!opts.json)
|
|
287
|
+
io.out(paint(io, `$ ${f.label}`, "1"));
|
|
288
|
+
await f.run(opts.json ? { ...io, out: () => { } } : io);
|
|
289
|
+
}
|
|
290
|
+
if (fixes.size) {
|
|
291
|
+
if (!opts.json)
|
|
292
|
+
io.out("");
|
|
293
|
+
checks = await collectChecks(io.env);
|
|
294
|
+
}
|
|
295
|
+
else if (!opts.json)
|
|
296
|
+
io.out("Nothing to fix automatically.\n");
|
|
297
|
+
}
|
|
298
|
+
const failed = checks.some((c) => c.level === "fail");
|
|
299
|
+
if (opts.json) {
|
|
300
|
+
printJson(io.out, { ok: !failed, checks: checks.map(({ fix, ...c }) => ({ ...c, fix: fix?.label ?? null })) });
|
|
301
|
+
return failed ? 1 : 0;
|
|
302
|
+
}
|
|
303
|
+
for (const c of checks)
|
|
304
|
+
report(io, c);
|
|
305
|
+
const fixable = checks.filter((c) => c.fix && (c.level === "warn" || c.level === "fail")).length;
|
|
306
|
+
if (fixable && !opts.fix)
|
|
307
|
+
io.out(`\n${fixable} can be fixed with: turno doctor --fix`);
|
|
308
|
+
return failed ? 1 : 0;
|
|
309
|
+
}
|
|
310
|
+
export const command = {
|
|
311
|
+
summary: "check everything (system, config, profiles, MCP, look, mcpd) and fix what is safe to fix",
|
|
312
|
+
usage: [
|
|
313
|
+
"Usage: turno doctor [--fix] [--json]",
|
|
314
|
+
"",
|
|
315
|
+
"Exits 1 when a hard check fails. --fix runs the repair each failed check names (relink a",
|
|
316
|
+
"profile, rewrite launchers, finish an upgrade), then checks again.",
|
|
317
|
+
].join("\n"),
|
|
318
|
+
flags: ["--fix", "--json"],
|
|
319
|
+
async run(args, io) {
|
|
320
|
+
const p = parseFlags(args, { fix: { type: "boolean" }, ...JSON_FLAG }, 0);
|
|
321
|
+
return doctor(io, { fix: bool(p, "fix"), json: bool(p, "json") });
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
//# sourceMappingURL=doctor.js.map
|