← Back to Pull requests

feat: plan a protocol by weeks, with a dose and a frequency per band #16

Closed
unknown closed this pull request without merging on Aug 21, 2026 05:08 UTC
View on GitHub
unknown unknown commented on Aug 19, 2026 16:34 UTC
Author

What

A titration varies the dose and holds the frequency. That is the right shape for a published escalation and the wrong shape for a plan someone writes themselves, so this could not be said at all:

Weeks 1 to 3     1 mg
Weeks 4 to 6     2 mg
Week 7           3 mg
Week 8 onwards   4 mg, and twice a week rather than weekly

This adds a third option to the protocol form, beside Fixed and Titration: By weeks. Bands of weeks, each with a dose and optionally a frequency of its own. The last band runs on indefinitely, which is what "week 8 onwards" means.

Model

ProtocolPhase is the general form of a titration: weeks, a dose, and an optional Schedule. It is optional on Protocol.

Phases live on the protocol and never in the compound library. A TitrationPlan carries a source and an evidence level because it is a claim about what was studied. A personal ladder is a claim about nothing except what its author intends to do, so it has no business sitting next to trial data.

One code path, not two

protocolPhases() reads an auto-advancing titration as a phase list, because that is what it already is. Everything downstream works on phases, so there is no second mechanism to keep in step with the first.

The schedule primitives are untouched. New protocol-level wrappers resolve phases onto the calendar and then defer to them:

  • protocolDoseTimesBetween

  • protocolNextDoseTime

  • protocolPreviousDoseTime

  • protocolDosesPerWeek
  • A protocol with no phases yields a single span covering all of time and takes exactly the path it always did. That is asserted rather than assumed: phases.test.ts compares the old and new calls across six schedule shapes, including cycling and an endedAt, and requires identical output.

    Two decisions worth naming

    Each phase anchors its own interval. "From week four, every three days" counts from the start of week four, not from a rhythm inherited from a start date months earlier. The alternative is defensible but surprising.

    protocolDosesPerWeek reports the current phase's rate, not an average. It feeds burn rate and days of supply, and the question those answer is how fast the vial is emptying now.

    Data

    phases is optional, so nothing needed migrating. migrateAppData spreads protocols rather than rebuilding them field by field, and the backup is whole object JSON, so a plan built on the web imports into the Android build and back out again.

    Gate

  • tsc --noEmit clean

  • eslint clean

  • 990 tests, 28 of them new, passing in UTC, America/New_York, Europe/Ljubljana and Pacific/Auckland

  • next build succeeds

  • BUILD_TARGET=static next build succeeds and emits /plan/index.html, so the Capacitor webview build is unaffected
  • The two builds were run with the next/font Google Fonts calls stubbed in a throwaway copy of the tree, because the environment this was prepared in cannot reach fonts.googleapis.com. Worth one confirming run somewhere with network before merge.

    Out of scope, deliberately

    No new network calls, no notifications, no changes to the compound library. Per-phase injection sites were not added; sites remain a protocol-level choice.

    Noticed in passing

    CLAUDE.md and CONTRIBUTING.md both say 774 tests. The suite is at 962 before this change and 990 after. Left alone here to keep the diff to one subject.

    Diff: 429 lines (+321 / -108) across 5 files Reviewer: ArunNGun Review duration: 2193m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 429 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.363
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #16"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.1% (MEDIUM) · Higher = larger blast radius
    45.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.8% · Safe to merge
    17.8%
    Repository