Repository navigation
feat(local-agent): enroll workspaces individually and give each agent its own access credential - #1495
Conversation
…行过一次安装提示词,才会出现项目绑定提示,才会被上报和同步。
HTTP team sources now carry agentTokens, so each Agent uses its own `sk-` access credential to report and sync models with the backend instead of sharing a single token. - `init --http` and `source add-http` gain an `--agent <tool>` option to declare which Agent the credential belongs to (e.g. codebuddy, claude); hooks are injected only into that tool - Updating one Agent's credential on the same endpoint no longer requires `--force`; the credentials of other Agents are left untouched - Agent credentials already in effect on the backend are kept while they are still usable, and newly issued credentials are not activated yet, so that already distributed model configs do not break when the token changes - Migrate the legacy shared token in a compatible way: the only account using that Agent takes over the credential; user-level `hk-` tokens are still shared by all Agents - Add unit tests for per-agent tokens, and update the command help text and the English and Chinese docs
Only the specified diff was read; no PR code was run, built, or installed. |
@JasonRUAN Thanks for the clear write-up. Notes for the maintainer and for you. We ran the built CLI against a loopback HTTP server that mimics the local-agent endpoints (report, sync, get-config, bind), with machines set up by main's build and then upgraded to this branch. The real backend's token rules and the install prompt are outside the repo, so we couldn't check them.
We agree with all four findings in the CI review and reproduced the three that involve running code. We rate its onboarding finding as blocking, for the reason above. No other open PR touches this code, and current main fixes none of it. |
|
分层代码评审 · 第 1 轮 · commit 91fbc05 分层代码评审:2 个需要处理(Important 2 / Security 0),Nit 3,原有问题 0 PR:#1495 · feat(local-agent): enroll workspaces individually and give each agent its own access credential · 作者 JasonRUAN 结论需要先修改(2 条 Important 未解决)。CI 全绿。 风险档位
发现(按严重程度)
已去重(PR 上已有人提过,本报告不重复计入):缺真实 CLI 运行记录;旧共享 token 迁移时被移走、其他 agent 拿不到(4807 行,迁移测试把该行为固定下来);换成 hk- 后旧 sk- 还在用; 验证
PR 说明缺的部分
同一批一起审的其他 PR
提醒
|
- Rework access-token ownership so an HTTP token is bound to the single agent it belongs to; refuse when several agents are named without a clear owner, and copy (not move) a legacy shared token so agents with no entry of their own keep a fallback credential. Drop a shared token that the backend now rejects, so those agents stop reporting success while stuck at 401. - Treat a workspace an earlier release delivered to as already enrolled, so upgrading keeps what it holds in sync instead of going silent. - Make binding-hint markers time-bounded and path-safe: the dedup marker used to embed path separators (writing into a nonexistent dir) or, on hosts with a stable process id, outlive the chat that wrote it and silence every later session. Hints are now consumed only after they are actually emitted. - Tell the user when a workspace is not enrolled (once per session, every host) instead of failing silently, and list available projects in non-interactive runs so setup scripts don't believe the account is empty. - Surface a local-agent init failure in `init` (exit 1 + warning) rather than hiding it as debug, and align the bind-project / enrollment wording across docs and skill data.
f041a2e to
c06e9cc
Compare
Review incomplete: The specified head commit No PR code was run, built, or installed. Please provide the exact diff or make the head commit available locally. |
Resolved: The earlier onboarding-documentation finding is fixed: the setup reference and both member guides now explain workspace enrollment with Only the specified diff and trusted base review criteria were read. No PR code was run, built, or installed. |
@JasonRUAN Thanks for the update. With the built CLI at
These still block it:
@jeff-r2026 This is a breaking change to how the HTTP local agent enrolls workspaces, so the call is yours. |
… initialized" refusal When `teamai init --http` enrolls an access token without an explicit `--agent`, the token's ownership was only a guess. The previous logic could drop that token when the guessed agent kept its still-working credential, and could refuse a brand-new install because loading the local-agent config backfills a `config.json` from the key the init itself just wrote — mistaking its own footprint for a pre-existing setup. This change: - Treats a token whose agent is inferred (no `--agent`) as a spare: if the guessed agent keeps the credential it already has, the incoming token is preserved in the shared slot so agents with no token of their own can still report with it. - Only counts a `config.json` that existed before the call as "already initialized", so a fresh `init --http --scope user` with a token and no `--agent` no longer fails with the overwrite refusal. - Removes the special `hk-` user-token sharing path; a user-level token now follows the same one-agent-at-a-time enrollment as every other token. The `--token` help text and CHANGELOG document the one-agent-at-a-time behavior, and E2E coverage is added for a fresh user-scope init plus extended across the local-agent and init-http scenarios.
Resolved: The earlier revoked-agent-token replacement scenario now selects the incoming token when the stored credential receives 401/403. The onboarding-documentation finding is also fixed in the setup reference and both member guides. Only the specified diff and trusted base criteria were read. No PR code was run, built, or installed. |
@JasonRUAN Thanks, this head closes most of what we raised at
Still open:
Locally, @jeff-r2026 This one is yours to merge: the record, |
…eeps a user token (hk-) in the shared slot, so it is accepted with any number of --agent and stays available to every agent.
Resolved: The earlier Only the specified diff and trusted base criteria were read. No PR code was run, built, or installed. |
@JasonRUAN Thanks, It brings one earlier point back, which the CI review also reports:
The CI review adds one point we haven't checked: Everything else from our last comment still stands: the real-CLI record in the body ([P1 blocking]), @jeff-r2026 For your merge call. |
… (hk-), that agent's own token entry is now cleared, so it falls back to the shared credential instead of keeping to send a revoked one.
Resolved: The single-agent revoked-token replacement, Only the specified diff, including relevant context, and trusted base review criteria were read. No PR code was run, built, or installed. |
@JasonRUAN Thanks, The CI review is right that the same happens with several agents. The rest of our earlier comments still stands, starting with the real-CLI record in the body ([P1 blocking]). @jeff-r2026 For your merge call. |
…to a shared user token When `init --http`/`add-http` re-enrolls a shared user token (`hk-`) for several agents at once via `--agent`, each named agent now has its own per-agent `sk-` entry removed so it reports with the shared token instead of a stale, possibly revoked credential. Previously only one of the named agents was cleared — the rest kept their old per-agent entries, so a revoked or rotated token outlived the switch and those agents kept sending a dead credential. The fix drops the per-agent entry of every agent listed in `--agent` (filterAgents) rather than a single matched agent. A test switches multiple agents to a shared user token and asserts the unnamed agent keeps its own token, matching the updated CHANGELOG note.
Resolved: Switching either one or multiple explicitly selected agents to an Only the specified diff, relevant context, supplied PR description, and trusted base criteria were read. No PR code was run, built, or installed. |
Resolved: The description now supplies sufficient representative real-CLI verification. Single- and multiple-agent switches to Only the specified diff, relevant context, supplied description, and trusted base criteria were read. No PR code was run, built, or installed. |
Update at
Still open from our earlier comments, for the maintainer to weigh:
The CI review's new point is that a same-endpoint token update without @jeff-r2026 for the call on the remaining items. |
Summary
Two changes to the HTTP local agent.
Enrollment is per workspace, not per machine (
54219565). Previously, running the install prompt once on a device enrolled every workspace on it: each one got a project-binding prompt and was reported and synced. Now a workspace is enrolled only after the install prompt has run in it (__pending__). A workspace where it never ran is left alone: no binding prompt, no report, no sync.One access credential per agent (
91fbc05d). The backend binds ansk-credential to the first agent instance that reports with it, and an instance is one agent type on one machine, so agents sharing one token evict each other. HTTP team sources now carryagentTokens:init --httpandsource add-httpgain--agent <tool>to declare which agent the credential belongs to; hooks are injected only into that tool.--force, and other agents' credentials are untouched.hk-tokens stay shared by all agents.Type of Change
Test Plan
npx tsc --noEmitpassesnpm run lintpassesnpx vitest runpassesReal-CLI verification record
1. Install prompt, scenario A, workspace W1 (this repo):
init --http→pull→ hooks check →bind-project→hook-dispatch session-start~/.teamai/local-agent/config.jsonafter the run:agentTokens: { codebuddy: sk-8992f*** }, no sharedtoken, W1 recorded as__pending__withideType: codebuddy.2. Bind a project
3. Install prompt again in W1 (idempotent, same token): exit 0, binding to project 29 kept,
agentTokensunchanged. Then report and sync for the bound workspace, from~/.teamai/debug.log:Queue empty, no
FAILEDindebug.log.4. Per-workspace enrollment, unenrolled workspace W2 (
clawpro-ws2, freshgit init)No report and no sync was sent, and W2 is not in
workspaceBindings. Running the install prompt in W2 then printedWorkspace enrolled for local-agent sync: .../clawpro-ws2, and W2 became__pending__(ideType: codebuddy). The queue was empty. W1's binding and thecodebuddytoken were untouched.Related Issues
Notes for Reviewers