Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

airules_en.md

maoxiaoyue edited this page May 14, 2026 · 1 revision

pkg/airules -- Cross-AI Tool Configuration File Generation

v0.8.5+ This package is a new feature added in HypGo v0.8.5 and is not available in v0.8.1.

Automatically generates configuration files for mainstream AI coding tools, enabling Codex, Gemini, Cursor, Windsurf, GitHub Copilot, and other tools to immediately understand framework conventions when opening a HypGo project, saving significant tokens.

Why Is This Needed?

Each AI coding tool has its own project configuration file format:

Tool Configuration File
Codex CLI / Cursor / Aider / OpenHands AGENTS.md
Google Gemini CLI / AI Studio GEMINI.md
GitHub Copilot .github/copilot-instructions.md
Cursor (new format) .cursor/rules/*.mdc
Windsurf .windsurf/rules/*.md

Without these files, AI tools start from scratch understanding your project every time -- they don't know to use router.Schema() to register routes, don't know about the Error Catalog, and don't know they can use contract.TestAll() for validation.

hyp ai-rules generates all configuration files with one command, with unified content and automatic maintenance.

Quick Start

CLI Usage

# Generate all AI tool configuration files
hyp ai-rules
# Generate only specific tool configuration files
hyp ai-rules --only agents,gemini
# Preview without writing (dry-run)
hyp ai-rules --dry-run
# Specify project root directory
hyp ai-rules --dir ./myproject

Programmatic Usage

import (
 "github.com/maoxiaoyue/hypgo/pkg/airules"
 "github.com/maoxiaoyue/hypgo/pkg/manifest"
)
// Prepare manifest (can be nil, static conventions will still be generated)
m := &manifest.Manifest{
 Routes: []manifest.RouteManifest{
 {Method: "POST", Path: "/api/users", Summary: "Create user"},
 },
}
// Generate all configuration files in the project root directory
targets := airules.AllTargets()
results, err := airules.GenerateAll(".", targets, m, false)
// Generate only specific tools
targets = airules.FilterTargets(airules.AllTargets(), "agents,gemini")
results, err = airules.GenerateAll(".", targets, m, false)

Generated Files

AGENTS.md

Placed in the project root directory. Supported by the most tools (Codex CLI, Cursor, Continue.dev, Aider, OpenHands).

AGENTS.md
├── Framework Framework name, version, Go version
├── Project Structure Directory structure description
├── Key Conventions Schema-first / Typed Errors / Contract Testing
├── Build & Test go build / go test commands
├── AI Collaboration Read .hyp/context.yaml first, hyp impact, hyp chkcomment
└── Current Routes Route table dynamically injected from manifest (if available)

GEMINI.md

Same format as AGENTS.md, placed in the project root directory. Natively read by Google Gemini CLI and AI Studio.

.github/copilot-instructions.md

Same format as AGENTS.md, placed in the .github/ directory. Read by GitHub Copilot (VS Code, JetBrains).

.cursor/rules/hypgo.mdc

Cursor new format, with frontmatter:

---
description: HypGo framework conventions and AI collaboration rules
globs: "**/*.go"
alwaysApply: true
---

alwaysApply: true ensures the rules are loaded every time a Go file is opened.

.windsurf/rules/hypgo.md

Windsurf format. Content is the same as other tools, but automatically kept within 6,000 characters (Windsurf single-file limit). Route tables are truncated when exceeded.

Dynamic Route Injection

If .hyp/context.yaml exists in the project root directory (generated by hyp context or AutoSync), hyp ai-rules reads route information from it and injects it into configuration files:

## Current Routes
| Method | Path | Summary |
|--------|------|---------|
| GET | /health | Health check |
| POST | /api/users | Create user |
| GET | /api/users/:id | Get user by ID |

This lets AI tools know not only framework conventions, but also which APIs the project currently has.

Recommended workflow:

# 1. Generate manifest first
hyp context -o .hyp/context.yaml
# 2. Then generate AI configuration files (will include route information)
hyp ai-rules

Safe Overwrite Mechanism

All auto-generated files contain a marker:

<!-- auto-generated by hyp ai-rules -->

Overwrite rules:

File Status Behavior
Does not exist Create new file
Exists with marker Overwrite (update content)
Exists without marker Skip (protect manually modified version)

If you manually created AGENTS.md and want hyp ai-rules to take over, simply add <!-- auto-generated by hyp ai-rules --> at the beginning of the file.

API Reference

AllTargets()

func AllTargets() []Target

Returns all supported AI tool configuration file targets (5 total).

FilterTargets()

func FilterTargets(targets []Target, names string) []Target

Filters targets by comma-separated names. Empty string means all.

Available names: agents, gemini, copilot, cursor, windsurf

GenerateAll()

func GenerateAll(dir string, targets []Target, m *manifest.Manifest, dryRun bool) ([]Result, error)

Generates configuration files in the specified directory. m can be nil (only static conventions are generated). When dryRun is true, files are not written and Result contains preview content.

Result

type Result struct {
 Path string // File path
 Status Status // created / skipped / dry-run / error
 Message string // Error or skip reason
 Content string // Preview content during dry-run
}

Relationship with Other AI Collaboration Features

hyp context -> Generates .hyp/context.yaml (project structure manifest)
hyp ai-rules -> Reads manifest + generates AI tool configuration files
 |
AGENTS.md / GEMINI.md / copilot-instructions.md / .cursor / .windsurf
 |
AI tool opens project -> Immediately knows HypGo conventions -> Saves tokens

CLAUDE.md is not in the generation scope (maintained manually by the user), but Claude Code also reads AGENTS.md.

HypGo

繁體中文 | English


中文文件

設計文件

套件

AI 協作工具鏈

CLI 命令


English Docs

Design Docs

Packages

AI Collaboration Toolchain

CLI Commands

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /