Imported from AmoghRavindraRao/me (
AGENTS.md). Install upstream withnpx skills add AmoghRavindraRao/me. Copyright stays with the author.
AGENTS
IMPORTANT: Agent-only document — DO NOT DEPLOY
This file is intended only for developer/agent use (automated coding assistants such as OpenCode).
Keep it in the repository root so agents can read it, but do NOT include it in production deployments.
A .vercelignore file is added to ensure this file and other agent-only artifacts are excluded from Vercel deployments.
This document is written for automated/agentic coding assistants that will operate in this repository. It collects the most important commands, repository conventions, and coding-style rules so agents can make safe, consistent changes.
- Quick commands (local)
- Install dependencies:
npm ci(preferred for CI) ornpm install - Start dev server:
npm run dev-> (vite) - Build for production:
npm run build-> outputs todist/ - Preview the production build locally:
npm run preview - Lint (project):
npm run lint(runseslint .as configured ineslint.config.js) - Type-check only:
npx tsc --noEmit(usestsconfig.json) - Run the CI sequence locally:
npm ci && npm run lint && npm run build(matches.github/workflows/ci.yml)
Notes: package.json scripts live in package.json (see dev, build, lint, preview). The CI file is .github/workflows/ci.yml and uses Node 20.
- Tests — current state and single-test guidance
-
Current repo: there are no dedicated test scripts or test runner configured in
package.json. -
If you need to run a single test file locally, the recommended modern approach is Vitest. Example commands once Vitest is added as a devDependency:
- Run a single test file:
npx vitest run path/to/file.test.tsornpx vitest run path/to/file.test.tsx - Run a single test by name:
npx vitest -t "partial test name"
- Run a single test file:
-
If you use Jest instead, run a single file or test with:
npx jest path/to/file.test.ts -t "partial test name"
-
Recommendation for adding tests:
- Add
vitest,@testing-library/reactand@testing-library/jest-domas devDependencies. - Add a
testscript inpackage.json:"test": "vitest"and"test:run": "vitest run". - Place unit tests next to components as
ComponentName.test.tsxor inside__tests__/directories.
- Add
- Linting & formatting
- Linting:
npm run lintrunseslint .usingeslint.config.js(the repo uses@eslint/jsandeslint-plugin-react-hooks). - Run ESLint on a single file:
npx eslint src/components/ChatWidget.tsx --fix - Type-aware lint: this repository currently has an ESLint JS flat config for JS files; TypeScript-focused linting can be introduced by adding
@typescript-eslintplugins/configs. - Formatting: the repository does not include Prettier by default. We recommend adding Prettier and running
npx prettier --write .if you introduce it — keep changes consistent with existing code.
- Environment & secrets
- Environment files present:
.env.example,.env,.env.local. - DO NOT commit credentials or secrets. If you need a secret for local work, create
.env.localand add it to.gitignore(already common practice here).
- Important repo files to inspect before making changes
package.json— scripts and dependency liststsconfig.json— path aliases and compiler options (seepathsfor@/*and~components/*etc.)eslint.config.js— lint rules and global ignores (currently excludesdist).github/workflows/ci.yml— CI pipeline (runsnpm ci,npm run lint,npm run build)src/— main source tree. Key folders:src/components,src/pages,src/features/*,src/hooks,src/providers
- Import & module conventions
-
Prefer the path aliases defined in
tsconfig.jsonrather than long relative imports when possible:@/*->src/*~components/*->src/components/*~hooks/*->src/hooks/*~pages/*->src/pages/*
-
Import ordering: keep a consistent, readable ordering:
- Node built-ins (if any)
- External packages (React, third-party)
- Absolute/alias imports (
@/...,~components/...,~pages/...) - Relative imports (
./,../)
-
Keep one blank line between groups. Use named imports for clarity. Use
import type { ... } from '...'for type-only imports.
- TypeScript & typing rules
- Project compiler options are strict (
strict: true) intsconfig.json. Follow them. - Use
interfacefor exported object shapes (models, props, context values) unless you need advanced unions / mapped types — then usetype. - Prefer
unknownoveranywhen receiving untrusted values; narrowunknownas early as possible. - Exported functions and React components should have explicit return types when it improves readability — at a minimum ensure exported APIs are well-typed.
- Use
import typefor types and interfaces to avoid runtime imports.
- Naming conventions
- Components and pages: PascalCase (e.g.
ChatWidget,Home,BlogPost) and filename should match the component name (ChatWidget.tsx). - React hooks: prefix with
useand use camelCase (e.g.useTypewriter,useChat). - Context/providers:
SomethingProvider(e.g.ChatProvider) and hook accessorsuseSomething(e.g.useChat). - Event handlers / callbacks: prefix with
handle(e.g.handleSend,handleKeyDown). - Boolean variables:
is/has/shouldprefix (e.g.isOpen,isLoading). - Constants: UPPER_SNAKE_CASE when module-level constants are configuration-like (
SUGGESTED_PROMPTS,INITIAL_MESSAGE) — otherwise PascalCase for exported objects.
- React & component patterns
- Use function components and hooks (already the dominant pattern here).
- Hooks must be called at the top-level of the component.
- Use
useCallback/useMemoto memoize handlers and values passed to stable children, but only when there is a measurable benefit. - Prefer small components; lift state up as needed. Use context for app-wide concerns (e.g. the
ChatProvider). - For expensive child components, use
React.memowith stable props.
- Error handling & async
- Always handle network errors and unexpected data shapes.
- For streaming or cancellable requests, use
AbortController(this repo already uses it instreamChatandChatContext). - When catching errors, populate user-facing messages in state and log full errors only in dev (or via an observability backend).
- Avoid swallowing errors silently — prefer explicit error states and fallbacks.
- Accessibility & UX
- Buttons and interactive elements should include
aria-labelwhen the visual text is insufficient. - Keyboard interactions: ensure focus management and keyboard shortcuts are non-intrusive (e.g.
Ctrl+.toggle documented inChatWidget). - Use semantic HTML elements where possible and keep focus-visible outlines for accessibility.
- Security
- Any time you inject HTML into the DOM (e.g.
dangerouslySetInnerHTML) sanitize it first. The project already depends ondompurify— use that. - Treat external input as untrusted. Validate server inputs (workers code) and client-side guardrails.
- Tailwind / styling
- The project uses Tailwind utility classes. Keep utility usage in components for layout and small styling concerns.
- Avoid embedding large style blocks in components; prefer re-usable classes or component-level CSS when duplication grows.
- Tests & test patterns (recommendations)
- File layout: place unit tests next to implementation (
Component.test.tsx) or undersrc/__tests__/. - Use Testing Library for React components and assert accessible roles instead of implementation details.
- Create small helper utilities to render components with common providers (e.g. SnackbarProvider, ChatProvider) for test setup.
- Pull requests and commit hygiene
- Before creating a PR: run
npm run lintandnpx tsc --noEmitandnpm run build. CI enforces lint + build. - Write focused commits; update
README.mdorCHANGELOG.mdif the change is user-facing.
- Cursor / Copilot rules
- I checked for Cursor rules under
.cursor/rules/and for Copilot rules under.github/copilot-instructions.md— none were found in this repository. If you add them, document them here and reference their path.
- Making changes (agent safety checklist)
- Run
npm ciandnpx tsc --noEmitlocally before making code changes. - Run
npm run lintand fix issues (or runnpx eslint <file> --fixfor one-off fixes). - If you add runtime dependencies, add them to
package.jsonand runnpm cilocally to update lockfile. - Do not modify
dist/— it is a build artifact and should be ignored. - Avoid committing secrets from
.envfiles.
If you need me to add a testing stack (Vitest + Testing Library) or a formatter (Prettier) I can create the config and scripts — tell me which one you prefer.
Appendix — quick file references
- Lint config:
eslint.config.js - Type config & aliases:
tsconfig.json - Scripts:
package.json - CI:
.github/workflows/ci.yml - Chat feature entry:
src/features/chat(context, api, types)
- CLIs, production sync & process
-
Use the official CLIs when performing production checks or deployments:
gh(GitHub CLI),vercel(Vercel CLI) andwrangler(Cloudflare Wrangler / Cloudflare CLI). Install vianpm i -g gh vercel @cloudflare/wrangleror your preferred package manager if they are missing. -
Authentication (examples):
gh auth login(GitHub)vercel login(Vercel) orvercel --token $VERCEL_TOKENwrangler loginor setCF_API_TOKENandCF_ACCOUNT_IDin your environment
-
Environment variables used by agents (never commit these):
CF_API_TOKEN,CF_ACCOUNT_ID,CF_SCRIPT_NAME,VERCEL_TOKEN,VERCEL_PROJECT,GH_TOKEN. -
Quick checks (examples):
- Get Cloudflare worker metadata (API):
curl -s -H "Authorization: Bearer $CF_API_TOKEN" "https://api.cloudflare.com/client/v4/accounts/$CF_ACCOUNT_ID/workers/scripts/$CF_SCRIPT_NAME" | jq . - List Vercel deployments (CLI / API):
vercel --token $VERCEL_TOKEN projects lsandvercel --token $VERCEL_TOKEN deployments ls $VERCEL_PROJECT - GitHub: view open PRs / create a PR via
gh pr create --title "sync: ..." --body "..." --base main --head sync/production-sync
- Get Cloudflare worker metadata (API):
-
Sync policy (canonical order):
- Cloudflare Workers (Primary) — treat the live Worker script as the primary canonical source for serverless code running on Cloudflare. If production differs from GitHub, bring Cloudflare -> GitHub.
- Vercel (Secondary) — for static assets / frontend builds. If Vercel production differs from GitHub, reconcile after Cloudflare is synced.
- GitHub — canonical source of truth for the repository code; ensure GitHub contains the exact production code by creating PRs that merge the production state into the repo.
-
Recommended sync workflow when a drift is detected:
- Verify account access:
gh auth status,wrangler whoami,vercel whoami. - Fetch production artifact(s): download Cloudflare script and Vercel deployment metadata (use the CLIs or APIs; store in a temp location).
- Diff against local files:
git --no-pager diff --no-index /tmp/production-worker.js src/worker/worker.jsor usediff -u. - Create a proof branch:
git checkout -b sync/production-<service>-YYYYMMDDand commit the minimal, well-documented changes:git add ... && git commit -m "chore(sync): sync <service> production -> repo (<reason>)". - Open a PR for human review:
gh pr create --title "sync: <service> production" --body "Production -> GitHub sync. Verified by <agent>". - Run
npm ci && npm run lint && npx tsc --noEmit && npm run buildin the PR CI steps (CI already enforces lint + build). - After approval & merge, optionally trigger a redeploy on Vercel or Cloudflare (use
vercel --prodorwrangler publishdepending on the change) — only redeploy when authorized.
- Verify account access:
-
Never push or force-push direct to
mainon behalf of the team; create PRs and require at least one human reviewer unless explicitly allowed.
- Skills & runtime policy
- Always prefer using available agent skills (the runtime
skilltool) for specialized tasks (testing, deployment checks, UI audits, DB operations). Example skill names in this environment:webapp-testing,vercel-react-best-practices,web-design-guidelines,frontend-dev-guidelines,security-review. - If a required skill is not present locally, the agent should attempt to install it (or request permission to install). Installation methods vary by environment — examples:
- Use the skill loader: call the
skilltool with the skill name if available in the runtime. - If skill is an npm package, install with
npm i -D <package>(ask before modifying package.json if not already authorized).
- Use the skill loader: call the
- Record which skills were used for a change in the PR body (example:
Used skills: vercel-react-best-practices, webapp-testing).
- Final safeguards
- AGENTS.md and any
.opencode/or agent-only directories MUST NOT be deployed to production. We added.vercelignoreto prevent accidental Vercel deployments; ensure similar ignores exist for other deployment pipelines. - Do not expose secrets in PRs or commit messages. If a check requires a token, use environment variables in CI or ask a maintainer to run the step locally.
- If you are blocked by missing credentials or a destructive action (force-push, rollback, secret rotation), ask exactly one targeted question and recommend a default.
If you'd like, I can add automated scripts to help with the Cloudflare <-> GitHub sync, a PR template that includes the Used skills: line, and a small verification script that compares deployed worker code with repository files. Tell me which of the three to add (reply 1, 2, or 3).