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.
Spec: Conductor ⇄ crbn worktree parity
Status: Implemented on branch — settings.toml activates once merged to origin/main
Date: 2026-07-14
Author: research + draft (agent)
Area: packages/dev (crbn CLI) + Conductor repo config
Related rules: .ai/rules/environment-configuration.md, .ai/rules/dev-shared-redis.md, packages/dev/AGENTS.md
Changelog
- 2026-07-14 — implemented.
crbn init(packages/dev/src/commands/init.ts,canonicalSluginworktree.ts);crbn new's.env-copy task and the bashcheckoutdo_post_createhook both now delegate to it;crbn down --purge(§9-C decision below);conductor.json→.conductor/settings.toml. Unit tests forcanonicalSluginworktree.test.ts. Verified:pnpm --filter @carbon/dev typecheck+test(38 pass) + a livecrbn initrun producing slugcarbon-featuser-select(no longer collides with the main checkout'scarbon). - §9-C resolved as
crbn down --purge, not the recommendedcrbn remove --path/--yes. Reason discovered in implementation: Conductor runsarchiveinside the workspace dir and manages worktree/dir removal itself, butcrbn removedeliberately skips the current worktree and does its owngit worktree remove— wrong fit.down --purgetears down the stack + volumes, flushes the redis db, and callsremoveSlot(freeing the registry slot) without removing the dir, which is exactly what the archive hook needs.
1. Problem
crbn new / crbn checkout create a Carbon worktree whose dev environment is
fully isolated per-worktree: its own Docker Compose stack, ports, Supabase
JWT/anon/service keys, Redis logical DB, and portless *.dev domain. When we
instead create a workspace inside Conductor, Conductor does its own
git worktree add at ~/conductor/workspaces/<project>/<codename> and then runs
a repo-level setup script. That script tries to bolt crbn's provisioning on top,
but it does so unreliably — the result is not equivalent to a crbn checkout
worktree, and in at least one real case it collides with the main checkout.
We want: creating a workspace in Conductor produces the same fully-provisioned,
collision-free, branch-aligned worktree that crbn new / crbn checkout would —
even though the physical path differs.
1.1 Evidence (current state on this machine)
git worktree list (abridged):
/Users/barbinbrad/Code/carbon [main] slug: carbon
/Users/barbinbrad/conductor/workspaces/carbon/moscow [featuser-select]
/Users/barbinbrad/conductor/workspaces/carbon/macau [fixquote-markup-aggressiveness]
~/.carbon/dev-ports.json (the slot registry, keyed by slug):
slug=carbon -> /Users/barbinbrad/conductor/workspaces/carbon/moscow PORT_ERP=54943
slug=macau -> /Users/barbinbrad/conductor/workspaces/carbon/macau PORT_ERP=57199
slug=carbon-feat-service -> /Users/barbinbrad/Code/carbon-feat-service (native crbn worktree)
~/Code/carbon/.carbon-worktree=carbon(main checkout's slug).moscow/.carbon-worktree=carbon→ same slug as the main checkout. Docker projectcarbon-carbonand thecarbonregistry key are shared between main and this Conductor workspace. Whichever boots second either hitsensureSlugAvailable's "Slug already in use" error (packages/dev/src/worktree.ts:95-120) or steals the registry entry and re-allocates ports.macau/.carbon-worktree=macau→ happens to be unique, so macau works.
The mechanism that produced both values is the same line in conductor.json
(echo "$CONDUCTOR_WORKSPACE_NAME" > .carbon-worktree), yet it yielded carbon
for one workspace and macau for another. $CONDUCTOR_WORKSPACE_NAME is not a
reliable, unique, branch-aligned slug (the first workspace of a project appears
to inherit the project name carbon). That is the root cause.
2. How it works today (grounded)
2.1 crbn: directory creation vs. environment provisioning are separate
crbn new(packages/dev/src/commands/new.ts):git worktree add -b <branch>at a sibling of the main checkout,"<repoBase>-<slugify(branch)>"(new.ts:38), then copies.env. It does not allocate ports, mint JWTs, or write.env.local.crbn checkout(bash,packages/dev/bin/crbn:173-296): resolves/creates the worktree at the same"<repoBase>-<slug>"path, then runsdo_post_create(bin/crbn:404-417) =crbn env sync+.ai/scripts/install-skills.sh. Also does not allocate ports or write.env.local.crbn up(packages/dev/src/commands/up.ts) is where the per-worktree environment is actually minted:provisionSlot→resolveSlug→resolveSlot(ports/redisDb/jwt, persisted to~/.carbon/dev-ports.json) →branchToPrefix→renderEnv→writeEnv(.env.local)(up.ts:168-360,env.ts:6-113).
So "do what crbn checkout does" = (a) the worktree exists (Conductor already
does this), (b) files synced + skills installed, (c) a correct, unique
slug so (d) crbn up mints an isolated stack.
2.2 Two identity sources (must both be right)
| Identity | Source | Drives | Code |
|---|---|---|---|
| slug | $CARBON_WORKTREE → .carbon-worktree file → basename(worktreeRoot) |
Docker project carbon-<slug>, ~/.carbon/dev-ports.json key, CARBON_WORKTREE |
worktree.ts:49-60, 75-77 |
| branchPrefix | last /-segment of the git branch (sanitized), else slug |
DOMAIN, ERP_URL/MES_URL/SUPABASE_URL, portless *.dev aliases |
portless.ts:390-402, env.ts:18-97 |
In a native worktree both are unique per worktree (slug = full dir basename
carbon-feat-service; prefix = service). Under Conductor the slug is forced
to $CONDUCTOR_WORKSPACE_NAME, which is neither guaranteed unique nor
branch-aligned, while the prefix is still branch-derived — hence
CARBON_WORKTREE=carbon but DOMAIN=featuser-select.dev in this workspace.
2.3 Conductor config today (legacy conductor.json, committed)
conductor.json (repo root, identical in main/moscow/macau):
{
"scripts": {
"setup": "echo \"$CONDUCTOR_WORKSPACE_NAME\" > .carbon-worktree && pnpm install && ./packages/dev/bin/crbn env sync && bash .ai/scripts/install-skills.sh",
"run": "./packages/dev/bin/crbn up --all",
"archive": "./packages/dev/bin/crbn down --volumes"
}
}
Facts that matter for the redesign:
- Conductor treats
conductor.jsonas legacy; the modern form is.conductor/settings.toml. There is currently no.conductor/dir. - Conductor reuses a physical codename dir across successive workspaces (symlinks
accumulate;
git worktree listshows aprunablereused dir). A reused dir can carry a stale.carbon-worktreefrom a prior occupant. - Conductor strips slashes from branch names (
feat/user-select→featuser-select), so itsbranchPrefixdiffers from native crbn's. - Conductor's
archiverunscrbn down --volumes, which tears down containers + volumes but does not free the registry slot (onlycrbn removecallsremoveSlot,remove.ts:159). Orphan slots accumulate.
3. Goals / Non-goals
Goals
- A Conductor-created workspace boots via
crbn upinto a fully isolated stack, identical in shape to acrbn checkoutworktree. - The slug is deterministic, unique, and never collides with the main checkout or sibling workspaces — regardless of physical path or codename reuse.
- slug and domain are derived from a single, predictable rule (no more
carbonvsfeatuser-select.devsplit-brain). - The provisioning logic is a first-class, idempotent crbn command (usable by
Conductor, by native users adopting a hand-made
git worktree add, and by CI), not a one-off shell incantation embedded inconductor.json. - Migrate repo config to the supported
.conductor/settings.toml.
Non-goals
- Changing how the main checkout or native
crbn new/checkoutworktrees behave (parity means Conductor matches them, not vice-versa). - Changing Conductor's own
git worktree addpath/codename scheme (out of our control; we adapt to it). - Sharing databases across workspaces (that's the existing
crbn up --borrowopt-in; unchanged).
4. Proposed design
Two parts. Part A is the substance (a crbn command); Part B is the thin Conductor wrapper that calls it.
Part A — crbn init: provision the current worktree
Add an idempotent subcommand (working name crbn init; alt: adopt /
provision) that makes the worktree it is run in look exactly like one produced
by crbn checkout, then leaves the heavy stack boot to crbn up:
- Compute + persist a canonical slug (see §5) via
persistSlug(worktree.ts:62), overwriting any stale.carbon-worktree. This is the fix for the collision and the codename-reuse staleness. env sync— copypackage.json#crbn.copyfiles (today[".env"]) from the main checkout (copy.tsenvSync).- Install skills — run
.ai/scripts/install-skills.sh(symlink.ai/rules+.ai/skillsinto.claude/.codex), matchingdo_post_create. - Idempotent + path-agnostic: safe to re-run; resolves the main checkout via
--git-common-dir(already howbin/crbn:repo_rootworks), so it works from any path including Conductor's. - (Optional, see §9-D) pre-allocate the slot and write
.env.localso the env exists before the stack is booted.crbn upalready does this idempotently, so this is a convenience, not a requirement.
Then refactor do_post_create (bash, bin/crbn:404-417) and the .env copy in
new.ts:62-74 to call crbn init, so one code path provisions worktrees for
new, checkout, and Conductor. This removes today's drift where new copies
.env inline but skips env sync/skills while checkout does both.
initWorktree takes an explicit { root } and threads it through every step
(persistSlug(root), syncStaleCopyFiles(root), installSkills via
execa(…, { cwd: root })) rather than trusting process.cwd(). new must
pass root: targetPath — the freshly-created worktree, not the caller — so
provisioning lands there. The bash checkout/Conductor paths run init with
their cwd already inside the target, so the root default (getWorktreeRoot())
resolves correctly. Covered by init.test.ts (asserts .carbon-worktree is
written under the target, never the main checkout).
Part B — Conductor config → .conductor/settings.toml
Replace committed conductor.json with .conductor/settings.toml:
"$schema" = "https://conductor.build/schemas/settings.repo.schema.json"
[scripts]
setup = "pnpm install && ./packages/dev/bin/crbn init"
run_mode = "concurrent" # workspaces are port-isolated by crbn
archive = "./packages/dev/bin/crbn remove --path . --yes" # frees the registry slot too (see §6)
[scripts.run.dev]
command = "./packages/dev/bin/crbn up --all"
default = true
icon = "rocket"
Key changes vs today:
- Slug no longer comes from
$CONDUCTOR_WORKSPACE_NAME.crbn initowns it (§5), killing thecarboncollision. env sync+install-skillsfold intocrbn init(single source of truth).run_mode = "concurrent"is correct because crbn already isolates ports/DB per slug (the whole point of the slot registry).archivefrees the slot, not just the containers (§6).
Rollout caveat: Conductor only honors a settings.toml change after it is
merged to the default branch on the remote (origin/main). Until then it keeps
reading the committed conductor.json. So we can either (i) ship crbn init +
fix conductor.json in the same PR for an immediate effect on the current legacy
path, then (ii) migrate to settings.toml — or do both in one PR and accept that
the TOML only activates post-merge. See §8.
5. Slug derivation — the central decision
The slug must be unique per worktree, stable, and ideally aligned with native crbn. Candidates:
- (R) Branch-derived, repo-prefixed —
slug = "<repoBase>-<slugify(branch)>"(e.g.carbon-featuser-select). Read the current branch via git insidecrbn init.- ✅ Identical shape to native worktrees (
carbon-feat-service), socrbn list/statusshow Conductor + native worktrees uniformly. - ✅ Deterministic, branch-aligned (slug and domain now tell the same story).
- ✅ Never collides with main (
carbon) or siblings (distinct branches). - ⚠️ On Conductor codename reuse (archive → recreate on the same physical
dir with a new branch) the slug changes, so the old slot orphans in the
registry — mitigated by the §6 archive change (
crbn removefrees it).
- ✅ Identical shape to native worktrees (
- (B) Path/codename-derived — drop the
echoline entirely and letresolveSlugfall back tobasename(worktreeRoot)=moscow/macau.- ✅ Minimal change; already unique across Conductor dirs; reuses the same slot on codename reuse (no orphan).
- ❌ Not branch-aligned (slug
moscow, domainfeatuser-select.devsplit-brain persists); doesn't match native shape; a reused dir silently reuses a prior branch's DB unless volumes were wiped.
Recommendation: (R) branch-derived, repo-prefixed, because it most literally
satisfies "do the same thing as crbn checkout" and eliminates the split-brain.
Pair it with the §6 archive fix so orphan slots don't accumulate. (Option B is the
acceptable low-effort stopgap if we only want to stop the bleeding — see §8.)
Uniqueness guard: crbn init should still call ensureSlugAvailable
(worktree.ts:95) and, on the (rare) event that the branch-derived slug is taken
by a different live path, fall back to appending a short disambiguator or the
codename. Two git worktrees can't share a branch, so collisions only arise from
stale/misconfigured state.
6. Archive / registry-slot lifecycle
Today archive = crbn down --volumes stops the stack but leaves the
~/.carbon/dev-ports.json entry behind (down.ts never calls removeSlot). With
branch-derived slugs (§5-R), that means an orphan per archived workspace. Fix by
having archive free the slot. Options:
- Point archive at a non-interactive teardown that removes the slot.
crbn removealready doesremoveSlot(remove.ts:159) but is interactive (multi-select). This spec assumes we add non-interactive flags (crbn remove --path . --yes) or acrbn down --purgethat also callsremoveSlot+ flushes the redis DB index. Decision in §9-C.
7. Edge cases
- Main branch / main checkout. Conductor workspaces are always on a feature
branch, never
main, soslug = carbon-<branch>never regenerates the main checkout'scarbon.crbn initstill refuses to run in the main checkout to avoid clobberingcarbon, viaisLinkedWorktree(root)— it compares the normalizedgit-dirandgit-common-dir(equal in the main worktree, differ in linked worktrees). (Comparing--git-common-dirtocwdwould be unreliable — they aren't equal even in the main checkout.) Guard covered byinit.test.ts. - Codename reuse with stale
.carbon-worktree.crbn initoverwrites the slug file every run, so a reused dir is corrected on setup. (Today'sechoalso overwrites, but with the wrong value.) - Branch rename after creation. Domain (branchPrefix) follows the branch on the
next
crbn up; slug stays put (keyed in the registry). Acceptable and matches native behavior. If we want slug to track renames too, that's a separatecrbn init --reslug. - Slash-stripped branch names. Conductor's
featuser-selectvs a nativefeat/user-selectyields different prefixes/slugs. Cosmetic; note it. Not worth fighting Conductor's sanitizer. - PR workspaces. Native
crbn checkout <pr#>sets push-back tracking; Conductor has its own PR flow (.context/attachments/.../PR instructions.md). Out of scope —crbn initonly provisions env; it doesn't manage PR tracking. .contextdir. Conductor-managed, locally git-excluded; untouched.
8. Rollout plan
Because settings.toml activates only post-merge, sequence to avoid a broken
in-between state:
- PR 1 (crbn): add
crbn init(+ non-interactivecrbn remove/down --purgeper §9-C), refactordo_post_create/newto use it, unit tests (packages/dev/src/*.test.tsstyle). No behavior change for existing users ofnew/checkoutbeyond consolidation. - PR 1 also: fix the legacy
conductor.jsonsetuptopnpm install && ./packages/dev/bin/crbn initandarchiveto the slot-freeing teardown — this takes effect immediately on the current legacy path and fixes themoscow↔carboncollision without waiting on TOML. - PR 2 (config migration): add
.conductor/settings.toml(Part B) and deleteconductor.json. Takes effect once merged toorigin/main. Verify Conductor picks it up on the next new workspace. - One-time cleanup on dev machines:
crbn removethe stalecarbon-slug Conductor entry, or re-runcrbn init && crbn upin existing Conductor workspaces to re-slug them.
9. Open questions / decisions (recommendations — please veto)
- A. Command name.
crbn initvscrbn adoptvscrbn provision. Recommendcrbn init(shortest; "make this dir a ready Carbon worktree"). - B. Slug policy. §5. Recommend (R) branch-derived, repo-prefixed
carbon-<slugify(branch)>. - C. Archive teardown. Add
crbn remove --path . --yes(non-interactive) vs a newcrbn down --purge. Recommend extendingcrbn removewith--path/--yes(reuses its existingremoveSlot+ redis-flush path;down --purgewould duplicate that logic). - D. Should
crbn initalso write.env.local(pre-allocate the slot), or leave that tocrbn up? Recommend leaving it tocrbn upto keepinitcheap and side-effect-light; revisit if tools need.env.localpresent pre-boot. - E. Migrate to
settings.tomlnow, or just fixconductor.json? Recommend both, sequenced per §8 — fix the legacy file for an immediate effect, migrate to TOML for the supported long-term config. - F. Keep
run_mode = "concurrent"? Recommend yes — crbn's slot registry already guarantees per-workspace port/DB isolation, which is exactly the precondition for concurrent runs.
10. Acceptance criteria
- Creating a fresh Conductor workspace on branch
feat/xresults in:.carbon-worktree=carbon-feat-x(or the §9-B chosen scheme), nevercarbonand never equal to any other live worktree's slug.~/.carbon/dev-ports.jsongains a distinct entry pointing at the workspace path;crbn up --allboots without anensureSlugAvailableerror and with a port set disjoint from main and siblings..env.localCARBON_WORKTREEandDOMAINtell a consistent story (carbon-feat-x/x.devorfeat-x.devper Conductor's branch sanitizer)..claude/.codexskill symlinks present;.envcopied from main.
- Booting the main checkout and the Conductor workspace simultaneously works (no shared Docker project, no port clash).
- Archiving the workspace frees its registry slot (no orphan in
~/.carbon/dev-ports.json). crbn new/crbn checkoutbehavior for native worktrees is unchanged (verified by existingpackages/devtests + a manualcrbn newsmoke).
11. Risks
- Config-activation lag:
settings.tomlonly applies post-merge to main; mitigated by fixingconductor.jsonin the same PR (§8). - Refactoring
do_post_create/newto sharecrbn initcould regress native worktree creation — cover with tests + a manual smoke before merge. - Re-slugging existing Conductor workspaces changes their Docker project name,
so the old
carbon-carbon/carbon-macaustacks + volumes orphan until cleaned up (one-timecrbn remove, §8-4). Data in those dev stacks is disposable. - Branch-derived slug + codename reuse without the §6 archive fix would leak registry entries — the two changes must ship together.
Appendix — key files
packages/dev/bin/crbn— bash router;cmd_checkout(173-296),do_post_create(404-417),repo_root(63-75).packages/dev/src/commands/new.ts—newWorktree(dir +.envcopy).packages/dev/src/commands/up.ts—provisionSlot/resolveSlug/persistSlug(168-360).packages/dev/src/worktree.ts—resolveSlug(49-60),resolveSlot(134-166),ensureSlugAvailable(95-120), registry~/.carbon/dev-ports.json.packages/dev/src/env.ts—renderEnv/writeEnv(.env.local).packages/dev/src/services/portless.ts—branchToPrefix(390-402).packages/dev/src/commands/remove.ts—removeSlot(159).packages/dev/src/commands/copy.ts—envSync(package.json#crbn.copy).- Repo config:
conductor.json(legacy) →.conductor/settings.toml(target).