spec.md
107 lines · skills/ce-optimize/references/spec.md at 3449230
Most marks come from matching words in the file, so treat them as pointers.
Phase 0: input type and the optimization spec
Read this at the start of Phase 0. It carries how to tell a spec path from a goal description, and how to load, build, or validate the spec before CP-0. The schemas it validates against are references/optimize-spec-schema.yaml and references/experiment-log-schema.yaml.
Horizon: continue while another measurement or experiment is worthwhile within the stopping rules. Start serial until measurement is trusted. Stop as soon as a stopping criterion holds.
Raw lines 1 to 60.1 Determine Input Type
Check whether the input is:
- A spec file path (ends in
.yamlor.yml): read and validate it - A description of the optimization goal: help the user create a spec interactively
0.2 Load or Create Spec
If spec file provided:
- Read the YAML spec file. The orchestrating agent parses YAML natively -- no shell script parsing.
- Validate the spec against every rule in the
validation_rulessection ofreferences/optimize-spec-schema.yaml. That section is the single source of truth for what a valid spec requires. Do not rely on a remembered subset; conditional rules such as the singleton-rubric and exclusive-resources requirements live only there. - If any rule fails, report the specific failures and ask the user to fix them before proceeding
If description provided:
- Analyze the project to understand what can be measured.
references/usage-guide.mdhas longer kickoff prompt shapes if the interview needs them. - Detect whether the optimization target is qualitative or quantitative. This determines
type: hardvstype: judgeand is the single most important spec decision:
**Use type: hard** when:
- The metric is a scalar number with a clear "better" direction
- The metric is objectively measurable (build time, test pass rate, latency, memory usage)
- No human judgment is needed to evaluate "is this result actually good?"
- Examples: reduce build time, increase test coverage, reduce API latency, decrease bundle size
If the user names more than one hard success condition that must all hold (local wall time and CI critical path and runner-minutes, for example), put them in metric.objectives as role: required and keep metric.primary as the ranking key. A spec without metric.objectives keeps single-primary acceptance. If each evaluation costs minutes, set measurement.stability.mode: ladder with a relative or paired comparison and a futility bound; do not spend the full confirmation protocol on every exploratory experiment. Start from references/example-expensive-benchmark-spec.yaml for that shape.
**Use type: judge** when:
- The quality of the output requires semantic understanding to evaluate
- A human reviewer would need to look at the results to say "this is better"
- Proxy metrics exist but can mislead (e.g., "more clusters" does not mean "better clusters")
- The optimization could produce degenerate solutions that look good on paper
- Examples: clustering quality, search relevance, summarization quality, code readability, UX copy, recommendation relevance
IMPORTANT: If the target is qualitative, **strongly recommend type: judge**. Explain that hard metrics alone will optimize proxy numbers without checking actual quality. Show the user the three-tier approach:
- Degenerate gates (hard, cheap, fast checks that reject a candidate outright): catch obviously broken solutions such as "all items in 1 cluster" or "0% coverage". Run first. If any gate fails, skip the expensive judge step.
- LLM-as-judge (the actual optimization target): sample outputs, score them against a rubric, aggregate. This is what the loop optimizes.
- Diagnostics (logged, never used to reject): distribution stats, counts, timing. These help explain WHY a judge score changed.
If the user insists on type: hard for a qualitative target, proceed but warn that the results may optimize a misleading proxy.
Exemplars for the validity gate. A person's input is needed only where the score is itself a judgment. When the primary is measured objectively (a duration, a size, a count, a pass rate over fixed cases), ask the user for nothing here: the measurement is its own ground truth, and Phase 1 builds the shortcut probe itself. When the primary is a judgment (type: judge, or a hard metric standing in for a quality the user would otherwise rate), use the known-good and known-bad outputs the project already has (recorded failures, fixtures, the cases of a text target) and ask the user only for what is missing: a few outputs they would score at the top and a few at the bottom. A user who has none to give is not blocked; Phase 1 runs the probes it can and states the rest as a limitation at approval. When the target is instruction text (a skill, an agent-instructions file, a persona, a tool description), read references/text-targets.md before going further: the eval set and the hypothesis moves differ from a code target.
- Design the sampling strategy (for
type: judge):
Guide the user through defining stratified sampling. The key question is: "What parts of the output space do you need to check quality on?"
Walk through these questions:
- What does one "item" look like? (a cluster, a search result page, a summary, etc.)
- What are the natural size/quality strata? (e.g., large clusters vs small clusters vs singletons)
- Where are quality failures most likely? (e.g., very large clusters may be degenerate merges; singletons may be missed groupings)
- What total sample size balances cost vs signal? (default: 30 items, adjust based on output volume)
Example stratified sampling for clustering: ```yaml stratification:
- bucket: "top_by_size" # largest clusters: check for degenerate mega-clusters count: 10
- bucket: "mid_range" # middle of non-solo cluster size range: representative quality count: 10
- bucket: "small_clusters" # clusters with 2-3 items: check if connections are real count: 10 singleton_sample: 15 # singletons: check for false negatives (items that should cluster) ```
The sampling strategy is domain-specific. For search relevance, strata might be "top-3 results", "results 4-10", "tail results". For summarization, strata might be "short documents", "long documents", "multi-topic documents".
Singleton evaluation is critical when the goal involves coverage. Sampling singletons with the singleton rubric checks whether the system is missing obvious groupings.
- Design the rubric (for
type: judge):
Help the user define the scoring rubric. A good rubric:
- Has a 1-5 scale (or similar) with concrete descriptions for each level
- Includes supplementary fields that help diagnose issues (e.g.,
distinct_topics,outlier_count) - Is specific enough that two judges would give similar scores
- Does NOT assume bigger/more is better. "3 items per cluster average" is not inherently good or bad
- Asks for a per-item
feedbackstring (what is wrong, what would fix it); the judge template requires it and Phase 3 generates hypotheses from it
Example for clustering: ```yaml rubric: | Rate this cluster 1-5:
- 5: All items clearly about the same issue/feature
- 4: Strong theme, minor outliers
- 3: Related but covers 2-3 sub-topics that could reasonably be split
- 2: Weak connection: items share superficial similarity only
- 1: Unrelated items grouped together Also report: distinct_topics (integer), outlier_count (integer) ```
- Guide the user through the remaining spec fields:
- What degenerate cases should be rejected? (degenerate gates, for example "solo_pct <= 0.95" catches all-singletons and "max_cluster_size <= 500" catches mega-clusters)
- What command runs the measurement?
- What files can be modified? What is immutable?
- Any constraints or dependencies?
- If this is the first run: recommend
execution.mode: serial,execution.max_concurrent: 1,stopping.max_iterations: 4, andstopping.max_hours: 1 - If the user named multiple required hard targets or an expensive harness: recommend
metric.objectivesplusstability.mode: ladderas above, and showreferences/example-expensive-benchmark-spec.yaml - If
type: judge: recommendsample_size: 10,batch_size: 5, andmax_total_cost_usd: 5until the rubric and harness are trusted - Holdout: a held-out set the loop confirms against but never selects from.
measurement.holdout.command(same JSON shape as the measurement command), or for a judge primarymetric.judge.confirmation_seeddistinct fromsample_seed, whose sample shares no item with the selection sample. Required fortype: judgeand when the run waits between ticks through a wake after turn end (references/persistence.md, The Wait Record and Ticks); otherwise recommended, and its absence is stated at the approval gate - If
type: judge: do not ask for hand-scored examples here. When the user already has a labeled sample, name it inmetric.judge.calibration.labels; otherwise leave it unset, and Phase 1 offers a short guided check once the baseline has been judged (references/measurement.md1.3) - Per-case results: when the harness can emit a
casesmap (case id to pass/fail), setmeasurement.per_case: trueso keeps and the wrap-up report which cases the baseline passed and the candidate fails - Write the spec to
<state-root>/spec.yaml, with<state-root>resolved byreferences/persistence.md(The State Root) - Present the proposed scope, behavior constraints, measurement approach, and limits for approval before proceeding, with a link to the saved spec. Apply the SKILL.md body's user-facing reporting rule. Put whatever the user is being asked to judge in front of them: for a judge primary that is the rubric's scale, level by level, because it is their definition of better and they cannot approve it from a link to a file. Send all of that as an ordinary message, laid out so it is easy to read (the scale as a list, scope and limits on their own lines), and only then ask. The question itself is one short sentence and its options: a question picker shows long text as a single cramped block.