@voyager-crew/cli 0.1.0 → 0.2.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/README.md +44 -13
- package/README_ZH.md +32 -12
- package/dist/cli.mjs +527 -78
- package/package.json +2 -2
- package/skills/voyager/SKILL.md +6 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<img src="assets/logo.
|
|
3
|
-
<h1>
|
|
2
|
+
<img src="https://raw.githubusercontent.com/voyager-crew/voyager-cli/main/assets/logo.svg" alt="Voyager CLI logo" width="96" height="96">
|
|
3
|
+
<h1>Voyager CLI</h1>
|
|
4
4
|
<p>Ask ChatGPT from your terminal, or let your coding agent do it,<br>through the ChatGPT you are already signed in to in your browser.</p>
|
|
5
5
|
<p>
|
|
6
6
|
<a href="https://www.npmjs.com/package/@voyager-crew/cli"><img src="https://img.shields.io/npm/v/@voyager-crew/cli?style=flat-square" alt="npm version"></a>
|
|
@@ -13,28 +13,35 @@
|
|
|
13
13
|
voyager ask "Review this design" --attach ./docs/design.md
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
Voyager CLI is the reference client for the **ChatGPT Local Bridge** in the
|
|
17
|
+
[Voyager](https://github.com/voyager-crew/voyager) browser extension. The bridge lets programs on
|
|
18
|
+
your computer work with ChatGPT on the web: open a chat, send a prompt with files, wait for the
|
|
19
|
+
reply and read it, manage project files. Voyager CLI puts that in your terminal and saves each
|
|
20
|
+
reply as `response.md`. Everything stays on your machine: the CLI listens on `127.0.0.1` only,
|
|
21
|
+
and ChatGPT sees an ordinary chat from your own browser.
|
|
22
|
+
[More about the bridge →](https://voyager.nagi.fun/en/guide/local-bridge)
|
|
20
23
|
|
|
21
24
|
## Setup
|
|
22
25
|
|
|
23
|
-
1. Install
|
|
26
|
+
1. Install Voyager CLI (Node.js 20.3 or later):
|
|
24
27
|
|
|
25
28
|
```sh
|
|
26
29
|
npm install -g @voyager-crew/cli
|
|
27
30
|
```
|
|
28
31
|
|
|
29
|
-
2. Install Voyager
|
|
30
|
-
|
|
32
|
+
2. Install the Voyager extension, version 2.1.0 or later:
|
|
33
|
+
[Chrome](https://chromewebstore.google.com/detail/iifacdnjakkhjjiengaffnegbndgingi) ·
|
|
34
|
+
[Edge](https://microsoftedge.microsoft.com/addons/detail/voyager/gibmkggjijalcjinbdhcpklodjkhhlne) ·
|
|
35
|
+
[Firefox](https://addons.mozilla.org/firefox/addon/gemini-voyager/). In its popup, open
|
|
36
|
+
**Plugins**, turn on **ChatGPT · Local Bridge** and allow access to chatgpt.com.
|
|
31
37
|
3. Pair them once:
|
|
32
38
|
|
|
33
39
|
```sh
|
|
34
40
|
voyager pair
|
|
35
41
|
```
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
Open the Voyager popup on a ChatGPT tab and enter the eight-character code it prints in the
|
|
44
|
+
Local Bridge settings.
|
|
38
45
|
|
|
39
46
|
## Asking
|
|
40
47
|
|
|
@@ -76,7 +83,13 @@ voyager project remove "Thesis" old-notes.md # immediate and permanent; as
|
|
|
76
83
|
|
|
77
84
|
## Using it from an agent
|
|
78
85
|
|
|
79
|
-
Claude Code, Codex and any other agent that can run shell commands can use
|
|
86
|
+
Claude Code, Codex and any other agent that can run shell commands can use Voyager CLI. Install
|
|
87
|
+
the skill that teaches them how:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
npx skills add voyager-crew/voyager-cli
|
|
91
|
+
```
|
|
92
|
+
|
|
80
93
|
[`skills/voyager/SKILL.md`](skills/voyager/SKILL.md) is written for them: JSON output, what each
|
|
81
94
|
exit code means, how to wait for a long job without sending the prompt twice, and how to follow
|
|
82
95
|
up with `--chat` and the conversation id it got rather than `--continue`.
|
|
@@ -86,12 +99,30 @@ One job runs at a time. Every result also names your ChatGPT plan (`Pro Lite ($1
|
|
|
86
99
|
|
|
87
100
|
## Good to know
|
|
88
101
|
|
|
89
|
-
-
|
|
90
|
-
|
|
102
|
+
- `ask`, `read` and every `project` command open their own ChatGPT tab and close it when they
|
|
103
|
+
end, also after a failure; pass `--keep-tab` to leave it open. If ChatGPT asks you to sign in
|
|
104
|
+
or solve a challenge, Voyager CLI stops, leaves that tab open and says so (exit 3); it never
|
|
105
|
+
works around it.
|
|
106
|
+
- `voyager update` updates everything it can: the CLI (when npm installed it globally),
|
|
107
|
+
`voyager serve` (restarted unless a job is running) and the extension's page data, fetched now
|
|
108
|
+
instead of at its next check. Your browser's store updates the extension itself.
|
|
91
109
|
- Commands: `voyager --help`. State lives in `~/.voyager` (or `$VOYAGER_HOME`), private to
|
|
92
110
|
your user.
|
|
93
111
|
- Tested in Chrome. Edge and Firefox builds of Voyager include the bridge too; Safari does not.
|
|
94
112
|
|
|
113
|
+
## Disclaimer
|
|
114
|
+
|
|
115
|
+
- Voyager and Voyager CLI are community open-source projects. They are not affiliated with or
|
|
116
|
+
endorsed by OpenAI.
|
|
117
|
+
- The bridge automates ChatGPT on the web in your own signed-in browser. OpenAI's
|
|
118
|
+
[Terms of Use](https://openai.com/policies/terms-of-use/) restrict extracting output by automated or programmatic means, so decide
|
|
119
|
+
for yourself whether your use complies before you rely on it. Any limits placed on your account
|
|
120
|
+
as a result are your own risk.
|
|
121
|
+
- Similar tools take the same line: [oracle](https://github.com/steipete/oracle), for example, makes its browser mode an opt-in
|
|
122
|
+
experimental feature and points people who want to avoid the risk to the API. If you need a
|
|
123
|
+
supported route, use the OpenAI API.
|
|
124
|
+
- The bridge is for your own convenience on your own computer: connect only your own account, do not use it to serve other people, share an account or resell usage, and use it only for lawful purposes.
|
|
125
|
+
|
|
95
126
|
## License
|
|
96
127
|
|
|
97
128
|
MIT. Development notes are in [CONTRIBUTING.md](CONTRIBUTING.md).
|
package/README_ZH.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<img src="assets/logo.
|
|
3
|
-
<h1>
|
|
2
|
+
<img src="https://raw.githubusercontent.com/voyager-crew/voyager-cli/main/assets/logo.svg" alt="Voyager CLI logo" width="96" height="96">
|
|
3
|
+
<h1>Voyager CLI</h1>
|
|
4
4
|
<p>在终端里向 ChatGPT 提问,或者交给你的 coding agent 去问,<br>用的就是你浏览器里已经登录的那个 ChatGPT。</p>
|
|
5
5
|
<p>
|
|
6
6
|
<a href="https://www.npmjs.com/package/@voyager-crew/cli"><img src="https://img.shields.io/npm/v/@voyager-crew/cli?style=flat-square" alt="npm version"></a>
|
|
@@ -13,27 +13,31 @@
|
|
|
13
13
|
voyager ask "帮我审一下这份设计" --attach ./docs/design.md
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
ChatGPT
|
|
18
|
-
`127.0.0.1`,ChatGPT
|
|
16
|
+
Voyager CLI 是 [Voyager](https://github.com/voyager-crew/voyager) 浏览器插件里 **ChatGPT 本地桥**
|
|
17
|
+
的参考客户端。本地桥让本机程序可以跟 ChatGPT 网页版协作:打开对话、附文件发送、等回复写完再读取、管理项目文件。Voyager CLI
|
|
18
|
+
把这些带到终端里,每次的回答存成 `response.md`。全程都在你自己的电脑上:命令行只监听 `127.0.0.1`,ChatGPT
|
|
19
|
+
看到的就是你浏览器里一次普通的对话。[了解本地桥 →](https://voyager.nagi.fun/guide/local-bridge)
|
|
19
20
|
|
|
20
21
|
## 安装
|
|
21
22
|
|
|
22
|
-
1.
|
|
23
|
+
1. 安装 Voyager CLI(需要 Node.js 20.3 或更高版本):
|
|
23
24
|
|
|
24
25
|
```sh
|
|
25
26
|
npm install -g @voyager-crew/cli
|
|
26
27
|
```
|
|
27
28
|
|
|
28
|
-
2.
|
|
29
|
-
|
|
29
|
+
2. 安装 Voyager 插件,需要 2.1.0 或更高版本:
|
|
30
|
+
[Chrome](https://chromewebstore.google.com/detail/iifacdnjakkhjjiengaffnegbndgingi) ·
|
|
31
|
+
[Edge](https://microsoftedge.microsoft.com/addons/detail/voyager/gibmkggjijalcjinbdhcpklodjkhhlne) ·
|
|
32
|
+
[Firefox](https://addons.mozilla.org/firefox/addon/gemini-voyager/)。打开插件弹窗,进入
|
|
33
|
+
**插件**,打开 **ChatGPT · 本地桥**,并允许访问 chatgpt.com。
|
|
30
34
|
3. 配对一次:
|
|
31
35
|
|
|
32
36
|
```sh
|
|
33
37
|
voyager pair
|
|
34
38
|
```
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
在 ChatGPT 标签页上打开 Voyager 弹窗,把它显示的 8 位配对码填进「本地桥接」的设置。
|
|
37
41
|
|
|
38
42
|
## 提问
|
|
39
43
|
|
|
@@ -71,7 +75,12 @@ voyager project remove "论文" old-notes.md # 立即删除且无法恢
|
|
|
71
75
|
|
|
72
76
|
## 给 agent 用
|
|
73
77
|
|
|
74
|
-
Claude Code、Codex 以及任何能运行终端命令的 agent 都能用
|
|
78
|
+
Claude Code、Codex 以及任何能运行终端命令的 agent 都能用 Voyager CLI。先装上教它们怎么用的 skill:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
npx skills add voyager-crew/voyager-cli
|
|
82
|
+
```
|
|
83
|
+
|
|
75
84
|
[`skills/voyager/SKILL.md`](skills/voyager/SKILL.md) 就是写给它们看的:JSON 输出、每个退出码的含义、怎么等长任务而不把问题发两遍,以及接着问时用
|
|
76
85
|
`--chat` 加上次拿到的对话 id,而不是 `--continue`。
|
|
77
86
|
|
|
@@ -80,11 +89,22 @@ Claude Code、Codex 以及任何能运行终端命令的 agent 都能用 `voyage
|
|
|
80
89
|
|
|
81
90
|
## 须知
|
|
82
91
|
|
|
83
|
-
-
|
|
84
|
-
|
|
92
|
+
- `ask`、`read` 和所有 `project` 命令都会自己打开一个 ChatGPT 标签页,结束时关掉,失败了也关;
|
|
93
|
+
想留着就加 `--keep-tab`。如果 ChatGPT 要求登录或人机验证,Voyager CLI 会停下来、留着那个
|
|
94
|
+
标签页并告诉你(退出码 3),不会绕过。
|
|
95
|
+
- `voyager update` 把能更新的都更新一遍:命令行本身(用 npm 全局安装时)、`voyager serve`
|
|
96
|
+
(没有任务在跑时重启)和扩展的页面数据(立即重新获取,不等下一次定时检查)。扩展本身由浏览器的
|
|
97
|
+
扩展商店更新。
|
|
85
98
|
- 全部命令见 `voyager --help`。状态保存在 `~/.voyager`(或 `$VOYAGER_HOME`),只有你的用户能读。
|
|
86
99
|
- 已在 Chrome 中测试。Edge 和 Firefox 版的 Voyager 也带这个桥;Safari 版没有。
|
|
87
100
|
|
|
101
|
+
## 须知与免责
|
|
102
|
+
|
|
103
|
+
- Voyager 和 Voyager CLI 是社区开源项目,与 OpenAI 无关,也没有得到 OpenAI 的认可。
|
|
104
|
+
- 本地桥会在你自己登录的浏览器里自动操作 ChatGPT 网页版。OpenAI 的[使用条款](https://openai.com/policies/terms-of-use/)限制以自动或程序化的方式提取输出,使用前请自行判断是否符合条款;账号因此受到的任何限制,由你自己承担。
|
|
105
|
+
- 同类工具也是这样处理的:例如 [oracle](https://github.com/steipete/oracle) 把浏览器模式作为需要主动开启的实验功能,并建议在意风险的人改用 API。需要有保障的用法,请使用 OpenAI API。
|
|
106
|
+
- 本地桥是给你在自己电脑上、为自己方便而用的:只连你自己的账号,不要拿它对外提供服务、共享账号或转卖额度,也只用于合法用途。
|
|
107
|
+
|
|
88
108
|
## 许可证
|
|
89
109
|
|
|
90
110
|
MIT。开发说明见 [CONTRIBUTING.md](CONTRIBUTING.md)。
|
package/dist/cli.mjs
CHANGED
|
@@ -8,7 +8,7 @@ function definePlugin(plugin) {
|
|
|
8
8
|
return plugin;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
//
|
|
11
|
+
// node_modules/@voyager-crew/bridge-protocol/src/read.ts
|
|
12
12
|
var ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;
|
|
13
13
|
var SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
14
14
|
var MAX_STRING_LENGTH = 1e6;
|
|
@@ -139,7 +139,7 @@ function stringItem(rule = {}) {
|
|
|
139
139
|
return (raw, path, issues) => checkString(raw, path, issues, rule);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
//
|
|
142
|
+
// node_modules/@voyager-crew/bridge-protocol/src/account.ts
|
|
143
143
|
var ACCOUNT_PLAN_STRING_FIELDS = [
|
|
144
144
|
"planType",
|
|
145
145
|
"planDisplayName",
|
|
@@ -209,7 +209,7 @@ function accountTier(plan) {
|
|
|
209
209
|
return "unknown";
|
|
210
210
|
return named.every((tier) => tier === named[0]) ? named[0] : "unknown";
|
|
211
211
|
}
|
|
212
|
-
//
|
|
212
|
+
// node_modules/@voyager-crew/bridge-protocol/src/errors.ts
|
|
213
213
|
var ERROR_CATEGORIES = {
|
|
214
214
|
challenge: "user-action",
|
|
215
215
|
"login-required": "user-action",
|
|
@@ -264,7 +264,7 @@ function categoryOf(code) {
|
|
|
264
264
|
function bridgeError(code, message, details) {
|
|
265
265
|
return details === undefined ? { code, category: categoryOf(code), message } : { code, category: categoryOf(code), message, details };
|
|
266
266
|
}
|
|
267
|
-
//
|
|
267
|
+
// node_modules/@voyager-crew/bridge-protocol/src/http.ts
|
|
268
268
|
var DEFAULT_PORT = 47321;
|
|
269
269
|
var BRIDGE_HOST = "127.0.0.1";
|
|
270
270
|
var POLL_HOLD_MS = 25000;
|
|
@@ -312,7 +312,7 @@ function normalizePairingCode(input) {
|
|
|
312
312
|
}
|
|
313
313
|
var POLICY_STATES = ["allowed", "denied", "stale"];
|
|
314
314
|
var MAX_BLOB_CHUNK_BASE64 = Math.ceil(MAX_BLOB_CHUNK_BYTES / 3) * 4;
|
|
315
|
-
//
|
|
315
|
+
// node_modules/@voyager-crew/bridge-protocol/src/projectOps.ts
|
|
316
316
|
var PROJECT_OP_NAMES = [
|
|
317
317
|
"project.list",
|
|
318
318
|
"project.create",
|
|
@@ -334,7 +334,7 @@ var PROJECT_OP_VERSIONS = {
|
|
|
334
334
|
"project.remove": 1
|
|
335
335
|
};
|
|
336
336
|
|
|
337
|
-
//
|
|
337
|
+
// node_modules/@voyager-crew/bridge-protocol/src/ops.ts
|
|
338
338
|
var OP_NAMES = [
|
|
339
339
|
"conversation.open",
|
|
340
340
|
"conversation.close",
|
|
@@ -346,16 +346,22 @@ var OP_NAMES = [
|
|
|
346
346
|
"turns.waitReply",
|
|
347
347
|
"turns.read",
|
|
348
348
|
"files.download",
|
|
349
|
+
"catalog.refresh",
|
|
349
350
|
...PROJECT_OP_NAMES
|
|
350
351
|
];
|
|
351
352
|
function isOpName(value) {
|
|
352
353
|
return typeof value === "string" && OP_NAMES.includes(value);
|
|
353
354
|
}
|
|
355
|
+
var POLICY_EXEMPT_OPS = ["catalog.refresh"];
|
|
356
|
+
function isPolicyExemptOp(op) {
|
|
357
|
+
return POLICY_EXEMPT_OPS.includes(op);
|
|
358
|
+
}
|
|
354
359
|
var MAX_ATTACHMENTS = 10;
|
|
355
360
|
var MAX_ATTACHMENT_BYTES = 64 * 1024 * 1024;
|
|
356
361
|
var WAIT_REPLY_MAX_TIMEOUT_MS = 12 * 60 * 60000;
|
|
357
362
|
var WAIT_REPLY_DEFAULT_STALL_MS = 20 * 60000;
|
|
358
|
-
|
|
363
|
+
var CATALOG_HOST_PATTERN = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
364
|
+
// node_modules/@voyager-crew/bridge-protocol/src/version.ts
|
|
359
365
|
var PROTOCOL = { min: 1, max: 1 };
|
|
360
366
|
var PROTOCOL_HEADER = "X-Voyager-Protocol";
|
|
361
367
|
var OP_VERSIONS = {
|
|
@@ -369,6 +375,7 @@ var OP_VERSIONS = {
|
|
|
369
375
|
"turns.waitReply": 1,
|
|
370
376
|
"turns.read": 1,
|
|
371
377
|
"files.download": 1,
|
|
378
|
+
"catalog.refresh": 1,
|
|
372
379
|
...PROJECT_OP_VERSIONS
|
|
373
380
|
};
|
|
374
381
|
function negotiateProtocol(sides) {
|
|
@@ -385,7 +392,7 @@ function parseProtocolHeader(value) {
|
|
|
385
392
|
}
|
|
386
393
|
return Number(value.trim());
|
|
387
394
|
}
|
|
388
|
-
//
|
|
395
|
+
// node_modules/@voyager-crew/bridge-protocol/src/validate/projectOps.ts
|
|
389
396
|
var VIEWS = ["chat", "sources"];
|
|
390
397
|
var SWITCHABLE_MODES = ["chat", "work"];
|
|
391
398
|
var HTTPS_URL = { pattern: /^https:\/\//, maxLength: 4096 };
|
|
@@ -538,7 +545,7 @@ var PROJECT_RESULT_READERS = {
|
|
|
538
545
|
}
|
|
539
546
|
};
|
|
540
547
|
|
|
541
|
-
//
|
|
548
|
+
// node_modules/@voyager-crew/bridge-protocol/src/validate/ops.ts
|
|
542
549
|
var CHAT_MODES = ["chat", "work", "unknown"];
|
|
543
550
|
var SWITCHABLE_MODES2 = ["chat", "work"];
|
|
544
551
|
var HTTPS_URL2 = { pattern: /^https:\/\//, maxLength: 4096 };
|
|
@@ -546,6 +553,14 @@ var TURN_KEY = { maxLength: 256 };
|
|
|
546
553
|
var LABEL = { maxLength: 200, allowEmpty: true };
|
|
547
554
|
var FILE_NAME2 = { pattern: /^[^/\\\0]+$/, maxLength: 255 };
|
|
548
555
|
var MAX_FILE_CANDIDATES = 100;
|
|
556
|
+
var CATALOG_HOST = { pattern: CATALOG_HOST_PATTERN, maxLength: 253 };
|
|
557
|
+
var CATALOG_STATUSES = [
|
|
558
|
+
"updated",
|
|
559
|
+
"unchanged",
|
|
560
|
+
"missing",
|
|
561
|
+
"failed",
|
|
562
|
+
"disabled"
|
|
563
|
+
];
|
|
549
564
|
function readConversationId(rec, path, issues) {
|
|
550
565
|
return requireString(rec, "conversationId", path, issues, { pattern: ID_PATTERN });
|
|
551
566
|
}
|
|
@@ -735,6 +750,11 @@ var PARAM_READERS = {
|
|
|
735
750
|
assistantTurnKey: requireString(rec, "assistantTurnKey", path, issues, TURN_KEY),
|
|
736
751
|
candidate: readFileCandidate(rec.candidate, at(path, "candidate"), issues)
|
|
737
752
|
};
|
|
753
|
+
},
|
|
754
|
+
"catalog.refresh": (raw, path, issues) => {
|
|
755
|
+
const rec = readObject(raw, path, issues);
|
|
756
|
+
const host = optionalString(rec, "host", path, issues, CATALOG_HOST);
|
|
757
|
+
return host === undefined ? {} : { host };
|
|
738
758
|
}
|
|
739
759
|
};
|
|
740
760
|
var readDownloaded = (raw, path, issues) => {
|
|
@@ -833,7 +853,20 @@ var RESULT_READERS = {
|
|
|
833
853
|
})
|
|
834
854
|
};
|
|
835
855
|
},
|
|
836
|
-
"files.download": readDownloaded
|
|
856
|
+
"files.download": readDownloaded,
|
|
857
|
+
"catalog.refresh": (raw, path, issues) => {
|
|
858
|
+
const rec = readObject(raw, path, issues);
|
|
859
|
+
const checkedAt = optionalInt(rec, "checkedAt", path, issues);
|
|
860
|
+
const reason = optionalString(rec, "reason", path, issues, { maxLength: 1000 });
|
|
861
|
+
return {
|
|
862
|
+
host: requireString(rec, "host", path, issues, CATALOG_HOST),
|
|
863
|
+
status: requireLiteral(rec, "status", path, issues, CATALOG_STATUSES),
|
|
864
|
+
revision: nullableInt(rec, "revision", path, issues),
|
|
865
|
+
...checkedAt === undefined ? {} : { checkedAt },
|
|
866
|
+
...reason === undefined ? {} : { reason },
|
|
867
|
+
extensionVersion: requireString(rec, "extensionVersion", path, issues, { maxLength: 64 })
|
|
868
|
+
};
|
|
869
|
+
}
|
|
837
870
|
};
|
|
838
871
|
function opParamsReader(op) {
|
|
839
872
|
return PARAM_READERS[op];
|
|
@@ -845,7 +878,7 @@ function validateOpResult(op, raw) {
|
|
|
845
878
|
return validateWith(RESULT_READERS[op], raw);
|
|
846
879
|
}
|
|
847
880
|
|
|
848
|
-
//
|
|
881
|
+
// node_modules/@voyager-crew/bridge-protocol/src/validate/http.ts
|
|
849
882
|
var VERSION = { maxLength: 64 };
|
|
850
883
|
var ID = { pattern: ID_PATTERN };
|
|
851
884
|
var MAX_PROTOCOL_VERSION = 1e4;
|
|
@@ -953,9 +986,10 @@ var READERS = {
|
|
|
953
986
|
const caps = readObject(rec.capabilities, capsPath, issues);
|
|
954
987
|
const policyPath = at(path, "policy");
|
|
955
988
|
const policy = readObject(rec.policy, policyPath, issues);
|
|
989
|
+
const offered = Array.isArray(caps.ops) ? caps.ops.filter((op) => !isRecord(op) || typeof op.name !== "string" || isOpName(op.name)) : caps.ops;
|
|
956
990
|
return {
|
|
957
991
|
capabilities: {
|
|
958
|
-
ops: requireArray(
|
|
992
|
+
ops: requireArray({ ops: offered }, "ops", capsPath, issues, readOpCapability, {
|
|
959
993
|
max: OP_NAMES.length
|
|
960
994
|
})
|
|
961
995
|
},
|
|
@@ -1059,11 +1093,6 @@ var READERS = {
|
|
|
1059
1093
|
function validateMessage(kind, raw) {
|
|
1060
1094
|
return validateWith(READERS[kind], raw);
|
|
1061
1095
|
}
|
|
1062
|
-
// src/util/attach/stage.ts
|
|
1063
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
1064
|
-
import { copyFile, constants as constants2, readFile as readFile4, realpath, stat } from "node:fs/promises";
|
|
1065
|
-
import { basename, join as join3, resolve } from "node:path";
|
|
1066
|
-
|
|
1067
1096
|
// src/util/isRecord.ts
|
|
1068
1097
|
function isRecord2(value) {
|
|
1069
1098
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -1094,6 +1123,46 @@ function toBridgeError(thrown) {
|
|
|
1094
1123
|
return bridgeError("bad-request", `internal error: ${message}`);
|
|
1095
1124
|
}
|
|
1096
1125
|
|
|
1126
|
+
// src/plugins/sendGuard.ts
|
|
1127
|
+
var SENDING_CHECKPOINT = "sending";
|
|
1128
|
+
var BEFORE_CLICK = new Set([
|
|
1129
|
+
"composer-busy",
|
|
1130
|
+
"selector-missing",
|
|
1131
|
+
"attachment-rejected",
|
|
1132
|
+
"mode-unavailable",
|
|
1133
|
+
"mode-unknown"
|
|
1134
|
+
]);
|
|
1135
|
+
function failedBeforeClick(error) {
|
|
1136
|
+
if (BEFORE_CLICK.has(error.code))
|
|
1137
|
+
return true;
|
|
1138
|
+
if (error.code !== "unverified")
|
|
1139
|
+
return false;
|
|
1140
|
+
const { stage, reason } = error.details ?? {};
|
|
1141
|
+
return stage === "fill" || reason === "conversation-mismatch";
|
|
1142
|
+
}
|
|
1143
|
+
function sendUnverified(message, details) {
|
|
1144
|
+
return bridgeError("send-unverified", message, { ...details, sent: "unknown" });
|
|
1145
|
+
}
|
|
1146
|
+
function sendInterrupted(checkpoints) {
|
|
1147
|
+
return checkpoints[SENDING_CHECKPOINT] !== undefined && checkpoints.sent === undefined;
|
|
1148
|
+
}
|
|
1149
|
+
async function sendOnce(ctx, params) {
|
|
1150
|
+
await ctx.checkpoint(SENDING_CHECKPOINT, { at: Date.now() });
|
|
1151
|
+
try {
|
|
1152
|
+
return await ctx.ops.call("composer.send", params);
|
|
1153
|
+
} catch (thrown) {
|
|
1154
|
+
const error = toBridgeError(thrown);
|
|
1155
|
+
if (error.code === "send-unverified" || failedBeforeClick(error))
|
|
1156
|
+
throw thrown;
|
|
1157
|
+
throw new BridgeFailure(sendUnverified(`composer.send ended with ${error.code} after it was dispatched (${error.message}); the prompt may have been sent`, { ...error.details, cause: error.code }));
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// src/util/attach/stage.ts
|
|
1162
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1163
|
+
import { copyFile, constants as constants2, readFile as readFile4, realpath, stat } from "node:fs/promises";
|
|
1164
|
+
import { basename, join as join3, resolve } from "node:path";
|
|
1165
|
+
|
|
1097
1166
|
// src/util/mime.ts
|
|
1098
1167
|
var TYPES = {
|
|
1099
1168
|
zip: "application/zip",
|
|
@@ -1977,6 +2046,44 @@ async function closeBridgeTab(ctx, tabId) {
|
|
|
1977
2046
|
ctx.log.warn("could not close the bridge tab", { error: String(error) });
|
|
1978
2047
|
}
|
|
1979
2048
|
}
|
|
2049
|
+
var KEEPS_TAB = new Set([
|
|
2050
|
+
"tab-closed",
|
|
2051
|
+
"document-lost",
|
|
2052
|
+
"extension-offline",
|
|
2053
|
+
"server-unreachable",
|
|
2054
|
+
"send-unverified",
|
|
2055
|
+
"login-required",
|
|
2056
|
+
"challenge",
|
|
2057
|
+
"account-blocked",
|
|
2058
|
+
"rate-limited"
|
|
2059
|
+
]);
|
|
2060
|
+
async function inBridgeTab(ctx, tabId, keepTab, body) {
|
|
2061
|
+
let result;
|
|
2062
|
+
try {
|
|
2063
|
+
result = await body();
|
|
2064
|
+
} catch (thrown) {
|
|
2065
|
+
if (closesAfter(ctx, thrown, keepTab))
|
|
2066
|
+
await closeBridgeTab(ctx, tabId);
|
|
2067
|
+
throw thrown;
|
|
2068
|
+
}
|
|
2069
|
+
if (!keepTab)
|
|
2070
|
+
await closeBridgeTab(ctx, tabId);
|
|
2071
|
+
return result;
|
|
2072
|
+
}
|
|
2073
|
+
function closesAfter(ctx, thrown, keepTab) {
|
|
2074
|
+
return !keepTab && !ctx.signal.aborted && !KEEPS_TAB.has(toBridgeError(thrown).code);
|
|
2075
|
+
}
|
|
2076
|
+
async function openBridgeTab(ctx, params, keepTab) {
|
|
2077
|
+
try {
|
|
2078
|
+
return await ctx.ops.call("conversation.open", params);
|
|
2079
|
+
} catch (thrown) {
|
|
2080
|
+
const tabId = toBridgeError(thrown).details?.tabId;
|
|
2081
|
+
const opened = typeof tabId === "number" && Number.isInteger(tabId) && tabId > 0;
|
|
2082
|
+
if (opened && closesAfter(ctx, thrown, keepTab))
|
|
2083
|
+
await closeBridgeTab(ctx, tabId);
|
|
2084
|
+
throw thrown;
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
1980
2087
|
function presentResponse(job) {
|
|
1981
2088
|
const response = job.result?.response;
|
|
1982
2089
|
const markdown = typeof response?.markdown === "string" ? response.markdown : "";
|
|
@@ -2088,25 +2195,27 @@ async function run2(ctx, input) {
|
|
|
2088
2195
|
const attachments = input.attachments ?? [];
|
|
2089
2196
|
const blobs = await registerAll(ctx, attachments);
|
|
2090
2197
|
const existing = input.conversationId;
|
|
2091
|
-
const opened = await ctx
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2198
|
+
const opened = await openBridgeTab(ctx, existing === undefined ? { new: true } : { conversationId: existing }, input.keepTab);
|
|
2199
|
+
return inBridgeTab(ctx, opened.tabId, input.keepTab, async () => {
|
|
2200
|
+
if (!opened.ready.loggedIn)
|
|
2201
|
+
throw failure("login-required", "ChatGPT is not logged in");
|
|
2202
|
+
if (opened.ready.mode !== "chat") {
|
|
2203
|
+
const work = opened.ready.mode === "work";
|
|
2204
|
+
if (!work) {
|
|
2205
|
+
const { lang, composerLabels } = opened.ready.evidence;
|
|
2206
|
+
throw failure("mode-unknown", `could not confirm ChatGPT is in chat mode (page language ${JSON.stringify(lang ?? "")}, composer labels ${JSON.stringify(composerLabels ?? [])}); the mode labels have only been measured on the Chinese (zh-CN) ChatGPT interface so far`, { lang, composerLabels });
|
|
2207
|
+
}
|
|
2208
|
+
throw failure("mode-unavailable", existing !== undefined ? `conversation ${existing} is a ChatGPT Work conversation; voyager asks only in chat-mode conversations` : `ChatGPT is not in chat mode (${opened.ready.mode})`);
|
|
2099
2209
|
}
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
await ctx
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
return askInTab(ctx, input, { startedAt, blobs, attachments, existing, opened, model });
|
|
2210
|
+
await ctx.checkpoint("opened", { tabId: opened.tabId, url: opened.url });
|
|
2211
|
+
if (input.project !== undefined) {
|
|
2212
|
+
const { projectId } = await resolveProject(ctx, input.project);
|
|
2213
|
+
const shown = await callProjectOp(ctx, "project.open", { projectId, view: "chat" });
|
|
2214
|
+
await ctx.checkpoint("project", { projectId, url: shown.url });
|
|
2215
|
+
}
|
|
2216
|
+
const model = await chooseModel(ctx, input.model ?? DEFAULT_ASK_MODEL);
|
|
2217
|
+
return askInTab(ctx, input, { startedAt, blobs, attachments, existing, opened, model });
|
|
2218
|
+
});
|
|
2110
2219
|
}
|
|
2111
2220
|
async function askInTab(ctx, input, {
|
|
2112
2221
|
startedAt,
|
|
@@ -2128,7 +2237,7 @@ async function askInTab(ctx, input, {
|
|
|
2128
2237
|
const text = preamble === "" ? input.prompt : `${input.prompt}
|
|
2129
2238
|
|
|
2130
2239
|
${preamble}`;
|
|
2131
|
-
const sent = await ctx
|
|
2240
|
+
const sent = await sendOnce(ctx, {
|
|
2132
2241
|
text,
|
|
2133
2242
|
...blobs.length > 0 ? { expectAttachments: blobs.map((blob) => blob.name) } : {},
|
|
2134
2243
|
...existing === undefined ? {} : { expect: { conversationId: existing } }
|
|
@@ -2158,8 +2267,6 @@ ${preamble}`;
|
|
|
2158
2267
|
const saved = await saveResponse(ctx, read);
|
|
2159
2268
|
const { responsePath } = saved;
|
|
2160
2269
|
await ctx.checkpoint("read", { assistantTurnKey: reply.assistantTurnKey, responsePath });
|
|
2161
|
-
if (!input.keepTab)
|
|
2162
|
-
await closeBridgeTab(ctx, opened.tabId);
|
|
2163
2270
|
return {
|
|
2164
2271
|
data: {
|
|
2165
2272
|
conversationUrl: sent.url,
|
|
@@ -2425,14 +2532,14 @@ async function act(ctx, input) {
|
|
|
2425
2532
|
return { project: named, outcome: "removed", name: removed.removed, files: removed.files };
|
|
2426
2533
|
}
|
|
2427
2534
|
async function run3(ctx, input) {
|
|
2428
|
-
const opened = await ctx
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2535
|
+
const opened = await openBridgeTab(ctx, { new: true }, input.keepTab);
|
|
2536
|
+
return inBridgeTab(ctx, opened.tabId, input.keepTab, async () => {
|
|
2537
|
+
if (!opened.ready.loggedIn)
|
|
2538
|
+
throw failure("login-required", "ChatGPT is not logged in");
|
|
2539
|
+
await ctx.checkpoint("opened", { tabId: opened.tabId, url: opened.url });
|
|
2540
|
+
const data = await act(ctx, input);
|
|
2541
|
+
return { data: { action: input.action, ...data } };
|
|
2542
|
+
});
|
|
2436
2543
|
}
|
|
2437
2544
|
function fileLines(files) {
|
|
2438
2545
|
if (!Array.isArray(files))
|
|
@@ -2516,29 +2623,29 @@ async function prepare3(_fg, argv) {
|
|
|
2516
2623
|
}
|
|
2517
2624
|
async function run4(ctx, input) {
|
|
2518
2625
|
const startedAt = Date.now();
|
|
2519
|
-
const opened = await ctx
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
latest: true
|
|
2526
|
-
});
|
|
2527
|
-
const saved = await saveResponse(ctx, read);
|
|
2528
|
-
await ctx.checkpoint("read", { turnKey: read.turnKey, responsePath: saved.responsePath });
|
|
2529
|
-
if (!input.keepTab)
|
|
2530
|
-
await closeBridgeTab(ctx, opened.tabId);
|
|
2531
|
-
return {
|
|
2532
|
-
data: {
|
|
2533
|
-
conversationUrl: opened.url,
|
|
2626
|
+
const opened = await openBridgeTab(ctx, { conversationId: input.conversationId }, input.keepTab);
|
|
2627
|
+
return inBridgeTab(ctx, opened.tabId, input.keepTab, async () => {
|
|
2628
|
+
if (!opened.ready.loggedIn)
|
|
2629
|
+
throw failure("login-required", "ChatGPT is not logged in");
|
|
2630
|
+
await ctx.checkpoint("opened", { tabId: opened.tabId, url: opened.url });
|
|
2631
|
+
const read = await ctx.ops.call("turns.read", {
|
|
2534
2632
|
conversationId: input.conversationId,
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2633
|
+
latest: true
|
|
2634
|
+
});
|
|
2635
|
+
const saved = await saveResponse(ctx, read);
|
|
2636
|
+
await ctx.checkpoint("read", { turnKey: read.turnKey, responsePath: saved.responsePath });
|
|
2637
|
+
return {
|
|
2638
|
+
data: {
|
|
2639
|
+
conversationUrl: opened.url,
|
|
2640
|
+
conversationId: input.conversationId,
|
|
2641
|
+
responsePath: saved.responsePath,
|
|
2642
|
+
turnKey: read.turnKey,
|
|
2643
|
+
files: [],
|
|
2644
|
+
timings: { startedAt, finishedAt: Date.now() },
|
|
2645
|
+
response: responseBlock(read, saved)
|
|
2646
|
+
}
|
|
2647
|
+
};
|
|
2648
|
+
});
|
|
2542
2649
|
}
|
|
2543
2650
|
var readPlugin = definePlugin({
|
|
2544
2651
|
name: "read",
|
|
@@ -2565,7 +2672,7 @@ function opCommand(op) {
|
|
|
2565
2672
|
summary: `run ${op} once`,
|
|
2566
2673
|
prepare: () => Promise.reject(failure("bad-request", "use voyager call")),
|
|
2567
2674
|
run: async (ctx, params) => {
|
|
2568
|
-
const result = await ctx.ops.call(op, params);
|
|
2675
|
+
const result = op === "composer.send" ? await sendOnce(ctx, params) : await ctx.ops.call(op, params);
|
|
2569
2676
|
return { data: { op, result } };
|
|
2570
2677
|
}
|
|
2571
2678
|
};
|
|
@@ -2646,7 +2753,7 @@ async function ensureHome(paths) {
|
|
|
2646
2753
|
// package.json
|
|
2647
2754
|
var package_default = {
|
|
2648
2755
|
name: "@voyager-crew/cli",
|
|
2649
|
-
version: "0.
|
|
2756
|
+
version: "0.2.0",
|
|
2650
2757
|
description: "Ask ChatGPT from your terminal or your coding agent, through the Voyager browser extension",
|
|
2651
2758
|
keywords: [
|
|
2652
2759
|
"chatgpt",
|
|
@@ -2692,7 +2799,7 @@ var package_default = {
|
|
|
2692
2799
|
},
|
|
2693
2800
|
devDependencies: {
|
|
2694
2801
|
"@types/node": "^24.9.0",
|
|
2695
|
-
"@voyager-crew/bridge-protocol": "^0.
|
|
2802
|
+
"@voyager-crew/bridge-protocol": "^0.3.0",
|
|
2696
2803
|
fflate: "0.8.2",
|
|
2697
2804
|
oxfmt: "^0.65.0",
|
|
2698
2805
|
oxlint: "^1.80.0",
|
|
@@ -3576,7 +3683,9 @@ class BlobStore {
|
|
|
3576
3683
|
}
|
|
3577
3684
|
|
|
3578
3685
|
// src/server/extensionState.ts
|
|
3579
|
-
function policyFailure(state) {
|
|
3686
|
+
function policyFailure(state, op) {
|
|
3687
|
+
if (op !== undefined && isPolicyExemptOp(op))
|
|
3688
|
+
return;
|
|
3580
3689
|
if (state === "denied") {
|
|
3581
3690
|
return failure("policy-denied", "the extension policy does not allow the bridge");
|
|
3582
3691
|
}
|
|
@@ -3635,6 +3744,13 @@ class JobStore {
|
|
|
3635
3744
|
if (job === undefined || isTerminal(job.status))
|
|
3636
3745
|
continue;
|
|
3637
3746
|
await this.loadEvents(jobId);
|
|
3747
|
+
if (sendInterrupted(job.checkpoints)) {
|
|
3748
|
+
const error = sendUnverified("serve stopped before the send was confirmed; the prompt may have been sent", { reason: "serve restarted" });
|
|
3749
|
+
this.update(job, { status: "failed", error });
|
|
3750
|
+
this.appendEvent(jobId, "status", { status: "failed", reason: "serve restarted" });
|
|
3751
|
+
this.appendEvent(jobId, "done", { status: "failed", error });
|
|
3752
|
+
continue;
|
|
3753
|
+
}
|
|
3638
3754
|
const status = job.status === "cancelling" ? "cancelled" : "detached";
|
|
3639
3755
|
this.update(job, { status });
|
|
3640
3756
|
this.appendEvent(jobId, "status", { status, reason: "serve restarted" });
|
|
@@ -3836,7 +3952,8 @@ var DEFAULT_OP_TIMEOUT_MS = {
|
|
|
3836
3952
|
"project.open": 60000,
|
|
3837
3953
|
"project.files": 30000,
|
|
3838
3954
|
"project.upload": 120000,
|
|
3839
|
-
"project.remove": 30000
|
|
3955
|
+
"project.remove": 30000,
|
|
3956
|
+
"catalog.refresh": 30000
|
|
3840
3957
|
};
|
|
3841
3958
|
var WAIT_REPLY_MARGIN_MS = 30000;
|
|
3842
3959
|
function defaultOpTimeout(op, params) {
|
|
@@ -3851,7 +3968,7 @@ function createOpsClient(hooks) {
|
|
|
3851
3968
|
async call(op, params, options = {}) {
|
|
3852
3969
|
if (hooks.signal.aborted)
|
|
3853
3970
|
throw failure("cancelled", "job was cancelled");
|
|
3854
|
-
const refused = policyFailure(hooks.policy());
|
|
3971
|
+
const refused = policyFailure(hooks.policy(), op);
|
|
3855
3972
|
if (refused !== undefined)
|
|
3856
3973
|
throw refused;
|
|
3857
3974
|
const available = hooks.available();
|
|
@@ -3902,12 +4019,13 @@ class JobRunner {
|
|
|
3902
4019
|
if (!this.deps.isPaired()) {
|
|
3903
4020
|
throw failure("not-paired", "no extension is paired; run `voyager pair`");
|
|
3904
4021
|
}
|
|
3905
|
-
const
|
|
4022
|
+
const op = plugin === CALL_PLUGIN && isOpName(command) ? command : undefined;
|
|
4023
|
+
const refused = policyFailure(this.deps.extension.policy?.state, op);
|
|
3906
4024
|
if (refused !== undefined)
|
|
3907
4025
|
throw refused;
|
|
3908
4026
|
const available = this.deps.extension.opNames();
|
|
3909
4027
|
const required = this.deps.registry.plugin(plugin)?.requiresOps ?? [];
|
|
3910
|
-
const missing = available === null ? [] : required.filter((
|
|
4028
|
+
const missing = available === null ? [] : required.filter((op2) => !available.has(op2));
|
|
3911
4029
|
if (missing.length > 0) {
|
|
3912
4030
|
throw failure("unsupported-op", `the extension does not offer ${missing.join(", ")}; update the Voyager extension`, { missing });
|
|
3913
4031
|
}
|
|
@@ -3952,7 +4070,10 @@ class JobRunner {
|
|
|
3952
4070
|
status = "succeeded";
|
|
3953
4071
|
result = output.data;
|
|
3954
4072
|
} catch (thrown) {
|
|
3955
|
-
error =
|
|
4073
|
+
error = toBridgeError(thrown);
|
|
4074
|
+
if (controller.signal.aborted && error.code !== "send-unverified") {
|
|
4075
|
+
error = toBridgeError(failure("cancelled", "job was cancelled"));
|
|
4076
|
+
}
|
|
3956
4077
|
status = statusForError(error, job.checkpoints);
|
|
3957
4078
|
}
|
|
3958
4079
|
await this.deps.slot.idle();
|
|
@@ -4177,7 +4298,7 @@ class TaskSlot {
|
|
|
4177
4298
|
return;
|
|
4178
4299
|
}
|
|
4179
4300
|
if (entry.state === "queued") {
|
|
4180
|
-
const refused = policyFailure(view.policy);
|
|
4301
|
+
const refused = policyFailure(view.policy, entry.task.op);
|
|
4181
4302
|
if (refused !== undefined) {
|
|
4182
4303
|
this.settle(entry, refused);
|
|
4183
4304
|
this.release(entry);
|
|
@@ -5315,6 +5436,326 @@ async function readLockPid2(paths) {
|
|
|
5315
5436
|
}
|
|
5316
5437
|
}
|
|
5317
5438
|
|
|
5439
|
+
// src/cli/commands/update.ts
|
|
5440
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
5441
|
+
import { realpath as realpath3 } from "node:fs/promises";
|
|
5442
|
+
import { join as join10, sep as sep2 } from "node:path";
|
|
5443
|
+
var CLI_PACKAGE = "@voyager-crew/cli";
|
|
5444
|
+
var INSTALL_COMMAND = `npm i -g ${CLI_PACKAGE}@latest`;
|
|
5445
|
+
var DEFAULT_REGISTRY = "https://registry.npmjs.org/";
|
|
5446
|
+
var PAGE_DATA_WAIT_MS = 2 * 60000;
|
|
5447
|
+
function defaultUpdateDeps(paths) {
|
|
5448
|
+
return {
|
|
5449
|
+
currentVersion: CLI_VERSION,
|
|
5450
|
+
fetch: (...args) => fetch(...args),
|
|
5451
|
+
env: process.env,
|
|
5452
|
+
scriptPath: process.argv[1],
|
|
5453
|
+
run: runCommand,
|
|
5454
|
+
connect: () => connectServe(paths),
|
|
5455
|
+
ensure: () => ensureServe(paths),
|
|
5456
|
+
restartServe: async () => {
|
|
5457
|
+
if (await stopServe(paths) !== 0)
|
|
5458
|
+
throw new Error("the running voyager serve did not stop");
|
|
5459
|
+
await ensureServe(paths);
|
|
5460
|
+
},
|
|
5461
|
+
pageDataWaitMs: PAGE_DATA_WAIT_MS
|
|
5462
|
+
};
|
|
5463
|
+
}
|
|
5464
|
+
function runCommand(command, args, options) {
|
|
5465
|
+
return new Promise((resolve2, reject) => {
|
|
5466
|
+
const child = spawn3(command, [...args], {
|
|
5467
|
+
stdio: options.capture ? ["ignore", "pipe", "ignore"] : ["ignore", 2, 2],
|
|
5468
|
+
shell: process.platform === "win32"
|
|
5469
|
+
});
|
|
5470
|
+
let stdout = "";
|
|
5471
|
+
child.stdout?.on("data", (chunk) => {
|
|
5472
|
+
stdout += chunk.toString();
|
|
5473
|
+
});
|
|
5474
|
+
child.once("error", reject);
|
|
5475
|
+
child.once("close", (code) => resolve2({ code: code ?? 1, stdout }));
|
|
5476
|
+
});
|
|
5477
|
+
}
|
|
5478
|
+
function compareVersions(a, b) {
|
|
5479
|
+
const split = (version2) => {
|
|
5480
|
+
const [core = "", pre] = version2.trim().replace(/^v/, "").split("+")[0].split("-", 2);
|
|
5481
|
+
return { parts: core.split(".").map((part) => Number.parseInt(part, 10) || 0), pre };
|
|
5482
|
+
};
|
|
5483
|
+
const left = split(a);
|
|
5484
|
+
const right = split(b);
|
|
5485
|
+
for (let i2 = 0;i2 < 3; i2 += 1) {
|
|
5486
|
+
const diff = (left.parts[i2] ?? 0) - (right.parts[i2] ?? 0);
|
|
5487
|
+
if (diff !== 0)
|
|
5488
|
+
return Math.sign(diff);
|
|
5489
|
+
}
|
|
5490
|
+
if (left.pre === right.pre)
|
|
5491
|
+
return 0;
|
|
5492
|
+
if (left.pre === undefined)
|
|
5493
|
+
return 1;
|
|
5494
|
+
if (right.pre === undefined)
|
|
5495
|
+
return -1;
|
|
5496
|
+
return left.pre < right.pre ? -1 : 1;
|
|
5497
|
+
}
|
|
5498
|
+
var resolved = (path) => realpath3(path).catch(() => path);
|
|
5499
|
+
async function detectInstall(deps) {
|
|
5500
|
+
if (deps.scriptPath === undefined)
|
|
5501
|
+
return { kind: "local", path: "?" };
|
|
5502
|
+
const script = await resolved(deps.scriptPath);
|
|
5503
|
+
if (script.split(sep2).includes("_npx") || deps.env.npm_command === "exec")
|
|
5504
|
+
return { kind: "npx" };
|
|
5505
|
+
try {
|
|
5506
|
+
const root = await deps.run("npm", ["root", "-g"], { capture: true });
|
|
5507
|
+
const globalRoot = root.stdout.trim();
|
|
5508
|
+
if (root.code === 0 && globalRoot !== "") {
|
|
5509
|
+
const installed = await resolved(join10(globalRoot, ...CLI_PACKAGE.split("/")));
|
|
5510
|
+
if (script.startsWith(`${installed}${sep2}`))
|
|
5511
|
+
return { kind: "global" };
|
|
5512
|
+
}
|
|
5513
|
+
} catch {}
|
|
5514
|
+
return { kind: "local", path: script };
|
|
5515
|
+
}
|
|
5516
|
+
async function latestVersion(deps) {
|
|
5517
|
+
const registry = deps.env.npm_config_registry ?? DEFAULT_REGISTRY;
|
|
5518
|
+
const url = `${registry.replace(/\/?$/, "/")}${CLI_PACKAGE.replace("/", "%2F")}/latest`;
|
|
5519
|
+
const response = await deps.fetch(url, { signal: AbortSignal.timeout(1e4) });
|
|
5520
|
+
if (!response.ok)
|
|
5521
|
+
throw new Error(`the registry answered HTTP ${response.status}`);
|
|
5522
|
+
const body = await response.json();
|
|
5523
|
+
if (!isRecord2(body) || typeof body.version !== "string") {
|
|
5524
|
+
throw new Error("the registry answered without a version");
|
|
5525
|
+
}
|
|
5526
|
+
return body.version;
|
|
5527
|
+
}
|
|
5528
|
+
async function updateCli(deps) {
|
|
5529
|
+
const current = deps.currentVersion;
|
|
5530
|
+
let latest;
|
|
5531
|
+
try {
|
|
5532
|
+
latest = await latestVersion(deps);
|
|
5533
|
+
} catch (error) {
|
|
5534
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
5535
|
+
note(`could not reach the npm registry (${reason}); the CLI was not checked`);
|
|
5536
|
+
return {
|
|
5537
|
+
line: `CLI ${current} (not checked: offline?)`,
|
|
5538
|
+
code: EXIT.transient,
|
|
5539
|
+
json: { version: current, latest: null, error: reason }
|
|
5540
|
+
};
|
|
5541
|
+
}
|
|
5542
|
+
const install = await detectInstall(deps);
|
|
5543
|
+
const newer = compareVersions(latest, current) > 0;
|
|
5544
|
+
const json = { version: current, latest, install: install.kind };
|
|
5545
|
+
if (install.kind === "npx") {
|
|
5546
|
+
if (newer)
|
|
5547
|
+
note(`npx ran ${current}: use npx ${CLI_PACKAGE}@latest, or install it: ${INSTALL_COMMAND}`);
|
|
5548
|
+
return {
|
|
5549
|
+
line: newer ? `CLI ${current} (${latest} via npx ${CLI_PACKAGE}@latest)` : `CLI ${current} ✓`,
|
|
5550
|
+
code: EXIT.ok,
|
|
5551
|
+
json: { ...json, updated: false },
|
|
5552
|
+
serveTarget: current
|
|
5553
|
+
};
|
|
5554
|
+
}
|
|
5555
|
+
if (install.kind === "local") {
|
|
5556
|
+
if (newer)
|
|
5557
|
+
note(`this CLI runs from ${install.path}; to install ${latest}: ${INSTALL_COMMAND}`);
|
|
5558
|
+
return {
|
|
5559
|
+
line: newer ? `CLI ${current} (${latest} out: ${INSTALL_COMMAND})` : `CLI ${current} ✓`,
|
|
5560
|
+
code: EXIT.ok,
|
|
5561
|
+
json: { ...json, updated: false },
|
|
5562
|
+
serveTarget: current
|
|
5563
|
+
};
|
|
5564
|
+
}
|
|
5565
|
+
if (!newer) {
|
|
5566
|
+
return {
|
|
5567
|
+
line: `CLI ${current} ✓`,
|
|
5568
|
+
code: EXIT.ok,
|
|
5569
|
+
json: { ...json, updated: false },
|
|
5570
|
+
serveTarget: current
|
|
5571
|
+
};
|
|
5572
|
+
}
|
|
5573
|
+
note(`CLI ${current} → ${latest}: ${INSTALL_COMMAND}`);
|
|
5574
|
+
let installed;
|
|
5575
|
+
try {
|
|
5576
|
+
installed = await deps.run("npm", ["i", "-g", `${CLI_PACKAGE}@latest`], { capture: false });
|
|
5577
|
+
} catch (error) {
|
|
5578
|
+
note(`could not run npm: ${String(error)}`);
|
|
5579
|
+
installed = { code: 1, stdout: "" };
|
|
5580
|
+
}
|
|
5581
|
+
if (installed.code !== 0) {
|
|
5582
|
+
note(`npm exited ${installed.code}; run it yourself: ${INSTALL_COMMAND}`);
|
|
5583
|
+
return {
|
|
5584
|
+
line: `CLI ${current} (update failed)`,
|
|
5585
|
+
code: EXIT.failed,
|
|
5586
|
+
json: { ...json, updated: false },
|
|
5587
|
+
serveTarget: current
|
|
5588
|
+
};
|
|
5589
|
+
}
|
|
5590
|
+
return {
|
|
5591
|
+
line: `CLI ${current} → ${latest}`,
|
|
5592
|
+
code: EXIT.ok,
|
|
5593
|
+
json: { ...json, updated: true },
|
|
5594
|
+
serveTarget: latest
|
|
5595
|
+
};
|
|
5596
|
+
}
|
|
5597
|
+
async function restartServe(deps, target) {
|
|
5598
|
+
if (target === undefined)
|
|
5599
|
+
return;
|
|
5600
|
+
const client = await deps.connect().catch(() => {
|
|
5601
|
+
return;
|
|
5602
|
+
});
|
|
5603
|
+
if (client === undefined)
|
|
5604
|
+
return;
|
|
5605
|
+
const status = await client.request("GET", BRIDGE_PATHS.status);
|
|
5606
|
+
if (compareVersions(target, status.serverVersion) <= 0)
|
|
5607
|
+
return;
|
|
5608
|
+
if (status.activeJob !== undefined) {
|
|
5609
|
+
note(`voyager serve still runs ${status.serverVersion}: job ${status.activeJob.jobId} is running`);
|
|
5610
|
+
return { line: "restart voyager serve after the current job", code: EXIT.ok };
|
|
5611
|
+
}
|
|
5612
|
+
try {
|
|
5613
|
+
await deps.restartServe();
|
|
5614
|
+
} catch (error) {
|
|
5615
|
+
note(`could not restart voyager serve: ${String(error)}; run voyager serve --stop`);
|
|
5616
|
+
return { line: "serve not restarted", code: EXIT.transient };
|
|
5617
|
+
}
|
|
5618
|
+
return { line: `serve ${status.serverVersion} → ${target}`, code: EXIT.ok };
|
|
5619
|
+
}
|
|
5620
|
+
function isRefreshResult(value) {
|
|
5621
|
+
return isRecord2(value) && typeof value.status === "string" && typeof value.host === "string";
|
|
5622
|
+
}
|
|
5623
|
+
async function refreshPageData(deps) {
|
|
5624
|
+
let client;
|
|
5625
|
+
let jobId;
|
|
5626
|
+
try {
|
|
5627
|
+
client = await deps.ensure();
|
|
5628
|
+
await warnIfExtensionAway(client);
|
|
5629
|
+
({ jobId } = await client.request("POST", BRIDGE_PATHS.call, {
|
|
5630
|
+
op: "catalog.refresh",
|
|
5631
|
+
params: {}
|
|
5632
|
+
}));
|
|
5633
|
+
} catch (thrown) {
|
|
5634
|
+
const error = toBridgeError(thrown);
|
|
5635
|
+
if (thrown instanceof BridgeFailure && error.code === "busy") {
|
|
5636
|
+
const active = String(error.details?.activeJobId ?? "?");
|
|
5637
|
+
note(`job ${active} is running and jobs are not queued; run voyager update again after it`);
|
|
5638
|
+
return {
|
|
5639
|
+
line: "page data not refreshed (a job is running)",
|
|
5640
|
+
code: EXIT.busy,
|
|
5641
|
+
unsupported: false,
|
|
5642
|
+
error
|
|
5643
|
+
};
|
|
5644
|
+
}
|
|
5645
|
+
note(`page data: ${error.code}: ${error.message}`);
|
|
5646
|
+
return {
|
|
5647
|
+
line: `page data not refreshed (${error.code})`,
|
|
5648
|
+
code: exitForError(error),
|
|
5649
|
+
unsupported: false,
|
|
5650
|
+
error
|
|
5651
|
+
};
|
|
5652
|
+
}
|
|
5653
|
+
const outcome = await waitForJob(client, jobId, deps.pageDataWaitMs);
|
|
5654
|
+
const job = outcome.job;
|
|
5655
|
+
if (outcome.kind === "timeout") {
|
|
5656
|
+
note(`the extension has not answered yet; job ${jobId} continues (voyager job wait ${jobId})`);
|
|
5657
|
+
return {
|
|
5658
|
+
line: "page data: waiting for the extension",
|
|
5659
|
+
code: EXIT.waitTimeout,
|
|
5660
|
+
unsupported: false
|
|
5661
|
+
};
|
|
5662
|
+
}
|
|
5663
|
+
if (job.status !== "succeeded") {
|
|
5664
|
+
if (job.error?.code === "unsupported-op") {
|
|
5665
|
+
return {
|
|
5666
|
+
line: "page data needs a newer extension",
|
|
5667
|
+
code: EXIT.ok,
|
|
5668
|
+
unsupported: true,
|
|
5669
|
+
error: job.error
|
|
5670
|
+
};
|
|
5671
|
+
}
|
|
5672
|
+
note(`page data: ${job.error?.code ?? job.status}: ${job.error?.message ?? ""}`);
|
|
5673
|
+
return {
|
|
5674
|
+
line: `page data not refreshed (${job.error?.code ?? job.status})`,
|
|
5675
|
+
code: exitForJob(job),
|
|
5676
|
+
unsupported: false,
|
|
5677
|
+
error: job.error
|
|
5678
|
+
};
|
|
5679
|
+
}
|
|
5680
|
+
const result = job.result?.result;
|
|
5681
|
+
if (!isRefreshResult(result)) {
|
|
5682
|
+
return { line: "page data: no result", code: EXIT.failed, unsupported: false };
|
|
5683
|
+
}
|
|
5684
|
+
const revision = result.revision === null ? "" : ` (revision ${result.revision})`;
|
|
5685
|
+
switch (result.status) {
|
|
5686
|
+
case "updated":
|
|
5687
|
+
return { line: `page data refreshed${revision}`, code: EXIT.ok, result, unsupported: false };
|
|
5688
|
+
case "unchanged":
|
|
5689
|
+
return { line: `page data up to date${revision}`, code: EXIT.ok, result, unsupported: false };
|
|
5690
|
+
case "missing":
|
|
5691
|
+
return {
|
|
5692
|
+
line: `no page data published for ${result.host}`,
|
|
5693
|
+
code: EXIT.ok,
|
|
5694
|
+
result,
|
|
5695
|
+
unsupported: false
|
|
5696
|
+
};
|
|
5697
|
+
case "disabled":
|
|
5698
|
+
return {
|
|
5699
|
+
line: "this extension build has no online page data",
|
|
5700
|
+
code: EXIT.ok,
|
|
5701
|
+
result,
|
|
5702
|
+
unsupported: false
|
|
5703
|
+
};
|
|
5704
|
+
case "failed":
|
|
5705
|
+
note(`the extension could not fetch the page data: ${result.reason ?? "unknown error"}`);
|
|
5706
|
+
return { line: "page data refresh failed", code: EXIT.transient, result, unsupported: false };
|
|
5707
|
+
}
|
|
5708
|
+
}
|
|
5709
|
+
async function pairedExtensionVersion(deps) {
|
|
5710
|
+
try {
|
|
5711
|
+
const client = await deps.connect();
|
|
5712
|
+
if (client === undefined)
|
|
5713
|
+
return null;
|
|
5714
|
+
return (await client.request("GET", BRIDGE_PATHS.status)).extension.version;
|
|
5715
|
+
} catch {
|
|
5716
|
+
return null;
|
|
5717
|
+
}
|
|
5718
|
+
}
|
|
5719
|
+
async function updateCommand(paths, argv, deps = defaultUpdateDeps(paths)) {
|
|
5720
|
+
const args = parse(argv, { json: { type: "boolean", summary: "JSON output" } });
|
|
5721
|
+
const cli = await updateCli(deps);
|
|
5722
|
+
const serve = await restartServe(deps, cli.serveTarget);
|
|
5723
|
+
const page = await refreshPageData(deps);
|
|
5724
|
+
const running = page.result?.extensionVersion;
|
|
5725
|
+
const paired = running === undefined ? await pairedExtensionVersion(deps) : null;
|
|
5726
|
+
let extension;
|
|
5727
|
+
if (running !== undefined)
|
|
5728
|
+
extension = { line: `extension ${running} ✓`, code: EXIT.ok };
|
|
5729
|
+
else if (page.unsupported) {
|
|
5730
|
+
note("this extension cannot refresh its page data yet: update the Voyager extension in your browser");
|
|
5731
|
+
extension = {
|
|
5732
|
+
line: `extension ${paired ?? "?"}: update the Voyager extension in your browser`,
|
|
5733
|
+
code: EXIT.ok
|
|
5734
|
+
};
|
|
5735
|
+
} else
|
|
5736
|
+
extension = {
|
|
5737
|
+
line: paired === null ? "extension version unknown" : `extension ${paired}`,
|
|
5738
|
+
code: EXIT.ok
|
|
5739
|
+
};
|
|
5740
|
+
const steps = [cli, ...serve ? [serve] : [], page, extension];
|
|
5741
|
+
const code = steps.find((step) => step.code !== EXIT.ok)?.code ?? EXIT.ok;
|
|
5742
|
+
if (args.options.json === true) {
|
|
5743
|
+
printJson({
|
|
5744
|
+
ok: code === EXIT.ok,
|
|
5745
|
+
cli: cli.json,
|
|
5746
|
+
serve: serve?.line ?? null,
|
|
5747
|
+
pageData: page.result ?? (page.error === undefined ? null : { error: page.error }),
|
|
5748
|
+
extension: {
|
|
5749
|
+
version: running ?? paired,
|
|
5750
|
+
offersRefresh: page.unsupported ? false : running !== undefined ? true : null
|
|
5751
|
+
},
|
|
5752
|
+
summary: steps.map((step) => step.line).join(" · ")
|
|
5753
|
+
});
|
|
5754
|
+
} else
|
|
5755
|
+
printLine(steps.map((step) => step.line).join(" · "));
|
|
5756
|
+
return code;
|
|
5757
|
+
}
|
|
5758
|
+
|
|
5318
5759
|
// src/cli/main.ts
|
|
5319
5760
|
var USAGE2 = `voyager ${CLI_VERSION}: drive ChatGPT through the Voyager extension, locally
|
|
5320
5761
|
|
|
@@ -5327,10 +5768,12 @@ usage:
|
|
|
5327
5768
|
[--project <name|id>] ask in a new chat of a ChatGPT project (its files are there)
|
|
5328
5769
|
[--timeout 30m] [--no-wait] [--keep-tab]
|
|
5329
5770
|
voyager read <link|id> [--json] save an existing conversation's last finished reply
|
|
5771
|
+
[--keep-tab] leave its ChatGPT tab open
|
|
5330
5772
|
voyager project list | create <name> | files <project> ChatGPT projects; <project>: name or g-p- id
|
|
5331
5773
|
| upload <project> <file|folder> replaces a same-name file (ChatGPT ignores re-uploads),
|
|
5332
5774
|
skips one unchanged; a folder goes up as <folder>.zip
|
|
5333
5775
|
| remove <project> <file> [--yes] deletes at once, no undo; asks, or needs --yes without a tty
|
|
5776
|
+
[--keep-tab] any project command: leave its ChatGPT tab open
|
|
5334
5777
|
voyager status [--json] serve, pairing and active job
|
|
5335
5778
|
voyager commands [--json] plugin commands and extension ops
|
|
5336
5779
|
voyager call <op> [--params JSON] run one extension op (debugging)
|
|
@@ -5339,7 +5782,11 @@ usage:
|
|
|
5339
5782
|
while it exits 4; never resend the prompt
|
|
5340
5783
|
voyager plugin create <dir> | check <dir> write a Voyager extension plugin
|
|
5341
5784
|
voyager serve [--foreground | --stop]
|
|
5785
|
+
voyager update [--json] update the CLI (global npm install), restart serve onto it,
|
|
5786
|
+
refresh the extension's page data, report its version
|
|
5342
5787
|
|
|
5788
|
+
each job opens its own ChatGPT tab and closes it when it ends, also after a failure,
|
|
5789
|
+
unless --keep-tab; one you need to look at (sign-in, an unconfirmed send) stays open
|
|
5343
5790
|
results name the ChatGPT plan the pages last showed (JSON: account; may trail a change)
|
|
5344
5791
|
exit codes: 0 ok, 2 failed (data), 3 needs a person, 4 wait timed out (job continues),
|
|
5345
5792
|
5 busy, 6 transient/detached/reply-stalled, 7 not paired or extension offline
|
|
@@ -5373,6 +5820,8 @@ async function main(argv) {
|
|
|
5373
5820
|
return jobCommand(paths, registry, rest);
|
|
5374
5821
|
case "plugin":
|
|
5375
5822
|
return extensionPluginCommand(rest);
|
|
5823
|
+
case "update":
|
|
5824
|
+
return updateCommand(paths, rest);
|
|
5376
5825
|
default: {
|
|
5377
5826
|
const found = registry.findCommand(command);
|
|
5378
5827
|
if (found === undefined) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voyager-crew/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Ask ChatGPT from your terminal or your coding agent, through the Voyager browser extension",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatgpt",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/node": "^24.9.0",
|
|
49
|
-
"@voyager-crew/bridge-protocol": "^0.
|
|
49
|
+
"@voyager-crew/bridge-protocol": "^0.3.0",
|
|
50
50
|
"fflate": "0.8.2",
|
|
51
51
|
"oxfmt": "^0.65.0",
|
|
52
52
|
"oxlint": "^1.80.0",
|
package/skills/voyager/SKILL.md
CHANGED
|
@@ -75,7 +75,7 @@ voyager job wait <jobId> --timeout 10m --json
|
|
|
75
75
|
| Code | Meaning | Next step |
|
|
76
76
|
| ---- | ----------------------------------------------------------------------------------- | ------------------------------------------------------- |
|
|
77
77
|
| 0 | succeeded | read `responsePath` |
|
|
78
|
-
| 2 | failed (bad input, or the page changed)
|
|
78
|
+
| 2 | failed (bad input, or the page changed); `send-unverified`: the prompt may be sent | report `error.message`; never resend `send-unverified` |
|
|
79
79
|
| 3 | needs a person (`login-required`, `challenge`, `rate-limited`, `policy-denied`, …) | stop and tell the person what `error.code` asks of them |
|
|
80
80
|
| 4 | wait timed out; job continues | `voyager job wait <jobId> --json` again; do not resend |
|
|
81
81
|
| 5 | busy: another job runs (`error.details.activeJobId`) | wait for that job, or ask the person |
|
|
@@ -84,6 +84,10 @@ voyager job wait <jobId> --timeout 10m --json
|
|
|
84
84
|
|
|
85
85
|
Exactly one job runs at a time, and jobs are never queued. Each prompt is submitted **once**. After any exit other than 0, report to the person and let them decide; a second `voyager ask` with the same prompt would send it again. `send-unverified` means the page may have sent it, so the person checks ChatGPT first.
|
|
86
86
|
|
|
87
|
+
## The browser tab
|
|
88
|
+
|
|
89
|
+
`ask`, `read` and every `project` command open their own ChatGPT tab and close it when they end, also after a failure. `--keep-tab` leaves it open, for when the person wants to look at the page. A tab the person has to act in stays open by itself: sign-in or a challenge (exit 3), and `send-unverified`.
|
|
90
|
+
|
|
87
91
|
## Pairing (the person does this once)
|
|
88
92
|
|
|
89
93
|
```sh
|
|
@@ -97,3 +101,4 @@ It prints a code like `1234-5678`. The person types it into the Voyager popup (C
|
|
|
97
101
|
- `voyager job list | show <id> | cancel <id>`: cancelling stops Voyager from watching. A prompt already sent stays in ChatGPT.
|
|
98
102
|
- `voyager commands --json`: plugin commands, and the ops the extension offers right now.
|
|
99
103
|
- `voyager call <op> --params '<json>'`: one raw op, for debugging only.
|
|
104
|
+
- `voyager update [--json]`: only when the person asks. It may run `npm i -g @voyager-crew/cli@latest` and restart `voyager serve`; it refreshes the extension's page data and reports the extension's version. Exit 0 also when it only printed a command for the person to run.
|