A full-featured CRM built with React, shadcn/ui, and Supabase.
improve skill
erwanMarmelab00b52c91d260
diff --git a/.claude/skills/delete-initial-resource/SKILL.md b/.claude/skills/delete-initial-resource/SKILL.mdindex e69de29b..115f7395 100644--- a/.claude/skills/delete-initial-resource/SKILL.md+++ b/.claude/skills/delete-initial-resource/SKILL.md@@ -0,0 +1,91 @@+---+name: delete-initial-resource+description: Remove one or more of the initial CRM resources (contacts, companies, deals, tags, tasks) from the codebase. Use when the user asks to delete, remove, or strip out one or several of these built-in resources. Runs the delete-initial-resource.ts script to drop each resource's own folder, then guides cleanup of every file that references them.+---++This skill removes one or more of the five initial Atomic CRM resources and all references to them. The supported resources are: `contacts`, `companies`, `deals`, `tags`, `tasks`.++## How it works++A helper script does the mechanical first step (deleting each resource's own folder) and then lists every other file that depends on the resource(s). The script does **not** edit the dependent files — that cleanup is your job, guided by its output.++## Deleting several resources at once++The script accepts **multiple** resource names in one run (e.g. `… deals tags`). When you do this it:+- deletes every named folder, then+- returns the **merged, de-duplicated** dependent-file list across all of them, **minus** any file that lives inside a folder it just deleted (so it won't ask you to clean up a file that no longer exists — e.g. `companies/CompanyShow.tsx` is a dependent of `contacts`, but it's gone once `companies` is deleted in the same run).++Two things to watch when deleting several at once:+- **Order the cleanup from the most-coupled resource outward**, and read all the relevant per-resource notes below before editing — the cascade interactions compound. The clearest example is the **shared subsystems** (notes, activity log): deleting `contacts` narrows the notes union to `"deals"` while deleting `deals` narrows it to `"contacts"` — doing **both** deletes the subsystem's reference entirely rather than narrowing it, so don't half-apply each note's "narrow the union" guidance; reconcile them first.+- The per-resource notes below still apply individually, but a file shared by two deleted resources should be cleaned **once**, for both — don't make two passes that fight each other.++## Steps++1. **Confirm the target(s).** Make sure the user named one or more of: `contacts`, `companies`, `deals`, `tags`, `tasks`. If ambiguous, ask. Confirm the full set before running — the deletion is irreversible.++ **`contacts` is the spine of the CRM — confirm the cascade scope before starting.** It is the widest deletion of the five: notes attach to `contacts | deals`, tasks belong only to contacts, `tags` is a field only on `Contact`, companies aggregate `nb_contacts`, and deals link contacts via `contact_ids`. Removing contacts leaves notes/tasks/tags with no attachment target. Ask the user how far the deletion should cascade (e.g. *"contacts only, leave notes/tasks/tags as compiling shells"* vs *"also delete the now-orphaned subsystems"*) and whether to touch the backend — the answer changes the whole job. (For `contacts`, narrowing the notes union lands on `"deals"`, so notes stays valid as long as deals exists; tasks/tags become orphaned shells.)++ **`companies` is also a spine/link resource — confirm the cascade scope too.** It owns the companies table *and* is a `company_id` link on **both** `contacts` and `deals`, its `companies_summary` view aggregates `nb_contacts`/`nb_deals`, and it adds a **denormalized `company_name`** to the `Contact` type. So it fans out far wider than its folder (≈50 frontend files + backend). Ask whether to **remove `company_id` fully** (cleanest — drops the column from the `Contact`/`Deal` types, the CSV import/export, `mergeContacts`, the fakerest generators, and i18n) or **leave it as an orphaned shell** (keep the column typed `Identifier`, default `null`/unset, but delete all company UI). The full removal is what makes the deletion large; the shell option compiles but leaves dead FKs pointing at a dropped table.++2. **Run the script** from the project root, passing one or more resource names as arguments:++ ```bash+ npx -y tsx .claude/skills/delete-initial-resource/delete-initial-resource.ts <resource> [<resource> ...]+ ```++ Node 18 cannot run TypeScript directly, so `tsx` is required (`npx -y` fetches it if absent). The script:+ - Validates every resource name (exiting with an error if any is unknown) and exits if a folder is missing.+ - Deletes `src/components/atomic-crm/<resource>/` recursively for each name.+ - Prints the **merged, de-duplicated** list of **dependent files** (files elsewhere that reference the resource(s)) plus shared files like `root/CRM.tsx`, with files inside any deleted folder removed.++3. **Clean up each dependent file** printed by the script. For every path, open it and remove the parts that reference the deleted resource:+ - Imports of components/types from the deleted folder.+ - JSX usage, routes, menu/navigation entries, dashboard widgets.+ - Resource registration in `src/components/atomic-crm/root/CRM.tsx` (the `<Resource name="...">` entry and its imports).+ - In activity-log, fakerest data generators, and import/export helpers: drop the resource's branches/fields.+ - The `Tag`/`Deal`/… type in `types.ts`, and any field the resource adds to another record (e.g. `tags` is a `number[]` on `Contact`). Removing a *field* fans out much wider than removing a *standalone* resource: the merge logic (`providers/commons/mergeContacts.ts`), import paths (`useContactImport.tsx`, `useImportFromJson.ts`), i18n message catalogs (`english`/`frenchCrmMessages.ts`), Storybook stories/tests, the `StoryWrapper` record builders, and the sample CSVs (`contacts_export.csv`, `test-data/contacts.csv` — drop the column from the header **and** every row) all carry it.+ - **Aggregated `nb_<resource>` columns fan out like a field even when the resource is "standalone".** `tasks` looks self-contained, but `contacts_summary` exposes a `nb_tasks` count that lands on the `Contact` type and is read in `CompanyShow.tsx`, `ContactListContent.tsx`, `ContactShow.tsx`, `ContactListFilter.tsx` (a `nb_tasks@gt` filter) and the FakeRest provider/generators (which increment/decrement it). Likewise `companies_summary` exposes `nb_contacts` (read in `CompanyShow.tsx`'s contacts tab, `CompanyCard.tsx`'s avatar group, `CompanyList.tsx`'s sort fields, and incremented in the FakeRest contact callbacks/generator). **`nb_<resource>` is invisible to a `\b<resource>\b` grep** (the `_` is a word char), so these only surface under `tsc` — grep `nb_<resource>` separately.+ - **Resource-specific configuration props fan out too.** `tasks` ships a `taskTypes` prop (like `dealStages`, `noteStatuses`): it lives in `root/defaultConfiguration.ts`, the `ConfigurationContextValue` interface (`root/ConfigurationContext.tsx`), `root/CRM.tsx` (prop default, jsdoc, store seed), the `App.tsx` doc comment, and `settings/SettingsPage.tsx` — which has **both** an editor `<Card>` **and** an entry in the section-list/sidebar array; remove both. `deals` ships **three** (`dealStages`/`dealCategories`/`dealPipelineStatuses`) plus its `<Card>` carries a `validateItemsInUse` helper (exported + unit-tested in `SettingsPage.test.ts`, and backed by a `crm.settings.validation` i18n block) — delete the helper, its test file, and the i18n block. `companies` ships `companySectors` — its Settings `<Card>` holds only a `companySectors` `ArrayInput` (no `validateItemsInUse`), but the prop still lives in `defaultConfiguration.ts`, `ConfigurationContext.tsx`, `CRM.tsx` (default + jsdoc + store seed), `App.tsx`, and `SettingsPage.tsx` (the `<Card>`, the section-list entry, and the `transformFormValues`/`defaultValues` objects). It is also read in `useImportFromJson.ts` to validate an imported company's `sector` — see the import-type note below.+ - **A config prop is not always named after the resource.** `deals` also owned `currency` — it lived inside the Deals settings `<Card>` and its only readers were deal components (`DealsChart`, `DealsPipeline`, `CompanyShow`'s deal iterator). Grep the contents of the resource's settings `<Card>` for any other config key, and trace each one's consumers before deciding to keep it. (Removing `currency` is a judgement call — flag it to the user rather than silently dropping a borderline-general prop.)+ - **Shared subsystems are parameterised by the resource, not keyed to a folder.** The notes feature (`notes/`) is generic over `reference: "contacts" | "deals"` (see `foreignKeyMapping.ts`, `NoteInputs.tsx`, `NoteCreate.tsx`, `Note.tsx`, `NoteAttachments.tsx`, `NotesIterator.tsx`); the activity log is generic over a `"company" | "contact" | "deal" | "all"` context union (`ActivityLog.tsx`, `ActivityLogContext.tsx`). Deleting `deals` means **narrowing the union to drop the deal member** and pruning the now-dead branches — `=== "contacts"` comparisons stay valid (so `tsc` won't flag them), but `=== "deals"`/`deal_id`/`DealNote` must go. The activity log also has per-type render components (`ActivityLogDealCreated.tsx`, `ActivityLogDealNoteCreated.tsx`) to delete outright, branches in `ActivityLogIterator.tsx`, a `getNewDealsAndNotes` fetcher in `providers/commons/activity.ts`, and the `DEAL_CREATED`/`DEAL_NOTE_CREATED` consts + `ActivityDeal*` union members in `consts.ts`/`types.ts`.+ - **Deleting `contacts` narrows the same subsystems the other way — and trips a typing landmine.** The notes union narrows to `"deals"`; the activity-log union drops `"contact"`. Two extra wrinkles: (a) the notes feature has **contact-only *mobile* components** (`NoteCreateSheet.tsx`, `NoteEditSheet.tsx`, `NoteShowPage.tsx`, `NotesIteratorMobile.tsx`, `NoteInputsMobile.tsx`) that are dead once contacts is gone — delete them outright, drop the `NotesIteratorMobile` re-export from `notes/index.ts`, and clean their importers (`MobileNavigation.tsx`, the mobile `<Resource name="contacts">` note route in `CRM.tsx`). (b) **`DealNote.status` is typed `undefined`** (a deliberate ContactNote-compat marker in `types.ts`), so retyping `NoteInputs`'s `useFormContext<ContactNote | DealNote>` down to `<DealNote>` collapses `status` to `never` and `tsc` rejects the status-hydration `setValue("status", …)`. Widen it back with `useFormContext<Omit<DealNote, "status"> & { status?: string }>()`.+ - **Deleting `companies` combines a standalone-table delete with a column removal on two resources.** Like `deals`/`contacts` it has a dedicated activity-log branch (`company.created` → delete `ActivityLogCompanyCreated.tsx` outright + the branch in `ActivityLogIterator.tsx` + `COMPANY_CREATED` in `consts.ts`/`types.ts`) and a `"company"` member in the `ActivityLogContext` union — narrowing that union turns the `=== "company"` checks in `ActivityLogContactCreated`/`ActivityLogContactNoteCreated`/`ActivityLogDealCreated`/`ActivityLogDealNoteCreated` into type errors, so prune those branches (the `company_id` "to/at `<company>`" ReferenceField + the `CompanyAvatar` in the deal-note header). It is *also* a `company_id` **link** on contacts (`ContactInputs` selector, `ContactShow`/`ContactListContent` avatar+name) and on deals (`DealInputs` required selector, `DealCard`/`DealShow`/`DealEdit` avatar, `DealList` filter), plus the note-header `CompanyAvatar` in `notes/Note.tsx`. **`companies` also adds a *denormalized* `company_name` to `Contact`** (from `companies_summary`'s `c.name as company_name`) — read in `ContactOption.tsx`, `deals/ContactList.tsx`, `dashboard/HotContacts.tsx`, and the `position_at_company` rendering. **`company_name` is invisible to a `\bcompan(y|ies)\b` grep** — grep `company_name` separately, just like `nb_<resource>`. One artifact: `deals/OnlyMineInput.tsx` uses a **mislabeled** i18n key `resources.companies.filters.only_mine` ("Only companies I manage") even though it filters deals — re-point it to a deals key rather than deleting the input.+ - **A resource can be a LINK/field on *other* resources, not just a standalone table.** `contacts` is referenced by `deals.contact_ids` (a contact selector in `DealInputs.tsx`, a per-deal `<ContactList/>` in `DealShow.tsx` + the standalone `deals/ContactList.tsx` to delete, and the "create a contact first" gate in `DealEmpty.tsx`) and by `tasks.contact_id` (the whole `tasks/` contact-linking UI: `AddTask`, `Task`, `TaskCreateSheet`, `TaskEditSheet`, `TaskFormContent`'s `selectContact`, and the `showContact`/`filterByContact` threading in `TasksIterator`/`TasksListFilter`/`TasksListByDueDate`). Decide per-link whether to **keep the column as an orphaned shell** (e.g. leave `deals.contact_ids` as `Identifier[]`, default `[]`) or drop it — and remove the UI either way.+ - **Custom dataProvider methods live in both providers and feed the `CrmDataProvider` type.** `deals` had an `unarchiveDeal(deal)` method in **both** `providers/fakerest/dataProvider.ts` and `providers/supabase/dataProvider.ts`; `CrmDataProvider` is `ReturnType<typeof getDataProviderWithCustomMethods>` (the supabase provider), so removing it there drops it from the type automatically. `contacts` likewise owns `mergeContacts(sourceId, targetId)` in both providers (the FakeRest one delegates to `providers/commons/mergeContacts.ts` — delete that file; the supabase one invokes the `merge_contacts` edge function — see backend). Also clean the resource's lifecycle-callback blocks in both providers and any sales-deletion reassignment (`beforeDelete`): for `contacts` that means the `contacts`/`contact_notes` callbacks, the `tasks` callbacks that maintain `nb_tasks` on the contact, `processContactAvatar`/`getContactAvatar` (delete `providers/commons/getContactAvatar.ts` + test), and the supabase `getList` routing `contacts -> contacts_summary` + the `activity_log` `contact_note -> contactNote` remap. **`companies` has no custom dataProvider method but a lot of lifecycle machinery in both providers**: the supabase `getList`/`getOne` route `companies -> companies_summary` (drop both branches) and the contacts FTS list adds `company_name`; the FakeRest provider has a `processCompanyLogo` (favicon), a `fetchAndUpdateCompanyData` that stamps `company_name` onto contacts (called from the `contacts` `beforeCreate`/`beforeUpdate`), an `updateCompany` helper that maintains `nb_contacts`/`nb_deals` from the `contacts`/`deals` `afterCreate`/`afterDelete` callbacks, the whole `companies` callback block, the `companies` arm of the `sales` `beforeDelete` reassignment, and the `getActivityLog(dataProvider, companyId, salesId)` call (drop the `companyId` arg — and the `companyId`/`company_id` filter plumbing in `providers/commons/activity.ts`). Delete `providers/commons/getCompanyAvatar.ts` + its test.+ - **The FakeRest data generators are deeply company-coupled — they don't just reference the field, they drive record creation.** `dataGenerator/companies.ts` is deleted outright and dropped from `index.ts` (mind the generation order: sales → tags → [companies] → contacts → …) and `types.ts` (`Db.companies`). But `contacts.ts` *picks a company* to derive each contact's `company_id`/`company_name`/`sales_id`/`first_seen` (and enforces a per-company-size `maxContacts` cap), and `deals.ts` *picks a company* then filters contacts by `company_id` for `contact_ids` and takes `sales_id` from the company — rewrite both to pick a **random sale** (`db.sales`) and use `randomDate()` for the base date, and (for deals) pick random contacts. The `faker` library's own `company` namespace import (e.g. `company as fakerCompany` for `bsAdjective()` titles) is unrelated — keep it.+ - Some "wrapper" components outside the resource folder exist only to render it (e.g. `dashboard/TasksList.tsx`, `contacts/ContactTasksList.tsx`; for `deals`: `dashboard/DealsChart.tsx`, `dashboard/DealsPipeline.tsx`; for `contacts`: `dashboard/HotContacts.tsx` and `dashboard/DashboardStepper.tsx` — a contacts widget and a contact-onboarding wizard) — delete these outright rather than editing them, then clean their importers (e.g. `Dashboard.tsx` keeps both an import *and* a `{totalDeal ? <DealsChart/> : null}` JSX site — remove both; for contacts, `Dashboard.tsx`/`MobileDashboard.tsx` also gate the whole render on contact/contactNote counts via the stepper — drop that gating).+ - **The JSON importer (`misc/useImportFromJson.ts`) treats some resources as top-level importable TYPES.** `companies` (like `sales`/`contacts`/`notes`/`tasks`) is one: it has an `importCompany` function, a `"$.companies.*"` parser path, a `companies` arm in the `TYPES` array + the `switch`, `CompanyImport`/`isCompany` guards, a `mapSizeToCategory` helper, `companies` keys in the `stats`/`failedImports`/`idsMaps` objects, and a `companySectors`-based sector validation — remove all of it, plus the `company_id` mapping that `importContact` applies to imported contacts. Mirror the same trims in `ImportPage.tsx` (the stats table row + the help-text sentence) and the `import-sample.json` fixture (drop the `companies` array + the contact `company_id`). The CSV importer (`useContactImport.tsx`) similarly has a `getCompanies` cache + a `company` column that maps to `company_id`.+ - Don't forget `useCallback`/`useMemo` dependency arrays — a stale `getTags`/`getCompanies` reference there is invisible until `tsc` runs.++4. **Check the backend** (the script only touches frontend files). Removing a resource usually also means:+ - Dropping or adjusting the table/view in `supabase/schemas/` and generating a migration (`npx supabase db diff --local -f remove_<resource>`).+ - Updating `contacts_summary` / `companies_summary` views if they aggregated the removed data (e.g. `companies_summary` exposed `count(distinct d.id) as nb_deals` plus a `left join public.deals` — drop both).+ - The `activity_log` view (`03_views.sql`) is a `UNION ALL` where **every branch declares the same column set** — `deals` contributed a `deal` and a `deal_note` column to *all* branches **and** two dedicated branches (`deal.created`, `dealNote.created`). Remove the deal columns from every branch (keep the column lists aligned) and delete the two deal branches. The supabase provider then mirrors this: `providers/supabase/dataProvider.ts` `getList("activity_log")` renames the snake_case view columns to camelCase (`deal_note` → `dealNote`) — drop that mapping line too.+ - `06_grants.sql` grants **both** the table and its `<resource>_id_seq` sequence — remove both, or `db diff` fails with `relation "public.<resource>_id_seq" does not exist`.+ - `05_policies.sql` has an `alter table … enable row level security` line *and* a block of `create policy` statements — remove both.+ - If the resource is referenced inside a SQL function (e.g. `merge_contacts` in `02_functions.sql` merges `tags` and reassigns `tasks`), drop those lines and the now-unused local variable declaration. Editing `02_functions.sql` makes `db diff` regenerate the whole function — that's expected; renumber the leftover step comments so they stay sequential.+ - **Deleting `contacts` removes whole functions/triggers and orphans others.** Drop the `contacts` + `contact_notes` tables and the `tasks.contact_id` column (its FK + index), the `contacts_summary` view, and the contact-specific functions `merge_contacts`, `handle_contact_saved`, `handle_contact_note_created_or_updated` outright — plus their triggers/policies/grants and the `contacts_id_seq` / `"contactNotes_id_seq"` sequence grants. Two helper functions become **orphaned** once the contact triggers are gone: `get_avatar_for_email` (only called by `handle_contact_saved`) and `lowercase_email_jsonb` (only wired to the contact email trigger) — remove them and their grants too. The `activity_log` view carries the contact pattern (a `contact` + `contact_note` column on every branch **and** two dedicated branches `contact.created` / `contactNote.created`) just like deals.+ - **Deleting `companies` drops a table + a column on two resources, and trips an orphan subtlety.** Drop the `companies` table, the `companies_id_seq` grant, the `company_id` columns on **both** `contacts` and `deals` (their FKs `contacts_company_id_fkey`/`deals_company_id_fkey` + indexes `contacts_company_id_idx`/`deals_company_id_idx`), the `companies_summary` view (+ its grant), the `companies` RLS-enable line + its 4 policies, and the table grants. Update `contacts_summary` to drop `co.company_id`, the `c.name as company_name` column, the `left join public.companies`, and narrow the `group by` to `co.id`. The `activity_log` view carries the company pattern (a `company` column on **every** branch **and** a dedicated `company.created` branch) — remove the `company` + `company_id` columns from all branches (the `contactNote`/`dealNote` branches only joined to a table to fetch `company_id`, so drop those now-unused joins) and delete the `company.created` branch. Drop the company-only function `handle_company_saved` (favicon-from-website trigger) + its `company_saved` trigger + its grant, and the `set_company_sales_id_trigger`. **Orphan subtlety:** `handle_company_saved` calls `get_domain_favicon`, but `get_domain_favicon` is **also** called by `get_avatar_for_email` (contact avatars) — so it is **not** orphaned; **keep** it and the `favicons_excluded_domains` table. Finally drop the `company_id` line from `merge_contacts` in `02_functions.sql`.+ - Grep the **edge functions** too — they are separate from the schema and easy to miss: `supabase/functions/merge_contacts/index.ts`, `supabase/functions/_shared/db.ts` (Kysely table types), `supabase/functions/postmark/addNoteToContact.ts`, and especially `supabase/functions/mcp/` — the **MCP edge function is a whole AI subsystem** that may have tooling dedicated to a resource. For `tasks` it had `mcp/taskListUi.ts` (a 13 KB guest-HTML "MCP App" — delete outright), `display_task_list` + `complete_task` tools and prompt examples in `mcp/index.ts` (plus a now-unused `CRM_BASE_URL` env var + comment in `supabase/functions/.env`), and a `tasks` example in `mcp/validateSql.test.ts`. The depth varies per resource: `deals` had **no** dedicated MCP App — only its `DealsTable` Kysely interface in `_shared/db.ts`, the deal-reassignment step in `merge_contacts/index.ts` (whose removal left the `sql` import unused — drop it), and deal mentions in the `query`/`mutate` tool **prompt-text examples** in `mcp/index.ts` (rewrite the examples, don't just delete lines). `contacts` is the deepest: delete the **whole `merge_contacts/` edge function** (and its `[functions.merge_contacts]` block in `config.toml`) and the **whole `postmark/` inbound-email function** (it parses emails into contact notes — also remove its `[functions.postmark]` block; note this leaves the inbound-email settings UI in `ProfilePage`/`SettingsPageMobile` and the `POSTMARK_*`/`VITE_INBOUND_EMAIL` env vars hollow — flag that to the user). In `_shared/db.ts` drop `ContactsTable`/`ContactNotesTable`, the `tasks.contact_id` field, and their `Database` registrations. In `mcp/`: it was `contacts` (not tasks) that drove the `CRM_BASE_URL` env var — the `display_task_list` tool's `contact_name`/`contact_id` schema fields and `taskListUi.ts`'s contact-link rendering exist only to deep-link task→contact, so removing them makes `CRM_BASE_URL` (in `mcp/index.ts`, the `__CRM_BASE_URL__` HTML placeholder, and `supabase/functions/.env`) dead — drop it. Also rewrite the `contacts`/`contacts_summary` mentions in the `get_schema`/`query`/`mutate` prompt examples, and swap the `contacts` table name in `mcp/validateSql.test.ts` fixtures for a surviving table. `companies` is interesting because the **`postmark/` inbound-email function auto-creates a company from the sender's email domain** (`getOrCreateCompanyFromDomain` in `addNoteToContact.ts`, `extractCompanyName` in `extractMailContactData.ts`) and links the new contact via `company_id` — but unlike `contacts` (delete the whole function), for `companies` you **keep** postmark and surgically remove the company bits: delete `getOrCreateCompanyFromDomain`, drop the `domain`/`companyName`/`website` params threaded through `getOrCreateContactFromEmailInfo`/`addNoteToContact`/`index.ts`, drop `company_id` from the contact insert, remove `extractCompanyName` + the `companyName`/`website` output fields + the now-unused `tldts` import from `extractMailContactData.ts`, and update the three postmark test files (`addNoteToContact.test.ts`, `extractMailContactData.test.ts`). **Flag to the user that auto-company-creation on inbound email is gone but contact+note creation still works.** Elsewhere: `_shared/db.ts` declares `company_id` on **both** `ContactsTable` and `DealsTable` (no dedicated `CompaniesTable` exists), `merge_contacts/index.ts` merges `company_id` in `mergeContactData`, and `mcp/index.ts` mentions `companies`/`companies_summary` in the `get_schema`/`query`/`mutate` prompt examples + `mcp/validateSql.test.ts` fixtures (swap for a surviving table). No `config.toml` block changes are needed (postmark + merge_contacts both survive).+ See the `backend-dev` skill for the migration workflow.++5. **Verify** the result compiles and lints:++ ```bash+ make typecheck && make lint+ ```++ Resolve any remaining references the typecheck surfaces (the script's dependent-file list is a guide, not a guarantee of completeness). A final `grep -rniE "\\b<resource>\\b"` over `src/` and `supabase/` is worth it — **and grep the denormalized/aggregated columns (`nb_<resource>`, `company_name`) and any config-prop name (`<resource>Types`, `companySectors`, `currency`, etc.) separately**, since `\b<resource>\b` won't match `nb_tasks` or `company_name`. Watch for substring false positives: deleting `tags` matches `stage`; deleting `deals` matches `ideal` (an English comment in `RelativeDate.tsx`) and the French `affaires`/`Chiffre d'affaires` (= revenue, not a deal) in `frenchCrmMessages.ts` — filter them out (`grep -viE "ideal"`) and don't blindly delete French lines. For `companies`, benign matches to leave: the `faker` library's `company` namespace import in `dataGenerator/contacts.ts` (used for `bsAdjective()` titles), the `reference="companies"`/`source="company_id"` JSDoc examples in the **mutable** `admin/reference-input.tsx` and `admin/list.tsx`, and email-domain fixtures like `@company.com`/`[email protected]` in test bodies. For `contacts`, several matches are **benign and intentionally left**: `resources.companies.field_categories.contact` (a company "Company info" section label, not the contacts resource — in `CompanyInputs.tsx`/`CompanyAside.tsx`), the `resource="contacts"` JSDoc examples in `misc/CreateSheet.tsx`/`EditSheet.tsx`, and the now-unused `resources.contacts.*` blocks in the i18n catalogs (harmless dead translation keys — removing them is optional and large, so flag rather than force it). `supabase/migrations/` also keeps historical contact references — never edit past migrations.++ The same **dead-i18n-key** judgement applies to every resource (`resources.companies.*`, `position_at_company`, `you_added_company`/`at_company`, `crm.settings.companies.*`, etc. after a `companies` delete): they're unused but harmless, and crucially **`frenchCrmMessages.ts` is type-checked against the `CrmMessages` type derived from `englishCrmMessages.ts`**, so you must remove a key from **both** catalogs or **neither** — a one-sided removal is a `tsc` error. Because it's all-or-nothing and large, prefer to **flag** the dead keys to the user rather than force the cleanup. Likewise `test-data/contacts.csv` keeps `company_id`/`company_name`/`company` columns after a `companies` delete — the contact CSV importer ignores unknown columns, so leaving them is harmless (dropping them means editing the header **and** all ~500 rows — flag it).++ **`frenchCrmMessages.ts` uses literal `…` escapes for ellipses.** The `Edit` tool's char↔escape swapping copes with a single occurrence but can fail to match a block that spans one — if an exact-string Edit fails there, fall back to deleting the block by line range (`sed -i '<from>,<to>d'`) after confirming the line numbers with a fresh read.++ If local Supabase is running, verify the migration end-to-end with `npx supabase db reset --local` — it replays the whole chain (including your new migration) and reloads `seed.sql`, catching a broken view/function/grant that `db diff` alone won't. (Benign `index "…_pkey" does not exist, skipping` NOTICEs appear because the generated migration drops indexes after the table drop already removed them.)++ Note: `make test` (vitest) requires Node ≥ 20.12 — under Node 18 it aborts at startup with `crypto.hash is not a function` before any test loads, so typecheck + lint are the reliable gates here.++## Notes++- The deletion is irreversible — rely on git to recover if needed. Confirm the resource with the user before running.+- The dependent-file list lives inside the script (`dependentFiles`); if the codebase grows new references, update that map so future runs stay accurate.diff --git a/.claude/skills/delete-initial-resource/delete-initial-resource.ts b/.claude/skills/delete-initial-resource/delete-initial-resource.tsindex 74aef937..c487a576 100755--- a/.claude/skills/delete-initial-resource/delete-initial-resource.ts+++ b/.claude/skills/delete-initial-resource/delete-initial-resource.ts@@ -1,68 +1,367 @@-#!/usr/bin/node-+// Run with `npx -y tsx .claude/skills/delete-initial-resource/delete-initial-resource.ts`.+// `process` is declared locally because this standalone script lives outside the+// project's tsconfig and so doesn't pick up the global @types/node.declare const process: {- cwd(): unknown;- argv: string[];- exit(code?: number): never;+ cwd(): string;+ argv: string[];+ exit(code?: number): never;};import { existsSync } from "node:fs";import { rm } from "node:fs/promises";// ================================ CONSTANTS ================================const initialResource = [- "contacts",- "companies",- "deals",- "tags",- "tasks",+ "contacts",+ "companies",+ "deals",+ "tags",+ "tasks",] as const;const dependentFiles: ResourceFiles = {- companies: [- "src/components/atomic-crm/contacts/ContactInputs.tsx",- "src/components/atomic-crm/deals/DealInputs.tsx",- "src/components/atomic-crm/activity/ActivityLogCompanyCreated.tsx",- "src/components/atomic-crm/activity/ActivityLogDealNoteCreated.tsx",- "src/components/atomic-crm/contacts/ContactShow.tsx",- "src/components/atomic-crm/dashboard/DealsPipeline.tsx",- "src/components/atomic-crm/deals/DealCard.tsx",- "src/components/atomic-crm/deals/DealEdit.tsx",- "src/components/atomic-crm/deals/DealShow.tsx",- "src/components/atomic-crm/notes/Note.tsx",- ],- contacts: [- "src/components/atomic-crm/companies/CompanyShow.tsx",- "src/components/atomic-crm/misc/useImportFromJson.ts",- "src/components/atomic-crm/providers/fakerest/dataGenerator/contacts.ts",- "src/components/atomic-crm/dashboard/DashboardStepper.tsx",- "src/components/atomic-crm/layout/MobileNavigation.tsx",- "src/components/atomic-crm/activity/ActivityLogContactCreated.tsx",- "src/components/atomic-crm/activity/ActivityLogContactNoteCreated.tsx",- "src/components/atomic-crm/companies/CompanyCard.tsx",- "src/components/atomic-crm/companies/CompanyShow.tsx",- "src/components/atomic-crm/dashboard/HotContacts.tsx",- "src/components/atomic-crm/deals/ContactList.tsx",- "src/components/atomic-crm/misc/ContactOption.tsx",- ],- deals: [- "src/components/atomic-crm/dashboard/DealsPipeline.tsx",- "src/components/atomic-crm/dashboard/DealsChart.tsx",- "src/components/atomic-crm/companies/CompanyShow.tsx",- ],- tags: [- "src/components/atomic-crm/misc/useImportFromJson.ts",- "src/components/atomic-crm/contacts/TagsListEdit.tsx",- "src/components/atomic-crm/contacts/BulkTagButton.tsx",- ],- tasks: [- "src/components/atomic-crm/dashboard/TasksList.tsx",- "src/components/atomic-crm/contacts/ContactAside.tsx",- "src/components/atomic-crm/layout/MobileNavigation.tsx",- "src/components/atomic-crm/contacts/ContactTasksList.tsx",- ],+ companies: [+ // `companies` is a SPINE/LINK resource like contacts: it owns the companies+ // table AND is a `company_id` link on BOTH `contacts` and `deals`, AND its+ // `companies_summary` view exposes aggregated `nb_contacts`/`nb_deals` plus a+ // denormalized `company_name` that lands on the `Contact` type. So it fans out+ // far wider than the standalone folder. CONFIRM CASCADE SCOPE with the user:+ // remove `company_id` fully (cleanest — drops the column from Contact/Deal,+ // CSVs, merge, generators) vs leave it as an orphaned shell. See SKILL.md.+ "src/components/atomic-crm/types.ts", // Company, ActivityCompanyCreated, Contact.company_id+company_name, Deal.company_id+ "src/components/atomic-crm/consts.ts", // COMPANY_CREATED++ // Activity log — a dedicated `company.created` branch (ActivityLogCompanyCreated,+ // delete outright) PLUS a `"company"` member in the context union. Narrowing the+ // union turns every `=== "company"` check into a type error, so prune them in the+ // contact/deal render components too (the `company_id` ReferenceField / CompanyAvatar):+ "src/components/atomic-crm/activity/ActivityLogCompanyCreated.tsx", // delete outright+ "src/components/atomic-crm/activity/ActivityLog.tsx", // companyId prop + company_id filter; context union+ "src/components/atomic-crm/activity/ActivityLogContext.tsx", // "company"|"contact"|"deal"|"all" union+ "src/components/atomic-crm/activity/ActivityLogIterator.tsx", // COMPANY_CREATED import + branch+ "src/components/atomic-crm/activity/ActivityLogContactCreated.tsx", // company_id "to <company>" block + context==="company"+ "src/components/atomic-crm/activity/ActivityLogContactNoteCreated.tsx", // context==="company"+ "src/components/atomic-crm/activity/ActivityLogDealCreated.tsx", // company_id "to <company>" block + context==="company"+ "src/components/atomic-crm/activity/ActivityLogDealNoteCreated.tsx", // CompanyAvatar + "at_company <company>" + context==="company"+ "src/components/atomic-crm/providers/commons/activity.ts", // getNewCompanies fetcher + company_id on contact/deal activities + companyId param++ // `companySectors` config prop (like dealStages/taskTypes — fans out beyond the folder).+ // The Companies settings <Card> holds only a `companySectors` ArrayInput (NO validateItemsInUse):+ "src/components/atomic-crm/root/defaultConfiguration.ts", // defaultCompanySectors + the default config object+ "src/components/atomic-crm/root/ConfigurationContext.tsx", // companySectors in the interface+ "src/components/atomic-crm/settings/SettingsPage.tsx", // the Companies <Card> AND the section-list entry + transform/defaultValues+ "src/App.tsx", // the prop-list doc comment++ // Contacts feature — `company_id` is a contact field with a company selector,+ // a company avatar/name in the show + lists, and `company_name` (DENORMALIZED+ // from companies_summary) used for "position_at_company". `company_name` is+ // INVISIBLE to a \bcompan(y|ies)\b grep — grep `company_name` separately:+ "src/components/atomic-crm/contacts/ContactInputs.tsx", // AutocompleteCompanyInput ReferenceInput+ "src/components/atomic-crm/contacts/ContactShow.tsx", // company avatar/name (desktop + mobile)+ "src/components/atomic-crm/contacts/ContactListContent.tsx", // company ReferenceField (desktop + mobile)+ "src/components/atomic-crm/contacts/ContactList.tsx", // exporter fetchRelatedRecords companies + `company` CSV column+ "src/components/atomic-crm/contacts/contactModel.ts", // exportToVCard `company?` param + ORG: line+ "src/components/atomic-crm/contacts/ExportVCardButton.tsx", // useGetOne("companies") + passes company to exportToVCard+ "src/components/atomic-crm/contacts/useContactImport.tsx", // getCompanies cache, company column, company_id mapping+ "src/components/atomic-crm/contacts/Avatar.tsx", // stale "if we come from company page" comment only+ "src/components/atomic-crm/contacts/contacts_export.csv", // drop the `company` column (header + every row)++ // Deals feature — `company_id` is a required deal field with a selector + a+ // company avatar in card/show/edit + a company filter in the list:+ "src/components/atomic-crm/deals/DealInputs.tsx", // AutocompleteCompanyInput ReferenceInput (required)+ "src/components/atomic-crm/deals/DealCard.tsx", // company ReferenceField title + CompanyAvatar+ "src/components/atomic-crm/deals/DealShow.tsx", // CompanyAvatar header+ "src/components/atomic-crm/deals/DealEdit.tsx", // CompanyAvatar header+ "src/components/atomic-crm/deals/DealList.tsx", // company_id ReferenceInput filter+ "src/components/atomic-crm/deals/OnlyMineInput.tsx", // MISLABELED i18n key resources.companies.filters.only_mine — re-point to deals+ "src/components/atomic-crm/deals/ContactList.tsx", // company_name in position_at_company++ // SHARED notes subsystem — the note header avatar resolved a `company_id`+ // ReferenceField (CompanyAvatar). Remove it from Note.tsx:+ "src/components/atomic-crm/notes/Note.tsx",++ // Dashboard — HotContacts shows company_name; DealsPipeline leftAvatar is a CompanyAvatar:+ "src/components/atomic-crm/dashboard/HotContacts.tsx", // company_name in secondaryText+ "src/components/atomic-crm/dashboard/DealsPipeline.tsx", // CompanyAvatar leftAvatar++ // Misc — ContactOption renders company_name; the JSON importer treats+ // `companies` as a top-level importable TYPE (importCompany, $.companies.* path,+ // CompanyImport/isCompany, mapSizeToCategory, companySectors validation, stats/+ // failedImports/idsMaps keys) AND maps company_id onto imported contacts:+ "src/components/atomic-crm/misc/ContactOption.tsx", // company_name+ "src/components/atomic-crm/misc/useImportFromJson.ts", // whole importCompany branch + contact company_id+ "src/components/atomic-crm/misc/ImportPage.tsx", // companies stats row + help text+ "src/components/atomic-crm/misc/import-sample.json", // drop the companies section + contact company_id++ // Providers — getList/getOne route companies -> companies_summary (supabase);+ // FakeRest keeps nb_contacts/nb_deals via updateCompany + company callbacks ++ // processCompanyLogo + fetchAndUpdateCompanyData (company_name on contacts) and+ // reassigns companies in the sales beforeDelete; merge_contacts merges company_id:+ "src/components/atomic-crm/providers/supabase/dataProvider.ts", // processCompanyLogo, companies->companies_summary getList/getOne, contacts FTS company_name, companies lifecycle block+ "src/components/atomic-crm/providers/fakerest/dataProvider.ts", // processCompanyLogo, fetchAndUpdateCompanyData, updateCompany, companies callbacks, nb_contacts/nb_deals, sales beforeDelete reassign, getActivityLog companyId arg+ "src/components/atomic-crm/providers/commons/getCompanyAvatar.ts", // delete outright (+ .test.ts)+ "src/components/atomic-crm/providers/commons/mergeContacts.ts", // company_id merge line+ "src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts", // delete outright+ "src/components/atomic-crm/providers/fakerest/dataGenerator/index.ts", // generateCompanies call + generation order+ "src/components/atomic-crm/providers/fakerest/dataGenerator/types.ts", // Db.companies+ "src/components/atomic-crm/providers/fakerest/dataGenerator/contacts.ts", // picks a company, derives sales_id/first_seen from it — rewrite to a random sale + randomDate()+ "src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts", // picks a company + filters contacts by company_id — rewrite to random contacts + random sale+ "src/components/atomic-crm/providers/commons/englishCrmMessages.ts", // resources.companies block, company_id, company_name, position_at_company, settings.companies, activity you_added_company/at_company (dead keys — removal optional, see SKILL)+ "src/components/atomic-crm/providers/commons/frenchCrmMessages.ts", // same (uses … escapes — see SKILL note)++ // Layout / story harness:+ "src/components/atomic-crm/layout/Header.tsx", // companies nav tab + path matcher+ "src/components/atomic-crm/layout/MobileNavigation.tsx", // companies path matcher+ "src/test/StoryWrapper.tsx", // createCrmDb companies key + company_id/company_name on buildContact+ "test-data/contacts.csv", // company_id/company_name/company columns (importer ignores them — optional, see SKILL)+ ],+ contacts: [+ // `contacts` is the SPINE of the CRM and the WIDEST deletion of the five:+ // notes attach to it, tasks belong to it, tags is a field on it, companies+ // aggregate it (nb_contacts), deals link it (contact_ids), and the activity+ // log + JSON import + merge subsystems all revolve around it. Removing it+ // orphans notes/tasks/tags (their only attachment target disappears) — so+ // CONFIRM THE CASCADE SCOPE with the user first (keep them as compiling+ // shells, or delete them too). See SKILL.md.+ "src/components/atomic-crm/types.ts", // Contact, ContactNote, Company.nb_contacts, Task.contact_id, ActivityContact*+ "src/components/atomic-crm/consts.ts", // CONTACT_CREATED, CONTACT_NOTE_CREATED++ // Activity log — TWO dedicated branches (contact.created, contactNote.created)+ // to delete, plus a "contact" member in the context union to drop:+ "src/components/atomic-crm/activity/ActivityLogContactCreated.tsx", // delete outright+ "src/components/atomic-crm/activity/ActivityLogContactNoteCreated.tsx", // delete outright+ "src/components/atomic-crm/activity/ActivityLogIterator.tsx",+ "src/components/atomic-crm/activity/ActivityLog.tsx", // context: "company"|"contact"|"deal"|"all"+ "src/components/atomic-crm/activity/ActivityLogContext.tsx", // same union+ "src/components/atomic-crm/providers/commons/activity.ts", // getNewContactsAndNotes (FakeRest feed)++ // Dashboard — HotContacts is a contacts widget and DashboardStepper is a+ // contact-onboarding wizard (delete both); Dashboard/MobileDashboard gate on+ // contact counts; LatestNotes mixes contact_notes + a <Contact> renderer:+ "src/components/atomic-crm/dashboard/HotContacts.tsx", // delete outright+ "src/components/atomic-crm/dashboard/DashboardStepper.tsx", // delete outright (contact onboarding)+ "src/components/atomic-crm/dashboard/Dashboard.tsx",+ "src/components/atomic-crm/dashboard/MobileDashboard.tsx",+ "src/components/atomic-crm/dashboard/LatestNotes.tsx",+ "src/components/atomic-crm/dashboard/TasksList.tsx", // <AddTask selectContact/>++ // Companies — nb_contacts fans out like nb_tasks and is INVISIBLE to a+ // \bcontacts?\b grep (the `_` is a word char) — grep `nb_contacts` separately:+ "src/components/atomic-crm/companies/CompanyShow.tsx", // contacts tab + ContactsIterator + nb_contacts+ "src/components/atomic-crm/companies/CompanyCard.tsx", // nb_contacts avatar group+ "src/components/atomic-crm/companies/CompanyList.tsx", // nb_contacts sort field++ // SHARED notes subsystem — generic over `reference: "contacts" | "deals"`.+ // Narrow the union to "deals". GOTCHA: DealNote.status is typed `undefined`+ // (ContactNote-compat), so `useFormContext<DealNote>` collapses status to+ // `never` and breaks the status hydration in NoteInputs — widen with+ // `Omit<DealNote, "status"> & { status?: string }`. The contact-ONLY mobile+ // note components are dead once contacts is gone — delete them outright+ // (and their stories/tests + the index.ts re-export):+ "src/components/atomic-crm/notes/foreignKeyMapping.ts", // drop the contacts key+ "src/components/atomic-crm/notes/NoteInputs.tsx", // narrow; drop contactOptionText + status hydration+ "src/components/atomic-crm/notes/NoteInputs.test.tsx", // drop the "contacts" reference test+ "src/components/atomic-crm/notes/NoteCreate.tsx",+ "src/components/atomic-crm/notes/NotesIterator.tsx",+ "src/components/atomic-crm/notes/Note.tsx", // ContactNote|DealNote -> DealNote+ "src/components/atomic-crm/notes/NoteAttachments.tsx", // same union+ "src/components/atomic-crm/notes/index.ts", // drops the NotesIteratorMobile re-export+ "src/components/atomic-crm/notes/NoteCreateSheet.tsx", // delete outright (contact-only mobile)+ "src/components/atomic-crm/notes/NoteEditSheet.tsx", // delete outright+ "src/components/atomic-crm/notes/NoteShowPage.tsx", // delete outright+ "src/components/atomic-crm/notes/NotesIteratorMobile.tsx", // delete (+ .stories + .test)+ "src/components/atomic-crm/notes/NoteInputsMobile.tsx", // delete (+ .stories + .test)++ // Tasks belong to contacts (contact_id) and carry nb_tasks bookkeeping.+ // Strip the contact-linking UI/queries (keep tasks as a standalone shell):+ "src/components/atomic-crm/tasks/AddTask.tsx",+ "src/components/atomic-crm/tasks/Task.tsx", // showContact + contact ReferenceField+ "src/components/atomic-crm/tasks/TaskCreateSheet.tsx",+ "src/components/atomic-crm/tasks/TaskCreateSheet.stories.tsx", // uses buildContact+ "src/components/atomic-crm/tasks/TaskCreateSheet.test.tsx", // delete (contact-create flow)+ "src/components/atomic-crm/tasks/TaskEditSheet.tsx",+ "src/components/atomic-crm/tasks/TaskFormContent.tsx", // selectContact reference input+ "src/components/atomic-crm/tasks/TasksIterator.tsx", // showContact+ "src/components/atomic-crm/tasks/TasksListFilter.tsx", // showContact+ "src/components/atomic-crm/tasks/TasksListFilter.test.tsx",+ "src/components/atomic-crm/tasks/TasksListByDueDate.tsx", // filterByContact + showContact++ // Deals link contacts via `contact_ids` — keep the column but remove the UI+ // (the selector, the per-deal contact list, the contacts-gated empty state):+ "src/components/atomic-crm/deals/DealInputs.tsx", // contact_ids ReferenceArrayInput + contactOptionText+ "src/components/atomic-crm/deals/DealShow.tsx", // contact_ids ReferenceArrayField + <ContactList/>+ "src/components/atomic-crm/deals/ContactList.tsx", // delete outright (the deal's contact list)+ "src/components/atomic-crm/deals/DealEmpty.tsx", // drop the "create a contact first" gating++ // Misc — ContactOption is a shared option renderer (delete); the JSON+ // importer is heavily contact-coupled (importContact/importNote, contactGender):+ "src/components/atomic-crm/misc/ContactOption.tsx", // delete outright+ "src/components/atomic-crm/misc/useImportFromJson.ts", // importContact, importNote(contact_notes), contactGender, stats/idsMaps+ "src/components/atomic-crm/misc/ImportPage.tsx", // contacts/notes stats rows + help text+ "src/components/atomic-crm/misc/import-sample.json", // drop the contacts + notes sections++ // Providers — `mergeContacts` is a custom dataProvider method in BOTH+ // providers (part of the CrmDataProvider type) backed by the merge_contacts+ // edge+SQL fn; getContactAvatar generates avatars; the supabase getList+ // routes contacts -> contacts_summary and remaps activity_log+ // contact_note -> contactNote:+ "src/components/atomic-crm/providers/commons/mergeContacts.ts", // delete outright+ "src/components/atomic-crm/providers/commons/getContactAvatar.ts", // delete (+ .test.ts)+ "src/components/atomic-crm/providers/fakerest/dataProvider.ts", // mergeContacts, processContactAvatar, contact/contact_notes callbacks, tasks nb_tasks callbacks, sales beforeDelete reassign+ "src/components/atomic-crm/providers/supabase/dataProvider.ts", // mergeContacts, contacts->contacts_summary routing, activity_log contactNote remap, contact(_notes) lifecycle+ "src/components/atomic-crm/providers/fakerest/dataGenerator/contacts.ts", // delete outright+ "src/components/atomic-crm/providers/fakerest/dataGenerator/contactNotes.ts", // delete outright+ "src/components/atomic-crm/providers/fakerest/dataGenerator/finalize.ts", // delete (sets contact status from notes)+ "src/components/atomic-crm/providers/fakerest/dataGenerator/index.ts", // generateContacts/ContactNotes + finalize+ "src/components/atomic-crm/providers/fakerest/dataGenerator/types.ts", // Db.contacts, Db.contact_notes+ "src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts", // contact_ids generation+ "src/components/atomic-crm/providers/fakerest/dataGenerator/tasks.ts", // contact_id + nb_tasks increment+ "src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts", // nb_contacts seed+ "src/components/atomic-crm/providers/commons/englishCrmMessages.ts", // resources.contacts block, nb_contacts, position_at_company, etc.+ "src/components/atomic-crm/providers/commons/frenchCrmMessages.ts", // same (uses … escapes — see SKILL note)++ // Layout / login / story harness:+ "src/components/atomic-crm/layout/Header.tsx", // contacts nav tab + path matcher+ "src/components/atomic-crm/layout/MobileNavigation.tsx", // contacts nav + ContactCreateSheet + NoteCreateSheet + contact_id+ "src/components/atomic-crm/login/SignupPage.tsx", // redirectTo: "/contacts"+ "src/test/StoryWrapper.tsx", // buildContact builder + createCrmDb contacts/contact_notes keys+ ],+ deals: [+ // `deals` LOOKS standalone (it owns the deals + deal_notes tables) but it+ // is woven into two SHARED subsystems — notes and the activity log — adds an+ // aggregated `nb_deals` column to `companies_summary`, ships THREE config props+ // (dealStages/dealCategories/dealPipelineStatuses) PLUS a `currency` prop that is+ // NOT named after the resource, and has a custom `unarchiveDeal` dataProvider+ // method. So it fans out almost as wide as a column removal.+ "src/components/atomic-crm/types.ts", // Deal, DealNote, ActivityDeal*, DealStage, Company.nb_deals+ "src/components/atomic-crm/consts.ts", // DEAL_CREATED, DEAL_NOTE_CREATED+ // Deal-only components living OUTSIDE deals/ — delete these outright:+ "src/components/atomic-crm/dashboard/DealsChart.tsx",+ "src/components/atomic-crm/dashboard/DealsPipeline.tsx",+ "src/components/atomic-crm/activity/ActivityLogDealCreated.tsx",+ "src/components/atomic-crm/activity/ActivityLogDealNoteCreated.tsx",+ "src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts",+ "src/components/atomic-crm/providers/fakerest/dataGenerator/dealNotes.ts",+ // SHARED notes subsystem — parameterised by `reference: "contacts" | "deals"`.+ // Narrow the union to "contacts" and prune the now-dead deal branches (the+ // `=== "contacts"` checks stay valid; only `=== "deals"`/`deal_id` must go):+ "src/components/atomic-crm/notes/foreignKeyMapping.ts",+ "src/components/atomic-crm/notes/NoteInputs.tsx",+ "src/components/atomic-crm/notes/NoteCreate.tsx",+ "src/components/atomic-crm/notes/Note.tsx",+ "src/components/atomic-crm/notes/NoteAttachments.tsx",+ "src/components/atomic-crm/notes/NotesIterator.tsx",+ "src/components/atomic-crm/notes/NoteInputs.test.tsx", // drops the "deals" reference test+ // SHARED activity-log subsystem — branches + a `"deal"` member in the context union:+ "src/components/atomic-crm/activity/ActivityLogIterator.tsx",+ "src/components/atomic-crm/activity/ActivityLog.tsx", // context: "company"|"contact"|"deal"|"all"+ "src/components/atomic-crm/activity/ActivityLogContext.tsx", // same union+ // Dashboard:+ "src/components/atomic-crm/dashboard/Dashboard.tsx", // totalDeal + <DealsChart/>+ "src/components/atomic-crm/dashboard/LatestNotes.tsx", // deal_notes fetch + <Deal/> renderer+ // Providers — note the `unarchiveDeal` custom method lives in BOTH providers and+ // is part of the `CrmDataProvider` type (derived from the supabase provider's return):+ "src/components/atomic-crm/providers/commons/activity.ts", // getNewDealsAndNotes+ "src/components/atomic-crm/providers/commons/mergeContacts.ts", // reassign deal contact_ids+ "src/components/atomic-crm/providers/fakerest/dataProvider.ts", // unarchiveDeal, deal(_notes) callbacks, sales beforeDelete reassign+ "src/components/atomic-crm/providers/supabase/dataProvider.ts", // unarchiveDeal, deal(_notes) callbacks, activity_log deal_note→dealNote remap+ "src/components/atomic-crm/providers/fakerest/dataGenerator/index.ts",+ "src/components/atomic-crm/providers/fakerest/dataGenerator/types.ts",+ "src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts", // nb_deals seed+ "src/components/atomic-crm/providers/commons/englishCrmMessages.ts", // resources.deals, nb_deals, activity, dashboard, settings.deals, settings.validation+ "src/components/atomic-crm/providers/commons/frenchCrmMessages.ts", // same (uses … escapes — see SKILL note)+ "src/components/atomic-crm/providers/commons/i18nProvider.test.ts", // asserts a resources.deals.* key+ // Config props — dealStages/dealCategories/dealPipelineStatuses AND `currency`+ // (currency is deal-scoped but NOT named after the resource — easy to miss):+ "src/components/atomic-crm/root/defaultConfiguration.ts",+ "src/components/atomic-crm/root/ConfigurationContext.tsx",+ "src/components/atomic-crm/settings/SettingsPage.tsx", // the Deals <Card>, the section-list entry, validateItemsInUse + currency input+ "src/components/atomic-crm/settings/SettingsPage.test.ts", // only tests validateItemsInUse — delete outright+ "src/App.tsx", // the prop-list doc comment+ // Companies / contacts / layout consumers (nb_deals badges invisible to \bdeals?\b grep):+ "src/components/atomic-crm/companies/CompanyShow.tsx", // deals tab + DealsIterator + nb_deals+ "src/components/atomic-crm/companies/CompanyCard.tsx", // nb_deals badge+ "src/components/atomic-crm/contacts/ContactMergeButton.tsx", // dealsCount preview+ "src/components/atomic-crm/layout/Header.tsx", // deals nav tab + path matcher+ "src/components/atomic-crm/layout/MobileNavigation.tsx", // deals path matcher+ "src/test/StoryWrapper.tsx", // deals: [] + deal_notes: [] db shape+ ],+ tags: [+ // `tags` is a column on `contacts`, so its references are woven through+ // the contacts feature, the providers, i18n, tests and the sample data.+ "src/components/atomic-crm/types.ts",+ // Tag-only components living under contacts/ — delete these outright:+ "src/components/atomic-crm/contacts/TagsList.tsx",+ "src/components/atomic-crm/contacts/TagsListEdit.tsx",+ "src/components/atomic-crm/contacts/BulkTagButton.tsx",+ // Consumers of the components above + the contacts.tags field:+ "src/components/atomic-crm/contacts/ContactShow.tsx",+ "src/components/atomic-crm/contacts/ContactAside.tsx",+ "src/components/atomic-crm/contacts/ContactListContent.tsx",+ "src/components/atomic-crm/contacts/ContactList.tsx",+ "src/components/atomic-crm/contacts/ContactListFilter.tsx",+ "src/components/atomic-crm/contacts/contactModel.ts",+ "src/components/atomic-crm/contacts/useContactImport.tsx",+ "src/components/atomic-crm/companies/CompanyShow.tsx",+ "src/components/atomic-crm/misc/useImportFromJson.ts",+ "src/components/atomic-crm/providers/commons/mergeContacts.ts",+ // i18n: drop the `bulk_tag` block, `filters.tags`, and the `tags` resource block:+ "src/components/atomic-crm/providers/commons/englishCrmMessages.ts",+ "src/components/atomic-crm/providers/commons/frenchCrmMessages.ts",+ // FakeRest data layer:+ "src/components/atomic-crm/providers/fakerest/dataGenerator/contacts.ts",+ "src/components/atomic-crm/providers/fakerest/dataGenerator/index.ts",+ "src/components/atomic-crm/providers/fakerest/dataGenerator/types.ts",+ // Tests, stories and sample data (the contacts.tags column lives in the CSVs):+ "src/components/atomic-crm/contacts/ContactList.stories.tsx",+ "src/components/atomic-crm/contacts/ContactList.test.tsx",+ "src/test/StoryWrapper.tsx",+ "src/components/atomic-crm/contacts/contacts_export.csv",+ "test-data/contacts.csv",+ ],+ tasks: [+ // `tasks` is a standalone resource, BUT it also adds an aggregated+ // `nb_tasks` column to the `contacts_summary` view (surfaced on the+ // `Contact` type) and ships a `taskTypes` configuration prop — so its+ // references fan out almost as wide as a column removal.+ "src/components/atomic-crm/types.ts",+ // Task-only wrapper components living outside tasks/ — delete outright:+ "src/components/atomic-crm/dashboard/TasksList.tsx",+ "src/components/atomic-crm/contacts/ContactTasksList.tsx",+ "src/components/atomic-crm/providers/fakerest/dataGenerator/tasks.ts",+ // Consumers of the tasks resource / the `nb_tasks` contact field:+ "src/components/atomic-crm/dashboard/Dashboard.tsx",+ "src/components/atomic-crm/layout/MobileNavigation.tsx",+ "src/components/atomic-crm/contacts/ContactShow.tsx",+ "src/components/atomic-crm/contacts/ContactShow.test.tsx",+ "src/components/atomic-crm/contacts/ContactAside.tsx",+ "src/components/atomic-crm/contacts/ContactListContent.tsx", // nb_tasks badge — invisible to \btasks?\b grep+ "src/components/atomic-crm/contacts/ContactListFilter.tsx",+ "src/components/atomic-crm/contacts/ContactMergeButton.tsx",+ "src/components/atomic-crm/companies/CompanyShow.tsx", // nb_tasks badge — invisible to \btasks?\b grep+ // Import / merge logic:+ "src/components/atomic-crm/misc/useImportFromJson.ts",+ "src/components/atomic-crm/misc/ImportPage.tsx",+ "src/components/atomic-crm/misc/import-sample.json",+ "src/components/atomic-crm/providers/commons/mergeContacts.ts",+ // FakeRest data layer (generators + provider callbacks that keep nb_tasks):+ "src/components/atomic-crm/providers/fakerest/dataProvider.ts",+ "src/components/atomic-crm/providers/fakerest/dataGenerator/index.ts",+ "src/components/atomic-crm/providers/fakerest/dataGenerator/types.ts",+ "src/components/atomic-crm/providers/fakerest/dataGenerator/contacts.ts", // nb_tasks+ "src/test/StoryWrapper.tsx", // tasks: [] db shape + nb_tasks on the contact builder+ // i18n: drop the `tasks` resource block, `task_count`, `upcoming_tasks`,+ // `filters.tasks`, `settings.tasks` and the import description:+ "src/components/atomic-crm/providers/commons/englishCrmMessages.ts",+ "src/components/atomic-crm/providers/commons/frenchCrmMessages.ts",+ // `taskTypes` configuration prop (fans out like dealStages/noteStatuses):+ "src/components/atomic-crm/root/defaultConfiguration.ts",+ "src/components/atomic-crm/root/ConfigurationContext.tsx",+ "src/components/atomic-crm/settings/SettingsPage.tsx", // the Tasks <Card> AND the section-list entry+ "src/App.tsx", // the prop-list doc comment+ ],} as const;const sharedDependentFiles: string[] = [- "src/components/atomic-crm/root/CRM.tsx",-] as const;+ "src/components/atomic-crm/root/CRM.tsx",+];const resourceFilesPath = "src/components/atomic-crm" as const;// ================================ TYPES ================================@@ -70,68 +369,88 @@ type InitialResource = (typeof initialResource)[number];type DependentFile = string;type ResourceFiles = Record<InitialResource, DependentFile[]>;-// ================================ FONCTIONS ================================+// ================================ FUNCTIONS ================================const main = async () => {- const resourceToDelete = getResource();- const basePath = process.cwd() as string;- await deleteIsolatedFiles(resourceToDelete, basePath);- returnDependentFiles(resourceToDelete);+ const resourcesToDelete = getResources();+ const basePath = process.cwd();+ for (const resource of resourcesToDelete) {+ await deleteIsolatedFiles(resource, basePath);+ }+ returnDependentFiles(resourcesToDelete);};-// Get the resource to delete from the command line arguments, and check if it's valid-const getResource = (): InitialResource => {- const resourceToDelete = process.argv[2];- if (!resourceToDelete) {- console.error("Please provide a resource to delete.");- process.exit(1);- }+// Get the resources to delete from the command line arguments (one or more),+// validate each one, and de-duplicate.+const getResources = (): InitialResource[] => {+ const args = process.argv.slice(2);+ if (args.length === 0) {+ console.error(+ "Please provide at least one resource to delete (you may pass several).",+ );+ process.exit(1);+ }- if (!checkResourceExists(resourceToDelete)) {- console.error(`Resource "${resourceToDelete}" does not exist.`);- process.exit(1);- }+ const invalid = args.filter(+ (resource) => !initialResource.includes(resource as InitialResource),+ );+ if (invalid.length > 0) {+ console.error(+ `Resource(s) ${invalid+ .map((resource) => `"${resource}"`)+ .join(", ")} do not exist. Valid resources: ${initialResource.join(+ ", ",+ )}.`,+ );+ process.exit(1);+ }- return resourceToDelete as InitialResource;-};-// Check if the resource exists in the initialResource array-const checkResourceExists = (resource: string): boolean => {- if (!initialResource.includes(resource as InitialResource)) {- return false;- }- return true;+ return [...new Set(args)] as InitialResource[];};-// Delete the ressource folder and their files. And return any that failed to delete+// Delete the resource folder and its files.const deleteIsolatedFiles = async (- resource: InitialResource,- basePath: string,+ resource: InitialResource,+ basePath: string,) => {- const folderPath = `${basePath}/${resourceFilesPath}/${resource}`;+ const folderPath = `${basePath}/${resourceFilesPath}/${resource}`;- if (!existsSync(folderPath)) {- console.error(- `Folder for resource "${resource}" does not exist. Skipping deletion of isolated files.`,- );- process.exit(1);- }+ if (!existsSync(folderPath)) {+ console.error(+ `Folder for resource "${resource}" does not exist. Skipping deletion of isolated files.`,+ );+ process.exit(1);+ }- await rm(folderPath, { recursive: true, force: true });+ await rm(folderPath, { recursive: true, force: true });};-// Return to Claude all the files dependent on the deleted resource-const returnDependentFiles = (resource: InitialResource) => {- const dependentFilesToReturn = dependentFiles[resource];- const allDependentFilesToReturn = [- ...dependentFilesToReturn,- ...sharedDependentFiles,- ];-- // eslint-disable-next-line no-console- console.log(- `Dependent files for resource "${resource}":\n`,- allDependentFilesToReturn,- );- process.exit(0);+// Return to Claude all the files dependent on the deleted resource(s).+// When several resources are deleted at once, merge and de-duplicate their+// dependent-file lists, then drop any file that lives inside a folder we just+// deleted (e.g. `companies/CompanyShow.tsx` is a dependent of `contacts`, but+// it is gone once `companies` is deleted too).+const returnDependentFiles = (resources: InitialResource[]) => {+ const deletedFolders = resources.map(+ (resource) => `${resourceFilesPath}/${resource}/`,+ );++ const merged = new Set<DependentFile>([+ ...resources.flatMap((resource) => dependentFiles[resource]),+ ...sharedDependentFiles,+ ]);++ const allDependentFilesToReturn = [...merged]+ .filter((file) => !deletedFolders.some((folder) => file.startsWith(folder)))+ .sort();++ // eslint-disable-next-line no-console+ console.log(+ `Dependent files for resource(s) ${resources+ .map((resource) => `"${resource}"`)+ .join(", ")}:\n`,+ allDependentFilesToReturn,+ );+ process.exit(0);};// ================================ MAIN CALL ================================