@darkhunt-security/endpoint-codex 0.9.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/.codex-plugin/plugin.json +11 -0
- package/README.md +76 -0
- package/commands/setup.md +72 -0
- package/commands/status.md +31 -0
- package/dist/bin/backfill.mjs +21868 -0
- package/dist/bin/enroll.mjs +1244 -0
- package/dist/bin/forwarder.mjs +21846 -0
- package/dist/bin/guard.mjs +1421 -0
- package/dist/bin/init.mjs +1135 -0
- package/dist/bin/spool.mjs +1222 -0
- package/dist/bin/status.mjs +1375 -0
- package/hooks/hooks.json +39 -0
- package/package.json +27 -0
|
@@ -0,0 +1,1375 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __dhCreateRequire } from 'node:module';
|
|
3
|
+
const require = __dhCreateRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
// packages/core/dist/config/local.js
|
|
6
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
7
|
+
import { join as join3 } from "node:path";
|
|
8
|
+
|
|
9
|
+
// packages/core/dist/config/paths.js
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
var CONFIG_DIR = join(homedir(), ".darkhunt");
|
|
13
|
+
|
|
14
|
+
// packages/core/dist/config/profile.js
|
|
15
|
+
import { homedir as homedir2 } from "node:os";
|
|
16
|
+
import { isAbsolute, join as join2, resolve } from "node:path";
|
|
17
|
+
var DEFAULT_PROFILE = "default";
|
|
18
|
+
var CREDENTIALS_BASENAME = "endpoint-credentials";
|
|
19
|
+
var DEFAULT_CREDENTIALS_PATH = join2(CONFIG_DIR, `${CREDENTIALS_BASENAME}.json`);
|
|
20
|
+
var CREDENTIALS_ENV = "DARKHUNT_ENDPOINT_CREDENTIALS";
|
|
21
|
+
function resolveProfile(explicit, fromConfig) {
|
|
22
|
+
return explicit ?? process.env["DARKHUNT_PROFILE"] ?? fromConfig ?? DEFAULT_PROFILE;
|
|
23
|
+
}
|
|
24
|
+
function expandPath(path) {
|
|
25
|
+
if (path.startsWith("~/"))
|
|
26
|
+
return join2(homedir2(), path.slice(2));
|
|
27
|
+
return isAbsolute(path) ? path : resolve(CONFIG_DIR, path);
|
|
28
|
+
}
|
|
29
|
+
function credentialsSelection(sources = {}) {
|
|
30
|
+
const s = typeof sources === "string" ? { profile: sources } : sources;
|
|
31
|
+
const pointer = s.explicitPath ?? process.env[CREDENTIALS_ENV] ?? s.configuredPath;
|
|
32
|
+
if (pointer)
|
|
33
|
+
return { path: expandPath(pointer), explicit: true };
|
|
34
|
+
const profile = s.profile ?? DEFAULT_PROFILE;
|
|
35
|
+
if (profile === DEFAULT_PROFILE)
|
|
36
|
+
return { path: DEFAULT_CREDENTIALS_PATH, explicit: false };
|
|
37
|
+
return { path: join2(CONFIG_DIR, `${CREDENTIALS_BASENAME}.${profile}.json`), explicit: true };
|
|
38
|
+
}
|
|
39
|
+
function scopeKey(vendor, profile) {
|
|
40
|
+
return profile === DEFAULT_PROFILE ? vendor : `${vendor}.${profile}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// packages/core/dist/config/local.js
|
|
44
|
+
function configPath() {
|
|
45
|
+
return join3(CONFIG_DIR, `${CONFIG_BASENAME}.json`);
|
|
46
|
+
}
|
|
47
|
+
var CONFIG_BASENAME = "endpoint-config";
|
|
48
|
+
var ConfigError = class extends Error {
|
|
49
|
+
};
|
|
50
|
+
var ConfigMissingError = class extends ConfigError {
|
|
51
|
+
};
|
|
52
|
+
var DEFAULT_API_BASE_URL = "https://api.darkhunt.ai";
|
|
53
|
+
var REQUIRED_FIELDS = ["apiKey", "tenantId", "workspaceId", "applicationId"];
|
|
54
|
+
function readSecure(path) {
|
|
55
|
+
const mode = statSync(path).mode & 511;
|
|
56
|
+
if (mode & 63)
|
|
57
|
+
throw new ConfigError(`${path} is mode ${mode.toString(8)}; must be 0600`);
|
|
58
|
+
return readFileSync(path, "utf8");
|
|
59
|
+
}
|
|
60
|
+
function readJson(path) {
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse(readSecure(path));
|
|
63
|
+
} catch (err) {
|
|
64
|
+
if (err instanceof ConfigError)
|
|
65
|
+
throw err;
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function settingsFor(file, vendor) {
|
|
70
|
+
const override = file.endpoints?.[vendor] ?? {};
|
|
71
|
+
return {
|
|
72
|
+
...file,
|
|
73
|
+
...override,
|
|
74
|
+
// Spelled out because these are nested: a spread would let an override naming only
|
|
75
|
+
// `mode` drop `failClosed` back to its default, quietly turning fail-closed off.
|
|
76
|
+
...file.capture ?? override.capture ? { capture: { ...file.capture, ...override.capture } } : {},
|
|
77
|
+
...file.enforce ?? override.enforce ? { enforce: { ...file.enforce, ...override.enforce } } : {}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function readConfigFile(vendor) {
|
|
81
|
+
if (!existsSync(configPath())) {
|
|
82
|
+
throw new ConfigMissingError(`${configPath()} does not exist \u2014 run init.mjs to create it`);
|
|
83
|
+
}
|
|
84
|
+
const file = readJson(configPath());
|
|
85
|
+
if (!file) {
|
|
86
|
+
throw new ConfigError(`cannot read ${configPath()} \u2014 it exists but did not parse`);
|
|
87
|
+
}
|
|
88
|
+
return settingsFor(file, vendor);
|
|
89
|
+
}
|
|
90
|
+
function loadLocalConfig(vendor, options = {}) {
|
|
91
|
+
const vendorFile = readConfigFile(vendor);
|
|
92
|
+
const profile = resolveProfile(options.profile, vendorFile.profile);
|
|
93
|
+
const selection = credentialsSelection({
|
|
94
|
+
...options.credentialsPath !== void 0 ? { explicitPath: options.credentialsPath } : {},
|
|
95
|
+
...vendorFile.credentials !== void 0 ? { configuredPath: vendorFile.credentials } : {},
|
|
96
|
+
profile
|
|
97
|
+
});
|
|
98
|
+
const inlineComplete = REQUIRED_FIELDS.every((name) => typeof vendorFile[name] === "string" && vendorFile[name] !== "");
|
|
99
|
+
const useInline = inlineComplete && !selection.explicit;
|
|
100
|
+
const credsPath = useInline ? configPath() : selection.path;
|
|
101
|
+
const creds = useInline ? {} : readJson(credsPath) ?? {};
|
|
102
|
+
const apiKey = creds.apiKey ?? vendorFile.apiKey;
|
|
103
|
+
const tenantId = creds.tenantId ?? vendorFile.tenantId;
|
|
104
|
+
const apiBaseUrl = (creds.apiBaseUrl ?? vendorFile.apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/+$/, "");
|
|
105
|
+
const baseUrl = vendorFile.baseUrl ?? `${apiBaseUrl}/trace-hub`;
|
|
106
|
+
const workspaceId = creds.workspaceId ?? vendorFile.workspaceId;
|
|
107
|
+
const applicationId = creds.applicationId ?? vendorFile.applicationId;
|
|
108
|
+
for (const [name, value] of [
|
|
109
|
+
["apiKey", apiKey],
|
|
110
|
+
["tenantId", tenantId],
|
|
111
|
+
["workspaceId", workspaceId],
|
|
112
|
+
["applicationId", applicationId]
|
|
113
|
+
]) {
|
|
114
|
+
if (typeof value !== "string" || value === "") {
|
|
115
|
+
throw new ConfigError(useInline ? `missing ${name} in ${configPath()}` : `missing ${name} for profile '${profile}' (looked in ${credsPath}, then ${configPath()})`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
profile,
|
|
120
|
+
credentialsPath: credsPath,
|
|
121
|
+
scope: scopeKey(vendor, profile),
|
|
122
|
+
baseUrl,
|
|
123
|
+
apiKey,
|
|
124
|
+
tenantId,
|
|
125
|
+
workspaceId,
|
|
126
|
+
applicationId,
|
|
127
|
+
...(creds.userId ?? vendorFile.userId) !== void 0 ? { userId: creds.userId ?? vendorFile.userId } : {},
|
|
128
|
+
enabled: vendorFile.enabled ?? true,
|
|
129
|
+
capture: { enabled: vendorFile.capture?.enabled ?? true },
|
|
130
|
+
enforce: {
|
|
131
|
+
mode: vendorFile.enforce?.mode ?? "off",
|
|
132
|
+
failClosed: vendorFile.enforce?.failClosed ?? true
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// packages/core/dist/spool/spool.js
|
|
138
|
+
import { join as join4 } from "node:path";
|
|
139
|
+
var SPOOL_DIR = join4(CONFIG_DIR, "spool");
|
|
140
|
+
function spoolPath(vendor) {
|
|
141
|
+
return join4(SPOOL_DIR, `${vendor}.jsonl`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// packages/core/dist/runtime/beat.js
|
|
145
|
+
import { mkdirSync, readFileSync as readFileSync2, renameSync, writeFileSync } from "node:fs";
|
|
146
|
+
import { join as join5 } from "node:path";
|
|
147
|
+
var BEAT_LIVE_MS = 30 * 60 * 1e3;
|
|
148
|
+
function beatPath(scope) {
|
|
149
|
+
return join5(CONFIG_DIR, `${scope}.hook-beat.json`);
|
|
150
|
+
}
|
|
151
|
+
function loadBeat(scope) {
|
|
152
|
+
try {
|
|
153
|
+
const beat = JSON.parse(readFileSync2(beatPath(scope), "utf8"));
|
|
154
|
+
return { ...beat, sessions: beat.sessions ?? {} };
|
|
155
|
+
} catch {
|
|
156
|
+
return void 0;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// packages/core/dist/forwarder/checkpoint.js
|
|
161
|
+
import { mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync3, renameSync as renameSync2, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
162
|
+
import { join as join6 } from "node:path";
|
|
163
|
+
function checkpointPath(scope) {
|
|
164
|
+
return join6(CONFIG_DIR, `${scope}.checkpoints.json`);
|
|
165
|
+
}
|
|
166
|
+
function loadCheckpoints(scope) {
|
|
167
|
+
try {
|
|
168
|
+
return JSON.parse(readFileSync3(checkpointPath(scope), "utf8"));
|
|
169
|
+
} catch {
|
|
170
|
+
return {};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// packages/core/dist/forwarder/tail.js
|
|
175
|
+
var DEFAULT_MAX_BYTES = 16 * 1024 * 1024;
|
|
176
|
+
var LINE_CEILING = 64 * 1024 * 1024;
|
|
177
|
+
|
|
178
|
+
// packages/core/dist/forwarder/lock.js
|
|
179
|
+
var STALE_MS = 5 * 60 * 1e3;
|
|
180
|
+
|
|
181
|
+
// packages/core/dist/forwarder/health.js
|
|
182
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
183
|
+
import { join as join7 } from "node:path";
|
|
184
|
+
function healthPath(scope) {
|
|
185
|
+
return join7(CONFIG_DIR, `${scope}.forwarder-health.json`);
|
|
186
|
+
}
|
|
187
|
+
function loadHealth(scope) {
|
|
188
|
+
try {
|
|
189
|
+
return JSON.parse(readFileSync4(healthPath(scope), "utf8"));
|
|
190
|
+
} catch {
|
|
191
|
+
return void 0;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// node_modules/@darkhunt-security/telemetry/package.json
|
|
196
|
+
var package_default = {
|
|
197
|
+
name: "@darkhunt-security/telemetry",
|
|
198
|
+
version: "0.5.5-build.165",
|
|
199
|
+
description: "TypeScript SDK for sending LLM traces, generations, and observations to the Darkhunt platform for persistence and security data enrichment. Built on OpenTelemetry primitives, with built-in client-side data masking.",
|
|
200
|
+
type: "module",
|
|
201
|
+
license: "Apache-2.0",
|
|
202
|
+
author: "Darkhunt Limited",
|
|
203
|
+
homepage: "https://github.com/darkhunt-security/darkhunt-telemetry-ts#readme",
|
|
204
|
+
bugs: {
|
|
205
|
+
url: "https://github.com/darkhunt-security/darkhunt-telemetry-ts/issues"
|
|
206
|
+
},
|
|
207
|
+
keywords: [
|
|
208
|
+
"opentelemetry",
|
|
209
|
+
"otel",
|
|
210
|
+
"otlp",
|
|
211
|
+
"llm",
|
|
212
|
+
"observability",
|
|
213
|
+
"tracing",
|
|
214
|
+
"data-masking",
|
|
215
|
+
"pii"
|
|
216
|
+
],
|
|
217
|
+
engines: {
|
|
218
|
+
node: "^18.19.0 || >=20.6.0"
|
|
219
|
+
},
|
|
220
|
+
main: "dist/index.js",
|
|
221
|
+
types: "dist/index.d.ts",
|
|
222
|
+
exports: {
|
|
223
|
+
".": {
|
|
224
|
+
types: "./dist/index.d.ts",
|
|
225
|
+
import: "./dist/index.js",
|
|
226
|
+
default: "./dist/index.js"
|
|
227
|
+
},
|
|
228
|
+
"./transports": {
|
|
229
|
+
types: "./dist/transports/index.d.ts",
|
|
230
|
+
import: "./dist/transports/index.js",
|
|
231
|
+
default: "./dist/transports/index.js"
|
|
232
|
+
},
|
|
233
|
+
"./temporal": {
|
|
234
|
+
types: "./dist/temporal/index.d.ts",
|
|
235
|
+
import: "./dist/temporal/index.js",
|
|
236
|
+
default: "./dist/temporal/index.js"
|
|
237
|
+
},
|
|
238
|
+
"./temporal/workflow": {
|
|
239
|
+
types: "./dist/temporal/workflow-interceptors.d.ts",
|
|
240
|
+
import: "./dist/temporal/workflow-interceptors.js",
|
|
241
|
+
default: "./dist/temporal/workflow-interceptors.js"
|
|
242
|
+
},
|
|
243
|
+
"./package.json": "./package.json"
|
|
244
|
+
},
|
|
245
|
+
files: [
|
|
246
|
+
"dist/",
|
|
247
|
+
"LICENSE",
|
|
248
|
+
"NOTICE",
|
|
249
|
+
"README.md"
|
|
250
|
+
],
|
|
251
|
+
publishConfig: {
|
|
252
|
+
registry: "https://registry.npmjs.org",
|
|
253
|
+
access: "public"
|
|
254
|
+
},
|
|
255
|
+
repository: {
|
|
256
|
+
type: "git",
|
|
257
|
+
url: "git+https://github.com/darkhunt-security/darkhunt-telemetry-ts.git"
|
|
258
|
+
},
|
|
259
|
+
scripts: {
|
|
260
|
+
dev: "tsx watch src/index.ts",
|
|
261
|
+
prepare: "tsx scripts/generate-rules-json.ts && tsc",
|
|
262
|
+
prebuild: "tsx scripts/generate-rules-json.ts",
|
|
263
|
+
build: "tsc",
|
|
264
|
+
prepublishOnly: "npm run build",
|
|
265
|
+
pretypecheck: "tsx scripts/generate-rules-json.ts",
|
|
266
|
+
typecheck: "tsc --noEmit",
|
|
267
|
+
test: "tsx scripts/generate-rules-json.ts && node --import tsx --test 'test/**/*.test.ts'",
|
|
268
|
+
"test:coverage": "tsx scripts/generate-rules-json.ts && c8 --reporter=lcov --reporter=text --include 'src/**/*.ts' --exclude 'src/**/*.d.ts' --exclude 'src/masking/rules/**' node --import tsx --test 'test/**/*.test.ts'",
|
|
269
|
+
lint: "eslint",
|
|
270
|
+
format: "prettier --write .",
|
|
271
|
+
"format:check": "prettier --check ."
|
|
272
|
+
},
|
|
273
|
+
dependencies: {
|
|
274
|
+
"@noble/hashes": "^1.8.0",
|
|
275
|
+
"@opentelemetry/api": "^1.9.1",
|
|
276
|
+
"@opentelemetry/context-async-hooks": "^2.0.0",
|
|
277
|
+
"@opentelemetry/core": "^2.0.0",
|
|
278
|
+
"@opentelemetry/otlp-transformer": "^0.218.0",
|
|
279
|
+
"@opentelemetry/resources": "^2.0.0",
|
|
280
|
+
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
281
|
+
"@opentelemetry/sdk-trace-node": "^2.0.0",
|
|
282
|
+
"@opentelemetry/semantic-conventions": "^1.30.0"
|
|
283
|
+
},
|
|
284
|
+
devDependencies: {
|
|
285
|
+
"@eslint/js": "^9.0.0",
|
|
286
|
+
"@temporalio/common": "^1.20.2",
|
|
287
|
+
"@temporalio/worker": "^1.20.2",
|
|
288
|
+
"@temporalio/workflow": "^1.20.2",
|
|
289
|
+
"@types/node": "^25.0.0",
|
|
290
|
+
c8: "^11.0.0",
|
|
291
|
+
eslint: "^9.0.0",
|
|
292
|
+
"eslint-config-prettier": "^10.0.0",
|
|
293
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
294
|
+
prettier: "^3.8.0",
|
|
295
|
+
tsx: "^4.19.0",
|
|
296
|
+
typescript: "^5.9.0",
|
|
297
|
+
"typescript-eslint": "^8.0.0",
|
|
298
|
+
yaml: "^2.8.4"
|
|
299
|
+
},
|
|
300
|
+
peerDependencies: {
|
|
301
|
+
"@temporalio/common": ">=1.11.0 <2",
|
|
302
|
+
"@temporalio/worker": ">=1.11.0 <2",
|
|
303
|
+
"@temporalio/workflow": ">=1.11.0 <2"
|
|
304
|
+
},
|
|
305
|
+
peerDependenciesMeta: {
|
|
306
|
+
"@temporalio/common": {
|
|
307
|
+
optional: true
|
|
308
|
+
},
|
|
309
|
+
"@temporalio/worker": {
|
|
310
|
+
optional: true
|
|
311
|
+
},
|
|
312
|
+
"@temporalio/workflow": {
|
|
313
|
+
optional: true
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/aba.js
|
|
319
|
+
var WEIGHTS = [3, 7, 1, 3, 7, 1, 3, 7, 1];
|
|
320
|
+
function aba(input) {
|
|
321
|
+
const digits = input.replace(/\s/g, "");
|
|
322
|
+
if (digits.length !== 9)
|
|
323
|
+
return false;
|
|
324
|
+
let sum = 0;
|
|
325
|
+
for (let i = 0; i < 9; i++) {
|
|
326
|
+
const n = digits.charCodeAt(i) - 48;
|
|
327
|
+
if (n < 0 || n > 9)
|
|
328
|
+
return false;
|
|
329
|
+
sum += n * WEIGHTS[i];
|
|
330
|
+
}
|
|
331
|
+
return sum % 10 === 0;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// node_modules/@noble/hashes/esm/utils.js
|
|
335
|
+
function isBytes(a) {
|
|
336
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
337
|
+
}
|
|
338
|
+
function anumber(n) {
|
|
339
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
340
|
+
throw new Error("positive integer expected, got " + n);
|
|
341
|
+
}
|
|
342
|
+
function abytes(b, ...lengths) {
|
|
343
|
+
if (!isBytes(b))
|
|
344
|
+
throw new Error("Uint8Array expected");
|
|
345
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
346
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
347
|
+
}
|
|
348
|
+
function aexists(instance, checkFinished = true) {
|
|
349
|
+
if (instance.destroyed)
|
|
350
|
+
throw new Error("Hash instance has been destroyed");
|
|
351
|
+
if (checkFinished && instance.finished)
|
|
352
|
+
throw new Error("Hash#digest() has already been called");
|
|
353
|
+
}
|
|
354
|
+
function aoutput(out, instance) {
|
|
355
|
+
abytes(out);
|
|
356
|
+
const min = instance.outputLen;
|
|
357
|
+
if (out.length < min) {
|
|
358
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function u32(arr) {
|
|
362
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
363
|
+
}
|
|
364
|
+
function clean(...arrays) {
|
|
365
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
366
|
+
arrays[i].fill(0);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function createView(arr) {
|
|
370
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
371
|
+
}
|
|
372
|
+
function rotr(word, shift) {
|
|
373
|
+
return word << 32 - shift | word >>> shift;
|
|
374
|
+
}
|
|
375
|
+
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
376
|
+
function byteSwap(word) {
|
|
377
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
378
|
+
}
|
|
379
|
+
function byteSwap32(arr) {
|
|
380
|
+
for (let i = 0; i < arr.length; i++) {
|
|
381
|
+
arr[i] = byteSwap(arr[i]);
|
|
382
|
+
}
|
|
383
|
+
return arr;
|
|
384
|
+
}
|
|
385
|
+
var swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
386
|
+
function utf8ToBytes(str2) {
|
|
387
|
+
if (typeof str2 !== "string")
|
|
388
|
+
throw new Error("string expected");
|
|
389
|
+
return new Uint8Array(new TextEncoder().encode(str2));
|
|
390
|
+
}
|
|
391
|
+
function toBytes(data) {
|
|
392
|
+
if (typeof data === "string")
|
|
393
|
+
data = utf8ToBytes(data);
|
|
394
|
+
abytes(data);
|
|
395
|
+
return data;
|
|
396
|
+
}
|
|
397
|
+
var Hash = class {
|
|
398
|
+
};
|
|
399
|
+
function createHasher(hashCons) {
|
|
400
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
401
|
+
const tmp = hashCons();
|
|
402
|
+
hashC.outputLen = tmp.outputLen;
|
|
403
|
+
hashC.blockLen = tmp.blockLen;
|
|
404
|
+
hashC.create = () => hashCons();
|
|
405
|
+
return hashC;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// node_modules/@noble/hashes/esm/_md.js
|
|
409
|
+
function setBigUint64(view, byteOffset, value, isLE2) {
|
|
410
|
+
if (typeof view.setBigUint64 === "function")
|
|
411
|
+
return view.setBigUint64(byteOffset, value, isLE2);
|
|
412
|
+
const _32n2 = BigInt(32);
|
|
413
|
+
const _u32_max = BigInt(4294967295);
|
|
414
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
415
|
+
const wl = Number(value & _u32_max);
|
|
416
|
+
const h = isLE2 ? 4 : 0;
|
|
417
|
+
const l = isLE2 ? 0 : 4;
|
|
418
|
+
view.setUint32(byteOffset + h, wh, isLE2);
|
|
419
|
+
view.setUint32(byteOffset + l, wl, isLE2);
|
|
420
|
+
}
|
|
421
|
+
function Chi(a, b, c) {
|
|
422
|
+
return a & b ^ ~a & c;
|
|
423
|
+
}
|
|
424
|
+
function Maj(a, b, c) {
|
|
425
|
+
return a & b ^ a & c ^ b & c;
|
|
426
|
+
}
|
|
427
|
+
var HashMD = class extends Hash {
|
|
428
|
+
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
429
|
+
super();
|
|
430
|
+
this.finished = false;
|
|
431
|
+
this.length = 0;
|
|
432
|
+
this.pos = 0;
|
|
433
|
+
this.destroyed = false;
|
|
434
|
+
this.blockLen = blockLen;
|
|
435
|
+
this.outputLen = outputLen;
|
|
436
|
+
this.padOffset = padOffset;
|
|
437
|
+
this.isLE = isLE2;
|
|
438
|
+
this.buffer = new Uint8Array(blockLen);
|
|
439
|
+
this.view = createView(this.buffer);
|
|
440
|
+
}
|
|
441
|
+
update(data) {
|
|
442
|
+
aexists(this);
|
|
443
|
+
data = toBytes(data);
|
|
444
|
+
abytes(data);
|
|
445
|
+
const { view, buffer, blockLen } = this;
|
|
446
|
+
const len = data.length;
|
|
447
|
+
for (let pos = 0; pos < len; ) {
|
|
448
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
449
|
+
if (take === blockLen) {
|
|
450
|
+
const dataView = createView(data);
|
|
451
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
452
|
+
this.process(dataView, pos);
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
456
|
+
this.pos += take;
|
|
457
|
+
pos += take;
|
|
458
|
+
if (this.pos === blockLen) {
|
|
459
|
+
this.process(view, 0);
|
|
460
|
+
this.pos = 0;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
this.length += data.length;
|
|
464
|
+
this.roundClean();
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
digestInto(out) {
|
|
468
|
+
aexists(this);
|
|
469
|
+
aoutput(out, this);
|
|
470
|
+
this.finished = true;
|
|
471
|
+
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
|
472
|
+
let { pos } = this;
|
|
473
|
+
buffer[pos++] = 128;
|
|
474
|
+
clean(this.buffer.subarray(pos));
|
|
475
|
+
if (this.padOffset > blockLen - pos) {
|
|
476
|
+
this.process(view, 0);
|
|
477
|
+
pos = 0;
|
|
478
|
+
}
|
|
479
|
+
for (let i = pos; i < blockLen; i++)
|
|
480
|
+
buffer[i] = 0;
|
|
481
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
482
|
+
this.process(view, 0);
|
|
483
|
+
const oview = createView(out);
|
|
484
|
+
const len = this.outputLen;
|
|
485
|
+
if (len % 4)
|
|
486
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
487
|
+
const outLen = len / 4;
|
|
488
|
+
const state = this.get();
|
|
489
|
+
if (outLen > state.length)
|
|
490
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
491
|
+
for (let i = 0; i < outLen; i++)
|
|
492
|
+
oview.setUint32(4 * i, state[i], isLE2);
|
|
493
|
+
}
|
|
494
|
+
digest() {
|
|
495
|
+
const { buffer, outputLen } = this;
|
|
496
|
+
this.digestInto(buffer);
|
|
497
|
+
const res = buffer.slice(0, outputLen);
|
|
498
|
+
this.destroy();
|
|
499
|
+
return res;
|
|
500
|
+
}
|
|
501
|
+
_cloneInto(to) {
|
|
502
|
+
to || (to = new this.constructor());
|
|
503
|
+
to.set(...this.get());
|
|
504
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
505
|
+
to.destroyed = destroyed;
|
|
506
|
+
to.finished = finished;
|
|
507
|
+
to.length = length;
|
|
508
|
+
to.pos = pos;
|
|
509
|
+
if (length % blockLen)
|
|
510
|
+
to.buffer.set(buffer);
|
|
511
|
+
return to;
|
|
512
|
+
}
|
|
513
|
+
clone() {
|
|
514
|
+
return this._cloneInto();
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
518
|
+
1779033703,
|
|
519
|
+
3144134277,
|
|
520
|
+
1013904242,
|
|
521
|
+
2773480762,
|
|
522
|
+
1359893119,
|
|
523
|
+
2600822924,
|
|
524
|
+
528734635,
|
|
525
|
+
1541459225
|
|
526
|
+
]);
|
|
527
|
+
|
|
528
|
+
// node_modules/@noble/hashes/esm/_u64.js
|
|
529
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
530
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
531
|
+
function fromBig(n, le = false) {
|
|
532
|
+
if (le)
|
|
533
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
534
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
535
|
+
}
|
|
536
|
+
function split(lst, le = false) {
|
|
537
|
+
const len = lst.length;
|
|
538
|
+
let Ah = new Uint32Array(len);
|
|
539
|
+
let Al = new Uint32Array(len);
|
|
540
|
+
for (let i = 0; i < len; i++) {
|
|
541
|
+
const { h, l } = fromBig(lst[i], le);
|
|
542
|
+
[Ah[i], Al[i]] = [h, l];
|
|
543
|
+
}
|
|
544
|
+
return [Ah, Al];
|
|
545
|
+
}
|
|
546
|
+
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
547
|
+
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
548
|
+
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
549
|
+
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
550
|
+
|
|
551
|
+
// node_modules/@noble/hashes/esm/sha2.js
|
|
552
|
+
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
553
|
+
1116352408,
|
|
554
|
+
1899447441,
|
|
555
|
+
3049323471,
|
|
556
|
+
3921009573,
|
|
557
|
+
961987163,
|
|
558
|
+
1508970993,
|
|
559
|
+
2453635748,
|
|
560
|
+
2870763221,
|
|
561
|
+
3624381080,
|
|
562
|
+
310598401,
|
|
563
|
+
607225278,
|
|
564
|
+
1426881987,
|
|
565
|
+
1925078388,
|
|
566
|
+
2162078206,
|
|
567
|
+
2614888103,
|
|
568
|
+
3248222580,
|
|
569
|
+
3835390401,
|
|
570
|
+
4022224774,
|
|
571
|
+
264347078,
|
|
572
|
+
604807628,
|
|
573
|
+
770255983,
|
|
574
|
+
1249150122,
|
|
575
|
+
1555081692,
|
|
576
|
+
1996064986,
|
|
577
|
+
2554220882,
|
|
578
|
+
2821834349,
|
|
579
|
+
2952996808,
|
|
580
|
+
3210313671,
|
|
581
|
+
3336571891,
|
|
582
|
+
3584528711,
|
|
583
|
+
113926993,
|
|
584
|
+
338241895,
|
|
585
|
+
666307205,
|
|
586
|
+
773529912,
|
|
587
|
+
1294757372,
|
|
588
|
+
1396182291,
|
|
589
|
+
1695183700,
|
|
590
|
+
1986661051,
|
|
591
|
+
2177026350,
|
|
592
|
+
2456956037,
|
|
593
|
+
2730485921,
|
|
594
|
+
2820302411,
|
|
595
|
+
3259730800,
|
|
596
|
+
3345764771,
|
|
597
|
+
3516065817,
|
|
598
|
+
3600352804,
|
|
599
|
+
4094571909,
|
|
600
|
+
275423344,
|
|
601
|
+
430227734,
|
|
602
|
+
506948616,
|
|
603
|
+
659060556,
|
|
604
|
+
883997877,
|
|
605
|
+
958139571,
|
|
606
|
+
1322822218,
|
|
607
|
+
1537002063,
|
|
608
|
+
1747873779,
|
|
609
|
+
1955562222,
|
|
610
|
+
2024104815,
|
|
611
|
+
2227730452,
|
|
612
|
+
2361852424,
|
|
613
|
+
2428436474,
|
|
614
|
+
2756734187,
|
|
615
|
+
3204031479,
|
|
616
|
+
3329325298
|
|
617
|
+
]);
|
|
618
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
619
|
+
var SHA256 = class extends HashMD {
|
|
620
|
+
constructor(outputLen = 32) {
|
|
621
|
+
super(64, outputLen, 8, false);
|
|
622
|
+
this.A = SHA256_IV[0] | 0;
|
|
623
|
+
this.B = SHA256_IV[1] | 0;
|
|
624
|
+
this.C = SHA256_IV[2] | 0;
|
|
625
|
+
this.D = SHA256_IV[3] | 0;
|
|
626
|
+
this.E = SHA256_IV[4] | 0;
|
|
627
|
+
this.F = SHA256_IV[5] | 0;
|
|
628
|
+
this.G = SHA256_IV[6] | 0;
|
|
629
|
+
this.H = SHA256_IV[7] | 0;
|
|
630
|
+
}
|
|
631
|
+
get() {
|
|
632
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
633
|
+
return [A, B, C, D, E, F, G, H];
|
|
634
|
+
}
|
|
635
|
+
// prettier-ignore
|
|
636
|
+
set(A, B, C, D, E, F, G, H) {
|
|
637
|
+
this.A = A | 0;
|
|
638
|
+
this.B = B | 0;
|
|
639
|
+
this.C = C | 0;
|
|
640
|
+
this.D = D | 0;
|
|
641
|
+
this.E = E | 0;
|
|
642
|
+
this.F = F | 0;
|
|
643
|
+
this.G = G | 0;
|
|
644
|
+
this.H = H | 0;
|
|
645
|
+
}
|
|
646
|
+
process(view, offset) {
|
|
647
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
648
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
649
|
+
for (let i = 16; i < 64; i++) {
|
|
650
|
+
const W15 = SHA256_W[i - 15];
|
|
651
|
+
const W2 = SHA256_W[i - 2];
|
|
652
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
653
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
654
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
655
|
+
}
|
|
656
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
657
|
+
for (let i = 0; i < 64; i++) {
|
|
658
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
659
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
660
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
661
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
662
|
+
H = G;
|
|
663
|
+
G = F;
|
|
664
|
+
F = E;
|
|
665
|
+
E = D + T1 | 0;
|
|
666
|
+
D = C;
|
|
667
|
+
C = B;
|
|
668
|
+
B = A;
|
|
669
|
+
A = T1 + T2 | 0;
|
|
670
|
+
}
|
|
671
|
+
A = A + this.A | 0;
|
|
672
|
+
B = B + this.B | 0;
|
|
673
|
+
C = C + this.C | 0;
|
|
674
|
+
D = D + this.D | 0;
|
|
675
|
+
E = E + this.E | 0;
|
|
676
|
+
F = F + this.F | 0;
|
|
677
|
+
G = G + this.G | 0;
|
|
678
|
+
H = H + this.H | 0;
|
|
679
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
680
|
+
}
|
|
681
|
+
roundClean() {
|
|
682
|
+
clean(SHA256_W);
|
|
683
|
+
}
|
|
684
|
+
destroy() {
|
|
685
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
686
|
+
clean(this.buffer);
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
690
|
+
|
|
691
|
+
// node_modules/@noble/hashes/esm/sha256.js
|
|
692
|
+
var sha2562 = sha256;
|
|
693
|
+
|
|
694
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/base58check.js
|
|
695
|
+
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
696
|
+
var BASE = 58n;
|
|
697
|
+
function base58check(input) {
|
|
698
|
+
if (input.length === 0)
|
|
699
|
+
return false;
|
|
700
|
+
let leadingOnes = 0;
|
|
701
|
+
while (leadingOnes < input.length && input.charAt(leadingOnes) === "1") {
|
|
702
|
+
leadingOnes++;
|
|
703
|
+
}
|
|
704
|
+
let num2 = 0n;
|
|
705
|
+
for (let i = 0; i < input.length; i++) {
|
|
706
|
+
const idx = ALPHABET.indexOf(input.charAt(i));
|
|
707
|
+
if (idx === -1)
|
|
708
|
+
return false;
|
|
709
|
+
num2 = num2 * BASE + BigInt(idx);
|
|
710
|
+
}
|
|
711
|
+
const bodyBytes = [];
|
|
712
|
+
while (num2 > 0n) {
|
|
713
|
+
bodyBytes.unshift(Number(num2 & 0xffn));
|
|
714
|
+
num2 >>= 8n;
|
|
715
|
+
}
|
|
716
|
+
const bytes = new Uint8Array(leadingOnes + bodyBytes.length);
|
|
717
|
+
for (let i = 0; i < bodyBytes.length; i++)
|
|
718
|
+
bytes[leadingOnes + i] = bodyBytes[i];
|
|
719
|
+
if (bytes.length < 5)
|
|
720
|
+
return false;
|
|
721
|
+
const payload = bytes.subarray(0, bytes.length - 4);
|
|
722
|
+
const checksum = bytes.subarray(bytes.length - 4);
|
|
723
|
+
const hash = sha2562(sha2562(payload));
|
|
724
|
+
for (let i = 0; i < 4; i++) {
|
|
725
|
+
if (hash[i] !== checksum[i])
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/bech32.js
|
|
732
|
+
var CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
733
|
+
var GENERATOR = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
734
|
+
var BECH32_CONST = 1;
|
|
735
|
+
var BECH32M_CONST = 734539939;
|
|
736
|
+
function polymod(values) {
|
|
737
|
+
let chk = 1;
|
|
738
|
+
for (const v of values) {
|
|
739
|
+
const top = chk >>> 25;
|
|
740
|
+
chk = (chk & 33554431) << 5 ^ v;
|
|
741
|
+
for (let i = 0; i < 5; i++) {
|
|
742
|
+
if (top >> i & 1)
|
|
743
|
+
chk ^= GENERATOR[i];
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return chk;
|
|
747
|
+
}
|
|
748
|
+
function hrpExpand(hrp) {
|
|
749
|
+
const out = [];
|
|
750
|
+
for (let i = 0; i < hrp.length; i++)
|
|
751
|
+
out.push(hrp.charCodeAt(i) >> 5);
|
|
752
|
+
out.push(0);
|
|
753
|
+
for (let i = 0; i < hrp.length; i++)
|
|
754
|
+
out.push(hrp.charCodeAt(i) & 31);
|
|
755
|
+
return out;
|
|
756
|
+
}
|
|
757
|
+
function bech32(input) {
|
|
758
|
+
if (input.length > 90)
|
|
759
|
+
return false;
|
|
760
|
+
const lower = input.toLowerCase();
|
|
761
|
+
const upper = input.toUpperCase();
|
|
762
|
+
if (input !== lower && input !== upper)
|
|
763
|
+
return false;
|
|
764
|
+
const sepIdx = lower.lastIndexOf("1");
|
|
765
|
+
if (sepIdx < 1 || sepIdx + 7 > lower.length)
|
|
766
|
+
return false;
|
|
767
|
+
const hrp = lower.slice(0, sepIdx);
|
|
768
|
+
for (let i = 0; i < hrp.length; i++) {
|
|
769
|
+
const c = hrp.charCodeAt(i);
|
|
770
|
+
if (c < 33 || c > 126)
|
|
771
|
+
return false;
|
|
772
|
+
}
|
|
773
|
+
const data = [];
|
|
774
|
+
for (let i = sepIdx + 1; i < lower.length; i++) {
|
|
775
|
+
const idx = CHARSET.indexOf(lower.charAt(i));
|
|
776
|
+
if (idx === -1)
|
|
777
|
+
return false;
|
|
778
|
+
data.push(idx);
|
|
779
|
+
}
|
|
780
|
+
const checksum = polymod(hrpExpand(hrp).concat(data));
|
|
781
|
+
return checksum === BECH32_CONST || checksum === BECH32M_CONST;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/luhn.js
|
|
785
|
+
function luhn(input) {
|
|
786
|
+
let sum = 0;
|
|
787
|
+
let alternate = false;
|
|
788
|
+
let len = 0;
|
|
789
|
+
for (let i = input.length - 1; i >= 0; i--) {
|
|
790
|
+
const ch = input.charCodeAt(i);
|
|
791
|
+
if (ch === 32 || ch === 45)
|
|
792
|
+
continue;
|
|
793
|
+
const digit = ch - 48;
|
|
794
|
+
if (digit < 0 || digit > 9)
|
|
795
|
+
return false;
|
|
796
|
+
let n = digit;
|
|
797
|
+
if (alternate) {
|
|
798
|
+
n *= 2;
|
|
799
|
+
if (n > 9)
|
|
800
|
+
n -= 9;
|
|
801
|
+
}
|
|
802
|
+
sum += n;
|
|
803
|
+
alternate = !alternate;
|
|
804
|
+
len++;
|
|
805
|
+
}
|
|
806
|
+
return len > 0 && sum % 10 === 0;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/creditCard.js
|
|
810
|
+
function creditCard(input) {
|
|
811
|
+
const digits = input.replace(/[\s-]/g, "");
|
|
812
|
+
return digits.length >= 13 && digits.length <= 16 && hasValidIin(digits) && luhn(digits);
|
|
813
|
+
}
|
|
814
|
+
function hasValidIin(digits) {
|
|
815
|
+
const len = digits.length;
|
|
816
|
+
if (len < 13)
|
|
817
|
+
return false;
|
|
818
|
+
return isVisa(digits, len) || isMastercard(digits, len) || isAmex(digits, len) || isDiners(digits, len) || isJcb(digits, len) || isDiscover(digits, len);
|
|
819
|
+
}
|
|
820
|
+
function isVisa(d, len) {
|
|
821
|
+
return d.startsWith("4") && (len === 13 || len === 16);
|
|
822
|
+
}
|
|
823
|
+
function isMastercard(d, len) {
|
|
824
|
+
if (len !== 16)
|
|
825
|
+
return false;
|
|
826
|
+
if (d.startsWith("5")) {
|
|
827
|
+
const d1 = d.charAt(1);
|
|
828
|
+
return d1 >= "1" && d1 <= "5";
|
|
829
|
+
}
|
|
830
|
+
if (d.startsWith("2")) {
|
|
831
|
+
const prefix = Number.parseInt(d.slice(0, 4), 10);
|
|
832
|
+
return prefix >= 2221 && prefix <= 2720;
|
|
833
|
+
}
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
function isAmex(d, len) {
|
|
837
|
+
return len === 15 && (d.startsWith("34") || d.startsWith("37"));
|
|
838
|
+
}
|
|
839
|
+
function isDiners(d, len) {
|
|
840
|
+
if (len !== 14)
|
|
841
|
+
return false;
|
|
842
|
+
if (d.startsWith("30")) {
|
|
843
|
+
const d2 = d.charAt(2);
|
|
844
|
+
return d2 >= "0" && d2 <= "5";
|
|
845
|
+
}
|
|
846
|
+
return d.startsWith("36") || d.startsWith("38");
|
|
847
|
+
}
|
|
848
|
+
function isJcb(d, len) {
|
|
849
|
+
return len === 16 && d.startsWith("35");
|
|
850
|
+
}
|
|
851
|
+
function isDiscover(d, len) {
|
|
852
|
+
if (len !== 16)
|
|
853
|
+
return false;
|
|
854
|
+
if (d.startsWith("6011"))
|
|
855
|
+
return true;
|
|
856
|
+
if (d.startsWith("65"))
|
|
857
|
+
return true;
|
|
858
|
+
if (d.startsWith("64")) {
|
|
859
|
+
const d2 = d.charAt(2);
|
|
860
|
+
return d2 >= "4" && d2 <= "9";
|
|
861
|
+
}
|
|
862
|
+
if (d.startsWith("62")) {
|
|
863
|
+
const prefix = Number.parseInt(d.slice(0, 6), 10);
|
|
864
|
+
return prefix >= 622126 && prefix <= 622925;
|
|
865
|
+
}
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// node_modules/@noble/hashes/esm/sha3.js
|
|
870
|
+
var _0n = BigInt(0);
|
|
871
|
+
var _1n = BigInt(1);
|
|
872
|
+
var _2n = BigInt(2);
|
|
873
|
+
var _7n = BigInt(7);
|
|
874
|
+
var _256n = BigInt(256);
|
|
875
|
+
var _0x71n = BigInt(113);
|
|
876
|
+
var SHA3_PI = [];
|
|
877
|
+
var SHA3_ROTL = [];
|
|
878
|
+
var _SHA3_IOTA = [];
|
|
879
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
880
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
881
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
882
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
883
|
+
let t = _0n;
|
|
884
|
+
for (let j = 0; j < 7; j++) {
|
|
885
|
+
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
886
|
+
if (R & _2n)
|
|
887
|
+
t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
|
|
888
|
+
}
|
|
889
|
+
_SHA3_IOTA.push(t);
|
|
890
|
+
}
|
|
891
|
+
var IOTAS = split(_SHA3_IOTA, true);
|
|
892
|
+
var SHA3_IOTA_H = IOTAS[0];
|
|
893
|
+
var SHA3_IOTA_L = IOTAS[1];
|
|
894
|
+
var rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
|
|
895
|
+
var rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
|
|
896
|
+
function keccakP(s, rounds = 24) {
|
|
897
|
+
const B = new Uint32Array(5 * 2);
|
|
898
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
899
|
+
for (let x = 0; x < 10; x++)
|
|
900
|
+
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
901
|
+
for (let x = 0; x < 10; x += 2) {
|
|
902
|
+
const idx1 = (x + 8) % 10;
|
|
903
|
+
const idx0 = (x + 2) % 10;
|
|
904
|
+
const B0 = B[idx0];
|
|
905
|
+
const B1 = B[idx0 + 1];
|
|
906
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
907
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
908
|
+
for (let y = 0; y < 50; y += 10) {
|
|
909
|
+
s[x + y] ^= Th;
|
|
910
|
+
s[x + y + 1] ^= Tl;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
let curH = s[2];
|
|
914
|
+
let curL = s[3];
|
|
915
|
+
for (let t = 0; t < 24; t++) {
|
|
916
|
+
const shift = SHA3_ROTL[t];
|
|
917
|
+
const Th = rotlH(curH, curL, shift);
|
|
918
|
+
const Tl = rotlL(curH, curL, shift);
|
|
919
|
+
const PI = SHA3_PI[t];
|
|
920
|
+
curH = s[PI];
|
|
921
|
+
curL = s[PI + 1];
|
|
922
|
+
s[PI] = Th;
|
|
923
|
+
s[PI + 1] = Tl;
|
|
924
|
+
}
|
|
925
|
+
for (let y = 0; y < 50; y += 10) {
|
|
926
|
+
for (let x = 0; x < 10; x++)
|
|
927
|
+
B[x] = s[y + x];
|
|
928
|
+
for (let x = 0; x < 10; x++)
|
|
929
|
+
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
930
|
+
}
|
|
931
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
932
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
933
|
+
}
|
|
934
|
+
clean(B);
|
|
935
|
+
}
|
|
936
|
+
var Keccak = class _Keccak extends Hash {
|
|
937
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
938
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
939
|
+
super();
|
|
940
|
+
this.pos = 0;
|
|
941
|
+
this.posOut = 0;
|
|
942
|
+
this.finished = false;
|
|
943
|
+
this.destroyed = false;
|
|
944
|
+
this.enableXOF = false;
|
|
945
|
+
this.blockLen = blockLen;
|
|
946
|
+
this.suffix = suffix;
|
|
947
|
+
this.outputLen = outputLen;
|
|
948
|
+
this.enableXOF = enableXOF;
|
|
949
|
+
this.rounds = rounds;
|
|
950
|
+
anumber(outputLen);
|
|
951
|
+
if (!(0 < blockLen && blockLen < 200))
|
|
952
|
+
throw new Error("only keccak-f1600 function is supported");
|
|
953
|
+
this.state = new Uint8Array(200);
|
|
954
|
+
this.state32 = u32(this.state);
|
|
955
|
+
}
|
|
956
|
+
clone() {
|
|
957
|
+
return this._cloneInto();
|
|
958
|
+
}
|
|
959
|
+
keccak() {
|
|
960
|
+
swap32IfBE(this.state32);
|
|
961
|
+
keccakP(this.state32, this.rounds);
|
|
962
|
+
swap32IfBE(this.state32);
|
|
963
|
+
this.posOut = 0;
|
|
964
|
+
this.pos = 0;
|
|
965
|
+
}
|
|
966
|
+
update(data) {
|
|
967
|
+
aexists(this);
|
|
968
|
+
data = toBytes(data);
|
|
969
|
+
abytes(data);
|
|
970
|
+
const { blockLen, state } = this;
|
|
971
|
+
const len = data.length;
|
|
972
|
+
for (let pos = 0; pos < len; ) {
|
|
973
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
974
|
+
for (let i = 0; i < take; i++)
|
|
975
|
+
state[this.pos++] ^= data[pos++];
|
|
976
|
+
if (this.pos === blockLen)
|
|
977
|
+
this.keccak();
|
|
978
|
+
}
|
|
979
|
+
return this;
|
|
980
|
+
}
|
|
981
|
+
finish() {
|
|
982
|
+
if (this.finished)
|
|
983
|
+
return;
|
|
984
|
+
this.finished = true;
|
|
985
|
+
const { state, suffix, pos, blockLen } = this;
|
|
986
|
+
state[pos] ^= suffix;
|
|
987
|
+
if ((suffix & 128) !== 0 && pos === blockLen - 1)
|
|
988
|
+
this.keccak();
|
|
989
|
+
state[blockLen - 1] ^= 128;
|
|
990
|
+
this.keccak();
|
|
991
|
+
}
|
|
992
|
+
writeInto(out) {
|
|
993
|
+
aexists(this, false);
|
|
994
|
+
abytes(out);
|
|
995
|
+
this.finish();
|
|
996
|
+
const bufferOut = this.state;
|
|
997
|
+
const { blockLen } = this;
|
|
998
|
+
for (let pos = 0, len = out.length; pos < len; ) {
|
|
999
|
+
if (this.posOut >= blockLen)
|
|
1000
|
+
this.keccak();
|
|
1001
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
1002
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
1003
|
+
this.posOut += take;
|
|
1004
|
+
pos += take;
|
|
1005
|
+
}
|
|
1006
|
+
return out;
|
|
1007
|
+
}
|
|
1008
|
+
xofInto(out) {
|
|
1009
|
+
if (!this.enableXOF)
|
|
1010
|
+
throw new Error("XOF is not possible for this instance");
|
|
1011
|
+
return this.writeInto(out);
|
|
1012
|
+
}
|
|
1013
|
+
xof(bytes) {
|
|
1014
|
+
anumber(bytes);
|
|
1015
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
1016
|
+
}
|
|
1017
|
+
digestInto(out) {
|
|
1018
|
+
aoutput(out, this);
|
|
1019
|
+
if (this.finished)
|
|
1020
|
+
throw new Error("digest() was already called");
|
|
1021
|
+
this.writeInto(out);
|
|
1022
|
+
this.destroy();
|
|
1023
|
+
return out;
|
|
1024
|
+
}
|
|
1025
|
+
digest() {
|
|
1026
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
1027
|
+
}
|
|
1028
|
+
destroy() {
|
|
1029
|
+
this.destroyed = true;
|
|
1030
|
+
clean(this.state);
|
|
1031
|
+
}
|
|
1032
|
+
_cloneInto(to) {
|
|
1033
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
1034
|
+
to || (to = new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
1035
|
+
to.state32.set(this.state32);
|
|
1036
|
+
to.pos = this.pos;
|
|
1037
|
+
to.posOut = this.posOut;
|
|
1038
|
+
to.finished = this.finished;
|
|
1039
|
+
to.rounds = rounds;
|
|
1040
|
+
to.suffix = suffix;
|
|
1041
|
+
to.outputLen = outputLen;
|
|
1042
|
+
to.enableXOF = enableXOF;
|
|
1043
|
+
to.destroyed = this.destroyed;
|
|
1044
|
+
return to;
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
var gen = (suffix, blockLen, outputLen) => createHasher(() => new Keccak(blockLen, suffix, outputLen));
|
|
1048
|
+
var keccak_256 = /* @__PURE__ */ (() => gen(1, 136, 256 / 8))();
|
|
1049
|
+
|
|
1050
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/eip55.js
|
|
1051
|
+
var ADDR_RE = /^0[xX][0-9a-fA-F]{40}$/;
|
|
1052
|
+
function eip55(input) {
|
|
1053
|
+
if (!ADDR_RE.test(input))
|
|
1054
|
+
return false;
|
|
1055
|
+
const addr = input.slice(2);
|
|
1056
|
+
const lower = addr.toLowerCase();
|
|
1057
|
+
if (addr === lower || addr === addr.toUpperCase())
|
|
1058
|
+
return true;
|
|
1059
|
+
return matchesChecksum(addr, lower);
|
|
1060
|
+
}
|
|
1061
|
+
function matchesChecksum(addr, lower) {
|
|
1062
|
+
const hashBytes = keccak_256(lower);
|
|
1063
|
+
for (let i = 0; i < 40; i++) {
|
|
1064
|
+
if (!charCaseMatchesNibble(addr.charCodeAt(i), nibbleAt(hashBytes, i))) {
|
|
1065
|
+
return false;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
return true;
|
|
1069
|
+
}
|
|
1070
|
+
function nibbleAt(bytes, i) {
|
|
1071
|
+
return bytes[i >> 1] >> (i % 2 === 0 ? 4 : 0) & 15;
|
|
1072
|
+
}
|
|
1073
|
+
function charCaseMatchesNibble(ch, nibble) {
|
|
1074
|
+
if (ch >= 97 && ch <= 102)
|
|
1075
|
+
return nibble < 8;
|
|
1076
|
+
if (ch >= 65 && ch <= 70)
|
|
1077
|
+
return nibble >= 8;
|
|
1078
|
+
return true;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/ibanMod97.js
|
|
1082
|
+
function ibanMod97(input) {
|
|
1083
|
+
const iban = input.replace(/\s/g, "");
|
|
1084
|
+
const len = iban.length;
|
|
1085
|
+
if (len < 15 || len > 34)
|
|
1086
|
+
return false;
|
|
1087
|
+
let rearranged = "";
|
|
1088
|
+
for (let i = 4; i < len + 4; i++) {
|
|
1089
|
+
const c = iban.charCodeAt(i % len);
|
|
1090
|
+
if (c >= 48 && c <= 57) {
|
|
1091
|
+
rearranged += String.fromCharCode(c);
|
|
1092
|
+
} else if (c >= 65 && c <= 90) {
|
|
1093
|
+
rearranged += String(c - 65 + 10);
|
|
1094
|
+
} else if (c >= 97 && c <= 122) {
|
|
1095
|
+
rearranged += String(c - 97 + 10);
|
|
1096
|
+
} else {
|
|
1097
|
+
return false;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
try {
|
|
1101
|
+
return BigInt(rearranged) % 97n === 1n;
|
|
1102
|
+
} catch {
|
|
1103
|
+
return false;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// node_modules/@darkhunt-security/telemetry/dist/masking/validators/index.js
|
|
1108
|
+
var VALIDATORS = Object.freeze({
|
|
1109
|
+
aba,
|
|
1110
|
+
base58check,
|
|
1111
|
+
bech32,
|
|
1112
|
+
credit_card: creditCard,
|
|
1113
|
+
eip55,
|
|
1114
|
+
iban_mod97: ibanMod97,
|
|
1115
|
+
luhn
|
|
1116
|
+
});
|
|
1117
|
+
|
|
1118
|
+
// node_modules/@darkhunt-security/telemetry/dist/client.js
|
|
1119
|
+
var LIB_VERSION = package_default.version;
|
|
1120
|
+
|
|
1121
|
+
// packages/core/dist/cli/status.js
|
|
1122
|
+
import { existsSync as existsSync2, readFileSync as readFileSync5, statSync as statSync3 } from "node:fs";
|
|
1123
|
+
var SESSION_HOOK_STALE_MS = 30 * 60 * 1e3;
|
|
1124
|
+
function status(vendor, mapper) {
|
|
1125
|
+
const config = loadLocalConfig(vendor);
|
|
1126
|
+
const checkpoints = loadCheckpoints(config.scope);
|
|
1127
|
+
const transcripts = [];
|
|
1128
|
+
for (const [path, cp] of Object.entries(checkpoints)) {
|
|
1129
|
+
if (path === "::spool::")
|
|
1130
|
+
continue;
|
|
1131
|
+
const size = existsSync2(path) ? statSync3(path).size : 0;
|
|
1132
|
+
transcripts.push({ path, shipped: cp.offset, size, lag: Math.max(0, size - cp.offset) });
|
|
1133
|
+
}
|
|
1134
|
+
const lastPass = loadHealth(config.scope);
|
|
1135
|
+
const spool = spoolPath(vendor);
|
|
1136
|
+
let spoolEvents = 0;
|
|
1137
|
+
let spoolLastAt;
|
|
1138
|
+
if (existsSync2(spool)) {
|
|
1139
|
+
const lines = readFileSync5(spool, "utf8").split("\n").filter(Boolean);
|
|
1140
|
+
spoolEvents = lines.length;
|
|
1141
|
+
const last = lines[lines.length - 1];
|
|
1142
|
+
if (last) {
|
|
1143
|
+
try {
|
|
1144
|
+
const ts = JSON.parse(last).ts;
|
|
1145
|
+
if (ts)
|
|
1146
|
+
spoolLastAt = new Date(ts).toISOString();
|
|
1147
|
+
} catch {
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
const beat = loadBeat(config.scope);
|
|
1152
|
+
const guardAt = beat?.lane === "guard" ? Date.parse(beat.at) : Date.parse(beat?.at ?? "");
|
|
1153
|
+
const sessionAt = Date.parse(spoolLastAt ?? beat?.lastSpoolAt ?? "");
|
|
1154
|
+
const sessionHooksStale = !Number.isNaN(guardAt) && Date.now() - guardAt < SESSION_HOOK_STALE_MS && (Number.isNaN(sessionAt) || guardAt - sessionAt > SESSION_HOOK_STALE_MS);
|
|
1155
|
+
const fromAgent = mapper?.resolveUserId?.();
|
|
1156
|
+
const userId = fromAgent ?? config.userId;
|
|
1157
|
+
return {
|
|
1158
|
+
profile: config.profile,
|
|
1159
|
+
baseUrl: config.baseUrl,
|
|
1160
|
+
tenantId: config.tenantId,
|
|
1161
|
+
workspaceId: config.workspaceId,
|
|
1162
|
+
scope: config.scope,
|
|
1163
|
+
capture: config.capture.enabled && config.enabled,
|
|
1164
|
+
enforce: config.enabled ? config.enforce.mode : "off (kill switch)",
|
|
1165
|
+
spoolEvents,
|
|
1166
|
+
...spoolLastAt !== void 0 ? { spoolLastAt } : {},
|
|
1167
|
+
...beat !== void 0 ? { lastHookAt: beat.at, lastHookLane: beat.lane } : {},
|
|
1168
|
+
sessionHooksStale,
|
|
1169
|
+
...userId !== void 0 ? { userId } : {},
|
|
1170
|
+
userIdSource: fromAgent !== void 0 ? "agent" : userId !== void 0 ? "config" : "none",
|
|
1171
|
+
transcripts,
|
|
1172
|
+
totalLag: transcripts.reduce((sum, t) => sum + t.lag, 0),
|
|
1173
|
+
...lastPass !== void 0 ? { lastPass } : {},
|
|
1174
|
+
lockHeld: existsSync2(spool.replace(/spool\/.*$/, `${config.scope}.forwarder.lock`))
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
// packages/core/dist/cli/enroll.js
|
|
1179
|
+
import { homedir as homedir3 } from "node:os";
|
|
1180
|
+
import { join as join8 } from "node:path";
|
|
1181
|
+
var CLI_CREDENTIALS_PATH = join8(homedir3(), ".darkhunt", "credentials.json");
|
|
1182
|
+
|
|
1183
|
+
// adapters/codex/dist/transcript.js
|
|
1184
|
+
import { basename, join as join9 } from "node:path";
|
|
1185
|
+
import { homedir as homedir4 } from "node:os";
|
|
1186
|
+
function str(value) {
|
|
1187
|
+
return typeof value === "string" ? value : void 0;
|
|
1188
|
+
}
|
|
1189
|
+
function num(value) {
|
|
1190
|
+
return typeof value === "number" ? value : void 0;
|
|
1191
|
+
}
|
|
1192
|
+
function mapTokenCount(info) {
|
|
1193
|
+
if (!info || typeof info !== "object")
|
|
1194
|
+
return void 0;
|
|
1195
|
+
const bag = info;
|
|
1196
|
+
const last = bag["last_token_usage"] ?? bag["total_token_usage"] ?? bag;
|
|
1197
|
+
const out = {};
|
|
1198
|
+
const input = num(last["input_tokens"]);
|
|
1199
|
+
const output = num(last["output_tokens"]);
|
|
1200
|
+
const cached = num(last["cached_input_tokens"]);
|
|
1201
|
+
const reasoning = num(last["reasoning_output_tokens"]);
|
|
1202
|
+
if (input !== void 0)
|
|
1203
|
+
out.input_tokens = input;
|
|
1204
|
+
if (output !== void 0)
|
|
1205
|
+
out.output_tokens = output;
|
|
1206
|
+
if (cached !== void 0)
|
|
1207
|
+
out.cache_read_tokens = cached;
|
|
1208
|
+
if (reasoning !== void 0)
|
|
1209
|
+
out.thinking_tokens = reasoning;
|
|
1210
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
1211
|
+
}
|
|
1212
|
+
function textOf(content) {
|
|
1213
|
+
if (typeof content === "string")
|
|
1214
|
+
return content;
|
|
1215
|
+
if (!Array.isArray(content))
|
|
1216
|
+
return void 0;
|
|
1217
|
+
const parts = content.map((b) => b && typeof b === "object" ? str(b["text"]) : void 0).filter((t) => !!t);
|
|
1218
|
+
return parts.length > 0 ? parts.join("\n") : void 0;
|
|
1219
|
+
}
|
|
1220
|
+
var codexTranscript = {
|
|
1221
|
+
vendor: "codex",
|
|
1222
|
+
sessionRoots() {
|
|
1223
|
+
return [join9(homedir4(), ".codex", "sessions")];
|
|
1224
|
+
},
|
|
1225
|
+
// No `resolveUserId` yet, so Codex traces fall back to the configured `userId`.
|
|
1226
|
+
// The identity exists but not as a plain field: `~/.codex/auth.json` holds
|
|
1227
|
+
// `tokens.account_id` (a UUID, not a person) and an `email` claim inside the
|
|
1228
|
+
// `id_token` JWT. Reading it means decoding an OAuth token and honouring its expiry —
|
|
1229
|
+
// a stale token would attribute sessions to a *wrong* address, which is worse than
|
|
1230
|
+
// leaving them unattributed. Tracked separately.
|
|
1231
|
+
sessionIdFor(path) {
|
|
1232
|
+
const name = basename(path, ".jsonl");
|
|
1233
|
+
const match = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i.exec(name);
|
|
1234
|
+
return match?.[1] ?? name;
|
|
1235
|
+
},
|
|
1236
|
+
mapLine(line, offset = 0) {
|
|
1237
|
+
const trimmed = line.trim();
|
|
1238
|
+
if (!trimmed)
|
|
1239
|
+
return [];
|
|
1240
|
+
let raw;
|
|
1241
|
+
try {
|
|
1242
|
+
raw = JSON.parse(trimmed);
|
|
1243
|
+
} catch {
|
|
1244
|
+
return [];
|
|
1245
|
+
}
|
|
1246
|
+
const payload = raw.payload;
|
|
1247
|
+
if (!payload)
|
|
1248
|
+
return [];
|
|
1249
|
+
const ts = raw.timestamp ? Date.parse(raw.timestamp) : Date.now();
|
|
1250
|
+
const uuid = `codex:${offset}`;
|
|
1251
|
+
const base = { vendor: "codex", ts, uuid };
|
|
1252
|
+
if (raw.type === "session_meta") {
|
|
1253
|
+
return [
|
|
1254
|
+
{
|
|
1255
|
+
...base,
|
|
1256
|
+
kind: "session_meta",
|
|
1257
|
+
meta: {
|
|
1258
|
+
...str(payload["cwd"]) !== void 0 ? { cwd: str(payload["cwd"]) } : {},
|
|
1259
|
+
...str(payload["cli_version"]) !== void 0 ? { version: str(payload["cli_version"]) } : {},
|
|
1260
|
+
...str(payload["originator"]) !== void 0 ? { entrypoint: str(payload["originator"]) } : {}
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
];
|
|
1264
|
+
}
|
|
1265
|
+
if (raw.type === "turn_context") {
|
|
1266
|
+
const model = str(payload["model"]);
|
|
1267
|
+
if (!model)
|
|
1268
|
+
return [];
|
|
1269
|
+
return [{ ...base, kind: "session_meta", meta: { model } }];
|
|
1270
|
+
}
|
|
1271
|
+
const kind = str(payload["type"]);
|
|
1272
|
+
if (raw.type === "event_msg" && kind === "token_count") {
|
|
1273
|
+
const usage = mapTokenCount(payload["info"]);
|
|
1274
|
+
return usage ? [{ ...base, kind: "usage", usage }] : [];
|
|
1275
|
+
}
|
|
1276
|
+
if (raw.type !== "response_item")
|
|
1277
|
+
return [];
|
|
1278
|
+
switch (kind) {
|
|
1279
|
+
case "function_call":
|
|
1280
|
+
return [
|
|
1281
|
+
{
|
|
1282
|
+
...base,
|
|
1283
|
+
kind: "tool_call",
|
|
1284
|
+
toolName: str(payload["name"]) ?? "tool",
|
|
1285
|
+
input: payload["arguments"],
|
|
1286
|
+
...str(payload["call_id"]) !== void 0 ? { toolCallId: str(payload["call_id"]) } : {}
|
|
1287
|
+
}
|
|
1288
|
+
];
|
|
1289
|
+
case "function_call_output":
|
|
1290
|
+
return [
|
|
1291
|
+
{
|
|
1292
|
+
...base,
|
|
1293
|
+
kind: "tool_result",
|
|
1294
|
+
output: payload["output"],
|
|
1295
|
+
...str(payload["call_id"]) !== void 0 ? { toolCallId: str(payload["call_id"]) } : {}
|
|
1296
|
+
}
|
|
1297
|
+
];
|
|
1298
|
+
case "reasoning": {
|
|
1299
|
+
const text = textOf(payload["summary"]) ?? textOf(payload["content"]);
|
|
1300
|
+
return text ? [{ ...base, kind: "thinking", text }] : [];
|
|
1301
|
+
}
|
|
1302
|
+
case "message": {
|
|
1303
|
+
const text = textOf(payload["content"]);
|
|
1304
|
+
if (!text)
|
|
1305
|
+
return [];
|
|
1306
|
+
switch (str(payload["role"])) {
|
|
1307
|
+
case "user":
|
|
1308
|
+
return [{ ...base, kind: "user_message", text }];
|
|
1309
|
+
case "assistant":
|
|
1310
|
+
return [{ ...base, kind: "assistant_message", text }];
|
|
1311
|
+
default:
|
|
1312
|
+
return [];
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
default:
|
|
1316
|
+
return [];
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1321
|
+
// adapters/codex/bin/status.mjs
|
|
1322
|
+
try {
|
|
1323
|
+
const s = status("codex", codexTranscript);
|
|
1324
|
+
const n = (x) => x.toLocaleString();
|
|
1325
|
+
console.log(`darkhunt endpoint status \u2014 codex`);
|
|
1326
|
+
console.log(` profile ${s.profile} -> ${s.baseUrl}`);
|
|
1327
|
+
console.log(` tenant ${s.tenantId} workspace ${s.workspaceId}`);
|
|
1328
|
+
console.log(
|
|
1329
|
+
` user ${s.userId ?? "(none \u2014 traces are unattributed)"}` + (s.userIdSource === "none" ? "" : ` [from ${s.userIdSource}]`)
|
|
1330
|
+
);
|
|
1331
|
+
console.log(` capture ${s.capture ? "ON" : "OFF"} enforce ${s.enforce}`);
|
|
1332
|
+
console.log(
|
|
1333
|
+
` hook events ${s.spoolEvents}${s.spoolLastAt ? " last " + s.spoolLastAt : " (no session hook has ever fired)"}`
|
|
1334
|
+
);
|
|
1335
|
+
if (s.lastHookAt) {
|
|
1336
|
+
console.log(` last hook ${s.lastHookAt} (${s.lastHookLane} lane)`);
|
|
1337
|
+
}
|
|
1338
|
+
if (s.sessionHooksStale) {
|
|
1339
|
+
console.log(
|
|
1340
|
+
" WARNING session hooks are not firing \u2014 the guard is running but\n SessionStart/Stop/SessionEnd have gone quiet. Capture is\n riding PreToolUse alone; run backfill.mjs to close any gap."
|
|
1341
|
+
);
|
|
1342
|
+
}
|
|
1343
|
+
console.log(` forwarder ${s.lockHeld ? "RUNNING" : "idle"}`);
|
|
1344
|
+
if (s.lastPass) {
|
|
1345
|
+
const p = s.lastPass;
|
|
1346
|
+
console.log(
|
|
1347
|
+
` last pass ${p.ok ? "OK" : "FAILED"} ${p.at}` + (p.ok ? ` (${p.transcripts} transcript(s), ${n(p.records)} record(s))` : "")
|
|
1348
|
+
);
|
|
1349
|
+
if (!p.ok) {
|
|
1350
|
+
console.log(` cause ${p.error}`);
|
|
1351
|
+
console.log(
|
|
1352
|
+
` ${p.consecutiveFailures} pass(es) failed in a row \u2014 checkpoints are held, nothing is being lost`
|
|
1353
|
+
);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
if (s.transcripts.length === 0) {
|
|
1357
|
+
console.log(" transcripts none shipped yet");
|
|
1358
|
+
} else {
|
|
1359
|
+
console.log(" transcripts:");
|
|
1360
|
+
for (const t of s.transcripts) {
|
|
1361
|
+
console.log(` ${t.path.split("/").pop()}`);
|
|
1362
|
+
console.log(` shipped ${n(t.shipped)} / ${n(t.size)} bytes lag ${n(t.lag)}`);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
const note = s.totalLag > 0 ? " (ships on the next turn)" : s.lastPass && !s.lastPass.ok ? " (nothing shipped \u2014 see last pass)" : " (fully caught up)";
|
|
1366
|
+
console.log(` total lag ${n(s.totalLag)} bytes${note}`);
|
|
1367
|
+
} catch (err) {
|
|
1368
|
+
console.error(`darkhunt: ${err.message}`);
|
|
1369
|
+
process.exit(1);
|
|
1370
|
+
}
|
|
1371
|
+
/*! Bundled license information:
|
|
1372
|
+
|
|
1373
|
+
@noble/hashes/esm/utils.js:
|
|
1374
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
1375
|
+
*/
|