@biffo/cli 0.323.0 → 0.324.1

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 (2) hide show
  1. package/dist/index.js +499 -233
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -7565,6 +7565,14 @@ function resolveCoreRoot(input) {
7565
7565
  }
7566
7566
  return cache;
7567
7567
  }
7568
+ function resolveCoreRootForCli(explicit, runner) {
7569
+ return resolveCoreRoot({
7570
+ ...explicit ? { explicit } : {},
7571
+ env: process.env,
7572
+ coreTag: `core-v${getLatestCoreVersion()}`,
7573
+ runner
7574
+ });
7575
+ }
7568
7576
 
7569
7577
  // src/lib/plugin-compose/dev-up.ts
7570
7578
  import { existsSync as existsSync24 } from "fs";
@@ -7683,9 +7691,10 @@ function isGitIgnored(deps, cwd, file) {
7683
7691
  return status !== 1;
7684
7692
  }
7685
7693
  async function runDevUp(options, deps, hooks) {
7694
+ const label = options.label ?? "dev up";
7686
7695
  if (options.configFile && !isGitIgnored(deps, options.pluginRoot, options.configFile)) {
7687
7696
  log.warn(
7688
- `dev up: ${options.configFile} may hold secret values and is NOT git-ignored \u2014 add it to .gitignore before it is committed (Secret Scan reads history, not just your diff)`
7697
+ `${label}: ${options.configFile} may hold secret values and is NOT git-ignored \u2014 add it to .gitignore before it is committed (Secret Scan reads history, not just your diff)`
7689
7698
  );
7690
7699
  }
7691
7700
  let stack;
@@ -7693,10 +7702,10 @@ async function runDevUp(options, deps, hooks) {
7693
7702
  stack = await composeStack({ ...options, readyTimeoutMs: 12e4 }, deps);
7694
7703
  } catch (err) {
7695
7704
  if (options.signal?.aborted) {
7696
- log.info("dev up: interrupted \u2014 everything started so far was torn down");
7705
+ log.info(`${label}: interrupted \u2014 everything started so far was torn down`);
7697
7706
  return INTERRUPTED_EXIT;
7698
7707
  }
7699
- log.error(`dev up: ${err.message}`);
7708
+ log.error(`${label}: ${err.message}`);
7700
7709
  return 1;
7701
7710
  }
7702
7711
  try {
@@ -7710,23 +7719,23 @@ async function runDevUp(options, deps, hooks) {
7710
7719
  wrongKeyToken: mintDevToken(wrongKey.privateKeyPem, { groups: stack.groups })
7711
7720
  });
7712
7721
  const results = await runProbes(probes, deps.fetchFn);
7713
- hooks.write(`dev up: ${results.filter((r) => r.ok).length}/${results.length} probes matched`);
7722
+ hooks.write(`${label}: ${results.filter((r) => r.ok).length}/${results.length} probes matched`);
7714
7723
  for (const line of formatProbeTable(results)) hooks.write(line);
7715
7724
  for (const note of notes) hooks.write(` note: ${note}`);
7716
7725
  const verdict = probesGreen(results, stack.manifest);
7717
7726
  if (stack.sink.unexpected.length > 0) {
7718
7727
  hooks.write(
7719
- `dev up: WARNING ${stack.sink.unexpected.length} AWS call(s) hit the local sink with no implementation (${[...new Set(stack.sink.unexpected)].join(", ")}) \u2014 refused, not forwarded`
7728
+ `${label}: WARNING ${stack.sink.unexpected.length} AWS call(s) hit the local sink with no implementation (${[...new Set(stack.sink.unexpected)].join(", ")}) \u2014 refused, not forwarded`
7720
7729
  );
7721
7730
  }
7722
7731
  if (options.check) {
7723
7732
  if (options.signal?.aborted) return INTERRUPTED_EXIT;
7724
- if (!verdict.ok) log.error(`dev up --check: ${verdict.reason}`);
7725
- else log.success("dev up --check: composition healthy");
7733
+ if (!verdict.ok) log.error(`${label} --check: ${verdict.reason}`);
7734
+ else log.success(`${label} --check: composition healthy`);
7726
7735
  return verdict.ok ? 0 : 1;
7727
7736
  }
7728
7737
  if (!verdict.ok)
7729
- log.warn(`dev up: ${verdict.reason} \u2014 the stack is up, but do not trust it yet`);
7738
+ log.warn(`${label}: ${verdict.reason} \u2014 the stack is up, but do not trust it yet`);
7730
7739
  hooks.write("");
7731
7740
  hooks.write(` Core ${stack.coreUrl}/api/v1 (health: /health)`);
7732
7741
  hooks.write(` Plugin host ${stack.hostUrl}/${stack.manifest.name}/<route>`);
@@ -7744,13 +7753,17 @@ async function runDevUp(options, deps, hooks) {
7744
7753
  ` curl -H "Authorization: Bearer $TOKEN" ${stack.hostUrl}/${stack.manifest.name}/<declared route>`
7745
7754
  );
7746
7755
  hooks.write("");
7747
- hooks.write("dev up: running \u2014 Ctrl-C to stop");
7756
+ hooks.write(`${label}: running \u2014 Ctrl-C to stop`);
7748
7757
  await hooks.untilInterrupted();
7749
7758
  return 0;
7750
7759
  } finally {
7751
7760
  await stack.close();
7752
7761
  }
7753
7762
  }
7763
+ function runCompositionCheck(options, deps, write) {
7764
+ return runDevUp({ ...options, check: true }, deps, { write, untilInterrupted: async () => {
7765
+ } });
7766
+ }
7754
7767
 
7755
7768
  // src/lib/plugin-compose/interrupt.ts
7756
7769
  var INTERRUPTS = ["SIGINT", "SIGTERM", "SIGHUP"];
@@ -7780,12 +7793,7 @@ var devUpCommand = new Command10("up").description(
7780
7793
  const runner = new RealCommandRunner();
7781
7794
  let coreRoot;
7782
7795
  try {
7783
- coreRoot = resolveCoreRoot({
7784
- ...options.coreRoot ? { explicit: options.coreRoot } : {},
7785
- env: process.env,
7786
- coreTag: `core-v${getLatestCoreVersion()}`,
7787
- runner
7788
- });
7796
+ coreRoot = resolveCoreRootForCli(options.coreRoot, runner);
7789
7797
  } catch (err) {
7790
7798
  log.error(`dev up: ${err.message}`);
7791
7799
  process.exit(1);
@@ -9555,8 +9563,8 @@ async function promptForConfig(awsAccountId, awsRegion, awsProfile) {
9555
9563
  import { Command as Command23 } from "commander";
9556
9564
 
9557
9565
  // src/commands/plugin-create.ts
9558
- import { existsSync as existsSync31, readFileSync as readFileSync22, writeFileSync as writeFileSync10 } from "fs";
9559
- import { dirname as dirname10, join as join31, resolve as resolve13 } from "path";
9566
+ import { existsSync as existsSync32, readFileSync as readFileSync23, writeFileSync as writeFileSync11 } from "fs";
9567
+ import { dirname as dirname10, join as join32, resolve as resolve13 } from "path";
9560
9568
  import { fileURLToPath as fileURLToPath6 } from "url";
9561
9569
  import chalk13 from "chalk";
9562
9570
  import { Command as Command14 } from "commander";
@@ -9656,18 +9664,254 @@ function findInstalledPlugins(cwd) {
9656
9664
  ].sort((a, b) => a.relDir.localeCompare(b.relDir));
9657
9665
  }
9658
9666
 
9667
+ // src/lib/plugin-workspace-sources.ts
9668
+ import { existsSync as existsSync30, readdirSync as readdirSync11, readFileSync as readFileSync21, writeFileSync as writeFileSync9 } from "fs";
9669
+ import { join as join30 } from "path";
9670
+ import { parse as parseToml } from "smol-toml";
9671
+ function readTomlStringArray(text, key) {
9672
+ const open = new RegExp(`^${key}\\s*=\\s*\\[`, "m").exec(text);
9673
+ if (!open) return [];
9674
+ const strings = [];
9675
+ let depth = 1;
9676
+ let i = open.index + open[0].length;
9677
+ while (i < text.length && depth > 0) {
9678
+ const c = text[i];
9679
+ if (c === "#") {
9680
+ const nl = text.indexOf("\n", i);
9681
+ i = nl === -1 ? text.length : nl;
9682
+ } else if (c === '"' || c === "'") {
9683
+ const close = text.indexOf(c, i + 1);
9684
+ if (close === -1) break;
9685
+ if (depth === 1) strings.push(text.slice(i + 1, close));
9686
+ i = close + 1;
9687
+ } else {
9688
+ if (c === "[") depth++;
9689
+ else if (c === "]") depth--;
9690
+ i++;
9691
+ }
9692
+ }
9693
+ return depth === 0 ? strings : [];
9694
+ }
9695
+ function readProjectName(text) {
9696
+ let inProject = false;
9697
+ for (const line of text.split("\n")) {
9698
+ const trimmed = line.trim();
9699
+ if (trimmed.startsWith("[")) {
9700
+ inProject = trimmed === "[project]";
9701
+ continue;
9702
+ }
9703
+ if (inProject) {
9704
+ const m = /^name\s*=\s*["']([^"']+)["']/.exec(trimmed);
9705
+ if (m) return m[1];
9706
+ }
9707
+ }
9708
+ return null;
9709
+ }
9710
+ function requirementName(requirement) {
9711
+ return /^\s*([A-Za-z0-9._-]+)/.exec(requirement)?.[1] ?? null;
9712
+ }
9713
+ function isTable(value) {
9714
+ return typeof value === "object" && value !== null && !Array.isArray(value);
9715
+ }
9716
+ function requirementsIn(groups) {
9717
+ if (!isTable(groups)) return [];
9718
+ return Object.values(groups).filter(Array.isArray).flat().filter((entry) => typeof entry === "string");
9719
+ }
9720
+ function readDeclaredDependencyNames(doc) {
9721
+ const project = isTable(doc.project) ? doc.project : {};
9722
+ const requirements = [
9723
+ ...(Array.isArray(project.dependencies) ? project.dependencies : []).filter(
9724
+ (dep) => typeof dep === "string"
9725
+ ),
9726
+ ...requirementsIn(project["optional-dependencies"]),
9727
+ ...requirementsIn(doc["dependency-groups"])
9728
+ ];
9729
+ return requirements.map(requirementName).filter((name) => name !== null);
9730
+ }
9731
+ function existingSourceNames(doc) {
9732
+ const tool = isTable(doc.tool) ? doc.tool : {};
9733
+ const uv = isTable(tool.uv) ? tool.uv : {};
9734
+ return new Set(isTable(uv.sources) ? Object.keys(uv.sources) : []);
9735
+ }
9736
+ function hasSourcesTable(doc) {
9737
+ const tool = isTable(doc.tool) ? doc.tool : {};
9738
+ const uv = isTable(tool.uv) ? tool.uv : {};
9739
+ return uv.sources !== void 0;
9740
+ }
9741
+ function sourcesHeaderLineEnd(text) {
9742
+ let depth = 0;
9743
+ let atLineStart = true;
9744
+ let i = 0;
9745
+ while (i < text.length) {
9746
+ const c = text[i];
9747
+ if (c === "\n") {
9748
+ atLineStart = true;
9749
+ i++;
9750
+ } else if (c === " " || c === " " || c === "\r") {
9751
+ i++;
9752
+ } else if (c === "#") {
9753
+ const nl = text.indexOf("\n", i);
9754
+ i = nl === -1 ? text.length : nl;
9755
+ } else if (c === '"' || c === "'") {
9756
+ atLineStart = false;
9757
+ const triple = text.startsWith(c.repeat(3), i);
9758
+ const quote = triple ? c.repeat(3) : c;
9759
+ i += quote.length;
9760
+ while (i < text.length && !text.startsWith(quote, i)) {
9761
+ if (c === '"' && text[i] === "\\") i++;
9762
+ if (!triple && text[i] === "\n") break;
9763
+ i++;
9764
+ }
9765
+ i += quote.length;
9766
+ } else if (atLineStart && depth === 0 && c === "[") {
9767
+ const isArrayOfTables = text[i + 1] === "[";
9768
+ const close = isArrayOfTables ? "]]" : "]";
9769
+ let j = i + close.length;
9770
+ while (j < text.length && !text.startsWith(close, j)) {
9771
+ if (text[j] === '"' || text[j] === "'") {
9772
+ const end = text.indexOf(text[j], j + 1);
9773
+ j = end === -1 ? text.length : end;
9774
+ }
9775
+ j++;
9776
+ }
9777
+ const header = text.slice(i, j + close.length);
9778
+ const nl = text.indexOf("\n", j);
9779
+ const lineEnd = nl === -1 ? text.length : nl + 1;
9780
+ if (!isArrayOfTables && isSourcesHeader(header)) return lineEnd;
9781
+ i = lineEnd;
9782
+ atLineStart = true;
9783
+ } else {
9784
+ atLineStart = false;
9785
+ if (c === "[" || c === "{") depth++;
9786
+ else if (c === "]" || c === "}") depth--;
9787
+ i++;
9788
+ }
9789
+ }
9790
+ return null;
9791
+ }
9792
+ function isSourcesHeader(header) {
9793
+ let node = parseToml(`${header}
9794
+ `);
9795
+ for (const segment of ["tool", "uv", "sources"]) {
9796
+ if (!isTable(node) || Object.keys(node).length !== 1 || !(segment in node)) return false;
9797
+ node = node[segment];
9798
+ }
9799
+ return isTable(node) && Object.keys(node).length === 0;
9800
+ }
9801
+ function workspaceMemberNames(instanceRoot) {
9802
+ const rootPyproject = join30(instanceRoot, "pyproject.toml");
9803
+ if (!existsSync30(rootPyproject)) return /* @__PURE__ */ new Set();
9804
+ const text = readFileSync21(rootPyproject, "utf8");
9805
+ const members = readTomlStringArray(text, "members");
9806
+ const excluded = new Set(readTomlStringArray(text, "exclude"));
9807
+ const dirs = [];
9808
+ for (const member of members) {
9809
+ if (member.endsWith("/*")) {
9810
+ const base = member.slice(0, -2);
9811
+ let entries;
9812
+ try {
9813
+ entries = readdirSync11(join30(instanceRoot, base), { withFileTypes: true });
9814
+ } catch {
9815
+ continue;
9816
+ }
9817
+ for (const entry of entries) {
9818
+ const rel = `${base}/${entry.name}`;
9819
+ if (entry.isDirectory() && !entry.name.startsWith(".") && !excluded.has(rel)) dirs.push(rel);
9820
+ }
9821
+ } else if (!excluded.has(member)) {
9822
+ dirs.push(member);
9823
+ }
9824
+ }
9825
+ const names = /* @__PURE__ */ new Set();
9826
+ for (const dir of dirs) {
9827
+ const pp = join30(instanceRoot, dir, "pyproject.toml");
9828
+ if (!existsSync30(pp)) continue;
9829
+ const name = readProjectName(readFileSync21(pp, "utf8"));
9830
+ if (name) names.add(name);
9831
+ }
9832
+ return names;
9833
+ }
9834
+ function ensureWorkspaceSources(pluginPyprojectPath, memberNames) {
9835
+ if (!existsSync30(pluginPyprojectPath) || memberNames.size === 0) return [];
9836
+ const text = readFileSync21(pluginPyprojectPath, "utf8");
9837
+ const doc = parsePyproject(text, pluginPyprojectPath);
9838
+ const already = existingSourceNames(doc);
9839
+ const declared = new Set(readDeclaredDependencyNames(doc));
9840
+ const toAdd = [...declared].filter((n) => memberNames.has(n) && !already.has(n));
9841
+ if (toAdd.length === 0) return [];
9842
+ const lines = toAdd.map(
9843
+ (n) => `${/^[A-Za-z0-9_-]+$/.test(n) ? n : JSON.stringify(n)} = { workspace = true }`
9844
+ );
9845
+ let updated;
9846
+ if (hasSourcesTable(doc)) {
9847
+ const insertAt = sourcesHeaderLineEnd(text);
9848
+ if (insertAt === null) {
9849
+ throw new Error(
9850
+ `${pluginPyprojectPath} defines tool.uv.sources as an inline table or dotted keys, which biffo cannot extend in place without risking a duplicate. Add \`{ workspace = true }\` sources for ${toAdd.join(", ")} by hand (the instance provides them as uv workspace members), then re-run.`
9851
+ );
9852
+ }
9853
+ const sep5 = text.slice(0, insertAt).endsWith("\n") ? "" : "\n";
9854
+ updated = `${text.slice(0, insertAt)}${sep5}${lines.join("\n")}
9855
+ ${text.slice(insertAt)}`;
9856
+ } else {
9857
+ const sep5 = text.endsWith("\n") ? "" : "\n";
9858
+ updated = `${text}${sep5}
9859
+ # Vendored into this instance by \`biffo plugin install\`: resolve dependencies the
9860
+ # instance's uv workspace provides as members from the workspace, not PyPI.
9861
+ [tool.uv.sources]
9862
+ ${lines.join("\n")}
9863
+ `;
9864
+ }
9865
+ let written = /* @__PURE__ */ new Set();
9866
+ try {
9867
+ written = existingSourceNames(parseToml(updated));
9868
+ } catch {
9869
+ }
9870
+ const missing = toAdd.filter((n) => !written.has(n));
9871
+ if (missing.length > 0) {
9872
+ throw new Error(
9873
+ `${pluginPyprojectPath}: could not add a workspace source for ${missing.join(", ")} to tool.uv.sources without producing invalid TOML. Add them by hand (the instance provides them as uv workspace members), then re-run.`
9874
+ );
9875
+ }
9876
+ writeFileSync9(pluginPyprojectPath, updated);
9877
+ return toAdd;
9878
+ }
9879
+ function parsePyproject(text, path) {
9880
+ try {
9881
+ return parseToml(text);
9882
+ } catch (err) {
9883
+ throw new Error(
9884
+ `${path} is not valid TOML: ${err instanceof Error ? err.message : String(err)}`,
9885
+ {
9886
+ cause: err
9887
+ }
9888
+ );
9889
+ }
9890
+ }
9891
+ function applyWorkspaceSources(targetDir, cwd, relTargetDir) {
9892
+ const pluginPyproject = join30(targetDir, "pyproject.toml");
9893
+ if (!existsSync30(pluginPyproject)) return [];
9894
+ const sourced = ensureWorkspaceSources(pluginPyproject, workspaceMemberNames(cwd));
9895
+ if (sourced.length > 0) {
9896
+ log.info(
9897
+ `Sourced ${sourced.join(", ")} from the workspace in ${relTargetDir}/pyproject.toml (the instance provides it as a workspace member).`
9898
+ );
9899
+ }
9900
+ return sourced;
9901
+ }
9902
+
9659
9903
  // src/lib/plugin-scaffold.ts
9660
9904
  import {
9661
9905
  chmodSync as chmodSync2,
9662
9906
  copyFileSync,
9663
- existsSync as existsSync30,
9907
+ existsSync as existsSync31,
9664
9908
  mkdirSync as mkdirSync9,
9665
- readFileSync as readFileSync21,
9666
- readdirSync as readdirSync11,
9909
+ readFileSync as readFileSync22,
9910
+ readdirSync as readdirSync12,
9667
9911
  statSync as statSync7,
9668
- writeFileSync as writeFileSync9
9912
+ writeFileSync as writeFileSync10
9669
9913
  } from "fs";
9670
- import { dirname as dirname9, join as join30 } from "path";
9914
+ import { dirname as dirname9, join as join31 } from "path";
9671
9915
  var STANDALONE_ONLY_ENTRIES = {
9672
9916
  ".github": "standalone-repo CI/release workflows \u2014 the host monorepo already runs lint/type/test/security over services/",
9673
9917
  "registry-schema.json": "the plugin-registry publishing schema, used when submitting a *published* plugin to the registry repo, not by an in-tree plugin",
@@ -9721,10 +9965,10 @@ function applySubstitutions(text, names) {
9721
9965
  var BINARY_EXTENSIONS = /\.(png|jpe?g|gif|ico|woff2?|ttf|zip|gz)$/i;
9722
9966
  function scaffoldPlugin(skeletonRoot, destDir, names, options = {}) {
9723
9967
  const layout = options.layout ?? "in-tree";
9724
- if (!existsSync30(skeletonRoot)) {
9968
+ if (!existsSync31(skeletonRoot)) {
9725
9969
  throw new Error(`Plugin skeleton not found at ${skeletonRoot}`);
9726
9970
  }
9727
- if (!existsSync30(join30(skeletonRoot, "terraform"))) {
9971
+ if (!existsSync31(join31(skeletonRoot, "terraform"))) {
9728
9972
  throw new Error(
9729
9973
  `Plugin skeleton at ${skeletonRoot} has no terraform/ directory. Refusing to scaffold a plugin that cannot receive events (issue #194) \u2014 the skeleton is broken.`
9730
9974
  );
@@ -9732,8 +9976,8 @@ function scaffoldPlugin(skeletonRoot, destDir, names, options = {}) {
9732
9976
  const skipped = [];
9733
9977
  const files = [];
9734
9978
  const walk2 = (relDir) => {
9735
- const absDir = join30(skeletonRoot, relDir);
9736
- for (const entry of readdirSync11(absDir, { withFileTypes: true }).sort(
9979
+ const absDir = join31(skeletonRoot, relDir);
9980
+ for (const entry of readdirSync12(absDir, { withFileTypes: true }).sort(
9737
9981
  (a, b) => a.name.localeCompare(b.name)
9738
9982
  )) {
9739
9983
  if (NEVER_COPY.has(entry.name)) continue;
@@ -9747,13 +9991,13 @@ function scaffoldPlugin(skeletonRoot, destDir, names, options = {}) {
9747
9991
  continue;
9748
9992
  }
9749
9993
  const destRel = applySubstitutions(relPath, names);
9750
- const destPath = join30(destDir, destRel);
9994
+ const destPath = join31(destDir, destRel);
9751
9995
  mkdirSync9(dirname9(destPath), { recursive: true });
9752
- const srcPath = join30(skeletonRoot, relPath);
9996
+ const srcPath = join31(skeletonRoot, relPath);
9753
9997
  if (BINARY_EXTENSIONS.test(entry.name)) {
9754
9998
  copyFileSync(srcPath, destPath);
9755
9999
  } else {
9756
- writeFileSync9(destPath, applySubstitutions(readFileSync21(srcPath, "utf8"), names));
10000
+ writeFileSync10(destPath, applySubstitutions(readFileSync22(srcPath, "utf8"), names));
9757
10001
  chmodSync2(destPath, statSync7(srcPath).mode);
9758
10002
  }
9759
10003
  files.push(destRel);
@@ -9770,8 +10014,8 @@ function scaffoldPlugin(skeletonRoot, destDir, names, options = {}) {
9770
10014
  function findSkeletonRoot(startDir, skeleton) {
9771
10015
  let dir = startDir;
9772
10016
  for (; ; ) {
9773
- const candidate = join30(dir, "_skeletons", skeleton);
9774
- if (existsSync30(candidate)) return candidate;
10017
+ const candidate = join31(dir, "_skeletons", skeleton);
10018
+ if (existsSync31(candidate)) return candidate;
9775
10019
  const parent = dirname9(dir);
9776
10020
  if (parent === dir) return null;
9777
10021
  dir = parent;
@@ -9839,7 +10083,7 @@ async function runPluginCreate(name, options, deps) {
9839
10083
  reportBranchProtectionSummary();
9840
10084
  return;
9841
10085
  }
9842
- const isInstance = existsSync31(join31(options.cwd, INSTANCE_CORE_FILE));
10086
+ const isInstance = existsSync32(join32(options.cwd, INSTANCE_CORE_FILE));
9843
10087
  if (options.firstParty && isInstance) {
9844
10088
  throw new Error(
9845
10089
  `--first-party scaffolds into services/_plugins/, which is template-owned: \`biffo core upgrade\` three-way-merges it against the template on every upgrade, and the template has no '${names.slug}'. This checkout is a Biffo instance (${INSTANCE_CORE_FILE} is present), so your plugin belongs in the user-owned ${pluginDir(names.slug, "third-party")}/ \u2014 re-run without --first-party.`
@@ -9847,19 +10091,19 @@ async function runPluginCreate(name, options, deps) {
9847
10091
  }
9848
10092
  const channel = options.firstParty ? "first-party" : "third-party";
9849
10093
  const relDir = pluginDir(names.slug, channel);
9850
- const destDir = join31(options.cwd, relDir);
9851
- const servicesDir = join31(options.cwd, "services");
9852
- if (!existsSync31(servicesDir)) {
10094
+ const destDir = join32(options.cwd, relDir);
10095
+ const servicesDir = join32(options.cwd, "services");
10096
+ if (!existsSync32(servicesDir)) {
9853
10097
  throw new Error(
9854
10098
  `${servicesDir} does not exist \u2014 is ${options.cwd} the root of a Biffo project checkout?`
9855
10099
  );
9856
10100
  }
9857
- if (existsSync31(destDir)) {
10101
+ if (existsSync32(destDir)) {
9858
10102
  throw new Error(`${relDir}/ already exists. Choose a different name, or remove it first.`);
9859
10103
  }
9860
10104
  const here = dirname10(fileURLToPath6(import.meta.url));
9861
- const skeletonRoot = options.skeletonRoot ?? findSkeletonRoot(here, "plugin-template") ?? join31(options.cwd, "_skeletons", "plugin-template");
9862
- if (!existsSync31(skeletonRoot)) {
10105
+ const skeletonRoot = options.skeletonRoot ?? findSkeletonRoot(here, "plugin-template") ?? join32(options.cwd, "_skeletons", "plugin-template");
10106
+ if (!existsSync32(skeletonRoot)) {
9863
10107
  throw new Error(
9864
10108
  `Could not find the plugin skeleton (_skeletons/plugin-template/). Pass --skeleton <path> to point at it explicitly.`
9865
10109
  );
@@ -9874,8 +10118,8 @@ async function runPluginCreate(name, options, deps) {
9874
10118
  for (const { entry, reason } of skipped) {
9875
10119
  log.info(`Skipped ${entry} \u2014 ${reason}`);
9876
10120
  }
9877
- const manifestPath = join31(destDir, "biffo.plugin.json");
9878
- const manifest = validateManifest(JSON.parse(readFileSync22(manifestPath, "utf8")));
10121
+ const manifestPath = join32(destDir, "biffo.plugin.json");
10122
+ const manifest = validateManifest(JSON.parse(readFileSync23(manifestPath, "utf8")));
9879
10123
  if (manifest.name !== names.slug) {
9880
10124
  throw new Error(
9881
10125
  `Scaffolded manifest declares name '${manifest.name}', expected '${names.slug}'. The skeleton's manifest name may have diverged from 'example-plugin'.`
@@ -9884,6 +10128,7 @@ async function runPluginCreate(name, options, deps) {
9884
10128
  log.success(
9885
10129
  `Manifest valid \u2014 ${manifest.tables.length} table(s), ${manifest.api_routes.length} route(s)`
9886
10130
  );
10131
+ applyWorkspaceSources(destDir, options.cwd, relDir);
9887
10132
  if (options.commit) {
9888
10133
  if (!await deps.git.isGitRepo(options.cwd)) {
9889
10134
  throw new Error(
@@ -9898,8 +10143,8 @@ async function runPluginCreate(name, options, deps) {
9898
10143
  printNextSteps(names, relDir, channel);
9899
10144
  }
9900
10145
  async function runStandaloneCreate(names, options, deps) {
9901
- const destDir = join31(options.cwd, names.dist);
9902
- if (existsSync31(destDir)) {
10146
+ const destDir = join32(options.cwd, names.dist);
10147
+ if (existsSync32(destDir)) {
9903
10148
  throw new Error(`${names.dist}/ already exists. Choose a different name, or remove it first.`);
9904
10149
  }
9905
10150
  const skeletonRoot = resolveSkeletonRoot(options);
@@ -9917,7 +10162,7 @@ async function runStandaloneCreate(names, options, deps) {
9917
10162
  restorePackagedDotfiles(destDir);
9918
10163
  log.success(`Scaffolded ${String(files.length)} file(s) into ${names.dist}/`);
9919
10164
  const manifest = validateManifest(
9920
- JSON.parse(readFileSync22(join31(destDir, "biffo.plugin.json"), "utf8"))
10165
+ JSON.parse(readFileSync23(join32(destDir, "biffo.plugin.json"), "utf8"))
9921
10166
  );
9922
10167
  if (manifest.name !== names.slug) {
9923
10168
  throw new Error(
@@ -9927,13 +10172,13 @@ async function runStandaloneCreate(names, options, deps) {
9927
10172
  log.success(
9928
10173
  `Manifest valid \u2014 ${String(manifest.tables.length)} table(s), ${String(manifest.api_routes.length)} route(s)`
9929
10174
  );
9930
- writeFileSync10(
9931
- join31(destDir, ".biffo-shared-version"),
10175
+ writeFileSync11(
10176
+ join32(destDir, ".biffo-shared-version"),
9932
10177
  `core-v${getLatestCoreVersion().replace(/^core-v/, "")}
9933
10178
  `
9934
10179
  );
9935
10180
  if (options.commit) {
9936
- if (!existsSync31(join31(destDir, "uv.lock"))) {
10181
+ if (!existsSync32(join32(destDir, "uv.lock"))) {
9937
10182
  throw new Error(
9938
10183
  `Scaffolded plugin at ${destDir} has no uv.lock. The standalone layout must carry a substituted uv.lock (see plugin-scaffold.ts STANDALONE_ONLY_ENTRIES) so the first commit's CI run can satisfy 'uv sync --locked'. Refusing to commit a repo that would ship red on its very first push (issue #1769) \u2014 run 'uv lock' in ${destDir} first.`
9939
10184
  );
@@ -9966,8 +10211,8 @@ async function createAndPushStandaloneRepo(org, names, destDir, options, deps) {
9966
10211
  await deps.git.push(destDir, "dev", { token });
9967
10212
  log.success(`Pushed dev to ${org}/${names.dist}`);
9968
10213
  await github.setDefaultBranch(org, names.dist, "dev");
9969
- const ciPath = join31(destDir, ".github", "workflows", "ci.yml");
9970
- const contexts = existsSync31(ciPath) ? workflowCheckContexts(readFileSync22(ciPath, "utf8")) : [];
10214
+ const ciPath = join32(destDir, ".github", "workflows", "ci.yml");
10215
+ const contexts = existsSync32(ciPath) ? workflowCheckContexts(readFileSync23(ciPath, "utf8")) : [];
9971
10216
  if (contexts.length === 0) {
9972
10217
  log.warn(
9973
10218
  `Could not determine required status checks from ${ciPath} \u2014 skipping branch protection. Configure it manually on dev once you know the CI job names.`
@@ -9996,8 +10241,8 @@ async function registerInRegistrySources(names, cloneUrl, token, deps) {
9996
10241
  let dir;
9997
10242
  try {
9998
10243
  dir = await deps.git.cloneForEditing(REGISTRY_REPO, "biffo-registry", token);
9999
- const path = join31(dir, "sources.json");
10000
- const file = JSON.parse(readFileSync22(path, "utf8"));
10244
+ const path = join32(dir, "sources.json");
10245
+ const file = JSON.parse(readFileSync23(path, "utf8"));
10001
10246
  const next = addSource(file, {
10002
10247
  name: names.slug,
10003
10248
  repo: cloneUrl.replace(/\.git$/, ""),
@@ -10008,7 +10253,7 @@ async function registerInRegistrySources(names, cloneUrl, token, deps) {
10008
10253
  log.info(`${names.slug} is already listed in the registry's sources.json`);
10009
10254
  return;
10010
10255
  }
10011
- writeFileSync10(path, serialiseSources(next));
10256
+ writeFileSync11(path, serialiseSources(next));
10012
10257
  await deps.git.add(dir, ["sources.json"]);
10013
10258
  await deps.git.commit(dir, `feat(registry): track ${names.slug} in sources.json`);
10014
10259
  await deps.git.push(dir, "main", { token });
@@ -10105,8 +10350,8 @@ function printStandaloneNextSteps(names, minor) {
10105
10350
  }
10106
10351
  function resolveSkeletonRoot(options) {
10107
10352
  const here = dirname10(fileURLToPath6(import.meta.url));
10108
- const skeletonRoot = options.skeletonRoot ?? findSkeletonRoot(here, "plugin-template") ?? join31(options.cwd, "_skeletons", "plugin-template");
10109
- if (!existsSync31(skeletonRoot)) {
10353
+ const skeletonRoot = options.skeletonRoot ?? findSkeletonRoot(here, "plugin-template") ?? join32(options.cwd, "_skeletons", "plugin-template");
10354
+ if (!existsSync32(skeletonRoot)) {
10110
10355
  throw new Error(
10111
10356
  `Could not find the plugin skeleton (_skeletons/plugin-template/). Pass --skeleton <path> to point at it explicitly.`
10112
10357
  );
@@ -10342,7 +10587,7 @@ import chalk15 from "chalk";
10342
10587
  import { Command as Command16 } from "commander";
10343
10588
 
10344
10589
  // src/adapters/plugin-migrations/index.ts
10345
- import { join as join32 } from "path";
10590
+ import { join as join33 } from "path";
10346
10591
  var PluginMigrationsAdapter = class {
10347
10592
  /**
10348
10593
  * Generates migration file(s) for `pluginNames` (every discovered
@@ -10351,40 +10596,53 @@ var PluginMigrationsAdapter = class {
10351
10596
  * or declared no tables.
10352
10597
  */
10353
10598
  async generate(cwd, pluginNames) {
10354
- const scriptPath = join32(cwd, "services", "api", "scripts", "generate_plugin_migrations.py");
10599
+ const scriptPath = join33(cwd, "services", "api", "scripts", "generate_plugin_migrations.py");
10355
10600
  const args = [
10356
10601
  "run",
10357
10602
  "python",
10358
10603
  scriptPath,
10359
10604
  "--services-root",
10360
- join32(cwd, "services"),
10605
+ join33(cwd, "services"),
10361
10606
  "--versions-dir",
10362
- join32(cwd, "services", "api", "migrations", "versions")
10607
+ join33(cwd, "services", "api", "migrations", "versions")
10363
10608
  ];
10364
10609
  for (const name of pluginNames ?? []) {
10365
10610
  args.push("--plugin", name);
10366
10611
  }
10367
- let result;
10368
- try {
10369
- result = await execa("uv", args, { cwd: join32(cwd, "services", "api") });
10370
- } catch (err) {
10371
- const cause = err;
10372
- if (cause.code === "ENOENT") {
10373
- throw new Error(
10374
- "biffo plugin install/upgrade/sync-migrations needs `uv` (Python) on PATH to generate a real migration file \u2014 see https://docs.astral.sh/uv/ to install it. Once installed, re-run this command (or `biffo plugin sync-migrations <name>` if services/<name>/ is already copied in)."
10375
- );
10376
- }
10377
- throw new Error(
10378
- `Failed to generate plugin migration: ${cause.stderr?.trim() || err.message}`
10379
- );
10380
- }
10612
+ const result = await runUv(args, join33(cwd, "services", "api"), {
10613
+ missing: "biffo plugin install/upgrade/sync-migrations needs `uv` (Python) on PATH to generate a real migration file \u2014 see https://docs.astral.sh/uv/ to install it. Once installed, re-run this command (or `biffo plugin sync-migrations <name>` if services/<name>/ is already copied in).",
10614
+ failed: "Failed to generate plugin migration"
10615
+ });
10381
10616
  return result.stdout.split("\n").map((line) => line.trim()).filter(Boolean);
10382
10617
  }
10618
+ /**
10619
+ * Brings the instance's root `uv.lock` in step with its workspace (`uv lock`).
10620
+ *
10621
+ * `plugin install` adds a member to the uv workspace, so the committed lock is stale the moment the plugin lands — whether or
10622
+ * not the plugin has tables (only a table-bearing plugin runs `uv run` for a migration, which is a side effect that happens to
10623
+ * re-lock). Locking explicitly, then staging the result, is what makes `uv lock --check` pass on the install commit
10624
+ * (biffo-template#2106); leaving it to whichever `uv run` came last is how the no-tables install shipped a stale lock.
10625
+ */
10626
+ async refreshLock(cwd) {
10627
+ await runUv(["lock"], cwd, {
10628
+ missing: "biffo plugin install needs `uv` (Python) on PATH to refresh uv.lock for the workspace member it adds \u2014 see https://docs.astral.sh/uv/ to install it, then run `uv lock` and commit uv.lock yourself.",
10629
+ failed: "Failed to refresh uv.lock (`uv lock`)"
10630
+ });
10631
+ }
10383
10632
  };
10633
+ async function runUv(args, cwd, messages) {
10634
+ try {
10635
+ return await execa("uv", args, { cwd });
10636
+ } catch (err) {
10637
+ const cause = err;
10638
+ if (cause.code === "ENOENT") throw new Error(messages.missing);
10639
+ throw new Error(`${messages.failed}: ${cause.stderr?.trim() || err.message}`);
10640
+ }
10641
+ }
10384
10642
 
10385
10643
  // src/lib/plugin-frontend-registry.ts
10386
- import { existsSync as existsSync32, readFileSync as readFileSync23, writeFileSync as writeFileSync11 } from "fs";
10387
- import { join as join33 } from "path";
10644
+ import { existsSync as existsSync33, readFileSync as readFileSync24, writeFileSync as writeFileSync12 } from "fs";
10645
+ import { join as join34 } from "path";
10388
10646
  var PLUGIN_REGISTRY_RELATIVE_PATH = "apps/frontend/src/lib/plugins.ts";
10389
10647
  var REGISTRY_START_MARKER = "// BIFFO-PLUGIN-REGISTRY:START \u2014 managed by `biffo plugin install`/`uninstall`. Do not hand-edit.";
10390
10648
  var REGISTRY_END_MARKER = "// BIFFO-PLUGIN-REGISTRY:END";
@@ -10395,7 +10653,7 @@ function frontendUrlForSlug(slug) {
10395
10653
  return `/api/v1/plugins/${slug}/ui`;
10396
10654
  }
10397
10655
  function registryPath2(cwd) {
10398
- return join33(cwd, PLUGIN_REGISTRY_RELATIVE_PATH);
10656
+ return join34(cwd, PLUGIN_REGISTRY_RELATIVE_PATH);
10399
10657
  }
10400
10658
  function missingRegistryError(cwd, pluginSlug) {
10401
10659
  return new Error(
@@ -10472,8 +10730,8 @@ function assertPluginRegistryReady(cwd, pluginSlug) {
10472
10730
  }
10473
10731
  function readManagedEntries(cwd, pluginSlug) {
10474
10732
  const path = registryPath2(cwd);
10475
- if (!existsSync32(path)) throw missingRegistryError(cwd, pluginSlug);
10476
- const source = readFileSync23(path, "utf8");
10733
+ if (!existsSync33(path)) throw missingRegistryError(cwd, pluginSlug);
10734
+ const source = readFileSync24(path, "utf8");
10477
10735
  const found = findManagedRegion(source);
10478
10736
  if (!found) throw malformedRegistryError(cwd, pluginSlug);
10479
10737
  return { source, region: found.region, entries: splitEntries(found.body) };
@@ -10481,7 +10739,7 @@ function readManagedEntries(cwd, pluginSlug) {
10481
10739
  function writeManagedEntries(cwd, region, entries) {
10482
10740
  const body = entries.length > 0 ? "\n" + entries.map((e) => ` {${e.raw}},
10483
10741
  `).join("") : "\n";
10484
- writeFileSync11(registryPath2(cwd), region.before + body + region.after, "utf8");
10742
+ writeFileSync12(registryPath2(cwd), region.before + body + region.after, "utf8");
10485
10743
  }
10486
10744
  function upsertPluginRegistryEntry(cwd, entry) {
10487
10745
  const { region, entries } = readManagedEntries(cwd, entry.slug);
@@ -10496,8 +10754,8 @@ function removePluginRegistryEntry(cwd, pluginSlug) {
10496
10754
  }
10497
10755
 
10498
10756
  // src/lib/plugin-provenance.ts
10499
- import { existsSync as existsSync33, readFileSync as readFileSync24, writeFileSync as writeFileSync12 } from "fs";
10500
- import { join as join34 } from "path";
10757
+ import { existsSync as existsSync34, readFileSync as readFileSync25, writeFileSync as writeFileSync13 } from "fs";
10758
+ import { join as join35 } from "path";
10501
10759
  var PLUGIN_PROVENANCE_FILENAME = ".biffo-plugin-provenance.json";
10502
10760
  function isPluginProvenance(value) {
10503
10761
  if (typeof value !== "object" || value === null) return false;
@@ -10505,11 +10763,11 @@ function isPluginProvenance(value) {
10505
10763
  return typeof v["origin"] === "string" && (typeof v["ref"] === "string" || v["ref"] === null) && (typeof v["sha"] === "string" || v["sha"] === null) && typeof v["recordedAt"] === "string" && typeof v["inTree"] === "boolean";
10506
10764
  }
10507
10765
  function readProvenance(pluginDir2) {
10508
- const path = join34(pluginDir2, PLUGIN_PROVENANCE_FILENAME);
10509
- if (!existsSync33(path)) return { status: "absent" };
10766
+ const path = join35(pluginDir2, PLUGIN_PROVENANCE_FILENAME);
10767
+ if (!existsSync34(path)) return { status: "absent" };
10510
10768
  let parsed;
10511
10769
  try {
10512
- parsed = JSON.parse(readFileSync24(path, "utf8"));
10770
+ parsed = JSON.parse(readFileSync25(path, "utf8"));
10513
10771
  } catch (err) {
10514
10772
  return {
10515
10773
  status: "invalid",
@@ -10525,7 +10783,7 @@ function readProvenance(pluginDir2) {
10525
10783
  return { status: "present", record: parsed };
10526
10784
  }
10527
10785
  function writePluginProvenance(pluginDir2, record) {
10528
- writeFileSync12(join34(pluginDir2, PLUGIN_PROVENANCE_FILENAME), `${JSON.stringify(record, null, 2)}
10786
+ writeFileSync13(join35(pluginDir2, PLUGIN_PROVENANCE_FILENAME), `${JSON.stringify(record, null, 2)}
10529
10787
  `);
10530
10788
  }
10531
10789
  function reconcileProvenance(previous, next) {
@@ -10575,8 +10833,8 @@ async function tryGit(cwd, args) {
10575
10833
  }
10576
10834
 
10577
10835
  // src/lib/plugin-seed-vendor.ts
10578
- import { cpSync as cpSync3, existsSync as existsSync34, mkdirSync as mkdirSync10, readdirSync as readdirSync12, rmSync as rmSync9 } from "fs";
10579
- import { join as join35 } from "path";
10836
+ import { cpSync as cpSync3, existsSync as existsSync35, mkdirSync as mkdirSync10, readdirSync as readdirSync13, rmSync as rmSync9 } from "fs";
10837
+ import { join as join36 } from "path";
10580
10838
  var VENDOR_PREFIX = "_plugin-";
10581
10839
  function pluginSeedImportDir(pluginName) {
10582
10840
  return `db/imports/${VENDOR_PREFIX}${pluginName}`;
@@ -10585,24 +10843,24 @@ function vendorPluginSeed(pluginSourceDir, manifest, cwd) {
10585
10843
  if (!manifest.seed) {
10586
10844
  return { vendored: false };
10587
10845
  }
10588
- const sourceSeedDir = join35(pluginSourceDir, manifest.seed.dir);
10589
- if (!existsSync34(sourceSeedDir)) {
10846
+ const sourceSeedDir = join36(pluginSourceDir, manifest.seed.dir);
10847
+ if (!existsSync35(sourceSeedDir)) {
10590
10848
  throw new Error(
10591
10849
  `${manifest.name}'s manifest declares seed.dir '${manifest.seed.dir}', but ${sourceSeedDir} does not exist in the plugin's source.`
10592
10850
  );
10593
10851
  }
10594
- const sqlFiles = readdirSync12(sourceSeedDir).filter((f) => f.endsWith(".sql"));
10852
+ const sqlFiles = readdirSync13(sourceSeedDir).filter((f) => f.endsWith(".sql"));
10595
10853
  if (sqlFiles.length === 0) {
10596
10854
  throw new Error(
10597
10855
  `${manifest.name}'s manifest declares seed.dir '${manifest.seed.dir}', but ${sourceSeedDir} contains no *.sql files.`
10598
10856
  );
10599
10857
  }
10600
10858
  const relTargetDir = pluginSeedImportDir(manifest.name);
10601
- const targetDir = join35(cwd, relTargetDir);
10859
+ const targetDir = join36(cwd, relTargetDir);
10602
10860
  rmSync9(targetDir, { recursive: true, force: true });
10603
10861
  mkdirSync10(targetDir, { recursive: true });
10604
10862
  for (const file of sqlFiles) {
10605
- cpSync3(join35(sourceSeedDir, file), join35(targetDir, file));
10863
+ cpSync3(join36(sourceSeedDir, file), join36(targetDir, file));
10606
10864
  }
10607
10865
  log.success(
10608
10866
  `Vendored ${sqlFiles.length} seed file(s) to ${relTargetDir}/ (baseline_tables: ${manifest.seed.baseline_tables.join(", ") || "none declared"})`
@@ -10615,7 +10873,7 @@ function vendorPluginSeed(pluginSourceDir, manifest, cwd) {
10615
10873
 
10616
10874
  // src/lib/plugin-source-copy.ts
10617
10875
  import { copyFileSync as copyFileSync2, cpSync as cpSync4, mkdirSync as mkdirSync11 } from "fs";
10618
- import { basename as basename2, dirname as dirname11, join as join36 } from "path";
10876
+ import { basename as basename2, dirname as dirname11, join as join37 } from "path";
10619
10877
  var LOCAL_COPY_EXCLUDES = /* @__PURE__ */ new Set([
10620
10878
  ".git",
10621
10879
  ".venv",
@@ -10631,9 +10889,9 @@ async function copyPluginSource(sourceDir, targetDir) {
10631
10889
  if (await isGitWorkingTree2(sourceDir)) {
10632
10890
  const files = await listGitFiles(sourceDir);
10633
10891
  for (const relPath of files) {
10634
- const destPath = join36(targetDir, relPath);
10892
+ const destPath = join37(targetDir, relPath);
10635
10893
  mkdirSync11(dirname11(destPath), { recursive: true });
10636
- copyFileSync2(join36(sourceDir, relPath), destPath);
10894
+ copyFileSync2(join37(sourceDir, relPath), destPath);
10637
10895
  }
10638
10896
  return { usedGitIgnoreRules: true };
10639
10897
  }
@@ -10664,125 +10922,6 @@ async function listGitFiles(dir) {
10664
10922
  return stdout.split("\0").filter((p) => p.length > 0);
10665
10923
  }
10666
10924
 
10667
- // src/lib/plugin-workspace-sources.ts
10668
- import { existsSync as existsSync35, readdirSync as readdirSync13, readFileSync as readFileSync25, writeFileSync as writeFileSync13 } from "fs";
10669
- import { join as join37 } from "path";
10670
- function readTomlStringArray(text, key) {
10671
- const open = new RegExp(`^${key}\\s*=\\s*\\[`, "m").exec(text);
10672
- if (!open) return [];
10673
- const strings = [];
10674
- let depth = 1;
10675
- let i = open.index + open[0].length;
10676
- while (i < text.length && depth > 0) {
10677
- const c = text[i];
10678
- if (c === "#") {
10679
- const nl = text.indexOf("\n", i);
10680
- i = nl === -1 ? text.length : nl;
10681
- } else if (c === '"' || c === "'") {
10682
- const close = text.indexOf(c, i + 1);
10683
- if (close === -1) break;
10684
- if (depth === 1) strings.push(text.slice(i + 1, close));
10685
- i = close + 1;
10686
- } else {
10687
- if (c === "[") depth++;
10688
- else if (c === "]") depth--;
10689
- i++;
10690
- }
10691
- }
10692
- return depth === 0 ? strings : [];
10693
- }
10694
- function readProjectName(text) {
10695
- let inProject = false;
10696
- for (const line of text.split("\n")) {
10697
- const trimmed = line.trim();
10698
- if (trimmed.startsWith("[")) {
10699
- inProject = trimmed === "[project]";
10700
- continue;
10701
- }
10702
- if (inProject) {
10703
- const m = /^name\s*=\s*["']([^"']+)["']/.exec(trimmed);
10704
- if (m) return m[1];
10705
- }
10706
- }
10707
- return null;
10708
- }
10709
- function readDependencyNames(text) {
10710
- return readTomlStringArray(text, "dependencies").map((dep) => /^\s*([A-Za-z0-9._-]+)/.exec(dep)?.[1] ?? "").filter(Boolean);
10711
- }
10712
- function workspaceMemberNames(instanceRoot) {
10713
- const rootPyproject = join37(instanceRoot, "pyproject.toml");
10714
- if (!existsSync35(rootPyproject)) return /* @__PURE__ */ new Set();
10715
- const text = readFileSync25(rootPyproject, "utf8");
10716
- const members = readTomlStringArray(text, "members");
10717
- const excluded = new Set(readTomlStringArray(text, "exclude"));
10718
- const dirs = [];
10719
- for (const member of members) {
10720
- if (member.endsWith("/*")) {
10721
- const base = member.slice(0, -2);
10722
- let entries;
10723
- try {
10724
- entries = readdirSync13(join37(instanceRoot, base), { withFileTypes: true });
10725
- } catch {
10726
- continue;
10727
- }
10728
- for (const entry of entries) {
10729
- const rel = `${base}/${entry.name}`;
10730
- if (entry.isDirectory() && !entry.name.startsWith(".") && !excluded.has(rel)) dirs.push(rel);
10731
- }
10732
- } else if (!excluded.has(member)) {
10733
- dirs.push(member);
10734
- }
10735
- }
10736
- const names = /* @__PURE__ */ new Set();
10737
- for (const dir of dirs) {
10738
- const pp = join37(instanceRoot, dir, "pyproject.toml");
10739
- if (!existsSync35(pp)) continue;
10740
- const name = readProjectName(readFileSync25(pp, "utf8"));
10741
- if (name) names.add(name);
10742
- }
10743
- return names;
10744
- }
10745
- function existingWorkspaceSources(text) {
10746
- return new Set(
10747
- [...text.matchAll(/^\s*([A-Za-z0-9._-]+)\s*=\s*\{[^}]*\bworkspace\b/gm)].map((m) => m[1])
10748
- );
10749
- }
10750
- function ensureWorkspaceSources(pluginPyprojectPath, memberNames) {
10751
- if (!existsSync35(pluginPyprojectPath) || memberNames.size === 0) return [];
10752
- const text = readFileSync25(pluginPyprojectPath, "utf8");
10753
- const already = existingWorkspaceSources(text);
10754
- const toAdd = readDependencyNames(text).filter((n) => memberNames.has(n) && !already.has(n));
10755
- if (toAdd.length === 0) return [];
10756
- const lines = toAdd.map((n) => `${n} = { workspace = true }`);
10757
- const header = /^\[tool\.uv\.sources\]\s*$/m.exec(text);
10758
- let updated;
10759
- if (header) {
10760
- const insertAt = header.index + header[0].length;
10761
- updated = `${text.slice(0, insertAt)}
10762
- ${lines.join("\n")}${text.slice(insertAt)}`;
10763
- } else {
10764
- const sep5 = text.endsWith("\n") ? "" : "\n";
10765
- updated = `${text}${sep5}
10766
- # Vendored into this instance by \`biffo plugin install\`: resolve dependencies the
10767
- # instance's uv workspace provides as members from the workspace, not PyPI.
10768
- [tool.uv.sources]
10769
- ${lines.join("\n")}
10770
- `;
10771
- }
10772
- writeFileSync13(pluginPyprojectPath, updated);
10773
- return toAdd;
10774
- }
10775
- function applyWorkspaceSources(targetDir, cwd, relTargetDir) {
10776
- const pluginPyproject = join37(targetDir, "pyproject.toml");
10777
- if (!existsSync35(pluginPyproject)) return;
10778
- const sourced = ensureWorkspaceSources(pluginPyproject, workspaceMemberNames(cwd));
10779
- if (sourced.length > 0) {
10780
- log.info(
10781
- `Sourced ${sourced.join(", ")} from the workspace in ${relTargetDir}/pyproject.toml (the instance provides it as a workspace member).`
10782
- );
10783
- }
10784
- }
10785
-
10786
10925
  // src/commands/plugin-install.ts
10787
10926
  var TARGET_PATTERN = /^([a-z][a-z0-9-]*)@(\d+\.\d+)$/;
10788
10927
  var pluginInstallCommand = new Command16("install").description(
@@ -10944,6 +11083,7 @@ async function runPluginInstall(target, options, deps) {
10944
11083
  };
10945
11084
  }
10946
11085
  const { manifest } = source;
11086
+ const left = newInstallLeftovers(options.cwd, registryCwd);
10947
11087
  try {
10948
11088
  log.success(
10949
11089
  `Manifest valid \u2014 ${manifest.tables.length} table(s), ${manifest.api_routes.length} route(s)`
@@ -10974,23 +11114,30 @@ async function runPluginInstall(target, options, deps) {
10974
11114
  if (inTreeSource) {
10975
11115
  log.info(`${relTargetDir}/ is already in this checkout \u2014 installing in place.`);
10976
11116
  } else {
11117
+ left.core.written.push(relTargetDir);
10977
11118
  mkdirSync12(targetDir, { recursive: true });
10978
11119
  await copyPluginSource(source.sourceDir, targetDir);
10979
11120
  log.success(`Installed plugin source at ${relTargetDir}/`);
10980
11121
  }
10981
11122
  const previousProvenance = readProvenance(targetDir);
10982
11123
  const nextProvenance = inTreeSource ? inTreePluginProvenance(relTargetDir) : entry ? resolveRegistryProvenance(entry.repo, await deps.git.resolveDefaultBranchSha(entry.repo)) : await resolveLocalProvenance(source.sourceDir, source.origin);
11124
+ if (inTreeSource) left.core.written.push(`${relTargetDir}/${PLUGIN_PROVENANCE_FILENAME}`);
10983
11125
  writePluginProvenance(targetDir, reconcileProvenance(previousProvenance, nextProvenance));
10984
- applyWorkspaceSources(targetDir, options.cwd, relTargetDir);
11126
+ const sourced = applyWorkspaceSources(targetDir, options.cwd, relTargetDir);
11127
+ if (inTreeSource && sourced.length > 0) left.core.written.push(`${relTargetDir}/pyproject.toml`);
10985
11128
  const stagePaths = [relTargetDir];
11129
+ const track = (...paths) => {
11130
+ stagePaths.push(...paths);
11131
+ left.core.written.push(...paths);
11132
+ };
10986
11133
  const tfSourceDir = join38(targetDir, "terraform");
10987
11134
  if (existsSync36(tfSourceDir)) {
10988
11135
  mkdirSync12(modulesDir, { recursive: true });
10989
11136
  cpSync5(tfSourceDir, modulesDir, { recursive: true });
10990
- stagePaths.push(`modules/plugins/${pluginName}`);
11137
+ track(`modules/plugins/${pluginName}`);
10991
11138
  log.success(`Copied Terraform module to modules/plugins/${pluginName}/`);
10992
11139
  const wiring = syncPluginTerraform(options.cwd);
10993
- stagePaths.push(...wiring.changedPaths);
11140
+ track(...wiring.changedPaths);
10994
11141
  if (wiring.environments.length > 0) {
10995
11142
  log.success(
10996
11143
  `Wired module "plugin_${pluginName}" and enabled_plugins into ${wiring.environments.length} environment(s): ${wiring.environments.join(", ")}`
@@ -11015,9 +11162,11 @@ async function runPluginInstall(target, options, deps) {
11015
11162
  }
11016
11163
  if (manifest.tables.length > 0) {
11017
11164
  log.info(`Generating migration for ${relTargetDir}/'s ${manifest.tables.length} table(s)...`);
11165
+ left.phase = "migration";
11018
11166
  const generatedPaths = await deps.migrations.generate(options.cwd, [pluginName]);
11167
+ left.phase = "other";
11019
11168
  for (const absPath of generatedPaths) {
11020
- stagePaths.push(relative4(options.cwd, absPath));
11169
+ track(relative4(options.cwd, absPath));
11021
11170
  }
11022
11171
  if (generatedPaths.length > 0) {
11023
11172
  log.success(`Generated migration: ${relative4(options.cwd, generatedPaths[0])}`);
@@ -11027,7 +11176,7 @@ async function runPluginInstall(target, options, deps) {
11027
11176
  }
11028
11177
  const seedResult = vendorPluginSeed(targetDir, manifest, options.cwd);
11029
11178
  if (seedResult.vendored) {
11030
- stagePaths.push(seedResult.stagedPath);
11179
+ track(seedResult.stagedPath);
11031
11180
  }
11032
11181
  if (manifest.config.length > 0) {
11033
11182
  const configFilePath = join38(targetDir, "biffo.plugin-config.json");
@@ -11049,11 +11198,15 @@ async function runPluginInstall(target, options, deps) {
11049
11198
  ) + "\n",
11050
11199
  "utf8"
11051
11200
  );
11052
- stagePaths.push(relative4(options.cwd, configFilePath));
11201
+ track(relative4(options.cwd, configFilePath));
11053
11202
  log.success(
11054
11203
  `Recorded ${configSupply.resolved.length}/${manifest.config.length} declared config value(s) at ${relative4(options.cwd, configFilePath)}`
11055
11204
  );
11056
11205
  }
11206
+ if (existsSync36(join38(options.cwd, "uv.lock"))) {
11207
+ await deps.migrations.refreshLock(options.cwd);
11208
+ stagePaths.push("uv.lock");
11209
+ }
11057
11210
  if (manifest.user_frontend) {
11058
11211
  upsertPluginRegistryEntry(registryCwd, {
11059
11212
  slug: pluginName,
@@ -11062,18 +11215,27 @@ async function runPluginInstall(target, options, deps) {
11062
11215
  });
11063
11216
  if (options.frontendCwd) {
11064
11217
  const dashboardCommitMessage = `feat(plugins): register ${pluginName}@${source.version} in dashboard`;
11218
+ left.dashboard.written.push(PLUGIN_REGISTRY_RELATIVE_PATH);
11219
+ left.dashboard.stage = "partial";
11065
11220
  await deps.git.add(registryCwd, [PLUGIN_REGISTRY_RELATIVE_PATH]);
11221
+ left.dashboard.stage = "staged";
11222
+ left.dashboard.staged = [PLUGIN_REGISTRY_RELATIVE_PATH];
11066
11223
  await deps.git.commit(registryCwd, dashboardCommitMessage);
11224
+ left.dashboard.stage = "committed";
11225
+ left.dashboard.committed = dashboardCommitMessage;
11067
11226
  log.success(
11068
11227
  `Registered ${pluginName} in ${registryCwd}/${PLUGIN_REGISTRY_RELATIVE_PATH} (committed there: "${dashboardCommitMessage}")`
11069
11228
  );
11070
11229
  } else {
11071
- stagePaths.push(PLUGIN_REGISTRY_RELATIVE_PATH);
11230
+ track(PLUGIN_REGISTRY_RELATIVE_PATH);
11072
11231
  log.success(`Registered ${pluginName} in ${PLUGIN_REGISTRY_RELATIVE_PATH}`);
11073
11232
  }
11074
11233
  }
11075
11234
  const commitMessage = `feat(plugins): install ${pluginName}@${source.version}`;
11235
+ left.core.stage = "partial";
11076
11236
  await deps.git.add(options.cwd, stagePaths);
11237
+ left.core.stage = "staged";
11238
+ left.core.staged = stagePaths;
11077
11239
  await deps.git.commit(options.cwd, commitMessage);
11078
11240
  log.success(`Committed: ${commitMessage}`);
11079
11241
  console.log(chalk15.bold("\n Plugin installed!\n"));
@@ -11091,10 +11253,53 @@ async function runPluginInstall(target, options, deps) {
11091
11253
  console.log(chalk15.dim(` biffo deploy <environment> --app-only
11092
11254
  `));
11093
11255
  printConfigWiringInstructions(pluginName, configSupply.resolved);
11256
+ } catch (err) {
11257
+ throw withLeftovers(err, left, pluginName);
11094
11258
  } finally {
11095
11259
  source.cleanup();
11096
11260
  }
11097
11261
  }
11262
+ function newInstallLeftovers(cwd, registryCwd) {
11263
+ const repo = (dir) => ({
11264
+ cwd: dir,
11265
+ written: [],
11266
+ staged: [],
11267
+ stage: "none",
11268
+ committed: null
11269
+ });
11270
+ return { core: repo(cwd), dashboard: repo(registryCwd), phase: "other" };
11271
+ }
11272
+ function withLeftovers(err, left, pluginName) {
11273
+ const repos = left.dashboard.cwd === left.core.cwd ? [left.core] : [left.core, left.dashboard];
11274
+ const lines = [];
11275
+ for (const repo of repos) {
11276
+ if (repo.stage === "partial") {
11277
+ lines.push(
11278
+ ` - \`git add\` failed part-way in ${repo.cwd}: any of ${[...repo.written, ...repo.staged].join(", ")} may be partially staged`
11279
+ );
11280
+ } else if (repo.stage === "staged") {
11281
+ lines.push(` - staged (git add), not committed, in ${repo.cwd}: ${repo.staged.join(", ")}`);
11282
+ } else if (repo.stage !== "committed" && repo.written.length > 0) {
11283
+ lines.push(` - written, not committed, in ${repo.cwd}: ${repo.written.join(", ")}`);
11284
+ }
11285
+ if (repo.committed !== null) {
11286
+ lines.push(` - already committed in ${repo.cwd}: "${repo.committed}" (not undone)`);
11287
+ }
11288
+ }
11289
+ if (lines.length === 0) return err;
11290
+ const committedElsewhere = repos.some((r) => r.committed !== null);
11291
+ const advice = left.phase === "migration" ? `Fix the error above, then \`biffo plugin sync-migrations ${pluginName}\` and commit, or discard those paths with git.` : left.core.stage === "staged" ? `Fix what the commit reported and run \`git commit\` in ${left.core.cwd}, or unstage and discard those paths with git.` : "Fix the error above and commit those paths yourself, or discard them with git.";
11292
+ const undo = committedElsewhere ? " A commit already made is not undone: `git reset --soft HEAD~1` in that checkout if you abandon the install." : "";
11293
+ const message = err instanceof Error ? err.message : String(err);
11294
+ return new Error(
11295
+ `${message}
11296
+
11297
+ biffo plugin install stopped part-way and rolled nothing back. What it left:
11298
+ ${lines.join("\n")}
11299
+ ${advice}${undo}`,
11300
+ { cause: err }
11301
+ );
11302
+ }
11098
11303
  function printConfigWiringInstructions(pluginName, resolved) {
11099
11304
  if (resolved.length === 0) return;
11100
11305
  console.log(chalk15.bold(` ${pluginName} needs these env vars on the shared plugin host:
@@ -12255,10 +12460,19 @@ function runChecksOnce(runner, cwd, dsn) {
12255
12460
  }
12256
12461
 
12257
12462
  // src/lib/plugin-verify/run-plugin-verify.ts
12463
+ var REAL_CORE_LABEL = "plugin verify (real_core)";
12258
12464
  var PG_TEST_DB_SCRIPT2 = "scripts/pg-test-db.sh";
12259
12465
  async function runPluginVerify(options, deps) {
12260
12466
  if (options.listChecks) {
12261
- return listChecks(deps.runner, options.cwd);
12467
+ const status = listChecks(deps.runner, options.cwd);
12468
+ log.info(
12469
+ "real_core composition-owned: run by `biffo plugin verify` itself via plugin-compose/compose-stack (not by `conformance run`); --no-real-core skips it"
12470
+ );
12471
+ return status;
12472
+ }
12473
+ if (options.realCore && !deps.realCore) {
12474
+ log.error("plugin verify: the real_core seam is required but no composition was wired in");
12475
+ return 2;
12262
12476
  }
12263
12477
  const script = deps.findScript(PG_TEST_DB_SCRIPT2);
12264
12478
  if (!script) {
@@ -12287,24 +12501,76 @@ async function runPluginVerify(options, deps) {
12287
12501
  return second;
12288
12502
  }
12289
12503
  log.success("plugin verify: green twice against the same database");
12290
- return 0;
12504
+ if (!options.realCore) {
12505
+ log.warn(
12506
+ "plugin verify: the real_core seam was SKIPPED (--no-real-core) -- Core + the plugin host were NOT composed, so nothing here proves the plugin starts under real Core"
12507
+ );
12508
+ return 0;
12509
+ }
12510
+ return runRealCore(options, deps.realCore);
12511
+ }
12512
+ async function runRealCore(options, real) {
12513
+ let coreRoot;
12514
+ try {
12515
+ coreRoot = real.coreRoot();
12516
+ } catch (err) {
12517
+ log.error(`${REAL_CORE_LABEL}: ${err.message}`);
12518
+ return 1;
12519
+ }
12520
+ log.info(`${REAL_CORE_LABEL}: composing Core + plugin host (the stack \`biffo dev up\` runs)`);
12521
+ const status = await runCompositionCheck(
12522
+ {
12523
+ pluginRoot: options.cwd,
12524
+ coreRoot,
12525
+ configFile: pickConfigFile(options.cwd, options.configFile),
12526
+ reload: false,
12527
+ label: REAL_CORE_LABEL,
12528
+ ...options.signal ? { signal: options.signal } : {}
12529
+ },
12530
+ real.compose,
12531
+ (line) => log.info(line)
12532
+ );
12533
+ if (status === 0) log.success("plugin verify: real_core green");
12534
+ return status;
12291
12535
  }
12292
12536
 
12293
12537
  // src/commands/plugin-verify.ts
12294
12538
  var pluginVerifyCommand = new Command22("verify").description(
12295
12539
  "Real-execution conformance harness for a plugin repo: raises a real Postgres, runs every implemented biffo_plugin_sdk.conformance check twice against it, and exits non-zero on the first failure (biffo-template#1523/#1924)."
12296
- ).option("--cwd <path>", "Plugin repo root to check (defaults to the current directory)").option("--list-checks", "Print every declared #1523 seam and its implemented state, then exit").action(async (options) => {
12297
- const cwd = options.cwd ? resolve20(options.cwd) : process.cwd();
12298
- const here = dirname12(fileURLToPath7(import.meta.url));
12299
- const exitCode = await runPluginVerify(
12300
- { cwd, listChecks: options.listChecks ?? false },
12301
- {
12302
- runner: new RealCommandRunner(),
12303
- findScript: (relativePath) => findPackagedScript(here, relativePath)
12304
- }
12305
- );
12306
- process.exit(exitCode);
12307
- });
12540
+ ).option("--cwd <path>", "Plugin repo root to check (defaults to the current directory)").option("--list-checks", "Print every declared #1523 seam and its implemented state, then exit").option("--core-root <path>", "A biffo-template checkout to run Core from (or BIFFO_CORE_ROOT)").option(
12541
+ "--config-file <path>",
12542
+ "Local plugin config JSON for the real_core composition (default: biffo.dev.json if present)"
12543
+ ).option(
12544
+ "--no-real-core",
12545
+ "SKIP the real_core seam (Core + plugin host composition) \u2014 loud, never silent"
12546
+ ).action(
12547
+ async (options) => {
12548
+ const cwd = options.cwd ? resolve20(options.cwd) : process.cwd();
12549
+ const here = dirname12(fileURLToPath7(import.meta.url));
12550
+ const runner = new RealCommandRunner();
12551
+ const findScript = (relativePath) => findPackagedScript(here, relativePath);
12552
+ const interrupt = installInterruptSignal();
12553
+ const exitCode = await runPluginVerify(
12554
+ {
12555
+ cwd,
12556
+ listChecks: options.listChecks ?? false,
12557
+ realCore: options.realCore,
12558
+ ...options.configFile ? { configFile: resolve20(options.configFile) } : {},
12559
+ signal: interrupt.signal
12560
+ },
12561
+ {
12562
+ runner,
12563
+ findScript,
12564
+ realCore: {
12565
+ coreRoot: () => resolveCoreRootForCli(options.coreRoot, runner),
12566
+ compose: realComposeDeps(runner, findScript, (l) => log.info(l))
12567
+ }
12568
+ }
12569
+ );
12570
+ interrupt.dispose();
12571
+ process.exit(exitCode);
12572
+ }
12573
+ );
12308
12574
 
12309
12575
  // src/commands/plugin.ts
12310
12576
  var pluginCommand = new Command23("plugin").description("Manage Biffo plugins");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.323.0",
3
+ "version": "0.324.1",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -63,6 +63,7 @@
63
63
  "execa": "^9.5.2",
64
64
  "inquirer": "^12.3.0",
65
65
  "ora": "^8.1.1",
66
+ "smol-toml": "^1.9.0",
66
67
  "zod": "^3.24.1"
67
68
  },
68
69
  "devDependencies": {