@artifactshare/cli 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,9 +1,9 @@
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";
6
- import { setTimeout } from "node:timers/promises";
6
+ import { setTimeout as setTimeout$1 } from "node:timers/promises";
7
7
  import { homedir } from "node:os";
8
8
  import { createReadStream } from "node:fs";
9
9
  import { createHash } from "node:crypto";
@@ -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) {
@@ -1217,6 +1234,104 @@ function spawnFile(command, args, input) {
1217
1234
  else child.stdin.end();
1218
1235
  });
1219
1236
  }
1237
+ function browserOpenSkipReason() {
1238
+ if (process.env.CI === "true") return "ci";
1239
+ if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) return "headless_linux";
1240
+ return null;
1241
+ }
1242
+ function resolveBrowserOpener(url) {
1243
+ if (process.platform === "darwin") return {
1244
+ command: "open",
1245
+ args: [url],
1246
+ label: "open"
1247
+ };
1248
+ if (process.platform === "win32") return {
1249
+ command: "rundll32",
1250
+ args: ["url.dll,FileProtocolHandler", url],
1251
+ label: "rundll32"
1252
+ };
1253
+ return {
1254
+ command: "xdg-open",
1255
+ args: [url],
1256
+ label: "xdg-open"
1257
+ };
1258
+ }
1259
+ const BROWSER_OPENER_CLOSE_TIMEOUT_MS = 1500;
1260
+ function spawnDetached(command, args) {
1261
+ return new Promise((resolve) => {
1262
+ const child = spawn(command, args, {
1263
+ stdio: "ignore",
1264
+ detached: true
1265
+ });
1266
+ let settled = false;
1267
+ const finish = (result) => {
1268
+ if (settled) return;
1269
+ settled = true;
1270
+ clearTimeout(timeoutId);
1271
+ resolve(result);
1272
+ };
1273
+ const timeoutId = setTimeout(() => {
1274
+ child.unref();
1275
+ finish({ status: "started" });
1276
+ }, BROWSER_OPENER_CLOSE_TIMEOUT_MS);
1277
+ child.once("error", (error) => {
1278
+ finish({
1279
+ status: "failed",
1280
+ reason: error instanceof Error ? error.message : String(error)
1281
+ });
1282
+ });
1283
+ child.once("close", (code, signal) => {
1284
+ if (signal) {
1285
+ finish({
1286
+ status: "failed",
1287
+ reason: `signal_${signal}`
1288
+ });
1289
+ return;
1290
+ }
1291
+ if (code === 0) {
1292
+ finish({ status: "started" });
1293
+ return;
1294
+ }
1295
+ finish({
1296
+ status: "failed",
1297
+ reason: `exit_${code ?? "null"}`
1298
+ });
1299
+ });
1300
+ });
1301
+ }
1302
+ async function openDeviceAuthorizationUrl(url) {
1303
+ const testOpener = process.env.ARTIFACTSHARE_TEST_BROWSER_OPENER?.trim();
1304
+ if (testOpener === "success") return {
1305
+ attempted: true,
1306
+ status: "started",
1307
+ command: "test"
1308
+ };
1309
+ if (testOpener === "fail") return {
1310
+ attempted: true,
1311
+ status: "failed",
1312
+ command: "test",
1313
+ reason: "spawn_failed"
1314
+ };
1315
+ const skipReason = browserOpenSkipReason();
1316
+ if (skipReason) return {
1317
+ attempted: false,
1318
+ status: "skipped",
1319
+ reason: skipReason
1320
+ };
1321
+ const opener = resolveBrowserOpener(url);
1322
+ const spawnResult = await spawnDetached(opener.command, opener.args);
1323
+ if (spawnResult.status === "failed") return {
1324
+ attempted: true,
1325
+ status: "failed",
1326
+ command: opener.label,
1327
+ reason: spawnResult.reason
1328
+ };
1329
+ return {
1330
+ attempted: true,
1331
+ status: "started",
1332
+ command: opener.label
1333
+ };
1334
+ }
1220
1335
  //#endregion
1221
1336
  //#region src/destination.ts
1222
1337
  function destinationConflictError(options) {
@@ -1309,32 +1424,40 @@ async function readProfileToken(profile, options) {
1309
1424
  const account = accountName(profile, baseUrlOf(options));
1310
1425
  const native = await nativeStore();
1311
1426
  if (native) {
1312
- const token = await native.read(account);
1313
- if (token) return {
1314
- ok: true,
1315
- token,
1427
+ const parsed = parseStoredProfileCredential(await native.read(account));
1428
+ if (parsed.ok) return {
1429
+ ...parsed,
1316
1430
  store: native.kind
1317
1431
  };
1432
+ if (parsed.reason === "legacy") return parsed;
1318
1433
  }
1319
- const plaintext = await readPlaintextToken(account);
1320
- if (plaintext) return {
1321
- ok: true,
1322
- token: plaintext,
1434
+ const plaintext = parseStoredProfileCredential(await readPlaintextToken(account));
1435
+ if (plaintext.ok) return {
1436
+ ...plaintext,
1323
1437
  store: "plaintext_file"
1324
1438
  };
1439
+ if (plaintext.reason === "legacy") return plaintext;
1325
1440
  return {
1326
1441
  ok: false,
1327
1442
  reason: native || options.allowPlaintextTokenStore ? "missing" : "unavailable"
1328
1443
  };
1329
1444
  }
1330
- async function saveProfileToken(profile, token, options) {
1445
+ async function saveProfileSessionCredential(profile, credential, options) {
1446
+ return await saveProfileCredential(profile, credential, options);
1447
+ }
1448
+ async function saveProfileApiTokenCredential(profile, credential, options) {
1449
+ return await saveProfileCredential(profile, credential, options);
1450
+ }
1451
+ async function saveProfileCredential(profile, credential, options) {
1331
1452
  const account = accountName(profile, baseUrlOf(options));
1453
+ const value = JSON.stringify(credential);
1332
1454
  const native = await nativeStore();
1333
- if (native && await native.write(account, token)) return {
1455
+ if (native && await native.write(account, value)) return {
1334
1456
  ok: true,
1335
1457
  store: native.kind
1336
1458
  };
1337
- if (options.allowPlaintextTokenStore && await writePlaintextToken(account, token)) return {
1459
+ const hasPlaintextEntry = await readPlaintextToken(account) !== null;
1460
+ if ((options.allowPlaintextTokenStore || hasPlaintextEntry) && await writePlaintextToken(account, value)) return {
1338
1461
  ok: true,
1339
1462
  store: "plaintext_file"
1340
1463
  };
@@ -1343,6 +1466,53 @@ async function saveProfileToken(profile, token, options) {
1343
1466
  reason: "unavailable"
1344
1467
  };
1345
1468
  }
1469
+ function parseStoredProfileCredential(raw) {
1470
+ if (!raw) return {
1471
+ ok: false,
1472
+ reason: "missing"
1473
+ };
1474
+ const parsed = parseJsonRecord(raw);
1475
+ if (!parsed) return {
1476
+ ok: false,
1477
+ reason: "legacy"
1478
+ };
1479
+ 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)) {
1480
+ const credential = {
1481
+ kind: "session",
1482
+ session_token: parsed.session_token,
1483
+ refresh_token: parsed.refresh_token,
1484
+ ...parsed.expires_at !== void 0 ? { expires_at: parsed.expires_at } : {}
1485
+ };
1486
+ return {
1487
+ ok: true,
1488
+ token: credential.session_token,
1489
+ credential
1490
+ };
1491
+ }
1492
+ if (parsed.kind === "api_token" && typeof parsed.token === "string" && parsed.token) {
1493
+ const credential = {
1494
+ kind: "api_token",
1495
+ token: parsed.token
1496
+ };
1497
+ return {
1498
+ ok: true,
1499
+ token: credential.token,
1500
+ credential
1501
+ };
1502
+ }
1503
+ return {
1504
+ ok: false,
1505
+ reason: "legacy"
1506
+ };
1507
+ }
1508
+ function parseJsonRecord(raw) {
1509
+ try {
1510
+ const parsed = JSON.parse(raw);
1511
+ return isRecord(parsed) ? parsed : null;
1512
+ } catch {
1513
+ return null;
1514
+ }
1515
+ }
1346
1516
  async function readGlobalConfig() {
1347
1517
  const home = configHome();
1348
1518
  if (!home) return null;
@@ -1600,7 +1770,9 @@ async function resolveProfileCredential(source, profile, options, globalConfig,
1600
1770
  ok: true,
1601
1771
  source,
1602
1772
  profile,
1603
- token: stored.token
1773
+ token: stored.token,
1774
+ profileCredentialKind: stored.credential.kind,
1775
+ ...stored.credential.kind === "session" ? { refreshToken: stored.credential.refresh_token } : {}
1604
1776
  };
1605
1777
  return profileAuthRequired(source, profile, stored.reason, options, globalConfig, configPath, configKind);
1606
1778
  }
@@ -1608,7 +1780,7 @@ async function profileAuthRequired(source, profile, reason, options, globalConfi
1608
1780
  const baseUrl = baseUrlOf(options);
1609
1781
  const url = tokensUrl(baseUrl);
1610
1782
  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}".`;
1783
+ 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
1784
  const alternative = await findAlternativeProfileWithToken(globalConfig, options, profile);
1613
1785
  const details = {
1614
1786
  ...authRecoveryDetails(baseUrl, `${CLI_INVOCATION} login --profile ${profile}`),
@@ -1724,15 +1896,18 @@ async function performDeviceLogin(profile, options, mode) {
1724
1896
  error: code.error
1725
1897
  };
1726
1898
  const deadline = Date.now() + code.expires_in * 1e3;
1727
- if (mode.json) writeEvent({
1728
- status: "pending",
1729
- verification_uri: code.verification_uri,
1730
- verification_uri_complete: code.verification_uri_complete ?? null,
1731
- user_code: code.user_code,
1732
- expires_at: new Date(deadline).toISOString(),
1733
- interval_seconds: code.interval
1734
- });
1735
- else writeText([
1899
+ if (mode.json) {
1900
+ const browserOpen = await openDeviceAuthorizationUrl(code.verification_uri_complete ?? code.verification_uri);
1901
+ writeEvent({
1902
+ status: "pending",
1903
+ verification_uri: code.verification_uri,
1904
+ verification_uri_complete: code.verification_uri_complete ?? null,
1905
+ user_code: code.user_code,
1906
+ expires_at: new Date(deadline).toISOString(),
1907
+ interval_seconds: code.interval,
1908
+ browser_open: browserOpen
1909
+ });
1910
+ } else writeText([
1736
1911
  "Open this URL in a browser to sign in:",
1737
1912
  code.verification_uri_complete ?? code.verification_uri,
1738
1913
  "",
@@ -1746,7 +1921,7 @@ async function performDeviceLogin(profile, options, mode) {
1746
1921
  error: token.error
1747
1922
  };
1748
1923
  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);
1924
+ const stored = await verifyAndStoreProfileToken(profile, token.access_token, options, request.init, sessionExpiresAt);
1750
1925
  if (!stored.ok) return {
1751
1926
  ok: false,
1752
1927
  error: stored.error
@@ -1837,7 +2012,7 @@ async function pollForToken(options, code, init, profile, deadline) {
1837
2012
  let intervalMs = Math.max(code.interval, 1) * 1e3;
1838
2013
  let networkFailures = 0;
1839
2014
  while (Date.now() < deadline) {
1840
- await setTimeout(intervalMs);
2015
+ await setTimeout$1(intervalMs);
1841
2016
  const response = await fetch(apiUrl("/api/auth/device/token", baseUrlOf(options)), {
1842
2017
  method: "POST",
1843
2018
  headers: { "content-type": "application/json" },
@@ -1868,39 +2043,97 @@ async function pollForToken(options, code, init, profile, deadline) {
1868
2043
  }
1869
2044
  return { error: authExpiredError(profile) };
1870
2045
  }
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 {
2046
+ async function verifyAndStoreProfileToken(profile, token, options, init, sessionExpiresAt = null) {
2047
+ const verified = await verifyProfileTokenAccount(profile, token, options, init);
2048
+ if (!verified.ok) return verified;
2049
+ const refresh = await issueCliRefreshCredential(token, options, init);
2050
+ if ("error" in refresh) return {
1875
2051
  ok: false,
1876
- error: whoamiResult.error
2052
+ error: refresh.error
1877
2053
  };
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 {
2054
+ const saved = await saveProfileSessionCredential(profile, {
2055
+ kind: "session",
2056
+ session_token: token,
2057
+ refresh_token: refresh.refresh_token,
2058
+ expires_at: sessionExpiresAt
2059
+ }, options);
2060
+ if (!saved.ok) return {
1882
2061
  ok: false,
1883
- error: authAccountMismatchError(profile, expectedEmail, whoami.email)
2062
+ error: tokenStoreUnavailableError(profile)
2063
+ };
2064
+ await writeProfileConfig(profile, options, saved.store, verified.whoami);
2065
+ return {
2066
+ ok: true,
2067
+ data: {
2068
+ profile,
2069
+ token_store: saved.store,
2070
+ user: { email: verified.whoami.email },
2071
+ workspace: {
2072
+ id: verified.whoami.workspace_id,
2073
+ hosted_domain: verified.whoami.hosted_domain
2074
+ }
2075
+ }
1884
2076
  };
1885
- const saved = await saveProfileToken(profile, token, options);
2077
+ }
2078
+ async function verifyAndStoreApiTokenProfile(profile, token, options, init) {
2079
+ const verified = await verifyProfileTokenAccount(profile, token, options, init);
2080
+ if (!verified.ok) return verified;
2081
+ const saved = await saveProfileApiTokenCredential(profile, {
2082
+ kind: "api_token",
2083
+ token
2084
+ }, options);
1886
2085
  if (!saved.ok) return {
1887
2086
  ok: false,
1888
2087
  error: tokenStoreUnavailableError(profile)
1889
2088
  };
1890
- await writeProfileConfig(profile, options, saved.store, whoami);
2089
+ await writeProfileConfig(profile, options, saved.store, verified.whoami);
1891
2090
  return {
1892
2091
  ok: true,
1893
2092
  data: {
1894
2093
  profile,
1895
2094
  token_store: saved.store,
1896
- user: { email: whoami.email },
2095
+ user: { email: verified.whoami.email },
1897
2096
  workspace: {
1898
- id: whoami.workspace_id,
1899
- hosted_domain: whoami.hosted_domain
2097
+ id: verified.whoami.workspace_id,
2098
+ hosted_domain: verified.whoami.hosted_domain
1900
2099
  }
1901
2100
  }
1902
2101
  };
1903
2102
  }
2103
+ async function verifyProfileTokenAccount(profile, token, options, init) {
2104
+ const config = await readGlobalConfig() ?? {};
2105
+ const whoamiResult = await apiGet("/api/cli/whoami", token, options, init, {
2106
+ authenticated: true,
2107
+ baseUrl: baseUrlOf(options)
2108
+ });
2109
+ if (whoamiResult.error) return {
2110
+ ok: false,
2111
+ error: whoamiResult.error
2112
+ };
2113
+ const whoami = whoamiProfile(whoamiResult.body);
2114
+ const profiles = config.profiles ?? {};
2115
+ const expectedEmail = nonEmpty((Object.hasOwn(profiles, profile) ? profiles[profile] : void 0)?.email);
2116
+ if (expectedEmail && whoami.email !== expectedEmail) return {
2117
+ ok: false,
2118
+ error: authAccountMismatchError(profile, expectedEmail, whoami.email)
2119
+ };
2120
+ return {
2121
+ ok: true,
2122
+ whoami
2123
+ };
2124
+ }
2125
+ async function issueCliRefreshCredential(token, options, init) {
2126
+ const result = await apiPost("/api/cli/auth/refresh-credentials", token, {}, options, init, {
2127
+ authenticated: true,
2128
+ baseUrl: baseUrlOf(options)
2129
+ });
2130
+ if (result.error) return { error: result.error };
2131
+ if (typeof result.body?.refresh_token === "string" && typeof result.body.refresh_token_expires_at === "string") return {
2132
+ refresh_token: result.body.refresh_token,
2133
+ refresh_token_expires_at: result.body.refresh_token_expires_at
2134
+ };
2135
+ return { error: validationError("Refresh credential response was invalid.", "Retry login. If this repeats, report the response shape.", "service_error") };
2136
+ }
1904
2137
  async function writeProfileConfig(profile, options, tokenStore, whoami) {
1905
2138
  const config = await readGlobalConfig() ?? {};
1906
2139
  const profiles = config.profiles ?? {};
@@ -1986,6 +2219,11 @@ async function handleCredentialFailure(command, credential, options, mode, rerun
1986
2219
  }
1987
2220
  async function handleAuthenticatedCredentialFailure(command, error, credential, options, mode, rerun, isRetry = false) {
1988
2221
  if (error.code !== "auth_required") return writeFailure(command, error, mode, 1);
2222
+ if (!isRetry && credential.profile && credential.profileCredentialKind === "session" && credential.refreshToken) {
2223
+ const refreshed = await refreshStoredProfileSession(credential.profile, credential.refreshToken, options);
2224
+ if (refreshed.ok) return rerun();
2225
+ if (refreshed.error) return writeFailure(command, refreshed.error, mode, 1);
2226
+ }
1989
2227
  return await handleCredentialFailure(command, {
1990
2228
  ok: false,
1991
2229
  source: credential.source,
@@ -1993,6 +2231,40 @@ async function handleAuthenticatedCredentialFailure(command, error, credential,
1993
2231
  error
1994
2232
  }, options, mode, rerun, isRetry);
1995
2233
  }
2234
+ async function refreshStoredProfileSession(profile, refreshToken, options) {
2235
+ const request = await requestConfig(options);
2236
+ if (request.error) return {
2237
+ ok: false,
2238
+ error: request.error
2239
+ };
2240
+ const result = await apiPostPublic("/api/cli/auth/refresh", { refresh_token: refreshToken }, options, request.init);
2241
+ if (result.error) return {
2242
+ ok: false,
2243
+ error: result.error
2244
+ };
2245
+ const { response, body } = result;
2246
+ if (!response.ok) {
2247
+ if (response.status === 401) return { ok: false };
2248
+ return {
2249
+ ok: false,
2250
+ error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) })
2251
+ };
2252
+ }
2253
+ if (typeof body?.access_token !== "string" || body.access_token.length === 0 || body.token_type?.toLowerCase() !== "bearer" || typeof body.expires_at !== "string") return {
2254
+ ok: false,
2255
+ error: validationError("Refresh response was invalid.", "Run login again. If this repeats, report the response shape.", "service_error")
2256
+ };
2257
+ if (!(await saveProfileSessionCredential(profile, {
2258
+ kind: "session",
2259
+ session_token: body.access_token,
2260
+ refresh_token: refreshToken,
2261
+ expires_at: body.expires_at
2262
+ }, options)).ok) return {
2263
+ ok: false,
2264
+ error: tokenStoreUnavailableError(profile)
2265
+ };
2266
+ return { ok: true };
2267
+ }
1996
2268
  async function handleJsonPendingAuth(command, credential, options, mode, rerun) {
1997
2269
  const profile = profileForAutoLogin(credential);
1998
2270
  const extraDetails = authRequiredExtraDetails(credential.error);
@@ -2008,7 +2280,7 @@ async function handleJsonPendingAuth(command, credential, options, mode, rerun)
2008
2280
  return writeFailure(command, exchange.error, mode, 1);
2009
2281
  }
2010
2282
  if (exchange.status === "success") {
2011
- const stored = await verifyAndStoreProfileToken(profile, exchange.token.access_token, options, request.init);
2283
+ 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
2284
  if (!stored.ok) return writeFailure(command, stored.error, mode, 1);
2013
2285
  await clearPendingDeviceAuth(baseUrl, profile);
2014
2286
  return rerun();
@@ -2042,13 +2314,6 @@ async function runArtifactsGet(parsed, mode, isRetry = false) {
2042
2314
  if (result.error) return handleAuthenticatedCredentialFailure(command, result.error, credential, parsed.options, mode, () => runArtifactsGet(parsed, mode, true), isRetry);
2043
2315
  return writeSuccess(command, result.data, mode);
2044
2316
  }
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
2317
  function parseArtifactReadTarget(parsed, command) {
2053
2318
  const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to read.");
2054
2319
  if (target.error) return { error: target.error };
@@ -2080,7 +2345,8 @@ async function fetchArtifact(parsed, target, credential) {
2080
2345
  artifactTarget: true,
2081
2346
  baseUrl: baseUrlOf(parsed.options),
2082
2347
  credentialSource: credential.source,
2083
- profile: credential.profile
2348
+ profile: credential.profile,
2349
+ profileCredentialKind: credential.profileCredentialKind
2084
2350
  }) };
2085
2351
  if (!artifactGetSuccessFields(body)) return { error: serviceError("Artifact read succeeded but the response did not include source metadata.") };
2086
2352
  return { data: body };
@@ -2112,7 +2378,8 @@ async function runArtifactsList(parsed, mode) {
2112
2378
  authenticated: true,
2113
2379
  baseUrl: baseUrlOf(parsed.options),
2114
2380
  credentialSource: credential.source,
2115
- profile: credential.profile
2381
+ profile: credential.profile,
2382
+ profileCredentialKind: credential.profileCredentialKind
2116
2383
  }), mode, 1);
2117
2384
  if (!artifactsListSuccessFields(body)) return writeFailure(command, serviceError("Artifact list succeeded but the response did not include list metadata."), mode, 1);
2118
2385
  return writeSuccess(command, body, mode);
@@ -2262,6 +2529,9 @@ async function autoTargets(scope) {
2262
2529
  for (const tool of autoOrder) if (TOOL_CONFIG[tool].scopes.includes(targetScope) && await isToolDetected(tool, targetScope)) detected.add(tool);
2263
2530
  return (detected.size > 0 ? [...detected] : ["codex", "claude"]).filter((tool) => TOOL_CONFIG[tool].scopes.includes(targetScope)).map((tool) => skillTarget(tool, targetScope));
2264
2531
  }
2532
+ function targetPathKey(target) {
2533
+ return realpath(target.absolutePath).catch(() => target.absolutePath);
2534
+ }
2265
2535
  async function applyAction({ target, action, content }) {
2266
2536
  if (content !== void 0) {
2267
2537
  await mkdir(dirname(target.absolutePath), { recursive: true });
@@ -2285,20 +2555,33 @@ async function cleanupSkillDirs(target) {
2285
2555
  dir = dirname(dir);
2286
2556
  }
2287
2557
  }
2558
+ function skillUpdateCommand(target) {
2559
+ return `${CLI_INVOCATION} skills update --tool ${target.tool} --scope ${target.scope} --json`;
2560
+ }
2288
2561
  async function finishActions(command, planned, dryRun, mode) {
2289
- if (!dryRun) try {
2290
- for (const item of planned) await applyAction(item);
2562
+ const completed = [...planned];
2563
+ if (!dryRun) for (const [index, item] of planned.entries()) try {
2564
+ await applyAction(item);
2565
+ completed[index] = item;
2291
2566
  } catch (error) {
2567
+ if (item.fallbackAction) {
2568
+ completed[index] = {
2569
+ target: item.target,
2570
+ action: item.fallbackAction
2571
+ };
2572
+ continue;
2573
+ }
2292
2574
  writeFailure(command, unexpectedError(error), mode, 1);
2293
2575
  return;
2294
2576
  }
2295
2577
  return {
2296
2578
  dry_run: dryRun,
2297
- targets: planned.map(({ target, action }) => ({
2579
+ targets: completed.map(({ target, action }) => ({
2298
2580
  tool: target.tool,
2299
2581
  scope: target.scope,
2300
2582
  path: target.path,
2301
- action
2583
+ action,
2584
+ ...action === "update_recommended" ? { update_command: skillUpdateCommand(target) } : {}
2302
2585
  }))
2303
2586
  };
2304
2587
  }
@@ -2366,15 +2649,33 @@ async function ensureSkills(parsed, mode, options = {}) {
2366
2649
  return;
2367
2650
  }
2368
2651
  const unchanged = state.kind === "managed" && state.version === bundled.version;
2652
+ const recommendUpdate = options.recommendProjectUpdates && target.scope === "project" && state.kind === "managed" && state.version !== bundled.version;
2369
2653
  planned.push(unchanged ? {
2370
2654
  target,
2371
2655
  action: "unchanged"
2656
+ } : recommendUpdate ? {
2657
+ target,
2658
+ action: "update_recommended"
2372
2659
  } : {
2373
2660
  target,
2374
2661
  action: state.kind === "missing" ? "installed" : "updated",
2375
2662
  content: bundled.contents[target.tool]
2376
2663
  });
2377
2664
  }
2665
+ if (options.autoUpdateUserManaged) {
2666
+ const plannedPaths = new Set(await Promise.all(planned.map((action) => targetPathKey(action.target))));
2667
+ for (const target of allTargets().filter((candidate) => candidate.scope === "user")) {
2668
+ if (plannedPaths.has(await targetPathKey(target))) continue;
2669
+ const state = await readTarget(target);
2670
+ if (state.kind !== "managed" || state.version === bundled.version) continue;
2671
+ planned.push({
2672
+ target,
2673
+ action: "updated",
2674
+ content: bundled.contents[target.tool],
2675
+ fallbackAction: "update_recommended"
2676
+ });
2677
+ }
2678
+ }
2378
2679
  return finishActions(command, planned, parsed.options.dryRun === true, mode);
2379
2680
  }
2380
2681
  async function runSkillsEnsure(parsed, mode) {
@@ -2403,6 +2704,31 @@ async function runSkillsList(parsed, mode) {
2403
2704
  targets
2404
2705
  }, mode);
2405
2706
  }
2707
+ async function skillDiagnostics() {
2708
+ const bundled = await loadBundledSkills();
2709
+ const targets = [];
2710
+ for (const target of allTargets()) {
2711
+ const state = await readTarget(target);
2712
+ const updateAvailable = state.kind === "managed" && state.version !== bundled.version;
2713
+ targets.push({
2714
+ tool: target.tool,
2715
+ scope: target.scope,
2716
+ path: target.path,
2717
+ installed: state.kind !== "missing",
2718
+ managed: state.kind === "managed",
2719
+ installed_version: state.kind === "managed" ? state.version : null,
2720
+ update_available: updateAvailable,
2721
+ update_command: updateAvailable ? skillUpdateCommand(target) : null
2722
+ });
2723
+ }
2724
+ const updateTargets = targets.filter((target) => target.update_available);
2725
+ return {
2726
+ bundled_version: bundled.version,
2727
+ update_available: updateTargets.length > 0,
2728
+ update_command: updateTargets.length > 0 ? `${CLI_INVOCATION} skills update --json` : null,
2729
+ targets
2730
+ };
2731
+ }
2406
2732
  async function runSkillsUpdate(parsed, mode) {
2407
2733
  const command = "skills update";
2408
2734
  const filters = parseFilters(parsed);
@@ -2451,7 +2777,7 @@ async function runSkillsRemove(parsed, mode) {
2451
2777
  }
2452
2778
  //#endregion
2453
2779
  //#region src/command-runners/open.ts
2454
- async function runOpen(parsed, mode) {
2780
+ async function runOpen(parsed, mode, isRetry = false) {
2455
2781
  const command = "open";
2456
2782
  const skills = await ensureSkills({
2457
2783
  ...parsed,
@@ -2460,11 +2786,21 @@ async function runOpen(parsed, mode) {
2460
2786
  tool: "auto",
2461
2787
  scope: "project"
2462
2788
  }
2463
- }, mode, { command });
2789
+ }, mode, {
2790
+ command,
2791
+ autoUpdateUserManaged: true,
2792
+ recommendProjectUpdates: true
2793
+ });
2464
2794
  if (!skills) return;
2465
2795
  const target = parseArtifactTarget(parsed.positionals[0], command, "Pass an artifact ID or share URL to read.");
2466
2796
  if (target.error) return writeFailure(command, target.error, mode, 1);
2467
- const result = await readArtifact(parsed, command);
2797
+ const credential = await resolveCredential(parsed.options, await resolveProjectConfig());
2798
+ if (!credential.ok) return handleCredentialFailure(command, credential, parsed.options, mode, () => runOpen(parsed, mode, true), isRetry);
2799
+ const result = await fetchArtifact(parsed, {
2800
+ artifactId: target.artifactId,
2801
+ include: [],
2802
+ offset: void 0
2803
+ }, credential);
2468
2804
  if (result.error) {
2469
2805
  if (result.error.code === "unsupported_kind") return writeSuccess(command, {
2470
2806
  skills,
@@ -2473,6 +2809,7 @@ async function runOpen(parsed, mode) {
2473
2809
  next_command: agentDownloadCommand(target.artifactId)
2474
2810
  }
2475
2811
  }, mode);
2812
+ if (result.error.code === "auth_required") return handleAuthenticatedCredentialFailure(command, result.error, credential, parsed.options, mode, () => runOpen(parsed, mode, true), isRetry);
2476
2813
  return writeFailure(command, result.error, mode, 1);
2477
2814
  }
2478
2815
  return writeSuccess(command, {
@@ -2497,7 +2834,8 @@ async function runCommentsList(parsed, mode) {
2497
2834
  const result = await apiGet(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, parsed.options, request.init, {
2498
2835
  artifactTarget: true,
2499
2836
  credentialSource: credential.source,
2500
- profile: credential.profile
2837
+ profile: credential.profile,
2838
+ profileCredentialKind: credential.profileCredentialKind
2501
2839
  });
2502
2840
  if (result.error) return writeFailure(command, result.error, mode, 1);
2503
2841
  const comments = Array.isArray(result.body?.comments) ? result.body.comments : [];
@@ -2524,16 +2862,19 @@ async function runCommentsPost(parsed, mode) {
2524
2862
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
2525
2863
  const request = await requestConfig(parsed.options);
2526
2864
  if (request.error) return writeFailure(command, request.error, mode, 1);
2865
+ const agent = parsed.options.agent;
2527
2866
  const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, {
2528
2867
  body,
2529
2868
  reply_to: replyTo,
2530
2869
  quote,
2531
2870
  quote_before: parsed.options.quoteBefore,
2532
- quote_after: parsed.options.quoteAfter
2871
+ quote_after: parsed.options.quoteAfter,
2872
+ ...agent ? { agent } : {}
2533
2873
  }, parsed.options, request.init, {
2534
2874
  artifactTarget: true,
2535
2875
  credentialSource: credential.source,
2536
- profile: credential.profile
2876
+ profile: credential.profile,
2877
+ profileCredentialKind: credential.profileCredentialKind
2537
2878
  });
2538
2879
  if (result.error) return writeFailure(command, result.error, mode, 1);
2539
2880
  const threadId = configString(result.body?.thread_id);
@@ -2635,7 +2976,8 @@ async function postCommentAction(parsed, command, artifactId, payload, mode) {
2635
2976
  const result = await apiPost(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/comments`, credential.token, payload, parsed.options, request.init, {
2636
2977
  artifactTarget: true,
2637
2978
  credentialSource: credential.source,
2638
- profile: credential.profile
2979
+ profile: credential.profile,
2980
+ profileCredentialKind: credential.profileCredentialKind
2639
2981
  });
2640
2982
  if (result.error) {
2641
2983
  writeFailure(command, result.error, mode, 1);
@@ -2666,7 +3008,8 @@ async function runDelete(parsed, mode) {
2666
3008
  authenticated: true,
2667
3009
  artifactTarget: true,
2668
3010
  credentialSource: credential.source,
2669
- profile: credential.profile
3011
+ profile: credential.profile,
3012
+ profileCredentialKind: credential.profileCredentialKind
2670
3013
  });
2671
3014
  if (result.error) return writeFailure(command, result.error, mode, 1);
2672
3015
  const body = result.body;
@@ -2722,6 +3065,7 @@ async function runDoctor(parsed, mode) {
2722
3065
  next_command: null,
2723
3066
  base_url: baseUrlOf(parsed.options),
2724
3067
  config: await configDiagnostics(project),
3068
+ skills: await skillDiagnostics(),
2725
3069
  auth: {
2726
3070
  credential_source: credential.source,
2727
3071
  ...credential.profile ? { profile: credential.profile } : {},
@@ -2770,7 +3114,8 @@ async function runDoctor(parsed, mode) {
2770
3114
  authenticated: true,
2771
3115
  baseUrl: baseUrlOf(parsed.options),
2772
3116
  credentialSource: credential.source,
2773
- profile: credential.profile
3117
+ profile: credential.profile,
3118
+ profileCredentialKind: credential.profileCredentialKind
2774
3119
  });
2775
3120
  data.auth.code = error.code;
2776
3121
  data.auth.hint = error.hint;
@@ -3024,7 +3369,8 @@ async function runDownload(parsed, mode, isRetry = false) {
3024
3369
  artifactTarget: true,
3025
3370
  baseUrl,
3026
3371
  credentialSource: credential.source,
3027
- profile: credential.profile
3372
+ profile: credential.profile,
3373
+ profileCredentialKind: credential.profileCredentialKind
3028
3374
  }), credential, parsed.options, mode, () => runDownload(parsed, mode, true), isRetry);
3029
3375
  if (!downloadManifestFields(body)) return writeFailure(command, serviceError("Download manifest succeeded but the response did not include file metadata."), mode, 1);
3030
3376
  const plan = await prepareDownloadPlan(body, parsed.options.output ?? artifactId, Boolean(parsed.options.force));
@@ -3044,7 +3390,8 @@ async function runDownload(parsed, mode, isRetry = false) {
3044
3390
  artifactTarget: true,
3045
3391
  baseUrl,
3046
3392
  credentialSource: credential.source,
3047
- profile: credential.profile
3393
+ profile: credential.profile,
3394
+ profileCredentialKind: credential.profileCredentialKind
3048
3395
  }), credential, parsed.options, mode, () => runDownload(parsed, mode, true), isRetry);
3049
3396
  const bytes = Buffer.from(await fileResponse.arrayBuffer());
3050
3397
  const verified = verifyDownloadedBytes(file, bytes);
@@ -3101,7 +3448,8 @@ async function runEdit(parsed, mode) {
3101
3448
  artifactTarget: true,
3102
3449
  editSettings: true,
3103
3450
  credentialSource: credential.source,
3104
- profile: credential.profile
3451
+ profile: credential.profile,
3452
+ profileCredentialKind: credential.profileCredentialKind
3105
3453
  });
3106
3454
  if (result.error) return writeFailure(command, result.error, mode, 1);
3107
3455
  const data = parseEditData(result.body);
@@ -3263,7 +3611,11 @@ async function runInitOnboarding(parsed, mode) {
3263
3611
  tool: "auto",
3264
3612
  scope: "project"
3265
3613
  }
3266
- }, mode, { command });
3614
+ }, mode, {
3615
+ command,
3616
+ autoUpdateUserManaged: true,
3617
+ recommendProjectUpdates: true
3618
+ });
3267
3619
  if (!skills) return;
3268
3620
  const project = await resolveProjectConfig();
3269
3621
  const signedIn = (await resolveCredential(parsed.options, project)).ok;
@@ -3278,7 +3630,11 @@ function onboardingNextSteps(signedIn) {
3278
3630
  return [{
3279
3631
  id: "login",
3280
3632
  title: signedIn ? "Already signed in." : "Sign in so you can share files.",
3281
- command: `${CLI_INVOCATION} login`,
3633
+ command: `${CLI_INVOCATION} login --json`,
3634
+ ...!signedIn ? {
3635
+ requires_browser_approval: true,
3636
+ awaits_user_action: true
3637
+ } : {},
3282
3638
  done: signedIn
3283
3639
  }, {
3284
3640
  id: "share",
@@ -3340,7 +3696,8 @@ async function runMove(parsed, mode) {
3340
3696
  const result = await apiPost(`/api/cli/shareables/${encodeURIComponent(target.artifactId)}/move`, credential.token, { destination: home ? "home" : { project_id: projectId } }, parsed.options, request.init, {
3341
3697
  artifactTarget: true,
3342
3698
  credentialSource: credential.source,
3343
- profile: credential.profile
3699
+ profile: credential.profile,
3700
+ profileCredentialKind: credential.profileCredentialKind
3344
3701
  });
3345
3702
  if (result.error) return writeFailure(command, result.error, mode, 1);
3346
3703
  const data = parseMoveData(result.body);
@@ -3456,7 +3813,7 @@ async function runProfilesImportToken(parsed, mode) {
3456
3813
  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
3814
  const request = await requestConfig(parsed.options);
3458
3815
  if (request.error) return writeFailure(command, request.error, mode, 1);
3459
- const stored = await verifyAndStoreProfileToken(profile, token, parsed.options, request.init);
3816
+ const stored = await verifyAndStoreApiTokenProfile(profile, token, parsed.options, request.init);
3460
3817
  if (!stored.ok) return writeFailure(command, stored.error, mode, 1);
3461
3818
  return writeSuccess(command, {
3462
3819
  profile,
@@ -3493,7 +3850,8 @@ async function runProjectsList(parsed, mode) {
3493
3850
  if (request.error) return writeFailure(command, request.error, mode, 1);
3494
3851
  const result = await fetchProjects(credential.token, parsed.options, request.init, {
3495
3852
  credentialSource: credential.source,
3496
- profile: credential.profile
3853
+ profile: credential.profile,
3854
+ profileCredentialKind: credential.profileCredentialKind
3497
3855
  });
3498
3856
  if (result.error) return writeFailure(command, result.error, mode, 1);
3499
3857
  const defaultProjectId = configString(projectConfig.config?.default_project_id);
@@ -3524,7 +3882,8 @@ async function runProjectsCreate(parsed, mode) {
3524
3882
  base_visibility: visibility ?? null
3525
3883
  }, parsed.options, request.init, {
3526
3884
  credentialSource: credential.source,
3527
- profile: credential.profile
3885
+ profile: credential.profile,
3886
+ profileCredentialKind: credential.profileCredentialKind
3528
3887
  });
3529
3888
  if (result.error) return writeFailure(command, result.error, mode, 1);
3530
3889
  const project = isRecord(result.body?.project) ? result.body.project : null;
@@ -3554,7 +3913,8 @@ async function runProjectsEdit(parsed, mode) {
3554
3913
  const result = await apiPost(`/api/cli/projects/${encodeURIComponent(projectId)}`, credential.token, payload.body, parsed.options, request.init, {
3555
3914
  projectTarget: true,
3556
3915
  credentialSource: credential.source,
3557
- profile: credential.profile
3916
+ profile: credential.profile,
3917
+ profileCredentialKind: credential.profileCredentialKind
3558
3918
  });
3559
3919
  if (result.error) return writeFailure(command, result.error, mode, 1);
3560
3920
  const data = parseProjectsEditData(result.body);
@@ -3662,7 +4022,8 @@ async function runShare(parsed, mode, isRetry = false) {
3662
4022
  authenticated: true,
3663
4023
  baseUrl,
3664
4024
  credentialSource: credential.source,
3665
- profile: credential.profile
4025
+ profile: credential.profile,
4026
+ profileCredentialKind: credential.profileCredentialKind
3666
4027
  });
3667
4028
  if (resolved.error) return handleAuthenticatedCredentialFailure(command, resolved.error, credential, parsed.options, mode, () => runShare(parsed, mode, true), isRetry);
3668
4029
  const { project: _project, ...rest } = parsed.options;
@@ -3699,7 +4060,8 @@ async function runShare(parsed, mode, isRetry = false) {
3699
4060
  authenticated: true,
3700
4061
  baseUrl,
3701
4062
  credentialSource: credential.source,
3702
- profile: credential.profile
4063
+ profile: credential.profile,
4064
+ profileCredentialKind: credential.profileCredentialKind
3703
4065
  }), credential, parsed.options, mode, () => runShare(parsed, mode, true), isRetry);
3704
4066
  const id = body?.id ?? null;
3705
4067
  return writeSuccess(command, {
@@ -3749,7 +4111,8 @@ async function runRequestAccess(parsed, mode) {
3749
4111
  if (request.error) return writeFailure(command, request.error, mode, 1);
3750
4112
  const result = await apiPost("/api/cli/request-access", credential.token, { note }, parsed.options, request.init, {
3751
4113
  credentialSource: credential.source,
3752
- profile: credential.profile
4114
+ profile: credential.profile,
4115
+ profileCredentialKind: credential.profileCredentialKind
3753
4116
  });
3754
4117
  if (result.error) return writeFailure(command, result.error, mode, 1);
3755
4118
  const body = result.body;
@@ -3786,7 +4149,8 @@ async function runResolve(parsed, mode) {
3786
4149
  authenticated: true,
3787
4150
  baseUrl: baseUrlOf(parsed.options),
3788
4151
  credentialSource: credential.source,
3789
- profile: credential.profile
4152
+ profile: credential.profile,
4153
+ profileCredentialKind: credential.profileCredentialKind
3790
4154
  }), mode, 1);
3791
4155
  if (!resolveSuccessFields(body)) return writeFailure(command, serviceError("Resolve succeeded but the response did not include query, candidates, and has_more."), mode, 1);
3792
4156
  return writeSuccess(command, body, mode);
@@ -3827,7 +4191,8 @@ async function runUpdate(parsed, mode, isRetry = false) {
3827
4191
  artifactTarget: true,
3828
4192
  baseUrl,
3829
4193
  credentialSource: credential.source,
3830
- profile: credential.profile
4194
+ profile: credential.profile,
4195
+ profileCredentialKind: credential.profileCredentialKind
3831
4196
  }), credential, parsed.options, mode, () => runUpdate(parsed, mode, true), isRetry);
3832
4197
  const id = body?.id ?? artifactId;
3833
4198
  const result = {
@@ -3852,7 +4217,8 @@ async function runWhoami(parsed, mode) {
3852
4217
  if (request.error) return writeFailure(command, request.error, mode, 1);
3853
4218
  const whoami = await apiGet("/api/cli/whoami", credential.token, parsed.options, request.init, {
3854
4219
  credentialSource: credential.source,
3855
- profile: credential.profile
4220
+ profile: credential.profile,
4221
+ profileCredentialKind: credential.profileCredentialKind
3856
4222
  });
3857
4223
  if (whoami.error) return writeFailure(command, whoami.error, mode, 1);
3858
4224
  return writeSuccess(command, isRecord(whoami.body) ? {
@@ -4582,6 +4948,11 @@ const commentsPostDefinition = define({
4582
4948
  type: "string",
4583
4949
  toKebab: true,
4584
4950
  description: "Text just after the quote, to pick the right occurrence"
4951
+ },
4952
+ agent: {
4953
+ type: "string",
4954
+ toKebab: true,
4955
+ description: "Agent name posting on behalf of the user (e.g. Claude, Cursor)"
4585
4956
  }
4586
4957
  },
4587
4958
  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.1",
4
4
  "description": "Upload and share HTML, Markdown, folders, and static sites from terminals, AI agents, automation, and CI.",
5
5
  "homepage": "https://artifactshare.com/connect",
6
6
  "license": "Apache-2.0",
@@ -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: 19
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,75 +26,207 @@ 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
 
41
48
  - In non-interactive environments (agents, CI, scripts), ask the user to issue
42
49
  an API token at `https://artifactshare.com/settings/tokens`, then use
43
50
  `ARTIFACTSHARE_TOKEN` or `--token` for normal commands.
44
- - `login --profile <name>` prints a sign-in URL and code (device flow); only
45
- suggest it in interactive sessions. Do not pass API tokens to `login`.
51
+ - `login --profile <name> --json` starts device login and may open the OS
52
+ browser for approval. Use it when a user is present; the pending event on
53
+ stderr includes `browser_open`. Do not pass API tokens to `login`.
54
+ Profiles created by `login` renew expired CLI sessions automatically.
46
55
  - To keep using an issued token as a named profile without TTY or browser
47
56
  login, pipe it on standard input:
48
57
  `printf '%s' "$TOKEN" | npx --yes @artifactshare/cli profiles import-token --profile <name> --json`.
58
+ Imported API-token profiles are not renewed by the CLI.
49
59
  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
60
+ - Check the current state with `whoami --json`, or `doctor --json` for
61
+ authentication, destination, network, upload access, and skill update status.
54
62
 
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.
63
+ ## Share
62
64
 
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
65
+ Use `share` for new files. Use `update` to replace an existing artifact.
69
66
 
70
67
  ```bash
71
- npx --yes @artifactshare/cli open <artifact-id-or-url> --json
72
68
  npx --yes @artifactshare/cli share ./report.html --json
73
69
  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
70
+ ```
71
+
72
+ - `share` accepts a single `.html` / `.md` file or a static-site directory.
73
+ The returned `share_url` is the link to give the user.
74
+ - Pick the destination with `--project-id <id>`, `--project <name>` (by exact
75
+ name, no prior `resolve` needed), the saved default from `init`, or `--home`.
76
+ Without any of these it fails with `destination_required`.
77
+ - Set visibility at share time with `--visibility private|workspace|project`.
78
+ When `--grant-email` is passed, the default becomes `private`.
79
+ - For repeat jobs with a stable caller-owned name, use
80
+ `share <path> --key <key> --json`: the first run creates the artifact, later
81
+ runs add versions to the same artifact.
82
+ - Run `share --help` for all flags.
83
+
84
+ ## Update
85
+
86
+ Use `update` to add a new version to an existing artifact while keeping its URL.
87
+
88
+ ```bash
78
89
  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
90
+ ```
91
+
92
+ - To keep an existing share URL, do not run `share --artifact-id`; use `update`.
93
+ - Pass the same kind of input (single file vs directory) it was created with.
94
+ - `update` does not change title, visibility, viewers, or placement. Use `edit`
95
+ for those.
96
+ - Run `update --help` for all flags.
97
+
98
+ ## Read back and download
99
+
100
+ Use `artifacts get` for single-file sources. Use `download` for static sites.
101
+
102
+ ```bash
81
103
  npx --yes @artifactshare/cli artifacts get <artifact-id-or-url> --json
104
+ npx --yes @artifactshare/cli artifacts get <artifact-id-or-url> --include versions --include comments --json
82
105
  npx --yes @artifactshare/cli download <artifact-id-or-url> --output ./out --json
106
+ ```
107
+
108
+ - If `artifacts get` returns `truncated: true`, call again with `--offset` set
109
+ to `next_offset`.
110
+ - `--include versions` and `--include comments` fetch version history or
111
+ inline comments in one call.
112
+ - `download` saves static-site bundles. Pass `--force` to overwrite an existing
113
+ output directory.
114
+ - Find artifact IDs with `artifacts list --json`. Filter with `--project-id`,
115
+ `--home`, or `--query <text>`.
116
+ - When the user gives a title, project name, or URL instead of an ID, run
117
+ `resolve <value> --json` first and use the returned ID.
118
+ - Run `artifacts get --help` or `download --help` for all flags.
119
+
120
+ ## Comment
121
+
122
+ Use `comments list` to read, `comments post` to write. IDs from `list` feed
123
+ into `edit`, `resolve`, `reopen`, and `delete`.
124
+
125
+ ```bash
83
126
  npx --yes @artifactshare/cli comments list <artifact-id-or-url> --json
84
127
  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
128
+ npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body '<text>' --reply-to <thread-id> --json
129
+ npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body '<text>' --quote 'exact text' --json
130
+ npx --yes @artifactshare/cli comments post <artifact-id-or-url> --body '<text>' --agent 'Claude' --json
131
+ ```
132
+
133
+ - `--reply-to <thread-id>` replies to an existing thread from `comments list`.
134
+ - `--quote <text>` anchors a new thread to the quoted text. Copy the text from
135
+ `artifacts get` so it matches exactly. When the same text appears more than
136
+ once, add `--quote-before` and/or `--quote-after` to pick the right one.
137
+ Do not combine `--quote` with `--reply-to`.
138
+ - `--agent <name>` declares the posting agent (e.g. `Claude`, `Cursor`).
139
+ The comment shows an agent badge in the viewer. Omit to post without a badge.
140
+ `comments list` returns an `agent` field on messages posted with this flag.
141
+
142
+ ```bash
143
+ npx --yes @artifactshare/cli comments edit <artifact-id-or-url> --message-id <id> --body '<text>' --json
144
+ npx --yes @artifactshare/cli comments resolve <artifact-id-or-url> --thread-id <id> --json
145
+ npx --yes @artifactshare/cli comments reopen <artifact-id-or-url> --thread-id <id> --json
146
+ npx --yes @artifactshare/cli comments delete <artifact-id-or-url> --thread-id <id> --message-id <id> --json
147
+ ```
148
+
149
+ - Comment deletion cannot be undone. Omit `--message-id` only when the user
150
+ wants the whole thread deleted.
151
+ - Run `comments post --help` for all flags.
152
+
153
+ ## Organize and settings
154
+
155
+ Use `edit` for post-share changes. Use `projects list/create/edit` for
156
+ project management.
157
+
158
+ ```bash
159
+ npx --yes @artifactshare/cli edit <artifact-id-or-url> --title 'New title' --json
160
+ npx --yes @artifactshare/cli edit <artifact-id-or-url> --visibility private --grant-email viewer@example.com --json
161
+ npx --yes @artifactshare/cli edit <artifact-id-or-url> --project-id <id> --json
162
+ npx --yes @artifactshare/cli edit <artifact-id-or-url> --home --json
163
+ npx --yes @artifactshare/cli delete <artifact-id-or-url> --json
164
+ ```
165
+
166
+ - `edit` changes title, visibility, explicit viewers, or project placement
167
+ without adding a new version.
168
+ - Moving a `project` visibility artifact home makes it `private`, because home
169
+ has no project audience.
170
+ - The older `move` command remains available for placement-only automation, but
171
+ prefer `edit` for new flows.
172
+ - `delete` permanently removes an artifact and its version history. Use only
173
+ when the user explicitly asks.
174
+
175
+ ```bash
176
+ npx --yes @artifactshare/cli projects list --json
177
+ npx --yes @artifactshare/cli projects create 'Client reports' --json
178
+ npx --yes @artifactshare/cli projects create 'Internal' --visibility private --json
179
+ npx --yes @artifactshare/cli projects edit <id> --add-email viewer@example.com --json
180
+ npx --yes @artifactshare/cli projects edit <id> --archive --json
89
181
  ```
90
182
 
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.
183
+ - `projects create` defaults to `--visibility workspace`. Pass
184
+ `--visibility private` for confidential projects.
185
+ - `projects edit` changes name, description, visibility, audience
186
+ (`--add-email` / `--remove-email`), and archive state (`--archive` /
187
+ `--unarchive`).
188
+ - `init --project-id <id> --json` saves a default project for the working
189
+ directory. `init --dry-run --json` previews the setup without side effects.
190
+ - Run `edit --help`, `projects create --help`, or `projects edit --help` for
191
+ all flags.
192
+
193
+ ## Profiles
194
+
195
+ ```bash
196
+ npx --yes @artifactshare/cli profiles list --json
197
+ npx --yes @artifactshare/cli profiles use <name> --json
198
+ ```
199
+
200
+ - `profiles list` shows saved profiles and the default.
201
+ - `profiles use` switches the default profile.
202
+ - To create a profile, use `login --profile <name>` (interactive) or
203
+ `profiles import-token` (non-interactive, see Authentication).
204
+
205
+ ## Skills
206
+
207
+ ```bash
208
+ npx --yes @artifactshare/cli skills ensure --tool auto --json
209
+ npx --yes @artifactshare/cli skills update --json
210
+ npx --yes @artifactshare/cli skills list --json
211
+ ```
212
+
213
+ - `skills ensure --tool auto` detects the agent (Claude Code, Codex, Cursor)
214
+ and installs this skill if missing, or reports when an update is available.
215
+ - `skills update` updates installed skills to the bundled version.
216
+ - `skills install --tool <name> --scope user` installs the skill at the user
217
+ level instead of the project. `--force` overwrites an unmanaged file.
218
+ - Run `skills --help` for all subcommands.
219
+
220
+ ## Output contract
221
+
222
+ - Always pass `--json`. Success prints
223
+ `{"schema_version":2,"ok":true,"command":...,"data":...}` to stdout; failure
224
+ prints `{"schema_version":2,"ok":false,"error":...}` to stderr with exit
225
+ code 1.
226
+ - On failure, read `error.code`, `error.hint`, and `error.recovery`.
227
+ `recovery.kind` is one of `change_input`, `run_command`, `retry_later`,
228
+ `ask_human`, `report_issue`. When `error.requires_human` is true, report to
229
+ the user instead of retrying.
103
230
 
104
231
  ## Upload access
105
232
 
@@ -107,3 +234,11 @@ If `share` or `update` fails with `upload_not_allowed`, run
107
234
  `request-access --note '<why>' --json` to join the waitlist, then tell the
108
235
  user that sharing stays closed until an operator opens it. Do not retry
109
236
  share in a loop.
237
+
238
+ ## First-time setup
239
+
240
+ `npx --yes @artifactshare/cli init` detects the agent, installs or updates
241
+ this skill, and reports the next steps (sign in, then share). When you receive
242
+ a share URL instead, start with `open <artifact-id-or-url> --json`. It ensures
243
+ this skill is installed or updated, then reads single-file artifacts or returns
244
+ 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: 19
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> --json` when a user is present for browser approval. The pending event on stderr includes `browser_open`. 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 --json` detects the agent, installs or updates this rule, and reports the next steps (sign in, then share).