@sovereignfs/create 0.18.0 → 0.27.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.
Files changed (61) hide show
  1. package/README.md +5 -3
  2. package/dist/create.mjs +354 -87
  3. package/package.json +3 -2
  4. package/template/app/AGENTS.md +36 -3
  5. package/template/app/CONTRIBUTING.md +3 -3
  6. package/template/app/Dockerfile +6 -5
  7. package/template/app/README.md +64 -32
  8. package/template/app/_env.example +11 -1
  9. package/template/app/_githooks/pre-push +2 -2
  10. package/template/app/_github/workflows/ci.yml +5 -4
  11. package/template/app/_github/workflows/publish.yml +8 -6
  12. package/template/app/_gitignore +4 -0
  13. package/template/app/app/actions.ts +34 -8
  14. package/template/app/app/api/auth/[...all]/route.ts +10 -0
  15. package/template/app/app/api/files/[id]/route.ts +4 -6
  16. package/template/app/app/api/files/route.ts +8 -5
  17. package/template/app/app/api/push/subscription/route.ts +23 -0
  18. package/template/app/app/api/sign-in-salt/route.ts +9 -0
  19. package/template/app/app/api/sovereign/account-deleted/route.ts +10 -0
  20. package/template/app/app/api/sovereign/backchannel-logout/route.ts +10 -0
  21. package/template/app/app/api/sovereign/export/route.ts +10 -0
  22. package/template/app/app/notifications.tsx +42 -0
  23. package/template/app/app/page.tsx +21 -9
  24. package/template/app/app/push-actions.ts +41 -0
  25. package/template/app/app/security/actions.ts +45 -0
  26. package/template/app/app/security/page.tsx +33 -0
  27. package/template/app/app/security/panels.tsx +50 -0
  28. package/template/app/app/sign-in/page.tsx +49 -0
  29. package/template/app/app/sign-in/panel.tsx +71 -0
  30. package/template/app/app/sign-out.tsx +19 -0
  31. package/template/app/app/sign-up/page.tsx +39 -0
  32. package/template/app/app/sign-up/panel.tsx +54 -0
  33. package/template/app/app/sw.js/route.ts +10 -2
  34. package/template/app/app/ui.tsx +13 -1
  35. package/template/app/compose.yml +3 -2
  36. package/template/app/instrumentation.ts +9 -1
  37. package/template/app/lib/account.ts +6 -0
  38. package/template/app/lib/crypto.ts +16 -9
  39. package/template/app/lib/csp.ts +5 -3
  40. package/template/app/lib/notices.ts +63 -0
  41. package/template/app/lib/push.ts +227 -0
  42. package/template/app/lib/session.ts +40 -0
  43. package/template/app/lib/sign-in-client.ts +22 -0
  44. package/template/app/lib/sign-in.ts +113 -0
  45. package/template/app/lib/sovereign.ts +12 -3
  46. package/template/app/migrations/002_push.sql +24 -0
  47. package/template/app/sovereign.manifest.json +11 -8
  48. package/template/encryption/_env.example +27 -0
  49. package/template/encryption/_skip +18 -0
  50. package/template/encryption/app/api/files/[id]/route.ts +45 -0
  51. package/template/encryption/app/api/files/route.ts +43 -0
  52. package/template/{app → encryption}/app/auth/[action]/route.ts +2 -1
  53. package/template/encryption/app/page.tsx +7 -2
  54. package/template/encryption/app/sign-out.tsx +21 -0
  55. package/template/encryption/app/ui.tsx +1 -0
  56. package/template/encryption/instrumentation.ts +12 -0
  57. package/template/encryption/lib/account.ts +6 -0
  58. package/template/encryption/lib/auth.ts +36 -0
  59. package/template/encryption/sovereign.manifest.json +4 -3
  60. package/template/pm/yarn/_yarnrc.yml +3 -0
  61. package/template/app/lib/auth.ts +0 -18
package/dist/create.mjs CHANGED
@@ -7,7 +7,7 @@ import { createInterface } from "readline/promises";
7
7
  // package.json
8
8
  var package_default = {
9
9
  name: "@sovereignfs/create",
10
- version: "0.18.0",
10
+ version: "0.27.0",
11
11
  type: "module",
12
12
  description: "npm create @sovereignfs: makes an instance repository, pinned to the toolkit (sv) of the same version.",
13
13
  license: "AGPL-3.0-or-later",
@@ -35,6 +35,7 @@ var package_default = {
35
35
  typecheck: "tsc --noEmit"
36
36
  },
37
37
  devDependencies: {
38
+ "@sovereignfs/push": "workspace:*",
38
39
  "@sovereignfs/pwa": "workspace:*",
39
40
  "@sovereignfs/tsconfig": "workspace:*",
40
41
  "@types/node": "catalog:",
@@ -48,6 +49,7 @@ var package_default = {
48
49
  };
49
50
 
50
51
  // src/app.ts
52
+ import { existsSync } from "fs";
51
53
  import { mkdir as mkdir2, readFile, readdir as readdir2, writeFile as writeFile2 } from "fs/promises";
52
54
  import path3 from "path";
53
55
 
@@ -55,6 +57,110 @@ import path3 from "path";
55
57
  import { chmod, mkdir, readdir, writeFile } from "fs/promises";
56
58
  import path from "path";
57
59
 
60
+ // src/versions.ts
61
+ var APP_DEPENDENCIES = {
62
+ // `@sovereignfs/ui` is one bundle that imports these two, which it lists as optional peers: an app has to have them for the bundle to load.
63
+ "@dnd-kit/core": "^6.3.1",
64
+ "@dnd-kit/sortable": "^10.0.0",
65
+ // The sign-in: the package's preset, pages' flows and core as a way in, on better-auth at the one version the package names.
66
+ "@sovereignfs/auth": "^0.4.0",
67
+ "@sovereignfs/config": "^0.1.0",
68
+ // 0.2 has the worker's push handlers and `usePush`, which the template's notifications use.
69
+ "@sovereignfs/pwa": "^0.2.0",
70
+ // Web Push for the app's server: the key, the store's shape, the outbox and the subscription route.
71
+ "@sovereignfs/push": "^0.2.0",
72
+ // 2.11 answers core's export request (`handleExportRequest`), which the template mounts; 2.10 has the typed `User` the package's
73
+ // `userOf` gives, on 2.9's sign-in for a session the app keeps (`finishSignIn`).
74
+ "@sovereignfs/sdk": "^2.11.0",
75
+ "@sovereignfs/storage": "^0.1.0",
76
+ // 0.104 has `PushControl`.
77
+ "@sovereignfs/ui": "^0.104.0",
78
+ "better-auth": "1.7.18",
79
+ next: "^16.4.6",
80
+ pg: "^8.23.1",
81
+ react: "^19.3.1",
82
+ "react-dom": "^19.3.1"
83
+ };
84
+ var ENCRYPTION_DEPENDENCIES = {
85
+ "@sovereignfs/sdk": "^2.11.0"
86
+ };
87
+ var ENCRYPTION_LEAVES_OUT = ["@sovereignfs/auth", "better-auth"];
88
+ var APP_DEV_DEPENDENCIES = {
89
+ // Makes the image's label and port from the manifest, and checks the manifest (`sovereign-manifest`).
90
+ "@sovereignfs/manifest": "^0.4.0",
91
+ "@types/node": "^24.19.2",
92
+ "@types/pg": "^8.23.1",
93
+ "@types/react": "^19.3.0",
94
+ "@types/react-dom": "^19.3.0",
95
+ typescript: "~6.0.3"
96
+ };
97
+ var CREATE_VERSION = package_default.version;
98
+ var SHARED_WORKFLOWS_REF = "ef1ddb5f623ba702fc34c8769b4b2f98c6f61ed8";
99
+ var PNPM_VERSION = "11.28.9";
100
+ var YARN_VERSION = "4.18.1";
101
+
102
+ // src/package-manager.ts
103
+ var PACKAGE_MANAGERS = ["pnpm", "npm", "yarn"];
104
+ var DEFAULT_PACKAGE_MANAGER = "pnpm";
105
+ var MANAGERS = {
106
+ pnpm: {
107
+ pin: `pnpm@${PNPM_VERSION}`,
108
+ lockfile: "pnpm-lock.yaml",
109
+ installFiles: ["pnpm-lock.yaml"],
110
+ install: "pnpm install",
111
+ ciInstall: "pnpm install --frozen-lockfile --ignore-scripts",
112
+ lockfileOnly: ["pnpm", "install", "--lockfile-only", "--ignore-scripts"],
113
+ run: "pnpm run",
114
+ exec: "pnpm exec",
115
+ hookScript: "prepare",
116
+ corepack: true
117
+ },
118
+ npm: {
119
+ pin: void 0,
120
+ lockfile: "package-lock.json",
121
+ installFiles: ["package-lock.json"],
122
+ install: "npm install",
123
+ ciInstall: "npm ci --ignore-scripts --no-audit --no-fund",
124
+ lockfileOnly: [
125
+ "npm",
126
+ "install",
127
+ "--package-lock-only",
128
+ "--ignore-scripts",
129
+ "--no-audit",
130
+ "--no-fund"
131
+ ],
132
+ run: "npm run",
133
+ exec: "npx",
134
+ hookScript: "prepare",
135
+ corepack: false
136
+ },
137
+ yarn: {
138
+ pin: `yarn@${YARN_VERSION}`,
139
+ lockfile: "yarn.lock",
140
+ installFiles: ["yarn.lock", ".yarnrc.yml"],
141
+ install: "yarn install",
142
+ ciInstall: "yarn install --immutable --mode=skip-build",
143
+ lockfileOnly: ["yarn", "install", "--mode=update-lockfile"],
144
+ run: "yarn run",
145
+ exec: "yarn exec",
146
+ hookScript: "postinstall",
147
+ corepack: true
148
+ }
149
+ };
150
+ function parsePackageManager(value) {
151
+ if (PACKAGE_MANAGERS.includes(value)) return value;
152
+ throw new CreateError(
153
+ `${value || "(nothing)"} is not a package manager an app can be made with.`,
154
+ 2,
155
+ `Use one of ${PACKAGE_MANAGERS.join(", ")} (${DEFAULT_PACKAGE_MANAGER} when none is named).`
156
+ );
157
+ }
158
+ function managerOf(field) {
159
+ if (typeof field !== "string" || field === "") return "npm";
160
+ const name = field.split("@")[0] ?? "";
161
+ return PACKAGE_MANAGERS.includes(name) ? name : "npm";
162
+ }
163
+
58
164
  // src/templates.ts
59
165
  var LAUNCHER = `#!/bin/sh
60
166
  # Runs the toolkit this repository pins (@sovereignfs/cli in package.json), and nothing else.
@@ -125,6 +231,84 @@ function packageJson(name, cliVersion) {
125
231
  )}
126
232
  `;
127
233
  }
234
+ function agentsGuide(name) {
235
+ return `# AGENTS.md
236
+
237
+ Guidance for an AI agent looking after **${name}**, a [Sovereign](https://github.com/sovereignfs/sovereign) instance, when its operator
238
+ asks one to (Claude Code reads it through \`CLAUDE.md\`). The operator stays responsible for the instance: an agent prepares and explains,
239
+ and changes the server only when asked, each time. The last section is the operator's own.
240
+
241
+ ## What this repository is
242
+
243
+ Everything that decides what runs is here; everything the server makes for itself (databases, generated secrets, its own age key) is on
244
+ the server and in its backups.
245
+
246
+ | File | What it is | How it changes |
247
+ | -------------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------- |
248
+ | \`suite.yml\` | What the operator chose: the domain, the server, core's version, the apps | \`./sv\` commands, or by hand and then checked by \`./sv push\` |
249
+ | \`suite.lock\` | The image digests those choices resolved to | Only by \`./sv\`; never by hand |
250
+ | \`secrets.age.yml\` | Secrets the operator entered, encrypted to the recipients in \`suite.yml\` | Only by \`./sv secret \u2026\` |
251
+ | \`package.json\`, lock | The toolkit this repository pins (\`@sovereignfs/cli\`) | \`./sv upgrade\` |
252
+ | \`overrides/\` | Additions to what the toolkit renders | By hand, rarely |
253
+ | \`.github/workflows/\` | The deployment workflow, when the instance deploys from GitHub | \`./sv setup\` |
254
+ | \`sv\` | The launcher: runs the pinned toolkit and nothing else | Never |
255
+
256
+ \`./sv push\` commits these files, \`README.md\`, \`.gitignore\` and this guide, and no others. The reference for every command is
257
+ [the operator toolkit's specification](https://github.com/sovereignfs/sovereign/blob/main/docs/specs/operator-cli.md); how to run an
258
+ instance is [Operating](https://github.com/sovereignfs/sovereign/blob/main/docs/operating.md).
259
+
260
+ ## How a change is made
261
+
262
+ 1. **Look first.** \`./sv status\` (what runs against what the repository says), \`./sv doctor\` (DNS, ports, certificates, versions),
263
+ \`./sv logs [NAME]\`, \`git log\` and \`git diff\`.
264
+ 2. **Change the repository** with the command for it (\`./sv app add\`, \`./sv app update\`, \`./sv database set\`, \`./sv upgrade\`, \u2026), which
265
+ checks what it writes. Show the operator the diff and say what it will do on the server.
266
+ 3. **Push and deploy only when the operator says so:** \`./sv push -m "why"\` checks the files, commits them and pushes; \`./sv deploy\`
267
+ applies the pushed commit on the server, backing up first when a version changes.
268
+ 4. **Check it worked:** \`./sv status\` and \`./sv doctor\` again, and the logs of what changed. If it did not, say so, and offer
269
+ \`./sv rollback\`, which returns the server to the release before.
270
+
271
+ Every command is run as \`./sv\`, from this repository. Never reach the server around it (\`ssh\`, \`docker\`, \`docker compose\` on the
272
+ server, editing its files): what is not in this repository is undone by the next deployment, and is in no backup's record.
273
+
274
+ ## What an agent may do
275
+
276
+ - **On its own:** read anything here, and run what only reads: \`./sv status\`, \`./sv doctor\`, \`./sv logs\`, \`./sv app list\`,
277
+ \`./sv database\`, \`./sv secret list\` (names, never values), \`./sv backups\`, \`./sv rollback --list\`.
278
+ - **Prepared, then shown:** commands that change only this repository: \`./sv app add\`, \`./sv app update\`, \`./sv app remove\` (without
279
+ \`--purge\`), \`./sv app upgrade\`, \`./sv database set\`, \`./sv upgrade\`, and edits to \`suite.yml\`. Nothing reaches the server until it is
280
+ pushed and deployed.
281
+ - **Only when the operator asks, for that one time:** \`./sv push\` (it publishes the commit), \`./sv deploy\`, \`./sv rollback\`,
282
+ \`./sv backup\`, \`./sv secret rotate\`, \`./sv server bootstrap\`, \`./sv setup\`, \`./sv key recovery\`. An earlier yes is not a yes for
283
+ the next one.
284
+ - **Never, even when asked; the operator runs these themselves:**
285
+ - anything that shows or handles a secret's value: \`./sv app show --secret\`, \`./sv secret set\` (the operator types the value into
286
+ its hidden prompt), \`./sv backup --unencrypted\`, and reading \`~/.config/sovereign/age.key\` or any other age key;
287
+ - anything that destroys data: \`./sv app remove --purge\`, \`./sv restore\`;
288
+ - \`./sv seed\`, whose answer holds passwords;
289
+ - writing \`suite.lock\` or \`secrets.age.yml\` by hand, putting a secret in \`suite.yml\`, or committing a key, an \`.env\` file or a backup.
290
+
291
+ When a command refuses, read what it says and the hint it gives; do not work around it. A \`production\` instance (\`environment\` in
292
+ \`suite.yml\`) has people's accounts and data on it: say so before anything that reaches its server.
293
+
294
+ ## Commits
295
+
296
+ \`./sv push\` makes the commit. Its message says why, not just what (\`-m "Move Tusk to 0.4.0 for the shared calendar"\`). An agent's
297
+ commit ends with its own model-agnostic trailer, such as \`Co-Authored-By: Claude Code <noreply@anthropic.com>\`. Never rewrite what has
298
+ been pushed: the server deploys from it.
299
+
300
+ ## Rules of this instance
301
+
302
+ Say here what is particular to this instance: who uses it, when it may be changed, who to tell, what must never be touched.
303
+ `;
304
+ }
305
+ var CLAUDE_GUIDE = `# CLAUDE.md
306
+
307
+ The guidance for an agent looking after this instance is in [AGENTS.md](AGENTS.md), the one copy every agent reads; Claude Code loads it
308
+ through the import below.
309
+
310
+ @AGENTS.md
311
+ `;
128
312
 
129
313
  // src/create.ts
130
314
  var CreateError = class extends Error {
@@ -154,6 +338,7 @@ function readRequest(argv, env) {
154
338
  let remote;
155
339
  let port;
156
340
  let encryption = false;
341
+ let packageManager;
157
342
  const words = [];
158
343
  for (let i = 0; i < argv.length; i += 1) {
159
344
  const word = argv[i];
@@ -164,11 +349,14 @@ function readRequest(argv, env) {
164
349
  else if (word === "--port") port = argv[++i] ?? "";
165
350
  else if (word.startsWith("--port=")) port = word.slice("--port=".length);
166
351
  else if (word === "--encryption") encryption = true;
352
+ else if (word === "--package-manager") packageManager = argv[++i] ?? "";
353
+ else if (word.startsWith("--package-manager="))
354
+ packageManager = word.slice("--package-manager=".length);
167
355
  else if (word.startsWith("--"))
168
356
  throw new CreateError(
169
357
  `There is no option ${word}.`,
170
358
  2,
171
- "Use: npm create @sovereignfs instance <folder> [--remote URL], or app <folder> [--port N] [--encryption]"
359
+ "Use: npm create @sovereignfs instance <folder> [--remote URL], or app <folder> [--port N] [--encryption] [--package-manager pnpm|npm|yarn]"
172
360
  );
173
361
  else words.push(word);
174
362
  }
@@ -188,12 +376,14 @@ function readRequest(argv, env) {
188
376
  port ??= env.npm_config_port === void 0 || env.npm_config_port === "" ? void 0 : env.npm_config_port;
189
377
  const flag = env.npm_config_encryption;
190
378
  if (flag !== void 0 && flag !== "" && flag !== "false") encryption = true;
379
+ packageManager ??= env.npm_config_package_manager === void 0 || env.npm_config_package_manager === "" ? void 0 : env.npm_config_package_manager;
191
380
  return {
192
381
  kind,
193
382
  dir: words[0],
194
383
  remote,
195
384
  port: port === void 0 ? void 0 : parsePort(port),
196
- encryption
385
+ encryption,
386
+ packageManager: packageManager === void 0 ? void 0 : parsePackageManager(packageManager)
197
387
  };
198
388
  }
199
389
  async function checkEmpty(dir) {
@@ -219,6 +409,8 @@ async function createInstance(request, io2, exec2, cwd) {
219
409
  await chmod(path.join(target, "sv"), 493);
220
410
  await writeFile(path.join(target, ".gitignore"), GITIGNORE);
221
411
  await writeFile(path.join(target, "README.md"), readme(name));
412
+ await writeFile(path.join(target, "AGENTS.md"), agentsGuide(name));
413
+ await writeFile(path.join(target, "CLAUDE.md"), CLAUDE_GUIDE);
222
414
  io2.err(`Wrote the files of ${name}.`);
223
415
  const step = async (label, command, args, hint) => {
224
416
  const done = await exec2(command, args, { cwd: target });
@@ -259,7 +451,17 @@ async function createInstance(request, io2, exec2, cwd) {
259
451
  await step(
260
452
  "git add",
261
453
  "git",
262
- ["add", "--", "package.json", "package-lock.json", "sv", ".gitignore", "README.md"],
454
+ [
455
+ "add",
456
+ "--",
457
+ "package.json",
458
+ "package-lock.json",
459
+ "sv",
460
+ ".gitignore",
461
+ "README.md",
462
+ "AGENTS.md",
463
+ "CLAUDE.md"
464
+ ],
263
465
  ""
264
466
  );
265
467
  await step(
@@ -280,6 +482,7 @@ var TEMPLATE = fileURLToPath(new URL("../template/app", import.meta.url));
280
482
  var ENCRYPTION_TEMPLATE = fileURLToPath(
281
483
  new URL("../template/encryption", import.meta.url)
282
484
  );
485
+ var managerTemplate = (manager) => fileURLToPath(new URL(`../template/pm/${manager}`, import.meta.url));
283
486
  var RENAMED = {
284
487
  _gitignore: ".gitignore",
285
488
  _dockerignore: ".dockerignore",
@@ -288,12 +491,29 @@ var RENAMED = {
288
491
  "_tsconfig.json": "tsconfig.json",
289
492
  _github: ".github",
290
493
  // Hooks are versioned here and turned on by the `prepare` script (CONTRIBUTING.md).
291
- _githooks: ".githooks"
494
+ _githooks: ".githooks",
495
+ "_yarnrc.yml": ".yarnrc.yml"
292
496
  };
293
497
  var targetOf = (file) => path2.join(...file.split(/[\\/]/).map((part) => RENAMED[part] ?? part));
498
+ var line = (text2, placeholder, value) => text2.replace(
499
+ new RegExp(`^([ \\t]*)# ${placeholder}\\n`, "gm"),
500
+ (_, indent) => value === void 0 ? "" : `${indent}${value}
501
+ `
502
+ );
294
503
  function fill(text2, values) {
295
504
  const { names } = values;
296
- return text2.replaceAll("__PREFIX_LOWER__", names.prefix.toLowerCase()).replaceAll("__PREFIX__", names.prefix).replaceAll("__NAME__", names.name).replaceAll("__TITLE__", names.title).replaceAll("**TITLE**", names.title).replaceAll("__PORT__", String(values.port)).replaceAll("__WORKFLOWS_REF__", values.workflowsRef).replaceAll("__DIRECTORY__", values.directory).replaceAll("__TAG_PREFIX__", values.tagPrefix);
505
+ const manager = MANAGERS[values.packageManager];
506
+ let lines = line(
507
+ text2,
508
+ "__COREPACK_STEP__",
509
+ manager.corepack ? "- run: corepack enable" : void 0
510
+ );
511
+ lines = line(
512
+ lines,
513
+ "__COREPACK__",
514
+ manager.corepack ? "ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0\nRUN corepack enable" : void 0
515
+ );
516
+ return lines.replaceAll("__PREFIX_LOWER__", names.prefix.toLowerCase()).replaceAll("__PREFIX__", names.prefix).replaceAll("__NAME__", names.name).replaceAll("__TITLE__", names.title).replaceAll("**TITLE**", names.title).replaceAll("__PORT__", String(values.port)).replaceAll("__WORKFLOWS_REF__", values.workflowsRef).replaceAll("__DIRECTORY__", values.directory).replaceAll("__TAG_PREFIX__", values.tagPrefix).replaceAll("__CI_INSTALL__", manager.ciInstall).replaceAll("__INSTALL__", manager.install).replaceAll("__RUN__", manager.run).replaceAll("__EXEC__", manager.exec).replaceAll("__INSTALL_FILES__", ["package.json", ...manager.installFiles].join(" ")).replaceAll("__LOCKFILE__", manager.lockfile);
297
517
  }
298
518
 
299
519
  // src/commands.ts
@@ -315,36 +535,6 @@ function repositorySettings(text2, requiredChecks) {
315
535
  `;
316
536
  }
317
537
 
318
- // src/versions.ts
319
- var APP_DEPENDENCIES = {
320
- // `@sovereignfs/ui` is one bundle that imports these two, which it lists as optional peers: an app has to have them for the bundle to load.
321
- "@dnd-kit/core": "^6.3.1",
322
- "@dnd-kit/sortable": "^10.0.0",
323
- "@sovereignfs/config": "^0.1.0",
324
- "@sovereignfs/pwa": "^0.1.0",
325
- "@sovereignfs/sdk": "^2.0.0",
326
- "@sovereignfs/storage": "^0.1.0",
327
- "@sovereignfs/ui": "^0.101.0",
328
- next: "^16.4.6",
329
- pg: "^8.23.1",
330
- react: "^19.3.1",
331
- "react-dom": "^19.3.1"
332
- };
333
- var ENCRYPTION_DEPENDENCIES = {
334
- "@sovereignfs/sdk": "^2.5.0"
335
- };
336
- var APP_DEV_DEPENDENCIES = {
337
- // Makes the image's label and port from the manifest, and checks the manifest (`sovereign-manifest`).
338
- "@sovereignfs/manifest": "^0.3.0",
339
- "@types/node": "^24.19.2",
340
- "@types/pg": "^8.23.1",
341
- "@types/react": "^19.3.0",
342
- "@types/react-dom": "^19.3.0",
343
- typescript: "~6.0.3"
344
- };
345
- var CREATE_VERSION = package_default.version;
346
- var SHARED_WORKFLOWS_REF = "ef1ddb5f623ba702fc34c8769b4b2f98c6f61ed8";
347
-
348
538
  // src/app.ts
349
539
  var NAME = /^[a-z][a-z0-9-]{0,30}[a-z0-9]$/;
350
540
  function namesOf(dir) {
@@ -381,7 +571,15 @@ async function* walk(dir, base = dir) {
381
571
  else yield path3.relative(base, full);
382
572
  }
383
573
  }
574
+ var SKIP_FILE = "_skip";
575
+ async function skipList(overlay) {
576
+ const text2 = await readFile(path3.join(overlay, SKIP_FILE), "utf8").catch(() => "");
577
+ return new Set(
578
+ text2.split("\n").map((line2) => line2.trim()).filter((line2) => line2 !== "" && !line2.startsWith("#"))
579
+ );
580
+ }
384
581
  function appPackageJson(names, port = DEFAULT_APP_PORT, options = {}) {
582
+ const manager = MANAGERS[options.packageManager ?? DEFAULT_PACKAGE_MANAGER];
385
583
  return `${JSON.stringify(
386
584
  {
387
585
  // Every app of the suite is named in the @sovereignfs scope. It is private, so the name claims nothing on npm.
@@ -390,19 +588,25 @@ function appPackageJson(names, port = DEFAULT_APP_PORT, options = {}) {
390
588
  private: true,
391
589
  description: `${names.title}, an app for a Sovereign instance`,
392
590
  engines: { node: ">=24.15" },
591
+ // The manager and its version, which corepack runs in the image and in CI. An app made with npm has none.
592
+ ...manager.pin ? { packageManager: manager.pin } : {},
393
593
  scripts: {
394
- // The manifest's port, so `npm run dev` and the image listen where the instance and .env.example say.
594
+ // The manifest's port, so `dev` and the image listen where the instance and .env.example say.
395
595
  dev: `next dev --port ${port}`,
396
596
  build: "next build",
397
597
  start: `PORT=\${PORT:-${port}} node .next/standalone/server.js`,
398
598
  typecheck: "tsc --noEmit",
399
599
  "manifest:check": "sovereign-manifest check",
400
600
  // What the pre-push hook runs: CI does not run for `develop` or a feature branch (CONTRIBUTING.md).
401
- verify: "npm run typecheck && npm run manifest:check",
601
+ verify: `${manager.run} typecheck && ${manager.run} manifest:check`,
402
602
  // Turns the versioned hooks on for whoever installs; harmless where there is no repository (the image's build).
403
- prepare: "git config core.hooksPath .githooks || true"
603
+ [manager.hookScript]: "git config core.hooksPath .githooks || true"
404
604
  },
405
- dependencies: options.encryption ? { ...APP_DEPENDENCIES, ...ENCRYPTION_DEPENDENCIES } : APP_DEPENDENCIES,
605
+ dependencies: options.encryption ? Object.fromEntries(
606
+ Object.entries({ ...APP_DEPENDENCIES, ...ENCRYPTION_DEPENDENCIES }).filter(
607
+ ([name]) => !ENCRYPTION_LEAVES_OUT.includes(name)
608
+ )
609
+ ) : APP_DEPENDENCIES,
406
610
  // `@sovereignfs/create` is pinned exactly: `npm create @sovereignfs sync` and the shared workflows run this version (research 0007).
407
611
  devDependencies: { ...APP_DEV_DEPENDENCIES, "@sovereignfs/create": CREATE_VERSION },
408
612
  // What the shared files need of this app: its tag prefix, the checks its main requires, and any shared file it keeps as its own.
@@ -416,12 +620,28 @@ function appPackageJson(names, port = DEFAULT_APP_PORT, options = {}) {
416
620
  async function writeApp(target, names, port = DEFAULT_APP_PORT, options = {}) {
417
621
  await checkEmpty(target);
418
622
  const written = /* @__PURE__ */ new Set();
419
- const values = { names, port, workflowsRef: SHARED_WORKFLOWS_REF, directory: ".", tagPrefix: "" };
623
+ const packageManager = options.packageManager ?? DEFAULT_PACKAGE_MANAGER;
624
+ const values = {
625
+ names,
626
+ port,
627
+ workflowsRef: SHARED_WORKFLOWS_REF,
628
+ directory: ".",
629
+ tagPrefix: "",
630
+ packageManager
631
+ };
420
632
  const replace = (text2) => fill(text2, values);
421
- const sources = [TEMPLATE, ...options.encryption ? [ENCRYPTION_TEMPLATE] : []];
633
+ const managerFiles = managerTemplate(packageManager);
634
+ const sources = [
635
+ TEMPLATE,
636
+ ...options.encryption ? [ENCRYPTION_TEMPLATE] : [],
637
+ ...existsSync(managerFiles) ? [managerFiles] : []
638
+ ];
639
+ const skipped = options.encryption ? await skipList(ENCRYPTION_TEMPLATE) : /* @__PURE__ */ new Set();
422
640
  for (const source of sources)
423
641
  for await (const file of walk(source)) {
642
+ if (file === SKIP_FILE) continue;
424
643
  const out = targetOf(file);
644
+ if (source === TEMPLATE && skipped.has(out.split(path3.sep).join("/"))) continue;
425
645
  const target_ = path3.join(target, out);
426
646
  await mkdir2(path3.dirname(target_), { recursive: true });
427
647
  let text2 = replace(await readFile(path3.join(source, file), "utf8"));
@@ -433,7 +653,10 @@ async function writeApp(target, names, port = DEFAULT_APP_PORT, options = {}) {
433
653
  });
434
654
  written.add(out);
435
655
  }
436
- await writeFile2(path3.join(target, "package.json"), appPackageJson(names, port, options));
656
+ await writeFile2(
657
+ path3.join(target, "package.json"),
658
+ appPackageJson(names, port, { ...options, packageManager })
659
+ );
437
660
  written.add("package.json");
438
661
  return [...written].sort();
439
662
  }
@@ -441,19 +664,23 @@ async function createApp(request, io2, exec2, cwd) {
441
664
  const target = path3.resolve(cwd, request.dir);
442
665
  const names = namesOf(target);
443
666
  const port = request.port ?? DEFAULT_APP_PORT;
444
- const written = await writeApp(target, names, port, { encryption: request.encryption ?? false });
667
+ const packageManager = request.packageManager ?? DEFAULT_PACKAGE_MANAGER;
668
+ const manager = MANAGERS[packageManager];
669
+ const written = await writeApp(target, names, port, {
670
+ encryption: request.encryption ?? false,
671
+ packageManager
672
+ });
445
673
  io2.err(
446
- `Wrote the files of ${names.name}, on port ${port}${request.encryption ? ", with its notes encrypted" : ""}.`
674
+ `Wrote the files of ${names.name}, on port ${port}, with ${packageManager}${request.encryption ? ", with its notes encrypted" : ""}.`
447
675
  );
448
- const step = async (label, command, args, hint) => {
449
- const done = await exec2(command, args, { cwd: target });
450
- if (done.code !== 0) {
451
- throw new CreateError(
452
- `${label} failed: ${(done.stderr || done.stdout).trim().split("\n").slice(-3).join(" ")}`,
453
- 1,
454
- hint
455
- );
456
- }
676
+ const failed = (label, done, hint) => new CreateError(
677
+ `${label} failed: ${(done.stderr || done.stdout).trim().split("\n").slice(-3).join(" ")}`,
678
+ 1,
679
+ hint
680
+ );
681
+ const step = async (label, command2, args2, hint) => {
682
+ const done = await exec2(command2, args2, { cwd: target });
683
+ if (done.code !== 0) throw failed(label, done, hint);
457
684
  };
458
685
  await step(
459
686
  "git init",
@@ -461,13 +688,15 @@ async function createApp(request, io2, exec2, cwd) {
461
688
  ["init", "--initial-branch=main"],
462
689
  "Is git installed? Then run the rest by hand: see README.md."
463
690
  );
464
- await step(
465
- "Resolving the packages",
466
- "npm",
467
- ["install", "--package-lock-only", "--ignore-scripts", "--no-audit", "--no-fund"],
468
- `Check the network, then run npm install in ${request.dir}.`
469
- );
470
- await step("git add", "git", ["add", "--", ...written, "package-lock.json"], "");
691
+ const [command, ...args] = manager.lockfileOnly;
692
+ const resolving = `Check the network, and that ${packageManager} is installed (${manager.corepack ? `corepack enable ${packageManager}, or ` : ""}choose another with --package-manager); then run ${manager.install} in ${request.dir}.`;
693
+ const direct = await exec2(command, args, { cwd: target });
694
+ if (direct.code !== 0) {
695
+ if (!(manager.corepack && /ENOENT/.test(direct.stderr)))
696
+ throw failed("Resolving the packages", direct, resolving);
697
+ await step("Resolving the packages", "corepack", [command, ...args], resolving);
698
+ }
699
+ await step("git add", "git", ["add", "--", ...written, manager.lockfile], "");
471
700
  await step(
472
701
  "The first commit",
473
702
  "git",
@@ -483,9 +712,9 @@ async function createApp(request, io2, exec2, cwd) {
483
712
  io2.err(
484
713
  `Made ${names.name}, on the branch develop (CONTRIBUTING.md: main takes release pull requests). Next:
485
714
  cd ${request.dir}
486
- npm install && npm run dev (http://localhost:${port})
487
- npm run build
488
- docker build -t ${names.name} .
715
+ ${manager.install} && ${manager.run} dev (http://localhost:${port})
716
+ ${manager.run} build
717
+ eval "docker build $(${manager.exec} sovereign-manifest docker-args) -t ${names.name} ."
489
718
  Then host it with ./sv app add ${names.name} --image <the image> in your instance. See README.md.`
490
719
  );
491
720
  }
@@ -502,10 +731,10 @@ var isPrefix = (prefix) => PREFIX.test(prefix);
502
731
  function changelogSection(text2, version) {
503
732
  const lines = text2.split("\n");
504
733
  const heading = `## [${version}]`;
505
- const start = lines.findIndex((line) => line.startsWith(heading));
734
+ const start = lines.findIndex((line2) => line2.startsWith(heading));
506
735
  if (start === -1) return void 0;
507
736
  const rest = lines.slice(start + 1);
508
- const end = rest.findIndex((line) => /^## /.test(line));
737
+ const end = rest.findIndex((line2) => /^## /.test(line2));
509
738
  const body = (end === -1 ? rest : rest.slice(0, end)).join("\n").trim();
510
739
  return body === "" ? void 0 : body;
511
740
  }
@@ -518,11 +747,11 @@ function trailerProblems(message) {
518
747
  const problems = [];
519
748
  for (const raw of message.split("\n")) {
520
749
  if (raw.startsWith("#")) continue;
521
- const line = raw.trim();
522
- if (!/^co-authored-by:/i.test(line)) continue;
523
- if (!AGENT_ADDRESSES.some((address) => line.toLowerCase().includes(address))) continue;
524
- if (!AGENT_TRAILERS.includes(line)) {
525
- problems.push(`"${line}" is not an agent trailer; use one of: ${AGENT_TRAILERS.join(", ")}`);
750
+ const line2 = raw.trim();
751
+ if (!/^co-authored-by:/i.test(line2)) continue;
752
+ if (!AGENT_ADDRESSES.some((address) => line2.toLowerCase().includes(address))) continue;
753
+ if (!AGENT_TRAILERS.includes(line2)) {
754
+ problems.push(`"${line2}" is not an agent trailer; use one of: ${AGENT_TRAILERS.join(", ")}`);
526
755
  }
527
756
  }
528
757
  return problems;
@@ -675,11 +904,11 @@ function versionIn(file, content) {
675
904
  if (file.endsWith("Cargo.toml")) {
676
905
  for (const table of ["workspace.package", "package"]) {
677
906
  let inside = false;
678
- for (const line of content.split("\n")) {
679
- const header = /^\s*\[([^\]]+)\]\s*$/.exec(line);
907
+ for (const line2 of content.split("\n")) {
908
+ const header = /^\s*\[([^\]]+)\]\s*$/.exec(line2);
680
909
  if (header) inside = header[1] === table;
681
910
  else if (inside) {
682
- const found = /^\s*version\s*=\s*"([^"]+)"/.exec(line);
911
+ const found = /^\s*version\s*=\s*"([^"]+)"/.exec(line2);
683
912
  if (found) return found[1];
684
913
  }
685
914
  }
@@ -713,7 +942,12 @@ var MANAGED = [
713
942
  { file: "CONTRIBUTING.md", at: "app", kind: "section" },
714
943
  { file: "RELEASING.md", at: "app", kind: "section" },
715
944
  { file: "CLAUDE.md", at: "app", kind: "text" },
716
- { file: "AGENTS.md", at: "app", kind: "section" }
945
+ { file: "AGENTS.md", at: "app", kind: "section" },
946
+ // The image and running it with Docker: the same in every app, filled with its name, port and package manager. An app that needs its own
947
+ // (another service, a native dependency) lists the file under `sovereign.unmanaged`.
948
+ { file: "Dockerfile", at: "image", kind: "text" },
949
+ { file: "_dockerignore", at: "image", kind: "text" },
950
+ { file: "compose.yml", at: "image", kind: "text" }
717
951
  ];
718
952
  var strings2 = (value, what) => {
719
953
  if (value === void 0) return [];
@@ -751,7 +985,8 @@ async function readAppSettings(appDir) {
751
985
  tagPrefix,
752
986
  requiredChecks: own.requiredChecks === void 0 ? [...DEFAULT_REQUIRED_CHECKS] : strings2(own.requiredChecks, "requiredChecks"),
753
987
  unmanaged: strings2(own.unmanaged, "unmanaged"),
754
- port
988
+ port,
989
+ packageManager: managerOf(manifest.packageManager)
755
990
  };
756
991
  }
757
992
  var canonical = (text2) => {
@@ -777,11 +1012,23 @@ var readText = async (file) => {
777
1012
  return void 0;
778
1013
  }
779
1014
  };
1015
+ async function rootManager(gitRoot2) {
1016
+ const text2 = await readText(path5.join(gitRoot2, "package.json"));
1017
+ try {
1018
+ return managerOf(text2 === void 0 ? void 0 : JSON.parse(text2).packageManager);
1019
+ } catch {
1020
+ return "npm";
1021
+ }
1022
+ }
780
1023
  async function syncApp(appDir, gitRoot2, options) {
781
1024
  const releases = await readReleases(gitRoot2, appDir, DEFAULT_REQUIRED_CHECKS);
782
1025
  const several = releases.file === "sovereign.json";
783
1026
  const docsDir = several ? gitRoot2 : appDir;
784
- const settings2 = several ? { port: DEFAULT_APP_PORT, tagPrefix: "" } : await readAppSettings(appDir);
1027
+ const settings2 = several ? {
1028
+ port: DEFAULT_APP_PORT,
1029
+ tagPrefix: "",
1030
+ packageManager: await rootManager(gitRoot2)
1031
+ } : await readAppSettings(appDir);
785
1032
  const names = namesOf(path5.join(path5.sep, releases.name || path5.basename(appDir)));
786
1033
  const directory = several ? "." : path5.relative(gitRoot2, appDir) || ".";
787
1034
  const values = {
@@ -789,11 +1036,13 @@ async function syncApp(appDir, gitRoot2, options) {
789
1036
  port: settings2.port,
790
1037
  workflowsRef: SHARED_WORKFLOWS_REF,
791
1038
  directory: directory.split(path5.sep).join("/"),
792
- tagPrefix: settings2.tagPrefix
1039
+ tagPrefix: settings2.tagPrefix,
1040
+ packageManager: settings2.packageManager
793
1041
  };
794
1042
  const results = [];
795
1043
  for (const entry of MANAGED) {
796
- const base = entry.at === "root" ? gitRoot2 : docsDir;
1044
+ if (several && entry.at === "image") continue;
1045
+ const base = entry.at === "root" ? gitRoot2 : entry.at === "image" ? appDir : docsDir;
797
1046
  const target = path5.join(base, targetOf(entry.file));
798
1047
  const shown = path5.relative(gitRoot2, target).split(path5.sep).join("/");
799
1048
  if (releases.unmanaged.includes(shown)) {
@@ -1197,7 +1446,7 @@ async function commitsCheck(argv, ctx) {
1197
1446
  }
1198
1447
  if (refused.length > 0) {
1199
1448
  ctx.io.err(`${refused.length} commit(s) in ${range} carry a trailer that is not allowed:`);
1200
- for (const line of refused) ctx.io.err(` ${line}`);
1449
+ for (const line2 of refused) ctx.io.err(` ${line2}`);
1201
1450
  return 1;
1202
1451
  }
1203
1452
  ctx.io.out(`Every commit in ${range} has allowed trailers.`);
@@ -1218,9 +1467,9 @@ async function sync(argv, ctx) {
1218
1467
  drifted: "differs from the template",
1219
1468
  unmanaged: "kept as the app's own"
1220
1469
  }[result.state];
1221
- const line = ` ${result.path}: ${said}${result.reason ? ` (${result.reason})` : ""}`;
1222
- if (result.state === "drifted") ctx.io.err(line);
1223
- else ctx.io.out(line);
1470
+ const line2 = ` ${result.path}: ${said}${result.reason ? ` (${result.reason})` : ""}`;
1471
+ if (result.state === "drifted") ctx.io.err(line2);
1472
+ else ctx.io.out(line2);
1224
1473
  }
1225
1474
  const drifted = results.filter((result) => result.state === "drifted");
1226
1475
  if (drifted.length > 0) {
@@ -1259,7 +1508,7 @@ async function settings(verb, argv, ctx) {
1259
1508
  ctx.io.err(` ${what}: not checked; this token cannot read it (an owner's apply can).`);
1260
1509
  if (verb === "apply") {
1261
1510
  const done = await apply(ctx.exec, root, repo, file, live, flags.has("prune"));
1262
- for (const line of done.length > 0 ? done : ["nothing to change"]) ctx.io.out(` ${line}`);
1511
+ for (const line2 of done.length > 0 ? done : ["nothing to change"]) ctx.io.out(` ${line2}`);
1263
1512
  return 0;
1264
1513
  }
1265
1514
  const found = differences(file, live);
@@ -1295,7 +1544,7 @@ var exec = (command, args, options) => new Promise((resolve) => {
1295
1544
  );
1296
1545
  });
1297
1546
  var io = {
1298
- err: (line) => process.stderr.write(`${line}
1547
+ err: (line2) => process.stderr.write(`${line2}
1299
1548
  `),
1300
1549
  interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
1301
1550
  async ask(question) {
@@ -1312,7 +1561,7 @@ async function main() {
1312
1561
  const argv = process.argv.slice(2);
1313
1562
  if (argv[0] === "app" && TOOL_COMMANDS.includes(argv[1] ?? "")) {
1314
1563
  return await runTool(argv.slice(1), {
1315
- io: { ...io, out: (line) => process.stdout.write(`${line}
1564
+ io: { ...io, out: (line2) => process.stdout.write(`${line2}
1316
1565
  `) },
1317
1566
  exec,
1318
1567
  cwd: process.cwd(),
@@ -1352,10 +1601,28 @@ async function main() {
1352
1601
  const answer = await io.ask(`Which port should it listen on? (${DEFAULT_APP_PORT})`);
1353
1602
  port = answer === "" ? DEFAULT_APP_PORT : parsePort(answer);
1354
1603
  }
1355
- await createApp({ dir, port, encryption: request.encryption }, io, exec, process.cwd());
1604
+ let { packageManager } = request;
1605
+ if (packageManager === void 0 && io.interactive) {
1606
+ const answer = await io.ask(
1607
+ `Which package manager (pnpm, npm or yarn)? (${DEFAULT_PACKAGE_MANAGER})`
1608
+ );
1609
+ packageManager = answer === "" ? DEFAULT_PACKAGE_MANAGER : parsePackageManager(answer);
1610
+ }
1611
+ await createApp(
1612
+ { dir, port, encryption: request.encryption, packageManager },
1613
+ io,
1614
+ exec,
1615
+ process.cwd()
1616
+ );
1356
1617
  } else {
1357
1618
  if (request.encryption)
1358
1619
  throw new CreateError("--encryption is for an app.", 2, "Make an app with it instead.");
1620
+ if (request.packageManager !== void 0)
1621
+ throw new CreateError(
1622
+ "--package-manager is for an app.",
1623
+ 2,
1624
+ "An instance installs its toolkit with npm, from the lockfile it is made with."
1625
+ );
1359
1626
  if (request.port !== void 0)
1360
1627
  throw new CreateError(
1361
1628
  "--port is for an app.",