finfocus
Copilot instructions10 starsChanged 2 months agoApache-2.0View on GitHub
FinFocus is a CLI tool for calculating cloud infrastructure costs from Pulumi infrastructure definitions. It uses a plugin-based architecture to query multiple cost data sources via gRPC. Always run make lint and make test before committing. The finfocus binary runs as both a standalone CLI and a Pulumi tool plugin. Mode is detected via binary name (pulumi-tool-finfocus) or FINFOCUS_PLUGIN_MODE=true. This changes the Use string and examples but shares all subcommands. Plugins communicate via gRPC using protocol buffers from finfocus-spec. Always…
In this repository7 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- pick-issueSkill
- promote-issueSkill
- agentic-workflow-designerSkill
- agentic-workflowsSkill
- jqschemaSkill
The file
We split this copilot-instructions.md into the rules it gives an agent
8 rules. About 0 are common, 1 is distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 93
Logging: Use internal/logging with logging.FromContext(ctx).
- Very specific: line 98
Testify required: Use require.* for setup (stops test), assert.* for values (continues test)
- Very specific: line 100
Table-driven tests: Use wantErr and errContains fields
- Very specific: line 107
Use RunE (not Run) for error handling
- Very specific: line 108
Use cmd.Printf() for output (not fmt.Printf())
- Distinctive: line 114
Use the correct import path for Analyzer development:
- Very specific: line 131
Run make docs-lint after Markdown edits.
- Very specific: line 159
All PRs must pass: unit tests with race detection, 61% coverage gate, golangci-lint v2.9.0, govulncheck, cross-platform builds …
≈ “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
FinFocus Development Instructions
FinFocus is a CLI tool for calculating cloud infrastructure costs from Pulumi infrastructure definitions. It uses a plugin-based architecture to query multiple cost data sources via gRPC.
Build, Test, and Lint Commands
make build # Build binary to bin/finfocus
make build-all # Build binary + all plugins (recorder, Pulumi tool)
make clean # Remove build artifacts
make test # Run unit tests (fast, default)
go test ./internal/cli/... # Test specific package
go test -run TestName ./... # Run single test by name
go test -v -run TestName ./internal/engine/... # Single test in one package
make test-race # Run with race detector
make test-integration # Integration tests (slower)
make test-e2e # E2E tests (requires AWS credentials)
make lint # golangci-lint v2.9.0 + markdownlint + actionlint
make validate # go mod tidy -diff + go vet
make docs-lint # Lint documentation only
go test -coverprofile=coverage.out ./... # Coverage report
go tool cover -html=coverage.outAlways run make lint and make test before committing.
Architecture
Pulumi JSON → Ingestion → Resource Descriptors → Router → Engine → Plugins (gRPC) / Specs (YAML) → OutputDual-Mode Binary
The finfocus binary runs as both a standalone CLI and a Pulumi tool plugin. Mode is detected via binary name (pulumi-tool-finfocus) or FINFOCUS_PLUGIN_MODE=true. This changes the Use string and examples but shares all subcommands.
Core Components
- CLI (
internal/cli/) — Cobra commands:overview,cost projected|actual|recommendations|budget|estimate,plugin *,config *,analyzer serve - Engine (
internal/engine/) — Orchestrates cost calculation. Tries plugins first, falls back to local YAML specs inspecs/. UseshoursPerMonth = 730. Supports table, JSON, NDJSON output. Includes batch processing (threshold: 100 resources), caching, and budget forecasting. - Router (
internal/router/) — Routes resource types to the correct plugin based on provider patterns, priority rules, and config-driven routing from~/.finfocus/config.yaml. - Proto Adapter (
internal/proto/) — Bridge between engine and plugins. ConvertsResourceDescriptorto protobuf requests, performs pre-flight validation viapluginsdk, extracts SKU/Region from resourceInputs, and aggregates errors withCostResultWithErrors. - Plugin Host (
internal/pluginhost/) — gRPC plugin lifecycle.ProcessLauncher(TCP) andStdioLauncher(stdin/stdout). 10-second timeout, 100ms retry. Always callcmd.Wait()afterKill()to prevent zombies. - Registry (
internal/registry/) — Discovers plugins at~/.finfocus/plugins/<name>/<version>/. Optionalplugin.manifest.jsonvalidation. - Ingestion (
internal/ingest/) — Parsespulumi preview --json. Must inspectnewStateto extractInputs— without this, property extraction fails and plugins returnInvalidArgument. - Analyzer (
internal/analyzer/) — Implementspulumirpc.AnalyzerServerfor zero-click cost estimation duringpulumi preview. Prints ONLY port number to stdout (Pulumi handshake). All logs go to stderr. ADVISORY enforcement only. - Config (
internal/config/) — Manages~/.finfocus/config.yamlincluding plugin routing rules, budget definitions, and dismissed recommendation state (~/.finfocus/dismissed.json). - TUI (
internal/tui/) — Bubble Tea + Lip Gloss with adaptive color schemes.
Plugin Communication
Plugins communicate via gRPC using protocol buffers from finfocus-spec. Always use pluginsdk constants for environment variables and metadata keys:
pluginsdk.EnvPort // "FINFOCUS_PLUGIN_PORT"
pluginsdk.EnvLogLevel // "FINFOCUS_LOG_LEVEL"
pluginsdk.EnvLogFormat // "FINFOCUS_LOG_FORMAT"
pluginsdk.TraceIDMetadataKey // "x-finfocus-trace-id" (gRPC metadata)Trace IDs propagate automatically: TraceInterceptor() in pluginhost injects them into outgoing gRPC calls; plugins extract via pluginsdk.TracingUnaryServerInterceptor().
Pre-Flight Validation Pattern
The proto adapter validates requests before making gRPC calls. Invalid resources get a $0 placeholder with "VALIDATION: ..." notes (distinct from plugin errors prefixed "ERROR:"):
if err := pluginsdk.ValidateProjectedCostRequest(protoReq); err != nil {
log.Warn().Str("resource_type", resource.Type).Err(err).Msg("pre-flight validation failed")
result.Results = append(result.Results, &CostResult{
Currency: "USD", MonthlyCost: 0,
Notes: fmt.Sprintf("VALIDATION: %v", err),
})
continue
}Recorder Plugin
plugins/recorder/ is a reference plugin for development. It records all gRPC requests to JSON files and optionally returns mock responses (FINFOCUS_RECORDER_MOCK_RESPONSE=true). Build with make build-recorder, install with make install-recorder.
Key Conventions
Go Standards
- Go Version: 1.27.1
- Imports: Standard library → third-party → internal packages (enforced by
goimportsin golangci-lint) - Error Handling: Wrap with
%w:fmt.Errorf("operation failed: %w", err). Sentinel errors:var ErrName = errors.New("description") - Logging: Use
internal/loggingwithlogging.FromContext(ctx). Includecomponentandoperationfields. UseDebugfor flow,Infofor milestones,Warnfor recoverable issues. - Context: Pass
context.Contextthrough all request lifecycles
Testing
- Testify required: Use
require.*for setup (stops test),assert.*for values (continues test) - Coverage: 80% goal, 95% critical paths; CI enforces 61% minimum
- Table-driven tests: Use
wantErranderrContainsfields - Test both paths: Success and error cases
- Error messages:
assert.Contains(t, err.Error(), "expected text")
CLI Command Pattern
- Constructor:
NewXxxCmd() *cobra.Command - Use
RunE(notRun) for error handling - Use
cmd.Printf()for output (notfmt.Printf()) - Defer cleanup immediately after resource acquisition
- Support multiple date formats:
"2006-01-02", RFC3339
Pulumi SDK Import
Use the correct import path for Analyzer development:
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
// NOT: github.com/pulumi/pulumi/sdk/v3/proto/go/pulumirpcNaming
- Package names: lowercase, short (
engine,config,pluginhost) - CLI flags: kebab-case (
--pulumi-json) - Environment/config keys: uppercase snake (
FINFOCUS_*) - Exported types: require Go doc comments
Documentation
- Markdown frontmatter:
title,description,layout. Thetitleis the H1; content starts with H2. - Run
make docs-lintafter Markdown edits.
Commit Messages
Conventional Commits: feat(cli): add --format flag, fix(engine): correct monthly cost, test(registry): add discovery tests
Multi-Repository Ecosystem
| Repository | Purpose |
| finfocus (this repo) | CLI tool, plugin host, engine |
| finfocus-spec | Protocol buffers, pluginsdk |
| finfocus-plugin | Plugin implementations |
Cross-repo changes require coordination per .specify/memory/constitution.md.
Configuration
Precedence: CLI flags → Environment variables → Config file (~/.finfocus/config.yaml) → Defaults
Key environment variables: FINFOCUS_LOG_LEVEL, FINFOCUS_LOG_FORMAT, FINFOCUS_TRACE_ID, FINFOCUS_PLUGIN_*
finfocus --debug cost projected --pulumi-json plan.json # Debug outputCI/CD
All PRs must pass: unit tests with race detection, 61% coverage gate, golangci-lint v2.9.0, govulncheck, cross-platform builds (Linux/macOS/Windows, amd64/arm64).
Feature Development
New features MUST use SpecKit workflow (/speckit.specify → /speckit.clarify → /speckit.plan → /speckit.tasks → /speckit.analyze → /speckit.implement). Minor bug fixes don't require SpecKit.
Constitution
The constitution (.specify/memory/constitution.md) takes absolute precedence. Key principles: no TODOs or stubs, complete implementation required, high test coverage mandatory.
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.

