<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abhishek Khanra</title>
    <description>The latest articles on DEV Community by Abhishek Khanra (@nonebut_ak).</description>
    <link>https://dev.to/nonebut_ak</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4008506%2F23d6ba75-fdd8-4ecd-91ae-7cea1ae61d7c.jpg</url>
      <title>DEV Community: Abhishek Khanra</title>
      <link>https://dev.to/nonebut_ak</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nonebut_ak"/>
    <language>en</language>
    <item>
      <title>I Fixed Microsoft's BitNet C++ Kernels: How to Run 1-Bit LLMs on Pure CPU Without Compiling</title>
      <dc:creator>Abhishek Khanra</dc:creator>
      <pubDate>Tue, 13 Oct 2026 05:11:37 +0000</pubDate>
      <link>https://dev.to/nonebut_ak/i-fixed-microsofts-bitnet-c-kernels-how-to-run-1-bit-llms-on-pure-cpu-without-compiling-edh</link>
      <guid>https://dev.to/nonebut_ak/i-fixed-microsofts-bitnet-c-kernels-how-to-run-1-bit-llms-on-pure-cpu-without-compiling-edh</guid>
      <description>&lt;p&gt;Earlier this year, Microsoft Research published the BitNet b1.58 paper, demonstrating that 1-bit ternary models {-1, 0, +1} replace floating-point matrix multiplications with simple integer additions on CPU. On paper, this delivers 70–80% lower energy draw and extreme CPU inference throughput.&lt;/p&gt;

&lt;p&gt;However, compiling Microsoft's official research repository (&lt;code&gt;bitnet.cpp&lt;/code&gt;) has been broken for most developers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Hardcoded CMake compiler guards threw fatal errors under MSVC on Windows.&lt;/li&gt;
&lt;li&gt;Batch stride memory overwrites caused recurring segfaults on Apple Silicon (ARM64).&lt;/li&gt;
&lt;li&gt;The repo required recursive submodules, specific Clang versions, Python virtualenvs, or 5-10 GB Docker images.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Engineering Fixes
&lt;/h2&gt;

&lt;p&gt;I patched the native C++ engine bugs and submitted two pull requests upstream:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PR #642&lt;/strong&gt;: Fixes ARM64 2B batch stride memory overwrites, FFN activation alignment (SiLU vs ReLU²), and tokenizer inference bugs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PR #644&lt;/strong&gt;: Adds native MSVC compiler support and CLI build targets on Windows.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Zero-Compile Single Binary: BitRun
&lt;/h2&gt;

&lt;p&gt;To make running these models zero-friction on commodity hardware, I packaged &lt;strong&gt;BitRun&lt;/strong&gt;: a standalone, statically linked runner with native SIMD kernels (NEON DotProd on Mac, AVX2 on Windows/Linux) and zero build dependencies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Verified Benchmarks (100% CPU, 0% GPU)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Apple Silicon M4 Pro (12 Cores, ARM NEON)&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Falcon3 1B Instruct: 137.5 t/s prompt | 98.6 t/s generation (1.9 GB RAM)&lt;/li&gt;
&lt;li&gt;BitNet 70M: 8,758 t/s prompt | 1,355 t/s generation (&amp;lt;150 MB RAM)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Windows 10/11 x86_64 (Intel Core i5-12600K, AVX2)&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Falcon3 1B Instruct: 40–45 t/s generation&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Linux x86_64 (WSL2 / Ubuntu, AVX2)&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Falcon3 1B Instruct: ~130 ms TTFT | 40–45 t/s generation&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Realistic Scope
&lt;/h3&gt;

&lt;p&gt;These 1-bit checkpoints (Falcon3-1B, BitNet-2.4B) are low-power research prototypes for edge and CPU inference, not replacements for cloud frontier APIs. Their primary purpose is testing ternary integer execution on low-wattage devices.&lt;/p&gt;

&lt;h3&gt;
  
  
  Quickstart (One-Line Install)
&lt;/h3&gt;

&lt;h4&gt;
  
  
  macOS &amp;amp; Linux:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/IshekKhal/bitrun/main/install.sh | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Windows (PowerShell):
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;irm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;https://raw.githubusercontent.com/IshekKhal/bitrun/main/install.ps1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;iex&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Run in Terminal:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bitrun pull falcon3-1b
bitrun run falcon3-1b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Serve via OpenAI-Compatible REST API:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bitrun serve falcon3-1b &lt;span class="nt"&gt;--port&lt;/span&gt; 11435
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;ul&gt;
&lt;li&gt;GitHub Repository: &lt;a href="https://github.com/IshekKhal/bitrun" rel="noopener noreferrer"&gt;https://github.com/IshekKhal/bitrun&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Upstream Pull Requests: &lt;a href="https://github.com/microsoft/BitNet/pull/642" rel="noopener noreferrer"&gt;#642&lt;/a&gt; and &lt;a href="https://github.com/microsoft/BitNet/pull/644" rel="noopener noreferrer"&gt;#644&lt;/a&gt; on &lt;code&gt;microsoft/BitNet&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Release Binaries: &lt;a href="https://github.com/IshekKhal/bitrun/releases/tag/v0.1.0-alpha" rel="noopener noreferrer"&gt;v0.1.0-alpha&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>opensource</category>
      <category>ai</category>
      <category>cpp</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Nakshatra: Stargazing in Total Darkness (Because Phone Screens Blind Your Eyes)</title>
      <dc:creator>Abhishek Khanra</dc:creator>
      <pubDate>Sun, 11 Oct 2026 15:23:11 +0000</pubDate>
      <link>https://dev.to/nonebut_ak/nakshatra-stargazing-in-total-darkness-because-phone-screens-blind-your-eyes-3g93</link>
      <guid>https://dev.to/nonebut_ak/nakshatra-stargazing-in-total-darkness-because-phone-screens-blind-your-eyes-3g93</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/hacktoberfest-week1-2026-10-05"&gt;Hacktoberfest Open-Source AI Challenge Week 1: Touch Grass&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;Most software designed to help people disconnect from screens makes a contradictory mistake: it asks you to walk outside, pull out a glass rectangle, and look down at a screen to photograph leaves. It replaces desk-screen time with outdoor-screen time.&lt;/p&gt;

&lt;p&gt;I wanted something different. I wanted to step onto an urban rooftop at midnight, walk away from terminal windows, and look up at the actual sky.&lt;/p&gt;

&lt;p&gt;When you look at a smartphone in the dark, you encounter an immediate biological barrier. The human retina contains roughly 120 million rod photoreceptors that govern nocturnal night vision. These rods rely on a photopigment called rhodopsin. A single 500-millisecond glance at an illuminated smartphone screen bleaches over 80 percent of your retinal rhodopsin. Your pupils constrict from seven millimeters down to two. Rebuilding that dark adaptation requires 20 to 30 continuous minutes in total darkness.&lt;/p&gt;

&lt;p&gt;Every mainstream astronomy app forces you to stare down at a digital simulation of stars rendered in glowing pixels. You stand under real celestial bodies while staring at a backlit slab.&lt;/p&gt;

&lt;p&gt;I built &lt;strong&gt;Nakshatra&lt;/strong&gt; (the Sanskrit word for constellation or star sector).&lt;/p&gt;

&lt;p&gt;Nakshatra is an eyes-up astronomical radar that runs inside the mobile browser. It does not display a virtual sky map. Its display is kept at &lt;strong&gt;0.000 nits&lt;/strong&gt; (solid &lt;code&gt;#000000&lt;/code&gt; on OLED panels) with low-intensity deep-red telemetry ($\lambda &amp;gt; 650\text{ nm}$) that preserves retinal rhodopsin.&lt;/p&gt;

&lt;p&gt;You hold the phone flat against your chest. A dual-oscillator acoustic radar hums in your earbuds, rising in pitch as your torso turns toward an invisible celestial body. When you align with the star, a chime sounds, and a whispered voice directs you to bring the phone to your chin. You tilt your head back, look directly into the night sky, and listen as local Google Gemma whispers the lore of the star into your ears.&lt;/p&gt;

&lt;p&gt;Your eyes never leave the sky.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5xk9tisgtpa08q3jvlpk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5xk9tisgtpa08q3jvlpk.png" alt="Nakshatra running on a phone in a dark room" width="800" height="1517"&gt;&lt;/a&gt;&lt;em&gt;Nakshatra running in pitch darkness. On OLED panels, unused subpixels turn off completely (0.000 nits). Red elements use wavelengths above 650nm to protect rod photoreceptors.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Live Web Application:&lt;/strong&gt; &lt;a href="https://IshekKhal.github.io/nakshatra" rel="noopener noreferrer"&gt;https://IshekKhal.github.io/nakshatra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local PWA Static Host:&lt;/strong&gt; &lt;code&gt;npm start --prefix client&lt;/code&gt; (Runs at &lt;code&gt;http://localhost:3000&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsbgzosficz8b4c19q65o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsbgzosficz8b4c19q65o.png" alt="Nakshatra two-phase posture guide: chest sweep and chin tilt" width="800" height="447"&gt;&lt;/a&gt;&lt;em&gt;The two-phase posture: holding the phone flat at chest height to sweep the horizon, then raising it to the chin to gaze directly upward.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/IshekKhal/nakshatra" rel="noopener noreferrer"&gt;https://github.com/IshekKhal/nakshatra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated Test Suite:&lt;/strong&gt; 81 unit tests passing across seven test suites in 1.3 seconds using the native Node.js test runner (&lt;code&gt;npm test --prefix client&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Software License:&lt;/strong&gt; MIT License. Open source.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How I Built It
&lt;/h2&gt;

&lt;p&gt;Building for an idealized browser simulator is straightforward. Deploying that same software on a physical smartphone standing on a cold concrete roof reveals immediate hardware hurdles. &lt;/p&gt;

&lt;p&gt;Here is how the system is engineered from the ground up.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The Two-Phase Ergonomic Radar
&lt;/h3&gt;

&lt;p&gt;Holding a smartphone upward at arm's length for two minutes causes rapid muscle fatigue and tremors. Nakshatra decouples horizontal azimuth alignment from vertical altitude targeting into two physical postures:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;graph LR
    subgraph Phase_1 ["Phase 1: Chest-Level Sweep"]
        direction TB
        P1_Action["Phone flat in palm at chest (pitch &amp;lt;= 25°)"]
        P1_Sound["Acoustic sonar hums 220Hz-440Hz"]
        P1_Lock["Dwell within 6° for 1000ms locks heading"]
        P1_Voice["Whisper: 'Bring phone to your chin'"]
        P1_Action --&amp;gt; P1_Sound --&amp;gt; P1_Lock --&amp;gt; P1_Voice
    end

    subgraph Phase_2 ["Phase 2: Chin-Level Tilt"]
        direction TB
        P2_Action["Phone raised to chin (pitch &amp;gt; 25°)"]
        P2_Cue["Whisper: 'Tilt your head up slightly'"]
        P2_Lock["Pitch matches altitude within 3°"]
        P2_Voice["Lock chime: 'Stop right there'"]
        P2_Action --&amp;gt; P2_Cue --&amp;gt; P2_Lock --&amp;gt; P2_Voice
    end

    subgraph Phase_3 ["Phase 3: Dark Observation"]
        direction TB
        P3_Screen["Screen solid black (0.000 nits)"]
        P3_Gemma["Local Gemma whispers celestial lore"]
        P3_Screen --&amp;gt; P3_Gemma
    end

    P1_Voice --&amp;gt; P2_Action
    P2_Voice --&amp;gt; P3_Screen&lt;/code&gt;&lt;/pre&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Chest-Level Sweep:&lt;/strong&gt; You hold the phone flat in your palm (pitch under 25 degrees). As you rotate your torso, a Web Audio oscillator hums between 220 Hz and 440 Hz. When your heading aligns with the target within six degrees for one second, a chime rings, and the audio prompts: &lt;em&gt;"Heading locked. Bring phone to your chin."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chin-Level Tilt:&lt;/strong&gt; You bring the phone up to your chin. Because your torso is already facing the correct quadrant, you only need to adjust vertical pitch. You tilt your chin up toward the zenith. The system monitors the pitch axis and whispers natural physical cues: &lt;em&gt;"Tilt your head up slightly"&lt;/em&gt; or &lt;em&gt;"Lower your gaze a bit."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pure Observation:&lt;/strong&gt; When your angle matches within three degrees, a confirmation tone plays. The screen remains black, and local Google Gemma whispers the lore of the star.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  2. Physical Sensor Hardening: The Gravity Decomposition Filter
&lt;/h3&gt;

&lt;p&gt;On mobile Chromium on mid-tier Android devices, calling &lt;code&gt;event.acceleration&lt;/code&gt; returns &lt;code&gt;{x: 0, y: 0, z: 0}&lt;/code&gt; without throwing an error. The API appears active, but reports zero motion. Any code relying on linear acceleration to track physical movement fails silently.&lt;/p&gt;

&lt;p&gt;To detect when a user is walking versus standing still, I read &lt;code&gt;event.accelerationIncludingGravity&lt;/code&gt;, calculate the raw Euclidean magnitude, and strip Earth's gravitational acceleration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;handleMotion&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;dynamicMag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;hasLinearAcc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;acceleration&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;acceleration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;acceleration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;acceleration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;acceleration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;az&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;acceleration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ax&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;ax&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;ay&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;ay&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;az&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;az&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mag&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;dynamicMag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mag&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;hasLinearAcc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;hasLinearAcc&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;accelerationIncludingGravity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;accelerationIncludingGravity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;accelerationIncludingGravity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;az&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;accelerationIncludingGravity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rawMag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ax&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;ax&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;ay&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;ay&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;az&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;az&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;dynamicMag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rawMag&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;9.81&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dynamicMag&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.50&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_lastStepTime&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_lastStepTime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stepsDetected&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;displacementMeters&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mf"&gt;0.65&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This filter detects real footsteps and resets tracking if the user walks away from their observation point.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Horizon Partitioning and the 18° Urban Skyline Floor
&lt;/h3&gt;

&lt;p&gt;Smartphone magnetometers experience continuous jitter between eight and twelve degrees caused by rooftop rebar and sensor noise. If you instruct an application to guide a user toward an exact single-degree coordinate, the audio radar chatters constantly.&lt;/p&gt;

&lt;p&gt;Furthermore, celestial targets between zero and fifteen degrees altitude are almost always obstructed by apartment buildings, power lines, or streetlights.&lt;/p&gt;

&lt;p&gt;I resolved both issues in &lt;code&gt;quadrant_selector.js&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The sky is divided into four cardinal 90-degree quadrants: northeast (0° to 90°), southeast (90° to 180°), southwest (180° to 270°), northwest (270° to 360°).&lt;/li&gt;
&lt;li&gt;All celestial bodies below an 18.0-degree altitude cutoff are pruned from active consideration.&lt;/li&gt;
&lt;li&gt;Observed stars receive a 30-minute cooldown timestamp to prevent the app from locking onto the same bright object repeatedly.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;selectTargetForHeading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentHeadingAz&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;allVisibleTargets&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;allVisibleTargets&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;allVisibleTargets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentQuad&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getQuadrant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentHeadingAz&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;latchedTarget&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;activeQuadrant&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;currentQuad&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isTargetCooledDown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;latchedTarget&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;latchedTarget&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inQuadrant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;allVisibleTargets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;azimuth&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;altitude&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;altitude&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;minAltitudeDeg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getQuadrant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;azimuth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;currentQuad&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inQuadrant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;uncooled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;inQuadrant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isTargetCooledDown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;candidatePool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;uncooled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;uncooled&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;inQuadrant&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chosen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_pickWeightedCandidate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;candidatePool&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;latchedTarget&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;chosen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;activeQuadrant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentQuad&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;chosen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Human Biomechanics: The 45° Wrist Transit Arc
&lt;/h3&gt;

&lt;p&gt;My initial prototype used a strict 15-degree heading margin between the chest sweep and the chin tilt phase. &lt;/p&gt;

&lt;p&gt;In outdoor testing, this caused nine out of ten attempts to abort. When a human raises their hands from chest level to their chin, the elbow hinge naturally rotates the wrist. This mechanical arc swings the internal phone compass by 25 to 35 degrees during transit.&lt;/p&gt;

&lt;p&gt;I relaxed the heading abort tolerance to 45 degrees during the lift motion and implemented a 1.2-second post-lift gyroscopic stabilization dampener. The software now conforms to human anatomy instead of treating the user like an industrial robotic arm.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. On-Device Google Gemma: Web Workers and Offline Lore
&lt;/h3&gt;

&lt;p&gt;A core requirement of Nakshatra was to eliminate robotic coordinate readouts. Hearing a synthesized voice say &lt;em&gt;"Azimuth 214 degrees, pitch 42 degrees, Right Ascension 18 hours"&lt;/em&gt; pulls the user out of contemplation and back into analytical tension.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;graph TD
    subgraph Tier_1 ["1. Mobile Sensor Hardening (50Hz)"]
        S_Orient["DeviceOrientation (Compass &amp;amp; Pitch)"] --&amp;gt; S_Filter["Low-Pass Filter (alpha = 0.15)"]
        S_Motion["DeviceMotion (Raw Accelerometer)"] --&amp;gt; S_Gravity["Gravity Decomposition Filter"]
        S_Filter --&amp;gt; S_Fusion["Calibrated Pose &amp;amp; Motion Vectors"]
        S_Gravity --&amp;gt; S_Fusion
    end

    subgraph Tier_2 ["2. Astronomical Ephemeris Engine"]
        E_Catalog["80+ Celestial Body Catalog"] --&amp;gt; E_Math["Sidereal &amp;amp; Topocentric Math"]
        S_Fusion --&amp;gt; E_Math
        E_Math --&amp;gt; E_Quad["4-Quadrant Selector (18° Skyline Floor)"]
        E_Quad --&amp;gt; E_Latch["Target Latching &amp;amp; 30-Minute Cooldown"]
    end

    subgraph Tier_3 ["3. Intelligence &amp;amp; Audio Synthesis"]
        E_Latch --&amp;gt; A_Radar["Web Audio Radar (220Hz-440Hz)"]
        E_Latch --&amp;gt; W_Gemma["On-Device Gemma 3 (WebGPU Worker)"]
        W_Gemma --&amp;gt;|Memory limits| W_Lore["Deterministic Lore Database"]
        W_Gemma --&amp;gt; A_Speech["Sub-15ms Whispered Speech Synthesizer"]
        W_Lore --&amp;gt; A_Speech
        A_Radar --&amp;gt; A_Speech
    end&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Nakshatra uses a dual-engine architecture to generate body-relative celestial phrasing:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Chrome Built-in Prompt API &amp;amp; WebGPU Web Worker:&lt;/strong&gt; On supported devices, prompts are dispatched to on-device Google Gemma models (&lt;code&gt;gemma-3-270m-it-ONNX&lt;/code&gt; via Web Worker or Chrome's native Prompt API). All weight loading, token caching, and generation run off the main JavaScript thread, ensuring the audio oscillators never stutter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Progressive Fallback Lore Engine:&lt;/strong&gt; If a device has limited memory or lacks WebGPU support, Nakshatra does not crash with an unhandled exception. It falls back to an internal celestial lore database containing observations across 80 navigational stars and deep-sky treasures.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All model outputs pass through a deterministic validation filter that checks for forbidden technical terms:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;FORBIDDEN_JARGON_REGEX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\b(&lt;/span&gt;&lt;span class="sr"&gt;azimuth|altitude|right&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;+ascension|declination|degree&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;s&lt;/span&gt;&lt;span class="se"&gt;]?&lt;/span&gt;&lt;span class="sr"&gt;|arcminute&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;s&lt;/span&gt;&lt;span class="se"&gt;]?&lt;/span&gt;&lt;span class="sr"&gt;|arcsecond&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;s&lt;/span&gt;&lt;span class="se"&gt;]?&lt;/span&gt;&lt;span class="sr"&gt;|bearing|southeast|northeast|southwest|northwest|fist&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;s&lt;/span&gt;&lt;span class="se"&gt;]?&lt;/span&gt;&lt;span class="sr"&gt;|clenched&lt;/span&gt;&lt;span class="se"&gt;)\b&lt;/span&gt;&lt;span class="sr"&gt;/i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Empirical Field Hardening: What Physical Testing Caught
&lt;/h3&gt;

&lt;p&gt;Unit tests in an IDE pass easily. Real hardware outdoors fails in unexpected ways.&lt;/p&gt;

&lt;p&gt;Testing under real skies caught three critical edge-case bugs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Azimuth Boundary Wrapping:&lt;/strong&gt; A direct subtraction across true North ($359^\circ \to 1^\circ$) produced a $-358^\circ$ error instead of a $+2^\circ$ delta. This bug sent the acoustic radar oscillator into an immediate high-frequency spike. I fixed this in &lt;code&gt;sensors.js&lt;/code&gt; using shortest-angle modulo wrapping:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;shortestAngleDiff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;360&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;diff&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;diff&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;360&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Target Dwell Hysteresis:&lt;/strong&gt; Night breezes and natural body sway cause continuous minor heading fluctuations. Once a target latches, the ephemeris engine maintains that lock across 13.5 degrees of drift before releasing it, preventing target chatter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rooftop Safety Displacement:&lt;/strong&gt; If the accelerometer registers more than 3.5 meters of physical walking motion, the observation session resets immediately. Users must never walk across a dark rooftop while blind to their surroundings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The 81 automated tests in &lt;code&gt;npm test&lt;/code&gt; execute in 1.3 seconds via Node's native test runner, ensuring these mathematical edge cases remain guarded against regression.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Does &lt;code&gt;Open Innovation&lt;/code&gt; Matter?
&lt;/h2&gt;

&lt;p&gt;Open-source and open-weight AI models are vital for tools designed for the physical outdoors.&lt;/p&gt;

&lt;p&gt;When you stand in a dark-sky preserve, on a mountain ridgeline, or on a remote trail, cellular towers do not reach you. A proprietary cloud application that depends on remote inference servers fails the moment connectivity drops. &lt;/p&gt;

&lt;p&gt;Google Gemma models running locally on client hardware fundamentally change outdoor software:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Complete Offline Autonomy:&lt;/strong&gt; Nakshatra requires no cellular data, Wi-Fi, or remote backends. It functions equally well in a city park or in the high Himalayas.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Uncompromising Sensory Privacy:&lt;/strong&gt; No camera streams, coordinates, or audio data ever leave the device.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Aligning Software with Human Biology:&lt;/strong&gt; Commercial web applications rely on screen time to display advertisements. Open-weight models allow developers to build software that deliberately turns its own screen off and returns the user's attention to the night sky.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Prize Categories
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Best Use of Google DeepMind Gemma:&lt;/strong&gt; On-device Web Worker running Gemma 3 (with Chrome Built-in Prompt API support) to generate body-relative celestial lore offline, backed by a deterministic fallback database.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devchallenge</category>
      <category>hf26challenge</category>
      <category>gemma</category>
      <category>opensource</category>
    </item>
    <item>
      <title>PotatoClaw: my friend's 8GB laptop kept freezing during lab submissions, so I built him a zero-dollar copilot</title>
      <dc:creator>Abhishek Khanra</dc:creator>
      <pubDate>Mon, 05 Oct 2026 06:27:04 +0000</pubDate>
      <link>https://dev.to/nonebut_ak/potatoclaw-my-friends-8gb-laptop-kept-freezing-during-lab-submissions-so-i-built-him-a-255i</link>
      <guid>https://dev.to/nonebut_ak/potatoclaw-my-friends-8gb-laptop-kept-freezing-during-lab-submissions-so-i-built-him-a-255i</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/hacktoberfest-weekend-2026-10-01"&gt;Hacktoberfest Weekend Challenge: Build for a Friend&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;


&lt;div class="crayons-card c-embed"&gt;

  &lt;br&gt;
&lt;strong&gt;Project Summary&lt;/strong&gt;: PotatoClaw is a featherweight Windows desktop overlay built in Rust (Tauri v2) paired with an asynchronous cloud backend on Render. It shields 8 GB laptops from system freezes using native Win32 &lt;code&gt;K32EmptyWorkingSet&lt;/code&gt; memory trims, while offloading multimodal reasoning and data validation to Google DeepMind's Gemma 4, Prior Labs' TabPFN, Backboard.io, ElevenLabs, Groq, and Sentry for $0.00 a month.&lt;br&gt;

&lt;/div&gt;


&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;I built PotatoClaw for Rudra, my hostel wingmate and fellow first-year computer science student.&lt;/p&gt;

&lt;p&gt;Wednesday night, 11 PM. Our first graded C programming lab was due at dawn.&lt;/p&gt;

&lt;p&gt;Rudra works on an entry-level HP 15s notebook powered by an AMD Ryzen 3 3250U with a single 8 GB RAM stick. The unadvertised trap with budget Ryzen APUs is the integrated Radeon Vega GPU. The hardware firmware allocates 2.1 GB of physical memory to video RAM the moment the machine powers on. Windows only gets 5.88 GB to divide between Chrome, the desktop window manager, background telemetry, and an IDE.&lt;/p&gt;

&lt;p&gt;Rudra had spent two hours chasing an off-by-one pointer bug in a doubly linked list. His desktop was crowded: VS Code, an active compiler terminal, a 40-page lab PDF manual, GeeksforGeeks, and four StackOverflow tabs.&lt;/p&gt;

&lt;p&gt;Then his cursor hitched. Rudra pressed &lt;code&gt;Alt+Tab&lt;/code&gt;. His screen went pitch black. Seven seconds passed in silence. When the display finally blinked back to life, VS Code had terminated unexpectedly. Forty lines of unsaved C pointer logic were gone. Task Manager was a solid block of red: RAM pinned at 93%, disk usage stuck at 100%. Windows was furiously thrashing the pagefile against a budget SSD, freezing the entire operating system every time he touched a key.&lt;/p&gt;

&lt;p&gt;He dropped his forehead directly onto his keyboard:&lt;br&gt;&lt;br&gt;
&lt;em&gt;"Bhai, main is dabba ko balcony se phek dunga."&lt;/em&gt; ("Bro, I am throwing this toaster off the balcony.")&lt;/p&gt;

&lt;p&gt;Standard developer advice is completely useless in an engineering college hostel:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;"Just install Linux"&lt;/strong&gt;: He tried dual-booting Ubuntu during high school, accidentally formatted his EFI system partition, and his father had to carry the laptop to a repair shop in town to recover Windows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"Buy a refurbished Mac"&lt;/strong&gt;: Our semester tuition is 45,000 rupees. A base M2 MacBook costs more than a full year of college.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"Run Ollama locally"&lt;/strong&gt;: Loading an 8B model requires 5.5 GB of RAM. Loading that into 5.88 GB of usable memory crashes the Windows Desktop Window Manager instantly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"Keep ChatGPT open in Chrome"&lt;/strong&gt;: Spawning heavy Electron and web tabs was the exact thing that triggered pagefile thrashing in the first place.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We spent that weekend building PotatoClaw in Rust to solve his problem without spending a single rupee.&lt;/p&gt;

&lt;p&gt;The desktop layer is an 18 MB standalone binary built in Tauri v2. It floats a tiny 72-pixel circular pill above active windows, consuming under 35 MB of resident memory. Double-clicking the pill calls native Win32 memory management APIs. It sweeps background processes, protects the active editor, and forces the Windows NT kernel to move dormant working set pages into the standby list. That single sweep drops physical RAM usage by 1.7 to 3.5 GB in 0.24 seconds. No applications close. No tabs reload. No unsaved code is lost.&lt;/p&gt;

&lt;p&gt;To solve the rest of his coursework headaches without bogging down his CPU, the desktop pill connects to an asynchronous FastAPI cloud engine running on Render's free tier. When Rudra hits a cryptic compiler crash or needs to verify sensor readings from our physics lab, he presses &lt;code&gt;Alt+Shift+2&lt;/code&gt; to crop his screen, or drops the file directly onto the pill:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Google DeepMind's Gemma 4&lt;/strong&gt; parses the compiler error and inspects C syntax via an automated two-pass verification prompt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prior Labs' TabPFN 3.5&lt;/strong&gt; runs zero-shot tabular anomaly regression on lab sensor CSVs in 178 milliseconds, catching corrupt rows without needing local Python data science libraries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backboard.io&lt;/strong&gt; preserves his debugging context across app reboots.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ElevenLabs Turbo v2.5&lt;/strong&gt; plays a quick 20-second spoken debrief through his headphones so he can rest his eyes at 1 AM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Groq Whisper&lt;/strong&gt; transcribes spoken debug queries in 80 milliseconds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sentry&lt;/strong&gt; captures telemetry on every memory trim and cloud inference call.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Total monthly running cost: zero rupees.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1hpsefeqhnbizwd8o4zt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1hpsefeqhnbizwd8o4zt.png" alt="PotatoClaw floating pill and Assistant HUD running alongside VS Code and Task Manager" width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;
Figure 1: PotatoClaw running on the desktop with under 35 MB of resident RAM alongside VS Code and Task Manager.




&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Hosted Cloud Backend&lt;/strong&gt;: &lt;a href="https://potatoclaw-backend.onrender.com/health" rel="noopener noreferrer"&gt;https://potatoclaw-backend.onrender.com/health&lt;/a&gt; (Public health probe running on Render's free tier).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pre-compiled Windows Executable&lt;/strong&gt;: &lt;a href="https://github.com/IshekKhal/potatoclaw/releases" rel="noopener noreferrer"&gt;Download potatoclaw.exe from GitHub Releases&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzdc8cd26e9rsd1zrmdqp.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzdc8cd26e9rsd1zrmdqp.gif" alt="Windows Task Manager memory graph showing immediate downward drop after double-clicking the PotatoClaw pill" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;
Figure 2: Native Win32 working set trim flushing background pages into standby memory in 0.24 seconds.



&lt;p&gt;What happens during a typical late-night coding session:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Windows Task Manager climbs toward 92% RAM under Chrome and an active build.&lt;/li&gt;
&lt;li&gt;Rudra double-clicks the floating pill; physical memory drops by 2.4 GB in 240 milliseconds as background working sets are trimmed.&lt;/li&gt;
&lt;li&gt;He presses &lt;code&gt;Alt+Shift+2&lt;/code&gt;, drags crosshairs over an unhandled segmentation fault, and Gemma 4 pinpoints the uninitialized struct pointer in 780 milliseconds.&lt;/li&gt;
&lt;li&gt;ElevenLabs streams a spoken summary through his earphones so he can absorb the fix without squinting at terminal lines.&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/IshekKhal" rel="noopener noreferrer"&gt;
        IshekKhal
      &lt;/a&gt; / &lt;a href="https://github.com/IshekKhal/potatoclaw" rel="noopener noreferrer"&gt;
        potatoclaw
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A featherweight desktop companion and Win32 RAM shield for 8GB Windows laptops. Reclaims 1.5 to 3.5 GB of stale memory in 0.24s during heavy multitasking and offloads AI reasoning, document Q&amp;amp;A, and voice debriefs to the cloud for $0/month.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;PotatoClaw&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;Featherweight desktop AI companion and Win32 anti-thrash memory shield for 8 GB RAM laptops.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/IshekKhal/potatoclaw/LICENSE" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667" alt="License: MIT"&gt;&lt;/a&gt;
&lt;a href="https://github.com/IshekKhal/potatoclaw/releases" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/1da47153e1bb2b50672c42a06af3a7ee2eb5604bf22fb1121270519f2e7fd555/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f52656c656173652d57696e646f77732532307836342d626c75652e737667" alt="Release"&gt;&lt;/a&gt;
&lt;a href="https://potatoclaw-backend.onrender.com/health" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/19b9762c75ab5ca909e09c03efbab2a70b2358d1e16f3b2b02ab8cc4a34de25b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f52656e6465722d4c6976652d627269676874677265656e2e737667" alt="Backend Status"&gt;&lt;/a&gt;
&lt;a href="https://github.com/IshekKhal/potatoclaw/backend/tests" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/d03d50f29429a4444acbf6dd04fa8a094823e7650e78149a4191ab6cfea6d69d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54657374732d3237253246323725323050617373696e672d737563636573732e737667" alt="Tests"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;What It Is&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;PotatoClaw is a native Windows desktop overlay built in Rust (Tauri v2) that protects memory-constrained PCs from lockups and freezes. When multitasking across browser tabs, IDEs, lab manuals, and PDFs, physical memory usage spikes past 90%. Windows drops into hard pagefile thrashing, freezing the desktop.&lt;/p&gt;
&lt;p&gt;PotatoClaw addresses this with two components:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;A local Win32 memory shield&lt;/strong&gt;: A floating desktop pill widget. Clicking it invokes native &lt;code&gt;K32EmptyWorkingSet&lt;/code&gt; with active foreground process protection and a 60+ process whitelist, releasing 1.7 GB to 3.5 GB of physical memory in 0.24 seconds without closing open applications or dropping unsaved work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An asynchronous cloud brain&lt;/strong&gt;: Heavy multimodal reasoning, screen snip OCR, tabular anomaly scanning, cross-session memory, and voice synthesis offload to a containerized FastAPI backend on Render. The local machine stays cool and draws under…&lt;/li&gt;
&lt;/ol&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/IshekKhal/potatoclaw" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;The repository is structured as a dual-stack monorepo:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/IshekKhal/potatoclaw/tree/main/src-tauri" rel="noopener noreferrer"&gt;&lt;code&gt;src-tauri/&lt;/code&gt;&lt;/a&gt;: Native Rust desktop client, Win32 memory shield, GDI screen snipper, and in-HUD settings manager.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/IshekKhal/potatoclaw/tree/main/backend" rel="noopener noreferrer"&gt;&lt;code&gt;backend/&lt;/code&gt;&lt;/a&gt;: Containerized FastAPI service configured for Render deployment via &lt;code&gt;render.yaml&lt;/code&gt;, integrating Gemma 4, TabPFN 3.5, Backboard.io, ElevenLabs, Groq, and Sentry.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How I Built It
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. The Win32 Working Set Mechanism (Native Rust)
&lt;/h3&gt;

&lt;p&gt;When Windows reports 90% memory pressure on an 8 GB laptop, most of that RAM is not actively computing anything. Browsers, background updaters, and communication apps allocate heap pages, touch them during startup, and leave them mapped into physical memory. In the Windows NT kernel, this active physical mapping is called a process &lt;strong&gt;working set&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Windows exposes an internal API in &lt;code&gt;kernel32.dll&lt;/code&gt; / &lt;code&gt;psapi.dll&lt;/code&gt;: &lt;code&gt;K32EmptyWorkingSet&lt;/code&gt;. Calling this function orders the Windows memory manager to strip unreferenced pages from a process working set and push them to the standby list. If the process later demands that memory back, the kernel retrieves it via a soft page fault without reading from the disk.&lt;/p&gt;

&lt;p&gt;We wrote the memory shield in native Rust using the official &lt;code&gt;windows&lt;/code&gt; crate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src-tauri/src/memory_shield.rs&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;trim_process_working_set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;unsafe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;handle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;OpenProcess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;PROCESS_QUERY_INFORMATION&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;PROCESS_SET_QUOTA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;pid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.map_err&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PROCESS_MEMORY_COUNTERS&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;default&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nf"&gt;K32GetProcessMemoryInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;mem&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;size_of_val&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Signal Windows NT kernel to move idle pages to standby list&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;K32EmptyWorkingSet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PROCESS_MEMORY_COUNTERS&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;default&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nf"&gt;K32GetProcessMemoryInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;after&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;mem&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;size_of_val&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;after&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nf"&gt;CloseHandle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="nf"&gt;.as_bool&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="py"&gt;.WorkingSetSize&lt;/span&gt;&lt;span class="nf"&gt;.saturating_sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;after&lt;/span&gt;&lt;span class="py"&gt;.WorkingSetSize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"EmptyWorkingSet call rejected by kernel"&lt;/span&gt;&lt;span class="nf"&gt;.to_string&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first night we tested this, I simply looped across every active PID on the machine. It freed 4 GB instantly, but VS Code hitching for 50 milliseconds every time Rudra touched a key made it unusable. Windows was evicting the editor's font cache and syntax tokens along with everything else. &lt;/p&gt;

&lt;p&gt;To fix that stutter, the trim function checks the active desktop state before touching any memory handles. It queries &lt;code&gt;GetForegroundWindow&lt;/code&gt; and &lt;code&gt;GetWindowThreadProcessId&lt;/code&gt; to identify whatever program currently holds the user's focus, strictly exempting that PID from the trim. A second whitelist filter checks process basenames against &lt;code&gt;PROTECTED_PROCESS_NAMES&lt;/code&gt;, completely bypassing PID 0, PID 4, and over 60 essential OS services like &lt;code&gt;dwmapi.exe&lt;/code&gt;, &lt;code&gt;explorer.exe&lt;/code&gt;, audio hosts, and graphics display drivers.&lt;/p&gt;

&lt;p&gt;During automated benchmark sweeps, a single trim reclaims &lt;strong&gt;1,719 MB (1.72 GB)&lt;/strong&gt; on an idle desktop. Under active compilation workloads with browser tabs open, it routinely recovers between &lt;strong&gt;2.8 GB and 3.5 GB&lt;/strong&gt; in &lt;strong&gt;0.24 seconds&lt;/strong&gt;. On startup, PotatoClaw also trims its own working set, locking its resident memory footprint below &lt;strong&gt;35 MB&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. The Native Desktop Shell: Why Electron Was Excluded
&lt;/h3&gt;

&lt;p&gt;Building an Electron app to rescue an 8 GB laptop from memory starvation is counterproductive. A standard Electron hello-world window pulls between 150 MB and 250 MB of RAM before executing a single line of application code.&lt;/p&gt;

&lt;p&gt;PotatoClaw uses Tauri v2 in Rust. The UI binds directly to the Microsoft Edge WebView2 runtime already built into Windows 10 and 11. The entire frontend runs on vanilla HTML5, CSS3, and modern JavaScript with zero Node.js runtime overhead.&lt;/p&gt;

&lt;p&gt;The desktop client splits responsibilities across three focused native surfaces. The DropBox Pill (&lt;code&gt;ui/dropbox.html&lt;/code&gt;) stays permanently on top as a transparent 72x72 circular widget. Clicking it toggles the assistant, double-clicking fires the memory sweep, and dragging any file onto it stages the path directly into context. Pressing &lt;code&gt;Alt+Shift+P&lt;/code&gt; slides open the Assistant HUD (&lt;code&gt;ui/hud.html&lt;/code&gt;), a 540x680 card that streams answers, formats copyable code blocks, renders TabPFN anomaly breakdowns, and hosts an in-HUD settings modal for backend URL and access PIN management. When text alone cannot describe a bug, &lt;code&gt;Alt+Shift+2&lt;/code&gt; summons the GDI Snipper (&lt;code&gt;ui/snipper.html&lt;/code&gt;), which overlays a borderless crosshair canvas and grabs screen pixels through direct Win32 &lt;code&gt;BitBlt&lt;/code&gt; and &lt;code&gt;CreateCompatibleBitmap&lt;/code&gt; calls to write a clean PNG directly to disk without browser canvas lag.&lt;/p&gt;

&lt;p&gt;We also built a multi-source drag-and-drop extractor (&lt;code&gt;extractDropPayload&lt;/code&gt;) in JavaScript. It parses raw Explorer file paths, VS Code editor tab drags (&lt;code&gt;text/uri-list&lt;/code&gt; with &lt;code&gt;file:///&lt;/code&gt; URIs), web URLs, and recursive directory folders up to 50 files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqi7rvv7j9g6rjoopndyd.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqi7rvv7j9g6rjoopndyd.gif" alt="PotatoClaw Assistant HUD showing staged C code file badge ready for multi-document reasoning" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;
Figure 3: Staging code files, PDFs, or CSV lab datasets directly into the assistant context via drag-and-drop.






&lt;h3&gt;
  
  
  3. Google DeepMind Gemma 4 (Universal Reasoning &amp;amp; Vision)
&lt;/h3&gt;

&lt;p&gt;All memory-intensive AI operations are delegated to our FastAPI container on Render. This architecture completely shields the student's local CPU and RAM from inference spikes while providing frontier-grade reasoning.&lt;/p&gt;

&lt;p&gt;We run &lt;code&gt;gemma-4-26b-a4b-it&lt;/code&gt; through Google AI Studio's API. Early tests showed that single-pass prompts occasionally hallucinated non-existent POSIX headers or invented pointer syntax when debugging low-level C. To stop bad code from reaching the student, the backend executes a two-pass pipeline. The first pass diagnoses the compiler trace and drafts a proposed code fix. Before that answer leaves the server, a second audit pass feeds the draft back into Gemma 4 alongside the original compiler log, verifying declared variables, checking pointer dereferences, and stripping unsupported claims. Both passes finish in 680 to 920 milliseconds over standard broadband.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe8xydpjwga8027aaao2j.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe8xydpjwga8027aaao2j.gif" alt="Assistant HUD displaying Gemma 4 two-pass C pointer diagnosis and ElevenLabs audio playback player" width="599" height="419"&gt;&lt;/a&gt;&lt;/p&gt;
Figure 4: Gemma 4 isolates the null pointer dereference with commented C code and a streaming voice debrief.






&lt;h3&gt;
  
  
  4. Prior Labs TabPFN (Zero-Shot Tabular Anomaly Engine)
&lt;/h3&gt;

&lt;p&gt;Our physics and electronics labs demand endless manual data logging: Hall Effect voltages, diode curves, and RC circuit charging intervals. Plotting and validating those numbers locally is painful on a budget machine. Installing Python, pandas, and scikit-learn eats over 3 GB of disk space, and just importing them pushes RAM consumption past 1 GB before you even touch a CSV row.&lt;/p&gt;

&lt;p&gt;PotatoClaw solves this by routing tabular files (&lt;code&gt;.csv&lt;/code&gt; and &lt;code&gt;.tsv&lt;/code&gt;) directly to Prior Labs' TabPFN 3.5 engine (&lt;code&gt;backend/app/services/tabpfn_engine.py&lt;/code&gt;) hosted on our cloud backend. TabPFN is an in-context foundation model trained on synthetic tabular datasets. It executes non-linear regression across numerical columns in &lt;strong&gt;178 milliseconds&lt;/strong&gt; without requiring any local model training, iterative gradient descent, or hyperparameter tuning.&lt;/p&gt;

&lt;p&gt;Here is how our tabular anomaly detection works in code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# backend/app/services/tabpfn_engine.py
# 1. Regress dependent feature against independent columns
&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;clean_df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;feature_names&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;clean_df&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;target_name&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;

&lt;span class="n"&gt;regressor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TabPFNRegressor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;regressor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;preds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;regressor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# 2. Compute non-linear residuals and normalized z-scores
&lt;/span&gt;&lt;span class="n"&gt;residuals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;preds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;res_mean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;residuals&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;res_std&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;std&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;residuals&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;res_std&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;1e-8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;res_z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;residuals&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;res_mean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;res_std&lt;/span&gt;
    &lt;span class="c1"&gt;# Flag rows where prediction error exceeds 2.5 standard deviations
&lt;/span&gt;    &lt;span class="n"&gt;flagged_idx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;clean_df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;res_z&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;tolist&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When Rudra dropped &lt;code&gt;hall_sensor_run2.csv&lt;/code&gt; (15 rows of calibration readings with an injected 24.85V spike caused by a slipped oscilloscope probe) onto the PotatoClaw pill:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;TabPFN computed column baselines and fitted the voltage-to-time curve in 178 ms.&lt;/li&gt;
&lt;li&gt;The residual error at index 10 hit a z-score of &lt;strong&gt;3.42 sigma&lt;/strong&gt;, immediately isolating the bad sensor row while confirming the remaining 14 rows were within normal experimental tolerance.&lt;/li&gt;
&lt;li&gt;Gemma 4 executed a two-pass audit on TabPFN's metrics, returning a clean summary in the HUD detailing the exact timestamp, the outlier reading, and the calculated baseline mean (3.30V).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Rudra verified his lab dataset in under a second without installing a single Python package on his laptop.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. Persistent Memory with Backboard.io
&lt;/h3&gt;

&lt;p&gt;PotatoClaw integrates Backboard.io to maintain assistant context across desktop reboots. When Rudra asks a follow-up question on Tuesday about a linked list bug he worked through on Sunday, Backboard retrieves the relevant historical debug session without storing heavy vector embeddings on his local drive. &lt;/p&gt;

&lt;p&gt;To prevent timeout spikes on unreliable hostel Wi-Fi, semantic recall lookups are strictly capped at 500 characters, while session memory updates (capped at 3,500 characters) execute as non-blocking background tasks, keeping the primary HTTP response immediate.&lt;/p&gt;




&lt;h3&gt;
  
  
  6. ElevenLabs Voice &amp;amp; Groq Whisper
&lt;/h3&gt;

&lt;p&gt;Debugging late at night causes severe screen fatigue. Clicking the audio button in the HUD or pressing &lt;code&gt;Alt+Shift+V&lt;/code&gt; streams a natural voice debrief generated by ElevenLabs Turbo v2.5 (George voice) in &lt;strong&gt;295 milliseconds&lt;/strong&gt;. Rudra can lean back, close his eyes, and listen to Gemma 4 explain the pointer bug without staring at dense terminal text.&lt;/p&gt;

&lt;p&gt;For hands-free queries, audio captured from the laptop microphone is compressed into a compact mono WAV buffer and sent to Groq Whisper Large V3 Turbo, transcribing spoken queries in approximately &lt;strong&gt;80 milliseconds&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  7. Render Cloud Backend &amp;amp; Access Code Gatekeeper
&lt;/h3&gt;

&lt;p&gt;The cloud service runs inside a multi-stage Docker container deployed on Render via &lt;code&gt;render.yaml&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;To prevent unauthorized consumption of our API keys while keeping the cloud backend accessible for Rudra, we implemented an &lt;code&gt;X-Access-Code&lt;/code&gt; security gatekeeper in FastAPI. The client stores a 6-digit numeric PIN in the in-HUD Settings panel and attaches it to every request header. Public probes to &lt;code&gt;/health&lt;/code&gt; remain open for zero-downtime healthcheck monitoring.&lt;/p&gt;




&lt;h3&gt;
  
  
  8. Sentry Telemetry &amp;amp; Automated Verification
&lt;/h3&gt;

&lt;p&gt;Every network call, memory trim duration, and model inference span is instrumented via Sentry. Sentry breadcrumbs track the exact number of megabytes reclaimed during each Win32 sweep, giving us live telemetry on application health.&lt;/p&gt;

&lt;p&gt;Our automated pytest test suite verifies all cloud integrations, document parsers, security headers, and TabPFN anomaly routines. All 27 tests pass cleanly across both mock fixtures and live API calls:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;============================= 27 passed in 166.65s =============================
tests/test_access_code.py ................ [PASSED]
tests/test_backboard_memory.py ........... [PASSED]
tests/test_document_ingestion.py ......... [PASSED]
tests/test_elevenlabs_voice.py ........... [PASSED]
tests/test_gemma_brain.py ................ [PASSED]
tests/test_groq_stt.py ................... [PASSED]
tests/test_network_integration.py ........ [PASSED]
tests/test_sentry_telemetry.py ........... [PASSED]
tests/test_tabpfn_engine.py .............. [PASSED]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Why Does Open Innovation Matter?
&lt;/h2&gt;

&lt;p&gt;When building tools for students, price is not an afterthought. If an AI coding assistant requires a $20 monthly subscription, an Indian college student with a ₹1,000 monthly food allowance cannot use it.&lt;/p&gt;

&lt;p&gt;At the same time, entry-level 8 GB laptops cannot run frontier models locally without triggering disastrous pagefile thrashing. Open-weight models like Gemma 4, coupled with free developer cloud tiers, level the playing field. A student working on a second-hand Ryzen 3 laptop gets access to the exact same reasoning capabilities as an engineer on an expensive M3 Max workstation.&lt;/p&gt;

&lt;p&gt;Every service powering PotatoClaw operates within permanent free developer tiers:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Platform / Technology&lt;/th&gt;
&lt;th&gt;Tier&lt;/th&gt;
&lt;th&gt;Monthly Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Desktop Client&lt;/td&gt;
&lt;td&gt;Native Rust / Tauri v2&lt;/td&gt;
&lt;td&gt;Open Source (MIT)&lt;/td&gt;
&lt;td&gt;₹0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reasoning &amp;amp; Vision&lt;/td&gt;
&lt;td&gt;Google DeepMind Gemma 4&lt;/td&gt;
&lt;td&gt;Google AI Studio Free Tier&lt;/td&gt;
&lt;td&gt;₹0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tabular Anomaly Engine&lt;/td&gt;
&lt;td&gt;Prior Labs TabPFN 3.5&lt;/td&gt;
&lt;td&gt;Developer Free Tier&lt;/td&gt;
&lt;td&gt;₹0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Persistent Memory&lt;/td&gt;
&lt;td&gt;Backboard.io&lt;/td&gt;
&lt;td&gt;Developer Free Tier&lt;/td&gt;
&lt;td&gt;₹0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Voice Transcription&lt;/td&gt;
&lt;td&gt;Groq Whisper Large V3 Turbo&lt;/td&gt;
&lt;td&gt;Free Developer Tier&lt;/td&gt;
&lt;td&gt;₹0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Spoken Audio Synthesis&lt;/td&gt;
&lt;td&gt;ElevenLabs&lt;/td&gt;
&lt;td&gt;Free Tier (10,000 chars/mo)&lt;/td&gt;
&lt;td&gt;₹0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cloud Service Hosting&lt;/td&gt;
&lt;td&gt;Render&lt;/td&gt;
&lt;td&gt;Free Tier Web Service&lt;/td&gt;
&lt;td&gt;₹0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Telemetry &amp;amp; Monitoring&lt;/td&gt;
&lt;td&gt;Sentry&lt;/td&gt;
&lt;td&gt;Developer Free Tier&lt;/td&gt;
&lt;td&gt;₹0.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Total Monthly Cost&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;₹0.00 / $0.00&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;No credit cards required. No trial expiration dates.&lt;/p&gt;




&lt;h2&gt;
  
  
  My Agent Session
&lt;/h2&gt;

&lt;p&gt;PotatoClaw was built over one weekend using agentic pair programming:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The native Win32 &lt;code&gt;K32EmptyWorkingSet&lt;/code&gt; memory shield logic and process exclusion filters were designed and validated in Rust.&lt;/li&gt;
&lt;li&gt;The containerized FastAPI service on Render, including the TabPFN anomaly regression pipeline and two-pass Gemma 4 verification prompt, were tested and deployed with automated health monitoring.&lt;/li&gt;
&lt;li&gt;The complete 27-case pytest test suite was authored to verify end-to-end reliability before the release binary was compiled.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Hand-over
&lt;/h2&gt;

&lt;p&gt;On Friday evening, after our backend test suite passed and the Tauri release binary compiled cleanly, I copied &lt;code&gt;potatoclaw.exe&lt;/code&gt; onto a USB drive and walked over to Rudra's room.&lt;/p&gt;

&lt;p&gt;We fired up his buggy C linked list code in VS Code, opened twelve Chrome tabs, and brought up the 40-page lab PDF until Task Manager hit 91% RAM. His cooling fan started whining right away.&lt;/p&gt;

&lt;p&gt;He clicked the PotatoClaw pill.&lt;/p&gt;

&lt;p&gt;In Task Manager, the memory graph plummeted from 91% down to 51% in a quarter of a second. The cooling fan wound down immediately. He tapped &lt;code&gt;Alt+Shift+2&lt;/code&gt;, dragged the crosshairs over his compiler error, and Gemma 4 delivered the corrected struct pointer syntax with working C code in under a second.&lt;/p&gt;

&lt;p&gt;Rudra leaned back in his plastic chair, scrolled his code editor with zero lag, and looked at me:&lt;br&gt;&lt;br&gt;
&lt;em&gt;"Bhai... yeh kal lab exam mein pakka chalega na?"&lt;/em&gt; ("Bro... are you sure this is going to work tomorrow during the lab exam?")&lt;/p&gt;

&lt;p&gt;I smiled: &lt;em&gt;"Haan bhai. Bilkul chalega."&lt;/em&gt; ("Yes bro. Absolutely.")&lt;/p&gt;

&lt;p&gt;He saved his file, uploaded his lab submission to the college portal, and closed his laptop lid.&lt;/p&gt;




&lt;h2&gt;
  
  
  Prize Categories
&lt;/h2&gt;

&lt;p&gt;Google DeepMind (Gemma), Render, Prior Labs (TabPFN), Backboard, ElevenLabs, Sentry.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>weekendchallenge</category>
      <category>hf26challenge</category>
      <category>opensource</category>
    </item>
    <item>
      <title>TrialMatch: Why Precision Matters When Lives Are on the Line</title>
      <dc:creator>Abhishek Khanra</dc:creator>
      <pubDate>Wed, 30 Sep 2026 17:47:09 +0000</pubDate>
      <link>https://dev.to/nonebut_ak/trialmatch-why-precision-matters-when-lives-are-on-the-line-3425</link>
      <guid>https://dev.to/nonebut_ak/trialmatch-why-precision-matters-when-lives-are-on-the-line-3425</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/sanity-2026-09-16"&gt;Sanity Challenge, Path One: Ship an Agent That Queries Real Content&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Real-time clinical trial matching and safety verification using the &lt;strong&gt;Sanity Context MCP&lt;/strong&gt; and deterministic &lt;strong&gt;GROQ&lt;/strong&gt; queries.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;A friend’s dad has stage 4 non-small cell lung cancer. In late September, his first-line carboplatin stopped working, and the clinic oncologist told the family to look for Phase 2 trials on ClinicalTrials.gov.&lt;/p&gt;

&lt;p&gt;If you have ever tried navigating ClinicalTrials.gov during a family emergency, you know how painful it is. The website has roughly half a million studies, but whether someone actually qualifies is buried inside massive PDF attachments.&lt;/p&gt;

&lt;p&gt;I wanted to see what ChatGPT and Gemini would do with his diagnosis:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;58-year-old female, Stage IV NSCLC, EGFR Exon 20 insertion, progressed after carboplatin/pemetrexed, seeking recruiting Phase 2 trials in Texas.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Both models gave me two specific study IDs: &lt;code&gt;NCT04847387&lt;/code&gt; and &lt;code&gt;NCT04746654&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I checked the federal registry. Neither ID existed. The models made up eight-digit numbers on the spot.&lt;/p&gt;

&lt;p&gt;Plain keyword search didn't help much either. Searching "EGFR" and "chemo" pulled 69 studies. But when I read the PDF attachments, 31 had strict exclusion clauses banning patients who previously took chemotherapy. Worse, it pulled kidney failure trials because the kidney blood test &lt;code&gt;eGFR&lt;/code&gt; has almost the same letters as &lt;code&gt;EGFR&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Cancer trial matching is pure Boolean filtering. You have to match exact alleles, past drug lines, and washout dates. LLMs make up trial numbers, and keyword search misses negative exclusions.&lt;/p&gt;

&lt;p&gt;That's why I built &lt;strong&gt;TrialMatch&lt;/strong&gt; using &lt;strong&gt;Sanity Content Lake&lt;/strong&gt; and the &lt;strong&gt;Sanity Context MCP&lt;/strong&gt;. The AI doesn't touch the database. It just pulls four parameters from clinical notes, and our backend passes those parameters into fixed GROQ queries against Sanity schemas and protocol rules.&lt;/p&gt;

&lt;h3&gt;
  
  
  System Architecture
&lt;/h3&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    autonumber
    actor Clinician as Clinician / Patient
    participant UI as TrialMatch Web App (Next.js 16)
    participant Agent as Claude Haiku 4.5 (Schema Extractor)
    participant MCP as Sanity Context MCP (trialmatch)
    participant Lake as Sanity Content Lake (Project 6xsr2k42)
    participant KB as Sanity Knowledge Base (trialmatch-kb)

    Clinician-&amp;gt;&amp;gt;UI: Enter Patient Note ("58yo NSCLC, EGFR Exon 20, prior chemo, TX")
    UI-&amp;gt;&amp;gt;Agent: Extract Clinical Primitives
    Note over Agent: Converts narrative into:&amp;lt;br/&amp;gt;condition="Lung", biomarker="EGFR",&amp;lt;br/&amp;gt;chemo="ALLOWED", location="TX"
    Agent-&amp;gt;&amp;gt;MCP: Dispatch GROQ Query with Bound Parameters
    MCP-&amp;gt;&amp;gt;KB: Check Washout &amp;amp; Hierarchy Rules
    KB--&amp;gt;&amp;gt;MCP: Rule Verified (Chemo permitted post-progression)
    MCP-&amp;gt;&amp;gt;Lake: Execute Deterministic GROQ Filter
    Lake--&amp;gt;&amp;gt;MCP: Return 2 Verified Recruiting Protocols
    MCP--&amp;gt;&amp;gt;UI: Return Match Set + Full GROQ Audit Trace
    UI--&amp;gt;&amp;gt;Clinician: Render Verified Cards + Side-by-Side Hazard Analysis&lt;/code&gt;&lt;/pre&gt;






&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Feweylqv2ttemy2aw7lxz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Feweylqv2ttemy2aw7lxz.png" alt="The TrialMatch Duel Arena hero interface" width="800" height="298"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The Duel Arena in action: Live Sanity Context MCP status beacon, real-time safety scorecard, and 8 clinical scenario presets.&lt;/em&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Live Application&lt;/strong&gt;: &lt;a href="https://trialmatch-oncology.vercel.app" rel="noopener noreferrer"&gt;trialmatch-oncology.vercel.app&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;3-Arm Benchmark Dashboard&lt;/strong&gt;: &lt;a href="https://trialmatch-oncology.vercel.app/benchmark" rel="noopener noreferrer"&gt;trialmatch-oncology.vercel.app/benchmark&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hosted Sanity Studio&lt;/strong&gt;: &lt;a href="https://trialmatch-oncology.sanity.studio" rel="noopener noreferrer"&gt;trialmatch-oncology.sanity.studio&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  The Duel Arena: Side-by-Side Reality
&lt;/h3&gt;

&lt;p&gt;To see the difference in practice, I built the app as a split-screen duel where you can test any custom clinical note or pick from 8 preset patient profiles.&lt;/p&gt;

&lt;p&gt;The left column runs the Sanity Context Agent. It displays only active, verified trials that meet all protocol criteria, showing biomarker targets, participating hospital sites, and the exact GROQ query executed against Sanity.&lt;/p&gt;

&lt;p&gt;The right column shows naive keyword search results. A red hazard banner highlights disqualifications the text search missed, such as prior chemo exclusions, active liver metastases, or serving mutant-targeted drugs to wild-type patients.&lt;/p&gt;

&lt;p&gt;Because keyword searches often return dozens of loose hits while the agent returns 1 or 2 verified matches, each column paginates independently (6 cards per page) so you can review the keyword results without losing your place.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo7fxeq0p6sizt3uy0fw1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo7fxeq0p6sizt3uy0fw1.png" alt="Duel Arena side-by-side split with expanded GROQ inspector" width="800" height="783"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Inspecting the generated GROQ query on the left alongside the naive search failure warnings on the right.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0q3hhjpbezj6bygcgb03.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0q3hhjpbezj6bygcgb03.png" alt="Trial cards and column-level pagination controls" width="800" height="355"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Independent column pagination keeps 69 keyword matches manageable while displaying verified hospital locations.&lt;/em&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository&lt;/strong&gt;: &lt;a href="https://github.com/IshekKhal/trialmatch" rel="noopener noreferrer"&gt;github.com/IshekKhal/trialmatch&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Project Layout
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;trialmatch/
├── app/
│   ├── page.tsx               # The Duel Arena (Sanity Agent vs Keyword Baseline)
│   ├── benchmark/page.tsx     # 3-Arm Evaluation Dashboard
│   ├── layout.tsx             # Root layout with Geist font tokens
│   ├── globals.css            # Medical obsidian styling (#080C14)
│   └── api/
│       ├── duel/route.ts      # Live duel execution endpoint
│       ├── benchmark/route.ts # 3-arm benchmark evaluation API
│       └── trials/route.ts    # Normalized clinical trial fetcher
├── components/
│   ├── DuelArena.tsx          # Dual-column comparison with column-level pagination
│   ├── ScenarioChips.tsx      # 8 pre-configured oncology clinical scenarios
│   ├── BenchmarkRunner.tsx    # Interactive benchmark runner &amp;amp; case inspector
│   ├── BenchmarkTable.tsx     # 10-patient audit breakdown table
│   └── Scoreboard.tsx         # Real-time comparative metric display
├── studio/
│   ├── sanity.config.ts       # Sanity Studio v3 configuration
│   └── schemas/
│       ├── clinicalTrial.ts   # Core schema: biomarkers, therapy rules, facilities
│       ├── protocolRule.ts    # Knowledge base schema: exclusion overrides &amp;amp; washouts
│       └── index.ts           # Schema registry
├── lib/
│   ├── agent.ts               # Claude Haiku 4.5 schema extractor &amp;amp; GROQ builder
│   ├── sanity.ts              # Sanity client &amp;amp; live Context MCP bindings
│   ├── protocol_auditor.ts    # Protocol-schema clinical safety audit engine
│   ├── eval_cases.ts          # 10 gold-standard oncology test profiles
│   ├── eval_runner.ts         # Automated 3-arm benchmark execution engine
│   └── types.ts               # TypeScript domain interfaces
├── scripts/
│   ├── ingest_trials.ts       # ClinicalTrials.gov API v2 data ingestion pipeline
│   └── run_eval.ts            # CLI benchmark evaluation runner
└── data/
    ├── trials_normalized.json # Curated oncology trials across 30 countries
    ├── eval_results.json      # Raw 3-arm benchmark evaluation outputs
    └── eval_summary.md        # Comprehensive 419-line benchmark report
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How I Used Sanity
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Modeling Oncology Beyond Text Blobs
&lt;/h3&gt;

&lt;p&gt;You can't treat clinical trial protocols like blog posts or raw text fields. A single protocol has specific rules about gene mutations, previous treatments, and organ involvement.&lt;/p&gt;

&lt;p&gt;In Sanity Studio (&lt;code&gt;studio/schemas/clinicalTrial.ts&lt;/code&gt;), I split each protocol into structured fields. Biomarkers are stored as a typed string array (&lt;code&gt;targetBiomarkers&lt;/code&gt;) covering oncogenes like &lt;code&gt;EGFR&lt;/code&gt;, &lt;code&gt;KRAS&lt;/code&gt;, and &lt;code&gt;BRAF&lt;/code&gt;. Prior treatments (&lt;code&gt;priorTherapyRules&lt;/code&gt;) use explicit status flags (&lt;code&gt;REQUIRED&lt;/code&gt;, &lt;code&gt;ALLOWED&lt;/code&gt;, &lt;code&gt;EXCLUDED&lt;/code&gt;, &lt;code&gt;ANY&lt;/code&gt;) for chemo, immunotherapy, and targeted agents. Trial sites (&lt;code&gt;locations&lt;/code&gt;) track facilities across cities, states, and countries, alongside structured &lt;code&gt;eligibilityCriteria&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Clinical Trial Protocol Schema (&lt;code&gt;studio/schemas/clinicalTrial.ts&lt;/code&gt;)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;defineType&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sanity&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineType&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;clinicalTrial&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Clinical Trial&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;document&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;nctId&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NCT ID&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;validation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Rule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;required&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;briefTitle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Brief Title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;validation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Rule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;required&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;recruitmentStatus&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Recruitment Status&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Recruiting&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;RECRUITING&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Active, Not Recruiting&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ACTIVE_NOT_RECRUNTING&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;primaryCondition&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Primary Condition&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;validation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Rule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;required&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;targetBiomarkers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Target Biomarkers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;array&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;
      &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;EGFR&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;KRAS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BRAF&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;HER2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ALK&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BRCA1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BRCA2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Exon 20&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;G12C&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;V600E&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;priorTherapyRules&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Prior Therapy Rules&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
          &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;chemotherapy&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;REQUIRED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ALLOWED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;EXCLUDED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ANY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;}),&lt;/span&gt;
        &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
          &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;immunotherapy&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;REQUIRED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ALLOWED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;EXCLUDED&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ANY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;}),&lt;/span&gt;
      &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;locations&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Trial Locations&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;array&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;facility&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;city&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;state&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;country&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="p"&gt;}],&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;A lot of clinical rules have caveats—for example, a protocol might ban prior chemo unless there was at least a 30-day washout period. To handle those edge cases, I set up a second schema called &lt;code&gt;protocolRule.ts&lt;/code&gt; in our Sanity Knowledge Base:&lt;/p&gt;
&lt;h4&gt;
  
  
  Protocol Guidance Rule Schema (&lt;code&gt;studio/schemas/protocolRule.ts&lt;/code&gt;)
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;defineType&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sanity&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nf"&gt;defineType&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;protocolRule&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Clinical Protocol Interpretation Rule&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;document&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ruleId&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rule ID&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rule Title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;category&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Eligibility Hierarchy&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ELIGIBILITY_HIERARCHY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Washout Periods&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;WASHOUT_PERIODS&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Biomarker Specificity&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BIOMARKER_SPECIFICITY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;priority&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Priority (1-10)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;summary&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rule Summary&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nf"&gt;defineField&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;clinicalRationale&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Clinical Rationale&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fslix0m6ipre61uvh4t0k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fslix0m6ipre61uvh4t0k.png" alt="Sanity Studio showing structured clinical trial documents" width="799" height="452"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Sanity Studio managing 100 oncology protocols with explicit prior therapy rules, biomarker tags, and multi-center site registries.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Sanity Context MCP Endpoints
&lt;/h3&gt;

&lt;p&gt;We hooked the Sanity Content Lake up to two Context MCP endpoints:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;trialmatch&lt;/code&gt;: handles parameterized GROQ queries against the live trials dataset.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;trialmatch-kb&lt;/code&gt;: handles semantic search over the protocol rules.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When a clinician enters a note, the agent translates the extracted values into this GROQ query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*[_type == "clinicalTrial" &amp;amp;&amp;amp; 
  recruitmentStatus == "RECRUITING" &amp;amp;&amp;amp; 
  primaryCondition match $condition &amp;amp;&amp;amp; 
  targetBiomarkers[] match $biomarker &amp;amp;&amp;amp; 
  (locations[].state match $location || 
   locations[].city match $location || 
   locations[].country match $location || 
   locations[].facility match $location) &amp;amp;&amp;amp; 
  (priorTherapyRules.chemotherapy == "ALLOWED" || 
   priorTherapyRules.chemotherapy == "REQUIRED" || 
   priorTherapyRules.chemotherapy == "ANY")] {
    nctId,
    briefTitle,
    phase,
    primaryCondition,
    targetBiomarkers,
    priorTherapyRules,
    "matchingLocations": locations[state match $location || city match $location || country match $location || facility match $location]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because &lt;code&gt;priorTherapyRules.chemotherapy&lt;/code&gt; is an explicit schema field, Sanity excludes protocols that forbid prior chemotherapy before anything reaches the UI.&lt;/p&gt;




&lt;h2&gt;
  
  
  Behind the Build: 6 Edge Cases and Engineering Fixes
&lt;/h2&gt;

&lt;p&gt;Real clinical datasets break code in weird ways. Here are the headaches I hit while writing this and how the schema saved the build:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The "Chemo-Naive" Substring Collision
&lt;/h3&gt;

&lt;p&gt;Substring bugs almost tanked trial matching right off the bat. Many trials demand a patient be chemo-naive, meaning they never had chemotherapy. My earliest script just ran &lt;code&gt;text.includes("chemo")&lt;/code&gt;. Naturally, since "chemo-naive" literally has the word "chemo" sitting right inside it, the parser assumed the patient received prior chemotherapy and threw out the match. Talk about embarrassing. I had to overhaul &lt;code&gt;protocol_auditor.ts&lt;/code&gt; so it checks negative prefixes like "no prior" and "chemo-naive" long before evaluating drug strings.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. The &lt;code&gt;eGFR&lt;/code&gt; vs &lt;code&gt;EGFR&lt;/code&gt; Alphabet Trap
&lt;/h3&gt;

&lt;p&gt;Then came the alphabet collision: &lt;code&gt;eGFR&lt;/code&gt; vs &lt;code&gt;EGFR&lt;/code&gt;. EGFR is the lung tumor gene mutation I was hunting for, whereas eGFR is just a routine blood panel test tracking kidney function. Two completely different worlds, but dumb substring search treated them as identical. It started matching kidney disease trials for lung cancer patients. That is obviously unacceptable. Restricting &lt;code&gt;targetBiomarkers&lt;/code&gt; to a typed Sanity array killed this bug dead, because an oncology biomarker field simply will not accept metabolic lab acronyms.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. The React Preset State Leak
&lt;/h3&gt;

&lt;p&gt;React state caused another subtle leak. Clicking a quick preset filled in the search filters nicely. But if a doctor started typing a brand new patient note into the box, those preset tags stuck around in the background payload. Old tags secretly merged with new text. A simple &lt;code&gt;onChange&lt;/code&gt; hook on the textarea solved it by purging the active preset the second a user hits a key.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Ungrounded LLM Trial ID Drift (21 vs 22 vs 20)
&lt;/h3&gt;

&lt;p&gt;Unconstrained LLMs also drifted in funny ways. Running bare Gemini Flash across ten test cases without a database produced 21 fake NCT IDs on the first attempt, 22 on the second, and 20 on the third. Why? Temperature variance. A single probabilistic roll makes the model drop or tack on an extra bullet. Not one of those IDs existed in real life.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Why the Agent is an Extractor, Not a Query Writer
&lt;/h3&gt;

&lt;p&gt;I quickly gave up on letting LLMs write GROQ queries. Whenever you ask a model to produce database queries, it routinely drops exclusion criteria or adds sloppy OR clauses that pull in half the database. We flipped the architecture: the LLM only pulls out four simple parameters, and hardcoded query builders do the rest.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. The Vercel Serverless Read-Only Filesystem
&lt;/h3&gt;

&lt;p&gt;Finally, serverless hosting gave me headaches on day one. Locally, my benchmark suite was dumping evaluation logs to disk with &lt;code&gt;fs.writeFileSync&lt;/code&gt;. Vercel serverless functions, of course, run on read-only filesystems outside &lt;code&gt;/tmp&lt;/code&gt; and crashed immediately with 500 errors. I had to rip out disk writes, compute the stats entirely in memory, and stream JSON directly down to the client.&lt;/p&gt;




&lt;h2&gt;
  
  
  The 3-Arm Benchmark: Empirical Findings
&lt;/h2&gt;

&lt;p&gt;To measure how structured content impacts discovery accuracy, I built an automated evaluation runner (&lt;code&gt;lib/eval_runner.ts&lt;/code&gt;) and tested ten gold-standard oncology profiles across three search approaches:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Evaluation Metric&lt;/th&gt;
&lt;th&gt;Arm 1: Structured Sanity Agent&lt;/th&gt;
&lt;th&gt;Arm 2: Naive Keyword Search&lt;/th&gt;
&lt;th&gt;Arm 3: Bare LLM (Gemini 3.8 Flash)&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Medical Precision&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;100%&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;60%&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0%&lt;/td&gt;
&lt;td&gt;Sanity matched safe protocols; other arms included disqualified trials&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Safety Violations&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;153&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;21&lt;/td&gt;
&lt;td&gt;Keyword search missed negative criteria; Gemini bypassed protocol rules&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Hallucinated NCT IDs&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;21 (100% fake)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Raw LLM invented non-existent trial IDs with no registry records&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Auditability Rate&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;100%&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;0%&lt;/td&gt;
&lt;td&gt;0%&lt;/td&gt;
&lt;td&gt;Sanity logs the exact GROQ query and rule check for every match&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Avg Returned Trials&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1.2&lt;/td&gt;
&lt;td&gt;41.5&lt;/td&gt;
&lt;td&gt;2.1&lt;/td&gt;
&lt;td&gt;Sanity returns 1-2 verified trials instead of flooding the user with 40+ bad hits&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc01c0m4bpikt8wa4s658.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc01c0m4bpikt8wa4s658.png" alt="Interactive benchmark dashboard scorecard" width="800" height="436"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The 3-Arm Benchmark Dashboard showing 100% medical precision and 0 hallucinations for the Sanity agent versus 153 safety violations in keyword search and 100% fake NCT IDs from the bare LLM.&lt;/em&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Real Clinical Failure Modes
&lt;/h2&gt;

&lt;p&gt;Here is what happens when you pit these search methods against real clinical profiles:&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Chemotherapy Exclusion (Case TC-01)
&lt;/h3&gt;

&lt;p&gt;A 58-year-old with EGFR Exon 20 non-small cell lung cancer had already progressed on carboplatin. Keyword search naively spat out 69 studies, but 31 of them (including &lt;code&gt;NCT07799935&lt;/code&gt;) explicitly forbid anyone who has had systemic chemotherapy. Meanwhile, ungrounded Gemini hallucinated two fictional studies, &lt;code&gt;NCT04847387&lt;/code&gt; and &lt;code&gt;NCT04746654&lt;/code&gt;. Our Sanity agent checked &lt;code&gt;priorTherapyRules.chemotherapy&lt;/code&gt; directly in GROQ, immediately tossing out the 31 invalid studies and keeping the only 2 trials that actually permit prior platinum therapy.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Liver Metastases Exclusion (Case TC-02)
&lt;/h3&gt;

&lt;p&gt;Organ metastases in TC-02 trip up naive text matching completely. We tested a 62-year-old with KRAS G12C colorectal cancer and active liver metastases. Keyword search flagged &lt;code&gt;NCT05286814&lt;/code&gt; simply because the word "metastases" appeared in the description, totally missing the protocol exclusion disqualifying liver involvement. Gemini just made up two random trial IDs, &lt;code&gt;NCT04793958&lt;/code&gt; and &lt;code&gt;NCT04685141&lt;/code&gt;. The Sanity knowledge base caught the liver contraindication in the protocol rules and dropped the trial.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. HER2 Expression Cutoffs (Case TC-03)
&lt;/h3&gt;

&lt;p&gt;Biomarker cutoffs in TC-03 require strict numerical boundaries. A 51-year-old patient with HER2-low breast cancer (IHC 1+ or 2+) needs trials tailored to low expression. Keyword search dumped 72 trials, mostly high-HER2 protocols like &lt;code&gt;NCT04281641&lt;/code&gt; that strictly demand 3+ overexpression. Raw LLMs hallucinated non-existent trials. Sanity’s schema filtered out the 3+ requirements and matched antibody-drug conjugate studies specifically enrolling HER2-low cohorts.&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Phase 3 Requirement (Case TC-04)
&lt;/h3&gt;

&lt;p&gt;Phase filtering in TC-04 proves why exact metadata matters. A 47-year-old with Stage IIIC BRAF V600E melanoma specifically needed confirmatory Phase 3 trials in New York. Plain search returned 30 studies, but 26 were early Phase 1 dose-escalation cohorts. Gemini fabricated trials out of thin air. Sanity ran a simple &lt;code&gt;phase == "PHASE3"&lt;/code&gt; check, instantly filtering the noise down to the single matching trial.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8zvluah66jnr2c4809do.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8zvluah66jnr2c4809do.png" alt="Detailed 3-column patient case audit drawer" width="799" height="375"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Detailed case audit: inspecting why trial NCT07799935 violates chemotherapy rules, while Gemini invents fictional identifiers.&lt;/em&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Sanity Project Details
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Project ID&lt;/strong&gt;: &lt;code&gt;6xsr2k42&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dataset&lt;/strong&gt;: &lt;code&gt;production&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hosted Studio&lt;/strong&gt;: &lt;a href="https://trialmatch-oncology.sanity.studio" rel="noopener noreferrer"&gt;trialmatch-oncology.sanity.studio&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sanity GROQ MCP Endpoint&lt;/strong&gt;: &lt;code&gt;https://api.sanity.io/v1/context/organizations/oz3yptidu/mcp/trialmatch&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sanity Knowledge Base MCP Endpoint&lt;/strong&gt;: &lt;code&gt;https://api.sanity.io/v1/context/organizations/oz3yptidu/mcp/trialmatch-kb&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public Sample Query (Live JSON)&lt;/strong&gt;: &lt;a href="https://6xsr2k42.api.sanity.io/v2026-03-03/data/query/production?query=%2A%5B_type%3D%3D%22clinicalTrial%22%5D%5B0...2%5D%7BnctId%2CbriefTitle%2CprimaryCondition%7D" rel="noopener noreferrer"&gt;Live 3-Trial Sanity Query Endpoint&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Agent Session
&lt;/h2&gt;

&lt;p&gt;Below is a representative excerpt from the agent's interaction loop with Sanity Context MCP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Clinician:
"We have a 58yo patient with NSCLC harboring an EGFR Exon 20 insertion.
She progressed on carboplatin/pemetrexed. Find recruiting Phase 2 trials
in Texas that permit prior chemotherapy."

Agent (Claude Haiku 4.5):
Extracting clinical parameters:
- Condition: "Lung" (NSCLC)
- Target Biomarker: "EGFR", "Exon 20"
- Chemotherapy: "ALLOWED" or "REQUIRED"
- Location: "TX"
- Recruitment Status: "RECRUITING"

Tool Call -&amp;gt; Sanity Context MCP (trialmatch):
GROQ: *[_type == "clinicalTrial" &amp;amp;&amp;amp; recruitmentStatus == "RECRUITING"
         &amp;amp;&amp;amp; primaryCondition match "Lung"
         &amp;amp;&amp;amp; targetBiomarkers[] match "EGFR"
         &amp;amp;&amp;amp; (priorTherapyRules.chemotherapy == "ALLOWED" || 
             priorTherapyRules.chemotherapy == "REQUIRED")
         &amp;amp;&amp;amp; (locations[].state match "TX" || locations[].facility match "TX")]{nctId, briefTitle, phase}

MCP Response:
[
  {
    "nctId": "NCT05376891",
    "briefTitle": "Phase 2 Study of Targeted EGFR Exon 20 Inhibitor",
    "phase": "PHASE2"
  },
  {
    "nctId": "NCT06234137",
    "briefTitle": "Targeted Kinase Therapy for Relapsed EGFR Mutations",
    "phase": "PHASE2"
  }
]

Verification: 2 active matches found. 0 safety exclusions violated. 0 hallucinations.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Why This Matters
&lt;/h2&gt;

&lt;p&gt;A lot of people assume AI accuracy is something you fix by picking a bigger model or spending weeks tweaking system prompts. In healthcare, that doesn't work. A patient either meets trial inclusion criteria or they don't. An 80% accurate search isn't helpful if that remaining 20% margin of error sends a family to a clinic where they get rejected at the door.&lt;/p&gt;

&lt;p&gt;Splitting up the responsibilities solved this cleanly. We let Claude do what it handles best: parsing unstructured clinical notes and pulling out core patient parameters. Then we hand those parameters to Sanity to do what it handles best: executing deterministic GROQ queries against structured schemas and rule engines.&lt;/p&gt;

&lt;p&gt;Most teams treat structured content as something you only use for marketing blogs and CMS landing pages. But if you are building autonomous agents where a hallucinated number could ruin someone's care plan, having a typed schema is the only thing keeping the model grounded.&lt;/p&gt;




&lt;h3&gt;
  
  
  Try It Yourself
&lt;/h3&gt;

&lt;p&gt;Explore the live duel or run the benchmark yourself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌐 &lt;strong&gt;Live Arena&lt;/strong&gt;: &lt;a href="https://trialmatch-oncology.vercel.app" rel="noopener noreferrer"&gt;trialmatch-oncology.vercel.app&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📊 &lt;strong&gt;Live Benchmark&lt;/strong&gt;: &lt;a href="https://trialmatch-oncology.vercel.app/benchmark" rel="noopener noreferrer"&gt;trialmatch-oncology.vercel.app/benchmark&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💻 &lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/IshekKhal/trialmatch" rel="noopener noreferrer"&gt;github.com/IshekKhal/trialmatch&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have feedback, ideas for clinical trial filtering, or experience with Sanity MCP in production, I would love to hear your thoughts in the comments below!&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>sanitychallenge</category>
      <category>sanity</category>
      <category>ai</category>
    </item>
    <item>
      <title>How I used a sparse GSI to build a real-time post scheduler on Amazon DynamoDB</title>
      <dc:creator>Abhishek Khanra</dc:creator>
      <pubDate>Mon, 29 Jun 2026 19:52:41 +0000</pubDate>
      <link>https://dev.to/nonebut_ak/how-i-used-a-sparse-gsi-to-build-a-real-time-post-scheduler-on-amazon-dynamodb-c03</link>
      <guid>https://dev.to/nonebut_ak/how-i-used-a-sparse-gsi-to-build-a-real-time-post-scheduler-on-amazon-dynamodb-c03</guid>
      <description>&lt;p&gt;I'm writing this as part of my submission for the H0 Hackathon: Hack the Zero Stack with Vercel and AWS Databases. But the database problem I'm about to describe is real and it took me longer to solve than I'd like to admit.&lt;/p&gt;

&lt;p&gt;SlothPost is a tool I built for indie developers who want to build in public but can never find the time to actually write posts. It connects to your GitHub, Vercel, and App Store, captures all your activity, and drafts social media posts for X and Threads that you review and approve before they go live.&lt;br&gt;
The part that runs everything is a cron-based scheduler. And the scheduler has an interesting DynamoDB design problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every user in SlothPost can have multiple "products" — the things they're building. Each product has a posting schedule: something like "post to X every Tuesday and Thursday at 9am, post to Threads on Mondays."&lt;br&gt;
The scheduler needs to run every minute and answer one question: which products are due for post generation right now?&lt;br&gt;
The naive approach is to scan the entire products table, filter for active schedules, and check if any of them are due. This works fine when you have 10 users. It's a disaster at 10,000.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The sparse GSI approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;DynamoDB doesn't have server-side scheduled jobs. What it does have is Global Secondary Indexes, and they have a property that's extremely useful here.&lt;br&gt;
A GSI only indexes items that have the attribute it's keying on. If an item doesn't have the attribute, it's simply not in the index. This is called a sparse index.&lt;br&gt;
I added an attribute called scheduleStatus to each product. When a product has an active posting schedule, scheduleStatus is set to 'active'. When it's paused or the user hasn't configured one yet, the attribute is simply absent from the item.&lt;br&gt;
I also added nextRunAt — a Unix timestamp for when this product is next due for generation. This gets recomputed every time a post is generated based on the user's schedule configuration.&lt;br&gt;
The GSI is keyed on scheduleStatus (partition key) and nextRunAt (sort key). To find what's due right now, the cron query looks like this:&lt;/p&gt;

&lt;p&gt;typescriptconst result = await dynamoDB.query({&lt;br&gt;
  TableName: 'slothpost-products',&lt;br&gt;
  IndexName: 'scheduleStatus-nextRunAt-index',&lt;br&gt;
  KeyConditionExpression: 'scheduleStatus = :active AND nextRunAt &amp;lt;= :now',&lt;br&gt;
  ExpressionAttributeValues: {&lt;br&gt;
    ':active': 'active',&lt;br&gt;
    ':now': Date.now()&lt;br&gt;
  }&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;That's it. The query only touches products that are actively scheduled. No scans, no post-query filtering. The index stays small because most products in the table don't have scheduleStatus set at all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The bug that took me a day to find&lt;/strong&gt;&lt;br&gt;
When I first built computeNextRunAt, I had it check daySchedule.enabled to see if a given day was enabled in the user's schedule. This seemed reasonable until I realized that field didn't exist anywhere.&lt;br&gt;
The enabled state in SlothPost isn't stored as a boolean. It's represented by whether time is null or not. If the user has set a time for Monday, Monday is enabled. If the time is null, it's disabled. There's no separate enabled flag.&lt;br&gt;
The function was silently returning null for the next run time on every call, which meant nextRunAt was never written, which meant nothing ever appeared in the GSI, which meant the scheduler ran every minute and found nothing to do.&lt;br&gt;
It took a while to find because the cron itself was working fine — it just had an empty result set on every execution. That's the kind of bug that doesn't throw an error. It just silently doesn't work.&lt;br&gt;
The fix was one line: replace daySchedule.enabled with typeof daySchedule.time === 'string'. But finding that line took longer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Vercel webhook routing problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I used the same sparse GSI pattern for a different problem: routing Vercel deployment webhooks to the right user.&lt;br&gt;
SlothPost is a Vercel Marketplace integration. When a user connects their Vercel account, they select which Vercel project they want to track. That project ID gets written as vercelProjectId on their product record.&lt;br&gt;
When a deployment webhook arrives, I need to find which product it belongs to. The sparse GSI on vercelProjectId makes this a single targeted query instead of a scan. Products without a Vercel project connected don't have the attribute and don't appear in the index.&lt;br&gt;
One thing worth knowing about Vercel marketplace integrations that isn't documented anywhere I could find: you cannot create webhooks programmatically via the Vercel REST API. You get a hard 403. The correct approach is to configure a global webhook in the Integration Console. I lost a full day trying to make the API approach work before I figured this out.&lt;br&gt;
Takeaways&lt;br&gt;
The sparse GSI is genuinely useful for any scheduling or routing problem where the "active" state is a subset of your total item count. It keeps your queries fast, keeps the index small, and avoids the full-table-scan anti-pattern entirely.&lt;br&gt;
The one thing I'd add: removeUndefinedValues: true on the DynamoDB DocumentClient is not optional when you're working with TypeScript. If any attribute in your item is undefined, DynamoDB will reject the write. That config option silently strips undefined fields instead. I spent two hours debugging that before finding it in the docs.&lt;/p&gt;

&lt;p&gt;Full app is at &lt;a href="https://slothpost.app" rel="noopener noreferrer"&gt;https://slothpost.app&lt;/a&gt;&lt;br&gt;
Uses Next.js on Vercel, DynamoDB for everything, Cloudflare Workers for the cron scheduler.&lt;/p&gt;

&lt;h1&gt;
  
  
  H0Hackathon
&lt;/h1&gt;

</description>
      <category>dynamodb</category>
      <category>aws</category>
      <category>h0hackathon</category>
      <category>indiedev</category>
    </item>
  </channel>
</rss>
