@getgavel/cli 0.1.13 → 0.1.14

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 CHANGED
@@ -33,6 +33,7 @@ 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 find "nudge a decision" # the API's routes for what you want, and who may call each
35
35
  gavel work claim # when you're free: your next ready task; work done W-12 when it ships
36
+ gavel link-cursor-run # in Cursor, when Gavel didn't start you: link this chat (then --code)
36
37
  gavel help # every command
37
38
  gavel act --help # one command's usage
38
39
  ```
@@ -1,6 +1,6 @@
1
1
  import { execFileSync } from "node:child_process";
2
2
  import { randomUUID } from "node:crypto";
3
- import { appendFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
3
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { basename, dirname, join, relative } from "node:path";
6
6
  import { claudeOpen, claudeResume, claudeSessions, claudeSettingsFile, claudeWords, withWakeHook } from "./claude-code.js";
@@ -154,7 +154,10 @@ async function bridge(run, ctx) {
154
154
  return;
155
155
  }
156
156
  mkdirSync(dirname(settings), { recursive: true });
157
- writeFileSync(settings, next);
157
+ // Claude Code reads it whenever it likes: it changes whole, through a temp file and a rename.
158
+ const temp = `${settings}.${process.pid}.tmp`;
159
+ writeFileSync(temp, next);
160
+ renameSync(temp, settings);
158
161
  if (want) {
159
162
  const ignored = keepOutOfGit(settingsName, ctx.cwd);
160
163
  say(`Added Gavel's wake hook to ${settingsName}, so an open session hears from ${me.person.name} even while idle; it comes out when the chat is off or the bridge stops.${ignored ? ` (${ignored}.)` : ""}`);
package/dist/gavel.js CHANGED
@@ -120,6 +120,10 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
120
120
  gavel call <GET|POST|PUT|PATCH|DELETE> </v1/path> [--query <name=value>] [--body <file.json>]
121
121
  [--for-person true] any route of the API as you, or as your person with
122
122
  --for-person: MCP's do_action, the answer as it comes
123
+ gavel link-cursor-run [<bc-…> | none] [--code <code>]
124
+ your own Cursor run, when Gavel didn't start you (this
125
+ one by default, in a Cursor agent's shell): Gavel sends a
126
+ code into that chat; link again with --code; none unlinks
123
127
  gavel find (<words> | --query <words>) [--limit <n>]
124
128
  the API's routes for what you want to do, who may call each
125
129
  gavel me
@@ -270,6 +274,7 @@ const FLAGS = {
270
274
  "move-agent": ["under"],
271
275
  call: ["query", "body", "for-person"],
272
276
  find: ["query", "limit"],
277
+ "link-cursor-run": ["code"],
273
278
  me: [],
274
279
  "my-queue": ["view", "before", "limit"],
275
280
  "decide-mine": ["option", "text", "note", "their-words"],
@@ -1114,6 +1119,20 @@ export function toRequest(argv) {
1114
1119
  agentId: f.agent,
1115
1120
  }),
1116
1121
  };
1122
+ case "link-cursor-run": {
1123
+ upTo(1);
1124
+ if ((lists.code ?? []).length > 1)
1125
+ throw new UsageError("give --code once");
1126
+ if (p[0] === "none") {
1127
+ if (f.code !== undefined)
1128
+ throw new UsageError("--code goes with a run, not with none");
1129
+ return { linkRun: { cursorAgentId: null } };
1130
+ }
1131
+ const run = need(p[0] ?? cursorRunHere(process.env), "your Cursor run (bc-…, as cursor.com/agents/bc-… shows it), or none to unlink");
1132
+ if (!CURSOR_RUN.test(run))
1133
+ throw new UsageError(`a Cursor run is bc-…, as cursor.com/agents/bc-… shows it, not "${run}"`);
1134
+ return { linkRun: { cursorAgentId: run, ...(f.code !== undefined ? { code: need(f.code, "the code Gavel sent into that chat") } : {}) } };
1135
+ }
1117
1136
  case "find": {
1118
1137
  const q = words("query", p, "what you want to do, in words");
1119
1138
  const limit = f.limit;
@@ -1600,6 +1619,39 @@ async function actionsEnv(as) {
1600
1619
  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));
1601
1620
  return 0;
1602
1621
  }
1622
+ // ---------- gavel link-cursor-run ----------
1623
+ // A Cursor agent's shell names its own run in CURSOR_CONVERSATION_ID, "bc-…" on Cursor's cloud and on
1624
+ // a worker; any other id there isn't a run a link takes.
1625
+ const CURSOR_RUN = /^bc-[A-Za-z0-9-]{1,100}$/;
1626
+ function cursorRunHere(env) {
1627
+ const id = env.CURSOR_CONVERSATION_ID?.trim();
1628
+ return id && CURSOR_RUN.test(id) ? id : undefined;
1629
+ }
1630
+ // The route names the agent, so the caller's own id comes first (GET /v1/me); an exit code when it
1631
+ // can't be had.
1632
+ async function linkRunRequest(base, token, as, { cursorAgentId, code }) {
1633
+ const res = await fetch(`${base}/v1/me`, { headers: { authorization: `Bearer ${token}`, accept: "application/json", ...agentHeader(as) } });
1634
+ const text = await res.text();
1635
+ if (!res.ok) {
1636
+ console.error(pretty(text) || `HTTP ${res.status}`);
1637
+ return 1;
1638
+ }
1639
+ const id = JSON.parse(text).agent?.id;
1640
+ if (typeof id !== "string") {
1641
+ console.error("gavel: link-cursor-run links an agent's own run: GAVEL_TOKEN must be its agent token");
1642
+ return 2;
1643
+ }
1644
+ const path = `/v1/agents/${encodeURIComponent(id)}/cursor-run`;
1645
+ return cursorAgentId === null ? { method: "DELETE", path } : { method: "PUT", path, body: { cursorAgentId, ...(code !== undefined ? { code } : {}) } };
1646
+ }
1647
+ function pretty(text) {
1648
+ try {
1649
+ return JSON.stringify(JSON.parse(text), null, 2);
1650
+ }
1651
+ catch {
1652
+ return text;
1653
+ }
1654
+ }
1603
1655
  async function main(argvIn) {
1604
1656
  let request;
1605
1657
  let as = null;
@@ -1638,26 +1690,28 @@ async function main(argvIn) {
1638
1690
  return watch(token, as);
1639
1691
  if ("upload" in request)
1640
1692
  return upload(token, as, request.upload);
1641
- const res = await fetch(base + request.path, {
1642
- method: request.method,
1693
+ let call;
1694
+ if ("linkRun" in request) {
1695
+ const linking = await linkRunRequest(base, token, as, request.linkRun);
1696
+ if (typeof linking === "number")
1697
+ return linking;
1698
+ call = linking;
1699
+ }
1700
+ else
1701
+ call = request;
1702
+ const res = await fetch(base + call.path, {
1703
+ method: call.method,
1643
1704
  headers: {
1644
1705
  authorization: `Bearer ${token}`,
1645
1706
  accept: "application/json",
1646
1707
  "x-gavel-waiting": "1",
1647
1708
  ...agentHeader(as),
1648
- ...(request.forPerson ? { "x-gavel-for-person": "true" } : {}),
1649
- ...(request.body !== undefined ? { "content-type": "application/json" } : {}),
1709
+ ...(call.forPerson ? { "x-gavel-for-person": "true" } : {}),
1710
+ ...(call.body !== undefined ? { "content-type": "application/json" } : {}),
1650
1711
  },
1651
- ...(request.body !== undefined ? { body: JSON.stringify(request.body) } : {}),
1712
+ ...(call.body !== undefined ? { body: JSON.stringify(call.body) } : {}),
1652
1713
  });
1653
- const text = await res.text();
1654
- let out = text;
1655
- try {
1656
- out = JSON.stringify(JSON.parse(text), null, 2);
1657
- }
1658
- catch {
1659
- // not JSON: print as it came
1660
- }
1714
+ const out = pretty(await res.text());
1661
1715
  if (!res.ok) {
1662
1716
  console.error(out || `HTTP ${res.status}`);
1663
1717
  return 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getgavel/cli",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
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",