@artifactshare/cli 0.1.0 → 0.1.2
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 +8 -6
- package/dist/index.d.ts +1 -6
- package/dist/index.js +426 -180
- package/package.json +1 -1
- package/skills/artifactshare/SKILL.md +5 -1
- package/skills/artifactshare/artifactshare.mdc +5 -1
package/README.md
CHANGED
|
@@ -9,19 +9,21 @@ Artifact Share hosts AI-built reports, documents, and static sites so you can sh
|
|
|
9
9
|
Requires Node.js 22 or later.
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
|
-
npx @artifactshare/cli publish ./report.html
|
|
12
|
+
npx --yes @artifactshare/cli publish ./report.html
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
`--yes` lets agents and CI fetch the package without stopping for an npx install prompt.
|
|
16
|
+
|
|
15
17
|
On the first run in an interactive terminal, the CLI prints a sign-in link — open it in your browser, and the publish completes and prints the share URL. Folders work too:
|
|
16
18
|
|
|
17
19
|
```sh
|
|
18
|
-
npx @artifactshare/cli publish ./dist --project "Weekly Reports"
|
|
19
|
-
npx @artifactshare/cli update <share-url> ./dist
|
|
20
|
+
npx --yes @artifactshare/cli publish ./dist --project "Weekly Reports"
|
|
21
|
+
npx --yes @artifactshare/cli update <share-url> ./dist
|
|
20
22
|
```
|
|
21
23
|
|
|
22
24
|
## Authentication
|
|
23
25
|
|
|
24
|
-
- **Interactive**: run `npx @artifactshare/cli login`, or just run any command — unauthenticated `publish` / `update` / `download` start the sign-in for you (the CLI prints a link and code to open in your browser).
|
|
26
|
+
- **Interactive**: run `npx --yes @artifactshare/cli login`, or just run any command — unauthenticated `publish` / `update` / `download` start the sign-in for you (the CLI prints a link and code to open in your browser).
|
|
25
27
|
- **CI / non-interactive**: set `ARTIFACTSHARE_TOKEN` (or pass `--token`). Without a token, non-interactive runs fail with `error.code: "auth_required"` instead of hanging.
|
|
26
28
|
- Multiple accounts: keep one local profile per account (`profiles list` / `profiles use <name>`), no re-linking required.
|
|
27
29
|
|
|
@@ -48,7 +50,7 @@ npx @artifactshare/cli update <share-url> ./dist
|
|
|
48
50
|
Teach your agent how to use Artifact Share once:
|
|
49
51
|
|
|
50
52
|
```sh
|
|
51
|
-
npx @artifactshare/cli skills install
|
|
53
|
+
npx --yes @artifactshare/cli skills install
|
|
52
54
|
```
|
|
53
55
|
|
|
54
56
|
This installs a skill (for Claude Code, Codex, and Cursor) that covers publishing, updating, and reading comments.
|
|
@@ -56,7 +58,7 @@ This installs a skill (for Claude Code, Codex, and Cursor) that covers publishin
|
|
|
56
58
|
All commands emit stable JSON when run non-interactively, piped, or with `--json`: success on stdout as `{ "schema_version": 1, "ok": true, "command": ..., "data": ... }`, failures on stderr as `{ "schema_version": 1, "ok": false, "command": ..., "error": ... }` with exit code 1. The `error` object carries a machine-readable `code`, a `hint`, and a structured `recovery` field (for example `{ "kind": "run_command", ... }`), so agents and scripts can branch and recover without parsing prose.
|
|
57
59
|
|
|
58
60
|
```sh
|
|
59
|
-
npx @artifactshare/cli publish ./dist --json
|
|
61
|
+
npx --yes @artifactshare/cli publish ./dist --json
|
|
60
62
|
```
|
|
61
63
|
|
|
62
64
|
## Links
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { chmod, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
2
|
+
import { appendFile, chmod, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
4
3
|
import { cli, define, lazy } from "gunshi";
|
|
5
|
-
import { Agent } from "undici";
|
|
6
4
|
import { spawn } from "node:child_process";
|
|
7
5
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
8
6
|
import { createReadStream } from "node:fs";
|
|
@@ -10,6 +8,7 @@ import { createHash } from "node:crypto";
|
|
|
10
8
|
import { setTimeout } from "node:timers/promises";
|
|
11
9
|
import { homedir } from "node:os";
|
|
12
10
|
const DEVICE_CLIENT_ID = "artifactshare-cli";
|
|
11
|
+
const CLI_INVOCATION = "npx --yes @artifactshare/cli";
|
|
13
12
|
const IGNORED_FILENAMES = new Set([
|
|
14
13
|
".DS_Store",
|
|
15
14
|
"Thumbs.db",
|
|
@@ -89,8 +88,8 @@ const UPDATE_OPTION_KEYS = new Set([
|
|
|
89
88
|
]);
|
|
90
89
|
//#endregion
|
|
91
90
|
//#region src/errors.ts
|
|
92
|
-
const REQUEST_ACCESS_COMMAND$1 =
|
|
93
|
-
const PROJECTS_LIST_COMMAND =
|
|
91
|
+
const REQUEST_ACCESS_COMMAND$1 = `${CLI_INVOCATION} request-access --json`;
|
|
92
|
+
const PROJECTS_LIST_COMMAND = `${CLI_INVOCATION} projects list --json`;
|
|
94
93
|
function apiError(body) {
|
|
95
94
|
const error = body?.error;
|
|
96
95
|
if (typeof error === "string") return {
|
|
@@ -104,7 +103,7 @@ function apiError(body) {
|
|
|
104
103
|
}
|
|
105
104
|
function mapApiError(status, body, options = {}) {
|
|
106
105
|
const { code: apiCode, message: apiMessage } = apiError(body);
|
|
107
|
-
if (status === 401) return options.authenticated ? tokenInvalidError() : authRequiredError();
|
|
106
|
+
if (status === 401) return options.authenticated ? tokenInvalidError() : authRequiredError(options.baseUrl ?? "https://artifactshare.com");
|
|
108
107
|
if (apiCode === "upload-not-allowed") return cliError({
|
|
109
108
|
code: "upload_not_allowed",
|
|
110
109
|
message: "This account cannot publish yet.",
|
|
@@ -179,7 +178,7 @@ function mapApiError(status, body, options = {}) {
|
|
|
179
178
|
code: "thread_not_found",
|
|
180
179
|
message: apiMessage ?? "Comment thread was not found.",
|
|
181
180
|
why: "No comment thread with that ID exists on this artifact.",
|
|
182
|
-
hint:
|
|
181
|
+
hint: `Run ${CLI_INVOCATION} comments list <artifact-id> --json and retry with a listed thread id.`,
|
|
183
182
|
agentRecoverable: true,
|
|
184
183
|
requiresHuman: false,
|
|
185
184
|
recovery: { kind: "change_input" }
|
|
@@ -206,7 +205,7 @@ function mapApiError(status, body, options = {}) {
|
|
|
206
205
|
code: "quote_not_found",
|
|
207
206
|
message: apiMessage ?? "The quoted text was not found in the artifact.",
|
|
208
207
|
why: "The --quote value must match the artifact text exactly.",
|
|
209
|
-
hint:
|
|
208
|
+
hint: `Copy the exact text from ${CLI_INVOCATION} artifacts get <artifact-id>, or add --quote-before / --quote-after to pick the right occurrence.`,
|
|
210
209
|
agentRecoverable: true,
|
|
211
210
|
requiresHuman: false,
|
|
212
211
|
recovery: { kind: "change_input" }
|
|
@@ -339,12 +338,15 @@ function serviceError(message) {
|
|
|
339
338
|
recovery: { kind: "retry_later" }
|
|
340
339
|
});
|
|
341
340
|
}
|
|
342
|
-
function
|
|
341
|
+
function tokensUrl(baseUrl) {
|
|
342
|
+
return `${baseUrl.replace(/\/$/, "")}/settings/tokens`;
|
|
343
|
+
}
|
|
344
|
+
function authRequiredError(baseUrl) {
|
|
343
345
|
return cliError({
|
|
344
346
|
code: "auth_required",
|
|
345
347
|
message: "Login is required.",
|
|
346
348
|
why: "No ARTIFACTSHARE_TOKEN or --token value was provided.",
|
|
347
|
-
hint:
|
|
349
|
+
hint: `Run ${CLI_INVOCATION} login --profile default, or set ARTIFACTSHARE_TOKEN. You can issue a token at ${tokensUrl(baseUrl)}.`,
|
|
348
350
|
agentRecoverable: false,
|
|
349
351
|
requiresHuman: true,
|
|
350
352
|
recovery: { kind: "ask_human" }
|
|
@@ -366,13 +368,13 @@ function authDeniedError(profile) {
|
|
|
366
368
|
code: "auth_denied",
|
|
367
369
|
message: "Login was denied.",
|
|
368
370
|
why: "The device login request was denied in the browser.",
|
|
369
|
-
hint: `Run
|
|
371
|
+
hint: `Run ${CLI_INVOCATION} login --profile ${profile} again if you want to sign in.`,
|
|
370
372
|
agentRecoverable: false,
|
|
371
373
|
requiresHuman: true,
|
|
372
374
|
recovery: { kind: "ask_human" },
|
|
373
375
|
details: {
|
|
374
376
|
profile,
|
|
375
|
-
suggested_command:
|
|
377
|
+
suggested_command: `${CLI_INVOCATION} login --profile ${profile}`
|
|
376
378
|
}
|
|
377
379
|
});
|
|
378
380
|
}
|
|
@@ -381,13 +383,13 @@ function authExpiredError(profile) {
|
|
|
381
383
|
code: "auth_expired",
|
|
382
384
|
message: "Login expired.",
|
|
383
385
|
why: "The device login was not completed before the code expired.",
|
|
384
|
-
hint: `Run
|
|
386
|
+
hint: `Run ${CLI_INVOCATION} login --profile ${profile} again.`,
|
|
385
387
|
agentRecoverable: false,
|
|
386
388
|
requiresHuman: true,
|
|
387
389
|
recovery: { kind: "ask_human" },
|
|
388
390
|
details: {
|
|
389
391
|
profile,
|
|
390
|
-
suggested_command:
|
|
392
|
+
suggested_command: `${CLI_INVOCATION} login --profile ${profile}`
|
|
391
393
|
}
|
|
392
394
|
});
|
|
393
395
|
}
|
|
@@ -412,7 +414,7 @@ function profileNotFoundError(profile) {
|
|
|
412
414
|
code: "profile_not_found",
|
|
413
415
|
message: `Profile "${profile}" was not found.`,
|
|
414
416
|
why: "No saved CLI profile has that name.",
|
|
415
|
-
hint: `Run
|
|
417
|
+
hint: `Run ${CLI_INVOCATION} profiles list to see saved profiles, or ${CLI_INVOCATION} login --profile ${profile} to create it.`,
|
|
416
418
|
agentRecoverable: true,
|
|
417
419
|
requiresHuman: false,
|
|
418
420
|
recovery: { kind: "change_input" },
|
|
@@ -448,12 +450,12 @@ function unknownCommandError(command) {
|
|
|
448
450
|
code: "unknown_command",
|
|
449
451
|
message: `Unknown command: ${command}`,
|
|
450
452
|
why: "The command is not part of Artifact Share CLI.",
|
|
451
|
-
hint:
|
|
453
|
+
hint: `Run ${CLI_INVOCATION} --help.`,
|
|
452
454
|
agentRecoverable: true,
|
|
453
455
|
requiresHuman: false,
|
|
454
456
|
recovery: {
|
|
455
457
|
kind: "run_command",
|
|
456
|
-
command:
|
|
458
|
+
command: `${CLI_INVOCATION} --help`
|
|
457
459
|
}
|
|
458
460
|
});
|
|
459
461
|
}
|
|
@@ -856,11 +858,12 @@ let insecureLocalhostDispatcher;
|
|
|
856
858
|
function baseUrlOf(options) {
|
|
857
859
|
return String(options.baseUrl ?? process.env.ARTIFACTSHARE_BASE_URL ?? "https://artifactshare.com").replace(/\/$/, "");
|
|
858
860
|
}
|
|
859
|
-
function requestConfig(options) {
|
|
861
|
+
async function requestConfig(options) {
|
|
860
862
|
if (!insecureLocalhostEnabled(options)) return { init: {} };
|
|
861
863
|
const baseUrl = baseUrlOf(options);
|
|
862
864
|
const url = new URL(baseUrl);
|
|
863
865
|
if (url.protocol !== "https:" || !isLocalHostname(url.hostname)) return { error: validationError("--insecure-localhost only works with local HTTPS base URLs.", "Use it only with https://localhost, https://127.0.0.1, or https://[::1].") };
|
|
866
|
+
const { Agent } = await import("undici");
|
|
864
867
|
return { init: { dispatcher: insecureLocalhostDispatcher ??= new Agent({ connect: { rejectUnauthorized: false } }) } };
|
|
865
868
|
}
|
|
866
869
|
function insecureLocalhostEnabled(options) {
|
|
@@ -970,21 +973,60 @@ function resolveDestination(options, config) {
|
|
|
970
973
|
code: "destination_required",
|
|
971
974
|
message: "A publish destination is required.",
|
|
972
975
|
why: "Non-interactive publish never guesses a project or home destination.",
|
|
973
|
-
hint: "Retry with --project-id <id>, configure .artifactshare/config.json, or pass --home.",
|
|
976
|
+
hint: "Retry with --project-id <id>, configure .artifactshare/config.local.json, or pass --home.",
|
|
974
977
|
agentRecoverable: true,
|
|
975
978
|
requiresHuman: false,
|
|
976
979
|
recovery: { kind: "change_input" }
|
|
977
980
|
}) };
|
|
978
981
|
}
|
|
979
982
|
const PROJECT_CONFIG_PATH = ".artifactshare/config.json";
|
|
980
|
-
|
|
981
|
-
|
|
983
|
+
const PROJECT_CONFIG_LOCAL_PATH = ".artifactshare/config.local.json";
|
|
984
|
+
function projectConfigLocalPath(cwd = process.cwd()) {
|
|
985
|
+
return resolve(cwd, PROJECT_CONFIG_LOCAL_PATH);
|
|
986
|
+
}
|
|
987
|
+
function relativeProjectConfigPath(cwd, directory, filename) {
|
|
988
|
+
const absolute = join(directory, filename);
|
|
989
|
+
const rel = relative(cwd, absolute);
|
|
990
|
+
return rel.startsWith("..") ? absolute : rel;
|
|
991
|
+
}
|
|
992
|
+
async function resolveProjectConfig(cwd = process.cwd()) {
|
|
993
|
+
let current = resolve(cwd);
|
|
994
|
+
const root = resolve(current, "/");
|
|
995
|
+
while (true) {
|
|
996
|
+
const localPath = join(current, PROJECT_CONFIG_LOCAL_PATH);
|
|
997
|
+
const sharedPath = join(current, PROJECT_CONFIG_PATH);
|
|
998
|
+
const localRaw = await readJsonFile(localPath);
|
|
999
|
+
if (localRaw !== null) return {
|
|
1000
|
+
config: localRaw,
|
|
1001
|
+
raw: localRaw,
|
|
1002
|
+
kind: "local",
|
|
1003
|
+
path: relativeProjectConfigPath(cwd, current, PROJECT_CONFIG_LOCAL_PATH),
|
|
1004
|
+
directory: current
|
|
1005
|
+
};
|
|
1006
|
+
const sharedRaw = await readJsonFile(sharedPath);
|
|
1007
|
+
if (sharedRaw !== null) return {
|
|
1008
|
+
config: sharedRaw,
|
|
1009
|
+
raw: sharedRaw,
|
|
1010
|
+
kind: "shared",
|
|
1011
|
+
path: relativeProjectConfigPath(cwd, current, PROJECT_CONFIG_PATH),
|
|
1012
|
+
directory: current
|
|
1013
|
+
};
|
|
1014
|
+
if (current === root) break;
|
|
1015
|
+
current = dirname(current);
|
|
1016
|
+
}
|
|
1017
|
+
return {
|
|
1018
|
+
config: null,
|
|
1019
|
+
raw: null,
|
|
1020
|
+
kind: null,
|
|
1021
|
+
path: null,
|
|
1022
|
+
directory: null
|
|
1023
|
+
};
|
|
982
1024
|
}
|
|
983
|
-
async function
|
|
984
|
-
return await readJsonFile(
|
|
1025
|
+
async function readProjectConfigAtDirectory(directory, kind) {
|
|
1026
|
+
return await readJsonFile(join(directory, kind === "local" ? PROJECT_CONFIG_LOCAL_PATH : PROJECT_CONFIG_PATH));
|
|
985
1027
|
}
|
|
986
|
-
async function
|
|
987
|
-
return await readJsonFile(
|
|
1028
|
+
async function readRawLocalProjectConfig(cwd = process.cwd()) {
|
|
1029
|
+
return await readJsonFile(projectConfigLocalPath(cwd));
|
|
988
1030
|
}
|
|
989
1031
|
function configString(value) {
|
|
990
1032
|
return nonEmpty(typeof value === "string" ? value : void 0) ?? null;
|
|
@@ -1169,7 +1211,7 @@ function configHome() {
|
|
|
1169
1211
|
}
|
|
1170
1212
|
//#endregion
|
|
1171
1213
|
//#region src/credentials.ts
|
|
1172
|
-
async function resolveCredential(options,
|
|
1214
|
+
async function resolveCredential(options, projectInput = null) {
|
|
1173
1215
|
const envToken = nonEmpty(process.env.ARTIFACTSHARE_TOKEN);
|
|
1174
1216
|
const optionToken = nonEmpty(options.token);
|
|
1175
1217
|
const profile = nonEmpty(options.profile);
|
|
@@ -1190,18 +1232,36 @@ async function resolveCredential(options, projectConfig = null) {
|
|
|
1190
1232
|
token: envToken
|
|
1191
1233
|
};
|
|
1192
1234
|
const globalConfig = await readGlobalConfig();
|
|
1193
|
-
if (profile) return await resolveProfileCredential("profile", profile, options, globalConfig);
|
|
1194
|
-
const
|
|
1195
|
-
|
|
1235
|
+
if (profile) return await resolveProfileCredential("profile", profile, options, globalConfig, null, null);
|
|
1236
|
+
const project = normalizeProjectInput(projectInput);
|
|
1237
|
+
const projectProfile = nonEmpty(project.config?.default_profile);
|
|
1238
|
+
if (projectProfile) return await resolveProfileCredential(project.kind === "local" ? "local_config" : "project_config", projectProfile, options, globalConfig, project.path, project.kind);
|
|
1196
1239
|
const globalProfile = nonEmpty(globalConfig?.default_profile);
|
|
1197
|
-
if (globalProfile) return await resolveProfileCredential("global_profile", globalProfile, options, globalConfig);
|
|
1240
|
+
if (globalProfile) return await resolveProfileCredential("global_profile", globalProfile, options, globalConfig, null, null);
|
|
1198
1241
|
return {
|
|
1199
1242
|
ok: false,
|
|
1200
1243
|
source: "none",
|
|
1201
|
-
error: authRequiredError()
|
|
1244
|
+
error: authRequiredError(baseUrlOf(options))
|
|
1202
1245
|
};
|
|
1203
1246
|
}
|
|
1204
|
-
|
|
1247
|
+
function normalizeProjectInput(projectInput) {
|
|
1248
|
+
if (!projectInput) return {
|
|
1249
|
+
config: null,
|
|
1250
|
+
raw: null,
|
|
1251
|
+
kind: null,
|
|
1252
|
+
path: null,
|
|
1253
|
+
directory: null
|
|
1254
|
+
};
|
|
1255
|
+
if ("kind" in projectInput) return projectInput;
|
|
1256
|
+
return {
|
|
1257
|
+
config: projectInput,
|
|
1258
|
+
raw: projectInput,
|
|
1259
|
+
kind: "shared",
|
|
1260
|
+
path: null,
|
|
1261
|
+
directory: null
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
async function resolveProfileCredential(source, profile, options, globalConfig, configPath, configKind) {
|
|
1205
1265
|
const profileBaseUrl = nonEmpty(globalConfig?.profiles?.[profile]?.base_url);
|
|
1206
1266
|
if (profileBaseUrl && !nonEmpty(options.baseUrl) && !nonEmpty(process.env.ARTIFACTSHARE_BASE_URL)) options.baseUrl = profileBaseUrl;
|
|
1207
1267
|
const stored = await readProfileToken(profile, options);
|
|
@@ -1211,11 +1271,46 @@ async function resolveProfileCredential(source, profile, options, globalConfig)
|
|
|
1211
1271
|
profile,
|
|
1212
1272
|
token: stored.token
|
|
1213
1273
|
};
|
|
1214
|
-
return profileAuthRequired(source, profile, stored.reason);
|
|
1274
|
+
return profileAuthRequired(source, profile, stored.reason, options, globalConfig, configPath, configKind);
|
|
1215
1275
|
}
|
|
1216
|
-
function profileAuthRequired(source, profile, reason) {
|
|
1217
|
-
const
|
|
1276
|
+
async function profileAuthRequired(source, profile, reason, options, globalConfig, configPath, configKind) {
|
|
1277
|
+
const baseUrl = baseUrlOf(options);
|
|
1278
|
+
const url = tokensUrl(baseUrl);
|
|
1279
|
+
const error = authRequiredError(baseUrl);
|
|
1218
1280
|
const why = reason === "unavailable" ? `No safe token store is available for profile "${profile}".` : `No saved credential was found for profile "${profile}".`;
|
|
1281
|
+
const alternative = await findAlternativeProfileWithToken(globalConfig, options, profile);
|
|
1282
|
+
const details = {
|
|
1283
|
+
credential_source: source,
|
|
1284
|
+
profile
|
|
1285
|
+
};
|
|
1286
|
+
if (configPath) {
|
|
1287
|
+
details.config_path = configPath;
|
|
1288
|
+
if (configKind) details.config_kind = configKind;
|
|
1289
|
+
}
|
|
1290
|
+
if (alternative) {
|
|
1291
|
+
const switchHint = profileSwitchHint(alternative);
|
|
1292
|
+
return {
|
|
1293
|
+
ok: false,
|
|
1294
|
+
source,
|
|
1295
|
+
profile,
|
|
1296
|
+
error: {
|
|
1297
|
+
...error,
|
|
1298
|
+
why,
|
|
1299
|
+
hint: `${switchHint} Or run ${CLI_INVOCATION} login --profile ${profile}, or set ARTIFACTSHARE_TOKEN. You can issue a token at ${url}.`,
|
|
1300
|
+
agent_recoverable: true,
|
|
1301
|
+
requires_human: false,
|
|
1302
|
+
recovery: {
|
|
1303
|
+
kind: "run_command",
|
|
1304
|
+
command: `${CLI_INVOCATION} profiles use ${alternative}`
|
|
1305
|
+
},
|
|
1306
|
+
details: {
|
|
1307
|
+
...details,
|
|
1308
|
+
alternative_profile: alternative,
|
|
1309
|
+
suggested_profile_command: `${CLI_INVOCATION} profiles use ${alternative}`
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1219
1314
|
return {
|
|
1220
1315
|
ok: false,
|
|
1221
1316
|
source,
|
|
@@ -1223,14 +1318,66 @@ function profileAuthRequired(source, profile, reason) {
|
|
|
1223
1318
|
error: {
|
|
1224
1319
|
...error,
|
|
1225
1320
|
why,
|
|
1226
|
-
hint: `Run
|
|
1227
|
-
details
|
|
1228
|
-
credential_source: source,
|
|
1229
|
-
profile
|
|
1230
|
-
}
|
|
1321
|
+
hint: `Run ${CLI_INVOCATION} login --profile ${profile}, or set ARTIFACTSHARE_TOKEN. You can issue a token at ${url}.`,
|
|
1322
|
+
details
|
|
1231
1323
|
}
|
|
1232
1324
|
};
|
|
1233
1325
|
}
|
|
1326
|
+
function profileSwitchHint(profile) {
|
|
1327
|
+
return `Run with --profile ${profile}, init --profile ${profile}, or profiles use ${profile}.`;
|
|
1328
|
+
}
|
|
1329
|
+
async function findAlternativeProfileWithToken(globalConfig, options, excludeProfile) {
|
|
1330
|
+
const profiles = globalConfig?.profiles ?? {};
|
|
1331
|
+
const candidates = [];
|
|
1332
|
+
for (const name of Object.keys(profiles)) {
|
|
1333
|
+
if (name === excludeProfile) continue;
|
|
1334
|
+
const baseUrl = nonEmpty(profiles[name]?.base_url) ?? baseUrlOf(options);
|
|
1335
|
+
candidates.push({
|
|
1336
|
+
name,
|
|
1337
|
+
localDev: isLocalDevUrl(baseUrl)
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
if (candidates.length === 0) return null;
|
|
1341
|
+
candidates.sort((left, right) => {
|
|
1342
|
+
if (left.localDev !== right.localDev) return left.localDev ? 1 : -1;
|
|
1343
|
+
return left.name.localeCompare(right.name);
|
|
1344
|
+
});
|
|
1345
|
+
for (const candidate of candidates) {
|
|
1346
|
+
const baseUrl = nonEmpty(profiles[candidate.name]?.base_url) ?? baseUrlOf(options);
|
|
1347
|
+
if ((await readProfileToken(candidate.name, {
|
|
1348
|
+
...options,
|
|
1349
|
+
baseUrl
|
|
1350
|
+
})).ok) return candidate.name;
|
|
1351
|
+
}
|
|
1352
|
+
return null;
|
|
1353
|
+
}
|
|
1354
|
+
function isLocalDevUrl(baseUrl) {
|
|
1355
|
+
try {
|
|
1356
|
+
return isLocalHostname(new URL(baseUrl).hostname);
|
|
1357
|
+
} catch {
|
|
1358
|
+
return false;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
async function resolveEffectiveDefaultProfile(projectInput = null) {
|
|
1362
|
+
const project = normalizeProjectInput(projectInput);
|
|
1363
|
+
const projectProfile = nonEmpty(project.config?.default_profile);
|
|
1364
|
+
if (projectProfile) return {
|
|
1365
|
+
profile: projectProfile,
|
|
1366
|
+
source: project.kind === "local" ? "local" : "project",
|
|
1367
|
+
path: project.path
|
|
1368
|
+
};
|
|
1369
|
+
const globalProfile = nonEmpty((await readGlobalConfig())?.default_profile);
|
|
1370
|
+
if (globalProfile) return {
|
|
1371
|
+
profile: globalProfile,
|
|
1372
|
+
source: "global",
|
|
1373
|
+
path: null
|
|
1374
|
+
};
|
|
1375
|
+
return {
|
|
1376
|
+
profile: null,
|
|
1377
|
+
source: "none",
|
|
1378
|
+
path: null
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1234
1381
|
//#endregion
|
|
1235
1382
|
//#region src/command-runners/artifacts-get.ts
|
|
1236
1383
|
async function runArtifactsGet(parsed, mode) {
|
|
@@ -1242,9 +1389,9 @@ async function runArtifactsGet(parsed, mode) {
|
|
|
1242
1389
|
if (offset.error) return writeFailure(command, offset.error, mode, 1);
|
|
1243
1390
|
const include = parseIncludeOptions(parsed.options.include);
|
|
1244
1391
|
if (include.error) return writeFailure(command, include.error, mode, 1);
|
|
1245
|
-
const credential = await resolveCredential(parsed.options, await
|
|
1392
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
1246
1393
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
1247
|
-
const request = requestConfig(parsed.options);
|
|
1394
|
+
const request = await requestConfig(parsed.options);
|
|
1248
1395
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1249
1396
|
const url = apiUrl(`/api/cli/artifacts/${encodeURIComponent(artifactId)}`, baseUrlOf(parsed.options));
|
|
1250
1397
|
if (offset.value !== void 0) url.searchParams.set("offset", offset.value);
|
|
@@ -1269,9 +1416,9 @@ async function runCommentsList(parsed, mode) {
|
|
|
1269
1416
|
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
1270
1417
|
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
1271
1418
|
const artifactId = target.artifactId;
|
|
1272
|
-
const credential = await resolveCredential(parsed.options, await
|
|
1419
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
1273
1420
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
1274
|
-
const request = requestConfig(parsed.options);
|
|
1421
|
+
const request = await requestConfig(parsed.options);
|
|
1275
1422
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1276
1423
|
const result = await apiGet(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, parsed.options, request.init, { artifactTarget: true });
|
|
1277
1424
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
@@ -1295,9 +1442,9 @@ async function runCommentsPost(parsed, mode) {
|
|
|
1295
1442
|
const quote = parsed.options.quote;
|
|
1296
1443
|
if (quote !== void 0 && replyTo !== void 0) return writeFailure(command, validationError("Choose either --quote or --reply-to.", "A quote anchors a new thread; a reply joins an existing thread. Remove one and retry."), mode, 1);
|
|
1297
1444
|
if (quote === void 0 && (parsed.options.quoteBefore !== void 0 || parsed.options.quoteAfter !== void 0)) return writeFailure(command, validationError("--quote-before and --quote-after require --quote.", "Add --quote <text>, or remove the context options."), mode, 1);
|
|
1298
|
-
const credential = await resolveCredential(parsed.options, await
|
|
1445
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
1299
1446
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
1300
|
-
const request = requestConfig(parsed.options);
|
|
1447
|
+
const request = await requestConfig(parsed.options);
|
|
1301
1448
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1302
1449
|
const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, {
|
|
1303
1450
|
body,
|
|
@@ -1319,12 +1466,16 @@ async function runCommentsPost(parsed, mode) {
|
|
|
1319
1466
|
}
|
|
1320
1467
|
//#endregion
|
|
1321
1468
|
//#region src/command-runners/doctor.ts
|
|
1322
|
-
const LOGIN_COMMAND =
|
|
1323
|
-
const REQUEST_ACCESS_COMMAND =
|
|
1469
|
+
const LOGIN_COMMAND = `${CLI_INVOCATION} login`;
|
|
1470
|
+
const REQUEST_ACCESS_COMMAND = `${CLI_INVOCATION} request-access`;
|
|
1324
1471
|
function bearerTokenBlocksLogin(data) {
|
|
1325
1472
|
return data.auth.credential_source === "env" || data.auth.credential_source === "token_option";
|
|
1326
1473
|
}
|
|
1327
1474
|
function resolveDoctorNextCommand(data) {
|
|
1475
|
+
if (data.config.local.code === "token_store_unsafe") {
|
|
1476
|
+
if (bearerTokenBlocksLogin(data)) return null;
|
|
1477
|
+
return LOGIN_COMMAND;
|
|
1478
|
+
}
|
|
1328
1479
|
if (data.config.project.code === "token_store_unsafe") {
|
|
1329
1480
|
if (bearerTokenBlocksLogin(data)) return null;
|
|
1330
1481
|
return LOGIN_COMMAND;
|
|
@@ -1345,14 +1496,13 @@ function doctorDataWithNextCommand(data) {
|
|
|
1345
1496
|
}
|
|
1346
1497
|
async function runDoctor(parsed, mode) {
|
|
1347
1498
|
const command = "doctor";
|
|
1348
|
-
const
|
|
1349
|
-
const
|
|
1350
|
-
const
|
|
1351
|
-
const destination = resolveDestination(parsed.options, config);
|
|
1499
|
+
const project = await resolveProjectConfig();
|
|
1500
|
+
const credential = await resolveCredential(parsed.options, project);
|
|
1501
|
+
const destination = resolveDestination(parsed.options, project.config);
|
|
1352
1502
|
const data = {
|
|
1353
1503
|
next_command: null,
|
|
1354
1504
|
base_url: baseUrlOf(parsed.options),
|
|
1355
|
-
config: await configDiagnostics(
|
|
1505
|
+
config: await configDiagnostics(project),
|
|
1356
1506
|
auth: {
|
|
1357
1507
|
credential_source: credential.source,
|
|
1358
1508
|
...credential.profile ? { profile: credential.profile } : {},
|
|
@@ -1380,7 +1530,7 @@ async function runDoctor(parsed, mode) {
|
|
|
1380
1530
|
data.auth.hint = credential.error.hint;
|
|
1381
1531
|
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
1382
1532
|
}
|
|
1383
|
-
const request = requestConfig(parsed.options);
|
|
1533
|
+
const request = await requestConfig(parsed.options);
|
|
1384
1534
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1385
1535
|
const response = await fetch(apiUrl("/api/cli/doctor", baseUrlOf(parsed.options)), {
|
|
1386
1536
|
headers: { Authorization: `Bearer ${credential.token}` },
|
|
@@ -1413,24 +1563,52 @@ async function runDoctor(parsed, mode) {
|
|
|
1413
1563
|
}
|
|
1414
1564
|
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
1415
1565
|
}
|
|
1416
|
-
async function configDiagnostics(
|
|
1566
|
+
async function configDiagnostics(project) {
|
|
1417
1567
|
const globalConfig = await readGlobalConfig();
|
|
1418
|
-
const
|
|
1568
|
+
const cwd = process.cwd();
|
|
1569
|
+
const directory = project.directory;
|
|
1570
|
+
const localRaw = directory ? await readProjectConfigAtDirectory(directory, "local") : null;
|
|
1571
|
+
const sharedRaw = directory ? await readProjectConfigAtDirectory(directory, "shared") : null;
|
|
1419
1572
|
return {
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
default_profile: configString(rawProjectConfig?.default_profile),
|
|
1423
|
-
default_project_id: configString(rawProjectConfig?.default_project_id),
|
|
1424
|
-
...unsafeKey ? {
|
|
1425
|
-
code: "token_store_unsafe",
|
|
1426
|
-
hint: `Remove "${unsafeKey}" from ${PROJECT_CONFIG_PATH} and run npx @artifactshare/cli login instead; the working-directory config must never hold secrets.`
|
|
1427
|
-
} : {}
|
|
1428
|
-
},
|
|
1573
|
+
local: fileDiagnostics(localRaw, directory ? relativeProjectConfigPath(cwd, directory, PROJECT_CONFIG_LOCAL_PATH) : null),
|
|
1574
|
+
project: fileDiagnostics(sharedRaw, directory ? relativeProjectConfigPath(cwd, directory, PROJECT_CONFIG_PATH) : null),
|
|
1429
1575
|
global: {
|
|
1430
1576
|
present: globalConfig !== null,
|
|
1431
1577
|
default_profile: configString(globalConfig?.default_profile),
|
|
1432
1578
|
profile_count: Object.keys(globalConfig?.profiles ?? {}).length
|
|
1433
|
-
}
|
|
1579
|
+
},
|
|
1580
|
+
effective: effectiveDiagnostics(project, globalConfig)
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
function fileDiagnostics(raw, path) {
|
|
1584
|
+
const unsafeKey = Object.keys(raw ?? {}).find((key) => key.toLowerCase().includes("token"));
|
|
1585
|
+
return {
|
|
1586
|
+
present: raw !== null,
|
|
1587
|
+
path,
|
|
1588
|
+
default_profile: configString(raw?.default_profile),
|
|
1589
|
+
default_project_id: configString(raw?.default_project_id),
|
|
1590
|
+
...unsafeKey ? {
|
|
1591
|
+
code: "token_store_unsafe",
|
|
1592
|
+
hint: `Remove "${unsafeKey}" from ${path ?? "the working-directory config"} and run ${CLI_INVOCATION} login instead; the working-directory config must never hold secrets.`
|
|
1593
|
+
} : {}
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
function effectiveDiagnostics(project, globalConfig) {
|
|
1597
|
+
const projectProfile = configString(project.config?.default_profile);
|
|
1598
|
+
const projectProjectId = configString(project.config?.default_project_id);
|
|
1599
|
+
const globalProfile = configString(globalConfig?.default_profile);
|
|
1600
|
+
const defaultProfile = projectProfile ?? globalProfile;
|
|
1601
|
+
const defaultProfileSource = projectProfile ? project.kind === "local" ? "local" : "project" : globalProfile ? "global" : "none";
|
|
1602
|
+
const defaultProfilePath = defaultProfileSource === "local" || defaultProfileSource === "project" ? project.path : null;
|
|
1603
|
+
const defaultProjectId = projectProjectId;
|
|
1604
|
+
const defaultProjectIdSource = projectProjectId ? project.kind === "local" ? "local" : "project" : "none";
|
|
1605
|
+
return {
|
|
1606
|
+
default_profile: defaultProfile,
|
|
1607
|
+
default_profile_source: defaultProfileSource,
|
|
1608
|
+
default_profile_path: defaultProfilePath,
|
|
1609
|
+
default_project_id: defaultProjectId,
|
|
1610
|
+
default_project_id_source: defaultProjectIdSource,
|
|
1611
|
+
default_project_id_path: defaultProjectIdSource === "local" || defaultProjectIdSource === "project" ? project.path : null
|
|
1434
1612
|
};
|
|
1435
1613
|
}
|
|
1436
1614
|
//#endregion
|
|
@@ -1601,7 +1779,7 @@ function artifactKindForFile(path) {
|
|
|
1601
1779
|
//#endregion
|
|
1602
1780
|
//#region src/command-runners/login.ts
|
|
1603
1781
|
async function performDeviceLogin(profile, options, mode) {
|
|
1604
|
-
const request = requestConfig(options);
|
|
1782
|
+
const request = await requestConfig(options);
|
|
1605
1783
|
if (request.error) return {
|
|
1606
1784
|
ok: false,
|
|
1607
1785
|
error: request.error
|
|
@@ -1652,24 +1830,30 @@ async function performDeviceLogin(profile, options, mode) {
|
|
|
1652
1830
|
error: tokenStoreUnavailableError(profile)
|
|
1653
1831
|
};
|
|
1654
1832
|
await writeProfileConfig(profile, options, saved.store, whoami);
|
|
1833
|
+
const effective = await resolveEffectiveDefaultProfile(await resolveProjectConfig());
|
|
1834
|
+
const data = {
|
|
1835
|
+
profile,
|
|
1836
|
+
status: "completed",
|
|
1837
|
+
credential_source: "profile",
|
|
1838
|
+
token_store: saved.store,
|
|
1839
|
+
user: { email: whoami.email },
|
|
1840
|
+
workspace: {
|
|
1841
|
+
id: whoami.workspace_id,
|
|
1842
|
+
hosted_domain: whoami.hosted_domain
|
|
1843
|
+
},
|
|
1844
|
+
verification_uri: code.verification_uri,
|
|
1845
|
+
verification_uri_complete: code.verification_uri_complete ?? null,
|
|
1846
|
+
user_code: code.user_code,
|
|
1847
|
+
expires_at: sessionExpiresAt,
|
|
1848
|
+
interval_seconds: code.interval
|
|
1849
|
+
};
|
|
1850
|
+
if (effective.profile && effective.profile !== profile) {
|
|
1851
|
+
data.effective_default_profile = effective.profile;
|
|
1852
|
+
data.profile_switch_hint = `Saved credentials for "${profile}", but the current default profile is "${effective.profile}". Run with --profile ${profile}, init --profile ${profile}, or profiles use ${profile} before the next command.`;
|
|
1853
|
+
}
|
|
1655
1854
|
return {
|
|
1656
1855
|
ok: true,
|
|
1657
|
-
data
|
|
1658
|
-
profile,
|
|
1659
|
-
status: "completed",
|
|
1660
|
-
credential_source: "profile",
|
|
1661
|
-
token_store: saved.store,
|
|
1662
|
-
user: { email: whoami.email },
|
|
1663
|
-
workspace: {
|
|
1664
|
-
id: whoami.workspace_id,
|
|
1665
|
-
hosted_domain: whoami.hosted_domain
|
|
1666
|
-
},
|
|
1667
|
-
verification_uri: code.verification_uri,
|
|
1668
|
-
verification_uri_complete: code.verification_uri_complete ?? null,
|
|
1669
|
-
user_code: code.user_code,
|
|
1670
|
-
expires_at: sessionExpiresAt,
|
|
1671
|
-
interval_seconds: code.interval
|
|
1672
|
-
}
|
|
1856
|
+
data
|
|
1673
1857
|
};
|
|
1674
1858
|
}
|
|
1675
1859
|
async function runLogin(parsed, mode) {
|
|
@@ -1689,7 +1873,7 @@ async function requestDeviceCode(options, init) {
|
|
|
1689
1873
|
}).catch((error) => ({ networkError: error }));
|
|
1690
1874
|
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
1691
1875
|
const body = await readJson(response);
|
|
1692
|
-
if (!response.ok) return { error: mapApiError(response.status, body) };
|
|
1876
|
+
if (!response.ok) return { error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) }) };
|
|
1693
1877
|
if (!isDeviceCodeResponse(body)) return { error: validationError("Device login response was invalid.", "Retry login. If this repeats, report the response shape.", "service_error") };
|
|
1694
1878
|
return body;
|
|
1695
1879
|
}
|
|
@@ -1724,7 +1908,7 @@ async function pollForToken(options, code, init, profile, deadline) {
|
|
|
1724
1908
|
}
|
|
1725
1909
|
if (authError === "access_denied") return { error: authDeniedError(profile) };
|
|
1726
1910
|
if (authError === "expired_token") return { error: authExpiredError(profile) };
|
|
1727
|
-
return { error: mapApiError(response.status, body) };
|
|
1911
|
+
return { error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) }) };
|
|
1728
1912
|
}
|
|
1729
1913
|
return { error: authExpiredError(profile) };
|
|
1730
1914
|
}
|
|
@@ -1792,9 +1976,9 @@ async function runDownload(parsed, mode, isRetry = false) {
|
|
|
1792
1976
|
const target = parseArtifactTarget(parsed.positionals[0], "download", "Pass an artifact ID or share URL to download.");
|
|
1793
1977
|
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
1794
1978
|
const artifactId = target.artifactId;
|
|
1795
|
-
const credential = await resolveCredential(parsed.options, await
|
|
1979
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
1796
1980
|
if (!credential.ok) return handleCredentialFailure(command, credential, parsed.options, mode, () => runDownload(parsed, mode, true), isRetry);
|
|
1797
|
-
const request = requestConfig(parsed.options);
|
|
1981
|
+
const request = await requestConfig(parsed.options);
|
|
1798
1982
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1799
1983
|
const baseUrl = baseUrlOf(parsed.options);
|
|
1800
1984
|
const manifestUrl = apiUrl(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/download`, baseUrl);
|
|
@@ -1865,36 +2049,103 @@ async function runDownload(parsed, mode, isRetry = false) {
|
|
|
1865
2049
|
}, mode);
|
|
1866
2050
|
}
|
|
1867
2051
|
//#endregion
|
|
2052
|
+
//#region src/git-exclude.ts
|
|
2053
|
+
async function ensureGitExclude(cwd) {
|
|
2054
|
+
const git = await findGitDir(cwd);
|
|
2055
|
+
if (!git) return {
|
|
2056
|
+
applied: false,
|
|
2057
|
+
warning: null
|
|
2058
|
+
};
|
|
2059
|
+
const excludePath = join(git.gitDir, "info", "exclude");
|
|
2060
|
+
const excludeEntry = gitPattern(relative(git.workTree, resolve(cwd, PROJECT_CONFIG_LOCAL_PATH)));
|
|
2061
|
+
try {
|
|
2062
|
+
const existing = await readFile(excludePath, "utf8").catch(() => "");
|
|
2063
|
+
if (excludeLines(existing).includes(excludeEntry)) return {
|
|
2064
|
+
applied: false,
|
|
2065
|
+
warning: null
|
|
2066
|
+
};
|
|
2067
|
+
await mkdir(dirname(excludePath), { recursive: true });
|
|
2068
|
+
await appendFile(excludePath, `${existing.endsWith("\n") || existing.length === 0 ? "" : "\n"}${excludeEntry}\n`, "utf8");
|
|
2069
|
+
return {
|
|
2070
|
+
applied: true,
|
|
2071
|
+
warning: null
|
|
2072
|
+
};
|
|
2073
|
+
} catch {
|
|
2074
|
+
return {
|
|
2075
|
+
applied: false,
|
|
2076
|
+
warning: `Could not update ${excludePath}; keep ${PROJECT_CONFIG_LOCAL_PATH} out of version control manually.`
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
function excludeLines(text) {
|
|
2081
|
+
return text.split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
2082
|
+
}
|
|
2083
|
+
async function findGitDir(start) {
|
|
2084
|
+
let current = resolve(start);
|
|
2085
|
+
const root = resolve(current, "/");
|
|
2086
|
+
while (true) {
|
|
2087
|
+
const gitDir = await resolveGitDir(join(current, ".git"));
|
|
2088
|
+
if (gitDir) return {
|
|
2089
|
+
gitDir,
|
|
2090
|
+
workTree: current
|
|
2091
|
+
};
|
|
2092
|
+
if (current === root) return null;
|
|
2093
|
+
current = dirname(current);
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
async function resolveGitDir(gitPath) {
|
|
2097
|
+
const info = await stat(gitPath).catch(() => null);
|
|
2098
|
+
if (!info) return null;
|
|
2099
|
+
if (info.isDirectory()) return gitPath;
|
|
2100
|
+
if (!info.isFile()) return null;
|
|
2101
|
+
const text = await readFile(gitPath, "utf8").catch(() => null);
|
|
2102
|
+
if (!text) return null;
|
|
2103
|
+
const gitDir = text.match(/^gitdir:\s*(.+)$/m)?.[1]?.trim();
|
|
2104
|
+
if (!gitDir) return null;
|
|
2105
|
+
const resolvedGitDir = resolve(dirname(gitPath), gitDir);
|
|
2106
|
+
const commonDir = await readFile(join(resolvedGitDir, "commondir"), "utf8").then((value) => value.trim()).catch(() => null);
|
|
2107
|
+
return commonDir ? resolve(resolvedGitDir, commonDir) : resolvedGitDir;
|
|
2108
|
+
}
|
|
2109
|
+
function gitPattern(path) {
|
|
2110
|
+
return path.split("\\").join("/");
|
|
2111
|
+
}
|
|
2112
|
+
//#endregion
|
|
1868
2113
|
//#region src/command-runners/init.ts
|
|
1869
2114
|
async function runInit(parsed, mode) {
|
|
1870
2115
|
const command = "init";
|
|
1871
2116
|
const profile = nonEmpty(parsed.options.profile);
|
|
1872
2117
|
const projectId = nonEmpty(parsed.options.projectId);
|
|
1873
|
-
const
|
|
1874
|
-
if (!profile && !projectId) return writeSuccess(command, initData(false,
|
|
2118
|
+
const resolved = await resolveProjectConfig();
|
|
2119
|
+
if (!profile && !projectId) return writeSuccess(command, initData(false, resolved.raw ?? {}, resolved), mode);
|
|
1875
2120
|
if (profile) {
|
|
1876
2121
|
if (!configHome()) return writeFailure(command, tokenStoreUnavailableError(profile), mode, 1);
|
|
1877
2122
|
const globalConfig = await readGlobalConfig();
|
|
1878
2123
|
if (!Object.hasOwn(globalConfig?.profiles ?? {}, profile)) return writeFailure(command, profileNotFoundError(profile), mode, 1);
|
|
1879
2124
|
}
|
|
1880
2125
|
const next = {
|
|
1881
|
-
...
|
|
2126
|
+
...await readRawLocalProjectConfig() ?? {},
|
|
1882
2127
|
...profile ? { default_profile: profile } : {},
|
|
1883
2128
|
...projectId ? { default_project_id: projectId } : {}
|
|
1884
2129
|
};
|
|
1885
|
-
const path =
|
|
2130
|
+
const path = projectConfigLocalPath();
|
|
1886
2131
|
await mkdir(dirname(path), { recursive: true });
|
|
1887
2132
|
await writeFile(path, `${JSON.stringify(next, null, 2)}\n`);
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
2133
|
+
const gitExclude = await ensureGitExclude(process.cwd());
|
|
2134
|
+
const data = initData(true, next, resolved);
|
|
2135
|
+
delete data.read_path;
|
|
2136
|
+
if (gitExclude.warning) data.git_exclude_warning = gitExclude.warning;
|
|
2137
|
+
if (gitExclude.applied) data.git_exclude_applied = true;
|
|
2138
|
+
return writeSuccess(command, data, mode);
|
|
2139
|
+
}
|
|
2140
|
+
function initData(written, config, resolved) {
|
|
1891
2141
|
return {
|
|
1892
|
-
path:
|
|
2142
|
+
path: PROJECT_CONFIG_LOCAL_PATH,
|
|
1893
2143
|
written,
|
|
1894
2144
|
config: {
|
|
1895
2145
|
default_profile: configString(config.default_profile),
|
|
1896
2146
|
default_project_id: configString(config.default_project_id)
|
|
1897
|
-
}
|
|
2147
|
+
},
|
|
2148
|
+
...resolved.path ? { read_path: resolved.path } : {}
|
|
1898
2149
|
};
|
|
1899
2150
|
}
|
|
1900
2151
|
//#endregion
|
|
@@ -1925,12 +2176,12 @@ async function runProfilesList(parsed, mode) {
|
|
|
1925
2176
|
default_profile: defaultProfile,
|
|
1926
2177
|
profiles
|
|
1927
2178
|
}, mode);
|
|
1928
|
-
if (!mode.json && profiles.length === 0) writeText(
|
|
2179
|
+
if (!mode.json && profiles.length === 0) writeText(`No profiles yet. Run ${CLI_INVOCATION} login --profile default to create one.\n`);
|
|
1929
2180
|
}
|
|
1930
2181
|
async function runProfilesUse(parsed, mode) {
|
|
1931
2182
|
const command = "profiles use";
|
|
1932
2183
|
const name = nonEmpty(parsed.positionals[0]);
|
|
1933
|
-
if (!name) return writeFailure(command, validationError("A profile name is required.",
|
|
2184
|
+
if (!name) return writeFailure(command, validationError("A profile name is required.", `Run ${CLI_INVOCATION} profiles use <name>.`), mode, 1);
|
|
1934
2185
|
if (!configHome()) return writeFailure(command, tokenStoreUnavailableError(), mode, 1);
|
|
1935
2186
|
const config = await readGlobalConfig() ?? {};
|
|
1936
2187
|
if (!Object.hasOwn(config.profiles ?? {}, name)) return writeFailure(command, profileNotFoundError(name), mode, 1);
|
|
@@ -1964,14 +2215,14 @@ async function fetchProjects(token, options, init) {
|
|
|
1964
2215
|
}
|
|
1965
2216
|
async function runProjectsList(parsed, mode) {
|
|
1966
2217
|
const command = "projects list";
|
|
1967
|
-
const
|
|
1968
|
-
const credential = await resolveCredential(parsed.options,
|
|
2218
|
+
const projectConfig = await resolveProjectConfig();
|
|
2219
|
+
const credential = await resolveCredential(parsed.options, projectConfig);
|
|
1969
2220
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
1970
|
-
const request = requestConfig(parsed.options);
|
|
2221
|
+
const request = await requestConfig(parsed.options);
|
|
1971
2222
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1972
2223
|
const result = await fetchProjects(credential.token, parsed.options, request.init);
|
|
1973
2224
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
1974
|
-
const defaultProjectId = configString(config?.default_project_id);
|
|
2225
|
+
const defaultProjectId = configString(projectConfig.config?.default_project_id);
|
|
1975
2226
|
const projects = result.projects.map((project) => ({
|
|
1976
2227
|
...project,
|
|
1977
2228
|
is_default: project.id === defaultProjectId
|
|
@@ -1994,8 +2245,8 @@ async function runPublish(parsed, mode, isRetry = false) {
|
|
|
1994
2245
|
publishKey = (typeof parsed.options.key === "string" ? parsed.options.key : "").trim();
|
|
1995
2246
|
if (publishKey.length === 0 || publishKey.length > MAX_PUBLISH_KEY_LENGTH) return writeFailure(command, validationError(`--key must be 1-${MAX_PUBLISH_KEY_LENGTH} characters after trimming.`, "Pass a short stable identifier, like a job name or PR number."), mode, 1);
|
|
1996
2247
|
}
|
|
1997
|
-
const
|
|
1998
|
-
const credential = await resolveCredential(parsed.options,
|
|
2248
|
+
const project = await resolveProjectConfig();
|
|
2249
|
+
const credential = await resolveCredential(parsed.options, project);
|
|
1999
2250
|
if (!credential.ok) return handleCredentialFailure(command, credential, parsed.options, mode, () => runPublish(parsed, mode, true), isRetry);
|
|
2000
2251
|
const baseUrl = baseUrlOf(parsed.options);
|
|
2001
2252
|
const hasProjectFlag = "project" in parsed.options;
|
|
@@ -2007,12 +2258,12 @@ async function runPublish(parsed, mode, isRetry = false) {
|
|
|
2007
2258
|
const conflict = destinationConflictError(parsed.options);
|
|
2008
2259
|
if (conflict) return writeFailure(command, conflict, mode, 1);
|
|
2009
2260
|
} else {
|
|
2010
|
-
const earlyDestination = resolveDestination(parsed.options, config);
|
|
2261
|
+
const earlyDestination = resolveDestination(parsed.options, project.config);
|
|
2011
2262
|
if (earlyDestination.error) return writeFailure(command, earlyDestination.error, mode, 1);
|
|
2012
2263
|
}
|
|
2013
2264
|
const fileStat = await stat(targetPath).catch(() => null);
|
|
2014
2265
|
if (!fileStat) return writeFailure(command, validationError("Path was not found.", `Check the path and retry: ${targetPath}`), mode, 1);
|
|
2015
|
-
const request = requestConfig(parsed.options);
|
|
2266
|
+
const request = await requestConfig(parsed.options);
|
|
2016
2267
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2017
2268
|
if (hasProjectFlag && projectName) {
|
|
2018
2269
|
const resolved = await resolveProjectIdByName(projectName, credential.token, parsed.options, request.init);
|
|
@@ -2023,7 +2274,7 @@ async function runPublish(parsed, mode, isRetry = false) {
|
|
|
2023
2274
|
projectId: resolved.projectId
|
|
2024
2275
|
};
|
|
2025
2276
|
}
|
|
2026
|
-
const destination = resolveDestination(destinationOptions, config);
|
|
2277
|
+
const destination = resolveDestination(destinationOptions, project.config);
|
|
2027
2278
|
if (destination.error) return writeFailure(command, destination.error, mode, 1);
|
|
2028
2279
|
const initialForm = new FormData();
|
|
2029
2280
|
const grantEmails = arrayOption(parsed.options.grantEmail);
|
|
@@ -2090,9 +2341,9 @@ async function runRequestAccess(parsed, mode) {
|
|
|
2090
2341
|
const command = "request-access";
|
|
2091
2342
|
const note = parsed.options.note;
|
|
2092
2343
|
if (note !== void 0 && note.length > NOTE_MAX) return writeFailure(command, validationError(`A note can be at most ${NOTE_MAX} characters.`, "Shorten --note and retry."), mode, 1);
|
|
2093
|
-
const credential = await resolveCredential(parsed.options, await
|
|
2344
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2094
2345
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2095
|
-
const request = requestConfig(parsed.options);
|
|
2346
|
+
const request = await requestConfig(parsed.options);
|
|
2096
2347
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2097
2348
|
const result = await apiPost("/api/cli/request-access", credential.token, { note }, parsed.options, request.init);
|
|
2098
2349
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
@@ -2114,9 +2365,9 @@ async function runResolve(parsed, mode) {
|
|
|
2114
2365
|
const command = "resolve";
|
|
2115
2366
|
const value = parsed.positionals[0]?.trim();
|
|
2116
2367
|
if (!value) return writeFailure(command, validationError("Resolve value is required.", "Pass a URL, ID, title, or project name to resolve."), mode, 1);
|
|
2117
|
-
const credential = await resolveCredential(parsed.options, await
|
|
2368
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2118
2369
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2119
|
-
const request = requestConfig(parsed.options);
|
|
2370
|
+
const request = await requestConfig(parsed.options);
|
|
2120
2371
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2121
2372
|
const url = apiUrl("/api/cli/resolve", baseUrlOf(parsed.options));
|
|
2122
2373
|
url.searchParams.set("q", value);
|
|
@@ -2403,12 +2654,12 @@ async function runUpdate(parsed, mode, isRetry = false) {
|
|
|
2403
2654
|
if (unsupportedOption) return writeFailure(command, validationError(`Update does not accept --${unsupportedOption}.`, "Update only adds a new version. Remove unsupported options and retry."), mode, 1);
|
|
2404
2655
|
const artifactId = resolveArtifactId(artifactInput);
|
|
2405
2656
|
if (!artifactId) return writeFailure(command, targetResolutionError(artifactInput, "update"), mode, 1);
|
|
2406
|
-
const credential = await resolveCredential(parsed.options, await
|
|
2657
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2407
2658
|
if (!credential.ok) return handleCredentialFailure(command, credential, parsed.options, mode, () => runUpdate(parsed, mode, true), isRetry);
|
|
2408
2659
|
const fileStat = await stat(targetPath).catch(() => null);
|
|
2409
2660
|
if (!fileStat) return writeFailure(command, validationError("Path was not found.", `Check the path and retry: ${targetPath}`), mode, 1);
|
|
2410
2661
|
const baseUrl = baseUrlOf(parsed.options);
|
|
2411
|
-
const request = requestConfig(parsed.options);
|
|
2662
|
+
const request = await requestConfig(parsed.options);
|
|
2412
2663
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2413
2664
|
const upload = await prepareUploadPayload(targetPath, fileStat);
|
|
2414
2665
|
if (upload.error) return writeFailure(command, upload.error, mode, 1);
|
|
@@ -2443,9 +2694,9 @@ async function runUpdate(parsed, mode, isRetry = false) {
|
|
|
2443
2694
|
//#region src/command-runners/whoami.ts
|
|
2444
2695
|
async function runWhoami(parsed, mode) {
|
|
2445
2696
|
const command = "whoami";
|
|
2446
|
-
const credential = await resolveCredential(parsed.options, await
|
|
2697
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2447
2698
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2448
|
-
const request = requestConfig(parsed.options);
|
|
2699
|
+
const request = await requestConfig(parsed.options);
|
|
2449
2700
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2450
2701
|
const whoami = await apiGet("/api/cli/whoami", credential.token, parsed.options, request.init);
|
|
2451
2702
|
if (whoami.error) return writeFailure(command, whoami.error, mode, 1);
|
|
@@ -2535,14 +2786,11 @@ async function doctorRunner(ctx) {
|
|
|
2535
2786
|
function parentCommandRunner(command) {
|
|
2536
2787
|
return (ctx) => {
|
|
2537
2788
|
const parsed = parsedArgsFromContext(command, ctx);
|
|
2538
|
-
writeFailure(command, validationError("A subcommand is required.", `Run
|
|
2789
|
+
writeFailure(command, validationError("A subcommand is required.", `Run ${CLI_INVOCATION} ${command} <${(SUBCOMMANDS[command] ?? []).join(" | ")}>.`), outputMode(parsed.options), 1);
|
|
2539
2790
|
};
|
|
2540
2791
|
}
|
|
2541
2792
|
//#endregion
|
|
2542
2793
|
//#region src/index.ts
|
|
2543
|
-
function isCliEntrypoint() {
|
|
2544
|
-
return Boolean(process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href);
|
|
2545
|
-
}
|
|
2546
2794
|
async function main(rawArgv) {
|
|
2547
2795
|
const argv = joinLeadingDashValues(rawArgv);
|
|
2548
2796
|
const command = commandNameFromArgv(argv);
|
|
@@ -2634,24 +2882,24 @@ const entryCommand = define({
|
|
|
2634
2882
|
description: "Artifact Share CLI",
|
|
2635
2883
|
toKebab: true,
|
|
2636
2884
|
args: commonArgs,
|
|
2637
|
-
examples: `npx @artifactshare/cli publish <path> --project-id <id> --json
|
|
2638
|
-
npx @artifactshare/cli update <artifact-id-or-url> <path> --json
|
|
2639
|
-
npx @artifactshare/cli resolve <url-id-or-title> --json
|
|
2640
|
-
npx @artifactshare/cli artifacts get <artifact-id-or-url> --json
|
|
2641
|
-
npx @artifactshare/cli comments list <artifact-id-or-url> --json
|
|
2642
|
-
npx @artifactshare/cli comments post <artifact-id-or-url> --body "<text>" --json
|
|
2643
|
-
npx @artifactshare/cli download <artifact-id-or-url> --output ./artifact --json
|
|
2644
|
-
npx @artifactshare/cli login --profile default
|
|
2645
|
-
npx @artifactshare/cli profiles list --json
|
|
2646
|
-
npx @artifactshare/cli profiles use <name> --json
|
|
2647
|
-
npx @artifactshare/cli projects list --json
|
|
2648
|
-
npx @artifactshare/cli skills install --tool codex --json
|
|
2649
|
-
npx @artifactshare/cli skills list --json
|
|
2650
|
-
npx @artifactshare/cli init --profile <name> --project-id <id> --json
|
|
2651
|
-
npx @artifactshare/cli publish <path> --home --json
|
|
2652
|
-
npx @artifactshare/cli request-access --json
|
|
2653
|
-
npx @artifactshare/cli whoami --json
|
|
2654
|
-
npx @artifactshare/cli doctor --json
|
|
2885
|
+
examples: `npx --yes @artifactshare/cli publish <path> --project-id <id> --json
|
|
2886
|
+
npx --yes @artifactshare/cli update <artifact-id-or-url> <path> --json
|
|
2887
|
+
npx --yes @artifactshare/cli resolve <url-id-or-title> --json
|
|
2888
|
+
npx --yes @artifactshare/cli artifacts get <artifact-id-or-url> --json
|
|
2889
|
+
npx --yes @artifactshare/cli comments list <artifact-id-or-url> --json
|
|
2890
|
+
npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body "<text>" --json
|
|
2891
|
+
npx --yes @artifactshare/cli download <artifact-id-or-url> --output ./artifact --json
|
|
2892
|
+
npx --yes @artifactshare/cli login --profile default
|
|
2893
|
+
npx --yes @artifactshare/cli profiles list --json
|
|
2894
|
+
npx --yes @artifactshare/cli profiles use <name> --json
|
|
2895
|
+
npx --yes @artifactshare/cli projects list --json
|
|
2896
|
+
npx --yes @artifactshare/cli skills install --tool codex --json
|
|
2897
|
+
npx --yes @artifactshare/cli skills list --json
|
|
2898
|
+
npx --yes @artifactshare/cli init --profile <name> --project-id <id> --json
|
|
2899
|
+
npx --yes @artifactshare/cli publish <path> --home --json
|
|
2900
|
+
npx --yes @artifactshare/cli request-access --json
|
|
2901
|
+
npx --yes @artifactshare/cli whoami --json
|
|
2902
|
+
npx --yes @artifactshare/cli doctor --json
|
|
2655
2903
|
|
|
2656
2904
|
Common failures:
|
|
2657
2905
|
auth_required Set ARTIFACTSHARE_TOKEN or pass --token
|
|
@@ -2665,8 +2913,8 @@ const loginDefinition = define({
|
|
|
2665
2913
|
description: "Sign in with device authorization and save a CLI profile.",
|
|
2666
2914
|
toKebab: true,
|
|
2667
2915
|
args: commonArgs,
|
|
2668
|
-
examples: `npx @artifactshare/cli login --profile default
|
|
2669
|
-
npx @artifactshare/cli login --profile client-a --json
|
|
2916
|
+
examples: `npx --yes @artifactshare/cli login --profile default
|
|
2917
|
+
npx --yes @artifactshare/cli login --profile client-a --json
|
|
2670
2918
|
|
|
2671
2919
|
Common failures:
|
|
2672
2920
|
auth_denied The browser approval was denied
|
|
@@ -2715,7 +2963,7 @@ const publishDefinition = define({
|
|
|
2715
2963
|
description: "Stable key for create-or-update: the first publish creates the artifact, repeats add versions. Not a secret; it appears in logs and JSON"
|
|
2716
2964
|
}
|
|
2717
2965
|
},
|
|
2718
|
-
examples: `npx @artifactshare/cli publish report.html --project-id <id> --key nightly-report --json
|
|
2966
|
+
examples: `npx --yes @artifactshare/cli publish report.html --project-id <id> --key nightly-report --json
|
|
2719
2967
|
|
|
2720
2968
|
Common failures:
|
|
2721
2969
|
auth_required Set ARTIFACTSHARE_TOKEN before publish
|
|
@@ -2765,8 +3013,8 @@ const resolveDefinition = define({
|
|
|
2765
3013
|
description: "Share URL, sandbox URL, ID, title, or project name"
|
|
2766
3014
|
}
|
|
2767
3015
|
},
|
|
2768
|
-
examples: `npx @artifactshare/cli resolve "Weekly report" --json
|
|
2769
|
-
npx @artifactshare/cli resolve https://artifactshare.com/a/abc123def4 --json
|
|
3016
|
+
examples: `npx --yes @artifactshare/cli resolve "Weekly report" --json
|
|
3017
|
+
npx --yes @artifactshare/cli resolve https://artifactshare.com/a/abc123def4 --json
|
|
2770
3018
|
|
|
2771
3019
|
Use resolve before write commands when a user gives a title or project name.
|
|
2772
3020
|
Pass the returned artifact id or project id to the next command.
|
|
@@ -2798,8 +3046,8 @@ const downloadDefinition = define({
|
|
|
2798
3046
|
description: "Allow writing into an existing output directory"
|
|
2799
3047
|
}
|
|
2800
3048
|
},
|
|
2801
|
-
examples: `npx @artifactshare/cli download abc123def4 --json
|
|
2802
|
-
npx @artifactshare/cli download https://artifactshare.com/a/abc123def4 --output ./artifact --json
|
|
3049
|
+
examples: `npx --yes @artifactshare/cli download abc123def4 --json
|
|
3050
|
+
npx --yes @artifactshare/cli download https://artifactshare.com/a/abc123def4 --output ./artifact --json
|
|
2803
3051
|
|
|
2804
3052
|
Use resolve first when a user gives a title or project name, then pass the id here.
|
|
2805
3053
|
Download writes files to a directory so the result can be inspected or passed to update.
|
|
@@ -2838,9 +3086,9 @@ const artifactsDefinition = define({
|
|
|
2838
3086
|
description: "Extra data to include: versions or comments"
|
|
2839
3087
|
}
|
|
2840
3088
|
},
|
|
2841
|
-
examples: `npx @artifactshare/cli artifacts get abc123def4 --json
|
|
2842
|
-
npx @artifactshare/cli artifacts get https://artifactshare.com/a/abc123def4 --include versions --include comments --json
|
|
2843
|
-
npx @artifactshare/cli artifacts get abc123def4 --offset 200000 --json
|
|
3089
|
+
examples: `npx --yes @artifactshare/cli artifacts get abc123def4 --json
|
|
3090
|
+
npx --yes @artifactshare/cli artifacts get https://artifactshare.com/a/abc123def4 --include versions --include comments --json
|
|
3091
|
+
npx --yes @artifactshare/cli artifacts get abc123def4 --offset 200000 --json
|
|
2844
3092
|
|
|
2845
3093
|
Use resolve first when a user gives a title or project name, then pass the id here.
|
|
2846
3094
|
If truncated is true, call again with --offset set to next_offset before updating.
|
|
@@ -2851,7 +3099,7 @@ Common failures:
|
|
|
2851
3099
|
unsupported_kind Use download for static sites or other multi-file artifacts
|
|
2852
3100
|
validation_failed Check --offset and --include values`
|
|
2853
3101
|
}), artifactsGetRunner) },
|
|
2854
|
-
examples: `npx @artifactshare/cli artifacts get <artifact-id-or-url> --json
|
|
3102
|
+
examples: `npx --yes @artifactshare/cli artifacts get <artifact-id-or-url> --json
|
|
2855
3103
|
|
|
2856
3104
|
Use artifacts get to read back Markdown or HTML before update.`,
|
|
2857
3105
|
run: parentCommandRunner("artifacts")
|
|
@@ -2868,7 +3116,7 @@ const commentsListDefinition = define({
|
|
|
2868
3116
|
description: "Artifact ID, /a/<id> share URL, or <id>.sandbox.* URL"
|
|
2869
3117
|
}
|
|
2870
3118
|
},
|
|
2871
|
-
examples: `npx @artifactshare/cli comments list abc123def4 --json
|
|
3119
|
+
examples: `npx --yes @artifactshare/cli comments list abc123def4 --json
|
|
2872
3120
|
|
|
2873
3121
|
Returns up to 50 threads (open threads first); has_more reports whether more exist.
|
|
2874
3122
|
Each thread carries its messages, status, and quoted-text anchor when present.
|
|
@@ -2914,9 +3162,9 @@ const commentsPostDefinition = define({
|
|
|
2914
3162
|
description: "Text just after the quote, to pick the right occurrence"
|
|
2915
3163
|
}
|
|
2916
3164
|
},
|
|
2917
|
-
examples: `npx @artifactshare/cli comments post abc123def4 --body "Looks good" --json
|
|
2918
|
-
npx @artifactshare/cli comments post abc123def4 --body "Done" --reply-to <thread-id> --json
|
|
2919
|
-
npx @artifactshare/cli comments post abc123def4 --body "Fix this" --quote "exact text" --json
|
|
3165
|
+
examples: `npx --yes @artifactshare/cli comments post abc123def4 --body "Looks good" --json
|
|
3166
|
+
npx --yes @artifactshare/cli comments post abc123def4 --body "Done" --reply-to <thread-id> --json
|
|
3167
|
+
npx --yes @artifactshare/cli comments post abc123def4 --body "Fix this" --quote "exact text" --json
|
|
2920
3168
|
|
|
2921
3169
|
Copy quote text from artifacts get so it matches the artifact exactly.
|
|
2922
3170
|
|
|
@@ -2937,8 +3185,8 @@ const commentsDefinition = define({
|
|
|
2937
3185
|
list: lazyCommand(commentsListDefinition, commentsListRunner),
|
|
2938
3186
|
post: lazyCommand(commentsPostDefinition, commentsPostRunner)
|
|
2939
3187
|
},
|
|
2940
|
-
examples: `npx @artifactshare/cli comments list <artifact-id-or-url> --json
|
|
2941
|
-
npx @artifactshare/cli comments post <artifact-id-or-url> --body "<text>" --json`,
|
|
3188
|
+
examples: `npx --yes @artifactshare/cli comments list <artifact-id-or-url> --json
|
|
3189
|
+
npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body "<text>" --json`,
|
|
2942
3190
|
run: parentCommandRunner("comments")
|
|
2943
3191
|
});
|
|
2944
3192
|
const profilesListDefinition = define({
|
|
@@ -2946,7 +3194,7 @@ const profilesListDefinition = define({
|
|
|
2946
3194
|
description: "List saved CLI profiles and the default profile.",
|
|
2947
3195
|
toKebab: true,
|
|
2948
3196
|
args: commonArgs,
|
|
2949
|
-
examples: `npx @artifactshare/cli profiles list --json
|
|
3197
|
+
examples: `npx --yes @artifactshare/cli profiles list --json
|
|
2950
3198
|
|
|
2951
3199
|
token_present shows whether a saved credential exists; token values are never printed.`
|
|
2952
3200
|
});
|
|
@@ -2961,7 +3209,7 @@ const profilesUseDefinition = define({
|
|
|
2961
3209
|
description: "Profile name to make the default"
|
|
2962
3210
|
}
|
|
2963
3211
|
},
|
|
2964
|
-
examples: `npx @artifactshare/cli profiles use client-a --json
|
|
3212
|
+
examples: `npx --yes @artifactshare/cli profiles use client-a --json
|
|
2965
3213
|
|
|
2966
3214
|
Common failures:
|
|
2967
3215
|
profile_not_found Run profiles list to see saved profiles, or login --profile <name>`
|
|
@@ -2975,8 +3223,8 @@ const profilesDefinition = define({
|
|
|
2975
3223
|
list: lazyCommand(profilesListDefinition, profilesListRunner),
|
|
2976
3224
|
use: lazyCommand(profilesUseDefinition, profilesUseRunner)
|
|
2977
3225
|
},
|
|
2978
|
-
examples: `npx @artifactshare/cli profiles list --json
|
|
2979
|
-
npx @artifactshare/cli profiles use client-a --json`,
|
|
3226
|
+
examples: `npx --yes @artifactshare/cli profiles list --json
|
|
3227
|
+
npx --yes @artifactshare/cli profiles use client-a --json`,
|
|
2980
3228
|
run: parentCommandRunner("profiles")
|
|
2981
3229
|
});
|
|
2982
3230
|
const projectsDefinition = define({
|
|
@@ -2989,12 +3237,12 @@ const projectsDefinition = define({
|
|
|
2989
3237
|
description: "List projects you can publish into.",
|
|
2990
3238
|
toKebab: true,
|
|
2991
3239
|
args: commonArgs,
|
|
2992
|
-
examples: `npx @artifactshare/cli projects list --json
|
|
3240
|
+
examples: `npx --yes @artifactshare/cli projects list --json
|
|
2993
3241
|
|
|
2994
3242
|
is_default marks the working-directory default project from .artifactshare/config.json.
|
|
2995
3243
|
Use a project id with publish --project-id or init --project-id.`
|
|
2996
3244
|
}), projectsListRunner) },
|
|
2997
|
-
examples: `npx @artifactshare/cli projects list --json`,
|
|
3245
|
+
examples: `npx --yes @artifactshare/cli projects list --json`,
|
|
2998
3246
|
run: parentCommandRunner("projects")
|
|
2999
3247
|
});
|
|
3000
3248
|
const skillsToolArgs = {
|
|
@@ -3028,8 +3276,8 @@ const skillsInstallDefinition = define({
|
|
|
3028
3276
|
description: "Overwrite an existing unmanaged file or reinstall the same version"
|
|
3029
3277
|
}
|
|
3030
3278
|
},
|
|
3031
|
-
examples: `npx @artifactshare/cli skills install --tool codex --scope project --json
|
|
3032
|
-
npx @artifactshare/cli skills install --tool claude --tool cursor --dry-run --json
|
|
3279
|
+
examples: `npx --yes @artifactshare/cli skills install --tool codex --scope project --json
|
|
3280
|
+
npx --yes @artifactshare/cli skills install --tool claude --tool cursor --dry-run --json
|
|
3033
3281
|
|
|
3034
3282
|
Writes a managed SKILL.md (codex, claude) or Cursor rule (cursor).
|
|
3035
3283
|
Files without the Artifact Share managed marker are never overwritten without --force.
|
|
@@ -3043,7 +3291,7 @@ const skillsListDefinition = define({
|
|
|
3043
3291
|
description: "Show skill install status for each supported agent tool.",
|
|
3044
3292
|
toKebab: true,
|
|
3045
3293
|
args: commonArgs,
|
|
3046
|
-
examples: `npx @artifactshare/cli skills list --json
|
|
3294
|
+
examples: `npx --yes @artifactshare/cli skills list --json
|
|
3047
3295
|
|
|
3048
3296
|
Reports each tool and scope with detection, install state, and update availability.
|
|
3049
3297
|
Runs locally; no network or authentication is used.`
|
|
@@ -3061,8 +3309,8 @@ const skillsUpdateDefinition = define({
|
|
|
3061
3309
|
description: "Rewrite managed files even when the version already matches"
|
|
3062
3310
|
}
|
|
3063
3311
|
},
|
|
3064
|
-
examples: `npx @artifactshare/cli skills update --json
|
|
3065
|
-
npx @artifactshare/cli skills update --tool codex --scope user --json
|
|
3312
|
+
examples: `npx --yes @artifactshare/cli skills update --json
|
|
3313
|
+
npx --yes @artifactshare/cli skills update --tool codex --scope user --json
|
|
3066
3314
|
|
|
3067
3315
|
Only files created by skills install (managed marker present) are updated.
|
|
3068
3316
|
|
|
@@ -3077,8 +3325,8 @@ const skillsRemoveDefinition = define({
|
|
|
3077
3325
|
...commonArgs,
|
|
3078
3326
|
...skillsToolArgs
|
|
3079
3327
|
},
|
|
3080
|
-
examples: `npx @artifactshare/cli skills remove --json
|
|
3081
|
-
npx @artifactshare/cli skills remove --tool cursor --json
|
|
3328
|
+
examples: `npx --yes @artifactshare/cli skills remove --json
|
|
3329
|
+
npx --yes @artifactshare/cli skills remove --tool cursor --json
|
|
3082
3330
|
|
|
3083
3331
|
Only files created by skills install are deleted; unmanaged files are skipped.`
|
|
3084
3332
|
});
|
|
@@ -3093,8 +3341,8 @@ const skillsDefinition = define({
|
|
|
3093
3341
|
update: lazyCommand(skillsUpdateDefinition, skillsUpdateRunner),
|
|
3094
3342
|
remove: lazyCommand(skillsRemoveDefinition, skillsRemoveRunner)
|
|
3095
3343
|
},
|
|
3096
|
-
examples: `npx @artifactshare/cli skills install --tool codex --json
|
|
3097
|
-
npx @artifactshare/cli skills list --json`,
|
|
3344
|
+
examples: `npx --yes @artifactshare/cli skills install --tool codex --json
|
|
3345
|
+
npx --yes @artifactshare/cli skills list --json`,
|
|
3098
3346
|
run: parentCommandRunner("skills")
|
|
3099
3347
|
});
|
|
3100
3348
|
const initDefinition = define({
|
|
@@ -3109,8 +3357,8 @@ const initDefinition = define({
|
|
|
3109
3357
|
description: "Default project for publish in this directory"
|
|
3110
3358
|
}
|
|
3111
3359
|
},
|
|
3112
|
-
examples: `npx @artifactshare/cli init --profile client-a --project-id <id> --json
|
|
3113
|
-
npx @artifactshare/cli init --json
|
|
3360
|
+
examples: `npx --yes @artifactshare/cli init --profile client-a --project-id <id> --json
|
|
3361
|
+
npx --yes @artifactshare/cli init --json
|
|
3114
3362
|
|
|
3115
3363
|
Without flags, init reports the current config and writes nothing.
|
|
3116
3364
|
Secrets are never written to .artifactshare/config.json.
|
|
@@ -3130,8 +3378,8 @@ const requestAccessDefinition = define({
|
|
|
3130
3378
|
description: "Optional message for the Artifact Share team (max 2000 characters)"
|
|
3131
3379
|
}
|
|
3132
3380
|
},
|
|
3133
|
-
examples: `npx @artifactshare/cli request-access --json
|
|
3134
|
-
npx @artifactshare/cli request-access --note "Publishing weekly reports for my team" --json
|
|
3381
|
+
examples: `npx --yes @artifactshare/cli request-access --json
|
|
3382
|
+
npx --yes @artifactshare/cli request-access --note "Publishing weekly reports for my team" --json
|
|
3135
3383
|
|
|
3136
3384
|
Joining the waitlist does not enable publishing immediately; an operator opens it.
|
|
3137
3385
|
Re-running updates your note without creating a duplicate entry.
|
|
@@ -3151,11 +3399,9 @@ const doctorDefinition = define({
|
|
|
3151
3399
|
toKebab: true,
|
|
3152
3400
|
args: commonArgs
|
|
3153
3401
|
});
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
});
|
|
3159
|
-
}
|
|
3402
|
+
const cliArgv = process.argv.slice(2);
|
|
3403
|
+
main(cliArgv).catch((error) => {
|
|
3404
|
+
writeFailure("unknown", unexpectedError(error), outputModeFromArgv(cliArgv), 1);
|
|
3405
|
+
});
|
|
3160
3406
|
//#endregion
|
|
3161
|
-
export {
|
|
3407
|
+
export {};
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ description: Publish, update, and read back shared artifacts with the Artifact S
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
<!-- artifactshare-skill
|
|
7
|
-
version:
|
|
7
|
+
version: 3
|
|
8
8
|
managed: true
|
|
9
9
|
-->
|
|
10
10
|
|
|
@@ -17,6 +17,10 @@ designed for agents: every command supports `--json` with a stable contract.
|
|
|
17
17
|
Run commands with `npx --yes @artifactshare/cli`. When unsure about a
|
|
18
18
|
command or flag, read `npx --yes @artifactshare/cli --help` first.
|
|
19
19
|
|
|
20
|
+
Use the CLI whenever the artifact already exists as a local file or folder.
|
|
21
|
+
The remote MCP tools accept HTML or Markdown source strings; they cannot read
|
|
22
|
+
paths like `/Users/.../report.html` from the user's filesystem.
|
|
23
|
+
|
|
20
24
|
## Output contract
|
|
21
25
|
|
|
22
26
|
- Always pass `--json`. Success prints `{"schema_version":1,"ok":true,"command":...,"data":...}` to stdout; failure prints `{"ok":false,"error":...}` to stderr with exit code 1.
|
|
@@ -4,7 +4,7 @@ alwaysApply: false
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
<!-- artifactshare-skill
|
|
7
|
-
version:
|
|
7
|
+
version: 3
|
|
8
8
|
managed: true
|
|
9
9
|
-->
|
|
10
10
|
|
|
@@ -15,6 +15,10 @@ sites) with versions and comments. Use `npx --yes @artifactshare/cli` to
|
|
|
15
15
|
publish from the terminal, and read
|
|
16
16
|
`npx --yes @artifactshare/cli --help` before choosing a command.
|
|
17
17
|
|
|
18
|
+
Use the CLI for local files and folders. The remote MCP tools accept HTML or
|
|
19
|
+
Markdown source strings; they cannot read paths like `/Users/.../report.html`
|
|
20
|
+
from the user's filesystem.
|
|
21
|
+
|
|
18
22
|
- Always pass `--json`; on failure read `error.code`, `error.hint`, and `error.recovery`.
|
|
19
23
|
- Pick the destination with `projects list --json`, `init --project-id <id>`, or `--project-id`.
|
|
20
24
|
- Publish with `publish <path> --json`; add a version with `update <artifact-id-or-url> <path> --json`.
|