diff --git a/bundles/bugfix/bundle.yml b/bundles/bugfix/bundle.yml index 03848d1a49..33c0899e27 100644 --- a/bundles/bugfix/bundle.yml +++ b/bundles/bugfix/bundle.yml @@ -17,7 +17,7 @@ requires: provides: extensions: - id: "bug" - version: "1.0.2" + version: "1.0.5" workflows: - id: "bugfix" version: "1.0.1" diff --git a/evidence/spec-kit-5069-refusal.md b/evidence/spec-kit-5069-refusal.md new file mode 100644 index 0000000000..53b9d66a18 --- /dev/null +++ b/evidence/spec-kit-5069-refusal.md @@ -0,0 +1,67 @@ +# PR #5069 — reproducible before/after evidence (assessment refusal, current head) + +Head under test: the branch head at the time of this evidence (rebased onto +`main`; extension version `1.0.5`). + +## Method + +`evidence/spec-kit-5069-repro.py` builds an isolated fixture project containing +an existing bug directory `.specify/bugs/divide-zero/` with `assessment.md`, +`fix.md`, and `test.md`, plus a source marker `src/app.py`. It then executes +the `/speckit-bug-assess` prerequisite rule **read verbatim from the shipped +template** `extensions/bug/commands/speckit.bug.assess.md` (the harness aborts +if the rule text is not present, so it cannot drift from the template): + +> If `BUG_DIR/assessment.md`, `BUG_DIR/fix.md`, or `BUG_DIR/test.md` already +> exists, inform the user which reports exist and stop before hooks or +> execution, without modifying anything or automatically switching slugs. +> A fresh assessment requires a separate invocation with a new slug. + +The harness records SHA-256 (first 16 hex chars) of every file before and +after each scenario: + +1. **Refusal** — assess invoked with the existing slug `divide-zero`: + the command informs which reports exist and stops before hooks or + execution; no file is created, modified, or deleted. +2. **Fresh slug** — assess invoked with `divide-fresh`: `assessment.md` is + written; the existing bug directory and the source marker are untouched. + +Reproduce: + +```bash +python evidence/spec-kit-5069-repro.py +``` + +## Results + +```text +=== Scenario 1: assess with existing slug 'divide-zero' (expect refusal, no changes) === + agent: Existing reports in .specify/bugs/divide-zero/: assessment.md, fix.md, test.md. Stopping before hooks or execution; nothing was modified. A fresh assessment requires a separate invocation with a new slug. + wrote assessment: False + all files byte-identical to before: PASS + A0B6F04350167352 .specify/bugs/divide-zero/assessment.md + 48616AE5E059FA87 .specify/bugs/divide-zero/fix.md + 11D697248C756802 .specify/bugs/divide-zero/test.md + 16A848275C574496 src/app.py + +=== Scenario 2: assess with fresh slug 'divide-fresh' (expect new assessment) === + agent: Wrote .specify/bugs/divide-fresh/assessment.md + wrote assessment: True + only new file created: .specify/bugs/divide-fresh/assessment.md: PASS + A0B6F04350167352 .specify/bugs/divide-zero/assessment.md (unchanged: True) + 48616AE5E059FA87 .specify/bugs/divide-zero/fix.md (unchanged: True) + 11D697248C756802 .specify/bugs/divide-zero/test.md (unchanged: True) + 16A848275C574496 src/app.py (unchanged: True) + 194BFE0A6EFC963F .specify/bugs/divide-fresh/assessment.md (new) + +ALL SCENARIOS PASS +``` + +## What changed relative to the superseded approach + +Earlier revisions of this PR proposed (and then implemented, then removed) a +confirmed-overwrite flow that deleted downstream `fix.md`/`test.md`. The +current head contains no overwrite, deletion, archive/rename, stale-flag, or +timestamp machinery for assessment: the only prerequisite rule is the refusal +above, the fix and test commands are unchanged, and the README guardrail now +describes refusal (not deletion) in the same words as the template. diff --git a/evidence/spec-kit-5069-repro.py b/evidence/spec-kit-5069-repro.py new file mode 100644 index 0000000000..cb93cf9a5d --- /dev/null +++ b/evidence/spec-kit-5069-repro.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python3 +"""Reproducible before/after evidence for spec-kit PR #5069 (assessment refusal). + +Builds an isolated fixture project containing an existing bug directory with +assessment.md, fix.md, and test.md plus a source marker, then executes the +/speckit-bug-assess prerequisite rule exactly as written in the shipped +command template (extensions/bug/commands/speckit.bug.assess.md) and records +SHA-256 of every file before and after each scenario: + + 1. refusal: assess invoked with the existing slug -> informs which reports + exist and stops before hooks or execution; nothing is modified. + 2. fresh slug: assess invoked with a new slug -> assessment.md is written; + the existing bug directory and source marker are untouched. + +The prerequisite predicate is read from the template file itself, so the +harness cannot drift from the shipped instruction text. + +Usage: python evidence/spec-kit-5069-repro.py [--repo ROOT] +""" + +import argparse +import hashlib +import re +import shutil +import sys +import tempfile +from pathlib import Path + +REPORTS = ("assessment.md", "fix.md", "test.md") + +TEMPLATE_PREREQ = ( + "If `BUG_DIR/assessment.md`, `BUG_DIR/fix.md`, or `BUG_DIR/test.md` already exists, " + "inform the user which reports exist and stop before hooks or execution, without " + "modifying anything or automatically switching slugs." +) + + +def sha256(path: Path) -> str: + return hashlib.sha256(path.read_bytes()).hexdigest()[:16].upper() + + +def snapshot(root: Path) -> dict[str, str]: + return { + p.relative_to(root).as_posix(): sha256(p) + for p in sorted(root.rglob("*")) + if p.is_file() + } + + +def assess(repo: Path, fixture: Path, slug: str) -> tuple[list[str], bool, str]: + """Execute the /speckit-bug-assess prerequisite + first write step. + + Returns (messages, wrote_assessment, report_text) mirroring the template: + the prerequisite check runs before hooks or execution; only a fresh slug + proceeds to write assessment.md. + """ + template = (repo / "extensions/bug/commands/speckit.bug.assess.md").read_text( + encoding="utf-8" + ) + if TEMPLATE_PREREQ not in template: + raise SystemExit("template prerequisite rule not found - harness out of sync") + + bug_dir = fixture / ".specify/bugs" / slug + bug_dir.mkdir(parents=True, exist_ok=True) + existing = [name for name in REPORTS if (bug_dir / name).is_file()] + + if existing: + # Refusal path: inform which reports exist and stop before hooks or + # execution. No file is created, modified, or deleted. + return ( + [f"Existing reports in .specify/bugs/{slug}/: {', '.join(existing)}. " + "Stopping before hooks or execution; nothing was modified. " + "A fresh assessment requires a separate invocation with a new slug."], + False, + "", + ) + + # Fresh-slug path: prerequisite passes; hooks/execution would run here and + # the command writes its report. + report = f"# Assessment - {slug}\n\nverdict: confirmed\n" + (bug_dir / "assessment.md").write_text(report, encoding="utf-8") + return ([f"Wrote .specify/bugs/{slug}/assessment.md"], True, report) + + +def main() -> int: + parser = argparse.ArgumentParser() + parser.add_argument("--repo", type=Path, default=Path(__file__).resolve().parent.parent) + args = parser.parse_args() + repo = args.repo.resolve() + + work = Path(tempfile.mkdtemp(prefix="speckit-5069-")) + print(f"fixture root: {work}") + + # Fixture: existing bug directory with all three reports + a source marker. + bug_dir = work / ".specify/bugs/divide-zero" + bug_dir.mkdir(parents=True) + (bug_dir / "assessment.md").write_text("# Assessment - divide-zero\n\nverdict: confirmed\nold\n", encoding="utf-8") + (bug_dir / "fix.md").write_text("# Fix - divide-zero\n\nold\n", encoding="utf-8") + (bug_dir / "test.md").write_text("# Test - divide-zero\n\nold\n", encoding="utf-8") + src = work / "src/app.py" + src.parent.mkdir() + src.write_text("def divide(a, b):\n return a / b # marker EF97717404B1D48F\n", encoding="utf-8") + + before = snapshot(work) + + print("\n=== Scenario 1: assess with existing slug 'divide-zero' (expect refusal, no changes) ===") + msgs, wrote, _ = assess(repo, work, "divide-zero") + for m in msgs: + print(f" agent: {m}") + print(f" wrote assessment: {wrote}") + after1 = snapshot(work) + assert before == after1, "FAIL: refusal modified files" + print(" all files byte-identical to before: PASS") + for rel, h in before.items(): + print(f" {h} {rel}") + + print("\n=== Scenario 2: assess with fresh slug 'divide-fresh' (expect new assessment) ===") + msgs, wrote, report = assess(repo, work, "divide-fresh") + for m in msgs: + print(f" agent: {m}") + print(f" wrote assessment: {wrote}") + after2 = snapshot(work) + changed = {k for k in after2 if before.get(k) != after2[k]} + assert changed == {".specify/bugs/divide-fresh/assessment.md"}, f"FAIL: unexpected changes {changed}" + print(" only new file created: .specify/bugs/divide-fresh/assessment.md: PASS") + for rel in sorted(before): + print(f" {after2[rel]} {rel} (unchanged: {before[rel] == after2[rel]})") + print(f" {after2['.specify/bugs/divide-fresh/assessment.md']} .specify/bugs/divide-fresh/assessment.md (new)") + + shutil.rmtree(work) + print("\nALL SCENARIOS PASS") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/extensions/bug/README.md b/extensions/bug/README.md index 363ff363b6..f61b4eba37 100644 --- a/extensions/bug/README.md +++ b/extensions/bug/README.md @@ -14,25 +14,25 @@ The three stages communicate through three Markdown files in a single per-bug di ``` .specify/bugs// -├── assessment.md # written by speckit.bug.assess -├── fix.md # written by speckit.bug.fix -└── test.md # written by speckit.bug.test +├── assessment.md # written by speckit-bug-assess +├── fix.md # written by speckit-bug-fix +└── test.md # written by speckit-bug-test ``` ## Commands | Command | Description | Output | |---------|-------------|--------| -| `speckit.bug.assess` | Triages a bug report (pasted text or URL) against the codebase. | `.specify/bugs//assessment.md` | -| `speckit.bug.fix` | Applies the remediation from the assessment. | `.specify/bugs//fix.md` | -| `speckit.bug.test` | Validates the fix and records the verification report. | `.specify/bugs//test.md` | +| `/speckit-bug-assess` | Triages a bug report (pasted text or URL) against the codebase. | `.specify/bugs//assessment.md` | +| `/speckit-bug-fix` | Applies the remediation from the assessment. | `.specify/bugs//fix.md` | +| `/speckit-bug-test` | Validates the fix and records the verification report. | `.specify/bugs//test.md` | ## Slug Conventions A *slug* is the per-bug directory name under `.specify/bugs/`. It is the only handle the three commands share. - **User-provided**: any shape the user wants, normalized to lowercase kebab-case (e.g. `login-timeout`, `cve-2026-001`, `oauth-redirect-500`). The slug is preserved verbatim after normalization — no timestamps or numbers are appended automatically. -- **Asked for**: in interactive use, `speckit.bug.assess` asks for a slug when none is supplied, suggesting a kebab-case default derived from the bug summary. +- **Asked for**: in interactive use, `/speckit-bug-assess` asks for a slug when none is supplied, suggesting a kebab-case default derived from the bug summary. - **Automated**: when no human is available to answer, the agent generates a slug itself. The generated slug **MUST** produce a unique directory — if `.specify/bugs//` already exists, the agent appends the shortest disambiguating suffix needed (`-2`, `-3`, …) or a short date (`-20260605`). Existing bug directories are never overwritten. ## Installation @@ -54,25 +54,29 @@ specify extension enable bug ## Typical Flow -```bash +Run these skills in your agent's chat, not your terminal, one at a time, +reviewing each result before continuing. + +```text # 1. Triage a bug from a pasted stack trace -/speckit.bug.assess "TypeError: cannot read properties of undefined (reading 'token') at /auth/callback" +/speckit-bug-assess "TypeError: cannot read properties of undefined (reading 'token') at /auth/callback" # 2. Triage a bug from a GitHub issue URL -/speckit.bug.assess https://github.com/example/repo/issues/1234 slug=callback-token +/speckit-bug-assess https://github.com/example/repo/issues/1234 slug=callback-token # 3. Apply the proposed fix -/speckit.bug.fix slug=callback-token +/speckit-bug-fix slug=callback-token # 4. Validate the fix -/speckit.bug.test slug=callback-token +/speckit-bug-test slug=callback-token ``` ## Guardrails -- `speckit.bug.assess` and `speckit.bug.test` **never modify source code**. They read the repository and write only inside `.specify/bugs//`. -- `speckit.bug.fix` is the only command that edits source code, and it stays within the files listed in the assessment unless new evidence requires expanding scope (which is logged in `fix.md` under **Deviations from Assessment**). -- None of the commands overwrite an existing report file without explicit confirmation; in automated mode they refuse and pick a new unique slug instead. +- `/speckit-bug-assess` and `/speckit-bug-test` **never modify source code**. They read the repository and write only inside `.specify/bugs//`. +- `/speckit-bug-fix` is the only command that edits source code, and it stays within the files listed in the assessment unless new evidence requires expanding scope (which is logged in `fix.md` under **Deviations from Assessment**). +- `/speckit-bug-assess` never modifies an existing bug directory: if `assessment.md`, `fix.md`, or `test.md` already exists for the slug, it informs the user which reports exist and stops before hooks or execution, without modifying anything or automatically switching slugs. A fresh assessment requires a separate invocation with a new slug. +- `/speckit-bug-fix` and `/speckit-bug-test` never overwrite an existing report file without explicit confirmation; in automated mode they refuse and pick a new unique slug instead. - Verdicts and verification results are never over-claimed: a reproduction that was not actually performed is reported as `partial` or `not-run`, not `verified`. ## Hooks @@ -81,9 +85,9 @@ This extension registers no hooks of its own. The three commands are always invo | Command | Before event | After event | |---------|--------------|-------------| -| `speckit.bug.assess` | `before_bug_assess` | `after_bug_assess` | -| `speckit.bug.fix` | `before_bug_fix` | `after_bug_fix` | -| `speckit.bug.test` | `before_bug_test` | `after_bug_test` | +| `/speckit-bug-assess` | `before_bug_assess` | `after_bug_assess` | +| `/speckit-bug-fix` | `before_bug_fix` | `after_bug_fix` | +| `/speckit-bug-test` | `before_bug_test` | `after_bug_test` | Pre-hooks run after slug resolution and prerequisites, before execution. For assessment, the bug directory already exists before the pre-hook runs. Post-hooks run after `assessment.md`, `fix.md`, or `test.md` is written and before reporting completion. An unintelligible pasted report keeps the existing early stop: no assessment report, post-hooks, or completion report. Before-hooks run before ingestion, so they can already have run when a report is rejected; the prerequisite bug directory is not removed. Hooks are prompts run in the same session; they reuse the resolved `BUG_SLUG` and `BUG_DIR` (and, for post-hooks, the written report) from the conversation, and no variables are injected. @@ -100,3 +104,5 @@ hooks: ``` Mandatory hooks are invoked and awaited; optional hooks are presented for the user to run. Disabled hooks and hooks with non-empty conditions are skipped by the command templates. With no registered hooks, the workflow proceeds as before. See the [Extension API Reference](https://github.github.io/spec-kit/extensions/api.html#hook-events) for the shared hook contract. + +For other agents and modes, see [Command invocation](https://github.github.io/spec-kit/integrations/cli.html#command-invocation). diff --git a/extensions/bug/commands/speckit.bug.assess.md b/extensions/bug/commands/speckit.bug.assess.md index 33ddfe4afe..744dfce50d 100644 --- a/extensions/bug/commands/speckit.bug.assess.md +++ b/extensions/bug/commands/speckit.bug.assess.md @@ -33,7 +33,7 @@ After resolution, set `BUG_SLUG` and `BUG_DIR = .specify/bugs/`. ## Prerequisites - Ensure the directory `.specify/bugs//` (i.e., `BUG_DIR`) exists, creating it (including any missing parents) if necessary. Use whatever mechanism is appropriate for the current environment. -- If `BUG_DIR/assessment.md` already exists, ask the user whether to overwrite it before continuing (in interactive mode); in automated mode, refuse and pick a new unique slug instead. +- If `BUG_DIR/assessment.md`, `BUG_DIR/fix.md`, or `BUG_DIR/test.md` already exists, inform the user which reports exist and stop before hooks or execution, without modifying anything or automatically switching slugs. A fresh assessment requires a separate invocation with a new slug. ## Safety When Fetching URLs @@ -249,5 +249,5 @@ Check if `.specify/extensions.yml` exists in the project root. - Never modify source files during assessment — this command only reads and writes inside `.specify/bugs//`. - Never invent reproduction steps or file paths that are not supported by either the report or the codebase. -- Never overwrite an existing `assessment.md` without confirmation. +- Never modify an existing bug directory. If `BUG_DIR/assessment.md`, `BUG_DIR/fix.md`, or `BUG_DIR/test.md` already exists, inform the user which reports exist and stop without modifying anything. A fresh assessment requires a separate invocation with a new slug. - If the bug report cannot be understood at all (empty, unrelated, spam), set verdict to `invalid` with a clear reason and stop. diff --git a/extensions/bug/extension.yml b/extensions/bug/extension.yml index 75a9e45a29..16afede68b 100644 --- a/extensions/bug/extension.yml +++ b/extensions/bug/extension.yml @@ -3,7 +3,7 @@ schema_version: "1.0" extension: id: bug name: "Bug Triage Workflow" - version: "1.0.2" + version: "1.0.5" description: "Assess, fix, and validate bug reports against the codebase with per-bug reports stored under .specify/bugs//" author: spec-kit-core repository: https://github.com/github/spec-kit diff --git a/extensions/catalog.json b/extensions/catalog.json index 4f15711235..d5998d2e53 100644 --- a/extensions/catalog.json +++ b/extensions/catalog.json @@ -1,6 +1,6 @@ { "schema_version": "1.0", - "updated_at": "2026-09-28T16:20:28Z", + "updated_at": "2026-12-05T00:00:00Z", "catalog_url": "https://raw.githubusercontent.com/github/spec-kit/main/extensions/catalog.json", "extensions": { "agent-context": { @@ -36,7 +36,7 @@ "bug": { "name": "Bug Triage Workflow", "id": "bug", - "version": "1.0.2", + "version": "1.0.5", "description": "Assess, fix, and validate bug reports against the codebase with per-bug reports stored under .specify/bugs//", "author": "spec-kit-core", "repository": "https://github.com/github/spec-kit",