Repository navigation
Commit 8d34c44
feat(pm): git-history ancestor and dev-worktree.sh take over two procedures os-dev retyped by hand (#38018)
Part of #35237
Clause-②: no
Metadata-protocol: none
Rule-change: none
Slice 7 of the card (the last slice its release notes name):
`git-history ancestor` and `dev-worktree.sh`, with the `os-dev.md`
pointers. The card stays open for the seat to judge its done-when across
all seven slices.
## 维护者速读
- 用户能看到什么变化:用户无感。开发 agent
开工时「建自己的工作区」和判断「某个提交是否已经在主干里」这两件事,从每次手敲一串命令,改成各跑一个脚本。
-
为什么做:这是「把技能里反复手敲的流程做成脚本」这张卡的最后一片;手敲版在不完整的代码副本上会把「其实已经合入」读成「没合入」,而且看不出任何异常。
-
出错会怎样:只影响车队内部工具,不动产品代码。脚本拿不准时拒绝回答而不是给一个错答案,不明说就不向远端推送任何东西;发现问题可以整体撤回这一个改动。
- 要你做什么:合并这一个改动(它改了开发 agent 的规则文件,属于要你点头才落地的范围)。
## What changes
Angle-bracket placeholders of the source files are spelled as capital
words below (`N`, `SLUG`, `REPO`, `SHA`, `BRANCH`).
### 1. `node scripts/pm/git-history.mjs ancestor --commit=SHA
[--ref=origin/main] [--control=SHA]`
**What it mechanises:** the two-leg procedure of
`references/dev-traps.md` 〈浅检出上的祖先读数〉. `git merge-base --is-ancestor` on
a shallow clone fails in one direction only: exit 0 proves itself, and
exit 1 is also what a shallow cut produces for a real ancestor that sits
below it. The prose had a dev run a second leg by hand (a commit known
to be in the ref's history, at least as deep as the tested one, must
answer 0 on the same clone), deepen until it does, and read again.
The command runs both legs and prints `yes` or `no` alone on stdout,
with both legs and the exit code git gave each in a one-line receipt on
stderr:
- a **yes** prints at once and never fetches;
- a **no** stands only when no cut can hide the tested commit: the ref's
history carries no graft at all, or every graft boundary under the ref
is older than the tested commit by the skew margin. The newest boundary
is the control leg, and that leg is run;
- `--control=SHA` adds the operator's own leg on top. It must answer 0
and must not be newer than the tested commit (a near relative inside the
shallow window is refused);
- otherwise it climbs the same additive ladder `touch` climbs
(`--deepen=N` doubling, then `--unshallow`) and reads again, and
**refuses** with exit 2 and empty stdout when the negative still cannot
be told from a cut;
- a boundary walk that could not be read is refused too. It is never
taken for a complete history, which is the one reading that proves a no.
Three decisions (each judged to hold by the contract review of the first
head):
1. **The control is chosen by the tool.** The floor is the one commit
that is always in the history and always deep enough, and it covers a
second cut on another line of a merged history, which one hand-picked
control does not.
2. **A proven no exits 3.** Not 0, so `ancestor … && echo landed` cannot
read a no as a yes. Not 1, because 1 is this tool's usage exit. The
other commands keep their exit contract.
3. **"Deeper" is read by committer date**, with `--margin-days` (default
7) as slack. A history whose committer dates run backwards along
ancestry defeats it; a complete clone needs no such assumption. The file
header says so.
### 2. `bash scripts/pm/dev-worktree.sh --branch=claude/issue-N-SLUG
[--probe]`
**What it mechanises:** rule 1 of `os-dev.md` (Worktree-first), step by
step, in the rule's own order.
| Rule 1 line | What the script runs |
|:---|:---|
| build the worktree from a fetched `origin/main` | `git fetch origin
main`, then `git worktree add --no-track` beside the checkout, named
`REPO-issue-N` from the branch (`--worktree=NAME` when the claim names
it) |
| `Resume-from: BRANCH@SHA` | `--resume-from=BRANCH@SHA`: the same-name
branch from `origin/BRANCH`, after checking that its tip is that sha.
The merge of `origin/main` stays `os-regen-merge.sh`'s; the script names
it |
| record `BASE` before the first edit | HEAD is pinned in a file in the
worktree's own git dir; `--base` prints it. A resumed branch pins after
its merge with `--pin-base`. A pin is never moved |
| push the empty branch before any edit | **only with `--probe`**: `git
push -u origin BRANCH` |
| a card-thread branch is never pushed | the default. With no flag
nothing is pushed, whatever the branch is called; `--no-probe` says the
default out loud |
| 403 stops, only a network error is retried | exit 3 after one push on
a 403; a network error is retried on `--backoff` (default 2, 4, 8, 16 s)
and then given up with exit 4; any other refusal is exit 5 with no retry
|
| `issue-N/` under the scratchpad | `--scratchpad=DIR` |
| `pnpm install` in the tree | run last (`--no-install` skips it) |
**Nothing is pushed on a spelling alone.** A branch name cannot tell a
self-built branch from the alias a card thread builds its tree under, so
no name is probed by default. A run without `--probe` prints
`PROBE=skipped` and the line that says what a self-built branch still
owes; the same command with `--probe` completes it.
It never forces: no `--force`, no `-B`, no checkout in the shared tree.
An existing path, an existing local branch, or a branch already on
`origin` with no `--resume-from` is refused before anything is created.
A second run for a tree it already built re-creates nothing, and with
`--probe` sends the probe only if the branch is still empty and absent
from `origin`.
The build starts from a checkout, because that is where `git worktree
add` runs. Every WRITE there is refused: the tree is always built beside
the checkout, and `--pin-base` refuses in the shared checkout.
**Not mechanised, and why:** the merge of `origin/main` on a resume
(already `os-regen-merge.sh`); the clean-up step; a card thread whose
platform branch is already checked out in the shared tree (the script
refuses an existing local branch, so that case stays by hand, and now
pushes nothing either way).
### 3. The pointers
| File | Line | Before | After |
|:---|:---|:---|:---|
| `os-dev.md` | rule 1, command line | `git fetch origin main && git
worktree add --no-track ../REPO-issue-N -b claude/issue-N-SLUG
origin/main` | `bash scripts/pm/dev-worktree.sh
--branch=claude/issue-N-SLUG`:自 `origin/main` 建 `../REPO-issue-N`。 |
| `os-dev.md` | rule 1, probe line | 建好分支后先推空分支(任何编辑前 `git push -u
origin BRANCH`):落地标记兼写路由探针。 | 建好分支后先推空分支(任何编辑前 `dev-worktree.sh
--probe`):落地标记兼写路由探针。 |
| `dev-traps.md` | control-leg line | 它必须答 exit 0;否则阴性作废,`git fetch
--deepen` / `--unshallow` 到控制腿转 0 再重读。 | 它必须答 exit 0;否则阴性作废,加深到控制腿转 0
重读;现读 `git-history.mjs ancestor`。 |
Every other line of rule 1 and of the dev-traps section is unchanged,
the card-thread ⛔ line included. Each changed line keeps its rule
sentence and names the script as its reading; only the typed command
leaves.
**The `os-dev.md` ancestor line is back to main's text.** The first head
appended the reader to it. Naming the script on the probe line costs 26
bytes, the file sits at its 33504-byte ceiling, and that line was the
only place the bytes could come from without cutting a rule sentence.
The line still orders the dev-traps section read before any ancestor
judgment, and that section's control-leg line names `git-history.mjs
ancestor`. The form that keeps all three pointers was measured and fits
at exactly 33504 bytes, but only by writing the probe line as 「加
`--probe`」 with no script name, naming `git-history.mjs` without its
subcommand, and dropping `bash` from the command line.
**Why `Rule-change: none` holds:** the three lines change which command
is typed, not what a dev may do, in what order, or what goes to the
maintainer. The worktree is still built before any edit from a fetched
`origin/main`, the base is still recorded before the first edit, the
empty branch is still pushed before any edit by the dev who owns a
self-built branch, a card-thread branch is still never pushed (now by
default), a 403 still stops with no retry, and a negative ancestor
reading still owes a control leg that answers 0.
Budget: `os-dev.md` 356 → 356 lines, 33504 → 33500 bytes (ceiling 33504,
not moved); `dev-traps.md` 34 → 34 lines, 2627 → 2627 bytes (ceiling
2627). Whole PR: 1683 changed lines (+1671 / -12) over 5 files.
### 4. Wiring
`git-history.mjs --self-test` already runs in `lint.yml`'s
shallow-history step. `dev-worktree.sh --self-test` joins the existing
`check:pm-with-fleet` chain in `package.json`. No new CI job, no
workflow edit.
## Tests
Both self-tests carry a named-battery floor and a verdict handshake.
<details>
<summary>Self-tests at b829905</summary>
```
node scripts/pm/git-history.mjs --self-test exit 0 git-history --self-test: all cases passed. (123 cases, 7 batteries; the ancestor battery registers 38)
bash scripts/pm/dev-worktree.sh --self-test exit 0 ✓ dev-worktree self-test: 85 cases pass across 7 batteries — offline, a bare fixture origin, no network.
```
The `ancestor` battery reproduces the defect first, on a 40-commit
repository cloned at depth 5 (git 2.43.0):
| `git merge-base --is-ancestor X origin/main` | exit |
|:---|:---|
| c38, inside the window | 0 |
| c2, in main's real history, its object not in the clone | 128 |
| c2 again, after its object was fetched by sha | **1** |
| a commit built on c2 that never merged | 1 |
The `dev-worktree` self-test builds real worktrees against a bare origin
in a temp dir. A `git` shim on `PATH` answers the probe from a plan
(403, network, other, or the real push) and counts the pushes; a `pnpm`
shim records the install.
Cases added by the review round:
- no flag, the `claude/issue-N-SLUG` spelling: the tree is built, zero
pushes, origin has no such branch, the base is pinned; the same command
with `--probe` then sends one push;
- a branch under any other spelling needs no flag and is not pushed;
`--no-probe` is still accepted;
- an injected boundary walk that answers null reads `unreadable`, on the
clone and the commit whose honest reading is `no`;
- an injected parent read that answers null makes the complete clone's
root an undecided boundary, and an undecided boundary proves nothing;
- the floor's control leg carries the exit code git gave for it;
- a real blob's sha as `--commit` on a complete clone is usage (exit 1),
where it was answered `no`.
</details>
<details>
<summary>Ablations (each through scripts/ablation-replace.mjs; mutation
proven on disk, restore proven blob == HEAD)</summary>
At `b829905e0`, for the review round:
| File | Mutation | Self-test |
|:---|:---|:---|
| `dev-worktree.sh` | the default probe mode is `probe` again | exit 1,
5 red (the no-flag case first: one push where zero is pinned) |
| `git-history.mjs` | the boundary walk is read with a fallback to the
empty list again | exit 1, 1 red (the injected null walk reads `no`) |
| `git-history.mjs` | an unreadable parentless commit is not recorded |
exit 1, 2 red |
| `git-history.mjs` | the prefix problem is not turned into usage | exit
1, 1 red (the blob case) |
The first attempt at the second row did not run: its anchor occurred
twice in the file and the tool wrote nothing. It was re-run with a
longer anchor.
At `6bf1b0608`, for the first head (the graft-boundary row is superseded
by the two rows above; the others still describe current code):
| File | Mutation | Self-test |
|:---|:---|:---|
| `git-history.mjs` | the floor comparison accepts any boundary | exit
1, 8 red |
| `git-history.mjs` | the near-relative check on `--control` never fires
| exit 1, 3 red |
| `git-history.mjs` | no parentless commit is read as a graft boundary |
exit 1, 11 red |
| `dev-worktree.sh` | the 403 pattern never matches | exit 1, 7 red |
| `dev-worktree.sh` | `--no-probe` is not honoured | exit 1, 1 red |
| `dev-worktree.sh` | a branch already on origin is logged instead of
refused | exit 1, 2 red |
| `dev-worktree.sh` | the `Resume-from` sha is not compared with the tip
| exit 1, 2 red |
</details>
<details>
<summary>Live readings on this container's shallow clone (one graft
boundary under origin/main, dated 2026-11-16)</summary>
```
ancestor --commit=d44b5e3d --no-fetch yes exit 0 (the squash commit of this card's slices 3, 5 and 6)
ancestor --commit=d1a21fcaf --no-fetch no exit 3 tested leg exit 1 · control leg 8436f67 exit 0 (2026-11-16, at least 7 days older)
```
Taken at the first head. `d1a21fcaf` is this branch's own first commit,
so the no is true. `dev-worktree.sh` was run live only on paths that
write nothing to origin. A live fresh build with `--probe` would leave a
probe branch on origin that no seat can delete, so that path is measured
in the self-test only; the classifier has not seen this platform's own
refusal text, and a line it cannot place reads `other` (exit 5, stop, no
retry).
</details>
## Review round 1
The contract review of the first head (`e1dcc0304`) answered FAIL with
one mandatory finding (M1) and one recommended one (S1). At `b829905e0`:
- **M1, taken on the seat's route.** The script never pushes on a
spelling alone, and rule 1's probe line names the script with `--probe`.
- **S1, taken.** A boundary walk that cannot be read is `unreadable`
(exit 2); a parentless commit whose parents cannot be read is an
undecided boundary, which proves nothing.
- **N1, taken.** A hex string that is ambiguous, or that names an object
which is not a commit, is usage.
- **N2, taken by running the leg.** The floor's control leg is run and
the receipt prints the exit code git gave.
- **N4, taken, all three.** A `git worktree add` that fails after making
the branch is refused with a verdict that names the branch it left; the
refusal for a path that holds another branch names `--worktree=NAME`; an
unpinned tree is told its base is unpinned, not that it "is no longer an
empty branch".
- **N3 and N5, left as recorded.** The classifier's uneven edges are
bounded and on the stopping side; the usage line does not yet say that a
proven no is proven against the ref as last fetched.
## Acceptance notes
- **`--pin-base` pins HEAD.** It is the base only while the tree's first
edit is still ahead, and the script says so when it finds a tree it did
not build.
- **The margin is a heuristic and is named as one.** A no proved by the
floor rests on committer dates being monotone along ancestry within
`--margin-days`. A complete clone is the assumption-free leg.
- **Raw `merge-base --is-ancestor` is still spelled in four reference
files outside this surface** (`cross-repo-coordination.md`,
`lanes/security.md`, `readings-queue.md`, `readings-shell.md`). They are
seat procedures, not the dev's; the seat carries them on the card.
- `AGENTS.md` names `git-history.mjs` for the windowed question only. It
is outside this surface and unchanged.
- `os-dev.md` is 4 bytes under its ceiling. The ceiling row lives in the
ratchet script, which is outside this surface, so it was not lowered
here.
- Ablations were run although `os-dev.md` lists scripts among the things
not ablated: each one mutates a behaviour a self-test pins.
## Verification
**Read first (by risk):**
1. `.claude/agents/os-dev.md`: two lines of rule 1 (the command line and
the probe line). This is fleet rule text; judge `Rule-change: none`
here.
2. `scripts/pm/dev-worktree.sh`: the probe-mode default in `mode_build`,
`probe_push` and `classify_push_failure`. This is the only code in the
PR that writes to origin, and it runs only under `--probe`.
3. `scripts/pm/git-history.mjs`: `graftBoundaries`, `negativeIsProven`
and `ancestorReading`. This is the proof a no rests on.
**Two-minute check:** `bash scripts/pm/dev-worktree.sh --self-test &&
node scripts/pm/git-history.mjs --self-test`. Expect the two success
lines quoted under Tests, exit 0, in about 15 seconds.
<details>
<summary>Gates and CI at b829905</summary>
```
Local, at b829905 (tree clean):
dispatch-gates --commands 84 derived families (5 paths vs merge base 4af32b9)
all 84 run, each exit recorded before any pipe: 78 exit 0, 6 exit 3 (PREREQUISITE NOT MET)
dispatch-gates --ran exit 0 "84 derived famil(ies) accounted for — 78 run, 6 NOT-MEASURED (6 DERIVED from a recorded exit 3)."
NOT MEASURED locally (they read a built dist; the diff touches no package, so none was built):
check:doc-formula-expressions, check:dts-closure, check:dual-build-cjs-loads,
check:i18n-coverage, check:lean-entry-closure, check:sourcemap-no-sources-content
named inside the 78: check:pm-with-fleet, check:pm-skill-ratchet (os-dev.md 33500/33504, dev-traps.md 2627/2627),
check:pm-skill-id-lint, check:pm-governed-prose, check:pm-dispatch-gates, check:bash32-floor,
check-self-test-wired, check:nul-bytes, check:commit-card-trailers
CI check-runs on b829905, read when the local round ended: 59 runs — 45 success, 10 skipped, 0 failed,
0 in_progress at the seat's re-read after the run finished: 60 runs, 50 success, 10 skipped, 0 failed.
success: Lint & Repo Gates, TypeScript Type Check, Test Core, Build Core, Governed Surface Queue Guard,
PR-body guards. The pull reads mergeable: true.
```
</details>
<!-- signed: repo:objectstack#8 · os-mickey ·
session_01ASNY8UcT2uJmgTyCPnMiMZ -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent dbe0716 commit 8d34c44
5 files changed
Lines changed: 1671 additions & 12 deletions
File tree
- .claude
- agents
- skills/pm-dispatch/references
- scripts/pm
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| |||
0 commit comments