Repository navigation
feat(learnings): write learnings to the teamai-learnings branch - #616
Merged
Merged
Conversation
`reports-branch.ts` managed the `teamai-reports` orphan branch: cold-start creation across two git versions, stale-worktree repair, a non-blocking lock, commit, and push with fetch+rebase retry. Learnings need the same machinery on their own branch (Tencent#485), and must not share the branch, the worktree or the lock. The engine moves to `branch-worktree.ts`, parameterised by a spec of three names plus an init commit message. Reports become one instance of it and keep every exported name, so no caller changes. `reports-branch.ts` keeps what is not a side branch: `EmptyRepoError` and `withKnowledgeWorktree`. - A publish returns `PublishResult` instead of a boolean. A caller holding the only durable copy of its data must be able to tell "landed on origin" from "another writer holds the lock", "nothing to commit" and "rejected". Reports map it back to today's boolean, so their behaviour is unchanged. - A publish confirms the ref actually moved before reporting success, and separates "nothing to commit" from "nothing to deliver": an earlier attempt may have committed the content and failed to push it. A successful push updates the remote-tracking ref locally, so the check is a local rev-list. Anything unreadable counts as not landed, which costs one extra push instead of losing data. - `getWorktreeDir` and `getBusinessRoot` come out of the reports-specific helpers; `getReportsDir` is now one call to the first. - `usesReportsBranch` was a one-line forward; its eleven call sites use `usesBranchWorktree`, which says what it means now that two branches use it. - A side branch's `.gitignore` lists every worktree directory, so no worktree can nest-track another. - `ensureReportsDir` had no callers and duplicated `ensureReportsWorktree`. Refs Tencent#485
…every root Contributing no longer touches the default branch, so a member whose team protects `main` can contribute. Everything the team wrote before the switch stays readable exactly where it is: nothing is copied, deleted or migrated. **One accessor.** Eleven call sites built the learnings path by hand, from a different base each time, so a forgotten one did not fail — it read an empty directory and recall quietly returned less. `learningsRoots(localConfig)` now answers with a write root and an ordered read list, and a test fails on a new hand-built path. Two call sites have no config to resolve (the `viz --repo` flag and CI) and opt out in place, with the reason on the line. **Every root is read.** `buildIndex` takes the whole list. For one relative path the first root wins, deduplicated while collecting: that path is also the id votes are counted by, so two entries would double-count votes and then have one silently dropped by recall's dedup. The clone's `learnings/` is always the last root, which is what keeps the pre-switch corpus searchable. **One publish path.** `teamai contribute` writes into the `teamai-learnings` worktree and pushes, for independent clones and single-repo installs alike. Single-repo mode stops opening a pull request per contribution, so the disposable knowledge worktree and the machine-wide cache copy that stood in for it are gone — and with them the cross-project leak of writing one project's learnings into a cache every project shares. What cannot be published stays in the durable queue outside the clone and is retried by the next `teamai pull`. **Maintenance.** Pruning, promotion and confidence write-backs used to mutate a checkout nothing pushes: the result reached no teammate, and a realign could undo it. Promotion was worse — the `promoted_to` mark it wrote was discarded, so the same learning was promoted again on the next run and paid for another model call. They now write to the write root, publish what they changed, and refuse to prune an inherited learning instead of deleting a file that comes back. Fixes that fall out of reading the same code: - A recall that had to rebuild the index passed no project namespaces, so every project-private learning vanished from the rebuilt index while a pull-built one had them. - Recall printed the absolute path an entry had when it was indexed; a worktree that is removed and rebuilt leaves that dangling, and the agent reading the output got a dead pointer. - `pull`'s mirror deletes whatever its source does not have, so it now takes every published root except the mirror itself — pointed at one root it would have stopped propagating upstream deletions (Tencent#458). - The learnings count in `pull` deduplicates across roots, the way the index does. - Contributing self-heals the single-repo `.gitignore` first, the way `pull` and `push` already do, so the new worktree never shows up in the user's own `git status`. - Recall says why a scope was skipped instead of swallowing the reason: an invalid projects manifest reported "No learnings available" and nothing else. Real-git coverage against a bare origin whose `update` hook refuses the default branch: the learning lands on the side branch with `main` untouched, a refused branch leaves the note recoverable, a commit whose push failed is delivered on the next attempt, two members publishing at once both land, one member reads the other's learning after a refresh, and the inherited corpus is still there. Refs Tencent#485
…cent#486) A team that turns on branch protection needs to know what still works and what access its members actually need. The docs said learnings live on the default branch, and the providers guide said the push target is hardcoded to `master`. - The data-layout table covers knowledge, learnings, reports and machine-local data, and says for each how it is written and whether it needs write access to the default branch. EN and ZH match row for row. - A minimum-permissions section in the usage guide and in the providers guide: what a member needs, what they do not, and that `provider: git` still cannot open a pull request for you while `contribute` never needs one. - The directory trees show `learnings-wt/` and `pending-learnings/`. - The admin checklist says `init` commits an empty `learnings/` and that contributions do not go there. - `docs/providers.md` no longer says the push target is hardcoded: it is resolved by `getDefaultBranch()`. The same stale claim in the docstring of `pushRepoDirectly` goes with it. - The share-learnings skill names the branch instead of "directly to master". - All five READMEs name the branch in the `teamai contribute` row. - Both design documents describe the new split. Closes Tencent#486
…lished Splitting this change in two left a gap the full version did not have. Before learnings moved to their own branch the note was written into the clone, so it was indexed no matter what git did. Now a contribution is written into the branch worktree — and when that worktree cannot be created at all, the durable copy was kept but never indexed, so the member could not recall what they had just written. - The queue is a learnings root for the index, in `contribute` and in `pull`. - The durable copy is written before the index is rebuilt, not after, or there would be nothing to index. The queue stays the fallback here; making it the write path is Tencent#615. Refs Tencent#485
Collaborator
Author
|
The follow-up is ready to go whenever this merges: #615 has the branch It carries what you moved out of #485: the queue as the single write path, single-repo mode routed through it, and the queue state surfaced during No rush from my side: it is out of this PR's way, exactly as you asked. |
…long it can take A review pass against edge cases found three ways this change could report or behave worse than what it replaced. **A successful push read as a failure.** The publish confirmed delivery by checking that HEAD was no longer ahead of `origin/<branch>`. That ref is only updated through the remote's FETCH refspec, so in a clone made with `--single-branch` — what CI checkouts and many business repos are — pushing a side branch leaves no tracking ref behind and the check said "not landed". The result was five pushes of the same content and a reported failure although the data was on origin, and for reports a `save-session` that printed a push timeout for a write that had worked. A push that resolves is a push the remote accepted; git exits non-zero when it refuses one. The tracking ref is now only consulted to answer "does this worktree still owe origin a commit?", where an unreadable answer means push and find out. **No cap on how long publishing can take.** `contribute` used to give its push ten seconds. That cap was lost, so an unreachable origin or a credential prompt could block the CLI through five push and rebase rounds. Both publish paths carry it again; timing out is safe because the durable copy stays. **A warning aimed at a backend with no branch.** Maintenance on an HTTP team repo has nothing to publish, and said so as a failure. It stays quiet. Also from the same pass: - `teamai pull` publishes the queue for every repo kind. It sat inside the team-repo refresh, which returns early for single-repo and HTTP, so the promise contribute makes — "will retry on the next pull" — was only true for independent clones. - The auto-migration skips `learnings-wt/` along with the other worktrees, driven by the shared list so the next worktree is covered without anyone remembering this file. `pending-learnings/` deliberately still travels: it is work the member has already done. - `recall`'s own index rebuild reads the queue, so a contribution that could not be published does not vanish when anything invalidates the index. - The learnings mirror carries every visible file in an active namespace again, not only Markdown. Refs Tencent#485
9 of 13 tasks
5 tasks done
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
…ent#616) * refactor(branch): extract the orphan-branch worktree engine `reports-branch.ts` managed the `teamai-reports` orphan branch: cold-start creation across two git versions, stale-worktree repair, a non-blocking lock, commit, and push with fetch+rebase retry. Learnings need the same machinery on their own branch (Tencent#485), and must not share the branch, the worktree or the lock. The engine moves to `branch-worktree.ts`, parameterised by a spec of three names plus an init commit message. Reports become one instance of it and keep every exported name, so no caller changes. `reports-branch.ts` keeps what is not a side branch: `EmptyRepoError` and `withKnowledgeWorktree`. - A publish returns `PublishResult` instead of a boolean. A caller holding the only durable copy of its data must be able to tell "landed on origin" from "another writer holds the lock", "nothing to commit" and "rejected". Reports map it back to today's boolean, so their behaviour is unchanged. - A publish confirms the ref actually moved before reporting success, and separates "nothing to commit" from "nothing to deliver": an earlier attempt may have committed the content and failed to push it. A successful push updates the remote-tracking ref locally, so the check is a local rev-list. Anything unreadable counts as not landed, which costs one extra push instead of losing data. - `getWorktreeDir` and `getBusinessRoot` come out of the reports-specific helpers; `getReportsDir` is now one call to the first. - `usesReportsBranch` was a one-line forward; its eleven call sites use `usesBranchWorktree`, which says what it means now that two branches use it. - A side branch's `.gitignore` lists every worktree directory, so no worktree can nest-track another. - `ensureReportsDir` had no callers and duplicated `ensureReportsWorktree`. Refs Tencent#485 * feat(learnings): write learnings to teamai-learnings, read them from every root Contributing no longer touches the default branch, so a member whose team protects `main` can contribute. Everything the team wrote before the switch stays readable exactly where it is: nothing is copied, deleted or migrated. **One accessor.** Eleven call sites built the learnings path by hand, from a different base each time, so a forgotten one did not fail — it read an empty directory and recall quietly returned less. `learningsRoots(localConfig)` now answers with a write root and an ordered read list, and a test fails on a new hand-built path. Two call sites have no config to resolve (the `viz --repo` flag and CI) and opt out in place, with the reason on the line. **Every root is read.** `buildIndex` takes the whole list. For one relative path the first root wins, deduplicated while collecting: that path is also the id votes are counted by, so two entries would double-count votes and then have one silently dropped by recall's dedup. The clone's `learnings/` is always the last root, which is what keeps the pre-switch corpus searchable. **One publish path.** `teamai contribute` writes into the `teamai-learnings` worktree and pushes, for independent clones and single-repo installs alike. Single-repo mode stops opening a pull request per contribution, so the disposable knowledge worktree and the machine-wide cache copy that stood in for it are gone — and with them the cross-project leak of writing one project's learnings into a cache every project shares. What cannot be published stays in the durable queue outside the clone and is retried by the next `teamai pull`. **Maintenance.** Pruning, promotion and confidence write-backs used to mutate a checkout nothing pushes: the result reached no teammate, and a realign could undo it. Promotion was worse — the `promoted_to` mark it wrote was discarded, so the same learning was promoted again on the next run and paid for another model call. They now write to the write root, publish what they changed, and refuse to prune an inherited learning instead of deleting a file that comes back. Fixes that fall out of reading the same code: - A recall that had to rebuild the index passed no project namespaces, so every project-private learning vanished from the rebuilt index while a pull-built one had them. - Recall printed the absolute path an entry had when it was indexed; a worktree that is removed and rebuilt leaves that dangling, and the agent reading the output got a dead pointer. - `pull`'s mirror deletes whatever its source does not have, so it now takes every published root except the mirror itself — pointed at one root it would have stopped propagating upstream deletions (Tencent#458). - The learnings count in `pull` deduplicates across roots, the way the index does. - Contributing self-heals the single-repo `.gitignore` first, the way `pull` and `push` already do, so the new worktree never shows up in the user's own `git status`. - Recall says why a scope was skipped instead of swallowing the reason: an invalid projects manifest reported "No learnings available" and nothing else. Real-git coverage against a bare origin whose `update` hook refuses the default branch: the learning lands on the side branch with `main` untouched, a refused branch leaves the note recoverable, a commit whose push failed is delivered on the next attempt, two members publishing at once both land, one member reads the other's learning after a refresh, and the inherited corpus is still there. Refs Tencent#485 * docs: document the branch layout and the minimum Git permissions (Tencent#486) A team that turns on branch protection needs to know what still works and what access its members actually need. The docs said learnings live on the default branch, and the providers guide said the push target is hardcoded to `master`. - The data-layout table covers knowledge, learnings, reports and machine-local data, and says for each how it is written and whether it needs write access to the default branch. EN and ZH match row for row. - A minimum-permissions section in the usage guide and in the providers guide: what a member needs, what they do not, and that `provider: git` still cannot open a pull request for you while `contribute` never needs one. - The directory trees show `learnings-wt/` and `pending-learnings/`. - The admin checklist says `init` commits an empty `learnings/` and that contributions do not go there. - `docs/providers.md` no longer says the push target is hardcoded: it is resolved by `getDefaultBranch()`. The same stale claim in the docstring of `pushRepoDirectly` goes with it. - The share-learnings skill names the branch instead of "directly to master". - All five READMEs name the branch in the `teamai contribute` row. - Both design documents describe the new split. Closes Tencent#486 * fix(contribute): keep a contribution findable when nothing can be published Splitting this change in two left a gap the full version did not have. Before learnings moved to their own branch the note was written into the clone, so it was indexed no matter what git did. Now a contribution is written into the branch worktree — and when that worktree cannot be created at all, the durable copy was kept but never indexed, so the member could not recall what they had just written. - The queue is a learnings root for the index, in `contribute` and in `pull`. - The durable copy is written before the index is rebuilt, not after, or there would be nothing to index. The queue stays the fallback here; making it the write path is Tencent#615. Refs Tencent#485 * fix(learnings): do not call a successful push a failure, and cap how long it can take A review pass against edge cases found three ways this change could report or behave worse than what it replaced. **A successful push read as a failure.** The publish confirmed delivery by checking that HEAD was no longer ahead of `origin/<branch>`. That ref is only updated through the remote's FETCH refspec, so in a clone made with `--single-branch` — what CI checkouts and many business repos are — pushing a side branch leaves no tracking ref behind and the check said "not landed". The result was five pushes of the same content and a reported failure although the data was on origin, and for reports a `save-session` that printed a push timeout for a write that had worked. A push that resolves is a push the remote accepted; git exits non-zero when it refuses one. The tracking ref is now only consulted to answer "does this worktree still owe origin a commit?", where an unreadable answer means push and find out. **No cap on how long publishing can take.** `contribute` used to give its push ten seconds. That cap was lost, so an unreachable origin or a credential prompt could block the CLI through five push and rebase rounds. Both publish paths carry it again; timing out is safe because the durable copy stays. **A warning aimed at a backend with no branch.** Maintenance on an HTTP team repo has nothing to publish, and said so as a failure. It stays quiet. Also from the same pass: - `teamai pull` publishes the queue for every repo kind. It sat inside the team-repo refresh, which returns early for single-repo and HTTP, so the promise contribute makes — "will retry on the next pull" — was only true for independent clones. - The auto-migration skips `learnings-wt/` along with the other worktrees, driven by the shared list so the next worktree is covered without anyone remembering this file. `pending-learnings/` deliberately still travels: it is work the member has already done. - `recall`'s own index rebuild reads the queue, so a contribution that could not be published does not vanish when anything invalidates the index. - The learnings mirror carries every visible file in an active namespace again, not only Markdown. Refs Tencent#485
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
learnings/moves to ateamai-learningsorphan branch, written by direct push, so a member with no write access to a protected default branch can contribute. Everything the team wrote before the switch stays exactly where it is and keeps coming back fromteamai recall.Shaped by the decisions in #485: orphan branch holding only
learnings/, the old tree kept as the last read root, and the read seam folded into this one PR rather than landed separately. The offline-first queue rework is out of scope here and now lives in #615.members/sessions/votes/stats) toteamai-reportsin independent git clones #484 is extracted intobranch-worktree.ts, parameterised by branch, worktree directory and lock. Reports become one instance of it and keep every exported name; learnings are the other.learningsRoots(localConfig)gives a write root and an ordered read list.buildIndextakes the whole list and, for one relative path, the first root wins — that path is also the id votes are counted by.teamai contributepublishes to the branch in both independent-clone and single-repo mode. Single-repo mode stops opening a pull request per contribution.main#486).Type of Change
Bugs found and fixed along the way
Each has a test.
git pushresolved, and returned the samefalsefor "busy lock", "nothing staged" and "rejected". A caller holding the only durable copy could not tell them apartbranch-worktree.tsbranch-worktree.tscontribute.ts~/.teamai/learnings, which every project on the machine shares, so one project's learnings surfaced in another's recallcontribute.tsrecall.tsrecall.tspromoted_tomark into a checkout nothing commits, so a realign discarded it and the same learning was promoted again on the next run, paying for another model callpromote.tsprune.tspull.tsrecall.tsensureReportsDirwas dead code duplicatingensureReportsWorktreereports-branch.tsdocs/providers.mdsaid the push target is hardcoded tomaster;getDefaultBranch()resolves itgit.tspending-learnings/still travels because it is work the member has already donemigrate.tsTest Plan
npx tsc --noEmit— cleannpx vitest run— 3348 tests, 244 files, greensrc/__tests__/git-kind-learnings.test.ts(bare origin whoseupdatehook refusesmain/master): the learning lands onorigin/teamai-learningswithmainuntouched; a refused branch leaves the note recoverable; a commit whose push failed is delivered on the next attempt; a namespaced learning keeps its subdirectory; one member reads another's learning after a refresh; two members publishing at once both land; the inherited corpus is still readable and still in the clonesrc/__tests__/maintenance-two-roots.test.ts: an inherited learning is updated in the write root, the clone is untouched, and pruning an inherited learning is refused with an actionable messagesrc/__tests__/learnings-path-guard.test.ts: fails on a new hand-built learnings pathsrc/__tests__/contribute-unpublishable.test.ts: a contribution stays findable on the member's own machine even when the learnings worktree cannot be created at all — the guarantee the old write-into-the-clone path gave for freesrc/__tests__/contribute-edge-modes.test.ts: a single-repo install with no commits yet keeps the note; an HTTP team repo is refused by the read-only guard, as beforesrc/__tests__/pull-publishes-queue.test.ts:pullpublishes the queue in single-repo mode too, not only in an independent clone--single-branchclone, the shape CI checkouts have: a push of a side branch leaves no remote-tracking ref, so delivery is judged by the push itself (git-kind-learnings.test.ts)npm run build, then the built CLI against a local bare remote whoseupdatehook rejects the default branch:gitend to end, as above.gitlabandgithubdiffer only in pull-request creation, whichcontributeno longer uses;teamai pushis untouchedRelated Issues
Closes #485
Closes #486
Follow-up: #615 (make the pending queue the write path for contribute, and surface it) — split out at your request.
Notes for Reviewers
viz --repo <path>andci/extract-mrhave noLocalConfigto resolve roots from, so they opt out of the path guard in place, with the reason on the line.ci extract-mrstill writes its learning to the default branch. CI holds a token that may write there, the clone stays a read root so the learning is still found, and splitting its single commit across two branches is not something this change can verify end to end. Writelearnings/to ateamai-learningsbranch (direct push, no PR) #485 lists it as a follow-up.src/ci/extract-mr.tslogs in Chinese, against the repo's own rule. It predates this change; translating it would widen the diff, so it is left alone.