@prismatic-io/lux 0.0.2-preview.4 → 0.0.2-preview.7

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 (138) hide show
  1. package/lib/assertions/authoring.d.ts +2 -2
  2. package/lib/assertions/authoring.d.ts.map +1 -1
  3. package/lib/assertions/authoring.js.map +1 -1
  4. package/lib/assertions/core/index.d.ts.map +1 -1
  5. package/lib/assertions/core/index.js +2 -1
  6. package/lib/assertions/core/index.js.map +1 -1
  7. package/lib/assertions/core/resource-checks.d.ts +19 -0
  8. package/lib/assertions/core/resource-checks.d.ts.map +1 -1
  9. package/lib/assertions/core/resource-checks.js +32 -0
  10. package/lib/assertions/core/resource-checks.js.map +1 -1
  11. package/lib/cli/program.d.ts.map +1 -1
  12. package/lib/cli/program.js +6 -65
  13. package/lib/cli/program.js.map +1 -1
  14. package/lib/cli/view.d.ts +13 -0
  15. package/lib/cli/view.d.ts.map +1 -0
  16. package/lib/cli/view.js +126 -0
  17. package/lib/cli/view.js.map +1 -0
  18. package/lib/core/action-events.d.ts +29 -0
  19. package/lib/core/action-events.d.ts.map +1 -0
  20. package/lib/core/action-events.js +51 -0
  21. package/lib/core/action-events.js.map +1 -0
  22. package/lib/core/agent-activity.d.ts +49 -0
  23. package/lib/core/agent-activity.d.ts.map +1 -0
  24. package/lib/core/agent-activity.js +206 -0
  25. package/lib/core/agent-activity.js.map +1 -0
  26. package/lib/core/agent-events.d.ts +26 -0
  27. package/lib/core/agent-events.d.ts.map +1 -0
  28. package/lib/core/agent-events.js +13 -0
  29. package/lib/core/agent-events.js.map +1 -0
  30. package/lib/core/driver-metrics.d.ts +98 -0
  31. package/lib/core/driver-metrics.d.ts.map +1 -0
  32. package/lib/core/driver-metrics.js +36 -0
  33. package/lib/core/driver-metrics.js.map +1 -0
  34. package/lib/core/events.d.ts +34 -0
  35. package/lib/core/events.d.ts.map +1 -1
  36. package/lib/core/events.js +11 -2
  37. package/lib/core/events.js.map +1 -1
  38. package/lib/core/experiment.d.ts +19 -0
  39. package/lib/core/experiment.d.ts.map +1 -1
  40. package/lib/core/experiment.js +2 -0
  41. package/lib/core/experiment.js.map +1 -1
  42. package/lib/core/index.d.ts +4 -0
  43. package/lib/core/index.d.ts.map +1 -1
  44. package/lib/core/index.js +4 -0
  45. package/lib/core/index.js.map +1 -1
  46. package/lib/core/run.d.ts +149 -0
  47. package/lib/core/run.d.ts.map +1 -1
  48. package/lib/core/run.js +9 -0
  49. package/lib/core/run.js.map +1 -1
  50. package/lib/core/wire.d.ts +11 -0
  51. package/lib/core/wire.d.ts.map +1 -1
  52. package/lib/drivers/claude-code/parse-events.d.ts.map +1 -1
  53. package/lib/drivers/claude-code/parse-events.js +73 -8
  54. package/lib/drivers/claude-code/parse-events.js.map +1 -1
  55. package/lib/drivers/codex/app-events.d.ts +9 -2
  56. package/lib/drivers/codex/app-events.d.ts.map +1 -1
  57. package/lib/drivers/codex/app-events.js +93 -12
  58. package/lib/drivers/codex/app-events.js.map +1 -1
  59. package/lib/drivers/codex/index.d.ts.map +1 -1
  60. package/lib/drivers/codex/index.js +10 -14
  61. package/lib/drivers/codex/index.js.map +1 -1
  62. package/lib/index.d.ts +6 -2
  63. package/lib/index.d.ts.map +1 -1
  64. package/lib/index.js +6 -2
  65. package/lib/index.js.map +1 -1
  66. package/lib/orchestrator/compare.d.ts +13 -1
  67. package/lib/orchestrator/compare.d.ts.map +1 -1
  68. package/lib/orchestrator/compare.js +12 -0
  69. package/lib/orchestrator/compare.js.map +1 -1
  70. package/lib/orchestrator/experiment-contracts.d.ts +19 -0
  71. package/lib/orchestrator/experiment-contracts.d.ts.map +1 -1
  72. package/lib/orchestrator/experiment-evaluation.d.ts.map +1 -1
  73. package/lib/orchestrator/experiment-evaluation.js +17 -0
  74. package/lib/orchestrator/experiment-evaluation.js.map +1 -1
  75. package/lib/orchestrator/experiment-report.d.ts +19 -0
  76. package/lib/orchestrator/experiment-report.d.ts.map +1 -1
  77. package/lib/orchestrator/experiment-runs.d.ts +38 -0
  78. package/lib/orchestrator/experiment-runs.d.ts.map +1 -1
  79. package/lib/orchestrator/index.d.ts +1 -1
  80. package/lib/orchestrator/index.d.ts.map +1 -1
  81. package/lib/orchestrator/index.js +1 -1
  82. package/lib/orchestrator/index.js.map +1 -1
  83. package/lib/orchestrator/list-runs.d.ts +7 -1
  84. package/lib/orchestrator/list-runs.d.ts.map +1 -1
  85. package/lib/orchestrator/list-runs.js +50 -6
  86. package/lib/orchestrator/list-runs.js.map +1 -1
  87. package/lib/orchestrator/run-execution.d.ts.map +1 -1
  88. package/lib/orchestrator/run-execution.js +17 -3
  89. package/lib/orchestrator/run-execution.js.map +1 -1
  90. package/lib/orchestrator/suite-compare.d.ts +34 -0
  91. package/lib/orchestrator/suite-compare.d.ts.map +1 -1
  92. package/lib/orchestrator/suite-summary.d.ts +68 -0
  93. package/lib/orchestrator/suite-summary.d.ts.map +1 -1
  94. package/lib/orchestrator/suite-summary.js +45 -7
  95. package/lib/orchestrator/suite-summary.js.map +1 -1
  96. package/lib/previewer/artifacts.d.ts +25 -0
  97. package/lib/previewer/artifacts.d.ts.map +1 -0
  98. package/lib/previewer/artifacts.js +180 -0
  99. package/lib/previewer/artifacts.js.map +1 -0
  100. package/lib/previewer/server.d.ts +105 -0
  101. package/lib/previewer/server.d.ts.map +1 -0
  102. package/lib/previewer/server.js +542 -0
  103. package/lib/previewer/server.js.map +1 -0
  104. package/package.json +2 -1
  105. package/skills/lux/references/eval-authoring.md +4 -2
  106. package/skills/lux-answerer/SKILL.md +1 -1
  107. package/src/assertions/authoring.ts +2 -0
  108. package/src/assertions/core/index.ts +2 -0
  109. package/src/assertions/core/resource-checks.ts +35 -0
  110. package/src/cli/program.ts +5 -91
  111. package/src/cli/view.ts +168 -0
  112. package/src/core/action-events.ts +59 -0
  113. package/src/core/agent-activity.ts +236 -0
  114. package/src/core/agent-events.ts +17 -0
  115. package/src/core/driver-metrics.ts +51 -0
  116. package/src/core/events.ts +13 -2
  117. package/src/core/experiment.ts +2 -0
  118. package/src/core/index.ts +4 -0
  119. package/src/core/run.ts +9 -0
  120. package/src/drivers/claude-code/parse-events.ts +98 -12
  121. package/src/drivers/codex/app-events.ts +116 -16
  122. package/src/drivers/codex/index.ts +16 -14
  123. package/src/index.ts +40 -0
  124. package/src/orchestrator/compare.ts +18 -0
  125. package/src/orchestrator/experiment-evaluation.ts +23 -0
  126. package/src/orchestrator/index.ts +1 -0
  127. package/src/orchestrator/list-runs.ts +66 -5
  128. package/src/orchestrator/run-execution.ts +19 -2
  129. package/src/orchestrator/suite-summary.ts +101 -8
  130. package/src/previewer/artifacts.ts +221 -0
  131. package/src/previewer/server.ts +765 -0
  132. package/viewer/app.css +2075 -0
  133. package/viewer/app.js +606 -0
  134. package/viewer/artifact-view.js +48 -0
  135. package/viewer/charts.js +86 -0
  136. package/viewer/detail.js +1214 -0
  137. package/viewer/format.js +129 -0
  138. package/viewer/index.html +151 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifacts.js","sourceRoot":"","sources":["../../src/previewer/artifacts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE5E,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAClC,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,cAAc,GAAG,SAAS,CAAC;AAyBjC,MAAM,iBAAiB,GAAG,CACxB,OAA4B,EAC5B,UAA6B,EACjB,EAAE;IACd,MAAM,GAAG,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IACzB,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACvE,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,G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K,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QACvF,OAAO;YACL,IAAI;YACJ,MAAM;YACN,KAAK;YACL,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,8BAA8B;SACxE,CAAC;IACJ,CAAC;IACD,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACtD,OAAO;QACL,IAAI;QACJ,MAAM;QACN,KAAK;QACL,UAAU;QACV,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,+CAA+C;KAC5E,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,105 @@
1
+ import { type DriverMetricDescriptor, type DriverMetrics } from "../core/index.js";
2
+ type PreviewKind = "run" | "suite" | "experiment";
3
+ type PreviewStatus = "passed" | "failed" | "running" | "aborted" | "error" | "ungraded";
4
+ type PreviewRun = {
5
+ id: string;
6
+ kind: "run";
7
+ status: PreviewStatus;
8
+ caseId: string;
9
+ driver: string;
10
+ agentId: string | null;
11
+ startedAt: string | null;
12
+ durationMs: number | null;
13
+ timeToFirstActionMs: number | null;
14
+ timeToFirstMutationMs: number | null;
15
+ timeToFirstDurableMutationMs: number | null;
16
+ driverMetrics: DriverMetrics;
17
+ subagentCount: number;
18
+ score: number | null;
19
+ assertions: {
20
+ passed: number;
21
+ total: number;
22
+ };
23
+ path: string;
24
+ };
25
+ type PreviewSuite = {
26
+ id: string;
27
+ kind: "suite";
28
+ status: PreviewStatus;
29
+ suiteId: string;
30
+ startedAt: string;
31
+ endedAt: string | null;
32
+ concurrency: number;
33
+ profileId?: string | undefined;
34
+ items: Array<{
35
+ caseId: string;
36
+ canonicalCaseId: string;
37
+ status: string;
38
+ exitReason: string | null;
39
+ casePassed: boolean | null;
40
+ runId: string | null;
41
+ errorMessage?: string | undefined;
42
+ }>;
43
+ path: string;
44
+ };
45
+ type PreviewExperiment = {
46
+ id: string;
47
+ kind: "experiment";
48
+ status: PreviewStatus;
49
+ experimentId: string;
50
+ campaignId: string;
51
+ mode: "experiment" | "optimize";
52
+ startedAt: string;
53
+ endedAt: string | null;
54
+ activeTimeMs: number;
55
+ candidateCount: number;
56
+ championCandidateId: string | null;
57
+ budget: {
58
+ metricCalls: number;
59
+ judgeCalls: number;
60
+ proposalCalls: number;
61
+ costUsd: number;
62
+ };
63
+ evaluations: Array<{
64
+ candidateId: string;
65
+ profileId: string;
66
+ split: "train" | "validation" | "test";
67
+ passRate: number;
68
+ metrics: Record<string, number>;
69
+ metricDefinitions: Record<string, DriverMetricDescriptor>;
70
+ failedCases: Array<{
71
+ caseId: string;
72
+ score: number | null;
73
+ feedback: string[];
74
+ }>;
75
+ }>;
76
+ path: string;
77
+ };
78
+ export type PreviewSnapshot = {
79
+ generatedAt: string;
80
+ runsRoot: string;
81
+ initial: {
82
+ kind: PreviewKind;
83
+ id: string;
84
+ } | null;
85
+ runs: PreviewRun[];
86
+ suites: PreviewSuite[];
87
+ experiments: PreviewExperiment[];
88
+ };
89
+ export type PreviewServer = {
90
+ url: string;
91
+ closed: Promise<void>;
92
+ close: () => Promise<void>;
93
+ };
94
+ export type StartPreviewServerOptions = {
95
+ runsRoot: string;
96
+ port?: number | undefined;
97
+ initialPath?: string | undefined;
98
+ initialKind?: PreviewKind | undefined;
99
+ caseFilter?: string | undefined;
100
+ signal?: AbortSignal | undefined;
101
+ };
102
+ export declare const startPreviewServer: (options: StartPreviewServerOptions) => Promise<PreviewServer>;
103
+ export declare const openPreviewUrl: (url: string) => Promise<void>;
104
+ export {};
105
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/previewer/server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,sBAAsB,EAA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YAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAC;KAClF,CAAC,CAAC;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAClD,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,WAAW,EAAE,iBAAiB,EAAE,CAAC;CAClC,CAAC;AAOF,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,WAAW,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IACtC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAClC,CAAC;AAgkBF,eAAO,MAAM,kBAAkB,YACpB,yBAAyB,KACjC,OAAO,CAAC,aAAa,CA4CvB,CAAC;AAEF,eAAO,MAAM,cAAc,QAAe,MAAM,KAAG,OAAO,CAAC,IAAI,CAgB9D,CAAC"}
@@ -0,0 +1,542 @@
1
+ import { existsSync } from "node:fs";
2
+ import { readFile } from "node:fs/promises";
3
+ import { createServer } from "node:http";
4
+ import { basename, relative, resolve, sep } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { exec } from "../core/index.js";
7
+ import { compareRuns, compareSuiteRuns, listExperimentRuns, listRuns, listSuiteRuns, loadExperimentCandidates, loadRunArtifacts, loadRunDetail, loadSuiteSummary, loadVerifiedExperimentDecisionSnapshot, } from "../orchestrator/index.js";
8
+ import { compareArtifactPreviews, loadArtifactPreview } from "./artifacts.js";
9
+ const LOOPBACK_HOST = "127.0.0.1";
10
+ const ASSET_ROOT = fileURLToPath(new URL("../../viewer/", import.meta.url));
11
+ const opaqueId = (runsRoot, path) => Buffer.from(relative(resolve(runsRoot), resolve(path))).toString("base64url");
12
+ const displayPath = (runsRoot, path) => {
13
+ const value = relative(resolve(runsRoot), resolve(path));
14
+ return value.split(sep).join("/");
15
+ };
16
+ const runStatus = (run) => {
17
+ if (run.exitReason && run.exitReason !== "done")
18
+ return "error";
19
+ if (run.casePassed === true)
20
+ return "passed";
21
+ if (run.casePassed === false)
22
+ return "failed";
23
+ return "ungraded";
24
+ };
25
+ const normalizeStatus = (status) => {
26
+ if (status === "passed" || status === "failed" || status === "running" || status === "aborted") {
27
+ return status;
28
+ }
29
+ return "ungraded";
30
+ };
31
+ const buildSnapshot = async (runsRoot, options) => {
32
+ const absoluteRunsRoot = resolve(runsRoot);
33
+ const [listedRuns, listedSuites, listedExperiments] = await Promise.all([
34
+ listRuns(absoluteRunsRoot),
35
+ listSuiteRuns(absoluteRunsRoot),
36
+ listExperimentRuns(absoluteRunsRoot),
37
+ ]);
38
+ const runs = listedRuns
39
+ .filter((run) => !options.caseFilter || run.caseSlug === options.caseFilter)
40
+ .map((run) => ({
41
+ id: opaqueId(absoluteRunsRoot, run.runDir),
42
+ kind: "run",
43
+ status: runStatus(run),
44
+ caseId: run.caseSlug,
45
+ driver: run.driverName,
46
+ agentId: run.driverAgentId,
47
+ startedAt: run.startedAt,
48
+ durationMs: run.durationMs,
49
+ timeToFirstActionMs: run.timeToFirstActionMs,
50
+ timeToFirstMutationMs: run.timeToFirstMutationMs,
51
+ timeToFirstDurableMutationMs: run.timeToFirstDurableMutationMs,
52
+ driverMetrics: run.driverMetrics,
53
+ subagentCount: run.subagentCount,
54
+ score: run.caseScore,
55
+ assertions: { passed: run.assertionPassed, total: run.assertionTotal },
56
+ path: displayPath(absoluteRunsRoot, run.runDir),
57
+ }));
58
+ const runIdsByPath = new Map(listedRuns.map((run) => [resolve(run.runDir), opaqueId(absoluteRunsRoot, run.runDir)]));
59
+ const suites = listedSuites.map((suite) => ({
60
+ id: opaqueId(absoluteRunsRoot, suite.suiteDir),
61
+ kind: "suite",
62
+ status: normalizeStatus(suite.status),
63
+ suiteId: suite.suiteId,
64
+ startedAt: suite.startedAt,
65
+ endedAt: suite.endedAt,
66
+ concurrency: suite.concurrency,
67
+ ...(suite.profileId ? { profileId: suite.profileId } : {}),
68
+ items: suite.items.map((item) => ({
69
+ caseId: item.caseId,
70
+ canonicalCaseId: item.canonicalCaseId,
71
+ status: item.status,
72
+ exitReason: item.exitReason,
73
+ casePassed: item.casePassed,
74
+ runId: item.runDir
75
+ ? (runIdsByPath.get(resolve(suite.suiteDir, item.runDir)) ?? null)
76
+ : null,
77
+ ...(item.errorMessage ? { errorMessage: item.errorMessage } : {}),
78
+ })),
79
+ path: displayPath(absoluteRunsRoot, suite.suiteDir),
80
+ }));
81
+ const experiments = listedExperiments.map((experiment) => ({
82
+ id: opaqueId(absoluteRunsRoot, experiment.experimentDir),
83
+ kind: "experiment",
84
+ status: normalizeStatus(experiment.status),
85
+ experimentId: experiment.experimentId,
86
+ campaignId: experiment.campaignId,
87
+ mode: experiment.mode,
88
+ startedAt: experiment.startedAt,
89
+ endedAt: experiment.endedAt,
90
+ activeTimeMs: experiment.activeTimeMs,
91
+ candidateCount: experiment.candidates.length,
92
+ championCandidateId: experiment.championCandidateId ?? null,
93
+ budget: {
94
+ metricCalls: experiment.budgetUsage.metricCalls,
95
+ judgeCalls: experiment.budgetUsage.judgeCalls,
96
+ proposalCalls: experiment.budgetUsage.proposalCalls,
97
+ costUsd: experiment.budgetUsage.costUsd,
98
+ },
99
+ evaluations: experiment.evaluations.map((evaluation) => ({
100
+ candidateId: evaluation.candidateId,
101
+ profileId: evaluation.profileId,
102
+ split: evaluation.split,
103
+ passRate: evaluation.passRate,
104
+ metrics: evaluation.metrics,
105
+ metricDefinitions: evaluation.metricDefinitions ?? {},
106
+ failedCases: evaluation.failedCases,
107
+ })),
108
+ path: displayPath(absoluteRunsRoot, experiment.experimentDir),
109
+ }));
110
+ const initialPath = options.initialPath ? resolve(options.initialPath) : null;
111
+ const initialKind = options.initialKind;
112
+ const candidates = [
113
+ ...runs,
114
+ ...suites,
115
+ ...experiments,
116
+ ];
117
+ let initialEntry;
118
+ if (initialPath) {
119
+ initialEntry = candidates.find((entry) => (!initialKind || entry.kind === initialKind) &&
120
+ resolve(absoluteRunsRoot, entry.path) === initialPath);
121
+ }
122
+ else if (initialKind) {
123
+ initialEntry = candidates.find((entry) => entry.kind === initialKind);
124
+ }
125
+ return {
126
+ generatedAt: new Date().toISOString(),
127
+ runsRoot: absoluteRunsRoot,
128
+ initial: initialEntry ? { kind: initialEntry.kind, id: initialEntry.id } : null,
129
+ runs,
130
+ suites,
131
+ experiments,
132
+ };
133
+ };
134
+ const securityHeaders = {
135
+ "Content-Security-Policy": "default-src 'self'; base-uri 'none'; connect-src 'self'; form-action 'none'; frame-ancestors 'none'; img-src 'self' data:; object-src 'none'; script-src 'self'; style-src 'self'",
136
+ "Cross-Origin-Opener-Policy": "same-origin",
137
+ "Cross-Origin-Resource-Policy": "same-origin",
138
+ "Permissions-Policy": "camera=(), geolocation=(), microphone=()",
139
+ "Referrer-Policy": "no-referrer",
140
+ "X-Content-Type-Options": "nosniff",
141
+ "X-Frame-Options": "DENY",
142
+ };
143
+ const send = (request, response, status, contentType, body, cacheControl = "no-store") => {
144
+ const bytes = Buffer.isBuffer(body) ? body : Buffer.from(body);
145
+ response.writeHead(status, {
146
+ ...securityHeaders,
147
+ "Cache-Control": cacheControl,
148
+ "Content-Length": bytes.length,
149
+ "Content-Type": contentType,
150
+ });
151
+ response.end(request.method === "HEAD" ? undefined : bytes);
152
+ };
153
+ const sendJson = (request, response, status, value) => {
154
+ send(request, response, status, "application/json; charset=utf-8", JSON.stringify(value));
155
+ };
156
+ const findRunById = async (runsRoot, id) => {
157
+ const runs = await listRuns(runsRoot);
158
+ return runs.find((run) => opaqueId(runsRoot, run.runDir) === id) ?? null;
159
+ };
160
+ const findRunsById = async (runsRoot, ids) => {
161
+ const runs = await listRuns(runsRoot);
162
+ const found = ids.map((id) => runs.find((run) => opaqueId(runsRoot, run.runDir) === id) ?? null);
163
+ return found.every((run) => run !== null) ? found : null;
164
+ };
165
+ const findSuiteById = async (runsRoot, id) => {
166
+ const suites = await listSuiteRuns(runsRoot);
167
+ return suites.find((suite) => opaqueId(runsRoot, suite.suiteDir) === id) ?? null;
168
+ };
169
+ const findSuitesById = async (runsRoot, ids) => {
170
+ const suites = await listSuiteRuns(runsRoot);
171
+ const found = ids.map((id) => suites.find((suite) => opaqueId(runsRoot, suite.suiteDir) === id) ?? null);
172
+ return found.every((suite) => suite !== null)
173
+ ? found
174
+ : null;
175
+ };
176
+ const findExperimentById = async (runsRoot, id) => {
177
+ const experiments = await listExperimentRuns(runsRoot);
178
+ return (experiments.find((experiment) => opaqueId(runsRoot, experiment.experimentDir) === id) ?? null);
179
+ };
180
+ const artifactPreview = async (run, path) => {
181
+ const [detail, indexed] = await Promise.all([
182
+ loadRunDetail(run.runDir, { maxArtifacts: 2_000 }),
183
+ loadRunArtifacts(run.runDir),
184
+ ]);
185
+ return loadArtifactPreview(run.runDir, indexed, detail.artifacts, path);
186
+ };
187
+ const publicRunDetail = async (runsRoot, runDir) => ({
188
+ ...(await loadRunDetail(runDir, { maxArtifacts: 2_000 })),
189
+ runDir: displayPath(runsRoot, runDir),
190
+ });
191
+ const requiredPair = (url) => {
192
+ const before = url.searchParams.get("before");
193
+ const after = url.searchParams.get("after");
194
+ return before && after && before !== after ? [before, after] : null;
195
+ };
196
+ const isLoopbackHost = (host) => host === LOOPBACK_HOST || host?.startsWith(`${LOOPBACK_HOST}:`) === true;
197
+ const handleRunComparison = async ({ request, response, url, runsRoot, }) => {
198
+ const pair = requiredPair(url);
199
+ if (!pair) {
200
+ sendJson(request, response, 400, { error: "two distinct run ids are required" });
201
+ return;
202
+ }
203
+ const runs = await findRunsById(runsRoot, pair);
204
+ if (!runs) {
205
+ sendJson(request, response, 404, { error: "run not found" });
206
+ return;
207
+ }
208
+ const [before, after] = runs;
209
+ if (!before || !after)
210
+ throw new Error("run pair resolution failed");
211
+ const [comparison, beforeDetail, afterDetail] = await Promise.all([
212
+ compareRuns({ pathA: before.runDir, pathB: after.runDir }),
213
+ publicRunDetail(runsRoot, before.runDir),
214
+ publicRunDetail(runsRoot, after.runDir),
215
+ ]);
216
+ sendJson(request, response, 200, {
217
+ kind: "run",
218
+ comparison: {
219
+ ...comparison,
220
+ pathA: displayPath(runsRoot, before.runDir),
221
+ pathB: displayPath(runsRoot, after.runDir),
222
+ },
223
+ before: beforeDetail,
224
+ after: afterDetail,
225
+ });
226
+ };
227
+ const handleSuiteComparison = async ({ request, response, url, runsRoot, }) => {
228
+ const pair = requiredPair(url);
229
+ if (!pair) {
230
+ sendJson(request, response, 400, { error: "two distinct suite ids are required" });
231
+ return;
232
+ }
233
+ const suites = await findSuitesById(runsRoot, pair);
234
+ if (!suites) {
235
+ sendJson(request, response, 404, { error: "suite not found" });
236
+ return;
237
+ }
238
+ const [before, after] = suites;
239
+ if (!before || !after)
240
+ throw new Error("suite pair resolution failed");
241
+ const [comparison, beforeSummary, afterSummary] = await Promise.all([
242
+ compareSuiteRuns(before.suiteDir, after.suiteDir),
243
+ loadSuiteSummary(before.suiteDir),
244
+ loadSuiteSummary(after.suiteDir),
245
+ ]);
246
+ sendJson(request, response, 200, {
247
+ kind: "suite",
248
+ comparison: {
249
+ ...comparison,
250
+ pathA: displayPath(runsRoot, before.suiteDir),
251
+ pathB: displayPath(runsRoot, after.suiteDir),
252
+ },
253
+ before: beforeSummary,
254
+ after: afterSummary,
255
+ });
256
+ };
257
+ const handleArtifactComparison = async ({ request, response, url, runsRoot, }) => {
258
+ const pair = requiredPair(url);
259
+ const path = url.searchParams.get("path");
260
+ if (!pair || !path) {
261
+ sendJson(request, response, 400, {
262
+ error: "two distinct run ids and an artifact path are required",
263
+ });
264
+ return;
265
+ }
266
+ const runs = await findRunsById(runsRoot, pair);
267
+ if (!runs) {
268
+ sendJson(request, response, 404, { error: "run not found" });
269
+ return;
270
+ }
271
+ const [before, after] = runs;
272
+ if (!before || !after)
273
+ throw new Error("artifact run pair resolution failed");
274
+ const [beforePreview, afterPreview] = await Promise.all([
275
+ artifactPreview(before, path),
276
+ artifactPreview(after, path),
277
+ ]);
278
+ sendJson(request, response, 200, compareArtifactPreviews(path, beforePreview, afterPreview));
279
+ };
280
+ const handleComparisonRoute = async (context) => {
281
+ if (context.url.pathname === "/api/compare/runs") {
282
+ await handleRunComparison(context);
283
+ return true;
284
+ }
285
+ if (context.url.pathname === "/api/compare/suites") {
286
+ await handleSuiteComparison(context);
287
+ return true;
288
+ }
289
+ if (context.url.pathname === "/api/compare/artifacts") {
290
+ await handleArtifactComparison(context);
291
+ return true;
292
+ }
293
+ return false;
294
+ };
295
+ const handleArtifactRoute = async ({ request, response, url, runsRoot, }) => {
296
+ if (url.pathname !== "/api/artifact")
297
+ return false;
298
+ const runId = url.searchParams.get("run");
299
+ const path = url.searchParams.get("path");
300
+ if (!runId || !path) {
301
+ sendJson(request, response, 400, { error: "a run id and artifact path are required" });
302
+ return true;
303
+ }
304
+ const run = await findRunById(runsRoot, runId);
305
+ if (!run) {
306
+ sendJson(request, response, 404, { error: "run not found" });
307
+ return true;
308
+ }
309
+ const preview = await artifactPreview(run, path);
310
+ sendJson(request, response, preview.exists ? 200 : 404, preview);
311
+ return true;
312
+ };
313
+ const experimentDetail = async (runsRoot, experiment) => {
314
+ const [candidateResult, decisionResult] = await Promise.allSettled([
315
+ loadExperimentCandidates(experiment.experimentDir),
316
+ loadVerifiedExperimentDecisionSnapshot(experiment.experimentDir),
317
+ ]);
318
+ const integrityErrors = [candidateResult, decisionResult].flatMap((result) => result.status === "rejected"
319
+ ? [result.reason instanceof Error ? result.reason.message : String(result.reason)]
320
+ : []);
321
+ return {
322
+ experiment: {
323
+ experimentId: experiment.experimentId,
324
+ campaignId: experiment.campaignId,
325
+ mode: experiment.mode,
326
+ evaluationKind: experiment.evaluationKind,
327
+ status: experiment.status,
328
+ startedAt: experiment.startedAt,
329
+ endedAt: experiment.endedAt,
330
+ activeTimeMs: experiment.activeTimeMs,
331
+ championCandidateId: experiment.championCandidateId ?? null,
332
+ errorMessage: experiment.errorMessage ?? null,
333
+ selection: experiment.selection ?? null,
334
+ budgetUsage: experiment.budgetUsage,
335
+ evaluations: experiment.evaluations.map((evaluation) => ({
336
+ candidateId: evaluation.candidateId,
337
+ profileId: evaluation.profileId,
338
+ split: evaluation.split,
339
+ repetitions: evaluation.repetitions,
340
+ passRate: evaluation.passRate,
341
+ casePassRates: evaluation.casePassRates,
342
+ metrics: evaluation.metrics,
343
+ metricDefinitions: evaluation.metricDefinitions ?? {},
344
+ costUsd: evaluation.costUsd ?? null,
345
+ failedCases: evaluation.failedCases,
346
+ })),
347
+ },
348
+ candidates: candidateResult.status === "fulfilled"
349
+ ? candidateResult.value.map((candidate) => ({
350
+ id: candidate.id,
351
+ parentIds: candidate.parentIds,
352
+ createdAt: candidate.createdAt,
353
+ proposer: candidate.proposer,
354
+ sourceBytes: candidate.sourceBytes,
355
+ rationale: candidate.rationale ?? null,
356
+ components: Object.keys(candidate.components).sort(),
357
+ }))
358
+ : [],
359
+ decision: decisionResult.status === "fulfilled"
360
+ ? {
361
+ ...decisionResult.value.report,
362
+ experimentDir: displayPath(runsRoot, experiment.experimentDir),
363
+ }
364
+ : null,
365
+ integrity: {
366
+ verified: integrityErrors.length === 0,
367
+ errors: integrityErrors,
368
+ },
369
+ };
370
+ };
371
+ const handleDetailRoute = async ({ request, response, url, runsRoot, }) => {
372
+ if (url.pathname.startsWith("/api/suites/")) {
373
+ const suite = await findSuiteById(runsRoot, url.pathname.slice("/api/suites/".length));
374
+ if (!suite)
375
+ sendJson(request, response, 404, { error: "suite not found" });
376
+ else
377
+ sendJson(request, response, 200, {
378
+ suite: {
379
+ ...suite,
380
+ suiteDir: displayPath(runsRoot, suite.suiteDir),
381
+ },
382
+ summary: await loadSuiteSummary(suite.suiteDir),
383
+ });
384
+ return true;
385
+ }
386
+ if (url.pathname.startsWith("/api/experiments/")) {
387
+ const experiment = await findExperimentById(runsRoot, url.pathname.slice("/api/experiments/".length));
388
+ if (!experiment)
389
+ sendJson(request, response, 404, { error: "experiment not found" });
390
+ else
391
+ sendJson(request, response, 200, await experimentDetail(runsRoot, experiment));
392
+ return true;
393
+ }
394
+ if (url.pathname.startsWith("/api/runs/")) {
395
+ const run = await findRunById(runsRoot, url.pathname.slice("/api/runs/".length));
396
+ if (!run)
397
+ sendJson(request, response, 404, { error: "run not found" });
398
+ else
399
+ sendJson(request, response, 200, await publicRunDetail(runsRoot, run.runDir));
400
+ return true;
401
+ }
402
+ return false;
403
+ };
404
+ const requestHandler = (assets, runsRoot, options) => async (request, response) => {
405
+ if (!isLoopbackHost(request.headers.host)) {
406
+ sendJson(request, response, 421, { error: "untrusted host" });
407
+ return;
408
+ }
409
+ if (request.method !== "GET" && request.method !== "HEAD") {
410
+ sendJson(request, response, 405, { error: "method not allowed" });
411
+ return;
412
+ }
413
+ const url = new URL(request.url ?? "/", `http://${LOOPBACK_HOST}`);
414
+ if (url.pathname === "/" || url.pathname === "/index.html") {
415
+ send(request, response, 200, "text/html; charset=utf-8", assets.html);
416
+ return;
417
+ }
418
+ const asset = assets.files.get(url.pathname);
419
+ if (asset) {
420
+ send(request, response, 200, asset.contentType, asset.body, "no-cache");
421
+ return;
422
+ }
423
+ if (url.pathname === "/api/snapshot") {
424
+ sendJson(request, response, 200, await buildSnapshot(runsRoot, options));
425
+ return;
426
+ }
427
+ const context = { request, response, url, runsRoot };
428
+ if (await handleComparisonRoute(context))
429
+ return;
430
+ if (await handleArtifactRoute(context))
431
+ return;
432
+ if (await handleDetailRoute(context))
433
+ return;
434
+ if (url.pathname === "/health") {
435
+ sendJson(request, response, 200, { ok: true });
436
+ return;
437
+ }
438
+ sendJson(request, response, 404, { error: "not found" });
439
+ };
440
+ const loadAssets = async () => {
441
+ const htmlPath = resolve(ASSET_ROOT, "index.html");
442
+ const definitions = [
443
+ ["/assets/app.css", "app.css", "text/css; charset=utf-8"],
444
+ ["/assets/app.js", "app.js", "text/javascript; charset=utf-8"],
445
+ ["/assets/artifact-view.js", "artifact-view.js", "text/javascript; charset=utf-8"],
446
+ ["/assets/charts.js", "charts.js", "text/javascript; charset=utf-8"],
447
+ ["/assets/detail.js", "detail.js", "text/javascript; charset=utf-8"],
448
+ ["/assets/format.js", "format.js", "text/javascript; charset=utf-8"],
449
+ ];
450
+ const paths = [htmlPath, ...definitions.map((definition) => resolve(ASSET_ROOT, definition[1]))];
451
+ for (const path of paths) {
452
+ if (!existsSync(path))
453
+ throw new Error(`Lux preview asset is missing: ${basename(path)}`);
454
+ }
455
+ const [html, ...bodies] = await Promise.all(paths.map((path) => readFile(path)));
456
+ if (!html)
457
+ throw new Error("Lux preview index is empty");
458
+ const files = new Map(definitions.map(([url, , contentType], index) => {
459
+ const body = bodies[index];
460
+ if (!body)
461
+ throw new Error(`Lux preview asset is empty: ${url}`);
462
+ return [url, { body, contentType }];
463
+ }));
464
+ return { html, files };
465
+ };
466
+ const listen = (server, port) => new Promise((resolveListen, reject) => {
467
+ const onError = (error) => {
468
+ server.off("listening", onListening);
469
+ reject(error);
470
+ };
471
+ const onListening = () => {
472
+ server.off("error", onError);
473
+ resolveListen();
474
+ };
475
+ server.once("error", onError);
476
+ server.once("listening", onListening);
477
+ server.listen(port, LOOPBACK_HOST);
478
+ });
479
+ export const startPreviewServer = async (options) => {
480
+ const runsRoot = resolve(options.runsRoot);
481
+ const assets = await loadAssets();
482
+ const server = createServer((request, response) => {
483
+ void requestHandler(assets, runsRoot, options)(request, response).catch((error) => {
484
+ const message = error instanceof Error ? error.message : String(error);
485
+ if (!response.headersSent)
486
+ sendJson(request, response, 500, { error: message });
487
+ else
488
+ response.destroy();
489
+ });
490
+ });
491
+ await listen(server, options.port ?? 0);
492
+ const address = server.address();
493
+ if (!address || typeof address === "string") {
494
+ server.close();
495
+ throw new Error("Lux preview server did not receive a TCP address");
496
+ }
497
+ let closePromise = null;
498
+ const close = () => {
499
+ closePromise ??= new Promise((resolveClose, reject) => {
500
+ server.close((error) => {
501
+ options.signal?.removeEventListener("abort", onAbort);
502
+ if (error)
503
+ reject(error);
504
+ else
505
+ resolveClose();
506
+ });
507
+ });
508
+ return closePromise;
509
+ };
510
+ const onAbort = () => {
511
+ void close();
512
+ };
513
+ if (options.signal?.aborted)
514
+ onAbort();
515
+ else
516
+ options.signal?.addEventListener("abort", onAbort, { once: true });
517
+ const closed = new Promise((resolveClosed) => {
518
+ server.once("close", resolveClosed);
519
+ });
520
+ return {
521
+ url: `http://${LOOPBACK_HOST}:${address.port}`,
522
+ closed,
523
+ close,
524
+ };
525
+ };
526
+ export const openPreviewUrl = async (url) => {
527
+ let launcher = { command: "xdg-open", args: [url] };
528
+ if (process.platform === "darwin") {
529
+ launcher = { command: "open", args: [url] };
530
+ }
531
+ else if (process.platform === "win32") {
532
+ launcher = { command: "cmd.exe", args: ["/d", "/s", "/c", "start", "", url] };
533
+ }
534
+ const result = await exec(launcher.command, launcher.args, {
535
+ timeoutMs: 5_000,
536
+ maxBuffer: 2_000,
537
+ });
538
+ if (result.exitCode !== 0 || result.timedOut) {
539
+ throw new Error(result.stderr.trim() || `browser launcher exited ${result.exitCode ?? "early"}`);
540
+ }
541
+ };
542
+ //# sourceMappingURL=server.js.map