@biffo/cli 0.324.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 +401 -204
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -9563,8 +9563,8 @@ async function promptForConfig(awsAccountId, awsRegion, awsProfile) {
9563
9563
  import { Command as Command23 } from "commander";
9564
9564
 
9565
9565
  // src/commands/plugin-create.ts
9566
- import { existsSync as existsSync31, readFileSync as readFileSync22, writeFileSync as writeFileSync10 } from "fs";
9567
- 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";
9568
9568
  import { fileURLToPath as fileURLToPath6 } from "url";
9569
9569
  import chalk13 from "chalk";
9570
9570
  import { Command as Command14 } from "commander";
@@ -9664,18 +9664,254 @@ function findInstalledPlugins(cwd) {
9664
9664
  ].sort((a, b) => a.relDir.localeCompare(b.relDir));
9665
9665
  }
9666
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
+
9667
9903
  // src/lib/plugin-scaffold.ts
9668
9904
  import {
9669
9905
  chmodSync as chmodSync2,
9670
9906
  copyFileSync,
9671
- existsSync as existsSync30,
9907
+ existsSync as existsSync31,
9672
9908
  mkdirSync as mkdirSync9,
9673
- readFileSync as readFileSync21,
9674
- readdirSync as readdirSync11,
9909
+ readFileSync as readFileSync22,
9910
+ readdirSync as readdirSync12,
9675
9911
  statSync as statSync7,
9676
- writeFileSync as writeFileSync9
9912
+ writeFileSync as writeFileSync10
9677
9913
  } from "fs";
9678
- import { dirname as dirname9, join as join30 } from "path";
9914
+ import { dirname as dirname9, join as join31 } from "path";
9679
9915
  var STANDALONE_ONLY_ENTRIES = {
9680
9916
  ".github": "standalone-repo CI/release workflows \u2014 the host monorepo already runs lint/type/test/security over services/",
9681
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",
@@ -9729,10 +9965,10 @@ function applySubstitutions(text, names) {
9729
9965
  var BINARY_EXTENSIONS = /\.(png|jpe?g|gif|ico|woff2?|ttf|zip|gz)$/i;
9730
9966
  function scaffoldPlugin(skeletonRoot, destDir, names, options = {}) {
9731
9967
  const layout = options.layout ?? "in-tree";
9732
- if (!existsSync30(skeletonRoot)) {
9968
+ if (!existsSync31(skeletonRoot)) {
9733
9969
  throw new Error(`Plugin skeleton not found at ${skeletonRoot}`);
9734
9970
  }
9735
- if (!existsSync30(join30(skeletonRoot, "terraform"))) {
9971
+ if (!existsSync31(join31(skeletonRoot, "terraform"))) {
9736
9972
  throw new Error(
9737
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.`
9738
9974
  );
@@ -9740,8 +9976,8 @@ function scaffoldPlugin(skeletonRoot, destDir, names, options = {}) {
9740
9976
  const skipped = [];
9741
9977
  const files = [];
9742
9978
  const walk2 = (relDir) => {
9743
- const absDir = join30(skeletonRoot, relDir);
9744
- 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(
9745
9981
  (a, b) => a.name.localeCompare(b.name)
9746
9982
  )) {
9747
9983
  if (NEVER_COPY.has(entry.name)) continue;
@@ -9755,13 +9991,13 @@ function scaffoldPlugin(skeletonRoot, destDir, names, options = {}) {
9755
9991
  continue;
9756
9992
  }
9757
9993
  const destRel = applySubstitutions(relPath, names);
9758
- const destPath = join30(destDir, destRel);
9994
+ const destPath = join31(destDir, destRel);
9759
9995
  mkdirSync9(dirname9(destPath), { recursive: true });
9760
- const srcPath = join30(skeletonRoot, relPath);
9996
+ const srcPath = join31(skeletonRoot, relPath);
9761
9997
  if (BINARY_EXTENSIONS.test(entry.name)) {
9762
9998
  copyFileSync(srcPath, destPath);
9763
9999
  } else {
9764
- writeFileSync9(destPath, applySubstitutions(readFileSync21(srcPath, "utf8"), names));
10000
+ writeFileSync10(destPath, applySubstitutions(readFileSync22(srcPath, "utf8"), names));
9765
10001
  chmodSync2(destPath, statSync7(srcPath).mode);
9766
10002
  }
9767
10003
  files.push(destRel);
@@ -9778,8 +10014,8 @@ function scaffoldPlugin(skeletonRoot, destDir, names, options = {}) {
9778
10014
  function findSkeletonRoot(startDir, skeleton) {
9779
10015
  let dir = startDir;
9780
10016
  for (; ; ) {
9781
- const candidate = join30(dir, "_skeletons", skeleton);
9782
- if (existsSync30(candidate)) return candidate;
10017
+ const candidate = join31(dir, "_skeletons", skeleton);
10018
+ if (existsSync31(candidate)) return candidate;
9783
10019
  const parent = dirname9(dir);
9784
10020
  if (parent === dir) return null;
9785
10021
  dir = parent;
@@ -9847,7 +10083,7 @@ async function runPluginCreate(name, options, deps) {
9847
10083
  reportBranchProtectionSummary();
9848
10084
  return;
9849
10085
  }
9850
- const isInstance = existsSync31(join31(options.cwd, INSTANCE_CORE_FILE));
10086
+ const isInstance = existsSync32(join32(options.cwd, INSTANCE_CORE_FILE));
9851
10087
  if (options.firstParty && isInstance) {
9852
10088
  throw new Error(
9853
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.`
@@ -9855,19 +10091,19 @@ async function runPluginCreate(name, options, deps) {
9855
10091
  }
9856
10092
  const channel = options.firstParty ? "first-party" : "third-party";
9857
10093
  const relDir = pluginDir(names.slug, channel);
9858
- const destDir = join31(options.cwd, relDir);
9859
- const servicesDir = join31(options.cwd, "services");
9860
- if (!existsSync31(servicesDir)) {
10094
+ const destDir = join32(options.cwd, relDir);
10095
+ const servicesDir = join32(options.cwd, "services");
10096
+ if (!existsSync32(servicesDir)) {
9861
10097
  throw new Error(
9862
10098
  `${servicesDir} does not exist \u2014 is ${options.cwd} the root of a Biffo project checkout?`
9863
10099
  );
9864
10100
  }
9865
- if (existsSync31(destDir)) {
10101
+ if (existsSync32(destDir)) {
9866
10102
  throw new Error(`${relDir}/ already exists. Choose a different name, or remove it first.`);
9867
10103
  }
9868
10104
  const here = dirname10(fileURLToPath6(import.meta.url));
9869
- const skeletonRoot = options.skeletonRoot ?? findSkeletonRoot(here, "plugin-template") ?? join31(options.cwd, "_skeletons", "plugin-template");
9870
- if (!existsSync31(skeletonRoot)) {
10105
+ const skeletonRoot = options.skeletonRoot ?? findSkeletonRoot(here, "plugin-template") ?? join32(options.cwd, "_skeletons", "plugin-template");
10106
+ if (!existsSync32(skeletonRoot)) {
9871
10107
  throw new Error(
9872
10108
  `Could not find the plugin skeleton (_skeletons/plugin-template/). Pass --skeleton <path> to point at it explicitly.`
9873
10109
  );
@@ -9882,8 +10118,8 @@ async function runPluginCreate(name, options, deps) {
9882
10118
  for (const { entry, reason } of skipped) {
9883
10119
  log.info(`Skipped ${entry} \u2014 ${reason}`);
9884
10120
  }
9885
- const manifestPath = join31(destDir, "biffo.plugin.json");
9886
- 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")));
9887
10123
  if (manifest.name !== names.slug) {
9888
10124
  throw new Error(
9889
10125
  `Scaffolded manifest declares name '${manifest.name}', expected '${names.slug}'. The skeleton's manifest name may have diverged from 'example-plugin'.`
@@ -9892,6 +10128,7 @@ async function runPluginCreate(name, options, deps) {
9892
10128
  log.success(
9893
10129
  `Manifest valid \u2014 ${manifest.tables.length} table(s), ${manifest.api_routes.length} route(s)`
9894
10130
  );
10131
+ applyWorkspaceSources(destDir, options.cwd, relDir);
9895
10132
  if (options.commit) {
9896
10133
  if (!await deps.git.isGitRepo(options.cwd)) {
9897
10134
  throw new Error(
@@ -9906,8 +10143,8 @@ async function runPluginCreate(name, options, deps) {
9906
10143
  printNextSteps(names, relDir, channel);
9907
10144
  }
9908
10145
  async function runStandaloneCreate(names, options, deps) {
9909
- const destDir = join31(options.cwd, names.dist);
9910
- if (existsSync31(destDir)) {
10146
+ const destDir = join32(options.cwd, names.dist);
10147
+ if (existsSync32(destDir)) {
9911
10148
  throw new Error(`${names.dist}/ already exists. Choose a different name, or remove it first.`);
9912
10149
  }
9913
10150
  const skeletonRoot = resolveSkeletonRoot(options);
@@ -9925,7 +10162,7 @@ async function runStandaloneCreate(names, options, deps) {
9925
10162
  restorePackagedDotfiles(destDir);
9926
10163
  log.success(`Scaffolded ${String(files.length)} file(s) into ${names.dist}/`);
9927
10164
  const manifest = validateManifest(
9928
- JSON.parse(readFileSync22(join31(destDir, "biffo.plugin.json"), "utf8"))
10165
+ JSON.parse(readFileSync23(join32(destDir, "biffo.plugin.json"), "utf8"))
9929
10166
  );
9930
10167
  if (manifest.name !== names.slug) {
9931
10168
  throw new Error(
@@ -9935,13 +10172,13 @@ async function runStandaloneCreate(names, options, deps) {
9935
10172
  log.success(
9936
10173
  `Manifest valid \u2014 ${String(manifest.tables.length)} table(s), ${String(manifest.api_routes.length)} route(s)`
9937
10174
  );
9938
- writeFileSync10(
9939
- join31(destDir, ".biffo-shared-version"),
10175
+ writeFileSync11(
10176
+ join32(destDir, ".biffo-shared-version"),
9940
10177
  `core-v${getLatestCoreVersion().replace(/^core-v/, "")}
9941
10178
  `
9942
10179
  );
9943
10180
  if (options.commit) {
9944
- if (!existsSync31(join31(destDir, "uv.lock"))) {
10181
+ if (!existsSync32(join32(destDir, "uv.lock"))) {
9945
10182
  throw new Error(
9946
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.`
9947
10184
  );
@@ -9974,8 +10211,8 @@ async function createAndPushStandaloneRepo(org, names, destDir, options, deps) {
9974
10211
  await deps.git.push(destDir, "dev", { token });
9975
10212
  log.success(`Pushed dev to ${org}/${names.dist}`);
9976
10213
  await github.setDefaultBranch(org, names.dist, "dev");
9977
- const ciPath = join31(destDir, ".github", "workflows", "ci.yml");
9978
- 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")) : [];
9979
10216
  if (contexts.length === 0) {
9980
10217
  log.warn(
9981
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.`
@@ -10004,8 +10241,8 @@ async function registerInRegistrySources(names, cloneUrl, token, deps) {
10004
10241
  let dir;
10005
10242
  try {
10006
10243
  dir = await deps.git.cloneForEditing(REGISTRY_REPO, "biffo-registry", token);
10007
- const path = join31(dir, "sources.json");
10008
- const file = JSON.parse(readFileSync22(path, "utf8"));
10244
+ const path = join32(dir, "sources.json");
10245
+ const file = JSON.parse(readFileSync23(path, "utf8"));
10009
10246
  const next = addSource(file, {
10010
10247
  name: names.slug,
10011
10248
  repo: cloneUrl.replace(/\.git$/, ""),
@@ -10016,7 +10253,7 @@ async function registerInRegistrySources(names, cloneUrl, token, deps) {
10016
10253
  log.info(`${names.slug} is already listed in the registry's sources.json`);
10017
10254
  return;
10018
10255
  }
10019
- writeFileSync10(path, serialiseSources(next));
10256
+ writeFileSync11(path, serialiseSources(next));
10020
10257
  await deps.git.add(dir, ["sources.json"]);
10021
10258
  await deps.git.commit(dir, `feat(registry): track ${names.slug} in sources.json`);
10022
10259
  await deps.git.push(dir, "main", { token });
@@ -10113,8 +10350,8 @@ function printStandaloneNextSteps(names, minor) {
10113
10350
  }
10114
10351
  function resolveSkeletonRoot(options) {
10115
10352
  const here = dirname10(fileURLToPath6(import.meta.url));
10116
- const skeletonRoot = options.skeletonRoot ?? findSkeletonRoot(here, "plugin-template") ?? join31(options.cwd, "_skeletons", "plugin-template");
10117
- if (!existsSync31(skeletonRoot)) {
10353
+ const skeletonRoot = options.skeletonRoot ?? findSkeletonRoot(here, "plugin-template") ?? join32(options.cwd, "_skeletons", "plugin-template");
10354
+ if (!existsSync32(skeletonRoot)) {
10118
10355
  throw new Error(
10119
10356
  `Could not find the plugin skeleton (_skeletons/plugin-template/). Pass --skeleton <path> to point at it explicitly.`
10120
10357
  );
@@ -10350,7 +10587,7 @@ import chalk15 from "chalk";
10350
10587
  import { Command as Command16 } from "commander";
10351
10588
 
10352
10589
  // src/adapters/plugin-migrations/index.ts
10353
- import { join as join32 } from "path";
10590
+ import { join as join33 } from "path";
10354
10591
  var PluginMigrationsAdapter = class {
10355
10592
  /**
10356
10593
  * Generates migration file(s) for `pluginNames` (every discovered
@@ -10359,40 +10596,53 @@ var PluginMigrationsAdapter = class {
10359
10596
  * or declared no tables.
10360
10597
  */
10361
10598
  async generate(cwd, pluginNames) {
10362
- const scriptPath = join32(cwd, "services", "api", "scripts", "generate_plugin_migrations.py");
10599
+ const scriptPath = join33(cwd, "services", "api", "scripts", "generate_plugin_migrations.py");
10363
10600
  const args = [
10364
10601
  "run",
10365
10602
  "python",
10366
10603
  scriptPath,
10367
10604
  "--services-root",
10368
- join32(cwd, "services"),
10605
+ join33(cwd, "services"),
10369
10606
  "--versions-dir",
10370
- join32(cwd, "services", "api", "migrations", "versions")
10607
+ join33(cwd, "services", "api", "migrations", "versions")
10371
10608
  ];
10372
10609
  for (const name of pluginNames ?? []) {
10373
10610
  args.push("--plugin", name);
10374
10611
  }
10375
- let result;
10376
- try {
10377
- result = await execa("uv", args, { cwd: join32(cwd, "services", "api") });
10378
- } catch (err) {
10379
- const cause = err;
10380
- if (cause.code === "ENOENT") {
10381
- throw new Error(
10382
- "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)."
10383
- );
10384
- }
10385
- throw new Error(
10386
- `Failed to generate plugin migration: ${cause.stderr?.trim() || err.message}`
10387
- );
10388
- }
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
+ });
10389
10616
  return result.stdout.split("\n").map((line) => line.trim()).filter(Boolean);
10390
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
+ }
10391
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
+ }
10392
10642
 
10393
10643
  // src/lib/plugin-frontend-registry.ts
10394
- import { existsSync as existsSync32, readFileSync as readFileSync23, writeFileSync as writeFileSync11 } from "fs";
10395
- 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";
10396
10646
  var PLUGIN_REGISTRY_RELATIVE_PATH = "apps/frontend/src/lib/plugins.ts";
10397
10647
  var REGISTRY_START_MARKER = "// BIFFO-PLUGIN-REGISTRY:START \u2014 managed by `biffo plugin install`/`uninstall`. Do not hand-edit.";
10398
10648
  var REGISTRY_END_MARKER = "// BIFFO-PLUGIN-REGISTRY:END";
@@ -10403,7 +10653,7 @@ function frontendUrlForSlug(slug) {
10403
10653
  return `/api/v1/plugins/${slug}/ui`;
10404
10654
  }
10405
10655
  function registryPath2(cwd) {
10406
- return join33(cwd, PLUGIN_REGISTRY_RELATIVE_PATH);
10656
+ return join34(cwd, PLUGIN_REGISTRY_RELATIVE_PATH);
10407
10657
  }
10408
10658
  function missingRegistryError(cwd, pluginSlug) {
10409
10659
  return new Error(
@@ -10480,8 +10730,8 @@ function assertPluginRegistryReady(cwd, pluginSlug) {
10480
10730
  }
10481
10731
  function readManagedEntries(cwd, pluginSlug) {
10482
10732
  const path = registryPath2(cwd);
10483
- if (!existsSync32(path)) throw missingRegistryError(cwd, pluginSlug);
10484
- const source = readFileSync23(path, "utf8");
10733
+ if (!existsSync33(path)) throw missingRegistryError(cwd, pluginSlug);
10734
+ const source = readFileSync24(path, "utf8");
10485
10735
  const found = findManagedRegion(source);
10486
10736
  if (!found) throw malformedRegistryError(cwd, pluginSlug);
10487
10737
  return { source, region: found.region, entries: splitEntries(found.body) };
@@ -10489,7 +10739,7 @@ function readManagedEntries(cwd, pluginSlug) {
10489
10739
  function writeManagedEntries(cwd, region, entries) {
10490
10740
  const body = entries.length > 0 ? "\n" + entries.map((e) => ` {${e.raw}},
10491
10741
  `).join("") : "\n";
10492
- writeFileSync11(registryPath2(cwd), region.before + body + region.after, "utf8");
10742
+ writeFileSync12(registryPath2(cwd), region.before + body + region.after, "utf8");
10493
10743
  }
10494
10744
  function upsertPluginRegistryEntry(cwd, entry) {
10495
10745
  const { region, entries } = readManagedEntries(cwd, entry.slug);
@@ -10504,8 +10754,8 @@ function removePluginRegistryEntry(cwd, pluginSlug) {
10504
10754
  }
10505
10755
 
10506
10756
  // src/lib/plugin-provenance.ts
10507
- import { existsSync as existsSync33, readFileSync as readFileSync24, writeFileSync as writeFileSync12 } from "fs";
10508
- 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";
10509
10759
  var PLUGIN_PROVENANCE_FILENAME = ".biffo-plugin-provenance.json";
10510
10760
  function isPluginProvenance(value) {
10511
10761
  if (typeof value !== "object" || value === null) return false;
@@ -10513,11 +10763,11 @@ function isPluginProvenance(value) {
10513
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";
10514
10764
  }
10515
10765
  function readProvenance(pluginDir2) {
10516
- const path = join34(pluginDir2, PLUGIN_PROVENANCE_FILENAME);
10517
- if (!existsSync33(path)) return { status: "absent" };
10766
+ const path = join35(pluginDir2, PLUGIN_PROVENANCE_FILENAME);
10767
+ if (!existsSync34(path)) return { status: "absent" };
10518
10768
  let parsed;
10519
10769
  try {
10520
- parsed = JSON.parse(readFileSync24(path, "utf8"));
10770
+ parsed = JSON.parse(readFileSync25(path, "utf8"));
10521
10771
  } catch (err) {
10522
10772
  return {
10523
10773
  status: "invalid",
@@ -10533,7 +10783,7 @@ function readProvenance(pluginDir2) {
10533
10783
  return { status: "present", record: parsed };
10534
10784
  }
10535
10785
  function writePluginProvenance(pluginDir2, record) {
10536
- writeFileSync12(join34(pluginDir2, PLUGIN_PROVENANCE_FILENAME), `${JSON.stringify(record, null, 2)}
10786
+ writeFileSync13(join35(pluginDir2, PLUGIN_PROVENANCE_FILENAME), `${JSON.stringify(record, null, 2)}
10537
10787
  `);
10538
10788
  }
10539
10789
  function reconcileProvenance(previous, next) {
@@ -10583,8 +10833,8 @@ async function tryGit(cwd, args) {
10583
10833
  }
10584
10834
 
10585
10835
  // src/lib/plugin-seed-vendor.ts
10586
- import { cpSync as cpSync3, existsSync as existsSync34, mkdirSync as mkdirSync10, readdirSync as readdirSync12, rmSync as rmSync9 } from "fs";
10587
- 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";
10588
10838
  var VENDOR_PREFIX = "_plugin-";
10589
10839
  function pluginSeedImportDir(pluginName) {
10590
10840
  return `db/imports/${VENDOR_PREFIX}${pluginName}`;
@@ -10593,24 +10843,24 @@ function vendorPluginSeed(pluginSourceDir, manifest, cwd) {
10593
10843
  if (!manifest.seed) {
10594
10844
  return { vendored: false };
10595
10845
  }
10596
- const sourceSeedDir = join35(pluginSourceDir, manifest.seed.dir);
10597
- if (!existsSync34(sourceSeedDir)) {
10846
+ const sourceSeedDir = join36(pluginSourceDir, manifest.seed.dir);
10847
+ if (!existsSync35(sourceSeedDir)) {
10598
10848
  throw new Error(
10599
10849
  `${manifest.name}'s manifest declares seed.dir '${manifest.seed.dir}', but ${sourceSeedDir} does not exist in the plugin's source.`
10600
10850
  );
10601
10851
  }
10602
- const sqlFiles = readdirSync12(sourceSeedDir).filter((f) => f.endsWith(".sql"));
10852
+ const sqlFiles = readdirSync13(sourceSeedDir).filter((f) => f.endsWith(".sql"));
10603
10853
  if (sqlFiles.length === 0) {
10604
10854
  throw new Error(
10605
10855
  `${manifest.name}'s manifest declares seed.dir '${manifest.seed.dir}', but ${sourceSeedDir} contains no *.sql files.`
10606
10856
  );
10607
10857
  }
10608
10858
  const relTargetDir = pluginSeedImportDir(manifest.name);
10609
- const targetDir = join35(cwd, relTargetDir);
10859
+ const targetDir = join36(cwd, relTargetDir);
10610
10860
  rmSync9(targetDir, { recursive: true, force: true });
10611
10861
  mkdirSync10(targetDir, { recursive: true });
10612
10862
  for (const file of sqlFiles) {
10613
- cpSync3(join35(sourceSeedDir, file), join35(targetDir, file));
10863
+ cpSync3(join36(sourceSeedDir, file), join36(targetDir, file));
10614
10864
  }
10615
10865
  log.success(
10616
10866
  `Vendored ${sqlFiles.length} seed file(s) to ${relTargetDir}/ (baseline_tables: ${manifest.seed.baseline_tables.join(", ") || "none declared"})`
@@ -10623,7 +10873,7 @@ function vendorPluginSeed(pluginSourceDir, manifest, cwd) {
10623
10873
 
10624
10874
  // src/lib/plugin-source-copy.ts
10625
10875
  import { copyFileSync as copyFileSync2, cpSync as cpSync4, mkdirSync as mkdirSync11 } from "fs";
10626
- 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";
10627
10877
  var LOCAL_COPY_EXCLUDES = /* @__PURE__ */ new Set([
10628
10878
  ".git",
10629
10879
  ".venv",
@@ -10639,9 +10889,9 @@ async function copyPluginSource(sourceDir, targetDir) {
10639
10889
  if (await isGitWorkingTree2(sourceDir)) {
10640
10890
  const files = await listGitFiles(sourceDir);
10641
10891
  for (const relPath of files) {
10642
- const destPath = join36(targetDir, relPath);
10892
+ const destPath = join37(targetDir, relPath);
10643
10893
  mkdirSync11(dirname11(destPath), { recursive: true });
10644
- copyFileSync2(join36(sourceDir, relPath), destPath);
10894
+ copyFileSync2(join37(sourceDir, relPath), destPath);
10645
10895
  }
10646
10896
  return { usedGitIgnoreRules: true };
10647
10897
  }
@@ -10672,125 +10922,6 @@ async function listGitFiles(dir) {
10672
10922
  return stdout.split("\0").filter((p) => p.length > 0);
10673
10923
  }
10674
10924
 
10675
- // src/lib/plugin-workspace-sources.ts
10676
- import { existsSync as existsSync35, readdirSync as readdirSync13, readFileSync as readFileSync25, writeFileSync as writeFileSync13 } from "fs";
10677
- import { join as join37 } from "path";
10678
- function readTomlStringArray(text, key) {
10679
- const open = new RegExp(`^${key}\\s*=\\s*\\[`, "m").exec(text);
10680
- if (!open) return [];
10681
- const strings = [];
10682
- let depth = 1;
10683
- let i = open.index + open[0].length;
10684
- while (i < text.length && depth > 0) {
10685
- const c = text[i];
10686
- if (c === "#") {
10687
- const nl = text.indexOf("\n", i);
10688
- i = nl === -1 ? text.length : nl;
10689
- } else if (c === '"' || c === "'") {
10690
- const close = text.indexOf(c, i + 1);
10691
- if (close === -1) break;
10692
- if (depth === 1) strings.push(text.slice(i + 1, close));
10693
- i = close + 1;
10694
- } else {
10695
- if (c === "[") depth++;
10696
- else if (c === "]") depth--;
10697
- i++;
10698
- }
10699
- }
10700
- return depth === 0 ? strings : [];
10701
- }
10702
- function readProjectName(text) {
10703
- let inProject = false;
10704
- for (const line of text.split("\n")) {
10705
- const trimmed = line.trim();
10706
- if (trimmed.startsWith("[")) {
10707
- inProject = trimmed === "[project]";
10708
- continue;
10709
- }
10710
- if (inProject) {
10711
- const m = /^name\s*=\s*["']([^"']+)["']/.exec(trimmed);
10712
- if (m) return m[1];
10713
- }
10714
- }
10715
- return null;
10716
- }
10717
- function readDependencyNames(text) {
10718
- return readTomlStringArray(text, "dependencies").map((dep) => /^\s*([A-Za-z0-9._-]+)/.exec(dep)?.[1] ?? "").filter(Boolean);
10719
- }
10720
- function workspaceMemberNames(instanceRoot) {
10721
- const rootPyproject = join37(instanceRoot, "pyproject.toml");
10722
- if (!existsSync35(rootPyproject)) return /* @__PURE__ */ new Set();
10723
- const text = readFileSync25(rootPyproject, "utf8");
10724
- const members = readTomlStringArray(text, "members");
10725
- const excluded = new Set(readTomlStringArray(text, "exclude"));
10726
- const dirs = [];
10727
- for (const member of members) {
10728
- if (member.endsWith("/*")) {
10729
- const base = member.slice(0, -2);
10730
- let entries;
10731
- try {
10732
- entries = readdirSync13(join37(instanceRoot, base), { withFileTypes: true });
10733
- } catch {
10734
- continue;
10735
- }
10736
- for (const entry of entries) {
10737
- const rel = `${base}/${entry.name}`;
10738
- if (entry.isDirectory() && !entry.name.startsWith(".") && !excluded.has(rel)) dirs.push(rel);
10739
- }
10740
- } else if (!excluded.has(member)) {
10741
- dirs.push(member);
10742
- }
10743
- }
10744
- const names = /* @__PURE__ */ new Set();
10745
- for (const dir of dirs) {
10746
- const pp = join37(instanceRoot, dir, "pyproject.toml");
10747
- if (!existsSync35(pp)) continue;
10748
- const name = readProjectName(readFileSync25(pp, "utf8"));
10749
- if (name) names.add(name);
10750
- }
10751
- return names;
10752
- }
10753
- function existingWorkspaceSources(text) {
10754
- return new Set(
10755
- [...text.matchAll(/^\s*([A-Za-z0-9._-]+)\s*=\s*\{[^}]*\bworkspace\b/gm)].map((m) => m[1])
10756
- );
10757
- }
10758
- function ensureWorkspaceSources(pluginPyprojectPath, memberNames) {
10759
- if (!existsSync35(pluginPyprojectPath) || memberNames.size === 0) return [];
10760
- const text = readFileSync25(pluginPyprojectPath, "utf8");
10761
- const already = existingWorkspaceSources(text);
10762
- const toAdd = readDependencyNames(text).filter((n) => memberNames.has(n) && !already.has(n));
10763
- if (toAdd.length === 0) return [];
10764
- const lines = toAdd.map((n) => `${n} = { workspace = true }`);
10765
- const header = /^\[tool\.uv\.sources\]\s*$/m.exec(text);
10766
- let updated;
10767
- if (header) {
10768
- const insertAt = header.index + header[0].length;
10769
- updated = `${text.slice(0, insertAt)}
10770
- ${lines.join("\n")}${text.slice(insertAt)}`;
10771
- } else {
10772
- const sep5 = text.endsWith("\n") ? "" : "\n";
10773
- updated = `${text}${sep5}
10774
- # Vendored into this instance by \`biffo plugin install\`: resolve dependencies the
10775
- # instance's uv workspace provides as members from the workspace, not PyPI.
10776
- [tool.uv.sources]
10777
- ${lines.join("\n")}
10778
- `;
10779
- }
10780
- writeFileSync13(pluginPyprojectPath, updated);
10781
- return toAdd;
10782
- }
10783
- function applyWorkspaceSources(targetDir, cwd, relTargetDir) {
10784
- const pluginPyproject = join37(targetDir, "pyproject.toml");
10785
- if (!existsSync35(pluginPyproject)) return;
10786
- const sourced = ensureWorkspaceSources(pluginPyproject, workspaceMemberNames(cwd));
10787
- if (sourced.length > 0) {
10788
- log.info(
10789
- `Sourced ${sourced.join(", ")} from the workspace in ${relTargetDir}/pyproject.toml (the instance provides it as a workspace member).`
10790
- );
10791
- }
10792
- }
10793
-
10794
10925
  // src/commands/plugin-install.ts
10795
10926
  var TARGET_PATTERN = /^([a-z][a-z0-9-]*)@(\d+\.\d+)$/;
10796
10927
  var pluginInstallCommand = new Command16("install").description(
@@ -10952,6 +11083,7 @@ async function runPluginInstall(target, options, deps) {
10952
11083
  };
10953
11084
  }
10954
11085
  const { manifest } = source;
11086
+ const left = newInstallLeftovers(options.cwd, registryCwd);
10955
11087
  try {
10956
11088
  log.success(
10957
11089
  `Manifest valid \u2014 ${manifest.tables.length} table(s), ${manifest.api_routes.length} route(s)`
@@ -10982,23 +11114,30 @@ async function runPluginInstall(target, options, deps) {
10982
11114
  if (inTreeSource) {
10983
11115
  log.info(`${relTargetDir}/ is already in this checkout \u2014 installing in place.`);
10984
11116
  } else {
11117
+ left.core.written.push(relTargetDir);
10985
11118
  mkdirSync12(targetDir, { recursive: true });
10986
11119
  await copyPluginSource(source.sourceDir, targetDir);
10987
11120
  log.success(`Installed plugin source at ${relTargetDir}/`);
10988
11121
  }
10989
11122
  const previousProvenance = readProvenance(targetDir);
10990
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}`);
10991
11125
  writePluginProvenance(targetDir, reconcileProvenance(previousProvenance, nextProvenance));
10992
- 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`);
10993
11128
  const stagePaths = [relTargetDir];
11129
+ const track = (...paths) => {
11130
+ stagePaths.push(...paths);
11131
+ left.core.written.push(...paths);
11132
+ };
10994
11133
  const tfSourceDir = join38(targetDir, "terraform");
10995
11134
  if (existsSync36(tfSourceDir)) {
10996
11135
  mkdirSync12(modulesDir, { recursive: true });
10997
11136
  cpSync5(tfSourceDir, modulesDir, { recursive: true });
10998
- stagePaths.push(`modules/plugins/${pluginName}`);
11137
+ track(`modules/plugins/${pluginName}`);
10999
11138
  log.success(`Copied Terraform module to modules/plugins/${pluginName}/`);
11000
11139
  const wiring = syncPluginTerraform(options.cwd);
11001
- stagePaths.push(...wiring.changedPaths);
11140
+ track(...wiring.changedPaths);
11002
11141
  if (wiring.environments.length > 0) {
11003
11142
  log.success(
11004
11143
  `Wired module "plugin_${pluginName}" and enabled_plugins into ${wiring.environments.length} environment(s): ${wiring.environments.join(", ")}`
@@ -11023,9 +11162,11 @@ async function runPluginInstall(target, options, deps) {
11023
11162
  }
11024
11163
  if (manifest.tables.length > 0) {
11025
11164
  log.info(`Generating migration for ${relTargetDir}/'s ${manifest.tables.length} table(s)...`);
11165
+ left.phase = "migration";
11026
11166
  const generatedPaths = await deps.migrations.generate(options.cwd, [pluginName]);
11167
+ left.phase = "other";
11027
11168
  for (const absPath of generatedPaths) {
11028
- stagePaths.push(relative4(options.cwd, absPath));
11169
+ track(relative4(options.cwd, absPath));
11029
11170
  }
11030
11171
  if (generatedPaths.length > 0) {
11031
11172
  log.success(`Generated migration: ${relative4(options.cwd, generatedPaths[0])}`);
@@ -11035,7 +11176,7 @@ async function runPluginInstall(target, options, deps) {
11035
11176
  }
11036
11177
  const seedResult = vendorPluginSeed(targetDir, manifest, options.cwd);
11037
11178
  if (seedResult.vendored) {
11038
- stagePaths.push(seedResult.stagedPath);
11179
+ track(seedResult.stagedPath);
11039
11180
  }
11040
11181
  if (manifest.config.length > 0) {
11041
11182
  const configFilePath = join38(targetDir, "biffo.plugin-config.json");
@@ -11057,11 +11198,15 @@ async function runPluginInstall(target, options, deps) {
11057
11198
  ) + "\n",
11058
11199
  "utf8"
11059
11200
  );
11060
- stagePaths.push(relative4(options.cwd, configFilePath));
11201
+ track(relative4(options.cwd, configFilePath));
11061
11202
  log.success(
11062
11203
  `Recorded ${configSupply.resolved.length}/${manifest.config.length} declared config value(s) at ${relative4(options.cwd, configFilePath)}`
11063
11204
  );
11064
11205
  }
11206
+ if (existsSync36(join38(options.cwd, "uv.lock"))) {
11207
+ await deps.migrations.refreshLock(options.cwd);
11208
+ stagePaths.push("uv.lock");
11209
+ }
11065
11210
  if (manifest.user_frontend) {
11066
11211
  upsertPluginRegistryEntry(registryCwd, {
11067
11212
  slug: pluginName,
@@ -11070,18 +11215,27 @@ async function runPluginInstall(target, options, deps) {
11070
11215
  });
11071
11216
  if (options.frontendCwd) {
11072
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";
11073
11220
  await deps.git.add(registryCwd, [PLUGIN_REGISTRY_RELATIVE_PATH]);
11221
+ left.dashboard.stage = "staged";
11222
+ left.dashboard.staged = [PLUGIN_REGISTRY_RELATIVE_PATH];
11074
11223
  await deps.git.commit(registryCwd, dashboardCommitMessage);
11224
+ left.dashboard.stage = "committed";
11225
+ left.dashboard.committed = dashboardCommitMessage;
11075
11226
  log.success(
11076
11227
  `Registered ${pluginName} in ${registryCwd}/${PLUGIN_REGISTRY_RELATIVE_PATH} (committed there: "${dashboardCommitMessage}")`
11077
11228
  );
11078
11229
  } else {
11079
- stagePaths.push(PLUGIN_REGISTRY_RELATIVE_PATH);
11230
+ track(PLUGIN_REGISTRY_RELATIVE_PATH);
11080
11231
  log.success(`Registered ${pluginName} in ${PLUGIN_REGISTRY_RELATIVE_PATH}`);
11081
11232
  }
11082
11233
  }
11083
11234
  const commitMessage = `feat(plugins): install ${pluginName}@${source.version}`;
11235
+ left.core.stage = "partial";
11084
11236
  await deps.git.add(options.cwd, stagePaths);
11237
+ left.core.stage = "staged";
11238
+ left.core.staged = stagePaths;
11085
11239
  await deps.git.commit(options.cwd, commitMessage);
11086
11240
  log.success(`Committed: ${commitMessage}`);
11087
11241
  console.log(chalk15.bold("\n Plugin installed!\n"));
@@ -11099,10 +11253,53 @@ async function runPluginInstall(target, options, deps) {
11099
11253
  console.log(chalk15.dim(` biffo deploy <environment> --app-only
11100
11254
  `));
11101
11255
  printConfigWiringInstructions(pluginName, configSupply.resolved);
11256
+ } catch (err) {
11257
+ throw withLeftovers(err, left, pluginName);
11102
11258
  } finally {
11103
11259
  source.cleanup();
11104
11260
  }
11105
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
+ }
11106
11303
  function printConfigWiringInstructions(pluginName, resolved) {
11107
11304
  if (resolved.length === 0) return;
11108
11305
  console.log(chalk15.bold(` ${pluginName} needs these env vars on the shared plugin host:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.324.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": {