@artifactshare/cli 0.1.5 → 0.1.7
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 +43 -21
- package/dist/index.js +1723 -738
- package/package.json +2 -2
- package/skills/artifactshare/SKILL.md +29 -10
- package/skills/artifactshare/artifactshare.mdc +11 -4
package/dist/index.js
CHANGED
|
@@ -3,14 +3,15 @@ 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 { homedir } from "node:os";
|
|
6
7
|
import { createReadStream } from "node:fs";
|
|
7
8
|
import { createHash } from "node:crypto";
|
|
8
9
|
import { setTimeout } from "node:timers/promises";
|
|
9
|
-
import { homedir } from "node:os";
|
|
10
10
|
//#region src/constants.ts
|
|
11
11
|
const DEFAULT_BASE_URL = "https://artifactshare.com";
|
|
12
12
|
const DEVICE_CLIENT_ID = "artifactshare-cli";
|
|
13
13
|
const CLI_INVOCATION = "npx --yes @artifactshare/cli";
|
|
14
|
+
const AGENT_DOWNLOAD_OUTPUT = "./artifact";
|
|
14
15
|
const TOKEN_ENV_VAR = "ARTIFACTSHARE_TOKEN";
|
|
15
16
|
const TOKEN_OPTION = "--token";
|
|
16
17
|
const IGNORED_FILENAMES = new Set([
|
|
@@ -26,31 +27,41 @@ const EXCLUDED_DIR_NAMES = new Set([
|
|
|
26
27
|
]);
|
|
27
28
|
const BOOLEAN_FLAGS = new Set([
|
|
28
29
|
"allow-plaintext-token-store",
|
|
30
|
+
"archive",
|
|
29
31
|
"dry-run",
|
|
30
32
|
"force",
|
|
31
33
|
"json",
|
|
32
34
|
"help",
|
|
33
35
|
"home",
|
|
34
|
-
"insecure-localhost"
|
|
36
|
+
"insecure-localhost",
|
|
37
|
+
"unarchive"
|
|
35
38
|
]);
|
|
36
39
|
const VALUE_FLAGS = new Set([
|
|
40
|
+
"add-email",
|
|
37
41
|
"base-url",
|
|
38
42
|
"body",
|
|
39
43
|
"description",
|
|
40
44
|
"grant-email",
|
|
41
45
|
"include",
|
|
42
46
|
"key",
|
|
47
|
+
"message-id",
|
|
48
|
+
"name",
|
|
43
49
|
"note",
|
|
44
50
|
"offset",
|
|
45
51
|
"output",
|
|
46
52
|
"profile",
|
|
47
53
|
"project",
|
|
48
54
|
"project-id",
|
|
55
|
+
"query",
|
|
49
56
|
"quote",
|
|
50
57
|
"quote-after",
|
|
51
58
|
"quote-before",
|
|
52
59
|
"reply-to",
|
|
60
|
+
"remove-email",
|
|
61
|
+
"revoke-email",
|
|
53
62
|
"scope",
|
|
63
|
+
"thread-id",
|
|
64
|
+
"title",
|
|
54
65
|
"token",
|
|
55
66
|
"tool",
|
|
56
67
|
"visibility"
|
|
@@ -59,8 +70,11 @@ const COMMAND_NAMES = new Set([
|
|
|
59
70
|
"login",
|
|
60
71
|
"publish",
|
|
61
72
|
"update",
|
|
73
|
+
"edit",
|
|
74
|
+
"delete",
|
|
62
75
|
"resolve",
|
|
63
76
|
"download",
|
|
77
|
+
"agent",
|
|
64
78
|
"move",
|
|
65
79
|
"artifacts",
|
|
66
80
|
"comments",
|
|
@@ -73,19 +87,32 @@ const COMMAND_NAMES = new Set([
|
|
|
73
87
|
"init"
|
|
74
88
|
]);
|
|
75
89
|
const SUBCOMMANDS = {
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
agent: ["open"],
|
|
91
|
+
artifacts: ["list", "get"],
|
|
92
|
+
comments: [
|
|
93
|
+
"list",
|
|
94
|
+
"post",
|
|
95
|
+
"edit",
|
|
96
|
+
"resolve",
|
|
97
|
+
"reopen",
|
|
98
|
+
"delete"
|
|
99
|
+
],
|
|
78
100
|
profiles: [
|
|
79
101
|
"list",
|
|
80
102
|
"use",
|
|
81
103
|
"import-token"
|
|
82
104
|
],
|
|
83
|
-
projects: [
|
|
105
|
+
projects: [
|
|
106
|
+
"list",
|
|
107
|
+
"create",
|
|
108
|
+
"edit"
|
|
109
|
+
],
|
|
84
110
|
skills: [
|
|
85
111
|
"install",
|
|
86
112
|
"list",
|
|
87
113
|
"update",
|
|
88
|
-
"remove"
|
|
114
|
+
"remove",
|
|
115
|
+
"ensure"
|
|
89
116
|
]
|
|
90
117
|
};
|
|
91
118
|
const UPDATE_OPTION_KEYS = new Set([
|
|
@@ -97,6 +124,9 @@ const UPDATE_OPTION_KEYS = new Set([
|
|
|
97
124
|
"profile",
|
|
98
125
|
"token"
|
|
99
126
|
]);
|
|
127
|
+
function agentDownloadCommand(target) {
|
|
128
|
+
return `${CLI_INVOCATION} download ${target} --output ${AGENT_DOWNLOAD_OUTPUT} --json`;
|
|
129
|
+
}
|
|
100
130
|
//#endregion
|
|
101
131
|
//#region src/errors.ts
|
|
102
132
|
const REQUEST_ACCESS_COMMAND$1 = `${CLI_INVOCATION} request-access --json`;
|
|
@@ -194,6 +224,15 @@ function mapApiError(status, body, options = {}) {
|
|
|
194
224
|
requiresHuman: false,
|
|
195
225
|
recovery: { kind: "change_input" }
|
|
196
226
|
});
|
|
227
|
+
if (apiCode === "message-not-found") return cliError({
|
|
228
|
+
code: "message_not_found",
|
|
229
|
+
message: apiMessage ?? "Comment message was not found.",
|
|
230
|
+
why: "No comment message with that ID exists in the selected thread.",
|
|
231
|
+
hint: `Run ${CLI_INVOCATION} comments list <artifact-id> --json and retry with a listed message_id.`,
|
|
232
|
+
agentRecoverable: true,
|
|
233
|
+
requiresHuman: false,
|
|
234
|
+
recovery: { kind: "change_input" }
|
|
235
|
+
});
|
|
197
236
|
if (apiCode === "thread-resolved") return cliError({
|
|
198
237
|
code: "thread_resolved",
|
|
199
238
|
message: apiMessage ?? "Comment thread is resolved.",
|
|
@@ -203,6 +242,7 @@ function mapApiError(status, body, options = {}) {
|
|
|
203
242
|
requiresHuman: false,
|
|
204
243
|
recovery: { kind: "change_input" }
|
|
205
244
|
});
|
|
245
|
+
if (apiCode === "invalid-comment") return validationError(apiMessage ?? "Invalid comment payload.", "Check the comment body and IDs, then retry.");
|
|
206
246
|
if (apiCode === "quote-unsupported") return cliError({
|
|
207
247
|
code: "quote_unsupported",
|
|
208
248
|
message: apiMessage ?? "This artifact does not support quoted comments.",
|
|
@@ -230,6 +270,18 @@ function mapApiError(status, body, options = {}) {
|
|
|
230
270
|
requiresHuman: false,
|
|
231
271
|
recovery: { kind: "change_input" }
|
|
232
272
|
});
|
|
273
|
+
if (options.projectTarget && (apiCode === "not-found" || status === 404)) return cliError({
|
|
274
|
+
code: "target_not_found",
|
|
275
|
+
message: apiMessage ?? "Project target was not found.",
|
|
276
|
+
why: "The specified project does not exist or is not available in the current workspace.",
|
|
277
|
+
hint: `Run ${PROJECTS_LIST_COMMAND}, then retry with a listed project id.`,
|
|
278
|
+
agentRecoverable: true,
|
|
279
|
+
requiresHuman: false,
|
|
280
|
+
recovery: {
|
|
281
|
+
kind: "run_command",
|
|
282
|
+
command: PROJECTS_LIST_COMMAND
|
|
283
|
+
}
|
|
284
|
+
});
|
|
233
285
|
if (options.artifactTarget && apiCode === "unsupported-kind") return cliError({
|
|
234
286
|
code: "unsupported_kind",
|
|
235
287
|
message: apiMessage ?? "This artifact cannot be read as a single source file.",
|
|
@@ -257,6 +309,15 @@ function mapApiError(status, body, options = {}) {
|
|
|
257
309
|
requiresHuman: false,
|
|
258
310
|
recovery: { kind: "change_input" }
|
|
259
311
|
});
|
|
312
|
+
if (apiCode === "forbidden" || status === 403) return cliError({
|
|
313
|
+
code: "forbidden",
|
|
314
|
+
message: apiMessage ?? "You do not have permission to do that.",
|
|
315
|
+
why: "The current account is not allowed to change this comment or artifact.",
|
|
316
|
+
hint: "Use an account with permission, or ask the artifact owner or a workspace admin to make the change.",
|
|
317
|
+
agentRecoverable: false,
|
|
318
|
+
requiresHuman: true,
|
|
319
|
+
recovery: { kind: "ask_human" }
|
|
320
|
+
});
|
|
260
321
|
if (apiCode === "key-target-moved") return cliError({
|
|
261
322
|
code: "key_target_moved",
|
|
262
323
|
message: apiMessage ?? "The artifact for this key moved.",
|
|
@@ -296,6 +357,33 @@ function mapApiError(status, body, options = {}) {
|
|
|
296
357
|
command: PROJECTS_LIST_COMMAND
|
|
297
358
|
}
|
|
298
359
|
});
|
|
360
|
+
if (options.editSettings && apiCode === "workspace-unavailable") return cliError({
|
|
361
|
+
code: "workspace_unavailable",
|
|
362
|
+
message: apiMessage ?? "Workspace visibility is unavailable for this account.",
|
|
363
|
+
why: "Personal Google accounts cannot share with a whole workspace.",
|
|
364
|
+
hint: "Retry with --visibility private and explicit --grant-email values.",
|
|
365
|
+
agentRecoverable: true,
|
|
366
|
+
requiresHuman: false,
|
|
367
|
+
recovery: { kind: "change_input" }
|
|
368
|
+
});
|
|
369
|
+
if ((options.editSettings || options.projectTarget) && apiCode === "too-many-grants") return cliError({
|
|
370
|
+
code: "too_many_grants",
|
|
371
|
+
message: apiMessage ?? "Too many people are shared.",
|
|
372
|
+
why: "The target reached the maximum number of explicit viewers.",
|
|
373
|
+
hint: "Remove one or more viewers, or use a narrower set of email values.",
|
|
374
|
+
agentRecoverable: true,
|
|
375
|
+
requiresHuman: false,
|
|
376
|
+
recovery: { kind: "change_input" }
|
|
377
|
+
});
|
|
378
|
+
if (options.projectTarget && apiCode === "project-archived") return cliError({
|
|
379
|
+
code: "project_archived",
|
|
380
|
+
message: apiMessage ?? "Project is archived.",
|
|
381
|
+
why: "Archived projects must be unarchived before changing their settings or audience.",
|
|
382
|
+
hint: "Retry with --unarchive in the same command, or unarchive the project first.",
|
|
383
|
+
agentRecoverable: true,
|
|
384
|
+
requiresHuman: false,
|
|
385
|
+
recovery: { kind: "change_input" }
|
|
386
|
+
});
|
|
299
387
|
if (apiCode !== null && [
|
|
300
388
|
"unsupported-type",
|
|
301
389
|
"invalid-key",
|
|
@@ -501,7 +589,7 @@ function skillUpdateConflictError(path) {
|
|
|
501
589
|
code: "skill_update_conflict",
|
|
502
590
|
message: `The file at ${path} is not managed by Artifact Share CLI.`,
|
|
503
591
|
why: "Artifact Share only rewrites or removes skill files it created with a managed marker comment.",
|
|
504
|
-
hint: "Inspect the file and resolve it yourself, or rerun skills install
|
|
592
|
+
hint: "Inspect the file and resolve it yourself, or rerun skills install --tool <tool> --force to overwrite it.",
|
|
505
593
|
agentRecoverable: false,
|
|
506
594
|
requiresHuman: true,
|
|
507
595
|
recovery: { kind: "ask_human" },
|
|
@@ -622,6 +710,9 @@ function parseIncludeOptions(value) {
|
|
|
622
710
|
}
|
|
623
711
|
return { values: [...new Set(values)] };
|
|
624
712
|
}
|
|
713
|
+
function hasProjectIdHomeConflict(options) {
|
|
714
|
+
return options.projectId !== void 0 && Boolean(options.home);
|
|
715
|
+
}
|
|
625
716
|
function unsupportedUpdateOption(options) {
|
|
626
717
|
for (const key of Object.keys(options)) if (!UPDATE_OPTION_KEYS.has(key)) return kebabCase(key);
|
|
627
718
|
return null;
|
|
@@ -645,9 +736,16 @@ const TARGET_COMMAND_LABELS = {
|
|
|
645
736
|
update: "Update",
|
|
646
737
|
"artifacts get": "Artifacts get",
|
|
647
738
|
download: "Download",
|
|
739
|
+
"agent open": "Agent open",
|
|
648
740
|
"comments list": "Comments list",
|
|
649
741
|
"comments post": "Comments post",
|
|
650
|
-
|
|
742
|
+
"comments edit": "Comments edit",
|
|
743
|
+
"comments resolve": "Comments resolve",
|
|
744
|
+
"comments reopen": "Comments reopen",
|
|
745
|
+
"comments delete": "Comments delete",
|
|
746
|
+
move: "Move",
|
|
747
|
+
edit: "Edit",
|
|
748
|
+
delete: "Delete"
|
|
651
749
|
};
|
|
652
750
|
function targetResolutionError(input, command) {
|
|
653
751
|
return cliError({
|
|
@@ -684,6 +782,14 @@ function parsedArgsFromContext(command, ctx) {
|
|
|
684
782
|
const name = camelCase(rawName);
|
|
685
783
|
if (options[name] === void 0 && !UPDATE_OPTION_KEYS.has(name)) options[name] = true;
|
|
686
784
|
}
|
|
785
|
+
if (command === "edit") for (const token of ctx.tokens) {
|
|
786
|
+
if (token.kind !== "option") continue;
|
|
787
|
+
if ((token.name ?? token.rawName?.replace(/^--?/, "")) === "title" && options.title === void 0) options.title = "";
|
|
788
|
+
}
|
|
789
|
+
if (command === "projects edit") for (const token of ctx.tokens) {
|
|
790
|
+
if (token.kind !== "option") continue;
|
|
791
|
+
if ((token.name ?? token.rawName?.replace(/^--?/, "")) === "description" && options.description === void 0) options.description = "";
|
|
792
|
+
}
|
|
687
793
|
return {
|
|
688
794
|
command,
|
|
689
795
|
options,
|
|
@@ -720,23 +826,35 @@ function isKnownFlagToken(token) {
|
|
|
720
826
|
const name = eqIndex === -1 ? token.slice(2) : token.slice(2, eqIndex);
|
|
721
827
|
return BOOLEAN_FLAGS.has(name) || VALUE_FLAGS.has(name) || name === "help" || name === "version";
|
|
722
828
|
}
|
|
723
|
-
function validateRawArgs(argv) {
|
|
829
|
+
function validateRawArgs(argv, command) {
|
|
724
830
|
for (let i = 0; i < argv.length; i += 1) {
|
|
725
831
|
const arg = argv[i] ?? "";
|
|
726
832
|
if (!arg.startsWith("--")) continue;
|
|
727
833
|
const eqIndex = arg.indexOf("=");
|
|
728
834
|
if (eqIndex === -1) {
|
|
729
835
|
const rawName = arg.slice(2);
|
|
730
|
-
|
|
836
|
+
const artifactIdError = unsupportedPublishArtifactId(rawName, command);
|
|
837
|
+
if (artifactIdError) return artifactIdError;
|
|
838
|
+
const next = argv[i + 1];
|
|
839
|
+
if (VALUE_FLAGS.has(rawName) && (next === void 0 || isKnownFlagToken(next) || next === "" && !allowsEmptyValue(rawName))) return validationError(`--${rawName} requires a value.`, `Pass --${rawName} <value> and retry.`);
|
|
731
840
|
continue;
|
|
732
841
|
}
|
|
733
842
|
const rawName = arg.slice(2, eqIndex);
|
|
843
|
+
const artifactIdError = unsupportedPublishArtifactId(rawName, command);
|
|
844
|
+
if (artifactIdError) return artifactIdError;
|
|
734
845
|
const value = arg.slice(eqIndex + 1);
|
|
735
846
|
if (BOOLEAN_FLAGS.has(rawName)) return validationError(`--${rawName} does not accept a value.`, `Use --${rawName} without =value.`);
|
|
736
|
-
if (VALUE_FLAGS.has(rawName) && value === "") return validationError(`--${rawName} requires a value.`, `Pass --${rawName} <value> and retry.`);
|
|
847
|
+
if (VALUE_FLAGS.has(rawName) && value === "" && !allowsEmptyValue(rawName)) return validationError(`--${rawName} requires a value.`, `Pass --${rawName} <value> and retry.`);
|
|
737
848
|
}
|
|
738
849
|
return null;
|
|
739
850
|
}
|
|
851
|
+
function unsupportedPublishArtifactId(rawName, command) {
|
|
852
|
+
if (command !== "publish" || rawName !== "artifact-id" && rawName !== "artifactId") return null;
|
|
853
|
+
return validationError("Publish 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 publish --key <key>.`);
|
|
854
|
+
}
|
|
855
|
+
function allowsEmptyValue(rawName) {
|
|
856
|
+
return rawName === "title" || rawName === "description";
|
|
857
|
+
}
|
|
740
858
|
function commandNameFromArgv(argv) {
|
|
741
859
|
const found = findCommandCandidate(argv);
|
|
742
860
|
const command = found?.command;
|
|
@@ -861,8 +979,26 @@ function humanSuccess(command, data) {
|
|
|
861
979
|
].join("\n");
|
|
862
980
|
}
|
|
863
981
|
if (command === "doctor") return doctorHumanOutput(data);
|
|
982
|
+
if (command === "agent open") return agentOpenHumanOutput(data);
|
|
864
983
|
return `${JSON.stringify(data, null, 2)}\n`;
|
|
865
984
|
}
|
|
985
|
+
function agentOpenHumanOutput(data) {
|
|
986
|
+
const body = `${JSON.stringify(data, null, 2)}`;
|
|
987
|
+
const nextCommand = agentOpenNextCommand(data);
|
|
988
|
+
if (!nextCommand) return `${body}\n`;
|
|
989
|
+
return `${body}\nNext command: ${nextCommand}\n`;
|
|
990
|
+
}
|
|
991
|
+
function agentOpenNextCommand(data) {
|
|
992
|
+
if (!isAgentOpenData(data)) return null;
|
|
993
|
+
return data.open.kind === "download_required" ? data.open.next_command : null;
|
|
994
|
+
}
|
|
995
|
+
function isAgentOpenData(data) {
|
|
996
|
+
if (!isRecord(data)) return false;
|
|
997
|
+
const open = data.open;
|
|
998
|
+
if (!isRecord(open)) return false;
|
|
999
|
+
if (open.kind === "read") return true;
|
|
1000
|
+
return open.kind === "download_required" && typeof open.next_command === "string";
|
|
1001
|
+
}
|
|
866
1002
|
function doctorHumanOutput(data) {
|
|
867
1003
|
const nextCommand = doctorNextCommand(data);
|
|
868
1004
|
const body = `${JSON.stringify(data, null, 2)}`;
|
|
@@ -908,6 +1044,17 @@ function artifactGetSuccessFields(data) {
|
|
|
908
1044
|
if (!isRecord(data)) return false;
|
|
909
1045
|
return typeof data.id === "string" && typeof data.share_url === "string" && typeof data.version_id === "string" && (data.format === "html" || data.format === "markdown") && typeof data.content === "string" && typeof data.size_bytes === "number" && typeof data.truncated === "boolean" && (typeof data.next_offset === "number" || data.next_offset === null);
|
|
910
1046
|
}
|
|
1047
|
+
function artifactsListSuccessFields(data) {
|
|
1048
|
+
if (!isRecord(data)) return false;
|
|
1049
|
+
return Array.isArray(data.artifacts) && data.artifacts.every((item) => {
|
|
1050
|
+
if (!isRecord(item)) return false;
|
|
1051
|
+
return typeof item.id === "string" && typeof item.title === "string" && typeof item.share_url === "string" && typeof item.visibility === "string" && typeof item.updated_at === "string" && (typeof item.project_id === "string" || item.project_id === null);
|
|
1052
|
+
}) && typeof data.limit === "number" && typeof data.has_more === "boolean" && (typeof data.next_cursor === "string" || data.next_cursor === null);
|
|
1053
|
+
}
|
|
1054
|
+
function deleteSuccessFields(data) {
|
|
1055
|
+
if (!isRecord(data)) return false;
|
|
1056
|
+
return typeof data.id === "string" && data.deleted === true;
|
|
1057
|
+
}
|
|
911
1058
|
function downloadManifestFields(data) {
|
|
912
1059
|
if (!isRecord(data)) return false;
|
|
913
1060
|
return typeof data.id === "string" && typeof data.share_url === "string" && typeof data.version_id === "string" && typeof data.artifact_kind === "string" && Array.isArray(data.files) && data.files.every(downloadManifestFileFields) && typeof data.total_size_bytes === "number";
|
|
@@ -972,6 +1119,13 @@ async function apiPost(path, token, payload, options, init, errorOptions = {}) {
|
|
|
972
1119
|
...init
|
|
973
1120
|
}, errorOptions);
|
|
974
1121
|
}
|
|
1122
|
+
async function apiDelete(path, token, options, init, errorOptions = {}) {
|
|
1123
|
+
return await apiRequest(path, options, {
|
|
1124
|
+
method: "DELETE",
|
|
1125
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
1126
|
+
...init
|
|
1127
|
+
}, errorOptions);
|
|
1128
|
+
}
|
|
975
1129
|
async function apiRequest(path, options, init, errorOptions) {
|
|
976
1130
|
const response = await fetch(apiUrl(path, baseUrlOf(options)), init).catch((error) => ({ networkError: error }));
|
|
977
1131
|
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
@@ -1516,17 +1670,22 @@ async function resolveEffectiveDefaultProfile(projectInput = null) {
|
|
|
1516
1670
|
//#region src/command-runners/artifacts-get.ts
|
|
1517
1671
|
async function runArtifactsGet(parsed, mode) {
|
|
1518
1672
|
const command = "artifacts get";
|
|
1673
|
+
const result = await readArtifact(parsed, command);
|
|
1674
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
1675
|
+
return writeSuccess(command, result.data, mode);
|
|
1676
|
+
}
|
|
1677
|
+
async function readArtifact(parsed, command) {
|
|
1519
1678
|
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to read.");
|
|
1520
|
-
if (target.error) return
|
|
1679
|
+
if (target.error) return { error: target.error };
|
|
1521
1680
|
const artifactId = target.artifactId;
|
|
1522
1681
|
const offset = parseOffsetOption(parsed.options.offset);
|
|
1523
|
-
if (offset.error) return
|
|
1682
|
+
if (offset.error) return { error: offset.error };
|
|
1524
1683
|
const include = parseIncludeOptions(parsed.options.include);
|
|
1525
|
-
if (include.error) return
|
|
1684
|
+
if (include.error) return { error: include.error };
|
|
1526
1685
|
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
1527
|
-
if (!credential.ok) return
|
|
1686
|
+
if (!credential.ok) return { error: credential.error };
|
|
1528
1687
|
const request = await requestConfig(parsed.options);
|
|
1529
|
-
if (request.error) return
|
|
1688
|
+
if (request.error) return { error: request.error };
|
|
1530
1689
|
const url = apiUrl(`/api/cli/artifacts/${encodeURIComponent(artifactId)}`, baseUrlOf(parsed.options));
|
|
1531
1690
|
if (offset.value !== void 0) url.searchParams.set("offset", offset.value);
|
|
1532
1691
|
for (const item of include.values) url.searchParams.append("include", item);
|
|
@@ -1534,335 +1693,849 @@ async function runArtifactsGet(parsed, mode) {
|
|
|
1534
1693
|
headers: { Authorization: `Bearer ${credential.token}` },
|
|
1535
1694
|
...request.init
|
|
1536
1695
|
}).catch((error) => ({ networkError: error }));
|
|
1537
|
-
if ("networkError" in response) return
|
|
1696
|
+
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
1538
1697
|
const body = await readJson(response);
|
|
1539
|
-
if (!response.ok) return
|
|
1698
|
+
if (!response.ok) return { error: mapApiError(response.status, body, {
|
|
1540
1699
|
authenticated: true,
|
|
1541
1700
|
artifactTarget: true
|
|
1542
|
-
})
|
|
1543
|
-
if (!artifactGetSuccessFields(body)) return
|
|
1544
|
-
return
|
|
1545
|
-
}
|
|
1546
|
-
//#endregion
|
|
1547
|
-
//#region src/command-runners/comments.ts
|
|
1548
|
-
async function runCommentsList(parsed, mode) {
|
|
1549
|
-
const command = "comments list";
|
|
1550
|
-
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
1551
|
-
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
1552
|
-
const artifactId = target.artifactId;
|
|
1553
|
-
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
1554
|
-
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
1555
|
-
const request = await requestConfig(parsed.options);
|
|
1556
|
-
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1557
|
-
const result = await apiGet(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, parsed.options, request.init, { artifactTarget: true });
|
|
1558
|
-
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
1559
|
-
const comments = Array.isArray(result.body?.comments) ? result.body.comments : [];
|
|
1560
|
-
writeSuccess(command, {
|
|
1561
|
-
artifact_id: artifactId,
|
|
1562
|
-
share_url: configString(result.body?.share_url),
|
|
1563
|
-
comments,
|
|
1564
|
-
has_more: result.body?.has_more === true
|
|
1565
|
-
}, mode);
|
|
1566
|
-
if (!mode.json && comments.length === 0) writeText("No comments yet.\n");
|
|
1701
|
+
}) };
|
|
1702
|
+
if (!artifactGetSuccessFields(body)) return { error: serviceError("Artifact read succeeded but the response did not include source metadata.") };
|
|
1703
|
+
return { data: body };
|
|
1567
1704
|
}
|
|
1568
|
-
async function
|
|
1569
|
-
const command = "
|
|
1570
|
-
const
|
|
1571
|
-
|
|
1572
|
-
const
|
|
1573
|
-
|
|
1574
|
-
if (
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
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);
|
|
1578
|
-
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);
|
|
1705
|
+
async function runArtifactsList(parsed, mode) {
|
|
1706
|
+
const command = "artifacts list";
|
|
1707
|
+
const hasProjectId = parsed.options.projectId !== void 0;
|
|
1708
|
+
const projectId = parsed.options.projectId?.trim() ?? "";
|
|
1709
|
+
const home = Boolean(parsed.options.home);
|
|
1710
|
+
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);
|
|
1711
|
+
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);
|
|
1712
|
+
const query = parsed.options.query?.trim();
|
|
1713
|
+
if (parsed.options.query !== void 0 && !query) return writeFailure(command, validationError("--query must not be empty.", "Pass --query <text> or omit --query."), mode, 1);
|
|
1579
1714
|
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
1580
1715
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
1581
1716
|
const request = await requestConfig(parsed.options);
|
|
1582
1717
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1583
|
-
const
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
thread_id: threadId,
|
|
1597
|
-
reply: result.body?.reply === true,
|
|
1598
|
-
thread: result.body?.thread ?? null
|
|
1599
|
-
}, mode);
|
|
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
|
|
1725
|
+
}).catch((error) => ({ networkError: error }));
|
|
1726
|
+
if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
|
|
1727
|
+
const body = await readJson(response);
|
|
1728
|
+
if (!response.ok) return writeFailure(command, mapApiError(response.status, body, { authenticated: true }), mode, 1);
|
|
1729
|
+
if (!artifactsListSuccessFields(body)) return writeFailure(command, serviceError("Artifact list succeeded but the response did not include list metadata."), mode, 1);
|
|
1730
|
+
return writeSuccess(command, body, mode);
|
|
1600
1731
|
}
|
|
1601
1732
|
//#endregion
|
|
1602
|
-
//#region src/command-runners/
|
|
1603
|
-
const
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
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: []
|
|
1622
1761
|
}
|
|
1623
|
-
|
|
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
|
+
};
|
|
1624
1772
|
}
|
|
1625
|
-
function
|
|
1626
|
-
|
|
1627
|
-
return authRecoveryDetails(data.base_url, loginCommand);
|
|
1773
|
+
function allTargets() {
|
|
1774
|
+
return SKILL_TOOLS.flatMap((tool) => TOOL_CONFIG[tool].scopes.map((scope) => skillTarget(tool, scope)));
|
|
1628
1775
|
}
|
|
1629
|
-
function
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
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)
|
|
1634
1786
|
};
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1787
|
+
}
|
|
1788
|
+
async function readTarget(target) {
|
|
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
|
+
}
|
|
1807
|
+
return {
|
|
1808
|
+
contents,
|
|
1809
|
+
version
|
|
1638
1810
|
};
|
|
1639
|
-
return next;
|
|
1640
1811
|
}
|
|
1641
|
-
|
|
1642
|
-
const
|
|
1643
|
-
const
|
|
1644
|
-
const
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
credential_source: credential.source,
|
|
1652
|
-
...credential.profile ? { profile: credential.profile } : {},
|
|
1653
|
-
token_present: credential.ok,
|
|
1654
|
-
ok: false
|
|
1655
|
-
},
|
|
1656
|
-
destination: destination.error ? {
|
|
1657
|
-
ok: false,
|
|
1658
|
-
code: destination.error.code,
|
|
1659
|
-
hint: destination.error.hint
|
|
1660
|
-
} : {
|
|
1661
|
-
ok: true,
|
|
1662
|
-
type: destination.containerId ? "project" : "home",
|
|
1663
|
-
project_id: destination.containerId ?? null
|
|
1664
|
-
},
|
|
1665
|
-
network: { ok: false },
|
|
1666
|
-
upload: {
|
|
1667
|
-
ok: false,
|
|
1668
|
-
checked: false
|
|
1812
|
+
function parseTools(value, options = {}) {
|
|
1813
|
+
const raws = arrayOption(value);
|
|
1814
|
+
const tools = [];
|
|
1815
|
+
for (const raw of raws) for (const item of raw.split(",")) {
|
|
1816
|
+
const trimmed = item.trim();
|
|
1817
|
+
if (!trimmed) continue;
|
|
1818
|
+
if (trimmed === "auto") {
|
|
1819
|
+
if (!options.allowAuto) return { error: validationError(`Unknown --tool value: ${trimmed}`, "Pass --tool codex, --tool claude, or --tool cursor.") };
|
|
1820
|
+
tools.push(trimmed);
|
|
1821
|
+
continue;
|
|
1669
1822
|
}
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
if (credential.error.code !== "auth_required") return writeFailure(command, credential.error, mode, 1);
|
|
1673
|
-
data.auth.code = credential.error.code;
|
|
1674
|
-
data.auth.hint = credential.error.hint;
|
|
1675
|
-
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
1676
|
-
}
|
|
1677
|
-
const request = await requestConfig(parsed.options);
|
|
1678
|
-
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
1679
|
-
const response = await fetch(apiUrl("/api/cli/doctor", baseUrlOf(parsed.options)), {
|
|
1680
|
-
headers: { Authorization: `Bearer ${credential.token}` },
|
|
1681
|
-
...request.init
|
|
1682
|
-
}).catch((error) => ({ networkError: error }));
|
|
1683
|
-
if ("networkError" in response) {
|
|
1684
|
-
data.network = {
|
|
1685
|
-
ok: false,
|
|
1686
|
-
code: "network_failed",
|
|
1687
|
-
hint: networkError(response.networkError).hint
|
|
1688
|
-
};
|
|
1689
|
-
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
1690
|
-
}
|
|
1691
|
-
data.network.ok = true;
|
|
1692
|
-
const body = await readJson(response);
|
|
1693
|
-
if (!response.ok) {
|
|
1694
|
-
const error = mapApiError(response.status, body, { authenticated: true });
|
|
1695
|
-
data.auth.code = error.code;
|
|
1696
|
-
data.auth.hint = error.hint;
|
|
1697
|
-
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
1698
|
-
}
|
|
1699
|
-
if (!body) throw new Error("Doctor response was not valid JSON.");
|
|
1700
|
-
data.auth.ok = body.auth?.ok ?? true;
|
|
1701
|
-
data.auth.email = body.user?.email ?? null;
|
|
1702
|
-
data.upload.checked = true;
|
|
1703
|
-
data.upload.ok = body.upload?.ok ?? false;
|
|
1704
|
-
if (!data.upload.ok) {
|
|
1705
|
-
data.upload.code = normalizeApiCode(body.upload?.code);
|
|
1706
|
-
data.upload.hint = uploadBlockedHint(data.upload.code);
|
|
1823
|
+
if (!SKILL_TOOLS.includes(trimmed)) return { error: validationError(`Unknown --tool value: ${trimmed}`, "Pass --tool codex, --tool claude, or --tool cursor.") };
|
|
1824
|
+
tools.push(trimmed);
|
|
1707
1825
|
}
|
|
1708
|
-
return
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
const cwd = process.cwd();
|
|
1713
|
-
const directory = project.directory;
|
|
1714
|
-
const localRaw = directory ? await readProjectConfigAtDirectory(directory, "local") : null;
|
|
1715
|
-
const sharedRaw = directory ? await readProjectConfigAtDirectory(directory, "shared") : null;
|
|
1826
|
+
if (raws.length > 0 && tools.length === 0) return { error: validationError("--tool has no value.", "Pass --tool codex, --tool claude, or --tool cursor.") };
|
|
1827
|
+
const unique = [...new Set(tools)];
|
|
1828
|
+
const auto = unique.includes("auto");
|
|
1829
|
+
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.") };
|
|
1716
1830
|
return {
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
global: {
|
|
1720
|
-
present: globalConfig !== null,
|
|
1721
|
-
default_profile: configString(globalConfig?.default_profile),
|
|
1722
|
-
profile_count: Object.keys(globalConfig?.profiles ?? {}).length
|
|
1723
|
-
},
|
|
1724
|
-
effective: effectiveDiagnostics(project, globalConfig)
|
|
1831
|
+
tools: unique.filter((tool) => tool !== "auto"),
|
|
1832
|
+
auto
|
|
1725
1833
|
};
|
|
1726
1834
|
}
|
|
1727
|
-
function
|
|
1728
|
-
const
|
|
1729
|
-
return {
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
default_profile: configString(raw?.default_profile),
|
|
1733
|
-
default_project_id: configString(raw?.default_project_id),
|
|
1734
|
-
...unsafeKey ? {
|
|
1735
|
-
code: "token_store_unsafe",
|
|
1736
|
-
hint: `Remove "${unsafeKey}" from ${path ?? "the working-directory config"} and run ${CLI_INVOCATION} login instead; the working-directory config must never hold secrets.`
|
|
1737
|
-
} : {}
|
|
1738
|
-
};
|
|
1835
|
+
function parseScope(value) {
|
|
1836
|
+
const trimmed = nonEmpty(value);
|
|
1837
|
+
if (trimmed === void 0) return { scope: void 0 };
|
|
1838
|
+
if (trimmed === "project" || trimmed === "user") return { scope: trimmed };
|
|
1839
|
+
return { error: validationError(`Unknown --scope value: ${trimmed}`, "Pass --scope project or --scope user.") };
|
|
1739
1840
|
}
|
|
1740
|
-
function
|
|
1741
|
-
const
|
|
1742
|
-
|
|
1743
|
-
const
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
const
|
|
1747
|
-
|
|
1748
|
-
const defaultProjectIdSource = projectProjectId ? project.kind === "local" ? "local" : "project" : "none";
|
|
1841
|
+
function parseFilters(parsed, options = {}) {
|
|
1842
|
+
const tools = parseTools(parsed.options.tool, options);
|
|
1843
|
+
if (tools.error) return { error: tools.error };
|
|
1844
|
+
const scope = parseScope(parsed.options.scope);
|
|
1845
|
+
if (scope.error) return { error: scope.error };
|
|
1846
|
+
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.") };
|
|
1847
|
+
const unsupported = scope.scope === void 0 ? void 0 : tools.tools.find((tool) => !TOOL_CONFIG[tool].scopes.includes(scope.scope));
|
|
1848
|
+
if (unsupported) return { error: validationError(`The ${unsupported} tool does not support --scope ${scope.scope}.`, `Use --tool ${unsupported} --scope project.`) };
|
|
1749
1849
|
return {
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
default_project_id: defaultProjectId,
|
|
1754
|
-
default_project_id_source: defaultProjectIdSource,
|
|
1755
|
-
default_project_id_path: defaultProjectIdSource === "local" || defaultProjectIdSource === "project" ? project.path : null
|
|
1850
|
+
tools: tools.tools,
|
|
1851
|
+
auto: tools.auto,
|
|
1852
|
+
scope: scope.scope
|
|
1756
1853
|
};
|
|
1757
1854
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
async function prepareUploadPayload(targetPath, fileStat, initialForm = new FormData()) {
|
|
1761
|
-
if (fileStat.isDirectory()) {
|
|
1762
|
-
let files;
|
|
1763
|
-
try {
|
|
1764
|
-
files = await collectDirectoryFiles(resolve(targetPath));
|
|
1765
|
-
} catch (error) {
|
|
1766
|
-
if (error instanceof CollectDirectoryFilesError) return { error: validationError(error.message, error.hint) };
|
|
1767
|
-
throw error;
|
|
1768
|
-
}
|
|
1769
|
-
if (files.length === 0) return { error: validationError("Directory has no publishable files.", "Add index.html or index.md and retry.") };
|
|
1770
|
-
for (const file of files) initialForm.append("file", await blobFor(file.path), file.relativePath);
|
|
1771
|
-
return { payload: {
|
|
1772
|
-
form: initialForm,
|
|
1773
|
-
kind: "static_site"
|
|
1774
|
-
} };
|
|
1775
|
-
}
|
|
1776
|
-
if (fileStat.isFile()) {
|
|
1777
|
-
initialForm.append("file", await blobFor(targetPath), basename(targetPath));
|
|
1778
|
-
return { payload: {
|
|
1779
|
-
form: initialForm,
|
|
1780
|
-
kind: artifactKindForFile(targetPath)
|
|
1781
|
-
} };
|
|
1782
|
-
}
|
|
1783
|
-
return { error: validationError("Path must be a file or directory.", "Pass a regular file or directory.") };
|
|
1855
|
+
function filteredTargets(tools, scope) {
|
|
1856
|
+
return allTargets().filter((target) => (tools.length === 0 || tools.includes(target.tool)) && (scope === void 0 || target.scope === scope));
|
|
1784
1857
|
}
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
const
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
const
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
...file,
|
|
1810
|
-
relativePath: relativePath.value
|
|
1811
|
-
});
|
|
1858
|
+
function detectionBase(scope) {
|
|
1859
|
+
return scope === "project" ? process.cwd() : homedir();
|
|
1860
|
+
}
|
|
1861
|
+
async function isToolDetected(tool, scope) {
|
|
1862
|
+
const base = detectionBase(scope);
|
|
1863
|
+
for (const dir of TOOL_CONFIG[tool].detectDirs) if ((await stat(join(base, dir)).catch(() => null))?.isDirectory()) return true;
|
|
1864
|
+
return false;
|
|
1865
|
+
}
|
|
1866
|
+
async function autoTargets(scope) {
|
|
1867
|
+
const targetScope = scope ?? "project";
|
|
1868
|
+
const autoOrder = [
|
|
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));
|
|
1876
|
+
}
|
|
1877
|
+
async function applyAction({ target, action, content }) {
|
|
1878
|
+
if (content !== void 0) {
|
|
1879
|
+
await mkdir(dirname(target.absolutePath), { recursive: true });
|
|
1880
|
+
await writeFile(target.absolutePath, content);
|
|
1881
|
+
return;
|
|
1812
1882
|
}
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
const files = [];
|
|
1817
|
-
for (const file of relativeFiles) {
|
|
1818
|
-
const targetPath = resolve(tempRoot, file.relativePath);
|
|
1819
|
-
files.push({
|
|
1820
|
-
...file,
|
|
1821
|
-
targetPath
|
|
1822
|
-
});
|
|
1883
|
+
if (action === "removed") {
|
|
1884
|
+
await rm(target.absolutePath, { force: true });
|
|
1885
|
+
await cleanupSkillDirs(target);
|
|
1823
1886
|
}
|
|
1824
|
-
return { value: {
|
|
1825
|
-
root,
|
|
1826
|
-
tempRoot,
|
|
1827
|
-
replaceExisting: Boolean(existing),
|
|
1828
|
-
files
|
|
1829
|
-
} };
|
|
1830
|
-
}
|
|
1831
|
-
function downloadRelativePath(path) {
|
|
1832
|
-
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.") };
|
|
1833
|
-
const segments = path.split("/").slice(1);
|
|
1834
|
-
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.") };
|
|
1835
|
-
return { value: segments.join("/") };
|
|
1836
1887
|
}
|
|
1837
|
-
function
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
if (
|
|
1888
|
+
async function cleanupSkillDirs(target) {
|
|
1889
|
+
let dir = dirname(target.absolutePath);
|
|
1890
|
+
for (const expected of TOOL_CONFIG[target.tool].pruneDirs) {
|
|
1891
|
+
if (basename(dir) !== expected) return;
|
|
1892
|
+
try {
|
|
1893
|
+
await rmdir(dir);
|
|
1894
|
+
} catch {
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
dir = dirname(dir);
|
|
1841
1898
|
}
|
|
1842
|
-
return { ok: true };
|
|
1843
1899
|
}
|
|
1844
|
-
function
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1900
|
+
async function finishActions(command, planned, dryRun, mode) {
|
|
1901
|
+
if (!dryRun) try {
|
|
1902
|
+
for (const item of planned) await applyAction(item);
|
|
1903
|
+
} catch (error) {
|
|
1904
|
+
writeFailure(command, unexpectedError(error), mode, 1);
|
|
1905
|
+
return;
|
|
1906
|
+
}
|
|
1907
|
+
return {
|
|
1908
|
+
dry_run: dryRun,
|
|
1909
|
+
targets: planned.map(({ target, action }) => ({
|
|
1910
|
+
tool: target.tool,
|
|
1911
|
+
scope: target.scope,
|
|
1912
|
+
path: target.path,
|
|
1913
|
+
action
|
|
1914
|
+
}))
|
|
1915
|
+
};
|
|
1854
1916
|
}
|
|
1855
|
-
function
|
|
1856
|
-
|
|
1917
|
+
async function runActions(command, planned, dryRun, mode) {
|
|
1918
|
+
const data = await finishActions(command, planned, dryRun, mode);
|
|
1919
|
+
if (data) writeSuccess(command, data, mode);
|
|
1857
1920
|
}
|
|
1858
|
-
async function
|
|
1859
|
-
|
|
1921
|
+
async function bundledOrFailure(command, mode) {
|
|
1922
|
+
try {
|
|
1923
|
+
return await loadBundledSkills();
|
|
1924
|
+
} catch (error) {
|
|
1925
|
+
writeFailure(command, unexpectedError(error), mode, 1);
|
|
1926
|
+
return;
|
|
1927
|
+
}
|
|
1860
1928
|
}
|
|
1861
|
-
function
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1929
|
+
async function runSkillsInstall(parsed, mode) {
|
|
1930
|
+
const command = "skills install";
|
|
1931
|
+
const filters = parseFilters(parsed);
|
|
1932
|
+
if (filters.error) return writeFailure(command, filters.error, mode, 1);
|
|
1933
|
+
const { tools } = filters;
|
|
1934
|
+
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);
|
|
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);
|
|
2063
|
+
}
|
|
2064
|
+
//#endregion
|
|
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;
|
|
2077
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to read.");
|
|
2078
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
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);
|
|
2104
|
+
const artifactId = target.artifactId;
|
|
2105
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2106
|
+
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2107
|
+
const request = await requestConfig(parsed.options);
|
|
2108
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2109
|
+
const result = await apiGet(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, parsed.options, request.init, { artifactTarget: true });
|
|
2110
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2111
|
+
const comments = Array.isArray(result.body?.comments) ? result.body.comments : [];
|
|
2112
|
+
writeSuccess(command, {
|
|
2113
|
+
artifact_id: artifactId,
|
|
2114
|
+
share_url: configString(result.body?.share_url),
|
|
2115
|
+
comments,
|
|
2116
|
+
has_more: result.body?.has_more === true
|
|
2117
|
+
}, mode);
|
|
2118
|
+
if (!mode.json && comments.length === 0) writeText("No comments yet.\n");
|
|
2119
|
+
}
|
|
2120
|
+
async function runCommentsPost(parsed, mode) {
|
|
2121
|
+
const command = "comments post";
|
|
2122
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
2123
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2124
|
+
const artifactId = target.artifactId;
|
|
2125
|
+
const body = parsed.options.body;
|
|
2126
|
+
if (!body || !body.trim()) return writeFailure(command, validationError("A comment body is required.", "Retry with --body <text>."), mode, 1);
|
|
2127
|
+
const replyTo = parsed.options.replyTo;
|
|
2128
|
+
const quote = parsed.options.quote;
|
|
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);
|
|
2131
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2132
|
+
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2133
|
+
const request = await requestConfig(parsed.options);
|
|
2134
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2135
|
+
const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, {
|
|
2136
|
+
body,
|
|
2137
|
+
reply_to: replyTo,
|
|
2138
|
+
quote,
|
|
2139
|
+
quote_before: parsed.options.quoteBefore,
|
|
2140
|
+
quote_after: parsed.options.quoteAfter
|
|
2141
|
+
}, parsed.options, request.init, { artifactTarget: true });
|
|
2142
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2143
|
+
const threadId = configString(result.body?.thread_id);
|
|
2144
|
+
if (!threadId) return writeFailure(command, serviceError("Comment was saved but the response had no thread id."), mode, 1);
|
|
2145
|
+
writeSuccess(command, {
|
|
2146
|
+
artifact_id: artifactId,
|
|
2147
|
+
share_url: configString(result.body?.share_url),
|
|
2148
|
+
thread_id: threadId,
|
|
2149
|
+
reply: result.body?.reply === true,
|
|
2150
|
+
thread: result.body?.thread ?? null
|
|
2151
|
+
}, mode);
|
|
2152
|
+
}
|
|
2153
|
+
async function runCommentsEdit(parsed, mode) {
|
|
2154
|
+
const command = "comments edit";
|
|
2155
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
2156
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2157
|
+
const messageId = requiredOption(parsed.options.messageId, "--message-id is required.", "Run comments list and retry with a listed message_id.");
|
|
2158
|
+
if (messageId.error) return writeFailure(command, messageId.error, mode, 1);
|
|
2159
|
+
const body = requiredOption(parsed.options.body, "--body is required.", "Pass --body <text> with the updated comment.");
|
|
2160
|
+
if (body.error) return writeFailure(command, body.error, mode, 1);
|
|
2161
|
+
const result = await postCommentAction(parsed, command, target.artifactId, {
|
|
2162
|
+
action: "edit",
|
|
2163
|
+
message_id: messageId.value,
|
|
2164
|
+
body: body.value
|
|
2165
|
+
}, mode);
|
|
2166
|
+
if (!result) return;
|
|
2167
|
+
const threadId = configString(result.thread_id);
|
|
2168
|
+
if (!threadId || result.thread === void 0) return writeFailure(command, serviceError("Comment was changed but the response had no thread."), mode, 1);
|
|
2169
|
+
writeSuccess(command, {
|
|
2170
|
+
artifact_id: target.artifactId,
|
|
2171
|
+
share_url: configString(result.share_url),
|
|
2172
|
+
thread_id: threadId,
|
|
2173
|
+
thread: result.thread
|
|
2174
|
+
}, mode);
|
|
2175
|
+
}
|
|
2176
|
+
async function runCommentsResolve(parsed, mode) {
|
|
2177
|
+
return await runCommentsStatus(parsed, mode, "comments resolve", "resolve");
|
|
2178
|
+
}
|
|
2179
|
+
async function runCommentsReopen(parsed, mode) {
|
|
2180
|
+
return await runCommentsStatus(parsed, mode, "comments reopen", "reopen");
|
|
2181
|
+
}
|
|
2182
|
+
async function runCommentsDelete(parsed, mode) {
|
|
2183
|
+
const command = "comments delete";
|
|
2184
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
2185
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2186
|
+
const threadId = requiredOption(parsed.options.threadId, "--thread-id is required.", "Run comments list and retry with a listed thread_id.");
|
|
2187
|
+
if (threadId.error) return writeFailure(command, threadId.error, mode, 1);
|
|
2188
|
+
const payload = {
|
|
2189
|
+
action: "delete",
|
|
2190
|
+
thread_id: threadId.value
|
|
2191
|
+
};
|
|
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
|
+
}
|
|
2209
|
+
async function runCommentsStatus(parsed, mode, command, action) {
|
|
2210
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL.");
|
|
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);
|
|
2227
|
+
}
|
|
2228
|
+
async function postCommentAction(parsed, command, artifactId, payload, mode) {
|
|
2229
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2230
|
+
if (!credential.ok) {
|
|
2231
|
+
writeFailure(command, credential.error, mode, 1);
|
|
2232
|
+
return null;
|
|
2233
|
+
}
|
|
2234
|
+
const request = await requestConfig(parsed.options);
|
|
2235
|
+
if (request.error) {
|
|
2236
|
+
writeFailure(command, request.error, mode, 1);
|
|
2237
|
+
return null;
|
|
2238
|
+
}
|
|
2239
|
+
const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, payload, parsed.options, request.init, { artifactTarget: true });
|
|
2240
|
+
if (result.error) {
|
|
2241
|
+
writeFailure(command, result.error, mode, 1);
|
|
2242
|
+
return null;
|
|
2243
|
+
}
|
|
2244
|
+
if (result.body === null) {
|
|
2245
|
+
writeFailure(command, serviceError("Comment was changed but the response was empty."), mode, 1);
|
|
2246
|
+
return null;
|
|
2247
|
+
}
|
|
2248
|
+
return result.body;
|
|
2249
|
+
}
|
|
2250
|
+
function requiredOption(value, message, hint) {
|
|
2251
|
+
if (!value || !value.trim()) return { error: validationError(message, hint) };
|
|
2252
|
+
return { value: value.trim() };
|
|
2253
|
+
}
|
|
2254
|
+
//#endregion
|
|
2255
|
+
//#region src/command-runners/delete.ts
|
|
2256
|
+
async function runDelete(parsed, mode) {
|
|
2257
|
+
const command = "delete";
|
|
2258
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to delete.");
|
|
2259
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2260
|
+
const artifactId = target.artifactId;
|
|
2261
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2262
|
+
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2263
|
+
const request = await requestConfig(parsed.options);
|
|
2264
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2265
|
+
const result = await apiDelete(`/api/cli/artifacts/${encodeURIComponent(artifactId)}`, credential.token, parsed.options, request.init, {
|
|
2266
|
+
authenticated: true,
|
|
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);
|
|
2273
|
+
}
|
|
2274
|
+
//#endregion
|
|
2275
|
+
//#region src/command-runners/doctor.ts
|
|
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";
|
|
2280
|
+
}
|
|
2281
|
+
function resolveDoctorNextCommand(data) {
|
|
2282
|
+
if (data.config.local.code === "token_store_unsafe") {
|
|
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;
|
|
2297
|
+
}
|
|
2298
|
+
function authRecovery(data, nextCommand) {
|
|
2299
|
+
const loginCommand = nextCommand?.startsWith(LOGIN_COMMAND) === true ? nextCommand : data.auth.profile ? `${LOGIN_COMMAND} --profile ${data.auth.profile}` : LOGIN_COMMAND;
|
|
2300
|
+
return authRecoveryDetails(data.base_url, loginCommand);
|
|
2301
|
+
}
|
|
2302
|
+
function doctorDataWithNextCommand(data) {
|
|
2303
|
+
const nextCommand = resolveDoctorNextCommand(data);
|
|
2304
|
+
const next = {
|
|
2305
|
+
...data,
|
|
2306
|
+
next_command: nextCommand
|
|
2307
|
+
};
|
|
2308
|
+
if (next.auth.code === "auth_required") next.auth = {
|
|
2309
|
+
...next.auth,
|
|
2310
|
+
recovery: authRecovery(next, nextCommand)
|
|
2311
|
+
};
|
|
2312
|
+
return next;
|
|
2313
|
+
}
|
|
2314
|
+
async function runDoctor(parsed, mode) {
|
|
2315
|
+
const command = "doctor";
|
|
2316
|
+
const project = await resolveProjectConfig();
|
|
2317
|
+
const credential = await resolveCredential(parsed.options, project);
|
|
2318
|
+
const destination = resolveDestination(parsed.options, project.config);
|
|
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);
|
|
2363
|
+
}
|
|
2364
|
+
data.network.ok = true;
|
|
2365
|
+
const body = await readJson(response);
|
|
2366
|
+
if (!response.ok) {
|
|
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);
|
|
2371
|
+
}
|
|
2372
|
+
if (!body) throw new Error("Doctor response was not valid JSON.");
|
|
2373
|
+
data.auth.ok = body.auth?.ok ?? true;
|
|
2374
|
+
data.auth.email = body.user?.email ?? null;
|
|
2375
|
+
data.upload.checked = true;
|
|
2376
|
+
data.upload.ok = body.upload?.ok ?? false;
|
|
2377
|
+
if (!data.upload.ok) {
|
|
2378
|
+
data.upload.code = normalizeApiCode(body.upload?.code);
|
|
2379
|
+
data.upload.hint = uploadBlockedHint(data.upload.code);
|
|
2380
|
+
}
|
|
2381
|
+
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
2382
|
+
}
|
|
2383
|
+
async function configDiagnostics(project) {
|
|
2384
|
+
const globalConfig = await readGlobalConfig();
|
|
2385
|
+
const cwd = process.cwd();
|
|
2386
|
+
const directory = project.directory;
|
|
2387
|
+
const localRaw = directory ? await readProjectConfigAtDirectory(directory, "local") : null;
|
|
2388
|
+
const sharedRaw = directory ? await readProjectConfigAtDirectory(directory, "shared") : null;
|
|
2389
|
+
return {
|
|
2390
|
+
local: fileDiagnostics(localRaw, directory ? relativeProjectConfigPath(cwd, directory, PROJECT_CONFIG_LOCAL_PATH) : null),
|
|
2391
|
+
project: fileDiagnostics(sharedRaw, directory ? relativeProjectConfigPath(cwd, directory, PROJECT_CONFIG_PATH) : null),
|
|
2392
|
+
global: {
|
|
2393
|
+
present: globalConfig !== null,
|
|
2394
|
+
default_profile: configString(globalConfig?.default_profile),
|
|
2395
|
+
profile_count: Object.keys(globalConfig?.profiles ?? {}).length
|
|
2396
|
+
},
|
|
2397
|
+
effective: effectiveDiagnostics(project, globalConfig)
|
|
2398
|
+
};
|
|
2399
|
+
}
|
|
2400
|
+
function fileDiagnostics(raw, path) {
|
|
2401
|
+
const unsafeKey = Object.keys(raw ?? {}).find((key) => key.toLowerCase().includes("token"));
|
|
2402
|
+
return {
|
|
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
|
+
};
|
|
2412
|
+
}
|
|
2413
|
+
function effectiveDiagnostics(project, globalConfig) {
|
|
2414
|
+
const projectProfile = configString(project.config?.default_profile);
|
|
2415
|
+
const projectProjectId = configString(project.config?.default_project_id);
|
|
2416
|
+
const globalProfile = configString(globalConfig?.default_profile);
|
|
2417
|
+
const defaultProfile = projectProfile ?? globalProfile;
|
|
2418
|
+
const defaultProfileSource = projectProfile ? project.kind === "local" ? "local" : "project" : globalProfile ? "global" : "none";
|
|
2419
|
+
const defaultProfilePath = defaultProfileSource === "local" || defaultProfileSource === "project" ? project.path : null;
|
|
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
|
+
};
|
|
2430
|
+
}
|
|
2431
|
+
//#endregion
|
|
2432
|
+
//#region src/files.ts
|
|
2433
|
+
async function prepareUploadPayload(targetPath, fileStat, initialForm = new FormData()) {
|
|
2434
|
+
if (fileStat.isDirectory()) {
|
|
2435
|
+
let files;
|
|
2436
|
+
try {
|
|
2437
|
+
files = await collectDirectoryFiles(resolve(targetPath));
|
|
2438
|
+
} catch (error) {
|
|
2439
|
+
if (error instanceof CollectDirectoryFilesError) return { error: validationError(error.message, error.hint) };
|
|
2440
|
+
throw error;
|
|
2441
|
+
}
|
|
2442
|
+
if (files.length === 0) return { error: validationError("Directory has no publishable files.", "Add index.html or index.md and retry.") };
|
|
2443
|
+
for (const file of files) initialForm.append("file", await blobFor(file.path), file.relativePath);
|
|
2444
|
+
return { payload: {
|
|
2445
|
+
form: initialForm,
|
|
2446
|
+
kind: "static_site"
|
|
2447
|
+
} };
|
|
2448
|
+
}
|
|
2449
|
+
if (fileStat.isFile()) {
|
|
2450
|
+
initialForm.append("file", await blobFor(targetPath), basename(targetPath));
|
|
2451
|
+
return { payload: {
|
|
2452
|
+
form: initialForm,
|
|
2453
|
+
kind: artifactKindForFile(targetPath)
|
|
2454
|
+
} };
|
|
2455
|
+
}
|
|
2456
|
+
return { error: validationError("Path must be a file or directory.", "Pass a regular file or directory.") };
|
|
2457
|
+
}
|
|
2458
|
+
async function prepareDownloadPlan(manifest, outputPath, force) {
|
|
2459
|
+
if (manifest.files.length === 0) return { error: validationError("Download manifest contains no files.", "Check the artifact and retry.") };
|
|
2460
|
+
if (outputPath === "") return { error: validationError("--output requires a non-empty directory.", "Pass --output <path> or omit --output to use the artifact ID.") };
|
|
2461
|
+
const root = resolve(outputPath);
|
|
2462
|
+
const existing = await lstat(root).catch(() => null);
|
|
2463
|
+
if (existing?.isSymbolicLink()) return { error: validationError("Output path must not be a symbolic link.", "Choose a regular directory path and retry.") };
|
|
2464
|
+
if (existing && !force) return { error: cliError({
|
|
2465
|
+
code: "output_exists",
|
|
2466
|
+
message: "Output path already exists.",
|
|
2467
|
+
why: "Download will not write into an existing path unless --force is set.",
|
|
2468
|
+
hint: "Choose a different --output path or retry with --force.",
|
|
2469
|
+
agentRecoverable: true,
|
|
2470
|
+
requiresHuman: false,
|
|
2471
|
+
recovery: { kind: "change_input" }
|
|
2472
|
+
}) };
|
|
2473
|
+
if (existing && !existing.isDirectory()) return { error: validationError("Output path is not a directory.", "Choose a directory path or remove the existing file.") };
|
|
2474
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2475
|
+
const relativeFiles = [];
|
|
2476
|
+
for (const file of manifest.files) {
|
|
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
|
|
2484
|
+
});
|
|
2485
|
+
}
|
|
2486
|
+
const parent = dirname(root);
|
|
2487
|
+
await mkdir(parent, { recursive: true });
|
|
2488
|
+
const tempRoot = await mkdtemp(join(parent, `.${basename(root)}.tmp-`));
|
|
2489
|
+
const files = [];
|
|
2490
|
+
for (const file of relativeFiles) {
|
|
2491
|
+
const targetPath = resolve(tempRoot, file.relativePath);
|
|
2492
|
+
files.push({
|
|
2493
|
+
...file,
|
|
2494
|
+
targetPath
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
return { value: {
|
|
2498
|
+
root,
|
|
2499
|
+
tempRoot,
|
|
2500
|
+
replaceExisting: Boolean(existing),
|
|
2501
|
+
files
|
|
2502
|
+
} };
|
|
2503
|
+
}
|
|
2504
|
+
function downloadRelativePath(path) {
|
|
2505
|
+
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.") };
|
|
2506
|
+
const segments = path.split("/").slice(1);
|
|
2507
|
+
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.") };
|
|
2508
|
+
return { value: segments.join("/") };
|
|
2509
|
+
}
|
|
2510
|
+
function verifyDownloadedBytes(file, bytes) {
|
|
2511
|
+
if (bytes.byteLength !== file.size_bytes) return { error: downloadIntegrityError(file.path, "size mismatch") };
|
|
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 };
|
|
2516
|
+
}
|
|
2517
|
+
function downloadIntegrityError(path, reason) {
|
|
2518
|
+
return cliError({
|
|
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
|
+
});
|
|
2527
|
+
}
|
|
2528
|
+
function backupPathFor(root) {
|
|
2529
|
+
return join(dirname(root), `.${basename(root)}.old-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`);
|
|
2530
|
+
}
|
|
2531
|
+
async function pathExists(path) {
|
|
2532
|
+
return Boolean(await lstat(path).catch(() => null));
|
|
2533
|
+
}
|
|
2534
|
+
function downloadFileSystemError(error) {
|
|
2535
|
+
return cliError({
|
|
2536
|
+
code: "download_failed",
|
|
2537
|
+
message: "Could not write downloaded files.",
|
|
2538
|
+
why: error instanceof Error ? error.message : "The local filesystem rejected a download operation.",
|
|
1866
2539
|
hint: "Check --output permissions and available disk space, then retry.",
|
|
1867
2540
|
agentRecoverable: true,
|
|
1868
2541
|
requiresHuman: false,
|
|
@@ -2291,7 +2964,105 @@ async function runDownload(parsed, mode, isRetry = false) {
|
|
|
2291
2964
|
count: plan.value.files.length,
|
|
2292
2965
|
total_size_bytes: body.total_size_bytes
|
|
2293
2966
|
}
|
|
2294
|
-
}, mode);
|
|
2967
|
+
}, mode);
|
|
2968
|
+
}
|
|
2969
|
+
//#endregion
|
|
2970
|
+
//#region src/command-runners/edit.ts
|
|
2971
|
+
async function runEdit(parsed, mode) {
|
|
2972
|
+
const command = "edit";
|
|
2973
|
+
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to edit.");
|
|
2974
|
+
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2975
|
+
const payload = buildEditPayload(parsed);
|
|
2976
|
+
if (payload.error) return writeFailure(command, payload.error, mode, 1);
|
|
2977
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2978
|
+
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2979
|
+
const request = await requestConfig(parsed.options);
|
|
2980
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2981
|
+
const result = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/edit`, credential.token, payload.body, parsed.options, request.init, {
|
|
2982
|
+
artifactTarget: true,
|
|
2983
|
+
editSettings: true
|
|
2984
|
+
});
|
|
2985
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2986
|
+
const data = parseEditData(result.body);
|
|
2987
|
+
if (!data) return writeFailure(command, serviceError("Edit succeeded but the response did not include edit data."), mode, 1);
|
|
2988
|
+
writeSuccess(command, data, mode);
|
|
2989
|
+
}
|
|
2990
|
+
function buildEditPayload(parsed) {
|
|
2991
|
+
const body = {};
|
|
2992
|
+
let hasChange = false;
|
|
2993
|
+
if (parsed.options.title !== void 0) {
|
|
2994
|
+
body.title = parsed.options.title;
|
|
2995
|
+
hasChange = true;
|
|
2996
|
+
}
|
|
2997
|
+
if (parsed.options.visibility !== void 0) {
|
|
2998
|
+
const visibility = parsed.options.visibility.trim();
|
|
2999
|
+
if (visibility !== "private" && visibility !== "workspace") return { error: validationError("--visibility must be private or workspace.", "Retry with --visibility private or --visibility workspace.") };
|
|
3000
|
+
body.visibility = visibility;
|
|
3001
|
+
hasChange = true;
|
|
3002
|
+
}
|
|
3003
|
+
const addEmails = normalizedEmailOptions$1(parsed.options.grantEmail);
|
|
3004
|
+
if (addEmails.error) return { error: addEmails.error };
|
|
3005
|
+
if (parsed.options.grantEmail !== void 0) {
|
|
3006
|
+
body.add_emails = addEmails.values;
|
|
3007
|
+
hasChange = true;
|
|
3008
|
+
}
|
|
3009
|
+
const removeEmails = normalizedEmailOptions$1(parsed.options.revokeEmail);
|
|
3010
|
+
if (removeEmails.error) return { error: removeEmails.error };
|
|
3011
|
+
if (parsed.options.revokeEmail !== void 0) {
|
|
3012
|
+
body.remove_emails = removeEmails.values;
|
|
3013
|
+
hasChange = true;
|
|
3014
|
+
}
|
|
3015
|
+
if (hasProjectIdHomeConflict(parsed.options)) return { error: validationError("Edit destination is conflicting.", "Choose either --project-id <id> or --home.", "destination_conflict") };
|
|
3016
|
+
if (parsed.options.home) {
|
|
3017
|
+
body.destination = "home";
|
|
3018
|
+
hasChange = true;
|
|
3019
|
+
} else if (parsed.options.projectId !== void 0) {
|
|
3020
|
+
const projectId = parsed.options.projectId.trim();
|
|
3021
|
+
if (!projectId) return { error: validationError("--project-id must not be blank.", "Retry with an active project id from projects list, or use --home.", "invalid_destination") };
|
|
3022
|
+
body.destination = { project_id: projectId };
|
|
3023
|
+
hasChange = true;
|
|
3024
|
+
}
|
|
3025
|
+
if (!hasChange) return { error: validationError("At least one edit option is required.", "Pass --title, --visibility, --grant-email, --revoke-email, --project-id, or --home.") };
|
|
3026
|
+
return { body };
|
|
3027
|
+
}
|
|
3028
|
+
function normalizedEmailOptions$1(value) {
|
|
3029
|
+
const values = arrayOption(value).map((email) => email.trim()).filter(Boolean);
|
|
3030
|
+
if (value !== void 0 && values.length === 0) return { error: validationError("Email option must not be blank.", "Pass a non-empty email address.") };
|
|
3031
|
+
return { values };
|
|
3032
|
+
}
|
|
3033
|
+
function parseEditData(body) {
|
|
3034
|
+
if (!isRecord(body)) return null;
|
|
3035
|
+
const artifact = body.artifact;
|
|
3036
|
+
const destination = body.destination;
|
|
3037
|
+
const share = body.share;
|
|
3038
|
+
if (!isRecord(artifact) || !isRecord(destination) || !isRecord(share)) return null;
|
|
3039
|
+
if (typeof artifact.id !== "string" || typeof body.title !== "string" || typeof destination.type !== "string" || typeof share.visibility !== "string") return null;
|
|
3040
|
+
const base = {
|
|
3041
|
+
artifact: {
|
|
3042
|
+
id: artifact.id,
|
|
3043
|
+
url: typeof artifact.url === "string" ? artifact.url : null
|
|
3044
|
+
},
|
|
3045
|
+
title: body.title,
|
|
3046
|
+
share: { visibility: share.visibility }
|
|
3047
|
+
};
|
|
3048
|
+
if (destination.type === "project") {
|
|
3049
|
+
if (typeof destination.project_id !== "string") return null;
|
|
3050
|
+
return {
|
|
3051
|
+
...base,
|
|
3052
|
+
destination: {
|
|
3053
|
+
type: "project",
|
|
3054
|
+
project_id: destination.project_id
|
|
3055
|
+
}
|
|
3056
|
+
};
|
|
3057
|
+
}
|
|
3058
|
+
if (destination.type === "home" && destination.project_id === null) return {
|
|
3059
|
+
...base,
|
|
3060
|
+
destination: {
|
|
3061
|
+
type: "home",
|
|
3062
|
+
project_id: null
|
|
3063
|
+
}
|
|
3064
|
+
};
|
|
3065
|
+
return null;
|
|
2295
3066
|
}
|
|
2296
3067
|
//#endregion
|
|
2297
3068
|
//#region src/git-exclude.ts
|
|
@@ -2399,10 +3170,11 @@ async function runMove(parsed, mode) {
|
|
|
2399
3170
|
const command = "move";
|
|
2400
3171
|
const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to move.");
|
|
2401
3172
|
if (target.error) return writeFailure(command, target.error, mode, 1);
|
|
2402
|
-
|
|
3173
|
+
parsed.options.projectId;
|
|
2403
3174
|
const projectId = parsed.options.projectId?.trim() ?? "";
|
|
2404
3175
|
const home = Boolean(parsed.options.home);
|
|
2405
|
-
|
|
3176
|
+
const destinationConflict = hasProjectIdHomeConflict(parsed.options);
|
|
3177
|
+
if (destinationConflict || !projectId && !home) return writeFailure(command, validationError("Move destination is required.", "Choose exactly one destination: --project-id <id> or --home.", destinationConflict ? "destination_conflict" : "invalid_destination"), mode, 1);
|
|
2406
3178
|
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2407
3179
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2408
3180
|
const request = await requestConfig(parsed.options);
|
|
@@ -2600,414 +3372,234 @@ async function runProjectsCreate(parsed, mode) {
|
|
|
2600
3372
|
next_command: `npx --yes @artifactshare/cli publish <path> --project-id ${id} --json`
|
|
2601
3373
|
}, mode);
|
|
2602
3374
|
}
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
const
|
|
2606
|
-
|
|
2607
|
-
const
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
if ("key" in parsed.options) {
|
|
2612
|
-
publishKey = (typeof parsed.options.key === "string" ? parsed.options.key : "").trim();
|
|
2613
|
-
if (publishKey.length === 0 || publishKey.length > MAX_PUBLISH_KEY_LENGTH) return writeFailure(command, validationError(`--key must be 1-${MAX_PUBLISH_KEY_LENGTH} characters after trimming.`, "Pass a short stable identifier, like a job name or PR number."), mode, 1);
|
|
2614
|
-
}
|
|
2615
|
-
const project = await resolveProjectConfig();
|
|
2616
|
-
const credential = await resolveCredential(parsed.options, project);
|
|
2617
|
-
if (!credential.ok) return handleCredentialFailure(command, credential, parsed.options, mode, () => runPublish(parsed, mode, true), isRetry);
|
|
2618
|
-
const baseUrl = baseUrlOf(parsed.options);
|
|
2619
|
-
const hasProjectFlag = "project" in parsed.options;
|
|
2620
|
-
let destinationOptions = parsed.options;
|
|
2621
|
-
let projectName;
|
|
2622
|
-
if (hasProjectFlag) {
|
|
2623
|
-
projectName = nonEmpty(typeof parsed.options.project === "string" ? parsed.options.project : "");
|
|
2624
|
-
if (!projectName) return writeFailure(command, validationError("--project requires a value.", "Pass --project <name> and retry."), mode, 1);
|
|
2625
|
-
const conflict = destinationConflictError(parsed.options);
|
|
2626
|
-
if (conflict) return writeFailure(command, conflict, mode, 1);
|
|
2627
|
-
} else {
|
|
2628
|
-
const earlyDestination = resolveDestination(parsed.options, project.config);
|
|
2629
|
-
if (earlyDestination.error) return writeFailure(command, earlyDestination.error, mode, 1);
|
|
2630
|
-
}
|
|
2631
|
-
const fileStat = await stat(targetPath).catch(() => null);
|
|
2632
|
-
if (!fileStat) return writeFailure(command, validationError("Path was not found.", `Check the path and retry: ${targetPath}`), mode, 1);
|
|
2633
|
-
const request = await requestConfig(parsed.options);
|
|
2634
|
-
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2635
|
-
if (hasProjectFlag && projectName) {
|
|
2636
|
-
const resolved = await resolveProjectIdByName(projectName, credential.token, parsed.options, request.init);
|
|
2637
|
-
if (resolved.error) return writeFailure(command, resolved.error, mode, 1);
|
|
2638
|
-
const { project: _project, ...rest } = parsed.options;
|
|
2639
|
-
destinationOptions = {
|
|
2640
|
-
...rest,
|
|
2641
|
-
projectId: resolved.projectId
|
|
2642
|
-
};
|
|
2643
|
-
}
|
|
2644
|
-
const destination = resolveDestination(destinationOptions, project.config);
|
|
2645
|
-
if (destination.error) return writeFailure(command, destination.error, mode, 1);
|
|
2646
|
-
const initialForm = new FormData();
|
|
2647
|
-
const grantEmails = arrayOption(parsed.options.grantEmail);
|
|
2648
|
-
const requestedVisibility = parsed.options.visibility ?? (destination.containerId && grantEmails.length === 0 ? "project" : "private");
|
|
2649
|
-
initialForm.set("visibility", requestedVisibility);
|
|
2650
|
-
for (const email of grantEmails) initialForm.append("grant_email", email);
|
|
2651
|
-
if (destination.containerId) initialForm.set("container_id", destination.containerId);
|
|
2652
|
-
const uploadUrl = apiUrl("/api/shareables/uploads", baseUrl);
|
|
2653
|
-
if (publishKey !== null) uploadUrl.searchParams.set("publish_key", publishKey);
|
|
2654
|
-
const upload = await prepareUploadPayload(targetPath, fileStat, initialForm);
|
|
2655
|
-
if (upload.error) return writeFailure(command, upload.error, mode, 1);
|
|
2656
|
-
if (upload.payload.kind === "static_site") {
|
|
2657
|
-
uploadUrl.searchParams.set("artifact_kind", "static_site");
|
|
2658
|
-
if (destination.containerId) uploadUrl.searchParams.set("container_id", destination.containerId);
|
|
2659
|
-
}
|
|
2660
|
-
const response = await fetch(uploadUrl, {
|
|
2661
|
-
method: "POST",
|
|
2662
|
-
headers: { Authorization: `Bearer ${credential.token}` },
|
|
2663
|
-
body: upload.payload.form,
|
|
2664
|
-
...request.init
|
|
2665
|
-
}).catch((error) => ({ networkError: error }));
|
|
2666
|
-
if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
|
|
2667
|
-
const body = await readJson(response);
|
|
2668
|
-
if (!response.ok) return writeFailure(command, mapApiError(response.status, body, { authenticated: true }), mode, 1);
|
|
2669
|
-
const id = body?.id ?? null;
|
|
2670
|
-
return writeSuccess(command, {
|
|
2671
|
-
artifact: {
|
|
2672
|
-
id,
|
|
2673
|
-
url: body?.shareUrl ?? (id ? `${baseUrl.replace(/\/$/, "")}/a/${id}` : null),
|
|
2674
|
-
kind: body?.artifactKind ?? upload.payload.kind
|
|
2675
|
-
},
|
|
2676
|
-
version: { id: body?.versionId ?? null },
|
|
2677
|
-
result: { created: body?.created ?? true },
|
|
2678
|
-
...publishKey !== null ? { key: publishKey } : {},
|
|
2679
|
-
destination: destination.containerId ? {
|
|
2680
|
-
type: "project",
|
|
2681
|
-
project_id: destination.containerId
|
|
2682
|
-
} : { type: "home" },
|
|
2683
|
-
share: {
|
|
2684
|
-
visibility: body?.visibility ?? requestedVisibility,
|
|
2685
|
-
grant_emails: grantEmails
|
|
2686
|
-
}
|
|
2687
|
-
}, mode);
|
|
2688
|
-
}
|
|
2689
|
-
async function resolveProjectIdByName(projectName, token, options, init) {
|
|
2690
|
-
const result = await fetchProjects(token, options, init);
|
|
2691
|
-
if (result.error) return { error: result.error };
|
|
2692
|
-
const candidates = result.projects.flatMap((project) => {
|
|
2693
|
-
if (project.name !== projectName) return [];
|
|
2694
|
-
return [{
|
|
2695
|
-
project_id: project.id,
|
|
2696
|
-
name: project.name,
|
|
2697
|
-
updated_at: project.updated_at
|
|
2698
|
-
}];
|
|
2699
|
-
});
|
|
2700
|
-
if (candidates.length === 0) return { error: projectNotFoundByNameError() };
|
|
2701
|
-
if (candidates.length > 1) return { error: projectAmbiguousError(candidates) };
|
|
2702
|
-
return { projectId: candidates[0].project_id };
|
|
2703
|
-
}
|
|
2704
|
-
//#endregion
|
|
2705
|
-
//#region src/command-runners/request-access.ts
|
|
2706
|
-
const NOTE_MAX = 2e3;
|
|
2707
|
-
async function runRequestAccess(parsed, mode) {
|
|
2708
|
-
const command = "request-access";
|
|
2709
|
-
const note = parsed.options.note;
|
|
2710
|
-
if (note !== void 0 && note.length > NOTE_MAX) return writeFailure(command, validationError(`A note can be at most ${NOTE_MAX} characters.`, "Shorten --note and retry."), mode, 1);
|
|
2711
|
-
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
3375
|
+
async function runProjectsEdit(parsed, mode) {
|
|
3376
|
+
const command = "projects edit";
|
|
3377
|
+
const projectId = parsed.positionals[0]?.trim();
|
|
3378
|
+
if (!projectId) return writeFailure(command, validationError("Project id is required.", "Pass a project id: projects edit <id>."), mode, 1);
|
|
3379
|
+
const payload = buildProjectsEditPayload(parsed);
|
|
3380
|
+
if (payload.error) return writeFailure(command, payload.error, mode, 1);
|
|
3381
|
+
const projectConfig = await resolveProjectConfig();
|
|
3382
|
+
const credential = await resolveCredential(parsed.options, projectConfig);
|
|
2712
3383
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2713
3384
|
const request = await requestConfig(parsed.options);
|
|
2714
3385
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2715
|
-
const result = await apiPost(
|
|
3386
|
+
const result = await apiPost(`/api/cli/projects/${encodeURIComponent(projectId)}`, credential.token, payload.body, parsed.options, request.init, { projectTarget: true });
|
|
2716
3387
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2717
|
-
const
|
|
2718
|
-
|
|
2719
|
-
requested: body?.requested === true,
|
|
2720
|
-
already_enabled: body?.already_enabled === true,
|
|
2721
|
-
status: typeof body?.status === "string" ? body.status : null,
|
|
2722
|
-
created: body?.created === true,
|
|
2723
|
-
requires_operator_action: body?.requires_operator_action === true,
|
|
2724
|
-
message: typeof body?.message === "string" ? body.message : ""
|
|
2725
|
-
};
|
|
3388
|
+
const data = parseProjectsEditData(result.body);
|
|
3389
|
+
if (!data) return writeFailure(command, serviceError("Project edit succeeded but the response did not include project data."), mode, 1);
|
|
2726
3390
|
writeSuccess(command, data, mode);
|
|
2727
|
-
if (!mode.json && data.message) writeText(`${data.message}\n`);
|
|
2728
|
-
}
|
|
2729
|
-
//#endregion
|
|
2730
|
-
//#region src/command-runners/resolve.ts
|
|
2731
|
-
async function runResolve(parsed, mode) {
|
|
2732
|
-
const command = "resolve";
|
|
2733
|
-
const value = parsed.positionals[0]?.trim();
|
|
2734
|
-
if (!value) return writeFailure(command, validationError("Resolve value is required.", "Pass a URL, ID, title, or project name to resolve."), mode, 1);
|
|
2735
|
-
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
2736
|
-
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2737
|
-
const request = await requestConfig(parsed.options);
|
|
2738
|
-
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2739
|
-
const url = apiUrl("/api/cli/resolve", baseUrlOf(parsed.options));
|
|
2740
|
-
url.searchParams.set("q", value);
|
|
2741
|
-
const response = await fetch(url, {
|
|
2742
|
-
headers: { Authorization: `Bearer ${credential.token}` },
|
|
2743
|
-
...request.init
|
|
2744
|
-
}).catch((error) => ({ networkError: error }));
|
|
2745
|
-
if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
|
|
2746
|
-
const body = await readJson(response);
|
|
2747
|
-
if (!response.ok) return writeFailure(command, mapApiError(response.status, body, { authenticated: true }), mode, 1);
|
|
2748
|
-
if (!resolveSuccessFields(body)) return writeFailure(command, serviceError("Resolve succeeded but the response did not include query, candidates, and has_more."), mode, 1);
|
|
2749
|
-
return writeSuccess(command, body, mode);
|
|
2750
3391
|
}
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
const TOOL_CONFIG = {
|
|
2760
|
-
codex: {
|
|
2761
|
-
relativePath: join(".agents", SKILL_FILE_PATH),
|
|
2762
|
-
scopes: ["project", "user"],
|
|
2763
|
-
detectDirs: [".codex", ".agents"],
|
|
2764
|
-
bundledFile: "SKILL.md",
|
|
2765
|
-
pruneDirs: ["artifactshare", "skills"]
|
|
2766
|
-
},
|
|
2767
|
-
claude: {
|
|
2768
|
-
relativePath: join(".claude", SKILL_FILE_PATH),
|
|
2769
|
-
scopes: ["project", "user"],
|
|
2770
|
-
detectDirs: [".claude"],
|
|
2771
|
-
bundledFile: "SKILL.md",
|
|
2772
|
-
pruneDirs: ["artifactshare", "skills"]
|
|
2773
|
-
},
|
|
2774
|
-
cursor: {
|
|
2775
|
-
relativePath: join(".cursor", "rules", "artifactshare.mdc"),
|
|
2776
|
-
scopes: ["project"],
|
|
2777
|
-
detectDirs: [".cursor"],
|
|
2778
|
-
bundledFile: "artifactshare.mdc",
|
|
2779
|
-
pruneDirs: []
|
|
3392
|
+
function buildProjectsEditPayload(parsed) {
|
|
3393
|
+
const body = {};
|
|
3394
|
+
let hasChange = false;
|
|
3395
|
+
if (parsed.options.name !== void 0) {
|
|
3396
|
+
const name = parsed.options.name.trim();
|
|
3397
|
+
if (!name) return { error: validationError("--name must not be blank.", "Retry with a non-empty project name.") };
|
|
3398
|
+
body.name = name;
|
|
3399
|
+
hasChange = true;
|
|
2780
3400
|
}
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
const path = scope === "project" ? relative : join(homedir(), relative);
|
|
2785
|
-
return {
|
|
2786
|
-
tool,
|
|
2787
|
-
scope,
|
|
2788
|
-
path,
|
|
2789
|
-
absolutePath: resolve(path)
|
|
2790
|
-
};
|
|
2791
|
-
}
|
|
2792
|
-
function allTargets() {
|
|
2793
|
-
return SKILL_TOOLS.flatMap((tool) => TOOL_CONFIG[tool].scopes.map((scope) => skillTarget(tool, scope)));
|
|
2794
|
-
}
|
|
2795
|
-
function managedState(content) {
|
|
2796
|
-
if (content === null) return { kind: "missing" };
|
|
2797
|
-
if (!content.includes("artifactshare-skill")) return { kind: "unmanaged" };
|
|
2798
|
-
const block = content.match(/<!--\s*artifactshare-skill([\s\S]*?)-->/)?.[1];
|
|
2799
|
-
const version = block?.match(/(?:^|\n)\s*version:\s*(\d+)\s*(?:\n|$)/)?.[1];
|
|
2800
|
-
const managed = block !== void 0 && /(?:^|\n)\s*managed:\s*true\s*(?:\n|$)/.test(block);
|
|
2801
|
-
if (version === void 0 || !managed) return { kind: "broken" };
|
|
2802
|
-
return {
|
|
2803
|
-
kind: "managed",
|
|
2804
|
-
version: Number(version)
|
|
2805
|
-
};
|
|
2806
|
-
}
|
|
2807
|
-
async function readTarget(target) {
|
|
2808
|
-
return managedState(await readFile(target.absolutePath, "utf8").catch(() => null));
|
|
2809
|
-
}
|
|
2810
|
-
async function loadBundledSkills() {
|
|
2811
|
-
const byFile = /* @__PURE__ */ new Map();
|
|
2812
|
-
const contents = {};
|
|
2813
|
-
let version;
|
|
2814
|
-
for (const tool of SKILL_TOOLS) {
|
|
2815
|
-
const file = TOOL_CONFIG[tool].bundledFile;
|
|
2816
|
-
let content = byFile.get(file);
|
|
2817
|
-
if (content === void 0) {
|
|
2818
|
-
content = await readFile(new URL(`../skills/artifactshare/${file}`, import.meta.url), "utf8");
|
|
2819
|
-
const state = managedState(content);
|
|
2820
|
-
if (state.kind !== "managed" || (version ?? state.version) !== state.version) throw new Error(`The bundled ${file} has a missing or mismatched managed marker.`);
|
|
2821
|
-
version = state.version;
|
|
2822
|
-
byFile.set(file, content);
|
|
2823
|
-
}
|
|
2824
|
-
contents[tool] = content;
|
|
3401
|
+
if (parsed.options.description !== void 0) {
|
|
3402
|
+
body.description = parsed.options.description;
|
|
3403
|
+
hasChange = true;
|
|
2825
3404
|
}
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
function parseTools(value) {
|
|
2832
|
-
const raws = arrayOption(value);
|
|
2833
|
-
const tools = [];
|
|
2834
|
-
for (const raw of raws) for (const item of raw.split(",")) {
|
|
2835
|
-
const trimmed = item.trim();
|
|
2836
|
-
if (!trimmed) continue;
|
|
2837
|
-
if (!SKILL_TOOLS.includes(trimmed)) return { error: validationError(`Unknown --tool value: ${trimmed}`, "Pass --tool codex, --tool claude, or --tool cursor.") };
|
|
2838
|
-
tools.push(trimmed);
|
|
3405
|
+
if (parsed.options.visibility !== void 0) {
|
|
3406
|
+
const visibility = parsed.options.visibility.trim();
|
|
3407
|
+
if (visibility !== "workspace" && visibility !== "private") return { error: validationError("--visibility must be workspace or private.", "Retry with --visibility workspace or --visibility private.") };
|
|
3408
|
+
body.base_visibility = visibility;
|
|
3409
|
+
hasChange = true;
|
|
2839
3410
|
}
|
|
2840
|
-
|
|
2841
|
-
return {
|
|
3411
|
+
const addEmails = normalizedEmailOptions(parsed.options.addEmail);
|
|
3412
|
+
if (addEmails.error) return { error: addEmails.error };
|
|
3413
|
+
if (parsed.options.addEmail !== void 0) {
|
|
3414
|
+
body.add_emails = addEmails.values;
|
|
3415
|
+
hasChange = true;
|
|
3416
|
+
}
|
|
3417
|
+
const removeEmails = normalizedEmailOptions(parsed.options.removeEmail);
|
|
3418
|
+
if (removeEmails.error) return { error: removeEmails.error };
|
|
3419
|
+
if (parsed.options.removeEmail !== void 0) {
|
|
3420
|
+
body.remove_emails = removeEmails.values;
|
|
3421
|
+
hasChange = true;
|
|
3422
|
+
}
|
|
3423
|
+
if (parsed.options.archive && parsed.options.unarchive) return { error: validationError("Archive state is conflicting.", "Choose either --archive or --unarchive.") };
|
|
3424
|
+
if (parsed.options.archive) {
|
|
3425
|
+
body.archived = true;
|
|
3426
|
+
hasChange = true;
|
|
3427
|
+
}
|
|
3428
|
+
if (parsed.options.unarchive) {
|
|
3429
|
+
body.archived = false;
|
|
3430
|
+
hasChange = true;
|
|
3431
|
+
}
|
|
3432
|
+
if (!hasChange) return { error: validationError("At least one project edit option is required.", "Pass --name, --description, --visibility, --add-email, --remove-email, --archive, or --unarchive.") };
|
|
3433
|
+
return { body };
|
|
2842
3434
|
}
|
|
2843
|
-
function
|
|
2844
|
-
const
|
|
2845
|
-
if (
|
|
2846
|
-
|
|
2847
|
-
return { error: validationError(`Unknown --scope value: ${trimmed}`, "Pass --scope project or --scope user.") };
|
|
3435
|
+
function normalizedEmailOptions(value) {
|
|
3436
|
+
const values = arrayOption(value).map((email) => email.trim()).filter(Boolean);
|
|
3437
|
+
if (value !== void 0 && values.length === 0) return { error: validationError("Email option must not be blank.", "Pass a non-empty email address.") };
|
|
3438
|
+
return { values };
|
|
2848
3439
|
}
|
|
2849
|
-
function
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
if (scope.error) return { error: scope.error };
|
|
2854
|
-
const unsupported = scope.scope === void 0 ? void 0 : tools.tools.find((tool) => !TOOL_CONFIG[tool].scopes.includes(scope.scope));
|
|
2855
|
-
if (unsupported) return { error: validationError(`The ${unsupported} tool does not support --scope ${scope.scope}.`, `Use --tool ${unsupported} --scope project.`) };
|
|
3440
|
+
function parseProjectsEditData(body) {
|
|
3441
|
+
if (!isRecord(body) || !isRecord(body.project)) return null;
|
|
3442
|
+
const { project } = body;
|
|
3443
|
+
if (typeof project.id !== "string" || typeof project.archived !== "boolean" || !Array.isArray(body.audience) || body.audience.some((email) => typeof email !== "string")) return null;
|
|
2856
3444
|
return {
|
|
2857
|
-
|
|
2858
|
-
|
|
3445
|
+
project: {
|
|
3446
|
+
id: project.id,
|
|
3447
|
+
name: configString(project.name),
|
|
3448
|
+
description: configString(project.description),
|
|
3449
|
+
base_visibility: configString(project.base_visibility),
|
|
3450
|
+
file_count: typeof project.file_count === "number" ? project.file_count : null,
|
|
3451
|
+
archived: project.archived
|
|
3452
|
+
},
|
|
3453
|
+
audience: body.audience
|
|
2859
3454
|
};
|
|
2860
3455
|
}
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
async function
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
3456
|
+
//#endregion
|
|
3457
|
+
//#region src/command-runners/publish.ts
|
|
3458
|
+
const MAX_PUBLISH_KEY_LENGTH = 128;
|
|
3459
|
+
async function runPublish(parsed, mode, isRetry = false) {
|
|
3460
|
+
const command = "publish";
|
|
3461
|
+
const targetPath = parsed.positionals[0];
|
|
3462
|
+
if (!targetPath) return writeFailure(command, validationError("Path is required.", "Pass a file or directory to publish."), mode, 1);
|
|
3463
|
+
let publishKey = null;
|
|
3464
|
+
if ("key" in parsed.options) {
|
|
3465
|
+
publishKey = (typeof parsed.options.key === "string" ? parsed.options.key : "").trim();
|
|
3466
|
+
if (publishKey.length === 0 || publishKey.length > MAX_PUBLISH_KEY_LENGTH) return writeFailure(command, validationError(`--key must be 1-${MAX_PUBLISH_KEY_LENGTH} characters after trimming.`, "Pass a short stable identifier, like a job name or PR number."), mode, 1);
|
|
2869
3467
|
}
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
3468
|
+
const project = await resolveProjectConfig();
|
|
3469
|
+
const credential = await resolveCredential(parsed.options, project);
|
|
3470
|
+
if (!credential.ok) return handleCredentialFailure(command, credential, parsed.options, mode, () => runPublish(parsed, mode, true), isRetry);
|
|
3471
|
+
const baseUrl = baseUrlOf(parsed.options);
|
|
3472
|
+
const hasProjectFlag = "project" in parsed.options;
|
|
3473
|
+
let destinationOptions = parsed.options;
|
|
3474
|
+
let projectName;
|
|
3475
|
+
if (hasProjectFlag) {
|
|
3476
|
+
projectName = nonEmpty(typeof parsed.options.project === "string" ? parsed.options.project : "");
|
|
3477
|
+
if (!projectName) return writeFailure(command, validationError("--project requires a value.", "Pass --project <name> and retry."), mode, 1);
|
|
3478
|
+
const conflict = destinationConflictError(parsed.options);
|
|
3479
|
+
if (conflict) return writeFailure(command, conflict, mode, 1);
|
|
3480
|
+
} else {
|
|
3481
|
+
const earlyDestination = resolveDestination(parsed.options, project.config);
|
|
3482
|
+
if (earlyDestination.error) return writeFailure(command, earlyDestination.error, mode, 1);
|
|
2873
3483
|
}
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
}
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
3484
|
+
const fileStat = await stat(targetPath).catch(() => null);
|
|
3485
|
+
if (!fileStat) return writeFailure(command, validationError("Path was not found.", `Check the path and retry: ${targetPath}`), mode, 1);
|
|
3486
|
+
const request = await requestConfig(parsed.options);
|
|
3487
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3488
|
+
if (hasProjectFlag && projectName) {
|
|
3489
|
+
const resolved = await resolveProjectIdByName(projectName, credential.token, parsed.options, request.init);
|
|
3490
|
+
if (resolved.error) return writeFailure(command, resolved.error, mode, 1);
|
|
3491
|
+
const { project: _project, ...rest } = parsed.options;
|
|
3492
|
+
destinationOptions = {
|
|
3493
|
+
...rest,
|
|
3494
|
+
projectId: resolved.projectId
|
|
3495
|
+
};
|
|
2885
3496
|
}
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
3497
|
+
const destination = resolveDestination(destinationOptions, project.config);
|
|
3498
|
+
if (destination.error) return writeFailure(command, destination.error, mode, 1);
|
|
3499
|
+
const initialForm = new FormData();
|
|
3500
|
+
const grantEmails = arrayOption(parsed.options.grantEmail);
|
|
3501
|
+
const requestedVisibility = parsed.options.visibility ?? (destination.containerId && grantEmails.length === 0 ? "project" : "private");
|
|
3502
|
+
initialForm.set("visibility", requestedVisibility);
|
|
3503
|
+
for (const email of grantEmails) initialForm.append("grant_email", email);
|
|
3504
|
+
if (destination.containerId) initialForm.set("container_id", destination.containerId);
|
|
3505
|
+
const uploadUrl = apiUrl("/api/shareables/uploads", baseUrl);
|
|
3506
|
+
if (publishKey !== null) uploadUrl.searchParams.set("publish_key", publishKey);
|
|
3507
|
+
const upload = await prepareUploadPayload(targetPath, fileStat, initialForm);
|
|
3508
|
+
if (upload.error) return writeFailure(command, upload.error, mode, 1);
|
|
3509
|
+
if (upload.payload.kind === "static_site") {
|
|
3510
|
+
uploadUrl.searchParams.set("artifact_kind", "static_site");
|
|
3511
|
+
if (destination.containerId) uploadUrl.searchParams.set("container_id", destination.containerId);
|
|
2892
3512
|
}
|
|
3513
|
+
const response = await fetch(uploadUrl, {
|
|
3514
|
+
method: "POST",
|
|
3515
|
+
headers: { Authorization: `Bearer ${credential.token}` },
|
|
3516
|
+
body: upload.payload.form,
|
|
3517
|
+
...request.init
|
|
3518
|
+
}).catch((error) => ({ networkError: error }));
|
|
3519
|
+
if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
|
|
3520
|
+
const body = await readJson(response);
|
|
3521
|
+
if (!response.ok) return writeFailure(command, mapApiError(response.status, body, { authenticated: true }), mode, 1);
|
|
3522
|
+
const id = body?.id ?? null;
|
|
2893
3523
|
return writeSuccess(command, {
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
}
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
}
|
|
2910
|
-
}
|
|
2911
|
-
async function runSkillsInstall(parsed, mode) {
|
|
2912
|
-
const command = "skills install";
|
|
2913
|
-
const filters = parseFilters(parsed);
|
|
2914
|
-
if (filters.error) return writeFailure(command, filters.error, mode, 1);
|
|
2915
|
-
const { tools } = filters;
|
|
2916
|
-
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);
|
|
2917
|
-
const scope = filters.scope ?? "project";
|
|
2918
|
-
const force = parsed.options.force === true;
|
|
2919
|
-
const bundled = await bundledOrFailure(command, mode);
|
|
2920
|
-
if (!bundled) return;
|
|
2921
|
-
const planned = [];
|
|
2922
|
-
for (const tool of tools) {
|
|
2923
|
-
const target = skillTarget(tool, scope);
|
|
2924
|
-
const state = await readTarget(target);
|
|
2925
|
-
if ((state.kind === "unmanaged" || state.kind === "broken") && !force) return writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
2926
|
-
if (state.kind === "managed" && state.version === bundled.version && !force) {
|
|
2927
|
-
planned.push({
|
|
2928
|
-
target,
|
|
2929
|
-
action: "unchanged"
|
|
2930
|
-
});
|
|
2931
|
-
continue;
|
|
3524
|
+
artifact: {
|
|
3525
|
+
id,
|
|
3526
|
+
url: body?.shareUrl ?? (id ? `${baseUrl.replace(/\/$/, "")}/a/${id}` : null),
|
|
3527
|
+
kind: body?.artifactKind ?? upload.payload.kind
|
|
3528
|
+
},
|
|
3529
|
+
version: { id: body?.versionId ?? null },
|
|
3530
|
+
result: { created: body?.created ?? true },
|
|
3531
|
+
...publishKey !== null ? { key: publishKey } : {},
|
|
3532
|
+
destination: destination.containerId ? {
|
|
3533
|
+
type: "project",
|
|
3534
|
+
project_id: destination.containerId
|
|
3535
|
+
} : { type: "home" },
|
|
3536
|
+
share: {
|
|
3537
|
+
visibility: body?.visibility ?? requestedVisibility,
|
|
3538
|
+
grant_emails: grantEmails
|
|
2932
3539
|
}
|
|
2933
|
-
planned.push({
|
|
2934
|
-
target,
|
|
2935
|
-
action: state.kind === "missing" ? "installed" : "updated",
|
|
2936
|
-
content: bundled.contents[tool]
|
|
2937
|
-
});
|
|
2938
|
-
}
|
|
2939
|
-
return finishActions(command, planned, parsed.options.dryRun === true, mode);
|
|
2940
|
-
}
|
|
2941
|
-
async function runSkillsList(parsed, mode) {
|
|
2942
|
-
const bundled = await bundledOrFailure("skills list", mode);
|
|
2943
|
-
if (!bundled) return;
|
|
2944
|
-
const targets = [];
|
|
2945
|
-
for (const target of allTargets()) {
|
|
2946
|
-
const base = target.scope === "project" ? process.cwd() : homedir();
|
|
2947
|
-
let detected = false;
|
|
2948
|
-
for (const dir of TOOL_CONFIG[target.tool].detectDirs) if ((await stat(join(base, dir)).catch(() => null))?.isDirectory()) detected = true;
|
|
2949
|
-
const state = await readTarget(target);
|
|
2950
|
-
targets.push({
|
|
2951
|
-
tool: target.tool,
|
|
2952
|
-
scope: target.scope,
|
|
2953
|
-
path: target.path,
|
|
2954
|
-
detected,
|
|
2955
|
-
installed: state.kind !== "missing",
|
|
2956
|
-
managed: state.kind === "managed",
|
|
2957
|
-
installed_version: state.kind === "managed" ? state.version : null,
|
|
2958
|
-
update_available: state.kind === "managed" && state.version !== bundled.version
|
|
2959
|
-
});
|
|
2960
|
-
}
|
|
2961
|
-
return writeSuccess("skills list", {
|
|
2962
|
-
bundled_version: bundled.version,
|
|
2963
|
-
targets
|
|
2964
3540
|
}, mode);
|
|
2965
3541
|
}
|
|
2966
|
-
async function
|
|
2967
|
-
const
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
});
|
|
2981
|
-
else if (state.kind === "unmanaged") planned.push({
|
|
2982
|
-
target,
|
|
2983
|
-
action: "skipped_unmanaged"
|
|
2984
|
-
});
|
|
2985
|
-
else if (state.version !== bundled.version || force) planned.push({
|
|
2986
|
-
target,
|
|
2987
|
-
action: "updated",
|
|
2988
|
-
content: bundled.contents[target.tool]
|
|
2989
|
-
});
|
|
2990
|
-
else planned.push({
|
|
2991
|
-
target,
|
|
2992
|
-
action: "unchanged"
|
|
2993
|
-
});
|
|
2994
|
-
}
|
|
2995
|
-
return finishActions(command, planned, parsed.options.dryRun === true, mode);
|
|
3542
|
+
async function resolveProjectIdByName(projectName, token, options, init) {
|
|
3543
|
+
const result = await fetchProjects(token, options, init);
|
|
3544
|
+
if (result.error) return { error: result.error };
|
|
3545
|
+
const candidates = result.projects.flatMap((project) => {
|
|
3546
|
+
if (project.name !== projectName) return [];
|
|
3547
|
+
return [{
|
|
3548
|
+
project_id: project.id,
|
|
3549
|
+
name: project.name,
|
|
3550
|
+
updated_at: project.updated_at
|
|
3551
|
+
}];
|
|
3552
|
+
});
|
|
3553
|
+
if (candidates.length === 0) return { error: projectNotFoundByNameError() };
|
|
3554
|
+
if (candidates.length > 1) return { error: projectAmbiguousError(candidates) };
|
|
3555
|
+
return { projectId: candidates[0].project_id };
|
|
2996
3556
|
}
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
const
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3557
|
+
//#endregion
|
|
3558
|
+
//#region src/command-runners/request-access.ts
|
|
3559
|
+
const NOTE_MAX = 2e3;
|
|
3560
|
+
async function runRequestAccess(parsed, mode) {
|
|
3561
|
+
const command = "request-access";
|
|
3562
|
+
const note = parsed.options.note;
|
|
3563
|
+
if (note !== void 0 && note.length > NOTE_MAX) return writeFailure(command, validationError(`A note can be at most ${NOTE_MAX} characters.`, "Shorten --note and retry."), mode, 1);
|
|
3564
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
3565
|
+
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3566
|
+
const request = await requestConfig(parsed.options);
|
|
3567
|
+
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);
|
|
3569
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3570
|
+
const body = result.body;
|
|
3571
|
+
const data = {
|
|
3572
|
+
requested: body?.requested === true,
|
|
3573
|
+
already_enabled: body?.already_enabled === true,
|
|
3574
|
+
status: typeof body?.status === "string" ? body.status : null,
|
|
3575
|
+
created: body?.created === true,
|
|
3576
|
+
requires_operator_action: body?.requires_operator_action === true,
|
|
3577
|
+
message: typeof body?.message === "string" ? body.message : ""
|
|
3578
|
+
};
|
|
3579
|
+
writeSuccess(command, data, mode);
|
|
3580
|
+
if (!mode.json && data.message) writeText(`${data.message}\n`);
|
|
3581
|
+
}
|
|
3582
|
+
//#endregion
|
|
3583
|
+
//#region src/command-runners/resolve.ts
|
|
3584
|
+
async function runResolve(parsed, mode) {
|
|
3585
|
+
const command = "resolve";
|
|
3586
|
+
const value = parsed.positionals[0]?.trim();
|
|
3587
|
+
if (!value) return writeFailure(command, validationError("Resolve value is required.", "Pass a URL, ID, title, or project name to resolve."), mode, 1);
|
|
3588
|
+
const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
|
|
3589
|
+
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3590
|
+
const request = await requestConfig(parsed.options);
|
|
3591
|
+
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3592
|
+
const url = apiUrl("/api/cli/resolve", baseUrlOf(parsed.options));
|
|
3593
|
+
url.searchParams.set("q", value);
|
|
3594
|
+
const response = await fetch(url, {
|
|
3595
|
+
headers: { Authorization: `Bearer ${credential.token}` },
|
|
3596
|
+
...request.init
|
|
3597
|
+
}).catch((error) => ({ networkError: error }));
|
|
3598
|
+
if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
|
|
3599
|
+
const body = await readJson(response);
|
|
3600
|
+
if (!response.ok) return writeFailure(command, mapApiError(response.status, body, { authenticated: true }), mode, 1);
|
|
3601
|
+
if (!resolveSuccessFields(body)) return writeFailure(command, serviceError("Resolve succeeded but the response did not include query, candidates, and has_more."), mode, 1);
|
|
3602
|
+
return writeSuccess(command, body, mode);
|
|
3011
3603
|
}
|
|
3012
3604
|
//#endregion
|
|
3013
3605
|
//#region src/command-runners/update.ts
|
|
@@ -3086,6 +3678,14 @@ async function updateRunner(ctx) {
|
|
|
3086
3678
|
const parsed = parsedArgsFromContext("update", ctx);
|
|
3087
3679
|
return await runUpdate(parsed, outputMode(parsed.options));
|
|
3088
3680
|
}
|
|
3681
|
+
async function editRunner(ctx) {
|
|
3682
|
+
const parsed = parsedArgsFromContext("edit", ctx);
|
|
3683
|
+
return await runEdit(parsed, outputMode(parsed.options));
|
|
3684
|
+
}
|
|
3685
|
+
async function deleteRunner(ctx) {
|
|
3686
|
+
const parsed = parsedArgsFromContext("delete", ctx);
|
|
3687
|
+
return await runDelete(parsed, outputMode(parsed.options));
|
|
3688
|
+
}
|
|
3089
3689
|
async function resolveRunner(ctx) {
|
|
3090
3690
|
const parsed = parsedArgsFromContext("resolve", ctx);
|
|
3091
3691
|
return await runResolve(parsed, outputMode(parsed.options));
|
|
@@ -3094,6 +3694,10 @@ async function downloadRunner(ctx) {
|
|
|
3094
3694
|
const parsed = parsedArgsFromContext("download", ctx);
|
|
3095
3695
|
return await runDownload(parsed, outputMode(parsed.options));
|
|
3096
3696
|
}
|
|
3697
|
+
async function agentOpenRunner(ctx) {
|
|
3698
|
+
const parsed = parsedArgsFromContext("agent open", ctx);
|
|
3699
|
+
return await runAgentOpen(parsed, outputMode(parsed.options));
|
|
3700
|
+
}
|
|
3097
3701
|
async function moveRunner(ctx) {
|
|
3098
3702
|
const parsed = parsedArgsFromContext("move", ctx);
|
|
3099
3703
|
return await runMove(parsed, outputMode(parsed.options));
|
|
@@ -3102,6 +3706,10 @@ async function artifactsGetRunner(ctx) {
|
|
|
3102
3706
|
const parsed = parsedArgsFromContext("artifacts get", ctx);
|
|
3103
3707
|
return await runArtifactsGet(parsed, outputMode(parsed.options));
|
|
3104
3708
|
}
|
|
3709
|
+
async function artifactsListRunner(ctx) {
|
|
3710
|
+
const parsed = parsedArgsFromContext("artifacts list", ctx);
|
|
3711
|
+
return await runArtifactsList(parsed, outputMode(parsed.options));
|
|
3712
|
+
}
|
|
3105
3713
|
async function commentsListRunner(ctx) {
|
|
3106
3714
|
const parsed = parsedArgsFromContext("comments list", ctx);
|
|
3107
3715
|
return await runCommentsList(parsed, outputMode(parsed.options));
|
|
@@ -3110,6 +3718,22 @@ async function commentsPostRunner(ctx) {
|
|
|
3110
3718
|
const parsed = parsedArgsFromContext("comments post", ctx);
|
|
3111
3719
|
return await runCommentsPost(parsed, outputMode(parsed.options));
|
|
3112
3720
|
}
|
|
3721
|
+
async function commentsEditRunner(ctx) {
|
|
3722
|
+
const parsed = parsedArgsFromContext("comments edit", ctx);
|
|
3723
|
+
return await runCommentsEdit(parsed, outputMode(parsed.options));
|
|
3724
|
+
}
|
|
3725
|
+
async function commentsResolveRunner(ctx) {
|
|
3726
|
+
const parsed = parsedArgsFromContext("comments resolve", ctx);
|
|
3727
|
+
return await runCommentsResolve(parsed, outputMode(parsed.options));
|
|
3728
|
+
}
|
|
3729
|
+
async function commentsReopenRunner(ctx) {
|
|
3730
|
+
const parsed = parsedArgsFromContext("comments reopen", ctx);
|
|
3731
|
+
return await runCommentsReopen(parsed, outputMode(parsed.options));
|
|
3732
|
+
}
|
|
3733
|
+
async function commentsDeleteRunner(ctx) {
|
|
3734
|
+
const parsed = parsedArgsFromContext("comments delete", ctx);
|
|
3735
|
+
return await runCommentsDelete(parsed, outputMode(parsed.options));
|
|
3736
|
+
}
|
|
3113
3737
|
async function requestAccessRunner(ctx) {
|
|
3114
3738
|
const parsed = parsedArgsFromContext("request-access", ctx);
|
|
3115
3739
|
return await runRequestAccess(parsed, outputMode(parsed.options));
|
|
@@ -3139,6 +3763,10 @@ async function projectsCreateRunner(ctx) {
|
|
|
3139
3763
|
const parsed = parsedArgsFromContext("projects create", ctx);
|
|
3140
3764
|
return await runProjectsCreate(parsed, outputMode(parsed.options));
|
|
3141
3765
|
}
|
|
3766
|
+
async function projectsEditRunner(ctx) {
|
|
3767
|
+
const parsed = parsedArgsFromContext("projects edit", ctx);
|
|
3768
|
+
return await runProjectsEdit(parsed, outputMode(parsed.options));
|
|
3769
|
+
}
|
|
3142
3770
|
async function initRunner(ctx) {
|
|
3143
3771
|
const parsed = parsedArgsFromContext("init", ctx);
|
|
3144
3772
|
return await runInit(parsed, outputMode(parsed.options));
|
|
@@ -3155,6 +3783,10 @@ async function skillsUpdateRunner(ctx) {
|
|
|
3155
3783
|
const parsed = parsedArgsFromContext("skills update", ctx);
|
|
3156
3784
|
return await runSkillsUpdate(parsed, outputMode(parsed.options));
|
|
3157
3785
|
}
|
|
3786
|
+
async function skillsEnsureRunner(ctx) {
|
|
3787
|
+
const parsed = parsedArgsFromContext("skills ensure", ctx);
|
|
3788
|
+
return await runSkillsEnsure(parsed, outputMode(parsed.options));
|
|
3789
|
+
}
|
|
3158
3790
|
async function skillsRemoveRunner(ctx) {
|
|
3159
3791
|
const parsed = parsedArgsFromContext("skills remove", ctx);
|
|
3160
3792
|
return await runSkillsRemove(parsed, outputMode(parsed.options));
|
|
@@ -3182,7 +3814,7 @@ async function main(rawArgv) {
|
|
|
3182
3814
|
const argv = joinLeadingDashValues(rawArgv);
|
|
3183
3815
|
const command = commandNameFromArgv(argv);
|
|
3184
3816
|
const commandCandidate = firstCommandCandidate(argv);
|
|
3185
|
-
const rawError = validateRawArgs(argv);
|
|
3817
|
+
const rawError = validateRawArgs(argv, command);
|
|
3186
3818
|
if (rawError) return writeFailure(command ?? "unknown", rawError, outputModeFromArgv(argv), 1);
|
|
3187
3819
|
if (command === void 0 && commandCandidate !== void 0) return writeFailure("unknown", unknownCommandError(commandCandidate), outputModeFromArgv(argv), 1);
|
|
3188
3820
|
const usage = await runGunshi(command === void 0 ? ["--help"] : normalizeArgvForGunshi(argv, commandCandidate)).catch((error) => {
|
|
@@ -3212,8 +3844,11 @@ async function runGunshi(argv) {
|
|
|
3212
3844
|
login: lazyCommand(loginDefinition, loginRunner),
|
|
3213
3845
|
publish: lazyCommand(publishDefinition, publishRunner),
|
|
3214
3846
|
update: lazyCommand(updateDefinition, updateRunner),
|
|
3847
|
+
edit: lazyCommand(editDefinition, editRunner),
|
|
3848
|
+
delete: lazyCommand(deleteDefinition, deleteRunner),
|
|
3215
3849
|
resolve: lazyCommand(resolveDefinition, resolveRunner),
|
|
3216
3850
|
download: lazyCommand(downloadDefinition, downloadRunner),
|
|
3851
|
+
agent: agentDefinition,
|
|
3217
3852
|
move: lazyCommand(moveDefinition, moveRunner),
|
|
3218
3853
|
artifacts: artifactsDefinition,
|
|
3219
3854
|
comments: commentsDefinition,
|
|
@@ -3272,13 +3907,17 @@ const entryCommand = define({
|
|
|
3272
3907
|
args: commonArgs,
|
|
3273
3908
|
examples: `npx --yes @artifactshare/cli publish <path> --project-id <id> --json
|
|
3274
3909
|
npx --yes @artifactshare/cli update <artifact-id-or-url> <path> --json
|
|
3910
|
+
npx --yes @artifactshare/cli edit <artifact-id-or-url> --title "New title" --json
|
|
3911
|
+
npx --yes @artifactshare/cli delete <artifact-id-or-url> --json
|
|
3275
3912
|
npx --yes @artifactshare/cli resolve <url-id-or-title> --json
|
|
3276
3913
|
npx --yes @artifactshare/cli projects create "Launch review" --json
|
|
3914
|
+
npx --yes @artifactshare/cli projects edit <id> --add-email viewer@example.com --json
|
|
3277
3915
|
npx --yes @artifactshare/cli move <artifact-id-or-url> --project-id <id> --json
|
|
3916
|
+
npx --yes @artifactshare/cli artifacts list --json
|
|
3278
3917
|
npx --yes @artifactshare/cli artifacts get <artifact-id-or-url> --json
|
|
3279
3918
|
npx --yes @artifactshare/cli comments list <artifact-id-or-url> --json
|
|
3280
3919
|
npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body "<text>" --json
|
|
3281
|
-
|
|
3920
|
+
${agentDownloadCommand("<artifact-id-or-url>")}
|
|
3282
3921
|
npx --yes @artifactshare/cli login --profile default
|
|
3283
3922
|
npx --yes @artifactshare/cli profiles list --json
|
|
3284
3923
|
npx --yes @artifactshare/cli profiles use <name> --json
|
|
@@ -3361,7 +4000,13 @@ const publishDefinition = define({
|
|
|
3361
4000
|
description: "Stable key for create-or-update: the first publish creates the artifact, repeats add versions. Not a secret; it appears in logs and JSON"
|
|
3362
4001
|
}
|
|
3363
4002
|
},
|
|
3364
|
-
examples: `npx --yes @artifactshare/cli publish report.html --project-id <id> --
|
|
4003
|
+
examples: `npx --yes @artifactshare/cli publish report.html --project-id <id> --json
|
|
4004
|
+
npx --yes @artifactshare/cli publish report.html --project-id <id> --key nightly-report --json
|
|
4005
|
+
|
|
4006
|
+
To keep an existing share URL, use update:
|
|
4007
|
+
npx --yes @artifactshare/cli update <artifact-id-or-url> <path> --json
|
|
4008
|
+
|
|
4009
|
+
For repeat jobs, use --key: first publish creates the artifact, later runs add versions.
|
|
3365
4010
|
|
|
3366
4011
|
Common failures:
|
|
3367
4012
|
auth_required Set ARTIFACTSHARE_TOKEN before publish
|
|
@@ -3400,6 +4045,89 @@ Common failures:
|
|
|
3400
4045
|
file_too_large Reduce file or directory size and retry
|
|
3401
4046
|
validation_failed Check file type (.html / .md for single files) and directory layout`
|
|
3402
4047
|
});
|
|
4048
|
+
const editDefinition = define({
|
|
4049
|
+
name: "edit",
|
|
4050
|
+
description: "Edit artifact title, sharing, or project placement.",
|
|
4051
|
+
toKebab: true,
|
|
4052
|
+
args: {
|
|
4053
|
+
...commonArgs,
|
|
4054
|
+
artifactIdOrUrl: {
|
|
4055
|
+
type: "positional",
|
|
4056
|
+
toKebab: true,
|
|
4057
|
+
description: "Artifact ID, /a/<id> share URL, or <id>.sandbox.* URL"
|
|
4058
|
+
},
|
|
4059
|
+
title: {
|
|
4060
|
+
type: "string",
|
|
4061
|
+
toKebab: true,
|
|
4062
|
+
description: "Set display title; pass an empty value to clear it"
|
|
4063
|
+
},
|
|
4064
|
+
visibility: {
|
|
4065
|
+
type: "string",
|
|
4066
|
+
toKebab: true,
|
|
4067
|
+
description: "private or workspace"
|
|
4068
|
+
},
|
|
4069
|
+
grantEmail: {
|
|
4070
|
+
type: "string",
|
|
4071
|
+
multiple: true,
|
|
4072
|
+
toKebab: true,
|
|
4073
|
+
description: "Add an explicit viewer; repeat for multiple viewers"
|
|
4074
|
+
},
|
|
4075
|
+
revokeEmail: {
|
|
4076
|
+
type: "string",
|
|
4077
|
+
multiple: true,
|
|
4078
|
+
toKebab: true,
|
|
4079
|
+
description: "Remove an explicit viewer; repeat for multiple viewers"
|
|
4080
|
+
},
|
|
4081
|
+
projectId: {
|
|
4082
|
+
type: "string",
|
|
4083
|
+
toKebab: true,
|
|
4084
|
+
description: "Move into this project"
|
|
4085
|
+
},
|
|
4086
|
+
home: {
|
|
4087
|
+
type: "boolean",
|
|
4088
|
+
toKebab: true,
|
|
4089
|
+
description: "Move back to the owner home area"
|
|
4090
|
+
}
|
|
4091
|
+
},
|
|
4092
|
+
examples: `npx --yes @artifactshare/cli edit abc123def4 --title "Launch plan" --json
|
|
4093
|
+
npx --yes @artifactshare/cli edit abc123def4 --visibility private --grant-email viewer@example.com --json
|
|
4094
|
+
npx --yes @artifactshare/cli edit https://artifactshare.com/a/abc123def4 --project-id prj123 --json
|
|
4095
|
+
npx --yes @artifactshare/cli edit abc123def4 --home --json
|
|
4096
|
+
|
|
4097
|
+
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-publish settings.
|
|
4099
|
+
|
|
4100
|
+
Common failures:
|
|
4101
|
+
auth_required Set ARTIFACTSHARE_TOKEN before edit
|
|
4102
|
+
target_not_found Retry with an artifact ID, share URL, or sandbox URL
|
|
4103
|
+
destination_conflict Choose either --project-id or --home
|
|
4104
|
+
invalid_destination Use an active project id from projects list, or --home
|
|
4105
|
+
workspace_unavailable Use --visibility private for personal Google accounts
|
|
4106
|
+
too_many_grants Remove viewers or grant fewer email addresses`
|
|
4107
|
+
});
|
|
4108
|
+
const deleteDefinition = define({
|
|
4109
|
+
name: "delete",
|
|
4110
|
+
description: "Permanently delete an artifact you published.",
|
|
4111
|
+
toKebab: true,
|
|
4112
|
+
args: {
|
|
4113
|
+
...commonArgs,
|
|
4114
|
+
artifactIdOrUrl: {
|
|
4115
|
+
type: "positional",
|
|
4116
|
+
toKebab: true,
|
|
4117
|
+
description: "Artifact ID, /a/<id> share URL, or <id>.sandbox.* URL"
|
|
4118
|
+
}
|
|
4119
|
+
},
|
|
4120
|
+
examples: `npx --yes @artifactshare/cli delete abc123def4 --json
|
|
4121
|
+
npx --yes @artifactshare/cli delete https://artifactshare.com/a/abc123def4 --json
|
|
4122
|
+
|
|
4123
|
+
Delete permanently removes the artifact and its version history. This cannot be undone.
|
|
4124
|
+
Use resolve first when a user gives a title or project name, then pass the id here.
|
|
4125
|
+
|
|
4126
|
+
Common failures:
|
|
4127
|
+
auth_required Set ARTIFACTSHARE_TOKEN before delete
|
|
4128
|
+
target_not_found Retry with an artifact ID, share URL, or sandbox URL
|
|
4129
|
+
service_error Retry later if deletion could not complete`
|
|
4130
|
+
});
|
|
3403
4131
|
const resolveDefinition = define({
|
|
3404
4132
|
name: "resolve",
|
|
3405
4133
|
description: "Find artifact, version, and project candidates before writing.",
|
|
@@ -3445,7 +4173,7 @@ const downloadDefinition = define({
|
|
|
3445
4173
|
}
|
|
3446
4174
|
},
|
|
3447
4175
|
examples: `npx --yes @artifactshare/cli download abc123def4 --json
|
|
3448
|
-
|
|
4176
|
+
${agentDownloadCommand("https://artifactshare.com/a/abc123def4")}
|
|
3449
4177
|
|
|
3450
4178
|
Use resolve first when a user gives a title or project name, then pass the id here.
|
|
3451
4179
|
Download writes files to a directory so the result can be inspected or passed to update.
|
|
@@ -3456,6 +4184,39 @@ Common failures:
|
|
|
3456
4184
|
output_exists Choose another --output path or pass --force
|
|
3457
4185
|
validation_failed Check --output and downloaded file paths`
|
|
3458
4186
|
});
|
|
4187
|
+
const agentDefinition = define({
|
|
4188
|
+
name: "agent",
|
|
4189
|
+
description: "Agent-first helpers for Artifact Share URLs.",
|
|
4190
|
+
toKebab: true,
|
|
4191
|
+
args: commonArgs,
|
|
4192
|
+
subCommands: { open: lazyCommand(define({
|
|
4193
|
+
name: "open",
|
|
4194
|
+
description: "Prepare agent skills and read an Artifact Share URL.",
|
|
4195
|
+
toKebab: true,
|
|
4196
|
+
args: {
|
|
4197
|
+
...commonArgs,
|
|
4198
|
+
artifactIdOrUrl: {
|
|
4199
|
+
type: "positional",
|
|
4200
|
+
toKebab: true,
|
|
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
|
|
4206
|
+
|
|
4207
|
+
Use this as the first command when an agent receives an Artifact Share URL.
|
|
4208
|
+
It installs or updates the local Artifact Share skill, then reads single-file artifacts.
|
|
4209
|
+
For static sites or multi-file artifacts, the JSON includes a download next_command.
|
|
4210
|
+
|
|
4211
|
+
Common failures:
|
|
4212
|
+
auth_required Set ARTIFACTSHARE_TOKEN before agent open
|
|
4213
|
+
skill_update_conflict Inspect the file or run skills install --tool <tool> --force
|
|
4214
|
+
target_not_found Retry with an artifact ID, share URL, or sandbox URL
|
|
4215
|
+
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
|
+
});
|
|
3459
4220
|
const moveDefinition = define({
|
|
3460
4221
|
name: "move",
|
|
3461
4222
|
description: "Move an artifact into a project or back home.",
|
|
@@ -3491,35 +4252,30 @@ Common failures:
|
|
|
3491
4252
|
destination_conflict Choose either --project-id or --home
|
|
3492
4253
|
invalid_destination Use an active project id from projects list, or --home`
|
|
3493
4254
|
});
|
|
3494
|
-
const
|
|
3495
|
-
name: "
|
|
3496
|
-
description: "Read
|
|
4255
|
+
const artifactsGetDefinition = define({
|
|
4256
|
+
name: "get",
|
|
4257
|
+
description: "Read a single-file artifact source and metadata.",
|
|
3497
4258
|
toKebab: true,
|
|
3498
|
-
args:
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
},
|
|
3510
|
-
offset: {
|
|
3511
|
-
type: "string",
|
|
3512
|
-
toKebab: true,
|
|
3513
|
-
description: "Character offset for continuing a truncated read"
|
|
3514
|
-
},
|
|
3515
|
-
include: {
|
|
3516
|
-
type: "string",
|
|
3517
|
-
multiple: true,
|
|
3518
|
-
toKebab: true,
|
|
3519
|
-
description: "Extra data to include: versions or comments"
|
|
3520
|
-
}
|
|
4259
|
+
args: {
|
|
4260
|
+
...commonArgs,
|
|
4261
|
+
artifactIdOrUrl: {
|
|
4262
|
+
type: "positional",
|
|
4263
|
+
toKebab: true,
|
|
4264
|
+
description: "Artifact ID, /a/<id> share URL, or <id>.sandbox.* URL"
|
|
4265
|
+
},
|
|
4266
|
+
offset: {
|
|
4267
|
+
type: "string",
|
|
4268
|
+
toKebab: true,
|
|
4269
|
+
description: "Character offset for continuing a truncated read"
|
|
3521
4270
|
},
|
|
3522
|
-
|
|
4271
|
+
include: {
|
|
4272
|
+
type: "string",
|
|
4273
|
+
multiple: true,
|
|
4274
|
+
toKebab: true,
|
|
4275
|
+
description: "Extra data to include: versions or comments"
|
|
4276
|
+
}
|
|
4277
|
+
},
|
|
4278
|
+
examples: `npx --yes @artifactshare/cli artifacts get abc123def4 --json
|
|
3523
4279
|
npx --yes @artifactshare/cli artifacts get https://artifactshare.com/a/abc123def4 --include versions --include comments --json
|
|
3524
4280
|
npx --yes @artifactshare/cli artifacts get abc123def4 --offset 200000 --json
|
|
3525
4281
|
|
|
@@ -3531,9 +4287,52 @@ Common failures:
|
|
|
3531
4287
|
target_not_found Retry with an artifact ID, share URL, or sandbox URL
|
|
3532
4288
|
unsupported_kind Use download for static sites or other multi-file artifacts
|
|
3533
4289
|
validation_failed Check --offset and --include values`
|
|
3534
|
-
|
|
3535
|
-
|
|
4290
|
+
});
|
|
4291
|
+
const artifactsDefinition = define({
|
|
4292
|
+
name: "artifacts",
|
|
4293
|
+
description: "Read Artifact Share artifacts.",
|
|
4294
|
+
toKebab: true,
|
|
4295
|
+
args: commonArgs,
|
|
4296
|
+
subCommands: {
|
|
4297
|
+
list: lazyCommand(define({
|
|
4298
|
+
name: "list",
|
|
4299
|
+
description: "List artifacts you published, newest first.",
|
|
4300
|
+
toKebab: true,
|
|
4301
|
+
args: {
|
|
4302
|
+
...commonArgs,
|
|
4303
|
+
projectId: {
|
|
4304
|
+
type: "string",
|
|
4305
|
+
toKebab: true,
|
|
4306
|
+
description: "Only artifacts in this project"
|
|
4307
|
+
},
|
|
4308
|
+
home: {
|
|
4309
|
+
type: "boolean",
|
|
4310
|
+
toKebab: true,
|
|
4311
|
+
description: "Only artifacts in the unfiled home area"
|
|
4312
|
+
},
|
|
4313
|
+
query: {
|
|
4314
|
+
type: "string",
|
|
4315
|
+
toKebab: true,
|
|
4316
|
+
description: "Only artifacts whose title contains this text"
|
|
4317
|
+
}
|
|
4318
|
+
},
|
|
4319
|
+
examples: `npx --yes @artifactshare/cli artifacts list --json
|
|
4320
|
+
npx --yes @artifactshare/cli artifacts list --project-id <id> --json
|
|
4321
|
+
npx --yes @artifactshare/cli artifacts list --home --query report --json
|
|
4322
|
+
|
|
4323
|
+
Use an id from this list with update, edit, move, delete, artifacts get, or comments list.
|
|
4324
|
+
|
|
4325
|
+
Common failures:
|
|
4326
|
+
auth_required Set ARTIFACTSHARE_TOKEN before artifacts list
|
|
4327
|
+
invalid_destination Run projects list, then retry with --project-id <id> or --home
|
|
4328
|
+
validation_failed Choose only one of --project-id or --home`
|
|
4329
|
+
}), artifactsListRunner),
|
|
4330
|
+
get: lazyCommand(artifactsGetDefinition, artifactsGetRunner)
|
|
4331
|
+
},
|
|
4332
|
+
examples: `npx --yes @artifactshare/cli artifacts list --json
|
|
4333
|
+
npx --yes @artifactshare/cli artifacts get <artifact-id-or-url> --json
|
|
3536
4334
|
|
|
4335
|
+
Use artifacts list to find IDs for update, edit, move, delete, artifacts get, and comments list.
|
|
3537
4336
|
Use artifacts get to read back Markdown or HTML before update.`,
|
|
3538
4337
|
run: parentCommandRunner("artifacts")
|
|
3539
4338
|
});
|
|
@@ -3609,17 +4408,115 @@ Common failures:
|
|
|
3609
4408
|
quote_not_found Copy the exact text from artifacts get
|
|
3610
4409
|
validation_failed Pass --body, and do not combine --quote with --reply-to`
|
|
3611
4410
|
});
|
|
4411
|
+
const commentThreadActionArgs = {
|
|
4412
|
+
...commonArgs,
|
|
4413
|
+
artifactIdOrUrl: {
|
|
4414
|
+
type: "positional",
|
|
4415
|
+
toKebab: true,
|
|
4416
|
+
description: "Artifact ID, /a/<id> share URL, or <id>.sandbox.* URL"
|
|
4417
|
+
},
|
|
4418
|
+
threadId: {
|
|
4419
|
+
type: "string",
|
|
4420
|
+
toKebab: true,
|
|
4421
|
+
description: "Thread id from comments list"
|
|
4422
|
+
}
|
|
4423
|
+
};
|
|
4424
|
+
const commentsEditDefinition = define({
|
|
4425
|
+
name: "edit",
|
|
4426
|
+
description: "Edit a comment message you wrote.",
|
|
4427
|
+
toKebab: true,
|
|
4428
|
+
args: {
|
|
4429
|
+
...commonArgs,
|
|
4430
|
+
artifactIdOrUrl: {
|
|
4431
|
+
type: "positional",
|
|
4432
|
+
toKebab: true,
|
|
4433
|
+
description: "Artifact ID, /a/<id> share URL, or <id>.sandbox.* URL"
|
|
4434
|
+
},
|
|
4435
|
+
messageId: {
|
|
4436
|
+
type: "string",
|
|
4437
|
+
toKebab: true,
|
|
4438
|
+
description: "Message id from comments list"
|
|
4439
|
+
},
|
|
4440
|
+
body: {
|
|
4441
|
+
type: "string",
|
|
4442
|
+
toKebab: true,
|
|
4443
|
+
description: "Updated comment text (required)"
|
|
4444
|
+
}
|
|
4445
|
+
},
|
|
4446
|
+
examples: `npx --yes @artifactshare/cli comments edit abc123def4 --message-id <message-id> --body "Updated text" --json
|
|
4447
|
+
|
|
4448
|
+
Common failures:
|
|
4449
|
+
message_not_found Run comments list and retry with a listed message_id
|
|
4450
|
+
forbidden You can edit only your own comments
|
|
4451
|
+
validation_failed Pass --message-id and --body`
|
|
4452
|
+
});
|
|
4453
|
+
const commentsResolveDefinition = define({
|
|
4454
|
+
name: "resolve",
|
|
4455
|
+
description: "Mark a comment thread as resolved.",
|
|
4456
|
+
toKebab: true,
|
|
4457
|
+
args: commentThreadActionArgs,
|
|
4458
|
+
examples: `npx --yes @artifactshare/cli comments resolve abc123def4 --thread-id <thread-id> --json
|
|
4459
|
+
|
|
4460
|
+
Common failures:
|
|
4461
|
+
thread_not_found Run comments list and retry with a listed thread_id
|
|
4462
|
+
forbidden Resolving needs the thread author, artifact owner, or workspace admin
|
|
4463
|
+
validation_failed Pass --thread-id`
|
|
4464
|
+
});
|
|
4465
|
+
const commentsReopenDefinition = define({
|
|
4466
|
+
name: "reopen",
|
|
4467
|
+
description: "Reopen a resolved comment thread.",
|
|
4468
|
+
toKebab: true,
|
|
4469
|
+
args: commentThreadActionArgs,
|
|
4470
|
+
examples: `npx --yes @artifactshare/cli comments reopen abc123def4 --thread-id <thread-id> --json
|
|
4471
|
+
|
|
4472
|
+
Common failures:
|
|
4473
|
+
thread_not_found Run comments list and retry with a listed thread_id
|
|
4474
|
+
forbidden Reopening needs the thread author, artifact owner, or workspace admin
|
|
4475
|
+
validation_failed Pass --thread-id`
|
|
4476
|
+
});
|
|
4477
|
+
const commentsDeleteDefinition = define({
|
|
4478
|
+
name: "delete",
|
|
4479
|
+
description: "Permanently delete a comment message or a whole thread.",
|
|
4480
|
+
toKebab: true,
|
|
4481
|
+
args: {
|
|
4482
|
+
...commentThreadActionArgs,
|
|
4483
|
+
messageId: {
|
|
4484
|
+
type: "string",
|
|
4485
|
+
toKebab: true,
|
|
4486
|
+
description: "Message id from comments list; omit to delete the thread"
|
|
4487
|
+
}
|
|
4488
|
+
},
|
|
4489
|
+
examples: `npx --yes @artifactshare/cli comments delete abc123def4 --thread-id <thread-id> --message-id <message-id> --json
|
|
4490
|
+
npx --yes @artifactshare/cli comments delete abc123def4 --thread-id <thread-id> --json
|
|
4491
|
+
|
|
4492
|
+
Deleting comments cannot be undone. Omit --message-id only when deleting the whole thread.
|
|
4493
|
+
|
|
4494
|
+
Common failures:
|
|
4495
|
+
thread_not_found Run comments list and retry with a listed thread_id
|
|
4496
|
+
message_not_found Retry with a message_id from that thread
|
|
4497
|
+
forbidden You can delete your own comments; owners/admins can delete any thread
|
|
4498
|
+
validation_failed Pass --thread-id`
|
|
4499
|
+
});
|
|
3612
4500
|
const commentsDefinition = define({
|
|
3613
4501
|
name: "comments",
|
|
3614
|
-
description: "Read and
|
|
4502
|
+
description: "Read, write, edit, resolve, reopen, and delete artifact comments.",
|
|
3615
4503
|
toKebab: true,
|
|
3616
4504
|
args: commonArgs,
|
|
3617
4505
|
subCommands: {
|
|
3618
4506
|
list: lazyCommand(commentsListDefinition, commentsListRunner),
|
|
3619
|
-
post: lazyCommand(commentsPostDefinition, commentsPostRunner)
|
|
4507
|
+
post: lazyCommand(commentsPostDefinition, commentsPostRunner),
|
|
4508
|
+
edit: lazyCommand(commentsEditDefinition, commentsEditRunner),
|
|
4509
|
+
resolve: lazyCommand(commentsResolveDefinition, commentsResolveRunner),
|
|
4510
|
+
reopen: lazyCommand(commentsReopenDefinition, commentsReopenRunner),
|
|
4511
|
+
delete: lazyCommand(commentsDeleteDefinition, commentsDeleteRunner)
|
|
3620
4512
|
},
|
|
3621
4513
|
examples: `npx --yes @artifactshare/cli comments list <artifact-id-or-url> --json
|
|
3622
|
-
npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body "<text>" --json
|
|
4514
|
+
npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body "<text>" --json
|
|
4515
|
+
npx --yes @artifactshare/cli comments edit <artifact-id-or-url> --message-id <message-id> --body "<text>" --json
|
|
4516
|
+
npx --yes @artifactshare/cli comments resolve <artifact-id-or-url> --thread-id <thread-id> --json
|
|
4517
|
+
npx --yes @artifactshare/cli comments delete <artifact-id-or-url> --thread-id <thread-id> --json
|
|
4518
|
+
|
|
4519
|
+
Deleting comments cannot be undone.`,
|
|
3623
4520
|
run: parentCommandRunner("comments")
|
|
3624
4521
|
});
|
|
3625
4522
|
const profilesListDefinition = define({
|
|
@@ -3724,17 +4621,79 @@ Common failures:
|
|
|
3724
4621
|
upload_not_allowed Your account cannot publish yet; request access from an operator
|
|
3725
4622
|
validation_failed Pass a non-empty name and valid --visibility`
|
|
3726
4623
|
});
|
|
4624
|
+
const projectsEditDefinition = define({
|
|
4625
|
+
name: "edit",
|
|
4626
|
+
description: "Edit project settings and audience.",
|
|
4627
|
+
toKebab: true,
|
|
4628
|
+
args: {
|
|
4629
|
+
...commonArgs,
|
|
4630
|
+
id: {
|
|
4631
|
+
type: "positional",
|
|
4632
|
+
description: "Project id"
|
|
4633
|
+
},
|
|
4634
|
+
name: {
|
|
4635
|
+
type: "string",
|
|
4636
|
+
toKebab: true,
|
|
4637
|
+
description: "New project name"
|
|
4638
|
+
},
|
|
4639
|
+
description: {
|
|
4640
|
+
type: "string",
|
|
4641
|
+
toKebab: true,
|
|
4642
|
+
description: "New project description; pass an empty value to clear it"
|
|
4643
|
+
},
|
|
4644
|
+
visibility: {
|
|
4645
|
+
type: "string",
|
|
4646
|
+
toKebab: true,
|
|
4647
|
+
description: "workspace or private"
|
|
4648
|
+
},
|
|
4649
|
+
addEmail: {
|
|
4650
|
+
type: "string",
|
|
4651
|
+
multiple: true,
|
|
4652
|
+
toKebab: true,
|
|
4653
|
+
description: "Add an audience email address; repeat for multiple"
|
|
4654
|
+
},
|
|
4655
|
+
removeEmail: {
|
|
4656
|
+
type: "string",
|
|
4657
|
+
multiple: true,
|
|
4658
|
+
toKebab: true,
|
|
4659
|
+
description: "Remove an audience email address; repeat for multiple"
|
|
4660
|
+
},
|
|
4661
|
+
archive: {
|
|
4662
|
+
type: "boolean",
|
|
4663
|
+
toKebab: true,
|
|
4664
|
+
description: "Archive the project after other edits"
|
|
4665
|
+
},
|
|
4666
|
+
unarchive: {
|
|
4667
|
+
type: "boolean",
|
|
4668
|
+
toKebab: true,
|
|
4669
|
+
description: "Unarchive the project before other edits"
|
|
4670
|
+
}
|
|
4671
|
+
},
|
|
4672
|
+
examples: `npx --yes @artifactshare/cli projects edit <id> --name "Launch review" --json
|
|
4673
|
+
npx --yes @artifactshare/cli projects edit <id> --visibility private --add-email viewer@example.com --json
|
|
4674
|
+
npx --yes @artifactshare/cli projects edit <id> --archive --json
|
|
4675
|
+
npx --yes @artifactshare/cli projects edit <id> --unarchive --description "" --json
|
|
4676
|
+
|
|
4677
|
+
Common failures:
|
|
4678
|
+
target_not_found Use a project id from projects list
|
|
4679
|
+
forbidden Only the creator or workspace admin can edit project settings
|
|
4680
|
+
project_archived Retry with --unarchive, or unarchive first
|
|
4681
|
+
too_many_grants Remove project audience entries before adding more
|
|
4682
|
+
validation_failed Pass a project id and at least one valid edit option`
|
|
4683
|
+
});
|
|
3727
4684
|
const projectsDefinition = define({
|
|
3728
4685
|
name: "projects",
|
|
3729
|
-
description: "Create and
|
|
4686
|
+
description: "Create, find, and edit publish destinations.",
|
|
3730
4687
|
toKebab: true,
|
|
3731
4688
|
args: commonArgs,
|
|
3732
4689
|
subCommands: {
|
|
3733
4690
|
list: lazyCommand(projectsListDefinition, projectsListRunner),
|
|
3734
|
-
create: lazyCommand(projectsCreateDefinition, projectsCreateRunner)
|
|
4691
|
+
create: lazyCommand(projectsCreateDefinition, projectsCreateRunner),
|
|
4692
|
+
edit: lazyCommand(projectsEditDefinition, projectsEditRunner)
|
|
3735
4693
|
},
|
|
3736
4694
|
examples: `npx --yes @artifactshare/cli projects list --json
|
|
3737
|
-
npx --yes @artifactshare/cli projects create "Launch review" --json
|
|
4695
|
+
npx --yes @artifactshare/cli projects create "Launch review" --json
|
|
4696
|
+
npx --yes @artifactshare/cli projects edit <id> --add-email viewer@example.com --json`,
|
|
3738
4697
|
run: parentCommandRunner("projects")
|
|
3739
4698
|
});
|
|
3740
4699
|
const skillsToolArgs = {
|
|
@@ -3809,6 +4768,30 @@ Only files created by skills install (managed marker present) are updated.
|
|
|
3809
4768
|
Common failures:
|
|
3810
4769
|
skill_update_conflict A managed marker is broken; inspect the file or reinstall with --force`
|
|
3811
4770
|
});
|
|
4771
|
+
const skillsEnsureDefinition = define({
|
|
4772
|
+
name: "ensure",
|
|
4773
|
+
description: "Install or update the bundled Artifact Share skill.",
|
|
4774
|
+
toKebab: true,
|
|
4775
|
+
args: {
|
|
4776
|
+
...commonArgs,
|
|
4777
|
+
...skillsToolArgs,
|
|
4778
|
+
dryRun: {
|
|
4779
|
+
type: "boolean",
|
|
4780
|
+
toKebab: true,
|
|
4781
|
+
description: "Show planned file changes without writing"
|
|
4782
|
+
}
|
|
4783
|
+
},
|
|
4784
|
+
examples: `npx --yes @artifactshare/cli skills ensure --tool auto --scope project --json
|
|
4785
|
+
npx --yes @artifactshare/cli skills ensure --tool claude --json
|
|
4786
|
+
|
|
4787
|
+
Use --tool auto from an agent workspace. It detects .claude, .agents/.codex,
|
|
4788
|
+
and .cursor in the current directory; if none are present, it prepares Codex
|
|
4789
|
+
and Claude Code project skills.
|
|
4790
|
+
|
|
4791
|
+
Common failures:
|
|
4792
|
+
validation_failed Pass --tool auto|codex|claude|cursor; auto supports --scope project only
|
|
4793
|
+
skill_update_conflict An unmanaged or broken skill file exists; inspect it before overwriting`
|
|
4794
|
+
});
|
|
3812
4795
|
const skillsRemoveDefinition = define({
|
|
3813
4796
|
name: "remove",
|
|
3814
4797
|
description: "Remove Artifact Share skills installed by this CLI.",
|
|
@@ -3831,9 +4814,11 @@ const skillsDefinition = define({
|
|
|
3831
4814
|
install: lazyCommand(skillsInstallDefinition, skillsInstallRunner),
|
|
3832
4815
|
list: lazyCommand(skillsListDefinition, skillsListRunner),
|
|
3833
4816
|
update: lazyCommand(skillsUpdateDefinition, skillsUpdateRunner),
|
|
4817
|
+
ensure: lazyCommand(skillsEnsureDefinition, skillsEnsureRunner),
|
|
3834
4818
|
remove: lazyCommand(skillsRemoveDefinition, skillsRemoveRunner)
|
|
3835
4819
|
},
|
|
3836
4820
|
examples: `npx --yes @artifactshare/cli skills install --tool codex --json
|
|
4821
|
+
npx --yes @artifactshare/cli skills ensure --tool auto --json
|
|
3837
4822
|
npx --yes @artifactshare/cli skills list --json`,
|
|
3838
4823
|
run: parentCommandRunner("skills")
|
|
3839
4824
|
});
|