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.
- plotroom/__init__.py +0 -0
- plotroom/__main__.py +8 -0
- plotroom/_secret_file.py +8 -0
- plotroom/adapters/__init__.py +0 -0
- plotroom/adapters/claude_desktop.py +219 -0
- plotroom/adapters/embedding_http.py +175 -0
- plotroom/adapters/github/__init__.py +337 -0
- plotroom/adapters/github/app_credential.py +209 -0
- plotroom/adapters/github/ci.py +738 -0
- plotroom/adapters/github/commit_statuses.py +63 -0
- plotroom/adapters/github/deployments.py +213 -0
- plotroom/adapters/github/details.py +867 -0
- plotroom/adapters/github/issue_details.py +368 -0
- plotroom/adapters/github/junit.py +210 -0
- plotroom/adapters/github/junit_xml.py +162 -0
- plotroom/adapters/github/kodus_review.py +347 -0
- plotroom/adapters/github/pr_details.py +192 -0
- plotroom/adapters/github/pull_comparison.py +108 -0
- plotroom/adapters/github/read.py +530 -0
- plotroom/adapters/github/ticket_tree.py +336 -0
- plotroom/adapters/mcp/__init__.py +5 -0
- plotroom/adapters/mcp/proxy.py +722 -0
- plotroom/adapters/mcp/server.py +931 -0
- plotroom/adapters/openrouter.py +151 -0
- plotroom/adapters/store_sqlite/__init__.py +6 -0
- plotroom/adapters/store_sqlite/actions_sql.py +148 -0
- plotroom/adapters/store_sqlite/asks_sql.py +153 -0
- plotroom/adapters/store_sqlite/backfill_sql.py +138 -0
- plotroom/adapters/store_sqlite/budgets_sql.py +102 -0
- plotroom/adapters/store_sqlite/checklists_sql.py +77 -0
- plotroom/adapters/store_sqlite/claims_sql.py +54 -0
- plotroom/adapters/store_sqlite/embedding_sql.py +275 -0
- plotroom/adapters/store_sqlite/github_sql.py +331 -0
- plotroom/adapters/store_sqlite/goals_sql.py +57 -0
- plotroom/adapters/store_sqlite/human_queue_sql.py +60 -0
- plotroom/adapters/store_sqlite/items_sql.py +129 -0
- plotroom/adapters/store_sqlite/lanes_sql.py +85 -0
- plotroom/adapters/store_sqlite/ledger_sql.py +506 -0
- plotroom/adapters/store_sqlite/migrate.py +194 -0
- plotroom/adapters/store_sqlite/migrations/env.py +36 -0
- plotroom/adapters/store_sqlite/migrations/script.py.mako +19 -0
- plotroom/adapters/store_sqlite/migrations/versions/0001_project_meta.py +23 -0
- plotroom/adapters/store_sqlite/migrations/versions/0002_event_log.py +40 -0
- plotroom/adapters/store_sqlite/migrations/versions/0003_next_items.py +49 -0
- plotroom/adapters/store_sqlite/migrations/versions/0004_actions.py +28 -0
- plotroom/adapters/store_sqlite/migrations/versions/0005_lanes.py +36 -0
- plotroom/adapters/store_sqlite/migrations/versions/0006_work_items.py +22 -0
- plotroom/adapters/store_sqlite/migrations/versions/0007_item_changes.py +33 -0
- plotroom/adapters/store_sqlite/migrations/versions/0008_claude_turn_aliases.py +30 -0
- plotroom/adapters/store_sqlite/migrations/versions/0009_github_projection.py +38 -0
- plotroom/adapters/store_sqlite/migrations/versions/0010_github_pull_freshness.py +37 -0
- plotroom/adapters/store_sqlite/migrations/versions/0011_github_resources.py +27 -0
- plotroom/adapters/store_sqlite/migrations/versions/0012_local_triggers_outbox.py +80 -0
- plotroom/adapters/store_sqlite/migrations/versions/0013_lane_claims.py +22 -0
- plotroom/adapters/store_sqlite/migrations/versions/0015_recurring_triggers.py +45 -0
- plotroom/adapters/store_sqlite/migrations/versions/0016_merge_controller.py +28 -0
- plotroom/adapters/store_sqlite/migrations/versions/0017_lane_checklists.py +36 -0
- plotroom/adapters/store_sqlite/migrations/versions/0018_guardrails.py +33 -0
- plotroom/adapters/store_sqlite/migrations/versions/0019_clerk_import_metadata.py +16 -0
- plotroom/adapters/store_sqlite/migrations/versions/0020_search.py +30 -0
- plotroom/adapters/store_sqlite/migrations/versions/0021_human_queue.py +46 -0
- plotroom/adapters/store_sqlite/migrations/versions/0022_search_records.py +77 -0
- plotroom/adapters/store_sqlite/migrations/versions/0023_operator_goals.py +25 -0
- plotroom/adapters/store_sqlite/migrations/versions/0024_embedding_rejections.py +36 -0
- plotroom/adapters/store_sqlite/outbox_sql.py +78 -0
- plotroom/adapters/store_sqlite/routes_sql.py +26 -0
- plotroom/adapters/store_sqlite/search_sql.py +116 -0
- plotroom/adapters/store_sqlite/store.py +623 -0
- plotroom/adapters/store_sqlite/triggers_sql.py +111 -0
- plotroom/adapters/store_sqlite/work_items_sql.py +36 -0
- plotroom/adapters/switchboard.py +152 -0
- plotroom/adapters/usage_fixture.py +11 -0
- plotroom/adapters/work_items_bmad.py +256 -0
- plotroom/adapters/work_items_github_issues.py +323 -0
- plotroom/app/__init__.py +0 -0
- plotroom/app/bridge.py +162 -0
- plotroom/app/clerk_import.py +349 -0
- plotroom/app/cli.py +290 -0
- plotroom/app/clock.py +12 -0
- plotroom/app/config.py +984 -0
- plotroom/app/daemon_start.py +453 -0
- plotroom/app/lock.py +77 -0
- plotroom/app/logging.py +93 -0
- plotroom/app/portfile.py +218 -0
- plotroom/app/runtime.py +518 -0
- plotroom/app/serve.py +671 -0
- plotroom/app/session_intake.py +51 -0
- plotroom/app/sqlite_floor.py +35 -0
- plotroom/app/tokens.py +265 -0
- plotroom/core/__init__.py +0 -0
- plotroom/core/actions.py +67 -0
- plotroom/core/ask_checks.py +124 -0
- plotroom/core/asks.py +123 -0
- plotroom/core/branch_updates.py +207 -0
- plotroom/core/bridge.py +112 -0
- plotroom/core/briefs.py +83 -0
- plotroom/core/budgets.py +182 -0
- plotroom/core/catalog.py +464 -0
- plotroom/core/checklists.py +151 -0
- plotroom/core/claims.py +296 -0
- plotroom/core/clerk_import.py +379 -0
- plotroom/core/commands.py +85 -0
- plotroom/core/deploy_window.py +21 -0
- plotroom/core/envelope.py +20 -0
- plotroom/core/events.py +227 -0
- plotroom/core/github.py +306 -0
- plotroom/core/github_projection.py +310 -0
- plotroom/core/goal_language.py +374 -0
- plotroom/core/goal_projection.py +146 -0
- plotroom/core/human_queue.py +119 -0
- plotroom/core/intake.py +106 -0
- plotroom/core/kodus_review.py +53 -0
- plotroom/core/lanes.py +281 -0
- plotroom/core/ledger.py +808 -0
- plotroom/core/merge_controller.py +344 -0
- plotroom/core/merge_flakes.py +422 -0
- plotroom/core/merge_gate.py +724 -0
- plotroom/core/merge_lane.py +70 -0
- plotroom/core/merge_overlap.py +76 -0
- plotroom/core/next_items.py +60 -0
- plotroom/core/operator_goals.py +103 -0
- plotroom/core/outbox.py +70 -0
- plotroom/core/pull_overlaps.py +152 -0
- plotroom/core/reports.py +62 -0
- plotroom/core/roles.py +100 -0
- plotroom/core/routing.py +55 -0
- plotroom/core/run_reports.py +53 -0
- plotroom/core/search.py +266 -0
- plotroom/core/search_sources.py +94 -0
- plotroom/core/snapshot.py +204 -0
- plotroom/core/trigger_actions.py +89 -0
- plotroom/core/triggers.py +550 -0
- plotroom/core/unit_of_work.py +541 -0
- plotroom/core/watchers.py +35 -0
- plotroom/core/work_items.py +23 -0
- plotroom/core/writer.py +164 -0
- plotroom/ports/__init__.py +6 -0
- plotroom/ports/clock.py +12 -0
- plotroom/ports/github_write.py +72 -0
- plotroom/ports/search.py +197 -0
- plotroom/ports/session_reader.py +23 -0
- plotroom/ports/store.py +323 -0
- plotroom/ports/usage_meter.py +35 -0
- plotroom/ports/work_items.py +22 -0
- plotroom/py.typed +0 -0
- plotroom-0.1.0.dist-info/METADATA +230 -0
- plotroom-0.1.0.dist-info/RECORD +150 -0
- plotroom-0.1.0.dist-info/WHEEL +4 -0
- plotroom-0.1.0.dist-info/entry_points.txt +2 -0
- plotroom-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
"""The ledger's SQL: the writer transaction and the event reads (SQLAlchemy Core, no ORM)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from collections.abc import Mapping
|
|
7
|
+
from fnmatch import fnmatchcase
|
|
8
|
+
from typing import TYPE_CHECKING, Any
|
|
9
|
+
|
|
10
|
+
from sqlalchemy import Row, text
|
|
11
|
+
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine
|
|
12
|
+
|
|
13
|
+
from plotroom.adapters.store_sqlite import (
|
|
14
|
+
actions_sql,
|
|
15
|
+
asks_sql,
|
|
16
|
+
backfill_sql,
|
|
17
|
+
budgets_sql,
|
|
18
|
+
checklists_sql,
|
|
19
|
+
claims_sql,
|
|
20
|
+
embedding_sql,
|
|
21
|
+
github_sql,
|
|
22
|
+
goals_sql,
|
|
23
|
+
human_queue_sql,
|
|
24
|
+
items_sql,
|
|
25
|
+
lanes_sql,
|
|
26
|
+
outbox_sql,
|
|
27
|
+
routes_sql,
|
|
28
|
+
search_sql,
|
|
29
|
+
triggers_sql,
|
|
30
|
+
work_items_sql,
|
|
31
|
+
)
|
|
32
|
+
from plotroom.core.actions import Action
|
|
33
|
+
from plotroom.core.ask_checks import Ask, IssueComment
|
|
34
|
+
from plotroom.core.claims import Claim
|
|
35
|
+
from plotroom.core.events import Event
|
|
36
|
+
from plotroom.core.github import FetchCursor, FetchRetry, PullRequest
|
|
37
|
+
from plotroom.core.github_projection import GitHubResource
|
|
38
|
+
from plotroom.core.goal_projection import StoredGoal
|
|
39
|
+
from plotroom.core.lanes import Lane
|
|
40
|
+
from plotroom.core.next_items import Item
|
|
41
|
+
from plotroom.core.search_sources import event_record
|
|
42
|
+
from plotroom.ports.search import (
|
|
43
|
+
BackfillPage,
|
|
44
|
+
BackfillPosition,
|
|
45
|
+
BackfillSource,
|
|
46
|
+
EmbeddingModel,
|
|
47
|
+
IndexedEmbedding,
|
|
48
|
+
SearchRecord,
|
|
49
|
+
)
|
|
50
|
+
from plotroom.ports.work_items import WorkItem
|
|
51
|
+
|
|
52
|
+
if TYPE_CHECKING:
|
|
53
|
+
from plotroom.core.budgets import Budget
|
|
54
|
+
from plotroom.core.checklists import Checklist
|
|
55
|
+
from plotroom.core.human_queue import Decision
|
|
56
|
+
from plotroom.core.outbox import OutboxLease, OutboxMessage
|
|
57
|
+
from plotroom.core.triggers import Trigger
|
|
58
|
+
|
|
59
|
+
FIND_EVENT = text(
|
|
60
|
+
"SELECT seq, id, source, kind, upstream_id, lane_id, fields, body, observed_at "
|
|
61
|
+
"FROM events WHERE source = :source AND kind = :kind AND upstream_id = :uid"
|
|
62
|
+
)
|
|
63
|
+
FIND_INDEX_EVENT = text("SELECT * FROM events WHERE seq = :seq AND id = :id AND kind = :kind")
|
|
64
|
+
LATEST_EVENT = text("""
|
|
65
|
+
SELECT events.* FROM events
|
|
66
|
+
WHERE kind = :kind AND seq > :after
|
|
67
|
+
AND NOT EXISTS (
|
|
68
|
+
SELECT 1 FROM json_each(:fields) AS expected
|
|
69
|
+
WHERE json_extract(events.fields, '$.' || expected.key) IS NOT expected.value
|
|
70
|
+
)
|
|
71
|
+
ORDER BY seq DESC LIMIT 1
|
|
72
|
+
""")
|
|
73
|
+
LATEST_RUN_REPORT = text("""
|
|
74
|
+
SELECT * FROM events
|
|
75
|
+
WHERE kind = 'run.status' AND json_extract(fields, '$.run_id') = :run_id
|
|
76
|
+
ORDER BY seq DESC LIMIT 1
|
|
77
|
+
""")
|
|
78
|
+
LANE_ACTIVITY = text("""
|
|
79
|
+
WITH scoped AS (
|
|
80
|
+
SELECT * FROM events
|
|
81
|
+
WHERE lane_id = :lane AND kind NOT IN ('core.trigger_fired', 'core.lane_marked')
|
|
82
|
+
ORDER BY seq DESC LIMIT 1
|
|
83
|
+
), receipts AS (
|
|
84
|
+
SELECT * FROM events
|
|
85
|
+
WHERE kind IN ('core.lane_start', 'core.lane_update', 'core.lane_ready',
|
|
86
|
+
'core.lane_archive', 'core.claim', 'core.release')
|
|
87
|
+
AND json_extract(fields, '$.args.lane') = :lane
|
|
88
|
+
ORDER BY seq DESC LIMIT 1
|
|
89
|
+
)
|
|
90
|
+
SELECT * FROM scoped UNION ALL SELECT * FROM receipts ORDER BY seq DESC LIMIT 1
|
|
91
|
+
""")
|
|
92
|
+
INSERT_EVENT = text(
|
|
93
|
+
"INSERT INTO events (seq, id, source, kind, upstream_id, lane_id, fields, body, observed_at) "
|
|
94
|
+
"VALUES (:seq, :id, :source, :kind, :uid, :lane_id, :fields, :body, :observed_at)"
|
|
95
|
+
)
|
|
96
|
+
FIND_CLAUDE_TURN = text("""
|
|
97
|
+
SELECT events.* FROM claude_turn_aliases AS matched JOIN events ON events.id = matched.event_id
|
|
98
|
+
WHERE matched.session = :session AND matched.alias = :alias
|
|
99
|
+
AND (:index_alias IS NULL OR NOT EXISTS (
|
|
100
|
+
SELECT 1 FROM claude_turn_aliases AS indexed
|
|
101
|
+
WHERE indexed.event_id = matched.event_id AND indexed.session = matched.session
|
|
102
|
+
AND indexed.alias GLOB 'index:*' AND indexed.alias != :index_alias
|
|
103
|
+
))
|
|
104
|
+
ORDER BY events.seq DESC LIMIT 1
|
|
105
|
+
""")
|
|
106
|
+
BIND_CLAUDE_TURN = text(
|
|
107
|
+
"INSERT INTO claude_turn_aliases (session, alias, event_id) VALUES (:session, :alias, :event) "
|
|
108
|
+
"ON CONFLICT DO NOTHING"
|
|
109
|
+
)
|
|
110
|
+
FIND_NOOP_RECEIPT = text(
|
|
111
|
+
"SELECT receipt FROM noop_command_receipts WHERE command = :command AND request_key = :key"
|
|
112
|
+
)
|
|
113
|
+
INSERT_NOOP_RECEIPT = text(
|
|
114
|
+
"INSERT INTO noop_command_receipts (command, request_key, receipt) "
|
|
115
|
+
"VALUES (:command, :key, :receipt)"
|
|
116
|
+
)
|
|
117
|
+
ALLOCATE_SEQ = text("UPDATE project_seq SET value = value + 1 WHERE id = 1 RETURNING value")
|
|
118
|
+
HEAD_SEQ = text("SELECT value FROM project_seq WHERE id = 1")
|
|
119
|
+
EVENTS_AFTER = text(
|
|
120
|
+
"SELECT seq, id, source, kind, upstream_id, lane_id, fields, body, observed_at "
|
|
121
|
+
"FROM events WHERE seq > :seq ORDER BY seq LIMIT max(:limit, 0)"
|
|
122
|
+
)
|
|
123
|
+
LATEST_MERGE_VERDICT = text("""
|
|
124
|
+
SELECT events.* FROM merge_verdicts JOIN events ON events.seq = merge_verdicts.event_seq
|
|
125
|
+
WHERE merge_verdicts.repository = :repository AND merge_verdicts.number = :number
|
|
126
|
+
""")
|
|
127
|
+
SAVE_MERGE_VERDICT = text("""
|
|
128
|
+
INSERT INTO merge_verdicts (repository, number, event_seq) VALUES (:repository, :number, :seq)
|
|
129
|
+
ON CONFLICT (repository, number) DO UPDATE SET event_seq = excluded.event_seq
|
|
130
|
+
""")
|
|
131
|
+
DEPLOY_FREEZE = text("SELECT value FROM project_meta WHERE key = 'merge.deploy_freeze'")
|
|
132
|
+
SAVE_DEPLOY_FREEZE = text("""
|
|
133
|
+
INSERT INTO project_meta (key, value) VALUES ('merge.deploy_freeze', :reason)
|
|
134
|
+
ON CONFLICT (key) DO UPDATE SET value = excluded.value
|
|
135
|
+
""")
|
|
136
|
+
CLEAR_DEPLOY_FREEZE = text("DELETE FROM project_meta WHERE key = 'merge.deploy_freeze'")
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def event_from_row(row: Row[Any]) -> Event:
|
|
140
|
+
return Event(
|
|
141
|
+
seq=row.seq,
|
|
142
|
+
id=row.id,
|
|
143
|
+
source=row.source,
|
|
144
|
+
kind=row.kind,
|
|
145
|
+
upstream_id=row.upstream_id,
|
|
146
|
+
lane_id=row.lane_id,
|
|
147
|
+
fields=json.loads(row.fields),
|
|
148
|
+
body=row.body,
|
|
149
|
+
observed_at=row.observed_at,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class SqliteTransaction:
|
|
154
|
+
"""Implements ``plotroom.ports.Transaction`` on the writer connection's open transaction."""
|
|
155
|
+
|
|
156
|
+
def __init__(self, connection: AsyncConnection) -> None:
|
|
157
|
+
self._connection = connection
|
|
158
|
+
self._expired = False
|
|
159
|
+
self._branch_candidates: dict[str, tuple[tuple[int, str], ...]] = {}
|
|
160
|
+
|
|
161
|
+
def expire(self) -> None:
|
|
162
|
+
"""End the handle's life with its transaction: the connection serves the next input."""
|
|
163
|
+
self._expired = True
|
|
164
|
+
|
|
165
|
+
def _live(self) -> AsyncConnection:
|
|
166
|
+
if self._expired:
|
|
167
|
+
raise RuntimeError("this transaction has ended; a retained handle cannot write")
|
|
168
|
+
return self._connection
|
|
169
|
+
|
|
170
|
+
async def find_event(self, source: str, kind: str, upstream_id: str) -> Event | None:
|
|
171
|
+
result = await self._live().execute(
|
|
172
|
+
FIND_EVENT, {"source": source, "kind": kind, "uid": upstream_id}
|
|
173
|
+
)
|
|
174
|
+
row = result.first()
|
|
175
|
+
return None if row is None else event_from_row(row)
|
|
176
|
+
|
|
177
|
+
async def latest_merge_verdict(self, repository: str, number: int) -> Event | None:
|
|
178
|
+
row = (
|
|
179
|
+
await self._live().execute(
|
|
180
|
+
LATEST_MERGE_VERDICT, {"repository": repository, "number": number}
|
|
181
|
+
)
|
|
182
|
+
).first()
|
|
183
|
+
return None if row is None else event_from_row(row)
|
|
184
|
+
|
|
185
|
+
async def save_merge_verdict(self, repository: str, number: int, seq: int) -> None:
|
|
186
|
+
await self._live().execute(
|
|
187
|
+
SAVE_MERGE_VERDICT, {"repository": repository, "number": number, "seq": seq}
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
async def latest_event(
|
|
191
|
+
self,
|
|
192
|
+
kind: str,
|
|
193
|
+
*,
|
|
194
|
+
fields: Mapping[str, str | bool] | None = None,
|
|
195
|
+
after: int = 0,
|
|
196
|
+
) -> Event | None:
|
|
197
|
+
result = await self._live().execute(
|
|
198
|
+
LATEST_EVENT,
|
|
199
|
+
{"kind": kind, "after": after, "fields": json.dumps(fields or {})},
|
|
200
|
+
)
|
|
201
|
+
row = result.first()
|
|
202
|
+
return None if row is None else event_from_row(row)
|
|
203
|
+
|
|
204
|
+
async def latest_run_report(self, run_id: str) -> Event | None:
|
|
205
|
+
row = (await self._live().execute(LATEST_RUN_REPORT, {"run_id": run_id})).first()
|
|
206
|
+
return None if row is None else event_from_row(row)
|
|
207
|
+
|
|
208
|
+
async def lane_activity(self, lane: str) -> Event | None:
|
|
209
|
+
row = (await self._live().execute(LANE_ACTIVITY, {"lane": lane})).first()
|
|
210
|
+
return None if row is None else event_from_row(row)
|
|
211
|
+
|
|
212
|
+
async def deploy_freeze(self) -> str | None:
|
|
213
|
+
return (await self._live().execute(DEPLOY_FREEZE)).scalar_one_or_none()
|
|
214
|
+
|
|
215
|
+
async def set_deploy_freeze(self, reason: str | None) -> None:
|
|
216
|
+
connection = self._live()
|
|
217
|
+
if reason is None:
|
|
218
|
+
await connection.execute(CLEAR_DEPLOY_FREEZE)
|
|
219
|
+
else:
|
|
220
|
+
await connection.execute(SAVE_DEPLOY_FREEZE, {"reason": reason})
|
|
221
|
+
|
|
222
|
+
async def insert_event(self, event: Event) -> None:
|
|
223
|
+
await self._live().execute(
|
|
224
|
+
INSERT_EVENT,
|
|
225
|
+
{
|
|
226
|
+
"seq": event.seq,
|
|
227
|
+
"id": event.id,
|
|
228
|
+
"source": event.source,
|
|
229
|
+
"kind": event.kind,
|
|
230
|
+
"uid": event.upstream_id,
|
|
231
|
+
"lane_id": event.lane_id,
|
|
232
|
+
"fields": json.dumps(event.fields, separators=(",", ":"), allow_nan=False),
|
|
233
|
+
"body": event.body,
|
|
234
|
+
"observed_at": event.observed_at,
|
|
235
|
+
},
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
async def index_event(self, engine: AsyncEngine, event: Event) -> None:
|
|
239
|
+
connection = self._live()
|
|
240
|
+
if connection.engine is not engine:
|
|
241
|
+
raise RuntimeError("cannot index an event through another project's transaction")
|
|
242
|
+
row = (
|
|
243
|
+
await connection.execute(
|
|
244
|
+
FIND_INDEX_EVENT, {"seq": event.seq, "id": event.id, "kind": event.kind}
|
|
245
|
+
)
|
|
246
|
+
).first()
|
|
247
|
+
if row is None:
|
|
248
|
+
raise RuntimeError("cannot index an event without its matching local event")
|
|
249
|
+
await search_sql.index_record(
|
|
250
|
+
connection, event_record(event_from_row(row)), only_if_absent=True
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
async def index_record(
|
|
254
|
+
self, engine: AsyncEngine, record: SearchRecord, *, only_if_absent: bool
|
|
255
|
+
) -> None:
|
|
256
|
+
connection = self._live()
|
|
257
|
+
if connection.engine is not engine:
|
|
258
|
+
raise RuntimeError("cannot index a record through another project's transaction")
|
|
259
|
+
await search_sql.index_record(connection, record, only_if_absent=only_if_absent)
|
|
260
|
+
|
|
261
|
+
async def commit_search_backfill(
|
|
262
|
+
self,
|
|
263
|
+
engine: AsyncEngine,
|
|
264
|
+
source: BackfillSource,
|
|
265
|
+
expected: BackfillPosition,
|
|
266
|
+
page: BackfillPage,
|
|
267
|
+
) -> bool:
|
|
268
|
+
connection = self._live()
|
|
269
|
+
if connection.engine is not engine:
|
|
270
|
+
raise RuntimeError("cannot backfill search through another project's transaction")
|
|
271
|
+
return await backfill_sql.commit(connection, source, expected, page)
|
|
272
|
+
|
|
273
|
+
async def commit_embedding_batch(
|
|
274
|
+
self,
|
|
275
|
+
engine: AsyncEngine,
|
|
276
|
+
model: EmbeddingModel,
|
|
277
|
+
expected: int,
|
|
278
|
+
through: int,
|
|
279
|
+
records: tuple[IndexedEmbedding, ...],
|
|
280
|
+
) -> bool:
|
|
281
|
+
connection = self._live()
|
|
282
|
+
if connection.engine is not engine:
|
|
283
|
+
raise RuntimeError("cannot index vectors through another project's transaction")
|
|
284
|
+
return await embedding_sql.commit_batch(connection, model, expected, through, records)
|
|
285
|
+
|
|
286
|
+
async def find_claude_turn(self, session: str, aliases: tuple[str, ...]) -> Event | None:
|
|
287
|
+
index = next((alias for alias in aliases if alias.startswith("index:")), None)
|
|
288
|
+
for alias in aliases:
|
|
289
|
+
result = await self._live().execute(
|
|
290
|
+
FIND_CLAUDE_TURN, {"session": session, "alias": alias, "index_alias": index}
|
|
291
|
+
)
|
|
292
|
+
if (row := result.first()) is not None:
|
|
293
|
+
return event_from_row(row)
|
|
294
|
+
return None
|
|
295
|
+
|
|
296
|
+
async def bind_claude_turn(self, session: str, aliases: tuple[str, ...], event: str) -> None:
|
|
297
|
+
await self._live().execute(
|
|
298
|
+
BIND_CLAUDE_TURN,
|
|
299
|
+
[{"session": session, "alias": alias, "event": event} for alias in aliases],
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
async def allocate_seq(self) -> int:
|
|
303
|
+
result = await self._live().execute(ALLOCATE_SEQ)
|
|
304
|
+
return int(result.scalar_one())
|
|
305
|
+
|
|
306
|
+
async def find_noop_receipt(self, command: str, key: str) -> dict[str, Any] | None:
|
|
307
|
+
value = (
|
|
308
|
+
await self._live().execute(FIND_NOOP_RECEIPT, {"command": command, "key": key})
|
|
309
|
+
).scalar_one_or_none()
|
|
310
|
+
receipt: dict[str, Any] | None = None if value is None else json.loads(value)
|
|
311
|
+
return receipt
|
|
312
|
+
|
|
313
|
+
async def insert_noop_receipt(self, command: str, key: str, receipt: dict[str, Any]) -> None:
|
|
314
|
+
await self._live().execute(
|
|
315
|
+
INSERT_NOOP_RECEIPT, {"command": command, "key": key, "receipt": json.dumps(receipt)}
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
async def active_item_subjects(self, kind: str) -> set[str]:
|
|
319
|
+
return await items_sql.active_item_subjects(self._live(), kind)
|
|
320
|
+
|
|
321
|
+
async def find_item(self, item_id: str) -> Item | None:
|
|
322
|
+
return await items_sql.find_item(self._live(), item_id)
|
|
323
|
+
|
|
324
|
+
async def active_item(self, key: str) -> Item | None:
|
|
325
|
+
return await items_sql.active_item(self._live(), key)
|
|
326
|
+
|
|
327
|
+
async def ready_work_items(self) -> tuple[WorkItem, ...]:
|
|
328
|
+
return await work_items_sql.ready_work_items(self._live())
|
|
329
|
+
|
|
330
|
+
async def replace_work_items(self, items: tuple[WorkItem, ...]) -> None:
|
|
331
|
+
await work_items_sql.replace_work_items(self._live(), items)
|
|
332
|
+
|
|
333
|
+
async def claimed_work_items(self) -> set[str]:
|
|
334
|
+
return await work_items_sql.claimed_work_items(self._live())
|
|
335
|
+
|
|
336
|
+
async def find_lane(self, lane_id: str) -> Lane | None:
|
|
337
|
+
return await lanes_sql.find_lane(self._live(), lane_id)
|
|
338
|
+
|
|
339
|
+
async def find_budget(self, run: str) -> Budget | None:
|
|
340
|
+
return await budgets_sql.find_budget(self._live(), run)
|
|
341
|
+
|
|
342
|
+
async def insert_budget(self, budget: Budget) -> None:
|
|
343
|
+
await budgets_sql.insert_budget(self._live(), budget)
|
|
344
|
+
|
|
345
|
+
async def reserve_openrouter_key(self, reservation: str, run: str) -> bool:
|
|
346
|
+
return await budgets_sql.reserve_openrouter_key(self._live(), reservation, run)
|
|
347
|
+
|
|
348
|
+
async def update_budget_spend(self, budget: Budget) -> None:
|
|
349
|
+
await budgets_sql.update_budget_spend(self._live(), budget)
|
|
350
|
+
|
|
351
|
+
async def has_routes(self) -> bool:
|
|
352
|
+
return await routes_sql.has_routes(self._live())
|
|
353
|
+
|
|
354
|
+
async def find_route(self, action_kind: str) -> str | None:
|
|
355
|
+
return await routes_sql.find_route(self._live(), action_kind)
|
|
356
|
+
|
|
357
|
+
async def save_route(self, action_kind: str, lane: str) -> None:
|
|
358
|
+
await routes_sql.save_route(self._live(), action_kind, lane)
|
|
359
|
+
|
|
360
|
+
async def worker_lane(self, worker: str) -> Lane | None:
|
|
361
|
+
return await lanes_sql.worker_lane(self._live(), worker)
|
|
362
|
+
|
|
363
|
+
async def branch_lane(self, branch: str) -> Lane | None:
|
|
364
|
+
return await lanes_sql.branch_lane(self._live(), branch)
|
|
365
|
+
|
|
366
|
+
async def branch_lanes(self, branch: str) -> list[Lane]:
|
|
367
|
+
return await lanes_sql.branch_lanes(self._live(), branch)
|
|
368
|
+
|
|
369
|
+
async def active_lanes(self) -> list[Lane]:
|
|
370
|
+
return await lanes_sql.board_lanes(self._live(), "orchestrator")
|
|
371
|
+
|
|
372
|
+
async def lane_claims(self, lane: str | None = None) -> list[Claim]:
|
|
373
|
+
return await claims_sql.read_claims(self._live(), "orchestrator", lane)
|
|
374
|
+
|
|
375
|
+
async def save_claims(self, claims: list[Claim]) -> None:
|
|
376
|
+
await claims_sql.save_claims(self._live(), claims)
|
|
377
|
+
|
|
378
|
+
async def delete_claims(self, lane: str, globs: list[str] | None) -> None:
|
|
379
|
+
await claims_sql.delete_claims(self._live(), lane, globs)
|
|
380
|
+
|
|
381
|
+
async def pull_request(self, repository: str, number: int) -> PullRequest | None:
|
|
382
|
+
return await github_sql.pull_request(self._live(), repository, number)
|
|
383
|
+
|
|
384
|
+
async def open_branch_pull(self, repository: str, branch: str) -> PullRequest | None:
|
|
385
|
+
return await github_sql.open_branch_pull(self._live(), repository, branch)
|
|
386
|
+
|
|
387
|
+
async def open_pulls(self, repository: str) -> tuple[PullRequest, ...]:
|
|
388
|
+
return await github_sql.open_pulls(self._live(), repository)
|
|
389
|
+
|
|
390
|
+
async def detail_capacity_exceeded(self, repository: str) -> bool:
|
|
391
|
+
return await github_sql.detail_capacity_exceeded(self._live(), repository)
|
|
392
|
+
|
|
393
|
+
async def save_pull_request(self, pull: PullRequest) -> None:
|
|
394
|
+
await github_sql.save_pull_request(self._live(), pull)
|
|
395
|
+
self._branch_candidates.pop(pull.repository, None)
|
|
396
|
+
|
|
397
|
+
async def github_resource(
|
|
398
|
+
self, repository: str, resource: str, scope: str = ""
|
|
399
|
+
) -> GitHubResource | None:
|
|
400
|
+
return await github_sql.github_resource(self._live(), repository, resource, scope)
|
|
401
|
+
|
|
402
|
+
async def save_github_resource(
|
|
403
|
+
self, repository: str, resource: str, scope: str, result: GitHubResource
|
|
404
|
+
) -> None:
|
|
405
|
+
await github_sql.save_github_resource(self._live(), repository, resource, scope, result)
|
|
406
|
+
|
|
407
|
+
async def fetch_cursor(self, repository: str, resource: str) -> FetchCursor | None:
|
|
408
|
+
return await github_sql.fetch_cursor(self._live(), repository, resource)
|
|
409
|
+
|
|
410
|
+
async def save_fetch_cursor(self, repository: str, resource: str, cursor: FetchCursor) -> None:
|
|
411
|
+
await github_sql.save_fetch_cursor(self._live(), repository, resource, cursor)
|
|
412
|
+
|
|
413
|
+
async def save_fetch_retry(
|
|
414
|
+
self, repository: str, resource: str, retry: FetchRetry | None
|
|
415
|
+
) -> None:
|
|
416
|
+
await github_sql.save_fetch_retry(self._live(), repository, resource, retry)
|
|
417
|
+
|
|
418
|
+
async def save_lane(self, lane: Lane) -> None:
|
|
419
|
+
await lanes_sql.save_lane(self._live(), lane)
|
|
420
|
+
|
|
421
|
+
async def find_checklist(self, lane: str) -> Checklist | None:
|
|
422
|
+
return await checklists_sql.find_checklist(self._live(), lane)
|
|
423
|
+
|
|
424
|
+
async def save_checklist(self, checklist: Checklist) -> None:
|
|
425
|
+
await checklists_sql.save_checklist(self._live(), checklist)
|
|
426
|
+
|
|
427
|
+
async def set_checklist_step_completion(
|
|
428
|
+
self, lane: str, version: int, step: str, completion_ref: str
|
|
429
|
+
) -> bool:
|
|
430
|
+
return await checklists_sql.set_checklist_step_completion(
|
|
431
|
+
self._live(), lane, version, step, completion_ref
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
async def insert_action(self, action: Action) -> None:
|
|
435
|
+
await actions_sql.insert_action(self._live(), action)
|
|
436
|
+
|
|
437
|
+
async def bridge_action(
|
|
438
|
+
self, workers: tuple[str, ...], now: str, act_id: str | None
|
|
439
|
+
) -> Action | None:
|
|
440
|
+
return await actions_sql.bridge_action(self._live(), workers, now, act_id)
|
|
441
|
+
|
|
442
|
+
async def update_action(self, action: Action) -> None:
|
|
443
|
+
await actions_sql.update_action(self._live(), action)
|
|
444
|
+
|
|
445
|
+
async def insert_outbox(self, message: OutboxMessage) -> None:
|
|
446
|
+
await outbox_sql.insert_outbox(self._live(), message)
|
|
447
|
+
|
|
448
|
+
async def lease_outbox(self, lease_id: str, now: str, expires_at: str) -> OutboxLease | None:
|
|
449
|
+
return await outbox_sql.lease_outbox(self._live(), lease_id, now, expires_at)
|
|
450
|
+
|
|
451
|
+
async def complete_outbox(self, lease_id: str, now: str) -> str | None:
|
|
452
|
+
return await outbox_sql.complete_outbox(self._live(), lease_id, now)
|
|
453
|
+
|
|
454
|
+
async def retire_stale_outbox(self, now: str) -> None:
|
|
455
|
+
await outbox_sql.retire_stale_outbox(self._live(), now)
|
|
456
|
+
|
|
457
|
+
async def find_trigger(self, trigger_id: str) -> Trigger | None:
|
|
458
|
+
return await triggers_sql.find_trigger(self._live(), trigger_id)
|
|
459
|
+
|
|
460
|
+
async def insert_decision(self, decision: Decision) -> None:
|
|
461
|
+
await human_queue_sql.insert_decision(self._live(), decision)
|
|
462
|
+
|
|
463
|
+
async def ask_for_comment(self, repository: str, comment_id: int) -> Ask | None:
|
|
464
|
+
return await asks_sql.ask_for_comment(self._live(), repository, comment_id)
|
|
465
|
+
|
|
466
|
+
async def find_ask(self, ask_id: str) -> Ask | None:
|
|
467
|
+
return await asks_sql.find_ask(self._live(), ask_id)
|
|
468
|
+
|
|
469
|
+
async def goals_use_blockers(self) -> bool:
|
|
470
|
+
return await goals_sql.goals_use_blockers(self._live())
|
|
471
|
+
|
|
472
|
+
async def save_goal(self, goal: StoredGoal) -> None:
|
|
473
|
+
await goals_sql.save_goal(self._live(), goal)
|
|
474
|
+
|
|
475
|
+
async def save_ask(self, ask: Ask) -> None:
|
|
476
|
+
await asks_sql.save_ask(self._live(), ask)
|
|
477
|
+
|
|
478
|
+
async def unsettled_asks(self, repository: str) -> list[Ask]:
|
|
479
|
+
return await asks_sql.unsettled_asks(self._live(), repository)
|
|
480
|
+
|
|
481
|
+
async def ask_comment_histories(
|
|
482
|
+
self, repository: str, issues: set[int]
|
|
483
|
+
) -> dict[int, tuple[str, frozenset[int]]]:
|
|
484
|
+
return await asks_sql.ask_comment_histories(self._live(), repository, issues)
|
|
485
|
+
|
|
486
|
+
async def ask_comments(
|
|
487
|
+
self, repository: str, issues: set[int]
|
|
488
|
+
) -> dict[int, list[IssueComment]]:
|
|
489
|
+
return await asks_sql.ask_comments(self._live(), repository, issues)
|
|
490
|
+
|
|
491
|
+
async def open_triggers(self) -> list[Trigger]:
|
|
492
|
+
return await triggers_sql.open_triggers(self._live())
|
|
493
|
+
|
|
494
|
+
async def save_trigger(self, trigger: Trigger) -> None:
|
|
495
|
+
await triggers_sql.save_trigger(self._live(), trigger)
|
|
496
|
+
|
|
497
|
+
async def first_matching_pull(self, repository: str, pattern: str) -> int | None:
|
|
498
|
+
connection = self._live()
|
|
499
|
+
candidates = self._branch_candidates.get(repository)
|
|
500
|
+
if candidates is None:
|
|
501
|
+
candidates = await triggers_sql.branch_candidates(connection, repository)
|
|
502
|
+
self._branch_candidates[repository] = candidates
|
|
503
|
+
return next((number for number, branch in candidates if fnmatchcase(branch, pattern)), None)
|
|
504
|
+
|
|
505
|
+
async def save_item(self, item: Item) -> None:
|
|
506
|
+
await items_sql.save_item(self._live(), item)
|