ui.server¶
Web UI for ground-truth label collection and live prediction monitoring.
The shared runtime classes (ActivityMonitor, _LabelSuggester) live in
taskclf.ui.runtime, while tray-specific orchestration stays in
taskclf.ui.tray.TrayLabeler.
Launch¶
For frontend development with hot reload:
For browser-based full-stack development with frontend HMR plus backend auto-reload:
Options:
| Option | Default | Description |
|---|---|---|
--port |
8741 |
Port for the web server |
--model-dir |
(none) | Model bundle for live predictions |
--aw-host |
http://localhost:5600 |
ActivityWatch server URL |
--poll-seconds |
60 |
Seconds between AW polling |
--title-salt |
taskclf-default-salt |
Salt for hashing window titles |
--data-dir |
data/processed (ephemeral in --dev) |
Processed data directory; omit with --dev for an auto-cleaned temp dir |
--transition-minutes |
3 |
Minutes before suggesting a label change |
--idle-transition-minutes |
1 |
Minutes before a lockscreen/idle transition fires (separate from general transitions) |
--dev |
off | Start Vite dev server for frontend hot reload; in browser mode, the FastAPI backend also runs with auto-reload. Uses an ephemeral data dir unless --data-dir is set |
Panels¶
- Label -- Form with date/time pickers,
CoreLabeldropdown, confidence slider, and user ID input. - Recent -- Quick-label with preset durations (now / 1 / 5 / 10 / 15 / 30 / 60 min) or a custom duration input supporting seconds, minutes, hours, and days. "now" labels the span from the last label's
end_tsto the current moment (falling back to 1 minute if no last label exists or the span would be < 1 minute); the button dynamically shows the duration (e.g. "now (12m)"). Other values label the corresponding trailing window. The "Extend until next label" checkbox (on by default) setsextend_forward=trueon the new label; when the next label is created, this label'send_tsis automatically stretched to meet the next label'sstart_ts, producing contiguous coverage without gaps. For a zero-duration "now" label withextend_forward=true, the server performs a same-timestamp handoff by ending the currently active same-user label atnow, then creating the new open-ended label atnow, so no overlap dialog is needed in the common switch-label-now flow. The History view immediately renders the new span as open-ended (start – Now, durationuntil next label) so users get instant confirmation that the label was recorded before the next label closes the span. Shows a live ActivityWatch summary when available. The footer switches between a compact "Last: Label Nm ago" summary for completed labels and "Current: Label since Nm ago" for any label whoseextend_forwardcoverage is still active. Quick-label keeps those two notions separate:GET /api/labels/currentdetects the activeextend_forwardlabel that drives the footer and Stop current label control, whileGET /api/labels?limit=1still returns the span with the latestend_tsfirst for gap-fill and "last ended" behavior, including when overlapping spans exist (allow_overlap). That keeps the stop action visible for running labels even if some completed overlapping span ends later. When a current label is active, the footer offers a two-step Stop current label action that closes the running span at the moment the user confirms, without deleting the label that has already been recorded. This applies both to zero-duration "from now" labels and to earlier backfilled spans that were saved withextend_forward=trueand are still the active label. On success, the compact badge immediately drops the stale manual label and falls back to the latest passive live-status label from the model. The gap shortcut is hidden while a currentextend_forwardlabel is active so the quick-label surface does not imply there is unlabeled time to backfill. When the last completed label is shown, the gap button (e.g.gap 5m) reflects unlabeled time since that label’send_tsand refreshes on a ~30s wall-clock tick so the duration stays current while the window stays open. After a successful label, a brief "Saved" flash appears (click to dismiss instantly); the grid stays open for rapid consecutive labeling. Non-overlap quick-label failures now render a persistent inline error banner with Copy error and Close actions instead of auto-dismissing after a timeout. On overlap errors, instead of a dead-end flash the grid shows a compact confirmation prompt listing the conflicting label names (e.g. "Overlaps 3 labels: Write, Debug, Review") with the affected time range shown below (e.g. "(10:50–11:20 will be replaced)"), plus Overwrite/Keep All/Cancel buttons. For a single conflict the per-span time range is shown inline; for multiple conflicts a "show details" toggle reveals per-span times. Choosing Overwrite re-submits the label withoverwrite: true, which truncates, splits, or removes the conflicting existing span(s) to make room for the new label. Choosing Keep All re-submits withallow_overlap: true, preserving all existing and new labels on the overlapping time range. IflastLabelchanges while the prompt is visible (e.g. from another tab or WebSocket), the prompt is automatically dismissed since the conflict data may be stale. - Queue -- Pending
LabelRequestitems sorted by confidence (lowest first). Shows time range, predicted label, confidence, and reason.
Live Features¶
- Live badge (compact) -- Header pill showing the current label/app and connection dot. Visible in the collapsed tray window. When a
suggest_labelevent arrives, the compact badge immediately switches to the suggested label as a frontend-only display override. If the suggestion is skipped, the pill restores the pre-suggestion display; if the suggestion is accepted, the pill keeps the accepted suggestion until a fresherpredictionorlive_statusupdate supersedes it. - State panel -- Tabbed panel with three views, selected via a segmented control at the top:
- System tab -- Internal-state debug panel with a collapsible accordion layout: each section header shows an inline summary badge (e.g., current app, predicted label, connection status) so all states are scannable at a glance. Click any header to expand its detail rows. Activity Monitor and Last Prediction default to open; all other sections start collapsed. Eight sections:
- Activity Monitor -- summary:
state · current_app. Details:state,current_app,since,poll_interval,poll_count,last_polltimestamp,uptime. When a transition candidate exists:candidate_app,candidate_progresswith duration/threshold/percentage and a visual progress bar. - Last Prediction -- summary:
mapped_label confidence%. Details:label,mapped_label,confidence(color-coded green/red at 50% threshold),ts,trigger_app. - Model -- summary:
loaded/not loaded(color-coded). Details:loadedstatus,model_dir,schema_hash,suggestedlabel,suggestion_conf. When a model is loaded and the tray exposesmodel_dir, the panel also shows bundle-saved validation metrics (val_macro_f1,val_weighted_f1, training range, top confusion pairs) fromGET /api/train/models/current/inspect— static metrics on disk, not a live replay of the test split. - Transitions -- summary: transition count. Details:
totalcount, last transition details:prev → newapps,blocktime range,fired_attimestamp. - Active Suggestion -- appears when the model suggests a label on transition. Summary:
suggested confidence%. Details:suggested,confidence,reason,old_label,blocktime range. - Activity Source -- summary: provider
state(checking,ready,setup required) with provider-neutral diagnostics. Details: provider name, endpoint, resolvedsource_id,last_sample_count, last-sample app distribution, and a setup callout when the configured source is unavailable. The setup callout is intentionally non-blocking: manual label creation, editing, and suggestion accept/skip flows remain enabled even when summaries are unavailable. - WebSocket -- summary: connection status (color-coded). Details:
status,messagestotal, per-typebreakdown(st/pred/tray/sug),last_receivedtimestamp,reconnectscount,connected_since. - Config -- summary:
dev/prod. Details:data_dir,ui_port,dev_mode,labels_savedcount.
- Activity Monitor -- summary:
- Training tab -- Model training interface with data readiness checks, a training form (date range, boost rounds, class weight, synthetic toggle), real-time progress via WebSocket, result display (macro/weighted F1), and a model bundle list. Each bundle row can expand Bundle metrics to lazy-load the same bundle-saved validation inspection as
GET /api/train/models/{model_id}/inspect. Validation/start/cancel failures and failed-run messages use the same persistent inline error banner with Copy error and Close controls. See training.md for endpoint details. - History tab -- Single-day view with date navigation (prev/next arrows and a date picker). Shows a full-day timeline strip (00:00–23:59) with color-coded labeled segments and clickable unlabeled gaps. Click any label row to expand an inline editor showing the ActivityContext for that time window (apps used, input stats), a label-change grid (current label highlighted), and a delete button with confirmation. Label time edits are minute-based and use end-exclusive semantics (
15:00-15:01means one minute); equal start/end values (15:00-15:00) are rejected. Row display stays compact atHH:MM, but includes seconds when either boundary has non-zero seconds. Click any unlabeled gap row to expand an inline editor with time range inputs (pre-filled to the gap boundaries, adjustable to label a sub-range), ActivityContext for the selected range, and a label picker grid; selecting a label creates a new label span for the chosen sub-range. Navigating to a past date with no labels shows the entire day as a single labelable gap. The active date refetches immediately onlabels_changedWebSocket events, so manual labels, accepted suggestions, edits, deletes, and imports appear without requiring a tab switch. Provides a dedicated review surface separate from the quick-label popup, with the full panel height available for browsing. - Suggestion banner -- When present, it is shown at the top of the label column (above the duration/time picker and the rolling activity summary) so the model prompt is visible first. It appears when a new inferred label arrives from
suggest_label. The banner shows the current label, suggested label, confidence, and the applicable block time range (block_start->block_end), using a compact local-time display and adding the date when the suggested range crosses midnight locally. Below that, an inline activity summary for that same range reuses the same surface as the main label panel (ActivitySummaryviaGET /api/activity/summary): top apps, input-rate hints when available, and bucket/session coverage. If the configured activity source is unavailable, the banner shows the same non-blocking setup callout used elsewhere; if the range is simply empty, it showsNo activity data for this window. Label names use the same color cues as the label grid. ClickingUse suggestionimmediately writes the suggested label to label history. When that suggestion lands inside the effective coverage of the currentextend_forwardlabel, the backend automatically splits the running label into a before-fragment and a resumed open-ended fragment after the suggestion so the active label continues past the suggested block. Other same-user overlaps still use the same Overwrite All / Keep All / Cancel prompt as quick-labeling; retries usePOST /api/notification/acceptwithoverwriteorallow_overlapso the span staysprovenance="suggestion".Skipcalls the notification-skip flow without creating labels. Manual quick-label saves (POST /api/labels) do not dismiss the banner; it clears when the suggestion is accepted, skipped, or cleared by tray-side auto-save paths. The compact badge mirrors the suggestion immediately while the banner is present, reverts to its pre-suggestion display on skip, and stays on the accepted suggestion until a fresher explicit badge signal arrives. Optional client auto-dismiss is configured bysuggestion_banner_ttl_secondsinconfig.toml(see core/config.md andGET /api/config/user);0disables the timer. Save/skip failures surface as persistent inline errors with Copy error and Close actions rather than disappearing on a timer. - Auto-save BreakIdle -- When a completed activity block is detected as idle (lockscreen app was dominant, or the model suggested
BreakIdle), the tray auto-saves the label withprovenance="auto_idle"and publishes alabel_createdevent. No user confirmation is required since the user was away. Lockscreen/idle transitions use a separate, faster threshold (idle_transition_minutes, default 1 min) so breaks are detected quickly without affecting the general transition cadence (transition_minutes, default 2 min). The fast threshold applies in both directions: when the lockscreen app becomes dominant, and when the user returns from lockscreen. Matching uses normalized app IDs:com.apple.loginwindow(macOS),com.microsoft.LockApp/com.microsoft.LogonUI(Windows),org.gnome.ScreenSaver,org.gnome.Shell,org.i3wm.i3lock,org.swaywm.swaylock,org.jwz.xscreensaver,org.freedesktop.light-locker,org.suckless.slock(Linux).
Architecture¶
The UI is a SolidJS single-page application served by a FastAPI backend:
- REST endpoints (
/api/labels,/api/labels/export,/api/labels/import,/api/labels/stats,/api/queue,/api/features/summary,/api/activity/summary,/api/aw/live,/api/config/labels,/api/config/user,/api/tray/pause,/api/tray/state,/api/train/*) handle label CRUD, import/export, stats, queue management, user configuration, tray control, model training, and data queries. See training.md for the/api/train/*endpoints (including bundle-only model inspection under/api/train/models/.../inspect). GET /api/labelsaccepts optionallimit(default 50, max 500),date(ISO-8601 date string, e.g.2025-03-07), and optionalrange_start/range_end(ISO-8601 UTC bounds) query parameters. After filters are applied, results are sorted byend_tsdescending (latest-ended first). Whendateis provided, only labels overlapping that day are returned. The History tab uses this to fetch labels for the selected date.GET /api/labels/currentreturns the most recently started label whoseextend_forwardcoverage still contains "now", ornullwhen none exists. That includes zero-duration "from now" labels (start_ts == end_ts) and earlier spans saved withextend_forward=truewhen no later same-user label has ended that coverage yet. Quick-label uses this endpoint for the footer's current badge and stop action, so the active label remains discoverable even whenGET /api/labelsis ordered by latestend_ts.POST /api/labelsaccepts optionalextend_forward,overwrite, andallow_overlapbooleans.extend_forwardpersists the label withextend_forward=true; when the next label is created for the same user, this label'send_tsis automatically stretched to the new label'sstart_ts, producing contiguous coverage. For zero-durationextend_forwardlabels (start_ts == end_ts, used by "label from now"), the server first truncates the currently active same-user span at that same timestamp, then appends the new label, ensuring a contiguous no-overlap handoff. The quick-label UI sets this flag by default. Before overlap checks, same-user boundaries within 1 ms are snapped together so timestamps that passed through JavaScriptDatedo not fail with false microsecond overlaps. Whenoverwriteistrue, conflicting same-user spans are truncated, split, or removed to make room for the new label (no 409 is returned). Whenallow_overlapistrue, the overlap check is skipped entirely and multiple labels are allowed to coexist on the same time range; this is useful for multi-task periods. When both arefalse(default), an overlap returns 409 with structured conflict details:{"detail": {"error": "...", "conflicting_start_ts": "...", "conflicting_end_ts": "..."}}so the frontend can prompt the user to overwrite or keep all.PUT /api/labelschanges the label on an existing span identified bystart_ts+end_ts. Optionalnew_start_ts,new_end_ts, andextend_forwardfields can also change the time range and running/current state. The quick-label "Stop current label" action usesnew_end_ts=<click time>withextend_forward=falseto close the active label without deleting it. Returns 404 if no matching span exists.DELETE /api/labelsremoves a span identified bystart_ts+end_ts. Returns 404 if no matching span exists.GET /api/labels/exportdownloads all label spans as a CSV file (text/csv). Returns 404 if no labels file exists or the file contains no spans.POST /api/labels/importaccepts a multipart CSV file upload (file) and an optionalstrategyform field ("merge"or"overwrite", default"merge"). In merge mode, imported spans are deduplicated against existing labels by(start_ts, end_ts, user_id)and overlap-checked; conflicts return 409. In overwrite mode, all existing labels are replaced. Returns{"status": "ok", "imported": N, "total": M, "strategy": "merge"|"overwrite"}. Returns 422 on invalid CSV or strategy.GET /api/labels/statsreturns labeling statistics for a given day. Accepts an optionaldatequery parameter (ISO-8601 date string, defaults to today UTC). Returns{"date": "2026-03-01", "count": 5, "total_minutes": 75.0, "breakdown": {"Build": 45.0, "Meet": 20.0, "Write": 10.0}}.GET /api/activity/summaryis the frontend-facing activity summary endpoint. Query params:start,end(ISO-8601). It returns the usual aggregate stats plusactivity_provider,recent_apps,range_state, andmessage.range_state="ok"means summary data exists,range_state="no_data"means the source is reachable but the requested window is empty, andrange_state="provider_unavailable"means the configured source is not ready and the response includes setup guidance. Manual labeling remains available regardless ofrange_state.POST /api/tray/pausetoggles the monitoring pause state. Returns{"status": "ok", "paused": true/false}when connected to a tray, or{"status": "unavailable", "paused": false}when no tray callbacks are configured.GET /api/tray/statereturns tray availability and pause state. When the tray backend providesget_tray_state, the payload may also includemodel_dirandmodels_dir(each a string path ornull).models_diris set when--models-diris configured so clients (e.g. Electron) can enable Advanced → Edit Inference Policy.POST /api/notification/acceptconfirms an inferred label suggestion and writes it tolabels.parquetwithprovenance="suggestion". Required body:{"block_start": "...", "block_end": "...", "label": "..."}. Optionaloverwriteandallow_overlapbooleans matchPOST /api/labels. When the suggested block falls inside the effective coverage of the current same-userextend_forwardlabel, the server automatically uses overwrite-style splitting so the prior label resumes after the accepted suggestion. Other overlaps still return 409 with the same structured conflict details as manual labeling, and the UI can retry withoverwrite=trueorallow_overlap=truewithout changing provenance.POST /api/notification/skipdismisses the current suggestion without saving a label and broadcastssuggestion_clearedwith reason"skipped"so all connected clients clear the prompt.- WebSocket (
/ws/predictions) streams live events from the ActivityMonitor: status-- every poll cycle:state("collecting"or"paused"),current_app,current_app_since,candidate_app,candidate_duration_s,transition_threshold_s,poll_seconds,poll_count,last_poll_ts,uptime_s, and nestedactivity_provider(provider_id,provider_name,state,summary_available,endpoint,source_id,last_sample_count,last_sample_breakdown,setup_title,setup_message,setup_steps,help_url). Legacyaw_connected,aw_bucket_id,aw_host,last_event_count, andlast_app_countsare still emitted temporarily as compatibility aliases. When monitoring is paused,stateis"paused"and polling/transition detection is skipped.tray_state-- every poll cycle:model_loaded,model_dir,model_schema_hash,suggested_label,suggested_confidence,transition_count,last_transition(withprev_app,new_app,block_start,block_end,fired_at),labels_saved_count,data_dir,ui_port,dev_mode,paused.initial_app-- once on startup when the first dominant app is detected:app,ts. Allows the UI to prompt the user to label the pre-start period that would otherwise be unlabeled.prediction-- on app transition with model suggestion:label,confidence,ts,mapped_label,current_app. Reserved for actual model outputs; manual labels no longer use this event type.no_model_transition-- on app transition without a loaded model:current_app,ts,block_start,block_end. The frontend uses this to distinguish "no model loaded" from "model predicted unknown";LiveBadgeshows "No Model" instead of "Unknown Label" whentrayState.model_loaded === false.label_created-- when a label withextend_forward=trueis created viaPOST /api/labels, or when the tray auto-saves aBreakIdlelabel (lockscreen/idle detection):label,confidence,ts(end),start_ts,extend_forward. The frontend maps this to aPrediction-compatible object soLiveBadgeandStatePanelupdate automatically.label_stopped-- when an open-ended running label is closed viaPUT /api/labels:ts(the new end timestamp). Clients clear any stale manual badge prediction at or before that timestamp, then fall back to the latestlive_statuslabel if available.labels_changed-- on any label-history mutation that should invalidate day views:reason,ts. Published afterPOST /api/labels,PUT /api/labels,DELETE /api/labels,POST /api/labels/import,POST /api/notification/accept, and tray-side auto-savedBreakIdlelabels.suggestion_cleared-- published after successful suggestion acceptance (POST /api/notification/accept), dismissals (POST /api/notification/skip), and auto-saved BreakIdle labels:reason(e.g."label_saved","skipped","auto_saved_breakidle"). ManualPOST /api/labelssaves do not publish this event. Clients clear the active suggestion on receipt. The compact badge treats"skipped"as a restore-to-previous-display signal; accepted/auto-saved clears keep the assumed suggestion visible until a fresherpredictionorlive_statusevent arrives. The frontend may also auto-dismiss aftersuggestion_banner_ttl_secondsfromconfig.toml(viaGET /api/config/user);0disables that timer.suggest_label-- on app transition with model suggestion:suggested,confidence,reason,old_label,block_start,block_end.prompt_label-- on task transition with labeling prompt:prev_app,new_app,block_start,block_end,duration_min,suggested_label,suggestion_text. The structuredblock_start/block_endbounds remain UTC; the human-readablesuggestion_textrange is rendered in the user's local timezone for notification display. Frontend notification surfaces may also derive a second exact local-time range line directly fromblock_start/block_endfor higher-precision display.label_grid_show-- triggered byPOST /api/window/show-label-grid:type("label_grid_show", no other fields).train_progress-- during training:job_id,step,progress_pct,message.train_complete-- on training success:job_id,metrics(macro_f1,weighted_f1),model_dir.train_failed-- on training failure:job_id,error.unlabeled_time-- every poll cycle when unlabeled time exists:unlabeled_minutes,text,last_label_end,ts.gap_fill_prompt-- at idle return (>5 min), session start, or post-acceptance:trigger,unlabeled_minutes,text,last_label_end,ts.gap_fill_escalated-- when unlabeled time exceeds threshold:unlabeled_minutes,threshold_minutes.
Backpressure policy: Each WebSocket subscriber has a 256-event queue. When the queue is full, the oldest event is evicted to make room for the new one. The subscriber is never silently dropped; it continues receiving events at the cost of missing stale ones.
Timestamp format: All ISO-8601 timestamps emitted by the server (REST responses and WebSocket events) include an explicit UTC timezone suffix (+00:00). Incoming timestamps in request bodies are accepted with or without timezone info and normalized to timezone-aware UTC via ts_utc_aware_get(). All internal comparisons, filters, and storage operations use aware UTC. Legacy naive timestamps in existing Parquet files are treated as UTC and normalized to aware UTC on read.
Privacy¶
The UI never displays raw window titles, keystrokes, or URLs.
Only aggregated metrics and application identifiers are shown.
Transition notifications (web and desktop fallback) redact app names by default
(privacy_notifications=True); set to False to show raw app identifiers.
Desktop fallback notifications can be disabled entirely with notifications_enabled=False.
taskclf.ui.server
¶
FastAPI backend for the taskclf labeling web UI.
Provides REST endpoints for label CRUD, queue management, feature summaries, and model training, plus a WebSocket channel for live prediction streaming and training progress.
create_app(*, data_dir=Path(DEFAULT_DATA_DIR), models_dir=None, aw_host=DEFAULT_AW_HOST, title_salt=DEFAULT_TITLE_SALT, event_bus=None, window_api=None, on_label_saved=None, on_model_trained=None, on_suggestion_accepted=None, pause_toggle=None, is_paused=None, tray_actions=None, get_tray_state=None, get_activity_provider_status=None)
¶
Build and return the FastAPI application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
Path
|
Path to the processed data directory. |
Path(DEFAULT_DATA_DIR)
|
models_dir
|
Path | None
|
Path to the directory containing model bundles. |
None
|
aw_host
|
str
|
ActivityWatch server URL. |
DEFAULT_AW_HOST
|
title_salt
|
str
|
Salt for hashing window titles. |
DEFAULT_TITLE_SALT
|
event_bus
|
EventBus | None
|
Shared event bus for WebSocket broadcasting. |
None
|
window_api
|
Any
|
Optional |
None
|
on_label_saved
|
Callable[[], None] | None
|
Optional callback invoked after a label is
successfully saved (via |
None
|
on_model_trained
|
Callable[[str], None] | None
|
Optional callback invoked with the model run directory path after training completes successfully. |
None
|
on_suggestion_accepted
|
Callable[[], None] | None
|
Optional callback invoked after a
transition suggestion is accepted via
|
None
|
pause_toggle
|
Callable[[], bool] | None
|
Optional callback to toggle pause state; returns new paused boolean. |
None
|
is_paused
|
Callable[[], bool] | None
|
Optional callable returning current paused state. |
None
|
tray_actions
|
dict[str, Callable[..., Any]] | None
|
Optional mapping of action names to callbacks for the tray menu. |
None
|
get_tray_state
|
Callable[[], dict[str, Any]] | None
|
Optional callable returning the full tray state dictionary. |
None
|
get_activity_provider_status
|
Callable[[], dict[str, Any]] | None
|
Optional callable returning the latest cached activity-source status snapshot from the runtime monitor. |
None
|
Source code in src/taskclf/ui/server.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 | |
ui.tray¶
System tray labeling app for continuous background labeling.
Launch¶
taskclf tray
taskclf tray --model-dir models/run_20260226
taskclf tray --username alice
taskclf tray --retrain-config configs/retrain.yaml
taskclf tray --dev
Features¶
- System tray icon -- runs persistently in the background via pystray.
- In-process web UI server -- the FastAPI server always runs in-process, sharing the tray's
EventBus. In--browsermode the dashboard opens in the default browser; otherwise a lightweight pywebview subprocess provides a native floating window. Both modes receive the same live events (status,tray_state,prompt_label,suggest_label,prediction) because the server and the tray publish/subscribe on the sameEventBusinstance. To keep cold starts responsive, the HTTP server is started before optional model loading finishes, so the dashboard can appear while suggestions are still warming up. Browser-only startup imports the sharedtaskclf.ui.runtimehelpers instead of the tray icon module, so it does not pull Pillow/pystray into that import path. Parquet/pandasI/O is loaded lazily inside label, feature-summary, and training-related handlers so the initial import path stays lighter than the full data stack. - Activity transition detection -- polls ActivityWatch and detects when the dominant foreground app changes. A transition fires when the new app persists for >=
--transition-minutes(default matchesDEFAULT_TRANSITION_MINUTES, currently 2 minutes). On the first poll, aninitial_appevent is published so the UI can prompt labeling for the pre-start period. - Pause/resume -- monitoring can be paused via the tray menu ("Pause"/"Resume") or the
POST /api/tray/pauseREST endpoint. When paused, polling and transition detection are skipped but session state (poll count, transitions) is preserved. Thestatusevent emitsstate: "paused"and thetray_stateevent includespaused: true. - Transition notifications -- on each transition, a notification prompts the user to label the completed block. Plain browser mode uses the Web Notifications API (driven by the
prompt_labelWebSocket event and requested when the route mounts). Native shells stay on native notification paths: Electron shows an OS notification with action buttons, and the legacy pywebview shell forwards the sameprompt_labelevent throughWindowAPI.show_transition_notification()so suggestions still raise a desktop notification even when the embedded webview does not expose the browser Notification API. User-facing time ranges in notification copy are displayed in the local timezone, while the structured event timestamps remain UTC. Notification bodies include an exact local start/end range line derived fromblock_start/block_endfor precise review. Standalone label/panel windows reuse the same prompt event path as the compact shell, and the frontend de-dupes each transition by block range so multiple subscribed windows do not alert twice for the same prompt. On supported Web Notifications runtimes, transition prompts request persistent display (requireInteraction) so they stay visible until dismissed or clicked instead of auto-closing immediately. In the Electron shell, transition prompts use a native notification path with action buttons on supported platforms: when a model suggestion exists the notification offersAccept,Review, andSkip, while clicking the notification body also opens the labeler; without a suggestion, the native action isReview. The pywebview native path uses privacy-safe copy (suggestion_textwhen present, otherwiseActivity changed) plus the exact local range line; it does not expose raw app names. By default, app names are redacted for privacy (privacy_notifications=True). Setprivacy_notifications=Falseto show raw app identifiers. Desktop fallback notifications can be disabled entirely withnotifications_enabled=False. - Label suggestions -- when
--model-diris provided, the app predicts a label and includes it in the notification. Without a model, all 8 core labels are shown. On startup, model loading is deferred until after the embedded UI server begins listening, sotray_state.model_loadedmay briefly remainfalseduring cold-start while the suggester loads in the background. The shared_LabelSuggesterruntime helper propagates the stable config-backeduser_id(fromUserConfig) tobuild_features_from_aw_eventsso the model receives the same personalization signal used during training. When no config is available, falls back to"default-user". Input events (keyboard/mouse statistics fromaw-watcher-input) are also fetched and passed to feature building so that input-derived features (keys_per_min,clicks_per_min, etc.) are populated rather than left asNone. - Quick labeling -- preset durations and the label grid live in the web UI (for example the Recent panel), not in the pystray right-click menu. Use Toggle Dashboard to open the UI.
- Today's Labels -- tray menu action that shows a desktop notification summarizing today's labeling progress: total label count, total time, and per-label breakdown (e.g. "Today: 5 labels, 1h 35m -- Build 1h 5m, Debug 20m, Write 10m"). Counts use the UTC calendar day. Also available via
GET /api/labels/statsfor programmatic access. - Import Labels -- tray menu action that imports label spans from a CSV file. Opens a file-open dialog (via tkinter) to choose the source CSV, then prompts the user to merge with existing labels or overwrite them. Falls back to native macOS file dialogs (via osascript) when tkinter is unavailable or fails (e.g. threading conflicts with the pystray event loop). Merge deduplicates by
(start_ts, end_ts, user_id)and rejects overlapping spans; overwrite replaces all labels. Also available viaPOST /api/labels/importfor programmatic access. - Export Labels -- tray menu action that exports all label spans to a CSV file. Opens a save-file dialog (via tkinter) to choose the destination; falls back to
<data_dir>/labels_v1/labels_export.csvwhen tkinter is unavailable. Also available viaGET /api/labels/exportfor programmatic access. - Show Status -- tray menu action that shows a desktop notification with connection and session status: ActivityWatch connection state, poll count, transition count, saved labels count, and loaded model name.
- Open Data Folder -- tray menu action that opens the data directory in the OS file manager (Finder on macOS,
xdg-openon Linux). Falls back to a notification showing the path if the file manager cannot be launched. - Edit Config -- tray menu action that opens
config.tomlin the default text editor. On first run, if the file is missing, taskclf writes a full commented starter template once (all supported keys); existing files are not regenerated on later startups. Resolved runtime settings are not rewritten on every launch; values from this file are read at startup, and explicit non-default CLI flags override file values for that run. Changes from the web UI (for example username or suggestion banner TTL via/api/config/user) merge intoconfig.toml. See User config template andconfigs/user_config.template.toml. Existingconfig.jsonfiles are auto-migrated to TOML whenconfig.tomlis absent. - Edit Inference Policy -- under the tray Advanced submenu; opens
models/inference_policy.jsonin the default text editor (disabled when--models-diris not set). If the file is missing, it is created first only when the currently loaded/resolved model bundle can seed it, reusingmetadata.json's advisoryreject_thresholdand auto-attaching a matchingartifacts/calibrator_storewhen itsstore.jsonis explicitly bound to that model. If no model can be resolved, the tray does not write a placeholder file; instead it notifies you to use Prediction Model or Open Data Folder (themodels/folder sits next to your data directory), and mentions the optional CLI commandtaskclf policy create --model-dir models/<run_id>for users who have the CLI installed. The canonical starter shape still lives inconfigs/inference_policy.template.json; see Inference policy template. Unlikeconfig.toml, this file is not auto-created on first run—only when you use this action with a resolvable model or create it via the CLI. Invalid hand-edits may cause inference to fall back toactive.jsonresolution until the file parses again. - Report Issue -- tray menu action that opens the GitHub issue tracker (
https://github.com/fruitiecutiepie/taskclf/issues/new) in the default browser, pre-filled with thebug_report.ymltemplate and version/OS diagnostics as query parameters. The user controls what information is submitted; no data is sent automatically. - Prediction Model submenu -- a Prediction Model submenu listing all valid model bundles found in
--models-dir(defaultmodels/). The submenu auto-refreshes on every menu open by re-scanning the models directory, so new bundles created by retraining appear immediately without restarting the tray. The currently loaded model shows a check mark (radio-button effect). Clicking a different bundle hot-swaps the in-memory suggester without restarting. A No Model entry unloads the model entirely. The submenu also contains Refresh Model (reloads via inference policy when configured, otherwise re-reads the active bundle from disk) and Retrain Status to run the retrain eligibility check. When--models-diris missing or empty, a disabled No Models Found placeholder is shown. - Retrain Status -- tray menu action (inside the Prediction Model submenu) that checks whether retraining is due based on the latest model's age and the configured cadence. Shows a notification with "Retrain recommended" (with model name and creation date) or "Model is current". Uses
--retrain-configto load a custom retrain YAML config; falls back to defaults when not provided. Disabled when--models-diris not set. - Tray menu order (pystray) -- Toggle Dashboard, Pause / Resume, Show Status; then Today's Labels, Import Labels, Export Labels; then Prediction Model (submenu), Open Data Folder, Edit Config, Advanced (submenu: Edit Inference Policy), Report Issue; then Quit. Left-click opens or toggles the dashboard depending on mode; right-click shows this menu.
- Shell UI parity -- The compact badge route in a normal browser tab uses a light solid page background and right-aligned in-page label/panel popups with hover, pin, and 300 ms delayed hide so it feels closer to the packaged Electron shell.
Host.invokeis still a no-op without a host bridge. The?view=labeland?view=panelroutes match native popup markup. Use the pywebview floating window,taskclf electron, or Electron dev with the sidecar backend for full multi-window behavior. - Gap-fill surface -- tracks unlabeled time since the last confirmed label and publishes
unlabeled_timeevents every poll cycle (passive badge). Activegap_fill_promptevents are published only at idle return (>5 min), session start, or immediately after accepting a transition suggestion. When unlabeled time exceedsgap_fill_escalation_minutes(default 480), the tray icon changes to orange (gap_fill_escalatedevent). No popup or notification is sent on escalation. - Event broadcasting -- publishes
status,tray_state,initial_app,prediction,label_created,labels_changed,suggest_label,unlabeled_time,gap_fill_prompt, andgap_fill_escalatedevents to the shared EventBus for connected WebSocket clients. - Frontend log channel -- in frontend dev mode (
--dev), debug/error messages emitted in the SolidJS app can be forwarded throughwindow.pywebview.api.frontend_debug_log(...)andwindow.pywebview.api.frontend_error_log(...). Debug lines are written at DEBUG level (requires DEBUG logging enabled, e.g. global--verbose), while error lines are written at ERROR level. The app also installs globalwindow.onerrorandunhandledrejectionhandlers in dev mode so uncaught frontend failures are captured and forwarded via the same error channel. - Crash handler --
TrayLabeler.run()wraps the main loop in a top-leveltry/except. On unhandled exceptions, a crash report is written to<TASKCLF_HOME>/logs/crash_<YYYYMMDD_HHMMSS>.txtand a desktop notification is attempted with the crash file path. See core.crash for details.
Surface Architecture¶
The tray implements three distinct UI surfaces with separate code paths, interaction patterns, and confidence profiles (Decision 6):
| Surface | Method | Event type | Copy function | Trigger |
|---|---|---|---|---|
| Transition suggestion | _handle_transition |
prompt_label |
transition_suggestion_text |
App transition |
| Live status | _publish_live_status |
live_status |
live_status_text |
Every poll cycle |
| Gap-fill indicator | _publish_unlabeled_time |
unlabeled_time |
gap_fill_prompt |
Every poll cycle (passive) |
| Gap-fill prompt | _publish_gap_fill_prompt |
gap_fill_prompt |
gap_fill_prompt |
Idle return / session start / post-acceptance |
| Gap-fill escalation | _check_escalation |
gap_fill_escalated |
— | Unlabeled time exceeds threshold |
- Transition suggestions aggregate all buckets in the completed interval
via
infer.aggregation.aggregate_intervaland display an action-oriented prompt with a concrete local-time range (e.g. "Was this Coding? 12:00–12:47"). - Live status predicts only the current single bucket and publishes a passive present-tense label ("Now: Coding").
- Gap-fill indicator is a passive badge showing total unlabeled time
since the last confirmed label. Published every poll cycle as an
unlabeled_timeevent. Does not interrupt the user. - Gap-fill prompt is an active prompt published only at three defined trigger points: idle return (>5 min idle), session start, or immediately after the user accepts a transition suggestion.
- Gap-fill escalation fires when unlabeled time exceeds a configurable
threshold (
gap_fill_escalation_minutes, default 480 = one active day). Changes the tray icon color to orange. No popup or notification is sent. - Numeric confidence is never shown to the user on transition or live status surfaces.
- All user-facing copy strings are centralized in
ui.copy.
Gap-fill events¶
Three new WebSocket event types support the gap-fill surface:
unlabeled_time— published every poll cycle when unlabeled time exists:unlabeled_minutes,text(human-readable badge text),last_label_end,ts.gap_fill_prompt— published at idle return, session start, or post-acceptance:trigger("idle_return","session_start", or"post_acceptance"),unlabeled_minutes,text,last_label_end,ts.gap_fill_escalated— published when unlabeled time exceeds the escalation threshold:unlabeled_minutes,threshold_minutes.
The gap_fill_escalation_minutes setting (default 480) controls when
escalation fires. It is a user-facing config unlike the reject threshold.
Privacy¶
Same guarantees as the web UI: no raw window titles or keystrokes are displayed or stored. Desktop notifications redact app names by default.
Shared monitor and suggestion helpers are documented in ui.runtime.
taskclf.ui.tray
¶
System tray labeling app: persistent background labeler with activity transition detection.
Launch with::
taskclf tray
taskclf tray --model-dir models/run_20260226
Runs a pystray icon in the system tray that:
- Polls ActivityWatch for the current foreground app
- Detects activity transitions (dominant app changes persisting >= N minutes)
- Sends desktop notifications prompting the user to label completed blocks
- Left-click opens the web dashboard; labeling is done through the web UI
- Publishes prediction/suggestion events to a shared EventBus for the web UI
TrayLabeler
dataclass
¶
System tray icon with labeling menus and notification support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
Path
|
Path to the processed data directory (for label storage). |
(lambda: Path(DEFAULT_DATA_DIR))()
|
model_dir
|
Path | None
|
Optional path to a model bundle for label suggestions. |
None
|
models_dir
|
Path | None
|
Optional path to the directory containing all model bundles. When set, the tray builds a dynamic "Prediction Model" submenu listing available bundles for hot-swapping. |
None
|
aw_host
|
str
|
ActivityWatch server URL. |
DEFAULT_AW_HOST
|
title_salt
|
str
|
Salt for hashing window titles. |
DEFAULT_TITLE_SALT
|
poll_seconds
|
int
|
Seconds between AW polls. |
DEFAULT_POLL_SECONDS
|
transition_minutes
|
int
|
Minutes for transition detection threshold. |
DEFAULT_TRANSITION_MINUTES
|
event_bus
|
EventBus | None
|
Optional shared event bus for broadcasting events. |
None
|
ui_port
|
int
|
Port for the embedded UI server. |
8741
|
open_browser
|
bool
|
When |
True
|
Source code in src/taskclf/ui/tray.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 | |
run()
¶
Start the tray icon and background monitor. Blocks until quit.
Source code in src/taskclf/ui/tray.py
run_tray(*, model_dir=None, models_dir=None, aw_host=DEFAULT_AW_HOST, poll_seconds=DEFAULT_POLL_SECONDS, aw_timeout_seconds=DEFAULT_AW_TIMEOUT_SECONDS, title_salt=DEFAULT_TITLE_SALT, data_dir=Path(DEFAULT_DATA_DIR), transition_minutes=DEFAULT_TRANSITION_MINUTES, event_bus=None, ui_port=8741, dev=False, browser=False, no_tray=False, open_browser=True, username=None, notifications_enabled=True, privacy_notifications=True, retrain_config=None)
¶
Launch the system tray labeling app.
Always starts the FastAPI server in-process so the tray's
EventBus is shared with WebSocket clients. In browser mode
the dashboard opens in the default browser; otherwise a lightweight
pywebview subprocess provides the native floating window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_dir
|
Path | None
|
Optional path to a trained model bundle. When provided, the tray suggests labels on activity transitions. |
None
|
models_dir
|
Path | None
|
Optional path to the directory containing all model bundles. Enables the "Prediction Model" submenu for hot-swapping. |
None
|
aw_host
|
str
|
ActivityWatch server URL. |
DEFAULT_AW_HOST
|
poll_seconds
|
int
|
Seconds between AW polling cycles. |
DEFAULT_POLL_SECONDS
|
aw_timeout_seconds
|
int
|
Seconds to wait for AW API responses. |
DEFAULT_AW_TIMEOUT_SECONDS
|
title_salt
|
str
|
Salt for hashing window titles. |
DEFAULT_TITLE_SALT
|
data_dir
|
Path
|
Processed data directory (labels stored here). |
Path(DEFAULT_DATA_DIR)
|
transition_minutes
|
int
|
Minutes a new dominant app must persist before a transition notification fires. |
DEFAULT_TRANSITION_MINUTES
|
event_bus
|
EventBus | None
|
Optional shared event bus for broadcasting events to connected WebSocket clients. |
None
|
ui_port
|
int
|
Port for the embedded web UI server. |
8741
|
dev
|
bool
|
When |
False
|
browser
|
bool
|
When |
False
|
no_tray
|
bool
|
When |
False
|
open_browser
|
bool
|
When |
True
|
username
|
str | None
|
Display name to persist in |
None
|
notifications_enabled
|
bool
|
When |
True
|
privacy_notifications
|
bool
|
When |
True
|
retrain_config
|
Path | None
|
Optional path to a retrain YAML config. Enables the "Retrain Status" item in the Prediction Model submenu. |
None
|
Source code in src/taskclf/ui/tray.py
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 | |