$npx -y skills add chanjing-ai/chan-skills --skill chanjing-credentials-guardGuide users to configure local Chanjing credentials safely via local commands only, and validate local token status when needed.
| 1 | # Chanjing Credentials Guard |
| 2 | |
| 3 | ## 功能说明 |
| 4 | |
| 5 | 仅通过**本地命令**引导用户配置/校验蝉镜 **AK/SK** 与 **Token**,打开登录页;**不在对话中索取密钥**。可配合其它 Chanjing 技能使用。 |
| 6 | |
| 7 | ## 运行依赖 |
| 8 | |
| 9 | - **python3** 与 `scripts/chanjing_config.py`、`scripts/open_login_page.py`、`scripts/chanjing_get_token.py` 等 |
| 10 | |
| 11 | ## 环境变量与机器可读声明 |
| 12 | |
| 13 | - 环境变量键名与说明:**`manifest.yaml`**(`environment` 段)及本文 |
| 14 | - 变量、写盘路径与权限:**`manifest.yaml`** |
| 15 | |
| 16 | ## 使用命令 |
| 17 | |
| 18 | - **ClawHub**(slug 以注册表为准):`clawhub run chanjing-credentials-guard` |
| 19 | - **本仓库**:`python skills/chanjing-credentials-guard/scripts/chanjing_config.py --status` |
| 20 | |
| 21 | --- |
| 22 | |
| 23 | ## When to Run |
| 24 | |
| 25 | 1. **When user asks to configure/get Chanjing keys (AK/SK)**: use this skill to guide local setup. |
| 26 | 2. **When credentials are missing/invalid before a Chanjing API call**: use this skill to recover local config. |
| 27 | |
| 28 | This skill is a **local credential guide**, not a cross-skill runtime dependency. |
| 29 | |
| 30 | ## Execution Flow |
| 31 | |
| 32 | ``` |
| 33 | 1. Check if local AK/SK exists |
| 34 | └─ No → Run open_login_page.py (open login in browser) → Ask user to run local config command |
| 35 | └─ Yes → Continue |
| 36 | |
| 37 | 2. Check if local Token exists and is not expired |
| 38 | └─ No → Call API to request/refresh Token → Save |
| 39 | └─ Yes → Continue |
| 40 | |
| 41 | 3. Prompt user to continue target action |
| 42 | ``` |
| 43 | |
| 44 | ## Credential Storage (AK/SK read from config file) |
| 45 | |
| 46 | AK/SK and Token are read from the **same config file**. Path and format follow the script **`scripts/chanjing_config.py`** in this skill. |
| 47 | |
| 48 | - **Path**: `~/.chanjing/credentials.json`(目录由 **`CHANJING_OPENAPI_CREDENTIALS_DIR`** 覆盖,兼容 **`CHANJING_CONFIG_DIR`**) |
| 49 | - **Format**: |
| 50 | ```json |
| 51 | { |
| 52 | "app_id": "Your Access Key", |
| 53 | "secret_key": "Your Secret Key", |
| 54 | "access_token": "Optional, auto-generated", |
| 55 | "expire_in": 1721289220 |
| 56 | } |
| 57 | ``` |
| 58 | |
| 59 | `expire_in` is a Unix timestamp. Token is valid for about 24 hours; refresh 5 minutes before expiry. |
| 60 | |
| 61 | ## When AK/SK Is Missing |
| 62 | |
| 63 | When local `app_id` or `secret_key` is missing: |
| 64 | |
| 65 | 1. **Open login page**: Run the `open_login_page.py` script to open the Chanjing sign-in page in the default browser (`https://www.chanjing.cc/openapi/login`). |
| 66 | 2. **Require local setup command** after the user obtains keys: |
| 67 | - Show command only; user runs it locally in terminal. |
| 68 | 3. **Do not request secrets in chat**: |
| 69 | - Never ask user to paste AK/SK in conversation. |
| 70 | - Never echo or store AK/SK in chat summaries. |
| 71 | 4. **After setting**: |
| 72 | - Ask user to run status check and then proceed to target action. |
| 73 | |
| 74 | Commands to set AK/SK (use either): |
| 75 | |
| 76 | ```bash |
| 77 | python scripts/chanjing_config.py --ak <your_app_id> --sk <your_secret_key> |
| 78 | python skills/chanjing-credentials-guard/scripts/chanjing_config.py --ak <your_app_id> --sk <your_secret_key> |
| 79 | ``` |
| 80 | |
| 81 | To open the login page manually: `python skills/chanjing-credentials-guard/scripts/open_login_page.py` |
| 82 | |
| 83 | ## Guide When User Wants to Generate Keys |
| 84 | |
| 85 | When the user clearly wants to **generate chanjing keys**, **get keys**, or **configure AK/SK**, follow this flow: |
| 86 | |
| 87 | ### Step 1: Check if already configured |
| 88 | |
| 89 | Check if local AK/SK already exists (read `~/.chanjing/credentials.json` for non-empty `app_id` and `secret_key`, or run `python skills/chanjing-credentials-guard/scripts/chanjing_config.py --status`). |
| 90 | |
| 91 | ### Step 2: Branch on result |
| 92 | |
| 93 | - **If already configured**: ask whether user wants to overwrite local config. |
| 94 | - If yes, run guide steps. |
| 95 | - If no, stop. |
| 96 | |
| 97 | - **If not configured**: Run the “Guide steps” below directly. |
| 98 | |
| 99 | ### Guide steps (when not configured or user confirmed re-apply) |
| 100 | |
| 101 | 1. **Run `open_login_page.py`** to open the Chanjing login page in the default browser. |
| 102 | 2. **Explain the page flow clearly**: |
| 103 | - New users are registered automatically and the current page will display `App ID` and `Secret Key` with copy buttons. |
| 104 | - Existing users may be redirected to the console; tell them to open the left-side **API 密钥** page to view or reset keys. |
| 105 | 3. **Ask user to run local command to configure AK/SK**: |
| 106 | ```bash |
| 107 | python skills/chanjing-credentials-guard/scripts/chanjing_config.py --ak <your_app_id> --sk <your_secret_key> |
| 108 | ``` |
| 109 | 4. **Secret handling rule**: |
| 110 | - Do not ask user to paste AK/SK in chat. |
| 111 | - If user shares secret in chat anyway, remind them to rotate keys and continue with local-command-only flow. |
| 112 | 5. **After setting**: |
| 113 | - Run status check: |
| 114 | `python skills/chanjing-credentials-guard/scripts/chanjing_config.py --status` |
| 115 | - Then proceed to target Chanjing action. |
| 116 | |
| 117 | ## Token API (see chanjing-openapi.yaml) |
| 118 | |
| 119 | ```http |
| 120 | POST https://open-api.chanjing.cc/open/v1/access_token |
| 121 | Content-Type: applicat |