cws-release 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,11 +20,127 @@ npx cws-release check # proves the credentials work, in three seconds
20
20
  npx cws-release release # upload -> submit for review -> print the state
21
21
  ```
22
22
 
23
- Prerequisites (`check` will tell you what is missing): the item already exists
24
- in the store, the publisher has 2FA on, and the service account is added under
25
- **Account** in the [Developer Dashboard](https://chrome.google.com/webstore/devconsole).
26
- The API cannot create a new item — the first upload and the listing tabs are
27
- manual.
23
+ Nothing above works until the [one-time setup](#one-time-setup) is done: the API
24
+ enabled, a service-account key, that account added to the publisher, and two
25
+ identifiers in `.cws.json`. `check` names whichever piece is missing. Budget
26
+ about ten minutes for it; you will not repeat it per release.
27
+
28
+ The API cannot create a new item — the first upload and the listing, privacy and
29
+ visibility tabs are manual.
30
+
31
+ ## One-time setup
32
+
33
+ Once per **publisher account**, not per extension. Four pieces of state have to
34
+ agree — the API enabled, the key, the dashboard's service-account entry, and
35
+ `.cws.json` — and any mismatch fails with `PUBLISHER_FORBIDDEN` (HTTP 403) even
36
+ when the key itself is perfectly valid. One symptom, four possible causes: work
37
+ through them in this order and the first failure names the piece that is wrong.
38
+
39
+ **1. Enable the Chrome Web Store API** in a Google Cloud project:
40
+
41
+ <https://console.cloud.google.com/apis/library/chromewebstore.googleapis.com>
42
+
43
+ An account that is otherwise fine but runs in a project with this API disabled
44
+ is rejected at the call, not at authentication — it looks like a permissions
45
+ bug and is not one. Select the right project in the console's project picker
46
+ before you click **Enable**.
47
+
48
+ ![The Chrome Web Store API product page in Google Cloud, with the Enable button](docs/assets/enable-api.webp)
49
+
50
+ *The product page carries the **Enable** button. Menu labels follow your console
51
+ language, and Google rearranges these pages from time to time — if the layout
52
+ differs, look for the API name and an enable control.*
53
+
54
+ **2. Create a service account, with no IAM roles:**
55
+
56
+ <https://console.cloud.google.com/iam-admin/serviceaccounts/create>
57
+
58
+ Name it something recognisable (`cws-release`), then **Create and continue** →
59
+ **Continue** → **Done**. Grant no role: access comes from step 4, not from IAM.
60
+
61
+ **3. Create and download a JSON key.** Open the account → **Keys** → **Add key**
62
+ → **Create new key** → **JSON**. Move it out of `~/Downloads` and lock it down
63
+ before you do anything else — see [Key handling](#key-handling):
64
+
65
+ ```sh
66
+ mkdir -p ~/.config/cws
67
+ mv ~/Downloads/<project>-<hex>.json ~/.config/cws/service-account.json
68
+ chmod 700 ~/.config/cws
69
+ chmod 600 ~/.config/cws/service-account.json
70
+ ```
71
+
72
+ **4. Authorize the account in the Developer Dashboard — this is the step that
73
+ actually grants access.** Skipping it returns `PUBLISHER_FORBIDDEN` for every
74
+ item, real or invented:
75
+
76
+ <https://chrome.google.com/webstore/devconsole>
77
+
78
+ Open **Settings** from the sidebar. The service-account field is in the
79
+ **Management** section — *not* under the **Account → Profile** group, which
80
+ holds the display name, contact email, trader declaration and address.
81
+ Paste the `…@….iam.gserviceaccount.com` email shown in the Google Cloud console
82
+ and save; it then appears in the table with today's join date. One publisher
83
+ accepts **one** service account, and the publisher account needs 2-step
84
+ verification enabled.
85
+
86
+ ![The dashboard Settings page, with the Service account table in the Management section](docs/assets/service-account.webp)
87
+
88
+ *The **Service account** table sits in the **Management** block of Settings.
89
+ The one row is the account, keyed by email, with its join date. Google's own
90
+ labels may change; the block name is the anchor, not the row.*
91
+
92
+ **5. Copy the two identifiers into `.cws.json`.** Both are on the **Settings**
93
+ page:
94
+
95
+ - **Publisher ID** — a field under **Profile** in the Account group; it is also
96
+ the `/webstore/devconsole/<publisherId>/settings` segment of the URL.
97
+ - **Item ID** — the 32-character extension id, from the item's own URL in the
98
+ dashboard or from `chrome://extensions`.
99
+
100
+ These are per-publisher values: copy yours, never another project's. Identifiers
101
+ are safe to commit; the key is not.
102
+
103
+ ![The Settings page showing the Publisher ID field under Profile](docs/assets/publisher-id.webp)
104
+
105
+ *The **Publisher ID** is the short field under **Profile**, next to the display
106
+ name and contact email — not in the **Management** block above. In this shot
107
+ it is partly redacted; yours is a UUID-like string such as
108
+ `7c6b…-…-…-…-…`.*
109
+
110
+ **6. Point the CLI at the key** — in the shell you will release from, or as a CI
111
+ secret:
112
+
113
+ ```sh
114
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
115
+ ```
116
+
117
+ Then `npx cws-release check`. It exchanges the token and calls `fetchStatus`, so
118
+ a `PUBLISHER_FORBIDDEN` at this point means step 4 or 5 — not the key.
119
+
120
+ `CWS_ACCESS_TOKEN` skips the key entirely for a one-off run
121
+ (`gcloud auth print-access-token --scopes=https://www.googleapis.com/auth/chromewebstore`);
122
+ it expires in about an hour.
123
+
124
+ ## Key handling
125
+
126
+ The service-account key is a long-lived credential for every item under the
127
+ publisher. Treat it as one secret, not as config:
128
+
129
+ - **Keep it out of the repository.** `~/.config/cws/` or a CI secret variable —
130
+ never `.cws.json`, which is committed, and never pasted into an issue or a
131
+ chat. When a conversation means to *report* a key, report its path and the
132
+ account email instead; neither is a secret.
133
+ - **Directory `700`, file `600`** (the `chmod` in step 3). Move it out of
134
+ `~/Downloads` straight after Google hands it over: download folders are
135
+ synced, indexed and scanned by other tools.
136
+ - **No `set -x` around it**, and no `--verbose` on a script that exports it. The
137
+ CLI never prints the key; your shell should not either.
138
+ - **Lost or exposed?** Delete the key in Google Cloud (**Keys** → delete),
139
+ create a new one, and point `CWS_SERVICE_ACCOUNT_FILE` at it. The dashboard
140
+ entry keys off the account *email*, which does not change, so step 4 stands.
141
+ - Doubling as a backstop, `.gitignore` in every extension repository can carry
142
+ `service-account*.json`. A backstop is not a plan — the file does not belong
143
+ in the working tree in the first place.
28
144
 
29
145
  ## Why this one
30
146
 
@@ -34,11 +150,9 @@ manual.
34
150
  dashboard, covers every item under that publisher and does not expire.
35
151
  - **Honest output.** `publish` returns a review state, not "live"; the CLI prints
36
152
  the store's state instead of inventing one.
37
- - **Built for agents.** Every command accepts `--json` and returns
38
- `{ ok, command, data }`; a failure returns a stable `error.code` and a hint on
39
- what to fix. No log scraping — see [For agents and scripts](#for-agents-and-scripts).
40
- - **Ships as a [skill](SKILL.md)** for coding agents: the procedure, the
41
- guardrails and the CLI live together.
153
+ - **Built for agents.** One command installs the skill
154
+ (`npx skills add XCreativeStudio/cws-release`), and the CLI underneath answers
155
+ in JSON with stable error codes — see [Using it with an AI agent](#using-it-with-an-ai-agent).
42
156
 
43
157
  ## Install
44
158
 
@@ -68,8 +182,11 @@ Commit identifiers, never secrets, in `.cws.json` (`init` writes the template):
68
182
  }
69
183
  ```
70
184
 
71
- `itemId` is the 32-character extension id; `zip` may be a single `*`/`?` glob
72
- because build output usually carries the version. Point the CLI at the key:
185
+ `publisherId` and `itemId` come from the dashboard's **Settings** page
186
+ ([step 5](#one-time-setup)); `itemId` is the 32-character extension id. `zip`
187
+ may be a single `*`/`?` glob, because build output usually carries the version.
188
+
189
+ The key is pointed at separately, by environment variable:
73
190
 
74
191
  ```sh
75
192
  export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json" # local
@@ -86,7 +203,7 @@ override the matching keys.
86
203
 
87
204
  | Command | What it does |
88
205
  | --- | --- |
89
- | `cws init` | Write a `.cws.json` template and the agent skill into this repository |
206
+ | `cws init` | Write a `.cws.json` template plus the agent skill into this repository; leaves existing files alone without `--force` |
90
207
  | `cws check` | Exchange the token and call `fetchStatus`; separates "the secret is set" from "the secret works" |
91
208
  | `cws upload [zip]` | Upload the package, then wait for asynchronous processing |
92
209
  | `cws publish` | Submit the uploaded package for review |
@@ -101,10 +218,21 @@ Flags: `--staged` (`STAGED_PUBLISH`), `--live` (`DEFAULT_PUBLISH`),
101
218
  `status` is the honest answer to "is it live yet?": `PUBLISHED` in
102
219
  `publishedItemRevisionStatus` means live, anything else is still in review.
103
220
 
104
- ## For agents and scripts
221
+ ## Using it with an AI agent
105
222
 
106
- `--json` turns the CLI into an interface instead of a log to scrape. Success
107
- goes to stdout; progress lines go to stderr.
223
+ Install the skill — the [skills CLI][skills-cli] handles Claude Code, Codex,
224
+ Cursor, Copilot and 70+ other agents:
225
+
226
+ ```sh
227
+ npx skills add XCreativeStudio/cws-release
228
+ ```
229
+
230
+ It lands in `.agents/skills/chrome-web-store-publish/` and brings **both** the
231
+ procedure ([`SKILL.md`](SKILL.md)) and a working copy of the CLI, so the agent can
232
+ run `node .agents/skills/chrome-web-store-publish/cws.mjs check` offline.
233
+
234
+ Then the CLI answers in JSON instead of logs. Success goes to stdout; progress
235
+ lines go to stderr.
108
236
 
109
237
  ```jsonc
110
238
  // cws release --json (stdout)
@@ -117,7 +245,7 @@ found among the progress lines:
117
245
  ```sh
118
246
  cws:json {"ok":false,"error":{"code":"PUBLISHER_FORBIDDEN","status":403,
119
247
  "reason":"PERMISSION_DENIED","message":"HTTP 403: PERMISSION_DENIED: …",
120
- "hint":"Add the service-account email under Account in the Developer Dashboard, and check publisherId in .cws.json."}}
248
+ "hint":"Add the service-account email in the Developer Dashboard under Settings, in the Management section, then check publisherId in .cws.json."}}
121
249
  ```
122
250
 
123
251
  Extract it with `sed -n 's/^cws:json //p'` and branch on `error.code`, which
@@ -126,13 +254,54 @@ never changes meaning. The most common ones:
126
254
  | `code` | Usual fix |
127
255
  | --- | --- |
128
256
  | `NO_CREDENTIALS` | Set `CWS_SERVICE_ACCOUNT_FILE` or `CWS_ACCESS_TOKEN` |
129
- | `PUBLISHER_FORBIDDEN` | Add the service account in the dashboard; check `publisherId` |
257
+ | `CREDENTIALS_UNREADABLE` | The key file is missing or not valid JSON — usually newlines lost when passing `private_key` through a shell or CI variable |
258
+ | `AUTH_FAILED` | Re-exchange the token; tokens last about an hour, and a twice-failed exchange means the key itself is wrong |
259
+ | `PUBLISHER_FORBIDDEN` | The account is not added on the dashboard's **Settings** page — or `publisherId` is wrong. This 403 also masks a disabled API, so work through [steps 1–5](#one-time-setup) in order |
130
260
  | `UPLOAD_REJECTED` | Raise the manifest version above the published one |
131
261
 
132
262
  All 14 codes, with meanings and fixes: [docs/errors.md](docs/errors.md). Exit
133
263
  codes stay coarse for shells — `0` success, `1` failure, `2` usage — and the
134
264
  keys of `data` are the raw API responses, unchanged.
135
265
 
266
+ ### When npm is not reachable
267
+
268
+ Not every environment can install from npm: some agents only read a skill
269
+ directory, and a locked-down CI runner may have no registry access at all.
270
+ Either a `git clone` or `npx cws-release init` drops the same two files into the
271
+ same place, and the CLI runs from there with no install:
272
+
273
+ ```sh
274
+ git clone --depth 1 https://github.com/XCreativeStudio/cws-release.git \
275
+ .agents/skills/chrome-web-store-publish
276
+ ```
277
+
278
+ [INSTALL.md](INSTALL.md) compares every option. The skill is a convenience — the
279
+ CLI and the [one-time setup](#one-time-setup) are the contract, and both work
280
+ from a terminal with no agent in the loop.
281
+
282
+ ### A worked run
283
+
284
+ Publishing an MV3 extension whose build output is
285
+ `.output/<name>-<version>-chrome.zip` to a publisher that already owns the item:
286
+
287
+ ```sh
288
+ cd my-extension
289
+ npx cws-release init # writes .cws.json + the skill
290
+ # paste publisherId and itemId from the dashboard Settings page
291
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
292
+
293
+ npx cws-release check # credentials + store access, ~3 s
294
+ npx cws-release upload # glob picks the only zip; waits for processing
295
+ npx cws-release publish --staged # submit for review, deploy manually later
296
+ npx cws-release status # current live version and the one in review
297
+ ```
298
+
299
+ `--staged` (`STAGED_PUBLISH`) is the version for a release you want to watch:
300
+ the review approves it, then deploying is your explicit act. `--live`
301
+ (`DEFAULT_PUBLISH`) goes live as soon as review passes. Use `--staged` for the
302
+ first release of an item and for anything that touches permissions; the CLI
303
+ never claims a version is live — `cws status` reads the store and says so.
304
+
136
305
  ## CI
137
306
 
138
307
  As a GitHub Action — it installs the CLI, checks the Node version, and exposes
@@ -180,6 +349,8 @@ The suite covers JWT signing, config precedence, upload/publish request shapes,
180
349
  asynchronous polling, error mapping, the JSON error contract, and real HTTP
181
350
  round trips against a local server. No credentials needed.
182
351
 
352
+ [skills-cli]: https://github.com/vercel-labs/skills
353
+
183
354
  ## License
184
355
 
185
356
  MIT
package/README.zh-CN.md CHANGED
@@ -19,9 +19,109 @@ npx cws-release check # 三秒内验证凭据可用
19
19
  npx cws-release release # 上传 → 提交审核 → 打印状态
20
20
  ```
21
21
 
22
- 前置条件(`check` 会告诉你还差什么):条目已在商店中存在、发布者已开启两步验证、
23
- 服务账号已加入[开发者后台](https://chrome.google.com/webstore/devconsole)的
24
- **Account** 页。API 无法创建新条目——首次上传和商店信息页需手动完成。
22
+ 上面的命令都要先完成[一次性配置](#一次性配置)才能用:启用 API、拿到服务账号密钥、
23
+ 把该账号加入发布者、并在 `.cws.json` 里填好两个标识符。缺哪一块 `check` 就报哪一块。
24
+ 这件事大约十分钟,不必每次发版重复。
25
+
26
+ API 无法创建新条目——首次上传和商店信息、隐私、可见性页都需手动完成。
27
+
28
+ ## 一次性配置
29
+
30
+ 每个**发布者账号**做一次,不是每个扩展做一次。有四处状态必须一致:API 已启用、
31
+ 密钥、后台里的服务账号条目、`.cws.json`。任一处不一致都会返回
32
+ `PUBLISHER_FORBIDDEN`(HTTP 403),即使密钥本身完全正确。**同一个症状,四种可能的
33
+ 原因**——按下面的顺序走,第一个失败就会告诉你缺的是哪一块。
34
+
35
+ **1. 在 Google Cloud 项目里启用 Chrome Web Store API:**
36
+
37
+ <https://console.cloud.google.com/apis/library/chromewebstore.googleapis.com>
38
+
39
+ 点 **Enable**。项目里没启用这个 API 时,请求是在调用阶段被拒的,而不是在认证阶段
40
+ ——它看起来像权限问题,其实不是。点之前先在控制台顶部的项目选择器里选对项目。
41
+
42
+ ![Google Cloud 里 Chrome Web Store API 的产品页,以及启用按钮](docs/assets/enable-api.webp)
43
+
44
+ *产品页上的**启用**按钮。菜单文字会跟随控制台语言,谷歌也会不时调整页面布局;如果
45
+ 界面和这里不同,就找 API 名字和一个启用控件。*
46
+
47
+ **2. 创建服务账号,不授予任何 IAM 角色:**
48
+
49
+ <https://console.cloud.google.com/iam-admin/serviceaccounts/create>
50
+
51
+ 起个好认的名字(如 `cws-release`),然后 **Create and continue** → **Continue**
52
+ → **Done**。不要授予角色:权限来自第 4 步,不是 IAM。
53
+
54
+ **3. 创建并下载 JSON 密钥。** 打开该账号 → **Keys** → **Add key** →
55
+ **Create new key** → **JSON**。先把它移出 `~/Downloads` 并收紧权限,再干别的
56
+ ——见[密钥保护](#密钥保护):
57
+
58
+ ```sh
59
+ mkdir -p ~/.config/cws
60
+ mv ~/Downloads/<project>-<hex>.json ~/.config/cws/service-account.json
61
+ chmod 700 ~/.config/cws
62
+ chmod 600 ~/.config/cws/service-account.json
63
+ ```
64
+
65
+ **4. 在开发者后台授权这个服务账号——真正授予权限的是这一步。** 跳过它,任何条目
66
+ (真的还是编的)都会返回 `PUBLISHER_FORBIDDEN`:
67
+
68
+ <https://chrome.google.com/webstore/devconsole>
69
+
70
+ 从侧边栏进入 **Settings** 页。服务账号的填写框在 **Management** 区块里——**不是**
71
+ 侧边栏 **Account → Profile** 那一组(那里是显示名、联系邮箱、trader 声明和地址)。
72
+ 粘贴 Google Cloud 控制台里显示的 `…@….iam.gserviceaccount.com` 邮箱并保存;随后它
73
+ 会出现在表格中,带当天的加入日期。一个发布者只接受**一个**服务账号,且发布者账号
74
+ 必须已开启两步验证。
75
+
76
+ ![后台 Settings 页,Management 区块里的 Service account 表格](docs/assets/service-account.webp)
77
+
78
+ ***Service account** 表格位于 Settings 页的 **Management** 区块。表中那一行就是该账号,
79
+ 以邮箱为标识,并带加入日期。谷歌的界面文字可能变,认准区块名而不是某一行的样式。*
80
+
81
+ **5. 把两个标识符填进 `.cws.json`。** 两者都在 **Settings** 页:
82
+
83
+ - **Publisher ID** —— Account 组 Profile 区里的一个字段;也出现在该页 URL 的
84
+ `/webstore/devconsole/<publisherId>/settings` 中。
85
+ - **Item ID** —— 32 位扩展 ID,来自后台里该条目的 URL,或 `chrome://extensions`。
86
+
87
+ 这些是按发布者区分的值:填你自己的,不要照抄别人项目里的。标识符可以安全提交,
88
+ 密钥不行。
89
+
90
+ ![Settings 页 Profile 区的 Publisher ID 字段](docs/assets/publisher-id.webp)
91
+
92
+ ***Publisher ID** 是 **Profile** 区里的那个短字段,在显示名和联系邮箱旁边——不在上面
93
+ 的 **Management** 区块里。图里它做了部分打码;你自己的是一串形如
94
+ `7c6b…-…-…-…-…` 的 UUID。*
95
+
96
+ **6. 让 CLI 找到密钥** —— 写在你要执行发布的 shell 里,或作为 CI 密钥:
97
+
98
+ ```sh
99
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
100
+ ```
101
+
102
+ 然后 `npx cws-release check`。它会换取令牌并调用 `fetchStatus`,所以此时若仍返回
103
+ `PUBLISHER_FORBIDDEN`,问题在第 4 步或第 5 步,不在密钥。
104
+
105
+ 一次性运行也可以完全不用密钥,改用 `CWS_ACCESS_TOKEN`
106
+ (`gcloud auth print-access-token --scopes=https://www.googleapis.com/auth/chromewebstore`),
107
+ 它约一小时后过期。
108
+
109
+ ## 密钥保护
110
+
111
+ 服务账号密钥是该发布者下所有条目的长期凭据。把它当**一个秘密**对待,而不是配置:
112
+
113
+ - **不要放进仓库。** 放 `~/.config/cws/` 或 CI 密钥变量——绝不放进会被提交的
114
+ `.cws.json`,也绝不粘贴到 issue 或对话里。对话需要"报"密钥时,报它的**路径**和
115
+ 账号邮箱即可,两者都不是秘密。
116
+ - **目录 `700`、文件 `600`**(即第 3 步的 `chmod`)。谷歌刚把它下载下来就立刻移出
117
+ `~/Downloads`:下载目录会被其他工具同步、索引和扫描。
118
+ - **不要在它周围 `set -x`**,也不要给导出它的脚本加 `--verbose`。CLI 从不打印密钥,
119
+ 你的 shell 也不该。
120
+ - **丢了或泄漏了?** 去 Google Cloud 删掉该密钥(**Keys** → 删除),新建一个,
121
+ 再把 `CWS_SERVICE_ACCOUNT_FILE` 指向新文件。后台的那条记录绑定的是账号**邮箱**,
122
+ 邮箱不变,所以第 4 步不用重做。
123
+ - 作为兜底,每个扩展仓库的 `.gitignore` 可以加一行 `service-account*.json`。兜底不等于
124
+ 方案——这个文件本来就不该出现在工作树里。
25
125
 
26
126
  ## 为什么用它
27
127
 
@@ -31,9 +131,8 @@ npx cws-release release # 上传 → 提交审核 → 打印状态
31
131
  且不会过期。
32
132
  - **诚实的输出。** `publish` 返回的是审核状态而不是"已上线";CLI 打印商店的真实状态,
33
133
  不编造。
34
- - **为 AI 设计。** 所有命令都支持 `--json`,返回 `{ ok, command, data }`;失败返回
35
- 稳定的 `error.code` 和修复提示,不需要爬日志——见[给 AI 和脚本使用](#给-ai-和脚本使用)。
36
- - **附带 [skill](SKILL.md)** 给编码助手:操作流程、护栏和 CLI 放在一起。
134
+ - **为 AI 设计。** 一条命令装好 skill(`npx skills add XCreativeStudio/cws-release`),
135
+ 底层 CLI 用 JSON 作答、错误码稳定——见[配合 AI 助手使用](#配合-ai-助手使用)。
37
136
 
38
137
  ## 安装
39
138
 
@@ -61,8 +160,10 @@ npx cws-release release # 上传 → 提交审核 → 打印状态
61
160
  }
62
161
  ```
63
162
 
64
- `itemId` 是 32 位的扩展 ID;`zip` 可以是单个 `*`/`?` 通配符,因为构建产物通常带版本号。
65
- 让 CLI 找到密钥:
163
+ `publisherId` 和 `itemId` 来自后台的 **Settings** 页([第 5 步](#一次性配置));
164
+ `itemId` 是 32 位扩展 ID。`zip` 可以是单个 `*`/`?` 通配符,因为构建产物通常带版本号。
165
+
166
+ 密钥单独通过环境变量指向:
66
167
 
67
168
  ```sh
68
169
  export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json" # 本地
@@ -78,7 +179,7 @@ export CWS_ACCESS_TOKEN="$(gcloud auth print-access-token \
78
179
 
79
180
  | 命令 | 作用 |
80
181
  | --- | --- |
81
- | `cws init` | 在当前仓库写入 `.cws.json` 模板和 agent skill |
182
+ | `cws init` | 在当前仓库写入 `.cws.json` 模板和 agent skill;不加 `--force` 时不动已存在的文件 |
82
183
  | `cws check` | 换取令牌并调用 `fetchStatus`;区分"密钥已配置"和"密钥可用" |
83
184
  | `cws upload [zip]` | 上传包,然后等待异步处理完成 |
84
185
  | `cws publish` | 把已上传的包提交审核 |
@@ -93,9 +194,19 @@ export CWS_ACCESS_TOKEN="$(gcloud auth print-access-token \
93
194
  "到底上线了吗"——用 `status` 回答:`publishedItemRevisionStatus` 里的
94
195
  `PUBLISHED` 才算已上线,其余都还在审核中。
95
196
 
96
- ## 给 AI 和脚本使用
197
+ ## 配合 AI 助手使用
198
+
199
+ 安装 skill——[skills CLI][skills-cli] 支持 Claude Code、Codex、Cursor、Copilot 等 70+ 种助手:
97
200
 
98
- `--json` 把 CLI 变成可解析的接口,而不是需要爬取的日志。成功写 stdout;进度行写 stderr。
201
+ ```sh
202
+ npx skills add XCreativeStudio/cws-release
203
+ ```
204
+
205
+ 它会把内容装到 `.agents/skills/chrome-web-store-publish/`,同时带上**操作流程**
206
+ ([`SKILL.md`](SKILL.md))和**一份可运行的 CLI**,所以助手可以离线执行
207
+ `node .agents/skills/chrome-web-store-publish/cws.mjs check`。
208
+
209
+ 之后 CLI 用 JSON 而非日志作答。成功写 stdout;进度行写 stderr。
99
210
 
100
211
  ```jsonc
101
212
  // cws release --json (stdout)
@@ -107,7 +218,7 @@ export CWS_ACCESS_TOKEN="$(gcloud auth print-access-token \
107
218
  ```sh
108
219
  cws:json {"ok":false,"error":{"code":"PUBLISHER_FORBIDDEN","status":403,
109
220
  "reason":"PERMISSION_DENIED","message":"HTTP 403: PERMISSION_DENIED: …",
110
- "hint":"Add the service-account email under Account in the Developer Dashboard, and check publisherId in .cws.json."}}
221
+ "hint":"Add the service-account email in the Developer Dashboard under Settings, in the Management section, then check publisherId in .cws.json."}}
111
222
  ```
112
223
 
113
224
  用 `sed -n 's/^cws:json //p'` 提取,然后对 `error.code` 分支——它的含义永不改变。
@@ -116,13 +227,51 @@ cws:json {"ok":false,"error":{"code":"PUBLISHER_FORBIDDEN","status":403,
116
227
  | `code` | 通常的修复方式 |
117
228
  | --- | --- |
118
229
  | `NO_CREDENTIALS` | 设置 `CWS_SERVICE_ACCOUNT_FILE` 或 `CWS_ACCESS_TOKEN` |
119
- | `PUBLISHER_FORBIDDEN` | 在后台加入服务账号;检查 `publisherId` |
230
+ | `CREDENTIALS_UNREADABLE` | 密钥文件不存在或不是合法 JSON——多半是 `private_key` 经 shell 或 CI 变量传递时丢了换行 |
231
+ | `AUTH_FAILED` | 重新换取令牌;令牌约一小时有效期,连续两次失败说明密钥本身有问题 |
232
+ | `PUBLISHER_FORBIDDEN` | 账号没在后台 **Settings** 页加入,或 `publisherId` 不对。这个 403 也会掩盖"API 未启用",所以按[第 1–5 步](#一次性配置)顺序排查 |
120
233
  | `UPLOAD_REJECTED` | 把 manifest 版本号提高到已发布版本之上 |
121
234
 
122
235
  全部 14 个错误码的完整含义与修复方式见 [docs/errors.md](docs/errors.md)。退出码对
123
236
  shell 保持粗粒度——`0` 成功、`1` 失败、`2` 用法错误——`data` 里的字段是未经改动的
124
237
  原始 API 响应。
125
238
 
239
+ ### npm 不可达时
240
+
241
+ 不是每个环境都能从 npm 安装:有些助手只读 skill 目录,隔离的 CI 跑者也可能访问不了
242
+ registry。用 `git clone` 或 `npx cws-release init` 都能把同样两个文件放到同一位置,
243
+ 之后无需安装即可运行 CLI:
244
+
245
+ ```sh
246
+ git clone --depth 1 https://github.com/XCreativeStudio/cws-release.git \
247
+ .agents/skills/chrome-web-store-publish
248
+ ```
249
+
250
+ 全部安装方式的对比见 [INSTALL.md](INSTALL.md)。skill 只是便利——真正的契约是 CLI 和
251
+ [一次性配置](#一次性配置),两者在完全没有助手的终端里同样可用。
252
+
253
+ ### 一次完整运行
254
+
255
+ 把一个 MV3 扩展(构建产物为 `.output/<name>-<version>-chrome.zip`)发布到已拥有该条目
256
+ 的发布者:
257
+
258
+ ```sh
259
+ cd my-extension
260
+ npx cws-release init # 生成 .cws.json 和 skill
261
+ # 从后台 Settings 页填入 publisherId 和 itemId
262
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
263
+
264
+ npx cws-release check # 凭据与商店权限,约 3 秒
265
+ npx cws-release upload # 通配符匹配唯一的 zip,并等待处理完成
266
+ npx cws-release publish --staged # 提交审核,通过后再手动上线
267
+ npx cws-release status # 当前线上版本与审核中的版本
268
+ ```
269
+
270
+ `--staged`(`STAGED_PUBLISH`)适合需要盯着的发版:审核通过后再"上线"是你的明确动作。
271
+ `--live`(`DEFAULT_PUBLISH`)则在审核通过后立即上线。条目的首次发版、以及任何改动权限
272
+ 的版本,都用 `--staged`。CLI 从不声称某个版本已上线——`cws status` 去读商店,由商店
273
+ 自己说。
274
+
126
275
  ## CI
127
276
 
128
277
  作为 GitHub Action——它会安装 CLI、检查 Node 版本,并把 JSON 信封暴露为 `result`、
@@ -167,6 +316,8 @@ node --test
167
316
  测试覆盖 JWT 签名、配置优先级、上传/发布请求结构、异步轮询、错误映射、JSON 错误契约,
168
317
  以及针对本地服务器的真实 HTTP 往返。无需任何凭据。
169
318
 
319
+ [skills-cli]: https://github.com/vercel-labs/skills
320
+
170
321
  ## 许可证
171
322
 
172
323
  MIT
package/SKILL.md CHANGED
@@ -9,23 +9,31 @@ description: Use when uploading or publishing a Chrome extension to the Chrome W
9
9
  v2. It authenticates with a Google Cloud service account, uploads a zip,
10
10
  submits it for review, and reports status.
11
11
 
12
- ## Getting the CLI into the repository
12
+ ## How this skill was installed
13
13
 
14
- Nothing is installed next to this file: GitHub is the source. Use whichever
15
- form is already available, from the repository root:
14
+ ```sh
15
+ npx skills add XCreativeStudio/cws-release # installs this skill into .agents/skills/
16
+ ```
17
+
18
+ That command copies the whole repository, so `<skill-dir>/cws.mjs` — a working
19
+ CLI — is already next to this file. Prefer it: no network, no version drift.
20
+ The repository also has `npx cws-release init`, which writes the skill for
21
+ projects that would rather not clone the repository.
22
+
23
+ ## Running the CLI
24
+
25
+ From the repository root, use whichever form is available:
16
26
 
17
27
  ```sh
18
- npx cws-release <command> # installed as a dev dependency, or fetched
28
+ node <skill-dir>/cws.mjs <command> # this install: self-contained, no network
29
+ npx cws-release <command> # dev dependency, or fetched from npm
19
30
  npm run cws <command> # if package.json has "scripts": { "cws": "cws" }
20
- node <skill-dir>/cws.mjs <command> # this clone, no network
21
31
  ```
22
32
 
23
33
  The package name comes first and the command second — **no `--` separator**,
24
34
  which the CLI would reject as an unknown option. Both npm forms run with the
25
- repository root as cwd, so `.cws.json` resolves correctly. Run `cws init` once
26
- per repository: it writes the `.cws.json` template and copies this skill into
27
- `.agents/skills/` when missing. Never run `npx cws-publish` — that npm name is
28
- an unrelated project.
35
+ repository root as cwd, so `.cws.json` resolves correctly. Never run
36
+ `npx cws-publish` — that npm name is an unrelated project.
29
37
 
30
38
  A clone whose `cws.mjs --help` shows no `init` line predates `init`; run it with
31
39
  the npx form above.
@@ -37,20 +45,31 @@ the npx form above.
37
45
  [Developer Dashboard](https://chrome.google.com/webstore/devconsole). The API
38
46
  cannot create items.
39
47
  - The publisher account has 2-step verification enabled.
40
- - A service account has been added once under **Account** in the dashboard.
41
- Only one service account can be added per publisher; the same key works for
42
- every item under that publisher.
48
+ - A service account has been added once on the dashboard's **Settings** page,
49
+ which is what actually grants access. Only one service account can be added
50
+ per publisher; the same key works for every item under that publisher.
43
51
  - The manifest version is strictly greater than the published one.
44
52
 
45
53
  ## One-time setup
46
54
 
47
- 1. Google Cloud Console: create/select a project and enable **Chrome Web Store API**.
48
- 2. Create a service account (no IAM roles needed) and download a JSON key.
49
- 3. Developer Dashboard → **Account** → add the service-account email.
50
- 4. Copy the **Publisher ID** (Publisher → Settings) and the **item ID**
51
- (the 32-character extension ID).
52
-
53
- Keep the key outside the repository, for example `~/.config/cws/service-account.json` (mode 600):
55
+ Per publisher account, not per extension. Four pieces of state must agree, and
56
+ any mismatch returns `PUBLISHER_FORBIDDEN` (HTTP 403) even with a valid key.
57
+
58
+ 1. **Enable the API.** In the Google Cloud project:
59
+ <https://console.cloud.google.com/apis/library/chromewebstore.googleapis.com>
60
+ Disabled here, calls fail at the API, not at authentication.
61
+ 2. **Create a service account** with no IAM roles, then **Keys → Add key → JSON**.
62
+ 3. **Authorize it in the dashboard,** under **Settings → Management** — *not*
63
+ under **Account → Profile**, which holds the display name and contact email.
64
+ Paste the `<name>@<project>.iam.gserviceaccount.com` email. This is the step
65
+ that grants access; skip it and every item returns 403.
66
+ 4. **Read both identifiers** on the same **Settings** page: the **Publisher ID**
67
+ (a field under Profile, also in the URL as
68
+ `/webstore/devconsole/<publisherId>/settings`) and the **item ID** (the
69
+ 32-character extension ID). They are per-publisher — never copy another
70
+ project's values.
71
+
72
+ Keep the key outside the repository, for example `~/.config/cws/service-account.json` (mode 600),
54
73
 
55
74
  ```sh
56
75
  export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
@@ -58,6 +77,16 @@ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
58
77
 
59
78
  In CI, put the whole JSON in a secret and export it as `CWS_SERVICE_ACCOUNT`.
60
79
 
80
+ **Key handling.** The key is a long-lived credential for every item under the
81
+ publisher. Keep it at `~/.config/cws/` with directory `700` and file `600`, out
82
+ of the repository and out of `.cws.json`. Never print it, never echo it, never
83
+ put it in a command line that lands in shell history, and never add `set -x` to
84
+ a script that exports it. If a task needs to *report* on the key, report its
85
+ path and the account email — neither is a secret. If it may have been exposed:
86
+ delete the key in Google Cloud (**Keys** → delete), create a new one, and point
87
+ `CWS_SERVICE_ACCOUNT_FILE` at it; the dashboard entry is keyed by email and
88
+ needs no change.
89
+
61
90
  ## Repository config
62
91
 
63
92
  Commit identifiers only — never secrets:
@@ -106,7 +135,7 @@ Branch on `error.code`, never on the message text:
106
135
  | `NO_CREDENTIALS` | No key or token in the environment | Ask the user for `CWS_SERVICE_ACCOUNT_FILE`; do not retry |
107
136
  | `CREDENTIALS_UNREADABLE` | Key file missing or malformed | Ask for the whole key file; newlines are often lost |
108
137
  | `AUTH_FAILED` | Google rejected the token | Re-run the token exchange once; two failures means the key is wrong |
109
- | `PUBLISHER_FORBIDDEN` | Account not authorized | The user must add the service account in the dashboard |
138
+ | `PUBLISHER_FORBIDDEN` | Account not authorized | The user must add the service account under **Settings → Management**; check `publisherId` |
110
139
  | `ITEM_NOT_FOUND` | Wrong `itemId`/`publisherId` | Fix `.cws.json`; do not retry |
111
140
  | `ITEM_STATE_CONFLICT` | State blocks this | Run `cws status`, report the state |
112
141
  | `RATE_LIMITED` | Throttled | Back off (seconds to minutes), then retry once |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cws-release",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Zero-dependency CLI for the Chrome Web Store API v2: upload, publish and check extension status with a service account.",
5
5
  "type": "module",
6
6
  "bin": { "cws": "./cws.mjs" },
package/src/api.mjs CHANGED
@@ -40,7 +40,7 @@ function hintFor(code) {
40
40
  case 'AUTH_FAILED':
41
41
  return 'The token expired (about 1 hour) or the key is wrong; re-run the token exchange.';
42
42
  case 'PUBLISHER_FORBIDDEN':
43
- return 'Add the service-account email under Account in the Developer Dashboard, and check publisherId in .cws.json.';
43
+ return 'Add the service-account email in the Developer Dashboard under Settings, in the Management section, then check publisherId in .cws.json.';
44
44
  case 'ITEM_NOT_FOUND':
45
45
  return 'Check itemId (the 32-character extension id) and publisherId; the item must exist in the store.';
46
46
  case 'ITEM_STATE_CONFLICT':