cws-release 0.1.2 → 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/INSTALL.md CHANGED
@@ -1,39 +1,68 @@
1
1
  # Install
2
2
 
3
- Two ways, one trade-off:
3
+ Four options. Pick by **how many extensions you maintain**, not by taste:
4
4
 
5
- | | Way | What you run | When |
6
- | --- | --- | --- | --- |
7
- | **A** | **npx** — no install | `npx -y cws-release -- cws release` | Try it, or one-off releases from a terminal or CI |
8
- | **B** | **Install** — a permanent `cws` command | `npm i -g cws-release`, then `cws release` | You publish regularly; nothing to re-type |
5
+ | | Option | What you run | Version lives in | Best for |
6
+ | --- | --- | --- | --- | --- |
7
+ | A | npx, nothing saved | `npx cws-release release` | nowhere (latest each run) | Trying it out, a one-off hotfix |
8
+ | **B** | **dev dependency (recommended)** | `npm i -D cws-release`, then `npm run cws release` | `package.json` + lockfile, per repo | **Several extensions** |
9
+ | C | global | `npm i -g cws-release`, then `cws release` | your machine | One extension, or a throwaway VM |
10
+ | D | GitHub Action | `uses: XCreativeStudio/cws-release@v1` | the `@v1` tag | Release pipelines |
9
11
 
10
- Both handle the same repository config. If an agent maintains the release
11
- flow, **B** costs one more step and removes a long command from every run
12
- afterwards.
12
+ Every option reads the same `.cws.json` from the repository, so switching
13
+ between them later changes nothing else.
13
14
 
14
- ## A. npx — nothing to install
15
+ ## Option B in detail: a dev dependency, for several extensions
15
16
 
16
17
  ```sh
17
- npx -y cws-release -- cws init # once
18
- npx -y cws-release -- cws release # every release
18
+ npm i -D cws-release # in each extension repository
19
+ npm pkg set scripts.cws=cws
20
+ npm run cws init # once per repo
21
+ npm run cws release # every release
19
22
  ```
20
23
 
21
- Until `cws-release` is on npm, use
22
- `npx -y --package=github:XCreativeStudio/cws-release -- cws <command>`.
24
+ Why this scales to many repositories, while `-g` does not:
23
25
 
24
- The bare `npx -y <spec> <args>` form does **not** work here — npx passes `init`
25
- to `cws` as if it were a package name, and you get the `--help` text instead.
26
- Keep `--package=<spec> -- cws <command>`.
26
+ - **Each repo pins its own version.** Two extensions can sit on different
27
+ CLI versions at the same time; upgrading one is a one-line diff in *that*
28
+ repo, reviewable like any dependency bump.
29
+ - **CI and teammates get the same binary.** The lockfile travels with the
30
+ code, so `npm ci && npm run cws release` behaves identically everywhere.
31
+ A global install pins nothing: today's latest is tomorrow's surprise.
32
+ - **`npm run cws` always finds it**, and works from any subdirectory, because
33
+ npm puts `node_modules/.bin` on `PATH` for scripts.
34
+ - **`npx cws-release`** in a repo that has it installed uses the *local*
35
+ copy, so even ad-hoc commands respect the pin.
27
36
 
28
- `npx` caches the package in `~/.npm/_npx`; it writes nothing into the
29
- repository, so it adds no git churn and no lockfile entry. `npm run cws`
30
- still works if you prefer a script alias:
37
+ Cost: `node_modules` gains one package (it has no dependencies of its own).
31
38
 
32
- ```json
33
- { "scripts": { "cws": "npx -y cws-release -- cws" } }
39
+ Use `-g` only when the machine is not the project — a scratch VM, a shell
40
+ where you publish once. For a laptop that builds several extensions, `-g`
41
+ quietly couples every project to one version.
42
+
43
+ Keep it in `devDependencies`: this is a **publishing tool, not a runtime
44
+ dependency** of the extension. The CLI uploads a zip your build already
45
+ produced and never packages anything itself, so it has no effect on the
46
+ extension's contents.
47
+
48
+ ## Option A: npx — nothing saved
49
+
50
+ ```sh
51
+ npx cws-release init # once
52
+ npx cws-release release # every release
34
53
  ```
35
54
 
36
- ## B. Install — a `cws` command
55
+ The package name goes first, the command second — **no `--` separator**, which
56
+ would be forwarded to the CLI and rejected as an unknown option. Both `-y` and
57
+ `--no` are unnecessary here: since npm 7 `npx` installs a missing package
58
+ without asking. Add `--no` only when you want a missing install to fail fast
59
+ instead of fetching (`npx --no cws-release release`).
60
+
61
+ `npx` caches the package in `~/.npm/_npx`; it writes nothing into the
62
+ repository, so it adds no git churn and no lockfile entry. A repository that has
63
+ `cws-release` in `devDependencies` gets its **local** copy automatically.
64
+
65
+ ## Option C: install — a `cws` command
37
66
 
38
67
  Once per machine, for every extension repository:
39
68
 
@@ -54,7 +83,7 @@ npm install --no-save --no-audit --no-fund cws-release
54
83
  npm run cws release
55
84
  ```
56
85
 
57
- ## CI / as a GitHub Action
86
+ ## Option D: a GitHub Action
58
87
 
59
88
  ```yaml
60
89
  - uses: XCreativeStudio/cws-release@v1
@@ -67,7 +96,7 @@ npm run cws release
67
96
  The action needs Node ≥ 22 on the runner (`actions/setup-node`), installs `cws`
68
97
  and returns the JSON envelope as `result` plus the failure `code`.
69
98
 
70
- ## C. For an agent
99
+ ## For an agent
71
100
 
72
101
  Some agents only read a skill directory; they cannot run a command first to
73
102
  discover one. Give them the skill and let the procedure carry the install
@@ -78,15 +107,14 @@ mkdir -p .agents/skills
78
107
  git clone --depth 1 https://github.com/XCreativeStudio/cws-release.git .agents/skills/chrome-web-store-publish
79
108
  ```
80
109
 
81
- The agent then reads `SKILL.md` and runs the npx or installed form from
82
- options A/B. A cloned skill directory is version-pinned and works offline,
83
- which is what an agent workspace wants. `cws init` also copies `SKILL.md`
84
- and this file into `.agents/skills/chrome-web-store-publish/`, so in a
85
- repository that has already done A or B the agent needs no extra step.
110
+ The agent then reads `SKILL.md` and runs the CLI from option A, B or C. A
111
+ cloned skill directory is version-pinned and works offline, which is what an
112
+ agent workspace wants. `cws init` also copies `SKILL.md` and this file into
113
+ `.agents/skills/chrome-web-store-publish/`, so a repository that already did B
114
+ or C needs no extra step.
86
115
 
87
116
  ## The package name is cws-release
88
117
 
89
118
  The npm name **`cws-publish` belongs to an unrelated project**, so never run
90
119
  `npx cws-publish` or `npm i -g cws-publish` — you would install someone else's
91
- code. This CLI is published as **`cws-release`**. If a release is not on npm yet,
92
- fall back to the `github:` specifier (`github:XCreativeStudio/cws-release`).
120
+ code. This CLI is published as **`cws-release`**.
package/README.md CHANGED
@@ -1,70 +1,178 @@
1
- # cws-publish
1
+ # cws-release
2
2
 
3
- Upload and publish Chrome extensions with the **Chrome Web Store API v2**, from
4
- one zero-dependency Node CLI.
3
+ Publish Chrome extensions from the terminal, your CI, or an AI agent — with the
4
+ **Chrome Web Store API v2**, from one zero-dependency Node CLI.
5
+
6
+ **English** · [简体中文](README.zh-CN.md) · [Project site](https://xcreativestudio.github.io/cws-release/)
7
+
8
+ Stop clicking through the developer dashboard for every release. `cws` uploads
9
+ your zip, submits it for review, and tells you the store's real state — or the
10
+ exact reason it refused.
11
+
12
+ ## Quick start
5
13
 
6
14
  ```sh
7
- cws check # prove the credentials work, then print the item status
8
- cws release # upload the zip, submit for review, print the result
9
- cws status # published / submitted revision state
15
+ npm i -D cws-release # in your extension repository
16
+ npx cws-release init # once: writes .cws.json + the agent skill
17
+
18
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
19
+ npx cws-release check # proves the credentials work, in three seconds
20
+ npx cws-release release # upload -> submit for review -> print the state
10
21
  ```
11
22
 
12
- - **No dependencies.** Node ≥ 22 signs the service-account JWT with `node:crypto`
13
- and uses the built-in `fetch`; there is nothing to install or audit.
14
- - **Service account, not a refresh token.** One key, added once in the Web Store
15
- dashboard, covers every item under that publisher and does not expire.
16
- - **Honest output.** `publish` returns a review state, not "live"; the CLI prints
17
- the store's state instead of inventing one.
18
- - **Built for agents.** Every command accepts `--json` and returns
19
- `{ ok, command, data }`; a failure returns a stable `error.code` and a hint on
20
- what to fix. No log scraping.
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.
21
27
 
22
- It also ships as a [skill](SKILL.md) for coding agents: the skill directory
23
- holds the procedure, the guardrails and the CLI together.
28
+ The API cannot create a new item — the first upload and the listing, privacy and
29
+ visibility tabs are manual.
24
30
 
25
- ## Install
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>
26
57
 
27
- Two ways, same CLI. **npx** — nothing to install:
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):
28
64
 
29
65
  ```sh
30
- npx -y cws-release -- cws init # once; on npm
31
- npx -y cws-release -- cws release # every release; on npm
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
32
70
  ```
33
71
 
34
- **Install** — a permanent `cws` command, for regular publishers and CI:
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:
35
112
 
36
113
  ```sh
37
- npm i -g cws-release
38
- cws release
114
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
39
115
  ```
40
116
 
41
- Until `cws-release` is on npm, use the GitHub specifier instead:
42
- `npx -y --package=github:XCreativeStudio/cws-release -- cws release` /
43
- `npm i -g github:XCreativeStudio/cws-release`.
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.
44
119
 
45
- Run `init` once in each extension repository: it writes a `.cws.json` template
46
- and copies the agent skill into `.agents/skills/chrome-web-store-publish/`.
47
- Installing into an agent instead? Clone the repo into that skill directory and
48
- the agent follows [SKILL.md](SKILL.md) — that is option C in
49
- [INSTALL.md](INSTALL.md).
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.
50
123
 
51
- The npm package is **`cws-release`** (not `cws-publish` — that name belongs to an
52
- unrelated project). No build step, no `npm install` inside this repository.
124
+ ## Key handling
53
125
 
54
- ## One-time setup
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.
55
144
 
56
- 1. Google Cloud Console: enable **Chrome Web Store API**, create a service
57
- account, download a JSON key.
58
- 2. [Developer Dashboard](https://chrome.google.com/webstore/devconsole) →
59
- **Account** → add the service-account email (one per publisher).
60
- 3. Note the **Publisher ID** and the **item ID** (the extension ID).
145
+ ## Why this one
61
146
 
62
- The API cannot create items: the first upload and the listing/privacy tabs are
63
- manual. After that, everything below is scriptable.
147
+ - **No dependencies.** Node ≥ 22 signs the service-account JWT with `node:crypto`
148
+ and uses the built-in `fetch`; there is nothing to install or audit.
149
+ - **Service account, not a refresh token.** One key, added once in the Web Store
150
+ dashboard, covers every item under that publisher and does not expire.
151
+ - **Honest output.** `publish` returns a review state, not "live"; the CLI prints
152
+ the store's state instead of inventing one.
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).
156
+
157
+ ## Install
158
+
159
+ | You have… | Use | Pin |
160
+ | --- | --- | --- |
161
+ | **Several extensions** | `npm i -D cws-release`, then `npx cws-release <cmd>` | `package.json` + lockfile, per repo |
162
+ | One extension, or trying it | `npm i -g cws-release` | your machine |
163
+ | A release pipeline | `uses: XCreativeStudio/cws-release@v1` | the tag |
164
+
165
+ With a dev dependency each repository pins its own version, so upgrading one
166
+ extension never changes another and CI installs exactly what you tested. A
167
+ global install pins nothing — every project on that machine shares one version.
168
+ [INSTALL.md](INSTALL.md) compares all four options, including running `cws` from
169
+ an agent skill directory.
170
+
171
+ No build step, and no `npm install` inside this repository.
64
172
 
65
173
  ## Configure
66
174
 
67
- Commit identifiers in `.cws.json`:
175
+ Commit identifiers, never secrets, in `.cws.json` (`init` writes the template):
68
176
 
69
177
  ```json
70
178
  {
@@ -74,82 +182,136 @@ Commit identifiers in `.cws.json`:
74
182
  }
75
183
  ```
76
184
 
77
- Keep the key out of the repository:
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:
78
190
 
79
191
  ```sh
80
- export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
81
- # or, in CI:
82
- export CWS_SERVICE_ACCOUNT="$(cat key.json)"
83
- # or reuse a token from gcloud / the OAuth playground:
84
- export CWS_ACCESS_TOKEN="$(gcloud auth print-access-token --scopes=https://www.googleapis.com/auth/chromewebstore)"
192
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json" # local
193
+ export CWS_SERVICE_ACCOUNT="$(cat key.json)" # CI secret
194
+ export CWS_ACCESS_TOKEN="$(gcloud auth print-access-token \
195
+ --scopes=https://www.googleapis.com/auth/chromewebstore)" # short-lived
85
196
  ```
86
197
 
87
- Environment overrides the file; `--zip` overrides both.
198
+ Environment overrides the file; `--zip` overrides both. `CWS_PUBLISHER_ID`,
199
+ `CWS_ITEM_ID` (`CWS_EXTENSION_ID` also works), `CWS_ZIP` and `CWS_PUBLISH_TYPE`
200
+ override the matching keys.
88
201
 
89
202
  ## Commands
90
203
 
91
204
  | Command | What it does |
92
205
  | --- | --- |
93
- | `cws init` | Write a `.cws.json` template and the skill into the current repository |
94
- | `cws check` | Token exchange + `fetchStatus`; separates "the secret is set" from "the secret works" |
95
- | `cws upload [zip]` | `upload` the package and wait for asynchronous processing |
96
- | `cws publish` | `publish` the uploaded package for review |
97
- | `cws release [zip]` | upload + publish + status |
98
- | `cws status` | published and submitted revision state |
99
- | `cws cancel` | cancel a submission under review |
206
+ | `cws init` | Write a `.cws.json` template plus the agent skill into this repository; leaves existing files alone without `--force` |
207
+ | `cws check` | Exchange the token and call `fetchStatus`; separates "the secret is set" from "the secret works" |
208
+ | `cws upload [zip]` | Upload the package, then wait for asynchronous processing |
209
+ | `cws publish` | Submit the uploaded package for review |
210
+ | `cws release [zip]` | upload → publish → status, in one step |
211
+ | `cws status` | Published and submitted revision state |
212
+ | `cws cancel` | Cancel a submission that is under review |
100
213
 
101
214
  Flags: `--staged` (`STAGED_PUBLISH`), `--live` (`DEFAULT_PUBLISH`),
102
215
  `--block-on-warnings`, `--json`, `--timeout <ms>`, `--config <path>`,
103
- `--api <url>`.
216
+ `--api <url>`, `--force` (with `init`).
217
+
218
+ `status` is the honest answer to "is it live yet?": `PUBLISHED` in
219
+ `publishedItemRevisionStatus` means live, anything else is still in review.
220
+
221
+ ## Using it with an AI agent
104
222
 
105
- ## For agents and scripts
223
+ Install the skill — the [skills CLI][skills-cli] handles Claude Code, Codex,
224
+ Cursor, Copilot and 70+ other agents:
106
225
 
107
- `--json` turns the CLI into an interface an agent can trust, instead of a log to
108
- scrape. Success goes to stdout, progress lines go to stderr.
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.
109
236
 
110
237
  ```jsonc
111
- // cws release --json (success, stdout)
112
- { "ok": true, "command": "release", "data": { "upload": {...}, "publish": {...}, "status": {...} } }
238
+ // cws release --json (stdout)
239
+ { "ok": true, "command": "release", "data": { "upload": {…}, "publish": {…}, "status": {…} } }
113
240
  ```
114
241
 
115
- Failure writes exactly one structured line to stderr, prefixed so it can be
242
+ A failure writes exactly one structured line to stderr, prefixed so it can be
116
243
  found among the progress lines:
117
244
 
118
245
  ```sh
119
- cws:json {"ok":false,"error":{"code":"PUBLISHER_FORBIDDEN","status":403,"reason":"PERMISSION_DENIED","message":"HTTP 403: PERMISSION_DENIED: ...","hint":"Add the service-account email under Account in the Developer Dashboard, and check publisherId in .cws.json."}}
246
+ cws:json {"ok":false,"error":{"code":"PUBLISHER_FORBIDDEN","status":403,
247
+ "reason":"PERMISSION_DENIED","message":"HTTP 403: PERMISSION_DENIED: …",
248
+ "hint":"Add the service-account email in the Developer Dashboard under Settings, in the Management section, then check publisherId in .cws.json."}}
120
249
  ```
121
250
 
122
- `error.code` is stable and safe to branch on:
251
+ Extract it with `sed -n 's/^cws:json //p'` and branch on `error.code`, which
252
+ never changes meaning. The most common ones:
123
253
 
124
- | `code` | Meaning | Usual fix |
125
- | --- | --- | --- |
126
- | `NO_CREDENTIALS` | No key or token configured | Set `CWS_SERVICE_ACCOUNT_FILE` / `CWS_ACCESS_TOKEN` |
127
- | `CREDENTIALS_UNREADABLE` | Key file missing or malformed | Paste the whole JSON key, newlines included |
128
- | `AUTH_FAILED` | Google rejected the token | Token expired (≈1 h) or key is wrong |
129
- | `PUBLISHER_FORBIDDEN` | Account not authorized for the item | Add the service account in the dashboard |
130
- | `ITEM_NOT_FOUND` | Wrong `itemId`/`publisherId` | Fix `.cws.json` |
131
- | `ITEM_STATE_CONFLICT` | State blocks the request | Run `cws status`, act on the state |
132
- | `RATE_LIMITED` | Store throttled the call | Back off and retry |
133
- | `UPLOAD_REJECTED` | Store rejected the package | Raise the manifest version; check the manifest |
134
- | `UPLOAD_TIMEOUT` | Async upload did not settle | `--timeout`, or check the dashboard |
135
- | `MISCONFIGURED` | `.cws.json` is invalid | Fill the identifiers |
136
- | `INVALID_PACKAGE` | Zip missing, ambiguous or not a zip | Build the package, or pass an exact path |
137
- | `USAGE` | Command line could not be parsed | Fix arguments (exit code 2) |
138
- | `API_ERROR` | Unclassified store error | Read `status`/`reason` |
139
-
140
- Exit codes stay coarse for shells: `0` success, `1` failure, `2` usage. The
141
- `--json` shape for success is `{ ok, command, data }`; the keys of `data` are the
142
- raw API responses, unchanged.
254
+ | `code` | Usual fix |
255
+ | --- | --- |
256
+ | `NO_CREDENTIALS` | Set `CWS_SERVICE_ACCOUNT_FILE` or `CWS_ACCESS_TOKEN` |
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 |
260
+ | `UPLOAD_REJECTED` | Raise the manifest version above the published one |
261
+
262
+ All 14 codes, with meanings and fixes: [docs/errors.md](docs/errors.md). Exit
263
+ codes stay coarse for shells — `0` success, `1` failure, `2` usage — and the
264
+ keys of `data` are the raw API responses, unchanged.
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.
143
304
 
144
305
  ## CI
145
306
 
146
- As a GitHub Action (no install step, `result` and `code` as outputs):
307
+ As a GitHub Action — it installs the CLI, checks the Node version, and exposes
308
+ the JSON envelope as `result` and the failure code as `code`:
147
309
 
148
310
  ```yaml
149
311
  - uses: actions/checkout@v4
150
312
  - uses: actions/setup-node@v4
151
313
  with:
152
- node-version: 22 # the CLI needs Node ≥ 22; the action checks this
314
+ node-version: 22
153
315
  - uses: XCreativeStudio/cws-release@v1
154
316
  with:
155
317
  command: release
@@ -158,41 +320,24 @@ As a GitHub Action (no install step, `result` and `code` as outputs):
158
320
  CWS_SERVICE_ACCOUNT: ${{ secrets.CWS_SERVICE_ACCOUNT }}
159
321
  ```
160
322
 
161
- Inputs: `command` (`release`, `upload`, `publish`, `status`, `check`, `cancel`),
162
- `zip`, `staged`, `block_on_warnings`, `timeout`, `json`, `cli_version`.
163
- Credentials are **not** inputs — put them in the step `env`, so they never show
164
- up in the action's resolved inputs.
165
-
166
- As a plain command, on any CI:
323
+ Inputs: `command`, `zip`, `staged`, `block_on_warnings`, `timeout`, `json`,
324
+ `cli_version`. Credentials are **not** inputs — keep them in the step `env` so
325
+ they never appear in the action's resolved inputs.
167
326
 
168
- ```yaml
169
- - run: npx -y cws-release -- cws release
170
- env:
171
- CWS_SERVICE_ACCOUNT: ${{ secrets.CWS_SERVICE_ACCOUNT }}
172
- ```
173
-
174
- Or, as a script that fails with the API's own reason and hint:
327
+ Other CI systems: [docs/ci.md](docs/ci.md).
175
328
 
176
- ```sh
177
- out=$(npx -y cws-release -- cws release --json 2>err.log) || {
178
- sed -n 's/^cws:json //p' err.log | jq -r '.error | "\(.code): \(.message) — \(.hint // "")"'
179
- exit 1
180
- }
181
- echo "$out" | jq -r '.data.status.publishedItemRevisionStatus.state'
182
- ```
329
+ ## What this CLI does and does not do
183
330
 
184
- ## What the API can and cannot do
331
+ Implemented: `upload`, `publish` (DEFAULT and STAGED), `fetchStatus`,
332
+ `cancelSubmission`.
185
333
 
186
- | Can | Cannot |
187
- | --- | --- |
188
- | `upload` a package | create a new item |
189
- | `publish` (DEFAULT or STAGED) | edit the listing, screenshots or privacy answers |
190
- | `fetchStatus`, `fetchReviews`, `queryMetrics` | change visibility |
191
- | `cancelSubmission`, `rollback`, `setPublishedDeployPercentage` | — |
334
+ Not implemented: `fetchReviews`, `getRatingSummary`, `queryMetrics`, `rollback`,
335
+ `setPublishedDeployPercentage`. The v2 API offers them; this CLI does not call
336
+ them — see the roadmap on the [project site](https://xcreativestudio.github.io/cws-release/).
192
337
 
193
- Details: [Using the API](https://developer.chrome.com/docs/webstore/using-api),
194
- [service accounts](https://developer.chrome.com/docs/webstore/service-accounts),
195
- [REST v2](https://developer.chrome.com/docs/webstore/api/reference/rest).
338
+ Outside the API's reach, so do these by hand in the dashboard: creating a new
339
+ item, editing the listing, screenshots, privacy answers, visibility and
340
+ pricing.
196
341
 
197
342
  ## Development
198
343
 
@@ -201,8 +346,10 @@ node --test
201
346
  ```
202
347
 
203
348
  The suite covers JWT signing, config precedence, upload/publish request shapes,
204
- asynchronous polling, error mapping, and one real HTTP round trip against a
205
- local server. No credentials needed.
349
+ asynchronous polling, error mapping, the JSON error contract, and real HTTP
350
+ round trips against a local server. No credentials needed.
351
+
352
+ [skills-cli]: https://github.com/vercel-labs/skills
206
353
 
207
354
  ## License
208
355
 
@@ -0,0 +1,323 @@
1
+ # cws-release
2
+
3
+ 从终端、CI,或让 AI 助手,用 **Chrome Web Store API v2** 发布 Chrome 扩展——
4
+ 一个零依赖的 Node CLI。
5
+
6
+ [English](README.md) · **简体中文** · [项目主页](https://xcreativestudio.github.io/cws-release/)
7
+
8
+ 每次发版不用再在开发者后台里点来点去。`cws` 上传你的 zip、提交审核,并告诉你
9
+ 商店的真实状态——或者它拒绝的准确原因。
10
+
11
+ ## 快速开始
12
+
13
+ ```sh
14
+ npm i -D cws-release # 在你的扩展仓库里
15
+ npx cws-release init # 一次性:生成 .cws.json + agent skill
16
+
17
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json"
18
+ npx cws-release check # 三秒内验证凭据可用
19
+ npx cws-release release # 上传 → 提交审核 → 打印状态
20
+ ```
21
+
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
+ 方案——这个文件本来就不该出现在工作树里。
125
+
126
+ ## 为什么用它
127
+
128
+ - **零依赖。** Node ≥ 22 用 `node:crypto` 自签服务账号 JWT,用内置 `fetch` 发请求;
129
+ 没有东西需要安装或审计。
130
+ - **服务账号,不是 refresh token。** 一把密钥在后台加一次,该发布者下所有条目通用,
131
+ 且不会过期。
132
+ - **诚实的输出。** `publish` 返回的是审核状态而不是"已上线";CLI 打印商店的真实状态,
133
+ 不编造。
134
+ - **为 AI 设计。** 一条命令装好 skill(`npx skills add XCreativeStudio/cws-release`),
135
+ 底层 CLI 用 JSON 作答、错误码稳定——见[配合 AI 助手使用](#配合-ai-助手使用)。
136
+
137
+ ## 安装
138
+
139
+ | 你的情况 | 用 | 版本固定在哪 |
140
+ | --- | --- | --- |
141
+ | **维护多个扩展** | `npm i -D cws-release`,然后 `npx cws-release <命令>` | 每个仓库的 `package.json` + lockfile |
142
+ | 只有一个扩展,或试用 | `npm i -g cws-release` | 你的机器 |
143
+ | 发布流水线 | `uses: XCreativeStudio/cws-release@v1` | 标签 |
144
+
145
+ 用 dev dependency 时,每个仓库固定自己的版本,升级一个扩展不会影响另一个,CI 装的
146
+ 正是你测过的那个。全局安装不固定任何版本——那台机器上所有项目共用一个版本。
147
+ [INSTALL.md](INSTALL.md) 对比了全部四种方式,包括从 agent skill 目录运行。
148
+
149
+ 没有构建步骤,本仓库内部也不需要 `npm install`。
150
+
151
+ ## 配置
152
+
153
+ 把标识符(不是密钥)提交进 `.cws.json`(`init` 会生成模板):
154
+
155
+ ```json
156
+ {
157
+ "publisherId": "…",
158
+ "itemId": "…",
159
+ "zip": ".output/*-chrome.zip"
160
+ }
161
+ ```
162
+
163
+ `publisherId` 和 `itemId` 来自后台的 **Settings** 页([第 5 步](#一次性配置));
164
+ `itemId` 是 32 位扩展 ID。`zip` 可以是单个 `*`/`?` 通配符,因为构建产物通常带版本号。
165
+
166
+ 密钥单独通过环境变量指向:
167
+
168
+ ```sh
169
+ export CWS_SERVICE_ACCOUNT_FILE="$HOME/.config/cws/service-account.json" # 本地
170
+ export CWS_SERVICE_ACCOUNT="$(cat key.json)" # CI 密钥
171
+ export CWS_ACCESS_TOKEN="$(gcloud auth print-access-token \
172
+ --scopes=https://www.googleapis.com/auth/chromewebstore)" # 短期令牌
173
+ ```
174
+
175
+ 环境变量覆盖配置文件;`--zip` 覆盖两者。`CWS_PUBLISHER_ID`、`CWS_ITEM_ID`
176
+ (`CWS_EXTENSION_ID` 也可)、`CWS_ZIP`、`CWS_PUBLISH_TYPE` 覆盖对应字段。
177
+
178
+ ## 命令
179
+
180
+ | 命令 | 作用 |
181
+ | --- | --- |
182
+ | `cws init` | 在当前仓库写入 `.cws.json` 模板和 agent skill;不加 `--force` 时不动已存在的文件 |
183
+ | `cws check` | 换取令牌并调用 `fetchStatus`;区分"密钥已配置"和"密钥可用" |
184
+ | `cws upload [zip]` | 上传包,然后等待异步处理完成 |
185
+ | `cws publish` | 把已上传的包提交审核 |
186
+ | `cws release [zip]` | 一步完成 上传 → 提交审核 → 状态 |
187
+ | `cws status` | 已发布和已提交的版本状态 |
188
+ | `cws cancel` | 取消正在审核中的提交 |
189
+
190
+ 参数:`--staged`(`STAGED_PUBLISH`)、`--live`(`DEFAULT_PUBLISH`)、
191
+ `--block-on-warnings`、`--json`、`--timeout <ms>`、`--config <path>`、
192
+ `--api <url>`、`--force`(配合 `init`)。
193
+
194
+ "到底上线了吗"——用 `status` 回答:`publishedItemRevisionStatus` 里的
195
+ `PUBLISHED` 才算已上线,其余都还在审核中。
196
+
197
+ ## 配合 AI 助手使用
198
+
199
+ 安装 skill——[skills CLI][skills-cli] 支持 Claude Code、Codex、Cursor、Copilot 等 70+ 种助手:
200
+
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。
210
+
211
+ ```jsonc
212
+ // cws release --json (stdout)
213
+ { "ok": true, "command": "release", "data": { "upload": {…}, "publish": {…}, "status": {…} } }
214
+ ```
215
+
216
+ 失败时 stderr 恰好写一行结构化数据,带前缀,便于在进度行中定位:
217
+
218
+ ```sh
219
+ cws:json {"ok":false,"error":{"code":"PUBLISHER_FORBIDDEN","status":403,
220
+ "reason":"PERMISSION_DENIED","message":"HTTP 403: PERMISSION_DENIED: …",
221
+ "hint":"Add the service-account email in the Developer Dashboard under Settings, in the Management section, then check publisherId in .cws.json."}}
222
+ ```
223
+
224
+ 用 `sed -n 's/^cws:json //p'` 提取,然后对 `error.code` 分支——它的含义永不改变。
225
+ 最常见的几个:
226
+
227
+ | `code` | 通常的修复方式 |
228
+ | --- | --- |
229
+ | `NO_CREDENTIALS` | 设置 `CWS_SERVICE_ACCOUNT_FILE` 或 `CWS_ACCESS_TOKEN` |
230
+ | `CREDENTIALS_UNREADABLE` | 密钥文件不存在或不是合法 JSON——多半是 `private_key` 经 shell 或 CI 变量传递时丢了换行 |
231
+ | `AUTH_FAILED` | 重新换取令牌;令牌约一小时有效期,连续两次失败说明密钥本身有问题 |
232
+ | `PUBLISHER_FORBIDDEN` | 账号没在后台 **Settings** 页加入,或 `publisherId` 不对。这个 403 也会掩盖"API 未启用",所以按[第 1–5 步](#一次性配置)顺序排查 |
233
+ | `UPLOAD_REJECTED` | 把 manifest 版本号提高到已发布版本之上 |
234
+
235
+ 全部 14 个错误码的完整含义与修复方式见 [docs/errors.md](docs/errors.md)。退出码对
236
+ shell 保持粗粒度——`0` 成功、`1` 失败、`2` 用法错误——`data` 里的字段是未经改动的
237
+ 原始 API 响应。
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
+
275
+ ## CI
276
+
277
+ 作为 GitHub Action——它会安装 CLI、检查 Node 版本,并把 JSON 信封暴露为 `result`、
278
+ 把失败码暴露为 `code`:
279
+
280
+ ```yaml
281
+ - uses: actions/checkout@v4
282
+ - uses: actions/setup-node@v4
283
+ with:
284
+ node-version: 22
285
+ - uses: XCreativeStudio/cws-release@v1
286
+ with:
287
+ command: release
288
+ zip: .output/*-chrome.zip
289
+ env:
290
+ CWS_SERVICE_ACCOUNT: ${{ secrets.CWS_SERVICE_ACCOUNT }}
291
+ ```
292
+
293
+ 输入:`command`、`zip`、`staged`、`block_on_warnings`、`timeout`、`json`、
294
+ `cli_version`。凭据**不是**输入项——放进步骤的 `env`,这样它们不会出现在 action
295
+ 的已解析输入日志里。
296
+
297
+ 其他 CI 系统见 [docs/ci.md](docs/ci.md)。
298
+
299
+ ## 本 CLI 能做与不能做
300
+
301
+ 已实现:`upload`、`publish`(DEFAULT 与 STAGED)、`fetchStatus`、`cancelSubmission`。
302
+
303
+ 未实现:`fetchReviews`、`getRatingSummary`、`queryMetrics`、`rollback`、
304
+ `setPublishedDeployPercentage`。v2 API 提供了它们,但本 CLI 不调用——路线图见
305
+ [项目主页](https://xcreativestudio.github.io/cws-release/)。
306
+
307
+ API 边界之外、需要在后台手动完成的:创建新条目、编辑商店信息、截图、隐私问卷、
308
+ 可见性和定价。
309
+
310
+ ## 开发
311
+
312
+ ```sh
313
+ node --test
314
+ ```
315
+
316
+ 测试覆盖 JWT 签名、配置优先级、上传/发布请求结构、异步轮询、错误映射、JSON 错误契约,
317
+ 以及针对本地服务器的真实 HTTP 往返。无需任何凭据。
318
+
319
+ [skills-cli]: https://github.com/vercel-labs/skills
320
+
321
+ ## 许可证
322
+
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 -y cws-release -- cws <command> # nothing installed
19
- npm run cws <command> # "scripts": { "cws": "cws" }
20
- node <skill-dir>/cws.mjs <command> # this clone, no network
28
+ node <skill-dir>/cws.mjs <command> # this install: self-contained, no network
29
+ npx cws-release <command> # dev dependency, or fetched from npm
30
+ npm run cws <command> # if package.json has "scripts": { "cws": "cws" }
21
31
  ```
22
32
 
23
- Both npm forms run with the repository root as cwd, so `.cws.json` resolves
24
- correctly. Run `cws init` once per repository: it writes the `.cws.json`
25
- template and copies this skill into `.agents/skills/` when missing. Do not
26
- retry with a bare `npx cws-publish` — that name on npm is another project. The
27
- package is `cws-release`; if a release is not on npm yet, use
28
- `--package=github:XCreativeStudio/cws-release --`.
33
+ The package name comes first and the command second — **no `--` separator**,
34
+ which the CLI would reject as an unknown option. Both npm forms run with the
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 |
@@ -160,8 +189,8 @@ Or inline, with no extra action:
160
189
  ```
161
190
 
162
191
  The CLI has no dependencies, so the install step only clones and caches it; no
163
- `pnpm install` is needed. `npx -y cws-release -- cws release`
164
- also works as a single step — the cache warm-up is the only cost from then on.
192
+ `pnpm install` is needed. `npx cws-release release` also works as a single
193
+ step — the cache warm-up is the only cost from then on.
165
194
 
166
195
  ## Troubleshooting
167
196
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cws-release",
3
- "version": "0.1.2",
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':
package/src/init.mjs CHANGED
@@ -42,7 +42,7 @@ export function init({ cwd = process.cwd(), force = false, log = (line) => proce
42
42
  if (!existsSync(configPath) || defaultsOnly(configPath)) {
43
43
  log(`\nnext fill publisherId and itemId in ${CONFIG_FILE} (never the key)`);
44
44
  }
45
- log(' check npx -y --package=github:XCreativeStudio/cws-release -- cws check');
45
+ log(' check npx cws-release check');
46
46
  return 0;
47
47
  }
48
48