Paths: File paths (references/,../ln-*) are relative to this skill directory.
Type: L2 Domain Coordinator Category: 8XX Optimization
Performance Optimizer
Runtime-backed multi-cycle optimization coordinator. Profiles, researches, validates, and executes optimization hypotheses until target reached, plateau detected, or budget exhausted.
Inputs
| Input | Required | Description | |-------|----------|-------------| | target | Yes | endpoint, function, or pipeline to optimize | | observed_metric | Yes | current performance problem | | target_metric | No | user or research-derived target | | max_cycles | No | default 3 |
Purpose & Scope
- Detect whether optimization is the right tool
- Run iterative cycles:
profile -> gate -> research -> target -> context -> validate -> execute - Preserve optimization artifacts under
.hex-skills/optimization/{slug}/and runtime state under.hex-skills/optimization/runtime/runs/{run_id}/ - Resume deterministically from the last checkpointed phase
- Keep cycle summaries machine-readable
Runtime Contract
MANDATORY READ: Load references/ci_tool_detection.md MANDATORY READ: Load references/coordinator_runtime_contract.md, references/optimization_runtime_contract.md, references/coordinator_summary_contract.md
Runtime CLI:
node references/scripts/optimization-runtime/cli.mjs start --slug {slug} --manifest-file .hex-skills/optimization/{slug}/manifest.json
node references/scripts/optimization-runtime/cli.mjs status --slug {slug}
node references/scripts/optimization-runtime/cli.mjs record-worker-result --payload '{...}'
node references/scripts/optimization-runtime/cli.mjs record-summary --payload '{...}'
node references/scripts/optimization-runtime/cli.mjs record-cycle --payload '{...}'
node references/scripts/optimization-runtime/cli.mjs checkpoint --phase PHASE_8_EXECUTE --payload '{...}'
node references/scripts/optimization-runtime/cli.mjs advance --to PHASE_9_CYCLE_BOUNDARY
Runtime Layout
Runtime state is run-scoped, while optimization artifacts stay slug-scoped:
.hex-skills/optimization/
runtime/active/ln-810/{slug}.json
runtime/runs/{run_id}/manifest.json
runtime/runs/{run_id}/state.json
runtime/runs/{run_id}/checkpoints.json
runtime/runs/{run_id}/history.jsonl
runtime-artifacts/runs/{run_id}/optimization-coordinator/ln-810--{slug}.json
runtime-artifacts/runs/{run_id}/optimization-worker/{worker}--{child_identifier}.json
{slug}/context.md
{slug}/ln-814-log.tsv
Workflow
Phase 0: Preflight
- Validate:
- target identifiable
- observed metric provided
- git clean state
- test infrastructure exists
- Detect stack and optional service topology.
- Derive slug.
- Build manifest with:
slugtargetobserved_metrictarget_metricexecution_modecycle_config- Start runtime and checkpoint
PHASE_0_PREFLIGHT.
Phase 1: Parse Input
- Normalize the problem statement.
- Set or defer
target_metric. - Checkpoint
PHASE_1_PARSE_INPUT.
Phase 2: Profile
- Compute deterministic child metadata:
identifier=ln-811--{slug}--cycle-{current_cycle}- child
run_id - exact
summaryArtifactPath=.hex-skills/runtime-artifacts/runs/{parent_run_id}/optimization-worker/ln-811--{slug}--cycle-{current_cycle}.json - Checkpoint
PHASE_2_PROFILEwithchild_run. - Invoke
ln-811-performance-profilerwith the childrunIdand exactsummaryArtifactPath. - Read the emitted
optimization-workersummary envelope from the exact artifact path. - Record the worker summary with
record-worker-result.
Phase 3: Wrong Tool Gate
Evaluate profiler output:
| Gate | Meaning | Action | |------|---------|--------| | PROCEED | optimization work is justified | continue | | CONCERNS | measurements usable but imperfect | continue with warning | | BLOCK | wrong tool, already optimized, or infrastructure-bound | aggregate and exit | | WAIVED | user overrides BLOCK | continue with explicit waiver |
Rules:
- cycle 1
BLOCK-> finish as diagnostic result - cycle 2+
BLOCKdue toalready_optimizedorwithin_industry_norm-> finish as successful stop
Checkpoint PHASE_3_WRONG_TOOL_GATE with:
gate_verdictstop_reasonwhen blockedfinal_resultwhen terminal
Phase 4: Research
- Compute deterministic child metadata for
ln-812. - Checkpoint
PHASE_4_RESEARCHwithchild_run. - Invoke
ln-812-optimization-researcherwith the childrunIdand exactsummaryArtifactPath. - Read and record the emitted
optimization-workersummary envelope. - If no hypotheses remain, stop after aggregate/report.
Phase 5: Set Target
- Resolve target metric:
- user-specified target wins
- otherwise use research target with confidence
- otherwise default to 50% improvement
- Checkpoint
PHASE_5_SET_TARGETwithtarget_metric.
Phase 6: Write Context
- Build
.hex-skills/optimization/{slug}/context.md. - Include:
- problem statement
- performance map
- target metrics
- hypotheses and conflicts
- local codebase findings
- previous cycles
- Checkpoint
PHASE_6_WRITE_CONTEXTwithcontext_file.
Phase 7: Validate Plan
- Compute deterministic child metadata for
ln-813. - Checkpoint
PHASE_7_VALIDATE_PLANwithvalidation_verdictandchild_run. - Invoke
ln-813-optimization-plan-validatorwith the childrunIdand exactsummaryArtifactPath. - Read and record the emitted
evaluation-coordinatorsummary envelope. - If verdict is
NO_GO, pause runtime until user resolves or waives.
Phase 8: Execute
execution_mode=execute:
- Compute deterministic child metadata for
ln-814. - Checkpoint
PHASE_8_EXECUTEwithchild_run. - Invoke
ln-814-optimization-executorwith the childrunIdand exactsummaryArtifactPath. - Read and record the emitted
optimization-workersummary envelope.
execution_mode=plan_only:
- Do not run
ln-814. - Checkpoint
PHASE_8_EXECUTEasskipped_by_mode.
Phase 9: Cycle Boundary
- Record the cycle summary with
record-cycle. - Evaluate stop conditions:
- target met
- plateau
- max cycles reached
- no new hypotheses
- If continuing:
- merge previous branch when needed
- increment
current_cycle - checkpoint
PHASE_9_CYCLE_BOUNDARY - advance back to
PHASE_2_PROFILE - If stopping:
- checkpoint
PHASE_9_CYCLE_BOUNDARYwithstop_reason - advance to
PHASE_10_AGGREGATE
Phase 10: Aggregate
- Aggregate all cycle summaries from runtime state.
- Compute cumulative improvement.
- Checkpoint
PHASE_10_AGGREGATE.
Phase 11: Report
- Produce final report with:
- per-cycle summary
- cumulative improvement
- final result
- gap analysis when target not met
- Checkpoint
PHASE_11_REPORTwith: report_ready=truefinal_result- Record the
optimization-coordinatorsummary envelope withrecord-summary. - Complete runtime only after the report checkpoint and coordinator summary exist.
Worker Invocation (MANDATORY)
Host Skill Invocation: Skill(skill: "...", args: "...") is mandatory delegation.
- Claude: call the Skill tool exactly as shown.
- Codex: if no Skill tool exists, locate the named skill in available skills, read its
SKILL.md, treatargsas$ARGUMENTS, execute that skill workflow, then return here with its result/artifact. - Do not inline worker logic or mark the worker complete without executing the target skill.
| Phase | Skill | Purpose | |-------|--------|---------| | 2 | ln-811-performance-profiler | Build measured performance map | | 4 | ln-812-optimization-researcher | Research hypotheses and targets | | 7 | ln-813-optimization-plan-validator | Validate feasibility via evaluation-platform review (L2 Coordinator) | | 8 | ln-814-optimization-executor | Execute optimization strike and bisect |
Skill(s