use crate::command::CommandStatus;
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, schemars::JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Kind {
Error,
Stop,
Warning,
}
impl Kind {
#[must_use]
pub const fn prefix(self) -> &'static str {
match self {
Self::Error => "error",
Self::Stop => "stopped",
Self::Warning => "warning",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Entry {
pub name: &'static str,
pub kind: Kind,
pub status: CommandStatus,
pub title: &'static str,
pub explain: &'static str,
pub fix: &'static [&'static str],
}
pub const DOCS: &str = "https://hupe1980.github.io/speccoder/docs/codes/";
impl Entry {
#[must_use]
pub fn docs(&self) -> String {
format!("{DOCS}#{}", self.name.to_ascii_lowercase())
}
}
use CommandStatus as S;
use Kind::{Error as E, Stop as P, Warning as W};
macro_rules! entry {
($name:literal, $kind:expr, $status:expr, $title:literal, $explain:literal, [$($fix:literal),+ $(,)?]) => {
Entry { name: $name, kind: $kind, status: $status, title: $title, explain: $explain, fix: &[$($fix),+] }
};
}
pub const CATALOG: &[Entry] = &[
entry!(
"USAGE",
E,
S::UsageError,
"the arguments are not valid for this command",
"The command line could not be parsed: an unknown flag, a missing value, or a value outside the allowed set.",
["speccoder {command} --help"]
),
entry!(
"USAGE-CONFLICT",
E,
S::UsageError,
"two options were given that exclude each other",
"`--json` prints one result object and `--events` prints a stream of events ending in that object; a command does one or the other.",
["speccoder {command} --events", "speccoder {command} --json"]
),
entry!(
"USAGE-UNKNOWN-CODE",
E,
S::UsageError,
"there is no code by that name",
"`speccoder explain` knows the codes speccoder itself prints; the closest names are listed with the error.",
["speccoder explain --list"]
),
entry!(
"CALL-CHANGED",
E,
S::UsageError,
"the call waiting now is not the one that was shown",
"An approval or rejection from an interface names the call it showed and that call's object. The call expired or was decided and another waits now, or the attempt stopped on another object; nothing was decided.",
["speccoder report --approvals"]
),
entry!(
"INTERNAL",
E,
S::Error,
"speccoder failed in a way it does not expect",
"An unexpected failure inside speccoder: an IO error, a broken state file, a bug. The message says what failed.",
["→ re-run with -v and report the output at https://github.com/hupe1980/speccoder/issues"]
),
entry!(
"NO-PROJECT",
E,
S::NotAProject,
"speccoder works on a Spec Kit or OpenSpec project, and found none here",
"No `.specify/` (Spec Kit) or `openspec/` (OpenSpec) directory was found here or above. Spec Kit makes one (`--integration claude` installs the skills speccoder runs); then `speccoder init` and `speccoder spec specify` take it from there.",
["specify init --here --integration claude", "openspec init"]
),
entry!(
"SPEC-DIAGNOSTICS",
E,
S::DiagnosticsError,
"the spec artifacts have errors speccoder will not guess around",
"The task list or spec could not be read as written: a dependency on a task that does not exist, a cycle, a malformed task line. `inspect` lists every diagnostic with its line.",
["speccoder inspect"]
),
entry!(
"FEATURE-SELECTION",
E,
S::SelectionNeeded,
"more than one feature could be meant",
"Several features exist and none is current: neither `--feature`, the format's variable nor its pointer (Spec Kit: `.specify/feature.json`) names one. Make one current, or name it for this command.",
[
"speccoder feature",
"speccoder feature <name>",
"speccoder {command} --feature <name>"
]
),
entry!(
"CHECK-BROKEN",
E,
S::ConfigError,
"a check cannot run on the untouched code",
"A fast check failed on the untouched worktree without running a test: a command or profile it names is missing, a file it needs was never committed, or it does not build. It could never judge the task, so nothing was attempted.",
[
"speccoder doctor",
"git status",
"speccoder run --allow-failing-baseline"
]
),
entry!(
"FEATURE-GONE",
E,
S::SelectionNeeded,
"the current feature no longer exists",
"The format's pointer (Spec Kit: `.specify/feature.json`) or its variable names a feature directory that is not there — renamed, deleted, or from another checkout.",
[
"speccoder feature",
"speccoder feature <name>",
"speccoder feature --clear"
]
),
entry!(
"REVIEW-PENDING",
P,
S::NeedsHuman,
"the spec is not approved yet",
"`[review] required` is on: a run waits until every requirement of the spec is approved on its current wording, in the review committed with it (`review.json`). A requirement reworded since its approval needs approving again.",
["speccoder review", "speccoder review approve", "git commit"]
),
entry!(
"REVIEW-AMBIGUOUS",
P,
S::NeedsHuman,
"two readings of a requirement disagree",
"Two independent test authors read a scenario two ways (the same given, different expected outcomes). Until you choose a reading or reword the requirement, it is not approved, its tests are not frozen, and a gated run (`[review] required`) waits.",
[
"speccoder review tests <REQ> --reading A <scenario>",
"speccoder review tests <REQ> --reading B <scenario>",
"→ or reword the scenario so it reads one way"
]
),
entry!(
"REVIEW-NO-SCENARIOS",
E,
S::UsageError,
"the requirement has no scenarios to write tests from",
"Tests are written at review per requirement from its acceptance scenarios. The requirement named has none (or the format yields no requirement by that key), so there is nothing to derive a test from.",
[
"speccoder review",
"→ add acceptance scenarios to the requirement"
]
),
entry!(
"REVIEW-TESTS-OWN-PIPELINE",
E,
S::UsageError,
"this unit's tests are written by its own pipeline",
"A quick change writes its own tests and a bug's reproductions are confirmed by you; review writes no second set for them.",
["speccoder do \"…\"", "speccoder bug confirm <unit>/<task>"]
),
entry!(
"ACCEPTANCE-OFF",
E,
S::ConfigError,
"acceptance tests are turned off",
"`[acceptance] generate = false`: no acceptance tests are written, at review or at run time.",
["speccoder config set acceptance.generate true"]
),
entry!(
"ORACLE-AUTHOR-FAILED",
E,
S::RunFailed,
"the test author could not write the tests",
"The acceptance author call failed or the model provider refused it. Nothing was stored or frozen for the requirement; the message carries the provider's reason.",
["speccoder review tests <REQ> --write"]
),
entry!(
"ORACLE-TAMPERED",
P,
S::NeedsHuman,
"a frozen test no longer matches what was frozen",
"A test frozen at review is stored in the state directory with its digest. The stored file or its record no longer matches: reusing it would run tests nobody approved, so the task stops and nothing is ticked.",
[
"speccoder review tests <REQ>",
"→ write and approve the tests again, or run without the frozen set"
]
),
entry!(
"ORACLE-FROZEN",
E,
S::UsageError,
"the requirement's tests are frozen with the approval",
"*Approve and Run* froze these tests and their held-out set, so they cannot be changed. Reword the requirement to lapse the freeze and write them again.",
[
"speccoder review",
"→ reword the requirement to lapse the freeze, then write its tests again"
]
),
entry!(
"REVIEW-CHANGED",
P,
S::NeedsHuman,
"what the approval would freeze changed since it was shown",
"What the approval sheet showed changed before the click (another tab asked again, a *Write Tests* finished). Nothing was approved; look again and approve what you see.",
[
"speccoder review",
"→ open the sheet again and approve what it shows"
]
),
entry!(
"REVIEW-UNREADABLE",
P,
S::NeedsHuman,
"the review record cannot be read",
"`review.json` (decisions, frozen tests, approval) or a record beside it is not valid. Reading it as empty would drop every decision and freeze, so speccoder stops until you look.",
[
"git diff -- <unit>/review.json",
"→ restore it from git (`git checkout -- <unit>/review.json`) or fix the JSON"
]
),
entry!(
"RUN-ACTIVE",
E,
S::GitPrecondition,
"a run is active for this project",
"*Approve and Run* starts a feature run; one is running already (in a terminal or the web app). Approving now would start a second run beside it.",
["speccoder report", "→ wait for the run to end, or stop it"]
),
entry!(
"AUTOPILOT-NEEDS-GRANT-OBJECTS",
E,
S::ConfigError,
"autopilot needs object-bound grants",
"Autopilot holds only grants the person saw in full and ticked, each bound to one resolved object (a canonical path, an exact argv, an MCP tool digest). This build has no such grants, so autopilot is off.",
["speccoder review approve --run ask"]
),
entry!(
"FEATURE-UNKNOWN",
E,
S::SelectionNeeded,
"no feature has that name or number",
"`--feature` (or `--change`) names a feature by its directory name, a part of it, or its number in `speccoder feature`'s list; none matches what was given.",
["speccoder feature", "speccoder report --feature <name>"]
),
entry!(
"CONFIG",
E,
S::ConfigError,
"the configuration or the environment is not usable",
"`speccoder.toml` or the environment does not allow this command to run; the message names what is wrong.",
["speccoder init"]
),
entry!(
"NO-STATE-DIR",
E,
S::ConfigError,
"speccoder has nowhere to keep its state",
"Journals, worktrees and live progress live in a state directory: `$SPECCODER_STATE_DIR`, else `$XDG_STATE_HOME/speccoder`, else `~/.local/state/speccoder`. None of these variables is set.",
["export SPECCODER_STATE_DIR=\"$PWD/.speccoder-state\""]
),
entry!(
"SANDBOX-UNAVAILABLE",
E,
S::ConfigError,
"the OS sandbox is not available and the project requires it",
"No OS sandbox is available (Linux without Landlock, a container without user namespaces, another OS) while `[sandbox] mode = \"required\"` or an autopilot run needs one.",
[
"→ run on macOS or Linux 6.2+ (Landlock ABI 3)",
"→ or set [sandbox] mode = \"auto\" to run unsandboxed and be told",
"→ autopilot: choose Ask on Risky Calls, or enable the OS sandbox"
]
),
entry!(
"GITHUB-AUTH",
E,
S::Error,
"not signed in to GitHub",
"No GitHub token was found (GH_TOKEN, GITHUB_TOKEN, or the one `speccoder auth login` keeps in your keychain), or GitHub refused it.",
[
"speccoder auth login --with-token",
"speccoder auth status",
"→ or set GH_TOKEN (a fine-grained token: Issues read; Pull requests read and write; Contents and Metadata read)"
]
),
entry!(
"GITHUB-FAILED",
E,
S::Error,
"the GitHub API could not do it",
"GitHub answered, and not as asked: no such issue, no access for the token, a rate limit used up, or GitHub did not answer in time. The message is GitHub's, in words.",
["speccoder auth status", "git remote -v"]
),
entry!(
"CONFIG-EXISTS",
E,
S::ConfigError,
"the project has a speccoder.toml already",
"`init` writes a new one; change the existing one with `speccoder config` (or Settings), or start over with `--force`.",
["speccoder config", "speccoder init --force"]
),
entry!(
"CONFIG-MISSING",
E,
S::ConfigError,
"the project has no speccoder.toml",
"speccoder needs to know which checks decide \"nothing regressed\" and which model to use; `init` detects them and writes a commented file.",
["speccoder init"]
),
entry!(
"CONFIG-INVALID",
E,
S::ConfigError,
"speccoder.toml has an error",
"An unknown section or key, a wrong type, or a value outside the allowed set. Unknown keys are errors so a typo never goes unnoticed.",
["→ fix the line the message names in speccoder.toml, then commit it"]
),
entry!(
"KEY-MISSING",
E,
S::ConfigError,
"the model provider's API key is not in the environment",
"speccoder reads API keys from the environment only. The message names the variable the configured provider needs.",
["→ export the variable the message names, e.g. export ANTHROPIC_API_KEY=…"]
),
entry!(
"NO-CHECKS",
E,
S::ConfigError,
"no check applies, so nothing could show that nothing regressed",
"Every configured check was skipped (`when_exists` did not match) or none is configured. A task cannot be judged without at least one check: add your test command as one.",
["speccoder config set checks.test.argv -- <your test command>"]
),
entry!(
"GIT",
E,
S::GitPrecondition,
"git is not in the state this command needs",
"A git precondition does not hold; the message names it.",
["git status"]
),
entry!(
"SETUP-INCOMPLETE",
E,
S::GitPrecondition,
"the project's setup is not committed, so every run would trip over it",
"A worktree holds only commits: a file the checks need but the checkout never committed (`speccoder.toml`, `.config/nextest.toml`), a lockfile the checks write, or build output `.gitignore` does not list. `speccoder fix` commits that setup once.",
["speccoder fix"]
),
entry!(
"NO-REPOSITORY",
E,
S::GitPrecondition,
"speccoder needs a git repository with at least one commit",
"Evidence lives in commits and refs, and work happens on a branch of its own, so the project must be a git repository with a first commit.",
["git init && git add -A && git commit -m init"]
),
entry!(
"UNCOMMITTED-INTENT",
E,
S::GitPrecondition,
"the spec has uncommitted changes the run would not see",
"speccoder reads committed files only — a worktree is checked out from a commit — so an uncommitted edit to the spec, plan or tasks would silently not count.",
["git status", "speccoder run --in-place"]
),
entry!(
"NO-REMOTE",
E,
S::GitPrecondition,
"there is no git remote to push to",
"`pr` pushes `speccoder/<feature>` to a remote and opens the pull request there; `issue` reads the remote's GitHub issues. Add the repository's GitHub address as a remote, or name the one to use.",
[
"git remote add origin <url>",
"git remote -v",
"speccoder pr --remote <name>"
]
),
entry!(
"WORKTREE-DIRTY",
E,
S::GitPrecondition,
"the feature's worktree has uncommitted changes",
"Work left in the worktree outside a commit — a failed attempt's, or an edit by hand — would be mixed into what comes next.",
["speccoder worktree", "speccoder run --feature {feature}"]
),
entry!(
"NOTHING-TO-HAND-OFF",
E,
S::GitPrecondition,
"the speccoder branch has nothing the base does not have",
"`pr` hands off work on `speccoder/<feature>`; there is none yet, or it is already merged.",
["speccoder run --feature {feature}"]
),
entry!(
"DIRTY-CHECKOUT",
E,
S::GitPrecondition,
"an in-place run needs a clean checkout",
"In place, the attempt runs in your checkout; uncommitted changes would be judged as the agent's.",
["git stash -u", "git commit -am wip"]
),
entry!(
"UNBORN-HEAD",
E,
S::GitPrecondition,
"the checkout has no commit yet",
"An in-place run branches from HEAD; there is no HEAD to branch from.",
["git add -A && git commit -m init"]
),
entry!(
"CONFIG-NOT-TRACKED",
E,
S::GitPrecondition,
"speccoder.toml must be committed",
"The judge's configuration is a reviewed input; an untracked or modified one could be changed without review.",
["git add speccoder.toml && git commit -m \"speccoder: config\""]
),
entry!(
"BRANCH-IN-WORKTREE",
E,
S::GitPrecondition,
"the feature's branch is checked out in a worktree",
"git refuses to check out a branch twice; an in-place run needs `speccoder/<feature>` free.",
["git worktree list", "git worktree remove <path>"]
),
entry!(
"IN-PLACE-ACTIVE",
E,
S::GitPrecondition,
"an in-place run holds this checkout",
"Another in-place session is active (or was killed); it owns the checkout until it ends or is left.",
[
"speccoder run --in-place",
"speccoder run --in-place --return"
]
),
entry!(
"IN-PLACE-SESSION",
E,
S::GitPrecondition,
"an in-place session is recorded for this checkout",
"A worktree-mode command would not see what the in-place session holds.",
[
"speccoder run --in-place",
"speccoder run --in-place --return"
]
),
entry!(
"IN-PLACE-PARALLEL",
E,
S::UsageError,
"an in-place run works one task at a time",
"Parallel lanes need worktrees of their own; in place there is only your checkout.",
["speccoder run --in-place", "speccoder run --parallel 2"]
),
entry!(
"MERGE-CONFLICT",
E,
S::GitPrecondition,
"the checkout is in the middle of a merge or rebase",
"An in-place run cannot start or return while git waits for a conflict to be resolved.",
["git status", "git merge --abort"]
),
entry!(
"INTENT-CHANGED",
P,
S::NeedsHuman,
"the spec, plan or tasks changed during the run",
"Intent files are hashed when an in-place run starts and compared before every task; a change means the work would be judged against a spec it was not given.",
["git diff", "speccoder run --in-place"]
),
entry!(
"JUDGE-CHANGED",
P,
S::NeedsHuman,
"the judge's inputs changed during the run",
"Checks, test configuration or agent configuration changed after the run started; a verdict under changed rules would mean nothing.",
["git diff", "speccoder run --in-place"]
),
entry!(
"CHECKOUT-CHANGED",
P,
S::NeedsHuman,
"the checkout moved under the run",
"HEAD, the branch or the tree is not where speccoder left it; someone or something else changed the checkout.",
["git status", "speccoder run --in-place --return"]
),
entry!(
"GIT-CHANGED",
P,
S::NeedsHuman,
"git's configuration, hooks or refs changed during the run",
"Where the sandbox cannot keep `.git` read-only, speccoder fingerprints it; a change stops the run before the next tick.",
[
"git config --list --show-origin",
"speccoder run --in-place --return"
]
),
entry!(
"RETURN-BLOCKED",
P,
S::NeedsHuman,
"the in-place run cannot switch back to your branch",
"Switching back would overwrite changes or fail; the session stays until the checkout allows it.",
["git status", "speccoder run --in-place --return"]
),
entry!(
"NOT-FOUND",
E,
S::NotFound,
"nothing by that name exists",
"No task, run, call or object matches what was asked for; the message names it.",
["speccoder report"]
),
entry!(
"NOT-FOUND-SCHEMA",
E,
S::NotFound,
"there is no schema by that name",
"`speccoder schema` lists the schemas speccoder publishes.",
["speccoder schema"]
),
entry!(
"TASK-NOT-READY",
E,
S::TaskNotReady,
"no task can run now",
"The task is done, or waits for tasks it depends on.",
["speccoder report"]
),
entry!(
"TASK-DONE",
E,
S::TaskNotReady,
"the task is already ticked",
"A ticked task is not run again; its evidence is in its commit.",
["speccoder report"]
),
entry!(
"TASK-BLOCKED",
E,
S::TaskNotReady,
"the task waits for tasks it depends on",
"Dependencies come from the task list's phases, `[P]` markers and explicit references; the message names the open ones.",
[
"speccoder run --feature {feature}",
"speccoder task skip <dependency> --reason \"…\""
]
),
entry!(
"VERIFICATION-FAILED",
E,
S::VerificationFailed,
"the checks or the acceptance tests did not pass",
"After the retries, a check regressed or the spec-derived acceptance tests did not go from red to green. The attempt is saved under its ref.",
[
"speccoder report",
"speccoder task nudge {task} --note \"…\""
]
),
entry!(
"REGRESSION-ONLY",
W,
S::Ok,
"ticked on the regression checks alone, nothing task-specific was shown",
"The checks still pass, but no acceptance test showed this task's behaviour (the spec has no example for it, or the tests could not be made red first). It is ticked `regression_only`, never `verified`.",
[
"→ add an acceptance example to the task's story, then converge",
"speccoder converge --feature {feature}"
]
),
entry!(
"ATTESTATION-FAILED",
E,
S::AttestationFailed,
"an attestation is missing, unsigned where required, or does not hold",
"`attest verify` found a tick whose signed statements are missing, malformed, edited, about another commit, or signed by no one you trust.",
["speccoder attest verify --feature {feature} --json"]
),
entry!(
"NEEDS-HUMAN",
P,
S::NeedsHuman,
"the run stopped for a person",
"The run cannot go on without a decision; the message says what waits.",
["speccoder report"]
),
entry!(
"NEEDS-APPROVAL",
P,
S::NeedsHuman,
"a call waits for a person's decision; nothing ran",
"The model asked for something the policy does not allow on its own — a dependency change, the network, a protected file. The attempt waits; deciding continues it from that call.",
[
"speccoder report --approvals",
"speccoder task approve {task}",
"speccoder task reject {task} --reason \"…\""
]
),
entry!(
"BLOCKED",
P,
S::NeedsHuman,
"the model says the task cannot be done as written",
"The model used its honest exit: something in the spec or the code stops it. Its reason is a claim, shown as \"Model says\".",
[
"speccoder task nudge {task} --note \"…\"",
"speccoder task skip {task} --reason \"…\""
]
),
entry!(
"BUDGET-EXHAUSTED",
P,
S::NeedsHuman,
"the attempt ran out of turns, calls or tokens",
"The attempt reached a limit of `[budget]` before finishing. The work so far is saved under the attempt's ref.",
[
"speccoder task nudge {task} --note \"…\"",
"→ raise the limit in speccoder.toml [budget]"
]
),
entry!(
"NOT-DEMONSTRATED",
P,
S::NeedsHuman,
"the evidence the task needs could not be produced",
"The acceptance tests could not be made red before the attempt (they already pass, or fail for another reason), or a convergence gap shows in no failing test. Ticking would claim more than was shown.",
[
"speccoder report",
"speccoder task accept {task} --reason \"…\""
]
),
entry!(
"ACCEPTANCE-UNWRITTEN",
P,
S::NeedsHuman,
"the acceptance tests could not be written, so nothing was attempted",
"The call that writes acceptance tests from the spec failed (no credits, a rejected key, a broken run). Without them the task would be judged on regression checks only, so it stops.",
[
"speccoder run --feature {feature}",
"→ or set [acceptance] generate = false to rely on the checks alone"
]
),
entry!(
"SUSPECTED-GAMING",
P,
S::NeedsHuman,
"the gaming monitor suspects a shortcut",
"A separate review of the passing attempt found something like a hard-coded result or a weakened test. The task stays unticked until a person decides.",
[
"speccoder report",
"speccoder task accept {task} --reason \"…\"",
"speccoder task nudge {task} --note \"…\""
]
),
entry!(
"TESTS-OVER-STRICT",
P,
S::NeedsHuman,
"an acceptance test rejects an implementation the spec appears to allow",
"An alternative the spec allows (another order, wording, tie-break) failed the acceptance tests: they may encode a choice the spec did not make. The attempt is held until you rule; if the tests are right, the next run ticks it without a model call.",
[
"speccoder task rule {task} --tests-right --reason \"…\"",
"speccoder run --task {task} --fresh-acceptance",
"speccoder task accept {task} --reason \"…\""
]
),
entry!(
"ACCEPTANCE-WEAK",
P,
S::NeedsHuman,
"the acceptance tests are too weak for [acceptance] min_strength",
"Wrong implementations — mutants of the changed code and model-written near misses — passed the acceptance tests too often, and adding tests once did not fix it. The task stays unticked; the report names what got through.",
[
"speccoder report",
"speccoder run --task {task}",
"speccoder task accept {task} --reason \"…\""
]
),
entry!(
"INTERRUPTED",
P,
S::NeedsHuman,
"the run was interrupted",
"The process was stopped or killed; the journal holds what finished. The next run resumes without repeating finished calls.",
["speccoder run --feature {feature}"]
),
entry!(
"CHECKLISTS-OPEN",
P,
S::NeedsHuman,
"the feature's checklists have unchecked items",
"Spec Kit checklists gate implementation; nothing ran.",
[
"→ finish the checklists in the feature's checklists/ directory",
"speccoder run --ignore-checklists"
]
),
entry!(
"ARCHIVE-AWAITING",
P,
S::NeedsHuman,
"the OpenSpec archive waits for your yes",
"The diff of the archive is shown; nothing is written until a person confirms.",
["speccoder spec archive --yes"]
),
entry!(
"RUN-FAILED",
E,
S::RunFailed,
"the model call or the run failed",
"The provider returned an error, the journal could not be written, or the run broke; the message names it. Nothing was ticked.",
["speccoder run --feature {feature} -v"]
),
entry!(
"PROVIDER-REFUSED",
E,
S::RunFailed,
"the model provider refused the request",
"No credits, a rejected or revoked key, or an account limit. speccoder stops instead of judging the task on less evidence.",
[
"→ check the provider account's credits and the API key",
"speccoder run --feature {feature}"
]
),
entry!(
"REPLAY-DIVERGED",
E,
S::ReplayDiverged,
"the replay did not reproduce the recorded run",
"Strict replay re-derives a run from its journal without a model; a difference means the code's decisions changed.",
["speccoder replay <run> --json"]
),
entry!(
"NOT-REPLAYABLE",
E,
S::NotReplayable,
"this build cannot re-derive the recorded run",
"The run was recorded by a build whose skills or effects this one does not have.",
["→ replay with the speccoder version that recorded the run"]
),
entry!(
"BUG-NO-UNIT",
E,
S::UsageError,
"this spec format has no place for a bug",
"A bug lives in the format's own bug structure (Spec Kit's `bug` extension) or in its standing bug-fix unit (Spec Kit's `NNN-bugfixes`, an OpenSpec standing change). Kiro projects are not supported: nothing is written.",
[
"→ write a spec for the change and run it",
"→ a change without a reproduction: speccoder do \"…\""
]
),
entry!(
"BUG-EMPTY",
E,
S::UsageError,
"the symptom and every statement need words",
"`speccoder bug` records the person's own words: an empty symptom, `--expected` or `--unchanged` is refused before anything is written.",
["speccoder bug \"<what happens>\" --expected \"<what should>\""]
),
entry!(
"BUG-NO-EXPECTED",
E,
S::UsageError,
"a bug needs at least one --expected statement",
"A reproduction asserts what should happen; speccoder never infers it from the symptom or an issue. Give one `--expected` per behaviour.",
["speccoder bug \"<what happens>\" --expected \"<what should>\""]
),
entry!(
"BUG-ASSESSMENT-DRIFT",
P,
S::NeedsHuman,
"the bug's home does not carry exactly your words",
"The bug's file (`assessment.md`, or the standing unit) does not read back exactly your Current, Expected and Unchanged statements: one is missing, added, reworded, or changed by the file's markup. Reproductions are written from your words only, so nothing was reproduced.",
[
"→ edit the assessment so it carries each statement as a `Current:` / `Expected:` / `Unchanged:` line",
"speccoder bug --slug <slug>"
]
),
entry!(
"BUG-ASSESSMENT-UNREADABLE",
P,
S::NeedsHuman,
"the bug's assessment is not in a shape speccoder reads",
"speccoder reads `assessment.md` in the layout of the `bug` extension version it was built against, and refuses rather than guesses on any other shape.",
[
"specify extension list --json",
"→ add `Current:` and `Expected:` lines to the assessment's Report section"
]
),
entry!(
"BUG-TEST-NOT-FOUND",
E,
S::UsageError,
"the test named with --test is not found",
"`--test PATH::NAME` must name an existing test file and a test in it that the runner collects.",
["→ give the test as PATH::NAME, as the runner lists it"]
),
entry!(
"BUG-TEST-NOT-RED",
E,
S::UsageError,
"the named test does not fail on an assertion",
"A reproduction must fail on the untouched code by an assertion, twice. A build or collection error, a timeout, an absent symbol or a flaky failure shows nothing about the bug.",
["→ fix the test so it fails on an assertion, then run `speccoder bug` again"]
),
entry!(
"BUG-TEST-PASSES",
E,
S::UsageError,
"the named test passes on the untouched code",
"A test that passes before any fix cannot show the bug. Perhaps it is fixed already.",
["→ check the behaviour by hand; if it is fixed, there is nothing to record"]
),
entry!(
"BUG-TEST-COVERAGE",
E,
S::UsageError,
"each --expected statement needs its own --test",
"Each stated behaviour gets its own reproduction: repeat `--test` once per `--expected`, in the same order.",
[
"speccoder bug \"…\" --expected \"<e1>\" --test <file>::<test1> --expected \"<e2>\" --test <file>::<test2>"
]
),
entry!(
"BUG-CANNOT-REPRODUCE",
P,
S::NeedsHuman,
"the bug could not be reproduced: nothing is fixed",
"No try produced a test for each Expected statement that fails on its own assertion, or you rejected them (rejected tries count against `[bug] reproduce_tries`). A fix without a failing reproduction would be a guess, so the bug comes back to you with what each try showed.",
[
"speccoder bug run --task {feature}/{task}",
"speccoder bug \"…\" --expected \"…\" --test <file>::<test>",
"speccoder task drop {task}"
]
),
entry!(
"BUG-ALREADY-SATISFIED",
W,
S::Ok,
"the reproductions already pass: nothing to fix",
"Every reproduction passed on the untouched code on every try. Nothing is ticked; keep the reproductions as a regression test (committed, the task attested) or drop the task.",
[
"speccoder bug keep {feature}/{task} --reason \"kept as a regression test\"",
"speccoder task drop {task}"
]
),
entry!(
"BUG-UNCHANGED-NOT-HOLDING",
P,
S::NeedsHuman,
"an Unchanged statement does not hold today",
"The test of an Unchanged statement fails on the untouched code, so the statement is not true now and cannot guard the fix. The bug stops before any fix.",
["→ reword or remove the statement, then `speccoder bug run`"]
),
entry!(
"BUG-NOT-DISCRIMINATING",
E,
S::VerificationFailed,
"the reproduction does not tell the fix from no fix",
"With the attempt's source changes undone (its tests kept), no reproduction failed on an assertion: passing them proves nothing about the fix. The retry is told which statement.",
["speccoder run --task {task}"]
),
entry!(
"BUG-REPRO-WEAK",
P,
S::NeedsHuman,
"a fix that special-cases the reproduction's input passes",
"A candidate fix that only recognises the reproduction's literal inputs passed the reproductions and the held-out variants, even after one variant was written again. The tests are too weak for a verified fix.",
[
"speccoder task rule {task} --tests-right --reason \"…\"",
"speccoder bug \"…\" --expected \"…\" --test <file>::<test>"
]
),
entry!(
"BUG-CANDIDATE-APPLY",
E,
S::GitPrecondition,
"the candidate patch is not applied",
"`--candidate` applies the patch on the untouched code with `git apply --check` first; some hunks did not apply, git could not read it as a patch, or it carries a binary hunk or a symbolic link (neither is judged as a candidate).",
["→ rebase the patch on HEAD, as a text diff without binary hunks or links"]
),
entry!(
"BUG-CANDIDATE-JUDGE",
E,
S::UsageError,
"the candidate patch touches what judges it",
"A candidate must not change a frozen reproduction, a held-out path or another judge input (checks, configuration, the intent) — by an edit, a rename, a deletion or a mode change, as git itself reads the patch. It is refused before it is applied.",
["→ remove those hunks from the patch"]
),
entry!(
"EVAL-FAILED",
E,
S::EvalFailed,
"the evaluation found a false completion or a cheat",
"A case ended done although its hidden oracle fails, or the attempt gamed its tests.",
["speccoder eval --keep <dir>"]
),
];
#[must_use]
pub fn lookup(name: &str) -> Option<&'static Entry> {
CATALOG.iter().find(|e| e.name == name)
}
#[must_use]
pub fn default_for(status: CommandStatus) -> Option<&'static Entry> {
let name = match status {
S::Ok => return None,
S::UsageError => "USAGE",
S::Error => "INTERNAL",
S::NotAProject => "NO-PROJECT",
S::DiagnosticsError => "SPEC-DIAGNOSTICS",
S::SelectionNeeded => "FEATURE-SELECTION",
S::ConfigError => "CONFIG",
S::VerificationFailed => "VERIFICATION-FAILED",
S::GitPrecondition => "GIT",
S::NotFound => "NOT-FOUND",
S::RunFailed => "RUN-FAILED",
S::ReplayDiverged => "REPLAY-DIVERGED",
S::TaskNotReady => "TASK-NOT-READY",
S::NeedsHuman => "NEEDS-HUMAN",
S::EvalFailed => "EVAL-FAILED",
S::NotReplayable => "NOT-REPLAYABLE",
S::AttestationFailed => "ATTESTATION-FAILED",
};
lookup(name)
}
#[must_use]
pub fn nearest(name: &str, n: usize) -> Vec<&'static str> {
let wanted = name.to_ascii_uppercase();
let mut scored: Vec<(usize, &'static str)> = CATALOG
.iter()
.map(|e| (distance(&wanted, e.name), e.name))
.collect();
scored.sort();
scored
.into_iter()
.filter(|(d, _)| *d <= wanted.len().max(3) / 2 + 1)
.take(n)
.map(|(_, name)| name)
.collect()
}
fn distance(a: &str, b: &str) -> usize {
let b: Vec<char> = b.chars().collect();
let mut row: Vec<usize> = (0..=b.len()).collect();
for (i, ca) in a.chars().enumerate() {
let mut prev = row[0];
row[0] = i + 1;
for (j, cb) in b.iter().enumerate() {
let cur = row[j + 1];
row[j + 1] = (prev + usize::from(ca != *cb)).min(row[j] + 1).min(cur + 1);
prev = cur;
}
}
row[b.len()]
}
#[must_use]
pub fn fixes(
entry: &Entry,
command: &str,
task: Option<&str>,
feature: Option<&str>,
) -> Vec<String> {
let general = entry.fix.iter().any(|f| !f.contains("{task}"));
entry
.fix
.iter()
.filter(|f| task.is_some() || !general || !f.contains("{task}"))
.map(|f| {
let feature_arg = feature.map_or_else(String::new, |f| f.to_owned());
let mut line = f
.replace("{command}", command)
.replace("{task}", task.unwrap_or("<task>"));
line = if feature.is_some() {
line.replace("{feature}", &feature_arg)
} else {
line.replace(" --feature {feature}", "")
.replace("{feature}", "<feature>")
};
line
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
const STATUSES: [CommandStatus; 17] = [
S::Ok,
S::UsageError,
S::Error,
S::NotAProject,
S::DiagnosticsError,
S::SelectionNeeded,
S::ConfigError,
S::VerificationFailed,
S::GitPrecondition,
S::NotFound,
S::RunFailed,
S::ReplayDiverged,
S::TaskNotReady,
S::NeedsHuman,
S::EvalFailed,
S::NotReplayable,
S::AttestationFailed,
];
#[test]
fn names_are_unique_upper_case_words() {
let mut seen = std::collections::BTreeSet::new();
for e in CATALOG {
assert!(seen.insert(e.name), "{} twice", e.name);
assert!(
e.name.split('-').all(|w| !w.is_empty()
&& w.chars()
.all(|c| c.is_ascii_uppercase() || c.is_ascii_digit())),
"{}",
e.name
);
assert!(!e.fix.is_empty() && !e.title.ends_with('.'), "{}", e.name);
assert!(
e.title.chars().next().is_some_and(char::is_lowercase),
"{}",
e.name
);
}
}
#[test]
fn every_non_ok_status_has_a_default_and_kinds_agree_with_statuses() {
for s in STATUSES {
let d = default_for(s);
assert_eq!(d.is_none(), s == S::Ok, "{s:?}");
if let Some(d) = d {
assert_eq!(d.status, s);
}
}
for e in CATALOG {
assert_eq!(
e.kind == Kind::Stop,
e.status == S::NeedsHuman,
"{}",
e.name
);
assert_eq!(e.kind == Kind::Warning, e.status == S::Ok, "{}", e.name);
}
}
#[test]
fn near_misses_are_suggested_and_placeholders_filled() {
assert_eq!(nearest("uncommited-intent", 1), ["UNCOMMITTED-INTENT"]);
assert_eq!(nearest("NEEDS-APROVAL", 1), ["NEEDS-APPROVAL"]);
assert!(nearest("completely-unrelated-words", 3).is_empty());
let e = lookup("NEEDS-APPROVAL").unwrap();
assert_eq!(
fixes(e, "run", Some("T004"), None)[1],
"speccoder task approve T004"
);
let r = lookup("INTERRUPTED").unwrap();
assert_eq!(fixes(r, "run", None, None), ["speccoder run"]);
assert_eq!(
fixes(r, "run", None, Some("001-x")),
["speccoder run --feature 001-x"]
);
}
}