Repository navigation
feat(pull): pin a workspace to a team ref with --team-ref - #1207
Conversation
A team trying a branch, tag or commit of its team repo had to clone it by hand or move the whole team. teamai pull --team-ref <ref> pins one workspace: the ref is saved as repo.ref in its local config, the clone is checked out detached at the resolved commit, and every later pull, hooks included, follows it. A branch pin follows its tip, a tag or commit pin stays put, and the default branch unpins. Switching revisions removes the unchanged copies the new commit lacks, across every checkout of the workspace. The ref is resolved without parsing git output, and only a ref whose commit holds teamai.yaml is accepted. A clone with uncommitted tracked changes is not switched. Scope and kind blockers refuse before anything is written. A pinned pull exits 1 unless delivery completes; an unpinned pull keeps its exit status. Every writer of the dedicated clone now checks for a detached HEAD: push refuses with the pin message, and source edits, manifest edits, previews, imports and wiki writes refuse before writing. Publishing helpers rethrow the refusal instead of reporting success, so the unit test that expected a null result on a detached clone now expects the rejection. teamai status shows the pin. Closes Tencent#1183
Describe pinning, unpinning, what a pin refuses, and that an older CLI drops repo.ref when it saves the local config.
Testing evidence is sufficient: the description includes build and representative real-CLI verification records. Deferred provider/agent coverage is acceptable. No PR code was run. |
…ision A workflow step in a pinned workspace must record the commit the pin delivered as agent.team.revision, follow the branch tip after a pull, and the default branch again after an unpin. Each complete pull writes a fresh checkout record, so no stale push base hides the revision.
Checkout leaves the worktree of a submodule the target commit drops, and handlers scan the working tree, so a later pull, --force included, delivered that skill again after the revision that removed it. A pin, re-pin, unpin or recovery now removes that worktree after the checkout, and refuses the switch first when it holds local changes, so nothing a member changed there is lost.
… written The hook pass and the co-author pass catch a failed write per tool and carry on, so a pinned pull exited 0 although the pinned commit's hooks or co-author policy never reached the tool. Both now report those writes to the pull, which counts them against the pinned outcome only. They stay out of the startup errors, so an unpinned pull, a git hook's failure record included, behaves as before.
…ctly The transition error is thrown only when a detached clone with no pin fails to reattach, so DetachedRecoveryError says what it marks, and the class alone carries that fact while .name stays free for the fetch timeout. HEAD is read with rev-parse -q --verify, so only an unborn branch means no previous commit and any other git failure propagates. The ref and commit probes share one helper.
Only source add and remove edit the team clone, so they check for a detached clone themselves before taking the lock, and withSourceLock is back to its two parameters. The git repository pre-check is gone: the guard already skips a path outside git, and a missing clone fails earlier when the team config is loaded.
When the default branch replaces a pinned branch's submodule with tracked files at the same path, unpinning removed those files after the pull wrote them, so the skill was not delivered and the clone looked edited. Only remove the worktree of a submodule whose path the new revision no longer tracks.
… work Removing a dropped submodule's worktree is safe only when nothing in it would be lost. A deinitialized path with local files, or a worktree whose git directory is embedded rather than kept in the clone's .git/modules, would lose those files or its unpushed commits. Treat such a path like an uncommitted change and refuse the switch, leaving the clone as it was.
A submodule worktree the target revision no longer has as a submodule is now checked and removed before the checkout, whether the target drops the path or tracks files there. Git refused to write a branch's files over the old worktree, so pinning such a branch failed with a raw git error, and an edited worktree there skipped the uncommitted-change refusal. An unpin whose co-author setting could not be written now says why it exits 1.
… clear Each hand-written test of whether a worktree held nothing worth keeping missed a shape: a regular file at the path, a nested repository, a .git file copied from another worktree. git submodule deinit already refuses a worktree with local modifications, untracked files, local commits or a nested repository, and absorbs an embedded git directory before it clears one. Use it, and treat its refusal as an uncommitted change. A submodule holding an unpushed commit now refuses the switch instead of being cleared.
git submodule deinit exits 0 when filesystem permissions stop it from emptying the worktree, so the switch went ahead and the leftover skill was delivered again by a forced pull. Check that the directory is empty after deinit and refuse the switch otherwise. A regular file at the path is left alone without calling deinit, since nothing is delivered from it.
|
Fixed the submodule P1. Before a revision switch, every submodule the new revision no longer has goes through |
|
No new findings in the specified diff.
Only the diff was read; no PR code was run, built, or installed. |
* feat(pull): pin a workspace to a team ref with --team-ref A team trying a branch, tag or commit of its team repo had to clone it by hand or move the whole team. teamai pull --team-ref <ref> pins one workspace: the ref is saved as repo.ref in its local config, the clone is checked out detached at the resolved commit, and every later pull, hooks included, follows it. A branch pin follows its tip, a tag or commit pin stays put, and the default branch unpins. Switching revisions removes the unchanged copies the new commit lacks, across every checkout of the workspace. The ref is resolved without parsing git output, and only a ref whose commit holds teamai.yaml is accepted. A clone with uncommitted tracked changes is not switched. Scope and kind blockers refuse before anything is written. A pinned pull exits 1 unless delivery completes; an unpinned pull keeps its exit status. Every writer of the dedicated clone now checks for a detached HEAD: push refuses with the pin message, and source edits, manifest edits, previews, imports and wiki writes refuse before writing. Publishing helpers rethrow the refusal instead of reporting success, so the unit test that expected a null result on a detached clone now expects the rejection. teamai status shows the pin. Closes Tencent#1183 * docs(pull): explain workspace team ref pins Describe pinning, unpinning, what a pin refuses, and that an older CLI drops repo.ref when it saves the local config. * test(pull): record a pinned team commit as a workflow step's team revision A workflow step in a pinned workspace must record the commit the pin delivered as agent.team.revision, follow the branch tip after a pull, and the default branch again after an unpin. Each complete pull writes a fresh checkout record, so no stale push base hides the revision. * fix(pull): remove a submodule the new team revision lacks when switching Checkout leaves the worktree of a submodule the target commit drops, and handlers scan the working tree, so a later pull, --force included, delivered that skill again after the revision that removed it. A pin, re-pin, unpin or recovery now removes that worktree after the checkout, and refuses the switch first when it holds local changes, so nothing a member changed there is lost. * fix(pull): fail a pinned pull when a hook or co-author setting is not written The hook pass and the co-author pass catch a failed write per tool and carry on, so a pinned pull exited 0 although the pinned commit's hooks or co-author policy never reached the tool. Both now report those writes to the pull, which counts them against the pinned outcome only. They stay out of the startup errors, so an unpinned pull, a git hook's failure record included, behaves as before. * refactor(pull): name the detached recovery failure and read HEAD strictly The transition error is thrown only when a detached clone with no pin fails to reattach, so DetachedRecoveryError says what it marks, and the class alone carries that fact while .name stays free for the fetch timeout. HEAD is read with rev-parse -q --verify, so only an unborn branch means no previous commit and any other git failure propagates. The ref and commit probes share one helper. * refactor(source): check the team clone before the source lock Only source add and remove edit the team clone, so they check for a detached clone themselves before taking the lock, and withSourceLock is back to its two parameters. The git repository pre-check is gone: the guard already skips a path outside git, and a missing clone fails earlier when the team config is loaded. * fix(pull): keep a path the new team revision tracks as files When the default branch replaces a pinned branch's submodule with tracked files at the same path, unpinning removed those files after the pull wrote them, so the skill was not delivered and the clone looked edited. Only remove the worktree of a submodule whose path the new revision no longer tracks. * fix(pull): refuse to remove a dropped submodule path that holds local work Removing a dropped submodule's worktree is safe only when nothing in it would be lost. A deinitialized path with local files, or a worktree whose git directory is embedded rather than kept in the clone's .git/modules, would lose those files or its unpushed commits. Treat such a path like an uncommitted change and refuse the switch, leaving the clone as it was. * fix(pull): clear a leaving submodule before switching the team revision A submodule worktree the target revision no longer has as a submodule is now checked and removed before the checkout, whether the target drops the path or tracks files there. Git refused to write a branch's files over the old worktree, so pinning such a branch failed with a raw git error, and an edited worktree there skipped the uncommitted-change refusal. An unpin whose co-author setting could not be written now says why it exits 1. * fix(pull): let git decide which leaving submodule worktree is safe to clear Each hand-written test of whether a worktree held nothing worth keeping missed a shape: a regular file at the path, a nested repository, a .git file copied from another worktree. git submodule deinit already refuses a worktree with local modifications, untracked files, local commits or a nested repository, and absorbs an embedded git directory before it clears one. Use it, and treat its refusal as an uncommitted change. A submodule holding an unpushed commit now refuses the switch instead of being cleared. * fix(pull): refuse a switch when a leaving submodule could not be emptied git submodule deinit exits 0 when filesystem permissions stop it from emptying the worktree, so the switch went ahead and the leftover skill was delivered again by a forced pull. Check that the directory is empty after deinit and refuse the switch otherwise. A regular file at the path is left alone without calling deinit, since nothing is delivered from it.
Closes #1183.
Summary
teamai pull --team-ref <ref>pins one workspace (init --scope workspace, standalone git team repo) to a team branch, tag or commit. The pin isrepo.refin the workspace's local config, so every later pull, including the session-start and git hooks, follows it. Passing the default branch unpins.A detached dedicated clone is protected at every writer:
pushsource add/source remove, manifest edits,removepreviewsimport,codebasewrites, wiki publishingassertTeamwikiWritable), exit 1pullRepo, push branches, reset helpersassertAttachedTeamRepoguard (a path outside git, such as an HTTP team copy, is left alone)teamai statusprints the pin line. Docs:docs/guide/distribution.mdand its zh-CN page, CHANGELOG, and the regeneratedcommands.md.Evidence
Before:
teamai pull --team-ref feature/review-skill→error: unknown option '--team-ref'.After: real CLI build plus a real Claude Code session in a temporary HOME.
A workflow step in the pinned workspace records the pinned commit, and after unpinning the default branch's (criterion 9; the agent CLI is a stub, the teamai CLI and workflow engine are real):
A third real-CLI run pins a workspace and a linked worktree, then unpins. The flat and namespaced branch-only copies are removed from both checkouts, and
pull --dry-run --team-ref trialrefuses with all 141 HOME and checkout file hashes unchanged.Tests:
src/__tests__/e2e/pull-team-ref-1183.test.ts: 80 passed. It covers acceptance criteria 1 to 12, including the session-start hook path for Claude Code and Codex and a workflow step'sagent.team.revision. It also covers the regressions: a dirty clone refusing a switch, a failed submodule update, localized git errors, an offline unpinned pull keeping exit 0, a refused import leaving the clone clean, imports into a non-git team path behaving as before, and hook or co-author write failures failing only a pinned pull.pull --force; a path the new revision tracks as files is delivered from those files; and the switch is refused, with the clone unchanged, over edits, untracked files, an unpushed commit, an embedded git directory, a nested repository, a copied.gitfile, or a directory that cannot be emptied.src/__tests__/team-ref.test.ts: ref resolution, transitions, and removal naming parity with the handlers.npm run build,npx tsc --noEmitandnpm run lintpass.Not covered here: providers
gitlab/githuband agents other than Claude Code and Codex are left to CI.Merge Danger
Door: two-way
The new flag is opt-in. An unpinned workspace keeps today's refresh path and exit codes, including exit 0 when the remote is unreachable. Reverting leaves
repo.refin pinned workspaces' local configs. An older CLI ignores the field and drops it on the next config save (noted in the CHANGELOG).Blast Radius: pull
Every pull now goes through
transitionTeamRepo, and every writer of the dedicated team clone checks for a detached HEAD. Known limits, each a follow-up rather than part of this change:git submodule deinit, which removes files the submodule's own ignore rules mark as ignored.pullReporeset recovery, which can drop an unpushed env edit that conflicts upstream, as any plain pull does today.--prunebefore it resolves the ref.