Global WatchGW Docs
Development

AI Agents Guide

AI Agents Guide

This page summarises the engineering rules every AI agent (Claude, Cursor, Copilot, Amazon Q, etc.) must follow when contributing to Global Watch. It is a public summary of the canonical sources:

When in doubt, the in-repo files win.

Agents who skip the investigation step (Law 1) or commit without explicit user request (Law 4) will have their work rejected. These are not suggestions.

Quick Start

Before doing anything in the repository:

  1. Read /AGENTS.md end to end (~5 min).
  2. Read the per-workspace AGENTS.md for the area you'll touch (e.g. apps/web/AGENTS.md, packages/gw/AGENTS.md).
  3. Investigate before designing or coding (Law 1).
  4. Write a failing test first (Law 2).
  5. Place all new code in @gw/* (Law 8).
  6. Never commit unless the user asks (Law 4).

The 8 Absolute Laws

These rules have zero tolerance. Any violation blocks the PR.

Law 1 — Investigate Before You Build

Before designing or coding anything, search the codebase exhaustively and prove the thing does not already exist.

Required search order: packages/gw/packages/fw/apps/{web,map,mobile}/.kiro/specs/.kiro/steering/.

The investigation must be documented in your plan as an Investigation Report.

Law 2 — TDD Iron Law

RED → GREEN → REFACTOR. Always in that order. No production code before a failing test that fails for the right reason.

# 1. RED: write a failing test
pnpm --filter <pkg> test:run     # must FAIL

# 2. GREEN: minimal code to pass
pnpm --filter <pkg> test:run     # must PASS

# 3. REFACTOR: clean up
pnpm --filter <pkg> test:run     # must STAY PASS

Coverage floor: 70% overall, 90% on critical paths (auth, billing, RLS, multi-tenancy).

Law 3 — Type Safety Is Not Optional

any, as any, @ts-ignore, @ts-expect-error in production code = rejection.

// ❌ REJECTED
const data: any = getData();

// ✅ Library types
import type { GeoJSONSource } from 'mapbox-gl';
const source = map.getSource('points') as GeoJSONSource;

// ✅ Database types (source of truth for DB shape)
import type { Database } from '~/lib/database.types';
type ProjectRow = Database['public']['Tables']['projects']['Row'];

// ✅ unknown + type guards
function process(data: unknown) {
  if (typeof data === 'object' && data !== null) { /* ... */ }
}

Law 4 — Commit Only When Asked

No git commit without explicit user request. This includes git push, --amend, rebase, and git add of unrelated files.

Stage changes. Propose a Conventional Commit message. Wait for the user to say "commit."

Law 5 — Workspace Boundaries Are Sacred

Working in apps/web/? Stay in apps/web/. Working in packages/gw/{name}/? Stay there.

Reading other workspaces for investigation (Law 1) is always allowed. Cross-cutting changes (root package.json, turbo.json, shared configs) require explicit approval.

Law 6 — Environment Variables for All URLs

// ❌ REJECTED
const url = 'http://localhost:3000/auth/callback';
const origin = window.location.origin;

// ✅ CORRECT
const url = process.env.NEXT_PUBLIC_APP_URL + '/auth/callback';

Required env vars: NEXT_PUBLIC_APP_URL, NEXT_PUBLIC_BASE_DOMAIN, NEXT_PUBLIC_SITE_URL.

Law 7 — Post-Task Review Is Mandatory

pnpm typecheck                     # exit 0
pnpm lint:fix                      # exit 0
pnpm format:fix                    # no diff (or commit it)
pnpm --filter <pkg> test:run       # all green
pnpm --filter <app> build          # exit 0 (when applicable)

For UI work, re-read your own JSX for nesting, accessibility, and i18n keys.

Law 8 — All New Code Lives in @gw/*

NamespaceStatusWhat goes here
@gw/* (packages/gw/)🟢 Active — present and futureAll new code, components, services, packages.
@fw/* (packages/fw/)🟡 Frozen — patches onlyExisting legacy code. Critical bug fixes only. No new files.
@kit/* (packages/)🔴 Archaeology — read-onlyOriginal Makerkit boilerplate. Reference only.

When extending or replacing functionality from @kit/* or @fw/*, build the new version in @gw/* and migrate consumers progressively.


RITO Methodology v2.0.0

RITO = Rigor · Iteration · Testing · Ownership.

The RITO Loop is the only sanctioned development cycle:

Intent → (Spec) → Investigation → TDD (RED) → Build (GREEN/REFACTOR) → Review → Docs → Ship

Investigation Protocol

Use these tools — in parallel when possible:

ToolPurpose
grep / ripgrepText search across the entire repo
ast_grepStructural code search (functions, components)
globFind files by name pattern
lsp_* (find_references, goto_definition, symbols)Symbol-aware navigation
explore agentParallel multi-angle codebase grep
librarian agentExternal docs / OSS reference search

Investigation Report (required in your plan)

## Investigation Report

**Task:** <one sentence>

**Searched:**
- packages/gw/   → grep "<term>"     → <findings or "no matches">
- packages/fw/   → grep "<term>"     → <findings or "no matches">
- apps/web/      → grep "<term>"     → <findings or "no matches">
- .kiro/specs/   → ls + grep         → <relevant specs or "none">
- .kiro/steering → relevant files    → <list>

**What already exists that I will reuse:**
- <file:line> — <what it provides>

**What does not exist and must be created:**
- <component/service/page> in `packages/gw/<name>/` because <reason>

**Decision:**
- Reuse: <list>
- Create new in @gw: <list>
- Migrate from @fw if encountered: <list>

No report = no work.


Definition of Done

A task is complete only when every box is checked:

[ ] Investigation Report included in the plan       (Law 1)
[ ] Failing test was written first                  (Law 2)
[ ] Implementation makes the test pass
[ ] All new code is in @gw/* or app workspaces      (Law 8)
[ ] No new files in @fw/* or @kit/*                 (Law 8)
[ ] pnpm typecheck                                  → exit 0
[ ] pnpm lint:fix                                   → exit 0
[ ] pnpm format:fix                                 → no uncommitted diff
[ ] pnpm --filter <pkg> test:run                    → all green
[ ] pnpm --filter <app> build                       → exit 0 (if app code changed)
[ ] Feature manually verified in browser            → no console errors
[ ] No regressions in adjacent features
[ ] i18n keys present in en, pt-br, ar              → if UI strings added
[ ] RTL verified                                    → if UI changed
[ ] RLS policy added/updated and tested             → if DB tables touched
[ ] docs/features/{FEATURE}.md updated              → §Documentation Contract
[ ] apps/docs MDX updated                           → if user-facing
[ ] ADR written                                     → if architectural decision made
[ ] Commit message proposed (NOT executed)          → Law 4

Documentation Contract

For every shipped feature, produce two artifacts (and optionally a third):

ArtifactPathAudience
Internal feature docdocs/features/{FEATURE_NAME}.mdEngineering team
Public MDXapps/docs/content/docs/{section}/{feature}.mdxCustomers / integrators
ADR (optional)docs/architecture/ADR-{NNN}-{slug}.mdFuture contributors — only when an architectural decision was made

Sprint documents (SPRINT_N_*.md) are no longer required. Time/cost tracking is not part of the documentation contract.


Commit Message Format

Conventional Commits. No time tracking. Wait for explicit user request before running git commit.

type(scope): brief description

[Optional body explaining the why]

✅ Verified:
- TypeCheck: ✅
- Lint: ✅
- Tests: ✅ <X/Y passing>
- Build: ✅
- Manual: ✅

📚 Documentation:
- docs/features/{FEATURE}.md
- apps/docs/content/docs/{section}/{feature}.mdx (if user-facing)
- docs/architecture/ADR-NNN-{slug}.md (if architectural decision)

Closes #XXX

Types: feat, fix, chore, refactor, docs, test, style, perf, build, ci.


Feature Flags

Verify flag state before implementing — building for a disabled flag is wasted work.

FlagDefaultDescription
enableThemeToggle✅ trueLight/dark theme toggle
enableTeamAccounts✅ trueTeam accounts
enableTeamCreation✅ trueTeam creation
enableNotifications✅ trueNotification system
enableWorkOrders✅ trueWork orders & crews
enableAccountDeletion❌ falsePersonal account deletion
enableTeamDeletion❌ falseTeam deletion
enablePersonalAccountBilling❌ falsePersonal billing
enableTeamAccountBilling❌ falseTeam billing
realtimeNotifications❌ falseRealtime notifications

Source of truth: apps/web/config/feature-flags.config.ts.

Rules: never enable billing/deletion flags without explicit authorization. Document any feature that depends on a specific flag.


Optional: Context Manager Tooling

The repo ships an optional Context Manager (@fw/context-manager) that can persist and switch between workstreams when several agents collaborate. It is not mandatory under RITO v2.0.0 — your task list (todowrite) and the per-task Investigation Report cover the required state.

# Track lifecycle (optional)
pnpm track:list
pnpm track:create my-track "Agent name" "What this track is for"
pnpm track:switch my-track
pnpm context:restart

# Save / load context
pnpm context:save
pnpm context:load

Getting Help

When stuck:

  1. Re-read /AGENTS.md.
  2. Consult /docs/RITO_METHODOLOGY.md.
  3. Consult the relevant file in /.kiro/steering/.
  4. Ask the user before proceeding.

Never improvise. Always ask when in doubt.


On this page