Skill v1.0.0
currentLLM-judged scan90/100version: "1.0.0" name: obh-retrofit-import-export description: Use to assess or replace ad-hoc CSV import/export code with @obh/import-export. Finds csv-parse/papaparse/fast-csv usage, multipart CSV upload-then-insert handlers, and synchronous export routes, then maps each to a typed import/export registry that runs as background jobs and reads/writes CSV through the files service. Assessment-only by default; implements on request.
Purpose: replace hand-rolled CSV handling with the import-export primitive. Imports and exports become typed definitions in a registry, run as background jobs, and read/write their CSV through the files service — so the request path only starts a batch and returns 202, and heavy row work happens in the worker. Requires files and jobs (auto-added).
Assessment (read-only)
- Find the CSV code. Grep for:
csv-parse/csv-stringify/papaparse/fast-csv/json2csv; multipart CSV uploads (multer+ a loop of inserts); export routes that build a CSV string and stream it in the response; "download CSV"/"export" endpoints; and one-off bulk-import scripts.
- Inventory each import and export. For each: the entity type, the columns/fields involved, where imported rows are written (the domain insert), where exported rows are read from, validation done today, and whether it currently blocks the request. Flag synchronous in-request processing and non-idempotent inserts as the risks this move fixes.
- Map imports to `defineImport`. For each importable type, list
fields: [{ key, label, required, schema: z.… }]and thecommitRowwrite — which must be idempotent (upsert / natural key), because job retries can re-run it. Note the domain table eachcommitRowtargets.
- Map exports to `defineExport`. For each exportable type, list
columns: [{ key, label }]and theloadRowsquery that supplies them.
- Note the job + file flow. API
imports.createBatch({ workspaceId, importType, sourceFileId })/exports.createExport({ workspaceId, exportType })then enqueueimport_parse_csv/export_generate_csv; the worker drains them, reading/writing CSV via files (signed upload/download URLs). Ifevents/files/jobsaren't present, record the prerequisite.
Produces the import-export retrofit plan. Nothing above mutates the repo — a valid stopping point when you only need the survey.
Implementation (only after the plan is agreed)
- Install.
forge add import-export(--dry-runfirst; auto-addsfiles+jobs). Adds the migration, the registry+client atapps/api/src/platform/import-export.ts(aFileStoreover@obh/files+createImportExportClient({ db, files, registry })), the start-import/export routes, and the worker tick (createImportWorker/createExportWorkerbound to theimport_*/export_*jobs). Runpnpm migrate. Record the filesS3_*secret NAMES.
- Fill in the definitions. Replace the example
defineImport/defineExportwith the types from the plan: realfields(with Zod schemas), an idempotentcommitRow, realcolumns, and aloadRowsquery. Keep the worker's copy in sync (the worker never imports fromapps/api).
- Cut over and retire. Move upload to files (client uploads the CSV, passes
sourceFileId); switch export links to the async endpoint (202 → poll/download the generated file). Then delete the oldcsv-*parsing/generation, the in-request loops, and the multer wiring.
- Validate.
forge doctor.
Output
Assessment → the import-export retrofit plan: per type, the defineImport fields + idempotent commitRow target and/or defineExport columns + loadRows source; the job names (import_parse_csv/export_generate_csv) and file flow; and the files/jobs/events prerequisites. Implementation → the installed registry/routes/worker with real definitions, the S3_* secret NAMES, the async upload/download flow, and the retired CSV code.