Skip to content

fix(env): give each directory its own team env (#1018) - #1023

Merged
jeff-r2026 merged 17 commits into
Tencent:mainfrom
SaulMoro:fix/env-by-directory
Oct 13, 2026
Merged

jeff-r2026 merged 17 commits into
Tencent:mainfrom
SaulMoro:fix/env-by-directory

Conversation

@SaulMoro

@SaulMoro SaulMoro commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1018

Summary

Team env follows the directory a shell starts in, not the project that pulled last.

 pull (any scope)
-  write `source <scope>/env.sh` into the profile, replacing the other project's block
+  register the scope in ~/.teamai/env-scopes   (git common dir → env.sh)
+  write ~/.teamai/env-loader.sh and one profile block that sources it

 shell starts, or cd in an interactive shell
+  loader: $PWD → registry row → env.sh files
+    put back the member's values, then source the new files
Directory Gets
project (or its worktree) its own env.sh
project with inheritUserScope: true user env.sh, then the project's; never user secrets
project not yet registered, or a repository git can't read nothing
anywhere else user env.sh

The loader routes to the scope resolveConfigForDir resolves, so shells, env exec, MCP, doctor and the session hint agree. Outside git that is the directory holding .teamai itself, not its subdirectories, as for the CLI. While a scope's env can't be resolved, its row keeps routing to the last env.sh, the values env exec and MCP keep too, minus any key now declared a secret; a scope never delivered loads nothing, never the user scope's. Inside a project, and in a bash env exec starts, a team value arrives as written, even into a declare -i/-l/-u variable. Leaving restores each key as the member had it, with its attributes (bash before 4.2, macOS's /bin/bash, can't restore one from a function). doctor checks the directory with the member's own PATH/GIT_*, and compares env names case-insensitively on Windows.

The README marks env ✓² for Pi, DeepSeek Harness and ZCode: env reaches them only through teamai env exec. The rules marker becomes ✓¹ (Muse Code included). For zsh, Muse Code's model key block now goes in the same .zshenv (or $ZDOTDIR/.zshenv) as the loader, and a restore takes it out of there.

On Windows, MCP already compares a secret's name case-insensitively (declaredSecretKeys().has folds through envName), so a member's token never sits beside the secret TOKEN; two win32 tests now pin that.

Evidence

  • Before: after teamai pull in project B, a new shell in project A gets B's env and doctor fails in A.
    After: env-by-directory-1018.test.ts passes 3/3.
  • Before: a key declared a secret while env.yaml (or the values file) was broken stayed in shells (keeps a key ... now declares a secret, 4 rows); declare -ix TOKEN=3 got team 1+1 as 2 (bash, zsh, also -l/-u), in a project and through a member BASH_ENV under env exec; on win32 doctor called jira_password missing and leftover for JIRA_PASSWORD.
    After: all pass.
  • Real CLI at 392de135, a project with team TOKEN='1+1', member ~/.bash_env with declare -ix TOKEN=3:
    $ BASH_ENV=~/.bash_env teamai env exec -- bash -c 'printf "%s\n" "$TOKEN"'
    bash 5.3: 1+1 (nested bash: 1+1)
    bash 3.2: 1+1 (nested bash: 1+1)
    
  • At 392de135: tsc, lint, build pass; npx vitest run 9,402 passed, 20 skipped, and with /bin/bash 3.2 first on PATH (as on the macOS runners) 9,397 passed, 23 skipped; e2e selected by the diff (all 112 files) 1,187 passed, 27 skipped, 1 failed (source-freshness-recall, which fails the same way on origin/main on macOS).

Merge Danger

Door: two-way

Pull moves older per-scope blocks out of the profile; teamai uninstall removes the loader block. Rollback to an earlier release not exercised.

Blast Radius: shells

Every bash and zsh startup sources the loader. User-scope env no longer loads inside a project unless it sets inheritUserScope: true (in the changelog as breaking).

@SaulMoro
SaulMoro force-pushed the fix/env-by-directory branch from deef0c4 to 407a767 Compare October 9, 2026 20:45
@jeff-r2026 jeff-r2026 self-assigned this Oct 10, 2026
@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/utils/shell-profile.ts:53 selects ~/.zshenv whenever it exists, even when the current process exports ZDOTDIR. A parent zsh commonly exports ZDOTDIR from ~/.zshenv; every child zsh -c then reads $ZDOTDIR/.zshenv instead, so it never runs the injected loader and can carry another directory’s env.
  • [P1 blocking] src/resources/env.ts:349 returns before installing or migrating the loader when a project has no env.sh. After upgrading a machine with an old user-scope block, pulling an env-less project only registers the scope; the old block remains active and continues leaking user env into that project.
  • [P1 blocking] src/resources/env-loader.ts:278 exports BASH_ENV only while already running under bash. A zsh session loaded with project A’s env that launches bash -c with cwd in project B leaves BASH_ENV unset, so non-interactive bash skips the loader and incorrectly receives A’s env.
  • [P1 blocking] src/resources/env-loader.ts:253 skips all work when the inherited directory marker matches $PWD, without detecting changes to the loaded env.sh. After teamai pull changes a value, a new zsh -c or bash -c started from the same parent and directory keeps the old value indefinitely because it inherits both the stale env and marker.

The PR description’s testing record is sufficient, including representative real-CLI verification.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/resources/env-loader.ts:223 always falls back to the user env.sh, without recording whether the user-scope team set injectShellProfile: false. If that user scope is pulled and any project later installs the shared loader, shells outside registered projects receive the opted-out user variables.
  • [P1 blocking] src/env-exec.ts:194 removes another scope’s exported values but retains its BASH_ENV and __TEAMAI_ENV_* bookkeeping. If project B exported TOKEN, project A declares TOKEN as a secret, and teamai env exec in A launches a Bash script, the loader un-applies B after the secret overlay and unsets/restores TOKEN; A’s env.sh cannot restore it because secrets are excluded.

The four previously reported findings are resolved in the current diff. The PR description includes sufficient real-CLI testing.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/uninstall.ts:2116 keeps the profile block when a user-scope uninstall detects remaining projects, but the later generic removal of ~/.teamai still deletes env-loader.sh and env-scopes. After uninstalling user scope while a project remains registered, new shells source a nonexistent loader and the project receives no team env.
  • [P1 blocking] src/resources/env.ts:396 still honors an existing sharing.env.shellProfilePath such as ~/.zshrc. Upgraded zsh users with that supported override get the loader only in .zshrc, which zsh -c never reads, so commands started in a project receive no—or another project’s—env while both new doctor checks pass.
  • [P1 blocking] src/resources/env-loader.ts:317 leaves a pre-existing BASH_ENV unchanged. If a non-interactive zsh loaded project A, then runs cd <project-B> && bash -c ..., Bash sources only the member’s existing BASH_ENV; the loader never reroutes it and project A’s env leaks into project B.

The six earlier findings are resolved in the current diff. The PR description includes sufficient representative real-CLI testing.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/resources/env-loader.ts:140 preserves only projects whose registry entry contains an env.sh path. A registered project with injectShellProfile: false records -, so uninstalling the user scope—or home-only uninstall—returns no project files to keep and deletes its config/data, registry, and loader. The project remains initialized but loses its machine state; preserve every registered project’s data home independently of whether its env loads in shells.

The previously reported findings are resolved in the current diff. The PR description includes sufficient representative real-CLI testing.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/resources/env-loader.ts:360 lets a team env.sh overwrite loader control variables after BASH_ENV is routed. If project A declares BASH_ENV, then a zsh in A runs cd <project-B> && bash -c ..., Bash sources A’s file instead of env-loader.sh, so A’s env leaks into B.
  • [P1 blocking] src/resources/env.ts:362 installs the loader for an env-less project only when some profile already has a TeamAI block. If an inheritUserScope: true project has no variables and the opted-in user scope’s block was deleted, pulling inside the project registers the inherited env but never restores the loader, so new shells receive no user variables.
  • [P1 blocking] src/resources/env-loader.ts:179 preserves an opted-out project partition only when its recorded anchor is currently accessible to Git. If the main checkout is deleted or temporarily unmounted during user-scope uninstall, gitCommonDir(anchor) returns null and removeAllBut deletes that registered project’s machine state; reconnecting the project then finds its config and data gone.

The previously reported concrete cases are resolved. The PR description includes sufficient representative real-CLI testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:394 resolves the new directory before unapplying the previous team env. If project A exports PATH without git, or sets GIT_DIR, then cd into Git project B makes this lookup fail or resolve A’s repository, so B receives no env—or the wrong env. Restore the previous environment before running the registry lookup.
  • [P1 blocking] src/resources/env.ts:501 still permits HOME and ZDOTDIR. If project A exports either, a child zsh reads A’s alternate .zshenv instead of the installed loader; starting it in project B therefore retains A’s env and never routes to B.
  • [P1 blocking] src/resources/env-loader.ts:399 allows a team env.sh to overwrite PROMPT_COMMAND. In interactive Bash, the first prompt’s apply reloads that value and removes __teamai_env_apply; a subsequent cd to another project no longer switches environments.
  • [P1 blocking] src/env-exec.ts:210 applies reserved variables without filtering them. A team declaring BASH_ENV is ignored by env.sh, but teamai env exec -- bash -c ... still passes that value to Bash, which sources the declared file despite the warning that this variable is reserved and ignored.

All previously reported findings are resolved in the current diff. The PR description includes sufficient representative real-CLI testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:410 discovers each file’s keys after sourcing the previous file. If an inherited user scope sets PATH without sed, the project file is sourced but its keys are not recorded, so its values leak after leaving the project.
  • [P1 blocking] src/resources/env-loader.ts:328 applies the user env whenever the project row has inheritUserScope: true, even when that row’s env path is -. A project with injectShellProfile: false therefore still receives inherited user variables, contrary to the documented opt-out behavior.
  • [P1 blocking] src/env-reserved.ts:8 checks reserved names case-sensitively on Windows, where environment names are case-insensitive. A team variable named home bypasses filtering; env exec then removes the member’s HOME and passes the team value to the child.
  • [P3 nit] src/resources/env-loader.ts:187 converts every backslash in a recorded partition to the platform separator. On POSIX, a legitimate project path containing a literal backslash is changed, so user-scope uninstall fails to preserve that project’s actual machine-data directory.

All previously reported findings are resolved. The PR description includes sufficient representative real-CLI testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:421 exports every previous shell value into __TEAMAI_ENV_PREV_<key> without checking whether the original variable was exported. If a member has an unexported local value such as TOKEN=mine, entering a project that defines TOKEN exposes mine to every child process through the bookkeeping variable; leaving also restores TOKEN with export at src/resources/env-loader.ts:392, permanently changing its visibility.
  • [P1 blocking] src/mcp-reconcile.ts:201 builds MCP substitutions from only the project’s resolved variables and the inherited process environment. In an inheritUserScope: true project, a user-scope variable is therefore missing when teamai pull runs from a clean/desktop-launched process; a project MCP server referencing it remains unresolved even though shells and env exec receive that inherited variable.

All previously reported findings are resolved in the current diff. The PR description includes sufficient representative real-CLI testing.

@SaulMoro

Copy link
Copy Markdown
Collaborator Author

@jeff-r2026 could you re-run the Codex PR Review job for this head (run 38046833356)? It failed with DeploymentNotFound from the API, not on the diff. The same error has hit the review on several recent pushes here and on #1022. All other checks on 4fda43f pass. Thanks!

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:443 allows team variables to overwrite transient loader state not covered by the reserved-name rule. For example, a team defining TOKEN=x and __teamai_keys=OTHER replaces the captured key list while sourcing env.sh; after changing directories, TOKEN is never unapplied and leaks into the next scope. Reserve all loader working names, not only __teamai_env_*.
  • [P1 blocking] src/env-resolution.ts:121 filters inherited user variables against only the user scope’s secret declarations. If the user scope defines ordinary variable TOKEN=user, while an inheriting project declares TOKEN as a secret with no value, shells and MCP receive the user value instead of treating the project secret as missing. Filter inherited variables against the project’s secret keys before merging.
  • [P2 non-blocking] src/doctor-delivery.ts:1376 checks only project declarations and returns early when the project itself declares no variables. An inheritUserScope: true project whose user env.sh is missing or stale therefore passes both env delivery checks even though none of its inherited variables reach shells.

The earlier reported findings remain resolved. The PR description includes sufficient representative real-CLI testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/env-reserved.ts:11 still permits transient loader names such as __teamai_keys. If a team exports TOKEN=x and __teamai_keys=OTHER, sourcing the file replaces the captured key list; leaving the directory never unapplies TOKEN, so it leaks into the next scope.
  • [P1 blocking] src/env-resolution.ts:121 filters inherited variables against only the user scope’s secrets. If an inheriting project declares TOKEN as a secret while the user scope defines ordinary TOKEN=user, shells and MCP receive the user value when the project secret is missing.
  • [P1 blocking] src/resources/env-loader.ts:518 sources the member’s original BASH_ENV after applying the directory’s team env. If that file exports a key also defined by the team, every bash -c receives the member value instead of the team value.
  • [P2 non-blocking] src/resources/env-loader.ts:442 restores the member’s IFS immediately after sourcing the team files. Because IFS is not reserved, a team may declare it, but shells silently discard that value while env exec and MCP retain it.
  • [P2 non-blocking] src/env-listing.ts:46 lists only project declarations, ignoring inheritedVariables. In an inheriting project with only user-scope variables, teamai env list reports no variables even though shells, MCP, and env exec receive them.
  • [P2 non-blocking] src/doctor-delivery.ts:1376 validates only project declarations. Missing or stale user env.sh content in an inheriting project therefore passes diagnostics even though inherited variables are not delivered.

The earlier findings predating the October 11 review pass are resolved. The PR description includes sufficient representative real-CLI testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:303 uses pwd -W and falls back to pwd -P, but Windows zsh does not provide Bash’s -W output. The registry stores native paths such as C:/work/repo, while zsh returns /c/work/repo or /cygdrive/c/work/repo; the exact comparison at src/resources/env-loader.ts:324 never matches, so every Windows zsh started in a registered project loads the user fallback instead of the project env.
  • [P1 blocking] src/resources/env.ts:523 generates the inherited-value restore check with the project declaration’s exact casing. On Windows, if user scope exports token=user and the project declares missing secret TOKEN, resolution correctly treats them as the same key, but the shell check for TOKEN does not notice the scanned token; the user value remains exported and leaks to native child processes under Windows’ case-insensitive environment.

The previously reported findings are resolved in the current diff. The PR description includes sufficient representative real-CLI testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/env-resolution.ts:118 excludes an HTTP-backed user scope from inheritance. If a Git project sets inheritUserScope: true while the user scope uses the supported HTTP source and exports USER_TOKEN, shells source the user env.sh, but env exec, MCP substitutions, listings, and hints omit USER_TOKEN, violating R5’s single-resolution contract.
  • [P1 blocking] src/resources/env-loader.ts:436 restores every case-insensitive match before the project export. On Windows, if the member starts with token=mine, the user scope exports token=user, and the project exports TOKEN=project, loading leaves both token=mine and TOKEN=project; commands reading the lowercase spelling receive the member value even though Windows resolution treats it as the project’s variable.
  • [P2 non-blocking] src/mcp-reconcile.ts:204 falls back only to the project’s env backup when project variable resolution fails. In an inheriting project with malformed env.yaml, a valid inherited user variable remains available to shells and env exec but disappears from MCP substitutions.
  • [P2 non-blocking] src/doctor-delivery.ts:1348 emits the unsupported-shell note only when the current scope’s own env.sh exists. An inheriting project with only user-scope variables commonly has no project env.sh, so Fish or another unsupported shell receives no env and doctor gives no explanatory note.

The previously reported findings are resolved in the current diff. The PR description includes sufficient representative real-CLI testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/pull.ts:2707 still excludes env when pulling an inherited user scope. If the user team changes USER_ONLY=old to new and the member pulls inside an inheritUserScope: true project, the user repo refreshes but its env.sh remains old; new shells get old, while MCP and env exec resolve new from the refreshed repo. Include the user env stage or otherwise rewrite the inherited file during this pull.
  • [P2 non-blocking] src/env-listing.ts:48 hides inherited variables whenever the project’s own env.yaml fails. resolveTeamEnv still resolves the user-scope portion in this state, and MCP plus env exec apply it, but teamai env list reports the parse problem without listing those active inherited values.
  • [P2 non-blocking] src/hook-handlers.ts:837 emits the new variable hint even when secret declarations fail. With a valid env.yaml and malformed secrets.yaml, SessionStart claims the variables are available through teamai env exec, while env exec deliberately applies no team values because it cannot determine which variables are secrets.

Earlier reported findings remain resolved. The PR description documents sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/env-resolution.ts:122 treats failed user-scope secret declarations as an empty secret set. If an inheriting project has valid declarations while the user scope’s malformed secrets.yaml was meant to mark TOKEN secret, the project inherits and applies TOKEN from env.yaml; the user scope itself correctly applies nothing because any variable may be secret.
  • [P1 blocking] src/env-resolution.ts:128 silently discards an inherited user scope’s unreadable value-store state. With a corrupt user value store, the user env.sh retains its previous value, but an inheriting project’s env exec omits it and env list displays the repository default without reporting the read failure.
  • [P1 blocking] src/env-exec.ts:253 removes a missing secret only from the initial environment and does not include it in the BASH_ENV shim’s restoration list. If the member’s BASH_ENV exports that key, teamai env exec -- bash -c ... receives a secret value that resolution marked missing.
  • [P1 blocking] src/resources/env-loader.ts:64 does not restore the shim as BASH_ENV after sourcing the member’s file. If that file changes BASH_ENV, the first Bash gets the team value, but a nested Bash sources the replacement file directly and can overwrite the team value.

The previously reported findings are resolved. The PR description documents sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:428 resolves non-Git projects using the shell’s exact current directory, while registration stores only the project root. A shell started in <project>/src therefore misses the row and loads the user-scope env instead of the project env.
  • [P1 blocking] src/resources/env-loader.ts:147 replaces registry rows only when their directory key is unchanged. After moving a checkout and pulling from its new location, the old row remains; if another repository later occupies the old path, it receives the moved project’s env.
  • [P1 blocking] src/env-resolution.ts:213 treats the line-based KEY=value backup as an exact copy of env.sh. Values containing newlines or leading/trailing whitespace are truncated or trimmed by readEnvBackup; after a declaration/value-store failure, shells retain the exact last-pulled value while env exec, MCP, listings, and hints use a different value.

The previously reported findings are resolved in the current diff. The PR description documents sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:580 assumes ordinary assignment remains shell-local. In Bash with TOKEN=mine; set -a, the saved __TEAMAI_ENV_PREV_TOKEN is automatically exported to child processes, and restoration at src/resources/env-loader.ts:510 makes the originally local TOKEN exported. This breaks faithful restoration and exposes the local value through loader bookkeeping.
  • [P1 blocking] src/resources/env-loader.ts:522 lets Bash’s ambient nocasematch option change environment-name semantics. On Linux, if the user scope exports token=user, a project keeps TOKEN, and .bashrc enabled shopt -s nocasematch, the keep pattern also matches lowercase token and removes it, even though those are distinct POSIX variables.
  • [P1 blocking] src/resources/env.ts:209 uses readFileSafe, which turns an unreadable backup into an empty backup. If env.sh still exports TOKEN=old, the backup becomes unreadable, and declarations then fail, shells retain old while env exec, MCP, listings, and hints silently omit it—violating the last-pull fallback contract.

The previously reported findings remain resolved. The PR description includes sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:498 appends __teamai_env_apply after existing Bash PROMPT_COMMAND and zsh chpwd_functions hooks. After moving from project A to B, those hooks run with A’s environment first; a prompt hook invoking gh, AWS tooling, or similar can use A’s credentials in B before TeamAI switches scopes. Install the routing hook before existing hooks.
  • [P1 blocking] src/resources/env-loader.ts:632 guards Bash allexport and nocasematch only during initial loader sourcing; later PROMPT_COMMAND calls invoke __teamai_env_apply directly. If a member enables either option after startup and changes directories, the loader again exports bookkeeping/restored local values or performs case-insensitive POSIX key matching—the previously reported option-isolation bug remains on interactive directory changes.

The other previously reported cases appear resolved. The PR description includes sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:58 sources the member’s original BASH_ENV while $BASH_ENV still names TeamAI’s shim; the loader repeats this at src/resources/env-loader.ts:755. A valid file that locates companion files via dirname "$BASH_ENV" therefore resolves them beside env-exec-bash-env.sh or env-loader.sh instead of beside itself, breaking every Bash command. Temporarily expose the member’s original value while sourcing it, then restore TeamAI’s routing value.
  • [P2 non-blocking] src/doctor-delivery.ts:1370 returns immediately when the project’s own env declarations fail. In an inheriting project, the user-scope part remains independently active, so a missing or stale user env.sh is not diagnosed until the unrelated project error is fixed.
  • [P3 nit] src/resources/env.ts:235 treats malformed JSON backups as legacy KEY=value files. A truncated JSON backup is therefore silently read as empty while env.sh retains its values, recreating the shell/CLI divergence the backup is intended to prevent; JSON-shaped but invalid content should report an unreadable/corrupt backup.

The previously reported findings appear resolved. The PR description includes sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:622 treats any line beginning export KEY= as an assignment, even when that line is inside a multiline single-quoted value. A team value containing \nexport AWS_SECRET_ACCESS_KEY=x\n causes the loader to capture and export the member’s real credential as __TEAMAI_ENV_PREV_AWS_SECRET_ACCESS_KEY at src/resources/env-loader.ts:650, exposing it to ordinary child processes. The Windows spelling scan at src/resources/env-loader.ts:376 can additionally unset the real variable even though the file never assigns it.
  • [P1 blocking] src/resources/env.ts:612 removes working legacy blocks from other profile files before the replacement block is successfully written at src/resources/env.ts:626. During the zsh migration from .zshrc to .zshenv, an unwritable or managed .zshenv makes the final write fail after the .zshrc block has already been deleted, leaving subsequent shells with no TeamAI env. Install the replacement successfully before deleting old blocks, or roll back on failure.

The previously reported findings appear resolved in the current diff. The PR description includes sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env.ts:653 installs the loader block before rewriting legacy profile files. If .zshenv is writable but an old .zshrc block is read-only, pull fails after leaving both blocks installed; interactive zsh loads the directory-selected env first, then the stale project env from .zshrc, potentially leaking project A credentials into project B. Roll back the new block when legacy cleanup fails, or make the migration atomic.

The previously reported findings appear resolved in the current diff. The PR description includes sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env.ts:611 deduplicates profile candidates only by pathname, not by resolved file. If ~/.zshrc is a symlink to ~/.zshenv and contains a legacy env block, the write at src/resources/env.ts:640 first installs the loader through .zshenv, then writes the stripped legacy content through .zshrc to the same target, erasing the new block. Pull reports success, but subsequent zsh processes load no TeamAI env. Resolve and deduplicate symlink targets before planning the writes.

The previously reported findings appear resolved. The PR description includes sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env.ts:655 records a dangling profile symlink as nonexistent because pathExists follows the link. If ~/.zshenv points to a missing file in an existing dotfiles directory, the loader write creates that target; if a later profile cleanup fails, rollback at src/resources/env.ts:667 removes ~/.zshenv itself instead of the newly created target. The failed pull therefore deletes the member’s symlink and leaves the profile migration partially applied. Track link existence separately and roll back the resolved target without removing the link.

The previously reported findings appear resolved. The PR description includes sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/env-loader.ts:634 silently depends on awk being available through the member’s PATH. In a supported non-Git project with a restricted PATH containing TeamAI but no awk, the key scan fails, yet env.sh is still sourced; __TEAMAI_ENV_KEYS stays empty, so variables are never unapplied and leak into subsequent directories.
  • [P1 blocking] src/env-exec.ts:277 deliberately skips empty-string values when removing another scope’s exports. If project A exports FLAG='' and a non-interactive shell changes into project B before running teamai env exec, memberEnvironment identifies FLAG as non-member state, but this filter retains it; B’s command receives a variable its resolution and env list do not contain.
  • [P3 nit] src/resources/env.ts:645 treats every profile read failure as a nonexistent/empty file. A write-only profile or ACL allowing writes but denying reads is therefore overwritten with only the TeamAI block, destroying its existing contents instead of reporting the read failure.

The previously reported findings appear resolved in the current diff. The PR description documents sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P3 nit] src/env-reserved.ts:14 does not reserve the internal TEAMAI_ENV_SH_<64-hex> marker namespace. If a team declares such a key, parseEnvFile ignores it as metadata; when it matches the scope’s generated marker, shells receive the digest marker while env exec and MCP receive the declared value. Reserve names matching isEnvShMarker.

The previously reported findings appear resolved. The PR description includes sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/utils/shell-profile.ts:85 installs the loader into only the profile selected by $SHELL. With zsh as the default, an interactive Bash started in project A never sources the loader from .bashrc; after moving to project B it retains A’s environment. The reverse also affects zsh started by a Bash-based setup, allowing cross-project credentials to leak.
  • [P1 blocking] src/mcp-reconcile.ts:217 adds every inherited process variable to MCP substitutions without checking resolved.member. In Bash, cd project-B && teamai pull runs before the prompt routing hook, so the process can still carry project A’s exported TOKEN; if B’s MCP references ${TOKEN} without declaring it, A’s value is written into B’s MCP configuration.
  • [P2 non-blocking] src/env-listing.ts:76 hides resolved inherited values whenever the project’s own secrets.yaml fails. The inherited user-scope part remains active independently, so env exec and MCP receive its value while env list shows only its name rather than the active masked/revealed value.

The previously reported findings appear resolved in the current diff. The PR description documents sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/utils/shell-profile.ts:108 assumes the secondary Bash profile is always .bashrc on POSIX. With SHELL=zsh, an existing ~/.bash_profile that does not source .bashrc receives no loader; bash -l started in project A then ignores BASH_ENV and retains A’s credentials after changing to project B. Select an existing Bash login profile or follow its startup chain before deciding where to install the secondary block.

All previously reported findings appear resolved. The PR description documents sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/utils/shell-profile.ts:111 and src/utils/shell-profile.ts:139 install blocks only into secondary startup files that already exist. With zsh as the default and no ~/.bashrc, bash -i inherits project A’s credentials but never installs the routing hook, so changing to project B retains A’s environment. Likewise, with Bash as the default and no login profile, pull creates only .bashrc; bash -l ignores it and has the same leak. Ensure supported Bash/zsh startup modes receive a loader even when their profile file is initially absent.

The previously reported concrete cases appear resolved. The PR description includes sufficient representative real-CLI and end-to-end testing.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/resources/env.ts:506 disables an existing scope’s shell route whenever resolution fails. After successfully pulling TOKEN=old, corrupt env.yaml and pull again: registration changes the env path to -, so new shells lose TOKEN, while env exec and MCP retain old from the backup. Preserve the last successful route; register as disabled only when no previous delivery exists.

  • [P2 non-blocking] src/resources/env-loader.ts:796 unsets the original variable and restores only its value and export visibility, losing other attributes. After declare -ix PORT=3000, entering and leaving a project restores a plain exported string; PORT=1+1 subsequently produces literal 1+1 instead of integer 2. Save and restore the original declaration attributes.

The last pass’s diagnostic-environment and exported-variable detection findings are resolved.

The PR description includes sufficient representative real-CLI testing. I only read the specified diff; I did not run, build, or install PR code.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/resources/env.ts:506 still disables an existing route when resolution fails. Pull TOKEN=old, corrupt env.yaml, then pull again: new shells lose TOKEN, while env exec and MCP retain old from the backup. Preserve the last successful route; disable only scopes without previous delivery.

  • [P2 non-blocking] src/resources/env-loader.ts:796 still restores only the variable’s value and export visibility, discarding other attributes. After declare -ix PORT=3000, entering and leaving a project restores an exported string; assigning PORT=1+1 produces literal 1+1 rather than integer 2. Save and restore the declaration attributes.

  • [P1 blocking] src/mcp-reconcile.ts:208 still checks secret names case-sensitively on Windows. With member export token=member and resolved team secret TOKEN=team-secret, the process loop inserts token before the secret inserts TOKEN; case-insensitive ${TOKEN} lookup selects the member value. Compare secret names using envName.

The latest diagnostic-environment and exported-variable detection findings are resolved. The PR description includes sufficient representative real-CLI testing; its older recorded commit is not blocking.

I only read the specified diff and trusted base criteria; I did not run, build, or install PR code.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] src/resources/env.ts:512 keeps routing to an unchanged env.sh even when valid secret declarations now exclude one of its exports. Pull user variable TOKEN=old, then declare TOKEN a secret and corrupt the user env.yaml. An inheriting project still sources that stale user file and receives TOKEN, violating “never user secrets”; env exec and MCP correctly exclude it. Remove newly declared secret exports before retaining the route.

  • [P2 non-blocking] src/resources/env-loader.ts:964 sources team assignments while the member’s integer attributes remain active. With declare -ix TOKEN=3 and team value TOKEN='1+1', Bash exports 2, whereas env exec and MCP deliver literal 1+1. Temporarily clear value-coercing attributes during delivery and restore them when leaving.

The latest reported route-preservation, attribute-restoration, and Windows MCP cases are resolved. The PR description documents sufficient representative real-CLI testing.

I only read the specified diff and trusted base criteria; I did not run, build, or install PR code.

bash prints `declare -ix PORT=...` and zsh `export -i PORT=...`, so a
member's exported integer came back unexported after leaving a project.
…IT_*

A tool started from a project shell inherits the project's values; the
check now puts back the member's ones before it runs the loader, so a
project PATH without git no longer reports broken routing.
Keep the per-directory rules and the limits a member runs into; drop the
loader internals and the profile-file selection details, and leave the
README matrix as main has it.
@SaulMoro
SaulMoro force-pushed the fix/env-by-directory branch from 364ba71 to df27477 Compare October 13, 2026 08:38
@github-actions

Copy link
Copy Markdown
  • [P2 non-blocking] src/resources/env-loader.ts:71 restores team values without clearing attributes set by the member’s BASH_ENV. With team TOKEN='1+1' and a member file containing declare -ix TOKEN=3, teamai env exec -- bash -c 'printf "%s\n" "$TOKEN"' receives 2, not literal 1+1. Clear value-coercing attributes before restoring the overlay, as the directory loader now does.

The previously reported secret-filtering and directory-loader attribute-coercion findings are resolved in this diff.

The PR description documents sufficient representative real-CLI testing. I only read the specified diff and trusted base criteria; I did not run, build, or install PR code.

@github-actions

Copy link
Copy Markdown
  • [P2 non-blocking] src/resources/env-loader.ts:1124 sources the member’s BASH_ENV inside __teamai_env_start. In Bash, a file containing declare -ix TOKEN=3 therefore creates a function-local TOKEN; the project’s export updates that local, which disappears when startup returns. A normal bash -c launched from zsh in a project defining TOKEN='1+1' receives no TOKEN when none existed before. Source the member file outside the function, or preserve its declarations globally.

The previously reported findings appear resolved, including the latest env exec shim attribute-coercion case.

The PR description documents sufficient representative real-CLI testing.

I only read the specified diff and trusted base criteria; I did not run, build, or install PR code.

@SaulMoro
SaulMoro requested a review from jeff-r2026 October 13, 2026 09:27
@jeff-r2026
jeff-r2026 merged commit 1ce25ac into Tencent:main Oct 13, 2026
14 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…t#1023)

* fix(env): load each directory's team env through one loader block

Closes Tencent#1018

* fix(env): keep a variable exported when it has other attributes too

bash prints `declare -ix PORT=...` and zsh `export -i PORT=...`, so a
member's exported integer came back unexported after leaving a project.

* fix(doctor): check a directory's env with the member's own PATH and GIT_*

A tool started from a project shell inherits the project's values; the
check now puts back the member's ones before it runs the loader, so a
project PATH without git no longer reports broken routing.

* docs(env): shorten the env-by-directory docs to what a member needs

Keep the per-directory rules and the limits a member runs into; drop the
loader internals and the profile-file selection details, and leave the
README matrix as main has it.

* docs(readme): mark env for Pi, DeepSeek Harness and ZCode through teamai env exec

* fix(env): keep a scope's shell env while its env.yaml cannot resolve

* fix(env): keep a variable's other attributes when leaving a project

* docs(readme): shorten the env exec footnote

* test(mcp): keep one spelling of a secret's name in a server's table on Windows

* fix(env): keep a key now declared a secret out of shells while env.yaml cannot resolve

* fix(env): deliver a team value as written to a variable with an integer or case attribute

* fix(doctor): compare env names as Windows does when checking env.sh

* docs(env): note how a variable's attributes survive a project

* docs(readme): mark Muse Code's rules with the renamed always-on marker

* fix(models): find Muse Code's key block in the zsh startup file the env loader uses

* test(env): expect bash before 4.2 to leave the integer attribute off after a project

* fix(env): deliver a team value as written in env exec when the member's BASH_ENV gives the key an integer or case attribute
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] several project scopes, no user scope: only one project's env block survives, and doctor fails in every other project

3 participants