Rescue a Phase III study's enrollment before the steering committee

1,738 screening-log rows into site status, why screening fails, last-patient-in forecasts with and without mitigations, and a six-slide steering committee deck that says the mitigations gain 11 days.

Who
Veridian's clinical trial manager, in Claude with Artiwright's tools
Runs in
Claude
Hands over
.xlsxVRD-301_enrollment_model.xlsx.pptxVRD-301_steerco_enrollment.pptx
6 slides + 9 sheetsin 2 files, opened in Office
54 turns, 12 minone agent run in Claude on claude-opus-5-5, unedited

The ask

VRD-301 is behind on enrollment and the steering committee meets in two weeks. The CTMS screening log and site plan are here, and the study team's rules are in steerco_brief.md. Build the enrollment model (site status, enrollment against plan, why screening fails, and the last-patient-in forecast with and without mitigations) and the steering committee deck. The site totals must tie to the log. Spruce theme.

Veridian's clinical trial manager, in Claude with Artiwright's tools

VRD-301, a Phase III study across 38 sites, is behind its randomization plan and the steering committee meets in two weeks. Someone usually rebuilds the site tracker from the CTMS export by hand, and the numbers are stale by the meeting.

This is one real session in Claude with Artiwright's tools: the screening log, the site plan and the study team's rules. The agent builds the model, applies the red/amber/green rules, costs the mitigations and writes the deck, with a comment for the medical monitor.

What they handed over

Made-up data in the shape of a real export. Download it and try the ask yourself.

What came out

VRD-301_enrollment_model.xlsxExcel · 9 sheets · 106 KB
Download
VRD-301_steerco_enrollment.pptxPowerPoint · 6 slides · 57 KB
Download

Screenshots exported by PowerPoint and Excel.

What the agent noticed

It said the mitigations gain 11 days

HbA1c pre-screening from January and four backup sites from February move last patient in from 21 March to 10 March 2027, against a plan of 28 December 2026. Both start too late to matter much. The deck says so, names earlier backup activation as the lever, and warns that the run rate will fall: seven sites that stopped screening still gave 23 randomizations in the last three months.

It called the 10% lift a ceiling

The study team expects pre-screening to lift the run rate 10%. HbA1c caused 120 screen fails, equal to 10.0% of the 1,201 randomizations, so 10% holds only if every one of those patients would have randomized. The agent said so on the slide and left a comment asking the medical monitor whether sites can pre-screen with a local HbA1c result.

It checked its own formula against the log

The column counting screen fails at the three high-fail sites first totaled 6. The agent counted the same thing straight from the log, got 91, and rewrote the formula until the two agreed.

Build it yourself

VRD-301 is behind on enrollment and the steering committee meets in two weeks. The CTMS screening log and site plan are here, and the study team's rules are in steerco_brief.md. Build the enrollment model (site status, enrollment against plan, why screening fails, and the last-patient-in forecast with and without mitigations) and the steering committee deck. The site totals must tie to the log. Spruce theme.

Set Artiwright up in your app first: Quickstart for AI apps, Google ADK, LangGraph, Node.js.

Inside the workbook

9 sheets, laid out by the agent. In its words, sheet by sheet:

  1. The Summary sheet
    Summary

    Where the study stands: 1,201 of 1,700 randomized, 195 behind plan, 10 red, 7 amber and 21 green sites, and last patient in for seven scenarios.

  2. The Inputs sheet
    Inputs

    The target, status thresholds, run-rate window, trend start and mitigation assumptions, each with its source or marked as an assumption. A switch counts consent withdrawals as screen fails.

  3. The Sites sheet
    Sites

    All 38 sites: screened, randomized, screen-fail rate, days since the last screening and progress against plan, with the status and the reason. A table below sums each status group.

  4. The Monthly sheet
    Monthly

    Planned and actual randomizations by month from March 2025 to September 2026, and cumulatively.

Show all 9 sheets
  1. The Screen fails sheet
    Screen fails

    The eight fail reasons ranked, how many come from the three high-fail sites, the screening funnel, each country, and a cross-check of the pre-screening lift.

  2. The Forecast sheet
    Forecast

    Last patient in at the planned rate, the run rate, the trend, and with each mitigation, from monthly projections to December 2028.

  3. The Checks sheet
    Checks

    Twelve tie-outs between the log, the plan and the model. All come to zero.

  4. The Screening log sheet
    Screening log

    The CTMS export, 1,738 rows, as the table the formulas read.

  5. The Site plan sheet
    Site plan

    Each site's activation date and planned monthly rate.

How it got thereSee all 53 calls the agent made, what lint found and the finalize report

The run

One real session in Claude (claude-opus-5-5), with only Artiwright's tools and read access to the files above. Nothing below is edited: every call the agent made, what came back, and the renders it looked at.

  1. Glob*
    {
      "pattern": "**/*"
    }
    site_plan.csv
    screening_log.csv
    steerco_brief.md
  2. Readsteerco_brief.md
    {
      "file_path": "./work/steerco_brief.md"
    }
    1	# VRD-301: steering committee brief (from the clinical trial manager)
    2	
    3	- Randomization target: **1,700**. Data as of September 30, 2026 (the CTMS export).
    4	- Each site's plan starts the month after activation, at its planned rate (site_plan.csv).
    5	- Site status rules the study team agreed: **red** if screen-fail is above 35% or no screening in 30
    6	  days; **amber** if randomizations are more than 20% behind the site's plan to date.
    7	- Forecast last patient in: at the planned rate, at the last three months' run rate, and by trend.
    8	- Mitigations we want costed: activate 4 backup sites (about 2.5 randomizations a month each), and
    9	  HbA1c pre-screening, which we think lifts the run rate about 10%.
    10	- The steering committee meets in two weeks: about six slides, including the sites holding us back,
    11	  why screening fails, a revised timeline and the decisions. Leave a comment for the medical monitor
    12	  where their input is needed.
    13	
  3. Readsite_plan.csv
    {
      "file_path": "./work/site_plan.csv"
    }
    1	Site ID,Investigator,Country,Activated,Planned per month
    2	US-101,Dr. T. Halvorsen,United States,2025-05-09,3
    3	US-102,Dr. B. Mbeki,United States,2025-06-05,3
    4	US-103,Dr. J. Castellano,United States,2025-04-19,3
    5	US-104,Dr. S. Nowak,United States,2025-05-10,3
    6	US-105,Dr. E. Okafor,United States,2025-03-08,1.5
    7	US-106,Dr. C. Lindqvist,United States,2025-03-08,2.5
    8	US-107,Dr. M. Ferreira,United States,2025-05-10,1.5
    9	US-108,Dr. S. Tanaka,United States,2025-03-07,2.5
    10	US-109,Dr. H. Brennan,United States,2025-04-10,3
    11	US-110,Dr. E. Kowalczyk,United States,2025-03-05,2.5
    12	PL-101,Dr. E. Varga,Poland,2025-05-19,3.5
    13	PL-102,Dr. H. Ruiz,Poland,2025-03-11,2
    14	PL-103,Dr. G. Schreiber,Poland,2025-04-10,3
    15	PL-104,Dr. A. Petrov,Poland,2025-03-12,3
    16	PL-105,Dr. K. Achterberg,Poland,2025-04-17,3
    17	PL-106,Dr. E. Moreau,Poland,2025-05-12,3
    18	ES-101,Dr. S. Delgado,Spain,2025-11-09,3.5
    19	ES-102,Dr. B. Szabo,Spain,2025-07-05,2
    20	ES-103,Dr. R. Whitfield,Spain,2025-08-10,3.5
    21	ES-104,Dr. E. Ibarra,Spain,2025-07-05,3
    22	ES-105,Dr. A. Kim,Spain,2025-11-10,2.5
    23	DE-101,Dr. E. Lehmann,Germany,2025-07-13,3.5
    24	DE-102,Dr. E. Duarte,Germany,2025-10-19,3
    25	DE-103,Dr. H. Novak,Germany,2025-08-11,3
    26	DE-104,Dr. L. Osei,Germany,2025-06-19,2
    27	DE-105,Dr. E. Park,Germany,2025-08-16,2.5
    28	HU-101,Dr. P. Grabowski,Hungary,2025-12-03,2.5
    29	HU-102,Dr. G. Esposito,Hungary,2026-02-25,3
    30	HU-103,Dr. T. Hartley,Hungary,2025-12-11,2
    31	HU-104,Dr. T. Molnar,Hungary,2025-12-17,3.5
    32	BR-101,Dr. N. Santos,Brazil,2025-11-22,3.5
    33	BR-102,Dr. R. Vogel,Brazil,2026-02-10,3.5
    34	BR-103,Dr. R. Reyes,Brazil,2025-12-22,3
    35	BR-104,Dr. N. Abara,Brazil,2025-10-13,3
    36	KR-101,Dr. D. Lee,South Korea,2025-12-21,2
    37	KR-102,Dr. E. Kaminski,South Korea,2025-11-10,3
    38	KR-103,Dr. P. Ortega,South Korea,2025-10-05,2.5
    39	KR-104,Dr. E. Fischer,South Korea,2025-09-06,2
    40	
  4. Readscreening_log.csv
    {
      "file_path": "./work/screening_log.csv",
      "limit": 30
    }
    1	Subject ID,Site ID,Country,Screening date,Status,Randomized on,Criterion type,Fail reason
    2	US-110-001,US-110,United States,2025-03-06,Screen failed,,Inclusion,I-04 HbA1c outside 7.0-10.5%
    3	US-108-003,US-108,United States,2025-03-10,Randomized,2025-04-08,,
    4	PL-102-002,PL-102,Poland,2025-03-12,Randomized,2025-03-30,,
    5	US-108-002,US-108,United States,2025-03-15,Randomized,2025-04-07,,
    6	US-108-005,US-108,United States,2025-03-16,Screen failed,,Inclusion,I-04 HbA1c outside 7.0-10.5%
    7	US-106-001,US-106,United States,2025-03-17,Randomized,2025-04-05,,
    8	US-110-003,US-110,United States,2025-03-19,Screen failed,,Inclusion,I-04 HbA1c outside 7.0-10.5%
    9	US-108-004,US-108,United States,2025-03-22,Randomized,2025-04-16,,
    10	PL-104-001,PL-104,Poland,2025-03-24,Randomized,2025-04-11,,
    11	PL-104-002,PL-104,Poland,2025-03-24,Randomized,2025-04-21,,
    12	US-105-001,US-105,United States,2025-03-25,Randomized,2025-04-13,,
    13	US-110-002,US-110,United States,2025-03-27,Randomized,2025-04-26,,
    14	PL-102-001,PL-102,Poland,2025-03-30,Withdrawn,,Other,Consent withdrawn
    15	US-105-002,US-105,United States,2025-03-30,Randomized,2025-04-19,,
    16	US-108-001,US-108,United States,2025-03-30,Randomized,2025-04-24,,
    17	PL-104-003,PL-104,Poland,2025-04-02,Randomized,2025-05-02,,
    18	US-108-007,US-108,United States,2025-04-04,Randomized,2025-04-18,,
    19	US-110-004,US-110,United States,2025-04-05,Withdrawn,,Other,Consent withdrawn
    20	PL-104-005,PL-104,Poland,2025-04-06,Randomized,2025-05-01,,
    21	PL-104-008,PL-104,Poland,2025-04-06,Randomized,2025-04-25,,
    22	PL-104-006,PL-104,Poland,2025-04-08,Randomized,2025-05-08,,
    23	US-105-003,US-105,United States,2025-04-08,Randomized,2025-05-04,,
    24	PL-104-004,PL-104,Poland,2025-04-12,Randomized,2025-04-30,,
    25	US-106-004,US-106,United States,2025-04-14,Screen failed,,Inclusion,I-02 Age outside 30-80
    26	US-110-005,US-110,United States,2025-04-16,Screen failed,,Inclusion,I-06 UACR below 200 mg/g
    27	US-108-009,US-108,United States,2025-04-17,Screen failed,,Other,O-02 Screening window expired
    28	US-106-002,US-106,United States,2025-04-19,Screen failed,,Exclusion,E-11 CV event in past 6 months
    29	PL-104-007,PL-104,Poland,2025-04-20,Randomized,2025-05-17,,
    30	US-103-002,US-103,United States,2025-04-20,Randomized,2025-05-07,,
  5. ToolSearch
    {
      "query": "select:mcp__artiwright__artiwright_help,mcp__artiwright__artiwright_run,mcp__artiwright__artiwright_render,mcp__artiwright__artiwright_lint,mcp__artiwright__artiwright_inspect,mcp__artiwright__artiwright_finalize,mcp__artiwright__artiwright_status,mcp__artiwright__artiwright_import",
      "max_results": 10
    }
  6. artiwright_help
    {
      "query": "skill spreadsheets"
    }
    ---
    name: artiwright-spreadsheets
    description: Build native Excel workbooks (.xlsx) with Artiwright - live formulas that compute as you write them, tables, number formats, conditional formats, data validation and native charts, then render, lint and publish a checked file. Use when a user asks for a spreadsheet, workbook, financial or operating model, budget, tracker, dashboard or data "as Excel".
    ---
    
    # Artiwright spreadsheets
    
    You build workbooks as code against a live document. Formulas compute as you write them, so you
    can read results back, check them, and look at the sheet as an image before you publish.
    Everything you make stays native and editable in Excel: real formulas (not pasted values), tables,
    number formats, conditional formats, validation dropdowns and charts linked to the cells.
    
    ## The loop
    
    1. **Plan the sheets.** Inputs (assumptions the user can change) → calculations → outputs
       (summary, charts). Decide the rows, columns and units before writing. Never invent numbers:
       ask, or label an assumption clearly as one.
    2. **Build** a sheet or a whole section per call: values, then formulas, then formats.
    3. **Look.** Render each sheet (`artiwright_render`) and read key results back (`return` a range,
       or `artiwright_inspect` with kind `formula`).
    4. **Check** with lint: formula errors, cycles, `####` columns, numbers stored as text, typed-in
       numbers in formulas. Fix everything in one call, then look again.
    5. **Publish** with finalize, stating requirements: the sheets, tables and charts that must exist
       and key cells with the values they must hold (`{ cell: "Checks!B2", equals: 0 }`).
    
    ## Work in few calls
    
    Every call resends the whole conversation, so a workbook made in 4 calls costs a fraction of one
    made in 25. When the user gives the data, this is usually enough:
    
    1. **One `artiwright_run` that builds every sheet**: rename `Sheet1`, write inputs, formulas,
       formats, tables, rules and charts, and `return` the key result cells to read them back.
    2. **`artiwright_lint`**. If it reports problems, fix them all in **one** run.
    3. **`artiwright_finalize`** with requirements (sheets, tables, charts, key cell values).
    
    - Don't probe the API with small runs: the calls on this page are enough. Use `help` only for
      something it doesn't show (`help("range.format")`, `help("functions")`).
    - One formula fills a range adjusted per row: `sheet
    …
  7. artiwright_help
    {
      "query": "skill presentations"
    }
    ---
    name: artiwright-presentations
    description: Build native, editable PowerPoint decks (.pptx) with Artiwright - plan the story, compose slides from layout recipes with real charts and tables, render and lint them, fix problems by anchor, and publish a checked file. Use when a user asks for a presentation, deck, slides, a QBR, a pitch, or a report "as PowerPoint".
    ---
    
    # Artiwright presentations
    
    You build decks as code against a live document, look at what you built, fix it, and publish a file
    that has been checked. Every object has an anchor (`sl_…` slides, `sh_…` shapes, `ch_…` charts,
    `tb_…` tables, `im_…` pictures) that stays the same across calls, so you can point at exactly what
    to change.
    
    ## The loop
    
    1. **Plan.** Who is the audience and what should they conclude? Write one message per slide. A slide
       that reports a finding gets a headline sentence with the claim ("Enterprise drove 48% of new
       ARR", not "Revenue"); a slide that sets something up (agenda, process, method, team) gets a plain
       name for what it shows ("How a renewal is approved"). Gather the facts first (from the user,
       files or other agents); never invent numbers. A requested slide count is the total, title
       slide included.
    2. **Build** each slide from a layout recipe (`references/recipes.md`), with native charts and
       tables. A recipe slide is a few lines of code and comes out aligned, readable and lint clean;
       boxes placed by hand take many times the code, and are where overlaps, small text and crowded
       slides come from. Place shapes yourself only for a slide no recipe fits.
    3. **Look.** Render the slides (a contact sheet first, then single slides you doubt) and lint.
    4. **Fix** by anchor, then look again. Repeat until lint has no errors.
    5. **Review** as the audience will: the headlines alone, the copy on each slide (the `writing`
       guide), and the contact sheet for slides that look alike but say different kinds of things.
       Lint checks that slides are built right, not that they read well. Fix what you find.
    6. **Publish** with finalize, stating requirements (slide count, which slides need native charts).
       Tell the user what the deck contains and anything you could not do.
    
    ## Decks from a workbook
    
    When the deck reports on a workbook in the same session, take every figure from the workbook. In
    one `artiwright_run` on the workbook, return the values the slides ne
    …
  8. artiwright_status
    {}
    {
      "id": "default",
      "createdAt": "2026-11-15T23:21:02.967Z",
      "updatedAt": "2026-11-15T23:21:02.967Z",
      "documents": []
    }
  9. artiwright_importscreening_log.csv
    {
      "path": "./work/screening_log.csv",
      "document": "model",
      "sheet": "Screening log",
      "table": "Log",
      "theme": "spruce",
      "dates": "iso"
    }
    {
      "ok": true,
      "value": {
        "sheet": "Screening log",
        "range": "A1:H1739",
        "rows": 1738,
        "columns": [
          "Subject ID",
          "Site ID",
          "Country",
          "Screening date",
          "Status",
          "Randomized on",
          "Criterion type",
          "Fail reason"
        ],
        "firstRows": [
          [
            "US-110-001",
            "US-110",
            "United States",
            45722,
            "Screen failed",
            null,
            "Inclusion",
            "I-04 HbA1c outside 7.0-10.5%"
          ],
          [
            "US-108-003",
            "US-108",
            "United States",
            45726,
            "Randomized",
            45755,
            null,
            null
          ],
          [
            "PL-102-002",
            "PL-102",
            "Poland",
            45728,
            "Randomized",
            45746,
            null,
            null
          ]
        ],
        "table": "Log"
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Screening log"
      ],
      "version": 1,
      "lint": {
        "errors": 0,
        "warnings": 1
      },
      "next": "Use the table in formulas, e.g. =SUM(Log[column]); import the next file the same way."
    }
  10. artiwright_importsite_plan.csv
    {
      "path": "./work/site_plan.csv",
      "document": "model",
      "sheet": "Site plan",
      "table": "Plan",
      "dates": "iso"
    }
    {
      "ok": true,
      "value": {
        "sheet": "Site plan",
        "range": "A1:E39",
        "rows": 38,
        "columns": [
          "Site ID",
          "Investigator",
          "Country",
          "Activated",
          "Planned per month"
        ],
        "firstRows": [
          [
            "US-101",
            "Dr. T. Halvorsen",
            "United States",
            45786,
            3
          ],
          [
            "US-102",
            "Dr. B. Mbeki",
            "United States",
            45813,
            3
          ],
          [
            "US-103",
            "Dr. J. Castellano",
            "United States",
            45766,
            3
          ]
        ],
        "table": "Plan"
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Screening log",
        "Site plan"
      ],
      "version": 2,
      "lint": {
        "errors": 0,
        "warnings": 1
      },
      "next": "Use the table in formulas, e.g. =SUM(Plan[column]); import the next file the same way."
    }
  11. Both files are loaded into a workbook. Next I'm profiling the log for data-quality issues (duplicates, odd statuses, sites missing from the plan) before I build the model.

  12. artiwright_run
    const log = workbook.sheets.get("Screening log").range("A2:H1739").values;
    const plan = workbook.sheets.get("Site plan").range("A2:E39").values;
    const planIds = new Set(plan.map(r=>r[0]));
    const cnt = (arr)=>arr.reduce((m,k)=>(m[k]=(m[k]||0)+1,m),{});
    const ids = cnt(log.map(r=>r[0]));
    const dupIds = Object.entries(ids).filter(([k,v])=>v>1);
    const dupRows = log.filter(r=>ids[r[0]]>1).slice(0,20);
    const siteStr = cnt(log.map(r=>JSON.stringify(r[1])));
    const notInPlan = Object.keys(siteStr).filter(k=>!planIds.has(JSON.parse(k)));
    const status = cnt(log.map(r=>JSON.stringify(r[4])));
    const crit = cnt(log.map(r=>r[6]+" | "+r[7]));
    const types = cnt(log.map(r=>typeof r[3]+"/"+typeof r[5]));
    const randNoDate = log.filter(r=>/rand/i.test(r[4]||"") && !r[5]).length;
    const dateNoRand = log.filter(r=>!/^Randomized$/.test(r[4]||"") && r[5]).length;
    const subjSiteMismatch = log.filter(r=>!String(r[0]).startsWith(String(r[1]))).slice(0,10);
    const countryMismatch = log.filter(r=>{const p=plan.find(x=>x[0]===r[1]); return p && p[2]!==r[2];}).slice(0,10);
    const dates = log.map(r=>r[3]).filter(x=>typeof x==="number");
    const rd = log.map(r=>r[5]).filter(x=>typeof x==="number");
    const badOrder = log.filter(r=>typeof r[5]==="number" && r[5]<r[3]).length;
    const nonNumDates = log.filter(r=>typeof r[3]!=="number"||(r[5]!=null&&typeof r[5]!=="number")).slice(0,10);
    return {dupIds:dupIds.length, dupRows, siteStr, notInPlan, status, crit, types, randNoDate, dateNoRand, subjSiteMismatch, countryMismatch, minS:Math.min(...dates), maxS:Math.max(...dates), minR:Math.min(...rd), maxR:Math.max(...rd), badOrder, nonNumDates};
    {
      "ok": true,
      "value": {
        "dupIds": 0,
        "dupRows": [],
        "siteStr": {
          "\"US-110\"": 44,
          "\"US-108\"": 74,
          "\"PL-102\"": 38,
          "\"US-106\"": 45,
          "\"PL-104\"": 85,
          "\"US-105\"": 26,
          "\"US-103\"": 43,
          "\"US-109\"": 66,
          "\"PL-105\"": 76,
          "\"US-104\"": 99,
          "\"US-101\"": 40,
          "\"PL-103\"": 39,
          "\"US-107\"": 41,
          "\"PL-106\"": 64,
          "\"PL-101\"": 85,
          "\"US-102\"": 74,
          "\"DE-104\"": 25,
          "\"ES-102\"": 37,
          "\"ES-104\"": 52,
          "\"DE-101\"": 65,
          "\"ES-103\"": 35,
          "\"DE-105\"": 36,
          "\"DE-103\"": 35,
          "\"KR-104\"": 40,
          "\"BR-104\"": 51,
          "\"KR-103\"": 20,
          "\"DE-102\"": 45,
          "\"ES-101\"": 55,
          "\"KR-102\"": 33,
          "\"ES-105\"": 32,
          "\"BR-101\"": 33,
          "\"HU-101\"": 36,
          "\"HU-103\"": 28,
          "\"KR-101\"": 15,
          "\"BR-103\"": 38,
          "\"HU-104\"": 44,
          "\"BR-102\"": 21,
          "\"HU-102\"": 23
        },
        "notInPlan": [],
        "status": {
          "\"Screen failed\"": 393,
          "\"Randomized\"": 1201,
          "\"Withdrawn\"": 77,
          "\"In screening\"": 67
        },
        "crit": {
          "Inclusion | I-04 HbA1c outside 7.0-10.5%": 120,
          "null | null": 1268,
          "Other | Consent withdrawn": 77,
          "Inclusion | I-02 Age outside 30-80": 15,
          "Inclusion | I-06 UACR below 200 mg/g": 51,
          "Other | O-02 Screening window expired": 18,
          "Exclusion | E-11 CV event in past 6 months": 35,
          "Exclusion | E-15 SGLT2 inhibitor in past 8 weeks": 30,
          "Exclusion | E-07 eGFR below 25": 95,
          "Exclusion | E-03 Uncontrolled blood pressure": 29
        },
        "types": {
          "number/object": 537,
          "number/number": 1201
        },
        "randNoDate": 0,
        "dateNoRand": 0,
        "subjSiteMismatch": [],
        "countryMismatch": [],
        "minS": 45722,
        "maxS": 46294,
        "minR": 45746,
        "maxR": 46295,
        "badOrder": 0,
        "nonNumDates": []
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Screening log",
        "Site plan"
      ],
      "version": 2,
      "lint": {
        "errors": 0,
        "warnings": 1
      }
    }
  13. artiwright_run
    const log = workbook.sheets.get("Screening log").range("A2:H1739").values;
    const plan = workbook.sheets.get("Site plan").range("A2:E39").values;
    const toD = s=>new Date(Date.UTC(1899,11,30)+s*864e5);
    const ym = s=>{const d=toD(s);return d.getUTCFullYear()*100+d.getUTCMonth()+1};
    const mR={}, mS={};
    log.forEach(r=>{mS[ym(r[3])]=(mS[ym(r[3])]||0)+1; if(r[5]) mR[ym(r[5])]=(mR[ym(r[5])]||0)+1;});
    const asof = 46295; // 2026-09-30
    const sites = plan.map(p=>{
      const rows = log.filter(r=>r[1]===p[0]);
      const R = rows.filter(r=>r[4]==="Randomized").length, SF=rows.filter(r=>r[4]==="Screen failed").length, W=rows.filter(r=>r[4]==="Withdrawn").length, IS=rows.filter(r=>r[4]==="In screening").length;
      const a=toD(p[3]); const start = a.getUTCFullYear()*12+a.getUTCMonth()+1; const end = 2026*12+8; const months = Math.max(0,end-start+1);
      const planTD = months*p[4];
      const last = Math.max(...rows.map(r=>r[3]));
      const days = asof-last;
      const sfA = SF/(SF+R+W), sfB = SF/(SF+R);
      return [p[0], R, SF, W, IS, months, planTD, +(R/planTD).toFixed(2), days, +sfA.toFixed(3), +sfB.toFixed(3)];
    });
    const totalRate = plan.reduce((a,p)=>a+p[4],0);
    return {mR, mS, totalRate, sites};
    {
      "ok": true,
      "value": {
        "mR": {
          "202503": 1,
          "202504": 13,
          "202505": 16,
          "202506": 32,
          "202507": 31,
          "202508": 63,
          "202509": 43,
          "202510": 55,
          "202511": 61,
          "202512": 71,
          "202601": 86,
          "202602": 88,
          "202603": 88,
          "202604": 102,
          "202605": 97,
          "202606": 90,
          "202607": 102,
          "202608": 75,
          "202609": 87
        },
        "mS": {
          "202503": 15,
          "202504": 24,
          "202505": 41,
          "202506": 55,
          "202507": 70,
          "202508": 76,
          "202509": 70,
          "202510": 89,
          "202511": 83,
          "202512": 122,
          "202601": 115,
          "202602": 120,
          "202603": 133,
          "202604": 131,
          "202605": 125,
          "202606": 134,
          "202607": 110,
          "202608": 112,
          "202609": 113
        },
        "totalRate": 105,
        "sites": [
          [
            "US-101",
            34,
            2,
            3,
            1,
            16,
            48,
            0.71,
            7,
            0.051,
            0.056
          ],
          [
            "US-102",
            59,
            8,
            4,
            3,
            15,
            45,
            1.31,
            2,
            0.113,
            0.119
          ],
          [
            "US-103",
            31,
            8,
            4,
            0,
            17,
            51,
            0.61,
            63,
            0.186,
            0.205
          ],
          [
            "US-104",
            46,
            42,
            6,
            5,
            16,
            48,
            0.96,
            1,
            0.447,
            0.477
          ],
          [
            "US-105",
            19,
            4,
            2,
            1,
            18,
            27,
            0.7,
            1,
            0.16,
            0.174
          ],
          [
            "US-106",
            32,
            10,
            1,
            2,
            18,
            45,
            0.71,
            13,
            0.233,
            0.238
          ],
          [
            "US-107",
            28,
            9,
            2,
            2,
            16,
            24,
            1.17,
            11,
            0.231,
            0.243
          ],
          [
            "US-108",
            49,
            19,
            3,
            3,
            18,
            45,
            1.09,
            7,
            0.268,
            0.279
          ],
          [
            "US-109",
            44,
            15,
            3,
            4,
            17,
            51,
            0.86,
            6,
            0.242,
            0.254
          ],
          [
            "US-110",
            21,
            20,
            3,
            0,
            18,
            45,
        
    …
  14. artiwright_runerror
    const wb = workbook;
    // ---------- Inputs ----------
    const inp = wb.sheets.add("Inputs");
    inp.range("A1").values = [["VRD-301 enrollment model: inputs"]];
    inp.range("A1").format({ bold: true, size: 14 });
    inp.range("A3:C3").values = [["Input", "Value", "Source"]];
    const rows = [
      ["Data as of (CTMS export)", "=DATE(2026,9,30)", "Steering committee brief"],
      ["Randomization target", 1700, "Steering committee brief"],
      ["Red: screen-fail rate above", 0.35, "Study team status rules"],
      ["Red: days without screening above", 30, "Study team status rules"],
      ["Amber: randomizations behind plan to date by more than", 0.2, "Study team status rules"],
      ["Count consent withdrawals as screen fails (Yes/No)", "No", "Assumption: CTMS status 'Withdrawn' kept separate from 'Screen failed'"],
      ["Run rate: months averaged", 3, "Steering committee brief (last three months)"],
      ["Trend: fit from month", "=DATE(2026,3,1)", "Assumption: first month all 38 sites were on plan (HU-102 activated Feb 2026)"],
      ["Backup sites activated", 4, "Steering committee brief"],
      ["Backup site rate (randomizations per site per month)", 2.5, "Steering committee brief"],
      ["Backup sites first randomize in", "=DATE(2027,2,1)", "Assumption: activated Jan 2027, plan starts the month after"],
      ["HbA1c pre-screening lift to run rate", 0.10, "Steering committee brief (study team estimate)"],
      ["HbA1c pre-screening live from", "=DATE(2027,1,1)", "Assumption: about a month after the steering committee decision"],
    ];
    inp.range("A4:C16").values = rows;
    const names = ["AsOf","Target","RedSF","SilentDays","AmberGap","CountWithdrawn","RunMonths","TrendStart","BackupSites","BackupRate","BackupStart","PreLift","PreStart"];
    names.forEach((n,i)=>wb.names.add(n, `Inputs!$B$${4+i}`));
    inp.range("A3:C3").format({ bold: true, fill: "accent1", color: "white" });
    inp.range("B4:B16").format({ color: "blue-700", fill: "blue-50" });
    ["B4","B11","B14","B16"].forEach(c=>inp.range(c).numberFormat="d mmm yyyy");
    ["B6","B8","B15"].forEach(c=>inp.range(c).numberFormat="0%");
    inp.range("B5").numberFormat="#,##0";
    inp.validations.add("B9", { type: "list", values: ["Yes","No"], error: "Yes or No" });
    inp.setColumnWidth("A", 380).setColumnWidth("B", 110).setColumnWidth("C", 470);
    
    // ---------- Sites ----------
    const s = wb.sheets.add("Sites");
    const hdr = ["Site ID","Investigator","Country","Activated","Planned per month","Plan start","Months on plan","Plan to date","Screened","Randomized","Screen failed","Withdrawn","In screening","Plan achieved","Versus plan","Screen-fail rate","Last screening","Days since screening","Randomized last 3 months","Status","Why"];
    s.range("A1:U1").values = [hdr];
    const n = 38, last = n+1;
    s.range(`A2:A${last}`).formulas = "='Site plan'!A2";
    s.range(`B2:B${last}`).formulas = "='Site plan'!B2";
    s.range(`C2:C${last}`).formulas = "='Site plan'!C2";
    s.range(`D2:D${last}`).formulas = "='Site plan'!D2";
    s.range(`E2:E${last}`).formulas = "='Site plan'!E2";
    s.range(`F2:F${last}`).formulas = "=EOMONTH(D2,0)+1";
    s.range(`G2:G${last}`).formulas = "=MAX(0,(YEAR(AsOf)-YEAR(F2))*12+MONTH(AsOf)-MONTH(F2)+1)";
    s.range(`H2:H${last}`).formulas = "=G2*E2";
    s.range(`I2:I${last}`).formulas = "=COUNTIFS(Log[Site ID],A2)";
    s.range(`J2:J${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Randomized")';
    s.range(`K2:K${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Screen failed")';
    s.range(`L2:L${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Withdrawn")';
    s.range(`M2:M${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"In screening")';
    s.range(`N2:N${last}`).formulas = "=IFERROR(J2/H2,0)";
    s.range(`O2:O${last}`).formulas = "=J2-H2";
    s.range(`P2:P${last}`).formulas = '=IFERROR((K2+IF(CountWithdrawn="Yes",L2,0))/(J2+K2+L2),0)';
    s.range(`Q2:Q${last}`).formulas = "=MAXIFS(Log[Screening date],Log[Site ID],A2)";
    s.range(`R2:R${last}`).formulas = "=AsOf-Q2";
    s.range(`S2:S${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Randomized on],">"&EDATE(AsOf,-RunMonths),Log[Randomized on],"<="&AsOf)';
    s.range(`T2:T${last}`).formulas = '=IF(OR(P2>RedSF,R2>SilentDays),"Red",IF(J2<H2*(1-AmberGap),"Amber","Green"))';
    s.range(`U2:U${last}`).formulas = '=TEXTJOIN("; ",TRUE,IF(P2>RedSF,"screen-fail "&TEXT(P2,"0%"),""),IF(R2>SilentDays,"no screening for "&R2&" days",""),IF(J2<H2*(1-AmberGap),TEXT(1-N2,"0%")&" behind plan",""))';
    s.tables.add(`A1:U${last}`, { name: "Sites" });
    const t = last+1;
    s.range(`A${t}`).values = [["Total"]];
    ["E","H","I","J","K","L","M","O","S"].forEach(c=>s.range(`${c}${t}`).formulas = `=SUM(${c}2:${c}${last})`);
    s.range(`N${t}`).formulas = `=J${t}/H${t}`;
    s.range(`P${t}`).formulas = `=(K${t}+IF(CountWithdrawn="Yes",L${t},0))/(J${t}+K${t}+L${t})`;
    s.range(`Q${t}`).formulas = `=MAX(Q2:Q${last})`;
    s.range(`T${t}`).formulas = `=COUNTIF(T2:T${last},"Red")&" red, "&COUNTIF(T2:T${last},"Amber")&" amber, "&COUNTIF(T2:T${last},"Green")&" green"`;
    s.range(`A${t}:U${t}`).format({ bold: true, borderTop: "medium" });
    s.range(`D2:D${t}`).numberFormat = "d mmm yyyy";
    s.range(`F2:F${t}`).numberFormat = "mmm yyyy";
    s.range(`Q2:Q${t}`).numberFormat = "d mmm yyyy";
    s.range(`E2:E${t}`).numberFormat = "0.0";
    s.range(`H2:H${t}`).numberFormat = "#,##0.0";
    s.range(`I2:M${t}`).numberFormat = "#,##0";
    s.range(`N2:N${t}`).numberFormat = "0%";
    s.range(`O2:O${t}`).numberFormat = "+#,##0.0;-#,##0.0;0";
    s.range(`P2:P${t}`).numberFormat = "0.0%";
    s.range(`R2:S${t}`).numberFormat = "#,##0";
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Red", format: { color: "red-800", fill: "red-100" } });
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Amber", format: { color: "amber-800", fill: "amber-100" } });
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Green", format: { color: "green-800", fill: "green-100" } });
    s.setColumnWidth("A", 70).setColumnWidth("B", 130).setColumnWidth("C", 110).setColumnWidth("D:S", 92).setColumnWidth("T", 70).setColumnWidth("U", 330);
    s.range("A1:U1").format({ wrap: true });
    s.freeze(1, 1);
    
    // ---------- Monthly ----------
    const m = wb.sheets.add("Monthly");
    m.range("A1:I1").values = [["Month","Month no.","Sites on plan","Planned","Screened","Randomized","Cumulative plan","Cumulative randomized","Versus plan"]];
    const mr = 20; // Mar 2025..Sep 2026 = 19 months, rows 2..20
    m.range("A2").formulas = "=DATE(YEAR(MIN(Log[Screening date])),MONTH(MIN(Log[Screening date])),1)";
    m.range(`A3:A${mr}`).formulas = "=EDATE(A2,1)";
    m.range(`B2:B${mr}`).formulas = "=12*YEAR(A2)+MONTH(A2)";
    m.range(`C2:C${mr}`).formulas = '=COUNTIFS(Sites[Plan start],"<="&A2)';
    m.range(`D2:D${mr}`).formulas = '=SUMIFS(Sites[Planned per month],Sites[Plan start],"<="&A2)';
    m.range(`E2:E${mr}`).formulas = '=COUNTIFS(Log[Screening date],">="&A2,Log[Screening date],"<="&EOMONTH(A2,0))';
    m.range(`F2:F${mr}`).formulas = '=COUNTIFS(Log[Randomized on],">="&A2,Log[Randomized on],"<="&EOMONTH(A2,0))';
    m.range("G2").formulas = "=D2"; m.range(`G3:G${mr}`).formulas = "=G2+D3";
    m.range("H2").formulas = "=F2"; m.range(`H3:H${mr}`).formulas = "=H2+F3";
    m.range(`I2:I${mr}`).formulas = "=H2-G2";
    m.tables.add(`A1:I${mr}`, { name: "Monthly" });
    m.range(`A2:A${mr}`).numberFormat = "mmm yyyy";
    m.range(`D2:D${mr}`).numberFormat = "#,##0.0";
    m.range(`G2:G${mr}`).numberFormat = "#,##0";
    m.range(`I2:I${mr}`).numberFormat = "+#,##0;-#,##0;0";
    m.setColumnWidth("A:I", 105);
    m.charts.add("line", { data: `A1:A${mr}`, series: [{ name: "Cumulative plan", values: `G2:G${mr}` }, { name: "Cumulative randomized", values: `H2:H${mr}` }], at: "K2", title: "Cumulative randomizations against plan" });
    
    // ---------- Screen fails ----------
    const f = wb.sheets.add("Screen fails");
    f.range("A1").values = [["Why screening fails (CTMS status 'Screen failed')"]];
    f.range("A1").format({ bold: true, size: 14 });
    f.range("A3:H3").values = [["Code","Reason","Criterion type","Screen fails","Share of screen fails","Cumulative share","Share of completed screenings","At sites over the screen-fail limit"]];
    const reasons = ["I-04 HbA1c outside 7.0-10.5%","E-07 eGFR below 25","I-06 UACR below 200 mg/g","E-11 CV event in past 6 months","E-15 SGLT2 inhibitor in past 8 weeks","E-03 Uncontrolled blood pressure","O-02 Screening window expired","I-02 Age outside 30-80"];
    f.range("B4:B11").values = reasons.map(r=>[r]);
    f.range("A4:A11").formulas = '=TEXTBEFORE(B4," ")';
    f.range("C4:C11").formulas = '=XLOOKUP(B4,Log[Fail reason],Log[Criterion type])';
    f.range("D4:D11").formulas = '=COUNTIFS(Log[Fail reason],B4,Log[Status],"Screen failed")';
    f.range("E4:E11").formulas = "=D4/$D$12";
    f.range("F4").formulas = "=E4"; f.range("F5:F11").formulas = "=F4+E5";
    f.range("G4:G11").formulas = "=D4/$B$17";
    f.range("H4:H11").formulas = '=SUMPRODUCT(COUNTIFS(Log[Site ID],Sites[Site ID],Log[Fail reason],B4,Log[Status],"Screen failed")*(Sites[Screen-fail rate]>RedSF))';
    f.tables.add("A3:H11", { name: "FailReasons" });
    f.range("A12").values = [["Total"]];
    f.range("D12").formulas = "=SUM(D4:D11)"; f.range("E12").formulas = "=SUM(E4:E11)"; f.range("G12").formulas = "=D12/$B$17"; f.range("H12").formulas = "=SUM(H4:H11)";
    f.range("A12:H12").format({ bold: true, borderTop: "medium" });
    f.range("E4:G12").numberFormat = "0.0%";
    f.range("A15:B15").values = [["Screening funnel", "Subjects"]];
    f.range("A16:A22").values = [["Screened"],["Completed screening (randomized, failed or withdrawn)"],["Randomized"],["Screen failed"],["Consent withdrawn during screening"],["Still in screening"],["Overall screen-fail rate"]];
    f.range("B16").formulas = "=ROWS(Log[Subject ID])";
    f.range("B17").formulas = "=B18+B19+B20";
    f.range("B18").formulas = '=COUNTIF(Log[Status],"Randomized")';
    f.range("B19").formulas = '=COUNTIF(Log[Status],"Screen failed")';
    f.range("B20").formulas = '=COUNTIF(Log[Status],"Withdrawn")';
    f.range("B21").formulas = '=COUNTIF(Log[Status],"In screening")';
    f.range("B22").formulas = '=(B19+IF(CountWithdrawn="Yes",B20,0))/B17';
    f.range("B22").numberFormat = "0.0%";
    f.range("A24:B24").values = [["Pre-screening cross-check", "Value"]];
    f.range("A25:A27").values = [["HbA1c (I-04) screen fails"],["HbA1c fails per randomization: the most pre-screening could add if every one became a randomization"],["Lift assumed in the forecast"]];
    f.range("B25").formulas = "=D4"; f.range("B26").formulas = "=B25/B18"; f.range("B27").formulas = "=PreLift";
    f.range("B26:B27").numberFormat = "0.0%";
    f.range("A15:B15").format({ bold: true, borderBottom: "medium" });
    f.range("A24:B24").format({ bold: true, borderBottom: "medium" });
    // by country
    f.range("D15:J15").values = [["Country","Sites","Screened","Randomized","Screen failed","Screen-fail rate","Plan achieved"]];
    const countries = ["United States","Poland","Spain","Germany","Hungary","Brazil","South Korea"];
    f.range("D16:D22").values = countries.map(c=>[c]);
    f.range("E16:E22").formulas = "=COUNTIFS(Sites[Country],D16)";
    f.range("F16:F22").formulas = "=SUMIFS(Sites[Screened],Sites[Country],D16)";
    f.range("G16:G22").formulas = "=SUMIFS(Sites[Randomized],Sites[Country],D16)";
    f.range("H16:H22").formulas = "=SUMIFS(Sites[Screen failed],Sites[Country],D16)";
    f.range("I16:I22").formulas = '=(H16+IF(CountWithdrawn="Yes",SUMIFS(Sites[Withdrawn],Sites[Country],D16),0))/(G16+H16+SUMIFS(Sites[Withdrawn],Sites[Country],D16))';
    f.range("J16:J22").formulas = "=G16/SUMIFS(Sites[Plan to date],Sites[Country],D16)";
    f.range("D15:J15").format({ bold: true, borderBottom: "medium" });
    f.range("I16:J22").numberFormat = "0%";
    f.setColumnWidth("A", 330).setColumnWidth("B", 230).setColumnWidth("C:H", 105);
    f.range("A3:H3").format({ wrap: true });
    f.charts.add("bar", { data: "B3:B11", series: [{ name: "Screen fails", values: "D4:D11" }], at: "L3", title: "Screen fails by reason" });
    
    // ---------- Forecast ----------
    const fc = wb.sheets.add("Forecast");
    fc.range("A1").values = [["Last-patient-in forecast (from the month after the data cut)"]];
    fc.range("A1").format({ bold: true, size: 14 });
    fc.range("A3:B3").values = [["Starting point and rates","Value"]];
    fc.range("A4:A9").values = [["Randomized to date"],["Still to randomize"],["Original plan to date"],["Planned rate, all 38 sites (per month)"],["Run rate, last months averaged (per month)"],["Trend slope since fit month (change per month)"]];
    fc.range("B4").formulas = "=SUM(Sites[Randomized])";
    fc.range("B5").formulas = "=Target-B4";
    fc.range("B6").formulas = "=SUM(Sites[Plan to date])";
    fc.range("B7").formulas = "=SUM(Plan[Planned per month])";
    fc.range("B8").formulas = '=SUMIFS(Monthly[Randomized],Monthly[Month],">"&EDATE(AsOf,-RunMonths))/RunMonths';
    fc.range("B9").formulas = "=SLOPE(FILTER(Monthly[Randomized],Monthly[Month]>=TrendStart),FILTER(Monthly[Month no.],Monthly[Month]>=TrendStart))";
    fc.range("B4:B7").numberFormat = "#,##0"; fc.range("B8:B9").numberFormat = "#,##0.0";
    fc.range("A3:B3").format({ bold: true, borderBottom: "medium" });
    // LPI summary
    fc.range("A11:D11").values = [["Scenario","Last patient in","Months later than original plan","Days earlier than run rate alone"]];
    const scen = ["Original plan","At planned rate","At run rate","By trend","Run rate + HbA1c pre-screening","Run rate + backup sites","Run rate + both mitigations"];
    fc.range("A12:A18").values = scen.map(x=>[x]);
    const R0 = 22, R1 = 48; // monthly rows Oct 2026..Dec 2028
    const cumCols = ["C","D","E","F","G","H","I"], monCols = ["J","K","L","M","N","O","P"];
    scen.forEach((sc,i)=>{
      const c = cumCols[i], mcol = monCols[i], start = i===0 ? "$B$6" : "$B$4";
      fc.range(`B${12+i}`).formulas = `=LET(c,${c}${R0}:${c}${R1},m,${mcol}${R0}:${mcol}${R1},d,$A$${R0}:$A$${R1},i,XMATCH(TRUE,c>=Target),prev,IF(i=1,${start},INDEX(c,i-1)),INDEX(d,i)+ROUNDUP((Target-prev)/INDEX(m,i)*DAY(EOMONTH(INDEX(d,i),0)),0)-1)`;
    });
    fc.range("C12:C18").formulas = "=(B12-$B$12)/(365.25/12)";
    fc.range("D12:D18").formulas = "=$B$14-B12";
    fc.range("B12:B18").numberFormat = "d mmm yyyy";
    fc.range("C12:C18").numberFormat = "0.0";
    fc.range("D12:D18").numberFormat = "#,##0;-#,##0;0";
    fc.range("A11:D11").format({ bold: true, fill: "accent1", color: "white", wrap: true });
    // monthly projection
    fc.range(`A${R0-1}:P${R0-1}`).values = [["Month","Target","Cum. original plan","Cum. at planned rate","Cum. at run rate","Cum. by trend","Cum. run rate + pre-screening","Cum. run rate + backup sites","Cum. run rate + both","Original plan","At planned rate","At run rate","By trend","Run rate + pre-screening","Run rate + backup sites","Run rate + both"]];
    fc.range(`A${R0}`).formulas = "=EOMONTH(AsOf,0)+1";
    fc.range(`A${R0+1}:A${R1}`).formulas = `=EDATE(A${R0},1)`;
    fc.range(`B${R0}:B${R1}`).formulas = "=Target";
    fc.range(`J${R0}:J${R1}`).formulas = "=$B$7";
    fc.range(`K${R0}:K${R1}`).formulas = "=$B$7";
    fc.range(`L${R0}:L${R1}`).formulas = "=$B$8";
    fc.range(`M${R0}:M${R1}`).formulas = `=MAX(0,FORECAST.LINEAR(12*YEAR(A${R0})+MONTH(A${R0}),FILTER(Monthly[Randomized],Monthly[Month]>=TrendStart),FILTER(Monthly[Month no.],Monthly[Month]>=TrendStart)))`;
    fc.range(`N${R0}:N${R1}`).formulas = `=$B$8*(1+IF(A${R0}>=PreStart,PreLift,0))`;
    fc.range(`O${R0}:O${R1}`).formulas = `=$B$8+IF(A${R0}>=BackupStart,BackupSites*BackupRate,0)`;
    fc.range(`P${R0}:P${R1}`).formulas = `=$B$8*(1+IF(A${R0}>=PreStart,PreLift,0))+IF(A${R0}>=BackupStart,BackupSites*BackupRate,0)`;
    fc.range(`C${R0}`).formulas = `=$B$6+J${R0}`;
    fc.range(`C${R0+1}:C${R1}`).formulas = `=C${R0}+J${R0+1}`;
    ["D","E","F","G","H","I"].forEach((c,k)=>{
      const mc = monCols[k+1];
      fc.range(`${c}${R0}`).formulas = `=$B$4+${mc}${R0}`;
      fc.range(`${c}${R0+1}:${c}${R1}`).formulas = `=${c}${R0}+${mc}${R0+1}`;
    });
    fc.tables.add(`A${R0-1}:P${R1}`, { name: "Projection" });
    fc.range(`A${R0}:A${R1}`).numberFormat = "mmm yyyy";
    fc.range(`B${R0}:I${R1}`).numberFormat = "#,##0";
    fc.range(`J${R0}:P${R1}`).numberFormat = "#,##0.0";
    fc.range(`A${R0-1}:P${R0-1}`).format({ wrap: true });
    fc.setColumnWidth("A", 290).setColumnWidth("B:P", 100);
    fc.charts.add("line", { data: `A${R0-1}:A${R0+11}`, series: [
      { name: "Target", values: `B${R0}:B${R0+11}` },
      { name: "At planned rate", values: `D${R0}:D${R0+11}` },
      { name: "At run rate", values: `E${R0}:E${R0+11}` },
      { name: "By trend", values: `F${R0}:F${R0+11}` },
      { name: "Run rate + both mitigations", values: `I${R0}:I${R0+11}` }], at: "F2", size: { w: 620, h: 300 }, title: "Cumulative randomizations by scenario" });
    
    // ---------- Checks ----------
    const ck = wb.sheets.add("Checks");
    ck.range("A1:D1").values = [["Check","Model","CTMS log","Difference"]];
    const checks = [
      ["Subjects screened: site totals vs log rows", "=Sites!I40", "=ROWS(Log[Subject ID])"],
      ["Randomized: site totals vs log", "=Sites!J40", '=COUNTIF(Log[Status],"Randomized")'],
      ["Screen failed: site totals vs log", "=Sites!K40", '=COUNTIF(Log[Status],"Screen failed")'],
      ["Withdrawn: site totals vs log", "=Sites!L40", '=COUNTIF(Log[Status],"Withdrawn")'],
      ["In screening: site totals vs log", "=Sites!M40", '=COUNTIF(Log[Status],"In screening")'],
      ["Every subject has one of the four statuses", "=Sites!J40+Sites!K40+Sites!L40+Sites!M40", "=ROWS(Log[Subject ID])"],
      ["Log subjects at sites missing from the plan", "=SUMPRODUCT(--(COUNTIF(Plan[Site ID],Log[Site ID])=0))", "=0"],
      ["Screen fails by reason vs log", "='Screen fails'!D12", '=COUNTIF(Log[Status],"Screen failed")'],
      ["Randomized by month vs log", "=SUM(Monthly[Randomized])", '=COUNTIF(Log[Status],"Randomized")'],
      ["Screened by month vs log", "=SUM(Monthly[Screened])", "=ROWS(Log[Subject ID])"],
      ["Randomized by country vs log", "=SUM('Screen fails'!G16:G22)", '=COUNTIF(Log[Status],"Randomized")'],
    ];
    ck.range("A2:C12").values = checks;
    ck.range("D2:D12").formulas = "=B2-C2";
    ck.range("A14").values = [["All checks (should be 0)"]];
    ck.range("D14").formulas = "=SUMPRODUCT(ABS(D2:D12))";
    ck.range("A1:D1").format({ bold: true, fill: "accent1", color: "white" });
    ck.range("A14:D14").format({ bold: true, borderTop: "medium" });
    ck.range("B2:D14").numberFormat = "#,##0";
    ck.conditionalFormats.add("D2:D14", { type: "cellIs", operator: "notEqual", value: 0, format: { color: "red-800", fill: "red-100" } });
    ck.setColumnWidth("A", 330).setColumnWidth("B:D", 100);
    
    return {
      sitesTotal: s.range("A40:T40").values,
      checks: ck.range("A2:D14").values,
      lpi: fc.range("A4:D18").values,
      fails: f.range("A4:H12").values, funnel: f.range("A16:B27").values, country: f.range("D16:J22").values,
      monthly: m.range("A2:I20").values.slice(-8),
    };
    {
      "ok": false,
      "error": {
        "name": "SyntaxError",
        "message": "Identifier 'wb' has already been declared"
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Screening log",
        "Site plan"
      ],
      "version": 2,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  15. artiwright_runerror
    // ---------- Inputs ----------
    const inp = wb.sheets.add("Inputs");
    inp.range("A1").values = [["VRD-301 enrollment model: inputs"]];
    inp.range("A1").format({ bold: true, size: 14 });
    inp.range("A3:C3").values = [["Input", "Value", "Source"]];
    const rows = [
      ["Data as of (CTMS export)", "=DATE(2026,9,30)", "Steering committee brief"],
      ["Randomization target", 1700, "Steering committee brief"],
      ["Red: screen-fail rate above", 0.35, "Study team status rules"],
      ["Red: days without screening above", 30, "Study team status rules"],
      ["Amber: randomizations behind plan to date by more than", 0.2, "Study team status rules"],
      ["Count consent withdrawals as screen fails (Yes/No)", "No", "Assumption: CTMS status 'Withdrawn' kept separate from 'Screen failed'"],
      ["Run rate: months averaged", 3, "Steering committee brief (last three months)"],
      ["Trend: fit from month", "=DATE(2026,3,1)", "Assumption: first month all 38 sites were on plan (HU-102 activated Feb 2026)"],
      ["Backup sites activated", 4, "Steering committee brief"],
      ["Backup site rate (randomizations per site per month)", 2.5, "Steering committee brief"],
      ["Backup sites first randomize in", "=DATE(2027,2,1)", "Assumption: activated Jan 2027, plan starts the month after"],
      ["HbA1c pre-screening lift to run rate", 0.10, "Steering committee brief (study team estimate)"],
      ["HbA1c pre-screening live from", "=DATE(2027,1,1)", "Assumption: about a month after the steering committee decision"],
    ];
    inp.range("A4:C16").values = rows;
    const names = ["AsOf","Target","RedSF","SilentDays","AmberGap","CountWithdrawn","RunMonths","TrendStart","BackupSites","BackupRate","BackupStart","PreLift","PreStart"];
    names.forEach((n,i)=>wb.names.add(n, `Inputs!$B$${4+i}`));
    inp.range("A3:C3").format({ bold: true, fill: "accent1", color: "white" });
    inp.range("B4:B16").format({ color: "blue-700", fill: "blue-50" });
    ["B4","B11","B14","B16"].forEach(c=>inp.range(c).numberFormat="d mmm yyyy");
    ["B6","B8","B15"].forEach(c=>inp.range(c).numberFormat="0%");
    inp.range("B5").numberFormat="#,##0";
    inp.validations.add("B9", { type: "list", values: ["Yes","No"], error: "Yes or No" });
    inp.setColumnWidth("A", 380).setColumnWidth("B", 110).setColumnWidth("C", 470);
    
    // ---------- Sites ----------
    const s = wb.sheets.add("Sites");
    const hdr = ["Site ID","Investigator","Country","Activated","Planned per month","Plan start","Months on plan","Plan to date","Screened","Randomized","Screen failed","Withdrawn","In screening","Plan achieved","Versus plan","Screen-fail rate","Last screening","Days since screening","Randomized last 3 months","Status","Why"];
    s.range("A1:U1").values = [hdr];
    const n = 38, last = n+1;
    s.range(`A2:A${last}`).formulas = "='Site plan'!A2";
    s.range(`B2:B${last}`).formulas = "='Site plan'!B2";
    s.range(`C2:C${last}`).formulas = "='Site plan'!C2";
    s.range(`D2:D${last}`).formulas = "='Site plan'!D2";
    s.range(`E2:E${last}`).formulas = "='Site plan'!E2";
    s.range(`F2:F${last}`).formulas = "=EOMONTH(D2,0)+1";
    s.range(`G2:G${last}`).formulas = "=MAX(0,(YEAR(AsOf)-YEAR(F2))*12+MONTH(AsOf)-MONTH(F2)+1)";
    s.range(`H2:H${last}`).formulas = "=G2*E2";
    s.range(`I2:I${last}`).formulas = "=COUNTIFS(Log[Site ID],A2)";
    s.range(`J2:J${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Randomized")';
    s.range(`K2:K${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Screen failed")';
    s.range(`L2:L${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Withdrawn")';
    s.range(`M2:M${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"In screening")';
    s.range(`N2:N${last}`).formulas = "=IFERROR(J2/H2,0)";
    s.range(`O2:O${last}`).formulas = "=J2-H2";
    s.range(`P2:P${last}`).formulas = '=IFERROR((K2+IF(CountWithdrawn="Yes",L2,0))/(J2+K2+L2),0)';
    s.range(`Q2:Q${last}`).formulas = "=MAXIFS(Log[Screening date],Log[Site ID],A2)";
    s.range(`R2:R${last}`).formulas = "=AsOf-Q2";
    s.range(`S2:S${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Randomized on],">"&EDATE(AsOf,-RunMonths),Log[Randomized on],"<="&AsOf)';
    s.range(`T2:T${last}`).formulas = '=IF(OR(P2>RedSF,R2>SilentDays),"Red",IF(J2<H2*(1-AmberGap),"Amber","Green"))';
    s.range(`U2:U${last}`).formulas = '=TEXTJOIN("; ",TRUE,IF(P2>RedSF,"screen-fail "&TEXT(P2,"0%"),""),IF(R2>SilentDays,"no screening for "&R2&" days",""),IF(J2<H2*(1-AmberGap),TEXT(1-N2,"0%")&" behind plan",""))';
    s.tables.add(`A1:U${last}`, { name: "Sites" });
    const t = last+1;
    s.range(`A${t}`).values = [["Total"]];
    ["E","H","I","J","K","L","M","O","S"].forEach(c=>s.range(`${c}${t}`).formulas = `=SUM(${c}2:${c}${last})`);
    s.range(`N${t}`).formulas = `=J${t}/H${t}`;
    s.range(`P${t}`).formulas = `=(K${t}+IF(CountWithdrawn="Yes",L${t},0))/(J${t}+K${t}+L${t})`;
    s.range(`Q${t}`).formulas = `=MAX(Q2:Q${last})`;
    s.range(`T${t}`).formulas = `=COUNTIF(T2:T${last},"Red")&" red, "&COUNTIF(T2:T${last},"Amber")&" amber, "&COUNTIF(T2:T${last},"Green")&" green"`;
    s.range(`A${t}:U${t}`).format({ bold: true, borderTop: "medium" });
    s.range(`D2:D${t}`).numberFormat = "d mmm yyyy";
    s.range(`F2:F${t}`).numberFormat = "mmm yyyy";
    s.range(`Q2:Q${t}`).numberFormat = "d mmm yyyy";
    s.range(`E2:E${t}`).numberFormat = "0.0";
    s.range(`H2:H${t}`).numberFormat = "#,##0.0";
    s.range(`I2:M${t}`).numberFormat = "#,##0";
    s.range(`N2:N${t}`).numberFormat = "0%";
    s.range(`O2:O${t}`).numberFormat = "+#,##0.0;-#,##0.0;0";
    s.range(`P2:P${t}`).numberFormat = "0.0%";
    s.range(`R2:S${t}`).numberFormat = "#,##0";
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Red", format: { color: "red-800", fill: "red-100" } });
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Amber", format: { color: "amber-800", fill: "amber-100" } });
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Green", format: { color: "green-800", fill: "green-100" } });
    s.setColumnWidth("A", 70).setColumnWidth("B", 130).setColumnWidth("C", 110).setColumnWidth("D:S", 92).setColumnWidth("T", 70).setColumnWidth("U", 330);
    s.range("A1:U1").format({ wrap: true });
    s.freeze(1, 1);
    
    // ---------- Monthly ----------
    const m = wb.sheets.add("Monthly");
    m.range("A1:I1").values = [["Month","Month no.","Sites on plan","Planned","Screened","Randomized","Cumulative plan","Cumulative randomized","Versus plan"]];
    const mr = 20;
    m.range("A2").formulas = "=DATE(YEAR(MIN(Log[Screening date])),MONTH(MIN(Log[Screening date])),1)";
    m.range(`A3:A${mr}`).formulas = "=EDATE(A2,1)";
    m.range(`B2:B${mr}`).formulas = "=12*YEAR(A2)+MONTH(A2)";
    m.range(`C2:C${mr}`).formulas = '=COUNTIFS(Sites[Plan start],"<="&A2)';
    m.range(`D2:D${mr}`).formulas = '=SUMIFS(Sites[Planned per month],Sites[Plan start],"<="&A2)';
    m.range(`E2:E${mr}`).formulas = '=COUNTIFS(Log[Screening date],">="&A2,Log[Screening date],"<="&EOMONTH(A2,0))';
    m.range(`F2:F${mr}`).formulas = '=COUNTIFS(Log[Randomized on],">="&A2,Log[Randomized on],"<="&EOMONTH(A2,0))';
    m.range("G2").formulas = "=D2"; m.range(`G3:G${mr}`).formulas = "=G2+D3";
    m.range("H2").formulas = "=F2"; m.range(`H3:H${mr}`).formulas = "=H2+F3";
    m.range(`I2:I${mr}`).formulas = "=H2-G2";
    m.tables.add(`A1:I${mr}`, { name: "Monthly" });
    m.range(`A2:A${mr}`).numberFormat = "mmm yyyy";
    m.range(`D2:D${mr}`).numberFormat = "#,##0.0";
    m.range(`G2:G${mr}`).numberFormat = "#,##0";
    m.range(`I2:I${mr}`).numberFormat = "+#,##0;-#,##0;0";
    m.setColumnWidth("A:I", 105);
    m.charts.add("line", { data: `A1:A${mr}`, series: [{ name: "Cumulative plan", values: `G2:G${mr}` }, { name: "Cumulative randomized", values: `H2:H${mr}` }], at: "K2", title: "Cumulative randomizations against plan" });
    
    // ---------- Screen fails ----------
    const f = wb.sheets.add("Screen fails");
    f.range("A1").values = [["Why screening fails (CTMS status 'Screen failed')"]];
    f.range("A1").format({ bold: true, size: 14 });
    f.range("A3:H3").values = [["Code","Reason","Criterion type","Screen fails","Share of screen fails","Cumulative share","Share of completed screenings","At sites over the screen-fail limit"]];
    const reasons = ["I-04 HbA1c outside 7.0-10.5%","E-07 eGFR below 25","I-06 UACR below 200 mg/g","E-11 CV event in past 6 months","E-15 SGLT2 inhibitor in past 8 weeks","E-03 Uncontrolled blood pressure","O-02 Screening window expired","I-02 Age outside 30-80"];
    f.range("B4:B11").values = reasons.map(r=>[r]);
    f.range("A4:A11").formulas = '=TEXTBEFORE(B4," ")';
    f.range("C4:C11").formulas = '=XLOOKUP(B4,Log[Fail reason],Log[Criterion type])';
    f.range("D4:D11").formulas = '=COUNTIFS(Log[Fail reason],B4,Log[Status],"Screen failed")';
    f.range("E4:E11").formulas = "=D4/$D$12";
    f.range("F4").formulas = "=E4"; f.range("F5:F11").formulas = "=F4+E5";
    f.range("G4:G11").formulas = "=D4/$B$17";
    f.range("H4:H11").formulas = '=SUMPRODUCT(COUNTIFS(Log[Site ID],Sites[Site ID],Log[Fail reason],B4,Log[Status],"Screen failed")*(Sites[Screen-fail rate]>RedSF))';
    f.tables.add("A3:H11", { name: "FailReasons" });
    f.range("A12").values = [["Total"]];
    f.range("D12").formulas = "=SUM(D4:D11)"; f.range("E12").formulas = "=SUM(E4:E11)"; f.range("G12").formulas = "=D12/$B$17"; f.range("H12").formulas = "=SUM(H4:H11)";
    f.range("A12:H12").format({ bold: true, borderTop: "medium" });
    f.range("E4:G12").numberFormat = "0.0%";
    f.range("A15:B15").values = [["Screening funnel", "Subjects"]];
    f.range("A16:A22").values = [["Screened"],["Completed screening (randomized, failed or withdrawn)"],["Randomized"],["Screen failed"],["Consent withdrawn during screening"],["Still in screening"],["Overall screen-fail rate"]];
    f.range("B16").formulas = "=ROWS(Log[Subject ID])";
    f.range("B17").formulas = "=B18+B19+B20";
    f.range("B18").formulas = '=COUNTIF(Log[Status],"Randomized")';
    f.range("B19").formulas = '=COUNTIF(Log[Status],"Screen failed")';
    f.range("B20").formulas = '=COUNTIF(Log[Status],"Withdrawn")';
    f.range("B21").formulas = '=COUNTIF(Log[Status],"In screening")';
    f.range("B22").formulas = '=(B19+IF(CountWithdrawn="Yes",B20,0))/B17';
    f.range("B22").numberFormat = "0.0%";
    f.range("A24:B24").values = [["Pre-screening cross-check", "Value"]];
    f.range("A25:A27").values = [["HbA1c (I-04) screen fails"],["HbA1c fails per randomization: the most pre-screening could add if every one became a randomization"],["Lift assumed in the forecast"]];
    f.range("B25").formulas = "=D4"; f.range("B26").formulas = "=B25/B18"; f.range("B27").formulas = "=PreLift";
    f.range("B26:B27").numberFormat = "0.0%";
    f.range("A15:B15").format({ bold: true, borderBottom: "medium" });
    f.range("A24:B24").format({ bold: true, borderBottom: "medium" });
    f.range("D15:J15").values = [["Country","Sites","Screened","Randomized","Screen failed","Screen-fail rate","Plan achieved"]];
    const countries = ["United States","Poland","Spain","Germany","Hungary","Brazil","South Korea"];
    f.range("D16:D22").values = countries.map(c=>[c]);
    f.range("E16:E22").formulas = "=COUNTIFS(Sites[Country],D16)";
    f.range("F16:F22").formulas = "=SUMIFS(Sites[Screened],Sites[Country],D16)";
    f.range("G16:G22").formulas = "=SUMIFS(Sites[Randomized],Sites[Country],D16)";
    f.range("H16:H22").formulas = "=SUMIFS(Sites[Screen failed],Sites[Country],D16)";
    f.range("I16:I22").formulas = '=(H16+IF(CountWithdrawn="Yes",SUMIFS(Sites[Withdrawn],Sites[Country],D16),0))/(G16+H16+SUMIFS(Sites[Withdrawn],Sites[Country],D16))';
    f.range("J16:J22").formulas = "=G16/SUMIFS(Sites[Plan to date],Sites[Country],D16)";
    f.range("D15:J15").format({ bold: true, borderBottom: "medium" });
    f.range("I16:J22").numberFormat = "0%";
    f.setColumnWidth("A", 330).setColumnWidth("B", 230).setColumnWidth("C:H", 105);
    f.range("A3:H3").format({ wrap: true });
    f.charts.add("bar", { data: "B3:B11", series: [{ name: "Screen fails", values: "D4:D11" }], at: "L3", title: "Screen fails by reason" });
    
    // ---------- Forecast ----------
    const fc = wb.sheets.add("Forecast");
    fc.range("A1").values = [["Last-patient-in forecast (from the month after the data cut)"]];
    fc.range("A1").format({ bold: true, size: 14 });
    fc.range("A3:B3").values = [["Starting point and rates","Value"]];
    fc.range("A4:A9").values = [["Randomized to date"],["Still to randomize"],["Original plan to date"],["Planned rate, all 38 sites (per month)"],["Run rate, last months averaged (per month)"],["Trend slope since fit month (change per month)"]];
    fc.range("B4").formulas = "=SUM(Sites[Randomized])";
    fc.range("B5").formulas = "=Target-B4";
    fc.range("B6").formulas = "=SUM(Sites[Plan to date])";
    fc.range("B7").formulas = "=SUM(Plan[Planned per month])";
    fc.range("B8").formulas = '=SUMIFS(Monthly[Randomized],Monthly[Month],">"&EDATE(AsOf,-RunMonths))/RunMonths';
    fc.range("B9").formulas = "=SLOPE(FILTER(Monthly[Randomized],Monthly[Month]>=TrendStart),FILTER(Monthly[Month no.],Monthly[Month]>=TrendStart))";
    fc.range("B4:B7").numberFormat = "#,##0"; fc.range("B8:B9").numberFormat = "#,##0.0";
    fc.range("A3:B3").format({ bold: true, borderBottom: "medium" });
    fc.range("A11:D11").values = [["Scenario","Last patient in","Months later than original plan","Days earlier than run rate alone"]];
    const scen = ["Original plan","At planned rate","At run rate","By trend","Run rate + HbA1c pre-screening","Run rate + backup sites","Run rate + both mitigations"];
    fc.range("A12:A18").values = scen.map(x=>[x]);
    const R0 = 22, R1 = 48;
    const cumCols = ["C","D","E","F","G","H","I"], monCols = ["J","K","L","M","N","O","P"];
    scen.forEach((sc,i)=>{
      const c = cumCols[i], mcol = monCols[i], start = i===0 ? "$B$6" : "$B$4";
      fc.range(`B${12+i}`).formulas = `=LET(c,${c}${R0}:${c}${R1},m,${mcol}${R0}:${mcol}${R1},d,$A$${R0}:$A$${R1},i,XMATCH(TRUE,c>=Target),prev,IF(i=1,${start},INDEX(c,i-1)),INDEX(d,i)+ROUNDUP((Target-prev)/INDEX(m,i)*DAY(EOMONTH(INDEX(d,i),0)),0)-1)`;
    });
    fc.range("C12:C18").formulas = "=(B12-$B$12)/(365.25/12)";
    fc.range("D12:D18").formulas = "=$B$14-B12";
    fc.range("B12:B18").numberFormat = "d mmm yyyy";
    fc.range("C12:C18").numberFormat = "0.0";
    fc.range("D12:D18").numberFormat = "#,##0;-#,##0;0";
    fc.range("A11:D11").format({ bold: true, fill: "accent1", color: "white", wrap: true });
    fc.range(`A${R0-1}:P${R0-1}`).values = [["Month","Target","Cum. original plan","Cum. at planned rate","Cum. at run rate","Cum. by trend","Cum. run rate + pre-screening","Cum. run rate + backup sites","Cum. run rate + both","Original plan","At planned rate","At run rate","By trend","Run rate + pre-screening","Run rate + backup sites","Run rate + both"]];
    fc.range(`A${R0}`).formulas = "=EOMONTH(AsOf,0)+1";
    fc.range(`A${R0+1}:A${R1}`).formulas = `=EDATE(A${R0},1)`;
    fc.range(`B${R0}:B${R1}`).formulas = "=Target";
    fc.range(`J${R0}:J${R1}`).formulas = "=$B$7";
    fc.range(`K${R0}:K${R1}`).formulas = "=$B$7";
    fc.range(`L${R0}:L${R1}`).formulas = "=$B$8";
    fc.range(`M${R0}:M${R1}`).formulas = `=MAX(0,FORECAST.LINEAR(12*YEAR(A${R0})+MONTH(A${R0}),FILTER(Monthly[Randomized],Monthly[Month]>=TrendStart),FILTER(Monthly[Month no.],Monthly[Month]>=TrendStart)))`;
    fc.range(`N${R0}:N${R1}`).formulas = `=$B$8*(1+IF(A${R0}>=PreStart,PreLift,0))`;
    fc.range(`O${R0}:O${R1}`).formulas = `=$B$8+IF(A${R0}>=BackupStart,BackupSites*BackupRate,0)`;
    fc.range(`P${R0}:P${R1}`).formulas = `=$B$8*(1+IF(A${R0}>=PreStart,PreLift,0))+IF(A${R0}>=BackupStart,BackupSites*BackupRate,0)`;
    fc.range(`C${R0}`).formulas = `=$B$6+J${R0}`;
    fc.range(`C${R0+1}:C${R1}`).formulas = `=C${R0}+J${R0+1}`;
    ["D","E","F","G","H","I"].forEach((c,k)=>{
      const mc = monCols[k+1];
      fc.range(`${c}${R0}`).formulas = `=$B$4+${mc}${R0}`;
      fc.range(`${c}${R0+1}:${c}${R1}`).formulas = `=${c}${R0}+${mc}${R0+1}`;
    });
    fc.tables.add(`A${R0-1}:P${R1}`, { name: "Projection" });
    fc.range(`A${R0}:A${R1}`).numberFormat = "mmm yyyy";
    fc.range(`B${R0}:I${R1}`).numberFormat = "#,##0";
    fc.range(`J${R0}:P${R1}`).numberFormat = "#,##0.0";
    fc.range(`A${R0-1}:P${R0-1}`).format({ wrap: true });
    fc.setColumnWidth("A", 290).setColumnWidth("B:P", 100);
    fc.charts.add("line", { data: `A${R0-1}:A${R0+11}`, series: [
      { name: "Target", values: `B${R0}:B${R0+11}` },
      { name: "At planned rate", values: `D${R0}:D${R0+11}` },
      { name: "At run rate", values: `E${R0}:E${R0+11}` },
      { name: "By trend", values: `F${R0}:F${R0+11}` },
      { name: "Run rate + both mitigations", values: `I${R0}:I${R0+11}` }], at: "F2", size: { w: 620, h: 300 }, title: "Cumulative randomizations by scenario" });
    
    // ---------- Checks ----------
    const ck = wb.sheets.add("Checks");
    ck.range("A1:D1").values = [["Check","Model","CTMS log","Difference"]];
    const checks = [
      ["Subjects screened: site totals vs log rows", "=Sites!I40", "=ROWS(Log[Subject ID])"],
      ["Randomized: site totals vs log", "=Sites!J40", '=COUNTIF(Log[Status],"Randomized")'],
      ["Screen failed: site totals vs log", "=Sites!K40", '=COUNTIF(Log[Status],"Screen failed")'],
      ["Withdrawn: site totals vs log", "=Sites!L40", '=COUNTIF(Log[Status],"Withdrawn")'],
      ["In screening: site totals vs log", "=Sites!M40", '=COUNTIF(Log[Status],"In screening")'],
      ["Every subject has one of the four statuses", "=Sites!J40+Sites!K40+Sites!L40+Sites!M40", "=ROWS(Log[Subject ID])"],
      ["Log subjects at sites missing from the plan", "=SUMPRODUCT(--(COUNTIF(Plan[Site ID],Log[Site ID])=0))", "=0"],
      ["Screen fails by reason vs log", "='Screen fails'!D12", '=COUNTIF(Log[Status],"Screen failed")'],
      ["Randomized by month vs log", "=SUM(Monthly[Randomized])", '=COUNTIF(Log[Status],"Randomized")'],
      ["Screened by month vs log", "=SUM(Monthly[Screened])", "=ROWS(Log[Subject ID])"],
      ["Randomized by country vs log", "=SUM('Screen fails'!G16:G22)", '=COUNTIF(Log[Status],"Randomized")'],
    ];
    ck.range("A2:C12").values = checks;
    ck.range("D2:D12").formulas = "=B2-C2";
    ck.range("A14").values = [["All checks (should be 0)"]];
    ck.range("D14").formulas = "=SUMPRODUCT(ABS(D2:D12))";
    ck.range("A1:D1").format({ bold: true, fill: "accent1", color: "white" });
    ck.range("A14:D14").format({ bold: true, borderTop: "medium" });
    ck.range("B2:D14").numberFormat = "#,##0";
    ck.conditionalFormats.add("D2:D14", { type: "cellIs", operator: "notEqual", value: 0, format: { color: "red-800", fill: "red-100" } });
    ck.setColumnWidth("A", 330).setColumnWidth("B:D", 100);
    
    return {
      sitesTotal: s.range("A40:T40").values,
      checks: ck.range("A2:D14").values,
      lpi: fc.range("A4:D18").values,
      fails: f.range("A4:H12").values, funnel: f.range("A16:B27").values, country: f.range("D16:J22").values,
      monthly: m.range("A2:I20").values.slice(-8),
      status: s.range("A2:A39").values.map((r,i)=>[r[0], s.range(`T${i+2}`).values[0][0], s.range(`U${i+2}`).values[0][0]]).filter(r=>r[1]!=="Green"),
    };
    {
      "ok": false,
      "error": {
        "name": "OptionsError",
        "message": "charts.add:\n  - series[0].values: expected array, got \"G2:G20\"\n  - series[1].values: expected array, got \"H2:H20\""
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Screening log",
        "Site plan"
      ],
      "version": 2,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  16. artiwright_help
    {
      "query": "guide workbook-charts",
      "maxChars": 5000
    }
    # Workbook charts guide
    
    Charts in a workbook read their data from cells, so they update when the numbers change.
    
    ```js workbook-test
    const s = workbook.sheets.get("Sheet1");
    s.range("A1").values = [
      ["Month", "Revenue", "Margin"],
      ["Jan", 120, 0.21],
      ["Feb", 135, 0.22],
      ["Mar", 150, 0.24],
    ];
    s.range("B2:B4").numberFormat = "currency0";
    s.range("C2:C4").numberFormat = "percent";
    s.charts.add("column", {
      data: "A1:C4",
      at: "E2",
      size: { w: 520, h: 300 },
      title: "Revenue grew while margin widened",
      series: [{}, { type: "line", axis: "secondary" }],
    });
    ```
    
    - `data` is a block with series names in its first row and categories in its first column (text);
      `seriesIn: "rows"` when series run across. Another sheet: `data: "Model!A1:C13"`.
    - Place with `at` (top-left cell) and `size` in px, or `to` (bottom-right cell). Put charts beside
      or below the numbers, not over them. On a summary sheet, below its table at the table's width.
    - To show $M or $K, give the source cells (or `axes.y.format`) a scaled number format like
      `"millions"`; don't copy the numbers into a second table in other units for the chart.
    - Text defaults to Excel's sizes (9 pt labels, 14 pt title); set `style` only for a reason.
    - `series` restyles series by position: `{ type: "line", axis: "secondary" }` for a combo,
      `{ fill: "accent2" }` for a color.
    - Axes and values take the cells' number formats unless you set `axes: { y: { format } }`.
    - Types: column, bar, line, area, pie, doughnut, scatter (x values in the first column), bubble,
      radar, stock; and the Office 2016 types waterfall, funnel, pareto, histogram, boxWhisker,
      treemap and sunburst (leading text columns are the levels).
    - A chart title should say what the chart shows ("Revenue grew 25% in Q1"), not just "Revenue".
    
  17. artiwright_runerror
    // ---------- Inputs ----------
    const inp = wb.sheets.add("Inputs");
    inp.range("A1").values = [["VRD-301 enrollment model: inputs"]];
    inp.range("A1").format({ bold: true, size: 14 });
    inp.range("A3:C3").values = [["Input", "Value", "Source"]];
    const rows = [
      ["Data as of (CTMS export)", "=DATE(2026,9,30)", "Steering committee brief"],
      ["Randomization target", 1700, "Steering committee brief"],
      ["Red: screen-fail rate above", 0.35, "Study team status rules"],
      ["Red: days without screening above", 30, "Study team status rules"],
      ["Amber: randomizations behind plan to date by more than", 0.2, "Study team status rules"],
      ["Count consent withdrawals as screen fails (Yes/No)", "No", "Assumption: CTMS status 'Withdrawn' kept separate from 'Screen failed'"],
      ["Run rate: months averaged", 3, "Steering committee brief (last three months)"],
      ["Trend: fit from month", "=DATE(2026,3,1)", "Assumption: first month all 38 sites were on plan (HU-102 activated Feb 2026)"],
      ["Backup sites activated", 4, "Steering committee brief"],
      ["Backup site rate (randomizations per site per month)", 2.5, "Steering committee brief"],
      ["Backup sites first randomize in", "=DATE(2027,2,1)", "Assumption: activated Jan 2027, plan starts the month after"],
      ["HbA1c pre-screening lift to run rate", 0.10, "Steering committee brief (study team estimate)"],
      ["HbA1c pre-screening live from", "=DATE(2027,1,1)", "Assumption: about a month after the steering committee decision"],
    ];
    inp.range("A4:C16").values = rows;
    const names = ["AsOf","Target","RedSF","SilentDays","AmberGap","CountWithdrawn","RunMonths","TrendStart","BackupSites","BackupRate","BackupStart","PreLift","PreStart"];
    names.forEach((n,i)=>wb.names.add(n, `Inputs!$B$${4+i}`));
    inp.range("A3:C3").format({ bold: true, fill: "accent1", color: "white" });
    inp.range("B4:B16").format({ color: "blue-700", fill: "blue-50" });
    ["B4","B11","B14","B16"].forEach(c=>inp.range(c).numberFormat="d mmm yyyy");
    ["B6","B8","B15"].forEach(c=>inp.range(c).numberFormat="0%");
    inp.range("B5").numberFormat="#,##0";
    inp.validations.add("B9", { type: "list", values: ["Yes","No"], error: "Yes or No" });
    inp.setColumnWidth("A", 380).setColumnWidth("B", 110).setColumnWidth("C", 470);
    
    // ---------- Sites ----------
    const s = wb.sheets.add("Sites");
    const hdr = ["Site ID","Investigator","Country","Activated","Planned per month","Plan start","Months on plan","Plan to date","Screened","Randomized","Screen failed","Withdrawn","In screening","Plan achieved","Versus plan","Screen-fail rate","Last screening","Days since screening","Randomized last 3 months","Status","Why"];
    s.range("A1:U1").values = [hdr];
    const n = 38, last = n+1;
    s.range(`A2:A${last}`).formulas = "='Site plan'!A2";
    s.range(`B2:B${last}`).formulas = "='Site plan'!B2";
    s.range(`C2:C${last}`).formulas = "='Site plan'!C2";
    s.range(`D2:D${last}`).formulas = "='Site plan'!D2";
    s.range(`E2:E${last}`).formulas = "='Site plan'!E2";
    s.range(`F2:F${last}`).formulas = "=EOMONTH(D2,0)+1";
    s.range(`G2:G${last}`).formulas = "=MAX(0,(YEAR(AsOf)-YEAR(F2))*12+MONTH(AsOf)-MONTH(F2)+1)";
    s.range(`H2:H${last}`).formulas = "=G2*E2";
    s.range(`I2:I${last}`).formulas = "=COUNTIFS(Log[Site ID],A2)";
    s.range(`J2:J${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Randomized")';
    s.range(`K2:K${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Screen failed")';
    s.range(`L2:L${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Withdrawn")';
    s.range(`M2:M${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"In screening")';
    s.range(`N2:N${last}`).formulas = "=IFERROR(J2/H2,0)";
    s.range(`O2:O${last}`).formulas = "=J2-H2";
    s.range(`P2:P${last}`).formulas = '=IFERROR((K2+IF(CountWithdrawn="Yes",L2,0))/(J2+K2+L2),0)';
    s.range(`Q2:Q${last}`).formulas = "=MAXIFS(Log[Screening date],Log[Site ID],A2)";
    s.range(`R2:R${last}`).formulas = "=AsOf-Q2";
    s.range(`S2:S${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Randomized on],">"&EDATE(AsOf,-RunMonths),Log[Randomized on],"<="&AsOf)';
    s.range(`T2:T${last}`).formulas = '=IF(OR(P2>RedSF,R2>SilentDays),"Red",IF(J2<H2*(1-AmberGap),"Amber","Green"))';
    s.range(`U2:U${last}`).formulas = '=TEXTJOIN("; ",TRUE,IF(P2>RedSF,"screen-fail "&TEXT(P2,"0%"),""),IF(R2>SilentDays,"no screening for "&R2&" days",""),IF(J2<H2*(1-AmberGap),TEXT(1-N2,"0%")&" behind plan",""))';
    s.tables.add(`A1:U${last}`, { name: "Sites" });
    const t = last+1;
    s.range(`A${t}`).values = [["Total"]];
    ["E","H","I","J","K","L","M","O","S"].forEach(c=>s.range(`${c}${t}`).formulas = `=SUM(${c}2:${c}${last})`);
    s.range(`N${t}`).formulas = `=J${t}/H${t}`;
    s.range(`P${t}`).formulas = `=(K${t}+IF(CountWithdrawn="Yes",L${t},0))/(J${t}+K${t}+L${t})`;
    s.range(`Q${t}`).formulas = `=MAX(Q2:Q${last})`;
    s.range(`T${t}`).formulas = `=COUNTIF(T2:T${last},"Red")&" red, "&COUNTIF(T2:T${last},"Amber")&" amber, "&COUNTIF(T2:T${last},"Green")&" green"`;
    s.range(`A${t}:U${t}`).format({ bold: true, borderTop: "medium" });
    s.range(`D2:D${t}`).numberFormat = "d mmm yyyy";
    s.range(`F2:F${t}`).numberFormat = "mmm yyyy";
    s.range(`Q2:Q${t}`).numberFormat = "d mmm yyyy";
    s.range(`E2:E${t}`).numberFormat = "0.0";
    s.range(`H2:H${t}`).numberFormat = "#,##0.0";
    s.range(`I2:M${t}`).numberFormat = "#,##0";
    s.range(`N2:N${t}`).numberFormat = "0%";
    s.range(`O2:O${t}`).numberFormat = "+#,##0.0;-#,##0.0;0";
    s.range(`P2:P${t}`).numberFormat = "0.0%";
    s.range(`R2:S${t}`).numberFormat = "#,##0";
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Red", format: { color: "red-800", fill: "red-100" } });
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Amber", format: { color: "amber-800", fill: "amber-100" } });
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Green", format: { color: "green-800", fill: "green-100" } });
    s.setColumnWidth("A", 70).setColumnWidth("B", 130).setColumnWidth("C", 110).setColumnWidth("D:S", 92).setColumnWidth("T", 70).setColumnWidth("U", 330);
    s.range("A1:U1").format({ wrap: true });
    s.freeze(1, 1);
    
    // ---------- Monthly ----------
    const m = wb.sheets.add("Monthly");
    m.range("A1:I1").values = [["Month","Cumulative plan","Cumulative randomized","Versus plan","Month no.","Sites on plan","Planned","Screened","Randomized"]];
    const mr = 20;
    m.range("A2").formulas = "=DATE(YEAR(MIN(Log[Screening date])),MONTH(MIN(Log[Screening date])),1)";
    m.range(`A3:A${mr}`).formulas = "=EDATE(A2,1)";
    m.range(`E2:E${mr}`).formulas = "=12*YEAR(A2)+MONTH(A2)";
    m.range(`F2:F${mr}`).formulas = '=COUNTIFS(Sites[Plan start],"<="&A2)';
    m.range(`G2:G${mr}`).formulas = '=SUMIFS(Sites[Planned per month],Sites[Plan start],"<="&A2)';
    m.range(`H2:H${mr}`).formulas = '=COUNTIFS(Log[Screening date],">="&A2,Log[Screening date],"<="&EOMONTH(A2,0))';
    m.range(`I2:I${mr}`).formulas = '=COUNTIFS(Log[Randomized on],">="&A2,Log[Randomized on],"<="&EOMONTH(A2,0))';
    m.range("B2").formulas = "=G2"; m.range(`B3:B${mr}`).formulas = "=B2+G3";
    m.range("C2").formulas = "=I2"; m.range(`C3:C${mr}`).formulas = "=C2+I3";
    m.range(`D2:D${mr}`).formulas = "=C2-B2";
    m.tables.add(`A1:I${mr}`, { name: "Monthly" });
    m.range(`A2:A${mr}`).numberFormat = "mmm yyyy";
    m.range(`B2:B${mr}`).numberFormat = "#,##0";
    m.range(`D2:D${mr}`).numberFormat = "+#,##0;-#,##0;0";
    m.range(`G2:G${mr}`).numberFormat = "#,##0.0";
    m.setColumnWidth("A:I", 105);
    m.charts.add("line", { data: `A1:C${mr}`, at: "K2", size: { w: 620, h: 320 }, title: "Randomizations fell behind plan from mid-2025" });
    
    // ---------- Screen fails ----------
    const f = wb.sheets.add("Screen fails");
    f.range("A1").values = [["Why screening fails (CTMS status 'Screen failed')"]];
    f.range("A1").format({ bold: true, size: 14 });
    f.range("A3:H3").values = [["Code","Reason","Screen fails","Share of screen fails","Cumulative share","Share of completed screenings","At sites over the screen-fail limit","Criterion type"]];
    const reasons = ["I-04 HbA1c outside 7.0-10.5%","E-07 eGFR below 25","I-06 UACR below 200 mg/g","E-11 CV event in past 6 months","E-15 SGLT2 inhibitor in past 8 weeks","E-03 Uncontrolled blood pressure","O-02 Screening window expired","I-02 Age outside 30-80"];
    f.range("B4:B11").values = reasons.map(r=>[r]);
    f.range("A4:A11").formulas = '=TEXTBEFORE(B4," ")';
    f.range("C4:C11").formulas = '=COUNTIFS(Log[Fail reason],B4,Log[Status],"Screen failed")';
    f.range("D4:D11").formulas = "=C4/$C$12";
    f.range("E4").formulas = "=D4"; f.range("E5:E11").formulas = "=E4+D5";
    f.range("F4:F11").formulas = "=C4/$B$17";
    f.range("G4:G11").formulas = '=SUMPRODUCT(COUNTIFS(Log[Site ID],Sites[Site ID],Log[Fail reason],B4,Log[Status],"Screen failed")*(Sites[Screen-fail rate]>RedSF))';
    f.range("H4:H11").formulas = '=XLOOKUP(B4,Log[Fail reason],Log[Criterion type])';
    f.tables.add("A3:H11", { name: "FailReasons" });
    f.range("A12").values = [["Total"]];
    f.range("C12").formulas = "=SUM(C4:C11)"; f.range("D12").formulas = "=SUM(D4:D11)"; f.range("F12").formulas = "=C12/$B$17"; f.range("G12").formulas = "=SUM(G4:G11)";
    f.range("A12:H12").format({ bold: true, borderTop: "medium" });
    f.range("D4:F12").numberFormat = "0.0%";
    f.range("A15:B15").values = [["Screening funnel", "Subjects"]];
    f.range("A16:A22").values = [["Screened"],["Completed screening (randomized, failed or withdrawn)"],["Randomized"],["Screen failed"],["Consent withdrawn during screening"],["Still in screening"],["Overall screen-fail rate"]];
    f.range("B16").formulas = "=ROWS(Log[Subject ID])";
    f.range("B17").formulas = "=B18+B19+B20";
    f.range("B18").formulas = '=COUNTIF(Log[Status],"Randomized")';
    f.range("B19").formulas = '=COUNTIF(Log[Status],"Screen failed")';
    f.range("B20").formulas = '=COUNTIF(Log[Status],"Withdrawn")';
    f.range("B21").formulas = '=COUNTIF(Log[Status],"In screening")';
    f.range("B22").formulas = '=(B19+IF(CountWithdrawn="Yes",B20,0))/B17';
    f.range("B22").numberFormat = "0.0%";
    f.range("A24:B24").values = [["Pre-screening cross-check", "Value"]];
    f.range("A25:A27").values = [["HbA1c (I-04) screen fails"],["HbA1c fails per randomization: the most pre-screening could add if every one became a randomization"],["Lift assumed in the forecast"]];
    f.range("B25").formulas = "=C4"; f.range("B26").formulas = "=B25/B18"; f.range("B27").formulas = "=PreLift";
    f.range("B26:B27").numberFormat = "0.0%";
    f.range("A25:A27").format({ wrap: true });
    f.range("A15:B15").format({ bold: true, borderBottom: "medium" });
    f.range("A24:B24").format({ bold: true, borderBottom: "medium" });
    f.range("D15:J15").values = [["Country","Sites","Screened","Randomized","Screen failed","Screen-fail rate","Plan achieved"]];
    const countries = ["United States","Poland","Spain","Germany","Hungary","Brazil","South Korea"];
    f.range("D16:D22").values = countries.map(c=>[c]);
    f.range("E16:E22").formulas = "=COUNTIFS(Sites[Country],D16)";
    f.range("F16:F22").formulas = "=SUMIFS(Sites[Screened],Sites[Country],D16)";
    f.range("G16:G22").formulas = "=SUMIFS(Sites[Randomized],Sites[Country],D16)";
    f.range("H16:H22").formulas = "=SUMIFS(Sites[Screen failed],Sites[Country],D16)";
    f.range("I16:I22").formulas = '=(H16+IF(CountWithdrawn="Yes",SUMIFS(Sites[Withdrawn],Sites[Country],D16),0))/(G16+H16+SUMIFS(Sites[Withdrawn],Sites[Country],D16))';
    f.range("J16:J22").formulas = "=G16/SUMIFS(Sites[Plan to date],Sites[Country],D16)";
    f.range("D15:J15").format({ bold: true, borderBottom: "medium" });
    f.range("I16:J22").numberFormat = "0%";
    f.setColumnWidth("A", 330).setColumnWidth("B", 230).setColumnWidth("C:J", 105);
    f.range("A3:H3").format({ wrap: true });
    f.charts.add("bar", { data: "B3:C11", at: "L3", size: { w: 560, h: 320 }, title: "HbA1c and eGFR cause over half of screen fails" });
    
    // ---------- Forecast ----------
    const fc = wb.sheets.add("Forecast");
    fc.range("A1").values = [["Last-patient-in forecast (from the month after the data cut)"]];
    fc.range("A1").format({ bold: true, size: 14 });
    fc.range("A3:B3").values = [["Starting point and rates","Value"]];
    fc.range("A4:A9").values = [["Randomized to date"],["Still to randomize"],["Original plan to date"],["Planned rate, all 38 sites (per month)"],["Run rate, last months averaged (per month)"],["Trend slope since fit month (change per month)"]];
    fc.range("B4").formulas = "=SUM(Sites[Randomized])";
    fc.range("B5").formulas = "=Target-B4";
    fc.range("B6").formulas = "=SUM(Sites[Plan to date])";
    fc.range("B7").formulas = "=SUM(Plan[Planned per month])";
    fc.range("B8").formulas = '=SUMIFS(Monthly[Randomized],Monthly[Month],">"&EDATE(AsOf,-RunMonths))/RunMonths';
    fc.range("B9").formulas = "=SLOPE(FILTER(Monthly[Randomized],Monthly[Month]>=TrendStart),FILTER(Monthly[Month no.],Monthly[Month]>=TrendStart))";
    fc.range("B4:B7").numberFormat = "#,##0"; fc.range("B8:B9").numberFormat = "#,##0.0";
    fc.range("A3:B3").format({ bold: true, borderBottom: "medium" });
    fc.range("A11:D11").values = [["Scenario","Last patient in","Months later than original plan","Days earlier than run rate alone"]];
    const scen = ["Original plan","At planned rate","At run rate","By trend","Run rate + HbA1c pre-screening","Run rate + backup sites","Run rate + both mitigations"];
    fc.range("A12:A18").values = scen.map(x=>[x]);
    const R0 = 22, R1 = 48;
    // cumulative cols (chart order first): C planned, D run, E trend, F both, G original, H pre, I backup
    const cumOf = ["G","C","D","E","H","I","F"], monOf = ["J","K","L","M","N","O","P"];
    scen.forEach((sc,i)=>{
      const c = cumOf[i], mcol = monOf[i], start = i===0 ? "$B$6" : "$B$4";
      fc.range(`B${12+i}`).formulas = `=LET(c,${c}${R0}:${c}${R1},m,${mcol}${R0}:${mcol}${R1},d,$A$${R0}:$A$${R1},i,XMATCH(TRUE,c>=Target),prev,IF(i=1,${start},INDEX(c,i-1)),INDEX(d,i)+ROUNDUP((Target-prev)/INDEX(m,i)*DAY(EOMONTH(INDEX(d,i),0)),0)-1)`;
      fc.range(`${c}${R0}`).formulas = `=${start}+${mcol}${R0}`;
      fc.range(`${c}${R0+1}:${c}${R1}`).formulas = `=${c}${R0}+${mcol}${R0+1}`;
    });
    fc.range("C12:C18").formulas = "=(B12-$B$12)/(365.25/12)";
    fc.range("D12:D18").formulas = "=$B$14-B12";
    fc.range("B12:B18").numberFormat = "d mmm yyyy";
    fc.range("C12:C18").numberFormat = "0.0";
    fc.range("D12:D18").numberFormat = "#,##0;-#,##0;0";
    fc.range("A11:D11").format({ bold: true, fill: "accent1", color: "white", wrap: true });
    fc.range(`A${R0-1}:P${R0-1}`).values = [["Month","Target","Cum. at planned rate","Cum. at run rate","Cum. by trend","Cum. run rate + both","Cum. original plan","Cum. run rate + pre-screening","Cum. run rate + backup sites","Original plan","At planned rate","At run rate","By trend","Run rate + pre-screening","Run rate + backup sites","Run rate + both"]];
    fc.range(`A${R0}`).formulas = "=EOMONTH(AsOf,0)+1";
    fc.range(`A${R0+1}:A${R1}`).formulas = `=EDATE(A${R0},1)`;
    fc.range(`B${R0}:B${R1}`).formulas = "=Target";
    fc.range(`J${R0}:J${R1}`).formulas = "=$B$7";
    fc.range(`K${R0}:K${R1}`).formulas = "=$B$7";
    fc.range(`L${R0}:L${R1}`).formulas = "=$B$8";
    fc.range(`M${R0}:M${R1}`).formulas = `=MAX(0,FORECAST.LINEAR(12*YEAR(A${R0})+MONTH(A${R0}),FILTER(Monthly[Randomized],Monthly[Month]>=TrendStart),FILTER(Monthly[Month no.],Monthly[Month]>=TrendStart)))`;
    fc.range(`N${R0}:N${R1}`).formulas = `=$B$8*(1+IF(A${R0}>=PreStart,PreLift,0))`;
    fc.range(`O${R0}:O${R1}`).formulas = `=$B$8+IF(A${R0}>=BackupStart,BackupSites*BackupRate,0)`;
    fc.range(`P${R0}:P${R1}`).formulas = `=$B$8*(1+IF(A${R0}>=PreStart,PreLift,0))+IF(A${R0}>=BackupStart,BackupSites*BackupRate,0)`;
    fc.tables.add(`A${R0-1}:P${R1}`, { name: "Projection" });
    fc.range(`A${R0}:A${R1}`).numberFormat = "mmm yyyy";
    fc.range(`B${R0}:I${R1}`).numberFormat = "#,##0";
    fc.range(`J${R0}:P${R1}`).numberFormat = "#,##0.0";
    fc.range(`A${R0-1}:P${R0-1}`).format({ wrap: true });
    fc.setColumnWidth("A", 290).setColumnWidth("B:P", 100);
    fc.charts.add("line", { data: `A${R0-1}:F${R0+11}`, at: "F2", size: { w: 620, h: 300 }, title: "Cumulative randomizations by scenario" });
    
    // ---------- Checks ----------
    const ck = wb.sheets.add("Checks");
    ck.range("A1:D1").values = [["Check","Model","CTMS log","Difference"]];
    const checks = [
      ["Subjects screened: site totals vs log rows", "=Sites!I40", "=ROWS(Log[Subject ID])"],
      ["Randomized: site totals vs log", "=Sites!J40", '=COUNTIF(Log[Status],"Randomized")'],
      ["Screen failed: site totals vs log", "=Sites!K40", '=COUNTIF(Log[Status],"Screen failed")'],
      ["Withdrawn: site totals vs log", "=Sites!L40", '=COUNTIF(Log[Status],"Withdrawn")'],
      ["In screening: site totals vs log", "=Sites!M40", '=COUNTIF(Log[Status],"In screening")'],
      ["Every subject has one of the four statuses", "=Sites!J40+Sites!K40+Sites!L40+Sites!M40", "=ROWS(Log[Subject ID])"],
      ["Log subjects at sites missing from the plan", "=SUMPRODUCT(--(COUNTIF(Plan[Site ID],Log[Site ID])=0))", "=0"],
      ["Screen fails by reason vs log", "='Screen fails'!C12", '=COUNTIF(Log[Status],"Screen failed")'],
      ["Randomized by month vs log", "=SUM(Monthly[Randomized])", '=COUNTIF(Log[Status],"Randomized")'],
      ["Screened by month vs log", "=SUM(Monthly[Screened])", "=ROWS(Log[Subject ID])"],
      ["Randomized by country vs log", "=SUM('Screen fails'!G16:G22)", '=COUNTIF(Log[Status],"Randomized")'],
    ];
    ck.range("A2:C12").values = checks;
    ck.range("D2:D12").formulas = "=B2-C2";
    ck.range("A14").values = [["All checks (should be 0)"]];
    ck.range("D14").formulas = "=SUMPRODUCT(ABS(D2:D12))";
    ck.range("A1:D1").format({ bold: true, fill: "accent1", color: "white" });
    ck.range("A14:D14").format({ bold: true, borderTop: "medium" });
    ck.range("B2:D14").numberFormat = "#,##0";
    ck.conditionalFormats.add("D2:D14", { type: "cellIs", operator: "notEqual", value: 0, format: { color: "red-800", fill: "red-100" } });
    ck.setColumnWidth("A", 330).setColumnWidth("B:D", 100);
    
    return {
      sitesTotal: s.range("A40:T40").values,
      checks: ck.range("A2:D14").values,
      lpi: fc.range("A4:D18").values,
      fails: f.range("A4:G12").values, funnel: f.range("A16:B27").values, country: f.range("D16:J22").values,
      monthly: m.range("A2:I20").values.slice(-8),
      status: s.range("A2:U39").values.filter(r=>r[19]!=="Green").map(r=>[r[0],r[2],r[4],r[9],r[7],r[13],r[15],r[17],r[18],r[19],r[20]]),
    };
    {
      "ok": false,
      "error": {
        "name": "OptionsError",
        "message": "conditionalFormats.add: operator: \"notEqual\" is not one of >, >=, <, <=, =, !=, between, notBetween"
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Screening log",
        "Site plan"
      ],
      "version": 2,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  18. Fixing one option name in the model build and re-running it.

  19. artiwright_run
    // ---------- Inputs ----------
    const inp = wb.sheets.add("Inputs");
    inp.range("A1").values = [["VRD-301 enrollment model: inputs"]];
    inp.range("A1").format({ bold: true, size: 14 });
    inp.range("A3:C3").values = [["Input", "Value", "Source"]];
    const rows = [
      ["Data as of (CTMS export)", "=DATE(2026,9,30)", "Steering committee brief"],
      ["Randomization target", 1700, "Steering committee brief"],
      ["Red: screen-fail rate above", 0.35, "Study team status rules"],
      ["Red: days without screening above", 30, "Study team status rules"],
      ["Amber: randomizations behind plan to date by more than", 0.2, "Study team status rules"],
      ["Count consent withdrawals as screen fails (Yes/No)", "No", "Assumption: CTMS status 'Withdrawn' kept separate from 'Screen failed'"],
      ["Run rate: months averaged", 3, "Steering committee brief (last three months)"],
      ["Trend: fit from month", "=DATE(2026,3,1)", "Assumption: first month all 38 sites were on plan (HU-102 activated Feb 2026)"],
      ["Backup sites activated", 4, "Steering committee brief"],
      ["Backup site rate (randomizations per site per month)", 2.5, "Steering committee brief"],
      ["Backup sites first randomize in", "=DATE(2027,2,1)", "Assumption: activated Jan 2027, plan starts the month after"],
      ["HbA1c pre-screening lift to run rate", 0.10, "Steering committee brief (study team estimate)"],
      ["HbA1c pre-screening live from", "=DATE(2027,1,1)", "Assumption: about a month after the steering committee decision"],
    ];
    inp.range("A4:C16").values = rows;
    const names = ["AsOf","Target","RedSF","SilentDays","AmberGap","CountWithdrawn","RunMonths","TrendStart","BackupSites","BackupRate","BackupStart","PreLift","PreStart"];
    names.forEach((n,i)=>wb.names.add(n, `Inputs!$B$${4+i}`));
    inp.range("A3:C3").format({ bold: true, fill: "accent1", color: "white" });
    inp.range("B4:B16").format({ color: "blue-700", fill: "blue-50" });
    ["B4","B11","B14","B16"].forEach(c=>inp.range(c).numberFormat="d mmm yyyy");
    ["B6","B8","B15"].forEach(c=>inp.range(c).numberFormat="0%");
    inp.range("B5").numberFormat="#,##0";
    inp.validations.add("B9", { type: "list", values: ["Yes","No"], error: "Yes or No" });
    inp.setColumnWidth("A", 380).setColumnWidth("B", 110).setColumnWidth("C", 470);
    
    // ---------- Sites ----------
    const s = wb.sheets.add("Sites");
    const hdr = ["Site ID","Investigator","Country","Activated","Planned per month","Plan start","Months on plan","Plan to date","Screened","Randomized","Screen failed","Withdrawn","In screening","Plan achieved","Versus plan","Screen-fail rate","Last screening","Days since screening","Randomized last 3 months","Status","Why"];
    s.range("A1:U1").values = [hdr];
    const n = 38, last = n+1;
    s.range(`A2:A${last}`).formulas = "='Site plan'!A2";
    s.range(`B2:B${last}`).formulas = "='Site plan'!B2";
    s.range(`C2:C${last}`).formulas = "='Site plan'!C2";
    s.range(`D2:D${last}`).formulas = "='Site plan'!D2";
    s.range(`E2:E${last}`).formulas = "='Site plan'!E2";
    s.range(`F2:F${last}`).formulas = "=EOMONTH(D2,0)+1";
    s.range(`G2:G${last}`).formulas = "=MAX(0,(YEAR(AsOf)-YEAR(F2))*12+MONTH(AsOf)-MONTH(F2)+1)";
    s.range(`H2:H${last}`).formulas = "=G2*E2";
    s.range(`I2:I${last}`).formulas = "=COUNTIFS(Log[Site ID],A2)";
    s.range(`J2:J${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Randomized")';
    s.range(`K2:K${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Screen failed")';
    s.range(`L2:L${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"Withdrawn")';
    s.range(`M2:M${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Status],"In screening")';
    s.range(`N2:N${last}`).formulas = "=IFERROR(J2/H2,0)";
    s.range(`O2:O${last}`).formulas = "=J2-H2";
    s.range(`P2:P${last}`).formulas = '=IFERROR((K2+IF(CountWithdrawn="Yes",L2,0))/(J2+K2+L2),0)';
    s.range(`Q2:Q${last}`).formulas = "=MAXIFS(Log[Screening date],Log[Site ID],A2)";
    s.range(`R2:R${last}`).formulas = "=AsOf-Q2";
    s.range(`S2:S${last}`).formulas = '=COUNTIFS(Log[Site ID],A2,Log[Randomized on],">"&EDATE(AsOf,-RunMonths),Log[Randomized on],"<="&AsOf)';
    s.range(`T2:T${last}`).formulas = '=IF(OR(P2>RedSF,R2>SilentDays),"Red",IF(J2<H2*(1-AmberGap),"Amber","Green"))';
    s.range(`U2:U${last}`).formulas = '=TEXTJOIN("; ",TRUE,IF(P2>RedSF,"screen-fail "&TEXT(P2,"0%"),""),IF(R2>SilentDays,"no screening for "&R2&" days",""),IF(J2<H2*(1-AmberGap),TEXT(1-N2,"0%")&" behind plan",""))';
    s.tables.add(`A1:U${last}`, { name: "Sites" });
    const t = last+1;
    s.range(`A${t}`).values = [["Total"]];
    ["E","H","I","J","K","L","M","O","S"].forEach(c=>s.range(`${c}${t}`).formulas = `=SUM(${c}2:${c}${last})`);
    s.range(`N${t}`).formulas = `=J${t}/H${t}`;
    s.range(`P${t}`).formulas = `=(K${t}+IF(CountWithdrawn="Yes",L${t},0))/(J${t}+K${t}+L${t})`;
    s.range(`Q${t}`).formulas = `=MAX(Q2:Q${last})`;
    s.range(`T${t}`).formulas = `=COUNTIF(T2:T${last},"Red")&" red, "&COUNTIF(T2:T${last},"Amber")&" amber, "&COUNTIF(T2:T${last},"Green")&" green"`;
    s.range(`A${t}:U${t}`).format({ bold: true, borderTop: "medium" });
    s.range(`D2:D${t}`).numberFormat = "d mmm yyyy";
    s.range(`F2:F${t}`).numberFormat = "mmm yyyy";
    s.range(`Q2:Q${t}`).numberFormat = "d mmm yyyy";
    s.range(`E2:E${t}`).numberFormat = "0.0";
    s.range(`H2:H${t}`).numberFormat = "#,##0.0";
    s.range(`I2:M${t}`).numberFormat = "#,##0";
    s.range(`N2:N${t}`).numberFormat = "0%";
    s.range(`O2:O${t}`).numberFormat = "+#,##0.0;-#,##0.0;0";
    s.range(`P2:P${t}`).numberFormat = "0.0%";
    s.range(`R2:S${t}`).numberFormat = "#,##0";
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Red", format: { color: "red-800", fill: "red-100" } });
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Amber", format: { color: "amber-800", fill: "amber-100" } });
    s.conditionalFormats.add(`T2:T${last}`, { type: "containsText", text: "Green", format: { color: "green-800", fill: "green-100" } });
    s.setColumnWidth("A", 70).setColumnWidth("B", 130).setColumnWidth("C", 110).setColumnWidth("D:S", 92).setColumnWidth("T", 70).setColumnWidth("U", 330);
    s.range("A1:U1").format({ wrap: true });
    s.freeze(1, 1);
    
    // ---------- Monthly ----------
    const m = wb.sheets.add("Monthly");
    m.range("A1:I1").values = [["Month","Cumulative plan","Cumulative randomized","Versus plan","Month no.","Sites on plan","Planned","Screened","Randomized"]];
    const mr = 20;
    m.range("A2").formulas = "=DATE(YEAR(MIN(Log[Screening date])),MONTH(MIN(Log[Screening date])),1)";
    m.range(`A3:A${mr}`).formulas = "=EDATE(A2,1)";
    m.range(`E2:E${mr}`).formulas = "=12*YEAR(A2)+MONTH(A2)";
    m.range(`F2:F${mr}`).formulas = '=COUNTIFS(Sites[Plan start],"<="&A2)';
    m.range(`G2:G${mr}`).formulas = '=SUMIFS(Sites[Planned per month],Sites[Plan start],"<="&A2)';
    m.range(`H2:H${mr}`).formulas = '=COUNTIFS(Log[Screening date],">="&A2,Log[Screening date],"<="&EOMONTH(A2,0))';
    m.range(`I2:I${mr}`).formulas = '=COUNTIFS(Log[Randomized on],">="&A2,Log[Randomized on],"<="&EOMONTH(A2,0))';
    m.range("B2").formulas = "=G2"; m.range(`B3:B${mr}`).formulas = "=B2+G3";
    m.range("C2").formulas = "=I2"; m.range(`C3:C${mr}`).formulas = "=C2+I3";
    m.range(`D2:D${mr}`).formulas = "=C2-B2";
    m.tables.add(`A1:I${mr}`, { name: "Monthly" });
    m.range(`A2:A${mr}`).numberFormat = "mmm yyyy";
    m.range(`B2:B${mr}`).numberFormat = "#,##0";
    m.range(`D2:D${mr}`).numberFormat = "+#,##0;-#,##0;0";
    m.range(`G2:G${mr}`).numberFormat = "#,##0.0";
    m.setColumnWidth("A:I", 105);
    m.charts.add("line", { data: `A1:C${mr}`, at: "K2", size: { w: 620, h: 320 }, title: "Randomizations fell behind plan from mid-2025" });
    
    // ---------- Screen fails ----------
    const f = wb.sheets.add("Screen fails");
    f.range("A1").values = [["Why screening fails (CTMS status 'Screen failed')"]];
    f.range("A1").format({ bold: true, size: 14 });
    f.range("A3:H3").values = [["Code","Reason","Screen fails","Share of screen fails","Cumulative share","Share of completed screenings","At sites over the screen-fail limit","Criterion type"]];
    const reasons = ["I-04 HbA1c outside 7.0-10.5%","E-07 eGFR below 25","I-06 UACR below 200 mg/g","E-11 CV event in past 6 months","E-15 SGLT2 inhibitor in past 8 weeks","E-03 Uncontrolled blood pressure","O-02 Screening window expired","I-02 Age outside 30-80"];
    f.range("B4:B11").values = reasons.map(r=>[r]);
    f.range("A4:A11").formulas = '=TEXTBEFORE(B4," ")';
    f.range("C4:C11").formulas = '=COUNTIFS(Log[Fail reason],B4,Log[Status],"Screen failed")';
    f.range("D4:D11").formulas = "=C4/$C$12";
    f.range("E4").formulas = "=D4"; f.range("E5:E11").formulas = "=E4+D5";
    f.range("F4:F11").formulas = "=C4/$B$17";
    f.range("G4:G11").formulas = '=SUMPRODUCT(COUNTIFS(Log[Site ID],Sites[Site ID],Log[Fail reason],B4,Log[Status],"Screen failed")*(Sites[Screen-fail rate]>RedSF))';
    f.range("H4:H11").formulas = '=XLOOKUP(B4,Log[Fail reason],Log[Criterion type])';
    f.tables.add("A3:H11", { name: "FailReasons" });
    f.range("A12").values = [["Total"]];
    f.range("C12").formulas = "=SUM(C4:C11)"; f.range("D12").formulas = "=SUM(D4:D11)"; f.range("F12").formulas = "=C12/$B$17"; f.range("G12").formulas = "=SUM(G4:G11)";
    f.range("A12:H12").format({ bold: true, borderTop: "medium" });
    f.range("D4:F12").numberFormat = "0.0%";
    f.range("A15:B15").values = [["Screening funnel", "Subjects"]];
    f.range("A16:A22").values = [["Screened"],["Completed screening (randomized, failed or withdrawn)"],["Randomized"],["Screen failed"],["Consent withdrawn during screening"],["Still in screening"],["Overall screen-fail rate"]];
    f.range("B16").formulas = "=ROWS(Log[Subject ID])";
    f.range("B17").formulas = "=B18+B19+B20";
    f.range("B18").formulas = '=COUNTIF(Log[Status],"Randomized")';
    f.range("B19").formulas = '=COUNTIF(Log[Status],"Screen failed")';
    f.range("B20").formulas = '=COUNTIF(Log[Status],"Withdrawn")';
    f.range("B21").formulas = '=COUNTIF(Log[Status],"In screening")';
    f.range("B22").formulas = '=(B19+IF(CountWithdrawn="Yes",B20,0))/B17';
    f.range("B22").numberFormat = "0.0%";
    f.range("A24:B24").values = [["Pre-screening cross-check", "Value"]];
    f.range("A25:A27").values = [["HbA1c (I-04) screen fails"],["HbA1c fails per randomization: the most pre-screening could add if every one became a randomization"],["Lift assumed in the forecast"]];
    f.range("B25").formulas = "=C4"; f.range("B26").formulas = "=B25/B18"; f.range("B27").formulas = "=PreLift";
    f.range("B26:B27").numberFormat = "0.0%";
    f.range("A25:A27").format({ wrap: true });
    f.range("A15:B15").format({ bold: true, borderBottom: "medium" });
    f.range("A24:B24").format({ bold: true, borderBottom: "medium" });
    f.range("D15:J15").values = [["Country","Sites","Screened","Randomized","Screen failed","Screen-fail rate","Plan achieved"]];
    const countries = ["United States","Poland","Spain","Germany","Hungary","Brazil","South Korea"];
    f.range("D16:D22").values = countries.map(c=>[c]);
    f.range("E16:E22").formulas = "=COUNTIFS(Sites[Country],D16)";
    f.range("F16:F22").formulas = "=SUMIFS(Sites[Screened],Sites[Country],D16)";
    f.range("G16:G22").formulas = "=SUMIFS(Sites[Randomized],Sites[Country],D16)";
    f.range("H16:H22").formulas = "=SUMIFS(Sites[Screen failed],Sites[Country],D16)";
    f.range("I16:I22").formulas = '=(H16+IF(CountWithdrawn="Yes",SUMIFS(Sites[Withdrawn],Sites[Country],D16),0))/(G16+H16+SUMIFS(Sites[Withdrawn],Sites[Country],D16))';
    f.range("J16:J22").formulas = "=G16/SUMIFS(Sites[Plan to date],Sites[Country],D16)";
    f.range("D15:J15").format({ bold: true, borderBottom: "medium" });
    f.range("I16:J22").numberFormat = "0%";
    f.setColumnWidth("A", 330).setColumnWidth("B", 230).setColumnWidth("C:J", 105);
    f.range("A3:H3").format({ wrap: true });
    f.charts.add("bar", { data: "B3:C11", at: "L3", size: { w: 560, h: 320 }, title: "HbA1c and eGFR cause over half of screen fails" });
    
    // ---------- Forecast ----------
    const fc = wb.sheets.add("Forecast");
    fc.range("A1").values = [["Last-patient-in forecast (from the month after the data cut)"]];
    fc.range("A1").format({ bold: true, size: 14 });
    fc.range("A3:B3").values = [["Starting point and rates","Value"]];
    fc.range("A4:A9").values = [["Randomized to date"],["Still to randomize"],["Original plan to date"],["Planned rate, all 38 sites (per month)"],["Run rate, last months averaged (per month)"],["Trend slope since fit month (change per month)"]];
    fc.range("B4").formulas = "=SUM(Sites[Randomized])";
    fc.range("B5").formulas = "=Target-B4";
    fc.range("B6").formulas = "=SUM(Sites[Plan to date])";
    fc.range("B7").formulas = "=SUM(Plan[Planned per month])";
    fc.range("B8").formulas = '=SUMIFS(Monthly[Randomized],Monthly[Month],">"&EDATE(AsOf,-RunMonths))/RunMonths';
    fc.range("B9").formulas = "=SLOPE(FILTER(Monthly[Randomized],Monthly[Month]>=TrendStart),FILTER(Monthly[Month no.],Monthly[Month]>=TrendStart))";
    fc.range("B4:B7").numberFormat = "#,##0"; fc.range("B8:B9").numberFormat = "#,##0.0";
    fc.range("A3:B3").format({ bold: true, borderBottom: "medium" });
    fc.range("A11:D11").values = [["Scenario","Last patient in","Months later than original plan","Days earlier than run rate alone"]];
    const scen = ["Original plan","At planned rate","At run rate","By trend","Run rate + HbA1c pre-screening","Run rate + backup sites","Run rate + both mitigations"];
    fc.range("A12:A18").values = scen.map(x=>[x]);
    const R0 = 22, R1 = 48;
    const cumOf = ["G","C","D","E","H","I","F"], monOf = ["J","K","L","M","N","O","P"];
    scen.forEach((sc,i)=>{
      const c = cumOf[i], mcol = monOf[i], start = i===0 ? "$B$6" : "$B$4";
      fc.range(`B${12+i}`).formulas = `=LET(c,${c}${R0}:${c}${R1},m,${mcol}${R0}:${mcol}${R1},d,$A$${R0}:$A$${R1},i,XMATCH(TRUE,c>=Target),prev,IF(i=1,${start},INDEX(c,i-1)),INDEX(d,i)+ROUNDUP((Target-prev)/INDEX(m,i)*DAY(EOMONTH(INDEX(d,i),0)),0)-1)`;
      fc.range(`${c}${R0}`).formulas = `=${start}+${mcol}${R0}`;
      fc.range(`${c}${R0+1}:${c}${R1}`).formulas = `=${c}${R0}+${mcol}${R0+1}`;
    });
    fc.range("C12:C18").formulas = "=(B12-$B$12)/(365.25/12)";
    fc.range("D12:D18").formulas = "=$B$14-B12";
    fc.range("B12:B18").numberFormat = "d mmm yyyy";
    fc.range("C12:C18").numberFormat = "0.0";
    fc.range("D12:D18").numberFormat = "#,##0;-#,##0;0";
    fc.range("A11:D11").format({ bold: true, fill: "accent1", color: "white", wrap: true });
    fc.range(`A${R0-1}:P${R0-1}`).values = [["Month","Target","Cum. at planned rate","Cum. at run rate","Cum. by trend","Cum. run rate + both","Cum. original plan","Cum. run rate + pre-screening","Cum. run rate + backup sites","Original plan","At planned rate","At run rate","By trend","Run rate + pre-screening","Run rate + backup sites","Run rate + both"]];
    fc.range(`A${R0}`).formulas = "=EOMONTH(AsOf,0)+1";
    fc.range(`A${R0+1}:A${R1}`).formulas = `=EDATE(A${R0},1)`;
    fc.range(`B${R0}:B${R1}`).formulas = "=Target";
    fc.range(`J${R0}:J${R1}`).formulas = "=$B$7";
    fc.range(`K${R0}:K${R1}`).formulas = "=$B$7";
    fc.range(`L${R0}:L${R1}`).formulas = "=$B$8";
    fc.range(`M${R0}:M${R1}`).formulas = `=MAX(0,FORECAST.LINEAR(12*YEAR(A${R0})+MONTH(A${R0}),FILTER(Monthly[Randomized],Monthly[Month]>=TrendStart),FILTER(Monthly[Month no.],Monthly[Month]>=TrendStart)))`;
    fc.range(`N${R0}:N${R1}`).formulas = `=$B$8*(1+IF(A${R0}>=PreStart,PreLift,0))`;
    fc.range(`O${R0}:O${R1}`).formulas = `=$B$8+IF(A${R0}>=BackupStart,BackupSites*BackupRate,0)`;
    fc.range(`P${R0}:P${R1}`).formulas = `=$B$8*(1+IF(A${R0}>=PreStart,PreLift,0))+IF(A${R0}>=BackupStart,BackupSites*BackupRate,0)`;
    fc.tables.add(`A${R0-1}:P${R1}`, { name: "Projection" });
    fc.range(`A${R0}:A${R1}`).numberFormat = "mmm yyyy";
    fc.range(`B${R0}:I${R1}`).numberFormat = "#,##0";
    fc.range(`J${R0}:P${R1}`).numberFormat = "#,##0.0";
    fc.range(`A${R0-1}:P${R0-1}`).format({ wrap: true });
    fc.setColumnWidth("A", 290).setColumnWidth("B:P", 100);
    fc.charts.add("line", { data: `A${R0-1}:F${R0+11}`, at: "F2", size: { w: 620, h: 300 }, title: "Cumulative randomizations by scenario" });
    
    // ---------- Checks ----------
    const ck = wb.sheets.add("Checks");
    ck.range("A1:D1").values = [["Check","Model","CTMS log","Difference"]];
    const checks = [
      ["Subjects screened: site totals vs log rows", "=Sites!I40", "=ROWS(Log[Subject ID])"],
      ["Randomized: site totals vs log", "=Sites!J40", '=COUNTIF(Log[Status],"Randomized")'],
      ["Screen failed: site totals vs log", "=Sites!K40", '=COUNTIF(Log[Status],"Screen failed")'],
      ["Withdrawn: site totals vs log", "=Sites!L40", '=COUNTIF(Log[Status],"Withdrawn")'],
      ["In screening: site totals vs log", "=Sites!M40", '=COUNTIF(Log[Status],"In screening")'],
      ["Every subject has one of the four statuses", "=Sites!J40+Sites!K40+Sites!L40+Sites!M40", "=ROWS(Log[Subject ID])"],
      ["Log subjects at sites missing from the plan", "=SUMPRODUCT(--(COUNTIF(Plan[Site ID],Log[Site ID])=0))", "=0"],
      ["Screen fails by reason vs log", "='Screen fails'!C12", '=COUNTIF(Log[Status],"Screen failed")'],
      ["Randomized by month vs log", "=SUM(Monthly[Randomized])", '=COUNTIF(Log[Status],"Randomized")'],
      ["Screened by month vs log", "=SUM(Monthly[Screened])", "=ROWS(Log[Subject ID])"],
      ["Randomized by country vs log", "=SUM('Screen fails'!G16:G22)", '=COUNTIF(Log[Status],"Randomized")'],
    ];
    ck.range("A2:C12").values = checks;
    ck.range("D2:D12").formulas = "=B2-C2";
    ck.range("A14").values = [["All checks (should be 0)"]];
    ck.range("D14").formulas = "=SUMPRODUCT(ABS(D2:D12))";
    ck.range("A1:D1").format({ bold: true, fill: "accent1", color: "white" });
    ck.range("A14:D14").format({ bold: true, borderTop: "medium" });
    ck.range("B2:D14").numberFormat = "#,##0";
    ck.conditionalFormats.add("D2:D14", { type: "cellIs", operator: "!=", value: 0, format: { color: "red-800", fill: "red-100" } });
    ck.setColumnWidth("A", 330).setColumnWidth("B:D", 100);
    
    return {
      sitesTotal: s.range("A40:T40").values,
      checks: ck.range("A2:D14").values,
      lpi: fc.range("A4:D18").values,
      fails: f.range("A4:G12").values, funnel: f.range("A16:B27").values, country: f.range("D16:J22").values,
      monthly: m.range("A2:I20").values.slice(-8),
      status: s.range("A2:U39").values.filter(r=>r[19]!=="Green").map(r=>[r[0],r[2],r[4],r[9],r[7],r[13],r[15],r[17],r[18],r[19],r[20]]),
    };
    {
      "ok": true,
      "value": {
        "sitesTotal": [
          [
            "Total",
            null,
            null,
            null,
            105,
            null,
            null,
            1396,
            1738,
            1201,
            393,
            77,
            67,
            0.8603151862464183,
            -195,
            0.23518850987432674,
            46294,
            null,
            264,
            "10 red, 7 amber, 21 green"
          ]
        ],
        "checks": [
          [
            "Subjects screened: site totals vs log rows",
            1738,
            1738,
            0
          ],
          [
            "Randomized: site totals vs log",
            1201,
            1201,
            0
          ],
          [
            "Screen failed: site totals vs log",
            393,
            393,
            0
          ],
          [
            "Withdrawn: site totals vs log",
            77,
            77,
            0
          ],
          [
            "In screening: site totals vs log",
            67,
            67,
            0
          ],
          [
            "Every subject has one of the four statuses",
            1738,
            1738,
            0
          ],
          [
            "Log subjects at sites missing from the plan",
            0,
            0,
            0
          ],
          [
            "Screen fails by reason vs log",
            393,
            393,
            0
          ],
          [
            "Randomized by month vs log",
            1201,
            1201,
            0
          ],
          [
            "Screened by month vs log",
            1738,
            1738,
            0
          ],
          [
            "Randomized by country vs log",
            1201,
            1201,
            0
          ],
          [
            null,
            null,
            null,
            null
          ],
          [
            "All checks (should be 0)",
            null,
            null,
            0
          ]
        ],
        "lpi": [
          [
            "Randomized to date",
            1201,
            null,
            null
          ],
          [
            "Still to randomize",
            499,
            null,
            null
          ],
          [
            "Original plan to date",
            1396,
            null,
            null
          ],
          [
            "Planned rate, all 38 sites (per month)",
            105,
            null,
            null
          ],
          [
            "Run rate, last months averaged (per month)",
            88,
            null,
            null
          ],
          [
            "Trend slope since fit month (change per month)",
            -1.8571428571428572,
            null,
            null
          ],
          [
            null,
            null,
            null,
            null
          ],
          [
            "Scenario",
            "La
    …
  20. artiwright_run
    const log = wb.sheets.get("Screening log").range("A2:H1739").values;
    const hi = ["US-104","US-110","PL-106"];
    const mix = {}; log.filter(r=>hi.includes(r[1]) && r[4]==="Screen failed").forEach(r=>mix[r[7]]=(mix[r[7]]||0)+1);
    const f = wb.sheets.get("Screen fails");
    f.range("G4:G11").formulas = '=SUMPRODUCT((Log[Fail reason]=B4)*(Log[Status]="Screen failed")*(XLOOKUP(Log[Site ID],Sites[Site ID],Sites[Screen-fail rate])>RedSF))';
    const g = f.range("G4:G12").values;
    
    // Status summary on Sites sheet
    const s = wb.sheets.get("Sites");
    s.range("A43").values = [["Sites by status"]];
    s.range("A43").format({ bold: true, size: 13 });
    s.range("A44:H44").values = [["Group","Rule","Sites","Planned per month","Plan to date","Randomized","Versus plan","Randomized last 3 months"]];
    s.range("A45:B49").values = [
      ["Red: no screening","No screening in more than 30 days"],
      ["Red: high screen-fail","Screen-fail rate above 35%"],
      ["Amber","More than 20% behind plan to date"],
      ["Green","On or near plan"],
      ["All sites",""]];
    const crit = [
      'Sites[Status],"Red",Sites[Days since screening],">"&SilentDays',
      'Sites[Status],"Red",Sites[Days since screening],"<="&SilentDays',
      'Sites[Status],"Amber"',
      'Sites[Status],"Green"'];
    crit.forEach((c,i)=>{
      const r = 45+i;
      s.range(`C${r}`).formulas = `=COUNTIFS(${c})`;
      s.range(`D${r}`).formulas = `=SUMIFS(Sites[Planned per month],${c})`;
      s.range(`E${r}`).formulas = `=SUMIFS(Sites[Plan to date],${c})`;
      s.range(`F${r}`).formulas = `=SUMIFS(Sites[Randomized],${c})`;
      s.range(`G${r}`).formulas = `=F${r}-E${r}`;
      s.range(`H${r}`).formulas = `=SUMIFS(Sites[Randomized last 3 months],${c})`;
    });
    ["C","D","E","F","G","H"].forEach(c=>s.range(`${c}49`).formulas = `=SUM(${c}45:${c}48)`);
    s.range("A44:H44").format({ bold: true, fill: "accent1", color: "white", wrap: true });
    s.range("A49:H49").format({ bold: true, borderTop: "medium" });
    s.range("D45:E49").numberFormat = "#,##0.0";
    s.range("F45:F49").numberFormat = "#,##0";
    s.range("G45:G49").numberFormat = "+#,##0.0;-#,##0.0;0";
    s.range("H45:H49").numberFormat = "#,##0";
    s.range("B45:B49").format({ wrap: true });
    
    // Checks: status groups cover all sites
    const ck = wb.sheets.get("Checks");
    ck.range("A13:C13").values = [["Sites by status vs sites in plan", "=Sites!C49", "=ROWS(Plan[Site ID])"]];
    ck.range("D13").formulas = "=B13-C13";
    ck.range("D14").formulas = "=SUMPRODUCT(ABS(D2:D13))";
    ck.range("A14").values=[["All checks (should be 0)"]];
    ck.range("B13:D13").numberFormat = "#,##0";
    
    // ---------- Summary ----------
    const sm = wb.sheets.add("Summary");
    wb.sheets.move("Summary", 0);
    sm.showGridLines = false;
    sm.range("A1").values = [["VRD-301 enrollment: steering committee summary"]];
    sm.merge("A1:D1");
    sm.range("A1:D1").format({ bold: true, size: 16, fill: "accent1", color: "white" });
    sm.range("A2").formulas = '="CTMS data as of "&TEXT(AsOf,"d mmmm yyyy")';
    sm.range("A2").format({ italic: true, color: "slate-600" });
    sm.range("A4:B4").values = [["Enrollment","Value"]];
    sm.range("A5:A13").values = [["Randomization target"],["Randomized"],["Share of target"],["Original plan to date"],["Versus plan to date"],["Planned rate per month"],["Run rate per month (last 3 months)"],["Overall screen-fail rate"],["Sites red, amber, green"]];
    sm.range("B5").formulas = "=Target";
    sm.range("B6").formulas = "=Forecast!B4";
    sm.range("B7").formulas = "=B6/B5";
    sm.range("B8").formulas = "=Forecast!B6";
    sm.range("B9").formulas = "=B6-B8";
    sm.range("B10").formulas = "=Forecast!B7";
    sm.range("B11").formulas = "=Forecast!B8";
    sm.range("B12").formulas = "='Screen fails'!B22";
    sm.range("B13").formulas = "=Sites!T40";
    sm.range("B5:B6").numberFormat = "#,##0"; sm.range("B7").numberFormat = "0%"; sm.range("B8").numberFormat = "#,##0";
    sm.range("B9").numberFormat = "+#,##0;-#,##0;0"; sm.range("B10:B11").numberFormat = "#,##0"; sm.range("B12").numberFormat = "0.0%";
    sm.range("B5:B13").format({ align: "right" });
    sm.range("A4:B4").format({ bold: true, borderBottom: "medium" });
    sm.range("A15:D15").values = [["Last patient in","Date","Months later than original plan","Days earlier than run rate alone"]];
    sm.range("A16:A22").formulas = "=Forecast!A12";
    sm.range("B16:B22").formulas = "=Forecast!B12";
    sm.range("C16:C22").formulas = "=Forecast!C12";
    sm.range("D16:D22").formulas = "=Forecast!D12";
    sm.range("B16:B22").numberFormat = "d mmm yyyy"; sm.range("C16:C22").numberFormat = "0.0"; sm.range("D16:D22").numberFormat = "#,##0;-#,##0;0";
    sm.range("A15:D15").format({ bold: true, borderBottom: "medium", wrap: true });
    sm.range("A24").formulas = '="Model checks: "&IF(Checks!D14=0,"all site totals tie to the CTMS log","CHECK FAILED, see Checks sheet")';
    sm.range("A24").format({ bold: true, color: "green-700" });
    sm.setColumnWidth("A", 300).setColumnWidth("B", 150).setColumnWidth("C:D", 150);
    sm.charts.add("line", { data: "Monthly!A1:C20", at: "A26", size: { w: 750, h: 300 }, title: "Randomized fell 195 behind plan by September 2026" });
    
    return { mix, g, statusSummary: s.range("A45:H49").values, check: ck.range("D13:D14").values, summary: sm.range("A5:B13").values };
    {
      "ok": true,
      "value": {
        "mix": {
          "I-04 HbA1c outside 7.0-10.5%": 28,
          "I-06 UACR below 200 mg/g": 18,
          "E-07 eGFR below 25": 20,
          "E-11 CV event in past 6 months": 7,
          "O-02 Screening window expired": 5,
          "E-03 Uncontrolled blood pressure": 8,
          "I-02 Age outside 30-80": 3,
          "E-15 SGLT2 inhibitor in past 8 weeks": 2
        },
        "g": [
          [
            28
          ],
          [
            20
          ],
          [
            18
          ],
          [
            7
          ],
          [
            2
          ],
          [
            8
          ],
          [
            5
          ],
          [
            3
          ],
          [
            91
          ]
        ],
        "statusSummary": [
          [
            "Red: no screening",
            "No screening in more than 30 days",
            7,
            19.5,
            235.5,
            145,
            -90.5,
            23
          ],
          [
            "Red: high screen-fail",
            "Screen-fail rate above 35%",
            3,
            8.5,
            141,
            100,
            -41,
            18
          ],
          [
            "Amber",
            "More than 20% behind plan to date",
            7,
            18,
            274.5,
            186,
            -88.5,
            43
          ],
          [
            "Green",
            "On or near plan",
            21,
            59,
            745,
            770,
            25,
            180
          ],
          [
            "All sites",
            null,
            38,
            105,
            1396,
            1201,
            -195,
            264
          ]
        ],
        "check": [
          [
            0
          ],
          [
            0
          ]
        ],
        "summary": [
          [
            "Randomization target",
            1700
          ],
          [
            "Randomized",
            1201
          ],
          [
            "Share of target",
            0.7064705882352941
          ],
          [
            "Original plan to date",
            1396
          ],
          [
            "Versus plan to date",
            -195
          ],
          [
            "Planned rate per month",
            105
          ],
          [
            "Run rate per month (last 3 months)",
            88
          ],
          [
            "Overall screen-fail rate",
            0.23518850987432674
          ],
          [
            "Sites red, amber, green",
            "10 red, 7 amber, 21 green"
          ]
        ]
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Summary",
        "Screening log",
        "Site plan",
        "Inputs",
        "Sites",
        "Monthly",
        "Screen fails",
        "Forecast",
        "Checks"
      ],
      "version": 4,
      "lint": {
        "err
    …
  21. Formula fixed (now matches the raw log: 91 of 393 screen fails come from the three high-fail sites). Linting the workbook.

  22. artiwright_lint
    {
      "document": "model"
    }
    {
      "ok": true,
      "errors": 0,
      "warnings": 18,
      "findings": [
        {
          "rule": "text/clipped",
          "sheet": "Summary",
          "range": "B13",
          "message": "Summary!B13 is cut off: \"10 red, 7 amber, 21 green\" is wider than the column and A13 is not empty.",
          "evidence": {
            "needs": 165,
            "width": 150
          },
          "fix": "Widen the column, wrap the text (format({ wrap: true })), or shorten it.",
          "severity": "warn"
        },
        {
          "rule": "text/clipped",
          "sheet": "Screening log",
          "range": "F1",
          "message": "Screening log!F1 is cut off: \"Randomized on\" is wider than the column and G1 is not empty.",
          "evidence": {
            "needs": 110,
            "width": 108
          },
          "fix": "Widen the column, wrap the text (format({ wrap: true })), or shorten it.",
          "severity": "warn"
        },
        {
          "rule": "text/clipped",
          "sheet": "Sites",
          "range": "A45",
          "message": "Sites!A45 is cut off: \"Red: no screening\" is wider than the column and B45 is not empty.",
          "evidence": {
            "needs": 119,
            "width": 70
          },
          "fix": "Widen the column, wrap the text (format({ wrap: true })), or shorten it.",
          "severity": "warn"
        },
        {
          "rule": "text/clipped",
          "sheet": "Sites",
          "range": "A46",
          "message": "Sites!A46 is cut off: \"Red: high screen-fail\" is wider than the column and B46 is not empty.",
          "evidence": {
            "needs": 136,
            "width": 70
          },
          "fix": "Widen the column, wrap the text (format({ wrap: true })), or shorten it.",
          "severity": "warn"
        },
        {
          "rule": "text/clipped",
          "sheet": "Monthly",
          "range": "B1",
          "message": "Monthly!B1 is cut off: \"Cumulative plan\" is wider than the column and C1 is not empty.",
          "evidence": {
            "needs": 111,
            "width": 105
          },
          "fix": "Widen the column, wrap the text (format({ wrap: true })), or shorten it.",
          "severity": "warn"
        },
        {
          "rule": "text/clipped",
          "sheet": "Monthly",
          "range": "C1",
          "message": "Monthly!C1 is cut off: \"Cumulative randomized\" is wider than the column and D1 is not empty.",
          "evidence": {
            "needs": 157,
            "width": 105
          },
          "fix": "Widen the column, wrap the text (format({ wrap: true })), or shorten it.",
          "severity": "warn"
    …
  23. artiwright_run
    wb.sheets.get("Summary").setColumnWidth("B", 180);
    wb.sheets.get("Screening log").setColumnWidth("F", 120);
    wb.sheets.get("Sites").setColumnWidth("A", 150);
    wb.sheets.get("Monthly").setColumnWidth("B:C", 160);
    const mo = wb.sheets.get("Monthly"); mo.range("E2:E20").numberFormat = "0";
    const f = wb.sheets.get("Screen fails"); f.setColumnWidth("B", 250).setColumnWidth("I", 115).setColumnWidth("A", 370);
    const fc = wb.sheets.get("Forecast"); fc.setColumnWidth("A", 320);
    fc.range("C12:C18").formulas = "=YEARFRAC($B$12,B12,1)*12";
    wb.sheets.move("Screening log", 8); wb.sheets.move("Site plan", 8);
    return { order: wb.sheets.items ? wb.sheets.items.map(s=>s.name) : null, c: fc.range("C12:C18").values };
    {
      "ok": true,
      "value": {
        "order": [
          "Summary",
          "Inputs",
          "Sites",
          "Monthly",
          "Screen fails",
          "Forecast",
          "Checks",
          "Screening log",
          "Site plan"
        ],
        "c": [
          [
            0
          ],
          [
            1.841095890410959
          ],
          [
            2.728767123287671
          ],
          [
            3.3863013698630136
          ],
          [
            2.4986301369863013
          ],
          [
            2.5643835616438357
          ],
          [
            2.367123287671233
          ]
        ]
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Summary",
        "Inputs",
        "Sites",
        "Monthly",
        "Screen fails",
        "Forecast",
        "Checks",
        "Screening log",
        "Site plan"
      ],
      "version": 5,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  24. artiwright_render
    {
      "document": "model",
      "sheets": [
        "Summary",
        "Forecast"
      ]
    }
    Sheet Summary[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785333952-jv2ck0.png]Sheet Forecast[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785333955-xt1e9d.png]
    A render the agent looked atA render the agent looked at
  25. artiwright_help
    {
      "query": "WorkbookChartOptions.axes, sheet.charts, sheet.setRowHeight",
      "maxChars": 4000
    }
    WorkbookChartOptions.axes: help: nothing called "WorkbookChartOptions.axes". Try help() for the overview or help({ search: "…" }).
    
    2 entries under sheet.charts:
      sheet.charts.add  A native chart of cells on this (or another) sheet.
      sheet.charts.items  The charts on this sheet.
    
    sheet.setRowHeight: sheet.setRowHeight(rows: number | string, px: number): this
    Sets row heights in px: `sheet.setRowHeight(1, 32)`, `sheet.setRowHeight("2:10", 24)`. Rows are 1-based like Excel's.
    
    Examples:
      sheet.setRowHeight(1, 32)
      sheet.setRowHeight("2:10", 24)
  26. artiwright_help
    {
      "query": "sheet.charts.add, sheet.charts.items",
      "maxChars": 4000
    }
    sheet.charts.add: sheet.charts.add(type: ChartType, options: SheetChartOptions): SheetChart
    A native chart of cells on this (or another) sheet. The first row names the series and the first column holds the categories: `charts.add("column", { data: "A1:C13", at: "E2", title: "Revenue by month" })`.
    
    SheetChartOptions:
      data: string  The cells to plot: "A1:C13" on this sheet or "Model!A1:C13".
      seriesIn? (columns | rows)  Series run down columns (default) or across rows.
      at: string  The chart's top-left cell.
      size?: { w: number; h: number }  Size in px (default 480×288), or `to` for the bottom-right cell.
      to?: string
      series?: Array<Partial<ChartSeriesInput>>  Per-series look, by position: `[{ fill: "accent2" }, { type: "line", axis: "secondary" }]`.
      name?: string
      alt?: string
      title?: string | { text: string; style?: string | TextStyle; overlay?: boolean }
      legend?: false | LegendPosition | { position?: LegendPosition; overlay?: boolean; style?: string | TextStyle }  Position, false to hide, or options.
      dataLabels?: boolean | DataLabelsInput  Labels on every series.
      stacked?: boolean | "percent"  Column, bar, line and area charts: stack series, or stack to 100%.
      axes?: { x?: AxisInput; y?: AxisInput; y2?: AxisInput }  y2: the secondary value axis on the right, for series with axis: "secondary".
      gap?: number  Space between bar groups, percent of a bar's width (0–500).
      overlap?: number  Bar overlap within a group, percent (-100–100).
      holeSize?: number  Doughnut hole, percent of the diameter (10–90).
      firstSliceAngle?: number  Pie and doughnut rotation in degrees.
      varyColors?: boolean  A different color for every point.
      radarStyle? (marker | filled | lines)
      blanks? (gap | zero | span)  How gaps draw: leave a gap, drop to zero, or connect across.
      style?: string | TextStyle  Default text for the chart: font, size, color.
      background?: string
      border?: string | LineOptions
      plotBackground?: string
      upDownBars?: boolean  Stock charts with four series (open, high, low, close).
      highLowLines?: boolean
      totals?: number[]  Waterfall: indexes of the points that are totals (full bars from zero), e.g. [0, 4].
      connectorLines?: boolean  Waterfall: lines joining the bars (default true).
      parentLabels? (overlapping | banner | none)  Treemap: parent labels (default "overlapping").
      bins?: number | { count?: number; width?: number } 
    …
  27. artiwright_runerror
    const out = {};
    const redo = (sheetName, type, opts) => {
      const sh = wb.sheets.get(sheetName);
      const ch = sh.charts.items[0];
      if (ch.remove) ch.remove(); else sh.charts.remove(ch);
      sh.charts.add(type, opts);
    };
    const x = { format: "mmm yy" };
    redo("Summary", "line", { data: "Monthly!A1:C20", at: "A26", size: { w: 780, h: 300 }, axes: { x }, title: "Randomized fell 195 behind plan by September 2026" });
    redo("Monthly", "line", { data: "A1:C20", at: "K2", size: { w: 620, h: 320 }, axes: { x }, title: "Randomizations fell behind plan from mid-2025" });
    redo("Forecast", "line", { data: "A21:F30", at: "F2", size: { w: 620, h: 300 }, axes: { x, y: { min: 1200 } }, title: "Every scenario reaches 1,700 after the December 2026 plan" });
    wb.sheets.get("Summary").setRowHeight(15, 36);
    wb.sheets.get("Forecast").setRowHeight(11, 36).setRowHeight(21, 36);
    wb.sheets.get("Screen fails").setRowHeight(3, 48);
    wb.sheets.get("Sites").setRowHeight(1, 36).setRowHeight(44, 36);
    return wb.sheets.get("Forecast").charts.items.length;
    {
      "ok": false,
      "error": {
        "name": "TypeError",
        "message": "sh.charts.remove is not a function"
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Summary",
        "Inputs",
        "Sites",
        "Monthly",
        "Screen fails",
        "Forecast",
        "Checks",
        "Screening log",
        "Site plan"
      ],
      "version": 5,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  28. Polishing the workbook charts (date axes were showing serial numbers). Looking up how to edit an existing chart.

  29. artiwright_help
    {
      "query": "SheetChart",
      "maxChars": 2500
    }
    Nothing is called "SheetChart". Closest entries (ask help(path) for one):
      SheetChartOptions
  30. artiwright_run
    const ch = wb.sheets.get("Forecast").charts.items[0];
    let p = Object.getPrototypeOf(ch); const k = new Set(Object.keys(ch));
    while (p && p !== Object.prototype) { Object.getOwnPropertyNames(p).forEach(n=>k.add(n)); p = Object.getPrototypeOf(p); }
    return [...k];
    {
      "ok": true,
      "value": [
        "sheet",
        "type",
        "options",
        "name",
        "constructor"
      ],
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Summary",
        "Inputs",
        "Sites",
        "Monthly",
        "Screen fails",
        "Forecast",
        "Checks",
        "Screening log",
        "Site plan"
      ],
      "version": 5,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  31. artiwright_run
    const x = { format: "mmm yy" };
    const set = (name, patch) => { const ch = wb.sheets.get(name).charts.items[0]; Object.assign(ch.options, patch); return ch.options; };
    set("Summary", { axes: { x }, size: { w: 780, h: 300 } });
    set("Monthly", { axes: { x } });
    const o = set("Forecast", { data: "A21:F30", axes: { x, y: { min: 1200 } }, title: "Every scenario reaches 1,700 after the December 2026 plan" });
    wb.sheets.get("Summary").setRowHeight(15, 36);
    wb.sheets.get("Forecast").setRowHeight(11, 36).setRowHeight(21, 36);
    wb.sheets.get("Screen fails").setRowHeight(3, 48);
    wb.sheets.get("Sites").setRowHeight(1, 36).setRowHeight(44, 36);
    return o;
    {
      "ok": true,
      "value": {
        "data": "A21:F30",
        "at": "F2",
        "size": {
          "w": 620,
          "h": 300
        },
        "title": "Every scenario reaches 1,700 after the December 2026 plan",
        "axes": {
          "x": {
            "format": "mmm yy"
          },
          "y": {
            "min": 1200
          }
        }
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Summary",
        "Inputs",
        "Sites",
        "Monthly",
        "Screen fails",
        "Forecast",
        "Checks",
        "Screening log",
        "Site plan"
      ],
      "version": 6,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  32. artiwright_render
    {
      "document": "model",
      "sheets": [
        "Forecast",
        "Sites",
        "Screen fails"
      ],
      "range": "A1:U49"
    }
    Sheet Forecast A1:U49[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785359783-wjm7bo.png, original 2180x1032, displayed at 2000x947. Multiply coordinates by 1.09 to map to original image.]Sheet Sites A1:U49[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785359787-0pvmhm.png, original 2302x1032, displayed at 2000x897. Multiply coordinates by 1.15 to map to original image.]Sheet Screen fails A1:U49[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785359787-cue4ty.png, original 2214x1028, displayed at 2000x929. Multiply coordinates by 1.11 to map to original image.]
    A render the agent looked atA render the agent looked atA render the agent looked at
  33. artiwright_run
    // chart helper blocks with text month labels
    const fc = wb.sheets.get("Forecast");
    fc.range("R21:W21").values = [["Chart: month","Target","At planned rate","At run rate","By trend","Run rate + both mitigations"]];
    fc.range("R22:R30").formulas = '=TEXT(A22,"mmm yy")';
    fc.range("S22:S30").formulas = "=B22"; fc.range("T22:T30").formulas = "=C22"; fc.range("U22:U30").formulas = "=D22"; fc.range("V22:V30").formulas = "=E22"; fc.range("W22:W30").formulas = "=F22";
    fc.range("S22:W30").numberFormat = "#,##0";
    fc.range("R21:W21").format({ bold: true, wrap: true });
    fc.setColumnWidth("R:W", 100);
    Object.assign(fc.charts.items[0].options, { data: "R21:W30", axes: { y: { min: 1200 } } });
    const mo = wb.sheets.get("Monthly");
    mo.range("K1:M1").values = [["Chart: month","Cumulative plan","Cumulative randomized"]];
    mo.range("K2:K20").formulas = '=TEXT(A2,"mmm yy")';
    mo.range("L2:L20").formulas = "=B2"; mo.range("M2:M20").formulas = "=C2";
    mo.range("L2:M20").numberFormat = "#,##0";
    mo.range("K1:M1").format({ bold: true, wrap: true });
    mo.setColumnWidth("K:M", 100);
    mo.setRowHeight(1, 36);
    Object.assign(mo.charts.items[0].options, { data: "K1:M20", at: "O2", axes: {} });
    Object.assign(wb.sheets.get("Summary").charts.items[0].options, { data: "Monthly!K1:M20", axes: {} });
    fc.setRowHeight(11, 52).setRowHeight(21, 52);
    const f = wb.sheets.get("Screen fails");
    f.range("B16:B21").numberFormat = "#,##0"; f.range("B25").numberFormat = "#,##0";
    f.setRowHeight(3, 66).setRowHeight(26, 36).setRowHeight(17, 20);
    f.range("A17").format({ wrap: false }); f.setColumnWidth("A", 380);
    const s = wb.sheets.get("Sites");
    s.setRowHeight(1, 52).setRowHeight(44, 52);
    s.setColumnWidth("B", 200);
    return "ok";
    {
      "ok": true,
      "value": "ok",
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Summary",
        "Inputs",
        "Sites",
        "Monthly",
        "Screen fails",
        "Forecast",
        "Checks",
        "Screening log",
        "Site plan"
      ],
      "version": 7,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  34. artiwright_render
    {
      "document": "model",
      "sheets": [
        "Summary",
        "Monthly"
      ],
      "range": "A1:U42"
    }
    Sheet Summary A1:U42[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785377731-qsgpay.png]Sheet Monthly A1:U42[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785377731-2xu8ab.png]
    A render the agent looked atA render the agent looked at
  35. artiwright_run
    wb.sheets.get("Monthly").range("C2:C20").numberFormat = "#,##0";
    wb.sheets.get("Monthly").setColumnWidth("C", 170);
    wb.sheets.get("Summary").setRowHeight(1, 32);
    return wb.lint().length ?? wb.lint();
    {
      "ok": true,
      "value": {
        "ok": true,
        "errors": 0,
        "warnings": 0,
        "findings": []
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 0,
      "sheets": [
        "Summary",
        "Inputs",
        "Sites",
        "Monthly",
        "Screen fails",
        "Forecast",
        "Checks",
        "Screening log",
        "Site plan"
      ],
      "version": 8,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  36. artiwright_finalizeVRD-301_enrollment_model.xlsx
    {
      "document": "model",
      "file": "VRD-301_enrollment_model.xlsx",
      "requirements": {
        "sheets": [
          "Summary",
          "Inputs",
          "Sites",
          "Monthly",
          "Screen fails",
          "Forecast",
          "Checks",
          "Screening log",
          "Site plan"
        ],
        "tables": [
          "Log",
          "Plan",
          "Sites",
          "Monthly",
          "FailReasons",
          "Projection"
        ],
        "charts": 4,
        "values": [
          {
            "cell": "Checks!D14",
            "equals": 0
          },
          {
            "cell": "Sites!I40",
            "equals": 1738
          },
          {
            "cell": "Sites!J40",
            "equals": 1201
          },
          {
            "cell": "Forecast!B5",
            "equals": 499
          }
        ],
        "lint": {
          "block": [
            "error",
            "warn"
          ]
        }
      }
    }
    {
      "ok": true,
      "blocking": [],
      "warnings": [],
      "checks": [
        {
          "step": 1,
          "code": "path",
          "ok": true
        },
        {
          "step": 2,
          "code": "validate",
          "ok": true
        },
        {
          "step": 3,
          "code": "requirements",
          "ok": true
        },
        {
          "step": 4,
          "code": "lint",
          "ok": true
        },
        {
          "step": 5,
          "code": "publish",
          "ok": true
        }
      ],
      "path": "./sessions/default/outputs/VRD-301_enrollment_model.xlsx",
      "sha256": "d718ed7f012a6a0cfb054fc212488d10bd60e98067b426d18eecabd8079c465f",
      "bytes": 108569,
      "receiptPath": "./sessions/default/.artiwright/receipts/VRD-301_enrollment_model.d718ed7f012a.1794785387104.receipt.json"
    }
  37. Workbook published with all checks passing. Now pulling the deck figures from the model and building the steering committee deck.

  38. artiwright_run
    const S = wb.sheets.get("Sites"), F = wb.sheets.get("Screen fails"), FC = wb.sheets.get("Forecast"), M = wb.sheets.get("Monthly");
    const d = v => { const x = new Date(Date.UTC(1899,11,30)+v*864e5); return x.getUTCDate()+" "+["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][x.getUTCMonth()]+" "+x.getUTCFullYear(); };
    const sites = S.range("A2:U39").values;
    return {
      monthly: M.range("K2:M20").values,
      red: sites.filter(r=>r[19]==="Red").map(r=>[r[0], r[2], r[20], r[9], r[7], r[18]]),
      amber: sites.filter(r=>r[19]==="Amber").map(r=>r[0]),
      groups: S.range("A45:H49").values,
      fails: F.range("A4:G12").values.map(r=>[r[1], r[2], r[3], r[6]]),
      funnel: F.range("B16:B27").values.flat(),
      lpi: FC.range("A12:D18").values.map(r=>[r[0], d(r[1]), Math.round(r[2]*10)/10, r[3]]),
      rates: FC.range("B4:B9").values.flat(),
    };
    {
      "ok": true,
      "value": {
        "monthly": [
          [
            "Mar 25",
            0,
            1
          ],
          [
            "Apr 25",
            14,
            14
          ],
          [
            "May 25",
            40,
            30
          ],
          [
            "Jun 25",
            80,
            62
          ],
          [
            "Jul 25",
            125,
            93
          ],
          [
            "Aug 25",
            178.5,
            156
          ],
          [
            "Sep 25",
            241,
            199
          ],
          [
            "Oct 25",
            305.5,
            254
          ],
          [
            "Nov 25",
            378.5,
            315
          ],
          [
            "Dec 25",
            464,
            386
          ],
          [
            "Jan 26",
            562.5,
            472
          ],
          [
            "Feb 26",
            661,
            560
          ],
          [
            "Mar 26",
            766,
            648
          ],
          [
            "Apr 26",
            871,
            750
          ],
          [
            "May 26",
            976,
            847
          ],
          [
            "Jun 26",
            1081,
            937
          ],
          [
            "Jul 26",
            1186,
            1039
          ],
          [
            "Aug 26",
            1291,
            1114
          ],
          [
            "Sep 26",
            1396,
            1201
          ]
        ],
        "red": [
          [
            "US-103",
            "United States",
            "no screening for 63 days; 39% behind plan",
            31,
            51,
            1
          ],
          [
            "US-104",
            "United States",
            "screen-fail 45%",
            46,
            48,
            8
          ],
          [
            "US-110",
            "United States",
            "screen-fail 45%; 53% behind plan",
            21,
            45,
            3
          ],
          [
            "PL-106",
            "Poland",
            "screen-fail 45%; 31% behind plan",
            33,
            48,
            7
          ],
          [
            "ES-103",
            "Spain",
            "no screening for 102 days; 47% behind plan",
            24,
            45.5,
            1
          ],
          [
            "DE-103",
            "Germany",
            "no screening for 43 days; 31% behind plan",
            27,
            39,
            7
          ],
          [
            "DE-104",
            "Germany",
            "no screening for 100 days; 30% behind plan",
            21,
            30,
            2
          ],
          [
            "BR-102",
            "Brazil",
            "no screening for 59 days; 39% behind plan",
            15,
            24.5,
            8
          ],
          [
            "KR-101",
            "South Korea",
            "no screening for 91 days; 28%
    …
  39. artiwright_help
    {
      "query": "guide notes-and-comments",
      "maxChars": 3000
    }
    # Notes, comments and footers guide
    
    ```js test
    const s = deck.slides.add({ layout: "title-only", title: "Q3 at a glance" });
    s.notes = "Open with the 18% growth; the next slide explains the enterprise deals.";
    deck.comments.setAuthor({ name: "Deck agent" });
    s.comment("Revenue is unaudited until the 15th.", { replies: ["Will update after close"] });
    deck.footer.set({ text: "Confidential", slideNumber: true });
    ```
    
    - **Speaker notes** (`slide.notes`): what the presenter says; good for detail cut from the slide.
    - **Comments** are PowerPoint's threaded comments: questions for reviewers, assumptions to confirm.
      Put one on an object with `{ target: chart }`; `reply`, `resolve` and `reopen` manage threads.
    - **Footer:** text, slide numbers and a date on every slide; a slide opts out with `slide.footer = false`.
    
  40. artiwright_run
    deck.comments.setAuthor({ name: "Enrollment model" });
    deck.footer.set({ text: "VRD-301 steering committee. CTMS data as of 30 September 2026", slideNumber: true });
    
    // 1. Title
    const s1 = deck.slides.add();
    compose(s1, h(TitleSlide, {
      eyebrow: "VRD-301",
      title: "Enrollment recovery: where we stand and what we need to decide",
      subtitle: "Steering committee. CTMS data as of 30 September 2026",
      figures: [
        { value: "1,201", label: "randomized of 1,700" },
        { value: "195", label: "behind plan to date" },
        { value: "21 Mar 2027", label: "last patient in at today's run rate" },
      ],
    }));
    s1.footer = false;
    s1.notes = "Source: CTMS screening log export and site plan, data as of 30 September 2026. The original plan reached 1,700 on 28 December 2026. Everything in this deck comes from the VRD-301 enrollment model workbook; all site totals tie to the log (1,738 subjects).";
    
    // 2. Enrollment against plan
    const mon = [["Mar 25",0,1],["Apr 25",14,14],["May 25",40,30],["Jun 25",80,62],["Jul 25",125,93],["Aug 25",178.5,156],["Sep 25",241,199],["Oct 25",305.5,254],["Nov 25",378.5,315],["Dec 25",464,386],["Jan 26",562.5,472],["Feb 26",661,560],["Mar 26",766,648],["Apr 26",871,750],["May 26",976,847],["Jun 26",1081,937],["Jul 26",1186,1039],["Aug 26",1291,1114],["Sep 26",1396,1201]];
    const s2 = deck.slides.add();
    compose(s2, h(ChartTakeaway, {
      title: "Randomization is 195 behind plan, and the gap has widened every month since February",
      chart: { type: "line", categories: mon.map(r=>r[0]), series: [
        { name: "Cumulative plan", values: mon.map(r=>r[1]) },
        { name: "Cumulative randomized", values: mon.map(r=>r[2]) }], format: "#,##0" },
      figure: { value: "1,201", label: "randomized, 71% of the 1,700 target" },
      takeaways: [
        "Sites randomize 88 a month against 105 planned",
        "All 38 sites have been on plan since March 2026, so the gap is site performance, not start-up",
        "Monthly randomizations peaked in April and July and have drifted down since",
      ],
      note: "Plan: each site's planned monthly rate from the month after activation. Run rate: July to September 2026.",
    }));
    s2.notes = "Plan to date 1,396 against 1,201 randomized. Gap by month: -101 in February, -118 March, -121 April, -129 May, -144 June, -147 July, -177 August, -195 September. The trend fitted since March 2026 falls by about 1.9 randomizations a month.";
    
    // 3. Sites holding us back
    const s3 = deck.slides.add();
    compose(s3, h(ComparisonTable, {
      title: "Ten sites are red: seven have stopped screening and three fail 45% of screens",
      rows: [
        ["Site", "Country", "Why red", "Randomized", "Plan to date"],
        ["ES-103", "Spain", "No screening for 102 days", 24, 45.5],
        ["DE-104", "Germany", "No screening for 100 days", 21, 30],
        ["KR-101", "South Korea", "No screening for 91 days", 13, 18],
        ["KR-103", "South Korea", "No screening for 76 days", 14, 27.5],
        ["US-103", "United States", "No screening for 63 days", 31, 51],
        ["BR-102", "Brazil", "No screening for 59 days", 15, 24.5],
        ["DE-103", "Germany", "No screening for 43 days", 27, 39],
        ["US-110", "United States", "Screen-fail 45%", 21, 45],
        ["PL-106", "Poland", "Screen-fail 45%", 33, 48],
        ["US-104", "United States", "Screen-fail 45%", 46, 48],
      ],
      takeaways: [
        "The seven silent sites hold 19.5 of the 105 planned randomizations a month",
        "Seven amber sites are more than 20% behind plan: US-101, US-105, US-106, PL-102, PL-103, DE-105, BR-101",
        "The 21 green sites are 25 ahead of plan",
      ],
      note: "Red: screen-fail above 35% or no screening in 30 days. Amber: more than 20% behind plan to date. Days counted to 30 September 2026.",
    }));
    s3.notes = "By group against plan to date: silent red sites -90.5, high screen-fail red sites -41, amber sites -88.5, green sites +25; total -195. Screen-fail rate counts CTMS status 'Screen failed' over completed screenings; consent withdrawals are kept separate. Counting withdrawals as fails would push DE-105, HU-101 and BR-103 over 35% as well; the switch is on the Inputs sheet.";
    
    // 4. Why screening fails
    const s4 = deck.slides.add();
    compose(s4, h(ChartTakeaway, {
      title: "HbA1c and eGFR account for 55% of the 393 screen fails",
      chart: { type: "bar", categories: ["HbA1c outside 7.0-10.5% (I-04)","eGFR below 25 (E-07)","UACR below 200 mg/g (I-06)","CV event in past 6 months (E-11)","SGLT2 inhibitor in past 8 weeks (E-15)","Uncontrolled blood pressure (E-03)","Screening window expired (O-02)","Age outside 30-80 (I-02)"],
        series: [{ name: "Screen fails", values: [120,95,51,35,30,29,18,15] }], format: "#,##0" },
      figure: { value: "23.5%", label: "of completed screenings fail" },
      takeaways: [
        "US-104, US-110 and PL-106 produce 91 of the 393 screen fails",
        "HbA1c fails equal 10.0% of randomizations, so the 10% pre-screening lift is a ceiling, not an estimate",
        "Screening window expiry (18) is the only operational cause; the rest are eligibility",
      ],
      note: "CTMS status 'Screen failed', all sites, to 30 September 2026. A further 77 subjects withdrew consent during screening.",
    }));
    s4.notes = "Funnel: 1,738 screened, 1,671 completed screening, 1,201 randomized, 393 screen failed, 77 withdrew consent, 67 still in screening. At the three high-fail sites the main reasons are HbA1c (28), eGFR (20) and UACR (18). The pre-screening lift of 10% assumes every HbA1c screen fail turns into a randomization; a realistic figure is lower, which is why we ask the medical monitor to weigh in.";
    const chart4 = s4.charts.items ? s4.charts.items[0] : null;
    s4.comment("Medical monitor: input needed on two points. (1) Can sites pre-screen HbA1c from a recent local or point-of-care result before the full screening visit, and what window would you accept? (2) eGFR below 25 (E-07) caused 95 screen fails: is the screening lab timing or a retest allowed under the protocol, or would this need an amendment?");
    
    // 5. Revised timeline
    const s5 = deck.slides.add();
    compose(s5, h(Timeline, {
      title: "Last patient in moves from 28 December 2026 to 21 March 2027 at today's run rate",
      steps: [
        { date: "28 Dec 2026", title: "Original plan", text: "Baseline" },
        { date: "22 Feb 2027", title: "At planned rate", text: "105 a month from October: 1.8 months late" },
        { date: "10 Mar 2027", title: "Run rate + both mitigations", text: "2.4 months late" },
        { date: "21 Mar 2027", title: "At run rate", text: "88 a month: 2.7 months late" },
        { date: "10 Apr 2027", title: "By trend", text: "If the decline since March continues: 3.4 months late" },
      ],
    }));
    s5.notes = "Forecast starts October 2026 with 499 randomizations to go. Planned rate is the sum of all 38 sites' planned rates (105 a month). Run rate averages July to September 2026 (88 a month). Trend is a straight line fitted to monthly randomizations from March to September 2026, when all sites were on plan. Pre-screening alone: 14 Mar 2027 (7 days earlier than run rate). Backup sites alone: 16 Mar 2027 (5 days earlier). Both: 10 Mar 2027 (11 days earlier). Mitigation timing is an assumption: pre-screening live January 2027, backup sites randomizing from February 2027. Risk: 23 of the last three months' randomizations came from the seven sites that have stopped screening, so the run rate will fall unless they restart.";
    
    // 6. Decisions
    const s6 = deck.slides.add();
    compose(s6, h(ComparisonTable, {
      title: "Four decisions today: the proposed mitigations gain 11 days, not the plan",
      rows: [
        ["Decision", "Effect on last patient in", "Ask of the committee"],
        ["Start HbA1c pre-screening from January 2027", "7 days earlier (14 Mar 2027)", "Approve, subject to the medical monitor's view"],
        ["Activate 4 backup sites, randomizing from February 2027", "5 days earlier (16 Mar 2027)", "Approve start-up"],
        ["Restart or close the 7 silent sites", "Protects the 88 a month run rate", "Agree a site-by-site plan"],
        ["Re-baseline last patient in", "10 Mar 2027 with both mitigations", "Approve the new date"],
      ],
      takeaways: [
        "Backup sites arrive too late to move the date much; earlier activation is the lever",
        "The silent sites gave 23 randomizations in the last three months and will give none if they stay idle",
      ],
      note: "Days measured against last patient in at the run rate (21 Mar 2027). Backup sites at 2.5 randomizations a month each.",
    }));
    s6.notes = "The brief asked for both mitigations to be costed. In randomizations: pre-screening adds 10% to the run rate (8.8 a month) from January; backup sites add 10 a month from February. Neither changes the date by more than a week because only about two and a half months of enrollment remain. The model's Inputs sheet lets the team test earlier start dates.";
    return deck.slides.items.map(s=>s.id);
    {
      "ok": true,
      "value": [
        "sl_J88QSHSQ",
        "sl_Y2C5DWQ6",
        "sl_J4NRFZCG",
        "sl_8EKVVPTC",
        "sl_D7SE7DGV",
        "sl_ENSWGRK4"
      ],
      "logs": [],
      "created": [
        "sl_J88QSHSQ",
        "sh_GAEBH7E1",
        "sh_WS0786KY",
        "sh_9J1G2HK2",
        "sh_SYQS65HZ",
        "sh_7QYB3WXW",
        "sh_DT2NXJMB",
        "sh_RJJRCMGG",
        "sh_0ZSSW29E",
        "sh_0T5GN0BQ",
        "sh_934YJ30E",
        "sl_Y2C5DWQ6",
        "sh_3D2DJGVS",
        "ch_RTFWFD24",
        "sh_AH6GK0TE",
        "sh_9R9SBQKZ",
        "sh_0E0YMVRS",
        "sh_F19QDR61",
        "sl_J4NRFZCG",
        "sh_Y3ZH1D1J",
        "tb_NBX9SEYN",
        "sh_G41XVCZJ",
        "sh_80WGM80H",
        "sl_8EKVVPTC",
        "sh_2B0DDA5A",
        "ch_EXB9Q2EX",
        "sh_CYZQFAHS",
        "sh_PA1DADX9",
        "sh_VZ5P26XX",
        "sh_K6F3M7RY",
        "th_GNG9M2M3",
        "sl_D7SE7DGV",
        "sh_FD5YF05Z",
        "sh_JZXZYDBP",
        "sh_3B5ETAE5",
        "sh_5Z1DF0AJ",
        "sh_N3EQSGP7",
        "sh_CSERFTFX",
        "sh_9PDGGNRS",
        "sh_5DJCMRN4",
        "sh_QC1GYRC3",
        "sh_Q4B8SNQ7",
        "sh_FW2RWQS1",
        "sh_F2NA5M7F",
        "sh_CVJAHK5K",
        "sh_VM9DV56C",
        "sh_DPV804Z6",
        "sh_JKFKCSA2",
        "sh_Q81QGHTD",
        "sh_J2H5KCV9",
        "sh_5VVB4FVE",
        "sh_7ERTNVHH",
        "sh_HBG4QVAV",
        "sh_A2S2VDXY",
        "sh_002A7TH2",
        "sh_Q2EFGWAJ",
        "sh_BQVNH72G",
        "sh_7DHJPA6H",
        "sl_ENSWGRK4",
        "sh_V8E3ZZ4S",
        "tb_4DFN8MCD",
        "sh_VXRSE7J6",
        "sh_0F2E8PVW"
      ],
      "removed": [],
      "slides": 6,
      "version": 1,
      "lint": {
        "errors": 10,
        "warnings": 11
      },
      "theme": {
        "theme": "Spruce",
        "source": "requested"
      }
    }
  41. artiwright_render
    {}
    Contact sheet of 6 slides.[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785466341-z86atn.png]
    A render the agent looked at
  42. artiwright_lint
    {}
    {
      "ok": false,
      "errors": 10,
      "warnings": 11,
      "findings": [
        {
          "rule": "text/overflow",
          "message": "Text in \"footer\" runs past the bottom of its box.",
          "evidence": {
            "lines": 2,
            "boxHeight": 38.3,
            "textHeight": 37.7
          },
          "fix": "Shorten the text, make the box taller, or set textBox: { autofit: \"shrink\" }.",
          "severity": "error",
          "slide": "sl_Y2C5DWQ6",
          "slideIndex": 2,
          "id": "sh_JMGFW4EJ"
        },
        {
          "rule": "layout/off-canvas",
          "message": "\"table\" extends 87 px outside the slide.",
          "evidence": {
            "bounds": [
              72,
              213,
              1136,
              594
            ],
            "slide": [
              1280,
              720
            ]
          },
          "fix": "Move or resize it to sit inside the slide.",
          "severity": "error",
          "slide": "sl_J4NRFZCG",
          "slideIndex": 3,
          "id": "tb_NBX9SEYN"
        },
        {
          "rule": "text/overflow",
          "message": "Text in \"bullets\" runs past the bottom of its box.",
          "evidence": {
            "lines": 4,
            "boxHeight": 108,
            "textHeight": 151.4
          },
          "fix": "Shorten the text, make the box taller, or set textBox: { autofit: \"shrink\" }.",
          "severity": "error",
          "slide": "sl_J4NRFZCG",
          "slideIndex": 3,
          "id": "sh_G41XVCZJ"
        },
        {
          "rule": "text/overflow",
          "message": "Text in \"Red: screen-fail above 35% or…\" runs past the bottom of its box.",
          "evidence": {
            "lines": 1,
            "boxHeight": 15,
            "textHeight": 23.1
          },
          "fix": "Shorten the text, make the box taller, or set textBox: { autofit: \"shrink\" }.",
          "severity": "error",
          "slide": "sl_J4NRFZCG",
          "slideIndex": 3,
          "id": "sh_80WGM80H"
        },
        {
          "rule": "text/overflow",
          "message": "Text in \"footer\" runs past the bottom of its box.",
          "evidence": {
            "lines": 2,
            "boxHeight": 38.3,
            "textHeight": 37.7
          },
          "fix": "Shorten the text, make the box taller, or set textBox: { autofit: \"shrink\" }.",
          "severity": "error",
          "slide": "sl_J4NRFZCG",
          "slideIndex": 3,
          "id": "sh_0RM7VMV7"
        },
        {
          "rule": "layout/overlap",
          "message": "Text in \"bullets\" overlaps the text of \"Red: screen-fail above 35% or…\".",
          "evidence": {
            "with": "
    …
  43. artiwright_run
    deck.footer.set({ text: "VRD-301 steering committee", slideNumber: true });
    ["sl_J4NRFZCG","sl_8EKVVPTC","sl_ENSWGRK4"].forEach(id=>deck.slides.remove(id));
    
    const s3 = deck.slides.add();
    compose(s3, h(ComparisonTable, {
      title: "Ten sites are red: seven have stopped screening and three fail 45% of screens",
      rows: [
        ["Site", "Why red", "Randomized of plan"],
        ["ES-103 Spain", "No screening for 102 days", "24 of 45.5"],
        ["DE-104 Germany", "No screening for 100 days", "21 of 30"],
        ["KR-101 South Korea", "No screening for 91 days", "13 of 18"],
        ["KR-103 South Korea", "No screening for 76 days", "14 of 27.5"],
        ["US-103 United States", "No screening for 63 days", "31 of 51"],
        ["BR-102 Brazil", "No screening for 59 days", "15 of 24.5"],
        ["DE-103 Germany", "No screening for 43 days", "27 of 39"],
        ["US-110 United States", "Screen-fail 45%", "21 of 45"],
        ["PL-106 Poland", "Screen-fail 45%", "33 of 48"],
        ["US-104 United States", "Screen-fail 45%", "46 of 48"],
      ],
      takeaways: [
        "Silent sites hold 19.5 of the 105 planned a month",
        "Seven amber sites are over 20% behind plan",
        "The 21 green sites are 25 ahead of plan",
      ],
      note: "Red: screen-fail over 35% or no screening in 30 days. Amber: over 20% behind plan to date.",
    }));
    s3.notes = "Amber sites: US-101, US-105, US-106, PL-102, PL-103, DE-105, BR-101. By group against plan to date: silent red sites -90.5, high screen-fail red sites -41, amber sites -88.5, green sites +25; total -195. Days without screening are counted to 30 September 2026. Screen-fail rate counts CTMS status 'Screen failed' over completed screenings; consent withdrawals are kept separate. Counting withdrawals as fails would also push DE-105, HU-101 and BR-103 over 35%; the switch is on the model's Inputs sheet.";
    
    const s4 = deck.slides.add();
    compose(s4, h(ChartTakeaway, {
      title: "HbA1c and eGFR account for 55% of the 393 screen fails",
      chart: { type: "bar", categories: ["HbA1c outside 7.0-10.5%","eGFR below 25","UACR below 200 mg/g","CV event in past 6 months","SGLT2 inhibitor in past 8 weeks","Uncontrolled blood pressure","Screening window expired","Age outside 30-80"],
        series: [{ name: "Screen fails", values: [120,95,51,35,30,29,18,15] }], format: "#,##0" },
      figure: { value: "23.5%", label: "of completed screenings fail" },
      takeaways: [
        "Three sites, US-104, US-110 and PL-106, produce 91 of the fails",
        "HbA1c fails equal 10.0% of randomizations: the assumed 10% lift is the ceiling",
      ],
      note: "CTMS status 'Screen failed' to 30 September 2026. 77 consent withdrawals are not counted.",
    }));
    s4.notes = "Criteria: I-04 HbA1c, E-07 eGFR, I-06 UACR, E-11 CV event, E-15 SGLT2 inhibitor, E-03 blood pressure, O-02 screening window, I-02 age. Funnel: 1,738 screened, 1,671 completed screening, 1,201 randomized, 393 screen failed, 77 withdrew consent, 67 still in screening. At the three high-fail sites the main reasons are HbA1c (28), eGFR (20) and UACR (18). The 10% pre-screening lift holds only if every HbA1c screen fail turned into a randomization; a realistic lift is lower, which is why we need the medical monitor's view. Screening window expiry (18) is the only operational cause; the rest are eligibility.";
    s4.comment("Medical monitor: your input is needed on two points before the committee. (1) Can sites pre-screen HbA1c from a recent local or point-of-care result before the full screening visit, and what result window would you accept? (2) eGFR below 25 (E-07) caused 95 screen fails: does the protocol allow a retest or different lab timing, or would that need an amendment?");
    
    const s6 = deck.slides.add();
    compose(s6, h(ComparisonTable, {
      title: "Four decisions today: the proposed mitigations gain 11 days, not the plan",
      rows: [
        ["Decision", "Effect on last patient in", "Ask"],
        ["Start HbA1c pre-screening in January", "7 days earlier", "Approve, pending the medical monitor"],
        ["Activate 4 backup sites, randomizing from February", "5 days earlier", "Approve start-up"],
        ["Restart or close the 7 silent sites", "Protects the 88 a month run rate", "Agree a plan per site"],
        ["Re-baseline last patient in", "10 Mar 2027", "Approve the new date"],
      ],
      takeaways: [
        "Backup sites start too late to move the date much",
        "Silent sites gave 23 randomizations in three months; idle, they give none",
      ],
      note: "Days against last patient in at the run rate, 21 Mar 2027.",
    }));
    s6.notes = "Pre-screening alone moves last patient in to 14 Mar 2027; backup sites alone to 16 Mar 2027; both to 10 Mar 2027. Pre-screening adds 10% to the run rate from January 2027; the four backup sites add 2.5 randomizations a month each from February 2027. Neither changes the date by more than a week because they start in January and February, leaving little enrollment for them to act on. Activating backup sites earlier is the main lever; the model's Inputs sheet lets the team test other start dates.";
    return deck.slides.items.map(s=>s.id);
    {
      "ok": true,
      "value": [
        "sl_J88QSHSQ",
        "sl_Y2C5DWQ6",
        "sl_D7SE7DGV",
        "sl_D58ATST1",
        "sl_V7DJFJVA",
        "sl_F68R1FHE"
      ],
      "logs": [],
      "created": [
        "sl_D58ATST1",
        "sh_XM41Z8G3",
        "tb_NS68QDRD",
        "sh_92C7V79K",
        "sh_2WT1M9PT",
        "sl_V7DJFJVA",
        "sh_5SNVT7MD",
        "ch_4CCC991K",
        "sh_NNV9NX70",
        "sh_0FBAX542",
        "sh_WKCZS0CN",
        "sh_D431KT2X",
        "th_GBVFEBT7",
        "sl_F68R1FHE",
        "sh_M3NJ1NZ7",
        "tb_11MTTY00",
        "sh_VBEK4WDR",
        "sh_X2479818"
      ],
      "removed": [
        "sl_J4NRFZCG",
        "sh_Y3ZH1D1J",
        "tb_NBX9SEYN",
        "sh_G41XVCZJ",
        "sh_80WGM80H",
        "sl_8EKVVPTC",
        "sh_2B0DDA5A",
        "ch_EXB9Q2EX",
        "sh_CYZQFAHS",
        "sh_PA1DADX9",
        "sh_VZ5P26XX",
        "sh_K6F3M7RY",
        "th_GNG9M2M3",
        "sl_ENSWGRK4",
        "sh_V8E3ZZ4S",
        "tb_4DFN8MCD",
        "sh_VXRSE7J6",
        "sh_0F2E8PVW"
      ],
      "slides": 6,
      "version": 2,
      "lint": {
        "errors": 4,
        "warnings": 4
      }
    }
  44. artiwright_run
    deck.slides.move("sl_D7SE7DGV", 4);
    return deck.slides.items.map(s=>s.id);
    {
      "ok": true,
      "value": [
        "sl_J88QSHSQ",
        "sl_Y2C5DWQ6",
        "sl_D58ATST1",
        "sl_V7DJFJVA",
        "sl_D7SE7DGV",
        "sl_F68R1FHE"
      ],
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 6,
      "version": 3,
      "lint": {
        "errors": 4,
        "warnings": 4
      }
    }
  45. artiwright_lint
    {}
    {
      "ok": false,
      "errors": 4,
      "warnings": 4,
      "findings": [
        {
          "rule": "layout/off-canvas",
          "message": "\"table\" extends 377 px outside the slide.",
          "evidence": {
            "bounds": [
              72,
              213,
              658,
              884
            ],
            "slide": [
              1280,
              720
            ]
          },
          "fix": "Move or resize it to sit inside the slide.",
          "severity": "error",
          "slide": "sl_D58ATST1",
          "slideIndex": 3,
          "id": "tb_NS68QDRD"
        },
        {
          "rule": "text/overflow",
          "message": "Text in \"Red: screen-fail over 35% or …\" runs past the bottom of its box.",
          "evidence": {
            "lines": 1,
            "boxHeight": 22,
            "textHeight": 23.1
          },
          "fix": "Shorten the text, make the box taller, or set textBox: { autofit: \"shrink\" }.",
          "severity": "error",
          "slide": "sl_D58ATST1",
          "slideIndex": 3,
          "id": "sh_2WT1M9PT"
        },
        {
          "rule": "layout/overlap",
          "message": "Text in \"Red: screen-fail over 35% or …\" overlaps the table \"table\".",
          "evidence": {
            "with": "tb_NS68QDRD",
            "overlap": [
              72,
              648,
              658,
              17
            ]
          },
          "fix": "Move one of them, or put them in a stack if the overlap is intended.",
          "severity": "warn",
          "slide": "sl_D58ATST1",
          "slideIndex": 3,
          "id": "sh_2WT1M9PT"
        },
        {
          "rule": "layout/overlap",
          "message": "Text in \"footer\" overlaps the table \"table\".",
          "evidence": {
            "with": "tb_NS68QDRD",
            "overlap": [
              442,
              679,
              199,
              15
            ]
          },
          "fix": "Move one of them, or put them in a stack if the overlap is intended.",
          "severity": "warn",
          "slide": "sl_D58ATST1",
          "slideIndex": 3,
          "id": "sh_WK9F7S88"
        },
        {
          "rule": "layout/off-canvas",
          "message": "\"table\" extends 20 px outside the slide.",
          "evidence": {
            "bounds": [
              72,
              213,
              658,
              527
            ],
            "slide": [
              1280,
              720
            ]
          },
          "fix": "Move or resize it to sit inside the slide.",
          "severity": "error",
          "slide": "sl_F68R1FHE",
          "slideIndex": 6,
          "id": "tb_11MTTY00"
        },
        {
          "rule": "text/overflow",
          "message": "T
    …
  46. artiwright_render
    {
      "slides": [
        2,
        3,
        4,
        5,
        6
      ]
    }
    Slide 2[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785498569-zwsvhk.png]Slide 3[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785498569-rkvrlu.png]Slide 4[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785498569-gr0gcj.png]Slide 5[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785498569-f4acfj.png]Slide 6[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785498569-e0mt7t.png]
    A render the agent looked atA render the agent looked atA render the agent looked atA render the agent looked atA render the agent looked at
  47. artiwright_help
    {
      "query": "TableOptions",
      "maxChars": 3500
    }
    TableOptions
      frame: Frame
      name?: string
      alt?: string
      rows: Cell[][]  Rows of cells, HTML-style: a cell with colSpan/rowSpan covers later positions, and the covered positions are left out of later cells in that row or the rows below.
      columns?: Array<number | string>  Column widths in px or fractions ("2fr").
      header?: boolean | number  Number of header rows (default 1).
      style?: TableStylePreset  Default "grid".
      headerFill?: string
      headerColor?: string
      bandFill?: string  Fill for alternating body rows.
      border?: string  Border stroke used by the preset, e.g. "1px solid slate-300".
      textStyle?: string | TextStyle  Style for body cells.
      headerStyle?: string | TextStyle  Style for header cells (merged over textStyle).
      padding?: number | { x: number; y: number }  Cell padding in px: one value or { x, y }.
      rowHeight?: number  Minimum row height in px.
      rowHeights?: number[]  Each row's height in px, overriding rowHeight (compose sets these from the measured text).
      numberAlign?: TextStyle["align"]  Alignment for columns whose body cells are all numbers, header included.
      Also accepted: data → rows, cells → rows, body → rows, colWidths → columns, columnWidths → columns, headerRows → header, position → frame, description → alt, preset → style, fontSize → textStyle.size, cellPadding → padding, margin → padding
  48. Slides 3 and 6 had tables running off the slide, so I'm rebuilding them as full-width tables with the key points alongside.

  49. artiwright_run
    const s3old = "sl_D58ATST1", s6old = "sl_F68R1FHE";
    const notes3 = deck.resolve(s3old).notes, notes6 = deck.resolve(s6old).notes;
    deck.slides.remove(s3old); deck.slides.remove(s6old);
    const tStyle = { style: "striped", textStyle: { size: 16 }, headerStyle: { size: 16, bold: true }, padding: { x: 12, y: 6 } };
    const bullets = (s, items, frame) => s.shapes.add({ geometry: "textbox", frame, text: items.map(t=>({ text: t, bullet: true })), textStyle: { size: 18, color: "text1" }, textBox: { valign: "top" } });
    
    // Slide 3
    const s3 = deck.slides.add({ layout: "title-only", title: "Ten sites are red: seven have stopped screening and three fail 45% of screens" });
    s3.tables.add({ ...tStyle, frame: { x: 72, y: 200, w: 720, h: 420 }, columns: ["1.3fr","2fr","1.1fr","1fr"], numberAlign: "right",
      rows: [
        ["Site", "Why red", "Randomized", "Plan to date"],
        ["ES-103 Spain", "No screening for 102 days", 24, 45.5],
        ["DE-104 Germany", "No screening for 100 days", 21, 30],
        ["KR-101 South Korea", "No screening for 91 days", 13, 18],
        ["KR-103 South Korea", "No screening for 76 days", 14, 27.5],
        ["US-103 United States", "No screening for 63 days", 31, 51],
        ["BR-102 Brazil", "No screening for 59 days", 15, 24.5],
        ["DE-103 Germany", "No screening for 43 days", 27, 39],
        ["US-110 United States", "Screen-fail 45%", 21, 45],
        ["PL-106 Poland", "Screen-fail 45%", 33, 48],
        ["US-104 United States", "Screen-fail 45%", 46, 48],
      ] });
    bullets(s3, [
      "The seven silent sites hold 19.5 of the 105 planned randomizations a month",
      "Seven amber sites are more than 20% behind plan",
      "The 21 green sites are 25 ahead of plan",
    ], { x: 830, y: 200, w: 380, h: 300 });
    s3.shapes.add({ geometry: "textbox", frame: { x: 72, y: 630, w: 1136, h: 26 }, text: "Red: screen-fail over 35% or no screening in 30 days. Amber: over 20% behind plan to date. Days counted to 30 September 2026.", textStyle: { size: 14, color: "text2" } });
    s3.notes = notes3;
    deck.slides.move(s3.id, 2);
    
    // Slide 6
    const s6 = deck.slides.add({ layout: "title-only", title: "Four decisions today: the proposed mitigations gain 11 days, not the plan" });
    s6.tables.add({ ...tStyle, textStyle: { size: 18 }, headerStyle: { size: 18, bold: true }, padding: { x: 14, y: 10 }, frame: { x: 72, y: 200, w: 1136, h: 300 }, columns: ["2.2fr","1.6fr","1.6fr"],
      rows: [
        ["Decision", "Effect on last patient in", "Ask of the committee"],
        ["Start HbA1c pre-screening in January 2027", "7 days earlier (14 Mar 2027)", "Approve, pending the medical monitor"],
        ["Activate 4 backup sites, randomizing from February 2027", "5 days earlier (16 Mar 2027)", "Approve start-up"],
        ["Restart or close the 7 silent sites", "Protects the 88 a month run rate", "Agree a plan for each site"],
        ["Re-baseline last patient in", "10 Mar 2027 with both mitigations", "Approve the new date"],
      ] });
    bullets(s6, [
      "Backup sites start too late to move the date much; earlier activation is the lever",
      "The silent sites gave 23 randomizations in the last three months and give none while idle",
    ], { x: 72, y: 530, w: 1136, h: 90 });
    s6.shapes.add({ geometry: "textbox", frame: { x: 72, y: 630, w: 1136, h: 26 }, text: "Days measured against last patient in at the run rate, 21 Mar 2027.", textStyle: { size: 14, color: "text2" } });
    s6.notes = notes6;
    return { order: deck.slides.items.map(s=>s.id), lint: deck.lint().findings ?? deck.lint() };
    {
      "ok": true,
      "value": {
        "order": [
          "sl_J88QSHSQ",
          "sl_Y2C5DWQ6",
          "sl_H6KYSY8C",
          "sl_V7DJFJVA",
          "sl_D7SE7DGV",
          "sl_X91GA5G5"
        ],
        "lint": [
          {
            "rule": "text/overflow",
            "message": "Text in \"title\" runs past the bottom of its box.",
            "evidence": {
              "lines": 2,
              "boxHeight": 139.3,
              "textHeight": 137.5
            },
            "fix": "Shorten the text, make the box taller, or set textBox: { autofit: \"shrink\" }.",
            "severity": "error",
            "slide": "sl_H6KYSY8C",
            "slideIndex": 3,
            "id": "sh_ATHP7C53"
          },
          {
            "rule": "text/overflow",
            "message": "Text in \"Red: screen-fail over 35% or …\" runs past the bottom of its box.",
            "evidence": {
              "lines": 1,
              "boxHeight": 26,
              "textHeight": 22.8
            },
            "fix": "Shorten the text, make the box taller, or set textBox: { autofit: \"shrink\" }.",
            "severity": "error",
            "slide": "sl_H6KYSY8C",
            "slideIndex": 3,
            "id": "sh_A0AK758Z"
          },
          {
            "rule": "text/overflow",
            "message": "Text in \"title\" runs past the bottom of its box.",
            "evidence": {
              "lines": 2,
              "boxHeight": 139.3,
              "textHeight": 137.5
            },
            "fix": "Shorten the text, make the box taller, or set textBox: { autofit: \"shrink\" }.",
            "severity": "error",
            "slide": "sl_X91GA5G5",
            "slideIndex": 6,
            "id": "sh_18D38ZAD"
          },
          {
            "rule": "text/overflow",
            "message": "Text in \"Days measured against last pa…\" runs past the bottom of its box.",
            "evidence": {
              "lines": 1,
              "boxHeight": 26,
              "textHeight": 22.8
            },
            "fix": "Shorten the text, make the box taller, or set textBox: { autofit: \"shrink\" }.",
            "severity": "error",
            "slide": "sl_X91GA5G5",
            "slideIndex": 6,
            "id": "sh_2NXTW4J6"
          }
        ]
      },
      "logs": [],
      "created": [
        "sl_H6KYSY8C",
        "sh_ATHP7C53",
        "tb_VQ8HDXR1",
        "sh_D95F4JX0",
        "sh_A0AK758Z",
        "sl_X91GA5G5",
        "sh_18D38ZAD",
        "tb_23QYZ4JN",
        "sh_Y43R0G4J",
        "sh_2NXTW4J6"
      ],
      "removed": [
        "sl_D58ATST1",
        "sh_XM41Z8G3",
        "tb_NS68QDRD",
        "sh_92C7V79K",
        "sh_2WT1M9PT",
        "sl_F68R1FHE",
        "s
    …
  50. artiwright_run
    const out = [];
    for (const id of ["sh_ATHP7C53","sh_18D38ZAD"]) { const t = deck.resolve(id); out.push(t.frame); }
    for (const id of ["sh_A0AK758Z","sh_2NXTW4J6"]) deck.resolve(id).update({ frame: { x: 72, y: 624, w: 1136, h: 34 } });
    return out;
    {
      "ok": true,
      "value": [
        {
          "x": 88,
          "y": 38.02,
          "w": 1104,
          "h": 139.32
        },
        {
          "x": 88,
          "y": 38.02,
          "w": 1104,
          "h": 139.32
        }
      ],
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 6,
      "version": 5,
      "lint": {
        "errors": 2,
        "warnings": 0
      }
    }
  51. artiwright_run
    for (const id of ["sh_ATHP7C53","sh_18D38ZAD"]) deck.resolve(id).update({ frame: { x: 72, y: 46, w: 1136, h: 146 } });
    return deck.lint();
    {
      "ok": true,
      "value": {
        "ok": true,
        "errors": 0,
        "warnings": 0,
        "findings": []
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 6,
      "version": 6,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  52. artiwright_render
    {
      "slides": [
        1,
        3,
        6
      ]
    }
    Slide 1[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785524359-sbfhm7.png]Slide 3[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785524359-hiqgmr.png]Slide 6[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785524359-99z3v5.png]
    A render the agent looked atA render the agent looked atA render the agent looked at
  53. artiwright_inspect
    {
      "kind": "text",
      "search": "title|Sites randomize",
      "slide": 2,
      "maxChars": 2500
    }
    {"kind":"text","id":"sh_3D2DJGVS","slide":"sl_Y2C5DWQ6","name":"title","bbox":[72,56,1136,129],"compose":"column:slide/column[0]:header/text[0]:title","text":"Randomization is 195 behind plan, and the gap has widened every month since February","chars":84,"lines":2,"fontPx":48}
    {"kind":"text","id":"sh_0E0YMVRS","slide":"sl_Y2C5DWQ6","name":"bullets","bbox":[845,343,363,290],"compose":"column:slide/column[1]:body/grid[0]/column[1]:takeaways/text[1]:bullets","text":"Sites randomize 88 a month against 105 planned\nAll 38 sites have been on plan since March 2026, so the gap is site performance, not start-up\nMonthly randomizations peaked in April and July and have d…","chars":216,"lines":8,"fontPx":24}
  54. artiwright_inspect
    {
      "kind": "text",
      "search": "title",
      "slide": 3,
      "maxChars": 1500
    }
    {"kind":"text","id":"sh_ATHP7C53","slide":"sl_H6KYSY8C","name":"title","bbox":[72,46,1136,146],"placeholder":"title","text":"Ten sites are red: seven have stopped screening and three fail 45% of screens","chars":77,"lines":2,"fontPx":58.67}
  55. artiwright_run
    const ref = deck.resolve("sh_3D2DJGVS");
    const st = ref.textStyle ?? ref.style ?? null;
    for (const id of ["sh_ATHP7C53","sh_18D38ZAD"]) {
      const t = deck.resolve(id);
      t.update({ frame: { x: 72, y: 56, w: 1136, h: 129 }, textStyle: st ?? { size: 36 } });
    }
    return { st, after: deck.resolve("sh_ATHP7C53").textStyle };
    {
      "ok": true,
      "value": {
        "st": null,
        "after": null
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 6,
      "version": 7,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  56. Matching the title styling on the two rebuilt slides to the rest of the deck, then a final review.

  57. artiwright_render
    {
      "slides": [
        2,
        3
      ]
    }
    Slide 2[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785537863-70avtw.png]Slide 3[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785537863-gm2lsz.png]
    A render the agent looked atA render the agent looked at
  58. artiwright_run
    for (const id of ["sh_ATHP7C53","sh_18D38ZAD"]) deck.resolve(id).update({ frame: { x: 62, y: 56, w: 1146, h: 129 }, textStyle: { size: 48 } });
    for (const id of ["sh_D95F4JX0","sh_Y43R0G4J"]) deck.resolve(id).update({ textStyle: { size: 22 } });
    deck.resolve("sh_D95F4JX0").update({ frame: { x: 830, y: 200, w: 378, h: 420 }, textBox: { valign: "top" } });
    return deck.lint();
    {
      "ok": true,
      "value": {
        "ok": true,
        "errors": 0,
        "warnings": 0,
        "findings": []
      },
      "logs": [],
      "created": [],
      "removed": [],
      "slides": 6,
      "version": 8,
      "lint": {
        "errors": 0,
        "warnings": 0
      }
    }
  59. artiwright_render
    {}
    Contact sheet of 6 slides.[Image: source: <render>sers-venu-Documents-Personal-paperwright-out-agent-runs-enrollment-rescue-work/d4cda6b0-a49b-45f7-b22b-5b0d6894650f/tool-results/mcp-artiwright-blob-1794785545283-qyoyvc.png]
    A render the agent looked at
  60. Lint is clean and the slides are consistent. Publishing the deck.

  61. artiwright_finalizeVRD-301_steerco_enrollment.pptx
    {
      "file": "VRD-301_steerco_enrollment.pptx",
      "requirements": {
        "slideCount": 6,
        "nativeCharts": [
          "sl_Y2C5DWQ6",
          "sl_V7DJFJVA"
        ],
        "nativeTables": [
          "sl_H6KYSY8C",
          "sl_X91GA5G5"
        ],
        "lint": {
          "block": [
            "error"
          ]
        }
      }
    }
    {
      "ok": true,
      "blocking": [],
      "warnings": [],
      "checks": [
        {
          "step": 1,
          "code": "path",
          "ok": true
        },
        {
          "step": 2,
          "code": "size",
          "ok": true
        },
        {
          "step": 2,
          "code": "validate",
          "ok": true
        },
        {
          "step": 3,
          "code": "package",
          "ok": true
        },
        {
          "step": 4,
          "code": "slideCount",
          "ok": true
        },
        {
          "step": 4,
          "code": "nativeCharts",
          "ok": true
        },
        {
          "step": 4,
          "code": "nativeTables",
          "ok": true
        },
        {
          "step": 4,
          "code": "numbers",
          "ok": true
        },
        {
          "step": 5,
          "code": "chartData",
          "ok": true
        },
        {
          "step": 6,
          "code": "lint",
          "ok": true
        },
        {
          "step": 7,
          "code": "reimport",
          "ok": true
        },
        {
          "step": 8,
          "code": "publish",
          "ok": true
        }
      ],
      "path": "./sessions/default/outputs/VRD-301_steerco_enrollment.pptx",
      "sha256": "6c20f0f4bd6c682f1a9e669f4d9c402586e9ddce1a0e3a02df23d9dd9fc46808",
      "bytes": 58327,
      "manifestPath": "./sessions/default/outputs/VRD-301_steerco_enrollment.pptx.manifest.ndjson",
      "receiptPath": "./sessions/default/.artiwright/receipts/VRD-301_steerco_enrollment.6c20f0f4bd6c.1794785551913.receipt.json"
    }
The agent's last message

I've built the enrollment model and a 6-slide steering committee deck in the Spruce theme. The site totals tie to the log exactly: 1,738 subjects in total, made up of 1,201 randomized, 393 screen failed, 77 withdrawn and 67 still in screening. The model has 12 tie-out checks and all of them come to zero. Every number in the deck comes from the model, and the publish step confirmed that.

Main finding: the two proposed mitigations together bring last patient in forward by only 11 days. They don't get close to the original plan date.

| Scenario | Last patient in |

|---|---|

| Original plan | 28 Dec 2026 |

| At planned rate (105 a month) | 22 Feb 2027 |

| Run rate + both mitigations | 10 Mar 2027 |

| At run rate (88 a month, Jul–Sep) | 21 Mar 2027 |

| By trend (falling about 1.9 a month since March) | 10 Apr 2027 |

  • Where things stand: 1,201 of 1,700 randomized, 195 behind plan. The gap has grown every month since February.
  • Site status: 10 red, 7 amber, 21 green. Seven red sites haven't screened anyone for 43 to 102 days. The other three red sites (US-104, US-110, PL-106) fail about 45% of screens.
  • The run rate will probably fall. The seven sites that have stopped screening still produced 23 randomizations in the last three months, from patients already in screening. Those will stop unless the sites restart, so even the 21 March date is optimistic.
  • Why screening fails: HbA1c (120) and eGFR (95) cause 55% of the 393 screen fails.
  • The 10% lift from HbA1c pre-screening is a best case. HbA1c fails add up to exactly 10.0% of randomizations, so the lift only reaches 10% if every one of those patients ends up randomized.
  • Medical monitor comment: it's on slide 4. It asks whether sites can pre-screen with a local HbA1c result, and whether the protocol allows an eGFR retest.

Assumptions I made that you should check (each one can be changed on the Inputs sheet):

  • Screen-fail rate counts only the "Screen failed" status, divided by completed screenings. Consent withdrawals are left out. If you count them as fails, DE-105, HU-101 and BR-103 also go red.
  • Mitigation timing: pre-screening starts in January 2027 and the backup sites start randomizing in February 2027. The brief didn't give dates. Activating the backup sites earlier is the main way to get more out of them.
  • The trend is fitted from March 2026, the first month all 38 sites were on plan. Fitting it to the whole history would include the start-up ramp and look too optimistic.
  • Data cut: the forecast starts in October 2026. October and November have already happened but aren't in this export.

Files are in out/agent-runs/enrollment-rescue/sessions/default/outputs/:

  • VRD-301_enrollment_model.xlsx
  • VRD-301_steerco_enrollment.pptx

Lint during the run

21 deck findings, then two tables still off the slide

Lint found 21 problems in the first draft of the deck: tables running off two slides, text running over its box and shapes overlapping. The agent shortened the footer, rebuilt three slides and linted again. Eight were left, including the same two tables off the slide, so it rebuilt those slides as full-width tables, made their title boxes taller and saved only when lint was clean. In the workbook it fixed 10 clipped labels and replaced a typed 365.25 in seven formulas with YEARFRAC.

  1. lintmodel10 × text/clipped1 × number/unformatted7 × Number typed into a formula
  2. finalizeVRD-301_enrollment_model.xlsxNo findings
  3. lint8 × Text overflows its box2 × Off the slide11 × Text overlaps
  4. lint2 × Off the slide2 × Text overflows its box4 × Text overlaps
  5. finalizeVRD-301_steerco_enrollment.pptxNo findings

Finalize report

Nothing is published until these pass. Finalize checks the real file and never overwrites one.

How this example was made: the request above went to Claude Code with Artiwright's MCP server and nothing else, using agent-runs/run.mjs. The files are what it finalized, opened in PowerPoint and Excel for the screenshots. Companies, people and figures are made up.