Skip to content

feat: one namespace model for every resource type (#707) - #816

Merged
jeff-r2026 merged 53 commits into
Tencent:mainfrom
SaulMoro:feat-707-namespace-scoping
Sep 25, 2026
Merged

jeff-r2026 merged 53 commits into
Tencent:mainfrom
SaulMoro:feat-707-namespace-scoping

Conversation

@SaulMoro

@SaulMoro SaulMoro commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Every resource type now scopes to roles and projects in the same way: files under <type>/<ns>/ in the team repo, declared in resources:. A namespace item replaces the root item with the same name.

 team repo
   <type>/            root, shared
   <type>/<ns>/       only where <ns> is active (role ∪ project)
 env/env.yaml
-  - key: DB_URL
-    projects: [checkout]          # per-entry scoping, removed
+env/checkout/env.yaml             # checkout's value replaces the root one
 manifest/projects.yaml
   resources:
     agents: [checkout]
+    env: [checkout]               # also hooks, mcp, models, docs
namespace vs root        namespace wins, whole item
namespace vs namespace   error when both compete for one slot; that type is skipped this run, installed state kept
broken active file       that type is skipped this run, installed state kept
Type Override key Notes
env / hooks / mcp key / hook / server name new axes; legacy mode reads the root file only
models profile id API key bound to the gateway origin
skills name root stays the tag catalog in role/project mode
agents stem root + namespace is no longer an error
rules / claudemd first-level file name two namespaces with one name are both delivered (no shared slot)
docs / learnings none each namespace is its own subtree; ids never collide

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Breaking changes: per-entry projects: (env/hooks/MCP) and roles: on env existed only in the 0.26.0 betas and are removed. An entry that still has one reaches nobody, and the warning names its target file. roles: on hooks/MCP, which shipped in 0.25.0, keeps filtering for one minor, with a warning in pull and a doctor check.

Test Plan

  • npx tsc --noEmit passes
  • npx vitest run passes: 313 files, 4863 passed, 1 skipped
  • npm run test:e2e passes: 51 files, 265 passed, 26 skipped (live-provider suites)
  • Added/updated tests for the change, plus fast-check property tests on the namespace resolver

Real CLI (dist/), checkout overriding API_BASE and MCP server db:

$ teamai pull --force              env.sh: API_BASE='https://api.company.test'   mcp db: https://db.company.test/mcp
$ teamai projects set checkout
$ teamai pull --force              env.sh: API_BASE='https://api.checkout.test'  mcp db: https://db.checkout.test/mcp
$ teamai doctor
  ℹ env: "API_BASE" from env/checkout/env.yaml replaces env/env.yaml
  ℹ mcp: "db" from mcp/checkout/mcp.yaml replaces mcp/mcp.yaml
$ teamai projects set
$ teamai pull --force              env.sh: API_BASE='https://api.company.test'   mcp db: https://db.company.test/mcp

Real CLI, first pull with a broken hooks/hooks.yaml:

$ teamai pull --force
  ⚠ hooks/hooks.yaml does not parse: … hooks was not applied this run, so your installed team hooks are unchanged. Fix the file in the team repo and push.
  ✔ Updated teamai hooks in ~/.claude/settings.json        # built-in hooks still installed
  ⚠   ✖ Team hooks can be resolved

Real CLI, teamai remove mcp db with a broken mcp/mcp.yaml and db in mcp/checkout/mcp.yaml:

before  ℹ db is checkout/db   ✔ Removed 1 mcp   exit 0, removal branch pushed
after   ✖ Cannot tell which MCP file defines "db": mcp/mcp.yaml does not parse. Fix it in the team repo, or pass --role <ns> or --project <id> to name the file.
        ✖ Nothing was removed.   exit 1, no branch

Real CLI, devops member with the root review skill; the member adds front-only.md, a path skills/frontend/review/ also has, then pulls:

before  front-only.md: DELETED
after   ⚠ Kept ~/.claude/skills/review/front-only.md: another team version of this skill has a file at that path with different content, so it may be yours or an edited copy. Delete it if you do not need it.
        front-only.md: my own notes

Real CLI, teamai env add NEW_KEY x --role checkout on an env/checkout/env.yaml written as a plain KEY: value mapping:

before  ✔ Added env variable in env/checkout/env.yaml: NEW_KEY=x    file now holds NEW_KEY alone; API_BASE and DB_URL gone
after   ✖ …/env/checkout/env.yaml declares no variables. Its top-level key must be `variables:` … Nothing was changed.    exit 1, file unchanged

Real CLI, devops member with the root review skill; the team then adds skills/devops/review/notes.md with no SKILL.md:

before  installed review/: notes.md          (SKILL.md removed; doctor: "delivered but unreadable: review")
after   ⚠ skills/devops/review has no SKILL.md, so it is not delivered as a skill. Add SKILL.md to it in the team repo, or remove it.
        installed review/: SKILL.md

Same setup, teamai --dry-run push --all with the root skill unedited:

before  1. [skills] review (modified)   to: skills/devops/review
after   ℹ No new or modified resources to push
Case Before After
invalid mcp.yaml / hooks.yaml every managed entry removed nothing removed; that type is skipped, with a warning
skill clash between two namespaces whole scope aborted only skills skipped; agents, rules and env still sync
root env.yaml removed or emptied old env.sh stays exported env.sh rewritten from what still applies
remove mcp <name> while an MCP file does not parse removes the one readable namespace copy removes nothing, names the file
remove mcp <name> --project <id> on a file that does not parse Not found (skipping) names the file, exit 1
env add / env remove on an env file that does not parse file rewritten with only the edited variable refused, file unchanged, exit 1
env add / env remove --project after a failed pull edits the namespace a stale projects.yaml names refused, exit 1 (root and --role still only warn)
namespace skill dir without SKILL.md replaces the root skill; installed SKILL.md removed not a skill: root skill still delivered, dir named
namespace agent file that does not parse root agent removed, nothing delivered root agent stays installed

Related Issues

Closes #707. Spec, tickets and design decisions: #707 (comment)

Notes for Reviewers

Door: two-way for code. It is one-way for teams that declare the new axes, because 0.25.0 and the betas reject unknown resources: keys and those members' pull breaks. Upgrade every member first (CHANGELOG says so). From this version on, an unknown key only warns. The new axes are .optional(), so saving a manifest never writes env: [].

Blast radius: broad. Pull, push, doctor, recall and the env / remove mcp commands, across every resource type.

Decisions made after the spec, where the code differs from it:

  • Skill install removes only files that are byte for byte another team version's file at that path. Files a member added or edited survive, and one at a path another version has is named on each pull.
  • Shared content meant to be overridable lives at the root (rules/x.md), not in rules/common/, because common is just another namespace.
  • Legacy mode (no roles, no projects) is unchanged. Agents still reject stem clashes, skills stay last-wins with a doctor note, and env/hooks/MCP read the root file only. So a member with no role stops receiving role-scoped hooks/MCP once the admin moves them into <type>/<ns>/.
  • Model API keys are stored as team:<id>@<origin>, for root profiles as well. When a gateway host changes, the member runs teamai models switch team:<id> once. A beta key is bound once to the origin it was last sent to. Models exist only in the betas.
  • A bare remove mcp <name> removes the root server even while an active namespace overrides it. Members of that namespace keep their override; everyone else loses the server.
  • Docs (merged with fix(docs): remove stale local documents during pull #817's mirror): the local docs dir mirrors only this member's resolved set. A team doc of an inactive namespace is removed when unchanged and kept with a warning when edited. Local-only files are pruned everywhere, as fix(docs): remove stale local documents during pull #817 does.
  • team-codebase cannot be a docs namespace. Directory names match case-insensitively.
  • A hooks resolve failure also skips the built-in hooks for that run, because their builtin: overrides live in the root file.

An adversarial pass with the CI Codex review prompt (1 P1, 5 P2, 4 P3) is fixed. The main fixes:

  • If team hooks do not resolve, the built-in hooks are still installed, with the root file's builtin: overrides when that file parses.
  • roles/projects saves keep unknown resources: keys.
  • doctor fails a check when team hooks or model profiles do not resolve.
  • A replaced root rule is also withdrawn from the shared rule dirs (JoyCode, OMP, Pi, Copilot).

The CI Codex review on this PR (3 P1) is fixed, each with a test that failed first:

  • recall, contribute and pull index the rules pull delivers (ruleFiles, like docFiles), not all of rules/. A replaced root rule and the rules of inactive namespaces are no longer returned. Rules the member's tags leave out are not indexed either, as for skills.
  • env add|remove and remove mcp with --role / --project write to the existing directory the namespace matches case-folded, which is the file pull reads. Before, on Linux, --project checkout created env/checkout/, which shadowed env/Checkout/.
  • A bare remove mcp <name> that the root file does not define removes nothing while any MCP file does not parse.
  • Found while fixing that: --role / --project naming a file that does not parse now says so, instead of reporting the server as not found.

The Codex review of c0a51d5 posted only its opening line, so the same prompt was run locally (read-only) on that head. It confirmed the three P1s resolved and raised one P2, fixed with a test that failed first: skill install deleted a member-added file whenever another version of the skill had a file at that path, even in a namespace the member never had.

The CI Codex review of 8169268 (2 P1) is fixed, with tests that failed first: env add|remove no longer rewrite an env file that does not parse (this predates the PR for env/env.yaml; the PR extends it to namespace files), and --project changes nothing when the team repo cannot be refreshed.

The CI Codex review of c8fc79b (2 P1) is fixed, with tests that failed first: an unusable namespace item no longer replaces the root one. A skill directory without SKILL.md is left out of the desired set, so it neither replaces the root skill nor strips the installed SKILL.md. While a namespace agent file cannot be read or parsed, cleanup keeps the root agent it would replace.

The Codex review of 6c7df8e timed out (15-minute job limit), so its prompt was run locally, read-only, on that head. It raised one P1, a regression of that commit, now fixed with a test that failed first: push still mapped a skill to a namespace directory without SKILL.md, so an unedited root skill showed as modified and push would publish it there. Two P3s are fixed too: the agent cleanup guard now spares only the replaced root agent, and a doc comment went back on its function.

Left for follow-up issues (#822): local-edit protection on pull; mistyped per-entry keys are silently dropped; pull --dry-run shows no hooks/MCP warnings; a tagged skill that exists only in an inactive namespace still reaches the member; recall prints a Chinese footer.

…esolver (Tencent#707)

Add src/namespace-resolver.ts, the pure rule tickets 02-05 build on: an
active namespace item replaces the root item of the same name, and a name
twice in one place or in two active namespaces is a tagged conflict naming
both sources. The result depends only on the active order, not read order.

Agents and skills now run their duplicate checks through it and throw the
same messages. Agents still treat root + namespace as an error.

Add fast-check for the resolver's property tests.
…encent#707)

env/<ns>/env.yaml, hooks/<ns>/hooks.yaml and mcp/<ns>/mcp.yaml are read where
<ns> is active in resources.env/hooks/mcp; a namespace entry replaces the root
entry of the same key, hook id or server name. A broken active file, a name
twice in one file or in two active namespaces stops that type for the run and
keeps what is installed. Per-entry projects: (and roles: on env) reach nobody;
roles: on hooks and MCP keeps filtering with a deprecation warning. Unknown
resources: keys warn instead of failing the manifest.
…ills, agents, rules and claudemd (Tencent#707)

With a role or project configured, an item in an active namespace now
replaces the root item of the same name, whole:

- agents by stem: root + namespace is no longer a duplicate error, and a
  recorded (placed) agent replaces the root agent too
- skills by name, including a root skill received through a tag; an
  install removes the files of the version it replaces
- rules by first-level file name, in tool dirs and Hermes' SOUL.md block
- claudemd files by name in the managed block

Two active namespaces with one rule or claudemd name stop that type for
the run and keep what is installed. Push writes an edited overridden
skill, agent or rule back to its namespace, and the skills push scan
covers role and project namespaces. The placement record is withdrawn
by a same-name shared-root file only in legacy mode. Recall indexes the
skills pull delivers. doctor lists overrides, and in legacy mode repeated
names, as notes. Legacy mode is otherwise unchanged.
Tencent#707)

Rules and claudemd have no namespace-vs-namespace conflict: each
namespace rule keeps its own local path and each claudemd file its own
place in the block, so two active namespaces with one first-level name
are both delivered, as before. Only root suppression applies.

doctor override and legacy repeated-name notes now use the same wording
as the env, hooks and MCP ones. The usage guide and admin reference say
to keep overridable shared content at the root, with an example.
…nt#707)

Two active namespaces with one skill name or agent stem used to throw
and abort the whole scope, so rules, env, docs, cleanup and the search
index were skipped too. resolveDesiredSkills, resolveDesiredAgents,
scanRoleAwareSkills and filterAgentsByNamespaces now return a tagged
conflict. pull warns, leaves that type as installed (no install, no
inactive-namespace sweep) and syncs the rest. doctor reports the
collision as before; recall indexes no skills while it stands.
…ocs (Tencent#707)

env add/remove take --role/--project; remove mcp searches every file and asks
for --role/--project when several define the name; push picks up
env/<ns>/env.yaml. status, list and doctor show where each entry comes from;
doctor lists overrides as notes and per-entry roles:/projects: as one
informational check. Usage guides and the admin skill reference describe the
namespace files; the Tencent#668 e2e moves onto them.
…nch (Tencent#707)

Merges impl-707-02 (ticket 02) onto tickets 01 and 04. doctor keeps one
notes channel: item overrides, then entry overrides, then the Codex
reminder. The usage guide's doctor paragraph now names env, hook and MCP
notes too.
…ent#707)

remove mcp <name> follows push's convention: mcp/mcp.yaml when it defines the
name, else the one namespace file that does; --role/--project pick a namespace.
Only a name several namespace files (and not the root) define is refused.
…Tencent#707)

A docs/<ns>/ that any role or project lists under resources.docs now
reaches only members with that namespace active; an undeclared
docs/<dir>/ stays shared. Leaving a namespace removes its local docs that
are byte-equal to the team copy and keeps edited ones with a line.
team-codebase is rejected as a docs namespace. The search index (pull,
recall, contribute) and doctor's "Team docs delivered" use the same set.
… their gateway (Tencent#707)

models/<ns>/models.yaml, declared under resources.models, replaces the root
profile with the same id while <ns> is active. A team API key is stored per
profile id and base_url origin, so pull never writes a key next to a gateway
on another origin; it prints the models switch line instead. Conflicts and
broken files stop model updates for the run. models list and doctor show
where each profile comes from; push validates every models file.
Rewrite the multi-project design doc's precedence section for
namespace-over-root, add the per-type conflict, failure and legacy-mode
rules, and replace the per-entry key rows in the product overview. The
JSON doctor notes now also carry namespace notes.
…ent#707)

Drop the beta-only per-entry projects: entry, add the namespace axes,
the override, the per-type failure policy, the roles: deprecation on
hooks and MCP, and the upgrade-every-member-first note.
Tencent#707)

Namespace fallback warnings, entry notices and unknown resources: keys
now go through utils/warn-once, reset once per pull, so the quiet option
threaded through eleven signatures is gone. The one-line wrappers
resolveTeamEnv, resolveTeamMcpServers and resolveTeamProfiles are removed;
every caller uses resolveEntries/resolveEntriesFor with the type's reader.
…ew code (Tencent#707)

- listEntryFiles/entryFileAbsolutePath replace the per-type file listers
  in env, mcp and models and the repeated path joins.
- gatewaySuffix replaces three spellings of the gateway suffix.
- LATER_RESOURCE_TYPES and friends are named for what they are:
  HAND_DECLARED_RESOURCE_TYPES, HandDeclaredNamespacesShape.
- Error messages use instanceof Error; manifest role/project ids are
  narrowed instead of cast; mapResources builds a typed object; pull
  writes env through an EnvHandler instance instead of a cast.
- status keys counts by entry type; rules localNameFor reuses
  deliversEveryNamespace, whose false answer is now documented.
…cent#707)

Commands must stay thin, and recall, contribute and doctor imported
pull.js only to learn what a member receives. The skills, agents, rules
and claudemd resolvers, RolePullContext and the index sources now live in
src/resources/desired.ts; root suppression, the override note and the
repeated-name grouping live in namespace-resolver.

- A skill or agent conflict is a tagged DeliveryConflict carrying the
  resolver's NamespaceConflict, rendered once by describeDeliveryConflict
  (wording unchanged); DesiredItems names the result union.
- DesiredItems keeps each override, so doctor no longer rebuilds skill
  and agent overrides by hand.
- recall and contribute share deliveredIndexSources; pull indexes through
  the same indexedSkills instead of a second copy.
- doctor: one unresolvableCheck for skills, agents and docs; the docs
  check reports an unreadable manifest instead of returning nothing; the
  namespace notes catch only the team-repo reads.
- docs withdrawal reuses utils pruneEmptyDirs.
Story 8 asks for a message naming both files. A skill or agent conflict
named only the namespaces, and an agent defined twice inside one
namespace (agents/a/x.md next to agents/a/x.yaml) read as 'found in
active namespaces "a" and "a"'. The duplicate case now names its one
place, and both cases list the two files.
…n every tool (Tencent#707)

- The rules override ran before the tag filter, so a namespace rule the
  member's tag subscription excludes still suppressed the root rule and
  the member received neither. The tag filter now runs first.
- JoyCode, OMP, Pi and Copilot share their rule directory with the
  member's own rules, so the stale sweep deletes nothing there unless a
  tombstone names it: the root rule a namespace rule replaced stayed
  installed and both versions loaded (story 6). pullAllRules now removes
  such a copy while it is byte-equal to its render, as agents do.
…em (Tencent#707)

On a skills conflict pull keeps the installed skills, but the index was
rebuilt with none, so recall returned none of the skills the member still
has. The index now keeps the skills entries it already held, and pull
does the same when resolving the skills fails.
… not resolve (Tencent#707)

reconcileTeamHooksForConfig returned [] when the team hooks could not be
resolved, the same value as a team without hooks, so hooks inject printed
'Hooks injected into all AI tool settings' and exited 0 over a broken
hooks/<ns>/hooks.yaml. It now returns { ok: false }, and hooks inject
exits 1 after the warning that names the file. mcp inject said 'Already
up to date.' in the same case; the MCP reconcile now marks the result
unresolved and mcp inject exits 1.
…encent#707)

- A key a 0.26.0 beta stored under team:<id> counted for whatever origin
  the root profile had now, so a root profile moved to another host got
  the old key written next to it. The first pull or models command that
  reads such a key now binds it to the origin TeamAI last wrote into the
  agents switched to that profile (the root's current origin when it is
  among them), else to the root's current origin, and never re-reads the
  unbound key. Pull then leaves a moved agent alone and asks for the
  switch.
- The 'switch to set a key' and 'no longer active' lines are written to
  debug.log too: SessionStart pulls run silent.
- Legacy mode, which reads no namespace, says a profile 'was removed'.
- A models command whose profiles do not resolve reports it with
  log.error and exit code 1, as env list and mcp list do, instead of
  throwing.
…s: working (Tencent#707)

0.25.0 let hooks.yaml and mcp.yaml repeat a hook or server name under
different roles:, delivering every copy that passed the role filter (MCP
kept the last). The namespace resolver treated that as a duplicate, so a
member holding both roles, or a role-less member in a team with
projects.yaml, stopped receiving hooks or MCP entirely. During the
roles: deprecation window such a repeat is delivered as in 0.25; a name
repeated without roles: on every copy is still a duplicate.

Also restores the test that the role filter runs before
requireTeamScripts, so the transparency print lists only what will run.
)

The spec asks doctor, like status and the list commands, to show each
entry's namespace; doctor listed overrides only. For env, hooks, MCP and
models, a namespace contributing any entry now adds a note counting the
entries by origin, 'env: 3 received here (2 root, 1 checkout)', from the
describeOrigins that status uses.
…in: in a namespace file (Tencent#707)

Seam 1 asks every type to show, through pull, that two active namespaces
defining one name keep the installed state and name both files. Env and
hooks were covered only through doctor and the handler; so was the
warning for builtin: in a namespace hooks file.
…mai push (Tencent#707)

manage-admin.md told admins to publish hooks/MCP file edits with
teamai push, which sweeps only rules/, env/ and .codebuddy-plugin/, so
an agent following it would push nothing. It now says to commit and
push the file with git, as the usage guide does.
…me a kept copy (Tencent#707)

In the JoyCode, OMP, Pi and Copilot rule dirs, a replaced root rule's
copy was removed only while it matched the current root rule. When the
admin edited the root rule and added its namespace override in one push,
the member's unedited copy stayed loaded beside the override, silently.
It is now also compared with the render at the last pull, and a copy
that is kept is named with the fix.
…solve (Tencent#707)

teamai status counts such a type as 0 and says to run doctor, but doctor
had failing checks only for env and MCP, so a duplicate hook id or a
two-namespace clash showed nothing there.
…t#707)

env add/remove --role <ns> wrote env/<ns>/env.yaml for a namespace no
role or project lists under resources.env, so the variable reached
nobody and nothing said so. The same applies to remove mcp --role.
…n push (Tencent#707)

git ls-files quotes such a path by default, so it never matched the name
on disk and push skipped the change.
… read stops the type (Tencent#707)

The readers folded every read error into 'file does not exist', so an
unreadable namespace file silently delivered the root entry in place of
its override. Only ENOENT is absence now; any other error is a broken
file, like one that does not parse.
…lded, as docs does (Tencent#707)

A declared namespace was joined onto the path as written, so with
env: [checkout] and a directory env/Checkout/, macOS and Windows members
got the override and Linux members the root value.
…ncent#707)

listFilesRecursive always joins with '/', so on Windows every path was
one segment and a claudemd/<ns>/x.md beside claudemd/x.md was never
reported.
@jeff-r2026 jeff-r2026 self-assigned this Sep 25, 2026
@jeff-r2026
jeff-r2026 self-requested a review September 25, 2026 03:49
@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/desired.ts:310 — Recall only resolves member-specific docs and skills; pull, recall, and contribute still pass the entire rules/ directory to buildIndex. With rules/checkout/style.md replacing rules/style.md, recall indexes both versions—and also inactive namespaces—so it can return rules this member was not delivered. Resolve and pass the same rule set used by resolveDesiredRules.
  • [P1 blocking] src/namespaced-entries.ts:521 — Namespace reads are case-folded, but write targeting returns the flag/manifest spelling unchanged. On a case-sensitive filesystem, a project declaring checkout with an existing env/Checkout/env.yaml will cause env add --project checkout to create env/checkout/env.yaml; the exact-match reader then shadows the original file and its variables disappear from delivery. Resolve an existing case-fold-equivalent directory before returning the write namespace.
  • [P1 blocking] src/remove.ts:148 — MCP discovery skips files that fail parsing, but bare-name removal then treats the remaining candidate as authoritative. If malformed mcp/mcp.yaml contains db and valid mcp/checkout/mcp.yaml also contains db, teamai remove mcp db removes the checkout server instead of refusing because the preferred root file is unreadable. Any unreadable candidate file must make automatic target selection fail closed.

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

…Tencent#707)

A namespace rule replaces the root rule of its name, but recall, contribute
and pull indexed every file under rules/: the replaced root rule and the rules
of inactive namespaces came back from recall. Index the resolved rule set, as
docs and skills already do.
… from (Tencent#707)

Pull matches a declared namespace to its directory case-folded, but --role and
--project returned the spelling typed. On a case-sensitive filesystem
`env add --project checkout` created env/checkout/, which shadowed
env/Checkout/ and dropped its variables from delivery.
…es not parse (Tencent#707)

The team scan skips a file that does not parse. With mcp/mcp.yaml broken,
`remove mcp db` took the one readable checkout/db as the target and removed
it. Refuse and name the file unless the readable root defines the name.
…e, not that the name is missing (Tencent#707)

The team scan skips a file that does not parse, so `remove mcp db --project
checkout` with a broken mcp/checkout/mcp.yaml reported "Not found". Name the
file and remove nothing.
@github-actions

Copy link
Copy Markdown

I’ll inspect the exact PR diff without executing any project code, then trace the changed paths for concrete regressions and verify the earlier findings are resolved. Since the requested comparison is already available locally, I’ll use read-only Git commands only.

…matches that version (Tencent#707)

Install removed any installed file at a path another team version of the skill
has, by path alone. A file a member added under that name, e.g. README.md
beside a namespace they never had, was deleted on every pull. Remove it only
when it is byte for byte that version's file; keep any other and name it.
@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/env-commands.ts:83 — After pullRepo fails, env add/remove --project continues and resolves the destination using a potentially stale manifest/projects.yaml. If the project’s env namespace changed remotely, the command edits or deletes from the old namespace and a later push can publish the wrong file. Abort when refresh fails if --project is used.
  • [P1 blocking] src/env-commands.ts:92 — parseEnvYaml() converts any malformed target file into { variables: [] }. Therefore env add --role/--project against an invalid existing namespace file overwrites its entire contents with the new variable. Read via readEnvYaml() and refuse to write when parsing fails.

The three findings from the earlier review are resolved in the current diff. The PR description includes sufficient representative real-CLI and automated testing.

…et after a failed refresh (Tencent#707)

env add and env remove read the target through parseEnvYaml, which answers an
empty list for a file that does not parse, then wrote that back: every
variable the file had was replaced. They now refuse and name the file.

--project resolves through manifest/projects.yaml. After a failed pull that
copy may be stale and name a namespace the project no longer uses, whose file
push would publish, so --project now changes nothing then. The root file and
--role do not depend on the manifest and still only warn.
@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] src/resources/agents.ts:815 — An invalid active namespace agent can delete the valid root agent it supposedly replaces. For example, with a deployed root review.yaml and malformed agents/checkout/review.yaml, delivery skips the malformed file, but cleanup sees the root as inactive and removes its unchanged deployed copy because the malformed replacement produced no active destination. Validate/render replacements before suppressing or deleting the root.
  • [P1 blocking] src/resources/skills.ts:703 — A malformed namespace skill can destroy the previously deployed root version. If skills/checkout/review/ lacks a readable SKILL.md, copyDir overlays that directory, removeLeftoverVersionFiles deletes the root version’s matching SKILL.md, and ensureSkillFrontmatter silently returns false; pull still reports the skill as synced. Reject invalid replacement skills before copying or preserve the installed version.

The five findings from earlier review passes are resolved in the current diff. The PR description includes sufficient automated and representative real-CLI testing.

…nt#707)

A skill directory without SKILL.md replaced the root skill of its name:
install overlaid it and removed the installed SKILL.md as the other version's
leftover, while pull still counted the skill as synced. Such a directory is
no longer a skill; pull names it and keeps delivering the root one.

An agent file that does not parse delivers nothing, yet it still replaced the
root agent, and cleanup removed the unchanged root copy because no active
destination held that stem. The root agent now stays while its replacement
cannot be read or parsed.
…s skill (Tencent#707)

Pull stopped delivering such a directory in 6c7df8e, but the push scan still
mapped the skill name to it. An unedited root skill then showed as modified,
and push wrote it into skills/<ns>/<name>/, deleting what was there and making
it a namespace skill that replaces the root one.

Also keep only a replaced root agent while its replacement does not parse, so
an unchanged copy from an inactive namespace is still removed, and put
renderedForTool's doc comment back on it.
@github-actions

Copy link
Copy Markdown

Findings

  • No new findings.

All seven findings from earlier review passes are resolved in the current diff. The PR description documents sufficient automated testing and representative real-CLI verification.

@jeff-r2026
jeff-r2026 merged commit 21cb76a into Tencent:main Sep 25, 2026
10 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…ent#816)

* chore: start one namespace model for every resource type (Tencent#707)

* refactor(pull): check agent and skill namespace collisions with one resolver (Tencent#707)

Add src/namespace-resolver.ts, the pure rule tickets 02-05 build on: an
active namespace item replaces the root item of the same name, and a name
twice in one place or in two active namespaces is a tagged conflict naming
both sources. The result depends only on the active order, not read order.

Agents and skills now run their duplicate checks through it and throw the
same messages. Agents still treat root + namespace as an error.

Add fast-check for the resolver's property tests.

* feat(env,hooks,mcp): scope env, hooks and MCP servers by namespace (Tencent#707)

env/<ns>/env.yaml, hooks/<ns>/hooks.yaml and mcp/<ns>/mcp.yaml are read where
<ns> is active in resources.env/hooks/mcp; a namespace entry replaces the root
entry of the same key, hook id or server name. A broken active file, a name
twice in one file or in two active namespaces stops that type for the run and
keeps what is installed. Per-entry projects: (and roles: on env) reach nobody;
roles: on hooks and MCP keeps filtering with a deprecation warning. Unknown
resources: keys warn instead of failing the manifest.

* feat(pull): let an active namespace item replace the root item for skills, agents, rules and claudemd (Tencent#707)

With a role or project configured, an item in an active namespace now
replaces the root item of the same name, whole:

- agents by stem: root + namespace is no longer a duplicate error, and a
  recorded (placed) agent replaces the root agent too
- skills by name, including a root skill received through a tag; an
  install removes the files of the version it replaces
- rules by first-level file name, in tool dirs and Hermes' SOUL.md block
- claudemd files by name in the managed block

Two active namespaces with one rule or claudemd name stop that type for
the run and keep what is installed. Push writes an edited overridden
skill, agent or rule back to its namespace, and the skills push scan
covers role and project namespaces. The placement record is withdrawn
by a same-name shared-root file only in legacy mode. Recall indexes the
skills pull delivers. doctor lists overrides, and in legacy mode repeated
names, as notes. Legacy mode is otherwise unchanged.

* fix(pull): deliver both namespace rules and claudemd files of one name (Tencent#707)

Rules and claudemd have no namespace-vs-namespace conflict: each
namespace rule keeps its own local path and each claudemd file its own
place in the block, so two active namespaces with one first-level name
are both delivered, as before. Only root suppression applies.

doctor override and legacy repeated-name notes now use the same wording
as the env, hooks and MCP ones. The usage guide and admin reference say
to keep overridable shared content at the root, with an example.

* fix(pull): stop only skills or agents on a namespace collision (Tencent#707)

Two active namespaces with one skill name or agent stem used to throw
and abort the whole scope, so rules, env, docs, cleanup and the search
index were skipped too. resolveDesiredSkills, resolveDesiredAgents,
scanRoleAwareSkills and filterAgentsByNamespaces now return a tagged
conflict. pull warns, leaves that type as installed (no install, no
inactive-namespace sweep) and syncs the rest. doctor reports the
collision as before; recall indexes no skills while it stands.

* feat(env,hooks,mcp): namespace flags, origins in status and doctor, docs (Tencent#707)

env add/remove take --role/--project; remove mcp searches every file and asks
for --role/--project when several define the name; push picks up
env/<ns>/env.yaml. status, list and doctor show where each entry comes from;
doctor lists overrides as notes and per-entry roles:/projects: as one
informational check. Usage guides and the admin skill reference describe the
namespace files; the Tencent#668 e2e moves onto them.

* test(env): show a broken env file stops env only (Tencent#707)

* fix(remove): remove an MCP server from the root file by default (Tencent#707)

remove mcp <name> follows push's convention: mcp/mcp.yaml when it defines the
name, else the one namespace file that does; --role/--project pick a namespace.
Only a name several namespace files (and not the root) define is refused.

* test(remove): expect namespace files in sorted order (Tencent#707)

* feat(docs): deliver a declared docs namespace only where it is active (Tencent#707)

A docs/<ns>/ that any role or project lists under resources.docs now
reaches only members with that namespace active; an undeclared
docs/<dir>/ stays shared. Leaving a namespace removes its local docs that
are byte-equal to the team copy and keeps edited ones with a line.
team-codebase is rejected as a docs namespace. The search index (pull,
recall, contribute) and doctor's "Team docs delivered" use the same set.

* feat(models): scope team model profiles by namespace and bind keys to their gateway (Tencent#707)

models/<ns>/models.yaml, declared under resources.models, replaces the root
profile with the same id while <ns> is active. A team API key is stored per
profile id and base_url origin, so pull never writes a key next to a gateway
on another origin; it prints the models switch line instead. Conflicts and
broken files stop model updates for the run. models list and doctor show
where each profile comes from; push validates every models file.

* docs(models): describe model profiles by namespace and key binding (Tencent#707)

* docs: list docs among the axes declared by hand (Tencent#707)

* docs: describe one namespace model for every resource type (Tencent#707)

Rewrite the multi-project design doc's precedence section for
namespace-over-root, add the per-type conflict, failure and legacy-mode
rules, and replace the per-entry key rows in the product overview. The
JSON doctor notes now also carry namespace notes.

* docs(changelog): replace per-entry scoping with namespace files (Tencent#707)

Drop the beta-only per-entry projects: entry, add the namespace axes,
the override, the per-type failure policy, the roles: deprecation on
hooks and MCP, and the upgrade-every-member-first note.

* docs(changelog): say the model key binding re-keys once and affects only betas (Tencent#707)

* refactor(namespaces): one warn-once registry instead of the quiet flag (Tencent#707)

Namespace fallback warnings, entry notices and unknown resources: keys
now go through utils/warn-once, reset once per pull, so the quiet option
threaded through eleven signatures is gone. The one-line wrappers
resolveTeamEnv, resolveTeamMcpServers and resolveTeamProfiles are removed;
every caller uses resolveEntries/resolveEntriesFor with the type's reader.

* refactor(namespaces): shared entry-file helpers, no unsafe casts in new code (Tencent#707)

- listEntryFiles/entryFileAbsolutePath replace the per-type file listers
  in env, mcp and models and the repeated path joins.
- gatewaySuffix replaces three spellings of the gateway suffix.
- LATER_RESOURCE_TYPES and friends are named for what they are:
  HAND_DECLARED_RESOURCE_TYPES, HandDeclaredNamespacesShape.
- Error messages use instanceof Error; manifest role/project ids are
  narrowed instead of cast; mapResources builds a typed object; pull
  writes env through an EnvHandler instance instead of a cast.
- status keys counts by entry type; rules localNameFor reuses
  deliversEveryNamespace, whose false answer is now documented.

* refactor(desired): move the desired-set resolvers out of pull.ts (Tencent#707)

Commands must stay thin, and recall, contribute and doctor imported
pull.js only to learn what a member receives. The skills, agents, rules
and claudemd resolvers, RolePullContext and the index sources now live in
src/resources/desired.ts; root suppression, the override note and the
repeated-name grouping live in namespace-resolver.

- A skill or agent conflict is a tagged DeliveryConflict carrying the
  resolver's NamespaceConflict, rendered once by describeDeliveryConflict
  (wording unchanged); DesiredItems names the result union.
- DesiredItems keeps each override, so doctor no longer rebuilds skill
  and agent overrides by hand.
- recall and contribute share deliveredIndexSources; pull indexes through
  the same indexedSkills instead of a second copy.
- doctor: one unresolvableCheck for skills, agents and docs; the docs
  check reports an unreadable manifest instead of returning nothing; the
  namespace notes catch only the team-repo reads.
- docs withdrawal reuses utils pruneEmptyDirs.

* fix(pull): name both files in a skill or agent conflict (Tencent#707)

Story 8 asks for a message naming both files. A skill or agent conflict
named only the namespaces, and an agent defined twice inside one
namespace (agents/a/x.md next to agents/a/x.yaml) read as 'found in
active namespaces "a" and "a"'. The duplicate case now names its one
place, and both cases list the two files.

* fix(rules): only a delivered namespace rule replaces the root rule, in every tool (Tencent#707)

- The rules override ran before the tag filter, so a namespace rule the
  member's tag subscription excludes still suppressed the root rule and
  the member received neither. The tag filter now runs first.
- JoyCode, OMP, Pi and Copilot share their rule directory with the
  member's own rules, so the stale sweep deletes nothing there unless a
  tombstone names it: the root rule a namespace rule replaced stayed
  installed and both versions loaded (story 6). pullAllRules now removes
  such a copy while it is byte-equal to its render, as agents do.

* fix(recall): keep the indexed skills while a skills conflict holds them (Tencent#707)

On a skills conflict pull keeps the installed skills, but the index was
rebuilt with none, so recall returned none of the skills the member still
has. The index now keeps the skills entries it already held, and pull
does the same when resolving the skills fails.

* fix(hooks,mcp): fail hooks inject and mcp inject when team entries do not resolve (Tencent#707)

reconcileTeamHooksForConfig returned [] when the team hooks could not be
resolved, the same value as a team without hooks, so hooks inject printed
'Hooks injected into all AI tool settings' and exited 0 over a broken
hooks/<ns>/hooks.yaml. It now returns { ok: false }, and hooks inject
exits 1 after the warning that names the file. mcp inject said 'Already
up to date.' in the same case; the MCP reconcile now marks the result
unresolved and mcp inject exits 1.

* fix(models): bind a beta API key to the gateway it was sent to, once (Tencent#707)

- A key a 0.26.0 beta stored under team:<id> counted for whatever origin
  the root profile had now, so a root profile moved to another host got
  the old key written next to it. The first pull or models command that
  reads such a key now binds it to the origin TeamAI last wrote into the
  agents switched to that profile (the root's current origin when it is
  among them), else to the root's current origin, and never re-reads the
  unbound key. Pull then leaves a moved agent alone and asks for the
  switch.
- The 'switch to set a key' and 'no longer active' lines are written to
  debug.log too: SessionStart pulls run silent.
- Legacy mode, which reads no namespace, says a profile 'was removed'.
- A models command whose profiles do not resolve reports it with
  log.error and exit code 1, as env list and mcp list do, instead of
  throwing.

* fix(entries): keep 0.25 files that repeat a name under different roles: working (Tencent#707)

0.25.0 let hooks.yaml and mcp.yaml repeat a hook or server name under
different roles:, delivering every copy that passed the role filter (MCP
kept the last). The namespace resolver treated that as a duplicate, so a
member holding both roles, or a role-less member in a team with
projects.yaml, stopped receiving hooks or MCP entirely. During the
roles: deprecation window such a repeat is delivered as in 0.25; a name
repeated without roles: on every copy is still a duplicate.

Also restores the test that the role filter runs before
requireTeamScripts, so the transparency print lists only what will run.

* feat(doctor): say where each entry type's entries come from (Tencent#707)

The spec asks doctor, like status and the list commands, to show each
entry's namespace; doctor listed overrides only. For env, hooks, MCP and
models, a namespace contributing any entry now adds a note counting the
entries by origin, 'env: 3 received here (2 root, 1 checkout)', from the
describeOrigins that status uses.

* test(pull): env and hooks conflicts between two namespaces, and builtin: in a namespace file (Tencent#707)

Seam 1 asks every type to show, through pull, that two active namespaces
defining one name keep the installed state and name both files. Env and
hooks were covered only through doctor and the handler; so was the
warning for builtin: in a namespace hooks file.

* docs(skill-data): hooks and MCP edits are published with git, not teamai push (Tencent#707)

manage-admin.md told admins to publish hooks/MCP file edits with
teamai push, which sweeps only rules/, env/ and .codebuddy-plugin/, so
an agent following it would push nothing. It now says to commit and
push the file with git, as the usage guide does.

* refactor(models): read switched agents without a cast (Tencent#707)

* docs(changelog): doctor counts entries per namespace; inject fails on unresolved entries (Tencent#707)

* refactor(pull): drop imports the resolver move left unused (Tencent#707)

* fix(hooks): install the built-in hooks when the team hooks do not resolve (Tencent#707)

A first init or bootstrap whose team hooks did not resolve (a broken
namespace file, a clash, a duplicate id) installed no built-in hook, so
the session-start pull that heals the member never ran. Installed team
hooks are still kept; the built-in hooks are now installed where missing,
with the root file's builtin: overrides whenever hooks/hooks.yaml parses,
and with their defaults only in a tool with no teamai hook when it does
not. init and bootstrap say that the team hooks were not installed.

* fix(manifest): keep an unknown resources: key when roles and projects save (Tencent#707)

zod stripped the key this CLI only warns about, so a projects or roles
command run on this version deleted a newer CLI's type from the team
repo for everyone.

* fix(docs): withdraw a copy the team edited after delivery, not only an unchanged one (Tencent#707)

Withdrawing an inactive docs namespace compared the local copy with the
current team file only. A doc the team changed after the member received
it was then kept forever with a false 'you edited it' line. A copy equal
to an earlier team commit is what the mirror delivered, so it goes too.

* fix(rules): withdraw a replaced root rule edited in the same push, name a kept copy (Tencent#707)

In the JoyCode, OMP, Pi and Copilot rule dirs, a replaced root rule's
copy was removed only while it matched the current root rule. When the
admin edited the root rule and added its namespace override in one push,
the member's unedited copy stayed loaded beside the override, silently.
It is now also compared with the render at the last pull, and a copy
that is kept is named with the fix.

* fix(doctor): fail a check when team hooks or model profiles do not resolve (Tencent#707)

teamai status counts such a type as 0 and says to run doctor, but doctor
had failing checks only for env and MCP, so a duplicate hook id or a
two-namespace clash showed nothing there.

* fix(env): warn when --role names a namespace nothing declares (Tencent#707)

env add/remove --role <ns> wrote env/<ns>/env.yaml for a namespace no
role or project lists under resources.env, so the variable reached
nobody and nothing said so. The same applies to remove mcp --role.

* fix(env): find a changed namespace env file whose name is not ASCII on push (Tencent#707)

git ls-files quotes such a path by default, so it never matched the name
on disk and push skipped the change.

* fix(entries): an active env, hooks, MCP or models file that cannot be read stops the type (Tencent#707)

The readers folded every read error into 'file does not exist', so an
unreadable namespace file silently delivered the root entry in place of
its override. Only ENOENT is absence now; any other error is a broken
file, like one that does not parse.

* fix(entries): match env, hooks, MCP and models namespace dirs case-folded, as docs does (Tencent#707)

A declared namespace was joined onto the path as written, so with
env: [checkout] and a directory env/Checkout/, macOS and Windows members
got the override and Linux members the root value.

* fix(doctor): split the legacy claudemd paths on '/', not path.sep (Tencent#707)

listFilesRecursive always joins with '/', so on Windows every path was
one segment and a claudemd/<ns>/x.md beside claudemd/x.md was never
reported.

* fix(recall): index the rules pull delivers, not the whole rules/ tree (Tencent#707)

A namespace rule replaces the root rule of its name, but recall, contribute
and pull indexed every file under rules/: the replaced root rule and the rules
of inactive namespaces came back from recall. Index the resolved rule set, as
docs and skills already do.

* fix(entries): write a namespace file into the directory pull reads it from (Tencent#707)

Pull matches a declared namespace to its directory case-folded, but --role and
--project returned the spelling typed. On a case-sensitive filesystem
`env add --project checkout` created env/checkout/, which shadowed
env/Checkout/ and dropped its variables from delivery.

* fix(remove): remove no MCP server by a bare name while an MCP file does not parse (Tencent#707)

The team scan skips a file that does not parse. With mcp/mcp.yaml broken,
`remove mcp db` took the one readable checkout/db as the target and removed
it. Refuse and name the file unless the readable root defines the name.

* docs: rules in recall, namespace writes and remove mcp on a broken file (Tencent#707)

* fix(remove): say the MCP file --role or --project names does not parse, not that the name is missing (Tencent#707)

The team scan skips a file that does not parse, so `remove mcp db --project
checkout` with a broken mcp/checkout/mcp.yaml reported "Not found". Name the
file and remove nothing.

* fix(skills): remove a leftover of another skill version only when it matches that version (Tencent#707)

Install removed any installed file at a path another team version of the skill
has, by path alone. A file a member added under that name, e.g. README.md
beside a namespace they never had, was deleted on every pull. Remove it only
when it is byte for byte that version's file; keep any other and name it.

* fix(env): edit no env file that does not parse, and no --project target after a failed refresh (Tencent#707)

env add and env remove read the target through parseEnvYaml, which answers an
empty list for a file that does not parse, then wrote that back: every
variable the file had was replaced. They now refuse and name the file.

--project resolves through manifest/projects.yaml. After a failed pull that
copy may be stale and name a namespace the project no longer uses, whose file
push would publish, so --project now changes nothing then. The root file and
--role do not depend on the manifest and still only warn.

* fix(pull): let no unusable namespace item replace the root one (Tencent#707)

A skill directory without SKILL.md replaced the root skill of its name:
install overlaid it and removed the installed SKILL.md as the other version's
leftover, while pull still counted the skill as synced. Such a directory is
no longer a skill; pull names it and keeps delivering the root one.

An agent file that does not parse delivers nothing, yet it still replaced the
root agent, and cleanup removed the unchanged root copy because no active
destination held that stem. The root agent now stays while its replacement
cannot be read or parsed.

* fix(push): take no namespace directory without SKILL.md for a member's skill (Tencent#707)

Pull stopped delivering such a directory in 6c7df8e, but the push scan still
mapped the skill name to it. An unedited root skill then showed as modified,
and push wrote it into skills/<ns>/<name>/, deleting what was there and making
it a namespace skill that replaces the root one.

Also keep only a replaced root agent while its replacement does not parse, so
an unchanged copy from an inactive namespace is still removed, and put
renderedForTool's doc comment back on 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(projects): extend project isolation to knowledge/docs/agents/env/hooks/mcp

2 participants