Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- 新增 `dyro line add-repo`:把一个已经登记的仓库加入现有开发线。已有子线保持不变;子线只能加入父线里已经有的仓库。
- 新增 `dyro line push`:把开发线分支推到 origin 并设置上游。只推已提交内容,需 `policy.allow_push`;`anchor-reference` 仓库会跳过。推送说明(`next` 的 `push_note`、工作区和开发线说明、控制面技能)同步提到这条命令;已 seed 的工作区 doctor 会报模板不一致,运行一次 `dyro host seed --force` 即可。
- 修复 `dyro line create` / `dyro line spawn` 中途失败回滚时留下本次新建分支的问题:之前用另一个基线重试会静默复用旧分支;现在回滚会删除本次新建的分支,原本就有的分支保持不动。
- 修复 `line merge` / `line sync` / `task merge` 的 `--push`:推送前钉住分支 tip,用显式 refspec `git push origin <tip>:refs/heads/<branch>` 推送,并把远端锚点记成恰好这个 SHA。此前在 `push.default=upstream` 且分支上游指向别的远端分支时,会把合并结果推到那个分支上(例如 `main`);推送后工作区被切走时,锚点也可能和实际推送的提交不一致。`--recover` 打印的手动推送命令、建线后的发布提示和推送说明也不再给出裸的 `git push origin <分支>`。

## 0.7.18 - 2026-11-14

Expand Down
10 changes: 5 additions & 5 deletions docs/designs/line-aware-next-and-push-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

推送句子今天有三套。工作区 overlay(`instructions.py:31`)禁止绕过门禁做 `git merge` / `git push`。线 overlay(`instructions.py:41-46`)要求必须跟踪 `origin/<branch>`。`PUSH_DISABLED_NOTE` 是「Dyro 不会 push;普通 `git push` 仍可用。」(`config.py:23`)。`allow_push` 为 true 时 `push_disclosure` 返回空串(`config.py:133-137`),`push_policy_fields` 不带 `push_note`(`config.py:140-143`)。

会执行 `git push origin <branch>` 的位置是线 merge/sync(`workspace.py`)和 `task merge`(`tasks.py`)。都要显式 `--push`,并且 `policy.allow_push`。本地合并成功后才逐仓 push。`--push` 前已有 `git push --dry-run`(`workspace.py:825-836`)。清单不写远端 SHA。
线 merge/sync(`workspace.py`)和 `task merge`(`tasks.py`)在显式 `--push` 且 `policy.allow_push` 时,本地合并成功后才逐仓推送。推送前把 `refs/heads/<branch>` 钉成 tip,执行 `git push origin <tip>:refs/heads/<branch>`(不用 `-u`,不用 `--force` / `--force-with-lease` / `+`)。预检是 `git push --dry-run origin refs/heads/<branch>:refs/heads/<branch>`。成功后 `[remote_anchors]` 记的是这次推送的 tip,不是事后的 HEAD。

`seed_overlay_files` 在文件已存在且未 `--force` 时跳过(`instructions.py:94-96`)。`overlay_instruction_warning` 只在工作区文件缺失时发 WARN(`instructions.py:62-67`),`doctor` 调用它(`workspace.py:1439-1443`),不比较正文。

Expand Down Expand Up @@ -191,7 +191,7 @@ JSON `next` 继续使用已经跑完 `doctor` 的那只 45 秒预算。增量 Gi
`next` 的 `push_note`、工作区 overlay、开发线 overlay、控制面技能资产使用下面三段,字节级相同。`allow_push` 为 true 时也返回这段,不再返回空串。

```text
Dyro 默认不执行 push。只有 `policy.allow_push = true` 时才推送:`dyro line push` 推开发线分支;显式带 `--push` 的命令在本地合并成功后逐仓执行 `git push origin <分支>`。多仓 push 不是原子操作。
Dyro 默认不执行 push。只有 `policy.allow_push = true` 时才推送:`dyro line push` 推开发线分支;显式带 `--push` 的命令在本地合并成功后逐仓推送该分支的 tip。多仓 push 不是原子操作。
开发线的期望上游是 `origin/<line.branch>`。本地还没有这条远端分支时,doctor 给出 WARN,工作区仍可打开;这不表示可以推送。
普通 `git push` 仍然能改远端,但不会写入 Dyro 的远端锚点,也不算通过门禁。
```
Expand Down Expand Up @@ -227,7 +227,7 @@ doctor 的 WARN 原文保持 `WARN <kind>:<id>/<repo>: missing origin/<branch>`

### push 成功后的远端 SHA

在 `workspace.py` 与 `tasks.py` 两处,每一仓 `git push` 成功后,把该仓 HEAD 的全文 SHA 写入该线的 `[remote_anchors]`。只记录 `linked-worktree`。`anchor-reference` 不写入。后一仓失败时,已成功仓的锚点保留。清单写入失败要报出来,因为 push 已经发生。
在 `workspace.py` 与 `tasks.py` 两处,每一仓按 `git push origin <tip>:refs/heads/<branch>` 推送成功后,把这次钉住并推送的 `refs/heads/<branch>` tip 写入该线的 `[remote_anchors]`,不用事后的 HEAD。只记录 `linked-worktree`。`anchor-reference` 不写入。后一仓失败时,已成功仓的锚点保留。清单写入失败要报出来,因为 push 已经发生。

持久化规则:

Expand All @@ -237,7 +237,7 @@ doctor 的 WARN 原文保持 `WARN <kind>:<id>/<repo>: missing origin/<branch>`
- 旧 Dyro 遇到版本 4 会在 `workspace.py:109-110` 拒绝解析,因此旧的 `_write_line` 不会拿到 `Line`,也不会把表抹掉。代价是:第一次写下锚点之后,旧二进制不能再加载这条线。没有锚点的线保持版本 2 或 3,旧二进制仍可读写。
- 新的 `_write_line` 从字段写出该表。任何会持久化的 `Line(` 构造都必须带上读到的 `remote_anchors`。默认空映射只用于新建的线。漏带字段再写回,新二进制自己也会抹掉该表。

不新增名为 `line publish` 的命令。顶层线和子线用 `dyro line push` 发布自己的分支:先确认 `policy.allow_push`,再取与 `line merge --push`、`retire` 相同的 L1 合并锁;再按仓库 ID 升序取 L2 anchor 锁;锁内重读清单,并拒绝该线任何未完成的操作(merge、merge-into-base、retire)。只推 `linked-worktree`。全部这类仓库预检通过后(工作树存在且是 Git、当前分支就是线分支、没有进行中的 Git 操作、同一 refspec 的 `git push --dry-run` 成功),才按清单顺序执行 `git push -u origin refs/heads/<branch>:refs/heads/<branch>`(显式同名 refspec,`push.default=upstream` 也不能把目标改到别的远端分支;`-u` 同时把上游纠正为 `origin/<branch>`)。不使用 `--force`、`--force-with-lease` 或 `+refspec`,也不要求工作树干净,只推已提交内容。成功一仓就为该仓写 `[remote_anchors]`,取值是推送前后各读一次、两次一致的 `refs/heads/<branch>` tip;不用事后的 HEAD(工作树可能已切走),也不用 `refs/remotes/origin/<branch>`(窄 fetch refspec 下不会更新);推送期间分支移动则不写该仓锚点并报错;`anchor-reference` 跳过、不写锚点。跨仓不原子:后一仓失败时,已成功仓的锚点保留。锚点写入失败要报出来,因为 push 已经发生。`spawn` 不发布。终端里的普通 `git push` 不写 `[remote_anchors]`。`policy.allow_push = true` 时,`line merge` / `line sync` / `task merge` 仍可显式加 `--push`。
不新增名为 `line publish` 的命令。顶层线和子线用 `dyro line push` 发布自己的分支:先确认 `policy.allow_push`,再取与 `line merge --push`、`retire` 相同的 L1 合并锁;再按仓库 ID 升序取 L2 anchor 锁;锁内重读清单,并拒绝该线任何未完成的操作(merge、merge-into-base、retire)。只推 `linked-worktree`。全部这类仓库预检通过后(工作树存在且是 Git、当前分支就是线分支、没有进行中的 Git 操作、同一 refspec 的 `git push --dry-run` 成功),才按清单顺序执行 `git push -u origin refs/heads/<branch>:refs/heads/<branch>`(显式同名 refspec,`push.default=upstream` 也不能把目标改到别的远端分支;`-u` 同时把上游纠正为 `origin/<branch>`)。不使用 `--force`、`--force-with-lease` 或 `+refspec`,也不要求工作树干净,只推已提交内容。成功一仓就为该仓写 `[remote_anchors]`,取值是推送前后各读一次、两次一致的 `refs/heads/<branch>` tip;不用事后的 HEAD(工作树可能已切走),也不用 `refs/remotes/origin/<branch>`(窄 fetch refspec 下不会更新);推送期间分支移动则不写该仓锚点并报错;`anchor-reference` 跳过、不写锚点。跨仓不原子:后一仓失败时,已成功仓的锚点保留。锚点写入失败要报出来,因为 push 已经发生。`spawn` 不发布。终端里的普通 `git push` 不写 `[remote_anchors]`。`policy.allow_push = true` 时,`line merge` / `line sync` / `task merge` 仍可显式加 `--push`:推送前钉住 `refs/heads/<branch>` 的 tip,执行 `git push origin <tip>:refs/heads/<branch>`(不用 `-u`),并把 `[remote_anchors]` 记成这个 tip。

## 4. 延期

Expand Down Expand Up @@ -270,7 +270,7 @@ doctor 的 WARN 原文保持 `WARN <kind>:<id>/<repo>: missing origin/<branch>`
- doctor 对与模板不同的已有 `AGENTS.md` / `CLAUDE.md` 发 WARN;缺失文件仍是原来的缺失 WARN;doctor 不改文件。不带 `--force` 的 seed 保持原字节。
- 已有 overlay 超过单文件上限(`FILE_TOO_LARGE`),或这一份文件为 `UNSAFE_FILE`:一条「无法核对」WARN,doctor 继续并返回其余 findings。`AGGREGATE_BYTES_EXCEEDED` 与 `DEADLINE_EXCEEDED` 不降级成这条 WARN。截止仍由 doctor 收成 partial 返回;aggregate 在保存 findings 后重新抛出,且不会继续读清单和 Git。
- 三段口径在 `push_note` 与两套模板中逐字相同。`allow_push=true` 时 `push_note` 仍非空。
- 线 merge `--push` 成功后,`remote_anchors` 等于该仓 HEAD,清单为 schema_version 4。第二仓失败时第一仓锚点仍在。`anchor-reference` 不出现在表里。无锚点的旧清单仍是版本 2 或 3 且能加载。版本 4 能往返 `_parse_line_content` 与 `_write_line` 而不丢表。构造 `Line` 时漏掉该字段再写回,测试要失败。
- 线 merge `--push` 成功后,`remote_anchors` 等于这次推送钉住的 `refs/heads/<branch>` tip(`git push origin <tip>:refs/heads/<branch>`),清单为 schema_version 4。第二仓失败时第一仓锚点仍在。`anchor-reference` 不出现在表里。无锚点的旧清单仍是版本 2 或 3 且能加载。版本 4 能往返 `_parse_line_content` 与 `_write_line` 而不丢表。构造 `Line` 时漏掉该字段再写回,测试要失败。

## 7. 实现边界

Expand Down
4 changes: 3 additions & 1 deletion src/dyro/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3102,7 +3102,9 @@ def _create_line(args: argparse.Namespace, kind: str) -> None:
f"{'DRY RUN: ' if args.dry_run else ''}已创建 {line.kind} {line.id},分支 {line.branch},仓库基线:{bases}"
)
if not args.dry_run:
print(f"发布此线(Dyro 不会代你执行):git push -u origin {line.branch}")
ref = f"refs/heads/{line.branch}"
# Explicit refspec: a bare branch obeys push.default=upstream.
print(f"发布此线:dyro line push {line.id} --yes(需 policy.allow_push),或 git push -u origin {ref}:{ref}")


def cmd_line_create(args: argparse.Namespace) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/dyro/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
OBJECTIVES_DIR = ".dyro/objectives"

SAFE_ID = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$")
PUSH_DISABLED_NOTE = 'Dyro 默认不执行 push。只有 `policy.allow_push = true` 时才推送:`dyro line push` 推开发线分支;显式带 `--push` 的命令在本地合并成功后逐仓执行 `git push origin <分支>`。多仓 push 不是原子操作。\n开发线的期望上游是 `origin/<line.branch>`。本地还没有这条远端分支时,doctor 给出 WARN,工作区仍可打开;这不表示可以推送。\n普通 `git push` 仍然能改远端,但不会写入 Dyro 的远端锚点,也不算通过门禁。'
PUSH_DISABLED_NOTE = 'Dyro 默认不执行 push。只有 `policy.allow_push = true` 时才推送:`dyro line push` 推开发线分支;显式带 `--push` 的命令在本地合并成功后逐仓推送该分支的 tip。多仓 push 不是原子操作。\n开发线的期望上游是 `origin/<line.branch>`。本地还没有这条远端分支时,doctor 给出 WARN,工作区仍可打开;这不表示可以推送。\n普通 `git push` 仍然能改远端,但不会写入 Dyro 的远端锚点,也不算通过门禁。'


@dataclass(frozen=True)
Expand Down
2 changes: 1 addition & 1 deletion src/dyro/integrations/assets/dyro-control-plane/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Only hand off a workspace-scoped mutation when the returned command retains an e

If the user asks for 会审, 对抗, or Go/No-Go, follow the `dyro-board` protocol (human command `/dyro-review-board`) instead of inventing P0 here. A CLI summary alone is never final runtime or production acceptance.

Dyro 默认不执行 push。只有 `policy.allow_push = true` 时才推送:`dyro line push` 推开发线分支;显式带 `--push` 的命令在本地合并成功后逐仓执行 `git push origin <分支>`。多仓 push 不是原子操作。
Dyro 默认不执行 push。只有 `policy.allow_push = true` 时才推送:`dyro line push` 推开发线分支;显式带 `--push` 的命令在本地合并成功后逐仓推送该分支的 tip。多仓 push 不是原子操作。
开发线的期望上游是 `origin/<line.branch>`。本地还没有这条远端分支时,doctor 给出 WARN,工作区仍可打开;这不表示可以推送。
普通 `git push` 仍然能改远端,但不会写入 Dyro 的远端锚点,也不算通过门禁。

Expand Down
12 changes: 8 additions & 4 deletions src/dyro/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3039,7 +3039,7 @@ def _prepare_merge(
"push",
"--dry-run",
"origin",
line.branch,
f"refs/heads/{line.branch}:refs/heads/{line.branch}",
),
f"预检推送 {plan.repository}",
)
Expand Down Expand Up @@ -3161,8 +3161,11 @@ def _merge_task_repositories_locked(

pushed: list[str] = []
if push:
from .workspace import _branch_tip, record_remote_anchor

for plan in plans:
result = git(plan.target, "push", "origin", line.branch)
tip = _branch_tip(plan.target, line.branch)
result = git(plan.target, "push", "origin", f"{tip}:refs/heads/{line.branch}")
if result.code != 0:
ledger(
config,
Expand All @@ -3177,8 +3180,9 @@ def _merge_task_repositories_locked(
f"\n{result.stdout.strip()}"
)
pushed.append(plan.repository)
from .workspace import record_remote_anchor
line = record_remote_anchor(config, line, plan.repository, plan.target)
line = record_remote_anchor(
config, line, plan.repository, plan.target, sha=tip
)

for plan in plans:
result_head = require_ok(
Expand Down
50 changes: 37 additions & 13 deletions src/dyro/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ def _prepare_line_merge_plans(
"push",
"--dry-run",
"origin",
target.branch,
f"refs/heads/{target.branch}:refs/heads/{target.branch}",
),
f"预检推送 {plan.repository}",
)
Expand Down Expand Up @@ -1220,7 +1220,8 @@ def _merge_line_repositories_locked(
pushed: list[str] = []
if push:
for plan in plans:
result = git(plan.target, "push", "origin", target.branch)
tip = _branch_tip(plan.target, target.branch)
result = git(plan.target, "push", "origin", f"{tip}:refs/heads/{target.branch}")
if result.code != 0:
_line_ledger(
config,
Expand All @@ -1236,7 +1237,9 @@ def _merge_line_repositories_locked(
f"\n{result.stdout.strip()}"
)
pushed.append(plan.repository)
target = record_remote_anchor(config, target, plan.repository, plan.target)
target = record_remote_anchor(
config, target, plan.repository, plan.target, sha=tip
)

changeset_id = ""
if not dry_run:
Expand Down Expand Up @@ -1506,6 +1509,13 @@ def _head_sha(repo: Path) -> str:
return require_ok(git(repo, "rev-parse", "HEAD"), f"读取 {repo} HEAD").stdout.strip()


def _branch_tip(repo: Path, branch: str) -> str:
return require_ok(
git(repo, "rev-parse", "--verify", f"refs/heads/{branch}"),
f"读取 {branch} 分支",
).stdout.strip()


def _has_merge_head(repo: Path) -> bool:
return git(repo, "rev-parse", "--verify", "-q", "MERGE_HEAD").code == 0

Expand Down Expand Up @@ -2088,8 +2098,15 @@ def _run_journaled_line_merge(
)
if push:
for plan in plans:
branch = branches[plan.repository]
require_ok(
git(plan.target, "push", "--dry-run", "origin", branches[plan.repository]),
git(
plan.target,
"push",
"--dry-run",
"origin",
f"refs/heads/{branch}:refs/heads/{branch}",
),
f"预检推送 {plan.repository}",
)
if dry_run:
Expand Down Expand Up @@ -2144,26 +2161,32 @@ def _run_journaled_line_merge(
if push:
pushed: list[str] = []
for index, plan in enumerate(plans):
push_head = _head_sha(plan.target)
branch = branches[plan.repository]
tip = _branch_tip(plan.target, branch)
record_repo_intent(
config, op_id, plan.repository, "push",
original_head=plan.original_head, target_sha=push_head,
branch=branches[plan.repository], remote="origin",
original_head=plan.original_head, target_sha=tip,
branch=branch, remote="origin",
)
result = git(plan.target, "push", "origin", branches[plan.repository])
result = git(plan.target, "push", "origin", f"{tip}:refs/heads/{branch}")
if result.code == 0:
target = record_remote_anchor(config, target, plan.repository, plan.target)
target = record_remote_anchor(
config, target, plan.repository, plan.target, sha=tip
)
record_repo_result(
config, op_id, plan.repository, "push",
outcome="pushed" if result.code == 0 else "push_failed",
new_tip=push_head if result.code == 0 else "",
new_tip=tip if result.code == 0 else "",
error=result.stdout.strip() if result.code != 0 else "",
)
if result.code != 0:
for remaining in plans[index + 1:]:
record_repo_intent(
config, op_id, remaining.repository, "push",
original_head=remaining.original_head, target_sha=_head_sha(remaining.target),
original_head=remaining.original_head,
target_sha=_branch_tip(
remaining.target, branches[remaining.repository]
),
branch=branches[remaining.repository], remote="origin",
)
record_repo_result(
Expand Down Expand Up @@ -2659,8 +2682,9 @@ def recover_line_merge(
)
if push_step is not None:
path = shlex.quote(str(repo["snapshot"]["path"]))
branch = shlex.quote(str(push_step["intent"]["branch"]))
report.append(f" 手动:git -C {path} push origin {branch}")
ref = f"refs/heads/{push_step['intent']['branch']}"
# Explicit refspec: a bare branch obeys push.default=upstream.
report.append(f" 手动:git -C {path} push origin {shlex.quote(f'{ref}:{ref}')}")
outcomes[repo_id] = (
op["repositories"][repo_id]["outcome"] if terminal
else _reconcile_merge_repo(config, op, repo_id, report=report)
Expand Down
Loading
Loading