@artifactshare/cli 0.6.0 → 0.7.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/CHANGELOG.md ADDED
@@ -0,0 +1,45 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@artifactshare/cli` are documented here.
4
+ For user-facing announcements, see https://artifactshare.com/updates?product=cli.
5
+
6
+ ## 0.7.0 - 2026-07-13
7
+
8
+ - Share without a destination now posts to home, so agents and automation have a predictable first destination.
9
+ - Configure `home_audience` for a user or repository to choose whether home posts are private or visible to the workspace.
10
+ - Repository settings take precedence over user settings, giving teams a shared default while preserving a personal fallback.
11
+
12
+ ## 0.6.1 - 2026-07-12
13
+
14
+ - Fix `--insecure-localhost` failing every command with `network_failed` on Node 22/24 by routing all CLI HTTP requests through undici's own fetch
15
+
16
+ ## 0.6.0 - 2026-07-11
17
+
18
+ - Add Cursor user-scope skill install and update support
19
+ - Move automatic skill install and update to user scope by default
20
+
21
+ ## 0.5.2 - 2026-07-09
22
+
23
+ - Auto-update outdated managed user-scope skills after successful commands
24
+
25
+ ## 0.5.1 - 2026-07-09
26
+
27
+ - Refresh expired session profiles automatically across authenticated API calls
28
+
29
+ ## 0.5.0 - 2026-06-23
30
+
31
+ - Add `logout` to remove saved local credentials
32
+
33
+ ## 0.4.1 - 2026-06-22
34
+
35
+ - Start browser approval automatically during non-interactive JSON login
36
+
37
+ ## 0.4.0 - 2026-06-21
38
+
39
+ - Expand bundled skill coverage to match current CLI commands
40
+ - Refresh CLI login sessions during normal use
41
+ - Report outdated managed skills from `doctor`
42
+
43
+ ## 0.1.0 - 2026-06-11
44
+
45
+ - Initial public releases (0.1.x through 0.3.x): npm publish, agent onboarding with `init` and `open`, bundled skills, `request-access`, and core share, update, download, and comment commands
package/README.md CHANGED
@@ -26,6 +26,8 @@ npx --yes @artifactshare/cli edit <artifact-id-or-url> --visibility private --gr
26
26
  npx --yes @artifactshare/cli update <artifact-id-or-url> ./dist
27
27
  npx --yes @artifactshare/cli delete <artifact-id-or-url> --json
28
28
  npx --yes @artifactshare/cli logout --profile default --json
29
+ npx --yes @artifactshare/cli config get home_audience --json
30
+ npx --yes @artifactshare/cli config set home_audience private --scope repository --json
29
31
  ```
30
32
 
31
33
  To keep an existing share URL, update it with
@@ -58,10 +60,28 @@ runs add versions to the same file.
58
60
  | `request-access` | Join the waitlist when sharing is not enabled yet |
59
61
  | `login` / `logout` / `whoami` | Sign in, remove a saved local credential, and check who you are |
60
62
  | `doctor` | Diagnose auth, destination, network, and upload readiness — tells you the next command to run |
63
+ | `changelog` | Show the installed version, this release's notes, and the public updates page |
61
64
  | `profiles list / use / import-token / delete` | Switch between local account profiles, import an issued token from stdin, and delete profile entries |
62
65
  | `init` | Set up this directory: detect Claude Code, Codex, or Cursor and install the skill in user scope, then show next steps; or save defaults with `--profile` / `--project-id` |
63
66
  | `skills ensure / install / list / update / remove` | Install or update the bundled usage guide in your AI agent's skills |
64
67
 
68
+ Public command paths covered by this reference:
69
+
70
+ `artifacts`, `artifacts get`, `artifacts list`, `changelog`, `comments`, `comments delete`, `comments edit`, `comments list`, `comments post`, `comments reopen`, `comments resolve`, `config`, `config get`, `config set`, `config unset`, `delete`, `doctor`, `download`, `edit`, `init`, `login`, `logout`, `move`, `open`, `profiles`, `profiles delete`, `profiles import-token`, `profiles list`, `profiles use`, `projects`, `projects create`, `projects edit`, `projects list`, `request-access`, `resolve`, `share`, `skills`, `skills ensure`, `skills install`, `skills list`, `skills remove`, `skills update`, `update`, `whoami`.
71
+
72
+ ## Where shared files are delivered
73
+
74
+ Posting to a project delivers to the audience defined by that project. With no destination, `share` posts to home. The repository `home_audience` selects `private` (only you) or `workspace` (everyone in the workspace/company):
75
+
76
+ ```sh
77
+ npx --yes @artifactshare/cli config get home_audience --json
78
+ npx --yes @artifactshare/cli config set home_audience private --scope repository --json
79
+ ```
80
+
81
+ Pass `--visibility` to override the destination default for that post only. For project creation, pass `projects create <name> --visibility private|workspace`; persistent project defaults are documented in `projects create --help`.
82
+
83
+ For the complete settings reference, `home_audience` is the canonical home key. `default_artifact_visibility` remains a compatibility alias, and `default_project_visibility` is the advanced default for `projects create`. User and repository settings are resolved with repository taking precedence, followed by user and product default `workspace`; home also checks the compatibility alias at each scope. Keyless `config get --json` returns only `home_audience`; pass an explicit key to read either other setting. These settings only affect new home posts and project creation; update, edit, Web, and MCP defaults are unchanged.
84
+
65
85
  ## For AI agents
66
86
 
67
87
  For first-time setup in a project, start here:
@@ -95,4 +115,5 @@ Quote paths and free-form text before passing them through a shell. Artifact Sha
95
115
  ## Links
96
116
 
97
117
  - Setup guide for AI tools and terminals: https://artifactshare.com/connect
118
+ - Public updates (Web, CLI, Agent, MCP): https://artifactshare.com/updates
98
119
  - Artifact Share: https://artifactshare.com
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { appendFile, chmod, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
3
2
  import { cli, define, lazy } from "gunshi";
4
3
  import { spawn } from "node:child_process";
4
+ import { appendFile, chmod, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
5
5
  import { basename, dirname, join, relative, resolve, sep } from "node:path";
6
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
+ import { Blob } from "node:buffer";
9
10
  import { createHash } from "node:crypto";
10
11
  //#region src/constants.ts
11
12
  const DEFAULT_BASE_URL = "https://artifactshare.com";
@@ -86,7 +87,9 @@ const COMMAND_NAMES = /* @__PURE__ */ new Set([
86
87
  "profiles",
87
88
  "projects",
88
89
  "skills",
89
- "init"
90
+ "init",
91
+ "changelog",
92
+ "config"
90
93
  ]);
91
94
  const SUBCOMMANDS = {
92
95
  artifacts: ["list", "get"],
@@ -115,6 +118,11 @@ const SUBCOMMANDS = {
115
118
  "update",
116
119
  "remove",
117
120
  "ensure"
121
+ ],
122
+ config: [
123
+ "get",
124
+ "set",
125
+ "unset"
118
126
  ]
119
127
  };
120
128
  const UPDATE_OPTION_KEYS = /* @__PURE__ */ new Set([
@@ -174,11 +182,21 @@ function mapApiError(status, body, options = {}) {
174
182
  suggested_command: REQUEST_ACCESS_COMMAND$1
175
183
  }
176
184
  });
177
- if (apiCode === "upload-suspended") return cliError({
178
- code: "upload_suspended",
179
- message: apiMessage ?? "Your upload permission is suspended.",
180
- why: "Artifact Share suspended upload access for this account.",
181
- hint: "Ask an operator to restore upload access, then retry share.",
185
+ if (apiCode === "self-upload-disabled") return cliError({
186
+ code: "self_upload_disabled",
187
+ message: "This account cannot upload its own files.",
188
+ why: "Email-code sign-in creates a viewer workspace for shared files only.",
189
+ hint: "Sign in with Google or Microsoft on the Artifact Share website, then retry share.",
190
+ agentRecoverable: false,
191
+ requiresHuman: true,
192
+ recovery: { kind: "ask_human" },
193
+ details: { limit: "self_upload" }
194
+ });
195
+ if (apiCode === "workspace-access-revoked") return cliError({
196
+ code: "workspace_access_revoked",
197
+ message: apiMessage ?? "Your access to this workspace has been revoked.",
198
+ why: "Artifact Share revoked this account’s workspace membership.",
199
+ hint: "Ask a workspace administrator to restore membership, then retry share.",
182
200
  agentRecoverable: false,
183
201
  requiresHuman: true,
184
202
  recovery: { kind: "ask_human" }
@@ -665,6 +683,7 @@ function normalizeApiCode(value) {
665
683
  return typeof value === "string" ? value : null;
666
684
  }
667
685
  function uploadBlockedHint(code) {
686
+ if (code === "self-upload-disabled") return "Sign in with Google or Microsoft on the Artifact Share website, then retry share.";
668
687
  if (code === "upload-not-allowed") return `Run ${REQUEST_ACCESS_COMMAND$1} to join the waitlist, then retry share once an operator opens sharing.`;
669
688
  if (code === "upload-policy-unavailable") return "Retry doctor later; upload permission could not be checked.";
670
689
  return "Resolve the upload issue, then retry share.";
@@ -1046,6 +1065,7 @@ function humanSuccess(command, data) {
1046
1065
  if (command === "doctor") return doctorHumanOutput(data);
1047
1066
  if (command === "open") return openHumanOutput(data);
1048
1067
  if (command === "init") return initHumanOutput(data);
1068
+ if (command === "changelog") return changelogHumanOutput(data);
1049
1069
  const output = `${JSON.stringify(data, null, 2)}\n`;
1050
1070
  return suffix ? `${output}${suffix}` : output;
1051
1071
  }
@@ -1102,6 +1122,23 @@ function doctorNextCommand(data) {
1102
1122
  if (!isRecord(data) || !("next_command" in data)) return null;
1103
1123
  return typeof data.next_command === "string" ? data.next_command : null;
1104
1124
  }
1125
+ function changelogHumanOutput(data) {
1126
+ if (!isRecord(data)) return `${JSON.stringify(data, null, 2)}\n`;
1127
+ const version = typeof data.version === "string" ? data.version : "";
1128
+ const updatesUrl = typeof data.updates_url === "string" ? data.updates_url : "";
1129
+ const lines = [
1130
+ `Artifact Share CLI ${version}`,
1131
+ "",
1132
+ `Updates: ${updatesUrl}`
1133
+ ];
1134
+ const latest = data.latest;
1135
+ if (isRecord(latest) && typeof latest.body === "string" && latest.body) {
1136
+ const latestVersion = typeof latest.version === "string" ? latest.version : version;
1137
+ const latestDate = typeof latest.date === "string" ? latest.date : "";
1138
+ lines.push("", `Changes in ${latestVersion} (${latestDate}):`, latest.body);
1139
+ }
1140
+ return `${lines.join("\n")}\n`;
1141
+ }
1105
1142
  function shareSuccessFields(data) {
1106
1143
  if (!isRecord(data)) return null;
1107
1144
  const artifact = data.artifact;
@@ -1159,16 +1196,32 @@ function downloadManifestFileFields(data) {
1159
1196
  //#endregion
1160
1197
  //#region src/api.ts
1161
1198
  let insecureLocalhostDispatcher;
1199
+ let undiciModule$1;
1200
+ async function loadUndici() {
1201
+ return undiciModule$1 ??= await import("undici");
1202
+ }
1162
1203
  function baseUrlOf(options) {
1163
1204
  return String(options.baseUrl ?? process.env.ARTIFACTSHARE_BASE_URL ?? "https://artifactshare.com").replace(/\/$/, "");
1164
1205
  }
1165
- async function requestConfig(options) {
1206
+ function requestConfig(options) {
1166
1207
  if (!insecureLocalhostEnabled(options)) return { init: {} };
1167
1208
  const baseUrl = baseUrlOf(options);
1168
1209
  const url = new URL(baseUrl);
1169
1210
  if (url.protocol !== "https:" || !isLocalHostname(url.hostname)) return { error: validationError("--insecure-localhost only works with local HTTPS base URLs.", "Use it only with https://localhost, https://127.0.0.1, or https://[::1].") };
1170
- const { Agent } = await import("undici");
1171
- return { init: { dispatcher: insecureLocalhostDispatcher ??= new Agent({ connect: { rejectUnauthorized: false } }) } };
1211
+ return { init: { insecureLocalhost: true } };
1212
+ }
1213
+ async function cliFetch(input, init = {}) {
1214
+ const { insecureLocalhost, ...fetchInit } = init;
1215
+ const { fetch, Agent } = await loadUndici();
1216
+ const requestInit = insecureLocalhost ? {
1217
+ ...fetchInit,
1218
+ dispatcher: insecureLocalhostDispatcher ??= new Agent({ connect: { rejectUnauthorized: false } })
1219
+ } : fetchInit;
1220
+ try {
1221
+ return await fetch(input, requestInit);
1222
+ } catch (error) {
1223
+ return { networkError: error };
1224
+ }
1172
1225
  }
1173
1226
  function insecureLocalhostEnabled(options) {
1174
1227
  return Boolean(options.insecureLocalhost) || process.env.ARTIFACTSHARE_INSECURE_LOCALHOST === "1";
@@ -1239,7 +1292,7 @@ async function apiRequest(path, options, init, errorOptions) {
1239
1292
  return { body };
1240
1293
  }
1241
1294
  async function apiRequestRaw(path, options, init) {
1242
- const response = await fetch(apiUrl(path, baseUrlOf(options)), init).catch((error) => ({ networkError: error }));
1295
+ const response = await cliFetch(apiUrl(path, baseUrlOf(options)), init);
1243
1296
  if ("networkError" in response) return { error: networkError(response.networkError) };
1244
1297
  return {
1245
1298
  response,
@@ -1395,15 +1448,7 @@ function resolveDestination(options, config) {
1395
1448
  if (options.home) return { containerId: null };
1396
1449
  const containerId = options.projectId ?? config?.default_project_id ?? null;
1397
1450
  if (containerId) return { containerId };
1398
- return { error: cliError({
1399
- code: "destination_required",
1400
- message: "A share destination is required.",
1401
- why: "Non-interactive share never guesses a project or home destination.",
1402
- hint: "Retry with --project-id <id>, configure .artifactshare/config.local.json, or pass --home.",
1403
- agentRecoverable: true,
1404
- requiresHuman: false,
1405
- recovery: { kind: "change_input" }
1406
- }) };
1451
+ return { containerId: null };
1407
1452
  }
1408
1453
  const PROJECT_CONFIG_PATH = ".artifactshare/config.json";
1409
1454
  const PROJECT_CONFIG_LOCAL_PATH = ".artifactshare/config.local.json";
@@ -1448,6 +1493,154 @@ async function resolveProjectConfig(cwd = process.cwd()) {
1448
1493
  directory: null
1449
1494
  };
1450
1495
  }
1496
+ async function resolveSharedProjectConfig(cwd = process.cwd()) {
1497
+ let current = resolve(cwd);
1498
+ const root = resolve(current, "/");
1499
+ while (true) {
1500
+ const path = join(current, PROJECT_CONFIG_PATH);
1501
+ try {
1502
+ const text = await readFile(path, "utf8");
1503
+ let parsed;
1504
+ try {
1505
+ parsed = JSON.parse(text);
1506
+ } catch {
1507
+ return invalidProjectConfigResolution(path, "Repository config contains invalid JSON.");
1508
+ }
1509
+ if (!isRecord(parsed)) return invalidProjectConfigResolution(path, "Repository config must contain a JSON object.");
1510
+ return {
1511
+ config: parsed,
1512
+ raw: parsed,
1513
+ kind: "shared",
1514
+ path: relativeProjectConfigPath(cwd, current, PROJECT_CONFIG_PATH),
1515
+ directory: current
1516
+ };
1517
+ } catch (error) {
1518
+ if (error.code !== "ENOENT") return invalidProjectConfigResolution(path, "Repository config could not be read.");
1519
+ }
1520
+ if (current === root) break;
1521
+ current = dirname(current);
1522
+ }
1523
+ return {
1524
+ config: null,
1525
+ raw: null,
1526
+ kind: null,
1527
+ path: null,
1528
+ directory: null
1529
+ };
1530
+ }
1531
+ function invalidProjectConfigResolution(path, message) {
1532
+ return {
1533
+ config: null,
1534
+ raw: null,
1535
+ kind: null,
1536
+ path,
1537
+ directory: dirname(path),
1538
+ error: validationError(message, `Fix or restore access to ${path} before resolving visibility settings.`)
1539
+ };
1540
+ }
1541
+ function resolveVisibility(explicitValue, repositoryValue, userValue) {
1542
+ const candidates = [
1543
+ {
1544
+ value: explicitValue,
1545
+ source: "explicit"
1546
+ },
1547
+ {
1548
+ value: repositoryValue,
1549
+ source: "repository"
1550
+ },
1551
+ {
1552
+ value: userValue,
1553
+ source: "user"
1554
+ }
1555
+ ];
1556
+ for (const candidate of candidates) {
1557
+ if (candidate.value === void 0) continue;
1558
+ if (candidate.value === "workspace" || candidate.value === "private") return {
1559
+ value: candidate.value,
1560
+ source: candidate.source
1561
+ };
1562
+ return { invalid: candidate.source };
1563
+ }
1564
+ return {
1565
+ value: "workspace",
1566
+ source: "product_default"
1567
+ };
1568
+ }
1569
+ function resolveHomeVisibility(explicitValue, repositoryHomeValue, repositoryLegacyValue, userHomeValue, userLegacyValue) {
1570
+ const candidates = [
1571
+ {
1572
+ value: explicitValue,
1573
+ source: "explicit"
1574
+ },
1575
+ {
1576
+ value: repositoryHomeValue,
1577
+ source: "repository"
1578
+ },
1579
+ {
1580
+ value: repositoryLegacyValue,
1581
+ source: "repository"
1582
+ },
1583
+ {
1584
+ value: userHomeValue,
1585
+ source: "user"
1586
+ },
1587
+ {
1588
+ value: userLegacyValue,
1589
+ source: "user"
1590
+ }
1591
+ ];
1592
+ for (const candidate of candidates) {
1593
+ if (candidate.value === void 0) continue;
1594
+ if (candidate.value === "workspace" || candidate.value === "private") return {
1595
+ value: candidate.value,
1596
+ source: candidate.source
1597
+ };
1598
+ return { invalid: candidate.source };
1599
+ }
1600
+ return {
1601
+ value: "workspace",
1602
+ source: "product_default"
1603
+ };
1604
+ }
1605
+ async function resolveDefaultVisibility(key, repositoryConfig) {
1606
+ const shared = repositoryConfig ?? await resolveSharedProjectConfig();
1607
+ if (shared.error) return { error: shared.error };
1608
+ const homeKey = key === "home_audience" || key === "default_artifact_visibility";
1609
+ const repositoryValue = homeKey ? shared.config?.home_audience : shared.config?.[key];
1610
+ const repositoryLegacyValue = homeKey ? shared.config?.default_artifact_visibility : void 0;
1611
+ if (homeKey && repositoryValue === void 0) {
1612
+ if (repositoryLegacyValue !== void 0) {
1613
+ const resolution = resolveHomeVisibility(void 0, void 0, repositoryLegacyValue, void 0, void 0);
1614
+ if (!("invalid" in resolution)) return resolution;
1615
+ return { error: validationError("Repository home_audience must be workspace or private.", "Fix the repository config before resolving visibility settings.") };
1616
+ }
1617
+ } else if (repositoryValue !== void 0) {
1618
+ const resolution = homeKey ? resolveHomeVisibility(void 0, repositoryValue, repositoryLegacyValue, void 0, void 0) : resolveVisibility(void 0, repositoryValue, void 0);
1619
+ if (!("invalid" in resolution)) return resolution;
1620
+ return { error: validationError(`Repository ${key} must be workspace or private.`, "Fix the repository config before resolving visibility settings.") };
1621
+ }
1622
+ const home = configHome();
1623
+ let global = null;
1624
+ if (home) {
1625
+ const path = join(home, "config.json");
1626
+ try {
1627
+ const text = await readFile(path, "utf8");
1628
+ let parsed;
1629
+ try {
1630
+ parsed = JSON.parse(text);
1631
+ } catch {
1632
+ return { error: validationError("User config contains invalid JSON.", `Fix ${path} before resolving visibility settings.`) };
1633
+ }
1634
+ if (!isRecord(parsed)) return { error: validationError("User config must contain a JSON object.", `Fix ${path} before resolving visibility settings.`) };
1635
+ global = parsed;
1636
+ } catch (error) {
1637
+ if (error.code !== "ENOENT") return { error: validationError("User config could not be read.", `Check access to ${path} before resolving visibility settings.`) };
1638
+ }
1639
+ } else global = await readGlobalConfig();
1640
+ const resolution = homeKey ? resolveHomeVisibility(void 0, void 0, void 0, global?.home_audience, global?.default_artifact_visibility) : resolveVisibility(void 0, void 0, global?.[key]);
1641
+ if (!("invalid" in resolution)) return resolution;
1642
+ return { error: validationError(`User ${homeKey ? "home_audience" : key} must be workspace or private.`, "Fix the user config before resolving visibility settings.") };
1643
+ }
1451
1644
  async function readProjectConfigAtDirectory(directory, kind) {
1452
1645
  return await readJsonFile(join(directory, kind === "local" ? PROJECT_CONFIG_LOCAL_PATH : PROJECT_CONFIG_PATH));
1453
1646
  }
@@ -2070,12 +2263,12 @@ async function runLogin(parsed, mode) {
2070
2263
  return writeSuccess(command, result.data, mode);
2071
2264
  }
2072
2265
  async function requestDeviceCode(options, init) {
2073
- const response = await fetch(apiUrl("/api/auth/device/code", baseUrlOf(options)), {
2266
+ const response = await cliFetch(apiUrl("/api/auth/device/code", baseUrlOf(options)), {
2074
2267
  method: "POST",
2075
2268
  headers: { "content-type": "application/json" },
2076
2269
  body: JSON.stringify({ client_id: DEVICE_CLIENT_ID }),
2077
2270
  ...init
2078
- }).catch((error) => ({ networkError: error }));
2271
+ });
2079
2272
  if ("networkError" in response) return { error: networkError(response.networkError) };
2080
2273
  const body = await readJson(response);
2081
2274
  if (!response.ok) return { error: mapApiError(response.status, body, { baseUrl: baseUrlOf(options) }) };
@@ -2083,7 +2276,7 @@ async function requestDeviceCode(options, init) {
2083
2276
  return body;
2084
2277
  }
2085
2278
  async function exchangeDeviceTokenOnce(options, deviceCode, init) {
2086
- const response = await fetch(apiUrl("/api/auth/device/token", baseUrlOf(options)), {
2279
+ const response = await cliFetch(apiUrl("/api/auth/device/token", baseUrlOf(options)), {
2087
2280
  method: "POST",
2088
2281
  headers: { "content-type": "application/json" },
2089
2282
  body: JSON.stringify({
@@ -2092,7 +2285,7 @@ async function exchangeDeviceTokenOnce(options, deviceCode, init) {
2092
2285
  client_id: DEVICE_CLIENT_ID
2093
2286
  }),
2094
2287
  ...init
2095
- }).catch((error) => ({ networkError: error }));
2288
+ });
2096
2289
  if ("networkError" in response) return { error: networkError(response.networkError) };
2097
2290
  const body = await readJson(response);
2098
2291
  if (response.ok && isDeviceTokenResponse(body)) return {
@@ -2125,7 +2318,7 @@ async function pollForToken(options, code, init, profile, deadline) {
2125
2318
  let networkFailures = 0;
2126
2319
  while (Date.now() < deadline) {
2127
2320
  await setTimeout$1(intervalMs);
2128
- const response = await fetch(apiUrl("/api/auth/device/token", baseUrlOf(options)), {
2321
+ const response = await cliFetch(apiUrl("/api/auth/device/token", baseUrlOf(options)), {
2129
2322
  method: "POST",
2130
2323
  headers: { "content-type": "application/json" },
2131
2324
  body: JSON.stringify({
@@ -2134,7 +2327,7 @@ async function pollForToken(options, code, init, profile, deadline) {
2134
2327
  client_id: DEVICE_CLIENT_ID
2135
2328
  }),
2136
2329
  ...init
2137
- }).catch((error) => ({ networkError: error }));
2330
+ });
2138
2331
  if ("networkError" in response) {
2139
2332
  networkFailures += 1;
2140
2333
  if (networkFailures >= 5) return { error: networkError(response.networkError) };
@@ -2473,10 +2666,10 @@ async function fetchArtifact(parsed, target, credential) {
2473
2666
  const url = apiUrl(`/api/cli/artifacts/${encodeURIComponent(target.artifactId)}`, baseUrlOf(parsed.options));
2474
2667
  if (target.offset !== void 0) url.searchParams.set("offset", target.offset);
2475
2668
  for (const item of target.include) url.searchParams.append("include", item);
2476
- const response = await fetch(url, {
2669
+ const response = await cliFetch(url, {
2477
2670
  headers: { Authorization: `Bearer ${credential.token}` },
2478
2671
  ...request.init
2479
- }).catch((error) => ({ networkError: error }));
2672
+ });
2480
2673
  if ("networkError" in response) return { error: networkError(response.networkError) };
2481
2674
  const body = await readJson(response);
2482
2675
  if (!response.ok) return { error: mapApiError(response.status, body, {
@@ -2508,10 +2701,10 @@ async function runArtifactsList(parsed, mode) {
2508
2701
  else if (projectId) url.searchParams.set("project_id", projectId);
2509
2702
  if (query) url.searchParams.set("query", query);
2510
2703
  const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
2511
- const response = await fetch(url, {
2704
+ const response = await cliFetch(url, {
2512
2705
  headers: { Authorization: `Bearer ${current.token}` },
2513
2706
  ...request.init
2514
- }).catch((error) => ({ networkError: error }));
2707
+ });
2515
2708
  if ("networkError" in response) return { error: networkError(response.networkError) };
2516
2709
  const body = await readJson(response);
2517
2710
  if (!response.ok) return { error: mapApiError(response.status, body, {
@@ -3303,10 +3496,10 @@ async function runDoctor(parsed, mode) {
3303
3496
  const request = await requestConfig(parsed.options);
3304
3497
  if (request.error) return writeFailure(command, request.error, mode, 1);
3305
3498
  const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
3306
- const response = await fetch(apiUrl("/api/cli/doctor", baseUrlOf(parsed.options)), {
3499
+ const response = await cliFetch(apiUrl("/api/cli/doctor", baseUrlOf(parsed.options)), {
3307
3500
  headers: { Authorization: `Bearer ${current.token}` },
3308
3501
  ...request.init
3309
- }).catch((error) => ({ networkError: error }));
3502
+ });
3310
3503
  if ("networkError" in response) return { data: {
3311
3504
  kind: "network_failed",
3312
3505
  hint: networkError(response.networkError).hint
@@ -3406,8 +3599,75 @@ function effectiveDiagnostics(project, globalConfig) {
3406
3599
  };
3407
3600
  }
3408
3601
  //#endregion
3602
+ //#region src/changelog.ts
3603
+ const CLI_UPDATES_URL = "https://artifactshare.com/updates?product=cli";
3604
+ const SECTION_HEADING = /^## (\S+) - (\d{4}-\d{2}-\d{2})$/;
3605
+ function extractChangelogSection(content, version) {
3606
+ const lines = content.split("\n");
3607
+ let bodyStart = -1;
3608
+ let date = "";
3609
+ for (let index = 0; index < lines.length; index += 1) {
3610
+ const match = lines[index]?.match(SECTION_HEADING);
3611
+ if (!match || match[1] !== version) continue;
3612
+ bodyStart = index + 1;
3613
+ date = match[2] ?? "";
3614
+ break;
3615
+ }
3616
+ if (bodyStart === -1) return null;
3617
+ const bodyLines = [];
3618
+ for (let index = bodyStart; index < lines.length; index += 1) {
3619
+ const line = lines[index] ?? "";
3620
+ if (line.startsWith("## ")) break;
3621
+ bodyLines.push(line);
3622
+ }
3623
+ return {
3624
+ version,
3625
+ date,
3626
+ body: bodyLines.join("\n").trim()
3627
+ };
3628
+ }
3629
+ async function readBundledChangelog() {
3630
+ try {
3631
+ return await readFile(new URL("../CHANGELOG.md", import.meta.url), "utf8");
3632
+ } catch {
3633
+ return null;
3634
+ }
3635
+ }
3636
+ function changelogDataFromContent(version, content) {
3637
+ return {
3638
+ version,
3639
+ updates_url: CLI_UPDATES_URL,
3640
+ latest: content ? extractChangelogSection(content, version) : null
3641
+ };
3642
+ }
3643
+ async function buildChangelogData(version) {
3644
+ return changelogDataFromContent(version, await readBundledChangelog());
3645
+ }
3646
+ //#endregion
3647
+ //#region src/version.ts
3648
+ async function loadCliVersion() {
3649
+ try {
3650
+ const content = await readFile(new URL("../package.json", import.meta.url), "utf8");
3651
+ const pkg = JSON.parse(content);
3652
+ return typeof pkg.version === "string" ? pkg.version : "0.0.0";
3653
+ } catch {
3654
+ return "0.0.0";
3655
+ }
3656
+ }
3657
+ //#endregion
3658
+ //#region src/command-runners/changelog.ts
3659
+ async function runChangelog(_parsed, mode) {
3660
+ return writeSuccess("changelog", await buildChangelogData(await loadCliVersion()), mode);
3661
+ }
3662
+ //#endregion
3409
3663
  //#region src/files.ts
3410
- async function prepareUploadPayload(targetPath, fileStat, initialForm = new FormData()) {
3664
+ let undiciModule;
3665
+ async function createUploadForm() {
3666
+ const { FormData } = undiciModule ??= await import("undici");
3667
+ return new FormData();
3668
+ }
3669
+ async function prepareUploadPayload(targetPath, fileStat, initialForm) {
3670
+ const form = initialForm ?? await createUploadForm();
3411
3671
  if (fileStat.isDirectory()) {
3412
3672
  let files;
3413
3673
  try {
@@ -3417,16 +3677,16 @@ async function prepareUploadPayload(targetPath, fileStat, initialForm = new Form
3417
3677
  throw error;
3418
3678
  }
3419
3679
  if (files.length === 0) return { error: validationError("Directory has no shareable files.", "Add index.html or index.md and retry.") };
3420
- for (const file of files) initialForm.append("file", await blobFor(file.path), file.relativePath);
3680
+ for (const file of files) form.append("file", await blobFor(file.path), file.relativePath);
3421
3681
  return { payload: {
3422
- form: initialForm,
3682
+ form,
3423
3683
  kind: "static_site"
3424
3684
  } };
3425
3685
  }
3426
3686
  if (fileStat.isFile()) {
3427
- initialForm.append("file", await blobFor(targetPath), basename(targetPath));
3687
+ form.append("file", await blobFor(targetPath), basename(targetPath));
3428
3688
  return { payload: {
3429
- form: initialForm,
3689
+ form,
3430
3690
  kind: artifactKindForFile(targetPath)
3431
3691
  } };
3432
3692
  }
@@ -3582,11 +3842,10 @@ async function runDownload(parsed, mode, isRetry = false) {
3582
3842
  const request = await requestConfig(parsed.options);
3583
3843
  if (request.error) return writeFailure(command, request.error, mode, 1);
3584
3844
  const baseUrl = baseUrlOf(parsed.options);
3585
- const manifestUrl = apiUrl(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/download`, baseUrl);
3586
- const manifestResponse = await fetch(manifestUrl, {
3845
+ const manifestResponse = await cliFetch(apiUrl(`/api/cli/artifacts/${encodeURIComponent(artifactId)}/download`, baseUrl), {
3587
3846
  headers: { Authorization: `Bearer ${credential.token}` },
3588
3847
  ...request.init
3589
- }).catch((error) => ({ networkError: error }));
3848
+ });
3590
3849
  if ("networkError" in manifestResponse) return writeFailure(command, networkError(manifestResponse.networkError), mode, 1);
3591
3850
  const body = await readJson(manifestResponse);
3592
3851
  if (!manifestResponse.ok) return handleAuthenticatedCredentialFailure(command, mapApiError(manifestResponse.status, body, {
@@ -3604,11 +3863,10 @@ async function runDownload(parsed, mode, isRetry = false) {
3604
3863
  let backupRoot = null;
3605
3864
  try {
3606
3865
  for (const file of plan.value.files) {
3607
- const fileUrl = downloadFileUrl(baseUrl, artifactId, file.path);
3608
- const fileResponse = await fetch(fileUrl, {
3866
+ const fileResponse = await cliFetch(downloadFileUrl(baseUrl, artifactId, file.path), {
3609
3867
  headers: { Authorization: `Bearer ${credential.token}` },
3610
3868
  ...request.init
3611
- }).catch((error) => ({ networkError: error }));
3869
+ });
3612
3870
  if ("networkError" in fileResponse) return writeFailure(command, networkError(fileResponse.networkError), mode, 1);
3613
3871
  if (!fileResponse.ok) return handleAuthenticatedCredentialFailure(command, mapApiError(fileResponse.status, await readJson(fileResponse), {
3614
3872
  authenticated: true,
@@ -4171,6 +4429,8 @@ async function runProjectsCreate(parsed, mode) {
4171
4429
  const visibility = parsed.options.visibility;
4172
4430
  if (visibility !== void 0 && visibility !== "workspace" && visibility !== "private") return writeFailure(command, validationError("--visibility must be workspace or private.", "Retry with --visibility workspace or --visibility private."), mode, 1);
4173
4431
  const projectConfig = await resolveProjectConfig();
4432
+ const defaultVisibility = visibility ? null : await resolveDefaultVisibility("default_project_visibility", await resolveSharedProjectConfig());
4433
+ if (defaultVisibility && "error" in defaultVisibility) return writeFailure(command, defaultVisibility.error, mode, 1);
4174
4434
  const credential = await resolveCredential(parsed.options, projectConfig);
4175
4435
  if (!credential.ok) return writeFailure(command, credential.error, mode, 1);
4176
4436
  const request = await requestConfig(parsed.options);
@@ -4179,7 +4439,7 @@ async function runProjectsCreate(parsed, mode) {
4179
4439
  const created = await apiPost("/api/cli/projects", current.token, {
4180
4440
  name,
4181
4441
  description: parsed.options.description ?? null,
4182
- base_visibility: visibility ?? null
4442
+ base_visibility: visibility ?? defaultVisibility.value
4183
4443
  }, parsed.options, request.init, {
4184
4444
  credentialSource: current.source,
4185
4445
  profile: current.profile,
@@ -4339,9 +4599,11 @@ async function runShare(parsed, mode, isRetry = false) {
4339
4599
  }
4340
4600
  const destination = resolveDestination(destinationOptions, project.config);
4341
4601
  if (destination.error) return writeFailure(command, destination.error, mode, 1);
4342
- const initialForm = new FormData();
4602
+ const initialForm = await createUploadForm();
4343
4603
  const grantEmails = arrayOption(parsed.options.grantEmail);
4344
- const requestedVisibility = parsed.options.visibility ?? (destination.containerId && grantEmails.length === 0 ? "project" : "private");
4604
+ const defaultVisibility = parsed.options.visibility || destination.containerId ? null : await resolveDefaultVisibility("home_audience", await resolveSharedProjectConfig());
4605
+ if (defaultVisibility && "error" in defaultVisibility) return writeFailure(command, defaultVisibility.error, mode, 1);
4606
+ const requestedVisibility = parsed.options.visibility ?? (destination.containerId ? "project" : defaultVisibility.value);
4345
4607
  initialForm.set("visibility", requestedVisibility);
4346
4608
  for (const email of grantEmails) initialForm.append("grant_email", email);
4347
4609
  if (destination.containerId) initialForm.set("container_id", destination.containerId);
@@ -4353,12 +4615,12 @@ async function runShare(parsed, mode, isRetry = false) {
4353
4615
  uploadUrl.searchParams.set("artifact_kind", "static_site");
4354
4616
  if (destination.containerId) uploadUrl.searchParams.set("container_id", destination.containerId);
4355
4617
  }
4356
- const response = await fetch(uploadUrl, {
4618
+ const response = await cliFetch(uploadUrl, {
4357
4619
  method: "POST",
4358
4620
  headers: { Authorization: `Bearer ${credential.token}` },
4359
4621
  body: upload.payload.form,
4360
4622
  ...request.init
4361
- }).catch((error) => ({ networkError: error }));
4623
+ });
4362
4624
  if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
4363
4625
  const body = await readJson(response);
4364
4626
  if (!response.ok) return handleAuthenticatedCredentialFailure(command, mapApiError(response.status, body, {
@@ -4448,10 +4710,10 @@ async function runResolve(parsed, mode) {
4448
4710
  const url = apiUrl("/api/cli/resolve", baseUrlOf(parsed.options));
4449
4711
  url.searchParams.set("q", value);
4450
4712
  const result = await runAuthenticatedApi(credential, parsed.options, async (current) => {
4451
- const response = await fetch(url, {
4713
+ const response = await cliFetch(url, {
4452
4714
  headers: { Authorization: `Bearer ${current.token}` },
4453
4715
  ...request.init
4454
- }).catch((error) => ({ networkError: error }));
4716
+ });
4455
4717
  if ("networkError" in response) return { error: networkError(response.networkError) };
4456
4718
  const body = await readJson(response);
4457
4719
  if (!response.ok) return { error: mapApiError(response.status, body, {
@@ -4491,12 +4753,12 @@ async function runUpdate(parsed, mode, isRetry = false) {
4491
4753
  if (upload.error) return writeFailure(command, upload.error, mode, 1);
4492
4754
  const updateUrl = apiUrl(`/api/shareables/${encodeURIComponent(artifactId)}/versions`, baseUrl);
4493
4755
  if (upload.payload.kind === "static_site") updateUrl.searchParams.set("artifact_kind", "static_site");
4494
- const response = await fetch(updateUrl, {
4756
+ const response = await cliFetch(updateUrl, {
4495
4757
  method: "POST",
4496
4758
  headers: { Authorization: `Bearer ${credential.token}` },
4497
4759
  body: upload.payload.form,
4498
4760
  ...request.init
4499
- }).catch((error) => ({ networkError: error }));
4761
+ });
4500
4762
  if ("networkError" in response) return writeFailure(command, networkError(response.networkError), mode, 1);
4501
4763
  const body = await readJson(response);
4502
4764
  if (!response.ok) return handleAuthenticatedCredentialFailure(command, mapApiError(response.status, body, {
@@ -4543,6 +4805,209 @@ async function runWhoami(parsed, mode) {
4543
4805
  } : { credential_source: credential.source }, mode);
4544
4806
  }
4545
4807
  //#endregion
4808
+ //#region src/command-runners/config.ts
4809
+ const KEYS = ["home_audience", "default_project_visibility"];
4810
+ const ACCEPTED_KEYS = [
4811
+ "home_audience",
4812
+ "default_artifact_visibility",
4813
+ "default_project_visibility"
4814
+ ];
4815
+ const SCOPES = ["user", "repository"];
4816
+ function keyOf(value) {
4817
+ if (value === "default_artifact_visibility") return value;
4818
+ return KEYS.includes(value) ? value : null;
4819
+ }
4820
+ function isHomeKey(key) {
4821
+ return key === "home_audience" || key === "default_artifact_visibility";
4822
+ }
4823
+ function logicalValue(config, key) {
4824
+ if (isHomeKey(key)) return Object.hasOwn(config, "home_audience") ? config.home_audience : config.default_artifact_visibility;
4825
+ return config[key];
4826
+ }
4827
+ function withConfigValue(config, key, value) {
4828
+ const next = { ...config };
4829
+ if (isHomeKey(key)) {
4830
+ delete next.default_artifact_visibility;
4831
+ if (value === null) delete next.home_audience;
4832
+ else next.home_audience = value;
4833
+ } else if (value === null) delete next[key];
4834
+ else next[key] = value;
4835
+ return next;
4836
+ }
4837
+ function scopeOf(value) {
4838
+ return SCOPES.includes(value) ? value : null;
4839
+ }
4840
+ function invalid(message, hint) {
4841
+ return validationError(message, hint, "validation_failed");
4842
+ }
4843
+ function invalidConfiguredValue(scope, key, value) {
4844
+ if (value === void 0 || value === "workspace" || value === "private") return null;
4845
+ return invalid(`${scope === "repository" ? "Repository" : "User"} ${isHomeKey(key) ? "home_audience" : key} must be workspace or private.`, `Fix the ${scope} config before using this setting.`);
4846
+ }
4847
+ function selectedKeys(positionals) {
4848
+ if (positionals.length === 0) return ["home_audience"];
4849
+ const key = keyOf(positionals[0]);
4850
+ return key && positionals.length === 1 ? [key] : null;
4851
+ }
4852
+ async function readUserConfig() {
4853
+ const home = configHome();
4854
+ if (!home) return { config: {} };
4855
+ const path = join(home, "config.json");
4856
+ try {
4857
+ const text = await readFile(path, "utf8");
4858
+ let parsed;
4859
+ try {
4860
+ parsed = JSON.parse(text);
4861
+ } catch {
4862
+ return { error: invalid("User config contains invalid JSON.", `Fix ${path} before reading user settings.`) };
4863
+ }
4864
+ if (!isRecord(parsed)) return { error: invalid("User config must contain a JSON object.", `Fix ${path} before reading user settings.`) };
4865
+ return { config: parsed };
4866
+ } catch (error) {
4867
+ if (error.code === "ENOENT") return { config: {} };
4868
+ return { error: invalid("User config could not be read.", `Check access to ${path} before reading user settings.`) };
4869
+ }
4870
+ }
4871
+ async function runConfigGet(parsed, mode) {
4872
+ const command = "config get";
4873
+ const keys = selectedKeys(parsed.positionals);
4874
+ if (!keys) return writeFailure(command, invalid("Unknown config key.", `Use one of: ${ACCEPTED_KEYS.join(", ")}.`), mode, 1);
4875
+ const scope = parsed.options.scope;
4876
+ if (scope !== void 0 && ![
4877
+ "user",
4878
+ "repository",
4879
+ "effective"
4880
+ ].includes(scope)) return writeFailure(command, invalid("Scope must be user, repository, or effective.", "Pass --scope user, --scope repository, or --scope effective."), mode, 1);
4881
+ const effective = scope === void 0 || scope === "effective";
4882
+ const shared = await resolveSharedProjectConfig();
4883
+ if (scope === "repository" && shared.error) return writeFailure(command, shared.error, mode, 1);
4884
+ const user = scope === "user" ? await readUserConfig() : { config: {} };
4885
+ if ("error" in user) return writeFailure(command, user.error, mode, 1);
4886
+ const data = {};
4887
+ for (const key of keys) if (effective) {
4888
+ const item = await resolveDefaultVisibility(key, shared);
4889
+ if ("error" in item) return writeFailure(command, item.error, mode, 1);
4890
+ data[key] = item;
4891
+ } else {
4892
+ const scoped = scope === "repository" ? "repository" : "user";
4893
+ const raw = scoped === "repository" ? logicalValue(shared.config ?? {}, key) : logicalValue(user.config, key);
4894
+ const valueError = invalidConfiguredValue(scoped, key, raw);
4895
+ if (valueError) return writeFailure(command, valueError, mode, 1);
4896
+ data[key] = {
4897
+ value: raw === "workspace" || raw === "private" ? raw : null,
4898
+ source: scoped
4899
+ };
4900
+ }
4901
+ return writeSuccess(command, data, mode);
4902
+ }
4903
+ async function writeRepository(key, value) {
4904
+ let directory = resolve(process.cwd());
4905
+ const root = resolve(directory, "/");
4906
+ let path = join(directory, PROJECT_CONFIG_PATH);
4907
+ let current = {};
4908
+ while (true) {
4909
+ path = join(directory, PROJECT_CONFIG_PATH);
4910
+ try {
4911
+ const text = await readFile(path, "utf8");
4912
+ let parsed;
4913
+ try {
4914
+ parsed = JSON.parse(text);
4915
+ } catch {
4916
+ return { error: invalid("Repository config contains invalid JSON.", `Fix ${path} before changing repository settings.`) };
4917
+ }
4918
+ if (!isRecord(parsed)) return { error: invalid("Repository config must contain a JSON object.", `Fix ${path} before changing repository settings.`) };
4919
+ current = parsed;
4920
+ break;
4921
+ } catch (error) {
4922
+ if (error.code !== "ENOENT") return { error: invalid("Repository config could not be read.", `Check access to ${path} before changing repository settings.`) };
4923
+ }
4924
+ if (directory === root) {
4925
+ directory = resolve(process.cwd());
4926
+ path = join(directory, PROJECT_CONFIG_PATH);
4927
+ break;
4928
+ }
4929
+ directory = dirname(directory);
4930
+ }
4931
+ const next = withConfigValue(current, key, value);
4932
+ try {
4933
+ await mkdir(dirname(path), { recursive: true });
4934
+ await writeFile(path, `${JSON.stringify(next, null, 2)}\n`);
4935
+ } catch {
4936
+ return { error: invalid("Repository config could not be written.", `Check access to ${path} before changing repository settings.`) };
4937
+ }
4938
+ return { path };
4939
+ }
4940
+ async function writeConfig(scope, key, value) {
4941
+ if (scope === "repository") return writeRepository(key, value);
4942
+ const home = configHome();
4943
+ if (!home) return { path: null };
4944
+ const path = join(home, "config.json");
4945
+ let current = {};
4946
+ try {
4947
+ const text = await readFile(path, "utf8");
4948
+ let parsed;
4949
+ try {
4950
+ parsed = JSON.parse(text);
4951
+ } catch {
4952
+ return { error: invalid("User config contains invalid JSON.", `Fix ${path} before changing user settings.`) };
4953
+ }
4954
+ if (!isRecord(parsed)) return { error: invalid("User config must contain a JSON object.", `Fix ${path} before changing user settings.`) };
4955
+ current = parsed;
4956
+ } catch (error) {
4957
+ if (error.code !== "ENOENT") return { error: invalid("User config could not be read.", `Check access to ${path} before changing user settings.`) };
4958
+ }
4959
+ const next = withConfigValue(current, key, value);
4960
+ try {
4961
+ if (!await writeGlobalConfig(next)) return { path: null };
4962
+ } catch {
4963
+ return { error: invalid("User config could not be written.", `Check access to ${path} before changing user settings.`) };
4964
+ }
4965
+ return { path };
4966
+ }
4967
+ async function runMutation(parsed, mode, unset) {
4968
+ const command = unset ? "config unset" : "config set";
4969
+ const key = keyOf(parsed.positionals[0]);
4970
+ const value = parsed.positionals[1];
4971
+ const scope = scopeOf(parsed.options.scope);
4972
+ if (!key) return writeFailure(command, invalid("Unknown config key.", `Use one of: ${ACCEPTED_KEYS.join(", ")}.`), mode, 1);
4973
+ if (!scope) return writeFailure(command, invalid("--scope is required and must be user or repository.", "Pass --scope user or --scope repository."), mode, 1);
4974
+ if (unset ? parsed.positionals.length !== 1 : parsed.positionals.length !== 2) return writeFailure(command, invalid(unset ? "A single config key is required." : "A config key and value are required.", `Use ${command} <key>${unset ? "" : " <workspace|private>"} --scope ${scope}.`), mode, 1);
4975
+ if (!unset && value !== "workspace" && value !== "private") return writeFailure(command, invalid("Config value must be workspace or private.", "Use workspace or private."), mode, 1);
4976
+ const shared = await resolveSharedProjectConfig();
4977
+ if (shared.error) return writeFailure(command, shared.error, mode, 1);
4978
+ const user = scope === "repository" && !unset ? { config: {} } : await readUserConfig();
4979
+ if ("error" in user) return writeFailure(command, user.error, mode, 1);
4980
+ if (scope !== "repository") {
4981
+ const repositoryValueError = invalidConfiguredValue("repository", key, logicalValue(shared.config ?? {}, key));
4982
+ if (repositoryValueError) return writeFailure(command, repositoryValueError, mode, 1);
4983
+ }
4984
+ if (scope === "repository" && unset) {
4985
+ const userValueError = invalidConfiguredValue("user", key, logicalValue(user.config, key));
4986
+ if (userValueError) return writeFailure(command, userValueError, mode, 1);
4987
+ }
4988
+ const writtenValue = unset ? null : value;
4989
+ const written = await writeConfig(scope, key, writtenValue);
4990
+ if ("error" in written) return writeFailure(command, written.error, mode, 1);
4991
+ if (!written.path) return writeFailure(command, invalid("The config store is unavailable.", "Set ARTIFACTSHARE_CONFIG_HOME to a writable directory."), mode, 1);
4992
+ const repositoryConfig = scope === "repository" ? withConfigValue(shared.config ?? {}, key, writtenValue) : shared.config ?? {};
4993
+ const userConfig = scope === "user" ? withConfigValue(user.config, key, writtenValue) : user.config;
4994
+ const repositoryValue = logicalValue(repositoryConfig, key);
4995
+ const userValue = logicalValue(userConfig, key);
4996
+ const item = isHomeKey(key) ? resolveHomeVisibility(void 0, repositoryConfig.home_audience, repositoryConfig.default_artifact_visibility, userConfig.home_audience, userConfig.default_artifact_visibility) : resolveVisibility(void 0, repositoryValue, userValue);
4997
+ if ("invalid" in item) return writeFailure(command, invalid("Config value must be workspace or private.", "Fix the config before using this setting."), mode, 1);
4998
+ return writeSuccess(command, {
4999
+ scope,
5000
+ path: written.path,
5001
+ [key]: item
5002
+ }, mode);
5003
+ }
5004
+ function runConfigSet(parsed, mode) {
5005
+ return runMutation(parsed, mode, false);
5006
+ }
5007
+ function runConfigUnset(parsed, mode) {
5008
+ return runMutation(parsed, mode, true);
5009
+ }
5010
+ //#endregion
4546
5011
  //#region src/commands.ts
4547
5012
  async function shareRunner(ctx) {
4548
5013
  const parsed = parsedArgsFromContext("share", ctx);
@@ -4629,6 +5094,18 @@ async function profilesListRunner(ctx) {
4629
5094
  const parsed = parsedArgsFromContext("profiles list", ctx);
4630
5095
  return await runWithSkillAutoUpdate(parsed, () => runProfilesList(parsed, outputMode(parsed.options)));
4631
5096
  }
5097
+ async function configGetRunner(ctx) {
5098
+ const parsed = parsedArgsFromContext("config get", ctx);
5099
+ return await runConfigGet(parsed, outputMode(parsed.options));
5100
+ }
5101
+ async function configSetRunner(ctx) {
5102
+ const parsed = parsedArgsFromContext("config set", ctx);
5103
+ return await runConfigSet(parsed, outputMode(parsed.options));
5104
+ }
5105
+ async function configUnsetRunner(ctx) {
5106
+ const parsed = parsedArgsFromContext("config unset", ctx);
5107
+ return await runConfigUnset(parsed, outputMode(parsed.options));
5108
+ }
4632
5109
  async function profilesUseRunner(ctx) {
4633
5110
  const parsed = parsedArgsFromContext("profiles use", ctx);
4634
5111
  return await runWithSkillAutoUpdate(parsed, () => runProfilesUse(parsed, outputMode(parsed.options)));
@@ -4682,6 +5159,10 @@ async function doctorRunner(ctx) {
4682
5159
  const parsed = parsedArgsFromContext("doctor", ctx);
4683
5160
  return await runDoctor(parsed, outputMode(parsed.options));
4684
5161
  }
5162
+ async function changelogRunner(ctx) {
5163
+ const parsed = parsedArgsFromContext("changelog", ctx);
5164
+ return await runChangelog(parsed, outputMode(parsed.options));
5165
+ }
4685
5166
  async function runWithSkillAutoUpdate(parsed, runner) {
4686
5167
  const mode = outputMode(parsed.options);
4687
5168
  if (!mode.json) {
@@ -4761,15 +5242,6 @@ async function main(rawArgv) {
4761
5242
  });
4762
5243
  if (usage) writeText(usage);
4763
5244
  }
4764
- async function loadCliVersion() {
4765
- try {
4766
- const content = await readFile(new URL("../package.json", import.meta.url), "utf8");
4767
- const pkg = JSON.parse(content);
4768
- return typeof pkg.version === "string" ? pkg.version : "0.0.0";
4769
- } catch {
4770
- return "0.0.0";
4771
- }
4772
- }
4773
5245
  async function runGunshi(argv) {
4774
5246
  return cli(argv, entryCommand, {
4775
5247
  name: "artifactshare",
@@ -4791,8 +5263,10 @@ async function runGunshi(argv) {
4791
5263
  "request-access": lazyCommand(requestAccessDefinition, requestAccessRunner),
4792
5264
  whoami: lazyCommand(whoamiDefinition, whoamiRunner),
4793
5265
  doctor: lazyCommand(doctorDefinition, doctorRunner),
5266
+ changelog: lazyCommand(changelogDefinition, changelogRunner),
4794
5267
  profiles: profilesDefinition,
4795
5268
  projects: projectsDefinition,
5269
+ config: configDefinition,
4796
5270
  skills: skillsDefinition,
4797
5271
  init: lazyCommand(initDefinition, initRunner)
4798
5272
  },
@@ -4861,6 +5335,7 @@ npx --yes @artifactshare/cli logout --profile default --json
4861
5335
  npx --yes @artifactshare/cli profiles list --json
4862
5336
  npx --yes @artifactshare/cli profiles use <name> --json
4863
5337
  npx --yes @artifactshare/cli projects list --json
5338
+ npx --yes @artifactshare/cli config get home_audience --json
4864
5339
  npx --yes @artifactshare/cli skills install --tool codex --json
4865
5340
  npx --yes @artifactshare/cli skills list --json
4866
5341
  npx --yes @artifactshare/cli init --profile <name> --project-id <id> --json
@@ -4875,7 +5350,6 @@ Authentication:
4875
5350
 
4876
5351
  Common failures:
4877
5352
  auth_required Use ${TOKEN_ENV_VAR} or ${TOKEN_OPTION}; tokens are issued at ${DEFAULT_BASE_URL}/settings/tokens
4878
- destination_required Add --project-id, configure .artifactshare/config.json, or pass --home
4879
5353
  invalid_destination Choose --project-id <id> or --home
4880
5354
  target_not_found Use an artifact ID, share URL, or sandbox URL
4881
5355
  upload_not_allowed Upload access is limited; run request-access to join the waitlist`,
@@ -4941,7 +5415,7 @@ const shareDefinition = define({
4941
5415
  visibility: {
4942
5416
  type: "string",
4943
5417
  toKebab: true,
4944
- description: "private, workspace, or project (default: project for a project destination, private otherwise or with --grant-email)"
5418
+ description: "private, workspace, or project (default: project for a project destination, otherwise resolved from config)"
4945
5419
  },
4946
5420
  grantEmail: {
4947
5421
  type: "string",
@@ -4958,6 +5432,13 @@ const shareDefinition = define({
4958
5432
  examples: `npx --yes @artifactshare/cli share report.html --project-id <id> --json
4959
5433
  npx --yes @artifactshare/cli share report.html --project-id <id> --key nightly-report --json
4960
5434
 
5435
+ Posting to a project delivers to the audience defined by that project.
5436
+ With no destination, share posts to home. The repository home_audience selects
5437
+ private (only you) or workspace (everyone in the workspace/company):
5438
+ npx --yes @artifactshare/cli config get home_audience --json
5439
+ npx --yes @artifactshare/cli config set home_audience private --scope repository --json
5440
+ Use --visibility as a per-post override of the destination default.
5441
+
4961
5442
  To keep an existing share URL, use update:
4962
5443
  npx --yes @artifactshare/cli update <artifact-id-or-url> <path> --json
4963
5444
 
@@ -4965,7 +5446,6 @@ For repeat jobs, use --key: first share creates the artifact, later runs add ver
4965
5446
 
4966
5447
  Common failures:
4967
5448
  auth_required Set ARTIFACTSHARE_TOKEN before share
4968
- destination_required Non-interactive share needs --project-id, config default, or --home
4969
5449
  upload_not_allowed Your account cannot share yet; request access from an operator
4970
5450
  file_too_large Reduce file or directory size and retry
4971
5451
  validation_failed Check file type (.html / .md for single files) and directory layout
@@ -5535,6 +6015,85 @@ Common failures:
5535
6015
  profile_not_found Run profiles list to see saved profiles
5536
6016
  token_store_unavailable Credential removal failed; the profile entry is kept`
5537
6017
  });
6018
+ const configGetDefinition = define({
6019
+ name: "get",
6020
+ description: "Read where home posts are delivered and other visibility settings.",
6021
+ toKebab: true,
6022
+ args: {
6023
+ ...commonArgs,
6024
+ key: {
6025
+ type: "positional",
6026
+ required: false,
6027
+ description: "home_audience (default; keyless JSON returns only this key), default_artifact_visibility (compatibility alias), or default_project_visibility"
6028
+ },
6029
+ scope: {
6030
+ type: "string",
6031
+ toKebab: true,
6032
+ description: "user, repository, or effective"
6033
+ }
6034
+ }
6035
+ });
6036
+ const configSetDefinition = define({
6037
+ name: "set",
6038
+ description: "Set home audience or a default visibility setting.",
6039
+ toKebab: true,
6040
+ args: {
6041
+ ...commonArgs,
6042
+ key: {
6043
+ type: "positional",
6044
+ description: "Configuration key"
6045
+ },
6046
+ value: {
6047
+ type: "positional",
6048
+ description: "workspace or private"
6049
+ },
6050
+ scope: {
6051
+ type: "string",
6052
+ toKebab: true,
6053
+ description: "user or repository"
6054
+ }
6055
+ }
6056
+ });
6057
+ const configUnsetDefinition = define({
6058
+ name: "unset",
6059
+ description: "Remove a home audience or default visibility setting.",
6060
+ toKebab: true,
6061
+ args: {
6062
+ ...commonArgs,
6063
+ key: {
6064
+ type: "positional",
6065
+ description: "Configuration key"
6066
+ },
6067
+ scope: {
6068
+ type: "string",
6069
+ toKebab: true,
6070
+ description: "user or repository"
6071
+ }
6072
+ }
6073
+ });
6074
+ const configDefinition = define({
6075
+ name: "config",
6076
+ description: "Manage where home posts are delivered and project defaults.",
6077
+ toKebab: true,
6078
+ args: commonArgs,
6079
+ subCommands: {
6080
+ get: lazyCommand(configGetDefinition, configGetRunner),
6081
+ set: lazyCommand(configSetDefinition, configSetRunner),
6082
+ unset: lazyCommand(configUnsetDefinition, configUnsetRunner)
6083
+ },
6084
+ examples: `Posting to a project delivers to that project's audience. Without a destination, share posts to home.
6085
+ Set the repository home audience to private (only you) or workspace (everyone in the workspace/company):
6086
+ npx --yes @artifactshare/cli config get home_audience --json
6087
+ npx --yes @artifactshare/cli config set home_audience private --scope repository --json
6088
+
6089
+ Keys:
6090
+ home_audience Canonical home-post audience.
6091
+ default_artifact_visibility Compatibility alias for home_audience.
6092
+ default_project_visibility Advanced default for projects create.
6093
+
6094
+ Scopes: user stores in the global config; repository stores in the shared .artifactshare/config.json; effective reads the resolved value. Home audience resolution is repository home_audience, repository alias, user home_audience, user alias, then product default workspace. Project defaults resolve repository, user, then workspace. Keyless config get --json returns only home_audience; pass an explicit key to read default_project_visibility or the compatibility alias. Explicit --visibility overrides the destination default for one post.`,
6095
+ run: parentCommandRunner("config")
6096
+ });
5538
6097
  const profilesDefinition = define({
5539
6098
  name: "profiles",
5540
6099
  description: "Manage saved CLI profiles.",
@@ -5580,12 +6139,16 @@ const projectsCreateDefinition = define({
5580
6139
  visibility: {
5581
6140
  type: "string",
5582
6141
  toKebab: true,
5583
- description: "workspace or private (default: workspace)"
6142
+ description: "workspace or private (default: default_project_visibility, resolved from repository, user, then workspace)"
5584
6143
  }
5585
6144
  },
5586
6145
  examples: `npx --yes @artifactshare/cli projects create "Launch review" --json
5587
6146
  npx --yes @artifactshare/cli projects create "Client" --description "Weekly reports" --visibility private --json
5588
6147
 
6148
+ Persist the default for project creation in the repository:
6149
+ npx --yes @artifactshare/cli config get default_project_visibility --json
6150
+ npx --yes @artifactshare/cli config set default_project_visibility private --scope repository --json
6151
+
5589
6152
  The response includes project.id and next_command for share --project-id.
5590
6153
 
5591
6154
  Common failures:
@@ -5863,6 +6426,12 @@ const doctorDefinition = define({
5863
6426
  toKebab: true,
5864
6427
  args: commonArgs
5865
6428
  });
6429
+ const changelogDefinition = define({
6430
+ name: "changelog",
6431
+ description: "Show the installed CLI version, recent changes, and the public updates page.",
6432
+ toKebab: true,
6433
+ args: { json: commonArgs.json }
6434
+ });
5866
6435
  const cliArgv = process.argv.slice(2);
5867
6436
  main(cliArgv).catch((error) => {
5868
6437
  writeFailure("unknown", unexpectedError(error), outputModeFromArgv(cliArgv), 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artifactshare/cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.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",
@@ -25,6 +25,7 @@
25
25
  "dist",
26
26
  "skills",
27
27
  "README.md",
28
+ "CHANGELOG.md",
28
29
  "LICENSE"
29
30
  ],
30
31
  "publishConfig": {
@@ -4,7 +4,7 @@ description: Share, publish, upload, host, update, open, or read back existing f
4
4
  ---
5
5
 
6
6
  <!-- artifactshare-skill
7
- version: 24
7
+ version: 26
8
8
  managed: true
9
9
  -->
10
10
 
@@ -92,14 +92,43 @@ npx --yes @artifactshare/cli share ./site-dir --project-id <id> --json
92
92
  successful run creates a new artifact.
93
93
  - Pick the destination with `--project-id <id>`, `--project <name>` (by exact
94
94
  name, no prior `resolve` needed), the saved default from `init`, or `--home`.
95
- Without any of these it fails with `destination_required`.
95
+ Posting to a project delivers to the audience defined by that project.
96
+ Without any destination it posts to home.
97
+ - The repository `home_audience` selects `private` (only you) or `workspace`
98
+ (everyone in the workspace/company). Check or set it with:
99
+ `config get home_audience --json` and
100
+ `config set home_audience private --scope repository --json`.
96
101
  - Set visibility at share time with `--visibility private|workspace|project`.
97
- When `--grant-email` is passed, the default becomes `private`.
102
+ This is a per-post override; `--grant-email` does not change the resolved
103
+ default visibility.
98
104
  - For repeat jobs with a stable caller-owned name, use
99
105
  `share <path> --key <key> --json`: the first run creates the artifact, later
100
106
  runs add versions to the same artifact.
101
107
  - Run `share --help` for all flags.
102
108
 
109
+ ## Audience and visibility settings
110
+
111
+ Posting to a project delivers to the audience defined by that project. Without
112
+ a destination, `share` posts to home, whose repository `home_audience` is
113
+ `private` (only you) or `workspace` (everyone in the workspace/company). Check
114
+ or set it with `config get home_audience --json` and
115
+ `config set home_audience private --scope repository --json`.
116
+
117
+ Use `--visibility private|workspace|project` as a per-post override. For new
118
+ projects, pass `projects create --visibility private|workspace`; persistent
119
+ project defaults are documented in `projects create --help`.
120
+
121
+ The complete `config --help` reference covers user and repository scopes,
122
+ effective resolution, and the canonical `home_audience` key. The old
123
+ `default_artifact_visibility` remains a compatibility alias, while
124
+ `default_project_visibility` is the advanced `projects create` default. Home
125
+ resolution checks repository then user settings (including the alias at each
126
+ scope), then product default `workspace`; project defaults use repository,
127
+ user, then `workspace`. Keyless `config get --json` returns only
128
+ `home_audience`; pass an explicit key for either other setting. These settings
129
+ only affect new home posts and project creation; update, edit, Web, and MCP
130
+ defaults are unchanged.
131
+
103
132
  ## Update
104
133
 
105
134
  Use `update` to add a new version to an existing artifact while keeping its URL.
@@ -199,8 +228,8 @@ npx --yes @artifactshare/cli projects edit <id> --add-email viewer@example.com -
199
228
  npx --yes @artifactshare/cli projects edit <id> --archive --json
200
229
  ```
201
230
 
202
- - `projects create` defaults to `--visibility workspace`. Pass
203
- `--visibility private` for confidential projects.
231
+ - `projects create` uses `default_project_visibility` when saved, otherwise
232
+ `workspace`. Pass `--visibility private` for a confidential project.
204
233
  - `projects edit` changes name, description, visibility, audience
205
234
  (`--add-email` / `--remove-email`), and archive state (`--archive` /
206
235
  `--unarchive`).
@@ -4,7 +4,7 @@ alwaysApply: false
4
4
  ---
5
5
 
6
6
  <!-- artifactshare-skill
7
- version: 24
7
+ version: 26
8
8
  managed: true
9
9
  -->
10
10
 
@@ -43,7 +43,8 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
43
43
  - Remove a saved local credential with `logout --profile <name> --json`; this keeps profile metadata and does not revoke API tokens on the server.
44
44
  - Switch profiles with `profiles use <name> --json`; list with `profiles list --json`; remove a profile entry and its credential with `profiles delete <name> --json`.
45
45
  - When the user gives an Artifact Share URL, start with `open <artifact-id-or-url> --json`. It ensures this rule is installed or updated, then reads single-file artifacts or returns a `download` next command for static sites and multi-file artifacts.
46
- - Share with `share <path> --json`. In JSON output, give the user `data.artifact.url`; the artifact ID is `data.artifact.id`. Do not rerun `share` just to inspect the JSON shape: without `--key`, each successful run creates a new artifact. Pick the destination with `--project-id <id>`, `--project <name>` (by exact name), the saved default, or `--home`. Set visibility with `--visibility private|workspace|project`; when `--grant-email` is passed the default becomes `private`.
46
+ - Share with `share <path> --json`. In JSON output, give the user `data.artifact.url`; the artifact ID is `data.artifact.id`. Do not rerun `share` just to inspect the JSON shape: without `--key`, each successful run creates a new artifact. Posting to a project delivers to the audience defined by that project. Pick it with `--project-id <id>` or `--project <name>` (by exact name), or use the saved default. With no destination, share posts to home. The repository `home_audience` selects `private` (only you) or `workspace` (everyone in the workspace/company): inspect with `config get home_audience --json` and set with `config set home_audience private --scope repository --json`. Use `--visibility private|workspace|project` as a per-post override; `--grant-email` does not change the resolved default.
47
+ - For new projects, pass `projects create <name> --visibility private|workspace`; persistent project defaults are documented in `projects create --help`. The complete `config --help` reference covers the canonical `home_audience`, user/repository/effective scopes, and resolution. `default_artifact_visibility` is a compatibility alias; `default_project_visibility` is the advanced project-creation default. Home resolution checks repository then user settings, including the alias at each scope, then product default `workspace`. Keyless `config get --json` returns only `home_audience`; pass an explicit key for either other setting. These settings do not change update, edit, Web, or MCP defaults.
47
48
  - 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.
48
49
  - 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.
49
50
  - 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`.
@@ -53,7 +54,7 @@ contain `$`, spaces, `*`, or `?`; use single quotes such as
53
54
  - 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.
54
55
  - 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`.
55
56
  - Permanently remove an artifact only when the user explicitly asks with `delete <artifact-id-or-url> --json`.
56
- - Manage projects: `projects list --json`, `projects create <name> --json` (defaults to `--visibility workspace`; pass `--visibility private` for confidential projects), `projects edit <id>` for name, description, visibility, audience (`--add-email`/`--remove-email`), and archive state (`--archive`/`--unarchive`).
57
+ - Manage projects: `projects list --json`, `projects create <name> --json` (uses `default_project_visibility` when saved, otherwise `workspace`; pass `--visibility private` for a confidential project), `projects edit <id>` for name, description, visibility, audience (`--add-email`/`--remove-email`), and archive state (`--archive`/`--unarchive`).
57
58
  - Save a default project with `init --project-id <id> --json`. Preview setup with `init --dry-run --json`.
58
59
  - Manage skills: `skills ensure --tool auto --json` detects Claude Code, Codex, or Cursor and installs or updates user-scope skills; Cursor project scope needs `skills install --tool cursor --scope project --json`. Use `skills install --tool cursor --scope user --json` for the Cursor user-scope skill explicitly. Project scope is opt-in via `skills install --tool <tool> --scope project --json`. `skills update --json` updates installed managed skills; `--force` overwrites unmanaged files on install.
59
60
  - Check the current state with `whoami --json` or `doctor --json` for authentication, destination, network, upload access, and skill update status.