Skip to content

shape-doctor.py: a submodule a leg keeps is a note naming it, never root by rule, so a #166 assembly with a submodule at .cursor or .specify/vendored is no longer MISPLACED (#176) - #186

Merged
brettheap merged 4 commits into
mainfrom
fix/doctor-gitlink-placement
Oct 9, 2026
Merged

brettheap merged 4 commits into
mainfrom
fix/doctor-gitlink-placement

Conversation

@brettheap

@brettheap brettheap commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openreposhape-2 (openRepoShape-2)
Claim: #176 (comment)

What was wrong

The placement row classified each leg path with the globs in contracts/path-classification.yaml, and a glob cannot tell a gitlink from a file. Take an assembly adopted the way #166 requires: a vendored submodule at .cursor or .specify/vendored is kept in a leg, because the assembly root keeps no submodule except its legs. On such an assembly the doctor reported:

FINDING  placement  2 path(s) sit in a leg the policy puts elsewhere: code/.cursor: root by rule root-assistant-instructions; code/.specify/: root by rule root-spec-kit (2 root in the code leg)  [...]
MISPLACED (2 paths)   (exit 1)

I reproduced this on b18cca9 with a scaffolded assembly whose code leg held both gitlinks. The r4 review's adopted CURSOR, I3split and I3whole assemblies show the same row.

The change (shape-doctor.py only)

  • Modes from the same call. leg_tracked_files runs git ls-files --stage -z. It is still one git call per leg. The path list matches the old ls-files -z exactly, including unmerged stages, intent-to-add entries and a tab in a name, and each path now comes with its index mode.
  • Gitlinks stay out of walk(). audit_leg takes every gitlink (mode 160000) out before the walk, so it does not vote in the fold of the files beside it. Each one is named in a note: N submodule(s) the path policy does not judge, kept in a leg because the assembly root keeps no submodule but its legs: code/.cursor, .... A gitlink never produces root by rule.
  • Files are judged as before. A root-ruled file beside a kept submodule, such as a constitution next to .specify/vendored, is still MISPLACED by root-spec-kit. That is the I3whole case.
  • Every gitlink, whatever rule its name matches. adopt-project.py: a plan that sends .gitmodules to one leg and a submodule it registers to another passes check and execute, says adoption verified, and the assembly's recursive clone then fails: plan should ask, check should find, execute should refuse #166's plan asks about every entry that holds a gitlink, so the doctor treats them all the same way:
    • docs/theme in the code leg is a note, not "spec in the code leg".
    • vendor/lib, which no rule claims, was a default review note before and is the submodule note now. The verdict is unchanged: the row is note and the result is COMPLIANT, exit 0.
  • The row's status. A kept submodule on its own keeps the row at note rather than ok, and next is None. Next to a misplaced path or a question, it adds one clause to that sentence.

--placement-plan: a note, not the ambiguous-gitmodules question

A kept submodule is not an entry under paths:. It is listed in a new submodules: block, before ignored:, with path, in_leg and note. Why it is not a question:

No submodule, no change

detail.submodules, counts.submodules and the plan block only appear when a leg keeps a submodule. I ran the old and new doctor from one standard on six projects with no gitlink: clean, misplaced plus a question, a question only, an unread leg, an unwritable name, and 50 files folded. Text, --json and the plan were byte-identical on all six. On the gitlink projects, the only changes were the placement row and the width of the status column.

Not changed

A leg's own .gitmodules is still classified as a file. On this contract it is a default review note, and it becomes ambiguous-gitmodules once #166 lands. That is the r4 review's P3.3 residue and is outside #176.

Tests

tests/test_shape_doctor.py goes from 164 to 171 tests:

  • a code leg holding a submodule at .cursor and at .specify/vendored (parametrized; each first checks that the policy still roots that name)
  • a root-ruled file beside a kept submodule: still MISPLACED, with files == 1
  • a submodule at a path no rule claims: verdict unchanged
  • a submodule the policy would send to the other leg
  • a no-submodule project whose placement keys, counts, per-leg keys and reason sentence are exactly the old ones, and whose plan has no new block
  • the plan's submodules: block, read by the adoption's own reader

Against main's doctor, 6 of the 7 new tests fail. The unchanged-output test passes on both, as it should.

/usr/local/bin/pytest -q -p no:cacheprovider tests/test_shape_doctor.py                                  171 passed
/usr/local/bin/pytest -q -p no:cacheprovider tests/test_cli_reference.py tests/test_repo_hygiene.py      63 passed
python3 scripts/render-cli-reference.py --check                                                          [ok] (no --help text changed)

I did not run the full suite.

Independence

This PR is independent of the #166 branch (fix/adopt-split-submodule-plan). It touches only shape-doctor.py and tests/test_shape_doctor.py, and that branch changes neither file. git merge-tree against origin/main is clean.

Closes #176

🤖 Generated with Claude Code

Summary by Sourcery

Handle leg-held gitlinks separately from file placement classification so adopted submodules are reported without false MISPLACED findings.

New Features:

  • Report gitlinks kept in repository legs as non-actionable placement notes, including their leg, classification, and any relevant policy rule.
  • Include kept submodules in placement JSON details and generated plans without treating them as adoption questions.

Bug Fixes:

  • Prevent submodules under root-ruled or otherwise policy-matched paths from being falsely reported as misplaced.
  • Continue judging ordinary files beside submodules and correctly handle unmerged paths that contain a file stage.

Enhancements:

  • Distinguish submodules that are kept from those whose placement cannot be verified against the adoption plan while keeping both as notes.
  • Read index modes from the existing tracked-file scan and report every tracked gitlink, including paths otherwise excluded from file placement checks.

Tests:

  • Add coverage for root-ruled, unclaimed, cross-leg, unmerged, ignored-path, and mixed file/submodule placement cases.
  • Verify placement output and plans remain unchanged for projects without submodules.

… `root by rule`, so an assembly adopted the way #166 requires, with a vendored submodule at `.cursor` or `.specify/vendored` in its code leg, is no longer MISPLACED (#176)

The placement row classified every tracked path of a leg with
`contracts/path-classification.yaml`'s globs, and a glob cannot tell a
gitlink from a file. A submodule at `.cursor` read as the assistant
instructions and one at `.specify/vendored` as the Spec-Kit tooling, both of
which the 2026-09-02 ruling roots. But the assembly root keeps no submodule
except its legs, so an adoption keeps such a submodule in a LEG (#166). The
doctor answered `code/.cursor: root by rule root-assistant-instructions;
code/.specify/: root by rule root-spec-kit` and exited 1 MISPLACED over a
placement `adopt-project.py` had required. This was reproduced on b18cca9
with a scaffolded assembly whose code leg held both gitlinks, and with the r4
review's adopted CURSOR, I3split and I3whole assemblies.

How it is fixed:
- `leg_tracked_files` runs `git ls-files --stage -z` in place of
  `ls-files -z`. It is still one git call per leg. The path list is
  identical, checked on unmerged stages, intent-to-add entries and a tab in a
  name, and the call now also gives each path's mode. Modes come from the
  index, as the paths do, so a staged gitlink is seen as one.
- `audit_leg` keeps every gitlink (mode 160000) out of `walk()`. A gitlink
  no longer votes in the fold of the files beside it and is not counted as a
  file under it. It is returned on its own and named in a `note`: "N
  submodule(s) the path policy does not judge, kept in a leg because the
  assembly root keeps no submodule but its legs: ...".
- Files are judged exactly as before. A constitution beside
  `.specify/vendored` in the code leg is still MISPLACED by root-spec-kit
  (the I3whole case). The submodule clause is added to that row's sentence.
- This holds for every gitlink, whatever rule its name matches, because
  #166's `plan` asks on every entry that holds one. `docs/theme` (spec by
  spec-governance) in the code leg is a note, not "spec in the code leg".
  `vendor/lib`, which no rule claims, was a `default` review note before and
  is the submodule note now. The row is `note` and the verdict is COMPLIANT,
  exit 0, both before and after.
- A kept submodule alone keeps the row at `note` rather than `ok`, because a
  gitlink is a tracked path the policy did not classify. Its `next` is None:
  a note with nothing to resolve has no command.

The `--placement-plan` decision: a kept submodule carries a NOTE, not the
`ambiguous-gitmodules` question. The question is asked once, when the
repository is adopted, and the leg the submodule is in is the answer
somebody gave. Asking it again of a project already split would put an
answered question back on every run. Today's contract would ask it in
`default`'s words, which offer `root`, the one answer a submodule cannot
take. `ambiguous-gitmodules` exists only on the unmerged #166 branch, and
its text is written for adoption (the r4 review's P3.3). So a kept submodule
is not an entry under `paths:`, which holds paths a human resolves. It is
listed in a new `submodules:` block with `path`, `in_leg` and `note`, placed
before `ignored:`.

No submodule, no change: `detail.submodules` and `counts.submodules` appear
only when a leg keeps one, and the plan block likewise. I checked the old
and new doctor, run from one standard, on six projects with no gitlink
(clean, misplaced plus a question, a question only, an unread leg, an
unwritable name, 50 files folded). Text, `--json` and the plan were
byte-identical on all six. On the two gitlink projects only the placement
row changed, plus the status-column width in the text report.

Not changed: a leg's own `.gitmodules` is still classified as a file, as a
`default` review note on this contract (`ambiguous-gitmodules` once #166
lands). That is the r4 P3.3 residue and is outside #176.

Tests (tests/test_shape_doctor.py, 164 -> 171): a code leg holding a
submodule at `.cursor` and at `.specify/vendored` (parametrized), a
root-ruled file beside a kept submodule, a submodule at a path no rule
claims, one the policy sends to the other leg, a no-submodule project whose
row keys, counts and reason are exactly the old ones, and the plan's
`submodules:` block read by the adoption's own reader. Run against main's
doctor, 6 of the 7 fail; the unchanged-output test passes on both, as it
must. tests/test_shape_doctor.py 171 passed; tests/test_cli_reference.py
and tests/test_repo_hygiene.py 63 passed; render-cli-reference.py --check
ok. `--help` is unchanged.

This touches no file the #166 branch changes (adopt-project.py,
contracts/path-classification.yaml), so the two are independent.

Closes #176

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lane: openreposhape-2 (openRepoShape-2)
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@sourcery-ai

sourcery-ai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 15 hours and 58 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Reviewer's Guide

Updates shape-doctor.py to read gitlink modes from each leg’s index, treat every kept submodule as an informational note rather than judging it by its path glob, and retain existing classification for ordinary files. Diagnostics and placement plans now report kept submodules conditionally, with tests covering root-ruled, unclaimed, cross-leg, mixed, and no-submodule compatibility cases.

Sequence diagram for gitlink-aware placement auditing

sequenceDiagram
    participant Doctor as shape-doctor.py
    participant Git as Git index
    participant Audit as audit_leg
    participant Policy as Path policy
    Doctor->>Audit: audit_leg(...)
    Audit->>Git: git ls-files --stage -z
    Git-->>Audit: tracked paths with index modes
    Audit->>Audit: Separate mode 160000 gitlinks
    Audit->>Policy: walk(ordinary files)
    Policy-->>Audit: misplaced paths and review questions
    Audit-->>Doctor: placement results and kept submodules
    Doctor-->>Doctor: Render note and conditional submodules block
Loading

Flow diagram for kept submodule placement verdict

flowchart TD
    A[Read leg index with gitlink modes] --> B{Mode 160000?}
    B -->|Yes| C[Exclude from path classification]
    C --> D[Record submodule note with leg]
    B -->|No| E[Classify ordinary file by path policy]
    E --> F{Misplaced or requires review?}
    F -->|Yes| G[Retain finding or question]
    F -->|No| H[Count as classified]
    D --> I[Placement row remains note]
    G --> J[Add submodule clause if present]
    H --> K[Placement row remains ok unless other issues exist]
Loading

File-Level Changes

Change Details Files
Detect gitlinks from the index and exclude them from path-policy classification while preserving normal file placement checks.
  • Run staged file listing with index modes in one git call per leg.
  • Identify mode 160000 entries, deduplicate staged paths, and keep them out of the classification fold.
  • Continue judging ordinary files beside submodules, including root- or other-leg-ruled files.
  • Represent kept submodules as notes and prevent them from producing misplaced findings or adoption questions.
shape-doctor.py
Expose kept submodules in placement diagnostics and plans without changing output for projects that have none.
  • Add conditional JSON detail and submodule counts with path, leg, and explanatory note.
  • Adjust placement status and reason composition so submodules yield note status and no next command when unresolved paths are absent.
  • Add a conditional submodules plan block before ignored paths, excluding gitlinks from paths to resolve.
  • Preserve legacy keys, text, reasons, and plan output when no submodule is present.
shape-doctor.py
Add regression coverage for gitlink placement behavior, mixed file/submodule legs, and plan serialization.
  • Test root-ruled, unclaimed, and other-leg-ruled submodule paths as kept notes.
  • Verify ordinary misplaced files beside submodules remain findings with correct counts.
  • Verify no-submodule output compatibility and adoption-reader handling of the submodules plan block.
tests/test_shape_doctor.py

Assessment against linked issues

Issue Objective Addressed Explanation
#176 Update shape-doctor.py to identify gitlinks in each leg from the index mode and exclude them from path-based placement classification, reporting them as notes rather than as root-ruled or otherwise misplaced paths. ✅
#176 Ensure submodules kept in legs are represented appropriately in JSON details, placement verdicts, and placement plans without creating a new unresolved adoption question or an actionable next command. ✅
#176 Preserve all other placement behavior, including judging regular files beside submodules, retaining existing verdicts, and keeping output unchanged for projects without submodules, with regression coverage for the affected paths. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T08:37:48.360869Z 2ead645 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bff8122012

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread shape-doctor.py Outdated
if not any(regex.match(path) for regex in patterns)]
judged = [(path, size) for path, size in files
if not any(regex.match(path) for regex in patterns)]
kept = [(path, size) for path, size in judged if path not in gitlinks]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve regular stages at mixed-mode conflict paths

When an unmerged path has both a regular-file stage and a gitlink stage—for example, .cursor with modes 100644 and 160000—git ls-files --stage emits both entries (git ls-files -h describes --stage as showing staged contents), but gitlinks stores only the path name, so this condition removes both records from classification. The ordinary .cursor file therefore never reaches walk(), and the doctor can return a submodule note and COMPLIANT instead of the required root-placement finding; retain the mode per index entry, or exempt a path only when all of its stages are gitlinks.

AGENTS.md reference: AGENTS.md:L215-L219

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(lane openRepoShape-2, 2026-10-09T08:02Z) Taken in e0069c6: leg_tracked_files now keeps each path's modes per stage and a path is a gitlink only when every stage it holds is one, so an unmerged .cursor with a file stage still reaches walk() and is MISPLACED; test_an_unmerged_path_with_a_file_stage_is_still_judged_as_a_file (both stage orders, built with git update-index --index-info) pins it, and test_an_unmerged_path_whose_every_stage_is_a_gitlink_is_one_submodule pins the all-gitlink side.

Comment thread shape-doctor.py Outdated
Comment on lines +1722 to +1723
judged = [(path, size) for path, size in files
if not any(regex.match(path) for regex in patterns)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Report gitlinks that match everywhere exclusions

When a leg keeps a submodule at an everywhere path such as .github/actions, the .github/** pattern removes it while constructing judged, before held is derived. Consequently the placement row remains ok and neither JSON nor the placement plan names the submodule, contradicting this change's promise that every kept gitlink is reported as a note; collect gitlinks from files before applying the ordinary-file exclusion patterns.

AGENTS.md reference: AGENTS.md:L204-L207

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(lane openRepoShape-2, 2026-10-09T08:02Z) Taken in e0069c6: audit_leg now collects the gitlinks from every tracked path before the everywhere patterns are applied, so a submodule at .github/actions or COPYING is named as a note in the text report, in --json and in the placement plan's submodules: block; test_a_submodule_at_a_path_the_doctor_never_judges_is_still_named pins all three at both paths.

…x holds for it is a gitlink, and a submodule at an `everywhere` path such as `.github/actions` is named all the same (#176) (Codex review on #186)

Codex review on #186 found two paths by which the gitlink rule dropped
something it should have judged or reported. Both are P2 and both are valid.

1. A mixed-stage path was removed from the classification entirely
   (thread 4226514885). `git ls-files --stage` lists an unmerged path once
   per stage, so `.cursor` that is a file on one side (100644) and a
   submodule on the other (160000) gave two records. `leg_tracked_files`
   kept only the NAME of every path with a gitlink stage, so both records
   were taken out of `walk()`: the ordinary file never reached the policy and
   the doctor said "a submodule" and COMPLIANT where the 2026-09-02 ruling
   requires the root-placement finding. It now keeps each path's modes until
   the last record is read, and a path is a gitlink only when every stage it
   holds is one. A path with any regular stage is classified as the file it
   is, as it was before #176. A path whose every stage is a gitlink (two
   sides that moved a submodule to different commits) is still exempt, and is
   still named once and not once per stage.

2. A submodule at an `everywhere` path was never reported (thread
   4226514890). `audit_leg` built the list of paths to judge by dropping the
   `everywhere` matches (`.github/**`, `LICENSE`, `COPYING`, ...) and then
   derived the submodules from what was left, so a submodule kept at
   `.github/actions` vanished from it. The row stayed `ok` and neither
   `--json` nor the placement plan named it, which contradicts #186's promise
   that every gitlink a leg keeps is reported as a note. The submodules are
   now collected from every tracked path BEFORE the `everywhere` patterns are
   applied; the files to classify are the ones that are neither a gitlink nor
   an `everywhere` match, which is the same list as before for every project
   without a gitlink.

Nothing else moves. The path list `ls-files --stage -z` gives is unchanged,
so `tracked` and `classified` are the numbers they were, a project with no
gitlink gets the same row, `--json` and plan byte for byte, and an unmerged
path is still listed once per stage as it is on main, which is why the first
test does not pin how many entries the one file gets.

Tests (tests/test_shape_doctor.py, 171 -> 176):
- an unmerged `.cursor` with a file stage and a gitlink stage, in both orders
  (parametrized, built with `git update-index --index-info`): still a FINDING
  by root-assistant-instructions, and no submodule is named for it
- an unmerged `.cursor` whose every stage is a gitlink: one submodule, named
  once, COMPLIANT (the guard on the other side of the rule)
- a submodule at `.github/actions` and at `COPYING`, each first checked
  against the row's own `everywhere` list (parametrized): named in the text
  report, in `--json` and in the placement plan's `submodules:` block, and
  the row is a `note`

Run against bff8122's doctor, 4 of the 5 fail; the all-gitlink guard passes
on both, as it must. tests/test_shape_doctor.py, tests/test_cli_reference.py
and tests/test_repo_hygiene.py: 239 passed; render-cli-reference.py --check
ok. `--help` is unchanged, so docs/cli.md is too. The full suite was not run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lane: openreposhape-2 (openRepoShape-2)
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0069c6eb9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread shape-doctor.py
Comment on lines 1747 to +1749
kept = [(path, size) for path, size in files
if not any(regex.match(path) for regex in patterns)]
if path not in gitlinks
and not any(regex.match(path) for regex in patterns)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not exempt gitlinks without a recorded placement decision

For projects created before the proposed adoption work, or with a manually added nested submodule, there is no evidence that the gitlink's current leg was chosen by a human: the current adopt-project.py passes every tree path through walk() while discarding its mode at lines 703–704. Consequently, a gitlink such as docs/theme in the code leg is now removed from classification here and the doctor returns COMPLIANT, even though the policy assigns that path to spec; either defer this exemption until adoption records the decision or preserve a verifiable placement resolution for the doctor to consult.

AGENTS.md reference: AGENTS.md:L215-L219

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(lane openRepoShape-2, 2026-10-09T08:31Z) Taken in part in 2ead645: a gitlink at a path whose rule assigns the other leg is now reported as a placement the doctor cannot verify, naming the rule, in text, --json and the placement plan, with tests; it stays a note rather than MISPLACED because #166 makes every submodule leg a human answer and MISPLACED would recreate #176 for that case. Recording the plan answer in the assembly so the doctor can verify it is filed as a follow-up issue by lane openRepoShape-2.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(lane openRepoShape-2, 2026-10-09T08:31:51Z) The follow-up is #189 (adopt should write the plan's submodule answers into the assembly so the doctor can verify a kept gitlink's placement), filed 08:16Z, unclaimed.

@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-2, 2026-10-09T08:15:11Z) Full suite on this head e0069c6, run from a detached worktree in py-bench with git-filter-repo 2.47.0 on PATH: 1281 passed, 1 skipped (SHAPE_MEDXEHR_CLONE unset) in 11m51s, no filter-repo skips; the previous head bff8122 gave 1276 passed, 1 skipped. Log: opensoft/brett-wip handoffs/xFactory/attachments/lane-openRepoShape-2/openRepoShape-2-suite-pr186-e0069c6.log. CI green on all three platforms, quality gate passed. Codex's newest thread is being taken next. Not merged; merging waits on Brett Heap's word.

…g is a placement the doctor cannot verify, named with the rule, in text, `--json` and the plan, and still a `note` (#176) (Codex review on #186, round 2)

Codex review on #186, round 2 (thread 4228030879, P2) is right that the
exemption is blind. A kept gitlink was never judged by its path, so
`docs/theme` in the code leg, which `spec-governance` assigns to spec, got
the same note as `.cursor` and the doctor said COMPLIANT. That is correct
for a project adopted under #166, where a person answered the leg. But
#166's `ask_about_submodules` is not on main: main's adopt discards tree
modes (adopt-project.py:703-704) and never asks about a gitlink, and a
submodule can also be added by hand. For those projects nothing in the
assembly records that anyone chose the gitlink's leg, and the doctor said
"COMPLIANT" with no evidence either way.

The decision, taken by the coordinator:
- A kept gitlink is still never `root by rule`, which is #176's defect and
  stays fixed. The row's status for it stays `note` and the verdict stays
  COMPLIANT, because MISPLACED would recreate #176's false positive for the
  case #166 requires: a human answered the leg and the doctor cannot tell.
- But the note now says which of two things the doctor found, and names the
  rule:
  * `kept`: the name matches a root rule, no rule, or the rule of the leg it
    is in. "a submodule; the assembly root keeps no source submodule (#166),
    so a leg holds it", with the rule's id added where one matched.
  * `unverifiable`: the name matches a rule assigning the OTHER leg, as
    `docs/theme` under `spec-governance` in the code leg, or a code rule in
    the spec leg. "a submodule at a path rule `<id>` assigns to the <other>
    leg; a submodule's leg is the adoption plan's answer and the doctor
    cannot verify it here: confirm against the plan, or move it".

How it is carried out:
- `submodule_placement(policy, role, path)` asks the policy's own
  `rule_for` (first match; no extension majority and no `default`, which
  read what a FILE looks like) and returns `placement`, `rule` and `note`.
  A rule whose leg is `ambiguous` leaves the leg to a human, so it is
  `kept` with the rule named.
- Each entry of `detail.submodules` in `--json` now carries `placement`
  (`kept` | `unverifiable`) and `rule` (the id, or null) beside `path`,
  `leg`, `path_in_leg` and `note`.
- The row's sentence has one clause per class present, so both are said
  apart, each submodule once, with its rule. A submodule beside a misplaced
  path or a question still only adds its clause.
- The plan's `submodules:` block carries `placement` and `rule` on every
  entry, and its comment says what `unverifiable` asks of a reader. It is
  still not an entry under `paths:`, and asks no question.
- `counts.submodules`, `next` (None on its own) and every other row and
  verdict are as before. A project with no submodule in a leg gets the
  identical row, `--json` and plan: the no-submodule identity test is
  unchanged and passes.

Recording the plan's answer in the assembly, so the doctor can verify a
gitlink's leg instead of naming it, needs adopt to write it and is filed as
a follow-up issue by lane openRepoShape-2.

Tests (tests/test_shape_doctor.py, 176 -> 181): `docs/theme` in the code
leg is a `note` with the unverifiable wording and the rule id, verdict
unchanged, in `--json` and the text report; the same gitlink in the spec leg
gets the kept wording with the rule named; a code rule makes a gitlink in
the spec leg unverifiable; `.cursor` and `.specify/vendored` in code keep the
root-rule wording, now asserted with `placement` and `rule`; a project with
both classes says them apart in one row; an unverifiable submodule beside a
misplaced file adds its clause and leaves the FINDING and its `next`; the
plan carries the class and the rule of three submodules. The expected
wording is spelt out in the tests, not read back from the doctor. Against
e0069c6's doctor 10 of the tests that touch a submodule fail; the
unmerged-stage, `everywhere` and no-submodule tests pass on both.

tests/test_shape_doctor.py, tests/test_cli_reference.py and
tests/test_repo_hygiene.py: 244 passed (181 + 63).
`render-cli-reference.py --check` ok: `--help` is unchanged, so
docs/cli.md is too. The full suite was not run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Lane: openreposhape-2 (openRepoShape-2)
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 2ead6452aa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-2, 2026-10-09T08:43:14Z) Full suite on this head 2ead645 (fix round 2 for Codex thread 4228030879), run from a detached worktree in py-bench with git-filter-repo 2.47.0 on PATH, git 2.43: 1286 passed, 1 skipped in 11m14s (the skip is the MedxEHR clone fixture, as on main). Log: opensoft/brett-wip handoffs/xFactory/attachments/lane-openRepoShape-2/openRepoShape-2-suite-pr186-2ead645.log. Merging still waits on Brett's word.

…three unmerged-index fixtures stage `.cursor` and not `.cursor` plus a CR on the Windows job, where `tests-windows` has been red since fix round 1 (#176) (PR #186)

The `tests-windows` job on PR #186 has been red since e0069c6 (fix round 1;
bff8122's run was green) and is still red at 2ead645 (run 37905437159, job
113737647734): `3 failed, 1113 passed, 201 skipped`. The three are fixture
assertions, not the doctor: `[file-then-gitlink]` and `[gitlink-then-file]`
of `test_an_unmerged_path_with_a_file_stage_is_still_judged_as_a_file` and
`test_an_unmerged_path_whose_every_stage_is_a_gitlink_is_one_submodule`,
`assert [] == ['100644', '160000']` and `assert [] == ['160000', '160000']`.
`git ls-files --stage .cursor` listed nothing after `stage_unmerged` had run
with `check=True` and no error. Linux and macOS pass.

Cause: `stage_unmerged` piped `<mode> <object> <stage>\t<path>\n` records to
`git update-index --index-info` with `text=True`. A text-mode pipe writes
each `\n` as `os.linesep`, which is `\r\n` on Windows, so git read the path
as `.cursor\r`. A CR is a legal byte in a path for `update-index`, so git
accepted it, staged the entries at `.cursor\r` and exited 0, and the later
`ls-files --stage .cursor` found no entry. The `hash-object -w --stdin` call
a few lines above had the same text-mode pipe; its blob is a placeholder, so
it was harmless, but it is the same mistake.

The fix: both calls hand git bytes (`input=lines.encode("utf-8")`,
`input=b"x\n"`, no `text=True`; `hash-object`'s stdout is decoded), which
no operating system rewrites. The docstring says why. Test-only: no
assertion is changed and shape-doctor.py is not touched.

Not chosen: NUL-terminated records with `update-index -z`. `-z` does work
with `--index-info` on this box's git 2.43 (probed), but encoding is what
removes the translation, it is the required part and sufficient, and it
leaves the records in the very lines `ls-files --stage` prints. Nor was the
test marked WINDOWS_SKIP: the doctor's placement of an unmerged path is the
same on every system, and the Windows job is the one that proves it.

The same mistake, found by grep: `grep -n 'input=' tests/test_shape_doctor.py`
has four more hits, lines 738, 762, 782 and 798. Three are `input=""` to
`bash openRepoShape ...` and the fourth pipes the `openRepoShape` shim's own
text to `bash -s`; none feeds `update-index`, `mktree`, `hash-object` or a
path to git, and all four tests are WINDOWS_SKIP, so they are left alone.

The Windows pipe, reproduced on Linux
(scratchpad review186/windows_crlf_pipe.py, git 2.43.0; the OLD code with
the translation spelt out as `lines.replace("\n", "\r\n")`):

  OLD, LF:   ls-files --stage .cursor -> two stages at `.cursor`
  OLD, CRLF: ls-files --stage .cursor -> ''
             ls-files --stage -z      -> b'100644 587be6b4... 2\t.cursor\r\x00160000 8df1922e... 3\t.cursor\r\x00'
  NEW (stage_unmerged imported from this tree), file-then-gitlink:
             ls-files --stage .cursor -> '100644 587be6b4... 2\t.cursor\n160000 8e312f43... 3\t.cursor\n'
  NEW, gitlink-then-file and two gitlinks: both stages listed at `.cursor`

tests/test_shape_doctor.py: 181 passed on Linux (git 2.43.0), unchanged from
2ead645. I cannot run the Windows job from here; the `tests-windows` run on
this commit is the proof.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Lane: openreposhape-2 (openRepoShape-2)
@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-2, 2026-10-09T09:06Z) The tests-windows job has been red since e0069c6 (fix round 1; bff8122's run was green) on three unmerged-index fixtures in tests/test_shape_doctor.py: test_an_unmerged_path_with_a_file_stage_is_still_judged_as_a_file[file-then-gitlink], [gitlink-then-file] and test_an_unmerged_path_whose_every_stage_is_a_gitlink_is_one_submodule (3 failed, 1113 passed, 201 skipped at 2ead645, run 37905437159). Linux and macOS pass.

Cause: the fixture stage_unmerged piped its <mode> <object> <stage>\t<path>\n records to git update-index --index-info in text mode, and a text-mode pipe writes each \n as \r\n on Windows, so git staged the entries at .cursor\r, exited 0, and git ls-files --stage .cursor listed nothing. It is the fixture, not shape-doctor.py.

Taken in 5922521 (test-only): stage_unmerged hands git bytes, for update-index --index-info and for the hash-object call above it, and its docstring says why. No assertion is changed and shape-doctor.py is not touched. Reproduced on Linux with the CRLF translation spelt out: the old path leaves ls-files --stage .cursor empty and ls-files --stage -z listing .cursor\r; the bytes path lists the stages at .cursor.

tests/test_shape_doctor.py on Linux: 181 passed, the count at 2ead645.

I cannot run the Windows job from here: the tests-windows run on 5922521 is the proof, and this lane will report it. The head differs from the Codex-reviewed 2ead645 by this fixture only.

@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@brettheap

Copy link
Copy Markdown
Contributor Author

(lane openRepoShape-2, 2026-10-09T09:26:27Z) On this head 5922521 (2ead645 + the stage_unmerged bytes fix): tests-windows passes (run 37909107425; it was red from e0069c6 through 2ead645 on the three unmerged-index fixtures only), and tests and tests-macos pass. Full suite in py-bench from a detached worktree, git-filter-repo 2.47.0 on PATH, git 2.43: 1286 passed, 1 skipped in 11m30s (the MedxEHR clone skip, as on main). Log: opensoft/brett-wip handoffs/xFactory/attachments/lane-openRepoShape-2/openRepoShape-2-suite-pr186-5922521.log. The head differs from the Codex-reviewed 2ead645 by that test fixture alone. All three OS jobs, Sonar and Codex are green; merging waits on Brett's word.

@brettheap
brettheap merged commit 4ce9cb0 into main Oct 9, 2026
5 checks passed
@brettheap
brettheap deleted the fix/doctor-gitlink-placement branch October 9, 2026 18:42
brettheap added a commit that referenced this pull request Oct 9, 2026
…o fix/adopt-split-submodule-plan

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
brettheap added a commit that referenced this pull request Oct 12, 2026
…lan gave each submodule a leg keeps, and shape-doctor.py holds the submodule to that row, so one in the other leg is MISPLACED and a real adoption's placement reads `ok` (#189) (#394)

`adopt-project.py`'s `execute` now writes the plan's answer for each submodule a leg keeps into the split's `project.yaml`, in the split commit, as a `submodules:` block. There is one row per gitlink the plan keeps in a leg: its `path` in the leg, its `leg`, the covering entry's reason as `resolution:` when it has one, and its `source_commit`.
- A gitlink answered `drop` is in no leg and gets no row. A source with no submodule kept in a leg gets the `project.yaml` and the split it always got.
- Every path and reason is written by `repo_shape.double_quoted`, so a submodule at `null` or `0001`, or a name holding an invisible space or a byte that is not UTF-8, reads back as itself.
- A comment above the block says where the record came from and that it confers nothing.

`shape-doctor.py`'s `placement` row holds every submodule a leg keeps to the record:
- In the leg its row names, the submodule is `recorded`, which counts as placed.
- In the other leg it is `misplaced`, with `rule: null` and `confidence: recorded`. That is a finding, counted in `MISPLACED`, exit 1, and listed under the placement plan's `paths:`.
- The first row naming a path decides, as the project's validator reads the record. A row whose `leg:` the validator refuses decides nothing.
- Where the record places every submodule a leg keeps in that leg, it answers rule `ambiguous-gitmodules` for the leg's `.gitmodules`, so a real adoption's placement row reads `ok` where it read a note.
- A submodule no row names keeps #186's `kept` or `unverifiable` note word for word. Every assembly adopted before this change, and every submodule added by hand, gets byte-identical doctor output.
- `--json` and the placement plan carry `recorded_leg:` on any submodule a row names.

`templates/assembly-root/scripts/validate-manifest.py` checks the record:
- `submodules` is an optional list of mappings.
- Each `path` is named by one row only, and spelled the one way git records a path. That rule is `repo_shape.path_spelling_fault`, moved out of `shape_materialize.py`, whose `_spelling_reason` gives the same answer for 33 spellings.
- `leg` is `spec` or `code`; `resolution` is optional text; `source_commit` is optional and 40 hex.
- New finding codes: `manifest-submodules`, `manifest-submodule-path`, `manifest-submodule-leg`, `manifest-submodule-resolution` and `manifest-submodule-commit`.

`scripts/repo_shape.py` and the validator are copies a project pins, so a project's next `update-shape.py check` reads them as `upstream-changed` until `apply` re-pins them together.

AGENTS.md says what `execute` writes and how the doctor judges by it, and tests/test_repo_hygiene.py moves its cap from 482 to 490 lines.

Brett Heap ruled that #189 goes ahead as a code change, with no OpenSpec change first. Lane openRepoShape-2 reviewed e167d8b, the fix round answered its findings, a re-verify found 70f4d29 ready, and re-checks of the merges since then found 563ea16, 120d6ed and 7db009e ready; 7adcc84 merges `main` once more. 60a1a34 merges #188's landing: the record is written inside #188's late-failure reporting in `_commit_the_split`. 71d3ce2 and b88a36e merge `main` (ec4a7a0, then 437a360) once more each. CI is green on Linux, macOS and Windows at b88a36e, which has `main` 437a360 merged in.

Closes #189

Lane: openreposhape-1 (openRepoShape-1)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shape-doctor.py flags a submodule kept in a leg under a root-ruled path (.cursor, .specify/vendored) as MISPLACED, though #166 requires a leg for it

1 participant