# gaipack — AI Working Protocol (AGENTS.md)

> **Source of Truth:** The AI working protocol — norm priority, stop process, fail-loud reporting, checkpoints, and the core self-audit — for UI work on the gaipack site's design system.
>
> **Refer elsewhere for:**
>
> - Visual tokens, brand principles, high-level component visuals → `DESIGN.md`
> - Implementation details (props, code examples, technology-specific prohibitions) → `COMPONENTS.md`
> - Page and section patterns → `PATTERNS.md`
> - Change history and recorded deviations → `CHANGELOG.md`
> - Repository-wide engineering rules (commands, CMS, sync with the upstream repository) → the **repository-root** `AGENTS.md` (a different file — see "Two AGENTS.md files" below)
> - Service facts, numbers, and wording → the service definitions under `docs/services/` (synced from the upstream source of truth; never edited in this repository)
>
> This file says **how the AI behaves**, not **what to build**. It contains no visual values and no component specifications.

## Why this file is named AGENTS.md, not CLAUDE.md

The design system's four norm documents (`DESIGN.md` / `COMPONENTS.md` / `PATTERNS.md` / this file) are meant to be read by any AI coding agent — Claude Code, GitHub Copilot, Cursor, Gemini CLI. Naming the behavior file after one vendor's product would contradict the tool-and-agent independence this design system exists to provide, and it would conflict with gaipack's own convention: internally, `AGENTS.md` is the single source of truth for AI working rules, and a project's `CLAUDE.md` — where one exists — is only a thin pointer that tells Claude Code to go read `AGENTS.md` (this repository's own root `CLAUDE.md` does exactly that; GitHub Copilot points at the same file via `chat.useAgentsMdFile`). `AGENTS.md` is also becoming a cross-tool convention outside gaipack — several coding agents look for a file by that exact name. This file follows both precedents.

### Two AGENTS.md files in this repository

This repository has two files named `AGENTS.md`, at different scopes:

| File | Scope | Content |
| --- | --- | --- |
| `/AGENTS.md` (repository root) | The whole repository | Commands, architecture, CMS configuration, sync rules with the upstream repository |
| `/public/AGENTS.md` (this file) | The design system only | AI working protocol for UI implementation — reading order, stop process, self-audit |

They are not duplicates and do not conflict: the root file governs engineering work in general, this file governs UI implementation specifically, and this file's own "MANDATORY PRE-FLIGHT" section is what an agent reads once it is doing design-system work. Don't merge them.

---

## 1. MANDATORY PRE-FLIGHT

When asked to implement or change UI, read in this order before writing code:

1. **The requirement** — the issue, PR description, or request (fix the scope)
2. **`PATTERNS.md`** — does an existing page or section pattern apply?
3. **`COMPONENTS.md`** — which components and props are available (§1 Primitives / §1.5 Common / §2 Layout)
4. **`DESIGN.md`** — visual tokens, brand principles, high-level component visuals
5. **`docs/services/<service>.md`** — when the change touches service copy, numbers, or claims

> Do not write code before reading. "I roughly know it" is an assumption.
> Do not touch files or components outside the scope of the requirement (surgical changes).

### 1.1 Inference rules (absolute rules for AI judgment)

1. **Unspecified = default**
   - If the requirement does not specify a variant, use the component's default (`COMPONENTS.md`)
   - "Nothing was specified, so I chose something else" and "I picked the more prominent one" are prohibited
   - In particular, never promote a CTA to `primary` on your own; one primary action per screen
2. **Every judgment follows the decision tables in `COMPONENTS.md` / `PATTERNS.md` / `DESIGN.md`**
   - Deciding from "AI experience", "general practice", or "other products do it this way" is prohibited
   - If a decision flow reaches [STOP] or a condition is not in a mapping table, move to §3 (no autonomous continuation)
3. **Dark first, then light**
   - Write the dark look in base classes, then add `light:` overrides before declaring the change complete. A dark-only change is not complete
4. **Facts come from the source of truth**
   - Numbers, results, prices, and claims in the UI come from `docs/services/`. Never invent, round up, or strengthen them

---

## 2. Norm priority (on conflict the higher row wins)

| Priority | Norm | Enforcement |
| --- | --- | --- |
| 1 | Accessibility (WCAG AA contrast, focus visibility, 44px tap targets, `aria-label` on icon-only controls) | Reject |
| 2 | Lint syntax rules (`pnpm lint` = Biome on the changed files; `pnpm textlint` for Japanese copy) | Auto-reject |
| 3 | `DESIGN.md` YAML tokens (colors / typography / spacing / rounded / components) | Reject on implementation |
| 4 | `npx @google/design.md lint public/DESIGN.md` unexpected errors (expected warnings are listed in `DESIGN.md §11.4`) | Auto-reject |
| 5 | `DESIGN.md` Markdown body (usage mappings, high-level visual principles, Do's and Don'ts) | Self-audit |
| 6 | `COMPONENTS.md` / `PATTERNS.md` | Supporting reference |
| 7 | Official documentation of the UI library (shadcn/ui, Tailwind CSS) | Reference only |
| 8 | General AI knowledge | Lowest |

**When you find a contradiction, do not average.** Choose the higher norm and report the lower contradiction as "⚠️ Contradiction detected: [location]". Resolving contradictions automatically is prohibited.

> Legacy notations that `DESIGN.md` tolerates (e.g. `text-[#B9C2CC] light:text-content-muted`) may stay where they are; new work uses tokens. Do not mass-replace them unless the requirement asks for it.

---

## 3. Stop process

When any of the following applies, **stop immediately** and report in this format:

```
[STOP]
Reason: <UI not in COMPONENTS.md / value outside DESIGN.md tokens / not in the requirement / fact not in docs/services>
Requirement location: <issue / PR / line or section>
Closest existing UI: <COMPONENTS.md §X.X / PATTERNS.md §Y>
Proposal: A) <substitute with existing> / B) <add new — approval required> / C) <requirement needs clarification>
```

**When a component name is ambiguous** (an external framework name, an ARIA role, a design-tool name, a Japanese nickname), present candidates:

```
[NAME CHECK]
Received name: "<name>" (issue L__ / design file / verbal)
Candidates:
  A) <gaipack component> — <reason>
  B) <gaipack component> — <reason>
  C) None of the above (new component)

Which one is intended?
```

**Typical cases:** "button" → A) `<CTA>` (marketing action) / B) `<Button>` (in-page control). "card" → A) `Link` with the card treatment (marketing) / B) `<Card>` (documentation block). "tag" → A) accent pill `span` / B) `<Badge>`.

Do not proceed to implementation until you receive a go.

---

## 4. Fail loud (before saying "done")

**Before saying "implemented" or "complete", report the following first:**

- ⚠️ Parts skipped or not implemented
- ⚠️ Elements added by your own judgment that the requirement did not mention
- ⚠️ Places where a value outside the `DESIGN.md` tokens had to be used
- ⚠️ Components you built yourself that are not in `COMPONENTS.md`
- ⚠️ Light-theme overrides that are missing or unverified
- ⚠️ Numbers or claims whose source in `docs/services/` you could not confirm
- ⚠️ Errors you suppressed (`// biome-ignore`, `@ts-ignore`, `textlint-disable`)

"Complete", "verified", and "compliant" may be said only when the list of unmet items is empty. **A failure that looks like success is the most expensive kind.**

---

## 5. Checkpoint (multi-page / multi-step work)

When implementing several pages or steps in sequence, summarize after each step:

```
[Checkpoint]
Done: <what was implemented>
Verified: <what was checked — lint passed / both themes viewed / textlint passed / design.md lint>
Next: <what remains>
```

Do not move on if you cannot describe the state of the previous step. When lost, stop and re-plan.

---

## 6. No invented features or decoration

Unless the requirement states it, **never add** any of the following:

Search bars / notification bars / announcement banners / KPI or metric cards / extra CTAs / extra sections / extra tabs / testimonials / logos of customers or partners / pricing tables / comparison tables against competitors / theme-specific decorations / animations "for delight"

"For a better UX", "as a starting point", and "just for now" are also prohibited. To add something, use the stop process in §3.

**Copy is a feature too.** Never invent numbers, guarantees, superlatives, customer names, or prices. If the source of truth lacks a fact, leave the fact out and report it (§4).

---

## 7. Project-specific policies

### 7.1 TOKEN-FIRST POLICY

- Colors, spacing, and radii are referenced through the semantic tokens in `app/globals.css` (`bg-surface`, `text-content`, `border-border-subtle`, `text-accent-cyan`, …). Raw hex and Tailwind default colors are prohibited in new work (`DESIGN.md §8.1`)
- Adding a token means editing the `DESIGN.md` YAML and `globals.css` in the same PR and recording it in `CHANGELOG.md`
- Scoped LP tokens (`--lp-*` / `--gov-*` / `--svc-*`) stay scoped; never promote them to global tokens for convenience

### 7.2 THEME POLICY

- Both themes are mandatory for every page and component (the only exception is the static LP `/lp/aidd-camp`)
- Base classes are dark; `light:` overrides light. Never use `dark:` to define the dark look
- Glows and shadows are stripped globally under `.light`; do not add per-element `light:shadow-none`
- Verify both themes visually after every change (§10)

### 7.3 COMPONENT-FIRST POLICY

- Marketing actions use `<CTA>`; in-page controls use `<Button>`. Never a raw `<a>` / `<button>` with gradient classes
- Navigation links use `Link` from `next/link`; in-page anchors use `<ScrollLink>`
- CMS images use `<ImageWithFallback>`; YouTube uses `<LiteYouTubeEmbed>`
- Breadcrumbs use `<Breadcrumb>` / `<BreadcrumbWithJsonLd>`; service pages use `buildServiceBreadcrumbItems`
- Pagination uses `<Pagination>`
- The gaipack logo is placed only through `<Logo>` (`DESIGN.md §10` NO RECREATION)

**Permitted custom implementations:** feature components inside `features/<domain>/components/` that compose the parts above within a `PATTERNS.md` pattern. New Common or Layout components need approval.

### 7.4 BRAND AND COPY POLICY

- The company name is「KDDIアイレット株式会社」/「KDDIアイレット」— never「アイレット」alone
- Customer and project names appear only within the disclosure scope of the corresponding case page
- Numbers keep the qualifiers of the source (「約」「最大」「目指す」). Disclaimers accompany metrics
- Japanese copy passes `pnpm textlint` (spacing between Japanese and Latin characters, notation rules)

### 7.5 SOURCE-OF-TRUTH SYNC POLICY

- `docs/services/`, `docs/cases/`, and the `gaipack-*`-prefixed files under `docs/guidelines/` and `.agents/skills/` are synced daily from the upstream repository. **Never edit them here**; a change there is a PR in the upstream repository
- Service copy on the site must match those documents. When they disagree, the site is what changes

### 7.6 PUBLISHED NORMS

- `public/DESIGN.md`, `COMPONENTS.md`, `PATTERNS.md`, `AGENTS.md` (this file), and `CHANGELOG.md` are published on the site. Write nothing confidential in them (internal issue numbers, customer names, unpublished prices, internal tooling details)

---

## 8. Implementing from an image (mockups, screenshots)

Extract **structure only** from images:

| OK to extract | Never extract |
| --- | --- |
| ✅ Layout structure (vertical/horizontal arrangement, grouping) | ❌ Color values (guessing hex, eyedropping) |
| ✅ Component kinds (card / grid / list / form) | ❌ Sizes (font size, padding in px) |
| ✅ Element hierarchy | ❌ Radius / shadow / border strength |
| ✅ Text content | ❌ Icon shapes |

Every color, size, and decoration value is forced to `DESIGN.md` tokens.

---

## 9. Self-audit (mandatory before output)

Check these core items internally. If any is ✗, fix before output.

- [ ] **Zero elements outside the requirement** — no invented search bars, banners, extra CTAs, extra sections
- [ ] **Zero values outside `DESIGN.md` tokens** — no raw hex, Tailwind default colors, arbitrary spacing in new work
- [ ] **Both themes implemented** — `light:` overrides present and viewed
- [ ] **Zero raw `<a>` / `<button>` CTAs** — `<CTA>` / `<Button>` used correctly
- [ ] **The pattern in `PATTERNS.md` is followed** — section order, item counts (3 problems / 4 steps), CTA placement
- [ ] **One primary action per screen**
- [ ] **State or category is never conveyed by color alone**
- [ ] **Icon-only controls have `aria-label` or `sr-only`; new-tab links have the `sr-only` note**
- [ ] **Numbers and claims match `docs/services/`** with their qualifiers
- [ ] **Company name notation is correct** (KDDIアイレット)
- [ ] **No synced source-of-truth paths were edited**
- [ ] **Stopped where stopping was required** — no undefined UI or token passed by judgment
- [ ] **Fail-loud conditions (§4) satisfied** — unmet items and additions reported first

---

## 10. Verification commands

```bash
# Lint the changed files (Biome). The whole repository has known pre-existing findings; check your files only.
pnpm exec biome check <changed files>

# Japanese copy check (required CI check for app/ features/ lib/ shared/)
pnpm textlint

# Unit tests
pnpm test

# Google design.md lint (expected warnings are listed in DESIGN.md §11.4; errors block)
npx @google/design.md lint public/DESIGN.md

# Production build (also validates the CMS connection when credentials are present)
pnpm build
```

Visual verification: open the changed pages locally in **both** dark and light, at mobile and desktop widths, before reporting completion.

---

## 11. Where the sources of truth live

**Design-system norms (published):** `public/AGENTS.md` (this file) / `public/DESIGN.md` (visuals) / `public/COMPONENTS.md` (implementation) / `public/PATTERNS.md` (page patterns) / `public/CHANGELOG.md` (history)

**Engineering rules:** `AGENTS.md` (commands, architecture, CMS, sync, textlint) / `docs/architecture.md`

**Facts and copy:** `docs/services/*.md` (service definitions, synced) / `docs/cases/` (published cases, synced) / `docs/usage-rules.md` (notation)

**Brand constants in code:** `lib/brand.ts` (tri-color line) / `app/globals.css` (semantic tokens for both themes)

**Foundation:** Next.js App Router + React + Tailwind CSS v4 + shadcn/ui (new-york) + lucide-react + next-themes. Dark is the reference theme; light is mandatory.
