@getgavel/cli 0.1.22 → 0.1.23
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 +11 -6
- package/dist/bridge/claude-live.js +36 -40
- package/dist/bridge/codex.js +6 -29
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gavel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
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
|
@@ -159,6 +159,7 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
159
159
|
let stopping = false;
|
|
160
160
|
let thread = null;
|
|
161
161
|
let state = null;
|
|
162
|
+
let opens = null;
|
|
162
163
|
let liveRoute = true;
|
|
163
164
|
let outgoing = [];
|
|
164
165
|
const sent = new Map();
|
|
@@ -283,9 +284,12 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
283
284
|
const now = Date.now();
|
|
284
285
|
while (posted.length && posted[0] <= now - 1000)
|
|
285
286
|
posted.shift();
|
|
286
|
-
// A turn's end, with its last words, goes at once even inside the gap: one a turn
|
|
287
|
-
//
|
|
288
|
-
|
|
287
|
+
// A turn's end, with its last words, goes at once even inside the gap: one a turn. So does the
|
|
288
|
+
// session ceasing to work (idle, waiting on the laptop, closed): its last words show then, while
|
|
289
|
+
// its end waits for the push that keeps them. Never more than three posts in a second, but the
|
|
290
|
+
// end's own, a fourth at a turn's close (the route takes 240 a minute).
|
|
291
|
+
const stopped = outgoing.some((e) => e.event === "state" && e.state !== "working");
|
|
292
|
+
const end = outgoing.some((e) => e.event === "end") ? posted.length < 4 : stopped && posted.length < 3;
|
|
289
293
|
if (liveTimer) {
|
|
290
294
|
if (!end)
|
|
291
295
|
return;
|
|
@@ -445,10 +449,11 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
445
449
|
outgoing.push(event);
|
|
446
450
|
liveSoon();
|
|
447
451
|
},
|
|
448
|
-
state: (next) => {
|
|
452
|
+
state: (next, open) => {
|
|
449
453
|
state = next;
|
|
454
|
+
opens = next === "waiting" ? (open ?? null) : null;
|
|
450
455
|
if (on && liveRoute) {
|
|
451
|
-
outgoing.push({ event: "state", state: next });
|
|
456
|
+
outgoing.push({ event: "state", state: next, ...(opens ? { opens } : {}) });
|
|
452
457
|
liveSoon();
|
|
453
458
|
}
|
|
454
459
|
if (next === "idle" || next === "closed")
|
|
@@ -530,7 +535,7 @@ async function harnessBridge(h, harness, setup, ctx) {
|
|
|
530
535
|
thread = null;
|
|
531
536
|
sent.clear();
|
|
532
537
|
if (state)
|
|
533
|
-
outgoing.push({ event: "state", state });
|
|
538
|
+
outgoing.push({ event: "state", state, ...(opens ? { opens } : {}) });
|
|
534
539
|
await push();
|
|
535
540
|
liveSoon();
|
|
536
541
|
}
|
|
@@ -310,8 +310,9 @@ export class ClaudeCodeHarness {
|
|
|
310
310
|
watcher = null;
|
|
311
311
|
watching = null;
|
|
312
312
|
display = null;
|
|
313
|
-
resumed = null;
|
|
314
313
|
lastState = null;
|
|
314
|
+
// The short ids Claude Code gave the sessions the bridge put in the background.
|
|
315
|
+
backgrounded = new Set();
|
|
315
316
|
changedTimer = null;
|
|
316
317
|
// The person's name, for the words that say who wrote: the core learns it after it builds the
|
|
317
318
|
// harness, from GET /v1/me.
|
|
@@ -346,17 +347,21 @@ export class ClaudeCodeHarness {
|
|
|
346
347
|
}
|
|
347
348
|
// The session Gavel shows and writes to: the newest one open, else the folder's newest.
|
|
348
349
|
current() {
|
|
349
|
-
const open = [...this.sessions.values()].filter((s) => s.open).sort((a, b) => b.seen - a.seen);
|
|
350
|
+
const open = [...this.sessions.values()].filter((s) => s.open).sort((a, b) => Number(b.begun) - Number(a.begun) || b.seen - a.seen);
|
|
350
351
|
return open[0] ?? null;
|
|
351
352
|
}
|
|
352
|
-
setState(next) {
|
|
353
|
-
|
|
353
|
+
setState(next, opens) {
|
|
354
|
+
const said = `${next} ${opens ?? ""}`;
|
|
355
|
+
if (said === this.lastState)
|
|
354
356
|
return;
|
|
355
|
-
this.lastState =
|
|
356
|
-
this.listener?.state(next);
|
|
357
|
+
this.lastState = said;
|
|
358
|
+
this.listener?.state(next, opens);
|
|
357
359
|
}
|
|
360
|
+
// A session in the background that waits on a prompt opens with `claude attach` and the short id
|
|
361
|
+
// Claude Code gives it (its id's first 8 characters).
|
|
358
362
|
stateNow() {
|
|
359
|
-
this.
|
|
363
|
+
const s = this.current();
|
|
364
|
+
this.setState(s?.state ?? "closed", s?.state === "waiting" && s.background ? `claude attach ${s.id.slice(0, 8)}` : null);
|
|
360
365
|
}
|
|
361
366
|
// A transcript write comes as a few file events at once: one changed() for them, quickly, since the
|
|
362
367
|
// session's copy of a Gavel message is what marks it read.
|
|
@@ -399,7 +404,7 @@ export class ClaudeCodeHarness {
|
|
|
399
404
|
session(id) {
|
|
400
405
|
let s = this.sessions.get(id);
|
|
401
406
|
if (!s) {
|
|
402
|
-
s = { id, inbox: null, transcript: null, open: true, hooked: false, state: "idle", seen: Date.now(), run: null, spoken: new Map() };
|
|
407
|
+
s = { id, inbox: null, transcript: null, open: true, hooked: false, background: false, begun: false, state: "idle", seen: Date.now(), run: null, spoken: new Map() };
|
|
403
408
|
this.sessions.set(id, s);
|
|
404
409
|
}
|
|
405
410
|
return s;
|
|
@@ -416,6 +421,9 @@ export class ClaudeCodeHarness {
|
|
|
416
421
|
const s = this.session(id);
|
|
417
422
|
s.seen = Date.now();
|
|
418
423
|
s.hooked = true;
|
|
424
|
+
s.begun ||= event === "SessionStart" ? input.source !== "startup" : event !== "SessionEnd";
|
|
425
|
+
if (this.backgrounded.has(id.slice(0, 8)))
|
|
426
|
+
s.background = true;
|
|
419
427
|
if (e.inbox)
|
|
420
428
|
s.inbox = e.inbox;
|
|
421
429
|
if (typeof input.transcript_path === "string")
|
|
@@ -563,15 +571,17 @@ export class ClaudeCodeHarness {
|
|
|
563
571
|
return { outcome: "left", say: `${this.ctx.person} wrote in Gavel; your Claude Code session here is open and the bridge can't reach it yet, so it goes in at the session's next step, or once it closes.` };
|
|
564
572
|
return this.resume(m, text);
|
|
565
573
|
}
|
|
566
|
-
// A closed session, resumed with the person's words as a turn of its own
|
|
567
|
-
//
|
|
568
|
-
//
|
|
574
|
+
// A closed session, resumed with the person's words as a turn of its own in the background
|
|
575
|
+
// (D-1174, changing D-905's "nothing that would prompt runs"): it runs under their own permission
|
|
576
|
+
// settings, and what would ask them waits till they open it on the laptop (`claude attach`). Its
|
|
577
|
+
// edits stay in the folder, as their own session's: no worktree of its own (Master Gavel's call).
|
|
578
|
+
// The words go on stdin, never in its arguments. Delivered once Claude Code says it's backgrounded;
|
|
579
|
+
// from then the session's own hooks name it, so their next words go through its inbox.
|
|
569
580
|
resume(m, text) {
|
|
570
581
|
const newest = claudeSessions(this.ctx.cwd, this.ctx.home, this.ctx.env)[0] ?? null;
|
|
571
|
-
const args = [
|
|
582
|
+
const args = [...(newest ? ["--resume", newest.id] : []), "--bg", "--settings", JSON.stringify({ worktree: { bgIsolation: "none" } })];
|
|
572
583
|
return new Promise((resolve) => {
|
|
573
|
-
const child = spawn("claude", args, { cwd: this.ctx.cwd, stdio: ["pipe", "pipe", "pipe"] });
|
|
574
|
-
this.resumed = child;
|
|
584
|
+
const child = spawn("claude", args, { cwd: this.ctx.cwd, env: this.ctx.env, stdio: ["pipe", "pipe", "pipe"] });
|
|
575
585
|
let out = "";
|
|
576
586
|
let err = "";
|
|
577
587
|
let settled = false;
|
|
@@ -580,38 +590,27 @@ export class ClaudeCodeHarness {
|
|
|
580
590
|
resolve(d);
|
|
581
591
|
settled = true;
|
|
582
592
|
};
|
|
593
|
+
const quit = setTimeout(() => child.kill(), 60_000);
|
|
583
594
|
child.stdout.on("data", (d) => (out += d));
|
|
584
595
|
child.stderr.on("data", (d) => (err += d));
|
|
585
|
-
child.on("spawn", () => {
|
|
586
|
-
this.remember(m.id, promptKey(text));
|
|
587
|
-
setTimeout(() => settle({ outcome: "delivered" }), 300).unref();
|
|
588
|
-
});
|
|
589
596
|
child.on("error", (e) => settle({ outcome: "failed", reason: e.code === "ENOENT" ? "Claude Code's claude command isn't on the laptop's PATH where the bridge runs." : `Claude Code didn't start: ${e.message}` }));
|
|
590
597
|
child.on("close", (code) => {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
catch {
|
|
597
|
-
// its reason is on stderr
|
|
598
|
-
}
|
|
599
|
-
const first = (t) => t.split("\n").map((l) => l.trim()).find(Boolean) ?? "";
|
|
600
|
-
if (code === 0 && result && !result.is_error) {
|
|
601
|
-
const refused = [...new Set((result.permission_denials ?? []).map((d) => d?.tool_name).filter((n) => typeof n === "string"))];
|
|
602
|
-
if (refused.length)
|
|
603
|
-
this.listener?.note(`Claude Code didn't do what it would have asked you about first (${refused.join(", ")}): nobody was at the laptop to allow it. Allow it in the session there, or answer here.`);
|
|
598
|
+
clearTimeout(quit);
|
|
599
|
+
const short = /^backgrounded · ([0-9a-f]{8,36})\b/m.exec(out)?.[1];
|
|
600
|
+
if (code === 0 && short) {
|
|
601
|
+
this.remember(m.id, promptKey(text));
|
|
602
|
+
this.backgrounded.add(short.slice(0, 8));
|
|
604
603
|
settle({ outcome: "delivered" });
|
|
605
604
|
}
|
|
606
605
|
else {
|
|
607
|
-
const
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
this.listener?.note(reason);
|
|
606
|
+
const first = (t) => t.split("\n").map((l) => l.trim()).find(Boolean) ?? "";
|
|
607
|
+
const said = first(err) || first(out);
|
|
608
|
+
const reason = (/unknown option.*(--bg|--background)/i.test(err) ? "The laptop's Claude Code is too old for the bridge: run claude update there." : said ? `Claude Code said: ${said}` : `Claude Code stopped without answering (code ${code}).`).slice(0, 300);
|
|
611
609
|
settle({ outcome: "failed", reason });
|
|
612
610
|
}
|
|
613
611
|
this.listener?.changed();
|
|
614
612
|
});
|
|
613
|
+
child.stdin.on("error", () => undefined);
|
|
615
614
|
child.stdin.end(text);
|
|
616
615
|
});
|
|
617
616
|
}
|
|
@@ -636,6 +635,7 @@ export class ClaudeCodeHarness {
|
|
|
636
635
|
const s = this.session(newest.sessionId);
|
|
637
636
|
s.open = true;
|
|
638
637
|
s.inbox = s.inbox ?? (socket ? { socket, token: null } : null);
|
|
638
|
+
s.background ||= newest.kind === "background";
|
|
639
639
|
s.state = newest.status === "busy" ? "working" : newest.status === "waiting" ? "waiting" : "idle";
|
|
640
640
|
this.stateNow();
|
|
641
641
|
return s;
|
|
@@ -645,12 +645,8 @@ export class ClaudeCodeHarness {
|
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
647
|
// Stop in Gavel: the turn interrupted from its inbox (priority now), Claude then reading why; a
|
|
648
|
-
// resumed
|
|
648
|
+
// resumed session's too, in the background. Over when nothing runs.
|
|
649
649
|
async interrupt() {
|
|
650
|
-
if (this.resumed) {
|
|
651
|
-
this.resumed.kill("SIGINT");
|
|
652
|
-
return "stopped";
|
|
653
|
-
}
|
|
654
650
|
const open = this.current();
|
|
655
651
|
if (!open?.inbox || (open.state !== "working" && open.state !== "waiting"))
|
|
656
652
|
return "over";
|
package/dist/bridge/codex.js
CHANGED
|
@@ -150,15 +150,7 @@ async function codexQueue(session, text, cwd) {
|
|
|
150
150
|
throw new Error(firstLineOf(e.stderr ?? "") || e.message);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
//
|
|
154
|
-
// Nobody is at the laptop to allow it; the person hears what wasn't done (D-905, as exec did).
|
|
155
|
-
const DECLINE = {
|
|
156
|
-
"item/commandExecution/requestApproval": { result: { decision: "decline" }, what: "a command" },
|
|
157
|
-
"item/fileChange/requestApproval": { result: { decision: "decline" }, what: "a file change" },
|
|
158
|
-
"item/permissions/requestApproval": { result: { permissions: {}, scope: "turn" }, what: "more access" },
|
|
159
|
-
"item/tool/requestUserInput": { result: { answers: {} }, what: "a question for you" },
|
|
160
|
-
"mcpServer/elicitation/request": { result: { action: "decline", content: null, _meta: null }, what: "a tool's question" },
|
|
161
|
-
};
|
|
153
|
+
// ---------- The harness ----------
|
|
162
154
|
const SOURCES = ["cli", "vscode", "exec", "appServer"];
|
|
163
155
|
const HISTORY_TURNS = 30;
|
|
164
156
|
// After the person stops a turn at the laptop, Gavel's wake waits this long.
|
|
@@ -183,7 +175,6 @@ class CodexHarness {
|
|
|
183
175
|
// Threads the bridge loaded itself, with nobody at the laptop, and the turns it started there.
|
|
184
176
|
ownLoaded = new Set();
|
|
185
177
|
unattended = new Set();
|
|
186
|
-
declined = new Map();
|
|
187
178
|
// A message put in through Codex's queue has no client id: its copy joins it by its words.
|
|
188
179
|
queued = new Map();
|
|
189
180
|
state = null;
|
|
@@ -208,7 +199,10 @@ class CodexHarness {
|
|
|
208
199
|
if (state === this.state)
|
|
209
200
|
return;
|
|
210
201
|
this.state = state;
|
|
211
|
-
|
|
202
|
+
// Waiting in a session the bridge loaded itself: the person opens it on the laptop, where Codex
|
|
203
|
+
// shows what it asks, and answers there (D-1174).
|
|
204
|
+
const mine = state === "waiting" && this.current && this.ownLoaded.has(this.current.id) ? this.current.id : null;
|
|
205
|
+
this.listener?.state(state, mine ? `codex resume ${mine}` : null);
|
|
212
206
|
}
|
|
213
207
|
connect() {
|
|
214
208
|
if (this.app)
|
|
@@ -219,7 +213,7 @@ class CodexHarness {
|
|
|
219
213
|
// Codex's shared server, started first if none runs, as a Codex terminal does by itself.
|
|
220
214
|
async open() {
|
|
221
215
|
const socket = controlSocket(this.ctx.env, this.ctx.home);
|
|
222
|
-
const handlers = { notification: (method, params) => this.notified(method, params), serverRequest: (
|
|
216
|
+
const handlers = { notification: (method, params) => this.notified(method, params), serverRequest: () => undefined };
|
|
223
217
|
let app;
|
|
224
218
|
try {
|
|
225
219
|
app = await connectCodex(socket, handlers, cliVersion());
|
|
@@ -373,14 +367,8 @@ class CodexHarness {
|
|
|
373
367
|
this.turnId = null;
|
|
374
368
|
if (turn.status === "interrupted")
|
|
375
369
|
this.stoppedAt = Date.now();
|
|
376
|
-
const declined = this.declined.get(turn.id);
|
|
377
|
-
if (declined?.length) {
|
|
378
|
-
const some = [...new Set(declined)].join(", ");
|
|
379
|
-
this.listener?.note(`Codex didn't do what it would have asked you about first (${some}): nobody was at the laptop to allow it. Allow it in the session there, or answer here.`);
|
|
380
|
-
}
|
|
381
370
|
if (turn.status === "failed" && this.unattended.has(turn.id))
|
|
382
371
|
this.listener?.note(`Codex couldn't finish: ${turn.error?.message ?? "the turn failed"}`.slice(0, 300));
|
|
383
|
-
this.declined.delete(turn.id);
|
|
384
372
|
this.unattended.delete(turn.id);
|
|
385
373
|
this.listener?.changed();
|
|
386
374
|
if (this.announced.delete(turn.id))
|
|
@@ -389,17 +377,6 @@ class CodexHarness {
|
|
|
389
377
|
}
|
|
390
378
|
}
|
|
391
379
|
}
|
|
392
|
-
// A request Codex puts to its clients. The person's own Codex gets it too and answers it; the bridge
|
|
393
|
-
// answers only in a session it opened itself, which nobody has typed in at the laptop since.
|
|
394
|
-
asked(request) {
|
|
395
|
-
const threadId = typeof request.params.threadId === "string" ? request.params.threadId : null;
|
|
396
|
-
const turnId = typeof request.params.turnId === "string" ? request.params.turnId : null;
|
|
397
|
-
const decline = DECLINE[request.method];
|
|
398
|
-
if (!threadId || !turnId || !decline || !this.ownLoaded.has(threadId))
|
|
399
|
-
return;
|
|
400
|
-
this.app?.respond(request.id, decline.result);
|
|
401
|
-
this.declined.set(turnId, [...(this.declined.get(turnId) ?? []), decline.what]);
|
|
402
|
-
}
|
|
403
380
|
// Into the newest session: started on its turn when idle, steering it while it runs (turn/start does
|
|
404
381
|
// either); loaded first when nobody has it open, or a new session when the folder has none.
|
|
405
382
|
async put(app, input, clientUserMessageId, words, wake) {
|
package/package.json
CHANGED