Skip to content

Commit 732def5

Browse files
docs(client, cli): say environments activate writes no server state (#31806)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9PMDzvc5jP3MDLgvgcsqgUY)_ Fixes #31783 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:SDK `environments.activate` 的注释、环境接口列表,以及 CLI `os environments switch` / `create` 的注释、`--remote` 说明和 `--no-remote` 提示,改为如实描述:这个调用只确认调用者是该环境成员,不写任何服务器状态。 - 为什么改:原文说服务器会把当前环境写进会话,实际上 cloud 的路由什么都不写(回 `sessionUpdated: false`);当前环境只存在 CLI 本地的 credentials 里。 - 风险与回滚:只改注释、flag 说明和一行提示文字,行为不变。回滚即还原本 PR。 - 先看:`packages/cli/src/commands/environments/switch.ts`(flag 说明与提示)、`packages/client/src/index.ts`(`activate` 的 jsdoc)、`packages/cli/src/commands/environments/create.ts`。 - 两分钟验证:`git grep -n -E "session row|server session|server-side session|active_environment_id" packages/client/src packages/cli/src/commands/environments`,预期无输出。 - 需要你做的:无,席位落地。 ## What changes Option A of the card, wording only. Every place in `packages/client` and `packages/cli` that said the server writes or switches the session's active environment now says what happens: the `/activate` call reads the environment, confirms the caller is a member of it, and writes no server state; the active environment lives in the CLI's local credentials. Places changed (line numbers on head `dd02a89c`): 1. `packages/client/src/index.ts:3389`: the environments endpoint list (card place 1). 2. `packages/client/src/index.ts:3703-3711`: the `environments.activate` jsdoc (card place 2). It also says the answer carries `sessionUpdated: false` and that the CLI keeps the active environment locally and sends it per request (`X-Environment-Id`). 3. `packages/cli/src/commands/environments/switch.ts:15-18`: the command's doc comment (card place 3), plus `:21-22`, one added sentence that the active environment lives only in the local files. 4. `packages/cli/src/commands/environments/switch.ts:52`: the `--remote` flag description, now `Also call /activate on the server to confirm access (writes no server state)` (card place 4). 5. `packages/cli/src/commands/environments/switch.ts:76`: the code comment (card place 5). 6. `packages/cli/src/commands/environments/switch.ts:110`: the `--no-remote` note, now `(local only — /activate was not called)` (card place 6, user-visible text; FAIL round 1 replaced an inaccurate first wording, since `environments.get` has already resolved the environment on the server by then). 7. Further hits from the delta's grep (ruling 1), same claim in `packages/cli`: `packages/cli/src/commands/environments/create.ts:25-27` (doc comment) and `:125` (code comment, "the server session is already switched"). The grep ran over `packages/client` and `packages/cli` for `active_environment_id`, "session row", "server session", "server-side session", `sessionUpdated` and "session's active environment". Left as they are: `packages/cli/src/commands/logout.ts:29` ("Revoke server-side session", a real server write, unrelated), the `sessionUpdated` field in the `activate` return type (the wire shape), and `client.environments-namespace.test.ts:333-342`, which relays a stub envelope with `sessionUpdated: true` to pin pass-through and says nothing about what the server does. No code path, flag or default changes. `--remote` stays default-on (option B not taken). Changeset: `.changeset/31783-environments-activate-wording.md`, patch for `@objectstack/client` and `@objectstack/cli`. Rule followed: AGENTS.md Post-Task Checklist step 3 and os-dev's published-surface test. The client jsdoc ships in the published `.d.ts`, and the flag description and the `--no-remote` note ship in the CLI's help and output, so this is not the comments-only fast lane. The `--remote` description is not snapshot-tested and appears in no generated doc or help file (`git grep` for the old texts outside `switch.ts`: zero hits), so nothing was regenerated. `content/docs/deployment/cli.mdx:3137-3138` already describes switch and create as local-only and needs no change. ## Tests No test changes. No test pins the old texts. ## Acceptance notes - Option B (drop the default-on `/activate` call) is not in this PR. `switch` already calls `environments.get` on the same id just before `/activate`, so the default call adds a second access check and nothing else. Seat ruling at review: no card for B. ## Verification Head `dd02a89c` (FAIL round 1 fix on top of `d9a5e8ff`, which is `ea8fe660` plus a merge of `origin/main` at `2b752aa4`). All three heads were measured green; the numbers below are `dd02a89c`'s. <details><summary>Builds, tests, typecheck, lint</summary> - `turbo run build --concurrency=2 --filter='./packages/**' --filter='./examples/**'` under the lock: `VERDICT command-exit 0`. - `pnpm --filter @objectstack/client test`: `Test Files 56 passed (56)`, `Tests 721 passed (721)`; then `pnpm --filter @objectstack/client typecheck` green. - `pnpm --filter @objectstack/cli typecheck`, then `pnpm --filter @objectstack/cli exec vitest run --project unit --maxWorkers=2`: `Test Files 406 passed (406)`, `Tests 5777 passed (5777)`. One lock run for the client and cli legs: `VERDICT command-exit 0`. The integration tier is left to CI (no integration or spawn-entry file touched). - `eslint --no-inline-config` on the three touched files: exit 0 (re-run on `switch.ts` at `dd02a89c`: exit 0) (neither package has its own lint script). </details> <details><summary>Derived gates</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at `dd02a89c`: 65 commands, each run with its exit code captured before any pipe; all 65 exit 0. Reconciliation: `dispatch-gates --ran: 65 derived famil(ies) accounted for — 65 run, 0 NOT-MEASURED`. On the first round, four gates first answered exit 3 (prerequisite not met: the teardown self-test fixture commit, and dist for the dual-build, i18n-coverage and skill-examples gates). They went green after fetching the fixture commit and building packages and examples. </details> No ablation: wording only, no tested behaviour changed. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmRXLCQFr5TnPia6y3J)_ <!-- signed: domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0243357 commit 732def5

4 files changed

Lines changed: 31 additions & 13 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@objectstack/client': patch
3+
'@objectstack/cli': patch
4+
---
5+
6+
docs(client, cli): `environments.activate` and `os environments switch` no longer say the server writes the session's active environment
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
The control plane's `POST /api/v1/cloud/environments/:id/activate` reads the environment, confirms the caller is a member of it and writes no server state (it answers `sessionUpdated: false`). The SDK's `environments.activate` jsdoc, the environments endpoint list, the comments of `os environments switch` and `os environments create`, and the `--remote` flag description of `os environments switch` all said it updated the server-side session. They now say what happens: the call confirms access, and the active environment lives only in the CLI's local credentials (`~/.objectstack/credentials.json`, and `~/.objectstack/cloud.json` where that control plane is the one recorded there). `os environments switch --no-remote` now prints `(local only — /activate was not called)` in place of `(local only — server session unchanged)`. No behaviour changes.

‎packages/cli/src/commands/environments/create.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import { recordCloudActiveEnvironmentId } from '../../utils/active-environment.j
2222
* session where it targets the server, else `cloud.json`'s (the order is
2323
* written once, there).
2424
*
25-
* On success, optionally activates the new environment for the current session
26-
* and persists `activeEnvironmentId` into `~/.objectstack/credentials.json`
25+
* On success, optionally activates the new environment for later CLI calls:
26+
* the `/activate` call confirms access and writes no server state, and the
27+
* CLI persists `activeEnvironmentId` into `~/.objectstack/credentials.json`
2728
* (unless `--no-activate` is passed, or the create ran on `cloud.json`'s
2829
* session, whose server is not the one `credentials.json` names). When the
2930
* control plane it just talked to IS the one `~/.objectstack/cloud.json`
@@ -121,7 +122,7 @@ export default class EnvironmentsCreate extends Command {
121122
await client.environments.activate(res.environment.id);
122123

123124
// Cloud store first, for the reason `os environments switch` writes
124-
// it first: the server session is already switched by the call above,
125+
// it first: the server has already confirmed access in the call above,
125126
// so the publish-side record must not be lost to a failure in the
126127
// runtime store below (a user who only ran `os cloud login` has no
127128
// `credentials.json` at all). The url gate inside the helper decides

‎packages/cli/src/commands/environments/switch.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import { activateCloudDeployTarget } from '../../utils/runtime-target.js';
1212
*
1313
* Authenticates through `createControlPlaneApiClient` — `credentials.json`'s
1414
* session where it targets the server, else `cloud.json`'s (the order is
15-
* written once, there). Calls `POST /api/v1/cloud/environments/:id/activate`
16-
* to update the server-side session, then persists `activeEnvironmentId` into
15+
* written once, there). Calls `POST /api/v1/cloud/environments/:id/activate`,
16+
* which confirms the caller is a member of the environment and writes no
17+
* server state, then persists `activeEnvironmentId` into
1718
* `~/.objectstack/credentials.json` so subsequent CLI commands (and any
1819
* client they create via `createApiClient`) automatically target this
1920
* environment — unless the switch ran on `cloud.json`'s session, whose server
20-
* is not the one `credentials.json` names.
21+
* is not the one `credentials.json` names. The active environment lives only
22+
* in those local files: the server keeps no record of it.
2123
*
2224
* When the control plane it just talked to IS the one `~/.objectstack/cloud.json`
2325
* records, the same id is written there as well, so `os package publish --install`
@@ -47,7 +49,7 @@ export default class EnvironmentsSwitch extends Command {
4749
url: Flags.string({ char: 'u', description: 'Server URL', env: 'OS_CLOUD_URL' }),
4850
token: Flags.string({ char: 't', description: 'Authentication token', env: 'OS_TOKEN' }),
4951
remote: Flags.boolean({
50-
description: 'Also call /activate on the server (updates the session row)',
52+
description: 'Also call /activate on the server to confirm access (writes no server state)',
5153
default: true,
5254
allowNo: true,
5355
}),
@@ -71,7 +73,7 @@ export default class EnvironmentsSwitch extends Command {
7173
await client.environments.activate(environment.id);
7274
}
7375

74-
// Cloud store first: the server session is already switched at this
76+
// Cloud store first: the server has already confirmed access at this
7577
// point, so the publish-side record must not be lost to a failure in the
7678
// runtime store below (a user who only ran `os cloud login` has no
7779
// `credentials.json` at all).
@@ -105,7 +107,7 @@ export default class EnvironmentsSwitch extends Command {
105107
console.log(' ⚠ no local credential store to record it in — run `os login` or `os cloud login`');
106108
}
107109
if (!flags.remote) {
108-
console.log(' (local only — server session unchanged)');
110+
console.log(' (local only — /activate was not called)');
109111
}
110112
console.log('');
111113
} catch (error: any) {

‎packages/client/src/index.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,7 +3386,7 @@ export class ObjectStackClient {
33863386
* - GET /api/v1/cloud/environments/:id → get one (with database info)
33873387
* - POST /api/v1/cloud/environments → provision a new environment
33883388
* - PATCH /api/v1/cloud/environments/:id → update (display_name, is_default, metadata)
3389-
* - POST /api/v1/cloud/environments/:id/activate → set as session's active environment
3389+
* - POST /api/v1/cloud/environments/:id/activate → confirm the caller can use it (writes no server state)
33903390
* - POST /api/v1/cloud/environments/:id/credentials/rotate → rotate credential
33913391
*
33923392
* That PATCH accept-set is the WHOLE set. `plan`, `status` and `visibility`
@@ -3701,9 +3701,13 @@ export class ObjectStackClient {
37013701
},
37023702

37033703
/**
3704-
* Activate this environment for the current session. The server writes
3705-
* `active_environment_id` on the better-auth session; subsequent requests
3706-
* are routed to this environment's database.
3704+
* Confirm the caller can use this environment. The control plane reads
3705+
* the environment, checks the caller is a member of it, and answers it
3706+
* back. It writes no server state: the session is not changed (the answer
3707+
* carries `sessionUpdated: false`), and later requests are not routed by
3708+
* this call. Which environment a client targets is the caller's own
3709+
* choice: the CLI keeps it in its local credentials and sends it on each
3710+
* request.
37073711
*/
37083712
activate: async (id: string) => {
37093713
const res = await this.fetch(`${this.baseUrl}/api/v1/cloud/environments/${encodeURIComponent(id)}/activate`, {

0 commit comments

Comments
 (0)