@argos-ci/cli 6.8.0 → 6.9.1
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/dist/index.mjs +65 -2
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { Option, program } from "commander";
|
|
|
5
5
|
import { deploy, finalize, skip, upload, uploadMedia } from "@argos-ci/core";
|
|
6
6
|
import ora from "ora";
|
|
7
7
|
import { APIError, createClient, throwAPIError } from "@argos-ci/api-client";
|
|
8
|
+
import { determineAgent } from "@vercel/detect-agent";
|
|
8
9
|
import { homedir } from "node:os";
|
|
9
10
|
import { createHash, randomBytes } from "node:crypto";
|
|
10
11
|
import { createServer } from "node:http";
|
|
@@ -157,6 +158,66 @@ function skipCommand(program) {
|
|
|
157
158
|
});
|
|
158
159
|
}
|
|
159
160
|
//#endregion
|
|
161
|
+
//#region src/lib/user-agent.ts
|
|
162
|
+
/**
|
|
163
|
+
* The `User-Agent` the CLI sends on every API request.
|
|
164
|
+
*
|
|
165
|
+
* Beyond the usual product token, it carries an `agent/<name>` token when a
|
|
166
|
+
* coding agent is driving the CLI. That token is the only thing telling the API
|
|
167
|
+
* apart a command a person typed from one an agent ran on their behalf — the
|
|
168
|
+
* token signing the request is the same either way — and is what lets Argos
|
|
169
|
+
* mark the resulting comment as agent-made.
|
|
170
|
+
*/
|
|
171
|
+
/** Product token of the CLI itself, e.g. `argos-cli/6.7.0`. */
|
|
172
|
+
const PRODUCT = "argos-cli";
|
|
173
|
+
/**
|
|
174
|
+
* Longest agent name we forward. `AI_AGENT` is free-form, so a caller could put
|
|
175
|
+
* anything in it; the API only needs enough to recognize the agent.
|
|
176
|
+
*/
|
|
177
|
+
const MAX_AGENT_LENGTH = 64;
|
|
178
|
+
/**
|
|
179
|
+
* Reduce an agent name to a `token` as the HTTP grammar defines it (RFC 9110
|
|
180
|
+
* §5.6.2), lowercased.
|
|
181
|
+
*
|
|
182
|
+
* `@vercel/detect-agent` returns the `AI_AGENT` environment variable verbatim
|
|
183
|
+
* when it is set, so the value is user input: anything outside the allowed set —
|
|
184
|
+
* spaces, and control characters that would otherwise let it inject a header —
|
|
185
|
+
* becomes a hyphen. Returns `null` when nothing usable is left.
|
|
186
|
+
*/
|
|
187
|
+
function sanitizeAgentName(name) {
|
|
188
|
+
return name.trim().toLowerCase().slice(0, MAX_AGENT_LENGTH).replaceAll(/[^a-z0-9.@_-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Format the `User-Agent` value, e.g.
|
|
192
|
+
* `argos-cli/6.7.0 node/22.11.0 agent/claude`.
|
|
193
|
+
*/
|
|
194
|
+
function formatUserAgent(input) {
|
|
195
|
+
const tokens = [`${PRODUCT}/${input.version}`, `node/${process.versions.node}`];
|
|
196
|
+
const agent = input.agent ? sanitizeAgentName(input.agent) : null;
|
|
197
|
+
if (agent) tokens.push(`agent/${agent}`);
|
|
198
|
+
return tokens.join(" ");
|
|
199
|
+
}
|
|
200
|
+
let userAgent;
|
|
201
|
+
/**
|
|
202
|
+
* Detect the agent driving the CLI and build the `User-Agent` from it, once per
|
|
203
|
+
* process. Called at startup, before any command runs.
|
|
204
|
+
*/
|
|
205
|
+
async function initUserAgent(version) {
|
|
206
|
+
const { agent } = await determineAgent();
|
|
207
|
+
userAgent = formatUserAgent({
|
|
208
|
+
version,
|
|
209
|
+
agent: agent?.name
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The `User-Agent` for API requests, `undefined` until {@link initUserAgent} has
|
|
214
|
+
* run — the API client then falls back to the runtime's own default rather than
|
|
215
|
+
* claiming a version we do not know.
|
|
216
|
+
*/
|
|
217
|
+
function getUserAgent() {
|
|
218
|
+
return userAgent;
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
160
221
|
//#region src/lib/api.ts
|
|
161
222
|
/** Optional override for the API base URL (used in tests and dev). */
|
|
162
223
|
function getApiBaseUrl() {
|
|
@@ -166,7 +227,8 @@ function getApiBaseUrl() {
|
|
|
166
227
|
function createApiClient(authToken) {
|
|
167
228
|
return createClient({
|
|
168
229
|
authToken,
|
|
169
|
-
baseUrl: getApiBaseUrl()
|
|
230
|
+
baseUrl: getApiBaseUrl(),
|
|
231
|
+
userAgent: getUserAgent
|
|
170
232
|
});
|
|
171
233
|
}
|
|
172
234
|
/**
|
|
@@ -2239,7 +2301,7 @@ function registerMediaUpdate(media) {
|
|
|
2239
2301
|
//#endregion
|
|
2240
2302
|
//#region src/commands/media/upload.ts
|
|
2241
2303
|
function registerMediaUpload(media) {
|
|
2242
|
-
media.command("upload").argument("<files...>", "Image or video files to upload").description("Upload images or videos and print their share URLs and Markdown embeds").addOption(tokenOption).addOption(mediaProjectPathOption).addOption(new Option("--branch <branch>", "Branch the media belongs to. Use this when the pull request does not exist yet: Argos publishes the media and comments on the pull request by itself once one opens for that branch")).addOption(new Option("--pr <number>", "Pull request to publish the media to. Argos keeps one comment on it listing every media uploaded, edited in place")).addOption(new Option("--state <state>", "Which half of a before/after pair these files are. Inferred from a file name ending in -before or -after").choices(["before", "after"])).addOption(new Option("--description <text>", "Prose shown under the media in the pull request comment")).addOption(new Option("--visibility <visibility>", "Who can open the share page. Defaults to
|
|
2304
|
+
media.command("upload").argument("<files...>", "Image or video files to upload").description("Upload images or videos and print their share URLs and Markdown embeds").addOption(tokenOption).addOption(mediaProjectPathOption).addOption(new Option("--branch <branch>", "Branch the media belongs to. Use this when the pull request does not exist yet: Argos publishes the media and comments on the pull request by itself once one opens for that branch")).addOption(new Option("--pr <number>", "Pull request to publish the media to. Argos keeps one comment on it listing every media uploaded, edited in place")).addOption(new Option("--state <state>", "Which half of a before/after pair these files are. Inferred from a file name ending in -before or -after").choices(["before", "after"])).addOption(new Option("--description <text>", "Prose shown under the media in the pull request comment")).addOption(new Option("--visibility <visibility>", "Who can open the share page. Defaults to your project's visibility in Argos: public for a public project, team for a private one").choices(["team", "public"])).addOption(new Option("--no-compress", "Upload images exactly as they are instead of converting them to WebP")).addOption(jsonOption).action(async (files, options) => {
|
|
2243
2305
|
const spinner = options.json ? null : ora(files.length === 1 ? "Uploading media" : `Uploading ${files.length} files`).start();
|
|
2244
2306
|
try {
|
|
2245
2307
|
const results = await uploadMedia({
|
|
@@ -3214,6 +3276,7 @@ function automationCommand(program) {
|
|
|
3214
3276
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
3215
3277
|
const rawPkg = await readFile(resolve(__dirname, "..", "package.json"), "utf8");
|
|
3216
3278
|
const pkg = JSON.parse(rawPkg);
|
|
3279
|
+
await initUserAgent(pkg.version);
|
|
3217
3280
|
program.name(pkg.name).description("Interact with and upload screenshots to Argos via command line.").version(pkg.version);
|
|
3218
3281
|
uploadCommand(program);
|
|
3219
3282
|
skipCommand(program);
|
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.
|
|
4
|
+
"version": "6.9.1",
|
|
5
5
|
"bin": {
|
|
6
6
|
"argos": "./bin/argos-cli.js"
|
|
7
7
|
},
|
|
@@ -34,8 +34,9 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@argos-ci/api-client": "0.
|
|
38
|
-
"@argos-ci/core": "6.8.
|
|
37
|
+
"@argos-ci/api-client": "0.31.0",
|
|
38
|
+
"@argos-ci/core": "6.8.2",
|
|
39
|
+
"@vercel/detect-agent": "^1.2.5",
|
|
39
40
|
"commander": "^15.0.0",
|
|
40
41
|
"open": "^11.0.0",
|
|
41
42
|
"ora": "^9.4.1"
|
|
@@ -53,5 +54,5 @@
|
|
|
53
54
|
"check-format": "prettier --check --ignore-unknown --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
|
|
54
55
|
"lint": "eslint ."
|
|
55
56
|
},
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "30a374b2c0f2b67b7a90fd4d22e395b70c191e0c"
|
|
57
58
|
}
|