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,194 @@
|
|
|
1
|
+
"""Alembic wiring: one linear history, run on the store's own connection."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import sqlite3
|
|
8
|
+
import stat
|
|
9
|
+
import tempfile
|
|
10
|
+
from contextlib import closing
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from time import monotonic, time_ns
|
|
13
|
+
|
|
14
|
+
from alembic import command
|
|
15
|
+
from alembic.config import Config
|
|
16
|
+
from alembic.script import ScriptDirectory
|
|
17
|
+
from sqlalchemy import Connection
|
|
18
|
+
from sqlalchemy.ext.asyncio import AsyncEngine
|
|
19
|
+
|
|
20
|
+
MIGRATIONS_DIR = Path(__file__).parent / "migrations"
|
|
21
|
+
_BACKUP_TIMEOUT_SECONDS = 60
|
|
22
|
+
_BACKUP_LOCK_WAIT_SECONDS = 5
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def alembic_config(script_location: Path = MIGRATIONS_DIR) -> Config:
|
|
26
|
+
cfg = Config()
|
|
27
|
+
# Alembic reads options through ConfigParser, where a literal "%" must be written "%%"
|
|
28
|
+
cfg.set_main_option("script_location", str(script_location).replace("%", "%%"))
|
|
29
|
+
return cfg
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def script_heads(cfg: Config | None = None) -> list[str]:
|
|
33
|
+
"""Every head in the history; CI fails when there is more than one."""
|
|
34
|
+
return list(ScriptDirectory.from_config(cfg or alembic_config()).get_heads())
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def head_revision(cfg: Config | None = None) -> str:
|
|
38
|
+
heads = script_heads(cfg)
|
|
39
|
+
if len(heads) != 1:
|
|
40
|
+
raise RuntimeError(f"migration history must have exactly one head, found {heads}")
|
|
41
|
+
return heads[0]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _upgrade(connection: Connection, cfg: Config) -> None:
|
|
45
|
+
cfg.attributes["connection"] = connection
|
|
46
|
+
command.upgrade(cfg, "head")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
async def upgrade_to_head(engine: AsyncEngine, cfg: Config | None = None) -> None:
|
|
50
|
+
"""Bring the project file the engine points at to the head revision."""
|
|
51
|
+
cfg = cfg or alembic_config()
|
|
52
|
+
head_revision(cfg)
|
|
53
|
+
async with engine.begin() as connection:
|
|
54
|
+
await connection.run_sync(_upgrade, cfg)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class ProjectMigrationError(RuntimeError):
|
|
58
|
+
"""A project file cannot be safely opened or migrated."""
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _current_revision(source: sqlite3.Connection) -> str | None:
|
|
62
|
+
table = source.execute(
|
|
63
|
+
"SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = 'alembic_version'"
|
|
64
|
+
).fetchone()
|
|
65
|
+
if table is None:
|
|
66
|
+
return None
|
|
67
|
+
rows = source.execute("SELECT version_num FROM alembic_version LIMIT 2").fetchall()
|
|
68
|
+
if not rows:
|
|
69
|
+
return None
|
|
70
|
+
revision = rows[0][0]
|
|
71
|
+
if len(rows) != 1 or not isinstance(revision, str):
|
|
72
|
+
raise ProjectMigrationError("invalid project schema revision record")
|
|
73
|
+
return revision
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _backup(source: sqlite3.Connection, path: Path) -> None:
|
|
77
|
+
_copy_backup(source, path.parent / "migration-backups", f"{path.name}.pre-migration-")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _copy_backup(source: sqlite3.Connection, directory: Path, prefix: str) -> Path:
|
|
81
|
+
directory.mkdir(mode=0o700, exist_ok=True)
|
|
82
|
+
info = directory.lstat()
|
|
83
|
+
if (
|
|
84
|
+
not stat.S_ISDIR(info.st_mode)
|
|
85
|
+
or info.st_uid != os.geteuid()
|
|
86
|
+
or stat.S_IMODE(info.st_mode) & 0o077
|
|
87
|
+
):
|
|
88
|
+
raise ProjectMigrationError(
|
|
89
|
+
"migration backup directory must be private and owned by the daemon"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
fd, name = tempfile.mkstemp(prefix=f".{prefix}", suffix=".tmp", dir=directory)
|
|
93
|
+
staging = Path(name)
|
|
94
|
+
try:
|
|
95
|
+
started = monotonic()
|
|
96
|
+
busy_until = started + _BACKUP_LOCK_WAIT_SECONDS
|
|
97
|
+
finish_by = started + _BACKUP_TIMEOUT_SECONDS
|
|
98
|
+
|
|
99
|
+
def progress(status: int, _remaining: int, _total: int) -> None:
|
|
100
|
+
nonlocal busy_until
|
|
101
|
+
now = monotonic()
|
|
102
|
+
if status in (sqlite3.SQLITE_BUSY, sqlite3.SQLITE_LOCKED) and now >= busy_until:
|
|
103
|
+
raise ProjectMigrationError("SQLite backup could not obtain a read lock")
|
|
104
|
+
# Other connections can restart the copy even when a step reports success.
|
|
105
|
+
if status != sqlite3.SQLITE_DONE and now >= finish_by:
|
|
106
|
+
raise ProjectMigrationError("SQLite backup exceeded its deadline")
|
|
107
|
+
if status == sqlite3.SQLITE_OK:
|
|
108
|
+
busy_until = now + _BACKUP_LOCK_WAIT_SECONDS
|
|
109
|
+
|
|
110
|
+
with closing(sqlite3.connect(staging)) as target:
|
|
111
|
+
source.backup(target, pages=256, progress=progress)
|
|
112
|
+
# The published backup must be a single self-contained file, even for a WAL source.
|
|
113
|
+
if target.execute("PRAGMA journal_mode=DELETE").fetchone() != ("delete",):
|
|
114
|
+
raise ProjectMigrationError("SQLite backup could not leave WAL mode")
|
|
115
|
+
os.fsync(fd)
|
|
116
|
+
backup = staging.with_name(staging.name.removeprefix(".").removesuffix(".tmp") + ".bak")
|
|
117
|
+
os.link(staging, backup)
|
|
118
|
+
# Sync both the backup entry and the directory entry created on the first backup.
|
|
119
|
+
for parent in (directory, directory.parent):
|
|
120
|
+
directory_fd = os.open(parent, os.O_RDONLY | os.O_DIRECTORY)
|
|
121
|
+
try:
|
|
122
|
+
os.fsync(directory_fd)
|
|
123
|
+
finally:
|
|
124
|
+
os.close(directory_fd)
|
|
125
|
+
return backup
|
|
126
|
+
finally:
|
|
127
|
+
os.close(fd)
|
|
128
|
+
staging.unlink(missing_ok=True)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
_SCHEDULED_NAME = re.compile(r"scheduled-[0-9]{20}-[a-z0-9_]{8}\.bak")
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def scheduled_backup(path: Path, root: Path, project: str, retain: int) -> str:
|
|
135
|
+
"""Copy one project's live database and prune its previously committed scheduled copies."""
|
|
136
|
+
directory = root / project
|
|
137
|
+
with closing(sqlite3.connect(f"{path.absolute().as_uri()}?mode=ro", uri=True)) as source:
|
|
138
|
+
current = _copy_backup(source, directory, f"scheduled-{time_ns():020d}-")
|
|
139
|
+
older = sorted(
|
|
140
|
+
(
|
|
141
|
+
candidate
|
|
142
|
+
for candidate in directory.iterdir()
|
|
143
|
+
if candidate != current
|
|
144
|
+
and _SCHEDULED_NAME.fullmatch(candidate.name)
|
|
145
|
+
and stat.S_ISREG(candidate.lstat().st_mode)
|
|
146
|
+
),
|
|
147
|
+
reverse=True,
|
|
148
|
+
)
|
|
149
|
+
for candidate in older[retain - 1 :]:
|
|
150
|
+
candidate.unlink()
|
|
151
|
+
return current.name
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def prepare_upgrade(path: Path, cfg: Config) -> None:
|
|
155
|
+
"""Inspect an existing file read-only and back it up before allowing schema changes."""
|
|
156
|
+
try:
|
|
157
|
+
path.stat()
|
|
158
|
+
except FileNotFoundError:
|
|
159
|
+
return
|
|
160
|
+
head = head_revision(cfg)
|
|
161
|
+
script = ScriptDirectory.from_config(cfg)
|
|
162
|
+
try:
|
|
163
|
+
with closing(sqlite3.connect(f"{path.absolute().as_uri()}?mode=ro", uri=True)) as source:
|
|
164
|
+
current = _current_revision(source)
|
|
165
|
+
if current is not None and current != head:
|
|
166
|
+
known = {item.revision for item in script.walk_revisions()}
|
|
167
|
+
if current not in known:
|
|
168
|
+
if (
|
|
169
|
+
current.isascii()
|
|
170
|
+
and current.isdecimal()
|
|
171
|
+
and len(current) <= 32
|
|
172
|
+
and head.isascii()
|
|
173
|
+
and head.isdecimal()
|
|
174
|
+
and int(current) > int(head)
|
|
175
|
+
):
|
|
176
|
+
raise ProjectMigrationError(
|
|
177
|
+
f"project schema revision {current} is newer "
|
|
178
|
+
f"than supported revision {head}"
|
|
179
|
+
)
|
|
180
|
+
raise ProjectMigrationError("unknown project schema revision")
|
|
181
|
+
if current == head:
|
|
182
|
+
if source.execute("PRAGMA quick_check('alembic_version')").fetchall() != [("ok",)]:
|
|
183
|
+
raise ProjectMigrationError("SQLite schema revision integrity check failed")
|
|
184
|
+
return
|
|
185
|
+
if source.execute("PRAGMA quick_check(1)").fetchall() != [("ok",)]:
|
|
186
|
+
raise ProjectMigrationError("SQLite project integrity check failed")
|
|
187
|
+
try:
|
|
188
|
+
_backup(source, path)
|
|
189
|
+
except (OSError, sqlite3.Error) as exc:
|
|
190
|
+
raise ProjectMigrationError(
|
|
191
|
+
"could not create the pre-migration SQLite backup"
|
|
192
|
+
) from exc
|
|
193
|
+
except sqlite3.Error as exc:
|
|
194
|
+
raise ProjectMigrationError("cannot read the SQLite project database") from exc
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Alembic environment. Migrations run on a connection the store hands in (AD-5)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from alembic import context
|
|
6
|
+
|
|
7
|
+
config = context.config
|
|
8
|
+
connection = config.attributes.get("connection")
|
|
9
|
+
if connection is None:
|
|
10
|
+
raise RuntimeError(
|
|
11
|
+
"migrations run only through plotroom.adapters.store_sqlite.upgrade_to_head(); "
|
|
12
|
+
"use `alembic revision` to add one"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def include_object(
|
|
17
|
+
_object: object, name: str | None, type_: str, _reflected: bool, _compare_to: object
|
|
18
|
+
) -> bool:
|
|
19
|
+
# The hand-written FTS migration owns the virtual table and its shadow tables.
|
|
20
|
+
return type_ != "table" or name not in {
|
|
21
|
+
"message_fts",
|
|
22
|
+
"message_fts_config",
|
|
23
|
+
"message_fts_content",
|
|
24
|
+
"message_fts_data",
|
|
25
|
+
"message_fts_docsize",
|
|
26
|
+
"message_fts_idx",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
context.configure(
|
|
31
|
+
connection=connection,
|
|
32
|
+
target_metadata=config.attributes.get("target_metadata"),
|
|
33
|
+
include_object=include_object,
|
|
34
|
+
)
|
|
35
|
+
with context.begin_transaction():
|
|
36
|
+
context.run_migrations()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""${message}
|
|
2
|
+
|
|
3
|
+
Revision ID: ${up_revision}
|
|
4
|
+
Revises: ${down_revision | comma,n}
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from collections.abc import Sequence
|
|
8
|
+
|
|
9
|
+
import sqlalchemy as sa
|
|
10
|
+
from alembic import op
|
|
11
|
+
|
|
12
|
+
revision: str = ${repr(up_revision)}
|
|
13
|
+
down_revision: str | None = ${repr(down_revision)}
|
|
14
|
+
branch_labels: str | Sequence[str] | None = ${repr(branch_labels)}
|
|
15
|
+
depends_on: str | Sequence[str] | None = ${repr(depends_on)}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def upgrade() -> None:
|
|
19
|
+
${upgrades if upgrades else "pass"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Project metadata table: the first revision of every project file.
|
|
2
|
+
|
|
3
|
+
Revision ID: 0001
|
|
4
|
+
Revises:
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from collections.abc import Sequence
|
|
8
|
+
|
|
9
|
+
import sqlalchemy as sa
|
|
10
|
+
from alembic import op
|
|
11
|
+
|
|
12
|
+
revision: str = "0001"
|
|
13
|
+
down_revision: str | None = None
|
|
14
|
+
branch_labels: str | Sequence[str] | None = None
|
|
15
|
+
depends_on: str | Sequence[str] | None = None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def upgrade() -> None:
|
|
19
|
+
op.create_table(
|
|
20
|
+
"project_meta",
|
|
21
|
+
sa.Column("key", sa.Text(), primary_key=True),
|
|
22
|
+
sa.Column("value", sa.Text(), nullable=False),
|
|
23
|
+
)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""The event log and the project ``seq`` counter (AD-2, AD-9).
|
|
2
|
+
|
|
3
|
+
Revision ID: 0002
|
|
4
|
+
Revises: 0001
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from collections.abc import Sequence
|
|
8
|
+
|
|
9
|
+
import sqlalchemy as sa
|
|
10
|
+
from alembic import op
|
|
11
|
+
|
|
12
|
+
revision: str = "0002"
|
|
13
|
+
down_revision: str | None = "0001"
|
|
14
|
+
branch_labels: str | Sequence[str] | None = None
|
|
15
|
+
depends_on: str | Sequence[str] | None = None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def upgrade() -> None:
|
|
19
|
+
op.create_table(
|
|
20
|
+
"events",
|
|
21
|
+
sa.Column("seq", sa.Integer(), primary_key=True, autoincrement=False),
|
|
22
|
+
sa.Column("id", sa.Text(), nullable=False, unique=True),
|
|
23
|
+
sa.Column("source", sa.Text(), nullable=False),
|
|
24
|
+
sa.Column("kind", sa.Text(), nullable=False),
|
|
25
|
+
sa.Column("upstream_id", sa.Text(), nullable=False),
|
|
26
|
+
sa.Column("lane_id", sa.Text(), nullable=True),
|
|
27
|
+
sa.Column("fields", sa.Text(), nullable=False),
|
|
28
|
+
sa.Column("body", sa.Text(), nullable=False),
|
|
29
|
+
sa.Column("observed_at", sa.Text(), nullable=False),
|
|
30
|
+
sa.UniqueConstraint("source", "kind", "upstream_id", name="uq_events_identity"),
|
|
31
|
+
sa.CheckConstraint("seq > 0", name="ck_events_seq_positive"),
|
|
32
|
+
sa.CheckConstraint("json_valid(fields)", name="ck_events_fields_json"),
|
|
33
|
+
)
|
|
34
|
+
op.create_table(
|
|
35
|
+
"project_seq",
|
|
36
|
+
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=False),
|
|
37
|
+
sa.Column("value", sa.Integer(), nullable=False),
|
|
38
|
+
sa.CheckConstraint("id = 1", name="ck_project_seq_single_row"),
|
|
39
|
+
)
|
|
40
|
+
op.execute("INSERT INTO project_seq (id, value) VALUES (1, 0)")
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Durable next items (AD-18).
|
|
2
|
+
|
|
3
|
+
Revision ID: 0003
|
|
4
|
+
Revises: 0002
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sqlalchemy as sa
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0003"
|
|
11
|
+
down_revision = "0002"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def upgrade() -> None:
|
|
17
|
+
op.create_table(
|
|
18
|
+
"noop_command_receipts",
|
|
19
|
+
sa.Column("command", sa.Text(), primary_key=True),
|
|
20
|
+
sa.Column("request_key", sa.Text(), primary_key=True),
|
|
21
|
+
sa.Column("receipt", sa.Text(), nullable=False),
|
|
22
|
+
sa.CheckConstraint("json_valid(receipt)"),
|
|
23
|
+
)
|
|
24
|
+
op.create_table(
|
|
25
|
+
"next_items",
|
|
26
|
+
sa.Column("id", sa.Text(), primary_key=True),
|
|
27
|
+
sa.Column("kind", sa.Text(), nullable=False),
|
|
28
|
+
sa.Column("subject_ref", sa.Text(), nullable=False),
|
|
29
|
+
sa.Column("dedup_key", sa.Text(), nullable=False),
|
|
30
|
+
sa.Column("role", sa.Text(), nullable=False),
|
|
31
|
+
sa.Column("rank_class", sa.Integer(), nullable=False),
|
|
32
|
+
sa.Column("state", sa.Text(), nullable=False),
|
|
33
|
+
sa.Column("opened_seq", sa.Integer(), nullable=False),
|
|
34
|
+
sa.Column("closed_seq", sa.Integer()),
|
|
35
|
+
sa.Column("seq", sa.Integer(), nullable=False, unique=True),
|
|
36
|
+
sa.Column("context", sa.Text(), nullable=False),
|
|
37
|
+
sa.Column("suggested_actions", sa.Text(), nullable=False),
|
|
38
|
+
sa.CheckConstraint("state IN ('open', 'snoozed', 'closed')"),
|
|
39
|
+
sa.CheckConstraint("(state = 'closed') = (closed_seq IS NOT NULL)"),
|
|
40
|
+
sa.CheckConstraint("json_valid(context) AND json_valid(suggested_actions)"),
|
|
41
|
+
)
|
|
42
|
+
op.create_index(
|
|
43
|
+
"uq_next_items_active_key",
|
|
44
|
+
"next_items",
|
|
45
|
+
["dedup_key"],
|
|
46
|
+
unique=True,
|
|
47
|
+
sqlite_where=sa.text("state != 'closed'"),
|
|
48
|
+
)
|
|
49
|
+
op.create_index("ix_next_items_rank", "next_items", ["state", "rank_class", "opened_seq"])
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Committed effects and their retry state.
|
|
2
|
+
|
|
3
|
+
Revision ID: 0004
|
|
4
|
+
Revises: 0003
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sqlalchemy as sa
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0004"
|
|
11
|
+
down_revision = "0003"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def upgrade() -> None:
|
|
17
|
+
op.create_table(
|
|
18
|
+
"actions",
|
|
19
|
+
sa.Column("action_key", sa.Text(), primary_key=True),
|
|
20
|
+
sa.Column("kind", sa.Text(), nullable=False),
|
|
21
|
+
sa.Column("cause_id", sa.Text(), sa.ForeignKey("events.id"), nullable=False),
|
|
22
|
+
sa.Column("payload", sa.Text(), nullable=False),
|
|
23
|
+
sa.Column("attempts", sa.Integer(), nullable=False),
|
|
24
|
+
sa.Column("state", sa.Text(), nullable=False),
|
|
25
|
+
sa.CheckConstraint("state IN ('pending', 'done', 'failed')"),
|
|
26
|
+
sa.CheckConstraint("attempts >= 0 AND json_valid(payload)"),
|
|
27
|
+
)
|
|
28
|
+
op.create_index("ix_actions_pending", "actions", ["state"])
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""The durable lane board.
|
|
2
|
+
|
|
3
|
+
Revision ID: 0005
|
|
4
|
+
Revises: 0004
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sqlalchemy as sa
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0005"
|
|
11
|
+
down_revision = "0004"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def upgrade() -> None:
|
|
17
|
+
op.create_table(
|
|
18
|
+
"lanes",
|
|
19
|
+
sa.Column("id", sa.Text(), primary_key=True),
|
|
20
|
+
sa.Column("worker", sa.Text(), nullable=False),
|
|
21
|
+
sa.Column("work_items", sa.Text(), nullable=False),
|
|
22
|
+
sa.Column("branch", sa.Text(), nullable=False),
|
|
23
|
+
sa.Column("state", sa.Text(), nullable=False),
|
|
24
|
+
sa.Column("waiting_on", sa.Text()),
|
|
25
|
+
sa.Column("pr", sa.Integer()),
|
|
26
|
+
sa.Column("head_sha", sa.Text()),
|
|
27
|
+
sa.CheckConstraint("json_valid(work_items)"),
|
|
28
|
+
sa.CheckConstraint("state IN ('active', 'ready', 'archived')"),
|
|
29
|
+
)
|
|
30
|
+
op.create_index(
|
|
31
|
+
"uq_lanes_live_worker",
|
|
32
|
+
"lanes",
|
|
33
|
+
["worker"],
|
|
34
|
+
unique=True,
|
|
35
|
+
sqlite_where=sa.text("state != 'archived'"),
|
|
36
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Mirror of ready work from the configured source.
|
|
2
|
+
|
|
3
|
+
Revision ID: 0006
|
|
4
|
+
Revises: 0005
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sqlalchemy as sa
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0006"
|
|
11
|
+
down_revision = "0005"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def upgrade() -> None:
|
|
17
|
+
op.create_table(
|
|
18
|
+
"work_items",
|
|
19
|
+
sa.Column("ref", sa.Text(), primary_key=True),
|
|
20
|
+
sa.Column("title", sa.Text(), nullable=False),
|
|
21
|
+
sa.Column("source_order", sa.Integer(), nullable=False),
|
|
22
|
+
)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Retain the ordered item changes consumed by wait (AD-9).
|
|
2
|
+
|
|
3
|
+
Revision ID: 0007
|
|
4
|
+
Revises: 0006
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sqlalchemy as sa
|
|
8
|
+
from alembic import op
|
|
9
|
+
|
|
10
|
+
revision = "0007"
|
|
11
|
+
down_revision = "0006"
|
|
12
|
+
branch_labels = None
|
|
13
|
+
depends_on = None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def upgrade() -> None:
|
|
17
|
+
op.create_table(
|
|
18
|
+
"item_changes",
|
|
19
|
+
sa.Column("seq", sa.Integer(), primary_key=True, autoincrement=False),
|
|
20
|
+
sa.Column("role", sa.Text(), nullable=False),
|
|
21
|
+
sa.Column("item", sa.Text(), nullable=False),
|
|
22
|
+
sa.CheckConstraint("seq > 0 AND json_valid(item)"),
|
|
23
|
+
)
|
|
24
|
+
op.create_index("ix_item_changes_role_seq", "item_changes", ["role", "seq"])
|
|
25
|
+
op.execute(
|
|
26
|
+
"""INSERT INTO item_changes (seq, role, item)
|
|
27
|
+
SELECT seq, role, json_object(
|
|
28
|
+
'id', id, 'kind', kind, 'subject_ref', subject_ref, 'dedup_key', dedup_key,
|
|
29
|
+
'role', role, 'rank_class', rank_class, 'state', state, 'opened_seq', opened_seq,
|
|
30
|
+
'closed_seq', closed_seq, 'seq', seq, 'context', json(context),
|
|
31
|
+
'suggested_actions', json(suggested_actions)
|
|
32
|
+
) FROM next_items"""
|
|
33
|
+
)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Persist the alternate identities of Claude turn reports."""
|
|
2
|
+
|
|
3
|
+
import sqlalchemy as sa
|
|
4
|
+
from alembic import op
|
|
5
|
+
|
|
6
|
+
revision = "0008"
|
|
7
|
+
down_revision = "0007"
|
|
8
|
+
branch_labels = None
|
|
9
|
+
depends_on = None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def upgrade() -> None:
|
|
13
|
+
op.create_table(
|
|
14
|
+
"claude_turn_aliases",
|
|
15
|
+
sa.Column("session", sa.Text(), primary_key=True),
|
|
16
|
+
sa.Column("alias", sa.Text(), primary_key=True),
|
|
17
|
+
sa.Column("event_id", sa.Text(), sa.ForeignKey("events.id"), primary_key=True),
|
|
18
|
+
)
|
|
19
|
+
op.create_index(
|
|
20
|
+
"ix_claude_turn_index",
|
|
21
|
+
"claude_turn_aliases",
|
|
22
|
+
["session", "alias"],
|
|
23
|
+
unique=True,
|
|
24
|
+
sqlite_where=sa.text("alias GLOB 'index:*'"),
|
|
25
|
+
)
|
|
26
|
+
op.create_index(
|
|
27
|
+
"ix_claude_turn_event",
|
|
28
|
+
"claude_turn_aliases",
|
|
29
|
+
["event_id", "session", "alias"],
|
|
30
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Store the GitHub PR projection and the progress of each resource fetcher."""
|
|
2
|
+
|
|
3
|
+
import sqlalchemy as sa
|
|
4
|
+
from alembic import op
|
|
5
|
+
|
|
6
|
+
revision = "0009"
|
|
7
|
+
down_revision = "0008"
|
|
8
|
+
branch_labels = None
|
|
9
|
+
depends_on = None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def upgrade() -> None:
|
|
13
|
+
op.create_table(
|
|
14
|
+
"github_pull_requests",
|
|
15
|
+
sa.Column("repository", sa.Text(), primary_key=True),
|
|
16
|
+
sa.Column("number", sa.Integer(), primary_key=True, autoincrement=False),
|
|
17
|
+
sa.Column("branch", sa.Text(), nullable=False),
|
|
18
|
+
sa.Column("head_sha", sa.Text(), nullable=False),
|
|
19
|
+
sa.Column("head_repository", sa.Text()),
|
|
20
|
+
sa.Column("state", sa.Text(), nullable=False),
|
|
21
|
+
sa.Column("updated_at", sa.Text(), nullable=False),
|
|
22
|
+
sa.CheckConstraint("number > 0 AND state IN ('open', 'closed', 'merged')"),
|
|
23
|
+
)
|
|
24
|
+
op.create_index("ix_github_pull_state", "github_pull_requests", ["repository", "state"])
|
|
25
|
+
op.create_index(
|
|
26
|
+
"ix_github_pull_branch",
|
|
27
|
+
"github_pull_requests",
|
|
28
|
+
["repository", "head_repository", "branch", "state"],
|
|
29
|
+
)
|
|
30
|
+
op.create_table(
|
|
31
|
+
"github_fetch_cursors",
|
|
32
|
+
sa.Column("repository", sa.Text(), primary_key=True),
|
|
33
|
+
sa.Column("resource", sa.Text(), primary_key=True),
|
|
34
|
+
sa.Column("watermark", sa.Text(), nullable=False),
|
|
35
|
+
sa.Column("as_of", sa.Text(), nullable=False),
|
|
36
|
+
sa.Column("generation", sa.Integer(), nullable=False),
|
|
37
|
+
sa.CheckConstraint("generation > 0"),
|
|
38
|
+
)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Track the last completed observation and fact version for each projected PR."""
|
|
2
|
+
|
|
3
|
+
import sqlalchemy as sa
|
|
4
|
+
from alembic import op
|
|
5
|
+
|
|
6
|
+
revision = "0010"
|
|
7
|
+
down_revision = "0009"
|
|
8
|
+
branch_labels = None
|
|
9
|
+
depends_on = None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def upgrade() -> None:
|
|
13
|
+
op.create_table(
|
|
14
|
+
"github_fetch_retries",
|
|
15
|
+
sa.Column("repository", sa.Text(), primary_key=True),
|
|
16
|
+
sa.Column("resource", sa.Text(), primary_key=True),
|
|
17
|
+
sa.Column("until", sa.Text(), nullable=False),
|
|
18
|
+
sa.Column("next_backoff", sa.Integer(), nullable=False),
|
|
19
|
+
)
|
|
20
|
+
op.add_column(
|
|
21
|
+
"github_pull_requests", sa.Column("as_of", sa.Text(), nullable=False, server_default="")
|
|
22
|
+
)
|
|
23
|
+
op.add_column(
|
|
24
|
+
"github_pull_requests",
|
|
25
|
+
sa.Column("complete", sa.Boolean(), nullable=False, server_default="1"),
|
|
26
|
+
)
|
|
27
|
+
op.add_column(
|
|
28
|
+
"github_pull_requests",
|
|
29
|
+
sa.Column("version", sa.Integer(), nullable=False, server_default="1"),
|
|
30
|
+
)
|
|
31
|
+
op.execute(
|
|
32
|
+
"""UPDATE github_pull_requests SET as_of = COALESCE(
|
|
33
|
+
(SELECT as_of FROM github_fetch_cursors AS c
|
|
34
|
+
WHERE c.repository = github_pull_requests.repository AND c.resource = 'pull_requests'),
|
|
35
|
+
updated_at
|
|
36
|
+
)"""
|
|
37
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Add read-only GitHub resource projections."""
|
|
2
|
+
|
|
3
|
+
import sqlalchemy as sa
|
|
4
|
+
from alembic import op
|
|
5
|
+
|
|
6
|
+
revision = "0011"
|
|
7
|
+
down_revision = "0010"
|
|
8
|
+
branch_labels = None
|
|
9
|
+
depends_on = None
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def upgrade() -> None:
|
|
13
|
+
op.create_table(
|
|
14
|
+
"github_resources",
|
|
15
|
+
sa.Column("repository", sa.Text(), primary_key=True),
|
|
16
|
+
sa.Column("resource", sa.Text(), primary_key=True),
|
|
17
|
+
sa.Column("scope", sa.Text(), primary_key=True),
|
|
18
|
+
sa.Column("records", sa.Text(), nullable=False),
|
|
19
|
+
sa.Column("attributes", sa.Text(), nullable=False),
|
|
20
|
+
sa.Column("complete", sa.Boolean(), nullable=False),
|
|
21
|
+
sa.Column("generation", sa.Integer(), nullable=False),
|
|
22
|
+
sa.Column("as_of", sa.Text(), nullable=False),
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def downgrade() -> None:
|
|
27
|
+
op.drop_table("github_resources")
|