@buffcore/cli 0.8.47 → 0.8.48

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 (93) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/commands/build/server-text.en.d.ts +5 -0
  3. package/dist/commands/build/server-text.en.js +5 -0
  4. package/dist/commands/build/server-text.js +5 -0
  5. package/dist/commands/build/server.d.ts +4 -0
  6. package/dist/commands/build/server.js +10 -1
  7. package/dist/commands/change-merge.d.ts +2 -2
  8. package/dist/commands/dev.d.ts +9 -2
  9. package/dist/commands/dev.js +24 -5
  10. package/dist/commands/hardening.d.ts +3 -0
  11. package/dist/commands/hardening.en.d.ts +3 -0
  12. package/dist/commands/hardening.en.js +3 -0
  13. package/dist/commands/hardening.es.d.ts +2 -0
  14. package/dist/commands/hardening.es.js +3 -0
  15. package/dist/commands/hardening.js +19 -0
  16. package/dist/commands/prototype/comp-record.d.ts +5 -0
  17. package/dist/commands/prototype/comp-record.js +22 -0
  18. package/dist/commands/server/build.d.ts +2 -1
  19. package/dist/commands/server/build.js +10 -2
  20. package/dist/commands/server/deploy-local.d.ts +3 -0
  21. package/dist/commands/server/deploy-local.js +9 -0
  22. package/dist/commands/server/deploy-plan.d.ts +5 -0
  23. package/dist/commands/server/deploy-plan.js +56 -0
  24. package/dist/commands/server/deploy-result.d.ts +7 -0
  25. package/dist/commands/server/deploy-result.js +1 -0
  26. package/dist/commands/server/deploy-script.d.ts +2 -0
  27. package/dist/commands/server/deploy-script.js +3 -2
  28. package/dist/commands/server/deploy.d.ts +9 -6
  29. package/dist/commands/server/deploy.js +39 -61
  30. package/dist/commands/server/files.d.ts +9 -1
  31. package/dist/commands/server/files.js +25 -5
  32. package/dist/commands/server/image.d.ts +4 -2
  33. package/dist/commands/server/image.js +6 -5
  34. package/dist/commands/server/setup.js +4 -0
  35. package/dist/commands/server/system-packages.d.ts +29 -0
  36. package/dist/commands/server/system-packages.js +103 -0
  37. package/dist/commands/services/compose.d.ts +1 -1
  38. package/dist/commands/services/compose.js +5 -3
  39. package/dist/commands/ui/agents-route.js +2 -0
  40. package/dist/commands/ui/approval-authority.en.d.ts +1 -0
  41. package/dist/commands/ui/approval-authority.en.js +1 -0
  42. package/dist/commands/ui/approval-authority.es.d.ts +1 -0
  43. package/dist/commands/ui/approval-authority.es.js +1 -0
  44. package/dist/commands/ui/approval-authority.js +7 -2
  45. package/dist/commands/ui/approve.js +2 -4
  46. package/dist/commands/ui/autopilot-records.d.ts +2 -0
  47. package/dist/commands/ui/autopilot-records.js +5 -0
  48. package/dist/commands/ui/brand-approval.js +5 -1
  49. package/dist/commands/ui/chat/permissions.js +1 -1
  50. package/dist/commands/ui/chat/routes.js +4 -0
  51. package/dist/commands/ui/comp-approval.d.ts +14 -2
  52. package/dist/commands/ui/comp-approval.js +45 -8
  53. package/dist/commands/ui/level-route.js +3 -0
  54. package/dist/commands/ui/merge-authority.d.ts +4 -1
  55. package/dist/commands/ui/merge-authority.en.d.ts +4 -0
  56. package/dist/commands/ui/merge-authority.en.js +5 -1
  57. package/dist/commands/ui/merge-authority.es.d.ts +4 -0
  58. package/dist/commands/ui/merge-authority.es.js +5 -1
  59. package/dist/commands/ui/merge-authority.js +6 -3
  60. package/dist/commands/ui/merge-claims.d.ts +7 -0
  61. package/dist/commands/ui/merge-claims.js +21 -0
  62. package/dist/commands/ui/merge-delegation.js +8 -3
  63. package/dist/commands/ui/merge-hold-name.d.ts +5 -0
  64. package/dist/commands/ui/merge-hold-name.js +5 -0
  65. package/dist/commands/ui/merge-hold.d.ts +6 -1
  66. package/dist/commands/ui/merge-hold.js +23 -5
  67. package/dist/commands/ui/merge-publish-host.d.ts +1 -0
  68. package/dist/commands/ui/merge-publish-host.js +2 -2
  69. package/dist/commands/ui/merge-record.d.ts +2 -0
  70. package/dist/commands/ui/merge-record.js +1 -1
  71. package/dist/commands/ui/merge-route.js +17 -1
  72. package/dist/commands/ui/merge-settle.d.ts +32 -0
  73. package/dist/commands/ui/merge-settle.js +133 -0
  74. package/dist/commands/ui/merge-state.d.ts +5 -0
  75. package/dist/commands/ui/merge-state.js +7 -1
  76. package/dist/commands/ui/merge-withdraw.d.ts +9 -0
  77. package/dist/commands/ui/merge-withdraw.js +29 -0
  78. package/dist/commands/ui/plan-files.js +5 -2
  79. package/dist/commands/ui/plan-structure.js +5 -7
  80. package/dist/commands/ui/prototype-comp-route.d.ts +12 -3
  81. package/dist/commands/ui/prototype-comp-route.js +35 -17
  82. package/dist/commands/ui/real-file.d.ts +11 -0
  83. package/dist/commands/ui/real-file.js +84 -0
  84. package/dist/commands/ui/save-route.js +4 -1
  85. package/dist/commands/ui/server.d.ts +1 -0
  86. package/dist/commands/ui/server.js +1 -0
  87. package/dist/commands/ui/studio-state.d.ts +1 -0
  88. package/dist/commands/ui/studio-versions.js +19 -3
  89. package/dist/ui/page.js +79 -79
  90. package/docs/PROTOTYPE.md +13 -0
  91. package/docs/WORKBENCH.md +30 -0
  92. package/package.json +11 -11
  93. package/skills/ape-deploy/SKILL.md +4 -2
package/CHANGELOG.md CHANGED
@@ -4,6 +4,24 @@ One section per release (a git tag). **Upgrade notes** list anything that breaks
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## v0.8.48 (2026-12-05)
8
+
9
+ - A product may set `hardening` in `buffcore.config.ts`. With `refuseDebugOptions: true` (off by default), the API and each declared Node process refuse to start when Node's debugging or dump options (`--inspect*`, `--debug-port`, the heap snapshot options, `--diagnostic-dir`, `--report-*`) reach them on the command line or in `NODE_OPTIONS`: on a server a small module imported before the entry exits 1 naming the option, with `--disable-sigusr1`, and `ape dev` and `ape server setup` refuse every one of them in the `NODE_OPTIONS` they pass on (the shell's, `.env`'s, the settings file's) before starting anything, since `--inspect-brk` and `--inspect-wait` pause Node before any code runs. A `NODE_OPTIONS` word with a quote or a backslash is refused too. The compose file `ape server setup` writes now runs the API, each declared process and container, and the `ape` tools service with `ulimits: { core: 0 }`, so a crash writes no core dump; `coreDumps: true` keeps Docker's default. The compose file records the `hardening` it was written for, and `ape deploy` refuses a server whose file differs or predates it. Development is unchanged.
10
+
11
+ **Upgrade notes** (every product): run `ape server setup` again before the next deploy: `ape deploy` refuses a server whose compose file predates `hardening`, since it lacks the core-file limit; a product that needs core files sets `hardening: { coreDumps: true }` first.
12
+
13
+ - A product can add Debian system packages to its server image: `server: { systemPackages: ['openssh-client'] }` in `buffcore.config.ts`, for programs its API starts itself. `ape deploy` and `ape build server` install them in the image's last stage before it drops to the API's user, and record the installed versions in their `--json` (`systemPackages`). A name that isn't a Debian package name is refused with a plain sentence before anything is built, and a package that can't be installed fails the build. With no list the image is the same as before.
14
+
15
+ **Upgrade:** nothing to do. A tool that compares the whole `ape deploy --json` or `ape build server --json` line should expect the new `systemPackages` key.
16
+
17
+ - A hosted studio with an approval authority can approve the look. **Approve the look** now asks the host's authority once (`kind: 'comp'`, as for brand, prototype, release and places) and records its grant in `prototype/versions/comp.json` by the studio's own approval commit; it was refused with `approval_authority_invalid` before the host was asked. An agent or an AI approver is still refused. On a hosted studio the comp read shows the look approved only when the host confirms that record (`action: 'check'`), and shows the reason when it does not. The comp's pictures, and the plan, structure, design and version files the studio reads, are read only from a regular file with one link whose real path stays inside the product's folder: a link, junction or hard link leading out, or a folder, is not read. On Linux the check is made on the opened file itself. On Windows and macOS it resolves the path again, so a process that keeps swapping a folder on the path for a link while the studio reads can still slip one file past it; keep the product folder writable only by the people and agents who work on it.
18
+
19
+ **Upgrade notes** (every product): a host whose `approval` hook decides approvals now receives `{ kind: 'comp', version: null, commit, fingerprint }` with `action: 'approve'` and `'check'`. Answer as for the other kinds, with a person's signature only (no `agent`, no `ai`); the studio writes the record itself. The `check` names the commit the record's signature holds (the one checked out when the person approved), not today's HEAD, so key grants by commit and fingerprint. A `comp` rule in `plan/approvals.md` is still refused: the look is one person's approval. A host that refuses `comp` keeps the look unapproved, as before. A comp picture, plan file, `plan/structure.md`, `design/DESIGN.md` or `prototype/versions/*.json` that is a link (or a hard link) to a place outside the product's folder is no longer read: copy the file into the folder.
20
+
21
+ - A host whose `merge` hook answers `pending` for an Autopilot change can now settle it later from its own process: `settleHostMerge(root, { change, head, claim, outcome, code? })` from `@buffcore/cli/workbench`, where `claim` is the new `HostMergeInput.claim`, a secret the host was given with that ask (the studio keeps only its hash). It is accepted only for that exact waiting Autopilot claim (change, head and claim) while the saved level is Autopilot, runs under the same hold and publication lock as `publish`, and for `merged` only when main holds that exact head; the studio's next read records the merge and runs its Snapshot as for a published claim. BuffCore chose this over settling on main alone: since 0.8.27 an Autopilot success must pass the hold, and on a hosted studio the host itself writes main, so main holding the head shows a write happened, not that it respected a person's hold. A waiting merge now shows how long it has waited. A waiting Autopilot claim (not a person's own) ends when a person withdraws it from the merge preview (`POST /api/merge/withdraw`), turns the hold on, leaves Autopilot or presses Stop on the change, unless main already holds it; so a host that never answers cannot hold Autopilot, and Autopilot asks again after its next turn. A settle of any outcome that finds `plan/agents.md` or the hold edited since the ask withdraws the claim the same way, and the merge preview offers Withdraw only on an Autopilot wait (`automatic: true` in `work.merges`). Local studios, a person's own merge and a hook that answers `merged` are unchanged.
22
+
23
+ **Upgrade notes** (hosts with a `merge` hook): a queue that merges an Autopilot change after answering `pending` keeps `HostMergeInput.claim` with the queued request and calls `settleHostMerge` once the merge lands on main (or with `outcome: 'not_merged'` and a code when it gives up). Call it with `outcome: 'check'` (writes nothing, answers `ready`) just before the final write. When a settle answers `merge_settle_unknown` (the claim was withdrawn, held, stopped, or `plan/agents.md` or the hold changed since the ask), drop the queue entry and do not write main for it; the studio asks again when the change is merged next. A change the queue merged anyway shows in Work as a merge Git holds, like one made at a terminal, with no host line, record or Snapshot. On `merge_record_failed`, call again. On `merge_publication_lock` (the studio's publication lock stayed busy), call again later. `merge_settle_invalid` and `merge_settle_unknown` are now reserved codes.
24
+
7
25
  ## v0.8.47 (2026-12-04)
8
26
 
9
27
  - On Linux and macOS, `ape prototype snapshot` reuses unchanged console scenes again: files Vite serves from outside the console's folder (`/@fs/…`) were read as paths under the working folder, so every console scene was drawn again. A worktree's snapshot also records its dev servers every few seconds while they start, so the next run stops the servers of a run killed during their cold start.
@@ -4,6 +4,11 @@ export declare const en: {
4
4
  'build.server.name': string;
5
5
  'build.server.inspect': string;
6
6
  'build.server.made': string;
7
+ 'build.server.packages': string;
8
+ 'build.server.packagesFailed': string;
9
+ 'build.server.versionsRun': string;
10
+ 'build.server.label': string;
11
+ 'build.server.versionsMissing': string;
7
12
  'build.server.flags': string;
8
13
  'build.server.platformOnly': string;
9
14
  'build.server.platform': string;
@@ -5,6 +5,11 @@ export const en = {
5
5
  'build.server.name': '{name} is not a name setup took.',
6
6
  'build.server.inspect': 'Could not read the image ID for {image}.',
7
7
  'build.server.made': 'Built {image}: {id}',
8
+ 'build.server.packages': 'buffcore.config.ts: {problems}. Nothing was built: fix server.systemPackages, then run it again.',
9
+ 'build.server.packagesFailed': 'The image did not build. It installs system packages ({names}): when the output above shows apt-get or "ape: the system package" failing, check those names in Debian. No image is made without them.',
10
+ 'build.server.versionsRun': "Could not read the system packages' versions in {image}: Docker said {cause}. Is Docker running, and is the image on this machine?",
11
+ 'build.server.label': "The image {image}'s ape.system-packages label names {name}, which is not a Debian package name: its system packages' versions were not read.",
12
+ 'build.server.versionsMissing': '{name} is not installed in {image} by that name: list each system package by its own Debian name, not one another package provides.',
8
13
  'build.server.flags': '--local, --builder and --simulator are for ape build ios only.',
9
14
  'build.server.platformOnly': '--platform is for ape build server only.',
10
15
  'build.server.platform': 'server only: the image platform (default: linux/amd64)',
@@ -6,6 +6,11 @@ const es = {
6
6
  'build.server.name': '{name} no es un nombre aceptado por setup.',
7
7
  'build.server.inspect': 'No se pudo leer el ID de la imagen {image}.',
8
8
  'build.server.made': 'Imagen creada {image}: {id}',
9
+ 'build.server.packages': 'buffcore.config.ts: {problems}. No se creó nada: corrige server.systemPackages y ejecútalo otra vez.',
10
+ 'build.server.packagesFailed': 'La imagen no se creó. Instala paquetes del sistema ({names}): si la salida de arriba muestra un fallo de apt-get o de "ape: the system package", revisa esos nombres en Debian. No se crea ninguna imagen sin ellos.',
11
+ 'build.server.versionsRun': 'No se pudieron leer las versiones de los paquetes del sistema en {image}: Docker dijo {cause}. ¿Está Docker en marcha y la imagen en esta máquina?',
12
+ 'build.server.label': 'La etiqueta ape.system-packages de la imagen {image} nombra {name}, que no es un nombre de paquete de Debian: no se leyeron las versiones de sus paquetes del sistema.',
13
+ 'build.server.versionsMissing': '{name} no está instalado en {image} con ese nombre: nombra cada paquete del sistema por su propio nombre en Debian, no por uno que otro paquete provee.',
9
14
  'build.server.flags': '--local, --builder y --simulator son solo para ape build ios.',
10
15
  'build.server.platformOnly': '--platform es solo para ape build server.',
11
16
  'build.server.platform': 'solo server: la plataforma de la imagen (predeterminada: linux/amd64)',
@@ -1,5 +1,6 @@
1
1
  import { type Local } from '../server/build.ts';
2
2
  import { type ImageReader } from '../server/image-id.ts';
3
+ import { type PackageReader } from '../server/system-packages.ts';
3
4
  import { type Runner } from './runner.ts';
4
5
  export interface ServerBuildOptions {
5
6
  platform?: string;
@@ -17,6 +18,8 @@ export interface ServerBuildResult {
17
18
  image: string;
18
19
  id: string;
19
20
  }[];
21
+ /** The system packages' installed versions in the image (`server.systemPackages`); `{}` for none. */
22
+ systemPackages: Record<string, string>;
20
23
  }
21
24
  export interface ServerBuildDeps {
22
25
  root?: string;
@@ -24,6 +27,7 @@ export interface ServerBuildDeps {
24
27
  run?: Runner;
25
28
  log?: (line: string) => void;
26
29
  readImage?: ImageReader;
30
+ readPackages?: PackageReader;
27
31
  }
28
32
  /** Only a failure after the build starts is exit 1; preparation failures are refusals (2). */
29
33
  export declare class ServerBuildFailed extends Error {
@@ -4,6 +4,7 @@ import { buildImages, local } from '../server/build.js';
4
4
  import { imagePlan, workspaceOf } from '../server/deploy.js';
5
5
  import { dockerfile } from '../server/image.js';
6
6
  import { imageIdOf } from '../server/image-id.js';
7
+ import { packageVersions, systemPackagesOf, } from '../server/system-packages.js';
7
8
  import { shell } from './runner.js';
8
9
  import { t } from './server-text.js';
9
10
  /** Only a failure after the build starts is exit 1; preparation failures are refusals (2). */
@@ -29,7 +30,13 @@ export async function buildServer(options, deps = {}) {
29
30
  const commit = here.commit(workspace);
30
31
  if (commit.changed)
31
32
  throw new Error(t('build.server.changed'));
32
- const docker = dockerfile(imagePlan(root, workspace, { name: product.name, commit: commit.sha }));
33
+ const systemPackages = systemPackagesOf(product);
34
+ const plan = imagePlan(root, workspace, {
35
+ name: product.name,
36
+ commit: commit.sha,
37
+ systemPackages,
38
+ });
39
+ const docker = dockerfile(plan);
33
40
  const info = run('docker info --format "{{.ServerVersion}}"', {
34
41
  cwd: workspace,
35
42
  capture: true,
@@ -44,6 +51,7 @@ export async function buildServer(options, deps = {}) {
44
51
  json: Boolean(options.json),
45
52
  log,
46
53
  tag: commit.sha,
54
+ packages: systemPackages,
47
55
  });
48
56
  const images = [];
49
57
  for (const image of tags)
@@ -52,6 +60,7 @@ export async function buildServer(options, deps = {}) {
52
60
  ...images[0],
53
61
  commit: commit.sha,
54
62
  containers: images.slice(1).map((image, i) => ({ name: built.names[i], ...image })),
63
+ systemPackages: await packageVersions(tags[0], systemPackages, where.platform, deps.readPackages),
55
64
  };
56
65
  }
57
66
  catch (error) {
@@ -103,11 +103,11 @@ export declare const hasMerge: (path: string, git: MergeGit) => Promise<boolean>
103
103
  * may rewrite it). Any read failure holds it.
104
104
  */
105
105
  export declare function hostLevelRefusal(root: string, refs: string[], tools: MergeTools): Promise<{
106
- reason: 'held';
107
- detail: string;
108
106
  ok: false;
109
107
  code: string;
110
108
  error: string;
109
+ reason: 'held';
110
+ detail: string;
111
111
  } | undefined>;
112
112
  /** Person-only action shared by CLI and studio. Nothing pushes or forces a branch. */
113
113
  export declare function mergeOne(root: string, change: string, tools?: MergeTools, approval?: MergeAuthority, level?: HostLevel): Promise<MergeResult>;
@@ -1,4 +1,4 @@
1
- import { type CoreEnv, type ProductConfig, type ProductProcess } from '@buffcore/config';
1
+ import { type CoreEnv, type Hardening, type ProductConfig, type ProductProcess } from '@buffcore/config';
2
2
  export { buffcorePackages, clearExpoCache } from './dev-expo-cache.ts';
3
3
  /** The Docker services file: the product's, or BuffCore's own when in the BuffCore repository. */
4
4
  export declare function composeFile(root: string): string;
@@ -40,13 +40,20 @@ export type DevEnv = Pick<CoreEnv, 'APE_API_PORT' | 'APE_API_URL' | 'APE_ADMIN_U
40
40
  */
41
41
  export declare function devProcesses(root: string, declared: readonly ProductProcess[], env: DevEnv & Pick<CoreEnv, 'APE_ENV'>,
42
42
  /** Start Expo with its cache cleared (`clearExpoCache`). */
43
- clearApp?: boolean): DevProcess[];
43
+ clearApp?: boolean,
44
+ /** The product's `hardening`: its debug options refused before anything starts. */
45
+ hardening?: Hardening): DevProcess[];
44
46
  /**
45
47
  * The admin and app are told the API's address as `APE_API_URL`. On this computer that address
46
48
  * must be the API's own port, or they would call another checkout's API (a copied `.env` where
47
49
  * only `APE_API_PORT` changed). A tunnel or network address is the developer's to name.
48
50
  */
49
51
  export declare function checkApiAddress(env: DevEnv): void;
52
+ /**
53
+ * `.env`'s settings. Node reads its NODE_OPTIONS through --env-file before any code runs, as the
54
+ * shell's, so `ape dev` refuses debugging options in either before starting anything.
55
+ */
56
+ export declare const devSettings: (root: string) => Record<string, string | undefined>;
50
57
  /**
51
58
  * `ape dev`: Docker services and the product's containers (none with `APE_DEV_SERVICES=external`),
52
59
  * then the API with hot reload, the product's other declared processes, and the admin and web app
@@ -7,6 +7,7 @@ import { devAddresses, devPorts, findRoot, loadEnv, loadProduct, uiFolder } from
7
7
  import { clearExpoCache } from './dev-expo-cache.js';
8
8
  import { watchDevOutput } from './dev-output.js';
9
9
  import { watchDevReady } from './dev-ready.js';
10
+ import { refuseDebugStart } from './hardening.js';
10
11
  import { claimBlock } from './port-claims.js';
11
12
  import { containersOf, devCompose } from './services/compose.js';
12
13
  import { runComposeUp } from './services/compose-up.js';
@@ -106,7 +107,13 @@ export function apiFolder(root) {
106
107
  */
107
108
  export function devProcesses(root, declared, env,
108
109
  /** Start Expo with its cache cleared (`clearExpoCache`). */
109
- clearApp = false) {
110
+ clearApp = false,
111
+ /** The product's `hardening`: its debug options refused before anything starts. */
112
+ hardening) {
113
+ refuseDebugStart(hardening, {
114
+ shell: process.env.NODE_OPTIONS,
115
+ '.env': devSettings(root).NODE_OPTIONS,
116
+ });
110
117
  const api = apiFolder(root);
111
118
  return [
112
119
  {
@@ -168,6 +175,14 @@ export function checkApiAddress(env) {
168
175
  throw new Error(`APE_API_URL (${env.APE_API_URL}) is not on APE_API_PORT (${env.APE_API_PORT}). Set both, or the admin and app call another API.`);
169
176
  }
170
177
  }
178
+ /**
179
+ * `.env`'s settings. Node reads its NODE_OPTIONS through --env-file before any code runs, as the
180
+ * shell's, so `ape dev` refuses debugging options in either before starting anything.
181
+ */
182
+ export const devSettings = (root) => {
183
+ const file = join(root, '.env');
184
+ return existsSync(file) ? parseEnv(readFileSync(file, 'utf8')) : {};
185
+ };
171
186
  /**
172
187
  * `ape dev`: Docker services and the product's containers (none with `APE_DEV_SERVICES=external`),
173
188
  * then the API with hot reload, the product's other declared processes, and the admin and web app
@@ -181,15 +196,19 @@ export async function dev() {
181
196
  // This product's block stays claimed, so `ape create` picks another one even while it is stopped.
182
197
  await claimBlock(root, String(Math.floor(env.APE_API_PORT / 100)));
183
198
  const product = await loadProduct(root);
184
- await startDevServices(root, product);
185
199
  const app = uiFolder(root, 'app');
186
200
  const clear = app !== undefined && clearExpoCache(root, app);
201
+ // Before the services: the product's debugging options are refused before anything starts.
202
+ refuseDebugStart(product.hardening, {
203
+ shell: process.env.NODE_OPTIONS,
204
+ '.env': devSettings(root).NODE_OPTIONS,
205
+ });
206
+ await startDevServices(root, product);
207
+ const entries = devProcesses(root, product.processes ?? [], env, clear, product.hardening);
187
208
  if (clear)
188
209
  console.log("BuffCore's packages changed: the app starts with Expo's cache cleared.");
189
- const entries = devProcesses(root, product.processes ?? [], env, clear);
210
+ const values = devSettings(root);
190
211
  console.log(`API ${env.APE_API_URL} · admin ${env.APE_ADMIN_URL} · app ${env.APE_APP_URL}`);
191
- const envFile = join(root, '.env');
192
- const values = existsSync(envFile) ? parseEnv(readFileSync(envFile, 'utf8')) : {};
193
212
  const containerNames = new Set(containersOf(product.processes).map(({ name }) => name));
194
213
  // Keep using the process record for this checkout; readers see each complete update.
195
214
  const record = { pid: process.pid, children: [] };
@@ -0,0 +1,3 @@
1
+ import { type Hardening } from '@buffcore/config';
2
+ /** Throws, naming the options, when the setting is on and a NODE_OPTIONS carries any. */
3
+ export declare function refuseDebugStart(hardening: Hardening | undefined, nodeOptions: Readonly<Record<string, string | undefined>>): void;
@@ -0,0 +1,3 @@
1
+ export declare const en: {
2
+ 'hardening.refused': string;
3
+ };
@@ -0,0 +1,3 @@
1
+ export const en = {
2
+ 'hardening.refused': "buffcore.config.ts turns hardening.refuseDebugOptions on, and {where}'s NODE_OPTIONS carries Node's debugging or dump options, or a word with a quote or a backslash ({found}): Node reads it before any code runs, so nothing was started. Remove them and run this again.",
3
+ };
@@ -0,0 +1,2 @@
1
+ import type { en } from './hardening.en.ts';
2
+ export declare const es: typeof en;
@@ -0,0 +1,3 @@
1
+ export const es = {
2
+ 'hardening.refused': 'buffcore.config.ts activa hardening.refuseDebugOptions, y el NODE_OPTIONS de {where} lleva opciones de depuración o de volcado de Node, o una palabra con comillas o barra invertida ({found}): Node lo lee antes de ejecutar código, así que no se inició nada. Quítalas y vuelve a ejecutar esto.',
3
+ };
@@ -0,0 +1,19 @@
1
+ // `hardening.refuseDebugOptions` where BuffCore starts the processes (`ape dev`) or writes what
2
+ // starts them (`ape server setup`): a NODE_OPTIONS Node would read before any code runs is
3
+ // refused before anything starts (`debug-options.ts` in @buffcore/config).
4
+ import { debugStartOptions } from '@buffcore/config';
5
+ import { createI18n } from '@buffcore/i18n';
6
+ import { en } from './hardening.en.js';
7
+ import { es } from './hardening.es.js';
8
+ const translator = createI18n({ catalogs: [{ en, es }] });
9
+ /** Throws, naming the options, when the setting is on and a NODE_OPTIONS carries any. */
10
+ export function refuseDebugStart(hardening, nodeOptions) {
11
+ for (const [where, value] of Object.entries(nodeOptions)) {
12
+ const found = debugStartOptions(hardening, [value]);
13
+ if (found.length)
14
+ throw new Error(translator.t(new Intl.NumberFormat().resolvedOptions().locale, 'hardening.refused', {
15
+ where,
16
+ found: found.join(', '),
17
+ }));
18
+ }
19
+ }
@@ -25,3 +25,8 @@ export interface CompSigner {
25
25
  * (the studio's approval save commits it on its own); returns what the file holds.
26
26
  */
27
27
  export declare function approveComp(root: string, signer: CompSigner, write?: boolean): CompRecord;
28
+ /**
29
+ * A host authority's grant for the comp the page showed, recorded as the studio's own record: only
30
+ * a person's signatures (no agent, no AI) on this comp's pictures. Writes it when `write`.
31
+ */
32
+ export declare function compGrantRecord(root: string, approval: Approval, write?: boolean): CompRecord;
@@ -76,6 +76,28 @@ export function approveComp(root, signer, write = true) {
76
76
  writeRecord(root, record);
77
77
  return record;
78
78
  }
79
+ /**
80
+ * A host authority's grant for the comp the page showed, recorded as the studio's own record: only
81
+ * a person's signatures (no agent, no AI) on this comp's pictures. Writes it when `write`.
82
+ */
83
+ export function compGrantRecord(root, approval, write = true) {
84
+ const comp = newestComp(root);
85
+ if (!comp)
86
+ throw new ApprovalRefusal(compT('comp.missing'));
87
+ if (!comp.report.scenes.length)
88
+ throw new ApprovalRefusal(compT('comp.empty'));
89
+ if (compApproved(readCompApproval(root), comp))
90
+ throw new ApprovalRefusal(compT('comp.approved'));
91
+ if (approval.kind !== 'comp' ||
92
+ approval.signatures.some((s) => s.agent !== undefined || s.ai !== undefined))
93
+ throw new ApprovalRefusal(compT('comp.person'));
94
+ if (approval.signatures.some((s) => s.fingerprint !== comp.fingerprint))
95
+ throw new ApprovalRefusal(compT('comp.changed'));
96
+ const record = { folder: comp.folder, approval };
97
+ if (write)
98
+ writeRecord(root, record);
99
+ return record;
100
+ }
79
101
  function writeRecord(root, record) {
80
102
  const file = join(root, COMP_FILE);
81
103
  mkdirSync(join(root, 'prototype', 'versions'), { recursive: true });
@@ -53,10 +53,11 @@ export declare function buildImages(here: Local, where: {
53
53
  }, product: ProductConfig, { text, source }: {
54
54
  text: string;
55
55
  source: string;
56
- }, { json, log, tag }: {
56
+ }, { json, log, tag, packages, }: {
57
57
  json: boolean;
58
58
  log: (line: string) => void;
59
59
  tag?: string;
60
+ packages?: readonly string[];
60
61
  }): Promise<{
61
62
  tags: string[];
62
63
  built: {
@@ -8,6 +8,7 @@ import { join, relative } from 'node:path';
8
8
  import { createGzip } from 'node:zlib';
9
9
  import { builtImage, containersOf } from '../services/compose.js';
10
10
  import { stopTree } from '../ui/runner.js';
11
+ import { packagesFailed } from './system-packages.js';
11
12
  /** The Dockerfile's name inside the build context (added to the commit's files). */
12
13
  export const DOCKERFILE = 'ape.Dockerfile';
13
14
  /** The image is never built from prototype screenshots (most of a repository's size). */
@@ -111,11 +112,18 @@ export const local = {
111
112
  * moment never takes this one's place), then each container with a Dockerfile from its folder of
112
113
  * the same commit, under the same source. Answers the tags to ship, the product's first.
113
114
  */
114
- export async function buildImages(here, where, product, { text, source }, { json, log, tag = source }) {
115
+ export async function buildImages(here, where, product, { text, source }, { json, log, tag = source, packages = [], }) {
115
116
  const { root, workspace, sha, platform } = where;
116
117
  const image = `${product.name}:${tag}`;
117
118
  log('Building the image...');
118
- await here.build(workspace, sha, text, image, platform, json);
119
+ try {
120
+ await here.build(workspace, sha, text, image, platform, json);
121
+ }
122
+ catch (error) {
123
+ if (!packages.length)
124
+ throw error;
125
+ throw new Error(`${error.message} ${packagesFailed(packages)}`);
126
+ }
119
127
  const containers = containersOf(product.processes).filter((c) => c.build);
120
128
  const tags = [image];
121
129
  for (const c of containers) {
@@ -1,5 +1,6 @@
1
1
  import { type DeployResult } from './deploy-result.ts';
2
2
  import { type RemoteRead, type RemoteRun } from './ssh.ts';
3
+ import { type PackageReader } from './system-packages.ts';
3
4
  export interface LocalDeployOptions {
4
5
  /** The approval file. */
5
6
  approval: string;
@@ -10,6 +11,8 @@ export interface LocalDeployDeps {
10
11
  read?: RemoteRead;
11
12
  now?: () => Date;
12
13
  log?: (line: string) => void;
14
+ /** Reads the image's system packages (`system-packages.ts`); this machine's Docker when unset. */
15
+ readPackages?: PackageReader;
13
16
  }
14
17
  /** `ape deploy --local`. Answers how it ended, as `ape deploy` does. */
15
18
  export declare function deployLocal(image: string, options: LocalDeployOptions, deps?: LocalDeployDeps): Promise<DeployResult>;
@@ -11,6 +11,7 @@ import { deployScript, parseState, stateScript } from './deploy-script.js';
11
11
  import { intakeWarnings } from './deploy-warnings.js';
12
12
  import { SCRIPT_COMMAND } from './script.js';
13
13
  import { here } from './ssh.js';
14
+ import { imagePackages } from './system-packages.js';
14
15
  /** `ape deploy --local`. Answers how it ended, as `ape deploy` does. */
15
16
  export async function deployLocal(image, options, deps = {}) {
16
17
  const machine = here(options.json ? 'stderr' : 'show');
@@ -36,6 +37,14 @@ export async function deployLocal(image, options, deps = {}) {
36
37
  log(`Deploying ${product} at ${approval.commit.slice(0, 12)} on this machine (${state.api}), as approved until ${approval.expires}.`);
37
38
  result.warnings = intakeWarnings(await run(SCRIPT_COMMAND, deployScript(product, state, { ref: image, approved: approval.image })));
38
39
  printIntakeWarnings(result.warnings, log);
40
+ // What the approved image holds, read by its ID once the deploy proved that is what runs; a
41
+ // failed read is said and leaves null, never a guess.
42
+ try {
43
+ result.systemPackages = await imagePackages(approval.image, deps.readPackages);
44
+ }
45
+ catch (error) {
46
+ log(error instanceof Error ? error.message : String(error));
47
+ }
39
48
  log(`Deployed: ${state.api} runs the approved image and answers healthy.`);
40
49
  return end({ result: 'deployed' });
41
50
  }
@@ -0,0 +1,5 @@
1
+ import type { ImagePlan } from './image.ts';
2
+ /** The folder with the lockfile: the product's, or the repository the product sits in. */
3
+ export declare function workspaceOf(root: string): string;
4
+ /** The image's plan: where the product, its API, its console and its web app are, and what they're called. */
5
+ export declare function imagePlan(root: string, workspace: string, site: Pick<ImagePlan, 'name' | 'commit' | 'systemPackages'>): ImagePlan;
@@ -0,0 +1,56 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { dirname, join, relative } from 'node:path';
3
+ import { apiFolder } from '../dev.js';
4
+ import { surfaceDir } from '../prototype/export.js';
5
+ // Where the product, its API, console and web app are, for the server image (split from deploy.ts).
6
+ const readJson = (file) => JSON.parse(readFileSync(file, 'utf8'));
7
+ /** The folder with the lockfile: the product's, or the repository the product sits in. */
8
+ export function workspaceOf(root) {
9
+ for (let dir = root;; dir = dirname(dir)) {
10
+ if (existsSync(join(dir, 'pnpm-lock.yaml')))
11
+ return dir;
12
+ if (dirname(dir) === dir)
13
+ throw new Error(`No pnpm-lock.yaml in ${root} or above.`);
14
+ }
15
+ }
16
+ /** The image's plan: where the product, its API, its console and its web app are, and what they're called. */
17
+ export function imagePlan(root, workspace, site) {
18
+ const from = (dir) => relative(workspace, dir).replaceAll('\\', '/') || '.';
19
+ const product = from(root);
20
+ const api = from(join(root, apiFolder(root)));
21
+ const admin = surfaceDir(root, 'admin');
22
+ if (!admin)
23
+ throw new Error(`No admin console in ${root} (admin/ or apps/admin/).`);
24
+ const app = surfaceDir(root, 'app');
25
+ const apiPackage = readJson(join(workspace, api, 'package.json'));
26
+ if (!apiPackage.dependencies?.['@buffcore/cli']) {
27
+ throw new Error(`${api}/package.json must list @buffcore/cli in its dependencies: the server runs one-off commands with its ape (Node runs the API and processes), and the image installs only what the API's package depends on.`);
28
+ }
29
+ const pnpm = /^pnpm@(\d+\.\d+\.\d+)/.exec(readJson(join(workspace, 'package.json')).packageManager ?? '');
30
+ if (!pnpm)
31
+ throw new Error(`${workspace}/package.json must name pnpm in packageManager.`);
32
+ const names = {
33
+ product: readJson(join(root, 'package.json')).name,
34
+ api: apiPackage.name,
35
+ admin: readJson(join(admin, 'package.json')).name,
36
+ app: app && readJson(join(app, 'package.json')).name,
37
+ };
38
+ if (!names.product || !names.api || !names.admin || (app && !names.app))
39
+ throw new Error("The product's, API's, console's and web app's package.json need names.");
40
+ const { systemPackages, ...named } = site;
41
+ return {
42
+ ...named,
43
+ pnpm: pnpm[1],
44
+ dirs: { product, api, admin: from(admin), ...(app ? { app: from(app) } : {}) },
45
+ packages: {
46
+ product: names.product,
47
+ api: names.api,
48
+ admin: names.admin,
49
+ ...(names.app ? { app: names.app } : {}),
50
+ },
51
+ ...(apiPackage.dependencies?.['@buffcore/cli']?.startsWith('workspace:')
52
+ ? { sources: true }
53
+ : {}),
54
+ ...(systemPackages?.length ? { systemPackages } : {}),
55
+ };
56
+ }
@@ -22,6 +22,13 @@ export interface DeployResult {
22
22
  commit: string | null;
23
23
  /** The image's ID (`sha256:…`): the one built, or the one approved; null when none was. */
24
24
  image: string | null;
25
+ /**
26
+ * The system packages' installed versions in the image deployed (`server.systemPackages`), by
27
+ * name: `{}` for none. `--local` reads them from the approved image (its label names the list);
28
+ * `unchanged` from the image this computer built last time, when still here. Null when they
29
+ * couldn't be read, or nothing was built (refused).
30
+ */
31
+ systemPackages: Record<string, string> | null;
25
32
  /** What went wrong, in a sentence; null when it worked. */
26
33
  error: string | null;
27
34
  /** Unrevoked key counts (expired too), or an explicit unchecked warning; no credentials. */
@@ -30,6 +30,7 @@ export function tracking() {
30
30
  product: '',
31
31
  commit: null,
32
32
  image: null,
33
+ systemPackages: null,
33
34
  error: null,
34
35
  warnings: [{ kind: 'intake-unchecked' }],
35
36
  ms: 0,
@@ -39,6 +39,8 @@ export interface ServerState {
39
39
  deployKey?: string;
40
40
  /** The services the server's compose file runs (setup wrote it from `buffcore.config.ts`). */
41
41
  services?: string[];
42
+ /** The `hardening` its compose file was written for (`hardeningMark`); empty before hardening. */
43
+ hardening?: string;
42
44
  /** Whether the server's Caddyfile serves the web app (one from an older setup doesn't). */
43
45
  web?: boolean;
44
46
  }
@@ -5,7 +5,7 @@
5
5
  // stay in the server's .env, and only its addresses and the deploy key (a public key) are read
6
6
  // back. As in setup, a command that could read input reads /dev/null: the script itself is the input.
7
7
  import { health, migrationCheck, processChecks, SETTLE_SECONDS } from './deploy-checks.js';
8
- import { otherProducts, refuseOtherProduct, stackDir } from './files.js';
8
+ import { HARDENING_LINE, otherProducts, refuseOtherProduct, stackDir } from './files.js';
9
9
  import { CONSOLE_DIR, WEB_API_URL, WEB_DIR } from './image.js';
10
10
  import { imageCheckStep } from './image-check.js';
11
11
  import { configIdScript } from './image-id.js';
@@ -44,6 +44,7 @@ if grep -q 'tls internal' "$dir/Caddyfile"; then echo internal=yes; fi
44
44
  if grep -q '/srv/app' "$dir/Caddyfile"; then echo web=yes; fi
45
45
  cd "$dir"
46
46
  echo "services=$(docker compose config --services 2>/dev/null | tr '\\n' ' ')"
47
+ sed -n 's/^${HARDENING_LINE}/hardening=/p' compose.yml 2>/dev/null || true
47
48
  api=$(docker compose ps -q api 2>/dev/null || true)
48
49
  if [ -n "$api" ]; then
49
50
  echo "running=$(docker inspect --format '{{index .Config.Labels "ape.source"}}' "$api")"
@@ -80,7 +81,7 @@ export function parseState(output, destination, name) {
80
81
  running: value('running').replace('<no value>', ''),
81
82
  ...(commit ? { commit } : {}),
82
83
  deployKey: value('deploy_key'),
83
- ...(services.length ? { services } : {}),
84
+ ...(services.length ? { services, hardening: value('hardening') } : {}),
84
85
  ...(value('web') === 'yes' ? { web: true } : {}),
85
86
  };
86
87
  }
@@ -4,23 +4,22 @@ import { type Local } from './build.ts';
4
4
  import { checkDeploy } from './deploy-chain.ts';
5
5
  import { type DeployResult } from './deploy-result.ts';
6
6
  import { type ServerState } from './deploy-script.ts';
7
- import { type ImagePlan } from './image.ts';
7
+ import { type ImageReader } from './image-id.ts';
8
8
  import { type Output, type RemoteRead, type RemoteRun } from './ssh.ts';
9
+ import { type PackageReader } from './system-packages.ts';
9
10
  export interface DeployOptions {
10
11
  /** The SSH key, as `ssh -i`. */
11
12
  identity?: string;
12
13
  /** One line of JSON on stdout (`deploy-result.ts`); what the steps say goes to stderr. */
13
14
  json?: boolean;
14
15
  }
15
- /** The folder with the lockfile: the product's, or the repository the product sits in. */
16
- export declare function workspaceOf(root: string): string;
17
- /** The image's plan: where the product, its API, its console and its web app are, and what they're called. */
18
- export declare function imagePlan(root: string, workspace: string, site: Pick<ImagePlan, 'name' | 'commit'>): ImagePlan;
16
+ import { imagePlan, workspaceOf } from './deploy-plan.ts';
17
+ export { imagePlan, workspaceOf };
19
18
  /**
20
19
  * The server runs what `buffcore.config.ts` declares, since setup wrote its compose file from it:
21
20
  * a process added or removed since needs setup again, or it would quietly not run (or keep running).
22
21
  */
23
- export declare function checkStack(product: Pick<ProductConfig, 'processes'>, state: Pick<ServerState, 'services'>, destination: string): void;
22
+ export declare function checkStack(product: Pick<ProductConfig, 'processes' | 'hardening'>, state: Pick<ServerState, 'services' | 'hardening'>, destination: string): void;
24
23
  export interface DeployDeps {
25
24
  root?: string;
26
25
  remote?: (destination: string, identity?: string, output?: Output) => RemoteRun;
@@ -31,6 +30,10 @@ export interface DeployDeps {
31
30
  catalog?: CatalogDeps;
32
31
  /** Local checks before building; tests can stand in for git and pnpm as for Docker. */
33
32
  checks?: typeof checkDeploy;
33
+ /** Reads a local image's ID (`image-id.ts`); Docker when unset. */
34
+ readImage?: ImageReader;
35
+ /** Reads the built image's system package versions (`system-packages.ts`); Docker when unset. */
36
+ readPackages?: PackageReader;
34
37
  }
35
38
  /**
36
39
  * `ape deploy`. Read the server, build if it runs something else, ship, then the server's steps.