Skip to content

feat(sources): Google Calendar as a sensor, as a service account or a connected Google account - #399

Merged
adeelahmad merged 2 commits into
mainfrom
claude/project-thread-4kmlnn
Oct 15, 2026
Merged

adeelahmad merged 2 commits into
mainfrom
claude/project-thread-4kmlnn

Conversation

@adeelahmad

Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Description

Before: a Google calendar reached Lens only as an iCal feed (its secret address).

After: Sources has a Google Calendar connection (type gcal, also POST /api/v1/sources). Each calendar is a folder and each event a file <calendar id>/<event id>.ics, read as text exactly as an iCal feed's events are, so browsing, picking events, watching and importing work unchanged. It reads through the Calendar API with the read-only calendar.readonly scope and signs in either:

  • as a service account (its .json key file): calendars shared with it (IDs in calendars), or, in Google Workspace, a user's calendars through domain-wide delegation (impersonate);
  • as a Google account: an OAuth client's authorized user JSON (client_id, client_secret, refresh_token). A "Connect with Google" button that fills this in from a consent screen is the next PR.

Events also say which occurrences of a repeating event were cancelled (EXDATE) and their video call; the event text now shows both for iCal feeds too. Working-location entries are left out, and watching the whole account skips Google's own holiday/birthday calendars. days_back (365) leaves out old events.

How: app/domain/google_auth.py is the shared Google sign-in layer (JWT bearer for service accounts, refresh tokens for accounts, access tokens cached in memory, every call a row in the activity ledger, Google's own token endpoint whatever a key file's token_uri says). app/domain/gcal.py maps the Calendar API to files; feeds.py dispatches to it through a small OWN table that other Google sources (Gmail) can join. The connection dialog gets the Google Calendar form.

Motivation and Context

Adeel asked for Google Calendar as a sensor, both by OAuth and service account.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (ruff, prettier, eslint, mypy, tsc clean).
  • I added or updated tests (tests/api/test_google_calendar_source.py against tests/fake_google.py; __tests__/sources-model.test.ts).
  • My change requires documentation updates, and I have updated docs/ accordingly (docs/processing.md, docs/sensors.md).
  • Users need more than the title to understand it, so I wrote it under ## Unreleased in CHANGELOG.md.

Done questions (AGENTS.md)

  • Goal: delivers what the user wanted, merged on green CI. (Merging on green; the one-click consent flow follows in the next PR.)
  • Agents: POST /api/v1/sources with type gcal, browse, watch and import through the same API as every source.
  • Zero setup: nothing new to install (pyjwt, cryptography and httpx are already dependencies).
  • Fewest clicks: one form; the account path gets a Connect button next PR.
  • Configurable: every option is in the connection form with a default; nothing in the setup wizard.
  • Light: a few HTTPS calls per poll; nothing heavy.
  • Private and secure: key and token sealed and write-only; read-only scope; threat model and companions list the new entry point.
  • Cost: no model calls; Google calls are rows in the activity ledger (google.token, google.calendar).
  • User decides: nothing happens until an admin adds a connection; defaults unchanged.
  • Upgrades: n/a, no stored-data shape change (a new source type only).
  • Honest: docs say exactly what is built; the Connect button is labelled as next.
  • Tests, docs and generated files updated (make openapi).
  • Open standards (iCalendar, OAuth 2.0, RFC 7523); no new dependencies.
  • Result reported with evidence; refine later: Google syncToken incremental sync instead of a full list each poll; event attachments; push notifications (events.watch) instead of polling.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CGVfwJfXV4MiUhSyusia64


Generated by Claude Code

… connected Google account

A new source type, gcal, reads Google Calendar through the Calendar API with
read-only access: each calendar is a folder and each event a file
<calendar id>/<event id>.ics, read as text exactly as an iCal feed's events
are, so browsing, choosing events, watching and importing work unchanged.

It signs in as a service account (its key file; acting as a Workspace user
through domain-wide delegation with impersonate) or as a connected Google
account (an OAuth client's authorized user JSON). google_auth.py is the shared
sign-in layer for Google sources: JWT bearer and refresh-token access tokens,
cached in memory, every call to Google a row in the activity ledger, and
Google's own token endpoint whatever a key file says.

Events carry cancelled occurrences (EXDATE) and their video call, which the
event text now shows for iCal feeds too. The web app's connection dialog gains
the Google Calendar form; docs, changelog and threat model describe it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CGVfwJfXV4MiUhSyusia64
# Conflicts:
#	CHANGELOG.md
@adeelahmad adeelahmad self-assigned this Oct 15, 2026
@adeelahmad
adeelahmad merged commit 3b0bc70 into main Oct 15, 2026
11 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-4kmlnn branch October 15, 2026 11:29
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.

2 participants