Skip to content

fix(tags,roles): honor --dry-run and count namespaced skills in tags list (#836) - #837

Merged
jeff-r2026 merged 6 commits into
Tencent:mainfrom
SaulMoro:fix/dry-run-tags-roles
Sep 26, 2026
Merged

jeff-r2026 merged 6 commits into
Tencent:mainfrom
SaulMoro:fix/dry-run-tags-roles

Conversation

@SaulMoro

@SaulMoro SaulMoro commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Two tags/roles bugs from #836, one commit each.

1. --dry-run wrote anyway. teamai tags subscribe, tags unsubscribe and roles set saved the local config and reset lastPullRev even under the global --dry-run ("Preview mode, no changes made"). Now they return early after validation, the same way tags add/remove and roles init/add/remove/update already did.

 tagsSubscribe / tagsUnsubscribe / rolesSet
   validate input
+  if options.dryRun
+    log "[dry-run] Would …"
+    return
   save local config (user or project scope)
   reset lastPullRev in state

Loading the config could still write before that guard. For a user config with no primaryRole next to a roles.yaml that declares hai, loadLocalConfig() migrates the config to hai and saves it. loadLocalConfig, requireInit and autoDetectInit now take an optional { dryRun }, and these three commands pass theirs, so under --dry-run the migration stays in memory and logs [dry-run] Would migrate …. Callers that pass nothing behave as before.

 migrateLegacyRoleConfig(config, path, options = {})
   migrated = { ...config, primaryRole: 'hai', … }
+  if options.dryRun
+    log "[dry-run] Would migrate …"
+    return migrated
   write config.yaml

Project detection could write as well. On a fresh clone of a single-repo (mode: self) project with no machine config, detectProjectConfig() runs bootstrapSelfRepo(). That call writes the partition config, state and anchor, seeds tool dirs, injects hooks and registers the member on the reports branch. Detection also renames a partition that still has its pre-#546 name. detectProjectConfig and resolvePartitionDir now take the same { dryRun }. Under it, detection previews the bootstrap: previewSelfBootstrap builds the config the bootstrap would write, keeps it in memory, and prints [dry-run] Would bootstrap …. The preview makes no provider auth call: with a stale token, authenticate() can fall through to gh auth login --web, which prompts and stores credentials. So the preview names the provider but not the username. A partition with its old name is read where it is.

 detectProjectConfig(cwd, onUnreadable, options = {})
-  partitionDir = resolvePartitionDir(anchor)
+  partitionDir = resolvePartitionDir(anchor, options)   // dryRun: no rename, no config rewrite
   read the partition config
-  bootstrapSelfRepo(root), then read the partition
+  if options.dryRun: previewSelfBootstrap(root)         // in-memory config, "[dry-run] Would bootstrap …"
+  else:              bootstrapSelfRepo(root), then read the partition

bootstrapSelfRepo is split into a plan (remote, provider, username, team config, agents, role) and the writes. The preview runs the plan without its two auth calls (isAuthenticated, authenticate).

Audited writes on the path these three commands take before their guard:

Step Write Under --dry-run
preAction auto-migration moves .teamai/ into the partition not triggered: only init, pull, push and the learning-queueing commands trigger it
resolvePartitionDir (detection and bootstrap) renames a pre-#546 partition, removes an empty canonical dir, rewrites repo.localPath in its config.yaml skipped; the old dir is read in place
bootstrap lock creates and deletes <repo>/.teamai/.bootstrap.lock not taken
bootstrap config partition config.yaml, anchor, state.json kept in memory
bootstrap tools project tool dirs (.claude/skills, …), hook settings (.claude/settings.json, managed-hooks record) skipped
bootstrap registration reports worktree (git worktree add), members/<user>.yaml, commit, push skipped
loadLocalConfig legacy role migration ~/.teamai/config.yaml kept in memory (previous round)
resolveAnchors, readConfigFrom, loadTeamConfig, loadRolesManifest none (git and file reads) unchanged
provider isAuthenticated() in the bootstrap plan none, but spawns gh auth status / gf auth whoami / cnb skipped
provider authenticate() in the bootstrap plan gh api user, GET /user; falls through to gh auth login --web, gf auth login, cnb login or GitCode's token prompt (writes ~/.netrc) skipped; the preview says it would look up the username
getProvider, detectProvider, parseRepoInput none (URL parsing) unchanged
getRemoteUrl, resolveAnchors none (local git remote / rev-parse) unchanged
member registration, clone, fetch, create repo, create PR network writes not reachable (registration skipped above; the rest are not on these commands' path)
logger appends to ~/.teamai/debug.log kept: this is diagnostics, and every command writes it

pull --dry-run, push --dry-run and status reach the same writes through loaders that do not pass { dryRun } (loadLocalConfigForScope, and autoDetectInit/detectProjectConfig without options). They are outside #836 and are not changed here. Callers that pass nothing behave as before.

The roles set preview always names the additional roles it would save, including none, because a real run replaces the existing list. oxlint found the first two: options was never read in either function. rolesSet has the same bug, but the linter misses it because the function reads options.add.

2. tags list counted namespaces as skills. The "N skill(s) have no tags" hint counted the top-level directories under skills/, so a namespace counted as one skill and its skills were not counted at all. It also subtracted the number of tags.yaml entries instead of checking which skills have tags.

 tagsList
-  untagged = listDirs(skills/).length - keys(tags.yaml skills).length
+  delivered = resolveDesiredSkills(teamConfig, localConfig, buildRolePullContext(localConfig))
+  untagged  = delivered.items without tags in tags.yaml

Pull delivers every skill in the member's namespaces (all of them without roles) whatever its tags; tags only add skills from elsewhere. So "no tags and always synced" means the untagged skills among those pull delivers, and asking pull's own resolver counts roles, exclusions and a name held by both the root and a namespace the way pull does. No new walk of skills/.

The count is only a hint, so if the resolver throws (a malformed manifest/roles.yaml or manifest/projects.yaml), tags list warns Could not count untagged skills: <cause> and drops the hint instead of failing after the table is printed. The old helper swallowed errors silently; teamai doctor handles the same resolver failure the same way.

Refs #836, the oxlint follow-up to #828.

Evidence

  • Before: the new tests fail on origin/main (7c834ce4).

    × tag subscription commands > previews subscribe under --dry-run …
    × tag subscription commands > previews unsubscribe under --dry-run …
    × rolesSet — state invalidation > should preview under --dry-run …
    × rolesSet — state invalidation > should preview clearing additional roles under --dry-run
    × tags list > counts untagged skills in both the flat and the namespace layout
    

    dry-run-load-path.test.ts hashes every file under a temp root (HOME, the project with .git and .git/hooks, and state.json) around each of the three commands. It uses three fixtures: a fresh self-mode clone, a config waiting for the legacy role migration, and a partition with its pre-feat(partition): encode the full project path into the data-home slug #546 name. The provider stub parses the remote and records and throws on every other method, and the test asserts it saw no call. updateReports is a spy that must not be called. On 5dcd6d2b the self-mode fixture fails for all three commands with expected [ 'isAuthenticated' ] to deeply equal []. On 4661d2f9 the self-mode and partition fixtures fail for all three commands (6 of 9). The diff lists the new files: partition config.yaml, state.json, anchor, and app/.claude/settings.json. The legacy-migration fixture was already fixed in the previous round (it failed on 7e5e4414).
    After: unit tests npx vitest run: 5061 passed, 1 skipped. npx tsc --noEmit is clean, npm run build succeeds. New tests also cover a role member (an untagged skill outside their namespaces is not counted), a name in both the root and a namespace (counted once), a malformed roles.yaml (table still prints, hint replaced by a warning, no throw), and --dry-run in project scope.

  • Real CLI, --dry-run (npm run build, node dist/index.js, isolated HOME with a local team repo, user scope, state.json seeded with lastPullRev: abc1234). Neither config.yaml nor state.json changes under --dry-run; both change without it:

    config sha=4f91a05e5daa state sha=9b5c789d50c8
    $ teamai tags subscribe testing --dry-run
    ℹ [dry-run] Would subscribe to: testing
    exit=0 config sha=4f91a05e5daa state sha=9b5c789d50c8
    $ teamai tags unsubscribe frontend --dry-run
    ℹ [dry-run] Would unsubscribe from: frontend
    exit=0 config sha=4f91a05e5daa state sha=9b5c789d50c8
    --- without --dry-run (writes expected)
    $ teamai tags subscribe testing
    ✔ Subscribed to: testing
    exit=0 config sha=62f621172c90 state sha=76e76fbf3aec   (lastPullRev: null)
    
    # roles.yaml with hai and pm, state reseeded
    config sha=62f621172c90 state sha=9b5c789d50c8
    $ teamai roles set hai --add pm --dry-run
    ℹ [dry-run] Would set primary role to: hai, additional roles: pm
    exit=0 config sha=62f621172c90 state sha=9b5c789d50c8
    $ teamai roles set pm --dry-run
    ℹ [dry-run] Would set primary role to: pm, additional roles: none
    exit=0 config sha=62f621172c90 state sha=9b5c789d50c8
    --- without --dry-run (writes expected)
    $ teamai roles set hai
    ✔ Primary role set to: hai
    exit=0 config sha=5c1bc31d7c4e state sha=76e76fbf3aec   (additionalRoles: [], lastPullRev: null)
    

    The last run replaced additionalRoles: [pm] with [], which is what the none preview says. Project scope is covered by a unit test, not a real-CLI run; the dry-run guard runs before the scope branch.

  • Real CLI, --dry-run with a config that needs the legacy role migration (no primaryRole in config.yaml, roles.yaml declares hai and pm, fresh HOME per run, cwd outside git). Before is 7e5e4414 built from git archive:

    === before (7e5e4414) ===
    $ teamai tags subscribe testing --dry-run
    ℹ Migrated legacy teamai config to default role profile: hai
    ℹ [dry-run] Would subscribe to: testing
    config.yaml sha256: aa929148c4aa -> 6f04e40828b8 (MODIFIED)
    $ teamai tags unsubscribe frontend --dry-run
    ℹ Migrated legacy teamai config to default role profile: hai
    ℹ [dry-run] Would unsubscribe from: frontend
    config.yaml sha256: 3750f96d8537 -> 6c8722a9bda9 (MODIFIED)
    $ teamai roles set pm --dry-run
    ℹ Migrated legacy teamai config to default role profile: hai
    ℹ [dry-run] Would set primary role to: pm, additional roles: none
    config.yaml sha256: f473283ad237 -> 3ccf9bdffb3e (MODIFIED)
    
    === after ===
    $ teamai tags subscribe testing --dry-run
    ℹ [dry-run] Would migrate legacy teamai config to default role profile: hai
    ℹ [dry-run] Would subscribe to: testing
    config.yaml sha256: c031c00ccb13 -> c031c00ccb13 (unchanged)
    $ teamai tags unsubscribe frontend --dry-run
    ℹ [dry-run] Would migrate legacy teamai config to default role profile: hai
    ℹ [dry-run] Would unsubscribe from: frontend
    config.yaml sha256: bf2a22aa43d2 -> bf2a22aa43d2 (unchanged)
    $ teamai roles set pm --dry-run
    ℹ [dry-run] Would migrate legacy teamai config to default role profile: hai
    ℹ [dry-run] Would set primary role to: pm, additional roles: none
    config.yaml sha256: 79dbf08b979c -> 79dbf08b979c (unchanged)
    
    --- without --dry-run, the migration is still saved
    $ teamai tags subscribe testing
    ℹ Migrated legacy teamai config to default role profile: hai
    ✔ Subscribed to: testing
    (config.yaml now has primaryRole: hai, resourceProfileVersion: 1, subscribedTags: [testing])
    

    The hashes differ between runs because each run writes its own temp path into config.yaml.

  • Real CLI, --dry-run on a fresh self-mode clone with an invalid GITHUB_TOKEN in a terminal. The project is a git init with origin https://github.com/SaulMoro/teamai-dry-run-demo.git (the repo does not exist) and a committed .teamai/teamai.yaml with mode: self and a two-role manifest. HOME is isolated and has ~/.claude. GITHUB_TOKEN=ghp_invalid…, and script -q /dev/null gives the CLI a TTY, so isInteractive() is true. tree is a sha256 over every file under HOME and the project, .git included, excluding debug.log. A gh shim first on PATH logs every invocation. Before is 5dcd6d2b, built from git archive:

    === before (5dcd6d2b) ===
    $ teamai --dry-run tags subscribe testing
    ℹ Starting GitHub authentication via gh CLI...
    The value of the GITHUB_TOKEN environment variable is being used for authentication.
    NotInitializedError: teamai is not initialized. Run `teamai init` first.
    exit=1
    (same for tags unsubscribe and roles set)
    gh invocations: 3 × (gh api user -q .login ×2, gh auth login --web --git-protocol https)
    
    === after ===
    tree before: 891a0f5fcf0ee41f
    $ teamai --dry-run tags subscribe testing
    ℹ [dry-run] Would bootstrap this single-repo project if you are authenticated with github (not checked in a dry run): look up your username, write its config and state to …/home/.teamai/projects/<slug>, seed tool dirs, inject hooks and register you as a member
    ℹ [dry-run] Would subscribe to: testing
    exit=0  tree: 891a0f5fcf0ee41f
    $ teamai --dry-run tags unsubscribe frontend
    ℹ [dry-run] Would bootstrap this single-repo project if you are authenticated with github …
    ℹ Not subscribed to any of the specified tags.
    exit=0  tree: 891a0f5fcf0ee41f
    $ teamai --dry-run roles set pm --add hai
    ℹ [dry-run] Would bootstrap this single-repo project if you are authenticated with github …
    ℹ [dry-run] Would set primary role to: pm, additional roles: hai
    exit=0  tree: 891a0f5fcf0ee41f
    gh invocations: none
    

    The gh auth login --web before the fix reached no prompt only because gh refuses to log in while GITHUB_TOKEN is set; without that guard it prompts, for example cnb login with a rejected CNB_TOKEN (by reading the code; not run). Before the baseline, the fixture HOME ran gh auth status once, because gh writes its own ~/.local/state/gh/device-id the first time it runs under a new HOME. The file-write contrast from the previous round (4661d2f9 wrote app/.claude/settings.json, the partition config/state/anchor and reports-wt/members/SaulMoro.yaml) is covered by the unit test above.

  • Real CLI, tags list: skills/solo (flat) plus skills/hai/{a,b,c} (namespace), and only a is tagged.

    # no roles manifest, no role: pull delivers everything → solo, b, c
    --- before (main)
    1 skill(s) have no tags and are always synced.
    --- after
    3 skill(s) have no tags and are always synced.
    
    # roles.yaml with hai and pm, primaryRole: hai: pull delivers hai/* only → b, c
    --- before (main)
    1 skill(s) have no tags and are always synced.
    --- after
    2 skill(s) have no tags and are always synced.
    
    # separate fixture, malformed manifest/roles.yaml (`roles: [`): table prints, hint becomes a warning, exit 0
    $ teamai tags list
      frontend            1         0           ✓
      testing             1         0
    ⚠ Could not count untagged skills: Invalid roles manifest YAML: Flow sequence in block collection must be sufficiently indented and end with a ] at line 2, column 1: …
    exit=0
    

Merge Danger

Door: two-way

Blast Radius: small

Only runs with --dry-run change, and they no longer write anything or call the provider's auth. The config loaders, detectProjectConfig and resolvePartitionDir gain an optional { dryRun } argument that only these three commands pass. bootstrapSelfRepo keeps its steps and results. Its one non-silent "Detected a teamai single-repo project" line now prints after the team config and roles manifest are read, not before. tags list changes only its untagged-skills hint: the number, and a warning in place of a crash when the manifest is malformed. Everything else behaves as before, and the existing tests pass unchanged.

Review notes: Under --dry-run, an adoption that crashed between the rename and the repo.localPath rewrite is not finished, because finishing it is a write. The dry run reads the stale repo.localPath as it is, so roles set cannot find the roles manifest there (by reading the code; not run). Nothing is written, and the next real command finishes the adoption.

…and roles set (Tencent#836)

The three commands saved the local config and reset lastPullRev even
under the global --dry-run, which is documented as "Preview mode, no
changes made". Their siblings (tags add/remove, roles init/add/remove/
update) already return early with a [dry-run] message.

The roles set preview names the additional roles it would save,
including none, because a real run replaces the existing list.

oxlint reported the unused options parameter in tagsSubscribe and
tagsUnsubscribe; rolesSet has the same bug but reads options.add.
@SaulMoro SaulMoro changed the title fix(tags,roles): honor --dry-run in tags subscribe, tags unsubscribe and roles set (#836) fix(tags,roles): honor --dry-run and count namespaced skills in tags list (#836) Sep 25, 2026
The "N skill(s) have no tags and are always synced" hint counted the
top-level directories under skills/, so a namespace counted as one
skill and its skills were not counted at all. It also subtracted the
number of tags.yaml entries instead of checking which skills have tags.

Count the untagged skills among those pull delivers, using pull's own
resolver (resolveDesiredSkills with the member's role context). Pull
delivers every skill in the member's namespaces, all of them without
roles, whatever its tags; tags only add skills from elsewhere. So roles,
exclusions and a name held by both the root and a namespace are counted
the way pull counts them.
@SaulMoro
SaulMoro force-pushed the fix/dry-run-tags-roles branch from 751ac93 to 3e8d4c8 Compare September 25, 2026 20:44
@jeff-r2026 jeff-r2026 self-assigned this Sep 26, 2026
@github-actions

Copy link
Copy Markdown

Findings

  • [P2 non-blocking] Prevent the auxiliary count from aborting tags list — src/tags.ts:283. If manifest/roles.yaml or manifest/projects.yaml is malformed, buildRolePullContext() throws, causing an otherwise readable tag listing to fail after partially printing its table. The previous counting helper caught errors; catch resolver failures here and omit the hint or warn instead.

Testing

  • The PR description includes sufficient unit, type-check, build, and representative real-CLI verification for the runtime changes.

@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] Guard config-loading migrations during dry-run — src/tags.ts:125 and src/roles-cmd.ts:213. With a user config lacking primaryRole and a roles.yaml containing hai, resolveTagsScope()/autoDetectInit() calls loadLocalConfig(), whose legacy-role migration writes the config before these guards run. Consequently, all three commands can still modify disk under --dry-run. Use a dry-run-aware loading path or suppress migration writes.

Previous Finding

  • Resolved: countUntaggedDeliveredSkills() now catches role/project resolver failures, warns, and preserves the displayed tag list.

Testing

  • The PR description documents sufficient unit, type-check, build, and representative real-CLI verification.

SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Sep 26, 2026
…nd unsubscribe

With the Tencent#837 dry-run fix reverted out of this PR, both functions no
longer read options. The underscore prefix keeps the signature and call
sites unchanged, so Tencent#837 can rebase onto it by renaming the parameter
back.
@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] Suppress project self-healing during dry-run — src/config.ts:613. autoDetectInit() and resolveTagsScope() still call detectProjectConfig() without the dry-run option. In a fresh self-mode clone with no machine config, detection invokes bootstrapSelfRepo(), which writes config/state, installs hooks, and may register the member remotely. Therefore roles set, tags subscribe, and tags unsubscribe can still mutate state under --dry-run. Pass dry-run through project detection or disable self-healing for preview loads.

Previous Findings

  • Resolved: resolver failures no longer abort tags list.
  • Resolved: user-config legacy-role migration now remains in memory during dry-run.

Testing

  • The PR description includes sufficient unit, type-check, build, and representative real-CLI verification.

… partition adoption under --dry-run (Tencent#836)

detectProjectConfig now takes the { dryRun } load option that roles set,
tags subscribe and tags unsubscribe already pass. Under it, a fresh
self-mode clone gets the config bootstrapSelfRepo would write, kept in
memory (previewSelfBootstrap), and a pre-Tencent#546 partition is read where it
is instead of being renamed. One test hashes HOME, the project (with .git)
and state.json around each command on three fixtures.
@github-actions

Copy link
Copy Markdown

Findings

  • [P1 blocking] Keep self-bootstrap preview authentication read-only — src/bootstrap.ts:194. On a fresh self-mode clone, --dry-run calls planSelfBootstrap(), which invokes provider.authenticate(). For example, with an invalid/expired GITHUB_TOKEN in an interactive terminal, isAuthenticated() returns true based on token presence, but authenticate() can fall through to gh auth login --web, prompting and modifying stored credentials despite “Preview mode, no changes made.” Use a non-interactive/read-only identity lookup during preview.

Previous Findings

  • Resolved: malformed role/project manifests no longer abort tags list.
  • Resolved: legacy-role migration and project partition/bootstrap filesystem writes are suppressed during dry-run.

Testing

  • The PR description documents sufficient unit, type-check, build, and representative real-CLI verification.

@github-actions

Copy link
Copy Markdown

Findings

  • [P2 non-blocking] Preserve real scope selection when authentication is unavailable — src/bootstrap.ts:110. The preview unconditionally synthesizes a project config without checking authentication. In a fresh self-mode clone with no provider credentials, --dry-run roles set or tags subscribe previews a project-scoped change, while the real command skips bootstrap and either falls back to the user config or reports “not initialized.” The preview should not claim a different target/outcome than the real command.
  • [P3 nit] Rebase stale partition paths in memory during dry-run — src/utils/partition.ts:223. If adoption previously stopped after renaming the legacy partition but before rewriting repo.localPath, dry-run selects the canonical directory but leaves the stale path unchanged. roles set --dry-run then cannot load roles.yaml, although the real command repairs the path and succeeds.

Previous Findings

  • Resolved: malformed role/project manifests no longer abort tags list.
  • Resolved: legacy-role migration and project bootstrap filesystem writes are suppressed during dry-run.
  • Resolved: bootstrap preview no longer invokes provider authentication.

Testing

  • The PR description documents sufficient unit, build, type-check, and representative real-CLI verification.

@jeff-r2026
jeff-r2026 self-requested a review September 26, 2026 11:24
@jeff-r2026
jeff-r2026 merged commit be87a57 into Tencent:main Sep 26, 2026
11 checks passed
jeff-r2026 pushed a commit that referenced this pull request Sep 26, 2026
* fix(tags,roles): honor --dry-run in tags subscribe, tags unsubscribe and roles set (#836)

The three commands saved the local config and reset lastPullRev even
under the global --dry-run, which is documented as "Preview mode, no
changes made". Their siblings (tags add/remove, roles init/add/remove/
update) already return early with a [dry-run] message.

The roles set preview names the additional roles it would save,
including none, because a real run replaces the existing list.

oxlint reported the unused options parameter in tagsSubscribe and
tagsUnsubscribe; rolesSet has the same bug but reads options.add.

* chore(lint): add oxlint with its default rules

Pinned to an exact version so a new default rule arrives in its own PR,
not as a CI failure on an unrelated one. The no-unused-vars options
keep oxlint's _ ignore patterns and add ignoreRestSiblings, which the
rest-omit in dashboard.ts relies on to keep config and roots out of
/api/workspaces.

* style(lint): apply oxlint safe fixes

Drop redundant escapes in regex character classes and template literals,
empty-object fallbacks in object spreads (spreading undefined adds
nothing), and anchored regexes that are plain startsWith/endsWith
checks. No behavior change.

* refactor(lint): remove unused imports and an unused catch binding

Applied with oxlint --fix-suggestions and reviewed by hand. Every
removed whole import is a library module with no import-time side
effects.

* refactor(lint): remove dead code reported by no-unused-vars

Each hit was checked against its callers and git history; none is
missing wiring (the two that were, tags subscribe/unsubscribe, are fixed
in the preceding commit). Removed: unused locals and functions, the
options parameter of tagsList, rolesList and generateDigest (read-only
commands), the never-read interactive option of importFromRepo, the
empty test/e2e.mjs left over from the E2E migration, and a try/catch
that only rethrew. new Array(n) becomes Array.from. No behavior change.

* test(lint): fix lint hits in tests

- contribute dry-run test asserted nothing; it now checks that the run
  leaves the repo/HOME tree unchanged (verified to fail when the dry-run
  early return is removed).
- Drop a no-op expect(result).not.toThrow on a string.
- Keep undefined in two optional-chain casts so a regression fails the
  assertion instead of throwing a TypeError.
- Remove unused locals, helpers and imports; new Array(n) becomes
  Array.from.

* refactor(lint): write control-character classes as \p{Cc}

no-control-regex flags literal control ranges. \p{Cc} names the same
set (C0, DEL, C1) and reads as what it means. Checked against the old
classes on every code point from U+0000 to U+10FFFF: manifest-schema and
agent-format match exactly, and contribute-check's normalization
pipeline produces the same output. The test assertion is now stricter
and checks every control character the sanitizer removes.

* refactor(lint): remove disable directives for rules that are not enabled

Four eslint-disable comments named rules this repo never ran
(no-await-in-loop, @typescript-eslint/no-explicit-any), so they
suppressed nothing.

* ci(lint): fail CI on any oxlint warning (#828)

npm run lint runs oxlint --deny-warnings and runs before the type check
in both GitHub Actions and Coding CI. The repo is at zero warnings, so
new code must stay clean. --report-unused-disable-directives also fails
on a disable comment that suppresses nothing, so a suppression cannot
outlive the code it was written for. CLAUDE.md, AGENTS.md,
CONTRIBUTING.md and the PR template list the command so contributors
and agents run it before opening a PR.

Closes #828

* chore(lint): pin oxlint 1.16.0, the newest release that accepts Node 20.0

oxlint 1.17.0 and later declare engines.node ^20.19.0 || >=22.12.0,
while the repo supports Node >=20. 1.16.0 declares >=8, supports
--deny-warnings and --report-unused-disable-directives, and reports 0
warnings on this branch.

* Revert "fix(tags,roles): honor --dry-run in tags subscribe, tags unsubscribe and roles set (#836)"

This reverts commit 224d459.

* refactor(lint): mark the unused options parameter of tags subscribe and unsubscribe

With the #837 dry-run fix reverted out of this PR, both functions no
longer read options. The underscore prefix keeps the signature and call
sites unchanged, so #837 can rebase onto it by renaming the parameter
back.

* chore(lint): restore oxlint 1.85.0

This reverts commit e2347ef. oxlint is a devDependency, so its Node
requirement (^20.19.0 || >=22.12.0) never reaches users installing
teamai-cli, and CI's node-version 20 resolves to the latest 20.x.
Staying on 1.85.0 keeps the #836 warning counts and the planned
type-aware follow-up on the same version.

* docs(contributing): note the Node version npm run lint needs

* docs(agents): note the Node version npm run lint needs
jeff-r2026 pushed a commit that referenced this pull request Sep 27, 2026
…on save and recall use (#853)

#837 threaded LoadOptions through the config loaders, and #850 fixes the
three commands that still reach them bare (pull, push, status). Three more
commands load their config before their own dry-run guard and pass nothing:

- contribute (--scope project loads, then --scope user / auto-detect)
- session save (same three branches)
- recall (detection, the inherited user scope, and the user branch)

On a config pending the legacy role migration each of them rewrote
~/.teamai/config.yaml under --dry-run, printing the migration line without
any [dry-run] marker; the auto-detect and project branches can also adopt a
pre-#546 partition and run the single-repo self-heal bootstrap.

loadLocalConfigForScope is the loader #837 missed: it now takes
LoadOptions and forwards them to detectProjectConfig and both
migrateLegacyRoleConfig calls. Callers that pass nothing behave as before —
a real run still migrates in place.

Co-authored-by: ydflow <[email protected]>
jeff-r2026 pushed a commit that referenced this pull request Sep 28, 2026
…s and list use (#866)

* fix(dry-run): thread { dryRun } through the loaders pull, push, status and list use

`--dry-run` is documented as previewing without making changes, and #837 made
that true for `tags subscribe`, `tags unsubscribe` and `roles set`. `pull`,
`push` and `status` still wrote: each runs its scope-detection block before any
dry-run guard, and that block called config loaders that were never given the
flag. A preview could therefore persist the legacy role migration, and in a git
repo adopt a pre-#546 partition or run the single-repo self-heal bootstrap.

The loaders already take LoadOptions — #853 threaded them through
`loadLocalConfigForScope` for contribute / session save / recall. These
commands simply did not supply the flag.

- pull.ts: both loaders take { dryRun: options.dryRun }.
- push.ts: autoDetectInit takes it.
- status.ts and list: { dryRun: true } unconditionally, because both are
  read-only and should never migrate, adopt a partition or bootstrap.

Callers that pass nothing behave as before, the same compatibility promise
#837 made. The one observable change is that the preview path logs, so
`status`/`list` now surface a "[dry-run] Would ..." line where a migration or
bootstrap is pending; the PR description asks for a decision on that label.

Verification: seven new command-level cases, each failing on unmodified main
with the identical test file (the project-scope three need a git project with
a pre-#546 partition name, which the existing user-scope fixture never
reaches); and the issue's own real-CLI reproduction, 6/6 — the control writes
the reported fields, this change writes nothing.

oxlint --deny-warnings and tsc --noEmit: rc=0 here and rc=0 on unmodified main.

Closes #850

* fix(pull,push): a --dry-run must leave a fresh self-mode clone alone

Resolves both P1 findings on this PR.

pull.ts:1891 - the previewed self-mode config reached lockScope(), whose
acquireLock() calls ensureDir() on the lock's parent. On a fresh clone the
partition does not exist yet, so the directory was created and stayed:
releaseLock removes the lock file, not its parent. The guard sits inside
lockScope(), the one choke point all three call sites share.

push.ts:731 - the same previewed config ran the whole self-mode setup before
pushCore reached its own dry-run guard at push.ts:1577: the sync-lock,
migrateSelfModeGitignore(), and the disposable knowledge worktree.

Both guards are deliberately narrow. A blanket early return before the
git-mode branch would also skip resetToCleanMaster/pullRepo (push.ts:934),
which a dry run performs on purpose so it can name the destination the real
command would use. Only writes that outlive the command are gated.

The preview still reads the uncommitted teamai.yaml that pushCore receives
as initialPendingTeamConfig; that block is now pendingSelfTeamConfig(), the
identical read, so the preview keeps describing the config edit it exists to
describe.

Fixture gap, also flagged: dry-run-load-path.test.ts already had a
fresh-self-mode-clone fixture, but only tags/roles ran against it. pull and
push ran at user scope, or on a project partition that already exists - never
on the one shape where acquireLock has something new to create. Two cases
added there; the unfixed tree fails them at
fs.existsSync(<HOME>/.teamai/projects) with "expected true to be false".

Not fixed here, and named in the PR description: pull --dry-run on a fresh
clone still creates an empty <HOME>/.teamai/locks/, via listPendingForInstall
in utils/pending-learnings.ts. That call is unchanged by this PR and the file
is outside its scope; the test declares and counts the entry, so anything
else appearing still fails.

* test(pull): pin the loader call shape the widened signature produces

Fixes the red Lint & Test on the previous head (all four matrix entries).

pull-scope-isolation.test.ts asserted the exact argument list of
loadLocalConfigForScope, which this change widens to carry LoadOptions:

  expect(loadLocalConfigForScope).toHaveBeenCalledWith('user');
    received ['user', undefined, { dryRun: undefined }]

The shape is not a free choice: recall.ts:464 and recall.ts:515 already pass
the same third argument, landed with #853, so pull.ts matches the merged
precedent. recall-scope-isolation.test.ts never asserts the argument list,
which is why the same change left it green.

The affected set is derived from the changed symbols rather than from the
topic: every test file that mentions loadLocalConfigForScope,
detectProjectConfig or autoDetectInit (76 files, 1221 tests).

* fix(update): a --dry-run asks the lock for its state instead of taking it

`acquireLock` is not a read. It `ensureDir`s the lock's parent, which on a
fresh self-mode clone is a `<getDataHome>` partition that does not exist yet —
and `releaseLock` removes the lock FILE, not that directory, so the directory
outlives the command. Any preview that calls it therefore writes, which is the
defect this PR is about (#866).

The new `options.dryRun` returns what the preview actually owes its caller: the
ANSWER the real run would get. `lockState` already separates `live` (a holder
is running) from `stale` and `missing`, and the real run reclaims either of the
latter and wins, so `acquireLock(path, { dryRun: true })` is exactly that
verdict — no mkdir, no lock file, no reclaim sentinel.

Nothing is recorded in `heldLockOwners`, which is what makes the preview safe
alongside the existing `releaseLock` calls: it returns at its first line when
it holds no owner token for the path, so a preview cannot delete a lock another
process owns.

No caller passes `dryRun` yet; this commit is the primitive only.

* fix(pull,push): acquire the preview's locks read-only, and stop hiding what it reports

Supersedes the guards added in cfd7c57. Those guards stopped the writes, and
E2E (fork-safe) caught what they cost — 6 failures in
push-sync-followups-823.test.ts, all of the same shape:

  expected '- Scanning local resources...\nNo new or modified resources to push'
  to contain '[rules] teamai-rule (modified)'

A preview that reports no changes for a tree with a deliberately edited team
rule is not a conservative preview; it is this PR's own defect with the sign
flipped.

pull.ts — `lockScope()` returned `true` outright for a dry run, asserting the
scope was uncontended. That is a fabricated fact: its callers read `true` as
"you hold the lock". It now acquires through the read-only primitive and
records the lock for release only when it really took one, so a scope with a
live holder is reported as contended and skipped, exactly as a real pull does.

push.ts — the self-mode branch returned early for a dry run. Two of the three
things it skipped are right to skip and one is not.

  - the sync-lock: read-only now, at both push.ts:784 (self) and push.ts:839
    (git mode).
  - `migrateSelfModeGitignore()`: still skipped. It rewrites a tracked file in
    the user's ACTIVE tree, which outlives the preview, and it is idempotent,
    so the next real push performs it.
  - the knowledge worktree: MUST run, and that is the correction. `pushCore`
    adds the active tree's `.teamai/{skills,rules}` as scan sources and diffs
    them against `localConfig.repo.localPath` (push.ts:1095-1112) — the clean
    worktree checkout. Outside the worktree those are the same path in self
    mode, so the diff is empty by construction: skipping the worktree does not
    report an edit early, it hides the edit. `withKnowledgeWorktree` already
    removes it in a `finally`, so it stays disposable.

Fixture — `push --dry-run` now performs its `git fetch` for real, which leaves
`app/.git/FETCH_HEAD` behind. Declared and counted next to the existing
`<getDataHome>/locks/` entry, so any OTHER new entry still fails the case.
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…list (Tencent#836) (Tencent#837)

* fix(tags,roles): honor --dry-run in tags subscribe, tags unsubscribe and roles set (Tencent#836)

The three commands saved the local config and reset lastPullRev even
under the global --dry-run, which is documented as "Preview mode, no
changes made". Their siblings (tags add/remove, roles init/add/remove/
update) already return early with a [dry-run] message.

The roles set preview names the additional roles it would save,
including none, because a real run replaces the existing list.

oxlint reported the unused options parameter in tagsSubscribe and
tagsUnsubscribe; rolesSet has the same bug but reads options.add.

* fix(tags): count namespaced skills in tags list (Tencent#836)

The "N skill(s) have no tags and are always synced" hint counted the
top-level directories under skills/, so a namespace counted as one
skill and its skills were not counted at all. It also subtracted the
number of tags.yaml entries instead of checking which skills have tags.

Count the untagged skills among those pull delivers, using pull's own
resolver (resolveDesiredSkills with the member's role context). Pull
delivers every skill in the member's namespaces, all of them without
roles, whatever its tags; tags only add skills from elsewhere. So roles,
exclusions and a name held by both the root and a namespace are counted
the way pull counts them.

* fix(tags): address review — warn instead of aborting tags list on a malformed manifest (Tencent#836)

* fix(tags,roles): address review — keep the legacy role migration in memory under --dry-run (Tencent#836)

* fix(tags,roles): address review — preview the self-mode bootstrap and partition adoption under --dry-run (Tencent#836)

detectProjectConfig now takes the { dryRun } load option that roles set,
tags subscribe and tags unsubscribe already pass. Under it, a fresh
self-mode clone gets the config bootstrapSelfRepo would write, kept in
memory (previewSelfBootstrap), and a pre-Tencent#546 partition is read where it
is instead of being renamed. One test hashes HOME, the project (with .git)
and state.json around each command on three fixtures.

* fix(bootstrap): address review — make no provider auth call in the --dry-run bootstrap preview (Tencent#836)
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…t#839)

* fix(tags,roles): honor --dry-run in tags subscribe, tags unsubscribe and roles set (Tencent#836)

The three commands saved the local config and reset lastPullRev even
under the global --dry-run, which is documented as "Preview mode, no
changes made". Their siblings (tags add/remove, roles init/add/remove/
update) already return early with a [dry-run] message.

The roles set preview names the additional roles it would save,
including none, because a real run replaces the existing list.

oxlint reported the unused options parameter in tagsSubscribe and
tagsUnsubscribe; rolesSet has the same bug but reads options.add.

* chore(lint): add oxlint with its default rules

Pinned to an exact version so a new default rule arrives in its own PR,
not as a CI failure on an unrelated one. The no-unused-vars options
keep oxlint's _ ignore patterns and add ignoreRestSiblings, which the
rest-omit in dashboard.ts relies on to keep config and roots out of
/api/workspaces.

* style(lint): apply oxlint safe fixes

Drop redundant escapes in regex character classes and template literals,
empty-object fallbacks in object spreads (spreading undefined adds
nothing), and anchored regexes that are plain startsWith/endsWith
checks. No behavior change.

* refactor(lint): remove unused imports and an unused catch binding

Applied with oxlint --fix-suggestions and reviewed by hand. Every
removed whole import is a library module with no import-time side
effects.

* refactor(lint): remove dead code reported by no-unused-vars

Each hit was checked against its callers and git history; none is
missing wiring (the two that were, tags subscribe/unsubscribe, are fixed
in the preceding commit). Removed: unused locals and functions, the
options parameter of tagsList, rolesList and generateDigest (read-only
commands), the never-read interactive option of importFromRepo, the
empty test/e2e.mjs left over from the E2E migration, and a try/catch
that only rethrew. new Array(n) becomes Array.from. No behavior change.

* test(lint): fix lint hits in tests

- contribute dry-run test asserted nothing; it now checks that the run
  leaves the repo/HOME tree unchanged (verified to fail when the dry-run
  early return is removed).
- Drop a no-op expect(result).not.toThrow on a string.
- Keep undefined in two optional-chain casts so a regression fails the
  assertion instead of throwing a TypeError.
- Remove unused locals, helpers and imports; new Array(n) becomes
  Array.from.

* refactor(lint): write control-character classes as \p{Cc}

no-control-regex flags literal control ranges. \p{Cc} names the same
set (C0, DEL, C1) and reads as what it means. Checked against the old
classes on every code point from U+0000 to U+10FFFF: manifest-schema and
agent-format match exactly, and contribute-check's normalization
pipeline produces the same output. The test assertion is now stricter
and checks every control character the sanitizer removes.

* refactor(lint): remove disable directives for rules that are not enabled

Four eslint-disable comments named rules this repo never ran
(no-await-in-loop, @typescript-eslint/no-explicit-any), so they
suppressed nothing.

* ci(lint): fail CI on any oxlint warning (Tencent#828)

npm run lint runs oxlint --deny-warnings and runs before the type check
in both GitHub Actions and Coding CI. The repo is at zero warnings, so
new code must stay clean. --report-unused-disable-directives also fails
on a disable comment that suppresses nothing, so a suppression cannot
outlive the code it was written for. CLAUDE.md, AGENTS.md,
CONTRIBUTING.md and the PR template list the command so contributors
and agents run it before opening a PR.

Closes Tencent#828

* chore(lint): pin oxlint 1.16.0, the newest release that accepts Node 20.0

oxlint 1.17.0 and later declare engines.node ^20.19.0 || >=22.12.0,
while the repo supports Node >=20. 1.16.0 declares >=8, supports
--deny-warnings and --report-unused-disable-directives, and reports 0
warnings on this branch.

* Revert "fix(tags,roles): honor --dry-run in tags subscribe, tags unsubscribe and roles set (Tencent#836)"

This reverts commit 224d459.

* refactor(lint): mark the unused options parameter of tags subscribe and unsubscribe

With the Tencent#837 dry-run fix reverted out of this PR, both functions no
longer read options. The underscore prefix keeps the signature and call
sites unchanged, so Tencent#837 can rebase onto it by renaming the parameter
back.

* chore(lint): restore oxlint 1.85.0

This reverts commit e2347ef. oxlint is a devDependency, so its Node
requirement (^20.19.0 || >=22.12.0) never reaches users installing
teamai-cli, and CI's node-version 20 resolves to the latest 20.x.
Staying on 1.85.0 keeps the Tencent#836 warning counts and the planned
type-aware follow-up on the same version.

* docs(contributing): note the Node version npm run lint needs

* docs(agents): note the Node version npm run lint needs
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…on save and recall use (Tencent#853)

Tencent#837 threaded LoadOptions through the config loaders, and Tencent#850 fixes the
three commands that still reach them bare (pull, push, status). Three more
commands load their config before their own dry-run guard and pass nothing:

- contribute (--scope project loads, then --scope user / auto-detect)
- session save (same three branches)
- recall (detection, the inherited user scope, and the user branch)

On a config pending the legacy role migration each of them rewrote
~/.teamai/config.yaml under --dry-run, printing the migration line without
any [dry-run] marker; the auto-detect and project branches can also adopt a
pre-Tencent#546 partition and run the single-repo self-heal bootstrap.

loadLocalConfigForScope is the loader Tencent#837 missed: it now takes
LoadOptions and forwards them to detectProjectConfig and both
migrateLegacyRoleConfig calls. Callers that pass nothing behave as before —
a real run still migrates in place.

Co-authored-by: ydflow <[email protected]>
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…s and list use (Tencent#866)

* fix(dry-run): thread { dryRun } through the loaders pull, push, status and list use

`--dry-run` is documented as previewing without making changes, and Tencent#837 made
that true for `tags subscribe`, `tags unsubscribe` and `roles set`. `pull`,
`push` and `status` still wrote: each runs its scope-detection block before any
dry-run guard, and that block called config loaders that were never given the
flag. A preview could therefore persist the legacy role migration, and in a git
repo adopt a pre-Tencent#546 partition or run the single-repo self-heal bootstrap.

The loaders already take LoadOptions — Tencent#853 threaded them through
`loadLocalConfigForScope` for contribute / session save / recall. These
commands simply did not supply the flag.

- pull.ts: both loaders take { dryRun: options.dryRun }.
- push.ts: autoDetectInit takes it.
- status.ts and list: { dryRun: true } unconditionally, because both are
  read-only and should never migrate, adopt a partition or bootstrap.

Callers that pass nothing behave as before, the same compatibility promise
Tencent#837 made. The one observable change is that the preview path logs, so
`status`/`list` now surface a "[dry-run] Would ..." line where a migration or
bootstrap is pending; the PR description asks for a decision on that label.

Verification: seven new command-level cases, each failing on unmodified main
with the identical test file (the project-scope three need a git project with
a pre-Tencent#546 partition name, which the existing user-scope fixture never
reaches); and the issue's own real-CLI reproduction, 6/6 — the control writes
the reported fields, this change writes nothing.

oxlint --deny-warnings and tsc --noEmit: rc=0 here and rc=0 on unmodified main.

Closes Tencent#850

* fix(pull,push): a --dry-run must leave a fresh self-mode clone alone

Resolves both P1 findings on this PR.

pull.ts:1891 - the previewed self-mode config reached lockScope(), whose
acquireLock() calls ensureDir() on the lock's parent. On a fresh clone the
partition does not exist yet, so the directory was created and stayed:
releaseLock removes the lock file, not its parent. The guard sits inside
lockScope(), the one choke point all three call sites share.

push.ts:731 - the same previewed config ran the whole self-mode setup before
pushCore reached its own dry-run guard at push.ts:1577: the sync-lock,
migrateSelfModeGitignore(), and the disposable knowledge worktree.

Both guards are deliberately narrow. A blanket early return before the
git-mode branch would also skip resetToCleanMaster/pullRepo (push.ts:934),
which a dry run performs on purpose so it can name the destination the real
command would use. Only writes that outlive the command are gated.

The preview still reads the uncommitted teamai.yaml that pushCore receives
as initialPendingTeamConfig; that block is now pendingSelfTeamConfig(), the
identical read, so the preview keeps describing the config edit it exists to
describe.

Fixture gap, also flagged: dry-run-load-path.test.ts already had a
fresh-self-mode-clone fixture, but only tags/roles ran against it. pull and
push ran at user scope, or on a project partition that already exists - never
on the one shape where acquireLock has something new to create. Two cases
added there; the unfixed tree fails them at
fs.existsSync(<HOME>/.teamai/projects) with "expected true to be false".

Not fixed here, and named in the PR description: pull --dry-run on a fresh
clone still creates an empty <HOME>/.teamai/locks/, via listPendingForInstall
in utils/pending-learnings.ts. That call is unchanged by this PR and the file
is outside its scope; the test declares and counts the entry, so anything
else appearing still fails.

* test(pull): pin the loader call shape the widened signature produces

Fixes the red Lint & Test on the previous head (all four matrix entries).

pull-scope-isolation.test.ts asserted the exact argument list of
loadLocalConfigForScope, which this change widens to carry LoadOptions:

  expect(loadLocalConfigForScope).toHaveBeenCalledWith('user');
    received ['user', undefined, { dryRun: undefined }]

The shape is not a free choice: recall.ts:464 and recall.ts:515 already pass
the same third argument, landed with Tencent#853, so pull.ts matches the merged
precedent. recall-scope-isolation.test.ts never asserts the argument list,
which is why the same change left it green.

The affected set is derived from the changed symbols rather than from the
topic: every test file that mentions loadLocalConfigForScope,
detectProjectConfig or autoDetectInit (76 files, 1221 tests).

* fix(update): a --dry-run asks the lock for its state instead of taking it

`acquireLock` is not a read. It `ensureDir`s the lock's parent, which on a
fresh self-mode clone is a `<getDataHome>` partition that does not exist yet —
and `releaseLock` removes the lock FILE, not that directory, so the directory
outlives the command. Any preview that calls it therefore writes, which is the
defect this PR is about (Tencent#866).

The new `options.dryRun` returns what the preview actually owes its caller: the
ANSWER the real run would get. `lockState` already separates `live` (a holder
is running) from `stale` and `missing`, and the real run reclaims either of the
latter and wins, so `acquireLock(path, { dryRun: true })` is exactly that
verdict — no mkdir, no lock file, no reclaim sentinel.

Nothing is recorded in `heldLockOwners`, which is what makes the preview safe
alongside the existing `releaseLock` calls: it returns at its first line when
it holds no owner token for the path, so a preview cannot delete a lock another
process owns.

No caller passes `dryRun` yet; this commit is the primitive only.

* fix(pull,push): acquire the preview's locks read-only, and stop hiding what it reports

Supersedes the guards added in cfd7c57. Those guards stopped the writes, and
E2E (fork-safe) caught what they cost — 6 failures in
push-sync-followups-823.test.ts, all of the same shape:

  expected '- Scanning local resources...\nNo new or modified resources to push'
  to contain '[rules] teamai-rule (modified)'

A preview that reports no changes for a tree with a deliberately edited team
rule is not a conservative preview; it is this PR's own defect with the sign
flipped.

pull.ts — `lockScope()` returned `true` outright for a dry run, asserting the
scope was uncontended. That is a fabricated fact: its callers read `true` as
"you hold the lock". It now acquires through the read-only primitive and
records the lock for release only when it really took one, so a scope with a
live holder is reported as contended and skipped, exactly as a real pull does.

push.ts — the self-mode branch returned early for a dry run. Two of the three
things it skipped are right to skip and one is not.

  - the sync-lock: read-only now, at both push.ts:784 (self) and push.ts:839
    (git mode).
  - `migrateSelfModeGitignore()`: still skipped. It rewrites a tracked file in
    the user's ACTIVE tree, which outlives the preview, and it is idempotent,
    so the next real push performs it.
  - the knowledge worktree: MUST run, and that is the correction. `pushCore`
    adds the active tree's `.teamai/{skills,rules}` as scan sources and diffs
    them against `localConfig.repo.localPath` (push.ts:1095-1112) — the clean
    worktree checkout. Outside the worktree those are the same path in self
    mode, so the diff is empty by construction: skipping the worktree does not
    report an edit early, it hides the edit. `withKnowledgeWorktree` already
    removes it in a `finally`, so it stays disposable.

Fixture — `push --dry-run` now performs its `git fetch` for real, which leaves
`app/.git/FETCH_HEAD` behind. Declared and counted next to the existing
`<getDataHome>/locks/` entry, so any OTHER new entry still fails the case.
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.

2 participants