@getgavel/cli 0.1.9 → 0.1.11

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 +19 -1
  2. package/dist/gavel.js +530 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -41,14 +41,32 @@ gavel act --help # one command's usage
41
41
  ## For your person
42
42
 
43
43
  Once your person lets you, their personal agent, do what they can in Gavel (Settings › Agents,
44
- "Can do what you can in Gavel"), you act on their decisions as them:
44
+ "Can do what you can in Gavel"), you act as them: on their decisions, settings, trusts, agents,
45
+ Blockers and workspace, as far as their role goes. What stays theirs by hand (a key, connecting a
46
+ service, an Owner) comes back as a to-do to ask them.
45
47
 
46
48
  ```sh
47
49
  gavel my-queue # their queue
48
50
  gavel decide-mine D-12 --option <id> --their-words "ship it" # only on their word, from your chat
49
51
  gavel boomerang D-12 # forward-mine, research-more, ask-someone, defer, undo…
52
+ gavel set-my-day --day-start 09:00 --day-end 18:00 # their day, alerts, reports and trusts
53
+ gavel move-agent-mine <agent id> --under <agent id> # their agents: edit, pause, archive…
54
+ gavel my-blockers # what's stuck; nudge-mine, reassign
55
+ gavel invite-person --email gia@acme.com # their workspace: roles, areas, boards…
56
+ gavel call GET /v1/me --for-person true # any route, as you or as them
50
57
  ```
51
58
 
59
+ ## In GitHub Actions
60
+
61
+ A job with `permissions: id-token: write` needs no pasted token: the command trades GitHub's token
62
+ for the run's own, once a person has let the repository's runs ask under one of their agents
63
+ (Settings › Agents). `gavel actions-env` writes it, masked, as `GAVEL_TOKEN` for the job's later
64
+ steps, for an agent there that speaks MCP. Name the run by its task with `GAVEL_AGENT` (or `--as`):
65
+ a run of the same task later comes back as the same agent. Without one, Gavel names it by the
66
+ workflow and run number.
67
+
68
+ Each command ends, on stderr, with what's waiting for you in Gavel when something is.
69
+
52
70
  ## Your Claude Code or Codex chat, in Gavel
53
71
 
54
72
  If your agent works in Claude Code or Codex on your laptop, run this in its folder, in a terminal
package/dist/gavel.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  // The `gavel` command-line tool: the MCP server's operations over the HTTP API, for agents that
3
3
  // prefer a shell. GAVEL_TOKEN (an agent's token) and GAVEL_API_URL (default https://api.getgavel.ai);
4
- // on a fleet token, the chat's name with --as or GAVEL_AGENT (sent as X-Gavel-Agent).
4
+ // on a fleet token, the chat's name with --as or GAVEL_AGENT (sent as X-Gavel-Agent). In a GitHub
5
+ // Actions job with id-token: write and no GAVEL_TOKEN, the run's own token, traded for GitHub's.
5
6
  // Prints the API's JSON; on an error, prints it to stderr and exits 1.
6
7
  import { execFileSync } from "node:child_process";
7
8
  import { createHash, randomUUID } from "node:crypto";
@@ -23,6 +24,9 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
23
24
  the words it would send from the newest session here; sends
24
25
  nothing
25
26
  gavel bridge wake [--server <name>] the bridge's wake hook, which Claude Code runs (not by hand)
27
+ gavel actions-env in a GitHub Actions job with id-token: write, GAVEL_TOKEN
28
+ for its next steps: the run's own token, traded for
29
+ GitHub's and masked (never printed)
26
30
  gavel search (<words> | --query <words>) [--area <slug>] [--status open|decided|any] [--limit <n>]
27
31
  gavel ask --file decision.json the decision, as MCP ask's input
28
32
  gavel revise <D-12> --file decision.json a draft the editor sent back, fixed (the whole ask again)
@@ -100,6 +104,12 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
100
104
  your person's own machine (My Machines), --agent starts an
101
105
  agent under you, or yourself, as itself (no --name), its
102
106
  old tokens ended
107
+ gavel move-agent <agent id> --under <agent id>
108
+ an agent below you, with what's under it, under you or
109
+ another agent below you
110
+ gavel call <GET|POST|PUT|PATCH|DELETE> </v1/path> [--query <name=value>] [--body <file.json>]
111
+ [--for-person true] any route of the API as you, or as your person with
112
+ --for-person: MCP's do_action, the answer as it comes
103
113
  gavel me
104
114
  gavel my-queue [--view mine|asked|decided] [--before <time>] [--limit <n>]
105
115
  your person's queue, what they asked, or their Decided
@@ -124,22 +134,91 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
124
134
  gavel overrule <D-12> [--text <words> --their-words <words>] [--note <words>]
125
135
  what one of their agents decided: their own decision
126
136
  instead, or reopened in their queue
137
+ gavel my-settings your person's day, alerts, weekly report and Slack messages
138
+ gavel set-my-day [--timezone <zone>] [--day-start <HH:MM>] [--day-end <HH:MM>] [--morning <HH:MM>]
139
+ [--later-every <minutes>] when Now alerts may reach them, their morning, Later's pace
140
+ gavel set-my-alerts [--on-call true|false] [--sounds all|now|off] [--sound <name>]
141
+ [--later-like-now true|false] [--muted true|false] [--workspace-sound <name>|none]
142
+ [--snooze-until <time>|none]
143
+ gavel set-my-reports [--weekly-report true|false] [--slack-messages true|false]
144
+ gavel my-notifications [--limit <n>] what went out to them, and how many are unread
145
+ gavel mark-notification-read <id>
146
+ gavel my-weekly-report
147
+ gavel my-trusts what their agents decide without asking them
148
+ gavel add-trust --agent <id> --words <plain words> [--area <id>]
149
+ for one of their own agents
150
+ gavel edit-trust <trust id> [--words <plain words>] [--area <id>|none]
151
+ gavel revoke-trust <trust id>
152
+ gavel trust-decisions <trust id>
153
+ gavel trust-suggestions <D-12> Defer to my agent's ready-made trusts for a decision
154
+ gavel my-agents your person's agents and their sub-agents
155
+ gavel edit-agent <agent id> [--name <name>] [--title <title>|none] [--description <words>]
156
+ gavel show-agent <agent id> --visible true|false
157
+ shown to the workspace, or hidden, with what's under it
158
+ gavel pause-agent <agent id> [--paused true|false]
159
+ paused (the default), or resumed with --paused false
160
+ gavel set-agent-permissions <agent id> [--permissions <ask,answer>] [--may-invite true|false]
161
+ [--may-ask-person true|false]
162
+ gavel add-sub-agent <parent agent id> --name <name> [--description <words>] [--permissions <ask,answer>]
163
+ no token: your person pairs it by hand
164
+ gavel move-agent-mine <agent id> --under <agent id>
165
+ one of theirs, with what's under it, under another of theirs
166
+ gavel archive-agent <agent id> a sub-agent, back as it was on its next call
167
+ gavel remove-agent <agent id> --their-words <words>
168
+ an agent and everything under it, for good: only on
169
+ their word
170
+ gavel my-blockers what's stuck, as Blockers shows your person
171
+ gavel nudge-mine <D-12> its decider, for them: once a day, when it blocks them
172
+ gavel reassign <D-12> (--to-person <email> | --to-agent <id>) [--note <words>]
173
+ a stuck decision to someone else, for them: an Admin's
174
+ gavel workspace-settings its name, triage person, depth and untrusted areas
175
+ gavel edit-workspace [--name <name>] [--triage-person <person id>|none] [--sub-agent-depth <n>]
176
+ [--never-trusted <area id,area id>|none]
177
+ Admins and Owners; only what you give changes
178
+ gavel workspace-people everyone, with their role
179
+ gavel set-role <person id> --role owner|admin|member
180
+ as far as their role goes; an Owner's stays theirs by hand
181
+ gavel invitations the open ones
182
+ gavel invite-person --email <email> [--role admin|member]
183
+ gavel email-invitation-again <invitation id>
184
+ gavel take-back-invitation <invitation id>
185
+ gavel invite-link the link, and who it lets in
186
+ gavel reset-invite-link Admins and Owners: the old one stops letting anyone in
187
+ gavel set-invite-link-rule --mode off|anyone|domains [--domains <a.com,b.com>]
188
+ Owners: who it lets in
189
+ gavel workspace-areas the areas, their owners and code paths
190
+ gavel add-area --slug <slug> --name <name> [--description <words>] [--owner <email or id>]
191
+ [--code-paths <a/,b/>] Admins and Owners
192
+ gavel edit-area <area id> [--slug <slug>] [--name <name>] [--description <words>]
193
+ [--owner <email or id>|none] [--code-paths <a/,b/>]
194
+ gavel area-suggestions [--fresh true] what CODEOWNERS suggests, to confirm or dismiss
195
+ gavel confirm-area-suggestion <suggestion id>
196
+ gavel dismiss-area-suggestion <suggestion id>
197
+ gavel linear-teams the Linear teams a board can show
198
+ gavel add-linear-board <team id>
199
+ gavel remove-linear-board <team id> Linear keeps its issues
200
+ gavel workspace-logo the logo, and the ones its connections offer
201
+ gavel set-workspace-logo slack|github|linear|none
202
+ gavel workspace-connections what's connected, never a key; keys stay your person's
127
203
 
128
204
  --as <name> on a fleet token, which chat you are (the name you go by,
129
205
  e.g. worker 35 or the task you're on; keep using the same one)
130
206
 
131
207
  gavel <command> --help shows one command's usage. A command refuses a flag or a word it doesn't
132
- take, and a flag given twice (but --option), with its usage.
133
- The commands from my-queue to overrule act for your person, as them, once they've let you
208
+ take, and a flag given twice (but --option, --code, --label and --query), with its usage.
209
+ The commands from my-queue to workspace-connections act for your person, as them, once they've let you
134
210
  (Settings › Agents); each goes with X-Gavel-For-Person.
135
211
  A text argument or --file of "-" is read from stdin.
136
- Environment: GAVEL_TOKEN (required), GAVEL_API_URL (default https://api.getgavel.ai),
137
- GAVEL_AGENT (instead of --as).`;
212
+ Environment: GAVEL_TOKEN (required, but a GitHub Actions job with id-token: write trades GitHub's
213
+ token for the run's own, named by --as or GAVEL_AGENT), GAVEL_API_URL (default
214
+ https://api.getgavel.ai), GAVEL_AGENT (instead of --as), GAVEL_WORKSPACE (a run's workspace, only
215
+ when its repository asks in more than one).`;
138
216
  // What each command takes besides its words, as its usage above names them: anything else is
139
217
  // refused with that usage, never dropped.
140
218
  const FLAGS = {
141
219
  pair: ["harness", "machine"],
142
220
  bridge: ["harness", "server"],
221
+ "actions-env": [],
143
222
  search: ["query", "area", "status", "limit"],
144
223
  ask: ["file"],
145
224
  revise: ["file"],
@@ -169,6 +248,8 @@ const FLAGS = {
169
248
  agents: [],
170
249
  invite: ["name", "description", "permissions"],
171
250
  "start-cloud-agent": ["name", "repo", "task", "branch", "open-pr", "machine", "agent"],
251
+ "move-agent": ["under"],
252
+ call: ["query", "body", "for-person"],
172
253
  me: [],
173
254
  "my-queue": ["view", "before", "limit"],
174
255
  "decide-mine": ["option", "text", "note", "their-words"],
@@ -182,10 +263,119 @@ const FLAGS = {
182
263
  "todo-cant": ["reason", "their-words"],
183
264
  "decided-without-you": ["date"],
184
265
  overrule: ["text", "note", "their-words"],
266
+ "my-settings": [],
267
+ "set-my-day": ["timezone", "day-start", "day-end", "morning", "later-every"],
268
+ "set-my-alerts": ["on-call", "sounds", "sound", "later-like-now", "muted", "workspace-sound", "snooze-until"],
269
+ "set-my-reports": ["weekly-report", "slack-messages"],
270
+ "my-notifications": ["limit"],
271
+ "mark-notification-read": [],
272
+ "my-weekly-report": [],
273
+ "my-trusts": [],
274
+ "add-trust": ["agent", "words", "area"],
275
+ "edit-trust": ["words", "area"],
276
+ "revoke-trust": [],
277
+ "trust-decisions": [],
278
+ "trust-suggestions": [],
279
+ "my-agents": [],
280
+ "edit-agent": ["name", "title", "description"],
281
+ "show-agent": ["visible"],
282
+ "pause-agent": ["paused"],
283
+ "set-agent-permissions": ["permissions", "may-invite", "may-ask-person"],
284
+ "add-sub-agent": ["name", "description", "permissions"],
285
+ "move-agent-mine": ["under"],
286
+ "archive-agent": [],
287
+ "remove-agent": ["their-words"],
288
+ "my-blockers": [],
289
+ "nudge-mine": [],
290
+ reassign: ["to-person", "to-agent", "note"],
291
+ "workspace-settings": [],
292
+ "edit-workspace": ["name", "triage-person", "sub-agent-depth", "never-trusted"],
293
+ "workspace-people": [],
294
+ "set-role": ["role"],
295
+ invitations: [],
296
+ "invite-person": ["email", "role"],
297
+ "email-invitation-again": [],
298
+ "take-back-invitation": [],
299
+ "invite-link": [],
300
+ "reset-invite-link": [],
301
+ "set-invite-link-rule": ["mode", "domains"],
302
+ "workspace-areas": [],
303
+ "add-area": ["slug", "name", "description", "owner", "code-paths"],
304
+ "edit-area": ["slug", "name", "description", "owner", "code-paths"],
305
+ "area-suggestions": ["fresh"],
306
+ "confirm-area-suggestion": [],
307
+ "dismiss-area-suggestion": [],
308
+ "linear-teams": [],
309
+ "add-linear-board": [],
310
+ "remove-linear-board": [],
311
+ "workspace-logo": [],
312
+ "set-workspace-logo": [],
313
+ "workspace-connections": [],
185
314
  };
186
315
  // Your person's own actions, sent as them (X-Gavel-For-Person) once they've let you act for them
187
316
  // (D-911): the MCP tools' names.
188
- const FOR_PERSON = ["my-queue", "decide-mine", "forward-mine", "boomerang", "research-more", "ask-someone", "defer", "undo", "todo-done", "todo-cant", "decided-without-you", "overrule"];
317
+ const FOR_PERSON = [
318
+ "my-queue",
319
+ "decide-mine",
320
+ "forward-mine",
321
+ "boomerang",
322
+ "research-more",
323
+ "ask-someone",
324
+ "defer",
325
+ "undo",
326
+ "todo-done",
327
+ "todo-cant",
328
+ "decided-without-you",
329
+ "overrule",
330
+ "my-settings",
331
+ "set-my-day",
332
+ "set-my-alerts",
333
+ "set-my-reports",
334
+ "my-notifications",
335
+ "mark-notification-read",
336
+ "my-weekly-report",
337
+ "my-trusts",
338
+ "add-trust",
339
+ "edit-trust",
340
+ "revoke-trust",
341
+ "trust-decisions",
342
+ "trust-suggestions",
343
+ "my-agents",
344
+ "edit-agent",
345
+ "show-agent",
346
+ "pause-agent",
347
+ "set-agent-permissions",
348
+ "add-sub-agent",
349
+ "move-agent-mine",
350
+ "archive-agent",
351
+ "remove-agent",
352
+ "my-blockers",
353
+ "nudge-mine",
354
+ "reassign",
355
+ "workspace-settings",
356
+ "edit-workspace",
357
+ "workspace-people",
358
+ "set-role",
359
+ "invitations",
360
+ "invite-person",
361
+ "email-invitation-again",
362
+ "take-back-invitation",
363
+ "invite-link",
364
+ "reset-invite-link",
365
+ "set-invite-link-rule",
366
+ "workspace-areas",
367
+ "add-area",
368
+ "edit-area",
369
+ "area-suggestions",
370
+ "confirm-area-suggestion",
371
+ "dismiss-area-suggestion",
372
+ "linear-teams",
373
+ "add-linear-board",
374
+ "remove-linear-board",
375
+ "workspace-logo",
376
+ "set-workspace-logo",
377
+ "workspace-connections",
378
+ ];
189
379
  const isCommand = (name) => Object.hasOwn(FLAGS, name);
190
380
  // A command's own entries in USAGE: each line naming it, with the lines indented under it.
191
381
  export function usageOf(command) {
@@ -205,7 +395,7 @@ class UsageError extends Error {
205
395
  }
206
396
  // Only --option (a multiple question's picks), --code and --label (a work item's commits and pull
207
397
  // requests, and its labels) may come again: `flags` holds each flag's value and `lists` every one given.
208
- const REPEATABLE = ["option", "code", "label"];
398
+ const REPEATABLE = ["option", "code", "label", "query"];
209
399
  export function parseArgs(argv, command) {
210
400
  const positional = [];
211
401
  const flags = {};
@@ -305,6 +495,22 @@ function personRequest(command, p, f, options) {
305
495
  const theirWords = () => readText(need(f["their-words"], "--their-words: what your person said in your chat that decides it"));
306
496
  const list = (value) => value?.split(",").map((s) => s.trim()).filter(Boolean) ?? [];
307
497
  const asThem = (method, path, body) => ({ method, path, ...(body ? { body: compact(body) } : {}), forPerson: true });
498
+ const yesNo = (flag) => {
499
+ const v = f[flag];
500
+ if (v === undefined)
501
+ return undefined;
502
+ if (v !== "true" && v !== "false")
503
+ throw new UsageError(`--${flag} is true or false`);
504
+ return v === "true";
505
+ };
506
+ const orNone = (flag) => (f[flag] === undefined ? undefined : f[flag] === "none" ? null : f[flag]);
507
+ const changes = (body) => {
508
+ const set = compact(body);
509
+ if (!Object.keys(set).length)
510
+ throw new UsageError(`${command} needs something to change`);
511
+ return asThem("PATCH", "/v1/me", set);
512
+ };
513
+ const id = (what) => encodeURIComponent(need(p[0], what));
308
514
  switch (command) {
309
515
  case "my-queue": {
310
516
  upTo(0);
@@ -351,6 +557,224 @@ function personRequest(command, p, f, options) {
351
557
  case "overrule":
352
558
  upTo(1);
353
559
  return asThem("POST", `/v1/decisions/${ref(p[0])}/overrule`, { text: f.text && readText(f.text), note: f.note, theirWords: f["their-words"] && readText(f["their-words"]) });
560
+ case "my-settings":
561
+ upTo(0);
562
+ return asThem("GET", "/v1/me");
563
+ case "set-my-day": {
564
+ upTo(0);
565
+ const later = f["later-every"] === undefined ? undefined : Number(f["later-every"]);
566
+ if (later !== undefined && !Number.isInteger(later))
567
+ throw new UsageError("--later-every is a number of minutes");
568
+ return changes({ timezone: f.timezone, dayStart: f["day-start"], dayEnd: f["day-end"], morningTime: f.morning, laterEveryMinutes: later });
569
+ }
570
+ case "set-my-alerts":
571
+ upTo(0);
572
+ return changes({
573
+ onCall: yesNo("on-call"),
574
+ sounds: f.sounds,
575
+ alertSound: f.sound,
576
+ laterLikeNow: yesNo("later-like-now"),
577
+ muted: yesNo("muted"),
578
+ workspaceSound: orNone("workspace-sound"),
579
+ snoozedUntil: orNone("snooze-until"),
580
+ });
581
+ case "set-my-reports":
582
+ upTo(0);
583
+ return changes({ weeklyReport: yesNo("weekly-report"), slackMessages: yesNo("slack-messages") });
584
+ case "my-notifications":
585
+ upTo(0);
586
+ return asThem("GET", `/v1/notifications${f.limit ? `?limit=${encodeURIComponent(f.limit)}` : ""}`);
587
+ case "mark-notification-read":
588
+ upTo(1);
589
+ return asThem("POST", `/v1/notifications/${id("the notification's id")}/read`);
590
+ case "my-weekly-report":
591
+ upTo(0);
592
+ return asThem("GET", "/v1/weekly-report");
593
+ case "my-trusts":
594
+ upTo(0);
595
+ return asThem("GET", "/v1/trusts");
596
+ case "add-trust":
597
+ upTo(0);
598
+ return asThem("POST", "/v1/trusts", { agentId: need(f.agent, "--agent"), plainWords: readText(need(f.words, "--words")), areaId: f.area });
599
+ case "edit-trust": {
600
+ upTo(1);
601
+ const trust = id("the trust's id");
602
+ const body = compact({ plainWords: f.words && readText(f.words), areaId: orNone("area") });
603
+ if (!Object.keys(body).length)
604
+ throw new UsageError("edit-trust needs --words or --area");
605
+ return asThem("PATCH", `/v1/trusts/${trust}`, body);
606
+ }
607
+ case "revoke-trust":
608
+ upTo(1);
609
+ return asThem("DELETE", `/v1/trusts/${id("the trust's id")}`);
610
+ case "trust-decisions":
611
+ upTo(1);
612
+ return asThem("GET", `/v1/trusts/${id("the trust's id")}/decisions`);
613
+ case "trust-suggestions":
614
+ upTo(1);
615
+ return asThem("GET", `/v1/trusts/suggestions?decision=${ref(p[0])}`);
616
+ case "my-agents":
617
+ upTo(0);
618
+ return asThem("GET", "/v1/agents");
619
+ case "edit-agent": {
620
+ upTo(1);
621
+ const agent = id("the agent's id");
622
+ const body = compact({ name: f.name, title: orNone("title"), description: f.description && readText(f.description) });
623
+ if (!Object.keys(body).length)
624
+ throw new UsageError("edit-agent needs --name, --title or --description");
625
+ return asThem("PATCH", `/v1/agents/${agent}`, body);
626
+ }
627
+ case "show-agent": {
628
+ upTo(1);
629
+ const agent = id("the agent's id");
630
+ const visible = yesNo("visible");
631
+ if (visible === undefined)
632
+ throw new UsageError("show-agent needs --visible true or false");
633
+ return asThem("PATCH", `/v1/agents/${agent}`, { visibleToOrg: visible });
634
+ }
635
+ case "pause-agent": {
636
+ upTo(1);
637
+ const agent = id("the agent's id");
638
+ return asThem("PATCH", `/v1/agents/${agent}`, { status: yesNo("paused") === false ? "active" : "paused" });
639
+ }
640
+ case "set-agent-permissions": {
641
+ upTo(1);
642
+ const agent = id("the agent's id");
643
+ const body = compact({ permissions: f.permissions === undefined ? undefined : list(f.permissions), mayInvite: yesNo("may-invite"), mayAskPersonDirectly: yesNo("may-ask-person") });
644
+ if (!Object.keys(body).length)
645
+ throw new UsageError("set-agent-permissions needs --permissions, --may-invite or --may-ask-person");
646
+ return asThem("PATCH", `/v1/agents/${agent}`, body);
647
+ }
648
+ case "add-sub-agent": {
649
+ upTo(1);
650
+ const parent = id("the agent to add it under");
651
+ return asThem("POST", `/v1/agents/${parent}/sub-agents`, {
652
+ name: need(f.name, "--name"),
653
+ description: f.description && readText(f.description),
654
+ permissions: f.permissions === undefined ? undefined : list(f.permissions),
655
+ });
656
+ }
657
+ case "move-agent-mine":
658
+ upTo(1);
659
+ return asThem("PATCH", `/v1/agents/${id("the agent's id")}`, { parentAgentId: need(f.under, "--under") });
660
+ case "archive-agent":
661
+ upTo(1);
662
+ return asThem("POST", `/v1/agents/${id("the agent's id")}/archive`);
663
+ case "remove-agent":
664
+ upTo(1);
665
+ return asThem("DELETE", `/v1/agents/${id("the agent's id")}`, { theirWords: theirWords() });
666
+ case "my-blockers":
667
+ upTo(0);
668
+ return asThem("GET", "/v1/blockers");
669
+ case "nudge-mine":
670
+ upTo(1);
671
+ return asThem("POST", `/v1/decisions/${ref(p[0])}/nudge`);
672
+ case "reassign":
673
+ upTo(1);
674
+ return asThem("POST", `/v1/decisions/${ref(p[0])}/reassign`, { toPerson: f["to-person"], toAgentId: f["to-agent"], note: f.note });
675
+ case "workspace-settings":
676
+ upTo(0);
677
+ return asThem("GET", "/v1/workspace");
678
+ case "edit-workspace": {
679
+ upTo(0);
680
+ const depth = f["sub-agent-depth"];
681
+ if (depth !== undefined && !/^\d+$/.test(depth))
682
+ throw new UsageError("--sub-agent-depth is a number");
683
+ const untrusted = f["never-trusted"];
684
+ const body = compact({
685
+ name: f.name,
686
+ triagePersonId: orNone("triage-person"),
687
+ subAgentMaxDepth: depth === undefined ? undefined : Number(depth),
688
+ neverTrustableAreaIds: untrusted === undefined ? undefined : untrusted === "none" ? [] : list(untrusted),
689
+ });
690
+ if (!Object.keys(body).length)
691
+ throw new UsageError("edit-workspace needs something to change");
692
+ return asThem("PATCH", "/v1/workspace", body);
693
+ }
694
+ case "workspace-people":
695
+ upTo(0);
696
+ return asThem("GET", "/v1/workspace/people");
697
+ case "set-role":
698
+ upTo(1);
699
+ return asThem("PATCH", `/v1/workspace/people/${id("the person's id")}`, { role: need(f.role, "--role") });
700
+ case "invitations":
701
+ upTo(0);
702
+ return asThem("GET", "/v1/workspace/invitations");
703
+ case "invite-person":
704
+ upTo(0);
705
+ return asThem("POST", "/v1/workspace/invitations", { email: need(f.email, "--email"), role: f.role });
706
+ case "email-invitation-again":
707
+ upTo(1);
708
+ return asThem("POST", `/v1/workspace/invitations/${id("the invitation's id")}/email`);
709
+ case "take-back-invitation":
710
+ upTo(1);
711
+ return asThem("DELETE", `/v1/workspace/invitations/${id("the invitation's id")}`);
712
+ case "invite-link":
713
+ upTo(0);
714
+ return asThem("GET", "/v1/workspace/invite-link");
715
+ case "reset-invite-link":
716
+ upTo(0);
717
+ return asThem("POST", "/v1/workspace/invite-link/reset");
718
+ case "set-invite-link-rule":
719
+ upTo(0);
720
+ return asThem("PUT", "/v1/workspace/invite-link/rule", { mode: need(f.mode, "--mode"), domains: f.domains === undefined ? undefined : list(f.domains) });
721
+ case "workspace-areas":
722
+ upTo(0);
723
+ return asThem("GET", "/v1/areas");
724
+ case "add-area":
725
+ upTo(0);
726
+ return asThem("POST", "/v1/areas", {
727
+ slug: need(f.slug, "--slug"),
728
+ name: need(f.name, "--name"),
729
+ description: f.description && readText(f.description),
730
+ ownerPerson: f.owner,
731
+ codePaths: f["code-paths"] === undefined ? undefined : list(f["code-paths"]),
732
+ });
733
+ case "edit-area": {
734
+ upTo(1);
735
+ const area = id("the area's id");
736
+ const body = compact({
737
+ slug: f.slug,
738
+ name: f.name,
739
+ description: f.description && readText(f.description),
740
+ ownerPerson: orNone("owner"),
741
+ codePaths: f["code-paths"] === undefined ? undefined : list(f["code-paths"]),
742
+ });
743
+ if (!Object.keys(body).length)
744
+ throw new UsageError("edit-area needs something to change");
745
+ return asThem("PATCH", `/v1/areas/${area}`, body);
746
+ }
747
+ case "area-suggestions":
748
+ upTo(0);
749
+ return asThem("GET", `/v1/areas/suggestions${yesNo("fresh") ? "?fresh=1" : ""}`);
750
+ case "confirm-area-suggestion":
751
+ upTo(1);
752
+ return asThem("POST", `/v1/areas/suggestions/${id("the suggestion's id")}/confirm`);
753
+ case "dismiss-area-suggestion":
754
+ upTo(1);
755
+ return asThem("POST", `/v1/areas/suggestions/${id("the suggestion's id")}/dismiss`);
756
+ case "linear-teams":
757
+ upTo(0);
758
+ return asThem("GET", "/v1/board/teams");
759
+ case "add-linear-board":
760
+ upTo(1);
761
+ return asThem("POST", "/v1/board/boards", { teamId: need(p[0], "the team's id") });
762
+ case "remove-linear-board":
763
+ upTo(1);
764
+ return asThem("DELETE", `/v1/board/boards/${id("the team's id")}`);
765
+ case "workspace-logo":
766
+ upTo(0);
767
+ return asThem("GET", "/v1/workspace/logo");
768
+ case "set-workspace-logo": {
769
+ upTo(1);
770
+ const source = need(p[0], "slack, github, linear or none");
771
+ if (!["slack", "github", "linear", "none"].includes(source))
772
+ throw new UsageError("set-workspace-logo takes slack, github, linear or none");
773
+ return asThem("PUT", "/v1/workspace/logo", { source: source === "none" ? null : source });
774
+ }
775
+ case "workspace-connections":
776
+ upTo(0);
777
+ return asThem("GET", "/v1/connections");
354
778
  default:
355
779
  throw new UsageError(`unknown command "${command}"`);
356
780
  }
@@ -393,6 +817,7 @@ const attachBody = (file) => {
393
817
  const json = readJson(file);
394
818
  return json && typeof json === "object" && !Array.isArray(json) && SECTIONS.some((k) => k in json) ? json : { items: Array.isArray(json) ? json : [json] };
395
819
  };
820
+ const CALL_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
396
821
  // --as <name> (or --as=<name>) may come anywhere on the line; it's the caller's, not the command's.
397
822
  export function takeAs(argv) {
398
823
  const rest = [];
@@ -462,6 +887,9 @@ export function toRequest(argv) {
462
887
  throw new UsageError(`--harness is one of ${BRIDGE_HARNESSES.join(", ")}`);
463
888
  return { bridge: { action, harness, server: f.server } };
464
889
  }
890
+ case "actions-env":
891
+ upTo(0);
892
+ return { actionsEnv: true };
465
893
  case "watch":
466
894
  upTo(0);
467
895
  return { watch: true };
@@ -613,6 +1041,34 @@ export function toRequest(argv) {
613
1041
  agentId: f.agent,
614
1042
  }),
615
1043
  };
1044
+ case "move-agent":
1045
+ upTo(1);
1046
+ return { method: "PATCH", path: `/v1/agents/${encodeURIComponent(need(p[0], "the agent's id"))}`, body: { parentAgentId: need(f.under, "--under") } };
1047
+ case "call": {
1048
+ upTo(2);
1049
+ const method = CALL_METHODS.find((m) => m === need(p[0], "the method: GET, POST, PUT, PATCH or DELETE").toUpperCase());
1050
+ if (!method)
1051
+ throw new UsageError(`call's method is GET, POST, PUT, PATCH or DELETE, not "${p[0]}"`);
1052
+ const path = need(p[1], "the path, like /v1/blockers");
1053
+ if (!path.startsWith("/v1/") || path.split("?")[0].split("/").includes(".."))
1054
+ throw new UsageError("call's path is one under /v1/, like /v1/blockers");
1055
+ const query = new URLSearchParams();
1056
+ for (const pair of lists.query ?? []) {
1057
+ const eq = pair.indexOf("=");
1058
+ if (eq < 1)
1059
+ throw new UsageError(`--query is name=value, not "${pair}"`);
1060
+ query.append(pair.slice(0, eq), pair.slice(eq + 1));
1061
+ }
1062
+ const forPerson = f["for-person"];
1063
+ if (forPerson !== undefined && forPerson !== "true" && forPerson !== "false")
1064
+ throw new UsageError("--for-person is true or false");
1065
+ return {
1066
+ method,
1067
+ path: query.size ? `${path}${path.includes("?") ? "&" : "?"}${query}` : path,
1068
+ ...(f.body !== undefined ? { body: readJson(f.body) } : {}),
1069
+ ...(forPerson === "true" ? { forPerson: true } : {}),
1070
+ };
1071
+ }
616
1072
  case "me":
617
1073
  upTo(0);
618
1074
  return { method: "GET", path: "/v1/me" };
@@ -998,6 +1454,62 @@ async function watch(token, as) {
998
1454
  console.log(wakeLine(item));
999
1455
  }
1000
1456
  }
1457
+ // ---------- GitHub Actions (server/src/features/automations) ----------
1458
+ // A job with permissions: id-token: write can ask GitHub for its run's own token.
1459
+ export function inGitHubActions(env) {
1460
+ return !!env.ACTIONS_ID_TOKEN_REQUEST_URL && !!env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
1461
+ }
1462
+ // The run's own Gavel token, traded for GitHub's token for the run (asked for with Gavel's address as
1463
+ // its audience), as the sub-agent named by the run's task (--as, GAVEL_AGENT; else the server names
1464
+ // it by the workflow and run number). Kept in the job's temp folder, which goes with the job, so a job
1465
+ // trades once per name until five minutes before its hour is up. Never printed.
1466
+ async function runToken(base, name, env) {
1467
+ const named = name?.trim() || null;
1468
+ const kept = env.RUNNER_TEMP ? join(env.RUNNER_TEMP, `gavel-run-${createHash("sha256").update(`${base}\n${named ?? ""}`).digest("hex").slice(0, 16)}.json`) : null;
1469
+ if (kept && existsSync(kept)) {
1470
+ try {
1471
+ const run = JSON.parse(readFileSync(kept, "utf8"));
1472
+ if (new Date(run.expiresAt).getTime() - Date.now() > 5 * 60_000)
1473
+ return run;
1474
+ }
1475
+ catch {
1476
+ // Unreadable: trade again.
1477
+ }
1478
+ }
1479
+ const github = await fetch(`${env.ACTIONS_ID_TOKEN_REQUEST_URL}&audience=${encodeURIComponent(base)}`, {
1480
+ headers: { authorization: `bearer ${env.ACTIONS_ID_TOKEN_REQUEST_TOKEN}`, accept: "application/json" },
1481
+ });
1482
+ const proof = (await github.json().catch(() => ({})));
1483
+ if (!github.ok || !proof.value)
1484
+ throw new Error(`GitHub didn't give this run its token (HTTP ${github.status}): the job needs permissions: id-token: write`);
1485
+ const res = await fetch(`${base}/v1/automations/runs`, {
1486
+ method: "POST",
1487
+ headers: { "content-type": "application/json", accept: "application/json" },
1488
+ body: JSON.stringify({ githubToken: proof.value, ...(named ? { name: named } : {}), ...(env.GAVEL_WORKSPACE ? { workspace: env.GAVEL_WORKSPACE } : {}) }),
1489
+ });
1490
+ const body = (await res.json().catch(() => ({})));
1491
+ if (!res.ok)
1492
+ throw new Error(body.error?.message ?? `Gavel refused this run (HTTP ${res.status})`);
1493
+ if (kept)
1494
+ writeFileSync(kept, JSON.stringify(body), { mode: 0o600 });
1495
+ return body;
1496
+ }
1497
+ // For an agent in the job that speaks MCP: the run's token for the steps after this one, through the
1498
+ // job's GITHUB_ENV, masked first, GitHub's own way, so its log never shows it. The mask line is the
1499
+ // one line that holds the token, and the runner takes it rather than printing it.
1500
+ async function actionsEnv(as) {
1501
+ const env = process.env;
1502
+ if (!inGitHubActions(env) || !env.GITHUB_ENV) {
1503
+ console.error("gavel actions-env: run it in a GitHub Actions job with permissions: id-token: write");
1504
+ return 2;
1505
+ }
1506
+ const base = (env.GAVEL_API_URL ?? "https://api.getgavel.ai").replace(/\/+$/, "");
1507
+ const run = await runToken(base, as, env);
1508
+ console.log(`::add-mask::${run.token}`);
1509
+ appendFileSync(env.GITHUB_ENV, `GAVEL_TOKEN=${run.token}\nGAVEL_API_URL=${base}\nGAVEL_MCP_URL=${run.mcpUrl}\n`);
1510
+ console.log(JSON.stringify({ set: ["GAVEL_TOKEN", "GAVEL_API_URL", "GAVEL_MCP_URL"], agent: run.agent, workspace: run.workspace, server: run.server, expiresAt: run.expiresAt }, null, 2));
1511
+ return 0;
1512
+ }
1001
1513
  async function main(argvIn) {
1002
1514
  let request;
1003
1515
  let as = null;
@@ -1024,21 +1536,24 @@ async function main(argvIn) {
1024
1536
  return pair(request.pair);
1025
1537
  if ("bridge" in request)
1026
1538
  return runBridge(request.bridge, { cwd: process.cwd(), home: homedir(), env: process.env, as });
1027
- const token = process.env.GAVEL_TOKEN;
1539
+ if ("actionsEnv" in request)
1540
+ return actionsEnv(as);
1541
+ const base = (process.env.GAVEL_API_URL ?? "https://api.getgavel.ai").replace(/\/+$/, "");
1542
+ const token = process.env.GAVEL_TOKEN || (inGitHubActions(process.env) ? (await runToken(base, as, process.env)).token : undefined);
1028
1543
  if (!token) {
1029
- console.error("gavel: set GAVEL_TOKEN to your agent token (gvl_agent_…)");
1544
+ console.error("gavel: set GAVEL_TOKEN to your agent token (gvl_agent_…), or in a GitHub Actions job give it permissions: id-token: write");
1030
1545
  return 2;
1031
1546
  }
1032
1547
  if ("watch" in request)
1033
1548
  return watch(token, as);
1034
1549
  if ("upload" in request)
1035
1550
  return upload(token, as, request.upload);
1036
- const base = (process.env.GAVEL_API_URL ?? "https://api.getgavel.ai").replace(/\/+$/, "");
1037
1551
  const res = await fetch(base + request.path, {
1038
1552
  method: request.method,
1039
1553
  headers: {
1040
1554
  authorization: `Bearer ${token}`,
1041
1555
  accept: "application/json",
1556
+ "x-gavel-waiting": "1",
1042
1557
  ...agentHeader(as),
1043
1558
  ...(request.forPerson ? { "x-gavel-for-person": "true" } : {}),
1044
1559
  ...(request.body !== undefined ? { "content-type": "application/json" } : {}),
@@ -1058,6 +1573,11 @@ async function main(argvIn) {
1058
1573
  return 1;
1059
1574
  }
1060
1575
  console.log(out);
1576
+ // What's waiting for you (the server's own words), on stderr so stdout stays the answer's JSON. A
1577
+ // failed call's stderr stays its error alone.
1578
+ const waiting = res.headers.get("x-gavel-waiting");
1579
+ if (waiting)
1580
+ console.error(waiting);
1061
1581
  return 0;
1062
1582
  }
1063
1583
  main(process.argv.slice(2)).then((code) => process.exit(code), (err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getgavel/cli",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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",