@artifactshare/cli 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,9 +35,9 @@ runs add versions to the same file.
35
35
 
36
36
  ## Authentication
37
37
 
38
- - **Interactive**: run `npx --yes @artifactshare/cli login`, or run `share`, `update`, or `download` directly — those commands start sign-in for you when unauthenticated (the CLI prints a link and code to open in your browser).
38
+ - **Interactive**: run `npx --yes @artifactshare/cli login`, or run `share`, `update`, or `download` directly — those commands start sign-in for you when unauthenticated (the CLI prints a link and code to open in your browser). Profiles created by `login` renew expired CLI sessions automatically during normal use.
39
39
  - **CI / non-interactive**: issue a token at `https://artifactshare.com/settings/tokens`, then set `ARTIFACTSHARE_TOKEN` (or pass `--token`). Without a token, non-interactive runs fail with `error.code: "auth_required"` instead of hanging.
40
- - Multiple accounts: keep one local profile per account (`profiles list` / `profiles use <name>`). In non-interactive agents, pipe an issued token into `profiles import-token --profile <name> --json` to create a saved profile without browser login.
40
+ - Multiple accounts: keep one local profile per account (`profiles list` / `profiles use <name>`). In non-interactive agents, pipe an issued token into `profiles import-token --profile <name> --json` to create a saved API-token profile without browser login; API-token profiles are not renewed by the CLI.
41
41
 
42
42
  ## Commands
43
43
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { appendFile, chmod, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
2
+ import { appendFile, chmod, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
3
3
  import { cli, define, lazy } from "gunshi";
4
4
  import { spawn } from "node:child_process";
5
5
  import { basename, dirname, join, relative, resolve, sep } from "node:path";
@@ -38,6 +38,7 @@ const BOOLEAN_FLAGS = new Set([
38
38
  ]);
39
39
  const VALUE_FLAGS = new Set([
40
40
  "add-email",
41
+ "agent",
41
42
  "base-url",
42
43
  "body",
43
44
  "description",
@@ -152,7 +153,7 @@ function mapApiError(status, body, options = {}) {
152
153
  if (!options.authenticated) return authRequiredError(options.baseUrl ?? "https://artifactshare.com");
153
154
  const source = options.credentialSource;
154
155
  const profile = options.profile;
155
- if (typeof profile === "string" && profile.length > 0 && isProfileCredentialSource(source)) return profileReauthRequiredError(options.baseUrl ?? "https://artifactshare.com", source, profile);
156
+ if (typeof profile === "string" && profile.length > 0 && isProfileCredentialSource(source) && options.profileCredentialKind !== "api_token") return profileReauthRequiredError(options.baseUrl ?? "https://artifactshare.com", source, profile);
156
157
  return tokenInvalidError();
157
158
  }
158
159
  if (apiCode === "upload-not-allowed") return cliError({
@@ -1162,6 +1163,14 @@ async function apiPost(path, token, payload, options, init, errorOptions = {}) {
1162
1163
  ...init
1163
1164
  }, errorOptions);
1164
1165
  }
1166
+ async function apiPostPublic(path, payload, options, init) {
1167
+ return await apiRequestRaw(path, options, {
1168
+ method: "POST",
1169
+ headers: { "content-type": "application/json" },
1170
+ body: JSON.stringify(payload),
1171
+ ...init
1172
+ });
1173
+ }
1165
1174
  async function apiDelete(path, token, options, init, errorOptions = {}) {
1166
1175
  return await apiRequest(path, options, {
1167
1176
  method: "DELETE",
@@ -1170,9 +1179,9 @@ async function apiDelete(path, token, options, init, errorOptions = {}) {
1170
1179
  }, errorOptions);
1171
1180
  }
1172
1181
  async function apiRequest(path, options, init, errorOptions) {
1173
- const response = await fetch(apiUrl(path, baseUrlOf(options)), init).catch((error) => ({ networkError: error }));
1174
- if ("networkError" in response) return { error: networkError(response.networkError) };
1175
- const body = await readJson(response);
1182
+ const result = await apiRequestRaw(path, options, init);
1183
+ if (result.error) return { error: result.error };
1184
+ const { response, body } = result;
1176
1185
  if (!response.ok) return { error: mapApiError(response.status, body, {
1177
1186
  authenticated: true,
1178
1187
  baseUrl: baseUrlOf(options),
@@ -1180,6 +1189,14 @@ async function apiRequest(path, options, init, errorOptions) {
1180
1189
  }) };
1181
1190
  return { body };
1182
1191
  }
1192
+ async function apiRequestRaw(path, options, init) {
1193
+ const response = await fetch(apiUrl(path, baseUrlOf(options)), init).catch((error) => ({ networkError: error }));
1194
+ if ("networkError" in response) return { error: networkError(response.networkError) };
1195
+ return {
1196
+ response,
1197
+ body: await readJson(response)
1198
+ };
1199
+ }
1183
1200
  //#endregion
1184
1201
  //#region src/process.ts
1185
1202
  function spawnFile(command, args, input) {
@@ -1309,32 +1326,40 @@ async function readProfileToken(profile, options) {
1309
1326
  const account = accountName(profile, baseUrlOf(options));
1310
1327
  const native = await nativeStore();
1311
1328
  if (native) {
1312
- const token = await native.read(account);
1313
- if (token) return {
1314
- ok: true,
1315
- token,
1329
+ const parsed = parseStoredProfileCredential(await native.read(account));
1330
+ if (parsed.ok) return {
1331
+ ...parsed,
1316
1332
  store: native.kind
1317
1333
  };
1334
+ if (parsed.reason === "legacy") return parsed;
1318
1335
  }
1319
- const plaintext = await readPlaintextToken(account);
1320
- if (plaintext) return {
1321
- ok: true,
1322
- token: plaintext,
1336
+ const plaintext = parseStoredProfileCredential(await readPlaintextToken(account));
1337
+ if (plaintext.ok) return {
1338
+ ...plaintext,
1323
1339
  store: "plaintext_file"
1324
1340
  };
1341
+ if (plaintext.reason === "legacy") return plaintext;
1325
1342
  return {
1326
1343
  ok: false,
1327
1344
  reason: native || options.allowPlaintextTokenStore ? "missing" : "unavailable"
1328
1345
  };
1329
1346
  }
1330
- async function saveProfileToken(profile, token, options) {
1347
+ async function saveProfileSessionCredential(profile, credential, options) {
1348
+ return await saveProfileCredential(profile, credential, options);
1349
+ }
1350
+ async function saveProfileApiTokenCredential(profile, credential, options) {
1351
+ return await saveProfileCredential(profile, credential, options);
1352
+ }
1353
+ async function saveProfileCredential(profile, credential, options) {
1331
1354
  const account = accountName(profile, baseUrlOf(options));
1355
+ const value = JSON.stringify(credential);
1332
1356
  const native = await nativeStore();
1333
- if (native && await native.write(account, token)) return {
1357
+ if (native && await native.write(account, value)) return {
1334
1358
  ok: true,
1335
1359
  store: native.kind
1336
1360
  };
1337
- if (options.allowPlaintextTokenStore && await writePlaintextToken(account, token)) return {
1361
+ const hasPlaintextEntry = await readPlaintextToken(account) !== null;
1362
+ if ((options.allowPlaintextTokenStore || hasPlaintextEntry) && await writePlaintextToken(account, value)) return {
1338
1363
  ok: true,
1339
1364
  store: "plaintext_file"
1340
1365
  };
@@ -1343,6 +1368,53 @@ async function saveProfileToken(profile, token, options) {
1343
1368
  reason: "unavailable"
1344
1369
  };
1345
1370
  }
1371
+ function parseStoredProfileCredential(raw) {
1372
+ if (!raw) return {
1373
+ ok: false,
1374
+ reason: "missing"
1375
+ };
1376
+ const parsed = parseJsonRecord(raw);
1377
+ if (!parsed) return {
1378
+ ok: false,
1379
+ reason: "legacy"
1380
+ };
1381
+ if (parsed.kind === "session" && typeof parsed.session_token === "string" && parsed.session_token && typeof parsed.refresh_token === "string" && parsed.refresh_token && (typeof parsed.expires_at === "string" || parsed.expires_at === null || parsed.expires_at === void 0)) {
1382
+ const credential = {
1383
+ kind: "session",
1384
+ session_token: parsed.session_token,
1385
+ refresh_token: parsed.refresh_token,
1386
+ ...parsed.expires_at !== void 0 ? { expires_at: parsed.expires_at } : {}
1387
+ };
1388
+ return {
1389
+ ok: true,
1390
+ token: credential.session_token,
1391
+ credential
1392
+ };
1393
+ }
1394
+ if (parsed.kind === "api_token" && typeof parsed.token === "string" && parsed.token) {
1395
+ const credential = {
1396
+ kind: "api_token",
1397
+ token: parsed.token
1398
+ };
1399
+ return {
1400
+ ok: true,
1401
+ token: credential.token,
1402
+ credential
1403
+ };
1404
+ }
1405
+ return {
1406
+ ok: false,
1407
+ reason: "legacy"
1408
+ };
1409
+ }
1410
+ function parseJsonRecord(raw) {
1411
+ try {
1412
+ const parsed = JSON.parse(raw);
1413
+ return isRecord(parsed) ? parsed : null;
1414
+ } catch {
1415
+ return null;
1416
+ }
1417
+ }
1346
1418
  async function readGlobalConfig() {
1347
1419
  const home = configHome();
1348
1420
  if (!home) return null;
@@ -1600,7 +1672,9 @@ async function resolveProfileCredential(source, profile, options, globalConfig,
1600
1672
  ok: true,
1601
1673
  source,
1602
1674
  profile,
1603
- token: stored.token
1675
+ token: stored.token,
1676
+ profileCredentialKind: stored.credential.kind,
1677
+ ...stored.credential.kind === "session" ? { refreshToken: stored.credential.refresh_token } : {}
1604
1678
  };
1605
1679
  return profileAuthRequired(source, profile, stored.reason, options, globalConfig, configPath, configKind);
1606
1680
  }
@@ -1608,7 +1682,7 @@ async function profileAuthRequired(source, profile, reason, options, globalConfi
1608
1682
  const baseUrl = baseUrlOf(options);
1609
1683
  const url = tokensUrl(baseUrl);
1610
1684
  const error = authRequiredError(baseUrl);
1611
- const why = reason === "unavailable" ? `No safe token store is available for profile "${profile}".` : `No saved credential was found for profile "${profile}".`;
1685
+ const why = reason === "unavailable" ? `No safe token store is available for profile "${profile}".` : reason === "legacy" ? `The saved credential for profile "${profile}" uses an old format.` : `No saved credential was found for profile "${profile}".`;
1612
1686
  const alternative = await findAlternativeProfileWithToken(globalConfig, options, profile);
1613
1687
  const details = {
1614
1688
  ...authRecoveryDetails(baseUrl, `${CLI_INVOCATION} login --profile ${profile}`),
@@ -1746,7 +1820,7 @@ async function performDeviceLogin(profile, options, mode) {
1746
1820
  error: token.error
1747
1821
  };
1748
1822
  const sessionExpiresAt = token.expires_in === void 0 ? null : new Date(Date.now() + token.expires_in * 1e3).toISOString();
1749
- const stored = await verifyAndStoreProfileToken(profile, token.access_token, options, request.init);
1823
+ const stored = await verifyAndStoreProfileToken(profile, token.access_token, options, request.init, sessionExpiresAt);
1750
1824
  if (!stored.ok) return {
1751
1825
  ok: false,
1752
1826
  error: stored.error
@@ -1868,39 +1942,97 @@ async function pollForToken(options, code, init, profile, deadline) {
1868
1942
  }
1869
1943
  return { error: authExpiredError(profile) };
1870
1944
  }
1871
- async function verifyAndStoreProfileToken(profile, token, options, init) {
1872
- const config = await readGlobalConfig() ?? {};
1873
- const whoamiResult = await apiGet("/api/cli/whoami", token, options, init);
1874
- if (whoamiResult.error) return {
1945
+ async function verifyAndStoreProfileToken(profile, token, options, init, sessionExpiresAt = null) {
1946
+ const verified = await verifyProfileTokenAccount(profile, token, options, init);
1947
+ if (!verified.ok) return verified;
1948
+ const refresh = await issueCliRefreshCredential(token, options, init);
1949
+ if ("error" in refresh) return {
1875
1950
  ok: false,
1876
- error: whoamiResult.error
1951
+ error: refresh.error
1877
1952
  };
1878
- const whoami = whoamiProfile(whoamiResult.body);
1879
- const profiles = config.profiles ?? {};
1880
- const expectedEmail = nonEmpty((Object.hasOwn(profiles, profile) ? profiles[profile] : void 0)?.email);
1881
- if (expectedEmail && whoami.email !== expectedEmail) return {
1953
+ const saved = await saveProfileSessionCredential(profile, {
1954
+ kind: "session",
1955
+ session_token: token,
1956
+ refresh_token: refresh.refresh_token,
1957
+ expires_at: sessionExpiresAt
1958
+ }, options);
1959
+ if (!saved.ok) return {
1882
1960
  ok: false,
1883
- error: authAccountMismatchError(profile, expectedEmail, whoami.email)
1961
+ error: tokenStoreUnavailableError(profile)
1884
1962
  };
1885
- const saved = await saveProfileToken(profile, token, options);
1963
+ await writeProfileConfig(profile, options, saved.store, verified.whoami);
1964
+ return {
1965
+ ok: true,
1966
+ data: {
1967
+ profile,
1968
+ token_store: saved.store,
1969
+ user: { email: verified.whoami.email },
1970
+ workspace: {
1971
+ id: verified.whoami.workspace_id,
1972
+ hosted_domain: verified.whoami.hosted_domain
1973
+ }
1974
+ }
1975
+ };
1976
+ }
1977
+ async function verifyAndStoreApiTokenProfile(profile, token, options, init) {
1978
+ const verified = await verifyProfileTokenAccount(profile, token, options, init);
1979
+ if (!verified.ok) return verified;
1980
+ const saved = await saveProfileApiTokenCredential(profile, {
1981
+ kind: "api_token",
1982
+ token
1983
+ }, options);
1886
1984
  if (!saved.ok) return {
1887
1985
  ok: false,
1888
1986
  error: tokenStoreUnavailableError(profile)
1889
1987
  };
1890
- await writeProfileConfig(profile, options, saved.store, whoami);
1988
+ await writeProfileConfig(profile, options, saved.store, verified.whoami);
1891
1989
  return {
1892
1990
  ok: true,
1893
1991
  data: {
1894
1992
  profile,
1895
1993
  token_store: saved.store,
1896
- user: { email: whoami.email },
1994
+ user: { email: verified.whoami.email },
1897
1995
  workspace: {
1898
- id: whoami.workspace_id,
1899
- hosted_domain: whoami.hosted_domain
1996
+ id: verified.whoami.workspace_id,
1997
+ hosted_domain: verified.whoami.hosted_domain
1900
1998
  }
1901
1999
  }
1902
2000
  };
1903
2001
  }
2002
+ async function verifyProfileTokenAccount(profile, token, options, init) {
2003
+ const config = await readGlobalConfig() ?? {};
2004
+ const whoamiResult = await apiGet("/api/cli/whoami", token, options, init, {
2005
+ authenticated: true,
2006
+ baseUrl: baseUrlOf(options)
2007
+ });
2008
+ if (whoamiResult.error) return {
2009
+ ok: false,
2010
+ error: whoamiResult.error
2011
+ };
2012
+ const whoami = whoamiProfile(whoamiResult.body);
2013
+ const profiles = config.profiles ?? {};
2014
+ const expectedEmail = nonEmpty((Object.hasOwn(profiles, profile) ? profiles[profile] : void 0)?.email);
2015
+ if (expectedEmail && whoami.email !== expectedEmail) return {
2016
+ ok: false,
2017
+ error: authAccountMismatchError(profile, expectedEmail, whoami.email)
2018
+ };
2019
+ return {
2020
+ ok: true,
2021
+ whoami
2022
+ };
2023
+ }
2024
+ async function issueCliRefreshCredential(token, options, init) {
2025
+ const result = await apiPost("/api/cli/auth/refresh-credentials", token, {}, options, init, {
2026
+ authenticated: true,
2027
+ baseUrl: baseUrlOf(options)
2028
+ });
2029
+ if (result.error) return { error: result.error };
2030
+ if (typeof result.body?.refresh_token === "string" && typeof result.body.refresh_token_expires_at === "string") return {
2031
+ refresh_token: result.body.refresh_token,
2032
+ refresh_token_expires_at: result.body.refresh_token_expires_at
2033
+ };
2034
+ return { error: validationError("Refresh credential response was invalid.", "Retry login. If this repeats, report the response shape.", "service_error") };
2035
+ }
1904
2036
  async function writeProfileConfig(profile, options, tokenStore, whoami) {
1905
2037
  const config = await readGlobalConfig() ?? {};
1906
2038
  const profiles = config.profiles ?? {};
@@ -1986,6 +2118,11 @@ async function handleCredentialFailure(command, credential, options, mode, rerun
1986
2118
  }
1987
2119
  async function handleAuthenticatedCredentialFailure(command, error, credential, options, mode, rerun, isRetry = false) {
1988
2120
  if (error.code !== "auth_required") return writeFailure(command, error, mode, 1);
2121
+ if (!isRetry && credential.profile && credential.profileCredentialKind === "session" && credential.refreshToken) {
2122
+ const refreshed = await refreshStoredProfileSession(credential.profile, credential.refreshToken, options);
2123
+ if (refreshed.ok) return rerun();
2124
+ if (refreshed.error) return writeFailure(command, refreshed.error, mode, 1);
2125
+ }
1989
2126
  return await handleCredentialFailure(command, {
1990
2127
  ok: false,
1991
2128
  source: credential.source,
@@ -1993,6 +2130,40 @@ async function handleAuthenticatedCredentialFailure(command, error, credential,
1993
2130
  error
1994
2131
  }, options, mode, rerun, isRetry);
1995
2132
  }
2133
+ async function refreshStoredProfileSession(profile, refreshToken, options) {
2134
+ const request = await requestConfig(options);
2135
+ if (request.error) return {
2136
+ ok: false,
2137
+ error: request.error
2138
+ };
2139
+ const result = await apiPostPublic("/api/cli/auth/refresh", { refresh_token: refreshToken }, options, request.init);
2140
+ if (result.error) return {
2141
+ ok: false,
2142
+ error: result.error
2143
+ };
2144
+ const { response, body } = result;
2145
+ if (!response.ok) {
2146
+ if (response.status === 401) return { ok: false };
2147
+ return {
2148
+ ok: false,
2149
+ error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) })
2150
+ };
2151
+ }
2152
+ if (typeof body?.access_token !== "string" || body.access_token.length === 0 || body.token_type?.toLowerCase() !== "bearer" || typeof body.expires_at !== "string") return {
2153
+ ok: false,
2154
+ error: validationError("Refresh response was invalid.", "Run login again. If this repeats, report the response shape.", "service_error")
2155
+ };
2156
+ if (!(await saveProfileSessionCredential(profile, {
2157
+ kind: "session",
2158
+ session_token: body.access_token,
2159
+ refresh_token: refreshToken,
2160
+ expires_at: body.expires_at
2161
+ }, options)).ok) return {
2162
+ ok: false,
2163
+ error: tokenStoreUnavailableError(profile)
2164
+ };
2165
+ return { ok: true };
2166
+ }
1996
2167
  async function handleJsonPendingAuth(command, credential, options, mode, rerun) {
1997
2168
  const profile = profileForAutoLogin(credential);
1998
2169
  const extraDetails = authRequiredExtraDetails(credential.error);
@@ -2008,7 +2179,7 @@ async function handleJsonPendingAuth(command, credential, options, mode, rerun)
2008
2179
  return writeFailure(command, exchange.error, mode, 1);
2009
2180
  }
2010
2181
  if (exchange.status === "success") {
2011
- const stored = await verifyAndStoreProfileToken(profile, exchange.token.access_token, options, request.init);
2182
+ const stored = await verifyAndStoreProfileToken(profile, exchange.token.access_token, options, request.init, exchange.token.expires_in === void 0 ? null : new Date(Date.now() + exchange.token.expires_in * 1e3).toISOString());
2012
2183
  if (!stored.ok) return writeFailure(command, stored.error, mode, 1);
2013
2184
  await clearPendingDeviceAuth(baseUrl, profile);
2014
2185
  return rerun();
@@ -2042,13 +2213,6 @@ async function runArtifactsGet(parsed, mode, isRetry = false) {
2042
2213
  if (result.error) return handleAuthenticatedCredentialFailure(command, result.error, credential, parsed.options, mode, () => runArtifactsGet(parsed, mode, true), isRetry);
2043
2214
  return writeSuccess(command, result.data, mode);
2044
2215
  }
2045
- async function readArtifact(parsed, command) {
2046
- const target = parseArtifactReadTarget(parsed, command);
2047
- if (target.error) return { error: target.error };
2048
- const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
2049
- if (!credential.ok) return { error: credential.error };
2050
- return await fetchArtifact(parsed, target.value, credential);
2051
- }
2052
2216
  function parseArtifactReadTarget(parsed, command) {
2053
2217
  const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to read.");
2054
2218
  if (target.error) return { error: target.error };
@@ -2080,7 +2244,8 @@ async function fetchArtifact(parsed, target, credential) {
2080
2244
  artifactTarget: true,
2081
2245
  baseUrl: baseUrlOf(parsed.options),
2082
2246
  credentialSource: credential.source,
2083
- profile: credential.profile
2247
+ profile: credential.profile,
2248
+ profileCredentialKind: credential.profileCredentialKind
2084
2249
  }) };
2085
2250
  if (!artifactGetSuccessFields(body)) return { error: serviceError("Artifact read succeeded but the response did not include source metadata.") };
2086
2251
  return { data: body };
@@ -2112,7 +2277,8 @@ async function runArtifactsList(parsed, mode) {
2112
2277
  authenticated: true,
2113
2278
  baseUrl: baseUrlOf(parsed.options),
2114
2279
  credentialSource: credential.source,
2115
- profile: credential.profile
2280
+ profile: credential.profile,
2281
+ profileCredentialKind: credential.profileCredentialKind
2116
2282
  }), mode, 1);
2117
2283
  if (!artifactsListSuccessFields(body)) return writeFailure(command, serviceError("Artifact list succeeded but the response did not include list metadata."), mode, 1);
2118
2284
  return writeSuccess(command, body, mode);
@@ -2262,6 +2428,9 @@ async function autoTargets(scope) {
2262
2428
  for (const tool of autoOrder) if (TOOL_CONFIG[tool].scopes.includes(targetScope) && await isToolDetected(tool, targetScope)) detected.add(tool);
2263
2429
  return (detected.size > 0 ? [...detected] : ["codex", "claude"]).filter((tool) => TOOL_CONFIG[tool].scopes.includes(targetScope)).map((tool) => skillTarget(tool, targetScope));
2264
2430
  }
2431
+ function targetPathKey(target) {
2432
+ return realpath(target.absolutePath).catch(() => target.absolutePath);
2433
+ }
2265
2434
  async function applyAction({ target, action, content }) {
2266
2435
  if (content !== void 0) {
2267
2436
  await mkdir(dirname(target.absolutePath), { recursive: true });
@@ -2285,20 +2454,33 @@ async function cleanupSkillDirs(target) {
2285
2454
  dir = dirname(dir);
2286
2455
  }
2287
2456
  }
2457
+ function skillUpdateCommand(target) {
2458
+ return `${CLI_INVOCATION} skills update --tool ${target.tool} --scope ${target.scope} --json`;
2459
+ }
2288
2460
  async function finishActions(command, planned, dryRun, mode) {
2289
- if (!dryRun) try {
2290
- for (const item of planned) await applyAction(item);
2461
+ const completed = [...planned];
2462
+ if (!dryRun) for (const [index, item] of planned.entries()) try {
2463
+ await applyAction(item);
2464
+ completed[index] = item;
2291
2465
  } catch (error) {
2466
+ if (item.fallbackAction) {
2467
+ completed[index] = {
2468
+ target: item.target,
2469
+ action: item.fallbackAction
2470
+ };
2471
+ continue;
2472
+ }
2292
2473
  writeFailure(command, unexpectedError(error), mode, 1);
2293
2474
  return;
2294
2475
  }
2295
2476
  return {
2296
2477
  dry_run: dryRun,
2297
- targets: planned.map(({ target, action }) => ({
2478
+ targets: completed.map(({ target, action }) => ({
2298
2479
  tool: target.tool,
2299
2480
  scope: target.scope,
2300
2481
  path: target.path,
2301
- action
2482
+ action,
2483
+ ...action === "update_recommended" ? { update_command: skillUpdateCommand(target) } : {}
2302
2484
  }))
2303
2485
  };
2304
2486
  }
@@ -2366,15 +2548,33 @@ async function ensureSkills(parsed, mode, options = {}) {
2366
2548
  return;
2367
2549
  }
2368
2550
  const unchanged = state.kind === "managed" && state.version === bundled.version;
2551
+ const recommendUpdate = options.recommendProjectUpdates && target.scope === "project" && state.kind === "managed" && state.version !== bundled.version;
2369
2552
  planned.push(unchanged ? {
2370
2553
  target,
2371
2554
  action: "unchanged"
2555
+ } : recommendUpdate ? {
2556
+ target,
2557
+ action: "update_recommended"
2372
2558
  } : {
2373
2559
  target,
2374
2560
  action: state.kind === "missing" ? "installed" : "updated",
2375
2561
  content: bundled.contents[target.tool]
2376
2562
  });
2377
2563
  }
2564
+ if (options.autoUpdateUserManaged) {
2565
+ const plannedPaths = new Set(await Promise.all(planned.map((action) => targetPathKey(action.target))));
2566
+ for (const target of allTargets().filter((candidate) => candidate.scope === "user")) {
2567
+ if (plannedPaths.has(await targetPathKey(target))) continue;
2568
+ const state = await readTarget(target);
2569
+ if (state.kind !== "managed" || state.version === bundled.version) continue;
2570
+ planned.push({
2571
+ target,
2572
+ action: "updated",
2573
+ content: bundled.contents[target.tool],
2574
+ fallbackAction: "update_recommended"
2575
+ });
2576
+ }
2577
+ }
2378
2578
  return finishActions(command, planned, parsed.options.dryRun === true, mode);
2379
2579
  }
2380
2580
  async function runSkillsEnsure(parsed, mode) {
@@ -2403,6 +2603,31 @@ async function runSkillsList(parsed, mode) {
2403
2603
  targets
2404
2604
  }, mode);
2405
2605
  }
2606
+ async function skillDiagnostics() {
2607
+ const bundled = await loadBundledSkills();
2608
+ const targets = [];
2609
+ for (const target of allTargets()) {
2610
+ const state = await readTarget(target);
2611
+ const updateAvailable = state.kind === "managed" && state.version !== bundled.version;
2612
+ targets.push({
2613
+ tool: target.tool,
2614
+ scope: target.scope,
2615
+ path: target.path,
2616
+ installed: state.kind !== "missing",
2617
+ managed: state.kind === "managed",
2618
+ installed_version: state.kind === "managed" ? state.version : null,
2619
+ update_available: updateAvailable,
2620
+ update_command: updateAvailable ? skillUpdateCommand(target) : null
2621
+ });
2622
+ }
2623
+ const updateTargets = targets.filter((target) => target.update_available);
2624
+ return {
2625
+ bundled_version: bundled.version,
2626
+ update_available: updateTargets.length > 0,
2627
+ update_command: updateTargets.length > 0 ? `${CLI_INVOCATION} skills update --json` : null,
2628
+ targets
2629
+ };
2630
+ }
2406
2631
  async function runSkillsUpdate(parsed, mode) {
2407
2632
  const command = "skills update";
2408
2633
  const filters = parseFilters(parsed);
@@ -2451,7 +2676,7 @@ async function runSkillsRemove(parsed, mode) {
2451
2676
  }
2452
2677
  //#endregion
2453
2678
  //#region src/command-runners/open.ts
2454
- async function runOpen(parsed, mode) {
2679
+ async function runOpen(parsed, mode, isRetry = false) {
2455
2680
  const command = "open";
2456
2681
  const skills = await ensureSkills({
2457
2682
  ...parsed,
@@ -2460,11 +2685,21 @@ async function runOpen(parsed, mode) {
2460
2685
  tool: "auto",
2461
2686
  scope: "project"
2462
2687
  }
2463
- }, mode, { command });
2688
+ }, mode, {
2689
+ command,
2690
+ autoUpdateUserManaged: true,
2691
+ recommendProjectUpdates: true
2692
+ });
2464
2693
  if (!skills) return;
2465
2694
  const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to read.");
2466
2695
  if (target.error) return writeFailure(command, target.error, mode, 1);
2467
- const result = await readArtifact(parsed, command);
2696
+ const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
2697
+ if (!credential.ok) return handleCredentialFailure(command, credential, parsed.options, mode, () => runOpen(parsed, mode, true), isRetry);
2698
+ const result = await fetchArtifact(parsed, {
2699
+ artifactId: target.artifactId,
2700
+ include: [],
2701
+ offset: void 0
2702
+ }, credential);
2468
2703
  if (result.error) {
2469
2704
  if (result.error.code === "unsupported_kind") return writeSuccess(command, {
2470
2705
  skills,
@@ -2473,6 +2708,7 @@ async function runOpen(parsed, mode) {
2473
2708
  next_command: agentDownloadCommand(target.artifactId)
2474
2709
  }
2475
2710
  }, mode);
2711
+ if (result.error.code === "auth_required") return handleAuthenticatedCredentialFailure(command, result.error, credential, parsed.options, mode, () => runOpen(parsed, mode, true), isRetry);
2476
2712
  return writeFailure(command, result.error, mode, 1);
2477
2713
  }
2478
2714
  return writeSuccess(command, {
@@ -2497,7 +2733,8 @@ async function runCommentsList(parsed, mode) {
2497
2733
  const result = await apiGet(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, parsed.options, request.init, {
2498
2734
  artifactTarget: true,
2499
2735
  credentialSource: credential.source,
2500
- profile: credential.profile
2736
+ profile: credential.profile,
2737
+ profileCredentialKind: credential.profileCredentialKind
2501
2738
  });
2502
2739
  if (result.error) return writeFailure(command, result.error, mode, 1);
2503
2740
  const comments = Array.isArray(result.body?.comments) ? result.body.comments : [];
@@ -2524,16 +2761,19 @@ async function runCommentsPost(parsed, mode) {
2524
2761
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
2525
2762
  const request = await requestConfig(parsed.options);
2526
2763
  if (request.error) return writeFailure(command, request.error, mode, 1);
2764
+ const agent = parsed.options.agent;
2527
2765
  const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, {
2528
2766
  body,
2529
2767
  reply_to: replyTo,
2530
2768
  quote,
2531
2769
  quote_before: parsed.options.quoteBefore,
2532
- quote_after: parsed.options.quoteAfter
2770
+ quote_after: parsed.options.quoteAfter,
2771
+ ...agent ? { agent } : {}
2533
2772
  }, parsed.options, request.init, {
2534
2773
  artifactTarget: true,
2535
2774
  credentialSource: credential.source,
2536
- profile: credential.profile
2775
+ profile: credential.profile,
2776
+ profileCredentialKind: credential.profileCredentialKind
2537
2777
  });
2538
2778
  if (result.error) return writeFailure(command, result.error, mode, 1);
2539
2779
  const threadId = configString(result.body?.thread_id);
@@ -2635,7 +2875,8 @@ async function postCommentAction(parsed, command, artifactId, payload, mode) {
2635
2875
  const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, payload, parsed.options, request.init, {
2636
2876
  artifactTarget: true,
2637
2877
  credentialSource: credential.source,
2638
- profile: credential.profile
2878
+ profile: credential.profile,
2879
+ profileCredentialKind: credential.profileCredentialKind
2639
2880
  });
2640
2881
  if (result.error) {
2641
2882
  writeFailure(command, result.error, mode, 1);
@@ -2666,7 +2907,8 @@ async function runDelete(parsed, mode) {
2666
2907
  authenticated: true,
2667
2908
  artifactTarget: true,
2668
2909
  credentialSource: credential.source,
2669
- profile: credential.profile
2910
+ profile: credential.profile,
2911
+ profileCredentialKind: credential.profileCredentialKind
2670
2912
  });
2671
2913
  if (result.error) return writeFailure(command, result.error, mode, 1);
2672
2914
  const body = result.body;
@@ -2722,6 +2964,7 @@ async function runDoctor(parsed, mode) {
2722
2964
  next_command: null,
2723
2965
  base_url: baseUrlOf(parsed.options),
2724
2966
  config: await configDiagnostics(project),
2967
+ skills: await skillDiagnostics(),
2725
2968
  auth: {
2726
2969
  credential_source: credential.source,
2727
2970
  ...credential.profile ? { profile: credential.profile } : {},
@@ -2770,7 +3013,8 @@ async function runDoctor(parsed, mode) {
2770
3013
  authenticated: true,
2771
3014
  baseUrl: baseUrlOf(parsed.options),
2772
3015
  credentialSource: credential.source,
2773
- profile: credential.profile
3016
+ profile: credential.profile,
3017
+ profileCredentialKind: credential.profileCredentialKind
2774
3018
  });
2775
3019
  data.auth.code = error.code;
2776
3020
  data.auth.hint = error.hint;
@@ -3024,7 +3268,8 @@ async function runDownload(parsed, mode, isRetry = false) {
3024
3268
  artifactTarget: true,
3025
3269
  baseUrl,
3026
3270
  credentialSource: credential.source,
3027
- profile: credential.profile
3271
+ profile: credential.profile,
3272
+ profileCredentialKind: credential.profileCredentialKind
3028
3273
  }), credential, parsed.options, mode, () => runDownload(parsed, mode, true), isRetry);
3029
3274
  if (!downloadManifestFields(body)) return writeFailure(command, serviceError("Download manifest succeeded but the response did not include file metadata."), mode, 1);
3030
3275
  const plan = await prepareDownloadPlan(body, parsed.options.output ?? artifactId, Boolean(parsed.options.force));
@@ -3044,7 +3289,8 @@ async function runDownload(parsed, mode, isRetry = false) {
3044
3289
  artifactTarget: true,
3045
3290
  baseUrl,
3046
3291
  credentialSource: credential.source,
3047
- profile: credential.profile
3292
+ profile: credential.profile,
3293
+ profileCredentialKind: credential.profileCredentialKind
3048
3294
  }), credential, parsed.options, mode, () => runDownload(parsed, mode, true), isRetry);
3049
3295
  const bytes = Buffer.from(await fileResponse.arrayBuffer());
3050
3296
  const verified = verifyDownloadedBytes(file, bytes);
@@ -3101,7 +3347,8 @@ async function runEdit(parsed, mode) {
3101
3347
  artifactTarget: true,
3102
3348
  editSettings: true,
3103
3349
  credentialSource: credential.source,
3104
- profile: credential.profile
3350
+ profile: credential.profile,
3351
+ profileCredentialKind: credential.profileCredentialKind
3105
3352
  });
3106
3353
  if (result.error) return writeFailure(command, result.error, mode, 1);
3107
3354
  const data = parseEditData(result.body);
@@ -3263,7 +3510,11 @@ async function runInitOnboarding(parsed, mode) {
3263
3510
  tool: "auto",
3264
3511
  scope: "project"
3265
3512
  }
3266
- }, mode, { command });
3513
+ }, mode, {
3514
+ command,
3515
+ autoUpdateUserManaged: true,
3516
+ recommendProjectUpdates: true
3517
+ });
3267
3518
  if (!skills) return;
3268
3519
  const project = await resolveProjectConfig();
3269
3520
  const signedIn = (await resolveCredential(parsed.options, project)).ok;
@@ -3340,7 +3591,8 @@ async function runMove(parsed, mode) {
3340
3591
  const result = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/move`, credential.token, { destination: home ? "home" : { project_id: projectId } }, parsed.options, request.init, {
3341
3592
  artifactTarget: true,
3342
3593
  credentialSource: credential.source,
3343
- profile: credential.profile
3594
+ profile: credential.profile,
3595
+ profileCredentialKind: credential.profileCredentialKind
3344
3596
  });
3345
3597
  if (result.error) return writeFailure(command, result.error, mode, 1);
3346
3598
  const data = parseMoveData(result.body);
@@ -3456,7 +3708,7 @@ async function runProfilesImportToken(parsed, mode) {
3456
3708
  if (!token) return writeFailure(command, validationError("A token is required on standard input.", `Pipe a token: printf '%s' "$TOKEN" | ${CLI_INVOCATION} profiles import-token --profile ${profile} --json`), mode, 1);
3457
3709
  const request = await requestConfig(parsed.options);
3458
3710
  if (request.error) return writeFailure(command, request.error, mode, 1);
3459
- const stored = await verifyAndStoreProfileToken(profile, token, parsed.options, request.init);
3711
+ const stored = await verifyAndStoreApiTokenProfile(profile, token, parsed.options, request.init);
3460
3712
  if (!stored.ok) return writeFailure(command, stored.error, mode, 1);
3461
3713
  return writeSuccess(command, {
3462
3714
  profile,
@@ -3493,7 +3745,8 @@ async function runProjectsList(parsed, mode) {
3493
3745
  if (request.error) return writeFailure(command, request.error, mode, 1);
3494
3746
  const result = await fetchProjects(credential.token, parsed.options, request.init, {
3495
3747
  credentialSource: credential.source,
3496
- profile: credential.profile
3748
+ profile: credential.profile,
3749
+ profileCredentialKind: credential.profileCredentialKind
3497
3750
  });
3498
3751
  if (result.error) return writeFailure(command, result.error, mode, 1);
3499
3752
  const defaultProjectId = configString(projectConfig.config?.default_project_id);
@@ -3524,7 +3777,8 @@ async function runProjectsCreate(parsed, mode) {
3524
3777
  base_visibility: visibility ?? null
3525
3778
  }, parsed.options, request.init, {
3526
3779
  credentialSource: credential.source,
3527
- profile: credential.profile
3780
+ profile: credential.profile,
3781
+ profileCredentialKind: credential.profileCredentialKind
3528
3782
  });
3529
3783
  if (result.error) return writeFailure(command, result.error, mode, 1);
3530
3784
  const project = isRecord(result.body?.project) ? result.body.project : null;
@@ -3554,7 +3808,8 @@ async function runProjectsEdit(parsed, mode) {
3554
3808
  const result = await apiPost(`/api/cli/projects/${encodeURIComponent(projectId)}`, credential.token, payload.body, parsed.options, request.init, {
3555
3809
  projectTarget: true,
3556
3810
  credentialSource: credential.source,
3557
- profile: credential.profile
3811
+ profile: credential.profile,
3812
+ profileCredentialKind: credential.profileCredentialKind
3558
3813
  });
3559
3814
  if (result.error) return writeFailure(command, result.error, mode, 1);
3560
3815
  const data = parseProjectsEditData(result.body);
@@ -3662,7 +3917,8 @@ async function runShare(parsed, mode, isRetry = false) {
3662
3917
  authenticated: true,
3663
3918
  baseUrl,
3664
3919
  credentialSource: credential.source,
3665
- profile: credential.profile
3920
+ profile: credential.profile,
3921
+ profileCredentialKind: credential.profileCredentialKind
3666
3922
  });
3667
3923
  if (resolved.error) return handleAuthenticatedCredentialFailure(command, resolved.error, credential, parsed.options, mode, () => runShare(parsed, mode, true), isRetry);
3668
3924
  const { project: _project, ...rest } = parsed.options;
@@ -3699,7 +3955,8 @@ async function runShare(parsed, mode, isRetry = false) {
3699
3955
  authenticated: true,
3700
3956
  baseUrl,
3701
3957
  credentialSource: credential.source,
3702
- profile: credential.profile
3958
+ profile: credential.profile,
3959
+ profileCredentialKind: credential.profileCredentialKind
3703
3960
  }), credential, parsed.options, mode, () => runShare(parsed, mode, true), isRetry);
3704
3961
  const id = body?.id ?? null;
3705
3962
  return writeSuccess(command, {
@@ -3749,7 +4006,8 @@ async function runRequestAccess(parsed, mode) {
3749
4006
  if (request.error) return writeFailure(command, request.error, mode, 1);
3750
4007
  const result = await apiPost("/api/cli/request-access", credential.token, { note }, parsed.options, request.init, {
3751
4008
  credentialSource: credential.source,
3752
- profile: credential.profile
4009
+ profile: credential.profile,
4010
+ profileCredentialKind: credential.profileCredentialKind
3753
4011
  });
3754
4012
  if (result.error) return writeFailure(command, result.error, mode, 1);
3755
4013
  const body = result.body;
@@ -3786,7 +4044,8 @@ async function runResolve(parsed, mode) {
3786
4044
  authenticated: true,
3787
4045
  baseUrl: baseUrlOf(parsed.options),
3788
4046
  credentialSource: credential.source,
3789
- profile: credential.profile
4047
+ profile: credential.profile,
4048
+ profileCredentialKind: credential.profileCredentialKind
3790
4049
  }), mode, 1);
3791
4050
  if (!resolveSuccessFields(body)) return writeFailure(command, serviceError("Resolve succeeded but the response did not include query, candidates, and has_more."), mode, 1);
3792
4051
  return writeSuccess(command, body, mode);
@@ -3827,7 +4086,8 @@ async function runUpdate(parsed, mode, isRetry = false) {
3827
4086
  artifactTarget: true,
3828
4087
  baseUrl,
3829
4088
  credentialSource: credential.source,
3830
- profile: credential.profile
4089
+ profile: credential.profile,
4090
+ profileCredentialKind: credential.profileCredentialKind
3831
4091
  }), credential, parsed.options, mode, () => runUpdate(parsed, mode, true), isRetry);
3832
4092
  const id = body?.id ?? artifactId;
3833
4093
  const result = {
@@ -3852,7 +4112,8 @@ async function runWhoami(parsed, mode) {
3852
4112
  if (request.error) return writeFailure(command, request.error, mode, 1);
3853
4113
  const whoami = await apiGet("/api/cli/whoami", credential.token, parsed.options, request.init, {
3854
4114
  credentialSource: credential.source,
3855
- profile: credential.profile
4115
+ profile: credential.profile,
4116
+ profileCredentialKind: credential.profileCredentialKind
3856
4117
  });
3857
4118
  if (whoami.error) return writeFailure(command, whoami.error, mode, 1);
3858
4119
  return writeSuccess(command, isRecord(whoami.body) ? {
@@ -4582,6 +4843,11 @@ const commentsPostDefinition = define({
4582
4843
  type: "string",
4583
4844
  toKebab: true,
4584
4845
  description: "Text just after the quote, to pick the right occurrence"
4846
+ },
4847
+ agent: {
4848
+ type: "string",
4849
+ toKebab: true,
4850
+ description: "Agent name posting on behalf of the user (e.g. Claude, Cursor)"
4585
4851
  }
4586
4852
  },
4587
4853
  examples: `npx --yes @artifactshare/cli comments post abc123def4 --body "Looks good" --json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artifactshare/cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
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",
@@ -4,7 +4,7 @@ description: Open, share, update, and read back shared files with the Artifact S
4
4
  ---
5
5
 
6
6
  <!-- artifactshare-skill
7
- version: 16
7
+ version: 18
8
8
  managed: true
9
9
  -->
10
10
 
@@ -16,12 +16,7 @@ files and folders, and is designed for agents: every command supports `--json`
16
16
  with a stable contract.
17
17
 
18
18
  Run commands with `npx --yes @artifactshare/cli`. When unsure about a
19
- command or flag, read `npx --yes @artifactshare/cli --help` first.
20
-
21
- First-time setup in a project: `npx --yes @artifactshare/cli init` detects the
22
- agent (Claude Code, Codex, Cursor), installs or updates this skill, and reports
23
- the next steps (sign in, then share). When you receive a share URL instead,
24
- start with `open <artifact-id-or-url> --json`.
19
+ command or flag, run `npx --yes @artifactshare/cli <command> --help` first.
25
20
 
26
21
  Use the CLI whenever the file already exists locally as a file or folder.
27
22
  The remote MCP tools accept HTML or Markdown source strings; they cannot read
@@ -31,10 +26,22 @@ When passing paths or free-form text through a shell, quote them. Paths may
31
26
  contain `$`, spaces, `*`, or `?`; use single quotes such as
32
27
  `'apps/web/app/routes/a.$id/index.tsx'` so the shell does not expand them.
33
28
 
34
- ## Output contract
35
-
36
- - Always pass `--json`. Success prints `{"schema_version":2,"ok":true,"command":...,"data":...}` to stdout; failure prints `{"schema_version":2,"ok":false,"error":...}` to stderr with exit code 1.
37
- - On failure, read `error.code`, `error.hint`, and `error.recovery`. `recovery.kind` is one of `change_input`, `run_command`, `retry_later`, `ask_human`, `report_issue`. When `error.requires_human` is true, report to the user instead of retrying.
29
+ ## Quick reference
30
+
31
+ | Task | Command |
32
+ | ----------------------- | ----------------------------------------------- |
33
+ | Share a file or folder | `share <path> --json` |
34
+ | Replace with same URL | `update <target> <path> --json` |
35
+ | Read back source | `artifacts get <target> --json` |
36
+ | Download a site bundle | `download <target> --output ./out --json` |
37
+ | List your artifacts | `artifacts list --json` |
38
+ | Post a comment | `comments post <target> --body '<text>' --json` |
39
+ | Read comments | `comments list <target> --json` |
40
+ | Change title or sharing | `edit <target> --title 'New' --json` |
41
+ | Move to a project | `edit <target> --project-id <id> --json` |
42
+ | Create a project | `projects create 'Name' --json` |
43
+ | Find an ID from a title | `resolve <value> --json` |
44
+ | Open a share URL | `open <url> --json` |
38
45
 
39
46
  ## Authentication
40
47
 
@@ -43,63 +50,182 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
43
50
  `ARTIFACTSHARE_TOKEN` or `--token` for normal commands.
44
51
  - `login --profile <name>` prints a sign-in URL and code (device flow); only
45
52
  suggest it in interactive sessions. Do not pass API tokens to `login`.
53
+ Profiles created by `login` renew expired CLI sessions automatically.
46
54
  - To keep using an issued token as a named profile without TTY or browser
47
55
  login, pipe it on standard input:
48
56
  `printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile <name> --json`.
57
+ Imported API-token profiles are not renewed by the CLI.
49
58
  Use `--allow-plaintext-token-store` only on a trusted machine without a native token store.
50
- - Saved profiles (`--profile`) are created by `login` or `profiles import-token`.
51
- - Check the current state with `whoami --json`, or `doctor --json` for authentication, destination, network, and upload access at once.
52
-
53
- ## Choosing the destination
59
+ - Check the current state with `whoami --json`, or `doctor --json` for
60
+ authentication, destination, network, upload access, and skill update status.
54
61
 
55
- 1. `projects list --json` shows the projects this account can share into; `is_default` marks the working-directory default.
56
- 2. `projects create <name> --json` creates a project and returns `project.id` plus a `next_command` using `share --project-id <id>`.
57
- 3. `projects edit <id> --name 'New name' --json`, `projects edit <id> --visibility private --json`, `projects edit <id> --add-email person@example.com --json`, `projects edit <id> --remove-email person@example.com --json`, `projects edit <id> --archive --json`, and `projects edit <id> --unarchive --json` change the project settings and audience.
58
- 4. `init --project-id <id> --json` saves a default project for the working directory.
59
- 5. `share` resolves the destination from `--project-id`, then the saved default, then `--home` (the home destination for files not placed in a project). Without any of these it fails with `destination_required`.
60
- 6. `edit <artifact-id-or-url> --project-id <id> --json` moves an existing file into a project; `edit <artifact-id-or-url> --home --json` moves it back home.
61
- 7. `edit <artifact-id-or-url> --title 'New title' --json`, `edit <artifact-id-or-url> --visibility private --json`, `edit <artifact-id-or-url> --grant-email person@example.com --json`, and `edit <artifact-id-or-url> --revoke-email person@example.com --json` change post-share settings.
62
+ ## Share
62
63
 
63
- `edit` changes settings without adding a new version. Moving a `project`
64
- visibility artifact home makes it `private`, because home has no project
65
- audience. The older `move` command remains available for placement-only
66
- automation, but prefer `edit` for new flows.
67
-
68
- ## Core commands
64
+ Use `share` for new files. Use `update` to replace an existing artifact.
69
65
 
70
66
  ```bash
71
- npx --yes @artifactshare/cli open <artifact-id-or-url> --json
72
67
  npx --yes @artifactshare/cli share ./report.html --json
73
68
  npx --yes @artifactshare/cli share ./site-dir --project-id <id> --json
74
- npx --yes @artifactshare/cli projects create 'Client reports' --json
75
- npx --yes @artifactshare/cli projects edit <id> --add-email viewer@example.com --json
76
- npx --yes @artifactshare/cli edit <artifact-id-or-url> --project-id <id> --json
77
- npx --yes @artifactshare/cli edit <artifact-id-or-url> --visibility private --grant-email viewer@example.com --json
69
+ ```
70
+
71
+ - `share` accepts a single `.html` / `.md` file or a static-site directory.
72
+ The returned `share_url` is the link to give the user.
73
+ - Pick the destination with `--project-id <id>`, `--project <name>` (by exact
74
+ name, no prior `resolve` needed), the saved default from `init`, or `--home`.
75
+ Without any of these it fails with `destination_required`.
76
+ - Set visibility at share time with `--visibility private|workspace|project`.
77
+ When `--grant-email` is passed, the default becomes `private`.
78
+ - For repeat jobs with a stable caller-owned name, use
79
+ `share <path> --key <key> --json`: the first run creates the artifact, later
80
+ runs add versions to the same artifact.
81
+ - Run `share --help` for all flags.
82
+
83
+ ## Update
84
+
85
+ Use `update` to add a new version to an existing artifact while keeping its URL.
86
+
87
+ ```bash
78
88
  npx --yes @artifactshare/cli update <artifact-id-or-url> ./report.html --json
79
- npx --yes @artifactshare/cli delete <artifact-id-or-url> --json
80
- npx --yes @artifactshare/cli artifacts list --json
89
+ ```
90
+
91
+ - To keep an existing share URL, do not run `share --artifact-id`; use `update`.
92
+ - Pass the same kind of input (single file vs directory) it was created with.
93
+ - `update` does not change title, visibility, viewers, or placement. Use `edit`
94
+ for those.
95
+ - Run `update --help` for all flags.
96
+
97
+ ## Read back and download
98
+
99
+ Use `artifacts get` for single-file sources. Use `download` for static sites.
100
+
101
+ ```bash
81
102
  npx --yes @artifactshare/cli artifacts get <artifact-id-or-url> --json
103
+ npx --yes @artifactshare/cli artifacts get <artifact-id-or-url> --include versions --include comments --json
82
104
  npx --yes @artifactshare/cli download <artifact-id-or-url> --output ./out --json
105
+ ```
106
+
107
+ - If `artifacts get` returns `truncated: true`, call again with `--offset` set
108
+ to `next_offset`.
109
+ - `--include versions` and `--include comments` fetch version history or
110
+ inline comments in one call.
111
+ - `download` saves static-site bundles. Pass `--force` to overwrite an existing
112
+ output directory.
113
+ - Find artifact IDs with `artifacts list --json`. Filter with `--project-id`,
114
+ `--home`, or `--query <text>`.
115
+ - When the user gives a title, project name, or URL instead of an ID, run
116
+ `resolve <value> --json` first and use the returned ID.
117
+ - Run `artifacts get --help` or `download --help` for all flags.
118
+
119
+ ## Comment
120
+
121
+ Use `comments list` to read, `comments post` to write. IDs from `list` feed
122
+ into `edit`, `resolve`, `reopen`, and `delete`.
123
+
124
+ ```bash
83
125
  npx --yes @artifactshare/cli comments list <artifact-id-or-url> --json
84
126
  npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body '<text>' --json
85
- npx --yes @artifactshare/cli comments edit <artifact-id-or-url> --message-id <message-id> --body '<text>' --json
86
- npx --yes @artifactshare/cli comments resolve <artifact-id-or-url> --thread-id <thread-id> --json
87
- npx --yes @artifactshare/cli comments reopen <artifact-id-or-url> --thread-id <thread-id> --json
88
- npx --yes @artifactshare/cli comments delete <artifact-id-or-url> --thread-id <thread-id> --message-id <message-id> --json
127
+ npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body '<text>' --reply-to <thread-id> --json
128
+ npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body '<text>' --quote 'exact text' --json
129
+ npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body '<text>' --agent 'Claude' --json
130
+ ```
131
+
132
+ - `--reply-to <thread-id>` replies to an existing thread from `comments list`.
133
+ - `--quote <text>` anchors a new thread to the quoted text. Copy the text from
134
+ `artifacts get` so it matches exactly. When the same text appears more than
135
+ once, add `--quote-before` and/or `--quote-after` to pick the right one.
136
+ Do not combine `--quote` with `--reply-to`.
137
+ - `--agent <name>` declares the posting agent (e.g. `Claude`, `Cursor`).
138
+ The comment shows an agent badge in the viewer. Omit to post without a badge.
139
+ `comments list` returns an `agent` field on messages posted with this flag.
140
+
141
+ ```bash
142
+ npx --yes @artifactshare/cli comments edit <artifact-id-or-url> --message-id <id> --body '<text>' --json
143
+ npx --yes @artifactshare/cli comments resolve <artifact-id-or-url> --thread-id <id> --json
144
+ npx --yes @artifactshare/cli comments reopen <artifact-id-or-url> --thread-id <id> --json
145
+ npx --yes @artifactshare/cli comments delete <artifact-id-or-url> --thread-id <id> --message-id <id> --json
146
+ ```
147
+
148
+ - Comment deletion cannot be undone. Omit `--message-id` only when the user
149
+ wants the whole thread deleted.
150
+ - Run `comments post --help` for all flags.
151
+
152
+ ## Organize and settings
153
+
154
+ Use `edit` for post-share changes. Use `projects list/create/edit` for
155
+ project management.
156
+
157
+ ```bash
158
+ npx --yes @artifactshare/cli edit <artifact-id-or-url> --title 'New title' --json
159
+ npx --yes @artifactshare/cli edit <artifact-id-or-url> --visibility private --grant-email viewer@example.com --json
160
+ npx --yes @artifactshare/cli edit <artifact-id-or-url> --project-id <id> --json
161
+ npx --yes @artifactshare/cli edit <artifact-id-or-url> --home --json
162
+ npx --yes @artifactshare/cli delete <artifact-id-or-url> --json
163
+ ```
164
+
165
+ - `edit` changes title, visibility, explicit viewers, or project placement
166
+ without adding a new version.
167
+ - Moving a `project` visibility artifact home makes it `private`, because home
168
+ has no project audience.
169
+ - The older `move` command remains available for placement-only automation, but
170
+ prefer `edit` for new flows.
171
+ - `delete` permanently removes an artifact and its version history. Use only
172
+ when the user explicitly asks.
173
+
174
+ ```bash
175
+ npx --yes @artifactshare/cli projects list --json
176
+ npx --yes @artifactshare/cli projects create 'Client reports' --json
177
+ npx --yes @artifactshare/cli projects create 'Internal' --visibility private --json
178
+ npx --yes @artifactshare/cli projects edit <id> --add-email viewer@example.com --json
179
+ npx --yes @artifactshare/cli projects edit <id> --archive --json
89
180
  ```
90
181
 
91
- - When the user gives an Artifact Share URL, start with `open <artifact-id-or-url> --json`. It ensures this skill is installed or updated, then reads single-file artifacts or returns a `download` next command for static sites and multi-file artifacts.
92
- - `share` accepts a single `.html` / `.md` file or a static-site directory. The returned `share_url` is the link to give the user.
93
- - To keep an existing share URL, do not run `share --artifact-id`; run `update <artifact-id-or-url> <path> --json` instead.
94
- - For repeat jobs where the caller can choose a stable name, use `share <path> --key <key> --json`: the first run creates the artifact, later runs add versions to the same artifact.
95
- - `update` adds a new version to an existing file; pass the same kind of input (single file vs directory) it was created with. It does not change title, visibility, explicit viewers, or project placement.
96
- - `edit` changes the display title, visibility, explicit viewers, or project placement after sharing.
97
- - `projects edit` changes a project name, description, sharing scope, audience, or archive state. Use IDs from `projects list --json`.
98
- - `delete` permanently removes an artifact you shared, including its version history. Use it only when the user explicitly asks to delete.
99
- - Use `artifacts list --json` to find recent artifact IDs for `update`, `edit`, `move`, `delete`, `artifacts get`, or `comments list`. Filter with `--project-id <id>`, `--home`, or `--query <text>`.
100
- - Use IDs from `comments list --json` for `comments edit`, `comments resolve`, `comments reopen`, and `comments delete`. Comment deletion cannot be undone; omit `--message-id` only when the user wants the whole thread deleted.
101
- - When the user gives a title, project name, or URL instead of an ID, run `resolve <value> --json` first and use the returned ID.
102
- - `artifacts get` reads back single-file sources (use `--offset` to continue truncated reads); `download` saves static-site bundles.
182
+ - `projects create` defaults to `--visibility workspace`. Pass
183
+ `--visibility private` for confidential projects.
184
+ - `projects edit` changes name, description, visibility, audience
185
+ (`--add-email` / `--remove-email`), and archive state (`--archive` /
186
+ `--unarchive`).
187
+ - `init --project-id <id> --json` saves a default project for the working
188
+ directory. `init --dry-run --json` previews the setup without side effects.
189
+ - Run `edit --help`, `projects create --help`, or `projects edit --help` for
190
+ all flags.
191
+
192
+ ## Profiles
193
+
194
+ ```bash
195
+ npx --yes @artifactshare/cli profiles list --json
196
+ npx --yes @artifactshare/cli profiles use <name> --json
197
+ ```
198
+
199
+ - `profiles list` shows saved profiles and the default.
200
+ - `profiles use` switches the default profile.
201
+ - To create a profile, use `login --profile <name>` (interactive) or
202
+ `profiles import-token` (non-interactive, see Authentication).
203
+
204
+ ## Skills
205
+
206
+ ```bash
207
+ npx --yes @artifactshare/cli skills ensure --tool auto --json
208
+ npx --yes @artifactshare/cli skills update --json
209
+ npx --yes @artifactshare/cli skills list --json
210
+ ```
211
+
212
+ - `skills ensure --tool auto` detects the agent (Claude Code, Codex, Cursor)
213
+ and installs this skill if missing, or reports when an update is available.
214
+ - `skills update` updates installed skills to the bundled version.
215
+ - `skills install --tool <name> --scope user` installs the skill at the user
216
+ level instead of the project. `--force` overwrites an unmanaged file.
217
+ - Run `skills --help` for all subcommands.
218
+
219
+ ## Output contract
220
+
221
+ - Always pass `--json`. Success prints
222
+ `{"schema_version":2,"ok":true,"command":...,"data":...}` to stdout; failure
223
+ prints `{"schema_version":2,"ok":false,"error":...}` to stderr with exit
224
+ code 1.
225
+ - On failure, read `error.code`, `error.hint`, and `error.recovery`.
226
+ `recovery.kind` is one of `change_input`, `run_command`, `retry_later`,
227
+ `ask_human`, `report_issue`. When `error.requires_human` is true, report to
228
+ the user instead of retrying.
103
229
 
104
230
  ## Upload access
105
231
 
@@ -107,3 +233,11 @@ If `share` or `update` fails with `upload_not_allowed`, run
107
233
  `request-access --note '<why>' --json` to join the waitlist, then tell the
108
234
  user that sharing stays closed until an operator opens it. Do not retry
109
235
  share in a loop.
236
+
237
+ ## First-time setup
238
+
239
+ `npx --yes @artifactshare/cli init` detects the agent, installs or updates
240
+ this skill, and reports the next steps (sign in, then share). When you receive
241
+ a share URL instead, start with `open <artifact-id-or-url> --json`. It ensures
242
+ this skill is installed or updated, then reads single-file artifacts or returns
243
+ a `download` next command for static sites and multi-file artifacts.
@@ -4,7 +4,7 @@ alwaysApply: false
4
4
  ---
5
5
 
6
6
  <!-- artifactshare-skill
7
- version: 16
7
+ version: 18
8
8
  managed: true
9
9
  -->
10
10
 
@@ -12,12 +12,8 @@ managed: true
12
12
 
13
13
  Artifact Share hosts shared files (HTML pages, Markdown documents, static
14
14
  sites) with versions and comments. Use `npx --yes @artifactshare/cli` to
15
- open shared URLs and share local files from the terminal, and read
16
- `npx --yes @artifactshare/cli --help` before choosing a command.
17
-
18
- First-time setup in a project: `npx --yes @artifactshare/cli init` detects the
19
- agent (Claude Code, Codex, Cursor), installs or updates this rule, and reports
20
- the next steps (sign in, then share).
15
+ share local files, open shared URLs, and manage artifacts from the terminal.
16
+ Run `npx --yes @artifactshare/cli <command> --help` before choosing a command.
21
17
 
22
18
  Use the CLI for local files and folders. The remote MCP tools accept HTML or
23
19
  Markdown source strings; they cannot read paths like `/Users/.../report.html`
@@ -29,18 +25,23 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
29
25
 
30
26
  - Always pass `--json`; on failure read `error.code`, `error.hint`, and `error.recovery`.
31
27
  - In agents, CI, or scripts, ask the user to issue an API token at `https://artifactshare.com/settings/tokens`, then run normal commands with `ARTIFACTSHARE_TOKEN` or `--token`; do not pass API tokens to `login`.
32
- - To save that token as a named profile without TTY or browser login, pipe it on standard input: `printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile <name> --json`. Add `--allow-plaintext-token-store` only on a trusted machine without a native token store.
33
- - Use `login --profile <name>` only in an interactive terminal where the user can approve the browser device flow.
28
+ - To save that token as a named profile without TTY or browser login, pipe it on standard input: `printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile <name> --json`. Imported API-token profiles are not renewed by the CLI. Add `--allow-plaintext-token-store` only on a trusted machine without a native token store.
29
+ - Use `login --profile <name>` only in an interactive terminal where the user can approve the browser device flow. Profiles created by `login` renew expired CLI sessions automatically.
30
+ - Switch profiles with `profiles use <name> --json`; list with `profiles list --json`.
34
31
  - 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.
35
- - Pick the destination with `projects list --json`, `projects create <name> --json`, `init --project-id <id>`, or `--project-id`.
36
- - Change project settings with `projects edit <id> --name 'New name' --json`, `projects edit <id> --visibility private --json`, `projects edit <id> --add-email person@example.com --json`, `projects edit <id> --remove-email person@example.com --json`, `projects edit <id> --archive --json`, or `projects edit <id> --unarchive --json`.
37
- - Change post-share settings with `edit <artifact-id-or-url> --title 'New title' --json`, `edit <artifact-id-or-url> --visibility private --json`, `edit <artifact-id-or-url> --grant-email person@example.com --json`, `edit <artifact-id-or-url> --revoke-email person@example.com --json`, `edit <artifact-id-or-url> --project-id <id> --json`, or `edit <artifact-id-or-url> --home --json`. Moving a `project` visibility file home makes it `private`.
38
- - `move <artifact-id-or-url> --project-id <id> --json` and `move <artifact-id-or-url> --home --json` remain available for placement-only automation, but prefer `edit` for new flows.
39
- - Share with `share <path> --json`. To keep an existing share URL, do not use `share --artifact-id`; add a version with `update <artifact-id-or-url> <path> --json`.
32
+ - 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`.
40
33
  - 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.
34
+ - 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.
35
+ - 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`.
36
+ - Download static-site bundles with `download <target> --output ./out --json`. Pass `--force` to overwrite an existing output directory.
37
+ - Find artifact IDs with `artifacts list --json`; filter with `--project-id <id>`, `--home`, or `--query <text>`. Resolve titles, project names, and URLs to IDs with `resolve <value> --json`.
38
+ - Comment with `comments post <target> --body '<text>' --json`. Reply with `--reply-to <thread-id>`. Anchor to quoted text with `--quote '<text>'`; add `--quote-before`/`--quote-after` to disambiguate. Declare the posting agent with `--agent '<name>'` (e.g. `Claude`); omit for no badge. `comments list` returns an `agent` field on agent-posted messages.
39
+ - Edit, resolve, reopen, and delete comments with `comments edit`, `comments resolve`, `comments reopen`, and `comments delete` using IDs from `comments list`. Comment deletion cannot be undone; omit `--message-id` from `comments delete` only when the user wants the whole thread deleted.
40
+ - Change post-share settings with `edit <target>`: `--title`, `--visibility`, `--grant-email`, `--revoke-email`, `--project-id`, `--home`. Moving a `project` visibility file home makes it `private`. `move` remains for placement-only automation; prefer `edit`.
41
41
  - Permanently remove an artifact only when the user explicitly asks with `delete <artifact-id-or-url> --json`.
42
- - Find recent artifact IDs with `artifacts list --json`; filter with `--project-id <id>`, `--home`, or `--query <text>`.
43
- - Resolve titles, project names, and URLs to IDs with `resolve <value> --json` before writing.
44
- - Read back with `artifacts get` / `download`; comment with `comments list` / `comments post`; use `comments edit`, `comments resolve`, `comments reopen`, and `comments delete` with IDs from `comments list`.
45
- - Comment deletion cannot be undone. Omit `--message-id` from `comments delete` only when the user wants the whole thread deleted.
42
+ - 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`).
43
+ - Save a default project with `init --project-id <id> --json`. Preview setup with `init --dry-run --json`.
44
+ - 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
45
  - On `upload_not_allowed`, run `request-access --note '<why>' --json` and tell the user an operator opens sharing; do not retry in a loop.
46
+ - Check the current state with `whoami --json` or `doctor --json` for authentication, destination, network, upload access, and skill update status.
47
+ - First-time setup: `npx --yes @artifactshare/cli init` detects the agent, installs or updates this rule, and reports the next steps (sign in, then share).