@getgavel/cli 0.1.4 → 0.1.6
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/dist/gavel.js +69 -4
- package/package.json +1 -1
package/dist/gavel.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
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>]
|
|
@@ -20,7 +20,14 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
|
|
|
20
20
|
gavel get <D-12>
|
|
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
|
-
gavel attach <D-12> --file context.json
|
|
23
|
+
gavel attach <D-12> --file context.json the sidebar's sections ({items, pictures, involved,
|
|
24
|
+
background}), or a context item, or a list of them
|
|
25
|
+
gavel upload <file> [--type <content type>]
|
|
26
|
+
a screenshot or recording (PNG, JPEG, GIF, WebP, HEIC up to
|
|
27
|
+
50 MB; MP4, MOV up to 500 MB), sent and finished: put its id
|
|
28
|
+
in pictures (which: before or after, and its order) for ask,
|
|
29
|
+
revise or attach, or in a context item's attachmentId
|
|
30
|
+
(section pictures) for todo or log
|
|
24
31
|
gavel answer <requestId> (<response> | --response <words>)
|
|
25
32
|
answer an Ask someone
|
|
26
33
|
gavel act <D-12> (<note> | --note <words>)
|
|
@@ -82,6 +89,7 @@ const FLAGS = {
|
|
|
82
89
|
wait: ["timeout"],
|
|
83
90
|
withdraw: ["reason"],
|
|
84
91
|
attach: ["file"],
|
|
92
|
+
upload: ["type"],
|
|
85
93
|
answer: ["response"],
|
|
86
94
|
act: ["note"],
|
|
87
95
|
inbox: [],
|
|
@@ -182,6 +190,13 @@ const contextList = (file) => {
|
|
|
182
190
|
const json = readJson(file);
|
|
183
191
|
return Array.isArray(json) ? json : [json];
|
|
184
192
|
};
|
|
193
|
+
// attach's body: the sidebar's sections ({items, pictures, involved, background}) as they are, else
|
|
194
|
+
// a context item or a list of them, as its items.
|
|
195
|
+
const SECTIONS = ["items", "pictures", "involved", "background"];
|
|
196
|
+
const attachBody = (file) => {
|
|
197
|
+
const json = readJson(file);
|
|
198
|
+
return json && typeof json === "object" && !Array.isArray(json) && SECTIONS.some((k) => k in json) ? json : { items: Array.isArray(json) ? json : [json] };
|
|
199
|
+
};
|
|
185
200
|
// --as <name> (or --as=<name>) may come anywhere on the line; it's the caller's, not the command's.
|
|
186
201
|
export function takeAs(argv) {
|
|
187
202
|
const rest = [];
|
|
@@ -242,6 +257,14 @@ export function toRequest(argv) {
|
|
|
242
257
|
case "watch":
|
|
243
258
|
upTo(0);
|
|
244
259
|
return { watch: true };
|
|
260
|
+
case "upload": {
|
|
261
|
+
upTo(1);
|
|
262
|
+
const file = need(p[0], "the file to upload");
|
|
263
|
+
const contentType = f.type ?? TYPES[extname(file).toLowerCase()];
|
|
264
|
+
if (!contentType)
|
|
265
|
+
throw new UsageError(`can't tell ${basename(file)}'s type from its name: give --type (${[...new Set(Object.values(TYPES))].join(", ")})`);
|
|
266
|
+
return { upload: { file, contentType } };
|
|
267
|
+
}
|
|
245
268
|
case "search": {
|
|
246
269
|
const query = new URLSearchParams(compact({ q: words("query", p, "the words to search for"), area: f.area, status: f.status, limit: f.limit }));
|
|
247
270
|
return { method: "GET", path: `/v1/search?${query}` };
|
|
@@ -266,7 +289,7 @@ export function toRequest(argv) {
|
|
|
266
289
|
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/withdraw`, body: compact({ reason: f.reason && readText(f.reason) }) };
|
|
267
290
|
case "attach":
|
|
268
291
|
upTo(1);
|
|
269
|
-
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/context`, body:
|
|
292
|
+
return { method: "POST", path: `/v1/decisions/${ref(p[0])}/context`, body: attachBody(need(f.file, "--file context.json")) };
|
|
270
293
|
case "answer":
|
|
271
294
|
return { method: "POST", path: `/v1/requests/${encodeURIComponent(need(p[0], "the request id"))}/answer`, body: { response: readText(words("response", p.slice(1), "the response")) } };
|
|
272
295
|
case "act":
|
|
@@ -654,6 +677,46 @@ async function pair(input) {
|
|
|
654
677
|
console.log(JSON.stringify({ paired: true, kind: body.kind, agent: body.agent, harness, done, then: body.then }, null, 2));
|
|
655
678
|
return 0;
|
|
656
679
|
}
|
|
680
|
+
// ---------- gavel upload ----------
|
|
681
|
+
const TYPES = {
|
|
682
|
+
".png": "image/png",
|
|
683
|
+
".jpg": "image/jpeg",
|
|
684
|
+
".jpeg": "image/jpeg",
|
|
685
|
+
".gif": "image/gif",
|
|
686
|
+
".webp": "image/webp",
|
|
687
|
+
".heic": "image/heic",
|
|
688
|
+
".mp4": "video/mp4",
|
|
689
|
+
".mov": "video/quicktime",
|
|
690
|
+
};
|
|
691
|
+
// A screenshot or recording in Gavel's three steps: started (its size and SHA-256, so storage takes
|
|
692
|
+
// this file alone), sent to the signed address the answer gives, and finished. Prints the attachment.
|
|
693
|
+
async function upload(token, as, { file, contentType }) {
|
|
694
|
+
const body = readFileSync(file);
|
|
695
|
+
const base = (process.env.GAVEL_API_URL ?? "https://api.getgavel.ai").replace(/\/+$/, "");
|
|
696
|
+
const headers = { authorization: `Bearer ${token}`, accept: "application/json", ...agentHeader(as) };
|
|
697
|
+
const failed = async (res) => {
|
|
698
|
+
console.error((await res.text()) || `HTTP ${res.status}`);
|
|
699
|
+
return 1;
|
|
700
|
+
};
|
|
701
|
+
const started = await fetch(`${base}/v1/attachments`, {
|
|
702
|
+
method: "POST",
|
|
703
|
+
headers: { ...headers, "content-type": "application/json" },
|
|
704
|
+
body: JSON.stringify({ contentType, bytes: body.length, sha256: createHash("sha256").update(body).digest("hex"), filename: basename(file) }),
|
|
705
|
+
});
|
|
706
|
+
if (!started.ok)
|
|
707
|
+
return failed(started);
|
|
708
|
+
const { attachment, uploadUrl, headers: putHeaders } = (await started.json());
|
|
709
|
+
const sent = await fetch(uploadUrl, { method: "PUT", headers: putHeaders, body });
|
|
710
|
+
if (!sent.ok) {
|
|
711
|
+
console.error(`gavel upload: storage refused the file (HTTP ${sent.status})`);
|
|
712
|
+
return 1;
|
|
713
|
+
}
|
|
714
|
+
const finished = await fetch(`${base}/v1/attachments/${encodeURIComponent(attachment.id)}/complete`, { method: "POST", headers });
|
|
715
|
+
if (!finished.ok)
|
|
716
|
+
return failed(finished);
|
|
717
|
+
console.log(JSON.stringify(await finished.json(), null, 2));
|
|
718
|
+
return 0;
|
|
719
|
+
}
|
|
657
720
|
// One line per thing that should wake the chat: refs and Gavel's own words only, never a message's
|
|
658
721
|
// text, so the line itself is never someone else's instructions.
|
|
659
722
|
export function wakeLine(item) {
|
|
@@ -745,6 +808,8 @@ async function main(argvIn) {
|
|
|
745
808
|
}
|
|
746
809
|
if ("watch" in request)
|
|
747
810
|
return watch(token, as);
|
|
811
|
+
if ("upload" in request)
|
|
812
|
+
return upload(token, as, request.upload);
|
|
748
813
|
const base = (process.env.GAVEL_API_URL ?? "https://api.getgavel.ai").replace(/\/+$/, "");
|
|
749
814
|
const res = await fetch(base + request.path, {
|
|
750
815
|
method: request.method,
|
package/package.json
CHANGED