core.types¶
Pydantic models for the core data contracts.
FeatureRow identity fields¶
Every FeatureRow carries stable identity columns alongside the schema
metadata and feature values:
| Field | Type | Description |
|---|---|---|
user_id |
str |
Random UUID identifying the user (not PII). |
device_id |
str \| None |
Optional device identifier. |
session_id |
str |
Deterministic session identifier derived from user_id + session start timestamp. |
bucket_start_ts |
datetime |
Start of the 60 s bucket (UTC, inclusive). |
bucket_end_ts |
datetime |
End of the 60 s bucket (UTC, exclusive). |
The primary key is (user_id, bucket_start_ts).
LabelSpan fields¶
LabelSpan represents a contiguous time span carrying a single task-type
label. Gold labels and weak labels share this structure. During validation,
all timestamps are normalized to timezone-aware UTC via ts_utc_aware_get()
so persisted label spans and in-memory comparisons use a single timestamp
convention. Legacy naive inputs (from CSV, Parquet, or API) are accepted and
treated as UTC on read.
| Field | Type | Description |
|---|---|---|
start_ts |
datetime |
Span start (aware UTC, inclusive). |
end_ts |
datetime |
Span end (aware UTC, exclusive). |
label |
str |
Task-type label from LABEL_SET_V1. |
provenance |
str |
Origin tag, e.g. "manual" or "weak:app_rule". |
user_id |
str \| None |
User who created this label (optional, default None). |
confidence |
float \| None |
Labeler confidence 0-1 (optional, default None). NaN is coerced to None. |
TitlePolicy¶
TitlePolicy controls whether raw window titles may appear in a
FeatureRow.
| Member | Value | Behaviour |
|---|---|---|
HASH_ONLY |
"hash_only" |
Default. All raw_* fields are rejected. |
RAW_WINDOW_TITLE_OPT_IN |
"raw_window_title_opt_in" |
raw_window_title is accepted but excluded from model_dump(), preventing leakage into data/processed/. All other raw_* fields remain prohibited. |
Pass the policy via Pydantic validation context:
from taskclf.core.types import FeatureRow, TitlePolicy
row = FeatureRow.model_validate(
data,
context={"title_policy": TitlePolicy.RAW_WINDOW_TITLE_OPT_IN},
)
row.raw_window_title # available on the instance
row.model_dump() # raw_window_title is NOT included
taskclf.core.types
¶
Core data contracts: Event protocol, feature rows, and label spans.
Event
¶
Bases: Protocol
Normalized activity event contract.
Any adapter event type that exposes these read-only attributes
satisfies the protocol -- no inheritance required. For example,
:class:~taskclf.adapters.activitywatch.types.AWEvent is a valid
Event without importing or subclassing this protocol.
Source code in src/taskclf/core/types.py
CoreLabel
¶
Bases: StrEnum
Canonical task-type labels (v1).
Member ordering matches schema/labels_v1.json label IDs.
Do NOT reorder or remove members without a version bump.
Source code in src/taskclf/core/types.py
LabelEnvelope
¶
Bases: BaseModel
Source code in src/taskclf/core/types.py
label
property
¶
Backward-compatible alias for older callers.
EvidenceSnapshot
¶
Bases: BaseModel
Raw observational signals for a short time slice (e.g. 15-60s).
Source code in src/taskclf/core/types.py
TitlePolicy
¶
Bases: StrEnum
Controls whether raw window titles may appear in a :class:FeatureRow.
HASH_ONLY (default)
All raw_* fields are rejected — the standard privacy mode.
RAW_WINDOW_TITLE_OPT_IN
raw_window_title is accepted (but still excluded from
model_dump() so it can never leak into data/processed/).
All other raw_* fields remain prohibited.
Pass the policy via Pydantic validation context::
FeatureRow.model_validate(data, context={"title_policy": TitlePolicy.RAW_WINDOW_TITLE_OPT_IN})
Source code in src/taskclf/core/types.py
FeatureRowBase
¶
Bases: BaseModel
One bucketed observation (typically 60 s).
All persisted feature rows carry schema metadata so downstream consumers can detect silent drift.
Fields are grouped into four sections:
- meta —
bucket_start_ts,schema_version,schema_hash,source_ids. - context —
app_id,app_category,window_title_hash,is_browser,is_editor,is_terminal,app_switch_count_last_5m,app_foreground_time_ratio,app_change_count,app_dwell_time_seconds,app_entropy_5m,app_entropy_15m,top2_app_concentration_15m,idle_return_indicator. - keyboard / mouse — nullable until the corresponding collector is
wired (
keys_per_min,backspace_ratio,shortcut_rate,clicks_per_min,scroll_events_per_min,mouse_distance). - activity occupancy — nullable; derived from
aw-watcher-input(active_seconds_keyboard,active_seconds_mouse,active_seconds_any,max_idle_run_seconds,event_density). - temporal —
hour_of_day,day_of_week,session_length_so_far.
A pre-validator rejects any field whose name starts with raw_ to
enforce the privacy invariant (no raw keystrokes / titles). The
single exception is raw_window_title, which is accepted when
validation context carries title_policy=TitlePolicy.RAW_WINDOW_TITLE_OPT_IN.
Even then, the field is excluded from model_dump() so it cannot
leak into persisted datasets.
Source code in src/taskclf/core/types.py
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 | |
LabelSpan
¶
Bases: BaseModel
A contiguous time span carrying a single task-type label.
Gold labels and weak labels share this structure; provenance
distinguishes them (e.g. "manual" vs "weak:app_rule").
Optional user_id ties the span to a specific user (required for
multi-user datasets and block-to-window projection). Optional
confidence records the labeler's self-assessed certainty.
Both default to None for backward compatibility with existing
label CSV imports.