Skip to content

feat(pull): pin a workspace to a team ref with --team-ref - #1207

Merged
jeff-r2026 merged 13 commits into
Tencent:mainfrom
SaulMoro:feat/pull-team-ref-1183
Oct 20, 2026
Merged

jeff-r2026 merged 13 commits into
Tencent:mainfrom
SaulMoro:feat/pull-team-ref-1183

Conversation

@SaulMoro

@SaulMoro SaulMoro commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

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 is repo.ref in the workspace's local config, so every later pull, including the session-start and git hooks, follows it. Passing the default branch unpins.

pull [--team-ref <ref>]
  teamRefBlocker(project, user)          # scope/kind refusals, before anything is written
  refreshTeamRepo
    transitionTeamRepo                   # src/team-ref.ts
      no ref, attached clone  → pullRepo                         (unchanged)
      ref = default branch    → checkout <default>, pullRepo     (unpin)
      ref = branch/tag/commit → fetch, resolveTeamRef, checkout --detach <commit>
      dirty tracked files     → refuse, clone untouched
      leaving submodules      → git submodule deinit (no --force) before the checkout;
                                a refusal, or a directory left non-empty, refuses the switch
    save or drop repo.ref
  deliver at the pinned commit
    removedTeamResources(recorded revs → pinned commit)   # unchanged copies the new commit lacks
  print pin line; exit 1 unless delivery completed

A detached dedicated clone is protected at every writer:

Writer Pinned behaviour
push Refuses with the pin message, exit 1
source add / source remove, manifest edits, remove previews Refuse before any write, exit 1
import, codebase writes, wiki publishing Refuse before cloning or extraction (assertTeamwikiWritable), exit 1
pullRepo, push branches, reset helpers assertAttachedTeamRepo guard (a path outside git, such as an HTTP team copy, is left alone)

teamai status prints the pin line. Docs: docs/guide/distribution.md and its zh-CN page, CHANGELOG, and the regenerated commands.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.

    $ teamai pull --team-ref feature/review-skill
    ✔ [workspace] Team repo: team ref "feature/review-skill"
    ✔ [workspace] Synced 2 skills (2 new, 0 updated)
        new: base, review-checklist
    ℹ Pinned to team ref "feature/review-skill" at 07fe5de. Run teamai pull --team-ref main to follow the default branch again.
    $ claude -p "<list the project skills>"
    base
    review-checklist
    teamai
    $ teamai pull --team-ref main
    ✔ [workspace] Synced 1 skills (all updated)
    $ ls .claude/skills
    base
    teamai
    

    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):

    $ teamai pull --team-ref trial
    ℹ Pinned to team ref "trial" at 0cfdfbf. Run teamai pull --team-ref main to follow the default branch again.
    $ teamai workflow start check --driver local --tools default=claude
    record steps[0].agent.team = {"revision":"0cfdfbf1273d285b89e78bcff8f133b57663be30","localChanges":false}
    $ teamai pull --team-ref main
    $ teamai workflow start check --driver local --tools default=claude
    record steps[0].agent.team = {"revision":"c949b68485f4688ba17c5662406f4e85c4117f72","localChanges":false}
    

    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 trial refuses 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's agent.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.
    • Submodule skills across a switch: a submodule the new revision lacks is not delivered again, also on 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 .git file, or a directory that cannot be emptied.
    • src/__tests__/team-ref.test.ts: ref resolution, transitions, and removal naming parity with the handlers.
    • Full unit suite: 472 files, 11,241 passed, 21 skipped.
    • The existing e2e files for pull, push, source, init, worktrees, git hooks, import and codebase: 50 files, 515 passed.
    • npm run build, npx tsc --noEmit and npm run lint pass.
  • Not covered here: providers gitlab/github and 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.ref in 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:

  • Clearing a leaving submodule follows git submodule deinit, which removes files the submodule's own ignore rules mark as ignored.
  • A plain fast-forward pull on the default branch that drops a submodule still leaves its worktree behind, as it does today.
  • Unpinning an already-attached clone still goes through the existing pullRepo reset recovery, which can drop an unpushed env edit that conflicts upstream, as any plain pull does today.
  • A pinned pull fetches with --prune before it resolves the 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
Describe pinning, unpinning, what a pin refuses, and that an older CLI
drops repo.ref when it saves the local config.
@jeff-r2026 jeff-r2026 self-assigned this Oct 19, 2026
@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Prevent removed submodule skills from returning after unpinning — src/team-ref.ts:104: Pin a branch containing an initialized skills/sub submodule, unpin to main without that submodule, then run pull --force. Checkout leaves the populated submodule directory behind, and refresh does not deinitialize it. Because handlers scan the working tree, the forced pull redeploys sub even though the selected revision lacks it; revision-removal cleanup no longer applies after the unpin record is saved. Safely exclude or clean up removed submodule worktrees before delivery.

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.
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Fixed the submodule P1. Before a revision switch, every submodule the new revision no longer has goes through git submodule deinit (without --force), so a clean worktree is cleared and a forced pull no longer delivers it again. If git refuses (edits, untracked files, an unpushed commit, a nested or embedded repository), or the directory is still not empty afterwards, the switch is refused and the clone is left as it was. Covered in pull-team-ref-1183.test.ts, including your exact sequence (318de5e).

@github-actions

Copy link
Copy Markdown

No new findings in the specified diff.

  • Resolved: The earlier removed-submodule finding is addressed by deinitializing leaving submodules before checkout, refusing switches when cleanup fails, and adding regression coverage for pull --force.
  • Testing evidence is sufficient: The PR description documents build and representative real-CLI verification. Deferred provider/agent coverage is acceptable.

Only the diff was read; no PR code was run, built, or installed.

@jeff-r2026
jeff-r2026 merged commit 3127b96 into Tencent:main Oct 20, 2026
18 of 22 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] Pin a workspace to a team ref with teamai pull --team-ref

2 participants