From 82855092f61f56f9527c9f06d2f0027bd916ff4b Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 09:52:49 +0800 Subject: [PATCH 01/13] feat: a code repository without a remote can be closed against its local branch (#547) The IDD configuration takes spec_archive, mapping a code repository's path to {"ref": "local", "branch": ""}. idd-close Step 1.57 then checks the archive on that branch instead of fetching, Step 1.5 skips the branch lookup (check-existing-work.sh --skip-branches), and the link check of spec-wrapper.md step 5 starts at the issue's baseline. Accepted only while the repository has no remote. New spec-change.py subcommands archive-ref and link-base. Refs #547 Co-Authored-By: Claude Opus 5.5 --- .../idd-547-spec-archive-local/.openspec.yaml | 3 + .../idd-547-spec-archive-local/proposal.md | 60 ++++++++ .../specs/idd-existing-work-lookup/spec.md | 21 +++ .../specs/spec-on-every-issue/spec.md | 85 ++++++++++ .../idd-547-spec-archive-local/tasks.md | 23 +++ plugins/issue-driven-dev/CHANGELOG.md | 12 ++ .../references/config-protocol.md | 26 ++++ .../references/spec-wrapper.md | 19 ++- .../scripts/check-existing-work.sh | 42 +++-- .../issue-driven-dev/scripts/spec-change.py | 123 ++++++++++++++- .../scripts/tests/check-existing-work/test.sh | 39 +++++ .../scripts/tests/spec-archive-local/test.sh | 145 ++++++++++++++++++ .../scripts/tests/spec-close-gate/test.sh | 30 ++++ .../skills/idd-close/SKILL.md | 48 ++++-- 14 files changed, 644 insertions(+), 32 deletions(-) create mode 100644 openspec/changes/idd-547-spec-archive-local/.openspec.yaml create mode 100644 openspec/changes/idd-547-spec-archive-local/proposal.md create mode 100644 openspec/changes/idd-547-spec-archive-local/specs/idd-existing-work-lookup/spec.md create mode 100644 openspec/changes/idd-547-spec-archive-local/specs/spec-on-every-issue/spec.md create mode 100644 openspec/changes/idd-547-spec-archive-local/tasks.md create mode 100755 plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh diff --git a/openspec/changes/idd-547-spec-archive-local/.openspec.yaml b/openspec/changes/idd-547-spec-archive-local/.openspec.yaml new file mode 100644 index 00000000..f483aa4c --- /dev/null +++ b/openspec/changes/idd-547-spec-archive-local/.openspec.yaml @@ -0,0 +1,3 @@ +schema: spec-driven +created: 2026-11-14 +created_by: che cheng diff --git a/openspec/changes/idd-547-spec-archive-local/proposal.md b/openspec/changes/idd-547-spec-archive-local/proposal.md new file mode 100644 index 00000000..b05e62ca --- /dev/null +++ b/openspec/changes/idd-547-spec-archive-local/proposal.md @@ -0,0 +1,60 @@ +**GitHub-side tracker**: #547(設計決定見 issue comment 6869531838;症狀見 #546) + +## Problem + +`/idd-close` Step 1.57 對宣告了 change 的 issue 一律 `git fetch origin -- `,對 fetch 回來的 commit 跑 `spec-change.py archived`;fetch 失敗就是 `error`、硬性停下。issue 開在 repo A(有 GitHub remote)、程式與規格在 A 底下另一個**刻意沒有 remote** 的本機 git repo B 時,fetch 永遠失敗,這種佈局裡宣告了 change 的 issue 都無法結案,即使 change 已經封存在 B 的預設 branch 上。同一件事也讓 `spec-wrapper.md` 第 5 步的連結檢查找不到起點,`check-existing-work.sh` 在 Step 1.5 多記一筆 `git fetch failed`。 + +## Root Cause + +這三處都假設程式所在的 repo 有一個 remote,預設 branch「以遠端為準」。對沒有 remote 的 repo,這個假設沒有替代:沒有任何方式說「這個 repo 的預設 branch 就是本機的這一條」。 + +## Proposed Solution + +維護者已決定(2026-11-14,issue comment 6869531838):放寬只能靠設定明確打開,不做自動判斷。 + +- IDD 設定加欄位 `spec_archive`:一個以「程式 repo 相對於設定檔所在目錄的路徑」為 key 的物件,值是 `{"ref": "local", "branch": "<本機 branch>"}`。設定寫在 issue 所在 repo 的設定檔;從程式 repo 的 top level 往上找第一份 IDD 設定。 +- 只在程式 repo **沒有任何 remote** 時接受;有 remote 卻設了,回 `error`。沒有條目時行為完全不變。 +- `spec-change.py` 加兩個子命令:`archive-ref`(這個 repo 要用哪個 ref 判定封存:`remote`、`local` 或 `error`)與 `link-base`(本機模式的連結檢查起點:baseline tag → HEAD 歷史中第一個引用 `#N` 的 commit 的父 commit → `error`)。三處共用這兩個子命令,不各寫一份 bash。 +- Step 1.57:本機模式用本機 branch 的 commit 跑 `archived`,輸出寫明用的是本機 ref。 +- Step 1.5:本機模式呼叫 `check-existing-work.sh --skip-branches`,略過程式 repo 的 fetch 與 branch 列舉、只查 issue repo 的 PR,輸出寫明略過了。 +- `spec-wrapper.md` 第 5 步:本機模式用 `link-base` 的起點。 +- `config-protocol.md` 記這個欄位。 + +## Non-Goals + +- 自動偵測「沒有 remote」並放寬:維護者選了明確設定。 +- `idd-all` direct-commit 的推送、`close-stage.py` 的檢查:推送本來就需要 remote。 +- `idd-all` Step 0.5.1、`idd-implement` Step 0.37 呼叫 `check-existing-work.sh` 時的 `unknown`:不擋,只是多一行雜訊。 +- 程式 repo 不在 issue repo 底下的佈局:找不到設定,照舊 `error`。 +- ASSUMPTION: 不升版號,CHANGELOG 加在既有的 Unreleased 區塊(版號留給 release)。 + +## Success Criteria + +- 新增的測試在改程式之前失敗,改之後通過。 +- spec-close-gate、check-existing-work 原有的檢查照舊通過;run-all-tests 的全部 suite 通過。 +- 連結檢查對新增與修改的 requirement 回 ok。 + +## Capabilities + +### New Capabilities + +(none) + +### Modified Capabilities + +- `spec-on-every-issue`: 封存檢查的 requirement 加本機模式;新增 requirement 寫明 `spec_archive` 怎麼解析、本機模式的連結檢查起點。 +- `idd-existing-work-lookup`: 新增 requirement:helper 可以略過 branch 查詢;idd-close 在本機模式這樣呼叫它。 + +## Impact + +- Affected specs: spec-on-every-issue(MODIFIED「Close requires the issue's change to be archived」;ADDED「A repository without a remote can opt into its local default branch」)、idd-existing-work-lookup(ADDED「The helper can skip the branch lookup」) +- Affected code: + - Modified: plugins/issue-driven-dev/scripts/spec-change.py + - Modified: plugins/issue-driven-dev/scripts/check-existing-work.sh + - Modified: plugins/issue-driven-dev/skills/idd-close/SKILL.md + - Modified: plugins/issue-driven-dev/references/spec-wrapper.md + - Modified: plugins/issue-driven-dev/references/config-protocol.md + - Modified: plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh + - Modified: plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh + - New: plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh + - Modified: plugins/issue-driven-dev/CHANGELOG.md diff --git a/openspec/changes/idd-547-spec-archive-local/specs/idd-existing-work-lookup/spec.md b/openspec/changes/idd-547-spec-archive-local/specs/idd-existing-work-lookup/spec.md new file mode 100644 index 00000000..9d06ee03 --- /dev/null +++ b/openspec/changes/idd-547-spec-archive-local/specs/idd-existing-work-lookup/spec.md @@ -0,0 +1,21 @@ +## ADDED Requirements + +### Requirement: The helper can skip the branch lookup + +`check-existing-work.sh` SHALL accept `--skip-branches` before the repository argument. With it, the helper SHALL NOT run `git fetch` or list remote-tracking branches in `--cwd`, SHALL treat the clone as having no branches, SHALL NOT add a `git fetch failed` error, and SHALL add a top-level `notes` list that says the branch lookup was skipped. The PR lookups on the repository argument SHALL run as without the flag, and their failures and limits SHALL be reported as before. Without the flag the helper's output SHALL be as before, without a `notes` field. + +`idd-close` Step 1.5 SHALL pass `--skip-branches` only when `spec-change.py archive-ref` prints `local` for its working directory (requirement "A repository without a remote can opt into its local default branch" of `spec-on-every-issue`), and SHALL then print that the branch lookup was skipped and that the open PRs were checked on the issue's repository. The open-PR gate itself is unchanged. + +#### Scenario: idd-close in a repository opted into its local branch + +- **GIVEN** the working directory of `/idd-close` is a repository without a remote, opted into its local branch +- **WHEN** Step 1.5 runs +- **THEN** it calls the helper with `--skip-branches`, prints that the branch lookup was skipped, and still refuses to close while an open PR on the issue's repository references the issue + +##### Example: the branch lookup can be skipped + +| Clone | Flag | `git fetch` run | `errors` | `notes` | An open PR declaring the issue | +| --- | --- | --- | --- | --- | --- | +| has an `origin` that cannot be fetched | none | yes | has `git fetch failed` | absent | reported as E1 | +| has no remote | `--skip-branches` | no | no `git fetch failed` | says the branch lookup was skipped | reported as E1 | +| has no remote, the open PR list fails | `--skip-branches` | no | has the PR list failure | says the branch lookup was skipped | verdict `unknown` | diff --git a/openspec/changes/idd-547-spec-archive-local/specs/spec-on-every-issue/spec.md b/openspec/changes/idd-547-spec-archive-local/specs/spec-on-every-issue/spec.md new file mode 100644 index 00000000..e1e0c366 --- /dev/null +++ b/openspec/changes/idd-547-spec-archive-local/specs/spec-on-every-issue/spec.md @@ -0,0 +1,85 @@ +## MODIFIED Requirements + +### Requirement: Close requires the issue's change to be archived + +`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote`, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails. When the answer is `local`, it SHALL check the commit `archive-ref` returned, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch and the commit. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. + +#### Scenario: An unarchived change holds the close + +- **GIVEN** an Implementation Complete comment with the marker and `**Spec**: change idd-42-fix-timeout` +- **AND** `openspec/changes/idd-42-fix-timeout/` still exists on the default branch +- **WHEN** `idd-close` runs its gates +- **THEN** it does not close the issue and says the change is not archived + +#### Scenario: A repository without a remote, opted in + +- **GIVEN** the code repository has no remote and the IDD configuration above it maps the repository's path to `{"ref": "local", "branch": "master"}` +- **AND** the change is archived on `master` +- **WHEN** `idd-close` runs its gates +- **THEN** the gate passes without fetching and prints the local branch and commit it checked + +##### Example: the close gate reads the default branch + +| Newest Implementation Complete comment | On the default branch | Close gate | +| --- | --- | --- | +| marker, `**Spec**: change idd-42-fix-timeout` | the change is archived | passes | +| marker, `**Spec**: change idd-42-fix-timeout` | archived on the issue's branch only, not yet merged | stops, naming the change | +| marker, no `**Spec**:` line | not read | stops, naming the missing line | +| no marker, no `**Spec**:` line | not read | passes | +| the issue has no Implementation Complete comment | not read | passes | +| the comments could not be fetched | not read | stops, saying the comments could not be read | +| marker, `**Spec**: change idd-42-fix-timeout` | the default branch cannot be fetched | stops, saying the default branch could not be read | +| marker, `**Spec**: no behaviour change` | the default branch cannot be fetched | passes; the branch is not read | +| marker, `**Spec**: change idd-42-fix-timeout` | the remote's default branch dropped the archive, the local tracking ref did not move | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts the repository into its local `master`, where the change is archived | passes; prints `local ref master@` | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts in, the change is not archived on `master` | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | the repository has a remote and the configuration opts it into `local` | stops and prints the reason | + +## ADDED Requirements + +### Requirement: A repository without a remote can opt into its local default branch + +`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. It SHALL find the IDD configuration by walking up from the repository's top level: at each directory, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory or at `/`, and SHALL use the first file found. The key it looks up is the path of the repository's top level relative to the directory that holds that `.claude/` directory, with both paths resolved through symbolic links; a key in the file SHALL match when it names the same path after `.` and `..` segments and a trailing `/` are normalised, and `.` names the directory of the configuration itself. It SHALL print one JSON line and exit as follows: + +- `remote` (exit 0) when no configuration file is found, when the file has no `spec_archive` field, or when `spec_archive` has no entry for the key. Callers then read the default branch as the remote has it, as before. +- `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at), `config` and `key`, when the entry is `{"ref": "local", "branch": ""}`, the repository has no remote at all (`git remote` lists nothing), and the branch exists. +- `error` (exit 2), with a `reason`, when the file found cannot be read as a JSON object; when `spec_archive` is not an object; when the entry is not an object, its `ref` is not `local`, or its `branch` is missing, empty, not a string or starts with `-`; when the repository has any remote; when the branch does not exist; or when `` is not inside a git repository. + +The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. + +`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the tag `idd--baseline` when that tag exists and is an ancestor of `HEAD` (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message contains `#` not followed by another digit (`from: first-commit`). It SHALL print `error` (exit 2) when neither exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. + +`references/spec-wrapper.md` step 5 SHALL ask `link-base` first and use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote`, and SHALL stop when it prints `error` or nothing a JSON reader can take. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. + +#### Scenario: An entry for a repository that later gained a remote + +- **GIVEN** a configuration entry `{"ref": "local", "branch": "master"}` for a repository +- **AND** a remote was added to that repository afterwards +- **WHEN** `archive-ref` runs for it +- **THEN** it prints `error` and names the remote, instead of reading the local branch + +##### Example: how a spec_archive entry resolves + +| Configuration found | Entry for the repository's path | Repository | `archive-ref` | +| --- | --- | --- | --- | +| none | — | no remote | `remote` | +| a file without `spec_archive` | — | no remote | `remote` | +| `spec_archive` names another path only | — | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local`, `master` and its commit | +| `spec_archive` names this path as `./sub/` | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | has a remote `origin` | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "trunk"}` | no remote, no branch `trunk` | `error` | +| `spec_archive` names this path | `{"ref": "remote", "branch": "master"}` | no remote | `error` | +| `spec_archive` names this path | `{"ref": "local"}` | no remote | `error` | +| `spec_archive` is a list | — | no remote | `error` | +| the file is not JSON | — | no remote | `error` | + +##### Example: where the local link check starts + +| Repository (opted into local `master`) | `link-base --issue 14` | +| --- | --- | +| tag `idd-14-baseline` on an ancestor of `HEAD` | `ok`, the tag's commit, `from: baseline-tag` | +| no tag; commits `base`, `a (#14)`, `b (Refs #14)` | `ok`, the commit `base`, `from: first-commit` | +| no tag; the only commit naming a 14 says `#142` | `error` | +| no tag; the first commit with `#14` is the root commit | `error` | +| the repository is not opted in | `remote` | diff --git a/openspec/changes/idd-547-spec-archive-local/tasks.md b/openspec/changes/idd-547-spec-archive-local/tasks.md new file mode 100644 index 00000000..9858a119 --- /dev/null +++ b/openspec/changes/idd-547-spec-archive-local/tasks.md @@ -0,0 +1,23 @@ +## 1. 測試先行 + +- [x] 1.1 `spec_archive` 的解析:依 requirement「A repository without a remote can opt into its local default branch」的 Example「how a spec_archive entry resolves」,新 suite spec-archive-local 對 `spec-change.py archive-ref` 跑 Example 十一列,測試檔帶標記 spec-example: spec-on-every-issue / how a spec_archive entry resolves。驗證:改 spec-change.py 之前失敗(子命令不存在)。 +- [x] 1.2 本機模式的連結檢查起點:依同一條 requirement 的 Example「where the local link check starts」,spec-archive-local 對 `spec-change.py link-base` 跑 Example 五列,帶標記 spec-example: spec-on-every-issue / where the local link check starts。驗證:改之前失敗。 +- [x] 1.3 封存檢查的本機模式:依 requirement「Close requires the issue's change to be archived」的 Example「the close gate reads the default branch」新增的三列,spec-close-gate 照 SKILL.md 原文執行 Step 1.57 的區塊(有設定、沒有 remote 的 repo),帶既有標記。驗證:改 SKILL.md 之前,新的三列失敗;原有各列照舊通過。 +- [x] 1.4 略過 branch 查詢:依 requirement「The helper can skip the branch lookup」的 Example「the branch lookup can be skipped」,check-existing-work suite 跑三列,並檢查 idd-close Step 1.5 在本機模式帶 `--skip-branches`,帶標記 spec-example: idd-existing-work-lookup / the branch lookup can be skipped。驗證:改之前失敗。 + +## 2. 程式 + +- [x] 2.1 `spec-change.py` 加 `archive-ref` 與 `link-base` 子命令(docstring 一併更新)。驗證:1.1、1.2 通過;spec-change suite 照舊通過。 +- [x] 2.2 `check-existing-work.sh` 加 `--skip-branches`。驗證:1.4 的 helper 部分通過;check-existing-work 原有各項照舊通過。 + +## 3. skill 與文件 + +- [x] 3.1 idd-close Step 1.57:宣告了 change 時先問 `archive-ref`,`local` 用回傳的 commit 並印出本機 ref,`remote` 照舊 fetch,`error` 停下。驗證:1.3 通過;spec-close-gate 原有的文字檢查照舊通過。 +- [x] 3.2 idd-close Step 1.5:`archive-ref` 回 `local` 時帶 `--skip-branches` 並印出說明。驗證:1.4 的 skill 部分通過。 +- [x] 3.3 spec-wrapper.md 第 5 步:先問 `link-base`,`ok` 用它的起點、`remote` 照舊、`error` 停下。驗證:spec-wrapper-contract suite 照舊通過。 +- [x] 3.4 config-protocol.md 加 `spec_archive` 欄位一節(key 的算法、只在沒有 remote 時接受的理由、找不到設定時照舊)。驗證:git diff 只有新增。 + +## 4. 收尾 + +- [x] 4.1 CHANGELOG 的 Unreleased 加 Added 條目(#547)。驗證:已發布版本的條目沒有改動。 +- [ ] 4.2 跑 run-all-tests.sh 與連結檢查。驗證:結束碼都是 0,links 回 ok。 diff --git a/plugins/issue-driven-dev/CHANGELOG.md b/plugins/issue-driven-dev/CHANGELOG.md index e8f201bd..af68c84a 100644 --- a/plugins/issue-driven-dev/CHANGELOG.md +++ b/plugins/issue-driven-dev/CHANGELOG.md @@ -9,6 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Version number left to the release. +### Added + +- **A code repository without a remote can be closed against its local branch (#547, #546).** The IDD + configuration takes a `spec_archive` field that maps a code repository's path (relative to the configuration's + directory) to `{"ref": "local", "branch": ""}`. For that repository `idd-close` Step 1.57 checks the archive + on the local branch instead of fetching the default branch from a remote that does not exist, and says so + (`local ref @`); Step 1.5 skips the branch lookup (`check-existing-work.sh --skip-branches`) and + still checks open PRs on the issue repository; the link check of `references/spec-wrapper.md` step 5 starts at + the issue's baseline tag, or at the parent of the oldest commit naming `#N`. An entry is accepted only while the + repository has no remote at all; with a remote it is an error, never a silent fallback. Without an entry nothing + changes. New `spec-change.py` subcommands `archive-ref` and `link-base`; documented in `config-protocol.md`. + ### Fixed - **The edit-run suite has a time limit of its own (#508, #519).** Most of its run time is CPU time (about 65 s diff --git a/plugins/issue-driven-dev/references/config-protocol.md b/plugins/issue-driven-dev/references/config-protocol.md index 837a2921..a37dd093 100644 --- a/plugins/issue-driven-dev/references/config-protocol.md +++ b/plugins/issue-driven-dev/references/config-protocol.md @@ -487,6 +487,32 @@ Exit codes of `idd-ci-gate.sh run --commit [--cwd ]`: `0` pass, `1` In `local` mode a red remote check is reported and does not block merging. A release still requires green remote checks whatever the mode (`idd-close` Step 6.5), because only remote CI sees the older environments that users run. +### `spec_archive` field (#547) + +Which branch the spec checks read for a code repository that **deliberately has no remote** — typically a local-only sub-project inside the issue repository's working directory, holding data that must not go to GitHub. Without an entry, `idd-close` Step 1.57 fetches the default branch from the remote, and a repository without a remote can never pass it. + +```json +{ "spec_archive": { "projects/sub-repo": { "ref": "local", "branch": "master" } } } +``` + +| Part | Meaning | +|------|---------| +| key | The code repository's top level, relative to the directory that holds this `.claude/` (both resolved through symbolic links). `./sub/`, `sub/` and `sub` name the same path; `.` names the directory of this configuration itself | +| `ref` | Must be `local`. Any other value is an error | +| `branch` | The local branch that plays the default branch. Required: without a remote there is no `origin/HEAD` to read, and `HEAD` is only the branch checked out now | + +Read by `scripts/spec-change.py archive-ref` (and `link-base`), which walks up from the **code repository's** top level to the first IDD configuration — the same walk as the other fields, new file before legacy file at each level, stopping after `$HOME`. Write the entry in the issue repository's configuration; do not add a configuration to the code repository just for this, because a file without `github_repo` there would be the first one the other skills find. + +**Accepted only while the repository has no remote at all.** An entry for a repository that has any remote is an error, not a silent fallback to the remote: an entry written because there was no remote must not outlive that reason. Other errors: the file is not a JSON object, `spec_archive` is not an object, the entry is not `{"ref": "local", "branch": ""}`, or the branch does not exist. + +What it changes, and nothing else: + +- `idd-close` Step 1.57 checks the archive on `refs/heads/` instead of fetching, and prints `local ref @`. +- `idd-close` Step 1.5 calls `check-existing-work.sh --skip-branches`: no fetch in the code repository, open PRs still checked on the issue repository. +- `references/spec-wrapper.md` step 5 starts the link check at the issue's `idd--baseline` tag, or else at the parent of the oldest commit naming `#`; neither → stop. + +A code repository that is not under the issue repository's directory finds no entry and keeps the remote behaviour (and its error). + ### `collaborators[]` field An OPTIONAL identity registry so IDD can resolve a person's alias / email / display-name → their GitHub `@login` **without guessing** — the hard rule set by [tagging-collaborators.md](../rules/tagging-collaborators.md). It is a *resolution accelerator*, **not** an authority: a table hit is still existence-verified via `gh api users/` before any mention is posted, because the table can go stale. diff --git a/plugins/issue-driven-dev/references/spec-wrapper.md b/plugins/issue-driven-dev/references/spec-wrapper.md index 1f3c515b..55a860bf 100644 --- a/plugins/issue-driven-dev/references/spec-wrapper.md +++ b/plugins/issue-driven-dev/references/spec-wrapper.md @@ -127,10 +127,21 @@ fi 5. 連結檢查: ```bash -DEFAULT_BRANCH=$(gh repo view "$GITHUB_REPO" --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null) || DEFAULT_BRANCH="" +# #547: a repository without a remote, opted into its local branch by spec_archive, starts at the issue's +# baseline (link-base prints ok); with no entry link-base prints remote and the default branch is fetched as before. +LB=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" link-base --cwd "$CWD" --issue "$NUMBER" 2>/dev/null) +LB_STATUS=$(printf '%s' "$LB" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("status", ""))' 2>/dev/null) SPEC_BASE="" -if [ -n "$DEFAULT_BRANCH" ] && git -C "$CWD" fetch -q origin -- "$DEFAULT_BRANCH" 2>/dev/null; then - SPEC_BASE=$(git -C "$CWD" merge-base HEAD FETCH_HEAD 2>/dev/null) +if [ "$LB_STATUS" = ok ]; then + SPEC_BASE=$(printf '%s' "$LB" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read()).get("base", ""))') + printf '%s' "$LB" | python3 -c 'import json,sys; d=json.loads(sys.stdin.read()); print("→ link check from %s (%s; spec_archive local mode)" % (d["base"][:7], d["from"]))' +elif [ "$LB_STATUS" = remote ]; then + DEFAULT_BRANCH=$(gh repo view "$GITHUB_REPO" --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null) || DEFAULT_BRANCH="" + if [ -n "$DEFAULT_BRANCH" ] && git -C "$CWD" fetch -q origin -- "$DEFAULT_BRANCH" 2>/dev/null; then + SPEC_BASE=$(git -C "$CWD" merge-base HEAD FETCH_HEAD 2>/dev/null) + fi +else + echo "✗ spec close-out: spec_archive: $(printf '%s' "$LB" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("reason", "link-base printed nothing readable"))' 2>/dev/null)" >&2 fi if [ -n "$SPEC_BASE" ]; then python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" links --base "$SPEC_BASE" --cwd "$CWD" @@ -139,7 +150,7 @@ else fi ``` -`git merge-base HEAD FETCH_HEAD`(剛從遠端 fetch 的預設 branch)在 PR path 是分岔點;在 direct-commit path 是 run 還沒推的 commit 之前那一個。沒有印出 JSON(`SPEC_BASE` 取不到)就停下回報。`missing` 就補測試或標記再跑一次。要改的是 requirement 本身(例如寫了一個寫不出檢查的 Example)時,不改 `archive/` 底下的檔案,也不繞過 Spectra 直接改主規格:照第 7 步另建一個 change 修改那條 requirement,封存後再跑。`error` 停下回報。 +`git merge-base HEAD FETCH_HEAD`(剛從遠端 fetch 的預設 branch)在 PR path 是分岔點;在 direct-commit path 是 run 還沒推的 commit 之前那一個。程式 repo 沒有 remote、用 `spec_archive` 指到本機 branch 時(#547,見 `config-protocol.md`),沒有「還沒推的 commit」這條界線,起點改由 `link-base` 給:這張 issue 的 `idd--baseline` tag(是 HEAD 的祖先時),否則 HEAD 歷史裡第一個訊息含 `#`(後面不接數字)的 commit 的父 commit;兩者都沒有就停下,不退回 `merge-base`(direct-commit 時那是 HEAD,範圍是空的)。沒有印出 JSON(`SPEC_BASE` 取不到)就停下回報。`missing` 就補測試或標記再跑一次。要改的是 requirement 本身(例如寫了一個寫不出檢查的 Example)時,不改 `archive/` 底下的檔案,也不繞過 Spectra 直接改主規格:照第 7 步另建一個 change 修改那條 requirement,封存後再跑。`error` 停下回報。 6. 確認宣告與 HEAD 一致:把第 6 步要貼的 `**Spec**:` 行寫進一個暫存檔,跑 `python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archived --file <暫存檔> --cwd "$CWD" --ref HEAD`,要 `pass`。 diff --git a/plugins/issue-driven-dev/scripts/check-existing-work.sh b/plugins/issue-driven-dev/scripts/check-existing-work.sh index ad449091..905a8eee 100755 --- a/plugins/issue-driven-dev/scripts/check-existing-work.sh +++ b/plugins/issue-driven-dev/scripts/check-existing-work.sh @@ -2,7 +2,9 @@ # check-existing-work.sh — does a PR or a branch already address issue N? (#366) # # Usage: -# check-existing-work.sh [--cwd DIR] [...] +# check-existing-work.sh [--cwd DIR] [--skip-branches] [...] +# --skip-branches (#547): no git fetch and no remote-tracking branches in DIR (a clone without a remote, opted +# into its local branch); the PR lookups run as usual and a top-level "notes" list says the lookup was skipped. # # Stdout: JSON # {"repo":..., "truncated":bool, "errors":[...], @@ -36,13 +38,17 @@ COMMIT_REFS = re.compile(r'^\s*refs\b', re.I) def usage(msg): print(f"check-existing-work.sh: {msg}", file=sys.stderr) - print("usage: check-existing-work.sh [--cwd DIR] ...", file=sys.stderr) + print("usage: check-existing-work.sh [--cwd DIR] [--skip-branches] ...", file=sys.stderr) sys.exit(2) args = sys.argv[1:] cwd = "." -if args[:1] == ["--cwd"]: +skip_branches = False +while args[:1] in (["--cwd"], ["--skip-branches"]): + if args[0] == "--skip-branches": + skip_branches, args = True, args[1:] + continue if len(args) < 2: usage("--cwd needs a directory") cwd, args = args[1], args[2:] @@ -108,17 +114,22 @@ if len(merged_prs) >= LIMIT: errors.append(f"merged PR list reached its limit ({LIMIT}); older merged PRs were not checked") branches, default = {}, None -f = run(["git", "-C", cwd, "fetch", "--quiet", "--prune", "origin"]) -if f.returncode != 0: - errors.append(f"git fetch failed: {(f.stderr or '').strip()[:160]}") -r = run(["git", "-C", cwd, "for-each-ref", "--format=%(refname:short)\t%(objectname)", "refs/remotes/origin"]) -if r.returncode == 0: - for line in r.stdout.splitlines(): - name, _, oid = line.partition("\t") - if name.startswith("origin/") and name != "origin/HEAD": - branches[name[len("origin/"):]] = oid +notes = [] +if skip_branches: + # #547: a clone without a remote (spec_archive.ref=local) has no remote-tracking branches to read + notes.append("branch lookup skipped (--skip-branches): no git fetch, no remote-tracking branches read in --cwd") else: - errors.append("git for-each-ref failed") + f = run(["git", "-C", cwd, "fetch", "--quiet", "--prune", "origin"]) + if f.returncode != 0: + errors.append(f"git fetch failed: {(f.stderr or '').strip()[:160]}") + r = run(["git", "-C", cwd, "for-each-ref", "--format=%(refname:short)\t%(objectname)", "refs/remotes/origin"]) + if r.returncode == 0: + for line in r.stdout.splitlines(): + name, _, oid = line.partition("\t") + if name.startswith("origin/") and name != "origin/HEAD": + branches[name[len("origin/"):]] = oid + else: + errors.append("git for-each-ref failed") # The default branch comes from GitHub. The clone's refs/remotes/origin/HEAD is a snapshot from clone time and can # point at an old feature branch (seen on a real clone), which makes every commit on the real default branch look # unmerged. It is only the fallback when GitHub cannot be asked. @@ -207,5 +218,8 @@ for n in issues: verdict, reason = "clear", "" out[str(n)] = {"verdict": verdict, "reason": reason, "evidence": ev} -print(json.dumps({"repo": repo, "truncated": truncated, "errors": errors, "issues": out}, ensure_ascii=False)) +result = {"repo": repo, "truncated": truncated, "errors": errors, "issues": out} +if notes: + result["notes"] = notes +print(json.dumps(result, ensure_ascii=False)) PY diff --git a/plugins/issue-driven-dev/scripts/spec-change.py b/plugins/issue-driven-dev/scripts/spec-change.py index 10b0751a..97a9a8e5 100755 --- a/plugins/issue-driven-dev/scripts/spec-change.py +++ b/plugins/issue-driven-dev/scripts/spec-change.py @@ -35,6 +35,19 @@ {"form": proposed|change|no-behaviour-change|third-party-clone|none|invalid, "change": "...", "reason": "..."} exit 0, 1 (invalid), 2 (unreadable; no JSON) + archive-ref --cwd (#547) + Which branch do the spec checks read for this repository? The first IDD configuration walking up + from the repository's top level may map its path (relative to the directory holding .claude/) in + `spec_archive` to {"ref": "local", "branch": ""}; that is accepted only without any remote. + {"status": remote|local|error, "branch": "...", "ref": "", "config": "...", "key": "...", + "reason": "..."} exit 0 (remote, local), 2 (error) + + link-base --cwd --issue (#547) + Where does the link check start in local mode? The tag idd--baseline when it is an ancestor of + HEAD, else the parent of the oldest commit of HEAD's history naming # (no digit after it). + {"status": remote|ok|error, "base": "", "from": baseline-tag|first-commit, "reason": "..."} + exit 0 (remote, ok), 2 (error) + Paths named openspec/ above are relative to the spec directory Spectra uses: the `spec_dir:` line of .spectra.yaml, or `openspec` when there is none (read at the revision checked; preflight reads the working tree). @@ -556,11 +569,117 @@ def cmd_plan(argv): return emit({"form": form, "change": change, "reason": reason}, 1 if form == "invalid" else 0) +# ── archive-ref / link-base (#547) ────────────────────────────────────────── + +CONFIG_NAMES = (os.path.join(".claude", ".idd", "local.json"), os.path.join(".claude", "issue-driven-dev.local.json")) + + +def find_config(top): + """(path, directory that holds its .claude/) of the first IDD configuration walking up from top, or (None, None). + Same order as the skills' walk-up: the new file before the legacy one at each level, stop after HOME or at /.""" + home = os.path.realpath(os.path.expanduser("~")) + d = os.path.realpath(top) + while True: + for name in CONFIG_NAMES: + p = os.path.join(d, name) + if os.path.isfile(p): + return p, d + parent = os.path.dirname(d) + if d == home or parent == d: + return None, None + d = parent + + +def norm_key(k): + k = os.path.normpath(k.strip().rstrip("/") or ".") + return k.replace(os.sep, "/") + + +def archive_ref(cwd): + """{"status": "remote"} | {"status": "local", branch, ref, config, key}; raises Fail for an error.""" + top = repo_top(cwd) + path, root = find_config(top) + if path is None: + return {"status": "remote", "reason": "no IDD configuration found above the repository"} + try: + with open(path, encoding="utf-8") as fh: + data = json.load(fh) + except (OSError, UnicodeDecodeError, ValueError) as exc: + raise Fail(f"cannot read the IDD configuration {path}: {str(exc)[:160]}") + if not isinstance(data, dict): + raise Fail(f"the IDD configuration {path} is not a JSON object") + if "spec_archive" not in data: + return {"status": "remote", "reason": f"{path} has no spec_archive field"} + table = data["spec_archive"] + if not isinstance(table, dict): + raise Fail(f"spec_archive in {path} must be an object keyed by repository path") + key = norm_key(os.path.relpath(os.path.realpath(top), root)) + entries = [v for k, v in table.items() if isinstance(k, str) and norm_key(k) == key] + if not entries: + return {"status": "remote", "reason": f"spec_archive in {path} has no entry for {key}"} + if len(entries) > 1: + raise Fail(f"spec_archive in {path} has more than one entry for {key}") + entry = entries[0] + if not isinstance(entry, dict) or entry.get("ref") != "local": + raise Fail(f"spec_archive[{key!r}] in {path}: only {{\"ref\": \"local\", \"branch\": \"\"}} is supported") + branch = entry.get("branch") + if not isinstance(branch, str) or not branch.strip() or branch.startswith("-"): + raise Fail(f"spec_archive[{key!r}] in {path} needs a branch name") + remotes = git_text(top, "remote").split() + if remotes: + raise Fail(f"spec_archive[{key!r}] in {path} asks for the local branch, but this repository has a remote " + f"({', '.join(remotes)}); the local branch is accepted only for a repository without any remote") + p = git(top, "rev-parse", "--verify", "--quiet", f"refs/heads/{branch}^{{commit}}", check=False) + if p.returncode != 0: + raise Fail(f"spec_archive[{key!r}] in {path} names the branch {branch!r}, which does not exist here") + return {"status": "local", "branch": branch, "ref": p.stdout.decode("utf-8").strip(), "config": path, "key": key} + + +def cmd_archive_ref(argv): + a = parse(argv, {"--cwd"}, ["--cwd"]) + try: + out = archive_ref(a["--cwd"]) + except Fail as exc: + return emit({"status": "error", "reason": str(exc)}, 2) + return emit(out, 0) + + +def cmd_link_base(argv): + a = parse(argv, {"--cwd", "--issue"}, ["--cwd", "--issue"]) + try: + if not re.fullmatch(r"[1-9][0-9]*", a["--issue"]): + raise Fail(f"the issue number must be a positive integer written in digits: {a['--issue'][:20]!r}") + n = a["--issue"] + out = archive_ref(a["--cwd"]) + if out["status"] == "remote": + return emit(out, 0) + top = repo_top(a["--cwd"]) + tag = git(top, "rev-parse", "--verify", "--quiet", f"refs/tags/idd-{n}-baseline^{{commit}}", check=False) + if tag.returncode == 0: + sha = tag.stdout.decode("utf-8").strip() + if git(top, "merge-base", "--is-ancestor", sha, "HEAD", check=False).returncode == 0: + return emit({"status": "ok", "base": sha, "from": "baseline-tag"}, 0) + names = re.compile(r"#%s(?![0-9])" % n) + log = git_text(top, "log", "--reverse", "--format=%H%x00%P%x00%B%x1e", "HEAD") + for rec in log.split("\x1e"): + parts = rec.strip("\n").split("\x00") + if len(parts) < 3 or not names.search(parts[2]): + continue + parents = parts[1].split() + if not parents: + raise Fail(f"the oldest commit naming #{n} ({parts[0][:12]}) is the root commit; pass the base by hand") + return emit({"status": "ok", "base": parents[0], "from": "first-commit"}, 0) + raise Fail(f"no tag idd-{n}-baseline on the history of HEAD and no commit there names #{n}; pass the base by hand") + except Fail as exc: + return emit({"status": "error", "reason": str(exc)}, 2) + + def main(argv): handlers = {"declared": cmd_declared, "archived": cmd_archived, "links": cmd_links, "preflight": cmd_preflight, - "ic": cmd_ic, "plan": cmd_plan} + "ic": cmd_ic, "plan": cmd_plan, "archive-ref": cmd_archive_ref, "link-base": cmd_link_base} if not argv or argv[0] not in handlers: - print("spec-change: subcommand required: declared | archived | links | preflight | ic | plan", file=sys.stderr) + print("spec-change: subcommand required: declared | archived | links | preflight | ic | plan | archive-ref | " + "link-base", file=sys.stderr) return 64 try: return handlers[argv[0]](argv[1:]) diff --git a/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh b/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh index 478a9d63..51178282 100644 --- a/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh @@ -229,4 +229,43 @@ CLOSE_OUT=$(CLAUDE_PLUGIN_ROOT="$HERE/../../.." WORKDIR="$W/work" GITHUB_REPO=te assert_eq "idd-close: an issue the lookup could not read does not pass the PR gate" 1 "$CLOSE_RC" assert_grep "idd-close: and says why" "refusing to close" "$CLOSE_OUT" +# ── the branch lookup can be skipped (#547) ───────────────────────────────── +# spec-example: idd-existing-work-lookup / the branch lookup can be skipped +NR="$W/noremote"; git "${GIT_ENV[@]}" init -q "$NR"; ( cd "$NR" && git "${GIT_ENV[@]}" commit -q --allow-empty -m init ) +BR="$W/badremote"; git "${GIT_ENV[@]}" init -q "$BR"; ( cd "$BR" && git "${GIT_ENV[@]}" commit -q --allow-empty -m init ) +git -C "$BR" remote add origin "$W/no-such-origin.git" +runin() { PATH="$W/bin:$PATH" bash "$SCRIPT" "$@" 2>"$W/stderr"; } +reset_fx; issue 61 OPEN $ISSUE_T +pr open 30 "codex/a" fff $NEWER "" $'Refs #61\n\nbody' +OUT=$(runin --cwd "$BR" test/repo 61) +assert_grep "an origin that cannot be fetched, no flag → git fetch failed" "git fetch failed" "$(field "$OUT" "d['errors']")" +assert_eq "… no notes field" "False" "$(field "$OUT" "'notes' in d")" +assert_eq "… the open PR is E1" "['E1']" "$(kinds "$OUT" 61)" +OUT=$(runin --cwd "$NR" --skip-branches test/repo 61) +refute_grep "no remote, --skip-branches → no git fetch failed" "git fetch failed" "$(field "$OUT" "d['errors']")" +assert_grep "… notes say the branch lookup was skipped" "branch lookup skipped" "$(field "$OUT" "d.get('notes')")" +assert_eq "… the open PR is still E1" "['E1']" "$(kinds "$OUT" 61)" +OUT=$(runin --skip-branches --cwd "$NR" test/repo 61) +assert_eq "… the flag before --cwd works too" "['E1']" "$(kinds "$OUT" 61)" +touch "$FX/fail_pr_open" +OUT=$(runin --cwd "$NR" --skip-branches test/repo 61) +assert_grep "no remote, --skip-branches, the open PR list fails → reported" "--state open" "$(field "$OUT" "d['errors']")" +assert_grep "… notes still say the branch lookup was skipped" "branch lookup skipped" "$(field "$OUT" "d.get('notes')")" +assert_eq "… verdict unknown" "unknown" "$(verdict "$OUT" 61)" +rm -f "$FX/fail_pr_open" + +# idd-close Step 1.5 passes --skip-branches only when archive-ref says local +OPTP="$W/opted"; mkdir -p "$OPTP/.claude/.idd"; git "${GIT_ENV[@]}" init -q "$OPTP/code" +( cd "$OPTP/code" && git "${GIT_ENV[@]}" checkout -q -b master && git "${GIT_ENV[@]}" commit -q --allow-empty -m init ) +printf '%s\n' '{"spec_archive": {"code": {"ref": "local", "branch": "master"}}}' > "$OPTP/.claude/.idd/local.json" +OPT_OUT=$(HOME="$W" CLAUDE_PLUGIN_ROOT="$HERE/../../.." WORKDIR="$OPTP/code" GITHUB_REPO=test/repo NUMBER=61 PATH="$W/bin:$PATH" \ + bash -c "$(snippet "$CSEC")" 2>&1) +assert_grep "idd-close: in a repository opted into its local branch, Step 1.5 says the branch lookup was skipped" \ + "branch lookup skipped" "$OPT_OUT" +refute_grep "idd-close: … and the helper did not report a failed fetch" "git fetch failed" "$OPT_OUT" +NOPT_OUT=$(HOME="$W" CLAUDE_PLUGIN_ROOT="$HERE/../../.." WORKDIR="$BR" GITHUB_REPO=test/repo NUMBER=61 PATH="$W/bin:$PATH" \ + bash -c "$(snippet "$CSEC")" 2>&1) +refute_grep "idd-close: in a repository not opted in, Step 1.5 does not skip the branch lookup" "branch lookup skipped" "$NOPT_OUT" +assert_grep "idd-close: Step 1.5 asks archive-ref" 'spec-change.py" archive-ref' "$CSEC" + print_summary "check-existing-work" diff --git a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh new file mode 100755 index 00000000..59e954ea --- /dev/null +++ b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh @@ -0,0 +1,145 @@ +#!/usr/bin/env bash +# spec-archive-local suite (#547) — a repository without a remote can opt into its local +# default branch: `spec-change.py archive-ref` decides which branch the spec checks read, +# `spec-change.py link-base` gives the base of the link check in that mode. +# +# spec-example: spec-on-every-issue / how a spec_archive entry resolves +# spec-example: spec-on-every-issue / where the local link check starts +# +# Real git repositories under a temporary HOME, so the walk up for the IDD configuration +# stops inside the fixture and never reads the developer's own files. + +set -u +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +. "$HERE/../../lib/assert-helpers.sh" +PLUGIN="$(cd "$HERE/../../.." && pwd)" +SC="$PLUGIN/scripts/spec-change.py" +WORK=$(mktemp -d "${TMPDIR:-/tmp}/idd-spec-archive-local.XXXXXX") +WORK=$(cd "$WORK" && pwd -P) +trap 'rm -rf "$WORK"' EXIT +export HOME="$WORK" GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 +export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.test GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.test +field() { python3 -c 'import json,sys; d=json.loads(sys.stdin.read() or "{}"); print(d.get(sys.argv[1], ""))' "$1"; } + +mkrepo() { # dir → a repository with one commit on master + mkdir -p "$1"; git init -q -b master "$1" + git -C "$1" commit -q --allow-empty -m base +} +conf() { # parent-dir json → writes /.claude/.idd/local.json + mkdir -p "$1/.claude/.idd"; printf '%s\n' "$2" > "$1/.claude/.idd/local.json" +} +ar() { OUT=$(python3 "$SC" archive-ref --cwd "$1" 2>/dev/null); RC=$?; ST=$(printf '%s' "$OUT" | field status); } +OPT='{"ref": "local", "branch": "master"}' + +echo "spec-archive-local: how a spec_archive entry resolves" +mkrepo "$WORK/none/sub" +ar "$WORK/none/sub" +assert_eq "no configuration found → remote" remote "$ST" +assert_exit "… exit 0" 0 "$RC" + +mkrepo "$WORK/a2/sub"; conf "$WORK/a2" '{"github_repo": "o/r"}' +ar "$WORK/a2/sub" +assert_eq "a file without spec_archive → remote" remote "$ST" + +mkrepo "$WORK/a3/sub"; conf "$WORK/a3" "{\"spec_archive\": {\"other\": $OPT}}" +ar "$WORK/a3/sub" +assert_eq "spec_archive names another path only → remote" remote "$ST" + +mkrepo "$WORK/a4/sub"; conf "$WORK/a4" "{\"spec_archive\": {\"sub\": $OPT}}" +ar "$WORK/a4/sub" +assert_eq "spec_archive names this path → local" local "$ST" +assert_exit "… exit 0" 0 "$RC" +assert_eq "… branch master" master "$(printf '%s' "$OUT" | field branch)" +assert_eq "… and its commit" "$(git -C "$WORK/a4/sub" rev-parse master)" "$(printf '%s' "$OUT" | field ref)" +assert_eq "… key is the path relative to the configuration" sub "$(printf '%s' "$OUT" | field key)" +mkdir -p "$WORK/a4/sub/deeper" +ar "$WORK/a4/sub/deeper" +assert_eq "… also from a directory inside the repository" local "$ST" + +mkrepo "$WORK/a5/sub"; conf "$WORK/a5" "{\"spec_archive\": {\"./sub/\": $OPT}}" +ar "$WORK/a5/sub" +assert_eq "the path written as ./sub/ → local" local "$ST" + +mkrepo "$WORK/a6/sub"; conf "$WORK/a6" "{\"spec_archive\": {\"sub\": $OPT}}" +git -C "$WORK/a6/sub" remote add origin "$WORK/nowhere.git" +ar "$WORK/a6/sub" +assert_eq "the repository has a remote → error" error "$ST" +assert_exit "… exit 2" 2 "$RC" +assert_grep "… naming the remote" "origin" "$(printf '%s' "$OUT" | field reason)" + +mkrepo "$WORK/a7/sub"; conf "$WORK/a7" '{"spec_archive": {"sub": {"ref": "local", "branch": "trunk"}}}' +ar "$WORK/a7/sub" +assert_eq "the branch does not exist → error" error "$ST" + +mkrepo "$WORK/a8/sub"; conf "$WORK/a8" '{"spec_archive": {"sub": {"ref": "remote", "branch": "master"}}}' +ar "$WORK/a8/sub" +assert_eq "ref is not local → error" error "$ST" + +mkrepo "$WORK/a9/sub"; conf "$WORK/a9" '{"spec_archive": {"sub": {"ref": "local"}}}' +ar "$WORK/a9/sub" +assert_eq "no branch → error" error "$ST" + +mkrepo "$WORK/a10/sub"; conf "$WORK/a10" '{"spec_archive": ["sub"]}' +ar "$WORK/a10/sub" +assert_eq "spec_archive is a list → error" error "$ST" + +mkrepo "$WORK/a11/sub"; conf "$WORK/a11" '{"spec_archive": ' +ar "$WORK/a11/sub" +assert_eq "the file is not JSON → error" error "$ST" +assert_exit "… exit 2" 2 "$RC" + +# The legacy file name is read too, after the new one at the same level. +mkrepo "$WORK/a12/sub"; mkdir -p "$WORK/a12/.claude" +printf '%s\n' "{\"spec_archive\": {\"sub\": $OPT}}" > "$WORK/a12/.claude/issue-driven-dev.local.json" +ar "$WORK/a12/sub" +assert_eq "the legacy configuration file → local" local "$ST" + +# The repository's own configuration, key "." +mkrepo "$WORK/a13"; conf "$WORK/a13" "{\"spec_archive\": {\".\": $OPT}}" +ar "$WORK/a13" +assert_eq "the repository's own configuration, key . → local" local "$ST" + +ar "$WORK" +assert_eq "not inside a git repository → error" error "$ST" + +echo "spec-archive-local: where the local link check starts" +lb() { OUT=$(cd "$1" && python3 "$SC" link-base --cwd "$1" --issue "$2" 2>/dev/null); RC=$?; ST=$(printf '%s' "$OUT" | field status); } +B="$WORK/lb1/repo"; mkrepo "$B"; conf "$WORK/lb1" "{\"spec_archive\": {\"repo\": $OPT}}" +git -C "$B" commit -q --allow-empty -m "tagged"; git -C "$B" tag idd-14-baseline +TAGGED=$(git -C "$B" rev-parse HEAD) +git -C "$B" commit -q --allow-empty -m "a (#14)" +lb "$B" 14 +assert_eq "tag on an ancestor of HEAD → ok" ok "$ST" +assert_eq "… the tag's commit" "$TAGGED" "$(printf '%s' "$OUT" | field base)" +assert_eq "… from baseline-tag" baseline-tag "$(printf '%s' "$OUT" | field from)" + +B="$WORK/lb2/repo"; mkrepo "$B"; conf "$WORK/lb2" "{\"spec_archive\": {\"repo\": $OPT}}" +BASE=$(git -C "$B" rev-parse HEAD) +git -C "$B" commit -q --allow-empty -m "a (#14)"; git -C "$B" commit -q --allow-empty -m $'b\n\nRefs #14' +lb "$B" 14 +assert_eq "no tag; the parent of the first commit naming #14 → ok" ok "$ST" +assert_eq "… the commit before it" "$BASE" "$(printf '%s' "$OUT" | field base)" +assert_eq "… from first-commit" first-commit "$(printf '%s' "$OUT" | field from)" + +B="$WORK/lb3/repo"; mkrepo "$B"; conf "$WORK/lb3" "{\"spec_archive\": {\"repo\": $OPT}}" +git -C "$B" commit -q --allow-empty -m "a (#142)" +lb "$B" 14 +assert_eq "only #142 names a 14 → error" error "$ST" +assert_exit "… exit 2" 2 "$RC" + +B="$WORK/lb4/repo"; mkdir -p "$B"; git init -q -b master "$B"; conf "$WORK/lb4" "{\"spec_archive\": {\"repo\": $OPT}}" +git -C "$B" commit -q --allow-empty -m "start (#14)" +lb "$B" 14 +assert_eq "the first commit with #14 is the root commit → error" error "$ST" + +B="$WORK/lb5/repo"; mkrepo "$B" +git -C "$B" commit -q --allow-empty -m "a (#14)" +lb "$B" 14 +assert_eq "not opted in → remote" remote "$ST" +assert_exit "… exit 0" 0 "$RC" + +lb "$WORK/lb2/repo" 14x +assert_eq "an issue number that is not digits → error" error "$ST" +assert_exit "… exit 2" 2 "$RC" + +print_summary spec-archive-local diff --git a/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh b/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh index c7f43d15..ec5ead74 100755 --- a/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh @@ -113,6 +113,35 @@ step157 "$IC_OK" 0 assert_eq "the remote dropped the archive, the local tracking ref did not move → stops" refuse "$STATUS" git -C "$C" config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*' +echo "spec-close-gate: a repository without a remote, opted into its local branch (#547)" +# The configuration sits above the repository, keyed by its path; the repository has no remote. gh repo view +# fails in these rows, so a pass shows the gate did not go to the remote at all. +L="$WORK/issue-repo"; LR="$L/code"; mkdir -p "$L/.claude/.idd" "$LR" +printf '%s\n' '{"spec_archive": {"code": {"ref": "local", "branch": "master"}}}' > "$L/.claude/.idd/local.json" +git init -q -b master "$LR"; mkdir -p "$LR/openspec/specs"; echo x > "$LR/openspec/specs/.keep" +git -C "$LR" add -A; git -C "$LR" commit -q -m base +step157_in() { # dir comments-json → STATUS, GRC, OUTALL + printf '%s' "$2" > "$WORK/comments.json" + OUTALL=$(cd "$1" && env PATH="$WORK/bin:$PATH" HOME="$WORK" FAKE_COMMENTS="$WORK/comments.json" FAKE_FAIL=0 FAKE_VIEW_FAIL=1 \ + GITHUB_REPO=o/r NUMBER=42 CWD="$1" CLAUDE_PLUGIN_ROOT="$PLUGIN" \ + bash --norc --noprofile -c '. "$1"; printf "\nSTATUS=%s\nGRC=%s\n" "$(printf "%s" "$GATE" | python3 -c "import json,sys; print(json.loads(sys.stdin.read()).get(\"status\"))")" "$GATE_RC"' _ "$BLOCK" 2>/dev/null "$LR/openspec/changes/archive/2026-11-14-idd-42-fix-timeout/proposal.md" +git -C "$LR" add -A; git -C "$LR" commit -q -m "chore: archive idd-42-fix-timeout (#42)" +step157_in "$LR" "$IC_OK" +assert_eq "no remote, opted in, the change is archived on master → passes without the remote" pass "$STATUS" +assert_eq "… exit 0" 0 "$GRC" +assert_grep "… and prints the local branch and commit" "local ref master@$(git -C "$LR" rev-parse --short master)" "$OUTALL" +git -C "$LR" remote add origin "$WORK/o.git" +step157_in "$LR" "$IC_OK" +assert_eq "the repository has a remote and is opted into local → stops" error "$STATUS" +assert_eq "… exit 2" 2 "$GRC" +assert_grep "… and prints the reason" "remote" "$OUTALL" +git -C "$LR" remote remove origin + echo "spec-close-gate: the skill text" G="$(sed -n '/^### Step 1.57: /,/^### Step 1.6: /p' "$CLOSE")" line_of() { local n; n=$(grep -nF -- "$1" "$CLOSE" | head -1 | cut -d: -f1); printf '%s' "${n:-999999}"; } @@ -121,6 +150,7 @@ assert_true "Step 1.57 sits between Step 1.55 and Step 1.6" \ assert_grep "the gate calls spec-change.py archived" 'spec-change.py" archived' "$G" assert_grep "the gate fetches the default branch from the remote" 'fetch -q origin -- "$DEFAULT_BRANCH"' "$G" assert_grep "… and checks the commit that fetch returned" 'rev-parse -q --verify FETCH_HEAD' "$G" +assert_grep "the gate first asks archive-ref which branch to read (#547)" 'spec-change.py" archive-ref' "$G" assert_grep "the gate chooses the comment with spec-change.py ic (one selection, shared with verify)" 'spec-change.py" ic --comments' "$G" assert_grep "no Implementation Complete comment → not held to the gate (row 5)" "沒有 Implementation Complete" "$G" assert_grep "refuse or error stops the close" "停下、不 close" "$G" diff --git a/plugins/issue-driven-dev/skills/idd-close/SKILL.md b/plugins/issue-driven-dev/skills/idd-close/SKILL.md index 8e1b6bc1..0fb46c36 100644 --- a/plugins/issue-driven-dev/skills/idd-close/SKILL.md +++ b/plugins/issue-driven-dev/skills/idd-close/SKILL.md @@ -352,7 +352,7 @@ TaskCreate(name="check_prerequisites", description="gh issue view 確認 OPEN + TaskCreate(name="check_attachments", description="確認 closing comment 即將引用的 attachment 在 .claude/.idd/attachments/issue-NNN/ 仍存在(防止使用者搬檔造成失效引用);manifest 對照 issue 當下 attachment list,新增的不重新 fetch(那是 idd-diagnose 工作)。依 rules/process-attachments.md。") TaskCreate(name="check_open_prs", description="Step 1.5: gh pr list 找引用 #NNN 的 open PR;若有 unmerged PR → refuse close") TaskCreate(name="merge_completeness_gate", description="Step 1.55 (v2.84.0+, #184): resolve issue branch via merged-PR headRefOid (SHA — survives GitHub branch-delete-on-merge) → local idd/-* → VISIBLE skip note; bash ${CLAUDE_PLUGIN_ROOT}/scripts/check-merge-completeness.sh --branch --baseline origin/ (clean at once when the tip has the head's content; else finds the commit where the branch landed, then checks each commit's effects there in place by two-way diffs; the commits it cannot place at a landing commit are checked at the tip by line presence, #399); rc=3 orphans → AskUserQuestion 3-option (close anyway / abort+land / mis-detection), warn-only; rc=4 (could not verify — reason from the helper's stderr) / no-branch print a note (never silent). Never hard-blocks.") -TaskCreate(name="spec_archive_gate", description="Step 1.57 (#480): 最新一則由有寫入權的帳號貼的 Implementation Complete → spec-change.py archived --ref origin/;pass 才往下,refuse / error 停下、不 close;沒有 Implementation Complete 的 issue 不受這一道檢查") +TaskCreate(name="spec_archive_gate", description="Step 1.57 (#480): 最新一則由有寫入權的帳號貼的 Implementation Complete → spec-change.py archived --ref origin/(程式 repo 沒有 remote、設定 spec_archive 指到本機 branch 時改用本機 branch,#547);pass 才往下,refuse / error 停下、不 close;沒有 Implementation Complete 的 issue 不受這一道檢查") TaskCreate(name="semantic_gate_check", description="Step 1.6: 對每個 - [x] bullet 做 keyword extraction → 驗證對應 artifact 真存在/有 commit。Warn-only。") TaskCreate(name="draft_closing_comment", description="起草 closing summary:code issue(bug/feature/refactor/docs)用 Problem / Root Cause / Solution / Verification / Changes 五段式;`type=meeting` 用 decision→action mapping(每個決策 → follow-up action + owner),不用五段式、不跑 ### Verification、不要求 /idd-verify TDD pass(見上方「Meeting close」段 + Step 2 meeting 變體)") TaskCreate(name="review_with_user", description="顯示 closing comment 給使用者確認。一般 close 在使用者已明確下 /idd-close 時可省略;**--retroactive 不得省略**——那條路徑上 helper 已經交出許可權,人是唯一還在判斷的一層") @@ -412,7 +412,15 @@ Exit code: # #366: 引用本 issue 的 open PR 來自共用 helper(唯一的比對實作,契約 references/pr-issue-matching.md)。 # gate 語意不變:任何 open PR 引用本 issue(E1 宣告或 E2 只提及,自家或別人的)都擋 —— # Open PR = 「這個改動還沒進 main」,PR 路徑沒走完就不能結案。 -EW_JSON=$(bash "${CLAUDE_PLUGIN_ROOT}/scripts/check-existing-work.sh" --cwd "${WORKDIR:-$PWD}" "$GITHUB_REPO" "$NUMBER") || { +# #547: 程式 repo 沒有 remote、而且設定 spec_archive 把它指到本機 branch 時(spec-change.py archive-ref 回 local), +# 不 fetch 它、不讀它的 branch;open PR 照樣在 issue 所在的 repo 查。其他回覆(remote、error)照舊。 +EW_SKIP="" +if [ "$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archive-ref --cwd "${WORKDIR:-$PWD}" 2>/dev/null \ + | python3 -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("status", ""))' 2>/dev/null)" = local ]; then + EW_SKIP="--skip-branches" + echo "→ Step 1.5: spec_archive.ref=local — this repository has no remote; branch lookup skipped, open PRs checked on $GITHUB_REPO" +fi +EW_JSON=$(bash "${CLAUDE_PLUGIN_ROOT}/scripts/check-existing-work.sh" --cwd "${WORKDIR:-$PWD}" $EW_SKIP "$GITHUB_REPO" "$NUMBER") || { echo "✗ Step 1.5: existing-work lookup produced no result — refusing to close (fail-closed; retry)" >&2; exit 1; } # 查詢 open PR 本身失敗或列表達上限時拒絕結案:close 能 reopen,但結案摘要一貼出就通知了關注者、收不回,「不知道有沒有 open PR」不能當成「沒有」。 # (比 #366 之前更嚴:以前 gh 失敗時 OPEN_PRS 為空,gate 安靜通過。) @@ -533,7 +541,7 @@ fi 這張 issue 宣告的 Spectra change,要在預設 branch 上已經封存,才能結案(capability `spec-on-every-issue`;判定在 `scripts/spec-change.py`,契約見 [`references/spec-wrapper.md`](../../references/spec-wrapper.md))。 1. 留言用 `gh api --paginate` 抓,用 `spec-change.py ic` 選出這張 issue 的 Implementation Complete:最新一則以 `## Implementation Complete` 開頭(或第一行是 ``)、作者的 `author_association` 是 `OWNER`/`MEMBER`/`COLLABORATOR` 的留言(`author_association` 是寫入權的近似:API 不給留言者的權限)。`idd-verify` 用同一個指令,兩邊選到的一定是同一則。沒有 Implementation Complete 的 issue 不受這一道限制(`ic` 印出空的內容,讀成舊制留言)。 -2. 對遠端的預設 branch 跑封存檢查。留言抓不到、或 `ic` 讀不了,一律當成 `error`,**不**當成「沒有 Implementation Complete」(verify 第 1 輪的 HIGH:舊寫法用了一個沒有任何步驟設定的變數,抓不到時讀到空檔就放行): +2. 對遠端的預設 branch 跑封存檢查。程式 repo 沒有任何 remote、而且它上面的 IDD 設定用 `spec_archive` 把它指到本機 branch 時(`spec-change.py archive-ref` 回 `local`),改查那條本機 branch,不 fetch,並印出用的是本機 ref;設定見 [`references/config-protocol.md`](../../references/config-protocol.md) 的 `spec_archive` 一節(#547)。留言抓不到、或 `ic` 讀不了,一律當成 `error`,**不**當成「沒有 Implementation Complete」(verify 第 1 輪的 HIGH:舊寫法用了一個沒有任何步驟設定的變數,抓不到時讀到空檔就放行): ```bash SPEC_JSON=$(mktemp); SPEC_IC=$(mktemp) @@ -545,16 +553,32 @@ elif [ "$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" declared --file # so a failed fetch does not hold an issue this gate does not apply to. archived answers these from the comment. GATE=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archived --file "$SPEC_IC" --cwd "${CWD:-$PWD}" --ref HEAD); GATE_RC=$? else - # A declared change is checked against the default branch as the remote has it: no name, or a failed fetch, - # is an error, never a pass on a stale local ref (verify round 2). - DEFAULT_BRANCH=$(gh repo view "$GITHUB_REPO" --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null) || DEFAULT_BRANCH="" - # The commit the fetch returned (FETCH_HEAD), not origin/: a fetch refspec that does not cover the - # default branch leaves the tracking ref where it was (verify round 3). + # #547: which branch to read. A repository without any remote can be opted into its local branch by the + # `spec_archive` field of the IDD configuration above it (archive-ref prints local, with the commit); with no + # entry it prints remote and the default branch is read as the remote has it, as before; an entry that cannot + # be honoured (the repository has a remote, the branch does not exist, ...) is an error, never a fallback. + ARCH=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archive-ref --cwd "${CWD:-$PWD}" 2>/dev/null) + ARCH_STATUS=$(printf '%s' "$ARCH" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("status", ""))' 2>/dev/null) SPEC_REF="" - if [ -n "$DEFAULT_BRANCH" ] && git -C "${CWD:-$PWD}" fetch -q origin -- "$DEFAULT_BRANCH" 2>/dev/null; then - SPEC_REF=$(git -C "${CWD:-$PWD}" rev-parse -q --verify FETCH_HEAD 2>/dev/null) + if [ "$ARCH_STATUS" = local ]; then + SPEC_REF=$(printf '%s' "$ARCH" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read()).get("ref", ""))' 2>/dev/null) + printf '%s' "$ARCH" | python3 -c 'import json,sys; d=json.loads(sys.stdin.read()); print("→ spec archive gate: checking local ref %s@%s (this repository has no remote; spec_archive[%r] in %s)" % (d["branch"], d["ref"][:7], d["key"], d["config"]))' 2>/dev/null + elif [ "$ARCH_STATUS" = remote ]; then + # A declared change is checked against the default branch as the remote has it: no name, or a failed fetch, + # is an error, never a pass on a stale local ref (verify round 2). + DEFAULT_BRANCH=$(gh repo view "$GITHUB_REPO" --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null) || DEFAULT_BRANCH="" + # The commit the fetch returned (FETCH_HEAD), not origin/: a fetch refspec that does not cover the + # default branch leaves the tracking ref where it was (verify round 3). + if [ -n "$DEFAULT_BRANCH" ] && git -C "${CWD:-$PWD}" fetch -q origin -- "$DEFAULT_BRANCH" 2>/dev/null; then + SPEC_REF=$(git -C "${CWD:-$PWD}" rev-parse -q --verify FETCH_HEAD 2>/dev/null) + fi fi - if [ -z "$SPEC_REF" ]; then + if [ "$ARCH_STATUS" != local ] && [ "$ARCH_STATUS" != remote ]; then + GATE=$(printf '%s' "$ARCH" | python3 -c 'import json,sys +try: r = json.loads(sys.stdin.read()).get("reason", "") +except Exception: r = "" +print(json.dumps({"status": "error", "not_archived": [], "reason": "spec_archive: " + (r or "archive-ref printed nothing readable")}))'); GATE_RC=2 + elif [ -z "$SPEC_REF" ]; then GATE='{"status": "error", "not_archived": [], "reason": "the default branch could not be read (gh repo view or git fetch failed)"}'; GATE_RC=2 else GATE=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archived --file "$SPEC_IC" --cwd "${CWD:-$PWD}" --ref "$SPEC_REF"); GATE_RC=$? @@ -568,7 +592,7 @@ printf '%s\n' "$GATE" | jq -r '"→ spec archive gate: \(.status) \(.reason)"' |---|---| | `pass`(含 `no behaviour change`、`third-party clone`、舊制留言) | 往下 | | `refuse` | 停下、不 close:列出還沒封存的 change,或 `**Spec**:` 行的問題。常見原因是 PR 還沒合併,或封存 commit 不在合併的範圍裡 | -| `error` | 停下、不 close:留言、預設 branch 或設定讀不到,照原因處理後重跑 | +| `error` | 停下、不 close:留言、預設 branch 或設定讀不到,照原因處理後重跑。`spec_archive:` 開頭的原因是設定的問題(例如設了本機模式的 repo 有 remote、branch 不存在),改設定或移除那一條 | | 沒有輸出、不是 JSON、或上面沒列的 status | 停下、不 close,回報印出的內容 | 這一道和 Step 1.5 一樣是硬性的:不問人、沒有略過的選項。有人在場時要結案,先把 change 封存進預設 branch,或修正 Implementation Complete 的宣告。 From 071ff8879a9f0df57b18f8f5e4133268bac5b6ad Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 09:52:56 +0800 Subject: [PATCH 02/13] chore: record the attachment manifest (#547) Refs #547 Co-Authored-By: Claude Opus 5.5 --- .claude/.idd/attachments/issue-547/_manifest.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .claude/.idd/attachments/issue-547/_manifest.json diff --git a/.claude/.idd/attachments/issue-547/_manifest.json b/.claude/.idd/attachments/issue-547/_manifest.json new file mode 100644 index 00000000..964bd93d --- /dev/null +++ b/.claude/.idd/attachments/issue-547/_manifest.json @@ -0,0 +1,6 @@ +{ + "issue": 547, + "fetched_at": "2026-11-14T01:43:28Z", + "fetched_by": "idd-diagnose", + "files": [] +} From a263dafce43e5d897b51e549a68c16c7a0c0b11b Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 10:14:26 +0800 Subject: [PATCH 03/13] chore: archive idd-547-spec-archive-local (#547) Refs #547 Co-Authored-By: Claude Opus 5.5 --- .../.openspec.yaml | 2 + .../proposal.md | 0 .../specs/idd-existing-work-lookup/spec.md | 0 .../specs/spec-on-every-issue/spec.md | 0 .../tasks.md | 2 +- .../specs/idd-existing-work-lookup/spec.md | 21 +++++++ openspec/specs/spec-on-every-issue/spec.md | 58 ++++++++++++++++++- 7 files changed, 81 insertions(+), 2 deletions(-) rename openspec/changes/{idd-547-spec-archive-local => archive/2026-11-14-idd-547-spec-archive-local}/.openspec.yaml (54%) rename openspec/changes/{idd-547-spec-archive-local => archive/2026-11-14-idd-547-spec-archive-local}/proposal.md (100%) rename openspec/changes/{idd-547-spec-archive-local => archive/2026-11-14-idd-547-spec-archive-local}/specs/idd-existing-work-lookup/spec.md (100%) rename openspec/changes/{idd-547-spec-archive-local => archive/2026-11-14-idd-547-spec-archive-local}/specs/spec-on-every-issue/spec.md (100%) rename openspec/changes/{idd-547-spec-archive-local => archive/2026-11-14-idd-547-spec-archive-local}/tasks.md (97%) diff --git a/openspec/changes/idd-547-spec-archive-local/.openspec.yaml b/openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/.openspec.yaml similarity index 54% rename from openspec/changes/idd-547-spec-archive-local/.openspec.yaml rename to openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/.openspec.yaml index f483aa4c..1a60d392 100644 --- a/openspec/changes/idd-547-spec-archive-local/.openspec.yaml +++ b/openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/.openspec.yaml @@ -1,3 +1,5 @@ schema: spec-driven created: 2026-11-14 created_by: che cheng +archived_by: che cheng +archived_at: 2026-11-14 diff --git a/openspec/changes/idd-547-spec-archive-local/proposal.md b/openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/proposal.md similarity index 100% rename from openspec/changes/idd-547-spec-archive-local/proposal.md rename to openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/proposal.md diff --git a/openspec/changes/idd-547-spec-archive-local/specs/idd-existing-work-lookup/spec.md b/openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/specs/idd-existing-work-lookup/spec.md similarity index 100% rename from openspec/changes/idd-547-spec-archive-local/specs/idd-existing-work-lookup/spec.md rename to openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/specs/idd-existing-work-lookup/spec.md diff --git a/openspec/changes/idd-547-spec-archive-local/specs/spec-on-every-issue/spec.md b/openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/specs/spec-on-every-issue/spec.md similarity index 100% rename from openspec/changes/idd-547-spec-archive-local/specs/spec-on-every-issue/spec.md rename to openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/specs/spec-on-every-issue/spec.md diff --git a/openspec/changes/idd-547-spec-archive-local/tasks.md b/openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/tasks.md similarity index 97% rename from openspec/changes/idd-547-spec-archive-local/tasks.md rename to openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/tasks.md index 9858a119..107f7a82 100644 --- a/openspec/changes/idd-547-spec-archive-local/tasks.md +++ b/openspec/changes/archive/2026-11-14-idd-547-spec-archive-local/tasks.md @@ -20,4 +20,4 @@ ## 4. 收尾 - [x] 4.1 CHANGELOG 的 Unreleased 加 Added 條目(#547)。驗證:已發布版本的條目沒有改動。 -- [ ] 4.2 跑 run-all-tests.sh 與連結檢查。驗證:結束碼都是 0,links 回 ok。 +- [x] 4.2 跑 run-all-tests.sh 與連結檢查。驗證:結束碼都是 0,links 回 ok。 diff --git a/openspec/specs/idd-existing-work-lookup/spec.md b/openspec/specs/idd-existing-work-lookup/spec.md index 5eaa4417..7ce2378d 100644 --- a/openspec/specs/idd-existing-work-lookup/spec.md +++ b/openspec/specs/idd-existing-work-lookup/spec.md @@ -217,3 +217,24 @@ When `gh` or `git ls-remote` fails, or when a PR list reaches its limit, the hel - **AND** an open PR declares `#N` - **WHEN** `/idd-close #N` runs - **THEN** it SHALL refuse to close and print the reason + +--- +### Requirement: The helper can skip the branch lookup + +`check-existing-work.sh` SHALL accept `--skip-branches` before the repository argument. With it, the helper SHALL NOT run `git fetch` or list remote-tracking branches in `--cwd`, SHALL treat the clone as having no branches, SHALL NOT add a `git fetch failed` error, and SHALL add a top-level `notes` list that says the branch lookup was skipped. The PR lookups on the repository argument SHALL run as without the flag, and their failures and limits SHALL be reported as before. Without the flag the helper's output SHALL be as before, without a `notes` field. + +`idd-close` Step 1.5 SHALL pass `--skip-branches` only when `spec-change.py archive-ref` prints `local` for its working directory (requirement "A repository without a remote can opt into its local default branch" of `spec-on-every-issue`), and SHALL then print that the branch lookup was skipped and that the open PRs were checked on the issue's repository. The open-PR gate itself is unchanged. + +#### Scenario: idd-close in a repository opted into its local branch + +- **GIVEN** the working directory of `/idd-close` is a repository without a remote, opted into its local branch +- **WHEN** Step 1.5 runs +- **THEN** it calls the helper with `--skip-branches`, prints that the branch lookup was skipped, and still refuses to close while an open PR on the issue's repository references the issue + +##### Example: the branch lookup can be skipped + +| Clone | Flag | `git fetch` run | `errors` | `notes` | An open PR declaring the issue | +| --- | --- | --- | --- | --- | --- | +| has an `origin` that cannot be fetched | none | yes | has `git fetch failed` | absent | reported as E1 | +| has no remote | `--skip-branches` | no | no `git fetch failed` | says the branch lookup was skipped | reported as E1 | +| has no remote, the open PR list fails | `--skip-branches` | no | has the PR list failure | says the branch lookup was skipped | verdict `unknown` | diff --git a/openspec/specs/spec-on-every-issue/spec.md b/openspec/specs/spec-on-every-issue/spec.md index 56d32660..ba6098e7 100644 --- a/openspec/specs/spec-on-every-issue/spec.md +++ b/openspec/specs/spec-on-every-issue/spec.md @@ -325,7 +325,7 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL --- ### Requirement: Close requires the issue's change to be archived -`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails; for any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. +`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote`, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails. When the answer is `local`, it SHALL check the commit `archive-ref` returned, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch and the commit. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. #### Scenario: An unarchived change holds the close @@ -334,6 +334,13 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL - **WHEN** `idd-close` runs its gates - **THEN** it does not close the issue and says the change is not archived +#### Scenario: A repository without a remote, opted in + +- **GIVEN** the code repository has no remote and the IDD configuration above it maps the repository's path to `{"ref": "local", "branch": "master"}` +- **AND** the change is archived on `master` +- **WHEN** `idd-close` runs its gates +- **THEN** the gate passes without fetching and prints the local branch and commit it checked + ##### Example: the close gate reads the default branch | Newest Implementation Complete comment | On the default branch | Close gate | @@ -347,6 +354,9 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL | marker, `**Spec**: change idd-42-fix-timeout` | the default branch cannot be fetched | stops, saying the default branch could not be read | | marker, `**Spec**: no behaviour change` | the default branch cannot be fetched | passes; the branch is not read | | marker, `**Spec**: change idd-42-fix-timeout` | the remote's default branch dropped the archive, the local tracking ref did not move | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts the repository into its local `master`, where the change is archived | passes; prints `local ref master@` | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts in, the change is not archived on `master` | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | the repository has a remote and the configuration opts it into `local` | stops and prints the reason | --- ### Requirement: One way to choose the Implementation Complete comment @@ -376,3 +386,49 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL | JSON nested a hundred thousand arrays deep | nothing | 2 | --- +### Requirement: A repository without a remote can opt into its local default branch + +`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. It SHALL find the IDD configuration by walking up from the repository's top level: at each directory, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory or at `/`, and SHALL use the first file found. The key it looks up is the path of the repository's top level relative to the directory that holds that `.claude/` directory, with both paths resolved through symbolic links; a key in the file SHALL match when it names the same path after `.` and `..` segments and a trailing `/` are normalised, and `.` names the directory of the configuration itself. It SHALL print one JSON line and exit as follows: + +- `remote` (exit 0) when no configuration file is found, when the file has no `spec_archive` field, or when `spec_archive` has no entry for the key. Callers then read the default branch as the remote has it, as before. +- `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at), `config` and `key`, when the entry is `{"ref": "local", "branch": ""}`, the repository has no remote at all (`git remote` lists nothing), and the branch exists. +- `error` (exit 2), with a `reason`, when the file found cannot be read as a JSON object; when `spec_archive` is not an object; when the entry is not an object, its `ref` is not `local`, or its `branch` is missing, empty, not a string or starts with `-`; when the repository has any remote; when the branch does not exist; or when `` is not inside a git repository. + +The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. + +`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the tag `idd--baseline` when that tag exists and is an ancestor of `HEAD` (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message contains `#` not followed by another digit (`from: first-commit`). It SHALL print `error` (exit 2) when neither exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. + +`references/spec-wrapper.md` step 5 SHALL ask `link-base` first and use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote`, and SHALL stop when it prints `error` or nothing a JSON reader can take. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. + +#### Scenario: An entry for a repository that later gained a remote + +- **GIVEN** a configuration entry `{"ref": "local", "branch": "master"}` for a repository +- **AND** a remote was added to that repository afterwards +- **WHEN** `archive-ref` runs for it +- **THEN** it prints `error` and names the remote, instead of reading the local branch + +##### Example: how a spec_archive entry resolves + +| Configuration found | Entry for the repository's path | Repository | `archive-ref` | +| --- | --- | --- | --- | +| none | — | no remote | `remote` | +| a file without `spec_archive` | — | no remote | `remote` | +| `spec_archive` names another path only | — | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local`, `master` and its commit | +| `spec_archive` names this path as `./sub/` | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | has a remote `origin` | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "trunk"}` | no remote, no branch `trunk` | `error` | +| `spec_archive` names this path | `{"ref": "remote", "branch": "master"}` | no remote | `error` | +| `spec_archive` names this path | `{"ref": "local"}` | no remote | `error` | +| `spec_archive` is a list | — | no remote | `error` | +| the file is not JSON | — | no remote | `error` | + +##### Example: where the local link check starts + +| Repository (opted into local `master`) | `link-base --issue 14` | +| --- | --- | +| tag `idd-14-baseline` on an ancestor of `HEAD` | `ok`, the tag's commit, `from: baseline-tag` | +| no tag; commits `base`, `a (#14)`, `b (Refs #14)` | `ok`, the commit `base`, `from: first-commit` | +| no tag; the only commit naming a 14 says `#142` | `error` | +| no tag; the first commit with `#14` is the root commit | `error` | +| the repository is not opted in | `remote` | From 6e17b7dd4ff265f1267204a24e1299a209d5da78 Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 12:13:33 +0800 Subject: [PATCH 04/13] =?UTF-8?q?fix:=20spec=5Farchive=20verify=20round=20?= =?UTF-8?q?1=20=E2=80=94=20unreadable=20config=20is=20no=20entry,=20branch?= =?UTF-8?q?=20names=20only,=20link-base=20reads=20the=20config=20first=20(?= =?UTF-8?q?#547)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit archive-ref: a configuration that cannot be read as a JSON object counts as having no entry (remote, with the reason), so a repository that never set spec_archive is not blocked; a UTF-8 BOM is read; two keys naming one path are an error; the branch must be a branch name; a remote means a remote URL; a linked worktree uses its main working tree's key; the walk-up does not read /. link-base resolves the configuration before reading --issue, uses the pr-issue-matching guards, auto_tag.baseline_format and NUL separated log records. check-existing-work refuses a repeated --cwd. idd-close Step 1.57 carries archive-ref's reason into a failed fetch and no longer prints the config path; spec-wrapper step 5 takes NUMBER or N. Tests pin the configured branch over HEAD and the --skip-branches hand-off. Refs #547 Co-Authored-By: Claude Opus 5.5 --- openspec/changes/idd-547-fix1/.openspec.yaml | 3 + openspec/changes/idd-547-fix1/proposal.md | 47 ++++++ .../specs/spec-on-every-issue/spec.md | 99 ++++++++++++ openspec/changes/idd-547-fix1/tasks.md | 21 +++ plugins/issue-driven-dev/CHANGELOG.md | 7 +- .../references/config-protocol.md | 10 +- .../references/spec-wrapper.md | 10 +- .../scripts/check-existing-work.sh | 5 +- .../issue-driven-dev/scripts/spec-change.py | 141 ++++++++++++------ .../scripts/tests/check-existing-work/test.sh | 16 +- .../scripts/tests/spec-archive-local/test.sh | 100 ++++++++++++- .../scripts/tests/spec-close-gate/test.sh | 23 ++- .../issue-driven-dev/skills/idd-all/SKILL.md | 2 +- .../skills/idd-close/SKILL.md | 9 +- 14 files changed, 429 insertions(+), 64 deletions(-) create mode 100644 openspec/changes/idd-547-fix1/.openspec.yaml create mode 100644 openspec/changes/idd-547-fix1/proposal.md create mode 100644 openspec/changes/idd-547-fix1/specs/spec-on-every-issue/spec.md create mode 100644 openspec/changes/idd-547-fix1/tasks.md diff --git a/openspec/changes/idd-547-fix1/.openspec.yaml b/openspec/changes/idd-547-fix1/.openspec.yaml new file mode 100644 index 00000000..f483aa4c --- /dev/null +++ b/openspec/changes/idd-547-fix1/.openspec.yaml @@ -0,0 +1,3 @@ +schema: spec-driven +created: 2026-11-14 +created_by: che cheng diff --git a/openspec/changes/idd-547-fix1/proposal.md b/openspec/changes/idd-547-fix1/proposal.md new file mode 100644 index 00000000..c0b027f3 --- /dev/null +++ b/openspec/changes/idd-547-fix1/proposal.md @@ -0,0 +1,47 @@ +**GitHub-side tracker**: #547(第 1 輪 verify:comment 6871443624;本輪計畫:comment 6871456743) + +## Problem + +第 1 輪 verify 找到 1 項 Blocking 與 24 項 In-scope fix:`archive-ref` 對兩個指向同一路徑的 key 回 `error`,requirement 卻沒寫這一種;沒設 `spec_archive` 的 repo,設定檔只要是空檔、`null`、帶 BOM 或非 UTF-8 就被擋下,違反「沒設就不變」;`link-base` 先驗 `--issue` 再看設定,讓沒設定的 repo 也可能在連結檢查停下;`branch` 接受 revision 語法;`#N` 沒有左邊界;有幾項規則沒有測試能分辨對錯(讀的是設定的 branch 還是 HEAD、Step 1.5 有沒有真的把旗標傳給 helper)。 + +## Root Cause + +第一版把「設定讀不了」與「設定寫錯」一起當成 `error`,但前者在沒設 `spec_archive` 的 repo 也會發生;把 `--issue` 的驗證放在設定解析之前;branch 只檢查存在;測試的 fixture 只有一條 branch、`HEAD` 永遠在設定的 branch 上,分不出兩種讀法。 + +## Proposed Solution + +修改 `spec-on-every-issue` 的兩條 requirement(見 specs/),並照著改 `spec-change.py`、`check-existing-work.sh`、idd-close Step 1.57、spec-wrapper 第 5 步、idd-all Step 3b.6、config-protocol,補齊各 Example 的測試。 + +## Non-Goals + +- 設定檔的擁有者與權限檢查、`idd-all`/`idd-implement` 在沒有 remote 的 repo 的 `unknown`:Follow-up。 +- ASSUMPTION: 不升版號,CHANGELOG 的 Unreleased 條目照實補充。 + +## Success Criteria + +- 新增與改動的測試在改程式之前失敗,改之後通過;run-all-tests 全過;links 回 ok。 + +## Capabilities + +### New Capabilities + +(none) + +### Modified Capabilities + +- `spec-on-every-issue`: 「Close requires the issue's change to be archived」與「A repository without a remote can opt into its local default branch」。 + +## Impact + +- Affected specs: spec-on-every-issue(MODIFIED 兩條) +- Affected code: + - Modified: plugins/issue-driven-dev/scripts/spec-change.py + - Modified: plugins/issue-driven-dev/scripts/check-existing-work.sh + - Modified: plugins/issue-driven-dev/skills/idd-close/SKILL.md + - Modified: plugins/issue-driven-dev/skills/idd-all/SKILL.md + - Modified: plugins/issue-driven-dev/references/spec-wrapper.md + - Modified: plugins/issue-driven-dev/references/config-protocol.md + - Modified: plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh + - Modified: plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh + - Modified: plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh + - Modified: plugins/issue-driven-dev/CHANGELOG.md diff --git a/openspec/changes/idd-547-fix1/specs/spec-on-every-issue/spec.md b/openspec/changes/idd-547-fix1/specs/spec-on-every-issue/spec.md new file mode 100644 index 00000000..47e8e9ae --- /dev/null +++ b/openspec/changes/idd-547-fix1/specs/spec-on-every-issue/spec.md @@ -0,0 +1,99 @@ +## MODIFIED Requirements + +### Requirement: Close requires the issue's change to be archived + +`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote`, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails; the reason it prints SHALL then include the reason `archive-ref` gave for answering `remote`, so that a repository meant for the local branch whose entry was not found says why. When the answer is `local`, it SHALL check the commit `archive-ref` returned for the configured branch, not `HEAD`, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch, the commit and the entry's key, and without the configuration file's path. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. + +#### Scenario: An unarchived change holds the close + +- **GIVEN** an Implementation Complete comment with the marker and `**Spec**: change idd-42-fix-timeout` +- **AND** `openspec/changes/idd-42-fix-timeout/` still exists on the default branch +- **WHEN** `idd-close` runs its gates +- **THEN** it does not close the issue and says the change is not archived + +#### Scenario: A repository without a remote, opted in + +- **GIVEN** the code repository has no remote and the IDD configuration above it maps the repository's path to `{"ref": "local", "branch": "master"}` +- **AND** the change is archived on `master` +- **WHEN** `idd-close` runs its gates +- **THEN** the gate passes without fetching and prints the local branch and commit it checked + +##### Example: the close gate reads the default branch + +| Newest Implementation Complete comment | On the default branch | Close gate | +| --- | --- | --- | +| marker, `**Spec**: change idd-42-fix-timeout` | the change is archived | passes | +| marker, `**Spec**: change idd-42-fix-timeout` | archived on the issue's branch only, not yet merged | stops, naming the change | +| marker, no `**Spec**:` line | not read | stops, naming the missing line | +| no marker, no `**Spec**:` line | not read | passes | +| the issue has no Implementation Complete comment | not read | passes | +| the comments could not be fetched | not read | stops, saying the comments could not be read | +| marker, `**Spec**: change idd-42-fix-timeout` | the default branch cannot be fetched | stops, saying the default branch could not be read | +| marker, `**Spec**: no behaviour change` | the default branch cannot be fetched | passes; the branch is not read | +| marker, `**Spec**: change idd-42-fix-timeout` | the remote's default branch dropped the archive, the local tracking ref did not move | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts the repository into its local `master`, where the change is archived | passes; prints `local ref master@` | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts in, the change is not archived on `master` | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; opted into `master`; `HEAD` is on the issue's branch, where the change is archived, and `master` does not have it | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote and no `spec_archive` entry for the repository | stops, saying the default branch could not be read | +| marker, `**Spec**: change idd-42-fix-timeout` | the repository has a remote and the configuration opts it into `local` | stops and prints the reason | + +### Requirement: A repository without a remote can opt into its local default branch + +`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree, the directory that holds the repository's common `.git` directory; otherwise its top level. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. It SHALL print one JSON line and exit as follows: + +- `remote` (exit 0), with a `reason`, when no configuration file is found; when the file found cannot be read as a JSON object (it is empty, `null`, not JSON, not valid UTF-8, or nested too deeply; a UTF-8 byte order mark is read as usual); when the file has no `spec_archive` field; or when `spec_archive` has no entry for the key. Callers then read the default branch as the remote has it, as before; a repository without any remote then stops there, with this reason. +- `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at, whatever `HEAD` is), `config` and `key`, when exactly one entry matches the key, it is `{"ref": "local", "branch": ""}`, the repository has no remote, and the branch exists. +- `error` (exit 2), with a `reason`, when `spec_archive` is not an object; when more than one key matches; when the matching entry is not an object, its `ref` is not `local`, or its `branch` is missing, not a string, or not a valid branch name (`git check-ref-format --branch` must accept it unchanged, so revision syntax such as `master~1` or `master@{0}` is refused); when the repository has a remote; when the branch does not exist; or when `` is not inside a git repository. + +A repository has a remote when any `remote..url` is set in the git configuration it reads; a `remote` section without a URL (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. + +`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does first, and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would, without reading ``. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the baseline tag when that tag exists and is an ancestor of `HEAD` (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message contains `#` with no letter, digit, `_`, `/` or `-` right before the `#` and no digit after the number, the rule of `references/pr-issue-matching.md` (`from: first-commit`). The baseline tag is the configuration's `auto_tag.baseline_format` with `{N}` replaced by ``, or `idd--baseline` when that field is absent or not a string containing `{N}`. Commit messages SHALL be read so that no byte a message can hold hides a commit. It SHALL print `error` (exit 2) when neither base exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits; an empty `` is a usage error (exit 64), like any empty argument of `spec-change.py`. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. + +`references/spec-wrapper.md` step 5 SHALL ask `link-base` first, with the issue number taken from `NUMBER`, or from `N` when `NUMBER` is empty, and SHALL use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote`, and SHALL stop with the reason when it prints `error` or nothing a JSON reader can take, without also printing the message about a failed fetch. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. + +#### Scenario: An entry for a repository that later gained a remote + +- **GIVEN** a configuration entry `{"ref": "local", "branch": "master"}` for a repository +- **AND** a remote was added to that repository afterwards +- **WHEN** `archive-ref` runs for it +- **THEN** it prints `error` and names the remote, instead of reading the local branch + +##### Example: how a spec_archive entry resolves + +| Configuration found | Entry for the repository's path | Repository | `archive-ref` | +| --- | --- | --- | --- | +| none | — | no remote | `remote` | +| a file without `spec_archive` | — | no remote | `remote` | +| `spec_archive` names another path only | — | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local`, `master` and its commit | +| `spec_archive` names this path as `./sub/` | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | has a remote `origin` | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "trunk"}` | no remote, no branch `trunk` | `error` | +| `spec_archive` names this path | `{"ref": "remote", "branch": "master"}` | no remote | `error` | +| `spec_archive` names this path | `{"ref": "local"}` | no remote | `error` | +| `spec_archive` is a list | — | no remote | `error` | +| the file is not JSON | — | no remote | `remote`, saying the file could not be read | +| the file is empty, or holds `null` | — | no remote | `remote` | +| the file starts with a UTF-8 byte order mark | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path as `sub` and as `./sub/` | both `{"ref": "local", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master~1"}` | no remote | `error`, not a branch name | +| `spec_archive` names this path as ` sub` | `{"ref": "local", "branch": "master"}` | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote; the global git configuration has `[remote "origin"]` with only `prune = true` | `local` | +| `spec_archive` names the main working tree | `{"ref": "local", "branch": "master"}` | asked from a linked worktree of it | `local` | +| the new file without `spec_archive`, the legacy file beside it with an entry | — | no remote | `remote` (the new file wins) | +| a file above the home directory with an entry | — | no remote | `remote` (not read) | + +##### Example: where the local link check starts + +| Repository (opted into local `master`) | `link-base --issue 14` | +| --- | --- | +| tag `idd-14-baseline` on an ancestor of `HEAD` | `ok`, the tag's commit, `from: baseline-tag` | +| no tag; commits `base`, `a (#14)`, `b (Refs #14)` | `ok`, the commit `base`, `from: first-commit` | +| no tag; the only commit naming a 14 says `#142` | `error` | +| no tag; the first commit with `#14` is the root commit | `error` | +| the repository is not opted in | `remote` | +| the repository is not opted in, `--issue abc` | `remote` | +| no tag; commits `base`, `see o/r#14`, `x#14`, `fix (#14)` | `ok`, the parent of `fix (#14)` | +| tag `idd-14-baseline` on a commit that is not an ancestor of `HEAD`; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | +| `auto_tag.baseline_format` is `start-{N}`, tag `start-14` on an ancestor | `ok`, that tag's commit, `from: baseline-tag` | +| no tag; a commit before `a (#14)` has the byte 0x1e in its message | `ok`, the parent of `a (#14)` | diff --git a/openspec/changes/idd-547-fix1/tasks.md b/openspec/changes/idd-547-fix1/tasks.md new file mode 100644 index 00000000..71197b61 --- /dev/null +++ b/openspec/changes/idd-547-fix1/tasks.md @@ -0,0 +1,21 @@ +## 1. 測試先行 + +- [x] 1.1 requirement「A repository without a remote can opt into its local default branch」— spec-archive-local:Example「how a spec_archive entry resolves」改動與新增的列(讀不了的設定回 remote、BOM、重複 key、revision 語法、空白 key、沒有 URL 的全域 remote 區段、linked worktree、新檔先於舊檔、HOME 以上不讀),帶標記 spec-example: spec-on-every-issue / how a spec_archive entry resolves。驗證:改之前新的列失敗。 +- [x] 1.2 spec-archive-local:Example「where the local link check starts」新增的列(remote 時不讀 `--issue`、左邊界、baseline 不是祖先時的退路、`baseline_format`、0x1e),並檢查 spec-wrapper 第 5 步呼叫 `link-base`,帶標記 spec-example: spec-on-every-issue / where the local link check starts。驗證:改之前新的列失敗。 +- [x] 1.3 requirement「Close requires the issue's change to be archived」— spec-close-gate:Example「the close gate reads the default branch」新增的兩列(HEAD 在 issue branch、沒有條目),測試設 HOME;remote 而 fetch 失敗時原因帶出 archive-ref 的說明;本機模式訊息不含設定檔路徑。驗證:改之前 HEAD 那一列與原因那一項失敗。 +- [x] 1.4 check-existing-work:Step 1.5 在本機模式真的把 `--skip-branches` 傳給 helper(`EW_JSON` 有 notes),open PR 仍被算到;重複 `--cwd` 回 2。驗證:拿掉旗標的變異會失敗。 + +## 2. 程式 + +- [x] 2.1 `spec-change.py` 照 requirement 改 `archive-ref` 與 `link-base`。驗證:1.1、1.2 通過;spec-change suite 照舊。 +- [x] 2.2 `check-existing-work.sh` 拒絕重複的 `--cwd`。驗證:1.4 通過。 + +## 3. skill 與文件 + +- [x] 3.1 idd-close Step 1.57 的原因與本機訊息。驗證:1.3 通過。 +- [x] 3.2 spec-wrapper 第 5 步(`${NUMBER:-${N:-}}`、錯誤訊息)、idd-all Step 3b.6 補一句。驗證:spec-wrapper-contract 照舊。 +- [x] 3.3 config-protocol 與 CHANGELOG。驗證:git diff 只改這一節與 Unreleased。 + +## 4. 收尾 + +- [x] 4.1 跑 run-all-tests.sh 與連結檢查。驗證:結束碼 0,links 回 ok。 diff --git a/plugins/issue-driven-dev/CHANGELOG.md b/plugins/issue-driven-dev/CHANGELOG.md index af68c84a..9e30c4b0 100644 --- a/plugins/issue-driven-dev/CHANGELOG.md +++ b/plugins/issue-driven-dev/CHANGELOG.md @@ -18,8 +18,11 @@ Version number left to the release. (`local ref @`); Step 1.5 skips the branch lookup (`check-existing-work.sh --skip-branches`) and still checks open PRs on the issue repository; the link check of `references/spec-wrapper.md` step 5 starts at the issue's baseline tag, or at the parent of the oldest commit naming `#N`. An entry is accepted only while the - repository has no remote at all; with a remote it is an error, never a silent fallback. Without an entry nothing - changes. New `spec-change.py` subcommands `archive-ref` and `link-base`; documented in `config-protocol.md`. + repository has no remote at all (a remote with a URL); with a remote it is an error, never a silent fallback. + Without an entry nothing changes, and a configuration file that cannot be read as a JSON object counts as having + no entry, so it does not block a repository that never set the field. The branch must be a branch name, and the + check reads it whatever `HEAD` is; a linked worktree uses its main working tree's key. New `spec-change.py` + subcommands `archive-ref` and `link-base`; documented in `config-protocol.md`. ### Fixed diff --git a/plugins/issue-driven-dev/references/config-protocol.md b/plugins/issue-driven-dev/references/config-protocol.md index a37dd093..38634bac 100644 --- a/plugins/issue-driven-dev/references/config-protocol.md +++ b/plugins/issue-driven-dev/references/config-protocol.md @@ -497,19 +497,19 @@ Which branch the spec checks read for a code repository that **deliberately has | Part | Meaning | |------|---------| -| key | The code repository's top level, relative to the directory that holds this `.claude/` (both resolved through symbolic links). `./sub/`, `sub/` and `sub` name the same path; `.` names the directory of this configuration itself | +| key | The code repository's main working tree (for a linked worktree, the directory holding the common `.git`), relative to the directory that holds this `.claude/` (both resolved through symbolic links). `./sub/`, `sub/` and `sub` name the same path; `.` names the directory of this configuration itself; a key that is empty or has leading or trailing whitespace names nothing. Two keys that name the same path are an error | | `ref` | Must be `local`. Any other value is an error | -| `branch` | The local branch that plays the default branch. Required: without a remote there is no `origin/HEAD` to read, and `HEAD` is only the branch checked out now | +| `branch` | The local branch that plays the default branch: a branch name that `git check-ref-format --branch` accepts unchanged (not `master~1` or `master@{0}`). Required: without a remote there is no `origin/HEAD` to read, and `HEAD` is only the branch checked out now. The check reads this branch whatever `HEAD` is | -Read by `scripts/spec-change.py archive-ref` (and `link-base`), which walks up from the **code repository's** top level to the first IDD configuration — the same walk as the other fields, new file before legacy file at each level, stopping after `$HOME`. Write the entry in the issue repository's configuration; do not add a configuration to the code repository just for this, because a file without `github_repo` there would be the first one the other skills find. +Read by `scripts/spec-change.py archive-ref` (and `link-base`), which walks up from the **code repository's** main working tree to the first IDD configuration — the same walk as the other fields, new file before legacy file at each level, stopping after `$HOME` (`/` itself is not read). A file that cannot be read as a JSON object (empty, `null`, not JSON, not UTF-8) is treated as having no entry, so a repository that never set the field is not blocked by it; a repository without a remote then stops at the fetch, with that reason. Write the entry in the issue repository's configuration; do not add a configuration to the code repository just for this, because a file without `github_repo` there would be the first one the other skills find. -**Accepted only while the repository has no remote at all.** An entry for a repository that has any remote is an error, not a silent fallback to the remote: an entry written because there was no remote must not outlive that reason. Other errors: the file is not a JSON object, `spec_archive` is not an object, the entry is not `{"ref": "local", "branch": ""}`, or the branch does not exist. +**Accepted only while the repository has no remote at all** — no `remote..url` in the git configuration it reads; a `remote` section without a URL (a global `remote.origin.prune`, say) does not count. An entry for a repository that has any remote is an error, not a silent fallback to the remote: an entry written because there was no remote must not outlive that reason. Other errors: the file is not a JSON object, `spec_archive` is not an object, the entry is not `{"ref": "local", "branch": ""}`, or the branch does not exist. What it changes, and nothing else: - `idd-close` Step 1.57 checks the archive on `refs/heads/` instead of fetching, and prints `local ref @`. - `idd-close` Step 1.5 calls `check-existing-work.sh --skip-branches`: no fetch in the code repository, open PRs still checked on the issue repository. -- `references/spec-wrapper.md` step 5 starts the link check at the issue's `idd--baseline` tag, or else at the parent of the oldest commit naming `#`; neither → stop. +- `references/spec-wrapper.md` step 5 starts the link check at the issue's baseline tag (`auto_tag.baseline_format`, default `idd--baseline`) when it is an ancestor of `HEAD`, or else at the parent of the oldest commit naming `#` (the left and right guards of `pr-issue-matching.md`, so `other/repo#N` does not count); neither → stop. A code repository that is not under the issue repository's directory finds no entry and keeps the remote behaviour (and its error). diff --git a/plugins/issue-driven-dev/references/spec-wrapper.md b/plugins/issue-driven-dev/references/spec-wrapper.md index 55a860bf..7ef81127 100644 --- a/plugins/issue-driven-dev/references/spec-wrapper.md +++ b/plugins/issue-driven-dev/references/spec-wrapper.md @@ -129,7 +129,9 @@ fi ```bash # #547: a repository without a remote, opted into its local branch by spec_archive, starts at the issue's # baseline (link-base prints ok); with no entry link-base prints remote and the default branch is fetched as before. -LB=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" link-base --cwd "$CWD" --issue "$NUMBER" 2>/dev/null) +# The issue number: NUMBER in the skills that call this contract, N in idd-all. A remote repository never reads it. +ISSUE_N="${NUMBER:-${N:-}}" +LB=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" link-base --cwd "$CWD" --issue "${ISSUE_N:-none}" 2>/dev/null) LB_STATUS=$(printf '%s' "$LB" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("status", ""))' 2>/dev/null) SPEC_BASE="" if [ "$LB_STATUS" = ok ]; then @@ -141,11 +143,13 @@ elif [ "$LB_STATUS" = remote ]; then SPEC_BASE=$(git -C "$CWD" merge-base HEAD FETCH_HEAD 2>/dev/null) fi else - echo "✗ spec close-out: spec_archive: $(printf '%s' "$LB" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("reason", "link-base printed nothing readable"))' 2>/dev/null)" >&2 + echo "✗ spec close-out: spec_archive: $(printf '%s' "$LB" | python3 -c 'import json,sys +try: print(json.loads(sys.stdin.read()).get("reason", "") or "link-base printed nothing readable") +except Exception: print("link-base printed nothing readable")' 2>/dev/null); stopping" >&2 fi if [ -n "$SPEC_BASE" ]; then python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" links --base "$SPEC_BASE" --cwd "$CWD" -else +elif [ "$LB_STATUS" = remote ]; then echo "✗ spec close-out: cannot find where this branch left the default branch (gh repo view, git fetch or git merge-base failed); stopping" >&2 fi ``` diff --git a/plugins/issue-driven-dev/scripts/check-existing-work.sh b/plugins/issue-driven-dev/scripts/check-existing-work.sh index 905a8eee..54a35035 100755 --- a/plugins/issue-driven-dev/scripts/check-existing-work.sh +++ b/plugins/issue-driven-dev/scripts/check-existing-work.sh @@ -45,13 +45,16 @@ def usage(msg): args = sys.argv[1:] cwd = "." skip_branches = False +seen_cwd = False while args[:1] in (["--cwd"], ["--skip-branches"]): if args[0] == "--skip-branches": skip_branches, args = True, args[1:] continue + if seen_cwd: + usage("--cwd given more than once") if len(args) < 2: usage("--cwd needs a directory") - cwd, args = args[1], args[2:] + cwd, args, seen_cwd = args[1], args[2:], True if len(args) < 2: usage("need and at least one issue number") repo, issues = args[0], args[1:] diff --git a/plugins/issue-driven-dev/scripts/spec-change.py b/plugins/issue-driven-dev/scripts/spec-change.py index 97a9a8e5..e866f393 100755 --- a/plugins/issue-driven-dev/scripts/spec-change.py +++ b/plugins/issue-driven-dev/scripts/spec-change.py @@ -37,14 +37,16 @@ archive-ref --cwd (#547) Which branch do the spec checks read for this repository? The first IDD configuration walking up - from the repository's top level may map its path (relative to the directory holding .claude/) in - `spec_archive` to {"ref": "local", "branch": ""}; that is accepted only without any remote. + from the repository's main working tree may map its path (relative to the directory holding .claude/) + in `spec_archive` to {"ref": "local", "branch": ""}; accepted only without any remote URL. + A configuration that cannot be read as a JSON object counts as having no entry (remote, with a reason). {"status": remote|local|error, "branch": "...", "ref": "", "config": "...", "key": "...", "reason": "..."} exit 0 (remote, local), 2 (error) link-base --cwd --issue (#547) - Where does the link check start in local mode? The tag idd--baseline when it is an ancestor of - HEAD, else the parent of the oldest commit of HEAD's history naming # (no digit after it). + Where does the link check start in local mode? The baseline tag (auto_tag.baseline_format, default + idd--baseline) when it is an ancestor of HEAD, else the parent of the oldest commit of HEAD's + history naming # (pr-issue-matching.md guards). Remote never reads --issue. {"status": remote|ok|error, "base": "", "from": baseline-tag|first-commit, "reason": "..."} exit 0 (remote, ok), 2 (error) @@ -572,49 +574,84 @@ def cmd_plan(argv): # ── archive-ref / link-base (#547) ────────────────────────────────────────── CONFIG_NAMES = (os.path.join(".claude", ".idd", "local.json"), os.path.join(".claude", "issue-driven-dev.local.json")) +ISSUE_REF_RE = r"(? 1: @@ -623,9 +660,13 @@ def archive_ref(cwd): if not isinstance(entry, dict) or entry.get("ref") != "local": raise Fail(f"spec_archive[{key!r}] in {path}: only {{\"ref\": \"local\", \"branch\": \"\"}} is supported") branch = entry.get("branch") - if not isinstance(branch, str) or not branch.strip() or branch.startswith("-"): + if (not isinstance(branch, str) or not branch or branch.startswith("-") + or any(ord(c) < 32 or ord(c) == 127 for c in branch)): raise Fail(f"spec_archive[{key!r}] in {path} needs a branch name") - remotes = git_text(top, "remote").split() + fmt = git(top, "check-ref-format", "--branch", branch, check=False) + if fmt.returncode != 0 or fmt.stdout.decode("utf-8", "replace").strip() != branch: + raise Fail(f"spec_archive[{key!r}] in {path}: {branch!r} is not a branch name") + remotes = remotes_of(top) if remotes: raise Fail(f"spec_archive[{key!r}] in {path} asks for the local branch, but this repository has a remote " f"({', '.join(remotes)}); the local branch is accepted only for a repository without any remote") @@ -644,32 +685,42 @@ def cmd_archive_ref(argv): return emit(out, 0) +def baseline_tag(config_path, n): + data, _ = read_config(config_path) + fmt = ((data or {}).get("auto_tag") or {}).get("baseline_format") if isinstance((data or {}).get("auto_tag"), dict) else None + if not isinstance(fmt, str) or "{N}" not in fmt: + fmt = "idd-{N}-baseline" + return fmt.replace("{N}", n) + + def cmd_link_base(argv): a = parse(argv, {"--cwd", "--issue"}, ["--cwd", "--issue"]) try: + out = archive_ref(a["--cwd"]) # the configuration first: remote never reads --issue + if out["status"] == "remote": + return emit(out, 0) if not re.fullmatch(r"[1-9][0-9]*", a["--issue"]): raise Fail(f"the issue number must be a positive integer written in digits: {a['--issue'][:20]!r}") n = a["--issue"] - out = archive_ref(a["--cwd"]) - if out["status"] == "remote": - return emit(out, 0) top = repo_top(a["--cwd"]) - tag = git(top, "rev-parse", "--verify", "--quiet", f"refs/tags/idd-{n}-baseline^{{commit}}", check=False) - if tag.returncode == 0: - sha = tag.stdout.decode("utf-8").strip() + tag = baseline_tag(out["config"], n) + t = git(top, "rev-parse", "--verify", "--quiet", f"refs/tags/{tag}^{{commit}}", check=False) + if t.returncode == 0: + sha = t.stdout.decode("utf-8").strip() if git(top, "merge-base", "--is-ancestor", sha, "HEAD", check=False).returncode == 0: - return emit({"status": "ok", "base": sha, "from": "baseline-tag"}, 0) - names = re.compile(r"#%s(?![0-9])" % n) - log = git_text(top, "log", "--reverse", "--format=%H%x00%P%x00%B%x1e", "HEAD") - for rec in log.split("\x1e"): - parts = rec.strip("\n").split("\x00") - if len(parts) < 3 or not names.search(parts[2]): + return emit({"status": "ok", "base": sha, "from": "baseline-tag", "tag": tag}, 0) + names = re.compile(ISSUE_REF_RE % n) + # -z: one NUL between commits; a commit message cannot hold NUL, so no message hides a commit. + log = git(top, "log", "--reverse", "-z", "--format=%H %P%n%B", "HEAD").stdout.decode("utf-8", "replace") + for rec in log.split("\x00"): + head, _, body = rec.partition("\n") + ids = head.split() + if not ids or not names.search(body): continue - parents = parts[1].split() - if not parents: - raise Fail(f"the oldest commit naming #{n} ({parts[0][:12]}) is the root commit; pass the base by hand") - return emit({"status": "ok", "base": parents[0], "from": "first-commit"}, 0) - raise Fail(f"no tag idd-{n}-baseline on the history of HEAD and no commit there names #{n}; pass the base by hand") + if len(ids) < 2: + raise Fail(f"the oldest commit naming #{n} ({ids[0][:12]}) is the root commit; pass the base by hand") + return emit({"status": "ok", "base": ids[1], "from": "first-commit"}, 0) + raise Fail(f"no tag {tag} on the history of HEAD and no commit there names #{n}; pass the base by hand") except Fail as exc: return emit({"status": "error", "reason": str(exc)}, 2) diff --git a/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh b/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh index 51178282..2bec0f17 100644 --- a/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh @@ -259,13 +259,25 @@ OPTP="$W/opted"; mkdir -p "$OPTP/.claude/.idd"; git "${GIT_ENV[@]}" init -q "$OP ( cd "$OPTP/code" && git "${GIT_ENV[@]}" checkout -q -b master && git "${GIT_ENV[@]}" commit -q --allow-empty -m init ) printf '%s\n' '{"spec_archive": {"code": {"ref": "local", "branch": "master"}}}' > "$OPTP/.claude/.idd/local.json" OPT_OUT=$(HOME="$W" CLAUDE_PLUGIN_ROOT="$HERE/../../.." WORKDIR="$OPTP/code" GITHUB_REPO=test/repo NUMBER=61 PATH="$W/bin:$PATH" \ - bash -c "$(snippet "$CSEC")" 2>&1) + bash -c "$(snippet "$CSEC") +printf 'EWNOTES=%s\\n' \"\$(printf '%s' \"\$EW_JSON\" | jq -c '.notes // []')\" +printf 'OPENPRS=%s\\n' \"\$(printf '%s' \"\$OPEN_PRS\" | jq -c '[.[].number]')\"" 2>&1) assert_grep "idd-close: in a repository opted into its local branch, Step 1.5 says the branch lookup was skipped" \ "branch lookup skipped" "$OPT_OUT" refute_grep "idd-close: … and the helper did not report a failed fetch" "git fetch failed" "$OPT_OUT" NOPT_OUT=$(HOME="$W" CLAUDE_PLUGIN_ROOT="$HERE/../../.." WORKDIR="$BR" GITHUB_REPO=test/repo NUMBER=61 PATH="$W/bin:$PATH" \ - bash -c "$(snippet "$CSEC")" 2>&1) + bash -c "$(snippet "$CSEC") +printf 'EWNOTES=%s\\n' \"\$(printf '%s' \"\$EW_JSON\" | jq -c '.notes // []')\"" 2>&1) refute_grep "idd-close: in a repository not opted in, Step 1.5 does not skip the branch lookup" "branch lookup skipped" "$NOPT_OUT" assert_grep "idd-close: Step 1.5 asks archive-ref" 'spec-change.py" archive-ref' "$CSEC" +# idd-547-fix1: the helper itself received --skip-branches (its notes say so), and the open PR still reaches the gate +assert_grep "idd-close: in local mode the helper ran with --skip-branches (its notes say so)" "branch lookup skipped" \ + "$(printf '%s\n' "$OPT_OUT" | sed -n 's/^EWNOTES=//p')" +assert_eq "idd-close: … and the open PR declaring the issue still reaches the gate" "[30]" \ + "$(printf '%s\n' "$OPT_OUT" | sed -n 's/^OPENPRS=//p')" +assert_eq "idd-close: not opted in → the helper ran without the flag (no notes)" "[]" \ + "$(printf '%s\n' "$NOPT_OUT" | sed -n 's/^EWNOTES=//p')" +runin --cwd "$NR" --cwd "$BR" test/repo 61 >/dev/null; RC_DUP=$? +assert_eq "a repeated --cwd is a usage error (exit 2)" 2 "$RC_DUP" print_summary "check-existing-work" diff --git a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh index 59e954ea..dc615e67 100755 --- a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh @@ -85,8 +85,59 @@ assert_eq "spec_archive is a list → error" error "$ST" mkrepo "$WORK/a11/sub"; conf "$WORK/a11" '{"spec_archive": ' ar "$WORK/a11/sub" -assert_eq "the file is not JSON → error" error "$ST" -assert_exit "… exit 2" 2 "$RC" +assert_eq "the file is not JSON → remote (idd-547-fix1)" remote "$ST" +assert_exit "… exit 0" 0 "$RC" +assert_grep "… saying the file could not be read" "not readable" "$(printf '%s' "$OUT" | field reason)" + +# idd-547-fix1 rows +mkrepo "$WORK/b1/sub"; mkdir -p "$WORK/b1/.claude/.idd"; : > "$WORK/b1/.claude/.idd/local.json" +ar "$WORK/b1/sub" +assert_eq "an empty configuration file → remote" remote "$ST" +mkrepo "$WORK/b2/sub"; conf "$WORK/b2" 'null' +ar "$WORK/b2/sub" +assert_eq "a configuration holding null → remote" remote "$ST" +mkrepo "$WORK/b3/sub"; mkdir -p "$WORK/b3/.claude/.idd" +printf '\357\273\277%s\n' "{\"spec_archive\": {\"sub\": $OPT}}" > "$WORK/b3/.claude/.idd/local.json" +ar "$WORK/b3/sub" +assert_eq "a UTF-8 byte order mark → read as usual, local" local "$ST" +mkrepo "$WORK/b4/sub"; mkdir -p "$WORK/b4/.claude/.idd"; printf '{"a": "\377"}\n' > "$WORK/b4/.claude/.idd/local.json" +ar "$WORK/b4/sub" +assert_eq "a file that is not valid UTF-8 → remote" remote "$ST" +mkrepo "$WORK/b5/sub"; mkdir -p "$WORK/b5/.claude/.idd" +python3 -c 'print("[" * 100000 + "]" * 100000)' > "$WORK/b5/.claude/.idd/local.json" +ar "$WORK/b5/sub" +assert_eq "a file nested too deeply → remote, not a traceback" remote "$ST" +mkrepo "$WORK/b6/sub"; conf "$WORK/b6" "{\"spec_archive\": {\"sub\": $OPT, \"./sub/\": $OPT}}" +ar "$WORK/b6/sub" +assert_eq "two keys naming the same path → error" error "$ST" +assert_grep "… more than one entry" "more than one entry" "$(printf '%s' "$OUT" | field reason)" +mkrepo "$WORK/b7/sub"; conf "$WORK/b7" '{"spec_archive": {"sub": {"ref": "local", "branch": "master~1"}}}' +git -C "$WORK/b7/sub" commit -q --allow-empty -m second +ar "$WORK/b7/sub" +assert_eq "branch master~1 (revision syntax) → error" error "$ST" +mkrepo "$WORK/b8/sub"; conf "$WORK/b8" '{"spec_archive": {"sub": {"ref": "local", "branch": "master@{0}"}}}' +ar "$WORK/b8/sub" +assert_eq "branch master@{0} → error" error "$ST" +mkrepo "$WORK/b9/sub"; conf "$WORK/b9" "{\"spec_archive\": {\" sub\": $OPT, \"\": $OPT}}" +ar "$WORK/b9/sub" +assert_eq "keys with surrounding whitespace or empty match nothing → remote" remote "$ST" +mkrepo "$WORK/b10/sub"; conf "$WORK/b10" "{\"spec_archive\": {\"sub\": $OPT}}" +printf '[remote "origin"]\n\tprune = true\n' > "$WORK/gitconfig-prune" +OUT=$(GIT_CONFIG_GLOBAL="$WORK/gitconfig-prune" python3 "$SC" archive-ref --cwd "$WORK/b10/sub" 2>/dev/null); ST=$(printf '%s' "$OUT" | field status) +assert_eq "a global remote section without a URL is not a remote → local" local "$ST" +mkrepo "$WORK/b11/sub"; conf "$WORK/b11" "{\"spec_archive\": {\"sub\": $OPT}}" +git -C "$WORK/b11/sub" worktree add -q "$WORK/b11/sub/.claude/worktrees/wt" -b wt 2>/dev/null +ar "$WORK/b11/sub/.claude/worktrees/wt" +assert_eq "asked from a linked worktree of the opted-in repository → local" local "$ST" +assert_eq "… with the main working tree's key" sub "$(printf '%s' "$OUT" | field key)" +mkrepo "$WORK/b12/sub"; conf "$WORK/b12" '{"github_repo": "o/r"}' +printf '%s\n' "{\"spec_archive\": {\"sub\": $OPT}}" > "$WORK/b12/.claude/issue-driven-dev.local.json" +ar "$WORK/b12/sub" +assert_eq "the new file wins over the legacy file at the same level → remote" remote "$ST" +mkdir -p "$WORK/abovehome/.claude/.idd"; printf '%s\n' "{\"spec_archive\": {\"home/sub\": $OPT}}" > "$WORK/abovehome/.claude/.idd/local.json" +mkrepo "$WORK/abovehome/home/sub" +OUT=$(HOME="$WORK/abovehome/home" python3 "$SC" archive-ref --cwd "$WORK/abovehome/home/sub" 2>/dev/null); ST=$(printf '%s' "$OUT" | field status) +assert_eq "a configuration above the home directory is not read → remote" remote "$ST" # The legacy file name is read too, after the new one at the same level. mkrepo "$WORK/a12/sub"; mkdir -p "$WORK/a12/.claude" @@ -142,4 +193,49 @@ lb "$WORK/lb2/repo" 14x assert_eq "an issue number that is not digits → error" error "$ST" assert_exit "… exit 2" 2 "$RC" +# idd-547-fix1 rows +lb "$WORK/lb5/repo" abc +assert_eq "not opted in, --issue abc → remote (the issue is not read)" remote "$ST" +assert_exit "… exit 0" 0 "$RC" + +B="$WORK/lb6/repo"; mkrepo "$B"; conf "$WORK/lb6" "{\"spec_archive\": {\"repo\": $OPT}}" +git -C "$B" commit -q --allow-empty -m "see o/r#14"; git -C "$B" commit -q --allow-empty -m "x#14" +BEFORE=$(git -C "$B" rev-parse HEAD); git -C "$B" commit -q --allow-empty -m "fix (#14)" +lb "$B" 14 +assert_eq "o/r#14 and x#14 do not count; the parent of 'fix (#14)'" "$BEFORE" "$(printf '%s' "$OUT" | field base)" + +B="$WORK/lb7/repo"; mkrepo "$B"; conf "$WORK/lb7" "{\"spec_archive\": {\"repo\": $OPT}}" +BASE=$(git -C "$B" rev-parse HEAD) +git -C "$B" checkout -q -b side; git -C "$B" commit -q --allow-empty -m side; git -C "$B" tag idd-14-baseline; git -C "$B" checkout -q master +git -C "$B" commit -q --allow-empty -m "a (#14)" +lb "$B" 14 +assert_eq "a baseline tag that is not an ancestor of HEAD → falls back to the first commit" "$BASE" "$(printf '%s' "$OUT" | field base)" +assert_eq "… from first-commit" first-commit "$(printf '%s' "$OUT" | field from)" + +B="$WORK/lb8/repo"; mkrepo "$B"; conf "$WORK/lb8" "{\"auto_tag\": {\"baseline_format\": \"start-{N}\"}, \"spec_archive\": {\"repo\": $OPT}}" +git -C "$B" commit -q --allow-empty -m "tagged"; git -C "$B" tag start-14; T=$(git -C "$B" rev-parse HEAD) +git -C "$B" commit -q --allow-empty -m "a (#14)" +lb "$B" 14 +assert_eq "auto_tag.baseline_format start-{N} → that tag" "$T" "$(printf '%s' "$OUT" | field base)" +assert_eq "… from baseline-tag" baseline-tag "$(printf '%s' "$OUT" | field from)" + +B="$WORK/lb9/repo"; mkrepo "$B"; conf "$WORK/lb9" "{\"spec_archive\": {\"repo\": $OPT}}" +git -C "$B" commit -q --allow-empty -m "$(printf 'odd \036 byte')"; BEFORE=$(git -C "$B" rev-parse HEAD) +git -C "$B" commit -q --allow-empty -m "a (#14)" +lb "$B" 14 +assert_eq "a 0x1e byte in an earlier message does not hide a commit" "$BEFORE" "$(printf '%s' "$OUT" | field base)" + +# archive-ref reports the configured branch, not HEAD (idd-547-fix1) +git -C "$WORK/a4/sub" checkout -q -b elsewhere; git -C "$WORK/a4/sub" commit -q --allow-empty -m elsewhere +ar "$WORK/a4/sub" +assert_eq "HEAD on another branch → ref is still master's commit" "$(git -C "$WORK/a4/sub" rev-parse master)" "$(printf '%s' "$OUT" | field ref)" +git -C "$WORK/a4/sub" checkout -q master + +echo "spec-archive-local: the wrapper and idd-all text" +WRAP="$PLUGIN/references/spec-wrapper.md" +STEP5=$(sed -n '/^## 5\. Close-out/,/^## 6\./p' "$WRAP") +assert_grep "spec-wrapper step 5 asks link-base" 'spec-change.py" link-base' "$STEP5" +assert_grep "… with the issue number from NUMBER or N" '${NUMBER:-${N:-}}' "$STEP5" +assert_grep "idd-all Step 3b.6 names link-base for the local mode" "link-base" "$(sed -n '/^#### Step 3b.6/,/^---/p' "$PLUGIN/skills/idd-all/SKILL.md")" + print_summary spec-archive-local diff --git a/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh b/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh index ec5ead74..683697f6 100755 --- a/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh @@ -73,7 +73,7 @@ awk '/^### Step 1.57: /{f=1} f && /^```bash$/{b=1; next} b && /^```$/{exit} b' " step157() { # comments-json fail(0|1) → STATUS, GRC printf '%s' "$1" > "$WORK/comments.json" local out - out=$(cd "$C" && env PATH="$WORK/bin:$PATH" FAKE_COMMENTS="$WORK/comments.json" FAKE_FAIL="$2" FAKE_VIEW_FAIL="${FAKE_VIEW_FAIL:-0}" \ + out=$(cd "$C" && env PATH="$WORK/bin:$PATH" HOME="$WORK" FAKE_COMMENTS="$WORK/comments.json" FAKE_FAIL="$2" FAKE_VIEW_FAIL="${FAKE_VIEW_FAIL:-0}" \ GITHUB_REPO=o/r NUMBER=42 CWD="$C" CLAUDE_PLUGIN_ROOT="$PLUGIN" \ bash --norc --noprofile -c '. "$1"; printf "\nSTATUS=%s\nGRC=%s\n" "$(printf "%s" "$GATE" | python3 -c "import json,sys; print(json.loads(sys.stdin.read()).get(\"status\"))")" "$GATE_RC"' _ "$BLOCK" 2>/dev/null /dev/null; step157_in "$LR" "$IC_OK"; printf '%s' "$OUTALL")" +# idd-547-fix1: HEAD on the issue's branch, where the change is archived; the configured master does not have it. +LH="$WORK/issue-repo-h"; LHR="$LH/code"; mkdir -p "$LH/.claude/.idd" "$LHR" +printf '%s\n' '{"spec_archive": {"code": {"ref": "local", "branch": "master"}}}' > "$LH/.claude/.idd/local.json" +git init -q -b master "$LHR"; mkdir -p "$LHR/openspec/specs"; echo x > "$LHR/openspec/specs/.keep" +git -C "$LHR" add -A; git -C "$LHR" commit -q -m base; git -C "$LHR" checkout -q -b idd/42-x +mkdir -p "$LHR/openspec/changes/archive/2026-11-14-idd-42-fix-timeout"; echo p > "$LHR/openspec/changes/archive/2026-11-14-idd-42-fix-timeout/proposal.md" +git -C "$LHR" add -A; git -C "$LHR" commit -q -m "chore: archive idd-42-fix-timeout (#42)" +step157_in "$LHR" "$IC_OK" +assert_eq "no remote, opted into master, HEAD on the issue's branch with the archive, master without → stops" refuse "$STATUS" +# idd-547-fix1: no remote and no spec_archive entry → stops, and the reason says why archive-ref answered remote +LN="$WORK/noentry"; mkdir -p "$LN/.claude/.idd"; git init -q -b master "$LN/code" +printf '%s\n' '{"github_repo": "o/r"}' > "$LN/.claude/.idd/local.json" +mkdir -p "$LN/code/openspec/specs"; echo x > "$LN/code/openspec/specs/.keep"; git -C "$LN/code" add -A; git -C "$LN/code" commit -q -m base +step157_in "$LN/code" "$IC_OK" +assert_eq "no remote and no spec_archive entry → stops with error" error "$STATUS" +assert_eq "… exit 2" 2 "$GRC" +GATE_REASON=$(cd "$LN/code" && env PATH="$WORK/bin:$PATH" HOME="$WORK" FAKE_COMMENTS="$WORK/comments.json" FAKE_FAIL=0 FAKE_VIEW_FAIL=0 \ + GITHUB_REPO=o/r NUMBER=42 CWD="$LN/code" CLAUDE_PLUGIN_ROOT="$PLUGIN" \ + bash --norc --noprofile -c '. "$1"; printf "%s" "$GATE"' _ "$BLOCK" 2>/dev/null -y` → 確認封存落在 `$CWD` → commit `chore: archive (#N)` → `spec-change.py" links --base <這條 branch 與剛 fetch 的預設 branch(FETCH_HEAD)的 merge-base>`(契約第 5 步那段) → `spec-change.py" archived --ref HEAD`。任何一步沒過:unattended 停下回報(`Stopped:`),attended 告訴使用者哪一步、等他決定。 +`spectra-apply` 做完之後、Phase 4 之前,照 [`references/spec-wrapper.md`](../../references/spec-wrapper.md) 第 5 步做 Spec close-out,順序固定:`spectra-verify` → `spectra archive -y` → 確認封存落在 `$CWD` → commit `chore: archive (#N)` → `spec-change.py" links --base <這條 branch 與剛 fetch 的預設 branch(FETCH_HEAD)的 merge-base>`(契約第 5 步那段;程式 repo 沒有 remote、用 `spec_archive` 指到本機 branch 時,起點改由 `spec-change.py link-base` 給,#547) → `spec-change.py" archived --ref HEAD`。任何一步沒過:unattended 停下回報(`Stopped:`),attended 告訴使用者哪一步、等他決定。 通過之後貼 Implementation Complete(經 `gh-egress.sh`),讓 `idd-verify` 與 `idd-close` 讀得到這張 issue 的宣告: diff --git a/plugins/issue-driven-dev/skills/idd-close/SKILL.md b/plugins/issue-driven-dev/skills/idd-close/SKILL.md index 0fb46c36..5c253f0c 100644 --- a/plugins/issue-driven-dev/skills/idd-close/SKILL.md +++ b/plugins/issue-driven-dev/skills/idd-close/SKILL.md @@ -562,7 +562,7 @@ else SPEC_REF="" if [ "$ARCH_STATUS" = local ]; then SPEC_REF=$(printf '%s' "$ARCH" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read()).get("ref", ""))' 2>/dev/null) - printf '%s' "$ARCH" | python3 -c 'import json,sys; d=json.loads(sys.stdin.read()); print("→ spec archive gate: checking local ref %s@%s (this repository has no remote; spec_archive[%r] in %s)" % (d["branch"], d["ref"][:7], d["key"], d["config"]))' 2>/dev/null + printf '%s' "$ARCH" | python3 -c 'import json,sys; d=json.loads(sys.stdin.read()); print("→ spec archive gate: checking local ref %s@%s (this repository has no remote; spec_archive[%r])" % (d["branch"], d["ref"][:7], d["key"]))' 2>/dev/null elif [ "$ARCH_STATUS" = remote ]; then # A declared change is checked against the default branch as the remote has it: no name, or a failed fetch, # is an error, never a pass on a stale local ref (verify round 2). @@ -579,7 +579,12 @@ try: r = json.loads(sys.stdin.read()).get("reason", "") except Exception: r = "" print(json.dumps({"status": "error", "not_archived": [], "reason": "spec_archive: " + (r or "archive-ref printed nothing readable")}))'); GATE_RC=2 elif [ -z "$SPEC_REF" ]; then - GATE='{"status": "error", "not_archived": [], "reason": "the default branch could not be read (gh repo view or git fetch failed)"}'; GATE_RC=2 + # #547: say why archive-ref answered remote, so a repository meant for its local branch whose entry was not + # found (or whose configuration could not be read) shows the reason next to the failed fetch. + GATE=$(printf '%s' "$ARCH" | python3 -c 'import json,sys +try: r = json.loads(sys.stdin.read()).get("reason", "") +except Exception: r = "" +print(json.dumps({"status": "error", "not_archived": [], "reason": "the default branch could not be read (gh repo view or git fetch failed)" + ("; spec_archive: " + r if r else "")}))'); GATE_RC=2 else GATE=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archived --file "$SPEC_IC" --cwd "${CWD:-$PWD}" --ref "$SPEC_REF"); GATE_RC=$? fi From 81e37d3d87f36feba2948dba5cbbe4ae5934b4da Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 12:24:59 +0800 Subject: [PATCH 05/13] chore: archive idd-547-fix1 (#547) Refs #547 Co-Authored-By: Claude Opus 5.5 --- .../2026-11-14-idd-547-fix1}/.openspec.yaml | 2 ++ .../2026-11-14-idd-547-fix1}/proposal.md | 0 .../specs/spec-on-every-issue/spec.md | 0 .../2026-11-14-idd-547-fix1}/tasks.md | 0 openspec/specs/spec-on-every-issue/spec.md | 34 ++++++++++++++----- 5 files changed, 27 insertions(+), 9 deletions(-) rename openspec/changes/{idd-547-fix1 => archive/2026-11-14-idd-547-fix1}/.openspec.yaml (54%) rename openspec/changes/{idd-547-fix1 => archive/2026-11-14-idd-547-fix1}/proposal.md (100%) rename openspec/changes/{idd-547-fix1 => archive/2026-11-14-idd-547-fix1}/specs/spec-on-every-issue/spec.md (100%) rename openspec/changes/{idd-547-fix1 => archive/2026-11-14-idd-547-fix1}/tasks.md (100%) diff --git a/openspec/changes/idd-547-fix1/.openspec.yaml b/openspec/changes/archive/2026-11-14-idd-547-fix1/.openspec.yaml similarity index 54% rename from openspec/changes/idd-547-fix1/.openspec.yaml rename to openspec/changes/archive/2026-11-14-idd-547-fix1/.openspec.yaml index f483aa4c..1a60d392 100644 --- a/openspec/changes/idd-547-fix1/.openspec.yaml +++ b/openspec/changes/archive/2026-11-14-idd-547-fix1/.openspec.yaml @@ -1,3 +1,5 @@ schema: spec-driven created: 2026-11-14 created_by: che cheng +archived_by: che cheng +archived_at: 2026-11-14 diff --git a/openspec/changes/idd-547-fix1/proposal.md b/openspec/changes/archive/2026-11-14-idd-547-fix1/proposal.md similarity index 100% rename from openspec/changes/idd-547-fix1/proposal.md rename to openspec/changes/archive/2026-11-14-idd-547-fix1/proposal.md diff --git a/openspec/changes/idd-547-fix1/specs/spec-on-every-issue/spec.md b/openspec/changes/archive/2026-11-14-idd-547-fix1/specs/spec-on-every-issue/spec.md similarity index 100% rename from openspec/changes/idd-547-fix1/specs/spec-on-every-issue/spec.md rename to openspec/changes/archive/2026-11-14-idd-547-fix1/specs/spec-on-every-issue/spec.md diff --git a/openspec/changes/idd-547-fix1/tasks.md b/openspec/changes/archive/2026-11-14-idd-547-fix1/tasks.md similarity index 100% rename from openspec/changes/idd-547-fix1/tasks.md rename to openspec/changes/archive/2026-11-14-idd-547-fix1/tasks.md diff --git a/openspec/specs/spec-on-every-issue/spec.md b/openspec/specs/spec-on-every-issue/spec.md index ba6098e7..d25660c3 100644 --- a/openspec/specs/spec-on-every-issue/spec.md +++ b/openspec/specs/spec-on-every-issue/spec.md @@ -325,7 +325,7 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL --- ### Requirement: Close requires the issue's change to be archived -`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote`, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails. When the answer is `local`, it SHALL check the commit `archive-ref` returned, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch and the commit. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. +`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote`, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails; the reason it prints SHALL then include the reason `archive-ref` gave for answering `remote`, so that a repository meant for the local branch whose entry was not found says why. When the answer is `local`, it SHALL check the commit `archive-ref` returned for the configured branch, not `HEAD`, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch, the commit and the entry's key, and without the configuration file's path. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. #### Scenario: An unarchived change holds the close @@ -356,6 +356,8 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL | marker, `**Spec**: change idd-42-fix-timeout` | the remote's default branch dropped the archive, the local tracking ref did not move | stops, naming the change | | marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts the repository into its local `master`, where the change is archived | passes; prints `local ref master@` | | marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts in, the change is not archived on `master` | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; opted into `master`; `HEAD` is on the issue's branch, where the change is archived, and `master` does not have it | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote and no `spec_archive` entry for the repository | stops, saying the default branch could not be read | | marker, `**Spec**: change idd-42-fix-timeout` | the repository has a remote and the configuration opts it into `local` | stops and prints the reason | --- @@ -388,17 +390,17 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL --- ### Requirement: A repository without a remote can opt into its local default branch -`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. It SHALL find the IDD configuration by walking up from the repository's top level: at each directory, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory or at `/`, and SHALL use the first file found. The key it looks up is the path of the repository's top level relative to the directory that holds that `.claude/` directory, with both paths resolved through symbolic links; a key in the file SHALL match when it names the same path after `.` and `..` segments and a trailing `/` are normalised, and `.` names the directory of the configuration itself. It SHALL print one JSON line and exit as follows: +`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree, the directory that holds the repository's common `.git` directory; otherwise its top level. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. It SHALL print one JSON line and exit as follows: -- `remote` (exit 0) when no configuration file is found, when the file has no `spec_archive` field, or when `spec_archive` has no entry for the key. Callers then read the default branch as the remote has it, as before. -- `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at), `config` and `key`, when the entry is `{"ref": "local", "branch": ""}`, the repository has no remote at all (`git remote` lists nothing), and the branch exists. -- `error` (exit 2), with a `reason`, when the file found cannot be read as a JSON object; when `spec_archive` is not an object; when the entry is not an object, its `ref` is not `local`, or its `branch` is missing, empty, not a string or starts with `-`; when the repository has any remote; when the branch does not exist; or when `` is not inside a git repository. +- `remote` (exit 0), with a `reason`, when no configuration file is found; when the file found cannot be read as a JSON object (it is empty, `null`, not JSON, not valid UTF-8, or nested too deeply; a UTF-8 byte order mark is read as usual); when the file has no `spec_archive` field; or when `spec_archive` has no entry for the key. Callers then read the default branch as the remote has it, as before; a repository without any remote then stops there, with this reason. +- `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at, whatever `HEAD` is), `config` and `key`, when exactly one entry matches the key, it is `{"ref": "local", "branch": ""}`, the repository has no remote, and the branch exists. +- `error` (exit 2), with a `reason`, when `spec_archive` is not an object; when more than one key matches; when the matching entry is not an object, its `ref` is not `local`, or its `branch` is missing, not a string, or not a valid branch name (`git check-ref-format --branch` must accept it unchanged, so revision syntax such as `master~1` or `master@{0}` is refused); when the repository has a remote; when the branch does not exist; or when `` is not inside a git repository. -The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. +A repository has a remote when any `remote..url` is set in the git configuration it reads; a `remote` section without a URL (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. -`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the tag `idd--baseline` when that tag exists and is an ancestor of `HEAD` (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message contains `#` not followed by another digit (`from: first-commit`). It SHALL print `error` (exit 2) when neither exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. +`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does first, and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would, without reading ``. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the baseline tag when that tag exists and is an ancestor of `HEAD` (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message contains `#` with no letter, digit, `_`, `/` or `-` right before the `#` and no digit after the number, the rule of `references/pr-issue-matching.md` (`from: first-commit`). The baseline tag is the configuration's `auto_tag.baseline_format` with `{N}` replaced by ``, or `idd--baseline` when that field is absent or not a string containing `{N}`. Commit messages SHALL be read so that no byte a message can hold hides a commit. It SHALL print `error` (exit 2) when neither base exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits; an empty `` is a usage error (exit 64), like any empty argument of `spec-change.py`. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. -`references/spec-wrapper.md` step 5 SHALL ask `link-base` first and use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote`, and SHALL stop when it prints `error` or nothing a JSON reader can take. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. +`references/spec-wrapper.md` step 5 SHALL ask `link-base` first, with the issue number taken from `NUMBER`, or from `N` when `NUMBER` is empty, and SHALL use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote`, and SHALL stop with the reason when it prints `error` or nothing a JSON reader can take, without also printing the message about a failed fetch. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. #### Scenario: An entry for a repository that later gained a remote @@ -421,7 +423,16 @@ The repository having a remote turns an entry into an error, not a silent `remot | `spec_archive` names this path | `{"ref": "remote", "branch": "master"}` | no remote | `error` | | `spec_archive` names this path | `{"ref": "local"}` | no remote | `error` | | `spec_archive` is a list | — | no remote | `error` | -| the file is not JSON | — | no remote | `error` | +| the file is not JSON | — | no remote | `remote`, saying the file could not be read | +| the file is empty, or holds `null` | — | no remote | `remote` | +| the file starts with a UTF-8 byte order mark | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path as `sub` and as `./sub/` | both `{"ref": "local", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master~1"}` | no remote | `error`, not a branch name | +| `spec_archive` names this path as ` sub` | `{"ref": "local", "branch": "master"}` | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote; the global git configuration has `[remote "origin"]` with only `prune = true` | `local` | +| `spec_archive` names the main working tree | `{"ref": "local", "branch": "master"}` | asked from a linked worktree of it | `local` | +| the new file without `spec_archive`, the legacy file beside it with an entry | — | no remote | `remote` (the new file wins) | +| a file above the home directory with an entry | — | no remote | `remote` (not read) | ##### Example: where the local link check starts @@ -432,3 +443,8 @@ The repository having a remote turns an entry into an error, not a silent `remot | no tag; the only commit naming a 14 says `#142` | `error` | | no tag; the first commit with `#14` is the root commit | `error` | | the repository is not opted in | `remote` | +| the repository is not opted in, `--issue abc` | `remote` | +| no tag; commits `base`, `see o/r#14`, `x#14`, `fix (#14)` | `ok`, the parent of `fix (#14)` | +| tag `idd-14-baseline` on a commit that is not an ancestor of `HEAD`; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | +| `auto_tag.baseline_format` is `start-{N}`, tag `start-14` on an ancestor | `ok`, that tag's commit, `from: baseline-tag` | +| no tag; a commit before `a (#14)` has the byte 0x1e in its message | `ok`, the parent of `a (#14)` | From 2392385be13aeaaf1b54a1c08113081a6e1da0d0 Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 14:08:37 +0800 Subject: [PATCH 06/13] =?UTF-8?q?fix:=20spec=5Farchive=20verify=20round=20?= =?UTF-8?q?2=20=E2=80=94=20owner/repo#N=20for=20the=20issue=20repository,?= =?UTF-8?q?=20no=20fallback=20to=20.,=20signature-proof=20log=20(#547)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit link-base also counts the issue repository's own owner/repo#N (github_repo of the configuration): a separate code repository names its issues that way, and the pr-issue-matching left guard alone never found a base for this layout. git log runs with --no-show-signature and "--", and every id it reads must be hexadecimal. A baseline tag on HEAD itself is skipped. archive-ref no longer falls back to "." when the repository's path cannot be a key, counts pushurl-only and legacy remotes, keys a --separate-git-dir repository by its top level, keeps a trailing space in a path, refuses a key written twice, and names the configuration relative to the repository. idd-close and spec-wrapper read JSON with python3 -I and label archive-ref's reasons as such. Tests run the step-5 block, log the git calls behind --skip-branches, and check the reasons. Refs #547 Co-Authored-By: Claude Opus 5.5 --- openspec/changes/idd-547-fix2/.openspec.yaml | 3 + openspec/changes/idd-547-fix2/proposal.md | 45 ++++++ .../specs/spec-on-every-issue/spec.md | 71 ++++++++ openspec/changes/idd-547-fix2/tasks.md | 15 ++ plugins/issue-driven-dev/CHANGELOG.md | 3 +- .../references/config-protocol.md | 4 +- .../references/spec-wrapper.md | 10 +- .../issue-driven-dev/scripts/spec-change.py | 151 +++++++++++++----- .../scripts/tests/check-existing-work/test.sh | 28 +++- .../scripts/tests/spec-archive-local/test.sh | 65 ++++++++ .../scripts/tests/spec-close-gate/test.sh | 10 ++ .../skills/idd-close/SKILL.md | 20 +-- 12 files changed, 361 insertions(+), 64 deletions(-) create mode 100644 openspec/changes/idd-547-fix2/.openspec.yaml create mode 100644 openspec/changes/idd-547-fix2/proposal.md create mode 100644 openspec/changes/idd-547-fix2/specs/spec-on-every-issue/spec.md create mode 100644 openspec/changes/idd-547-fix2/tasks.md diff --git a/openspec/changes/idd-547-fix2/.openspec.yaml b/openspec/changes/idd-547-fix2/.openspec.yaml new file mode 100644 index 00000000..f483aa4c --- /dev/null +++ b/openspec/changes/idd-547-fix2/.openspec.yaml @@ -0,0 +1,3 @@ +schema: spec-driven +created: 2026-11-14 +created_by: che cheng diff --git a/openspec/changes/idd-547-fix2/proposal.md b/openspec/changes/idd-547-fix2/proposal.md new file mode 100644 index 00000000..cbe56eb5 --- /dev/null +++ b/openspec/changes/idd-547-fix2/proposal.md @@ -0,0 +1,45 @@ +**GitHub-side tracker**: #547(第 2 輪 verify:comment 6872782744;本輪計畫:comment 6872785819) + +## Problem + +第 2 輪 verify 找到 1 項 Blocking:issue repo 與程式 repo 分開時,程式 repo 的 commit 以 `owner/repo#N` 引用 issue,`link-base` 的左邊界把這種寫法排除,本機模式的連結檢查起點永遠找不到。另有 19 項 In-scope fix:`git log` 沒關簽章顯示也沒分隔路徑、key 當不了時退回 `.`(放寬方向)、remote 的判定漏了 pushurl 與舊式檔案、baseline tag 可以就在 HEAD、`spec_archive` 字面重複的 key 被吞掉、原因文字帶絕對路徑與錯誤的標籤,以及幾項測試沒有真正測到 Example。 + +## Root Cause + +第 1 輪把 `#N` 的判斷照搬 `pr-issue-matching.md`,那份契約是給「PR 與 issue 在同一個 repo」用的;這個功能的前提正好是兩個 repo 分開。其餘是邊界沒有逐一列出。 + +## Proposed Solution + +修改 `spec-on-every-issue`「A repository without a remote can opt into its local default branch」(見 specs/),照著改 `spec-change.py`、idd-close Step 1.5/1.57、spec-wrapper 第 5 步、config-protocol,並補測試。 + +## Non-Goals + +- 設定檔的擁有者與權限檢查、`idd-all`/`idd-implement` 的 `unknown` 雜訊、`origin` 被 git 當成路徑:Follow-up。 +- ASSUMPTION: 不升版號。 + +## Success Criteria + +- 新的測試在改程式之前失敗,改之後通過;run-all-tests 全過;links 回 ok。 + +## Capabilities + +### New Capabilities + +(none) + +### Modified Capabilities + +- `spec-on-every-issue`: 「A repository without a remote can opt into its local default branch」。 + +## Impact + +- Affected specs: spec-on-every-issue(MODIFIED 一條) +- Affected code: + - Modified: plugins/issue-driven-dev/scripts/spec-change.py + - Modified: plugins/issue-driven-dev/skills/idd-close/SKILL.md + - Modified: plugins/issue-driven-dev/references/spec-wrapper.md + - Modified: plugins/issue-driven-dev/references/config-protocol.md + - Modified: plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh + - Modified: plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh + - Modified: plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh + - Modified: plugins/issue-driven-dev/CHANGELOG.md diff --git a/openspec/changes/idd-547-fix2/specs/spec-on-every-issue/spec.md b/openspec/changes/idd-547-fix2/specs/spec-on-every-issue/spec.md new file mode 100644 index 00000000..bf89c0df --- /dev/null +++ b/openspec/changes/idd-547-fix2/specs/spec-on-every-issue/spec.md @@ -0,0 +1,71 @@ +## MODIFIED Requirements + +### Requirement: A repository without a remote can opt into its local default branch + +`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree (its git directory differs from the common git directory), the directory that holds the common `.git` directory; otherwise its top level, including a repository made with `--separate-git-dir`. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. When the repository's own path cannot be written as a key (it has leading or trailing whitespace), the answer is `remote`; it SHALL NOT fall back to `.`. Reasons name the configuration file by its path relative to the repository, not by an absolute path. It SHALL print one JSON line and exit as follows: + +- `remote` (exit 0), with a `reason`, when no configuration file is found; when the file found cannot be read as a JSON object (it is empty, `null`, not JSON, not valid UTF-8, or nested too deeply; a UTF-8 byte order mark is read as usual); when the file has no `spec_archive` field; when `spec_archive` has no entry for the key; or when the repository's path cannot be written as a key. Callers then read the default branch as the remote has it, as before; a repository without any remote then stops there, with this reason. +- `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at, whatever `HEAD` is), `config` and `key`, when exactly one entry matches the key, it is `{"ref": "local", "branch": ""}`, the repository has no remote, and the branch exists. +- `error` (exit 2), with a `reason`, when `spec_archive` is not an object; when more than one key matches, including the same key written twice in the file; when the matching entry is not an object, its `ref` is not `local`, or its `branch` is missing, not a string, or not a valid branch name (`git check-ref-format --branch` must accept it unchanged, so revision syntax such as `master~1` or `master@{0}` is refused); when the repository has a remote; when the branch does not exist; or when `` is not inside a git repository. + +A repository has a remote when `git remote` lists a name that has a `url` or a `pushurl` in the git configuration it reads, or a legacy `remotes/` or `branches/` file in its git directory; a `remote` section without either (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. + +`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does first, and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would, without reading ``. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the baseline tag when that tag exists and is an ancestor of `HEAD` other than `HEAD` itself (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message names issue ``: `#` with no letter, digit, `_`, `/` or `-` right before the `#`, the rule of `references/pr-issue-matching.md`, or `/#` where `/` is the configuration's `github_repo` (letter case ignored), the form a commit in a separate code repository uses for the issue repository's issues; in both forms no digit follows the number (`from: first-commit`). `/#` for any other repository does not count. The baseline tag is the configuration's `auto_tag.baseline_format` with `{N}` replaced by ``, or `idd--baseline` when that field is absent, not a string containing `{N}`, or does not give a valid tag name. Commit messages SHALL be read so that no byte a message can hold hides a commit, with signature display turned off and `HEAD` separated from paths, and every commit and parent read SHALL be a hexadecimal object id. It SHALL print `error` (exit 2) when neither base exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits; an empty `` is a usage error (exit 64), like any empty argument of `spec-change.py`. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. + +`references/spec-wrapper.md` step 5 SHALL ask `link-base` first, with the issue number taken from `NUMBER`, or from `N` when `NUMBER` is empty, and SHALL use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote`, and SHALL stop with the reason when it prints `error` or nothing a JSON reader can take, without also printing the message about a failed fetch. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. + +#### Scenario: An entry for a repository that later gained a remote + +- **GIVEN** a configuration entry `{"ref": "local", "branch": "master"}` for a repository +- **AND** a remote was added to that repository afterwards +- **WHEN** `archive-ref` runs for it +- **THEN** it prints `error` and names the remote, instead of reading the local branch + +##### Example: how a spec_archive entry resolves + +| Configuration found | Entry for the repository's path | Repository | `archive-ref` | +| --- | --- | --- | --- | +| none | — | no remote | `remote` | +| a file without `spec_archive` | — | no remote | `remote` | +| `spec_archive` names another path only | — | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local`, `master` and its commit | +| `spec_archive` names this path as `./sub/` | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | has a remote `origin` | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "trunk"}` | no remote, no branch `trunk` | `error` | +| `spec_archive` names this path | `{"ref": "remote", "branch": "master"}` | no remote | `error` | +| `spec_archive` names this path | `{"ref": "local"}` | no remote | `error` | +| `spec_archive` is a list | — | no remote | `error` | +| the file is not JSON | — | no remote | `remote`, saying the file could not be read | +| the file is empty, or holds `null` | — | no remote | `remote` | +| the file starts with a UTF-8 byte order mark | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path as `sub` and as `./sub/` | both `{"ref": "local", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master~1"}` | no remote | `error`, not a branch name | +| `spec_archive` names this path as ` sub` | `{"ref": "local", "branch": "master"}` | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote; the global git configuration has `[remote "origin"]` with only `prune = true` | `local` | +| `spec_archive` names the main working tree | `{"ref": "local", "branch": "master"}` | asked from a linked worktree of it | `local` | +| the new file without `spec_archive`, the legacy file beside it with an entry | — | no remote | `remote` (the new file wins) | +| a file above the home directory with an entry | — | no remote | `remote` (not read) | +| `spec_archive` has `.` | `{"ref": "local", "branch": "master"}` | another repository below, whose directory name ends in a space | `remote` (no fallback to `.`) | +| `spec_archive` names this path twice, written as the same key | `{"ref": "local", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has a `pushurl` and no `url` | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | a legacy `remotes/origin` file in its git directory | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | made with `--separate-git-dir` | `local`, keyed by its top level | + +##### Example: where the local link check starts + +| Repository (opted into local `master`) | `link-base --issue 14` | +| --- | --- | +| tag `idd-14-baseline` on an ancestor of `HEAD` | `ok`, the tag's commit, `from: baseline-tag` | +| no tag; commits `base`, `a (#14)`, `b (Refs #14)` | `ok`, the commit `base`, `from: first-commit` | +| no tag; the only commit naming a 14 says `#142` | `error` | +| no tag; the first commit with `#14` is the root commit | `error` | +| the repository is not opted in | `remote` | +| the repository is not opted in, `--issue abc` | `remote` | +| no tag; commits `base`, `see o/r#14`, `x#14`, `fix (#14)` | `ok`, the parent of `fix (#14)` | +| tag `idd-14-baseline` on a commit that is not an ancestor of `HEAD`; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | +| `auto_tag.baseline_format` is `start-{N}`, tag `start-14` on an ancestor | `ok`, that tag's commit, `from: baseline-tag` | +| no tag; a commit before `a (#14)` has the byte 0x1e in its message | `ok`, the parent of `a (#14)` | +| `github_repo` is `o/issues`; no tag; commits `base`, `see other/r#14`, `fix (O/ISSUES#14)` | `ok`, the parent of `fix (O/ISSUES#14)` | +| tag `idd-14-baseline` on `HEAD` itself; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | +| `log.showSignature` is on and a commit before `a (#14)` is signed | `ok`, the parent of `a (#14)` | +| a file named `HEAD` at the repository's top level; no tag; commits `base`, `a (#14)` | `ok`, the commit `base` | diff --git a/openspec/changes/idd-547-fix2/tasks.md b/openspec/changes/idd-547-fix2/tasks.md new file mode 100644 index 00000000..054cdfa2 --- /dev/null +++ b/openspec/changes/idd-547-fix2/tasks.md @@ -0,0 +1,15 @@ +## 1. 測試先行 + +- [x] 1.1 requirement「A repository without a remote can opt into its local default branch」— spec-archive-local:Example「how a spec_archive entry resolves」與「where the local link check starts」新增的各列(`.` 不再是退路、字面重複的 key、只有 pushurl、舊式 remotes 檔、separate-git-dir、`github_repo` 的 `owner/repo#N`、tag 在 HEAD、簽章、名為 HEAD 的檔),帶兩個既有標記。驗證:改之前新的列失敗。 +- [x] 1.2 check-existing-work:`--skip-branches` 不跑 fetch、不讀 tracking ref(git shim 記錄呼叫,tracking ref 不產生 E4);既有 Step 1.5 列設 HOME;Step 1.5 在 archive-ref 回 error 時不帶旗標;拿掉永遠不會失敗的斷言。驗證:帶旗標仍 fetch 的變異會失敗。 +- [x] 1.3 spec-close-gate:「沒有條目」列驗原因含「default branch could not be read」;與設定無關的錯誤標 `archive-ref:`;原因不含設定檔的絕對路徑。 + +## 2. 程式與文件 + +- [x] 2.1 `spec-change.py` 照 requirement 改。驗證:1.1 通過;spec-change suite 照舊。 +- [x] 2.2 idd-close Step 1.5/1.57(`python3 -I`、原因標籤、error 表說明)、spec-wrapper 第 5 步(`python3 -I`、說明文字)。驗證:1.2、1.3 通過;spec-wrapper-contract 照舊。 +- [x] 2.3 config-protocol 的矛盾句與新規則、CHANGELOG。 + +## 3. 收尾 + +- [ ] 3.1 run-all-tests.sh 與連結檢查。驗證:結束碼 0,links 回 ok。 diff --git a/plugins/issue-driven-dev/CHANGELOG.md b/plugins/issue-driven-dev/CHANGELOG.md index 9e30c4b0..119c9fad 100644 --- a/plugins/issue-driven-dev/CHANGELOG.md +++ b/plugins/issue-driven-dev/CHANGELOG.md @@ -21,7 +21,8 @@ Version number left to the release. repository has no remote at all (a remote with a URL); with a remote it is an error, never a silent fallback. Without an entry nothing changes, and a configuration file that cannot be read as a JSON object counts as having no entry, so it does not block a repository that never set the field. The branch must be a branch name, and the - check reads it whatever `HEAD` is; a linked worktree uses its main working tree's key. New `spec-change.py` + check reads it whatever `HEAD` is; a linked worktree uses its main working tree's key. The link check finds the + issue in a separate code repository's commits written as `owner/repo#N` for the configured `github_repo`. New `spec-change.py` subcommands `archive-ref` and `link-base`; documented in `config-protocol.md`. ### Fixed diff --git a/plugins/issue-driven-dev/references/config-protocol.md b/plugins/issue-driven-dev/references/config-protocol.md index 38634bac..e4c1f7fa 100644 --- a/plugins/issue-driven-dev/references/config-protocol.md +++ b/plugins/issue-driven-dev/references/config-protocol.md @@ -503,13 +503,13 @@ Which branch the spec checks read for a code repository that **deliberately has Read by `scripts/spec-change.py archive-ref` (and `link-base`), which walks up from the **code repository's** main working tree to the first IDD configuration — the same walk as the other fields, new file before legacy file at each level, stopping after `$HOME` (`/` itself is not read). A file that cannot be read as a JSON object (empty, `null`, not JSON, not UTF-8) is treated as having no entry, so a repository that never set the field is not blocked by it; a repository without a remote then stops at the fetch, with that reason. Write the entry in the issue repository's configuration; do not add a configuration to the code repository just for this, because a file without `github_repo` there would be the first one the other skills find. -**Accepted only while the repository has no remote at all** — no `remote..url` in the git configuration it reads; a `remote` section without a URL (a global `remote.origin.prune`, say) does not count. An entry for a repository that has any remote is an error, not a silent fallback to the remote: an entry written because there was no remote must not outlive that reason. Other errors: the file is not a JSON object, `spec_archive` is not an object, the entry is not `{"ref": "local", "branch": ""}`, or the branch does not exist. +**Accepted only while the repository has no remote at all** — no name that `git remote` lists with a `url` or `pushurl`, and no legacy `remotes/` or `branches/` file in its git directory; a `remote` section with neither (a global `remote.origin.prune`, say) does not count. An entry for a repository that has any remote is an error, not a silent fallback to the remote: an entry written because there was no remote must not outlive that reason. Other errors: `spec_archive` is not an object, two entries (or the same key written twice) name the repository's path, the entry is not `{"ref": "local", "branch": ""}`, or the branch does not exist. A repository whose own path cannot be written as a key (it ends in a space, say) gets no entry: it never borrows the `.` entry of the configuration's own directory. Reasons name the configuration file relative to the code repository, never by an absolute path. What it changes, and nothing else: - `idd-close` Step 1.57 checks the archive on `refs/heads/` instead of fetching, and prints `local ref @`. - `idd-close` Step 1.5 calls `check-existing-work.sh --skip-branches`: no fetch in the code repository, open PRs still checked on the issue repository. -- `references/spec-wrapper.md` step 5 starts the link check at the issue's baseline tag (`auto_tag.baseline_format`, default `idd--baseline`) when it is an ancestor of `HEAD`, or else at the parent of the oldest commit naming `#` (the left and right guards of `pr-issue-matching.md`, so `other/repo#N` does not count); neither → stop. +- `references/spec-wrapper.md` step 5 starts the link check at the issue's baseline tag (`auto_tag.baseline_format`, default `idd--baseline`) when it is an ancestor of `HEAD` other than `HEAD` itself, or else at the parent of the oldest commit naming the issue: `#` with the left and right guards of `pr-issue-matching.md`, or the issue repository's own `#` — the form a commit in a separate code repository uses (`other/repo#N` does not count); neither → stop. A code repository that is not under the issue repository's directory finds no entry and keeps the remote behaviour (and its error). diff --git a/plugins/issue-driven-dev/references/spec-wrapper.md b/plugins/issue-driven-dev/references/spec-wrapper.md index 7ef81127..38a50a67 100644 --- a/plugins/issue-driven-dev/references/spec-wrapper.md +++ b/plugins/issue-driven-dev/references/spec-wrapper.md @@ -132,18 +132,18 @@ fi # The issue number: NUMBER in the skills that call this contract, N in idd-all. A remote repository never reads it. ISSUE_N="${NUMBER:-${N:-}}" LB=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" link-base --cwd "$CWD" --issue "${ISSUE_N:-none}" 2>/dev/null) -LB_STATUS=$(printf '%s' "$LB" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("status", ""))' 2>/dev/null) +LB_STATUS=$(printf '%s' "$LB" | python3 -I -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("status", ""))' 2>/dev/null) SPEC_BASE="" if [ "$LB_STATUS" = ok ]; then - SPEC_BASE=$(printf '%s' "$LB" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read()).get("base", ""))') - printf '%s' "$LB" | python3 -c 'import json,sys; d=json.loads(sys.stdin.read()); print("→ link check from %s (%s; spec_archive local mode)" % (d["base"][:7], d["from"]))' + SPEC_BASE=$(printf '%s' "$LB" | python3 -I -c 'import json,sys; print(json.loads(sys.stdin.read()).get("base", ""))') + printf '%s' "$LB" | python3 -I -c 'import json,sys; d=json.loads(sys.stdin.read()); print("→ link check from %s (%s; spec_archive local mode)" % (d["base"][:7], d["from"]))' elif [ "$LB_STATUS" = remote ]; then DEFAULT_BRANCH=$(gh repo view "$GITHUB_REPO" --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null) || DEFAULT_BRANCH="" if [ -n "$DEFAULT_BRANCH" ] && git -C "$CWD" fetch -q origin -- "$DEFAULT_BRANCH" 2>/dev/null; then SPEC_BASE=$(git -C "$CWD" merge-base HEAD FETCH_HEAD 2>/dev/null) fi else - echo "✗ spec close-out: spec_archive: $(printf '%s' "$LB" | python3 -c 'import json,sys + echo "✗ spec close-out: archive-ref: $(printf '%s' "$LB" | python3 -I -c 'import json,sys try: print(json.loads(sys.stdin.read()).get("reason", "") or "link-base printed nothing readable") except Exception: print("link-base printed nothing readable")' 2>/dev/null); stopping" >&2 fi @@ -154,7 +154,7 @@ elif [ "$LB_STATUS" = remote ]; then fi ``` -`git merge-base HEAD FETCH_HEAD`(剛從遠端 fetch 的預設 branch)在 PR path 是分岔點;在 direct-commit path 是 run 還沒推的 commit 之前那一個。程式 repo 沒有 remote、用 `spec_archive` 指到本機 branch 時(#547,見 `config-protocol.md`),沒有「還沒推的 commit」這條界線,起點改由 `link-base` 給:這張 issue 的 `idd--baseline` tag(是 HEAD 的祖先時),否則 HEAD 歷史裡第一個訊息含 `#`(後面不接數字)的 commit 的父 commit;兩者都沒有就停下,不退回 `merge-base`(direct-commit 時那是 HEAD,範圍是空的)。沒有印出 JSON(`SPEC_BASE` 取不到)就停下回報。`missing` 就補測試或標記再跑一次。要改的是 requirement 本身(例如寫了一個寫不出檢查的 Example)時,不改 `archive/` 底下的檔案,也不繞過 Spectra 直接改主規格:照第 7 步另建一個 change 修改那條 requirement,封存後再跑。`error` 停下回報。 +`git merge-base HEAD FETCH_HEAD`(剛從遠端 fetch 的預設 branch)在 PR path 是分岔點;在 direct-commit path 是 run 還沒推的 commit 之前那一個。程式 repo 沒有 remote、用 `spec_archive` 指到本機 branch 時(#547,見 `config-protocol.md`),沒有「還沒推的 commit」這條界線,起點改由 `link-base` 給:這張 issue 的 baseline tag(`auto_tag.baseline_format`,預設 `idd--baseline`;是 HEAD 的祖先、而且不是 HEAD 本身時),否則 HEAD 歷史裡第一個引用這張 issue 的 commit 的父 commit——引用指 `#`(左右邊界同 `pr-issue-matching.md`),或設定檔 `github_repo` 那個 repo 的 `/#`(程式 repo 與 issue repo 分開時 commit 就是這樣寫的);兩者都沒有就停下,不退回 `merge-base`(direct-commit 時那是 HEAD,範圍是空的)。沒有設定的 repo,`link-base` 回 `remote`、不讀 issue 號,照舊 fetch。沒有印出 JSON(`SPEC_BASE` 取不到)就停下回報。`missing` 就補測試或標記再跑一次。要改的是 requirement 本身(例如寫了一個寫不出檢查的 Example)時,不改 `archive/` 底下的檔案,也不繞過 Spectra 直接改主規格:照第 7 步另建一個 change 修改那條 requirement,封存後再跑。`error` 停下回報。 6. 確認宣告與 HEAD 一致:把第 6 步要貼的 `**Spec**:` 行寫進一個暫存檔,跑 `python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archived --file <暫存檔> --cwd "$CWD" --ref HEAD`,要 `pass`。 diff --git a/plugins/issue-driven-dev/scripts/spec-change.py b/plugins/issue-driven-dev/scripts/spec-change.py index e866f393..5af8d2ff 100755 --- a/plugins/issue-driven-dev/scripts/spec-change.py +++ b/plugins/issue-driven-dev/scripts/spec-change.py @@ -135,7 +135,7 @@ def repo_top(cwd): p = git(cwd, "rev-parse", "--show-toplevel", check=False) if p.returncode != 0: raise Fail(f"{cwd} is not inside a git repository") - return p.stdout.decode("utf-8").strip() + return p.stdout.decode("utf-8").rstrip("\n") # a path may end in a space: only the newline goes SPEC_DIR_RE = re.compile(r"^spec_dir:(.*)$") @@ -575,6 +575,7 @@ def cmd_plan(argv): CONFIG_NAMES = (os.path.join(".claude", ".idd", "local.json"), os.path.join(".claude", "issue-driven-dev.local.json")) ISSUE_REF_RE = r"(? or branches/ file in the git directory. A section with neither (remote.origin.prune) is no remote.""" + gd = os.path.join(top, git_text(top, "rev-parse", "--git-common-dir").rstrip("\n")) + names = set(n for n in git_text(top, "remote").splitlines() if n) + for d in ("remotes", "branches"): # legacy files: newer git no longer lists them, fetch may still read them + try: + names.update(f for f in os.listdir(os.path.join(gd, d)) if os.path.isfile(os.path.join(gd, d, f))) + except OSError: + pass + out = [] + for name in names: + has = any(git(top, "config", "--get-all", f"remote.{name}.{k}", check=False).stdout.strip() + for k in ("url", "pushurl")) + has = has or any(os.path.isfile(os.path.join(gd, d, name)) for d in ("remotes", "branches")) + if has: + out.append(name) + return sorted(out) def archive_ref(cwd): @@ -642,38 +677,43 @@ def archive_ref(cwd): path, root = find_config(tree) if path is None: return {"status": "remote", "reason": "no IDD configuration found above the repository"} - data, why = read_config(path) + shown = rel_to(path, tree) # messages name the file as seen from the repository + data, why = read_config(path, shown) if data is None: return {"status": "remote", "reason": why} if "spec_archive" not in data: - return {"status": "remote", "reason": f"{path} has no spec_archive field"} + return {"status": "remote", "reason": f"{shown} has no spec_archive field"} table = data["spec_archive"] if not isinstance(table, dict): - raise Fail(f"spec_archive in {path} must be an object keyed by repository path") - key = norm_key(os.path.relpath(tree, root)) or "." - entries = [v for k, v in table.items() if norm_key(k) == key] + raise Fail(f"spec_archive in {shown} must be an object keyed by repository path") + rel = os.path.relpath(tree, root) + key = norm_key(rel) + if key is None: # never fall back to "." (that is another directory's entry) + return {"status": "remote", "reason": f"this repository's path {rel!r} cannot be written as a spec_archive key"} + dup = [k for k in table.get("\x00duplicate-keys", []) if norm_key(k) == key] + entries = [v for k, v in table.items() if not k.startswith("\x00") and norm_key(k) == key] if not entries: - return {"status": "remote", "reason": f"spec_archive in {path} has no entry for {key}"} - if len(entries) > 1: - raise Fail(f"spec_archive in {path} has more than one entry for {key}") + return {"status": "remote", "reason": f"spec_archive in {shown} has no entry for {key}"} + if len(entries) > 1 or dup: + raise Fail(f"spec_archive in {shown} has more than one entry for {key}") entry = entries[0] if not isinstance(entry, dict) or entry.get("ref") != "local": - raise Fail(f"spec_archive[{key!r}] in {path}: only {{\"ref\": \"local\", \"branch\": \"\"}} is supported") + raise Fail(f"spec_archive[{key!r}] in {shown}: only {{\"ref\": \"local\", \"branch\": \"\"}} is supported") branch = entry.get("branch") if (not isinstance(branch, str) or not branch or branch.startswith("-") or any(ord(c) < 32 or ord(c) == 127 for c in branch)): - raise Fail(f"spec_archive[{key!r}] in {path} needs a branch name") + raise Fail(f"spec_archive[{key!r}] in {shown} needs a branch name") fmt = git(top, "check-ref-format", "--branch", branch, check=False) if fmt.returncode != 0 or fmt.stdout.decode("utf-8", "replace").strip() != branch: - raise Fail(f"spec_archive[{key!r}] in {path}: {branch!r} is not a branch name") + raise Fail(f"spec_archive[{key!r}] in {shown}: {branch!r} is not a branch name") remotes = remotes_of(top) if remotes: - raise Fail(f"spec_archive[{key!r}] in {path} asks for the local branch, but this repository has a remote " + raise Fail(f"spec_archive[{key!r}] in {shown} asks for the local branch, but this repository has a remote " f"({', '.join(remotes)}); the local branch is accepted only for a repository without any remote") p = git(top, "rev-parse", "--verify", "--quiet", f"refs/heads/{branch}^{{commit}}", check=False) if p.returncode != 0: - raise Fail(f"spec_archive[{key!r}] in {path} names the branch {branch!r}, which does not exist here") - return {"status": "local", "branch": branch, "ref": p.stdout.decode("utf-8").strip(), "config": path, "key": key} + raise Fail(f"spec_archive[{key!r}] in {shown} names the branch {branch!r}, which does not exist here") + return {"status": "local", "branch": branch, "ref": p.stdout.decode("utf-8").strip(), "config": path, "config_shown": shown, "key": key} def cmd_archive_ref(argv): @@ -685,12 +725,29 @@ def cmd_archive_ref(argv): return emit(out, 0) -def baseline_tag(config_path, n): - data, _ = read_config(config_path) - fmt = ((data or {}).get("auto_tag") or {}).get("baseline_format") if isinstance((data or {}).get("auto_tag"), dict) else None - if not isinstance(fmt, str) or "{N}" not in fmt: - fmt = "idd-{N}-baseline" - return fmt.replace("{N}", n) +def config_of(config_path): + data, _ = read_config(config_path, "") + return data or {} + + +def baseline_tag(top, data, n): + at = data.get("auto_tag") + fmt = at.get("baseline_format") if isinstance(at, dict) else None + if isinstance(fmt, str) and "{N}" in fmt: + name = fmt.replace("{N}", n) + if git(top, "check-ref-format", f"refs/tags/{name}", check=False).returncode == 0: + return name + return f"idd-{n}-baseline" + + +def names_issue(data, n): + """A regex for a commit message that names issue n: #n with the pr-issue-matching guards, or the issue + repository's own owner/repo#n (the form a separate code repository uses).""" + parts = [ISSUE_REF_RE % n] + gh = data.get("github_repo") + if isinstance(gh, str) and re.fullmatch(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+", gh): + parts.append(r"(?&1); CLOSE_RC=$? assert_eq "idd-close: an issue the lookup could not read does not pass the PR gate" 1 "$CLOSE_RC" assert_grep "idd-close: and says why" "refusing to close" "$CLOSE_OUT" @@ -264,7 +264,6 @@ printf 'EWNOTES=%s\\n' \"\$(printf '%s' \"\$EW_JSON\" | jq -c '.notes // []')\" printf 'OPENPRS=%s\\n' \"\$(printf '%s' \"\$OPEN_PRS\" | jq -c '[.[].number]')\"" 2>&1) assert_grep "idd-close: in a repository opted into its local branch, Step 1.5 says the branch lookup was skipped" \ "branch lookup skipped" "$OPT_OUT" -refute_grep "idd-close: … and the helper did not report a failed fetch" "git fetch failed" "$OPT_OUT" NOPT_OUT=$(HOME="$W" CLAUDE_PLUGIN_ROOT="$HERE/../../.." WORKDIR="$BR" GITHUB_REPO=test/repo NUMBER=61 PATH="$W/bin:$PATH" \ bash -c "$(snippet "$CSEC") printf 'EWNOTES=%s\\n' \"\$(printf '%s' \"\$EW_JSON\" | jq -c '.notes // []')\"" 2>&1) @@ -278,6 +277,31 @@ assert_eq "idd-close: … and the open PR declaring the issue still reaches the assert_eq "idd-close: not opted in → the helper ran without the flag (no notes)" "[]" \ "$(printf '%s\n' "$NOPT_OUT" | sed -n 's/^EWNOTES=//p')" runin --cwd "$NR" --cwd "$BR" test/repo 61 >/dev/null; RC_DUP=$? +# idd-547-fix2: a logging git in front of the real one shows what the helper ran. +REALGIT=$(command -v git); mkdir -p "$W/gitlog" +printf '#!/bin/sh\necho "$*" >> "%s/gitlog/calls"\nexec "%s" "$@"\n' "$W" "$REALGIT" > "$W/gitlog/git" +python3 -c 'import os,sys; os.chmod(sys.argv[1], 0o755)' "$W/gitlog/git" +TR="$W/tracked"; git "${GIT_ENV[@]}" clone -q "$W/origin.git" "$TR" 2>/dev/null +mkbr "idd/61-x" "work for 61" >/dev/null; git -C "$TR" fetch -q origin +reset_fx; issue 61 OPEN $ISSUE_T +: > "$W/gitlog/calls" +OUT=$(PATH="$W/gitlog:$W/bin:$PATH" bash "$SCRIPT" --cwd "$TR" --skip-branches test/repo 61 2>"$W/stderr") +refute_grep "--skip-branches runs no git fetch" "fetch" "$(cat "$W/gitlog/calls")" +refute_grep "--skip-branches lists no remote-tracking branches" "refs/remotes/origin" "$(cat "$W/gitlog/calls")" +assert_eq "--skip-branches: a tracking ref idd/61-x is not read as E4" "[]" "$(kinds "$OUT" 61)" +: > "$W/gitlog/calls" +OUT=$(PATH="$W/gitlog:$W/bin:$PATH" bash "$SCRIPT" --cwd "$TR" test/repo 61 2>"$W/stderr") +assert_grep "without the flag the helper fetches" "fetch" "$(cat "$W/gitlog/calls")" +assert_eq "… and reads idd/61-x as E4" "['E4']" "$(kinds "$OUT" 61)" +# archive-ref answers error (spec_archive is a list): Step 1.5 does not pass the flag +ERRP="$W/errconf"; mkdir -p "$ERRP/.claude/.idd"; git "${GIT_ENV[@]}" init -q "$ERRP/code" +( cd "$ERRP/code" && git "${GIT_ENV[@]}" commit -q --allow-empty -m init ) +printf '%s\n' '{"spec_archive": ["code"]}' > "$ERRP/.claude/.idd/local.json" +ERR_OUT=$(HOME="$W" CLAUDE_PLUGIN_ROOT="$HERE/../../.." WORKDIR="$ERRP/code" GITHUB_REPO=test/repo NUMBER=61 PATH="$W/bin:$PATH" \ + bash -c "$(snippet "$CSEC") +printf 'EWNOTES=%s\\n' \"\$(printf '%s' \"\$EW_JSON\" | jq -c '.notes // []')\"" 2>&1) +assert_eq "idd-close: archive-ref answers error → Step 1.5 does not pass --skip-branches" "[]" \ + "$(printf '%s\n' "$ERR_OUT" | sed -n 's/^EWNOTES=//p')" assert_eq "a repeated --cwd is a usage error (exit 2)" 2 "$RC_DUP" print_summary "check-existing-work" diff --git a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh index dc615e67..bcaf1ace 100755 --- a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh @@ -231,11 +231,76 @@ ar "$WORK/a4/sub" assert_eq "HEAD on another branch → ref is still master's commit" "$(git -C "$WORK/a4/sub" rev-parse master)" "$(printf '%s' "$OUT" | field ref)" git -C "$WORK/a4/sub" checkout -q master +# idd-547-fix2 rows — how a spec_archive entry resolves +mkdir -p "$WORK/c1"; conf "$WORK/c1" "{\"spec_archive\": {\".\": $OPT}}"; git init -q -b master "$WORK/c1"; git -C "$WORK/c1" commit -q --allow-empty -m base +mkrepo "$WORK/c1/odd " +ar "$WORK/c1/odd " +assert_eq "a repository whose path cannot be a key does not fall back to . → remote" remote "$ST" +mkrepo "$WORK/c2/sub"; mkdir -p "$WORK/c2/.claude/.idd" +printf '{"spec_archive": {"sub": %s, "sub": %s}}\n' "$OPT" "$OPT" > "$WORK/c2/.claude/.idd/local.json" +ar "$WORK/c2/sub" +assert_eq "the same key written twice in the file → error" error "$ST" +mkrepo "$WORK/c3/sub"; conf "$WORK/c3" "{\"spec_archive\": {\"sub\": $OPT}}"; git -C "$WORK/c3/sub" config remote.origin.pushurl "$WORK/nowhere.git" +ar "$WORK/c3/sub" +assert_eq "a remote with only a pushurl counts → error" error "$ST" +assert_grep "… naming it" "origin" "$(printf '%s' "$OUT" | field reason)" +mkrepo "$WORK/c4/sub"; conf "$WORK/c4" "{\"spec_archive\": {\"sub\": $OPT}}"; mkdir -p "$WORK/c4/sub/.git/remotes" +printf 'URL: %s\n' "$WORK/nowhere.git" > "$WORK/c4/sub/.git/remotes/origin" +ar "$WORK/c4/sub" +assert_eq "a legacy remotes/origin file counts → error" error "$ST" +mkdir -p "$WORK/c5" "$WORK/c5gd"; conf "$WORK/c5" "{\"spec_archive\": {\"sub\": $OPT}}" +git init -q -b master --separate-git-dir "$WORK/c5gd/.git" "$WORK/c5/sub"; git -C "$WORK/c5/sub" commit -q --allow-empty -m base +ar "$WORK/c5/sub" +assert_eq "a repository made with --separate-git-dir is keyed by its top level → local" local "$ST" +OUT=$(python3 "$SC" archive-ref --cwd "$WORK/a3/sub" 2>/dev/null) +refute_grep "reasons do not carry the configuration's absolute path" "$WORK/a3/.claude" "$(printf '%s' "$OUT" | field reason)" + +# idd-547-fix2 rows — where the local link check starts +B="$WORK/ld1/repo"; mkrepo "$B"; conf "$WORK/ld1" "{\"github_repo\": \"o/issues\", \"spec_archive\": {\"repo\": $OPT}}" +git -C "$B" commit -q --allow-empty -m "see other/r#14"; BEFORE=$(git -C "$B" rev-parse HEAD) +git -C "$B" commit -q --allow-empty -m "fix (O/ISSUES#14)" +lb "$B" 14 +assert_eq "github_repo o/issues: O/ISSUES#14 counts, other/r#14 does not" "$BEFORE" "$(printf '%s' "$OUT" | field base)" +B="$WORK/ld2/repo"; mkrepo "$B"; conf "$WORK/ld2" "{\"spec_archive\": {\"repo\": $OPT}}"; BASE=$(git -C "$B" rev-parse HEAD) +git -C "$B" commit -q --allow-empty -m "a (#14)"; git -C "$B" tag idd-14-baseline +lb "$B" 14 +assert_eq "a baseline tag on HEAD itself → falls back to the first commit" "$BASE" "$(printf '%s' "$OUT" | field base)" +assert_eq "… from first-commit" first-commit "$(printf '%s' "$OUT" | field from)" +B="$WORK/ld3/repo"; mkrepo "$B"; conf "$WORK/ld3" "{\"spec_archive\": {\"repo\": $OPT}}" +# A commit carrying a (fake) signature, and log.showSignature pointing at a program that leaves a sentinel +# (the pattern of merge-completeness fixture 40b). Without --no-show-signature git log runs it and prints its text. +mkdir -p "$WORK/fakegpg"; printf '#!/bin/sh\ntouch "%s/ran"\necho "gpg: Signature made by fake"\nexit 1\n' "$WORK/fakegpg" > "$WORK/fakegpg/gpg" +python3 -c 'import os,sys; os.chmod(sys.argv[1], 0o755)' "$WORK/fakegpg/gpg" +git -C "$B" commit -q --allow-empty -m signed +SIGNED=$(git -C "$B" cat-file commit HEAD | awk 'NR == 1 { print; next } !done && /^committer / { print; print "gpgsig -----BEGIN PGP SIGNATURE-----"; print " Zm9v"; print " -----END PGP SIGNATURE-----"; done = 1; next } { print }' \ + | git -C "$B" hash-object -t commit -w --stdin) +git -C "$B" update-ref refs/heads/master "$SIGNED" +git -C "$B" config log.showSignature true; git -C "$B" config gpg.program "$WORK/fakegpg/gpg" +BEFORE=$(git -C "$B" rev-parse HEAD); git -C "$B" commit -q --allow-empty -m "a (#14)" +lb "$B" 14 +assert_eq "log.showSignature on, a signed commit before → still the parent of a (#14)" "$BEFORE" "$(printf '%s' "$OUT" | field base)" +assert_exit "… and gpg.program is not run" 1 "$([ -e "$WORK/fakegpg/ran" ]; echo $?)" +B="$WORK/ld4/repo"; mkrepo "$B"; conf "$WORK/ld4" "{\"spec_archive\": {\"repo\": $OPT}}"; BASE=$(git -C "$B" rev-parse HEAD) +echo x > "$B/HEAD"; git -C "$B" add HEAD; git -C "$B" commit -q -m "a (#14)" +lb "$B" 14 +assert_eq "a file named HEAD at the top level → still ok" "$BASE" "$(printf '%s' "$OUT" | field base)" + echo "spec-archive-local: the wrapper and idd-all text" WRAP="$PLUGIN/references/spec-wrapper.md" STEP5=$(sed -n '/^## 5\. Close-out/,/^## 6\./p' "$WRAP") assert_grep "spec-wrapper step 5 asks link-base" 'spec-change.py" link-base' "$STEP5" assert_grep "… with the issue number from NUMBER or N" '${NUMBER:-${N:-}}' "$STEP5" +refute_grep "step 5's JSON readers run isolated: no python3 -c without -I (idd-547-fix2)" "python3 -c 'import json" "$STEP5" +# idd-547-fix2: run the step-5 block as written. In local mode a link-base error stops with its reason and +# does not go on to print the failed-fetch message. +printf '%s\n' "$STEP5" | awk '/^```bash$/{b=1; next} b && /^```$/{exit} b' > "$WORK/step5.sh" +S5OUT=$(cd "$WORK/lb3/repo" && env HOME="$WORK" CWD="$WORK/lb3/repo" NUMBER=14 GITHUB_REPO=o/r CLAUDE_PLUGIN_ROOT="$PLUGIN" \ + bash --norc --noprofile "$WORK/step5.sh" 2>&1 &1 /dev/null /dev/null /dev/null \ - | python3 -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("status", ""))' 2>/dev/null)" = local ]; then + | python3 -I -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("status", ""))' 2>/dev/null)" = local ]; then EW_SKIP="--skip-branches" echo "→ Step 1.5: spec_archive.ref=local — this repository has no remote; branch lookup skipped, open PRs checked on $GITHUB_REPO" fi @@ -548,7 +548,7 @@ SPEC_JSON=$(mktemp); SPEC_IC=$(mktemp) if ! { gh api "repos/$GITHUB_REPO/issues/$NUMBER/comments" --paginate > "$SPEC_JSON" 2>/dev/null \ && python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" ic --comments "$SPEC_JSON" > "$SPEC_IC"; }; then GATE='{"status": "error", "not_archived": [], "reason": "the issue comments could not be read"}'; GATE_RC=2 -elif [ "$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" declared --file "$SPEC_IC" 2>/dev/null | python3 -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("form", ""))' 2>/dev/null)" != change ]; then +elif [ "$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" declared --file "$SPEC_IC" 2>/dev/null | python3 -I -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("form", ""))' 2>/dev/null)" != change ]; then # No change declared (no comment, legacy, an exemption, an invalid line): the default branch is not read, # so a failed fetch does not hold an issue this gate does not apply to. archived answers these from the comment. GATE=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archived --file "$SPEC_IC" --cwd "${CWD:-$PWD}" --ref HEAD); GATE_RC=$? @@ -558,11 +558,11 @@ else # entry it prints remote and the default branch is read as the remote has it, as before; an entry that cannot # be honoured (the repository has a remote, the branch does not exist, ...) is an error, never a fallback. ARCH=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archive-ref --cwd "${CWD:-$PWD}" 2>/dev/null) - ARCH_STATUS=$(printf '%s' "$ARCH" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("status", ""))' 2>/dev/null) + ARCH_STATUS=$(printf '%s' "$ARCH" | python3 -I -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("status", ""))' 2>/dev/null) SPEC_REF="" if [ "$ARCH_STATUS" = local ]; then - SPEC_REF=$(printf '%s' "$ARCH" | python3 -c 'import json,sys; print(json.loads(sys.stdin.read()).get("ref", ""))' 2>/dev/null) - printf '%s' "$ARCH" | python3 -c 'import json,sys; d=json.loads(sys.stdin.read()); print("→ spec archive gate: checking local ref %s@%s (this repository has no remote; spec_archive[%r])" % (d["branch"], d["ref"][:7], d["key"]))' 2>/dev/null + SPEC_REF=$(printf '%s' "$ARCH" | python3 -I -c 'import json,sys; print(json.loads(sys.stdin.read()).get("ref", ""))' 2>/dev/null) + printf '%s' "$ARCH" | python3 -I -c 'import json,sys; d=json.loads(sys.stdin.read()); print("→ spec archive gate: checking local ref %s@%s (this repository has no remote; spec_archive[%r])" % (d["branch"], d["ref"][:7], d["key"]))' 2>/dev/null elif [ "$ARCH_STATUS" = remote ]; then # A declared change is checked against the default branch as the remote has it: no name, or a failed fetch, # is an error, never a pass on a stale local ref (verify round 2). @@ -574,17 +574,17 @@ else fi fi if [ "$ARCH_STATUS" != local ] && [ "$ARCH_STATUS" != remote ]; then - GATE=$(printf '%s' "$ARCH" | python3 -c 'import json,sys + GATE=$(printf '%s' "$ARCH" | python3 -I -c 'import json,sys try: r = json.loads(sys.stdin.read()).get("reason", "") except Exception: r = "" -print(json.dumps({"status": "error", "not_archived": [], "reason": "spec_archive: " + (r or "archive-ref printed nothing readable")}))'); GATE_RC=2 +print(json.dumps({"status": "error", "not_archived": [], "reason": "archive-ref: " + (r or "printed nothing readable")}))'); GATE_RC=2 elif [ -z "$SPEC_REF" ]; then # #547: say why archive-ref answered remote, so a repository meant for its local branch whose entry was not # found (or whose configuration could not be read) shows the reason next to the failed fetch. - GATE=$(printf '%s' "$ARCH" | python3 -c 'import json,sys + GATE=$(printf '%s' "$ARCH" | python3 -I -c 'import json,sys try: r = json.loads(sys.stdin.read()).get("reason", "") except Exception: r = "" -print(json.dumps({"status": "error", "not_archived": [], "reason": "the default branch could not be read (gh repo view or git fetch failed)" + ("; spec_archive: " + r if r else "")}))'); GATE_RC=2 +print(json.dumps({"status": "error", "not_archived": [], "reason": "the default branch could not be read (gh repo view or git fetch failed)" + ("; archive-ref: " + r if r else "")}))'); GATE_RC=2 else GATE=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archived --file "$SPEC_IC" --cwd "${CWD:-$PWD}" --ref "$SPEC_REF"); GATE_RC=$? fi @@ -597,7 +597,7 @@ printf '%s\n' "$GATE" | jq -r '"→ spec archive gate: \(.status) \(.reason)"' |---|---| | `pass`(含 `no behaviour change`、`third-party clone`、舊制留言) | 往下 | | `refuse` | 停下、不 close:列出還沒封存的 change,或 `**Spec**:` 行的問題。常見原因是 PR 還沒合併,或封存 commit 不在合併的範圍裡 | -| `error` | 停下、不 close:留言、預設 branch 或設定讀不到,照原因處理後重跑。`spec_archive:` 開頭的原因是設定的問題(例如設了本機模式的 repo 有 remote、branch 不存在),改設定或移除那一條 | +| `error` | 停下、不 close:留言、預設 branch 或設定讀不到,照原因處理後重跑。`archive-ref:` 開頭的原因說的是 `spec-change.py archive-ref` 為什麼這樣回答:設定的問題(例如設了本機模式的 repo 有 remote、branch 不存在、同一個路徑有兩個條目)就改設定或移除那一條;程式 repo 讀不到(不是 git repo)就在正確的目錄重跑 | | 沒有輸出、不是 JSON、或上面沒列的 status | 停下、不 close,回報印出的內容 | 這一道和 Step 1.5 一樣是硬性的:不問人、沒有略過的選項。有人在場時要結案,先把 change 封存進預設 branch,或修正 Implementation Complete 的宣告。 From cb12565267d9bed8c1082635e6618c94a83d9c38 Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 14:21:42 +0800 Subject: [PATCH 07/13] chore: archive idd-547-fix2 (#547) Refs #547 Co-Authored-By: Claude Opus 5.5 --- .../2026-11-14-idd-547-fix2}/.openspec.yaml | 2 ++ .../2026-11-14-idd-547-fix2}/proposal.md | 0 .../specs/spec-on-every-issue/spec.md | 0 .../2026-11-14-idd-547-fix2}/tasks.md | 2 +- openspec/specs/spec-on-every-issue/spec.md | 19 ++++++++++++++----- 5 files changed, 17 insertions(+), 6 deletions(-) rename openspec/changes/{idd-547-fix2 => archive/2026-11-14-idd-547-fix2}/.openspec.yaml (54%) rename openspec/changes/{idd-547-fix2 => archive/2026-11-14-idd-547-fix2}/proposal.md (100%) rename openspec/changes/{idd-547-fix2 => archive/2026-11-14-idd-547-fix2}/specs/spec-on-every-issue/spec.md (100%) rename openspec/changes/{idd-547-fix2 => archive/2026-11-14-idd-547-fix2}/tasks.md (95%) diff --git a/openspec/changes/idd-547-fix2/.openspec.yaml b/openspec/changes/archive/2026-11-14-idd-547-fix2/.openspec.yaml similarity index 54% rename from openspec/changes/idd-547-fix2/.openspec.yaml rename to openspec/changes/archive/2026-11-14-idd-547-fix2/.openspec.yaml index f483aa4c..1a60d392 100644 --- a/openspec/changes/idd-547-fix2/.openspec.yaml +++ b/openspec/changes/archive/2026-11-14-idd-547-fix2/.openspec.yaml @@ -1,3 +1,5 @@ schema: spec-driven created: 2026-11-14 created_by: che cheng +archived_by: che cheng +archived_at: 2026-11-14 diff --git a/openspec/changes/idd-547-fix2/proposal.md b/openspec/changes/archive/2026-11-14-idd-547-fix2/proposal.md similarity index 100% rename from openspec/changes/idd-547-fix2/proposal.md rename to openspec/changes/archive/2026-11-14-idd-547-fix2/proposal.md diff --git a/openspec/changes/idd-547-fix2/specs/spec-on-every-issue/spec.md b/openspec/changes/archive/2026-11-14-idd-547-fix2/specs/spec-on-every-issue/spec.md similarity index 100% rename from openspec/changes/idd-547-fix2/specs/spec-on-every-issue/spec.md rename to openspec/changes/archive/2026-11-14-idd-547-fix2/specs/spec-on-every-issue/spec.md diff --git a/openspec/changes/idd-547-fix2/tasks.md b/openspec/changes/archive/2026-11-14-idd-547-fix2/tasks.md similarity index 95% rename from openspec/changes/idd-547-fix2/tasks.md rename to openspec/changes/archive/2026-11-14-idd-547-fix2/tasks.md index 054cdfa2..c1aacfb0 100644 --- a/openspec/changes/idd-547-fix2/tasks.md +++ b/openspec/changes/archive/2026-11-14-idd-547-fix2/tasks.md @@ -12,4 +12,4 @@ ## 3. 收尾 -- [ ] 3.1 run-all-tests.sh 與連結檢查。驗證:結束碼 0,links 回 ok。 +- [x] 3.1 run-all-tests.sh 與連結檢查。驗證:結束碼 0,links 回 ok。 diff --git a/openspec/specs/spec-on-every-issue/spec.md b/openspec/specs/spec-on-every-issue/spec.md index d25660c3..74d3127e 100644 --- a/openspec/specs/spec-on-every-issue/spec.md +++ b/openspec/specs/spec-on-every-issue/spec.md @@ -390,15 +390,15 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL --- ### Requirement: A repository without a remote can opt into its local default branch -`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree, the directory that holds the repository's common `.git` directory; otherwise its top level. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. It SHALL print one JSON line and exit as follows: +`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree (its git directory differs from the common git directory), the directory that holds the common `.git` directory; otherwise its top level, including a repository made with `--separate-git-dir`. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. When the repository's own path cannot be written as a key (it has leading or trailing whitespace), the answer is `remote`; it SHALL NOT fall back to `.`. Reasons name the configuration file by its path relative to the repository, not by an absolute path. It SHALL print one JSON line and exit as follows: -- `remote` (exit 0), with a `reason`, when no configuration file is found; when the file found cannot be read as a JSON object (it is empty, `null`, not JSON, not valid UTF-8, or nested too deeply; a UTF-8 byte order mark is read as usual); when the file has no `spec_archive` field; or when `spec_archive` has no entry for the key. Callers then read the default branch as the remote has it, as before; a repository without any remote then stops there, with this reason. +- `remote` (exit 0), with a `reason`, when no configuration file is found; when the file found cannot be read as a JSON object (it is empty, `null`, not JSON, not valid UTF-8, or nested too deeply; a UTF-8 byte order mark is read as usual); when the file has no `spec_archive` field; when `spec_archive` has no entry for the key; or when the repository's path cannot be written as a key. Callers then read the default branch as the remote has it, as before; a repository without any remote then stops there, with this reason. - `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at, whatever `HEAD` is), `config` and `key`, when exactly one entry matches the key, it is `{"ref": "local", "branch": ""}`, the repository has no remote, and the branch exists. -- `error` (exit 2), with a `reason`, when `spec_archive` is not an object; when more than one key matches; when the matching entry is not an object, its `ref` is not `local`, or its `branch` is missing, not a string, or not a valid branch name (`git check-ref-format --branch` must accept it unchanged, so revision syntax such as `master~1` or `master@{0}` is refused); when the repository has a remote; when the branch does not exist; or when `` is not inside a git repository. +- `error` (exit 2), with a `reason`, when `spec_archive` is not an object; when more than one key matches, including the same key written twice in the file; when the matching entry is not an object, its `ref` is not `local`, or its `branch` is missing, not a string, or not a valid branch name (`git check-ref-format --branch` must accept it unchanged, so revision syntax such as `master~1` or `master@{0}` is refused); when the repository has a remote; when the branch does not exist; or when `` is not inside a git repository. -A repository has a remote when any `remote..url` is set in the git configuration it reads; a `remote` section without a URL (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. +A repository has a remote when `git remote` lists a name that has a `url` or a `pushurl` in the git configuration it reads, or a legacy `remotes/` or `branches/` file in its git directory; a `remote` section without either (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. -`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does first, and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would, without reading ``. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the baseline tag when that tag exists and is an ancestor of `HEAD` (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message contains `#` with no letter, digit, `_`, `/` or `-` right before the `#` and no digit after the number, the rule of `references/pr-issue-matching.md` (`from: first-commit`). The baseline tag is the configuration's `auto_tag.baseline_format` with `{N}` replaced by ``, or `idd--baseline` when that field is absent or not a string containing `{N}`. Commit messages SHALL be read so that no byte a message can hold hides a commit. It SHALL print `error` (exit 2) when neither base exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits; an empty `` is a usage error (exit 64), like any empty argument of `spec-change.py`. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. +`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does first, and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would, without reading ``. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the baseline tag when that tag exists and is an ancestor of `HEAD` other than `HEAD` itself (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message names issue ``: `#` with no letter, digit, `_`, `/` or `-` right before the `#`, the rule of `references/pr-issue-matching.md`, or `/#` where `/` is the configuration's `github_repo` (letter case ignored), the form a commit in a separate code repository uses for the issue repository's issues; in both forms no digit follows the number (`from: first-commit`). `/#` for any other repository does not count. The baseline tag is the configuration's `auto_tag.baseline_format` with `{N}` replaced by ``, or `idd--baseline` when that field is absent, not a string containing `{N}`, or does not give a valid tag name. Commit messages SHALL be read so that no byte a message can hold hides a commit, with signature display turned off and `HEAD` separated from paths, and every commit and parent read SHALL be a hexadecimal object id. It SHALL print `error` (exit 2) when neither base exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits; an empty `` is a usage error (exit 64), like any empty argument of `spec-change.py`. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. `references/spec-wrapper.md` step 5 SHALL ask `link-base` first, with the issue number taken from `NUMBER`, or from `N` when `NUMBER` is empty, and SHALL use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote`, and SHALL stop with the reason when it prints `error` or nothing a JSON reader can take, without also printing the message about a failed fetch. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. @@ -433,6 +433,11 @@ A repository has a remote when any `remote..url` is set in the git configu | `spec_archive` names the main working tree | `{"ref": "local", "branch": "master"}` | asked from a linked worktree of it | `local` | | the new file without `spec_archive`, the legacy file beside it with an entry | — | no remote | `remote` (the new file wins) | | a file above the home directory with an entry | — | no remote | `remote` (not read) | +| `spec_archive` has `.` | `{"ref": "local", "branch": "master"}` | another repository below, whose directory name ends in a space | `remote` (no fallback to `.`) | +| `spec_archive` names this path twice, written as the same key | `{"ref": "local", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has a `pushurl` and no `url` | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | a legacy `remotes/origin` file in its git directory | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | made with `--separate-git-dir` | `local`, keyed by its top level | ##### Example: where the local link check starts @@ -448,3 +453,7 @@ A repository has a remote when any `remote..url` is set in the git configu | tag `idd-14-baseline` on a commit that is not an ancestor of `HEAD`; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | | `auto_tag.baseline_format` is `start-{N}`, tag `start-14` on an ancestor | `ok`, that tag's commit, `from: baseline-tag` | | no tag; a commit before `a (#14)` has the byte 0x1e in its message | `ok`, the parent of `a (#14)` | +| `github_repo` is `o/issues`; no tag; commits `base`, `see other/r#14`, `fix (O/ISSUES#14)` | `ok`, the parent of `fix (O/ISSUES#14)` | +| tag `idd-14-baseline` on `HEAD` itself; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | +| `log.showSignature` is on and a commit before `a (#14)` is signed | `ok`, the parent of `a (#14)` | +| a file named `HEAD` at the repository's top level; no tag; commits `base`, `a (#14)` | `ok`, the commit `base` | From ec1604513d18b28b5fe91e9e306683970b4be448 Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 17:44:33 +0800 Subject: [PATCH 08/13] =?UTF-8?q?fix:=20spec=5Farchive=20verify=20round=20?= =?UTF-8?q?3=20=E2=80=94=20no=20fetch=20without=20a=20remote,=20duplicates?= =?UTF-8?q?=20found=20while=20parsing,=20no=20guessed=20key=20for=20a=20se?= =?UTF-8?q?parate-git-dir=20worktree=20(#547)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - archive-ref: every remote answer carries has_remote; idd-close Step 1.57 and spec-wrapper step 5 fetch only when it is true (git would read a local path named origin as the remote) - duplicate keys recorded on the parsed objects (top-level spec_archive, its keys, the matching entry's keys), so no key in the file can imitate one; "spec_archive": null is no field - a remote counts when it has a url, a pushurl or a vcs - main working tree from git worktree list; a linked worktree of a --separate-git-dir repository, whose main working tree git does not record, gets no entry instead of a guessed key - link-base reads git log in UTF-8 whatever i18n.logOutputEncoding says - check-existing-work --skip-branches no longer looks up the default branch (no origin/HEAD read) - step 5 error label link-base:; docstring, config-protocol, CHANGELOG - tests: Example rows for each, detail assertions for three earlier rows, a top level ending in a space Refs #547 Co-Authored-By: Claude Opus 5.5 --- openspec/changes/idd-547-fix3/.openspec.yaml | 3 + openspec/changes/idd-547-fix3/proposal.md | 46 ++++++ .../specs/idd-existing-work-lookup/spec.md | 22 +++ .../specs/spec-on-every-issue/spec.md | 138 ++++++++++++++++++ openspec/changes/idd-547-fix3/tasks.md | 15 ++ plugins/issue-driven-dev/CHANGELOG.md | 22 ++- .../references/config-protocol.md | 6 +- .../references/spec-wrapper.md | 20 ++- .../scripts/check-existing-work.sh | 24 +-- .../issue-driven-dev/scripts/spec-change.py | 114 +++++++++++---- .../scripts/tests/check-existing-work/test.sh | 7 + .../scripts/tests/spec-archive-local/test.sh | 80 +++++++++- .../scripts/tests/spec-close-gate/test.sh | 14 +- .../skills/idd-close/SKILL.md | 26 ++-- 14 files changed, 468 insertions(+), 69 deletions(-) create mode 100644 openspec/changes/idd-547-fix3/.openspec.yaml create mode 100644 openspec/changes/idd-547-fix3/proposal.md create mode 100644 openspec/changes/idd-547-fix3/specs/idd-existing-work-lookup/spec.md create mode 100644 openspec/changes/idd-547-fix3/specs/spec-on-every-issue/spec.md create mode 100644 openspec/changes/idd-547-fix3/tasks.md diff --git a/openspec/changes/idd-547-fix3/.openspec.yaml b/openspec/changes/idd-547-fix3/.openspec.yaml new file mode 100644 index 00000000..f483aa4c --- /dev/null +++ b/openspec/changes/idd-547-fix3/.openspec.yaml @@ -0,0 +1,3 @@ +schema: spec-driven +created: 2026-11-14 +created_by: che cheng diff --git a/openspec/changes/idd-547-fix3/proposal.md b/openspec/changes/idd-547-fix3/proposal.md new file mode 100644 index 00000000..c6fc6243 --- /dev/null +++ b/openspec/changes/idd-547-fix3/proposal.md @@ -0,0 +1,46 @@ +**GitHub-side tracker**: #547(第 3 輪 verify:comment 6875253859;本輪計畫:comment 6875265846;不在範圍的三項合成 #552) + +## Problem + +第 3 輪 verify 找到 1 項 Blocking:第 2 輪把 `repo_top()` 改成只去換行,連帶讓 `archived`、`links`、`preflight` 對結尾有空白的路徑讀對了 repo(原本會讀到同名的兄弟目錄),但沒有 requirement 寫明、沒有測試。另有 11 項 In-scope fix:`--separate-git-dir` 主工作樹的 linked worktree 算錯 key(git 不記錄這種主工作樹在哪,改成不猜 key、說明原因)、`git log` 的輸出編碼沒固定、重複鍵的記號放在資料裡、沒有 remote 的 repo 仍去 fetch(git 會把名為 `origin` 的本機路徑當成 remote)、`"spec_archive": null` 擋住普通 repo,以及幾處標籤、文件與測試細節。 + +## Root Cause + +前兩輪逐項修邊界時,共用的 helper 改動沒有回頭補到其他子命令的規格;主工作樹與重複鍵的判斷用了推論而不是 git 與 parser 直接給的答案。 + +## Proposed Solution + +新增 requirement「spec-change.py reads the repository that holds --cwd」,修改「Close requires the issue's change to be archived」與「A repository without a remote can opt into its local default branch」(見 specs/),照著改程式、文件與測試。 + +## Non-Goals + +- 設定檔擁有者檢查、開工檢查的 `unknown` 雜訊、Step 1.55 的 fetch:#552。 +- ASSUMPTION: 不升版號。 + +## Success Criteria + +- 新的測試在改程式之前失敗,改之後通過;run-all-tests 全過;links 回 ok。 + +## Capabilities + +### New Capabilities + +(none) + +### Modified Capabilities + +- `spec-on-every-issue`: 新增一條、修改兩條 requirement。 + +## Impact + +- Affected specs: spec-on-every-issue +- Affected code: + - Modified: plugins/issue-driven-dev/scripts/spec-change.py + - Modified: plugins/issue-driven-dev/scripts/check-existing-work.sh + - Modified: plugins/issue-driven-dev/skills/idd-close/SKILL.md + - Modified: plugins/issue-driven-dev/references/spec-wrapper.md + - Modified: plugins/issue-driven-dev/references/config-protocol.md + - Modified: plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh + - Modified: plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh + - Modified: plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh + - Modified: plugins/issue-driven-dev/CHANGELOG.md diff --git a/openspec/changes/idd-547-fix3/specs/idd-existing-work-lookup/spec.md b/openspec/changes/idd-547-fix3/specs/idd-existing-work-lookup/spec.md new file mode 100644 index 00000000..b8d8fffa --- /dev/null +++ b/openspec/changes/idd-547-fix3/specs/idd-existing-work-lookup/spec.md @@ -0,0 +1,22 @@ +## MODIFIED Requirements + +### Requirement: The helper can skip the branch lookup + +`check-existing-work.sh` SHALL accept `--skip-branches` before the repository argument. With it, the helper SHALL NOT run `git fetch` or list remote-tracking branches in `--cwd`, SHALL treat the clone as having no branches, SHALL NOT look up the default branch (it asks neither GitHub nor `refs/remotes/origin/HEAD`, a remote-tracking ref; with no branches to compare it is not needed, so no default-branch error is added), SHALL NOT add a `git fetch failed` error, and SHALL add a top-level `notes` list that says the branch lookup was skipped. The PR lookups on the repository argument SHALL run as without the flag, and their failures and limits SHALL be reported as before. Without the flag the helper's output SHALL be as before, without a `notes` field. + +`idd-close` Step 1.5 SHALL pass `--skip-branches` only when `spec-change.py archive-ref` prints `local` for its working directory (requirement "A repository without a remote can opt into its local default branch" of `spec-on-every-issue`), and SHALL then print that the branch lookup was skipped and that the open PRs were checked on the issue's repository. The open-PR gate itself is unchanged. + +#### Scenario: idd-close in a repository opted into its local branch + +- **GIVEN** the working directory of `/idd-close` is a repository without a remote, opted into its local branch +- **WHEN** Step 1.5 runs +- **THEN** it calls the helper with `--skip-branches`, prints that the branch lookup was skipped, and still refuses to close while an open PR on the issue's repository references the issue + +##### Example: the branch lookup can be skipped + +| Clone | Flag | `git fetch` run | `errors` | `notes` | An open PR declaring the issue | +| --- | --- | --- | --- | --- | --- | +| has an `origin` that cannot be fetched | none | yes | has `git fetch failed` | absent | reported as E1 | +| has no remote | `--skip-branches` | no | no `git fetch failed` | says the branch lookup was skipped | reported as E1 | +| has no remote, the open PR list fails | `--skip-branches` | no | has the PR list failure | says the branch lookup was skipped | verdict `unknown` | +| has an `origin` and its `origin/HEAD`; `gh repo view` fails | `--skip-branches` | no | no default-branch error | says the branch lookup was skipped | none open; `origin/HEAD` is not read | diff --git a/openspec/changes/idd-547-fix3/specs/spec-on-every-issue/spec.md b/openspec/changes/idd-547-fix3/specs/spec-on-every-issue/spec.md new file mode 100644 index 00000000..7e49bc54 --- /dev/null +++ b/openspec/changes/idd-547-fix3/specs/spec-on-every-issue/spec.md @@ -0,0 +1,138 @@ +## MODIFIED Requirements + +### Requirement: Close requires the issue's change to be archived + +`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote` and `has_remote` is false (the repository has no remote at all), it SHALL stop without fetching and say that the repository has no remote, with the reason `archive-ref` gave; git would otherwise read a local path named `origin` as the remote. When the answer is `remote` otherwise, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails; the reason it prints SHALL then include the reason `archive-ref` gave for answering `remote`, so that a repository meant for the local branch whose entry was not found says why. When the answer is `local`, it SHALL check the commit `archive-ref` returned for the configured branch, not `HEAD`, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch, the commit and the entry's key, and without the configuration file's path. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. + +#### Scenario: An unarchived change holds the close + +- **GIVEN** an Implementation Complete comment with the marker and `**Spec**: change idd-42-fix-timeout` +- **AND** `openspec/changes/idd-42-fix-timeout/` still exists on the default branch +- **WHEN** `idd-close` runs its gates +- **THEN** it does not close the issue and says the change is not archived + +#### Scenario: A repository without a remote, opted in + +- **GIVEN** the code repository has no remote and the IDD configuration above it maps the repository's path to `{"ref": "local", "branch": "master"}` +- **AND** the change is archived on `master` +- **WHEN** `idd-close` runs its gates +- **THEN** the gate passes without fetching and prints the local branch and commit it checked + +##### Example: the close gate reads the default branch + +| Newest Implementation Complete comment | On the default branch | Close gate | +| --- | --- | --- | +| marker, `**Spec**: change idd-42-fix-timeout` | the change is archived | passes | +| marker, `**Spec**: change idd-42-fix-timeout` | archived on the issue's branch only, not yet merged | stops, naming the change | +| marker, no `**Spec**:` line | not read | stops, naming the missing line | +| no marker, no `**Spec**:` line | not read | passes | +| the issue has no Implementation Complete comment | not read | passes | +| the comments could not be fetched | not read | stops, saying the comments could not be read | +| marker, `**Spec**: change idd-42-fix-timeout` | the default branch cannot be fetched | stops, saying the default branch could not be read | +| marker, `**Spec**: no behaviour change` | the default branch cannot be fetched | passes; the branch is not read | +| marker, `**Spec**: change idd-42-fix-timeout` | the remote's default branch dropped the archive, the local tracking ref did not move | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts the repository into its local `master`, where the change is archived | passes; prints `local ref master@` | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts in, the change is not archived on `master` | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; opted into `master`; `HEAD` is on the issue's branch, where the change is archived, and `master` does not have it | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote and no `spec_archive` entry for the repository | stops, saying the default branch could not be read | +| marker, `**Spec**: change idd-42-fix-timeout` | the repository has a remote and the configuration opts it into `local` | stops and prints the reason | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote and no entry; a directory named `origin` beside it holds a repository whose default branch has the change archived | stops, saying the repository has no remote; nothing is fetched | + + +### Requirement: A repository without a remote can opt into its local default branch + +`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree (its git directory differs from the common git directory), the first worktree `git worktree list --porcelain` lists; when that entry is bare, the linked worktree's own top level; when that entry is the common git directory itself (a main working tree made with `--separate-git-dir`, to which git keeps no path back), no key is guessed and the answer is `remote`, with a reason saying the main working tree is not recorded; otherwise (not a linked worktree) its top level, including a repository made with `--separate-git-dir`. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. When the repository's own path cannot be written as a key (it has leading or trailing whitespace), the answer is `remote`; it SHALL NOT fall back to `.`. Reasons name the configuration file by its path relative to the repository, not by an absolute path. It SHALL print one JSON line and exit as follows: + +- `remote` (exit 0), with a `reason`, when no configuration file is found; when the file found cannot be read as a JSON object (it is empty, `null`, not JSON, not valid UTF-8, or nested too deeply; a UTF-8 byte order mark is read as usual); when the file has no `spec_archive` field or the field is `null`; when `spec_archive` has no entry for the key; or when the repository's path cannot be written as a key. Every `remote` answer carries `has_remote`, true when the repository has a remote; callers read the default branch as the remote has it only when it is true, and a repository without any remote stops there, with this reason. +- `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at, whatever `HEAD` is), `config` and `key`, when exactly one entry matches the key, it is `{"ref": "local", "branch": ""}`, the repository has no remote, and the branch exists. +- `error` (exit 2), with a `reason`, when `spec_archive` is not an object; when more than one key matches, including the same key written twice; when `spec_archive` itself, or a key of the matching entry, is written twice in the file (duplicates are found while the file is parsed, never by a marker kept in the data, so no key the file holds can imitate one); when the matching entry is not an object, its `ref` is not `local`, or its `branch` is missing, not a string, or not a valid branch name (`git check-ref-format --branch` must accept it unchanged, so revision syntax such as `master~1` or `master@{0}` is refused); when the repository has a remote; when the branch does not exist; or when `` is not inside a git repository. + +A repository has a remote when `git remote` lists a name that has a `url`, a `pushurl` or a `vcs` (a remote helper) in the git configuration it reads, or a legacy `remotes/` or `branches/` file in its git directory; a `remote` section without either (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. + +`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does first, and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would, without reading ``. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the baseline tag when that tag exists and is an ancestor of `HEAD` other than `HEAD` itself (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message names issue ``: `#` with no letter, digit, `_`, `/` or `-` right before the `#`, the rule of `references/pr-issue-matching.md`, or `/#` where `/` is the configuration's `github_repo` (letter case ignored), the form a commit in a separate code repository uses for the issue repository's issues; in both forms no digit follows the number (`from: first-commit`). `/#` for any other repository does not count. The baseline tag is the configuration's `auto_tag.baseline_format` with `{N}` replaced by ``, or `idd--baseline` when that field is absent, not a string containing `{N}`, or does not give a valid tag name. Commit messages SHALL be read so that no byte a message can hold hides a commit, with signature display turned off, the output encoding fixed to UTF-8 whatever `i18n.logOutputEncoding` says, and `HEAD` separated from paths, and every commit and parent read SHALL be a hexadecimal object id. It SHALL print `error` (exit 2) when neither base exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits; an empty `` is a usage error (exit 64), like any empty argument of `spec-change.py`. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. + +`references/spec-wrapper.md` step 5 SHALL ask `link-base` first, with the issue number taken from `NUMBER`, or from `N` when `NUMBER` is empty, and SHALL use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote`, and SHALL stop with the reason when it prints `error` or nothing a JSON reader can take, without also printing the message about a failed fetch. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. + +#### Scenario: An entry for a repository that later gained a remote + +- **GIVEN** a configuration entry `{"ref": "local", "branch": "master"}` for a repository +- **AND** a remote was added to that repository afterwards +- **WHEN** `archive-ref` runs for it +- **THEN** it prints `error` and names the remote, instead of reading the local branch + +##### Example: how a spec_archive entry resolves + +| Configuration found | Entry for the repository's path | Repository | `archive-ref` | +| --- | --- | --- | --- | +| none | — | no remote | `remote` | +| a file without `spec_archive` | — | no remote | `remote` | +| `spec_archive` names another path only | — | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local`, `master` and its commit | +| `spec_archive` names this path as `./sub/` | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | has a remote `origin` | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "trunk"}` | no remote, no branch `trunk` | `error` | +| `spec_archive` names this path | `{"ref": "remote", "branch": "master"}` | no remote | `error` | +| `spec_archive` names this path | `{"ref": "local"}` | no remote | `error` | +| `spec_archive` is a list | — | no remote | `error` | +| the file is not JSON | — | no remote | `remote`, saying the file could not be read | +| the file is empty, or holds `null` | — | no remote | `remote` | +| the file starts with a UTF-8 byte order mark | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path as `sub` and as `./sub/` | both `{"ref": "local", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master~1"}` | no remote | `error`, not a branch name | +| `spec_archive` names this path as ` sub` | `{"ref": "local", "branch": "master"}` | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote; the global git configuration has `[remote "origin"]` with only `prune = true` | `local` | +| `spec_archive` names the main working tree | `{"ref": "local", "branch": "master"}` | asked from a linked worktree of it | `local` | +| the new file without `spec_archive`, the legacy file beside it with an entry | — | no remote | `remote` (the new file wins) | +| a file above the home directory with an entry | — | no remote | `remote` (not read) | +| `spec_archive` has `.` | `{"ref": "local", "branch": "master"}` | another repository below, whose directory name ends in a space | `remote` (no fallback to `.`) | +| `spec_archive` names this path twice, written as the same key | `{"ref": "local", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has a `pushurl` and no `url` | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | a legacy `remotes/origin` file in its git directory | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | made with `--separate-git-dir` | `local`, keyed by its top level | +| `spec_archive` names the linked worktree's own path; the main working tree was made with `--separate-git-dir` | `{"ref": "local", "branch": "master"}` | asked from that linked worktree; no remote | `remote`, `has_remote` false, saying the main working tree is not recorded | +| `spec_archive` written twice at the top level | — | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path, and the file also holds a key that looks like an internal marker | `{"ref": "local", "branch": "master"}` | no remote | `local` | +| `"spec_archive": null` | — | has a remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has a `vcs` and no `url` | `error`, naming the remote | +| none | — | no remote | `remote`, `has_remote` false | + +##### Example: where the local link check starts + +| Repository (opted into local `master`) | `link-base --issue 14` | +| --- | --- | +| tag `idd-14-baseline` on an ancestor of `HEAD` | `ok`, the tag's commit, `from: baseline-tag` | +| no tag; commits `base`, `a (#14)`, `b (Refs #14)` | `ok`, the commit `base`, `from: first-commit` | +| no tag; the only commit naming a 14 says `#142` | `error` | +| no tag; the first commit with `#14` is the root commit | `error` | +| the repository is not opted in | `remote` | +| the repository is not opted in, `--issue abc` | `remote` | +| no tag; commits `base`, `see o/r#14`, `x#14`, `fix (#14)` | `ok`, the parent of `fix (#14)` | +| tag `idd-14-baseline` on a commit that is not an ancestor of `HEAD`; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | +| `auto_tag.baseline_format` is `start-{N}`, tag `start-14` on an ancestor | `ok`, that tag's commit, `from: baseline-tag` | +| no tag; a commit before `a (#14)` has the byte 0x1e in its message | `ok`, the parent of `a (#14)` | +| `github_repo` is `o/issues`; no tag; commits `base`, `see other/r#14`, `fix (O/ISSUES#14)` | `ok`, the parent of `fix (O/ISSUES#14)` | +| tag `idd-14-baseline` on `HEAD` itself; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | +| `log.showSignature` is on and a commit before `a (#14)` is signed | `ok`, the parent of `a (#14)` | +| a file named `HEAD` at the repository's top level; no tag; commits `base`, `a (#14)` | `ok`, the commit `base` | +| `i18n.logOutputEncoding` is `UTF-16`; no tag; commits `base`, `a (#14)` | `ok`, the commit `base` | + +## ADDED Requirements + +### Requirement: spec-change.py reads the repository that holds --cwd + +Every subcommand of `scripts/spec-change.py` that takes `--cwd` (`archived`, `links`, `preflight`, `archive-ref`, `link-base`) SHALL read the repository whose top level `git rev-parse --show-toplevel` reports for `--cwd`, and SHALL take that path exactly as git prints it, removing only the line ending. A top level whose name ends in whitespace is that directory, never a sibling directory whose name lacks the whitespace. + +#### Scenario: A top level whose name ends in a space + +- **GIVEN** two repositories side by side, `odd ` (with a trailing space) and `odd` +- **WHEN** a subcommand runs with `--cwd` inside `odd ` +- **THEN** it reads `odd ` + +##### Example: a top level whose name ends in a space + +| Repositories | Command | Result | +| --- | --- | --- | +| `odd ` has the change archived, the sibling `odd` does not | `archived --cwd 'odd ' --ref HEAD` | `pass` | +| `odd ` alone, with the change archived | `archived --cwd 'odd ' --ref HEAD` | `pass` | +| `odd ` has a spec added on a branch without an Example, the sibling `odd` has none | `links --base --cwd 'odd '` | `missing` | diff --git a/openspec/changes/idd-547-fix3/tasks.md b/openspec/changes/idd-547-fix3/tasks.md new file mode 100644 index 00000000..49708be9 --- /dev/null +++ b/openspec/changes/idd-547-fix3/tasks.md @@ -0,0 +1,15 @@ +## 1. 測試先行 + +- [x] 1.1 requirement「spec-change.py reads the repository that holds --cwd」— spec-archive-local:Example「a top level whose name ends in a space」三列,帶標記 spec-example: spec-on-every-issue / a top level whose name ends in a space。 +- [x] 1.2 requirement「A repository without a remote can opt into its local default branch」— spec-archive-local:Example 新增的各列(separate-git-dir 加 linked worktree、各種重複鍵、偽造記號、`null`、`vcs`、`has_remote`、UTF-16 log),以及第 3 輪第 4 列要補的三個細節斷言。驗證:改之前新的列失敗。 +- [x] 1.3 requirement「Close requires the issue's change to be archived」— spec-close-gate:名為 `origin` 的本機 repo 不會讓沒有 remote 的 repo 通過,也不 fetch。驗證:改之前失敗。 +- [x] 1.4 requirement「The helper can skip the branch lookup」— check-existing-work:`--skip-branches` 而 `gh repo view` 失敗時不讀 `origin/HEAD`、不記預設 branch 的錯誤;spec-wrapper 第 5 步 `link-base:` 標籤。 + +## 2. 程式與文件 + +- [x] 2.1 `spec-change.py`、`check-existing-work.sh`、idd-close Step 1.57、spec-wrapper 第 5 步。驗證:1.1–1.4 通過。 +- [x] 2.2 docstring、config-protocol、CHANGELOG 寫到目前的規則。 + +## 3. 收尾 + +- [x] 3.1 run-all-tests.sh 與連結檢查。驗證:結束碼 0,links 回 ok。 diff --git a/plugins/issue-driven-dev/CHANGELOG.md b/plugins/issue-driven-dev/CHANGELOG.md index 119c9fad..1227eb10 100644 --- a/plugins/issue-driven-dev/CHANGELOG.md +++ b/plugins/issue-driven-dev/CHANGELOG.md @@ -18,15 +18,25 @@ Version number left to the release. (`local ref @`); Step 1.5 skips the branch lookup (`check-existing-work.sh --skip-branches`) and still checks open PRs on the issue repository; the link check of `references/spec-wrapper.md` step 5 starts at the issue's baseline tag, or at the parent of the oldest commit naming `#N`. An entry is accepted only while the - repository has no remote at all (a remote with a URL); with a remote it is an error, never a silent fallback. - Without an entry nothing changes, and a configuration file that cannot be read as a JSON object counts as having - no entry, so it does not block a repository that never set the field. The branch must be a branch name, and the - check reads it whatever `HEAD` is; a linked worktree uses its main working tree's key. The link check finds the - issue in a separate code repository's commits written as `owner/repo#N` for the configured `github_repo`. New `spec-change.py` - subcommands `archive-ref` and `link-base`; documented in `config-protocol.md`. + repository has no remote at all (a remote with a url, a pushurl or a vcs); with a remote it is an error, never a + silent fallback. Without an entry nothing changes, and a configuration file that cannot be read as a JSON object, + or `"spec_archive": null`, counts as having no entry, so it does not block a repository that never set the field. + A key written twice is an error, found while the file is parsed. The branch must be a branch name, and the check + reads it whatever `HEAD` is; a linked worktree uses its main working tree's key, and a linked worktree of a + repository made with `--separate-git-dir` (whose main working tree git does not record) gets no entry. A + repository with no remote and no entry now stops without fetching, in Step 1.57 and in the link check: git would + read a local path named `origin` as the remote. The link check finds the issue in a separate code repository's + commits written as `owner/repo#N` for the configured `github_repo`, reading `git log` in UTF-8 whatever + `i18n.logOutputEncoding` says. With `--skip-branches` the helper does not look up the default branch either. + New `spec-change.py` subcommands `archive-ref` and `link-base`; documented in `config-protocol.md`. ### Fixed +- **`spec-change.py` reads the repository whose top level ends in whitespace (#547).** `archived`, `links` and + `preflight` stripped the top level `git rev-parse --show-toplevel` printed, so a repository named `odd ` (with a + trailing space) was read as a sibling directory `odd`, or failed when there was none. They now take the path as + git prints it, removing only the line ending. + - **The edit-run suite has a time limit of its own (#508, #519).** Most of its run time is CPU time (about 65 s on an 18-core Mac), so it takes longer on a busy machine: run alone it took 84 s at a load near 20 and 123 s at a load of 60 to 100, and inside full runs up to 168 s (#512). Once, at a load near 50 and with another full run using diff --git a/plugins/issue-driven-dev/references/config-protocol.md b/plugins/issue-driven-dev/references/config-protocol.md index e4c1f7fa..7c2687bf 100644 --- a/plugins/issue-driven-dev/references/config-protocol.md +++ b/plugins/issue-driven-dev/references/config-protocol.md @@ -497,13 +497,13 @@ Which branch the spec checks read for a code repository that **deliberately has | Part | Meaning | |------|---------| -| key | The code repository's main working tree (for a linked worktree, the directory holding the common `.git`), relative to the directory that holds this `.claude/` (both resolved through symbolic links). `./sub/`, `sub/` and `sub` name the same path; `.` names the directory of this configuration itself; a key that is empty or has leading or trailing whitespace names nothing. Two keys that name the same path are an error | +| key | The code repository's main working tree (for a linked worktree, the first entry `git worktree list` prints; git keeps no path back to the main working tree of a repository made with `--separate-git-dir`, so a linked worktree of one gets no entry — run from the main working tree), relative to the directory that holds this `.claude/` (both resolved through symbolic links). `./sub/`, `sub/` and `sub` name the same path; `.` names the directory of this configuration itself; a key that is empty or has leading or trailing whitespace names nothing. Two keys that name the same path are an error | | `ref` | Must be `local`. Any other value is an error | | `branch` | The local branch that plays the default branch: a branch name that `git check-ref-format --branch` accepts unchanged (not `master~1` or `master@{0}`). Required: without a remote there is no `origin/HEAD` to read, and `HEAD` is only the branch checked out now. The check reads this branch whatever `HEAD` is | -Read by `scripts/spec-change.py archive-ref` (and `link-base`), which walks up from the **code repository's** main working tree to the first IDD configuration — the same walk as the other fields, new file before legacy file at each level, stopping after `$HOME` (`/` itself is not read). A file that cannot be read as a JSON object (empty, `null`, not JSON, not UTF-8) is treated as having no entry, so a repository that never set the field is not blocked by it; a repository without a remote then stops at the fetch, with that reason. Write the entry in the issue repository's configuration; do not add a configuration to the code repository just for this, because a file without `github_repo` there would be the first one the other skills find. +Read by `scripts/spec-change.py archive-ref` (and `link-base`), which walks up from the **code repository's** main working tree to the first IDD configuration — the same walk as the other fields, new file before legacy file at each level, stopping after `$HOME` (`/` itself is not read). A file that cannot be read as a JSON object (empty, `null`, not JSON, not UTF-8), and `"spec_archive": null`, are treated as having no entry, so a repository that never set the field is not blocked by it. Every `remote` answer carries `has_remote`: when it is false the repository has no remote at all, and Step 1.57 and the link check stop without fetching, with that reason (git would otherwise read a local path named `origin` as the remote). Write the entry in the issue repository's configuration; do not add a configuration to the code repository just for this, because a file without `github_repo` there would be the first one the other skills find. -**Accepted only while the repository has no remote at all** — no name that `git remote` lists with a `url` or `pushurl`, and no legacy `remotes/` or `branches/` file in its git directory; a `remote` section with neither (a global `remote.origin.prune`, say) does not count. An entry for a repository that has any remote is an error, not a silent fallback to the remote: an entry written because there was no remote must not outlive that reason. Other errors: `spec_archive` is not an object, two entries (or the same key written twice) name the repository's path, the entry is not `{"ref": "local", "branch": ""}`, or the branch does not exist. A repository whose own path cannot be written as a key (it ends in a space, say) gets no entry: it never borrows the `.` entry of the configuration's own directory. Reasons name the configuration file relative to the code repository, never by an absolute path. +**Accepted only while the repository has no remote at all** — no name that `git remote` lists with a `url`, a `pushurl` or a `vcs` (a remote helper), and no legacy `remotes/` or `branches/` file in its git directory; a `remote` section with none of them (a global `remote.origin.prune`, say) does not count. An entry for a repository that has any remote is an error, not a silent fallback to the remote: an entry written because there was no remote must not outlive that reason. Other errors: `spec_archive` is not an object, two entries name the repository's path, a key is written twice (`spec_archive` itself, a key of it that names this path, or a key of the matching entry — found while the file is parsed, so no key the file holds can imitate a duplicate), the entry is not `{"ref": "local", "branch": ""}`, or the branch does not exist. A repository whose own path cannot be written as a key (it ends in a space, say) gets no entry: it never borrows the `.` entry of the configuration's own directory. Reasons name the configuration file relative to the code repository, never by an absolute path. What it changes, and nothing else: diff --git a/plugins/issue-driven-dev/references/spec-wrapper.md b/plugins/issue-driven-dev/references/spec-wrapper.md index 38a50a67..60167330 100644 --- a/plugins/issue-driven-dev/references/spec-wrapper.md +++ b/plugins/issue-driven-dev/references/spec-wrapper.md @@ -138,23 +138,31 @@ if [ "$LB_STATUS" = ok ]; then SPEC_BASE=$(printf '%s' "$LB" | python3 -I -c 'import json,sys; print(json.loads(sys.stdin.read()).get("base", ""))') printf '%s' "$LB" | python3 -I -c 'import json,sys; d=json.loads(sys.stdin.read()); print("→ link check from %s (%s; spec_archive local mode)" % (d["base"][:7], d["from"]))' elif [ "$LB_STATUS" = remote ]; then - DEFAULT_BRANCH=$(gh repo view "$GITHUB_REPO" --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null) || DEFAULT_BRANCH="" - if [ -n "$DEFAULT_BRANCH" ] && git -C "$CWD" fetch -q origin -- "$DEFAULT_BRANCH" 2>/dev/null; then - SPEC_BASE=$(git -C "$CWD" merge-base HEAD FETCH_HEAD 2>/dev/null) + # Only a repository that has a remote is fetched: without one, git would read a local path named origin. + LB_HAS_REMOTE=$(printf '%s' "$LB" | python3 -I -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("has_remote") is True)' 2>/dev/null) + if [ "$LB_HAS_REMOTE" = True ]; then + DEFAULT_BRANCH=$(gh repo view "$GITHUB_REPO" --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null) || DEFAULT_BRANCH="" + if [ -n "$DEFAULT_BRANCH" ] && git -C "$CWD" fetch -q origin -- "$DEFAULT_BRANCH" 2>/dev/null; then + SPEC_BASE=$(git -C "$CWD" merge-base HEAD FETCH_HEAD 2>/dev/null) + fi + else + echo "✗ spec close-out: link-base: this repository has no remote, so the default branch is not fetched; $(printf '%s' "$LB" | python3 -I -c 'import json,sys +try: print(json.loads(sys.stdin.read()).get("reason", "")) +except Exception: print("")' 2>/dev/null); stopping" >&2 fi else - echo "✗ spec close-out: archive-ref: $(printf '%s' "$LB" | python3 -I -c 'import json,sys + echo "✗ spec close-out: link-base: $(printf '%s' "$LB" | python3 -I -c 'import json,sys try: print(json.loads(sys.stdin.read()).get("reason", "") or "link-base printed nothing readable") except Exception: print("link-base printed nothing readable")' 2>/dev/null); stopping" >&2 fi if [ -n "$SPEC_BASE" ]; then python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" links --base "$SPEC_BASE" --cwd "$CWD" -elif [ "$LB_STATUS" = remote ]; then +elif [ "$LB_STATUS" = remote ] && [ "${LB_HAS_REMOTE:-}" = True ]; then echo "✗ spec close-out: cannot find where this branch left the default branch (gh repo view, git fetch or git merge-base failed); stopping" >&2 fi ``` -`git merge-base HEAD FETCH_HEAD`(剛從遠端 fetch 的預設 branch)在 PR path 是分岔點;在 direct-commit path 是 run 還沒推的 commit 之前那一個。程式 repo 沒有 remote、用 `spec_archive` 指到本機 branch 時(#547,見 `config-protocol.md`),沒有「還沒推的 commit」這條界線,起點改由 `link-base` 給:這張 issue 的 baseline tag(`auto_tag.baseline_format`,預設 `idd--baseline`;是 HEAD 的祖先、而且不是 HEAD 本身時),否則 HEAD 歷史裡第一個引用這張 issue 的 commit 的父 commit——引用指 `#`(左右邊界同 `pr-issue-matching.md`),或設定檔 `github_repo` 那個 repo 的 `/#`(程式 repo 與 issue repo 分開時 commit 就是這樣寫的);兩者都沒有就停下,不退回 `merge-base`(direct-commit 時那是 HEAD,範圍是空的)。沒有設定的 repo,`link-base` 回 `remote`、不讀 issue 號,照舊 fetch。沒有印出 JSON(`SPEC_BASE` 取不到)就停下回報。`missing` 就補測試或標記再跑一次。要改的是 requirement 本身(例如寫了一個寫不出檢查的 Example)時,不改 `archive/` 底下的檔案,也不繞過 Spectra 直接改主規格:照第 7 步另建一個 change 修改那條 requirement,封存後再跑。`error` 停下回報。 +`git merge-base HEAD FETCH_HEAD`(剛從遠端 fetch 的預設 branch)在 PR path 是分岔點;在 direct-commit path 是 run 還沒推的 commit 之前那一個。程式 repo 沒有 remote、用 `spec_archive` 指到本機 branch 時(#547,見 `config-protocol.md`),沒有「還沒推的 commit」這條界線,起點改由 `link-base` 給:這張 issue 的 baseline tag(`auto_tag.baseline_format`,預設 `idd--baseline`;是 HEAD 的祖先、而且不是 HEAD 本身時),否則 HEAD 歷史裡第一個引用這張 issue 的 commit 的父 commit——引用指 `#`(左右邊界同 `pr-issue-matching.md`),或設定檔 `github_repo` 那個 repo 的 `/#`(程式 repo 與 issue repo 分開時 commit 就是這樣寫的);兩者都沒有就停下,不退回 `merge-base`(direct-commit 時那是 HEAD,範圍是空的)。沒有設定的 repo,`link-base` 回 `remote`、不讀 issue 號,照舊 fetch;但回答裡的 `has_remote` 不是 true(repo 根本沒有 remote)時不 fetch,停下並說明(git 會把名為 `origin` 的本機路徑當成 remote)。錯誤訊息以 `link-base:` 開頭。沒有印出 JSON(`SPEC_BASE` 取不到)就停下回報。`missing` 就補測試或標記再跑一次。要改的是 requirement 本身(例如寫了一個寫不出檢查的 Example)時,不改 `archive/` 底下的檔案,也不繞過 Spectra 直接改主規格:照第 7 步另建一個 change 修改那條 requirement,封存後再跑。`error` 停下回報。 6. 確認宣告與 HEAD 一致:把第 6 步要貼的 `**Spec**:` 行寫進一個暫存檔,跑 `python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archived --file <暫存檔> --cwd "$CWD" --ref HEAD`,要 `pass`。 diff --git a/plugins/issue-driven-dev/scripts/check-existing-work.sh b/plugins/issue-driven-dev/scripts/check-existing-work.sh index 54a35035..3db26755 100755 --- a/plugins/issue-driven-dev/scripts/check-existing-work.sh +++ b/plugins/issue-driven-dev/scripts/check-existing-work.sh @@ -135,17 +135,19 @@ else: errors.append("git for-each-ref failed") # The default branch comes from GitHub. The clone's refs/remotes/origin/HEAD is a snapshot from clone time and can # point at an old feature branch (seen on a real clone), which makes every commit on the real default branch look -# unmerged. It is only the fallback when GitHub cannot be asked. -rv = gh_json(["gh", "repo", "view", repo, "--json", "defaultBranchRef"], "gh repo view") -default = ((rv or {}).get("defaultBranchRef") or {}).get("name") -if default is None: - h = run(["git", "-C", cwd, "symbolic-ref", "--short", "refs/remotes/origin/HEAD"]) - if h.returncode == 0 and h.stdout.strip().startswith("origin/"): - default = h.stdout.strip()[len("origin/"):] - else: - default = next((d for d in ("main", "master") if d in branches), None) -if default is None: - errors.append("could not determine the default branch") +# unmerged. It is only the fallback when GitHub cannot be asked. With --skip-branches there are no branches to +# compare, so the default branch is not looked up at all (and origin/HEAD, a remote-tracking ref, is not read; #547). +if not skip_branches: + rv = gh_json(["gh", "repo", "view", repo, "--json", "defaultBranchRef"], "gh repo view") + default = ((rv or {}).get("defaultBranchRef") or {}).get("name") + if default is None: + h = run(["git", "-C", cwd, "symbolic-ref", "--short", "refs/remotes/origin/HEAD"]) + if h.returncode == 0 and h.stdout.strip().startswith("origin/"): + default = h.stdout.strip()[len("origin/"):] + else: + default = next((d for d in ("main", "master") if d in branches), None) + if default is None: + errors.append("could not determine the default branch") merged_heads = {p["headRefOid"] for p in merged_prs} stale = {b for b, oid in branches.items() if oid in merged_heads} diff --git a/plugins/issue-driven-dev/scripts/spec-change.py b/plugins/issue-driven-dev/scripts/spec-change.py index 5af8d2ff..097aebc2 100755 --- a/plugins/issue-driven-dev/scripts/spec-change.py +++ b/plugins/issue-driven-dev/scripts/spec-change.py @@ -38,10 +38,13 @@ archive-ref --cwd (#547) Which branch do the spec checks read for this repository? The first IDD configuration walking up from the repository's main working tree may map its path (relative to the directory holding .claude/) - in `spec_archive` to {"ref": "local", "branch": ""}; accepted only without any remote URL. - A configuration that cannot be read as a JSON object counts as having no entry (remote, with a reason). + in `spec_archive` to {"ref": "local", "branch": ""}; accepted only without any remote (a url, pushurl + or vcs, or a legacy remotes/branches file). A configuration that cannot be read as a JSON object, and + `"spec_archive": null`, count as having no entry (remote, with a reason). A key written twice (spec_archive + itself, a key of it, a key of the matching entry) is an error. Every remote answer carries has_remote; + false means the repository has no remote at all, and callers stop instead of fetching. {"status": remote|local|error, "branch": "...", "ref": "", "config": "...", "key": "...", - "reason": "..."} exit 0 (remote, local), 2 (error) + "has_remote": true|false, "reason": "..."} exit 0 (remote, local), 2 (error) link-base --cwd --issue (#547) Where does the link check start in local mode? The baseline tag (auto_tag.baseline_format, default @@ -466,8 +469,8 @@ def cmd_preflight(argv): return emit({"status": "third-party", "message": "the account cannot write to this repository: " "implement without a spec change and declare `**Spec**: third-party clone`"}, 0) # Plain --git-dir / --git-common-dir (relative to top when not absolute): --path-format needs git 2.31. - gd = os.path.join(top, git_text(top, "rev-parse", "--git-dir").strip()) - cd = os.path.join(top, git_text(top, "rev-parse", "--git-common-dir").strip()) + gd = os.path.join(top, git_text(top, "rev-parse", "--git-dir").rstrip("\n")) + cd = os.path.join(top, git_text(top, "rev-parse", "--git-common-dir").rstrip("\n")) if os.path.realpath(gd) != os.path.realpath(cd): return emit({"status": "linked-worktree", "message": "this is a git linked worktree; spectra writes into " "the main working tree from here. Run in the main tree or a standalone clone"}, 1) @@ -604,14 +607,47 @@ def norm_key(k): return os.path.normpath(k).replace(os.sep, "/") +def first_worktree(top): + """(path, bare) of the first entry `git worktree list --porcelain` prints: the main working tree.""" + p = git(top, "worktree", "list", "--porcelain", "-z", check=False) + if p.returncode == 0: + fields = p.stdout.decode("utf-8", "replace").split("\x00") + else: # git older than 2.36 has no -z + fields = git_text(top, "worktree", "list", "--porcelain").split("\n") + path, bare = None, False + for f in fields: + if not f: + if path is not None: + break # the first entry ends at its empty field + continue + if path is None: + if not f.startswith("worktree "): + raise Fail(f"git worktree list printed an entry that does not start with its path: {f[:60]!r}") + path = f[len("worktree "):] + elif f == "bare": + bare = True + if path is None: + raise Fail("git worktree list printed no working tree") + return path, bare + + def main_tree(top): - """The repository's main working tree: for a linked worktree (its git dir is not the common one), the directory - holding the common .git directory; otherwise the top level (a --separate-git-dir repository included).""" + """The repository's main working tree, or None when git does not record it. For a linked worktree (its git dir + is not the common one): the first entry of `git worktree list --porcelain`; a bare entry means there is none, + and the top level is used; an entry that is the common git directory itself means git does not know where the + main working tree is (a repository made with --separate-git-dir keeps no path back to it), and no key is guessed. + Otherwise the top level (a --separate-git-dir repository asked from its main working tree included).""" gd = os.path.realpath(os.path.join(top, git_text(top, "rev-parse", "--git-dir").rstrip("\n"))) common = os.path.realpath(os.path.join(top, git_text(top, "rev-parse", "--git-common-dir").rstrip("\n"))) - if gd != common and os.path.basename(common) == ".git": - return os.path.dirname(common) - return os.path.realpath(top) + if gd == common: + return os.path.realpath(top) + path, bare = first_worktree(top) + if bare: + return os.path.realpath(top) + path = os.path.realpath(path) + if path == common: + return None + return path def rel_to(path, base): @@ -622,19 +658,20 @@ def rel_to(path, base): return os.path.basename(path) -class DuplicateKey(ValueError): - pass +class JsonObject(dict): + """A JSON object as parsed; `dups` holds the keys written more than once in it. The record lives on the + parsed object, not in its data, so no key the file holds can imitate one.""" + dups = () def _pairs(pairs): - """object_pairs_hook: keep the pairs as a dict, but remember a key written twice in one object.""" - d, dup = {}, [] + """object_pairs_hook: keep the pairs as a dict, and remember each key written twice in one object.""" + d, dup = JsonObject(), [] for k, v in pairs: - if k in d: + if k in d and k not in dup: dup.append(k) d[k] = v - if dup: - d["\x00duplicate-keys"] = dup + d.dups = tuple(dup) return d @@ -651,8 +688,9 @@ def read_config(path, shown): def remotes_of(top): - """Names of the remotes git can use here: listed by `git remote` and given a url or a pushurl, or a legacy - remotes/ or branches/ file in the git directory. A section with neither (remote.origin.prune) is no remote.""" + """Names of the remotes git can use here: listed by `git remote` and given a url, a pushurl or a vcs (a remote + helper), or a legacy remotes/ or branches/ file in the git directory. A section with none of them + (remote.origin.prune) is no remote.""" gd = os.path.join(top, git_text(top, "rev-parse", "--git-common-dir").rstrip("\n")) names = set(n for n in git_text(top, "remote").splitlines() if n) for d in ("remotes", "branches"): # legacy files: newer git no longer lists them, fetch may still read them @@ -663,7 +701,7 @@ def remotes_of(top): out = [] for name in names: has = any(git(top, "config", "--get-all", f"remote.{name}.{k}", check=False).stdout.strip() - for k in ("url", "pushurl")) + for k in ("url", "pushurl", "vcs")) has = has or any(os.path.isfile(os.path.join(gd, d, name)) for d in ("remotes", "branches")) if has: out.append(name) @@ -671,32 +709,45 @@ def remotes_of(top): def archive_ref(cwd): - """{"status": "remote", reason} | {"status": "local", branch, ref, config, key}; raises Fail for an error.""" + """{"status": "remote", reason, has_remote} | {"status": "local", branch, ref, config, key}; raises Fail for an error. + has_remote is false when the repository has no remote at all: callers then stop instead of fetching (git would + read a local path named like the remote).""" top = repo_top(cwd) tree = main_tree(top) + + def remote(reason): + return {"status": "remote", "reason": reason, "has_remote": bool(remotes_of(top))} + + if tree is None: + return remote("this is a linked worktree whose main working tree git does not record (its git directory " + "was made apart with --separate-git-dir); spec_archive is read only from the main working tree") path, root = find_config(tree) if path is None: - return {"status": "remote", "reason": "no IDD configuration found above the repository"} + return remote("no IDD configuration found above the repository") shown = rel_to(path, tree) # messages name the file as seen from the repository data, why = read_config(path, shown) if data is None: - return {"status": "remote", "reason": why} - if "spec_archive" not in data: - return {"status": "remote", "reason": f"{shown} has no spec_archive field"} + return remote(why) + if "spec_archive" in data.dups: + raise Fail(f"{shown} has more than one entry for spec_archive (the field is written twice)") + if data.get("spec_archive") is None: + return remote(f"{shown} has no spec_archive field") table = data["spec_archive"] if not isinstance(table, dict): raise Fail(f"spec_archive in {shown} must be an object keyed by repository path") rel = os.path.relpath(tree, root) key = norm_key(rel) if key is None: # never fall back to "." (that is another directory's entry) - return {"status": "remote", "reason": f"this repository's path {rel!r} cannot be written as a spec_archive key"} - dup = [k for k in table.get("\x00duplicate-keys", []) if norm_key(k) == key] - entries = [v for k, v in table.items() if not k.startswith("\x00") and norm_key(k) == key] + return remote(f"this repository's path {rel!r} cannot be written as a spec_archive key") + dup = [k for k in table.dups if norm_key(k) == key] + entries = [v for k, v in table.items() if norm_key(k) == key] if not entries: - return {"status": "remote", "reason": f"spec_archive in {shown} has no entry for {key}"} + return remote(f"spec_archive in {shown} has no entry for {key}") if len(entries) > 1 or dup: raise Fail(f"spec_archive in {shown} has more than one entry for {key}") entry = entries[0] + if isinstance(entry, JsonObject) and entry.dups: + raise Fail(f"spec_archive[{key!r}] in {shown} has more than one entry for {', '.join(map(repr, entry.dups))}") if not isinstance(entry, dict) or entry.get("ref") != "local": raise Fail(f"spec_archive[{key!r}] in {shown}: only {{\"ref\": \"local\", \"branch\": \"\"}} is supported") branch = entry.get("branch") @@ -769,8 +820,9 @@ def cmd_link_base(argv): if sha != head_sha and git(top, "merge-base", "--is-ancestor", sha, "HEAD", check=False).returncode == 0: return emit({"status": "ok", "base": sha, "from": "baseline-tag", "tag": tag}, 0) names = names_issue(data, n) - # -z: one NUL between commits (a commit message cannot hold NUL); no signature text; HEAD is a revision. - log = git(top, "log", "--no-show-signature", "--reverse", "-z", "--format=%H %P%n%B", "HEAD", "--") + # -z: one NUL between commits (a commit message cannot hold NUL); no signature text; UTF-8 whatever + # i18n.logOutputEncoding says (UTF-16 would put NULs inside every record); HEAD is a revision. + log = git(top, "log", "--no-show-signature", "--encoding=UTF-8", "--reverse", "-z", "--format=%H %P%n%B", "HEAD", "--") for rec in log.stdout.decode("utf-8", "replace").split("\x00"): head, _, body = rec.partition("\n") ids = head.split() diff --git a/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh b/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh index 886038fa..a7f9d7cf 100644 --- a/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh @@ -300,6 +300,13 @@ printf '%s\n' '{"spec_archive": ["code"]}' > "$ERRP/.claude/.idd/local.json" ERR_OUT=$(HOME="$W" CLAUDE_PLUGIN_ROOT="$HERE/../../.." WORKDIR="$ERRP/code" GITHUB_REPO=test/repo NUMBER=61 PATH="$W/bin:$PATH" \ bash -c "$(snippet "$CSEC") printf 'EWNOTES=%s\\n' \"\$(printf '%s' \"\$EW_JSON\" | jq -c '.notes // []')\"" 2>&1) +# idd-547-fix3: --skip-branches with gh repo view failing does not read origin/HEAD in --cwd +touch "$FX/fail_repo_view"; : > "$W/gitlog/calls" +OUT=$(PATH="$W/gitlog:$W/bin:$PATH" bash "$SCRIPT" --cwd "$TR" --skip-branches test/repo 61 2>"$W/stderr") +refute_grep "--skip-branches with gh repo view failing reads no origin/HEAD" "refs/remotes/origin/HEAD" "$(cat "$W/gitlog/calls")" +refute_grep "… and adds no default-branch error (the default branch is not needed)" "default branch" "$(field "$OUT" "d['errors']")" +refute_grep "… nor asks GitHub for it" "repo view" "$(field "$OUT" "d['errors']")" +rm -f "$FX/fail_repo_view" assert_eq "idd-close: archive-ref answers error → Step 1.5 does not pass --skip-branches" "[]" \ "$(printf '%s\n' "$ERR_OUT" | sed -n 's/^EWNOTES=//p')" assert_eq "a repeated --cwd is a usage error (exit 2)" 2 "$RC_DUP" diff --git a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh index bcaf1ace..d4898dc4 100755 --- a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh @@ -5,6 +5,7 @@ # # spec-example: spec-on-every-issue / how a spec_archive entry resolves # spec-example: spec-on-every-issue / where the local link check starts +# spec-example: spec-on-every-issue / a top level whose name ends in a space # # Real git repositories under a temporary HOME, so the walk up for the IDD configuration # stops inside the fixture and never reads the developer's own files. @@ -240,6 +241,7 @@ mkrepo "$WORK/c2/sub"; mkdir -p "$WORK/c2/.claude/.idd" printf '{"spec_archive": {"sub": %s, "sub": %s}}\n' "$OPT" "$OPT" > "$WORK/c2/.claude/.idd/local.json" ar "$WORK/c2/sub" assert_eq "the same key written twice in the file → error" error "$ST" +assert_grep "… more than one entry (idd-547-fix3)" "more than one entry" "$(printf '%s' "$OUT" | field reason)" mkrepo "$WORK/c3/sub"; conf "$WORK/c3" "{\"spec_archive\": {\"sub\": $OPT}}"; git -C "$WORK/c3/sub" config remote.origin.pushurl "$WORK/nowhere.git" ar "$WORK/c3/sub" assert_eq "a remote with only a pushurl counts → error" error "$ST" @@ -248,10 +250,12 @@ mkrepo "$WORK/c4/sub"; conf "$WORK/c4" "{\"spec_archive\": {\"sub\": $OPT}}"; mk printf 'URL: %s\n' "$WORK/nowhere.git" > "$WORK/c4/sub/.git/remotes/origin" ar "$WORK/c4/sub" assert_eq "a legacy remotes/origin file counts → error" error "$ST" +assert_grep "… naming the remote (idd-547-fix3)" "origin" "$(printf '%s' "$OUT" | field reason)" mkdir -p "$WORK/c5" "$WORK/c5gd"; conf "$WORK/c5" "{\"spec_archive\": {\"sub\": $OPT}}" git init -q -b master --separate-git-dir "$WORK/c5gd/.git" "$WORK/c5/sub"; git -C "$WORK/c5/sub" commit -q --allow-empty -m base ar "$WORK/c5/sub" assert_eq "a repository made with --separate-git-dir is keyed by its top level → local" local "$ST" +assert_eq "… with the key sub (idd-547-fix3)" sub "$(printf '%s' "$OUT" | field key)" OUT=$(python3 "$SC" archive-ref --cwd "$WORK/a3/sub" 2>/dev/null) refute_grep "reasons do not carry the configuration's absolute path" "$WORK/a3/.claude" "$(printf '%s' "$OUT" | field reason)" @@ -285,6 +289,69 @@ echo x > "$B/HEAD"; git -C "$B" add HEAD; git -C "$B" commit -q -m "a (#14)" lb "$B" 14 assert_eq "a file named HEAD at the top level → still ok" "$BASE" "$(printf '%s' "$OUT" | field base)" +# idd-547-fix3 rows — how a spec_archive entry resolves +mkdir -p "$WORK/d1" "$WORK/d1gd"; conf "$WORK/d1" "{\"spec_archive\": {\"sub\": $OPT}}" +git init -q -b master --separate-git-dir "$WORK/d1gd/meta.git" "$WORK/d1/sub"; git -C "$WORK/d1/sub" commit -q --allow-empty -m base +git -C "$WORK/d1/sub" worktree add -q "$WORK/d1/wt" -b wt 2>/dev/null +ar "$WORK/d1/wt" +assert_eq "a linked worktree of a --separate-git-dir main tree → remote (no key is guessed)" remote "$ST" +assert_eq "… has_remote false (callers stop)" False "$(printf '%s' "$OUT" | field has_remote)" +assert_grep "… saying the main working tree is not recorded" "main working tree" "$(printf '%s' "$OUT" | field reason)" +# its own path is never used as the key: an entry under that name is not read +conf "$WORK/d1" "{\"spec_archive\": {\"wt\": $OPT}}" +ar "$WORK/d1/wt" +assert_eq "… even when an entry names the linked worktree's own path → remote" remote "$ST" +ar "$WORK/d1/sub" +assert_eq "the --separate-git-dir main working tree itself, no entry for sub → remote" remote "$ST" +mkrepo "$WORK/d2/sub"; mkdir -p "$WORK/d2/.claude/.idd" +printf '{"spec_archive": {"sub": %s}, "spec_archive": {"sub": %s}}\n' "$OPT" "$OPT" > "$WORK/d2/.claude/.idd/local.json" +ar "$WORK/d2/sub" +assert_eq "spec_archive written twice at the top level → error" error "$ST" +assert_grep "… more than one entry" "more than one entry" "$(printf '%s' "$OUT" | field reason)" +mkrepo "$WORK/d3/sub"; mkdir -p "$WORK/d3/.claude/.idd" +printf '{"spec_archive": {"sub": {"ref": "local", "branch": "master", "branch": "master"}}}\n' > "$WORK/d3/.claude/.idd/local.json" +ar "$WORK/d3/sub" +assert_eq "a key written twice inside the entry → error" error "$ST" +mkrepo "$WORK/d4/sub"; mkdir -p "$WORK/d4/.claude/.idd" +printf '{"spec_archive": {"sub": %s, "\\u0000duplicate-keys": ["sub"]}, "\\u0000duplicate-keys": ["spec_archive"]}\n' "$OPT" > "$WORK/d4/.claude/.idd/local.json" +ar "$WORK/d4/sub" +assert_eq "a key that looks like an internal marker does not imitate a duplicate → local" local "$ST" +mkrepo "$WORK/d5/sub"; conf "$WORK/d5" '{"spec_archive": null}'; git -C "$WORK/d5/sub" remote add origin "$WORK/nowhere.git" +ar "$WORK/d5/sub" +assert_eq "spec_archive null → remote" remote "$ST" +assert_eq "… has_remote true" True "$(printf '%s' "$OUT" | field has_remote)" +mkrepo "$WORK/d6/sub"; conf "$WORK/d6" "{\"spec_archive\": {\"sub\": $OPT}}"; git -C "$WORK/d6/sub" config remote.origin.vcs hg +ar "$WORK/d6/sub" +assert_eq "a remote with only a vcs counts → error" error "$ST" +assert_grep "… naming it" "origin" "$(printf '%s' "$OUT" | field reason)" +ar "$WORK/none/sub" +assert_eq "no configuration, no remote → has_remote false" False "$(printf '%s' "$OUT" | field has_remote)" + +# idd-547-fix3 rows — where the local link check starts +B="$WORK/le1/repo"; mkrepo "$B"; conf "$WORK/le1" "{\"spec_archive\": {\"repo\": $OPT}}"; BASE=$(git -C "$B" rev-parse HEAD) +git -C "$B" commit -q --allow-empty -m "a (#14)"; git -C "$B" config i18n.logOutputEncoding UTF-16 +lb "$B" 14 +assert_eq "i18n.logOutputEncoding UTF-16 → still the commit before a (#14)" "$BASE" "$(printf '%s' "$OUT" | field base)" + +# idd-547-fix3 — a top level whose name ends in a space +mkdir -p "$WORK/sp"; git init -q -b main "$WORK/sp/odd "; git init -q -b main "$WORK/sp/odd" +for r in "$WORK/sp/odd " "$WORK/sp/odd"; do mkdir -p "$r/openspec/specs"; echo x > "$r/openspec/specs/.keep"; git -C "$r" add -A; git -C "$r" commit -q -m base; done +mkdir -p "$WORK/sp/odd /openspec/changes/archive/2026-11-14-idd-9-c1"; echo p > "$WORK/sp/odd /openspec/changes/archive/2026-11-14-idd-9-c1/proposal.md" +git -C "$WORK/sp/odd " add -A; git -C "$WORK/sp/odd " commit -q -m "archive c1" +mkdir -p "$WORK/sp/odd/openspec/changes/idd-9-c1"; echo p > "$WORK/sp/odd/openspec/changes/idd-9-c1/proposal.md"; git -C "$WORK/sp/odd" add -A; git -C "$WORK/sp/odd" commit -q -m "open c1" +printf '%s\n' '' '**Spec**: change idd-9-c1' > "$WORK/sp/ic.md" +OUT=$(python3 "$SC" archived --file "$WORK/sp/ic.md" --cwd "$WORK/sp/odd " --ref HEAD 2>/dev/null) +assert_eq "archived on 'odd ' with a sibling 'odd' → reads 'odd ' (pass)" pass "$(printf '%s' "$OUT" | field status)" +mv "$WORK/sp/odd" "$WORK/sp/away" +OUT=$(python3 "$SC" archived --file "$WORK/sp/ic.md" --cwd "$WORK/sp/odd " --ref HEAD 2>/dev/null) +assert_eq "archived on 'odd ' alone → pass" pass "$(printf '%s' "$OUT" | field status)" +mv "$WORK/sp/away" "$WORK/sp/odd" +SPB=$(git -C "$WORK/sp/odd " rev-parse HEAD); git -C "$WORK/sp/odd " checkout -q -b feat +mkdir -p "$WORK/sp/odd /openspec/specs/cap"; printf '## Purpose\n\nx\n\n## Requirements\n\n### Requirement: Something new\n\nIt SHALL do it.\n' > "$WORK/sp/odd /openspec/specs/cap/spec.md" +git -C "$WORK/sp/odd " add -A; git -C "$WORK/sp/odd " commit -q -m "add a spec" +OUT=$(python3 "$SC" links --base "$SPB" --cwd "$WORK/sp/odd " 2>/dev/null) +assert_eq "links on 'odd ' with a sibling 'odd' → missing (reads 'odd ')" missing "$(printf '%s' "$OUT" | field status)" + echo "spec-archive-local: the wrapper and idd-all text" WRAP="$PLUGIN/references/spec-wrapper.md" STEP5=$(sed -n '/^## 5\. Close-out/,/^## 6\./p' "$WRAP") @@ -293,14 +360,25 @@ assert_grep "… with the issue number from NUMBER or N" '${NUMBER:-${N:-}}' "$S refute_grep "step 5's JSON readers run isolated: no python3 -c without -I (idd-547-fix2)" "python3 -c 'import json" "$STEP5" # idd-547-fix2: run the step-5 block as written. In local mode a link-base error stops with its reason and # does not go on to print the failed-fetch message. +mkdir -p "$WORK/ghok"; printf '#!/bin/sh\ncase "$1 $2" in "repo view") echo main ;; *) exit 1 ;; esac\n' > "$WORK/ghok/gh" +python3 -c 'import os,sys; os.chmod(sys.argv[1], 0o755)' "$WORK/ghok/gh" printf '%s\n' "$STEP5" | awk '/^```bash$/{b=1; next} b && /^```$/{exit} b' > "$WORK/step5.sh" S5OUT=$(cd "$WORK/lb3/repo" && env HOME="$WORK" CWD="$WORK/lb3/repo" NUMBER=14 GITHUB_REPO=o/r CLAUDE_PLUGIN_ROOT="$PLUGIN" \ bash --norc --noprofile "$WORK/step5.sh" 2>&1 &1 /dev/null +git -C "$WORK/none/sub/origin" branch -q main master # fetchable: only has_remote keeps the fetch from running +S5NR=$(cd "$WORK/none/sub" && env HOME="$WORK" CWD="$WORK/none/sub" NUMBER=14 GITHUB_REPO=o/r CLAUDE_PLUGIN_ROOT="$PLUGIN" \ + PATH="$WORK/ghok:$PATH" bash --norc --noprofile "$WORK/step5.sh" 2>&1 /dev/null)" assert_grep "idd-all Step 3b.6 names link-base for the local mode" "link-base" "$(sed -n '/^#### Step 3b.6/,/^---/p' "$PLUGIN/skills/idd-all/SKILL.md")" print_summary spec-archive-local diff --git a/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh b/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh index 452e26df..faf05c2b 100755 --- a/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh @@ -122,7 +122,7 @@ git init -q -b master "$LR"; mkdir -p "$LR/openspec/specs"; echo x > "$LR/opensp git -C "$LR" add -A; git -C "$LR" commit -q -m base step157_in() { # dir comments-json → STATUS, GRC, OUTALL printf '%s' "$2" > "$WORK/comments.json" - OUTALL=$(cd "$1" && env PATH="$WORK/bin:$PATH" HOME="$WORK" FAKE_COMMENTS="$WORK/comments.json" FAKE_FAIL=0 FAKE_VIEW_FAIL=1 \ + OUTALL=$(cd "$1" && env PATH="$WORK/bin:$PATH" HOME="$WORK" FAKE_COMMENTS="$WORK/comments.json" FAKE_FAIL=0 FAKE_VIEW_FAIL="${VIEW_FAIL_IN:-1}" \ GITHUB_REPO=o/r NUMBER=42 CWD="$1" CLAUDE_PLUGIN_ROOT="$PLUGIN" \ bash --norc --noprofile -c '. "$1"; printf "\nSTATUS=%s\nGRC=%s\n" "$(printf "%s" "$GATE" | python3 -c "import json,sys; print(json.loads(sys.stdin.read()).get(\"status\"))")" "$GATE_RC"' _ "$BLOCK" 2>/dev/null /dev/null "$LO/code/openspec/specs/.keep"; git -C "$LO/code" add -A; git -C "$LO/code" commit -q -m base +git clone -q --bare "$LO/code" "$LO/code/origin" 2>/dev/null +OC="$WORK/originsrc"; git clone -q "$LO/code/origin" "$OC" 2>/dev/null; git -C "$OC" checkout -q -B main +mkdir -p "$OC/openspec/changes/archive/2026-11-14-idd-42-fix-timeout"; echo p > "$OC/openspec/changes/archive/2026-11-14-idd-42-fix-timeout/proposal.md" +git -C "$OC" add -A; git -C "$OC" commit -q -m archive; git -C "$OC" push -q origin main 2>/dev/null +VIEW_FAIL_IN=0 step157_in "$LO/code" "$IC_OK" +assert_eq "no remote, no entry, a local repository named origin beside it → stops (idd-547-fix3)" error "$STATUS" +assert_eq "… and nothing was fetched" "" "$(git -C "$LO/code" rev-parse -q --verify FETCH_HEAD 2>/dev/null)" +assert_grep "… saying the repository has no remote" "this repository has no remote" "$OUTALL" echo "spec-close-gate: the skill text" G="$(sed -n '/^### Step 1.57: /,/^### Step 1.6: /p' "$CLOSE")" diff --git a/plugins/issue-driven-dev/skills/idd-close/SKILL.md b/plugins/issue-driven-dev/skills/idd-close/SKILL.md index 25226754..84d65feb 100644 --- a/plugins/issue-driven-dev/skills/idd-close/SKILL.md +++ b/plugins/issue-driven-dev/skills/idd-close/SKILL.md @@ -565,12 +565,16 @@ else printf '%s' "$ARCH" | python3 -I -c 'import json,sys; d=json.loads(sys.stdin.read()); print("→ spec archive gate: checking local ref %s@%s (this repository has no remote; spec_archive[%r])" % (d["branch"], d["ref"][:7], d["key"]))' 2>/dev/null elif [ "$ARCH_STATUS" = remote ]; then # A declared change is checked against the default branch as the remote has it: no name, or a failed fetch, - # is an error, never a pass on a stale local ref (verify round 2). - DEFAULT_BRANCH=$(gh repo view "$GITHUB_REPO" --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null) || DEFAULT_BRANCH="" - # The commit the fetch returned (FETCH_HEAD), not origin/: a fetch refspec that does not cover the - # default branch leaves the tracking ref where it was (verify round 3). - if [ -n "$DEFAULT_BRANCH" ] && git -C "${CWD:-$PWD}" fetch -q origin -- "$DEFAULT_BRANCH" 2>/dev/null; then - SPEC_REF=$(git -C "${CWD:-$PWD}" rev-parse -q --verify FETCH_HEAD 2>/dev/null) + # is an error, never a pass on a stale local ref (verify round 2). Only when archive-ref says the repository + # has a remote: without one, git would fetch a local path named origin (#547 round 3), so it stops below. + ARCH_HAS_REMOTE=$(printf '%s' "$ARCH" | python3 -I -c 'import json,sys; print(json.loads(sys.stdin.read() or "{}").get("has_remote") is True)' 2>/dev/null) + if [ "$ARCH_HAS_REMOTE" = True ]; then + DEFAULT_BRANCH=$(gh repo view "$GITHUB_REPO" --json defaultBranchRef -q .defaultBranchRef.name 2>/dev/null) || DEFAULT_BRANCH="" + # The commit the fetch returned (FETCH_HEAD), not origin/: a fetch refspec that does not cover the + # default branch leaves the tracking ref where it was (verify round 3). + if [ -n "$DEFAULT_BRANCH" ] && git -C "${CWD:-$PWD}" fetch -q origin -- "$DEFAULT_BRANCH" 2>/dev/null; then + SPEC_REF=$(git -C "${CWD:-$PWD}" rev-parse -q --verify FETCH_HEAD 2>/dev/null) + fi fi fi if [ "$ARCH_STATUS" != local ] && [ "$ARCH_STATUS" != remote ]; then @@ -582,9 +586,11 @@ print(json.dumps({"status": "error", "not_archived": [], "reason": "archive-ref: # #547: say why archive-ref answered remote, so a repository meant for its local branch whose entry was not # found (or whose configuration could not be read) shows the reason next to the failed fetch. GATE=$(printf '%s' "$ARCH" | python3 -I -c 'import json,sys -try: r = json.loads(sys.stdin.read()).get("reason", "") -except Exception: r = "" -print(json.dumps({"status": "error", "not_archived": [], "reason": "the default branch could not be read (gh repo view or git fetch failed)" + ("; archive-ref: " + r if r else "")}))'); GATE_RC=2 +try: d = json.loads(sys.stdin.read()) +except Exception: d = {} +r = d.get("reason", "") if isinstance(d, dict) else "" +why = " (gh repo view or git fetch failed)" if isinstance(d, dict) and d.get("has_remote") is True else ": this repository has no remote, so it was not fetched" +print(json.dumps({"status": "error", "not_archived": [], "reason": "the default branch could not be read" + why + ("; archive-ref: " + r if r else "")}))'); GATE_RC=2 else GATE=$(python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" archived --file "$SPEC_IC" --cwd "${CWD:-$PWD}" --ref "$SPEC_REF"); GATE_RC=$? fi @@ -597,7 +603,7 @@ printf '%s\n' "$GATE" | jq -r '"→ spec archive gate: \(.status) \(.reason)"' |---|---| | `pass`(含 `no behaviour change`、`third-party clone`、舊制留言) | 往下 | | `refuse` | 停下、不 close:列出還沒封存的 change,或 `**Spec**:` 行的問題。常見原因是 PR 還沒合併,或封存 commit 不在合併的範圍裡 | -| `error` | 停下、不 close:留言、預設 branch 或設定讀不到,照原因處理後重跑。`archive-ref:` 開頭的原因說的是 `spec-change.py archive-ref` 為什麼這樣回答:設定的問題(例如設了本機模式的 repo 有 remote、branch 不存在、同一個路徑有兩個條目)就改設定或移除那一條;程式 repo 讀不到(不是 git repo)就在正確的目錄重跑 | +| `error` | 停下、不 close:留言、預設 branch 或設定讀不到,照原因處理後重跑。程式 repo 沒有任何 remote 而 `archive-ref` 回 `remote`(`has_remote` 為 false)時不 fetch,原因寫「this repository has no remote」:要嘛在 `spec_archive` 加這個 repo 的條目,要嘛加 remote。`archive-ref:` 開頭的原因說的是 `spec-change.py archive-ref` 為什麼這樣回答:設定的問題(例如設了本機模式的 repo 有 remote、branch 不存在、同一個路徑有兩個條目)就改設定或移除那一條;程式 repo 讀不到(不是 git repo)就在正確的目錄重跑 | | 沒有輸出、不是 JSON、或上面沒列的 status | 停下、不 close,回報印出的內容 | 這一道和 Step 1.5 一樣是硬性的:不問人、沒有略過的選項。有人在場時要結案,先把 change 封存進預設 branch,或修正 Implementation Complete 的宣告。 From 78dcf7b029d810af5aa4e3845ce5d3b708cf2c9f Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 17:57:33 +0800 Subject: [PATCH 09/13] chore: archive idd-547-fix3 (#547) Co-Authored-By: Claude Opus 5.5 --- .../2026-11-14-idd-547-fix3}/.openspec.yaml | 2 + .../2026-11-14-idd-547-fix3}/proposal.md | 0 .../specs/idd-existing-work-lookup/spec.md | 0 .../specs/spec-on-every-issue/spec.md | 0 .../2026-11-14-idd-547-fix3}/tasks.md | 0 .../specs/idd-existing-work-lookup/spec.md | 3 +- openspec/specs/spec-on-every-issue/spec.md | 40 ++++++++++++++++--- 7 files changed, 38 insertions(+), 7 deletions(-) rename openspec/changes/{idd-547-fix3 => archive/2026-11-14-idd-547-fix3}/.openspec.yaml (54%) rename openspec/changes/{idd-547-fix3 => archive/2026-11-14-idd-547-fix3}/proposal.md (100%) rename openspec/changes/{idd-547-fix3 => archive/2026-11-14-idd-547-fix3}/specs/idd-existing-work-lookup/spec.md (100%) rename openspec/changes/{idd-547-fix3 => archive/2026-11-14-idd-547-fix3}/specs/spec-on-every-issue/spec.md (100%) rename openspec/changes/{idd-547-fix3 => archive/2026-11-14-idd-547-fix3}/tasks.md (100%) diff --git a/openspec/changes/idd-547-fix3/.openspec.yaml b/openspec/changes/archive/2026-11-14-idd-547-fix3/.openspec.yaml similarity index 54% rename from openspec/changes/idd-547-fix3/.openspec.yaml rename to openspec/changes/archive/2026-11-14-idd-547-fix3/.openspec.yaml index f483aa4c..1a60d392 100644 --- a/openspec/changes/idd-547-fix3/.openspec.yaml +++ b/openspec/changes/archive/2026-11-14-idd-547-fix3/.openspec.yaml @@ -1,3 +1,5 @@ schema: spec-driven created: 2026-11-14 created_by: che cheng +archived_by: che cheng +archived_at: 2026-11-14 diff --git a/openspec/changes/idd-547-fix3/proposal.md b/openspec/changes/archive/2026-11-14-idd-547-fix3/proposal.md similarity index 100% rename from openspec/changes/idd-547-fix3/proposal.md rename to openspec/changes/archive/2026-11-14-idd-547-fix3/proposal.md diff --git a/openspec/changes/idd-547-fix3/specs/idd-existing-work-lookup/spec.md b/openspec/changes/archive/2026-11-14-idd-547-fix3/specs/idd-existing-work-lookup/spec.md similarity index 100% rename from openspec/changes/idd-547-fix3/specs/idd-existing-work-lookup/spec.md rename to openspec/changes/archive/2026-11-14-idd-547-fix3/specs/idd-existing-work-lookup/spec.md diff --git a/openspec/changes/idd-547-fix3/specs/spec-on-every-issue/spec.md b/openspec/changes/archive/2026-11-14-idd-547-fix3/specs/spec-on-every-issue/spec.md similarity index 100% rename from openspec/changes/idd-547-fix3/specs/spec-on-every-issue/spec.md rename to openspec/changes/archive/2026-11-14-idd-547-fix3/specs/spec-on-every-issue/spec.md diff --git a/openspec/changes/idd-547-fix3/tasks.md b/openspec/changes/archive/2026-11-14-idd-547-fix3/tasks.md similarity index 100% rename from openspec/changes/idd-547-fix3/tasks.md rename to openspec/changes/archive/2026-11-14-idd-547-fix3/tasks.md diff --git a/openspec/specs/idd-existing-work-lookup/spec.md b/openspec/specs/idd-existing-work-lookup/spec.md index 7ce2378d..2a4aae19 100644 --- a/openspec/specs/idd-existing-work-lookup/spec.md +++ b/openspec/specs/idd-existing-work-lookup/spec.md @@ -221,7 +221,7 @@ When `gh` or `git ls-remote` fails, or when a PR list reaches its limit, the hel --- ### Requirement: The helper can skip the branch lookup -`check-existing-work.sh` SHALL accept `--skip-branches` before the repository argument. With it, the helper SHALL NOT run `git fetch` or list remote-tracking branches in `--cwd`, SHALL treat the clone as having no branches, SHALL NOT add a `git fetch failed` error, and SHALL add a top-level `notes` list that says the branch lookup was skipped. The PR lookups on the repository argument SHALL run as without the flag, and their failures and limits SHALL be reported as before. Without the flag the helper's output SHALL be as before, without a `notes` field. +`check-existing-work.sh` SHALL accept `--skip-branches` before the repository argument. With it, the helper SHALL NOT run `git fetch` or list remote-tracking branches in `--cwd`, SHALL treat the clone as having no branches, SHALL NOT look up the default branch (it asks neither GitHub nor `refs/remotes/origin/HEAD`, a remote-tracking ref; with no branches to compare it is not needed, so no default-branch error is added), SHALL NOT add a `git fetch failed` error, and SHALL add a top-level `notes` list that says the branch lookup was skipped. The PR lookups on the repository argument SHALL run as without the flag, and their failures and limits SHALL be reported as before. Without the flag the helper's output SHALL be as before, without a `notes` field. `idd-close` Step 1.5 SHALL pass `--skip-branches` only when `spec-change.py archive-ref` prints `local` for its working directory (requirement "A repository without a remote can opt into its local default branch" of `spec-on-every-issue`), and SHALL then print that the branch lookup was skipped and that the open PRs were checked on the issue's repository. The open-PR gate itself is unchanged. @@ -238,3 +238,4 @@ When `gh` or `git ls-remote` fails, or when a PR list reaches its limit, the hel | has an `origin` that cannot be fetched | none | yes | has `git fetch failed` | absent | reported as E1 | | has no remote | `--skip-branches` | no | no `git fetch failed` | says the branch lookup was skipped | reported as E1 | | has no remote, the open PR list fails | `--skip-branches` | no | has the PR list failure | says the branch lookup was skipped | verdict `unknown` | +| has an `origin` and its `origin/HEAD`; `gh repo view` fails | `--skip-branches` | no | no default-branch error | says the branch lookup was skipped | none open; `origin/HEAD` is not read | diff --git a/openspec/specs/spec-on-every-issue/spec.md b/openspec/specs/spec-on-every-issue/spec.md index 74d3127e..7a0ede1a 100644 --- a/openspec/specs/spec-on-every-issue/spec.md +++ b/openspec/specs/spec-on-every-issue/spec.md @@ -325,7 +325,7 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL --- ### Requirement: Close requires the issue's change to be archived -`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote`, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails; the reason it prints SHALL then include the reason `archive-ref` gave for answering `remote`, so that a repository meant for the local branch whose entry was not found says why. When the answer is `local`, it SHALL check the commit `archive-ref` returned for the configured branch, not `HEAD`, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch, the commit and the entry's key, and without the configuration file's path. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. +`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote` and `has_remote` is false (the repository has no remote at all), it SHALL stop without fetching and say that the repository has no remote, with the reason `archive-ref` gave; git would otherwise read a local path named `origin` as the remote. When the answer is `remote` otherwise, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails; the reason it prints SHALL then include the reason `archive-ref` gave for answering `remote`, so that a repository meant for the local branch whose entry was not found says why. When the answer is `local`, it SHALL check the commit `archive-ref` returned for the configured branch, not `HEAD`, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch, the commit and the entry's key, and without the configuration file's path. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. #### Scenario: An unarchived change holds the close @@ -359,6 +359,7 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL | marker, `**Spec**: change idd-42-fix-timeout` | no remote; opted into `master`; `HEAD` is on the issue's branch, where the change is archived, and `master` does not have it | stops, naming the change | | marker, `**Spec**: change idd-42-fix-timeout` | no remote and no `spec_archive` entry for the repository | stops, saying the default branch could not be read | | marker, `**Spec**: change idd-42-fix-timeout` | the repository has a remote and the configuration opts it into `local` | stops and prints the reason | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote and no entry; a directory named `origin` beside it holds a repository whose default branch has the change archived | stops, saying the repository has no remote; nothing is fetched | --- ### Requirement: One way to choose the Implementation Complete comment @@ -390,15 +391,15 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL --- ### Requirement: A repository without a remote can opt into its local default branch -`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree (its git directory differs from the common git directory), the directory that holds the common `.git` directory; otherwise its top level, including a repository made with `--separate-git-dir`. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. When the repository's own path cannot be written as a key (it has leading or trailing whitespace), the answer is `remote`; it SHALL NOT fall back to `.`. Reasons name the configuration file by its path relative to the repository, not by an absolute path. It SHALL print one JSON line and exit as follows: +`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree (its git directory differs from the common git directory), the first worktree `git worktree list --porcelain` lists; when that entry is bare, the linked worktree's own top level; when that entry is the common git directory itself (a main working tree made with `--separate-git-dir`, to which git keeps no path back), no key is guessed and the answer is `remote`, with a reason saying the main working tree is not recorded; otherwise (not a linked worktree) its top level, including a repository made with `--separate-git-dir`. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. When the repository's own path cannot be written as a key (it has leading or trailing whitespace), the answer is `remote`; it SHALL NOT fall back to `.`. Reasons name the configuration file by its path relative to the repository, not by an absolute path. It SHALL print one JSON line and exit as follows: -- `remote` (exit 0), with a `reason`, when no configuration file is found; when the file found cannot be read as a JSON object (it is empty, `null`, not JSON, not valid UTF-8, or nested too deeply; a UTF-8 byte order mark is read as usual); when the file has no `spec_archive` field; when `spec_archive` has no entry for the key; or when the repository's path cannot be written as a key. Callers then read the default branch as the remote has it, as before; a repository without any remote then stops there, with this reason. +- `remote` (exit 0), with a `reason`, when no configuration file is found; when the file found cannot be read as a JSON object (it is empty, `null`, not JSON, not valid UTF-8, or nested too deeply; a UTF-8 byte order mark is read as usual); when the file has no `spec_archive` field or the field is `null`; when `spec_archive` has no entry for the key; or when the repository's path cannot be written as a key. Every `remote` answer carries `has_remote`, true when the repository has a remote; callers read the default branch as the remote has it only when it is true, and a repository without any remote stops there, with this reason. - `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at, whatever `HEAD` is), `config` and `key`, when exactly one entry matches the key, it is `{"ref": "local", "branch": ""}`, the repository has no remote, and the branch exists. -- `error` (exit 2), with a `reason`, when `spec_archive` is not an object; when more than one key matches, including the same key written twice in the file; when the matching entry is not an object, its `ref` is not `local`, or its `branch` is missing, not a string, or not a valid branch name (`git check-ref-format --branch` must accept it unchanged, so revision syntax such as `master~1` or `master@{0}` is refused); when the repository has a remote; when the branch does not exist; or when `` is not inside a git repository. +- `error` (exit 2), with a `reason`, when `spec_archive` is not an object; when more than one key matches, including the same key written twice; when `spec_archive` itself, or a key of the matching entry, is written twice in the file (duplicates are found while the file is parsed, never by a marker kept in the data, so no key the file holds can imitate one); when the matching entry is not an object, its `ref` is not `local`, or its `branch` is missing, not a string, or not a valid branch name (`git check-ref-format --branch` must accept it unchanged, so revision syntax such as `master~1` or `master@{0}` is refused); when the repository has a remote; when the branch does not exist; or when `` is not inside a git repository. -A repository has a remote when `git remote` lists a name that has a `url` or a `pushurl` in the git configuration it reads, or a legacy `remotes/` or `branches/` file in its git directory; a `remote` section without either (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. +A repository has a remote when `git remote` lists a name that has a `url`, a `pushurl` or a `vcs` (a remote helper) in the git configuration it reads, or a legacy `remotes/` or `branches/` file in its git directory; a `remote` section without either (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. -`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does first, and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would, without reading ``. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the baseline tag when that tag exists and is an ancestor of `HEAD` other than `HEAD` itself (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message names issue ``: `#` with no letter, digit, `_`, `/` or `-` right before the `#`, the rule of `references/pr-issue-matching.md`, or `/#` where `/` is the configuration's `github_repo` (letter case ignored), the form a commit in a separate code repository uses for the issue repository's issues; in both forms no digit follows the number (`from: first-commit`). `/#` for any other repository does not count. The baseline tag is the configuration's `auto_tag.baseline_format` with `{N}` replaced by ``, or `idd--baseline` when that field is absent, not a string containing `{N}`, or does not give a valid tag name. Commit messages SHALL be read so that no byte a message can hold hides a commit, with signature display turned off and `HEAD` separated from paths, and every commit and parent read SHALL be a hexadecimal object id. It SHALL print `error` (exit 2) when neither base exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits; an empty `` is a usage error (exit 64), like any empty argument of `spec-change.py`. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. +`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does first, and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would, without reading ``. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the baseline tag when that tag exists and is an ancestor of `HEAD` other than `HEAD` itself (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message names issue ``: `#` with no letter, digit, `_`, `/` or `-` right before the `#`, the rule of `references/pr-issue-matching.md`, or `/#` where `/` is the configuration's `github_repo` (letter case ignored), the form a commit in a separate code repository uses for the issue repository's issues; in both forms no digit follows the number (`from: first-commit`). `/#` for any other repository does not count. The baseline tag is the configuration's `auto_tag.baseline_format` with `{N}` replaced by ``, or `idd--baseline` when that field is absent, not a string containing `{N}`, or does not give a valid tag name. Commit messages SHALL be read so that no byte a message can hold hides a commit, with signature display turned off, the output encoding fixed to UTF-8 whatever `i18n.logOutputEncoding` says, and `HEAD` separated from paths, and every commit and parent read SHALL be a hexadecimal object id. It SHALL print `error` (exit 2) when neither base exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits; an empty `` is a usage error (exit 64), like any empty argument of `spec-change.py`. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. `references/spec-wrapper.md` step 5 SHALL ask `link-base` first, with the issue number taken from `NUMBER`, or from `N` when `NUMBER` is empty, and SHALL use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote`, and SHALL stop with the reason when it prints `error` or nothing a JSON reader can take, without also printing the message about a failed fetch. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. @@ -438,6 +439,13 @@ A repository has a remote when `git remote` lists a name that has a `url` or a ` | `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has a `pushurl` and no `url` | `error`, naming the remote | | `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | a legacy `remotes/origin` file in its git directory | `error`, naming the remote | | `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | made with `--separate-git-dir` | `local`, keyed by its top level | +| `spec_archive` names the linked worktree's own path; the main working tree was made with `--separate-git-dir` | `{"ref": "local", "branch": "master"}` | asked from that linked worktree; no remote | `remote`, `has_remote` false, saying the main working tree is not recorded | +| `spec_archive` written twice at the top level | — | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path, and the file also holds a key that looks like an internal marker | `{"ref": "local", "branch": "master"}` | no remote | `local` | +| `"spec_archive": null` | — | has a remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has a `vcs` and no `url` | `error`, naming the remote | +| none | — | no remote | `remote`, `has_remote` false | ##### Example: where the local link check starts @@ -457,3 +465,23 @@ A repository has a remote when `git remote` lists a name that has a `url` or a ` | tag `idd-14-baseline` on `HEAD` itself; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | | `log.showSignature` is on and a commit before `a (#14)` is signed | `ok`, the parent of `a (#14)` | | a file named `HEAD` at the repository's top level; no tag; commits `base`, `a (#14)` | `ok`, the commit `base` | +| `i18n.logOutputEncoding` is `UTF-16`; no tag; commits `base`, `a (#14)` | `ok`, the commit `base` | + +--- +### Requirement: spec-change.py reads the repository that holds --cwd + +Every subcommand of `scripts/spec-change.py` that takes `--cwd` (`archived`, `links`, `preflight`, `archive-ref`, `link-base`) SHALL read the repository whose top level `git rev-parse --show-toplevel` reports for `--cwd`, and SHALL take that path exactly as git prints it, removing only the line ending. A top level whose name ends in whitespace is that directory, never a sibling directory whose name lacks the whitespace. + +#### Scenario: A top level whose name ends in a space + +- **GIVEN** two repositories side by side, `odd ` (with a trailing space) and `odd` +- **WHEN** a subcommand runs with `--cwd` inside `odd ` +- **THEN** it reads `odd ` + +##### Example: a top level whose name ends in a space + +| Repositories | Command | Result | +| --- | --- | --- | +| `odd ` has the change archived, the sibling `odd` does not | `archived --cwd 'odd ' --ref HEAD` | `pass` | +| `odd ` alone, with the change archived | `archived --cwd 'odd ' --ref HEAD` | `pass` | +| `odd ` has a spec added on a branch without an Example, the sibling `odd` has none | `links --base --cwd 'odd '` | `missing` | From dbe3830253155c23197cc167847a759ecc653532 Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 18:03:08 +0800 Subject: [PATCH 10/13] test: preflight reads a top level that ends in a space (#547) Co-Authored-By: Claude Opus 5.5 --- .../scripts/tests/spec-archive-local/test.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh index d4898dc4..7822325c 100755 --- a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh @@ -351,6 +351,15 @@ mkdir -p "$WORK/sp/odd /openspec/specs/cap"; printf '## Purpose\n\nx\n\n## Requi git -C "$WORK/sp/odd " add -A; git -C "$WORK/sp/odd " commit -q -m "add a spec" OUT=$(python3 "$SC" links --base "$SPB" --cwd "$WORK/sp/odd " 2>/dev/null) assert_eq "links on 'odd ' with a sibling 'odd' → missing (reads 'odd ')" missing "$(printf '%s' "$OUT" | field status)" +# preflight, too (round 4 pre-check): 'pf ' has openspec/, its sibling 'pf' does not; a stub spectra on PATH +mkdir -p "$WORK/stubsp"; printf '#!/bin/sh\nexit 0\n' > "$WORK/stubsp/spectra"; python3 -c 'import os,sys; os.chmod(sys.argv[1], 0o755)' "$WORK/stubsp/spectra" +git init -q -b main "$WORK/sp/pf "; git -C "$WORK/sp/pf " commit -q --allow-empty -m base; mkdir -p "$WORK/sp/pf /openspec/specs" +git init -q -b main "$WORK/sp/pf"; git -C "$WORK/sp/pf" commit -q --allow-empty -m base +OUT=$(PATH="$WORK/stubsp:$PATH" python3 "$SC" preflight --cwd "$WORK/sp/pf " --can-write yes 2>/dev/null) +assert_eq "preflight on 'pf ' with a sibling 'pf' → reads 'pf ' (ready)" ready "$(printf '%s' "$OUT" | field status)" +mv "$WORK/sp/pf" "$WORK/sp/pf-away" +OUT=$(PATH="$WORK/stubsp:$PATH" python3 "$SC" preflight --cwd "$WORK/sp/pf " --can-write yes 2>/dev/null) +assert_eq "preflight on 'pf ' alone → ready" ready "$(printf '%s' "$OUT" | field status)" echo "spec-archive-local: the wrapper and idd-all text" WRAP="$PLUGIN/references/spec-wrapper.md" From e9514797aba0ab02a25b6ce779328fe84feb17f8 Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 22:48:22 +0800 Subject: [PATCH 11/13] =?UTF-8?q?fix:=20spec=5Farchive=20verify=20round=20?= =?UTF-8?q?4=20=E2=80=94=20a=20set=20remote=20key=20counts,=20only=20git's?= =?UTF-8?q?=20line=20ending=20goes,=20step=205=20remote=20path=20tested=20?= =?UTF-8?q?(#547)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remotes_of: a url, pushurl or vcs counts when the key is set, whatever its value (blank or empty url) - one_line(): paths git prints lose only the one line ending git appends (a name may end in a newline) - main_tree reason names both cases git does not record (separate git dir not named .git, a submodule); spec and config-protocol state the .git-named and bare cases as they behave - spec: fetch only when has_remote is exactly true, in both requirements; step 5 adds link-base's reason when the fetch fails - tests: blank and empty url, a top level ending in a newline, bare main, .git-named separate git dir, detail assertions for the rows that checked status only, step 5's remote path run as written (fails on a never-fetch mutation) - link-base docstring, config-protocol, CHANGELOG Refs #547 Co-Authored-By: Claude Opus 5.5 --- openspec/changes/idd-547-fix4/.openspec.yaml | 3 + openspec/changes/idd-547-fix4/proposal.md | 16 ++ .../specs/spec-on-every-issue/spec.md | 144 ++++++++++++++++++ openspec/changes/idd-547-fix4/tasks.md | 14 ++ plugins/issue-driven-dev/CHANGELOG.md | 11 +- .../references/config-protocol.md | 4 +- .../references/spec-wrapper.md | 5 +- .../issue-driven-dev/scripts/spec-change.py | 32 ++-- .../scripts/tests/check-existing-work/test.sh | 3 + .../scripts/tests/spec-archive-local/test.sh | 55 ++++++- .../scripts/tests/spec-close-gate/test.sh | 12 +- 11 files changed, 275 insertions(+), 24 deletions(-) create mode 100644 openspec/changes/idd-547-fix4/.openspec.yaml create mode 100644 openspec/changes/idd-547-fix4/proposal.md create mode 100644 openspec/changes/idd-547-fix4/specs/spec-on-every-issue/spec.md create mode 100644 openspec/changes/idd-547-fix4/tasks.md diff --git a/openspec/changes/idd-547-fix4/.openspec.yaml b/openspec/changes/idd-547-fix4/.openspec.yaml new file mode 100644 index 00000000..f483aa4c --- /dev/null +++ b/openspec/changes/idd-547-fix4/.openspec.yaml @@ -0,0 +1,3 @@ +schema: spec-driven +created: 2026-11-14 +created_by: che cheng diff --git a/openspec/changes/idd-547-fix4/proposal.md b/openspec/changes/idd-547-fix4/proposal.md new file mode 100644 index 00000000..52b38e3f --- /dev/null +++ b/openspec/changes/idd-547-fix4/proposal.md @@ -0,0 +1,16 @@ +## Why + +第 4 輪 verify(#547 comment 6879033245)判定 PASS、0 Blocking,但有 4 列 MEDIUM 的 In-scope fix:`remotes_of()` 用去掉空白後的值判斷 remote 是否存在(url 設成空白或空字串時漏算)、`repo_top()` 去掉所有結尾換行而不是只去 git 加的那一個、幾列 Example 的測試只驗 status、spec-wrapper 第 5 步的 remote 路徑沒有測試。另有 7 列 LOW/INFO:規格兩處對 `has_remote` 的說法不一致、主工作樹的規則沒有寫出 `.git` 命名與 submodule 的情況、bare 主 repo 沒有寫明、第 5 步 fetch 失敗時丟掉 `link-base` 的原因,以及 docstring 與 issue 文字。 + +## What Changes + +- `has_remote` 正好是 true 才 fetch,close 與 archive-ref 兩條 requirement 說法一致。 +- remote 是否存在看 `url`、`pushurl`、`vcs` 是否設定,不看值。 +- 主工作樹:照實寫出 git 不記錄主工作樹的兩種情況(其他名稱的 separate git dir、submodule),以及 `.git` 命名時 git 回報的路徑;bare 主 repo 的 linked worktree 以自己的路徑為 key。 +- 讀 git 印出的路徑只去一個結尾換行;Example 補換行結尾與 `preflight` 的列。 +- 第 5 步 fetch 失敗時附上 `link-base` 的原因。 + +## Impact + +- `plugins/issue-driven-dev/scripts/spec-change.py`、`references/spec-wrapper.md`、`references/config-protocol.md`、`CHANGELOG.md` +- 測試:`scripts/tests/spec-archive-local`、`spec-close-gate`、`check-existing-work` diff --git a/openspec/changes/idd-547-fix4/specs/spec-on-every-issue/spec.md b/openspec/changes/idd-547-fix4/specs/spec-on-every-issue/spec.md new file mode 100644 index 00000000..efc9b21c --- /dev/null +++ b/openspec/changes/idd-547-fix4/specs/spec-on-every-issue/spec.md @@ -0,0 +1,144 @@ +## MODIFIED Requirements + +### Requirement: Close requires the issue's change to be archived + +`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote` and `has_remote` is not exactly true (false when the repository has no remote at all; missing or not a boolean when the answer cannot be trusted), it SHALL stop without fetching and say that the repository has no remote, with the reason `archive-ref` gave; git would otherwise read a local path named `origin` as the remote. When the answer is `remote` and `has_remote` is true, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails; the reason it prints SHALL then include the reason `archive-ref` gave for answering `remote`, so that a repository meant for the local branch whose entry was not found says why. When the answer is `local`, it SHALL check the commit `archive-ref` returned for the configured branch, not `HEAD`, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch, the commit and the entry's key, and without the configuration file's path. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. + +#### Scenario: An unarchived change holds the close + +- **GIVEN** an Implementation Complete comment with the marker and `**Spec**: change idd-42-fix-timeout` +- **AND** `openspec/changes/idd-42-fix-timeout/` still exists on the default branch +- **WHEN** `idd-close` runs its gates +- **THEN** it does not close the issue and says the change is not archived + +#### Scenario: A repository without a remote, opted in + +- **GIVEN** the code repository has no remote and the IDD configuration above it maps the repository's path to `{"ref": "local", "branch": "master"}` +- **AND** the change is archived on `master` +- **WHEN** `idd-close` runs its gates +- **THEN** the gate passes without fetching and prints the local branch and commit it checked + +##### Example: the close gate reads the default branch + +| Newest Implementation Complete comment | On the default branch | Close gate | +| --- | --- | --- | +| marker, `**Spec**: change idd-42-fix-timeout` | the change is archived | passes | +| marker, `**Spec**: change idd-42-fix-timeout` | archived on the issue's branch only, not yet merged | stops, naming the change | +| marker, no `**Spec**:` line | not read | stops, naming the missing line | +| no marker, no `**Spec**:` line | not read | passes | +| the issue has no Implementation Complete comment | not read | passes | +| the comments could not be fetched | not read | stops, saying the comments could not be read | +| marker, `**Spec**: change idd-42-fix-timeout` | the default branch cannot be fetched | stops, saying the default branch could not be read | +| marker, `**Spec**: no behaviour change` | the default branch cannot be fetched | passes; the branch is not read | +| marker, `**Spec**: change idd-42-fix-timeout` | the remote's default branch dropped the archive, the local tracking ref did not move | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts the repository into its local `master`, where the change is archived | passes; prints `local ref master@` | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; the configuration opts in, the change is not archived on `master` | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote; opted into `master`; `HEAD` is on the issue's branch, where the change is archived, and `master` does not have it | stops, naming the change | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote and no `spec_archive` entry for the repository | stops, saying the default branch could not be read | +| marker, `**Spec**: change idd-42-fix-timeout` | the repository has a remote and the configuration opts it into `local` | stops and prints the reason | +| marker, `**Spec**: change idd-42-fix-timeout` | no remote and no entry; a directory named `origin` beside it holds a repository whose default branch has the change archived | stops, saying the repository has no remote; nothing is fetched | + + +### Requirement: A repository without a remote can opt into its local default branch + +`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree (its git directory differs from the common git directory), the first worktree `git worktree list --porcelain` lists; when that entry is bare, the linked worktree's own top level; when that entry is the common git directory itself, git does not record where the main working tree is (a repository whose git directory was made apart with `--separate-git-dir` under a name other than `.git`, or a submodule), so no key is guessed and the answer is `remote`, with a reason saying the main working tree is not recorded; a git directory made apart under the name `.git` is reported by git as the directory that holds it, and that directory is then the key, since git treats it as a working tree of the same repository; otherwise (not a linked worktree) its top level, including a repository made with `--separate-git-dir`. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. When the repository's own path cannot be written as a key (it has leading or trailing whitespace), the answer is `remote`; it SHALL NOT fall back to `.`. Reasons name the configuration file by its path relative to the repository, not by an absolute path. It SHALL print one JSON line and exit as follows: + +- `remote` (exit 0), with a `reason`, when no configuration file is found; when the file found cannot be read as a JSON object (it is empty, `null`, not JSON, not valid UTF-8, or nested too deeply; a UTF-8 byte order mark is read as usual); when the file has no `spec_archive` field or the field is `null`; when `spec_archive` has no entry for the key; or when the repository's path cannot be written as a key. Every `remote` answer carries `has_remote`, true when the repository has a remote; callers read the default branch as the remote has it only when it is true, and a repository without any remote stops there, with this reason. +- `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at, whatever `HEAD` is), `config` and `key`, when exactly one entry matches the key, it is `{"ref": "local", "branch": ""}`, the repository has no remote, and the branch exists. +- `error` (exit 2), with a `reason`, when `spec_archive` is not an object; when more than one key matches, including the same key written twice; when `spec_archive` itself, or a key of the matching entry, is written twice in the file (duplicates are found while the file is parsed, never by a marker kept in the data, so no key the file holds can imitate one); when the matching entry is not an object, its `ref` is not `local`, or its `branch` is missing, not a string, or not a valid branch name (`git check-ref-format --branch` must accept it unchanged, so revision syntax such as `master~1` or `master@{0}` is refused); when the repository has a remote; when the branch does not exist; or when `` is not inside a git repository. + +A repository has a remote when `git remote` lists a name for which a `url`, a `pushurl` or a `vcs` (a remote helper) is set in the git configuration it reads, whatever its value (an empty or blank `url` counts), or a legacy `remotes/` or `branches/` file in its git directory; a `remote` section without either (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. + +`spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does first, and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would, without reading ``. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the baseline tag when that tag exists and is an ancestor of `HEAD` other than `HEAD` itself (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message names issue ``: `#` with no letter, digit, `_`, `/` or `-` right before the `#`, the rule of `references/pr-issue-matching.md`, or `/#` where `/` is the configuration's `github_repo` (letter case ignored), the form a commit in a separate code repository uses for the issue repository's issues; in both forms no digit follows the number (`from: first-commit`). `/#` for any other repository does not count. The baseline tag is the configuration's `auto_tag.baseline_format` with `{N}` replaced by ``, or `idd--baseline` when that field is absent, not a string containing `{N}`, or does not give a valid tag name. Commit messages SHALL be read so that no byte a message can hold hides a commit, with signature display turned off, the output encoding fixed to UTF-8 whatever `i18n.logOutputEncoding` says, and `HEAD` separated from paths, and every commit and parent read SHALL be a hexadecimal object id. It SHALL print `error` (exit 2) when neither base exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits; an empty `` is a usage error (exit 64), like any empty argument of `spec-change.py`. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. + +`references/spec-wrapper.md` step 5 SHALL ask `link-base` first, with the issue number taken from `NUMBER`, or from `N` when `NUMBER` is empty, and SHALL use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote` with `has_remote` true, SHALL stop without fetching when it prints `remote` with `has_remote` not exactly true, saying the repository has no remote, and SHALL stop with the reason when it prints `error` or nothing a JSON reader can take, without also printing the message about a failed fetch. When the fetch of the default branch fails it SHALL stop with the message about a failed fetch and add `link-base`'s reason when there is one. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. + +#### Scenario: An entry for a repository that later gained a remote + +- **GIVEN** a configuration entry `{"ref": "local", "branch": "master"}` for a repository +- **AND** a remote was added to that repository afterwards +- **WHEN** `archive-ref` runs for it +- **THEN** it prints `error` and names the remote, instead of reading the local branch + +##### Example: how a spec_archive entry resolves + +| Configuration found | Entry for the repository's path | Repository | `archive-ref` | +| --- | --- | --- | --- | +| none | — | no remote | `remote` | +| a file without `spec_archive` | — | no remote | `remote` | +| `spec_archive` names another path only | — | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local`, `master` and its commit | +| `spec_archive` names this path as `./sub/` | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | has a remote `origin` | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "trunk"}` | no remote, no branch `trunk` | `error` | +| `spec_archive` names this path | `{"ref": "remote", "branch": "master"}` | no remote | `error` | +| `spec_archive` names this path | `{"ref": "local"}` | no remote | `error` | +| `spec_archive` is a list | — | no remote | `error` | +| the file is not JSON | — | no remote | `remote`, saying the file could not be read | +| the file is empty, or holds `null` | — | no remote | `remote` | +| the file starts with a UTF-8 byte order mark | `{"ref": "local", "branch": "master"}` | no remote, `master` exists | `local` | +| `spec_archive` names this path as `sub` and as `./sub/` | both `{"ref": "local", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master~1"}` | no remote | `error`, not a branch name | +| `spec_archive` names this path as ` sub` | `{"ref": "local", "branch": "master"}` | no remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | no remote; the global git configuration has `[remote "origin"]` with only `prune = true` | `local` | +| `spec_archive` names the main working tree | `{"ref": "local", "branch": "master"}` | asked from a linked worktree of it | `local` | +| the new file without `spec_archive`, the legacy file beside it with an entry | — | no remote | `remote` (the new file wins) | +| a file above the home directory with an entry | — | no remote | `remote` (not read) | +| `spec_archive` has `.` | `{"ref": "local", "branch": "master"}` | another repository below, whose directory name ends in a space | `remote` (no fallback to `.`) | +| `spec_archive` names this path twice, written as the same key | `{"ref": "local", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has a `pushurl` and no `url` | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | a legacy `remotes/origin` file in its git directory | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | made with `--separate-git-dir` | `local`, keyed by its top level | +| `spec_archive` names the linked worktree's own path; the main working tree was made with `--separate-git-dir meta.git` | `{"ref": "local", "branch": "master"}` | asked from that linked worktree; no remote | `remote`, `has_remote` false, saying the main working tree is not recorded | +| `spec_archive` names `store`; the main working tree was made with `--separate-git-dir store/.git` | `{"ref": "local", "branch": "master"}` | asked from a linked worktree; no remote | `local`, keyed by `store`, at the same repository's `master` | +| `spec_archive` names the linked worktree's own path; the main repository is bare | `{"ref": "local", "branch": "master"}` | asked from that linked worktree; no remote | `local`, keyed by its own path | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has the `url` ` ` (a blank) | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has an empty `url` | `error`, naming the remote | +| `spec_archive` written twice at the top level | — | no remote | `error`, more than one entry | +| `spec_archive` names this path | `{"ref": "local", "branch": "master", "branch": "master"}` | no remote | `error`, more than one entry | +| `spec_archive` names this path, and the file also holds a key that looks like an internal marker | `{"ref": "local", "branch": "master"}` | no remote | `local` | +| `"spec_archive": null` | — | has a remote | `remote` | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has a `vcs` and no `url` | `error`, naming the remote | +| none | — | no remote | `remote`, `has_remote` false | + +##### Example: where the local link check starts + +| Repository (opted into local `master`) | `link-base --issue 14` | +| --- | --- | +| tag `idd-14-baseline` on an ancestor of `HEAD` | `ok`, the tag's commit, `from: baseline-tag` | +| no tag; commits `base`, `a (#14)`, `b (Refs #14)` | `ok`, the commit `base`, `from: first-commit` | +| no tag; the only commit naming a 14 says `#142` | `error` | +| no tag; the first commit with `#14` is the root commit | `error` | +| the repository is not opted in | `remote` | +| the repository is not opted in, `--issue abc` | `remote` | +| no tag; commits `base`, `see o/r#14`, `x#14`, `fix (#14)` | `ok`, the parent of `fix (#14)` | +| tag `idd-14-baseline` on a commit that is not an ancestor of `HEAD`; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | +| `auto_tag.baseline_format` is `start-{N}`, tag `start-14` on an ancestor | `ok`, that tag's commit, `from: baseline-tag` | +| no tag; a commit before `a (#14)` has the byte 0x1e in its message | `ok`, the parent of `a (#14)` | +| `github_repo` is `o/issues`; no tag; commits `base`, `see other/r#14`, `fix (O/ISSUES#14)` | `ok`, the parent of `fix (O/ISSUES#14)` | +| tag `idd-14-baseline` on `HEAD` itself; commits `base`, `a (#14)` | `ok`, the commit `base`, `from: first-commit` | +| `log.showSignature` is on and a commit before `a (#14)` is signed | `ok`, the parent of `a (#14)` | +| a file named `HEAD` at the repository's top level; no tag; commits `base`, `a (#14)` | `ok`, the commit `base` | +| `i18n.logOutputEncoding` is `UTF-16`; no tag; commits `base`, `a (#14)` | `ok`, the commit `base` | + + +### Requirement: spec-change.py reads the repository that holds --cwd + +Every subcommand of `scripts/spec-change.py` that takes `--cwd` (`archived`, `links`, `preflight`, `archive-ref`, `link-base`) SHALL read the repository whose top level `git rev-parse --show-toplevel` reports for `--cwd`, and SHALL take that path exactly as git prints it, removing only the one line ending git appends (the name of the directory can itself end in a space or a newline). A top level whose name ends in whitespace is that directory, never a sibling directory whose name lacks the whitespace. + +#### Scenario: A top level whose name ends in whitespace + +- **GIVEN** two repositories side by side, `odd ` (with a trailing space) and `odd` +- **WHEN** a subcommand runs with `--cwd` inside `odd ` +- **THEN** it reads `odd ` + +##### Example: a top level whose name ends in whitespace + +| Repositories | Command | Result | +| --- | --- | --- | +| `odd ` has the change archived, the sibling `odd` does not | `archived --cwd 'odd ' --ref HEAD` | `pass` | +| `odd ` alone, with the change archived | `archived --cwd 'odd ' --ref HEAD` | `pass` | +| `odd ` has a spec added on a branch without an Example, the sibling `odd` has none | `links --base --cwd 'odd '` | `missing` | +| `pf ` has an `openspec/` directory, the sibling `pf` does not | `preflight --cwd 'pf ' --can-write yes` | `ready` | +| `pf ` alone, with an `openspec/` directory | `preflight --cwd 'pf ' --can-write yes` | `ready` | +| `nl` followed by a newline has the change archived, the sibling `nl` does not | `archived` with `--cwd` that directory, `--ref HEAD` | `pass` | diff --git a/openspec/changes/idd-547-fix4/tasks.md b/openspec/changes/idd-547-fix4/tasks.md new file mode 100644 index 00000000..d06b81ea --- /dev/null +++ b/openspec/changes/idd-547-fix4/tasks.md @@ -0,0 +1,14 @@ +## 1. 測試先行 + +- [x] 1.1 requirement「A repository without a remote can opt into its local default branch」— spec-archive-local:Example 新增的列(`.git` 命名的 separate git dir、bare 主 repo、空白與空字串的 url),`master~1` 與條目內重複鍵兩列補原因斷言,linked worktree 那一列補 `has_remote` 與原因;第 5 步 remote 路徑照原文執行一次(有可 fetch 的 origin、沒有條目),fetch 失敗時附上 `link-base` 的原因。驗證:空白與空字串的 url、fetch 失敗的原因在改之前失敗;第 5 步 remote 路徑在「永遠不 fetch」的變異上失敗。 +- [x] 1.2 requirement「spec-change.py reads the repository that holds --cwd」— spec-archive-local:Example 改名為 a top level whose name ends in whitespace,補換行結尾與 `preflight` 的列。驗證:換行結尾那列在改之前失敗。 +- [x] 1.3 requirement「Close requires the issue's change to be archived」— spec-close-gate:「stops, naming the change」各列補 `not_archived` 的斷言;requirement「The helper can skip the branch lookup」— check-existing-work 第 4 列補 fetch、notes 與 open PR 的斷言。 + +## 2. 程式與文件 + +- [x] 2.1 `spec-change.py`(`one_line`、`remotes_of`、原因文字、link-base docstring)、spec-wrapper 第 5 步。驗證:1.1–1.3 通過。 +- [x] 2.2 config-protocol 與 CHANGELOG 寫到目前的規則;issue 的 Proposal 與 Expected 第 3 項註明沒有 remote 時不 fetch。 + +## 3. 收尾 + +- [x] 3.1 run-all-tests.sh 與連結檢查。驗證:結束碼 0,links 回 ok。 diff --git a/plugins/issue-driven-dev/CHANGELOG.md b/plugins/issue-driven-dev/CHANGELOG.md index 1227eb10..1d5ad2d8 100644 --- a/plugins/issue-driven-dev/CHANGELOG.md +++ b/plugins/issue-driven-dev/CHANGELOG.md @@ -18,12 +18,13 @@ Version number left to the release. (`local ref @`); Step 1.5 skips the branch lookup (`check-existing-work.sh --skip-branches`) and still checks open PRs on the issue repository; the link check of `references/spec-wrapper.md` step 5 starts at the issue's baseline tag, or at the parent of the oldest commit naming `#N`. An entry is accepted only while the - repository has no remote at all (a remote with a url, a pushurl or a vcs); with a remote it is an error, never a - silent fallback. Without an entry nothing changes, and a configuration file that cannot be read as a JSON object, + repository has no remote at all (a remote with a url, a pushurl or a vcs set, whatever the value); with a remote + it is an error, never a silent fallback. Without an entry nothing changes, and a configuration file that cannot be read as a JSON object, or `"spec_archive": null`, counts as having no entry, so it does not block a repository that never set the field. A key written twice is an error, found while the file is parsed. The branch must be a branch name, and the check - reads it whatever `HEAD` is; a linked worktree uses its main working tree's key, and a linked worktree of a - repository made with `--separate-git-dir` (whose main working tree git does not record) gets no entry. A + reads it whatever `HEAD` is; a linked worktree uses its main working tree's key (its own path when the main + repository is bare), and a linked worktree whose main working tree git does not record (a `--separate-git-dir` + repository whose git directory is not named `.git`, or a submodule) gets no entry. A repository with no remote and no entry now stops without fetching, in Step 1.57 and in the link check: git would read a local path named `origin` as the remote. The link check finds the issue in a separate code repository's commits written as `owner/repo#N` for the configured `github_repo`, reading `git log` in UTF-8 whatever @@ -35,7 +36,7 @@ Version number left to the release. - **`spec-change.py` reads the repository whose top level ends in whitespace (#547).** `archived`, `links` and `preflight` stripped the top level `git rev-parse --show-toplevel` printed, so a repository named `odd ` (with a trailing space) was read as a sibling directory `odd`, or failed when there was none. They now take the path as - git prints it, removing only the line ending. + git prints it, removing only the one line ending git appends. - **The edit-run suite has a time limit of its own (#508, #519).** Most of its run time is CPU time (about 65 s on an 18-core Mac), so it takes longer on a busy machine: run alone it took 84 s at a load near 20 and 123 s at diff --git a/plugins/issue-driven-dev/references/config-protocol.md b/plugins/issue-driven-dev/references/config-protocol.md index 7c2687bf..427ddeaf 100644 --- a/plugins/issue-driven-dev/references/config-protocol.md +++ b/plugins/issue-driven-dev/references/config-protocol.md @@ -497,13 +497,13 @@ Which branch the spec checks read for a code repository that **deliberately has | Part | Meaning | |------|---------| -| key | The code repository's main working tree (for a linked worktree, the first entry `git worktree list` prints; git keeps no path back to the main working tree of a repository made with `--separate-git-dir`, so a linked worktree of one gets no entry — run from the main working tree), relative to the directory that holds this `.claude/` (both resolved through symbolic links). `./sub/`, `sub/` and `sub` name the same path; `.` names the directory of this configuration itself; a key that is empty or has leading or trailing whitespace names nothing. Two keys that name the same path are an error | +| key | The code repository's main working tree (for a linked worktree, the first entry `git worktree list` prints. When the main repository is bare, each linked worktree is keyed by its own path, so each needs its own entry. When git does not record the main working tree — a git directory made apart with `--separate-git-dir` under a name other than `.git`, or a submodule — a linked worktree gets no entry: run from the main working tree. A git directory made apart under the name `.git` is reported by git as the directory that holds it, and that directory is the key), relative to the directory that holds this `.claude/` (both resolved through symbolic links). `./sub/`, `sub/` and `sub` name the same path; `.` names the directory of this configuration itself; a key that is empty or has leading or trailing whitespace names nothing. Two keys that name the same path are an error | | `ref` | Must be `local`. Any other value is an error | | `branch` | The local branch that plays the default branch: a branch name that `git check-ref-format --branch` accepts unchanged (not `master~1` or `master@{0}`). Required: without a remote there is no `origin/HEAD` to read, and `HEAD` is only the branch checked out now. The check reads this branch whatever `HEAD` is | Read by `scripts/spec-change.py archive-ref` (and `link-base`), which walks up from the **code repository's** main working tree to the first IDD configuration — the same walk as the other fields, new file before legacy file at each level, stopping after `$HOME` (`/` itself is not read). A file that cannot be read as a JSON object (empty, `null`, not JSON, not UTF-8), and `"spec_archive": null`, are treated as having no entry, so a repository that never set the field is not blocked by it. Every `remote` answer carries `has_remote`: when it is false the repository has no remote at all, and Step 1.57 and the link check stop without fetching, with that reason (git would otherwise read a local path named `origin` as the remote). Write the entry in the issue repository's configuration; do not add a configuration to the code repository just for this, because a file without `github_repo` there would be the first one the other skills find. -**Accepted only while the repository has no remote at all** — no name that `git remote` lists with a `url`, a `pushurl` or a `vcs` (a remote helper), and no legacy `remotes/` or `branches/` file in its git directory; a `remote` section with none of them (a global `remote.origin.prune`, say) does not count. An entry for a repository that has any remote is an error, not a silent fallback to the remote: an entry written because there was no remote must not outlive that reason. Other errors: `spec_archive` is not an object, two entries name the repository's path, a key is written twice (`spec_archive` itself, a key of it that names this path, or a key of the matching entry — found while the file is parsed, so no key the file holds can imitate a duplicate), the entry is not `{"ref": "local", "branch": ""}`, or the branch does not exist. A repository whose own path cannot be written as a key (it ends in a space, say) gets no entry: it never borrows the `.` entry of the configuration's own directory. Reasons name the configuration file relative to the code repository, never by an absolute path. +**Accepted only while the repository has no remote at all** — no name that `git remote` lists with a `url`, a `pushurl` or a `vcs` (a remote helper) set, whatever the value (an empty or blank `url` counts), and no legacy `remotes/` or `branches/` file in its git directory; a `remote` section with none of them (a global `remote.origin.prune`, say) does not count. An entry for a repository that has any remote is an error, not a silent fallback to the remote: an entry written because there was no remote must not outlive that reason. Other errors: `spec_archive` is not an object, two entries name the repository's path, a key is written twice (`spec_archive` itself, a key of it that names this path, or a key of the matching entry — found while the file is parsed, so no key the file holds can imitate a duplicate), the entry is not `{"ref": "local", "branch": ""}`, or the branch does not exist. A repository whose own path cannot be written as a key (it ends in a space, say) gets no entry: it never borrows the `.` entry of the configuration's own directory. Reasons name the configuration file relative to the code repository, never by an absolute path. What it changes, and nothing else: diff --git a/plugins/issue-driven-dev/references/spec-wrapper.md b/plugins/issue-driven-dev/references/spec-wrapper.md index 60167330..01cd8f5e 100644 --- a/plugins/issue-driven-dev/references/spec-wrapper.md +++ b/plugins/issue-driven-dev/references/spec-wrapper.md @@ -158,7 +158,10 @@ fi if [ -n "$SPEC_BASE" ]; then python3 "${CLAUDE_PLUGIN_ROOT}/scripts/spec-change.py" links --base "$SPEC_BASE" --cwd "$CWD" elif [ "$LB_STATUS" = remote ] && [ "${LB_HAS_REMOTE:-}" = True ]; then - echo "✗ spec close-out: cannot find where this branch left the default branch (gh repo view, git fetch or git merge-base failed); stopping" >&2 + echo "✗ spec close-out: cannot find where this branch left the default branch (gh repo view, git fetch or git merge-base failed)$(printf '%s' "$LB" | python3 -I -c 'import json,sys +try: r = json.loads(sys.stdin.read()).get("reason", "") +except Exception: r = "" +print("; link-base: " + r if r else "")' 2>/dev/null); stopping" >&2 fi ``` diff --git a/plugins/issue-driven-dev/scripts/spec-change.py b/plugins/issue-driven-dev/scripts/spec-change.py index 097aebc2..1f2f34b4 100755 --- a/plugins/issue-driven-dev/scripts/spec-change.py +++ b/plugins/issue-driven-dev/scripts/spec-change.py @@ -48,8 +48,11 @@ link-base --cwd --issue (#547) Where does the link check start in local mode? The baseline tag (auto_tag.baseline_format, default - idd--baseline) when it is an ancestor of HEAD, else the parent of the oldest commit of HEAD's - history naming # (pr-issue-matching.md guards). Remote never reads --issue. + idd--baseline) when it is an ancestor of HEAD other than HEAD itself, else the parent of the oldest + commit of HEAD's history naming the issue: # (pr-issue-matching.md guards) or the configuration's + github_repo as /# (letter case ignored); neither, or a root commit → error. git log is read + in UTF-8 with signatures off, and every id must be hexadecimal. The configuration is resolved as archive-ref + does first: remote (with has_remote) and error never read --issue. {"status": remote|ok|error, "base": "", "from": baseline-tag|first-commit, "reason": "..."} exit 0 (remote, ok), 2 (error) @@ -132,13 +135,18 @@ def git_text(cwd, *args): return git(cwd, *args).stdout.decode("utf-8") +def one_line(text): + """A path git printed on one line: only the line ending git appends goes (a name may end in a space or a newline).""" + return text[:-1] if text.endswith("\n") else text + + def repo_top(cwd): if not os.path.isdir(cwd): raise Fail(f"{cwd} is not a directory") p = git(cwd, "rev-parse", "--show-toplevel", check=False) if p.returncode != 0: raise Fail(f"{cwd} is not inside a git repository") - return p.stdout.decode("utf-8").rstrip("\n") # a path may end in a space: only the newline goes + return one_line(p.stdout.decode("utf-8")) # a path may end in whitespace: only git's line ending goes SPEC_DIR_RE = re.compile(r"^spec_dir:(.*)$") @@ -469,8 +477,8 @@ def cmd_preflight(argv): return emit({"status": "third-party", "message": "the account cannot write to this repository: " "implement without a spec change and declare `**Spec**: third-party clone`"}, 0) # Plain --git-dir / --git-common-dir (relative to top when not absolute): --path-format needs git 2.31. - gd = os.path.join(top, git_text(top, "rev-parse", "--git-dir").rstrip("\n")) - cd = os.path.join(top, git_text(top, "rev-parse", "--git-common-dir").rstrip("\n")) + gd = os.path.join(top, one_line(git_text(top, "rev-parse", "--git-dir"))) + cd = os.path.join(top, one_line(git_text(top, "rev-parse", "--git-common-dir"))) if os.path.realpath(gd) != os.path.realpath(cd): return emit({"status": "linked-worktree", "message": "this is a git linked worktree; spectra writes into " "the main working tree from here. Run in the main tree or a standalone clone"}, 1) @@ -637,8 +645,8 @@ def main_tree(top): and the top level is used; an entry that is the common git directory itself means git does not know where the main working tree is (a repository made with --separate-git-dir keeps no path back to it), and no key is guessed. Otherwise the top level (a --separate-git-dir repository asked from its main working tree included).""" - gd = os.path.realpath(os.path.join(top, git_text(top, "rev-parse", "--git-dir").rstrip("\n"))) - common = os.path.realpath(os.path.join(top, git_text(top, "rev-parse", "--git-common-dir").rstrip("\n"))) + gd = os.path.realpath(os.path.join(top, one_line(git_text(top, "rev-parse", "--git-dir")))) + common = os.path.realpath(os.path.join(top, one_line(git_text(top, "rev-parse", "--git-common-dir")))) if gd == common: return os.path.realpath(top) path, bare = first_worktree(top) @@ -691,7 +699,7 @@ def remotes_of(top): """Names of the remotes git can use here: listed by `git remote` and given a url, a pushurl or a vcs (a remote helper), or a legacy remotes/ or branches/ file in the git directory. A section with none of them (remote.origin.prune) is no remote.""" - gd = os.path.join(top, git_text(top, "rev-parse", "--git-common-dir").rstrip("\n")) + gd = os.path.join(top, one_line(git_text(top, "rev-parse", "--git-common-dir"))) names = set(n for n in git_text(top, "remote").splitlines() if n) for d in ("remotes", "branches"): # legacy files: newer git no longer lists them, fetch may still read them try: @@ -700,7 +708,8 @@ def remotes_of(top): pass out = [] for name in names: - has = any(git(top, "config", "--get-all", f"remote.{name}.{k}", check=False).stdout.strip() + # the key being set is what counts, whatever its value: a url of " " names a directory git can fetch from + has = any(git(top, "config", "--get-all", f"remote.{name}.{k}", check=False).returncode == 0 for k in ("url", "pushurl", "vcs")) has = has or any(os.path.isfile(os.path.join(gd, d, name)) for d in ("remotes", "branches")) if has: @@ -719,8 +728,9 @@ def remote(reason): return {"status": "remote", "reason": reason, "has_remote": bool(remotes_of(top))} if tree is None: - return remote("this is a linked worktree whose main working tree git does not record (its git directory " - "was made apart with --separate-git-dir); spec_archive is read only from the main working tree") + return remote("this is a linked worktree whose main working tree git does not record (a repository whose " + "git directory was made apart with --separate-git-dir, or a submodule); no spec_archive key is " + "guessed: run from the main working tree") path, root = find_config(tree) if path is None: return remote("no IDD configuration found above the repository") diff --git a/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh b/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh index a7f9d7cf..90fdb68f 100644 --- a/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/check-existing-work/test.sh @@ -306,6 +306,9 @@ OUT=$(PATH="$W/gitlog:$W/bin:$PATH" bash "$SCRIPT" --cwd "$TR" --skip-branches t refute_grep "--skip-branches with gh repo view failing reads no origin/HEAD" "refs/remotes/origin/HEAD" "$(cat "$W/gitlog/calls")" refute_grep "… and adds no default-branch error (the default branch is not needed)" "default branch" "$(field "$OUT" "d['errors']")" refute_grep "… nor asks GitHub for it" "repo view" "$(field "$OUT" "d['errors']")" +refute_grep "… runs no git fetch (idd-547-fix4)" "fetch" "$(cat "$W/gitlog/calls")" +assert_grep "… notes say the branch lookup was skipped (idd-547-fix4)" "branch lookup skipped" "$(field "$OUT" "d.get('notes')")" +assert_eq "… none open (idd-547-fix4)" "[]" "$(kinds "$OUT" 61)" rm -f "$FX/fail_repo_view" assert_eq "idd-close: archive-ref answers error → Step 1.5 does not pass --skip-branches" "[]" \ "$(printf '%s\n' "$ERR_OUT" | sed -n 's/^EWNOTES=//p')" diff --git a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh index 7822325c..593e3191 100755 --- a/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/spec-archive-local/test.sh @@ -5,7 +5,7 @@ # # spec-example: spec-on-every-issue / how a spec_archive entry resolves # spec-example: spec-on-every-issue / where the local link check starts -# spec-example: spec-on-every-issue / a top level whose name ends in a space +# spec-example: spec-on-every-issue / a top level whose name ends in whitespace # # Real git repositories under a temporary HOME, so the walk up for the IDD configuration # stops inside the fixture and never reads the developer's own files. @@ -116,6 +116,7 @@ mkrepo "$WORK/b7/sub"; conf "$WORK/b7" '{"spec_archive": {"sub": {"ref": "local" git -C "$WORK/b7/sub" commit -q --allow-empty -m second ar "$WORK/b7/sub" assert_eq "branch master~1 (revision syntax) → error" error "$ST" +assert_grep "… not a branch name (idd-547-fix4)" "is not a branch name" "$(printf '%s' "$OUT" | field reason)" mkrepo "$WORK/b8/sub"; conf "$WORK/b8" '{"spec_archive": {"sub": {"ref": "local", "branch": "master@{0}"}}}' ar "$WORK/b8/sub" assert_eq "branch master@{0} → error" error "$ST" @@ -301,6 +302,8 @@ assert_grep "… saying the main working tree is not recorded" "main working tre conf "$WORK/d1" "{\"spec_archive\": {\"wt\": $OPT}}" ar "$WORK/d1/wt" assert_eq "… even when an entry names the linked worktree's own path → remote" remote "$ST" +assert_eq "… has_remote false (idd-547-fix4)" False "$(printf '%s' "$OUT" | field has_remote)" +assert_grep "… saying the main working tree is not recorded (idd-547-fix4)" "main working tree" "$(printf '%s' "$OUT" | field reason)" ar "$WORK/d1/sub" assert_eq "the --separate-git-dir main working tree itself, no entry for sub → remote" remote "$ST" mkrepo "$WORK/d2/sub"; mkdir -p "$WORK/d2/.claude/.idd" @@ -312,6 +315,7 @@ mkrepo "$WORK/d3/sub"; mkdir -p "$WORK/d3/.claude/.idd" printf '{"spec_archive": {"sub": {"ref": "local", "branch": "master", "branch": "master"}}}\n' > "$WORK/d3/.claude/.idd/local.json" ar "$WORK/d3/sub" assert_eq "a key written twice inside the entry → error" error "$ST" +assert_grep "… more than one entry (idd-547-fix4)" "more than one entry" "$(printf '%s' "$OUT" | field reason)" mkrepo "$WORK/d4/sub"; mkdir -p "$WORK/d4/.claude/.idd" printf '{"spec_archive": {"sub": %s, "\\u0000duplicate-keys": ["sub"]}, "\\u0000duplicate-keys": ["spec_archive"]}\n' "$OPT" > "$WORK/d4/.claude/.idd/local.json" ar "$WORK/d4/sub" @@ -351,6 +355,15 @@ mkdir -p "$WORK/sp/odd /openspec/specs/cap"; printf '## Purpose\n\nx\n\n## Requi git -C "$WORK/sp/odd " add -A; git -C "$WORK/sp/odd " commit -q -m "add a spec" OUT=$(python3 "$SC" links --base "$SPB" --cwd "$WORK/sp/odd " 2>/dev/null) assert_eq "links on 'odd ' with a sibling 'odd' → missing (reads 'odd ')" missing "$(printf '%s' "$OUT" | field status)" +# idd-547-fix4: a top level whose name ends in a newline, with a sibling without it +NL="$WORK/sp/nl"$'\n' +git init -q -b main "$NL"; mkdir -p "$NL/openspec/specs"; echo x > "$NL/openspec/specs/.keep"; git -C "$NL" add -A; git -C "$NL" commit -q -m base +mkdir -p "$NL/openspec/changes/archive/2026-11-14-idd-9-c1"; echo p > "$NL/openspec/changes/archive/2026-11-14-idd-9-c1/proposal.md" +git -C "$NL" add -A; git -C "$NL" commit -q -m "archive c1" +git init -q -b main "$WORK/sp/nl"; mkdir -p "$WORK/sp/nl/openspec/changes/idd-9-c1"; echo p > "$WORK/sp/nl/openspec/changes/idd-9-c1/proposal.md" +git -C "$WORK/sp/nl" add -A; git -C "$WORK/sp/nl" commit -q -m "open c1" +OUT=$(python3 "$SC" archived --file "$WORK/sp/ic.md" --cwd "$NL" --ref HEAD 2>/dev/null) +assert_eq "archived on a top level ending in a newline, with a sibling without it → reads itself (pass)" pass "$(printf '%s' "$OUT" | field status)" # preflight, too (round 4 pre-check): 'pf ' has openspec/, its sibling 'pf' does not; a stub spectra on PATH mkdir -p "$WORK/stubsp"; printf '#!/bin/sh\nexit 0\n' > "$WORK/stubsp/spectra"; python3 -c 'import os,sys; os.chmod(sys.argv[1], 0o755)' "$WORK/stubsp/spectra" git init -q -b main "$WORK/sp/pf "; git -C "$WORK/sp/pf " commit -q --allow-empty -m base; mkdir -p "$WORK/sp/pf /openspec/specs" @@ -361,6 +374,31 @@ mv "$WORK/sp/pf" "$WORK/sp/pf-away" OUT=$(PATH="$WORK/stubsp:$PATH" python3 "$SC" preflight --cwd "$WORK/sp/pf " --can-write yes 2>/dev/null) assert_eq "preflight on 'pf ' alone → ready" ready "$(printf '%s' "$OUT" | field status)" +# idd-547-fix4 rows — how a spec_archive entry resolves +for U in " " ""; do + R="$WORK/u$([ -z "$U" ] && echo e || echo s)"; mkrepo "$R/sub"; conf "$R" "{\"spec_archive\": {\"sub\": $OPT}}" + git -C "$R/sub" config remote.origin.url "$U" + ar "$R/sub" + assert_eq "a remote whose url is '$U' counts → error" error "$ST" + assert_grep "… naming it" "origin" "$(printf '%s' "$OUT" | field reason)" +done +# a bare main repository: its linked worktree is keyed by its own path +mkdir -p "$WORK/bare"; git init -q --bare -b master "$WORK/bare/main.git" +git clone -q "$WORK/bare/main.git" "$WORK/bare/seed" 2>/dev/null; git -C "$WORK/bare/seed" commit -q --allow-empty -m base +git -C "$WORK/bare/seed" push -q origin HEAD:master 2>/dev/null +git -C "$WORK/bare/main.git" worktree add -q "$WORK/bare/wt" master 2>/dev/null +conf "$WORK/bare" "{\"spec_archive\": {\"wt\": $OPT}}" +ar "$WORK/bare/wt" +assert_eq "a linked worktree of a bare repository → local" local "$ST" +assert_eq "… keyed by its own path" wt "$(printf '%s' "$OUT" | field key)" +# --separate-git-dir /.git: git reports as the main working tree, and that path is the key +mkdir -p "$WORK/sg/store" "$WORK/sg/iss"; conf "$WORK/sg" "{\"spec_archive\": {\"store\": $OPT}}" +git init -q -b master --separate-git-dir "$WORK/sg/store/.git" "$WORK/sg/iss/sub"; git -C "$WORK/sg/iss/sub" commit -q --allow-empty -m base +git -C "$WORK/sg/iss/sub" worktree add -q "$WORK/sg/wt" -b wt 2>/dev/null +ar "$WORK/sg/wt" +assert_eq "a linked worktree of a --separate-git-dir /.git repository → keyed by " store "$(printf '%s' "$OUT" | field key)" +assert_eq "… local, the same repository's master" "$(git -C "$WORK/sg/iss/sub" rev-parse master)" "$(printf '%s' "$OUT" | field ref)" + echo "spec-archive-local: the wrapper and idd-all text" WRAP="$PLUGIN/references/spec-wrapper.md" STEP5=$(sed -n '/^## 5\. Close-out/,/^## 6\./p' "$WRAP") @@ -379,6 +417,21 @@ refute_grep "… without the failed-fetch message" "cannot find where this branc S5OK=$(cd "$WORK/lb2/repo" && env HOME="$WORK" CWD="$WORK/lb2/repo" NUMBER=14 GITHUB_REPO=o/r CLAUDE_PLUGIN_ROOT="$PLUGIN" \ bash --norc --noprofile "$WORK/step5.sh" 2>&1 /dev/null +git -C "$RM/c" checkout -q -B main; mkdir -p "$RM/c/openspec/specs"; echo x > "$RM/c/openspec/specs/.keep" +git -C "$RM/c" add -A; git -C "$RM/c" commit -q -m base; git -C "$RM/c" push -q origin main 2>/dev/null +git -C "$RM/c" checkout -q -b feat; git -C "$RM/c" commit -q --allow-empty -m "work (#14)" +S5RM=$(cd "$RM/c" && env HOME="$WORK" CWD="$RM/c" NUMBER=14 GITHUB_REPO=o/r CLAUDE_PLUGIN_ROOT="$PLUGIN" \ + PATH="$WORK/ghok:$PATH" bash --norc --noprofile "$WORK/step5.sh" 2>&1 /dev/null)" +git -C "$RM/c" remote set-url origin "$RM/nowhere.git" +S5RF=$(cd "$RM/c" && env HOME="$WORK" CWD="$RM/c" NUMBER=14 GITHUB_REPO=o/r CLAUDE_PLUGIN_ROOT="$PLUGIN" \ + PATH="$WORK/ghok:$PATH" bash --norc --noprofile "$WORK/step5.sh" 2>&1 /dev/null git -C "$WORK/none/sub/origin" branch -q main master # fetchable: only has_remote keeps the fetch from running diff --git a/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh b/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh index faf05c2b..6aa646fd 100755 --- a/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh +++ b/plugins/issue-driven-dev/scripts/tests/spec-close-gate/test.sh @@ -75,8 +75,8 @@ step157() { # comments-json fail(0|1) → STATUS, GRC local out out=$(cd "$C" && env PATH="$WORK/bin:$PATH" HOME="$WORK" FAKE_COMMENTS="$WORK/comments.json" FAKE_FAIL="$2" FAKE_VIEW_FAIL="${FAKE_VIEW_FAIL:-0}" \ GITHUB_REPO=o/r NUMBER=42 CWD="$C" CLAUDE_PLUGIN_ROOT="$PLUGIN" \ - bash --norc --noprofile -c '. "$1"; printf "\nSTATUS=%s\nGRC=%s\n" "$(printf "%s" "$GATE" | python3 -c "import json,sys; print(json.loads(sys.stdin.read()).get(\"status\"))")" "$GATE_RC"' _ "$BLOCK" 2>/dev/null /dev/null "$WORK/comments.json" OUTALL=$(cd "$1" && env PATH="$WORK/bin:$PATH" HOME="$WORK" FAKE_COMMENTS="$WORK/comments.json" FAKE_FAIL=0 FAKE_VIEW_FAIL="${VIEW_FAIL_IN:-1}" \ GITHUB_REPO=o/r NUMBER=42 CWD="$1" CLAUDE_PLUGIN_ROOT="$PLUGIN" \ - bash --norc --noprofile -c '. "$1"; printf "\nSTATUS=%s\nGRC=%s\n" "$(printf "%s" "$GATE" | python3 -c "import json,sys; print(json.loads(sys.stdin.read()).get(\"status\"))")" "$GATE_RC"' _ "$BLOCK" 2>/dev/null /dev/null "$LR/openspec/changes/archive/2026-11-14-idd-42-fix-timeout/proposal.md" git -C "$LR" add -A; git -C "$LR" commit -q -m "chore: archive idd-42-fix-timeout (#42)" step157_in "$LR" "$IC_OK" @@ -151,6 +154,7 @@ mkdir -p "$LHR/openspec/changes/archive/2026-11-14-idd-42-fix-timeout"; echo p > git -C "$LHR" add -A; git -C "$LHR" commit -q -m "chore: archive idd-42-fix-timeout (#42)" step157_in "$LHR" "$IC_OK" assert_eq "no remote, opted into master, HEAD on the issue's branch with the archive, master without → stops" refuse "$STATUS" +assert_eq "… naming the change (idd-547-fix4)" idd-42-fix-timeout "$NA" # idd-547-fix1: no remote and no spec_archive entry → stops, and the reason says why archive-ref answered remote LN="$WORK/noentry"; mkdir -p "$LN/.claude/.idd"; git init -q -b master "$LN/code" printf '%s\n' '{"github_repo": "o/r"}' > "$LN/.claude/.idd/local.json" From 7ab30889763a86c0c6fceb6de538dc81e16efca8 Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 23:03:35 +0800 Subject: [PATCH 12/13] chore: archive idd-547-fix4 (#547) Co-Authored-By: Claude Opus 5.5 --- .../2026-11-14-idd-547-fix4}/.openspec.yaml | 2 ++ .../2026-11-14-idd-547-fix4}/proposal.md | 0 .../specs/spec-on-every-issue/spec.md | 0 .../2026-11-14-idd-547-fix4}/tasks.md | 0 openspec/specs/spec-on-every-issue/spec.md | 23 ++++++++++++------- 5 files changed, 17 insertions(+), 8 deletions(-) rename openspec/changes/{idd-547-fix4 => archive/2026-11-14-idd-547-fix4}/.openspec.yaml (54%) rename openspec/changes/{idd-547-fix4 => archive/2026-11-14-idd-547-fix4}/proposal.md (100%) rename openspec/changes/{idd-547-fix4 => archive/2026-11-14-idd-547-fix4}/specs/spec-on-every-issue/spec.md (100%) rename openspec/changes/{idd-547-fix4 => archive/2026-11-14-idd-547-fix4}/tasks.md (100%) diff --git a/openspec/changes/idd-547-fix4/.openspec.yaml b/openspec/changes/archive/2026-11-14-idd-547-fix4/.openspec.yaml similarity index 54% rename from openspec/changes/idd-547-fix4/.openspec.yaml rename to openspec/changes/archive/2026-11-14-idd-547-fix4/.openspec.yaml index f483aa4c..1a60d392 100644 --- a/openspec/changes/idd-547-fix4/.openspec.yaml +++ b/openspec/changes/archive/2026-11-14-idd-547-fix4/.openspec.yaml @@ -1,3 +1,5 @@ schema: spec-driven created: 2026-11-14 created_by: che cheng +archived_by: che cheng +archived_at: 2026-11-14 diff --git a/openspec/changes/idd-547-fix4/proposal.md b/openspec/changes/archive/2026-11-14-idd-547-fix4/proposal.md similarity index 100% rename from openspec/changes/idd-547-fix4/proposal.md rename to openspec/changes/archive/2026-11-14-idd-547-fix4/proposal.md diff --git a/openspec/changes/idd-547-fix4/specs/spec-on-every-issue/spec.md b/openspec/changes/archive/2026-11-14-idd-547-fix4/specs/spec-on-every-issue/spec.md similarity index 100% rename from openspec/changes/idd-547-fix4/specs/spec-on-every-issue/spec.md rename to openspec/changes/archive/2026-11-14-idd-547-fix4/specs/spec-on-every-issue/spec.md diff --git a/openspec/changes/idd-547-fix4/tasks.md b/openspec/changes/archive/2026-11-14-idd-547-fix4/tasks.md similarity index 100% rename from openspec/changes/idd-547-fix4/tasks.md rename to openspec/changes/archive/2026-11-14-idd-547-fix4/tasks.md diff --git a/openspec/specs/spec-on-every-issue/spec.md b/openspec/specs/spec-on-every-issue/spec.md index 7a0ede1a..98c2cc79 100644 --- a/openspec/specs/spec-on-every-issue/spec.md +++ b/openspec/specs/spec-on-every-issue/spec.md @@ -325,7 +325,7 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL --- ### Requirement: Close requires the issue's change to be archived -`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote` and `has_remote` is false (the repository has no remote at all), it SHALL stop without fetching and say that the repository has no remote, with the reason `archive-ref` gave; git would otherwise read a local path named `origin` as the remote. When the answer is `remote` otherwise, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails; the reason it prints SHALL then include the reason `archive-ref` gave for answering `remote`, so that a repository meant for the local branch whose entry was not found says why. When the answer is `local`, it SHALL check the commit `archive-ref` returned for the configured branch, not `HEAD`, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch, the commit and the entry's key, and without the configuration file's path. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. +`idd-close` SHALL fetch the issue's comments with `gh api --paginate`, SHALL choose the Implementation Complete comment with `spec-change.py ic` (requirement "One way to choose the Implementation Complete comment"), and SHALL run `spec-change.py archived` on it with `--ref` set to the default branch as the remote has it. It SHALL close the issue only when the command prints `pass`. On `refuse` it SHALL stop and name the changes that are not archived or the fault in the `**Spec**:` line; on `error` it SHALL stop and say the default branch could not be read. For a comment that declares a change, it SHALL first ask `spec-change.py archive-ref` which branch to read (requirement "A repository without a remote can opt into its local default branch"). When the answer is `remote` and `has_remote` is not exactly true (false when the repository has no remote at all; missing or not a boolean when the answer cannot be trusted), it SHALL stop without fetching and say that the repository has no remote, with the reason `archive-ref` gave; git would otherwise read a local path named `origin` as the remote. When the answer is `remote` and `has_remote` is true, it SHALL read the default branch by fetching it from the remote and checking the commit that fetch returned, and SHALL stop when `gh repo view` cannot name the default branch or the fetch fails; the reason it prints SHALL then include the reason `archive-ref` gave for answering `remote`, so that a repository meant for the local branch whose entry was not found says why. When the answer is `local`, it SHALL check the commit `archive-ref` returned for the configured branch, not `HEAD`, SHALL NOT fetch, and SHALL print that a local ref was used, with the branch, the commit and the entry's key, and without the configuration file's path. When the answer is `error`, or `archive-ref` prints nothing a JSON reader can take, it SHALL stop and print the reason. For any other comment the default branch is not read, since `archived` answers from the comment alone. When the comments cannot be fetched or `ic` exits 2, it SHALL stop and say the comments could not be read; it SHALL NOT treat that as an issue with no Implementation Complete comment. An issue with no Implementation Complete comment is not held to this rule. A retroactive close (`idd-close --retroactive`, for an issue that is already closed) skips this gate, as it skips the gates before it. #### Scenario: An unarchived change holds the close @@ -391,17 +391,17 @@ Before a wrapper creates any artifact or commit for an implementation, it SHALL --- ### Requirement: A repository without a remote can opt into its local default branch -`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree (its git directory differs from the common git directory), the first worktree `git worktree list --porcelain` lists; when that entry is bare, the linked worktree's own top level; when that entry is the common git directory itself (a main working tree made with `--separate-git-dir`, to which git keeps no path back), no key is guessed and the answer is `remote`, with a reason saying the main working tree is not recorded; otherwise (not a linked worktree) its top level, including a repository made with `--separate-git-dir`. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. When the repository's own path cannot be written as a key (it has leading or trailing whitespace), the answer is `remote`; it SHALL NOT fall back to `.`. Reasons name the configuration file by its path relative to the repository, not by an absolute path. It SHALL print one JSON line and exit as follows: +`spec-change.py archive-ref --cwd ` SHALL decide which branch the spec checks read for the repository that holds ``. The repository's path is its main working tree: for a linked worktree (its git directory differs from the common git directory), the first worktree `git worktree list --porcelain` lists; when that entry is bare, the linked worktree's own top level; when that entry is the common git directory itself, git does not record where the main working tree is (a repository whose git directory was made apart with `--separate-git-dir` under a name other than `.git`, or a submodule), so no key is guessed and the answer is `remote`, with a reason saying the main working tree is not recorded; a git directory made apart under the name `.git` is reported by git as the directory that holds it, and that directory is then the key, since git treats it as a working tree of the same repository; otherwise (not a linked worktree) its top level, including a repository made with `--separate-git-dir`. It SHALL find the IDD configuration by walking up from that path, the way the skills walk up: at each directory below `/`, `.claude/.idd/local.json` first and then `.claude/issue-driven-dev.local.json`, stopping after the home directory, and SHALL use the first file found. The key it looks up is that path relative to the directory that holds the configuration's `.claude/` directory, with both paths resolved through symbolic links. A key in the file SHALL match when it names the same path after `.` and `..` segments and trailing `/` are normalised; `.` names the directory of the configuration itself; a key that is empty, only `/`, or has leading or trailing whitespace matches nothing. When the repository's own path cannot be written as a key (it has leading or trailing whitespace), the answer is `remote`; it SHALL NOT fall back to `.`. Reasons name the configuration file by its path relative to the repository, not by an absolute path. It SHALL print one JSON line and exit as follows: - `remote` (exit 0), with a `reason`, when no configuration file is found; when the file found cannot be read as a JSON object (it is empty, `null`, not JSON, not valid UTF-8, or nested too deeply; a UTF-8 byte order mark is read as usual); when the file has no `spec_archive` field or the field is `null`; when `spec_archive` has no entry for the key; or when the repository's path cannot be written as a key. Every `remote` answer carries `has_remote`, true when the repository has a remote; callers read the default branch as the remote has it only when it is true, and a repository without any remote stops there, with this reason. - `local` (exit 0), with `branch`, `ref` (the commit `refs/heads/` points at, whatever `HEAD` is), `config` and `key`, when exactly one entry matches the key, it is `{"ref": "local", "branch": ""}`, the repository has no remote, and the branch exists. - `error` (exit 2), with a `reason`, when `spec_archive` is not an object; when more than one key matches, including the same key written twice; when `spec_archive` itself, or a key of the matching entry, is written twice in the file (duplicates are found while the file is parsed, never by a marker kept in the data, so no key the file holds can imitate one); when the matching entry is not an object, its `ref` is not `local`, or its `branch` is missing, not a string, or not a valid branch name (`git check-ref-format --branch` must accept it unchanged, so revision syntax such as `master~1` or `master@{0}` is refused); when the repository has a remote; when the branch does not exist; or when `` is not inside a git repository. -A repository has a remote when `git remote` lists a name that has a `url`, a `pushurl` or a `vcs` (a remote helper) in the git configuration it reads, or a legacy `remotes/` or `branches/` file in its git directory; a `remote` section without either (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. +A repository has a remote when `git remote` lists a name for which a `url`, a `pushurl` or a `vcs` (a remote helper) is set in the git configuration it reads, whatever its value (an empty or blank `url` counts), or a legacy `remotes/` or `branches/` file in its git directory; a `remote` section without either (for example a global `remote.origin.prune`) does not count. The repository having a remote turns an entry into an error, not a silent `remote`, so that an entry written for a repository without a remote cannot outlive the reason it was written for. `spec-change.py link-base --cwd --issue ` SHALL give the base of the link check (`spec-change.py links --base`) in local mode. It SHALL resolve the configuration as `archive-ref` does first, and print `remote` (exit 0) or the same `error` (exit 2) when `archive-ref` would, without reading ``. In local mode it SHALL print `ok` (exit 0) with `base` and `from`: the commit of the baseline tag when that tag exists and is an ancestor of `HEAD` other than `HEAD` itself (`from: baseline-tag`); otherwise the parent of the oldest commit in the history of `HEAD` whose message names issue ``: `#` with no letter, digit, `_`, `/` or `-` right before the `#`, the rule of `references/pr-issue-matching.md`, or `/#` where `/` is the configuration's `github_repo` (letter case ignored), the form a commit in a separate code repository uses for the issue repository's issues; in both forms no digit follows the number (`from: first-commit`). `/#` for any other repository does not count. The baseline tag is the configuration's `auto_tag.baseline_format` with `{N}` replaced by ``, or `idd--baseline` when that field is absent, not a string containing `{N}`, or does not give a valid tag name. Commit messages SHALL be read so that no byte a message can hold hides a commit, with signature display turned off, the output encoding fixed to UTF-8 whatever `i18n.logOutputEncoding` says, and `HEAD` separated from paths, and every commit and parent read SHALL be a hexadecimal object id. It SHALL print `error` (exit 2) when neither base exists, when that oldest commit has no parent, or when `` is not a positive integer written in digits; an empty `` is a usage error (exit 64), like any empty argument of `spec-change.py`. It SHALL NOT fall back to `merge-base` with the branch: on a direct-commit run that is `HEAD` itself, and the range would be empty. -`references/spec-wrapper.md` step 5 SHALL ask `link-base` first, with the issue number taken from `NUMBER`, or from `N` when `NUMBER` is empty, and SHALL use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote`, and SHALL stop with the reason when it prints `error` or nothing a JSON reader can take, without also printing the message about a failed fetch. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. +`references/spec-wrapper.md` step 5 SHALL ask `link-base` first, with the issue number taken from `NUMBER`, or from `N` when `NUMBER` is empty, and SHALL use its `base` when it prints `ok`, SHALL keep the fetch of the default branch when it prints `remote` with `has_remote` true, SHALL stop without fetching when it prints `remote` with `has_remote` not exactly true, saying the repository has no remote, and SHALL stop with the reason when it prints `error` or nothing a JSON reader can take, without also printing the message about a failed fetch. When the fetch of the default branch fails it SHALL stop with the message about a failed fetch and add `link-base`'s reason when there is one. `references/config-protocol.md` SHALL document the `spec_archive` field, the key, and why an entry is accepted only for a repository without a remote. #### Scenario: An entry for a repository that later gained a remote @@ -439,7 +439,11 @@ A repository has a remote when `git remote` lists a name that has a `url`, a `pu | `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has a `pushurl` and no `url` | `error`, naming the remote | | `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | a legacy `remotes/origin` file in its git directory | `error`, naming the remote | | `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | made with `--separate-git-dir` | `local`, keyed by its top level | -| `spec_archive` names the linked worktree's own path; the main working tree was made with `--separate-git-dir` | `{"ref": "local", "branch": "master"}` | asked from that linked worktree; no remote | `remote`, `has_remote` false, saying the main working tree is not recorded | +| `spec_archive` names the linked worktree's own path; the main working tree was made with `--separate-git-dir meta.git` | `{"ref": "local", "branch": "master"}` | asked from that linked worktree; no remote | `remote`, `has_remote` false, saying the main working tree is not recorded | +| `spec_archive` names `store`; the main working tree was made with `--separate-git-dir store/.git` | `{"ref": "local", "branch": "master"}` | asked from a linked worktree; no remote | `local`, keyed by `store`, at the same repository's `master` | +| `spec_archive` names the linked worktree's own path; the main repository is bare | `{"ref": "local", "branch": "master"}` | asked from that linked worktree; no remote | `local`, keyed by its own path | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has the `url` ` ` (a blank) | `error`, naming the remote | +| `spec_archive` names this path | `{"ref": "local", "branch": "master"}` | its only remote has an empty `url` | `error`, naming the remote | | `spec_archive` written twice at the top level | — | no remote | `error`, more than one entry | | `spec_archive` names this path | `{"ref": "local", "branch": "master", "branch": "master"}` | no remote | `error`, more than one entry | | `spec_archive` names this path, and the file also holds a key that looks like an internal marker | `{"ref": "local", "branch": "master"}` | no remote | `local` | @@ -470,18 +474,21 @@ A repository has a remote when `git remote` lists a name that has a `url`, a `pu --- ### Requirement: spec-change.py reads the repository that holds --cwd -Every subcommand of `scripts/spec-change.py` that takes `--cwd` (`archived`, `links`, `preflight`, `archive-ref`, `link-base`) SHALL read the repository whose top level `git rev-parse --show-toplevel` reports for `--cwd`, and SHALL take that path exactly as git prints it, removing only the line ending. A top level whose name ends in whitespace is that directory, never a sibling directory whose name lacks the whitespace. +Every subcommand of `scripts/spec-change.py` that takes `--cwd` (`archived`, `links`, `preflight`, `archive-ref`, `link-base`) SHALL read the repository whose top level `git rev-parse --show-toplevel` reports for `--cwd`, and SHALL take that path exactly as git prints it, removing only the one line ending git appends (the name of the directory can itself end in a space or a newline). A top level whose name ends in whitespace is that directory, never a sibling directory whose name lacks the whitespace. -#### Scenario: A top level whose name ends in a space +#### Scenario: A top level whose name ends in whitespace - **GIVEN** two repositories side by side, `odd ` (with a trailing space) and `odd` - **WHEN** a subcommand runs with `--cwd` inside `odd ` - **THEN** it reads `odd ` -##### Example: a top level whose name ends in a space +##### Example: a top level whose name ends in whitespace | Repositories | Command | Result | | --- | --- | --- | | `odd ` has the change archived, the sibling `odd` does not | `archived --cwd 'odd ' --ref HEAD` | `pass` | | `odd ` alone, with the change archived | `archived --cwd 'odd ' --ref HEAD` | `pass` | | `odd ` has a spec added on a branch without an Example, the sibling `odd` has none | `links --base --cwd 'odd '` | `missing` | +| `pf ` has an `openspec/` directory, the sibling `pf` does not | `preflight --cwd 'pf ' --can-write yes` | `ready` | +| `pf ` alone, with an `openspec/` directory | `preflight --cwd 'pf ' --can-write yes` | `ready` | +| `nl` followed by a newline has the change archived, the sibling `nl` does not | `archived` with `--cwd` that directory, `--ref HEAD` | `pass` | From 1eb18970292e9ade7f159328f4723bfcc3b87e6b Mon Sep 17 00:00:00 2001 From: che cheng Date: Sat, 14 Nov 2026 23:29:12 +0800 Subject: [PATCH 13/13] docs: main_tree docstring names the cases git does not record (#547) Co-Authored-By: Claude Opus 5.5 --- plugins/issue-driven-dev/scripts/spec-change.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/issue-driven-dev/scripts/spec-change.py b/plugins/issue-driven-dev/scripts/spec-change.py index 1f2f34b4..e76fbce5 100755 --- a/plugins/issue-driven-dev/scripts/spec-change.py +++ b/plugins/issue-driven-dev/scripts/spec-change.py @@ -643,7 +643,8 @@ def main_tree(top): """The repository's main working tree, or None when git does not record it. For a linked worktree (its git dir is not the common one): the first entry of `git worktree list --porcelain`; a bare entry means there is none, and the top level is used; an entry that is the common git directory itself means git does not know where the - main working tree is (a repository made with --separate-git-dir keeps no path back to it), and no key is guessed. + main working tree is (a git directory made apart with --separate-git-dir under a name other than .git, or a + submodule), and no key is guessed; for one named .git, git reports the directory holding it, which is then used. Otherwise the top level (a --separate-git-dir repository asked from its main working tree included).""" gd = os.path.realpath(os.path.join(top, one_line(git_text(top, "rev-parse", "--git-dir")))) common = os.path.realpath(os.path.join(top, one_line(git_text(top, "rev-parse", "--git-common-dir"))))