@getgavel/cli 0.1.3 → 0.1.5
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 +1 -0
- package/dist/gavel.js +208 -57
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ gavel ask --file decision.json # put a decision to your person
|
|
|
32
32
|
gavel wait D-12 --timeout 60 # until it's decided
|
|
33
33
|
gavel watch # one GAVEL_WAKE line per new thing for you; run it in the background
|
|
34
34
|
gavel help # every command
|
|
35
|
+
gavel act --help # one command's usage
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
`GAVEL_TOKEN` is your agent's token (pairing sets it up); `GAVEL_API_URL` defaults to
|
package/dist/gavel.js
CHANGED
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
// on a fleet token, the chat's name with --as or GAVEL_AGENT (sent as X-Gavel-Agent).
|
|
5
5
|
// Prints the API's JSON; on an error, prints it to stderr and exits 1.
|
|
6
6
|
import { execFileSync } from "node:child_process";
|
|
7
|
-
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
8
8
|
import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, unlinkSync, writeFileSync } from "node:fs";
|
|
9
9
|
import { homedir, hostname } from "node:os";
|
|
10
|
-
import { dirname, join } from "node:path";
|
|
10
|
+
import { basename, dirname, extname, join } from "node:path";
|
|
11
11
|
const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
|
|
12
12
|
|
|
13
13
|
gavel pair <code> [--harness cursor|claude-code|codex|other] [--machine <name>]
|
|
14
14
|
redeem your person's pairing code and write your setup
|
|
15
15
|
(no GAVEL_TOKEN needed; never prints the token)
|
|
16
|
-
gavel search <words> [--area <slug>] [--status open|decided|any] [--limit <n>]
|
|
16
|
+
gavel search (<words> | --query <words>) [--area <slug>] [--status open|decided|any] [--limit <n>]
|
|
17
17
|
gavel ask --file decision.json the decision, as MCP ask's input
|
|
18
18
|
gavel revise <D-12> --file decision.json a draft the editor sent back, fixed (the whole ask again)
|
|
19
19
|
gavel todo --file todo.json ask a person to do something: title, steps, why (MCP ask_to_do's input)
|
|
@@ -21,15 +21,23 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
|
|
|
21
21
|
gavel wait <D-12> [--timeout <seconds>] until it's decided (default 60)
|
|
22
22
|
gavel withdraw <D-12> [--reason <words>] take back what you asked, while it isn't decided
|
|
23
23
|
gavel attach <D-12> --file context.json a context item, or a list of them
|
|
24
|
-
gavel
|
|
25
|
-
|
|
24
|
+
gavel upload <file> [--type <content type>]
|
|
25
|
+
a screenshot or recording (PNG, JPEG, GIF, WebP, HEIC up to
|
|
26
|
+
50 MB; MP4, MOV up to 500 MB), sent and finished: put its id
|
|
27
|
+
in a context item's attachmentId (section pictures, kind
|
|
28
|
+
screenshot or recording) for attach, ask, todo or log
|
|
29
|
+
gavel answer <requestId> (<response> | --response <words>)
|
|
30
|
+
answer an Ask someone
|
|
31
|
+
gavel act <D-12> (<note> | --note <words>)
|
|
32
|
+
what you did with the answer
|
|
26
33
|
gavel inbox what's waiting on you
|
|
27
|
-
gavel status <text> [--folders <a,b>] [--state working|blocked|idle] [--issue <MA-482>]
|
|
34
|
+
gavel status (<text> | --text <words>) [--folders <a,b>] [--state working|blocked|idle] [--issue <MA-482>]
|
|
35
|
+
[--waiting-on <email>]
|
|
28
36
|
what you're doing now, in plain words ("" clears it);
|
|
29
37
|
--waiting-on names the person you're blocked on
|
|
30
|
-
gavel message (--to-agent <id> | --to-person <email>) <text> [--decision <D-12>]
|
|
38
|
+
gavel message (--to-agent <id> | --to-person <email>) (<text> | --text <words>) [--decision <D-12>]
|
|
31
39
|
start a conversation with another agent
|
|
32
|
-
gavel message --conversation <C-12> <text>
|
|
40
|
+
gavel message --conversation <C-12> (<text> | --text <words>)
|
|
33
41
|
reply in one
|
|
34
42
|
gavel conversations [<C-12>] yours, or one with its messages (reads it)
|
|
35
43
|
gavel wait-for-reply <C-12> [--timeout <seconds>]
|
|
@@ -40,6 +48,7 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
|
|
|
40
48
|
background; one per agent)
|
|
41
49
|
gavel log --question <q> --outcome <o> --reason <why> [--area <slug>] [--trust <id>] [--file context.json]
|
|
42
50
|
gavel log-answer --question <q> --answer <what they decided> [--note <their why>] [--area <slug>]
|
|
51
|
+
[--file context.json]
|
|
43
52
|
what your person answered you in chat, as theirs
|
|
44
53
|
gavel decide <D-12> (--option <id> | --text <words>) [--note <words>]
|
|
45
54
|
a multiple question: --option again for each pick,
|
|
@@ -47,29 +56,82 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
|
|
|
47
56
|
gavel decide-for <D-12> (--option <id> | --text <words>) --reason <why> --trust <id>
|
|
48
57
|
gavel priority <D-12> now|later [--note <words>]
|
|
49
58
|
gavel forward <D-12> (--to-person <email> | --to-agent <id>) [--note <words>]
|
|
50
|
-
gavel research-result <requestId> <response> [--file context.json]
|
|
59
|
+
gavel research-result <requestId> (<response> | --response <words>) [--file context.json]
|
|
51
60
|
gavel agents you and your sub-agents
|
|
52
61
|
gavel invite --name <name> [--description <words>] [--permissions ask,answer]
|
|
53
62
|
gavel start-cloud-agent --name <task's name> --repo <url> --task <words> [--branch <ref>] [--open-pr true]
|
|
54
63
|
[--machine <worker>] [--agent <agent id>]
|
|
55
64
|
a Cursor cloud agent under you, for a task; --machine runs it on
|
|
56
65
|
your person's own machine (My Machines), --agent starts an
|
|
57
|
-
agent under you as itself (no --name), its
|
|
66
|
+
agent under you, or yourself, as itself (no --name), its
|
|
67
|
+
old tokens ended
|
|
58
68
|
gavel me
|
|
59
69
|
|
|
60
70
|
--as <name> on a fleet token, which chat you are (the name you go by,
|
|
61
71
|
e.g. worker 35 or the task you're on; keep using the same one)
|
|
62
72
|
|
|
73
|
+
gavel <command> --help shows one command's usage. A command refuses a flag or a word it doesn't
|
|
74
|
+
take, and a flag given twice (but --option), with its usage.
|
|
63
75
|
A text argument or --file of "-" is read from stdin.
|
|
64
76
|
Environment: GAVEL_TOKEN (required), GAVEL_API_URL (default https://api.getgavel.ai),
|
|
65
77
|
GAVEL_AGENT (instead of --as).`;
|
|
78
|
+
// What each command takes besides its words, as its usage above names them: anything else is
|
|
79
|
+
// refused with that usage, never dropped.
|
|
80
|
+
const FLAGS = {
|
|
81
|
+
pair: ["harness", "machine"],
|
|
82
|
+
search: ["query", "area", "status", "limit"],
|
|
83
|
+
ask: ["file"],
|
|
84
|
+
revise: ["file"],
|
|
85
|
+
todo: ["file"],
|
|
86
|
+
get: [],
|
|
87
|
+
wait: ["timeout"],
|
|
88
|
+
withdraw: ["reason"],
|
|
89
|
+
attach: ["file"],
|
|
90
|
+
upload: ["type"],
|
|
91
|
+
answer: ["response"],
|
|
92
|
+
act: ["note"],
|
|
93
|
+
inbox: [],
|
|
94
|
+
status: ["text", "folders", "state", "issue", "waiting-on"],
|
|
95
|
+
message: ["to-agent", "to-person", "conversation", "text", "decision"],
|
|
96
|
+
conversations: [],
|
|
97
|
+
"wait-for-reply": ["timeout"],
|
|
98
|
+
watch: [],
|
|
99
|
+
log: ["question", "outcome", "reason", "area", "trust", "file"],
|
|
100
|
+
"log-answer": ["question", "answer", "note", "area", "file"],
|
|
101
|
+
decide: ["option", "text", "note"],
|
|
102
|
+
"decide-for": ["option", "text", "reason", "trust"],
|
|
103
|
+
priority: ["note"],
|
|
104
|
+
forward: ["to-person", "to-agent", "note"],
|
|
105
|
+
"research-result": ["response", "file"],
|
|
106
|
+
agents: [],
|
|
107
|
+
invite: ["name", "description", "permissions"],
|
|
108
|
+
"start-cloud-agent": ["name", "repo", "task", "branch", "open-pr", "machine", "agent"],
|
|
109
|
+
me: [],
|
|
110
|
+
};
|
|
111
|
+
const isCommand = (name) => Object.hasOwn(FLAGS, name);
|
|
112
|
+
// A command's own entries in USAGE: each line naming it, with the lines indented under it.
|
|
113
|
+
export function usageOf(command) {
|
|
114
|
+
const out = [];
|
|
115
|
+
let mine = false;
|
|
116
|
+
for (const line of USAGE.split("\n")) {
|
|
117
|
+
if (line.startsWith(" gavel "))
|
|
118
|
+
mine = line === ` gavel ${command}` || line.startsWith(` gavel ${command} `);
|
|
119
|
+
else if (!line.startsWith(" "))
|
|
120
|
+
mine = false;
|
|
121
|
+
if (mine)
|
|
122
|
+
out.push(line);
|
|
123
|
+
}
|
|
124
|
+
return out.join("\n");
|
|
125
|
+
}
|
|
66
126
|
class UsageError extends Error {
|
|
67
127
|
}
|
|
68
|
-
export function parseArgs(argv) {
|
|
128
|
+
export function parseArgs(argv, command) {
|
|
69
129
|
const positional = [];
|
|
70
130
|
const flags = {};
|
|
71
131
|
const lists = {};
|
|
72
132
|
const set = (name, value) => {
|
|
133
|
+
if (Object.hasOwn(flags, name) && name !== "option")
|
|
134
|
+
throw new UsageError(`give --${name} once`);
|
|
73
135
|
flags[name] = value;
|
|
74
136
|
(lists[name] ??= []).push(value);
|
|
75
137
|
};
|
|
@@ -77,13 +139,16 @@ export function parseArgs(argv) {
|
|
|
77
139
|
const arg = argv[i];
|
|
78
140
|
if (arg.startsWith("--")) {
|
|
79
141
|
const eq = arg.indexOf("=");
|
|
142
|
+
const name = eq > 0 ? arg.slice(2, eq) : arg.slice(2);
|
|
143
|
+
if (!FLAGS[command].includes(name))
|
|
144
|
+
throw new UsageError(`${command} doesn't take --${name}`);
|
|
80
145
|
if (eq > 0)
|
|
81
|
-
set(
|
|
146
|
+
set(name, arg.slice(eq + 1));
|
|
82
147
|
else {
|
|
83
148
|
const value = argv[i + 1];
|
|
84
149
|
if (value === undefined || (value.startsWith("--") && value !== "-"))
|
|
85
150
|
throw new UsageError(`${arg} needs a value`);
|
|
86
|
-
set(
|
|
151
|
+
set(name, value);
|
|
87
152
|
i++;
|
|
88
153
|
}
|
|
89
154
|
}
|
|
@@ -147,59 +212,109 @@ export function agentHeader(name) {
|
|
|
147
212
|
const trimmed = name?.trim();
|
|
148
213
|
return trimmed ? { "x-gavel-agent": encodeURIComponent(trimmed) } : {};
|
|
149
214
|
}
|
|
150
|
-
// A command line → one API request.
|
|
151
215
|
export function toRequest(argv) {
|
|
152
216
|
const [command, ...rest] = argv;
|
|
153
|
-
|
|
217
|
+
if (command === undefined || command === "help" || command === "--help" || command === "-h") {
|
|
218
|
+
if (rest.length > 1)
|
|
219
|
+
throw new UsageError(`help takes one command, not "${rest[1]}"`);
|
|
220
|
+
if (rest[0] === undefined)
|
|
221
|
+
return { help: USAGE };
|
|
222
|
+
if (!isCommand(rest[0]))
|
|
223
|
+
throw new UsageError(`unknown command "${rest[0]}"`);
|
|
224
|
+
return { help: usageOf(rest[0]) };
|
|
225
|
+
}
|
|
226
|
+
if (!isCommand(command))
|
|
227
|
+
throw new UsageError(`unknown command "${command}"`);
|
|
228
|
+
if (rest.includes("--help") || rest.includes("-h"))
|
|
229
|
+
return { help: usageOf(command) };
|
|
230
|
+
const { positional: p, flags: f, lists } = parseArgs(rest, command);
|
|
231
|
+
const upTo = (n) => {
|
|
232
|
+
if (p.length > n)
|
|
233
|
+
throw new UsageError(`${command} doesn't take "${p[n]}"`);
|
|
234
|
+
};
|
|
235
|
+
// A command's words may come as their flag instead (act's --note), never both.
|
|
236
|
+
const words = (flag, from, what) => {
|
|
237
|
+
if (f[flag] !== undefined && from.length)
|
|
238
|
+
throw new UsageError(`give ${what} once: as words or as --${flag}`);
|
|
239
|
+
return need(f[flag] ?? from.join(" "), what);
|
|
240
|
+
};
|
|
154
241
|
switch (command) {
|
|
155
|
-
case
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return "
|
|
242
|
+
case "pair": {
|
|
243
|
+
const harness = f.harness;
|
|
244
|
+
if (harness !== undefined && !HARNESSES.includes(harness))
|
|
245
|
+
throw new UsageError(`--harness is one of ${HARNESSES.join(", ")}`);
|
|
246
|
+
return { pair: { code: need(p.join(""), "the pairing code (like 4F7K-9QX2)"), harness, machine: f.machine } };
|
|
247
|
+
}
|
|
248
|
+
case "watch":
|
|
249
|
+
upTo(0);
|
|
250
|
+
return { watch: true };
|
|
251
|
+
case "upload": {
|
|
252
|
+
upTo(1);
|
|
253
|
+
const file = need(p[0], "the file to upload");
|
|
254
|
+
const contentType = f.type ?? TYPES[extname(file).toLowerCase()];
|
|
255
|
+
if (!contentType)
|
|
256
|
+
throw new UsageError(`can't tell ${basename(file)}'s type from its name: give --type (${[...new Set(Object.values(TYPES))].join(", ")})`);
|
|
257
|
+
return { upload: { file, contentType } };
|
|
258
|
+
}
|
|
160
259
|
case "search": {
|
|
161
|
-
const query = new URLSearchParams(compact({ q:
|
|
260
|
+
const query = new URLSearchParams(compact({ q: words("query", p, "the words to search for"), area: f.area, status: f.status, limit: f.limit }));
|
|
162
261
|
return { method: "GET", path: `/v1/search?${query}` };
|
|
163
262
|
}
|
|
164
263
|
case "ask":
|
|
264
|
+
upTo(0);
|
|
165
265
|
return { method: "POST", path: "/v1/decisions", body: readJson(need(f.file, "--file decision.json")) };
|
|
166
266
|
case "revise":
|
|
267
|
+
upTo(1);
|
|
167
268
|
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/revise`, body: readJson(need(f.file, "--file decision.json")) };
|
|
168
269
|
case "todo":
|
|
270
|
+
upTo(0);
|
|
169
271
|
return { method: "POST", path: "/v1/todos", body: readJson(need(f.file, "--file todo.json")) };
|
|
170
272
|
case "get":
|
|
273
|
+
upTo(1);
|
|
171
274
|
return { method: "GET", path: `/v1/decisions/${ref(p[0])}` };
|
|
172
275
|
case "wait":
|
|
276
|
+
upTo(1);
|
|
173
277
|
return { method: "GET", path: `/v1/decisions/${ref(p[0])}/wait?timeout=${encodeURIComponent(f.timeout ?? "60")}` };
|
|
174
278
|
case "withdraw":
|
|
279
|
+
upTo(1);
|
|
175
280
|
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/withdraw`, body: compact({ reason: f.reason && readText(f.reason) }) };
|
|
176
281
|
case "attach":
|
|
282
|
+
upTo(1);
|
|
177
283
|
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/context`, body: { items: contextList(need(f.file, "--file context.json")) } };
|
|
178
284
|
case "answer":
|
|
179
|
-
return { method: "POST", path: `/v1/requests/${encodeURIComponent(need(p[0], "the request id"))}/answer`, body: { response: readText(
|
|
285
|
+
return { method: "POST", path: `/v1/requests/${encodeURIComponent(need(p[0], "the request id"))}/answer`, body: { response: readText(words("response", p.slice(1), "the response")) } };
|
|
180
286
|
case "act":
|
|
181
|
-
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/act`, body: { note: readText(
|
|
287
|
+
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/act`, body: { note: readText(words("note", p.slice(1), "the note")) } };
|
|
182
288
|
case "inbox":
|
|
289
|
+
upTo(0);
|
|
183
290
|
return { method: "GET", path: "/v1/inbox" };
|
|
184
291
|
case "status": {
|
|
185
|
-
if (
|
|
292
|
+
if (f.text !== undefined && p.length)
|
|
293
|
+
throw new UsageError("give what you're doing once: as words or as --text");
|
|
294
|
+
const said = f.text ?? (p.length ? p.join(" ") : undefined);
|
|
295
|
+
if (said === undefined)
|
|
186
296
|
throw new UsageError('missing what you\'re doing now (or "" to clear it)');
|
|
187
297
|
const folders = f.folders?.split(",").map((s) => s.trim()).filter(Boolean);
|
|
188
|
-
return { method: "PATCH", path: "/v1/agents/me/status", body: compact({ text: readText(
|
|
298
|
+
return { method: "PATCH", path: "/v1/agents/me/status", body: compact({ text: readText(said) || null, folders, state: f.state, linearIssue: f.issue, waitingOn: f["waiting-on"] }) };
|
|
189
299
|
}
|
|
190
300
|
case "message": {
|
|
191
|
-
const text = readText(
|
|
301
|
+
const text = readText(words("text", p, "what to say"));
|
|
192
302
|
if ([f.conversation, f["to-agent"], f["to-person"]].filter(Boolean).length !== 1)
|
|
193
303
|
throw new UsageError("give --to-agent or --to-person to start a conversation, or --conversation to reply in one");
|
|
304
|
+
if (f.conversation && f.decision !== undefined)
|
|
305
|
+
throw new UsageError("--decision is only for starting a conversation");
|
|
194
306
|
if (f.conversation)
|
|
195
307
|
return { method: "POST", path: `/v1/conversations/${encodeURIComponent(f.conversation)}/messages`, body: { text } };
|
|
196
308
|
return { method: "POST", path: "/v1/conversations", body: compact({ toAgentId: f["to-agent"], toPerson: f["to-person"], text, decision: f.decision }) };
|
|
197
309
|
}
|
|
198
310
|
case "conversations":
|
|
311
|
+
upTo(1);
|
|
199
312
|
return { method: "GET", path: p[0] ? `/v1/conversations/${encodeURIComponent(p[0])}` : "/v1/conversations" };
|
|
200
313
|
case "wait-for-reply":
|
|
314
|
+
upTo(1);
|
|
201
315
|
return { method: "GET", path: `/v1/conversations/${encodeURIComponent(need(p[0], "the conversation (C-12)"))}/wait?timeout=${encodeURIComponent(f.timeout ?? "60")}` };
|
|
202
316
|
case "log":
|
|
317
|
+
upTo(0);
|
|
203
318
|
return {
|
|
204
319
|
method: "POST",
|
|
205
320
|
path: "/v1/decided",
|
|
@@ -213,42 +328,50 @@ export function toRequest(argv) {
|
|
|
213
328
|
}),
|
|
214
329
|
};
|
|
215
330
|
case "log-answer":
|
|
331
|
+
upTo(0);
|
|
216
332
|
return {
|
|
217
333
|
method: "POST",
|
|
218
334
|
path: "/v1/decided/answers",
|
|
219
335
|
body: compact({ question: need(f.question, "--question"), answer: readText(need(f.answer, "--answer")), note: f.note && readText(f.note), area: f.area, context: contextList(f.file) }),
|
|
220
336
|
};
|
|
221
337
|
case "decide":
|
|
338
|
+
upTo(1);
|
|
222
339
|
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/decide`, body: compact({ ...picks(lists.option), text: f.text && readText(f.text), note: f.note }) };
|
|
223
340
|
case "decide-for":
|
|
341
|
+
upTo(1);
|
|
224
342
|
return {
|
|
225
343
|
method: "POST",
|
|
226
344
|
path: `/v1/decisions/${ref(p[0])}/decide-for`,
|
|
227
345
|
body: compact({ ...picks(lists.option), text: f.text && readText(f.text), reason: readText(need(f.reason, "--reason")), trustId: need(f.trust, "--trust") }),
|
|
228
346
|
};
|
|
229
347
|
case "priority": {
|
|
348
|
+
upTo(2);
|
|
230
349
|
const priority = need(p[1], "now or later");
|
|
231
350
|
if (priority !== "now" && priority !== "later")
|
|
232
351
|
throw new UsageError("the priority is now or later");
|
|
233
352
|
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/priority`, body: compact({ priority, note: f.note }) };
|
|
234
353
|
}
|
|
235
354
|
case "forward":
|
|
355
|
+
upTo(1);
|
|
236
356
|
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/forward`, body: compact({ toPerson: f["to-person"], toAgentId: f["to-agent"], note: f.note }) };
|
|
237
357
|
case "research-result":
|
|
238
358
|
return {
|
|
239
359
|
method: "POST",
|
|
240
360
|
path: `/v1/requests/${encodeURIComponent(need(p[0], "the request id"))}/research-result`,
|
|
241
|
-
body: compact({ response: readText(
|
|
361
|
+
body: compact({ response: readText(words("response", p.slice(1), "the response")), context: contextList(f.file) }),
|
|
242
362
|
};
|
|
243
363
|
case "agents":
|
|
364
|
+
upTo(0);
|
|
244
365
|
return { method: "GET", path: "/v1/agents" };
|
|
245
366
|
case "invite":
|
|
367
|
+
upTo(0);
|
|
246
368
|
return {
|
|
247
369
|
method: "POST",
|
|
248
370
|
path: "/v1/sub-agents",
|
|
249
371
|
body: compact({ name: need(f.name, "--name"), description: f.description, permissions: f.permissions?.split(",").map((s) => s.trim()) }),
|
|
250
372
|
};
|
|
251
373
|
case "start-cloud-agent":
|
|
374
|
+
upTo(0);
|
|
252
375
|
return {
|
|
253
376
|
method: "POST",
|
|
254
377
|
path: "/v1/cloud-agents",
|
|
@@ -263,6 +386,7 @@ export function toRequest(argv) {
|
|
|
263
386
|
}),
|
|
264
387
|
};
|
|
265
388
|
case "me":
|
|
389
|
+
upTo(0);
|
|
266
390
|
return { method: "GET", path: "/v1/me" };
|
|
267
391
|
default:
|
|
268
392
|
throw new UsageError(`unknown command "${command}"`);
|
|
@@ -513,12 +637,8 @@ export async function dropLegacy(setup, legacy, opts) {
|
|
|
513
637
|
return [`left the old ${legacy.server} entry in ${old.where}: its token still works (another workspace's or agent's)`];
|
|
514
638
|
return [`left the old ${legacy.server} entry in ${old.where}: couldn't check its token`];
|
|
515
639
|
}
|
|
516
|
-
async function pair(
|
|
517
|
-
const
|
|
518
|
-
const code = need(positional.join(""), "the pairing code (like 4F7K-9QX2)");
|
|
519
|
-
const harness = (flags.harness ?? detectHarness(process.env));
|
|
520
|
-
if (!HARNESSES.includes(harness))
|
|
521
|
-
throw new UsageError(`--harness is one of ${HARNESSES.join(", ")}`);
|
|
640
|
+
async function pair(input) {
|
|
641
|
+
const harness = input.harness ?? detectHarness(process.env);
|
|
522
642
|
if (harness === "claude-code" && !runs("claude")) {
|
|
523
643
|
console.error("gavel: Claude Code's claude command isn't on this PATH, so Gavel can't be added to it from here. Run this in Claude Code, or where claude runs; the code still works.");
|
|
524
644
|
return 1;
|
|
@@ -527,7 +647,7 @@ async function pair(argv) {
|
|
|
527
647
|
const res = await fetch(`${base}/v1/pair`, {
|
|
528
648
|
method: "POST",
|
|
529
649
|
headers: { "content-type": "application/json", accept: "application/json" },
|
|
530
|
-
body: JSON.stringify({ code, harness, machine:
|
|
650
|
+
body: JSON.stringify({ code: input.code, harness, machine: input.machine ?? hostname().split(".")[0] }),
|
|
531
651
|
});
|
|
532
652
|
const body = (await res.json().catch(() => ({})));
|
|
533
653
|
if (!res.ok) {
|
|
@@ -548,6 +668,46 @@ async function pair(argv) {
|
|
|
548
668
|
console.log(JSON.stringify({ paired: true, kind: body.kind, agent: body.agent, harness, done, then: body.then }, null, 2));
|
|
549
669
|
return 0;
|
|
550
670
|
}
|
|
671
|
+
// ---------- gavel upload ----------
|
|
672
|
+
const TYPES = {
|
|
673
|
+
".png": "image/png",
|
|
674
|
+
".jpg": "image/jpeg",
|
|
675
|
+
".jpeg": "image/jpeg",
|
|
676
|
+
".gif": "image/gif",
|
|
677
|
+
".webp": "image/webp",
|
|
678
|
+
".heic": "image/heic",
|
|
679
|
+
".mp4": "video/mp4",
|
|
680
|
+
".mov": "video/quicktime",
|
|
681
|
+
};
|
|
682
|
+
// A screenshot or recording in Gavel's three steps: started (its size and SHA-256, so storage takes
|
|
683
|
+
// this file alone), sent to the signed address the answer gives, and finished. Prints the attachment.
|
|
684
|
+
async function upload(token, as, { file, contentType }) {
|
|
685
|
+
const body = readFileSync(file);
|
|
686
|
+
const base = (process.env.GAVEL_API_URL ?? "https://api.getgavel.ai").replace(/\/+$/, "");
|
|
687
|
+
const headers = { authorization: `Bearer ${token}`, accept: "application/json", ...agentHeader(as) };
|
|
688
|
+
const failed = async (res) => {
|
|
689
|
+
console.error((await res.text()) || `HTTP ${res.status}`);
|
|
690
|
+
return 1;
|
|
691
|
+
};
|
|
692
|
+
const started = await fetch(`${base}/v1/attachments`, {
|
|
693
|
+
method: "POST",
|
|
694
|
+
headers: { ...headers, "content-type": "application/json" },
|
|
695
|
+
body: JSON.stringify({ contentType, bytes: body.length, sha256: createHash("sha256").update(body).digest("hex"), filename: basename(file) }),
|
|
696
|
+
});
|
|
697
|
+
if (!started.ok)
|
|
698
|
+
return failed(started);
|
|
699
|
+
const { attachment, uploadUrl, headers: putHeaders } = (await started.json());
|
|
700
|
+
const sent = await fetch(uploadUrl, { method: "PUT", headers: putHeaders, body });
|
|
701
|
+
if (!sent.ok) {
|
|
702
|
+
console.error(`gavel upload: storage refused the file (HTTP ${sent.status})`);
|
|
703
|
+
return 1;
|
|
704
|
+
}
|
|
705
|
+
const finished = await fetch(`${base}/v1/attachments/${encodeURIComponent(attachment.id)}/complete`, { method: "POST", headers });
|
|
706
|
+
if (!finished.ok)
|
|
707
|
+
return failed(finished);
|
|
708
|
+
console.log(JSON.stringify(await finished.json(), null, 2));
|
|
709
|
+
return 0;
|
|
710
|
+
}
|
|
551
711
|
// One line per thing that should wake the chat: refs and Gavel's own words only, never a message's
|
|
552
712
|
// text, so the line itself is never someone else's instructions.
|
|
553
713
|
export function wakeLine(item) {
|
|
@@ -611,45 +771,36 @@ async function watch(token, as) {
|
|
|
611
771
|
async function main(argvIn) {
|
|
612
772
|
let request;
|
|
613
773
|
let as = null;
|
|
614
|
-
|
|
615
|
-
try {
|
|
616
|
-
return await pair(argvIn.slice(1));
|
|
617
|
-
}
|
|
618
|
-
catch (err) {
|
|
619
|
-
if (err instanceof UsageError) {
|
|
620
|
-
console.error(`gavel: ${err.message}\n\n${USAGE}`);
|
|
621
|
-
return 2;
|
|
622
|
-
}
|
|
623
|
-
console.error(`gavel: ${err instanceof Error ? err.message : String(err)}`);
|
|
624
|
-
return 1;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
774
|
+
let command;
|
|
627
775
|
try {
|
|
628
776
|
const taken = takeAs(argvIn);
|
|
629
|
-
|
|
630
|
-
if (taken.argv[0] === "watch") {
|
|
631
|
-
const token = process.env.GAVEL_TOKEN;
|
|
632
|
-
if (!token)
|
|
633
|
-
throw new UsageError("set GAVEL_TOKEN to your agent token (gvl_agent_…)");
|
|
634
|
-
return await watch(token, as);
|
|
635
|
-
}
|
|
777
|
+
command = taken.argv[0];
|
|
636
778
|
request = toRequest(taken.argv);
|
|
779
|
+
if ("pair" in request && taken.as !== null)
|
|
780
|
+
throw new UsageError("pair doesn't take --as: a code pairs the agent it was made for");
|
|
781
|
+
as = taken.as ?? process.env.GAVEL_AGENT ?? null;
|
|
637
782
|
}
|
|
638
783
|
catch (err) {
|
|
639
784
|
if (!(err instanceof UsageError))
|
|
640
785
|
throw err;
|
|
641
|
-
console.error(`gavel: ${err.message}\n\n${USAGE}`);
|
|
786
|
+
console.error(`gavel: ${err.message}\n\n${command !== undefined && isCommand(command) ? usageOf(command) : USAGE}`);
|
|
642
787
|
return 2;
|
|
643
788
|
}
|
|
644
|
-
if (
|
|
645
|
-
console.log(
|
|
789
|
+
if ("help" in request) {
|
|
790
|
+
console.log(request.help);
|
|
646
791
|
return 0;
|
|
647
792
|
}
|
|
793
|
+
if ("pair" in request)
|
|
794
|
+
return pair(request.pair);
|
|
648
795
|
const token = process.env.GAVEL_TOKEN;
|
|
649
796
|
if (!token) {
|
|
650
797
|
console.error("gavel: set GAVEL_TOKEN to your agent token (gvl_agent_…)");
|
|
651
798
|
return 2;
|
|
652
799
|
}
|
|
800
|
+
if ("watch" in request)
|
|
801
|
+
return watch(token, as);
|
|
802
|
+
if ("upload" in request)
|
|
803
|
+
return upload(token, as, request.upload);
|
|
653
804
|
const base = (process.env.GAVEL_API_URL ?? "https://api.getgavel.ai").replace(/\/+$/, "");
|
|
654
805
|
const res = await fetch(base + request.path, {
|
|
655
806
|
method: request.method,
|
package/package.json
CHANGED