codex
Copilot instructions9 starsChanged 8 months agoMITView on GitHub
Codex is a full-stack TypeScript monorepo using npm workspaces with three packages: - Root (/) - Workspace orchestration, shared devDependencies - Server (/server) - Express REST API on port 3001 + MCP server on port 3002 - Client (/client) - React SPA on port 3000 (Vite dev server proxies /api to server) Data flow: React components → api.ts service → Express routes → FileSystemService → /data directory (markdown files). MCP flow: AI agents → MCP server (port 3002) → MCP…
- Reads credentials
In this repository2 other files it gives its agents.
- frontend-designSkill
- react-ui-patternsSkill
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
28 rules. About 0 are common, 10 are distinctive, and 18 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
18
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 27
Tool registration pattern: All tools imported in server/src/mcp/tools/registry.ts and wrapped with asRegisteredTool().
- Very specific: line 67
All API calls go through client/src/services/api.ts{api,auth,mcp}.test.ts, uses isolated test-data/ or test-data-mcp/ directories
- Very specific: line 71
Test count verification: When adding MCP tools, update mcp.test.ts to expect correct tool count (currently 16)
- Very specific: line 76
If you need to run tests via make test, be sure to run from the root directory.
- Very specific: line 108
Create tool in server/src/mcp/tools/{category}.ts using defineTool() helper
- Very specific: line 112
Add to tools array using asRegisteredTool()
- Very specific: line 113
Add test in server/tests/mcp.test.ts and update tool count expectation
- Very specific: line 114
Path security: Always use validatePath() for user-provided paths to prevent traversal attacks
- Very specific: line 117
Create controller function in server/src/controllers/
- Very specific: line 118
Add route in server/src/routes/ and import in server/src/index.ts
- Very specific: line 119
Add client method in client/src/services/api.ts
- Very specific: line 120
Add test in server/tests/api.test.ts
- Very specific: line 121
Update API docs in GET /api handler (server/src/index.ts)
- Very specific: line 124
Create Component.tsx and Component.css in client/src/components/ (AUTH_PASSWORD, MCP_API_KEY, SESSION_SECRET)
- Very specific: line 125
Path traversal protection: Always use validatePath() helper (see server/src/mcp/tools/attachments.ts) for user-provided file paths
- Distinctive: line 126
Input validation: Use Zod schemas for all MCP tool inputs and API request validation
- Distinctive: line 127
Keep dependencies up to date (monitored by Dependabot)
- Very specific: line 134
Never use
anytype: - Use unknown for truly dynamic types, then narrow with type guards - Very specific: line 135
Always enable strict mode in tsconfig.json
- Distinctive: line 136
Prefer interfaces over type aliases for object shapes
- Distinctive: line 137
Use proper typing for all function parameters and return values
- Distinctive: line 140
Never commit secrets: - Use environment variables for sensitive data
- Distinctive: line 146
Write tests before pushing code
- Distinctive: line 149
Use descriptive test names that explain the behavior being tested
- Distinctive: line 160
Use modern Git commands instead of legacy git checkout:
- Distinctive: line 205
Use base64 encoding for file content transfer (MCP limitation)
- Very specific: line 207
Always validate paths and handle ENOENT errors gracefully
- Distinctive: line 213
Never suggest or document
git checkout: - always use git switch for branches and git restore for files.
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Codex - AI Coding Instructions
Architecture Overview
Codex is a full-stack TypeScript monorepo using npm workspaces with three packages:
- Root (
/) - Workspace orchestration, shared devDependencies - Server (
/server) - Express REST API on port 3001 + MCP server on port 3002 - Client (
/client) - React SPA on port 3000 (Vite dev server proxies/apito server)
Data flow: React components → api.ts service → Express routes → FileSystemService → /data directory (markdown files).
MCP flow: AI agents → MCP server (port 3002) → MCP tools → FileSystemService → /data directory.
Production mode: Express serves both API and static React build from port 3001 only (see server/src/index.ts static file serving section).
MCP Server Architecture
The Model Context Protocol (MCP) server allows AI agents to interact with Codex programmatically:
- Location:
server/src/mcp/- Separate from REST API - Port: 3002 (configurable via
MCP_PORT) - Protocol: HTTP-based MCP with session management
- Tools: 16 registered tools (pages, folders, attachments)
- Resources: Access pages via
codex://page/{path}URIs - Security: API key authentication via
MCP_API_KEYenvironment variable
Tool registration pattern: All tools imported in server/src/mcp/tools/registry.ts and wrapped with asRegisteredTool(). Each tool uses Zod schemas for input validation and returns structured ToolResult objects.
Critical Commands
make dev # Start both server (3001) and client (3000)
make test # Run all tests (server: Jest, client: Vitest)
make install # Fresh install all dependencies from root
make build # Build both server and client for productionMCP Development:
MCP_ENABLED=true npm run dev -w server # Start server with MCP on port 3002
npm run dev:mcp -w server # Dedicated MCP dev scriptImportant: Dependencies install at the root level only. Run
npm ciormake installfrom root, not from subdirectories. The rootpackage-lock.jsonmanages all workspace dependencies.
Docker Deployment
docker compose up -d --build # Build and run (port 3001 serves both UI and API)
docker compose logs -f codex # View logsAuthentication caveat: Session cookies use secure: "auto". For local Docker testing without HTTPS, run passwordless (comment out AUTH_PASSWORD). For production, deploy behind a reverse proxy with TRUST_PROXY=true to respect X-Forwarded-Proto headers.
Project Conventions
API Pattern
Routes follow REST conventions in server/src/routes/. Each route delegates to a controller, which calls FileSystemService:
routes/*.ts → controllers/*Controller.ts → services/fileSystem.tsSelf-documenting API available at GET /api returns all endpoints with examples.
Frontend Pattern
- All API calls go through
client/src/services/api.ts{api,auth,mcp}.test.ts, uses isolatedtest-data/ortest-data-mcp/directories - Client tests: Vitest + React Testing Library, co-located with components
- MCP tests: Comprehensive unit and integration tests in
server/tests/mcp.test.ts - Tests must clean up: server tests recreate
TEST_DATA_DIRinbeforeEach - Test count verification: When adding MCP tools, update
mcp.test.tsto expect correct tool count (currently 16) - CSS uses custom properties from
App.cssfor theming:var(--bg-primary),var(--text-primary), etc. - Keyboard navigation uses arrow keys AND vim-style
j/k(seeFolderTree.tsx,PageList.tsx,Search.tsx)
Testing
- If you need to run tests via
make test, be sure to run from the root directory. - Server tests: Jest + supertest in
server/tests/api.test.ts, uses isolatedtest-data/directory - Client tests: Vitest + React Testing Library, co-located with components
- Tests must clean up: server tests recreate
TEST_DATA_DIRinbeforeEach
TypeScript
- Server:
tsconfig.jsonincludes"types": ["node", "jest"]for test support - Client: Standard Vite/React config with strict mode
- Shared interfaces (
FolderNode,FileNode,Page) defined in client, server has own copy infileSystem.ts
Key Files
| Purpose | Location |
| AEST API routes | server/src/routes/{folders,pages,attachments,auth}.ts |
| MCP tool registry | server/src/mcp/tools/registry.ts |
| MCP tool implementations | server/src/mcp/tools/{pages,folders,attachments}.ts |
| MCP server | server/src/mcp/server.ts |
| MCP configuration | server/src/mcp/config.ts |
| Type definitions (client) | client/src/types/index.ts |
| Type definitions (MCP) | server/src/mcp/tools/types.ts |
| Theme variables | client/src/App.css (:root and [data-theme="dark"]) |
| Test setup | server/tests/{api,auth,mcp}/types/index.ts |
| Theme variables | client/src/App.css (:root and [data-theme="dark"]) |
| Test setup | server/tests/api.test.ts, client/src/test/setup.ts |
| Docker config | Dockerfile, docker-compose.yml |
| CI/CD workflows | .github/workflows/{ci.yml,release.yml} |
Adding Features
New API endpoint:
- AddMCP tool**:
- Create tool in
server/src/mcp/tools/{category}.tsusingdefineTool()helper - Define Zod schema for input validation
- Implement handler that returns
ToolResultwithcontentarray - Export tool and import in
server/src/mcp/tools/registry.ts - Add to
toolsarray usingasRegisteredTool() - Add test in
server/tests/mcp.test.tsand update tool count expectation - Path security: Always use
validatePath()for user-provided paths to prevent traversal attacks
**New method to FileSystemService in server/src/services/fileSystem.ts
2. Create controller function in server/src/controllers/
3. Add route in server/src/routes/ and import in server/src/index.ts
4. Add client method in client/src/services/api.ts
5. Add test in server/tests/api.test.ts
6. Update API docs in GET /api handler (server/src/index.ts)
New UI component:
- Create
Component.tsxandComponent.cssinclient/src/components/(AUTH_PASSWORD,MCP_API_KEY,SESSION_SECRET)
- Path traversal protection: Always use
validatePath()helper (seeserver/src/mcp/tools/attachments.ts) for user-provided file paths - Input validation: Use Zod schemas for all MCP tool inputs and API request validation
- Keep dependencies up to date (monitored by Dependabot)
- CSP directives configured in
server/src/index.tshelmet middleware - MCP authentication: Require
MCP_API_KEYin production; verify viaAuthorization: BearerorX-Api-Keyheaders
Code Quality Standards
TypeScript
- Never use
anytype - Useunknownfor truly dynamic types, then narrow with type guards - Always enable strict mode in tsconfig.json
- Prefer interfaces over type aliases for object shapes
- Use proper typing for all function parameters and return values
Security
- Never commit secrets - Use environment variables for sensitive data
- Sanitize file paths and validate user input to prevent path traversal attacks
- Keep dependencies up to date (monitored by Dependabot)
- CSP directives configured in
server/src/index.tshelmet middleware
Testing
- Write tests before pushing code
- Maintain test coverage for critical paths
- Tests must be deterministic and clean up after themselves
- Use descriptive test names that explain the behavior being tested
Boundaries - Do NOT Modify
- Never modify files in
node_modules/ordist/directories - Never modify the root
package-lock.jsondirectly (usenpm installcommands) - Do not remove existing tests unless they are explicitly broken by intended changes
- Do not change the npm workspace structure without discussion
Git Commands
Use modern Git commands instead of legacy git checkout:
| Instead of | Use |
git checkout <branch> | git switch <branch> |
MCP Tool Development Patterns
Tool Definition Example
export const exampleTool = defineTool({
name: 'tool_name',
description: 'Clear description for AI agents',
inputSchema: z.object({
param: z.string().describe('Parameter description'),
}),
annotations: {
readOnlyHint: true, // Optional: marks tool as read-only
},
handler: async (args, context) => {
// Check for cancellation
if (context.signal?.aborted) {
return { content: [{ type: 'text', text: 'Cancelled' }], isError: true };
}
try {
// Implementation using FileSystemService
const result = await someOperation(args.param);
return {
content: [{ type: 'text', text: `Success: ${result}` }],
structuredContent: { key: result }, // Optional structured data
};
} catch (error) {
return {
content: [{ type: 'text', text: `Error: ${error.message}` }],
isError: true,
};
}
},
});Attachment Handling
- Attachments stored in
.attachmentssubdirectories within folders - Use base64 encoding for file content transfer (MCP limitation)
- Images return with
type: 'image'content type in MCP responses - Always validate paths and handle
ENOENTerrors gracefully - Prevent filename collisions by appending timestamps when needed
|
git checkout -b <branch>|git switch -c <branch>| |git checkout -- <file>|git restore <file>| |git checkout HEAD -- <file>|git restore --source=HEAD <file>|
Never suggest or document git checkout - always use git switch for branches and git restore for files.
CI/CD Notes
- CI (
ci.yml): Runs on PRs - linting, tests, build verification - Release (
release.yml): Auto-runs on merge to main - bumps version viacommit-and-tag-version, creates GitHub Release with auto-generated notes - Uses Node 25.x, npm workspaces (single lock file at root)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

