token-goat 2.9.26 → 2.9.29
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/README.md +30 -88
- package/SECURITY.md +14 -0
- package/dist/{token-goat-chunk-OZRSREKR.mjs → token-goat-chunk-2AWQ2R5X.mjs} +2 -2
- package/dist/{token-goat-chunk-BH4ZVRB2.mjs → token-goat-chunk-2NNUA2LR.mjs} +4 -4
- package/dist/token-goat-chunk-2WOUYWLM.mjs +955 -0
- package/dist/{token-goat-chunk-IKZLSRII.mjs → token-goat-chunk-435UQTKD.mjs} +5 -3
- package/dist/{token-goat-chunk-62IHOU6L.mjs → token-goat-chunk-44BM7DDQ.mjs} +5 -3
- package/dist/token-goat-chunk-52NSDWYY.mjs +96 -0
- package/dist/{token-goat-chunk-CXBOFPF4.mjs → token-goat-chunk-67BNIKKO.mjs} +32 -18
- package/dist/{token-goat-chunk-XBESNWEX.mjs → token-goat-chunk-6AK46ZT7.mjs} +2 -3
- package/dist/{token-goat-chunk-7SXPJOSZ.mjs → token-goat-chunk-7CPMDFGB.mjs} +166 -40
- package/dist/token-goat-chunk-ASLWOQ3I.mjs +14 -0
- package/dist/{token-goat-chunk-MWID3YOY.mjs → token-goat-chunk-BGYOZ6DO.mjs} +6 -4
- package/dist/{token-goat-chunk-PAV6NNY7.mjs → token-goat-chunk-C5YPNZKQ.mjs} +22 -8
- package/dist/{token-goat-chunk-D2X7XN5M.mjs → token-goat-chunk-CIQ2FTY3.mjs} +23 -242
- package/dist/token-goat-chunk-D4ETHJD6.mjs +246 -0
- package/dist/{token-goat-chunk-7Y6GWTII.mjs → token-goat-chunk-DNRPXHYH.mjs} +25 -17
- package/dist/{token-goat-chunk-L43RKNHA.mjs → token-goat-chunk-DNSPXQXQ.mjs} +2 -2
- package/dist/token-goat-chunk-DPNLUJWB.mjs +220 -0
- package/dist/token-goat-chunk-E4ZOJIZK.mjs +1382 -0
- package/dist/token-goat-chunk-E5TK5DNO.mjs +718 -0
- package/dist/{token-goat-chunk-VVROQBQJ.mjs → token-goat-chunk-EUSDXRXU.mjs} +62 -12
- package/dist/{token-goat-chunk-POOI26O6.mjs → token-goat-chunk-FTP4U4QA.mjs} +12 -8
- package/dist/token-goat-chunk-G23DWHV4.mjs +142 -0
- package/dist/{token-goat-chunk-MDV5VWF4.mjs → token-goat-chunk-G7IWXCFF.mjs} +223 -15
- package/dist/{token-goat-chunk-C2PG4K5D.mjs → token-goat-chunk-GLXRTTLE.mjs} +7 -5
- package/dist/{token-goat-chunk-M6CVNHTW.mjs → token-goat-chunk-H5J3C56Q.mjs} +95 -573
- package/dist/{token-goat-chunk-BAWKGODL.mjs → token-goat-chunk-HNFZZHFW.mjs} +2 -2
- package/dist/{token-goat-chunk-TG5ZPD6B.mjs → token-goat-chunk-HUYUHODZ.mjs} +1036 -759
- package/dist/token-goat-chunk-IVE6U7KV.mjs +53 -0
- package/dist/{token-goat-chunk-ZZT6PVB3.mjs → token-goat-chunk-IVWI2OCK.mjs} +72 -45
- package/dist/{token-goat-chunk-GMOUBOX4.mjs → token-goat-chunk-JTKCQMQA.mjs} +37 -5
- package/dist/{token-goat-chunk-H2CPLEMP.mjs → token-goat-chunk-KOPIR3KZ.mjs} +46 -23
- package/dist/token-goat-chunk-L7H3U27L.mjs +35 -0
- package/dist/{token-goat-chunk-FLEYOCAS.mjs → token-goat-chunk-LZNBQTDK.mjs} +6 -4
- package/dist/token-goat-chunk-MELOKFDJ.mjs +199 -0
- package/dist/{token-goat-chunk-RH27ZSPF.mjs → token-goat-chunk-NMBWLRHW.mjs} +164 -50
- package/dist/{token-goat-chunk-43JFN26X.mjs → token-goat-chunk-O6I2XU4P.mjs} +27 -967
- package/dist/{token-goat-chunk-G6EYO5CD.mjs → token-goat-chunk-ONXH6NZ5.mjs} +2 -87
- package/dist/token-goat-chunk-ORNFMIER.mjs +295 -0
- package/dist/{token-goat-chunk-LHUP4DXZ.mjs → token-goat-chunk-PGTH2U4C.mjs} +1 -1
- package/dist/{token-goat-chunk-5BQ7W7D7.mjs → token-goat-chunk-PKRWMHVP.mjs} +76 -59
- package/dist/{token-goat-chunk-DA43OE7L.mjs → token-goat-chunk-PQ53BSCF.mjs} +1 -1
- package/dist/{token-goat-chunk-STYRLQIW.mjs → token-goat-chunk-PYSUADX4.mjs} +2 -2
- package/dist/{token-goat-chunk-JALB3KWJ.mjs → token-goat-chunk-QO3LXVVR.mjs} +4247 -5005
- package/dist/{token-goat-chunk-L45IWWMC.mjs → token-goat-chunk-RLP6J7WR.mjs} +6 -6
- package/dist/token-goat-chunk-RQGGMPCR.mjs +205 -0
- package/dist/{token-goat-chunk-MBDJR6HU.mjs → token-goat-chunk-RTMVLHWX.mjs} +3708 -4003
- package/dist/{token-goat-chunk-E3K3BTEQ.mjs → token-goat-chunk-S4VSXURL.mjs} +8 -6
- package/dist/{token-goat-chunk-LKSXAMJB.mjs → token-goat-chunk-SE6E4BKJ.mjs} +1 -1
- package/dist/token-goat-chunk-TCQANXYC.mjs +351 -0
- package/dist/token-goat-chunk-TDUT2CL6.mjs +564 -0
- package/dist/{token-goat-chunk-LRIZ7K3F.mjs → token-goat-chunk-TGOXNAHW.mjs} +54 -111
- package/dist/{token-goat-chunk-WNBSCSAI.mjs → token-goat-chunk-UA5BKWWQ.mjs} +1 -1
- package/dist/{token-goat-chunk-RIB6XY2V.mjs → token-goat-chunk-UXSXQQIY.mjs} +1 -1
- package/dist/{token-goat-chunk-7EPYB34H.mjs → token-goat-chunk-VMFWNHGR.mjs} +84 -73
- package/dist/token-goat-chunk-VQ6F6T7X.mjs +36 -0
- package/dist/{token-goat-chunk-5M3NRJD2.mjs → token-goat-chunk-VZQEWRVH.mjs} +6 -4
- package/dist/{token-goat-chunk-OSUFN2FV.mjs → token-goat-chunk-XB5KKOCG.mjs} +5 -25
- package/dist/{token-goat-chunk-6E2IDLHF.mjs → token-goat-chunk-XYWPOSCN.mjs} +57 -615
- package/dist/{token-goat-chunk-CQHY4SL7.mjs → token-goat-chunk-YAGLESS3.mjs} +8 -5
- package/dist/token-goat-chunk-YKSRAWUU.mjs +33 -0
- package/dist/{token-goat-chunk-F2ARFHLJ.mjs → token-goat-chunk-YOOVFPTP.mjs} +2 -2
- package/dist/{token-goat-chunk-EEIDFMEM.mjs → token-goat-chunk-YZAAZU2S.mjs} +12 -3
- package/dist/token-goat-chunk-Z6KBMOBI.mjs +53 -0
- package/dist/{token-goat-chunk-4GEDH2WU.mjs → token-goat-chunk-ZER6EAXZ.mjs} +81 -70
- package/dist/token-goat-hook-client.cjs +475 -0
- package/dist/token-goat-hook-client.mjs +26 -0
- package/dist/token-goat-hook.mjs +31 -21
- package/dist/token-goat.core.mjs +9 -39
- package/docs/C4_RUNTIME_ARCHITECTURE.md +2 -2
- package/docs/cli.md +35 -23
- package/docs/install.md +18 -14
- package/package.json +1 -1
- package/dist/token-goat-chunk-ADMR3QVF.mjs +0 -41
- package/dist/token-goat-chunk-E6B2UFDF.mjs +0 -30
- package/dist/token-goat-chunk-GKZ2US5B.mjs +0 -187
- package/dist/token-goat-chunk-MZTO4FXH.mjs +0 -26
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
configPath,
|
|
5
|
+
dataDir
|
|
6
|
+
} from "./token-goat-chunk-MELOKFDJ.mjs";
|
|
7
|
+
import {
|
|
8
|
+
init_define_import_meta_env
|
|
9
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
10
|
+
|
|
11
|
+
// src/hook_ipc.ts
|
|
12
|
+
init_define_import_meta_env();
|
|
13
|
+
import * as crypto from "node:crypto";
|
|
14
|
+
import * as fs from "node:fs";
|
|
15
|
+
import * as os from "node:os";
|
|
16
|
+
import * as path from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
var PROTOCOL_VERSION = 1;
|
|
19
|
+
var SERVER_SLOTS = 3;
|
|
20
|
+
var MAX_FRAME_BYTES = 64 * 1024 * 1024;
|
|
21
|
+
var KEY_BYTES = 32;
|
|
22
|
+
function bundleDir() {
|
|
23
|
+
const dir = path.dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
try {
|
|
25
|
+
return fs.realpathSync.native(dir);
|
|
26
|
+
} catch {
|
|
27
|
+
return dir;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function endpointId(dir) {
|
|
31
|
+
const fold = (p) => process.platform === "win32" ? p.toLowerCase() : p;
|
|
32
|
+
return crypto.createHash("sha256").update(`${fold(dir)}\0${fold(bundleDir())}`).digest("hex").slice(0, 16);
|
|
33
|
+
}
|
|
34
|
+
function endpointFor(slot, dir = dataDir()) {
|
|
35
|
+
const id = `${endpointId(dir)}-${slot}`;
|
|
36
|
+
if (process.platform === "win32") return String.raw`\\.\pipe\token-goat-hooks-` + id;
|
|
37
|
+
const inData = path.join(dir, `hooks-${id}.sock`);
|
|
38
|
+
if (Buffer.byteLength(inData) < 100) return inData;
|
|
39
|
+
const own = privateTempDir();
|
|
40
|
+
return own === void 0 ? inData : path.join(own, `${id}.sock`);
|
|
41
|
+
}
|
|
42
|
+
function privateTempDir() {
|
|
43
|
+
const uid = process.getuid?.();
|
|
44
|
+
if (uid === void 0) return void 0;
|
|
45
|
+
const own = path.join(os.tmpdir(), `token-goat-${uid}`);
|
|
46
|
+
try {
|
|
47
|
+
fs.mkdirSync(own, { mode: 448 });
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const st = fs.lstatSync(own);
|
|
52
|
+
return st.isDirectory() && st.uid === uid && (st.mode & 63) === 0 ? own : void 0;
|
|
53
|
+
} catch {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function serverKeyPath(dir = dataDir()) {
|
|
58
|
+
return path.join(dir, "hook-server.key");
|
|
59
|
+
}
|
|
60
|
+
function keyIsPrivate(st) {
|
|
61
|
+
if (process.platform === "win32") return true;
|
|
62
|
+
return (st.mode & 63) === 0 && (process.getuid === void 0 || st.uid === process.getuid());
|
|
63
|
+
}
|
|
64
|
+
function readServerKey(dir = dataDir()) {
|
|
65
|
+
try {
|
|
66
|
+
const p = serverKeyPath(dir);
|
|
67
|
+
if (!keyIsPrivate(fs.statSync(p))) return void 0;
|
|
68
|
+
const key = fs.readFileSync(p);
|
|
69
|
+
return key.length === KEY_BYTES ? key : void 0;
|
|
70
|
+
} catch {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function ensureServerKey(dir = dataDir()) {
|
|
75
|
+
const p = serverKeyPath(dir);
|
|
76
|
+
for (let attempt = 0; attempt < 50; attempt++) {
|
|
77
|
+
const existing = readServerKey(dir);
|
|
78
|
+
if (existing !== void 0) return existing;
|
|
79
|
+
const fresh = crypto.randomBytes(KEY_BYTES);
|
|
80
|
+
try {
|
|
81
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
82
|
+
fs.writeFileSync(p, fresh, { flag: "wx", mode: 384 });
|
|
83
|
+
return fresh;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if (e.code !== "EEXIST") throw e;
|
|
86
|
+
try {
|
|
87
|
+
const st = fs.statSync(p);
|
|
88
|
+
if (!keyIsPrivate(st) || st.size !== 0 && st.size !== KEY_BYTES || Date.now() - st.mtimeMs > 1e3) fs.rmSync(p, { force: true });
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
|
|
93
|
+
}
|
|
94
|
+
throw new Error(`could not establish ${p}`);
|
|
95
|
+
}
|
|
96
|
+
function nonce() {
|
|
97
|
+
return crypto.randomBytes(16).toString("hex");
|
|
98
|
+
}
|
|
99
|
+
function mac(key, ...parts) {
|
|
100
|
+
const h = crypto.createHmac("sha256", key);
|
|
101
|
+
for (const part of parts) h.update(`${Buffer.byteLength(part)}:`).update(part);
|
|
102
|
+
return h.digest("hex");
|
|
103
|
+
}
|
|
104
|
+
function macMatches(expected, actual) {
|
|
105
|
+
if (typeof actual !== "string" || actual.length !== expected.length) return false;
|
|
106
|
+
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(actual));
|
|
107
|
+
}
|
|
108
|
+
function writeFrame(socket, message) {
|
|
109
|
+
socket.write(encodeFrame(message));
|
|
110
|
+
}
|
|
111
|
+
function encodeFrame(message) {
|
|
112
|
+
const body = Buffer.from(JSON.stringify(message), "utf8");
|
|
113
|
+
const header = Buffer.alloc(4);
|
|
114
|
+
header.writeUInt32BE(body.length, 0);
|
|
115
|
+
return Buffer.concat([header, body]);
|
|
116
|
+
}
|
|
117
|
+
function frameFits(frame) {
|
|
118
|
+
return frame.length - 4 <= MAX_FRAME_BYTES;
|
|
119
|
+
}
|
|
120
|
+
function readFrames(socket, onFrame, onError) {
|
|
121
|
+
let buffered = Buffer.alloc(0);
|
|
122
|
+
socket.on("data", (chunk) => {
|
|
123
|
+
buffered = buffered.length === 0 ? chunk : Buffer.concat([buffered, chunk]);
|
|
124
|
+
while (buffered.length >= 4) {
|
|
125
|
+
const len = buffered.readUInt32BE(0);
|
|
126
|
+
if (len > MAX_FRAME_BYTES) {
|
|
127
|
+
onError(new Error(`frame of ${len} bytes exceeds ${MAX_FRAME_BYTES}`));
|
|
128
|
+
socket.destroy();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (buffered.length < 4 + len) return;
|
|
132
|
+
const body = buffered.subarray(4, 4 + len);
|
|
133
|
+
buffered = buffered.subarray(4 + len);
|
|
134
|
+
let message;
|
|
135
|
+
try {
|
|
136
|
+
message = JSON.parse(body.toString("utf8"));
|
|
137
|
+
} catch (e) {
|
|
138
|
+
onError(e);
|
|
139
|
+
socket.destroy();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (message === null || typeof message !== "object" || Array.isArray(message)) {
|
|
143
|
+
onError(new Error("frame is not a JSON object"));
|
|
144
|
+
socket.destroy();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
onFrame(message);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function envSnapshot() {
|
|
152
|
+
const env = {};
|
|
153
|
+
for (const [k, v] of Object.entries(process.env)) if (v !== void 0) env[k] = v;
|
|
154
|
+
return env;
|
|
155
|
+
}
|
|
156
|
+
function markerPath(name, dir = dataDir()) {
|
|
157
|
+
return path.join(dir, `hook-server.${name}`);
|
|
158
|
+
}
|
|
159
|
+
function markerAgeMs(name, dir = dataDir()) {
|
|
160
|
+
try {
|
|
161
|
+
return Date.now() - fs.statSync(markerPath(name, dir)).mtimeMs;
|
|
162
|
+
} catch {
|
|
163
|
+
return Infinity;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function touchMarker(name, content = String(process.pid), dir = dataDir()) {
|
|
167
|
+
try {
|
|
168
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
169
|
+
fs.writeFileSync(markerPath(name, dir), content);
|
|
170
|
+
} catch {
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function configStamp() {
|
|
174
|
+
try {
|
|
175
|
+
return String(fs.statSync(configPath()).mtimeMs);
|
|
176
|
+
} catch {
|
|
177
|
+
return "absent";
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function readMarker(name, dir = dataDir()) {
|
|
181
|
+
try {
|
|
182
|
+
return fs.readFileSync(markerPath(name, dir), "utf8");
|
|
183
|
+
} catch {
|
|
184
|
+
return void 0;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function removeMarker(name, dir = dataDir()) {
|
|
188
|
+
fs.rmSync(markerPath(name, dir), { force: true });
|
|
189
|
+
}
|
|
190
|
+
function bundleEntryFiles() {
|
|
191
|
+
const dir = bundleDir();
|
|
192
|
+
return ["token-goat.core.mjs", "token-goat-hook.mjs", "token-goat-hook-client.mjs", "token-goat-hook-client.cjs"].map((f) => path.join(dir, f));
|
|
193
|
+
}
|
|
194
|
+
function launcherPath() {
|
|
195
|
+
return path.join(bundleDir(), "token-goat.mjs");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export {
|
|
199
|
+
PROTOCOL_VERSION,
|
|
200
|
+
SERVER_SLOTS,
|
|
201
|
+
endpointFor,
|
|
202
|
+
serverKeyPath,
|
|
203
|
+
readServerKey,
|
|
204
|
+
ensureServerKey,
|
|
205
|
+
nonce,
|
|
206
|
+
mac,
|
|
207
|
+
macMatches,
|
|
208
|
+
writeFrame,
|
|
209
|
+
encodeFrame,
|
|
210
|
+
frameFits,
|
|
211
|
+
readFrames,
|
|
212
|
+
envSnapshot,
|
|
213
|
+
markerAgeMs,
|
|
214
|
+
touchMarker,
|
|
215
|
+
configStamp,
|
|
216
|
+
readMarker,
|
|
217
|
+
removeMarker,
|
|
218
|
+
bundleEntryFiles,
|
|
219
|
+
launcherPath
|
|
220
|
+
};
|