Falco

fastly/fastly-agent-toolkit/skills/falco

作者 fastly6db70eaf54ba885d56091861224987d6cf06c429無授權條款34 個星標收錄於 2026年10月9日更新於 2026年10月9日儲存庫2 天前更新

Lints, tests, simulates, and formats Fastly VCL code using the falco tool. Also serves as the authoritative VCL reference via the falco Go source, which implements Fastly's full VCL dialect. Use when validating VCL syntax, running VCL linting, testing VCL locally, simulating VCL request handling, formatting VCL files, writing VCL unit tests with assertions, debugging VCL logic errors, looking up VCL function signatures or variable scopes, understanding VCL subroutine behavior, or running `falco lint`/`falco simulate`/`falco test`/`falco fmt`. Also applies when working with VCL syntax errors, type mismatches in VCL, choosing which VCL subroutine to use, or setting up a local VCL development and testing environment.

AI 產生的概覽

指導使用 falco 命令列工具對 Fastly VCL 程式碼進行檢查、測試、模擬、格式化與參考查詢。

功能
此技能說明如何使用 falco 工具對 Fastly VCL 檔案進行 lint、單元測試、模擬、格式化與統計。它也將 falco 的 Go 原始碼視為 VCL 變數、函式、型別與副程式作用域的權威參考,並列出常見 VCL 錯誤與修正方式。產出為檢查結果、測試執行、本機模擬伺服器、格式化檔案與參考查詢,而非新的 VCL 程式碼。
適用情境
適用於驗證 VCL 語法、執行 falco lint、test、simulate 或 fmt、撰寫 VCL 單元測試、偵錯 VCL 邏輯或型別錯誤,以及查詢 VCL 函式簽章與變數作用域。不適用於非 Fastly 的 VCL、Fastly Compute/WASM、Fastly API 或主控台操作,也不用於撰寫 Terraform 資源。
執行需求
需要 falco 命令列工具,可透過 Homebrew 安裝,或使用 Go 1.25+ 從原始碼建置。選用的 Fastly API 存取需要 FASTLY_SERVICE_ID 與 FASTLY_API_KEY 才能使用遠端片段參數。不附帶指令碼,僅為說明文件與參考文件。

Trigger and scope

Trigger on: VCL files, .vcl extensions, XVCL files, .xvcl extensions, falco CLI, VCL unit tests, VCL linting/simulation/formatting, VCL REPL, beresp/bereq/req.http variables, subroutine scopes, backend/ACL/director/table declarations, edge dictionaries, validating VCL in Terraform plans, or running/testing XVCL scripts locally.

Do NOT use for: generic non-Fastly VCL, Fastly Compute/WASM, Fastly API/dashboard ops, CDN comparison, cache purging, or authoring Terraform resources.

Falco — VCL Development Tool & Reference

Falco is a Fastly VCL development tool for linting, testing, simulating, and formatting VCL code. Equally important, the falco source code is the most complete machine-readable specification of Fastly's VCL dialect — its parser, interpreter, and type system document every variable, function, type, and scope rule in VCL.

Official VCL documentation: https://www.fastly.com/documentation/guides/full-site-delivery/fastly-vcl/about-fastly-vcl/

Falco documentation: https://github.com/ysugimoto/falco

Using Falco Source as VCL Reference

If you need to understand how VCL works — what variables exist, which scopes they're available in, what functions are built-in, how types coerce — the falco source code is your best reference. It's a complete Go implementation of Fastly's VCL 2.x and is more precise than prose documentation.

If the falco source is not available locally, recommend cloning it:

bash
git clone https://github.com/ysugimoto/falco.git ~/src/falco

Once available locally, read the source files directly to answer VCL questions. See understanding-vcl-from-source.md [blocked] for a detailed guide on which files to read for different VCL topics.

Install

bash
# Homebrewbrew install falco
# From source (requires Go 1.25+)go install github.com/ysugimoto/falco/cmd/falco@latest
# Or clone and buildgit clone https://github.com/ysugimoto/falco.gitcd falcomake darwin_arm64    # or darwin_amd64, linux_amd64, linux_arm64

Commands

CommandDescription
falco [lint]Lint VCL files (default command)
falco testRun VCL unit tests
falco simulateStart local simulator server
falco fmtFormat VCL files
falco statsShow VCL code statistics
falco consoleInteractive VCL REPL
falco terraformLint VCL from Terraform plans
falco dapDebug Adapter Protocol server

Common flags (all commands)

FlagDescription
-I, --include_pathAdd include path for VCL imports
-h, --helpShow help
-V, --versionShow version
-r, --remoteFetch snippets from Fastly API
--refreshRefresh remote snippet cache

Quick reference

Lint before deployment:

bash
falco -vv -I ./vcl ./vcl/main.vcl

Run tests:

bash
falco test -I ./vcl ./vcl/main.vcl

Development with watch mode:

bash
falco test -w -I ./vcl ./vcl/main.vcl

Run VCL locally (this is how you "run" or "test locally" — use simulate, not just lint):

bash
falco simulate -I ./vcl ./vcl/main.vcl# Default port is 3124. Test with: curl http://localhost:3124/path# Use -p to override: falco simulate -p 8080 ./vcl/main.vcl

Format all VCL:

bash
falco fmt -w ./vcl/**/*.vcl

Terraform integration:

bash
terraform show -json planned.out | falco terraform -vv

Common VCL Issues

Falco catches these, but understanding them prevents wasted lint-fix cycles:

  • Type mismatch: set req.http.X-API = true — HTTP headers are STRING, not BOOL. Use "true".
  • Missing time suffix: set beresp.ttl = 86400 — RTIME values need s suffix: 86400s.
  • Wrong scope: beresp.* only exists in vcl_fetch. In vcl_deliver, use resp.*.
  • Deprecated: req.request → use req.method. Falco accepts both, but always change to req.method when fixing VCL.
  • Synthetic strings: synthetic "text" needs long-string syntax: synthetic {"text"}.
  • Backend naming: Use F_ prefix: backend F_origin { ... }, not backend origin.
  • No modulo operator: VCL has no %. Use substr() on a hash or randomint() for splitting.
  • req.url.path is read-only in tests: Use set req.url = "/path" in test subroutines, not set req.url.path.
  • Vary placement: Vary must be set in vcl_fetch, not just vcl_deliver. Setting Vary after the object enters the cache is too late — the cache key won't include the Vary dimensions.

Configuration

Create .falco.yaml in project root for persistent settings:

yaml
include_paths:  - ./vcl  - ./includes
linter:  verbose: "warning"  rules:    rule-name: ERROR  # or WARNING, INFO, IGNORE
testing:  timeout: 10  # minutes (default: 10)  filter: "*.test.vcl"
simulator:  port: 3124
format:  indent_width: 2  line_width: 120

Environment variables

VariableDescription
FASTLY_SERVICE_IDService ID for Fastly API
FASTLY_API_KEYAPI key for Fastly API

Required when using -r, --remote flag.

Configure API credentials locally, outside chat. Never ask for an API key in a conversation or print its value.

References

TopicFileUse when...
VCL from Sourceunderstanding-vcl-from-source.md [blocked]Understanding VCL semantics by reading falco's implementation
Testing VCLtesting-vcl.md [blocked]Running test suites, coverage, watch mode for TDD
Formatting VCLformatting-vcl.md [blocked]Formatting VCL for consistent style
Linting VCLlinting-vcl.md [blocked]Checking VCL for errors before deployment
Simulating VCLsimulating-vcl.md [blocked]Testing VCL against HTTP requests locally
Terraform VCLterraform-vcl.md [blocked]Validating VCL from Terraform plans
VCL Consolevcl-console.md [blocked]Experimenting with VCL expressions interactively
VCL Statisticsvcl-statistics.md [blocked]Analyzing VCL project size and complexity

Source Code as VCL Reference (Quick Lookup)

When you have access to the falco source code locally (default: ~/src/falco), use these paths to answer specific VCL questions:

QuestionRead This FileWhy
"What variables can I use in vcl_recv?"interpreter/variable/Every req.*, beresp.*, client.* variable with scopes
"What built-in functions exist?"interpreter/function/All 390+ functions with type signatures and scope rules
"What are the VCL types?"interpreter/value/STRING, INTEGER, FLOAT, BOOL, TIME, RTIME, IP, BACKEND
"What's the request lifecycle?"interpreter/context/The 9 scopes: recv, hash, hit, miss, pass, fetch, error, deliver, log
"Is this valid VCL syntax?"token/token.go, lexer/lexer.goEvery keyword, operator, literal type
"How does this VCL statement work?"interpreter/statement.goHow set, unset, return, restart, etc. execute
"What are common VCL mistakes?"linter/, docs/rules.md50+ linting rules with explanations
"How do directors work?"interpreter/director.goRandom, fallback, hash, client, chash director types

For a comprehensive guide, see understanding-vcl-from-source.md [blocked].

來源與署名

來源:fastly/fastly-agent-toolkit位於skills/falco提交6db70ea

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架