@artifactshare/cli 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +248 -141
- package/package.json +7 -7
- package/skills/artifactshare/SKILL.md +22 -14
- package/skills/artifactshare/artifactshare.mdc +19 -7
package/dist/index.js
CHANGED
|
@@ -14,18 +14,18 @@ const CLI_INVOCATION = "npx --yes @artifactshare/cli";
|
|
|
14
14
|
const AGENT_DOWNLOAD_OUTPUT = "./artifact";
|
|
15
15
|
const TOKEN_ENV_VAR = "ARTIFACTSHARE_TOKEN";
|
|
16
16
|
const TOKEN_OPTION = "--token";
|
|
17
|
-
const IGNORED_FILENAMES = new Set([
|
|
17
|
+
const IGNORED_FILENAMES = /* @__PURE__ */ new Set([
|
|
18
18
|
".DS_Store",
|
|
19
19
|
"Thumbs.db",
|
|
20
20
|
"desktop.ini"
|
|
21
21
|
]);
|
|
22
|
-
const EXCLUDED_DIR_NAMES = new Set([
|
|
22
|
+
const EXCLUDED_DIR_NAMES = /* @__PURE__ */ new Set([
|
|
23
23
|
"node_modules",
|
|
24
24
|
".git",
|
|
25
25
|
".artifactshare",
|
|
26
26
|
".turbo"
|
|
27
27
|
]);
|
|
28
|
-
const BOOLEAN_FLAGS = new Set([
|
|
28
|
+
const BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
|
|
29
29
|
"allow-plaintext-token-store",
|
|
30
30
|
"archive",
|
|
31
31
|
"dry-run",
|
|
@@ -36,7 +36,7 @@ const BOOLEAN_FLAGS = new Set([
|
|
|
36
36
|
"insecure-localhost",
|
|
37
37
|
"unarchive"
|
|
38
38
|
]);
|
|
39
|
-
const VALUE_FLAGS = new Set([
|
|
39
|
+
const VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
40
40
|
"add-email",
|
|
41
41
|
"agent",
|
|
42
42
|
"base-url",
|
|
@@ -67,7 +67,7 @@ const VALUE_FLAGS = new Set([
|
|
|
67
67
|
"tool",
|
|
68
68
|
"visibility"
|
|
69
69
|
]);
|
|
70
|
-
const COMMAND_NAMES = new Set([
|
|
70
|
+
const COMMAND_NAMES = /* @__PURE__ */ new Set([
|
|
71
71
|
"login",
|
|
72
72
|
"logout",
|
|
73
73
|
"share",
|
|
@@ -117,7 +117,7 @@ const SUBCOMMANDS = {
|
|
|
117
117
|
"ensure"
|
|
118
118
|
]
|
|
119
119
|
};
|
|
120
|
-
const UPDATE_OPTION_KEYS = new Set([
|
|
120
|
+
const UPDATE_OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
121
121
|
"allowPlaintextTokenStore",
|
|
122
122
|
"baseUrl",
|
|
123
123
|
"help",
|
|
@@ -322,6 +322,15 @@ function mapApiError(status, body, options = {}) {
|
|
|
322
322
|
requiresHuman: false,
|
|
323
323
|
recovery: { kind: "change_input" }
|
|
324
324
|
});
|
|
325
|
+
if (apiCode === "project-limit-reached") return cliError({
|
|
326
|
+
code: "project_limit_reached",
|
|
327
|
+
message: apiMessage ?? "You've reached your plan's project limit. Upgrade your plan or archive existing projects.",
|
|
328
|
+
why: "The workspace already has the maximum number of active projects allowed by its plan.",
|
|
329
|
+
hint: "Archive an existing project, upgrade the workspace plan, or choose a different project.",
|
|
330
|
+
agentRecoverable: false,
|
|
331
|
+
requiresHuman: true,
|
|
332
|
+
recovery: { kind: "change_input" }
|
|
333
|
+
});
|
|
325
334
|
if (apiCode === "forbidden" || status === 403) return cliError({
|
|
326
335
|
code: "forbidden",
|
|
327
336
|
message: apiMessage ?? "You do not have permission to do that.",
|
|
@@ -437,6 +446,16 @@ function mapApiError(status, body, options = {}) {
|
|
|
437
446
|
requiresHuman: false,
|
|
438
447
|
recovery: { kind: "retry_later" }
|
|
439
448
|
});
|
|
449
|
+
if (apiCode === "maintenance") return cliError({
|
|
450
|
+
code: "maintenance",
|
|
451
|
+
message: apiMessage ?? "Artifact Share is currently under maintenance.",
|
|
452
|
+
why: "Artifact Share is temporarily unavailable while maintenance is in progress.",
|
|
453
|
+
hint: "Retry the same command in a few minutes.",
|
|
454
|
+
agentRecoverable: true,
|
|
455
|
+
requiresHuman: false,
|
|
456
|
+
recovery: { kind: "retry_later" },
|
|
457
|
+
details: { status }
|
|
458
|
+
});
|
|
440
459
|
return cliError({
|
|
441
460
|
code: "service_error",
|
|
442
461
|
message: apiMessage ?? `Artifact Share returned HTTP ${status}.`,
|
|
@@ -2243,7 +2262,7 @@ function whoamiProfile(body) {
|
|
|
2243
2262
|
}
|
|
2244
2263
|
//#endregion
|
|
2245
2264
|
//#region src/command-runners/auto-login.ts
|
|
2246
|
-
const JSON_PENDING_AUTH_COMMANDS = new Set([
|
|
2265
|
+
const JSON_PENDING_AUTH_COMMANDS = /* @__PURE__ */ new Set([
|
|
2247
2266
|
"share",
|
|
2248
2267
|
"update",
|
|
2249
2268
|
"download",
|
|
@@ -2283,12 +2302,9 @@ async function handleCredentialFailure(command, credential, options, mode, rerun
|
|
|
2283
2302
|
return rerun();
|
|
2284
2303
|
}
|
|
2285
2304
|
async function handleAuthenticatedCredentialFailure(command, error, credential, options, mode, rerun, isRetry = false) {
|
|
2286
|
-
|
|
2287
|
-
if (
|
|
2288
|
-
|
|
2289
|
-
if (refreshed.ok) return rerun();
|
|
2290
|
-
if (refreshed.error) return writeFailure(command, refreshed.error, mode, 1);
|
|
2291
|
-
}
|
|
2305
|
+
const refreshed = await refreshAuthenticatedCredential(error, credential, options, isRetry);
|
|
2306
|
+
if (refreshed.ok) return rerun();
|
|
2307
|
+
if (refreshed.error) return writeFailure(command, refreshed.error, mode, 1);
|
|
2292
2308
|
return await handleCredentialFailure(command, {
|
|
2293
2309
|
ok: false,
|
|
2294
2310
|
source: credential.source,
|
|
@@ -2296,6 +2312,33 @@ async function handleAuthenticatedCredentialFailure(command, error, credential,
|
|
|
2296
2312
|
error
|
|
2297
2313
|
}, options, mode, rerun, isRetry);
|
|
2298
2314
|
}
|
|
2315
|
+
async function refreshAuthenticatedCredential(error, credential, options, isRetry = false) {
|
|
2316
|
+
if (error.code !== "auth_required") return {
|
|
2317
|
+
ok: false,
|
|
2318
|
+
error
|
|
2319
|
+
};
|
|
2320
|
+
if (isRetry || !credential.profile || credential.profileCredentialKind !== "session" || !credential.refreshToken) return { ok: false };
|
|
2321
|
+
const refreshed = await refreshStoredProfileSession(credential.profile, credential.refreshToken, options);
|
|
2322
|
+
if (!refreshed.ok) return refreshed;
|
|
2323
|
+
return {
|
|
2324
|
+
ok: true,
|
|
2325
|
+
credential: {
|
|
2326
|
+
...credential,
|
|
2327
|
+
token: refreshed.token
|
|
2328
|
+
}
|
|
2329
|
+
};
|
|
2330
|
+
}
|
|
2331
|
+
async function runAuthenticatedApi(credential, options, request) {
|
|
2332
|
+
const first = await request(credential);
|
|
2333
|
+
if (!first.error) return first;
|
|
2334
|
+
const refreshed = await refreshAuthenticatedCredential(first.error, credential, options);
|
|
2335
|
+
if (!refreshed.ok) return refreshed.error ? {
|
|
2336
|
+
error: first.error,
|
|
2337
|
+
originalError: first.error,
|
|
2338
|
+
refreshError: refreshed.error
|
|
2339
|
+
} : { error: first.error };
|
|
2340
|
+
return await request(refreshed.credential);
|
|
2341
|
+
}
|
|
2299
2342
|
async function refreshStoredProfileSession(profile, refreshToken, options) {
|
|
2300
2343
|
const request = await requestConfig(options);
|
|
2301
2344
|
if (request.error) return {
|
|
@@ -2328,7 +2371,10 @@ async function refreshStoredProfileSession(profile, refreshToken, options) {
|
|
|
2328
2371
|
ok: false,
|
|
2329
2372
|
error: tokenStoreUnavailableError(profile)
|
|
2330
2373
|
};
|
|
2331
|
-
return {
|
|
2374
|
+
return {
|
|
2375
|
+
ok: true,
|
|
2376
|
+
token: body.access_token
|
|
2377
|
+
};
|
|
2332
2378
|
}
|
|
2333
2379
|
async function handleJsonPendingAuth(command, credential, options, mode, rerun) {
|
|
2334
2380
|
const profile = profileForAutoLogin(credential);
|
|
@@ -2433,19 +2479,24 @@ async function runArtifactsList(parsed, mode) {
|
|
|
2433
2479
|
if (home) url.searchParams.set("project_id", "");
|
|
2434
2480
|
else if (projectId) url.searchParams.set("project_id", projectId);
|
|
2435
2481
|
if (query) url.searchParams.set("query", query);
|
|
2436
|
-
const
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2482
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
2483
|
+
const response = await fetch(url, {
|
|
2484
|
+
headers: { Authorization: `Bearer ${current.token}` },
|
|
2485
|
+
...request.init
|
|
2486
|
+
}).catch((error) => ({ networkError: error }));
|
|
2487
|
+
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
2488
|
+
const body = await readJson(response);
|
|
2489
|
+
if (!response.ok) return { error: mapApiError(response.status, body, {
|
|
2490
|
+
authenticated: true,
|
|
2491
|
+
baseUrl: baseUrlOf(parsed.options),
|
|
2492
|
+
credentialSource: current.source,
|
|
2493
|
+
profile: current.profile,
|
|
2494
|
+
profileCredentialKind: current.profileCredentialKind
|
|
2495
|
+
}) };
|
|
2496
|
+
return { data: body };
|
|
2497
|
+
});
|
|
2498
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2499
|
+
const body = result.data;
|
|
2449
2500
|
if (!artifactsListSuccessFields(body)) return writeFailure(command, serviceError("Artifact list succeeded but the response did not include list metadata."), mode, 1);
|
|
2450
2501
|
return writeSuccess(command, body, mode);
|
|
2451
2502
|
}
|
|
@@ -2896,19 +2947,22 @@ async function runCommentsList(parsed, mode) {
|
|
|
2896
2947
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
2897
2948
|
const request = await requestConfig(parsed.options);
|
|
2898
2949
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2899
|
-
const result = await
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2950
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
2951
|
+
const comments = await apiGet(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, current.token, parsed.options, request.init, {
|
|
2952
|
+
artifactTarget: true,
|
|
2953
|
+
credentialSource: current.source,
|
|
2954
|
+
profile: current.profile,
|
|
2955
|
+
profileCredentialKind: current.profileCredentialKind
|
|
2956
|
+
});
|
|
2957
|
+
return comments.error ? { error: comments.error } : { data: comments.body };
|
|
2904
2958
|
});
|
|
2905
2959
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2906
|
-
const comments = Array.isArray(result.
|
|
2960
|
+
const comments = Array.isArray(result.data?.comments) ? result.data.comments : [];
|
|
2907
2961
|
writeSuccess(command, {
|
|
2908
2962
|
artifact_id: artifactId,
|
|
2909
|
-
share_url: configString(result.
|
|
2963
|
+
share_url: configString(result.data?.share_url),
|
|
2910
2964
|
comments,
|
|
2911
|
-
has_more: result.
|
|
2965
|
+
has_more: result.data?.has_more === true
|
|
2912
2966
|
}, mode);
|
|
2913
2967
|
if (!mode.json && comments.length === 0) writeText("No comments yet.\n");
|
|
2914
2968
|
}
|
|
@@ -2928,28 +2982,31 @@ async function runCommentsPost(parsed, mode) {
|
|
|
2928
2982
|
const request = await requestConfig(parsed.options);
|
|
2929
2983
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
2930
2984
|
const agent = parsed.options.agent;
|
|
2931
|
-
const result = await
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2985
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
2986
|
+
const posted = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, current.token, {
|
|
2987
|
+
body,
|
|
2988
|
+
reply_to: replyTo,
|
|
2989
|
+
quote,
|
|
2990
|
+
quote_before: parsed.options.quoteBefore,
|
|
2991
|
+
quote_after: parsed.options.quoteAfter,
|
|
2992
|
+
...agent ? { agent } : {}
|
|
2993
|
+
}, parsed.options, request.init, {
|
|
2994
|
+
artifactTarget: true,
|
|
2995
|
+
credentialSource: current.source,
|
|
2996
|
+
profile: current.profile,
|
|
2997
|
+
profileCredentialKind: current.profileCredentialKind
|
|
2998
|
+
});
|
|
2999
|
+
return posted.error ? { error: posted.error } : { data: posted.body };
|
|
2943
3000
|
});
|
|
2944
3001
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
2945
|
-
const threadId = configString(result.
|
|
3002
|
+
const threadId = configString(result.data?.thread_id);
|
|
2946
3003
|
if (!threadId) return writeFailure(command, serviceError("Comment was saved but the response had no thread id."), mode, 1);
|
|
2947
3004
|
writeSuccess(command, {
|
|
2948
3005
|
artifact_id: artifactId,
|
|
2949
|
-
share_url: configString(result.
|
|
3006
|
+
share_url: configString(result.data?.share_url),
|
|
2950
3007
|
thread_id: threadId,
|
|
2951
|
-
reply: result.
|
|
2952
|
-
thread: result.
|
|
3008
|
+
reply: result.data?.reply === true,
|
|
3009
|
+
thread: result.data?.thread ?? null
|
|
2953
3010
|
}, mode);
|
|
2954
3011
|
}
|
|
2955
3012
|
async function runCommentsEdit(parsed, mode) {
|
|
@@ -3038,21 +3095,24 @@ async function postCommentAction(parsed, command, artifactId, payload, mode) {
|
|
|
3038
3095
|
writeFailure(command, request.error, mode, 1);
|
|
3039
3096
|
return null;
|
|
3040
3097
|
}
|
|
3041
|
-
const result = await
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3098
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
3099
|
+
const action = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, current.token, payload, parsed.options, request.init, {
|
|
3100
|
+
artifactTarget: true,
|
|
3101
|
+
credentialSource: current.source,
|
|
3102
|
+
profile: current.profile,
|
|
3103
|
+
profileCredentialKind: current.profileCredentialKind
|
|
3104
|
+
});
|
|
3105
|
+
return action.error ? { error: action.error } : { data: action.body };
|
|
3046
3106
|
});
|
|
3047
3107
|
if (result.error) {
|
|
3048
3108
|
writeFailure(command, result.error, mode, 1);
|
|
3049
3109
|
return null;
|
|
3050
3110
|
}
|
|
3051
|
-
if (result.
|
|
3111
|
+
if (result.data === null) {
|
|
3052
3112
|
writeFailure(command, serviceError("Comment was changed but the response was empty."), mode, 1);
|
|
3053
3113
|
return null;
|
|
3054
3114
|
}
|
|
3055
|
-
return result.
|
|
3115
|
+
return result.data;
|
|
3056
3116
|
}
|
|
3057
3117
|
function requiredOption(value, message, hint) {
|
|
3058
3118
|
if (!value || !value.trim()) return { error: validationError(message, hint) };
|
|
@@ -3069,15 +3129,18 @@ async function runDelete(parsed, mode) {
|
|
|
3069
3129
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3070
3130
|
const request = await requestConfig(parsed.options);
|
|
3071
3131
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3072
|
-
const result = await
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3132
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
3133
|
+
const deleted = await apiDelete(`/api/cli/artifacts/${encodeURIComponent(artifactId)}`, current.token, parsed.options, request.init, {
|
|
3134
|
+
authenticated: true,
|
|
3135
|
+
artifactTarget: true,
|
|
3136
|
+
credentialSource: current.source,
|
|
3137
|
+
profile: current.profile,
|
|
3138
|
+
profileCredentialKind: current.profileCredentialKind
|
|
3139
|
+
});
|
|
3140
|
+
return deleted.error ? { error: deleted.error } : { data: deleted.body };
|
|
3078
3141
|
});
|
|
3079
3142
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3080
|
-
const body = result.
|
|
3143
|
+
const body = result.data;
|
|
3081
3144
|
if (!deleteSuccessFields(body)) return writeFailure(command, serviceError("Delete succeeded but the response did not include deletion metadata."), mode, 1);
|
|
3082
3145
|
return writeSuccess(command, body, mode);
|
|
3083
3146
|
}
|
|
@@ -3160,32 +3223,50 @@ async function runDoctor(parsed, mode) {
|
|
|
3160
3223
|
}
|
|
3161
3224
|
const request = await requestConfig(parsed.options);
|
|
3162
3225
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3163
|
-
const
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3226
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
3227
|
+
const response = await fetch(apiUrl("/api/cli/doctor", baseUrlOf(parsed.options)), {
|
|
3228
|
+
headers: { Authorization: `Bearer ${current.token}` },
|
|
3229
|
+
...request.init
|
|
3230
|
+
}).catch((error) => ({ networkError: error }));
|
|
3231
|
+
if ("networkError" in response) return { data: {
|
|
3232
|
+
kind: "network_failed",
|
|
3233
|
+
hint: networkError(response.networkError).hint
|
|
3234
|
+
} };
|
|
3235
|
+
const body = await readJson(response);
|
|
3236
|
+
if (!response.ok) return { error: mapApiError(response.status, body, {
|
|
3237
|
+
authenticated: true,
|
|
3238
|
+
baseUrl: baseUrlOf(parsed.options),
|
|
3239
|
+
credentialSource: current.source,
|
|
3240
|
+
profile: current.profile,
|
|
3241
|
+
profileCredentialKind: current.profileCredentialKind
|
|
3242
|
+
}) };
|
|
3243
|
+
return { data: {
|
|
3244
|
+
kind: "body",
|
|
3245
|
+
body
|
|
3246
|
+
} };
|
|
3247
|
+
});
|
|
3248
|
+
if (result.error) {
|
|
3249
|
+
const authError = result.refreshError ? result.originalError ?? result.error : result.error;
|
|
3250
|
+
if (result.refreshError?.code === "network_failed") data.network = {
|
|
3169
3251
|
ok: false,
|
|
3170
3252
|
code: "network_failed",
|
|
3171
|
-
hint:
|
|
3253
|
+
hint: result.refreshError.hint
|
|
3172
3254
|
};
|
|
3255
|
+
else data.network.ok = true;
|
|
3256
|
+
data.auth.code = authError.code;
|
|
3257
|
+
data.auth.hint = authError.hint;
|
|
3173
3258
|
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
3174
3259
|
}
|
|
3175
|
-
data.
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
credentialSource: credential.source,
|
|
3182
|
-
profile: credential.profile,
|
|
3183
|
-
profileCredentialKind: credential.profileCredentialKind
|
|
3184
|
-
});
|
|
3185
|
-
data.auth.code = error.code;
|
|
3186
|
-
data.auth.hint = error.hint;
|
|
3260
|
+
if (result.data.kind === "network_failed") {
|
|
3261
|
+
data.network = {
|
|
3262
|
+
ok: false,
|
|
3263
|
+
code: "network_failed",
|
|
3264
|
+
hint: result.data.hint
|
|
3265
|
+
};
|
|
3187
3266
|
return writeSuccess(command, doctorDataWithNextCommand(data), mode);
|
|
3188
3267
|
}
|
|
3268
|
+
data.network.ok = true;
|
|
3269
|
+
const body = result.data.body;
|
|
3189
3270
|
if (!body) throw new Error("Doctor response was not valid JSON.");
|
|
3190
3271
|
data.auth.ok = body.auth?.ok ?? true;
|
|
3191
3272
|
data.auth.email = body.user?.email ?? null;
|
|
@@ -3509,15 +3590,18 @@ async function runEdit(parsed, mode) {
|
|
|
3509
3590
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3510
3591
|
const request = await requestConfig(parsed.options);
|
|
3511
3592
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3512
|
-
const result = await
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3593
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
3594
|
+
const edited = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/edit`, current.token, payload.body, parsed.options, request.init, {
|
|
3595
|
+
artifactTarget: true,
|
|
3596
|
+
editSettings: true,
|
|
3597
|
+
credentialSource: current.source,
|
|
3598
|
+
profile: current.profile,
|
|
3599
|
+
profileCredentialKind: current.profileCredentialKind
|
|
3600
|
+
});
|
|
3601
|
+
return edited.error ? { error: edited.error } : { data: edited.body };
|
|
3518
3602
|
});
|
|
3519
3603
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3520
|
-
const data = parseEditData(result.
|
|
3604
|
+
const data = parseEditData(result.data);
|
|
3521
3605
|
if (!data) return writeFailure(command, serviceError("Edit succeeded but the response did not include edit data."), mode, 1);
|
|
3522
3606
|
writeSuccess(command, data, mode);
|
|
3523
3607
|
}
|
|
@@ -3797,14 +3881,17 @@ async function runMove(parsed, mode) {
|
|
|
3797
3881
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3798
3882
|
const request = await requestConfig(parsed.options);
|
|
3799
3883
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3800
|
-
const result = await
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3884
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
3885
|
+
const moved = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/move`, current.token, { destination: home ? "home" : { project_id: projectId } }, parsed.options, request.init, {
|
|
3886
|
+
artifactTarget: true,
|
|
3887
|
+
credentialSource: current.source,
|
|
3888
|
+
profile: current.profile,
|
|
3889
|
+
profileCredentialKind: current.profileCredentialKind
|
|
3890
|
+
});
|
|
3891
|
+
return moved.error ? { error: moved.error } : { data: moved.body };
|
|
3805
3892
|
});
|
|
3806
3893
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3807
|
-
const data = parseMoveData(result.
|
|
3894
|
+
const data = parseMoveData(result.data);
|
|
3808
3895
|
if (!data) return writeFailure(command, serviceError("Move succeeded but the response did not include move data."), mode, 1);
|
|
3809
3896
|
writeSuccess(command, data, mode);
|
|
3810
3897
|
}
|
|
@@ -3979,14 +4066,17 @@ async function runProjectsList(parsed, mode) {
|
|
|
3979
4066
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
3980
4067
|
const request = await requestConfig(parsed.options);
|
|
3981
4068
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
3982
|
-
const result = await
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
4069
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4070
|
+
const fetched = await fetchProjects(current.token, parsed.options, request.init, {
|
|
4071
|
+
credentialSource: current.source,
|
|
4072
|
+
profile: current.profile,
|
|
4073
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4074
|
+
});
|
|
4075
|
+
return fetched.error ? { error: fetched.error } : { data: fetched.projects };
|
|
3986
4076
|
});
|
|
3987
4077
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
3988
4078
|
const defaultProjectId = configString(projectConfig.config?.default_project_id);
|
|
3989
|
-
const projects = result.
|
|
4079
|
+
const projects = result.data.map((project) => ({
|
|
3990
4080
|
...project,
|
|
3991
4081
|
is_default: project.id === defaultProjectId
|
|
3992
4082
|
}));
|
|
@@ -4007,17 +4097,20 @@ async function runProjectsCreate(parsed, mode) {
|
|
|
4007
4097
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
4008
4098
|
const request = await requestConfig(parsed.options);
|
|
4009
4099
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
4010
|
-
const result = await
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4100
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4101
|
+
const created = await apiPost("/api/cli/projects", current.token, {
|
|
4102
|
+
name,
|
|
4103
|
+
description: parsed.options.description ?? null,
|
|
4104
|
+
base_visibility: visibility ?? null
|
|
4105
|
+
}, parsed.options, request.init, {
|
|
4106
|
+
credentialSource: current.source,
|
|
4107
|
+
profile: current.profile,
|
|
4108
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4109
|
+
});
|
|
4110
|
+
return created.error ? { error: created.error } : { data: created.body };
|
|
4018
4111
|
});
|
|
4019
4112
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
4020
|
-
const project = isRecord(result.
|
|
4113
|
+
const project = isRecord(result.data?.project) ? result.data.project : null;
|
|
4021
4114
|
const id = configString(project?.id);
|
|
4022
4115
|
if (!id) return writeFailure(command, serviceError("Project create succeeded but no project id was returned."), mode, 1);
|
|
4023
4116
|
writeSuccess(command, {
|
|
@@ -4041,14 +4134,17 @@ async function runProjectsEdit(parsed, mode) {
|
|
|
4041
4134
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
4042
4135
|
const request = await requestConfig(parsed.options);
|
|
4043
4136
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
4044
|
-
const result = await
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4137
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4138
|
+
const edited = await apiPost(`/api/cli/projects/${encodeURIComponent(projectId)}`, current.token, payload.body, parsed.options, request.init, {
|
|
4139
|
+
projectTarget: true,
|
|
4140
|
+
credentialSource: current.source,
|
|
4141
|
+
profile: current.profile,
|
|
4142
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4143
|
+
});
|
|
4144
|
+
return edited.error ? { error: edited.error } : { data: edited.body };
|
|
4049
4145
|
});
|
|
4050
4146
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
4051
|
-
const data = parseProjectsEditData(result.
|
|
4147
|
+
const data = parseProjectsEditData(result.data);
|
|
4052
4148
|
if (!data) return writeFailure(command, serviceError("Project edit succeeded but the response did not include project data."), mode, 1);
|
|
4053
4149
|
writeSuccess(command, data, mode);
|
|
4054
4150
|
}
|
|
@@ -4240,13 +4336,16 @@ async function runRequestAccess(parsed, mode) {
|
|
|
4240
4336
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
4241
4337
|
const request = await requestConfig(parsed.options);
|
|
4242
4338
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
4243
|
-
const result = await
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4339
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4340
|
+
const requested = await apiPost("/api/cli/request-access", current.token, { note }, parsed.options, request.init, {
|
|
4341
|
+
credentialSource: current.source,
|
|
4342
|
+
profile: current.profile,
|
|
4343
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4344
|
+
});
|
|
4345
|
+
return requested.error ? { error: requested.error } : { data: requested.body };
|
|
4247
4346
|
});
|
|
4248
4347
|
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
4249
|
-
const body = result.
|
|
4348
|
+
const body = result.data;
|
|
4250
4349
|
const data = {
|
|
4251
4350
|
requested: body?.requested === true,
|
|
4252
4351
|
already_enabled: body?.already_enabled === true,
|
|
@@ -4270,19 +4369,24 @@ async function runResolve(parsed, mode) {
|
|
|
4270
4369
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
4271
4370
|
const url = apiUrl("/api/cli/resolve", baseUrlOf(parsed.options));
|
|
4272
4371
|
url.searchParams.set("q", value);
|
|
4273
|
-
const
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4372
|
+
const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4373
|
+
const response = await fetch(url, {
|
|
4374
|
+
headers: { Authorization: `Bearer ${current.token}` },
|
|
4375
|
+
...request.init
|
|
4376
|
+
}).catch((error) => ({ networkError: error }));
|
|
4377
|
+
if ("networkError" in response) return { error: networkError(response.networkError) };
|
|
4378
|
+
const body = await readJson(response);
|
|
4379
|
+
if (!response.ok) return { error: mapApiError(response.status, body, {
|
|
4380
|
+
authenticated: true,
|
|
4381
|
+
baseUrl: baseUrlOf(parsed.options),
|
|
4382
|
+
credentialSource: current.source,
|
|
4383
|
+
profile: current.profile,
|
|
4384
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4385
|
+
}) };
|
|
4386
|
+
return { data: body };
|
|
4387
|
+
});
|
|
4388
|
+
if (result.error) return writeFailure(command, result.error, mode, 1);
|
|
4389
|
+
const body = result.data;
|
|
4286
4390
|
if (!resolveSuccessFields(body)) return writeFailure(command, serviceError("Resolve succeeded but the response did not include query, candidates, and has_more."), mode, 1);
|
|
4287
4391
|
return writeSuccess(command, body, mode);
|
|
4288
4392
|
}
|
|
@@ -4346,14 +4450,17 @@ async function runWhoami(parsed, mode) {
|
|
|
4346
4450
|
if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
|
|
4347
4451
|
const request = await requestConfig(parsed.options);
|
|
4348
4452
|
if (request.error) return writeFailure(command, request.error, mode, 1);
|
|
4349
|
-
const whoami = await
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4453
|
+
const whoami = await runAuthenticatedApi(credential, parsed.options, async (current) => {
|
|
4454
|
+
const result = await apiGet("/api/cli/whoami", current.token, parsed.options, request.init, {
|
|
4455
|
+
credentialSource: current.source,
|
|
4456
|
+
profile: current.profile,
|
|
4457
|
+
profileCredentialKind: current.profileCredentialKind
|
|
4458
|
+
});
|
|
4459
|
+
return result.error ? { error: result.error } : { data: result.body };
|
|
4353
4460
|
});
|
|
4354
4461
|
if (whoami.error) return writeFailure(command, whoami.error, mode, 1);
|
|
4355
|
-
return writeSuccess(command, isRecord(whoami.
|
|
4356
|
-
...whoami.
|
|
4462
|
+
return writeSuccess(command, isRecord(whoami.data) ? {
|
|
4463
|
+
...whoami.data,
|
|
4357
4464
|
credential_source: credential.source
|
|
4358
4465
|
} : { credential_source: credential.source }, mode);
|
|
4359
4466
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artifactshare/cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Upload and share HTML, Markdown, folders, and static sites from terminals, AI agents, automation, and CI.",
|
|
5
5
|
"homepage": "https://artifactshare.com/connect",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"artifactshare": "./dist/index.js"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": ">=22"
|
|
22
|
+
"node": ">=22.19.0"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"gunshi": "^0.
|
|
35
|
-
"undici": "^
|
|
34
|
+
"gunshi": "^0.35.1",
|
|
35
|
+
"undici": "^8.5.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/node": "
|
|
39
|
-
"tsdown": "^0.22.
|
|
38
|
+
"@types/node": "26.0.0",
|
|
39
|
+
"tsdown": "^0.22.3",
|
|
40
40
|
"typescript": "6.0.3",
|
|
41
|
-
"vitest": "4.1.
|
|
41
|
+
"vitest": "4.1.9"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsdown",
|
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: artifactshare
|
|
3
|
-
description:
|
|
3
|
+
description: Share, publish, upload, host, update, open, or read back existing files and Artifact Share URLs. Use when the user wants a browser link for an HTML/Markdown report, folder, static site, or generated file; wants to update the same URL; says Artifact Share, artifactshare, or contextual "as"; or asks to read comments from a shared URL.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
<!-- artifactshare-skill
|
|
7
|
-
version:
|
|
7
|
+
version: 22
|
|
8
8
|
managed: true
|
|
9
9
|
-->
|
|
10
10
|
|
|
11
11
|
# Artifact Share CLI
|
|
12
12
|
|
|
13
|
-
Artifact Share
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
Artifact Share is for the last step after a file already exists: share,
|
|
14
|
+
publish, upload, or host HTML pages, Markdown documents, folders, and static
|
|
15
|
+
sites; return a browser link; update the same URL; open or read back an
|
|
16
|
+
Artifact Share URL; and read or post comments. The CLI is designed for agents:
|
|
17
|
+
every command supports `--json` with a stable contract.
|
|
18
|
+
|
|
19
|
+
Use this skill for Artifact Share, artifactshare, and contextual "as" requests.
|
|
20
|
+
Japanese requests such as `as でアップして` or `as に上げて` are strong
|
|
21
|
+
Artifact Share intents. In English, treat "as" as a user shorthand only when
|
|
22
|
+
the surrounding request is about sharing, publishing, updating, opening, or
|
|
23
|
+
reading a shared URL; bare English "as" alone is not an Artifact Share trigger.
|
|
24
|
+
|
|
25
|
+
Do not use this skill just because the user says "artifact". Claude Artifact is
|
|
26
|
+
for creating or designing an artifact inside the chat. Artifact Share is for
|
|
27
|
+
sharing, updating, opening, or reading back existing files, folders, static
|
|
28
|
+
sites, and Artifact Share URLs.
|
|
17
29
|
|
|
18
30
|
Run commands with `npx --yes @artifactshare/cli`. When unsure about a
|
|
19
31
|
command or flag, run `npx --yes @artifactshare/cli <command> --help` first.
|
|
@@ -74,7 +86,10 @@ npx --yes @artifactshare/cli share ./site-dir --project-id <id> --json
|
|
|
74
86
|
```
|
|
75
87
|
|
|
76
88
|
- `share` accepts a single `.html` / `.md` file or a static-site directory.
|
|
77
|
-
|
|
89
|
+
In JSON output, give the user `data.artifact.url`; the artifact ID is
|
|
90
|
+
`data.artifact.id`.
|
|
91
|
+
Do not rerun `share` just to inspect the JSON shape: without `--key`, each
|
|
92
|
+
successful run creates a new artifact.
|
|
78
93
|
- Pick the destination with `--project-id <id>`, `--project <name>` (by exact
|
|
79
94
|
name, no prior `resolve` needed), the saved default from `init`, or `--home`.
|
|
80
95
|
Without any of these it fails with `destination_required`.
|
|
@@ -235,13 +250,6 @@ npx --yes @artifactshare/cli skills list --json
|
|
|
235
250
|
`ask_human`, `report_issue`. When `error.requires_human` is true, report to
|
|
236
251
|
the user instead of retrying.
|
|
237
252
|
|
|
238
|
-
## Upload access
|
|
239
|
-
|
|
240
|
-
If `share` or `update` fails with `upload_not_allowed`, run
|
|
241
|
-
`request-access --note '<why>' --json` to join the waitlist, then tell the
|
|
242
|
-
user that sharing stays closed until an operator opens it. Do not retry
|
|
243
|
-
share in a loop.
|
|
244
|
-
|
|
245
253
|
## First-time setup
|
|
246
254
|
|
|
247
255
|
`npx --yes @artifactshare/cli init` detects the agent, installs or updates
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
---
|
|
2
|
-
description:
|
|
2
|
+
description: Share, publish, upload, host, update, open, or read back existing files and Artifact Share URLs.
|
|
3
3
|
alwaysApply: false
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
<!-- artifactshare-skill
|
|
7
|
-
version:
|
|
7
|
+
version: 22
|
|
8
8
|
managed: true
|
|
9
9
|
-->
|
|
10
10
|
|
|
11
11
|
# Artifact Share CLI
|
|
12
12
|
|
|
13
|
-
Artifact Share
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
Artifact Share is for the last step after a file already exists: share,
|
|
14
|
+
publish, upload, or host HTML pages, Markdown documents, folders, and static
|
|
15
|
+
sites; return a browser link; update the same URL; open or read back an
|
|
16
|
+
Artifact Share URL; and read or post comments. Use
|
|
17
|
+
`npx --yes @artifactshare/cli` from the terminal.
|
|
16
18
|
Run `npx --yes @artifactshare/cli <command> --help` before choosing a command.
|
|
17
19
|
|
|
20
|
+
Use this rule for Artifact Share, artifactshare, and contextual "as" requests.
|
|
21
|
+
Japanese requests such as `as でアップして` or `as に上げて` are strong
|
|
22
|
+
Artifact Share intents. In English, treat "as" as a user shorthand only when
|
|
23
|
+
the surrounding request is about sharing, publishing, updating, opening, or
|
|
24
|
+
reading a shared URL; bare English "as" alone is not an Artifact Share trigger.
|
|
25
|
+
|
|
26
|
+
Do not use this rule just because the user says "artifact". Claude Artifact is
|
|
27
|
+
for creating or designing an artifact inside the chat. Artifact Share is for
|
|
28
|
+
sharing, updating, opening, or reading back existing files, folders, static
|
|
29
|
+
sites, and Artifact Share URLs.
|
|
30
|
+
|
|
18
31
|
Use the CLI for local files and folders. The remote MCP tools accept HTML or
|
|
19
32
|
Markdown source strings; they cannot read paths like `/Users/.../report.html`
|
|
20
33
|
from the user's filesystem.
|
|
@@ -30,7 +43,7 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
30
43
|
- Remove a saved local credential with `logout --profile <name> --json`; this keeps profile metadata and does not revoke API tokens on the server.
|
|
31
44
|
- Switch profiles with `profiles use <name> --json`; list with `profiles list --json`; remove a profile entry and its credential with `profiles delete <name> --json`.
|
|
32
45
|
- When the user gives an Artifact Share URL, start with `open <artifact-id-or-url> --json`. It ensures this rule is installed or updated, then reads single-file artifacts or returns a `download` next command for static sites and multi-file artifacts.
|
|
33
|
-
- Share with `share <path> --json`. Pick the destination with `--project-id <id>`, `--project <name>` (by exact name), the saved default, or `--home`. Set visibility with `--visibility private|workspace|project`; when `--grant-email` is passed the default becomes `private`.
|
|
46
|
+
- Share with `share <path> --json`. In JSON output, give the user `data.artifact.url`; the artifact ID is `data.artifact.id`. Do not rerun `share` just to inspect the JSON shape: without `--key`, each successful run creates a new artifact. Pick the destination with `--project-id <id>`, `--project <name>` (by exact name), the saved default, or `--home`. Set visibility with `--visibility private|workspace|project`; when `--grant-email` is passed the default becomes `private`.
|
|
34
47
|
- For repeat jobs with a stable caller-owned name, use `share <path> --key <key> --json`: the first run creates the artifact, later runs add versions to the same artifact.
|
|
35
48
|
- To keep an existing share URL, do not use `share --artifact-id`; add a version with `update <artifact-id-or-url> <path> --json`. `update` does not change title, visibility, viewers, or placement.
|
|
36
49
|
- Read back with `artifacts get <target> --json`. Pass `--include versions` or `--include comments` to fetch history or comments in one call. If truncated, call again with `--offset` set to `next_offset`.
|
|
@@ -43,6 +56,5 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
|
|
|
43
56
|
- Manage projects: `projects list --json`, `projects create <name> --json` (defaults to `--visibility workspace`; pass `--visibility private` for confidential projects), `projects edit <id>` for name, description, visibility, audience (`--add-email`/`--remove-email`), and archive state (`--archive`/`--unarchive`).
|
|
44
57
|
- Save a default project with `init --project-id <id> --json`. Preview setup with `init --dry-run --json`.
|
|
45
58
|
- Manage skills: `skills ensure --tool auto --json` detects the agent and installs or reports updates; `skills update --json` updates installed skills to the bundled version; `skills install --tool <name> --scope user --json` installs at the user level (`--force` overwrites unmanaged files).
|
|
46
|
-
- On `upload_not_allowed`, run `request-access --note '<why>' --json` and tell the user an operator opens sharing; do not retry in a loop.
|
|
47
59
|
- Check the current state with `whoami --json` or `doctor --json` for authentication, destination, network, upload access, and skill update status.
|
|
48
60
|
- First-time setup: `npx --yes @artifactshare/cli init --json` detects the agent, installs or updates this rule, and reports the next steps (sign in, then share).
|