@sovereignfs/create 0.19.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 -88
  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 +7 -6
  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.19.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,37 +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
- // 2.8 checks a session against core (`checkEverySeconds`), which the template turns on.
326
- "@sovereignfs/sdk": "^2.8.0",
327
- "@sovereignfs/storage": "^0.1.0",
328
- "@sovereignfs/ui": "^0.101.0",
329
- next: "^16.4.6",
330
- pg: "^8.23.1",
331
- react: "^19.3.1",
332
- "react-dom": "^19.3.1"
333
- };
334
- var ENCRYPTION_DEPENDENCIES = {
335
- "@sovereignfs/sdk": "^2.5.0"
336
- };
337
- var APP_DEV_DEPENDENCIES = {
338
- // Makes the image's label and port from the manifest, and checks the manifest (`sovereign-manifest`).
339
- "@sovereignfs/manifest": "^0.3.0",
340
- "@types/node": "^24.19.2",
341
- "@types/pg": "^8.23.1",
342
- "@types/react": "^19.3.0",
343
- "@types/react-dom": "^19.3.0",
344
- typescript: "~6.0.3"
345
- };
346
- var CREATE_VERSION = package_default.version;
347
- var SHARED_WORKFLOWS_REF = "ef1ddb5f623ba702fc34c8769b4b2f98c6f61ed8";
348
-
349
538
  // src/app.ts
350
539
  var NAME = /^[a-z][a-z0-9-]{0,30}[a-z0-9]$/;
351
540
  function namesOf(dir) {
@@ -382,7 +571,15 @@ async function* walk(dir, base = dir) {
382
571
  else yield path3.relative(base, full);
383
572
  }
384
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
+ }
385
581
  function appPackageJson(names, port = DEFAULT_APP_PORT, options = {}) {
582
+ const manager = MANAGERS[options.packageManager ?? DEFAULT_PACKAGE_MANAGER];
386
583
  return `${JSON.stringify(
387
584
  {
388
585
  // Every app of the suite is named in the @sovereignfs scope. It is private, so the name claims nothing on npm.
@@ -391,19 +588,25 @@ function appPackageJson(names, port = DEFAULT_APP_PORT, options = {}) {
391
588
  private: true,
392
589
  description: `${names.title}, an app for a Sovereign instance`,
393
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 } : {},
394
593
  scripts: {
395
- // 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.
396
595
  dev: `next dev --port ${port}`,
397
596
  build: "next build",
398
597
  start: `PORT=\${PORT:-${port}} node .next/standalone/server.js`,
399
598
  typecheck: "tsc --noEmit",
400
599
  "manifest:check": "sovereign-manifest check",
401
600
  // What the pre-push hook runs: CI does not run for `develop` or a feature branch (CONTRIBUTING.md).
402
- verify: "npm run typecheck && npm run manifest:check",
601
+ verify: `${manager.run} typecheck && ${manager.run} manifest:check`,
403
602
  // Turns the versioned hooks on for whoever installs; harmless where there is no repository (the image's build).
404
- prepare: "git config core.hooksPath .githooks || true"
603
+ [manager.hookScript]: "git config core.hooksPath .githooks || true"
405
604
  },
406
- 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,
407
610
  // `@sovereignfs/create` is pinned exactly: `npm create @sovereignfs sync` and the shared workflows run this version (research 0007).
408
611
  devDependencies: { ...APP_DEV_DEPENDENCIES, "@sovereignfs/create": CREATE_VERSION },
409
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.
@@ -417,12 +620,28 @@ function appPackageJson(names, port = DEFAULT_APP_PORT, options = {}) {
417
620
  async function writeApp(target, names, port = DEFAULT_APP_PORT, options = {}) {
418
621
  await checkEmpty(target);
419
622
  const written = /* @__PURE__ */ new Set();
420
- 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
+ };
421
632
  const replace = (text2) => fill(text2, values);
422
- 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();
423
640
  for (const source of sources)
424
641
  for await (const file of walk(source)) {
642
+ if (file === SKIP_FILE) continue;
425
643
  const out = targetOf(file);
644
+ if (source === TEMPLATE && skipped.has(out.split(path3.sep).join("/"))) continue;
426
645
  const target_ = path3.join(target, out);
427
646
  await mkdir2(path3.dirname(target_), { recursive: true });
428
647
  let text2 = replace(await readFile(path3.join(source, file), "utf8"));
@@ -434,7 +653,10 @@ async function writeApp(target, names, port = DEFAULT_APP_PORT, options = {}) {
434
653
  });
435
654
  written.add(out);
436
655
  }
437
- 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
+ );
438
660
  written.add("package.json");
439
661
  return [...written].sort();
440
662
  }
@@ -442,19 +664,23 @@ async function createApp(request, io2, exec2, cwd) {
442
664
  const target = path3.resolve(cwd, request.dir);
443
665
  const names = namesOf(target);
444
666
  const port = request.port ?? DEFAULT_APP_PORT;
445
- 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
+ });
446
673
  io2.err(
447
- `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" : ""}.`
448
675
  );
449
- const step = async (label, command, args, hint) => {
450
- const done = await exec2(command, args, { cwd: target });
451
- if (done.code !== 0) {
452
- throw new CreateError(
453
- `${label} failed: ${(done.stderr || done.stdout).trim().split("\n").slice(-3).join(" ")}`,
454
- 1,
455
- hint
456
- );
457
- }
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);
458
684
  };
459
685
  await step(
460
686
  "git init",
@@ -462,13 +688,15 @@ async function createApp(request, io2, exec2, cwd) {
462
688
  ["init", "--initial-branch=main"],
463
689
  "Is git installed? Then run the rest by hand: see README.md."
464
690
  );
465
- await step(
466
- "Resolving the packages",
467
- "npm",
468
- ["install", "--package-lock-only", "--ignore-scripts", "--no-audit", "--no-fund"],
469
- `Check the network, then run npm install in ${request.dir}.`
470
- );
471
- 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], "");
472
700
  await step(
473
701
  "The first commit",
474
702
  "git",
@@ -484,9 +712,9 @@ async function createApp(request, io2, exec2, cwd) {
484
712
  io2.err(
485
713
  `Made ${names.name}, on the branch develop (CONTRIBUTING.md: main takes release pull requests). Next:
486
714
  cd ${request.dir}
487
- npm install && npm run dev (http://localhost:${port})
488
- npm run build
489
- 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} ."
490
718
  Then host it with ./sv app add ${names.name} --image <the image> in your instance. See README.md.`
491
719
  );
492
720
  }
@@ -503,10 +731,10 @@ var isPrefix = (prefix) => PREFIX.test(prefix);
503
731
  function changelogSection(text2, version) {
504
732
  const lines = text2.split("\n");
505
733
  const heading = `## [${version}]`;
506
- const start = lines.findIndex((line) => line.startsWith(heading));
734
+ const start = lines.findIndex((line2) => line2.startsWith(heading));
507
735
  if (start === -1) return void 0;
508
736
  const rest = lines.slice(start + 1);
509
- const end = rest.findIndex((line) => /^## /.test(line));
737
+ const end = rest.findIndex((line2) => /^## /.test(line2));
510
738
  const body = (end === -1 ? rest : rest.slice(0, end)).join("\n").trim();
511
739
  return body === "" ? void 0 : body;
512
740
  }
@@ -519,11 +747,11 @@ function trailerProblems(message) {
519
747
  const problems = [];
520
748
  for (const raw of message.split("\n")) {
521
749
  if (raw.startsWith("#")) continue;
522
- const line = raw.trim();
523
- if (!/^co-authored-by:/i.test(line)) continue;
524
- if (!AGENT_ADDRESSES.some((address) => line.toLowerCase().includes(address))) continue;
525
- if (!AGENT_TRAILERS.includes(line)) {
526
- 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(", ")}`);
527
755
  }
528
756
  }
529
757
  return problems;
@@ -676,11 +904,11 @@ function versionIn(file, content) {
676
904
  if (file.endsWith("Cargo.toml")) {
677
905
  for (const table of ["workspace.package", "package"]) {
678
906
  let inside = false;
679
- for (const line of content.split("\n")) {
680
- const header = /^\s*\[([^\]]+)\]\s*$/.exec(line);
907
+ for (const line2 of content.split("\n")) {
908
+ const header = /^\s*\[([^\]]+)\]\s*$/.exec(line2);
681
909
  if (header) inside = header[1] === table;
682
910
  else if (inside) {
683
- const found = /^\s*version\s*=\s*"([^"]+)"/.exec(line);
911
+ const found = /^\s*version\s*=\s*"([^"]+)"/.exec(line2);
684
912
  if (found) return found[1];
685
913
  }
686
914
  }
@@ -714,7 +942,12 @@ var MANAGED = [
714
942
  { file: "CONTRIBUTING.md", at: "app", kind: "section" },
715
943
  { file: "RELEASING.md", at: "app", kind: "section" },
716
944
  { file: "CLAUDE.md", at: "app", kind: "text" },
717
- { 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" }
718
951
  ];
719
952
  var strings2 = (value, what) => {
720
953
  if (value === void 0) return [];
@@ -752,7 +985,8 @@ async function readAppSettings(appDir) {
752
985
  tagPrefix,
753
986
  requiredChecks: own.requiredChecks === void 0 ? [...DEFAULT_REQUIRED_CHECKS] : strings2(own.requiredChecks, "requiredChecks"),
754
987
  unmanaged: strings2(own.unmanaged, "unmanaged"),
755
- port
988
+ port,
989
+ packageManager: managerOf(manifest.packageManager)
756
990
  };
757
991
  }
758
992
  var canonical = (text2) => {
@@ -778,11 +1012,23 @@ var readText = async (file) => {
778
1012
  return void 0;
779
1013
  }
780
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
+ }
781
1023
  async function syncApp(appDir, gitRoot2, options) {
782
1024
  const releases = await readReleases(gitRoot2, appDir, DEFAULT_REQUIRED_CHECKS);
783
1025
  const several = releases.file === "sovereign.json";
784
1026
  const docsDir = several ? gitRoot2 : appDir;
785
- 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);
786
1032
  const names = namesOf(path5.join(path5.sep, releases.name || path5.basename(appDir)));
787
1033
  const directory = several ? "." : path5.relative(gitRoot2, appDir) || ".";
788
1034
  const values = {
@@ -790,11 +1036,13 @@ async function syncApp(appDir, gitRoot2, options) {
790
1036
  port: settings2.port,
791
1037
  workflowsRef: SHARED_WORKFLOWS_REF,
792
1038
  directory: directory.split(path5.sep).join("/"),
793
- tagPrefix: settings2.tagPrefix
1039
+ tagPrefix: settings2.tagPrefix,
1040
+ packageManager: settings2.packageManager
794
1041
  };
795
1042
  const results = [];
796
1043
  for (const entry of MANAGED) {
797
- 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;
798
1046
  const target = path5.join(base, targetOf(entry.file));
799
1047
  const shown = path5.relative(gitRoot2, target).split(path5.sep).join("/");
800
1048
  if (releases.unmanaged.includes(shown)) {
@@ -1198,7 +1446,7 @@ async function commitsCheck(argv, ctx) {
1198
1446
  }
1199
1447
  if (refused.length > 0) {
1200
1448
  ctx.io.err(`${refused.length} commit(s) in ${range} carry a trailer that is not allowed:`);
1201
- for (const line of refused) ctx.io.err(` ${line}`);
1449
+ for (const line2 of refused) ctx.io.err(` ${line2}`);
1202
1450
  return 1;
1203
1451
  }
1204
1452
  ctx.io.out(`Every commit in ${range} has allowed trailers.`);
@@ -1219,9 +1467,9 @@ async function sync(argv, ctx) {
1219
1467
  drifted: "differs from the template",
1220
1468
  unmanaged: "kept as the app's own"
1221
1469
  }[result.state];
1222
- const line = ` ${result.path}: ${said}${result.reason ? ` (${result.reason})` : ""}`;
1223
- if (result.state === "drifted") ctx.io.err(line);
1224
- 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);
1225
1473
  }
1226
1474
  const drifted = results.filter((result) => result.state === "drifted");
1227
1475
  if (drifted.length > 0) {
@@ -1260,7 +1508,7 @@ async function settings(verb, argv, ctx) {
1260
1508
  ctx.io.err(` ${what}: not checked; this token cannot read it (an owner's apply can).`);
1261
1509
  if (verb === "apply") {
1262
1510
  const done = await apply(ctx.exec, root, repo, file, live, flags.has("prune"));
1263
- 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}`);
1264
1512
  return 0;
1265
1513
  }
1266
1514
  const found = differences(file, live);
@@ -1296,7 +1544,7 @@ var exec = (command, args, options) => new Promise((resolve) => {
1296
1544
  );
1297
1545
  });
1298
1546
  var io = {
1299
- err: (line) => process.stderr.write(`${line}
1547
+ err: (line2) => process.stderr.write(`${line2}
1300
1548
  `),
1301
1549
  interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
1302
1550
  async ask(question) {
@@ -1313,7 +1561,7 @@ async function main() {
1313
1561
  const argv = process.argv.slice(2);
1314
1562
  if (argv[0] === "app" && TOOL_COMMANDS.includes(argv[1] ?? "")) {
1315
1563
  return await runTool(argv.slice(1), {
1316
- io: { ...io, out: (line) => process.stdout.write(`${line}
1564
+ io: { ...io, out: (line2) => process.stdout.write(`${line2}
1317
1565
  `) },
1318
1566
  exec,
1319
1567
  cwd: process.cwd(),
@@ -1353,10 +1601,28 @@ async function main() {
1353
1601
  const answer = await io.ask(`Which port should it listen on? (${DEFAULT_APP_PORT})`);
1354
1602
  port = answer === "" ? DEFAULT_APP_PORT : parsePort(answer);
1355
1603
  }
1356
- 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
+ );
1357
1617
  } else {
1358
1618
  if (request.encryption)
1359
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
+ );
1360
1626
  if (request.port !== void 0)
1361
1627
  throw new CreateError(
1362
1628
  "--port is for an app.",