Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(crbn): typegen

Sidwebworks39fe6947cf5b
diff --git a/docs/scripts/generate-api-docs.mjs b/docs/scripts/generate-api-docs.mjs
index c025dbdf2b..e5e3ecb50e 100644
--- a/docs/scripts/generate-api-docs.mjs
+++ b/docs/scripts/generate-api-docs.mjs
@@ -82,6 +82,16 @@ const titleize = (s) =>
.replace(/[_-]+/g, " ")
.replace(/\b\w/g, (c) => c.toUpperCase())
.trim();
+
+// Pluralize an entity title for list-endpoint copy. Tuned to our table names:
+// many are already plural (currencies, customers, jobs) → leave them; the rest
+// follow standard English rules. Operates on the last word's ending.
+const pluralize = (word) => {
+ if (/(?:ss|us|ch|sh|x|z)$/i.test(word)) return `${word}es`; // process→es, address→es, status→es, tax→es
+ if (/[^aeiou]y$/i.test(word)) return `${word.slice(0, -1)}ies`; // currency→currencies, company→companies
+ if (/s$/i.test(word)) return word; // already plural: currencies, customers, jobs
+ return `${word}s`;
+};
const cleanDesc = (d = "") =>
d
.replace(/<pk\/>/g, "")
@@ -218,7 +228,7 @@ for (const path of tablePaths) {
const attrs = attributesFrom(def);
const pk = (attrs.find((a) => a.pk) || attrs.find((a) => a.name === "id") || attrs[0])?.name || "id";
const single = titleize(table);
- const plural = `${single}s`;
+ const plural = pluralize(single);
const row = sampleRow(attrs);
const writable = attrs.filter((a) => !a.pk && !AUDIT.has(a.name));
const endpoints = [];
diff --git a/packages/dev/src/commands/down.ts b/packages/dev/src/commands/down.ts
index 54b8e281b2..f45bca0b24 100644
--- a/packages/dev/src/commands/down.ts
+++ b/packages/dev/src/commands/down.ts
@@ -1,4 +1,4 @@
-import { intro, outro, tasks } from "@clack/prompts";
+import { intro, log, outro, tasks } from "@clack/prompts";
import pc from "picocolors";
import { syncAppPortlessConfigs } from "../env.js";
import { currentBranch } from "../git.js";
@@ -6,7 +6,6 @@ import { killOrphanedApps, killOrphanedStripe } from "../services/apps.js";
import { stopStack } from "../services/compose.js";
import { branchToPrefix, unregisterAliases } from "../services/portless.js";
import {
- ensureSlugAvailable,
getSlot,
getWorktreeRoot,
projectName,
@@ -23,9 +22,9 @@ export async function down(opts: { silent?: boolean; volumes?: boolean } = {}) {
const project = projectName(slug);
const withVolumes = opts.volumes ?? false;
- // Refuse to tear down a stack that another worktree owns (same slug, different
- // path). Passes for our own stack and when nothing is running.
- await ensureSlugAvailable(slug, root);
+ // No ensureSlugAvailable guard here — `down` is the user explicitly asking
+ // to stop their own stack. The guard (meant for `up`) would block teardown
+ // of moved/borrowed/stale worktrees, leaving containers orphaned.
if (opts.silent) {
return runPlain(root, slug, project, withVolumes);
@@ -37,7 +36,11 @@ export async function down(opts: { silent?: boolean; volumes?: boolean } = {}) {
title: `Stopping ${project} (${withVolumes ? "removing volumes" : "volumes preserved"})`,
task: async (msg) => {
msg(withVolumes ? "docker compose down -v" : "docker compose down");
- await stopStack(root, slug, withVolumes);
+ const code = await stopStack(root, slug, withVolumes);
+ if (code !== 0) {
+ log.warn("stack stop failed — containers may still be running");
+ return "partial — check `crbn status`";
+ }
return withVolumes ? "stack stopped, volumes removed" : "stack stopped";
}
},
@@ -84,7 +87,12 @@ async function runPlain(
step(
`stopping ${project} (${withVolumes ? "removing volumes" : "volumes preserved"})`
);
- await stopStack(root, slug, withVolumes);
+ const code = await stopStack(root, slug, withVolumes);
+ if (code !== 0) {
+ process.stderr.write(
+ `${pc.yellow("!")} stack stop failed — containers may still be running\n`
+ );
+ }
done(withVolumes ? "stack stopped, volumes removed" : "stack stopped");
step("killing orphaned dev servers & stripe listener");
diff --git a/packages/dev/src/commands/remove.ts b/packages/dev/src/commands/remove.ts
index e40e3f69b3..c2a13a9cf6 100644
--- a/packages/dev/src/commands/remove.ts
+++ b/packages/dev/src/commands/remove.ts
@@ -16,6 +16,7 @@ import {
removeWorktree
} from "../git.js";
import { confirmRemove } from "../prompts.js";
+import { killOrphanedApps, killOrphanedStripe } from "../services/apps.js";
import { destroyProjectVolumes, flushDb } from "../services/compose.js";
import {
branchToPrefix,
@@ -132,21 +133,32 @@ export async function removeWorktreeCmd(opts?: { prune?: boolean }) {
progress(`${label}: tearing down stack`);
await destroyProjectVolumes(target.path, projectLabel);
}
+ // Kill host dev servers + stripe listener that outlive `crbn up`.
+ // Without this, their cwd holds the worktree dir open and
+ // `git worktree remove` fails on macOS (busy directory).
+ if (slotInfo) {
+ progress(`${label}: killing dev servers`);
+ await killOrphanedApps(slotInfo.ports);
+ }
+ await killOrphanedStripe(target.path);
if (slotInfo && typeof slotInfo.redisDb === "number") {
progress(`${label}: flushing redis db ${slotInfo.redisDb}`);
await flushDb(slotInfo.redisDb);
}
- progress(`${label}: removing worktree`);
- await removeWorktree(target.path, dirty);
-
- if (pruneBranches && target.branch) {
- progress(`${label}: deleting branch`);
- await deleteBranch(target.branch);
+ try {
+ progress(`${label}: removing worktree`);
+ await removeWorktree(target.path, dirty);
+
+ if (pruneBranches && target.branch) {
+ progress(`${label}: deleting branch`);
+ await deleteBranch(target.branch);
+ }
+ } finally {
+ // Always release the port slot — a failed dir removal must not leak it.
+ if (slug) removeSlot(slug);
}
- if (slug) removeSlot(slug);
-
done++;
progress(pc.green(label));
})
diff --git a/packages/dev/src/commands/reset.ts b/packages/dev/src/commands/reset.ts
index 0693faef2a..d63dfc55b7 100644
--- a/packages/dev/src/commands/reset.ts
+++ b/packages/dev/src/commands/reset.ts
@@ -2,13 +2,12 @@ import { cancel, intro, log } from "@clack/prompts";
import { confirmReset } from "../prompts.js";
import {
destroyProject,
+ ensureDockerRunning,
flushDb,
listCarbonProjects,
- REDIS_CONTAINER,
- stopStack
+ REDIS_CONTAINER
} from "../services/compose.js";
import {
- ensureSlugAvailable,
getSlot,
getWorktreeRoot,
listSlugs,
@@ -21,20 +20,27 @@ export async function reset() {
intro("Carbon · dev reset");
const root = await getWorktreeRoot();
const slug = resolveSlug(root);
+ const project = projectName(slug);
- // reset is the most destructive command (down -v wipes volumes). Refuse if
- // another worktree owns this slug's running stack — don't nuke their data.
- await ensureSlugAvailable(slug, root);
+ // Fail fast with an actionable message instead of a silent partial reset.
+ await ensureDockerRunning();
- if (!(await confirmReset(projectName(slug)))) {
+ // No ensureSlugAvailable guard — the user confirmed via confirmReset below.
+ // The guard (meant for `up`) would block resetting moved/borrowed/stale
+ // worktrees, leaving volumes intact and defeating the purpose of `reset`.
+
+ if (!(await confirmReset(project))) {
cancel("reset aborted");
process.exit(0);
}
- log.warn(`resetting ${projectName(slug)}`);
+ log.warn(`resetting ${project}`);
- // Tear down current stack (compose-aware, removes containers + volumes).
- await stopStack(root, slug, true);
+ // Use destroyProject directly (not stopStack) — it doesn't depend on the
+ // compose file or .env.local, finds containers/networks/volumes by project
+ // label, and force-removes them. stopStack tries compose first (which can
+ // fail silently when .env.local is missing) then falls back to this anyway.
+ await destroyProject(project, true);
const slot = getSlot(slug);
if (slot && typeof slot.redisDb === "number") {
diff --git a/packages/dev/src/git.ts b/packages/dev/src/git.ts
index 1d42d35d98..fa16b23ddb 100644
--- a/packages/dev/src/git.ts
+++ b/packages/dev/src/git.ts
@@ -1,3 +1,5 @@
+import { existsSync } from "node:fs";
+import { rm } from "node:fs/promises";
import { execa } from "execa";
import { dirname, resolve } from "pathe";
@@ -92,11 +94,15 @@ export async function removeWorktree(
if (force) args.push("--force");
args.push(path);
const r = await execa("git", args, { reject: false });
- if (r.exitCode !== 0) {
- throw new Error(
- (r.stderr || r.stdout || "git worktree remove failed").trim()
- );
+ if (r.exitCode === 0) return;
+
+ // git refused (busy dir from a held cwd, locked, or corrupt gitdir). The
+ // caller already confirmed removal — fall back to a direct directory wipe
+ // and prune the orphaned admin metadata so git's worktree list stays clean.
+ if (existsSync(path)) {
+ await rm(path, { recursive: true, force: true });
}
+ await execa("git", ["worktree", "prune"], { reject: false });
}
export async function isDirty(path: string): Promise<boolean> {