Skip to content

feat(learn): start a screen time focus session with each focus period - #22

Merged
screen-gd merged 9 commits into
mainfrom
feat/screen-time-focus
Nov 14, 2026
Merged

screen-gd merged 9 commits into
mainfrom
feat/screen-time-focus

Conversation

@screen-gd

@screen-gd screen-gd commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Starting a focus period in Syllo now starts a Screen Time focus session, so only the study work stays usable. Breaks, pause, reset, the end of the period and turning the link off end it. The link is off by default and lives in Settings.

sequenceDiagram
    participant Timer as Pomodoro (browser)
    participant Syllo as Syllo server
    participant ST as Screen Time (same computer)
    Timer->>Syllo: POST /api/screen-time/session {goal, durationSeconds, resourceUrls}
    Syllo->>Syllo: read connection.json, validate (loopback only, live pid)
    Syllo->>ST: POST /api/v1/focus/session + X-Tally-Token
    ST-->>Syllo: 201 session / 409 busy
    Syllo-->>Timer: status union (no token)
Loading
focus running              -> start (remaining seconds, goal = "Lesson · Module" or "Study session")
under 60 s of focus left   -> no start
break / pause / reset      -> stop
first sync after load      -> always sent, so a reload can't leave the two disagreeing
link turned off            -> stop if Syllo started a session
session ended in Screen Time -> label drops within 20 s, timer keeps running, no restart
start refused (not running)  -> retried once Screen Time answers
  • allowSites is Syllo's own host plus the hosts of the open lesson's resources. mode, apps and sites are left unset so the lists saved in Screen Time apply.
  • Matches Screen Time's limits: the goal is at most 200 characters (long goals are cut on a word boundary) and the duration is 60 s to 12 h.
  • Requests are queued one at a time and the newest timer state wins, so fast Start/Pause clicks can't leave Screen Time blocking a paused timer.
  • Screen Time missing, not running, outdated (404), busy (409), a 409 on stop (another source's session) or a stale connection file turns into a calm one-line status. The timer never waits on it.
  • Works only when Syllo's server and Screen Time run on the same computer. The Settings copy and docs/syllo-setup.md say so. There's no pairing.
apps/web/src/
├── lib/screen-time/contract.ts        # zod schemas, status union, goal and duration limits, copy
├── lib/screen-time/client.ts          # browser API, link toggle, focus sync queue
├── lib/server/screen-time.ts          # connection file + Screen Time HTTP adapter
├── routes/api/screen-time/session.ts  # GET status / POST start / DELETE stop
└── components/learning/ScreenTimeSettings.tsx

Evidence

  • bun run typecheck, bun run lint, bun run build: pass. bun run test: 159 passed, including three new Screen Time test files.
  • Adapter tests use a real local fake Screen Time server: start, stop, 409 on start and on stop, missing file, missing app folder, bad JSON, non-loopback URL (no request sent), unreachable port, dead pid, 404, junk body, wrong token, a timed-out call, a dropped connection, a 250-character goal, a blank goal and a 50000 s duration.
  • Timer tests:
    • Start sends a POST for 1500 s and Pause sends a DELETE.
    • On load, a stored running timer re-posts its remaining time and a stored idle timer sends a stop.
    • With the link off nothing is sent, including no status checks.
    • A session ended in Screen Time drops the label without a new POST, and a visible tab triggers a status check.
    • With under 60 s left no start is sent.
    • A link to evil-youtube-nocookie.com does not unlock youtube.com.
    • Queue regressions cover stop → start → stop and turning the link off while a stop is in flight.
  • Live check against a built server on port 3100: GET /api/screen-time/session returned {"kind":"not-installed"} (this machine has no Screen Time), a bad POST returned 400, and a cross-site request returned 403.
  • No screenshots. No browser testing was requested, and Screen Time's session API (feat/focus-sessions) isn't merged, so there was no end-to-end run against the real app.

Reviewed with sol-loop: 3 rounds with gpt-6.1-sol. Sol verdict: approved.

Merge Danger

Door: two-way

The feature is off until it's switched on in Settings, and turning it off removes all of its behavior.

Blast Radius: small

The Pomodoro provider is mounted app-wide, so a crash there would affect every page. With the link off it sends nothing.

Created with Claude Opus 5.5 and SWE-2 (Devin, Fusion) in T3 Code. Reviewed by GPT-6.1 Sol.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 39 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a8a10c19-b17e-489c-8921-ff379ee98902
Commits

Reviewing files that changed from the base of the PR and between 0603231 and 9915cd0.

Files selected for processing: 7

  • apps/web/src/components/learning/Pomodoro.tsx
  • apps/web/src/components/learning/ScreenTimeSettings.tsx
  • apps/web/src/lib/__tests__/screen-time-adapter.test.ts
  • apps/web/src/lib/__tests__/screen-time-link.test.ts
  • apps/web/src/lib/__tests__/screen-time-pomodoro.test.tsx
  • apps/web/src/lib/screen-time/client.ts
  • apps/web/src/lib/server/screen-time.ts

No actionable comments were generated in the recent review.

Walkthrough

This change adds an optional Screen Time link for Pomodoro focus sessions. A local API route validates requests and communicates with Screen Time. Pomodoro and settings display link status, and lesson details provide focus goals and resource URLs.

Changes: Screen Time focus link

Layer / File(s) Summary
Screen Time contracts and focus sync
apps/web/src/lib/screen-time/contract.ts, apps/web/src/lib/screen-time/client.ts, apps/web/src/lib/__tests__/screen-time-link.test.ts
Defines request and status schemas, manages the local link setting, maps timer state to focus intents, and synchronizes updates with deduplication and queued-intent handling. Tests cover intent mapping, request dispatch, release, and recovery behavior.
Local Screen Time adapter and session route
apps/web/src/lib/server/screen-time.ts, apps/web/src/routes/api/screen-time/session.ts, apps/web/src/routeTree.gen.ts, apps/web/src/lib/__tests__/screen-time-adapter.test.ts
Adds local connection-file validation and Screen Time API calls. The session route handles status, validated start, and stop requests. The generated route tree registers the endpoint. Tests cover connection handling, request results, paths, and allowed-site selection.
Pomodoro, lesson, and settings integration
apps/web/src/components/learning/Pomodoro.tsx, apps/web/src/components/learning/ScreenTimeSettings.tsx, apps/web/src/views/studio/learn.tsx, apps/web/src/views/studio/personal-settings.tsx, apps/web/src/lib/__tests__/screen-time-pomodoro.test.tsx, docs/syllo-setup.md
The lesson page supplies a goal and filtered resource URLs. Pomodoro synchronizes focus intent, checks status, and displays link status. Personal settings adds the Screen Time link control. Tests cover timer and status behavior, and the setup guide documents the link.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Pomodoro
  participant ScreenTimeClient
  participant SessionRoute
  participant ScreenTimeAdapter
  participant ScreenTimeAPI
  Pomodoro->>ScreenTimeClient: Send focus intent when linked
  ScreenTimeClient->>SessionRoute: Request status, start, or stop
  SessionRoute->>ScreenTimeAdapter: Run the requested operation
  ScreenTimeAdapter->>ScreenTimeAPI: Send authenticated loopback request
  ScreenTimeAPI-->>ScreenTimeAdapter: Return session response
  ScreenTimeAdapter-->>SessionRoute: Return mapped status
  SessionRoute-->>ScreenTimeClient: Return status as JSON
  ScreenTimeClient-->>Pomodoro: Update link status
Loading
Merge Risk: Low · previous review 06032

This adds an optional, off-by-default Screen Time link that starts and stops a focus session with the Pomodoro timer. A few minor edge cases remain: a failed stop after pause may not be shown, a failed start has no retry path, a repeated unlink during an in-flight start may leave blocking on, and overlapping status checks in Settings can show stale information. None of these affect the timer itself, so it is mergeable with these tracked as follow-ups.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(learn): start a screen time focus session with each focus period" matches the main change. The PR adds an optional Screen Time link that starts a Screen Time session with each Pomodoro…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "feat(learn): start a screen time focus session with each focus period" matches the main change. The PR adds an optional Screen Time link that starts a Screen Time session with each Pomodoro focus period, and it stops the session on breaks, pauses, resets, and disabling the link. The title is specific and does not describe unrelated work. The changeset also includes supporting pieces (server route, client, allowlist logic, settings UI, and docs) that the title does not name, which is expected for a title.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit starts the focus clock,
And checks the link beside the lock.
Lesson goals and sites take flight,
Status checks return in sight.
When focus ends, the link lets go,
Then off to nibble greens below.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: be6d4df8-4c69-44cd-8be4-570d8606d616
Commits

Reviewing files that changed from the base of the PR and between 036b000 and 0603231.

Files selected for processing: 8

  • apps/web/src/components/learning/Pomodoro.tsx
  • apps/web/src/lib/__tests__/screen-time-adapter.test.ts
  • apps/web/src/lib/__tests__/screen-time-link.test.ts
  • apps/web/src/lib/__tests__/screen-time-pomodoro.test.tsx
  • apps/web/src/lib/screen-time/client.ts
  • apps/web/src/lib/screen-time/contract.ts
  • apps/web/src/lib/server/screen-time.ts
  • docs/syllo-setup.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

devin-ai-integration[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@screen-gd

Copy link
Copy Markdown
Owner Author

Note

🤖 Claude Opus 5.5 responding on behalf of screen-gd

Pushed two fixes to 0603231.

  • 2d9c902 A session ended from Screen Time is now noticed (Pomodoro.tsx, client.ts). While Syllo believes its session is on, it checks the status every 20 s and when the tab becomes visible. If the session is gone or belongs to another source, the "Focus · Screen Time" label drops and the timer keeps running. createFocusSync.markEnded stops that focus period from being sent again, even after a lesson change. The next focus period starts as usual. No checks run while the link is off or after a start was refused. A failed check only updates the status line.
  • 0603231 Screen Time's limits (contract.ts, client.ts, server/screen-time.ts). focusGoal trims the goal, falls back to "Study session" and cuts goals over 200 characters on a word boundary with "…". With under 60 s of focus left, Syllo skips the start without a request, and durations above 12 h are clamped to 43200 s. Both the client and the adapter enforce this, and the route rejects values outside the range. A DELETE answered with 409 now means "another source's session" and returns a calm ready status.

Checks on 0603231: bun run typecheck, bun run lint, bun run build pass, and bun run test passes 151 tests. A GPT-6.1 Sol review of the changes since 2d108a6 approved them.

@screen-gd

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@screen-gd

Copy link
Copy Markdown
Owner Author

/devin review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Starting Devin Review.

Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@screen-gd

Copy link
Copy Markdown
Owner Author

Note

🤖 Claude Opus 5.5 responding on behalf of screen-gd

Pushed 79f7b33 and 52c77fd (head 52c77fd). Each finding has a reply in its thread.

  • 79f7b33: a short focus period that replaces an earlier session now stops that session instead of skipping quietly (Devin Review).
  • 52c77fd, from CodeRabbit's review of the first head:
    • release() keeps a queued stop when it runs twice.
    • A start refused with not-running/unavailable is retried once Screen Time answers. A session ended in Screen Time still isn't restarted.
    • A failed stop shows its hint after pause.
    • "Check again" in Settings can't be overwritten by an older reply.

Checks on 52c77fd: bun run typecheck, bun run lint, bun run build pass, and bun run test passes 157 tests.

@screen-gd

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@screen-gd

Copy link
Copy Markdown
Owner Author

/devin review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Starting Devin Review.

Devin Review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@screen-gd

Copy link
Copy Markdown
Owner Author

Note

🤖 Claude Opus 5.5 responding on behalf of screen-gd

Pushed 628af05, from CodeRabbit's follow-up in the stop-failure thread. A Screen Time call that times out now reports unavailable instead of not-running, so the timer's hint shows a timed-out stop after pause. A refused connection still reports not-running. A new adapter test hangs the DELETE on the fake server.

Checks on 628af05: bun run typecheck, bun run lint, bun run build pass, and bun run test passes 158 tests. Devin Review on 52c77fd finished with no new findings.

@screen-gd

Copy link
Copy Markdown
Owner Author

/devin review

@screen-gd

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Starting Devin Review.

Devin Review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@screen-gd

Copy link
Copy Markdown
Owner Author

/devin review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Starting Devin Review.

Devin Review

@screen-gd

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@screen-gd
screen-gd merged commit 4f8d6d7 into main Nov 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant