unbrowse 3.0.4 → 3.1.0-experiments.186be38
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/dist/cli.js +643 -105
- package/dist/index.js +2 -6
- package/dist/mcp.js +649 -47
- package/dist/server.js +25798 -0
- package/package.json +1 -2
- package/vendor/kuri/darwin-arm64/kuri +0 -0
- package/vendor/kuri/darwin-x64/kuri +0 -0
- package/vendor/kuri/linux-arm64/kuri +0 -0
- package/vendor/kuri/linux-x64/kuri +0 -0
- package/vendor/kuri/manifest.json +7 -6
- package/runtime-src/agent-outcome.ts +0 -166
- package/runtime-src/analytics-session.ts +0 -55
- package/runtime-src/api/browse-index.ts +0 -317
- package/runtime-src/api/browse-session.ts +0 -572
- package/runtime-src/api/browse-submit-prereqs.ts +0 -48
- package/runtime-src/api/browse-submit.ts +0 -1184
- package/runtime-src/api/routes.ts +0 -1823
- package/runtime-src/auth/browser-cookies.ts +0 -423
- package/runtime-src/auth/index.ts +0 -535
- package/runtime-src/auth/runtime.ts +0 -116
- package/runtime-src/browser/index.ts +0 -659
- package/runtime-src/browser/types.ts +0 -41
- package/runtime-src/build-info.generated.ts +0 -6
- package/runtime-src/capture/index.ts +0 -1794
- package/runtime-src/capture/prefetch.ts +0 -95
- package/runtime-src/capture/rsc.ts +0 -45
- package/runtime-src/cli/shortcuts.ts +0 -273
- package/runtime-src/cli.ts +0 -1546
- package/runtime-src/client/graph-client.ts +0 -100
- package/runtime-src/client/index.ts +0 -1401
- package/runtime-src/debug-trace.ts +0 -18
- package/runtime-src/domain.ts +0 -38
- package/runtime-src/execution/index.ts +0 -3385
- package/runtime-src/execution/retry.ts +0 -46
- package/runtime-src/execution/robots.ts +0 -167
- package/runtime-src/execution/search-forms.ts +0 -188
- package/runtime-src/extraction/index.ts +0 -1507
- package/runtime-src/foundry/publish-bundle.ts +0 -392
- package/runtime-src/graph/agent-augment.ts +0 -315
- package/runtime-src/graph/index.ts +0 -1524
- package/runtime-src/graph/local-fixtures.ts +0 -393
- package/runtime-src/graph/local-harness.ts +0 -646
- package/runtime-src/graph/planner.ts +0 -411
- package/runtime-src/graph/session.ts +0 -294
- package/runtime-src/graph/trace-store.ts +0 -136
- package/runtime-src/index.ts +0 -24
- package/runtime-src/indexer/index.ts +0 -465
- package/runtime-src/intent-match.ts +0 -1515
- package/runtime-src/kuri/client.ts +0 -1835
- package/runtime-src/logger.ts +0 -30
- package/runtime-src/marketplace/index.ts +0 -103
- package/runtime-src/mcp.ts +0 -1747
- package/runtime-src/orchestrator/browser-agent.ts +0 -374
- package/runtime-src/orchestrator/dag-advisor.ts +0 -59
- package/runtime-src/orchestrator/dag-feedback.ts +0 -257
- package/runtime-src/orchestrator/first-pass-action.ts +0 -403
- package/runtime-src/orchestrator/index.ts +0 -4476
- package/runtime-src/orchestrator/passive-publish.ts +0 -187
- package/runtime-src/orchestrator/timing-economics.ts +0 -80
- package/runtime-src/payments/cascade.ts +0 -137
- package/runtime-src/payments/index.ts +0 -270
- package/runtime-src/payments/wallet.ts +0 -98
- package/runtime-src/publish/review-context.ts +0 -93
- package/runtime-src/publish/sanitize.ts +0 -197
- package/runtime-src/publish/schema-review.ts +0 -192
- package/runtime-src/publish-admission.ts +0 -388
- package/runtime-src/ratelimit/index.ts +0 -23
- package/runtime-src/reverse-engineer/bundle-scanner.ts +0 -127
- package/runtime-src/reverse-engineer/description-prompt.ts +0 -213
- package/runtime-src/reverse-engineer/index.ts +0 -1551
- package/runtime-src/router.ts +0 -17
- package/runtime-src/routing-telemetry.ts +0 -395
- package/runtime-src/runtime/browser-access.ts +0 -11
- package/runtime-src/runtime/browser-auth.ts +0 -12
- package/runtime-src/runtime/browser-host.ts +0 -48
- package/runtime-src/runtime/lifecycle.ts +0 -17
- package/runtime-src/runtime/local-server.ts +0 -311
- package/runtime-src/runtime/paths.ts +0 -99
- package/runtime-src/runtime/setup.ts +0 -251
- package/runtime-src/runtime/supervisor.ts +0 -69
- package/runtime-src/runtime/update-hints.ts +0 -351
- package/runtime-src/server.ts +0 -100
- package/runtime-src/session-logs.ts +0 -142
- package/runtime-src/settings.ts +0 -221
- package/runtime-src/single-binary.ts +0 -143
- package/runtime-src/site-policy.ts +0 -54
- package/runtime-src/stale-cleanup-runner.ts +0 -144
- package/runtime-src/stale-cleanup.ts +0 -133
- package/runtime-src/telemetry-attribution.ts +0 -120
- package/runtime-src/telemetry.ts +0 -253
- package/runtime-src/template-params.ts +0 -141
- package/runtime-src/transform/drift.ts +0 -60
- package/runtime-src/transform/index.ts +0 -277
- package/runtime-src/types/index.ts +0 -1
- package/runtime-src/types/skill.ts +0 -912
- package/runtime-src/vault/index.ts +0 -196
- package/runtime-src/verification/auth-gate.ts +0 -8
- package/runtime-src/verification/candidates.ts +0 -27
- package/runtime-src/verification/index.ts +0 -120
- package/runtime-src/verification/matrix.ts +0 -30
- package/runtime-src/version.ts +0 -148
- package/runtime-src/workflow/artifact.ts +0 -161
- package/runtime-src/workflow/compile.ts +0 -808
- package/runtime-src/workflow/publish.ts +0 -225
- package/runtime-src/workflow/runtime.ts +0 -213
package/dist/cli.js
CHANGED
|
@@ -17,12 +17,21 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
17
17
|
});
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
set: (newValue) => all[name] = () => newValue
|
|
27
|
+
});
|
|
28
|
+
};
|
|
20
29
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
21
30
|
var __promiseAll = (args) => Promise.all(args);
|
|
22
31
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
23
32
|
|
|
24
33
|
// ../../src/build-info.generated.ts
|
|
25
|
-
var BUILD_RELEASE_VERSION = "3.0.
|
|
34
|
+
var BUILD_RELEASE_VERSION = "3.1.0-experiments.186be38", BUILD_GIT_SHA = "186be383bb59", BUILD_CODE_HASH = "1488fc1d92b7", BUILD_RELEASE_MANIFEST_BASE64 = "eyJzY2hlbWFfdmVyc2lvbiI6MSwicmVsZWFzZV92ZXJzaW9uIjoiMy4xLjAtZXhwZXJpbWVudHMuMTg2YmUzOCIsImdpdF9zaGEiOiIxODZiZTM4M2JiNTkiLCJjb2RlX2hhc2giOiIxNDg4ZmMxZDkyYjciLCJ0cmFjZV92ZXJzaW9uIjoiMTQ4OGZjMWQ5MmI3QDE4NmJlMzgzYmI1OSIsImlzc3VlZF9hdCI6IjIwMjYtMDQtMDZUMDM6MzQ6MDUuMDkwWiJ9", BUILD_RELEASE_MANIFEST_SIGNATURE = "YZKX-KcH1QZ29BvWApkOsllb4sm0Uv-743YX97ml6HM", BUILD_DEFAULT_BACKEND_URL = "https://unbrowse-backend-experiments.lewis-6d8.workers.dev";
|
|
26
35
|
|
|
27
36
|
// ../../src/version.ts
|
|
28
37
|
import { createHash } from "crypto";
|
|
@@ -284,8 +293,114 @@ var init_telemetry_attribution = __esm(() => {
|
|
|
284
293
|
];
|
|
285
294
|
});
|
|
286
295
|
|
|
296
|
+
// ../../src/payments/lobster-pay.ts
|
|
297
|
+
var exports_lobster_pay = {};
|
|
298
|
+
__export(exports_lobster_pay, {
|
|
299
|
+
payAndRetry: () => payAndRetry,
|
|
300
|
+
lobsterX402Fetch: () => lobsterX402Fetch,
|
|
301
|
+
isLobsterAvailable: () => isLobsterAvailable
|
|
302
|
+
});
|
|
303
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
304
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
305
|
+
import { homedir as homedir2 } from "node:os";
|
|
306
|
+
import { join as join3 } from "node:path";
|
|
307
|
+
function getLobsterCommand() {
|
|
308
|
+
try {
|
|
309
|
+
execFileSync("lobstercash", ["--version"], { stdio: "ignore", timeout: 3000 });
|
|
310
|
+
return { cmd: "lobstercash", prefix: [] };
|
|
311
|
+
} catch (_e) {}
|
|
312
|
+
try {
|
|
313
|
+
const npmPrefix = execFileSync("npm", ["config", "get", "prefix"], { encoding: "utf8", timeout: 5000 }).trim();
|
|
314
|
+
const lobsterPath = join3(npmPrefix, "bin", "lobstercash");
|
|
315
|
+
if (existsSync3(lobsterPath)) {
|
|
316
|
+
execFileSync(lobsterPath, ["--version"], { stdio: "ignore", timeout: 3000 });
|
|
317
|
+
return { cmd: lobsterPath, prefix: [] };
|
|
318
|
+
}
|
|
319
|
+
} catch (_e) {}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
function lobsterCmd() {
|
|
323
|
+
if (cachedCommand === undefined)
|
|
324
|
+
cachedCommand = getLobsterCommand();
|
|
325
|
+
return cachedCommand;
|
|
326
|
+
}
|
|
327
|
+
function isLobsterAvailable() {
|
|
328
|
+
const agentsPath = join3(process.env.HOME || homedir2(), ".lobster", "agents.json");
|
|
329
|
+
return existsSync3(agentsPath);
|
|
330
|
+
}
|
|
331
|
+
function lobsterX402Fetch(url, options) {
|
|
332
|
+
return new Promise((resolve) => {
|
|
333
|
+
const resolved = lobsterCmd();
|
|
334
|
+
if (!resolved) {
|
|
335
|
+
resolve({ success: false, body: "", error: "lobstercash CLI not in PATH" });
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const { cmd, prefix } = resolved;
|
|
339
|
+
const args = [...prefix, "x402", "fetch", url, "--debug"];
|
|
340
|
+
if (options?.jsonBody) {
|
|
341
|
+
args.push("--json", options.jsonBody);
|
|
342
|
+
}
|
|
343
|
+
if (options?.headers) {
|
|
344
|
+
for (const [key, value] of Object.entries(options.headers)) {
|
|
345
|
+
args.push("--header", `${key}:${value}`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const timeout = options?.timeoutMs ?? LOBSTER_PAY_TIMEOUT_MS;
|
|
349
|
+
args.push("--timeout", String(timeout));
|
|
350
|
+
execFile(cmd, args, { timeout: timeout + 5000, maxBuffer: 1024 * 1024 }, (err, stdout, stderr) => {
|
|
351
|
+
if (err) {
|
|
352
|
+
const msg = stderr?.trim() || err.message;
|
|
353
|
+
console.warn(`[lobster-pay] x402 fetch failed: ${msg}`);
|
|
354
|
+
resolve({ success: false, body: "", error: msg });
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (stderr) {
|
|
358
|
+
for (const line of stderr.split(`
|
|
359
|
+
`).filter(Boolean)) {
|
|
360
|
+
console.log(`[lobster-pay] ${line}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const statusMatch = stdout.match(/^Status:\s*(\d+)/m);
|
|
364
|
+
const statusCode = statusMatch ? parseInt(statusMatch[1], 10) : undefined;
|
|
365
|
+
if (statusCode && statusCode >= 400) {
|
|
366
|
+
resolve({ success: false, body: stdout, statusCode, error: `HTTP ${statusCode}` });
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
resolve({ success: true, body: stdout, statusCode });
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
async function payAndRetry(fullUrl, options) {
|
|
374
|
+
if (!isLobsterAvailable()) {
|
|
375
|
+
console.log("[lobster-pay] lobster.cash not configured — skipping payment");
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
console.log(`[lobster-pay] attempting x402 payment for ${fullUrl}`);
|
|
379
|
+
const result = await lobsterX402Fetch(fullUrl, {
|
|
380
|
+
jsonBody: options?.body ? JSON.stringify(options.body) : undefined,
|
|
381
|
+
headers: options?.headers
|
|
382
|
+
});
|
|
383
|
+
if (!result.success) {
|
|
384
|
+
console.warn(`[lobster-pay] payment failed: ${result.error}`);
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
const raw = result.body;
|
|
389
|
+
const jsonStart = Math.min(...[raw.indexOf("{"), raw.indexOf("[")].filter((i) => i >= 0));
|
|
390
|
+
const jsonStr = jsonStart >= 0 ? raw.slice(jsonStart) : raw;
|
|
391
|
+
const data = JSON.parse(jsonStr);
|
|
392
|
+
console.log("[lobster-pay] payment successful — got paid response");
|
|
393
|
+
return { data, paid: true };
|
|
394
|
+
} catch (_e) {
|
|
395
|
+
console.warn("[lobster-pay] paid response was not valid JSON");
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
var LOBSTER_PAY_TIMEOUT_MS = 30000, cachedCommand = undefined;
|
|
400
|
+
var init_lobster_pay = () => {};
|
|
401
|
+
|
|
287
402
|
// ../../src/runtime/paths.ts
|
|
288
|
-
import { existsSync as
|
|
403
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync3, realpathSync } from "node:fs";
|
|
289
404
|
import os from "node:os";
|
|
290
405
|
import path from "node:path";
|
|
291
406
|
import { createRequire as createRequire2 } from "node:module";
|
|
@@ -299,7 +414,7 @@ function getPackageRoot(metaUrl) {
|
|
|
299
414
|
let dir = getModuleDir(metaUrl);
|
|
300
415
|
const root = path.parse(dir).root;
|
|
301
416
|
while (dir !== root) {
|
|
302
|
-
if (
|
|
417
|
+
if (existsSync6(path.join(dir, "package.json")))
|
|
303
418
|
return dir;
|
|
304
419
|
dir = path.dirname(dir);
|
|
305
420
|
}
|
|
@@ -318,7 +433,7 @@ function runtimeArgsForEntrypoint(metaUrl, entrypoint) {
|
|
|
318
433
|
const req = createRequire2(metaUrl);
|
|
319
434
|
const tsxPkg = req.resolve("tsx/package.json");
|
|
320
435
|
const tsxLoader = path.join(path.dirname(tsxPkg), "dist", "loader.mjs");
|
|
321
|
-
if (
|
|
436
|
+
if (existsSync6(tsxLoader))
|
|
322
437
|
return ["--import", pathToFileURL(tsxLoader).href, entrypoint];
|
|
323
438
|
} catch {}
|
|
324
439
|
return ["--import", "tsx", entrypoint];
|
|
@@ -326,16 +441,16 @@ function runtimeArgsForEntrypoint(metaUrl, entrypoint) {
|
|
|
326
441
|
function getUnbrowseHome() {
|
|
327
442
|
return path.join(os.homedir(), ".unbrowse");
|
|
328
443
|
}
|
|
329
|
-
function
|
|
330
|
-
if (!
|
|
331
|
-
|
|
444
|
+
function ensureDir2(dir) {
|
|
445
|
+
if (!existsSync6(dir))
|
|
446
|
+
mkdirSync3(dir, { recursive: true });
|
|
332
447
|
return dir;
|
|
333
448
|
}
|
|
334
449
|
function getLogsDir() {
|
|
335
|
-
return
|
|
450
|
+
return ensureDir2(path.join(getUnbrowseHome(), "logs"));
|
|
336
451
|
}
|
|
337
452
|
function getRunDir() {
|
|
338
|
-
return
|
|
453
|
+
return ensureDir2(process.env.UNBROWSE_RUN_DIR || path.join(getUnbrowseHome(), "run"));
|
|
339
454
|
}
|
|
340
455
|
function sanitizeSegment(value) {
|
|
341
456
|
return value.replace(/[^a-zA-Z0-9.-]+/g, "_");
|
|
@@ -470,8 +585,8 @@ var init_logger = __esm(() => {
|
|
|
470
585
|
});
|
|
471
586
|
|
|
472
587
|
// ../../src/kuri/client.ts
|
|
473
|
-
import { execFileSync, spawn as spawn2 } from "node:child_process";
|
|
474
|
-
import { existsSync as
|
|
588
|
+
import { execFileSync as execFileSync2, spawn as spawn2 } from "node:child_process";
|
|
589
|
+
import { existsSync as existsSync9 } from "node:fs";
|
|
475
590
|
import path5 from "node:path";
|
|
476
591
|
function createBrokerState(port = KURI_DEFAULT_PORT) {
|
|
477
592
|
return {
|
|
@@ -496,12 +611,14 @@ function currentBundledKuriTarget() {
|
|
|
496
611
|
return "linux-arm64";
|
|
497
612
|
if (process.platform === "linux" && process.arch === "x64")
|
|
498
613
|
return "linux-x64";
|
|
614
|
+
if (process.platform === "win32" && process.arch === "x64")
|
|
615
|
+
return "win-x64";
|
|
499
616
|
return null;
|
|
500
617
|
}
|
|
501
618
|
function resolveBinaryOnPath(name) {
|
|
502
619
|
const checker = process.platform === "win32" ? "where" : "which";
|
|
503
620
|
try {
|
|
504
|
-
const output =
|
|
621
|
+
const output = execFileSync2(checker, [name], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
505
622
|
const match = output.split(/\r?\n/).map((line) => line.trim()).find(Boolean);
|
|
506
623
|
return match || null;
|
|
507
624
|
} catch {
|
|
@@ -544,7 +661,7 @@ function findKuriBinary() {
|
|
|
544
661
|
if (process.env.KURI_BIN)
|
|
545
662
|
return process.env.KURI_BIN;
|
|
546
663
|
const candidates = getKuriBinaryCandidates();
|
|
547
|
-
return candidates.find((candidate) =>
|
|
664
|
+
return candidates.find((candidate) => existsSync9(candidate)) ?? candidates[0] ?? kuriBinaryName();
|
|
548
665
|
}
|
|
549
666
|
var KURI_DEFAULT_PORT = 7700, defaultBrokerState, brokerClients;
|
|
550
667
|
var init_client2 = __esm(() => {
|
|
@@ -567,7 +684,7 @@ var init_browser_access = () => {};
|
|
|
567
684
|
|
|
568
685
|
// ../../src/capture/index.ts
|
|
569
686
|
import { nanoid as nanoid2 } from "nanoid";
|
|
570
|
-
var activeTabRegistry, interceptorInjectedTabs;
|
|
687
|
+
var activeTabRegistry, interceptorInjectedTabs, cdpDocStartTabs, cdpCapturedHeaders;
|
|
571
688
|
var init_capture = __esm(() => {
|
|
572
689
|
init_client2();
|
|
573
690
|
init_domain();
|
|
@@ -575,6 +692,8 @@ var init_capture = __esm(() => {
|
|
|
575
692
|
init_browser_access();
|
|
576
693
|
activeTabRegistry = new Set;
|
|
577
694
|
interceptorInjectedTabs = new Set;
|
|
695
|
+
cdpDocStartTabs = new Set;
|
|
696
|
+
cdpCapturedHeaders = new Map;
|
|
578
697
|
});
|
|
579
698
|
|
|
580
699
|
// ../../src/transform/index.ts
|
|
@@ -584,11 +703,11 @@ var init_transform = __esm(() => {
|
|
|
584
703
|
});
|
|
585
704
|
|
|
586
705
|
// ../../src/debug-trace.ts
|
|
587
|
-
import { join as
|
|
706
|
+
import { join as join6 } from "node:path";
|
|
588
707
|
import { nanoid as nanoid3 } from "nanoid";
|
|
589
708
|
var TRACE_DIR;
|
|
590
709
|
var init_debug_trace = __esm(() => {
|
|
591
|
-
TRACE_DIR = process.env.TRACES_DIR ??
|
|
710
|
+
TRACE_DIR = process.env.TRACES_DIR ?? join6(process.cwd(), "traces");
|
|
592
711
|
});
|
|
593
712
|
|
|
594
713
|
// ../../src/publish/sanitize.ts
|
|
@@ -678,8 +797,8 @@ var init_bundle_scanner = __esm(() => {
|
|
|
678
797
|
});
|
|
679
798
|
|
|
680
799
|
// ../../src/vault/index.ts
|
|
681
|
-
import { join as
|
|
682
|
-
import { homedir as
|
|
800
|
+
import { join as join7 } from "path";
|
|
801
|
+
import { homedir as homedir5 } from "os";
|
|
683
802
|
function normalizeKeytarModule(mod) {
|
|
684
803
|
let candidate = mod;
|
|
685
804
|
for (let depth = 0;depth < 3; depth++) {
|
|
@@ -701,9 +820,9 @@ var init_vault = __esm(async () => {
|
|
|
701
820
|
try {
|
|
702
821
|
keytar = normalizeKeytarModule(await import("keytar"));
|
|
703
822
|
} catch {}
|
|
704
|
-
VAULT_DIR =
|
|
705
|
-
VAULT_FILE =
|
|
706
|
-
KEY_FILE =
|
|
823
|
+
VAULT_DIR = join7(homedir5(), ".unbrowse", "vault");
|
|
824
|
+
VAULT_FILE = join7(VAULT_DIR, "credentials.enc");
|
|
825
|
+
KEY_FILE = join7(VAULT_DIR, ".key");
|
|
707
826
|
vaultLock = Promise.resolve();
|
|
708
827
|
});
|
|
709
828
|
|
|
@@ -780,18 +899,6 @@ var init_extraction = __esm(() => {
|
|
|
780
899
|
CHROME_TAGS = new Set(["nav", "footer", "header"]);
|
|
781
900
|
});
|
|
782
901
|
|
|
783
|
-
// ../../src/graph/agent-augment.ts
|
|
784
|
-
var DEFAULT_MODEL, ENABLED, AUGMENT_TIMEOUT_MS, MAX_AUGMENT_ENDPOINTS, MAX_AUGMENT_PAYLOAD_CHARS, GENERIC_SEMANTIC_TYPES;
|
|
785
|
-
var init_agent_augment = __esm(() => {
|
|
786
|
-
init_graph();
|
|
787
|
-
DEFAULT_MODEL = process.env.UNBROWSE_AGENT_SEMANTIC_MODEL ?? process.env.UNBROWSE_AGENT_JUDGE_MODEL ?? "gpt-4.1-mini";
|
|
788
|
-
ENABLED = process.env.UNBROWSE_AGENT_SEMANTIC_AUGMENT !== "0";
|
|
789
|
-
AUGMENT_TIMEOUT_MS = Number(process.env.UNBROWSE_AGENT_SEMANTIC_TIMEOUT_MS ?? 8000);
|
|
790
|
-
MAX_AUGMENT_ENDPOINTS = Math.max(1, Number(process.env.UNBROWSE_AGENT_SEMANTIC_MAX_ENDPOINTS ?? 6));
|
|
791
|
-
MAX_AUGMENT_PAYLOAD_CHARS = Math.max(4000, Number(process.env.UNBROWSE_AGENT_SEMANTIC_MAX_PAYLOAD_CHARS ?? 24000));
|
|
792
|
-
GENERIC_SEMANTIC_TYPES = new Set(["identifier", "input", "resource", "entity", "item"]);
|
|
793
|
-
});
|
|
794
|
-
|
|
795
902
|
// ../../src/execution/search-forms.ts
|
|
796
903
|
var SEARCH_FIELD_NAMES, LOGIN_FIELD_NAMES, SUPPORTED_INPUT_TYPES;
|
|
797
904
|
var init_search_forms = __esm(() => {
|
|
@@ -854,7 +961,7 @@ var init_schema_review = __esm(() => {
|
|
|
854
961
|
});
|
|
855
962
|
|
|
856
963
|
// ../../src/indexer/index.ts
|
|
857
|
-
import { join as
|
|
964
|
+
import { join as join8 } from "node:path";
|
|
858
965
|
var SKILL_SNAPSHOT_DIR, indexInFlight, pendingIndexJobs;
|
|
859
966
|
var init_indexer = __esm(async () => {
|
|
860
967
|
init_graph();
|
|
@@ -869,7 +976,7 @@ var init_indexer = __esm(async () => {
|
|
|
869
976
|
init_graph();
|
|
870
977
|
init_schema_review();
|
|
871
978
|
await init_orchestrator();
|
|
872
|
-
SKILL_SNAPSHOT_DIR = process.env.UNBROWSE_SKILL_SNAPSHOT_DIR ??
|
|
979
|
+
SKILL_SNAPSHOT_DIR = process.env.UNBROWSE_SKILL_SNAPSHOT_DIR ?? join8(process.env.HOME ?? "/tmp", ".unbrowse", "skill-snapshots");
|
|
873
980
|
indexInFlight = new Map;
|
|
874
981
|
pendingIndexJobs = new Map;
|
|
875
982
|
});
|
|
@@ -917,7 +1024,6 @@ var init_execution = __esm(async () => {
|
|
|
917
1024
|
init_domain();
|
|
918
1025
|
init_extraction();
|
|
919
1026
|
init_graph();
|
|
920
|
-
init_agent_augment();
|
|
921
1027
|
init_logger();
|
|
922
1028
|
init_version();
|
|
923
1029
|
init_search_forms();
|
|
@@ -1046,8 +1152,8 @@ var init_routing_telemetry = __esm(() => {
|
|
|
1046
1152
|
});
|
|
1047
1153
|
// ../../src/orchestrator/index.ts
|
|
1048
1154
|
import { nanoid as nanoid9 } from "nanoid";
|
|
1049
|
-
import { existsSync as
|
|
1050
|
-
import { dirname as
|
|
1155
|
+
import { existsSync as existsSync10, writeFileSync as writeFileSync3, readFileSync as readFileSync6, mkdirSync as mkdirSync5, readdirSync as readdirSync3 } from "node:fs";
|
|
1156
|
+
import { dirname as dirname3, join as join9 } from "node:path";
|
|
1051
1157
|
var LIVE_CAPTURE_TIMEOUT_MS, capturedDomainCache, captureInFlight, captureDomainLocks, skillRouteCache, ROUTE_CACHE_FILE, SKILL_SNAPSHOT_DIR2, domainSkillCache, DOMAIN_CACHE_FILE, _routeCacheDirty = false, routeCacheFlushTimer, routeResultCache, ROUTE_CACHE_TTL, MARKETPLACE_HYDRATE_LIMIT, MARKETPLACE_GET_SKILL_TIMEOUT_MS, MARKETPLACE_DOMAIN_SEARCH_K, MARKETPLACE_GLOBAL_SEARCH_K, SEARCH_INTENT_STOPWORDS;
|
|
1052
1158
|
var init_orchestrator = __esm(async () => {
|
|
1053
1159
|
init_client();
|
|
@@ -1077,13 +1183,13 @@ var init_orchestrator = __esm(async () => {
|
|
|
1077
1183
|
captureInFlight = new Map;
|
|
1078
1184
|
captureDomainLocks = new Map;
|
|
1079
1185
|
skillRouteCache = new Map;
|
|
1080
|
-
ROUTE_CACHE_FILE =
|
|
1081
|
-
SKILL_SNAPSHOT_DIR2 = process.env.UNBROWSE_SKILL_SNAPSHOT_DIR ??
|
|
1186
|
+
ROUTE_CACHE_FILE = join9(process.env.HOME ?? "/tmp", ".unbrowse", "route-cache.json");
|
|
1187
|
+
SKILL_SNAPSHOT_DIR2 = process.env.UNBROWSE_SKILL_SNAPSHOT_DIR ?? join9(process.env.HOME ?? "/tmp", ".unbrowse", "skill-snapshots");
|
|
1082
1188
|
domainSkillCache = new Map;
|
|
1083
|
-
DOMAIN_CACHE_FILE =
|
|
1189
|
+
DOMAIN_CACHE_FILE = join9(process.env.HOME ?? "/tmp", ".unbrowse", "domain-skill-cache.json");
|
|
1084
1190
|
try {
|
|
1085
|
-
if (
|
|
1086
|
-
const data = JSON.parse(
|
|
1191
|
+
if (existsSync10(DOMAIN_CACHE_FILE)) {
|
|
1192
|
+
const data = JSON.parse(readFileSync6(DOMAIN_CACHE_FILE, "utf-8"));
|
|
1087
1193
|
for (const [k, v] of Object.entries(data)) {
|
|
1088
1194
|
const entry = v;
|
|
1089
1195
|
if (Date.now() - entry.ts < 7 * 24 * 60 * 60000) {
|
|
@@ -1098,17 +1204,17 @@ var init_orchestrator = __esm(async () => {
|
|
|
1098
1204
|
return;
|
|
1099
1205
|
_routeCacheDirty = false;
|
|
1100
1206
|
try {
|
|
1101
|
-
const dir =
|
|
1102
|
-
if (!
|
|
1103
|
-
|
|
1207
|
+
const dir = dirname3(ROUTE_CACHE_FILE);
|
|
1208
|
+
if (!existsSync10(dir))
|
|
1209
|
+
mkdirSync5(dir, { recursive: true });
|
|
1104
1210
|
const entries = Object.fromEntries(skillRouteCache);
|
|
1105
1211
|
writeFileSync3(ROUTE_CACHE_FILE, JSON.stringify(entries), "utf-8");
|
|
1106
1212
|
} catch {}
|
|
1107
1213
|
}, 5000);
|
|
1108
1214
|
routeCacheFlushTimer.unref?.();
|
|
1109
1215
|
try {
|
|
1110
|
-
if (
|
|
1111
|
-
const data = JSON.parse(
|
|
1216
|
+
if (existsSync10(ROUTE_CACHE_FILE)) {
|
|
1217
|
+
const data = JSON.parse(readFileSync6(ROUTE_CACHE_FILE, "utf-8"));
|
|
1112
1218
|
for (const [k, v] of Object.entries(data)) {
|
|
1113
1219
|
const entry = v;
|
|
1114
1220
|
if (Date.now() - entry.ts < 24 * 60 * 60000) {
|
|
@@ -1198,6 +1304,60 @@ var init_orchestrator = __esm(async () => {
|
|
|
1198
1304
|
]);
|
|
1199
1305
|
});
|
|
1200
1306
|
|
|
1307
|
+
// ../../src/payments/wallet.ts
|
|
1308
|
+
var exports_wallet = {};
|
|
1309
|
+
__export(exports_wallet, {
|
|
1310
|
+
getWalletContext: () => getWalletContext2,
|
|
1311
|
+
checkWalletConfigured: () => checkWalletConfigured2
|
|
1312
|
+
});
|
|
1313
|
+
import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
|
|
1314
|
+
import { homedir as homedir6 } from "node:os";
|
|
1315
|
+
import { join as join11 } from "node:path";
|
|
1316
|
+
function asNonEmptyString2(value) {
|
|
1317
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
1318
|
+
}
|
|
1319
|
+
function getLobsterWalletFromLocalConfig2() {
|
|
1320
|
+
const agentsPath = join11(process.env.HOME || homedir6(), ".lobster", "agents.json");
|
|
1321
|
+
if (!existsSync14(agentsPath))
|
|
1322
|
+
return;
|
|
1323
|
+
try {
|
|
1324
|
+
const raw = JSON.parse(readFileSync9(agentsPath, "utf8"));
|
|
1325
|
+
const activeAgentId = asNonEmptyString2(raw.activeAgentId);
|
|
1326
|
+
const activeAgent = Array.isArray(raw.agents) ? raw.agents.find((agent) => asNonEmptyString2(agent.id) === activeAgentId) : activeAgentId ? raw.agents?.[activeAgentId] : undefined;
|
|
1327
|
+
return asNonEmptyString2(activeAgent?.authorizedWallets?.solana) ?? asNonEmptyString2(activeAgent?.walletAddress) ?? asNonEmptyString2(activeAgent?.wallet_address);
|
|
1328
|
+
} catch {
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
function getWalletContext2() {
|
|
1333
|
+
const lobsterWallet = asNonEmptyString2(process.env.LOBSTER_WALLET_ADDRESS);
|
|
1334
|
+
if (lobsterWallet) {
|
|
1335
|
+
return { wallet_address: lobsterWallet, wallet_provider: "lobster.cash" };
|
|
1336
|
+
}
|
|
1337
|
+
const genericWallet = asNonEmptyString2(process.env.AGENT_WALLET_ADDRESS);
|
|
1338
|
+
if (genericWallet) {
|
|
1339
|
+
return {
|
|
1340
|
+
wallet_address: genericWallet,
|
|
1341
|
+
wallet_provider: asNonEmptyString2(process.env.AGENT_WALLET_PROVIDER)
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
const localLobsterWallet = getLobsterWalletFromLocalConfig2();
|
|
1345
|
+
if (localLobsterWallet) {
|
|
1346
|
+
return { wallet_address: localLobsterWallet, wallet_provider: "lobster.cash" };
|
|
1347
|
+
}
|
|
1348
|
+
return {};
|
|
1349
|
+
}
|
|
1350
|
+
function checkWalletConfigured2() {
|
|
1351
|
+
const wallet = getWalletContext2();
|
|
1352
|
+
if (!wallet.wallet_address)
|
|
1353
|
+
return { configured: false };
|
|
1354
|
+
return {
|
|
1355
|
+
configured: true,
|
|
1356
|
+
provider: wallet.wallet_provider ?? "unknown"
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
var init_wallet2 = () => {};
|
|
1360
|
+
|
|
1201
1361
|
// ../../src/cli.ts
|
|
1202
1362
|
import { config as loadEnv } from "dotenv";
|
|
1203
1363
|
import { spawn as spawn3 } from "child_process";
|
|
@@ -1207,9 +1367,9 @@ init_version();
|
|
|
1207
1367
|
init_cascade();
|
|
1208
1368
|
init_wallet();
|
|
1209
1369
|
init_telemetry_attribution();
|
|
1210
|
-
import { readFileSync as readFileSync3, writeFileSync, existsSync as
|
|
1211
|
-
import { join as
|
|
1212
|
-
import { homedir as
|
|
1370
|
+
import { readFileSync as readFileSync3, writeFileSync, existsSync as existsSync4, mkdirSync, readdirSync as readdirSync2 } from "fs";
|
|
1371
|
+
import { join as join4 } from "path";
|
|
1372
|
+
import { homedir as homedir3, hostname, release as osRelease } from "os";
|
|
1213
1373
|
import { randomBytes, createHash as createHash2 } from "crypto";
|
|
1214
1374
|
import { createInterface } from "readline";
|
|
1215
1375
|
var API_URL = process.env.UNBROWSE_BACKEND_URL || DEFAULT_BACKEND_URL;
|
|
@@ -1244,13 +1404,13 @@ function decodeBase64Json(value) {
|
|
|
1244
1404
|
function getConfigDir() {
|
|
1245
1405
|
if (process.env.UNBROWSE_CONFIG_DIR)
|
|
1246
1406
|
return process.env.UNBROWSE_CONFIG_DIR;
|
|
1247
|
-
return PROFILE_NAME ?
|
|
1407
|
+
return PROFILE_NAME ? join4(homedir3(), ".unbrowse", "profiles", PROFILE_NAME) : join4(homedir3(), ".unbrowse");
|
|
1248
1408
|
}
|
|
1249
1409
|
function getConfigPath() {
|
|
1250
|
-
return
|
|
1410
|
+
return join4(getConfigDir(), "config.json");
|
|
1251
1411
|
}
|
|
1252
1412
|
function getInstallTelemetryPath() {
|
|
1253
|
-
return
|
|
1413
|
+
return join4(getConfigDir(), "install-state.json");
|
|
1254
1414
|
}
|
|
1255
1415
|
function getLandingToken() {
|
|
1256
1416
|
const token = process.env.UNBROWSE_LANDING_TOKEN?.trim();
|
|
@@ -1265,7 +1425,7 @@ function getActiveProfile() {
|
|
|
1265
1425
|
function loadConfig() {
|
|
1266
1426
|
try {
|
|
1267
1427
|
const configPath = getConfigPath();
|
|
1268
|
-
if (
|
|
1428
|
+
if (existsSync4(configPath)) {
|
|
1269
1429
|
return JSON.parse(readFileSync3(configPath, "utf-8"));
|
|
1270
1430
|
}
|
|
1271
1431
|
} catch {}
|
|
@@ -1274,14 +1434,14 @@ function loadConfig() {
|
|
|
1274
1434
|
function saveConfig(config) {
|
|
1275
1435
|
const configDir = getConfigDir();
|
|
1276
1436
|
const configPath = getConfigPath();
|
|
1277
|
-
if (!
|
|
1437
|
+
if (!existsSync4(configDir))
|
|
1278
1438
|
mkdirSync(configDir, { recursive: true });
|
|
1279
1439
|
writeFileSync(configPath, JSON.stringify(config, null, 2), { mode: 384 });
|
|
1280
1440
|
}
|
|
1281
1441
|
function loadInstallTelemetryState() {
|
|
1282
1442
|
try {
|
|
1283
1443
|
const statePath = getInstallTelemetryPath();
|
|
1284
|
-
if (
|
|
1444
|
+
if (existsSync4(statePath)) {
|
|
1285
1445
|
return JSON.parse(readFileSync3(statePath, "utf-8"));
|
|
1286
1446
|
}
|
|
1287
1447
|
} catch {}
|
|
@@ -1290,7 +1450,7 @@ function loadInstallTelemetryState() {
|
|
|
1290
1450
|
function saveInstallTelemetryState(state) {
|
|
1291
1451
|
const configDir = getConfigDir();
|
|
1292
1452
|
const statePath = getInstallTelemetryPath();
|
|
1293
|
-
if (!
|
|
1453
|
+
if (!existsSync4(configDir))
|
|
1294
1454
|
mkdirSync(configDir, { recursive: true });
|
|
1295
1455
|
writeFileSync(statePath, JSON.stringify(state, null, 2), { mode: 384 });
|
|
1296
1456
|
}
|
|
@@ -1402,9 +1562,19 @@ async function recordInstallTelemetryEvent(source, options) {
|
|
|
1402
1562
|
skill_version: options?.skillVersion,
|
|
1403
1563
|
status: options?.status ?? "installed",
|
|
1404
1564
|
created_at: createdAt,
|
|
1405
|
-
properties: mergeTelemetryProperties(options?.properties, getTelemetryAttribution())
|
|
1565
|
+
properties: mergeTelemetryProperties({ ...getRuntimeContext(), ...options?.properties }, getTelemetryAttribution())
|
|
1406
1566
|
});
|
|
1407
1567
|
}
|
|
1568
|
+
function getRuntimeContext() {
|
|
1569
|
+
return {
|
|
1570
|
+
cli_version: PACKAGE_VERSION,
|
|
1571
|
+
code_hash: CODE_HASH,
|
|
1572
|
+
node_version: process.version,
|
|
1573
|
+
platform: process.platform,
|
|
1574
|
+
arch: process.arch,
|
|
1575
|
+
os_release: osRelease()
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1408
1578
|
async function recordFunnelTelemetryEvent(name, options) {
|
|
1409
1579
|
const createdAt = options?.createdAt ?? new Date().toISOString();
|
|
1410
1580
|
const landingToken = getLandingToken();
|
|
@@ -1416,7 +1586,7 @@ async function recordFunnelTelemetryEvent(name, options) {
|
|
|
1416
1586
|
source: options?.source ?? "cli",
|
|
1417
1587
|
host_type: options?.hostType ?? detectTelemetryHostType(),
|
|
1418
1588
|
created_at: createdAt,
|
|
1419
|
-
properties: mergeTelemetryProperties(options?.properties, getTelemetryAttribution())
|
|
1589
|
+
properties: mergeTelemetryProperties({ ...getRuntimeContext(), ...options?.properties }, getTelemetryAttribution())
|
|
1420
1590
|
});
|
|
1421
1591
|
}
|
|
1422
1592
|
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/i;
|
|
@@ -1448,6 +1618,10 @@ function getApiKey() {
|
|
|
1448
1618
|
}
|
|
1449
1619
|
return "";
|
|
1450
1620
|
}
|
|
1621
|
+
function getAgentId() {
|
|
1622
|
+
const config = loadConfig();
|
|
1623
|
+
return config?.agent_id ?? null;
|
|
1624
|
+
}
|
|
1451
1625
|
var API_TIMEOUT_MS = parseInt(process.env.UNBROWSE_API_TIMEOUT ?? "8000", 10);
|
|
1452
1626
|
var PUBLISH_TIMEOUT_MS = parseInt(process.env.UNBROWSE_PUBLISH_TIMEOUT ?? "30000", 10);
|
|
1453
1627
|
async function validateApiKey(key) {
|
|
@@ -1547,6 +1721,26 @@ async function apiRequest(method, path, body, opts) {
|
|
|
1547
1721
|
const paymentRequired = res.headers.get("PAYMENT-REQUIRED");
|
|
1548
1722
|
const legacyPaymentTerms = res.headers.get("X-Payment-Required");
|
|
1549
1723
|
const terms = paymentRequired ? decodeBase64Json(paymentRequired) : legacyPaymentTerms ? JSON.parse(legacyPaymentTerms) : data.terms;
|
|
1724
|
+
try {
|
|
1725
|
+
const { isLobsterAvailable: isLobsterAvailable2, payAndRetry: payAndRetry2 } = await Promise.resolve().then(() => (init_lobster_pay(), exports_lobster_pay));
|
|
1726
|
+
if (isLobsterAvailable2()) {
|
|
1727
|
+
const fullUrl = `${API_URL}${path}`;
|
|
1728
|
+
const paidResult = await payAndRetry2(fullUrl, {
|
|
1729
|
+
body,
|
|
1730
|
+
headers: {
|
|
1731
|
+
"Content-Type": "application/json",
|
|
1732
|
+
"Accept-Encoding": "gzip, deflate",
|
|
1733
|
+
...releaseAttestationHeaders,
|
|
1734
|
+
...key ? { Authorization: `Bearer ${key}` } : {}
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
if (paidResult) {
|
|
1738
|
+
return { data: paidResult.data, headers: new Headers };
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
} catch (payErr) {
|
|
1742
|
+
console.warn(`[x402] lobster pay-and-retry failed: ${payErr.message}`);
|
|
1743
|
+
}
|
|
1550
1744
|
const err = new Error(`Payment required: ${data.error ?? "This skill requires payment"}`);
|
|
1551
1745
|
err.x402 = true;
|
|
1552
1746
|
err.terms = terms;
|
|
@@ -1739,6 +1933,170 @@ async function syncAgentWallet(wallet = getLocalWalletContext()) {
|
|
|
1739
1933
|
return;
|
|
1740
1934
|
saveConfig({ ...config, ...wallet });
|
|
1741
1935
|
}
|
|
1936
|
+
async function getTransactionHistory(agentId) {
|
|
1937
|
+
return api("GET", `/v1/transactions/consumer/${agentId}`);
|
|
1938
|
+
}
|
|
1939
|
+
async function getCreatorEarnings(agentId) {
|
|
1940
|
+
return api("GET", `/v1/transactions/creator/${agentId}`);
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
// ../../src/impact-log.ts
|
|
1944
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync2, appendFileSync, statSync, readFileSync as readFileSync4, renameSync, unlinkSync } from "node:fs";
|
|
1945
|
+
import { homedir as homedir4 } from "node:os";
|
|
1946
|
+
import { dirname as dirname2, join as join5 } from "node:path";
|
|
1947
|
+
var MAX_LOG_BYTES = 5 * 1024 * 1024;
|
|
1948
|
+
var MAX_ROTATIONS = 3;
|
|
1949
|
+
function getLogDir() {
|
|
1950
|
+
if (process.env.UNBROWSE_CONFIG_DIR)
|
|
1951
|
+
return process.env.UNBROWSE_CONFIG_DIR;
|
|
1952
|
+
const profile = process.env.UNBROWSE_PROFILE?.trim();
|
|
1953
|
+
return profile ? join5(homedir4(), ".unbrowse", "profiles", profile) : join5(homedir4(), ".unbrowse");
|
|
1954
|
+
}
|
|
1955
|
+
function getImpactLogPath() {
|
|
1956
|
+
return join5(getLogDir(), "impact-log.jsonl");
|
|
1957
|
+
}
|
|
1958
|
+
function ensureDir(path) {
|
|
1959
|
+
const dir = dirname2(path);
|
|
1960
|
+
if (!existsSync5(dir))
|
|
1961
|
+
mkdirSync2(dir, { recursive: true });
|
|
1962
|
+
}
|
|
1963
|
+
function rotateIfNeeded(path) {
|
|
1964
|
+
try {
|
|
1965
|
+
if (!existsSync5(path))
|
|
1966
|
+
return;
|
|
1967
|
+
const size = statSync(path).size;
|
|
1968
|
+
if (size < MAX_LOG_BYTES)
|
|
1969
|
+
return;
|
|
1970
|
+
for (let i = MAX_ROTATIONS;i >= 1; i--) {
|
|
1971
|
+
const older = `${path}.${i}`;
|
|
1972
|
+
if (!existsSync5(older))
|
|
1973
|
+
continue;
|
|
1974
|
+
if (i === MAX_ROTATIONS) {
|
|
1975
|
+
try {
|
|
1976
|
+
unlinkSync(older);
|
|
1977
|
+
} catch {}
|
|
1978
|
+
} else {
|
|
1979
|
+
try {
|
|
1980
|
+
renameSync(older, `${path}.${i + 1}`);
|
|
1981
|
+
} catch {}
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
renameSync(path, `${path}.1`);
|
|
1985
|
+
} catch {}
|
|
1986
|
+
}
|
|
1987
|
+
function appendImpact(entry) {
|
|
1988
|
+
try {
|
|
1989
|
+
const hasSignal = (entry.time_saved_ms ?? 0) > 0 || (entry.tokens_saved ?? 0) > 0 || (entry.cost_saved_uc ?? 0) > 0 || entry.browser_avoided === true;
|
|
1990
|
+
if (!hasSignal)
|
|
1991
|
+
return;
|
|
1992
|
+
const path = getImpactLogPath();
|
|
1993
|
+
ensureDir(path);
|
|
1994
|
+
rotateIfNeeded(path);
|
|
1995
|
+
appendFileSync(path, JSON.stringify(entry) + `
|
|
1996
|
+
`, "utf8");
|
|
1997
|
+
} catch {}
|
|
1998
|
+
}
|
|
1999
|
+
function impactFromResult(command, result, extras = {}) {
|
|
2000
|
+
if (!result || typeof result !== "object")
|
|
2001
|
+
return null;
|
|
2002
|
+
const r = result;
|
|
2003
|
+
const impact = r.impact ?? null;
|
|
2004
|
+
if (!impact || typeof impact !== "object")
|
|
2005
|
+
return null;
|
|
2006
|
+
const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : undefined;
|
|
2007
|
+
return {
|
|
2008
|
+
ts: new Date().toISOString(),
|
|
2009
|
+
command,
|
|
2010
|
+
source: typeof impact.source === "string" ? impact.source : undefined,
|
|
2011
|
+
domain: extras.domain,
|
|
2012
|
+
intent: extras.intent,
|
|
2013
|
+
skill_id: extras.skill_id ?? (typeof r.skill_id === "string" ? r.skill_id : undefined),
|
|
2014
|
+
endpoint_id: extras.endpoint_id ?? (typeof r.endpoint_id === "string" ? r.endpoint_id : undefined),
|
|
2015
|
+
time_saved_ms: num(impact.time_saved_ms),
|
|
2016
|
+
time_saved_pct: num(impact.time_saved_pct),
|
|
2017
|
+
tokens_saved: num(impact.tokens_saved),
|
|
2018
|
+
tokens_saved_pct: num(impact.tokens_saved_pct),
|
|
2019
|
+
cost_saved_uc: num(impact.cost_saved_uc),
|
|
2020
|
+
browser_avoided: impact.browser_avoided === true,
|
|
2021
|
+
success: r.error == null
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
2024
|
+
function readImpactSummary() {
|
|
2025
|
+
const path = getImpactLogPath();
|
|
2026
|
+
const summary = {
|
|
2027
|
+
total_runs: 0,
|
|
2028
|
+
successful_runs: 0,
|
|
2029
|
+
browser_avoided_runs: 0,
|
|
2030
|
+
total_time_saved_ms: 0,
|
|
2031
|
+
total_tokens_saved: 0,
|
|
2032
|
+
total_cost_saved_uc: 0,
|
|
2033
|
+
avg_time_saved_pct: 0,
|
|
2034
|
+
avg_tokens_saved_pct: 0,
|
|
2035
|
+
by_source: {},
|
|
2036
|
+
first_entry_at: null,
|
|
2037
|
+
last_entry_at: null
|
|
2038
|
+
};
|
|
2039
|
+
const files = [];
|
|
2040
|
+
for (let i = MAX_ROTATIONS;i >= 1; i--) {
|
|
2041
|
+
const rotated = `${path}.${i}`;
|
|
2042
|
+
if (existsSync5(rotated))
|
|
2043
|
+
files.push(rotated);
|
|
2044
|
+
}
|
|
2045
|
+
if (existsSync5(path))
|
|
2046
|
+
files.push(path);
|
|
2047
|
+
if (files.length === 0)
|
|
2048
|
+
return summary;
|
|
2049
|
+
let timePctSum = 0;
|
|
2050
|
+
let timePctCount = 0;
|
|
2051
|
+
let tokenPctSum = 0;
|
|
2052
|
+
let tokenPctCount = 0;
|
|
2053
|
+
for (const file of files) {
|
|
2054
|
+
let raw;
|
|
2055
|
+
try {
|
|
2056
|
+
raw = readFileSync4(file, "utf8");
|
|
2057
|
+
} catch {
|
|
2058
|
+
continue;
|
|
2059
|
+
}
|
|
2060
|
+
for (const line of raw.split(`
|
|
2061
|
+
`)) {
|
|
2062
|
+
const trimmed = line.trim();
|
|
2063
|
+
if (!trimmed)
|
|
2064
|
+
continue;
|
|
2065
|
+
let e;
|
|
2066
|
+
try {
|
|
2067
|
+
e = JSON.parse(trimmed);
|
|
2068
|
+
} catch {
|
|
2069
|
+
continue;
|
|
2070
|
+
}
|
|
2071
|
+
summary.total_runs += 1;
|
|
2072
|
+
if (e.success !== false)
|
|
2073
|
+
summary.successful_runs += 1;
|
|
2074
|
+
if (e.browser_avoided)
|
|
2075
|
+
summary.browser_avoided_runs += 1;
|
|
2076
|
+
summary.total_time_saved_ms += e.time_saved_ms ?? 0;
|
|
2077
|
+
summary.total_tokens_saved += e.tokens_saved ?? 0;
|
|
2078
|
+
summary.total_cost_saved_uc += e.cost_saved_uc ?? 0;
|
|
2079
|
+
if (typeof e.time_saved_pct === "number") {
|
|
2080
|
+
timePctSum += e.time_saved_pct;
|
|
2081
|
+
timePctCount += 1;
|
|
2082
|
+
}
|
|
2083
|
+
if (typeof e.tokens_saved_pct === "number") {
|
|
2084
|
+
tokenPctSum += e.tokens_saved_pct;
|
|
2085
|
+
tokenPctCount += 1;
|
|
2086
|
+
}
|
|
2087
|
+
if (e.source) {
|
|
2088
|
+
summary.by_source[e.source] = (summary.by_source[e.source] ?? 0) + 1;
|
|
2089
|
+
}
|
|
2090
|
+
if (!summary.first_entry_at || e.ts < summary.first_entry_at)
|
|
2091
|
+
summary.first_entry_at = e.ts;
|
|
2092
|
+
if (!summary.last_entry_at || e.ts > summary.last_entry_at)
|
|
2093
|
+
summary.last_entry_at = e.ts;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
summary.avg_time_saved_pct = timePctCount > 0 ? Math.round(timePctSum / timePctCount) : 0;
|
|
2097
|
+
summary.avg_tokens_saved_pct = tokenPctCount > 0 ? Math.round(tokenPctSum / tokenPctCount) : 0;
|
|
2098
|
+
return summary;
|
|
2099
|
+
}
|
|
1742
2100
|
|
|
1743
2101
|
// ../../src/cli/shortcuts.ts
|
|
1744
2102
|
var linkedin = {
|
|
@@ -1939,7 +2297,7 @@ function buildDepsMetadata(pack, taskName) {
|
|
|
1939
2297
|
init_paths();
|
|
1940
2298
|
init_supervisor();
|
|
1941
2299
|
init_version();
|
|
1942
|
-
import { openSync, readFileSync as
|
|
2300
|
+
import { existsSync as existsSync7, openSync, readFileSync as readFileSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
1943
2301
|
import path2 from "node:path";
|
|
1944
2302
|
import { spawn } from "node:child_process";
|
|
1945
2303
|
function isServerVersionMismatch(runningVersion, installedVersion, runningCodeHash, installedCodeHash) {
|
|
@@ -1977,14 +2335,14 @@ function isPidAlive(pid) {
|
|
|
1977
2335
|
}
|
|
1978
2336
|
function readPidState(pidFile) {
|
|
1979
2337
|
try {
|
|
1980
|
-
return JSON.parse(
|
|
2338
|
+
return JSON.parse(readFileSync5(pidFile, "utf-8"));
|
|
1981
2339
|
} catch {
|
|
1982
2340
|
return null;
|
|
1983
2341
|
}
|
|
1984
2342
|
}
|
|
1985
2343
|
function clearStalePidFile(pidFile) {
|
|
1986
2344
|
try {
|
|
1987
|
-
|
|
2345
|
+
unlinkSync2(pidFile);
|
|
1988
2346
|
} catch {}
|
|
1989
2347
|
}
|
|
1990
2348
|
function deriveListenEnv(baseUrl) {
|
|
@@ -2005,6 +2363,10 @@ function getServerSpawnSpec(metaUrl, entrypoint = resolveSiblingEntrypoint(metaU
|
|
|
2005
2363
|
recordedEntrypoint: `${process.execPath} serve`
|
|
2006
2364
|
};
|
|
2007
2365
|
}
|
|
2366
|
+
const serverJs = path2.join(path2.dirname(entrypoint), "server.js");
|
|
2367
|
+
if (existsSync7(serverJs) && path2.basename(entrypoint) !== "server.js") {
|
|
2368
|
+
entrypoint = serverJs;
|
|
2369
|
+
}
|
|
2008
2370
|
return {
|
|
2009
2371
|
command: process.execPath,
|
|
2010
2372
|
args: runtimeArgsForEntrypoint(metaUrl, entrypoint),
|
|
@@ -2018,7 +2380,7 @@ function spawnServer(baseUrl, metaUrl, pidFile, restartCount = 0) {
|
|
|
2018
2380
|
const entrypoint = resolveSiblingEntrypoint(metaUrl, "index");
|
|
2019
2381
|
const spawnSpec = getServerSpawnSpec(metaUrl, entrypoint);
|
|
2020
2382
|
const logFile = getServerAutostartLogFile();
|
|
2021
|
-
|
|
2383
|
+
ensureDir2(path2.dirname(logFile));
|
|
2022
2384
|
const logFd = openSync(logFile, "a");
|
|
2023
2385
|
const child = spawn(spawnSpec.command, spawnSpec.args, {
|
|
2024
2386
|
cwd: spawnSpec.cwd,
|
|
@@ -2150,7 +2512,7 @@ async function restartServer(baseUrl, metaUrl) {
|
|
|
2150
2512
|
}
|
|
2151
2513
|
|
|
2152
2514
|
// ../../src/runtime/paths.ts
|
|
2153
|
-
import { existsSync as
|
|
2515
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync4, realpathSync as realpathSync2 } from "node:fs";
|
|
2154
2516
|
import path3 from "node:path";
|
|
2155
2517
|
import { createRequire as createRequire3 } from "node:module";
|
|
2156
2518
|
import { fileURLToPath as fileURLToPath3, pathToFileURL as pathToFileURL2 } from "node:url";
|
|
@@ -2170,7 +2532,7 @@ function runtimeArgsForEntrypoint2(metaUrl, entrypoint) {
|
|
|
2170
2532
|
const req = createRequire3(metaUrl);
|
|
2171
2533
|
const tsxPkg = req.resolve("tsx/package.json");
|
|
2172
2534
|
const tsxLoader = path3.join(path3.dirname(tsxPkg), "dist", "loader.mjs");
|
|
2173
|
-
if (
|
|
2535
|
+
if (existsSync8(tsxLoader))
|
|
2174
2536
|
return ["--import", pathToFileURL2(tsxLoader).href, entrypoint];
|
|
2175
2537
|
} catch {}
|
|
2176
2538
|
return ["--import", "tsx", entrypoint];
|
|
@@ -2200,8 +2562,8 @@ init_publish();
|
|
|
2200
2562
|
init_settings();
|
|
2201
2563
|
init_graph();
|
|
2202
2564
|
init_schema_review();
|
|
2203
|
-
import { join as
|
|
2204
|
-
var SKILL_SNAPSHOT_DIR3 = process.env.UNBROWSE_SKILL_SNAPSHOT_DIR ??
|
|
2565
|
+
import { join as join10 } from "node:path";
|
|
2566
|
+
var SKILL_SNAPSHOT_DIR3 = process.env.UNBROWSE_SKILL_SNAPSHOT_DIR ?? join10(process.env.HOME ?? "/tmp", ".unbrowse", "skill-snapshots");
|
|
2205
2567
|
var indexInFlight2 = new Map;
|
|
2206
2568
|
var pendingIndexJobs2 = new Map;
|
|
2207
2569
|
async function drainPendingIndexJobs() {
|
|
@@ -2238,14 +2600,14 @@ init_paths();
|
|
|
2238
2600
|
init_client2();
|
|
2239
2601
|
init_logger();
|
|
2240
2602
|
init_wallet();
|
|
2241
|
-
import { execFileSync as
|
|
2242
|
-
import { existsSync as
|
|
2603
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
2604
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
2243
2605
|
import os4 from "node:os";
|
|
2244
2606
|
import path7 from "node:path";
|
|
2245
2607
|
|
|
2246
2608
|
// ../../src/runtime/update-hints.ts
|
|
2247
2609
|
init_paths();
|
|
2248
|
-
import { existsSync as
|
|
2610
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync6, readFileSync as readFileSync7, writeFileSync as writeFileSync4 } from "node:fs";
|
|
2249
2611
|
import os3 from "node:os";
|
|
2250
2612
|
import path6 from "node:path";
|
|
2251
2613
|
var DEFAULT_INTERVAL_MS = 12 * 60 * 60 * 1000;
|
|
@@ -2258,20 +2620,20 @@ function getConfigDir2() {
|
|
|
2258
2620
|
return process.env.UNBROWSE_CONFIG_DIR;
|
|
2259
2621
|
return path6.join(getHomeDir(), ".unbrowse");
|
|
2260
2622
|
}
|
|
2261
|
-
function
|
|
2262
|
-
if (!
|
|
2263
|
-
|
|
2623
|
+
function ensureDir3(dir) {
|
|
2624
|
+
if (!existsSync11(dir))
|
|
2625
|
+
mkdirSync6(dir, { recursive: true });
|
|
2264
2626
|
return dir;
|
|
2265
2627
|
}
|
|
2266
2628
|
function readJsonFile(file) {
|
|
2267
2629
|
try {
|
|
2268
|
-
return JSON.parse(
|
|
2630
|
+
return JSON.parse(readFileSync7(file, "utf8"));
|
|
2269
2631
|
} catch {
|
|
2270
2632
|
return null;
|
|
2271
2633
|
}
|
|
2272
2634
|
}
|
|
2273
2635
|
function writeJsonFile(file, value) {
|
|
2274
|
-
|
|
2636
|
+
ensureDir3(path6.dirname(file));
|
|
2275
2637
|
writeFileSync4(file, `${JSON.stringify(value, null, 2)}
|
|
2276
2638
|
`);
|
|
2277
2639
|
}
|
|
@@ -2282,7 +2644,7 @@ function detectRepoRoot(start2) {
|
|
|
2282
2644
|
let dir = path6.resolve(start2);
|
|
2283
2645
|
const root = path6.parse(dir).root;
|
|
2284
2646
|
while (dir !== root) {
|
|
2285
|
-
if (
|
|
2647
|
+
if (existsSync11(path6.join(dir, ".git")))
|
|
2286
2648
|
return dir;
|
|
2287
2649
|
dir = path6.dirname(dir);
|
|
2288
2650
|
}
|
|
@@ -2361,13 +2723,13 @@ codex_hooks = true
|
|
|
2361
2723
|
}
|
|
2362
2724
|
function writeCodexHook(metaUrl) {
|
|
2363
2725
|
const configPath = getCodexConfigPath();
|
|
2364
|
-
if (!
|
|
2726
|
+
if (!existsSync11(path6.dirname(configPath))) {
|
|
2365
2727
|
return { host: "codex", action: "not-detected", config_file: configPath };
|
|
2366
2728
|
}
|
|
2367
2729
|
try {
|
|
2368
2730
|
const hookScript = getHookScriptPath(metaUrl).replace(/\\/g, "/");
|
|
2369
|
-
const fileExistsBefore =
|
|
2370
|
-
let content = fileExistsBefore ?
|
|
2731
|
+
const fileExistsBefore = existsSync11(configPath);
|
|
2732
|
+
let content = fileExistsBefore ? readFileSync7(configPath, "utf8") : "";
|
|
2371
2733
|
const previous = content;
|
|
2372
2734
|
content = ensureCodexHooksFeature(content);
|
|
2373
2735
|
if (!content.includes("unbrowse-update-hint.mjs")) {
|
|
@@ -2401,13 +2763,13 @@ command = ${JSON.stringify(command)}
|
|
|
2401
2763
|
}
|
|
2402
2764
|
function writeClaudeHook(metaUrl) {
|
|
2403
2765
|
const settingsPath = getClaudeSettingsPath();
|
|
2404
|
-
if (!
|
|
2766
|
+
if (!existsSync11(path6.dirname(settingsPath))) {
|
|
2405
2767
|
return { host: "claude", action: "not-detected", config_file: settingsPath };
|
|
2406
2768
|
}
|
|
2407
2769
|
try {
|
|
2408
2770
|
const hookScript = getHookScriptPath(metaUrl).replace(/\\/g, "/");
|
|
2409
2771
|
const command = `node "${hookScript}"`;
|
|
2410
|
-
const fileExistsBefore =
|
|
2772
|
+
const fileExistsBefore = existsSync11(settingsPath);
|
|
2411
2773
|
const settings = readJsonFile(settingsPath) ?? {};
|
|
2412
2774
|
settings.hooks ??= {};
|
|
2413
2775
|
settings.hooks.SessionStart ??= [];
|
|
@@ -2445,7 +2807,7 @@ function configureUpdateHintHooks(metaUrl, install) {
|
|
|
2445
2807
|
function hasBinary(name) {
|
|
2446
2808
|
const checker = process.platform === "win32" ? "where" : "which";
|
|
2447
2809
|
try {
|
|
2448
|
-
|
|
2810
|
+
execFileSync3(checker, [name], { stdio: "ignore" });
|
|
2449
2811
|
return true;
|
|
2450
2812
|
} catch {
|
|
2451
2813
|
return false;
|
|
@@ -2472,7 +2834,7 @@ function getOpenCodeProjectCommandsDir(cwd) {
|
|
|
2472
2834
|
return path7.join(cwd, ".opencode", "commands");
|
|
2473
2835
|
}
|
|
2474
2836
|
function detectOpenCode(cwd) {
|
|
2475
|
-
return hasBinary("opencode") ||
|
|
2837
|
+
return hasBinary("opencode") || existsSync12(path7.join(resolveConfigHome(), "opencode")) || existsSync12(path7.join(cwd, ".opencode"));
|
|
2476
2838
|
}
|
|
2477
2839
|
function renderOpenCodeCommand() {
|
|
2478
2840
|
return `---
|
|
@@ -2500,12 +2862,12 @@ function writeOpenCodeCommand(scope, cwd) {
|
|
|
2500
2862
|
if (scope === "auto" && !detected) {
|
|
2501
2863
|
return { detected: false, action: "not-detected", scope: "off" };
|
|
2502
2864
|
}
|
|
2503
|
-
const resolvedScope = scope === "project" ? "project" : scope === "global" ? "global" :
|
|
2865
|
+
const resolvedScope = scope === "project" ? "project" : scope === "global" ? "global" : existsSync12(path7.join(cwd, ".opencode")) ? "project" : "global";
|
|
2504
2866
|
const commandsDir = resolvedScope === "project" ? getOpenCodeProjectCommandsDir(cwd) : getOpenCodeGlobalCommandsDir();
|
|
2505
|
-
const commandFile = path7.join(
|
|
2867
|
+
const commandFile = path7.join(ensureDir2(commandsDir), "unbrowse.md");
|
|
2506
2868
|
const content = renderOpenCodeCommand();
|
|
2507
|
-
const action2 =
|
|
2508
|
-
|
|
2869
|
+
const action2 = existsSync12(commandFile) ? "updated" : "installed";
|
|
2870
|
+
mkdirSync7(path7.dirname(commandFile), { recursive: true });
|
|
2509
2871
|
writeFileSync5(commandFile, content);
|
|
2510
2872
|
return {
|
|
2511
2873
|
detected: detected || scope !== "auto",
|
|
@@ -2516,10 +2878,10 @@ function writeOpenCodeCommand(scope, cwd) {
|
|
|
2516
2878
|
}
|
|
2517
2879
|
async function ensureBrowserEngineInstalled() {
|
|
2518
2880
|
const binary = findKuriBinary();
|
|
2519
|
-
if (
|
|
2881
|
+
if (existsSync12(binary)) {
|
|
2520
2882
|
return { installed: true, action: "already-installed" };
|
|
2521
2883
|
}
|
|
2522
|
-
const sourceDir = getKuriSourceCandidates().find((candidate) =>
|
|
2884
|
+
const sourceDir = getKuriSourceCandidates().find((candidate) => existsSync12(path7.join(candidate, "build.zig")));
|
|
2523
2885
|
if (!sourceDir) {
|
|
2524
2886
|
return {
|
|
2525
2887
|
installed: false,
|
|
@@ -2535,13 +2897,13 @@ async function ensureBrowserEngineInstalled() {
|
|
|
2535
2897
|
};
|
|
2536
2898
|
}
|
|
2537
2899
|
try {
|
|
2538
|
-
|
|
2900
|
+
execFileSync3("zig", ["build", "-Doptimize=ReleaseFast"], {
|
|
2539
2901
|
cwd: sourceDir,
|
|
2540
2902
|
stdio: "inherit",
|
|
2541
2903
|
timeout: 300000
|
|
2542
2904
|
});
|
|
2543
2905
|
const builtBinary = findKuriBinary();
|
|
2544
|
-
if (
|
|
2906
|
+
if (existsSync12(builtBinary)) {
|
|
2545
2907
|
return {
|
|
2546
2908
|
installed: true,
|
|
2547
2909
|
action: "installed",
|
|
@@ -2566,11 +2928,11 @@ async function runSetup(options) {
|
|
|
2566
2928
|
const browser = options?.installBrowser === false ? { installed: false, action: "skipped" } : await ensureBrowserEngineInstalled();
|
|
2567
2929
|
const walletCheck = checkWalletConfigured();
|
|
2568
2930
|
const skipWalletSetup = process.env.UNBROWSE_SKIP_WALLET_SETUP === "1";
|
|
2569
|
-
const lobsterInstalled = hasBinary("lobstercash") ||
|
|
2931
|
+
const lobsterInstalled = hasBinary("lobstercash") || existsSync12(path7.join(os4.homedir(), ".agents", "skills", "lobstercash", "SKILL.md"));
|
|
2570
2932
|
if (!skipWalletSetup && !walletCheck.configured && lobsterInstalled) {
|
|
2571
2933
|
console.log("[unbrowse] Crossmint lobster.cash detected but wallet not configured — running wallet setup...");
|
|
2572
2934
|
try {
|
|
2573
|
-
|
|
2935
|
+
execFileSync3("npx", ["@crossmint/lobster-cli", "setup"], {
|
|
2574
2936
|
stdio: "inherit",
|
|
2575
2937
|
timeout: 60000
|
|
2576
2938
|
});
|
|
@@ -2606,7 +2968,7 @@ async function runSetup(options) {
|
|
|
2606
2968
|
|
|
2607
2969
|
// ../../src/runtime/update-hints.ts
|
|
2608
2970
|
init_paths();
|
|
2609
|
-
import { existsSync as
|
|
2971
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync8, readFileSync as readFileSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
2610
2972
|
import os5 from "node:os";
|
|
2611
2973
|
import path8 from "node:path";
|
|
2612
2974
|
var INSTALL_SCRIPT_URL = "https://unbrowse.ai/install.sh";
|
|
@@ -2619,20 +2981,20 @@ function getConfigDir3() {
|
|
|
2619
2981
|
return process.env.UNBROWSE_CONFIG_DIR;
|
|
2620
2982
|
return path8.join(getHomeDir2(), ".unbrowse");
|
|
2621
2983
|
}
|
|
2622
|
-
function
|
|
2623
|
-
if (!
|
|
2624
|
-
|
|
2984
|
+
function ensureDir4(dir) {
|
|
2985
|
+
if (!existsSync13(dir))
|
|
2986
|
+
mkdirSync8(dir, { recursive: true });
|
|
2625
2987
|
return dir;
|
|
2626
2988
|
}
|
|
2627
2989
|
function readJsonFile2(file) {
|
|
2628
2990
|
try {
|
|
2629
|
-
return JSON.parse(
|
|
2991
|
+
return JSON.parse(readFileSync8(file, "utf8"));
|
|
2630
2992
|
} catch {
|
|
2631
2993
|
return null;
|
|
2632
2994
|
}
|
|
2633
2995
|
}
|
|
2634
2996
|
function writeJsonFile2(file, value) {
|
|
2635
|
-
|
|
2997
|
+
ensureDir4(path8.dirname(file));
|
|
2636
2998
|
writeFileSync6(file, `${JSON.stringify(value, null, 2)}
|
|
2637
2999
|
`);
|
|
2638
3000
|
}
|
|
@@ -2646,7 +3008,7 @@ function detectRepoRoot2(start2) {
|
|
|
2646
3008
|
let dir = path8.resolve(start2);
|
|
2647
3009
|
const root = path8.parse(dir).root;
|
|
2648
3010
|
while (dir !== root) {
|
|
2649
|
-
if (
|
|
3011
|
+
if (existsSync13(path8.join(dir, ".git")))
|
|
2650
3012
|
return dir;
|
|
2651
3013
|
dir = path8.dirname(dir);
|
|
2652
3014
|
}
|
|
@@ -2679,7 +3041,7 @@ function detectInstallHost2(repoRoot) {
|
|
|
2679
3041
|
function getInstalledVersion(metaUrl) {
|
|
2680
3042
|
const packageRoot = getPackageRoot(metaUrl);
|
|
2681
3043
|
try {
|
|
2682
|
-
const pkg = JSON.parse(
|
|
3044
|
+
const pkg = JSON.parse(readFileSync8(path8.join(packageRoot, "package.json"), "utf8"));
|
|
2683
3045
|
return pkg.version ?? "unknown";
|
|
2684
3046
|
} catch {
|
|
2685
3047
|
return "unknown";
|
|
@@ -2780,6 +3142,7 @@ loadEnv({ quiet: true });
|
|
|
2780
3142
|
loadEnv({ path: ".env.runtime", quiet: true });
|
|
2781
3143
|
var BASE_URL = process.env.UNBROWSE_URL || "http://localhost:6969";
|
|
2782
3144
|
var CLI_CLIENT_ID = process.env.UNBROWSE_CLIENT_ID || `cli-${process.ppid || process.pid}`;
|
|
3145
|
+
var walletNudgeShown = false;
|
|
2783
3146
|
function parseArgs(argv) {
|
|
2784
3147
|
const raw = argv.slice(2);
|
|
2785
3148
|
const command = raw[0] && !raw[0].startsWith("--") ? raw[0] : "help";
|
|
@@ -2926,6 +3289,14 @@ function formatSavedDuration(ms) {
|
|
|
2926
3289
|
return `${(ms / 1000).toFixed(1)}s`;
|
|
2927
3290
|
return `${ms}ms`;
|
|
2928
3291
|
}
|
|
3292
|
+
function formatCostUsd(uc) {
|
|
3293
|
+
const usd = uc / 1e6;
|
|
3294
|
+
if (usd >= 1)
|
|
3295
|
+
return `$${usd.toFixed(2)}`;
|
|
3296
|
+
if (usd >= 0.01)
|
|
3297
|
+
return `$${usd.toFixed(3)}`;
|
|
3298
|
+
return `$${usd.toFixed(4)}`;
|
|
3299
|
+
}
|
|
2929
3300
|
function emitImpactSummary(result) {
|
|
2930
3301
|
const impact = result.impact;
|
|
2931
3302
|
if (!impact)
|
|
@@ -2934,14 +3305,17 @@ function emitImpactSummary(result) {
|
|
|
2934
3305
|
const tokensSaved = typeof impact.tokens_saved === "number" ? impact.tokens_saved : 0;
|
|
2935
3306
|
const timeSavedPct = typeof impact.time_saved_pct === "number" ? impact.time_saved_pct : 0;
|
|
2936
3307
|
const tokensSavedPct = typeof impact.tokens_saved_pct === "number" ? impact.tokens_saved_pct : 0;
|
|
3308
|
+
const costSavedUc = typeof impact.cost_saved_uc === "number" ? impact.cost_saved_uc : 0;
|
|
2937
3309
|
const browserAvoided = impact.browser_avoided === true;
|
|
2938
|
-
if (timeSavedMs <= 0 && tokensSaved <= 0 && !browserAvoided)
|
|
3310
|
+
if (timeSavedMs <= 0 && tokensSaved <= 0 && costSavedUc <= 0 && !browserAvoided)
|
|
2939
3311
|
return;
|
|
2940
3312
|
const parts = [];
|
|
2941
3313
|
if (timeSavedMs > 0)
|
|
2942
3314
|
parts.push(`${formatSavedDuration(timeSavedMs)} saved (${timeSavedPct}% faster)`);
|
|
2943
3315
|
if (tokensSaved > 0)
|
|
2944
3316
|
parts.push(`${tokensSaved.toLocaleString("en-US")} tokens saved (${tokensSavedPct}% less context)`);
|
|
3317
|
+
if (costSavedUc > 0)
|
|
3318
|
+
parts.push(`${formatCostUsd(costSavedUc)} saved`);
|
|
2945
3319
|
if (browserAvoided)
|
|
2946
3320
|
parts.push("browser avoided");
|
|
2947
3321
|
info(parts.join(" \u2022 "));
|
|
@@ -3086,9 +3460,24 @@ async function cmdResolve(flags) {
|
|
|
3086
3460
|
}
|
|
3087
3461
|
result = slimTrace(result);
|
|
3088
3462
|
emitImpactSummary(result);
|
|
3463
|
+
{
|
|
3464
|
+
const entry = impactFromResult("resolve", result, { intent, domain });
|
|
3465
|
+
if (entry)
|
|
3466
|
+
appendImpact(entry);
|
|
3467
|
+
}
|
|
3089
3468
|
emitNextActionSummary(result);
|
|
3090
3469
|
const skill = result.skill;
|
|
3091
3470
|
const trace = result.trace;
|
|
3471
|
+
if (trace?.success && !walletNudgeShown) {
|
|
3472
|
+
try {
|
|
3473
|
+
const { checkWalletConfigured: checkWalletConfigured3 } = await Promise.resolve().then(() => (init_wallet2(), exports_wallet));
|
|
3474
|
+
const wallet = checkWalletConfigured3();
|
|
3475
|
+
if (!wallet.configured) {
|
|
3476
|
+
info("You're indexing routes but have no payout wallet. Run: npx @crossmint/lobster-cli setup");
|
|
3477
|
+
walletNudgeShown = true;
|
|
3478
|
+
}
|
|
3479
|
+
} catch (_e) {}
|
|
3480
|
+
}
|
|
3092
3481
|
if (skill?.skill_id && trace) {
|
|
3093
3482
|
result._feedback = `unbrowse feedback --skill ${skill.skill_id} --endpoint ${trace.endpoint_id || "?"} --rating <1-5>`;
|
|
3094
3483
|
}
|
|
@@ -3246,6 +3635,14 @@ async function cmdExecute(flags) {
|
|
|
3246
3635
|
}
|
|
3247
3636
|
result = slimTrace(result);
|
|
3248
3637
|
emitImpactSummary(result);
|
|
3638
|
+
{
|
|
3639
|
+
const entry = impactFromResult("execute", result, {
|
|
3640
|
+
skill_id: skillId,
|
|
3641
|
+
endpoint_id: typeof flags.endpoint === "string" ? flags.endpoint : undefined
|
|
3642
|
+
});
|
|
3643
|
+
if (entry)
|
|
3644
|
+
appendImpact(entry);
|
|
3645
|
+
}
|
|
3249
3646
|
emitNextActionSummary(result);
|
|
3250
3647
|
const pathFlag = flags.path;
|
|
3251
3648
|
const extractFlag = flags.extract;
|
|
@@ -3472,6 +3869,16 @@ async function cmdSetup(flags) {
|
|
|
3472
3869
|
info(`${hook.host} update hint hook ${hook.action} at ${hook.config_file}`);
|
|
3473
3870
|
}
|
|
3474
3871
|
}
|
|
3872
|
+
if (report.wallet.configured) {
|
|
3873
|
+
info(`Wallet configured (${report.wallet.provider}): ${report.wallet.wallet_address ?? "linked"}`);
|
|
3874
|
+
} else if (report.wallet.lobster_installed) {
|
|
3875
|
+
info("Wallet not paired \u2014 your indexed routes won't earn payouts.");
|
|
3876
|
+
info("Run: npx @crossmint/lobster-cli setup");
|
|
3877
|
+
} else {
|
|
3878
|
+
info("No wallet configured \u2014 you're indexing routes for free.");
|
|
3879
|
+
info("Set up a wallet so you earn when agents use your routes:");
|
|
3880
|
+
info(" npx @crossmint/lobster-cli setup");
|
|
3881
|
+
}
|
|
3475
3882
|
await recordInstallTelemetryEvent("setup", {
|
|
3476
3883
|
hostType,
|
|
3477
3884
|
status: report.browser_engine.action === "failed" ? "failed" : "installed",
|
|
@@ -3565,7 +3972,8 @@ var CLI_REFERENCE = {
|
|
|
3565
3972
|
{ name: "back", usage: "[--session id]", desc: "Navigate back" },
|
|
3566
3973
|
{ name: "forward", usage: "[--session id]", desc: "Navigate forward" },
|
|
3567
3974
|
{ name: "sync", usage: "[--session id]", desc: "Checkpoint current capture, keep tab open, queue background index + publish, then inspect via skill/publish review" },
|
|
3568
|
-
{ name: "close", usage: "[--session id]", desc: "Checkpoint capture, queue background index + publish, close browse session, then inspect via skill/publish review" }
|
|
3975
|
+
{ name: "close", usage: "[--session id]", desc: "Checkpoint capture, queue background index + publish, close browse session, then inspect via skill/publish review" },
|
|
3976
|
+
{ name: "stats", usage: "[--json] [--pretty]", desc: "Show lifetime time/tokens/cost saved and marketplace earnings/spending" }
|
|
3569
3977
|
],
|
|
3570
3978
|
globalFlags: [
|
|
3571
3979
|
{ flag: "--pretty", desc: "Indented JSON output" },
|
|
@@ -3606,6 +4014,131 @@ var CLI_REFERENCE = {
|
|
|
3606
4014
|
`unbrowse publish --skill abc --endpoints '[{"endpoint_id":"def","description":"Search court judgments by keywords","action_kind":"search","resource_kind":"judgment"}]'`
|
|
3607
4015
|
]
|
|
3608
4016
|
};
|
|
4017
|
+
function formatTotalDuration(ms) {
|
|
4018
|
+
if (ms >= 3600000)
|
|
4019
|
+
return `${(ms / 3600000).toFixed(1)}h`;
|
|
4020
|
+
if (ms >= 60000)
|
|
4021
|
+
return `${(ms / 60000).toFixed(1)}m`;
|
|
4022
|
+
if (ms >= 1000)
|
|
4023
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
4024
|
+
return `${ms}ms`;
|
|
4025
|
+
}
|
|
4026
|
+
async function cmdStats(flags) {
|
|
4027
|
+
const pretty = !!flags.pretty;
|
|
4028
|
+
const jsonOnly = !!flags.json;
|
|
4029
|
+
const local = readImpactSummary();
|
|
4030
|
+
const agentId = getAgentId();
|
|
4031
|
+
let profile = null;
|
|
4032
|
+
let earnings = null;
|
|
4033
|
+
let spending = null;
|
|
4034
|
+
const remoteErrors = {};
|
|
4035
|
+
if (agentId) {
|
|
4036
|
+
const results = await Promise.allSettled([
|
|
4037
|
+
getMyProfile(),
|
|
4038
|
+
getCreatorEarnings(agentId),
|
|
4039
|
+
getTransactionHistory(agentId)
|
|
4040
|
+
]);
|
|
4041
|
+
if (results[0].status === "fulfilled")
|
|
4042
|
+
profile = results[0].value;
|
|
4043
|
+
else
|
|
4044
|
+
remoteErrors.profile = results[0].reason?.message ?? String(results[0].reason);
|
|
4045
|
+
if (results[1].status === "fulfilled")
|
|
4046
|
+
earnings = results[1].value;
|
|
4047
|
+
else
|
|
4048
|
+
remoteErrors.earnings = results[1].reason?.message ?? String(results[1].reason);
|
|
4049
|
+
if (results[2].status === "fulfilled")
|
|
4050
|
+
spending = results[2].value;
|
|
4051
|
+
else
|
|
4052
|
+
remoteErrors.spending = results[2].reason?.message ?? String(results[2].reason);
|
|
4053
|
+
} else {
|
|
4054
|
+
remoteErrors.profile = "No agent_id in local config. Run `unbrowse setup` to register.";
|
|
4055
|
+
}
|
|
4056
|
+
const earnedUsd = earnings?.ledger?.total_earned_usd ?? 0;
|
|
4057
|
+
const spentUsd = spending?.ledger?.total_spent_usd ?? 0;
|
|
4058
|
+
const netUsd = earnedUsd - spentUsd;
|
|
4059
|
+
const savedUsd = local.total_cost_saved_uc / 1e6;
|
|
4060
|
+
const payload = {
|
|
4061
|
+
agent_id: agentId,
|
|
4062
|
+
profile,
|
|
4063
|
+
impact: {
|
|
4064
|
+
total_runs: local.total_runs,
|
|
4065
|
+
successful_runs: local.successful_runs,
|
|
4066
|
+
browser_avoided_runs: local.browser_avoided_runs,
|
|
4067
|
+
total_time_saved_ms: local.total_time_saved_ms,
|
|
4068
|
+
total_time_saved_human: formatTotalDuration(local.total_time_saved_ms),
|
|
4069
|
+
total_tokens_saved: local.total_tokens_saved,
|
|
4070
|
+
total_cost_saved_usd: Number(savedUsd.toFixed(6)),
|
|
4071
|
+
avg_time_saved_pct: local.avg_time_saved_pct,
|
|
4072
|
+
avg_tokens_saved_pct: local.avg_tokens_saved_pct,
|
|
4073
|
+
by_source: local.by_source,
|
|
4074
|
+
first_entry_at: local.first_entry_at,
|
|
4075
|
+
last_entry_at: local.last_entry_at,
|
|
4076
|
+
log_path: getImpactLogPath()
|
|
4077
|
+
},
|
|
4078
|
+
earnings: {
|
|
4079
|
+
total_earned_usd: earnedUsd,
|
|
4080
|
+
total_earned_uc: earnings?.ledger?.total_earned_uc ?? 0,
|
|
4081
|
+
transaction_count: earnings?.ledger?.transaction_count ?? 0,
|
|
4082
|
+
last_transaction_at: earnings?.ledger?.last_transaction_at ?? null
|
|
4083
|
+
},
|
|
4084
|
+
spending: {
|
|
4085
|
+
total_spent_usd: spentUsd,
|
|
4086
|
+
total_spent_uc: spending?.ledger?.total_spent_uc ?? 0,
|
|
4087
|
+
transaction_count: spending?.ledger?.transaction_count ?? 0,
|
|
4088
|
+
last_transaction_at: spending?.ledger?.last_transaction_at ?? null
|
|
4089
|
+
},
|
|
4090
|
+
net_usd: netUsd,
|
|
4091
|
+
...Object.keys(remoteErrors).length > 0 ? { remote_errors: remoteErrors } : {}
|
|
4092
|
+
};
|
|
4093
|
+
if (jsonOnly) {
|
|
4094
|
+
output(payload, pretty);
|
|
4095
|
+
return;
|
|
4096
|
+
}
|
|
4097
|
+
const lines = [];
|
|
4098
|
+
lines.push("Unbrowse stats");
|
|
4099
|
+
lines.push(` agent_id: ${agentId ?? "(not registered \u2014 run `unbrowse setup`)"}`);
|
|
4100
|
+
if (profile?.name)
|
|
4101
|
+
lines.push(` name: ${profile.name}`);
|
|
4102
|
+
lines.push("");
|
|
4103
|
+
lines.push("Impact (local, this machine):");
|
|
4104
|
+
if (local.total_runs === 0) {
|
|
4105
|
+
lines.push(" No resolve/execute runs recorded yet.");
|
|
4106
|
+
lines.push(` Log file: ${getImpactLogPath()}`);
|
|
4107
|
+
} else {
|
|
4108
|
+
lines.push(` Runs: ${local.total_runs} (${local.successful_runs} successful, ${local.browser_avoided_runs} browser-avoided)`);
|
|
4109
|
+
if (local.total_time_saved_ms > 0) {
|
|
4110
|
+
lines.push(` Time saved: ${formatTotalDuration(local.total_time_saved_ms)} (avg ${local.avg_time_saved_pct}% faster)`);
|
|
4111
|
+
}
|
|
4112
|
+
if (local.total_tokens_saved > 0) {
|
|
4113
|
+
lines.push(` Tokens saved: ${local.total_tokens_saved.toLocaleString("en-US")} (avg ${local.avg_tokens_saved_pct}% less context)`);
|
|
4114
|
+
}
|
|
4115
|
+
if (savedUsd > 0) {
|
|
4116
|
+
lines.push(` Cost saved: ${formatCostUsd(local.total_cost_saved_uc)}`);
|
|
4117
|
+
}
|
|
4118
|
+
if (Object.keys(local.by_source).length > 0) {
|
|
4119
|
+
const topSources = Object.entries(local.by_source).sort((a, b) => b[1] - a[1]).slice(0, 5).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
4120
|
+
lines.push(` By source: ${topSources}`);
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
lines.push("");
|
|
4124
|
+
lines.push("Money (backend ledger):");
|
|
4125
|
+
if (!agentId) {
|
|
4126
|
+
lines.push(" (not registered \u2014 earnings/spending unavailable)");
|
|
4127
|
+
} else if (remoteErrors.earnings || remoteErrors.spending) {
|
|
4128
|
+
if (remoteErrors.earnings)
|
|
4129
|
+
lines.push(` earnings: error \u2014 ${remoteErrors.earnings}`);
|
|
4130
|
+
if (remoteErrors.spending)
|
|
4131
|
+
lines.push(` spending: error \u2014 ${remoteErrors.spending}`);
|
|
4132
|
+
} else {
|
|
4133
|
+
lines.push(` Earned: $${earnedUsd.toFixed(4)} (${earnings?.ledger?.transaction_count ?? 0} payouts)`);
|
|
4134
|
+
lines.push(` Spent: $${spentUsd.toFixed(4)} (${spending?.ledger?.transaction_count ?? 0} payments)`);
|
|
4135
|
+
lines.push(` Net: ${netUsd >= 0 ? "+" : ""}$${netUsd.toFixed(4)}`);
|
|
4136
|
+
}
|
|
4137
|
+
lines.push("");
|
|
4138
|
+
info(lines.join(`
|
|
4139
|
+
`));
|
|
4140
|
+
output(payload, pretty);
|
|
4141
|
+
}
|
|
3609
4142
|
function printHelp() {
|
|
3610
4143
|
const r = CLI_REFERENCE;
|
|
3611
4144
|
const lines = ["unbrowse \u2014 shell-safe CLI for the local API", ""];
|
|
@@ -4027,6 +4560,8 @@ async function main() {
|
|
|
4027
4560
|
return cmdUpgrade(flags);
|
|
4028
4561
|
if (command === "connect-chrome")
|
|
4029
4562
|
return cmdConnectChrome();
|
|
4563
|
+
if (command === "stats")
|
|
4564
|
+
return cmdStats(flags);
|
|
4030
4565
|
const KNOWN_COMMANDS = new Set([
|
|
4031
4566
|
"health",
|
|
4032
4567
|
"mcp",
|
|
@@ -4070,7 +4605,8 @@ async function main() {
|
|
|
4070
4605
|
"forward",
|
|
4071
4606
|
"sync",
|
|
4072
4607
|
"close",
|
|
4073
|
-
"connect-chrome"
|
|
4608
|
+
"connect-chrome",
|
|
4609
|
+
"stats"
|
|
4074
4610
|
]);
|
|
4075
4611
|
if (!KNOWN_COMMANDS.has(command)) {
|
|
4076
4612
|
const pack = findSitePack(command);
|
|
@@ -4166,6 +4702,8 @@ async function main() {
|
|
|
4166
4702
|
return cmdClose(flags);
|
|
4167
4703
|
case "connect-chrome":
|
|
4168
4704
|
return cmdConnectChrome();
|
|
4705
|
+
case "stats":
|
|
4706
|
+
return cmdStats(flags);
|
|
4169
4707
|
default:
|
|
4170
4708
|
info(`Unknown command: ${command}`);
|
|
4171
4709
|
printHelp();
|