ywc-infra-optimize
(ywc) Use when improving existing infrastructure: cost right-sizing, unused resource cleanup, reserved/spot adoption, drift remediation, and reliability hardening for AWS, GCP, Azure, or K8s. Triggers: "인프라 개선", "비용 최적화", "optimize infrastructure", "インフラ最適化", "ywc-infra-optimize". Do not use for greenfield infrastructure design (use ywc-infra-design), first-time IaC authoring (use ywc-iac-author), pre-apply review (use ywc-infra-review), or app hotspots (use ywc-performance-engineer).
- License 许可
- MIT
- 最近更新
- 2026-11-08
- Stars
- ★ 8
- Forks
- 1
01 前言 Front Matter
- name
- ywc-infra-optimize
- description
- (ywc) Use when improving existing infrastructure: cost right-sizing, unused resource cleanup, reserved/spot adoption, drift remediation, and reliability hardening for AWS, GCP, Azure, or K8s. Triggers: "인프라 개선", "비용 최적화", "optimize infrastructure", "インフラ最適化", "ywc-infra-optimize". Do not use for greenfield infrastructure design (use ywc-infra-design), first-time IaC authoring (use ywc-iac-author), pre-apply review (use ywc-infra-review), or app hotspots (use ywc-performance-engineer).
02 资源文件 5
- 参考文档agents/openai.yaml552 B
- 参考文档README.en.md2.8 KB
- 参考文档README.ja.md2.9 KB
- 参考文档README.ko.md2.9 KB
- 参考文档README.md2.9 KB
03 SKILL.md 正文
ywc-infra-optimize
Announce at start: "I'm using the ywc-infra-optimize skill to improve existing infrastructure under a SAFE/CAUTION/DANGER change loop with per-item terraform plan verification."
This skill is the infra counterpart to ywc-refactor-clean: cost right-sizing, unused-resource removal, reserved/spot adoption, drift detection, and reliability hardening planning against infrastructure that already exists. It borrows refactor-clean's Iron Law discipline — three independent witnesses before any change is recommended — but, in Codex v1, it is a planning and classification surface, not an execution worker. Terraform is the single fixed IaC tool for this toolkit; every analysis stops at terraform plan, never apply. SAFE, CAUTION, and DANGER classify how conservative the recommended next action should be; actual .tf edits route back through ywc-iac-author.
The Iron Law
NEVER RECOMMEND A CHANGE AS READY WITHOUT (1) COST/UTILIZATION DATA CONFIRMS THE CANDIDATE + (2) A PER-ITEM TERRAFORM PLAN CONFIRMS THE EXACT BLAST RADIUS + (3) THE CHANGE IS REVERSIBLE OR A SNAPSHOT EXISTS BEFORE IT LANDS
A resource a cost report flags "idle" but a per-item terraform plan shows referenced by another module or a DR failover path is not SAFE — that is a live dependency hiding behind a stale metric. An instance CloudWatch/Cloud Monitoring shows at 4% average CPU but that is a nightly-batch instance's daytime trough is not confirmed over-provisioned — utilization data needs a representative window (see ../references/infra/lenses/cost.md's p95 guidance), not a single snapshot. Single-source confidence is not confirmation; the discipline requires an independent data witness (cost/utilization report) plus a blast-radius witness (terraform plan) plus a reversibility guarantee — mirroring refactor-clean's tool + grep + test triad.
If a previously recommended SAFE change later proves risky, re-classify the item to CAUTION or DANGER before any authoring pass. Do not keep presenting it as SAFE once new evidence contradicts the original witnesses.
Rationalization Defense
When tempted to bypass a rule, check this table first:
| Excuse | Reality |
|---|---|
| "I'll batch all the SAFE changes into one recommendation and let someone figure it out later" | The point of SAFE is narrow blast radius and clear next action. A vague multi-item blob hides which change is actually low risk and which one needs a different owner. |
| "The cost tool says this resource is idle, so it's safe to destroy — skipping the third witness" | A cost report is one signal, not confirmation. It cannot see a DR failover target, a quarterly batch job's off-cycle trough, or a cross-module reference the terraform plan blast-radius witness would catch. Skipping the plan witness or the reversibility check turns "the tool said so" into the sole basis for an irreversible action. |
| "This CAUTION item looks low-risk, I'll auto-execute it anyway" | CAUTION exists precisely because "looks low-risk" is a judgment this skill is not authorized to make alone — reserved/spot adoption commits spend, and ambiguous utilization needs a human-reviewed authoring pass, not a confident guess. |
| "I'll skip the per-item plan confirmation since the batch plan already looked clean" | A batch-level terraform plan can hide a wider blast radius inside one item. Per-item confirmation is what proves the exact resource changed, and nothing else did — the batch-level view cannot substitute for it. |
"I'm already running ywc-infra-review, I'll execute the fix in the same pass" |
ywc-infra-review is diagnosis-only by design and has no write access. This skill is also diagnosis-and-planning only in Codex v1; remediation is always a separate authoring pass. |
"The terraform plan for this DB destroy came back clean, so it's fine to proceed" |
plan succeeding proves syntactic validity, not safety. A destroy against a stateful resource is DANGER regardless of how confident the plan or the classification tool is — it escalates, it never auto-executes. |
Violating the letter of these rules is violating the spirit. An optimization pass that trusts a single signal or turns planning into stealth execution turns a cost-saving loop into an outage risk.
Arguments
| Parameter | Format | Example | Description |
|---|---|---|---|
--scope |
--scope <path> |
--scope infra/modules/compute |
Restrict gather/classify/execute to a single Terraform module or path. Default: full IaC tree / live infrastructure. |
--dry-run |
flag | --dry-run |
Run gather + classify only and skip optional advisory follow-ups. Since this skill does not execute changes, --dry-run mainly suppresses extra planning detail. |
--skip-verify-done |
flag | --skip-verify-done |
Skip the final ywc-verify-done handoff. Only valid when the upstream caller (e.g., a scheduled hygiene orchestrator) will run it. |
Workflow
Step 1: Determine scope + gather current state
Determine scope from --scope, or default to the full IaC tree / live infrastructure. Run terraform plan (or terraform plan -detailed-exitcode) directly against the scoped module tree — this is the drift-detection signal: live infrastructure that has diverged from the committed .tf state.
Dispatch a Codex worker carrying the ywc-performance-engineer persona in read-only diagnostic mode, carrying the scoped Terraform and an explicit pointer to ../references/infra/lenses/cost.md and ../references/finops.md, to produce the cost/utilization report: idle or orphaned resources, over-provisioned compute (against observed p95), and pricing-model mismatches (on-demand load that should be reserved/spot).
Fan-out return contract: this skill dispatches two workers (Steps 1 and 3). Each dispatch must return the bounded status payload from
../references/subagent-status-actions.md§3.5 —Status | 1-line summary | artifact path | Concerns (<=10 lines), with full findings/plans written to a file whose path is returned.
Step 2: Classify into SAFE / CAUTION / DANGER
Sort every candidate into exactly one tier. Items that match multiple tiers escalate to the highest tier — same rule as ywc-refactor-clean.
| Tier | Pattern | Action |
|---|---|---|
| SAFE | Cost/drift: confirmed-idle resource (zero utilization over a representative window + terraform plan shows no other module references it); a clearly over-provisioned instance (e.g., <10% p95 CPU) with an unambiguous right-size target; drift where live state simply matches an already-approved-but-unapplied .tf change. Reliability hardening (additive, reversible, no recreation): enabling automated backups / point-in-time recovery on a store that lacks them, adding a missing health/readiness check, raising an autoscaling floor to min >= 2, enabling deletion protection — checked against ../references/infra/lenses/reliability.md |
Step 3 — prepare a low-risk remediation plan |
| CAUTION | Reserved/Spot adoption (commits spend or trades availability); a resource with moderate or ambiguous utilization; drift where live diverges from code in a way that looks intentional (manual hotfix); right-sizing a resource with recent scaling history; adding a multi-AZ standby or read replica (cost + failover implications) | Step 4 — escalate, do not execute |
| DANGER | Any destroy or recreate against a stateful resource (database, volume, bucket) regardless of tool confidence — including a reliability change whose plan would recreate rather than update the resource; a resource tagged/tied to compliance or DR; anything git log shows touched in the last 7 days |
Step 4 — escalate, never execute in this skill |
Step 3: SAFE planning loop
For each SAFE item, in order — reliability-hardening SAFE items flow through this identical loop, checked against ../references/infra/lenses/reliability.md instead of the cost lens:
- Re-confirm the signal is still current. Data gathered in Step 1 (cost/utilization for cost items, the config gap itself for reliability items) can go stale on a large scope — re-check the specific resource before executing.
- Capture the per-item plan baseline. Run a per-item
terraform planon the target resource before recommending remediation — pre-state evidence that nothing beyond the classified candidate is already drifting. - Optionally consult the read-only
ywc-cloud-engineerpersona when feasibility, provider nuance, or blast-radius interpretation is unclear. That consult stays advisory: it does not author files. - Record the recommended next action. For example:
ywc-iac-authorshould remove an idle resource block, adjustinstance_type, add a backup setting, or fix drift with the minimal.tfedit. Include the expected blast radius in the recommendation. - Reject false SAFE cases. If the per-item plan is wider than expected, or the consult exposes hidden coupling, re-classify the item to CAUTION and do not recommend it as SAFE.
Step 4: Escalate by tier, do not execute
For each SAFE, CAUTION, or DANGER item, emit a report entry (Output Format below) with the rationale and a concrete suggested next step — usually $ywc-iac-author for a reviewed remediation patch, or a direct question back to the user for a reserved/spot capacity commitment. SAFE means "low-risk to author next", not "execute here". DANGER especially never auto-executes regardless of how the classification tool scored it.
Step 5: Verify-done handoff
Hand off to $ywc-verify-done with the optimization report (Output Format below). Mandatory unless --skip-verify-done was passed by an upstream caller that will perform its own verify.
Output Format
Infra Optimize Report
─────────────────────────────────────────────────
Scope: infra/ (or --scope value)
Drift detected: 2 resources diverged from committed .tf state
Cost/utilization signal: ywc-performance-engineer persona (cost lens)
Planned next actions (SAFE):
- aws_eip.unused-1 remove via $ywc-iac-author; expected plan: destroy only this idle EIP
- aws_instance.worker right-size via $ywc-iac-author: m5.4xlarge -> m5.large
Escalated (CAUTION — not auto-authored):
- aws_instance.batch-runner moderate utilization, recent scaling history — needs manual review
Escalated (DANGER — not auto-authored):
- aws_db_instance.legacy plan shows a destroy — stateful, requires explicit human approval
Verification (per ywc-verify-done):
$ terraform plan (per-item, evidence only)
exit 0 (PASS — blast radius matched expectation on all 2 SAFE candidates)
─────────────────────────────────────────────────
Estimated monthly delta: -$340 (order of magnitude, cost lens estimate)
Validation Checklist
Before declaring the optimization pass complete, verify:
- [ ] Drift detection (
terraform plan) ran against the declared scope - [ ] Cost/utilization signal was gathered via the
ywc-performance-engineerpersona before classification - [ ] Every candidate is classified into exactly one tier (SAFE / CAUTION / DANGER); multi-tier matches escalate to the highest
- [ ] Every SAFE item captured a per-item
terraform planbaseline and an expected narrow blast radius before being recommended - [ ] Reliability-hardening candidates (missing backups/PITR, health checks, autoscaling floors, deletion protection) were classified alongside cost/drift candidates, not skipped
- [ ] No SAFE / CAUTION / DANGER item was executed in this skill — all are reported with next actions only
- [ ] No
terraform applywas run at any point - [ ] Final
$ywc-verify-doneblock uses the canonical wording (PASS / FAIL), unless--skip-verify-donewas passed
Common Mistakes
- Treating a clean per-item
terraform planas sufficient for a stateful destroy.planproves syntactic correctness, not safety — a destroy against a database is DANGER regardless of how clean the plan looks. - Re-using Step 1's cost/utilization snapshot for every item without re-checking. Signals age; a resource idle three days ago at gather-time may be back in active use by execute-time on a slow-moving scope.
- Treating SAFE as permission to edit immediately. SAFE means the evidence supports a low-risk follow-up authoring pass, not that this skill can write Terraform directly.
- Running this skill during a
ywc-infra-reviewpass instead of separately. Review is diagnosis-only and has no write access by design; mixing execution into a review pass collapses a boundary the rest of the toolkit relies on.
Integration
- Upstream:
ywc-infra-review(diagnosis that surfaces the cost/drift/reliability findings this skill classifies); direct user invocation for a scheduled optimization pass. - Downstream:
ywc-verify-done(mandatory final claim, unless skipped);ywc-iac-author(re-authoring path for SAFE, CAUTION, and DANGER follow-ups). - Consults:
ywc-performance-engineerpersona (cost/utilization signal, Step 1);ywc-cloud-engineerpersona (read-only feasibility and blast-radius consult, Step 3). - Must not be paired with: greenfield topology design (
ywc-infra-design), first-time authoring (ywc-iac-author), or a pre-apply-only review pass (ywc-infra-review) — those own separate lifecycle phases.
References
| Reference | Use when |
|---|---|
../references/infra/lenses/cost.md |
Step 1 — cost/utilization signal gathering, right-sizing and waste taxonomy |
../references/finops.md |
Step 1 — the detailed FinOps taxonomy (reserved/spot, data-transfer cost) the ywc-performance-engineer persona reviews against |
../references/infra/lenses/reliability.md |
Step 2/3 — classification taxonomy for reliability-hardening SAFE/CAUTION candidates (backups, health checks, autoscaling floors, deletion protection, multi-AZ) and the guardrail against a cost change dropping below the reliability floor |
../references/subagent-status-actions.md |
Steps 1 and 3 — the §3.5 bounded status-return contract each dispatch must follow so fan-out returns stay bounded |
ywc-verify-done |
Step 5 — per-batch verification block shape (command + exit code + claim) — mandatory unless --skip-verify-done |
04 同仓库更多 Skills
missing-frontmatter
暂无简介
malformed-frontmatter
暂无简介
fixture-501-fail
(ywc) Use when aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Do not use for x.
fixture-500-pass
(ywc) Use when aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Do not use for x.
ywc-worktrees
(ywc) Use when creating, auditing, pruning, or resolving git worktrees for isolated task workspaces, whether delegated from an executor or used standalone. Triggers: "worktree 생성", "worktree audit", "worktree 정리", "worktree prune", "ywc-worktrees", "create worktree". Do not use for branch creation/deletion alone, PR creation (use ywc-create-pr), CI or merge delivery (use ywc-finish-branch), task orchestration (use ywc-sequential-executor or ywc-parallel-executor), or non-git isolation.
ywc-wayfinder
(ywc) Use when a large or uncertain change needs multi-session discovery with a deterministic local map and exactly one active ticket before planning or implementation. Triggers: "wayfinder", "길찾기", "discovery map", "multi-session discovery", "탐색 ticket", "経路整理", "探索マップ", "ywc-wayfinder". Do not use for ordinary planning (use ywc-plan), idea clarification (use ywc-brainstorm), direct implementation, or tracker/database writes outside the local Markdown map.