@getgavel/cli 0.1.15 → 0.1.17
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 +9 -0
- package/README.md +1 -0
- package/dist/bridge/background.js +397 -0
- package/dist/bridge/bridge.js +324 -247
- package/dist/bridge/claude-code.js +0 -96
- package/dist/bridge/claude-live.js +625 -0
- package/dist/bridge/codex-app.js +135 -0
- package/dist/bridge/codex.js +440 -77
- package/dist/bridge/harness.js +1 -0
- package/dist/bridge/service.js +134 -0
- package/dist/bridge/setup.js +27 -18
- package/dist/bridge/websocket.js +166 -0
- package/dist/gavel.js +251 -42
- package/dist/hook.js +67 -7
- package/dist/output.js +14 -0
- package/hooks/hooks.json +30 -0
- package/package.json +5 -2
- package/skills/gavel/SKILL.md +30 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { openWebSocket } from "./websocket.js";
|
|
5
|
+
// A client of Codex's app-server (developers.openai.com/codex/app-server): JSON-RPC 2.0 without its
|
|
6
|
+
// "jsonrpc" field, over the shared background server's control socket that every Codex terminal
|
|
7
|
+
// attaches to (Codex's daemon, `daemon_auto_start`, 0.158 and later), so the bridge sees and steers
|
|
8
|
+
// the very session the person has open.
|
|
9
|
+
export const CLIENT_NAME = "gavel_bridge";
|
|
10
|
+
// Notifications the bridge never reads: reasoning, commands' and files' output, plans, diffs and the
|
|
11
|
+
// like. Codex leaves them off this connection, so they never even reach the bridge (D-894).
|
|
12
|
+
const UNREAD = [
|
|
13
|
+
"item/reasoning/summaryTextDelta",
|
|
14
|
+
"item/reasoning/summaryPartAdded",
|
|
15
|
+
"item/reasoning/textDelta",
|
|
16
|
+
"item/commandExecution/outputDelta",
|
|
17
|
+
"item/commandExecution/terminalInteraction",
|
|
18
|
+
"item/fileChange/outputDelta",
|
|
19
|
+
"item/fileChange/patchUpdated",
|
|
20
|
+
"item/plan/delta",
|
|
21
|
+
"item/mcpToolCall/progress",
|
|
22
|
+
"turn/diff/updated",
|
|
23
|
+
"turn/plan/updated",
|
|
24
|
+
"thread/tokenUsage/updated",
|
|
25
|
+
"command/exec/outputDelta",
|
|
26
|
+
"process/outputDelta",
|
|
27
|
+
"process/exited",
|
|
28
|
+
"rawResponseItem/completed",
|
|
29
|
+
"rawResponse/completed",
|
|
30
|
+
"fs/changed",
|
|
31
|
+
"thread/realtime/item/transcript/delta",
|
|
32
|
+
"thread/realtime/transcript/delta",
|
|
33
|
+
"thread/realtime/outputAudio/delta",
|
|
34
|
+
];
|
|
35
|
+
// Codex's own default: $CODEX_HOME/app-server-control/app-server-control.sock.
|
|
36
|
+
export const controlSocket = (env, home) => join(env.CODEX_HOME ?? join(home, ".codex"), "app-server-control", "app-server-control.sock");
|
|
37
|
+
export class CodexRpcError extends Error {
|
|
38
|
+
code;
|
|
39
|
+
constructor(message, code) {
|
|
40
|
+
super(message);
|
|
41
|
+
this.code = code;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// The socket where it really is: Codex keeps it as a link to a short path, since a socket's own path
|
|
45
|
+
// can't be longer than about 100 bytes (macOS's limit), which a deep CODEX_HOME passes.
|
|
46
|
+
function resolved(path) {
|
|
47
|
+
try {
|
|
48
|
+
return realpathSync(path);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return path;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export async function connectCodex(socketPath, handlers, clientVersion) {
|
|
55
|
+
const pending = new Map();
|
|
56
|
+
let next = 1;
|
|
57
|
+
const socket = await openWebSocket(resolved(socketPath), {
|
|
58
|
+
message(text) {
|
|
59
|
+
let msg;
|
|
60
|
+
try {
|
|
61
|
+
msg = JSON.parse(text);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (msg.method && msg.id !== undefined)
|
|
67
|
+
handlers.serverRequest({ id: msg.id, method: msg.method, params: msg.params ?? {} });
|
|
68
|
+
else if (msg.method)
|
|
69
|
+
handlers.notification(msg.method, msg.params ?? {});
|
|
70
|
+
else if (typeof msg.id === "number") {
|
|
71
|
+
const waiting = pending.get(msg.id);
|
|
72
|
+
if (!waiting)
|
|
73
|
+
return;
|
|
74
|
+
pending.delete(msg.id);
|
|
75
|
+
clearTimeout(waiting.timer);
|
|
76
|
+
if (msg.error)
|
|
77
|
+
waiting.reject(new CodexRpcError(msg.error.message ?? "Codex refused the request", msg.error.code ?? 0));
|
|
78
|
+
else
|
|
79
|
+
waiting.resolve(msg.result);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
void socket.closed.then((why) => {
|
|
84
|
+
for (const [id, waiting] of pending) {
|
|
85
|
+
clearTimeout(waiting.timer);
|
|
86
|
+
waiting.reject(new CodexRpcError(`Codex's server went away (${why ?? "closed"})`, -1));
|
|
87
|
+
pending.delete(id);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const request = (method, params, timeoutMs = 30_000) => new Promise((resolve, reject) => {
|
|
91
|
+
const id = next++;
|
|
92
|
+
const timer = setTimeout(() => {
|
|
93
|
+
pending.delete(id);
|
|
94
|
+
reject(new CodexRpcError(`Codex didn't answer ${method} in time`, -2));
|
|
95
|
+
}, timeoutMs);
|
|
96
|
+
pending.set(id, { resolve: resolve, reject, timer });
|
|
97
|
+
socket.send(JSON.stringify(params === undefined ? { method, id } : { method, id, params }));
|
|
98
|
+
});
|
|
99
|
+
try {
|
|
100
|
+
const init = await request("initialize", {
|
|
101
|
+
clientInfo: { name: CLIENT_NAME, title: "Gavel bridge", version: clientVersion },
|
|
102
|
+
capabilities: { experimentalApi: false, requestAttestation: false, optOutNotificationMethods: UNREAD },
|
|
103
|
+
}, 10_000);
|
|
104
|
+
socket.send(JSON.stringify({ method: "initialized" }));
|
|
105
|
+
return {
|
|
106
|
+
request,
|
|
107
|
+
respond: (id, result) => socket.send(JSON.stringify({ id, result })),
|
|
108
|
+
version: /\/(\d+\.\d+\.\d+)/.exec(init.userAgent ?? "")?.[1] ?? null,
|
|
109
|
+
closed: socket.closed,
|
|
110
|
+
close: () => socket.close(),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
socket.close();
|
|
115
|
+
throw err;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const firstLine = (text) => text.split("\n").map((l) => l.trim()).find(Boolean) ?? "";
|
|
119
|
+
// Starts Codex's own background server when none runs (what a Codex terminal does by itself):
|
|
120
|
+
// idempotent, back once it answers on the control socket. Null when it started; else why not.
|
|
121
|
+
export function startCodexServer(cwd, env) {
|
|
122
|
+
return new Promise((resolve) => {
|
|
123
|
+
execFile("codex", ["app-server", "daemon", "start"], { cwd, env, timeout: 90_000 }, (err, _stdout, stderr) => {
|
|
124
|
+
if (!err)
|
|
125
|
+
return resolve(null);
|
|
126
|
+
const e = err;
|
|
127
|
+
if (e.code === "ENOENT")
|
|
128
|
+
return resolve("Codex's codex command isn't on the laptop's PATH where the bridge runs.");
|
|
129
|
+
const said = firstLine(String(stderr ?? ""));
|
|
130
|
+
if (/unrecognized subcommand|unexpected argument|invalid value/i.test(said))
|
|
131
|
+
return resolve("This Codex has no background server for the bridge to join: run codex update.");
|
|
132
|
+
resolve(`Codex's background server didn't start${said ? `: ${said}` : "."}`.slice(0, 300));
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|