jevgate 0.1.1 → 0.2.0
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/LICENSE +21 -0
- package/jevgate.js +61 -13
- package/package.json +7 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 remotehost
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/jevgate.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// jevgate — one binary, zero dependencies.
|
|
3
3
|
// jevgate init write the hooks into Claude Code and codex
|
|
4
|
-
// jevgate login
|
|
4
|
+
// jevgate login sign in from the browser (no token to paste)
|
|
5
5
|
// jevgate decide (called by the harness) stdin JSON → decision JSON or nothing
|
|
6
6
|
// jevgate status endpoint, token, usage
|
|
7
7
|
// jevgate log last decisions
|
|
8
8
|
import fs from "node:fs";
|
|
9
9
|
import os from "node:os";
|
|
10
10
|
import path from "node:path";
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
11
13
|
|
|
12
14
|
const HOME = os.homedir();
|
|
13
15
|
const DIR = path.join(HOME, ".jevgate");
|
|
@@ -16,10 +18,16 @@ const LOG = path.join(DIR, "decisions.jsonl");
|
|
|
16
18
|
const endpoint = () => process.env.JEVGATE_ENDPOINT || config().endpoint || "https://jevgate.dev";
|
|
17
19
|
const TIMEOUT_MS = Number(process.env.JEVGATE_TIMEOUT_MS || 2500);
|
|
18
20
|
// The hook runs on every permission request, so it must not pay npx's resolver
|
|
19
|
-
// each time
|
|
20
|
-
//
|
|
21
|
+
// each time, and it must not point into npx's cache (pruned by `npm cache clean`,
|
|
22
|
+
// re-hashed on the next version). `init` copies this script to a stable home and
|
|
23
|
+
// points the hooks there; re-running init after an upgrade refreshes the copy.
|
|
21
24
|
const SELF = new URL(import.meta.url).pathname;
|
|
22
|
-
const
|
|
25
|
+
const BIN = path.join(DIR, "bin", "jevgate.js");
|
|
26
|
+
const HOOK_CMD = `node "${BIN}" decide`;
|
|
27
|
+
function installStableCopy() {
|
|
28
|
+
fs.mkdirSync(path.dirname(BIN), { recursive: true });
|
|
29
|
+
if (path.resolve(SELF) !== path.resolve(BIN)) fs.copyFileSync(SELF, BIN);
|
|
30
|
+
}
|
|
23
31
|
|
|
24
32
|
const readJson = (p, fallback) => { try { return JSON.parse(fs.readFileSync(p, "utf8")); } catch { return fallback; } };
|
|
25
33
|
const writeJson = (p, v) => { fs.mkdirSync(path.dirname(p), { recursive: true }); fs.writeFileSync(p, JSON.stringify(v, null, 2) + "\n"); };
|
|
@@ -57,7 +65,7 @@ async function decide() {
|
|
|
57
65
|
if (!res.ok) { appendLog({ ...meta(event, started), outcome: "error", status: res.status }); return; }
|
|
58
66
|
result = await res.json();
|
|
59
67
|
} catch (err) {
|
|
60
|
-
appendLog({ ...meta(event, started), outcome: "error", error: String(err?.name || err) });
|
|
68
|
+
appendLog({ ...meta(event, started), outcome: "error", error: String(err?.cause?.code || err?.name || err) });
|
|
61
69
|
return; // any failure → harness proceeds as usual
|
|
62
70
|
} finally { clearTimeout(timer); }
|
|
63
71
|
|
|
@@ -128,6 +136,8 @@ function codexTask(sessionId) {
|
|
|
128
136
|
// ---------------------------------------------------------------- init
|
|
129
137
|
function init() {
|
|
130
138
|
const results = [];
|
|
139
|
+
installStableCopy();
|
|
140
|
+
results.push(`installed ${BIN}`);
|
|
131
141
|
// Claude Code: PermissionRequest fires exactly when a permission prompt would
|
|
132
142
|
// appear. Allowing there skips the prompt; saying nothing shows it as usual.
|
|
133
143
|
const claude = path.join(HOME, ".claude", "settings.json");
|
|
@@ -149,7 +159,8 @@ function init() {
|
|
|
149
159
|
if (added) results.push("codex: open codex once and accept the jevgate hook when it asks (it verifies new hooks)");
|
|
150
160
|
} else results.push("codex: not found (~/.codex)");
|
|
151
161
|
for (const r of results) console.log(" " + r);
|
|
152
|
-
if (!config().token)
|
|
162
|
+
if (!config().token) return login();
|
|
163
|
+
console.log(` signed in as ${config().email || "(token on file)"}`);
|
|
153
164
|
}
|
|
154
165
|
const isOurs = (h) => /jevgate(\.js)?"? decide\b/.test(h?.command || "");
|
|
155
166
|
// Idempotent: one jevgate group per event, always pointing at this script.
|
|
@@ -164,10 +175,47 @@ function addHook(hooks, eventName, matcher, timeout) {
|
|
|
164
175
|
}
|
|
165
176
|
|
|
166
177
|
// ---------------------------------------------------------------- misc
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
178
|
+
// Sign in from the browser. The CLI asks the server for a device code, opens the
|
|
179
|
+
// login page, and polls until the emailed link is clicked. The token never passes
|
|
180
|
+
// through a human. `jevgate login --token <t>` remains for automation.
|
|
181
|
+
async function login(arg, arg2) {
|
|
182
|
+
if (arg === "--token" && arg2) {
|
|
183
|
+
writeJson(CONFIG, { ...config(), token: arg2, endpoint: endpoint() });
|
|
184
|
+
console.log(" token saved to ~/.jevgate/config.json");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const base = endpoint();
|
|
188
|
+
let start;
|
|
189
|
+
try {
|
|
190
|
+
const r = await fetch(`${base}/api/v1/device/start`, { method: "POST" });
|
|
191
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
192
|
+
start = await r.json();
|
|
193
|
+
} catch (e) { console.error(` could not reach ${base}: ${e.message}`); process.exit(1); }
|
|
194
|
+
console.log(`\n Confirm this device in your browser: ${start.url}`);
|
|
195
|
+
console.log(` Code: ${start.code} (opening the page for you)\n`);
|
|
196
|
+
openBrowser(start.url);
|
|
197
|
+
const deadline = Date.now() + (start.expires_in || 900) * 1000;
|
|
198
|
+
let shownEmail = false;
|
|
199
|
+
while (Date.now() < deadline) {
|
|
200
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
201
|
+
let st;
|
|
202
|
+
try { st = await (await fetch(`${base}/api/v1/device/poll?code=${encodeURIComponent(start.code)}&poll=${encodeURIComponent(start.poll)}`)).json(); }
|
|
203
|
+
catch { continue; }
|
|
204
|
+
if (st.status === "emailed" && !shownEmail) { console.log(` Sign-in link sent to ${st.email}. Waiting for the click…`); shownEmail = true; }
|
|
205
|
+
if (st.status === "done" && st.token) {
|
|
206
|
+
writeJson(CONFIG, { ...config(), token: st.token, email: st.email, endpoint: base });
|
|
207
|
+
console.log(` Signed in as ${st.email} (${st.plan}). Token saved to ~/.jevgate/config.json`);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (st.status === "expired" || st.status === "forbidden") { console.error(" login expired. Run `jevgate login` again."); process.exit(1); }
|
|
211
|
+
}
|
|
212
|
+
console.error(" login timed out. Run `jevgate login` again."); process.exit(1);
|
|
213
|
+
}
|
|
214
|
+
function openBrowser(url) {
|
|
215
|
+
const { spawn } = require("node:child_process");
|
|
216
|
+
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
217
|
+
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
218
|
+
try { spawn(cmd, args, { stdio: "ignore", detached: true }).unref(); } catch {}
|
|
171
219
|
}
|
|
172
220
|
async function status() {
|
|
173
221
|
const cfg = config();
|
|
@@ -191,6 +239,6 @@ function log(n = 20) {
|
|
|
191
239
|
// Piped output (jevgate log | head) must not crash the process.
|
|
192
240
|
process.stdout.on("error", (e) => { if (e.code === "EPIPE") process.exit(0); });
|
|
193
241
|
|
|
194
|
-
const [cmd, arg] = process.argv.slice(2);
|
|
195
|
-
({ decide, init, login: () => login(arg), status, log: () => log(Number(arg) || 20) }[cmd] ||
|
|
196
|
-
(() => console.log("usage: jevgate <init|login
|
|
242
|
+
const [cmd, arg, arg2] = process.argv.slice(2);
|
|
243
|
+
({ decide, init, login: () => login(arg, arg2), status, log: () => log(Number(arg) || 20) }[cmd] ||
|
|
244
|
+
(() => console.log("usage: jevgate <init|login|decide|status|log>")))();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jevgate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Auto-approve the benign majority of agent tool calls in ~300ms, with a probability and an audit log. Escalates the rest. Never denies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codex",
|
|
@@ -17,16 +17,20 @@
|
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"type": "module",
|
|
19
19
|
"bin": {
|
|
20
|
-
"jevgate": "
|
|
20
|
+
"jevgate": "jevgate.js"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"jevgate.js",
|
|
24
|
-
"README.md"
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
25
26
|
],
|
|
26
27
|
"engines": {
|
|
27
28
|
"node": ">=18"
|
|
28
29
|
},
|
|
29
30
|
"publishConfig": {
|
|
30
31
|
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://jevgate.dev"
|
|
31
35
|
}
|
|
32
36
|
}
|