Skip to content

Commit 35cf0ca

Browse files
PaulDuvallclaude
andcommitted
feat: simplify centralized rules with sync-based approach
Replace complex gateway pattern with simple Git-based sync strategy that: - Auto-generates CLAUDE.md, AGENTS.md, .cursorrules from central repository - Auto-detects language (Python, TypeScript, Go, etc.) and framework (React, Django, etc.) - Works offline after initial sync (no API calls required) - Compatible with all AI assistants (Claude Code, Cursor, Gemini) - Consolidates documentation into single comprehensive README Changes: - New sync-strategy/ with sync-ai-rules.sh (auto-detection & generation) - Quick-start helper: create-central-repo.sh - Example rules: Python, React, universal security/testing standards - Moved old gateway approach to gateway-strategy/ (advanced use cases) - Updated experiments/README.md pattern description - Consolidated centralized-rules/README.md (removed duplicate docs) Benefits over old approach: - 100 lines bash vs 500+ lines TypeScript - No Node.js service to deploy - Works with standard AI config files - Language/framework-aware rule selection 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 089f07a commit 35cf0ca

14 files changed

Lines changed: 2103 additions & 76 deletions

File tree

experiments/examples/centralized-rules/README.md

Lines changed: 416 additions & 76 deletions
Large diffs are not rendered by default.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Centralized Rules Example
2+
3+
This example demonstrates the three-layer architecture for centralizing AI rules across an organization using the Claude SDK.
4+
5+
## Architecture
6+
7+
```
8+
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
9+
│ ai-dev-cli │ ──► │ ai-gateway │ ──► │ Claude API │
10+
└─────────────┘ └─────────────┘ └─────────────┘
11+
│ │
12+
│ ┌──────┴──────┐
13+
│ │ Org Rules │
14+
│ │ Logging │
15+
│ │ Filters │
16+
│ └─────────────┘
17+
18+
└──────────► @yourorg/org-ai-client (alternative)
19+
```
20+
21+
## Components
22+
23+
### 1. ai-gateway/
24+
25+
Internal service that owns all org rules and calls the Claude API.
26+
27+
**Features**:
28+
- Centralized system prompts with org rules
29+
- Request/response logging
30+
- Input/output filtering hooks
31+
32+
### 2. org-ai-client/
33+
34+
Shared SDK wrapper that embeds org rules. Use this if you don't want a network service yet.
35+
36+
**Features**:
37+
- Org rules baked into system prompts
38+
- Consistent interface across all repos
39+
- Version-controlled rule updates
40+
41+
### 3. ai-dev-cli/
42+
43+
Developer CLI that calls the gateway or wrapper library.
44+
45+
**Features**:
46+
- Simple commands: `ai-dev plan`, `ai-dev refactor`
47+
- Auto-detects repo context
48+
- Consistent UX across tools
49+
50+
## Setup
51+
52+
### Prerequisites
53+
54+
- Node.js 18+
55+
- `ANTHROPIC_API_KEY` environment variable
56+
57+
### Install dependencies
58+
59+
```bash
60+
cd ai-gateway && npm install
61+
cd ../org-ai-client && npm install
62+
cd ../ai-dev-cli && npm install
63+
```
64+
65+
### Run the gateway
66+
67+
```bash
68+
cd ai-gateway
69+
npm start
70+
# Gateway running on http://localhost:3000
71+
```
72+
73+
### Use the CLI
74+
75+
```bash
76+
cd ai-dev-cli
77+
npm link
78+
ai-dev plan "Implement idempotent refund API"
79+
```
80+
81+
## Customization
82+
83+
### Modify org rules
84+
85+
Edit the system prompt in `ai-gateway/src/claudeClient.ts` or `org-ai-client/src/index.ts`:
86+
87+
```typescript
88+
const systemPrompt = `
89+
You are the org AI pair programmer.
90+
Follow ORG RULES v1.4:
91+
- Use spec-first development.
92+
- Your custom rules here...
93+
`;
94+
```
95+
96+
### Add input/output filters
97+
98+
Extend the gateway with validation:
99+
100+
```typescript
101+
// Before calling Claude
102+
if (containsSecrets(input)) {
103+
throw new Error("Input contains secrets");
104+
}
105+
106+
// After receiving response
107+
if (containsBannedPatterns(response)) {
108+
throw new Error("Response violates policy");
109+
}
110+
```
111+
112+
### Integrate policy-as-code
113+
114+
Add OPA or Cedar policy checks:
115+
116+
```typescript
117+
const allowed = await opa.evaluate("ai/task_allowed", {
118+
repo: input.repo,
119+
taskType: input.taskType,
120+
user: req.user
121+
});
122+
```

experiments/examples/centralized-rules/ai-dev-cli/package.json renamed to experiments/examples/centralized-rules/gateway-strategy/ai-dev-cli/package.json

File renamed without changes.

experiments/examples/centralized-rules/ai-dev-cli/src/cli.ts renamed to experiments/examples/centralized-rules/gateway-strategy/ai-dev-cli/src/cli.ts

File renamed without changes.

experiments/examples/centralized-rules/ai-gateway/package.json renamed to experiments/examples/centralized-rules/gateway-strategy/ai-gateway/package.json

File renamed without changes.

experiments/examples/centralized-rules/ai-gateway/src/claudeClient.ts renamed to experiments/examples/centralized-rules/gateway-strategy/ai-gateway/src/claudeClient.ts

File renamed without changes.

experiments/examples/centralized-rules/ai-gateway/src/server.ts renamed to experiments/examples/centralized-rules/gateway-strategy/ai-gateway/src/server.ts

File renamed without changes.

experiments/examples/centralized-rules/org-ai-client/package.json renamed to experiments/examples/centralized-rules/gateway-strategy/org-ai-client/package.json

File renamed without changes.

experiments/examples/centralized-rules/org-ai-client/src/index.ts renamed to experiments/examples/centralized-rules/gateway-strategy/org-ai-client/src/index.ts

File renamed without changes.

0 commit comments

Comments
 (0)