cfgit 0.4.2__tar.gz → 0.4.4__tar.gz

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 (85) hide show
  1. {cfgit-0.4.2 → cfgit-0.4.4}/PKG-INFO +1 -1
  2. {cfgit-0.4.2 → cfgit-0.4.4}/plugins/cfg_impact/pyproject.toml +2 -2
  3. {cfgit-0.4.2 → cfgit-0.4.4}/pyproject.toml +1 -1
  4. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/adapters/base.py +6 -0
  5. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/adapters/mongo.py +28 -2
  6. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/adapters/postgres.py +44 -2
  7. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/core/engine.py +58 -12
  8. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/ui/server.py +32 -6
  9. {cfgit-0.4.2 → cfgit-0.4.4}/.github/workflows/ci.yml +0 -0
  10. {cfgit-0.4.2 → cfgit-0.4.4}/.github/workflows/publish.yml +0 -0
  11. {cfgit-0.4.2 → cfgit-0.4.4}/.gitignore +0 -0
  12. {cfgit-0.4.2 → cfgit-0.4.4}/CONTRIBUTING.md +0 -0
  13. {cfgit-0.4.2 → cfgit-0.4.4}/CREDITS.md +0 -0
  14. {cfgit-0.4.2 → cfgit-0.4.4}/LICENSE +0 -0
  15. {cfgit-0.4.2 → cfgit-0.4.4}/NOTICE +0 -0
  16. {cfgit-0.4.2 → cfgit-0.4.4}/README.md +0 -0
  17. {cfgit-0.4.2 → cfgit-0.4.4}/SECURITY.md +0 -0
  18. {cfgit-0.4.2 → cfgit-0.4.4}/docs/ADAPTERS.md +0 -0
  19. {cfgit-0.4.2 → cfgit-0.4.4}/docs/AGENTS.md +0 -0
  20. {cfgit-0.4.2 → cfgit-0.4.4}/docs/BRANCHING_PLAN.md +0 -0
  21. {cfgit-0.4.2 → cfgit-0.4.4}/docs/CONFIGURATION.md +0 -0
  22. {cfgit-0.4.2 → cfgit-0.4.4}/docs/IDENTITY_AND_ATTRIBUTION.md +0 -0
  23. {cfgit-0.4.2 → cfgit-0.4.4}/docs/PUBLISHING.md +0 -0
  24. {cfgit-0.4.2 → cfgit-0.4.4}/docs/README.md +0 -0
  25. {cfgit-0.4.2 → cfgit-0.4.4}/docs/SPEC.md +0 -0
  26. {cfgit-0.4.2 → cfgit-0.4.4}/docs/SPEC_CORE.md +0 -0
  27. {cfgit-0.4.2 → cfgit-0.4.4}/docs/USAGE.md +0 -0
  28. {cfgit-0.4.2 → cfgit-0.4.4}/docs/screenshots/01-diff.png +0 -0
  29. {cfgit-0.4.2 → cfgit-0.4.4}/docs/screenshots/02-impact.png +0 -0
  30. {cfgit-0.4.2 → cfgit-0.4.4}/docs/screenshots/03-scoped-impact.png +0 -0
  31. {cfgit-0.4.2 → cfgit-0.4.4}/docs/screenshots/04-branches.png +0 -0
  32. {cfgit-0.4.2 → cfgit-0.4.4}/docs/screenshots/05-pull-request.png +0 -0
  33. {cfgit-0.4.2 → cfgit-0.4.4}/examples/.cfg.toml +0 -0
  34. {cfgit-0.4.2 → cfgit-0.4.4}/examples/cfgit-support-demo.toml +0 -0
  35. {cfgit-0.4.2 → cfgit-0.4.4}/examples/seed_support_demo.py +0 -0
  36. {cfgit-0.4.2 → cfgit-0.4.4}/plugins/cfg_impact/README.md +0 -0
  37. {cfgit-0.4.2 → cfgit-0.4.4}/plugins/cfg_impact/cfg_impact/__init__.py +0 -0
  38. {cfgit-0.4.2 → cfgit-0.4.4}/plugins/cfg_impact/cfg_impact/overview.py +0 -0
  39. {cfgit-0.4.2 → cfgit-0.4.4}/plugins/cfg_impact/cfg_impact/providers/__init__.py +0 -0
  40. {cfgit-0.4.2 → cfgit-0.4.4}/plugins/cfg_impact/cfg_impact/providers/base.py +0 -0
  41. {cfgit-0.4.2 → cfgit-0.4.4}/plugins/cfg_impact/cfg_impact/providers/claude.py +0 -0
  42. {cfgit-0.4.2 → cfgit-0.4.4}/plugins/cfg_impact/cfg_impact/providers/factory.py +0 -0
  43. {cfgit-0.4.2 → cfgit-0.4.4}/plugins/cfg_impact/cfg_impact/providers/gemini.py +0 -0
  44. {cfgit-0.4.2 → cfgit-0.4.4}/plugins/cfg_impact/cfg_impact/providers/openai_provider.py +0 -0
  45. {cfgit-0.4.2 → cfgit-0.4.4}/skills/cfgit/SKILL.md +0 -0
  46. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/__init__.py +0 -0
  47. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/adapters/__init__.py +0 -0
  48. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/approval/__init__.py +0 -0
  49. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/approval/base.py +0 -0
  50. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/cli/__init__.py +0 -0
  51. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/cli/main.py +0 -0
  52. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/core/__init__.py +0 -0
  53. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/core/authz.py +0 -0
  54. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/core/config.py +0 -0
  55. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/core/diff.py +0 -0
  56. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/core/hashing.py +0 -0
  57. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/core/identity.py +0 -0
  58. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/core/remedy.py +0 -0
  59. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/interfaces/__init__.py +0 -0
  60. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/interfaces/actions.py +0 -0
  61. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/mcp/__init__.py +0 -0
  62. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/mcp/server.py +0 -0
  63. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/ui/__init__.py +0 -0
  64. {cfgit-0.4.2 → cfgit-0.4.4}/src/cfg/update.py +0 -0
  65. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_adapter_contract_live.py +0 -0
  66. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_authz.py +0 -0
  67. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_awareness.py +0 -0
  68. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_commit_dry_run.py +0 -0
  69. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_config.py +0 -0
  70. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_config_discovery.py +0 -0
  71. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_console_script.py +0 -0
  72. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_core_purity.py +0 -0
  73. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_engine_safety.py +0 -0
  74. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_export_import.py +0 -0
  75. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_hashing.py +0 -0
  76. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_identity.py +0 -0
  77. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_impact_boundary.py +0 -0
  78. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_mcp_identity.py +0 -0
  79. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_mongo_history.py +0 -0
  80. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_output_mode.py +0 -0
  81. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_postgres_history.py +0 -0
  82. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_remedy.py +0 -0
  83. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_set_fields.py +0 -0
  84. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_ui_server.py +0 -0
  85. {cfgit-0.4.2 → cfgit-0.4.4}/tests/test_update_check.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cfgit
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Git-style history, diff, drift detection, and rollback for live database records without migrating or owning your datastore
5
5
  Project-URL: Homepage, https://github.com/AusafMo/cfgit
6
6
  Project-URL: Repository, https://github.com/AusafMo/cfgit
@@ -1,13 +1,13 @@
1
1
  [project]
2
2
  name = "cfgit-impact"
3
- version = "0.4.2"
3
+ version = "0.4.4"
4
4
  description = "Optional cfgit plugin for deterministic system-impact summaries and opt-in LLM narration of database record diffs"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
7
7
  license = "Apache-2.0"
8
8
  authors = [{ name = "Mohammad Ausaf" }]
9
9
  dependencies = [
10
- "cfgit>=0.4.2,<0.5.0",
10
+ "cfgit>=0.4.4,<0.5.0",
11
11
  "httpx>=0.27",
12
12
  ]
13
13
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cfgit"
3
- version = "0.4.2"
3
+ version = "0.4.4"
4
4
  description = "Git-style history, diff, drift detection, and rollback for live database records without migrating or owning your datastore"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -108,6 +108,12 @@ class StorageAdapter(Protocol):
108
108
  def get_records(self, collection: str, record_ids: list[str]) -> dict[str, dict]: ...
109
109
  def get_heads(self, collection: str, record_ids: list[str]) -> dict[str, dict]: ...
110
110
 
111
+ # OPTIONAL cheap ref list for Engine._all_refs. Returns just the distinct
112
+ # (collection, record_id) pairs that have history — no doc, no per-row object
113
+ # materialization. Callers feature-detect and fall back to query_history when
114
+ # absent. On a remote store this is the difference between ~160ms and ~5s per load.
115
+ def list_history_refs(self) -> list[tuple[str, str]]: ...
116
+
111
117
  # history reads
112
118
  def get_head(self, collection: str, record_id: str) -> dict | None: ...
113
119
  def query_history(self, *, collection: str | None = None, record_id: str | None = None,
@@ -31,6 +31,20 @@ except ModuleNotFoundError as exc: # pragma: no cover
31
31
  raise ModuleNotFoundError("install cfgit[mongo] to use MongoAdapter") from exc
32
32
 
33
33
 
34
+ # MongoClient is thread-safe and connection-pooled by design, so one per URI can be shared
35
+ # across engines. A fresh client pays a full TLS+SRV handshake (~2s on Atlas); the UI builds
36
+ # an engine per request, so without this cache every /api/state re-handshakes. Keyed by URI.
37
+ _CLIENT_CACHE: dict[str, "MongoClient"] = {}
38
+
39
+
40
+ def _client_for(uri: str) -> "MongoClient":
41
+ client = _CLIENT_CACHE.get(uri)
42
+ if client is None:
43
+ client = MongoClient(uri)
44
+ _CLIENT_CACHE[uri] = client
45
+ return client
46
+
47
+
34
48
  class MongoAdapter:
35
49
  def __init__(self, *, project: ProjectConfig, env_name: str):
36
50
  env = project.envs[env_name]
@@ -42,9 +56,9 @@ class MongoAdapter:
42
56
  self.history_uri = env.history_uri or env.uri
43
57
  self.runtime_db_name = env.runtime_db or env.db
44
58
  self.history_db_name = env.history_db or env.db
45
- self.client = MongoClient(self.history_uri)
59
+ self.client = _client_for(self.history_uri)
46
60
  self.history_client = self.client
47
- self.runtime_client = self.client if self.runtime_uri == self.history_uri else MongoClient(self.runtime_uri)
61
+ self.runtime_client = self.client if self.runtime_uri == self.history_uri else _client_for(self.runtime_uri)
48
62
  self.db = self.runtime_client[self.runtime_db_name]
49
63
  self.history_db = self.history_client[self.history_db_name]
50
64
  self.history = self.history_db[project.history.history_collection]
@@ -115,6 +129,18 @@ class MongoAdapter:
115
129
  out[rid] = _history_row(row, with_doc=True)
116
130
  return out
117
131
 
132
+ def list_history_refs(self) -> list[tuple[str, str]]:
133
+ """Distinct (collection, record_id) pairs that have history, projected to just
134
+ those two fields — no doc, no per-row object churn. Feeds Engine._all_refs cheaply
135
+ (~160ms vs ~5s of pulling full rows on a remote store)."""
136
+ cursor = self.history.find(
137
+ {"env": self.env_name}, {"collection": 1, "record_id": 1, "_id": 0}
138
+ )
139
+ seen: set[tuple[str, str]] = set()
140
+ for row in cursor:
141
+ seen.add((str(row["collection"]), str(row["record_id"])))
142
+ return sorted(seen)
143
+
118
144
  def get_head(self, collection: str, record_id: str) -> dict | None:
119
145
  ptr = self.heads.find_one(self._head_query(collection, record_id))
120
146
  if not ptr:
@@ -10,6 +10,7 @@ from __future__ import annotations
10
10
  from copy import deepcopy
11
11
  from datetime import datetime, timezone
12
12
  import re
13
+ import threading
13
14
  from typing import Any
14
15
 
15
16
  from cfg.adapters.base import (
@@ -38,6 +39,25 @@ except ModuleNotFoundError as exc: # pragma: no cover
38
39
  _IDENT_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
39
40
 
40
41
 
42
+ # A psycopg connection is stateful and NOT safe to share across threads (unlike a
43
+ # thread-safe MongoClient). The UI builds an adapter per request on a threading server,
44
+ # so we cache one connection per (thread, URI): each thread reuses its own connection
45
+ # across requests — reclaiming the ~seconds-long TLS connect — without cross-thread sharing.
46
+ _CONN_CACHE = threading.local()
47
+
48
+
49
+ def _conn_for(uri: str) -> "psycopg.Connection":
50
+ cache = getattr(_CONN_CACHE, "by_uri", None)
51
+ if cache is None:
52
+ cache = {}
53
+ _CONN_CACHE.by_uri = cache
54
+ conn = cache.get(uri)
55
+ if conn is None or conn.closed:
56
+ conn = psycopg.connect(uri, autocommit=True, row_factory=dict_row)
57
+ cache[uri] = conn
58
+ return conn
59
+
60
+
41
61
  class PostgresAdapter:
42
62
  def __init__(self, *, project: ProjectConfig, env_name: str):
43
63
  env = project.envs[env_name]
@@ -45,7 +65,7 @@ class PostgresAdapter:
45
65
  raise ValueError(f"missing Postgres URI for env {env_name}")
46
66
  self.project = project
47
67
  self.env_name = env_name
48
- self.conn = psycopg.connect(env.uri, autocommit=True, row_factory=dict_row)
68
+ self.conn = _conn_for(env.uri)
49
69
  self.history_table_name = project.history.history_collection
50
70
  self.heads_table_name = project.history.heads_collection
51
71
  self.refs_table_name = project.branches.refs_collection
@@ -147,6 +167,17 @@ class PostgresAdapter:
147
167
  rows = cur.fetchall()
148
168
  return {str(row["record_id"]): _history_row(row) for row in rows}
149
169
 
170
+ def list_history_refs(self) -> list[tuple[str, str]]:
171
+ """Distinct (collection, record_id) pairs that have history — cheap two-column
172
+ scan for Engine._all_refs instead of materializing full rows via query_history."""
173
+ with self.conn.cursor() as cur:
174
+ cur.execute(
175
+ f"SELECT DISTINCT collection_name, record_id FROM {self.history_table} "
176
+ f"WHERE env = %s ORDER BY collection_name, record_id",
177
+ [self.env_name],
178
+ )
179
+ return [(str(row["collection_name"]), str(row["record_id"])) for row in cur.fetchall()]
180
+
150
181
  def get_head(self, collection: str, record_id: str) -> dict | None:
151
182
  with self.conn.cursor() as cur:
152
183
  cur.execute(
@@ -211,8 +242,12 @@ class PostgresAdapter:
211
242
  add_clause("oid LIKE %s", f"{oid}%")
212
243
 
213
244
  direction = "DESC" if order == "desc" else "ASC"
245
+ # Select only the columns _history_row reads, and pull the large `doc` jsonb only
246
+ # when the caller asked for it — SELECT * shipped doc on every with_doc=False call
247
+ # (e.g. _all_refs, log listing), which is wasted transfer on a remote store.
248
+ cols = _HISTORY_COLUMNS + (", doc" if with_doc else "")
214
249
  sql = (
215
- f"SELECT * FROM {self.history_table} "
250
+ f"SELECT {cols} FROM {self.history_table} "
216
251
  f"WHERE {' AND '.join(clauses)} "
217
252
  f"ORDER BY collection_name ASC, record_id ASC, seq {direction}"
218
253
  )
@@ -779,6 +814,13 @@ class PostgresAdapter:
779
814
  )
780
815
 
781
816
 
817
+ # Columns _history_row reads (everything except the large `doc` jsonb, added on demand).
818
+ _HISTORY_COLUMNS = (
819
+ "env, collection_name, record_id, seq, oid, parent_oid, message, author, "
820
+ "recorded_at, valid_from, valid_to, valid_from_estimated, op, git_shas, tags, meta"
821
+ )
822
+
823
+
782
824
  def _history_row(row: dict[str, Any], *, with_doc: bool = True) -> dict[str, Any]:
783
825
  out = {
784
826
  "env": row["env"],
@@ -2,13 +2,14 @@
2
2
  """DB-neutral cfgit engine."""
3
3
  from __future__ import annotations
4
4
 
5
+ from concurrent.futures import ThreadPoolExecutor
5
6
  from copy import deepcopy
6
7
  from dataclasses import dataclass
7
8
  from datetime import datetime, time, timezone
8
9
  import fnmatch
9
10
  import re
10
11
  import uuid
11
- from typing import Any
12
+ from typing import Any, Callable, TypeVar
12
13
 
13
14
  from cfg.adapters.base import ApplyItem, AtomicityUnavailable, NoSuchConfig, StorageAdapter
14
15
  from cfg.core.authz import authorize_mutation
@@ -42,6 +43,25 @@ class BranchingDisabled(ValueError):
42
43
  """Branch/PR commands require [branches] enabled = true."""
43
44
 
44
45
 
46
+ _T = TypeVar("_T")
47
+
48
+
49
+ def _gather(tasks: list[Callable[[], _T]]) -> list[_T]:
50
+ """Run independent, blocking adapter reads concurrently and return results in order.
51
+
52
+ The status/ref-list path issues several store round-trips with no data dependency on
53
+ each other (per-collection id distincts, batch heads/records, the history ref list).
54
+ Run serially they sum one RTT each — the whole residual latency on a remote store
55
+ (issue #31). pymongo/psycopg release the GIL during network I/O, so a thread pool turns
56
+ that sum into ~max(single op). Falls back to serial for 0/1 task (no pool overhead).
57
+ Exceptions propagate (first one wins), preserving the serial behavior on failure.
58
+ """
59
+ if len(tasks) <= 1:
60
+ return [t() for t in tasks]
61
+ with ThreadPoolExecutor(max_workers=min(len(tasks), 8)) as pool:
62
+ return list(pool.map(lambda t: t(), tasks))
63
+
64
+
45
65
  class Engine:
46
66
  def __init__(
47
67
  self,
@@ -494,10 +514,19 @@ class Engine:
494
514
  batch_records = getattr(self.adapter, "get_records", None)
495
515
  batch_heads = getattr(self.adapter, "get_heads", None)
496
516
  if callable(batch_records) and callable(batch_heads):
497
- for collection, record_ids in by_collection.items():
498
- for rid, live in batch_records(collection, record_ids).items():
517
+ # One get_records + one get_heads per collection, all independent — run them
518
+ # concurrently so their round-trips overlap instead of summing (issue #31).
519
+ colls = list(by_collection)
520
+ tasks: list[Callable[[], dict]] = []
521
+ for collection in colls:
522
+ ids = by_collection[collection]
523
+ tasks.append(lambda c=collection, i=ids: batch_records(c, i))
524
+ tasks.append(lambda c=collection, i=ids: batch_heads(c, i))
525
+ results = _gather(tasks)
526
+ for idx, collection in enumerate(colls):
527
+ for rid, live in results[2 * idx].items():
499
528
  live_by_ref[(collection, rid)] = live
500
- for rid, head in batch_heads(collection, record_ids).items():
529
+ for rid, head in results[2 * idx + 1].items():
501
530
  head_by_ref[(collection, rid)] = head
502
531
  return live_by_ref, head_by_ref
503
532
 
@@ -552,12 +581,13 @@ class Engine:
552
581
  untracked), so the snapshot records exactly which version it represents. Writes nothing.
553
582
  """
554
583
  refs = [ref] if ref else self._all_refs(include_history=False)
584
+ live_by_ref, head_by_ref = self._batch_live_and_heads(refs)
555
585
  items: list[dict[str, Any]] = []
556
586
  for item in sorted(refs, key=lambda r: (r.collection, r.record_id)):
557
- live = self.adapter.get_record(item.collection, item.record_id)
587
+ live = live_by_ref.get((item.collection, item.record_id))
558
588
  if live is None:
559
589
  continue
560
- head = self.adapter.get_head(item.collection, item.record_id)
590
+ head = head_by_ref.get((item.collection, item.record_id))
561
591
  items.append(
562
592
  {
563
593
  "record": f"{item.collection}:{item.record_id}",
@@ -583,9 +613,10 @@ class Engine:
583
613
  secret_groups: dict[tuple[str, str, str], dict[str, Any]] = {}
584
614
  large_groups: dict[tuple[str, str], dict[str, Any]] = {}
585
615
  invariant_violations = self.adapter.check_runtime_invariant(ref.collection if ref else None)
616
+ live_by_ref, _ = self._batch_live_and_heads(refs)
586
617
  scanned = 0
587
618
  for item in refs:
588
- live = self.adapter.get_record(item.collection, item.record_id)
619
+ live = live_by_ref.get((item.collection, item.record_id))
589
620
  if live is None:
590
621
  continue
591
622
  scanned += 1
@@ -1313,12 +1344,27 @@ class Engine:
1313
1344
 
1314
1345
  def _all_refs(self, *, include_history: bool) -> list[RecordRef]:
1315
1346
  refs: set[tuple[str, str]] = set()
1316
- for coll in self.config.collections:
1317
- for record_id in self.adapter.list_record_ids(coll.name):
1318
- refs.add((coll.name, record_id))
1347
+ # The per-collection live-id lookups and the history ref list are independent
1348
+ # round-trips; run them concurrently so they overlap instead of summing (issue #31).
1349
+ colls = [coll.name for coll in self.config.collections]
1350
+ tasks: list[Callable[[], list]] = [
1351
+ lambda c=name: [(c, rid) for rid in self.adapter.list_record_ids(c)] for name in colls
1352
+ ]
1353
+ # Prefer the cheap two-field history ref list; fall back to query_history for adapters
1354
+ # that don't implement it (it materializes every non-doc field of every history row).
1355
+ list_history_refs = getattr(self.adapter, "list_history_refs", None)
1319
1356
  if include_history:
1320
- for row in self.adapter.query_history(limit=None, order="asc", with_doc=False):
1321
- refs.add((row["collection"], row["record_id"]))
1357
+ if callable(list_history_refs):
1358
+ tasks.append(lambda: list(list_history_refs()))
1359
+ else:
1360
+ tasks.append(
1361
+ lambda: [
1362
+ (row["collection"], row["record_id"])
1363
+ for row in self.adapter.query_history(limit=None, order="asc", with_doc=False)
1364
+ ]
1365
+ )
1366
+ for pairs in _gather(tasks):
1367
+ refs.update(pairs)
1322
1368
  return [RecordRef(collection, record_id) for collection, record_id in refs]
1323
1369
 
1324
1370
  def _main_doc(self, ref: RecordRef) -> dict[str, Any] | None:
@@ -266,6 +266,11 @@ UI_HTML = r"""<!doctype html>
266
266
  --disp:"Space Grotesk",ui-sans-serif,system-ui,sans-serif;
267
267
  --body:"Inter",ui-sans-serif,system-ui,-apple-system,sans-serif;
268
268
  --mono:"JetBrains Mono",ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
269
+ /* dashed drift ring, drawn as an SVG stroke so the dashes divide the circumference
270
+ evenly (a CSS dashed border bunches them to one side, and too many small dashes read
271
+ as a fuzzy dotted ring). Used as a mask; color comes from --amber. 5 clean dashes:
272
+ (4.0 dash + 2.28 gap) x5 ~= circumference 2*pi*5 = 31.4. */
273
+ --drift-ring:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 13 13"><circle cx="6.5" cy="6.5" r="5" fill="none" stroke="black" stroke-width="1.8" stroke-dasharray="4.0 2.28" stroke-linecap="butt"/></svg>');
269
274
  }
270
275
  /* DARK: deep slate, never pure black; calm on the eyes.
271
276
  Accent is monochrome (ink) + a single restrained GitHub green for primary actions. */
@@ -479,7 +484,8 @@ UI_HTML = r"""<!doctype html>
479
484
  .node.sel{background:var(--panel2)}
480
485
  .node.sel::before{content:"";position:absolute;left:0;top:0;bottom:0;width:2px;background:var(--accent)}
481
486
  /* graph rail: vertical line + node markers */
482
- .node .line{position:absolute;left:21px;top:0;bottom:0;width:2px;background:var(--edge2)}
487
+ /* line center (20.5 + 2/2 = 21.5) is aligned to the marker center (15 + 13/2 = 21.5). */
488
+ .node .line{position:absolute;left:20.5px;top:0;bottom:0;width:2px;background:var(--edge2)}
483
489
  .node:first-child .line{top:20px}
484
490
  .node:last-child .line{bottom:calc(100% - 20px)}
485
491
  .node .mk{position:absolute;left:15px;top:14px;width:13px;height:13px;border-radius:50%;
@@ -488,8 +494,16 @@ UI_HTML = r"""<!doctype html>
488
494
  .node.restore .mk{border-color:var(--sky)}
489
495
  .node.adopt .mk{border-color:var(--moss)}
490
496
  .node.importt .mk{border-color:var(--faint)}
491
- /* drift = open dashed ring in amber, sitting above the committed line */
492
- .node.live .mk{border:2px dashed var(--amber);background:var(--amber-bg);width:14px;height:14px;left:14.5px;animation:pulse 2.4s ease-in-out infinite}
497
+ /* drift = open dashed ring in amber. A CSS `border:dashed` renders its dashes from a
498
+ fixed origin, so they bunch to one side and the ring reads as off-center. Instead we
499
+ draw the ring as an SVG stroke whose dash pattern divides the circumference evenly
500
+ (perfectly symmetric), applied as a mask so it still respects the theme amber var.
501
+ An opaque base fill (pane bg + amber tint) keeps the timeline rail from showing through. */
502
+ .node.live .mk{border:0;z-index:2;background:linear-gradient(var(--amber-bg),var(--amber-bg)),var(--panel);
503
+ animation:pulse 2.4s ease-in-out infinite}
504
+ .node.live .mk::after{content:"";position:absolute;inset:0;background:var(--amber);
505
+ -webkit-mask:var(--drift-ring) center/contain no-repeat;mask:var(--drift-ring) center/contain no-repeat}
506
+
493
507
  @keyframes pulse{0%,100%{box-shadow:0 0 0 0 var(--amber-bg)}50%{box-shadow:0 0 0 5px transparent}}
494
508
  .node .msg{font-size:13px;line-height:1.4;margin-bottom:4px}
495
509
  .node.live .msg{color:var(--amber);font-weight:500}
@@ -968,7 +982,7 @@ document.addEventListener("click",e=>{if(!e.target.closest(".selectbox"))closeSe
968
982
  document.addEventListener("keydown",e=>{if(e.key==="Escape")closeSelectMenus();});
969
983
  syncSelectMenus();
970
984
 
971
- async function loadState(){
985
+ async function loadState(isRefresh){
972
986
  const st=await fetch("/api/state?"+qs()).then(r=>r.json()).catch(e=>({error:String(e)}));
973
987
  if(st.data&&st.data.whoami){const w=st.data.whoami;S.who=w;const id=w.identity||{};
974
988
  const disp=w.identity_display||w.author||"";
@@ -995,7 +1009,10 @@ async function loadState(){
995
1009
  if(Object.keys(S.open).length===0){colls.forEach(c=>{S.open[c]=S.records.some(r=>r.collection===c&&isDrift(r.state));});
996
1010
  if(!Object.values(S.open).some(Boolean)&&colls[0])S.open[colls[0]]=true;}
997
1011
  renderFilters();renderTree();
998
- if(!S.sel&&!document.querySelector(".app")?.classList.contains("pr-mode")&&!document.querySelector(".app")?.classList.contains("branches-mode"))renderRecentHistory();
1012
+ // Auto-default to the History/Activity view only on the FIRST load. On a refresh, softRefresh()
1013
+ // restores whatever tab you were on — so refreshing on Records (with nothing selected) must not
1014
+ // yank you to History.
1015
+ if(!isRefresh&&!S.sel&&!document.querySelector(".app")?.classList.contains("pr-mode")&&!document.querySelector(".app")?.classList.contains("branches-mode"))renderRecentHistory();
999
1016
  }
1000
1017
 
1001
1018
  function branchNames(){return [...new Set((S.branches.length?S.branches.map(b=>b.name):["main"]).filter(Boolean))];}
@@ -1771,7 +1788,16 @@ $("find").addEventListener("input",e=>{S.q=e.target.value;renderTree();});
1771
1788
  // Reload state from the server but stay on the current tab/record — used by the Refresh
1772
1789
  // button and by auto-refresh so new drift/branches/PRs (created in a terminal or another
1773
1790
  // tab) show up without a manual reload.
1774
- function softRefresh(){const keep=S.sel, prMode=inPrMode(), branchesMode=inBranchesMode();return loadState().then(()=>{if(prMode)renderPrWorkspace();else if(branchesMode)renderBranchesWorkspace();else if(keep)selectRecord(keep);});}
1791
+ function inActivityMode(){return $("navHistoryTab")?.classList.contains("on");}
1792
+ function softRefresh(){const keep=S.sel, prMode=inPrMode(), branchesMode=inBranchesMode(), activityMode=inActivityMode();
1793
+ return loadState(true).then(()=>{
1794
+ if(prMode){renderPrWorkspace();return;}
1795
+ if(branchesMode){renderBranchesWorkspace();return;}
1796
+ if(activityMode){renderRecentHistory();return;}
1797
+ if(keep){selectRecord(keep);return;}
1798
+ // Records tab with nothing selected: stay put (tree already re-rendered above).
1799
+ setNav("navRecordsTab");
1800
+ });}
1775
1801
  $("refresh").onclick=()=>softRefresh();
1776
1802
  // Auto-refresh: pick up out-of-band changes without a manual reload. We skip while a modal
1777
1803
  // is open or a diff/impact panel is loading so we never yank the view out from under you.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes