@getgavel/cli 0.1.31 → 0.1.32
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.
|
|
3
|
+
"version": "0.1.32",
|
|
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
|
@@ -5,7 +5,7 @@ import { basename, join } from "node:path";
|
|
|
5
5
|
import { jsonText } from "../output.js";
|
|
6
6
|
import { markChatOff, onHookEvent, STATUS_LINE_EVENT } from "./background.js";
|
|
7
7
|
import { claudeDayReporter, DAYS_EVERY_MS } from "./claude-days.js";
|
|
8
|
-
import { accountOf, claudePlanReporter, planUsageOf, usageBody } from "./claude-plan.js";
|
|
8
|
+
import { accountOf, checkClaudeExtra, claudePlanReporter, planUsageOf, usageBody } from "./claude-plan.js";
|
|
9
9
|
import { claudeSessions } from "./claude-code.js";
|
|
10
10
|
import { ClaudeCodeHarness } from "./claude-live.js";
|
|
11
11
|
import { codexHarness, codexSessions } from "./codex.js";
|
|
@@ -141,6 +141,7 @@ const PICTURE_KEEP_MS = 15 * 60_000;
|
|
|
141
141
|
// Live pieces go at most twice a second (the live route's own limit, 240 a minute an agent).
|
|
142
142
|
const LIVE_EVERY_MS = 500;
|
|
143
143
|
const LIVE_PIECE = 20_000;
|
|
144
|
+
const LONG_TEXT = 8_000;
|
|
144
145
|
const PUSH_EVERY_MS = 2000;
|
|
145
146
|
// What changed goes this long after (what changes with it goes along), and pushes that send words
|
|
146
147
|
// stay this far apart while things keep changing: each counts in the agent's 120 calls a minute.
|
|
@@ -367,6 +368,16 @@ async function harnessBridge(initial, harness, setup, ctx) {
|
|
|
367
368
|
}
|
|
368
369
|
return { paths, missed };
|
|
369
370
|
};
|
|
371
|
+
// A long message goes to a private file the software reads: a session's inbox can't carry 50,000
|
|
372
|
+
// characters whole (W-289).
|
|
373
|
+
const longAsFile = (text) => {
|
|
374
|
+
if (text.length <= LONG_TEXT)
|
|
375
|
+
return text;
|
|
376
|
+
const file = join(pictures, `${randomUUID()}.md`);
|
|
377
|
+
writeFileSync(file, text, { mode: 0o600 });
|
|
378
|
+
setTimeout(() => rmSync(file, { force: true }), PICTURE_KEEP_MS).unref();
|
|
379
|
+
return `${text.slice(0, 1_000)}\n\n[This message is ${text.length} characters, so it's longer than fits here. Read all of it, from its start, in the file ${file}, and answer that.]`;
|
|
380
|
+
};
|
|
370
381
|
let launchQueue = Promise.resolve();
|
|
371
382
|
const launch = (run) => {
|
|
372
383
|
const chosen = launchQueue.then(run);
|
|
@@ -379,7 +390,7 @@ async function harnessBridge(initial, harness, setup, ctx) {
|
|
|
379
390
|
urgentUntil = Date.now() + PUSH_URGENT_MS;
|
|
380
391
|
const result = await launch(async () => {
|
|
381
392
|
const route = await pick(null, "chat");
|
|
382
|
-
return route.allowed ? h.deliver({ id: m.id, text: m.text, decision: m.decision, pictures: paths }, route.fresh, route.run) : null;
|
|
393
|
+
return route.allowed ? h.deliver({ id: m.id, text: longAsFile(m.text), decision: m.decision, pictures: paths }, route.fresh, route.run) : null;
|
|
383
394
|
});
|
|
384
395
|
if (!result)
|
|
385
396
|
return;
|
|
@@ -466,6 +477,7 @@ async function harnessBridge(initial, harness, setup, ctx) {
|
|
|
466
477
|
const mine = { model: run.harness === activeHarness ? run.model : null, effort: run.effort, context: run.context };
|
|
467
478
|
return { allowed: true, fresh: chosen.fresh ? { ...chosen.fresh, ...mine } : null, run: mine };
|
|
468
479
|
};
|
|
480
|
+
const checkedExtra = new Map();
|
|
469
481
|
const pickPlan = async (fresh, job = "wake") => {
|
|
470
482
|
if (!machineId || busy() || (!fresh && thread && state === "idle"))
|
|
471
483
|
return { allowed: true, fresh };
|
|
@@ -479,6 +491,22 @@ async function harnessBridge(initial, harness, setup, ctx) {
|
|
|
479
491
|
if (res.status === 404)
|
|
480
492
|
return { allowed: true, fresh };
|
|
481
493
|
const route = res.ok ? await answer(res) : null;
|
|
494
|
+
const observe = route?.observeExtraPlanId;
|
|
495
|
+
if (observe && planIdPattern.test(observe) && Date.now() - (checkedExtra.get(observe) ?? 0) >= 3_600_000) {
|
|
496
|
+
const probeEnv = planEnvironment(ctx, observe, "claude-code");
|
|
497
|
+
if (probeEnv) {
|
|
498
|
+
checkedExtra.set(observe, Date.now());
|
|
499
|
+
void checkClaudeExtra(ctx.cwd, probeEnv).then(async (extraUsageAvailable) => {
|
|
500
|
+
if (extraUsageAvailable === null)
|
|
501
|
+
return;
|
|
502
|
+
const reported = await call(api, "POST", "/v1/agents/me/plan/usage", {
|
|
503
|
+
...usageBody(observe, { windows: [], limitReached: false, spendLimit: null }, new Date()), machineId, extraUsageAvailable,
|
|
504
|
+
});
|
|
505
|
+
if (reported.ok)
|
|
506
|
+
retryPlanAt = 0;
|
|
507
|
+
}).catch(() => undefined);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
482
510
|
if (route?.why === "unmanaged")
|
|
483
511
|
return { allowed: true, fresh };
|
|
484
512
|
if (route?.why === "wait") {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createInterface } from "node:readline";
|
|
1
3
|
import { createHash } from "node:crypto";
|
|
2
4
|
import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
3
5
|
import { hostname } from "node:os";
|
|
@@ -99,6 +101,43 @@ export function claudeAccount(home, env = process.env) {
|
|
|
99
101
|
return null;
|
|
100
102
|
}
|
|
101
103
|
}
|
|
104
|
+
// Claude's native headless stream reports whether the subscription can use overage. A
|
|
105
|
+
// deliberately short turn gives the bridge this signal even without an attached status line.
|
|
106
|
+
export async function checkClaudeExtra(cwd, env) {
|
|
107
|
+
const { CLAUDECODE: _nested, ...nativeEnv } = env;
|
|
108
|
+
const child = spawn("claude", [
|
|
109
|
+
"-p", "--no-session-persistence", "--tools", "", "--model", "haiku", "--setting-sources", "",
|
|
110
|
+
"--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--output-format", "stream-json", "--verbose",
|
|
111
|
+
"Reply with OK.",
|
|
112
|
+
], { cwd, env: nativeEnv, stdio: ["ignore", "pipe", "ignore"] });
|
|
113
|
+
const lines = createInterface({ input: child.stdout });
|
|
114
|
+
let available = null;
|
|
115
|
+
lines.on("line", (line) => {
|
|
116
|
+
try {
|
|
117
|
+
const event = JSON.parse(line);
|
|
118
|
+
if (event.type !== "rate_limit_event")
|
|
119
|
+
return;
|
|
120
|
+
const status = event.rate_limit_info?.overageStatus;
|
|
121
|
+
if (status === "allowed" || status === "allowed_warning")
|
|
122
|
+
available = true;
|
|
123
|
+
if (status === "rejected")
|
|
124
|
+
available = false;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Only native numeric usage and the overage flag are reportable.
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return new Promise((resolve) => {
|
|
131
|
+
const timer = setTimeout(() => child.kill(), 15_000);
|
|
132
|
+
const done = () => {
|
|
133
|
+
clearTimeout(timer);
|
|
134
|
+
lines.close();
|
|
135
|
+
resolve(available);
|
|
136
|
+
};
|
|
137
|
+
child.once("error", done);
|
|
138
|
+
child.once("close", done);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
102
141
|
// Which account first reported under each plan, kept beside the bridge's locks (mode 600).
|
|
103
142
|
function accountsFile(home) {
|
|
104
143
|
return join(home, ".gavel", "bridge", "plan-accounts.json");
|
package/package.json
CHANGED