1use crate::command::CommandStatus;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, schemars::JsonSchema)]
13#[serde(rename_all = "snake_case")]
14pub enum Kind {
15 Error,
17 Stop,
19 Warning,
21}
22
23impl Kind {
24 #[must_use]
26 pub const fn prefix(self) -> &'static str {
27 match self {
28 Self::Error => "error",
29 Self::Stop => "stopped",
30 Self::Warning => "warning",
31 }
32 }
33}
34
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
37pub struct Entry {
38 pub name: &'static str,
40 pub kind: Kind,
42 pub status: CommandStatus,
44 pub title: &'static str,
46 pub explain: &'static str,
48 pub fix: &'static [&'static str],
51}
52
53pub const DOCS: &str = "https://hupe1980.github.io/speccoder/docs/codes/";
55
56impl Entry {
57 #[must_use]
59 pub fn docs(&self) -> String {
60 format!("{DOCS}#{}", self.name.to_ascii_lowercase())
61 }
62}
63
64use CommandStatus as S;
65use Kind::{Error as E, Stop as P, Warning as W};
66
67macro_rules! entry {
68 ($name:literal, $kind:expr, $status:expr, $title:literal, $explain:literal, [$($fix:literal),+ $(,)?]) => {
69 Entry { name: $name, kind: $kind, status: $status, title: $title, explain: $explain, fix: &[$($fix),+] }
70 };
71}
72
73pub const CATALOG: &[Entry] = &[
75 entry!(
77 "USAGE",
78 E,
79 S::UsageError,
80 "the arguments are not valid for this command",
81 "The command line could not be parsed: an unknown flag, a missing value, or a value outside the allowed set.",
82 ["speccoder {command} --help"]
83 ),
84 entry!(
85 "USAGE-CONFLICT",
86 E,
87 S::UsageError,
88 "two options were given that exclude each other",
89 "`--json` prints one result object and `--events` prints a stream of events ending in that object; a command does one or the other.",
90 ["speccoder {command} --events", "speccoder {command} --json"]
91 ),
92 entry!(
93 "USAGE-UNKNOWN-CODE",
94 E,
95 S::UsageError,
96 "there is no code by that name",
97 "`speccoder explain` knows the codes speccoder itself prints; the closest names are listed with the error.",
98 ["speccoder explain --list"]
99 ),
100 entry!(
101 "CALL-CHANGED",
102 E,
103 S::UsageError,
104 "the call waiting now is not the one that was shown",
105 "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.",
106 ["speccoder report --approvals"]
107 ),
108 entry!(
110 "INTERNAL",
111 E,
112 S::Error,
113 "speccoder failed in a way it does not expect",
114 "An unexpected failure inside speccoder: an IO error, a broken state file, a bug. The message says what failed.",
115 ["→ re-run with -v and report the output at https://github.com/hupe1980/speccoder/issues"]
116 ),
117 entry!(
119 "NO-PROJECT",
120 E,
121 S::NotAProject,
122 "speccoder works on a Spec Kit or OpenSpec project, and found none here",
123 "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.",
124 ["specify init --here --integration claude", "openspec init"]
125 ),
126 entry!(
127 "SPEC-DIAGNOSTICS",
128 E,
129 S::DiagnosticsError,
130 "the spec artifacts have errors speccoder will not guess around",
131 "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.",
132 ["speccoder inspect"]
133 ),
134 entry!(
135 "FEATURE-SELECTION",
136 E,
137 S::SelectionNeeded,
138 "more than one feature could be meant",
139 "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.",
140 [
141 "speccoder feature",
142 "speccoder feature <name>",
143 "speccoder {command} --feature <name>"
144 ]
145 ),
146 entry!(
147 "CHECK-BROKEN",
148 E,
149 S::ConfigError,
150 "a check cannot run on the untouched code",
151 "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.",
152 [
153 "speccoder doctor",
154 "git status",
155 "speccoder run --allow-failing-baseline"
156 ]
157 ),
158 entry!(
159 "FEATURE-GONE",
160 E,
161 S::SelectionNeeded,
162 "the current feature no longer exists",
163 "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.",
164 [
165 "speccoder feature",
166 "speccoder feature <name>",
167 "speccoder feature --clear"
168 ]
169 ),
170 entry!(
171 "REVIEW-PENDING",
172 P,
173 S::NeedsHuman,
174 "the spec is not approved yet",
175 "`[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.",
176 ["speccoder review", "speccoder review approve", "git commit"]
177 ),
178 entry!(
179 "REVIEW-AMBIGUOUS",
180 P,
181 S::NeedsHuman,
182 "two readings of a requirement disagree",
183 "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.",
184 [
185 "speccoder review tests <REQ> --reading A <scenario>",
186 "speccoder review tests <REQ> --reading B <scenario>",
187 "→ or reword the scenario so it reads one way"
188 ]
189 ),
190 entry!(
191 "REVIEW-NO-SCENARIOS",
192 E,
193 S::UsageError,
194 "the requirement has no scenarios to write tests from",
195 "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.",
196 [
197 "speccoder review",
198 "→ add acceptance scenarios to the requirement"
199 ]
200 ),
201 entry!(
202 "REVIEW-TESTS-OWN-PIPELINE",
203 E,
204 S::UsageError,
205 "this unit's tests are written by its own pipeline",
206 "A quick change writes its own tests and a bug's reproductions are confirmed by you; review writes no second set for them.",
207 ["speccoder do \"…\"", "speccoder bug confirm <unit>/<task>"]
208 ),
209 entry!(
210 "ACCEPTANCE-OFF",
211 E,
212 S::ConfigError,
213 "acceptance tests are turned off",
214 "`[acceptance] generate = false`: no acceptance tests are written, at review or at run time.",
215 ["speccoder config set acceptance.generate true"]
216 ),
217 entry!(
218 "ORACLE-AUTHOR-FAILED",
219 E,
220 S::RunFailed,
221 "the test author could not write the tests",
222 "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.",
223 ["speccoder review tests <REQ> --write"]
224 ),
225 entry!(
226 "ORACLE-TAMPERED",
227 P,
228 S::NeedsHuman,
229 "a frozen test no longer matches what was frozen",
230 "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.",
231 [
232 "speccoder review tests <REQ>",
233 "→ write and approve the tests again, or run without the frozen set"
234 ]
235 ),
236 entry!(
237 "ORACLE-FROZEN",
238 E,
239 S::UsageError,
240 "the requirement's tests are frozen with the approval",
241 "*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.",
242 [
243 "speccoder review",
244 "→ reword the requirement to lapse the freeze, then write its tests again"
245 ]
246 ),
247 entry!(
248 "REVIEW-CHANGED",
249 P,
250 S::NeedsHuman,
251 "what the approval would freeze changed since it was shown",
252 "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.",
253 [
254 "speccoder review",
255 "→ open the sheet again and approve what it shows"
256 ]
257 ),
258 entry!(
259 "REVIEW-UNREADABLE",
260 P,
261 S::NeedsHuman,
262 "the review record cannot be read",
263 "`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.",
264 [
265 "git diff -- <unit>/review.json",
266 "→ restore it from git (`git checkout -- <unit>/review.json`) or fix the JSON"
267 ]
268 ),
269 entry!(
270 "RUN-ACTIVE",
271 E,
272 S::GitPrecondition,
273 "a run is active for this project",
274 "*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.",
275 ["speccoder report", "→ wait for the run to end, or stop it"]
276 ),
277 entry!(
278 "AUTOPILOT-NEEDS-GRANT-OBJECTS",
279 E,
280 S::ConfigError,
281 "autopilot needs object-bound grants",
282 "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.",
283 ["speccoder review approve --run ask"]
284 ),
285 entry!(
286 "FEATURE-UNKNOWN",
287 E,
288 S::SelectionNeeded,
289 "no feature has that name or number",
290 "`--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.",
291 ["speccoder feature", "speccoder report --feature <name>"]
292 ),
293 entry!(
295 "CONFIG",
296 E,
297 S::ConfigError,
298 "the configuration or the environment is not usable",
299 "`speccoder.toml` or the environment does not allow this command to run; the message names what is wrong.",
300 ["speccoder init"]
301 ),
302 entry!(
303 "NO-STATE-DIR",
304 E,
305 S::ConfigError,
306 "speccoder has nowhere to keep its state",
307 "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.",
308 ["export SPECCODER_STATE_DIR=\"$PWD/.speccoder-state\""]
309 ),
310 entry!(
311 "SANDBOX-UNAVAILABLE",
312 E,
313 S::ConfigError,
314 "the OS sandbox is not available and the project requires it",
315 "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.",
316 [
317 "→ run on macOS or Linux 6.2+ (Landlock ABI 3)",
318 "→ or set [sandbox] mode = \"auto\" to run unsandboxed and be told",
319 "→ autopilot: choose Ask on Risky Calls, or enable the OS sandbox"
320 ]
321 ),
322 entry!(
323 "GITHUB-AUTH",
324 E,
325 S::Error,
326 "not signed in to GitHub",
327 "No GitHub token was found (GH_TOKEN, GITHUB_TOKEN, or the one `speccoder auth login` keeps in your keychain), or GitHub refused it.",
328 [
329 "speccoder auth login --with-token",
330 "speccoder auth status",
331 "→ or set GH_TOKEN (a fine-grained token: Issues read; Pull requests read and write; Contents and Metadata read)"
332 ]
333 ),
334 entry!(
335 "GITHUB-FAILED",
336 E,
337 S::Error,
338 "the GitHub API could not do it",
339 "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.",
340 ["speccoder auth status", "git remote -v"]
341 ),
342 entry!(
343 "CONFIG-EXISTS",
344 E,
345 S::ConfigError,
346 "the project has a speccoder.toml already",
347 "`init` writes a new one; change the existing one with `speccoder config` (or Settings), or start over with `--force`.",
348 ["speccoder config", "speccoder init --force"]
349 ),
350 entry!(
351 "CONFIG-MISSING",
352 E,
353 S::ConfigError,
354 "the project has no speccoder.toml",
355 "speccoder needs to know which checks decide \"nothing regressed\" and which model to use; `init` detects them and writes a commented file.",
356 ["speccoder init"]
357 ),
358 entry!(
359 "CONFIG-INVALID",
360 E,
361 S::ConfigError,
362 "speccoder.toml has an error",
363 "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.",
364 ["→ fix the line the message names in speccoder.toml, then commit it"]
365 ),
366 entry!(
367 "KEY-MISSING",
368 E,
369 S::ConfigError,
370 "the model provider's API key is not in the environment",
371 "speccoder reads API keys from the environment only. The message names the variable the configured provider needs.",
372 ["→ export the variable the message names, e.g. export ANTHROPIC_API_KEY=…"]
373 ),
374 entry!(
375 "NO-CHECKS",
376 E,
377 S::ConfigError,
378 "no check applies, so nothing could show that nothing regressed",
379 "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.",
380 ["speccoder config set checks.test.argv -- <your test command>"]
381 ),
382 entry!(
384 "GIT",
385 E,
386 S::GitPrecondition,
387 "git is not in the state this command needs",
388 "A git precondition does not hold; the message names it.",
389 ["git status"]
390 ),
391 entry!(
392 "SETUP-INCOMPLETE",
393 E,
394 S::GitPrecondition,
395 "the project's setup is not committed, so every run would trip over it",
396 "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.",
397 ["speccoder fix"]
398 ),
399 entry!(
400 "NO-REPOSITORY",
401 E,
402 S::GitPrecondition,
403 "speccoder needs a git repository with at least one commit",
404 "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.",
405 ["git init && git add -A && git commit -m init"]
406 ),
407 entry!(
408 "UNCOMMITTED-INTENT",
409 E,
410 S::GitPrecondition,
411 "the spec has uncommitted changes the run would not see",
412 "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.",
413 ["git status", "speccoder run --in-place"]
414 ),
415 entry!(
416 "NO-REMOTE",
417 E,
418 S::GitPrecondition,
419 "there is no git remote to push to",
420 "`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.",
421 [
422 "git remote add origin <url>",
423 "git remote -v",
424 "speccoder pr --remote <name>"
425 ]
426 ),
427 entry!(
428 "WORKTREE-DIRTY",
429 E,
430 S::GitPrecondition,
431 "the feature's worktree has uncommitted changes",
432 "Work left in the worktree outside a commit — a failed attempt's, or an edit by hand — would be mixed into what comes next.",
433 ["speccoder worktree", "speccoder run --feature {feature}"]
434 ),
435 entry!(
436 "NOTHING-TO-HAND-OFF",
437 E,
438 S::GitPrecondition,
439 "the speccoder branch has nothing the base does not have",
440 "`pr` hands off work on `speccoder/<feature>`; there is none yet, or it is already merged.",
441 ["speccoder run --feature {feature}"]
442 ),
443 entry!(
445 "DIRTY-CHECKOUT",
446 E,
447 S::GitPrecondition,
448 "an in-place run needs a clean checkout",
449 "In place, the attempt runs in your checkout; uncommitted changes would be judged as the agent's.",
450 ["git stash -u", "git commit -am wip"]
451 ),
452 entry!(
453 "UNBORN-HEAD",
454 E,
455 S::GitPrecondition,
456 "the checkout has no commit yet",
457 "An in-place run branches from HEAD; there is no HEAD to branch from.",
458 ["git add -A && git commit -m init"]
459 ),
460 entry!(
461 "CONFIG-NOT-TRACKED",
462 E,
463 S::GitPrecondition,
464 "speccoder.toml must be committed",
465 "The judge's configuration is a reviewed input; an untracked or modified one could be changed without review.",
466 ["git add speccoder.toml && git commit -m \"speccoder: config\""]
467 ),
468 entry!(
469 "BRANCH-IN-WORKTREE",
470 E,
471 S::GitPrecondition,
472 "the feature's branch is checked out in a worktree",
473 "git refuses to check out a branch twice; an in-place run needs `speccoder/<feature>` free.",
474 ["git worktree list", "git worktree remove <path>"]
475 ),
476 entry!(
477 "IN-PLACE-ACTIVE",
478 E,
479 S::GitPrecondition,
480 "an in-place run holds this checkout",
481 "Another in-place session is active (or was killed); it owns the checkout until it ends or is left.",
482 [
483 "speccoder run --in-place",
484 "speccoder run --in-place --return"
485 ]
486 ),
487 entry!(
488 "IN-PLACE-SESSION",
489 E,
490 S::GitPrecondition,
491 "an in-place session is recorded for this checkout",
492 "A worktree-mode command would not see what the in-place session holds.",
493 [
494 "speccoder run --in-place",
495 "speccoder run --in-place --return"
496 ]
497 ),
498 entry!(
499 "IN-PLACE-PARALLEL",
500 E,
501 S::UsageError,
502 "an in-place run works one task at a time",
503 "Parallel lanes need worktrees of their own; in place there is only your checkout.",
504 ["speccoder run --in-place", "speccoder run --parallel 2"]
505 ),
506 entry!(
507 "MERGE-CONFLICT",
508 E,
509 S::GitPrecondition,
510 "the checkout is in the middle of a merge or rebase",
511 "An in-place run cannot start or return while git waits for a conflict to be resolved.",
512 ["git status", "git merge --abort"]
513 ),
514 entry!(
515 "INTENT-CHANGED",
516 P,
517 S::NeedsHuman,
518 "the spec, plan or tasks changed during the run",
519 "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.",
520 ["git diff", "speccoder run --in-place"]
521 ),
522 entry!(
523 "JUDGE-CHANGED",
524 P,
525 S::NeedsHuman,
526 "the judge's inputs changed during the run",
527 "Checks, test configuration or agent configuration changed after the run started; a verdict under changed rules would mean nothing.",
528 ["git diff", "speccoder run --in-place"]
529 ),
530 entry!(
531 "CHECKOUT-CHANGED",
532 P,
533 S::NeedsHuman,
534 "the checkout moved under the run",
535 "HEAD, the branch or the tree is not where speccoder left it; someone or something else changed the checkout.",
536 ["git status", "speccoder run --in-place --return"]
537 ),
538 entry!(
539 "GIT-CHANGED",
540 P,
541 S::NeedsHuman,
542 "git's configuration, hooks or refs changed during the run",
543 "Where the sandbox cannot keep `.git` read-only, speccoder fingerprints it; a change stops the run before the next tick.",
544 [
545 "git config --list --show-origin",
546 "speccoder run --in-place --return"
547 ]
548 ),
549 entry!(
550 "RETURN-BLOCKED",
551 P,
552 S::NeedsHuman,
553 "the in-place run cannot switch back to your branch",
554 "Switching back would overwrite changes or fail; the session stays until the checkout allows it.",
555 ["git status", "speccoder run --in-place --return"]
556 ),
557 entry!(
559 "NOT-FOUND",
560 E,
561 S::NotFound,
562 "nothing by that name exists",
563 "No task, run, call or object matches what was asked for; the message names it.",
564 ["speccoder report"]
565 ),
566 entry!(
567 "NOT-FOUND-SCHEMA",
568 E,
569 S::NotFound,
570 "there is no schema by that name",
571 "`speccoder schema` lists the schemas speccoder publishes.",
572 ["speccoder schema"]
573 ),
574 entry!(
575 "TASK-NOT-READY",
576 E,
577 S::TaskNotReady,
578 "no task can run now",
579 "The task is done, or waits for tasks it depends on.",
580 ["speccoder report"]
581 ),
582 entry!(
583 "TASK-DONE",
584 E,
585 S::TaskNotReady,
586 "the task is already ticked",
587 "A ticked task is not run again; its evidence is in its commit.",
588 ["speccoder report"]
589 ),
590 entry!(
591 "TASK-BLOCKED",
592 E,
593 S::TaskNotReady,
594 "the task waits for tasks it depends on",
595 "Dependencies come from the task list's phases, `[P]` markers and explicit references; the message names the open ones.",
596 [
597 "speccoder run --feature {feature}",
598 "speccoder task skip <dependency> --reason \"…\""
599 ]
600 ),
601 entry!(
603 "VERIFICATION-FAILED",
604 E,
605 S::VerificationFailed,
606 "the checks or the acceptance tests did not pass",
607 "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.",
608 [
609 "speccoder report",
610 "speccoder task nudge {task} --note \"…\""
611 ]
612 ),
613 entry!(
614 "REGRESSION-ONLY",
615 W,
616 S::Ok,
617 "ticked on the regression checks alone, nothing task-specific was shown",
618 "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`.",
619 [
620 "→ add an acceptance example to the task's story, then converge",
621 "speccoder converge --feature {feature}"
622 ]
623 ),
624 entry!(
625 "ATTESTATION-FAILED",
626 E,
627 S::AttestationFailed,
628 "an attestation is missing, unsigned where required, or does not hold",
629 "`attest verify` found a tick whose signed statements are missing, malformed, edited, about another commit, or signed by no one you trust.",
630 ["speccoder attest verify --feature {feature} --json"]
631 ),
632 entry!(
634 "NEEDS-HUMAN",
635 P,
636 S::NeedsHuman,
637 "the run stopped for a person",
638 "The run cannot go on without a decision; the message says what waits.",
639 ["speccoder report"]
640 ),
641 entry!(
642 "NEEDS-APPROVAL",
643 P,
644 S::NeedsHuman,
645 "a call waits for a person's decision; nothing ran",
646 "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.",
647 [
648 "speccoder report --approvals",
649 "speccoder task approve {task}",
650 "speccoder task reject {task} --reason \"…\""
651 ]
652 ),
653 entry!(
654 "BLOCKED",
655 P,
656 S::NeedsHuman,
657 "the model says the task cannot be done as written",
658 "The model used its honest exit: something in the spec or the code stops it. Its reason is a claim, shown as \"Model says\".",
659 [
660 "speccoder task nudge {task} --note \"…\"",
661 "speccoder task skip {task} --reason \"…\""
662 ]
663 ),
664 entry!(
665 "BUDGET-EXHAUSTED",
666 P,
667 S::NeedsHuman,
668 "the attempt ran out of turns, calls or tokens",
669 "The attempt reached a limit of `[budget]` before finishing. The work so far is saved under the attempt's ref.",
670 [
671 "speccoder task nudge {task} --note \"…\"",
672 "→ raise the limit in speccoder.toml [budget]"
673 ]
674 ),
675 entry!(
676 "NOT-DEMONSTRATED",
677 P,
678 S::NeedsHuman,
679 "the evidence the task needs could not be produced",
680 "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.",
681 [
682 "speccoder report",
683 "speccoder task accept {task} --reason \"…\""
684 ]
685 ),
686 entry!(
687 "ACCEPTANCE-UNWRITTEN",
688 P,
689 S::NeedsHuman,
690 "the acceptance tests could not be written, so nothing was attempted",
691 "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.",
692 [
693 "speccoder run --feature {feature}",
694 "→ or set [acceptance] generate = false to rely on the checks alone"
695 ]
696 ),
697 entry!(
698 "SUSPECTED-GAMING",
699 P,
700 S::NeedsHuman,
701 "the gaming monitor suspects a shortcut",
702 "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.",
703 [
704 "speccoder report",
705 "speccoder task accept {task} --reason \"…\"",
706 "speccoder task nudge {task} --note \"…\""
707 ]
708 ),
709 entry!(
710 "TESTS-OVER-STRICT",
711 P,
712 S::NeedsHuman,
713 "an acceptance test rejects an implementation the spec appears to allow",
714 "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.",
715 [
716 "speccoder task rule {task} --tests-right --reason \"…\"",
717 "speccoder run --task {task} --fresh-acceptance",
718 "speccoder task accept {task} --reason \"…\""
719 ]
720 ),
721 entry!(
722 "ACCEPTANCE-WEAK",
723 P,
724 S::NeedsHuman,
725 "the acceptance tests are too weak for [acceptance] min_strength",
726 "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.",
727 [
728 "speccoder report",
729 "speccoder run --task {task}",
730 "speccoder task accept {task} --reason \"…\""
731 ]
732 ),
733 entry!(
734 "INTERRUPTED",
735 P,
736 S::NeedsHuman,
737 "the run was interrupted",
738 "The process was stopped or killed; the journal holds what finished. The next run resumes without repeating finished calls.",
739 ["speccoder run --feature {feature}"]
740 ),
741 entry!(
742 "CHECKLISTS-OPEN",
743 P,
744 S::NeedsHuman,
745 "the feature's checklists have unchecked items",
746 "Spec Kit checklists gate implementation; nothing ran.",
747 [
748 "→ finish the checklists in the feature's checklists/ directory",
749 "speccoder run --ignore-checklists"
750 ]
751 ),
752 entry!(
753 "ARCHIVE-AWAITING",
754 P,
755 S::NeedsHuman,
756 "the OpenSpec archive waits for your yes",
757 "The diff of the archive is shown; nothing is written until a person confirms.",
758 ["speccoder spec archive --yes"]
759 ),
760 entry!(
762 "RUN-FAILED",
763 E,
764 S::RunFailed,
765 "the model call or the run failed",
766 "The provider returned an error, the journal could not be written, or the run broke; the message names it. Nothing was ticked.",
767 ["speccoder run --feature {feature} -v"]
768 ),
769 entry!(
770 "PROVIDER-REFUSED",
771 E,
772 S::RunFailed,
773 "the model provider refused the request",
774 "No credits, a rejected or revoked key, or an account limit. speccoder stops instead of judging the task on less evidence.",
775 [
776 "→ check the provider account's credits and the API key",
777 "speccoder run --feature {feature}"
778 ]
779 ),
780 entry!(
781 "REPLAY-DIVERGED",
782 E,
783 S::ReplayDiverged,
784 "the replay did not reproduce the recorded run",
785 "Strict replay re-derives a run from its journal without a model; a difference means the code's decisions changed.",
786 ["speccoder replay <run> --json"]
787 ),
788 entry!(
789 "NOT-REPLAYABLE",
790 E,
791 S::NotReplayable,
792 "this build cannot re-derive the recorded run",
793 "The run was recorded by a build whose skills or effects this one does not have.",
794 ["→ replay with the speccoder version that recorded the run"]
795 ),
796 entry!(
798 "BUG-NO-UNIT",
799 E,
800 S::UsageError,
801 "this spec format has no place for a bug",
802 "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.",
803 [
804 "→ write a spec for the change and run it",
805 "→ a change without a reproduction: speccoder do \"…\""
806 ]
807 ),
808 entry!(
809 "BUG-EMPTY",
810 E,
811 S::UsageError,
812 "the symptom and every statement need words",
813 "`speccoder bug` records the person's own words: an empty symptom, `--expected` or `--unchanged` is refused before anything is written.",
814 ["speccoder bug \"<what happens>\" --expected \"<what should>\""]
815 ),
816 entry!(
817 "BUG-NO-EXPECTED",
818 E,
819 S::UsageError,
820 "a bug needs at least one --expected statement",
821 "A reproduction asserts what should happen; speccoder never infers it from the symptom or an issue. Give one `--expected` per behaviour.",
822 ["speccoder bug \"<what happens>\" --expected \"<what should>\""]
823 ),
824 entry!(
825 "BUG-ASSESSMENT-DRIFT",
826 P,
827 S::NeedsHuman,
828 "the bug's home does not carry exactly your words",
829 "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.",
830 [
831 "→ edit the assessment so it carries each statement as a `Current:` / `Expected:` / `Unchanged:` line",
832 "speccoder bug --slug <slug>"
833 ]
834 ),
835 entry!(
836 "BUG-ASSESSMENT-UNREADABLE",
837 P,
838 S::NeedsHuman,
839 "the bug's assessment is not in a shape speccoder reads",
840 "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.",
841 [
842 "specify extension list --json",
843 "→ add `Current:` and `Expected:` lines to the assessment's Report section"
844 ]
845 ),
846 entry!(
847 "BUG-TEST-NOT-FOUND",
848 E,
849 S::UsageError,
850 "the test named with --test is not found",
851 "`--test PATH::NAME` must name an existing test file and a test in it that the runner collects.",
852 ["→ give the test as PATH::NAME, as the runner lists it"]
853 ),
854 entry!(
855 "BUG-TEST-NOT-RED",
856 E,
857 S::UsageError,
858 "the named test does not fail on an assertion",
859 "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.",
860 ["→ fix the test so it fails on an assertion, then run `speccoder bug` again"]
861 ),
862 entry!(
863 "BUG-TEST-PASSES",
864 E,
865 S::UsageError,
866 "the named test passes on the untouched code",
867 "A test that passes before any fix cannot show the bug. Perhaps it is fixed already.",
868 ["→ check the behaviour by hand; if it is fixed, there is nothing to record"]
869 ),
870 entry!(
871 "BUG-TEST-COVERAGE",
872 E,
873 S::UsageError,
874 "each --expected statement needs its own --test",
875 "Each stated behaviour gets its own reproduction: repeat `--test` once per `--expected`, in the same order.",
876 [
877 "speccoder bug \"…\" --expected \"<e1>\" --test <file>::<test1> --expected \"<e2>\" --test <file>::<test2>"
878 ]
879 ),
880 entry!(
881 "BUG-CANNOT-REPRODUCE",
882 P,
883 S::NeedsHuman,
884 "the bug could not be reproduced: nothing is fixed",
885 "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.",
886 [
887 "speccoder bug run --task {feature}/{task}",
888 "speccoder bug \"…\" --expected \"…\" --test <file>::<test>",
889 "speccoder task drop {task}"
890 ]
891 ),
892 entry!(
893 "BUG-ALREADY-SATISFIED",
894 W,
895 S::Ok,
896 "the reproductions already pass: nothing to fix",
897 "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.",
898 [
899 "speccoder bug keep {feature}/{task} --reason \"kept as a regression test\"",
900 "speccoder task drop {task}"
901 ]
902 ),
903 entry!(
904 "BUG-UNCHANGED-NOT-HOLDING",
905 P,
906 S::NeedsHuman,
907 "an Unchanged statement does not hold today",
908 "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.",
909 ["→ reword or remove the statement, then `speccoder bug run`"]
910 ),
911 entry!(
912 "BUG-NOT-DISCRIMINATING",
913 E,
914 S::VerificationFailed,
915 "the reproduction does not tell the fix from no fix",
916 "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.",
917 ["speccoder run --task {task}"]
918 ),
919 entry!(
920 "BUG-REPRO-WEAK",
921 P,
922 S::NeedsHuman,
923 "a fix that special-cases the reproduction's input passes",
924 "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.",
925 [
926 "speccoder task rule {task} --tests-right --reason \"…\"",
927 "speccoder bug \"…\" --expected \"…\" --test <file>::<test>"
928 ]
929 ),
930 entry!(
931 "BUG-CANDIDATE-APPLY",
932 E,
933 S::GitPrecondition,
934 "the candidate patch is not applied",
935 "`--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).",
936 ["→ rebase the patch on HEAD, as a text diff without binary hunks or links"]
937 ),
938 entry!(
939 "BUG-CANDIDATE-JUDGE",
940 E,
941 S::UsageError,
942 "the candidate patch touches what judges it",
943 "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.",
944 ["→ remove those hunks from the patch"]
945 ),
946 entry!(
947 "EVAL-FAILED",
948 E,
949 S::EvalFailed,
950 "the evaluation found a false completion or a cheat",
951 "A case ended done although its hidden oracle fails, or the attempt gamed its tests.",
952 ["speccoder eval --keep <dir>"]
953 ),
954];
955
956#[must_use]
958pub fn lookup(name: &str) -> Option<&'static Entry> {
959 CATALOG.iter().find(|e| e.name == name)
960}
961
962#[must_use]
964pub fn default_for(status: CommandStatus) -> Option<&'static Entry> {
965 let name = match status {
966 S::Ok => return None,
967 S::UsageError => "USAGE",
968 S::Error => "INTERNAL",
969 S::NotAProject => "NO-PROJECT",
970 S::DiagnosticsError => "SPEC-DIAGNOSTICS",
971 S::SelectionNeeded => "FEATURE-SELECTION",
972 S::ConfigError => "CONFIG",
973 S::VerificationFailed => "VERIFICATION-FAILED",
974 S::GitPrecondition => "GIT",
975 S::NotFound => "NOT-FOUND",
976 S::RunFailed => "RUN-FAILED",
977 S::ReplayDiverged => "REPLAY-DIVERGED",
978 S::TaskNotReady => "TASK-NOT-READY",
979 S::NeedsHuman => "NEEDS-HUMAN",
980 S::EvalFailed => "EVAL-FAILED",
981 S::NotReplayable => "NOT-REPLAYABLE",
982 S::AttestationFailed => "ATTESTATION-FAILED",
983 };
984 lookup(name)
985}
986
987#[must_use]
989pub fn nearest(name: &str, n: usize) -> Vec<&'static str> {
990 let wanted = name.to_ascii_uppercase();
991 let mut scored: Vec<(usize, &'static str)> = CATALOG
992 .iter()
993 .map(|e| (distance(&wanted, e.name), e.name))
994 .collect();
995 scored.sort();
996 scored
997 .into_iter()
998 .filter(|(d, _)| *d <= wanted.len().max(3) / 2 + 1)
999 .take(n)
1000 .map(|(_, name)| name)
1001 .collect()
1002}
1003
1004fn distance(a: &str, b: &str) -> usize {
1005 let b: Vec<char> = b.chars().collect();
1006 let mut row: Vec<usize> = (0..=b.len()).collect();
1007 for (i, ca) in a.chars().enumerate() {
1008 let mut prev = row[0];
1009 row[0] = i + 1;
1010 for (j, cb) in b.iter().enumerate() {
1011 let cur = row[j + 1];
1012 row[j + 1] = (prev + usize::from(ca != *cb)).min(row[j] + 1).min(cur + 1);
1013 prev = cur;
1014 }
1015 }
1016 row[b.len()]
1017}
1018
1019#[must_use]
1022pub fn fixes(
1023 entry: &Entry,
1024 command: &str,
1025 task: Option<&str>,
1026 feature: Option<&str>,
1027) -> Vec<String> {
1028 let general = entry.fix.iter().any(|f| !f.contains("{task}"));
1031 entry
1032 .fix
1033 .iter()
1034 .filter(|f| task.is_some() || !general || !f.contains("{task}"))
1035 .map(|f| {
1036 let feature_arg = feature.map_or_else(String::new, |f| f.to_owned());
1037 let mut line = f
1038 .replace("{command}", command)
1039 .replace("{task}", task.unwrap_or("<task>"));
1040 line = if feature.is_some() {
1041 line.replace("{feature}", &feature_arg)
1042 } else {
1043 line.replace(" --feature {feature}", "")
1045 .replace("{feature}", "<feature>")
1046 };
1047 line
1048 })
1049 .collect()
1050}
1051
1052#[cfg(test)]
1053mod tests {
1054 use super::*;
1055
1056 const STATUSES: [CommandStatus; 17] = [
1057 S::Ok,
1058 S::UsageError,
1059 S::Error,
1060 S::NotAProject,
1061 S::DiagnosticsError,
1062 S::SelectionNeeded,
1063 S::ConfigError,
1064 S::VerificationFailed,
1065 S::GitPrecondition,
1066 S::NotFound,
1067 S::RunFailed,
1068 S::ReplayDiverged,
1069 S::TaskNotReady,
1070 S::NeedsHuman,
1071 S::EvalFailed,
1072 S::NotReplayable,
1073 S::AttestationFailed,
1074 ];
1075
1076 #[test]
1077 fn names_are_unique_upper_case_words() {
1078 let mut seen = std::collections::BTreeSet::new();
1079 for e in CATALOG {
1080 assert!(seen.insert(e.name), "{} twice", e.name);
1081 assert!(
1082 e.name.split('-').all(|w| !w.is_empty()
1083 && w.chars()
1084 .all(|c| c.is_ascii_uppercase() || c.is_ascii_digit())),
1085 "{}",
1086 e.name
1087 );
1088 assert!(!e.fix.is_empty() && !e.title.ends_with('.'), "{}", e.name);
1089 assert!(
1090 e.title.chars().next().is_some_and(char::is_lowercase),
1091 "{}",
1092 e.name
1093 );
1094 }
1095 }
1096
1097 #[test]
1098 fn every_non_ok_status_has_a_default_and_kinds_agree_with_statuses() {
1099 for s in STATUSES {
1100 let d = default_for(s);
1101 assert_eq!(d.is_none(), s == S::Ok, "{s:?}");
1102 if let Some(d) = d {
1103 assert_eq!(d.status, s);
1104 }
1105 }
1106 for e in CATALOG {
1107 assert_eq!(
1108 e.kind == Kind::Stop,
1109 e.status == S::NeedsHuman,
1110 "{}",
1111 e.name
1112 );
1113 assert_eq!(e.kind == Kind::Warning, e.status == S::Ok, "{}", e.name);
1114 }
1115 }
1116
1117 #[test]
1118 fn near_misses_are_suggested_and_placeholders_filled() {
1119 assert_eq!(nearest("uncommited-intent", 1), ["UNCOMMITTED-INTENT"]);
1120 assert_eq!(nearest("NEEDS-APROVAL", 1), ["NEEDS-APPROVAL"]);
1121 assert!(nearest("completely-unrelated-words", 3).is_empty());
1122 let e = lookup("NEEDS-APPROVAL").unwrap();
1123 assert_eq!(
1124 fixes(e, "run", Some("T004"), None)[1],
1125 "speccoder task approve T004"
1126 );
1127 let r = lookup("INTERRUPTED").unwrap();
1128 assert_eq!(fixes(r, "run", None, None), ["speccoder run"]);
1129 assert_eq!(
1130 fixes(r, "run", None, Some("001-x")),
1131 ["speccoder run --feature 001-x"]
1132 );
1133 }
1134}