- Use Node.js 22 (the CI version) and npm; install from the lockfile with
npm ci. - Always run
npm run lintandnpm run format:check. For code changes, also runnpm testandnpm run build; the build performstsc -bbefore Vite. - Run one test file with
npm test -- src/path/to/file.test.ts; add-t "test name"to select one case. Vitest uses its default Node environment, so mockchrome,window, anddocumentwithvi.stubGlobalas the existing tests do. - CI currently runs only lint and formatting. A green CI job does not verify tests, type-checking, or the extension build.
- Prettier is authoritative: double quotes, semicolons, 4-space indentation, trailing commas, and 100-column lines.
- TypeScript enables
erasableSyntaxOnlyandverbatimModuleSyntax; use type-only imports where required and avoid enums, parameter properties, and other non-erasable TypeScript syntax.
src/manifest.tsis the development manifest and wiresindex.html(popup),options.html,src/background/service-worker.ts, andsrc/content/index.ts. Keep manifest changes mirrored insrc/manifest.prod.tswhen they apply to releases.src/content/index.tsis a side-effect entrypoint: its imports register page listeners, analysis, the long-livedevent-streamport, and the pet overlay. It runs with DOM access in Chrome's isolated content-script world.src/background/service-worker.tsowns browser listeners, engine orchestration, persistence, AI calls, and runtime-message handlers. It is an MV3 service worker and must not use DOM APIs.- Popup and Options are independent React roots. Put shared UI/runtime wrappers in
src/ui/; keep cross-context request/response types, unions, and type guards together insrc/messages.ts.
- Tracked events are interfaces under
src/models/events/; extendEventorUiEventand create instances withcreateEvent, which suppliestimestampandprocessed. - Options are one persisted
chrome.storage.localrecord. Adding a field requires updatingsrc/models/Option.ts, defaults and legacy normalization insrc/services/OptionStore.ts, and its tests. - IndexedDB stores have independent
DB_VERSIONvalues insrc/services/. Schema changes need a version bump and upgrade path for installed users; new persisted stores must also be cleared by the Settings page'sclearAllDataflow. clearAllDatacurrently removes the Option record and five IndexedDB stores, not auxiliarychrome.storage.localkeys. Do not describe it as a complete reset unless that flow is expanded.- Use
createLoggerfromsrc/utils/logger.ts; do not callconsole.*directly or log raw API keys, page HTML/Markdown, prompts, keystrokes, coordinates, DOM identifiers, or private URLs. - AI classification sends the full URL and page HTML-derived Markdown; AI daily reports send a structured activity/load summary. Both calls belong in the service worker. Keep the API key in extension storage/background code, never in the content script.
README.mdis the single public product, privacy, permission, setup, and release document. Update it when collected or persisted fields, AI payloads, content-script matches, host permissions, retention/clear behavior, developer commands, or release behavior changes.
npm run builduses the development manifest and writes the ignored, unpacked extension todist/.npm run previewcannot validate service workers, content scripts, or Chrome APIs; loaddist/throughchrome://extensionsand reload the extension after each rebuild.npm run build-produsessrc/manifest.prod.ts, writesdist-prod/, and packagesrelease/brainrest-x.y.z.zip. The packaging script requires productionupdate_urland rejects a manifestkey; debug/demo visibility depends on this distinction.- Keep the version synchronized in
package.json,src/manifest.ts, andsrc/manifest.prod.ts. Do not edit or commit generateddist/,dist-prod/, orrelease/contents.