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
package/dist/core/config.js
CHANGED
|
@@ -1,7 +1,115 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { parse } from "smol-toml";
|
|
3
|
-
import { AGENT_IDS, isAgentId } from "../agents/index.js";
|
|
4
|
-
import {
|
|
3
|
+
import { AGENT_IDS, DEFAULT_AGENT, adapter, isAgentId } from "../agents/index.js";
|
|
4
|
+
import { distance } from "../cli/io.js";
|
|
5
|
+
import { expandHome, paths, tildify } from "./paths.js";
|
|
6
|
+
/** Every key config.toml may hold, by table ("" is the top level; `*` stands for any name). */
|
|
7
|
+
const KNOWN_KEYS = {
|
|
8
|
+
"": [
|
|
9
|
+
"system",
|
|
10
|
+
"default",
|
|
11
|
+
"fallback",
|
|
12
|
+
"icons",
|
|
13
|
+
"nerd_terminals",
|
|
14
|
+
"update_check",
|
|
15
|
+
"hints",
|
|
16
|
+
"profiles",
|
|
17
|
+
"agents",
|
|
18
|
+
"projects",
|
|
19
|
+
"open",
|
|
20
|
+
"mcpd",
|
|
21
|
+
],
|
|
22
|
+
"profiles.*": ["agent", "browser", "color"],
|
|
23
|
+
"agents.*": ["default", "fallback"],
|
|
24
|
+
"projects[]": ["path", "profile", "mcp", "mcp_deny"],
|
|
25
|
+
open: ["chrome_dir"],
|
|
26
|
+
mcpd: ["port", "call_log", "max_request_body", "idle_under_pressure"],
|
|
27
|
+
};
|
|
28
|
+
const SIZE_UNITS = {
|
|
29
|
+
"": 1,
|
|
30
|
+
b: 1,
|
|
31
|
+
k: 1024,
|
|
32
|
+
kb: 1000,
|
|
33
|
+
kib: 1024,
|
|
34
|
+
m: 1024 ** 2,
|
|
35
|
+
mb: 1000 ** 2,
|
|
36
|
+
mib: 1024 ** 2,
|
|
37
|
+
g: 1024 ** 3,
|
|
38
|
+
gb: 1000 ** 3,
|
|
39
|
+
gib: 1024 ** 3,
|
|
40
|
+
};
|
|
41
|
+
/** Bounds of `mcpd.max_request_body`: below 1 MiB ordinary tool calls fail, above 1 GiB a client can exhaust memory. */
|
|
42
|
+
const MIN_REQUEST_BODY = 1024 ** 2;
|
|
43
|
+
const MAX_REQUEST_BODY = 1024 ** 3;
|
|
44
|
+
/**
|
|
45
|
+
* A size in bytes: a whole number of bytes, or a string such as "64MiB", "512 KiB" or "1GB".
|
|
46
|
+
* Undefined when it is neither.
|
|
47
|
+
*/
|
|
48
|
+
export function parseSize(v) {
|
|
49
|
+
if (typeof v === "number")
|
|
50
|
+
return Number.isInteger(v) && v >= 0 ? v : undefined;
|
|
51
|
+
if (typeof v !== "string")
|
|
52
|
+
return undefined;
|
|
53
|
+
const m = /^\s*(\d+(?:\.\d+)?)\s*([a-z]*)\s*$/i.exec(v);
|
|
54
|
+
const unit = m ? SIZE_UNITS[m[2].toLowerCase()] : undefined;
|
|
55
|
+
return m && unit ? Math.round(Number(m[1]) * unit) : undefined;
|
|
56
|
+
}
|
|
57
|
+
/** Check `mcpd.max_request_body`; the message when it is out of bounds or not a size. */
|
|
58
|
+
export function requestBodyProblem(v) {
|
|
59
|
+
const n = parseSize(v);
|
|
60
|
+
if (n === undefined || n < MIN_REQUEST_BODY || n > MAX_REQUEST_BODY)
|
|
61
|
+
return 'mcpd.max_request_body must be a size between 1MiB and 1GiB, in bytes or like "64MiB"';
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Default of `mcpd.idle_under_pressure`, in seconds. */
|
|
65
|
+
const DEFAULT_IDLE_UNDER_PRESSURE = 300;
|
|
66
|
+
/**
|
|
67
|
+
* `mcpd.idle_under_pressure` in seconds: a duration ("5m", "90s", "1h" or seconds) between 30
|
|
68
|
+
* seconds and 24 hours, `false` (0, off) or `true` (the default). Undefined when invalid.
|
|
69
|
+
*/
|
|
70
|
+
export function parseIdleUnderPressure(v) {
|
|
71
|
+
if (v === false)
|
|
72
|
+
return 0;
|
|
73
|
+
if (v === true)
|
|
74
|
+
return DEFAULT_IDLE_UNDER_PRESSURE;
|
|
75
|
+
let secs;
|
|
76
|
+
if (typeof v === "number")
|
|
77
|
+
secs = v;
|
|
78
|
+
else if (typeof v === "string") {
|
|
79
|
+
const m = /^(\d+(?:\.\d+)?)\s*(s|m|h)?$/.exec(v.trim());
|
|
80
|
+
if (m)
|
|
81
|
+
secs = Number(m[1]) * (m[2] === "h" ? 3600 : m[2] === "m" ? 60 : 1);
|
|
82
|
+
}
|
|
83
|
+
return secs !== undefined && Number.isFinite(secs) && secs >= 30 && secs <= 24 * 3600 ? secs : undefined;
|
|
84
|
+
}
|
|
85
|
+
export const IDLE_UNDER_PRESSURE_PROBLEM = 'mcpd.idle_under_pressure must be a duration between 30s and 24h, like "5m", or false';
|
|
86
|
+
/** The known key closest to `key`, when it is a likely typo (or `colour` for `color`). */
|
|
87
|
+
export function suggestKey(key, known) {
|
|
88
|
+
let best;
|
|
89
|
+
for (const k of known) {
|
|
90
|
+
const d = distance(key, k);
|
|
91
|
+
if (d <= Math.max(1, Math.min(3, Math.floor(k.length / 3))) && (!best || d < best.d))
|
|
92
|
+
best = { k, d };
|
|
93
|
+
}
|
|
94
|
+
return best?.k;
|
|
95
|
+
}
|
|
96
|
+
function unknownKeys(table, known, prefix, warnings) {
|
|
97
|
+
for (const key of Object.keys(table)) {
|
|
98
|
+
if (known.includes(key))
|
|
99
|
+
continue;
|
|
100
|
+
const near = suggestKey(key, known);
|
|
101
|
+
warnings.push(`unknown key ${prefix}${key}${near ? ` (did you mean ${prefix}${near}?)` : ""}; turno ignores it`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** A friendlier text for TOML syntax errors that smol-toml words in parser terms. */
|
|
105
|
+
function tomlMessage(message) {
|
|
106
|
+
const head = message.split("\n", 1)[0].replace(/^Invalid TOML document: /, "");
|
|
107
|
+
const pos = /\n(\d+):/.exec(message);
|
|
108
|
+
if (/control characters are not allowed in strings|unterminated string/i.test(head)) {
|
|
109
|
+
return `line ${pos?.[1] ?? "?"}: a string is not closed (a " is missing at the end of the value)`;
|
|
110
|
+
}
|
|
111
|
+
return message;
|
|
112
|
+
}
|
|
5
113
|
export class ConfigError extends Error {
|
|
6
114
|
constructor(file, message) {
|
|
7
115
|
super(`${file}: ${message}`);
|
|
@@ -19,24 +127,44 @@ function str(v, file, key) {
|
|
|
19
127
|
throw new ConfigError(file, `${key} must be a string`);
|
|
20
128
|
return v;
|
|
21
129
|
}
|
|
22
|
-
|
|
130
|
+
/** A list of MCP server names (`[[projects]] mcp`), or undefined when unset. */
|
|
131
|
+
function names(v, file, key) {
|
|
132
|
+
if (v === undefined)
|
|
133
|
+
return undefined;
|
|
134
|
+
if (!Array.isArray(v) || v.some((x) => typeof x !== "string" || !x))
|
|
135
|
+
throw new ConfigError(file, `${key} must be an array of server names, like ["issues", "docs"]`);
|
|
136
|
+
return v;
|
|
137
|
+
}
|
|
138
|
+
function table(v, file, key) {
|
|
139
|
+
if (v === undefined)
|
|
140
|
+
return {};
|
|
141
|
+
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
142
|
+
throw new ConfigError(file, `[${key}] must be a table`);
|
|
143
|
+
return v;
|
|
144
|
+
}
|
|
145
|
+
export function parseConfig(text, path = "config.toml", env = process.env) {
|
|
146
|
+
const file = tildify(path, env);
|
|
23
147
|
let raw;
|
|
24
148
|
try {
|
|
25
149
|
raw = parse(text);
|
|
26
150
|
}
|
|
27
151
|
catch (err) {
|
|
28
|
-
throw new ConfigError(file, err.message);
|
|
152
|
+
throw new ConfigError(file, tomlMessage(err.message));
|
|
29
153
|
}
|
|
154
|
+
const warnings = [];
|
|
155
|
+
unknownKeys(raw, KNOWN_KEYS[""], "", warnings);
|
|
30
156
|
const p = paths(env);
|
|
31
157
|
const cfg = {
|
|
32
158
|
icons: "auto",
|
|
33
159
|
nerdTerminals: [],
|
|
34
160
|
updateCheck: true,
|
|
161
|
+
hints: true,
|
|
35
162
|
profiles: {},
|
|
36
163
|
agents: {},
|
|
37
164
|
projects: [],
|
|
38
165
|
open: { chromeDir: p.chromeProfilesDir },
|
|
39
|
-
mcpd: { port: 47821 },
|
|
166
|
+
mcpd: { port: 47821, callLog: true, idleUnderPressure: DEFAULT_IDLE_UNDER_PRESSURE },
|
|
167
|
+
warnings,
|
|
40
168
|
};
|
|
41
169
|
cfg.system = str(raw.system, file, "system");
|
|
42
170
|
cfg.default = str(raw.default, file, "default");
|
|
@@ -60,13 +188,17 @@ export function parseConfig(text, file = "config.toml", env = process.env) {
|
|
|
60
188
|
throw new ConfigError(file, "update_check must be true or false");
|
|
61
189
|
cfg.updateCheck = raw.update_check;
|
|
62
190
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
191
|
+
if (raw.hints !== undefined) {
|
|
192
|
+
if (typeof raw.hints !== "boolean")
|
|
193
|
+
throw new ConfigError(file, "hints must be true or false");
|
|
194
|
+
cfg.hints = raw.hints;
|
|
195
|
+
}
|
|
196
|
+
const profiles = table(raw.profiles, file, "profiles");
|
|
66
197
|
for (const [name, value] of Object.entries(profiles)) {
|
|
67
198
|
if (!isValidProfileName(name))
|
|
68
199
|
throw new ConfigError(file, `invalid profile name "${name}"`);
|
|
69
|
-
const v = (value
|
|
200
|
+
const v = table(value, file, `profiles.${name}`);
|
|
201
|
+
unknownKeys(v, KNOWN_KEYS["profiles.*"], `profiles.${name}.`, warnings);
|
|
70
202
|
const browser = str(v.browser, file, `profiles.${name}.browser`) ?? "chrome";
|
|
71
203
|
if (browser !== "chrome" && browser !== "default") {
|
|
72
204
|
throw new ConfigError(file, `profiles.${name}.browser must be chrome or default`);
|
|
@@ -75,19 +207,18 @@ export function parseConfig(text, file = "config.toml", env = process.env) {
|
|
|
75
207
|
if (color !== undefined && typeof color !== "string" && typeof color !== "number") {
|
|
76
208
|
throw new ConfigError(file, `profiles.${name}.color must be a name or a number`);
|
|
77
209
|
}
|
|
78
|
-
const agent = v.agent ??
|
|
210
|
+
const agent = v.agent ?? DEFAULT_AGENT;
|
|
79
211
|
if (!isAgentId(agent))
|
|
80
212
|
throw new ConfigError(file, `profiles.${name}.agent must be one of ${AGENT_IDS.join(", ")}`);
|
|
81
213
|
cfg.profiles[name] = { agent, browser, ...(color !== undefined ? { color } : {}) };
|
|
82
214
|
}
|
|
83
|
-
const agents = raw.agents
|
|
84
|
-
if (typeof agents !== "object" || Array.isArray(agents))
|
|
85
|
-
throw new ConfigError(file, "[agents] must be a table");
|
|
215
|
+
const agents = table(raw.agents, file, "agents");
|
|
86
216
|
for (const [id, value] of Object.entries(agents)) {
|
|
87
|
-
if (!isAgentId(id) || id ===
|
|
88
|
-
throw new ConfigError(file, `[agents.${id}]: use one of ${AGENT_IDS.filter((a) => a !==
|
|
217
|
+
if (!isAgentId(id) || id === DEFAULT_AGENT) {
|
|
218
|
+
throw new ConfigError(file, `[agents.${id}]: use one of ${AGENT_IDS.filter((a) => a !== DEFAULT_AGENT).join(", ")} (${adapter(DEFAULT_AGENT).label} uses the top-level default and fallback)`);
|
|
89
219
|
}
|
|
90
|
-
const v = (value
|
|
220
|
+
const v = table(value, file, `agents.${id}`);
|
|
221
|
+
unknownKeys(v, KNOWN_KEYS["agents.*"], `agents.${id}.`, warnings);
|
|
91
222
|
const roles = {};
|
|
92
223
|
const d = str(v.default, file, `agents.${id}.default`);
|
|
93
224
|
const f = str(v.fallback, file, `agents.${id}.fallback`);
|
|
@@ -101,28 +232,55 @@ export function parseConfig(text, file = "config.toml", env = process.env) {
|
|
|
101
232
|
if (!Array.isArray(projects))
|
|
102
233
|
throw new ConfigError(file, "projects must be an array of tables ([[projects]])");
|
|
103
234
|
for (const [i, item] of projects.entries()) {
|
|
104
|
-
const v = item;
|
|
235
|
+
const v = table(item, file, `projects[${i}]`);
|
|
236
|
+
unknownKeys(v, KNOWN_KEYS["projects[]"], `projects[${i}].`, warnings);
|
|
105
237
|
const path = str(v.path, file, `projects[${i}].path`);
|
|
106
238
|
const profile = str(v.profile, file, `projects[${i}].profile`);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
239
|
+
const mcp = names(v.mcp, file, `projects[${i}].mcp`);
|
|
240
|
+
const mcpDeny = names(v.mcp_deny, file, `projects[${i}].mcp_deny`);
|
|
241
|
+
if (!path || (!profile && !mcp && !mcpDeny))
|
|
242
|
+
throw new ConfigError(file, `projects[${i}] needs path and profile, mcp or mcp_deny`);
|
|
243
|
+
cfg.projects.push({
|
|
244
|
+
path: expandHome(path, env),
|
|
245
|
+
...(profile ? { profile } : {}),
|
|
246
|
+
...(mcp ? { mcp } : {}),
|
|
247
|
+
...(mcpDeny ? { mcpDeny } : {}),
|
|
248
|
+
});
|
|
110
249
|
}
|
|
111
|
-
const open = (raw.open
|
|
250
|
+
const open = table(raw.open, file, "open");
|
|
251
|
+
unknownKeys(open, KNOWN_KEYS.open, "open.", warnings);
|
|
112
252
|
const chromeDir = str(open.chrome_dir, file, "open.chrome_dir");
|
|
113
253
|
if (chromeDir)
|
|
114
254
|
cfg.open.chromeDir = expandHome(chromeDir, env);
|
|
115
|
-
const mcpd = (raw.mcpd
|
|
255
|
+
const mcpd = table(raw.mcpd, file, "mcpd");
|
|
256
|
+
unknownKeys(mcpd, KNOWN_KEYS.mcpd, "mcpd.", warnings);
|
|
116
257
|
if (mcpd.port !== undefined) {
|
|
117
258
|
if (typeof mcpd.port !== "number" || !Number.isInteger(mcpd.port) || mcpd.port < 1024 || mcpd.port > 65535) {
|
|
118
259
|
throw new ConfigError(file, "mcpd.port must be an integer between 1024 and 65535");
|
|
119
260
|
}
|
|
120
261
|
cfg.mcpd.port = mcpd.port;
|
|
121
262
|
}
|
|
263
|
+
if (mcpd.call_log !== undefined) {
|
|
264
|
+
if (typeof mcpd.call_log !== "boolean")
|
|
265
|
+
throw new ConfigError(file, "mcpd.call_log must be true or false");
|
|
266
|
+
cfg.mcpd.callLog = mcpd.call_log;
|
|
267
|
+
}
|
|
268
|
+
if (mcpd.max_request_body !== undefined) {
|
|
269
|
+
const problem = requestBodyProblem(mcpd.max_request_body);
|
|
270
|
+
if (problem)
|
|
271
|
+
throw new ConfigError(file, problem);
|
|
272
|
+
cfg.mcpd.maxRequestBody = parseSize(mcpd.max_request_body);
|
|
273
|
+
}
|
|
274
|
+
if (mcpd.idle_under_pressure !== undefined) {
|
|
275
|
+
const secs = parseIdleUnderPressure(mcpd.idle_under_pressure);
|
|
276
|
+
if (secs === undefined)
|
|
277
|
+
throw new ConfigError(file, IDLE_UNDER_PRESSURE_PROBLEM);
|
|
278
|
+
cfg.mcpd.idleUnderPressure = secs;
|
|
279
|
+
}
|
|
122
280
|
return cfg;
|
|
123
281
|
}
|
|
124
282
|
/** Load ~/.config/turno/config.toml; a missing file means all defaults. */
|
|
125
|
-
export function loadConfig(env
|
|
283
|
+
export function loadConfig(env) {
|
|
126
284
|
const file = paths(env).configFile;
|
|
127
285
|
let text = "";
|
|
128
286
|
try {
|
package/dist/core/exhausted.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync, rmSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { paths } from "./paths.js";
|
|
3
|
+
import { paths, writePrivateFile } from "./paths.js";
|
|
4
4
|
/** Epoch seconds until which a profile is marked exhausted, or undefined (expired marks are removed). */
|
|
5
|
-
export function exhaustedUntil(profile, env
|
|
5
|
+
export function exhaustedUntil(profile, env, now = Date.now() / 1000) {
|
|
6
6
|
const file = join(paths(env).exhaustedDir, profile);
|
|
7
7
|
let until;
|
|
8
8
|
try {
|
|
@@ -19,12 +19,10 @@ export function exhaustedUntil(profile, env = process.env, now = Date.now() / 10
|
|
|
19
19
|
}
|
|
20
20
|
return until;
|
|
21
21
|
}
|
|
22
|
-
export function markExhausted(profile, until, env
|
|
23
|
-
|
|
24
|
-
mkdirSync(dir, { recursive: true });
|
|
25
|
-
writeFileSync(join(dir, profile), `${Math.floor(until)}\n`);
|
|
22
|
+
export function markExhausted(profile, until, env) {
|
|
23
|
+
writePrivateFile(join(paths(env).exhaustedDir, profile), `${Math.floor(until)}\n`, env);
|
|
26
24
|
}
|
|
27
|
-
export function clearExhausted(profile, env
|
|
25
|
+
export function clearExhausted(profile, env) {
|
|
28
26
|
rmSync(join(paths(env).exhaustedDir, profile), { force: true });
|
|
29
27
|
}
|
|
30
28
|
//# sourceMappingURL=exhausted.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { CliError } from "../cli/io.js";
|
|
3
|
+
/** Small file and process helpers shared across modules. Keep this file free of heavy imports. */
|
|
4
|
+
/** The real path of `p`, or `p` itself when it cannot be resolved (it does not exist, no access). */
|
|
5
|
+
export function realOr(p) {
|
|
6
|
+
try {
|
|
7
|
+
return realpathSync(p);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return p;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** The parsed JSON of a file, or undefined when it is missing, unreadable or not JSON. */
|
|
14
|
+
export function readJsonFile(file) {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** A JSON object: not null, not an array. */
|
|
23
|
+
export function isObject(v) {
|
|
24
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The object in a JSON config another program writes (Claude Code's .claude.json and
|
|
28
|
+
* settings.json, Cursor's mcp.json): valid JSON of any other shape is an error naming the file,
|
|
29
|
+
* not a TypeError later.
|
|
30
|
+
*/
|
|
31
|
+
export function parseJsonObject(text, file) {
|
|
32
|
+
const v = JSON.parse(text);
|
|
33
|
+
if (!isObject(v))
|
|
34
|
+
throw new CliError(`${file} does not hold a JSON object; fix or remove it`);
|
|
35
|
+
return v;
|
|
36
|
+
}
|
|
37
|
+
/** Whether a process is alive; shared with turno-browser. */
|
|
38
|
+
export { pidAlive } from "turno-core/process";
|
|
39
|
+
//# sourceMappingURL=fsutil.js.map
|