ask-bridge 0.1.0
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/LICENSE +21 -0
- package/README.en.md +251 -0
- package/README.md +257 -0
- package/npm/cli.cjs +22 -0
- package/npm/postinstall.cjs +181 -0
- package/npm/prepublish-check.cjs +115 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Will 保哥
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# Ask Bridge 🦀
|
|
2
|
+
|
|
3
|
+
`ask` is a powerful, lightweight command-line tool written in **Rust** that automates ChatGPT or Gemini directly in your real Chrome browser. It uses the **Model Context Protocol (MCP)** and **Chrome DevTools Protocol (CDP)** via the embedded `doggy8088/mcp-cli` Rust library dependency and `chrome-devtools-mcp` to control Chrome, input prompts, click submit, and print the response back to your terminal. ChatGPT is the default provider; use `--provider gemini` to switch to Gemini.
|
|
4
|
+
|
|
5
|
+
Unlike typical API clients, `ask` operates inside a real Chrome browser with a **persistent user profile**. This means:
|
|
6
|
+
- You log in manually **once** (`ask login`).
|
|
7
|
+
- You can solve CAPTCHAs, pass provider-side browser checks, and access the selected provider's web features like a normal user.
|
|
8
|
+
- Your session cookies, login state, and chat history are saved persistently.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 🌟 Key Features
|
|
13
|
+
|
|
14
|
+
- **🦀 100% Rust Core**: Extremely fast, lightweight, and compile-once, run-anywhere binary.
|
|
15
|
+
- **Multi-provider support**: Choose ChatGPT or Gemini with `--provider chatgpt|gemini`.
|
|
16
|
+
- **🌐 Real Browser Automation**: Directly interacts with Chrome on port `9223` (isolated debug profile).
|
|
17
|
+
- **🔒 Persistent Login**: Uses a dedicated local profile directory (`~/.config/ask-bridge/chrome-profile`) so you never lose your login state.
|
|
18
|
+
- **Response Output**: Prints the selected provider's response back to your terminal.
|
|
19
|
+
- **🌀 TUI Thinking Animation**: Displays a rotating spinner while waiting for the provider to reply, then clears it once output starts.
|
|
20
|
+
- **🧠 Intelligent Tab Management**: Reuses existing provider tabs if open, focuses them, or opens new ones, avoiding tab clutter.
|
|
21
|
+
- **🖥️ Pipe & Stdin Support**: Supports piping prompts via `stdin` (e.g. `cat report.txt | ask "summarize this"`).
|
|
22
|
+
- **📎 Image & File Attachments**: Attach local images to ChatGPT with `--image`, or documents (PDF, Word, Excel, plain text, Markdown, JSON, etc.) with `--file`; Gemini currently supports `--file` and rejects `--image`.
|
|
23
|
+
- **🔀 Model Switching**: Use `--model` to switch the provider model before the prompt is sent, such as ChatGPT `GPT-5.4` or Gemini `3.5 Flash`.
|
|
24
|
+
- **🔍 Quiet by Default & Verbose Mode**: Quiet and clean output by default (displaying only the generated response), with an optional `--verbose` flag to display full browser state logs if needed.
|
|
25
|
+
- **Version Info**: Use `-v` or `--version` to print the current version number.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 🛠️ Prerequisites
|
|
30
|
+
|
|
31
|
+
To run this tool, you need:
|
|
32
|
+
|
|
33
|
+
1. **`node`/`npx`** installed to automatically launch the `chrome-devtools-mcp` server.
|
|
34
|
+
2. **Google Chrome** installed (normally located at `/Applications/Google Chrome.app` on macOS). `make install` installs it with Homebrew when it is missing and Homebrew is available.
|
|
35
|
+
|
|
36
|
+
You do **not** need a global `mcp-cli` executable. The Rust binary uses `mcp-cli` as a Cargo dependency from `https://github.com/doggy8088/mcp-cli`.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 🚀 Installation & Build
|
|
41
|
+
|
|
42
|
+
### 1. Build the Rust Project
|
|
43
|
+
|
|
44
|
+
Clone or navigate to the project directory and install with Make:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
make install
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This installs the required Chrome browser when needed, builds the optimized binary, and links it to `~/.local/bin/ask`.
|
|
51
|
+
|
|
52
|
+
### 2. Add to PATH
|
|
53
|
+
|
|
54
|
+
If you only want to build without installing:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
cargo build --release
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The compiled binary will be located at `target/release/ask-bridge`.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 📖 Usage Guide
|
|
65
|
+
|
|
66
|
+
### 1. First Time Setup: Login to a provider
|
|
67
|
+
|
|
68
|
+
Before sending prompts, you need to log in to the selected provider. ChatGPT is the default:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
ask login
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
For Gemini:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
ask --provider gemini login
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- This will automatically launch Google Chrome with a dedicated, persistent debug profile.
|
|
81
|
+
- Log in manually to the selected provider page, such as `https://chatgpt.com/` or `https://gemini.google.com/app`.
|
|
82
|
+
- Once logged in, return to your terminal and press **`[Enter]`**.
|
|
83
|
+
- The tool will verify your login status and save your profile. You only need to do this **once**!
|
|
84
|
+
|
|
85
|
+
### 2. Send Prompts Directly
|
|
86
|
+
|
|
87
|
+
Simply pass your prompt as an argument:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
ask "What is the difference between a struct and a tuple in Rust?"
|
|
91
|
+
ask --provider gemini "What is the difference between a struct and a tuple in Rust?"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- Chrome will open or focus on your selected provider tab.
|
|
95
|
+
- The prompt will be typed out and submitted.
|
|
96
|
+
- The selected provider's response will be printed in your terminal.
|
|
97
|
+
|
|
98
|
+
### 3. Open a Brand New Session (`--new`)
|
|
99
|
+
|
|
100
|
+
By default, `ask` will reuse any existing open tab for the selected provider to avoid cluttering your browser with too many tabs.
|
|
101
|
+
|
|
102
|
+
If you want to start a **completely fresh conversation session** (equivalent to clicking "New Chat" in the sidebar), use the `--new` flag:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
ask "誰是保哥?" --new
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- This will open a **brand new selected-provider tab**.
|
|
109
|
+
- It will **automatically close previous tabs for the same provider** to keep your workspace clean and organized.
|
|
110
|
+
|
|
111
|
+
### 4. Headless Mode (Default: True)
|
|
112
|
+
|
|
113
|
+
By default, standard queries run Chrome in **headless mode** (`--headless=true`) so that the browser operates silently in the background without stealing your focus or popping up windows.
|
|
114
|
+
|
|
115
|
+
If you want to watch Chrome work in real-time or need to manually check what's happening on the page, you can run in **headful mode** by setting `--headless=false`:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
ask "誰是保哥?" --headless=false
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
*Note: `ask login` always overrides the default and runs in **headful mode** so you can interact with the UI. For other subcommands, pass `--headless=false` when you want a visible browser.*
|
|
122
|
+
|
|
123
|
+
### 5. Verbose Mode (`--verbose`)
|
|
124
|
+
|
|
125
|
+
By default, `ask` runs in a **quiet, clean mode** that hides all background browser-control logs (such as "Checking open Chrome tabs...", "Typing prompt...", etc.) and only displays the final markdown answer. However, it still plays an animated rotating spinner in your terminal while waiting for the provider to generate a response.
|
|
126
|
+
|
|
127
|
+
If you want to see detailed step-by-step status logs of what `ask` is doing behind the scenes, add the `--verbose` flag:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
ask "誰是保哥?" --verbose
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
This will print every stage of the browser automation:
|
|
134
|
+
- Checking open Chrome tabs...
|
|
135
|
+
- Focusing input field...
|
|
136
|
+
- Typing your prompt...
|
|
137
|
+
- Submitting...
|
|
138
|
+
- Waiting for provider response...
|
|
139
|
+
|
|
140
|
+
### 6. Version Info
|
|
141
|
+
|
|
142
|
+
Use `-v` or `--version` to print the current version number:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
ask -v
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 7. Piping & Stdin Support
|
|
149
|
+
|
|
150
|
+
You can pipe text or files directly into `ask`:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
echo "Explain quantum computing in one sentence" | ask
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
When you also pass a prompt argument, `ask` uses the prompt first and then appends stdin content after two newlines:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
cat /Users/will/.copilot/session-state/46cc0f1c-79fd-4622-9548-a0b7fa3794be/research/does-cursor-support-byok.md | ask 'What is this?'
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Or read files:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
cat src/main.rs | ask "Are there any memory leaks in this Rust code?"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### 8. Attaching Images or Files
|
|
169
|
+
|
|
170
|
+
Instead of piping file contents into the prompt, you can upload local files as attachments directly to the selected provider.
|
|
171
|
+
|
|
172
|
+
#### Attach images
|
|
173
|
+
|
|
174
|
+
Use `--image` (repeatable) to attach one or more local images. This currently supports ChatGPT; Gemini image input is not enabled and exits with an explicit error when used with `--provider gemini`.
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
ask "Describe this image." --image screenshot.png
|
|
178
|
+
ask "Compare these two images." --image v1.png --image v2.png
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Supported formats include PNG, JPEG, GIF, WebP, SVG, BMP, and more.
|
|
182
|
+
|
|
183
|
+
#### Attach documents
|
|
184
|
+
|
|
185
|
+
Use `--file` (repeatable) to attach documents such as PDF, Word, Excel, PowerPoint, plain text, Markdown, CSV, JSON, or source code. This flow supports both ChatGPT and Gemini.
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
ask "Summarize this PDF." --file report.pdf
|
|
189
|
+
ask "How many rows are in this CSV?" --file data.csv
|
|
190
|
+
ask "Check this code for issues." --file src/main.rs
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
You can attach images and documents at the same time:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
ask "Compare this design image against the spec document and list inconsistencies." --image design.png --file spec.docx
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 9. Switch Model
|
|
200
|
+
|
|
201
|
+
Use `--model` to automatically switch the provider model before the prompt is sent. Matching is case- and punctuation-insensitive (`-`, `.`, spaces, etc. are ignored).
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
ask "Introduce Rust in a few sentences." --model GPT-5.4
|
|
205
|
+
ask "Prove this math problem." --model o3
|
|
206
|
+
ask "Quickly translate this." --model 即時
|
|
207
|
+
ask --provider gemini "Introduce Rust in a few sentences." --model "3.5 Flash"
|
|
208
|
+
ask --provider gemini "Introduce Rust in a few sentences." --model "3.1 Pro"
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Available model names (depending on your account entitlements and provider UI):
|
|
212
|
+
|
|
213
|
+
- **ChatGPT models**: `GPT-5.5`, `GPT-5.4`, `GPT-5.3`, `o3`
|
|
214
|
+
- **ChatGPT thinking levels**: `智慧`, `即時`, `中等`, `高`, `超高`, `專業`
|
|
215
|
+
- **Gemini modes**: `3.5 Flash`, `3.1 Flash-Lite`, `3.1 Pro`
|
|
216
|
+
|
|
217
|
+
> If the requested name is not found in the menu, `ask` reports `Model switch failed: error: model not found in menu` and aborts without submitting the prompt.
|
|
218
|
+
|
|
219
|
+
### 10. Just Open a Provider
|
|
220
|
+
|
|
221
|
+
To quickly launch the browser and open the selected provider without sending any query:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
ask open
|
|
225
|
+
ask --provider gemini open
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 11. Close the Browser Instance
|
|
229
|
+
|
|
230
|
+
To close the Chrome debug profile instance managed by `ask`:
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
ask close
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
`close` only shuts down the `ask` Chrome instance that uses `~/.config/ask-bridge/chrome-profile` and listens on debug port `9223`. If that port is occupied by a non-`ask` Chrome process, it reports an error instead of closing it.
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## ⚙️ How It Works (Under the Hood)
|
|
241
|
+
|
|
242
|
+
1. **Browser Initialization**: `ask` checks if Chrome is listening on debugging port `9223`. If not, it spawns Google Chrome as a background process with a custom profile directory (`~/.config/ask-bridge/chrome-profile`).
|
|
243
|
+
2. **MCP Bridge Config**: On startup, it automatically writes a custom `mcp_servers.json` to `~/.config/ask-bridge/mcp_servers.json`, configuring the Chrome DevTools MCP server by default with `chrome-devtools-mcp@latest` and `--browser-url=http://127.0.0.1:9223`.
|
|
244
|
+
3. **Client Call**: `ask` calls the embedded `doggy8088/mcp-cli` Rust library dependency, invoking `list_pages`, `select_page`, `type_text`, and `evaluate_script` tools to automate the DOM without relying on an external `mcp-cli` executable.
|
|
245
|
+
4. **State Polling**: During generation, a lightweight JavaScript engine checks the provider's send/stop button states and extracts response element inner-text for terminal output.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## 📄 License
|
|
250
|
+
|
|
251
|
+
MIT License. Feel free to use, modify, and distribute.
|
package/README.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# Ask Bridge 🦀
|
|
2
|
+
|
|
3
|
+
`ask` 是以 Rust 撰寫的輕量命令列工具,可透過真實 Chrome 瀏覽器自動操作 ChatGPT 與 Gemini。它使用 Model Context Protocol MCP 與 Chrome DevTools Protocol CDP,並透過內建的 `doggy8088/mcp-cli` Rust library dependency 搭配 `chrome-devtools-mcp` 控制 Chrome、輸入 prompt、送出訊息,並將回覆輸出到終端機。預設 provider 為 ChatGPT,可用 `--provider gemini` 切換到 Gemini。
|
|
4
|
+
|
|
5
|
+
不同於一般 API client,`ask` 會在真實 Chrome 瀏覽器中執行,並使用持久化的專屬使用者 profile。這表示:
|
|
6
|
+
|
|
7
|
+
- 只需要手動登入一次,透過 `ask login` 完成。
|
|
8
|
+
- 可處理 CAPTCHA、Cloudflare,並像一般使用者一樣存取所選 provider 的網頁功能。
|
|
9
|
+
- Session cookies、登入狀態與對話紀錄會持久保存。
|
|
10
|
+
|
|
11
|
+
## 主要功能
|
|
12
|
+
|
|
13
|
+
- **100% Rust 核心**:快速、輕量,編譯後即可執行。
|
|
14
|
+
- **多 provider 支援**:使用 `--provider chatgpt|gemini` 選擇 ChatGPT 或 Gemini。
|
|
15
|
+
- **真實瀏覽器自動化**:直接控制監聽 `9223` port 的 Chrome debug profile。
|
|
16
|
+
- **持久登入狀態**:使用專屬本機 profile 目錄 `~/.config/ask-bridge/chrome-profile`,避免重複登入。
|
|
17
|
+
- **回覆輸出**:所選 provider 產生回覆時,將內容輸出到終端機。
|
|
18
|
+
- **思考動畫**:等待 provider 回覆時,在終端機顯示旋轉 spinner,開始輸出內容後自動清除。
|
|
19
|
+
- **智慧分頁管理**:可重用既有 provider 分頁、聚焦分頁,或開啟新分頁,避免分頁過度增加。
|
|
20
|
+
- **Pipe 與 stdin 支援**:支援透過 standard input 傳入 prompt,例如 `cat report.txt | ask "summarize this"`。
|
|
21
|
+
- **圖片與文件上傳**:可透過 `--image` 附上 ChatGPT 圖片,或透過 `--file` 附上文件(PDF、Word、Excel、純文字、Markdown、JSON 等皆可),一次可指定多個檔案;Gemini 目前支援 `--file`,不支援 `--image` 圖片輸入。
|
|
22
|
+
- **模型切換**:使用 `--model` 在送出 prompt 前自動切換 provider 模型(如 ChatGPT 的 `GPT-5.4`、`o3`,或 Gemini 的 `3.5 Flash`、`3.1 Pro`)。
|
|
23
|
+
- **預設安靜模式與 verbose 模式**:預設只輸出最終回覆;加上 `--verbose` 可顯示背景瀏覽器控制流程。
|
|
24
|
+
- **版本資訊**:使用 `-v` 或 `--version` 顯示目前版本號。
|
|
25
|
+
|
|
26
|
+
## 前置需求
|
|
27
|
+
|
|
28
|
+
執行此工具需要:
|
|
29
|
+
|
|
30
|
+
1. 已安裝 `node` 與 `npx`,用於自動啟動 `chrome-devtools-mcp` server。
|
|
31
|
+
2. 已安裝 Google Chrome。macOS 預設路徑通常是 `/Applications/Google Chrome.app`。若缺少 Chrome,且系統有 Homebrew,`make install` 會自動安裝。
|
|
32
|
+
|
|
33
|
+
不需要安裝全域 `mcp-cli` 執行檔。Rust binary 會透過 Cargo 從 `https://github.com/doggy8088/mcp-cli` 使用 `mcp-cli` 作為 dependency。
|
|
34
|
+
|
|
35
|
+
## 安裝與建置
|
|
36
|
+
|
|
37
|
+
### 1. 安裝工具
|
|
38
|
+
|
|
39
|
+
在專案目錄執行:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
make install
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
此命令會安裝必要的 Chrome 瀏覽器、建置最佳化 binary,並建立 `~/.local/bin/ask` symlink。
|
|
46
|
+
|
|
47
|
+
請確認 `~/.local/bin` 已加入 shell 的 `PATH`。
|
|
48
|
+
|
|
49
|
+
### 2. 只建置不安裝
|
|
50
|
+
|
|
51
|
+
若只想建置 binary:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
cargo build --release
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
編譯後的 binary 會位於 `target/release/ask-bridge`。
|
|
58
|
+
|
|
59
|
+
## 使用方式
|
|
60
|
+
|
|
61
|
+
### 1. 首次設定:登入 provider
|
|
62
|
+
|
|
63
|
+
送出 prompt 前,需要先登入所選 provider。ChatGPT 為預設:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
ask login
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
若要登入 Gemini:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
ask --provider gemini login
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
此命令會:
|
|
76
|
+
|
|
77
|
+
- 使用專屬且持久化的 debug profile 啟動 Google Chrome。
|
|
78
|
+
- 開啟所選 provider 頁面,例如 `https://chatgpt.com/` 或 `https://gemini.google.com/app`。
|
|
79
|
+
- 等待你手動登入帳號。
|
|
80
|
+
- 在你回到終端機按 Enter 後,驗證登入狀態並保存 profile。
|
|
81
|
+
|
|
82
|
+
此流程通常只需要執行一次。
|
|
83
|
+
|
|
84
|
+
### 2. 直接提問
|
|
85
|
+
|
|
86
|
+
將 prompt 作為 argument 傳入:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
ask "Rust struct 和 tuple 有什麼差異?"
|
|
90
|
+
ask --provider gemini "Rust struct 和 tuple 有什麼差異?"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
執行後:
|
|
94
|
+
|
|
95
|
+
- Chrome 會開啟或聚焦所選 provider 分頁。
|
|
96
|
+
- Prompt 會自動輸入並送出。
|
|
97
|
+
- 所選 provider 的回覆會輸出到終端機。
|
|
98
|
+
|
|
99
|
+
### 3. 開啟全新對話
|
|
100
|
+
|
|
101
|
+
預設情況下,`ask` 會重用既有所選 provider 分頁,以避免建立過多分頁。
|
|
102
|
+
|
|
103
|
+
若要開啟全新的 provider 對話,使用 `--new`:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
ask "誰是保哥?" --new
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
此模式會開啟新的所選 provider 分頁,並清理先前同一 provider 的分頁。
|
|
110
|
+
|
|
111
|
+
### 4. Headless 模式
|
|
112
|
+
|
|
113
|
+
一般提問預設使用 headless Chrome,也就是 `--headless=true`。Chrome 會在背景執行,不會搶走焦點或跳出視窗。
|
|
114
|
+
|
|
115
|
+
若想觀察 Chrome 的操作過程,或需要手動檢查頁面狀態,可改用 headful 模式:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
ask "誰是保哥?" --headless=false
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`ask login` 會強制使用 headful 模式,方便你和瀏覽器 UI 互動;其他 subcommand 若要可見瀏覽器,請明確加上 `--headless=false`。
|
|
122
|
+
|
|
123
|
+
### 5. Verbose 模式
|
|
124
|
+
|
|
125
|
+
預設情況下,`ask` 只輸出所選 provider 的最終回覆,隱藏背景控制訊息。
|
|
126
|
+
|
|
127
|
+
若要查看完整瀏覽器自動化流程,加入 `--verbose`:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
ask "誰是保哥?" --verbose
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Verbose 模式會顯示類似以下流程:
|
|
134
|
+
|
|
135
|
+
- 檢查已開啟的 Chrome 分頁。
|
|
136
|
+
- 聚焦輸入欄位。
|
|
137
|
+
- 輸入 prompt。
|
|
138
|
+
- 送出訊息。
|
|
139
|
+
- 等待 provider 回覆。
|
|
140
|
+
|
|
141
|
+
### 6. 顯示版本
|
|
142
|
+
|
|
143
|
+
使用 `-v` 或 `--version` 顯示目前版本號:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
ask -v
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 7. Pipe 與 stdin
|
|
150
|
+
|
|
151
|
+
可透過 pipe 將文字或檔案內容傳入 `ask`:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
echo "用一句話解釋 quantum computing" | ask
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
若同時提供 prompt argument,`ask` 會先送出該 prompt,接著加上兩個換行後再附加管道內容:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
cat /Users/will/.copilot/session-state/46cc0f1c-79fd-4622-9548-a0b7fa3794be/research/does-cursor-support-byok.md | ask 'What is this?'
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
也可以讀取檔案內容:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
cat src/main.rs | ask "這段 Rust code 有記憶體洩漏風險嗎?"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 8. 附上圖片或文件
|
|
170
|
+
|
|
171
|
+
除了把檔案內容透過 pipe 傳入 prompt,你也可以直接把本機檔案當作附件上傳給所選 provider。
|
|
172
|
+
|
|
173
|
+
#### 附上圖片
|
|
174
|
+
|
|
175
|
+
使用 `--image` 附上一或多張本機圖片(可重複指定)。此功能目前支援 ChatGPT;Gemini 圖片輸入尚未支援,搭配 `--provider gemini` 使用會立即回報錯誤。
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
ask "請描述這張圖片的內容。" --image screenshot.png
|
|
179
|
+
ask "比較這兩張圖的差異。" --image v1.png --image v2.png
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
支援的格式包含 PNG、JPEG、GIF、WebP、SVG、BMP 等。
|
|
183
|
+
|
|
184
|
+
#### 附上文件
|
|
185
|
+
|
|
186
|
+
使用 `--file` 附上一或多份本機文件(可重複指定),例如 PDF、Word、Excel、PowerPoint、純文字、Markdown、CSV、JSON、程式碼等。ChatGPT 與 Gemini 都支援此流程。
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
ask "請摘要這份 PDF 的重點。" --file report.pdf
|
|
190
|
+
ask "這份 CSV 總共有幾筆資料?" --file data.csv
|
|
191
|
+
ask "幫我檢查這段程式碼有沒有問題。" --file src/main.rs
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
也可以同時附上圖片與文件:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
ask "請對照這張設計圖與規格文件,指出不一致的地方。" --image design.png --file spec.docx
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### 顯示上傳結果
|
|
201
|
+
|
|
202
|
+
provider 回覆後,可使用 `-i` / `--image-output` 指定生成圖片的下載路徑(資料夾或檔案路徑)。
|
|
203
|
+
|
|
204
|
+
### 9. 切換模型
|
|
205
|
+
|
|
206
|
+
使用 `--model` 在送出 prompt 前自動切換 provider 的模型。比對時不分大小寫與標點符號(`-`、`.`、空格 等)。
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
ask "用幾句話介紹 Rust。" --model GPT-5.4
|
|
210
|
+
ask "證明這個數學問題。" --model o3
|
|
211
|
+
ask "快速翻譯這段話。" --model 即時
|
|
212
|
+
ask --provider gemini "用幾句話介紹 Rust。" --model "3.5 Flash"
|
|
213
|
+
ask --provider gemini "用幾句話介紹 Rust。" --model "3.1 Pro"
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
可用的模型名稱(視帳號權限與 provider UI 而定):
|
|
217
|
+
|
|
218
|
+
- **ChatGPT 模型**:`GPT-5.5`、`GPT-5.4`、`GPT-5.3`、`o3`
|
|
219
|
+
- **ChatGPT 思考強度**:`智慧`、`即時`、`中等`、`高`、`超高`、`專業`
|
|
220
|
+
- **Gemini 模式**:`3.5 Flash`、`3.1 Flash-Lite`、`3.1 Pro`
|
|
221
|
+
|
|
222
|
+
> 若指定的名稱在選單中找不到,`ask` 會回報 `Model switch failed: error: model not found in menu` 並中止,不會送出 prompt。
|
|
223
|
+
|
|
224
|
+
### 10. 只開啟 provider
|
|
225
|
+
|
|
226
|
+
若只想快速開啟瀏覽器並進入所選 provider:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
ask open
|
|
230
|
+
ask --provider gemini open
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### 11. 關閉瀏覽器 instance
|
|
234
|
+
|
|
235
|
+
若要關閉 `ask` 管理的 Chrome debug profile instance:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
ask close
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
`close` 只會關閉使用 `~/.config/ask-bridge/chrome-profile` 且監聽 debug port `9223` 的 `ask` Chrome instance;若該 port 被非 `ask` Chrome 程序占用,會回報錯誤而不會關閉它。
|
|
242
|
+
|
|
243
|
+
## 運作原理
|
|
244
|
+
|
|
245
|
+
1. **瀏覽器初始化**:`ask` 會檢查 Chrome 是否正在監聽 debug port `9223`。若沒有,會以專屬 profile 目錄 `~/.config/ask-bridge/chrome-profile` 啟動 Google Chrome。
|
|
246
|
+
2. **MCP Bridge 設定**:啟動時會自動寫入 `~/.config/ask-bridge/mcp_servers.json`,預設設定 Chrome DevTools MCP server,使用 `chrome-devtools-mcp@latest` 與 `--browser-url=http://127.0.0.1:9223`。
|
|
247
|
+
3. **Client 呼叫**:`ask` 透過內建的 `doggy8088/mcp-cli` Rust library dependency 呼叫 MCP tools,例如 `list_pages`、`select_page`、`type_text` 與 `evaluate_script`,不依賴系統上的外部 `mcp-cli` 命令。
|
|
248
|
+
4. **狀態輪詢**:provider 產生回覆期間,工具會以 JavaScript 檢查送出與停止按鈕狀態,擷取回覆元素的文字內容,並輸出到 `stdout`。
|
|
249
|
+
|
|
250
|
+
## 相關文件
|
|
251
|
+
|
|
252
|
+
- [快速開始](docs/quick-start.md)
|
|
253
|
+
- [背景 Chrome 隱形技術與實作原理](docs/headless-techniques.md)
|
|
254
|
+
|
|
255
|
+
## 授權
|
|
256
|
+
|
|
257
|
+
MIT License。可自由使用、修改與散布。
|
package/npm/cli.cjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { spawnSync } = require('node:child_process');
|
|
5
|
+
const { existsSync } = require('node:fs');
|
|
6
|
+
const { join } = require('node:path');
|
|
7
|
+
|
|
8
|
+
const BINARY_NAME = "ask-bridge";
|
|
9
|
+
const exe = process.platform === 'win32' ? `${BINARY_NAME}.exe` : BINARY_NAME;
|
|
10
|
+
const bin = join(__dirname, `${BINARY_NAME}-bin`, exe);
|
|
11
|
+
|
|
12
|
+
if (!existsSync(bin)) {
|
|
13
|
+
console.error(`${BINARY_NAME} native binary was not found. Try reinstalling ${BINARY_NAME}.`);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const result = spawnSync(bin, process.argv.slice(2), { stdio: 'inherit' });
|
|
18
|
+
if (result.error) {
|
|
19
|
+
console.error(result.error.message);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
process.exit(result.status ?? 1);
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { createHash } = require('node:crypto');
|
|
5
|
+
const { spawnSync } = require('node:child_process');
|
|
6
|
+
const {
|
|
7
|
+
chmodSync,
|
|
8
|
+
copyFileSync,
|
|
9
|
+
existsSync,
|
|
10
|
+
mkdirSync,
|
|
11
|
+
readFileSync,
|
|
12
|
+
readdirSync,
|
|
13
|
+
rmSync,
|
|
14
|
+
writeFileSync,
|
|
15
|
+
} = require('node:fs');
|
|
16
|
+
const { get } = require('node:https');
|
|
17
|
+
const { join } = require('node:path');
|
|
18
|
+
const { URL } = require('node:url');
|
|
19
|
+
|
|
20
|
+
const PACKAGE_ROOT = join(__dirname, '..');
|
|
21
|
+
const BINARY_NAME = "ask-bridge";
|
|
22
|
+
const GITHUB_OWNER = "doggy8088";
|
|
23
|
+
const GITHUB_REPO = "ask-bridge";
|
|
24
|
+
const BIN_DIR = join(__dirname, `${BINARY_NAME}-bin`);
|
|
25
|
+
const BIN_NAME = process.platform === 'win32' ? `${BINARY_NAME}.exe` : BINARY_NAME;
|
|
26
|
+
const DEST = join(BIN_DIR, BIN_NAME);
|
|
27
|
+
|
|
28
|
+
const TARGETS = {
|
|
29
|
+
'darwin-arm64': 'aarch64-apple-darwin',
|
|
30
|
+
'darwin-x64': 'x86_64-apple-darwin',
|
|
31
|
+
'linux-x64': 'x86_64-unknown-linux-gnu',
|
|
32
|
+
'win32-x64': 'x86_64-pc-windows-msvc',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function platformKey(platform = process.platform, arch = process.arch) {
|
|
36
|
+
return `${platform}-${arch}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function cargoTarget(platform = process.platform, arch = process.arch) {
|
|
40
|
+
const target = TARGETS[platformKey(platform, arch)];
|
|
41
|
+
if (!target) {
|
|
42
|
+
throw new Error(`Unsupported platform: ${platform}/${arch}`);
|
|
43
|
+
}
|
|
44
|
+
return target;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function packageVersion() {
|
|
48
|
+
return require(join(PACKAGE_ROOT, 'package.json')).version;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function artifactName(target) {
|
|
52
|
+
const ext = target.includes('windows') || target.includes('pc-windows') ? 'zip' : 'tar.xz';
|
|
53
|
+
return `${BINARY_NAME}-${target}.${ext}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function releaseBaseUrl(version = packageVersion()) {
|
|
57
|
+
return `https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}/releases/download/v${version}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function sha256(path) {
|
|
61
|
+
return createHash('sha256').update(readFileSync(path)).digest('hex');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function verifyChecksum(filePath, checksumText) {
|
|
65
|
+
const expected = checksumText.trim().split(/\s+/)[0].toLowerCase();
|
|
66
|
+
if (!/^[a-f0-9]{64}$/.test(expected)) {
|
|
67
|
+
throw new Error('Invalid checksum file format');
|
|
68
|
+
}
|
|
69
|
+
const actual = sha256(filePath);
|
|
70
|
+
if (actual !== expected) {
|
|
71
|
+
throw new Error(`Checksum mismatch for ${filePath}: expected ${expected}, got ${actual}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function download(url, destination, redirectsRemaining = 5) {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
get(url, (res) => {
|
|
78
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location && redirectsRemaining > 0) {
|
|
79
|
+
const nextUrl = new URL(res.headers.location, url).toString();
|
|
80
|
+
download(nextUrl, destination, redirectsRemaining - 1).then(resolve, reject);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (res.statusCode !== 200) {
|
|
84
|
+
reject(new Error(`Download failed ${res.statusCode}: ${url}`));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const chunks = [];
|
|
88
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
89
|
+
res.on('end', () => {
|
|
90
|
+
writeFileSync(destination, Buffer.concat(chunks));
|
|
91
|
+
resolve();
|
|
92
|
+
});
|
|
93
|
+
}).on('error', reject);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function run(command, args) {
|
|
98
|
+
const result = spawnSync(command, args, { stdio: 'inherit' });
|
|
99
|
+
if (result.error) throw result.error;
|
|
100
|
+
if (result.status !== 0) throw new Error(`Command failed: ${command}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function extract(archive, destDir) {
|
|
104
|
+
mkdirSync(destDir, { recursive: true });
|
|
105
|
+
if (archive.endsWith('.zip')) {
|
|
106
|
+
if (process.platform === 'win32') {
|
|
107
|
+
run('powershell', ['-NoProfile', '-Command', 'Expand-Archive', '-Force', '-Path', archive, '-DestinationPath', destDir]);
|
|
108
|
+
} else {
|
|
109
|
+
run('unzip', ['-o', archive, '-d', destDir]);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
run('tar', ['-xJf', archive, '-C', destDir]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function findExtractedBinary(dir, binName = BIN_NAME) {
|
|
117
|
+
const direct = join(dir, binName);
|
|
118
|
+
if (existsSync(direct)) return direct;
|
|
119
|
+
|
|
120
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
121
|
+
if (!entry.isDirectory()) continue;
|
|
122
|
+
const candidate = join(dir, entry.name, binName);
|
|
123
|
+
if (existsSync(candidate)) return candidate;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
throw new Error(`Archive did not contain ${binName}`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function installFromLocalBuild() {
|
|
130
|
+
const localRelease = join(PACKAGE_ROOT, 'target', 'release', BIN_NAME);
|
|
131
|
+
if (!existsSync(localRelease)) return false;
|
|
132
|
+
mkdirSync(BIN_DIR, { recursive: true });
|
|
133
|
+
copyFileSync(localRelease, DEST);
|
|
134
|
+
chmodSync(DEST, 0o755);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function installFromRelease() {
|
|
139
|
+
const target = cargoTarget();
|
|
140
|
+
const archive = artifactName(target);
|
|
141
|
+
const base = releaseBaseUrl();
|
|
142
|
+
const tmpDir = join(BIN_DIR, '.tmp');
|
|
143
|
+
const archivePath = join(tmpDir, archive);
|
|
144
|
+
const checksumPath = `${archivePath}.sha256`;
|
|
145
|
+
|
|
146
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
147
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
148
|
+
await download(`${base}/${archive}`, archivePath);
|
|
149
|
+
await download(`${base}/${archive}.sha256`, checksumPath);
|
|
150
|
+
verifyChecksum(archivePath, readFileSync(checksumPath, 'utf8'));
|
|
151
|
+
extract(archivePath, tmpDir);
|
|
152
|
+
|
|
153
|
+
const extracted = findExtractedBinary(tmpDir);
|
|
154
|
+
mkdirSync(BIN_DIR, { recursive: true });
|
|
155
|
+
copyFileSync(extracted, DEST);
|
|
156
|
+
chmodSync(DEST, 0o755);
|
|
157
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function main() {
|
|
161
|
+
if (installFromLocalBuild()) return;
|
|
162
|
+
await installFromRelease();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (require.main === module) {
|
|
166
|
+
main().catch((error) => {
|
|
167
|
+
console.error(error.message);
|
|
168
|
+
process.exit(1);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports = {
|
|
173
|
+
TARGETS,
|
|
174
|
+
artifactName,
|
|
175
|
+
cargoTarget,
|
|
176
|
+
findExtractedBinary,
|
|
177
|
+
platformKey,
|
|
178
|
+
releaseBaseUrl,
|
|
179
|
+
sha256,
|
|
180
|
+
verifyChecksum,
|
|
181
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { request } = require('node:https');
|
|
5
|
+
const { URL } = require('node:url');
|
|
6
|
+
const { artifactName, releaseBaseUrl, TARGETS } = require('./postinstall.cjs');
|
|
7
|
+
|
|
8
|
+
const MAX_REDIRECTS = 5;
|
|
9
|
+
|
|
10
|
+
function packageVersion() {
|
|
11
|
+
return require('../package.json').version;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function expectedReleaseUrls(version = packageVersion()) {
|
|
15
|
+
const base = releaseBaseUrl(version);
|
|
16
|
+
return Object.values(TARGETS).flatMap((target) => {
|
|
17
|
+
const archive = artifactName(target);
|
|
18
|
+
return [`${base}/${archive}`, `${base}/${archive}.sha256`];
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function checkUrl(url, redirectsRemaining = MAX_REDIRECTS) {
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
const req = request(url, { method: 'HEAD' }, (res) => {
|
|
25
|
+
const { statusCode, headers } = res;
|
|
26
|
+
res.resume();
|
|
27
|
+
|
|
28
|
+
if (statusCode >= 300 && statusCode < 400 && headers.location && redirectsRemaining > 0) {
|
|
29
|
+
const nextUrl = new URL(headers.location, url).toString();
|
|
30
|
+
checkUrl(nextUrl, redirectsRemaining - 1).then((result) => resolve({ ...result, url }));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
resolve({
|
|
35
|
+
url,
|
|
36
|
+
ok: statusCode >= 200 && statusCode < 300,
|
|
37
|
+
statusCode,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
req.on('error', (error) => {
|
|
42
|
+
resolve({ url, ok: false, errorMessage: error.message });
|
|
43
|
+
});
|
|
44
|
+
req.end();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function retryCountFromEnv() {
|
|
49
|
+
return Number.parseInt(process.env.ASK_CHATGPT_RELEASE_ASSET_RETRIES ?? '1', 10);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function retryDelayMsFromEnv() {
|
|
53
|
+
return Number.parseInt(process.env.ASK_CHATGPT_RELEASE_ASSET_RETRY_DELAY_MS ?? '1000', 10);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function sleep(ms) {
|
|
57
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function formatFailure(result) {
|
|
61
|
+
const reason = result.statusCode ? `HTTP ${result.statusCode}` : result.errorMessage;
|
|
62
|
+
return `- ${result.url} (${reason})`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function verifyReleaseAssets({
|
|
66
|
+
version = packageVersion(),
|
|
67
|
+
check = checkUrl,
|
|
68
|
+
retries = retryCountFromEnv(),
|
|
69
|
+
retryDelayMs = retryDelayMsFromEnv(),
|
|
70
|
+
} = {}) {
|
|
71
|
+
const urls = expectedReleaseUrls(version);
|
|
72
|
+
let failures = [];
|
|
73
|
+
|
|
74
|
+
for (let attempt = 1; attempt <= retries; attempt += 1) {
|
|
75
|
+
const results = await Promise.all(
|
|
76
|
+
urls.map(async (url) => ({
|
|
77
|
+
url,
|
|
78
|
+
...(await check(url)),
|
|
79
|
+
})),
|
|
80
|
+
);
|
|
81
|
+
failures = results.filter((result) => !result.ok);
|
|
82
|
+
if (failures.length === 0) return urls;
|
|
83
|
+
if (attempt < retries) await sleep(retryDelayMs);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
throw new Error(
|
|
87
|
+
[
|
|
88
|
+
`Missing or unavailable release assets for v${version}:`,
|
|
89
|
+
...failures.map(formatFailure),
|
|
90
|
+
'Create and host the GitHub release assets before publishing npm.',
|
|
91
|
+
].join('\n'),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function main() {
|
|
96
|
+
const version = packageVersion();
|
|
97
|
+
const urls = await verifyReleaseAssets({ version });
|
|
98
|
+
console.log(`Verified ${urls.length} release assets for v${version}.`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (require.main === module) {
|
|
102
|
+
main().catch((error) => {
|
|
103
|
+
console.error(error.message);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = {
|
|
109
|
+
checkUrl,
|
|
110
|
+
expectedReleaseUrls,
|
|
111
|
+
formatFailure,
|
|
112
|
+
retryCountFromEnv,
|
|
113
|
+
retryDelayMsFromEnv,
|
|
114
|
+
verifyReleaseAssets,
|
|
115
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ask-bridge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Automate ChatGPT or Gemini from the command line through Chrome.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"ask": "npm/cli.cjs"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node npm/postinstall.cjs",
|
|
10
|
+
"test": "node --test tests/postinstall.test.cjs",
|
|
11
|
+
"prepublishOnly": "npm test && npm pack --dry-run && node npm/prepublish-check.cjs"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"npm/cli.cjs",
|
|
15
|
+
"npm/postinstall.cjs",
|
|
16
|
+
"npm/prepublish-check.cjs",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/doggy8088/ask-bridge.git"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"chatgpt",
|
|
26
|
+
"gemini",
|
|
27
|
+
"chrome",
|
|
28
|
+
"rust",
|
|
29
|
+
"cli"
|
|
30
|
+
],
|
|
31
|
+
"author": "",
|
|
32
|
+
"license": "MIT"
|
|
33
|
+
}
|