@getgavel/cli 0.1.4 → 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/dist/gavel.js +58 -2
- 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>]
|
|
@@ -21,6 +21,11 @@ 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 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
|
|
24
29
|
gavel answer <requestId> (<response> | --response <words>)
|
|
25
30
|
answer an Ask someone
|
|
26
31
|
gavel act <D-12> (<note> | --note <words>)
|
|
@@ -82,6 +87,7 @@ const FLAGS = {
|
|
|
82
87
|
wait: ["timeout"],
|
|
83
88
|
withdraw: ["reason"],
|
|
84
89
|
attach: ["file"],
|
|
90
|
+
upload: ["type"],
|
|
85
91
|
answer: ["response"],
|
|
86
92
|
act: ["note"],
|
|
87
93
|
inbox: [],
|
|
@@ -242,6 +248,14 @@ export function toRequest(argv) {
|
|
|
242
248
|
case "watch":
|
|
243
249
|
upTo(0);
|
|
244
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
|
+
}
|
|
245
259
|
case "search": {
|
|
246
260
|
const query = new URLSearchParams(compact({ q: words("query", p, "the words to search for"), area: f.area, status: f.status, limit: f.limit }));
|
|
247
261
|
return { method: "GET", path: `/v1/search?${query}` };
|
|
@@ -654,6 +668,46 @@ async function pair(input) {
|
|
|
654
668
|
console.log(JSON.stringify({ paired: true, kind: body.kind, agent: body.agent, harness, done, then: body.then }, null, 2));
|
|
655
669
|
return 0;
|
|
656
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
|
+
}
|
|
657
711
|
// One line per thing that should wake the chat: refs and Gavel's own words only, never a message's
|
|
658
712
|
// text, so the line itself is never someone else's instructions.
|
|
659
713
|
export function wakeLine(item) {
|
|
@@ -745,6 +799,8 @@ async function main(argvIn) {
|
|
|
745
799
|
}
|
|
746
800
|
if ("watch" in request)
|
|
747
801
|
return watch(token, as);
|
|
802
|
+
if ("upload" in request)
|
|
803
|
+
return upload(token, as, request.upload);
|
|
748
804
|
const base = (process.env.GAVEL_API_URL ?? "https://api.getgavel.ai").replace(/\/+$/, "");
|
|
749
805
|
const res = await fetch(base + request.path, {
|
|
750
806
|
method: request.method,
|
package/package.json
CHANGED