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 @@ -3,6 +3,7 @@
## Unreleased

- 新增 `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` 中途失败回滚时留下本次新建分支的问题:之前用另一个基线重试会静默复用旧分支;现在回滚会删除本次新建的分支,原本就有的分支保持不动。

## 0.7.18 - 2026-11-14
Expand Down
6 changes: 3 additions & 3 deletions docs/designs/line-aware-next-and-push-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ JSON `next` 继续使用已经跑完 `doctor` 的那只 45 秒预算。增量 Gi
`next` 的 `push_note`、工作区 overlay、开发线 overlay、控制面技能资产使用下面三段,字节级相同。`allow_push` 为 true 时也返回这段,不再返回空串。

```text
Dyro 默认不执行 push。只有命令显式带 `--push` 且 `policy.allow_push = true` 时,Dyro 才会在本地合并成功之后逐仓执行 `git push origin <分支>`;多仓 push 不是原子操作。
Dyro 默认不执行 push。只有 `policy.allow_push = true` 时才推送:`dyro line push` 推开发线分支;显式带 `--push` 的命令在本地合并成功后逐仓执行 `git push origin <分支>`。多仓 push 不是原子操作。
开发线的期望上游是 `origin/<line.branch>`。本地还没有这条远端分支时,doctor 给出 WARN,工作区仍可打开;这不表示可以推送。
普通 `git push` 仍然能改远端,但不会写入 Dyro 的远端锚点,也不算通过门禁。
```
Expand Down Expand Up @@ -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`。发布姿势仍是:人在终端执行 `git push -u origin <branch>`,或在 `policy.allow_push = true` 时对已有的 `line merge` / `line sync` / `task merge` 显式加上 `--push`。`spawn` 不发布。终端里的普通 `git push` 不写 `[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`。

## 4. 延期

Expand All @@ -248,7 +248,7 @@ doctor 的 WARN 原文保持 `WARN <kind>:<id>/<repo>: missing origin/<branch>`

1. **旧 overlay 用 WARN,不自动刷新。** doctor 只报告与当前模板的字节差异,并指向 `dyro host seed --force`。自动覆盖会改掉操作者改过的文件,也会把写操作放进 doctor。
2. **`next` 不做跨分支的提交图遍历。** ahead/behind 只用 doctor 已经挂到 `ReadBudget` 上的 ref。SHA 相同则写 0。不相同则最多 4 次本地 `rev-list`,否则 `null`。兄弟比较和父线提交差不进入 `next`。
3. **不新增 `line publish`。** 见第 3 节末。`spawn` 不代跑首次发布。
3. **发布走 `dyro line push`,不新增 `line publish`。** 见第 3 节末。`spawn` 不代跑首次发布。
4. **有锚点表的清单升到 schema_version 4;空表不升。** 防脱落靠两件事:字段进入 `Line` 并由 `_write_line` 写出;旧客户端因版本 4 无法解析而无法走旧的整文件重写。控制面 JSON 的 `schema_version` 保持 1。

第二轮的四项由第 2 节和第 3 节回答。这里不重开上面四条。
Expand Down
34 changes: 34 additions & 0 deletions src/dyro/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
merge_line,
merge_line_from,
merge_line_into_base,
push_line,
observation_timeout_row,
recover_line_merge,
spawn_line,
Expand Down Expand Up @@ -3142,6 +3143,25 @@ def cmd_line_add_repo(args: argparse.Namespace) -> None:
)


def cmd_line_push(args: argparse.Namespace) -> None:
config = _config(args)
_require_yes(args, "推送开发线分支")
line, pushed, skipped = push_line(config, args.line, dry_run=args.dry_run)
if args.dry_run:
linked = ", ".join(
repo_id
for repo_id in line.repositories
if line.storage_for(repo_id) == "linked-worktree"
)
print(f"DRY RUN: 将推送 {line.kind} {line.id} 分支 {line.branch}:{linked}")
else:
for repo_id in pushed:
sha = line.remote_anchors[repo_id][:12]
print(f"已推送 {line.kind} {line.id} 仓库 {repo_id}:{sha}({line.branch})")
if skipped:
print(f"跳过 anchor-reference 仓库:{', '.join(skipped)}")


def cmd_line_merge(args: argparse.Namespace) -> None:
config = _config(args)
if getattr(args, "recover", None) is not None:
Expand Down Expand Up @@ -5438,6 +5458,20 @@ def build_parser() -> argparse.ArgumentParser:
)
line_add_repo.add_argument("--yes", action="store_true")
line_add_repo.set_defaults(func=cmd_line_add_repo)
line_push = line_sub.add_parser(
"push",
help="把开发线分支推到 origin 并设置上游(只推已提交内容;需 policy.allow_push)",
)
line_push.add_argument("line", help="开发线 ID")
line_push.add_argument(
"--dry-run",
dest="dry_run",
action="store_true",
default=argparse.SUPPRESS,
help="只预检推送,不推送、不改清单(兼容全局 --dry-run)",
)
line_push.add_argument("--yes", action="store_true")
line_push.set_defaults(func=cmd_line_push)
line_merge = line_sub.add_parser(
"merge",
help="子线合入父线(--into)、跨线合入(--from)或 --recover 对账",
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。只有命令显式带 `--push` 且 `policy.allow_push = true` 时,Dyro 才会在本地合并成功之后逐仓执行 `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` 的命令在本地合并成功后逐仓执行 `git push origin <分支>`。多仓 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。只有命令显式带 `--push` 且 `policy.allow_push = true` 时,Dyro 才会在本地合并成功之后逐仓执行 `git push origin <分支>`;多仓 push 不是原子操作。
Dyro 默认不执行 push。只有 `policy.allow_push = true` 时才推送:`dyro line push` 推开发线分支;显式带 `--push` 的命令在本地合并成功后逐仓执行 `git push origin <分支>`。多仓 push 不是原子操作。
开发线的期望上游是 `origin/<line.branch>`。本地还没有这条远端分支时,doctor 给出 WARN,工作区仍可打开;这不表示可以推送。
普通 `git push` 仍然能改远端,但不会写入 Dyro 的远端锚点,也不算通过门禁。

Expand Down
97 changes: 93 additions & 4 deletions src/dyro/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,9 +945,15 @@ def _require_push_allowed(config: Config, *, push: bool) -> None:


def _require_line_worktrees(
config: Config, line: Line, *, clean: bool, label: str
config: Config,
line: Line,
*,
clean: bool,
label: str,
repositories: Iterable[str] | None = None,
) -> None:
for repo_id in line.repositories:
selected = line.repositories if repositories is None else tuple(repositories)
for repo_id in selected:
target = line_repository_path(config, line, repo_id)
inside = git(target, "rev-parse", "--is-inside-work-tree")
if inside.code != 0 or inside.stdout.strip() != "true":
Expand Down Expand Up @@ -1255,15 +1261,98 @@ def _merge_line_repositories_locked(
)


def record_remote_anchor(config: Config, line: Line, repo_id: str, path: Path) -> Line:
def record_remote_anchor(
config: Config, line: Line, repo_id: str, path: Path, *, sha: str | None = None
) -> Line:
if line.storage_for(repo_id) != "linked-worktree":
return line
head = require_ok(git_read(path, "rev-parse", "HEAD"), "读取已推送 HEAD").stdout.strip()
head = sha or require_ok(git_read(path, "rev-parse", "HEAD"), "读取已推送 HEAD").stdout.strip()
updated = replace(line, remote_anchors={**line.remote_anchors, repo_id: head})
_write_line(config, updated)
return updated


def push_line(
config: Config, line_id: str, *, dry_run: bool = False
) -> tuple[Line, list[str], list[str]]:
"""Push one line branch to origin and record linked-worktree anchors.

Holds L1 then L2 like ``line merge --push``. Every linked worktree is
preflighted before any push. Repositories are not atomic: a later failure
keeps anchors already recorded. Anchor-reference repositories are skipped.
Only committed history is pushed.
"""
_require_push_allowed(config, push=True)
with exclusive_lock(
merge_lock_path(config, line_id),
timeout_seconds=MERGE_LOCK_TIMEOUT_SECONDS,
):
line = get_line(config, line_id)
require_no_unfinished_op(config, line.id)
linked = [r for r in line.repositories if line.storage_for(r) == "linked-worktree"]
skipped = [r for r in line.repositories if r not in linked]
if not linked:
raise DyroError(f"开发线 {line.id} 没有可推送的 linked-worktree 仓库")
with anchor_locks(config, linked):
_require_line_worktrees(
config, line, clean=False, label="开发线", repositories=linked
)
for repo_id in linked:
path = line_repository_path(config, line, repo_id)
if _git_in_progress(path):
raise DyroError(f"{repo_id} 有进行中的 Git 操作,拒绝推送")
require_ok(
git(path, "push", "--dry-run", "origin", f"refs/heads/{line.branch}:refs/heads/{line.branch}"),
f"预检推送 {repo_id}",
)
if dry_run:
return line, [], skipped
pushed: list[str] = []
for repo_id in linked:
path = line_repository_path(config, line, repo_id)
branch_ref = f"refs/heads/{line.branch}"
tip = require_ok(
git_read(path, "rev-parse", "--verify", branch_ref), f"读取 {repo_id} 分支"
).stdout.strip()
# Explicit same-name refspec: push.default=upstream must not redirect
# the destination. Never --force, --force-with-lease, or a "+" refspec.
result = git(path, "push", "-u", "origin", f"{branch_ref}:{branch_ref}")
if result.code != 0:
_line_ledger(
config,
line.id,
"line_push_failed",
repository=repo_id,
branch=line.branch,
pushed_repositories=pushed,
error=result.stdout.strip(),
)
raise DyroError(
f"推送 {repo_id} 失败;已推送仓库:{', '.join(pushed) or '-'}"
f"\n{result.stdout.strip()}"
)
pushed.append(repo_id)
try:
# Anchor the branch tip Git pushed, not HEAD (the worktree may
# have moved) and not the tracking ref (a narrow fetch refspec
# leaves it stale). A tip that moved during push is ambiguous.
after = require_ok(
git_read(path, "rev-parse", "--verify", branch_ref), f"读取 {repo_id} 分支"
).stdout.strip()
if after != tip:
raise DyroError(f"推送期间 {line.branch} 从 {tip[:12]} 移动到 {after[:12]}")
line = record_remote_anchor(config, line, repo_id, path, sha=tip)
_line_ledger(
config, line.id, "line_push",
repository=repo_id, branch=line.branch, head=tip,
)
except Exception as exc:
raise DyroError(
f"推送 {repo_id} 已发生,但远端锚点或 ledger 未记录完整:{exc};"
f"已推送仓库:{', '.join(pushed)}"
) from exc
return line, pushed, skipped

def merge_line(
config: Config,
child_id: str,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_line_next_contract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""First-wave line observations and push contract regression coverage."""
from dataclasses import replace
from pathlib import Path
from unittest.mock import patch

from dyro.config import load, Policy, push_policy_fields, PUSH_DISABLED_NOTE
Expand Down Expand Up @@ -27,6 +28,8 @@ def test_contract_exact_and_enabled(self):
self.assertEqual(fields['push_contract_version'], 1)
for body in (render_workspace_overlay(), render_line_persona(line_id='core', branch='feat/core')):
self.assertIn(PUSH_DISABLED_NOTE, body)
skill = Path(__file__).resolve().parents[1] / 'src/dyro/integrations/assets/dyro-control-plane/SKILL.md'
self.assertIn(PUSH_DISABLED_NOTE, skill.read_text(encoding='utf-8'))

def test_manifest_anchors_roundtrip_and_old_schema_rejection(self):
for parent in ('', 'parent'):
Expand Down
Loading
Loading