Skip to content

Commit 8613254

Browse files
committed
Add AGENTS.md file
1 parent 8259640 commit 8613254

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

AGENTS.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# AGENTS.md
2+
3+
## Project Overview
4+
5+
This is a secure-by-design template for building LLM-powered agents in Node.js + TypeScript. The template enforces security patterns to resist prompt injection, privilege escalation, and unsafe tool use through:
6+
7+
- **Dual LLM isolation** - separating untrusted text processing from tool execution
8+
- **Quarantined Readers** - convert raw text to strict JSON schemas without tool access
9+
- **Orchestrator/Reducers** - process sanitized data and handle tool execution
10+
- **Context minimization** - strips prompts/raw data before tool use
11+
- **Sandboxed execution** - tests run in network-isolated Docker containers
12+
13+
## Setup Commands
14+
15+
- Install dependencies: `npm ci`
16+
- Type checking: `npm run typecheck`
17+
- Linting: `npm run lint`
18+
- Format code: `npm run format`
19+
- Run tests: `npm test`
20+
- Watch tests: `npm run test:watch`
21+
22+
## Security Validation Commands
23+
24+
- Validate schemas: `npm run secure:schemas`
25+
- Validate file paths: `npm run secure:paths`
26+
- Run full CI locally: Use VS Code task "Secure Agents: Run CI Test (local container)"
27+
28+
## Code Style Guidelines
29+
30+
- **TypeScript strict mode** - all code must pass strict type checking
31+
- **ESLint rules** - enforced via `eslint.config.js` with TypeScript ESLint plugin
32+
- **Prettier formatting** - consistent code formatting
33+
- **No explicit `any` types** - use proper typing (warns on `any`)
34+
- **ES modules** - use `import/export` syntax (type: "module" in package.json)
35+
36+
## Architecture Patterns
37+
38+
### Required Security Patterns
39+
40+
1. **Plan → Patch workflow**:
41+
- Always create a PLAN (YAML) in `plans/` directory first
42+
- Then implement matching code changes
43+
- Plans must specify trust boundaries and tool scope
44+
45+
2. **Agent Structure**:
46+
47+
```
48+
agents/<agent-name>/
49+
├── reader/
50+
│ └── index.ts # Quarantined reader (no tools, outputs JSON schema)
51+
└── orchestrator/
52+
└── reducer.ts # Orchestrator/reducer (can use tools)
53+
```
54+
55+
3. **Trust Boundaries**:
56+
- Readers: see raw untrusted text, output only structured JSON
57+
- Orchestrators: consume sanitized JSON, may call tools
58+
- No free text pass-through between layers
59+
60+
## Testing Instructions
61+
62+
- **Test structure**: `tests/<agent-name>/<agent-name>.test.ts`
63+
- **Required tests**:
64+
- Reader always produces valid schema (never leaks raw text)
65+
- Orchestrator handles sanitized inputs correctly
66+
- Adversarial prompts don't break the pipeline
67+
- **Test runner**: Vitest with TypeScript support
68+
- **Network isolation**: All CI tests run in Docker with `--network=none`
69+
70+
## File Organization
71+
72+
```
73+
/
74+
├── agents/ # Agent implementations
75+
├── plans/ # YAML plan definitions
76+
├── schemas/ # JSON schemas for validation
77+
├── tests/ # Test files matching agent structure
78+
├── scripts/ # Validation and CI scripts
79+
└── .github/ # CI/CD workflows and Docker configs
80+
```
81+
82+
## Security Considerations
83+
84+
### Path Restrictions
85+
86+
The following paths require `security-approved` label on PRs:
87+
88+
- `.github/workflows/`
89+
- `.github/actions/`
90+
- `.github/docker/`
91+
- `infra/`
92+
- `deploy/`
93+
- `scripts/prod/`
94+
- Lock files (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`)
95+
96+
### Allowed Development Paths
97+
98+
- `agents/` - agent implementations
99+
- `tests/` - test files
100+
- `plans/` - agent plans
101+
- `schemas/` - validation schemas
102+
- `scripts/` - development scripts (non-production)
103+
104+
## CI/CD Pipeline
105+
106+
### GitHub Actions Workflow
107+
108+
1. **Path validation** - ensures only approved paths are modified
109+
2. **Schema validation** - validates YAML plans and JSON schemas
110+
3. **Isolated testing** - runs in Docker with no network access
111+
112+
### Local Development
113+
114+
- Use VS Code tasks for validation
115+
- Pre-commit hooks validate schemas and paths
116+
- Docker-based CI can be run locally
117+
118+
## Adding New Agents
119+
120+
1. **Create plan**: `plans/<agent-name>.yml` with security patterns defined
121+
2. **Validate plan**: `npm run secure:schemas`
122+
3. **Implement reader**: `agents/<agent-name>/reader/index.ts` (no tools)
123+
4. **Implement orchestrator**: `agents/<agent-name>/orchestrator/reducer.ts` (tools allowed)
124+
5. **Add tests**: `tests/<agent-name>/<agent-name>.test.ts`
125+
6. **Validate paths**: `npm run secure:paths`
126+
7. **Run full test suite**: `npm test`
127+
128+
## Common Patterns
129+
130+
### Reader Implementation
131+
132+
```typescript
133+
// Convert untrusted text to bounded schema - NO TOOLS
134+
export function processRawText(input: string): StructuredOutput {
135+
// Parse and validate against strict schema
136+
// Never pass through free text
137+
return {
138+
/* structured data only */
139+
};
140+
}
141+
```
142+
143+
### Orchestrator Implementation
144+
145+
```typescript
146+
// Process sanitized inputs - TOOLS ALLOWED
147+
export function orchestrate(sanitizedInputs: StructuredOutput[]): Result {
148+
// Can call external APIs, file system, etc.
149+
// Context has been minimized and sanitized
150+
return processWithTools(sanitizedInputs);
151+
}
152+
```
153+
154+
## Troubleshooting
155+
156+
### Docker Build Issues
157+
158+
- Check Node.js/npm compatibility in `.github/docker/ci.Dockerfile`
159+
- Ensure ESLint version compatibility with TypeScript ESLint plugins
160+
- Python packages may need `--break-system-packages` flag
161+
162+
### Schema Validation Failures
163+
164+
- Ensure YAML plans follow `schemas/plan.schema.json`
165+
- Check that all required fields are present
166+
- Validate JSON syntax and structure
167+
168+
### Path Validation Failures
169+
170+
- Check if modified files are in restricted paths
171+
- Add `security-approved` label for infrastructure changes
172+
- Ensure new files follow approved directory structure

0 commit comments

Comments
 (0)