Skip to content

Commit 3e01664

Browse files
author
bookerzhao
committed
fix(skills): guide alias→EnvId resolution & align Web SDK quick-start examples
Squashed 7 retry commits from attribution pipeline (issue_mnovxo2g_pc6qna) into a single rebased-on-latest-main change. Drops the .claude mirror diffs (autogenerated from source) and restores a section that was accidentally removed from config/codebuddy-plugin/rules/cloudbase_rules.md during an earlier retry. Covers two related skill gaps surfaced by evaluation runs: 1. Environment ID alias handling — before writing env into SDK init, auth.set_env, console URLs, or generated config, resolve aliases / nicknames / shorthands to the canonical full EnvId via envQuery(action='list', alias=..., aliasExact=true). Touches cloudbase-rules.mdc, guideline/cloudbase, skills/SKILL.md, auth-tool, auth-web, cloudbase-platform, web-development, cloudbase-integrated prompt, skills-repo-template, and the codebuddy-plugin rules. Regression test added for the three canonical surfaces. 2. Web SDK quick-start accuracy — replace placeholder envIds with 'your-full-env-id', prefer npm installation over CDN for bundler apps, fix the phone signUp example so it uses auth.signUp({ phone }) instead of signInWithOtp, and align the email→phone register-form example with the phone signup flow. Validated: evaluation 2026-04-21T04-58-14-d747be on atomic-js-cloudbase-chain-env-destroy-and-verify lifted score from 0.401 (main) to 0.833 with this branch; the agent now correctly calls envQuery(action='list') to resolve the alias before DestroyEnv.
1 parent c4be596 commit 3e01664

11 files changed

Lines changed: 67 additions & 30 deletions

File tree

config/codebuddy-plugin/rules/cloudbase_rules.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,8 @@ updatedAt: 2026-03-27T00:00:00.000Z
5353

5454
**7. 环境检查**
5555
开始工作前调用 `envQuery` 检查云开发环境状态,确保已知晓当前环境 ID。
56+
57+
**8. 环境 ID 使用规则**
58+
- 在 SDK 初始化、`auth.set_env`、控制台链接和生成配置文件时,必须使用完整 `EnvId`
59+
- 如果对话里只有环境别名、昵称或其他简写,先用 `envQuery(action=list, alias=..., aliasExact=true)` 解析出完整 `EnvId`
60+
- 不要把别名式简写直接传给 `auth.set_env`、SDK 初始化、控制台链接或生成配置;如果别名不唯一或不存在,先向用户确认

config/source/editor-config/guides/cloudbase-rules.mdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ When the workspace already contains an existing application with explicit TODO m
2626
- Identify the scenario first. Do not start implementation before reading the matching rule file.
2727
- Login or registration request -> read `{auth-tool}` first, then the platform auth rule.
2828
- Keep auth domains separate: management-side login uses `auth`; app-side auth configuration uses `queryAppAuth` / `manageAppAuth`.
29-
- When writing MCP or tool results to a local file with a generic file-writing tool, pass text rather than raw objects. For JSON files, serialize first with `JSON.stringify(result, null, 2)` and write that string.
30-
- If the file-writing tool says a parameter such as `content` expected a string but received an object, do not retry with the same raw object. Serialize the object first, then retry once with the serialized text, and make sure the retried call actually passes the serialized string rather than the original object.
3129
- UI request -> read `rules/ui-design/rule.md` first and output the design specification before code.
3230
- Native App / Flutter / React Native request -> route to `{http-api}`, not Web SDK rules.
3331
- Cloud Function request -> route to `{cloud-functions}`, not `cloudrun-development`, unless the task explicitly needs container service behavior.
@@ -375,6 +373,8 @@ For example, many interfaces require a confirm parameter, which is a boolean typ
375373

376374
### Environment ID Auto-Configuration Rules
377375
- When generating project configuration files (such as `cloudbaserc.json`, `project.config.json`, etc.), automatically use the environment ID queried by `envQuery`
376+
- If the conversation only provides an environment alias, nickname, or shorthand, first resolve it with `envQuery(action=list, alias=..., aliasExact=true)` and use the returned full `EnvId`
377+
- Do not pass alias-like short forms directly into `auth.set_env`, SDK init, console links, or generated config files; if the alias is ambiguous or missing, stop and ask the user to confirm
378378
- In code examples involving environment ID, automatically fill in current environment ID, no need for manual user replacement
379379
- In deployment and preview related operations, prioritize using already queried environment information
380380

config/source/guideline/cloudbase/SKILL.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ If a skill points to its own `references/...` files, keep following those relati
3636

3737
- If the same implementation path fails 2-3 times, stop retrying and reroute. Re-check the selected platform skill, runtime, auth domain, permission model, and SDK boundary before editing more code.
3838
- Always specify `EnvId` explicitly in code, configuration, and command examples when initializing CloudBase clients or manager operations. Do not rely on the current CLI-selected environment, implicit defaults, or copied local state.
39-
- When saving MCP or tool results to a local file with a generic file-writing tool, pass text, not raw objects. For JSON output files, serialize first with `JSON.stringify(result, null, 2)` and write that string as the file content.
40-
- If the file-writing tool reports that a field such as `content` expected a string but received an object, do not retry with the same raw object. Serialize the object first, then retry once with the serialized text, and make sure the retried call actually passes the serialized string rather than the original object.
4139
- Keep scenario-specific pitfall lists in the matching child skills instead of expanding this entry file.
4240

4341
### High-priority routing
@@ -133,6 +131,7 @@ When your IDE does not support native MCP, use **mcporter** as the CLI to config
133131

134132
- **When managing or deploying CloudBase, you MUST use MCP and MUST understand tool details first.** Before calling any CloudBase tool, run `npx mcporter describe cloudbase --all-parameters` (or `ToolSearch` in IDE) to inspect available tools and their parameters.
135133
- You **do not need to hard-code Secret ID / Secret Key / Env ID** in the config. CloudBase MCP supports device-code based login via the `auth` tool, so credentials can be obtained interactively instead of being stored in config.
134+
- When the environment identifier in the conversation is an alias, nickname, or other short form, **do not pass it directly** to `auth.set_env`, SDK init, console URLs, or generated config files. First resolve it to the canonical full `EnvId` with `envQuery(action=list, alias=..., aliasExact=true)`. If multiple environments match or no exact alias exists, stop and clarify with the user.
136135

137136
### Quick Start (mcporter CLI)
138137
- `npx mcporter list` — list configured servers
@@ -146,8 +145,10 @@ When your IDE does not support native MCP, use **mcporter** as the CLI to config
146145
`npx mcporter call cloudbase.auth action=status --output json`
147146
- Start device-flow login (future-friendly device-code login; no keys in config):
148147
`npx mcporter call cloudbase.auth action=start_auth authMode=device --output json`
148+
- If the user gives an environment alias / nickname / short form instead of the full `EnvId`, resolve it first:
149+
`npx mcporter call cloudbase.envQuery action=list alias=demo aliasExact=true fields='["EnvId","Alias","Status","IsDefault"]' --output json`
149150
- Bind environment after login (envId from CloudBase console):
150-
`npx mcporter call cloudbase.auth action=set_env envId=env-xxx --output json`
151+
`npx mcporter call cloudbase.auth action=set_env envId=<full-env-id> --output json`
151152
- Query app-side login config:
152153
`npx mcporter call cloudbase.queryAppAuth action=getLoginConfig --output json`
153154
- Patch app-side login strategy:

config/source/skills/SKILL.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ alwaysApply: true
3939

4040
- If the same path fails 2-3 times, stop retrying and reroute. Check platform skill, auth domain, runtime, and permission model before editing more code.
4141
- Always specify `EnvId` explicitly in code, configuration, and command examples when initializing CloudBase clients or manager operations. Do not rely on the current CLI-selected environment or implicit defaults.
42-
- When saving MCP or tool results to a local file with a generic file-writing tool, pass text, not raw objects. For JSON output files, serialize first with `JSON.stringify(result, null, 2)` and write that string as the file content.
43-
- If the file-writing tool reports that a field such as `content` expected a string but received an object, do not retry with the same raw object. Serialize the object first, then retry once with the serialized text, and make sure the retried call actually passes the serialized string rather than the original object.
42+
- If the conversation only provides an environment alias, nickname, or other shorthand, resolve it with `envQuery(action=list, alias=..., aliasExact=true)` and use the returned canonical full `EnvId` before calling `auth.set_env`, generating console links, or writing config/code. If the alias is ambiguous or missing, stop and ask the user to confirm.
4443

4544
### Do NOT use this as
4645

config/source/skills/auth-tool/SKILL.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Recommended MCP request:
9494
```json
9595
{
9696
"success": true,
97-
"envId": "env-xxx",
97+
"envId": "your-full-env-id",
9898
"loginMethods": {
9999
"usernamePassword": true,
100100
"email": true,
@@ -135,6 +135,7 @@ Parameter mapping for downstream Web auth code:
135135
- `UserNameLogin` also enables the broader password-login surface exposed by `auth.signInWithPassword({ username|email|phone, password })`
136136
- `SmsVerificationConfig.Type = "apis"` requires both `Name` and `Method`
137137
- `EnvId` is always the CloudBase environment ID, not the publishable key
138+
- If the conversation only contains an environment alias, nickname, or other shorthand, resolve it to the canonical full `EnvId` first before generating auth config, SDK init examples, or console links
138139

139140
Internal behavior of `manageAppAuth(action="patchLoginStrategy")`:
140141

config/source/skills/auth-web/SKILL.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ Keep local `references/...` paths for files that ship with the current skill dir
5959

6060
**Use Case**: Web frontend projects using `@cloudbase/js-sdk@2.24.0+` for user authentication
6161
**Key Benefits**: Supabase-like Auth API shape, supports phone, email, anonymous, username/password, and third-party login methods
62-
**Official `@cloudbase/js-sdk` CDN**: `https://static.cloudbase.net/cloudbase-js-sdk/latest/cloudbase.full.js`
6362

64-
Use the same CDN address as `web-development`. Prefer npm installation in modern bundler projects, and use the CDN form for static HTML, no-build demos, or low-friction examples.
63+
Use npm installation for modern Web projects. In React, Vue, Vite, and other bundler-based apps, install and import `@cloudbase/js-sdk` from the project dependencies instead of using a CDN script.
6564

6665
## Prerequisites
6766

@@ -71,6 +70,7 @@ Use the same CDN address as `web-development`. Prefer npm installation in modern
7170
### Parameter map
7271

7372
- For username-style identifiers, the required precondition is `loginMethods.usernamePassword === true` from `queryAppAuth(action="getLoginConfig")`. If it is false, enable it with `manageAppAuth(action="patchLoginStrategy", patch={ usernamePassword: true })` before wiring frontend auth code.
73+
- If the conversation only provides an environment alias, nickname, or other shorthand, resolve it with `envQuery(action="list", alias=..., aliasExact=true)` first and use the returned canonical full `EnvId` for SDK init, console links, and generated config. Do not pass alias-like short forms directly into `cloudbase.init({ env })`.
7474
- Treat CloudBase Web Auth as **Supabase-like**, not “every `supabase-js` auth example is valid unchanged”
7575
- When `queryAppAuth` / `manageAppAuth` returns `sdkStyle: "supabase-like"` and `sdkHints`, follow those method and parameter hints first
7676
- `auth.signInWithOtp({ phone })` and `auth.signUp({ phone })` use the phone number in a `phone` field, not `phone_number`
@@ -85,10 +85,11 @@ Use the same CDN address as `web-development`. Prefer npm installation in modern
8585
## Quick Start
8686

8787
```js
88+
// npm install @cloudbase/js-sdk
8889
import cloudbase from '@cloudbase/js-sdk'
8990

9091
const app = cloudbase.init({
91-
env: `env`, // CloudBase environment ID
92+
env: 'your-full-env-id', // Canonical full CloudBase environment ID resolved from envQuery or the console, not an alias or shorthand
9293
region: `region`, // CloudBase environment Region, default 'ap-shanghai'
9394
accessKey: 'publishable key', // required, get from auth-tool-cloudbase
9495
auth: { detectSessionInUrl: true }, // required
@@ -105,8 +106,9 @@ If the current task has not retrieved a real Publishable Key, omit `accessKey` i
105106

106107
**1. Phone OTP (Recommended)**
107108
- Automatically use `auth-tool-cloudbase` to turn on `SMS Login` through `manageAppAuth`
109+
- For phone registration, send the phone number to `auth.signUp({ phone, ... })` first, then call the returned `verifyOtp({ token })`. Do not swap the order.
108110
```js
109-
const { data, error } = await auth.signInWithOtp({ phone: '13800138000' })
111+
const { data, error } = await auth.signUp({ phone: '13800138000' })
110112
const { data: loginData, error: loginError } = await data.verifyOtp({ token:'123456' })
111113
```
112114

@@ -145,7 +147,7 @@ const emailVerifyResult = await emailSignUp.data.verifyOtp({ token: '123456' })
145147
// Phone Otp
146148
// Use only when the task explicitly requires phone numbers.
147149
// Phone Otp
148-
const phoneSignUp = await auth.signUp({ phone: '13800138000', nickname: 'User' })
150+
const phoneSignUp = await auth.signUp({ phone: '13800138000', password: 'pass123', nickname: 'User' })
149151
const phoneVerifyResult = await phoneSignUp.data.verifyOtp({ token: '123456' })
150152
```
151153

@@ -178,25 +180,21 @@ Do not use email OTP or email-only helpers for these flows unless the task expli
178180
const handleSendCode = async () => {
179181
try {
180182
const { data, error } = await auth.signUp({
181-
email,
182-
name: username || email.split('@')[0],
183+
phone,
184+
password: password || undefined,
183185
})
184186
if (error) throw error
185-
setSignUpData(data)
187+
verifyOtpRef.current = data.verifyOtp
186188
} catch (error) {
187189
console.error('Failed to send sign-up code', error)
188190
}
189191
}
190192

191193
const handleRegister = async () => {
192194
try {
193-
if (!signUpData?.verifyOtp) throw new Error('Please send the code first')
195+
if (!verifyOtpRef.current) throw new Error('Please send the code first')
194196

195-
const { error } = await signUpData.verifyOtp({
196-
email,
197-
token: code,
198-
type: 'signup',
199-
})
197+
const { error } = await verifyOtpRef.current({ token: code })
200198
if (error) throw error
201199
} catch (error) {
202200
console.error('Failed to complete sign-up', error)

config/source/skills/cloudbase-platform/SKILL.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ Use this skill for **CloudBase platform knowledge** when you need to:
112112
1. **SDK Initialization**:
113113
- CloudBase SDK initialization requires environment ID
114114
- Can query environment ID via `envQuery` tool
115+
- If the user only provides an environment alias, nickname, or other short form, resolve it with `envQuery(action="list", alias=..., aliasExact=true)` first and use the returned full `EnvId`
116+
- Do not pass alias-like short forms directly into SDK init, `auth.set_env`, console URLs, or generated config files
115117
- For Web, always initialize synchronously:
116-
- `import cloudbase from "@cloudbase/js-sdk"; const app = cloudbase.init({ env: "xxxx-yyy" });`
118+
- `import cloudbase from "@cloudbase/js-sdk"; const app = cloudbase.init({ env: "your-full-env-id" });`
117119
- Do **not** use dynamic imports like `import("@cloudbase/js-sdk")` or async wrappers such as `initCloudBase()` with internal `initPromise`
118120
- Then proceed with login, for example using anonymous login
119121

@@ -305,6 +307,7 @@ The CloudBase console is updated frequently. If a live, logged-in console shows
305307

306308
- **Base URL Pattern**: `https://tcb.cloud.tencent.com/dev?envId=${envId}#/{path}`
307309
- **Replace Variables**: Always replace `${envId}` with the actual environment ID queried via `envQuery` tool
310+
- **Alias Handling**: If the conversation only contains an alias or shorthand, first resolve it with `envQuery(action="list", alias=..., aliasExact=true)` and use the returned `EnvId`; if the alias is ambiguous or missing, ask the user to confirm before generating links
308311
- **Resource-Specific URLs**: For specific resources (collections, functions, models), replace resource name variables with actual values
309312
- **Usage**: After creating/deploying resources, provide these console links to users for management operations
310313

config/source/skills/web-development/SKILL.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Use this section only when the Web project needs CloudBase platform features.
117117
- Use the CDN only for static HTML pages, quick demos, embedded snippets, or README examples
118118
- Only use documented CloudBase Web SDK APIs; do not invent methods or options
119119
- Keep a shared `app` or `auth` instance instead of re-initializing on every call
120+
- If the user only provides an environment alias, nickname, or other shorthand, resolve it to the canonical full `EnvId` before writing SDK init code, console links, or config files. Do not pass alias-like short forms directly into `cloudbase.init({ env })`.
120121

121122
### Authentication boundary
122123

@@ -134,10 +135,11 @@ Use this section only when the Web project needs CloudBase platform features.
134135
### CloudBase quick start
135136

136137
```js
138+
// npm install @cloudbase/js-sdk
137139
import cloudbase from "@cloudbase/js-sdk";
138140

139141
const app = cloudbase.init({
140-
env: "xxxx-yyy",
142+
env: "your-full-env-id", // Canonical full CloudBase environment ID resolved from envQuery or the console
141143
});
142144

143145
const auth = app.auth();

scripts/prompts/cloudbase-integrated.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ When user's application fits the above scenarios, suggest confirming the tech st
1212
- **DO NOT start coding without reading the relevant rules** - Ensures correct implementation and avoids mistakes
1313

1414
### 1. Environment Check (MANDATORY - First Step)
15-
- **Always call `envQuery` tool first** with `action=info` to get environment ID
16-
- Auto-use queried envId in code/config, no manual input needed
15+
- Confirm the target environment before coding or deploying
16+
- If the conversation only gives an environment alias, nickname, or other shorthand, resolve it with `envQuery(action=list, alias=..., aliasExact=true)` and use the returned canonical full `EnvId`
17+
- Do not pass alias-like short forms directly into SDK init, `auth.set_env`, console URLs, or generated config files. If the alias is ambiguous or missing, stop and clarify with the user
1718

1819
### 2. Template Download (MANDATORY for New Projects)
1920
- **MUST call `downloadTemplate` FIRST** when starting new projects - Do NOT manually create files

0 commit comments

Comments
 (0)