filecafe 0.3.1 → 0.3.3

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
@@ -99,6 +99,8 @@ A saved token is only ever sent to the site it was issued for. To work against a
99
99
 
100
100
  Set `FILECAFE_DEBUG=1` to print stack traces for unexpected errors.
101
101
 
102
+ Output is only colored in a terminal, never when piped. Set `NO_COLOR=1` to turn colors off, or `FORCE_COLOR=1` to keep them when piping.
103
+
102
104
  ## Using file.cafe with AI agents
103
105
 
104
106
  Paste this into your project's `CLAUDE.md`, `AGENTS.md`, or Cursor rules:
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as updateCachePath, d as normalizeBaseUrl, f as readConfig, l as configPath, m as writeConfig, n as fetchLatestVersion, o as updateUpdateCache, p as resolveSettings, r as readUpdateCache, s as VERSION, t as CHECK_INTERVAL_MS, u as deleteConfig } from "./update-cache--jPxzzep.js";
2
+ import { a as updateCachePath, d as normalizeBaseUrl, f as readConfig, l as configPath, m as writeConfig, n as fetchLatestVersion, o as updateUpdateCache, p as resolveSettings, r as readUpdateCache, s as VERSION, t as CHECK_INTERVAL_MS, u as deleteConfig } from "./update-cache-tQTolnAo.js";
3
3
  import { Command } from "commander";
4
4
  import { homedir, hostname, tmpdir } from "node:os";
5
5
  import { realpath, stat } from "node:fs/promises";
@@ -8,6 +8,7 @@ import { execFile, spawn } from "node:child_process";
8
8
  import { createInterface } from "node:readline/promises";
9
9
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
10
10
  import { fileURLToPath } from "node:url";
11
+ import { Chalk } from "chalk";
11
12
  import { openAsBlob } from "node:fs";
12
13
  // src/api.ts
13
14
  const LOGIN_HINT = "Run \"filecafe login\" or set FILECAFE_TOKEN.";
@@ -292,6 +293,17 @@ async function requireSession(context, globals, onNotice) {
292
293
  }
293
294
  // src/terminal.ts
294
295
  /**
296
+ * Colors for text written to `stream`: on for a terminal, off when piped (scripts, CI logs,
297
+ * AI agents) or when NO_COLOR is set. FORCE_COLOR=1 or 0 overrides both.
298
+ */
299
+ function colorsFor(stream, env) {
300
+ return new Chalk({ level: useColor(stream, env) ? 1 : 0 });
301
+ }
302
+ function useColor(stream, env) {
303
+ if (env.FORCE_COLOR !== void 0) return env.FORCE_COLOR !== "0" && env.FORCE_COLOR !== "false";
304
+ return !env.NO_COLOR && Boolean(stream.isTTY) && env.TERM !== "dumb";
305
+ }
306
+ /**
295
307
  * Whether `stream` is a terminal that understands OSC 8 hyperlinks (link text that opens a
296
308
  * different URL when clicked). Terminals that don't would print the escape codes as garbage,
297
309
  * so this only says yes for ones known to support them. FORCE_HYPERLINK=1 or 0 overrides it.
@@ -343,8 +355,9 @@ function startSpinner(stream, text, env, platform) {
343
355
  return { stop: () => {} };
344
356
  }
345
357
  const frames = platform === "win32" && !env.WT_SESSION ? ASCII_FRAMES : FRAMES;
358
+ const color = colorsFor(stream, env);
346
359
  let frame = 0;
347
- const draw = () => stream.write(`\r${frames[frame++ % frames.length]} ${text}`);
360
+ const draw = () => stream.write(`\r${color.cyan(frames[frame++ % frames.length])} ${text}`);
348
361
  draw();
349
362
  const timer = setInterval(draw, 80);
350
363
  timer.unref();
@@ -390,8 +403,9 @@ async function tokenFromBrowser(context, baseUrl) {
390
403
  const client = clientFor(context, baseUrl, void 0, (message) => context.stderr.write(`${message}\n`));
391
404
  const login = await client.request("POST", "/api/v1/cli/logins", { name: hostname() });
392
405
  if (!isStartedLogin(login)) throw new CliError(`Unexpected response from ${baseUrl} when starting the login. Check the --url option / FILECAFE_URL.`);
393
- const link = supportsHyperlinks(context.stderr, context.env) ? hyperlink(login.verification_uri, login.verification_uri_complete) : login.verification_uri;
394
- context.stderr.write(`Your one-time code: ${login.user_code}\n\nOpening your browser to approve this login. Check that the code there matches.\nIf it does not open, visit ${link} and enter the code.\n\n`);
406
+ const color = colorsFor(context.stderr, context.env);
407
+ const link = color.cyan(supportsHyperlinks(context.stderr, context.env) ? hyperlink(login.verification_uri, login.verification_uri_complete) : login.verification_uri);
408
+ context.stderr.write(`Your one-time code: ${color.bold(login.user_code)}\n\nOpening your browser to approve this login. Check that the code there matches.\nIf it does not open, visit ${link} and enter the code.\n\n`);
395
409
  context.openBrowser(login.verification_uri_complete);
396
410
  const spinner = startSpinner(context.stderr, "Waiting for approval...", context.env, context.platform);
397
411
  const intervalMs = Math.max(login.interval, 1) * 1e3;
@@ -437,25 +451,30 @@ async function loginCommand(options, globals, context) {
437
451
  url: baseUrl,
438
452
  token
439
453
  });
440
- context.stdout.write(`Logged in as ${me.name} (${me.email})\n`);
441
- context.stderr.write(`Saved credentials for ${baseUrl} to ${configPath(context)}\n`);
442
- if (context.env.FILECAFE_TOKEN?.trim()) context.stderr.write("Note: FILECAFE_TOKEN is set in your environment and takes precedence over the saved login.\n");
443
- context.stderr.write("\nRun \"filecafe upload <file>\" to share a file.\n");
454
+ const out = colorsFor(context.stdout, context.env);
455
+ const err = colorsFor(context.stderr, context.env);
456
+ context.stdout.write(`${out.green("Logged in")} as ${out.bold(me.name)} (${me.email})\n`);
457
+ context.stderr.write(`${err.gray(`Saved credentials for ${baseUrl} to ${configPath(context)}`)}\n`);
458
+ if (context.env.FILECAFE_TOKEN?.trim()) context.stderr.write(`${err.yellow("Note:")} FILECAFE_TOKEN is set in your environment and takes precedence over the saved login.\n`);
459
+ const next = err.level > 0 ? err.cyan("filecafe upload <file>") : "\"filecafe upload <file>\"";
460
+ context.stderr.write(`\nRun ${next} to share a file.\n`);
444
461
  return 0;
445
462
  }
446
463
  // src/commands/logout.ts
447
464
  async function logoutCommand(context) {
448
465
  const saved = await readConfig(context).catch(() => null);
466
+ const out = colorsFor(context.stdout, context.env);
467
+ const err = colorsFor(context.stderr, context.env);
449
468
  if (saved) try {
450
469
  await clientFor(context, saved.url, saved.token).request("DELETE", "/api/v1/token", void 0, { idempotent: true });
451
470
  } catch (error) {
452
- if (!(error instanceof ApiError && error.status === 401)) context.stderr.write(`Could not revoke the token on ${saved.url}: ${error.message}\nIt may still be active; revoke it in Settings → API tokens.\n`);
471
+ if (!(error instanceof ApiError && error.status === 401)) context.stderr.write(`${err.yellow("Could not revoke the token")} on ${saved.url}: ${error.message}\nIt may still be active; revoke it in Settings → API tokens.\n`);
453
472
  }
454
473
  if (await deleteConfig(context)) {
455
- context.stdout.write(saved ? `Logged out of ${saved.url}.\n` : "Logged out.\n");
456
- context.stderr.write(`Removed ${configPath(context)}\n`);
474
+ context.stdout.write(saved ? `${out.green("Logged out")} of ${saved.url}.\n` : `${out.green("Logged out")}.\n`);
475
+ context.stderr.write(`${err.gray(`Removed ${configPath(context)}`)}\n`);
457
476
  } else context.stdout.write("Not logged in; nothing to do.\n");
458
- if (context.env.FILECAFE_TOKEN?.trim()) context.stderr.write("Note: FILECAFE_TOKEN is still set in your environment; unset it to stop using that token.\n");
477
+ if (context.env.FILECAFE_TOKEN?.trim()) context.stderr.write(`${err.yellow("Note:")} FILECAFE_TOKEN is still set in your environment; unset it to stop using that token.\n`);
459
478
  return 0;
460
479
  }
461
480
  // src/mime.ts
@@ -828,7 +847,9 @@ function createProgress(context, enabled) {
828
847
  async function uploadCommand(files, options, globals, context) {
829
848
  if (options.collection !== void 0 && !UUID_PATTERN.test(options.collection)) throw new CliError(`Invalid --collection "${options.collection}". Expected a collection UUID.`);
830
849
  if (files.length === 0) throw new CliError("No files given. Usage: filecafe upload <files...>");
831
- const progress = createProgress(context, Boolean(context.stderr.isTTY) && !options.json && !options.quiet);
850
+ const showProgress = Boolean(context.stderr.isTTY) && !options.json && !options.quiet;
851
+ const err = colorsFor(context.stderr, context.env);
852
+ const progress = createProgress(context, showProgress);
832
853
  const notice = (message) => {
833
854
  if (!options.quiet) {
834
855
  progress.clear();
@@ -855,7 +876,7 @@ async function uploadCommand(files, options, globals, context) {
855
876
  };
856
877
  else {
857
878
  const filename = uploadFilename(file);
858
- progress.update(`Uploading ${filename} (${formatBytes(size)})...`);
879
+ progress.update(`Uploading ${err.bold(filename)} (${formatBytes(size)})...`);
859
880
  try {
860
881
  const completed = await uploadFile({
861
882
  client,
@@ -871,7 +892,7 @@ async function uploadCommand(files, options, globals, context) {
871
892
  onProgress: (uploaded, total) => {
872
893
  if (uploaded > 0 && total > 0) {
873
894
  const percent = Math.floor(uploaded / total * 100);
874
- progress.update(`Uploading ${filename} ${percent}% (${formatBytes(uploaded)} / ${formatBytes(total)})`);
895
+ progress.update(`Uploading ${err.bold(filename)} ${err.cyan(`${percent}%`)} (${formatBytes(uploaded)} / ${formatBytes(total)})`);
875
896
  }
876
897
  }
877
898
  });
@@ -898,15 +919,15 @@ async function uploadCommand(files, options, globals, context) {
898
919
  results.push(result);
899
920
  if (!options.json) {
900
921
  if (result.ok && result.url) context.stdout.write(`${result.url}\n`);
901
- else if (result.ok) context.stderr.write(`${file}: uploaded (id ${result.id}), but the server returned no share link.\n`);
902
- else context.stderr.write(`${file}: ${result.error}\n`);
922
+ else if (result.ok) context.stderr.write(`${err.yellow(`${file}:`)} uploaded (id ${result.id}), but the server returned no share link.\n`);
923
+ else context.stderr.write(`${err.red(`${file}:`)} ${result.error}\n`);
903
924
  }
904
925
  }
905
926
  }
906
927
  if (options.json) context.stdout.write(`${JSON.stringify(results, null, 2)}\n`);
907
928
  else if (invalid.length > 0) {
908
- for (const entry of invalid) context.stderr.write(`${entry.file}: ${entry.error}\n`);
909
- context.stderr.write("Nothing was uploaded.\n");
929
+ for (const entry of invalid) context.stderr.write(`${err.red(`${entry.file}:`)} ${entry.error}\n`);
930
+ context.stderr.write(`${err.red("Nothing was uploaded.")}\n`);
910
931
  }
911
932
  return results.every((result) => result.ok) ? 0 : 1;
912
933
  }
@@ -926,8 +947,9 @@ async function whoamiCommand(options, globals, context) {
926
947
  token_source: settings.tokenSource
927
948
  })}\n`);
928
949
  else {
929
- context.stdout.write(`Logged in to ${settings.baseUrl} as ${me.name} (${me.email})\n`);
930
- if (settings.tokenSource === "env") context.stderr.write("(using FILECAFE_TOKEN)\n");
950
+ const out = colorsFor(context.stdout, context.env);
951
+ context.stdout.write(`Logged in to ${settings.baseUrl} as ${out.bold(me.name)} (${me.email})\n`);
952
+ if (settings.tokenSource === "env") context.stderr.write(`${colorsFor(context.stderr, context.env).gray("(using FILECAFE_TOKEN)")}\n`);
931
953
  }
932
954
  return 0;
933
955
  }
@@ -985,26 +1007,29 @@ function startUpdateCheck(context) {
985
1007
  }
986
1008
  /** Show the notice and, at a terminal, offer to install. `version` is null when npm could not confirm it. */
987
1009
  async function offerUpdate(context, version) {
988
- context.stderr.write(version ? `\nUpdate available for filecafe (${VERSION} → ${version}).\nChangelog: ${RELEASES_URL}/v${version}\n` : "\nA newer version of filecafe may be available.\n");
1010
+ const color = colorsFor(context.stderr, context.env);
1011
+ const run = (command) => color.cyan(command);
1012
+ context.stderr.write(version ? `\nUpdate available for filecafe (${color.gray(`v${VERSION}`)} → ${color.green(`v${version}`)})\nChangelog: ${color.cyan.underline(`${RELEASES_URL}/v${version}`)}\n` : "\nA newer version of filecafe may be available.\n");
989
1013
  if (context.env.npm_command === "exec" || context.scriptPath.replaceAll("\\", "/").includes("/_npx/")) {
990
- context.stderr.write("Run: npx filecafe@latest\n");
1014
+ context.stderr.write(`Run: ${run("npx filecafe@latest")}\n`);
991
1015
  return;
992
1016
  }
993
1017
  if (!context.stdin.isTTY || !context.stdout.isTTY) {
994
1018
  const installer = await detectInstaller(context);
995
- context.stderr.write(installer ? `Run: ${installer.join(" ")}\n` : UNKNOWN_INSTALL);
1019
+ context.stderr.write(installer ? `Run: ${run(installer.join(" "))}\n` : UNKNOWN_INSTALL);
996
1020
  return;
997
1021
  }
998
- if (!await context.confirm("Would you like to upgrade now? (Y/n) ")) return;
1022
+ const question = `${color.gray("?")} ${color.bold("Would you like to upgrade now?")} ${color.gray("(Y/n)")} `;
1023
+ if (!await context.confirm(question)) return;
999
1024
  const installer = await detectInstaller(context);
1000
1025
  if (!installer) {
1001
1026
  context.stderr.write(UNKNOWN_INSTALL);
1002
1027
  return;
1003
1028
  }
1004
1029
  const [command, ...args] = installer;
1005
- context.stderr.write(`> ${installer.join(" ")}\n`);
1030
+ context.stderr.write(`${color.gray(`> ${installer.join(" ")}`)}\n`);
1006
1031
  const exitCode = await context.run(command, args);
1007
- context.stderr.write(exitCode === 0 ? "Updated filecafe.\n" : `The update failed. Run it yourself: ${installer.join(" ")}\n`);
1032
+ context.stderr.write(exitCode === 0 ? `${color.green("Updated filecafe.")}\n` : `${color.red("The update failed.")} Run it yourself: ${run(installer.join(" "))}\n`);
1008
1033
  }
1009
1034
  const PACKAGE_MANAGERS = [
1010
1035
  {
@@ -1169,8 +1194,9 @@ async function execute(context, action, { quiet = false } = {}) {
1169
1194
  try {
1170
1195
  process.exitCode = await action();
1171
1196
  } catch (error) {
1172
- const message = error instanceof CliError || error instanceof ApiError ? error.message : `Unexpected error: ${error instanceof Error ? error.message : String(error)}`;
1173
- context.stderr.write(`${message}\n`);
1197
+ const label = error instanceof CliError || error instanceof ApiError ? "Error:" : "Unexpected error:";
1198
+ const message = error instanceof Error ? error.message : String(error);
1199
+ context.stderr.write(`${colorsFor(context.stderr, context.env).red(label)} ${message}\n`);
1174
1200
  if (context.env.FILECAFE_DEBUG && error instanceof Error && error.stack) context.stderr.write(`${error.stack}\n`);
1175
1201
  process.exitCode = 1;
1176
1202
  }
@@ -108,7 +108,7 @@ async function resolveSettings(environment, urlOption) {
108
108
  };
109
109
  }
110
110
  // src/version.ts
111
- const VERSION = "0.3.1";
111
+ const VERSION = "0.3.3";
112
112
  // src/update-cache.ts
113
113
  const REGISTRY_URL = "https://registry.npmjs.org/filecafe/latest";
114
114
  /** Ask npm at most once a day. */
@@ -1,4 +1,4 @@
1
- import { i as refreshUpdateCache, s as VERSION } from "./update-cache--jPxzzep.js";
1
+ import { i as refreshUpdateCache, s as VERSION } from "./update-cache-tQTolnAo.js";
2
2
  // src/update-worker.ts
3
3
  /**
4
4
  * Spawned detached by the CLI to refresh the update cache, so no command ever waits on npm.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "filecafe",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Upload files to file.cafe from the command line. Built for AI coding agents, humans, and CI.",
5
5
  "keywords": [
6
6
  "file.cafe",
@@ -28,6 +28,7 @@
28
28
  "prepublishOnly": "npm run build && npm test"
29
29
  },
30
30
  "dependencies": {
31
+ "chalk": "^5.6.2",
31
32
  "commander": "^14.0.3"
32
33
  },
33
34
  "devDependencies": {