@getgavel/cli 0.1.3 → 0.1.4

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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/dist/gavel.js +150 -55
  3. 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
@@ -13,7 +13,7 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
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,18 @@ 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 answer <requestId> <response> answer an Ask someone
25
- gavel act <D-12> <note> what you did with the answer
24
+ gavel answer <requestId> (<response> | --response <words>)
25
+ answer an Ask someone
26
+ gavel act <D-12> (<note> | --note <words>)
27
+ what you did with the answer
26
28
  gavel inbox what's waiting on you
27
- gavel status <text> [--folders <a,b>] [--state working|blocked|idle] [--issue <MA-482>] [--waiting-on <email>]
29
+ gavel status (<text> | --text <words>) [--folders <a,b>] [--state working|blocked|idle] [--issue <MA-482>]
30
+ [--waiting-on <email>]
28
31
  what you're doing now, in plain words ("" clears it);
29
32
  --waiting-on names the person you're blocked on
30
- gavel message (--to-agent <id> | --to-person <email>) <text> [--decision <D-12>]
33
+ gavel message (--to-agent <id> | --to-person <email>) (<text> | --text <words>) [--decision <D-12>]
31
34
  start a conversation with another agent
32
- gavel message --conversation <C-12> <text>
35
+ gavel message --conversation <C-12> (<text> | --text <words>)
33
36
  reply in one
34
37
  gavel conversations [<C-12>] yours, or one with its messages (reads it)
35
38
  gavel wait-for-reply <C-12> [--timeout <seconds>]
@@ -40,6 +43,7 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
40
43
  background; one per agent)
41
44
  gavel log --question <q> --outcome <o> --reason <why> [--area <slug>] [--trust <id>] [--file context.json]
42
45
  gavel log-answer --question <q> --answer <what they decided> [--note <their why>] [--area <slug>]
46
+ [--file context.json]
43
47
  what your person answered you in chat, as theirs
44
48
  gavel decide <D-12> (--option <id> | --text <words>) [--note <words>]
45
49
  a multiple question: --option again for each pick,
@@ -47,29 +51,81 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
47
51
  gavel decide-for <D-12> (--option <id> | --text <words>) --reason <why> --trust <id>
48
52
  gavel priority <D-12> now|later [--note <words>]
49
53
  gavel forward <D-12> (--to-person <email> | --to-agent <id>) [--note <words>]
50
- gavel research-result <requestId> <response> [--file context.json]
54
+ gavel research-result <requestId> (<response> | --response <words>) [--file context.json]
51
55
  gavel agents you and your sub-agents
52
56
  gavel invite --name <name> [--description <words>] [--permissions ask,answer]
53
57
  gavel start-cloud-agent --name <task's name> --repo <url> --task <words> [--branch <ref>] [--open-pr true]
54
58
  [--machine <worker>] [--agent <agent id>]
55
59
  a Cursor cloud agent under you, for a task; --machine runs it on
56
60
  your person's own machine (My Machines), --agent starts an
57
- agent under you as itself (no --name), its old tokens ended
61
+ agent under you, or yourself, as itself (no --name), its
62
+ old tokens ended
58
63
  gavel me
59
64
 
60
65
  --as <name> on a fleet token, which chat you are (the name you go by,
61
66
  e.g. worker 35 or the task you're on; keep using the same one)
62
67
 
68
+ gavel <command> --help shows one command's usage. A command refuses a flag or a word it doesn't
69
+ take, and a flag given twice (but --option), with its usage.
63
70
  A text argument or --file of "-" is read from stdin.
64
71
  Environment: GAVEL_TOKEN (required), GAVEL_API_URL (default https://api.getgavel.ai),
65
72
  GAVEL_AGENT (instead of --as).`;
73
+ // What each command takes besides its words, as its usage above names them: anything else is
74
+ // refused with that usage, never dropped.
75
+ const FLAGS = {
76
+ pair: ["harness", "machine"],
77
+ search: ["query", "area", "status", "limit"],
78
+ ask: ["file"],
79
+ revise: ["file"],
80
+ todo: ["file"],
81
+ get: [],
82
+ wait: ["timeout"],
83
+ withdraw: ["reason"],
84
+ attach: ["file"],
85
+ answer: ["response"],
86
+ act: ["note"],
87
+ inbox: [],
88
+ status: ["text", "folders", "state", "issue", "waiting-on"],
89
+ message: ["to-agent", "to-person", "conversation", "text", "decision"],
90
+ conversations: [],
91
+ "wait-for-reply": ["timeout"],
92
+ watch: [],
93
+ log: ["question", "outcome", "reason", "area", "trust", "file"],
94
+ "log-answer": ["question", "answer", "note", "area", "file"],
95
+ decide: ["option", "text", "note"],
96
+ "decide-for": ["option", "text", "reason", "trust"],
97
+ priority: ["note"],
98
+ forward: ["to-person", "to-agent", "note"],
99
+ "research-result": ["response", "file"],
100
+ agents: [],
101
+ invite: ["name", "description", "permissions"],
102
+ "start-cloud-agent": ["name", "repo", "task", "branch", "open-pr", "machine", "agent"],
103
+ me: [],
104
+ };
105
+ const isCommand = (name) => Object.hasOwn(FLAGS, name);
106
+ // A command's own entries in USAGE: each line naming it, with the lines indented under it.
107
+ export function usageOf(command) {
108
+ const out = [];
109
+ let mine = false;
110
+ for (const line of USAGE.split("\n")) {
111
+ if (line.startsWith(" gavel "))
112
+ mine = line === ` gavel ${command}` || line.startsWith(` gavel ${command} `);
113
+ else if (!line.startsWith(" "))
114
+ mine = false;
115
+ if (mine)
116
+ out.push(line);
117
+ }
118
+ return out.join("\n");
119
+ }
66
120
  class UsageError extends Error {
67
121
  }
68
- export function parseArgs(argv) {
122
+ export function parseArgs(argv, command) {
69
123
  const positional = [];
70
124
  const flags = {};
71
125
  const lists = {};
72
126
  const set = (name, value) => {
127
+ if (Object.hasOwn(flags, name) && name !== "option")
128
+ throw new UsageError(`give --${name} once`);
73
129
  flags[name] = value;
74
130
  (lists[name] ??= []).push(value);
75
131
  };
@@ -77,13 +133,16 @@ export function parseArgs(argv) {
77
133
  const arg = argv[i];
78
134
  if (arg.startsWith("--")) {
79
135
  const eq = arg.indexOf("=");
136
+ const name = eq > 0 ? arg.slice(2, eq) : arg.slice(2);
137
+ if (!FLAGS[command].includes(name))
138
+ throw new UsageError(`${command} doesn't take --${name}`);
80
139
  if (eq > 0)
81
- set(arg.slice(2, eq), arg.slice(eq + 1));
140
+ set(name, arg.slice(eq + 1));
82
141
  else {
83
142
  const value = argv[i + 1];
84
143
  if (value === undefined || (value.startsWith("--") && value !== "-"))
85
144
  throw new UsageError(`${arg} needs a value`);
86
- set(arg.slice(2), value);
145
+ set(name, value);
87
146
  i++;
88
147
  }
89
148
  }
@@ -147,59 +206,101 @@ export function agentHeader(name) {
147
206
  const trimmed = name?.trim();
148
207
  return trimmed ? { "x-gavel-agent": encodeURIComponent(trimmed) } : {};
149
208
  }
150
- // A command line → one API request.
151
209
  export function toRequest(argv) {
152
210
  const [command, ...rest] = argv;
153
- const { positional: p, flags: f, lists } = parseArgs(rest);
211
+ if (command === undefined || command === "help" || command === "--help" || command === "-h") {
212
+ if (rest.length > 1)
213
+ throw new UsageError(`help takes one command, not "${rest[1]}"`);
214
+ if (rest[0] === undefined)
215
+ return { help: USAGE };
216
+ if (!isCommand(rest[0]))
217
+ throw new UsageError(`unknown command "${rest[0]}"`);
218
+ return { help: usageOf(rest[0]) };
219
+ }
220
+ if (!isCommand(command))
221
+ throw new UsageError(`unknown command "${command}"`);
222
+ if (rest.includes("--help") || rest.includes("-h"))
223
+ return { help: usageOf(command) };
224
+ const { positional: p, flags: f, lists } = parseArgs(rest, command);
225
+ const upTo = (n) => {
226
+ if (p.length > n)
227
+ throw new UsageError(`${command} doesn't take "${p[n]}"`);
228
+ };
229
+ // A command's words may come as their flag instead (act's --note), never both.
230
+ const words = (flag, from, what) => {
231
+ if (f[flag] !== undefined && from.length)
232
+ throw new UsageError(`give ${what} once: as words or as --${flag}`);
233
+ return need(f[flag] ?? from.join(" "), what);
234
+ };
154
235
  switch (command) {
155
- case undefined:
156
- case "help":
157
- case "--help":
158
- case "-h":
159
- return "help";
236
+ case "pair": {
237
+ const harness = f.harness;
238
+ if (harness !== undefined && !HARNESSES.includes(harness))
239
+ throw new UsageError(`--harness is one of ${HARNESSES.join(", ")}`);
240
+ return { pair: { code: need(p.join(""), "the pairing code (like 4F7K-9QX2)"), harness, machine: f.machine } };
241
+ }
242
+ case "watch":
243
+ upTo(0);
244
+ return { watch: true };
160
245
  case "search": {
161
- const query = new URLSearchParams(compact({ q: need(p.join(" "), "the words to search for"), area: f.area, status: f.status, limit: f.limit }));
246
+ const query = new URLSearchParams(compact({ q: words("query", p, "the words to search for"), area: f.area, status: f.status, limit: f.limit }));
162
247
  return { method: "GET", path: `/v1/search?${query}` };
163
248
  }
164
249
  case "ask":
250
+ upTo(0);
165
251
  return { method: "POST", path: "/v1/decisions", body: readJson(need(f.file, "--file decision.json")) };
166
252
  case "revise":
253
+ upTo(1);
167
254
  return { method: "POST", path: `/v1/decisions/${ref(p[0])}/revise`, body: readJson(need(f.file, "--file decision.json")) };
168
255
  case "todo":
256
+ upTo(0);
169
257
  return { method: "POST", path: "/v1/todos", body: readJson(need(f.file, "--file todo.json")) };
170
258
  case "get":
259
+ upTo(1);
171
260
  return { method: "GET", path: `/v1/decisions/${ref(p[0])}` };
172
261
  case "wait":
262
+ upTo(1);
173
263
  return { method: "GET", path: `/v1/decisions/${ref(p[0])}/wait?timeout=${encodeURIComponent(f.timeout ?? "60")}` };
174
264
  case "withdraw":
265
+ upTo(1);
175
266
  return { method: "POST", path: `/v1/decisions/${ref(p[0])}/withdraw`, body: compact({ reason: f.reason && readText(f.reason) }) };
176
267
  case "attach":
268
+ upTo(1);
177
269
  return { method: "POST", path: `/v1/decisions/${ref(p[0])}/context`, body: { items: contextList(need(f.file, "--file context.json")) } };
178
270
  case "answer":
179
- return { method: "POST", path: `/v1/requests/${encodeURIComponent(need(p[0], "the request id"))}/answer`, body: { response: readText(need(p.slice(1).join(" "), "the response")) } };
271
+ 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
272
  case "act":
181
- return { method: "POST", path: `/v1/decisions/${ref(p[0])}/act`, body: { note: readText(need(p.slice(1).join(" "), "the note")) } };
273
+ return { method: "POST", path: `/v1/decisions/${ref(p[0])}/act`, body: { note: readText(words("note", p.slice(1), "the note")) } };
182
274
  case "inbox":
275
+ upTo(0);
183
276
  return { method: "GET", path: "/v1/inbox" };
184
277
  case "status": {
185
- if (!p.length)
278
+ if (f.text !== undefined && p.length)
279
+ throw new UsageError("give what you're doing once: as words or as --text");
280
+ const said = f.text ?? (p.length ? p.join(" ") : undefined);
281
+ if (said === undefined)
186
282
  throw new UsageError('missing what you\'re doing now (or "" to clear it)');
187
283
  const folders = f.folders?.split(",").map((s) => s.trim()).filter(Boolean);
188
- return { method: "PATCH", path: "/v1/agents/me/status", body: compact({ text: readText(p.join(" ")) || null, folders, state: f.state, linearIssue: f.issue, waitingOn: f["waiting-on"] }) };
284
+ 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
285
  }
190
286
  case "message": {
191
- const text = readText(need(p.join(" "), "what to say"));
287
+ const text = readText(words("text", p, "what to say"));
192
288
  if ([f.conversation, f["to-agent"], f["to-person"]].filter(Boolean).length !== 1)
193
289
  throw new UsageError("give --to-agent or --to-person to start a conversation, or --conversation to reply in one");
290
+ if (f.conversation && f.decision !== undefined)
291
+ throw new UsageError("--decision is only for starting a conversation");
194
292
  if (f.conversation)
195
293
  return { method: "POST", path: `/v1/conversations/${encodeURIComponent(f.conversation)}/messages`, body: { text } };
196
294
  return { method: "POST", path: "/v1/conversations", body: compact({ toAgentId: f["to-agent"], toPerson: f["to-person"], text, decision: f.decision }) };
197
295
  }
198
296
  case "conversations":
297
+ upTo(1);
199
298
  return { method: "GET", path: p[0] ? `/v1/conversations/${encodeURIComponent(p[0])}` : "/v1/conversations" };
200
299
  case "wait-for-reply":
300
+ upTo(1);
201
301
  return { method: "GET", path: `/v1/conversations/${encodeURIComponent(need(p[0], "the conversation (C-12)"))}/wait?timeout=${encodeURIComponent(f.timeout ?? "60")}` };
202
302
  case "log":
303
+ upTo(0);
203
304
  return {
204
305
  method: "POST",
205
306
  path: "/v1/decided",
@@ -213,42 +314,50 @@ export function toRequest(argv) {
213
314
  }),
214
315
  };
215
316
  case "log-answer":
317
+ upTo(0);
216
318
  return {
217
319
  method: "POST",
218
320
  path: "/v1/decided/answers",
219
321
  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
322
  };
221
323
  case "decide":
324
+ upTo(1);
222
325
  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
326
  case "decide-for":
327
+ upTo(1);
224
328
  return {
225
329
  method: "POST",
226
330
  path: `/v1/decisions/${ref(p[0])}/decide-for`,
227
331
  body: compact({ ...picks(lists.option), text: f.text && readText(f.text), reason: readText(need(f.reason, "--reason")), trustId: need(f.trust, "--trust") }),
228
332
  };
229
333
  case "priority": {
334
+ upTo(2);
230
335
  const priority = need(p[1], "now or later");
231
336
  if (priority !== "now" && priority !== "later")
232
337
  throw new UsageError("the priority is now or later");
233
338
  return { method: "POST", path: `/v1/decisions/${ref(p[0])}/priority`, body: compact({ priority, note: f.note }) };
234
339
  }
235
340
  case "forward":
341
+ upTo(1);
236
342
  return { method: "POST", path: `/v1/decisions/${ref(p[0])}/forward`, body: compact({ toPerson: f["to-person"], toAgentId: f["to-agent"], note: f.note }) };
237
343
  case "research-result":
238
344
  return {
239
345
  method: "POST",
240
346
  path: `/v1/requests/${encodeURIComponent(need(p[0], "the request id"))}/research-result`,
241
- body: compact({ response: readText(need(p.slice(1).join(" "), "the response")), context: contextList(f.file) }),
347
+ body: compact({ response: readText(words("response", p.slice(1), "the response")), context: contextList(f.file) }),
242
348
  };
243
349
  case "agents":
350
+ upTo(0);
244
351
  return { method: "GET", path: "/v1/agents" };
245
352
  case "invite":
353
+ upTo(0);
246
354
  return {
247
355
  method: "POST",
248
356
  path: "/v1/sub-agents",
249
357
  body: compact({ name: need(f.name, "--name"), description: f.description, permissions: f.permissions?.split(",").map((s) => s.trim()) }),
250
358
  };
251
359
  case "start-cloud-agent":
360
+ upTo(0);
252
361
  return {
253
362
  method: "POST",
254
363
  path: "/v1/cloud-agents",
@@ -263,6 +372,7 @@ export function toRequest(argv) {
263
372
  }),
264
373
  };
265
374
  case "me":
375
+ upTo(0);
266
376
  return { method: "GET", path: "/v1/me" };
267
377
  default:
268
378
  throw new UsageError(`unknown command "${command}"`);
@@ -513,12 +623,8 @@ export async function dropLegacy(setup, legacy, opts) {
513
623
  return [`left the old ${legacy.server} entry in ${old.where}: its token still works (another workspace's or agent's)`];
514
624
  return [`left the old ${legacy.server} entry in ${old.where}: couldn't check its token`];
515
625
  }
516
- async function pair(argv) {
517
- const { positional, flags } = parseArgs(argv);
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(", ")}`);
626
+ async function pair(input) {
627
+ const harness = input.harness ?? detectHarness(process.env);
522
628
  if (harness === "claude-code" && !runs("claude")) {
523
629
  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
630
  return 1;
@@ -527,7 +633,7 @@ async function pair(argv) {
527
633
  const res = await fetch(`${base}/v1/pair`, {
528
634
  method: "POST",
529
635
  headers: { "content-type": "application/json", accept: "application/json" },
530
- body: JSON.stringify({ code, harness, machine: flags.machine ?? hostname().split(".")[0] }),
636
+ body: JSON.stringify({ code: input.code, harness, machine: input.machine ?? hostname().split(".")[0] }),
531
637
  });
532
638
  const body = (await res.json().catch(() => ({})));
533
639
  if (!res.ok) {
@@ -611,45 +717,34 @@ async function watch(token, as) {
611
717
  async function main(argvIn) {
612
718
  let request;
613
719
  let as = null;
614
- if (argvIn[0] === "pair") {
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
- }
720
+ let command;
627
721
  try {
628
722
  const taken = takeAs(argvIn);
629
- as = taken.as ?? process.env.GAVEL_AGENT ?? null;
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
- }
723
+ command = taken.argv[0];
636
724
  request = toRequest(taken.argv);
725
+ if ("pair" in request && taken.as !== null)
726
+ throw new UsageError("pair doesn't take --as: a code pairs the agent it was made for");
727
+ as = taken.as ?? process.env.GAVEL_AGENT ?? null;
637
728
  }
638
729
  catch (err) {
639
730
  if (!(err instanceof UsageError))
640
731
  throw err;
641
- console.error(`gavel: ${err.message}\n\n${USAGE}`);
732
+ console.error(`gavel: ${err.message}\n\n${command !== undefined && isCommand(command) ? usageOf(command) : USAGE}`);
642
733
  return 2;
643
734
  }
644
- if (request === "help") {
645
- console.log(USAGE);
735
+ if ("help" in request) {
736
+ console.log(request.help);
646
737
  return 0;
647
738
  }
739
+ if ("pair" in request)
740
+ return pair(request.pair);
648
741
  const token = process.env.GAVEL_TOKEN;
649
742
  if (!token) {
650
743
  console.error("gavel: set GAVEL_TOKEN to your agent token (gvl_agent_…)");
651
744
  return 2;
652
745
  }
746
+ if ("watch" in request)
747
+ return watch(token, as);
653
748
  const base = (process.env.GAVEL_API_URL ?? "https://api.getgavel.ai").replace(/\/+$/, "");
654
749
  const res = await fetch(base + request.path, {
655
750
  method: request.method,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getgavel/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "The gavel command: an agent's Gavel from a shell (pair, ask, wait, watch and the rest)",
5
5
  "license": "UNLICENSED",
6
6
  "homepage": "https://getgavel.ai/agents",