unbrowse 3.1.0-experiments.995f8bb → 3.1.0-experiments.9cbcb13

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.
Files changed (105) hide show
  1. package/dist/cli.js +79 -33
  2. package/dist/index.js +2 -6
  3. package/dist/mcp.js +73 -22
  4. package/dist/server.js +25994 -0
  5. package/package.json +1 -2
  6. package/vendor/kuri/manifest.json +1 -1
  7. package/runtime-src/agent-outcome.ts +0 -166
  8. package/runtime-src/analytics-session.ts +0 -55
  9. package/runtime-src/api/browse-index.ts +0 -343
  10. package/runtime-src/api/browse-session.ts +0 -572
  11. package/runtime-src/api/browse-submit-prereqs.ts +0 -48
  12. package/runtime-src/api/browse-submit.ts +0 -1184
  13. package/runtime-src/api/routes.ts +0 -1833
  14. package/runtime-src/auth/browser-cookies.ts +0 -423
  15. package/runtime-src/auth/index.ts +0 -535
  16. package/runtime-src/auth/runtime.ts +0 -116
  17. package/runtime-src/browser/index.ts +0 -659
  18. package/runtime-src/browser/types.ts +0 -41
  19. package/runtime-src/build-info.generated.ts +0 -6
  20. package/runtime-src/capture/index.ts +0 -1929
  21. package/runtime-src/capture/prefetch.ts +0 -95
  22. package/runtime-src/capture/rsc.ts +0 -45
  23. package/runtime-src/cli/shortcuts.ts +0 -273
  24. package/runtime-src/cli.ts +0 -1734
  25. package/runtime-src/client/graph-client.ts +0 -100
  26. package/runtime-src/client/index.ts +0 -1425
  27. package/runtime-src/debug-trace.ts +0 -18
  28. package/runtime-src/domain.ts +0 -38
  29. package/runtime-src/execution/index.ts +0 -3407
  30. package/runtime-src/execution/retry.ts +0 -46
  31. package/runtime-src/execution/robots.ts +0 -167
  32. package/runtime-src/execution/search-forms.ts +0 -188
  33. package/runtime-src/execution/token-resolver.ts +0 -135
  34. package/runtime-src/extraction/index.ts +0 -1507
  35. package/runtime-src/foundry/publish-bundle.ts +0 -392
  36. package/runtime-src/graph/agent-augment.ts +0 -315
  37. package/runtime-src/graph/index.ts +0 -1532
  38. package/runtime-src/graph/local-fixtures.ts +0 -393
  39. package/runtime-src/graph/local-harness.ts +0 -646
  40. package/runtime-src/graph/planner.ts +0 -411
  41. package/runtime-src/graph/session.ts +0 -294
  42. package/runtime-src/graph/trace-store.ts +0 -136
  43. package/runtime-src/impact-log.ts +0 -227
  44. package/runtime-src/index.ts +0 -24
  45. package/runtime-src/indexer/index.ts +0 -465
  46. package/runtime-src/intent-match.ts +0 -1515
  47. package/runtime-src/kuri/client.ts +0 -1839
  48. package/runtime-src/logger.ts +0 -30
  49. package/runtime-src/marketplace/index.ts +0 -111
  50. package/runtime-src/mcp.ts +0 -1911
  51. package/runtime-src/orchestrator/browser-agent.ts +0 -374
  52. package/runtime-src/orchestrator/dag-advisor.ts +0 -59
  53. package/runtime-src/orchestrator/dag-feedback.ts +0 -257
  54. package/runtime-src/orchestrator/first-pass-action.ts +0 -403
  55. package/runtime-src/orchestrator/index.ts +0 -4480
  56. package/runtime-src/orchestrator/passive-publish.ts +0 -187
  57. package/runtime-src/orchestrator/timing-economics.ts +0 -80
  58. package/runtime-src/payments/cascade.ts +0 -137
  59. package/runtime-src/payments/index.ts +0 -270
  60. package/runtime-src/payments/lobster-pay.ts +0 -182
  61. package/runtime-src/payments/wallet.ts +0 -98
  62. package/runtime-src/publish/review-context.ts +0 -93
  63. package/runtime-src/publish/sanitize.ts +0 -197
  64. package/runtime-src/publish/schema-review.ts +0 -192
  65. package/runtime-src/publish-admission.ts +0 -388
  66. package/runtime-src/ratelimit/index.ts +0 -23
  67. package/runtime-src/reverse-engineer/bundle-scanner.ts +0 -127
  68. package/runtime-src/reverse-engineer/description-prompt.ts +0 -213
  69. package/runtime-src/reverse-engineer/index.ts +0 -1551
  70. package/runtime-src/reverse-engineer/token-sources.ts +0 -379
  71. package/runtime-src/router.ts +0 -17
  72. package/runtime-src/routing-telemetry.ts +0 -395
  73. package/runtime-src/runtime/browser-access.ts +0 -11
  74. package/runtime-src/runtime/browser-auth.ts +0 -12
  75. package/runtime-src/runtime/browser-host.ts +0 -48
  76. package/runtime-src/runtime/lifecycle.ts +0 -17
  77. package/runtime-src/runtime/local-server.ts +0 -311
  78. package/runtime-src/runtime/paths.ts +0 -99
  79. package/runtime-src/runtime/setup.ts +0 -251
  80. package/runtime-src/runtime/supervisor.ts +0 -69
  81. package/runtime-src/runtime/update-hints.ts +0 -351
  82. package/runtime-src/server.ts +0 -100
  83. package/runtime-src/session-logs.ts +0 -142
  84. package/runtime-src/settings.ts +0 -221
  85. package/runtime-src/single-binary.ts +0 -143
  86. package/runtime-src/site-policy.ts +0 -54
  87. package/runtime-src/stale-cleanup-runner.ts +0 -144
  88. package/runtime-src/stale-cleanup.ts +0 -133
  89. package/runtime-src/telemetry-attribution.ts +0 -120
  90. package/runtime-src/telemetry.ts +0 -253
  91. package/runtime-src/template-params.ts +0 -141
  92. package/runtime-src/transform/drift.ts +0 -60
  93. package/runtime-src/transform/index.ts +0 -277
  94. package/runtime-src/types/index.ts +0 -1
  95. package/runtime-src/types/skill.ts +0 -931
  96. package/runtime-src/vault/index.ts +0 -196
  97. package/runtime-src/verification/auth-gate.ts +0 -8
  98. package/runtime-src/verification/candidates.ts +0 -27
  99. package/runtime-src/verification/index.ts +0 -120
  100. package/runtime-src/verification/matrix.ts +0 -30
  101. package/runtime-src/version.ts +0 -148
  102. package/runtime-src/workflow/artifact.ts +0 -161
  103. package/runtime-src/workflow/compile.ts +0 -808
  104. package/runtime-src/workflow/publish.ts +0 -225
  105. package/runtime-src/workflow/runtime.ts +0 -213
@@ -1,136 +0,0 @@
1
- /**
2
- * Local execution trace storage for future RAG retrieval.
3
- *
4
- * Persists execution traces as JSONL files at ~/.unbrowse/traces/{domain}.jsonl.
5
- * Append-only writes, most-recent-last ordering.
6
- * All operations are synchronous — trace storage is not in the hot path.
7
- */
8
-
9
- import { existsSync, mkdirSync, appendFileSync, readFileSync, writeFileSync } from "node:fs";
10
- import { join } from "node:path";
11
- import { homedir } from "node:os";
12
-
13
- export interface StoredTrace {
14
- trace_id: string;
15
- domain: string;
16
- intent: string;
17
- goal_embedding?: number[]; // For future similarity search
18
- endpoint_sequence: string[]; // Ordered list of endpoint_ids tried
19
- selected_endpoint_id?: string; // The one that succeeded
20
- params: Record<string, unknown>;
21
- success: boolean;
22
- timestamp: string;
23
- duration_ms?: number;
24
- context_url?: string;
25
- }
26
-
27
- const MAX_TRACES_PER_DOMAIN = 1000;
28
-
29
- /** Allow tests to override the trace store root via env var. */
30
- function getTraceStoreRoot(): string {
31
- return process.env.UNBROWSE_TRACE_STORE_DIR ?? join(homedir(), ".unbrowse", "traces");
32
- }
33
-
34
- /**
35
- * Normalize a domain for use as a filename:
36
- * - strip leading "www."
37
- * - lowercase
38
- * - replace non-alphanumeric/dot/hyphen chars with underscore
39
- */
40
- function normalizeDomain(domain: string): string {
41
- return domain
42
- .toLowerCase()
43
- .replace(/^www\./, "")
44
- .replace(/[^a-z0-9.\-]/g, "_");
45
- }
46
-
47
- /** Get the trace store directory path. */
48
- export function getTraceStorePath(): string {
49
- return getTraceStoreRoot();
50
- }
51
-
52
- /** Get the JSONL file path for a given domain. */
53
- function domainFilePath(domain: string): string {
54
- return join(getTraceStoreRoot(), `${normalizeDomain(domain)}.jsonl`);
55
- }
56
-
57
- /**
58
- * Append a trace to the local trace store (JSONL file per domain).
59
- * Graceful degradation: if fs fails, log and continue.
60
- */
61
- export function storeExecutionTrace(trace: StoredTrace): void {
62
- try {
63
- const dir = getTraceStoreRoot();
64
- if (!existsSync(dir)) {
65
- mkdirSync(dir, { recursive: true });
66
- }
67
- const filePath = domainFilePath(trace.domain);
68
- const line = JSON.stringify(trace) + "\n";
69
- appendFileSync(filePath, line, "utf-8");
70
- } catch (err) {
71
- console.warn(`[trace-store] failed to store trace: ${(err as Error).message}`);
72
- }
73
- }
74
-
75
- /**
76
- * Parse a JSONL file into an array of StoredTrace, skipping malformed lines.
77
- * Returns most-recent-last (file order). Truncates to MAX_TRACES_PER_DOMAIN.
78
- */
79
- function readTraces(domain: string): StoredTrace[] {
80
- const filePath = domainFilePath(domain);
81
- if (!existsSync(filePath)) return [];
82
- try {
83
- const content = readFileSync(filePath, "utf-8");
84
- const lines = content.split("\n").filter((line) => line.trim().length > 0);
85
- const traces: StoredTrace[] = [];
86
- for (const line of lines) {
87
- try {
88
- traces.push(JSON.parse(line) as StoredTrace);
89
- } catch {
90
- // Skip malformed lines
91
- }
92
- }
93
- // Truncate old traces if over limit — keep the most recent ones
94
- if (traces.length > MAX_TRACES_PER_DOMAIN) {
95
- const truncated = traces.slice(-MAX_TRACES_PER_DOMAIN);
96
- // Rewrite the file with only the recent traces
97
- try {
98
- writeFileSync(filePath, truncated.map((t) => JSON.stringify(t)).join("\n") + "\n", "utf-8");
99
- } catch {
100
- // Ignore rewrite failures — reads still work
101
- }
102
- return truncated;
103
- }
104
- return traces;
105
- } catch (err) {
106
- console.warn(`[trace-store] failed to read traces for ${domain}: ${(err as Error).message}`);
107
- return [];
108
- }
109
- }
110
-
111
- /**
112
- * Retrieve recent traces for a domain (most recent first).
113
- * @param domain - The domain to look up
114
- * @param limit - Maximum number of traces to return (default 10)
115
- */
116
- export function getRecentTraces(domain: string, limit = 10): StoredTrace[] {
117
- const traces = readTraces(domain);
118
- // Reverse so most recent is first
119
- return traces.reverse().slice(0, limit);
120
- }
121
-
122
- /**
123
- * Retrieve traces matching an intent (simple case-insensitive substring match).
124
- * Returns most recent first.
125
- * @param domain - The domain to search within
126
- * @param intent - Substring to match against trace intents
127
- * @param limit - Maximum number of traces to return (default 5)
128
- */
129
- export function findTracesByIntent(domain: string, intent: string, limit = 5): StoredTrace[] {
130
- const traces = readTraces(domain);
131
- const lowerIntent = intent.toLowerCase();
132
- return traces
133
- .filter((t) => t.intent.toLowerCase().includes(lowerIntent))
134
- .reverse()
135
- .slice(0, limit);
136
- }
@@ -1,227 +0,0 @@
1
- /**
2
- * Local per-agent impact log.
3
- *
4
- * Every resolve/execute appends one line here with the savings it delivered
5
- * (time, tokens, dollars, browser avoided). `unbrowse stats` and the
6
- * unbrowse_stats MCP tool read this file to show lifetime impact without
7
- * needing a new backend endpoint.
8
- *
9
- * Format: JSONL at ~/.unbrowse/impact-log.jsonl (or $UNBROWSE_CONFIG_DIR).
10
- * Rotates when the file exceeds ~5MB.
11
- */
12
-
13
- import { existsSync, mkdirSync, appendFileSync, statSync, readFileSync, renameSync, unlinkSync } from "node:fs";
14
- import { homedir } from "node:os";
15
- import { dirname, join } from "node:path";
16
-
17
- const MAX_LOG_BYTES = 5 * 1024 * 1024;
18
- const MAX_ROTATIONS = 3;
19
-
20
- export interface ImpactLogEntry {
21
- ts: string;
22
- command: "resolve" | "execute" | "browse" | string;
23
- source?: string;
24
- domain?: string;
25
- intent?: string;
26
- skill_id?: string;
27
- endpoint_id?: string;
28
- time_saved_ms?: number;
29
- time_saved_pct?: number;
30
- tokens_saved?: number;
31
- tokens_saved_pct?: number;
32
- cost_saved_uc?: number;
33
- browser_avoided?: boolean;
34
- success?: boolean;
35
- }
36
-
37
- export interface ImpactSummary {
38
- total_runs: number;
39
- successful_runs: number;
40
- browser_avoided_runs: number;
41
- total_time_saved_ms: number;
42
- total_tokens_saved: number;
43
- total_cost_saved_uc: number;
44
- avg_time_saved_pct: number;
45
- avg_tokens_saved_pct: number;
46
- by_source: Record<string, number>;
47
- first_entry_at: string | null;
48
- last_entry_at: string | null;
49
- }
50
-
51
- function getLogDir(): string {
52
- if (process.env.UNBROWSE_CONFIG_DIR) return process.env.UNBROWSE_CONFIG_DIR;
53
- const profile = process.env.UNBROWSE_PROFILE?.trim();
54
- return profile
55
- ? join(homedir(), ".unbrowse", "profiles", profile)
56
- : join(homedir(), ".unbrowse");
57
- }
58
-
59
- export function getImpactLogPath(): string {
60
- return join(getLogDir(), "impact-log.jsonl");
61
- }
62
-
63
- function ensureDir(path: string): void {
64
- const dir = dirname(path);
65
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
66
- }
67
-
68
- function rotateIfNeeded(path: string): void {
69
- try {
70
- if (!existsSync(path)) return;
71
- const size = statSync(path).size;
72
- if (size < MAX_LOG_BYTES) return;
73
- for (let i = MAX_ROTATIONS; i >= 1; i--) {
74
- const older = `${path}.${i}`;
75
- if (!existsSync(older)) continue;
76
- if (i === MAX_ROTATIONS) {
77
- try { unlinkSync(older); } catch {}
78
- } else {
79
- try { renameSync(older, `${path}.${i + 1}`); } catch {}
80
- }
81
- }
82
- renameSync(path, `${path}.1`);
83
- } catch {
84
- // best-effort; never throw from logging
85
- }
86
- }
87
-
88
- /** Append a single impact record. Fire-and-forget; never throws. */
89
- export function appendImpact(entry: ImpactLogEntry): void {
90
- try {
91
- const hasSignal =
92
- (entry.time_saved_ms ?? 0) > 0 ||
93
- (entry.tokens_saved ?? 0) > 0 ||
94
- (entry.cost_saved_uc ?? 0) > 0 ||
95
- entry.browser_avoided === true;
96
- if (!hasSignal) return;
97
-
98
- const path = getImpactLogPath();
99
- ensureDir(path);
100
- rotateIfNeeded(path);
101
- appendFileSync(path, JSON.stringify(entry) + "\n", "utf8");
102
- } catch {
103
- // never surface logging errors
104
- }
105
- }
106
-
107
- /**
108
- * Extract an ImpactLogEntry from an orchestrator result's `impact` field.
109
- * Returns null if the result has no impact data.
110
- */
111
- export function impactFromResult(
112
- command: string,
113
- result: unknown,
114
- extras: { intent?: string; domain?: string; skill_id?: string; endpoint_id?: string } = {},
115
- ): ImpactLogEntry | null {
116
- if (!result || typeof result !== "object") return null;
117
- const r = result as Record<string, unknown>;
118
- const impact = (r.impact ?? null) as Record<string, unknown> | null;
119
- if (!impact || typeof impact !== "object") return null;
120
-
121
- const num = (v: unknown): number | undefined =>
122
- typeof v === "number" && Number.isFinite(v) ? v : undefined;
123
-
124
- return {
125
- ts: new Date().toISOString(),
126
- command,
127
- source: typeof impact.source === "string" ? impact.source : undefined,
128
- domain: extras.domain,
129
- intent: extras.intent,
130
- skill_id: extras.skill_id ?? (typeof r.skill_id === "string" ? r.skill_id : undefined),
131
- endpoint_id: extras.endpoint_id ?? (typeof r.endpoint_id === "string" ? r.endpoint_id : undefined),
132
- time_saved_ms: num(impact.time_saved_ms),
133
- time_saved_pct: num(impact.time_saved_pct),
134
- tokens_saved: num(impact.tokens_saved),
135
- tokens_saved_pct: num(impact.tokens_saved_pct),
136
- cost_saved_uc: num(impact.cost_saved_uc),
137
- browser_avoided: impact.browser_avoided === true,
138
- success: r.error == null,
139
- };
140
- }
141
-
142
- /** Read and aggregate the full impact log (across rotations). Safe on missing file. */
143
- export function readImpactSummary(): ImpactSummary {
144
- const path = getImpactLogPath();
145
- const summary: ImpactSummary = {
146
- total_runs: 0,
147
- successful_runs: 0,
148
- browser_avoided_runs: 0,
149
- total_time_saved_ms: 0,
150
- total_tokens_saved: 0,
151
- total_cost_saved_uc: 0,
152
- avg_time_saved_pct: 0,
153
- avg_tokens_saved_pct: 0,
154
- by_source: {},
155
- first_entry_at: null,
156
- last_entry_at: null,
157
- };
158
-
159
- const files: string[] = [];
160
- for (let i = MAX_ROTATIONS; i >= 1; i--) {
161
- const rotated = `${path}.${i}`;
162
- if (existsSync(rotated)) files.push(rotated);
163
- }
164
- if (existsSync(path)) files.push(path);
165
- if (files.length === 0) return summary;
166
-
167
- let timePctSum = 0;
168
- let timePctCount = 0;
169
- let tokenPctSum = 0;
170
- let tokenPctCount = 0;
171
-
172
- for (const file of files) {
173
- let raw: string;
174
- try {
175
- raw = readFileSync(file, "utf8");
176
- } catch {
177
- continue;
178
- }
179
- for (const line of raw.split("\n")) {
180
- const trimmed = line.trim();
181
- if (!trimmed) continue;
182
- let e: ImpactLogEntry;
183
- try {
184
- e = JSON.parse(trimmed) as ImpactLogEntry;
185
- } catch {
186
- continue;
187
- }
188
- summary.total_runs += 1;
189
- if (e.success !== false) summary.successful_runs += 1;
190
- if (e.browser_avoided) summary.browser_avoided_runs += 1;
191
- summary.total_time_saved_ms += e.time_saved_ms ?? 0;
192
- summary.total_tokens_saved += e.tokens_saved ?? 0;
193
- summary.total_cost_saved_uc += e.cost_saved_uc ?? 0;
194
- if (typeof e.time_saved_pct === "number") {
195
- timePctSum += e.time_saved_pct;
196
- timePctCount += 1;
197
- }
198
- if (typeof e.tokens_saved_pct === "number") {
199
- tokenPctSum += e.tokens_saved_pct;
200
- tokenPctCount += 1;
201
- }
202
- if (e.source) {
203
- summary.by_source[e.source] = (summary.by_source[e.source] ?? 0) + 1;
204
- }
205
- if (!summary.first_entry_at || e.ts < summary.first_entry_at) summary.first_entry_at = e.ts;
206
- if (!summary.last_entry_at || e.ts > summary.last_entry_at) summary.last_entry_at = e.ts;
207
- }
208
- }
209
-
210
- summary.avg_time_saved_pct = timePctCount > 0 ? Math.round(timePctSum / timePctCount) : 0;
211
- summary.avg_tokens_saved_pct = tokenPctCount > 0 ? Math.round(tokenPctSum / tokenPctCount) : 0;
212
- return summary;
213
- }
214
-
215
- /** For tests only. */
216
- export function _clearImpactLogForTests(): void {
217
- const path = getImpactLogPath();
218
- try {
219
- if (existsSync(path)) unlinkSync(path);
220
- for (let i = 1; i <= MAX_ROTATIONS + 1; i++) {
221
- const rotated = `${path}.${i}`;
222
- if (existsSync(rotated)) unlinkSync(rotated);
223
- }
224
- } catch {
225
- // ignore
226
- }
227
- }
@@ -1,24 +0,0 @@
1
- import { config as loadEnv } from "dotenv";
2
- import { installServerExitCleanup, startUnbrowseServer } from "./server.js";
3
-
4
- loadEnv({ quiet: true });
5
- loadEnv({ path: ".env.runtime", quiet: true });
6
-
7
- const pidFile = process.env.UNBROWSE_PID_FILE;
8
- installServerExitCleanup(pidFile);
9
-
10
- const server = await startUnbrowseServer({
11
- pidFile,
12
- scheduleVerification: true,
13
- });
14
-
15
- async function shutdown(signal: string): Promise<void> {
16
- console.log(`[shutdown] ${signal} — closing browsers and server`);
17
- await server.close();
18
- process.exit(0);
19
- }
20
-
21
- process.on("SIGTERM", () => { shutdown("SIGTERM").catch(() => process.exit(1)); });
22
- process.on("SIGINT", () => { shutdown("SIGINT").catch(() => process.exit(1)); });
23
-
24
- console.log(`unbrowse running on http://${server.host}:${server.port}`);