diff --git a/AGENTS.md b/AGENTS.md index 4b3b38d..92dfc8f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -39,3 +39,5 @@ Use Conventional Commits messages. The commit type decides the next version: ## This is your space If you find something noteworthy while working in this repository, add it here for discussion. + +- The `guided-coding-version` marker in `skills/guided-coding-setup/assets/ai-plans-AGENTS.md` is maintained by hand; the release tool does not update it. When you change the asset, set the marker to the version the next release will get, so that `guided-coding-setup` upgrades existing repositories. diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dec257..bbaee09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to Guided Coding are documented here. ## [Unreleased] +- Keep Plan Deviations documents editable until they are merged into the target branch instead of freezing them once committed, so that Follow-Up Plans from PR/MR reviews can still be recorded. `guided-coding-write-deviations` now rewrites the work item's existing document under a fresh timestamp, keeping one document per work item that sorts after all of its plans. Run `guided-coding-setup` to bring `ai-plans/AGENTS.md` up to date. - Add `guided-coding-plan-and-review`, which writes a plan and refines it through independent reviewers in bounded rounds. Reviewers run `guided-coding-review-plan` in fresh contexts; the planner addresses every finding but never changes a decision the user made explicitly, and reports every finding with its resolution. - Let models invoke `guided-coding-write-plan` and `guided-coding-review-plan`, so other Guided Coding skills can use them. Their descriptions limit them to explicit requests by the user or by another Guided Coding skill. - Add RDAT (Rationale, Decisions, Acceptance Criteria, Technical Details), an opt-in plan structure next to the default one: numbered Decisions summarize what a reviewer approves, and each section adds information instead of repeating earlier ones. diff --git a/claude-plugin/claude-skills/setup/assets/ai-plans-AGENTS.md b/claude-plugin/claude-skills/setup/assets/ai-plans-AGENTS.md index 6980ba7..23b839b 100644 --- a/claude-plugin/claude-skills/setup/assets/ai-plans-AGENTS.md +++ b/claude-plugin/claude-skills/setup/assets/ai-plans-AGENTS.md @@ -1,13 +1,13 @@ # AGENTS.md for AI plans - + This directory is the append-only record of how work in this repository was planned and how it turned out, similar to Event Sourcing. It follows the [Guided Coding](https://kenny-codes.net/docs/guided-coding/) approach. Frozen Plan file names use `YYYY-MM-DD-HHMM--.md`, timestamped in UTC. The `` is omitted when work has no ticket. It also carries a `*Frozen at ` line directly below its title. When a plan is not frozen yet, its file name is typically `.md`. Plan Deviations filenames use `YYYY-MM-DD-HHMM--plan-deviations.md` or `YYYY-MM-DD-HHMM--plan-deviations.md`. -Plans are frozen when their Planning Phase ends. From then on, the only permitted edit is checking an acceptance criterion (`- [ ]` to `- [x]`) after the implementation and relevant feedback loops verify it. Never reword, add, remove, or reorder criteria in a frozen plan. Plan Deviations documents are frozen once committed. +Plans are frozen when their Planning Phase ends. From then on, the only permitted edit is checking an acceptance criterion (`- [ ]` to `- [x]`) after the implementation and relevant feedback loops verify it. Never reword, add, remove, or reorder criteria in a frozen plan. Plan Deviations documents are frozen once they are merged into the target branch. Until then, it is rewritten under a fresh timestamp whenever it needs to change, e.g., when a review of the PR/MR leads to another Follow-Up Plan, so that it always sorts after all plans of its work item. A Follow-Up Plan supersedes decisions of a Frozen Plan. The decision to write one is made in the Guiding Phase, when the review of the implementation calls for larger changes. -A Plan Deviations document records all changes from the Initial Plan to the final implementation; it is only written when Follow-Up Plans exist or the implementation materially deviates from the plans. Reading the Initial Plan and, if present, the Plan Deviations document is enough to understand all work related to a ticket. +A work item has at most one Plan Deviations document. It records all changes from the Initial Plan to the final implementation. It is only written when Follow-Up Plans exist or the implementation materially deviates from the plans. Reading the Initial Plan and, if present, the Plan Deviations document is enough to understand all work related to a ticket. diff --git a/claude-plugin/claude-skills/write-deviations/SKILL.md b/claude-plugin/claude-skills/write-deviations/SKILL.md index 32759fd..c20a57c 100644 --- a/claude-plugin/claude-skills/write-deviations/SKILL.md +++ b/claude-plugin/claude-skills/write-deviations/SKILL.md @@ -1,23 +1,37 @@ --- name: write-deviations -description: "Decide whether a completed Guided Coding cycle needs a Plan Deviations document and write it when required. Run only when explicitly requested by the user." +description: "Decide whether a completed Guided Coding cycle needs a Plan Deviations document and write or update it when required. Run only when explicitly requested by the user." license: "MIT" disable-model-invocation: true --- # Write Plan Deviations -Your goal is to decide whether the completed implementation needs a Plan Deviations document and, if so, to write it into the `ai-plans/` folder at the repository root. After writing, report the document path and stop. +Your goal is to decide whether the completed implementation needs a Plan Deviations document and, if so, to write it into the `ai-plans/` folder at the repository root or update the existing one. After writing, report the document path and stop. -A Plan Deviations document summarizes how the completed implementation differs from the original plan. Reading the initial plan together with this document should be enough to understand the complete work. +A Plan Deviations document summarizes how the completed implementation differs from the original plan. Reading the initial plan together with this document should be enough to understand the complete work. A work item has at most one Plan Deviations document. It stays editable until it is merged into the target branch, because reviews of the PR/MR can still lead to Follow-Up Plans; from then on, it is frozen. ## 1. Inspect the Plans and the Implementation Read all plans for the current ticket in `ai-plans/`, oldest first. Identify them by the `` or `` in their file names, or by the plans mentioned in the conversation. Ask the user if the set of plans is unclear. -Determine the implementation range. Use the PR/MR if there is one. Otherwise, use the merge base between the target branch and the implementation branch. Inspect the commits in that range, all committed, staged, and unstaged changes, and any relevant earlier history. Verify every document and source-file reference you rely on. +Determine the target branch and the implementation range. Use the PR/MR if there is one. Otherwise, use the merge base between the target branch and the implementation branch. Ask the user if the target branch is unclear. Inspect the commits in that range, all committed, staged, and unstaged changes, and any relevant earlier history. Verify every document and source-file reference you rely on. -## 2. Decide Whether a Document Is Needed +## 2. Check for an Existing Plan Deviations Document + +Look for an existing Plan Deviations document of the current ticket in `ai-plans/`. Its file name ends with `--plan-deviations.md` or `--plan-deviations.md`, using the same `` or `` as the Initial Plan. If you find more than one, report them and stop; the user decides which one to keep. + +If there is an existing document, check whether it is already merged into the target branch: + +1. Fetch the target branch from its remote into its remote-tracking branch with an explicit refspec, e.g., `git fetch origin +refs/heads/main:refs/remotes/origin/main`, and use that remote-tracking branch, e.g., `origin/main`. The explicit refspec updates it regardless of the remote's configured fetch mappings. Only if the repository has no remote at all, use the local target branch. If fetching fails, report the error and stop without changing anything: a stale local branch cannot prove that the document is unmerged. +2. Verify that the target branch resolves, e.g., `git rev-parse --verify origin/main`. If it does not, report this and stop without changing anything. +3. Check whether the document's path exists on the target branch, e.g., `git cat-file -e origin/main:ai-plans/`. Check the path, not whether commits are ancestors of the target branch: squash and rebase merges rewrite commits but keep the file. + +If the document exists on the target branch, it is frozen. Report that it was merged into the target branch, and that the user can delete it and run this skill again to recreate it from scratch. Do not delete or change it yourself, and stop. + +Otherwise, you update the existing document in the following steps. + +## 3. Decide Whether a Document Is Needed Write a Plan Deviations document in either of these cases: @@ -26,23 +40,27 @@ Write a Plan Deviations document in either of these cases: Routine choices the plans left open are not deviations. An Acceptance Criterion that is documented but not met remains incomplete; it does not count as a deviation unless an accepted Follow-Up Plan explicitly supersedes it. -If there is only one plan and no material deviations, report that conclusion to the user, create nothing, and stop. +If there is only one plan and no material deviations, report that conclusion to the user, create nothing, and stop. If an existing, unmerged document is no longer needed, also report this, leave the document unchanged, and let the user decide whether to delete it. -## 3. Determine the File Name +## 4. Determine the File Name The file name is: - `--plan-deviations.md` if a `` is present - `--plan-deviations.md` otherwise -Take `` or `` from the file name of the Initial Plan. The `` is UTC in the format `YYYY-MM-DD-HHMM`. Use these commands to get it: +Take `` or `` from the file name of the Initial Plan. The `` is the current time in UTC in the format `YYYY-MM-DD-HHMM`, also when you update an existing document. Use these commands to get it: - `date -u +%F-%H%M` on Unix-based shells - `(Get-Date).ToUniversalTime().ToString("yyyy-MM-dd-HHmm")` on PowerShell -If a plan or Plan Deviations document with this file name already exists, report the collision and stop. Never overwrite or reuse an existing file. Committed Plan Deviations documents are frozen. +The Plan Deviations document must sort after all plans of the ticket. Therefore, the `` must be strictly later than the timestamps in the file names of all plans of the ticket and of the existing Plan Deviations document. If it is not, wait until the next minute and get the timestamp again. + +If a plan or another Plan Deviations document with this file name already exists, report the collision and stop. Never overwrite a plan or a frozen Plan Deviations document. + +## 5. Write the Document -## 4. Write the Document +When you update an existing document, first move it to the new file name. Use `git mv ` if the old file is tracked by Git, so that Git can detect the rename; otherwise, rename the file. Then rewrite the whole document from the plans and the implementation you inspected in step 1. Do not append to the previous content, and do not mention earlier versions of the document. Structure the document as follows: @@ -54,6 +72,6 @@ Structure the document as follows: Name the affected types, members, and files. Leave out work that matches the accepted plans. If the implementation matches all Follow-Up Plans, say so in the Summary and omit `## Deviations From the Accepted Plans`. -## 5. Stop +## 6. Stop -Report the document path. Do not commit, publish, or create or update a PR/MR. The user reviews and finalizes the document. +Report the document path. When you updated an existing document, also report its previous path and whether the rename is staged. Do not commit, publish, or create or update a PR/MR. The user reviews and finalizes the document. diff --git a/skills/guided-coding-setup/assets/ai-plans-AGENTS.md b/skills/guided-coding-setup/assets/ai-plans-AGENTS.md index 6980ba7..23b839b 100644 --- a/skills/guided-coding-setup/assets/ai-plans-AGENTS.md +++ b/skills/guided-coding-setup/assets/ai-plans-AGENTS.md @@ -1,13 +1,13 @@ # AGENTS.md for AI plans - + This directory is the append-only record of how work in this repository was planned and how it turned out, similar to Event Sourcing. It follows the [Guided Coding](https://kenny-codes.net/docs/guided-coding/) approach. Frozen Plan file names use `YYYY-MM-DD-HHMM--.md`, timestamped in UTC. The `` is omitted when work has no ticket. It also carries a `*Frozen at ` line directly below its title. When a plan is not frozen yet, its file name is typically `.md`. Plan Deviations filenames use `YYYY-MM-DD-HHMM--plan-deviations.md` or `YYYY-MM-DD-HHMM--plan-deviations.md`. -Plans are frozen when their Planning Phase ends. From then on, the only permitted edit is checking an acceptance criterion (`- [ ]` to `- [x]`) after the implementation and relevant feedback loops verify it. Never reword, add, remove, or reorder criteria in a frozen plan. Plan Deviations documents are frozen once committed. +Plans are frozen when their Planning Phase ends. From then on, the only permitted edit is checking an acceptance criterion (`- [ ]` to `- [x]`) after the implementation and relevant feedback loops verify it. Never reword, add, remove, or reorder criteria in a frozen plan. Plan Deviations documents are frozen once they are merged into the target branch. Until then, it is rewritten under a fresh timestamp whenever it needs to change, e.g., when a review of the PR/MR leads to another Follow-Up Plan, so that it always sorts after all plans of its work item. A Follow-Up Plan supersedes decisions of a Frozen Plan. The decision to write one is made in the Guiding Phase, when the review of the implementation calls for larger changes. -A Plan Deviations document records all changes from the Initial Plan to the final implementation; it is only written when Follow-Up Plans exist or the implementation materially deviates from the plans. Reading the Initial Plan and, if present, the Plan Deviations document is enough to understand all work related to a ticket. +A work item has at most one Plan Deviations document. It records all changes from the Initial Plan to the final implementation. It is only written when Follow-Up Plans exist or the implementation materially deviates from the plans. Reading the Initial Plan and, if present, the Plan Deviations document is enough to understand all work related to a ticket. diff --git a/skills/guided-coding-write-deviations/SKILL.md b/skills/guided-coding-write-deviations/SKILL.md index f45bc83..067c838 100644 --- a/skills/guided-coding-write-deviations/SKILL.md +++ b/skills/guided-coding-write-deviations/SKILL.md @@ -1,22 +1,36 @@ --- name: guided-coding-write-deviations -description: Decide whether a completed Guided Coding cycle needs a Plan Deviations document and write it when required. Run only when explicitly requested by the user. +description: Decide whether a completed Guided Coding cycle needs a Plan Deviations document and write or update it when required. Run only when explicitly requested by the user. license: MIT --- # Write Plan Deviations -Your goal is to decide whether the completed implementation needs a Plan Deviations document and, if so, to write it into the `ai-plans/` folder at the repository root. After writing, report the document path and stop. +Your goal is to decide whether the completed implementation needs a Plan Deviations document and, if so, to write it into the `ai-plans/` folder at the repository root or update the existing one. After writing, report the document path and stop. -A Plan Deviations document summarizes how the completed implementation differs from the original plan. Reading the initial plan together with this document should be enough to understand the complete work. +A Plan Deviations document summarizes how the completed implementation differs from the original plan. Reading the initial plan together with this document should be enough to understand the complete work. A work item has at most one Plan Deviations document. It stays editable until it is merged into the target branch, because reviews of the PR/MR can still lead to Follow-Up Plans; from then on, it is frozen. ## 1. Inspect the Plans and the Implementation Read all plans for the current ticket in `ai-plans/`, oldest first. Identify them by the `` or `` in their file names, or by the plans mentioned in the conversation. Ask the user if the set of plans is unclear. -Determine the implementation range. Use the PR/MR if there is one. Otherwise, use the merge base between the target branch and the implementation branch. Inspect the commits in that range, all committed, staged, and unstaged changes, and any relevant earlier history. Verify every document and source-file reference you rely on. +Determine the target branch and the implementation range. Use the PR/MR if there is one. Otherwise, use the merge base between the target branch and the implementation branch. Ask the user if the target branch is unclear. Inspect the commits in that range, all committed, staged, and unstaged changes, and any relevant earlier history. Verify every document and source-file reference you rely on. -## 2. Decide Whether a Document Is Needed +## 2. Check for an Existing Plan Deviations Document + +Look for an existing Plan Deviations document of the current ticket in `ai-plans/`. Its file name ends with `--plan-deviations.md` or `--plan-deviations.md`, using the same `` or `` as the Initial Plan. If you find more than one, report them and stop; the user decides which one to keep. + +If there is an existing document, check whether it is already merged into the target branch: + +1. Fetch the target branch from its remote into its remote-tracking branch with an explicit refspec, e.g., `git fetch origin +refs/heads/main:refs/remotes/origin/main`, and use that remote-tracking branch, e.g., `origin/main`. The explicit refspec updates it regardless of the remote's configured fetch mappings. Only if the repository has no remote at all, use the local target branch. If fetching fails, report the error and stop without changing anything: a stale local branch cannot prove that the document is unmerged. +2. Verify that the target branch resolves, e.g., `git rev-parse --verify origin/main`. If it does not, report this and stop without changing anything. +3. Check whether the document's path exists on the target branch, e.g., `git cat-file -e origin/main:ai-plans/`. Check the path, not whether commits are ancestors of the target branch: squash and rebase merges rewrite commits but keep the file. + +If the document exists on the target branch, it is frozen. Report that it was merged into the target branch, and that the user can delete it and run this skill again to recreate it from scratch. Do not delete or change it yourself, and stop. + +Otherwise, you update the existing document in the following steps. + +## 3. Decide Whether a Document Is Needed Write a Plan Deviations document in either of these cases: @@ -25,23 +39,27 @@ Write a Plan Deviations document in either of these cases: Routine choices the plans left open are not deviations. An Acceptance Criterion that is documented but not met remains incomplete; it does not count as a deviation unless an accepted Follow-Up Plan explicitly supersedes it. -If there is only one plan and no material deviations, report that conclusion to the user, create nothing, and stop. +If there is only one plan and no material deviations, report that conclusion to the user, create nothing, and stop. If an existing, unmerged document is no longer needed, also report this, leave the document unchanged, and let the user decide whether to delete it. -## 3. Determine the File Name +## 4. Determine the File Name The file name is: - `--plan-deviations.md` if a `` is present - `--plan-deviations.md` otherwise -Take `` or `` from the file name of the Initial Plan. The `` is UTC in the format `YYYY-MM-DD-HHMM`. Use these commands to get it: +Take `` or `` from the file name of the Initial Plan. The `` is the current time in UTC in the format `YYYY-MM-DD-HHMM`, also when you update an existing document. Use these commands to get it: - `date -u +%F-%H%M` on Unix-based shells - `(Get-Date).ToUniversalTime().ToString("yyyy-MM-dd-HHmm")` on PowerShell -If a plan or Plan Deviations document with this file name already exists, report the collision and stop. Never overwrite or reuse an existing file. Committed Plan Deviations documents are frozen. +The Plan Deviations document must sort after all plans of the ticket. Therefore, the `` must be strictly later than the timestamps in the file names of all plans of the ticket and of the existing Plan Deviations document. If it is not, wait until the next minute and get the timestamp again. + +If a plan or another Plan Deviations document with this file name already exists, report the collision and stop. Never overwrite a plan or a frozen Plan Deviations document. + +## 5. Write the Document -## 4. Write the Document +When you update an existing document, first move it to the new file name. Use `git mv ` if the old file is tracked by Git, so that Git can detect the rename; otherwise, rename the file. Then rewrite the whole document from the plans and the implementation you inspected in step 1. Do not append to the previous content, and do not mention earlier versions of the document. Structure the document as follows: @@ -53,6 +71,6 @@ Structure the document as follows: Name the affected types, members, and files. Leave out work that matches the accepted plans. If the implementation matches all Follow-Up Plans, say so in the Summary and omit `## Deviations From the Accepted Plans`. -## 5. Stop +## 6. Stop -Report the document path. Do not commit, publish, or create or update a PR/MR. The user reviews and finalizes the document. +Report the document path. When you updated an existing document, also report its previous path and whether the rename is staged. Do not commit, publish, or create or update a PR/MR. The user reviews and finalizes the document.