कार्यान्वयन योजना
मूल डाउनलोड करें ↓CRM-142 संपर्क आयात कार्यान्वयन योजना
एजेंटिक workers के लिए: इस रन में केवल योजना। बाद का निष्पादन native और single-agent रहे; अतिरिक्त skills, commits, worktrees या delegation नहीं। उपयोगकर्ता/प्रोजेक्ट निर्देश upstream execution-subskill template पर प्राथमिकता रखते हैं।
लक्ष्य: पूर्वावलोकन के दौरान सहेजे या संपर्क खोए बिना, समीक्षा किए CSV संपर्कों को मौजूदा स्थानीय सूची में आयात करें।
आर्किटेक्चर: नए import module में शुद्ध parsing/classification/merge; मौजूदा ऐप में inline panel और क्रमबद्ध writes। मौजूदा contacts/storage adapters अपरिवर्तित रहें।
तकनीकी स्टैक: साधारण HTML/CSS/browser ES modules, localStorage; Node >=24 का built-in test runner, निर्भरताएँ नहीं।
विनिर्देश: docs/brainstorming.md, docs/screen-design.md, docs/architecture.md; निश्चित आवश्यकताएँ यहाँ हैं: tickets/CRM-142.md और docs/import-contract.md.
समग्र सीमाएँ
केवल ऐप में बदलाव: index.html, style.css, src/app.js, नया src/import.js। Tests, samples, ticket, server, package, AGENTS.md और दोनों मौजूदा helper modules अपरिवर्तनीय हैं। बाहरी सेवा, निर्भरता बदलाव, companion execution, global installation, commits, deployment या publishing नहीं। लॉगिन, server database, field-mapping wizard, remote uploads, live CRM account या background jobs नहीं। सीमा 100,000 UTF-8 बाइट और 500 गैर-खाली डेटा रिकॉर्ड है; अपलोड से पहले दिखाएँ। पूर्वावलोकन कभी persist न करे। मौजूदा search/Add काम करते रहें। इस चरण में कार्यान्वयन की अनुमति नहीं है।
समीक्षा का केंद्र
अपरिवर्तनीय module tests कई parsing मामले जाँचते हैं, पर UI/storage व्यवहार साबित नहीं करते। संबंधित कार्यों में ये विशिष्ट manual checks शामिल करें:
- कार्य 3: तेज़ Add/Import और दोहरी पुष्टि save को race न करें या संपर्क न खोएँ।
- कार्य 3: save विफल होने पर preview और पुराना persisted data रहे; retry हर संपर्क एक बार जोड़े।
- कार्य 2: चयन/रद्द के बाद देर से आने वाली file reads पुराने preview वापस न लाएँ।
- कार्य 4: HTML जैसे सेल preview और list, दोनों में literal text रहें; injected element न बने।
- कार्य 4: keyboard focus/status और लंबे मान 320px पर उपयोगी रहें।
कार्य 1: शुद्ध CSV preview और merge
फ़ाइलें: बनाएँ src/import.js; अपरिवर्तित यह इस्तेमाल करें: src/contacts.js; अपरिवर्तित यह जाँचें: tests/import.test.js और tests/contacts.test.js. इंटरफ़ेस: बनाएँ previewCSV(text: string, existing: Contact[]): Preview और mergeReady(preview: Preview, existing: Contact[]): {contacts: Contact[], added: number, skipped: number}। Contact का मौजूदा स्वरूप यह है: {id,name,email,company} ; Preview यह है: {rows: {record:number,name:string,email:string,company:string,status:'ready'|'invalid'|'duplicate',reason:string}[], counts:{ready:number,invalid:number,duplicate:number}}। normalEmail, validContact और addContact यहाँ से इस्तेमाल करें: src/contacts.js.
- [ ] यह चलाएँ:
node --test tests/import.test.jsकार्यान्वयन से पहले; वर्तमान tree में इसके अनुपस्थित होने की अपेक्षा है:src/import.js, यह प्रोडक्ट व्यवहार की विफलता नहीं। टेस्ट न बदलें। - [ ] scanner/limits/header के निर्णयों के साथ previewCSV यहाँ लागू करें:
docs/architecture.md; किसी preview को लौटाने से पहले संरचनात्मक सत्यापन पूरा हो। duplicate tracking से पहले फ़ील्ड वर्गीकृत करें और हर गैर-खाली रिकॉर्ड तथा सही गिनती रखें। - [ ] mergeReady लागू करें, दिए गए current contacts से Ready रिकॉर्ड फिर जाँचें। Inputs और पुराने contacts सुरक्षित रखें, addContact से ID जोड़ें और फ़ाइल के हर न जुड़े रिकॉर्ड को skipped गिनें।
- [ ] यह चलाएँ:
node --test tests/import.test.js tests/contacts.test.js; सभी 17 मौजूदा टेस्ट सफल होने चाहिए (12 import, 5 contacts)। ये quoting, BOM/CRLF, वैकल्पिक company, खाली रिकॉर्ड, खराब संरचना, invalid-first duplicates, merge पर फिर सत्यापन, immutability और सीमाएँ साबित करते हैं। - [ ] inline Node module assertion probe चलाएँ, सहेजे गए टेस्ट न बदलें: ठीक 100,000-बाइट ASCII input स्वीकार हो और 100,001 अस्वीकार; trim किए mixed-case headers स्वीकार हों; duplicate normalized headers अस्वीकार; whitespace-only records अनदेखे; छोटी rows pad हों; unknown header values अनदेखे; closing quote के बाद characters अस्वीकार हों। दस्तावेज़ के निर्णयों से मेल रखें। इसे parse करें:
samples/customer-contacts.csvinitialContacts के साथ और गिनती यह जाँचें:{ready:3,invalid:1,duplicate:2}, rows length 6, merged added 3/skipped 3/contacts length 5।
कार्य 2: इनलाइन अपलोड और पूरी समीक्षा
फ़ाइलें: बदलें index.html, src/app.js, style.css केवल; कार्य 1 पर निर्भर है। इंटरफ़ेस: कार्य 1 के previewCSV और Preview इस्तेमाल करें। ऐप के भीतर यह बनाएँ: renderImport() और यहाँ बताई स्थिति: docs/architecture.md; मौजूदा ये बनाए रखें: #search, #contacts, #status, #add और उनका व्यवहार। लेबल वाला inline section और file input जोड़ें; नियंत्रणों के accessible names ये हैं: Import contacts, CSV file, Review CSV, Import ready contacts, Cancel import, Back to contacts, Fail next save.
- [ ] इनके अनुसार नियंत्रण, सीमा/मदद का टेक्स्ट और समीक्षा container जोड़ें:
docs/screen-design.md; कार्य 3 का save path जुड़ने तक confirmation बंद रखें। - [ ] खोलना, file selection, स्पष्ट Review CSV, cancellation और Back जोड़ें; generation token से asynchronous reads सुरक्षित करें और नए input पर पुरानी errors/preview हटाएँ। textContent से हर record के fields/status/reason और counts दिखाएँ।
- [ ] मौजूदा contact styling और स्पष्ट focus रखते हुए लेबल वाले record cards, लपेटे buttons और लंबे text के लिए सीमित responsive styles जोड़ें।
- [ ] इसके साथ
npm startऔरhttp://127.0.0.1:8830, नमूना चुनें: छह कार्ड और 3/1/2 गिनती की अपेक्षा है। Cancel/Back सूची, खोज और stored value सुरक्षित रखें। खराब फ़ाइल चुनें: त्रुटि और बंद confirmation हों; फिर वैध फ़ाइल चुनें: पुरानी त्रुटि हटे। पढ़ते समय तेज़ी से select/cancel करें: पुराना preview वापस न आए। ये बाद के निष्पादन के browser checks हैं, वर्तमान नतीजों के दावे नहीं।
कार्य 3: क्रमबद्ध पुष्टि, विफलता और retry
फ़ाइलें: बदलें src/app.js केवल (नियंत्रण कार्य 2 में पहले से परिभाषित हैं)। कार्य 1–2 पर निर्भर है। इंटरफ़ेस: mergeReady और मौजूदा addContact/readContacts/saveContacts इस्तेमाल करें। ऐप में यह बनाएँ: persistContacts(makeNext) coordinator, जहाँ makeNext वर्तमान committed Contact[] लेकर यह लौटाता है: {contacts:Contact[], added:number, skipped:number} (Add अपनी एक नई row को इस स्वरूप में ढालता है)। Promise storage के बाद परिणाम resolve करे; busy/failure पर reject। नया exported API या storage adapter बदलाव नहीं।
- [ ] मौजूदा Add और Import save को synchronous busy guard और coordinator से यहाँ चलाएँ:
docs/architecture.md। Import confirmation पर फिर merge करे; upload के दौरान next contacts पहले न निकालें। Save में mutation controls बंद हों। Storage सफल होने पर ही rows प्रकाशित हों; catch/finally में success message न दें। - [ ] Fail next save को लेबल वाले checkbox के रूप में जोड़ें, जिसका इस्तेमाल अगला वास्तविक adapter save करे। विफलता preview और committed list रखे, busy छोड़े और retry लौटाए; cancellation कुछ न लिखे। फिर सत्यापन पर additions शून्य हों तो storage छोड़कर सही counts बताएँ।
- [ ] आयात सफल हो तो preview और search हटाएँ, वही list दिखाएँ, असली added/skipped counts बताएँ और focus लौटाएँ। Zero-Ready confirmation बंद रखना और synchronous guard दोहराए submissions रोकें।
- [ ] नए ब्राउज़र में नमूना import करें: added 3/skipped 3, total 5, हो, search में Jordan मिले, Add नया अलग contact अब भी जोड़े और reload पर सभी saved contacts रहें।
- [ ] नया context: नमूना preview करें, Jordan हाथ से जोड़ें, फिर confirm; added 2/skipped 4 हो और हाथ से जोड़ा संपर्क बचे। 180ms save के दौरान confirm पर double-click और Add आज़माएँ: duplicate import, overlapping save या lost contact न हो।
- [ ] नया context: नमूना preview करें, Fail next save चालू करके confirm करें; list/storage अपरिवर्तित और failure status के साथ छह रिकॉर्ड का preview रहे। Retry: added 3/skipped 3 एक बार हो, फिर reload करके पाँच contacts जाँचें। Failed Add भी जाँचें ताकि regression न हो। Zero-Ready preview confirmation की अनुमति न दे।
कार्य 4: स्वीकृति सत्यापन और दायरे की समीक्षा
फ़ाइलें: केवल अनुमत application files की समीक्षा करें; tests अपरिवर्तित रहें। कार्य 1–3 पर निर्भर है। इंटरफ़ेस: मौजूदा पूरी Contacts UI और कार्य 2 के नियंत्रण; नया API नहीं।
- [ ] यह चलाएँ:
npm test; सभी 17 अपरिवर्तनीय टेस्ट सफल होने चाहिए। इसे browser storage/accessibility coverage के बराबर न मानें। - [ ] नमूने के record 6 को preview और imported list में browser से जाँचें: literal
<img src=x onerror=alert(1)>, img element या execution नहीं। Quoted multiline company और लंबे email/company के पढ़ने योग्य wrapping जाँचें। - [ ] 320px और desktop पर upload/review/cancel/confirm और Add केवल keyboard से चलाएँ। Labels, तार्किक Tab क्रम, स्पष्ट focus, review-heading focus, live counts/errors/success, cancel पर focus वापसी और बिना horizontal page scroll जाँचें। Focus trap नहीं; सभी छह नमूना रिकॉर्ड पहुँच में हों।
- [ ] खराब headers/quotes/extra fields और बड़े input से stored contacts न बदलें; 501 records अस्वीकार और 500 स्वीकार हों। बिना Ready rows वाला preview भी जाँचें।
- [ ] diff देखें: कार्यान्वयन में केवल चार अनुमत application paths बदलें; immutable files और selection artifacts अपरिवर्तित हों। असली test/browser outcomes और सीमाएँ बताएँ। ऑपरेटर समीक्षा के लिए रुकें; commit या deploy न करें।
मूल फ़ाइल और स्रोत का विवरण
output/docs/implementation-plan.md.txt · SHA-256 f20d8893150a7b9a6b0a44bfdc711d92b535cf9f8fcb7de224c4892b75c5cbf1
# CRM-142 Import Contacts Implementation Plan
> For agentic workers: planning only in this run. Later execution stays native and single-agent; no additional skills, commits, worktrees or delegation. User/project instructions override the upstream execution-subskill template.
**Goal:** Import reviewed CSV contacts into the existing local list without losing contacts or saving during preview.
**Architecture:** Pure parsing/classification/merge in a new import module; inline panel and serialized writes in the existing app. Existing contacts/storage adapters remain unchanged.
**Tech Stack:** Plain HTML/CSS/browser ES modules, localStorage; Node >=24 built-in test runner, no dependencies.
**Spec:** `docs/brainstorming.md`, `docs/screen-design.md`, `docs/architecture.md`; fixed requirements in `tickets/CRM-142.md` and `docs/import-contract.md`.
## Global constraints
Application changes only: `index.html`, `style.css`, `src/app.js`, new `src/import.js`. Tests, samples, ticket, server, package, AGENTS.md and both existing helper modules are immutable. No external services, dependency changes, companion execution, global installation, commits, deployment or publishing. No login, server database, field-mapping wizard, remote uploads, live CRM account or background jobs. Limit 100,000 UTF-8 bytes and 500 nonblank data records; display limits before upload. Preview never persists. Existing search/Add remain working. No implementation is authorized in this phase.
## Review focus
The immutable module tests cover many parsing cases but do not prove UI/storage behavior. Include these targeted manual checks in the owning tasks:
1. Task 3: rapid Add/Import and double confirmation cannot race a save or lose contacts.
2. Task 3: failed save retains preview and old persisted data; retry adds each contact once.
3. Task 2: late file reads after selection/cancel cannot restore stale previews.
4. Task 4: HTML-looking cells remain literal text in both preview and list; no injected element.
5. Task 4: keyboard focus/status and long values remain usable at 320px.
## Task 1: Pure CSV preview and merge
**Files:** Create `src/import.js`; consume unchanged `src/contacts.js`; verify unchanged `tests/import.test.js` and `tests/contacts.test.js`.
**Interfaces:** Produce `previewCSV(text: string, existing: Contact[]): Preview` and `mergeReady(preview: Preview, existing: Contact[]): {contacts: Contact[], added: number, skipped: number}`. Contact is the existing `{id,name,email,company}` shape; Preview is `{rows: {record:number,name:string,email:string,company:string,status:'ready'|'invalid'|'duplicate',reason:string}[], counts:{ready:number,invalid:number,duplicate:number}}`. Consume normalEmail, validContact and addContact from `src/contacts.js`.
- [ ] Run `node --test tests/import.test.js` before implementation; with the current tree expect missing `src/import.js`, not a product behavior failure. Do not edit tests.
- [ ] Implement previewCSV with scanner/limits/header decisions in `docs/architecture.md`; ensure structural validation completes before returning any preview. Classify fields before duplicate tracking, keeping every nonblank record and exact counts.
- [ ] Implement mergeReady, rechecking Ready records against its supplied current contacts. Preserve inputs and old contacts, add IDs through addContact, count every non-added file record as skipped.
- [ ] Run `node --test tests/import.test.js tests/contacts.test.js`; expect all 17 existing tests to pass (12 import, 5 contacts). These prove quoting, BOM/CRLF, optional company, blank records, malformed structures, invalid-first duplicates, merge revalidation, immutability and limits.
- [ ] Run an inline Node module assertion probe (no saved test edits): exact 100,000-byte ASCII input accepted and 100,001 rejected; trimmed mixed-case headers accepted; duplicate normalized headers rejected; whitespace-only records ignored; short records padded; unknown header values ignored; characters after closing quote rejected. Match the documented choices. Parse `samples/customer-contacts.csv` with initialContacts and assert counts `{ready:3,invalid:1,duplicate:2}`, rows length 6, merged added 3/skipped 3/contacts length 5.
## Task 2: Inline upload and complete review
**Files:** Modify `index.html`, `src/app.js`, `style.css` only; depends on Task 1.
**Interfaces:** Consume previewCSV and Preview from Task 1. Produce app-local `renderImport()` and state described in `docs/architecture.md`; keep existing `#search`, `#contacts`, `#status`, `#add` and their behavior. Add a labelled inline section and file input; control accessible names are `Import contacts`, `CSV file`, `Review CSV`, `Import ready contacts`, `Cancel import`, `Back to contacts`, `Fail next save`.
- [ ] Add controls, limit/help text and review container according to `docs/screen-design.md`; keep confirmation disabled until the save path in Task 3 is connected.
- [ ] Connect opening, file selection, explicit Review CSV, cancellation and Back; guard asynchronous reads with a generation token and clear prior errors/preview on new input. Show every record with fields/status/reason and counts using textContent.
- [ ] Add narrow responsive styles for labelled record cards, wrapped buttons and long text, retaining existing contact styling and visible focus.
- [ ] With `npm start` and `http://127.0.0.1:8830`, select the sample: expect six cards and 3/1/2 counts. Cancel/Back must preserve list, search and stored value. Select a malformed file: expect error and disabled confirmation; select a valid file afterward: old error disappears. Select/cancel rapidly while reading: no stale preview returns. These are browser checks for later execution, not claims of current results.
## Task 3: Serialized confirmation, failure and retry
**Files:** Modify `src/app.js` only (controls already defined in Task 2). Depends on Tasks 1–2.
**Interfaces:** Consume mergeReady and existing addContact/readContacts/saveContacts. Produce app-local `persistContacts(makeNext)` coordinator, where makeNext receives current committed Contact[] and returns `{contacts:Contact[], added:number, skipped:number}` (Add adapts its one new row to this shape). Promise resolves that result after storage; rejects on busy/failure. No new exported API or storage adapter changes.
- [ ] Route existing Add and Import saves through the synchronous busy guard and coordinator in `docs/architecture.md`. Import remerges at confirmation; do not precompute next contacts during upload. Disable mutation controls while saving. Publish rows only after successful storage; no success message in catch/finally.
- [ ] Wire Fail next save as a labelled checkbox consumed by the next actual adapter save. Failure retains preview and committed list, releases busy and restores retry; cancellation never writes. For zero additions after revalidation skip storage and report actual counts.
- [ ] On successful import clear preview and search, render the same list, announce actual added/skipped counts and restore focus. Ensure disabled zero-Ready confirmation and synchronous guarding prevent repeat submissions.
- [ ] In a fresh browser import the sample: expect added 3/skipped 3, total 5, search finds Jordan, Add still adds a unique contact, and reload retains all saved contacts.
- [ ] Fresh context: preview sample, Add Jordan manually, then confirm; expect added 2/skipped 4 and preservation of the manual contact. Double-click confirm and attempt Add during the 180ms save: no duplicate import, overlapping save or lost contact.
- [ ] Fresh context: preview sample, arm Fail next save and confirm; expect unchanged list/storage and retained six-record preview with failure status. Retry: expect added 3/skipped 3 once, then reload and verify five contacts. Also exercise failed Add to ensure no regression. Zero-Ready preview must not allow confirmation.
## Task 4: Acceptance verification and scope review
**Files:** Review only allowed application files; tests remain unchanged. Depends on Tasks 1–3.
**Interfaces:** Full existing Contacts UI plus the Task 2 controls; no new API.
- [ ] Run `npm test`; expect all 17 immutable tests to pass. Do not equate this with browser storage/accessibility coverage.
- [ ] Browser check sample record 6 in preview and imported list: literal `<img src=x onerror=alert(1)>`, no img element or execution. Check a quoted multiline company and a long email/company for readable wrapping.
- [ ] At 320px and desktop, operate upload/review/cancel/confirm and Add using keyboard only. Verify labels, logical tab order, visible focus, review-heading focus, live counts/errors/success, cancellation focus restoration and no horizontal page scroll. No focus trap; all six sample records reachable.
- [ ] Check malformed headers/quotes/extra fields and oversized input leave stored contacts unchanged; confirm 501 records rejected and 500 accepted. Include a preview with no Ready rows.
- [ ] Inspect diff: only the four allowed application paths changed during implementation; immutable files and selection artifacts unchanged. Report actual test/browser outcomes and any limitation. Stop for operator review; do not commit or deploy.