Skip to main content

Legacy Radar Flow — Keep/Delete/Adapt Inventory

Project: Commercial Intelligence Chat — reemplazo visible (C0/C1). Playbook: market-intelligence-chat-surface. Replaces the legacy Radar conversational product with a single Mastra Opportunity Flow; the old product must become unreachable, while reusable infrastructure (ledger, credits, quote/approval, provider attempts, cancel/reconcile, adapters, ports) survives behind the new workflow. C1 status: RETIRO COMPLETO. The legacy Radar product is removed from Chat (RadarConversationService, radar-copy, start_lead_search, the option seam, the sidecar entity, the interview HTTP endpoints, the dashboard rich-message rendering) and a structural candado (apps/api/src/radar/conversation/legacy-radar-candado.spec.ts) fails the build if Chat ever re-imports or re-registers it. The trajectory eval (opportunity-trajectory.trajectory.spec.ts) is now GREEN (7/7). KEEP-INFRA (ledger, credits, quote/approval, attempts, cancel/reconcile, adapters, ports) still compiles with its tests. Classification of every legacy-Radar reference across the API and dashboard:
  • DELETE — belongs to the legacy product only (interview, cotización, precio, radar-copy, estados/chips, start_lead_search, option seam). Removing it cannot break the new flow.
  • KEEP-INFRA — reusable infrastructure the new workflow needs: ledger, credits, quote/approval engine, provider attempts, cancel/reconcile, adapters, ports. Never delete.
  • ADAPT — shared surface that must change shape (chat turn pipeline, skills, DTOs, dashboard chat shell) so the legacy product stops being reachable while the new flow rides the same rails.
  • OUT-OF-SCOPE — exists in the codebase but is NOT part of this project (enrichment, contacts). Leave untouched; do not classify as new-flow infra.
This inventory was produced by reading every referenced file; line numbers are as of branch staging at the time of writing.

API (apps/api/src)


Dashboard (apps/dashboard/src)


What must NOT be deleted (KEEP-INFRA hard list)

Per the card, KEEP-INFRA is limited to ledger, credits, quote/approval, provider attempts, cancel/reconcile, adapters, and ports:
  • radar-run.service.ts (run ledger, trace, start/reconcile) — KEEP
  • credits.service.ts + radar/credits.integration.spec.ts (ledger) — KEEP
  • radar-pricing.ts / radar.dto.ts PriceRunDto / radar.controller.ts price (quote/approval engine) — KEEP, re-homed behind the workflow
  • provider attempts (ProviderAttemptService, gtm-provider-resolver.ts, adapters under radar/adapters/*, ports under radar/ports/*) — KEEP
  • cancel/reconcile (POST runs/:runId/reconcile, idempotent refunds) — KEEP
  • market-intelligence-gateway.port.ts + postgres-market-intelligence.adapter.ts — KEEP
  • planning/mastra-market-intelligence-workflow.ts — KEEP/ADAPT
NOT in the hard list: radar-monitor.service.ts, radar-criterion.service.ts, radar-stream.hub.ts, radar-webhook.controller.ts, radar/contact-path.ts, enrichment endpoints. They are not ledger/credits/quote-approval/attempts/ cancel-reconcile/adapters/ports, so the hard list cannot include them. Monitor and criterion have no concrete dependency in the new Opportunity Flow (the workflow re-homes criterion/contract compilation and coverage assessment; the legacy monitor is the radar product’s table watcher) — they stay untouched, unwired. (radar-onboarding.service.ts is ADAPT per the table — its profile facts feed the new compile-profile step — but it is not KEEP-INFRA either.) OUT-OF-SCOPE (do not classify as new-flow infra, do not wire): radar-enrichment.service.ts, contact-path.ts, enrichment endpoints, and anything contact/enrichment-shaped. The playbook keeps contact and enrichment strictly after an opportunity is selected, as a separate opt-in capability with its own cost/conditions. None of it belongs in this replacement.

Risks

Rollback plan

Rollback for any retirement card is a git revert of that card’s diff (the deletes are reversible; no data migration is destructive in C0). The legacy Radar product is NOT kept behind a feature flag — that contradicts the playbook (“No basta ocultarlo o dejarlo como fallback”) and the existing isCommercialFeatureEnabled flag does not gate Radar at all. If a later card retires the radar_threads table, the retirement ships as a NEW forward-only migration: its up() retires the table and its down() restores it. The historical migration file stays untouched — never modified, never deleted. C1 does not create that migration unless retiring the table is actually necessary. No staging data loss: radar_threads is a sidecar conversation table; chat_messages and run/credit ledgers are never deleted.

Reintegration requirement (C7)

The red baseline is intentionally excluded from the default vitest run while it is red. The moment it turns green (the retirement cards land), it MUST be reintegrated into the default suite: remove the **/*.trajectory.spec.ts exclude from apps/api/vitest.config.ts and delete apps/api/vitest.trajectory.config.ts, so the harness runs the trajectory acceptance on every check. A green eval that stays excluded is a failed C7 and a failed project (the playbook’s “Hola → oportunidades” acceptance must run in CI, not by hand).

Evidence of the red baseline

research/commercial-intelligence-chat/c0-trajectory-red-baseline.txt is the output of pnpm --filter @driftless/api test:trajectory against the current behavior: 5 tests failed / 2 passed, failing specifically for (1) the real turn’s belt still carrying start_lead_search, (2) the real «Hola» prompt still enumerating Topics/Leads/Collections, (3) query_records still satisfying the market preflight, (4) the option DTO seam, and (5) RADAR_TOOLS still declaring start_lead_search. The two passing guards pin the target: the market turn IS offered the warehouse path, and query_records/list_collections remain available for legitimate pipeline questions. Production behavior is unchanged by this card.