ask-bridge 0.2.4 → 0.2.10
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.en.md +66 -25
- package/README.md +71 -24
- package/npm/postinstall.cjs +63 -0
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -38,7 +38,9 @@ Unlike typical API clients, `ask-bridge` operates inside a real Chrome browser w
|
|
|
38
38
|
- **🧠 Intelligent Tab Management**: Reuses existing provider tabs if open, focuses them, or opens new ones, avoiding tab clutter.
|
|
39
39
|
- **🖥️ Pipe & Stdin Support**: Supports piping prompts via `stdin` (e.g. `cat report.txt | ask-bridge "summarize this"`).
|
|
40
40
|
- **📎 Image & File Attachments**: Attach local images with `--image` (supported on ChatGPT and Claude), or documents (PDF, Word, Excel, plain text, Markdown, JSON, etc.) with `--file`; Gemini currently supports `--file` and rejects `--image`.
|
|
41
|
-
- **🔀 Model
|
|
41
|
+
- **🔀 Model and Reasoning Selection**: Use `--model` for provider models and `--reasoning` for ChatGPT reasoning effort or Gemini Extended Thinking.
|
|
42
|
+
- **Resume Conversations**: Use `--session`, `--session-id`, or `--session-url` to continue an existing provider conversation with a new terminal prompt.
|
|
43
|
+
- **Response Timeout**: Use `--timeout <seconds>` to control how long to wait for a provider response, defaulting to `300` seconds.
|
|
42
44
|
- **🔍 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.
|
|
43
45
|
- **Version Info**: Use `-v` or `--version` to print the current version number.
|
|
44
46
|
|
|
@@ -89,6 +91,10 @@ irm https://raw.githubusercontent.com/doggy8088/ask-bridge/main/install.ps1 | ie
|
|
|
89
91
|
> [!NOTE]
|
|
90
92
|
> Make sure the installation path (`~/.local/bin` for macOS/Linux, and `$HOME\.local\bin` for Windows) is added to your system's `PATH` environment variable.
|
|
91
93
|
> The formal CLI command is `ask-bridge`; the installer also provides `ask` as a backward-compatible alias. The examples below use `ask-bridge`.
|
|
94
|
+
> The Windows installer verifies that the download is a PE executable, runs a
|
|
95
|
+
> `--version` smoke test, and puts the official install directory first in User
|
|
96
|
+
> PATH. Run `where.exe ask-bridge` and confirm that the first expanded path ends
|
|
97
|
+
> with `\.local\bin\ask-bridge.exe`.
|
|
92
98
|
|
|
93
99
|
### 2. Build & Install from Source (For Developers)
|
|
94
100
|
|
|
@@ -147,8 +153,8 @@ ask-bridge --provider claude login
|
|
|
147
153
|
|
|
148
154
|
- This will automatically launch Google Chrome with a dedicated, persistent debug profile.
|
|
149
155
|
- Log in manually to the selected provider page, such as `https://chatgpt.com/`, `https://gemini.google.com/app`, or `https://claude.ai/new`.
|
|
150
|
-
-
|
|
151
|
-
-
|
|
156
|
+
- The tool now checks login status every second automatically, so you can stay on the browser and it will return immediately after login is detected.
|
|
157
|
+
- If login is not detected within `--timeout` seconds (default: 300), it will warn you to verify the result and retry.
|
|
152
158
|
|
|
153
159
|
#### Global Provider Config
|
|
154
160
|
|
|
@@ -202,9 +208,29 @@ ask-bridge "誰是保哥?" --new
|
|
|
202
208
|
```
|
|
203
209
|
|
|
204
210
|
- This will open a **brand new selected-provider tab**.
|
|
205
|
-
-
|
|
211
|
+
- All provider and non-provider tabs that existed before the command will be preserved.
|
|
212
|
+
- If the new tab cannot be identified unambiguously, the command stops instead of
|
|
213
|
+
reusing or closing an existing tab.
|
|
206
214
|
|
|
207
|
-
### 4.
|
|
215
|
+
### 4. Resume an Existing Conversation
|
|
216
|
+
|
|
217
|
+
Pass either a provider conversation ID or a full conversation URL to continue its
|
|
218
|
+
existing web context:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
ask-bridge --provider chatgpt --session-id "conversation-uuid" "Continue the previous plan."
|
|
222
|
+
ask-bridge --session-url "https://chatgpt.com/c/conversation-uuid" "Produce the next steps."
|
|
223
|
+
ask-bridge --provider gemini --session "conversation-id" "Continue the analysis."
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
`--session`, `--session-id`, and `--session-url` are aliases for the same option.
|
|
227
|
+
An ID uses the selected or configured provider to build the conversation URL. A
|
|
228
|
+
full URL identifies its provider automatically. The command stops before opening
|
|
229
|
+
Chrome when an explicitly selected provider conflicts with the URL, the URL does
|
|
230
|
+
not belong to a supported provider, or `--new` is also supplied. Existing tabs
|
|
231
|
+
are preserved.
|
|
232
|
+
|
|
233
|
+
### 5. Headless Mode (Default: True)
|
|
208
234
|
|
|
209
235
|
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.
|
|
210
236
|
|
|
@@ -216,7 +242,7 @@ ask-bridge "誰是保哥?" --headless=false
|
|
|
216
242
|
|
|
217
243
|
*Note: `ask-bridge 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.*
|
|
218
244
|
|
|
219
|
-
###
|
|
245
|
+
### 6. Verbose Mode (`--verbose`)
|
|
220
246
|
|
|
221
247
|
By default, `ask-bridge` 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.
|
|
222
248
|
|
|
@@ -233,7 +259,23 @@ This will print every stage of the browser automation:
|
|
|
233
259
|
- Submitting...
|
|
234
260
|
- Waiting for provider response...
|
|
235
261
|
|
|
236
|
-
###
|
|
262
|
+
### 7. Response Timeout (`--timeout`)
|
|
263
|
+
|
|
264
|
+
The default wait time is 300 seconds. If a provider takes longer, increase (or decrease) the timeout:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
ask-bridge "Please summarize this report" --timeout 600
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
You can also set a shorter timeout:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
ask-bridge "Short answer" --timeout 60
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
If the response does not complete within the configured seconds, `ask-bridge` will stop waiting and print a timeout warning.
|
|
277
|
+
|
|
278
|
+
### 8. Version Info
|
|
237
279
|
|
|
238
280
|
Use `-v` or `--version` to print the current version number:
|
|
239
281
|
|
|
@@ -241,7 +283,7 @@ Use `-v` or `--version` to print the current version number:
|
|
|
241
283
|
ask-bridge -v
|
|
242
284
|
```
|
|
243
285
|
|
|
244
|
-
###
|
|
286
|
+
### 9. Piping & Stdin Support
|
|
245
287
|
|
|
246
288
|
You can pipe text or files directly into `ask-bridge`:
|
|
247
289
|
|
|
@@ -261,7 +303,7 @@ Or read files:
|
|
|
261
303
|
cat src/main.rs | ask-bridge "Are there any memory leaks in this Rust code?"
|
|
262
304
|
```
|
|
263
305
|
|
|
264
|
-
###
|
|
306
|
+
### 10. Attaching Images or Files
|
|
265
307
|
|
|
266
308
|
Instead of piping file contents into the prompt, you can upload local files as attachments directly to the selected provider.
|
|
267
309
|
|
|
@@ -293,30 +335,29 @@ You can attach images and documents at the same time:
|
|
|
293
335
|
ask-bridge "Compare this design image against the spec document and list inconsistencies." --image design.png --file spec.docx
|
|
294
336
|
```
|
|
295
337
|
|
|
296
|
-
###
|
|
338
|
+
### 11. Switch Models and Reasoning
|
|
297
339
|
|
|
298
|
-
Use `--model` to
|
|
340
|
+
Use `--model` to switch the provider model before the prompt is sent. Use `--reasoning` separately for provider-specific reasoning modes. ChatGPT accepts both in one invocation; Gemini Extended Thinking is compatible only with Pro models.
|
|
299
341
|
|
|
300
342
|
```bash
|
|
301
|
-
ask-bridge "
|
|
302
|
-
ask-bridge "
|
|
303
|
-
ask-bridge "
|
|
304
|
-
ask-bridge --provider gemini "
|
|
305
|
-
ask-bridge --provider gemini "Introduce Rust in a few sentences." --model "3.1 Pro"
|
|
343
|
+
ask-bridge "Prove this math problem." --model "GPT-5.6 Sol" --reasoning high
|
|
344
|
+
ask-bridge "Quickly translate this." --reasoning instant
|
|
345
|
+
ask-bridge --provider gemini "Introduce Rust in a few sentences." --model "3.6 Flash"
|
|
346
|
+
ask-bridge --provider gemini "Prove this math problem." --model "3.1 Pro" --reasoning extended
|
|
306
347
|
ask-bridge --provider claude "Introduce Rust in a few sentences." --model Sonnet
|
|
307
|
-
ask-bridge --provider claude "Prove this math problem." --model Opus
|
|
308
348
|
```
|
|
309
349
|
|
|
310
|
-
|
|
350
|
+
Argument rules:
|
|
351
|
+
|
|
352
|
+
- **ChatGPT**: `--reasoning` accepts `auto`, `instant`, `medium`, and `high`, plus the corresponding aliases `智慧`, `即時`, `中`, `中等`, and `高`.
|
|
353
|
+
- **Gemini**: `--reasoning extended` selects Extended Thinking. Omit `--model` or combine it with an available Pro model.
|
|
354
|
+
- **Claude**: `--reasoning` is unsupported. Existing Sonnet, Opus, and Haiku `--model` selection is unchanged.
|
|
311
355
|
|
|
312
|
-
|
|
313
|
-
- **ChatGPT thinking levels**: `智慧`, `即時`, `中等`, `高`, `超高`, `專業`
|
|
314
|
-
- **Gemini modes**: `3.5 Flash`, `3.1 Flash-Lite`, `3.1 Pro`
|
|
315
|
-
- **Claude models**: `Sonnet`, `Opus`, `Haiku` (actual names depend on the claude.ai menu and your plan)
|
|
356
|
+
Model matching uses only each menu item's primary label and ignores subtitles and badges. It remains case- and punctuation-insensitive. The tool never maps an obsolete model version to a different version. If the primary label is unavailable, the error lists the provider options currently found and aborts before sending the prompt.
|
|
316
357
|
|
|
317
|
-
|
|
358
|
+
Legacy forms such as `--model 高` and Gemini `--model 延伸思考` remain temporarily supported with a deprecation warning. Use `--reasoning` instead.
|
|
318
359
|
|
|
319
|
-
###
|
|
360
|
+
### 12. Just Open a Provider
|
|
320
361
|
|
|
321
362
|
To quickly launch the browser and open the selected provider without sending any query:
|
|
322
363
|
|
|
@@ -326,7 +367,7 @@ ask-bridge --provider gemini open
|
|
|
326
367
|
ask-bridge --provider claude open
|
|
327
368
|
```
|
|
328
369
|
|
|
329
|
-
###
|
|
370
|
+
### 13. Close the Browser Instance
|
|
330
371
|
|
|
331
372
|
To close the Chrome debug profile instance managed by `ask-bridge`:
|
|
332
373
|
|
package/README.md
CHANGED
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
- **智慧分頁管理**:可重用既有 provider 分頁、聚焦分頁,或開啟新分頁,避免分頁過度增加。
|
|
38
38
|
- **Pipe 與 stdin 支援**:支援透過 standard input 傳入 prompt,例如 `cat report.txt | ask-bridge "summarize this"`。
|
|
39
39
|
- **圖片與文件上傳**:可透過 `--image` 附上圖片(支援 ChatGPT 與 Claude),或透過 `--file` 附上文件(PDF、Word、Excel、純文字、Markdown、JSON 等皆可),一次可指定多個檔案;Gemini 目前支援 `--file`,不支援 `--image` 圖片輸入。
|
|
40
|
-
-
|
|
40
|
+
- **模型與推理模式切換**:使用 `--model` 選模型,並以 `--reasoning` 分別控制 ChatGPT 推理強度或 Gemini 延伸思考。
|
|
41
|
+
- **接續既有對話**:使用 `--session`、`--session-id` 或 `--session-url` 指定既有對話,再從終端機送出新的 prompt。
|
|
42
|
+
- **回應超時**:使用 `--timeout <秒數>` 設定等待回應上限,預設為 `300` 秒。
|
|
41
43
|
- **預設安靜模式與 verbose 模式**:預設只輸出最終回覆;加上 `--verbose` 可顯示背景瀏覽器控制流程。
|
|
42
44
|
- **版本資訊**:使用 `-v` 或 `--version` 顯示目前版本號。
|
|
43
45
|
|
|
@@ -84,6 +86,9 @@ irm https://raw.githubusercontent.com/doggy8088/ask-bridge/main/install.ps1 | ie
|
|
|
84
86
|
> [!NOTE]
|
|
85
87
|
> 請確保安裝路徑(macOS/Linux 為 `~/.local/bin`;Windows 為 `$HOME\.local\bin`)已加入您的系統 `PATH` 環境變數中。
|
|
86
88
|
> 正式 CLI 命令為 `ask-bridge`;安裝流程也會提供 `ask` 作為向後相容 alias。以下範例皆以 `ask-bridge` 為準。
|
|
89
|
+
> Windows 安裝程式會驗證下載檔為 PE 執行檔、執行 `--version` smoke test,
|
|
90
|
+
> 並把正式安裝目錄放在 User PATH 最前面。可用 `where.exe ask-bridge`
|
|
91
|
+
> 確認第一筆展開後的完整路徑結尾為 `\.local\bin\ask-bridge.exe`。
|
|
87
92
|
|
|
88
93
|
### 2. 從原始碼建置與安裝 (適用於開發者)
|
|
89
94
|
|
|
@@ -143,7 +148,7 @@ ask-bridge --provider claude login
|
|
|
143
148
|
- 使用專屬且持久化的 debug profile 啟動 Google Chrome。
|
|
144
149
|
- 開啟所選 provider 頁面,例如 `https://chatgpt.com/`、`https://gemini.google.com/app` 或 `https://claude.ai/new`。
|
|
145
150
|
- 等待你手動登入帳號。
|
|
146
|
-
-
|
|
151
|
+
- 本工具會每秒自動偵測登入狀態,不需要你回到終端機按 Enter;若超過 `--timeout`(預設 300 秒)仍未偵測到登入完成,會提醒你再確認一次。
|
|
147
152
|
|
|
148
153
|
此流程通常只需要執行一次。
|
|
149
154
|
|
|
@@ -200,9 +205,26 @@ ask-bridge --provider claude "Rust struct 和 tuple 有什麼差異?"
|
|
|
200
205
|
ask-bridge "誰是保哥?" --new
|
|
201
206
|
```
|
|
202
207
|
|
|
203
|
-
|
|
208
|
+
此模式只會開啟並使用新的所選 provider 分頁。執行前已存在的 provider
|
|
209
|
+
分頁與其他網站分頁都會保留;若無法唯一辨識新分頁,命令會停止且不會改用
|
|
210
|
+
或關閉既有分頁。
|
|
204
211
|
|
|
205
|
-
### 4.
|
|
212
|
+
### 4. 接續既有對話
|
|
213
|
+
|
|
214
|
+
使用 provider 對話 ID 或完整對話 URL,可接續網頁端既有的對話脈絡:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
ask-bridge --provider chatgpt --session-id "conversation-uuid" "請接續先前的規劃。"
|
|
218
|
+
ask-bridge --session-url "https://chatgpt.com/c/conversation-uuid" "請產出下一步計畫。"
|
|
219
|
+
ask-bridge --provider gemini --session "conversation-id" "請繼續分析。"
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
`--session`、`--session-id` 與 `--session-url` 是相同參數的別名。傳入 ID
|
|
223
|
+
時會依 `--provider` 或全域設定組成 provider 對話 URL;傳入完整 URL 時會辨識
|
|
224
|
+
provider。若同時明確指定不相符的 `--provider`、URL 不屬於支援的 provider,
|
|
225
|
+
或與 `--new` 同時使用,命令會在開啟瀏覽器前停止。既有頁籤不會被關閉。
|
|
226
|
+
|
|
227
|
+
### 5. Headless 模式
|
|
206
228
|
|
|
207
229
|
一般提問預設使用 headless Chrome,也就是 `--headless=true`。Chrome 會在背景執行,不會搶走焦點或跳出視窗。
|
|
208
230
|
|
|
@@ -214,7 +236,7 @@ ask-bridge "誰是保哥?" --headless=false
|
|
|
214
236
|
|
|
215
237
|
`ask-bridge login` 會強制使用 headful 模式,方便你和瀏覽器 UI 互動;其他 subcommand 若要可見瀏覽器,請明確加上 `--headless=false`。
|
|
216
238
|
|
|
217
|
-
###
|
|
239
|
+
### 6. Verbose 模式
|
|
218
240
|
|
|
219
241
|
預設情況下,`ask-bridge` 只輸出所選 provider 的最終回覆,隱藏背景控制訊息。
|
|
220
242
|
|
|
@@ -232,7 +254,23 @@ Verbose 模式會顯示類似以下流程:
|
|
|
232
254
|
- 送出訊息。
|
|
233
255
|
- 等待 provider 回覆。
|
|
234
256
|
|
|
235
|
-
###
|
|
257
|
+
### 7. 回應超時(`--timeout`)
|
|
258
|
+
|
|
259
|
+
回答等待預設 300 秒,若 provider 回應時間較長可提高(或降低)等待上限:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
ask-bridge "請幫我整理這份報告" --timeout 600
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
你也可以明確設定較短時間:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
ask-bridge "簡短回覆" --timeout 60
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
超過設定秒數仍未完成時,會輸出超時警告並直接結束回應等待流程。
|
|
272
|
+
|
|
273
|
+
### 8. 顯示版本
|
|
236
274
|
|
|
237
275
|
使用 `-v` 或 `--version` 顯示目前版本號:
|
|
238
276
|
|
|
@@ -240,7 +278,7 @@ Verbose 模式會顯示類似以下流程:
|
|
|
240
278
|
ask-bridge -v
|
|
241
279
|
```
|
|
242
280
|
|
|
243
|
-
###
|
|
281
|
+
### 9. Pipe 與 stdin
|
|
244
282
|
|
|
245
283
|
可透過 pipe 將文字或檔案內容傳入 `ask-bridge`:
|
|
246
284
|
|
|
@@ -260,7 +298,7 @@ cat /Users/will/.copilot/session-state/46cc0f1c-79fd-4622-9548-a0b7fa3794be/rese
|
|
|
260
298
|
cat src/main.rs | ask-bridge "這段 Rust code 有記憶體洩漏風險嗎?"
|
|
261
299
|
```
|
|
262
300
|
|
|
263
|
-
###
|
|
301
|
+
### 10. 附上圖片或文件
|
|
264
302
|
|
|
265
303
|
除了把檔案內容透過 pipe 傳入 prompt,你也可以直接把本機檔案當作附件上傳給所選 provider。
|
|
266
304
|
|
|
@@ -296,30 +334,29 @@ ask-bridge "請對照這張設計圖與規格文件,指出不一致的地方
|
|
|
296
334
|
|
|
297
335
|
provider 回覆後,可使用 `-i` / `--image-output` 指定生成圖片的下載路徑(資料夾或檔案路徑)。
|
|
298
336
|
|
|
299
|
-
###
|
|
337
|
+
### 11. 切換模型與推理模式
|
|
300
338
|
|
|
301
|
-
使用 `--model` 在送出 prompt
|
|
339
|
+
使用 `--model` 在送出 prompt 前切換 provider 模型;使用 `--reasoning` 分別指定 provider 支援的推理模式。兩者可在同一次 ChatGPT 呼叫中併用;Gemini 的延伸思考只相容於 Pro 模型。
|
|
302
340
|
|
|
303
341
|
```bash
|
|
304
|
-
ask-bridge "
|
|
305
|
-
ask-bridge "
|
|
306
|
-
ask-bridge "
|
|
307
|
-
ask-bridge --provider gemini "
|
|
308
|
-
ask-bridge --provider gemini "用幾句話介紹 Rust。" --model "3.1 Pro"
|
|
342
|
+
ask-bridge "證明這個數學問題。" --model "GPT-5.6 Sol" --reasoning high
|
|
343
|
+
ask-bridge "快速翻譯這段話。" --reasoning instant
|
|
344
|
+
ask-bridge --provider gemini "用幾句話介紹 Rust。" --model "3.6 Flash"
|
|
345
|
+
ask-bridge --provider gemini "證明這個數學問題。" --model "3.1 Pro" --reasoning extended
|
|
309
346
|
ask-bridge --provider claude "用幾句話介紹 Rust。" --model Sonnet
|
|
310
|
-
ask-bridge --provider claude "證明這個數學問題。" --model Opus
|
|
311
347
|
```
|
|
312
348
|
|
|
313
|
-
|
|
349
|
+
參數規則:
|
|
350
|
+
|
|
351
|
+
- **ChatGPT**:`--reasoning` 支援 `auto`、`instant`、`medium`、`high`,也接受 `智慧`、`即時`、`中`、`中等`、`高` 等對應別名。
|
|
352
|
+
- **Gemini**:`--reasoning extended` 選擇 Extended Thinking;可省略 `--model`,或搭配實際存在的 Pro 模型。
|
|
353
|
+
- **Claude**:不支援 `--reasoning`;`--model` 的 Sonnet、Opus、Haiku 選擇流程維持不變。
|
|
314
354
|
|
|
315
|
-
|
|
316
|
-
- **ChatGPT 思考強度**:`智慧`、`即時`、`中等`、`高`、`超高`、`專業`
|
|
317
|
-
- **Gemini 模式**:`3.5 Flash`、`3.1 Flash-Lite`、`3.1 Pro`
|
|
318
|
-
- **Claude 模型**:`Sonnet`、`Opus`、`Haiku`(實際名稱依 claude.ai 選單與帳號方案而定)
|
|
355
|
+
模型比對只使用選單的主標籤,忽略副標題與 badge;比對仍不分大小寫與標點。工具不會把舊版模型名稱自動改選為其他版本。若主標籤不存在,錯誤會列出目前讀到的 provider 選項,並在送出 prompt 前中止。
|
|
319
356
|
|
|
320
|
-
|
|
357
|
+
舊用法如 `--model 高` 或 Gemini 的 `--model 延伸思考` 暫時仍可使用,但會顯示棄用警告;請改用 `--reasoning`。
|
|
321
358
|
|
|
322
|
-
###
|
|
359
|
+
### 12. 只開啟 provider
|
|
323
360
|
|
|
324
361
|
若只想快速開啟瀏覽器並進入所選 provider:
|
|
325
362
|
|
|
@@ -329,7 +366,7 @@ ask-bridge --provider gemini open
|
|
|
329
366
|
ask-bridge --provider claude open
|
|
330
367
|
```
|
|
331
368
|
|
|
332
|
-
###
|
|
369
|
+
### 13. 關閉瀏覽器 instance
|
|
333
370
|
|
|
334
371
|
若要關閉 `ask-bridge` 管理的 Chrome debug profile instance:
|
|
335
372
|
|
|
@@ -339,6 +376,16 @@ ask-bridge close
|
|
|
339
376
|
|
|
340
377
|
`close` 只會關閉使用 `~/.config/ask-bridge/chrome-profile` 且監聽 debug port `9223` 的 `ask-bridge` Chrome instance;若該 port 被非 `ask-bridge` Chrome 程序占用,會回報錯誤而不會關閉它。
|
|
341
378
|
|
|
379
|
+
### 14. 更新 ask-bridge
|
|
380
|
+
|
|
381
|
+
若要直接自動更新目前安裝的 `ask-bridge`,可直接執行:
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
ask-bridge update
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
此命令會依作業系統重新執行 README 建議的官方安裝命令(macOS / Linux 或 Windows)。
|
|
388
|
+
|
|
342
389
|
## 運作原理
|
|
343
390
|
|
|
344
391
|
1. **瀏覽器初始化**:`ask-bridge` 會檢查 Chrome 是否正在監聽 debug port `9223`。若沒有,會以專屬 profile 目錄 `~/.config/ask-bridge/chrome-profile` 啟動 Google Chrome。
|
package/npm/postinstall.cjs
CHANGED
|
@@ -5,9 +5,12 @@ const { createHash } = require('node:crypto');
|
|
|
5
5
|
const { spawnSync } = require('node:child_process');
|
|
6
6
|
const {
|
|
7
7
|
chmodSync,
|
|
8
|
+
closeSync,
|
|
8
9
|
copyFileSync,
|
|
9
10
|
existsSync,
|
|
10
11
|
mkdirSync,
|
|
12
|
+
openSync,
|
|
13
|
+
readSync,
|
|
11
14
|
readFileSync,
|
|
12
15
|
readdirSync,
|
|
13
16
|
rmSync,
|
|
@@ -72,6 +75,60 @@ function verifyChecksum(filePath, checksumText) {
|
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
|
|
78
|
+
function verifyBinaryFormat(filePath, platform = process.platform) {
|
|
79
|
+
const header = Buffer.alloc(4);
|
|
80
|
+
const descriptor = openSync(filePath, 'r');
|
|
81
|
+
let bytesRead;
|
|
82
|
+
try {
|
|
83
|
+
bytesRead = readSync(descriptor, header, 0, header.length, 0);
|
|
84
|
+
} finally {
|
|
85
|
+
closeSync(descriptor);
|
|
86
|
+
}
|
|
87
|
+
const binaryHeader = header.subarray(0, bytesRead);
|
|
88
|
+
const magic = binaryHeader.toString('hex');
|
|
89
|
+
const supportedMagic = {
|
|
90
|
+
win32: ['4d5a'],
|
|
91
|
+
linux: ['7f454c46'],
|
|
92
|
+
darwin: [
|
|
93
|
+
'feedface',
|
|
94
|
+
'cefaedfe',
|
|
95
|
+
'feedfacf',
|
|
96
|
+
'cffaedfe',
|
|
97
|
+
'cafebabe',
|
|
98
|
+
'bebafeca',
|
|
99
|
+
'cafebabf',
|
|
100
|
+
'bfbafeca',
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
const expected = supportedMagic[platform];
|
|
104
|
+
if (!expected) {
|
|
105
|
+
throw new Error(`Unsupported platform for binary verification: ${platform}`);
|
|
106
|
+
}
|
|
107
|
+
if (!expected.some((prefix) => magic.startsWith(prefix))) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Downloaded binary format does not match ${platform} (header: ${magic || 'empty'})`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function verifyInstalledBinary(filePath, platform = process.platform) {
|
|
115
|
+
verifyBinaryFormat(filePath, platform);
|
|
116
|
+
const result = spawnSync(filePath, ['--version'], { encoding: 'utf8' });
|
|
117
|
+
if (result.error) {
|
|
118
|
+
throw new Error(`Installed binary could not start: ${result.error.message}`);
|
|
119
|
+
}
|
|
120
|
+
if (result.status !== 0) {
|
|
121
|
+
const detail = `${result.stdout || ''}${result.stderr || ''}`.trim();
|
|
122
|
+
throw new Error(
|
|
123
|
+
`Installed binary failed its version check with exit code ${result.status}${detail ? `: ${detail}` : ''}`,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
const output = `${result.stdout || ''}${result.stderr || ''}`.trim();
|
|
127
|
+
if (!/^ask-bridge\s+\d+\.\d+\.\d+/.test(output)) {
|
|
128
|
+
throw new Error(`Installed binary returned unexpected version output: ${output || '(empty)'}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
75
132
|
function download(url, destination, redirectsRemaining = 5) {
|
|
76
133
|
return new Promise((resolve, reject) => {
|
|
77
134
|
get(url, (res) => {
|
|
@@ -129,9 +186,11 @@ function findExtractedBinary(dir, binName = BIN_NAME) {
|
|
|
129
186
|
function installFromLocalBuild() {
|
|
130
187
|
const localRelease = join(PACKAGE_ROOT, 'target', 'release', BIN_NAME);
|
|
131
188
|
if (!existsSync(localRelease)) return false;
|
|
189
|
+
verifyBinaryFormat(localRelease);
|
|
132
190
|
mkdirSync(BIN_DIR, { recursive: true });
|
|
133
191
|
copyFileSync(localRelease, DEST);
|
|
134
192
|
chmodSync(DEST, 0o755);
|
|
193
|
+
verifyInstalledBinary(DEST);
|
|
135
194
|
return true;
|
|
136
195
|
}
|
|
137
196
|
|
|
@@ -151,9 +210,11 @@ async function installFromRelease() {
|
|
|
151
210
|
extract(archivePath, tmpDir);
|
|
152
211
|
|
|
153
212
|
const extracted = findExtractedBinary(tmpDir);
|
|
213
|
+
verifyBinaryFormat(extracted);
|
|
154
214
|
mkdirSync(BIN_DIR, { recursive: true });
|
|
155
215
|
copyFileSync(extracted, DEST);
|
|
156
216
|
chmodSync(DEST, 0o755);
|
|
217
|
+
verifyInstalledBinary(DEST);
|
|
157
218
|
rmSync(tmpDir, { recursive: true, force: true });
|
|
158
219
|
}
|
|
159
220
|
|
|
@@ -195,5 +256,7 @@ module.exports = {
|
|
|
195
256
|
platformKey,
|
|
196
257
|
releaseBaseUrl,
|
|
197
258
|
sha256,
|
|
259
|
+
verifyBinaryFormat,
|
|
198
260
|
verifyChecksum,
|
|
261
|
+
verifyInstalledBinary,
|
|
199
262
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ask-bridge",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Automate ChatGPT, Gemini or Claude from the command line through Chrome.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"ask-bridge": "npm/cli.cjs",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"postinstall": "node npm/postinstall.cjs",
|
|
11
|
-
"test": "node --test tests/postinstall.test.cjs",
|
|
11
|
+
"test": "node --test tests/postinstall.test.cjs tests/model-selection.test.cjs",
|
|
12
12
|
"prepublishOnly": "npm test && npm pack --dry-run && node npm/prepublish-check.cjs"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|