Every worktree can carry a deterministic merge flow in <git-dir>/pkgmgr/flow.yml (never committed, gone with the worktree): pull lists the refs merged into the branch, in order, before a gate, deploy or merge; push lists the branches the finished branch is merged into, in order, each then pushed by the operator.
- pkgmgr worktree flow [PATH] [--json] shows it; flow set (--pull REF.. | --no-pull) (--push BRANCH.. | --no-push) replaces both lists atomically (0600 temp file, os.replace, pkgmgr/ of mode 0700); flow clear removes it. JSON: worktree, git_dir, branch, flow_branch, pull, push, source (file, none, invalid), warnings.
- pkgmgr worktree up gains repeatable --pull/--push; without them pull is the base and push its local branch (origin/main gives main).
- pkgmgr branch tree carries "flow": {pull, push, source} or null on every item with a worktree, read from the linked worktree's metadata dir without running git inside the worktree; the Agent Orchestrator shows it.
The file and the arguments may come from an agent: every entry must equal its git check-ref-format --branch output (scan mode, cwd /) and must not start with -; the reader opens pkgmgr/ and flow.yml without following links, non-blocking, refuses anything but a regular file, caps at 64 KiB, uses yaml.safe_load, rejects unknown keys, wrong types and bool versions, and never raises into callers: a bad file reads as source invalid with empty lists and a warning.
Tests: 30 new (unit and integration on real repositories), unit suite 500 OK, integration 254 with the two known sandbox signing errors of test_publish_integration only.
🎯 Fix: 92 %
💥 Break: 4 %
💸 Cost: 97 %
⏱️ Time: 93 %
🛡️ Security: 100 %
🏆 Score: 98
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
SLOT_FILE = "pkgmgr-slot"
|
|
|
|
|
|
def used_slots(common_dir: str) -> set[int]:
|
|
base = os.path.join(common_dir, "worktrees")
|
|
slots: set[int] = set()
|
|
for entry in os.listdir(base) if os.path.isdir(base) else []:
|
|
try:
|
|
with open(os.path.join(base, entry, SLOT_FILE), encoding="utf-8") as fh:
|
|
slots.add(int(fh.read().strip()))
|
|
except (OSError, ValueError):
|
|
continue
|
|
return slots
|
|
|
|
|
|
def next_slot(used: set[int]) -> int:
|
|
slot = 1
|
|
while slot in used:
|
|
slot += 1
|
|
return slot
|
|
|
|
|
|
def new_worktree_meta(path: str) -> str:
|
|
"""
|
|
Args:
|
|
path: a worktree this process just added, whose `.git` file names
|
|
its metadata.
|
|
|
|
Returns:
|
|
The worktree's own git directory, `<common>/worktrees/<id>`.
|
|
"""
|
|
with open(os.path.join(path, ".git"), encoding="utf-8") as fh:
|
|
return os.path.normpath(
|
|
os.path.join(path, fh.read().strip().removeprefix("gitdir: "))
|
|
)
|
|
|
|
|
|
def write_slot(path: str, slot: int) -> None:
|
|
"""
|
|
Record a slot in the metadata of a worktree this process just added.
|
|
|
|
Args:
|
|
path: the new worktree, whose `.git` file names its metadata.
|
|
slot: the slot to record.
|
|
"""
|
|
with open(
|
|
os.path.join(new_worktree_meta(path), SLOT_FILE), "w", encoding="utf-8"
|
|
) as fh:
|
|
fh.write(f"{slot}\n")
|