@fluid-app/fluid-cli 0.1.762 → 0.1.764
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/README.md
CHANGED
|
@@ -188,9 +188,16 @@ a newer `@fluid-app/fluid-cli`, and a newer `@fluid-app/fluid-cli-member-site`
|
|
|
188
188
|
short notice prints on stderr after the command finishes. The Sites plugin's
|
|
189
189
|
notice is about the copy the command loaded, and names the command that
|
|
190
190
|
updates that copy.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
|
|
192
|
+
A coding agent running the CLI (one that sets `AI_AGENT`, `CLAUDECODE`,
|
|
193
|
+
`CODEX_SANDBOX`, `CODEX_THREAD_ID`, `CURSOR_AGENT`, `GEMINI_CLI` or
|
|
194
|
+
`FLUID_AGENT`) gets the same check, even though its output is piped. It sees
|
|
195
|
+
the notice as one stderr line, at most once a day, and never after a command
|
|
196
|
+
that prints JSON (`--json`, or `--format json`).
|
|
197
|
+
|
|
198
|
+
A failed check is retried the next day. It never runs in CI, for other piped
|
|
199
|
+
output, or for a workspace build. Set `FLUID_NO_UPDATE_CHECK=1` (or
|
|
200
|
+
`NO_UPDATE_NOTIFIER=1`) to turn it off.
|
|
194
201
|
|
|
195
202
|
## Environment Variables
|
|
196
203
|
|
|
@@ -203,6 +210,7 @@ to turn it off.
|
|
|
203
210
|
| `FLUID_IDENTITY_URL` | Identity service origin (default: follows `FLUID_API_BASE`) |
|
|
204
211
|
| `FLUID_NO_BROWSER` | Print the sign-in URL without opening a browser |
|
|
205
212
|
| `FLUID_NO_UPDATE_CHECK` | Turn off the daily update notice |
|
|
213
|
+
| `FLUID_AGENT` | Mark the run as a coding agent's, for the update notice |
|
|
206
214
|
|
|
207
215
|
## Development
|
|
208
216
|
|
package/dist/bin/fluid.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { $ as walkCommands, A as pollAgentAccess, D as fetchUserCompanies, E as confirmMfa, F as validateToken, M as sendMfa, N as signup, O as getFluidApiBase, P as switchCompany, Q as visibleSubcommands, S as resolveCredentialSource, X as rootCommand, Y as filterCatalog, Z as visibleOptions, _ as getAuthToken, c as inputsModeActive, g as getActiveProfile, j as redeemIdentityLink, k as isInsecureRemoteBase, l as registerInputsHook, s as exitOnInputsError, u as createInputsReader, w as FLUID_API_ERROR, x as readFdToken } from "../hook-
|
|
2
|
+
import { $ as walkCommands, A as pollAgentAccess, D as fetchUserCompanies, E as confirmMfa, F as validateToken, M as sendMfa, N as signup, O as getFluidApiBase, P as switchCompany, Q as visibleSubcommands, S as resolveCredentialSource, X as rootCommand, Y as filterCatalog, Z as visibleOptions, _ as getAuthToken, c as inputsModeActive, g as getActiveProfile, j as redeemIdentityLink, k as isInsecureRemoteBase, l as registerInputsHook, s as exitOnInputsError, u as createInputsReader, w as FLUID_API_ERROR, x as readFdToken } from "../hook-DrcfveIe.mjs";
|
|
3
3
|
import { A as isClientProfile, C as readStoredConfig, D as getConfigDir, E as isStrictConfig, S as readConfig, T as writeConfig, _ as primeClientProfile, c as sessionFacts, j as isIdentityProfile, l as signInWithBrowser, n as describeIdentityError, o as primeIdentityProfile, p as clientAccessToken, r as identityToken, t as endUnusedSessions, u as signOutIdentity, w as updateConfig, y as resolveIdentityUrl } from "../profiles-5slwyRzI.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
@@ -2172,10 +2172,11 @@ async function loadPlugins(program, basePath) {
|
|
|
2172
2172
|
//#endregion
|
|
2173
2173
|
//#region src/update/notifier.ts
|
|
2174
2174
|
/**
|
|
2175
|
-
* Tell
|
|
2176
|
-
* newer Sites plugin beside it, is on npm.
|
|
2177
|
-
*
|
|
2178
|
-
*
|
|
2175
|
+
* Tell a person at a terminal, or a coding agent running the CLI for one,
|
|
2176
|
+
* that a newer fluid CLI, or a newer Sites plugin beside it, is on npm. npm
|
|
2177
|
+
* is asked at most once a day. The check never holds a command open: a run
|
|
2178
|
+
* prints what the last check found, and a stale cache is refreshed by a
|
|
2179
|
+
* detached child process for next time.
|
|
2179
2180
|
*/
|
|
2180
2181
|
const PACKAGE_NAME = "@fluid-app/fluid-cli";
|
|
2181
2182
|
/**
|
|
@@ -2188,21 +2189,49 @@ const SITES_PLUGIN_NAME = "@fluid-app/fluid-cli-member-site";
|
|
|
2188
2189
|
const REFRESH_ARG = "__refresh-update-check";
|
|
2189
2190
|
const FETCH_TIMEOUT_MS = 5e3;
|
|
2190
2191
|
const CACHE_FILE = "update-check.json";
|
|
2192
|
+
/**
|
|
2193
|
+
* A coding agent sees the notice once a day: the run that creates the day's
|
|
2194
|
+
* claim file, `update-notice-<UTC date>`, shows it. Creating a file that
|
|
2195
|
+
* doesn't exist yet succeeds for one run only, however many run at once.
|
|
2196
|
+
*/
|
|
2197
|
+
const AGENT_NOTICE_CLAIM = "update-notice-";
|
|
2198
|
+
/**
|
|
2199
|
+
* Variables coding agents set on the commands they run: the shared
|
|
2200
|
+
* `AI_AGENT`, Claude Code, Codex, Cursor's and Gemini's CLIs, and our own
|
|
2201
|
+
* `FLUID_AGENT` for any other.
|
|
2202
|
+
*/
|
|
2203
|
+
const AGENT_ENV = [
|
|
2204
|
+
"FLUID_AGENT",
|
|
2205
|
+
"AI_AGENT",
|
|
2206
|
+
"CLAUDECODE",
|
|
2207
|
+
"CODEX_SANDBOX",
|
|
2208
|
+
"CODEX_THREAD_ID",
|
|
2209
|
+
"CURSOR_AGENT",
|
|
2210
|
+
"GEMINI_CLI"
|
|
2211
|
+
];
|
|
2212
|
+
/** Whether a coding agent, rather than a person, is running this command. */
|
|
2213
|
+
function isAgentRun(env) {
|
|
2214
|
+
return AGENT_ENV.some((name) => {
|
|
2215
|
+
const value = env[name]?.trim().toLowerCase();
|
|
2216
|
+
return Boolean(value) && value !== "0" && value !== "false";
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
2191
2219
|
/** Whether an Electron app, such as Mist, is running the CLI it bundles. */
|
|
2192
2220
|
function isElectronRun(env, versions = {}) {
|
|
2193
2221
|
return Boolean(env["ELECTRON_RUN_AS_NODE"] || versions["electron"]);
|
|
2194
2222
|
}
|
|
2195
2223
|
/**
|
|
2196
|
-
* Only an installed CLI
|
|
2197
|
-
* (
|
|
2198
|
-
* Electron app bundles (the app updates it) stay quiet.
|
|
2224
|
+
* Only an installed CLI checks, for a person at a terminal or a coding agent
|
|
2225
|
+
* (whose output is piped). Other piped runs, CI, a workspace build and a
|
|
2226
|
+
* copy an Electron app bundles (the app updates it) stay quiet.
|
|
2199
2227
|
*/
|
|
2200
|
-
function
|
|
2201
|
-
if (env["FLUID_NO_UPDATE_CHECK"] || env["NO_UPDATE_NOTIFIER"]) return
|
|
2202
|
-
if (env["CI"]) return
|
|
2203
|
-
if (isElectronRun(env, versions)) return
|
|
2204
|
-
if (!
|
|
2205
|
-
|
|
2228
|
+
function updateCheckAudience({ env, stdoutIsTTY, stderrIsTTY, entryPath, versions }) {
|
|
2229
|
+
if (env["FLUID_NO_UPDATE_CHECK"] || env["NO_UPDATE_NOTIFIER"]) return null;
|
|
2230
|
+
if (env["CI"]) return null;
|
|
2231
|
+
if (isElectronRun(env, versions)) return null;
|
|
2232
|
+
if (!entryPath.includes(`${sep}node_modules${sep}`)) return null;
|
|
2233
|
+
if (stdoutIsTTY && stderrIsTTY) return "person";
|
|
2234
|
+
return isAgentRun(env) ? "agent" : null;
|
|
2206
2235
|
}
|
|
2207
2236
|
function parseVersion(version) {
|
|
2208
2237
|
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version.trim());
|
|
@@ -2292,27 +2321,54 @@ function localCommand(manager, pkg) {
|
|
|
2292
2321
|
case "bun": return `bun update --latest ${pkg}`;
|
|
2293
2322
|
}
|
|
2294
2323
|
}
|
|
2324
|
+
/** The command that updates `pkg` for this install. */
|
|
2325
|
+
function updateCommand(install, pkg) {
|
|
2326
|
+
switch (install.kind) {
|
|
2327
|
+
case "global": return globalCommand(install.manager, pkg);
|
|
2328
|
+
case "npx": return `npx ${pkg}@latest`;
|
|
2329
|
+
case "local": return localCommand(install.manager, pkg);
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2295
2332
|
/**
|
|
2296
|
-
* The
|
|
2297
|
-
* plugins too, unless a plugin's own notice follows it.
|
|
2333
|
+
* The line that says how to update `pkg` for this install. The CLI's own
|
|
2334
|
+
* names the plugins too, unless a plugin's own notice follows it.
|
|
2298
2335
|
*/
|
|
2299
2336
|
function updateInstruction(install, pkg = PACKAGE_NAME, notePlugins = true) {
|
|
2337
|
+
const command = updateCommand(install, pkg);
|
|
2300
2338
|
const note = notePlugins ? ` ${PLUGINS_NOTE}` : "";
|
|
2301
2339
|
switch (install.kind) {
|
|
2302
|
-
case "global": return `Run: ${
|
|
2303
|
-
case "npx": return `Run:
|
|
2304
|
-
case "local": return `Run in ${install.projectDir}: ${
|
|
2340
|
+
case "global": return `Run: ${command}${note}\n`;
|
|
2341
|
+
case "npx": return `Run: ${command} to use the latest version\n`;
|
|
2342
|
+
case "local": return `Run in ${install.projectDir}: ${command}${note}\n`;
|
|
2305
2343
|
}
|
|
2306
2344
|
}
|
|
2307
|
-
const OPT_OUT =
|
|
2308
|
-
function
|
|
2345
|
+
const OPT_OUT = "Set FLUID_NO_UPDATE_CHECK=1 to stop these notices.";
|
|
2346
|
+
function cliUpdate(current, latest, install) {
|
|
2309
2347
|
if (!isNewer(current, latest)) return null;
|
|
2310
|
-
return
|
|
2348
|
+
return {
|
|
2349
|
+
name: "fluid",
|
|
2350
|
+
pkg: PACKAGE_NAME,
|
|
2351
|
+
installed: current,
|
|
2352
|
+
latest,
|
|
2353
|
+
install
|
|
2354
|
+
};
|
|
2311
2355
|
}
|
|
2312
|
-
/**
|
|
2313
|
-
function
|
|
2314
|
-
|
|
2315
|
-
|
|
2356
|
+
/** Whether the CLI's update also names the plugins: no plugin's own follows. */
|
|
2357
|
+
function notesPlugins(update, updates) {
|
|
2358
|
+
return update.pkg === "@fluid-app/fluid-cli" && updates.every(({ pkg }) => pkg === "@fluid-app/fluid-cli");
|
|
2359
|
+
}
|
|
2360
|
+
/** A person's notice: each update and how to run it, under one opt-out line. */
|
|
2361
|
+
function personNotice(updates) {
|
|
2362
|
+
return `${updates.map((update) => `\nUpdate available for ${update.name}: ${update.installed} → ${update.latest}\n` + updateInstruction(update.install, update.pkg, notesPlugins(update, updates))).join("")}${OPT_OUT}\n`;
|
|
2363
|
+
}
|
|
2364
|
+
/** A coding agent's notice: one line, with the command for each update. */
|
|
2365
|
+
function agentNotice(updates) {
|
|
2366
|
+
return `Update available: ${updates.map((update) => {
|
|
2367
|
+
const { name, installed, latest, install, pkg } = update;
|
|
2368
|
+
const where = install.kind === "local" ? ` in ${install.projectDir}` : "";
|
|
2369
|
+
const plugins = notesPlugins(update, updates) ? ", and update any @fluid-app/fluid-cli-* plugins you use" : "";
|
|
2370
|
+
return `${name} ${installed} → ${latest} (run${where}: ${updateCommand(install, pkg)}${plugins})`;
|
|
2371
|
+
}).join("; ")}. An older version can lack newer commands, options and config keys. ${OPT_OUT}\n`;
|
|
2316
2372
|
}
|
|
2317
2373
|
/** The folder before the first `node_modules` in a path: its install's root. */
|
|
2318
2374
|
function installRoot(path) {
|
|
@@ -2346,11 +2402,12 @@ function loadedPackage(source, pkg) {
|
|
|
2346
2402
|
}
|
|
2347
2403
|
}
|
|
2348
2404
|
/**
|
|
2349
|
-
* The Sites plugin's
|
|
2405
|
+
* The Sites plugin's update, for the copy this run loaded, when npm has a
|
|
2350
2406
|
* newer one. A copy in a project other than the CLI's own install is updated
|
|
2351
|
-
* with that project's package manager.
|
|
2407
|
+
* with that project's package manager. An npx run fetches its packages each
|
|
2408
|
+
* time, so it has none.
|
|
2352
2409
|
*/
|
|
2353
|
-
function
|
|
2410
|
+
function sitesPluginUpdate(options, latest) {
|
|
2354
2411
|
if (!latest) return null;
|
|
2355
2412
|
const plugin = options.loadedPlugins?.().find((loaded) => loaded.name === SITES_PLUGIN_NAME);
|
|
2356
2413
|
const installed = plugin && loadedPackage(plugin.source, "@fluid-app/fluid-cli-member-site");
|
|
@@ -2360,13 +2417,18 @@ function sitesPluginBody(options, latest) {
|
|
|
2360
2417
|
manager: projectManager(installed.root, existsSync),
|
|
2361
2418
|
projectDir: installed.root
|
|
2362
2419
|
};
|
|
2363
|
-
|
|
2420
|
+
if (install.kind === "npx") return null;
|
|
2421
|
+
return {
|
|
2422
|
+
name: "the Sites plugin (fluid sites)",
|
|
2423
|
+
pkg: SITES_PLUGIN_NAME,
|
|
2424
|
+
installed: installed.version,
|
|
2425
|
+
latest,
|
|
2426
|
+
install
|
|
2427
|
+
};
|
|
2364
2428
|
}
|
|
2365
|
-
/** Everything the last check found to
|
|
2366
|
-
function
|
|
2367
|
-
|
|
2368
|
-
const notice = [cache.latest && isNewer(options.currentVersion, cache.latest) ? cliNoticeBody(options.currentVersion, cache.latest, detectInstallKind(options.entryPath), pluginBody === null) : null, pluginBody].filter(Boolean).join("");
|
|
2369
|
-
return notice ? notice + OPT_OUT : null;
|
|
2429
|
+
/** Everything the last check found to update. */
|
|
2430
|
+
function pendingUpdates(options, cache) {
|
|
2431
|
+
return [cache.latest ? cliUpdate(options.currentVersion, cache.latest, detectInstallKind(options.entryPath)) : null, sitesPluginUpdate(options, cache.sitesPluginLatest)].filter((update) => update !== null);
|
|
2370
2432
|
}
|
|
2371
2433
|
function readUpdateCache(configDir) {
|
|
2372
2434
|
try {
|
|
@@ -2445,19 +2507,47 @@ function spawnRefresh(entryPath) {
|
|
|
2445
2507
|
child.unref();
|
|
2446
2508
|
} catch {}
|
|
2447
2509
|
}
|
|
2510
|
+
/** The name of the claim file for the UTC day `now` falls on. */
|
|
2511
|
+
function agentNoticeClaim(now) {
|
|
2512
|
+
return `${AGENT_NOTICE_CLAIM}${now.toISOString().slice(0, 10)}`;
|
|
2513
|
+
}
|
|
2514
|
+
/**
|
|
2515
|
+
* Show an agent the notice if this run is the first to claim the day. The
|
|
2516
|
+
* claim is created exclusively, so it never writes through a planted link,
|
|
2517
|
+
* and an unwritable config directory shows an agent nothing. Earlier days'
|
|
2518
|
+
* claims are removed; a later day's, from a run that started after this
|
|
2519
|
+
* one's day ended, is kept.
|
|
2520
|
+
*/
|
|
2521
|
+
function showAgentNotice(configDir, updates, now) {
|
|
2522
|
+
const claim = agentNoticeClaim(now);
|
|
2523
|
+
try {
|
|
2524
|
+
writeFileSync(join(configDir, claim), "", { flag: "wx" });
|
|
2525
|
+
} catch {
|
|
2526
|
+
return;
|
|
2527
|
+
}
|
|
2528
|
+
process.stderr.write(agentNotice(updates));
|
|
2529
|
+
try {
|
|
2530
|
+
for (const name of readdirSync(configDir)) if (name.startsWith(AGENT_NOTICE_CLAIM) && name < claim) rmSync(join(configDir, name), { force: true });
|
|
2531
|
+
} catch {}
|
|
2532
|
+
}
|
|
2448
2533
|
/**
|
|
2449
|
-
* Print the cached notice when the command finishes
|
|
2450
|
-
* check started a day ago or more, stamp the
|
|
2451
|
-
* detached process. The stamp throttles failed and
|
|
2452
|
-
* a day while keeping the last known version, and
|
|
2534
|
+
* Print the cached notice when the command finishes (to an agent, at most
|
|
2535
|
+
* once a day) and, when the last check started a day ago or more, stamp the
|
|
2536
|
+
* cache and refresh it in a detached process. The stamp throttles failed and
|
|
2537
|
+
* concurrent checks to one a day while keeping the last known version, and
|
|
2538
|
+
* its notice, in place.
|
|
2453
2539
|
*/
|
|
2454
2540
|
function startUpdateCheck(options) {
|
|
2455
|
-
|
|
2541
|
+
const audience = updateCheckAudience(options);
|
|
2542
|
+
if (!audience) return;
|
|
2456
2543
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
2457
2544
|
const cache = readUpdateCache(options.configDir);
|
|
2458
2545
|
if (cache?.latest || cache?.sitesPluginLatest) (options.onExit ?? ((listener) => process.once("exit", listener)))(() => {
|
|
2459
|
-
|
|
2460
|
-
|
|
2546
|
+
if (audience === "agent" && (options.quiet?.() || existsSync(join(options.configDir, agentNoticeClaim(now))))) return;
|
|
2547
|
+
const updates = pendingUpdates(options, cache);
|
|
2548
|
+
if (updates.length === 0) return;
|
|
2549
|
+
if (audience === "person") process.stderr.write(personNotice(updates));
|
|
2550
|
+
else showAgentNotice(options.configDir, updates, now);
|
|
2461
2551
|
});
|
|
2462
2552
|
if (!isStale(cache, now)) return;
|
|
2463
2553
|
if (writeUpdateCache(options.configDir, {
|
|
@@ -2503,7 +2593,10 @@ const selfAuthenticating = new Set([
|
|
|
2503
2593
|
completeCommand
|
|
2504
2594
|
].map((command) => command.name()));
|
|
2505
2595
|
registerInputsHook(program);
|
|
2596
|
+
let quietNotice = false;
|
|
2506
2597
|
program.hook("preAction", async (_program, actionCommand) => {
|
|
2598
|
+
const opts = actionCommand.optsWithGlobals();
|
|
2599
|
+
quietNotice = actionCommand === completeCommand || opts["json"] === true || opts["format"] === "json";
|
|
2507
2600
|
let topLevel = actionCommand;
|
|
2508
2601
|
while (topLevel.parent && topLevel.parent !== program) topLevel = topLevel.parent;
|
|
2509
2602
|
if (selfAuthenticating.has(topLevel.name())) return;
|
|
@@ -2517,7 +2610,8 @@ if (!inputsModeActive(process.env)) startUpdateCheck({
|
|
|
2517
2610
|
stderrIsTTY: Boolean(process.stderr.isTTY),
|
|
2518
2611
|
entryPath: realpathSync(fileURLToPath(import.meta.url)),
|
|
2519
2612
|
versions: process.versions,
|
|
2520
|
-
loadedPlugins
|
|
2613
|
+
loadedPlugins,
|
|
2614
|
+
quiet: () => quietNotice
|
|
2521
2615
|
});
|
|
2522
2616
|
await loadPlugins(program, packageRoot);
|
|
2523
2617
|
const missingPlugin = missingPluginHint(program, process.argv.slice(2));
|