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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
Plan: Inspection plans from STEP PMI
Spec: .ai/specs/2026-10-27-pmi-inspection-plans.md
Run record: .ai/runs/2026-10-27-pmi-inspection-plans.md
Tasks
1. Migration and types
- Run
pnpm db:migrate:new pmi-inspection-plans. - In the new file, add
inspectionDocument."modelUploadId"(FKmodelUpload, ON DELETE SET NULL),inspectionFeature."pmiItemId", and the partial unique indexinspectionDocument_part_model_key. - In the same file, drop and create
inspectionDocumentsagain (body of20260526153412_inspection-documents-view.sql). - Add
packages/database/src/event-system/handlers/queue_pmi_inspection_plans.sql(copyqueue_model_pipeline.sql). On INSERT or UPDATE ofitem, for each row whosemodelUploadIdchanged to a model withpmiPathset, sendcarbon/pmi-inspection-planwith{ companyId, modelUploadId, itemId }. Skip underapp.sync_in_progress. - Add
queue_pmi_inspection_planstoitem.statementinattachments.ts. - Run
pnpm db:migrate. Runpnpm --filter @carbon/database authz syncif migrate does not apply handlers. Ship the handler withpnpm --filter @carbon/database authz migration pmi-inspection-plans-handler. - Run
pnpm run generate:types.
Verify: psql shows the two columns, the index and trg_event_statement_queue_pmi_inspection_plans_* on item.
2. Mapping (@carbon/viewer/pmi)
- Add
pmiInspectionCharacteristics(doc: PmiDocument): PmiCharacteristic[]topackages/viewer/src/pmi.ts(mapping table in the spec). - Add
"./pmi": "./src/pmi.ts"topackages/viewer/package.jsonexports. - Add tests in
packages/viewer/src/pmi.test.ts: ± dimension, limit dimension, fit-only dimension, presentation dimension skipped, angle unit, inch conversion, tolerance with value, tolerance without value, datum and note skipped, labels in order.
Verify: pnpm --filter @carbon/viewer test passes.
3. Building block (@carbon/database/quality)
- Add
createPmiInspectionPlan(db, { companyId, itemId, modelUploadId, characteristics })topackages/database/src/quality.ts. It runs in the caller's transaction. It resolves the drawing number (readableIdWithRevision,(n)suffix), inserts the plan withON CONFLICT DO NOTHINGon the partial index, and inserts the features when the plan row is new. It returns the plan id or null.
Verify: pnpm exec turbo run typecheck --filter=@carbon/database.
4. Job
- Add
packages/jobs/src/inngest/functions/tasks/pmi-inspection-plan.ts: eventcarbon/pmi-inspection-plan, concurrency keycompanyId-modelUploadIdlimit 1, retries 2. One step,create-plans: read the model and the items with no plan for it, download and mappmi.json, then create each plan in its own transaction throughgetJobDatabaseClient. One step keeps the characteristics out of the step output. - Register the function in
tasks/index.tsand the inngest index. Add the event schema topackages/lib/src/events.ts(andtrigger.tswhen events are typed there). - In
model-optimize.ts, afterpersist,step.sendEvent("pmi-inspection-plan", …)whenoutputs.pmiis set.
Verify: pnpm exec turbo run typecheck --filter=@carbon/jobs.
5. Viewer: controlled PMI selection
- Add
selectedPmiItemId?: string | nullandonPmiItemSelect?: (id: string | null) => voidtoModelPreview. A change ofselectedPmiItemIdselects the item and sends a focus request. A user pick callsonPmiItemSelect.
Verify: pnpm --filter @carbon/viewer typecheck.
6. ERP
-
quality.service.ts:getInspectionDocumentandmapInspectionDocumentreturnmodel: { modelUploadId, modelPath } | null(embedmodelUpload(modelPath)).getInspectionSamplingPlansandgetInspectionFeaturesselectpmiItemId. - Add
ModelUploadPreviewto@carbon/viewer(./model-upload-preview): propsmodelUploadId,modelPath,companyId,pmiLinks,selectedLinkId,onLinkSelect. Superseded the first build's per-appInspectionModelPanecopies (nuclear self-review). -
InspectionView.tsx: propmodel; the drawing pane shows the model pane whenmodelis set. -
x+/inspection+/$id.tsx: passmodel. - Editor route
x+/inspection-document+/$id.tsxpassesmodel.InspectionDocumentEditor.tsx: withmodel, show the model pane in the top pane, hide the PDF actions and the Balloon button, add a Show action per row with apmiItemId. -
InspectionDocumentTable.tsx: no PDF link for a model plan (check what it shows).
Verify: pnpm exec turbo run typecheck --filter=erp.
7. MES
-
services/quality.service.ts: selectpmiItemIdon features, andmodelUploadId, modelUpload(modelPath)ingetInspectionDocumentWithBalloons; returnmodel. - Use
ModelUploadPreviewfrom@carbon/viewer(no app copy). -
InspectionView.tsxandx+/inspection.$operationId.tsx: pass and usemodel.
Verify: pnpm exec turbo run typecheck --filter=mes.
8. Docs and gates
- Update
.claude/rules/inspection-system.md,apps/erp/app/modules/quality/AGENTS.md,packages/viewer/AGENTS.md(PMI section). - Run
pnpm --filter @carbon/checks license-headersfor new files. - Run Biome on changed files, the scoped typechecks, and the viewer and database tests.
- Run
/translatefor new UI strings when the catalogs need it. Not needed: the one new string,Show, is already in the catalogs. - Item delete (
deleteItemsWithPriceBreaks,items.service.ts) deletes the item's PMI plans that no inspection used.
9. Nuclear self-review fixes
-
modelPreviewUrlsin@carbon/viewer, used byModelUploadPreview, ERPCadModeland the MES model tab. -
ModelPreview: clearpmiSelectedRefwith the selection on a new PMI document. -
deleteUnusedPmiInspectionPlansbuilding block;items.service.tscalls it. - Tests:
packages/database/src/pmi-inspection-plan.test.ts(DB),supabase/tests/pmi-inspection-plans.test.sql(trigger),packages/jobs/.../pmi-inspection-plan.test.ts(mapping graded byvaluateMeasurement). - Editor: zoom controls not rendered for a model plan; conformance baseline line re-keyed;
modelprop required;pmiLinksmemoized. -
crbn: oneassemblerMissingPrerequisite;dirname. - Docs: jobs and dev AGENTS.md, authz-manifest handler counts, user docs
inspections.mdx.