Skip to content

TD-0011: Time service, chat tools and GNOME recorder

Status: Implemented · Python 3.13 · 15 November 2026

Time shows where a person's hours go. Three sources feed one timeline:

  • Entries are deliberate records ("I did X from A to B"). They come from the web app (source=manual) or the chat agent through MCP tools (source=ai).
  • Desktop spans are "this window had focus" observations uploaded by a GNOME Shell extension.
  • Rules sort desktop spans into categories when a report is read.
flowchart LR
  Web["Web and phone UI"] -->|"entries, timer, rules"| API["loryth-time"]
  Chat["Chat agent"] -->|"MCP tools"| MCP["loryth-mcp"]
  MCP -->|"user bearer"| API
  Ext["GNOME Shell extension"] -->|"appends spans"| Spool["spool.jsonl"]
  Spool -->|"renamed into outbox"| Up["uploader, systemd timer"]
  Up -->|"Device key"| API
  API -->|"timeline and report"| Web

Categories

Categories form two levels, area › activity (Work › Loryth). Reports total leaf categories; the UI and MCP roll them up to areas. Categories are archived, never deleted, so past time keeps its label. POST /categories/resolve finds or creates a category by path, which lets the agent record time in one call. Desktop time that no rule matches is reported as Unsorted.

Entries

Entries share one table for manual and AI records. source and chat_session_id say where an entry came from; both the UI and the agent may edit any entry, guarded by revision.

  • Entries never overlap each other. A conflicting write returns 409 entry_overlap with the conflicting entries. Two deliberate records for the same minute are a mistake to resolve, so the agent asks the user.
  • ended_at = null is a running timer; a partial unique index allows one per user. Starting a timer stops the running one at the new start. For overlap checks a running timer claims all time after its start, so an entry logged a few minutes ahead cannot block stopping the timer later.
  • Writes take a per-user advisory lock before the overlap check, so concurrent creates cannot both pass it.

Desktop spans and rules

Spans are stored as uploaded: device, app_id (for example code.desktop), title, start and end. They never store a category.

Rules are an ordered list matched first-to-last on app_id (exact) and/or a title substring, both case-insensitive. A rule assigns a category or ignores the time. Classification runs on every timeline and report request. A week is a few thousand spans against a few dozen rules, so this stays cheap, and a new rule re-sorts all history without a backfill. To correct one stretch, the Day view turns it into a manual entry, which outranks desktop time.

Timeline merge

For a local date range and IANA timezone, the service loads entries and spans, classifies spans, lets the later-starting span win where two devices overlap, removes desktop time inside entries, and joins same-category desktop pieces separated by less than two minutes. What remains is untracked. GET /timeline returns entries, classified desktop rows and merged segments; GET /report returns totals per category, per source, per day, and the top unsorted apps.

Desktop recorder

In Loryth desktop 0.3.0 or later, Time › Settings › Devices › Record this computer creates a device using the signed-in session and installs both programs from the RPM resources. It requires GNOME Shell 50, Python 3.13 or later, the schema compiler and the systemd user manager. clients/gnome/ holds the two programs.

  • Extension loryth-time@souperk.dev. On GNOME Wayland only Shell code can see the focused window. The extension records focus and title changes, ends a span at the last input when the idle monitor fires, on lock and on suspend, and splits spans every five minutes. Excluded apps, title-hidden apps and private browser windows are filtered before anything is written. Each span is appended to $XDG_STATE_HOME/loryth-time/spool.jsonl with open–append–close.
  • Uploader loryth-time-upload.pyz. Built with make pyz, the standalone standard-library zipapp runs under /usr/bin/python3 from ~/.local/share/loryth-time/. A systemd user timer runs it every minute. It renames the spool into an outbox, uploads files oldest first in batches of 500 to POST /api/v1/time/desktop/spans, and deletes a file after every batch succeeds. The server ignores duplicate span ids, so resending is safe.

The desktop app stages the extension, compiles its schemas, copies the zipapp, and passes the key to configure on stdin. The uploader writes its own 0600 config under $XDG_CONFIG_HOME/loryth-time/. The app installs the user units, reloads systemd and enables the timer, then enables the extension. When Shell has not loaded the extension, the app adds its UUID to GNOME's enabled-extensions string array, preserving other entries. Log out and back in to load it; GNOME presents its own logout confirmation.

The settings card reports an unsupported environment, a required login, a turned-off extension, recording times or uploader failures. Reconnect creates a new device/key after revocation. Turn on reuses the installed key only when the device and server match. Stop recording removes the local installation, then revokes its device. Failed installs revoke their newly created device. At startup a newer packaged extension refreshes the extension, uploader and units without replacing the key; Shell needs another login to load that code.

Network calls and the device key stay outside the Shell process. Device keys are issued by the Time service, shown once and stored as SHA-256 hashes. A key can only add spans for its device; it cannot read data. The ingest path is a public path for the shared sign-in middleware and checks the key itself, so IAM is unchanged.

Chat tools

loryth-mcp publishes list_time_categories, log_time, start_timer, stop_timer, list_time_entries, update_time_entry, delete_time_entry, get_time_report, list_time_rules and create_time_rule. Tools take local times plus an IANA timezone. Overlaps return the conflicting entries so the agent can ask. Reports include category paths and the top unsorted apps so the agent can offer rules.

Privacy

Window titles are the most sensitive data. Titles older than LORYTH_TIME_TITLE_RETENTION_DAYS (default 90) are cleared during uploads; app ids and durations stay. The recorder never captures screenshots, keystrokes or URLs.

Deployment

  • Set DB_PASSWORD_TIME in the private deployment environment before the first deploy. The migration runner creates the time role and database with ensure-service-databases.py.
  • The gateway routes /api/v1/time/ through $time_upstream and does not depend on the Time container, so a missing Time API leaves other apps up.
  • Install Loryth desktop and choose Time › Settings › Record this computer. The RPM includes the extension, systemd units and zipapp and requires python3. There is no separate installer or runtime virtual environment. For manual development steps and removing an old uploader venv, see clients/gnome/README.md.