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.
EE vs CE Licensing Cleanup
Branch: ee-vs-ce-cleanup
Started: 2026-09-21
Owner: Brad ([email protected])
State legend: [ ] todo · [~] in progress · [x] done · [!] blocked/needs decision
This plan is the durable state for a large licensing refactor. Update the checkboxes and the "Session log" as work lands. Each feature is a self-contained unit; the tree must stay green after each.
Reference: .claude/rules/commercial-licensing.md (the pattern), LICENSE +
packages/ee/LICENSE (the boundary: Enterprise = everything under packages/ee
OR any filename containing .ee.).
Task 1 — Configurator rules engine → CE ✅ DONE
The configurator UI was freed in commit b99dd084a7; only the sandbox engine file was left marked EE.
-
git mv packages/database/supabase/functions/lib/sandbox.ee.ts → sandbox.ts - Update importer
packages/database/supabase/functions/get-method/index.ts:33 - Update doc source
docs/content/docs/reference/configurator.mdx - Regenerate agent KB (
pnpm run generate:agent-kb) - Verify no
sandbox.eereferences remain
Task 3 — License Section 2 wording ✅ DONE
-
packages/ee/LICENSESection 2 updated to add "…or otherwise without making any Enterprise functionality available…"
Task 4 — Material Planning (MRP + scheduler) → CE ✅ DONE
The engine packages/ee/src/planning/ was self-contained: zero EE-internal deps,
no entitlement gating. Depended only on @carbon/database subpaths + @carbon/utils.
Decision: new package packages/planning (@carbon/planning). Cleanest CE
licensing boundary; no cycle risk. Source-exported .ts like @carbon/ee.
Steps
- Created
packages/planning/(package.json,tsconfig.jsonextendsbase.json,vitest.config.ts). deps:@carbon/database,@carbon/utils,@internationalized/date,@supabase/supabase-js,kysely,zod. devDeps:@carbon/config,typescript,vitest. (No@logtapeneeded — planning reaches logging via@carbon/database/logging.) -
git mv packages/ee/src/planning/{index.ts,mrp,scheduling}→packages/planning/src/ - Removed
"./planning"export frompackages/ee/package.json - Repointed 9 functional import sites →
@carbon/planning(11 specifiers incl. 3 dynamic + vi.mock) - Repointed test
$jobId.status.test.ts(import + vi.mock) - Added
@carbon/planning: workspace:*topackages/jobs+apps/erppackage.json - Updated comment refs in the 7
@carbon/databasefiles +production.mcp.server.ts - Created
packages/planning/AGENTS.md; updatedpackages/ee/AGENTS.md,.claude/rules/{mrp-system,scheduling-data-structures}.md(paths + mentions),packages/database/AGENTS.md,apps/erp/app/modules/production/AGENTS.md,docs/content/docs/reference/forecast.mdx(+ regenerated agent KB) - Verified:
@carbon/planningtypecheck ✓ + 183 tests ✓;@carbon/jobstypecheck ✓;erptypecheck ✓ (afterreact-router typegen) -
pnpm install(workspace linked) - Note: 3 pre-existing biome style warnings in relocated test files (unchanged content).
- Note: MCP
tool-manifest.digest.jsonUNCHANGED (planning wasn't an MCP tool source).
Task 2 — Move CE-located commercial engines into packages/ee
All five already have Feature keys in packages/ee/src/plan.ts
(EMAIL_NOTIFICATIONS, MCP, BACKUPS, WORKFLOWS, AUDIT_LOG) and route/UX
gates. The remaining work per feature: relocate engine body into
packages/ee/src/<feature>/ and embed requireEntitlement (authoring) /
companyHasFeature (runtime-degrade). Do them one at a time, tree green each.
Order = ascending risk.
2a. Audit log ✅ DONE
Scoping revealed a CLEANER move than originally planned: only the ENGINE
(audit.ts) moves; audit.config.ts + audit.types.ts STAY in @carbon/database
(client-graph members holding generic schema types TableName/ColumnOf consumed
by CE packages @carbon/workflows, @carbon/jobs — moving them would force
community packages into a commercial dep for no licensing benefit). Cycle-safe:
@carbon/database never imports audit internally; all 10 engine importers are apps.
-
git mv packages/database/src/audit.ts→packages/ee/src/audit/audit.ts - Rewired moved engine's imports:
./audit.config→@carbon/database/audit.config,./audit.types→@carbon/database/audit.types,./event→@carbon/database/event - Embedded
requireEntitlement("AUDIT_LOG")inenableAuditLog, guarded byif (!CONTROLLED_ENVIRONMENT)(ITAR audit is mandatory; all 3 auto-enable call sites are already CONTROLLED_ENVIRONMENT-gated). Left read getters +insertAuditLogEntriesungated (capture is gated by subscription creation, whichenableAuditLogcontrols; avoids dropping security-audit events + hot-path cost). - Removed
"./audit"frompackages/database/package.json; added"./audit.server": "./src/audit/audit.ts"topackages/ee/package.json - Repointed 10 app engine importers
@carbon/database/audit→@carbon/ee/audit.server(erp routes + mes itar.service; both apps already depend on@carbon/ee) - Updated
.claude/rules/audit-log-system.md(paths + wrapper location),commercial-licensing.md(rollout ✅),packages/database/AGENTS.md,packages/ee/AGENTS.md - Verified:
@carbon/ee,erp,mes,@carbon/jobsall typecheck clean (mes/erp afterreact-router typegen). No audit .test.ts to move.
2b. MCP ✅ DONE — protocol engine → @carbon/ee/mcp + @carbon/ee/mcp.server
Executed via DI (the dispatch is ~/-bound and can't move): git mv server.ts +
catalog-search/describe-format/format-result/instructions/types → packages/ee/src/mcp/;
split exports — @carbon/ee/mcp (pure barrel index.ts, no auth/entitlement chain, for
tests) and @carbon/ee/mcp.server (server.ts). createMcpServer is now generic over
the auth context, takes injected deps { callOperation, operationsByName, isListOperation, isMcpBlockedTool, catalogSearch, toolMetadata }, and embeds requireEntitlement("MCP")
(async; route catches EntitlementError → 402, replacing the deletable in-route
companyHasFeature). types.ts McpContext redefined structurally (no ~/ import) +
McpServerDeps/McpCallResult; instructions.ts takes the catalog summary as an arg (no
app-JSON import). Route _index.ts builds catalogSearch once + passes deps; imports
createCatalogSearch from @carbon/ee/mcp, createMcpServer from @carbon/ee/mcp.server.
tool-metadata.json + mcp-blocked-tools.ts + manifest.ts + agent-setup-prompt.ts
stay in the app. Added ee deps: @modelcontextprotocol/sdk, zbsearch (runtime),
@carbon/api (devDep, type-only). The 3 pure-logic tests stay in-app (real
tool-metadata.json) importing from @carbon/ee/mcp (pure barrel avoids the glossary/auth
load that broke them under the heavy barrel). Updated .claude/rules/mcp-tools-reference.md,
commercial-licensing.md (✅), packages/ee/AGENTS.md.
Verified: ee + erp typecheck green; 158 MCP tests pass (49 lib + 109 generator/dispatch).
⚠️ RESIDUAL: server.ts is @ts-nocheck and the live POST /api/mcp endpoint can't be
exercised in this env — needs an endpoint smoke test before merge.
(original scoping) ~1k lines; engine in apps/erp/.../api+/mcp+/
- Move the dispatch core (
lib/server.ts+ helpers) intopackages/ee/src/mcp/; keep the thin route in the app calling it. - Embed
requireEntitlement("MCP")in the ee entry (route keeps itscompanyHasFeaturechoke as UX). - Watch
generate:mcpdigest: tools ARE the ERP*.service.ts; moving the dispatcher does not move the tool bodies. Runpnpm run generate:mcp, review digest diff. - Verify.
2c. Email notifications ✅ DONE
Scoping: the lockable seam is just the email-channel DECISION. sendEmail
(@carbon/lib) is GENERIC transactional transport (invites, MFA, password,
onboarding) — must NOT be gated. content.ts, in-app/slack channels, send-email.ts
all stay CE.
- Created
packages/ee/src/email-notifications/deliver.server.ts→emailNotificationsEnabled(client, companyId)(wrapscompanyHasFeature("EMAIL_NOTIFICATIONS"), DEGRADE not throw). Distinct dir from the existingpackages/ee/src/email/integration-config. - Added
"./email-notifications.server"export topackages/ee/package.json - Rewired
notify.tscheck-email-planstep →emailNotificationsEnabled(feature key + degrade contract now in commercial code); step id unchanged - Verified:
@carbon/ee+@carbon/jobstypecheck green
2d. Backups ✅ DONE (gate-in-place — engine is Inngest-coupled, CANNOT move)
Scoping: the durable functions import @carbon/jobs-internal ../../../db + the
inngest client, so the engine can't move to ee (would invert the dep). Onboarding
(company-template) is a second caller of buildCompanyBackup/wipeAndLoad and
must stay free. packages/jobs/src/backups/ is import-light (bare-tsx CLI +
db:check:backups) — left untouched.
- Created
packages/ee/src/backups.server.ts→requireBackupsEntitlement(companyId)=if (IS_LOCAL_DEV) return; requireEntitlement(serviceRole, companyId, "BACKUPS"). Added"./backups.server"export. - Embedded the gate at the top of all 5 durable functions:
companyExportFunction(company-export.ts),companyRestore{,Finalize,Revert}Function(company-restore.ts),companyImportFunction(company-import.ts — exemptsreferencedTemplateonboarding). - Left
canManageBackups(app route UX gate) +canAccessBackups(browser-safe hatch for nav/Demo Data) in place. Did NOT push the check intobuildCompanyBackup/wipeAndLoad(onboarding uses them). - In-app purge/delete/upload stay route-gated by
canManageBackups(they carryemailfor the internal-staff hatch; heavy work funnels into the gated durable fns). - Updated
commercial-licensing.md(✅),company-backup-restore.md,packages/ee/AGENTS.md. - Verified:
@carbon/ee+@carbon/jobstypecheck green. - Accepted tightening: internal-staff export of a real customer Starter company on Cloud is now blocked at the job (no email on the service-role path); backups is a paid feature and this path is not a normal support flow.
2e. Workflows ✅ DONE — moved the whole package into @carbon/ee/workflows
Executed: created @carbon/workflows-core leaf (run-trigger.ts + moments.ts
MOMENT_OUTPUT_KEYS/types); repointed @carbon/lib (events.ts + raise-moment.ts)
to the leaf and swapped its dep (cycle broken); git mv packages/workflows/src →
packages/ee/src/workflows + AGENTS.md; deleted packages/workflows; engine
run-trigger.ts/catalog/moments.ts re-export the contracts from the leaf; added ee
exports ./workflows, ./workflows/help, ./workflows/labels, ./workflows.server
- deps (
@carbon/workflows-core,@lingui/core, glossary devDep); repointed all 94 importers (@carbon/workflows→@carbon/ee/workflows); removed stale@carbon/workflowsdeps from erp/jobs package.json, swapped checks dep to@carbon/ee; fixed build-critical paths (turbo.json inputs, package.json generate script, lingui.config.js, scripts/{check,generate}-workflow-catalog.ts, checkssources/typescript.ts— removed the now-redundantpackages/workflows/srcentry sincepackages/ee/srcalready covers it); embedded gates — runtime DEGRADEworkflowsEnabledForCompany(companyId)in jobsengine/execute.ts(Skipped when not entitled), authoring throwrequireWorkflowsEntitlementin erppublishWorkflowVersion; added theMOMENT_OUTPUT_KEYS↔WORKFLOW_MOMENTSsync assertion tocheck-workflow-catalog.ts; added the ee mock to the 4 jobs engine test files. Verified: typecheck ee/jobs/erp/lib/checks/workflows-core green; ee tests 1499 pass, jobs tests 734 pass;check:workflow-cataloggreen. Docs update delegated to a subagent.
(original plan) ~23k lines, 96 importers
Directive: move the whole @carbon/workflows package into packages/ee.
Cycle reality (scoped): only @carbon/lib is a real cycle source —
@carbon/database and @carbon/checks were FALSE alarms:
@carbon/databasedatasets only MENTION@carbon/workflowsin comments (0 real imports); the real edge runs the other way (@carbon/databaseEXPORTS./seed-workflows, consumed test-only by workflows). Nodatabase → workflowsdep.@carbon/checksimports it (1 script) but@carbon/eedoes NOT depend on checks →checks → eeafter repoint is safe.@carbon/libimports it in 2 files, type-only:events.ts(type RunTrigger),workflows/raise-moment.ts(type MomentKey, MomentPayload).@carbon/eedepends on@carbon/lib→ this is the cycle to break.
Plan (confirmed: extract a tiny CE leaf, then move the rest):
- Create leaf package
@carbon/workflows-core(dep:zodonly) holding the wire contracts lib needs: -run-trigger.ts— moverunTriggerSchema+RunTriggerVERBATIM (it's already self-contained, imports onlyzod). - moment contract — the derivation isMomentPayload<K> = { [O in keyof WORKFLOW_MOMENTS[K]["outputs"]]: MomentEntityRef }, i.e. it needs the per-moment OUTPUT KEY NAMES only (not thet.entity(...)types). So the leaf holdsexport const MOMENT_OUTPUT_KEYS = { "production.jobReleased": ["job", "releasedBy"], ... } as const(9 entries, keys+output-key-names copied fromcatalog/moments.tsWORKFLOW_MOMENTS), thenMomentKey = keyof typeof MOMENT_OUTPUT_KEYS,MomentEntityRef = { id: string },MomentPayload<K> = { [O in (typeof MOMENT_OUTPUT_KEYS)[K][number]]: MomentEntityRef }. The engine'sWORKFLOW_MOMENTSstays the source of truth (labels/permissions/t.entity); have the engine RE-EXPORTMomentKey/MomentPayload/MomentEntityReffrom-core(drop its local defs) so there is ONE type. Add an assertion inscripts/check-workflow-catalog.tsthatObject.keys(MOMENT_OUTPUT_KEYS)===Object.keys(WORKFLOW_MOMENTS)AND each moment's output keys match — this is the sync invariant typecheck won't catch. - Repoint
@carbon/lib(events.ts,workflows/raise-moment.ts) →@carbon/workflows-core; swap its@carbon/workflowsdep for-core. -
git mv packages/workflows/src/**(minus the extracted leaf) →packages/ee/src/workflows/. Re-exportRunTrigger/runTriggerSchema+ moment types from-coreso@carbon/ee/workflowssurface is unchanged. - Add ee exports:
./workflows,./workflows/help,./workflows/labels. Add ee deps:@carbon/glossary(devDep, type-only),@lingui/core(for./workflows/labels),@carbon/workflows-core. (already has database, utils, intl-date, kysely, zod.) - Repoint 96 importers →
@carbon/ee/workflows(+/help,/labels): erp 61, jobs 32, checks 1 (lib now off it). erp + jobs already dep ee; add@carbon/eetopackages/checks/package.json. - Lock the runtime engine
packages/jobs/src/workflows/: embedcompanyHasFeature("WORKFLOWS")atengine/execute.ts(runs on background events, bypassing route gates). Default: gate in place, keep in jobs (Inngest-coupled). - Embed
requireEntitlement("WORKFLOWS")inapps/erp/app/modules/workflows/workflows.service.tsauthoring writes. - Move
packages/workflows/AGENTS.md→ ee; update rules referencing it. - Delete empty
packages/workflows;pnpm install. - Verify typecheck erp + jobs + ee + checks + lib; run workflows test suites.
Cross-cutting verification (run before considering any feature done)
pnpm exec turbo run typecheck --filter=<pkg>(scoped — whole-repo OOMs)pnpm run lint(biome)pnpm --filter <pkg> test- Dev build for
.serverclient-graph errors (typecheck won't catch these) - Update
.claude/rules/commercial-licensing.md"Rollout status" per feature - Update affected
AGENTS.mdand.claude/rules/*paths:frontmatter
Open decisions
- Task 4 destination: new
packages/planning— DONE. - Workflows cycle resolution (2e): scoped — only
@carbon/lib(2 type-only imports) is a real cycle; extract a tiny@carbon/workflows-coreleaf (zod-only:RunTrigger+ moment contract), repoint lib, move the rest to@carbon/ee/workflows. - [!] Does the jobs workflow-execution engine (
packages/jobs/src/workflows/) physically move to ee, or gate-in-place? Default: gate-in-place (companyHasFeatureatengine/execute.ts); it's Inngest-coupled.
Session log
- 2026-09-21: Tasks 1 & 3 done. Plan written. Task 4 DONE (new
@carbon/planningpackage; typechecks + 183 planning tests green). Task 2a (audit) DONE — engine →@carbon/ee/audit.serverwithrequireEntitlement(ITAR-guarded); config/types stay in@carbon/database; ee/erp/mes/jobs typecheck green. - 2026-09-21 (cont.): 2c (email) DONE —
@carbon/ee/email-notifications.server; ee+jobs green. 2d (backups) DONE — gate-in-place@carbon/ee/backups.serverrequireBackupsEntitlementembedded in all 5 durable functions; ee+jobs green. 6 of 8 pieces complete and green (1, 3, 4, 2a, 2c, 2d). Tree is GREEN. REMAINING (each must land atomically): 2e workflows (whole-package move: new@carbon/workflows-coreleaf + move to@carbon/ee/workflows+ repoint 96 importers + lock jobsexecute.ts/erpworkflows.service.ts) and 2b MCP (DI refactor of@ts-nocheckserver.ts + 5 helpers →@carbon/ee/mcp.server, inject app dispatch/metadata, +3 ee deps@modelcontextprotocol/sdk/zbsearch/@carbon/api; metadata-coupled tests stay in app importing from ee). Both fully scoped above. - 2026-09-21 (final): ALL 8 pieces DONE. 2e (workflows) — whole package →
@carbon/ee/workflows@carbon/workflows-coreleaf; 94 importers repointed; gates in jobsexecute.ts(runtime degrade) + erppublishWorkflowVersion(authoring throw); moment-sync invariant added. 2b (MCP) — engine →@carbon/ee/mcp(pure) +@carbon/ee/mcp.servervia DI;requireEntitlement("MCP")insidecreateMcpServer. Final consolidated typecheck GREEN 9/9 (ee, jobs, planning, workflows-core, lib, checks, erp, mes). Tests green: ee 1499, jobs 734, MCP 158, planning 183,check:workflow-catalog. Docs synced. Committed 6703148569 + pushed; PR #1696 open (base main). ✅ Brad smoke-tested MCP + the other flagged flows — all pass. No residuals.