agentleFS
bocanbocan/codex/.github/copilot-instructions.md

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

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
  1. Very specific:

    Tool registration pattern: All tools imported in server/src/mcp/tools/registry.ts and wrapped with asRegisteredTool().

    line 27
  2. Very specific:

    All API calls go through client/src/services/api.ts{api,auth,mcp}.test.ts, uses isolated test-data/ or test-data-mcp/ directories

    line 67
  3. Very specific:

    Test count verification: When adding MCP tools, update mcp.test.ts to expect correct tool count (currently 16)

    line 71
  4. Very specific:

    If you need to run tests via make test, be sure to run from the root directory.

    line 76
  5. Very specific:

    Create tool in server/src/mcp/tools/{category}.ts using defineTool() helper

    line 108
  6. Very specific:

    Add to tools array using asRegisteredTool()

    line 112
  7. Very specific:

    Add test in server/tests/mcp.test.ts and update tool count expectation

    line 113
  8. Very specific:

    Path security: Always use validatePath() for user-provided paths to prevent traversal attacks

    line 114
  9. Very specific:

    Create controller function in server/src/controllers/

    line 117
  10. Very specific:

    Add route in server/src/routes/ and import in server/src/index.ts

    line 118
  11. Very specific:

    Add client method in client/src/services/api.ts

    line 119
  12. Very specific:

    Add test in server/tests/api.test.ts

    line 120
  13. Very specific:

    Update API docs in GET /api handler (server/src/index.ts)

    line 121
  14. Very specific:

    Create Component.tsx and Component.css in client/src/components/ (AUTH_PASSWORD, MCP_API_KEY, SESSION_SECRET)

    line 124
  15. Very specific:

    Path traversal protection: Always use validatePath() helper (see server/src/mcp/tools/attachments.ts) for user-provided file paths

    line 125
  16. Distinctive:

    Input validation: Use Zod schemas for all MCP tool inputs and API request validation

    line 126
  17. Distinctive:

    Keep dependencies up to date (monitored by Dependabot)

    line 127
  18. Very specific:

    Never use any type: - Use unknown for truly dynamic types, then narrow with type guards

    line 134
  19. Very specific:

    Always enable strict mode in tsconfig.json

    line 135
  20. Distinctive:

    Prefer interfaces over type aliases for object shapes

    line 136
  21. Distinctive:

    Use proper typing for all function parameters and return values

    line 137
  22. Distinctive:

    Never commit secrets: - Use environment variables for sensitive data

    line 140
  23. Distinctive:

    Write tests before pushing code

    line 146
  24. Distinctive:

    Use descriptive test names that explain the behavior being tested

    line 149
  25. Distinctive:

    Use modern Git commands instead of legacy git checkout:

    line 160
  26. Distinctive:

    Use base64 encoding for file content transfer (MCP limitation)

    line 205
  27. Very specific:

    Always validate paths and handle ENOENT errors gracefully

    line 207
  28. Distinctive:

    Never suggest or document git checkout: - always use git switch for branches and git restore for files.

    line 213

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

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 /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 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_KEY environment 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 production

MCP 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 script

Important: Dependencies install at the root level only. Run npm ci or make install from root, not from subdirectories. The root package-lock.json manages 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 logs

Authentication 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.ts

Self-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 isolated test-data/ or test-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_DIR in beforeEach
  • Test count verification: When adding MCP tools, update mcp.test.ts to expect correct tool count (currently 16)
  • CSS uses custom properties from App.css for theming: var(--bg-primary), var(--text-primary), etc.
  • Keyboard navigation uses arrow keys AND vim-style j/k (see FolderTree.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 isolated test-data/ directory
  • Client tests: Vitest + React Testing Library, co-located with components
  • Tests must clean up: server tests recreate TEST_DATA_DIR in beforeEach

TypeScript

  • Server: tsconfig.json includes "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 in fileSystem.ts

Key Files

PurposeLocation
AEST API routesserver/src/routes/{folders,pages,attachments,auth}.ts
MCP tool registryserver/src/mcp/tools/registry.ts
MCP tool implementationsserver/src/mcp/tools/{pages,folders,attachments}.ts
MCP serverserver/src/mcp/server.ts
MCP configurationserver/src/mcp/config.ts
Type definitions (client)client/src/types/index.ts
Type definitions (MCP)server/src/mcp/tools/types.ts
Theme variablesclient/src/App.css (:root and [data-theme="dark"])
Test setupserver/tests/{api,auth,mcp}/types/index.ts
Theme variablesclient/src/App.css (:root and [data-theme="dark"])
Test setupserver/tests/api.test.ts, client/src/test/setup.ts
Docker configDockerfile, docker-compose.yml
CI/CD workflows.github/workflows/{ci.yml,release.yml}

Adding Features

New API endpoint:

  1. AddMCP tool**:
  2. Create tool in server/src/mcp/tools/{category}.ts using defineTool() helper
  3. Define Zod schema for input validation
  4. Implement handler that returns ToolResult with content array
  5. Export tool and import in server/src/mcp/tools/registry.ts
  6. Add to tools array using asRegisteredTool()
  7. Add test in server/tests/mcp.test.ts and update tool count expectation
  8. 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:

  1. Create Component.tsx and Component.css in client/src/components/ (AUTH_PASSWORD, MCP_API_KEY, SESSION_SECRET)
  • Path traversal protection: Always use validatePath() helper (see server/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.ts helmet middleware
  • MCP authentication: Require MCP_API_KEY in production; verify via Authorization: Bearer or X-Api-Key headers

Code Quality Standards

TypeScript

  • Never use any type - Use unknown for 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.ts helmet 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/ or dist/ directories
  • Never modify the root package-lock.json directly (use npm install commands)
  • 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 ofUse
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 .attachments subdirectories 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 ENOENT errors 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 via commit-and-tag-version, creates GitHub Release with auto-generated notes
  • Uses Node 25.x, npm workspaces (single lock file at root)

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.