luplo.core.import_pipeline.finalize

Phase 3 — receive agent results, validate, write items.

Defense-in-depth strips code blocks even if the agent followed the rule; cross-project guard ensures bundle_id belongs to the current project.

Functions

finalize_import(→ dict[str, Any])

Apply agent results to the bundle's work_unit and return a summary.

Module Contents

async luplo.core.import_pipeline.finalize.finalize_import(*, backend: luplo.core.backend.protocol.Backend, project_id: str, actor_id: str, results: luplo.core.import_pipeline.results.ImportResults) dict[str, Any]

Apply agent results to the bundle’s work_unit and return a summary.

Validates that results.bundle_id references an in-progress import work unit in project_id, defensively strips any fenced code blocks from each item body, and persists each ResultItem as a luplo item attached to the bundle’s work unit.

Parameters:
  • backend – The luplo Backend (Local or Remote).

  • project_id – Project owning the bundle; cross-project guard rejects mismatches.

  • actor_id – Caller’s actor UUID; recorded as the item author and as the closer if results.close_work_unit is set.

  • results – Envelope produced by the agent (bundle id + result items).

Returns:

A summary dict with keys status, bundle_id, items_created, and warnings (a list of human-readable strings, possibly empty).

Raises:

ValueError – When the bundle id is unknown, belongs to a different project, or is not in the in_progress state.