reeval 0.16.1 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/dist/{adapter-CRKYPkRt.js → adapter-CqUt4A0w.js} +3 -3
- package/dist/{adapter-CRKYPkRt.js.map → adapter-CqUt4A0w.js.map} +1 -1
- package/dist/{agent-BgH4-kFc.js → agent-BtAbRTFq.js} +4 -4
- package/dist/{agent-BgH4-kFc.js.map → agent-BtAbRTFq.js.map} +1 -1
- package/dist/{app-files-BMVBr079.js → app-files-CDttHPOz.js} +3 -3
- package/dist/app-files-CDttHPOz.js.map +1 -0
- package/dist/assemble-Bb7zqpRw.js +1 -0
- package/dist/{assemble-BVbI6NW-.js → assemble-J9rkE29m.js} +29 -12
- package/dist/{assemble-BVbI6NW-.js.map → assemble-J9rkE29m.js.map} +1 -1
- package/dist/{attempt-host-CIxjs2Be.js → attempt-host-DDedP7Qv.js} +9 -7
- package/dist/attempt-host-DDedP7Qv.js.map +1 -0
- package/dist/capture-Bvc4FtWT.js +15 -0
- package/dist/capture-Bvc4FtWT.js.map +1 -0
- package/dist/capture-D68TiQQy.js +1 -0
- package/dist/{capture-iQ6kYJV0.js → capture-DheNqeYS.js} +550 -84
- package/dist/capture-DheNqeYS.js.map +1 -0
- package/dist/{cli-1YQU-66F.js → cli-KTHjNFoo.js} +279 -61
- package/dist/cli-KTHjNFoo.js.map +1 -0
- package/dist/cli.js +2 -2
- package/dist/{colors-QV9dFVhN.js → colors-Y6O3mtl_.js} +20 -2
- package/dist/colors-Y6O3mtl_.js.map +1 -0
- package/dist/{command-C-HeGlap.js → command-1FBECMs-.js} +13 -13
- package/dist/{command-C-HeGlap.js.map → command-1FBECMs-.js.map} +1 -1
- package/dist/{command-Cr1zjRvl.js → command-Ce03LLtg.js} +12 -12
- package/dist/{command-Cr1zjRvl.js.map → command-Ce03LLtg.js.map} +1 -1
- package/dist/{command-8_Cg5v6b.js → command-CztRuwUM.js} +10 -10
- package/dist/{command-8_Cg5v6b.js.map → command-CztRuwUM.js.map} +1 -1
- package/dist/{command-BlYCAqu-.js → command-nNN0mx65.js} +7 -7
- package/dist/{command-BlYCAqu-.js.map → command-nNN0mx65.js.map} +1 -1
- package/dist/{commands-BvTNZ2-b.js → commands-DP13JX9i.js} +18 -11
- package/dist/commands-DP13JX9i.js.map +1 -0
- package/dist/{commands-Bj9NbmsO.js → commands-ZwQUezI1.js} +1 -1
- package/dist/{config-CneBZB84.js → config-BjjDryd5.js} +55 -33
- package/dist/config-BjjDryd5.js.map +1 -0
- package/dist/{contrasts-lhFsekco.js → contrasts-DSsRZpR8.js} +2 -2
- package/dist/{contrasts-lhFsekco.js.map → contrasts-DSsRZpR8.js.map} +1 -1
- package/dist/cursor-catalog-D7bFLEAD.js +143 -0
- package/dist/cursor-catalog-D7bFLEAD.js.map +1 -0
- package/dist/{db-Cnh3jIv_.js → db-B9Ityuit.js} +4 -4
- package/dist/{db-Cnh3jIv_.js.map → db-B9Ityuit.js.map} +1 -1
- package/dist/db-Bk6LWwza.js +2 -0
- package/dist/default-effort-DK8gospa.js +91 -0
- package/dist/default-effort-DK8gospa.js.map +1 -0
- package/dist/default-effort-DmXHpqo9.js +1 -0
- package/dist/{docker-DCAtFMo9.js → docker-BLCNfUie.js} +1 -1
- package/dist/{docker-Cqq03H72.js → docker-SKpYOlGi.js} +4 -4
- package/dist/{docker-Cqq03H72.js.map → docker-SKpYOlGi.js.map} +1 -1
- package/dist/{docker-BihzJwbV.js → docker-hwp3EucJ.js} +2 -2
- package/dist/{docker-BihzJwbV.js.map → docker-hwp3EucJ.js.map} +1 -1
- package/dist/{doctor-Dl4vMeqt.js → doctor-CT0Sgjng.js} +16 -16
- package/dist/{doctor-Dl4vMeqt.js.map → doctor-CT0Sgjng.js.map} +1 -1
- package/dist/{environment-Cf5HMjib.js → environment-CZdercoj.js} +2 -2
- package/dist/{environment-Cf5HMjib.js.map → environment-CZdercoj.js.map} +1 -1
- package/dist/{errors-CHebohjc.js → errors-BZVKVKYd.js} +7 -2
- package/dist/errors-BZVKVKYd.js.map +1 -0
- package/dist/{eval-source-CAE4y2Sr.js → eval-source-nZD7-FSz.js} +4 -4
- package/dist/{eval-source-CAE4y2Sr.js.map → eval-source-nZD7-FSz.js.map} +1 -1
- package/dist/{evaluate-D35T51AC.d.ts → evaluate-CNi0lZ7n.d.ts} +2 -2
- package/dist/{evaluate-CUtgyr43.js → evaluate-fhC1PCd_.js} +22 -19
- package/dist/evaluate-fhC1PCd_.js.map +1 -0
- package/dist/{files-CNiJ_fZf.js → files-BGy05Dlr.js} +4 -4
- package/dist/{files-CNiJ_fZf.js.map → files-BGy05Dlr.js.map} +1 -1
- package/dist/{files-BRViE7m-.js → files-BIGxpL08.js} +9 -7
- package/dist/{files-BRViE7m-.js.map → files-BIGxpL08.js.map} +1 -1
- package/dist/files-C2RC7K4m.js +1 -0
- package/dist/{files-BSqA2sZE.js → files-I1i6Xyh1.js} +4 -4
- package/dist/{files-BSqA2sZE.js.map → files-I1i6Xyh1.js.map} +1 -1
- package/dist/files-dJmrfmOM.js +1 -0
- package/dist/gateway.d.ts +1 -1
- package/dist/{git-UNxT_3z0.js → git-DR02tHtU.js} +2 -2
- package/dist/{git-UNxT_3z0.js.map → git-DR02tHtU.js.map} +1 -1
- package/dist/{harness-3NVyTSGK.js → harness-ylJLvrbp.js} +39 -5
- package/dist/{harness-3NVyTSGK.js.map → harness-ylJLvrbp.js.map} +1 -1
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +1 -1
- package/dist/{images-8A_LzVfw.js → images---X8Wu9d.js} +8 -8
- package/dist/{images-8A_LzVfw.js.map → images---X8Wu9d.js.map} +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.js +4 -4
- package/dist/init-BNTXrtMO.js +1 -0
- package/dist/{init-sFBgODhu.js → init-CA95ZnkV.js} +4 -4
- package/dist/{init-sFBgODhu.js.map → init-CA95ZnkV.js.map} +1 -1
- package/dist/{invocations-C9ejlOYl.js → invocations-BdoROAfb.js} +2 -2
- package/dist/{invocations-C9ejlOYl.js.map → invocations-BdoROAfb.js.map} +1 -1
- package/dist/{judge-Bg4v4e_K.js → judge-Dp7FPJ1P.js} +3 -3
- package/dist/{judge-Bg4v4e_K.js.map → judge-Dp7FPJ1P.js.map} +1 -1
- package/dist/judge.d.ts +1 -1
- package/dist/judge.js +1 -1
- package/dist/{live-DeMvnDD5.js → live-CBFkdK1K.js} +2 -2
- package/dist/{live-DeMvnDD5.js.map → live-CBFkdK1K.js.map} +1 -1
- package/dist/{matchers-BKPuaXlj.js → matchers-Cv74mJRJ.js} +30 -1
- package/dist/matchers-Cv74mJRJ.js.map +1 -0
- package/dist/{model-2rBZrdZA.js → model-6dfKFkQd.js} +4 -4
- package/dist/{model-2rBZrdZA.js.map → model-6dfKFkQd.js.map} +1 -1
- package/dist/{model-Bz7-j71_.js → model-Be7fPvgi.js} +2 -2
- package/dist/{model-Bz7-j71_.js.map → model-Be7fPvgi.js.map} +1 -1
- package/dist/{model-DkPwypN4.js → model-CN4ccjNz.js} +1 -1
- package/dist/model-C_5TspZS.js +1 -0
- package/dist/{model-3MJtpho8.js → model-DkJVmVd2.js} +3 -3
- package/dist/{model-3MJtpho8.js.map → model-DkJVmVd2.js.map} +1 -1
- package/dist/{node-fP-H2uxn.js → node-D_Zkwhq2.js} +2 -2
- package/dist/{node-fP-H2uxn.js.map → node-D_Zkwhq2.js.map} +1 -1
- package/dist/{opencode-providers-Bz0l7OZI.js → opencode-providers-DPgdqRfg.js} +26 -2
- package/dist/{opencode-providers-Bz0l7OZI.js.map → opencode-providers-DPgdqRfg.js.map} +1 -1
- package/dist/{openrouter-models-Bo8PZ4Ew.js → openrouter-models-CR00FWAa.js} +2 -2
- package/dist/{openrouter-models-Bo8PZ4Ew.js.map → openrouter-models-CR00FWAa.js.map} +1 -1
- package/dist/{patch-6T9XAipm.js → patch-BJNdOZsf.js} +2 -2
- package/dist/{patch-6T9XAipm.js.map → patch-BJNdOZsf.js.map} +1 -1
- package/dist/{plan-Dw2BjafJ.js → plan-C1UpGZTk.js} +60 -5
- package/dist/plan-C1UpGZTk.js.map +1 -0
- package/dist/{plugins-ngQEJBjJ.js → plugins-Cx6ReJWE.js} +2 -2
- package/dist/{plugins-ngQEJBjJ.js.map → plugins-Cx6ReJWE.js.map} +1 -1
- package/dist/{preflight-CDRpog9o.js → preflight-BZ3L7P3a.js} +3 -3
- package/dist/{preflight-CDRpog9o.js.map → preflight-BZ3L7P3a.js.map} +1 -1
- package/dist/{preflight-BYXkweNN.js → preflight-CUooKgtT.js} +1 -1
- package/dist/{prepare-PkARUGoF.js → prepare-BbBoTeDj.js} +7 -7
- package/dist/{prepare-PkARUGoF.js.map → prepare-BbBoTeDj.js.map} +1 -1
- package/dist/{prepare-B3btUlT6.js → prepare-CEZaEwaq.js} +2 -2
- package/dist/{provenance-7Hzg88f4.js → provenance-BWvTIlQM.js} +2 -2
- package/dist/{provenance-7Hzg88f4.js.map → provenance-BWvTIlQM.js.map} +1 -1
- package/dist/{providers-PKoJtGK0.js → providers-B3yqakc7.js} +5 -5
- package/dist/{providers-PKoJtGK0.js.map → providers-B3yqakc7.js.map} +1 -1
- package/dist/{providers-DDNMbv1T.js → providers-DdyZW_ru.js} +1 -1
- package/dist/query-BkwQ0W-c.js +1 -0
- package/dist/{query-nBXrgEwl.js → query-CZcqpOI9.js} +2 -2
- package/dist/{query-nBXrgEwl.js.map → query-CZcqpOI9.js.map} +1 -1
- package/dist/{questions-CkAwePPR.js → questions-CFU7-crW.js} +8 -6
- package/dist/{questions-CkAwePPR.js.map → questions-CFU7-crW.js.map} +1 -1
- package/dist/{record-DZBCjuwm.js → record-Bu1Xi6MQ.js} +8 -4
- package/dist/record-Bu1Xi6MQ.js.map +1 -0
- package/dist/{remarks-Bt0zwiQB.js → remarks-A3j-SkJ_.js} +7 -7
- package/dist/{remarks-Bt0zwiQB.js.map → remarks-A3j-SkJ_.js.map} +1 -1
- package/dist/{remarks-IFFe_oty.js → remarks-Dj_x9l5n.js} +2 -2
- package/dist/{remarks-IFFe_oty.js.map → remarks-Dj_x9l5n.js.map} +1 -1
- package/dist/{remote-DfJYiP-R.js → remote-EIFHdMd8.js} +5 -5
- package/dist/{remote-DfJYiP-R.js.map → remote-EIFHdMd8.js.map} +1 -1
- package/dist/{resolve-D_cLa4tW.js → resolve-8H5rz8mi.js} +5 -5
- package/dist/{resolve-D_cLa4tW.js.map → resolve-8H5rz8mi.js.map} +1 -1
- package/dist/resolve-Tm9pX7Hv.js +1 -0
- package/dist/{results-DrKJuIQF.js → results-E7JdVjq2.js} +6 -6
- package/dist/{results-DrKJuIQF.js.map → results-E7JdVjq2.js.map} +1 -1
- package/dist/{resume-BmIM52MJ.js → resume-Blu4yIcq.js} +4 -4
- package/dist/{resume-BmIM52MJ.js.map → resume-Blu4yIcq.js.map} +1 -1
- package/dist/{runtime-CZVpkr04.js → runtime-CNbsMJQ7.js} +3 -3
- package/dist/{runtime-CZVpkr04.js.map → runtime-CNbsMJQ7.js.map} +1 -1
- package/dist/{sandbox-Cmi6IQML.js → sandbox-RButGfIE.js} +2 -2
- package/dist/{sandbox-Cmi6IQML.js.map → sandbox-RButGfIE.js.map} +1 -1
- package/dist/sandbox.d.ts +1 -1
- package/dist/sandbox.js +1 -1
- package/dist/server-Dqrq-Sia.js +1 -0
- package/dist/{server-DS8BGhGU.js → server-XgCYs_MF.js} +9 -9
- package/dist/{server-DS8BGhGU.js.map → server-XgCYs_MF.js.map} +1 -1
- package/dist/{source-DcXv4de-.js → source-BOkbJCD2.js} +2 -2
- package/dist/{source-DcXv4de-.js.map → source-BOkbJCD2.js.map} +1 -1
- package/dist/source-DooSTtyz.js +1 -0
- package/dist/{src-h5uDlk3m.js → src-1M0srjji.js} +1 -1
- package/dist/{src-C0ySiej5.js → src-BJCKWacl.js} +11 -10
- package/dist/src-BJCKWacl.js.map +1 -0
- package/dist/{src-Dk2Na0b-.js → src-BZlhaDhE.js} +1 -1
- package/dist/{src-BO8AYqJ5.js → src-BkhEPVJZ.js} +12 -3
- package/dist/{src-BO8AYqJ5.js.map → src-BkhEPVJZ.js.map} +1 -1
- package/dist/{src-OESRtvOi.js → src-Bp6X4193.js} +1 -1
- package/dist/{src-BYLM3hEz.js → src-C2Japg_I.js} +21 -10
- package/dist/{src-BYLM3hEz.js.map → src-C2Japg_I.js.map} +1 -1
- package/dist/src-C5q3_fRV.js +3 -0
- package/dist/src-C9EHSYyP.js +2 -0
- package/dist/src-CJdpsrXi.js +2 -0
- package/dist/{src-1lpTocbd.js → src-D1ET6oPL.js} +3 -27
- package/dist/{src-1lpTocbd.js.map → src-D1ET6oPL.js.map} +1 -1
- package/dist/{src-BkiComGh.js → src-D4CZjMQ4.js} +1 -1
- package/dist/{src-Cp-2Hdib.js → src-GkJ-1Rdy.js} +1 -1
- package/dist/{src-BTqJbvj6.js → src-OOKE-5GA.js} +1 -1
- package/dist/state-BCyNaz13.js +1 -0
- package/dist/{state-C_kdhp5v.js → state-D6-tvqtp.js} +7 -7
- package/dist/{state-C_kdhp5v.js.map → state-D6-tvqtp.js.map} +1 -1
- package/dist/{views-Ca-rTixp.js → suite-BiWajSlA.js} +2 -2
- package/dist/{suite-DieLXvCT.js → suite-DYI1k2Ie.js} +9 -3
- package/dist/{suite-DieLXvCT.js.map → suite-DYI1k2Ie.js.map} +1 -1
- package/dist/{summary-CSzyBVsF.js → summary-CN2aqAUz.js} +24 -8
- package/dist/{summary-CSzyBVsF.js.map → summary-CN2aqAUz.js.map} +1 -1
- package/dist/testing.d.ts +46 -2
- package/dist/testing.js +4 -4
- package/dist/{types-DVvW66ci.d.ts → types-DDeCnNmp.d.ts} +116 -14
- package/dist/view/index.d.ts +19 -2
- package/dist/view/index.js +7 -6
- package/dist/views-7bNY17Z6.js +2 -0
- package/dist/{views-B9STsLB4.js → views-Bd-H71_t.js} +5 -5
- package/dist/{views-B9STsLB4.js.map → views-Bd-H71_t.js.map} +1 -1
- package/dist/{worker-entry-C5bLCv6s.js → worker-entry-BIHJqE_z.js} +4 -4
- package/dist/{worker-entry-C5bLCv6s.js.map → worker-entry-BIHJqE_z.js.map} +1 -1
- package/dist/workspace-CxwHv8mG.js +1 -0
- package/dist/{workspace-CBuI9Uds.js → workspace-Sy5g8zW9.js} +4 -4
- package/dist/{workspace-CBuI9Uds.js.map → workspace-Sy5g8zW9.js.map} +1 -1
- package/package.json +1 -1
- package/dist/app-files-BMVBr079.js.map +0 -1
- package/dist/assemble-SiHa4__F.js +0 -1
- package/dist/attempt-host-CIxjs2Be.js.map +0 -1
- package/dist/capture-iQ6kYJV0.js.map +0 -1
- package/dist/capture-px7Ey95_.js +0 -1
- package/dist/cli-1YQU-66F.js.map +0 -1
- package/dist/colors-QV9dFVhN.js.map +0 -1
- package/dist/commands-BvTNZ2-b.js.map +0 -1
- package/dist/config-CneBZB84.js.map +0 -1
- package/dist/db-BnXyamuj.js +0 -2
- package/dist/errors-CHebohjc.js.map +0 -1
- package/dist/evaluate-CUtgyr43.js.map +0 -1
- package/dist/files-BEnUJW1e.js +0 -1
- package/dist/files-Dts7EY3H.js +0 -1
- package/dist/init-okoALIah.js +0 -1
- package/dist/matchers-BKPuaXlj.js.map +0 -1
- package/dist/model-bREXVXwT.js +0 -1
- package/dist/plan-Dw2BjafJ.js.map +0 -1
- package/dist/query-Bt6vLJ3m.js +0 -1
- package/dist/record-DZBCjuwm.js.map +0 -1
- package/dist/resolve-CT4XZIfV.js +0 -1
- package/dist/server-CKJOnIB0.js +0 -1
- package/dist/source-CgUqpumI.js +0 -1
- package/dist/src-BvgeZ4tS.js +0 -2
- package/dist/src-C0ySiej5.js.map +0 -1
- package/dist/src-CgJrz5p0.js +0 -3
- package/dist/src-DMo2eCOJ.js +0 -2
- package/dist/state-C97udoh3.js +0 -1
- package/dist/suite-ByT1lsdD.js +0 -2
- package/dist/workspace-8uHtBSve.js +0 -1
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { n as isOneOf } from "./object-BkXGPKWY.js";
|
|
2
2
|
import { n as UsageError } from "./errors-B6BSMs03.js";
|
|
3
3
|
import { c as jsonValueSchema, h as parseDuration, i as durationSchema, m as TIMER_LIMIT, n as dataProblem, p as MAX_TIMER_MS } from "./shared-B_lvGqWz.js";
|
|
4
|
-
import {
|
|
4
|
+
import { x as gatewayNameSchema } from "./harness-ylJLvrbp.js";
|
|
5
5
|
import { l as sha256 } from "./ids-Bp6ut7ZD.js";
|
|
6
|
-
import {
|
|
6
|
+
import { At as captureWindowSchema, Ft as judgeFields, It as judgeModelNameSchema, Nt as fakeJudgeDataSchema, Rt as sharedInputFields, b as resolveModelGateway, ct as parseProbe, lt as probeScript, st as awaitListening, v as gatewayScope, zt as turnsSchema } from "./config-BjjDryd5.js";
|
|
7
7
|
import { y as vertexSettingsIn } from "./vertex-DypYjx71.js";
|
|
8
|
-
import { m as redactSecrets } from "./redact-DVIaahLv.js";
|
|
8
|
+
import { d as redactJson, m as redactSecrets } from "./redact-DVIaahLv.js";
|
|
9
9
|
import { a as plural, i as formatDuration, n as clip } from "./text-DTigcA64.js";
|
|
10
10
|
import { s as cacheDir } from "./root-Dlff-zp8.js";
|
|
11
|
-
import { pt as shellQuote } from "./src-
|
|
11
|
+
import { pt as shellQuote } from "./src-BJCKWacl.js";
|
|
12
12
|
import { t as InfraError } from "./types-C5vI3g1C.js";
|
|
13
|
-
import { r as getRunContext, s as SUBJECT } from "./runtime-
|
|
13
|
+
import { r as getRunContext, s as SUBJECT } from "./runtime-CNbsMJQ7.js";
|
|
14
14
|
import { i as debugTrace, r as debugLog } from "./attempt-CpbZ9arV.js";
|
|
15
|
-
import { r as openRouterFallbacks } from "./openrouter-models-
|
|
16
|
-
import { i as hostModel } from "./model-
|
|
15
|
+
import { r as openRouterFallbacks } from "./openrouter-models-CR00FWAa.js";
|
|
16
|
+
import { i as hostModel } from "./model-6dfKFkQd.js";
|
|
17
17
|
import { t as addUsage } from "./usage-BNY1ABrU.js";
|
|
18
|
-
import { t as untraced } from "./docker-
|
|
18
|
+
import { t as untraced } from "./docker-hwp3EucJ.js";
|
|
19
|
+
import { n as pageLines } from "./capture-Bvc4FtWT.js";
|
|
19
20
|
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
20
21
|
import { homedir, tmpdir } from "node:os";
|
|
21
22
|
import { join, posix } from "node:path";
|
|
@@ -177,6 +178,33 @@ const assertionRecordSchema = z.strictObject({
|
|
|
177
178
|
durationMs: z.number().optional()
|
|
178
179
|
});
|
|
179
180
|
const turnIndex = z.number().int("must be a turn index, from 0").min(0, "must be a turn index, from 0").describe("The turn's index, from 0.");
|
|
181
|
+
const captureConsoleMessageSchema = z.strictObject({
|
|
182
|
+
level: z.enum([
|
|
183
|
+
"error",
|
|
184
|
+
"warning",
|
|
185
|
+
"info",
|
|
186
|
+
"log",
|
|
187
|
+
"debug"
|
|
188
|
+
]),
|
|
189
|
+
text: z.string(),
|
|
190
|
+
source: z.string(),
|
|
191
|
+
url: z.string().optional()
|
|
192
|
+
});
|
|
193
|
+
const captureFailedRequestSchema = z.strictObject({
|
|
194
|
+
method: z.string(),
|
|
195
|
+
url: z.string(),
|
|
196
|
+
status: z.number().optional(),
|
|
197
|
+
error: z.string().optional()
|
|
198
|
+
});
|
|
199
|
+
const capturePageFields = {
|
|
200
|
+
status: z.number().optional(),
|
|
201
|
+
finalUrl: z.string(),
|
|
202
|
+
console: z.array(captureConsoleMessageSchema),
|
|
203
|
+
errors: z.array(z.string()),
|
|
204
|
+
failedRequests: z.array(captureFailedRequestSchema),
|
|
205
|
+
dropped: z.number().optional()
|
|
206
|
+
};
|
|
207
|
+
z.strictObject(capturePageFields);
|
|
180
208
|
const captureSchema = z.strictObject({
|
|
181
209
|
name: z.string(),
|
|
182
210
|
port: z.number(),
|
|
@@ -186,7 +214,8 @@ const captureSchema = z.strictObject({
|
|
|
186
214
|
path: z.string(),
|
|
187
215
|
sha256: z.string(),
|
|
188
216
|
bytes: z.number()
|
|
189
|
-
})
|
|
217
|
+
}),
|
|
218
|
+
...capturePageFields
|
|
190
219
|
});
|
|
191
220
|
const judgeArtifactRefSchema = z.strictObject({
|
|
192
221
|
name: z.string(),
|
|
@@ -540,6 +569,170 @@ function fakeInstructions(steps) {
|
|
|
540
569
|
function fakeInstructionSteps(value) {
|
|
541
570
|
if (typeof value === "object" && value !== null && FAKE_INSTRUCTIONS in value) return value[FAKE_INSTRUCTIONS];
|
|
542
571
|
}
|
|
572
|
+
const TEXT_MAX = 2e3;
|
|
573
|
+
const params = (msg) => msg.params ?? msg;
|
|
574
|
+
function argText(arg) {
|
|
575
|
+
if (arg.type === "string") return String(arg.value);
|
|
576
|
+
if (arg.unserializableValue !== void 0) return arg.unserializableValue;
|
|
577
|
+
if (arg.description !== void 0) return arg.description;
|
|
578
|
+
if (arg.value !== void 0) return JSON.stringify(arg.value);
|
|
579
|
+
return String(arg.type ?? "");
|
|
580
|
+
}
|
|
581
|
+
/** `console.*` call types that print nothing of their own. */
|
|
582
|
+
const SILENT = /* @__PURE__ */ new Set([
|
|
583
|
+
"clear",
|
|
584
|
+
"endGroup",
|
|
585
|
+
"profile",
|
|
586
|
+
"profileEnd"
|
|
587
|
+
]);
|
|
588
|
+
function consoleLevel(type) {
|
|
589
|
+
if (type === "error" || type === "assert") return "error";
|
|
590
|
+
if (type === "warning") return "warning";
|
|
591
|
+
if (type === "info") return "info";
|
|
592
|
+
if (type === "debug") return "debug";
|
|
593
|
+
return "log";
|
|
594
|
+
}
|
|
595
|
+
function logLevel(level) {
|
|
596
|
+
if (level === "error" || level === "warning" || level === "info") return level;
|
|
597
|
+
return "debug";
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Collects what the tab reports from the moment it's called: its console, its page errors
|
|
601
|
+
* (uncaught exceptions and unhandled rejections), its failed requests and its main frame's
|
|
602
|
+
* document status. Needs `Runtime.enable`, `Log.enable` and `Network.enable` sent after it, and
|
|
603
|
+
* the main frame's id once it's known.
|
|
604
|
+
*/
|
|
605
|
+
function watchPage(cdp) {
|
|
606
|
+
const consoleLines = [];
|
|
607
|
+
const errors = [];
|
|
608
|
+
const droppedErrors = /* @__PURE__ */ new Set();
|
|
609
|
+
const failed = [];
|
|
610
|
+
const requests = /* @__PURE__ */ new Map();
|
|
611
|
+
let frame;
|
|
612
|
+
let status;
|
|
613
|
+
let frameUrl = "";
|
|
614
|
+
let dropped = 0;
|
|
615
|
+
const keep = (list, item, count = list.length) => {
|
|
616
|
+
if (count < 100) list.push(item);
|
|
617
|
+
else dropped++;
|
|
618
|
+
return count < 100;
|
|
619
|
+
};
|
|
620
|
+
const held = (text) => clip(text, TEXT_MAX * 2);
|
|
621
|
+
const keepConsole = (line) => keep(consoleLines, line, consoleLines.filter((l) => l.level === line.level).length);
|
|
622
|
+
cdp.on("Runtime.consoleAPICalled", (msg) => {
|
|
623
|
+
const p = params(msg);
|
|
624
|
+
const type = p.type ?? "log";
|
|
625
|
+
if (SILENT.has(type)) return;
|
|
626
|
+
const url = p.stackTrace?.callFrames?.[0]?.url;
|
|
627
|
+
keepConsole({
|
|
628
|
+
level: consoleLevel(type),
|
|
629
|
+
text: held((p.args ?? []).map(argText).join(" ")),
|
|
630
|
+
source: "console-api",
|
|
631
|
+
...url ? { url } : {}
|
|
632
|
+
});
|
|
633
|
+
});
|
|
634
|
+
cdp.on("Log.entryAdded", (msg) => {
|
|
635
|
+
const { entry } = params(msg);
|
|
636
|
+
if (!entry) return;
|
|
637
|
+
keepConsole({
|
|
638
|
+
level: logLevel(entry.level),
|
|
639
|
+
text: held(entry.text ?? ""),
|
|
640
|
+
source: entry.source ?? "other",
|
|
641
|
+
...entry.url ? { url: entry.url } : {}
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
cdp.on("Runtime.exceptionThrown", (msg) => {
|
|
645
|
+
const { exceptionDetails: d } = params(msg);
|
|
646
|
+
if (!d) return;
|
|
647
|
+
const thrown = d.exception ? argText(d.exception) : "";
|
|
648
|
+
const text = held(thrown ? `${d.text ?? "Uncaught"} ${thrown}`.trim() : d.text ?? "Uncaught");
|
|
649
|
+
if (!keep(errors, {
|
|
650
|
+
id: d.exceptionId,
|
|
651
|
+
text
|
|
652
|
+
}) && d.exceptionId !== void 0) droppedErrors.add(d.exceptionId);
|
|
653
|
+
});
|
|
654
|
+
cdp.on("Runtime.exceptionRevoked", (msg) => {
|
|
655
|
+
const { exceptionId: id } = params(msg);
|
|
656
|
+
if (id === void 0) return;
|
|
657
|
+
if (droppedErrors.delete(id)) {
|
|
658
|
+
dropped--;
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const at = errors.findIndex((e) => e.id === id);
|
|
662
|
+
if (at >= 0) errors.splice(at, 1);
|
|
663
|
+
});
|
|
664
|
+
cdp.on("Page.frameNavigated", (msg) => {
|
|
665
|
+
const { frame: f } = params(msg);
|
|
666
|
+
if (f?.id && f.id === frame && f.url) frameUrl = f.url + (f.urlFragment ?? "");
|
|
667
|
+
});
|
|
668
|
+
cdp.on("Page.navigatedWithinDocument", (msg) => {
|
|
669
|
+
const p = params(msg);
|
|
670
|
+
if (p.frameId && p.frameId === frame && p.url) frameUrl = p.url;
|
|
671
|
+
});
|
|
672
|
+
cdp.on("Network.requestWillBeSent", (msg) => {
|
|
673
|
+
const p = params(msg);
|
|
674
|
+
if (p.requestId && p.request?.url) requests.set(p.requestId, {
|
|
675
|
+
url: p.request.url,
|
|
676
|
+
method: p.request.method ?? "GET"
|
|
677
|
+
});
|
|
678
|
+
});
|
|
679
|
+
cdp.on("Network.responseReceived", (msg) => {
|
|
680
|
+
const p = params(msg);
|
|
681
|
+
const code = p.response?.status ?? 0;
|
|
682
|
+
if (p.type === "Document" && p.frameId && p.frameId === frame) status = p.response?.status;
|
|
683
|
+
if (code < 400) return;
|
|
684
|
+
const req = p.requestId ? requests.get(p.requestId) : void 0;
|
|
685
|
+
keep(failed, {
|
|
686
|
+
method: req?.method ?? "GET",
|
|
687
|
+
url: p.response?.url ?? req?.url ?? "",
|
|
688
|
+
status: code
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
cdp.on("Network.loadingFinished", (msg) => {
|
|
692
|
+
const { requestId } = params(msg);
|
|
693
|
+
if (requestId) requests.delete(requestId);
|
|
694
|
+
});
|
|
695
|
+
cdp.on("Network.loadingFailed", (msg) => {
|
|
696
|
+
const p = params(msg);
|
|
697
|
+
const req = p.requestId ? requests.get(p.requestId) : void 0;
|
|
698
|
+
if (p.requestId) requests.delete(p.requestId);
|
|
699
|
+
if (p.canceled || !req) return;
|
|
700
|
+
const cors = p.corsErrorStatus?.corsError;
|
|
701
|
+
const error = `${p.errorText ?? "failed"}${cors ? ` (CORS ${cors})` : ""}`;
|
|
702
|
+
keep(failed, {
|
|
703
|
+
method: req.method,
|
|
704
|
+
url: req.url,
|
|
705
|
+
error
|
|
706
|
+
});
|
|
707
|
+
});
|
|
708
|
+
return {
|
|
709
|
+
mainFrame(id) {
|
|
710
|
+
frame = id;
|
|
711
|
+
},
|
|
712
|
+
facts(url, origin) {
|
|
713
|
+
url ||= frameUrl;
|
|
714
|
+
const base = origin.replace(/\/$/, "");
|
|
715
|
+
const at = base ? new RegExp(`${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?!\\d)`, "g") : void 0;
|
|
716
|
+
const local = (text) => clip(at ? text.replace(at, "") : text, TEXT_MAX);
|
|
717
|
+
const path = (u) => local(u) || "/";
|
|
718
|
+
return {
|
|
719
|
+
...status ? { status } : {},
|
|
720
|
+
finalUrl: path(url),
|
|
721
|
+
console: consoleLines.map((l) => ({
|
|
722
|
+
...l,
|
|
723
|
+
text: local(l.text),
|
|
724
|
+
...l.url ? { url: path(l.url) } : {}
|
|
725
|
+
})),
|
|
726
|
+
errors: errors.map((e) => local(e.text)),
|
|
727
|
+
failedRequests: failed.map((r) => ({
|
|
728
|
+
...r,
|
|
729
|
+
url: path(r.url)
|
|
730
|
+
})),
|
|
731
|
+
...dropped ? { dropped } : {}
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
}
|
|
543
736
|
//#endregion
|
|
544
737
|
//#region src/capture/zip.ts
|
|
545
738
|
const LOCAL = 67324752;
|
|
@@ -980,25 +1173,36 @@ async function ensureChrome(cacheRoot, options = { cacheLabel: cacheRoot }) {
|
|
|
980
1173
|
}
|
|
981
1174
|
return bin;
|
|
982
1175
|
}
|
|
1176
|
+
/** The least time a CDP call gets, so the page facts still come after a screenshot near the deadline. */
|
|
1177
|
+
const CDP_CALL_MIN_MS = 1e3;
|
|
1178
|
+
/**
|
|
1179
|
+
* A CDP connection whose every call settles: with the reply, at `callMs()` (at least
|
|
1180
|
+
* `CDP_CALL_MIN_MS`), or when the socket closes. A blocked browser can't hold a capture past its
|
|
1181
|
+
* budget.
|
|
1182
|
+
*/
|
|
983
1183
|
var Cdp = class {
|
|
984
1184
|
#ws;
|
|
985
1185
|
#next = 0;
|
|
986
1186
|
#pending = /* @__PURE__ */ new Map();
|
|
987
1187
|
#events = /* @__PURE__ */ new Map();
|
|
1188
|
+
#closed;
|
|
1189
|
+
callMs = () => 3e4;
|
|
988
1190
|
constructor(ws) {
|
|
989
1191
|
this.#ws = ws;
|
|
990
1192
|
ws.addEventListener("message", (ev) => {
|
|
991
1193
|
const msg = JSON.parse(String(ev.data));
|
|
992
1194
|
if (msg.id !== void 0) {
|
|
993
|
-
|
|
994
|
-
if (!p) return;
|
|
995
|
-
this.#pending.delete(msg.id);
|
|
996
|
-
if (msg.error) p.reject(new Error(msg.error.message));
|
|
997
|
-
else p.resolve(msg.result);
|
|
1195
|
+
this.#pending.get(msg.id)?.settle(msg);
|
|
998
1196
|
return;
|
|
999
1197
|
}
|
|
1000
1198
|
if (msg.method) for (const fn of this.#events.get(msg.method) ?? []) fn(msg);
|
|
1001
1199
|
});
|
|
1200
|
+
ws.addEventListener("close", () => this.#fail(/* @__PURE__ */ new Error("the browser closed its DevTools connection")));
|
|
1201
|
+
ws.addEventListener("error", () => this.#fail(/* @__PURE__ */ new Error("the browser closed its DevTools connection")));
|
|
1202
|
+
}
|
|
1203
|
+
#fail(error) {
|
|
1204
|
+
this.#closed ??= error;
|
|
1205
|
+
for (const p of [...this.#pending.values()]) p.reject(this.#closed);
|
|
1002
1206
|
}
|
|
1003
1207
|
on(method, fn) {
|
|
1004
1208
|
const list = this.#events.get(method) ?? [];
|
|
@@ -1006,18 +1210,38 @@ var Cdp = class {
|
|
|
1006
1210
|
this.#events.set(method, list);
|
|
1007
1211
|
}
|
|
1008
1212
|
send(method, params) {
|
|
1213
|
+
if (this.#closed) return Promise.reject(this.#closed);
|
|
1009
1214
|
const id = ++this.#next;
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1215
|
+
return new Promise((resolve, reject) => {
|
|
1216
|
+
const done = () => {
|
|
1217
|
+
clearTimeout(timer);
|
|
1218
|
+
this.#pending.delete(id);
|
|
1219
|
+
};
|
|
1220
|
+
const ms = Math.max(CDP_CALL_MIN_MS, this.callMs());
|
|
1221
|
+
const timer = setTimeout(() => {
|
|
1222
|
+
done();
|
|
1223
|
+
reject(/* @__PURE__ */ new Error(`c.capture() timed out after ${ms}ms waiting for the browser (${method})`));
|
|
1224
|
+
}, ms);
|
|
1225
|
+
this.#pending.set(id, {
|
|
1226
|
+
reject: (e) => {
|
|
1227
|
+
done();
|
|
1228
|
+
reject(e);
|
|
1229
|
+
},
|
|
1230
|
+
settle: (msg) => {
|
|
1231
|
+
done();
|
|
1232
|
+
if (msg.error) reject(new Error(msg.error.message));
|
|
1233
|
+
else resolve(msg.result);
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
this.#ws.send(JSON.stringify({
|
|
1237
|
+
id,
|
|
1238
|
+
method,
|
|
1239
|
+
params
|
|
1240
|
+
}));
|
|
1241
|
+
});
|
|
1019
1242
|
}
|
|
1020
1243
|
close() {
|
|
1244
|
+
this.#fail(/* @__PURE__ */ new Error("the capture closed its DevTools connection"));
|
|
1021
1245
|
this.#ws.close();
|
|
1022
1246
|
}
|
|
1023
1247
|
};
|
|
@@ -1141,7 +1365,9 @@ function proxyArgs(proxy) {
|
|
|
1141
1365
|
return proxy ? [`--proxy-server=http://${proxy}`, "--proxy-bypass-list=<-loopback>"] : [];
|
|
1142
1366
|
}
|
|
1143
1367
|
/** One Chrome process, one tab. `fn` must not keep the session after it returns. */
|
|
1144
|
-
async function withChrome(bin, window, timeoutMs, options, fn) {
|
|
1368
|
+
async function withChrome(bin, window, timeoutMs, options, fn, signal) {
|
|
1369
|
+
signal?.throwIfAborted();
|
|
1370
|
+
const deadline = Date.now() + timeoutMs;
|
|
1145
1371
|
const userData = mkdtempSync(join(tmpdir(), `reeval-chrome-${process.pid}-`));
|
|
1146
1372
|
const child = spawn(bin, [
|
|
1147
1373
|
"--headless",
|
|
@@ -1155,16 +1381,24 @@ async function withChrome(bin, window, timeoutMs, options, fn) {
|
|
|
1155
1381
|
"--remote-debugging-port=0",
|
|
1156
1382
|
...proxyArgs(options.proxy),
|
|
1157
1383
|
"about:blank"
|
|
1158
|
-
], { stdio:
|
|
1159
|
-
|
|
1160
|
-
"
|
|
1161
|
-
|
|
1162
|
-
|
|
1384
|
+
], { stdio: "ignore" });
|
|
1385
|
+
const kill = () => {
|
|
1386
|
+
if (child.exitCode === null && child.signalCode === null) child.kill("SIGKILL");
|
|
1387
|
+
};
|
|
1388
|
+
signal?.addEventListener("abort", kill, { once: true });
|
|
1163
1389
|
try {
|
|
1164
1390
|
const cdp = await cdpConnect(await pageDebuggerUrl(await waitForPortFile(join(userData, "DevToolsActivePort"), timeoutMs), timeoutMs), timeoutMs);
|
|
1391
|
+
cdp.callMs = () => deadline - Date.now();
|
|
1392
|
+
const abort = () => cdp.close();
|
|
1393
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
1165
1394
|
try {
|
|
1166
1395
|
await cdp.send("Page.enable");
|
|
1167
1396
|
await cdp.send("Page.setLifecycleEventsEnabled", { enabled: true });
|
|
1397
|
+
const watched = watchPage(cdp);
|
|
1398
|
+
const mainFrame = (await cdp.send("Page.getFrameTree"))?.frameTree?.frame?.id;
|
|
1399
|
+
if (mainFrame) watched.mainFrame(mainFrame);
|
|
1400
|
+
await cdp.send("Runtime.enable");
|
|
1401
|
+
await cdp.send("Log.enable");
|
|
1168
1402
|
const network = trackNetwork(cdp);
|
|
1169
1403
|
const loading = /* @__PURE__ */ new Set();
|
|
1170
1404
|
const frame = (msg) => {
|
|
@@ -1192,7 +1426,7 @@ async function withChrome(bin, window, timeoutMs, options, fn) {
|
|
|
1192
1426
|
mobile: false
|
|
1193
1427
|
});
|
|
1194
1428
|
let scrollY = 0;
|
|
1195
|
-
|
|
1429
|
+
const run = fn({
|
|
1196
1430
|
cdp,
|
|
1197
1431
|
window,
|
|
1198
1432
|
async navigate(url) {
|
|
@@ -1226,12 +1460,32 @@ async function withChrome(bin, window, timeoutMs, options, fn) {
|
|
|
1226
1460
|
},
|
|
1227
1461
|
dialogs() {
|
|
1228
1462
|
return opened.splice(0);
|
|
1463
|
+
},
|
|
1464
|
+
async page(origin) {
|
|
1465
|
+
const history = await cdp.send("Page.getNavigationHistory").catch(() => void 0);
|
|
1466
|
+
const url = history?.entries?.[history.currentIndex ?? -1]?.url ?? "";
|
|
1467
|
+
return watched.facts(url, origin);
|
|
1229
1468
|
}
|
|
1230
1469
|
});
|
|
1470
|
+
if (!signal) return await run;
|
|
1471
|
+
run.catch(() => {});
|
|
1472
|
+
let stop = () => {};
|
|
1473
|
+
const canceled = new Promise((_, reject) => {
|
|
1474
|
+
stop = () => reject(signal.reason);
|
|
1475
|
+
if (signal.aborted) stop();
|
|
1476
|
+
else signal.addEventListener("abort", stop, { once: true });
|
|
1477
|
+
});
|
|
1478
|
+
try {
|
|
1479
|
+
return await Promise.race([run, canceled]);
|
|
1480
|
+
} finally {
|
|
1481
|
+
signal.removeEventListener("abort", stop);
|
|
1482
|
+
}
|
|
1231
1483
|
} finally {
|
|
1484
|
+
signal?.removeEventListener("abort", abort);
|
|
1232
1485
|
cdp.close();
|
|
1233
1486
|
}
|
|
1234
1487
|
} finally {
|
|
1488
|
+
signal?.removeEventListener("abort", kill);
|
|
1235
1489
|
await disposeChrome(child, userData);
|
|
1236
1490
|
}
|
|
1237
1491
|
}
|
|
@@ -1853,14 +2107,43 @@ async function settledState(session, volatile, left) {
|
|
|
1853
2107
|
prev = next;
|
|
1854
2108
|
}
|
|
1855
2109
|
}
|
|
2110
|
+
/** How long a settled page is watched for a change still to come after a move that ends its instruction. */
|
|
2111
|
+
const LATE_CHANGE_MS = 1e3;
|
|
2112
|
+
/**
|
|
2113
|
+
* The page once a change that starts within `LATE_CHANGE_MS` of `settled` has settled too, or
|
|
2114
|
+
* `settled`: an auth callback's redirect or a save's message often comes a beat after the
|
|
2115
|
+
* request that made it, and the next instruction's first look must not be the page before it.
|
|
2116
|
+
*/
|
|
2117
|
+
async function lateSettledState(session, settled, volatile, left) {
|
|
2118
|
+
const until = Date.now() + Math.min(LATE_CHANGE_MS, left());
|
|
2119
|
+
while (Date.now() < until) {
|
|
2120
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(100, left())));
|
|
2121
|
+
if (differing(settled, await probePage(session), volatile).length || session.busy()) return settledState(session, volatile, left);
|
|
2122
|
+
}
|
|
2123
|
+
return settled;
|
|
2124
|
+
}
|
|
1856
2125
|
/** Points within this many CSS pixels of each other are the same move. */
|
|
1857
2126
|
const SAME_POINT = 8;
|
|
1858
2127
|
/** Model turns in a row thrown away because the page changed while the model chose. */
|
|
1859
2128
|
const STALE_ASKS = 2;
|
|
2129
|
+
/** How long a stopped instruction's screenshot may take once the budget is spent. */
|
|
2130
|
+
const STOPPED_SHOT_MS = 5e3;
|
|
1860
2131
|
function timedOut(clock) {
|
|
1861
2132
|
const { step } = clock;
|
|
1862
2133
|
const where = step ? ` (instruction ${step.index} of ${step.total}, after ${plural(step.moves, "move")})` : "";
|
|
1863
|
-
return /* @__PURE__ */ new Error(`c.capture() timed out on ${clock.detail}${where}: it used all of its ${formatDuration(clock.budgetMs)} timeout. Raise timeout on the call or capture.timeout.`);
|
|
2134
|
+
return /* @__PURE__ */ new Error(`c.capture() timed out on ${clock.detail}${where}: it used all of its ${formatDuration(clock.budgetMs)} timeout${stallReason(clock)}. Raise timeout on the call or capture.timeout.`);
|
|
2135
|
+
}
|
|
2136
|
+
/** Why the instruction's moves never finished it, as a clause; empty when nothing says. */
|
|
2137
|
+
function stallReason({ step, trail }) {
|
|
2138
|
+
if (!step || !trail) return "";
|
|
2139
|
+
const paths = [trail.start, ...trail.made.map((m) => m.after)].flatMap((s) => s ? [pathOf(s.url, trail.origin) ?? s.url] : []);
|
|
2140
|
+
for (let k = 2; k < paths.length; k++) {
|
|
2141
|
+
const path = paths[k];
|
|
2142
|
+
const first = paths.indexOf(path);
|
|
2143
|
+
if (first < k && paths.slice(first + 1, k).some((p) => p !== path)) return `; its moves left ${path} and came back to it, so the model may be undoing what it did`;
|
|
2144
|
+
}
|
|
2145
|
+
if (trail.choosing) return `; the model was still choosing move ${step.moves + 1}`;
|
|
2146
|
+
return "";
|
|
1864
2147
|
}
|
|
1865
2148
|
function check(clock) {
|
|
1866
2149
|
const left = clock.remaining();
|
|
@@ -1893,7 +2176,8 @@ function onClock(session, clock) {
|
|
|
1893
2176
|
screenshot: (fullPage) => race(clock, () => session.screenshot(fullPage)),
|
|
1894
2177
|
dispatch: (action, page) => race(clock, () => session.dispatch(action, page)),
|
|
1895
2178
|
busy: () => session.busy(),
|
|
1896
|
-
dialogs: () => session.dialogs()
|
|
2179
|
+
dialogs: () => session.dialogs(),
|
|
2180
|
+
page: (origin) => session.page(origin)
|
|
1897
2181
|
};
|
|
1898
2182
|
}
|
|
1899
2183
|
function asUsage(value) {
|
|
@@ -1906,19 +2190,33 @@ function asUsage(value) {
|
|
|
1906
2190
|
};
|
|
1907
2191
|
}
|
|
1908
2192
|
const finite = (value) => {
|
|
1909
|
-
const n = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
|
|
2193
|
+
const n = typeof value === "number" ? value : typeof value === "string" && value.trim() ? Number(value) : NaN;
|
|
1910
2194
|
return Number.isFinite(n) ? n : void 0;
|
|
1911
2195
|
};
|
|
1912
|
-
/**
|
|
2196
|
+
/**
|
|
2197
|
+
* The point at `x`/`y`, or both packed into one as `"217,163"`, which models sometimes send. A
|
|
2198
|
+
* half missing from the packed form (`"217,"`) is read from its own field.
|
|
2199
|
+
*/
|
|
1913
2200
|
function point(input, x, y) {
|
|
1914
2201
|
const packed = typeof input[x] === "string" ? input[x].split(",") : [];
|
|
1915
|
-
const px =
|
|
1916
|
-
const py =
|
|
2202
|
+
const px = packed.length === 2 ? finite(packed[0]) ?? finite(input[x]) : finite(input[x]);
|
|
2203
|
+
const py = packed.length === 2 ? finite(packed[1]) ?? finite(input[y]) : finite(input[y]);
|
|
1917
2204
|
return px === void 0 || py === void 0 ? void 0 : [px, py];
|
|
1918
2205
|
}
|
|
1919
|
-
/**
|
|
2206
|
+
/**
|
|
2207
|
+
* The action a tool call asks for, or why it can't be made. Only a click or a key press can
|
|
2208
|
+
* complete its goal: offered on `type`, models mark the text as final, not the goal.
|
|
2209
|
+
*/
|
|
1920
2210
|
function actionFromTool(name, input) {
|
|
1921
2211
|
if (name === "done") return { type: "done" };
|
|
2212
|
+
const move = moveFromTool(name, input);
|
|
2213
|
+
if ("refused" in move || move.type !== "click" && move.type !== "key") return move;
|
|
2214
|
+
return input.completesGoal === true || input.completesGoal === "true" ? {
|
|
2215
|
+
...move,
|
|
2216
|
+
final: true
|
|
2217
|
+
} : move;
|
|
2218
|
+
}
|
|
2219
|
+
function moveFromTool(name, input) {
|
|
1922
2220
|
if (name === "type") {
|
|
1923
2221
|
if (typeof input.text !== "string") return { refused: "it had no text" };
|
|
1924
2222
|
return {
|
|
@@ -1997,13 +2295,15 @@ function scalePoints(action, page) {
|
|
|
1997
2295
|
default: return action;
|
|
1998
2296
|
}
|
|
1999
2297
|
}
|
|
2000
|
-
const systemPrompt = (normalized) => `You drive a web page from screenshots. Call one tool. ${normalized ? `Coordinates are normalized to 0-${NORMALIZED} on the full-page image: x and toX across its width, y and toY down its height. A scroll's dy is in CSS pixels.` : "Coordinates are CSS pixels on the full-page image."} Each turn you get the goal, what has focus, your earlier moves with what each did, and a fresh screenshot. Click a field before typing into it, and do not repeat a move that already worked. A dropdown (select) never opens in the screenshot: click it once, press ArrowDown or ArrowUp until it shows the option you want, then press Enter to choose it. Call done when the goal is met. Do not mention CDP.`;
|
|
2298
|
+
const systemPrompt = (normalized) => `You drive a web page from screenshots. Call one tool. ${normalized ? `Coordinates are normalized to 0-${NORMALIZED} on the full-page image: x and toX across its width, y and toY down its height. A scroll's dy is in CSS pixels.` : "Coordinates are CSS pixels on the full-page image."} Each turn you get the goal, what has focus, your earlier moves with what each did, and a fresh screenshot. Click a field before typing into it, and do not repeat a move that already worked. A dropdown (select) never opens in the screenshot: click it once, press ArrowDown or ArrowUp until it shows the option you want, then press Enter to choose it. On a click or key press after which nothing of the goal is left, such as the click that submits a form you have filled in, set completesGoal to true: reeval makes it and goes on to the next goal without asking you again. Call done when the goal is met. Do not mention CDP.`;
|
|
2299
|
+
const completesGoal = z.boolean().optional().describe("True only on the last move the goal needs: nothing of the goal is left after it.");
|
|
2001
2300
|
const useTools = {
|
|
2002
2301
|
click: tool({
|
|
2003
2302
|
description: "Click at (x, y) on the screenshot.",
|
|
2004
2303
|
inputSchema: z.object({
|
|
2005
2304
|
x: z.number(),
|
|
2006
|
-
y: z.number()
|
|
2305
|
+
y: z.number(),
|
|
2306
|
+
completesGoal
|
|
2007
2307
|
})
|
|
2008
2308
|
}),
|
|
2009
2309
|
type: tool({
|
|
@@ -2015,7 +2315,10 @@ const useTools = {
|
|
|
2015
2315
|
}),
|
|
2016
2316
|
key: tool({
|
|
2017
2317
|
description: "Press a key in the focused element. In a dropdown (select), click it, press ArrowDown or ArrowUp to the option, then Enter to choose it. Space toggles a focused checkbox.",
|
|
2018
|
-
inputSchema: z.object({
|
|
2318
|
+
inputSchema: z.object({
|
|
2319
|
+
key: z.enum(CAPTURE_KEYS),
|
|
2320
|
+
completesGoal
|
|
2321
|
+
})
|
|
2019
2322
|
}),
|
|
2020
2323
|
scroll: tool({
|
|
2021
2324
|
description: "Wheel-scroll a constrained scroller at (x, y).",
|
|
@@ -2055,8 +2358,11 @@ async function runFakeScript(session, script, step, clock, volatile) {
|
|
|
2055
2358
|
moves
|
|
2056
2359
|
};
|
|
2057
2360
|
check(clock);
|
|
2058
|
-
if (action.type === "done") return
|
|
2059
|
-
|
|
2361
|
+
if (action.type === "done") return {
|
|
2362
|
+
moves,
|
|
2363
|
+
ended: "done"
|
|
2364
|
+
};
|
|
2365
|
+
if (moves >= 32) throw unfinished(step, clock);
|
|
2060
2366
|
const page = pngSize(await session.screenshot(true));
|
|
2061
2367
|
debugTrace("check", "capture-use", {
|
|
2062
2368
|
goal,
|
|
@@ -2065,7 +2371,14 @@ async function runFakeScript(session, script, step, clock, volatile) {
|
|
|
2065
2371
|
}, `capture use ${action.type}`);
|
|
2066
2372
|
await session.dispatch(action, page);
|
|
2067
2373
|
moves++;
|
|
2068
|
-
await settledState(session, volatile, clock.remaining);
|
|
2374
|
+
const settled = await settledState(session, volatile, clock.remaining);
|
|
2375
|
+
if (action.final) {
|
|
2376
|
+
await lateSettledState(session, settled, volatile, clock.remaining);
|
|
2377
|
+
return {
|
|
2378
|
+
moves,
|
|
2379
|
+
ended: "final"
|
|
2380
|
+
};
|
|
2381
|
+
}
|
|
2069
2382
|
}
|
|
2070
2383
|
clock.step = {
|
|
2071
2384
|
...step,
|
|
@@ -2074,9 +2387,9 @@ async function runFakeScript(session, script, step, clock, volatile) {
|
|
|
2074
2387
|
while (clock.remaining() > 0) await new Promise((resolve) => setTimeout(resolve, Math.min(100, clock.remaining())));
|
|
2075
2388
|
throw timedOut(clock);
|
|
2076
2389
|
}
|
|
2077
|
-
const unfinished = (step) => /* @__PURE__ */ new Error(`c.capture() instruction ${step.index} of ${step.total} ${JSON.stringify(step.goal)} did not finish in 32 moves`);
|
|
2390
|
+
const unfinished = (step, clock) => /* @__PURE__ */ new Error(`c.capture() instruction ${step.index} of ${step.total} ${JSON.stringify(step.goal)} did not finish in 32 moves${stallReason(clock)}`);
|
|
2078
2391
|
const grid = (n) => Math.round(n / SAME_POINT);
|
|
2079
|
-
function moveKey(action) {
|
|
2392
|
+
function moveKey({ final: _, ...action }) {
|
|
2080
2393
|
switch (action.type) {
|
|
2081
2394
|
case "click":
|
|
2082
2395
|
case "hover": return JSON.stringify([
|
|
@@ -2148,6 +2461,9 @@ function goalPrompt(step, earlier, now, moves, origin, volatile = /* @__PURE__ *
|
|
|
2148
2461
|
lines.push(`${i + 1}. ${m.said}${effect ? ` → ${effect}` : ""}`);
|
|
2149
2462
|
});
|
|
2150
2463
|
if (stuckMoves(moves) >= 2) lines.push("Your last moves repeated the same action and nothing changed. Do not repeat it: if the goal is met, call done; otherwise try a different action.");
|
|
2464
|
+
const from = pathOf(moves.find((m) => m.before)?.before?.url, origin);
|
|
2465
|
+
const at = pathOf(now.url, origin);
|
|
2466
|
+
if (from && at && from !== at) lines.push(`Your moves took the page from ${from} to ${at}. If they did what the goal asks, call done: a goal's "once", "if" or "when" says where it starts, so do not undo them to get back there.`);
|
|
2151
2467
|
return lines.join("\n");
|
|
2152
2468
|
}
|
|
2153
2469
|
async function runModelGoal(session, { step, earlier, origin, modelName, clock, volatile, pristine, loadModel }) {
|
|
@@ -2159,6 +2475,13 @@ async function runModelGoal(session, { step, earlier, origin, modelName, clock,
|
|
|
2159
2475
|
let usage = null;
|
|
2160
2476
|
let now = await probePage(session);
|
|
2161
2477
|
let stale = 0;
|
|
2478
|
+
const trail = {
|
|
2479
|
+
origin,
|
|
2480
|
+
start: now,
|
|
2481
|
+
made,
|
|
2482
|
+
choosing: false
|
|
2483
|
+
};
|
|
2484
|
+
clock.trail = trail;
|
|
2162
2485
|
while (made.length < 32) {
|
|
2163
2486
|
clock.step = {
|
|
2164
2487
|
...step,
|
|
@@ -2183,6 +2506,7 @@ async function runModelGoal(session, { step, earlier, origin, modelName, clock,
|
|
|
2183
2506
|
}, false);
|
|
2184
2507
|
const signal = AbortSignal.timeout(check(clock));
|
|
2185
2508
|
const asked = Date.now();
|
|
2509
|
+
trail.choosing = true;
|
|
2186
2510
|
const result = await race(clock, () => generateText({
|
|
2187
2511
|
model,
|
|
2188
2512
|
system: systemPrompt(normalized),
|
|
@@ -2204,6 +2528,7 @@ async function runModelGoal(session, { step, earlier, origin, modelName, clock,
|
|
|
2204
2528
|
})).catch((error) => {
|
|
2205
2529
|
throw signal.aborted ? timedOut(clock) : error;
|
|
2206
2530
|
});
|
|
2531
|
+
trail.choosing = false;
|
|
2207
2532
|
usage = addUsage(usage, asUsage(result.usage ?? {}));
|
|
2208
2533
|
const call = result.toolCalls?.[0];
|
|
2209
2534
|
if (!call) throw new Error(`c.capture() instruction ${JSON.stringify(goal)} returned no action`);
|
|
@@ -2212,13 +2537,11 @@ async function runModelGoal(session, { step, earlier, origin, modelName, clock,
|
|
|
2212
2537
|
const fresh = await probePage(session);
|
|
2213
2538
|
const opened = session.dialogs();
|
|
2214
2539
|
const moved = differing(now, fresh, volatile);
|
|
2215
|
-
if (!last) {
|
|
2216
|
-
if (
|
|
2217
|
-
for (const f of moved) if (f !== "url" && f !== "focus") volatile.add(f);
|
|
2218
|
-
}
|
|
2540
|
+
if (!last && pristine) {
|
|
2541
|
+
for (const f of moved) if (f !== "url" && f !== "focus") volatile.add(f);
|
|
2219
2542
|
} else if ((moved.length || opened.length) && stale < STALE_ASKS) {
|
|
2220
2543
|
stale++;
|
|
2221
|
-
if (!last.refused) {
|
|
2544
|
+
if (last && !last.refused) {
|
|
2222
2545
|
last.dialogs.push(...opened);
|
|
2223
2546
|
settleMove(last, fresh, origin, volatile);
|
|
2224
2547
|
}
|
|
@@ -2251,9 +2574,10 @@ async function runModelGoal(session, { step, earlier, origin, modelName, clock,
|
|
|
2251
2574
|
action: chosen,
|
|
2252
2575
|
page
|
|
2253
2576
|
}, `capture use ${chosen.type}`);
|
|
2254
|
-
if (
|
|
2577
|
+
if (asks.type === "done") return {
|
|
2255
2578
|
moves: dispatched,
|
|
2256
|
-
usage
|
|
2579
|
+
usage,
|
|
2580
|
+
ended: "done"
|
|
2257
2581
|
};
|
|
2258
2582
|
const move = {
|
|
2259
2583
|
said,
|
|
@@ -2267,8 +2591,28 @@ async function runModelGoal(session, { step, earlier, origin, modelName, clock,
|
|
|
2267
2591
|
now = await settledState(session, volatile, clock.remaining);
|
|
2268
2592
|
move.dialogs.push(...session.dialogs());
|
|
2269
2593
|
settleMove(move, now, origin, volatile);
|
|
2594
|
+
if (asks.final && move.changed) {
|
|
2595
|
+
await lateSettledState(session, now, volatile, clock.remaining);
|
|
2596
|
+
return {
|
|
2597
|
+
moves: dispatched,
|
|
2598
|
+
usage,
|
|
2599
|
+
ended: "final"
|
|
2600
|
+
};
|
|
2601
|
+
}
|
|
2270
2602
|
}
|
|
2271
|
-
|
|
2603
|
+
clock.step = {
|
|
2604
|
+
...step,
|
|
2605
|
+
moves: dispatched
|
|
2606
|
+
};
|
|
2607
|
+
throw unfinished(step, clock);
|
|
2608
|
+
}
|
|
2609
|
+
/** The page once an instruction stopped the capture, unless the screenshot takes too long. */
|
|
2610
|
+
async function stoppedShot(raw, fullPage) {
|
|
2611
|
+
let timer;
|
|
2612
|
+
const late = new Promise((resolve) => {
|
|
2613
|
+
timer = setTimeout(() => resolve(void 0), STOPPED_SHOT_MS);
|
|
2614
|
+
});
|
|
2615
|
+
return Promise.race([raw.screenshot(fullPage).catch(() => void 0), late]).finally(() => clearTimeout(timer));
|
|
2272
2616
|
}
|
|
2273
2617
|
/**
|
|
2274
2618
|
* Top-level wait, then the instruction loop, then the saved PNG.
|
|
@@ -2310,23 +2654,56 @@ async function runJourney(raw, url, options) {
|
|
|
2310
2654
|
clock.step = step;
|
|
2311
2655
|
check(clock);
|
|
2312
2656
|
debugLog("check", `capture instruction ${step.index} of ${step.total} ${JSON.stringify(instruction)}`);
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
volatile,
|
|
2325
|
-
pristine: moves === 0,
|
|
2326
|
-
loadModel: options.loadModel
|
|
2657
|
+
const began = Date.now();
|
|
2658
|
+
const shot = (png, ran) => {
|
|
2659
|
+
const ms = Date.now() - began;
|
|
2660
|
+
debugLog("check", `capture instruction ${step.index} of ${step.total} ${ran.ended} after ${plural(ran.moves, "move")} in ${formatDuration(ms)}`);
|
|
2661
|
+
return options.onStep?.({
|
|
2662
|
+
index: step.index,
|
|
2663
|
+
instruction,
|
|
2664
|
+
moves: ran.moves,
|
|
2665
|
+
ms,
|
|
2666
|
+
ended: ran.ended,
|
|
2667
|
+
png
|
|
2327
2668
|
});
|
|
2328
|
-
|
|
2329
|
-
|
|
2669
|
+
};
|
|
2670
|
+
try {
|
|
2671
|
+
let ran;
|
|
2672
|
+
if (use && "fake" in use) ran = await runFakeScript(session, use.fake[stringIndex] ?? [], step, clock, volatile);
|
|
2673
|
+
else if (use && "model" in use) {
|
|
2674
|
+
if (!options.loadModel) throw new Error("c.capture() instructions need a model loader");
|
|
2675
|
+
const goal = await runModelGoal(session, {
|
|
2676
|
+
step,
|
|
2677
|
+
earlier: goals.slice(0, stringIndex),
|
|
2678
|
+
origin,
|
|
2679
|
+
modelName: use.model,
|
|
2680
|
+
clock,
|
|
2681
|
+
volatile,
|
|
2682
|
+
pristine: moves === 0,
|
|
2683
|
+
loadModel: options.loadModel
|
|
2684
|
+
});
|
|
2685
|
+
usage = addUsage(usage, goal.usage);
|
|
2686
|
+
ran = goal;
|
|
2687
|
+
}
|
|
2688
|
+
if (ran) {
|
|
2689
|
+
moves += ran.moves;
|
|
2690
|
+
clock.step = {
|
|
2691
|
+
...step,
|
|
2692
|
+
moves: ran.moves
|
|
2693
|
+
};
|
|
2694
|
+
clock.trail = void 0;
|
|
2695
|
+
shot(await session.screenshot(fullPage), ran);
|
|
2696
|
+
}
|
|
2697
|
+
} catch (error) {
|
|
2698
|
+
clock.trail = void 0;
|
|
2699
|
+
const png = options.onStep && await stoppedShot(raw, fullPage);
|
|
2700
|
+
const saved = png && shot(png, {
|
|
2701
|
+
moves: clock.step?.moves ?? 0,
|
|
2702
|
+
ended: "stopped"
|
|
2703
|
+
});
|
|
2704
|
+
if (!saved || !(error instanceof Error)) throw error;
|
|
2705
|
+
const sentence = error.message.endsWith(".") ? error.message : `${error.message}.`;
|
|
2706
|
+
throw new Error(`${sentence} The page as it stopped: ${saved}.`);
|
|
2330
2707
|
}
|
|
2331
2708
|
stringIndex++;
|
|
2332
2709
|
}
|
|
@@ -2476,7 +2853,7 @@ function createChecks(a) {
|
|
|
2476
2853
|
function exec(command, options) {
|
|
2477
2854
|
const problem = options === void 0 ? void 0 : execOptionsProblem(options);
|
|
2478
2855
|
if (problem) return Promise.reject(new UsageError(problem));
|
|
2479
|
-
if (options?.background) return import("./capture-
|
|
2856
|
+
if (options?.background) return import("./capture-D68TiQQy.js").then(({ startBackground }) => startBackground(a, command, "c.exec({ background: true })"));
|
|
2480
2857
|
const run = execForeground(command, options?.retries ?? 0, options?.interval ?? 1e3);
|
|
2481
2858
|
return Object.defineProperty(run, SUBJECT, { value: command });
|
|
2482
2859
|
}
|
|
@@ -2645,7 +3022,34 @@ async function capturePage(a, target, call) {
|
|
|
2645
3022
|
const started = Date.now();
|
|
2646
3023
|
const remaining = () => Math.max(0, resolved.timeoutMs - (Date.now() - started));
|
|
2647
3024
|
let moves = 0;
|
|
2648
|
-
const
|
|
3025
|
+
const camera = {
|
|
3026
|
+
port: resolved.port,
|
|
3027
|
+
path: resolved.path,
|
|
3028
|
+
viewport: resolved.window,
|
|
3029
|
+
...resolved.fullPage ? { fullPage: true } : {}
|
|
3030
|
+
};
|
|
3031
|
+
const steps = [];
|
|
3032
|
+
const keepSteps = () => {
|
|
3033
|
+
for (const { name, png, step } of steps) {
|
|
3034
|
+
a.record.artifacts = a.record.artifacts ?? [];
|
|
3035
|
+
a.record.artifacts.push({
|
|
3036
|
+
name,
|
|
3037
|
+
mediaType: "image/png",
|
|
3038
|
+
sha256: sha256(png),
|
|
3039
|
+
bytes: png.length,
|
|
3040
|
+
capture: {
|
|
3041
|
+
...camera,
|
|
3042
|
+
step
|
|
3043
|
+
}
|
|
3044
|
+
});
|
|
3045
|
+
a.stepBlobs.set(name, png);
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3048
|
+
const url = pageUrl(origin, resolved.path);
|
|
3049
|
+
const { png, page } = fake ? {
|
|
3050
|
+
png: stubPng(resolved.name, resolved.port, resolved.path, resolved.viewport),
|
|
3051
|
+
page: await fetchedPage(url, origin, remaining(), a.signal)
|
|
3052
|
+
} : await shot(a, origin, url, {
|
|
2649
3053
|
...resolved,
|
|
2650
3054
|
use
|
|
2651
3055
|
}, remaining, (n) => {
|
|
@@ -2653,7 +3057,28 @@ async function capturePage(a, target, call) {
|
|
|
2653
3057
|
}, (port) => tunnel({
|
|
2654
3058
|
port,
|
|
2655
3059
|
protocol: "http"
|
|
2656
|
-
}).then((t) => t.url))
|
|
3060
|
+
}).then((t) => t.url), ({ png, ...step }) => {
|
|
3061
|
+
const name = `${resolved.name}.step-${step.index}`;
|
|
3062
|
+
steps.push({
|
|
3063
|
+
name,
|
|
3064
|
+
png,
|
|
3065
|
+
step: {
|
|
3066
|
+
of: resolved.name,
|
|
3067
|
+
...step
|
|
3068
|
+
}
|
|
3069
|
+
});
|
|
3070
|
+
return `artifacts/${name}.png`;
|
|
3071
|
+
}).catch((error) => {
|
|
3072
|
+
keepSteps();
|
|
3073
|
+
throw error;
|
|
3074
|
+
});
|
|
3075
|
+
tracePage(resolved.name, page);
|
|
3076
|
+
const facts = {
|
|
3077
|
+
schemaVersion: 1,
|
|
3078
|
+
...page
|
|
3079
|
+
};
|
|
3080
|
+
const pageJson = `${redactJson(facts, 2)}\n`;
|
|
3081
|
+
a.capturePages.set(resolved.name, pageJson);
|
|
2657
3082
|
const digest = sha256(png);
|
|
2658
3083
|
const file = {
|
|
2659
3084
|
path: `artifacts/${resolved.name}.png`,
|
|
@@ -2662,15 +3087,19 @@ async function capturePage(a, target, call) {
|
|
|
2662
3087
|
};
|
|
2663
3088
|
const goals = instructionGoals(resolved.instructions);
|
|
2664
3089
|
const capture = {
|
|
2665
|
-
|
|
2666
|
-
path: resolved.path,
|
|
2667
|
-
viewport: resolved.window,
|
|
2668
|
-
...resolved.fullPage ? { fullPage: true } : {},
|
|
3090
|
+
...camera,
|
|
2669
3091
|
...goals.length ? { instructions: goals } : {},
|
|
2670
3092
|
...use ? { use: {
|
|
2671
3093
|
model: "model" in use ? use.model : "fake",
|
|
2672
3094
|
moves
|
|
2673
|
-
} } : {}
|
|
3095
|
+
} } : {},
|
|
3096
|
+
...page.status ? { status: page.status } : {},
|
|
3097
|
+
...page.errors.length ? { pageErrors: page.errors.length } : {},
|
|
3098
|
+
page: {
|
|
3099
|
+
path: `artifacts/${resolved.name}.capture.json`,
|
|
3100
|
+
sha256: sha256(pageJson),
|
|
3101
|
+
bytes: Buffer.byteLength(pageJson)
|
|
3102
|
+
}
|
|
2674
3103
|
};
|
|
2675
3104
|
a.record.artifacts = a.record.artifacts ?? [];
|
|
2676
3105
|
a.record.artifacts.push({
|
|
@@ -2681,15 +3110,43 @@ async function capturePage(a, target, call) {
|
|
|
2681
3110
|
capture
|
|
2682
3111
|
});
|
|
2683
3112
|
a.artifactBlobs.set(resolved.name, png);
|
|
2684
|
-
|
|
3113
|
+
keepSteps();
|
|
3114
|
+
const taken = {
|
|
2685
3115
|
name: resolved.name,
|
|
2686
3116
|
port: resolved.port,
|
|
2687
3117
|
path: resolved.path,
|
|
2688
3118
|
viewport: resolved.viewport,
|
|
2689
|
-
file
|
|
3119
|
+
file,
|
|
3120
|
+
...structuredClone(page)
|
|
3121
|
+
};
|
|
3122
|
+
return Object.defineProperty(taken, SUBJECT, { value: resolved.name });
|
|
3123
|
+
}
|
|
3124
|
+
/** The fake sandbox has no browser: the page's status and final URL from a GET, and no more. */
|
|
3125
|
+
async function fetchedPage(url, origin, timeoutMs, signal) {
|
|
3126
|
+
const res = await fetch(url, { signal: AbortSignal.any([AbortSignal.timeout(Math.max(1, timeoutMs)), signal]) }).catch(() => void 0);
|
|
3127
|
+
await res?.body?.cancel();
|
|
3128
|
+
const base = origin.replace(/\/$/, "");
|
|
3129
|
+
const final = res?.url || url;
|
|
3130
|
+
return {
|
|
3131
|
+
...res ? { status: res.status } : {},
|
|
3132
|
+
finalUrl: final.startsWith(base) ? final.slice(base.length) || "/" : final,
|
|
3133
|
+
console: [],
|
|
3134
|
+
errors: [],
|
|
3135
|
+
failedRequests: []
|
|
2690
3136
|
};
|
|
2691
3137
|
}
|
|
2692
|
-
|
|
3138
|
+
/** The page's facts in the debug log, which `-v` prints: a summary, then a line each. */
|
|
3139
|
+
function tracePage(name, page) {
|
|
3140
|
+
const counts = [
|
|
3141
|
+
plural(page.errors.length, "page error"),
|
|
3142
|
+
plural(page.console.length, "console message"),
|
|
3143
|
+
plural(page.failedRequests.length, "failed request")
|
|
3144
|
+
];
|
|
3145
|
+
const status = page.status ? ` (${page.status})` : "";
|
|
3146
|
+
debugLog("check", `capture "${name}" at ${page.finalUrl}${status}: ${counts.join(" · ")}`);
|
|
3147
|
+
for (const line of pageLines(page)) debugLog("check", `capture "${name}" ${line}`);
|
|
3148
|
+
}
|
|
3149
|
+
async function shot(a, origin, url, resolved, remaining, onMoves, tunnel, onStep) {
|
|
2693
3150
|
const cache = cacheDir();
|
|
2694
3151
|
const bin = await ensureChrome(cache, {
|
|
2695
3152
|
cacheLabel: cacheLabel(cache),
|
|
@@ -2713,6 +3170,7 @@ async function shot(a, url, resolved, remaining, onMoves, tunnel) {
|
|
|
2713
3170
|
instructions: resolved.instructions,
|
|
2714
3171
|
use: resolved.use,
|
|
2715
3172
|
remaining,
|
|
3173
|
+
onStep,
|
|
2716
3174
|
loadModel: async (name) => {
|
|
2717
3175
|
const { config, profile } = getRunContext();
|
|
2718
3176
|
const scope = gatewayScope(config, profile);
|
|
@@ -2722,6 +3180,10 @@ async function shot(a, url, resolved, remaining, onMoves, tunnel) {
|
|
|
2722
3180
|
...gateway === "vertex" ? { vertex: vertexSettingsIn(scope.gateways) } : {}
|
|
2723
3181
|
});
|
|
2724
3182
|
}
|
|
3183
|
+
}).catch(async (error) => {
|
|
3184
|
+
const page = await session.page(origin).catch(() => void 0);
|
|
3185
|
+
if (page) tracePage(resolved.name, page);
|
|
3186
|
+
throw error;
|
|
2725
3187
|
});
|
|
2726
3188
|
onMoves(result.moves);
|
|
2727
3189
|
const spend = captureUseSpend(result);
|
|
@@ -2733,20 +3195,24 @@ async function shot(a, url, resolved, remaining, onMoves, tunnel) {
|
|
|
2733
3195
|
usage: addUsage(prev.usage, spend.usage)
|
|
2734
3196
|
} : spend;
|
|
2735
3197
|
}
|
|
2736
|
-
return
|
|
2737
|
-
|
|
3198
|
+
return {
|
|
3199
|
+
png: result.png,
|
|
3200
|
+
page: await session.page(origin)
|
|
3201
|
+
};
|
|
3202
|
+
}, a.signal).finally(async () => {
|
|
2738
3203
|
await proxy.close();
|
|
2739
3204
|
if (proxy.reached.length) debugLog("check", `c.capture ${resolved.name}: sandbox port ${proxy.reached.join(", ")} answered the page through its tunnel`);
|
|
2740
3205
|
});
|
|
2741
3206
|
}
|
|
2742
3207
|
/** Writes PNG sidecars next to the staging eval JSON so redact never sees the bytes. */
|
|
2743
|
-
async function writeCaptureSidecars(stagingDir, recordFile, blobs) {
|
|
3208
|
+
async function writeCaptureSidecars(stagingDir, recordFile, blobs, pages) {
|
|
2744
3209
|
if (blobs.size === 0) return;
|
|
2745
3210
|
const dir = join(stagingDir, "evals", recordFile.replace(/\.json$/, ".artifacts"));
|
|
2746
3211
|
await mkdir(dir, { recursive: true });
|
|
2747
3212
|
for (const [name, png] of blobs) await writeFile(join(dir, `${name}.png`), png);
|
|
3213
|
+
for (const [name, json] of pages) await writeFile(join(dir, `${name}.capture.json`), json);
|
|
2748
3214
|
}
|
|
2749
3215
|
//#endregion
|
|
2750
3216
|
export { writeCaptureSidecars as a, sandboxFor as c, workspaceFiles as d, fakeInstructions as f, startBackground as i, diffSinceSnapshot as l, msysTreeKill as n, asCheck as o, attemptRequestProblem as p, serveCommand as r, createChecks as s, capturePage as t, snapshot as u };
|
|
2751
3217
|
|
|
2752
|
-
//# sourceMappingURL=capture-
|
|
3218
|
+
//# sourceMappingURL=capture-DheNqeYS.js.map
|