Files
zeekay 82120531a1 fix(debrand): read the TypeScript import graph before dropping a product
drop_closure exists to refuse a drop that is really a refactor: if code we
keep still imports a product, deleting it is a ModuleNotFoundError waiting
for the next boot. It only ever read Python, so half the dependency graph was
invisible to it and five products whose TypeScript the core still imports were
dropped anyway — 21 files left importing 25 specifiers that resolve to
nothing, including lib/api.ts, which 760 files import, and seven lazy scene
imports in productScenes.tsx.

Django booted past it and the bundle did not, which is why the Python-only
rule looked like it was working.

The closure now reads both module systems through one table of
(extensions, pattern) pairs, so a third one is a row rather than a branch. The
TypeScript pattern is anchored on the import keyword rather than on the path,
because jest's testPathIgnorePatterns and oxlint's ignore list quote a product
path precisely because it is NOT built; matching those would hold desktop, the
4,797-file product the drop is mostly for.

integrations, wizard, platform_features, visual_review and ai_gateway come
back with their Django apps and workspace entries, since the closure now
spares them. desktop, field_notes, ingestion and support stay dropped.
2026-08-01 22:17:05 -07:00

66 lines
2.6 KiB
Python

"""
Django models for wizard.
Keep models thin — business logic belongs in logic/.
Use types from facade/enums.py where applicable.
Avoid ForeignKeys to models outside this app; if needed,
disallow reverse relations with related_name='+'.
"""
from django.db import models
from insights.models.scoping.root_mixin import TeamScopedRootMixin
from insights.models.utils import CreatedMetaFields, UUIDModel
from products.wizard.backend.facade.enums import RunPhase
class WizardSession(UUIDModel, TeamScopedRootMixin, CreatedMetaFields):
team = models.ForeignKey("insights.Team", on_delete=models.CASCADE, related_name="+")
# db_constraint=False because insights_user is a hot table (a constrained FK would lock it).
created_by = models.ForeignKey(
"insights.User",
on_delete=models.SET_NULL,
null=True,
blank=True,
related_name="+",
db_constraint=False,
)
session_id = models.CharField(max_length=255)
workflow_id = models.CharField(max_length=255)
skill_id = models.CharField(max_length=255)
started_at = models.DateTimeField()
run_phase = models.CharField(max_length=50, choices=[(phase.value, phase.value) for phase in RunPhase])
tasks = models.JSONField(default=list)
event_plan = models.JSONField(null=True, blank=True)
error = models.JSONField(null=True, blank=True)
# An in-flight wizard_ask prompt ({id, asked_at, question_count, sensitive, prompts?}).
# Null means no input is pending — each push replaces it, so the CLI clearing the
# question is just the next upsert without the field.
pending_input = models.JSONField(null=True, blank=True)
# The markdown handoff doc (the wizard's setup report) once the run has produced one.
# Unlike the fields above it is monotonic within a session: a push without it keeps
# the stored value (see upsert_session), since the doc arrives late in the run.
handoff_text = models.TextField(null=True, blank=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta(TeamScopedRootMixin.Meta):
constraints = [models.UniqueConstraint(fields=["team", "session_id"], name="unique_wizard_session_per_team")]
indexes = [
# to optimize fetching the latest session
models.Index(
fields=["team", "workflow_id", "skill_id", "-started_at"],
),
# the detector queries team + workflow_id (no skill_id) ordered by started_at desc
models.Index(
fields=["team", "workflow_id", "-started_at"],
name="wizard_sess_team_wf_start_idx",
),
]