@argos-ci/cli 6.9.3 → 6.9.5

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
@@ -7,7 +7,7 @@
7
7
  </a>
8
8
  </p>
9
9
 
10
- <p align="center"><strong>The open source visual testing platform for AI-native engineering teams.</strong></p>
10
+ <p align="center"><strong>The open source visual testing platform for teams and AI agents.</strong></p>
11
11
 
12
12
  # Argos Command Line Interface
13
13
 
package/dist/index.mjs CHANGED
@@ -758,6 +758,55 @@ function formatMediaVersions(versions) {
758
758
  ].filter((line) => line !== null).slice(0, -1).join("\n");
759
759
  }
760
760
  //#endregion
761
+ //#region src/lib/terminal.ts
762
+ /**
763
+ * Printing text the CLI did not author — an OAuth error description chosen by
764
+ * the authorization server, for instance.
765
+ *
766
+ * A terminal acts on what it is given: an ANSI escape sequence moves the
767
+ * cursor, erases a line or repaints it, and a carriage return overwrites the
768
+ * line just printed. Remote text reaching it unfiltered therefore doesn't just
769
+ * read badly, it can forge CLI output — a fake "run this command to continue"
770
+ * instruction under the CLI's own name (GHSA-q9j4-4h4j-mv5m).
771
+ */
772
+ /**
773
+ * Longest remote string we print. A description is a sentence; a wall of text
774
+ * is itself a way to scroll the real message off the screen.
775
+ */
776
+ const MAX_LENGTH = 200;
777
+ /**
778
+ * Escape sequences, matched together with the bytes that belong to them so no
779
+ * parameter remnant (`[2K`) is left behind as text: CSI (`ESC [`), OSC
780
+ * (`ESC ]`, up to its terminator) and, last, the plain escape sequences —
781
+ * optional intermediate bytes and a final one, which covers `ESC c` (reset the
782
+ * terminal) as much as `ESC 7`.
783
+ */
784
+ const ESCAPE_SEQUENCE_REGEX = /[\u001B\u009B](?:\[[0-?]*[ -/]*[@-~]|\][^\u0007\u001B]*(?:\u0007|\u001B\\)?|[ -/]*[0-~])/g;
785
+ /** Anything else a terminal acts on rather than displays: C0, DEL and C1. */
786
+ const CONTROL_CHARACTER_REGEX = /[\u0000-\u001F\u007F-\u009F]/g;
787
+ /**
788
+ * Explicit directional formatting: the other way to make a line read as
789
+ * something other than what it says, by reordering the characters around it
790
+ * rather than by driving the terminal. Bidirectional text itself is untouched —
791
+ * only the overrides, embeddings, isolates and marks are dropped.
792
+ */
793
+ const DIRECTIONAL_FORMATTING_REGEX = /[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g;
794
+ /**
795
+ * Reduce remote text to characters a terminal can only display, on a single
796
+ * line and bounded in length.
797
+ *
798
+ * Returns an empty string when nothing printable is left, so callers can fall
799
+ * back to a message of their own rather than print a blank error.
800
+ *
801
+ * @param text The remote value. Typed `unknown` because it comes from parsed
802
+ * JSON or a URL parameter and is not necessarily a string at runtime.
803
+ */
804
+ function sanitizeTerminalText(text) {
805
+ if (text === null || text === void 0) return "";
806
+ const sanitized = String(text).replace(ESCAPE_SEQUENCE_REGEX, "").replace(DIRECTIONAL_FORMATTING_REGEX, "").replace(CONTROL_CHARACTER_REGEX, " ").replace(/\s+/g, " ").trim();
807
+ return sanitized.length > MAX_LENGTH ? `${sanitized.slice(0, MAX_LENGTH)}…` : sanitized;
808
+ }
809
+ //#endregion
761
810
  //#region src/lib/oauth.ts
762
811
  /**
763
812
  * OAuth 2.1 client configuration and helpers for the `argos login` flow
@@ -840,7 +889,7 @@ async function postToken(body) {
840
889
  body: new URLSearchParams(body).toString()
841
890
  });
842
891
  const data = await response.json().catch(() => null);
843
- if (!response.ok || !data?.access_token) throw new OAuthTokenError(data?.error_description ?? data?.error ?? `HTTP ${response.status}`, data?.error);
892
+ if (!response.ok || !data?.access_token) throw new OAuthTokenError(sanitizeTerminalText(data?.error_description ?? data?.error) || `HTTP ${response.status}`, data?.error);
844
893
  if (typeof data.refresh_token !== "string" || data.refresh_token === "") throw new Error("Token endpoint response is missing a refresh token.");
845
894
  if (typeof data.expires_in !== "number" || !Number.isFinite(data.expires_in)) throw new Error("Token endpoint response is missing a valid expiry.");
846
895
  return data;
@@ -1696,6 +1745,10 @@ function color(text, code, isTTY) {
1696
1745
  const successColor = (text) => color(text, 32, process.stdout.isTTY);
1697
1746
  const warningColor = (text) => color(text, 33, process.stderr.isTTY);
1698
1747
  const errorColor = (text) => color(text, 31, process.stderr.isTTY);
1748
+ /**
1749
+ * Listen on an ephemeral loopback port for the OAuth redirect, and resolve with
1750
+ * the authorization code it carries.
1751
+ */
1699
1752
  function startCallbackServer() {
1700
1753
  return new Promise((resolve, reject) => {
1701
1754
  let resolveCallback = () => {};
@@ -1722,7 +1775,7 @@ function startCallbackServer() {
1722
1775
  const code = url.searchParams.get("code");
1723
1776
  const state = url.searchParams.get("state");
1724
1777
  if (callbackError) {
1725
- const message = callbackErrorDescription ?? callbackError;
1778
+ const message = sanitizeTerminalText(callbackErrorDescription ?? callbackError) || "Authorization failed";
1726
1779
  res.writeHead(400, {
1727
1780
  "Content-Type": "text/html; charset=utf-8",
1728
1781
  Connection: "close"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/cli",
3
3
  "description": "Command-line (CLI) for visual testing with Argos.",
4
- "version": "6.9.3",
4
+ "version": "6.9.5",
5
5
  "bin": {
6
6
  "argos": "./bin/argos-cli.js"
7
7
  },
@@ -34,11 +34,11 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@argos-ci/api-client": "0.31.0",
38
- "@argos-ci/core": "6.8.4",
37
+ "@argos-ci/api-client": "0.31.1",
38
+ "@argos-ci/core": "6.8.6",
39
39
  "@vercel/detect-agent": "^1.2.5",
40
40
  "commander": "^15.0.0",
41
- "open": "^11.0.0",
41
+ "open": "^11.0.4",
42
42
  "ora": "^9.4.1"
43
43
  },
44
44
  "devDependencies": {
@@ -54,5 +54,5 @@
54
54
  "check-format": "prettier --check --ignore-unknown --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
55
55
  "lint": "eslint ."
56
56
  },
57
- "gitHead": "212ed2c37ce532dd32c87ac685b55e2ab6e154c4"
57
+ "gitHead": "4f0edc08d8549534dd3a682bbe034ebcb604bddf"
58
58
  }