agent-usage-tracker 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. agent_usage_tracker/__init__.py +8 -0
  2. agent_usage_tracker/backup.py +225 -0
  3. agent_usage_tracker/cli.py +479 -0
  4. agent_usage_tracker/collectors/__init__.py +115 -0
  5. agent_usage_tracker/collectors/_util.py +310 -0
  6. agent_usage_tracker/collectors/activity_common.py +294 -0
  7. agent_usage_tracker/collectors/activitywatch.py +394 -0
  8. agent_usage_tracker/collectors/claude_code.py +484 -0
  9. agent_usage_tracker/collectors/claude_code_activity.py +317 -0
  10. agent_usage_tracker/collectors/codex.py +612 -0
  11. agent_usage_tracker/collectors/commits.py +154 -0
  12. agent_usage_tracker/collectors/cursor.py +193 -0
  13. agent_usage_tracker/collectors/cursor_api.py +247 -0
  14. agent_usage_tracker/collectors/cursor_cli.py +592 -0
  15. agent_usage_tracker/collectors/cursor_sdk.py +95 -0
  16. agent_usage_tracker/collectors/generic_sdk.py +100 -0
  17. agent_usage_tracker/collectors/pi.py +397 -0
  18. agent_usage_tracker/collectors/session_digest.py +379 -0
  19. agent_usage_tracker/collectors/t3.py +490 -0
  20. agent_usage_tracker/config.py +392 -0
  21. agent_usage_tracker/coverage.py +615 -0
  22. agent_usage_tracker/coverage_catalog.json +588 -0
  23. agent_usage_tracker/cursor_run.py +62 -0
  24. agent_usage_tracker/diagnostics.py +74 -0
  25. agent_usage_tracker/episode_store.py +78 -0
  26. agent_usage_tracker/event.py +132 -0
  27. agent_usage_tracker/git_day_cache.py +128 -0
  28. agent_usage_tracker/git_days.py +499 -0
  29. agent_usage_tracker/git_safe.py +58 -0
  30. agent_usage_tracker/harness_inventory.py +208 -0
  31. agent_usage_tracker/history_steers.py +88 -0
  32. agent_usage_tracker/improve/__init__.py +1 -0
  33. agent_usage_tracker/improve/case_view.py +112 -0
  34. agent_usage_tracker/improve/cli.py +138 -0
  35. agent_usage_tracker/improve/desktop.py +347 -0
  36. agent_usage_tracker/improve/evidence.py +322 -0
  37. agent_usage_tracker/improve/judge.py +671 -0
  38. agent_usage_tracker/improve/proposals.py +72 -0
  39. agent_usage_tracker/improve/rubric.py +360 -0
  40. agent_usage_tracker/improve/rubrics/avoidable_recovery.md +20 -0
  41. agent_usage_tracker/improve/rubrics/code_quality.md +22 -0
  42. agent_usage_tracker/improve/rubrics/completion_supported.md +20 -0
  43. agent_usage_tracker/improve/rubrics/redundant_tests.md +21 -0
  44. agent_usage_tracker/improve/rubrics/verbosity.md +21 -0
  45. agent_usage_tracker/improve/runtime.py +117 -0
  46. agent_usage_tracker/improve/schedule.py +291 -0
  47. agent_usage_tracker/improve/search_check.py +563 -0
  48. agent_usage_tracker/improve/store.py +244 -0
  49. agent_usage_tracker/improve/studies.py +285 -0
  50. agent_usage_tracker/improve/study_cli.py +46 -0
  51. agent_usage_tracker/improve/study_decision.py +121 -0
  52. agent_usage_tracker/improve/study_followup.py +174 -0
  53. agent_usage_tracker/improve/t3.py +269 -0
  54. agent_usage_tracker/improve/trial.py +318 -0
  55. agent_usage_tracker/improve/validation.py +148 -0
  56. agent_usage_tracker/inspector.py +350 -0
  57. agent_usage_tracker/label/__init__.py +22 -0
  58. agent_usage_tracker/label/backends.py +742 -0
  59. agent_usage_tracker/label/bakeoff.py +661 -0
  60. agent_usage_tracker/label/baseline.py +173 -0
  61. agent_usage_tracker/label/clef.py +258 -0
  62. agent_usage_tracker/label/context.py +382 -0
  63. agent_usage_tracker/label/core.py +355 -0
  64. agent_usage_tracker/label/covered_run.py +92 -0
  65. agent_usage_tracker/label/evalset.py +154 -0
  66. agent_usage_tracker/label/gold.py +209 -0
  67. agent_usage_tracker/label/local.py +326 -0
  68. agent_usage_tracker/label/local_parallel.py +232 -0
  69. agent_usage_tracker/label/merge.py +57 -0
  70. agent_usage_tracker/label/outcome_coverage.py +57 -0
  71. agent_usage_tracker/label/replay.py +194 -0
  72. agent_usage_tracker/label/run.py +339 -0
  73. agent_usage_tracker/label/tasks.py +579 -0
  74. agent_usage_tracker/label/teach.py +145 -0
  75. agent_usage_tracker/local_page.py +128 -0
  76. agent_usage_tracker/manual_time.py +69 -0
  77. agent_usage_tracker/net.py +23 -0
  78. agent_usage_tracker/observation_cli.py +65 -0
  79. agent_usage_tracker/observation_report.py +116 -0
  80. agent_usage_tracker/observation_server.py +110 -0
  81. agent_usage_tracker/observations.py +365 -0
  82. agent_usage_tracker/outcome_git.py +383 -0
  83. agent_usage_tracker/outcomes.py +464 -0
  84. agent_usage_tracker/pricing.py +248 -0
  85. agent_usage_tracker/push.py +530 -0
  86. agent_usage_tracker/redact.py +45 -0
  87. agent_usage_tracker/repo_keys.py +165 -0
  88. agent_usage_tracker/review.py +252 -0
  89. agent_usage_tracker/scan.py +472 -0
  90. agent_usage_tracker/scheduled.py +164 -0
  91. agent_usage_tracker/sdk.py +79 -0
  92. agent_usage_tracker/sink.py +82 -0
  93. agent_usage_tracker/sink_stack/README.md +71 -0
  94. agent_usage_tracker/sink_stack/apply.sh +63 -0
  95. agent_usage_tracker/sink_stack/compose.yaml +94 -0
  96. agent_usage_tracker/sink_stack/env.example +20 -0
  97. agent_usage_tracker/sink_stack/grafana/dashboards/agents-effort.json +634 -0
  98. agent_usage_tracker/sink_stack/grafana/dashboards/agents-usage.json +1279 -0
  99. agent_usage_tracker/sink_stack/grafana/provisioning/dashboards/aut.yaml +9 -0
  100. agent_usage_tracker/sink_stack/grafana/provisioning/datasources/agents.yaml +16 -0
  101. agent_usage_tracker/sink_stack/sql/01_schema.sql +1186 -0
  102. agent_usage_tracker/sink_stack/sql/02_price.sql +60 -0
  103. agent_usage_tracker/sink_stack/sql/03_effort.sql +1180 -0
  104. agent_usage_tracker/sink_stack/sql/04_grants.sql +149 -0
  105. agent_usage_tracker/sink_stack/sql/refresh.sql +66 -0
  106. agent_usage_tracker/sources.py +180 -0
  107. agent_usage_tracker/state.py +191 -0
  108. agent_usage_tracker/telemetry.py +165 -0
  109. agent_usage_tracker-0.1.0.dist-info/METADATA +366 -0
  110. agent_usage_tracker-0.1.0.dist-info/RECORD +113 -0
  111. agent_usage_tracker-0.1.0.dist-info/WHEEL +4 -0
  112. agent_usage_tracker-0.1.0.dist-info/entry_points.txt +3 -0
  113. agent_usage_tracker-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,392 @@
1
+ """Config loader. Secrets NEVER live in this repo: they live in a local TOML under
2
+ ~/.config/agent-usage-tracker/config.toml (override with AUT_CONFIG), and any value
3
+ written as "env:VAR" is resolved from the environment at run time.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import Any
9
+ import os
10
+ import re
11
+ import socket
12
+ import sys
13
+ import tomllib
14
+ from dataclasses import dataclass, field
15
+ from datetime import date, datetime
16
+ from pathlib import Path
17
+
18
+ from .state import warn_if_group_readable
19
+
20
+ # Must name what collectors.REGISTRY names (a test asserts it): collectors import this module, so
21
+ # it cannot derive the list from the registry.
22
+ ALL_AGENTS = ("claude_code", "codex", "cursor", "cursor_sdk", "cursor_api", "cursor_cli", "pi",
23
+ "activitywatch", "generic_sdk", "t3")
24
+ # activitywatch reads window titles, so it is opt-in: a config without `agents` never enables it.
25
+ DEFAULT_AGENTS = tuple(a for a in ALL_AGENTS if a not in ("activitywatch", "generic_sdk"))
26
+ # Must name what label.tasks.TASKS names (tests/label/test_label_tasks.py asserts it): label.tasks imports
27
+ # this module, so this module cannot derive the list from it.
28
+ LABEL_DECISION_TASKS = ("work_category", "steer_intent", "soft_outcome", "aw_title_relevance",
29
+ "writing_activity")
30
+ # What a "day" is in the sink: must equal the sink's AUT_TZ. This default keeps existing setups.
31
+ DEFAULT_LEDGER_TZ = "Europe/Amsterdam"
32
+ LABEL_NOTE = "daily_note" # generative, private: one draft per day (label/run.py), not a decision
33
+ LABEL_TASK_NAMES = (*LABEL_DECISION_TASKS, LABEL_NOTE)
34
+ LABEL_DAYS = 90 # the window units are rebuilt over (teach, review, eval, train)
35
+ DEFAULT_AW_URL = "http://localhost:5600"
36
+ DEFAULT_LABEL_MODEL = "mlx-community/gemma-4-31b-it-4bit"
37
+ DEFAULT_REPO_ROOTS = ("~/projects",)
38
+ DEFAULT_GIT_DAYS_SINCE = date(2022, 2, 3) # the public ledger's first day
39
+ AW_CATEGORIES = ("editor", "terminal", "agent", "dev", "browser", "comms", "docs", "design",
40
+ "media", "other")
41
+
42
+
43
+ class AutError(Exception):
44
+ """An error for the operator: main prints the message and exits 1, with no traceback."""
45
+
46
+
47
+ def config_path() -> Path:
48
+ if os.environ.get("AUT_CONFIG"):
49
+ return Path(os.environ["AUT_CONFIG"]).expanduser()
50
+ base = os.environ.get("XDG_CONFIG_HOME", str(Path.home() / ".config"))
51
+ return Path(base) / "agent-usage-tracker" / "config.toml"
52
+
53
+
54
+ def _text(section: dict[str, Any], key: str) -> str | None:
55
+ """A string setting, or None when absent. A TypeError names the key, never the value."""
56
+ value = section.get(key)
57
+ if value is not None and not isinstance(value, str):
58
+ raise TypeError(f"{key} must be a string")
59
+ return value
60
+
61
+
62
+ def _resolve(section: dict[str, Any], key: str) -> str | None:
63
+ """A string setting, with an "env:VAR" indirection resolved from the environment. An unset
64
+ variable reads as not configured, and says so: a scheduled job often lacks the variable."""
65
+ value = _text(section, key)
66
+ if value is None or not value.startswith("env:"):
67
+ return value
68
+ resolved = os.environ.get(value[4:])
69
+ if resolved is None:
70
+ print(f"aut: warning: {key} names the environment variable {value[4:]}, which is not set; "
71
+ "treating it as not configured.", file=sys.stderr)
72
+ return resolved
73
+
74
+
75
+ def _as_bool(value: object) -> bool:
76
+ """Truthy parse that respects a quoted string. TOML `x = false` is already a native bool, but
77
+ `x = "false"` (a quoted string) would be truthy under bool(); treat common false-y strings as
78
+ False so a mistyped opt-in flag can't silently enable a network collector."""
79
+ if isinstance(value, str):
80
+ return value.strip().lower() in ("1", "true", "yes", "on")
81
+ return bool(value)
82
+
83
+
84
+ @dataclass(slots=True)
85
+ class Config:
86
+ machine: str
87
+ agents: tuple[str, ...]
88
+ webhook_url: str | None
89
+ webhook_secret: str | None
90
+ pg_dsn: str | None
91
+ home: Path
92
+ ledger_timezone: str = DEFAULT_LEDGER_TZ
93
+ cursor_db_path: str | None = None # override Cursor's state.vscdb location
94
+ cursor_human_only: bool = False # `cursor` emits prompts only -> safe beside cursor_api
95
+ cursor_sdk_manifests: str | None = None # glob of orchestrator manifest.json files (SDK usage)
96
+ generic_sdk_paths: str | None = None # explicit local normalized SDK JSONL file/glob
97
+ cursor_api: bool = False # opt-in: pull accurate usage from Cursor's dashboard API
98
+ cursor_api_lookback_days: int = 90 # first-scan window when there is no watermark yet
99
+ # Cloudflare Access service token (Pattern 2) so a machine can push through CF Access from
100
+ # anywhere - no VPN. Both set -> sent as CF-Access-Client-Id / CF-Access-Client-Secret headers.
101
+ cf_access_client_id: str | None = None
102
+ cf_access_client_secret: str | None = None
103
+ # Key for the activity rows' repo_key HMAC. Unset: a random per-install salt file is created
104
+ # next to the state file. Set the same value on every machine so their keys match.
105
+ repo_key_salt: str | None = None
106
+ # activitywatch (opt-in): local aw-server, title retention there, and the guards' extensions.
107
+ activitywatch_url: str = DEFAULT_AW_URL
108
+ activitywatch_title_days: int = 0 # 0: keep titles for good (no purge)
109
+ activitywatch_titles: bool = True # false: intervals and categories, no titles
110
+ activitywatch_deny_apps: tuple[str, ...] = () # lowercased app names, dropped entirely
111
+ activitywatch_deny_titles: tuple[str, ...] = () # regexes (case-insensitive), dropped entirely
112
+ activitywatch_work_titles: tuple[str, ...] = () # regexes that make a browser row web-work
113
+ activitywatch_categories: dict[str, str] = field(default_factory=dict) # lowercased app -> cat
114
+ # `aut outcomes`: where the local clones live, and whether it fetches them (and asks gh) first.
115
+ outcome_repo_roots: tuple[str, ...] = DEFAULT_REPO_ROOTS
116
+ outcome_fetch: bool = False
117
+ # `aut label` (local model on this machine): which tasks the nightly run labels, the model,
118
+ # the precision bar for tau and the coverage gate, and the run's time budget.
119
+ label_tasks: tuple[str, ...] = ()
120
+ label_model: str = DEFAULT_LABEL_MODEL
121
+ label_llama_server: str = "llama-server"
122
+ label_precision: float = 0.90
123
+ label_recall: float = 0.60
124
+ label_coverage: float = 0.75
125
+ label_budget_s: int = 3600
126
+ label_mature_outcomes: bool = False # local-only catch-up, disabled until evaluated
127
+ # `aut backup` ([backup] table): the restic repository, the command that prints its password,
128
+ # the paths (empty: backup.default_paths) and excludes added to backup.default_excludes.
129
+ backup_repository: str | None = None
130
+ backup_password_command: str | None = None
131
+ backup_paths: tuple[str, ...] = ()
132
+ backup_excludes: tuple[str, ...] = ()
133
+ backup_retention: bool = True
134
+ # `aut git-days` ([git_days] table): the owner's commits per day, from local and remote clones.
135
+ git_days_enabled: bool = False # true: `aut scan` runs it once a day
136
+ git_days_exclude_dirs: tuple[str, ...] = ()
137
+ git_days_since: date = DEFAULT_GIT_DAYS_SINCE
138
+ git_days_identities: tuple[str, ...] = () # lowercased author emails
139
+ git_days_shared_authors: tuple[tuple[str, str], ...] = () # (email_regex, repo_regex)
140
+ git_days_roots: tuple[str, ...] = DEFAULT_REPO_ROOTS
141
+ git_days_remotes: tuple[tuple[str, tuple[str, ...]], ...] = () # (ssh host, roots there)
142
+
143
+ t3_activity_since: str | None = None # explicit prospective cutover, never inferred per scan
144
+
145
+ @property
146
+ def cf_access_headers(self) -> dict[str, str]:
147
+ """CF Access service-token headers, only when BOTH halves are present; else empty."""
148
+ if self.cf_access_client_id and self.cf_access_client_secret:
149
+ return {"CF-Access-Client-Id": self.cf_access_client_id,
150
+ "CF-Access-Client-Secret": self.cf_access_client_secret}
151
+ return {}
152
+
153
+ @property
154
+ def has_webhook(self) -> bool:
155
+ return bool(self.webhook_url)
156
+
157
+ @property
158
+ def has_pg(self) -> bool:
159
+ return bool(self.pg_dsn)
160
+
161
+ def require_pg(self, what: str) -> str:
162
+ """The DSN, or the operator's error saying that `what` cannot run without it."""
163
+ if not self.pg_dsn:
164
+ raise AutError(f"{what} needs transport.pg_dsn")
165
+ return self.pg_dsn
166
+
167
+
168
+ def load_config() -> Config:
169
+ path = config_path()
170
+ data: dict[str, Any] = {}
171
+ if path.exists():
172
+ try:
173
+ with open(path, "rb") as fh:
174
+ data = tomllib.load(fh)
175
+ except (tomllib.TOMLDecodeError, UnicodeDecodeError, OSError) as exc:
176
+ raise AutError(f"config: {path} is not readable TOML ({exc})") from None
177
+ try:
178
+ return _config_from(data, path)
179
+ except (AttributeError, OverflowError, TypeError, ValueError) as exc:
180
+ # Safe to print: only int() and float() echo a value, and no secret goes through them.
181
+ raise AutError(f"config: {path} has a value of the wrong type ({exc})") from None
182
+
183
+
184
+ def _agents_of(data: dict[str, Any]) -> tuple[str, ...]:
185
+ agents = tuple(data.get("agents") or DEFAULT_AGENTS)
186
+ unknown = [a for a in agents if a not in ALL_AGENTS]
187
+ if unknown:
188
+ raise AutError(f"config: unknown agent(s) {unknown}; valid = {list(ALL_AGENTS)}")
189
+ return agents
190
+
191
+
192
+ def _aw_categories(data: dict[str, Any]) -> dict[str, str]:
193
+ cats = {str(k).strip().lower(): v
194
+ for k, v in (data.get("activitywatch_categories") or {}).items()}
195
+ bad = sorted(k for k, v in cats.items() if v not in AW_CATEGORIES)
196
+ if bad:
197
+ raise AutError(f"config: activitywatch_categories {bad}: category must be one of "
198
+ f"{list(AW_CATEGORIES)}")
199
+ return cats
200
+
201
+
202
+ def _regex_list(data: dict[str, Any], key: str) -> tuple[str, ...]:
203
+ patterns = tuple(str(p) for p in data.get(key) or ())
204
+ for i, pat in enumerate(patterns):
205
+ try:
206
+ re.compile(pat)
207
+ except re.error as exc: # the pattern itself may name a bank: never echo it
208
+ raise AutError(f"config: {key}[{i}] is not a valid regex ({exc.msg})") from None
209
+ return patterns
210
+
211
+
212
+ def _repo_roots(data: dict[str, Any]) -> tuple[str, ...]:
213
+ roots = data.get("outcome_repo_roots") or list(DEFAULT_REPO_ROOTS)
214
+ roots = [roots] if isinstance(roots, str) else roots
215
+ if not isinstance(roots, list) or not all(isinstance(r, str) and r for r in roots):
216
+ raise AutError("config: outcome_repo_roots must be a list of directory strings")
217
+ return tuple(roots)
218
+
219
+
220
+ def _aw_url(data: dict[str, Any]) -> str:
221
+ url = str(data.get("activitywatch_url") or DEFAULT_AW_URL)
222
+ if not url.startswith(("http://", "https://")):
223
+ raise AutError("config: activitywatch_url must start with http:// or https://")
224
+ return url
225
+
226
+
227
+ def _aw_title_days(data: dict[str, Any]) -> int:
228
+ # 0 (the default) keeps titles for good; a number of days turns the limit on.
229
+ days = int(data.get("activitywatch_title_days") or 0)
230
+ if days < 0:
231
+ raise AutError("config: activitywatch_title_days must be 0 (keep) or a number of days")
232
+ return days
233
+
234
+
235
+ def _label_tasks(data: dict[str, Any]) -> tuple[str, ...]:
236
+ tasks = data.get("label_tasks") or []
237
+ if not isinstance(tasks, list) or any(t not in LABEL_TASK_NAMES for t in tasks):
238
+ raise AutError(f"config: label_tasks must be a list of {list(LABEL_TASK_NAMES)}")
239
+ return tuple(tasks)
240
+
241
+
242
+ def _str_list(section: dict[str, Any], key: str, where: str) -> tuple[str, ...]:
243
+ items = section.get(key) or []
244
+ if not isinstance(items, list) or not all(isinstance(x, str) and x for x in items):
245
+ raise AutError(f"config: {where}{key} must be a list of strings")
246
+ return tuple(items)
247
+
248
+
249
+ def _backup(data: dict[str, Any]) -> dict[str, Any]:
250
+ section = data.get("backup") or {}
251
+ if not isinstance(section, dict):
252
+ raise AutError("config: [backup] must be a table")
253
+ return {"backup_repository": _resolve(section, "repository"),
254
+ "backup_password_command": _resolve(section, "password_command"),
255
+ "backup_paths": _str_list(section, "paths", "backup."),
256
+ "backup_excludes": _str_list(section, "excludes", "backup."),
257
+ "backup_retention": _as_bool(section.get("retention", True))}
258
+
259
+
260
+ _SSH_HOST = re.compile(r"[A-Za-z0-9_.@][A-Za-z0-9_.@-]*") # never a leading "-": no ssh option
261
+
262
+
263
+ def _git_days(data: dict[str, Any]) -> dict[str, Any]:
264
+ """[git_days]. Errors name the key, never the value: identities, hosts and paths are private."""
265
+ section = data.get("git_days") or {}
266
+ if not isinstance(section, dict):
267
+ raise AutError("config: [git_days] must be a table")
268
+ exclude_dirs = _str_list(section, "exclude_dirs", "git_days.")
269
+ if any(not p.startswith("/") or "\n" in p or "\x00" in p for p in exclude_dirs):
270
+ raise AutError("config: git_days.exclude_dirs needs absolute physical directory paths")
271
+ shared = []
272
+ for i, entry in enumerate(section.get("shared_authors") or []):
273
+ if not isinstance(entry, dict):
274
+ raise AutError(f"config: git_days.shared_authors[{i}] must be a table")
275
+ pair = (_text(entry, "email_regex") or "", _text(entry, "repo_regex") or "")
276
+ for key, pat in zip(("email_regex", "repo_regex"), pair):
277
+ try:
278
+ re.compile(pat)
279
+ except re.error as exc:
280
+ raise AutError(f"config: git_days.shared_authors[{i}].{key} is not a valid regex "
281
+ f"({exc.msg})") from None
282
+ if not all(pair):
283
+ raise AutError(f"config: git_days.shared_authors[{i}] needs email_regex and repo_regex")
284
+ shared.append(pair)
285
+ remotes = []
286
+ for i, entry in enumerate(section.get("remotes") or []):
287
+ host = entry.get("host") if isinstance(entry, dict) else None
288
+ if not isinstance(host, str) or not _SSH_HOST.fullmatch(host):
289
+ raise AutError(f"config: git_days.remotes[{i}].host must be an ssh host name or alias")
290
+ roots = _str_list(entry, "roots", f"git_days.remotes[{i}].")
291
+ if not roots:
292
+ raise AutError(f"config: git_days.remotes[{i}].roots needs at least one folder")
293
+ remotes.append((host, roots))
294
+ since = section.get("since", DEFAULT_GIT_DAYS_SINCE)
295
+ if isinstance(since, datetime): # a TOML datetime: its own calendar day
296
+ since = since.date()
297
+ elif isinstance(since, str):
298
+ try:
299
+ since = date.fromisoformat(since)
300
+ except ValueError:
301
+ since = None
302
+ if not isinstance(since, date):
303
+ raise AutError("config: git_days.since must be a date (YYYY-MM-DD)")
304
+ return {"git_days_enabled": _as_bool(section.get("enabled", False)),
305
+ "git_days_exclude_dirs": exclude_dirs,
306
+ "git_days_since": since,
307
+ "git_days_identities": tuple(e.strip().lower() for e in
308
+ _str_list(section, "identities", "git_days.")),
309
+ "git_days_shared_authors": tuple(shared),
310
+ "git_days_roots": _str_list(section, "roots", "git_days.") or DEFAULT_REPO_ROOTS,
311
+ "git_days_remotes": tuple(remotes)}
312
+
313
+
314
+ def _label_bars(data: dict[str, Any]) -> tuple[float, float, float]:
315
+ precision, recall, coverage = (float(data.get(k, d)) for k, d in
316
+ (("label_precision", 0.90), ("label_recall", 0.60),
317
+ ("label_coverage", 0.75)))
318
+ if not (0 < precision <= 1 and 0 <= recall <= 1 and 0 <= coverage <= 1):
319
+ raise AutError("config: label_precision, label_recall and label_coverage must lie in 0..1")
320
+ return precision, recall, coverage
321
+
322
+
323
+ def _warn_if_secrets_written(path: Path, transport: dict[str, Any], data: dict[str, Any]) -> None:
324
+ # Only a value written in the file counts: an env:VAR reference keeps the secret out of it.
325
+ written = (transport.get("webhook_secret"), transport.get("pg_dsn"),
326
+ transport.get("cf_access_client_secret"), data.get("repo_key_salt"),
327
+ (data.get("backup") or {}).get("repository")) # a rest: URL can hold a password
328
+ if path.exists() and any(v and not str(v).startswith("env:") for v in written):
329
+ warn_if_group_readable(path)
330
+
331
+
332
+ def _config_from(data: dict[str, Any], path: Path) -> Config:
333
+ transport = data.get("transport", {})
334
+ agents = _agents_of(data)
335
+ aw_cats = _aw_categories(data)
336
+ deny_titles = _regex_list(data, "activitywatch_deny_titles")
337
+ work_titles = _regex_list(data, "activitywatch_work_titles")
338
+ roots = _repo_roots(data)
339
+ aw_days = _aw_title_days(data)
340
+ label_tasks = _label_tasks(data)
341
+ label_precision, label_recall, label_coverage = _label_bars(data)
342
+ t3_since = _text(data, "t3_activity_since")
343
+ if t3_since is not None:
344
+ try:
345
+ parsed_t3_since = datetime.fromisoformat(t3_since.replace("Z", "+00:00"))
346
+ except ValueError:
347
+ raise AutError("config: t3_activity_since must be a timezone-aware ISO timestamp") from None
348
+ if parsed_t3_since.tzinfo is None:
349
+ raise AutError("config: t3_activity_since must include a timezone")
350
+ backup = _backup(data)
351
+ git_days = _git_days(data)
352
+ _warn_if_secrets_written(path, transport, data)
353
+
354
+ return Config(
355
+ machine=_text(data, "machine") or socket.gethostname().split(".")[0],
356
+ agents=agents,
357
+ webhook_url=_resolve(transport, "webhook_url"),
358
+ webhook_secret=_resolve(transport, "webhook_secret"),
359
+ pg_dsn=_resolve(transport, "pg_dsn"),
360
+ home=Path(data.get("home") or Path.home()).expanduser(),
361
+ ledger_timezone=_text(data, "ledger_timezone") or DEFAULT_LEDGER_TZ,
362
+ t3_activity_since=t3_since,
363
+ cursor_db_path=_resolve(data, "cursor_db_path"),
364
+ cursor_human_only=_as_bool(data.get("cursor_human_only", False)),
365
+ cursor_sdk_manifests=_resolve(data, "cursor_sdk_manifests"),
366
+ generic_sdk_paths=_text(data, "generic_sdk_paths"),
367
+ cursor_api=_as_bool(data.get("cursor_api", False)),
368
+ cursor_api_lookback_days=int(data.get("cursor_api_lookback_days") or 90),
369
+ cf_access_client_id=_resolve(transport, "cf_access_client_id"),
370
+ cf_access_client_secret=_resolve(transport, "cf_access_client_secret"),
371
+ repo_key_salt=_resolve(data, "repo_key_salt"),
372
+ activitywatch_url=_aw_url(data),
373
+ activitywatch_title_days=aw_days,
374
+ activitywatch_titles=_as_bool(data.get("activitywatch_titles", True)),
375
+ activitywatch_deny_apps=tuple(str(a).strip().lower()
376
+ for a in data.get("activitywatch_deny_apps") or ()),
377
+ activitywatch_deny_titles=deny_titles,
378
+ activitywatch_work_titles=work_titles,
379
+ activitywatch_categories=aw_cats,
380
+ outcome_repo_roots=roots,
381
+ outcome_fetch=_as_bool(data.get("outcome_fetch", False)),
382
+ label_tasks=label_tasks,
383
+ label_model=str(data.get("label_model") or DEFAULT_LABEL_MODEL),
384
+ label_llama_server=str(data.get("label_llama_server") or "llama-server"),
385
+ label_precision=label_precision,
386
+ label_recall=label_recall,
387
+ label_coverage=label_coverage,
388
+ label_budget_s=int(data.get("label_budget_s") or 3600),
389
+ label_mature_outcomes=_as_bool(data.get("label_mature_outcomes", False)),
390
+ **backup,
391
+ **git_days,
392
+ )