@softure-ai/skills 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ONBOARD.md +2 -1
- package/README.md +7 -2
- package/WORKFLOW.md +64 -11
- package/package.json +1 -1
- package/rules/AGENTS.md +73 -19
- package/skills/softure-archive/SKILL.md +30 -6
- package/skills/softure-init/SKILL.md +9 -3
- package/skills/softure-worktree/SKILL.md +107 -46
- package/skills/softure-worktree/scripts/wt-merge-check.py +140 -0
- package/skills/softure-worktree/scripts/wt-roadmap.py +172 -18
- package/skills/softure-worktree/scripts/wt-startable.py +153 -0
- package/skills/softure-worktree/scripts/wt_config.py +2 -2
- package/skills/softure-worktree-manager/SKILL.md +40 -14
- package/skills/softure-worktree-manager/references/report-routine.md +11 -5
- package/skills/softure-worktree-manager/scripts/wm-resume.sh +5 -4
|
@@ -123,15 +123,23 @@ Read `mode` at A0 (`python3 <S>/wt_config.py mode`; WORKFLOW §8, the project's
|
|
|
123
123
|
an open thread;
|
|
124
124
|
2. no coordinator: go straight on;
|
|
125
125
|
3. then Phase B by `autonomy.merge`:
|
|
126
|
-
- `"pr"` (default):
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
(
|
|
134
|
-
|
|
126
|
+
- `"pr"` (default): the pull request was opened at READY (`Closes #N` when
|
|
127
|
+
the change solves an issue). After the go, run
|
|
128
|
+
`python3 <S>/wt-merge-check.py`. `VERDICT merge-as-is` and the forge
|
|
129
|
+
reports the pull request mergeable → merge it as it is (its checks were
|
|
130
|
+
green at READY). `VERDICT remerge` (or `autonomy.remergeMain: "always"`)
|
|
131
|
+
→ merge `origin/<main>` into the branch (A5), run the `RUN` lines it
|
|
132
|
+
printed, push, and enable the forge's auto-merge for the pull request
|
|
133
|
+
(`gh pr merge <N> --auto --merge` or the forge tool) so it merges on
|
|
134
|
+
green without polling; where auto-merge is not available, wait for
|
|
135
|
+
green checks and merge (`gh pr merge <N> --merge`). The forge deletes
|
|
136
|
+
the head branch. Confirm `origin/<main>` contains the merge, run
|
|
137
|
+
`python3 <S>/wt-roadmap.py done <change-id>` (it pushes the roadmap
|
|
138
|
+
state to `origin/<main>`), then the local cleanup of step 5. A red check
|
|
139
|
+
is fixed on the branch, never bypassed;
|
|
140
|
+
- `"push"`: Phase B as written (its `wt-roadmap.py done` included), then
|
|
141
|
+
push `<main>` through the pre-push hook (step 6's "no push" does not
|
|
142
|
+
apply). A rejected push → fetch, merge `origin/<main>`, push again;
|
|
135
143
|
4. report the merge (SHA, PR) to the coordinator or the project chat, and
|
|
136
144
|
close the session's thread when the harness has one.
|
|
137
145
|
|
|
@@ -157,15 +165,30 @@ add`), the change-id lives in `context/changes/`, the READY and merge reports
|
|
|
157
165
|
go to the coordinator's session by cross-session message, the go comes back
|
|
158
166
|
the same way, and the thread is resolved only after its pull request is merged.
|
|
159
167
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
`
|
|
168
|
+
**Bootstrap check (hosted thread, autonomous mode), in A0.** The coordinator
|
|
169
|
+
follows the managed block only if the project instructions point it there
|
|
170
|
+
(WORKFLOW §8.5, Bootstrap); without the pointer it runs on the harness defaults
|
|
171
|
+
and holds ready merges for the owner. So, at session start, look for the
|
|
172
|
+
pointer in the project instructions this session was given (the snippet, or
|
|
173
|
+
any reference to this repository's `AGENTS.md`). When it is missing, or there
|
|
174
|
+
are no project instructions at all, the first message to the coordinator says
|
|
175
|
+
so, carries the snippet from WORKFLOW §8.5 with `<owner>/<repo>` filled in from
|
|
176
|
+
`git remote get-url origin`, and asks the coordinator to read `AGENTS.md` and
|
|
177
|
+
`context/workflow.json` from the main branch now and to tell the owner where to
|
|
178
|
+
paste the snippet. Then carry on with the change; the check never blocks it.
|
|
179
|
+
|
|
180
|
+
**`worktree.cloudState: "branch"`** changes points 1, 6 and 7: the claim and
|
|
181
|
+
every stage are committed **on the session branch only** (`wt-roadmap.py` does
|
|
182
|
+
it by itself in that mode), A4 archives without `--handoff` (the branch writes
|
|
183
|
+
its own `done` row), and nothing goes to `origin/<main>` before the merge. The
|
|
184
|
+
price: every merge of `<main>` into the branch conflicts on `roadmap.md`, so a
|
|
185
|
+
merge can never skip the back-merge. Use it only when a push to `<main>` is
|
|
186
|
+
expensive (a pre-push hook without a cheap path for `context/`-only pushes,
|
|
187
|
+
WORKFLOW §2 → CI minutes) and a coordinator assigns the items — then the
|
|
188
|
+
assignment, not a claim on `<main>`, keeps two sessions off one item, so A1
|
|
189
|
+
takes the item it was given and does not need `origin/<main>` to show it free.
|
|
190
|
+
Default `"main"` is the flow below: the roadmap state lives on `origin/<main>`,
|
|
191
|
+
live for every stage, and the branch never edits `roadmap.md`.
|
|
169
192
|
|
|
170
193
|
**1. Claim first, on origin, before anything else.** Right after A1 picks the
|
|
171
194
|
item — before installing dependencies, before research — mark it taken **on
|
|
@@ -190,8 +213,8 @@ SHA before you start research.
|
|
|
190
213
|
The row says `cloud session, branch <session-branch> — do not take in another
|
|
191
214
|
session`. If `open` refuses because the row is already `in_progress`, another
|
|
192
215
|
session owns it: pick again (A1), never take it over. Every `stage` call later
|
|
193
|
-
in the chain
|
|
194
|
-
see live state. A1's "not already taken" check reads **`origin/<main>`**
|
|
216
|
+
in the chain, `ready`, and `done` after the merge go to origin the same way, so
|
|
217
|
+
the owner and every other session see live state. A1's "not already taken" check reads **`origin/<main>`**
|
|
195
218
|
(`git fetch origin <main> && git show origin/<main>:context/foundation/roadmap.md`),
|
|
196
219
|
not the local file.
|
|
197
220
|
|
|
@@ -239,9 +262,12 @@ project's CI on origin: push at READY and to sync before the merge, **never per
|
|
|
239
262
|
phase or per commit** (WORKFLOW §2, CI minutes).
|
|
240
263
|
|
|
241
264
|
**6. READY.** A3.8 runs before A4, as locally (unless the cadence defers it).
|
|
242
|
-
A5
|
|
243
|
-
|
|
244
|
-
|
|
265
|
+
A5 works on `origin/<main>` (after `git fetch origin <main>`), not the local
|
|
266
|
+
one, and with `autonomy.merge: "pr"` merges it in only when
|
|
267
|
+
`wt-merge-check.py` says `remerge` (A5). Then `wt-roadmap.py ready
|
|
268
|
+
<change-id>` (pushed to origin; with `cloudState: "branch"` committed on the
|
|
269
|
+
branch), push the session branch, open the pull request (with `autonomy.merge:
|
|
270
|
+
"pr"`), report, stop.
|
|
245
271
|
|
|
246
272
|
**No deploy from a cloud session, ever** — and, while `release.owner` is true,
|
|
247
273
|
from any session: no ssh to servers, no tags, no `gh release`, no edit of
|
|
@@ -273,9 +299,11 @@ git push origin <main> # the pre-push hook is the classic
|
|
|
273
299
|
Let the pre-push hook run — it *is* the full gate on `<main>` that A5 defers
|
|
274
300
|
to. If it fails, fix on the session branch, merge again, push again; never
|
|
275
301
|
`--no-verify`. A rejected push (`<main>` moved) → fetch, merge `origin/<main>`
|
|
276
|
-
into `<main>`, push again.
|
|
277
|
-
|
|
278
|
-
|
|
302
|
+
into `<main>`, push again. Then `python3 <S>/wt-roadmap.py done <change-id>`
|
|
303
|
+
records `done` / `done_code` on `origin/<main>` from the archived change's
|
|
304
|
+
`## Roadmap handoff` (with `cloudState: "branch"` the row arrived with the
|
|
305
|
+
merge itself). No worktree to remove; don't delete the session branch (the
|
|
306
|
+
harness owns it).
|
|
279
307
|
|
|
280
308
|
## The Prime Directive
|
|
281
309
|
|
|
@@ -452,8 +480,9 @@ folder"), use exactly that source. Moving an entry from `context/backlog/` into
|
|
|
452
480
|
> **Cloud session:** replaced by *Cloud session* points 1–3.
|
|
453
481
|
|
|
454
482
|
Order matters: **mark the roadmap on `<main>` first, then branch from it**, so
|
|
455
|
-
the
|
|
456
|
-
|
|
483
|
+
the claim is on `<main>` before any work starts. From here on the branch never
|
|
484
|
+
edits `roadmap.md` (A4); every later stage is a `wt-roadmap.py` commit on
|
|
485
|
+
`<main>`.
|
|
457
486
|
|
|
458
487
|
```bash
|
|
459
488
|
python3 <S>/wt-roadmap.py open <change-id> [--note "prerequisite X on branch Y — merge after X"]
|
|
@@ -790,23 +819,37 @@ owner. This rule may be the only thing between a session and production.
|
|
|
790
819
|
|
|
791
820
|
### A4 — Archive on the branch
|
|
792
821
|
|
|
793
|
-
Stage `archive`, then `/softure-archive <change-id> --auto` — **no
|
|
794
|
-
`<main>`** (the change branch may go to origin, `<main>` never). It
|
|
795
|
-
`change.md`, moves the folder to `context/archive/<created>-<id>/` and
|
|
796
|
-
`chore(archive): close <change-id>`. Commit uncommitted files of the
|
|
797
|
-
folder first (they are yours). Then, on the branch:
|
|
798
|
-
|
|
799
|
-
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
(`
|
|
822
|
+
Stage `archive`, then `/softure-archive <change-id> --auto --handoff` — **no
|
|
823
|
+
push of `<main>`** (the change branch may go to origin, `<main>` never). It
|
|
824
|
+
stamps `change.md`, moves the folder to `context/archive/<created>-<id>/` and
|
|
825
|
+
commits `chore(archive): close <change-id>`. Commit uncommitted files of the
|
|
826
|
+
change folder first (they are yours). Then, on the branch:
|
|
827
|
+
|
|
828
|
+
- **`roadmap.md` is not touched on the branch.** The archived `change.md`
|
|
829
|
+
carries `## Roadmap handoff` instead: `Status: done`, or `done_code
|
|
830
|
+
(waiting: <what waits for the release>)` when the change awaits a deploy
|
|
831
|
+
(pure document changes stay `done`), the `## Done` outcome, the owner checks
|
|
832
|
+
and the steps for `## Before the next release`. `wt-roadmap.py done
|
|
833
|
+
<change-id>` writes all of it on `<main>` right after the merge (Phase B).
|
|
834
|
+
With `cloudState: "branch"` archive without `--handoff`: the branch's row and
|
|
835
|
+
item block must read `done` / `done_code`, and the `## Done` line is there.
|
|
803
836
|
- Re-point links: documents that referenced `context/changes/<id>/` must now
|
|
804
837
|
point to `context/archive/<date>-<id>/` (`grep -rn "changes/<id>"`).
|
|
805
838
|
- Commit on the branch.
|
|
806
839
|
|
|
807
840
|
### A5 — Sync with `<main>` and prove it
|
|
808
841
|
|
|
809
|
-
`<main>` moved while you worked. It
|
|
842
|
+
`<main>` moved while you worked. It usually does.
|
|
843
|
+
|
|
844
|
+
**Autonomous mode with `autonomy.merge: "pr"`: merge it in only when needed.** Run
|
|
845
|
+
`python3 <S>/wt-merge-check.py` (it fetches `origin/<main>`). `VERDICT
|
|
846
|
+
merge-as-is` → skip the merge; READY says `<main> not merged in
|
|
847
|
+
(wt-merge-check: merge-as-is)` and the pull request is merged as it is after
|
|
848
|
+
the go. `VERDICT remerge` → merge as below, then run the `RUN` lines it printed
|
|
849
|
+
(the gates the merge can break: `GATES related` or `full`) before pushing.
|
|
850
|
+
`autonomy.remergeMain: "always"` → always merge. The same check runs again
|
|
851
|
+
after the go (*Operating mode*), because `<main>` keeps moving. Otherwise
|
|
852
|
+
(manual mode, or `autonomy.merge: "push"`) the branch is always made current:
|
|
810
853
|
|
|
811
854
|
```bash
|
|
812
855
|
cd <WT> && git merge <main> # merge, NOT rebase: ## Progress holds the branch's SHAs
|
|
@@ -817,15 +860,15 @@ check them:
|
|
|
817
860
|
|
|
818
861
|
| File | Resolution |
|
|
819
862
|
| --- | --- |
|
|
820
|
-
| `roadmap.md
|
|
821
|
-
| `roadmap.md`, every other row and section | **`<main>`** |
|
|
863
|
+
| `roadmap.md` | **`<main>`**: the branch never edits it (A4 hands off). Only with `cloudState: "branch"`: your row and block from the **branch** (`done` / `done_code`), every other row and section from `<main>` |
|
|
822
864
|
| `lessons.md` | `<main>`'s entries first, yours after, **renumbered** to the next free number (`wt-status.sh`). Update every reference to your old numbers (plan, reviews, archive docs, code comments): `grep -rn "L-<old>"`. |
|
|
823
865
|
| migration number collision (`migrations.dir`) | `<main>`'s migration keeps its number. Save your migration body (it may hold hand edits). Remove your migration and whatever metadata the generator keeps for it, take `<main>`'s metadata, run `migrations.regenerate`, then diff the new file against the saved body and restore any hand edits. Update prose that names the number. |
|
|
824
866
|
| `change.md` / archive docs of other changes | union: keep `<main>`'s links and add yours |
|
|
825
867
|
| code | resolve on the merits; this is the only row that needs thought |
|
|
826
868
|
|
|
827
|
-
Then commit the merge. **No full gates after a back-merge
|
|
828
|
-
|
|
869
|
+
Then commit the merge. **No full gates after a back-merge** (with
|
|
870
|
+
`autonomy.merge: "pr"`, the `RUN` lines of `wt-merge-check.py` instead). The
|
|
871
|
+
pre-commit hook is enough; don't run the test gate or integration on the merged tree, and
|
|
829
872
|
don't repeat A3.8 — the item's integration run was on the pre-merge branch,
|
|
830
873
|
and that is the one READY reports. Full gates run twice anyway: in the
|
|
831
874
|
worktree before the back-merge, and the classic way on `<main>` after Phase B
|
|
@@ -851,7 +894,7 @@ Write it in `chatLanguage` (default: `language`), for someone who wasn't there:
|
|
|
851
894
|
```
|
|
852
895
|
<ID> `<change-id>` — ready to merge.
|
|
853
896
|
|
|
854
|
-
Branch <change-id> (worktree ../<repo>-<change-id>), <N> commits, <main> merged in @ <sha
|
|
897
|
+
Branch <change-id> (worktree ../<repo>-<change-id>), <N> commits, <main> merged in @ <sha> | <main> not merged in (wt-merge-check: merge-as-is).
|
|
855
898
|
Gates on the branch before merging <main>: <each gate> ✓ (tests <count>)
|
|
856
899
|
integration: <green|red|n/a|not configured> <passed>/<total> on <sha> — <url>; new reds: <list or "none">
|
|
857
900
|
(reds already on <main>: <list or "none">; flaky: <list or "none">)
|
|
@@ -873,6 +916,18 @@ coordinator, the report is sent after the merge with its SHA and PR.
|
|
|
873
916
|
Then end the turn. Don't poll, don't schedule wake-ups, and don't ask "shall I
|
|
874
917
|
merge?". The report already says what happens next.
|
|
875
918
|
|
|
919
|
+
**Exception: PR events cannot reach this session.** In a cloud session with
|
|
920
|
+
`autonomy.merge: "pr"`, check at session start whether pull request activity can
|
|
921
|
+
reach you (subscribing to the pull request succeeds, the forge app has access
|
|
922
|
+
to the repository). If it cannot, ending the turn after a push or after the go
|
|
923
|
+
means sleeping until someone nudges you. Then, after every push of a branch
|
|
924
|
+
with an open pull request (READY, and Phase B after the go), check its checks
|
|
925
|
+
yourself until they finish: a scheduled wake-up every few minutes, for at most
|
|
926
|
+
about 60 minutes, then report to the coordinator what is still pending. When
|
|
927
|
+
the checks are green after the go, merge at once. After the go, prefer the
|
|
928
|
+
forge's auto-merge (*Operating mode*, step 3): it merges on green by itself,
|
|
929
|
+
so there is nothing to poll for.
|
|
930
|
+
|
|
876
931
|
## Phase B — merge (on the owner's signal; autonomous mode: see *Operating mode*)
|
|
877
932
|
|
|
878
933
|
Signals (in any language the owner uses): "merge", "go into main", "main is free",
|
|
@@ -914,6 +969,11 @@ merge at the end.
|
|
|
914
969
|
proof that `<main>` holds exactly the branch's tree. The full gates on that
|
|
915
970
|
tree run the classic way on `<main>` afterwards; say that in the report.
|
|
916
971
|
With `--no-tests`, the owner has also waived that later run; say so.
|
|
972
|
+
Then record the roadmap state on `<main>`: `python3 <S>/wt-roadmap.py done
|
|
973
|
+
<change-id>` (a documents-only commit of the row, the item block, `## Done`,
|
|
974
|
+
the owner checks and the release steps from the archived change's
|
|
975
|
+
`## Roadmap handoff`; with `cloudState: "branch"` the merge already brought
|
|
976
|
+
them).
|
|
917
977
|
5. **Cleanup — only your own:**
|
|
918
978
|
```bash
|
|
919
979
|
git -C <WT> status --short # must be empty (ignored files are fine)
|
|
@@ -951,13 +1011,14 @@ merge at the end.
|
|
|
951
1011
|
- **See the test fail before you believe the fix**; an arithmetic fix gets an
|
|
952
1012
|
oracle of a different kind.
|
|
953
1013
|
- **`<main>` is written by exactly two things:** `wt-roadmap.py` (one row per
|
|
954
|
-
commit) and the final
|
|
1014
|
+
commit, `done` included) and the final merge. **The branch never edits
|
|
1015
|
+
`roadmap.md`** (unless `cloudState: "branch"`). Nothing else from this skill lands on
|
|
955
1016
|
`<main>`, and nothing lands there before the owner's signal. Refs this skill
|
|
956
1017
|
may push: the change branch and whatever the project's integration command
|
|
957
1018
|
pushes — nothing else.
|
|
958
1019
|
- **The roadmap on `<main>` always shows where the change is:** `in_progress`
|
|
959
1020
|
from A2 with the current stage, `ready_to_merge` at READY,
|
|
960
|
-
`done` / `done_code` after the merge.
|
|
1021
|
+
`done` / `done_code` right after the merge (`wt-roadmap.py done`).
|
|
961
1022
|
- **Every file edit from A2 to B1 lands under `<WT>`**, never in the main tree.
|
|
962
1023
|
- **Integration: the full suite, once per item** (cadence `change`; once per
|
|
963
1024
|
roadmap at the coordinator's M7 with cadence `roadmap`) — A3.8, after impl-review and
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Decide whether a change branch must merge the main branch in again before its merge, and which gates
|
|
3
|
+
that merge has to re-run.
|
|
4
|
+
|
|
5
|
+
wt-merge-check.py [--base <ref>] [--no-fetch]
|
|
6
|
+
|
|
7
|
+
Run in the change branch's checkout (worktree or cloud session), after the go and before merging the
|
|
8
|
+
pull request. Compares what `<main>` brought since the branch last merged it (merge-base..origin/<main>)
|
|
9
|
+
with what the branch changes (merge-base..HEAD) and prints:
|
|
10
|
+
|
|
11
|
+
VERDICT merge-as-is | remerge
|
|
12
|
+
GATES none | related | full
|
|
13
|
+
<one line per finding: incoming, overlap, migrations, dependencies, test setup/config>
|
|
14
|
+
RUN <command> (only with `remerge`: the gates to run on the merged tree, in order)
|
|
15
|
+
|
|
16
|
+
`merge-as-is` — `<main>` has not moved, or (with `autonomy.remergeMain: "when-needed"`, the default) it
|
|
17
|
+
brought no migration, no dependency change and no file the branch also changes. Merge the pull request
|
|
18
|
+
as it is, provided the forge reports it mergeable and its checks were green at READY. No push, no hook.
|
|
19
|
+
|
|
20
|
+
`remerge` — merge `origin/<main>` into the branch, resolve, run the RUN lines, push. GATES says what the
|
|
21
|
+
merge can break:
|
|
22
|
+
- `related`: every gate except `gates.test`, then `autonomy.relatedTests` with `{files}` replaced by
|
|
23
|
+
the files the branch changes (on the merged tree);
|
|
24
|
+
- `full`: every gate — the incoming changes add a migration or touch dependencies, test setup or
|
|
25
|
+
config (built-in patterns plus `autonomy.fullGatePaths`), or `autonomy.relatedTests` is not set.
|
|
26
|
+
|
|
27
|
+
`autonomy.remergeMain: "always"` keeps the old behaviour (always `remerge`; GATES is still computed).
|
|
28
|
+
The release gate runs the full suite once per roadmap either way (WORKFLOW.md §2).
|
|
29
|
+
"""
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
import argparse
|
|
33
|
+
import fnmatch
|
|
34
|
+
import os
|
|
35
|
+
import shlex
|
|
36
|
+
import subprocess
|
|
37
|
+
import sys
|
|
38
|
+
|
|
39
|
+
sys.dont_write_bytecode = True # no __pycache__ inside the consumer's .claude/skills
|
|
40
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
41
|
+
from wt_config import load_config # noqa: E402
|
|
42
|
+
|
|
43
|
+
DEPENDENCY_FILES = {
|
|
44
|
+
"package.json", "package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "pnpm-workspace.yaml",
|
|
45
|
+
"yarn.lock", "bun.lock", "bun.lockb", ".npmrc", ".nvmrc", ".node-version",
|
|
46
|
+
"requirements.txt", "pyproject.toml", "poetry.lock", "uv.lock", "Pipfile", "Pipfile.lock",
|
|
47
|
+
"go.mod", "go.sum", "Cargo.toml", "Cargo.lock", "Gemfile", "Gemfile.lock",
|
|
48
|
+
"composer.json", "composer.lock", "Directory.Packages.props", "packages.lock.json",
|
|
49
|
+
}
|
|
50
|
+
FULL_GATE_PATTERNS = [
|
|
51
|
+
"vitest.config.*", "vitest.setup.*", "vitest.workspace.*", "jest.config.*", "jest.setup.*",
|
|
52
|
+
"playwright.config.*", "tsconfig*.json", "eslint.config.*", ".eslintrc*", "biome.json*",
|
|
53
|
+
"babel.config.*", ".babelrc*", "lefthook.yml", "lefthook.yaml", ".husky/*", ".github/workflows/*",
|
|
54
|
+
"test/setup*", "tests/setup*", "**/test-setup.*", "**/setupTests.*",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def git(*args: str) -> str:
|
|
59
|
+
return subprocess.run(["git", *args], check=True, capture_output=True, text=True).stdout
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def changed(rev_a: str, rev_b: str) -> list[str]:
|
|
63
|
+
return [f for f in git("diff", "--name-only", "--no-renames", rev_a, rev_b).splitlines() if f]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def matches(path: str, patterns: list[str]) -> bool:
|
|
67
|
+
name = os.path.basename(path)
|
|
68
|
+
return any(fnmatch.fnmatch(path, p) or fnmatch.fnmatch(name, p) for p in patterns)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def listing(files: list[str], limit: int = 8) -> str:
|
|
72
|
+
if not files:
|
|
73
|
+
return "none"
|
|
74
|
+
more = f" (+{len(files) - limit} more)" if len(files) > limit else ""
|
|
75
|
+
return ", ".join(files[:limit]) + more
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def main() -> None:
|
|
79
|
+
parser = argparse.ArgumentParser(add_help=True, description=__doc__.split("\n\n")[0])
|
|
80
|
+
parser.add_argument("--base", help="ref of the main branch to compare with (default: origin/<main>)")
|
|
81
|
+
parser.add_argument("--no-fetch", action="store_true")
|
|
82
|
+
opts = parser.parse_args()
|
|
83
|
+
|
|
84
|
+
config = load_config()
|
|
85
|
+
main_ref = config["mainBranch"]
|
|
86
|
+
autonomy = config.get("autonomy") or {}
|
|
87
|
+
base = opts.base or f"origin/{main_ref}"
|
|
88
|
+
if not opts.no_fetch and not opts.base:
|
|
89
|
+
subprocess.run(["git", "fetch", "-q", "origin", main_ref], check=False)
|
|
90
|
+
|
|
91
|
+
head = git("rev-parse", "HEAD").strip()
|
|
92
|
+
base_sha = git("rev-parse", base).strip()
|
|
93
|
+
merge_base = git("merge-base", head, base_sha).strip()
|
|
94
|
+
incoming = changed(merge_base, base_sha)
|
|
95
|
+
ours = changed(merge_base, head)
|
|
96
|
+
overlap = sorted(set(incoming) & set(ours))
|
|
97
|
+
|
|
98
|
+
migrations_dir = ((config.get("migrations") or {}).get("dir") or "").rstrip("/")
|
|
99
|
+
migrations = [f for f in incoming if migrations_dir and f.startswith(migrations_dir + "/")]
|
|
100
|
+
dependencies = [f for f in incoming if os.path.basename(f) in DEPENDENCY_FILES]
|
|
101
|
+
setup = [f for f in incoming if matches(f, FULL_GATE_PATTERNS + list(autonomy.get("fullGatePaths") or []))]
|
|
102
|
+
|
|
103
|
+
policy = autonomy.get("remergeMain") or "when-needed"
|
|
104
|
+
moved = merge_base != base_sha
|
|
105
|
+
needed = moved and (policy == "always" or bool(overlap or migrations or dependencies))
|
|
106
|
+
related_cmd = autonomy.get("relatedTests")
|
|
107
|
+
full = bool(migrations or dependencies or setup) or not related_cmd
|
|
108
|
+
|
|
109
|
+
print(f"VERDICT {'remerge' if needed else 'merge-as-is'}")
|
|
110
|
+
print(f"GATES {'none' if not needed else ('full' if full else 'related')}")
|
|
111
|
+
if not moved:
|
|
112
|
+
print(f"incoming: none — {base} ({base_sha[:8]}) is already in the branch")
|
|
113
|
+
else:
|
|
114
|
+
count = int(git("rev-list", "--count", f"{merge_base}..{base_sha}").strip())
|
|
115
|
+
print(f"incoming: {len(incoming)} files in {count} commits since {merge_base[:8]} ({base} {base_sha[:8]})")
|
|
116
|
+
print(f"overlap: {listing(overlap)}")
|
|
117
|
+
print(f"migrations: {listing(migrations)}")
|
|
118
|
+
print(f"dependencies: {listing(dependencies)}")
|
|
119
|
+
print(f"test setup/config: {listing(setup)}")
|
|
120
|
+
print(f"policy: autonomy.remergeMain={policy}; relatedTests={'set' if related_cmd else 'not set'}")
|
|
121
|
+
if not needed:
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
gates = config.get("gates") or {}
|
|
125
|
+
if full:
|
|
126
|
+
for name, cmd in gates.items():
|
|
127
|
+
if cmd:
|
|
128
|
+
print(f"RUN {cmd}")
|
|
129
|
+
return
|
|
130
|
+
for name, cmd in gates.items():
|
|
131
|
+
if cmd and name != "test":
|
|
132
|
+
print(f"RUN {cmd}")
|
|
133
|
+
existing = set(git("ls-tree", "-r", "--name-only", head).splitlines())
|
|
134
|
+
files = [f for f in ours if f in existing and not f.startswith("context/")]
|
|
135
|
+
if files:
|
|
136
|
+
print(f"RUN {related_cmd.replace('{files}', ' '.join(shlex.quote(f) for f in files))}")
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
if __name__ == "__main__":
|
|
140
|
+
main()
|