turno-cli 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +432 -0
- package/README.md +228 -73
- package/dist/accounts/audit.js +154 -12
- package/dist/accounts/builtin.js +100 -25
- package/dist/accounts/delegate.js +199 -35
- package/dist/accounts/policy.js +79 -0
- package/dist/accounts/registry.js +39 -21
- package/dist/agents/adapter.js +29 -0
- package/dist/agents/claude.js +246 -0
- package/dist/agents/codex.js +186 -0
- package/dist/agents/copilot.js +56 -0
- package/dist/agents/cursor.js +58 -0
- package/dist/agents/index.js +26 -86
- package/dist/agents/snippets.js +43 -13
- package/dist/cli/args.js +38 -6
- package/dist/cli/commands/accounts.js +119 -52
- package/dist/cli/commands/auto.js +121 -33
- package/dist/cli/commands/browser-identity.js +514 -0
- package/dist/cli/commands/browser-session.js +102 -0
- package/dist/cli/commands/browser-vault.js +193 -0
- package/dist/cli/commands/browser.js +319 -138
- package/dist/cli/commands/complete.js +14 -3
- package/dist/cli/commands/completion.js +8 -2
- package/dist/cli/commands/config.js +186 -24
- package/dist/cli/commands/demo.js +321 -0
- package/dist/cli/commands/doctor.js +525 -123
- package/dist/cli/commands/handoff.js +33 -22
- package/dist/cli/commands/identity.js +192 -54
- package/dist/cli/commands/init.js +648 -0
- package/dist/cli/commands/limit.js +84 -16
- package/dist/cli/commands/mcp-call.js +240 -0
- package/dist/cli/commands/mcp-oauth.js +221 -0
- package/dist/cli/commands/mcp-observe.js +539 -0
- package/dist/cli/commands/mcp-share.js +201 -0
- package/dist/cli/commands/mcp.js +816 -187
- package/dist/cli/commands/mcpd.js +388 -76
- package/dist/cli/commands/migrate.js +6 -4
- package/dist/cli/commands/open.js +115 -27
- package/dist/cli/commands/profile.js +396 -78
- package/dist/cli/commands/resolve.js +14 -3
- package/dist/cli/commands/run.js +36 -6
- package/dist/cli/commands/secret.js +80 -76
- package/dist/cli/commands/session.js +17 -6
- package/dist/cli/commands/sessions.js +48 -12
- package/dist/cli/commands/setup.js +214 -164
- package/dist/cli/commands/status.js +227 -44
- package/dist/cli/commands/statusline.js +311 -114
- package/dist/cli/commands/ui.js +78 -68
- package/dist/cli/commands/undo.js +193 -18
- package/dist/cli/commands/uninstall.js +481 -0
- package/dist/cli/commands/upgrade.js +172 -79
- package/dist/cli/commands/usage.js +125 -51
- package/dist/cli/commands/version.js +21 -7
- package/dist/cli/commands/which.js +9 -24
- package/dist/cli/compile-cache.js +32 -0
- package/dist/cli/diagnostics.js +184 -0
- package/dist/cli/exit.js +65 -0
- package/dist/cli/group.js +24 -12
- package/dist/cli/help.js +62 -0
- package/dist/cli/highlight.js +236 -0
- package/dist/cli/hints.js +30 -0
- package/dist/cli/io.js +186 -1
- package/dist/cli/launch.js +52 -39
- package/dist/cli/launchers.js +161 -95
- package/dist/cli/main.js +201 -31
- package/dist/cli/optional.js +144 -0
- package/dist/cli/output.js +123 -0
- package/dist/cli/picker.js +459 -0
- package/dist/cli/registry.js +61 -6
- package/dist/cli/safe.js +87 -0
- package/dist/cli/secret-input.js +63 -0
- package/dist/cli/security.js +561 -0
- package/dist/cli/style.js +311 -0
- package/dist/cli/topics.js +142 -0
- package/dist/core/config.js +181 -23
- package/dist/core/exhausted.js +6 -8
- package/dist/core/fsutil.js +39 -0
- package/dist/core/journal.js +294 -16
- package/dist/core/manifest.js +153 -6
- package/dist/core/paths.js +14 -13
- package/dist/core/profiles.js +160 -10
- package/dist/core/resolve.js +139 -23
- package/dist/core/secrets.js +68 -23
- package/dist/core/sessions.js +13 -20
- package/dist/core/state-file.js +107 -0
- package/dist/core/update.js +31 -18
- package/dist/core/version.js +57 -10
- package/dist/demo/server.js +42 -0
- package/dist/mcpd/cache.js +23 -10
- package/dist/mcpd/calllog.js +254 -0
- package/dist/mcpd/client-names.js +46 -0
- package/dist/mcpd/connectors.js +188 -18
- package/dist/mcpd/daemon.js +472 -115
- package/dist/mcpd/folder-sets.js +42 -0
- package/dist/mcpd/gateway.js +473 -51
- package/dist/mcpd/health.js +313 -0
- package/dist/mcpd/importer.js +453 -36
- package/dist/mcpd/instances.js +453 -65
- package/dist/mcpd/jsonrpc.js +11 -1
- package/dist/mcpd/launchd.js +65 -48
- package/dist/mcpd/middleware.js +144 -0
- package/dist/mcpd/modern.js +686 -0
- package/dist/mcpd/oauth.js +845 -0
- package/dist/mcpd/peerpid.js +134 -6
- package/dist/mcpd/pressure.js +88 -0
- package/dist/mcpd/rss.js +166 -0
- package/dist/mcpd/service.js +191 -0
- package/dist/mcpd/share.js +217 -0
- package/dist/mcpd/state.js +183 -0
- package/dist/mcpd/sync.js +72 -87
- package/dist/mcpd/systemd.js +83 -0
- package/dist/mcpd/tokens.js +85 -0
- package/dist/mcpd/upstream.js +163 -46
- package/dist/statusline/cost.js +167 -44
- package/dist/statusline/input.js +78 -0
- package/dist/statusline/render.js +9 -3
- package/dist/ui/fonts.js +8 -3
- package/dist/ui/settings.js +33 -16
- package/npm-shrinkwrap.json +1102 -0
- package/package.json +10 -9
- package/dist/cli/commands/available.js +0 -18
|
@@ -1,55 +1,63 @@
|
|
|
1
|
-
import { chmodSync,
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { adapter, agentHub, agentProfileDir } from "../../agents/index.js";
|
|
1
|
+
import { chmodSync, existsSync, lstatSync, mkdirSync, readdirSync, readlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, resolve as resolvePath } from "node:path";
|
|
3
|
+
import { DEFAULT_AGENT, adapter, agentHub, agentProfileDir } from "../../agents/index.js";
|
|
4
4
|
import { isValidProfileName, loadConfig } from "../../core/config.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { Journal, stamp } from "../../core/journal.js";
|
|
6
|
+
import { expandHome, tildify } from "../../core/paths.js";
|
|
7
7
|
import { agentOf } from "../../core/profiles.js";
|
|
8
8
|
import { profileBusy } from "../../core/sessions.js";
|
|
9
|
-
import { fail } from "../io.js";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
/** Hub files shared by every profile (linked only when they exist in the hub). */
|
|
13
|
-
export const SHARED_FILES = ["CLAUDE.md", "settings.json", "keybindings.json", "statusline-command.sh", ".mcp.json"];
|
|
14
|
-
/**
|
|
15
|
-
* Owned by each account and never linked. history.jsonl cannot be a symlink: Claude Code
|
|
16
|
-
* ignores it unless it is a regular file with a single link.
|
|
17
|
-
*/
|
|
18
|
-
export const PER_ACCOUNT = [
|
|
19
|
-
".claude.json",
|
|
20
|
-
".credentials.json",
|
|
21
|
-
"history.jsonl",
|
|
22
|
-
"backups",
|
|
23
|
-
"daemon",
|
|
24
|
-
"daemon.log",
|
|
25
|
-
"daemon-auth-cooldown",
|
|
26
|
-
"daemon-auth-status.json",
|
|
27
|
-
"daemon.lock",
|
|
28
|
-
"daemon.status.json",
|
|
29
|
-
"feedback",
|
|
30
|
-
"jobs",
|
|
31
|
-
"policy-limits.json",
|
|
32
|
-
"policy-limits.json.stamp.json",
|
|
33
|
-
"policy-limits.json.signature.json",
|
|
34
|
-
"remote-settings.json",
|
|
35
|
-
"remote-settings.json.signature.json",
|
|
36
|
-
"remote-settings.json.synced-at",
|
|
37
|
-
"mcp-needs-auth-cache.json",
|
|
38
|
-
"stats-cache.json",
|
|
39
|
-
"telemetry",
|
|
40
|
-
"shell-snapshots",
|
|
41
|
-
"debug",
|
|
42
|
-
".last-cleanup",
|
|
43
|
-
".last-update-result.json",
|
|
44
|
-
"computer-use.lock",
|
|
45
|
-
];
|
|
9
|
+
import { fail, plural } from "../io.js";
|
|
10
|
+
import { style } from "../style.js";
|
|
11
|
+
import { launcherName, refuseNpx, resolveTurnoCommand, writeHelperLaunchers, writeLauncher } from "../launchers.js";
|
|
46
12
|
/** Names a profile cannot take: every command, alias and legacy word. */
|
|
47
13
|
export const RESERVED = new Set([
|
|
48
|
-
"auto",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
14
|
+
"auto",
|
|
15
|
+
"which",
|
|
16
|
+
"resolve",
|
|
17
|
+
"sessions",
|
|
18
|
+
"usage",
|
|
19
|
+
"exhausted",
|
|
20
|
+
"available",
|
|
21
|
+
"hook",
|
|
22
|
+
"setup",
|
|
23
|
+
"status",
|
|
24
|
+
"open",
|
|
25
|
+
"migrate",
|
|
26
|
+
"doctor",
|
|
27
|
+
"statusline",
|
|
28
|
+
"handoff",
|
|
29
|
+
"mcp",
|
|
30
|
+
"mcpd",
|
|
31
|
+
"secret",
|
|
32
|
+
"accounts",
|
|
33
|
+
"browser",
|
|
34
|
+
"ui",
|
|
35
|
+
"help",
|
|
36
|
+
"version",
|
|
37
|
+
"cuenta",
|
|
38
|
+
"resolver",
|
|
39
|
+
"sesiones",
|
|
40
|
+
"uso",
|
|
41
|
+
"agotada",
|
|
42
|
+
"disponible",
|
|
43
|
+
"limite",
|
|
44
|
+
"abrir",
|
|
45
|
+
"sync-mcp",
|
|
46
|
+
"profile",
|
|
47
|
+
"navegador",
|
|
48
|
+
"run",
|
|
49
|
+
"limit",
|
|
50
|
+
"session",
|
|
51
|
+
"identity",
|
|
52
|
+
"config",
|
|
53
|
+
"undo",
|
|
54
|
+
"upgrade",
|
|
55
|
+
"completion",
|
|
56
|
+
"__complete",
|
|
57
|
+
"__update-check",
|
|
58
|
+
"uninstall",
|
|
59
|
+
"init",
|
|
60
|
+
"demo",
|
|
53
61
|
]);
|
|
54
62
|
export function checkName(name) {
|
|
55
63
|
if (!isValidProfileName(name))
|
|
@@ -57,8 +65,6 @@ export function checkName(name) {
|
|
|
57
65
|
if (RESERVED.has(name))
|
|
58
66
|
fail(`'${name}' is reserved`);
|
|
59
67
|
}
|
|
60
|
-
export { stamp } from "../../core/journal.js";
|
|
61
|
-
import { stamp } from "../../core/journal.js";
|
|
62
68
|
function lstat(path) {
|
|
63
69
|
try {
|
|
64
70
|
return lstatSync(path);
|
|
@@ -67,150 +73,194 @@ function lstat(path) {
|
|
|
67
73
|
return undefined;
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
|
-
/**
|
|
71
|
-
function
|
|
76
|
+
/** True when `path` holds the person's own data: a file, or a folder that is not empty. */
|
|
77
|
+
function ownCopy(path) {
|
|
78
|
+
const st = lstat(path);
|
|
79
|
+
if (!st || st.isSymbolicLink())
|
|
80
|
+
return false;
|
|
81
|
+
if (st.isDirectory())
|
|
82
|
+
return readdirSync(path).length > 0;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Make <dir>/<item> a symlink to the hub, moving a local copy aside. Every step goes through
|
|
87
|
+
* the journal, so `turno undo` removes the link and moves the copy back.
|
|
88
|
+
*/
|
|
89
|
+
function linkItem(dir, item, aside, journal, hub) {
|
|
72
90
|
const target = join(hub, item);
|
|
73
91
|
const path = join(dir, item);
|
|
74
92
|
const st = lstat(path);
|
|
93
|
+
let result = "linked";
|
|
75
94
|
if (st?.isSymbolicLink()) {
|
|
76
95
|
if (readlinkSync(path) === target)
|
|
77
|
-
return;
|
|
78
|
-
|
|
96
|
+
return "same";
|
|
97
|
+
journal.unlink(path);
|
|
79
98
|
}
|
|
80
99
|
else if (st?.isDirectory() && readdirSync(path).length === 0) {
|
|
81
|
-
|
|
100
|
+
journal.rmdir(path);
|
|
82
101
|
}
|
|
83
102
|
else if (st) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
103
|
+
journal.mkdir(aside);
|
|
104
|
+
journal.move(path, join(aside, item));
|
|
105
|
+
result = "aside";
|
|
87
106
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
const SEED_KEYS = ["mcpServers", "projects", "hasCompletedOnboarding", "lastOnboardingVersion", "theme"];
|
|
92
|
-
/** First .claude.json of a profile: user MCP servers and per-project state, never the account. */
|
|
93
|
-
function seedGlobalConfig(dir, io) {
|
|
94
|
-
const dst = join(dir, ".claude.json");
|
|
95
|
-
if (existsSync(dst)) {
|
|
96
|
-
io.out(" = .claude.json already exists (turno mcp sync brings in new MCP servers)");
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const src = paths(io.env).hubConfig;
|
|
100
|
-
let hub;
|
|
101
|
-
try {
|
|
102
|
-
hub = JSON.parse(readFileSync(src, "utf8"));
|
|
103
|
-
}
|
|
104
|
-
catch {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const seed = {};
|
|
108
|
-
for (const k of SEED_KEYS)
|
|
109
|
-
if (k in hub)
|
|
110
|
-
seed[k] = hub[k];
|
|
111
|
-
writeFileSync(dst, `${JSON.stringify(seed, null, 2)}\n`, { mode: 0o600 });
|
|
112
|
-
chmodSync(dst, 0o600);
|
|
113
|
-
const count = (v) => (v && typeof v === "object" ? Object.keys(v).length : 0);
|
|
114
|
-
io.out(` + .claude.json with ${count(seed.mcpServers)} MCP servers and ${count(seed.projects)} projects from the hub`);
|
|
107
|
+
journal.symlink(target, path);
|
|
108
|
+
return result;
|
|
115
109
|
}
|
|
116
110
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
111
|
+
* Create a profile folder (0700) through the journal, so undo removes it while it is empty, or
|
|
112
|
+
* narrow an existing one to 0700, so undo puts its old mode back.
|
|
119
113
|
*/
|
|
120
|
-
function
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
text = readFileSync(hubFile, "utf8");
|
|
129
|
-
io.out(" + config.toml from ~/.codex (the login is not copied)");
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const next = setValue(text, undefined, "cli_auth_credentials_store", "file");
|
|
133
|
-
if (next !== text || !existsSync(file)) {
|
|
134
|
-
writeFileSync(file, next, { mode: 0o600 });
|
|
135
|
-
io.out(' + cli_auth_credentials_store = "file" (the login stays in this profile)');
|
|
136
|
-
}
|
|
114
|
+
function profileFolder(dir, journal) {
|
|
115
|
+
journal.mkdir(dir, 0o700);
|
|
116
|
+
journal.chmod(dir, 0o700);
|
|
117
|
+
}
|
|
118
|
+
/** Write a file the setup creates or changes (seeds, agent config) through the journal. */
|
|
119
|
+
function writeOwn(file, text, journal) {
|
|
120
|
+
journal.save(file);
|
|
121
|
+
writeFileSync(file, text, { mode: 0o600 });
|
|
137
122
|
chmodSync(file, 0o600);
|
|
123
|
+
journal.settle(file);
|
|
138
124
|
}
|
|
139
|
-
/**
|
|
140
|
-
function
|
|
125
|
+
/** Shared items of a profile: its folder, the agent's hub, and the items linked from it (files only when they exist). */
|
|
126
|
+
function sharedItems(name, agent, env) {
|
|
141
127
|
const a = adapter(agent);
|
|
142
|
-
const hub = agentHub(agent,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
128
|
+
const hub = agentHub(agent, env);
|
|
129
|
+
return {
|
|
130
|
+
dir: agentProfileDir(name, agent, env),
|
|
131
|
+
hub,
|
|
132
|
+
dirs: [...a.sharedDirs],
|
|
133
|
+
files: a.sharedFiles.filter((f) => existsSync(join(hub, f))),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The person's own files that setting up `names` would move to .aside-<stamp>/, so a command
|
|
138
|
+
* can ask before it moves anything. `config` is the one the setup will run with (turno init
|
|
139
|
+
* passes the config it is about to write, so a profile it declares has its own agent).
|
|
140
|
+
*/
|
|
141
|
+
export function localCopies(names, env, config = loadConfig(env)) {
|
|
142
|
+
return names.map((name) => {
|
|
143
|
+
const s = sharedItems(name, agentOf(name, config), env);
|
|
144
|
+
return { name, dir: s.dir, items: [...s.dirs, ...s.files].filter((item) => ownCopy(join(s.dir, item))) };
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** Print what linking did: one line, or every item with `verbose`. */
|
|
148
|
+
function reportLinks(name, label, dir, hub, results, aside, io, verbose, brief = false) {
|
|
149
|
+
const env = io.env;
|
|
150
|
+
const dirs = results.length;
|
|
151
|
+
const st = style(io);
|
|
152
|
+
const more = verbose || !dirs ? "" : st.muted(" (-v lists them)");
|
|
153
|
+
io.out(st.wrap(`${st.accent("▸")} `, `${st.bold(name)}${label} → ${tildify(dir, env)}: shares ${plural(dirs, "item")} with ${tildify(hub, env)}${more}`));
|
|
154
|
+
if (verbose)
|
|
155
|
+
for (const [item, r] of results)
|
|
156
|
+
io.out(` ${r === "same" ? st.muted("=") : st.accent("↔")} ${item}`);
|
|
157
|
+
const moved = results.filter(([, r]) => r === "aside").map(([item]) => item);
|
|
158
|
+
if (moved.length) {
|
|
159
|
+
const it = moved.length === 1 ? "it" : "them";
|
|
160
|
+
const text = brief
|
|
161
|
+
? `moved ${moved.join(", ")} aside ${st.muted(`(turno undo puts ${it} back)`)}`
|
|
162
|
+
: `moved your own ${moved.join(", ")} to ${tildify(aside, env)}/ ${st.muted("(merge by hand if useful; turno undo puts them back)")}`;
|
|
163
|
+
io.out(st.wrap(` ${st.warn("!")} `, text));
|
|
151
164
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Set up one profile: its folder (0700), the hub links, the agent's own steps and
|
|
168
|
+
* its launcher. Local copies of shared items move to .aside-<stamp>/.
|
|
169
|
+
*/
|
|
170
|
+
function setupProfile(name, agent, io, verbose, journal, config, brief = false) {
|
|
171
|
+
const a = adapter(agent);
|
|
172
|
+
const step = {
|
|
173
|
+
name,
|
|
174
|
+
dir: agentProfileDir(name, agent, io.env),
|
|
175
|
+
hub: agentHub(agent, io.env),
|
|
176
|
+
env: io.env,
|
|
177
|
+
journal,
|
|
178
|
+
out: (line) => io.out(line),
|
|
179
|
+
writeOwn: (file, text) => writeOwn(file, text, journal),
|
|
180
|
+
busy: () => profileBusy(name, io.env, config),
|
|
181
|
+
};
|
|
182
|
+
a.setup?.before?.(step);
|
|
183
|
+
const s = sharedItems(name, agent, io.env);
|
|
184
|
+
const aside = join(s.dir, `.aside-${stamp()}`);
|
|
185
|
+
profileFolder(s.dir, journal);
|
|
186
|
+
const results = [];
|
|
187
|
+
const held = [];
|
|
188
|
+
for (const item of s.dirs) {
|
|
189
|
+
const why = a.setup?.hold?.(item, step);
|
|
190
|
+
if (why) {
|
|
191
|
+
held.push(why);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
mkdirSync(join(s.hub, item), { recursive: true });
|
|
195
|
+
results.push([item, linkItem(s.dir, item, aside, journal, s.hub)]);
|
|
155
196
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
197
|
+
for (const item of s.files)
|
|
198
|
+
results.push([item, linkItem(s.dir, item, aside, journal, s.hub)]);
|
|
199
|
+
reportLinks(name, agent === DEFAULT_AGENT ? "" : ` (${a.label})`, s.dir, s.hub, results, aside, io, verbose, brief);
|
|
200
|
+
const st = style(io);
|
|
201
|
+
for (const why of held)
|
|
202
|
+
io.out(st.wrap(` ${st.warn("!")} `, why));
|
|
203
|
+
a.setup?.after?.(step);
|
|
204
|
+
a.ruleFolders?.({ ...step, folders: ruleFolders(name, config, io.env) });
|
|
205
|
+
writeLauncher(name, io.env, agent, journal);
|
|
206
|
+
io.out(` ${st.ok("+")} command ${st.bold(launcherName(name, agent))}`);
|
|
207
|
+
}
|
|
208
|
+
/** The absolute folders whose `[[projects]]` rules name `profile`. */
|
|
209
|
+
function ruleFolders(profile, config, env) {
|
|
210
|
+
return [
|
|
211
|
+
...new Set(config.projects.filter((r) => r.profile === profile).map((r) => resolvePath(expandHome(r.path, env)))),
|
|
212
|
+
];
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The agent's per-folder setup for `profile`'s rules, after `turno profile assign`
|
|
216
|
+
* changed them. Nothing for agents without a `ruleFolders` hook.
|
|
217
|
+
*/
|
|
218
|
+
export function applyRuleFolders(profile, io, journal) {
|
|
219
|
+
const config = loadConfig(io.env);
|
|
220
|
+
const agent = agentOf(profile, config);
|
|
221
|
+
const hook = adapter(agent).ruleFolders;
|
|
222
|
+
if (!hook)
|
|
223
|
+
return;
|
|
224
|
+
hook({
|
|
225
|
+
name: profile,
|
|
226
|
+
dir: agentProfileDir(profile, agent, io.env),
|
|
227
|
+
folders: ruleFolders(profile, config, io.env),
|
|
228
|
+
env: io.env,
|
|
229
|
+
out: (line) => io.out(line),
|
|
230
|
+
writeOwn: (file, text) => writeOwn(file, text, journal),
|
|
231
|
+
});
|
|
160
232
|
}
|
|
161
233
|
export function setupProfiles(names, io, opts = {}) {
|
|
162
234
|
if (names.length === 0)
|
|
163
|
-
fail("usage: turno
|
|
235
|
+
fail("usage: turno profile repair <profile>...");
|
|
164
236
|
for (const name of names)
|
|
165
237
|
checkName(name);
|
|
166
|
-
|
|
238
|
+
// Launchers keep the path of this turno; a path into npx's cache disappears.
|
|
239
|
+
if (opts.turno === undefined)
|
|
240
|
+
refuseNpx();
|
|
241
|
+
const turno = opts.turno !== undefined ? { words: opts.turno } : resolveTurnoCommand(io.env);
|
|
242
|
+
const verbose = Boolean(opts.verbose);
|
|
167
243
|
const config = loadConfig(io.env);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
io.out(`▸ ${name} → ${tildify(dir, io.env)}`);
|
|
182
|
-
mkdirSync(dir, { recursive: true });
|
|
183
|
-
chmodSync(dir, 0o700);
|
|
184
|
-
for (const item of SHARED_DIRS) {
|
|
185
|
-
if (item === "sessions" && !lstat(join(dir, item))?.isSymbolicLink() && profileBusy(name, io.env, config)) {
|
|
186
|
-
io.out(" ! sessions: this profile has open sessions; close them and run setup again");
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
mkdirSync(join(p.hub, item), { recursive: true });
|
|
190
|
-
linkItem(dir, item, aside, io);
|
|
191
|
-
}
|
|
192
|
-
for (const item of SHARED_FILES) {
|
|
193
|
-
if (existsSync(join(p.hub, item)))
|
|
194
|
-
linkItem(dir, item, aside, io);
|
|
195
|
-
}
|
|
196
|
-
seedGlobalConfig(dir, io);
|
|
197
|
-
const history = join(dir, "history.jsonl");
|
|
198
|
-
const hubHistory = join(p.hub, "history.jsonl");
|
|
199
|
-
if (!existsSync(history) && lstat(hubHistory)?.isFile()) {
|
|
200
|
-
copyFileSync(hubHistory, history);
|
|
201
|
-
chmodSync(history, 0o600);
|
|
202
|
-
io.out(" + history.jsonl (initial copy; the ↑ history cannot be shared)");
|
|
203
|
-
}
|
|
204
|
-
writeLauncher(name, io.env, "claude");
|
|
205
|
-
io.out(` + command claude-${name}`);
|
|
244
|
+
const journal = opts.journal ?? new Journal(io.env, `profile repair ${names.join(" ")}`);
|
|
245
|
+
for (const name of names)
|
|
246
|
+
setupProfile(name, agentOf(name, config), io, verbose, journal, config, Boolean(opts.brief));
|
|
247
|
+
const written = writeHelperLaunchers(io.env, turno.words, journal);
|
|
248
|
+
if (verbose)
|
|
249
|
+
for (const w of written)
|
|
250
|
+
io.out(`+ command ${w}`);
|
|
251
|
+
if (turno.warning)
|
|
252
|
+
io.out(`! turno-auto and turno-open: ${turno.warning}`);
|
|
253
|
+
if (!opts.journal) {
|
|
254
|
+
const hint = journal.hint();
|
|
255
|
+
if (hint)
|
|
256
|
+
io.out(hint);
|
|
206
257
|
}
|
|
207
|
-
for (const written of writeHelperLaunchers(io.env, opts.turno ?? turnoCommand()))
|
|
208
|
-
io.out(`+ command ${written}`);
|
|
209
258
|
}
|
|
210
259
|
export const command = {
|
|
211
260
|
summary: "create or repair ~/.claude-<profile> and its claude-<profile> command",
|
|
261
|
+
hidden: true,
|
|
212
262
|
usage: [
|
|
213
|
-
"Usage: turno
|
|
263
|
+
"Usage: turno profile repair <profile>...",
|
|
214
264
|
"",
|
|
215
265
|
"Links the shared hub folders and files into the profile (local copies are moved",
|
|
216
266
|
"to .aside-<timestamp>/), seeds .claude.json and history.jsonl, and writes the",
|