@getgavel/cli 0.1.20 → 0.1.21

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gavel",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
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" },
@@ -110,6 +110,9 @@ const PUSH_EVERY_MS = 2000;
110
110
  // stay this far apart while things keep changing: each counts in the agent's 120 calls a minute.
111
111
  const PUSH_SOON_MS = 50;
112
112
  const PUSH_GAP_MS = 500;
113
+ // For this long after a delivery or a turn's end, the session's copy of the message or the turn's
114
+ // last words skip the gap (still never more than three pushes in a second).
115
+ const PUSH_URGENT_MS = 2000;
113
116
  const WAKE_AGAIN_MS = 60_000;
114
117
  // Gavel's one-line wake (D-1103, cloud-agents' wakePrompt): each ref once, what has none by its kind.
115
118
  export const wakeLineOf = (items) => {
@@ -172,6 +175,8 @@ async function harnessBridge(h, harness, setup, ctx) {
172
175
  };
173
176
  let syncing = null;
174
177
  let pushedAt = 0;
178
+ let urgentUntil = 0;
179
+ const pushes = [];
175
180
  const pushOnce = async () => {
176
181
  if (!on)
177
182
  return;
@@ -188,6 +193,7 @@ async function harnessBridge(h, harness, setup, ctx) {
188
193
  const part = messages.slice(i, i + 200);
189
194
  const res = await call(api, "PUT", "/v1/agents/me/chat/transcript", { thread: t.thread, label: t.label, messages: part });
190
195
  pushedAt = Date.now();
196
+ pushes.push(pushedAt);
191
197
  if (!res.ok)
192
198
  throw new Error(`HTTP ${res.status} sending the session's words`);
193
199
  if (!(await res.json()).on)
@@ -205,11 +211,23 @@ async function harnessBridge(h, harness, setup, ctx) {
205
211
  await push();
206
212
  };
207
213
  let soon = null;
214
+ let soonAt = 0;
208
215
  const pushSoon = () => {
209
- soon ??= setTimeout(() => {
216
+ const now = Date.now();
217
+ while (pushes.length && pushes[0] <= now - 1000)
218
+ pushes.shift();
219
+ const gap = now < urgentUntil && pushes.length < 3 ? 0 : PUSH_GAP_MS;
220
+ const at = now + Math.max(PUSH_SOON_MS, pushedAt + gap - now);
221
+ if (soon) {
222
+ if (soonAt <= at)
223
+ return;
224
+ clearTimeout(soon);
225
+ }
226
+ soonAt = at;
227
+ soon = setTimeout(() => {
210
228
  soon = null;
211
229
  void pushAfter();
212
- }, Math.max(PUSH_SOON_MS, pushedAt + PUSH_GAP_MS - Date.now()));
230
+ }, at - now);
213
231
  };
214
232
  const note = async (text) => {
215
233
  await pushAfter();
@@ -233,8 +251,10 @@ async function harnessBridge(h, harness, setup, ctx) {
233
251
  return;
234
252
  }
235
253
  const events = joined(outgoing.splice(0));
236
- if (events.some((e) => e.event === "end"))
254
+ if (events.some((e) => e.event === "end")) {
255
+ urgentUntil = Date.now() + PUSH_URGENT_MS;
237
256
  await pushAfter();
257
+ }
238
258
  for (let i = 0; i < events.length; i += 200) {
239
259
  const res = await call(api, "POST", `/v1/agents/me/chat/live?bridge=${id}`, { ...(thread ? { thread } : {}), events: events.slice(i, i + 200) });
240
260
  void res.body?.cancel();
@@ -302,6 +322,7 @@ async function harnessBridge(h, harness, setup, ctx) {
302
322
  const deliver = async (m) => {
303
323
  try {
304
324
  const { paths, missed } = await fetchPictures(m.images ?? []);
325
+ urgentUntil = Date.now() + PUSH_URGENT_MS;
305
326
  const result = await h.deliver({ id: m.id, text: m.text, decision: m.decision, pictures: paths });
306
327
  if (result.outcome === "left") {
307
328
  if (!left.has(m.id))
@@ -163,6 +163,9 @@ const SOURCES = ["cli", "vscode", "exec", "appServer"];
163
163
  const HISTORY_TURNS = 30;
164
164
  // After the person stops a turn at the laptop, Gavel's wake waits this long.
165
165
  const QUIET_AFTER_STOP_MS = 2 * 60_000;
166
+ // A thread the bridge started isn't in thread/list at first (60 to 200 ms in Codex 0.172.0); until
167
+ // it is, for at most this long, it stays the session.
168
+ const UNLISTED_MS = 10_000;
166
169
  const reasonOf = (err) => (err instanceof Error ? err.message : String(err));
167
170
  const notRunning = (err) => err instanceof WebSocketError && (err.code === "ENOENT" || err.code === "ECONNREFUSED");
168
171
  class CodexHarness {
@@ -185,6 +188,7 @@ class CodexHarness {
185
188
  queued = new Map();
186
189
  state = null;
187
190
  stoppedAt = 0;
191
+ started = null;
188
192
  constructor(ctx) {
189
193
  this.ctx = ctx;
190
194
  }
@@ -276,23 +280,27 @@ class CodexHarness {
276
280
  const app = await this.connect();
277
281
  const cwd = [...new Set([this.ctx.cwd, realpath(this.ctx.cwd)])];
278
282
  const { data } = await app.request("thread/list", { cwd, sortKey: "updated_at", sortDirection: "desc", limit: 10, sourceKinds: SOURCES, useStateDbOnly: true });
279
- const top = data.find((t) => !t.parentThreadId && !t.ephemeral);
280
- if (!top) {
281
- this.current = null;
282
- this.setState("closed");
283
- return null;
284
- }
285
- if (this.current?.id !== top.id) {
286
- this.current = { id: top.id, status: top.status, path: top.path, subscribed: false };
287
- this.words.clear();
288
- this.offsets.clear();
289
- this.turnId = null;
290
- await this.history(app, top.id, HISTORY_TURNS);
291
- }
292
- else if (!this.current.subscribed) {
293
- this.current.status = top.status;
294
- // Not heard live (open elsewhere, or closed): its newest turns, read again.
295
- await this.history(app, top.id, 3);
283
+ const tops = data.filter((t) => !t.parentThreadId && !t.ephemeral);
284
+ const mine = this.current && this.started?.id === this.current.id && Date.now() - this.started.at < UNLISTED_MS ? this.current : null;
285
+ if (!mine || tops.some((t) => t.id === mine.id)) {
286
+ const top = tops[0];
287
+ if (!top) {
288
+ this.current = null;
289
+ this.setState("closed");
290
+ return null;
291
+ }
292
+ if (this.current?.id !== top.id) {
293
+ this.current = { id: top.id, status: top.status, path: top.path, subscribed: false };
294
+ this.words.clear();
295
+ this.offsets.clear();
296
+ this.turnId = null;
297
+ await this.history(app, top.id, HISTORY_TURNS);
298
+ }
299
+ else if (!this.current.subscribed) {
300
+ this.current.status = top.status;
301
+ // Not heard live (open elsewhere, or closed): its newest turns, read again.
302
+ await this.history(app, top.id, 3);
303
+ }
296
304
  }
297
305
  const current = this.current;
298
306
  if (!current.subscribed && current.status.type !== "notLoaded")
@@ -400,6 +408,7 @@ class CodexHarness {
400
408
  if (!current) {
401
409
  const { thread } = await app.request("thread/start", { cwd: this.ctx.cwd });
402
410
  current = this.current = { id: thread.id, status: thread.status, path: thread.path, subscribed: true };
411
+ this.started = { id: thread.id, at: Date.now() };
403
412
  this.words.clear();
404
413
  this.ownLoaded.add(thread.id);
405
414
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getgavel/cli",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
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",