{"owner":"cloudflare","repo":"cloudflared","hasSkills":true,"totalSkillsCount":1,"totalTokensCount":2605,"categories":["root-instruction"],"hasMcp":false,"mcpConfig":null,"found":["AGENTS.md"],"skills":{"AGENTS.md":"# Cloudflared\n\nCloudflare's command-line tool and networking daemon written in Go.\nProduction-grade tunneling and network connectivity services used by millions of\ndevelopers and organizations worldwide.\n\n## Essential Commands\n\n### Build & Test (Always run before commits)\n\n```bash\n# Full development check (run before any commit)\nmake test lint\n\n# Build for current platform\nmake cloudflared\n\n# Run all unit tests with coverage\nmake test\nmake cover\n\n# Run specific test\ngo test -run TestFunctionName ./path/to/package\n\n# Run tests with race detection\ngo test -race ./...\n```\n\n### Platform-Specific Builds\n\n```bash\n# Linux\nTARGET_OS=linux TARGET_ARCH=amd64 make cloudflared\n\n# Windows\nTARGET_OS=windows TARGET_ARCH=amd64 make cloudflared\n\n# macOS ARM64\nTARGET_OS=darwin TARGET_ARCH=arm64 make cloudflared\n\n# FIPS compliant build\nFIPS=true make cloudflared\n```\n\n### Code Quality & Formatting\n\n```bash\n# Run linter (38+ enabled linters)\nmake lint\n\n# Auto-fix formatting\nmake fmt\ngofmt -w .\ngoimports -w .\n\n# Security scanning\nmake vet\n\n# Component tests (Python integration tests)\ncd component-tests && python -m pytest test_file.py::test_function_name\n```\n\nNotes on linting:\n\n- `.golangci.yaml` is configured with `new-from-rev` and `whole-files: true`.\n  Touching a file triggers linting of the ENTIRE file, not just the changed\n  hunks. Expect to fix pre-existing issues in files you modify, or add\n  targeted `// nolint: <linter>` comments with a short justification.\n- Prefer `defer func() { _ = resource.Close() }()` over `defer resource.Close()`\n  for `io.Closer` values whose error truly does not matter — this satisfies\n  `errcheck` without hiding real failures elsewhere.\n\n## Project Knowledge\n\n### Package Structure\n\n- Use meaningful package names that reflect functionality\n- Package names should be lowercase, single words when possible\n- Avoid generic names like `util`, `common`, `helper`\n\n#### Well-known shared packages\n\n- `crypto/`: Single source of truth for TLS curve preferences and other\n  cryptographic primitives shared by every edge-facing transport. Import as\n  `cfdcrypto \"github.com/cloudflare/cloudflared/crypto\"` to avoid colliding\n  with the standard library's `crypto` package. Do NOT duplicate TLS curve\n  or cipher selection logic in other packages.\n- `tlsconfig/`: Builds the base `*tls.Config` used for edge connections\n  (`CreateTunnelConfig`) and loads origin/CA pools. Curve selection is\n  intentionally NOT set here; it is applied per-connection from the\n  `crypto/` package so the same config can be cloned and reused across\n  protocols.\n- `features/`: Runtime feature flags including `PostQuantumMode`\n  (`PostQuantumPrefer` = default, `PostQuantumStrict` = `--post-quantum`).\n\n### Function and Method Guidelines\n\n```go\n// Good: Clear purpose, proper error handling\nfunc (c *Connection) HandleRequest(ctx context.Context, req *http.Request) error {\n    if req == nil {\n        return errors.New(\"request cannot be nil\")\n    }\n    // Implementation...\n    return nil\n}\n```\n\n### Error Handling\n\n- Always handle errors explicitly, never ignore them\n- Use `fmt.Errorf` for error wrapping\n- Create meaningful error messages with context\n- Use error variables for common errors\n\n```go\n// Good error handling patterns\nif err != nil {\n    return fmt.Errorf(\"failed to process connection: %w\", err)\n}\n```\n\n### Logging Standards\n\n- Use `github.com/rs/zerolog` for structured logging\n- Include relevant context fields\n- Use appropriate log levels (Debug, Info, Warn, Error)\n\n```go\nlogger.Info().\n    Str(\"tunnelID\", tunnel.ID).\n    Int(\"connIndex\", connIndex).\n    Msg(\"Connection established\")\n```\n\n### Testing Patterns\n\n- Use `github.com/stretchr/testify` for assertions\n- Test files end with `_test.go`\n- Use table-driven tests for multiple scenarios\n- Always use `t.Parallel()` for parallel-safe tests\n- Use meaningful test names that describe behavior\n\n```go\nfunc TestMetricsListenerCreation(t *testing.T) {\n    t.Parallel()\n    // Test implementation\n    assert.Equal(t, expected, actual)\n    require.NoError(t, err)\n}\n```\n\n### Constants and Variables\n\n```go\nconst (\n    MaxGracePeriod       = time.Minute * 3\n    MaxConcurrentStreams = math.MaxInt32\n    LogFieldConnIndex    = \"connIndex\"\n)\n\nvar (\n    // Group related variables\n    switchingProtocolText = fmt.Sprintf(\"%d %s\", http.StatusSwitchingProtocols, http.StatusText(http.StatusSwitchingProtocols))\n    flushableContentTypes = []string{sseContentType, grpcContentType, sseJsonContentType}\n)\n```\n\n### Type Definitions\n\n- Define interfaces close to their usage\n- Keep interfaces small and focused\n- Use descriptive names for complex types\n\n```go\ntype TunnelConnection interface {\n    Serve(ctx context.Context) error\n}\n\ntype TunnelProperties struct {\n    Credentials    Credentials\n    QuickTunnelUrl string\n}\n```\n\n## Key Architectural Patterns\n\n### Context Usage\n\n- Always accept `context.Context` as first parameter for long-running operations\n- Respect context cancellation in loops and blocking operations\n- Pass context through call chains\n\n### Concurrency\n\n- Use channels for goroutine communication\n- Protect shared state with mutexes\n- Prefer `sync.RWMutex` for read-heavy workloads\n- `*tls.Config` values stored in shared maps (e.g.\n  `TunnelConfig.EdgeTLSConfigs`) must be `Clone()`d before mutating\n  per-connection fields like `CurvePreferences` or `NextProtos`. Writing\n  through the shared pointer races with concurrent connection attempts.\n\n### TLS & Post-Quantum key exchange\n\n- Per-connection TLS configuration for edge connections is built via\n  `cfdcrypto.TLSConfigWithCurvePreferences(tlsConfig, pqMode)`. It clones\n  the provided `*tls.Config` and sets `CurvePreferences` based on `pqMode`,\n  so callers never need to clone or mutate `CurvePreferences` themselves.\n  Do NOT reach for the package-private `getCurvePreferences` helper; the\n  exported `TLSConfigWithCurvePreferences` is the only supported entry\n  point.\n- Two PQ modes are supported and apply identically to QUIC and HTTP/2:\n  - `PostQuantumPrefer` (default): `[X25519MLKEM768, P256Kyber768Draft00, CurveP256]`\n  - `PostQuantumStrict` (`--post-quantum`): `[X25519MLKEM768, P256Kyber768Draft00]`\n- FIPS and non-FIPS builds use the same curve list. Do NOT reintroduce a\n  `fipsEnabled` branch in curve-selection code; if the two modes ever\n  diverge, express the divergence inside `crypto/` so call sites remain\n  untouched.\n- FIPS and non-FIPS artifacts remain separate. Ordinary builds use\n  `GOFIPS140=off`; `FIPS=true` builds and internal container images use\n  `GOFIPS140=latest`. This runtime-level distinction enforces FIPS algorithms\n  for origin connections without changing the explicit edge curve list above.\n- HTTP/2 supports post-quantum handshakes. Never re-add a\n  `PostQuantumStrict`-based rejection to H2 code paths, and never force\n  `--post-quantum` to select QUIC-only in protocol selection.\n\n### Configuration\n\n- Use structured configuration with validation\n- Support both file-based and CLI flag configuration\n- Provide sensible defaults\n\n### Metrics and Observability\n\n- Instrument code with Prometheus metrics\n- Use OpenTelemetry for distributed tracing\n- Include structured logging with relevant context\n- Check if metrics are emitted as deltas to confirm need to guard for zero values, such as when importing or updating dependencies, e.g. quic-go\n\n## Boundaries\n\n### ✅ Always Do\n\n- Run `make test lint` before any commit\n- Handle all errors explicitly with proper context\n- Use `github.com/rs/zerolog` for all logging\n- Add `t.Parallel()` to all parallel-safe tests\n- Follow the import grouping conventions\n- Use meaningful variable and function names\n- Include context.Context for long-running operations\n- Close resources in defer statements\n\n### ⚠️ Ask First Before\n\n- Adding new dependencies to go.mod\n- Modifying CI/CD configuration files\n- Changing build system or Makefile\n- Modifying component test infrastructure\n- Adding new linter rules or changing golangci-lint config\n- Making breaking changes to public APIs\n- Changing logging levels or structured logging fields\n\n### Breaking Change Policy\n\nRemoving or renaming a CLI flag, environment variable, configuration key, alias, or\nsubcommand is a **breaking change** and requires advance notice:\n\n1. A new entry must be added to the [Cloudflare Tunnel changelog](https://developers.cloudflare.com/changelog/product/tunnel/)\n   and published in a release **at least 3 months before** the removal takes effect.\n2. The entry must name every affected flag/alias/env var, state the planned removal\n   date or release, and describe the migration path.\n3. The actual removal PR must not be merged until that notice has shipped in a\n   released version.\n\nIf you are asked to remove a flag or similar user-visible interface without a prior\nnotice, do not proceed without explicit confirmation.\n\n### 🚫 Never Do\n\n- Ignore errors without explicit handling (`_ = err`)\n- Use generic package names (`util`, `helper`, `common`)\n- Commit code that fails `make test lint`\n- Use `fmt.Print*` instead of structured logging\n- Commit secrets, credentials, or sensitive data\n- Use deprecated or unsafe Go patterns\n- Skip testing for new functionality\n- Remove existing tests unless they're genuinely invalid\n\n## Dependencies Management\n\n- Use Go modules (`go.mod`) exclusively\n- The `go` directive in `go.mod` must include the patch version (`major.minor.patch`).\n  It is the exact Go version for builds and tests: the Makefile exports\n  `GOTOOLCHAIN=go<version>` from it unless Go is configured with `GOTOOLCHAIN=local`.\n  Cloudflare's internal Go package sets that so its patches are never replaced by an\n  upstream toolchain (RFC-028); never override it. Do not add a `toolchain` directive.\n  When bumping Go, align all CI, Docker image, and documentation version references,\n  including the Linux CI builder image and digest; see README's \"Updating Go\" section.\n- Resolve dependencies from the locked module graph with `go mod download`; do not vendor dependencies.\n- Builds, tests, vet, and lint use `-mod=readonly`; `go.mod` and `go.sum` must not drift in CI.\n- Linux CI uses Athens before public and direct module sources; macOS and Windows use the public proxy directly.\n- CI caches modules in `$GOMODCACHE` and compiled packages in `$GOCACHE` under `.cache/go/` for Go-running jobs.\n- Keep dependencies up-to-date and secure\n- Prefer standard library when possible\n- Cloudflared uses a fork of quic-go always check release notes before bumping\n  this dependency.\n\n## Security Considerations\n\n- FIPS compliance support available\n- Vulnerability scanning integrated in CI\n- Credential handling follows security best practices\n- Network security with TLS/QUIC protocols\n- Regular security audits and updates\n- Post quantum encryption\n\n## Common Patterns to Follow\n\n1. **Graceful shutdown**: Always implement proper cleanup\n2. **Resource management**: Close resources in defer statements\n3. **Error propagation**: Wrap errors with meaningful context\n4. **Configuration validation**: Validate inputs early\n5. **Logging consistency**: Use structured logging throughout\n6. **Testing coverage**: Aim for comprehensive test coverage\n7. **Documentation**: Comment exported functions and types\n\nRemember: This is a mission-critical networking tool used in production by many\norganizations. Code quality, security, and reliability are paramount.\n"},"files":{"AGENTS.md":"# Cloudflared\n\nCloudflare's command-line tool and networking daemon written in Go.\nProduction-grade tunneling and network connectivity services used by millions of\ndevelopers and organizations worldwide.\n\n## Essential Commands\n\n### Build & Test (Always run before commits)\n\n```bash\n# Full development check (run before any commit)\nmake test lint\n\n# Build for current platform\nmake cloudflared\n\n# Run all unit tests with coverage\nmake test\nmake cover\n\n# Run specific test\ngo test -run TestFunctionName ./path/to/package\n\n# Run tests with race detection\ngo test -race ./...\n```\n\n### Platform-Specific Builds\n\n```bash\n# Linux\nTARGET_OS=linux TARGET_ARCH=amd64 make cloudflared\n\n# Windows\nTARGET_OS=windows TARGET_ARCH=amd64 make cloudflared\n\n# macOS ARM64\nTARGET_OS=darwin TARGET_ARCH=arm64 make cloudflared\n\n# FIPS compliant build\nFIPS=true make cloudflared\n```\n\n### Code Quality & Formatting\n\n```bash\n# Run linter (38+ enabled linters)\nmake lint\n\n# Auto-fix formatting\nmake fmt\ngofmt -w .\ngoimports -w .\n\n# Security scanning\nmake vet\n\n# Component tests (Python integration tests)\ncd component-tests && python -m pytest test_file.py::test_function_name\n```\n\nNotes on linting:\n\n- `.golangci.yaml` is configured with `new-from-rev` and `whole-files: true`.\n  Touching a file triggers linting of the ENTIRE file, not just the changed\n  hunks. Expect to fix pre-existing issues in files you modify, or add\n  targeted `// nolint: <linter>` comments with a short justification.\n- Prefer `defer func() { _ = resource.Close() }()` over `defer resource.Close()`\n  for `io.Closer` values whose error truly does not matter — this satisfies\n  `errcheck` without hiding real failures elsewhere.\n\n## Project Knowledge\n\n### Package Structure\n\n- Use meaningful package names that reflect functionality\n- Package names should be lowercase, single words when possible\n- Avoid generic names like `util`, `common`, `helper`\n\n#### Well-known shared packages\n\n- `crypto/`: Single source of truth for TLS curve preferences and other\n  cryptographic primitives shared by every edge-facing transport. Import as\n  `cfdcrypto \"github.com/cloudflare/cloudflared/crypto\"` to avoid colliding\n  with the standard library's `crypto` package. Do NOT duplicate TLS curve\n  or cipher selection logic in other packages.\n- `tlsconfig/`: Builds the base `*tls.Config` used for edge connections\n  (`CreateTunnelConfig`) and loads origin/CA pools. Curve selection is\n  intentionally NOT set here; it is applied per-connection from the\n  `crypto/` package so the same config can be cloned and reused across\n  protocols.\n- `features/`: Runtime feature flags including `PostQuantumMode`\n  (`PostQuantumPrefer` = default, `PostQuantumStrict` = `--post-quantum`).\n\n### Function and Method Guidelines\n\n```go\n// Good: Clear purpose, proper error handling\nfunc (c *Connection) HandleRequest(ctx context.Context, req *http.Request) error {\n    if req == nil {\n        return errors.New(\"request cannot be nil\")\n    }\n    // Implementation...\n    return nil\n}\n```\n\n### Error Handling\n\n- Always handle errors explicitly, never ignore them\n- Use `fmt.Errorf` for error wrapping\n- Create meaningful error messages with context\n- Use error variables for common errors\n\n```go\n// Good error handling patterns\nif err != nil {\n    return fmt.Errorf(\"failed to process connection: %w\", err)\n}\n```\n\n### Logging Standards\n\n- Use `github.com/rs/zerolog` for structured logging\n- Include relevant context fields\n- Use appropriate log levels (Debug, Info, Warn, Error)\n\n```go\nlogger.Info().\n    Str(\"tunnelID\", tunnel.ID).\n    Int(\"connIndex\", connIndex).\n    Msg(\"Connection established\")\n```\n\n### Testing Patterns\n\n- Use `github.com/stretchr/testify` for assertions\n- Test files end with `_test.go`\n- Use table-driven tests for multiple scenarios\n- Always use `t.Parallel()` for parallel-safe tests\n- Use meaningful test names that describe behavior\n\n```go\nfunc TestMetricsListenerCreation(t *testing.T) {\n    t.Parallel()\n    // Test implementation\n    assert.Equal(t, expected, actual)\n    require.NoError(t, err)\n}\n```\n\n### Constants and Variables\n\n```go\nconst (\n    MaxGracePeriod       = time.Minute * 3\n    MaxConcurrentStreams = math.MaxInt32\n    LogFieldConnIndex    = \"connIndex\"\n)\n\nvar (\n    // Group related variables\n    switchingProtocolText = fmt.Sprintf(\"%d %s\", http.StatusSwitchingProtocols, http.StatusText(http.StatusSwitchingProtocols))\n    flushableContentTypes = []string{sseContentType, grpcContentType, sseJsonContentType}\n)\n```\n\n### Type Definitions\n\n- Define interfaces close to their usage\n- Keep interfaces small and focused\n- Use descriptive names for complex types\n\n```go\ntype TunnelConnection interface {\n    Serve(ctx context.Context) error\n}\n\ntype TunnelProperties struct {\n    Credentials    Credentials\n    QuickTunnelUrl string\n}\n```\n\n## Key Architectural Patterns\n\n### Context Usage\n\n- Always accept `context.Context` as first parameter for long-running operations\n- Respect context cancellation in loops and blocking operations\n- Pass context through call chains\n\n### Concurrency\n\n- Use channels for goroutine communication\n- Protect shared state with mutexes\n- Prefer `sync.RWMutex` for read-heavy workloads\n- `*tls.Config` values stored in shared maps (e.g.\n  `TunnelConfig.EdgeTLSConfigs`) must be `Clone()`d before mutating\n  per-connection fields like `CurvePreferences` or `NextProtos`. Writing\n  through the shared pointer races with concurrent connection attempts.\n\n### TLS & Post-Quantum key exchange\n\n- Per-connection TLS configuration for edge connections is built via\n  `cfdcrypto.TLSConfigWithCurvePreferences(tlsConfig, pqMode)`. It clones\n  the provided `*tls.Config` and sets `CurvePreferences` based on `pqMode`,\n  so callers never need to clone or mutate `CurvePreferences` themselves.\n  Do NOT reach for the package-private `getCurvePreferences` helper; the\n  exported `TLSConfigWithCurvePreferences` is the only supported entry\n  point.\n- Two PQ modes are supported and apply identically to QUIC and HTTP/2:\n  - `PostQuantumPrefer` (default): `[X25519MLKEM768, P256Kyber768Draft00, CurveP256]`\n  - `PostQuantumStrict` (`--post-quantum`): `[X25519MLKEM768, P256Kyber768Draft00]`\n- FIPS and non-FIPS builds use the same curve list. Do NOT reintroduce a\n  `fipsEnabled` branch in curve-selection code; if the two modes ever\n  diverge, express the divergence inside `crypto/` so call sites remain\n  untouched.\n- FIPS and non-FIPS artifacts remain separate. Ordinary builds use\n  `GOFIPS140=off`; `FIPS=true` builds and internal container images use\n  `GOFIPS140=latest`. This runtime-level distinction enforces FIPS algorithms\n  for origin connections without changing the explicit edge curve list above.\n- HTTP/2 supports post-quantum handshakes. Never re-add a\n  `PostQuantumStrict`-based rejection to H2 code paths, and never force\n  `--post-quantum` to select QUIC-only in protocol selection.\n\n### Configuration\n\n- Use structured configuration with validation\n- Support both file-based and CLI flag configuration\n- Provide sensible defaults\n\n### Metrics and Observability\n\n- Instrument code with Prometheus metrics\n- Use OpenTelemetry for distributed tracing\n- Include structured logging with relevant context\n- Check if metrics are emitted as deltas to confirm need to guard for zero values, such as when importing or updating dependencies, e.g. quic-go\n\n## Boundaries\n\n### ✅ Always Do\n\n- Run `make test lint` before any commit\n- Handle all errors explicitly with proper context\n- Use `github.com/rs/zerolog` for all logging\n- Add `t.Parallel()` to all parallel-safe tests\n- Follow the import grouping conventions\n- Use meaningful variable and function names\n- Include context.Context for long-running operations\n- Close resources in defer statements\n\n### ⚠️ Ask First Before\n\n- Adding new dependencies to go.mod\n- Modifying CI/CD configuration files\n- Changing build system or Makefile\n- Modifying component test infrastructure\n- Adding new linter rules or changing golangci-lint config\n- Making breaking changes to public APIs\n- Changing logging levels or structured logging fields\n\n### Breaking Change Policy\n\nRemoving or renaming a CLI flag, environment variable, configuration key, alias, or\nsubcommand is a **breaking change** and requires advance notice:\n\n1. A new entry must be added to the [Cloudflare Tunnel changelog](https://developers.cloudflare.com/changelog/product/tunnel/)\n   and published in a release **at least 3 months before** the removal takes effect.\n2. The entry must name every affected flag/alias/env var, state the planned removal\n   date or release, and describe the migration path.\n3. The actual removal PR must not be merged until that notice has shipped in a\n   released version.\n\nIf you are asked to remove a flag or similar user-visible interface without a prior\nnotice, do not proceed without explicit confirmation.\n\n### 🚫 Never Do\n\n- Ignore errors without explicit handling (`_ = err`)\n- Use generic package names (`util`, `helper`, `common`)\n- Commit code that fails `make test lint`\n- Use `fmt.Print*` instead of structured logging\n- Commit secrets, credentials, or sensitive data\n- Use deprecated or unsafe Go patterns\n- Skip testing for new functionality\n- Remove existing tests unless they're genuinely invalid\n\n## Dependencies Management\n\n- Use Go modules (`go.mod`) exclusively\n- The `go` directive in `go.mod` must include the patch version (`major.minor.patch`).\n  It is the exact Go version for builds and tests: the Makefile exports\n  `GOTOOLCHAIN=go<version>` from it unless Go is configured with `GOTOOLCHAIN=local`.\n  Cloudflare's internal Go package sets that so its patches are never replaced by an\n  upstream toolchain (RFC-028); never override it. Do not add a `toolchain` directive.\n  When bumping Go, align all CI, Docker image, and documentation version references,\n  including the Linux CI builder image and digest; see README's \"Updating Go\" section.\n- Resolve dependencies from the locked module graph with `go mod download`; do not vendor dependencies.\n- Builds, tests, vet, and lint use `-mod=readonly`; `go.mod` and `go.sum` must not drift in CI.\n- Linux CI uses Athens before public and direct module sources; macOS and Windows use the public proxy directly.\n- CI caches modules in `$GOMODCACHE` and compiled packages in `$GOCACHE` under `.cache/go/` for Go-running jobs.\n- Keep dependencies up-to-date and secure\n- Prefer standard library when possible\n- Cloudflared uses a fork of quic-go always check release notes before bumping\n  this dependency.\n\n## Security Considerations\n\n- FIPS compliance support available\n- Vulnerability scanning integrated in CI\n- Credential handling follows security best practices\n- Network security with TLS/QUIC protocols\n- Regular security audits and updates\n- Post quantum encryption\n\n## Common Patterns to Follow\n\n1. **Graceful shutdown**: Always implement proper cleanup\n2. **Resource management**: Close resources in defer statements\n3. **Error propagation**: Wrap errors with meaningful context\n4. **Configuration validation**: Validate inputs early\n5. **Logging consistency**: Use structured logging throughout\n6. **Testing coverage**: Aim for comprehensive test coverage\n7. **Documentation**: Comment exported functions and types\n\nRemember: This is a mission-critical networking tool used in production by many\norganizations. Code quality, security, and reliability are paramount.\n"},"items":[{"name":"AGENTS.md","path":"AGENTS.md","rawUrl":"https://raw.githubusercontent.com/cloudflare/cloudflared/HEAD/AGENTS.md","title":"AI Agent Protocol & Instructions","category":"root-instruction","format":"markdown","content":"# Cloudflared\n\nCloudflare's command-line tool and networking daemon written in Go.\nProduction-grade tunneling and network connectivity services used by millions of\ndevelopers and organizations worldwide.\n\n## Essential Commands\n\n### Build & Test (Always run before commits)\n\n```bash\n# Full development check (run before any commit)\nmake test lint\n\n# Build for current platform\nmake cloudflared\n\n# Run all unit tests with coverage\nmake test\nmake cover\n\n# Run specific test\ngo test -run TestFunctionName ./path/to/package\n\n# Run tests with race detection\ngo test -race ./...\n```\n\n### Platform-Specific Builds\n\n```bash\n# Linux\nTARGET_OS=linux TARGET_ARCH=amd64 make cloudflared\n\n# Windows\nTARGET_OS=windows TARGET_ARCH=amd64 make cloudflared\n\n# macOS ARM64\nTARGET_OS=darwin TARGET_ARCH=arm64 make cloudflared\n\n# FIPS compliant build\nFIPS=true make cloudflared\n```\n\n### Code Quality & Formatting\n\n```bash\n# Run linter (38+ enabled linters)\nmake lint\n\n# Auto-fix formatting\nmake fmt\ngofmt -w .\ngoimports -w .\n\n# Security scanning\nmake vet\n\n# Component tests (Python integration tests)\ncd component-tests && python -m pytest test_file.py::test_function_name\n```\n\nNotes on linting:\n\n- `.golangci.yaml` is configured with `new-from-rev` and `whole-files: true`.\n  Touching a file triggers linting of the ENTIRE file, not just the changed\n  hunks. Expect to fix pre-existing issues in files you modify, or add\n  targeted `// nolint: <linter>` comments with a short justification.\n- Prefer `defer func() { _ = resource.Close() }()` over `defer resource.Close()`\n  for `io.Closer` values whose error truly does not matter — this satisfies\n  `errcheck` without hiding real failures elsewhere.\n\n## Project Knowledge\n\n### Package Structure\n\n- Use meaningful package names that reflect functionality\n- Package names should be lowercase, single words when possible\n- Avoid generic names like `util`, `common`, `helper`\n\n#### Well-known shared packages\n\n- `crypto/`: Single source of truth for TLS curve preferences and other\n  cryptographic primitives shared by every edge-facing transport. Import as\n  `cfdcrypto \"github.com/cloudflare/cloudflared/crypto\"` to avoid colliding\n  with the standard library's `crypto` package. Do NOT duplicate TLS curve\n  or cipher selection logic in other packages.\n- `tlsconfig/`: Builds the base `*tls.Config` used for edge connections\n  (`CreateTunnelConfig`) and loads origin/CA pools. Curve selection is\n  intentionally NOT set here; it is applied per-connection from the\n  `crypto/` package so the same config can be cloned and reused across\n  protocols.\n- `features/`: Runtime feature flags including `PostQuantumMode`\n  (`PostQuantumPrefer` = default, `PostQuantumStrict` = `--post-quantum`).\n\n### Function and Method Guidelines\n\n```go\n// Good: Clear purpose, proper error handling\nfunc (c *Connection) HandleRequest(ctx context.Context, req *http.Request) error {\n    if req == nil {\n        return errors.New(\"request cannot be nil\")\n    }\n    // Implementation...\n    return nil\n}\n```\n\n### Error Handling\n\n- Always handle errors explicitly, never ignore them\n- Use `fmt.Errorf` for error wrapping\n- Create meaningful error messages with context\n- Use error variables for common errors\n\n```go\n// Good error handling patterns\nif err != nil {\n    return fmt.Errorf(\"failed to process connection: %w\", err)\n}\n```\n\n### Logging Standards\n\n- Use `github.com/rs/zerolog` for structured logging\n- Include relevant context fields\n- Use appropriate log levels (Debug, Info, Warn, Error)\n\n```go\nlogger.Info().\n    Str(\"tunnelID\", tunnel.ID).\n    Int(\"connIndex\", connIndex).\n    Msg(\"Connection established\")\n```\n\n### Testing Patterns\n\n- Use `github.com/stretchr/testify` for assertions\n- Test files end with `_test.go`\n- Use table-driven tests for multiple scenarios\n- Always use `t.Parallel()` for parallel-safe tests\n- Use meaningful test names that describe behavior\n\n```go\nfunc TestMetricsListenerCreation(t *testing.T) {\n    t.Parallel()\n    // Test implementation\n    assert.Equal(t, expected, actual)\n    require.NoError(t, err)\n}\n```\n\n### Constants and Variables\n\n```go\nconst (\n    MaxGracePeriod       = time.Minute * 3\n    MaxConcurrentStreams = math.MaxInt32\n    LogFieldConnIndex    = \"connIndex\"\n)\n\nvar (\n    // Group related variables\n    switchingProtocolText = fmt.Sprintf(\"%d %s\", http.StatusSwitchingProtocols, http.StatusText(http.StatusSwitchingProtocols))\n    flushableContentTypes = []string{sseContentType, grpcContentType, sseJsonContentType}\n)\n```\n\n### Type Definitions\n\n- Define interfaces close to their usage\n- Keep interfaces small and focused\n- Use descriptive names for complex types\n\n```go\ntype TunnelConnection interface {\n    Serve(ctx context.Context) error\n}\n\ntype TunnelProperties struct {\n    Credentials    Credentials\n    QuickTunnelUrl string\n}\n```\n\n## Key Architectural Patterns\n\n### Context Usage\n\n- Always accept `context.Context` as first parameter for long-running operations\n- Respect context cancellation in loops and blocking operations\n- Pass context through call chains\n\n### Concurrency\n\n- Use channels for goroutine communication\n- Protect shared state with mutexes\n- Prefer `sync.RWMutex` for read-heavy workloads\n- `*tls.Config` values stored in shared maps (e.g.\n  `TunnelConfig.EdgeTLSConfigs`) must be `Clone()`d before mutating\n  per-connection fields like `CurvePreferences` or `NextProtos`. Writing\n  through the shared pointer races with concurrent connection attempts.\n\n### TLS & Post-Quantum key exchange\n\n- Per-connection TLS configuration for edge connections is built via\n  `cfdcrypto.TLSConfigWithCurvePreferences(tlsConfig, pqMode)`. It clones\n  the provided `*tls.Config` and sets `CurvePreferences` based on `pqMode`,\n  so callers never need to clone or mutate `CurvePreferences` themselves.\n  Do NOT reach for the package-private `getCurvePreferences` helper; the\n  exported `TLSConfigWithCurvePreferences` is the only supported entry\n  point.\n- Two PQ modes are supported and apply identically to QUIC and HTTP/2:\n  - `PostQuantumPrefer` (default): `[X25519MLKEM768, P256Kyber768Draft00, CurveP256]`\n  - `PostQuantumStrict` (`--post-quantum`): `[X25519MLKEM768, P256Kyber768Draft00]`\n- FIPS and non-FIPS builds use the same curve list. Do NOT reintroduce a\n  `fipsEnabled` branch in curve-selection code; if the two modes ever\n  diverge, express the divergence inside `crypto/` so call sites remain\n  untouched.\n- FIPS and non-FIPS artifacts remain separate. Ordinary builds use\n  `GOFIPS140=off`; `FIPS=true` builds and internal container images use\n  `GOFIPS140=latest`. This runtime-level distinction enforces FIPS algorithms\n  for origin connections without changing the explicit edge curve list above.\n- HTTP/2 supports post-quantum handshakes. Never re-add a\n  `PostQuantumStrict`-based rejection to H2 code paths, and never force\n  `--post-quantum` to select QUIC-only in protocol selection.\n\n### Configuration\n\n- Use structured configuration with validation\n- Support both file-based and CLI flag configuration\n- Provide sensible defaults\n\n### Metrics and Observability\n\n- Instrument code with Prometheus metrics\n- Use OpenTelemetry for distributed tracing\n- Include structured logging with relevant context\n- Check if metrics are emitted as deltas to confirm need to guard for zero values, such as when importing or updating dependencies, e.g. quic-go\n\n## Boundaries\n\n### ✅ Always Do\n\n- Run `make test lint` before any commit\n- Handle all errors explicitly with proper context\n- Use `github.com/rs/zerolog` for all logging\n- Add `t.Parallel()` to all parallel-safe tests\n- Follow the import grouping conventions\n- Use meaningful variable and function names\n- Include context.Context for long-running operations\n- Close resources in defer statements\n\n### ⚠️ Ask First Before\n\n- Adding new dependencies to go.mod\n- Modifying CI/CD configuration files\n- Changing build system or Makefile\n- Modifying component test infrastructure\n- Adding new linter rules or changing golangci-lint config\n- Making breaking changes to public APIs\n- Changing logging levels or structured logging fields\n\n### Breaking Change Policy\n\nRemoving or renaming a CLI flag, environment variable, configuration key, alias, or\nsubcommand is a **breaking change** and requires advance notice:\n\n1. A new entry must be added to the [Cloudflare Tunnel changelog](https://developers.cloudflare.com/changelog/product/tunnel/)\n   and published in a release **at least 3 months before** the removal takes effect.\n2. The entry must name every affected flag/alias/env var, state the planned removal\n   date or release, and describe the migration path.\n3. The actual removal PR must not be merged until that notice has shipped in a\n   released version.\n\nIf you are asked to remove a flag or similar user-visible interface without a prior\nnotice, do not proceed without explicit confirmation.\n\n### 🚫 Never Do\n\n- Ignore errors without explicit handling (`_ = err`)\n- Use generic package names (`util`, `helper`, `common`)\n- Commit code that fails `make test lint`\n- Use `fmt.Print*` instead of structured logging\n- Commit secrets, credentials, or sensitive data\n- Use deprecated or unsafe Go patterns\n- Skip testing for new functionality\n- Remove existing tests unless they're genuinely invalid\n\n## Dependencies Management\n\n- Use Go modules (`go.mod`) exclusively\n- The `go` directive in `go.mod` must include the patch version (`major.minor.patch`).\n  It is the exact Go version for builds and tests: the Makefile exports\n  `GOTOOLCHAIN=go<version>` from it unless Go is configured with `GOTOOLCHAIN=local`.\n  Cloudflare's internal Go package sets that so its patches are never replaced by an\n  upstream toolchain (RFC-028); never override it. Do not add a `toolchain` directive.\n  When bumping Go, align all CI, Docker image, and documentation version references,\n  including the Linux CI builder image and digest; see README's \"Updating Go\" section.\n- Resolve dependencies from the locked module graph with `go mod download`; do not vendor dependencies.\n- Builds, tests, vet, and lint use `-mod=readonly`; `go.mod` and `go.sum` must not drift in CI.\n- Linux CI uses Athens before public and direct module sources; macOS and Windows use the public proxy directly.\n- CI caches modules in `$GOMODCACHE` and compiled packages in `$GOCACHE` under `.cache/go/` for Go-running jobs.\n- Keep dependencies up-to-date and secure\n- Prefer standard library when possible\n- Cloudflared uses a fork of quic-go always check release notes before bumping\n  this dependency.\n\n## Security Considerations\n\n- FIPS compliance support available\n- Vulnerability scanning integrated in CI\n- Credential handling follows security best practices\n- Network security with TLS/QUIC protocols\n- Regular security audits and updates\n- Post quantum encryption\n\n## Common Patterns to Follow\n\n1. **Graceful shutdown**: Always implement proper cleanup\n2. **Resource management**: Close resources in defer statements\n3. **Error propagation**: Wrap errors with meaningful context\n4. **Configuration validation**: Validate inputs early\n5. **Logging consistency**: Use structured logging throughout\n6. **Testing coverage**: Aim for comprehensive test coverage\n7. **Documentation**: Comment exported functions and types\n\nRemember: This is a mission-critical networking tool used in production by many\norganizations. Code quality, security, and reliability are paramount.\n","isInternal":false,"tokens":2605,"sizeBytes":11393}],"systemPromptSnippet":"<yakaai_skills repo=\"cloudflare/cloudflared\">\n<!-- File: AGENTS.md (Tokens: ~2605 | Category: root-instruction) -->\n# Cloudflared\n\nCloudflare's command-line tool and networking daemon written in Go.\nProduction-grade tunneling and network connectivity services used by millions of\ndevelopers and organizations worldwide.\n\n## Essential Commands\n\n### Build & Test (Always run before commits)\n\n```bash\n# Full development check (run before any commit)\nmake test lint\n\n# Build for current platform\nmake cloudflared\n\n# Run all unit tests with coverage\nmake test\nmake cover\n\n# Run specific test\ngo test -run TestFunctionName ./path/to/package\n\n# Run tests with race detection\ngo test -race ./...\n```\n\n### Platform-Specific Builds\n\n```bash\n# Linux\nTARGET_OS=linux TARGET_ARCH=amd64 make cloudflared\n\n# Windows\nTARGET_OS=windows TARGET_ARCH=amd64 make cloudflared\n\n# macOS ARM64\nTARGET_OS=darwin TARGET_ARCH=arm64 make cloudflared\n\n# FIPS compliant build\nFIPS=true make cloudflared\n```\n\n### Code Quality & Formatting\n\n```bash\n# Run linter (38+ enabled linters)\nmake lint\n\n# Auto-fix formatting\nmake fmt\ngofmt -w .\ngoimports -w .\n\n# Security scanning\nmake vet\n\n# Component tests (Python integration tests)\ncd component-tests && python -m pytest test_file.py::test_function_name\n```\n\nNotes on linting:\n\n- `.golangci.yaml` is configured with `new-from-rev` and `whole-files: true`.\n  Touching a file triggers linting of the ENTIRE file, not just the changed\n  hunks. Expect to fix pre-existing issues in files you modify, or add\n  targeted `// nolint: <linter>` comments with a short justification.\n- Prefer `defer func() { _ = resource.Close() }()` over `defer resource.Close()`\n  for `io.Closer` values whose error truly does not matter — this satisfies\n  `errcheck` without hiding real failures elsewhere.\n\n## Project Knowledge\n\n### Package Structure\n\n- Use meaningful package names that reflect functionality\n- Package names should be lowercase, single words when possible\n- Avoid generic names like `util`, `common`, `helper`\n\n#### Well-known shared packages\n\n- `crypto/`: Single source of truth for TLS curve preferences and other\n  cryptographic primitives shared by every edge-facing transport. Import as\n  `cfdcrypto \"github.com/cloudflare/cloudflared/crypto\"` to avoid colliding\n  with the standard library's `crypto` package. Do NOT duplicate TLS curve\n  or cipher selection logic in other packages.\n- `tlsconfig/`: Builds the base `*tls.Config` used for edge connections\n  (`CreateTunnelConfig`) and loads origin/CA pools. Curve selection is\n  intentionally NOT set here; it is applied per-connection from the\n  `crypto/` package so the same config can be cloned and reused across\n  protocols.\n- `features/`: Runtime feature flags including `PostQuantumMode`\n  (`PostQuantumPrefer` = default, `PostQuantumStrict` = `--post-quantum`).\n\n### Function and Method Guidelines\n\n```go\n// Good: Clear purpose, proper error handling\nfunc (c *Connection) HandleRequest(ctx context.Context, req *http.Request) error {\n    if req == nil {\n        return errors.New(\"request cannot be nil\")\n    }\n    // Implementation...\n    return nil\n}\n```\n\n### Error Handling\n\n- Always handle errors explicitly, never ignore them\n- Use `fmt.Errorf` for error wrapping\n- Create meaningful error messages with context\n- Use error variables for common errors\n\n```go\n// Good error handling patterns\nif err != nil {\n    return fmt.Errorf(\"failed to process connection: %w\", err)\n}\n```\n\n### Logging Standards\n\n- Use `github.com/rs/zerolog` for structured logging\n- Include relevant context fields\n- Use appropriate log levels (Debug, Info, Warn, Error)\n\n```go\nlogger.Info().\n    Str(\"tunnelID\", tunnel.ID).\n    Int(\"connIndex\", connIndex).\n    Msg(\"Connection established\")\n```\n\n### Testing Patterns\n\n- Use `github.com/stretchr/testify` for assertions\n- Test files end with `_test.go`\n- Use table-driven tests for multiple scenarios\n- Always use `t.Parallel()` for parallel-safe tests\n- Use meaningful test names that describe behavior\n\n```go\nfunc TestMetricsListenerCreation(t *testing.T) {\n    t.Parallel()\n    // Test implementation\n    assert.Equal(t, expected, actual)\n    require.NoError(t, err)\n}\n```\n\n### Constants and Variables\n\n```go\nconst (\n    MaxGracePeriod       = time.Minute * 3\n    MaxConcurrentStreams = math.MaxInt32\n    LogFieldConnIndex    = \"connIndex\"\n)\n\nvar (\n    // Group related variables\n    switchingProtocolText = fmt.Sprintf(\"%d %s\", http.StatusSwitchingProtocols, http.StatusText(http.StatusSwitchingProtocols))\n    flushableContentTypes = []string{sseContentType, grpcContentType, sseJsonContentType}\n)\n```\n\n### Type Definitions\n\n- Define interfaces close to their usage\n- Keep interfaces small and focused\n- Use descriptive names for complex types\n\n```go\ntype TunnelConnection interface {\n    Serve(ctx context.Context) error\n}\n\ntype TunnelProperties struct {\n    Credentials    Credentials\n    QuickTunnelUrl string\n}\n```\n\n## Key Architectural Patterns\n\n### Context Usage\n\n- Always accept `context.Context` as first parameter for long-running operations\n- Respect context cancellation in loops and blocking operations\n- Pass context through call chains\n\n### Concurrency\n\n- Use channels for goroutine communication\n- Protect shared state with mutexes\n- Prefer `sync.RWMutex` for read-heavy workloads\n- `*tls.Config` values stored in shared maps (e.g.\n  `TunnelConfig.EdgeTLSConfigs`) must be `Clone()`d before mutating\n  per-connection fields like `CurvePreferences` or `NextProtos`. Writing\n  through the shared pointer races with concurrent connection attempts.\n\n### TLS & Post-Quantum key exchange\n\n- Per-connection TLS configuration for edge connections is built via\n  `cfdcrypto.TLSConfigWithCurvePreferences(tlsConfig, pqMode)`. It clones\n  the provided `*tls.Config` and sets `CurvePreferences` based on `pqMode`,\n  so callers never need to clone or mutate `CurvePreferences` themselves.\n  Do NOT reach for the package-private `getCurvePreferences` helper; the\n  exported `TLSConfigWithCurvePreferences` is the only supported entry\n  point.\n- Two PQ modes are supported and apply identically to QUIC and HTTP/2:\n  - `PostQuantumPrefer` (default): `[X25519MLKEM768, P256Kyber768Draft00, CurveP256]`\n  - `PostQuantumStrict` (`--post-quantum`): `[X25519MLKEM768, P256Kyber768Draft00]`\n- FIPS and non-FIPS builds use the same curve list. Do NOT reintroduce a\n  `fipsEnabled` branch in curve-selection code; if the two modes ever\n  diverge, express the divergence inside `crypto/` so call sites remain\n  untouched.\n- FIPS and non-FIPS artifacts remain separate. Ordinary builds use\n  `GOFIPS140=off`; `FIPS=true` builds and internal container images use\n  `GOFIPS140=latest`. This runtime-level distinction enforces FIPS algorithms\n  for origin connections without changing the explicit edge curve list above.\n- HTTP/2 supports post-quantum handshakes. Never re-add a\n  `PostQuantumStrict`-based rejection to H2 code paths, and never force\n  `--post-quantum` to select QUIC-only in protocol selection.\n\n### Configuration\n\n- Use structured configuration with validation\n- Support both file-based and CLI flag configuration\n- Provide sensible defaults\n\n### Metrics and Observability\n\n- Instrument code with Prometheus metrics\n- Use OpenTelemetry for distributed tracing\n- Include structured logging with relevant context\n- Check if metrics are emitted as deltas to confirm need to guard for zero values, such as when importing or updating dependencies, e.g. quic-go\n\n## Boundaries\n\n### ✅ Always Do\n\n- Run `make test lint` before any commit\n- Handle all errors explicitly with proper context\n- Use `github.com/rs/zerolog` for all logging\n- Add `t.Parallel()` to all parallel-safe tests\n- Follow the import grouping conventions\n- Use meaningful variable and function names\n- Include context.Context for long-running operations\n- Close resources in defer statements\n\n### ⚠️ Ask First Before\n\n- Adding new dependencies to go.mod\n- Modifying CI/CD configuration files\n- Changing build system or Makefile\n- Modifying component test infrastructure\n- Adding new linter rules or changing golangci-lint config\n- Making breaking changes to public APIs\n- Changing logging levels or structured logging fields\n\n### Breaking Change Policy\n\nRemoving or renaming a CLI flag, environment variable, configuration key, alias, or\nsubcommand is a **breaking change** and requires advance notice:\n\n1. A new entry must be added to the [Cloudflare Tunnel changelog](https://developers.cloudflare.com/changelog/product/tunnel/)\n   and published in a release **at least 3 months before** the removal takes effect.\n2. The entry must name every affected flag/alias/env var, state the planned removal\n   date or release, and describe the migration path.\n3. The actual removal PR must not be merged until that notice has shipped in a\n   released version.\n\nIf you are asked to remove a flag or similar user-visible interface without a prior\nnotice, do not proceed without explicit confirmation.\n\n### 🚫 Never Do\n\n- Ignore errors without explicit handling (`_ = err`)\n- Use generic package names (`util`, `helper`, `common`)\n- Commit code that fails `make test lint`\n- Use `fmt.Print*` instead of structured logging\n- Commit secrets, credentials, or sensitive data\n- Use deprecated or unsafe Go patterns\n- Skip testing for new functionality\n- Remove existing tests unless they're genuinely invalid\n\n## Dependencies Management\n\n- Use Go modules (`go.mod`) exclusively\n- The `go` directive in `go.mod` must include the patch version (`major.minor.patch`).\n  It is the exact Go version for builds and tests: the Makefile exports\n  `GOTOOLCHAIN=go<version>` from it unless Go is configured with `GOTOOLCHAIN=local`.\n  Cloudflare's internal Go package sets that so its patches are never replaced by an\n  upstream toolchain (RFC-028); never override it. Do not add a `toolchain` directive.\n  When bumping Go, align all CI, Docker image, and documentation version references,\n  including the Linux CI builder image and digest; see README's \"Updating Go\" section.\n- Resolve dependencies from the locked module graph with `go mod download`; do not vendor dependencies.\n- Builds, tests, vet, and lint use `-mod=readonly`; `go.mod` and `go.sum` must not drift in CI.\n- Linux CI uses Athens before public and direct module sources; macOS and Windows use the public proxy directly.\n- CI caches modules in `$GOMODCACHE` and compiled packages in `$GOCACHE` under `.cache/go/` for Go-running jobs.\n- Keep dependencies up-to-date and secure\n- Prefer standard library when possible\n- Cloudflared uses a fork of quic-go always check release notes before bumping\n  this dependency.\n\n## Security Considerations\n\n- FIPS compliance support available\n- Vulnerability scanning integrated in CI\n- Credential handling follows security best practices\n- Network security with TLS/QUIC protocols\n- Regular security audits and updates\n- Post quantum encryption\n\n## Common Patterns to Follow\n\n1. **Graceful shutdown**: Always implement proper cleanup\n2. **Resource management**: Close resources in defer statements\n3. **Error propagation**: Wrap errors with meaningful context\n4. **Configuration validation**: Validate inputs early\n5. **Logging consistency**: Use structured logging throughout\n6. **Testing coverage**: Aim for comprehensive test coverage\n7. **Documentation**: Comment exported functions and types\n\nRemember: This is a mission-critical networking tool used in production by many\norganizations. Code quality, security, and reliability are paramount.\n</yakaai_skills>"}