@getgavel/cli 0.1.18 → 0.1.20
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/.claude-plugin/plugin.json +1 -1
- package/dist/bridge/bridge.js +52 -12
- package/dist/bridge/claude-live.js +20 -5
- package/dist/gavel.js +32 -11
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gavel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"displayName": "Gavel",
|
|
5
5
|
"description": "Gavel in Claude Code: your person's chat in Gavel reaches your sessions at once (Gavel's bridge, started with each session), the end-of-turn reminder of what's waiting for you, and how to work with Gavel.",
|
|
6
6
|
"author": { "name": "Gavel", "url": "https://getgavel.ai" },
|
package/dist/bridge/bridge.js
CHANGED
|
@@ -106,6 +106,10 @@ const PICTURE_KEEP_MS = 15 * 60_000;
|
|
|
106
106
|
const LIVE_EVERY_MS = 500;
|
|
107
107
|
const LIVE_PIECE = 20_000;
|
|
108
108
|
const PUSH_EVERY_MS = 2000;
|
|
109
|
+
// What changed goes this long after (what changes with it goes along), and pushes that send words
|
|
110
|
+
// stay this far apart while things keep changing: each counts in the agent's 120 calls a minute.
|
|
111
|
+
const PUSH_SOON_MS = 50;
|
|
112
|
+
const PUSH_GAP_MS = 500;
|
|
109
113
|
const WAKE_AGAIN_MS = 60_000;
|
|
110
114
|
// Gavel's one-line wake (D-1103, cloud-agents' wakePrompt): each ref once, what has none by its kind.
|
|
111
115
|
export const wakeLineOf = (items) => {
|
|
@@ -167,6 +171,7 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
167
171
|
trouble = what;
|
|
168
172
|
};
|
|
169
173
|
let syncing = null;
|
|
174
|
+
let pushedAt = 0;
|
|
170
175
|
const pushOnce = async () => {
|
|
171
176
|
if (!on)
|
|
172
177
|
return;
|
|
@@ -182,6 +187,7 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
182
187
|
for (let i = 0; i < messages.length; i += 200) {
|
|
183
188
|
const part = messages.slice(i, i + 200);
|
|
184
189
|
const res = await call(api, "PUT", "/v1/agents/me/chat/transcript", { thread: t.thread, label: t.label, messages: part });
|
|
190
|
+
pushedAt = Date.now();
|
|
185
191
|
if (!res.ok)
|
|
186
192
|
throw new Error(`HTTP ${res.status} sending the session's words`);
|
|
187
193
|
if (!(await res.json()).on)
|
|
@@ -202,8 +208,8 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
202
208
|
const pushSoon = () => {
|
|
203
209
|
soon ??= setTimeout(() => {
|
|
204
210
|
soon = null;
|
|
205
|
-
void
|
|
206
|
-
},
|
|
211
|
+
void pushAfter();
|
|
212
|
+
}, Math.max(PUSH_SOON_MS, pushedAt + PUSH_GAP_MS - Date.now()));
|
|
207
213
|
};
|
|
208
214
|
const note = async (text) => {
|
|
209
215
|
await pushAfter();
|
|
@@ -212,8 +218,13 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
212
218
|
await call(api, "PUT", "/v1/agents/me/chat/transcript", { thread, messages: [{ id: `gavel:${randomUUID()}`, side: "gavel", text, at: new Date().toISOString() }] }).catch(() => undefined);
|
|
213
219
|
};
|
|
214
220
|
// Live: the words as they're written and the state, relayed to the person's open chat, never kept.
|
|
215
|
-
// A turn's end goes only once its words are kept.
|
|
221
|
+
// A turn's end goes only once its words are kept. One POST at most each LIVE_EVERY_MS, each as soon
|
|
222
|
+
// as that allows: a turn's start or a state change after a quiet moment shows at once, and words
|
|
223
|
+
// batch while they stream.
|
|
216
224
|
let posting = null;
|
|
225
|
+
let lastPost = 0;
|
|
226
|
+
const posted = [];
|
|
227
|
+
let liveTimer = null;
|
|
217
228
|
const postLive = async () => {
|
|
218
229
|
if (!outgoing.length)
|
|
219
230
|
return;
|
|
@@ -233,11 +244,35 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
233
244
|
return;
|
|
234
245
|
}
|
|
235
246
|
};
|
|
236
|
-
const
|
|
237
|
-
|
|
247
|
+
const sendLive = () => {
|
|
248
|
+
liveTimer = null;
|
|
249
|
+
if (posting)
|
|
250
|
+
return;
|
|
251
|
+
lastPost = Date.now();
|
|
252
|
+
posted.push(lastPost);
|
|
253
|
+
posting = postLive()
|
|
238
254
|
.catch(() => undefined)
|
|
239
|
-
.finally(() =>
|
|
240
|
-
|
|
255
|
+
.finally(() => {
|
|
256
|
+
posting = null;
|
|
257
|
+
liveSoon();
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
const liveSoon = () => {
|
|
261
|
+
if (stopping || posting || !outgoing.length)
|
|
262
|
+
return;
|
|
263
|
+
const now = Date.now();
|
|
264
|
+
while (posted.length && posted[0] <= now - 1000)
|
|
265
|
+
posted.shift();
|
|
266
|
+
// A turn's end, with its last words, goes at once even inside the gap: one a turn, and never more
|
|
267
|
+
// than three posts in a second (the route takes 240 a minute).
|
|
268
|
+
const end = outgoing.some((e) => e.event === "end") && posted.length < 3;
|
|
269
|
+
if (liveTimer) {
|
|
270
|
+
if (!end)
|
|
271
|
+
return;
|
|
272
|
+
clearTimeout(liveTimer);
|
|
273
|
+
}
|
|
274
|
+
liveTimer = setTimeout(sendLive, end ? 0 : Math.max(0, lastPost + LIVE_EVERY_MS - now));
|
|
275
|
+
};
|
|
241
276
|
const pushTimer = setInterval(() => void push(), PUSH_EVERY_MS);
|
|
242
277
|
const read = (body) => call(api, "POST", "/v1/agents/me/chat/read", body).then((res) => res.ok || console.error(`gavel bridge: HTTP ${res.status} marking a message read`), (err) => console.error(`gavel bridge: ${err instanceof Error ? err.message : String(err)} marking a message read`));
|
|
243
278
|
// A message's pictures, to private files on the laptop that its software reads (each an hour-long
|
|
@@ -286,7 +321,6 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
286
321
|
if (missed)
|
|
287
322
|
await note(`${missed === 1 ? "A picture" : `${missed} pictures`} from your message didn't reach the laptop, so ${h.name} got your words without ${missed === 1 ? "it" : "them"}.`);
|
|
288
323
|
}
|
|
289
|
-
pushSoon();
|
|
290
324
|
}
|
|
291
325
|
finally {
|
|
292
326
|
delivering.delete(m.id);
|
|
@@ -385,13 +419,17 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
385
419
|
const offHooks = onHookEvent((event) => h.hook?.(event.event, event));
|
|
386
420
|
h.listen({
|
|
387
421
|
live: (event) => {
|
|
388
|
-
if (on
|
|
389
|
-
|
|
422
|
+
if (!on || !liveRoute)
|
|
423
|
+
return;
|
|
424
|
+
outgoing.push(event);
|
|
425
|
+
liveSoon();
|
|
390
426
|
},
|
|
391
427
|
state: (next) => {
|
|
392
428
|
state = next;
|
|
393
|
-
if (on && liveRoute)
|
|
429
|
+
if (on && liveRoute) {
|
|
394
430
|
outgoing.push({ event: "state", state: next });
|
|
431
|
+
liveSoon();
|
|
432
|
+
}
|
|
395
433
|
if (next === "idle" || next === "closed")
|
|
396
434
|
void tryWake();
|
|
397
435
|
},
|
|
@@ -399,7 +437,8 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
399
437
|
note: (text) => void note(text),
|
|
400
438
|
});
|
|
401
439
|
const timers = () => {
|
|
402
|
-
|
|
440
|
+
if (liveTimer)
|
|
441
|
+
clearTimeout(liveTimer);
|
|
403
442
|
clearInterval(pushTimer);
|
|
404
443
|
clearInterval(wakeTimer);
|
|
405
444
|
if (soon)
|
|
@@ -472,6 +511,7 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
472
511
|
if (state)
|
|
473
512
|
outgoing.push({ event: "state", state });
|
|
474
513
|
await push();
|
|
514
|
+
liveSoon();
|
|
475
515
|
}
|
|
476
516
|
else if (ctx.env.GAVEL_BRIDGE_SERVICE !== "1") {
|
|
477
517
|
stop("The chat is off in Gavel: the bridge stops, and starts again with a session once it's on.");
|
|
@@ -4,7 +4,7 @@ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameS
|
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
5
|
import { connect } from "node:net";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
|
-
import { extname, join } from "node:path";
|
|
7
|
+
import { basename, dirname, extname, join } from "node:path";
|
|
8
8
|
import { promisify } from "node:util";
|
|
9
9
|
import { bridgePaths } from "./background.js";
|
|
10
10
|
import { claudeSessions, claudeWords } from "./claude-code.js";
|
|
@@ -295,24 +295,39 @@ export class ClaudeCodeHarness {
|
|
|
295
295
|
stateNow() {
|
|
296
296
|
this.setState(this.current()?.state ?? "closed");
|
|
297
297
|
}
|
|
298
|
+
// A transcript write comes as a few file events at once: one changed() for them, quickly, since the
|
|
299
|
+
// session's copy of a Gavel message is what marks it read.
|
|
298
300
|
soon() {
|
|
299
301
|
if (this.changedTimer)
|
|
300
302
|
return;
|
|
301
303
|
this.changedTimer = setTimeout(() => {
|
|
302
304
|
this.changedTimer = null;
|
|
303
305
|
this.listener?.changed();
|
|
304
|
-
},
|
|
306
|
+
}, 15);
|
|
305
307
|
}
|
|
308
|
+
// A new session's transcript appears with its first prompt: until then its folder is watched for it.
|
|
306
309
|
follow(file) {
|
|
307
310
|
if (file === this.watching)
|
|
308
311
|
return;
|
|
309
312
|
this.watcher?.close();
|
|
310
313
|
this.watcher = null;
|
|
311
314
|
this.watching = file;
|
|
312
|
-
if (!file
|
|
315
|
+
if (!file)
|
|
313
316
|
return;
|
|
314
317
|
try {
|
|
315
|
-
|
|
318
|
+
if (existsSync(file)) {
|
|
319
|
+
this.watcher = watch(file, () => this.soon());
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (!existsSync(dirname(file)))
|
|
323
|
+
return;
|
|
324
|
+
this.watcher = watch(dirname(file), (_event, name) => {
|
|
325
|
+
if (name !== basename(file) || !existsSync(file) || this.watching !== file)
|
|
326
|
+
return;
|
|
327
|
+
this.watching = null;
|
|
328
|
+
this.follow(file);
|
|
329
|
+
this.soon();
|
|
330
|
+
});
|
|
316
331
|
}
|
|
317
332
|
catch {
|
|
318
333
|
// the core reads every 2 s anyway
|
|
@@ -419,10 +434,10 @@ export class ClaudeCodeHarness {
|
|
|
419
434
|
async newest() {
|
|
420
435
|
const open = this.current();
|
|
421
436
|
const file = open?.transcript && existsSync(open.transcript) ? open.transcript : (claudeSessions(this.ctx.cwd, this.ctx.home, this.ctx.env)[0]?.file ?? null);
|
|
437
|
+
this.follow(open?.transcript ?? file);
|
|
422
438
|
if (!file)
|
|
423
439
|
return null;
|
|
424
440
|
const session = /([0-9a-f-]{36})\.jsonl$/i.exec(file)?.[1] ?? file;
|
|
425
|
-
this.follow(file);
|
|
426
441
|
const prompts = new Map();
|
|
427
442
|
for (const [id, key] of this.known)
|
|
428
443
|
if (key)
|
package/dist/gavel.js
CHANGED
|
@@ -63,10 +63,12 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
|
|
|
63
63
|
gavel revise <D-12> --file decision.json a draft the editor sent back, fixed (the whole ask again)
|
|
64
64
|
gavel todo --file todo.json ask a person to do something: title, steps, why (MCP ask_to_do's input)
|
|
65
65
|
gavel get <D-12>
|
|
66
|
-
gavel subscribe (<D-12> | --item <W-12> [--stop true])
|
|
66
|
+
gavel subscribe (<D-12> | --item <W-12> [--stop true] | --quiet answer,decision|none)
|
|
67
67
|
follow a decision you didn't ask (wait returns its answer
|
|
68
68
|
to you too), or a work item: what happens to it wakes you;
|
|
69
|
-
--stop true stops following the item
|
|
69
|
+
--stop true stops following the item; --quiet: answers to
|
|
70
|
+
what you wait on, or decisions you decide, wake you only
|
|
71
|
+
with something else (none wakes you on them again)
|
|
70
72
|
gavel wait <D-12> [--timeout <seconds>] until it's decided (default 60)
|
|
71
73
|
gavel withdraw <D-12> [--reason <words>] take back what you asked, while it isn't decided
|
|
72
74
|
gavel attach <D-12> --file context.json the sidebar's sections ({items, pictures, involved,
|
|
@@ -130,10 +132,12 @@ const USAGE = `gavel: Gavel from the command line (https://getgavel.ai/agents)
|
|
|
130
132
|
gavel message --conversation <C-12> (<text> | --text <words>) [--no-reply true] [--key <key>]
|
|
131
133
|
reply in one; --no-reply true: a note, which never wakes
|
|
132
134
|
them; --key: your own id for it, so a retry sends it once
|
|
133
|
-
gavel message --item <W-12> (<text> | --text <words>) [--key <key>]
|
|
135
|
+
gavel message --item <W-12> (<text> | --text <words>) [--no-reply true] [--key <key>]
|
|
134
136
|
write in a work item's thread, which all on it read
|
|
135
137
|
gavel conversations [<C-12>] yours, or one with its messages (reads it)
|
|
136
|
-
gavel thread <W-12> [join | leave
|
|
138
|
+
gavel thread <W-12> [join | leave | add <agent>]
|
|
139
|
+
a work item's thread: who's in and its messages; add
|
|
140
|
+
(its worker or the coordinator) brings in a reviewer
|
|
137
141
|
gavel wait-for-reply <C-12> [--timeout <seconds>]
|
|
138
142
|
until there's a message to you in it (default 60)
|
|
139
143
|
gavel chat [<text> | --text <words>] what your person wrote you in Gavel (each once), or
|
|
@@ -296,7 +300,7 @@ const FLAGS = {
|
|
|
296
300
|
revise: ["file"],
|
|
297
301
|
todo: ["file"],
|
|
298
302
|
get: [],
|
|
299
|
-
subscribe: ["item", "stop"],
|
|
303
|
+
subscribe: ["item", "stop", "quiet"],
|
|
300
304
|
wait: ["timeout"],
|
|
301
305
|
withdraw: ["reason"],
|
|
302
306
|
attach: ["file"],
|
|
@@ -1082,6 +1086,14 @@ export function toRequest(argv) {
|
|
|
1082
1086
|
return { method: "GET", path: `/v1/decisions/${ref(p[0])}` };
|
|
1083
1087
|
case "subscribe": {
|
|
1084
1088
|
upTo(1);
|
|
1089
|
+
if (f.quiet !== undefined) {
|
|
1090
|
+
if (p.length || f.item !== undefined || f.stop !== undefined)
|
|
1091
|
+
throw new UsageError("--quiet goes alone: gavel subscribe --quiet answer,decision (or none)");
|
|
1092
|
+
const kinds = f.quiet === "none" ? [] : f.quiet.split(",").map((k) => k.trim());
|
|
1093
|
+
if (f.quiet !== "none" && (!kinds.length || kinds.some((k) => k !== "answer" && k !== "decision")))
|
|
1094
|
+
throw new UsageError("--quiet is answer, decision, answer,decision or none");
|
|
1095
|
+
return { method: "PUT", path: "/v1/inbox/quiet", body: { kinds } };
|
|
1096
|
+
}
|
|
1085
1097
|
if (f.stop !== undefined && f.stop !== "true" && f.stop !== "false")
|
|
1086
1098
|
throw new UsageError("--stop is true or false");
|
|
1087
1099
|
if (f.item === undefined) {
|
|
@@ -1141,9 +1153,12 @@ export function toRequest(argv) {
|
|
|
1141
1153
|
case "message": {
|
|
1142
1154
|
const text = readText(words("text", p, "what to say"));
|
|
1143
1155
|
if (f.item) {
|
|
1144
|
-
if (f.conversation || f["to-agent"] || f["to-person"] || f.decision !== undefined
|
|
1145
|
-
throw new UsageError("--item writes in a work item's thread: give it alone, with --key if you like");
|
|
1146
|
-
|
|
1156
|
+
if (f.conversation || f["to-agent"] || f["to-person"] || f.decision !== undefined)
|
|
1157
|
+
throw new UsageError("--item writes in a work item's thread: give it alone, with --no-reply and --key if you like");
|
|
1158
|
+
const quiet = f["no-reply"];
|
|
1159
|
+
if (quiet !== undefined && quiet !== "true" && quiet !== "false")
|
|
1160
|
+
throw new UsageError("--no-reply is true or false");
|
|
1161
|
+
return { method: "POST", path: `/v1/work/${encodeURIComponent(f.item)}/thread`, body: compact({ text, noReply: quiet === undefined ? undefined : quiet === "true", key: f.key }) };
|
|
1147
1162
|
}
|
|
1148
1163
|
if ([f.conversation, f["to-agent"], f["to-person"]].filter(Boolean).length !== 1)
|
|
1149
1164
|
throw new UsageError("give --to-agent or --to-person to start a conversation, --conversation to reply in one, or --item to write in a work item's thread");
|
|
@@ -1161,12 +1176,16 @@ export function toRequest(argv) {
|
|
|
1161
1176
|
upTo(1);
|
|
1162
1177
|
return { method: "GET", path: p[0] ? `/v1/conversations/${encodeURIComponent(p[0])}` : "/v1/conversations" };
|
|
1163
1178
|
case "thread": {
|
|
1164
|
-
upTo(
|
|
1179
|
+
upTo(3);
|
|
1165
1180
|
const ref = encodeURIComponent(need(p[0], "the work item (W-12)"));
|
|
1166
1181
|
if (p[1] === undefined)
|
|
1167
1182
|
return { method: "GET", path: `/v1/work/${ref}/thread` };
|
|
1183
|
+
if (p[1] === "add")
|
|
1184
|
+
return { method: "POST", path: `/v1/work/${ref}/thread/join`, body: { agent: need(p[2], "the agent to add (its name or id)") } };
|
|
1168
1185
|
if (p[1] !== "join" && p[1] !== "leave")
|
|
1169
|
-
throw new UsageError("after the item, join or
|
|
1186
|
+
throw new UsageError("after the item, join, leave or add <agent>");
|
|
1187
|
+
if (p[2] !== undefined)
|
|
1188
|
+
throw new UsageError(`${p[1]} takes nothing after it`);
|
|
1170
1189
|
return { method: "POST", path: `/v1/work/${ref}/thread/${p[1]}` };
|
|
1171
1190
|
}
|
|
1172
1191
|
case "wait-for-reply":
|
|
@@ -1817,6 +1836,8 @@ export function wakeLine(item) {
|
|
|
1817
1836
|
return item.type === "ready"
|
|
1818
1837
|
? `GAVEL_WAKE task ${item.ref} ready: what it waited on is finished: gavel work show ${item.ref}`
|
|
1819
1838
|
: `GAVEL_WAKE task ${item.ref} ${item.type ?? "changed"} by someone else: gavel work show ${item.ref}`;
|
|
1839
|
+
case "replaced":
|
|
1840
|
+
return `GAVEL_WAKE replaced ${item.ref}: it no longer holds, ${item.type ?? "a newer decision"} replaces it: gavel get ${item.type ?? item.ref}, and follow that one`;
|
|
1820
1841
|
default:
|
|
1821
1842
|
return "GAVEL_WAKE something new: see gavel inbox";
|
|
1822
1843
|
}
|
|
@@ -1832,7 +1853,7 @@ async function watch(token, as) {
|
|
|
1832
1853
|
for (;;) {
|
|
1833
1854
|
let res;
|
|
1834
1855
|
try {
|
|
1835
|
-
res = await fetch(`${base}/v1/inbox/watch?watch=${id}&timeout=50&kinds=health,claim,work,drift,task${start ? "&start=true" : ""}`, {
|
|
1856
|
+
res = await fetch(`${base}/v1/inbox/watch?watch=${id}&timeout=50&kinds=health,claim,work,drift,task,replaced${start ? "&start=true" : ""}`, {
|
|
1836
1857
|
headers: { authorization: `Bearer ${token}`, accept: "application/json", ...agentHeader(as) },
|
|
1837
1858
|
});
|
|
1838
1859
|
}
|
package/package.json
CHANGED