@artifactshare/cli 0.1.7 → 0.2.0
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 +19 -16
- package/dist/index.js +1387 -1249
- package/package.json +1 -2
- package/skills/artifactshare/SKILL.md +31 -26
- package/skills/artifactshare/artifactshare.mdc +13 -9
package/dist/index.js
CHANGED
|
@@ -3,10 +3,10 @@ import { appendFile, chmod, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm
|
|
|
3
3
|
import { cli, define, lazy } from "gunshi";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { setTimeout } from "node:timers/promises";
|
|
6
7
|
import { homedir } from "node:os";
|
|
7
8
|
import { createReadStream } from "node:fs";
|
|
8
9
|
import { createHash } from "node:crypto";
|
|
9
|
-
import { setTimeout } from "node:timers/promises";
|
|
10
10
|
//#region src/constants.ts
|
|
11
11
|
const DEFAULT_BASE_URL = "https://artifactshare.com";
|
|
12
12
|
const DEVICE_CLIENT_ID = "artifactshare-cli";
|
|
@@ -68,13 +68,13 @@ const VALUE_FLAGS = new Set([
|
|
|
68
68
|
]);
|
|
69
69
|
const COMMAND_NAMES = new Set([
|
|
70
70
|
"login",
|
|
71
|
-
"
|
|
71
|
+
"share",
|
|
72
|
+
"open",
|
|
72
73
|
"update",
|
|
73
74
|
"edit",
|
|
74
75
|
"delete",
|
|
75
76
|
"resolve",
|
|
76
77
|
"download",
|
|
77
|
-
"agent",
|
|
78
78
|
"move",
|
|
79
79
|
"artifacts",
|
|
80
80
|
"comments",
|
|
@@ -87,7 +87,6 @@ const COMMAND_NAMES = new Set([
|
|
|
87
87
|
"init"
|
|
88
88
|
]);
|
|
89
89
|
const SUBCOMMANDS = {
|
|
90
|
-
agent: ["open"],
|
|
91
90
|
artifacts: ["list", "get"],
|
|
92
91
|
comments: [
|
|
93
92
|
"list",
|
|
@@ -128,6 +127,11 @@ function agentDownloadCommand(target) {
|
|
|
128
127
|
return `${CLI_INVOCATION} download ${target} --output ${AGENT_DOWNLOAD_OUTPUT} --json`;
|
|
129
128
|
}
|
|
130
129
|
//#endregion
|
|
130
|
+
//#region src/types.ts
|
|
131
|
+
function isProfileCredentialSource(source) {
|
|
132
|
+
return source === "profile" || source === "local_config" || source === "project_config" || source === "global_profile";
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
131
135
|
//#region src/errors.ts
|
|
132
136
|
const REQUEST_ACCESS_COMMAND$1 = `${CLI_INVOCATION} request-access --json`;
|
|
133
137
|
const PROJECTS_LIST_COMMAND = `${CLI_INVOCATION} projects list --json`;
|
|
@@ -144,12 +148,18 @@ function apiError(body) {
|
|
|
144
148
|
}
|
|
145
149
|
function mapApiError(status, body, options = {}) {
|
|
146
150
|
const { code: apiCode, message: apiMessage } = apiError(body);
|
|
147
|
-
if (status === 401)
|
|
151
|
+
if (status === 401) {
|
|
152
|
+
if (!options.authenticated) return authRequiredError(options.baseUrl ?? "https://artifactshare.com");
|
|
153
|
+
const source = options.credentialSource;
|
|
154
|
+
const profile = options.profile;
|
|
155
|
+
if (typeof profile === "string" && profile.length > 0 && isProfileCredentialSource(source)) return profileReauthRequiredError(options.baseUrl ?? "https://artifactshare.com", source, profile);
|
|
156
|
+
return tokenInvalidError();
|
|
157
|
+
}
|
|
148
158
|
if (apiCode === "upload-not-allowed") return cliError({
|
|
149
159
|
code: "upload_not_allowed",
|
|
150
|
-
message: "This account cannot
|
|
151
|
-
why: "Artifact Share is currently limiting who can
|
|
152
|
-
hint: `Run ${REQUEST_ACCESS_COMMAND$1} to join the early-access waitlist; an operator opens
|
|
160
|
+
message: "This account cannot share yet.",
|
|
161
|
+
why: "Artifact Share is currently limiting who can share.",
|
|
162
|
+
hint: `Run ${REQUEST_ACCESS_COMMAND$1} to join the early-access waitlist; an operator opens sharing afterwards.`,
|
|
153
163
|
agentRecoverable: false,
|
|
154
164
|
requiresHuman: true,
|
|
155
165
|
recovery: {
|
|
@@ -165,7 +175,7 @@ function mapApiError(status, body, options = {}) {
|
|
|
165
175
|
code: "upload_suspended",
|
|
166
176
|
message: apiMessage ?? "Your upload permission is suspended.",
|
|
167
177
|
why: "Artifact Share suspended upload access for this account.",
|
|
168
|
-
hint: "Ask an operator to restore upload access, then retry
|
|
178
|
+
hint: "Ask an operator to restore upload access, then retry share.",
|
|
169
179
|
agentRecoverable: false,
|
|
170
180
|
requiresHuman: true,
|
|
171
181
|
recovery: { kind: "ask_human" }
|
|
@@ -208,7 +218,7 @@ function mapApiError(status, body, options = {}) {
|
|
|
208
218
|
});
|
|
209
219
|
if (apiCode !== null && ["invalid-container"].includes(apiCode)) return cliError({
|
|
210
220
|
code: "project_not_found",
|
|
211
|
-
message: apiMessage ?? "The
|
|
221
|
+
message: apiMessage ?? "The share destination is invalid.",
|
|
212
222
|
why: "The project ID does not exist or is not available in this workspace.",
|
|
213
223
|
hint: "Retry with a valid --project-id or use --home.",
|
|
214
224
|
agentRecoverable: true,
|
|
@@ -322,7 +332,7 @@ function mapApiError(status, body, options = {}) {
|
|
|
322
332
|
code: "key_target_moved",
|
|
323
333
|
message: apiMessage ?? "The artifact for this key moved.",
|
|
324
334
|
why: "The artifact this key points to now lives in a different destination, so the key no longer updates it.",
|
|
325
|
-
hint: "Find the artifact with resolve --json, then update it by ID or
|
|
335
|
+
hint: "Find the artifact with resolve --json, then update it by ID or share with a new key.",
|
|
326
336
|
agentRecoverable: true,
|
|
327
337
|
requiresHuman: false,
|
|
328
338
|
recovery: { kind: "change_input" }
|
|
@@ -331,16 +341,16 @@ function mapApiError(status, body, options = {}) {
|
|
|
331
341
|
code: "key_kind_mismatch",
|
|
332
342
|
message: apiMessage ?? "The artifact for this key is a different kind.",
|
|
333
343
|
why: "The key points to an artifact whose kind (single file or static site) does not match this input.",
|
|
334
|
-
hint: "Check the existing artifact by ID, or
|
|
344
|
+
hint: "Check the existing artifact by ID, or share with a new key.",
|
|
335
345
|
agentRecoverable: true,
|
|
336
346
|
requiresHuman: false,
|
|
337
347
|
recovery: { kind: "change_input" }
|
|
338
348
|
});
|
|
339
349
|
if (apiCode === "key-conflict") return cliError({
|
|
340
350
|
code: "key_conflict",
|
|
341
|
-
message: apiMessage ?? "Another
|
|
342
|
-
why: "Two
|
|
343
|
-
hint: "Retry the same command; it will update the artifact the other
|
|
351
|
+
message: apiMessage ?? "Another share created this key first.",
|
|
352
|
+
why: "Two share commands raced to create the same key, and the other one won.",
|
|
353
|
+
hint: "Retry the same command; it will update the artifact the other share created.",
|
|
344
354
|
agentRecoverable: true,
|
|
345
355
|
requiresHuman: false,
|
|
346
356
|
recovery: { kind: "retry_later" }
|
|
@@ -400,7 +410,7 @@ function mapApiError(status, body, options = {}) {
|
|
|
400
410
|
].includes(apiCode)) return cliError({
|
|
401
411
|
code: "validation_failed",
|
|
402
412
|
message: apiMessage ?? "The upload input is invalid.",
|
|
403
|
-
why: "The file, directory, or
|
|
413
|
+
why: "The file, directory, or share options failed server-side validation.",
|
|
404
414
|
hint: "Check the path, file types, and visibility options, then retry.",
|
|
405
415
|
agentRecoverable: true,
|
|
406
416
|
requiresHuman: false,
|
|
@@ -473,6 +483,24 @@ function authRequiredError(baseUrl) {
|
|
|
473
483
|
details: authRecoveryDetails(baseUrl)
|
|
474
484
|
});
|
|
475
485
|
}
|
|
486
|
+
function profileReauthRequiredError(baseUrl, source, profile) {
|
|
487
|
+
const loginCommand = `${CLI_INVOCATION} login --profile ${profile}`;
|
|
488
|
+
return cliError({
|
|
489
|
+
code: "auth_required",
|
|
490
|
+
message: "Login is required.",
|
|
491
|
+
why: `The saved credential for profile "${profile}" is invalid or expired.`,
|
|
492
|
+
hint: `In an interactive terminal, run ${loginCommand}. In agents or CI, issue a token at ${tokensUrl(baseUrl)}, then set ${TOKEN_ENV_VAR} or pass ${TOKEN_OPTION}.`,
|
|
493
|
+
agentRecoverable: false,
|
|
494
|
+
requiresHuman: true,
|
|
495
|
+
recovery: { kind: "ask_human" },
|
|
496
|
+
details: {
|
|
497
|
+
...authRecoveryDetails(baseUrl, loginCommand),
|
|
498
|
+
credential_source: source,
|
|
499
|
+
reauth_reason: "profile_token_invalid_or_expired",
|
|
500
|
+
profile
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
}
|
|
476
504
|
function deviceAuthErrorDetails(pending) {
|
|
477
505
|
const openUrl = pending.verification_uri_complete ?? pending.verification_uri;
|
|
478
506
|
return {
|
|
@@ -486,7 +514,7 @@ function deviceAuthErrorDetails(pending) {
|
|
|
486
514
|
retry_hint: "After approval in the browser, rerun the same command to continue."
|
|
487
515
|
};
|
|
488
516
|
}
|
|
489
|
-
function authRequiredWithDeviceAuthError(baseUrl, pending) {
|
|
517
|
+
function authRequiredWithDeviceAuthError(baseUrl, pending, extraDetails = {}) {
|
|
490
518
|
const device = deviceAuthErrorDetails(pending);
|
|
491
519
|
const openUrl = pending.verification_uri_complete ?? pending.verification_uri;
|
|
492
520
|
return cliError({
|
|
@@ -499,6 +527,7 @@ function authRequiredWithDeviceAuthError(baseUrl, pending) {
|
|
|
499
527
|
recovery: { kind: "ask_human" },
|
|
500
528
|
details: {
|
|
501
529
|
...authRecoveryDetails(baseUrl, `${CLI_INVOCATION} login --profile ${pending.profile}`),
|
|
530
|
+
...extraDetails,
|
|
502
531
|
...device
|
|
503
532
|
}
|
|
504
533
|
});
|
|
@@ -614,14 +643,14 @@ function normalizeApiCode(value) {
|
|
|
614
643
|
return typeof value === "string" ? value : null;
|
|
615
644
|
}
|
|
616
645
|
function uploadBlockedHint(code) {
|
|
617
|
-
if (code === "upload-not-allowed") return `Run ${REQUEST_ACCESS_COMMAND$1} to join the waitlist, then retry
|
|
646
|
+
if (code === "upload-not-allowed") return `Run ${REQUEST_ACCESS_COMMAND$1} to join the waitlist, then retry share once an operator opens sharing.`;
|
|
618
647
|
if (code === "upload-policy-unavailable") return "Retry doctor later; upload permission could not be checked.";
|
|
619
|
-
return "Resolve the upload issue, then retry
|
|
648
|
+
return "Resolve the upload issue, then retry share.";
|
|
620
649
|
}
|
|
621
650
|
function projectNotFoundByNameError() {
|
|
622
651
|
return cliError({
|
|
623
652
|
code: "project_not_found",
|
|
624
|
-
message: "The
|
|
653
|
+
message: "The share destination project was not found.",
|
|
625
654
|
why: "No project in the current workspace matches the given project name exactly.",
|
|
626
655
|
hint: `Run ${PROJECTS_LIST_COMMAND}, then retry with --project-id <id>.`,
|
|
627
656
|
agentRecoverable: true,
|
|
@@ -635,7 +664,7 @@ function projectNotFoundByNameError() {
|
|
|
635
664
|
function projectAmbiguousError(candidates) {
|
|
636
665
|
return cliError({
|
|
637
666
|
code: "project_ambiguous",
|
|
638
|
-
message: "The
|
|
667
|
+
message: "The share destination project is ambiguous.",
|
|
639
668
|
why: "Multiple projects in the current workspace match the given project name exactly.",
|
|
640
669
|
hint: "Retry with --project-id <id> from the candidates.",
|
|
641
670
|
agentRecoverable: true,
|
|
@@ -734,9 +763,9 @@ function resolveArtifactId(input) {
|
|
|
734
763
|
}
|
|
735
764
|
const TARGET_COMMAND_LABELS = {
|
|
736
765
|
update: "Update",
|
|
766
|
+
open: "Open",
|
|
737
767
|
"artifacts get": "Artifacts get",
|
|
738
768
|
download: "Download",
|
|
739
|
-
"agent open": "Agent open",
|
|
740
769
|
"comments list": "Comments list",
|
|
741
770
|
"comments post": "Comments post",
|
|
742
771
|
"comments edit": "Comments edit",
|
|
@@ -833,14 +862,14 @@ function validateRawArgs(argv, command) {
|
|
|
833
862
|
const eqIndex = arg.indexOf("=");
|
|
834
863
|
if (eqIndex === -1) {
|
|
835
864
|
const rawName = arg.slice(2);
|
|
836
|
-
const artifactIdError =
|
|
865
|
+
const artifactIdError = unsupportedShareArtifactId(rawName, command);
|
|
837
866
|
if (artifactIdError) return artifactIdError;
|
|
838
867
|
const next = argv[i + 1];
|
|
839
868
|
if (VALUE_FLAGS.has(rawName) && (next === void 0 || isKnownFlagToken(next) || next === "" && !allowsEmptyValue(rawName))) return validationError(`--${rawName} requires a value.`, `Pass --${rawName} <value> and retry.`);
|
|
840
869
|
continue;
|
|
841
870
|
}
|
|
842
871
|
const rawName = arg.slice(2, eqIndex);
|
|
843
|
-
const artifactIdError =
|
|
872
|
+
const artifactIdError = unsupportedShareArtifactId(rawName, command);
|
|
844
873
|
if (artifactIdError) return artifactIdError;
|
|
845
874
|
const value = arg.slice(eqIndex + 1);
|
|
846
875
|
if (BOOLEAN_FLAGS.has(rawName)) return validationError(`--${rawName} does not accept a value.`, `Use --${rawName} without =value.`);
|
|
@@ -848,9 +877,9 @@ function validateRawArgs(argv, command) {
|
|
|
848
877
|
}
|
|
849
878
|
return null;
|
|
850
879
|
}
|
|
851
|
-
function
|
|
852
|
-
if (command !== "
|
|
853
|
-
return validationError("
|
|
880
|
+
function unsupportedShareArtifactId(rawName, command) {
|
|
881
|
+
if (command !== "share" || rawName !== "artifact-id" && rawName !== "artifactId") return null;
|
|
882
|
+
return validationError("Share does not accept --artifact-id.", `To keep an existing share URL, run ${CLI_INVOCATION} update <artifact-id-or-url> <path> --json. For repeat jobs, use share --key <key>.`);
|
|
854
883
|
}
|
|
855
884
|
function allowsEmptyValue(rawName) {
|
|
856
885
|
return rawName === "title" || rawName === "description";
|
|
@@ -935,9 +964,9 @@ function outputMode(options) {
|
|
|
935
964
|
return { json: Boolean(options.json) || process.env.CI === "true" || !process.stdout.isTTY };
|
|
936
965
|
}
|
|
937
966
|
function writeSuccess(command, data, mode) {
|
|
938
|
-
if (!mode.json && command === "
|
|
967
|
+
if (!mode.json && command === "share" && !shareSuccessFields(data)) return writeFailure(command, serviceError("Share succeeded but the response did not include an artifact id and URL."), mode, 1);
|
|
939
968
|
const payload = {
|
|
940
|
-
schema_version:
|
|
969
|
+
schema_version: 2,
|
|
941
970
|
ok: true,
|
|
942
971
|
command,
|
|
943
972
|
data
|
|
@@ -950,7 +979,7 @@ function writeSuccess(command, data, mode) {
|
|
|
950
979
|
}
|
|
951
980
|
function writeFailure(command, error, mode, exitCode) {
|
|
952
981
|
const payload = {
|
|
953
|
-
schema_version:
|
|
982
|
+
schema_version: 2,
|
|
954
983
|
ok: false,
|
|
955
984
|
command,
|
|
956
985
|
error
|
|
@@ -966,11 +995,11 @@ function writeEvent(data) {
|
|
|
966
995
|
process.stderr.write(`${JSON.stringify(data)}\n`);
|
|
967
996
|
}
|
|
968
997
|
function humanSuccess(command, data) {
|
|
969
|
-
if (command === "
|
|
970
|
-
const fields =
|
|
998
|
+
if (command === "share") {
|
|
999
|
+
const fields = shareSuccessFields(data);
|
|
971
1000
|
if (!fields) return `${JSON.stringify(data, null, 2)}\n`;
|
|
972
1001
|
return [
|
|
973
|
-
"
|
|
1002
|
+
"Shared",
|
|
974
1003
|
`Artifact ID: ${fields.artifactId}`,
|
|
975
1004
|
`URL: ${fields.url}`,
|
|
976
1005
|
`Destination: ${fields.destinationType}${fields.projectId ? ` (${fields.projectId})` : ""}`,
|
|
@@ -979,20 +1008,20 @@ function humanSuccess(command, data) {
|
|
|
979
1008
|
].join("\n");
|
|
980
1009
|
}
|
|
981
1010
|
if (command === "doctor") return doctorHumanOutput(data);
|
|
982
|
-
if (command === "
|
|
1011
|
+
if (command === "open") return openHumanOutput(data);
|
|
983
1012
|
return `${JSON.stringify(data, null, 2)}\n`;
|
|
984
1013
|
}
|
|
985
|
-
function
|
|
1014
|
+
function openHumanOutput(data) {
|
|
986
1015
|
const body = `${JSON.stringify(data, null, 2)}`;
|
|
987
|
-
const nextCommand =
|
|
1016
|
+
const nextCommand = openNextCommand(data);
|
|
988
1017
|
if (!nextCommand) return `${body}\n`;
|
|
989
1018
|
return `${body}\nNext command: ${nextCommand}\n`;
|
|
990
1019
|
}
|
|
991
|
-
function
|
|
992
|
-
if (!
|
|
1020
|
+
function openNextCommand(data) {
|
|
1021
|
+
if (!isOpenData(data)) return null;
|
|
993
1022
|
return data.open.kind === "download_required" ? data.open.next_command : null;
|
|
994
1023
|
}
|
|
995
|
-
function
|
|
1024
|
+
function isOpenData(data) {
|
|
996
1025
|
if (!isRecord(data)) return false;
|
|
997
1026
|
const open = data.open;
|
|
998
1027
|
if (!isRecord(open)) return false;
|
|
@@ -1009,7 +1038,7 @@ function doctorNextCommand(data) {
|
|
|
1009
1038
|
if (!isRecord(data) || !("next_command" in data)) return null;
|
|
1010
1039
|
return typeof data.next_command === "string" ? data.next_command : null;
|
|
1011
1040
|
}
|
|
1012
|
-
function
|
|
1041
|
+
function shareSuccessFields(data) {
|
|
1013
1042
|
if (!isRecord(data)) return null;
|
|
1014
1043
|
const artifact = data.artifact;
|
|
1015
1044
|
const destination = data.destination;
|
|
@@ -1132,6 +1161,7 @@ async function apiRequest(path, options, init, errorOptions) {
|
|
|
1132
1161
|
const body = await readJson(response);
|
|
1133
1162
|
if (!response.ok) return { error: mapApiError(response.status, body, {
|
|
1134
1163
|
authenticated: true,
|
|
1164
|
+
baseUrl: baseUrlOf(options),
|
|
1135
1165
|
...errorOptions
|
|
1136
1166
|
}) };
|
|
1137
1167
|
return { body };
|
|
@@ -1189,8 +1219,8 @@ function resolveDestination(options, config) {
|
|
|
1189
1219
|
if (containerId) return { containerId };
|
|
1190
1220
|
return { error: cliError({
|
|
1191
1221
|
code: "destination_required",
|
|
1192
|
-
message: "A
|
|
1193
|
-
why: "Non-interactive
|
|
1222
|
+
message: "A share destination is required.",
|
|
1223
|
+
why: "Non-interactive share never guesses a project or home destination.",
|
|
1194
1224
|
hint: "Retry with --project-id <id>, configure .artifactshare/config.local.json, or pass --home.",
|
|
1195
1225
|
agentRecoverable: true,
|
|
1196
1226
|
requiresHuman: false,
|
|
@@ -1554,7 +1584,7 @@ async function resolveProfileCredential(source, profile, options, globalConfig,
|
|
|
1554
1584
|
const stored = await readProfileToken(profile, options);
|
|
1555
1585
|
if (stored.ok) return {
|
|
1556
1586
|
ok: true,
|
|
1557
|
-
source
|
|
1587
|
+
source,
|
|
1558
1588
|
profile,
|
|
1559
1589
|
token: stored.token
|
|
1560
1590
|
};
|
|
@@ -1667,1225 +1697,1294 @@ async function resolveEffectiveDefaultProfile(projectInput = null) {
|
|
|
1667
1697
|
};
|
|
1668
1698
|
}
|
|
1669
1699
|
//#endregion
|
|
1670
|
-
//#region src/command-runners/
|
|
1671
|
-
async function
|
|
1672
|
-
const
|
|
1673
|
-
|
|
1674
|
-
|
|
1700
|
+
//#region src/command-runners/login.ts
|
|
1701
|
+
async function performDeviceLogin(profile, options, mode) {
|
|
1702
|
+
const request = await requestConfig(options);
|
|
1703
|
+
if (request.error) return {
|
|
1704
|
+
ok: false,
|
|
1705
|
+
error: request.error
|
|
1706
|
+
};
|
|
1707
|
+
const code = await requestDeviceCode(options, request.init);
|
|
1708
|
+
if ("error" in code) return {
|
|
1709
|
+
ok: false,
|
|
1710
|
+
error: code.error
|
|
1711
|
+
};
|
|
1712
|
+
const deadline = Date.now() + code.expires_in * 1e3;
|
|
1713
|
+
if (mode.json) writeEvent({
|
|
1714
|
+
status: "pending",
|
|
1715
|
+
verification_uri: code.verification_uri,
|
|
1716
|
+
verification_uri_complete: code.verification_uri_complete ?? null,
|
|
1717
|
+
user_code: code.user_code,
|
|
1718
|
+
expires_at: new Date(deadline).toISOString(),
|
|
1719
|
+
interval_seconds: code.interval
|
|
1720
|
+
});
|
|
1721
|
+
else writeText([
|
|
1722
|
+
"Open this URL in a browser to sign in:",
|
|
1723
|
+
code.verification_uri_complete ?? code.verification_uri,
|
|
1724
|
+
"",
|
|
1725
|
+
`Code: ${code.user_code}`,
|
|
1726
|
+
`Waiting for approval for profile "${profile}"...`,
|
|
1727
|
+
""
|
|
1728
|
+
].join("\n"));
|
|
1729
|
+
const token = await pollForToken(options, code, request.init, profile, deadline);
|
|
1730
|
+
if ("error" in token) return {
|
|
1731
|
+
ok: false,
|
|
1732
|
+
error: token.error
|
|
1733
|
+
};
|
|
1734
|
+
const sessionExpiresAt = token.expires_in === void 0 ? null : new Date(Date.now() + token.expires_in * 1e3).toISOString();
|
|
1735
|
+
const stored = await verifyAndStoreProfileToken(profile, token.access_token, options, request.init);
|
|
1736
|
+
if (!stored.ok) return {
|
|
1737
|
+
ok: false,
|
|
1738
|
+
error: stored.error
|
|
1739
|
+
};
|
|
1740
|
+
const effective = await resolveEffectiveDefaultProfile(await resolveProjectConfig());
|
|
1741
|
+
const data = {
|
|
1742
|
+
profile,
|
|
1743
|
+
status: "completed",
|
|
1744
|
+
credential_source: "profile",
|
|
1745
|
+
token_store: stored.data.token_store,
|
|
1746
|
+
user: stored.data.user,
|
|
1747
|
+
workspace: stored.data.workspace,
|
|
1748
|
+
verification_uri: code.verification_uri,
|
|
1749
|
+
verification_uri_complete: code.verification_uri_complete ?? null,
|
|
1750
|
+
user_code: code.user_code,
|
|
1751
|
+
expires_at: sessionExpiresAt,
|
|
1752
|
+
interval_seconds: code.interval
|
|
1753
|
+
};
|
|
1754
|
+
if (effective.profile && effective.profile !== profile) {
|
|
1755
|
+
data.effective_default_profile = effective.profile;
|
|
1756
|
+
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.`;
|
|
1757
|
+
}
|
|
1758
|
+
return {
|
|
1759
|
+
ok: true,
|
|
1760
|
+
data
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
async function runLogin(parsed, mode) {
|
|
1764
|
+
const command = "login";
|
|
1765
|
+
const profile = nonEmpty(parsed.options.profile) ?? "default";
|
|
1766
|
+
if (nonEmpty(process.env.ARTIFACTSHARE_TOKEN) || nonEmpty(parsed.options.token)) return writeFailure(command, validationError("Login cannot run with a bearer token already selected.", "Unset ARTIFACTSHARE_TOKEN and remove --token before running login."), mode, 1);
|
|
1767
|
+
const result = await performDeviceLogin(profile, parsed.options, mode);
|
|
1768
|
+
if (!result.ok) return writeFailure(command, result.error, mode, 1);
|
|
1675
1769
|
return writeSuccess(command, result.data, mode);
|
|
1676
1770
|
}
|
|
1677
|
-
async function
|
|
1678
|
-
const
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
const include = parseIncludeOptions(parsed.options.include);
|
|
1684
|
-
if (include.error) return { error: include.error };
|
|
1685
|
-
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
1686
|
-
if (!credential.ok) return { error: credential.error };
|
|
1687
|
-
const request = await requestConfig(parsed.options);
|
|
1688
|
-
if (request.error) return { error: request.error };
|
|
1689
|
-
const url = apiUrl(`/api/cli/artifacts/${encodeURIComponent(artifactId)}`, baseUrlOf(parsed.options));
|
|
1690
|
-
if (offset.value !== void 0) url.searchParams.set("offset", offset.value);
|
|
1691
|
-
for (const item of include.values) url.searchParams.append("include", item);
|
|
1692
|
-
const response = await fetch(url, {
|
|
1693
|
-
headers: { Authorization: `Bearer ${credential.token}` },
|
|
1694
|
-
...request.init
|
|
1771
|
+
async function requestDeviceCode(options, init) {
|
|
1772
|
+
const response = await fetch(apiUrl("/api/auth/device/code", baseUrlOf(options)), {
|
|
1773
|
+
method: "POST",
|
|
1774
|
+
headers: { "content-type": "application/json" },
|
|
1775
|
+
body: JSON.stringify({ client_id: DEVICE_CLIENT_ID }),
|
|
1776
|
+
...init
|
|
1695
1777
|
}).catch((error) => ({ networkError: error }));
|
|
1696
1778
|
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
1697
1779
|
const body = await readJson(response);
|
|
1698
|
-
if (!response.ok) return { error: mapApiError(response.status, body, {
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
}) };
|
|
1702
|
-
if (!artifactGetSuccessFields(body)) return { error: serviceError("Artifact read succeeded but the response did not include source metadata.") };
|
|
1703
|
-
return { data: body };
|
|
1780
|
+
if (!response.ok) return { error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) }) };
|
|
1781
|
+
if (!isDeviceCodeResponse(body)) return { error: validationError("Device login response was invalid.", "Retry login. If this repeats, report the response shape.", "service_error") };
|
|
1782
|
+
return body;
|
|
1704
1783
|
}
|
|
1705
|
-
async function
|
|
1706
|
-
const
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
1716
|
-
const request = await requestConfig(parsed.options);
|
|
1717
|
-
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1718
|
-
const url = apiUrl("/api/cli/artifacts", baseUrlOf(parsed.options));
|
|
1719
|
-
if (home) url.searchParams.set("project_id", "");
|
|
1720
|
-
else if (projectId) url.searchParams.set("project_id", projectId);
|
|
1721
|
-
if (query) url.searchParams.set("query", query);
|
|
1722
|
-
const response = await fetch(url, {
|
|
1723
|
-
headers: { Authorization: `Bearer ${credential.token}` },
|
|
1724
|
-
...request.init
|
|
1784
|
+
async function exchangeDeviceTokenOnce(options, deviceCode, init) {
|
|
1785
|
+
const response = await fetch(apiUrl("/api/auth/device/token", baseUrlOf(options)), {
|
|
1786
|
+
method: "POST",
|
|
1787
|
+
headers: { "content-type": "application/json" },
|
|
1788
|
+
body: JSON.stringify({
|
|
1789
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
1790
|
+
device_code: deviceCode,
|
|
1791
|
+
client_id: DEVICE_CLIENT_ID
|
|
1792
|
+
}),
|
|
1793
|
+
...init
|
|
1725
1794
|
}).catch((error) => ({ networkError: error }));
|
|
1726
|
-
if ("networkError" in response) return
|
|
1795
|
+
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
1727
1796
|
const body = await readJson(response);
|
|
1728
|
-
if (
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
}
|
|
1732
|
-
//#endregion
|
|
1733
|
-
//#region src/command-runners/skills.ts
|
|
1734
|
-
const SKILL_TOOLS = [
|
|
1735
|
-
"codex",
|
|
1736
|
-
"claude",
|
|
1737
|
-
"cursor"
|
|
1738
|
-
];
|
|
1739
|
-
const SKILL_FILE_PATH = join("skills", "artifactshare", "SKILL.md");
|
|
1740
|
-
const TOOL_CONFIG = {
|
|
1741
|
-
codex: {
|
|
1742
|
-
relativePath: join(".agents", SKILL_FILE_PATH),
|
|
1743
|
-
scopes: ["project", "user"],
|
|
1744
|
-
detectDirs: [".codex", ".agents"],
|
|
1745
|
-
bundledFile: "SKILL.md",
|
|
1746
|
-
pruneDirs: ["artifactshare", "skills"]
|
|
1747
|
-
},
|
|
1748
|
-
claude: {
|
|
1749
|
-
relativePath: join(".claude", SKILL_FILE_PATH),
|
|
1750
|
-
scopes: ["project", "user"],
|
|
1751
|
-
detectDirs: [".claude"],
|
|
1752
|
-
bundledFile: "SKILL.md",
|
|
1753
|
-
pruneDirs: ["artifactshare", "skills"]
|
|
1754
|
-
},
|
|
1755
|
-
cursor: {
|
|
1756
|
-
relativePath: join(".cursor", "rules", "artifactshare.mdc"),
|
|
1757
|
-
scopes: ["project"],
|
|
1758
|
-
detectDirs: [".cursor"],
|
|
1759
|
-
bundledFile: "artifactshare.mdc",
|
|
1760
|
-
pruneDirs: []
|
|
1761
|
-
}
|
|
1762
|
-
};
|
|
1763
|
-
function skillTarget(tool, scope) {
|
|
1764
|
-
const relative = TOOL_CONFIG[tool].relativePath;
|
|
1765
|
-
const path = scope === "project" ? relative : join(homedir(), relative);
|
|
1766
|
-
return {
|
|
1767
|
-
tool,
|
|
1768
|
-
scope,
|
|
1769
|
-
path,
|
|
1770
|
-
absolutePath: resolve(path)
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
function allTargets() {
|
|
1774
|
-
return SKILL_TOOLS.flatMap((tool) => TOOL_CONFIG[tool].scopes.map((scope) => skillTarget(tool, scope)));
|
|
1775
|
-
}
|
|
1776
|
-
function managedState(content) {
|
|
1777
|
-
if (content === null) return { kind: "missing" };
|
|
1778
|
-
if (!content.includes("artifactshare-skill")) return { kind: "unmanaged" };
|
|
1779
|
-
const block = content.match(/<!--\s*artifactshare-skill([\s\S]*?)-->/)?.[1];
|
|
1780
|
-
const version = block?.match(/(?:^|\n)\s*version:\s*(\d+)\s*(?:\n|$)/)?.[1];
|
|
1781
|
-
const managed = block !== void 0 && /(?:^|\n)\s*managed:\s*true\s*(?:\n|$)/.test(block);
|
|
1782
|
-
if (version === void 0 || !managed) return { kind: "broken" };
|
|
1783
|
-
return {
|
|
1784
|
-
kind: "managed",
|
|
1785
|
-
version: Number(version)
|
|
1797
|
+
if (response.ok && isDeviceTokenResponse(body)) return {
|
|
1798
|
+
status: "success",
|
|
1799
|
+
token: body
|
|
1786
1800
|
};
|
|
1801
|
+
const authError = deviceTokenError(body);
|
|
1802
|
+
if (authError === "authorization_pending") return { status: "pending" };
|
|
1803
|
+
if (authError === "slow_down") return { status: "slow_down" };
|
|
1804
|
+
if (authError === "access_denied") return { status: "denied" };
|
|
1805
|
+
if (authError === "expired_token") return { status: "expired" };
|
|
1806
|
+
if (response.status === 429 || response.status >= 500) return { status: "retry_later" };
|
|
1807
|
+
return { error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) }) };
|
|
1787
1808
|
}
|
|
1788
|
-
|
|
1789
|
-
return managedState(await readFile(target.absolutePath, "utf8").catch(() => null));
|
|
1790
|
-
}
|
|
1791
|
-
async function loadBundledSkills() {
|
|
1792
|
-
const byFile = /* @__PURE__ */ new Map();
|
|
1793
|
-
const contents = {};
|
|
1794
|
-
let version;
|
|
1795
|
-
for (const tool of SKILL_TOOLS) {
|
|
1796
|
-
const file = TOOL_CONFIG[tool].bundledFile;
|
|
1797
|
-
let content = byFile.get(file);
|
|
1798
|
-
if (content === void 0) {
|
|
1799
|
-
content = await readFile(new URL(`../skills/artifactshare/${file}`, import.meta.url), "utf8");
|
|
1800
|
-
const state = managedState(content);
|
|
1801
|
-
if (state.kind !== "managed" || (version ?? state.version) !== state.version) throw new Error(`The bundled ${file} has a missing or mismatched managed marker.`);
|
|
1802
|
-
version = state.version;
|
|
1803
|
-
byFile.set(file, content);
|
|
1804
|
-
}
|
|
1805
|
-
contents[tool] = content;
|
|
1806
|
-
}
|
|
1809
|
+
function pendingDeviceAuthFromCode(profile, options, code) {
|
|
1807
1810
|
return {
|
|
1808
|
-
|
|
1809
|
-
|
|
1811
|
+
base_url: baseUrlOf(options),
|
|
1812
|
+
profile,
|
|
1813
|
+
device_code: code.device_code,
|
|
1814
|
+
verification_uri: code.verification_uri,
|
|
1815
|
+
verification_uri_complete: code.verification_uri_complete ?? null,
|
|
1816
|
+
user_code: code.user_code,
|
|
1817
|
+
expires_at: new Date(Date.now() + code.expires_in * 1e3).toISOString(),
|
|
1818
|
+
interval_seconds: code.interval,
|
|
1819
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1810
1820
|
};
|
|
1811
1821
|
}
|
|
1812
|
-
function
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1822
|
+
async function pollForToken(options, code, init, profile, deadline) {
|
|
1823
|
+
let intervalMs = Math.max(code.interval, 1) * 1e3;
|
|
1824
|
+
let networkFailures = 0;
|
|
1825
|
+
while (Date.now() < deadline) {
|
|
1826
|
+
await setTimeout(intervalMs);
|
|
1827
|
+
const response = await fetch(apiUrl("/api/auth/device/token", baseUrlOf(options)), {
|
|
1828
|
+
method: "POST",
|
|
1829
|
+
headers: { "content-type": "application/json" },
|
|
1830
|
+
body: JSON.stringify({
|
|
1831
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
1832
|
+
device_code: code.device_code,
|
|
1833
|
+
client_id: DEVICE_CLIENT_ID
|
|
1834
|
+
}),
|
|
1835
|
+
...init
|
|
1836
|
+
}).catch((error) => ({ networkError: error }));
|
|
1837
|
+
if ("networkError" in response) {
|
|
1838
|
+
networkFailures += 1;
|
|
1839
|
+
if (networkFailures >= 5) return { error: networkError(response.networkError) };
|
|
1821
1840
|
continue;
|
|
1822
1841
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1842
|
+
networkFailures = 0;
|
|
1843
|
+
const body = await readJson(response);
|
|
1844
|
+
if (response.ok && isDeviceTokenResponse(body)) return body;
|
|
1845
|
+
const authError = deviceTokenError(body);
|
|
1846
|
+
if (authError === "authorization_pending") continue;
|
|
1847
|
+
if (authError === "slow_down") {
|
|
1848
|
+
intervalMs += 5e3;
|
|
1849
|
+
continue;
|
|
1850
|
+
}
|
|
1851
|
+
if (authError === "access_denied") return { error: authDeniedError(profile) };
|
|
1852
|
+
if (authError === "expired_token") return { error: authExpiredError(profile) };
|
|
1853
|
+
return { error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) }) };
|
|
1825
1854
|
}
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1855
|
+
return { error: authExpiredError(profile) };
|
|
1856
|
+
}
|
|
1857
|
+
async function verifyAndStoreProfileToken(profile, token, options, init) {
|
|
1858
|
+
const config = await readGlobalConfig() ?? {};
|
|
1859
|
+
const whoamiResult = await apiGet("/api/cli/whoami", token, options, init);
|
|
1860
|
+
if (whoamiResult.error) return {
|
|
1861
|
+
ok: false,
|
|
1862
|
+
error: whoamiResult.error
|
|
1863
|
+
};
|
|
1864
|
+
const whoami = whoamiProfile(whoamiResult.body);
|
|
1865
|
+
const profiles = config.profiles ?? {};
|
|
1866
|
+
const expectedEmail = nonEmpty((Object.hasOwn(profiles, profile) ? profiles[profile] : void 0)?.email);
|
|
1867
|
+
if (expectedEmail && whoami.email !== expectedEmail) return {
|
|
1868
|
+
ok: false,
|
|
1869
|
+
error: authAccountMismatchError(profile, expectedEmail, whoami.email)
|
|
1870
|
+
};
|
|
1871
|
+
const saved = await saveProfileToken(profile, token, options);
|
|
1872
|
+
if (!saved.ok) return {
|
|
1873
|
+
ok: false,
|
|
1874
|
+
error: tokenStoreUnavailableError(profile)
|
|
1875
|
+
};
|
|
1876
|
+
await writeProfileConfig(profile, options, saved.store, whoami);
|
|
1830
1877
|
return {
|
|
1831
|
-
|
|
1832
|
-
|
|
1878
|
+
ok: true,
|
|
1879
|
+
data: {
|
|
1880
|
+
profile,
|
|
1881
|
+
token_store: saved.store,
|
|
1882
|
+
user: { email: whoami.email },
|
|
1883
|
+
workspace: {
|
|
1884
|
+
id: whoami.workspace_id,
|
|
1885
|
+
hosted_domain: whoami.hosted_domain
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1833
1888
|
};
|
|
1834
1889
|
}
|
|
1835
|
-
function
|
|
1836
|
-
const
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1890
|
+
async function writeProfileConfig(profile, options, tokenStore, whoami) {
|
|
1891
|
+
const config = await readGlobalConfig() ?? {};
|
|
1892
|
+
const profiles = config.profiles ?? {};
|
|
1893
|
+
const currentProfile = Object.hasOwn(profiles, profile) ? profiles[profile] : void 0;
|
|
1894
|
+
await writeGlobalConfig({
|
|
1895
|
+
...config,
|
|
1896
|
+
default_profile: nonEmpty(config.default_profile) ?? profile,
|
|
1897
|
+
profiles: {
|
|
1898
|
+
...profiles,
|
|
1899
|
+
[profile]: {
|
|
1900
|
+
...currentProfile,
|
|
1901
|
+
base_url: baseUrlOf(options),
|
|
1902
|
+
email: whoami.email ?? currentProfile?.email ?? null,
|
|
1903
|
+
workspace_id: whoami.workspace_id,
|
|
1904
|
+
token_store: tokenStore,
|
|
1905
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
});
|
|
1840
1909
|
}
|
|
1841
|
-
function
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
if (
|
|
1847
|
-
|
|
1848
|
-
|
|
1910
|
+
function isDeviceCodeResponse(body) {
|
|
1911
|
+
if (!isRecord(body)) return false;
|
|
1912
|
+
return typeof body.device_code === "string" && typeof body.user_code === "string" && typeof body.verification_uri === "string" && (typeof body.verification_uri_complete === "string" || body.verification_uri_complete === void 0) && typeof body.expires_in === "number" && typeof body.interval === "number";
|
|
1913
|
+
}
|
|
1914
|
+
function isDeviceTokenResponse(body) {
|
|
1915
|
+
if (!isRecord(body)) return false;
|
|
1916
|
+
return typeof body.access_token === "string" && typeof body.token_type === "string" && body.token_type.toLowerCase() === "bearer" && (typeof body.expires_in === "number" || body.expires_in === void 0);
|
|
1917
|
+
}
|
|
1918
|
+
function deviceTokenError(body) {
|
|
1919
|
+
if (!isRecord(body)) return null;
|
|
1920
|
+
return typeof body.error === "string" ? body.error : null;
|
|
1921
|
+
}
|
|
1922
|
+
function whoamiProfile(body) {
|
|
1923
|
+
const record = isRecord(body) ? body : null;
|
|
1924
|
+
const user = record && isRecord(record.user) ? record.user : null;
|
|
1925
|
+
const workspace = record && isRecord(record.workspace) ? record.workspace : null;
|
|
1849
1926
|
return {
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1927
|
+
email: typeof user?.email === "string" ? user.email : null,
|
|
1928
|
+
workspace_id: typeof workspace?.id === "string" ? workspace.id : null,
|
|
1929
|
+
hosted_domain: typeof workspace?.hosted_domain === "string" ? workspace.hosted_domain : null
|
|
1853
1930
|
};
|
|
1854
1931
|
}
|
|
1855
|
-
|
|
1856
|
-
|
|
1932
|
+
//#endregion
|
|
1933
|
+
//#region src/command-runners/auto-login.ts
|
|
1934
|
+
const JSON_PENDING_AUTH_COMMANDS = new Set([
|
|
1935
|
+
"share",
|
|
1936
|
+
"update",
|
|
1937
|
+
"download",
|
|
1938
|
+
"artifacts get"
|
|
1939
|
+
]);
|
|
1940
|
+
function isInteractiveTerminal(mode) {
|
|
1941
|
+
return !mode.json && process.stdin.isTTY === true;
|
|
1857
1942
|
}
|
|
1858
|
-
function
|
|
1859
|
-
return
|
|
1943
|
+
function profileForAutoLogin(credential) {
|
|
1944
|
+
return credential.source === "none" ? "default" : credential.profile ?? "default";
|
|
1860
1945
|
}
|
|
1861
|
-
|
|
1862
|
-
const
|
|
1863
|
-
|
|
1864
|
-
return false;
|
|
1946
|
+
function isPendingExpired(pending) {
|
|
1947
|
+
const expiresAt = Date.parse(pending.expires_at);
|
|
1948
|
+
return Number.isNaN(expiresAt) || expiresAt <= Date.now();
|
|
1865
1949
|
}
|
|
1866
|
-
|
|
1867
|
-
const
|
|
1868
|
-
|
|
1869
|
-
"claude",
|
|
1870
|
-
"codex",
|
|
1871
|
-
"cursor"
|
|
1872
|
-
];
|
|
1873
|
-
const detected = /* @__PURE__ */ new Set();
|
|
1874
|
-
for (const tool of autoOrder) if (TOOL_CONFIG[tool].scopes.includes(targetScope) && await isToolDetected(tool, targetScope)) detected.add(tool);
|
|
1875
|
-
return (detected.size > 0 ? [...detected] : ["codex", "claude"]).filter((tool) => TOOL_CONFIG[tool].scopes.includes(targetScope)).map((tool) => skillTarget(tool, targetScope));
|
|
1950
|
+
function authRequiredExtraDetails(error) {
|
|
1951
|
+
const credentialSource = error.details?.credential_source;
|
|
1952
|
+
return typeof credentialSource === "string" ? { credential_source: credentialSource } : {};
|
|
1876
1953
|
}
|
|
1877
|
-
|
|
1878
|
-
if (
|
|
1879
|
-
|
|
1880
|
-
await writeFile(target.absolutePath, content);
|
|
1881
|
-
return;
|
|
1882
|
-
}
|
|
1883
|
-
if (action === "removed") {
|
|
1884
|
-
await rm(target.absolutePath, { force: true });
|
|
1885
|
-
await cleanupSkillDirs(target);
|
|
1886
|
-
}
|
|
1954
|
+
function interactiveLoginMessage(credential) {
|
|
1955
|
+
if (isProfileCredentialSource(credential.source) && credential.error.details?.reauth_reason === "profile_token_invalid_or_expired") return "Profile token expired. Starting device login to refresh...\n";
|
|
1956
|
+
return "Not signed in. Starting device login to continue...\n";
|
|
1887
1957
|
}
|
|
1888
|
-
async function
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
if (basename(dir) !== expected) return;
|
|
1892
|
-
try {
|
|
1893
|
-
await rmdir(dir);
|
|
1894
|
-
} catch {
|
|
1895
|
-
return;
|
|
1896
|
-
}
|
|
1897
|
-
dir = dirname(dir);
|
|
1898
|
-
}
|
|
1958
|
+
async function canAttemptProfileTokenSave(profile, options) {
|
|
1959
|
+
const stored = await readProfileToken(profile, options);
|
|
1960
|
+
return stored.ok || stored.reason !== "unavailable";
|
|
1899
1961
|
}
|
|
1900
|
-
async function
|
|
1901
|
-
if (
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
tool: target.tool,
|
|
1911
|
-
scope: target.scope,
|
|
1912
|
-
path: target.path,
|
|
1913
|
-
action
|
|
1914
|
-
}))
|
|
1915
|
-
};
|
|
1962
|
+
async function handleCredentialFailure(command, credential, options, mode, rerun, isRetry = false, deps = {}) {
|
|
1963
|
+
if (credential.error.code !== "auth_required") return writeFailure(command, credential.error, mode, 1);
|
|
1964
|
+
if (mode.json && JSON_PENDING_AUTH_COMMANDS.has(command) && !isRetry) return handleJsonPendingAuth(command, credential, options, mode, rerun);
|
|
1965
|
+
if (!isInteractiveTerminal(mode) || isRetry) return writeFailure(command, credential.error, mode, 1);
|
|
1966
|
+
const performLogin = deps.performLogin ?? performDeviceLogin;
|
|
1967
|
+
const profile = profileForAutoLogin(credential);
|
|
1968
|
+
writeText(interactiveLoginMessage(credential));
|
|
1969
|
+
const loginResult = await performLogin(profile, options, mode);
|
|
1970
|
+
if (!loginResult.ok) return writeFailure(command, loginResult.error, mode, 1);
|
|
1971
|
+
return rerun();
|
|
1916
1972
|
}
|
|
1917
|
-
async function
|
|
1918
|
-
|
|
1919
|
-
|
|
1973
|
+
async function handleAuthenticatedCredentialFailure(command, error, credential, options, mode, rerun, isRetry = false) {
|
|
1974
|
+
if (error.code !== "auth_required") return writeFailure(command, error, mode, 1);
|
|
1975
|
+
return await handleCredentialFailure(command, {
|
|
1976
|
+
ok: false,
|
|
1977
|
+
source: credential.source,
|
|
1978
|
+
...credential.profile ? { profile: credential.profile } : {},
|
|
1979
|
+
error
|
|
1980
|
+
}, options, mode, rerun, isRetry);
|
|
1920
1981
|
}
|
|
1921
|
-
async function
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1982
|
+
async function handleJsonPendingAuth(command, credential, options, mode, rerun) {
|
|
1983
|
+
const profile = profileForAutoLogin(credential);
|
|
1984
|
+
const extraDetails = authRequiredExtraDetails(credential.error);
|
|
1985
|
+
const baseUrl = baseUrlOf(options);
|
|
1986
|
+
const request = await requestConfig(options);
|
|
1987
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1988
|
+
if (!await canAttemptProfileTokenSave(profile, options)) return writeFailure(command, tokenStoreUnavailableError(profile), mode, 1);
|
|
1989
|
+
const existing = await readPendingDeviceAuth(baseUrl, profile);
|
|
1990
|
+
if (existing && !isPendingExpired(existing)) {
|
|
1991
|
+
const exchange = await exchangeDeviceTokenOnce(options, existing.device_code, request.init);
|
|
1992
|
+
if ("error" in exchange) {
|
|
1993
|
+
if (exchange.error.code !== "network_failed") await clearPendingDeviceAuth(baseUrl, profile);
|
|
1994
|
+
return writeFailure(command, exchange.error, mode, 1);
|
|
1995
|
+
}
|
|
1996
|
+
if (exchange.status === "success") {
|
|
1997
|
+
const stored = await verifyAndStoreProfileToken(profile, exchange.token.access_token, options, request.init);
|
|
1998
|
+
if (!stored.ok) return writeFailure(command, stored.error, mode, 1);
|
|
1999
|
+
await clearPendingDeviceAuth(baseUrl, profile);
|
|
2000
|
+
return rerun();
|
|
2001
|
+
}
|
|
2002
|
+
if (exchange.status === "denied") {
|
|
2003
|
+
await clearPendingDeviceAuth(baseUrl, profile);
|
|
2004
|
+
return writeFailure(command, authDeniedError(profile), mode, 1);
|
|
2005
|
+
}
|
|
2006
|
+
if (exchange.status === "expired") await clearPendingDeviceAuth(baseUrl, profile);
|
|
2007
|
+
else if (exchange.status === "retry_later") return writeFailure(command, authRequiredWithDeviceAuthError(baseUrl, existing, extraDetails), mode, 1);
|
|
2008
|
+
else return writeFailure(command, authRequiredWithDeviceAuthError(baseUrl, existing, extraDetails), mode, 1);
|
|
2009
|
+
} else if (existing) await clearPendingDeviceAuth(baseUrl, profile);
|
|
2010
|
+
const code = await requestDeviceCode(options, request.init);
|
|
2011
|
+
if ("error" in code) return writeFailure(command, credential.error, mode, 1);
|
|
2012
|
+
const pending = pendingDeviceAuthFromCode(profile, options, code);
|
|
2013
|
+
if (!await writePendingDeviceAuth(pending)) return writeFailure(command, credential.error, mode, 1);
|
|
2014
|
+
return writeFailure(command, authRequiredWithDeviceAuthError(baseUrl, pending, extraDetails), mode, 1);
|
|
2015
|
+
}
|
|
2016
|
+
//#endregion
|
|
2017
|
+
//#region src/command-runners/artifacts-get.ts
|
|
2018
|
+
async function runArtifactsGet(parsed, mode, isRetry = false) {
|
|
2019
|
+
const command = "artifacts get";
|
|
2020
|
+
const target = parseArtifactReadTarget(parsed, command);
|
|
2021
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2022
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2023
|
+
if (!credential.ok) {
|
|
2024
|
+
if (!mode.json) return writeFailure(command, credential.error, mode, 1);
|
|
2025
|
+
return handleCredentialFailure(command, credential, parsed.options, mode, () => runArtifactsGet(parsed, mode, true), isRetry);
|
|
1927
2026
|
}
|
|
2027
|
+
const result = await fetchArtifact(parsed, target.value, credential);
|
|
2028
|
+
if (result.error) return handleAuthenticatedCredentialFailure(command, result.error, credential, parsed.options, mode, () => runArtifactsGet(parsed, mode, true), isRetry);
|
|
2029
|
+
return writeSuccess(command, result.data, mode);
|
|
1928
2030
|
}
|
|
1929
|
-
async function
|
|
1930
|
-
const
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
const scope = filters.scope ?? "project";
|
|
1936
|
-
const force = parsed.options.force === true;
|
|
1937
|
-
const bundled = await bundledOrFailure(command, mode);
|
|
1938
|
-
if (!bundled) return;
|
|
1939
|
-
const planned = [];
|
|
1940
|
-
for (const tool of tools) {
|
|
1941
|
-
const target = skillTarget(tool, scope);
|
|
1942
|
-
const state = await readTarget(target);
|
|
1943
|
-
if ((state.kind === "unmanaged" || state.kind === "broken") && !force) return writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
1944
|
-
if (state.kind === "managed" && state.version === bundled.version && !force) {
|
|
1945
|
-
planned.push({
|
|
1946
|
-
target,
|
|
1947
|
-
action: "unchanged"
|
|
1948
|
-
});
|
|
1949
|
-
continue;
|
|
1950
|
-
}
|
|
1951
|
-
planned.push({
|
|
1952
|
-
target,
|
|
1953
|
-
action: state.kind === "missing" ? "installed" : "updated",
|
|
1954
|
-
content: bundled.contents[tool]
|
|
1955
|
-
});
|
|
1956
|
-
}
|
|
1957
|
-
await runActions(command, planned, parsed.options.dryRun === true, mode);
|
|
1958
|
-
}
|
|
1959
|
-
async function ensureSkills(parsed, mode, options = {}) {
|
|
1960
|
-
const command = options.command ?? "skills ensure";
|
|
1961
|
-
const filters = parseFilters(parsed, { allowAuto: true });
|
|
1962
|
-
if (filters.error) {
|
|
1963
|
-
writeFailure(command, filters.error, mode, 1);
|
|
1964
|
-
return;
|
|
1965
|
-
}
|
|
1966
|
-
if (filters.tools.length === 0 && !filters.auto) {
|
|
1967
|
-
writeFailure(command, validationError("--tool is required.", "Pass --tool auto, --tool codex, --tool claude, or --tool cursor; repeat explicit tools for multiple targets."), mode, 1);
|
|
1968
|
-
return;
|
|
1969
|
-
}
|
|
1970
|
-
const bundled = await bundledOrFailure(command, mode);
|
|
1971
|
-
if (!bundled) return void 0;
|
|
1972
|
-
const targets = filters.auto ? await autoTargets(filters.scope) : filteredTargets(filters.tools, filters.scope ?? "project");
|
|
1973
|
-
const planned = [];
|
|
1974
|
-
for (const target of targets) {
|
|
1975
|
-
const state = await readTarget(target);
|
|
1976
|
-
if (state.kind === "unmanaged" || state.kind === "broken") {
|
|
1977
|
-
writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
1978
|
-
return;
|
|
1979
|
-
}
|
|
1980
|
-
const unchanged = state.kind === "managed" && state.version === bundled.version;
|
|
1981
|
-
planned.push(unchanged ? {
|
|
1982
|
-
target,
|
|
1983
|
-
action: "unchanged"
|
|
1984
|
-
} : {
|
|
1985
|
-
target,
|
|
1986
|
-
action: state.kind === "missing" ? "installed" : "updated",
|
|
1987
|
-
content: bundled.contents[target.tool]
|
|
1988
|
-
});
|
|
1989
|
-
}
|
|
1990
|
-
return finishActions(command, planned, parsed.options.dryRun === true, mode);
|
|
1991
|
-
}
|
|
1992
|
-
async function runSkillsEnsure(parsed, mode) {
|
|
1993
|
-
const data = await ensureSkills(parsed, mode);
|
|
1994
|
-
if (data) writeSuccess("skills ensure", data, mode);
|
|
1995
|
-
}
|
|
1996
|
-
async function runSkillsList(parsed, mode) {
|
|
1997
|
-
const bundled = await bundledOrFailure("skills list", mode);
|
|
1998
|
-
if (!bundled) return;
|
|
1999
|
-
const targets = [];
|
|
2000
|
-
for (const target of allTargets()) {
|
|
2001
|
-
const state = await readTarget(target);
|
|
2002
|
-
targets.push({
|
|
2003
|
-
tool: target.tool,
|
|
2004
|
-
scope: target.scope,
|
|
2005
|
-
path: target.path,
|
|
2006
|
-
detected: await isToolDetected(target.tool, target.scope),
|
|
2007
|
-
installed: state.kind !== "missing",
|
|
2008
|
-
managed: state.kind === "managed",
|
|
2009
|
-
installed_version: state.kind === "managed" ? state.version : null,
|
|
2010
|
-
update_available: state.kind === "managed" && state.version !== bundled.version
|
|
2011
|
-
});
|
|
2012
|
-
}
|
|
2013
|
-
return writeSuccess("skills list", {
|
|
2014
|
-
bundled_version: bundled.version,
|
|
2015
|
-
targets
|
|
2016
|
-
}, mode);
|
|
2017
|
-
}
|
|
2018
|
-
async function runSkillsUpdate(parsed, mode) {
|
|
2019
|
-
const command = "skills update";
|
|
2020
|
-
const filters = parseFilters(parsed);
|
|
2021
|
-
if (filters.error) return writeFailure(command, filters.error, mode, 1);
|
|
2022
|
-
const force = parsed.options.force === true;
|
|
2023
|
-
const bundled = await bundledOrFailure(command, mode);
|
|
2024
|
-
if (!bundled) return;
|
|
2025
|
-
const planned = [];
|
|
2026
|
-
for (const target of filteredTargets(filters.tools, filters.scope)) {
|
|
2027
|
-
const state = await readTarget(target);
|
|
2028
|
-
if (state.kind === "broken") return writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
2029
|
-
if (state.kind === "missing") planned.push({
|
|
2030
|
-
target,
|
|
2031
|
-
action: "not_installed"
|
|
2032
|
-
});
|
|
2033
|
-
else if (state.kind === "unmanaged") planned.push({
|
|
2034
|
-
target,
|
|
2035
|
-
action: "skipped_unmanaged"
|
|
2036
|
-
});
|
|
2037
|
-
else if (state.version !== bundled.version || force) planned.push({
|
|
2038
|
-
target,
|
|
2039
|
-
action: "updated",
|
|
2040
|
-
content: bundled.contents[target.tool]
|
|
2041
|
-
});
|
|
2042
|
-
else planned.push({
|
|
2043
|
-
target,
|
|
2044
|
-
action: "unchanged"
|
|
2045
|
-
});
|
|
2046
|
-
}
|
|
2047
|
-
await runActions(command, planned, parsed.options.dryRun === true, mode);
|
|
2048
|
-
}
|
|
2049
|
-
async function runSkillsRemove(parsed, mode) {
|
|
2050
|
-
const command = "skills remove";
|
|
2051
|
-
const filters = parseFilters(parsed);
|
|
2052
|
-
if (filters.error) return writeFailure(command, filters.error, mode, 1);
|
|
2053
|
-
const planned = [];
|
|
2054
|
-
for (const target of filteredTargets(filters.tools, filters.scope)) {
|
|
2055
|
-
const state = await readTarget(target);
|
|
2056
|
-
const action = state.kind === "missing" ? "not_installed" : state.kind === "managed" ? "removed" : "skipped_unmanaged";
|
|
2057
|
-
planned.push({
|
|
2058
|
-
target,
|
|
2059
|
-
action
|
|
2060
|
-
});
|
|
2061
|
-
}
|
|
2062
|
-
await runActions(command, planned, parsed.options.dryRun === true, mode);
|
|
2031
|
+
async function readArtifact(parsed, command) {
|
|
2032
|
+
const target = parseArtifactReadTarget(parsed, command);
|
|
2033
|
+
if (target.error) return { error: target.error };
|
|
2034
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2035
|
+
if (!credential.ok) return { error: credential.error };
|
|
2036
|
+
return await fetchArtifact(parsed, target.value, credential);
|
|
2063
2037
|
}
|
|
2064
|
-
|
|
2065
|
-
//#region src/command-runners/agent.ts
|
|
2066
|
-
async function runAgentOpen(parsed, mode) {
|
|
2067
|
-
const command = "agent open";
|
|
2068
|
-
const skills = await ensureSkills({
|
|
2069
|
-
...parsed,
|
|
2070
|
-
options: {
|
|
2071
|
-
...parsed.options,
|
|
2072
|
-
tool: "auto",
|
|
2073
|
-
scope: "project"
|
|
2074
|
-
}
|
|
2075
|
-
}, mode, { command });
|
|
2076
|
-
if (!skills) return;
|
|
2038
|
+
function parseArtifactReadTarget(parsed, command) {
|
|
2077
2039
|
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to read.");
|
|
2078
|
-
if (target.error) return
|
|
2079
|
-
const result = await readArtifact(parsed, command);
|
|
2080
|
-
if (result.error) {
|
|
2081
|
-
if (result.error.code === "unsupported_kind") return writeSuccess(command, {
|
|
2082
|
-
skills,
|
|
2083
|
-
open: {
|
|
2084
|
-
kind: "download_required",
|
|
2085
|
-
next_command: agentDownloadCommand(target.artifactId)
|
|
2086
|
-
}
|
|
2087
|
-
}, mode);
|
|
2088
|
-
return writeFailure(command, result.error, mode, 1);
|
|
2089
|
-
}
|
|
2090
|
-
return writeSuccess(command, {
|
|
2091
|
-
skills,
|
|
2092
|
-
open: {
|
|
2093
|
-
kind: "read",
|
|
2094
|
-
artifact: result.data
|
|
2095
|
-
}
|
|
2096
|
-
}, mode);
|
|
2097
|
-
}
|
|
2098
|
-
//#endregion
|
|
2099
|
-
//#region src/command-runners/comments.ts
|
|
2100
|
-
async function runCommentsList(parsed, mode) {
|
|
2101
|
-
const command = "comments list";
|
|
2102
|
-
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
2103
|
-
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2040
|
+
if (target.error) return { error: target.error };
|
|
2104
2041
|
const artifactId = target.artifactId;
|
|
2105
|
-
const
|
|
2106
|
-
if (
|
|
2042
|
+
const offset = parseOffsetOption(parsed.options.offset);
|
|
2043
|
+
if (offset.error) return { error: offset.error };
|
|
2044
|
+
const include = parseIncludeOptions(parsed.options.include);
|
|
2045
|
+
if (include.error) return { error: include.error };
|
|
2046
|
+
return { value: {
|
|
2047
|
+
artifactId,
|
|
2048
|
+
include: include.values,
|
|
2049
|
+
offset: offset.value
|
|
2050
|
+
} };
|
|
2051
|
+
}
|
|
2052
|
+
async function fetchArtifact(parsed, target, credential) {
|
|
2107
2053
|
const request = await requestConfig(parsed.options);
|
|
2108
|
-
if (request.error) return
|
|
2109
|
-
const
|
|
2110
|
-
if (
|
|
2111
|
-
const
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
if (!
|
|
2054
|
+
if (request.error) return { error: request.error };
|
|
2055
|
+
const url = apiUrl(`/api/cli/artifacts/${encodeURIComponent(target.artifactId)}`, baseUrlOf(parsed.options));
|
|
2056
|
+
if (target.offset !== void 0) url.searchParams.set("offset", target.offset);
|
|
2057
|
+
for (const item of target.include) url.searchParams.append("include", item);
|
|
2058
|
+
const response = await fetch(url, {
|
|
2059
|
+
headers: { Authorization: `Bearer ${credential.token}` },
|
|
2060
|
+
...request.init
|
|
2061
|
+
}).catch((error) => ({ networkError: error }));
|
|
2062
|
+
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
2063
|
+
const body = await readJson(response);
|
|
2064
|
+
if (!response.ok) return { error: mapApiError(response.status, body, {
|
|
2065
|
+
authenticated: true,
|
|
2066
|
+
artifactTarget: true,
|
|
2067
|
+
baseUrl: baseUrlOf(parsed.options),
|
|
2068
|
+
credentialSource: credential.source,
|
|
2069
|
+
profile: credential.profile
|
|
2070
|
+
}) };
|
|
2071
|
+
if (!artifactGetSuccessFields(body)) return { error: serviceError("Artifact read succeeded but the response did not include source metadata.") };
|
|
2072
|
+
return { data: body };
|
|
2119
2073
|
}
|
|
2120
|
-
async function
|
|
2121
|
-
const command = "
|
|
2122
|
-
const
|
|
2123
|
-
|
|
2124
|
-
const
|
|
2125
|
-
|
|
2126
|
-
if (
|
|
2127
|
-
const
|
|
2128
|
-
|
|
2129
|
-
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);
|
|
2130
|
-
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);
|
|
2074
|
+
async function runArtifactsList(parsed, mode) {
|
|
2075
|
+
const command = "artifacts list";
|
|
2076
|
+
const hasProjectId = parsed.options.projectId !== void 0;
|
|
2077
|
+
const projectId = parsed.options.projectId?.trim() ?? "";
|
|
2078
|
+
const home = Boolean(parsed.options.home);
|
|
2079
|
+
if (hasProjectId && !projectId) return writeFailure(command, validationError("--project-id must not be empty.", "Pass --project-id <id>, use --home, or omit the destination filter."), mode, 1);
|
|
2080
|
+
if (hasProjectIdHomeConflict(parsed.options)) return writeFailure(command, validationError("Artifact list destination is ambiguous.", "Choose only one destination filter: --project-id <id> or --home.", "destination_conflict"), mode, 1);
|
|
2081
|
+
const query = parsed.options.query?.trim();
|
|
2082
|
+
if (parsed.options.query !== void 0 && !query) return writeFailure(command, validationError("--query must not be empty.", "Pass --query <text> or omit --query."), mode, 1);
|
|
2131
2083
|
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2132
2084
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2133
2085
|
const request = await requestConfig(parsed.options);
|
|
2134
2086
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2135
|
-
const
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2087
|
+
const url = apiUrl("/api/cli/artifacts", baseUrlOf(parsed.options));
|
|
2088
|
+
if (home) url.searchParams.set("project_id", "");
|
|
2089
|
+
else if (projectId) url.searchParams.set("project_id", projectId);
|
|
2090
|
+
if (query) url.searchParams.set("query", query);
|
|
2091
|
+
const response = await fetch(url, {
|
|
2092
|
+
headers: { Authorization: `Bearer ${credential.token}` },
|
|
2093
|
+
...request.init
|
|
2094
|
+
}).catch((error) => ({ networkError: error }));
|
|
2095
|
+
if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
|
|
2096
|
+
const body = await readJson(response);
|
|
2097
|
+
if (!response.ok) return writeFailure(command, mapApiError(response.status, body, {
|
|
2098
|
+
authenticated: true,
|
|
2099
|
+
baseUrl: baseUrlOf(parsed.options),
|
|
2100
|
+
credentialSource: credential.source,
|
|
2101
|
+
profile: credential.profile
|
|
2102
|
+
}), mode, 1);
|
|
2103
|
+
if (!artifactsListSuccessFields(body)) return writeFailure(command, serviceError("Artifact list succeeded but the response did not include list metadata."), mode, 1);
|
|
2104
|
+
return writeSuccess(command, body, mode);
|
|
2152
2105
|
}
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2106
|
+
//#endregion
|
|
2107
|
+
//#region src/command-runners/skills.ts
|
|
2108
|
+
const SKILL_TOOLS = [
|
|
2109
|
+
"codex",
|
|
2110
|
+
"claude",
|
|
2111
|
+
"cursor"
|
|
2112
|
+
];
|
|
2113
|
+
const SKILL_FILE_PATH = join("skills", "artifactshare", "SKILL.md");
|
|
2114
|
+
const TOOL_CONFIG = {
|
|
2115
|
+
codex: {
|
|
2116
|
+
relativePath: join(".agents", SKILL_FILE_PATH),
|
|
2117
|
+
scopes: ["project", "user"],
|
|
2118
|
+
detectDirs: [".codex", ".agents"],
|
|
2119
|
+
bundledFile: "SKILL.md",
|
|
2120
|
+
pruneDirs: ["artifactshare", "skills"]
|
|
2121
|
+
},
|
|
2122
|
+
claude: {
|
|
2123
|
+
relativePath: join(".claude", SKILL_FILE_PATH),
|
|
2124
|
+
scopes: ["project", "user"],
|
|
2125
|
+
detectDirs: [".claude"],
|
|
2126
|
+
bundledFile: "SKILL.md",
|
|
2127
|
+
pruneDirs: ["artifactshare", "skills"]
|
|
2128
|
+
},
|
|
2129
|
+
cursor: {
|
|
2130
|
+
relativePath: join(".cursor", "rules", "artifactshare.mdc"),
|
|
2131
|
+
scopes: ["project"],
|
|
2132
|
+
detectDirs: [".cursor"],
|
|
2133
|
+
bundledFile: "artifactshare.mdc",
|
|
2134
|
+
pruneDirs: []
|
|
2135
|
+
}
|
|
2136
|
+
};
|
|
2137
|
+
function skillTarget(tool, scope) {
|
|
2138
|
+
const relative = TOOL_CONFIG[tool].relativePath;
|
|
2139
|
+
const path = scope === "project" ? relative : join(homedir(), relative);
|
|
2140
|
+
return {
|
|
2141
|
+
tool,
|
|
2142
|
+
scope,
|
|
2143
|
+
path,
|
|
2144
|
+
absolutePath: resolve(path)
|
|
2145
|
+
};
|
|
2178
2146
|
}
|
|
2179
|
-
|
|
2180
|
-
return
|
|
2147
|
+
function allTargets() {
|
|
2148
|
+
return SKILL_TOOLS.flatMap((tool) => TOOL_CONFIG[tool].scopes.map((scope) => skillTarget(tool, scope)));
|
|
2181
2149
|
}
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
const
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2150
|
+
function managedState(content) {
|
|
2151
|
+
if (content === null) return { kind: "missing" };
|
|
2152
|
+
if (!content.includes("artifactshare-skill")) return { kind: "unmanaged" };
|
|
2153
|
+
const block = content.match(/<!--\s*artifactshare-skill([\s\S]*?)-->/)?.[1];
|
|
2154
|
+
const version = block?.match(/(?:^|\n)\s*version:\s*(\d+)\s*(?:\n|$)/)?.[1];
|
|
2155
|
+
const managed = block !== void 0 && /(?:^|\n)\s*managed:\s*true\s*(?:\n|$)/.test(block);
|
|
2156
|
+
if (version === void 0 || !managed) return { kind: "broken" };
|
|
2157
|
+
return {
|
|
2158
|
+
kind: "managed",
|
|
2159
|
+
version: Number(version)
|
|
2191
2160
|
};
|
|
2192
|
-
if (parsed.options.messageId !== void 0) {
|
|
2193
|
-
if (!parsed.options.messageId.trim()) return writeFailure(command, validationError("--message-id cannot be empty.", "Run comments list and retry with a listed message_id."), mode, 1);
|
|
2194
|
-
payload.message_id = parsed.options.messageId.trim();
|
|
2195
|
-
}
|
|
2196
|
-
const result = await postCommentAction(parsed, command, target.artifactId, payload, mode);
|
|
2197
|
-
if (!result) return;
|
|
2198
|
-
const responseThreadId = configString(result.thread_id);
|
|
2199
|
-
if (!responseThreadId || result.deleted !== true) return writeFailure(command, serviceError("Comment was deleted but the response was incomplete."), mode, 1);
|
|
2200
|
-
writeSuccess(command, {
|
|
2201
|
-
artifact_id: target.artifactId,
|
|
2202
|
-
share_url: configString(result.share_url),
|
|
2203
|
-
thread_id: responseThreadId,
|
|
2204
|
-
deleted: true,
|
|
2205
|
-
thread_deleted: result.thread_deleted === true,
|
|
2206
|
-
...result.thread !== void 0 ? { thread: result.thread } : {}
|
|
2207
|
-
}, mode);
|
|
2208
2161
|
}
|
|
2209
|
-
async function
|
|
2210
|
-
|
|
2211
|
-
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2212
|
-
const threadId = requiredOption(parsed.options.threadId, "--thread-id is required.", "Run comments list and retry with a listed thread_id.");
|
|
2213
|
-
if (threadId.error) return writeFailure(command, threadId.error, mode, 1);
|
|
2214
|
-
const result = await postCommentAction(parsed, command, target.artifactId, {
|
|
2215
|
-
action,
|
|
2216
|
-
thread_id: threadId.value
|
|
2217
|
-
}, mode);
|
|
2218
|
-
if (!result) return;
|
|
2219
|
-
const responseThreadId = configString(result.thread_id);
|
|
2220
|
-
if (!responseThreadId || result.thread === void 0) return writeFailure(command, serviceError("Comment was changed but the response had no thread."), mode, 1);
|
|
2221
|
-
writeSuccess(command, {
|
|
2222
|
-
artifact_id: target.artifactId,
|
|
2223
|
-
share_url: configString(result.share_url),
|
|
2224
|
-
thread_id: responseThreadId,
|
|
2225
|
-
thread: result.thread
|
|
2226
|
-
}, mode);
|
|
2162
|
+
async function readTarget(target) {
|
|
2163
|
+
return managedState(await readFile(target.absolutePath, "utf8").catch(() => null));
|
|
2227
2164
|
}
|
|
2228
|
-
async function
|
|
2229
|
-
const
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2165
|
+
async function loadBundledSkills() {
|
|
2166
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
2167
|
+
const contents = {};
|
|
2168
|
+
let version;
|
|
2169
|
+
for (const tool of SKILL_TOOLS) {
|
|
2170
|
+
const file = TOOL_CONFIG[tool].bundledFile;
|
|
2171
|
+
let content = byFile.get(file);
|
|
2172
|
+
if (content === void 0) {
|
|
2173
|
+
content = await readFile(new URL(`../skills/artifactshare/${file}`, import.meta.url), "utf8");
|
|
2174
|
+
const state = managedState(content);
|
|
2175
|
+
if (state.kind !== "managed" || (version ?? state.version) !== state.version) throw new Error(`The bundled ${file} has a missing or mismatched managed marker.`);
|
|
2176
|
+
version = state.version;
|
|
2177
|
+
byFile.set(file, content);
|
|
2178
|
+
}
|
|
2179
|
+
contents[tool] = content;
|
|
2243
2180
|
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2181
|
+
return {
|
|
2182
|
+
contents,
|
|
2183
|
+
version
|
|
2184
|
+
};
|
|
2185
|
+
}
|
|
2186
|
+
function parseTools(value, options = {}) {
|
|
2187
|
+
const raws = arrayOption(value);
|
|
2188
|
+
const tools = [];
|
|
2189
|
+
for (const raw of raws) for (const item of raw.split(",")) {
|
|
2190
|
+
const trimmed = item.trim();
|
|
2191
|
+
if (!trimmed) continue;
|
|
2192
|
+
if (trimmed === "auto") {
|
|
2193
|
+
if (!options.allowAuto) return { error: validationError(`Unknown --tool value: ${trimmed}`, "Pass --tool codex, --tool claude, or --tool cursor.") };
|
|
2194
|
+
tools.push(trimmed);
|
|
2195
|
+
continue;
|
|
2196
|
+
}
|
|
2197
|
+
if (!SKILL_TOOLS.includes(trimmed)) return { error: validationError(`Unknown --tool value: ${trimmed}`, "Pass --tool codex, --tool claude, or --tool cursor.") };
|
|
2198
|
+
tools.push(trimmed);
|
|
2247
2199
|
}
|
|
2248
|
-
return
|
|
2200
|
+
if (raws.length > 0 && tools.length === 0) return { error: validationError("--tool has no value.", "Pass --tool codex, --tool claude, or --tool cursor.") };
|
|
2201
|
+
const unique = [...new Set(tools)];
|
|
2202
|
+
const auto = unique.includes("auto");
|
|
2203
|
+
if (auto && unique.length > 1) return { error: validationError("--tool auto cannot be combined with explicit tools.", "Pass --tool auto by itself, or pass --tool codex, --tool claude, or --tool cursor.") };
|
|
2204
|
+
return {
|
|
2205
|
+
tools: unique.filter((tool) => tool !== "auto"),
|
|
2206
|
+
auto
|
|
2207
|
+
};
|
|
2249
2208
|
}
|
|
2250
|
-
function
|
|
2251
|
-
|
|
2252
|
-
return {
|
|
2209
|
+
function parseScope(value) {
|
|
2210
|
+
const trimmed = nonEmpty(value);
|
|
2211
|
+
if (trimmed === void 0) return { scope: void 0 };
|
|
2212
|
+
if (trimmed === "project" || trimmed === "user") return { scope: trimmed };
|
|
2213
|
+
return { error: validationError(`Unknown --scope value: ${trimmed}`, "Pass --scope project or --scope user.") };
|
|
2253
2214
|
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
const
|
|
2258
|
-
|
|
2259
|
-
if (
|
|
2260
|
-
const
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
artifactTarget: true
|
|
2268
|
-
});
|
|
2269
|
-
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2270
|
-
const body = result.body;
|
|
2271
|
-
if (!deleteSuccessFields(body)) return writeFailure(command, serviceError("Delete succeeded but the response did not include deletion metadata."), mode, 1);
|
|
2272
|
-
return writeSuccess(command, body, mode);
|
|
2215
|
+
function parseFilters(parsed, options = {}) {
|
|
2216
|
+
const tools = parseTools(parsed.options.tool, options);
|
|
2217
|
+
if (tools.error) return { error: tools.error };
|
|
2218
|
+
const scope = parseScope(parsed.options.scope);
|
|
2219
|
+
if (scope.error) return { error: scope.error };
|
|
2220
|
+
if (tools.auto && scope.scope === "user") return { error: validationError("--tool auto supports project scope only.", "Use --tool auto --scope project, or pass an explicit --tool for user scope.") };
|
|
2221
|
+
const unsupported = scope.scope === void 0 ? void 0 : tools.tools.find((tool) => !TOOL_CONFIG[tool].scopes.includes(scope.scope));
|
|
2222
|
+
if (unsupported) return { error: validationError(`The ${unsupported} tool does not support --scope ${scope.scope}.`, `Use --tool ${unsupported} --scope project.`) };
|
|
2223
|
+
return {
|
|
2224
|
+
tools: tools.tools,
|
|
2225
|
+
auto: tools.auto,
|
|
2226
|
+
scope: scope.scope
|
|
2227
|
+
};
|
|
2273
2228
|
}
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
const LOGIN_COMMAND = `${CLI_INVOCATION} login`;
|
|
2277
|
-
const REQUEST_ACCESS_COMMAND = `${CLI_INVOCATION} request-access`;
|
|
2278
|
-
function bearerTokenBlocksLogin(data) {
|
|
2279
|
-
return data.auth.credential_source === "env" || data.auth.credential_source === "token_option";
|
|
2229
|
+
function filteredTargets(tools, scope) {
|
|
2230
|
+
return allTargets().filter((target) => (tools.length === 0 || tools.includes(target.tool)) && (scope === void 0 || target.scope === scope));
|
|
2280
2231
|
}
|
|
2281
|
-
function
|
|
2282
|
-
|
|
2283
|
-
if (bearerTokenBlocksLogin(data)) return null;
|
|
2284
|
-
return LOGIN_COMMAND;
|
|
2285
|
-
}
|
|
2286
|
-
if (data.config.project.code === "token_store_unsafe") {
|
|
2287
|
-
if (bearerTokenBlocksLogin(data)) return null;
|
|
2288
|
-
return LOGIN_COMMAND;
|
|
2289
|
-
}
|
|
2290
|
-
if ((data.auth.code === "auth_required" || data.auth.code === "token_invalid") && !bearerTokenBlocksLogin(data)) return data.auth.profile ? `${LOGIN_COMMAND} --profile ${data.auth.profile}` : LOGIN_COMMAND;
|
|
2291
|
-
if (!data.network.ok) return null;
|
|
2292
|
-
if (data.upload.checked && !data.upload.ok) {
|
|
2293
|
-
if (data.upload.code === "upload-not-allowed") return REQUEST_ACCESS_COMMAND;
|
|
2294
|
-
return null;
|
|
2295
|
-
}
|
|
2296
|
-
return null;
|
|
2232
|
+
function detectionBase(scope) {
|
|
2233
|
+
return scope === "project" ? process.cwd() : homedir();
|
|
2297
2234
|
}
|
|
2298
|
-
function
|
|
2299
|
-
const
|
|
2300
|
-
|
|
2235
|
+
async function isToolDetected(tool, scope) {
|
|
2236
|
+
const base = detectionBase(scope);
|
|
2237
|
+
for (const dir of TOOL_CONFIG[tool].detectDirs) if ((await stat(join(base, dir)).catch(() => null))?.isDirectory()) return true;
|
|
2238
|
+
return false;
|
|
2301
2239
|
}
|
|
2302
|
-
function
|
|
2303
|
-
const
|
|
2304
|
-
const
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
return next;
|
|
2240
|
+
async function autoTargets(scope) {
|
|
2241
|
+
const targetScope = scope ?? "project";
|
|
2242
|
+
const autoOrder = [
|
|
2243
|
+
"claude",
|
|
2244
|
+
"codex",
|
|
2245
|
+
"cursor"
|
|
2246
|
+
];
|
|
2247
|
+
const detected = /* @__PURE__ */ new Set();
|
|
2248
|
+
for (const tool of autoOrder) if (TOOL_CONFIG[tool].scopes.includes(targetScope) && await isToolDetected(tool, targetScope)) detected.add(tool);
|
|
2249
|
+
return (detected.size > 0 ? [...detected] : ["codex", "claude"]).filter((tool) => TOOL_CONFIG[tool].scopes.includes(targetScope)).map((tool) => skillTarget(tool, targetScope));
|
|
2313
2250
|
}
|
|
2314
|
-
async function
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
const data = {
|
|
2320
|
-
next_command: null,
|
|
2321
|
-
base_url: baseUrlOf(parsed.options),
|
|
2322
|
-
config: await configDiagnostics(project),
|
|
2323
|
-
auth: {
|
|
2324
|
-
credential_source: credential.source,
|
|
2325
|
-
...credential.profile ? { profile: credential.profile } : {},
|
|
2326
|
-
token_present: credential.ok,
|
|
2327
|
-
ok: false
|
|
2328
|
-
},
|
|
2329
|
-
destination: destination.error ? {
|
|
2330
|
-
ok: false,
|
|
2331
|
-
code: destination.error.code,
|
|
2332
|
-
hint: destination.error.hint
|
|
2333
|
-
} : {
|
|
2334
|
-
ok: true,
|
|
2335
|
-
type: destination.containerId ? "project" : "home",
|
|
2336
|
-
project_id: destination.containerId ?? null
|
|
2337
|
-
},
|
|
2338
|
-
network: { ok: false },
|
|
2339
|
-
upload: {
|
|
2340
|
-
ok: false,
|
|
2341
|
-
checked: false
|
|
2342
|
-
}
|
|
2343
|
-
};
|
|
2344
|
-
if (!credential.ok) {
|
|
2345
|
-
if (credential.error.code !== "auth_required") return writeFailure(command, credential.error, mode, 1);
|
|
2346
|
-
data.auth.code = credential.error.code;
|
|
2347
|
-
data.auth.hint = credential.error.hint;
|
|
2348
|
-
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
2349
|
-
}
|
|
2350
|
-
const request = await requestConfig(parsed.options);
|
|
2351
|
-
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2352
|
-
const response = await fetch(apiUrl("/api/cli/doctor", baseUrlOf(parsed.options)), {
|
|
2353
|
-
headers: { Authorization: `Bearer ${credential.token}` },
|
|
2354
|
-
...request.init
|
|
2355
|
-
}).catch((error) => ({ networkError: error }));
|
|
2356
|
-
if ("networkError" in response) {
|
|
2357
|
-
data.network = {
|
|
2358
|
-
ok: false,
|
|
2359
|
-
code: "network_failed",
|
|
2360
|
-
hint: networkError(response.networkError).hint
|
|
2361
|
-
};
|
|
2362
|
-
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
2251
|
+
async function applyAction({ target, action, content }) {
|
|
2252
|
+
if (content !== void 0) {
|
|
2253
|
+
await mkdir(dirname(target.absolutePath), { recursive: true });
|
|
2254
|
+
await writeFile(target.absolutePath, content);
|
|
2255
|
+
return;
|
|
2363
2256
|
}
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
const error = mapApiError(response.status, body, { authenticated: true });
|
|
2368
|
-
data.auth.code = error.code;
|
|
2369
|
-
data.auth.hint = error.hint;
|
|
2370
|
-
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
2257
|
+
if (action === "removed") {
|
|
2258
|
+
await rm(target.absolutePath, { force: true });
|
|
2259
|
+
await cleanupSkillDirs(target);
|
|
2371
2260
|
}
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2261
|
+
}
|
|
2262
|
+
async function cleanupSkillDirs(target) {
|
|
2263
|
+
let dir = dirname(target.absolutePath);
|
|
2264
|
+
for (const expected of TOOL_CONFIG[target.tool].pruneDirs) {
|
|
2265
|
+
if (basename(dir) !== expected) return;
|
|
2266
|
+
try {
|
|
2267
|
+
await rmdir(dir);
|
|
2268
|
+
} catch {
|
|
2269
|
+
return;
|
|
2270
|
+
}
|
|
2271
|
+
dir = dirname(dir);
|
|
2380
2272
|
}
|
|
2381
|
-
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
2382
2273
|
}
|
|
2383
|
-
async function
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2274
|
+
async function finishActions(command, planned, dryRun, mode) {
|
|
2275
|
+
if (!dryRun) try {
|
|
2276
|
+
for (const item of planned) await applyAction(item);
|
|
2277
|
+
} catch (error) {
|
|
2278
|
+
writeFailure(command, unexpectedError(error), mode, 1);
|
|
2279
|
+
return;
|
|
2280
|
+
}
|
|
2389
2281
|
return {
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
}
|
|
2397
|
-
effective: effectiveDiagnostics(project, globalConfig)
|
|
2282
|
+
dry_run: dryRun,
|
|
2283
|
+
targets: planned.map(({ target, action }) => ({
|
|
2284
|
+
tool: target.tool,
|
|
2285
|
+
scope: target.scope,
|
|
2286
|
+
path: target.path,
|
|
2287
|
+
action
|
|
2288
|
+
}))
|
|
2398
2289
|
};
|
|
2399
2290
|
}
|
|
2400
|
-
function
|
|
2401
|
-
const
|
|
2402
|
-
|
|
2403
|
-
present: raw !== null,
|
|
2404
|
-
path,
|
|
2405
|
-
default_profile: configString(raw?.default_profile),
|
|
2406
|
-
default_project_id: configString(raw?.default_project_id),
|
|
2407
|
-
...unsafeKey ? {
|
|
2408
|
-
code: "token_store_unsafe",
|
|
2409
|
-
hint: `Remove "${unsafeKey}" from ${path ?? "the working-directory config"} and run ${CLI_INVOCATION} login instead; the working-directory config must never hold secrets.`
|
|
2410
|
-
} : {}
|
|
2411
|
-
};
|
|
2291
|
+
async function runActions(command, planned, dryRun, mode) {
|
|
2292
|
+
const data = await finishActions(command, planned, dryRun, mode);
|
|
2293
|
+
if (data) writeSuccess(command, data, mode);
|
|
2412
2294
|
}
|
|
2413
|
-
function
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
const defaultProjectId = projectProjectId;
|
|
2421
|
-
const defaultProjectIdSource = projectProjectId ? project.kind === "local" ? "local" : "project" : "none";
|
|
2422
|
-
return {
|
|
2423
|
-
default_profile: defaultProfile,
|
|
2424
|
-
default_profile_source: defaultProfileSource,
|
|
2425
|
-
default_profile_path: defaultProfilePath,
|
|
2426
|
-
default_project_id: defaultProjectId,
|
|
2427
|
-
default_project_id_source: defaultProjectIdSource,
|
|
2428
|
-
default_project_id_path: defaultProjectIdSource === "local" || defaultProjectIdSource === "project" ? project.path : null
|
|
2429
|
-
};
|
|
2295
|
+
async function bundledOrFailure(command, mode) {
|
|
2296
|
+
try {
|
|
2297
|
+
return await loadBundledSkills();
|
|
2298
|
+
} catch (error) {
|
|
2299
|
+
writeFailure(command, unexpectedError(error), mode, 1);
|
|
2300
|
+
return;
|
|
2301
|
+
}
|
|
2430
2302
|
}
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
if (
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2303
|
+
async function runSkillsInstall(parsed, mode) {
|
|
2304
|
+
const command = "skills install";
|
|
2305
|
+
const filters = parseFilters(parsed);
|
|
2306
|
+
if (filters.error) return writeFailure(command, filters.error, mode, 1);
|
|
2307
|
+
const { tools } = filters;
|
|
2308
|
+
if (tools.length === 0) return writeFailure(command, validationError("--tool is required.", "Pass --tool codex, --tool claude, or --tool cursor; repeat for multiple tools."), mode, 1);
|
|
2309
|
+
const scope = filters.scope ?? "project";
|
|
2310
|
+
const force = parsed.options.force === true;
|
|
2311
|
+
const bundled = await bundledOrFailure(command, mode);
|
|
2312
|
+
if (!bundled) return;
|
|
2313
|
+
const planned = [];
|
|
2314
|
+
for (const tool of tools) {
|
|
2315
|
+
const target = skillTarget(tool, scope);
|
|
2316
|
+
const state = await readTarget(target);
|
|
2317
|
+
if ((state.kind === "unmanaged" || state.kind === "broken") && !force) return writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
2318
|
+
if (state.kind === "managed" && state.version === bundled.version && !force) {
|
|
2319
|
+
planned.push({
|
|
2320
|
+
target,
|
|
2321
|
+
action: "unchanged"
|
|
2322
|
+
});
|
|
2323
|
+
continue;
|
|
2441
2324
|
}
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
} };
|
|
2325
|
+
planned.push({
|
|
2326
|
+
target,
|
|
2327
|
+
action: state.kind === "missing" ? "installed" : "updated",
|
|
2328
|
+
content: bundled.contents[tool]
|
|
2329
|
+
});
|
|
2448
2330
|
}
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2331
|
+
await runActions(command, planned, parsed.options.dryRun === true, mode);
|
|
2332
|
+
}
|
|
2333
|
+
async function ensureSkills(parsed, mode, options = {}) {
|
|
2334
|
+
const command = options.command ?? "skills ensure";
|
|
2335
|
+
const filters = parseFilters(parsed, { allowAuto: true });
|
|
2336
|
+
if (filters.error) {
|
|
2337
|
+
writeFailure(command, filters.error, mode, 1);
|
|
2338
|
+
return;
|
|
2455
2339
|
}
|
|
2456
|
-
|
|
2340
|
+
if (filters.tools.length === 0 && !filters.auto) {
|
|
2341
|
+
writeFailure(command, validationError("--tool is required.", "Pass --tool auto, --tool codex, --tool claude, or --tool cursor; repeat explicit tools for multiple targets."), mode, 1);
|
|
2342
|
+
return;
|
|
2343
|
+
}
|
|
2344
|
+
const bundled = await bundledOrFailure(command, mode);
|
|
2345
|
+
if (!bundled) return void 0;
|
|
2346
|
+
const targets = filters.auto ? await autoTargets(filters.scope) : filteredTargets(filters.tools, filters.scope ?? "project");
|
|
2347
|
+
const planned = [];
|
|
2348
|
+
for (const target of targets) {
|
|
2349
|
+
const state = await readTarget(target);
|
|
2350
|
+
if (state.kind === "unmanaged" || state.kind === "broken") {
|
|
2351
|
+
writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
2352
|
+
return;
|
|
2353
|
+
}
|
|
2354
|
+
const unchanged = state.kind === "managed" && state.version === bundled.version;
|
|
2355
|
+
planned.push(unchanged ? {
|
|
2356
|
+
target,
|
|
2357
|
+
action: "unchanged"
|
|
2358
|
+
} : {
|
|
2359
|
+
target,
|
|
2360
|
+
action: state.kind === "missing" ? "installed" : "updated",
|
|
2361
|
+
content: bundled.contents[target.tool]
|
|
2362
|
+
});
|
|
2363
|
+
}
|
|
2364
|
+
return finishActions(command, planned, parsed.options.dryRun === true, mode);
|
|
2457
2365
|
}
|
|
2458
|
-
async function
|
|
2459
|
-
|
|
2460
|
-
if (
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
if (
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
const relativePath = downloadRelativePath(file.path);
|
|
2478
|
-
if (relativePath.error) return { error: relativePath.error };
|
|
2479
|
-
if (seen.has(relativePath.value)) return { error: validationError("Download manifest contains duplicate file paths.", "Retry later. If this repeats, report the artifact ID.") };
|
|
2480
|
-
seen.add(relativePath.value);
|
|
2481
|
-
relativeFiles.push({
|
|
2482
|
-
...file,
|
|
2483
|
-
relativePath: relativePath.value
|
|
2366
|
+
async function runSkillsEnsure(parsed, mode) {
|
|
2367
|
+
const data = await ensureSkills(parsed, mode);
|
|
2368
|
+
if (data) writeSuccess("skills ensure", data, mode);
|
|
2369
|
+
}
|
|
2370
|
+
async function runSkillsList(parsed, mode) {
|
|
2371
|
+
const bundled = await bundledOrFailure("skills list", mode);
|
|
2372
|
+
if (!bundled) return;
|
|
2373
|
+
const targets = [];
|
|
2374
|
+
for (const target of allTargets()) {
|
|
2375
|
+
const state = await readTarget(target);
|
|
2376
|
+
targets.push({
|
|
2377
|
+
tool: target.tool,
|
|
2378
|
+
scope: target.scope,
|
|
2379
|
+
path: target.path,
|
|
2380
|
+
detected: await isToolDetected(target.tool, target.scope),
|
|
2381
|
+
installed: state.kind !== "missing",
|
|
2382
|
+
managed: state.kind === "managed",
|
|
2383
|
+
installed_version: state.kind === "managed" ? state.version : null,
|
|
2384
|
+
update_available: state.kind === "managed" && state.version !== bundled.version
|
|
2484
2385
|
});
|
|
2485
2386
|
}
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2387
|
+
return writeSuccess("skills list", {
|
|
2388
|
+
bundled_version: bundled.version,
|
|
2389
|
+
targets
|
|
2390
|
+
}, mode);
|
|
2391
|
+
}
|
|
2392
|
+
async function runSkillsUpdate(parsed, mode) {
|
|
2393
|
+
const command = "skills update";
|
|
2394
|
+
const filters = parseFilters(parsed);
|
|
2395
|
+
if (filters.error) return writeFailure(command, filters.error, mode, 1);
|
|
2396
|
+
const force = parsed.options.force === true;
|
|
2397
|
+
const bundled = await bundledOrFailure(command, mode);
|
|
2398
|
+
if (!bundled) return;
|
|
2399
|
+
const planned = [];
|
|
2400
|
+
for (const target of filteredTargets(filters.tools, filters.scope)) {
|
|
2401
|
+
const state = await readTarget(target);
|
|
2402
|
+
if (state.kind === "broken") return writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
2403
|
+
if (state.kind === "missing") planned.push({
|
|
2404
|
+
target,
|
|
2405
|
+
action: "not_installed"
|
|
2406
|
+
});
|
|
2407
|
+
else if (state.kind === "unmanaged") planned.push({
|
|
2408
|
+
target,
|
|
2409
|
+
action: "skipped_unmanaged"
|
|
2410
|
+
});
|
|
2411
|
+
else if (state.version !== bundled.version || force) planned.push({
|
|
2412
|
+
target,
|
|
2413
|
+
action: "updated",
|
|
2414
|
+
content: bundled.contents[target.tool]
|
|
2415
|
+
});
|
|
2416
|
+
else planned.push({
|
|
2417
|
+
target,
|
|
2418
|
+
action: "unchanged"
|
|
2495
2419
|
});
|
|
2496
2420
|
}
|
|
2497
|
-
|
|
2498
|
-
root,
|
|
2499
|
-
tempRoot,
|
|
2500
|
-
replaceExisting: Boolean(existing),
|
|
2501
|
-
files
|
|
2502
|
-
} };
|
|
2421
|
+
await runActions(command, planned, parsed.options.dryRun === true, mode);
|
|
2503
2422
|
}
|
|
2504
|
-
function
|
|
2505
|
-
|
|
2506
|
-
const
|
|
2507
|
-
if (
|
|
2508
|
-
|
|
2423
|
+
async function runSkillsRemove(parsed, mode) {
|
|
2424
|
+
const command = "skills remove";
|
|
2425
|
+
const filters = parseFilters(parsed);
|
|
2426
|
+
if (filters.error) return writeFailure(command, filters.error, mode, 1);
|
|
2427
|
+
const planned = [];
|
|
2428
|
+
for (const target of filteredTargets(filters.tools, filters.scope)) {
|
|
2429
|
+
const state = await readTarget(target);
|
|
2430
|
+
const action = state.kind === "missing" ? "not_installed" : state.kind === "managed" ? "removed" : "skipped_unmanaged";
|
|
2431
|
+
planned.push({
|
|
2432
|
+
target,
|
|
2433
|
+
action
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
await runActions(command, planned, parsed.options.dryRun === true, mode);
|
|
2437
|
+
}
|
|
2438
|
+
//#endregion
|
|
2439
|
+
//#region src/command-runners/open.ts
|
|
2440
|
+
async function runOpen(parsed, mode) {
|
|
2441
|
+
const command = "open";
|
|
2442
|
+
const skills = await ensureSkills({
|
|
2443
|
+
...parsed,
|
|
2444
|
+
options: {
|
|
2445
|
+
...parsed.options,
|
|
2446
|
+
tool: "auto",
|
|
2447
|
+
scope: "project"
|
|
2448
|
+
}
|
|
2449
|
+
}, mode, { command });
|
|
2450
|
+
if (!skills) return;
|
|
2451
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to read.");
|
|
2452
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2453
|
+
const result = await readArtifact(parsed, command);
|
|
2454
|
+
if (result.error) {
|
|
2455
|
+
if (result.error.code === "unsupported_kind") return writeSuccess(command, {
|
|
2456
|
+
skills,
|
|
2457
|
+
open: {
|
|
2458
|
+
kind: "download_required",
|
|
2459
|
+
next_command: agentDownloadCommand(target.artifactId)
|
|
2460
|
+
}
|
|
2461
|
+
}, mode);
|
|
2462
|
+
return writeFailure(command, result.error, mode, 1);
|
|
2463
|
+
}
|
|
2464
|
+
return writeSuccess(command, {
|
|
2465
|
+
skills,
|
|
2466
|
+
open: {
|
|
2467
|
+
kind: "read",
|
|
2468
|
+
artifact: result.data
|
|
2469
|
+
}
|
|
2470
|
+
}, mode);
|
|
2471
|
+
}
|
|
2472
|
+
//#endregion
|
|
2473
|
+
//#region src/command-runners/comments.ts
|
|
2474
|
+
async function runCommentsList(parsed, mode) {
|
|
2475
|
+
const command = "comments list";
|
|
2476
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
2477
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2478
|
+
const artifactId = target.artifactId;
|
|
2479
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2480
|
+
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2481
|
+
const request = await requestConfig(parsed.options);
|
|
2482
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2483
|
+
const result = await apiGet(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, parsed.options, request.init, {
|
|
2484
|
+
artifactTarget: true,
|
|
2485
|
+
credentialSource: credential.source,
|
|
2486
|
+
profile: credential.profile
|
|
2487
|
+
});
|
|
2488
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2489
|
+
const comments = Array.isArray(result.body?.comments) ? result.body.comments : [];
|
|
2490
|
+
writeSuccess(command, {
|
|
2491
|
+
artifact_id: artifactId,
|
|
2492
|
+
share_url: configString(result.body?.share_url),
|
|
2493
|
+
comments,
|
|
2494
|
+
has_more: result.body?.has_more === true
|
|
2495
|
+
}, mode);
|
|
2496
|
+
if (!mode.json && comments.length === 0) writeText("No comments yet.\n");
|
|
2497
|
+
}
|
|
2498
|
+
async function runCommentsPost(parsed, mode) {
|
|
2499
|
+
const command = "comments post";
|
|
2500
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
2501
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2502
|
+
const artifactId = target.artifactId;
|
|
2503
|
+
const body = parsed.options.body;
|
|
2504
|
+
if (!body || !body.trim()) return writeFailure(command, validationError("A comment body is required.", "Retry with --body <text>."), mode, 1);
|
|
2505
|
+
const replyTo = parsed.options.replyTo;
|
|
2506
|
+
const quote = parsed.options.quote;
|
|
2507
|
+
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);
|
|
2508
|
+
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);
|
|
2509
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2510
|
+
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2511
|
+
const request = await requestConfig(parsed.options);
|
|
2512
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2513
|
+
const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, {
|
|
2514
|
+
body,
|
|
2515
|
+
reply_to: replyTo,
|
|
2516
|
+
quote,
|
|
2517
|
+
quote_before: parsed.options.quoteBefore,
|
|
2518
|
+
quote_after: parsed.options.quoteAfter
|
|
2519
|
+
}, parsed.options, request.init, {
|
|
2520
|
+
artifactTarget: true,
|
|
2521
|
+
credentialSource: credential.source,
|
|
2522
|
+
profile: credential.profile
|
|
2523
|
+
});
|
|
2524
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2525
|
+
const threadId = configString(result.body?.thread_id);
|
|
2526
|
+
if (!threadId) return writeFailure(command, serviceError("Comment was saved but the response had no thread id."), mode, 1);
|
|
2527
|
+
writeSuccess(command, {
|
|
2528
|
+
artifact_id: artifactId,
|
|
2529
|
+
share_url: configString(result.body?.share_url),
|
|
2530
|
+
thread_id: threadId,
|
|
2531
|
+
reply: result.body?.reply === true,
|
|
2532
|
+
thread: result.body?.thread ?? null
|
|
2533
|
+
}, mode);
|
|
2534
|
+
}
|
|
2535
|
+
async function runCommentsEdit(parsed, mode) {
|
|
2536
|
+
const command = "comments edit";
|
|
2537
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
2538
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2539
|
+
const messageId = requiredOption(parsed.options.messageId, "--message-id is required.", "Run comments list and retry with a listed message_id.");
|
|
2540
|
+
if (messageId.error) return writeFailure(command, messageId.error, mode, 1);
|
|
2541
|
+
const body = requiredOption(parsed.options.body, "--body is required.", "Pass --body <text> with the updated comment.");
|
|
2542
|
+
if (body.error) return writeFailure(command, body.error, mode, 1);
|
|
2543
|
+
const result = await postCommentAction(parsed, command, target.artifactId, {
|
|
2544
|
+
action: "edit",
|
|
2545
|
+
message_id: messageId.value,
|
|
2546
|
+
body: body.value
|
|
2547
|
+
}, mode);
|
|
2548
|
+
if (!result) return;
|
|
2549
|
+
const threadId = configString(result.thread_id);
|
|
2550
|
+
if (!threadId || result.thread === void 0) return writeFailure(command, serviceError("Comment was changed but the response had no thread."), mode, 1);
|
|
2551
|
+
writeSuccess(command, {
|
|
2552
|
+
artifact_id: target.artifactId,
|
|
2553
|
+
share_url: configString(result.share_url),
|
|
2554
|
+
thread_id: threadId,
|
|
2555
|
+
thread: result.thread
|
|
2556
|
+
}, mode);
|
|
2509
2557
|
}
|
|
2510
|
-
function
|
|
2511
|
-
|
|
2512
|
-
if (file.sha256) {
|
|
2513
|
-
if (createHash("sha256").update(bytes).digest("base64url") !== file.sha256) return { error: downloadIntegrityError(file.path, "sha256 mismatch") };
|
|
2514
|
-
}
|
|
2515
|
-
return { ok: true };
|
|
2558
|
+
async function runCommentsResolve(parsed, mode) {
|
|
2559
|
+
return await runCommentsStatus(parsed, mode, "comments resolve", "resolve");
|
|
2516
2560
|
}
|
|
2517
|
-
function
|
|
2518
|
-
return
|
|
2519
|
-
code: "download_integrity_failed",
|
|
2520
|
-
message: "Downloaded file did not match the manifest.",
|
|
2521
|
-
why: `The downloaded file ${path} failed integrity verification: ${reason}.`,
|
|
2522
|
-
hint: "Retry the download. If this repeats, report the artifact ID.",
|
|
2523
|
-
agentRecoverable: true,
|
|
2524
|
-
requiresHuman: false,
|
|
2525
|
-
recovery: { kind: "retry_later" }
|
|
2526
|
-
});
|
|
2561
|
+
async function runCommentsReopen(parsed, mode) {
|
|
2562
|
+
return await runCommentsStatus(parsed, mode, "comments reopen", "reopen");
|
|
2527
2563
|
}
|
|
2528
|
-
function
|
|
2529
|
-
|
|
2564
|
+
async function runCommentsDelete(parsed, mode) {
|
|
2565
|
+
const command = "comments delete";
|
|
2566
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
2567
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2568
|
+
const threadId = requiredOption(parsed.options.threadId, "--thread-id is required.", "Run comments list and retry with a listed thread_id.");
|
|
2569
|
+
if (threadId.error) return writeFailure(command, threadId.error, mode, 1);
|
|
2570
|
+
const payload = {
|
|
2571
|
+
action: "delete",
|
|
2572
|
+
thread_id: threadId.value
|
|
2573
|
+
};
|
|
2574
|
+
if (parsed.options.messageId !== void 0) {
|
|
2575
|
+
if (!parsed.options.messageId.trim()) return writeFailure(command, validationError("--message-id cannot be empty.", "Run comments list and retry with a listed message_id."), mode, 1);
|
|
2576
|
+
payload.message_id = parsed.options.messageId.trim();
|
|
2577
|
+
}
|
|
2578
|
+
const result = await postCommentAction(parsed, command, target.artifactId, payload, mode);
|
|
2579
|
+
if (!result) return;
|
|
2580
|
+
const responseThreadId = configString(result.thread_id);
|
|
2581
|
+
if (!responseThreadId || result.deleted !== true) return writeFailure(command, serviceError("Comment was deleted but the response was incomplete."), mode, 1);
|
|
2582
|
+
writeSuccess(command, {
|
|
2583
|
+
artifact_id: target.artifactId,
|
|
2584
|
+
share_url: configString(result.share_url),
|
|
2585
|
+
thread_id: responseThreadId,
|
|
2586
|
+
deleted: true,
|
|
2587
|
+
thread_deleted: result.thread_deleted === true,
|
|
2588
|
+
...result.thread !== void 0 ? { thread: result.thread } : {}
|
|
2589
|
+
}, mode);
|
|
2530
2590
|
}
|
|
2531
|
-
async function
|
|
2532
|
-
|
|
2591
|
+
async function runCommentsStatus(parsed, mode, command, action) {
|
|
2592
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
2593
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2594
|
+
const threadId = requiredOption(parsed.options.threadId, "--thread-id is required.", "Run comments list and retry with a listed thread_id.");
|
|
2595
|
+
if (threadId.error) return writeFailure(command, threadId.error, mode, 1);
|
|
2596
|
+
const result = await postCommentAction(parsed, command, target.artifactId, {
|
|
2597
|
+
action,
|
|
2598
|
+
thread_id: threadId.value
|
|
2599
|
+
}, mode);
|
|
2600
|
+
if (!result) return;
|
|
2601
|
+
const responseThreadId = configString(result.thread_id);
|
|
2602
|
+
if (!responseThreadId || result.thread === void 0) return writeFailure(command, serviceError("Comment was changed but the response had no thread."), mode, 1);
|
|
2603
|
+
writeSuccess(command, {
|
|
2604
|
+
artifact_id: target.artifactId,
|
|
2605
|
+
share_url: configString(result.share_url),
|
|
2606
|
+
thread_id: responseThreadId,
|
|
2607
|
+
thread: result.thread
|
|
2608
|
+
}, mode);
|
|
2533
2609
|
}
|
|
2534
|
-
function
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2610
|
+
async function postCommentAction(parsed, command, artifactId, payload, mode) {
|
|
2611
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2612
|
+
if (!credential.ok) {
|
|
2613
|
+
writeFailure(command, credential.error, mode, 1);
|
|
2614
|
+
return null;
|
|
2615
|
+
}
|
|
2616
|
+
const request = await requestConfig(parsed.options);
|
|
2617
|
+
if (request.error) {
|
|
2618
|
+
writeFailure(command, request.error, mode, 1);
|
|
2619
|
+
return null;
|
|
2620
|
+
}
|
|
2621
|
+
const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, payload, parsed.options, request.init, {
|
|
2622
|
+
artifactTarget: true,
|
|
2623
|
+
credentialSource: credential.source,
|
|
2624
|
+
profile: credential.profile
|
|
2543
2625
|
});
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
async function visit(dir) {
|
|
2548
|
-
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
2549
|
-
if (entry.name === "__MACOSX") continue;
|
|
2550
|
-
const fullPath = join(dir, entry.name);
|
|
2551
|
-
if (entry.isSymbolicLink()) throw new CollectDirectoryFilesError("Directory contains a symbolic link.", "Remove or replace symlinked files and directories before publishing.");
|
|
2552
|
-
if (entry.isDirectory()) {
|
|
2553
|
-
if (EXCLUDED_DIR_NAMES.has(entry.name) || entry.name.startsWith(".")) continue;
|
|
2554
|
-
await visit(fullPath);
|
|
2555
|
-
continue;
|
|
2556
|
-
}
|
|
2557
|
-
if (!entry.isFile() || IGNORED_FILENAMES.has(entry.name) || entry.name.startsWith(".")) continue;
|
|
2558
|
-
const relativePath = relative(root, fullPath).split(sep).join("/");
|
|
2559
|
-
results.push({
|
|
2560
|
-
path: fullPath,
|
|
2561
|
-
relativePath
|
|
2562
|
-
});
|
|
2563
|
-
}
|
|
2626
|
+
if (result.error) {
|
|
2627
|
+
writeFailure(command, result.error, mode, 1);
|
|
2628
|
+
return null;
|
|
2564
2629
|
}
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
}
|
|
2569
|
-
var CollectDirectoryFilesError = class extends Error {
|
|
2570
|
-
hint;
|
|
2571
|
-
constructor(message, hint) {
|
|
2572
|
-
super(message);
|
|
2573
|
-
this.name = "CollectDirectoryFilesError";
|
|
2574
|
-
this.hint = hint;
|
|
2630
|
+
if (result.body === null) {
|
|
2631
|
+
writeFailure(command, serviceError("Comment was changed but the response was empty."), mode, 1);
|
|
2632
|
+
return null;
|
|
2575
2633
|
}
|
|
2576
|
-
|
|
2577
|
-
async function blobFor(path) {
|
|
2578
|
-
const chunks = [];
|
|
2579
|
-
for await (const chunk of createReadStream(path)) chunks.push(chunk);
|
|
2580
|
-
return new Blob(chunks, { type: contentTypeFor(path) });
|
|
2581
|
-
}
|
|
2582
|
-
function contentTypeFor(path) {
|
|
2583
|
-
if (path.endsWith(".html")) return "text/html";
|
|
2584
|
-
if (path.endsWith(".md")) return "text/markdown";
|
|
2585
|
-
if (path.endsWith(".css")) return "text/css";
|
|
2586
|
-
if (path.endsWith(".js")) return "text/javascript";
|
|
2587
|
-
if (path.endsWith(".json")) return "application/json";
|
|
2588
|
-
if (path.endsWith(".svg")) return "image/svg+xml";
|
|
2589
|
-
if (path.endsWith(".png")) return "image/png";
|
|
2590
|
-
if (path.endsWith(".jpg") || path.endsWith(".jpeg")) return "image/jpeg";
|
|
2591
|
-
return "application/octet-stream";
|
|
2634
|
+
return result.body;
|
|
2592
2635
|
}
|
|
2593
|
-
function
|
|
2594
|
-
|
|
2636
|
+
function requiredOption(value, message, hint) {
|
|
2637
|
+
if (!value || !value.trim()) return { error: validationError(message, hint) };
|
|
2638
|
+
return { value: value.trim() };
|
|
2595
2639
|
}
|
|
2596
2640
|
//#endregion
|
|
2597
|
-
//#region src/command-runners/
|
|
2598
|
-
async function
|
|
2599
|
-
const
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
verification_uri: code.verification_uri,
|
|
2613
|
-
verification_uri_complete: code.verification_uri_complete ?? null,
|
|
2614
|
-
user_code: code.user_code,
|
|
2615
|
-
expires_at: new Date(deadline).toISOString(),
|
|
2616
|
-
interval_seconds: code.interval
|
|
2641
|
+
//#region src/command-runners/delete.ts
|
|
2642
|
+
async function runDelete(parsed, mode) {
|
|
2643
|
+
const command = "delete";
|
|
2644
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to delete.");
|
|
2645
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2646
|
+
const artifactId = target.artifactId;
|
|
2647
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2648
|
+
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2649
|
+
const request = await requestConfig(parsed.options);
|
|
2650
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2651
|
+
const result = await apiDelete(`/api/cli/artifacts/${encodeURIComponent(artifactId)}`, credential.token, parsed.options, request.init, {
|
|
2652
|
+
authenticated: true,
|
|
2653
|
+
artifactTarget: true,
|
|
2654
|
+
credentialSource: credential.source,
|
|
2655
|
+
profile: credential.profile
|
|
2617
2656
|
});
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
workspace: stored.data.workspace,
|
|
2645
|
-
verification_uri: code.verification_uri,
|
|
2646
|
-
verification_uri_complete: code.verification_uri_complete ?? null,
|
|
2647
|
-
user_code: code.user_code,
|
|
2648
|
-
expires_at: sessionExpiresAt,
|
|
2649
|
-
interval_seconds: code.interval
|
|
2650
|
-
};
|
|
2651
|
-
if (effective.profile && effective.profile !== profile) {
|
|
2652
|
-
data.effective_default_profile = effective.profile;
|
|
2653
|
-
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.`;
|
|
2657
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2658
|
+
const body = result.body;
|
|
2659
|
+
if (!deleteSuccessFields(body)) return writeFailure(command, serviceError("Delete succeeded but the response did not include deletion metadata."), mode, 1);
|
|
2660
|
+
return writeSuccess(command, body, mode);
|
|
2661
|
+
}
|
|
2662
|
+
//#endregion
|
|
2663
|
+
//#region src/command-runners/doctor.ts
|
|
2664
|
+
const LOGIN_COMMAND = `${CLI_INVOCATION} login`;
|
|
2665
|
+
const REQUEST_ACCESS_COMMAND = `${CLI_INVOCATION} request-access`;
|
|
2666
|
+
function bearerTokenBlocksLogin(data) {
|
|
2667
|
+
return data.auth.credential_source === "env" || data.auth.credential_source === "token_option";
|
|
2668
|
+
}
|
|
2669
|
+
function resolveDoctorNextCommand(data) {
|
|
2670
|
+
if (data.config.local.code === "token_store_unsafe") {
|
|
2671
|
+
if (bearerTokenBlocksLogin(data)) return null;
|
|
2672
|
+
return LOGIN_COMMAND;
|
|
2673
|
+
}
|
|
2674
|
+
if (data.config.project.code === "token_store_unsafe") {
|
|
2675
|
+
if (bearerTokenBlocksLogin(data)) return null;
|
|
2676
|
+
return LOGIN_COMMAND;
|
|
2677
|
+
}
|
|
2678
|
+
if ((data.auth.code === "auth_required" || data.auth.code === "token_invalid") && !bearerTokenBlocksLogin(data)) return data.auth.profile ? `${LOGIN_COMMAND} --profile ${data.auth.profile}` : LOGIN_COMMAND;
|
|
2679
|
+
if (!data.network.ok) return null;
|
|
2680
|
+
if (data.upload.checked && !data.upload.ok) {
|
|
2681
|
+
if (data.upload.code === "upload-not-allowed") return REQUEST_ACCESS_COMMAND;
|
|
2682
|
+
return null;
|
|
2654
2683
|
}
|
|
2655
|
-
return
|
|
2656
|
-
ok: true,
|
|
2657
|
-
data
|
|
2658
|
-
};
|
|
2659
|
-
}
|
|
2660
|
-
async function runLogin(parsed, mode) {
|
|
2661
|
-
const command = "login";
|
|
2662
|
-
const profile = nonEmpty(parsed.options.profile) ?? "default";
|
|
2663
|
-
if (nonEmpty(process.env.ARTIFACTSHARE_TOKEN) || nonEmpty(parsed.options.token)) return writeFailure(command, validationError("Login cannot run with a bearer token already selected.", "Unset ARTIFACTSHARE_TOKEN and remove --token before running login."), mode, 1);
|
|
2664
|
-
const result = await performDeviceLogin(profile, parsed.options, mode);
|
|
2665
|
-
if (!result.ok) return writeFailure(command, result.error, mode, 1);
|
|
2666
|
-
return writeSuccess(command, result.data, mode);
|
|
2684
|
+
return null;
|
|
2667
2685
|
}
|
|
2668
|
-
|
|
2669
|
-
const
|
|
2670
|
-
|
|
2671
|
-
headers: { "content-type": "application/json" },
|
|
2672
|
-
body: JSON.stringify({ client_id: DEVICE_CLIENT_ID }),
|
|
2673
|
-
...init
|
|
2674
|
-
}).catch((error) => ({ networkError: error }));
|
|
2675
|
-
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
2676
|
-
const body = await readJson(response);
|
|
2677
|
-
if (!response.ok) return { error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) }) };
|
|
2678
|
-
if (!isDeviceCodeResponse(body)) return { error: validationError("Device login response was invalid.", "Retry login. If this repeats, report the response shape.", "service_error") };
|
|
2679
|
-
return body;
|
|
2686
|
+
function authRecovery(data, nextCommand) {
|
|
2687
|
+
const loginCommand = nextCommand?.startsWith(LOGIN_COMMAND) === true ? nextCommand : data.auth.profile ? `${LOGIN_COMMAND} --profile ${data.auth.profile}` : LOGIN_COMMAND;
|
|
2688
|
+
return authRecoveryDetails(data.base_url, loginCommand);
|
|
2680
2689
|
}
|
|
2681
|
-
|
|
2682
|
-
const
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
2687
|
-
device_code: deviceCode,
|
|
2688
|
-
client_id: DEVICE_CLIENT_ID
|
|
2689
|
-
}),
|
|
2690
|
-
...init
|
|
2691
|
-
}).catch((error) => ({ networkError: error }));
|
|
2692
|
-
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
2693
|
-
const body = await readJson(response);
|
|
2694
|
-
if (response.ok && isDeviceTokenResponse(body)) return {
|
|
2695
|
-
status: "success",
|
|
2696
|
-
token: body
|
|
2690
|
+
function doctorDataWithNextCommand(data) {
|
|
2691
|
+
const nextCommand = resolveDoctorNextCommand(data);
|
|
2692
|
+
const next = {
|
|
2693
|
+
...data,
|
|
2694
|
+
next_command: nextCommand
|
|
2697
2695
|
};
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
if (authError === "access_denied") return { status: "denied" };
|
|
2702
|
-
if (authError === "expired_token") return { status: "expired" };
|
|
2703
|
-
if (response.status === 429 || response.status >= 500) return { status: "retry_later" };
|
|
2704
|
-
return { error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) }) };
|
|
2705
|
-
}
|
|
2706
|
-
function pendingDeviceAuthFromCode(profile, options, code) {
|
|
2707
|
-
return {
|
|
2708
|
-
base_url: baseUrlOf(options),
|
|
2709
|
-
profile,
|
|
2710
|
-
device_code: code.device_code,
|
|
2711
|
-
verification_uri: code.verification_uri,
|
|
2712
|
-
verification_uri_complete: code.verification_uri_complete ?? null,
|
|
2713
|
-
user_code: code.user_code,
|
|
2714
|
-
expires_at: new Date(Date.now() + code.expires_in * 1e3).toISOString(),
|
|
2715
|
-
interval_seconds: code.interval,
|
|
2716
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2696
|
+
if (next.auth.code === "auth_required") next.auth = {
|
|
2697
|
+
...next.auth,
|
|
2698
|
+
recovery: authRecovery(next, nextCommand)
|
|
2717
2699
|
};
|
|
2700
|
+
return next;
|
|
2718
2701
|
}
|
|
2719
|
-
async function
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
}
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
}
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2702
|
+
async function runDoctor(parsed, mode) {
|
|
2703
|
+
const command = "doctor";
|
|
2704
|
+
const project = await resolveProjectConfig();
|
|
2705
|
+
const credential = await resolveCredential(parsed.options, project);
|
|
2706
|
+
const destination = resolveDestination(parsed.options, project.config);
|
|
2707
|
+
const data = {
|
|
2708
|
+
next_command: null,
|
|
2709
|
+
base_url: baseUrlOf(parsed.options),
|
|
2710
|
+
config: await configDiagnostics(project),
|
|
2711
|
+
auth: {
|
|
2712
|
+
credential_source: credential.source,
|
|
2713
|
+
...credential.profile ? { profile: credential.profile } : {},
|
|
2714
|
+
token_present: credential.ok,
|
|
2715
|
+
ok: false
|
|
2716
|
+
},
|
|
2717
|
+
destination: destination.error ? {
|
|
2718
|
+
ok: false,
|
|
2719
|
+
code: destination.error.code,
|
|
2720
|
+
hint: destination.error.hint
|
|
2721
|
+
} : {
|
|
2722
|
+
ok: true,
|
|
2723
|
+
type: destination.containerId ? "project" : "home",
|
|
2724
|
+
project_id: destination.containerId ?? null
|
|
2725
|
+
},
|
|
2726
|
+
network: { ok: false },
|
|
2727
|
+
upload: {
|
|
2728
|
+
ok: false,
|
|
2729
|
+
checked: false
|
|
2747
2730
|
}
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2731
|
+
};
|
|
2732
|
+
if (!credential.ok) {
|
|
2733
|
+
if (credential.error.code !== "auth_required") return writeFailure(command, credential.error, mode, 1);
|
|
2734
|
+
data.auth.code = credential.error.code;
|
|
2735
|
+
data.auth.hint = credential.error.hint;
|
|
2736
|
+
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
2751
2737
|
}
|
|
2752
|
-
|
|
2738
|
+
const request = await requestConfig(parsed.options);
|
|
2739
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2740
|
+
const response = await fetch(apiUrl("/api/cli/doctor", baseUrlOf(parsed.options)), {
|
|
2741
|
+
headers: { Authorization: `Bearer ${credential.token}` },
|
|
2742
|
+
...request.init
|
|
2743
|
+
}).catch((error) => ({ networkError: error }));
|
|
2744
|
+
if ("networkError" in response) {
|
|
2745
|
+
data.network = {
|
|
2746
|
+
ok: false,
|
|
2747
|
+
code: "network_failed",
|
|
2748
|
+
hint: networkError(response.networkError).hint
|
|
2749
|
+
};
|
|
2750
|
+
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
2751
|
+
}
|
|
2752
|
+
data.network.ok = true;
|
|
2753
|
+
const body = await readJson(response);
|
|
2754
|
+
if (!response.ok) {
|
|
2755
|
+
const error = mapApiError(response.status, body, {
|
|
2756
|
+
authenticated: true,
|
|
2757
|
+
baseUrl: baseUrlOf(parsed.options),
|
|
2758
|
+
credentialSource: credential.source,
|
|
2759
|
+
profile: credential.profile
|
|
2760
|
+
});
|
|
2761
|
+
data.auth.code = error.code;
|
|
2762
|
+
data.auth.hint = error.hint;
|
|
2763
|
+
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
2764
|
+
}
|
|
2765
|
+
if (!body) throw new Error("Doctor response was not valid JSON.");
|
|
2766
|
+
data.auth.ok = body.auth?.ok ?? true;
|
|
2767
|
+
data.auth.email = body.user?.email ?? null;
|
|
2768
|
+
data.upload.checked = true;
|
|
2769
|
+
data.upload.ok = body.upload?.ok ?? false;
|
|
2770
|
+
if (!data.upload.ok) {
|
|
2771
|
+
data.upload.code = normalizeApiCode(body.upload?.code);
|
|
2772
|
+
data.upload.hint = uploadBlockedHint(data.upload.code);
|
|
2773
|
+
}
|
|
2774
|
+
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
2753
2775
|
}
|
|
2754
|
-
async function
|
|
2755
|
-
const
|
|
2756
|
-
const
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
};
|
|
2761
|
-
const whoami = whoamiProfile(whoamiResult.body);
|
|
2762
|
-
const profiles = config.profiles ?? {};
|
|
2763
|
-
const expectedEmail = nonEmpty((Object.hasOwn(profiles, profile) ? profiles[profile] : void 0)?.email);
|
|
2764
|
-
if (expectedEmail && whoami.email !== expectedEmail) return {
|
|
2765
|
-
ok: false,
|
|
2766
|
-
error: authAccountMismatchError(profile, expectedEmail, whoami.email)
|
|
2767
|
-
};
|
|
2768
|
-
const saved = await saveProfileToken(profile, token, options);
|
|
2769
|
-
if (!saved.ok) return {
|
|
2770
|
-
ok: false,
|
|
2771
|
-
error: tokenStoreUnavailableError(profile)
|
|
2772
|
-
};
|
|
2773
|
-
await writeProfileConfig(profile, options, saved.store, whoami);
|
|
2776
|
+
async function configDiagnostics(project) {
|
|
2777
|
+
const globalConfig = await readGlobalConfig();
|
|
2778
|
+
const cwd = process.cwd();
|
|
2779
|
+
const directory = project.directory;
|
|
2780
|
+
const localRaw = directory ? await readProjectConfigAtDirectory(directory, "local") : null;
|
|
2781
|
+
const sharedRaw = directory ? await readProjectConfigAtDirectory(directory, "shared") : null;
|
|
2774
2782
|
return {
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2783
|
+
local: fileDiagnostics(localRaw, directory ? relativeProjectConfigPath(cwd, directory, PROJECT_CONFIG_LOCAL_PATH) : null),
|
|
2784
|
+
project: fileDiagnostics(sharedRaw, directory ? relativeProjectConfigPath(cwd, directory, PROJECT_CONFIG_PATH) : null),
|
|
2785
|
+
global: {
|
|
2786
|
+
present: globalConfig !== null,
|
|
2787
|
+
default_profile: configString(globalConfig?.default_profile),
|
|
2788
|
+
profile_count: Object.keys(globalConfig?.profiles ?? {}).length
|
|
2789
|
+
},
|
|
2790
|
+
effective: effectiveDiagnostics(project, globalConfig)
|
|
2785
2791
|
};
|
|
2786
2792
|
}
|
|
2787
|
-
|
|
2788
|
-
const
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
email: whoami.email ?? currentProfile?.email ?? null,
|
|
2800
|
-
workspace_id: whoami.workspace_id,
|
|
2801
|
-
token_store: tokenStore,
|
|
2802
|
-
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
});
|
|
2806
|
-
}
|
|
2807
|
-
function isDeviceCodeResponse(body) {
|
|
2808
|
-
if (!isRecord(body)) return false;
|
|
2809
|
-
return typeof body.device_code === "string" && typeof body.user_code === "string" && typeof body.verification_uri === "string" && (typeof body.verification_uri_complete === "string" || body.verification_uri_complete === void 0) && typeof body.expires_in === "number" && typeof body.interval === "number";
|
|
2810
|
-
}
|
|
2811
|
-
function isDeviceTokenResponse(body) {
|
|
2812
|
-
if (!isRecord(body)) return false;
|
|
2813
|
-
return typeof body.access_token === "string" && typeof body.token_type === "string" && body.token_type.toLowerCase() === "bearer" && (typeof body.expires_in === "number" || body.expires_in === void 0);
|
|
2814
|
-
}
|
|
2815
|
-
function deviceTokenError(body) {
|
|
2816
|
-
if (!isRecord(body)) return null;
|
|
2817
|
-
return typeof body.error === "string" ? body.error : null;
|
|
2793
|
+
function fileDiagnostics(raw, path) {
|
|
2794
|
+
const unsafeKey = Object.keys(raw ?? {}).find((key) => key.toLowerCase().includes("token"));
|
|
2795
|
+
return {
|
|
2796
|
+
present: raw !== null,
|
|
2797
|
+
path,
|
|
2798
|
+
default_profile: configString(raw?.default_profile),
|
|
2799
|
+
default_project_id: configString(raw?.default_project_id),
|
|
2800
|
+
...unsafeKey ? {
|
|
2801
|
+
code: "token_store_unsafe",
|
|
2802
|
+
hint: `Remove "${unsafeKey}" from ${path ?? "the working-directory config"} and run ${CLI_INVOCATION} login instead; the working-directory config must never hold secrets.`
|
|
2803
|
+
} : {}
|
|
2804
|
+
};
|
|
2818
2805
|
}
|
|
2819
|
-
function
|
|
2820
|
-
const
|
|
2821
|
-
const
|
|
2822
|
-
const
|
|
2806
|
+
function effectiveDiagnostics(project, globalConfig) {
|
|
2807
|
+
const projectProfile = configString(project.config?.default_profile);
|
|
2808
|
+
const projectProjectId = configString(project.config?.default_project_id);
|
|
2809
|
+
const globalProfile = configString(globalConfig?.default_profile);
|
|
2810
|
+
const defaultProfile = projectProfile ?? globalProfile;
|
|
2811
|
+
const defaultProfileSource = projectProfile ? project.kind === "local" ? "local" : "project" : globalProfile ? "global" : "none";
|
|
2812
|
+
const defaultProfilePath = defaultProfileSource === "local" || defaultProfileSource === "project" ? project.path : null;
|
|
2813
|
+
const defaultProjectId = projectProjectId;
|
|
2814
|
+
const defaultProjectIdSource = projectProjectId ? project.kind === "local" ? "local" : "project" : "none";
|
|
2823
2815
|
return {
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2816
|
+
default_profile: defaultProfile,
|
|
2817
|
+
default_profile_source: defaultProfileSource,
|
|
2818
|
+
default_profile_path: defaultProfilePath,
|
|
2819
|
+
default_project_id: defaultProjectId,
|
|
2820
|
+
default_project_id_source: defaultProjectIdSource,
|
|
2821
|
+
default_project_id_path: defaultProjectIdSource === "local" || defaultProjectIdSource === "project" ? project.path : null
|
|
2827
2822
|
};
|
|
2828
2823
|
}
|
|
2829
2824
|
//#endregion
|
|
2830
|
-
//#region src/
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2825
|
+
//#region src/files.ts
|
|
2826
|
+
async function prepareUploadPayload(targetPath, fileStat, initialForm = new FormData()) {
|
|
2827
|
+
if (fileStat.isDirectory()) {
|
|
2828
|
+
let files;
|
|
2829
|
+
try {
|
|
2830
|
+
files = await collectDirectoryFiles(resolve(targetPath));
|
|
2831
|
+
} catch (error) {
|
|
2832
|
+
if (error instanceof CollectDirectoryFilesError) return { error: validationError(error.message, error.hint) };
|
|
2833
|
+
throw error;
|
|
2834
|
+
}
|
|
2835
|
+
if (files.length === 0) return { error: validationError("Directory has no shareable files.", "Add index.html or index.md and retry.") };
|
|
2836
|
+
for (const file of files) initialForm.append("file", await blobFor(file.path), file.relativePath);
|
|
2837
|
+
return { payload: {
|
|
2838
|
+
form: initialForm,
|
|
2839
|
+
kind: "static_site"
|
|
2840
|
+
} };
|
|
2841
|
+
}
|
|
2842
|
+
if (fileStat.isFile()) {
|
|
2843
|
+
initialForm.append("file", await blobFor(targetPath), basename(targetPath));
|
|
2844
|
+
return { payload: {
|
|
2845
|
+
form: initialForm,
|
|
2846
|
+
kind: artifactKindForFile(targetPath)
|
|
2847
|
+
} };
|
|
2848
|
+
}
|
|
2849
|
+
return { error: validationError("Path must be a file or directory.", "Pass a regular file or directory.") };
|
|
2834
2850
|
}
|
|
2835
|
-
function
|
|
2836
|
-
|
|
2851
|
+
async function prepareDownloadPlan(manifest, outputPath, force) {
|
|
2852
|
+
if (manifest.files.length === 0) return { error: validationError("Download manifest contains no files.", "Check the artifact and retry.") };
|
|
2853
|
+
if (outputPath === "") return { error: validationError("--output requires a non-empty directory.", "Pass --output <path> or omit --output to use the artifact ID.") };
|
|
2854
|
+
const root = resolve(outputPath);
|
|
2855
|
+
const existing = await lstat(root).catch(() => null);
|
|
2856
|
+
if (existing?.isSymbolicLink()) return { error: validationError("Output path must not be a symbolic link.", "Choose a regular directory path and retry.") };
|
|
2857
|
+
if (existing && !force) return { error: cliError({
|
|
2858
|
+
code: "output_exists",
|
|
2859
|
+
message: "Output path already exists.",
|
|
2860
|
+
why: "Download will not write into an existing path unless --force is set.",
|
|
2861
|
+
hint: "Choose a different --output path or retry with --force.",
|
|
2862
|
+
agentRecoverable: true,
|
|
2863
|
+
requiresHuman: false,
|
|
2864
|
+
recovery: { kind: "change_input" }
|
|
2865
|
+
}) };
|
|
2866
|
+
if (existing && !existing.isDirectory()) return { error: validationError("Output path is not a directory.", "Choose a directory path or remove the existing file.") };
|
|
2867
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2868
|
+
const relativeFiles = [];
|
|
2869
|
+
for (const file of manifest.files) {
|
|
2870
|
+
const relativePath = downloadRelativePath(file.path);
|
|
2871
|
+
if (relativePath.error) return { error: relativePath.error };
|
|
2872
|
+
if (seen.has(relativePath.value)) return { error: validationError("Download manifest contains duplicate file paths.", "Retry later. If this repeats, report the artifact ID.") };
|
|
2873
|
+
seen.add(relativePath.value);
|
|
2874
|
+
relativeFiles.push({
|
|
2875
|
+
...file,
|
|
2876
|
+
relativePath: relativePath.value
|
|
2877
|
+
});
|
|
2878
|
+
}
|
|
2879
|
+
const parent = dirname(root);
|
|
2880
|
+
await mkdir(parent, { recursive: true });
|
|
2881
|
+
const tempRoot = await mkdtemp(join(parent, `.${basename(root)}.tmp-`));
|
|
2882
|
+
const files = [];
|
|
2883
|
+
for (const file of relativeFiles) {
|
|
2884
|
+
const targetPath = resolve(tempRoot, file.relativePath);
|
|
2885
|
+
files.push({
|
|
2886
|
+
...file,
|
|
2887
|
+
targetPath
|
|
2888
|
+
});
|
|
2889
|
+
}
|
|
2890
|
+
return { value: {
|
|
2891
|
+
root,
|
|
2892
|
+
tempRoot,
|
|
2893
|
+
replaceExisting: Boolean(existing),
|
|
2894
|
+
files
|
|
2895
|
+
} };
|
|
2837
2896
|
}
|
|
2838
|
-
function
|
|
2839
|
-
|
|
2840
|
-
|
|
2897
|
+
function downloadRelativePath(path) {
|
|
2898
|
+
if (!path.startsWith("/") || path.includes("\0") || path.includes("\\")) return { error: validationError("Download manifest contains an invalid file path.", "Retry later. If this repeats, report the artifact ID.") };
|
|
2899
|
+
const segments = path.split("/").slice(1);
|
|
2900
|
+
if (segments.length === 0 || segments.some((segment) => segment === "" || segment === "." || segment === "..")) return { error: validationError("Download manifest contains an unsafe file path.", "Retry later. If this repeats, report the artifact ID.") };
|
|
2901
|
+
return { value: segments.join("/") };
|
|
2841
2902
|
}
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2903
|
+
function verifyDownloadedBytes(file, bytes) {
|
|
2904
|
+
if (bytes.byteLength !== file.size_bytes) return { error: downloadIntegrityError(file.path, "size mismatch") };
|
|
2905
|
+
if (file.sha256) {
|
|
2906
|
+
if (createHash("sha256").update(bytes).digest("base64url") !== file.sha256) return { error: downloadIntegrityError(file.path, "sha256 mismatch") };
|
|
2907
|
+
}
|
|
2908
|
+
return { ok: true };
|
|
2845
2909
|
}
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2910
|
+
function downloadIntegrityError(path, reason) {
|
|
2911
|
+
return cliError({
|
|
2912
|
+
code: "download_integrity_failed",
|
|
2913
|
+
message: "Downloaded file did not match the manifest.",
|
|
2914
|
+
why: `The downloaded file ${path} failed integrity verification: ${reason}.`,
|
|
2915
|
+
hint: "Retry the download. If this repeats, report the artifact ID.",
|
|
2916
|
+
agentRecoverable: true,
|
|
2917
|
+
requiresHuman: false,
|
|
2918
|
+
recovery: { kind: "retry_later" }
|
|
2919
|
+
});
|
|
2856
2920
|
}
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2921
|
+
function backupPathFor(root) {
|
|
2922
|
+
return join(dirname(root), `.${basename(root)}.old-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`);
|
|
2923
|
+
}
|
|
2924
|
+
async function pathExists(path) {
|
|
2925
|
+
return Boolean(await lstat(path).catch(() => null));
|
|
2926
|
+
}
|
|
2927
|
+
function downloadFileSystemError(error) {
|
|
2928
|
+
return cliError({
|
|
2929
|
+
code: "download_failed",
|
|
2930
|
+
message: "Could not write downloaded files.",
|
|
2931
|
+
why: error instanceof Error ? error.message : "The local filesystem rejected a download operation.",
|
|
2932
|
+
hint: "Check --output permissions and available disk space, then retry.",
|
|
2933
|
+
agentRecoverable: true,
|
|
2934
|
+
requiresHuman: false,
|
|
2935
|
+
recovery: { kind: "change_input" }
|
|
2936
|
+
});
|
|
2937
|
+
}
|
|
2938
|
+
async function collectDirectoryFiles(root) {
|
|
2939
|
+
const results = [];
|
|
2940
|
+
async function visit(dir) {
|
|
2941
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
2942
|
+
if (entry.name === "__MACOSX") continue;
|
|
2943
|
+
const fullPath = join(dir, entry.name);
|
|
2944
|
+
if (entry.isSymbolicLink()) throw new CollectDirectoryFilesError("Directory contains a symbolic link.", "Remove or replace symlinked files and directories before sharing.");
|
|
2945
|
+
if (entry.isDirectory()) {
|
|
2946
|
+
if (EXCLUDED_DIR_NAMES.has(entry.name) || entry.name.startsWith(".")) continue;
|
|
2947
|
+
await visit(fullPath);
|
|
2948
|
+
continue;
|
|
2949
|
+
}
|
|
2950
|
+
if (!entry.isFile() || IGNORED_FILENAMES.has(entry.name) || entry.name.startsWith(".")) continue;
|
|
2951
|
+
const relativePath = relative(root, fullPath).split(sep).join("/");
|
|
2952
|
+
results.push({
|
|
2953
|
+
path: fullPath,
|
|
2954
|
+
relativePath
|
|
2955
|
+
});
|
|
2879
2956
|
}
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2957
|
+
}
|
|
2958
|
+
await visit(root);
|
|
2959
|
+
results.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
2960
|
+
return results;
|
|
2961
|
+
}
|
|
2962
|
+
var CollectDirectoryFilesError = class extends Error {
|
|
2963
|
+
hint;
|
|
2964
|
+
constructor(message, hint) {
|
|
2965
|
+
super(message);
|
|
2966
|
+
this.name = "CollectDirectoryFilesError";
|
|
2967
|
+
this.hint = hint;
|
|
2968
|
+
}
|
|
2969
|
+
};
|
|
2970
|
+
async function blobFor(path) {
|
|
2971
|
+
const chunks = [];
|
|
2972
|
+
for await (const chunk of createReadStream(path)) chunks.push(chunk);
|
|
2973
|
+
return new Blob(chunks, { type: contentTypeFor(path) });
|
|
2974
|
+
}
|
|
2975
|
+
function contentTypeFor(path) {
|
|
2976
|
+
if (path.endsWith(".html")) return "text/html";
|
|
2977
|
+
if (path.endsWith(".md")) return "text/markdown";
|
|
2978
|
+
if (path.endsWith(".css")) return "text/css";
|
|
2979
|
+
if (path.endsWith(".js")) return "text/javascript";
|
|
2980
|
+
if (path.endsWith(".json")) return "application/json";
|
|
2981
|
+
if (path.endsWith(".svg")) return "image/svg+xml";
|
|
2982
|
+
if (path.endsWith(".png")) return "image/png";
|
|
2983
|
+
if (path.endsWith(".jpg") || path.endsWith(".jpeg")) return "image/jpeg";
|
|
2984
|
+
return "application/octet-stream";
|
|
2985
|
+
}
|
|
2986
|
+
function artifactKindForFile(path) {
|
|
2987
|
+
return path.endsWith(".md") ? "markdown_page" : "html_page";
|
|
2889
2988
|
}
|
|
2890
2989
|
//#endregion
|
|
2891
2990
|
//#region src/command-runners/download.ts
|
|
@@ -2906,10 +3005,13 @@ async function runDownload(parsed, mode, isRetry = false) {
|
|
|
2906
3005
|
}).catch((error) => ({ networkError: error }));
|
|
2907
3006
|
if ("networkError" in manifestResponse) return writeFailure(command, networkError(manifestResponse.networkError), mode, 1);
|
|
2908
3007
|
const body = await readJson(manifestResponse);
|
|
2909
|
-
if (!manifestResponse.ok) return
|
|
3008
|
+
if (!manifestResponse.ok) return handleAuthenticatedCredentialFailure(command, mapApiError(manifestResponse.status, body, {
|
|
2910
3009
|
authenticated: true,
|
|
2911
|
-
artifactTarget: true
|
|
2912
|
-
|
|
3010
|
+
artifactTarget: true,
|
|
3011
|
+
baseUrl,
|
|
3012
|
+
credentialSource: credential.source,
|
|
3013
|
+
profile: credential.profile
|
|
3014
|
+
}), credential, parsed.options, mode, () => runDownload(parsed, mode, true), isRetry);
|
|
2913
3015
|
if (!downloadManifestFields(body)) return writeFailure(command, serviceError("Download manifest succeeded but the response did not include file metadata."), mode, 1);
|
|
2914
3016
|
const plan = await prepareDownloadPlan(body, parsed.options.output ?? artifactId, Boolean(parsed.options.force));
|
|
2915
3017
|
if (plan.error) return writeFailure(command, plan.error, mode, 1);
|
|
@@ -2923,10 +3025,13 @@ async function runDownload(parsed, mode, isRetry = false) {
|
|
|
2923
3025
|
...request.init
|
|
2924
3026
|
}).catch((error) => ({ networkError: error }));
|
|
2925
3027
|
if ("networkError" in fileResponse) return writeFailure(command, networkError(fileResponse.networkError), mode, 1);
|
|
2926
|
-
if (!fileResponse.ok) return
|
|
3028
|
+
if (!fileResponse.ok) return handleAuthenticatedCredentialFailure(command, mapApiError(fileResponse.status, await readJson(fileResponse), {
|
|
2927
3029
|
authenticated: true,
|
|
2928
|
-
artifactTarget: true
|
|
2929
|
-
|
|
3030
|
+
artifactTarget: true,
|
|
3031
|
+
baseUrl,
|
|
3032
|
+
credentialSource: credential.source,
|
|
3033
|
+
profile: credential.profile
|
|
3034
|
+
}), credential, parsed.options, mode, () => runDownload(parsed, mode, true), isRetry);
|
|
2930
3035
|
const bytes = Buffer.from(await fileResponse.arrayBuffer());
|
|
2931
3036
|
const verified = verifyDownloadedBytes(file, bytes);
|
|
2932
3037
|
if (verified.error) return writeFailure(command, verified.error, mode, 1);
|
|
@@ -2980,7 +3085,9 @@ async function runEdit(parsed, mode) {
|
|
|
2980
3085
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2981
3086
|
const result = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/edit`, credential.token, payload.body, parsed.options, request.init, {
|
|
2982
3087
|
artifactTarget: true,
|
|
2983
|
-
editSettings: true
|
|
3088
|
+
editSettings: true,
|
|
3089
|
+
credentialSource: credential.source,
|
|
3090
|
+
profile: credential.profile
|
|
2984
3091
|
});
|
|
2985
3092
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2986
3093
|
const data = parseEditData(result.body);
|
|
@@ -3179,7 +3286,11 @@ async function runMove(parsed, mode) {
|
|
|
3179
3286
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3180
3287
|
const request = await requestConfig(parsed.options);
|
|
3181
3288
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3182
|
-
const result = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/move`, credential.token, { destination: home ? "home" : { project_id: projectId } }, parsed.options, request.init, {
|
|
3289
|
+
const result = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/move`, credential.token, { destination: home ? "home" : { project_id: projectId } }, parsed.options, request.init, {
|
|
3290
|
+
artifactTarget: true,
|
|
3291
|
+
credentialSource: credential.source,
|
|
3292
|
+
profile: credential.profile
|
|
3293
|
+
});
|
|
3183
3294
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3184
3295
|
const data = parseMoveData(result.body);
|
|
3185
3296
|
if (!data) return writeFailure(command, serviceError("Move succeeded but the response did not include move data."), mode, 1);
|
|
@@ -3306,8 +3417,8 @@ async function runProfilesImportToken(parsed, mode) {
|
|
|
3306
3417
|
}
|
|
3307
3418
|
//#endregion
|
|
3308
3419
|
//#region src/command-runners/projects.ts
|
|
3309
|
-
async function fetchProjects(token, options, init) {
|
|
3310
|
-
const result = await apiGet("/api/cli/projects", token, options, init);
|
|
3420
|
+
async function fetchProjects(token, options, init, errorOptions = {}) {
|
|
3421
|
+
const result = await apiGet("/api/cli/projects", token, options, init, errorOptions);
|
|
3311
3422
|
if (result.error) return { error: result.error };
|
|
3312
3423
|
return { projects: (Array.isArray(result.body?.projects) ? result.body.projects : []).filter(isRecord).flatMap((project) => {
|
|
3313
3424
|
const id = configString(project.id);
|
|
@@ -3329,7 +3440,10 @@ async function runProjectsList(parsed, mode) {
|
|
|
3329
3440
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3330
3441
|
const request = await requestConfig(parsed.options);
|
|
3331
3442
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3332
|
-
const result = await fetchProjects(credential.token, parsed.options, request.init
|
|
3443
|
+
const result = await fetchProjects(credential.token, parsed.options, request.init, {
|
|
3444
|
+
credentialSource: credential.source,
|
|
3445
|
+
profile: credential.profile
|
|
3446
|
+
});
|
|
3333
3447
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3334
3448
|
const defaultProjectId = configString(projectConfig.config?.default_project_id);
|
|
3335
3449
|
const projects = result.projects.map((project) => ({
|
|
@@ -3340,7 +3454,7 @@ async function runProjectsList(parsed, mode) {
|
|
|
3340
3454
|
default_project_id: defaultProjectId,
|
|
3341
3455
|
projects
|
|
3342
3456
|
}, mode);
|
|
3343
|
-
if (!mode.json && projects.length === 0) writeText("No projects yet. Create one on the web, then
|
|
3457
|
+
if (!mode.json && projects.length === 0) writeText("No projects yet. Create one on the web, then share with --project-id.\n");
|
|
3344
3458
|
}
|
|
3345
3459
|
async function runProjectsCreate(parsed, mode) {
|
|
3346
3460
|
const command = "projects create";
|
|
@@ -3357,7 +3471,10 @@ async function runProjectsCreate(parsed, mode) {
|
|
|
3357
3471
|
name,
|
|
3358
3472
|
description: parsed.options.description ?? null,
|
|
3359
3473
|
base_visibility: visibility ?? null
|
|
3360
|
-
}, parsed.options, request.init
|
|
3474
|
+
}, parsed.options, request.init, {
|
|
3475
|
+
credentialSource: credential.source,
|
|
3476
|
+
profile: credential.profile
|
|
3477
|
+
});
|
|
3361
3478
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3362
3479
|
const project = isRecord(result.body?.project) ? result.body.project : null;
|
|
3363
3480
|
const id = configString(project?.id);
|
|
@@ -3369,7 +3486,7 @@ async function runProjectsCreate(parsed, mode) {
|
|
|
3369
3486
|
description: configString(project?.description),
|
|
3370
3487
|
base_visibility: configString(project?.base_visibility)
|
|
3371
3488
|
},
|
|
3372
|
-
next_command: `npx --yes @artifactshare/cli
|
|
3489
|
+
next_command: `npx --yes @artifactshare/cli share <path> --project-id ${id} --json`
|
|
3373
3490
|
}, mode);
|
|
3374
3491
|
}
|
|
3375
3492
|
async function runProjectsEdit(parsed, mode) {
|
|
@@ -3383,7 +3500,11 @@ async function runProjectsEdit(parsed, mode) {
|
|
|
3383
3500
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3384
3501
|
const request = await requestConfig(parsed.options);
|
|
3385
3502
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3386
|
-
const result = await apiPost(`/api/cli/projects/${encodeURIComponent(projectId)}`, credential.token, payload.body, parsed.options, request.init, {
|
|
3503
|
+
const result = await apiPost(`/api/cli/projects/${encodeURIComponent(projectId)}`, credential.token, payload.body, parsed.options, request.init, {
|
|
3504
|
+
projectTarget: true,
|
|
3505
|
+
credentialSource: credential.source,
|
|
3506
|
+
profile: credential.profile
|
|
3507
|
+
});
|
|
3387
3508
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3388
3509
|
const data = parseProjectsEditData(result.body);
|
|
3389
3510
|
if (!data) return writeFailure(command, serviceError("Project edit succeeded but the response did not include project data."), mode, 1);
|
|
@@ -3454,20 +3575,20 @@ function parseProjectsEditData(body) {
|
|
|
3454
3575
|
};
|
|
3455
3576
|
}
|
|
3456
3577
|
//#endregion
|
|
3457
|
-
//#region src/command-runners/
|
|
3458
|
-
const
|
|
3459
|
-
async function
|
|
3460
|
-
const command = "
|
|
3578
|
+
//#region src/command-runners/share.ts
|
|
3579
|
+
const MAX_SHARE_KEY_LENGTH = 128;
|
|
3580
|
+
async function runShare(parsed, mode, isRetry = false) {
|
|
3581
|
+
const command = "share";
|
|
3461
3582
|
const targetPath = parsed.positionals[0];
|
|
3462
|
-
if (!targetPath) return writeFailure(command, validationError("Path is required.", "Pass a file or directory to
|
|
3463
|
-
let
|
|
3583
|
+
if (!targetPath) return writeFailure(command, validationError("Path is required.", "Pass a file or directory to share."), mode, 1);
|
|
3584
|
+
let shareKey = null;
|
|
3464
3585
|
if ("key" in parsed.options) {
|
|
3465
|
-
|
|
3466
|
-
if (
|
|
3586
|
+
shareKey = (typeof parsed.options.key === "string" ? parsed.options.key : "").trim();
|
|
3587
|
+
if (shareKey.length === 0 || shareKey.length > MAX_SHARE_KEY_LENGTH) return writeFailure(command, validationError(`--key must be 1-${MAX_SHARE_KEY_LENGTH} characters after trimming.`, "Pass a short stable identifier, like a job name or PR number."), mode, 1);
|
|
3467
3588
|
}
|
|
3468
3589
|
const project = await resolveProjectConfig();
|
|
3469
3590
|
const credential = await resolveCredential(parsed.options, project);
|
|
3470
|
-
if (!credential.ok) return handleCredentialFailure(command, credential, parsed.options, mode, () =>
|
|
3591
|
+
if (!credential.ok) return handleCredentialFailure(command, credential, parsed.options, mode, () => runShare(parsed, mode, true), isRetry);
|
|
3471
3592
|
const baseUrl = baseUrlOf(parsed.options);
|
|
3472
3593
|
const hasProjectFlag = "project" in parsed.options;
|
|
3473
3594
|
let destinationOptions = parsed.options;
|
|
@@ -3486,8 +3607,13 @@ async function runPublish(parsed, mode, isRetry = false) {
|
|
|
3486
3607
|
const request = await requestConfig(parsed.options);
|
|
3487
3608
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3488
3609
|
if (hasProjectFlag && projectName) {
|
|
3489
|
-
const resolved = await resolveProjectIdByName(projectName, credential.token, parsed.options, request.init
|
|
3490
|
-
|
|
3610
|
+
const resolved = await resolveProjectIdByName(projectName, credential.token, parsed.options, request.init, {
|
|
3611
|
+
authenticated: true,
|
|
3612
|
+
baseUrl,
|
|
3613
|
+
credentialSource: credential.source,
|
|
3614
|
+
profile: credential.profile
|
|
3615
|
+
});
|
|
3616
|
+
if (resolved.error) return handleAuthenticatedCredentialFailure(command, resolved.error, credential, parsed.options, mode, () => runShare(parsed, mode, true), isRetry);
|
|
3491
3617
|
const { project: _project, ...rest } = parsed.options;
|
|
3492
3618
|
destinationOptions = {
|
|
3493
3619
|
...rest,
|
|
@@ -3503,7 +3629,7 @@ async function runPublish(parsed, mode, isRetry = false) {
|
|
|
3503
3629
|
for (const email of grantEmails) initialForm.append("grant_email", email);
|
|
3504
3630
|
if (destination.containerId) initialForm.set("container_id", destination.containerId);
|
|
3505
3631
|
const uploadUrl = apiUrl("/api/shareables/uploads", baseUrl);
|
|
3506
|
-
if (
|
|
3632
|
+
if (shareKey !== null) uploadUrl.searchParams.set("publish_key", shareKey);
|
|
3507
3633
|
const upload = await prepareUploadPayload(targetPath, fileStat, initialForm);
|
|
3508
3634
|
if (upload.error) return writeFailure(command, upload.error, mode, 1);
|
|
3509
3635
|
if (upload.payload.kind === "static_site") {
|
|
@@ -3518,7 +3644,12 @@ async function runPublish(parsed, mode, isRetry = false) {
|
|
|
3518
3644
|
}).catch((error) => ({ networkError: error }));
|
|
3519
3645
|
if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
|
|
3520
3646
|
const body = await readJson(response);
|
|
3521
|
-
if (!response.ok) return
|
|
3647
|
+
if (!response.ok) return handleAuthenticatedCredentialFailure(command, mapApiError(response.status, body, {
|
|
3648
|
+
authenticated: true,
|
|
3649
|
+
baseUrl,
|
|
3650
|
+
credentialSource: credential.source,
|
|
3651
|
+
profile: credential.profile
|
|
3652
|
+
}), credential, parsed.options, mode, () => runShare(parsed, mode, true), isRetry);
|
|
3522
3653
|
const id = body?.id ?? null;
|
|
3523
3654
|
return writeSuccess(command, {
|
|
3524
3655
|
artifact: {
|
|
@@ -3528,7 +3659,7 @@ async function runPublish(parsed, mode, isRetry = false) {
|
|
|
3528
3659
|
},
|
|
3529
3660
|
version: { id: body?.versionId ?? null },
|
|
3530
3661
|
result: { created: body?.created ?? true },
|
|
3531
|
-
...
|
|
3662
|
+
...shareKey !== null ? { key: shareKey } : {},
|
|
3532
3663
|
destination: destination.containerId ? {
|
|
3533
3664
|
type: "project",
|
|
3534
3665
|
project_id: destination.containerId
|
|
@@ -3539,8 +3670,8 @@ async function runPublish(parsed, mode, isRetry = false) {
|
|
|
3539
3670
|
}
|
|
3540
3671
|
}, mode);
|
|
3541
3672
|
}
|
|
3542
|
-
async function resolveProjectIdByName(projectName, token, options, init) {
|
|
3543
|
-
const result = await fetchProjects(token, options, init);
|
|
3673
|
+
async function resolveProjectIdByName(projectName, token, options, init, errorOptions) {
|
|
3674
|
+
const result = await fetchProjects(token, options, init, errorOptions);
|
|
3544
3675
|
if (result.error) return { error: result.error };
|
|
3545
3676
|
const candidates = result.projects.flatMap((project) => {
|
|
3546
3677
|
if (project.name !== projectName) return [];
|
|
@@ -3565,7 +3696,10 @@ async function runRequestAccess(parsed, mode) {
|
|
|
3565
3696
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3566
3697
|
const request = await requestConfig(parsed.options);
|
|
3567
3698
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3568
|
-
const result = await apiPost("/api/cli/request-access", credential.token, { note }, parsed.options, request.init
|
|
3699
|
+
const result = await apiPost("/api/cli/request-access", credential.token, { note }, parsed.options, request.init, {
|
|
3700
|
+
credentialSource: credential.source,
|
|
3701
|
+
profile: credential.profile
|
|
3702
|
+
});
|
|
3569
3703
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3570
3704
|
const body = result.body;
|
|
3571
3705
|
const data = {
|
|
@@ -3597,7 +3731,12 @@ async function runResolve(parsed, mode) {
|
|
|
3597
3731
|
}).catch((error) => ({ networkError: error }));
|
|
3598
3732
|
if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
|
|
3599
3733
|
const body = await readJson(response);
|
|
3600
|
-
if (!response.ok) return writeFailure(command, mapApiError(response.status, body, {
|
|
3734
|
+
if (!response.ok) return writeFailure(command, mapApiError(response.status, body, {
|
|
3735
|
+
authenticated: true,
|
|
3736
|
+
baseUrl: baseUrlOf(parsed.options),
|
|
3737
|
+
credentialSource: credential.source,
|
|
3738
|
+
profile: credential.profile
|
|
3739
|
+
}), mode, 1);
|
|
3601
3740
|
if (!resolveSuccessFields(body)) return writeFailure(command, serviceError("Resolve succeeded but the response did not include query, candidates, and has_more."), mode, 1);
|
|
3602
3741
|
return writeSuccess(command, body, mode);
|
|
3603
3742
|
}
|
|
@@ -3632,10 +3771,13 @@ async function runUpdate(parsed, mode, isRetry = false) {
|
|
|
3632
3771
|
}).catch((error) => ({ networkError: error }));
|
|
3633
3772
|
if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
|
|
3634
3773
|
const body = await readJson(response);
|
|
3635
|
-
if (!response.ok) return
|
|
3774
|
+
if (!response.ok) return handleAuthenticatedCredentialFailure(command, mapApiError(response.status, body, {
|
|
3636
3775
|
authenticated: true,
|
|
3637
|
-
artifactTarget: true
|
|
3638
|
-
|
|
3776
|
+
artifactTarget: true,
|
|
3777
|
+
baseUrl,
|
|
3778
|
+
credentialSource: credential.source,
|
|
3779
|
+
profile: credential.profile
|
|
3780
|
+
}), credential, parsed.options, mode, () => runUpdate(parsed, mode, true), isRetry);
|
|
3639
3781
|
const id = body?.id ?? artifactId;
|
|
3640
3782
|
const result = {
|
|
3641
3783
|
artifact: {
|
|
@@ -3657,7 +3799,10 @@ async function runWhoami(parsed, mode) {
|
|
|
3657
3799
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3658
3800
|
const request = await requestConfig(parsed.options);
|
|
3659
3801
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3660
|
-
const whoami = await apiGet("/api/cli/whoami", credential.token, parsed.options, request.init
|
|
3802
|
+
const whoami = await apiGet("/api/cli/whoami", credential.token, parsed.options, request.init, {
|
|
3803
|
+
credentialSource: credential.source,
|
|
3804
|
+
profile: credential.profile
|
|
3805
|
+
});
|
|
3661
3806
|
if (whoami.error) return writeFailure(command, whoami.error, mode, 1);
|
|
3662
3807
|
return writeSuccess(command, isRecord(whoami.body) ? {
|
|
3663
3808
|
...whoami.body,
|
|
@@ -3666,9 +3811,9 @@ async function runWhoami(parsed, mode) {
|
|
|
3666
3811
|
}
|
|
3667
3812
|
//#endregion
|
|
3668
3813
|
//#region src/commands.ts
|
|
3669
|
-
async function
|
|
3670
|
-
const parsed = parsedArgsFromContext("
|
|
3671
|
-
return await
|
|
3814
|
+
async function shareRunner(ctx) {
|
|
3815
|
+
const parsed = parsedArgsFromContext("share", ctx);
|
|
3816
|
+
return await runShare(parsed, outputMode(parsed.options));
|
|
3672
3817
|
}
|
|
3673
3818
|
async function loginRunner(ctx) {
|
|
3674
3819
|
const parsed = parsedArgsFromContext("login", ctx);
|
|
@@ -3694,9 +3839,9 @@ async function downloadRunner(ctx) {
|
|
|
3694
3839
|
const parsed = parsedArgsFromContext("download", ctx);
|
|
3695
3840
|
return await runDownload(parsed, outputMode(parsed.options));
|
|
3696
3841
|
}
|
|
3697
|
-
async function
|
|
3698
|
-
const parsed = parsedArgsFromContext("
|
|
3699
|
-
return await
|
|
3842
|
+
async function openRunner(ctx) {
|
|
3843
|
+
const parsed = parsedArgsFromContext("open", ctx);
|
|
3844
|
+
return await runOpen(parsed, outputMode(parsed.options));
|
|
3700
3845
|
}
|
|
3701
3846
|
async function moveRunner(ctx) {
|
|
3702
3847
|
const parsed = parsedArgsFromContext("move", ctx);
|
|
@@ -3842,13 +3987,13 @@ async function runGunshi(argv) {
|
|
|
3842
3987
|
version: await loadCliVersion(),
|
|
3843
3988
|
subCommands: {
|
|
3844
3989
|
login: lazyCommand(loginDefinition, loginRunner),
|
|
3845
|
-
|
|
3990
|
+
share: lazyCommand(shareDefinition, shareRunner),
|
|
3991
|
+
open: lazyCommand(openDefinition, openRunner),
|
|
3846
3992
|
update: lazyCommand(updateDefinition, updateRunner),
|
|
3847
3993
|
edit: lazyCommand(editDefinition, editRunner),
|
|
3848
3994
|
delete: lazyCommand(deleteDefinition, deleteRunner),
|
|
3849
3995
|
resolve: lazyCommand(resolveDefinition, resolveRunner),
|
|
3850
3996
|
download: lazyCommand(downloadDefinition, downloadRunner),
|
|
3851
|
-
agent: agentDefinition,
|
|
3852
3997
|
move: lazyCommand(moveDefinition, moveRunner),
|
|
3853
3998
|
artifacts: artifactsDefinition,
|
|
3854
3999
|
comments: commentsDefinition,
|
|
@@ -3905,7 +4050,8 @@ const entryCommand = define({
|
|
|
3905
4050
|
description: "Artifact Share CLI",
|
|
3906
4051
|
toKebab: true,
|
|
3907
4052
|
args: commonArgs,
|
|
3908
|
-
examples: `npx --yes @artifactshare/cli
|
|
4053
|
+
examples: `npx --yes @artifactshare/cli open <artifact-id-or-url> --json
|
|
4054
|
+
npx --yes @artifactshare/cli share <path> --json
|
|
3909
4055
|
npx --yes @artifactshare/cli update <artifact-id-or-url> <path> --json
|
|
3910
4056
|
npx --yes @artifactshare/cli edit <artifact-id-or-url> --title "New title" --json
|
|
3911
4057
|
npx --yes @artifactshare/cli delete <artifact-id-or-url> --json
|
|
@@ -3925,7 +4071,7 @@ npx --yes @artifactshare/cli projects list --json
|
|
|
3925
4071
|
npx --yes @artifactshare/cli skills install --tool codex --json
|
|
3926
4072
|
npx --yes @artifactshare/cli skills list --json
|
|
3927
4073
|
npx --yes @artifactshare/cli init --profile <name> --project-id <id> --json
|
|
3928
|
-
npx --yes @artifactshare/cli
|
|
4074
|
+
npx --yes @artifactshare/cli share <path> --home --json
|
|
3929
4075
|
npx --yes @artifactshare/cli request-access --json
|
|
3930
4076
|
npx --yes @artifactshare/cli whoami --json
|
|
3931
4077
|
npx --yes @artifactshare/cli doctor --json
|
|
@@ -3958,30 +4104,30 @@ Common failures:
|
|
|
3958
4104
|
auth_expired The device code expired before approval
|
|
3959
4105
|
token_store_unavailable Configure an OS credential store or use the explicit plaintext fallback`
|
|
3960
4106
|
});
|
|
3961
|
-
const
|
|
3962
|
-
name: "
|
|
3963
|
-
description: "
|
|
4107
|
+
const shareDefinition = define({
|
|
4108
|
+
name: "share",
|
|
4109
|
+
description: "Share a file or directory.",
|
|
3964
4110
|
toKebab: true,
|
|
3965
4111
|
args: {
|
|
3966
4112
|
...commonArgs,
|
|
3967
4113
|
path: {
|
|
3968
4114
|
type: "positional",
|
|
3969
|
-
description: "File or directory to
|
|
4115
|
+
description: "File or directory to share"
|
|
3970
4116
|
},
|
|
3971
4117
|
projectId: {
|
|
3972
4118
|
type: "string",
|
|
3973
4119
|
toKebab: true,
|
|
3974
|
-
description: "
|
|
4120
|
+
description: "Share into a project"
|
|
3975
4121
|
},
|
|
3976
4122
|
project: {
|
|
3977
4123
|
type: "string",
|
|
3978
4124
|
toKebab: true,
|
|
3979
|
-
description: "
|
|
4125
|
+
description: "Share into a project by exact name"
|
|
3980
4126
|
},
|
|
3981
4127
|
home: {
|
|
3982
4128
|
type: "boolean",
|
|
3983
4129
|
toKebab: true,
|
|
3984
|
-
description: "
|
|
4130
|
+
description: "Share to home instead of a project"
|
|
3985
4131
|
},
|
|
3986
4132
|
visibility: {
|
|
3987
4133
|
type: "string",
|
|
@@ -3997,21 +4143,21 @@ const publishDefinition = define({
|
|
|
3997
4143
|
key: {
|
|
3998
4144
|
type: "string",
|
|
3999
4145
|
toKebab: true,
|
|
4000
|
-
description: "Stable key for create-or-update: the first
|
|
4146
|
+
description: "Stable key for create-or-update: the first share creates the artifact, repeats add versions. Not a secret; it appears in logs and JSON"
|
|
4001
4147
|
}
|
|
4002
4148
|
},
|
|
4003
|
-
examples: `npx --yes @artifactshare/cli
|
|
4004
|
-
npx --yes @artifactshare/cli
|
|
4149
|
+
examples: `npx --yes @artifactshare/cli share report.html --project-id <id> --json
|
|
4150
|
+
npx --yes @artifactshare/cli share report.html --project-id <id> --key nightly-report --json
|
|
4005
4151
|
|
|
4006
4152
|
To keep an existing share URL, use update:
|
|
4007
4153
|
npx --yes @artifactshare/cli update <artifact-id-or-url> <path> --json
|
|
4008
4154
|
|
|
4009
|
-
For repeat jobs, use --key: first
|
|
4155
|
+
For repeat jobs, use --key: first share creates the artifact, later runs add versions.
|
|
4010
4156
|
|
|
4011
4157
|
Common failures:
|
|
4012
|
-
auth_required Set ARTIFACTSHARE_TOKEN before
|
|
4013
|
-
destination_required Non-interactive
|
|
4014
|
-
upload_not_allowed Your account cannot
|
|
4158
|
+
auth_required Set ARTIFACTSHARE_TOKEN before share
|
|
4159
|
+
destination_required Non-interactive share needs --project-id, config default, or --home
|
|
4160
|
+
upload_not_allowed Your account cannot share yet; request access from an operator
|
|
4015
4161
|
file_too_large Reduce file or directory size and retry
|
|
4016
4162
|
validation_failed Check file type (.html / .md for single files) and directory layout
|
|
4017
4163
|
key_target_moved The artifact for --key moved; update it by ID or use a new key
|
|
@@ -4041,7 +4187,7 @@ Common failures:
|
|
|
4041
4187
|
auth_required Set ARTIFACTSHARE_TOKEN before update
|
|
4042
4188
|
target_not_found Retry with an artifact ID, share URL, or sandbox URL
|
|
4043
4189
|
artifact_kind_mismatch Use a file for single-file artifacts or a directory for static sites
|
|
4044
|
-
upload_not_allowed Your account cannot
|
|
4190
|
+
upload_not_allowed Your account cannot share yet; request access from an operator
|
|
4045
4191
|
file_too_large Reduce file or directory size and retry
|
|
4046
4192
|
validation_failed Check file type (.html / .md for single files) and directory layout`
|
|
4047
4193
|
});
|
|
@@ -4095,7 +4241,7 @@ const editDefinition = define({
|
|
|
4095
4241
|
npx --yes @artifactshare/cli edit abc123def4 --home --json
|
|
4096
4242
|
|
|
4097
4243
|
Edit changes artifact settings without adding a new version. Use update to replace content.
|
|
4098
|
-
Move remains available for placement-only automation; edit is the main command for post-
|
|
4244
|
+
Move remains available for placement-only automation; edit is the main command for post-share settings.
|
|
4099
4245
|
|
|
4100
4246
|
Common failures:
|
|
4101
4247
|
auth_required Set ARTIFACTSHARE_TOKEN before edit
|
|
@@ -4107,7 +4253,7 @@ Common failures:
|
|
|
4107
4253
|
});
|
|
4108
4254
|
const deleteDefinition = define({
|
|
4109
4255
|
name: "delete",
|
|
4110
|
-
description: "Permanently delete an artifact you
|
|
4256
|
+
description: "Permanently delete an artifact you shared.",
|
|
4111
4257
|
toKebab: true,
|
|
4112
4258
|
args: {
|
|
4113
4259
|
...commonArgs,
|
|
@@ -4184,38 +4330,30 @@ Common failures:
|
|
|
4184
4330
|
output_exists Choose another --output path or pass --force
|
|
4185
4331
|
validation_failed Check --output and downloaded file paths`
|
|
4186
4332
|
});
|
|
4187
|
-
const
|
|
4188
|
-
name: "
|
|
4189
|
-
description: "
|
|
4333
|
+
const openDefinition = define({
|
|
4334
|
+
name: "open",
|
|
4335
|
+
description: "Prepare agent skills and read an Artifact Share URL.",
|
|
4190
4336
|
toKebab: true,
|
|
4191
|
-
args:
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
description: "Artifact ID, /a/<id> share URL, or <id>.sandbox.* URL"
|
|
4202
|
-
}
|
|
4203
|
-
},
|
|
4204
|
-
examples: `npx --yes @artifactshare/cli agent open https://artifactshare.com/a/abc123def4 --json
|
|
4205
|
-
npx --yes @artifactshare/cli agent open abc123def4 --json
|
|
4337
|
+
args: {
|
|
4338
|
+
...commonArgs,
|
|
4339
|
+
artifactIdOrUrl: {
|
|
4340
|
+
type: "positional",
|
|
4341
|
+
toKebab: true,
|
|
4342
|
+
description: "Artifact ID, /a/<id> share URL, or <id>.sandbox.* URL"
|
|
4343
|
+
}
|
|
4344
|
+
},
|
|
4345
|
+
examples: `npx --yes @artifactshare/cli open https://artifactshare.com/a/abc123def4 --json
|
|
4346
|
+
npx --yes @artifactshare/cli open abc123def4 --json
|
|
4206
4347
|
|
|
4207
4348
|
Use this as the first command when an agent receives an Artifact Share URL.
|
|
4208
4349
|
It installs or updates the local Artifact Share skill, then reads single-file artifacts.
|
|
4209
4350
|
For static sites or multi-file artifacts, the JSON includes a download next_command.
|
|
4210
4351
|
|
|
4211
4352
|
Common failures:
|
|
4212
|
-
auth_required Set ARTIFACTSHARE_TOKEN before
|
|
4353
|
+
auth_required Set ARTIFACTSHARE_TOKEN before open
|
|
4213
4354
|
skill_update_conflict Inspect the file or run skills install --tool <tool> --force
|
|
4214
4355
|
target_not_found Retry with an artifact ID, share URL, or sandbox URL
|
|
4215
4356
|
validation_failed Pass a non-empty artifact ID or URL`
|
|
4216
|
-
}), agentOpenRunner) },
|
|
4217
|
-
examples: `npx --yes @artifactshare/cli agent open https://artifactshare.com/a/abc123def4 --json`,
|
|
4218
|
-
run: parentCommandRunner("agent")
|
|
4219
4357
|
});
|
|
4220
4358
|
const moveDefinition = define({
|
|
4221
4359
|
name: "move",
|
|
@@ -4296,7 +4434,7 @@ const artifactsDefinition = define({
|
|
|
4296
4434
|
subCommands: {
|
|
4297
4435
|
list: lazyCommand(define({
|
|
4298
4436
|
name: "list",
|
|
4299
|
-
description: "List artifacts you
|
|
4437
|
+
description: "List artifacts you shared, newest first.",
|
|
4300
4438
|
toKebab: true,
|
|
4301
4439
|
args: {
|
|
4302
4440
|
...commonArgs,
|
|
@@ -4582,17 +4720,17 @@ printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --prof
|
|
|
4582
4720
|
});
|
|
4583
4721
|
const projectsListDefinition = define({
|
|
4584
4722
|
name: "list",
|
|
4585
|
-
description: "List projects you can
|
|
4723
|
+
description: "List projects you can share into.",
|
|
4586
4724
|
toKebab: true,
|
|
4587
4725
|
args: commonArgs,
|
|
4588
4726
|
examples: `npx --yes @artifactshare/cli projects list --json
|
|
4589
4727
|
|
|
4590
4728
|
is_default marks the working-directory default project from .artifactshare/config.json.
|
|
4591
|
-
Use a project id with
|
|
4729
|
+
Use a project id with share --project-id or init --project-id.`
|
|
4592
4730
|
});
|
|
4593
4731
|
const projectsCreateDefinition = define({
|
|
4594
4732
|
name: "create",
|
|
4595
|
-
description: "Create a project you can
|
|
4733
|
+
description: "Create a project you can share into.",
|
|
4596
4734
|
toKebab: true,
|
|
4597
4735
|
args: {
|
|
4598
4736
|
...commonArgs,
|
|
@@ -4614,11 +4752,11 @@ const projectsCreateDefinition = define({
|
|
|
4614
4752
|
examples: `npx --yes @artifactshare/cli projects create "Launch review" --json
|
|
4615
4753
|
npx --yes @artifactshare/cli projects create "Client" --description "Weekly reports" --visibility private --json
|
|
4616
4754
|
|
|
4617
|
-
The response includes project.id and next_command for
|
|
4755
|
+
The response includes project.id and next_command for share --project-id.
|
|
4618
4756
|
|
|
4619
4757
|
Common failures:
|
|
4620
4758
|
auth_required Set ARTIFACTSHARE_TOKEN before projects create
|
|
4621
|
-
upload_not_allowed Your account cannot
|
|
4759
|
+
upload_not_allowed Your account cannot share yet; request access from an operator
|
|
4622
4760
|
validation_failed Pass a non-empty name and valid --visibility`
|
|
4623
4761
|
});
|
|
4624
4762
|
const projectsEditDefinition = define({
|
|
@@ -4683,7 +4821,7 @@ Common failures:
|
|
|
4683
4821
|
});
|
|
4684
4822
|
const projectsDefinition = define({
|
|
4685
4823
|
name: "projects",
|
|
4686
|
-
description: "Create, find, and edit
|
|
4824
|
+
description: "Create, find, and edit share destinations.",
|
|
4687
4825
|
toKebab: true,
|
|
4688
4826
|
args: commonArgs,
|
|
4689
4827
|
subCommands: {
|
|
@@ -4831,7 +4969,7 @@ const initDefinition = define({
|
|
|
4831
4969
|
projectId: {
|
|
4832
4970
|
type: "string",
|
|
4833
4971
|
toKebab: true,
|
|
4834
|
-
description: "Default project for
|
|
4972
|
+
description: "Default project for sharing in this directory"
|
|
4835
4973
|
}
|
|
4836
4974
|
},
|
|
4837
4975
|
examples: `npx --yes @artifactshare/cli init --profile client-a --project-id <id> --json
|
|
@@ -4845,7 +4983,7 @@ Common failures:
|
|
|
4845
4983
|
});
|
|
4846
4984
|
const requestAccessDefinition = define({
|
|
4847
4985
|
name: "request-access",
|
|
4848
|
-
description: "Join the early-access waitlist for
|
|
4986
|
+
description: "Join the early-access waitlist for sharing.",
|
|
4849
4987
|
toKebab: true,
|
|
4850
4988
|
args: {
|
|
4851
4989
|
...commonArgs,
|
|
@@ -4856,9 +4994,9 @@ const requestAccessDefinition = define({
|
|
|
4856
4994
|
}
|
|
4857
4995
|
},
|
|
4858
4996
|
examples: `npx --yes @artifactshare/cli request-access --json
|
|
4859
|
-
npx --yes @artifactshare/cli request-access --note "
|
|
4997
|
+
npx --yes @artifactshare/cli request-access --note "Sharing weekly reports for my team" --json
|
|
4860
4998
|
|
|
4861
|
-
Joining the waitlist does not enable
|
|
4999
|
+
Joining the waitlist does not enable sharing immediately; an operator opens it.
|
|
4862
5000
|
Re-running updates your note without creating a duplicate entry.
|
|
4863
5001
|
|
|
4864
5002
|
Common failures:
|