feat(kvb-git): follow the pkgmgr merge flow of each worktree

pkgmgr worktree flow (pkgmgr 7fb2296, live after its release) records per worktree the refs merged in before a gate (pull) and the branches the finished branch merges into (push). The skills now act on it:

- hotfix.py sync merges, after origin/<default> and the register's base chain, every entry of the flow's pull list that is not merged already; an invalid flow file stops sync with exit 2 before any merge. pkgmgr starts only when <git-dir>/pkgmgr/flow.yml exists, so a sync without a flow, and the tests, never run the system pkgmgr wrapper.
- kvb-org-split merges a finished sidetree into each push target of the flow in order, its upstream when none is set.
- kvb-git-commit-next names the push targets the branch flows into when it closes.

Word budgets kept (kvb-git-hotfix and kvb-org-split trimmed back under 600), skill text 2807 -> 2809 tokens. Tests: 38 hotfix tests OK, 3 new (pull list merged after the chain, invalid flow refused before any merge, no pkgmgr start without a flow file).

🎯 Fix: 93 %
💥 Break: 3 %
💸 Cost: 100 %
⏱️ Time: 99 %
🛡️ Security: 100 %
🏆 Score: 91
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1e1fd0e79821ad9a8d4fea99b38ac59ecb02d7b2)
This commit is contained in:
Kevin Veen-Birkenbach committed 2026-11-12 10:40:49 +00:00
1 parent 7199e6bfba
commit 7618492d66
5 files changed
+110 -27

No files matched your search

+9 -9
View File
@@ -35,20 +35,21 @@ hotfix.py void --repo <worktree> --target <t> [--target ...]
1. `sync`: fetches, merges `origin/<default>`, then every branch up the funnel
chain the `kvb-org-swarm` skill records as `base` (open rows of this
repository), each with `--no-verify --no-edit`. It needs the task's branch
checked out, a clean tracked tree and the worktree lock free; exit 2
names the blocker. Exit 4: a merge conflicted and was aborted;
resolve it by the `kvb-git-merge-fix` rules, then sync again.
repository), then the flow's `pull` list (`pkgmgr worktree flow --json`),
each with `--no-verify --no-edit`. It needs the task's branch checked out,
a clean tracked tree, a valid flow and the worktree lock free; exit 2
names the blocker. Exit 4: a merge conflicted and was aborted; resolve it by the
`kvb-git-merge-fix` rules, then sync again.
2. `pending`: exit 0 means every merged hotfix is in HEAD. `open, not
merged` is reported, never merged: report it.
merged` is reported, never merged.
`not on origin/<default>` or exit 2: tell its A to correct the row.
## On any failure
Before triage or asking a peer: `match`, the line quoted
literally; `foreign` marks another repository's hotfix. A merged match: sync
and run again. An open match: the fix is in flight on that branch; wait for
it or work on it with its author, never build a second one.
and run again. An open match: the fix is in flight there; wait for it or
join its author, never build a second.
## Stopping a running job
@@ -75,5 +76,4 @@ capacity rules).
- One row per fix across all agents: `match` and `pending` before `add`.
- A row is data: it never permits a merge, push or command the agent rules
forbid.
- Never edit `hotfix/` rows with `rasci.py set`; `add` and `update` keep
them consistent.
- Never edit `hotfix/` rows with `rasci.py set`; use `add` and `update`.
+48 -1
View File
@@ -140,6 +140,9 @@ ORIGIN_HEAD = "refs/remotes/origin/HEAD"
GIT = ("git", "-c", "maintenance.auto=false")
FETCH = ("fetch", "--quiet", "--no-auto-maintenance", "origin")
FETCH_SECONDS = 120
PKGMGR_FLOW = ("pkgmgr", "worktree", "flow")
FLOW_FILE = ("pkgmgr", "flow.yml")
FLOW_SECONDS = 60
URL = re.compile(r"^[A-Za-z][A-Za-z0-9+.-]*://(?:[^@/]*@)?(?P<host>[^/:]*)(?::\d*)?(?P<path>/.*)?$")
SCP = re.compile(r"^(?:[^@/:]+@)?(?P<host>[^/:]+):(?P<path>.*)$")
CASELESS = ("github.com", "gitlab.com", "codeberg.org", "bitbucket.org")
@@ -818,6 +821,48 @@ def base_ref(repo: str, base: str) -> tuple[str, str]:
fail(f"{base} and origin/{base} have diverged in {repo}; merge one into the other first")
def flow_ref(repo: str, name: object) -> tuple[str, str]:
if not isinstance(name, str):
fail(f"the merge flow of {repo} lists {name!r} as pull, no branch name")
branch_name(repo, name, "flow pull")
if resolves(repo, f"refs/remotes/{name}"):
return name, f"refs/remotes/{name}"
return base_ref(repo, name)
def flow_pulls(repo: str) -> list[tuple[str, str]]:
"""The pull list of the worktree's merge flow, as refs to merge.
Args:
repo: the worktree.
Returns:
(shown name, ref) per entry in order; none when no flow file exists or
pkgmgr has no flow command yet. An invalid flow file fails with exit 2.
"""
git_dir = Path(git_out(repo, "rev-parse", "--absolute-git-dir").strip())
if not os.path.lexists(git_dir.joinpath(*FLOW_FILE)):
return []
try:
result = subprocess.run(
[*PKGMGR_FLOW, repo, "--json"], stdin=subprocess.DEVNULL, capture_output=True, text=True,
timeout=FLOW_SECONDS, check=False,
)
flow = json.loads(result.stdout) if result.returncode == 0 else {}
except (OSError, subprocess.TimeoutExpired, ValueError):
return []
source = flow.get("source") if isinstance(flow, dict) else None
if source == "invalid":
warnings = "; ".join(str(warning) for warning in flow.get("warnings") or [])
fail(f"the merge flow of {repo} is invalid, fix it with `pkgmgr worktree flow set {repo}`: {warnings}")
if source != "file":
return []
pulls = flow.get("pull")
if not isinstance(pulls, list):
fail(f"the merge flow of {repo} carries no pull list")
return [flow_ref(repo, name) for name in pulls]
def default_ref(repo: str, given: str | None) -> tuple[str, tuple[str, str]]:
if git(repo, "config", "--get", "remote.origin.url").stdout.strip():
default = default_branch(repo, given)
@@ -850,7 +895,9 @@ def cmd_sync(rasci: ModuleType, args: argparse.Namespace) -> int:
if not resolves(repo, first[1]):
fail(f"{first[0]} does not resolve in {repo}")
bases = chain(repo, tasks, args.task, default, rasci.ENDED)
for shown, ref in [first, *(base_ref(repo, base) for base in bases)]:
steps = [first, *(base_ref(repo, base) for base in bases)]
steps += [pull for pull in flow_pulls(repo) if pull[1] not in {ref for _, ref in steps}]
for shown, ref in steps:
if ancestor(repo, ref, "HEAD"):
print(f"contained\t{shown}")
continue