Skip to content

fix(codebase): publish --deep-enrich output in a team repo (#1537) - #1538

Closed
Kiddo4993 wants to merge 2 commits into
Tencent:mainfrom
Kiddo4993:fix/issue-1537
Closed

Kiddo4993 wants to merge 2 commits into
Tencent:mainfrom
Kiddo4993:fix/issue-1537

Conversation

@Kiddo4993

Copy link
Copy Markdown

Fixes #1537.

Problem

In a team that keeps its knowledge in the team repo (so no --output), teamai codebase --deep-enrich --project <name> wrote the docs into the local team clone and then stopped. It reported success, but nothing reached the remote. The clone was also left dirty, so the member's next teamai push failed.

Change

codebase --deep-enrich now handles the team clone the same way teamai import --dir does:

  • It holds the teamwiki import lock (lockTeamwiki) while it writes.
  • When the target is the team repo, it publishes the result with autoPushTeamRepo ([teamai] Deep enrich: <project>), the same push path import --dir uses.
  • With --output, or on --dry-run, it does not publish. Those cases already worked.

It publishes whatever was written even when enrichment is incomplete (exit code stays 1). This matches import, which also publishes partial deep-enrich output, so the clone is never left dirty.

To support this, teamwikiDirFor became teamwikiTargetFor and now returns the whole TeamwikiTarget so the handler knows about the team. --status and the other callers still only read wikiRoot, so their behaviour is unchanged.

Tests

Added src/__tests__/codebase-deep-enrich-publish.test.ts, which covers three cases:

  • Team-repo target: the command takes the lock, runs enrich, pushes, then releases the lock, in that order.
  • --output target: no push.
  • --dry-run: no lock and no push.

The existing --output deep-enrich tests are unaffected, because lockTeamwiki does nothing when there is no team. I couldn't run the test suite in this environment.

Fixes #1537


Happy to adjust anything or close it if it isn't a fit.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Missing real-CLI verification — src/codebase-cmd.ts:157 adds runtime publishing behavior, but the PR description contains no end-to-end / real-CLI verification record—only mocked tests that were not run. This violates the Code Review Rules requirement for runtime changes. Document one representative real-CLI run after npm run build, confirming that deep-enrich output reaches the remote. A full provider × agent matrix is not required.

@SaulMoro
SaulMoro marked this pull request as ready for review October 28, 2026 22:55
@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Missing real-CLI verification — src/codebase-cmd.ts:157 adds runtime publishing behavior, but the PR description still contains no end-to-end / real-CLI verification record; it only lists mocked tests that were not run. This violates the Code Review Rules requirement for runtime changes. Document one representative real-CLI run after npm run build, confirming that deep-enrich output reaches the remote. The earlier finding remains unresolved; a full provider × agent matrix is not required.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

@Kiddo4993 Thanks for picking up #1537 so quickly. We ran its sequence with the built CLI, main against d446a37d. On main, the remote never gets architecture.md or lib.md, the clone is left dirty, and teamai push fails. Here the docs reach the remote, the clone is clean, and the next push works. A partial run publishes what it wrote and exits 1, and a later complete run publishes the rest. --output, --dry-run and --status behave as before. tsc, lint and the unit test pass. Two things block it:

  • [P1 blocking] No real-CLI record. This changes what the command does, so the first Code Review Rules item in AGENTS.md asks for one built-CLI run. The CI review asks for the same, and we agree. #1537's sequence is enough: teamai import --dir ./svc with deep enrich failing, then teamai codebase --deep-enrich --project svc, then the remote's docs and git status of the team clone.

  • [P1 blocking] A publish that fails is reported as success, and the next push drops the docs. codebase --deep-enrich doesn't pull first, so if another member pushed to the team main since the last pull:

    1. The command prints ⚠ [git] autoPush failed (non-blocking): To file:///…, then Deep enrichment complete: project=svc, and exits 0. The docs are committed locally but not on the remote.
    2. The member's next teamai push prints Team repo diverged from origin/main; realigning discards 1 local commit(s), and architecture.md and lib.md are gone from the clone.

    A main that refuses direct pushes gives the same exit 0, and the docs then ride along in whatever the member pushes next. On main, the same sequence at least keeps the docs in the working tree. The cause is autoPushTeamRepo (src/utils/git.ts), which turns push errors into a warning. import --dir has the same flaw, and we've filed that separately. The smallest fix here: call pushRepoDirectly, which throws. On failure, log.error the cause and a next step ("run teamai pull, then rerun this command"), and exit 1. Publishing through a branch, as import --from-repo does, would avoid the moved-main case, but it changes how a team reviews the result, so that one is a maintainer call.

Non-blocking:

  • [P3 nit] lockTeamwiki writes a lock file nothing has read since #1293, so the call doesn't serialize anything. The test's ['lock','enrich','release'] check pins call order through a mock, and one of its three cases passes on main too.
  • [P3 nit] Each rerun with nothing new adds a [teamai] Deep enrich: <project> commit to the team main, because _review/progress.json gets a new timestamp.

@Kiddo4993

Copy link
Copy Markdown
Author

Thanks for the thorough triage run! Changes:

  • [P1] Failed publish reported as success: in the team repo, codebase --deep-enrich now publishes with pushRepoDirectly instead of autoPushTeamRepo, so push errors are no longer turned into a warning. If the push fails, the command still prints the enrichment result. It then logs the cause with log.error, adds a next step ("Run teamai pull, then rerun this command."), and exits 1. The lock is still released in finally. I added a unit test for this: a rejected push leads to exit 1, both error lines are logged, and the events are lock → enrich → release. The other tests now check pushRepoDirectly(repoPath, '[teamai] Deep enrich: svc', ['.']). I can't run code in this environment, so I haven't run this test or the rest of the suite.
  • [P1] Built-CLI record: not done, because I can't run the built CLI here. I'll add the [bug] codebase --deep-enrich in a team repo reports success but never publishes, and leaves the team clone dirty #1537 sequence to the PR description: import --dir ./svc with deep enrich failing, then codebase --deep-enrich --project svc, then the remote's docs and git status of the clone. I'll also add the moved-main failure case.
  • Publishing through a branch, as import --from-repo does, is left to you as you suggested. I didn't change the two P3 nits (the lockTeamwiki lock that nothing reads, and the empty-rerun commits). Happy to follow up on either.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Missing real-CLI verification — src/codebase-cmd.ts:157 adds runtime publishing, but the PR description still documents no end-to-end / real-CLI run and says the mocked tests were not run. This violates the first ## Code Review Rules item; the earlier finding remains unresolved. Document one representative real-CLI run after npm run build, confirming deep-enrich output reaches the remote. A full provider × agent matrix is not required.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@Kiddo4993 Thanks, the failed-publish fix works. We built 4ccd36a7 and ran it against main:

  • Another member pushed to main first. The command prints the cause and Run `teamai pull`, then rerun this command., then exits 1. Following that, teamai pull drops the unpushed local commit with a warning, and the rerun publishes architecture.md and lib.md on top of the other member's commit. The clone ends clean, so nothing is lost. On main, the same case exits 0 and leaves the clone dirty.
  • A main that refuses pushes. Exit 1 with git's message.
  • Tests and checks. tsc and lint pass. The unit tests pass, 199/199 across six files, and the new one fails without this change.

One thing is still open, and it's the only blocker:

  • [P1 blocking] No real-CLI record in the body. Since you can't run the CLI where you are, here is the record from our runs at this head. If it matches what you expect, paste it into the description in place of the Tests section's note, and we'll approve once CI is green:
Real-CLI record at 4ccd36a

Real-CLI verification (built CLI at 4ccd36a, npm run build)

Setup: isolated HOME, empty GIT_CONFIG_GLOBAL, GIT_CONFIG_NOSYSTEM=1, TEAMAI_NONINTERACTIVE=1. Team created with teamai init https://git.example.invalid/team/a.git --provider git --agent claude --scope user, routed to a local bare repo through url.insteadOf. svc is a small git project. A stub claude on PATH either fails (exit 1) or returns a fixed doc.

#1537 sequence

$ teamai import --dir ./svc                          # stub claude fails
exit 0; remote svc/docs: README.md graph-g1-relations.md graph-g2-dataflow.md graph-g3-interfaces.md graph-g6-multihop.md

$ teamai codebase --deep-enrich --project svc        # stub claude works
Deep enrichment complete: project=svc
exit 0
remote svc/docs: README.md architecture.md graph-g1-... graph-g6-multihop.md lib.md
remote log: [teamai] Deep enrich: svc | [teamai] Import from local dir: svc | seed
git -C ~/.teamai/team-repo status --porcelain: (empty), 0 commits ahead of origin/main

$ teamai push                                        # a new skill
✔ Pushed branch teamai/push/rv/20261029-011931

On main the same sequence leaves architecture.md and lib.md off the remote, the clone dirty, and teamai push fails with ✖ Cannot push: the team repo has uncommitted changes.

Publish fails: another member pushed to main since the last pull

$ teamai codebase --deep-enrich --project svc
Deep enrichment complete: project=svc
✖ Failed to publish deep enrichment to the team repo: To file:///.../a.git
!	refs/heads/main:refs/heads/main	[rejected] (fetch first)
...
✖ Run `teamai pull`, then rerun this command.
exit 1

$ teamai pull
⚠ Team repo diverged from origin/main; realigning discards 1 local commit(s) and 0 uncommitted change(s).
✔ [user] Team repo: reset to origin (diverged)
exit 0

$ teamai codebase --deep-enrich --project svc
Deep enrichment complete: project=svc
exit 0
remote svc/docs: README.md architecture.md graph-g1-... graph-g6-multihop.md lib.md
remote log: [teamai] Deep enrich: svc | other | [teamai] Import from local dir: svc | seed
clone clean, 0 commits ahead

Publish fails: a pre-receive hook refuses main

$ teamai codebase --deep-enrich --project svc
Deep enrichment complete: project=svc
✖ Failed to publish deep enrichment to the team repo: To file:///.../a.git
!	refs/heads/main:refs/heads/main	[remote rejected] (pre-receive hook declined)
remote: main is protected
✖ Run `teamai pull`, then rerun this command.
exit 1

Non-blocking, worth doing while you edit the body:

  • [P2 non-blocking] The body still says the command publishes with autoPushTeamRepo and lists three tests. It now uses pushRepoDirectly, and there are four.
  • [P3 nit] The printed next step doesn't fit every failure. When main refuses pushes, pull and a rerun fail again and add another local commit. When the team clone is pinned to a ref, the plain Run `teamai pull` line follows the pin error and contradicts its advice, because the new catch also catches the error autoPushTeamRepo used to rethrow (DetachedTeamRepoError). We found that one in the code and didn't run it. Rethrowing that error, as autoPushTeamRepo does, would keep it.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@Kiddo4993 Thanks for this. #1560 has since merged (7a0c52a0) and closed #1537. Main now publishes the codebase --deep-enrich output in a team repo under the import lock (src/codebase-cmd.ts, around line 147), which is what this PR does. This branch now conflicts with main.

Unless there is a case here that #1560 does not cover, I think this can be closed. If there is one, please rebase onto main and say which case it is, and I'll review it against #1560's version.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@Kiddo4993 Closing this in favor of #1560, which merged as 7a0c52a0 and closed #1537. I compared the two: main writes --deep-enrich output under the import lock in a team repo, publishes it, does nothing on --dry-run or with --output, and a failed push makes the command fail with git's reason. It also publishes only the evidence, router.md and index.md rather than the whole clone. I found no case here that main misses. Thanks for the fix; if you hit one, please open an issue with the steps.

@SaulMoro SaulMoro closed this Oct 30, 2026
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.

[bug] codebase --deep-enrich in a team repo reports success but never publishes, and leaves the team clone dirty

3 participants