@buffcore/cli 0.8.47 → 0.8.49

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 (175) hide show
  1. package/CHANGELOG.md +52 -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-serial.d.ts +6 -2
  8. package/dist/commands/change-merge-serial.js +5 -1
  9. package/dist/commands/change-merge.d.ts +2 -2
  10. package/dist/commands/change.js +3 -0
  11. package/dist/commands/check-skills.d.ts +16 -0
  12. package/dist/commands/check-skills.en.d.ts +14 -0
  13. package/dist/commands/check-skills.en.js +14 -0
  14. package/dist/commands/check-skills.es.d.ts +2 -0
  15. package/dist/commands/check-skills.es.js +14 -0
  16. package/dist/commands/check-skills.js +146 -0
  17. package/dist/commands/check.js +5 -0
  18. package/dist/commands/dev.d.ts +9 -2
  19. package/dist/commands/dev.js +24 -5
  20. package/dist/commands/extension/config-text.d.ts +2 -0
  21. package/dist/commands/extension/config-text.js +2 -0
  22. package/dist/commands/extension/index.js +14 -2
  23. package/dist/commands/extension/new.d.ts +16 -0
  24. package/dist/commands/extension/new.js +52 -0
  25. package/dist/commands/extension/pack-files.d.ts +23 -0
  26. package/dist/commands/extension/pack-files.js +78 -0
  27. package/dist/commands/extension/pack-scan.d.ts +24 -0
  28. package/dist/commands/extension/pack-scan.js +131 -0
  29. package/dist/commands/extension/pack.d.ts +48 -0
  30. package/dist/commands/extension/pack.js +142 -0
  31. package/dist/commands/extension/share-text.d.ts +3 -0
  32. package/dist/commands/extension/share-text.js +6 -0
  33. package/dist/commands/extension/share.en.d.ts +32 -0
  34. package/dist/commands/extension/share.en.js +32 -0
  35. package/dist/commands/extension/share.es.d.ts +2 -0
  36. package/dist/commands/extension/share.es.js +32 -0
  37. package/dist/commands/hardening.d.ts +3 -0
  38. package/dist/commands/hardening.en.d.ts +3 -0
  39. package/dist/commands/hardening.en.js +3 -0
  40. package/dist/commands/hardening.es.d.ts +2 -0
  41. package/dist/commands/hardening.es.js +3 -0
  42. package/dist/commands/hardening.js +19 -0
  43. package/dist/commands/prototype/comp-record.d.ts +5 -0
  44. package/dist/commands/prototype/comp-record.js +22 -0
  45. package/dist/commands/server/build.d.ts +2 -1
  46. package/dist/commands/server/build.js +10 -2
  47. package/dist/commands/server/deploy-local.d.ts +3 -0
  48. package/dist/commands/server/deploy-local.js +9 -0
  49. package/dist/commands/server/deploy-plan.d.ts +5 -0
  50. package/dist/commands/server/deploy-plan.js +56 -0
  51. package/dist/commands/server/deploy-result.d.ts +7 -0
  52. package/dist/commands/server/deploy-result.js +1 -0
  53. package/dist/commands/server/deploy-script.d.ts +2 -0
  54. package/dist/commands/server/deploy-script.js +3 -2
  55. package/dist/commands/server/deploy.d.ts +9 -6
  56. package/dist/commands/server/deploy.js +39 -61
  57. package/dist/commands/server/files.d.ts +9 -1
  58. package/dist/commands/server/files.js +25 -5
  59. package/dist/commands/server/image.d.ts +4 -2
  60. package/dist/commands/server/image.js +6 -5
  61. package/dist/commands/server/setup.d.ts +1 -0
  62. package/dist/commands/server/setup.js +4 -0
  63. package/dist/commands/server/system-packages.d.ts +29 -0
  64. package/dist/commands/server/system-packages.js +103 -0
  65. package/dist/commands/services/compose.d.ts +1 -1
  66. package/dist/commands/services/compose.js +5 -3
  67. package/dist/commands/ui/agents-route.js +2 -0
  68. package/dist/commands/ui/approval-authority.en.d.ts +1 -0
  69. package/dist/commands/ui/approval-authority.en.js +1 -0
  70. package/dist/commands/ui/approval-authority.es.d.ts +1 -0
  71. package/dist/commands/ui/approval-authority.es.js +1 -0
  72. package/dist/commands/ui/approval-authority.js +7 -2
  73. package/dist/commands/ui/approve.js +2 -4
  74. package/dist/commands/ui/autopilot-records.d.ts +2 -0
  75. package/dist/commands/ui/autopilot-records.js +5 -0
  76. package/dist/commands/ui/brand-approval.js +5 -1
  77. package/dist/commands/ui/chat/permissions.js +1 -1
  78. package/dist/commands/ui/chat/routes.js +4 -0
  79. package/dist/commands/ui/comp-approval.d.ts +14 -2
  80. package/dist/commands/ui/comp-approval.js +45 -8
  81. package/dist/commands/ui/index.d.ts +1 -0
  82. package/dist/commands/ui/level-route.js +3 -0
  83. package/dist/commands/ui/merge-authority.d.ts +4 -1
  84. package/dist/commands/ui/merge-authority.en.d.ts +4 -0
  85. package/dist/commands/ui/merge-authority.en.js +5 -1
  86. package/dist/commands/ui/merge-authority.es.d.ts +4 -0
  87. package/dist/commands/ui/merge-authority.es.js +5 -1
  88. package/dist/commands/ui/merge-authority.js +6 -3
  89. package/dist/commands/ui/merge-claims.d.ts +7 -0
  90. package/dist/commands/ui/merge-claims.js +21 -0
  91. package/dist/commands/ui/merge-delegation.js +8 -3
  92. package/dist/commands/ui/merge-hold-name.d.ts +5 -0
  93. package/dist/commands/ui/merge-hold-name.js +5 -0
  94. package/dist/commands/ui/merge-hold.d.ts +6 -1
  95. package/dist/commands/ui/merge-hold.js +23 -5
  96. package/dist/commands/ui/merge-publish-host.d.ts +1 -0
  97. package/dist/commands/ui/merge-publish-host.js +2 -2
  98. package/dist/commands/ui/merge-record.d.ts +2 -0
  99. package/dist/commands/ui/merge-record.js +1 -1
  100. package/dist/commands/ui/merge-route.js +17 -1
  101. package/dist/commands/ui/merge-settle.d.ts +32 -0
  102. package/dist/commands/ui/merge-settle.js +133 -0
  103. package/dist/commands/ui/merge-state.d.ts +5 -0
  104. package/dist/commands/ui/merge-state.js +7 -1
  105. package/dist/commands/ui/merge-withdraw.d.ts +9 -0
  106. package/dist/commands/ui/merge-withdraw.js +29 -0
  107. package/dist/commands/ui/outside-merge.d.ts +13 -0
  108. package/dist/commands/ui/outside-merge.js +84 -0
  109. package/dist/commands/ui/outside.d.ts +7 -4
  110. package/dist/commands/ui/outside.js +3 -0
  111. package/dist/commands/ui/plan-extensions.d.ts +34 -0
  112. package/dist/commands/ui/plan-extensions.en.d.ts +4 -0
  113. package/dist/commands/ui/plan-extensions.en.js +4 -0
  114. package/dist/commands/ui/plan-extensions.es.d.ts +2 -0
  115. package/dist/commands/ui/plan-extensions.es.js +4 -0
  116. package/dist/commands/ui/plan-extensions.js +86 -0
  117. package/dist/commands/ui/plan-files.js +9 -3
  118. package/dist/commands/ui/plan-structure.js +5 -7
  119. package/dist/commands/ui/prototype-comp-route.d.ts +12 -3
  120. package/dist/commands/ui/prototype-comp-route.js +35 -17
  121. package/dist/commands/ui/prototype-main.d.ts +6 -0
  122. package/dist/commands/ui/real-file.d.ts +11 -0
  123. package/dist/commands/ui/real-file.js +84 -0
  124. package/dist/commands/ui/save-route.js +4 -1
  125. package/dist/commands/ui/server.d.ts +1 -0
  126. package/dist/commands/ui/server.js +1 -0
  127. package/dist/commands/ui/studio-routes.js +2 -0
  128. package/dist/commands/ui/studio-state.d.ts +8 -0
  129. package/dist/commands/ui/studio-versions.js +19 -3
  130. package/dist/commands/ui/studio.en.d.ts +2 -0
  131. package/dist/commands/ui/studio.en.js +2 -0
  132. package/dist/commands/ui/studio.es.d.ts +2 -0
  133. package/dist/commands/ui/studio.es.js +2 -0
  134. package/dist/commands/upgrade.js +1 -1
  135. package/dist/ui/page.js +91 -91
  136. package/docs/EXTENSIONS.md +6 -0
  137. package/docs/PROTOTYPE.md +13 -0
  138. package/docs/WORKBENCH.md +55 -2
  139. package/package.json +11 -11
  140. package/skills/ape-add-ai-purpose/SKILL.md +1 -1
  141. package/skills/ape-add-event/SKILL.md +1 -1
  142. package/skills/ape-add-extension/SKILL.md +5 -1
  143. package/skills/ape-add-feature/SKILL.md +1 -1
  144. package/skills/ape-add-generator/SKILL.md +1 -1
  145. package/skills/ape-add-module/SKILL.md +1 -1
  146. package/skills/ape-add-route/SKILL.md +3 -1
  147. package/skills/ape-add-service/SKILL.md +1 -1
  148. package/skills/ape-add-translations/SKILL.md +2 -2
  149. package/skills/ape-admin-screen/SKILL.md +1 -1
  150. package/skills/ape-app-screen/SKILL.md +1 -1
  151. package/skills/ape-critique/SKILL.md +11 -32
  152. package/skills/ape-critique/references/after.md +15 -0
  153. package/skills/ape-critique/references/spacing-pass.md +20 -0
  154. package/skills/ape-deploy/SKILL.md +8 -3
  155. package/skills/ape-design-system/SKILL.md +15 -15
  156. package/skills/ape-design-system/references/by-hand.md +7 -0
  157. package/skills/ape-design-system/references/reference-study.md +11 -0
  158. package/skills/ape-diagnose/SKILL.md +24 -0
  159. package/skills/ape-migration/SKILL.md +1 -1
  160. package/skills/ape-plan-change/SKILL.md +37 -31
  161. package/skills/ape-plan-change/references/change-file-fields.md +5 -0
  162. package/skills/ape-plan-change/references/extensions.md +25 -0
  163. package/skills/ape-plan-change/references/finishing.md +3 -0
  164. package/skills/ape-plan-change/references/fix-from-error.md +3 -0
  165. package/skills/ape-plan-change/references/refactor.md +9 -0
  166. package/skills/ape-plan-change/references/structure.md +19 -0
  167. package/skills/ape-prototype/SKILL.md +13 -23
  168. package/skills/ape-prototype/references/comp.md +3 -0
  169. package/skills/ape-prototype/references/scope-and-export.md +5 -0
  170. package/skills/ape-prototype/references/snapshot.md +3 -0
  171. package/skills/ape-prototype/references/structure.md +11 -0
  172. package/skills/ape-prototype/references/working-app.md +7 -0
  173. package/skills/ape-request/SKILL.md +1 -1
  174. package/skills/ape-upgrade/SKILL.md +4 -1
  175. package/templates/product/package.json +1 -1
@@ -42,10 +42,12 @@ export interface ImagePlan {
42
42
  * dependencies. A product installed from the registry runs BuffCore's built JavaScript.
43
43
  */
44
44
  sources?: boolean;
45
+ /** Debian packages the API's own programs need (`server.systemPackages`); none, no lines. */
46
+ systemPackages?: readonly string[];
45
47
  }
46
48
  /**
47
- * The Dockerfile and its source: a hash of everything the image is made from (the commit and the
48
- * versions above). The image carries it as a label, so deploy sees when the server
49
+ * The Dockerfile and its source: a hash of everything the image is made from (the commit, the
50
+ * versions above and the system packages). The image carries it as a label, so deploy sees when the server
49
51
  * already runs exactly this.
50
52
  */
51
53
  export declare function dockerfile(plan: ImagePlan): {
@@ -4,6 +4,7 @@
4
4
  // what the API's package depends on, and carries the admin console's files, and the web app's, for
5
5
  // the server to copy.
6
6
  import { createHash } from 'node:crypto';
7
+ import { packagesLabel, systemPackageLines } from './system-packages.js';
7
8
  /** Node 24.20.0, the newest 24 at least two weeks old when S32 was built, by its digest. */
8
9
  export const NODE_IMAGE = 'node:24.20.0-slim@sha256:ba849c60be29959425b8734d57b8b4b7d56f98edd9504c9af091d5281095a71e';
9
10
  /** The Docker CLI alone (backups run pg_dump in the Postgres image through the server's Docker). */
@@ -37,7 +38,7 @@ ${store}
37
38
  }
38
39
  /** The Dockerfile, without its label. */
39
40
  function body(plan) {
40
- const { name, commit, pnpm, dirs, packages, sources } = plan;
41
+ const { name, commit, pnpm, dirs, packages, sources, systemPackages } = plan;
41
42
  return `# ${name}'s image, from ape deploy: the commit ${commit}, built on the developer's computer and
42
43
  # loaded on the server, never pushed to a registry. Only what the API's package depends on is
43
44
  # installed; the admin console and the web app are built in stages of their own and only their
@@ -68,7 +69,7 @@ FROM ${NODE_IMAGE}
68
69
  # No package manager in a release: it installs nothing, and deploy refuses development tooling.
69
70
  RUN rm -rf /usr/local/lib/node_modules/npm /usr/local/lib/node_modules/corepack /opt/yarn-* \\
70
71
  && cd /usr/local/bin && rm -f npm npx corepack yarn yarnpkg
71
- COPY --from=${DOCKER_CLI_IMAGE} /usr/local/bin/docker /usr/local/bin/docker
72
+ ${systemPackageLines(systemPackages)}COPY --from=${DOCKER_CLI_IMAGE} /usr/local/bin/docker /usr/local/bin/docker
72
73
  COPY --from=api /src /app
73
74
  COPY --from=console /src/${dirs.admin}/dist ${CONSOLE_DIR}
74
75
  ${dirs.app ? `COPY --from=web ${WEB_DIR} ${WEB_DIR}\n` : ''}WORKDIR ${at('/app', dirs.product)}
@@ -78,15 +79,15 @@ USER node
78
79
  `;
79
80
  }
80
81
  /**
81
- * The Dockerfile and its source: a hash of everything the image is made from (the commit and the
82
- * versions above). The image carries it as a label, so deploy sees when the server
82
+ * The Dockerfile and its source: a hash of everything the image is made from (the commit, the
83
+ * versions above and the system packages). The image carries it as a label, so deploy sees when the server
83
84
  * already runs exactly this.
84
85
  */
85
86
  export function dockerfile(plan) {
86
87
  const text = body(plan);
87
88
  const source = createHash('sha256').update(text).digest('hex').slice(0, 16);
88
89
  return {
89
- text: `${text}LABEL ape.product="${plan.name}" ape.source="${source}"\n`,
90
+ text: `${text}LABEL ape.product="${plan.name}" ape.source="${source}"${packagesLabel(plan.systemPackages)}\n`,
90
91
  source,
91
92
  };
92
93
  }
@@ -67,6 +67,7 @@ export declare function settingsFor(path: string, plan: ServerPlan): {
67
67
  APE_BACKUP_KEY?: string | undefined;
68
68
  TURNSTILE_SITE_KEY?: string | undefined;
69
69
  TURNSTILE_SECRET_KEY?: string | undefined;
70
+ APE_HOST_KEY_SHA256?: string | undefined;
70
71
  };
71
72
  appOrigin?: string | undefined;
72
73
  };
@@ -14,6 +14,7 @@ import { coreEnvSchema, defineEnv, isContainer, isEnabled, } from '@buffcore/con
14
14
  import { backupKey } from '@buffcore/modules/ops';
15
15
  import { findRoot, loadProduct } from '../../project.js';
16
16
  import { apiFolder, composeFile } from '../dev.js';
17
+ import { refuseDebugStart } from '../hardening.js';
17
18
  import { surfaceDir } from '../prototype/export.js';
18
19
  import { containersOf } from '../services/compose.js';
19
20
  import { deployKey } from './approval.js';
@@ -117,6 +118,7 @@ export async function planFor(root, site, images = serviceImages) {
117
118
  services,
118
119
  ...(containers.length ? { containers } : {}),
119
120
  push: isEnabled(product, 'push'),
121
+ ...(product.hardening ? { hardening: product.hardening } : {}),
120
122
  ...(surfaceDir(root, 'app') ? { web: true } : {}),
121
123
  };
122
124
  }
@@ -129,6 +131,8 @@ export function settingsFor(path, plan) {
129
131
  throw new Error(`No ${path}: make it with the product's own settings and the bucket for uploads and backups, ${GET_A_BUCKET} Setup adds the secrets it can make.`);
130
132
  }
131
133
  const file = parseEnv(readFileSync(path, 'utf8'));
134
+ // The services read NODE_OPTIONS from this file before any code runs: refused before it is written.
135
+ refuseDebugStart(plan.hardening, { [path]: file.NODE_OPTIONS });
132
136
  const missing = BUCKET.filter((key) => !file[key]);
133
137
  if (missing.length)
134
138
  throw new Error(`${path} must name the bucket for uploads and backups (${missing.join(', ')} missing): ${GET_A_BUCKET}`);
@@ -0,0 +1,29 @@
1
+ import { type ProductConfig } from '@buffcore/config';
2
+ /** Runs `docker` with these arguments, no shell, and answers its output; tests stand in for it. */
3
+ export type PackageReader = (args: string[]) => string | Promise<string>;
4
+ /** The list, refused with a plain sentence when a name isn't a Debian package name. */
5
+ export declare function systemPackagesOf(product: Pick<ProductConfig, 'server'>): string[];
6
+ /** The image label that names the list, so a deploy that only has the image can read it. */
7
+ export declare const PACKAGES_LABEL = "ape.system-packages";
8
+ /**
9
+ * The Dockerfile's lines that install them, or nothing for none (the image stays byte-identical).
10
+ * Each name is checked again here: nothing reaches the shell line unchecked. apt-get takes a name
11
+ * that matches no package as a pattern, so each is then checked as installed by its exact name.
12
+ */
13
+ export declare function systemPackageLines(names?: readonly string[]): string;
14
+ /** The label's part for the list (` ape.system-packages="a b"`), nothing for none. */
15
+ export declare const packagesLabel: (names?: readonly string[]) => string;
16
+ /** The sentence added to a failed build when the image installs system packages. */
17
+ export declare const packagesFailed: (names: readonly string[]) => string;
18
+ /** dpkg-query's format (its own fields; a real tab and newline): `name<TAB>version` per line. */
19
+ export declare const FORMAT = "-f=${Package}\t${Version}\n";
20
+ /**
21
+ * Each listed package's installed version in the built image, as `dpkg-query -W` reads it
22
+ * (never pulled, without network, as the image's own user). None listed, no Docker call and `{}`.
23
+ */
24
+ export declare function packageVersions(image: string, names: readonly string[], platform?: string, read?: PackageReader): Promise<Record<string, string>>;
25
+ /**
26
+ * The versions in an image that only the image says what it holds (`ape deploy --local`): the
27
+ * list from its label, checked again, then `packageVersions`. No label, `{}`.
28
+ */
29
+ export declare function imagePackages(image: string, read?: PackageReader): Promise<Record<string, string>>;
@@ -0,0 +1,103 @@
1
+ // The product's system packages (`server.systemPackages` in buffcore.config.ts): checked here,
2
+ // installed in the image's last stage as root before it drops to the API's user, and their
3
+ // installed versions read back from the built image so the build and the deploy record them.
4
+ import { spawnSync } from 'node:child_process';
5
+ import { SYSTEM_PACKAGE, serverProblems } from '@buffcore/config';
6
+ import { t } from '../build/server-text.js';
7
+ /** The list, refused with a plain sentence when a name isn't a Debian package name. */
8
+ export function systemPackagesOf(product) {
9
+ const problems = serverProblems(product.server);
10
+ if (problems.length)
11
+ throw new Error(t('build.server.packages', { problems: problems.join('; ') }));
12
+ return [...(product.server?.systemPackages ?? [])];
13
+ }
14
+ /** The image label that names the list, so a deploy that only has the image can read it. */
15
+ export const PACKAGES_LABEL = 'ape.system-packages';
16
+ /**
17
+ * The Dockerfile's lines that install them, or nothing for none (the image stays byte-identical).
18
+ * Each name is checked again here: nothing reaches the shell line unchecked. apt-get takes a name
19
+ * that matches no package as a pattern, so each is then checked as installed by its exact name.
20
+ */
21
+ export function systemPackageLines(names = []) {
22
+ if (!names.length)
23
+ return '';
24
+ systemPackagesOf({ server: { systemPackages: names } });
25
+ return `# The product's system packages (server.systemPackages in buffcore.config.ts), installed as
26
+ # root before the image drops to the API's user. One that can't be installed fails the build, as
27
+ # does one not installed by its exact name.
28
+ RUN apt-get update \\
29
+ && apt-get install -y --no-install-recommends ${names.join(' ')} \\
30
+ && for p in ${names.join(' ')}; do \\
31
+ [ "$(dpkg-query -W -f='\${db:Status-Status}' "$p" 2>/dev/null)" = installed ] \\
32
+ || { echo "ape: the system package $p is not installed by that exact name" >&2; exit 1; }; \\
33
+ done \\
34
+ && rm -rf /var/lib/apt/lists/*
35
+ `;
36
+ }
37
+ /** The label's part for the list (` ape.system-packages="a b"`), nothing for none. */
38
+ export const packagesLabel = (names = []) => names.length ? ` ${PACKAGES_LABEL}="${names.join(' ')}"` : '';
39
+ /** The sentence added to a failed build when the image installs system packages. */
40
+ export const packagesFailed = (names) => t('build.server.packagesFailed', { names: names.join(', ') });
41
+ /** dpkg-query's format (its own fields; a real tab and newline): `name<TAB>version` per line. */
42
+ // biome-ignore lint/suspicious/noTemplateCurlyInString: dpkg-query's placeholders, passed as is.
43
+ export const FORMAT = '-f=${Package}\t${Version}\n';
44
+ /** Docker's answer, or an error carrying its own last line (Docker down, no such image). */
45
+ const readDocker = (args) => {
46
+ const run = spawnSync('docker', args, { encoding: 'utf8', timeout: 120_000 });
47
+ if (run.status === 0)
48
+ return run.stdout;
49
+ const said = `${run.stderr ?? ''}`.trim().split('\n').pop();
50
+ throw new Error(said || run.error?.message || `docker exited with ${run.status}`);
51
+ };
52
+ /**
53
+ * Each listed package's installed version in the built image, as `dpkg-query -W` reads it
54
+ * (never pulled, without network, as the image's own user). None listed, no Docker call and `{}`.
55
+ */
56
+ export async function packageVersions(image, names, platform, read = readDocker) {
57
+ if (!names.length)
58
+ return {};
59
+ const args = ['run', '--rm', '--pull=never', '--network', 'none'];
60
+ if (platform)
61
+ args.push('--platform', platform);
62
+ args.push('--entrypoint', 'dpkg-query', image, '-W', FORMAT, ...names);
63
+ let out;
64
+ try {
65
+ out = await read(args);
66
+ }
67
+ catch (error) {
68
+ const cause = error instanceof Error ? error.message : String(error);
69
+ throw new Error(t('build.server.versionsRun', { image, cause }));
70
+ }
71
+ const found = new Map(out
72
+ .split('\n')
73
+ .map((line) => line.trim().split('\t'))
74
+ .filter((pair) => pair.length === 2 && Boolean(pair[1])));
75
+ const versions = {};
76
+ for (const name of names) {
77
+ const version = found.get(name);
78
+ if (!version)
79
+ throw new Error(t('build.server.versionsMissing', { image, name }));
80
+ versions[name] = version;
81
+ }
82
+ return versions;
83
+ }
84
+ /**
85
+ * The versions in an image that only the image says what it holds (`ape deploy --local`): the
86
+ * list from its label, checked again, then `packageVersions`. No label, `{}`.
87
+ */
88
+ export async function imagePackages(image, read = readDocker) {
89
+ const format = `{{index .Config.Labels "${PACKAGES_LABEL}"}}`;
90
+ let label;
91
+ try {
92
+ label = `${await read(['image', 'inspect', '--format', format, image])}`.trim();
93
+ }
94
+ catch (error) {
95
+ const cause = error instanceof Error ? error.message : String(error);
96
+ throw new Error(t('build.server.versionsRun', { image, cause }));
97
+ }
98
+ const names = label && label !== '<no value>' ? label.split(/\s+/) : [];
99
+ const bad = names.find((name) => !SYSTEM_PACKAGE.test(name));
100
+ if (bad !== undefined)
101
+ throw new Error(t('build.server.label', { image, name: bad }));
102
+ return packageVersions(image, names, undefined, read);
103
+ }
@@ -10,7 +10,7 @@ export type Where = {
10
10
  dev: string;
11
11
  } | 'server';
12
12
  /** The containers' services, and their volumes' entries, for a compose file's two sections. */
13
- export declare function containerServices(product: string, processes: readonly ProductProcess[] | undefined, where: Where): {
13
+ export declare function containerServices(product: string, processes: readonly ProductProcess[] | undefined, where: Where, coreDumps?: boolean): {
14
14
  services: string[];
15
15
  volumes: string[];
16
16
  };
@@ -26,7 +26,7 @@ function imageLines(product, c, where) {
26
26
  return [` build: ${quoted(slashes(folder))}`];
27
27
  }
28
28
  /** One container's service. */
29
- function service(product, c, where) {
29
+ function service(product, c, where, coreDumps) {
30
30
  const server = where === 'server';
31
31
  const count = c.count ?? 1;
32
32
  return [
@@ -45,13 +45,15 @@ function service(product, c, where) {
45
45
  ` mem_limit: ${c.size.memoryMb}m`,
46
46
  ...(server && count > 1 ? [` scale: ${count}`] : []),
47
47
  ...(server ? [' restart: unless-stopped'] : []),
48
+ // On a server a crash writes no core dump unless the product keeps them (hardening.coreDumps).
49
+ ...(server && !coreDumps ? [' ulimits: { core: 0 }'] : []),
48
50
  ].join('\n');
49
51
  }
50
52
  /** The containers' services, and their volumes' entries, for a compose file's two sections. */
51
- export function containerServices(product, processes, where) {
53
+ export function containerServices(product, processes, where, coreDumps = false) {
52
54
  const containers = containersOf(processes);
53
55
  return {
54
- services: containers.map((c) => service(product, c, where)),
56
+ services: containers.map((c) => service(product, c, where, coreDumps)),
55
57
  volumes: containers
56
58
  .filter((c) => c.volume)
57
59
  .map((c) => ` ${c.name}:\n name: ${volumeName(product, c.name)}`),
@@ -3,6 +3,7 @@ import { readAgentsFile, writeAgentsFile } from '../agents-file.js';
3
3
  import { supportedChoices } from './chat/supported-choices.js';
4
4
  import { modelForAgent } from './chat/turn-overrides.js';
5
5
  import { factsChanged, mergeEvent } from './merge-events.js';
6
+ import { afterLevel } from './merge-withdraw.js';
6
7
  async function saveAssignment(root, { role, agent }, local) {
7
8
  const previous = await readAgentsFile(root).catch((error) => {
8
9
  // The local route can still repair a damaged file.
@@ -37,6 +38,7 @@ async function saveAssignment(root, { role, agent }, local) {
37
38
  factsChanged('levels', 'unsaved');
38
39
  if (file.level !== 'auto')
39
40
  mergeEvent('level', root);
41
+ await afterLevel(root);
40
42
  }
41
43
  const queues = new Map();
42
44
  /** One queue per product for every write of plan/agents.md: each applies to the file the last left. */
@@ -1,5 +1,6 @@
1
1
  export declare const en: {
2
2
  'ui.authority.elsewhere': string;
3
3
  'ui.authority.refused': string;
4
+ 'ui.authority.unread': string;
4
5
  'ui.authority.signIn': string;
5
6
  };
@@ -1,5 +1,6 @@
1
1
  export const en = {
2
2
  'ui.authority.elsewhere': "Approve this in the product's own console, then come back.",
3
3
  'ui.authority.refused': 'The host did not approve this artifact. Ask again before continuing.',
4
+ 'ui.authority.unread': "This change's version record can't be read here (a link out of the product, or not a valid record), so it shows no approval.",
4
5
  'ui.authority.signIn': 'An approval authority requires hosted sign-in.',
5
6
  };
@@ -1,5 +1,6 @@
1
1
  export declare const es: {
2
2
  'ui.authority.elsewhere': string;
3
3
  'ui.authority.refused': string;
4
+ 'ui.authority.unread': string;
4
5
  'ui.authority.signIn': string;
5
6
  };
@@ -1,5 +1,6 @@
1
1
  export const es = {
2
2
  'ui.authority.elsewhere': 'Aprueba esto en la consola del propio producto y luego vuelve.',
3
3
  'ui.authority.refused': 'El anfitrión no aprobó este artefacto. Vuelve a consultar antes de continuar.',
4
+ 'ui.authority.unread': 'El registro de versiones de este cambio no se puede leer aquí (un enlace fuera del producto o un registro no válido), así que no muestra aprobación.',
4
5
  'ui.authority.signIn': 'Una autoridad de aprobación requiere iniciar sesión con el anfitrión.',
5
6
  };
@@ -41,7 +41,9 @@ export function approvalBound(approval, artifact, root) {
41
41
  approval.signatures.length === 0 ||
42
42
  approval.signatures.some((s) => s.fingerprint !== artifact.fingerprint ||
43
43
  (s.agent !== undefined &&
44
- (approval.rule !== undefined || !['brand', 'prototype'].includes(approval.kind)))))
44
+ (approval.rule !== undefined || !['brand', 'prototype'].includes(approval.kind))) ||
45
+ // The look is a person's at every level: no agent's or AI's signature on a comp grant.
46
+ (approval.kind === 'comp' && s.ai !== undefined)))
45
47
  return false;
46
48
  if (approval.signatures.every((s) => s.commit === artifact.commit))
47
49
  return true;
@@ -128,8 +130,11 @@ export async function judge(context, resolve, action, root) {
128
130
  let artifact;
129
131
  try {
130
132
  const found = resolve();
131
- if (!['brand', 'prototype', 'release', 'places'].includes(found.kind))
133
+ if (!['brand', 'prototype', 'release', 'places', 'comp'].includes(found.kind))
132
134
  return refused('approval_authority_invalid');
135
+ // Approve the look is a person's: an agent, an Autopilot turn or an AI approver never asks.
136
+ if (found.kind === 'comp' && (context.agent !== undefined || context.ai !== undefined))
137
+ return refused('approval_person_only');
133
138
  artifact = Object.freeze({
134
139
  ...found,
135
140
  version: found.version ? Object.freeze({ ...found.version }) : null,
@@ -4,7 +4,7 @@ import { ApprovalRefusal } from '../approval-rules.js';
4
4
  import { requireLegacyChange } from '../prototype/milestone-key.js';
5
5
  import { brandResolver, prototypeArtifact, releaseArtifact } from './approval-artifact.js';
6
6
  import { authorityFor, hostedApproval } from './approval-authority.js';
7
- import { compApproval, compResolver } from './comp-approval.js';
7
+ import { compApproval } from './comp-approval.js';
8
8
  import { brandApproval, prototypeApproval } from './loop-approve.js';
9
9
  import { placesApproval } from './places-approval.js';
10
10
  import { approveChangePlaces } from './places-change-approval.js';
@@ -60,9 +60,7 @@ export function brandApprovalRoute(root) {
60
60
  if (request.kind === 'places')
61
61
  return placesApproval(root, request, signer, role, context, source);
62
62
  if (request.kind === 'comp')
63
- return context
64
- ? hostedApproval(context, await compResolver(root, request.fingerprint))
65
- : compApproval(root, request.fingerprint, signer, role, undefined, source);
63
+ return compApproval(root, request.fingerprint, signer, role, undefined, source, context);
66
64
  if (context) {
67
65
  if (request.kind === 'brand') {
68
66
  const resolve = await brandResolver(root, request.direction);
@@ -9,6 +9,7 @@ declare const pendingSchema: z.ZodObject<{
9
9
  main: z.ZodString;
10
10
  automatic: z.ZodOptional<z.ZodLiteral<true>>;
11
11
  published: z.ZodOptional<z.ZodLiteral<true>>;
12
+ claimHash: z.ZodOptional<z.ZodString>;
12
13
  }, z.core.$strip>;
13
14
  /** What became of a head: the host's merge (seen in main) or its refusal of the ask. */
14
15
  declare const outcomeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -77,6 +78,7 @@ declare const recordSchema: z.ZodObject<{
77
78
  main: z.ZodString;
78
79
  automatic: z.ZodOptional<z.ZodLiteral<true>>;
79
80
  published: z.ZodOptional<z.ZodLiteral<true>>;
81
+ claimHash: z.ZodOptional<z.ZodString>;
80
82
  }, z.core.$strip>>;
81
83
  outcomes: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
82
84
  change: z.ZodString;
@@ -19,6 +19,11 @@ const pendingSchema = z.object({
19
19
  main: fullSha,
20
20
  automatic: z.literal(true).optional(),
21
21
  published: z.literal(true).optional(),
22
+ /** SHA-256 of the claim only the host was given; the claim itself is never kept. */
23
+ claimHash: z
24
+ .string()
25
+ .regex(/^[0-9a-f]{64}$/)
26
+ .optional(),
22
27
  });
23
28
  const outcomeFacts = { change, head: fullSha, at: z.iso.datetime() };
24
29
  /** What became of a head: the host's merge (seen in main) or its refusal of the ask. */
@@ -7,6 +7,7 @@ import { ApprovalRefusal, approvalRule, signApproval } from '../approval-rules.j
7
7
  import { loadTheme } from '../design/sources.js';
8
8
  import { themeHash } from '../design/state.js';
9
9
  import { themeSources } from '../design/theme-sources.js';
10
+ import { readInsideSync } from './real-file.js';
10
11
  export class BrandChanged extends ApprovalRefusal {
11
12
  }
12
13
  /** The colors and the fingerprint a card must carry come from one resolved source snapshot. */
@@ -27,7 +28,10 @@ export async function brandPreview(root) {
27
28
  export async function brandFingerprint(root, direction, snapshot) {
28
29
  const sources = snapshot?.sources ?? themeSources(root);
29
30
  const theme = snapshot?.theme ?? (await loadTheme(root, sources));
30
- const design = readFileSync(join(root, 'design', 'DESIGN.md'), 'utf8').replace(/\r\n/g, '\n');
31
+ const read = readInsideSync(join(root, 'design', 'DESIGN.md'), [root]);
32
+ if (!read)
33
+ throw new Error('design/DESIGN.md');
34
+ const design = read.toString('utf8').replace(/\r\n/g, '\n');
31
35
  const hash = createHash('sha256')
32
36
  .update(JSON.stringify({ theme: themeHash(theme), design, sources: sources.files }))
33
37
  .digest('hex');
@@ -1,6 +1,6 @@
1
1
  import { matchesGlob } from 'node:path';
2
2
  import { branchChange } from '../../change-trailers.js';
3
- import { mergeHoldName } from '../merge-hold.js';
3
+ import { mergeHoldName } from '../merge-hold-name.js';
4
4
  import { LINKED_SECRETS, linkedPackages } from './linked.js';
5
5
  import { verificationShimRules } from './verification.js';
6
6
  const PLANNING = ['pnpm ape change', 'pnpm ape change new:*'];
@@ -1,4 +1,5 @@
1
1
  import { chatIdSchema, newChatBody, sendBody, stopAnswer, stopBody, } from '@buffcore/contracts/workbench';
2
+ import { withdrawAutopilotClaims } from '../merge-withdraw.js';
2
3
  import { allowFolderRoute } from './allow-folder-route.js';
3
4
  import { readSendBody } from './attachments.js';
4
5
  import { CodingApprovalRefusal } from './coding-approval.js';
@@ -111,6 +112,9 @@ function stopRoute(engine) {
111
112
  return guarded('POST', '/api/chats/:id/stop', forChat(engine, async (chat, request) => {
112
113
  const body = await parsedBody(request, stopBody);
113
114
  const result = await engine.stop(chat.id, body.confirm === true);
115
+ // Stop ends Autopilot's waiting merge for this change too (main not holding it).
116
+ if (chat.change)
117
+ await withdrawAutopilotClaims(engine.root, [chat.change]).catch(() => 0);
114
118
  return result === 'confirm'
115
119
  ? {
116
120
  status: 202,
@@ -1,6 +1,18 @@
1
- import type { ApprovalArtifact } from './approval-authority.ts';
1
+ import type { Approval } from '@buffcore/contracts/approvals';
2
+ import { type CompSnapshot } from '../prototype/comp.ts';
3
+ import { type CompRecord } from '../prototype/comp-record.ts';
4
+ import { type ApprovalArtifact, type ApprovalContext } from './approval-authority.ts';
2
5
  import { type SaveSource } from './host-save.ts';
3
6
  import type { UiAnswer } from './routes.ts';
4
- export declare function compApproval(root: string, fingerprint: string, signer?: string, role?: string, agent?: string, source?: SaveSource): Promise<UiAnswer>;
7
+ export declare function compApproval(root: string, fingerprint: string, signer?: string, role?: string, agent?: string, source?: SaveSource, context?: ApprovalContext): Promise<UiAnswer>;
5
8
  /** What a host's authority judges: the comp the page showed, at the commit checked out. */
6
9
  export declare function compResolver(root: string, fingerprint: string): Promise<() => ApprovalArtifact>;
10
+ /**
11
+ * Under a host's authority the comp read says approved only when the host confirms the grant the
12
+ * record names (`action: 'check'`); a refusal, error or timeout leaves it unapproved, with the reason.
13
+ */
14
+ export declare function hostedComp(root: string, record: CompRecord | undefined, comp: CompSnapshot | undefined, context: ApprovalContext): Promise<{
15
+ approved: boolean;
16
+ approval: Approval | null;
17
+ approvalRefusal?: string;
18
+ }>;
@@ -1,17 +1,15 @@
1
- // Approve the look: the guarded approval route's door for the comp. A person's only, at every level;
2
- // there is no agent, MCP or Autopilot door, and `approveComp` refuses an agent's name. The record is
3
- // saved as its own isolated commit, as a version approval is (`saveApprovalRecord`).
4
1
  import { ApprovalRefusal } from '../approval-rules.js';
5
2
  import { newestComp } from '../prototype/comp.js';
6
- import { approveComp, COMP_FILE } from '../prototype/comp-record.js';
3
+ import { approveComp, COMP_FILE, compApproved, compGrantRecord, } from '../prototype/comp-record.js';
7
4
  import { compT } from '../prototype/comp-words.js';
8
5
  import { VersionRefusal } from '../prototype/versions.js';
9
6
  import { hostGit } from '../safe-git.js';
10
- import { HostSaveRefusal } from './host-save.js';
7
+ import { authorityMessage, authorityRefusal, judge, } from './approval-authority.js';
8
+ import { HostSaveRefusal, saveRefused } from './host-save.js';
11
9
  import { saveApprovalRecord } from './save-route.js';
12
10
  const git = async (root, args) => (await hostGit(root, args)).trim();
13
- export async function compApproval(root, fingerprint, signer, role, agent, source) {
14
- if (agent !== undefined)
11
+ export async function compApproval(root, fingerprint, signer, role, agent, source, context) {
12
+ if (agent !== undefined || context?.agent !== undefined || context?.ai !== undefined)
15
13
  return { status: 409, body: { error: compT('comp.person') } };
16
14
  const by = signer ?? (await git(root, ['config', 'user.email']).catch(() => ''));
17
15
  if (!by)
@@ -20,7 +18,25 @@ export async function compApproval(root, fingerprint, signer, role, agent, sourc
20
18
  if (!commit)
21
19
  return { status: 409, body: { error: compT('comp.commitFirst') } };
22
20
  try {
23
- const record = await saveApprovalRecord(root, COMP_FILE, (write = true) => approveComp(root, { by, commit, fingerprint, role }, write), by, undefined, source);
21
+ // Under a host's authority the host decides, once; its grant is recorded as the studio's own.
22
+ const resolve = context ? await compResolver(root, fingerprint) : undefined;
23
+ const answer = context && resolve ? await judge(context, resolve, 'approve') : undefined;
24
+ if (answer && !answer.allowed)
25
+ return authorityRefusal(answer.code);
26
+ if (answer?.allowed && !answer.approval)
27
+ return { status: 202, body: null };
28
+ const granted = answer?.allowed ? answer.approval : null;
29
+ const record = await saveApprovalRecord(root, COMP_FILE, (write = true) => granted
30
+ ? compGrantRecord(root, granted, write)
31
+ : approveComp(root, { by, commit, fingerprint, role }, write), by, undefined, source, resolve &&
32
+ (() => {
33
+ try {
34
+ resolve();
35
+ }
36
+ catch {
37
+ throw saveRefused('save_artifact_changed');
38
+ }
39
+ }));
24
40
  return { status: 201, body: record.approval };
25
41
  }
26
42
  catch (error) {
@@ -40,3 +56,24 @@ export async function compResolver(root, fingerprint) {
40
56
  return { kind: 'comp', version: null, commit, fingerprint };
41
57
  };
42
58
  }
59
+ /**
60
+ * Under a host's authority the comp read says approved only when the host confirms the grant the
61
+ * record names (`action: 'check'`); a refusal, error or timeout leaves it unapproved, with the reason.
62
+ */
63
+ export async function hostedComp(root, record, comp, context) {
64
+ const commit = record?.approval.signatures[0]?.commit;
65
+ if (!record || !comp || !commit)
66
+ return { approved: false, approval: null };
67
+ const fingerprint = comp.fingerprint;
68
+ const answer = await judge(context, () => {
69
+ if (newestComp(root)?.fingerprint !== fingerprint)
70
+ throw new Error();
71
+ return { kind: 'comp', version: null, commit, fingerprint };
72
+ }, 'check', root);
73
+ if (!answer.allowed)
74
+ return { approved: false, approval: null, approvalRefusal: authorityMessage(answer.code) };
75
+ if (!answer.approval)
76
+ return { approved: false, approval: null };
77
+ const held = { folder: record.folder, approval: answer.approval };
78
+ return { approved: compApproved(held, comp), approval: answer.approval };
79
+ }
@@ -44,6 +44,7 @@ export declare function uiEnvironment(root: string): {
44
44
  APE_BACKUP_KEY?: string | undefined;
45
45
  TURNSTILE_SITE_KEY?: string | undefined;
46
46
  TURNSTILE_SECRET_KEY?: string | undefined;
47
+ APE_HOST_KEY_SHA256?: string | undefined;
47
48
  };
48
49
  hostLaunched: boolean;
49
50
  };
@@ -4,6 +4,7 @@ import { personForTurn } from './chat/person.js';
4
4
  import { hostT, levelElsewhere } from './host.js';
5
5
  import { publishSave } from './host-save.js';
6
6
  import { factsChanged, mergeEvent } from './merge-events.js';
7
+ import { afterLevel } from './merge-withdraw.js';
7
8
  import { studioSave } from './save-route.js';
8
9
  /** A person's settings action: save only this selection, even while a turn is running. */
9
10
  export function levelRoute(root) {
@@ -43,6 +44,8 @@ export function levelRoute(root) {
43
44
  prepare: () => publishSave(target, 'level', 'plan/agents.md', content, request),
44
45
  }
45
46
  : undefined);
47
+ if (level !== 'auto')
48
+ await afterLevel(target);
46
49
  return { status: result.ok ? 202 : 409, body: result };
47
50
  },
48
51
  };
@@ -19,6 +19,8 @@ export type HostMergeInput = MergeFacts & Readonly<{
19
19
  signal: AbortSignal;
20
20
  /** Run the final write here, including when publishing a queued request. */
21
21
  publish: HostPublish;
22
+ /** Autopilot's ask only: names it to `settleHostMerge` when a queue merges it later. */
23
+ claim?: string;
22
24
  }>;
23
25
  export type HostMergeAnswer = {
24
26
  status: 'merged';
@@ -46,6 +48,7 @@ export type MergeContext = Readonly<{
46
48
  agent?: string;
47
49
  }>;
48
50
  export declare const mergeT: (key: keyof typeof en, values?: Record<string, unknown>) => string;
51
+ export declare const reservedCode: (code: string) => boolean;
49
52
  export declare const mergeHeldCode = "autopilot_merge_held";
50
53
  export declare const mergeMessage: (code: string) => string;
51
54
  export declare const mergeRefusal: (code: string) => {
@@ -74,4 +77,4 @@ export declare const refusalCode: z.ZodString;
74
77
  export declare const receiptText: z.ZodString;
75
78
  export declare function immutableFacts(facts: MergeFacts): MergeFacts;
76
79
  /** One bounded call, with late settlements consumed and no fallback or retry. */
77
- export declare function callMerge(context: MergeContext, facts: MergeFacts, publication: 'person' | HostPublish, signal?: AbortSignal, current?: () => boolean): Promise<HostMergeAnswer>;
80
+ export declare function callMerge(context: MergeContext, facts: MergeFacts, publication: 'person' | HostPublish, signal?: AbortSignal, current?: () => boolean, claim?: string): Promise<HostMergeAnswer>;
@@ -6,6 +6,10 @@ export declare const en: {
6
6
  'ui.merge.stopped': string;
7
7
  'ui.merge.pending': string;
8
8
  'ui.merge.since': string;
9
+ 'ui.merge.settleRefused': string;
10
+ 'ui.merge.settleHeld': string;
11
+ 'ui.merge.withdrawn': string;
12
+ 'ui.merge.notWithdrawn': string;
9
13
  'ui.merge.refused': string;
10
14
  'ui.merge.error': string;
11
15
  'ui.merge.timeout': string;
@@ -5,7 +5,11 @@ export const en = {
5
5
  'ui.merge.config': 'The host merge configuration conflicts or its timeout is not an integer from 1 to 30000 milliseconds.',
6
6
  'ui.merge.stopped': 'The last merge of this change ended without an answer (the studio stopped). Merge again.',
7
7
  'ui.merge.pending': 'Waiting for the host to merge.',
8
- 'ui.merge.since': 'Waiting for the host to merge. Asked {at}.',
8
+ 'ui.merge.since': 'Waiting for the host to merge. Asked {at}, {hours, plural, =0 {{minutes, plural, one {# minute} other {# minutes}}} one {# hour} other {# hours}} ago.',
9
+ 'ui.merge.settleRefused': 'The host could not settle this merge request. Reason: {code}.',
10
+ 'ui.merge.settleHeld': 'Autopilot merges are held, so the host could not settle this merge request.',
11
+ 'ui.merge.withdrawn': 'The merge request was withdrawn. The change can be merged again.',
12
+ 'ui.merge.notWithdrawn': 'There is no merge request to withdraw, or main already holds the change.',
9
13
  'ui.merge.refused': 'The host did not merge this change. Reason: {code}.',
10
14
  'ui.merge.error': 'The host merge could not be confirmed. Check its result before continuing.',
11
15
  'ui.merge.timeout': 'The host did not answer in time. Check its result before continuing.',
@@ -6,6 +6,10 @@ export declare const es: {
6
6
  'ui.merge.stopped': string;
7
7
  'ui.merge.pending': string;
8
8
  'ui.merge.since': string;
9
+ 'ui.merge.settleRefused': string;
10
+ 'ui.merge.settleHeld': string;
11
+ 'ui.merge.withdrawn': string;
12
+ 'ui.merge.notWithdrawn': string;
9
13
  'ui.merge.refused': string;
10
14
  'ui.merge.error': string;
11
15
  'ui.merge.timeout': string;