Repository navigation
update-shape.py: check reports upstream-added; apply --add <path> takes a file the standard gained since the pin - #29
Conversation
…>` takes a file the standard gained since the pin A pin can only record what existed the day it was written, and `update-shape.py` re-synced ONLY the pin's own rows — right for a file a project merged away, and blind to a file the standard adds later. Issue #28 adds `AGENTS-shape.md` to both root templates; without this, it would reach none of MedxEHR, MedxGlass, MedxScribe or the InkRouter members except by hand. `check` now also reports `upstream-added`: a destination the UPSTREAM's copy lists name AT THE TARGET COMMIT — read out of that commit's own `scripts/shape_materialize.py` with `ast`, never this checkout's lists and never `exec` — that the pin has no row for and the root has no file at (a file already there is the in-place-adoption state, not an addition; the Makefile/.gitignore merged-away case stays quiet, as the existing test demands). It counts as something to do, so `check` still exits 1. `apply` writes none of them unless `--add <path>` names one, per file: copy, chmod per the executable list, append the sha256 row, move the pin, all in the same transaction and rolled back whole — including unlinking created files — if a validator goes red. `--add` refuses a path already pinned, one the target's lists do not name, and one the root already has a file at (`update-add-would-overwrite`): two files with one name is a merge. Destinations that are absolute or contain `..` are rejected before any write. Two defects found by the new tests and fixed: `git commit -- <path>` refuses an untracked pathspec, so added paths are staged by name first, and the printed NEXT hint now says `git add -- <added> &&`. A project that DECLINES an addition has no way to say so yet and will see it on every `check`; that is left open on purpose and said in the README. README 513 -> 532; AGENTS.md § Updating gains point 5. Part of #28. Lane: codex-intake-shape Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
@codex review |
There was a problem hiding this comment.
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 2 days and 2 hours by commenting @sourcery-ai review. Upgrade to get a review now.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Reviewer's GuideThe PR extends Sequence diagram for detecting and explicitly adopting upstream-added filessequenceDiagram
participant User
participant UpdateShape as update-shape.py
participant Git as Upstream git
participant Root as Project or family root
participant Validators
User->>UpdateShape: check --at <commit>
UpdateShape->>Git: blob(<commit>, scripts/shape_materialize.py)
UpdateShape->>UpdateShape: ast.parse materializer lists
UpdateShape->>Git: blob(<commit>, source path)
UpdateShape-->>User: report upstream-added, exit 1
User->>UpdateShape: apply --at <commit> --add <path> --yes
UpdateShape->>UpdateShape: resolve_additions
UpdateShape->>Root: copy file and set executable bit
UpdateShape->>Root: append sha256 row and update commit/tree_sha256
UpdateShape->>Root: update manifest
UpdateShape->>Validators: run project or family validators
alt validation fails
UpdateShape->>Root: rollback metadata and remove created files
else validation succeeds
UpdateShape-->>User: re-sync completed
end
Flow diagram for upstream-added adoption decisionsflowchart TD
A[Read target commit materializer with ast] --> B[Map target copy lists to destinations]
B --> C{Pin has a row?}
C -->|Yes| D[Handle as existing pinned copy]
C -->|No| E{Root already has a file?}
E -->|Yes| F[Silently treat as in-place adoption]
E -->|No| G[Report upstream-added]
G --> H{apply includes --add <path>?}
H -->|No| I[Do not write; print pass --add <path>]
H -->|Yes| J{Path is valid and named by target lists?}
J -->|No| K[Refuse]
J -->|Yes| L[Copy file, append pin row, update manifest]
L --> M[Run validators and commit or roll back]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
There was a problem hiding this comment.
🟡 Changes recommended
There are a few concrete safety/robustness gaps in the new --add/filesystem-write paths (argument validation consistency and rollback coverage on OSError) that should be addressed before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds first-class support in update-shape.py for detecting files that were added upstream after a project/family was pinned, and for selectively adopting those files via an explicit apply --add <path> workflow.
Changes:
- Extend
checkto reportupstream-addedentries derived from the target commit’sscripts/shape_materialize.pycopy lists (parsed viaast). - Extend
applywith repeatable--add <path>to copy newly-added files, set executable bits, append new pin rows, and include additions in commits/hints with rollback on validator failure. - Add a comprehensive new test module covering additions, refusals, family-vs-project list separation, and rollback behavior; update README/AGENTS docs and README line-cap.
File summaries
| File | Description |
|---|---|
| update-shape.py | Implements upstream-added detection and apply --add adoption flow (AST list reading, refusals, transactional writes, commit/hint updates). |
| tests/test_update_shape_add.py | New test coverage for upstream-added reporting, --add behavior, refusal cases, family handling, and rollback. |
| tests/test_repo_hygiene.py | Updates README line-cap to reflect added documentation. |
| README.md | Documents upstream-added reporting and explicit adoption via --add, including refusal cases and behavioral constraints. |
| AGENTS.md | Updates the “Updating a project’s shape” procedure to include upstream-added / --add guidance. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| except Refusal: | ||
| for path, original in written.items(): | ||
| path.write_bytes(original) | ||
| for path in reversed(created): | ||
| if path.is_dir(): | ||
| if not any(path.iterdir()): | ||
| path.rmdir() | ||
| elif path.exists(): | ||
| path.unlink() | ||
| raise |
| def inside_a_root(rel: str) -> bool: | ||
| """Is `rel` a path a root can actually hold? | ||
|
|
||
| An absolute path or one with a `..` segment would put a copy OUTSIDE the | ||
| root this command was pointed at. Nothing in openRepoShape's lists has ever | ||
| looked like that, and this is not a defence against the standard — it is | ||
| that these strings arrive from a file read out of a git history, and a | ||
| write that leaves the directory a human named is the one mistake that | ||
| cannot be rolled back by putting the tree as it was. | ||
| """ | ||
| parts = Path(rel).parts | ||
| return bool(parts) and not Path(rel).is_absolute() and ".." not in parts |
| taking = resolve_additions(rows, additions, | ||
| [str(path) for path in (args.add or [])], | ||
| target) |
…scribes (#51) (#58) Git for Windows installs core.autocrlf=true by default; a colleague who did nothing but clone a scaffolded project got CRLF in the worktree and every pinned row went red for them alone. #53 covered the clone setup-project.py makes; this covers the next person. `* text=auto eol=lf` in both root templates, PINNED like every other copy (a file that says what the bytes are is worth nothing if it can be edited without the pin noticing); it joins COPIED_VERBATIM and FAMILY_COPIED_VERBATIM and nothing else in the materializer needed to change. Proof, as tests: a `git -c core.autocrlf=true clone` of a scaffolded project shows w/lf for every pinned file and its own validate-pins.py exits 0; the same clone with the file removed shows w/crlf and FINDING shape-copy-drift on every copy. Existing projects report `upstream-added: .gitattributes` on their next update-shape check and take it with `apply --add` (#29 machinery, tested). 583 tests. Lane: xfactory-2 (xFactory-2) Co-authored-by: Claude Fable 5.1 <[email protected]>



Lane: codex-intake-shape
Claim: #28 (comment)
What
Part of #28 (PR B of two).
update-shape.pyre-synced only the pin's own rows, so a file the standard ADDS after a project was cut never reached that project. Now:checkreportsupstream-addedfor a destination the upstream's copy lists name at the target commit and the pin has no row for and the root has no file at. The lists are read out of the target commit's ownscripts/shape_materialize.pywithast(noexec, no import), mapped source→destination the way_materializedoes, project vs family lists chosen by the manifest the tool already distinguishes. An older upstream whose materializer lacks the names yields no additions and no error.checkstill exits 1 when there is anything to do.apply --add <path>(repeatable) copies the named file, sets the executable bit per the materializer's list, appends thesha256row, movescommit/digests.tree_sha256, mirrors into the manifest, runs the project's own validators and rolls back whole — including unlinking created files — on red. Without--add,applywrites none of them, saysnot added; pass --add <path>, and re-pins the rest.--addof an already-pinned path, of a path the target's lists do not name, and of a path the root already has a file at (update-add-would-overwrite). Absolute or..destinations from an upstream list are rejected before any write.git commit -- <path>refuses an untracked pathspec (added paths are now staged by name first), and the printed NEXT hint now includesgit add -- <added> &&.Deliberate choices
upstream-added— that is the in-place-adoption state (Makefile,.gitignoremerged away, pin rows undershape/), which the existing testtest_a_file_with_no_pin_row_is_not_a_shape_fileprotects. The overwrite refusal is still reachable by naming the path.checkuntil a file arrives at that path. Stated in the README rather than solved here.AGENTS-shape.mdas the motivating addition; that file arrives in PR A (feat/agents-shape-file), in flight.Evidence
python3 -m pytest tests -q: 387 passed. New moduletests/test_update_shape_add.py(fixture: scaffold at C1, upstream C2 adds a verbatim file; check/apply/--add/refusals/family/older-commit).templates/,scripts/shape_materialize.pycopy lists andadopt-project.pyuntouched.🤖 Generated with Claude Code
Summary by Sourcery
Support detecting and selectively adopting files added by the standard after a project was pinned.
New Features:
apply --add <path>options.Bug Fixes:
Enhancements:
Documentation:
Tests: