A full-featured CRM built with React, shadcn/ui, and Supabase.
apply review
erwanMarmelab92fa45c8da0d
diff --git a/.claude/skills/delete-initial-resource/SKILL.md b/.claude/skills/delete-initial-resource/SKILL.mdindex 115f7395..45bb34cc 100644--- a/.claude/skills/delete-initial-resource/SKILL.md+++ b/.claude/skills/delete-initial-resource/SKILL.md@@ -3,89 +3,20 @@ name: delete-initial-resourcedescription: 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`.+# delete-initial-resource-## How it works+Removes one or more of the five initial Atomic CRM resources (`contacts`, `companies`, `deals`, `tags`, `tasks`) and every reference to them.-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.+## How to proceed-## Deleting several resources at once+1. **Read [`core.md`](core.md) first** — the script, the shapes a resource takes, the backend checklist, and the verify gates. These apply to every resource.+2. **Confirm the target(s)** with the user — the deletion is irreversible. For each resource named, read its file:+ - `contacts` → [`contacts.md`](contacts.md) — spine resource, **confirm cascade scope first**+ - `companies` → [`companies.md`](companies.md) — spine/link resource, **confirm cascade scope first**+ - `deals` → [`deals.md`](deals.md)+ - `tags` → [`tags.md`](tags.md)+ - `tasks` → [`tasks.md`](tasks.md)+3. **Run the script** (see core.md), then clean each dependent file it prints — guided by core.md's "shapes" patterns and the per-resource specifics.+4. **Verify** per core.md: `make typecheck && make lint`, targeted greps, and `db reset` if Supabase is running.-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.+Deleting several at once? See "Deleting several at once" in core.md, and read each named resource's file before editing.diff --git a/.claude/skills/delete-initial-resource/companies.md b/.claude/skills/delete-initial-resource/companies.mdnew file mode 100644index 00000000..56b9fa59--- /dev/null+++ b/.claude/skills/delete-initial-resource/companies.md@@ -0,0 +1,30 @@+# Deleting `companies`++A **spine/link** resource: 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). (Read [`core.md`](core.md) first.)++## Confirm cascade scope first+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 — compiles, but leaves dead FKs pointing at a dropped table).++The full removal is what makes the deletion large.++## Frontend specifics+- **Activity log** — a dedicated `company.created` branch (delete `ActivityLogCompanyCreated.tsx` outright + the branch in `ActivityLogIterator.tsx` + `COMPANY_CREATED` in `consts.ts`/`types.ts`) **and** a `"company"` member in the context union. Narrowing the union turns the `=== "company"` checks in `ActivityLogContactCreated`/`ActivityLogContactNoteCreated`/`ActivityLogDealCreated`/`ActivityLogDealNoteCreated` into type errors — prune those branches (the `company_id` "to/at `<company>`" ReferenceField + the `CompanyAvatar` in the deal-note header). `ActivityLog.tsx` has a `companyId` prop + `company_id` filter; `providers/commons/activity.ts` has a `getNewCompanies` fetcher + `companyId` param.+- **`company_id` link** on contacts (`ContactInputs` selector, `ContactShow`/`ContactListContent` avatar+name, the exporter's `fetchRelatedRecords` + the `company` CSV column, `contactModel.ts`'s vCard `ORG:` line, `ExportVCardButton.tsx`) and on deals (`DealInputs` required selector, `DealCard`/`DealShow`/`DealEdit` avatar, `DealList` filter), plus the note-header `CompanyAvatar` in `notes/Note.tsx`.+- **Denormalized `company_name`** (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. **Invisible to a `\bcompan(y|ies)\b` grep** — grep `company_name` separately.+- **`companySectors` config prop** — the Companies `<Card>` holds only a `companySectors` `ArrayInput` (no `validateItemsInUse`); the prop also lives in `defaultConfiguration.ts`, `ConfigurationContext.tsx`, `CRM.tsx`, `App.tsx`, and `SettingsPage.tsx` (the `<Card>`, the section-list entry, transform/defaultValues). It's also read in `useImportFromJson.ts` to validate an imported `sector`.+- **Providers** — supabase `getList`/`getOne` route `companies -> companies_summary` (drop both); the contacts FTS list adds `company_name`. FakeRest has `processCompanyLogo` (favicon), `fetchAndUpdateCompanyData` (stamps `company_name` onto contacts, called from the contacts `beforeCreate`/`beforeUpdate`), `updateCompany` (maintains `nb_contacts`/`nb_deals` from the contacts/deals `afterCreate`/`afterDelete`), the whole `companies` callback block, the `companies` arm of the `sales` `beforeDelete` reassignment, and the `getActivityLog(dataProvider, companyId, salesId)` call (drop the `companyId` arg + the `companyId`/`company_id` filter plumbing in `providers/commons/activity.ts`). Delete `providers/commons/getCompanyAvatar.ts` + test.+- **FakeRest generators are deeply company-coupled** — `dataGenerator/companies.ts` deleted outright + dropped from `index.ts` (mind the order: sales → tags → [companies] → contacts → …) and `types.ts` (`Db.companies`). `contacts.ts` *picks a company* to derive `company_id`/`company_name`/`sales_id`/`first_seen` (+ a per-company `maxContacts` cap), and `deals.ts` *picks a company* then filters contacts by `company_id` for `contact_ids` — rewrite both to pick a random `db.sales` + `randomDate()` (and random contacts for deals). The `faker` `company` namespace import is unrelated — keep it.+- **JSON importer** treats `companies` as a top-level type (`importCompany`, `$.companies.*`, `CompanyImport`/`isCompany`, `mapSizeToCategory`, `companySectors` validation, stats/idsMaps keys) + the `company_id` mapping on imported contacts. Mirror in `ImportPage.tsx` + `import-sample.json`. CSV importer (`useContactImport.tsx`) has a `getCompanies` cache + a `company` column → `company_id`.+- **Mislabeled i18n:** `deals/OnlyMineInput.tsx` uses `resources.companies.filters.only_mine` ("Only companies I manage") even though it filters deals — re-point it to a deals key, don't delete the input.++## Backend+- Drop the `companies` table + `companies_id_seq` grant + RLS-enable line + its 4 policies + table grants. Drop `company_id` on **both** `contacts` and `deals` (FKs `contacts_company_id_fkey`/`deals_company_id_fkey` + indexes `contacts_company_id_idx`/`deals_company_id_idx`). Drop the `companies_summary` view (+ grant). Update `contacts_summary`: drop `co.company_id`, the `c.name as company_name` column, the `left join public.companies`, and narrow the `group by` to `co.id`.+- `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 a table to fetch `company_id`, so drop those now-unused joins) and delete the branch.+- Drop the company-only function `handle_company_saved` (favicon-from-website trigger) + its `company_saved` trigger + grant, and the `set_company_sales_id_trigger`. Drop the `company_id` line from `merge_contacts`. **Orphan subtlety:** `handle_company_saved` calls `get_domain_favicon`, but so does `get_avatar_for_email` (contact avatars) — so it is **not** orphaned; **keep** `get_domain_favicon` and the `favicons_excluded_domains` table.+- **Edge functions:** unlike `contacts` (delete the whole function), **keep** `postmark/` and surgically remove the company bits — it 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`. 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 postmark tests (`addNoteToContact.test.ts`, `extractMailContactData.test.ts`). **Flag 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`); `merge_contacts/index.ts` merges `company_id` in `mergeContactData`; `mcp/index.ts` + `mcp/validateSql.test.ts` mention `companies`/`companies_summary` in prompt examples/fixtures (swap for a surviving table). No `config.toml` block changes are needed (postmark + merge_contacts both survive).++## grep — benign matches to leave+- The `faker` `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`/`admin/list.tsx`, and email-domain fixtures like `@company.com`/`[email protected]` in test bodies.+- Dead i18n keys (`resources.companies.*`, `position_at_company`, `you_added_company`/`at_company`, `crm.settings.companies.*`) — flag, don't force (both catalogs or neither). `test-data/contacts.csv` keeps `company_id`/`company_name`/`company` columns — the importer ignores them, so leaving them is harmless; dropping means editing the header **and** all ~500 rows — flag it.diff --git a/.claude/skills/delete-initial-resource/contacts.md b/.claude/skills/delete-initial-resource/contacts.mdnew file mode 100644index 00000000..64de404b--- /dev/null+++ b/.claude/skills/delete-initial-resource/contacts.md@@ -0,0 +1,29 @@+# Deleting `contacts`++**The spine of the CRM and the widest deletion of the five.** Notes attach to `contacts | deals`, tasks belong only to contacts, `tags` is a field on `Contact`, companies aggregate `nb_contacts`, deals link `contact_ids`, and the activity-log + JSON-import + merge subsystems all revolve around it. Removing it orphans notes/tasks/tags. (Read [`core.md`](core.md) first.)++## Confirm cascade scope first+Ask the user how far to cascade — the answer changes the whole job:+- **contacts only** — leave notes/tasks/tags as compiling shells (narrowing the notes union to `"deals"` keeps notes valid as long as deals exists; tasks/tags become orphaned shells), or+- **also delete the now-orphaned subsystems**.+- And whether to touch the backend.++## Frontend specifics+- **Shared subsystems** — narrow the notes union to `"deals"` and the activity-log union to drop `"contact"`. Delete `ActivityLogContactCreated.tsx` + `ActivityLogContactNoteCreated.tsx` outright; drop `getNewContactsAndNotes` in `providers/commons/activity.ts`.+- **Typing landmine:** `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 }>()`.+- **Contact-only *mobile* note components** (dead once contacts is gone) — delete outright: `NoteCreateSheet.tsx`, `NoteEditSheet.tsx`, `NoteShowPage.tsx`, `NotesIteratorMobile.tsx`, `NoteInputsMobile.tsx` (+ their stories/tests). Drop the `NotesIteratorMobile` re-export from `notes/index.ts` and clean importers (`MobileNavigation.tsx`, the mobile `<Resource name="contacts">` note route in `CRM.tsx`).+- **Links to contacts:** `deals.contact_ids` (a selector in `DealInputs.tsx`, a per-deal `<ContactList/>` in `DealShow.tsx` + the standalone `deals/ContactList.tsx` to delete, the "create a contact first" gate in `DealEmpty.tsx`) and `tasks.contact_id` (the whole task contact-linking UI: `AddTask`, `Task`, `TaskCreateSheet`, `TaskEditSheet`, `TaskFormContent`'s `selectContact`, the `showContact`/`filterByContact` threading in `TasksIterator`/`TasksListFilter`/`TasksListByDueDate`). Decide per-link: orphaned shell (`contact_ids: Identifier[]`, default `[]`) vs drop.+- **Custom method:** `mergeContacts(sourceId, targetId)` in both providers (FakeRest → `providers/commons/mergeContacts.ts`, delete it; supabase → the `merge_contacts` edge function). Also `processContactAvatar`/`getContactAvatar` (delete `providers/commons/getContactAvatar.ts` + test), the `contacts`/`contact_notes` + `tasks` `nb_tasks` callbacks, and the supabase `contacts -> contacts_summary` routing + `contact_note -> contactNote` remap.+- **Wrapper components** outside the folder, delete outright: `dashboard/HotContacts.tsx` (contacts widget), `dashboard/DashboardStepper.tsx` (contact-onboarding wizard). `Dashboard.tsx`/`MobileDashboard.tsx` gate the whole render on contact/contactNote counts via the stepper — drop that gating. `LatestNotes.tsx` mixes contact_notes + a `<Contact>` renderer; `dashboard/TasksList.tsx` has an `<AddTask selectContact/>`.+- **JSON importer** is heavily contact-coupled (`importContact`/`importNote` for `contact_notes`, `contactGender`, stats/idsMaps); also `import-sample.json` (drop the contacts + notes sections). `ContactOption.tsx` is a shared option renderer — delete it.+- FakeRest generators: delete `contacts.ts`, `contactNotes.ts`, `finalize.ts` outright; clean `index.ts`/`types.ts`; `deals.ts` (contact_ids), `tasks.ts` (contact_id + nb_tasks), `companies.ts` (nb_contacts seed).+- Layout/login: `Header.tsx`, `MobileNavigation.tsx`, `SignupPage.tsx` (`redirectTo: "/contacts"`), `StoryWrapper.tsx` (`buildContact` + the contacts/contact_notes db keys).++## Backend+- Drop the `contacts` + `contact_notes` tables, the `tasks.contact_id` column (FK + index), the `contacts_summary` view, and the 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"` grants.+- **Orphaned helpers:** `get_avatar_for_email` (only called by `handle_contact_saved`) and `lowercase_email_jsonb` (only wired to the contact email trigger) — remove them + grants.+- `activity_log` view carries the contact pattern (a `contact` + `contact_note` column on every branch **and** two dedicated branches `contact.created`/`contactNote.created`) — same shape as deals.+- **Edge functions (deepest of the five):** delete the whole `merge_contacts/` function (+ its `[functions.merge_contacts]` block in `config.toml`) and the whole `postmark/` inbound-email function (+ its `[functions.postmark]` block) — 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/`: `contacts` (not tasks) drives `CRM_BASE_URL` — the `display_task_list` `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. Rewrite the `contacts`/`contacts_summary` mentions in the `get_schema`/`query`/`mutate` prompt examples and swap the table name in `mcp/validateSql.test.ts` fixtures for a surviving table.++## grep — benign matches to leave (intentional)+- `resources.companies.field_categories.contact` (a company "Company info" section label in `CompanyInputs.tsx`/`CompanyAside.tsx`, not the contacts resource), the `resource="contacts"` JSDoc examples in `misc/CreateSheet.tsx`/`EditSheet.tsx`, and the now-unused `resources.contacts.*` i18n keys (optional/large — flag, don't force). `supabase/migrations/` keeps historical references — never edit them.diff --git a/.claude/skills/delete-initial-resource/core.md b/.claude/skills/delete-initial-resource/core.mdnew file mode 100644index 00000000..f42df6da--- /dev/null+++ b/.claude/skills/delete-initial-resource/core.md@@ -0,0 +1,62 @@+# delete-initial-resource — common rules++Read this before touching any resource, then read the per-resource file(s) for what you're deleting.++## The script++`delete-initial-resource.ts` deletes each resource's own folder, then prints the **merged, de-duplicated list of dependent files** (files inside a just-deleted folder are dropped automatically — e.g. `companies/CompanyShow.tsx` won't be listed if you also deleted `companies`). It does **not** edit those files — that's your job. Each entry in the script's `dependentFiles` map has a `//` comment telling you *what* to remove from that path; read it alongside the printed list.++Run from the project root (Node 18 can't run TS directly, so `tsx` is required; `npx -y` fetches it):++```bash+npx -y tsx .claude/skills/delete-initial-resource/delete-initial-resource.ts <resource> [<resource> ...]+```++It validates every name (exits on an unknown one or a missing folder), deletes `src/components/atomic-crm/<resource>/` for each, and prints the dependent files plus shared files like `root/CRM.tsx`.++## Shapes a resource takes++A resource is rarely just a folder. Look for each of these — the later ones are invisible to a `\b<resource>\b` grep:++- **Standalone usage** — imports, JSX, routes, menu/nav entries, dashboard widgets, the `<Resource name="...">` entry + imports in `root/CRM.tsx`. Some wrapper components *outside* the folder exist only to render the resource — delete them outright, then clean their importers.+- **Field/column on another record** — fans out much wider than a folder: the type in `types.ts`, the merge logic (`providers/commons/mergeContacts.ts`), CSV/JSON import, i18n, 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). For a *link* column, decide per-link: keep it as an orphaned shell (typed, defaulted) or drop it — remove the UI either way.+- **Aggregated `nb_<resource>` columns** (from the `_summary` views) land on a record type and are read across shows/lists/filters/generators. **Invisible to `\b<resource>\b` grep** (the `_` is a word char) — grep `nb_<resource>` separately. Same for the denormalized `company_name`.+- **Shared subsystems** — notes (over `reference: "contacts" | "deals"`) and the activity log (over a `"company" | "contact" | "deal" | "all"` context union) are parameterised by a union, not keyed to a folder. Narrow the union, delete the per-type render components (`ActivityLog*Created.tsx`) and dead branches, and prune the `providers/commons/activity.ts` fetcher + the `consts.ts`/`types.ts` members. Surviving `=== "<other>"` checks stay valid (tsc won't flag them) — only the deleted member's branches go.+- **Config props** (e.g. `taskTypes`, `dealStages`, `companySectors`) live in `root/defaultConfiguration.ts`, `ConfigurationContext.tsx`, `CRM.tsx` (default + jsdoc + store seed), `App.tsx`, and `SettingsPage.tsx` (the `<Card>` **and** the section-list entry + transform/defaultValues). **A config prop isn't always named after the resource** — grep the resource's settings `<Card>` for other keys (Deals also owned `currency`) and trace each one's consumers; flag borderline-general props rather than dropping them silently.+- **Custom dataProvider methods** live in **both** providers; `CrmDataProvider` is `ReturnType<typeof getDataProviderWithCustomMethods>` (the supabase provider), so removing them there drops them from the type. Also clean each resource's lifecycle-callback blocks in both providers, the `sales` `beforeDelete` reassignment, the supabase `getList` `<resource> -> <resource>_summary` routing, and the FakeRest generators — which *drive* record creation, not just reference the field.+- **The JSON importer** (`misc/useImportFromJson.ts`) treats `contacts`/`companies`/`notes`/`tasks` as top-level importable types (an `import<X>` fn, a `$.<x>.*` path, a `TYPES` arm + switch case, type guards, `stats`/`failedImports`/`idsMaps` keys). Mirror the trims in `ImportPage.tsx` (stats row + help text) and the `import-sample.json` fixture. The CSV importer (`useContactImport.tsx`) has parallel cache + column mappings.+- Don't forget `useCallback`/`useMemo` dependency arrays — a stale `getTags`/`getCompanies` reference there is invisible until `tsc` runs.++## Deleting several at once++- **Order cleanup from the most-coupled resource outward** and read all the relevant per-resource files before editing — the cascade interactions compound.+- Clean a file shared by two deleted resources **once**, for both — don't make two passes that fight each other.+- Reconcile interacting union guidance: deleting both `contacts` and `deals` removes the notes/activity-log subsystem reference *entirely* rather than each narrowing it the other's way — don't half-apply each file's "narrow the union" note.++## Backend (the script only touches frontend)++See the `backend-dev` skill for the migration workflow. In `supabase/schemas/`:++- Drop/adjust the table + view, generate a migration (`npx supabase db diff --local -f remove_<resource>`). Update `contacts_summary`/`companies_summary` if they aggregated the removed data.+- The **`activity_log` view** is a `UNION ALL` where **every branch declares the same column set** — remove the resource's columns from **every** branch (keep the lists aligned), delete its dedicated branch(es), and drop the matching snake→camel rename in the supabase provider's `getList("activity_log")`.+- `06_grants.sql` grants **both** the table and its `<resource>_id_seq` (drop both, or `db diff` fails with `relation "public.<resource>_id_seq" does not exist`). `05_policies.sql` has an `enable row level security` line **and** `create policy` statements (remove both).+- For a resource referenced inside a SQL **function** (`merge_contacts`), drop those lines + the now-unused local var. Editing `02_functions.sql` regenerates the whole function (expected) — renumber leftover step comments so they stay sequential.+- **Orphan subtlety:** deleting triggers can orphan helper functions — but check for shared callers first (`get_domain_favicon` is called by *both* `handle_company_saved` and contact avatars, so it survives a `companies` delete).+- **Edge functions** are separate from the schema and easy to miss: `merge_contacts/`, `_shared/db.ts` (Kysely table types), `postmark/` (inbound email → contact notes), and especially `mcp/` — a whole AI subsystem whose depth varies per resource. When a function loses a capability but survives, **flag the behavior change to the user**.++## Verify++```bash+make typecheck && make lint+```++The dependent-file list is a guide, not a guarantee — resolve whatever `tsc` surfaces. A final `grep -rniE "\b<resource>\b"` over `src/` and `supabase/` is worth it, plus **separate** greps for `nb_<resource>`, `company_name`, and config-prop names (`<resource>Types`, `companySectors`, `currency`). Watch for **benign/substring false positives** and don't blind-delete (each resource file lists its own). Never edit historical files under `supabase/migrations/`.++**i18n is all-or-nothing across both catalogs:** `frenchCrmMessages.ts` is type-checked against the `CrmMessages` type derived from `englishCrmMessages.ts`, so a key must be removed from **both** or **neither** — a one-sided removal is a `tsc` error. Dead `resources.<x>.*` keys are harmless; because cleanup is large and all-or-nothing, **flag them to the user rather than forcing it**. Note: `frenchCrmMessages.ts` uses literal `…` escapes — if an exact-string `Edit` fails on a block spanning one, fall back to `sed -i '<from>,<to>d'` after confirming line numbers with a fresh read.++If local Supabase is running, `npx supabase db reset --local` replays the whole chain + `seed.sql` and catches a broken view/function/grant that `db diff` alone won't (benign `index "…_pkey" does not exist, skipping` NOTICEs are expected). `make test` (vitest) needs Node ≥ 20.12 — under Node 18 it aborts at startup with `crypto.hash is not a function`, so typecheck + lint are the reliable gates.++## Notes++- The deletion is irreversible — rely on git to recover if needed. Confirm the resource(s) with the user before running.+- Per-file guidance lives in the script's `dependentFiles` map comments; if the codebase grows new references, update that map so future runs stay accurate.diff --git a/.claude/skills/delete-initial-resource/deals.md b/.claude/skills/delete-initial-resource/deals.mdnew file mode 100644index 00000000..bac88103--- /dev/null+++ b/.claude/skills/delete-initial-resource/deals.md@@ -0,0 +1,19 @@+# Deleting `deals`++`deals` owns the `deals` + `deal_notes` tables but is woven into **two shared subsystems** (notes, activity log), adds an aggregated `nb_deals` to `companies_summary`, ships **three** config props plus a non-eponymous one, and has a custom dataProvider method — so it fans out almost as wide as a column removal. (Read [`core.md`](core.md) first.)++## Frontend specifics+- **Shared subsystems** — narrow the notes union to `"contacts"` and the activity-log union to drop `"deal"`; prune the `=== "deals"`/`deal_id`/`DealNote` branches (the `=== "contacts"` checks stay valid). Delete `ActivityLogDealCreated.tsx` + `ActivityLogDealNoteCreated.tsx` outright; drop `getNewDealsAndNotes` in `providers/commons/activity.ts` and `DEAL_CREATED`/`DEAL_NOTE_CREATED` + `ActivityDeal*` in `consts.ts`/`types.ts`. Drop the `"deals"` reference test in `NoteInputs.test.tsx`.+- **Config props** — `dealStages`/`dealCategories`/`dealPipelineStatuses` **plus `currency`**, which is deal-scoped but NOT named after the resource (it lived in the Deals `<Card>`; readers are `DealsChart`/`DealsPipeline`/`CompanyShow`'s deal iterator). Removing `currency` is a judgement call — flag it. The Deals `<Card>` also carries a `validateItemsInUse` helper — exported, unit-tested in `SettingsPage.test.ts` (delete that test file outright), backed by a `crm.settings.validation` i18n block; delete all three.+- **Custom method** — `unarchiveDeal(deal)` in **both** providers (drops from `CrmDataProvider` automatically via the supabase provider's return type).+- **Wrapper components** outside the folder, delete outright: `dashboard/DealsChart.tsx`, `dashboard/DealsPipeline.tsx`. `Dashboard.tsx` keeps both an import **and** a `{totalDeal ? <DealsChart/> : null}` JSX site — remove both. `LatestNotes.tsx` fetches `deal_notes` + renders `<Deal/>`.+- **`nb_deals` readers** (invisible to `\bdeals?\b` grep): `CompanyShow.tsx` (deals tab), `CompanyCard.tsx` (badge). `ContactMergeButton.tsx` shows a `dealsCount` preview.+- i18n: `resources.deals`, `nb_deals`, activity/dashboard/`settings.deals`/`settings.validation` keys; `i18nProvider.test.ts` asserts a `resources.deals.*` key.++## Backend+- Drop the `deals` + `deal_notes` tables, grants, policies, sequences. Update `companies_summary` (drop `count(distinct d.id) as nb_deals` + the `left join public.deals`).+- `activity_log` view: `deals` contributed a `deal` + `deal_note` column to **every** branch **and** two dedicated branches (`deal.created`, `dealNote.created`) — remove both, keep column lists aligned, and drop the `deal_note → dealNote` rename in the supabase provider's `getList("activity_log")`.+- **MCP:** **no** dedicated MCP App — only the `DealsTable` Kysely interface in `_shared/db.ts`, the deal-reassignment step in `merge_contacts/index.ts` (its removal leaves the `sql` import unused — drop it), and deal mentions in the `query`/`mutate` **prompt-text examples** in `mcp/index.ts` (rewrite the examples, don't just delete lines).++## grep — benign matches to leave+- `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 and don't blind-delete French lines.diff --git a/.claude/skills/delete-initial-resource/tags.md b/.claude/skills/delete-initial-resource/tags.mdnew file mode 100644index 00000000..0a73be51--- /dev/null+++ b/.claude/skills/delete-initial-resource/tags.md@@ -0,0 +1,14 @@+# Deleting `tags`++The simplest of the five: `tags` is a **field** (`number[]`) on `Contact` plus a small standalone `tags` folder. No shared subsystem, no config prop, no aggregated column. (Read [`core.md`](core.md) first.)++## Frontend specifics+- Tag-only components under `contacts/` — delete outright: `TagsList.tsx`, `TagsListEdit.tsx`, `BulkTagButton.tsx`. Clean their consumers (`ContactShow`, `ContactAside`, `ContactListContent`, `ContactList`, `ContactListFilter`).+- The `contacts.tags` field lives in `contactModel.ts`, `useContactImport.tsx`, `providers/commons/mergeContacts.ts`, the FakeRest generators (`dataGenerator/contacts.ts` + `index.ts` + `types.ts`), the stories/tests (`ContactList.stories.tsx`, `ContactList.test.tsx`, `StoryWrapper.tsx`), and the sample CSVs (`contacts_export.csv`, `test-data/contacts.csv`).+- i18n: drop the `bulk_tag` block, `filters.tags`, and the `tags` resource block (both catalogs — see core.md).++## Backend+- Drop the `tags` table + its grants/policies/sequence. `merge_contacts` in `02_functions.sql` merges `tags` — drop those lines + the now-unused local var, and renumber step comments.++## grep — benign matches to leave+- `tags` matches `stage` — filter it out (`grep -viE "stage"`).diff --git a/.claude/skills/delete-initial-resource/tasks.md b/.claude/skills/delete-initial-resource/tasks.mdnew file mode 100644index 00000000..b08f7d4b--- /dev/null+++ b/.claude/skills/delete-initial-resource/tasks.md@@ -0,0 +1,13 @@+# Deleting `tasks`++`tasks` looks standalone (it owns the `tasks` folder + table) but it **adds an aggregated `nb_tasks` column to `contacts_summary`** (which lands on the `Contact` type) and ships a **`taskTypes` config prop** — so it fans out almost like a column removal. (Read [`core.md`](core.md) first.)++## Frontend specifics+- **`nb_tasks` readers:** `CompanyShow.tsx`, `ContactListContent.tsx`, `ContactShow.tsx` (+ test), `ContactListFilter.tsx` (a `nb_tasks@gt` filter), `ContactMergeButton.tsx`, and the FakeRest provider/generators (which increment/decrement it). **Invisible to `\btasks?\b` grep** — grep `nb_tasks` separately.+- **`taskTypes` config prop** — see core.md "Config props". The Tasks `<Card>` has no `validateItemsInUse`.+- **Wrapper components** outside the folder, delete outright: `dashboard/TasksList.tsx`, `contacts/ContactTasksList.tsx`.+- i18n: drop the `tasks` resource block, `task_count`, `upcoming_tasks`, `filters.tasks`, `settings.tasks`, and the import description (both catalogs — see core.md).++## Backend+- Drop the `tasks` table + grants/policies/sequence.+- **MCP edge function:** `mcp/taskListUi.ts` is a ~13 KB guest-HTML "MCP App" — delete outright. Remove the `display_task_list` + `complete_task` tools and their prompt examples in `mcp/index.ts`, and the `tasks` example in `mcp/validateSql.test.ts`. (Note: the `CRM_BASE_URL` env var is driven by the task→contact deep-link, which is really a `contacts` concern — see [`contacts.md`](contacts.md); it only goes dead if contacts is deleted too.)