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.

6.3 KB
Raw Blame

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" (FK modelUpload, ON DELETE SET NULL), inspectionFeature."pmiItemId", and the partial unique index inspectionDocument_part_model_key.
  • In the same file, drop and create inspectionDocuments again (body of 20260526153412_inspection-documents-view.sql).
  • Add packages/database/src/event-system/handlers/queue_pmi_inspection_plans.sql (copy queue_model_pipeline.sql). On INSERT or UPDATE of item, for each row whose modelUploadId changed to a model with pmiPath set, send carbon/pmi-inspection-plan with { companyId, modelUploadId, itemId }. Skip under app.sync_in_progress.
  • Add queue_pmi_inspection_plans to item.statement in attachments.ts.
  • Run pnpm db:migrate. Run pnpm --filter @carbon/database authz sync if migrate does not apply handlers. Ship the handler with pnpm --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[] to packages/viewer/src/pmi.ts (mapping table in the spec).
  • Add "./pmi": "./src/pmi.ts" to packages/viewer/package.json exports.
  • 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 }) to packages/database/src/quality.ts. It runs in the caller's transaction. It resolves the drawing number (readableIdWithRevision, (n) suffix), inserts the plan with ON CONFLICT DO NOTHING on 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: event carbon/pmi-inspection-plan, concurrency key companyId-modelUploadId limit 1, retries 2. One step, create-plans: read the model and the items with no plan for it, download and map pmi.json, then create each plan in its own transaction through getJobDatabaseClient. One step keeps the characteristics out of the step output.
  • Register the function in tasks/index.ts and the inngest index. Add the event schema to packages/lib/src/events.ts (and trigger.ts when events are typed there).
  • In model-optimize.ts, after persist, step.sendEvent("pmi-inspection-plan", …) when outputs.pmi is set.

Verify: pnpm exec turbo run typecheck --filter=@carbon/jobs.

5. Viewer: controlled PMI selection

  • Add selectedPmiItemId?: string | null and onPmiItemSelect?: (id: string | null) => void to ModelPreview. A change of selectedPmiItemId selects the item and sends a focus request. A user pick calls onPmiItemSelect.

Verify: pnpm --filter @carbon/viewer typecheck.

6. ERP

  • quality.service.ts: getInspectionDocument and mapInspectionDocument return model: { modelUploadId, modelPath } | null (embed modelUpload(modelPath)). getInspectionSamplingPlans and getInspectionFeatures select pmiItemId.
  • Add ModelUploadPreview to @carbon/viewer (./model-upload-preview): props modelUploadId, modelPath, companyId, pmiLinks, selectedLinkId, onLinkSelect. Superseded the first build's per-app InspectionModelPane copies (nuclear self-review).
  • InspectionView.tsx: prop model; the drawing pane shows the model pane when model is set.
  • x+/inspection+/$id.tsx: pass model.
  • Editor route x+/inspection-document+/$id.tsx passes model. InspectionDocumentEditor.tsx: with model, show the model pane in the top pane, hide the PDF actions and the Balloon button, add a Show action per row with a pmiItemId.
  • 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: select pmiItemId on features, and modelUploadId, modelUpload(modelPath) in getInspectionDocumentWithBalloons; return model.
  • Use ModelUploadPreview from @carbon/viewer (no app copy).
  • InspectionView.tsx and x+/inspection.$operationId.tsx: pass and use model.

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-headers for new files.
  • Run Biome on changed files, the scoped typechecks, and the viewer and database tests.
  • Run /translate for 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

  • modelPreviewUrls in @carbon/viewer, used by ModelUploadPreview, ERP CadModel and the MES model tab.
  • ModelPreview: clear pmiSelectedRef with the selection on a new PMI document.
  • deleteUnusedPmiInspectionPlans building block; items.service.ts calls 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 by valuateMeasurement).
  • Editor: zoom controls not rendered for a model plan; conformance baseline line re-keyed; model prop required; pmiLinks memoized.
  • crbn: one assemblerMissingPrerequisite; dirname.
  • Docs: jobs and dev AGENTS.md, authz-manifest handler counts, user docs inspections.mdx.