plotroom 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 (150) hide show
  1. plotroom/__init__.py +0 -0
  2. plotroom/__main__.py +8 -0
  3. plotroom/_secret_file.py +8 -0
  4. plotroom/adapters/__init__.py +0 -0
  5. plotroom/adapters/claude_desktop.py +219 -0
  6. plotroom/adapters/embedding_http.py +175 -0
  7. plotroom/adapters/github/__init__.py +337 -0
  8. plotroom/adapters/github/app_credential.py +209 -0
  9. plotroom/adapters/github/ci.py +738 -0
  10. plotroom/adapters/github/commit_statuses.py +63 -0
  11. plotroom/adapters/github/deployments.py +213 -0
  12. plotroom/adapters/github/details.py +867 -0
  13. plotroom/adapters/github/issue_details.py +368 -0
  14. plotroom/adapters/github/junit.py +210 -0
  15. plotroom/adapters/github/junit_xml.py +162 -0
  16. plotroom/adapters/github/kodus_review.py +347 -0
  17. plotroom/adapters/github/pr_details.py +192 -0
  18. plotroom/adapters/github/pull_comparison.py +108 -0
  19. plotroom/adapters/github/read.py +530 -0
  20. plotroom/adapters/github/ticket_tree.py +336 -0
  21. plotroom/adapters/mcp/__init__.py +5 -0
  22. plotroom/adapters/mcp/proxy.py +722 -0
  23. plotroom/adapters/mcp/server.py +931 -0
  24. plotroom/adapters/openrouter.py +151 -0
  25. plotroom/adapters/store_sqlite/__init__.py +6 -0
  26. plotroom/adapters/store_sqlite/actions_sql.py +148 -0
  27. plotroom/adapters/store_sqlite/asks_sql.py +153 -0
  28. plotroom/adapters/store_sqlite/backfill_sql.py +138 -0
  29. plotroom/adapters/store_sqlite/budgets_sql.py +102 -0
  30. plotroom/adapters/store_sqlite/checklists_sql.py +77 -0
  31. plotroom/adapters/store_sqlite/claims_sql.py +54 -0
  32. plotroom/adapters/store_sqlite/embedding_sql.py +275 -0
  33. plotroom/adapters/store_sqlite/github_sql.py +331 -0
  34. plotroom/adapters/store_sqlite/goals_sql.py +57 -0
  35. plotroom/adapters/store_sqlite/human_queue_sql.py +60 -0
  36. plotroom/adapters/store_sqlite/items_sql.py +129 -0
  37. plotroom/adapters/store_sqlite/lanes_sql.py +85 -0
  38. plotroom/adapters/store_sqlite/ledger_sql.py +506 -0
  39. plotroom/adapters/store_sqlite/migrate.py +194 -0
  40. plotroom/adapters/store_sqlite/migrations/env.py +36 -0
  41. plotroom/adapters/store_sqlite/migrations/script.py.mako +19 -0
  42. plotroom/adapters/store_sqlite/migrations/versions/0001_project_meta.py +23 -0
  43. plotroom/adapters/store_sqlite/migrations/versions/0002_event_log.py +40 -0
  44. plotroom/adapters/store_sqlite/migrations/versions/0003_next_items.py +49 -0
  45. plotroom/adapters/store_sqlite/migrations/versions/0004_actions.py +28 -0
  46. plotroom/adapters/store_sqlite/migrations/versions/0005_lanes.py +36 -0
  47. plotroom/adapters/store_sqlite/migrations/versions/0006_work_items.py +22 -0
  48. plotroom/adapters/store_sqlite/migrations/versions/0007_item_changes.py +33 -0
  49. plotroom/adapters/store_sqlite/migrations/versions/0008_claude_turn_aliases.py +30 -0
  50. plotroom/adapters/store_sqlite/migrations/versions/0009_github_projection.py +38 -0
  51. plotroom/adapters/store_sqlite/migrations/versions/0010_github_pull_freshness.py +37 -0
  52. plotroom/adapters/store_sqlite/migrations/versions/0011_github_resources.py +27 -0
  53. plotroom/adapters/store_sqlite/migrations/versions/0012_local_triggers_outbox.py +80 -0
  54. plotroom/adapters/store_sqlite/migrations/versions/0013_lane_claims.py +22 -0
  55. plotroom/adapters/store_sqlite/migrations/versions/0015_recurring_triggers.py +45 -0
  56. plotroom/adapters/store_sqlite/migrations/versions/0016_merge_controller.py +28 -0
  57. plotroom/adapters/store_sqlite/migrations/versions/0017_lane_checklists.py +36 -0
  58. plotroom/adapters/store_sqlite/migrations/versions/0018_guardrails.py +33 -0
  59. plotroom/adapters/store_sqlite/migrations/versions/0019_clerk_import_metadata.py +16 -0
  60. plotroom/adapters/store_sqlite/migrations/versions/0020_search.py +30 -0
  61. plotroom/adapters/store_sqlite/migrations/versions/0021_human_queue.py +46 -0
  62. plotroom/adapters/store_sqlite/migrations/versions/0022_search_records.py +77 -0
  63. plotroom/adapters/store_sqlite/migrations/versions/0023_operator_goals.py +25 -0
  64. plotroom/adapters/store_sqlite/migrations/versions/0024_embedding_rejections.py +36 -0
  65. plotroom/adapters/store_sqlite/outbox_sql.py +78 -0
  66. plotroom/adapters/store_sqlite/routes_sql.py +26 -0
  67. plotroom/adapters/store_sqlite/search_sql.py +116 -0
  68. plotroom/adapters/store_sqlite/store.py +623 -0
  69. plotroom/adapters/store_sqlite/triggers_sql.py +111 -0
  70. plotroom/adapters/store_sqlite/work_items_sql.py +36 -0
  71. plotroom/adapters/switchboard.py +152 -0
  72. plotroom/adapters/usage_fixture.py +11 -0
  73. plotroom/adapters/work_items_bmad.py +256 -0
  74. plotroom/adapters/work_items_github_issues.py +323 -0
  75. plotroom/app/__init__.py +0 -0
  76. plotroom/app/bridge.py +162 -0
  77. plotroom/app/clerk_import.py +349 -0
  78. plotroom/app/cli.py +290 -0
  79. plotroom/app/clock.py +12 -0
  80. plotroom/app/config.py +984 -0
  81. plotroom/app/daemon_start.py +453 -0
  82. plotroom/app/lock.py +77 -0
  83. plotroom/app/logging.py +93 -0
  84. plotroom/app/portfile.py +218 -0
  85. plotroom/app/runtime.py +518 -0
  86. plotroom/app/serve.py +671 -0
  87. plotroom/app/session_intake.py +51 -0
  88. plotroom/app/sqlite_floor.py +35 -0
  89. plotroom/app/tokens.py +265 -0
  90. plotroom/core/__init__.py +0 -0
  91. plotroom/core/actions.py +67 -0
  92. plotroom/core/ask_checks.py +124 -0
  93. plotroom/core/asks.py +123 -0
  94. plotroom/core/branch_updates.py +207 -0
  95. plotroom/core/bridge.py +112 -0
  96. plotroom/core/briefs.py +83 -0
  97. plotroom/core/budgets.py +182 -0
  98. plotroom/core/catalog.py +464 -0
  99. plotroom/core/checklists.py +151 -0
  100. plotroom/core/claims.py +296 -0
  101. plotroom/core/clerk_import.py +379 -0
  102. plotroom/core/commands.py +85 -0
  103. plotroom/core/deploy_window.py +21 -0
  104. plotroom/core/envelope.py +20 -0
  105. plotroom/core/events.py +227 -0
  106. plotroom/core/github.py +306 -0
  107. plotroom/core/github_projection.py +310 -0
  108. plotroom/core/goal_language.py +374 -0
  109. plotroom/core/goal_projection.py +146 -0
  110. plotroom/core/human_queue.py +119 -0
  111. plotroom/core/intake.py +106 -0
  112. plotroom/core/kodus_review.py +53 -0
  113. plotroom/core/lanes.py +281 -0
  114. plotroom/core/ledger.py +808 -0
  115. plotroom/core/merge_controller.py +344 -0
  116. plotroom/core/merge_flakes.py +422 -0
  117. plotroom/core/merge_gate.py +724 -0
  118. plotroom/core/merge_lane.py +70 -0
  119. plotroom/core/merge_overlap.py +76 -0
  120. plotroom/core/next_items.py +60 -0
  121. plotroom/core/operator_goals.py +103 -0
  122. plotroom/core/outbox.py +70 -0
  123. plotroom/core/pull_overlaps.py +152 -0
  124. plotroom/core/reports.py +62 -0
  125. plotroom/core/roles.py +100 -0
  126. plotroom/core/routing.py +55 -0
  127. plotroom/core/run_reports.py +53 -0
  128. plotroom/core/search.py +266 -0
  129. plotroom/core/search_sources.py +94 -0
  130. plotroom/core/snapshot.py +204 -0
  131. plotroom/core/trigger_actions.py +89 -0
  132. plotroom/core/triggers.py +550 -0
  133. plotroom/core/unit_of_work.py +541 -0
  134. plotroom/core/watchers.py +35 -0
  135. plotroom/core/work_items.py +23 -0
  136. plotroom/core/writer.py +164 -0
  137. plotroom/ports/__init__.py +6 -0
  138. plotroom/ports/clock.py +12 -0
  139. plotroom/ports/github_write.py +72 -0
  140. plotroom/ports/search.py +197 -0
  141. plotroom/ports/session_reader.py +23 -0
  142. plotroom/ports/store.py +323 -0
  143. plotroom/ports/usage_meter.py +35 -0
  144. plotroom/ports/work_items.py +22 -0
  145. plotroom/py.typed +0 -0
  146. plotroom-0.1.0.dist-info/METADATA +230 -0
  147. plotroom-0.1.0.dist-info/RECORD +150 -0
  148. plotroom-0.1.0.dist-info/WHEEL +4 -0
  149. plotroom-0.1.0.dist-info/entry_points.txt +2 -0
  150. plotroom-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,164 @@
1
+ """The per-project writer (AD-3, AD-14): one task, one connection, one transaction per input.
2
+
3
+ Inputs queue in arrival order and each runs in its own transaction on the one task that owns the
4
+ project's writer connection. A failed input rolls back and leaves the writer serving the next.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import asyncio
10
+ import contextvars
11
+ from collections.abc import Awaitable, Callable
12
+ from typing import Any
13
+
14
+ from plotroom.core.events import LedgerError
15
+ from plotroom.ports.store import Store, Transaction
16
+
17
+ type _Item = tuple[
18
+ Callable[[Transaction], Awaitable[Any]],
19
+ asyncio.Future[Any],
20
+ bool,
21
+ Callable[[Any], None] | None,
22
+ ]
23
+
24
+
25
+ # The writer whose transaction the current task is running work in, if any
26
+ _WORKING_FOR: contextvars.ContextVar[ProjectWriter | None] = contextvars.ContextVar(
27
+ "plotroom_working_for", default=None
28
+ )
29
+
30
+
31
+ def _unavailable() -> LedgerError:
32
+ return LedgerError("unavailable", "the project's ledger writer is not running")
33
+
34
+
35
+ class ProjectWriter:
36
+ """Serializes every write to one project's store."""
37
+
38
+ def __init__(self, store: Store) -> None:
39
+ self._store = store
40
+ self._queue: asyncio.Queue[_Item | None] | None = None
41
+ self._task: asyncio.Task[None] | None = None
42
+ self._accepting = False
43
+ self.commit_signal = asyncio.Event()
44
+
45
+ @property
46
+ def running(self) -> bool:
47
+ return self._accepting
48
+
49
+ def start(self) -> None:
50
+ """Start the writer task. Needs a running event loop."""
51
+ if self._task is not None and not self._task.done():
52
+ raise RuntimeError("the writer is already running")
53
+ self.commit_signal = asyncio.Event()
54
+ queue: asyncio.Queue[_Item | None] = asyncio.Queue()
55
+ self._queue = queue
56
+ self._accepting = True
57
+ self._task = asyncio.get_running_loop().create_task(self._run(queue))
58
+
59
+ async def stop(self) -> None:
60
+ """Stop accepting inputs, finish the queued ones, then end the task.
61
+
62
+ Canceling the caller does not cancel the draining: the task is awaited shielded.
63
+ """
64
+ if _WORKING_FOR.get() is self:
65
+ raise RuntimeError("re-entrant stop: the writer cannot be stopped from inside its work")
66
+ queue, task = self._queue, self._task
67
+ if task is None or queue is None:
68
+ return
69
+ if self._accepting:
70
+ self._accepting = False
71
+ queue.put_nowait(None)
72
+ try:
73
+ await asyncio.shield(task)
74
+ except asyncio.CancelledError:
75
+ if not task.cancelled(): # the caller was canceled, not the writer task
76
+ raise
77
+
78
+ async def submit[T](self, work: Callable[[Transaction], Awaitable[T]]) -> T:
79
+ """Run ``work`` in its own transaction on the writer and return its result.
80
+
81
+ ``LedgerError("unavailable")`` when the writer is not running. A caller canceled while
82
+ queued is skipped; one canceled while its transaction runs does not interrupt it.
83
+ ``RuntimeError`` when called from inside work running on this writer: it would wait
84
+ behind itself. The backlog is not capped: inputs are bounded by the transport's request
85
+ size, and a cap with backpressure belongs with the transport limits.
86
+ """
87
+ return await self.enqueue(work)
88
+
89
+ def enqueue[T](
90
+ self,
91
+ work: Callable[[Transaction], Awaitable[T]],
92
+ *,
93
+ notify: bool = True,
94
+ after_commit: Callable[[T], None] | None = None,
95
+ ) -> asyncio.Future[T]:
96
+ """Queue an input; publish its committed result before waking waiters.
97
+
98
+ Metadata-only writes can opt out of waking commit waiters.
99
+ """
100
+ if _WORKING_FOR.get() is self:
101
+ raise RuntimeError("re-entrant submit: use the UnitOfWork inside work")
102
+ queue = self._queue
103
+ if not self._accepting or queue is None:
104
+ raise _unavailable()
105
+ future: asyncio.Future[T] = asyncio.get_running_loop().create_future()
106
+ queue.put_nowait((work, future, notify, after_commit))
107
+ return future
108
+
109
+ async def _run(self, queue: asyncio.Queue[_Item | None]) -> None:
110
+ try:
111
+ while True:
112
+ item = await queue.get()
113
+ if item is None:
114
+ return
115
+ work, future, notify, after_commit = item
116
+ if future.cancelled():
117
+ continue
118
+ try:
119
+ async with self._store.transaction() as tx:
120
+ token = _WORKING_FOR.set(self)
121
+ try:
122
+ result = await work(tx)
123
+ finally:
124
+ _WORKING_FOR.reset(token)
125
+ except Exception as exc:
126
+ if not future.done():
127
+ future.set_exception(exc)
128
+ except asyncio.CancelledError:
129
+ current = asyncio.current_task()
130
+ if current is not None and current.cancelling():
131
+ # the writer itself was canceled: fail this input and end
132
+ if not future.done():
133
+ future.set_exception(_unavailable())
134
+ raise
135
+ # the work awaited something canceled elsewhere: the transaction has rolled
136
+ # back, this input fails, and the writer keeps serving the queue
137
+ if not future.done():
138
+ future.set_exception(
139
+ LedgerError(
140
+ "unavailable", "the input was canceled; nothing was written"
141
+ )
142
+ )
143
+ except BaseException:
144
+ if not future.done():
145
+ future.set_exception(_unavailable())
146
+ raise
147
+ else:
148
+ if after_commit is not None:
149
+ try:
150
+ after_commit(result)
151
+ except Exception as exc:
152
+ if not future.done():
153
+ future.set_exception(exc)
154
+ if notify:
155
+ committed, self.commit_signal = self.commit_signal, asyncio.Event()
156
+ committed.set()
157
+ if not future.done():
158
+ future.set_result(result)
159
+ finally:
160
+ self._accepting = False
161
+ while not queue.empty():
162
+ leftover = queue.get_nowait()
163
+ if leftover is not None and not leftover[1].done():
164
+ leftover[1].set_exception(_unavailable())
@@ -0,0 +1,6 @@
1
+ """Interfaces the core needs; adapters implement them."""
2
+
3
+ from plotroom.ports.clock import Clock
4
+ from plotroom.ports.store import Store, Transaction
5
+
6
+ __all__ = ["Clock", "Store", "Transaction"]
@@ -0,0 +1,12 @@
1
+ """The ``Clock`` port: core's only source of time (AD-2)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import datetime
6
+ from typing import Protocol
7
+
8
+
9
+ class Clock(Protocol):
10
+ def now(self) -> datetime:
11
+ """The current moment as a timezone-aware ``datetime``."""
12
+ ...
@@ -0,0 +1,72 @@
1
+ """Two expected-head operations for the local GitHub write fixture."""
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Literal, Protocol
5
+
6
+ from plotroom.core.merge_gate import GateSnapshot
7
+
8
+ type BranchUpdateOutcome = Literal["updated", "conflict"]
9
+
10
+
11
+ @dataclass(frozen=True)
12
+ class BranchUpdateReceipt:
13
+ outcome: BranchUpdateOutcome
14
+ main_sha: str
15
+ repository: str
16
+ number: int
17
+ head_sha: str
18
+ action_key: str
19
+ operation: str = "branch_update"
20
+
21
+
22
+ class FixtureGitHubWrite(Protocol):
23
+ async def update_branch(
24
+ self,
25
+ *,
26
+ repository: str,
27
+ number: int,
28
+ action_key: str,
29
+ expected_head_sha: str,
30
+ expected_main_sha: str | None,
31
+ recovery_only: bool = False,
32
+ ) -> BranchUpdateReceipt | None:
33
+ """Apply once per action key and return the recorded outcome on retry.
34
+
35
+ Scope the key to the repository and PR. Return the recorded receipt
36
+ before testing current SHAs. Recovery-only
37
+ calls can only return a receipt. New effects require both exact SHAs.
38
+ A recovery-only None means no receipt is available. A write-capable
39
+ None confirms that the request had no effect, such as a ref mismatch.
40
+ An uncertain write raises instead. Receipts bind the operation and exact
41
+ applied pins to the caller's action identity.
42
+ """
43
+ ...
44
+
45
+ async def merge(
46
+ self,
47
+ *,
48
+ repository: str,
49
+ number: int,
50
+ action_key: str,
51
+ expected_head_sha: str,
52
+ expected_main_sha: str,
53
+ method: Literal["merge", "squash", "rebase"],
54
+ evidence_revision: str,
55
+ ) -> bool:
56
+ """Atomically apply the exact evidence revision, refs, and method at most once."""
57
+ ...
58
+
59
+
60
+ @dataclass(frozen=True)
61
+ class FixtureMergeEvidence:
62
+ snapshot: GateSnapshot | None
63
+ revision: str
64
+ applied: bool = False
65
+
66
+
67
+ class FixtureGitHubMerge(FixtureGitHubWrite, Protocol):
68
+ async def merge_evidence(
69
+ self, *, repository: str, number: int, action_key: str
70
+ ) -> FixtureMergeEvidence:
71
+ """Read authoritative current facts or a durable receipt for this exact action key."""
72
+ ...
@@ -0,0 +1,197 @@
1
+ """A project's searchable records and their transaction-bound write path."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from enum import StrEnum
7
+ from typing import Protocol
8
+
9
+ from plotroom.core.events import Event
10
+ from plotroom.ports.store import Transaction
11
+
12
+ DEFAULT_SEARCH_LIMIT = 20
13
+ MAX_SEARCH_LIMIT = 100
14
+ MAX_SEARCH_QUERY_LENGTH = 512
15
+ MESSAGE_KIND = "switchboard.message"
16
+ DECISION_KIND = "decision"
17
+ ASK_KIND = "ask"
18
+ ISSUE_COMMENT_KIND = "github.issue_comment"
19
+ PR_BODY_KIND = "github.pr_body"
20
+
21
+
22
+ @dataclass(frozen=True)
23
+ class SearchRecord:
24
+ kind: str
25
+ id: str
26
+ body: str
27
+ provisional: bool = False
28
+
29
+
30
+ @dataclass(frozen=True)
31
+ class SearchHit:
32
+ id: str
33
+ kind: str
34
+ excerpt: str
35
+ # Half-open bounds of the lexical match within the excerpt.
36
+ match_span: tuple[int, int] | None = field(default=None, compare=False, repr=False)
37
+
38
+
39
+ @dataclass(frozen=True)
40
+ class SearchPage:
41
+ hits: tuple[SearchHit, ...]
42
+ total: int
43
+ mode: str | None = None
44
+ fallback_reason: str | None = None
45
+
46
+
47
+ class Search(Protocol):
48
+ @property
49
+ def project_id(self) -> str: ...
50
+
51
+ async def index(self, tx: Transaction, event: Event) -> None:
52
+ """Project a new event using the same writer transaction that stored it."""
53
+ ...
54
+
55
+ async def index_record(
56
+ self, tx: Transaction, record: SearchRecord, *, only_if_absent: bool = False
57
+ ) -> None:
58
+ """Store source text, preserving a confirmed record in insert-if-absent mode."""
59
+ ...
60
+
61
+ async def query(
62
+ self, project: str, text: str, kinds: tuple[str, ...] | None, limit: int
63
+ ) -> SearchPage:
64
+ """Find a literal phrase and count all matches in the selected project and kinds."""
65
+ ...
66
+
67
+
68
+ class BackfillSource(StrEnum):
69
+ EVENTS = "events"
70
+ DECISIONS = "decisions"
71
+ ASKS = "asks"
72
+ COMMENTS = "comments"
73
+ PULLS = "pulls"
74
+
75
+
76
+ # An empty position starts a source. None marks it complete.
77
+ type BackfillPosition = tuple[str | int, ...] | None
78
+
79
+
80
+ @dataclass(frozen=True)
81
+ class BackfillPage:
82
+ through: BackfillPosition
83
+ records: tuple[SearchRecord, ...] = ()
84
+
85
+
86
+ class SearchBackfill(Protocol):
87
+ @property
88
+ def project_id(self) -> str: ...
89
+
90
+ async def backfill_position(self, source: BackfillSource) -> BackfillPosition: ...
91
+
92
+ async def backfill_page(
93
+ self, source: BackfillSource, after: tuple[str | int, ...], limit: int
94
+ ) -> BackfillPage: ...
95
+
96
+ async def commit_backfill(
97
+ self,
98
+ tx: Transaction,
99
+ source: BackfillSource,
100
+ expected: BackfillPosition,
101
+ page: BackfillPage,
102
+ ) -> bool:
103
+ """Insert missing records and advance the checkpoint from the expected position."""
104
+ ...
105
+
106
+
107
+ class EmbeddingError(Exception):
108
+ """The provider failed to return a usable batch."""
109
+
110
+
111
+ class EmbeddingPending(Exception):
112
+ """At least one requested source is still being indexed."""
113
+
114
+
115
+ class EmbeddingRejection(StrEnum):
116
+ INPUT_TOO_LARGE = "input_too_large"
117
+
118
+
119
+ type EmbeddingOutcome = tuple[float, ...] | EmbeddingRejection
120
+
121
+
122
+ @dataclass(frozen=True)
123
+ class EmbeddingModel:
124
+ name: str
125
+ dimension: int
126
+
127
+
128
+ @dataclass(frozen=True)
129
+ class EmbeddedRecord:
130
+ seq: int
131
+ kind: str
132
+ id: str
133
+ vector: bytes
134
+
135
+
136
+ @dataclass(frozen=True)
137
+ class RejectedRecord:
138
+ seq: int
139
+ kind: str
140
+ id: str
141
+ reason: EmbeddingRejection
142
+
143
+
144
+ type IndexedEmbedding = EmbeddedRecord | RejectedRecord
145
+
146
+
147
+ @dataclass(frozen=True)
148
+ class EmbeddingRevision:
149
+ seq: int
150
+ record: SearchRecord | None
151
+
152
+
153
+ class Embedder(Protocol):
154
+ async def embed(self, texts: tuple[str, ...]) -> tuple[EmbeddingOutcome, ...]:
155
+ """Return one vector or confirmed input rejection per input, in order."""
156
+ ...
157
+
158
+
159
+ class EmbeddingReadiness(StrEnum):
160
+ EMPTY = "empty"
161
+ READY = "ready"
162
+ PENDING = "pending"
163
+ REJECTED_MATCH = "rejected_match"
164
+
165
+
166
+ class EmbeddingIndex(Protocol):
167
+ @property
168
+ def project_id(self) -> str: ...
169
+
170
+ @property
171
+ def model(self) -> EmbeddingModel: ...
172
+
173
+ async def cursor(self) -> int: ...
174
+
175
+ async def revisions_after(self, after: int, limit: int) -> list[EmbeddingRevision]: ...
176
+
177
+ async def preflight(
178
+ self, kinds: tuple[str, ...], text: str | None = None
179
+ ) -> EmbeddingReadiness:
180
+ """Check whether it is worth requesting a query vector for these sources."""
181
+ ...
182
+
183
+ async def commit(
184
+ self, tx: Transaction, expected: int, through: int, records: tuple[IndexedEmbedding, ...]
185
+ ) -> bool:
186
+ """Write the batch and advance its cursor together, or return False for a stale attempt."""
187
+ ...
188
+
189
+ async def query_vector(
190
+ self,
191
+ project: str,
192
+ vector: tuple[float, ...],
193
+ limit: int,
194
+ *,
195
+ kinds: tuple[str, ...] | None = None,
196
+ text: str | None = None,
197
+ ) -> SearchPage: ...
@@ -0,0 +1,23 @@
1
+ """Read normalized inbound signals from local session state."""
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Protocol
5
+
6
+
7
+ @dataclass(frozen=True)
8
+ class SessionEvent:
9
+ kind: str
10
+ session_id: str
11
+ body: str
12
+ upstream_id: str | None = None
13
+ turn_index: int | None = None
14
+
15
+
16
+ class SessionReader(Protocol):
17
+ async def read(self, session_id: str) -> tuple[SessionEvent, ...]:
18
+ """Return observations after the last accepted checkpoint."""
19
+ ...
20
+
21
+ def accept(self, session_id: str) -> None:
22
+ """Advance after the caller has handled the most recent read."""
23
+ ...