This guide explains how to turn a project idea into a clear, actionable specification for autonomous coding agents in LoopGate JS.
LoopGate JS relies on three core documents under docs/ to organize work between humans and AI agents:
| Document | Purpose | Owner |
|---|---|---|
docs/plan.md |
The Grand Vision: High-level objective, features, technical approach, and major project milestones. | Human (or delegated to agents) |
docs/specs/*.md |
Actionable Tasks: Concrete, track-specific instructions defining WHAT to build, test criteria, and boundaries. | Human / Agent |
docs/PROJECT_STATUS.md |
Current State: Snapshot of active focus, pass/fail status of gates, next actions, and changelog. | Human & Agent (updated each iteration) |
Check docs/plan.md to determine which milestone or feature you are addressing. Ensure the objective is well-defined.
Create a new file in docs/specs/ using docs/specs/base.md as the template:
cp docs/specs/base.md docs/specs/dark-mode-toggle.md- Priority Header: State priority (
PRIORITY 1,2, or3) and a 1–2 sentence problem statement. - Scope: Detail frameworks, APIs, files, or CSS classes to use.
- Priorities / Milestones: Break the work into concrete sub-tasks with verifiable definitions of done (e.g., test commands).
- Guardrails: Define constraints (e.g. use CSS custom properties, avoid measuring DOM via TypeScript).
- Acceptance Criteria: State measurable checks (e.g.,
pnpm gatepasses, 100% test coverage). - Out of Scope: Explicitly list non-goals to prevent agent scope creep.
Point the active focus to your new spec (e.g., Active spec: docs/specs/dark-mode-toggle.md → Milestone 1).
Here is a minimal, complete example of a frontend feature spec (docs/specs/dark-mode-toggle.md):
# Dark Mode Toggle Spec
> **PRIORITY 1.** Add a theme toggle button in the header that switches between light and dark themes using CSS variables and persists preference in localStorage.
## Scope
- Modify \`frontend/index.html\` to include the theme toggle button in the header.
- Add theme color variables (\`--bg-primary\`, \`--text-primary\`) in \`frontend/src/style.css\`.
- Add event listeners and localStorage persistence in \`frontend/src/theme.ts\`.
## Priorities
1. Milestone 1: Theme State Management & CSS Tokens
- Define CSS custom properties for \`[data-theme="dark"]\` and \`[data-theme="light"]\`.
- Implement \`initTheme()\` and \`toggleTheme()\` helper functions.
- Files created or updated: \`frontend/src/style.css\`, \`frontend/src/theme.ts\`
- Definition of done: \`pnpm --filter frontend test -- src/theme.test.ts\`
2. Milestone 2: UI Integration & Accessibility
- Mount button with \`aria-label="Toggle dark mode"\` and \`data-hook="theme-toggle"\`.
- Update e2e tests in \`frontend/tests/home.spec.ts\` to verify theme toggling across viewports.
- Definition of done: \`pnpm gate\` exits 0.
## Guardrails
- Use semantic CSS custom properties; do not hardcode hex values in component styles.
- Selector discipline: Target the button using \`data-hook="theme-toggle"\`.
- Keep bundle lean; do not introduce third-party icon packages.
## Acceptance Criteria
- Clicking the toggle flips \`data-theme\` attribute on \`<html>\` or \`<body>\`.
- Theme selection persists across page reloads via \`localStorage\`.
- Unit tests achieve 100% line and branch coverage.
- \`pnpm gate\` passes cleanly.
## Out of Scope
- System OS theme detection / matchMedia auto-switching (Milestone 2 follow-up).
- Animation transitions for theme change.
## Changelog
- Initial draft of dark mode toggle spec.Before running autonomous loops, ensure the project satisfies the gate:
pnpm preflight # Fast format and lint checks
pnpm gate # Full validation suite (types, unit tests, e2e, security)