usecloudy 0.3.1 → 0.3.3

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.
Files changed (3) hide show
  1. package/README.md +4 -4
  2. package/dist/index.js +351 -266
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Cloudy CLI
2
2
 
3
- The command line for [Cloudy](https://cloudtifact.com): publish pages and docs folders as links
3
+ The command line for [Cloudy](https://usecloudy.ai): publish pages and docs folders as links
4
4
  people comment on, keep every version, and give the comments back to your coding agent.
5
5
 
6
6
  ```sh
@@ -17,7 +17,7 @@ Or run it once without installing: `npx usecloudy publish page.html`.
17
17
  Without npm, use the install script:
18
18
 
19
19
  ```sh
20
- curl -fsSL https://api.cloudtifact.com/install.sh | sh
20
+ curl -fsSL https://usecloudy.ai/install.sh | sh
21
21
  ```
22
22
 
23
23
  The script puts the CLI in `~/.cloudtifact` (commands `cloudy` and `cloudtifact`) and adds `~/.cloudtifact/bin` to your PATH. Open a new terminal afterwards.
@@ -25,7 +25,7 @@ The script puts the CLI in `~/.cloudtifact` (commands `cloudy` and `cloudtifact`
25
25
  ```sh
26
26
  cloudy login
27
27
  cloudy publish page.html # one page or folder → a link
28
- cloudy copy https://cloudtifact.app/<id>/ # your own copy of a page someone sent
28
+ cloudy copy https://cloudy.page/<id>/ # your own copy of a page someone sent
29
29
  cloudy context pull --space <id> # Discord thread linked to the space
30
30
  cloudy init && cloudy push # a repo's docs folder, versioned
31
31
  cloudy comments --toon # what reviewers said, compact for agents
@@ -93,6 +93,6 @@ The tokens from `login` are stored in `~/.config/cloudtifact/config.json` (or `$
93
93
 
94
94
  ## Docs
95
95
 
96
- Every command and option: the [CLI reference](https://cloudtifact.com/docs/reference/cli).
96
+ Every command and option: the [CLI reference](https://usecloudy.ai/docs/reference/cli).
97
97
 
98
98
  MIT licensed.
package/dist/index.js CHANGED
@@ -12,15 +12,253 @@ import { createHash } from "node:crypto";
12
12
  import { createInterface } from "node:readline/promises";
13
13
  import { Readable, Transform } from "node:stream";
14
14
  import { pipeline } from "node:stream/promises";
15
+ //#region src/config.ts
16
+ /**
17
+ * Pinned, never derived from the site domain: saved sign-ins and each folder's space are keyed by this address, so a
18
+ * new default would sign everyone out and make publish create a new space each time (docs/domain-move.md).
19
+ */
20
+ const DEFAULT_API_URL = "https://api.cloudtifact.com";
21
+ const REPO_CONFIG_FILE = ".cloudtifact.json";
22
+ function homeDir(env = process.env) {
23
+ return env.CLOUDTIFACT_HOME || os.homedir();
24
+ }
25
+ function globalConfigDir(env = process.env) {
26
+ if (env.CLOUDTIFACT_CONFIG_DIR) return env.CLOUDTIFACT_CONFIG_DIR;
27
+ const xdg = env.XDG_CONFIG_HOME || path.join(homeDir(env), ".config");
28
+ return path.join(xdg, "cloudtifact");
29
+ }
30
+ function globalConfigPath(env = process.env) {
31
+ return path.join(globalConfigDir(env), "config.json");
32
+ }
33
+ async function readGlobalConfig(env = process.env) {
34
+ const file = globalConfigPath(env);
35
+ if (!existsSync(file)) return {};
36
+ try {
37
+ const data = JSON.parse(await readFile(file, "utf8"));
38
+ return data && typeof data === "object" ? data : {};
39
+ } catch {
40
+ throw new Error(`Could not parse ${file}. Fix or delete it, then run \`cloudy login\`.`);
41
+ }
42
+ }
43
+ async function writeGlobalConfig(config, env = process.env) {
44
+ const dir = globalConfigDir(env);
45
+ await mkdir(dir, {
46
+ recursive: true,
47
+ mode: 448
48
+ });
49
+ const file = globalConfigPath(env);
50
+ await writeFile(file, `${JSON.stringify(config, null, 2)}\n`, { mode: 384 });
51
+ await chmod(file, 384);
52
+ }
53
+ async function clearGlobalConfig(env = process.env) {
54
+ await rm(globalConfigPath(env), { force: true });
55
+ }
56
+ /** env CLOUDTIFACT_API_URL > config file > default. */
57
+ function resolveApiUrl(config, env = process.env) {
58
+ return (env.CLOUDTIFACT_API_URL || config.apiUrl || "https://api.cloudtifact.com").replace(/\/+$/, "");
59
+ }
60
+ /** The API the saved token was issued by: the apiUrl saved with it (`login` always saves both), else the default. */
61
+ function tokenApiUrl(config) {
62
+ return (config.apiUrl || "https://api.cloudtifact.com").replace(/\/+$/, "");
63
+ }
64
+ /**
65
+ * The saved token, but only for the API it came from. CLOUDTIFACT_API_URL can point the CLI at another API; the
66
+ * token is never sent there (that API could keep it and use it against ours). For another API you're signed out.
67
+ */
68
+ function savedTokenFor(config, apiUrl) {
69
+ return config.token && sameApi(tokenApiUrl(config), apiUrl) ? config.token : void 0;
70
+ }
71
+ function sameApi(a, b) {
72
+ const norm = (u) => {
73
+ try {
74
+ return new URL(u).href.replace(/\/+$/, "");
75
+ } catch {
76
+ return u.replace(/\/+$/, "");
77
+ }
78
+ };
79
+ return norm(a) === norm(b);
80
+ }
81
+ const sameAccount = (a, b) => a.handle === b.handle && sameApi(a.apiUrl, b.apiUrl);
82
+ /** The active account (the top-level fields), if signed in. Very old configs saved a token without a handle: "". */
83
+ function activeAccount(config) {
84
+ if (!config.token) return void 0;
85
+ const { token, handle = "", workspace } = config;
86
+ return {
87
+ apiUrl: tokenApiUrl(config),
88
+ token,
89
+ handle,
90
+ ...workspace ? { workspace } : {}
91
+ };
92
+ }
93
+ /** Every signed-in account, the active one first. Configs from before `accounts` hold just the active one. */
94
+ function accountsOf(config) {
95
+ const active = activeAccount(config);
96
+ const others = (config.accounts ?? []).filter((a) => !active || !sameAccount(a, active));
97
+ return active ? [active, ...others] : others;
98
+ }
99
+ /** Adds or updates an account and makes it the active one. */
100
+ function withActiveAccount(config, account) {
101
+ const { apiUrl, token, handle, workspace } = account;
102
+ const others = accountsOf(config).filter((a) => !sameAccount(a, account));
103
+ const { workspace: _w, ...rest } = config;
104
+ return {
105
+ ...rest,
106
+ apiUrl,
107
+ token,
108
+ handle,
109
+ ...workspace ? { workspace } : {},
110
+ accounts: [account, ...others]
111
+ };
112
+ }
113
+ /** Updates an account in place (its default workspace, say), active or not. */
114
+ function withAccountUpdated(config, account) {
115
+ const active = activeAccount(config);
116
+ if (active && sameAccount(active, account)) return withActiveAccount(config, account);
117
+ return {
118
+ ...config,
119
+ accounts: accountsOf(config).map((a) => sameAccount(a, account) ? account : a)
120
+ };
121
+ }
122
+ /** Forgets an account. If it was the active one, the next signed-in account becomes active. */
123
+ function withoutAccount(config, account) {
124
+ const left = accountsOf(config).filter((a) => !sameAccount(a, account));
125
+ const directories = Object.fromEntries(Object.entries(config.directories ?? {}).filter(([, h]) => h !== account.handle || left.some((a) => a.handle === h)));
126
+ const { apiUrl: _a, token: _t, handle: _h, workspace: _w, accounts: _l, directories: _d, ...rest } = config;
127
+ const base = {
128
+ ...rest,
129
+ ...Object.keys(directories).length ? { directories } : {}
130
+ };
131
+ const [next] = left;
132
+ return next ? withActiveAccount({
133
+ ...base,
134
+ accounts: left
135
+ }, next) : base;
136
+ }
137
+ /** The account a folder is bound to (`cloudy switch <handle> --here`): the nearest bound folder above `from`. */
138
+ function boundHandle(config, from = process.cwd()) {
139
+ const dirs = config.directories ?? {};
140
+ let dir = path.resolve(from);
141
+ for (;;) {
142
+ const handle = dirs[dir];
143
+ if (handle) return {
144
+ handle,
145
+ dir
146
+ };
147
+ const parent = path.dirname(dir);
148
+ if (parent === dir) return null;
149
+ dir = parent;
150
+ }
151
+ }
152
+ /** The folder `switch --here` binds: the repo root (or git root) above `from`, else `from`. */
153
+ function bindingRoot(from = process.cwd()) {
154
+ return findInitRoot(from);
155
+ }
156
+ /** Walks up from `from` to the nearest directory holding .cloudtifact.json. */
157
+ function findRepoRoot(from = process.cwd()) {
158
+ let dir = path.resolve(from);
159
+ for (;;) {
160
+ if (existsSync(path.join(dir, ".cloudtifact.json"))) return dir;
161
+ const parent = path.dirname(dir);
162
+ if (parent === dir) return null;
163
+ dir = parent;
164
+ }
165
+ }
166
+ /** Where `init` should write: the git root above `from`, else `from`. */
167
+ function findInitRoot(from = process.cwd()) {
168
+ let dir = path.resolve(from);
169
+ for (;;) {
170
+ if (existsSync(path.join(dir, ".git")) || existsSync(path.join(dir, ".cloudtifact.json"))) return dir;
171
+ const parent = path.dirname(dir);
172
+ if (parent === dir) return path.resolve(from);
173
+ dir = parent;
174
+ }
175
+ }
176
+ /**
177
+ * The project work belongs to, recorded on each version: CLOUDTIFACT_PROJECT, else the name of the git repo above
178
+ * `from` (a worktree counts as its main repo), else null.
179
+ */
180
+ function projectName(from = process.cwd(), env = process.env) {
181
+ const named = env.CLOUDTIFACT_PROJECT?.trim();
182
+ if (named) return named.slice(0, 100);
183
+ let dir = path.resolve(from);
184
+ for (;;) {
185
+ const git = path.join(dir, ".git");
186
+ if (existsSync(git)) {
187
+ try {
188
+ const m = /^gitdir:\s*(.+)$/m.exec(readFileSync(git, "utf8"));
189
+ const main = m?.[1] ? /^(.*)[\\/]\.git[\\/]worktrees[\\/]/.exec(m[1].trim()) : null;
190
+ if (main?.[1]) return path.basename(main[1]);
191
+ } catch {}
192
+ return path.basename(dir);
193
+ }
194
+ const parent = path.dirname(dir);
195
+ if (parent === dir) return null;
196
+ dir = parent;
197
+ }
198
+ }
199
+ function parseRepoConfig(raw, file = REPO_CONFIG_FILE) {
200
+ const bad = (why) => /* @__PURE__ */ new Error(`${file}: ${why}`);
201
+ if (!raw || typeof raw !== "object") throw bad("expected a JSON object");
202
+ const { dir, targets } = raw;
203
+ if (typeof dir !== "string" || !dir) throw bad("\"dir\" must be a non-empty string");
204
+ if (!Array.isArray(targets)) throw bad("\"targets\" must be an array");
205
+ return {
206
+ dir,
207
+ targets: targets.map((t, i) => {
208
+ if (!t || typeof t !== "object" || typeof t.spaceId !== "string") throw bad(`targets[${i}].spaceId must be a string`);
209
+ const { spaceId, label } = t;
210
+ return label ? {
211
+ spaceId,
212
+ label
213
+ } : { spaceId };
214
+ })
215
+ };
216
+ }
217
+ async function readRepoConfig(root) {
218
+ const file = path.join(root, REPO_CONFIG_FILE);
219
+ let raw;
220
+ try {
221
+ raw = JSON.parse(await readFile(file, "utf8"));
222
+ } catch (err) {
223
+ throw new Error(`Could not read ${file}: ${err.message}`);
224
+ }
225
+ return parseRepoConfig(raw, file);
226
+ }
227
+ async function writeRepoConfig(root, config) {
228
+ await writeFile(path.join(root, REPO_CONFIG_FILE), `${JSON.stringify(config, null, 2)}\n`);
229
+ }
230
+ const realOrSelf = (p) => {
231
+ try {
232
+ return realpathSync(p);
233
+ } catch {
234
+ return p;
235
+ }
236
+ };
237
+ async function loadRepo(from = process.cwd()) {
238
+ const root = findRepoRoot(from);
239
+ if (!root) throw new Error(`No ${REPO_CONFIG_FILE} found here or above. Run \`cloudy init\` first.`);
240
+ const config = await readRepoConfig(root);
241
+ const docsDir = path.resolve(root, config.dir);
242
+ const rel = path.relative(realOrSelf(root), realOrSelf(docsDir));
243
+ if (rel.startsWith("..") || path.isAbsolute(rel)) throw new Error(`"dir" in ${REPO_CONFIG_FILE} must be inside the repo (got "${config.dir}")`);
244
+ return {
245
+ root,
246
+ config,
247
+ docsDir
248
+ };
249
+ }
250
+ //#endregion
15
251
  //#region ../contract/src/domains.ts
16
252
  /**
17
253
  * Every public Cloudy address that code bakes in (CLI default, install command, landing and
18
- * docs links, badges). One place, so picking the real domain is a one-line change:
254
+ * docs links, badges). One place:
19
255
  *
20
- * export const PUBLIC_DOMAIN: string | null = "cloudtifact.com";
256
+ * export const PUBLIC_DOMAIN: string | null = "usecloudy.ai";
21
257
  *
22
- * With a domain set, our own hosts are api.<domain>, app.<domain> and the bare domain for the landing
23
- * site. What users publish (artifact pages and live apps) runs other people's HTML and JS, so it lives
258
+ * PUBLIC_DOMAIN is the site and app domain: app.<domain> and the bare domain for the landing site. The API and the MCP
259
+ * server live on SERVICE_DOMAIN instead, which never moves (the domain move, docs/domain-move.md): the CLI keys saved
260
+ * sign-ins and each folder's space by its API address, and connectors are signed in to the MCP address, so moving
261
+ * either would break every old CLI and connector. What users publish (artifact pages and live apps) runs other people's HTML and JS, so it lives
24
262
  * on a separate registrable domain, USER_CONTENT_DOMAIN, the way GitHub uses githubusercontent.com:
25
263
  * pages at the bare user-content domain (/<id>/, /t/<token>/), apps at <slug>.<user-content domain>.
26
264
  * Then a published page can never read or set cookies for the app or for Clerk. While PUBLIC_DOMAIN is
@@ -29,9 +267,20 @@ import { pipeline } from "node:stream/promises";
29
267
  * Deploy-time values (PUBLIC_API_URL, WEB_URL, ... in each wrangler.jsonc) are separate: wrangler
30
268
  * reads JSON, not this file. Update those in the same change (see README "Choosing the domain").
31
269
  */
32
- const PUBLIC_DOMAIN = "cloudtifact.com";
270
+ const PUBLIC_DOMAIN = "usecloudy.ai";
33
271
  /** Separate domain for published pages and live apps. Must not share a registrable domain with PUBLIC_DOMAIN. */
34
- const USER_CONTENT_DOMAIN = "cloudtifact.app";
272
+ const USER_CONTENT_DOMAIN = "cloudy.page";
273
+ /** Where api., mcp., admin. and assets. live, forever: programs talk to them, and they keep their addresses. */
274
+ const SERVICE_DOMAIN = "cloudtifact.com";
275
+ /**
276
+ * Every site and app domain we serve, new first. During and after the move (docs/domain-move.md) both answer: the old
277
+ * one sends page loads on to the new one and answers everything else in place.
278
+ */
279
+ const OWN_SITE_DOMAINS = ["usecloudy.ai", "cloudtifact.com"];
280
+ /** Every user-content domain we serve (published pages, live apps), new first. Same rule as OWN_SITE_DOMAINS. */
281
+ const OWN_USER_CONTENT_DOMAINS = ["cloudy.page", "cloudtifact.app"];
282
+ OWN_SITE_DOMAINS.map((d) => `https://app.${d}`);
283
+ OWN_USER_CONTENT_DOMAINS.map((d) => `https://${d}`);
35
284
  const WORKERS_DEV = {
36
285
  api: "https://cloudtifact-api.cloudtifact.workers.dev",
37
286
  web: "https://cloudtifact-docs.cloudtifact.workers.dev",
@@ -39,10 +288,10 @@ const WORKERS_DEV = {
39
288
  landing: "https://cloudtifact-landing.cloudtifact.workers.dev",
40
289
  appsHost: USER_CONTENT_DOMAIN
41
290
  };
42
- function urlsFor(domain, userContent = USER_CONTENT_DOMAIN) {
291
+ function urlsFor(domain, userContent = USER_CONTENT_DOMAIN, service = SERVICE_DOMAIN) {
43
292
  if (!domain) return WORKERS_DEV;
44
293
  return {
45
- api: `https://api.${domain}`,
294
+ api: `https://api.${service}`,
46
295
  web: `https://app.${domain}`,
47
296
  content: `https://${userContent}`,
48
297
  landing: `https://${domain}`,
@@ -5832,7 +6081,11 @@ const RESERVED_NAMES = /* @__PURE__ */ new Set([
5832
6081
  "billing",
5833
6082
  "blog",
5834
6083
  "cloudtifact",
6084
+ "cloudy",
5835
6085
  "docs",
6086
+ "edit",
6087
+ "explore",
6088
+ "feed",
5836
6089
  "guest",
5837
6090
  "help",
5838
6091
  "login",
@@ -5842,6 +6095,7 @@ const RESERVED_NAMES = /* @__PURE__ */ new Set([
5842
6095
  "null",
5843
6096
  "official",
5844
6097
  "owner",
6098
+ "posts",
5845
6099
  "root",
5846
6100
  "security",
5847
6101
  "settings",
@@ -5854,7 +6108,9 @@ const RESERVED_NAMES = /* @__PURE__ */ new Set([
5854
6108
  "support",
5855
6109
  "system",
5856
6110
  "team",
6111
+ "topics",
5857
6112
  "undefined",
6113
+ "usecloudy",
5858
6114
  "www"
5859
6115
  ]);
5860
6116
  const isReservedName = (name) => RESERVED_NAMES.has(name) || name.startsWith("deleted-");
@@ -5944,6 +6200,13 @@ const embedTokenOutput = object({
5944
6200
  token: string(),
5945
6201
  expiresAt: number$1()
5946
6202
  });
6203
+ object({ state: string().min(1).max(4096) });
6204
+ const signInCarryOutput = object({
6205
+ ticket: string(),
6206
+ expiresAt: number$1()
6207
+ });
6208
+ object({ ticket: string().min(1).max(200) });
6209
+ const signInCarryRedeemOutput = object({ state: string() });
5947
6210
  object({ token: string().max(200).optional() });
5948
6211
  const createSessionOutput = object({
5949
6212
  token: string(),
@@ -6575,7 +6838,8 @@ const listSpacesOutput = object({ spaces: array(spaceSchema) });
6575
6838
  object({
6576
6839
  q: string().trim().min(1).max(200),
6577
6840
  workspace: workspaceSlugSchema.optional(),
6578
- limit: number().int().min(1).max(50).default(10)
6841
+ limit: number().int().min(1).max(50).default(10),
6842
+ status: _enum(["active", "archived"]).default("active")
6579
6843
  });
6580
6844
  const findSpacesOutput = object({ spaces: array(spaceSchema.extend({
6581
6845
  /** Pages (HTML and Markdown files) in its latest version. */
@@ -6584,7 +6848,7 @@ const findSpacesOutput = object({ spaces: array(spaceSchema.extend({
6584
6848
  score: number$1(),
6585
6849
  /** Close enough to publish into without being told (topicMatch in find.ts). */
6586
6850
  strong: boolean(),
6587
- /** The page whose title matched better than the space's name, if any. */
6851
+ /** The page whose title matched at least as well as the space's name, if any. */
6588
6852
  page: string().nullable(),
6589
6853
  /** That page's path in the space ("plans/pricing.html"), for a link straight to it. */
6590
6854
  pagePath: string().nullable().optional()
@@ -6652,7 +6916,8 @@ const listVersionsOutput = object({ versions: array(versionSchema) });
6652
6916
  const getVersionOutput = object({
6653
6917
  version: versionSchema,
6654
6918
  files: array(fileEntrySchema),
6655
- diff: diffSchema
6919
+ diff: diffSchema,
6920
+ pagePictures: record(string(), string()).optional()
6656
6921
  });
6657
6922
  const getFileOutput = object({
6658
6923
  versionNumber: number$1().int(),
@@ -6767,6 +7032,7 @@ const commentSchema = object({
6767
7032
  resolvedAt: number$1().nullable(),
6768
7033
  resolvedBy: userSchema.nullable(),
6769
7034
  resolvedVia: string().nullable(),
7035
+ resolvedVersion: number$1().nullable().default(null),
6770
7036
  editedAt: number$1().nullable(),
6771
7037
  editedBy: userSchema.nullable(),
6772
7038
  editedVia: string().nullable(),
@@ -7205,7 +7471,8 @@ const spacePageOutput = object({
7205
7471
  revisions: record(string(), array(commentRevisionSchema)),
7206
7472
  discord: array(discordLinkSchema),
7207
7473
  muted: boolean().nullable().optional(),
7208
- mentionPeople: array(userSchema).nullable().optional()
7474
+ mentionPeople: array(userSchema).nullable().optional(),
7475
+ pagePictures: record(string(), string()).optional()
7209
7476
  }).nullable()
7210
7477
  });
7211
7478
  //#endregion
@@ -7558,13 +7825,16 @@ const customDomainStatusSchema = _enum([
7558
7825
  ]);
7559
7826
  const LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
7560
7827
  /** Hosts nobody may connect: ours, and the shared hosting ones a customer can't own. */
7561
- const NOT_CONNECTABLE = [
7828
+ const NOT_CONNECTABLE = [.../* @__PURE__ */ new Set([
7562
7829
  USER_CONTENT_DOMAIN,
7563
- "cloudtifact.com",
7830
+ "usecloudy.ai",
7831
+ SERVICE_DOMAIN,
7832
+ ...OWN_SITE_DOMAINS,
7833
+ ...OWN_USER_CONTENT_DOMAINS,
7564
7834
  "workers.dev",
7565
7835
  "pages.dev",
7566
7836
  "localhost"
7567
- ].filter(Boolean);
7837
+ ])].filter(Boolean);
7568
7838
  /** Lowercased, trimmed, without a scheme, path or trailing dot: what someone pasted, as a hostname. */
7569
7839
  function normalizeHostname(input) {
7570
7840
  let h = input.trim().toLowerCase();
@@ -7813,6 +8083,8 @@ function createClient(opts) {
7813
8083
  devLogin: (input) => call("POST", "/v1/auth/dev-login", devLoginOutput, input),
7814
8084
  createEmbedToken: () => call("POST", "/v1/auth/embed-token", embedTokenOutput),
7815
8085
  createVisitorLink: () => call("POST", "/v1/auth/visitor-link", embedTokenOutput),
8086
+ createSignInCarry: (state) => call("POST", "/v1/auth/carry", signInCarryOutput, { state }),
8087
+ redeemSignInCarry: (ticket) => call("POST", "/v1/auth/carry/redeem", signInCarryRedeemOutput, { ticket }),
7816
8088
  /** With the identity provider's session token as this client's token: swaps it for a browser sign-in. */
7817
8089
  createSession: (input = {}) => call("POST", "/v1/sessions", createSessionOutput, input),
7818
8090
  me: () => call("GET", "/v1/me", meOutput),
@@ -7873,6 +8145,7 @@ function createClient(opts) {
7873
8145
  const params = new URLSearchParams({ q: query.q });
7874
8146
  if (query.workspace) params.set("workspace", query.workspace);
7875
8147
  if (query.limit) params.set("limit", String(query.limit));
8148
+ if (query.status) params.set("status", query.status);
7876
8149
  return call("GET", `/v1/spaces/find?${params}`, findSpacesOutput);
7877
8150
  },
7878
8151
  createSpace: (input) => call("POST", "/v1/spaces", spaceSchema, input),
@@ -8721,238 +8994,6 @@ function resolveOptions(options) {
8721
8994
  //#region ../contract/src/toon.ts
8722
8995
  const toToon = (value) => encode(value);
8723
8996
  //#endregion
8724
- //#region src/config.ts
8725
- const DEFAULT_API_URL = PUBLIC_URLS.api;
8726
- const REPO_CONFIG_FILE = ".cloudtifact.json";
8727
- function homeDir(env = process.env) {
8728
- return env.CLOUDTIFACT_HOME || os.homedir();
8729
- }
8730
- function globalConfigDir(env = process.env) {
8731
- if (env.CLOUDTIFACT_CONFIG_DIR) return env.CLOUDTIFACT_CONFIG_DIR;
8732
- const xdg = env.XDG_CONFIG_HOME || path.join(homeDir(env), ".config");
8733
- return path.join(xdg, "cloudtifact");
8734
- }
8735
- function globalConfigPath(env = process.env) {
8736
- return path.join(globalConfigDir(env), "config.json");
8737
- }
8738
- async function readGlobalConfig(env = process.env) {
8739
- const file = globalConfigPath(env);
8740
- if (!existsSync(file)) return {};
8741
- try {
8742
- const data = JSON.parse(await readFile(file, "utf8"));
8743
- return data && typeof data === "object" ? data : {};
8744
- } catch {
8745
- throw new Error(`Could not parse ${file}. Fix or delete it, then run \`cloudy login\`.`);
8746
- }
8747
- }
8748
- async function writeGlobalConfig(config, env = process.env) {
8749
- const dir = globalConfigDir(env);
8750
- await mkdir(dir, {
8751
- recursive: true,
8752
- mode: 448
8753
- });
8754
- const file = globalConfigPath(env);
8755
- await writeFile(file, `${JSON.stringify(config, null, 2)}\n`, { mode: 384 });
8756
- await chmod(file, 384);
8757
- }
8758
- async function clearGlobalConfig(env = process.env) {
8759
- await rm(globalConfigPath(env), { force: true });
8760
- }
8761
- /** env CLOUDTIFACT_API_URL > config file > default. */
8762
- function resolveApiUrl(config, env = process.env) {
8763
- return (env.CLOUDTIFACT_API_URL || config.apiUrl || DEFAULT_API_URL).replace(/\/+$/, "");
8764
- }
8765
- /** The API the saved token was issued by: the apiUrl saved with it (`login` always saves both), else the default. */
8766
- function tokenApiUrl(config) {
8767
- return (config.apiUrl || DEFAULT_API_URL).replace(/\/+$/, "");
8768
- }
8769
- /**
8770
- * The saved token, but only for the API it came from. CLOUDTIFACT_API_URL can point the CLI at another API; the
8771
- * token is never sent there (that API could keep it and use it against ours). For another API you're signed out.
8772
- */
8773
- function savedTokenFor(config, apiUrl) {
8774
- return config.token && sameApi(tokenApiUrl(config), apiUrl) ? config.token : void 0;
8775
- }
8776
- function sameApi(a, b) {
8777
- const norm = (u) => {
8778
- try {
8779
- return new URL(u).href.replace(/\/+$/, "");
8780
- } catch {
8781
- return u.replace(/\/+$/, "");
8782
- }
8783
- };
8784
- return norm(a) === norm(b);
8785
- }
8786
- const sameAccount = (a, b) => a.handle === b.handle && sameApi(a.apiUrl, b.apiUrl);
8787
- /** The active account (the top-level fields), if signed in. Very old configs saved a token without a handle: "". */
8788
- function activeAccount(config) {
8789
- if (!config.token) return void 0;
8790
- const { token, handle = "", workspace } = config;
8791
- return {
8792
- apiUrl: tokenApiUrl(config),
8793
- token,
8794
- handle,
8795
- ...workspace ? { workspace } : {}
8796
- };
8797
- }
8798
- /** Every signed-in account, the active one first. Configs from before `accounts` hold just the active one. */
8799
- function accountsOf(config) {
8800
- const active = activeAccount(config);
8801
- const others = (config.accounts ?? []).filter((a) => !active || !sameAccount(a, active));
8802
- return active ? [active, ...others] : others;
8803
- }
8804
- /** Adds or updates an account and makes it the active one. */
8805
- function withActiveAccount(config, account) {
8806
- const { apiUrl, token, handle, workspace } = account;
8807
- const others = accountsOf(config).filter((a) => !sameAccount(a, account));
8808
- const { workspace: _w, ...rest } = config;
8809
- return {
8810
- ...rest,
8811
- apiUrl,
8812
- token,
8813
- handle,
8814
- ...workspace ? { workspace } : {},
8815
- accounts: [account, ...others]
8816
- };
8817
- }
8818
- /** Updates an account in place (its default workspace, say), active or not. */
8819
- function withAccountUpdated(config, account) {
8820
- const active = activeAccount(config);
8821
- if (active && sameAccount(active, account)) return withActiveAccount(config, account);
8822
- return {
8823
- ...config,
8824
- accounts: accountsOf(config).map((a) => sameAccount(a, account) ? account : a)
8825
- };
8826
- }
8827
- /** Forgets an account. If it was the active one, the next signed-in account becomes active. */
8828
- function withoutAccount(config, account) {
8829
- const left = accountsOf(config).filter((a) => !sameAccount(a, account));
8830
- const directories = Object.fromEntries(Object.entries(config.directories ?? {}).filter(([, h]) => h !== account.handle || left.some((a) => a.handle === h)));
8831
- const { apiUrl: _a, token: _t, handle: _h, workspace: _w, accounts: _l, directories: _d, ...rest } = config;
8832
- const base = {
8833
- ...rest,
8834
- ...Object.keys(directories).length ? { directories } : {}
8835
- };
8836
- const [next] = left;
8837
- return next ? withActiveAccount({
8838
- ...base,
8839
- accounts: left
8840
- }, next) : base;
8841
- }
8842
- /** The account a folder is bound to (`cloudy switch <handle> --here`): the nearest bound folder above `from`. */
8843
- function boundHandle(config, from = process.cwd()) {
8844
- const dirs = config.directories ?? {};
8845
- let dir = path.resolve(from);
8846
- for (;;) {
8847
- const handle = dirs[dir];
8848
- if (handle) return {
8849
- handle,
8850
- dir
8851
- };
8852
- const parent = path.dirname(dir);
8853
- if (parent === dir) return null;
8854
- dir = parent;
8855
- }
8856
- }
8857
- /** The folder `switch --here` binds: the repo root (or git root) above `from`, else `from`. */
8858
- function bindingRoot(from = process.cwd()) {
8859
- return findInitRoot(from);
8860
- }
8861
- /** Walks up from `from` to the nearest directory holding .cloudtifact.json. */
8862
- function findRepoRoot(from = process.cwd()) {
8863
- let dir = path.resolve(from);
8864
- for (;;) {
8865
- if (existsSync(path.join(dir, ".cloudtifact.json"))) return dir;
8866
- const parent = path.dirname(dir);
8867
- if (parent === dir) return null;
8868
- dir = parent;
8869
- }
8870
- }
8871
- /** Where `init` should write: the git root above `from`, else `from`. */
8872
- function findInitRoot(from = process.cwd()) {
8873
- let dir = path.resolve(from);
8874
- for (;;) {
8875
- if (existsSync(path.join(dir, ".git")) || existsSync(path.join(dir, ".cloudtifact.json"))) return dir;
8876
- const parent = path.dirname(dir);
8877
- if (parent === dir) return path.resolve(from);
8878
- dir = parent;
8879
- }
8880
- }
8881
- /**
8882
- * The project work belongs to, recorded on each version: CLOUDTIFACT_PROJECT, else the name of the git repo above
8883
- * `from` (a worktree counts as its main repo), else null.
8884
- */
8885
- function projectName(from = process.cwd(), env = process.env) {
8886
- const named = env.CLOUDTIFACT_PROJECT?.trim();
8887
- if (named) return named.slice(0, 100);
8888
- let dir = path.resolve(from);
8889
- for (;;) {
8890
- const git = path.join(dir, ".git");
8891
- if (existsSync(git)) {
8892
- try {
8893
- const m = /^gitdir:\s*(.+)$/m.exec(readFileSync(git, "utf8"));
8894
- const main = m?.[1] ? /^(.*)[\\/]\.git[\\/]worktrees[\\/]/.exec(m[1].trim()) : null;
8895
- if (main?.[1]) return path.basename(main[1]);
8896
- } catch {}
8897
- return path.basename(dir);
8898
- }
8899
- const parent = path.dirname(dir);
8900
- if (parent === dir) return null;
8901
- dir = parent;
8902
- }
8903
- }
8904
- function parseRepoConfig(raw, file = REPO_CONFIG_FILE) {
8905
- const bad = (why) => /* @__PURE__ */ new Error(`${file}: ${why}`);
8906
- if (!raw || typeof raw !== "object") throw bad("expected a JSON object");
8907
- const { dir, targets } = raw;
8908
- if (typeof dir !== "string" || !dir) throw bad("\"dir\" must be a non-empty string");
8909
- if (!Array.isArray(targets)) throw bad("\"targets\" must be an array");
8910
- return {
8911
- dir,
8912
- targets: targets.map((t, i) => {
8913
- if (!t || typeof t !== "object" || typeof t.spaceId !== "string") throw bad(`targets[${i}].spaceId must be a string`);
8914
- const { spaceId, label } = t;
8915
- return label ? {
8916
- spaceId,
8917
- label
8918
- } : { spaceId };
8919
- })
8920
- };
8921
- }
8922
- async function readRepoConfig(root) {
8923
- const file = path.join(root, REPO_CONFIG_FILE);
8924
- let raw;
8925
- try {
8926
- raw = JSON.parse(await readFile(file, "utf8"));
8927
- } catch (err) {
8928
- throw new Error(`Could not read ${file}: ${err.message}`);
8929
- }
8930
- return parseRepoConfig(raw, file);
8931
- }
8932
- async function writeRepoConfig(root, config) {
8933
- await writeFile(path.join(root, REPO_CONFIG_FILE), `${JSON.stringify(config, null, 2)}\n`);
8934
- }
8935
- const realOrSelf = (p) => {
8936
- try {
8937
- return realpathSync(p);
8938
- } catch {
8939
- return p;
8940
- }
8941
- };
8942
- async function loadRepo(from = process.cwd()) {
8943
- const root = findRepoRoot(from);
8944
- if (!root) throw new Error(`No ${REPO_CONFIG_FILE} found here or above. Run \`cloudy init\` first.`);
8945
- const config = await readRepoConfig(root);
8946
- const docsDir = path.resolve(root, config.dir);
8947
- const rel = path.relative(realOrSelf(root), realOrSelf(docsDir));
8948
- if (rel.startsWith("..") || path.isAbsolute(rel)) throw new Error(`"dir" in ${REPO_CONFIG_FILE} must be inside the repo (got "${config.dir}")`);
8949
- return {
8950
- root,
8951
- config,
8952
- docsDir
8953
- };
8954
- }
8955
- //#endregion
8956
8997
  //#region ../../node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
8957
8998
  /**
8958
8999
  * CommanderError class
@@ -12630,7 +12671,14 @@ async function pushTarget(client, target, initial, opts = {}) {
12630
12671
  let files = initial;
12631
12672
  let uploaded = 0;
12632
12673
  const planAndUpload = async () => {
12633
- const manifest = manifestOf(files);
12674
+ const sent = manifestOf(files);
12675
+ const ours = new Set(sent.map((f) => f.path));
12676
+ const kept = opts.keep ? (await opts.keep()).filter((f) => !ours.has(f.path)) : [];
12677
+ const manifest = [...sent, ...kept.map(({ path, sha256, size }) => ({
12678
+ path,
12679
+ sha256,
12680
+ size
12681
+ }))];
12634
12682
  const bySha = new Map(files.map((f) => [f.sha256, f]));
12635
12683
  const plan = await client.pushPlan(target.spaceId, {
12636
12684
  files: manifest,
@@ -12780,8 +12828,12 @@ function commentsUrl(shareUrl) {
12780
12828
  */
12781
12829
  function linkLines(space, prefix) {
12782
12830
  const share = space.shareUrl && prefix ? space.shareUrl + prefix : space.shareUrl;
12783
- if (share) return [`Page: ${share}`, `With comments: ${commentsUrl(share)}`];
12784
- return [`Link: ${prefix ? `${space.url}/${prefix}index.html` : space.url}`, `Private: only members of the ${space.workspace.slug} workspace can open it. To make it public, change visibility in the space settings on the website.`];
12831
+ if (share) return [
12832
+ `Page: ${share}`,
12833
+ `With comments: ${commentsUrl(share)}`,
12834
+ `Public: anyone with the link can open it. To make it private: cloudy settings --space ${space.id} --visibility private`
12835
+ ];
12836
+ return [`Link: ${prefix ? `${space.url}/${prefix}index.html` : space.url}`, `Private: only members of the ${space.workspace.slug} workspace can open it. To make it public: cloudy settings --space ${space.id} --visibility public (space admins), or the space's Settings on the website.`];
12785
12837
  }
12786
12838
  /** A local, relative reference, or null for absolute URLs, data:, anchors, etc. Drops ?query and #hash. */
12787
12839
  function localRef(raw) {
@@ -12851,6 +12903,7 @@ async function bundleHtmlFile(file) {
12851
12903
  warnings.push(`skipped ${ref}: ${why}`);
12852
12904
  return null;
12853
12905
  };
12906
+ if (ref.endsWith("/") || ref === ".") return null;
12854
12907
  const rel = resolveInside(fromRel, ref);
12855
12908
  if (!rel) return skip(`outside ${path.basename(base)}/`);
12856
12909
  if (rel === entryRel || picked.has(rel)) return null;
@@ -12910,10 +12963,14 @@ async function publishToSpace(client, spaceId, bundle, opts) {
12910
12963
  ...f,
12911
12964
  path: prefix + f.path
12912
12965
  })) : bundle.files;
12966
+ const keep = opts.keepOthers ? async () => {
12967
+ return (await client.getSpace(spaceId)).latestVersion > 0 ? (await client.getVersion(spaceId, "latest")).files : [];
12968
+ } : void 0;
12913
12969
  return pushTarget(client, { spaceId }, files, {
12914
12970
  message: opts.message,
12915
12971
  prefix,
12916
- project: opts.project
12972
+ project: opts.project,
12973
+ keep
12917
12974
  });
12918
12975
  }
12919
12976
  /**
@@ -13043,7 +13100,7 @@ function tokenSpace(token) {
13043
13100
  //#endregion
13044
13101
  //#region src/version.ts
13045
13102
  /** This CLI's version, from package.json at build time (tsdown.config.ts). Unbuilt (tests, tsx): "0.0.0-dev". */
13046
- const VERSION = "0.3.1";
13103
+ const VERSION = "0.3.3";
13047
13104
  /**
13048
13105
  * Sent on every API request, so the API can tell which CLI version is calling (and one day tell an old one to
13049
13106
  * upgrade). Without it Node sends just "node", which is what 0.2.2 and older send. The sign-in page shows it too.
@@ -14307,6 +14364,17 @@ const SETTINGS = [
14307
14364
  get: (s) => s.guestComments
14308
14365
  }
14309
14366
  ];
14367
+ /**
14368
+ * `--visibility`: who can open the space. private (members of its workspace) or public (anyone with the link); the
14369
+ * API calls private "members", and members stays an alias, as in `gh repo edit --visibility`.
14370
+ */
14371
+ const VISIBILITY_OPTION = "--visibility <private|public>";
14372
+ function visibilityOf(value) {
14373
+ const v = value.trim().toLowerCase();
14374
+ if (v === "private" || v === "members") return "members";
14375
+ if (v === "public") return "public";
14376
+ throw new CliError(`--visibility takes private or public, not ${value}.`);
14377
+ }
14310
14378
  function onOff(value, option) {
14311
14379
  const v = value.trim().toLowerCase();
14312
14380
  if (v === "on" || v === "true" || v === "yes") return true;
@@ -14316,6 +14384,7 @@ function onOff(value, option) {
14316
14384
  /** The PATCH /v1/spaces/:id body for the flags given; null when there are none. */
14317
14385
  function settingsPatch(opts) {
14318
14386
  const patch = {};
14387
+ if (opts.visibility !== void 0) patch.visibility = visibilityOf(opts.visibility);
14319
14388
  for (const s of SETTINGS) {
14320
14389
  const value = opts[s.flag];
14321
14390
  if (value === void 0) continue;
@@ -14347,7 +14416,7 @@ function settingsData(space) {
14347
14416
  };
14348
14417
  }
14349
14418
  function settingsText(space) {
14350
- const lines = [`${space.name} (${space.id}) · ${space.visibility === "public" ? "public" : "members only"}`];
14419
+ const lines = [`${space.name} (${space.id}) · ${space.visibility === "public" ? "public" : "private (members only)"}`];
14351
14420
  for (const s of SETTINGS) lines.push(` ${s.get(space) ? "on " : "off"} ${s.label} (${s.option.split(" ")[0]})`);
14352
14421
  if (space.shareUrl) {
14353
14422
  lines.push(` Public link ${space.shareUrl}`);
@@ -14357,7 +14426,7 @@ function settingsText(space) {
14357
14426
  lines.push(` Always works ${always.href}`);
14358
14427
  }
14359
14428
  }
14360
- if (space.visibility !== "public") lines.push("Guest writes and guest comments need a public space.");
14429
+ if (space.visibility !== "public") lines.push("Guest writes and guest comments need a public space (--visibility public, space admins).");
14361
14430
  return `${lines.join("\n")}\n`;
14362
14431
  }
14363
14432
  //#endregion
@@ -14429,13 +14498,22 @@ When you make an HTML page for the user, run \`cloudy publish <file.html>\` and
14429
14498
 
14430
14499
  - To update it, edit the same file and publish it again: new version, same link.
14431
14500
  - Keep supporting files next to the HTML (or in subfolders) and reference them with relative paths (\`style.css\`, \`img/logo.png\`). Absolute paths and files outside the page's folder aren't included.
14432
- - Pages are private by default; add \`--public\` on the first publish for a link anyone can open. \`cloudy artifacts\` lists what you've published.
14433
- - New work joins the space already about the same topic, as a page, instead of making another space: \`publish\` finds it (same workspace, same who-can-see) and prints \`Looks like "<space>"\`. Tell the user where it went. To check first, run \`cloudy find "<title>" --toon\`; \`--add-to <id>\` adds the page to a space you pick, \`--new\` makes a separate space when the user wants one.
14501
+ - Spaces are private. Never add \`--public\` unless the user asks for a public link in this conversation, or it's a PR screenshot page. \`--public\` only works on the first publish. To switch a space later, a space admin runs \`cloudy settings --space <id> --visibility private\` (members of the workspace only) or \`--visibility public\` (anyone with the link, same rule as \`--public\`). Going public turns guest comments on; going private turns guest comments and guest writes off, and the public link stops working. \`cloudy artifacts\` lists what you've published.
14502
+ - New work joins the space already about the same topic, as a page, instead of making another space: \`publish\` finds it (same workspace, same who-can-see) and prints \`Looks like "<space>"\`. Tell the user where it went. To check first, run \`cloudy find "<title>" --toon\`; \`--add-to <id>\` adds the page to a space you pick, \`--new\` makes a separate space when the user wants one. Then link it from the space's home page (below).
14434
14503
  - A page that stores something needs the space to allow it: read "What a space can't do" first.
14435
14504
 
14505
+ ### Adding a page to a space
14506
+
14507
+ A page added to a space (\`--add-to\`, or \`Looks like "<space>"\`) goes in its own folder, named after the file: \`mac-mini-server.html\` becomes \`mac-mini-server/\`, while \`index.html\` becomes \`index-2/\`. So name the file after its topic before you publish. Nobody finds the page unless the space's home page links to it, so every time:
14508
+
14509
+ 1. \`cloudy copy <space id> --no-publish -o <dir>\` writes the space's files (the home page is \`index.html\`, each added page is \`<folder>/index.html\`). It makes no new space.
14510
+ 2. Edit \`<dir>/index.html\`: add a link to the new page (\`href="mac-mini-server/"\`) in its navigation or list of contents, in the same style as the links already there. If the home page doesn't list its pages, add a short "Pages" list in its look; if the space has no home page at all, make a simple \`index.html\` that links to every folder.
14511
+ 3. \`cloudy publish <dir>/index.html --space <id> --keep-pages\`. Without \`--keep-pages\`, publishing to \`--space\` replaces every file in the space and deletes the added pages.
14512
+ 4. Give the user both links: the new page's and the home page's.
14513
+
14436
14514
  ## Copying a page someone sent you
14437
14515
 
14438
- When the user is sent a Cloudy link and wants their own copy, run \`cloudy copy <url>\`. It publishes the files into a new space in their workspace and prints the new link. Add \`--public\` if they want anyone to open it. \`-o <dir>\` also writes the files locally; \`--no-publish -o <dir>\` writes them without making a space.
14516
+ When the user is sent a Cloudy link and wants their own copy, run \`cloudy copy <url>\`. It publishes the files into a new space in their workspace and prints the new link. It's private; add \`--public\` only if the user asks for a link anyone can open. \`-o <dir>\` also writes the files locally; \`--no-publish -o <dir>\` writes them without making a space.
14439
14517
 
14440
14518
  ## Space files
14441
14519
 
@@ -14478,7 +14556,7 @@ Put the SQL a page needs in \`db/NNN_name.sql\` files next to it (the page's fol
14478
14556
 
14479
14557
  ## Guest writes
14480
14558
 
14481
- For visitors who aren't signed in to add data (a sign-up sheet, a vote, feedback, a high score), the page runs named writes you publish, never its own SQL. The space must be public, and an admin turns on "Pages can save data for people who are not signed in": in the space's Settings, or \`cloudy settings --guest-writes on\` (admins only). If the pages shouldn't show what guests saved (answers, sign-ups), also turn off "Pages can show saved data" (\`--pages-show-data off\`) first. \`cloudy settings\` shows both. \`cloudy settings --link homeideas\` sets the public link (\`--link off\` clears it). Ask the user before you turn guest writes on.
14559
+ For visitors who aren't signed in to add data (a sign-up sheet, a vote, feedback, a high score), the page runs named writes you publish, never its own SQL. The space must be public (ask the user first: spaces are private), and an admin turns on "Pages can save data for people who are not signed in": in the space's Settings, or \`cloudy settings --guest-writes on\` (admins only). If the pages shouldn't show what guests saved (answers, sign-ups), also turn off "Pages can show saved data" (\`--pages-show-data off\`) first. \`cloudy settings\` shows both. \`cloudy settings --link homeideas\` sets the public link (\`--link off\` clears it). Ask the user before you turn guest writes on.
14482
14560
 
14483
14561
  - Put the statements in \`db/guest-writes.sql\` next to the page: \`-- name: vote\` on its own line, then exactly one INSERT, UPDATE or DELETE. \`?\` placeholders take the page's params; \`$guest\` is the name the visitor gave and \`$guest_id\` a stable id for their browser, both filled in by the server. Publish and push upload the whole set (replacing the old one) after the migrations; \`cloudy db guest-writes\` shows what's live.
14484
14562
  - In the page: \`await window.cloudtifact.guest.set(name)\` once (it remembers the name), then \`await window.cloudtifact.db.run("vote", [choice])\`. Without a name it rejects with code \`no_guest\`.
@@ -14551,7 +14629,7 @@ async function skillCopies(home, version = VERSION) {
14551
14629
  * somebody edited by hand survives until the CLI changes. `check` reports and writes nothing.
14552
14630
  */
14553
14631
  async function installSkill(home, opts = {}) {
14554
- const version = opts.version ?? "0.3.1";
14632
+ const version = opts.version ?? "0.3.3";
14555
14633
  const markdown = skillMarkdown(version);
14556
14634
  const copies = await skillCopies(home, version);
14557
14635
  const written = [];
@@ -14868,7 +14946,7 @@ async function runUpdateCheck(source, deps = {}) {
14868
14946
  source,
14869
14947
  ...latest ? { latest } : before?.latest ? { latest: before.latest } : {}
14870
14948
  }, env);
14871
- await refreshSkillCopies(homeDir(env), deps.version ?? "0.3.1");
14949
+ await refreshSkillCopies(homeDir(env), deps.version ?? "0.3.3");
14872
14950
  }
14873
14951
  /** Starts the check in a detached process that outlives this one and is never waited for. */
14874
14952
  function spawnUpdateCheck(entry, source) {
@@ -15072,7 +15150,7 @@ const program = new Command().name("cloudy").description("Publish pages and docs
15072
15150
  const tty = !!process.stdout.isTTY && !!process.stderr.isTTY;
15073
15151
  if (updateNoticeOff({
15074
15152
  env: process.env,
15075
- current: "0.3.1",
15153
+ current: "0.3.3",
15076
15154
  command: cmd.name()
15077
15155
  })) return;
15078
15156
  const entry = fileURLToPath(import.meta.url);
@@ -15309,7 +15387,11 @@ async function workspaceForNewSpace(client, flag, saved) {
15309
15387
  if (cur.note) console.error(`note: ${cur.note}`);
15310
15388
  return cur;
15311
15389
  }
15312
- program.command("init").description("Link this repo to a space (creating one in the current workspace if needed) and write .cloudtifact.json").option("--dir <dir>", "folder to publish, relative to the repo root").option("--workspace <slug>", "workspace for a new space (default: the current one, see `workspace list`)").addOption(new Option("--visibility <v>", "who can view a new space (default: members)").choices(["public", "members"])).option("--space <id>", "link an existing space (id or link) instead of creating one").option("--name <name>", "name for a new space (default: the repo folder name)").option("-y, --yes", "accept defaults, no prompts").option("--hooks", "also install agent hooks (see `hooks install`)").action(run(async (opts) => {
15390
+ program.command("init").description("Link this repo to a space (creating one in the current workspace if needed) and write .cloudtifact.json").option("--dir <dir>", "folder to publish, relative to the repo root").option("--workspace <slug>", "workspace for a new space (default: the current one, see `workspace list`)").addOption(new Option("--visibility <v>", "who can view a new space (default: private)").choices([
15391
+ "private",
15392
+ "public",
15393
+ "members"
15394
+ ])).option("--space <id>", "link an existing space (id or link) instead of creating one").option("--name <name>", "name for a new space (default: the repo folder name)").option("-y, --yes", "accept defaults, no prompts").option("--hooks", "also install agent hooks (see `hooks install`)").action(run(async (opts) => {
15313
15395
  const { client, config } = await getClient();
15314
15396
  const root = findInitRoot();
15315
15397
  const configFile = path.join(root, REPO_CONFIG_FILE);
@@ -15332,7 +15414,7 @@ program.command("init").description("Link this repo to a space (creating one in
15332
15414
  } else {
15333
15415
  const cur = await workspaceForNewSpace(client, opts.workspace, config.workspace);
15334
15416
  console.log(workspaceLine(cur));
15335
- let visibility = opts.visibility;
15417
+ let visibility = opts.visibility ? visibilityOf(opts.visibility) : void 0;
15336
15418
  if (!visibility && prompt) visibility = await choose("Who can view it?", [`members of ${cur.workspace.slug} only`, "anyone with the link"]) ? "public" : "members";
15337
15419
  const defaultName = path.basename(root);
15338
15420
  const name = opts.name ?? (prompt ? await ask("Space name:", defaultName) : defaultName);
@@ -15588,8 +15670,9 @@ for (const [name, verb] of [["resolve", "Resolved"], ["unresolve", "Reopened"]])
15588
15670
  const c = await (name === "resolve" ? client.resolveComment(commentId) : client.unresolveComment(commentId));
15589
15671
  console.log(`${verb} ${c.id} on ${c.path}.`);
15590
15672
  }));
15591
- program.command("publish").description("Publish an HTML page (with the files it references) or a folder; prints its link").argument("<path>", "an .html file or a folder with index.html").option("--public", "anyone with the link can view (only when first published; default: private)").option("--name <name>", "space name (default: the page's <title>, else the file name)").option("--workspace <slug>", "workspace for a new space (default: the current one, see `workspace list`)").option("--space <id>", "publish as this existing space's main page (id or link), replacing its files").option("--add-to <id>", "add it as a page in this existing space (id or link), keeping the space's other pages").option("--new", "make a new space, even when an existing one looks like the same topic").option("--folder <path>", "file a new space in this folder, like \"Deals/Enterprise\" (see `cloudy folders`)").option("--project <name>", "the project this work belongs to (default: the git repo it's in)").option("--entry <file>", "folder only: the page to publish as index.html").option("-m, --message <message>", "version message").option("--no-db", "don't run the db/*.sql files next to the page").option("--strict", "make a page the space can't back an error, so nothing is published").action(run(async (target, opts) => {
15673
+ program.command("publish").description("Publish an HTML page (with the files it references) or a folder; prints its link").argument("<path>", "an .html file or a folder with index.html").option("--public", "anyone with the link can view (only when first published; default: private). Agents: only when the user asks").option("--name <name>", "space name (default: the page's <title>, else the file name)").option("--workspace <slug>", "workspace for a new space (default: the current one, see `workspace list`)").option("--space <id>", "publish as this existing space's main page (id or link), replacing its files").option("--keep-pages", "with --space: replace only the files you publish (its home page, say) and keep the space's other pages and files").option("--add-to <id>", "add it as a page in this existing space (id or link), keeping the space's other pages").option("--new", "make a new space, even when an existing one looks like the same topic").option("--folder <path>", "file a new space in this folder, like \"Deals/Enterprise\" (see `cloudy folders`)").option("--project <name>", "the project this work belongs to (default: the git repo it's in)").option("--entry <file>", "folder only: the page to publish as index.html").option("-m, --message <message>", "version message").option("--no-db", "don't run the db/*.sql files next to the page").option("--strict", "make a page the space can't back an error, so nothing is published").action(run(async (target, opts) => {
15592
15674
  if (opts.space && opts.addTo) throw new CliError("Pass --space or --add-to, not both.");
15675
+ if (opts.keepPages && !opts.space) throw new CliError("--keep-pages goes with --space <id>: it updates that space's main page and keeps the rest.");
15593
15676
  if ((opts.space || opts.addTo) && opts.new) throw new CliError("--new makes a new space; drop --space/--add-to.");
15594
15677
  const abs = path.resolve(target);
15595
15678
  if (!existsSync(abs)) throw new CliError(`${target} does not exist.`);
@@ -15696,6 +15779,7 @@ program.command("publish").description("Publish an HTML page (with the files it
15696
15779
  project: opts.project ?? projectName(path.dirname(abs)),
15697
15780
  message: opts.message,
15698
15781
  db: opts.db,
15782
+ keepOthers: opts.keepPages,
15699
15783
  log: (l) => console.log(l),
15700
15784
  warn: (l) => console.error(l)
15701
15785
  });
@@ -15703,8 +15787,9 @@ program.command("publish").description("Publish an HTML page (with the files it
15703
15787
  if (r.status === "pushed") console.log(`Published "${space.name}" v${r.version} (${n} file${n === 1 ? "" : "s"}; ${summarize(r.diff)})`);
15704
15788
  else console.log(`No changes since v${space.latestVersion}: "${space.name}"`);
15705
15789
  for (const line of linkLines(space, prefix)) console.log(line);
15790
+ if (prefix) console.log(`Home page: add a link to ${prefix} in the space's home page (index.html), then publish it with --space ${space.id} --keep-pages.`);
15706
15791
  }));
15707
- program.command("copy").description("Make your own copy of a Cloudy page someone sent you: a new space in your workspace").argument("<url>", "a Cloudy page link, space id, or public link").option("--at <n>", "the version to copy (default: the one in the URL, else latest)").option("--name <name>", "name for the new space (default: the original's name)").option("--workspace <slug>", "workspace for the new space (default: the current one, see `workspace list`)").option("--public", "anyone with the link can view (default: private)").option("-o, --output <dir>", "also write the files into this folder").option("--force", "overwrite files in -o").option("--no-publish", "write files with -o and don't make a new space").option("-m, --message <message>", "version message on the new space").option("--strict", "make a page the space can't back an error, so nothing is published").option("--toon", "print TOON (compact, for agents)").option("--json", "print JSON").action(run(async (url, opts) => {
15792
+ program.command("copy").description("Make your own copy of a Cloudy page someone sent you: a new space in your workspace").argument("<url>", "a Cloudy page link, space id, or public link").option("--at <n>", "the version to copy (default: the one in the URL, else latest)").option("--name <name>", "name for the new space (default: the original's name)").option("--workspace <slug>", "workspace for the new space (default: the current one, see `workspace list`)").option("--public", "anyone with the link can view (default: private). Agents: only when the user asks").option("-o, --output <dir>", "also write the files into this folder").option("--force", "overwrite files in -o").option("--no-publish", "write files with -o and don't make a new space").option("-m, --message <message>", "version message on the new space").option("--strict", "make a page the space can't back an error, so nothing is published").option("--toon", "print TOON (compact, for agents)").option("--json", "print JSON").action(run(async (url, opts) => {
15708
15793
  const publish = opts.publish !== false;
15709
15794
  if (!publish && !opts.output) throw new CliError("--no-publish needs -o <dir> to write the files.");
15710
15795
  if (opts.force && !opts.output) throw new CliError("--force only applies with -o.");
@@ -15841,7 +15926,7 @@ program.command("versions").description("List a space's versions, newest first")
15841
15926
  if (!rows.length) return console.log("Nothing pushed yet.");
15842
15927
  for (const v of rows) console.log(`v${v.version} ${v.at} UTC ${byPerson(`@${v.by}`, v.via)}${v.project ? ` · ${v.project}` : ""} +${v.added} ~${v.changed} -${v.removed}${v.message ? ` ${v.message}` : ""}`);
15843
15928
  }));
15844
- program.command("settings").description("Show a space's guest and visitor switches, or flip them (space admins; the same switches as in the app)").option("--space <id>", "space id, public link, or copied URL (default: the first target in .cloudtifact.json)").option(SETTINGS[0].option, SETTINGS[0].label).option(SETTINGS[1].option, `${SETTINGS[1].label} (off keeps the database private from visitors)`).option(SETTINGS[2].option, SETTINGS[2].label).option("--link <name>", "set the public link (letters and numbers, or off to clear it)").option("--toon", "print TOON (compact, for agents)").option("--json", "print JSON").action(run(async (opts) => {
15929
+ program.command("settings").description("Show who can open a space and its guest and visitor switches, or change them (space admins; the same switches as in the app)").option("--space <id>", "space id, public link, or copied URL (default: the first target in .cloudtifact.json)").option(VISIBILITY_OPTION, "who can open it: private (only members of its workspace; members also works) or public (anyone with the link). Going public turns guest comments on; going private turns guest comments and guest writes off").option(SETTINGS[0].option, SETTINGS[0].label).option(SETTINGS[1].option, `${SETTINGS[1].label} (off keeps the database private from visitors)`).option(SETTINGS[2].option, SETTINGS[2].label).option("--link <name>", "set the public link (letters and numbers, or off to clear it)").option("--toon", "print TOON (compact, for agents)").option("--json", "print JSON").action(run(async (opts) => {
15845
15930
  const { spaceId } = await pickSpace(opts.space);
15846
15931
  const patch = settingsPatch(opts);
15847
15932
  const { client } = await getClient();
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "usecloudy",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Publish pages and docs to Cloudy as links people comment on, with every version kept and the comments handed back to your agent.",
5
5
  "license": "MIT",
6
6
  "author": "The Cloudy authors",
7
- "homepage": "https://cloudtifact.com/docs/reference/cli",
7
+ "homepage": "https://usecloudy.ai/docs/reference/cli",
8
8
  "bugs": {
9
- "url": "https://cloudtifact.com/support"
9
+ "url": "https://usecloudy.ai/support"
10
10
  },
11
11
  "keywords": [
12
12
  "usecloudy",