@artifactshare/cli 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -80,7 +80,7 @@ npx --yes @artifactshare/cli open <artifact-id-or-url> --json
80
80
 
81
81
  This installs or updates the local skill first, then reads single-file artifacts. Static sites and multi-file artifacts return a `download` next command.
82
82
 
83
- To target a specific tool manually, use `skills install --tool <codex|claude|cursor>`; `skills ensure --tool auto` is the same detection `init` uses.
83
+ To target a specific tool manually, use `skills install --tool <codex|claude|cursor>`; `skills ensure --tool auto` is the same detection `init` uses. Regular successful commands also update outdated managed user-scope Codex and Claude Code skills when they are already installed.
84
84
 
85
85
  Comment deletion is permanent. Use `comments delete <target> --thread-id <id> --message-id <id> --json` for one message, or omit `--message-id` only when deleting the whole thread.
86
86
 
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}.`,
@@ -980,6 +999,18 @@ function writeSuccess(command, data, mode) {
980
999
  }
981
1000
  process.stdout.write(humanSuccess(command, data));
982
1001
  }
1002
+ function dataWithSkillAutoUpdate(data, autoUpdate) {
1003
+ if (!autoUpdate || autoUpdate.targets.length === 0) return data;
1004
+ if (!isRecord(data)) return data;
1005
+ const existingSkills = isRecord(data.skills) ? data.skills : {};
1006
+ return {
1007
+ ...data,
1008
+ skills: {
1009
+ ...existingSkills,
1010
+ auto_update: autoUpdate
1011
+ }
1012
+ };
1013
+ }
983
1014
  function writeFailure(command, error, mode, exitCode) {
984
1015
  const payload = {
985
1016
  schema_version: 2,
@@ -998,10 +1029,11 @@ function writeEvent(data) {
998
1029
  process.stderr.write(`${JSON.stringify(data)}\n`);
999
1030
  }
1000
1031
  function humanSuccess(command, data) {
1032
+ const suffix = skillAutoUpdateHumanOutput(data);
1001
1033
  if (command === "share") {
1002
1034
  const fields = shareSuccessFields(data);
1003
1035
  if (!fields) return `${JSON.stringify(data, null, 2)}\n`;
1004
- return [
1036
+ const output = [
1005
1037
  "Shared",
1006
1038
  `Artifact ID: ${fields.artifactId}`,
1007
1039
  `URL: ${fields.url}`,
@@ -1009,11 +1041,26 @@ function humanSuccess(command, data) {
1009
1041
  `Visibility: ${fields.visibility}`,
1010
1042
  ""
1011
1043
  ].join("\n");
1044
+ return suffix ? `${output}${suffix}` : output;
1012
1045
  }
1013
1046
  if (command === "doctor") return doctorHumanOutput(data);
1014
1047
  if (command === "open") return openHumanOutput(data);
1015
1048
  if (command === "init") return initHumanOutput(data);
1016
- return `${JSON.stringify(data, null, 2)}\n`;
1049
+ const output = `${JSON.stringify(data, null, 2)}\n`;
1050
+ return suffix ? `${output}${suffix}` : output;
1051
+ }
1052
+ function skillAutoUpdateHumanOutput(data) {
1053
+ if (!isRecord(data)) return "";
1054
+ const skills = data.skills;
1055
+ if (!isRecord(skills)) return "";
1056
+ const autoUpdate = skills.auto_update;
1057
+ if (!isRecord(autoUpdate) || !Array.isArray(autoUpdate.targets)) return "";
1058
+ const lines = autoUpdate.targets.filter(isRecord).map((target) => {
1059
+ const label = typeof target.tool === "string" && typeof target.scope === "string" ? `${target.tool}:${target.scope}` : "unknown";
1060
+ if (target.action === "update_recommended" && typeof target.update_command === "string") return `Skill update recommended: ${label} (${target.update_command})`;
1061
+ return `Skill updated: ${label}`;
1062
+ });
1063
+ return lines.length > 0 ? `${lines.join("\n")}\n` : "";
1017
1064
  }
1018
1065
  function initHumanOutput(data) {
1019
1066
  const body = `${JSON.stringify(data, null, 2)}`;
@@ -2243,7 +2290,7 @@ function whoamiProfile(body) {
2243
2290
  }
2244
2291
  //#endregion
2245
2292
  //#region src/command-runners/auto-login.ts
2246
- const JSON_PENDING_AUTH_COMMANDS = new Set([
2293
+ const JSON_PENDING_AUTH_COMMANDS = /* @__PURE__ */ new Set([
2247
2294
  "share",
2248
2295
  "update",
2249
2296
  "download",
@@ -2283,12 +2330,9 @@ async function handleCredentialFailure(command, credential, options, mode, rerun
2283
2330
  return rerun();
2284
2331
  }
2285
2332
  async function handleAuthenticatedCredentialFailure(command, error, credential, options, mode, rerun, isRetry = false) {
2286
- if (error.code !== "auth_required") return writeFailure(command, error, mode, 1);
2287
- if (!isRetry && credential.profile && credential.profileCredentialKind === "session" && credential.refreshToken) {
2288
- const refreshed = await refreshStoredProfileSession(credential.profile, credential.refreshToken, options);
2289
- if (refreshed.ok) return rerun();
2290
- if (refreshed.error) return writeFailure(command, refreshed.error, mode, 1);
2291
- }
2333
+ const refreshed = await refreshAuthenticatedCredential(error, credential, options, isRetry);
2334
+ if (refreshed.ok) return rerun();
2335
+ if (refreshed.error) return writeFailure(command, refreshed.error, mode, 1);
2292
2336
  return await handleCredentialFailure(command, {
2293
2337
  ok: false,
2294
2338
  source: credential.source,
@@ -2296,6 +2340,33 @@ async function handleAuthenticatedCredentialFailure(command, error, credential,
2296
2340
  error
2297
2341
  }, options, mode, rerun, isRetry);
2298
2342
  }
2343
+ async function refreshAuthenticatedCredential(error, credential, options, isRetry = false) {
2344
+ if (error.code !== "auth_required") return {
2345
+ ok: false,
2346
+ error
2347
+ };
2348
+ if (isRetry || !credential.profile || credential.profileCredentialKind !== "session" || !credential.refreshToken) return { ok: false };
2349
+ const refreshed = await refreshStoredProfileSession(credential.profile, credential.refreshToken, options);
2350
+ if (!refreshed.ok) return refreshed;
2351
+ return {
2352
+ ok: true,
2353
+ credential: {
2354
+ ...credential,
2355
+ token: refreshed.token
2356
+ }
2357
+ };
2358
+ }
2359
+ async function runAuthenticatedApi(credential, options, request) {
2360
+ const first = await request(credential);
2361
+ if (!first.error) return first;
2362
+ const refreshed = await refreshAuthenticatedCredential(first.error, credential, options);
2363
+ if (!refreshed.ok) return refreshed.error ? {
2364
+ error: first.error,
2365
+ originalError: first.error,
2366
+ refreshError: refreshed.error
2367
+ } : { error: first.error };
2368
+ return await request(refreshed.credential);
2369
+ }
2299
2370
  async function refreshStoredProfileSession(profile, refreshToken, options) {
2300
2371
  const request = await requestConfig(options);
2301
2372
  if (request.error) return {
@@ -2328,7 +2399,10 @@ async function refreshStoredProfileSession(profile, refreshToken, options) {
2328
2399
  ok: false,
2329
2400
  error: tokenStoreUnavailableError(profile)
2330
2401
  };
2331
- return { ok: true };
2402
+ return {
2403
+ ok: true,
2404
+ token: body.access_token
2405
+ };
2332
2406
  }
2333
2407
  async function handleJsonPendingAuth(command, credential, options, mode, rerun) {
2334
2408
  const profile = profileForAutoLogin(credential);
@@ -2433,19 +2507,24 @@ async function runArtifactsList(parsed, mode) {
2433
2507
  if (home) url.searchParams.set("project_id", "");
2434
2508
  else if (projectId) url.searchParams.set("project_id", projectId);
2435
2509
  if (query) url.searchParams.set("query", query);
2436
- const response = await fetch(url, {
2437
- headers: { Authorization: `Bearer ${credential.token}` },
2438
- ...request.init
2439
- }).catch((error) => ({ networkError: error }));
2440
- if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
2441
- const body = await readJson(response);
2442
- if (!response.ok) return writeFailure(command, mapApiError(response.status, body, {
2443
- authenticated: true,
2444
- baseUrl: baseUrlOf(parsed.options),
2445
- credentialSource: credential.source,
2446
- profile: credential.profile,
2447
- profileCredentialKind: credential.profileCredentialKind
2448
- }), mode, 1);
2510
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
2511
+ const response = await fetch(url, {
2512
+ headers: { Authorization: `Bearer ${current.token}` },
2513
+ ...request.init
2514
+ }).catch((error) => ({ networkError: error }));
2515
+ if ("networkError" in response) return { error: networkError(response.networkError) };
2516
+ const body = await readJson(response);
2517
+ if (!response.ok) return { error: mapApiError(response.status, body, {
2518
+ authenticated: true,
2519
+ baseUrl: baseUrlOf(parsed.options),
2520
+ credentialSource: current.source,
2521
+ profile: current.profile,
2522
+ profileCredentialKind: current.profileCredentialKind
2523
+ }) };
2524
+ return { data: body };
2525
+ });
2526
+ if (result.error) return writeFailure(command, result.error, mode, 1);
2527
+ const body = result.data;
2449
2528
  if (!artifactsListSuccessFields(body)) return writeFailure(command, serviceError("Artifact list succeeded but the response did not include list metadata."), mode, 1);
2450
2529
  return writeSuccess(command, body, mode);
2451
2530
  }
@@ -2743,6 +2822,46 @@ async function ensureSkills(parsed, mode, options = {}) {
2743
2822
  }
2744
2823
  return finishActions(command, planned, parsed.options.dryRun === true, mode);
2745
2824
  }
2825
+ async function autoUpdateUserManagedSkills() {
2826
+ try {
2827
+ const bundled = await loadBundledSkills();
2828
+ const planned = [];
2829
+ for (const target of allTargets().filter((candidate) => candidate.scope === "user")) {
2830
+ const state = await readTarget(target);
2831
+ if (state.kind !== "managed" || state.version >= bundled.version) continue;
2832
+ planned.push({
2833
+ target,
2834
+ action: "updated",
2835
+ content: bundled.contents[target.tool],
2836
+ fallbackAction: "update_recommended",
2837
+ installedVersion: state.version
2838
+ });
2839
+ }
2840
+ if (planned.length === 0) return void 0;
2841
+ const completed = [...planned];
2842
+ for (const [index, item] of planned.entries()) try {
2843
+ await applyAction(item);
2844
+ completed[index] = item;
2845
+ } catch {
2846
+ completed[index] = {
2847
+ target: item.target,
2848
+ action: "update_recommended",
2849
+ ...item.installedVersion !== void 0 ? { installedVersion: item.installedVersion } : {}
2850
+ };
2851
+ }
2852
+ return { targets: completed.map(({ target, action, installedVersion }) => ({
2853
+ tool: target.tool,
2854
+ scope: "user",
2855
+ path: target.path,
2856
+ action: action === "updated" ? "updated" : "update_recommended",
2857
+ installed_version: installedVersion ?? bundled.version,
2858
+ bundled_version: bundled.version,
2859
+ ...action === "update_recommended" ? { update_command: skillUpdateCommand(target) } : {}
2860
+ })) };
2861
+ } catch {
2862
+ return;
2863
+ }
2864
+ }
2746
2865
  async function runSkillsEnsure(parsed, mode) {
2747
2866
  const data = await ensureSkills(parsed, mode);
2748
2867
  if (data) writeSuccess("skills ensure", data, mode);
@@ -2896,19 +3015,22 @@ async function runCommentsList(parsed, mode) {
2896
3015
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
2897
3016
  const request = await requestConfig(parsed.options);
2898
3017
  if (request.error) return writeFailure(command, request.error, mode, 1);
2899
- const result = await apiGet(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, parsed.options, request.init, {
2900
- artifactTarget: true,
2901
- credentialSource: credential.source,
2902
- profile: credential.profile,
2903
- profileCredentialKind: credential.profileCredentialKind
3018
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
3019
+ const comments = await apiGet(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, current.token, parsed.options, request.init, {
3020
+ artifactTarget: true,
3021
+ credentialSource: current.source,
3022
+ profile: current.profile,
3023
+ profileCredentialKind: current.profileCredentialKind
3024
+ });
3025
+ return comments.error ? { error: comments.error } : { data: comments.body };
2904
3026
  });
2905
3027
  if (result.error) return writeFailure(command, result.error, mode, 1);
2906
- const comments = Array.isArray(result.body?.comments) ? result.body.comments : [];
3028
+ const comments = Array.isArray(result.data?.comments) ? result.data.comments : [];
2907
3029
  writeSuccess(command, {
2908
3030
  artifact_id: artifactId,
2909
- share_url: configString(result.body?.share_url),
3031
+ share_url: configString(result.data?.share_url),
2910
3032
  comments,
2911
- has_more: result.body?.has_more === true
3033
+ has_more: result.data?.has_more === true
2912
3034
  }, mode);
2913
3035
  if (!mode.json && comments.length === 0) writeText("No comments yet.\n");
2914
3036
  }
@@ -2928,28 +3050,31 @@ async function runCommentsPost(parsed, mode) {
2928
3050
  const request = await requestConfig(parsed.options);
2929
3051
  if (request.error) return writeFailure(command, request.error, mode, 1);
2930
3052
  const agent = parsed.options.agent;
2931
- const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, {
2932
- body,
2933
- reply_to: replyTo,
2934
- quote,
2935
- quote_before: parsed.options.quoteBefore,
2936
- quote_after: parsed.options.quoteAfter,
2937
- ...agent ? { agent } : {}
2938
- }, parsed.options, request.init, {
2939
- artifactTarget: true,
2940
- credentialSource: credential.source,
2941
- profile: credential.profile,
2942
- profileCredentialKind: credential.profileCredentialKind
3053
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
3054
+ const posted = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, current.token, {
3055
+ body,
3056
+ reply_to: replyTo,
3057
+ quote,
3058
+ quote_before: parsed.options.quoteBefore,
3059
+ quote_after: parsed.options.quoteAfter,
3060
+ ...agent ? { agent } : {}
3061
+ }, parsed.options, request.init, {
3062
+ artifactTarget: true,
3063
+ credentialSource: current.source,
3064
+ profile: current.profile,
3065
+ profileCredentialKind: current.profileCredentialKind
3066
+ });
3067
+ return posted.error ? { error: posted.error } : { data: posted.body };
2943
3068
  });
2944
3069
  if (result.error) return writeFailure(command, result.error, mode, 1);
2945
- const threadId = configString(result.body?.thread_id);
3070
+ const threadId = configString(result.data?.thread_id);
2946
3071
  if (!threadId) return writeFailure(command, serviceError("Comment was saved but the response had no thread id."), mode, 1);
2947
3072
  writeSuccess(command, {
2948
3073
  artifact_id: artifactId,
2949
- share_url: configString(result.body?.share_url),
3074
+ share_url: configString(result.data?.share_url),
2950
3075
  thread_id: threadId,
2951
- reply: result.body?.reply === true,
2952
- thread: result.body?.thread ?? null
3076
+ reply: result.data?.reply === true,
3077
+ thread: result.data?.thread ?? null
2953
3078
  }, mode);
2954
3079
  }
2955
3080
  async function runCommentsEdit(parsed, mode) {
@@ -3038,21 +3163,24 @@ async function postCommentAction(parsed, command, artifactId, payload, mode) {
3038
3163
  writeFailure(command, request.error, mode, 1);
3039
3164
  return null;
3040
3165
  }
3041
- const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, payload, parsed.options, request.init, {
3042
- artifactTarget: true,
3043
- credentialSource: credential.source,
3044
- profile: credential.profile,
3045
- profileCredentialKind: credential.profileCredentialKind
3166
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
3167
+ const action = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, current.token, payload, parsed.options, request.init, {
3168
+ artifactTarget: true,
3169
+ credentialSource: current.source,
3170
+ profile: current.profile,
3171
+ profileCredentialKind: current.profileCredentialKind
3172
+ });
3173
+ return action.error ? { error: action.error } : { data: action.body };
3046
3174
  });
3047
3175
  if (result.error) {
3048
3176
  writeFailure(command, result.error, mode, 1);
3049
3177
  return null;
3050
3178
  }
3051
- if (result.body === null) {
3179
+ if (result.data === null) {
3052
3180
  writeFailure(command, serviceError("Comment was changed but the response was empty."), mode, 1);
3053
3181
  return null;
3054
3182
  }
3055
- return result.body;
3183
+ return result.data;
3056
3184
  }
3057
3185
  function requiredOption(value, message, hint) {
3058
3186
  if (!value || !value.trim()) return { error: validationError(message, hint) };
@@ -3069,15 +3197,18 @@ async function runDelete(parsed, mode) {
3069
3197
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
3070
3198
  const request = await requestConfig(parsed.options);
3071
3199
  if (request.error) return writeFailure(command, request.error, mode, 1);
3072
- const result = await apiDelete(`/api/cli/artifacts/${encodeURIComponent(artifactId)}`, credential.token, parsed.options, request.init, {
3073
- authenticated: true,
3074
- artifactTarget: true,
3075
- credentialSource: credential.source,
3076
- profile: credential.profile,
3077
- profileCredentialKind: credential.profileCredentialKind
3200
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
3201
+ const deleted = await apiDelete(`/api/cli/artifacts/${encodeURIComponent(artifactId)}`, current.token, parsed.options, request.init, {
3202
+ authenticated: true,
3203
+ artifactTarget: true,
3204
+ credentialSource: current.source,
3205
+ profile: current.profile,
3206
+ profileCredentialKind: current.profileCredentialKind
3207
+ });
3208
+ return deleted.error ? { error: deleted.error } : { data: deleted.body };
3078
3209
  });
3079
3210
  if (result.error) return writeFailure(command, result.error, mode, 1);
3080
- const body = result.body;
3211
+ const body = result.data;
3081
3212
  if (!deleteSuccessFields(body)) return writeFailure(command, serviceError("Delete succeeded but the response did not include deletion metadata."), mode, 1);
3082
3213
  return writeSuccess(command, body, mode);
3083
3214
  }
@@ -3160,32 +3291,50 @@ async function runDoctor(parsed, mode) {
3160
3291
  }
3161
3292
  const request = await requestConfig(parsed.options);
3162
3293
  if (request.error) return writeFailure(command, request.error, mode, 1);
3163
- const response = await fetch(apiUrl("/api/cli/doctor", baseUrlOf(parsed.options)), {
3164
- headers: { Authorization: `Bearer ${credential.token}` },
3165
- ...request.init
3166
- }).catch((error) => ({ networkError: error }));
3167
- if ("networkError" in response) {
3168
- data.network = {
3294
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
3295
+ const response = await fetch(apiUrl("/api/cli/doctor", baseUrlOf(parsed.options)), {
3296
+ headers: { Authorization: `Bearer ${current.token}` },
3297
+ ...request.init
3298
+ }).catch((error) => ({ networkError: error }));
3299
+ if ("networkError" in response) return { data: {
3300
+ kind: "network_failed",
3301
+ hint: networkError(response.networkError).hint
3302
+ } };
3303
+ const body = await readJson(response);
3304
+ if (!response.ok) return { error: mapApiError(response.status, body, {
3305
+ authenticated: true,
3306
+ baseUrl: baseUrlOf(parsed.options),
3307
+ credentialSource: current.source,
3308
+ profile: current.profile,
3309
+ profileCredentialKind: current.profileCredentialKind
3310
+ }) };
3311
+ return { data: {
3312
+ kind: "body",
3313
+ body
3314
+ } };
3315
+ });
3316
+ if (result.error) {
3317
+ const authError = result.refreshError ? result.originalError ?? result.error : result.error;
3318
+ if (result.refreshError?.code === "network_failed") data.network = {
3169
3319
  ok: false,
3170
3320
  code: "network_failed",
3171
- hint: networkError(response.networkError).hint
3321
+ hint: result.refreshError.hint
3172
3322
  };
3323
+ else data.network.ok = true;
3324
+ data.auth.code = authError.code;
3325
+ data.auth.hint = authError.hint;
3173
3326
  return writeSuccess(command, doctorDataWithNextCommand(data), mode);
3174
3327
  }
3175
- data.network.ok = true;
3176
- const body = await readJson(response);
3177
- if (!response.ok) {
3178
- const error = mapApiError(response.status, body, {
3179
- authenticated: true,
3180
- baseUrl: baseUrlOf(parsed.options),
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;
3328
+ if (result.data.kind === "network_failed") {
3329
+ data.network = {
3330
+ ok: false,
3331
+ code: "network_failed",
3332
+ hint: result.data.hint
3333
+ };
3187
3334
  return writeSuccess(command, doctorDataWithNextCommand(data), mode);
3188
3335
  }
3336
+ data.network.ok = true;
3337
+ const body = result.data.body;
3189
3338
  if (!body) throw new Error("Doctor response was not valid JSON.");
3190
3339
  data.auth.ok = body.auth?.ok ?? true;
3191
3340
  data.auth.email = body.user?.email ?? null;
@@ -3509,15 +3658,18 @@ async function runEdit(parsed, mode) {
3509
3658
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
3510
3659
  const request = await requestConfig(parsed.options);
3511
3660
  if (request.error) return writeFailure(command, request.error, mode, 1);
3512
- const result = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/edit`, credential.token, payload.body, parsed.options, request.init, {
3513
- artifactTarget: true,
3514
- editSettings: true,
3515
- credentialSource: credential.source,
3516
- profile: credential.profile,
3517
- profileCredentialKind: credential.profileCredentialKind
3661
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
3662
+ const edited = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/edit`, current.token, payload.body, parsed.options, request.init, {
3663
+ artifactTarget: true,
3664
+ editSettings: true,
3665
+ credentialSource: current.source,
3666
+ profile: current.profile,
3667
+ profileCredentialKind: current.profileCredentialKind
3668
+ });
3669
+ return edited.error ? { error: edited.error } : { data: edited.body };
3518
3670
  });
3519
3671
  if (result.error) return writeFailure(command, result.error, mode, 1);
3520
- const data = parseEditData(result.body);
3672
+ const data = parseEditData(result.data);
3521
3673
  if (!data) return writeFailure(command, serviceError("Edit succeeded but the response did not include edit data."), mode, 1);
3522
3674
  writeSuccess(command, data, mode);
3523
3675
  }
@@ -3797,14 +3949,17 @@ async function runMove(parsed, mode) {
3797
3949
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
3798
3950
  const request = await requestConfig(parsed.options);
3799
3951
  if (request.error) return writeFailure(command, request.error, mode, 1);
3800
- const result = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/move`, credential.token, { destination: home ? "home" : { project_id: projectId } }, parsed.options, request.init, {
3801
- artifactTarget: true,
3802
- credentialSource: credential.source,
3803
- profile: credential.profile,
3804
- profileCredentialKind: credential.profileCredentialKind
3952
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
3953
+ const moved = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/move`, current.token, { destination: home ? "home" : { project_id: projectId } }, parsed.options, request.init, {
3954
+ artifactTarget: true,
3955
+ credentialSource: current.source,
3956
+ profile: current.profile,
3957
+ profileCredentialKind: current.profileCredentialKind
3958
+ });
3959
+ return moved.error ? { error: moved.error } : { data: moved.body };
3805
3960
  });
3806
3961
  if (result.error) return writeFailure(command, result.error, mode, 1);
3807
- const data = parseMoveData(result.body);
3962
+ const data = parseMoveData(result.data);
3808
3963
  if (!data) return writeFailure(command, serviceError("Move succeeded but the response did not include move data."), mode, 1);
3809
3964
  writeSuccess(command, data, mode);
3810
3965
  }
@@ -3979,14 +4134,17 @@ async function runProjectsList(parsed, mode) {
3979
4134
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
3980
4135
  const request = await requestConfig(parsed.options);
3981
4136
  if (request.error) return writeFailure(command, request.error, mode, 1);
3982
- const result = await fetchProjects(credential.token, parsed.options, request.init, {
3983
- credentialSource: credential.source,
3984
- profile: credential.profile,
3985
- profileCredentialKind: credential.profileCredentialKind
4137
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
4138
+ const fetched = await fetchProjects(current.token, parsed.options, request.init, {
4139
+ credentialSource: current.source,
4140
+ profile: current.profile,
4141
+ profileCredentialKind: current.profileCredentialKind
4142
+ });
4143
+ return fetched.error ? { error: fetched.error } : { data: fetched.projects };
3986
4144
  });
3987
4145
  if (result.error) return writeFailure(command, result.error, mode, 1);
3988
4146
  const defaultProjectId = configString(projectConfig.config?.default_project_id);
3989
- const projects = result.projects.map((project) => ({
4147
+ const projects = result.data.map((project) => ({
3990
4148
  ...project,
3991
4149
  is_default: project.id === defaultProjectId
3992
4150
  }));
@@ -4007,17 +4165,20 @@ async function runProjectsCreate(parsed, mode) {
4007
4165
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
4008
4166
  const request = await requestConfig(parsed.options);
4009
4167
  if (request.error) return writeFailure(command, request.error, mode, 1);
4010
- const result = await apiPost("/api/cli/projects", credential.token, {
4011
- name,
4012
- description: parsed.options.description ?? null,
4013
- base_visibility: visibility ?? null
4014
- }, parsed.options, request.init, {
4015
- credentialSource: credential.source,
4016
- profile: credential.profile,
4017
- profileCredentialKind: credential.profileCredentialKind
4168
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
4169
+ const created = await apiPost("/api/cli/projects", current.token, {
4170
+ name,
4171
+ description: parsed.options.description ?? null,
4172
+ base_visibility: visibility ?? null
4173
+ }, parsed.options, request.init, {
4174
+ credentialSource: current.source,
4175
+ profile: current.profile,
4176
+ profileCredentialKind: current.profileCredentialKind
4177
+ });
4178
+ return created.error ? { error: created.error } : { data: created.body };
4018
4179
  });
4019
4180
  if (result.error) return writeFailure(command, result.error, mode, 1);
4020
- const project = isRecord(result.body?.project) ? result.body.project : null;
4181
+ const project = isRecord(result.data?.project) ? result.data.project : null;
4021
4182
  const id = configString(project?.id);
4022
4183
  if (!id) return writeFailure(command, serviceError("Project create succeeded but no project id was returned."), mode, 1);
4023
4184
  writeSuccess(command, {
@@ -4041,14 +4202,17 @@ async function runProjectsEdit(parsed, mode) {
4041
4202
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
4042
4203
  const request = await requestConfig(parsed.options);
4043
4204
  if (request.error) return writeFailure(command, request.error, mode, 1);
4044
- const result = await apiPost(`/api/cli/projects/${encodeURIComponent(projectId)}`, credential.token, payload.body, parsed.options, request.init, {
4045
- projectTarget: true,
4046
- credentialSource: credential.source,
4047
- profile: credential.profile,
4048
- profileCredentialKind: credential.profileCredentialKind
4205
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
4206
+ const edited = await apiPost(`/api/cli/projects/${encodeURIComponent(projectId)}`, current.token, payload.body, parsed.options, request.init, {
4207
+ projectTarget: true,
4208
+ credentialSource: current.source,
4209
+ profile: current.profile,
4210
+ profileCredentialKind: current.profileCredentialKind
4211
+ });
4212
+ return edited.error ? { error: edited.error } : { data: edited.body };
4049
4213
  });
4050
4214
  if (result.error) return writeFailure(command, result.error, mode, 1);
4051
- const data = parseProjectsEditData(result.body);
4215
+ const data = parseProjectsEditData(result.data);
4052
4216
  if (!data) return writeFailure(command, serviceError("Project edit succeeded but the response did not include project data."), mode, 1);
4053
4217
  writeSuccess(command, data, mode);
4054
4218
  }
@@ -4240,13 +4404,16 @@ async function runRequestAccess(parsed, mode) {
4240
4404
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
4241
4405
  const request = await requestConfig(parsed.options);
4242
4406
  if (request.error) return writeFailure(command, request.error, mode, 1);
4243
- const result = await apiPost("/api/cli/request-access", credential.token, { note }, parsed.options, request.init, {
4244
- credentialSource: credential.source,
4245
- profile: credential.profile,
4246
- profileCredentialKind: credential.profileCredentialKind
4407
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
4408
+ const requested = await apiPost("/api/cli/request-access", current.token, { note }, parsed.options, request.init, {
4409
+ credentialSource: current.source,
4410
+ profile: current.profile,
4411
+ profileCredentialKind: current.profileCredentialKind
4412
+ });
4413
+ return requested.error ? { error: requested.error } : { data: requested.body };
4247
4414
  });
4248
4415
  if (result.error) return writeFailure(command, result.error, mode, 1);
4249
- const body = result.body;
4416
+ const body = result.data;
4250
4417
  const data = {
4251
4418
  requested: body?.requested === true,
4252
4419
  already_enabled: body?.already_enabled === true,
@@ -4270,19 +4437,24 @@ async function runResolve(parsed, mode) {
4270
4437
  if (request.error) return writeFailure(command, request.error, mode, 1);
4271
4438
  const url = apiUrl("/api/cli/resolve", baseUrlOf(parsed.options));
4272
4439
  url.searchParams.set("q", value);
4273
- const response = await fetch(url, {
4274
- headers: { Authorization: `Bearer ${credential.token}` },
4275
- ...request.init
4276
- }).catch((error) => ({ networkError: error }));
4277
- if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
4278
- const body = await readJson(response);
4279
- if (!response.ok) return writeFailure(command, mapApiError(response.status, body, {
4280
- authenticated: true,
4281
- baseUrl: baseUrlOf(parsed.options),
4282
- credentialSource: credential.source,
4283
- profile: credential.profile,
4284
- profileCredentialKind: credential.profileCredentialKind
4285
- }), mode, 1);
4440
+ const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
4441
+ const response = await fetch(url, {
4442
+ headers: { Authorization: `Bearer ${current.token}` },
4443
+ ...request.init
4444
+ }).catch((error) => ({ networkError: error }));
4445
+ if ("networkError" in response) return { error: networkError(response.networkError) };
4446
+ const body = await readJson(response);
4447
+ if (!response.ok) return { error: mapApiError(response.status, body, {
4448
+ authenticated: true,
4449
+ baseUrl: baseUrlOf(parsed.options),
4450
+ credentialSource: current.source,
4451
+ profile: current.profile,
4452
+ profileCredentialKind: current.profileCredentialKind
4453
+ }) };
4454
+ return { data: body };
4455
+ });
4456
+ if (result.error) return writeFailure(command, result.error, mode, 1);
4457
+ const body = result.data;
4286
4458
  if (!resolveSuccessFields(body)) return writeFailure(command, serviceError("Resolve succeeded but the response did not include query, candidates, and has_more."), mode, 1);
4287
4459
  return writeSuccess(command, body, mode);
4288
4460
  }
@@ -4346,14 +4518,17 @@ async function runWhoami(parsed, mode) {
4346
4518
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
4347
4519
  const request = await requestConfig(parsed.options);
4348
4520
  if (request.error) return writeFailure(command, request.error, mode, 1);
4349
- const whoami = await apiGet("/api/cli/whoami", credential.token, parsed.options, request.init, {
4350
- credentialSource: credential.source,
4351
- profile: credential.profile,
4352
- profileCredentialKind: credential.profileCredentialKind
4521
+ const whoami = await runAuthenticatedApi(credential, parsed.options, async (current) => {
4522
+ const result = await apiGet("/api/cli/whoami", current.token, parsed.options, request.init, {
4523
+ credentialSource: current.source,
4524
+ profile: current.profile,
4525
+ profileCredentialKind: current.profileCredentialKind
4526
+ });
4527
+ return result.error ? { error: result.error } : { data: result.body };
4353
4528
  });
4354
4529
  if (whoami.error) return writeFailure(command, whoami.error, mode, 1);
4355
- return writeSuccess(command, isRecord(whoami.body) ? {
4356
- ...whoami.body,
4530
+ return writeSuccess(command, isRecord(whoami.data) ? {
4531
+ ...whoami.data,
4357
4532
  credential_source: credential.source
4358
4533
  } : { credential_source: credential.source }, mode);
4359
4534
  }
@@ -4361,35 +4536,36 @@ async function runWhoami(parsed, mode) {
4361
4536
  //#region src/commands.ts
4362
4537
  async function shareRunner(ctx) {
4363
4538
  const parsed = parsedArgsFromContext("share", ctx);
4364
- return await runShare(parsed, outputMode(parsed.options));
4539
+ return await runWithSkillAutoUpdate(parsed, () => runShare(parsed, outputMode(parsed.options)));
4365
4540
  }
4366
4541
  async function loginRunner(ctx) {
4367
4542
  const parsed = parsedArgsFromContext("login", ctx);
4368
- return await runLogin(parsed, outputMode(parsed.options));
4543
+ const mode = outputMode(parsed.options);
4544
+ return await runWithSkillAutoUpdate(parsed, () => runLogin(parsed, mode));
4369
4545
  }
4370
4546
  async function logoutRunner(ctx) {
4371
4547
  const parsed = parsedArgsFromContext("logout", ctx);
4372
- return await runLogout(parsed, outputMode(parsed.options));
4548
+ return await runWithSkillAutoUpdate(parsed, () => runLogout(parsed, outputMode(parsed.options)));
4373
4549
  }
4374
4550
  async function updateRunner(ctx) {
4375
4551
  const parsed = parsedArgsFromContext("update", ctx);
4376
- return await runUpdate(parsed, outputMode(parsed.options));
4552
+ return await runWithSkillAutoUpdate(parsed, () => runUpdate(parsed, outputMode(parsed.options)));
4377
4553
  }
4378
4554
  async function editRunner(ctx) {
4379
4555
  const parsed = parsedArgsFromContext("edit", ctx);
4380
- return await runEdit(parsed, outputMode(parsed.options));
4556
+ return await runWithSkillAutoUpdate(parsed, () => runEdit(parsed, outputMode(parsed.options)));
4381
4557
  }
4382
4558
  async function deleteRunner(ctx) {
4383
4559
  const parsed = parsedArgsFromContext("delete", ctx);
4384
- return await runDelete(parsed, outputMode(parsed.options));
4560
+ return await runWithSkillAutoUpdate(parsed, () => runDelete(parsed, outputMode(parsed.options)));
4385
4561
  }
4386
4562
  async function resolveRunner(ctx) {
4387
4563
  const parsed = parsedArgsFromContext("resolve", ctx);
4388
- return await runResolve(parsed, outputMode(parsed.options));
4564
+ return await runWithSkillAutoUpdate(parsed, () => runResolve(parsed, outputMode(parsed.options)));
4389
4565
  }
4390
4566
  async function downloadRunner(ctx) {
4391
4567
  const parsed = parsedArgsFromContext("download", ctx);
4392
- return await runDownload(parsed, outputMode(parsed.options));
4568
+ return await runWithSkillAutoUpdate(parsed, () => runDownload(parsed, outputMode(parsed.options)));
4393
4569
  }
4394
4570
  async function openRunner(ctx) {
4395
4571
  const parsed = parsedArgsFromContext("open", ctx);
@@ -4397,76 +4573,76 @@ async function openRunner(ctx) {
4397
4573
  }
4398
4574
  async function moveRunner(ctx) {
4399
4575
  const parsed = parsedArgsFromContext("move", ctx);
4400
- return await runMove(parsed, outputMode(parsed.options));
4576
+ return await runWithSkillAutoUpdate(parsed, () => runMove(parsed, outputMode(parsed.options)));
4401
4577
  }
4402
4578
  async function artifactsGetRunner(ctx) {
4403
4579
  const parsed = parsedArgsFromContext("artifacts get", ctx);
4404
- return await runArtifactsGet(parsed, outputMode(parsed.options));
4580
+ return await runWithSkillAutoUpdate(parsed, () => runArtifactsGet(parsed, outputMode(parsed.options)));
4405
4581
  }
4406
4582
  async function artifactsListRunner(ctx) {
4407
4583
  const parsed = parsedArgsFromContext("artifacts list", ctx);
4408
- return await runArtifactsList(parsed, outputMode(parsed.options));
4584
+ return await runWithSkillAutoUpdate(parsed, () => runArtifactsList(parsed, outputMode(parsed.options)));
4409
4585
  }
4410
4586
  async function commentsListRunner(ctx) {
4411
4587
  const parsed = parsedArgsFromContext("comments list", ctx);
4412
- return await runCommentsList(parsed, outputMode(parsed.options));
4588
+ return await runWithSkillAutoUpdate(parsed, () => runCommentsList(parsed, outputMode(parsed.options)));
4413
4589
  }
4414
4590
  async function commentsPostRunner(ctx) {
4415
4591
  const parsed = parsedArgsFromContext("comments post", ctx);
4416
- return await runCommentsPost(parsed, outputMode(parsed.options));
4592
+ return await runWithSkillAutoUpdate(parsed, () => runCommentsPost(parsed, outputMode(parsed.options)));
4417
4593
  }
4418
4594
  async function commentsEditRunner(ctx) {
4419
4595
  const parsed = parsedArgsFromContext("comments edit", ctx);
4420
- return await runCommentsEdit(parsed, outputMode(parsed.options));
4596
+ return await runWithSkillAutoUpdate(parsed, () => runCommentsEdit(parsed, outputMode(parsed.options)));
4421
4597
  }
4422
4598
  async function commentsResolveRunner(ctx) {
4423
4599
  const parsed = parsedArgsFromContext("comments resolve", ctx);
4424
- return await runCommentsResolve(parsed, outputMode(parsed.options));
4600
+ return await runWithSkillAutoUpdate(parsed, () => runCommentsResolve(parsed, outputMode(parsed.options)));
4425
4601
  }
4426
4602
  async function commentsReopenRunner(ctx) {
4427
4603
  const parsed = parsedArgsFromContext("comments reopen", ctx);
4428
- return await runCommentsReopen(parsed, outputMode(parsed.options));
4604
+ return await runWithSkillAutoUpdate(parsed, () => runCommentsReopen(parsed, outputMode(parsed.options)));
4429
4605
  }
4430
4606
  async function commentsDeleteRunner(ctx) {
4431
4607
  const parsed = parsedArgsFromContext("comments delete", ctx);
4432
- return await runCommentsDelete(parsed, outputMode(parsed.options));
4608
+ return await runWithSkillAutoUpdate(parsed, () => runCommentsDelete(parsed, outputMode(parsed.options)));
4433
4609
  }
4434
4610
  async function requestAccessRunner(ctx) {
4435
4611
  const parsed = parsedArgsFromContext("request-access", ctx);
4436
- return await runRequestAccess(parsed, outputMode(parsed.options));
4612
+ return await runWithSkillAutoUpdate(parsed, () => runRequestAccess(parsed, outputMode(parsed.options)));
4437
4613
  }
4438
4614
  async function whoamiRunner(ctx) {
4439
4615
  const parsed = parsedArgsFromContext("whoami", ctx);
4440
- return await runWhoami(parsed, outputMode(parsed.options));
4616
+ return await runWithSkillAutoUpdate(parsed, () => runWhoami(parsed, outputMode(parsed.options)));
4441
4617
  }
4442
4618
  async function profilesListRunner(ctx) {
4443
4619
  const parsed = parsedArgsFromContext("profiles list", ctx);
4444
- return await runProfilesList(parsed, outputMode(parsed.options));
4620
+ return await runWithSkillAutoUpdate(parsed, () => runProfilesList(parsed, outputMode(parsed.options)));
4445
4621
  }
4446
4622
  async function profilesUseRunner(ctx) {
4447
4623
  const parsed = parsedArgsFromContext("profiles use", ctx);
4448
- return await runProfilesUse(parsed, outputMode(parsed.options));
4624
+ return await runWithSkillAutoUpdate(parsed, () => runProfilesUse(parsed, outputMode(parsed.options)));
4449
4625
  }
4450
4626
  async function profilesImportTokenRunner(ctx) {
4451
4627
  const parsed = parsedArgsFromContext("profiles import-token", ctx);
4452
4628
  if (hasOptionToken(ctx, "token")) parsed.options.token = "<redacted>";
4453
- return await runProfilesImportToken(parsed, outputMode(parsed.options));
4629
+ return await runWithSkillAutoUpdate(parsed, () => runProfilesImportToken(parsed, outputMode(parsed.options)));
4454
4630
  }
4455
4631
  async function profilesDeleteRunner(ctx) {
4456
4632
  const parsed = parsedArgsFromContext("profiles delete", ctx);
4457
- return await runProfilesDelete(parsed, outputMode(parsed.options));
4633
+ return await runWithSkillAutoUpdate(parsed, () => runProfilesDelete(parsed, outputMode(parsed.options)));
4458
4634
  }
4459
4635
  async function projectsListRunner(ctx) {
4460
4636
  const parsed = parsedArgsFromContext("projects list", ctx);
4461
- return await runProjectsList(parsed, outputMode(parsed.options));
4637
+ return await runWithSkillAutoUpdate(parsed, () => runProjectsList(parsed, outputMode(parsed.options)));
4462
4638
  }
4463
4639
  async function projectsCreateRunner(ctx) {
4464
4640
  const parsed = parsedArgsFromContext("projects create", ctx);
4465
- return await runProjectsCreate(parsed, outputMode(parsed.options));
4641
+ return await runWithSkillAutoUpdate(parsed, () => runProjectsCreate(parsed, outputMode(parsed.options)));
4466
4642
  }
4467
4643
  async function projectsEditRunner(ctx) {
4468
4644
  const parsed = parsedArgsFromContext("projects edit", ctx);
4469
- return await runProjectsEdit(parsed, outputMode(parsed.options));
4645
+ return await runWithSkillAutoUpdate(parsed, () => runProjectsEdit(parsed, outputMode(parsed.options)));
4470
4646
  }
4471
4647
  async function initRunner(ctx) {
4472
4648
  const parsed = parsedArgsFromContext("init", ctx);
@@ -4496,6 +4672,54 @@ async function doctorRunner(ctx) {
4496
4672
  const parsed = parsedArgsFromContext("doctor", ctx);
4497
4673
  return await runDoctor(parsed, outputMode(parsed.options));
4498
4674
  }
4675
+ async function runWithSkillAutoUpdate(parsed, runner) {
4676
+ const mode = outputMode(parsed.options);
4677
+ if (!mode.json) {
4678
+ const originalExitCode = process.exitCode;
4679
+ await runner();
4680
+ if (process.exitCode !== originalExitCode && process.exitCode !== 0) return;
4681
+ const autoUpdate = await autoUpdateUserManagedSkills();
4682
+ if (autoUpdate && autoUpdate.targets.length > 0) process.stdout.write(skillAutoUpdateHumanOutput({ skills: { auto_update: autoUpdate } }));
4683
+ return;
4684
+ }
4685
+ const originalWrite = process.stdout.write.bind(process.stdout);
4686
+ const originalExitCode = process.exitCode;
4687
+ let buffered = "";
4688
+ process.stdout.write = ((chunk, encoding, cb) => {
4689
+ buffered += Buffer.isBuffer(chunk) ? chunk.toString(typeof encoding === "string" ? encoding : void 0) : String(chunk);
4690
+ if (typeof encoding === "function") encoding();
4691
+ if (typeof cb === "function") cb();
4692
+ return true;
4693
+ });
4694
+ try {
4695
+ await runner();
4696
+ } catch (error) {
4697
+ process.stdout.write = originalWrite;
4698
+ originalWrite(buffered);
4699
+ throw error;
4700
+ }
4701
+ process.stdout.write = originalWrite;
4702
+ if (process.exitCode !== originalExitCode && process.exitCode !== 0) {
4703
+ originalWrite(buffered);
4704
+ return;
4705
+ }
4706
+ const autoUpdate = await autoUpdateUserManagedSkills();
4707
+ if (!autoUpdate || autoUpdate.targets.length === 0) {
4708
+ originalWrite(buffered);
4709
+ return;
4710
+ }
4711
+ if (mode.json) try {
4712
+ const payload = JSON.parse(buffered);
4713
+ payload.data = dataWithSkillAutoUpdate(payload.data, autoUpdate);
4714
+ originalWrite(`${JSON.stringify(payload, null, 2)}\n`);
4715
+ return;
4716
+ } catch {
4717
+ originalWrite(buffered);
4718
+ return;
4719
+ }
4720
+ originalWrite(buffered);
4721
+ originalWrite(skillAutoUpdateHumanOutput({ skills: { auto_update: autoUpdate } }));
4722
+ }
4499
4723
  function parentCommandRunner(command) {
4500
4724
  return (ctx) => {
4501
4725
  const parsed = parsedArgsFromContext(command, ctx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artifactshare/cli",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
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.33.0",
35
- "undici": "^7.28.0"
34
+ "gunshi": "^0.35.1",
35
+ "undici": "^8.5.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/node": "24.12.4",
39
- "tsdown": "^0.22.2",
38
+ "@types/node": "26.0.0",
39
+ "tsdown": "^0.22.3",
40
40
  "typescript": "6.0.3",
41
- "vitest": "4.1.7"
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: Open, share, update, and read back shared files with the Artifact Share CLI. Use when the user asks to open an Artifact Share URL, share an HTML/Markdown report, a static site, or other generated file, or to read back or comment on a shared file.
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: 20
7
+ version: 22
8
8
  managed: true
9
9
  -->
10
10
 
11
11
  # Artifact Share CLI
12
12
 
13
- Artifact Share hosts shared files (HTML pages, Markdown documents, static
14
- sites) with versions and comments. The CLI opens shared URLs, shares local
15
- files and folders, and is designed for agents: every command supports `--json`
16
- with a stable contract.
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
- The returned `share_url` is the link to give the user.
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: Use the Artifact Share CLI to open, share, update, and read back shared files.
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: 20
7
+ version: 22
8
8
  managed: true
9
9
  -->
10
10
 
11
11
  # Artifact Share CLI
12
12
 
13
- Artifact Share hosts shared files (HTML pages, Markdown documents, static
14
- sites) with versions and comments. Use `npx --yes @artifactshare/cli` to
15
- share local files, open shared URLs, and manage artifacts from the terminal.
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).