Skip to content

Commit 40c6560

Browse files
committed
@W-21450839 docs: ultra-optimize AGENTS.md (330→195 lines, -41%)
Apply Anthropic best practices: only include what prevents Claude from making errors. **Removed** (redundant, Claude infers from code): - Generic glossary (17 lines) - AI concepts, not console-specific - Project structure diagrams (26 lines) - readable from code - Common tasks tutorials (38 lines) - self-evident practices - Verbose code examples (40 lines) - principles suffice - Redundant links (15 lines) - already referenced above **Kept** (critical, non-obvious): - AMF model architecture (console does NOT parse API files) - AmfHelperMixin requirement (never direct JSON access) - Custom events pattern (Shadow DOM isolation) - vendor.js for CodeMirror/crypto (not ES modules) - @web/test-runner (NOT Jest - Shadow DOM issues) - Build strategy (don't build after every change) - mulesoft-git GPG requirement Each remaining line passes: "Would removing this cause Claude to make mistakes?"
1 parent 92c6668 commit 40c6560

1 file changed

Lines changed: 55 additions & 190 deletions

File tree

AGENTS.md

Lines changed: 55 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,74 @@
11
# AGENTS.md - api-console v6
22

3-
> **Purpose**: AI context file for assistants like Claude Code, Cursor, and Copilot.
4-
> Configuration for using AI tools with this open-source project.
3+
AI context file for assistants (Claude Code, Cursor, Copilot) working with this open-source Web Components project.
54

6-
---
7-
8-
## Glossary (For Contributors)
9-
10-
**New to AI coding assistants?** Key concepts:
11-
12-
- **Agent**: AI assistant instance with specific context (e.g., Cursor Composer, Claude Code session)
13-
- **Skill**: Automated workflow (e.g., `/create-pr`, `/update-components`)
14-
- **Rule**: Coding instruction (e.g., "use AmfHelperMixin for AMF queries")
15-
- **Pattern**: Team convention (e.g., custom events for component communication)
16-
17-
**How to contribute**:
18-
- **Skills**: See `.claude/skills/` for examples
19-
- **Patterns**: Document in `docs/team/patterns/`
20-
- **Runbooks**: Add to `docs/team/runbooks/`
21-
22-
**External Resources**:
23-
- [Claude Code Docs](https://docs.anthropic.com/en/docs/agents)
24-
- [Cursor Docs](https://docs.cursor.com)
5+
> **Full docs**: [README.md](./README.md) | **Team patterns**: [docs/team/](./docs/team/)
256
267
---
278

289
## Tech Stack
2910

30-
> **Full documentation**: See [README.md](./README.md) for usage, installation, and deployment.
31-
> **Team patterns**: See [docs/team/](./docs/team/) for architectural decisions and runbooks.
32-
33-
### Core Technologies
34-
- **LitElement 2.x** (base for Web Components)
35-
- **Web Components** (Shadow DOM, custom elements)
36-
- **AMF v4.0+** (API Modeling Framework for RAML/OAS/AsyncAPI/gRPC)
37-
- **Polymer components** (legacy, being migrated to pure LitElement)
38-
- **npm** (package manager, workspace with 18+ packages)
11+
- **LitElement 2.x** + Web Components (Shadow DOM)
12+
- **AMF v4.0+** (API Modeling Framework - RAML/OAS/AsyncAPI/gRPC)
13+
- **npm workspace** (18+ packages, main: `api-console`, components: `api-navigation`, `api-documentation`, etc.)
14+
- **@web/test-runner** (testing, **NOT Jest** - poor Shadow DOM support)
15+
- **Rollup** (builds), **Playwright** (visual regression)
3916

40-
### Build & Dev
41-
- **@web/dev-server** (local development)
42-
- **@web/test-runner** (testing, NOT Jest - poor Shadow DOM support)
43-
- **Rollup** (production builds)
44-
- **Playwright** (visual regression tests)
45-
46-
### Architecture
47-
**Open source multi-package workspace**:
48-
- Main package: `api-console` (orchestrator)
49-
- Components: `api-navigation`, `api-documentation`, `api-request-panel`, etc.
50-
- Each component: separate npm package with own repo (advanced-rest-client org)
51-
52-
---
53-
54-
## Project Structure
55-
56-
### Two Usage Modes
57-
58-
**1. Standalone Application** (`ApiConsoleApp`)
59-
- Full-featured with routing, layout, navigation drawer
60-
- Entry: `src/ApiConsoleApp.js`
61-
- Includes: OAuth components, request panel, responsive layout
62-
- Demo: `demo/standalone/index.html`
63-
64-
**2. Web Component** (`ApiConsole`)
65-
- Lightweight, embeddable
66-
- Entry: `src/ApiConsole.js`
67-
- No routing/layout (host app provides)
68-
- Demo: `demo/element/index.html`
69-
70-
### Component Hierarchy
71-
```
72-
ApiConsoleApp (extends ApiConsole)
73-
└── ApiConsole (extends AmfHelperMixin(LitElement))
74-
├── api-navigation (left drawer)
75-
├── api-documentation (main content)
76-
├── api-request-panel (try it panel)
77-
└── Helper components (OAuth, xhr-simple-request)
78-
```
17+
### Two Entry Points
18+
- `src/ApiConsoleApp.js` - Standalone app (routing, layout, OAuth)
19+
- `src/ApiConsole.js` - Embeddable component (no routing/layout)
7920

8021
---
8122

8223
## AMF Model Architecture (CRITICAL)
8324

84-
**API Console does NOT parse API files directly. It requires pre-generated AMF models.**
25+
**IMPORTANT**: API Console does **NOT** parse API files directly. It requires **pre-generated AMF models**.
8526

8627
### What is AMF?
87-
- MuleSoft's unified model for RAML, OAS, AsyncAPI, gRPC
88-
- Version: AMF v4.0+ (AMF model v2)
89-
- Format: JSON-LD
28+
MuleSoft's unified model for RAML, OAS, AsyncAPI, gRPC. Format: JSON-LD (AMF v4.0+).
9029

91-
### Model Generation
30+
### Generate Models
9231
```bash
93-
# 1. Define APIs in demo/apis.json
94-
{ "path/to/api.raml": "RAML 1.0" }
95-
32+
# 1. Define APIs in demo/apis.json: { "path/to/api.raml": "RAML 1.0" }
9633
# 2. Generate models
9734
npm run build:models
98-
9935
# 3. Models saved to demo/models/*.json
10036
```
10137

102-
### Model Flow
103-
```
104-
API Spec (RAML/OAS/AsyncAPI/gRPC)
105-
→ AMF Parser (amf-client-js)
106-
→ AMF Model (JSON-LD)
107-
→ api-console `amf` property
108-
→ AmfHelperMixin provides querying
109-
→ Renders UI
110-
```
111-
112-
### Loading Models
38+
### Load Models
11339
```javascript
114-
// Option 1: Direct model
115-
const model = await generateApiModel();
116-
apiConsole.amf = model;
40+
// Direct model
41+
apiConsole.amf = await generateApiModel();
11742

118-
// Option 2: URL to JSON
43+
// URL to JSON
11944
apiConsole.modelLocation = 'models/my-api.json';
12045
```
12146

12247
---
12348

124-
## Coding Patterns (Critical)
49+
## Coding Patterns (CRITICAL)
12550

12651
### 1. Component Communication
12752

128-
**IMPORTANT**: Use custom events for parent communication, NOT direct method calls.
53+
**IMPORTANT**: Use custom events, **NOT** direct method calls.
12954

13055
```javascript
131-
// ✅ GOOD: Custom event
56+
// ✅ GOOD: Custom event (bubbles across Shadow DOM)
13257
this.dispatchEvent(new CustomEvent('api-navigation-selection-changed', {
13358
bubbles: true,
13459
composed: true,
13560
detail: { selected, type }
13661
}));
13762

138-
// ❌ BAD: Direct parent method call
139-
this.parentElement.onNavigationChange(selected); // Breaks encapsulation
63+
// ❌ BAD: Direct method call (breaks encapsulation)
64+
this.parentElement.onNavigationChange(selected);
14065
```
14166

14267
**Why**: Shadow DOM isolation requires composed events to bubble across boundaries.
14368

14469
### 2. AMF Queries
14570

146-
**IMPORTANT**: Use AmfHelperMixin utilities, NOT direct JSON access.
71+
**IMPORTANT**: Use AmfHelperMixin utilities, **NOT** direct JSON access.
14772

14873
```javascript
14974
// ✅ GOOD: AmfHelperMixin
@@ -155,37 +80,27 @@ class MyComponent extends AmfHelperMixin(LitElement) {
15580
}
15681
}
15782

158-
// ❌ BAD: Direct JSON access
83+
// ❌ BAD: Direct JSON access (structure changes)
15984
const endpoints = model['@graph'][0]['http://raml.org/vocabularies/http#endpoint'];
16085
```
16186

162-
**Why**: AMF model structure can change; helpers abstract this complexity.
87+
**Why**: AMF model structure can change; helpers abstract this.
16388

16489
### 3. Shadow DOM Styling
16590

166-
**Use CSS custom properties for theming**:
167-
91+
Use CSS custom properties for theming:
16892
```css
16993
:host {
17094
--api-console-primary-color: #00A1E0;
171-
--api-console-background-color: #ffffff;
17295
}
17396
```
17497

175-
**Anti-pattern**:
176-
```css
177-
/* ❌ BAD: Direct DOM manipulation */
178-
document.querySelector('#api-console').style.color = 'red';
179-
```
98+
**Never** manipulate DOM styles directly (`document.querySelector('#api-console').style...`).
18099

181100
### 4. Lazy Loading
182101

183-
Large APIs benefit from lazy loading:
102+
For large APIs, lazy load components on demand:
184103
```javascript
185-
// Load navigation immediately
186-
<api-navigation .amf="${this.amf}"></api-navigation>
187-
188-
// Lazy load documentation on selection
189104
if (this.selectedShape) {
190105
import('@api-components/api-documentation')
191106
.then(() => this._renderDocumentation());
@@ -196,57 +111,44 @@ if (this.selectedShape) {
196111

197112
## Testing Strategy
198113

199-
### Unit Tests
200-
201-
**Run tests**:
114+
### Commands
202115
```bash
203116
npm test # All tests (chromium + firefox)
204-
npm run test:watch # Watch mode (chromium only)
117+
npm run test:watch # Watch mode
118+
npm run test:visual # Visual regression
119+
npm run test:visual:update # Update baselines (after intentional UI changes)
205120
```
206121

207-
**Write tests with @web/test-runner** (NOT Jest):
122+
### Write Tests with @web/test-runner
123+
**IMPORTANT**: Use @web/test-runner, **NOT Jest** (poor Shadow DOM support).
124+
208125
```javascript
209126
import { fixture, expect } from '@open-wc/testing';
210-
import '../api-console.js';
211-
212127
it('renders navigation', async () => {
213128
const el = await fixture('<api-console></api-console>');
214-
const nav = el.shadowRoot.querySelector('api-navigation');
215-
expect(nav).to.exist;
129+
expect(el.shadowRoot.querySelector('api-navigation')).to.exist;
216130
});
217131
```
218132

219-
### Visual Regression
220-
221-
```bash
222-
npm run test:visual # Run visual tests
223-
npm run test:visual:update # Update baselines (after intentional UI changes)
224-
```
225-
226-
**When to update baselines**:
227-
- After intentional styling changes
228-
- After Shadow DOM structure changes
229-
- NOT after accidental visual regressions (fix the bug instead)
230-
231133
---
232134

233135
## Anti-Patterns
234136

235137
### Code
236138
- **IMPORTANT: Never parse API files directly** → Use AMF models
237-
- **IMPORTANT: Never use direct method calls between components** → Use custom events
238139
- **IMPORTANT: Never access AMF JSON directly** → Use AmfHelperMixin
140+
- **IMPORTANT: Never use direct method calls between components** → Use custom events
141+
- **Never use Jest** → Use @web/test-runner
239142
- **Never use `any` in TypeScript** → Proper types
240-
- **Never use Jest** → Use @web/test-runner (better Shadow DOM support)
241143

242144
### Dependencies
243-
- **Never import CodeMirror/crypto as ES modules** → Use vendor.js (non-ES6 dependencies)
145+
- **Never import CodeMirror/crypto as ES modules** → Use `vendor.js` (non-ES6 dependencies bundled separately)
244146
- **Never modify AMF model structure** → External standard, use helpers
245147

246148
### Git
247-
- **Never commit directly to master** → Always create branch first
149+
- **Never commit directly to master** → Always create branch first (`fix/W-XXXXXXXX-desc` or `build/X.X.X`)
248150
- **Never skip GPG signing** → Run `mulesoft-git` before committing
249-
- **Never commit large models** → Generate locally with `npm run build:models`
151+
- **Never commit large models** → Generate locally (`npm run build:models`)
250152

251153
---
252154

@@ -258,73 +160,36 @@ npm run test:visual:update # Update baselines (after intentional UI changes)
258160
1. Implement feature
259161
2. Write tests
260162
3. Run `npm test` (once)
261-
4. Run `npm run build` (if needed)
262-
5. Fix compilation errors if any
263-
264-
**Exceptions** (when to build early):
265-
- User explicitly asks to verify compilation
266-
- Before creating final PR
267-
- After major changes to component interfaces
163+
4. Run `npm run build` only when: user asks explicitly, before PR, or after major type changes
268164

269165
---
270166

271-
## Common Tasks
272-
273-
### Add New Component Property
274-
275-
1. Define property in component:
276-
```javascript
277-
static get properties() {
278-
return {
279-
selectedShape: { type: String }
280-
};
281-
}
282-
```
283-
284-
2. Add to AMF helpers if needed
285-
3. Write tests for property changes
286-
4. Update TypeScript definitions if applicable
287-
288-
### Update Component from Workspace
167+
## Quick Commands
289168

290169
```bash
291-
# Update single component
292-
npm update @api-components/api-navigation
293-
294-
# Update all components
295-
npm update
296-
297-
# Verify package-lock.json changes
298-
git diff package-lock.json
170+
npm run prepare # Build vendor.js + generate AMF models (required after clone)
171+
npm start # Dev server
172+
npm test # Run all tests
173+
npm run build # Production build
174+
npm run build:models # Generate AMF models from demo/apis.json
175+
npm update @api-components/* # Update workspace components
299176
```
300177

301-
### Release Process
302-
303-
See [docs/team/runbooks/api-console-v6-release.md](./docs/team/runbooks/api-console-v6-release.md) for complete release workflow.
304-
305-
**Branch naming**:
306-
- Component fixes: `fix/W-XXXXXXXX-description`
307-
- Console release: `build/X.X.X`
308-
309178
---
310179

311-
## Links & Resources
312-
313-
### Quick Start
314-
- **Installation**: See [README.md](./README.md) sections "Preview and development" and "Working with AMF model"
315-
- **Full docs**: https://docs.api-console.io
180+
## Links
316181

317182
### Team Documentation
318-
- **Runbooks**: [docs/team/runbooks/](./docs/team/runbooks/) - Release process, debugging, troubleshooting
183+
- **Runbooks**: [docs/team/runbooks/](./docs/team/runbooks/) - Release process, debugging
319184
- **Patterns**: [docs/team/patterns/](./docs/team/patterns/) - Web Component communication, architecture
320-
- **Configs**: [docs/team/configs/](./docs/team/configs/) - Git setup, IDE settings
185+
- **Configs**: [docs/team/configs/](./docs/team/configs/) - Git GPG setup, IDE settings
321186

322187
### External Resources
188+
- **Full docs**: https://docs.api-console.io
323189
- **AMF**: https://github.com/aml-org/amf
324190
- **LitElement v2**: https://lit.dev/docs/v2/
325-
- **Web Components**: https://developer.mozilla.org/en-US/docs/Web/Web_Components
326191
- **@web/test-runner**: https://modern-web.dev/docs/test-runner/overview/
327192

328193
---
329194

330-
**Last Updated**: 2026-03-20 (Migrated from CLAUDE.md to AGENTS.md)
195+
**Last Updated**: 2026-03-20 (Ultra-optimized for AI context efficiency)

0 commit comments

Comments
 (0)