{
  "version": 3,
  "sources": ["../../src/app/ai/agents/evals2/scenarios/layout/evenGridGaps.eval.ts"],
  "sourcesContent": ["import type { CanvasNode } from \"document/models/CanvasTree/nodes/CanvasNode.ts\"\nimport type { NodeID } from \"document/models/CanvasTree/nodes/NodeID.ts\"\nimport { RichTextNode } from \"document/models/CanvasTree/nodes/RichTextNode.ts\"\nimport { isGridChildFillingCellHeight } from \"document/models/CanvasTree/traits/WithGridItemSize.ts\"\nimport { convertFrameToCanvas } from \"document/models/CanvasTree/utils/geometry.ts\"\nimport { DimensionType } from \"library/index.ts\"\nimport { agentEvalAsset } from \"../../harness/asset.ts\"\nimport { createEvalExportZipFixture } from \"../../harness/fixture.ts\"\nimport { getChildFrames, getFrame } from \"../helpers.ts\"\n\nconst milestonesGridDesktopId = \"h7bQ8H9FG\" satisfies NodeID\nconst milestonesGridPhoneId = `riqpamRb9${milestonesGridDesktopId}` satisfies NodeID\nconst expectedCardCount = 4\nconst spacingTolerance = 1\n\nfunction hasTruncatedText(node: CanvasNode): boolean {\n\treturn Array.from(node.walk()).some(\n\t\tdescendant => descendant instanceof RichTextNode && Boolean(descendant.textTruncation),\n\t)\n}\n\n/**\n * Prompt: i mean the gap between all elements in the grid. it doesn't look like the cards are\n * evenly spaced even though they have the same gap. don't ask questions, just do it\n */\nevaluation(\n\t\"Even Grid Gaps\",\n\tcreateEvalExportZipFixture(\"replay-even-grid-gaps\", agentEvalAsset(\"evenGridGaps.fixture.zip\"), {\n\t\truntimeTarget: \"browser\",\n\t}),\n\t{\n\t\tid: \"even-grid-gaps\",\n\t\trequestId: \"R8JSdExzv\",\n\t\tmaxSteps: 3,\n\t},\n\t({ engine, report, tools }) => {\n\t\ttools.reportReplayChecks(report, {\n\t\t\trequestId: \"R8JSdExzv\",\n\t\t})\n\n\t\tconst desktopGrid = getFrame(engine, milestonesGridDesktopId)\n\n\t\treport.correctness.required(\"keeps grid layout on desktop\", () => {\n\t\t\texpect(desktopGrid.layout).toBe(\"grid\")\n\t\t})\n\n\t\treport.correctness.required(\"keeps all milestone cards\", () => {\n\t\t\texpect(getChildFrames(desktopGrid)).toHaveLength(expectedCardCount)\n\t\t})\n\n\t\tconst phoneGrid = getFrame(engine, milestonesGridPhoneId)\n\t\tconst phoneCards = getChildFrames(phoneGrid)\n\n\t\treport.correctness.required(\"uses grid or stack layout on phone\", () => {\n\t\t\texpect([\"grid\", \"stack\"]).toContain(phoneGrid.layout)\n\t\t})\n\n\t\treport.correctness.required(\"keeps all milestone cards on phone\", () => {\n\t\t\texpect(phoneCards).toHaveLength(expectedCardCount)\n\t\t})\n\n\t\treport.functionality.required(\"spacing between grid items is uniform\", () => {\n\t\t\texpect(phoneCards).toHaveLength(expectedCardCount)\n\n\t\t\tconst rects = phoneCards.map(card => convertFrameToCanvas(engine.tree, card)).sort((a, b) => a.y - b.y)\n\t\t\tconst gaps: number[] = []\n\t\t\tfor (let index = 1; index < rects.length; index++) {\n\t\t\t\tconst previous = rects[index - 1]\n\t\t\t\tconst current = rects[index]\n\t\t\t\tif (!previous || !current) continue\n\t\t\t\tgaps.push(current.y - (previous.y + previous.height))\n\t\t\t}\n\n\t\t\texpect(Math.max(...gaps) - Math.min(...gaps)).toBeLessThanOrEqual(spacingTolerance)\n\t\t})\n\n\t\treport.functionality.scored(\"grid items have the same height\", () => {\n\t\t\texpect(phoneCards).toHaveLength(expectedCardCount)\n\n\t\t\tconst heights = phoneCards.map(card => convertFrameToCanvas(engine.tree, card).height)\n\t\t\texpect(Math.max(...heights) - Math.min(...heights)).toBeLessThanOrEqual(spacingTolerance)\n\t\t})\n\n\t\t// Score how the agent evened out the spacing. A grid whose items fill the cell height is the\n\t\t// most robust fix; truncating text keeps the layout flexible; fixed heights are the most\n\t\t// rigid. Anything else scores 0.\n\t\treport.accuracy.scored(\"evens out spacing in a robust way\", () => {\n\t\t\tconst fillsCellHeight = phoneCards.some(card => isGridChildFillingCellHeight(card))\n\t\t\tif (fillsCellHeight) return 1\n\n\t\t\tconst truncatesText = phoneCards.some(card => hasTruncatedText(card))\n\t\t\tif (truncatesText) return 0.5\n\n\t\t\tconst hasFixedHeight = phoneCards.some(card => card.heightType === DimensionType.FixedNumber)\n\t\t\tif (hasFixedHeight) return 0.25\n\n\t\t\treturn 0\n\t\t})\n\n\t\t// Diagnostics: surface which strategy the agent used to even out the spacing. These are\n\t\t// informational only and excluded from scoring (the scored check above grades the run).\n\t\treport.accuracy.diagnostic(\"fills grid item cell height\", () => {\n\t\t\texpect(phoneCards.some(card => isGridChildFillingCellHeight(card))).toBe(true)\n\t\t})\n\n\t\treport.accuracy.diagnostic(\"truncates text inside grid items\", () => {\n\t\t\texpect(phoneCards.some(card => hasTruncatedText(card))).toBe(true)\n\t\t})\n\n\t\treport.accuracy.diagnostic(\"sets grid item height to fixed\", () => {\n\t\t\texpect(phoneCards.some(card => card.heightType === DimensionType.FixedNumber)).toBe(true)\n\t\t})\n\t},\n)\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,IAAM,0BAA0B;AAChC,IAAM,wBAAwB,YAAY,uBAAuB;AACjE,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AAEzB,SAAS,iBAAiB,MAA2B;AACpD,SAAO,MAAM,KAAK,KAAK,KAAK,CAAC,EAAE;AAAA,IAC9B,gBAAc,sBAAsB,gBAAgB,QAAQ,WAAW,cAAc;AAAA,EACtF;AACD;AAMA;AAAA,EACC;AAAA,EACA,2BAA2B,yBAAyB,eAAe,0BAA0B,GAAG;AAAA,IAC/F,eAAe;AAAA,EAChB,CAAC;AAAA,EACD;AAAA,IACC,IAAI;AAAA,IACJ,WAAW;AAAA,IACX,UAAU;AAAA,EACX;AAAA,EACA,CAAC,EAAE,QAAQ,QAAQ,MAAM,MAAM;AAC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