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
plotroom/core/lanes.py ADDED
@@ -0,0 +1,281 @@
1
+ """Persistent lane lifecycle and worker ownership."""
2
+
3
+ from dataclasses import dataclass, replace
4
+ from typing import TYPE_CHECKING, Any
5
+
6
+ from plotroom.core.checklists import (
7
+ ARCHIVE_PROPOSAL,
8
+ Checklist,
9
+ activate_checklist,
10
+ complete_checklist_step,
11
+ declare_checklist,
12
+ invalidate_checklist,
13
+ )
14
+ from plotroom.core.events import LedgerError, NewEvent
15
+ from plotroom.core.roles import OwnershipView
16
+ from plotroom.core.work_items import refresh_idle_workers
17
+
18
+ if TYPE_CHECKING:
19
+ from plotroom.core.actions import Action
20
+ from plotroom.core.unit_of_work import UnitOfWork
21
+
22
+ LANE_WAITING = "lane_waiting"
23
+
24
+
25
+ @dataclass(frozen=True)
26
+ class Lane:
27
+ id: str
28
+ worker: str
29
+ work_items: tuple[str, ...]
30
+ branch: str
31
+ state: str = "active"
32
+ waiting_on: str | None = None
33
+ pr: int | None = None
34
+ head_sha: str | None = None
35
+ branch_pattern: str | None = None
36
+ checklist: Checklist | None = None
37
+ imported_channel: str | None = None
38
+ imported_trigger_id: str | None = None
39
+
40
+ def with_checklist(self, checklist: Checklist | None) -> Lane:
41
+ if checklist is None or checklist.state == "invalidated":
42
+ return self
43
+ return replace(
44
+ self,
45
+ checklist=checklist,
46
+ state="ready" if checklist.state == "pending" else self.state,
47
+ pr=checklist.pr,
48
+ head_sha=checklist.head_sha,
49
+ )
50
+
51
+ def render(self) -> dict[str, Any]:
52
+ result: dict[str, Any] = {
53
+ "id": self.id,
54
+ "worker": self.worker,
55
+ "work_items": list(self.work_items),
56
+ "branch": self.branch,
57
+ "state": self.state,
58
+ "waiting_on": self.waiting_on,
59
+ "pr": self.pr,
60
+ "head_sha": self.head_sha,
61
+ "branch_pattern": self.branch_pattern,
62
+ }
63
+ if self.checklist is not None:
64
+ result["checklist"] = self.checklist.render()
65
+ if self.imported_channel is not None:
66
+ result["imported_channel"] = self.imported_channel
67
+ if self.imported_trigger_id is not None:
68
+ result["imported_trigger_id"] = self.imported_trigger_id
69
+ return result
70
+
71
+
72
+ def with_projected_pr(lane: Lane, number: int | None, head_sha: str | None) -> Lane:
73
+ state = lane.state
74
+ if state == "ready" and (number is None or (number, head_sha) != (lane.pr, lane.head_sha)):
75
+ state = "active"
76
+ return replace(lane, state=state, pr=number, head_sha=head_sha)
77
+
78
+
79
+ async def infer_lane(
80
+ uow: UnitOfWork, *, worker: str | None = None, branch: str | None = None
81
+ ) -> str | None:
82
+ """Resolve an upstream binding against the current lane in the input transaction."""
83
+ if worker is not None:
84
+ lane = await uow.worker_lane(worker)
85
+ else:
86
+ lane = await uow.branch_lane(branch) if branch is not None else None
87
+ return lane.id if lane is not None else None
88
+
89
+
90
+ async def owns_lane(view: OwnershipView, args: dict[str, Any]) -> bool:
91
+ lane = await view.find_lane(args["lane"])
92
+ return lane is not None and view.role == f"worker:{lane.worker}"
93
+
94
+
95
+ async def start_lane(
96
+ uow: UnitOfWork,
97
+ args: dict[str, Any],
98
+ *,
99
+ workers: frozenset[str],
100
+ imported_channel: str | None = None,
101
+ imported_trigger_id: str | None = None,
102
+ refresh_idle: bool = True,
103
+ ) -> dict[str, Any]:
104
+ lane_id: str = args["lane"]
105
+ worker: str = args["worker"]
106
+ branch: str = args["branch"]
107
+ branch_pattern: str | None = args.get("branch_pattern")
108
+ work_items: list[Any] = args["work_items"]
109
+ if worker not in workers:
110
+ raise LedgerError("invalid", "worker is not configured for this project")
111
+ if not lane_id.strip() or len(lane_id.encode()) > 128 or not branch.strip():
112
+ raise LedgerError("invalid", "lane must be 1-128 UTF-8 bytes and branch must be non-empty")
113
+ if branch_pattern is not None and not branch_pattern.strip():
114
+ raise LedgerError("invalid", "branch_pattern must be non-empty when supplied")
115
+ if not all(isinstance(item, str) and item.strip() for item in work_items):
116
+ raise LedgerError("invalid", "work_items must contain non-empty strings")
117
+ if await uow.find_lane(lane_id) is not None:
118
+ raise LedgerError("conflict", "lane id already exists")
119
+ if await uow.worker_lane(worker) is not None:
120
+ raise LedgerError("conflict", "worker already has a lane")
121
+ if work_items and not set(work_items).isdisjoint(await uow.claimed_work_items()):
122
+ raise LedgerError("conflict", "one or more work items are already assigned")
123
+ lane = Lane(
124
+ lane_id,
125
+ worker,
126
+ tuple(work_items),
127
+ branch,
128
+ branch_pattern=branch_pattern,
129
+ imported_channel=imported_channel,
130
+ imported_trigger_id=imported_trigger_id,
131
+ )
132
+ await uow.save_lane(lane)
133
+ uow.pull_overlaps_changed()
134
+ if refresh_idle:
135
+ await refresh_idle_workers(uow, workers)
136
+ return lane.render()
137
+
138
+
139
+ async def _current(uow: UnitOfWork, lane_id: str) -> Lane:
140
+ lane = await uow.find_lane(lane_id)
141
+ if lane is None:
142
+ raise LedgerError("not_found", "lane not found")
143
+ if lane.state == "archived":
144
+ raise LedgerError("conflict", "lane is archived")
145
+ return lane
146
+
147
+
148
+ async def _save(uow: UnitOfWork, lane: Lane) -> dict[str, Any]:
149
+ await uow.save_lane(lane)
150
+ if lane.waiting_on == "orchestrator":
151
+ await uow.raise_item(LANE_WAITING, lane.id, "orchestrator", lane.render())
152
+ else:
153
+ await uow.clear_item(LANE_WAITING, lane.id)
154
+ return lane.render()
155
+
156
+
157
+ async def update_lane(uow: UnitOfWork, args: dict[str, Any]) -> dict[str, Any]:
158
+ lane = await _current(uow, args["lane"])
159
+ return await _save(uow, replace(lane, waiting_on=args["waiting_on"] or None))
160
+
161
+
162
+ async def ready_lane(
163
+ uow: UnitOfWork, args: dict[str, Any], *, repository: str | None
164
+ ) -> dict[str, Any]:
165
+ lane = await _current(uow, args["lane"])
166
+ if not 0 < args["pr"] <= 2**63 - 1 or not args["head_sha"].strip():
167
+ raise LedgerError("invalid", "pr must be positive and head_sha must be non-empty")
168
+ if repository is not None:
169
+ pr = await uow.open_branch_pull(repository, lane.branch)
170
+ if pr is None or pr.number != args["pr"] or pr.head_sha != args["head_sha"]:
171
+ raise LedgerError("conflict", "the PR and head must match the open GitHub projection")
172
+ await declare_checklist(uow, lane, repository, args)
173
+ return await _save(
174
+ uow, replace(lane, state="ready", waiting_on=None, pr=args["pr"], head_sha=args["head_sha"])
175
+ )
176
+
177
+
178
+ async def refresh_ready_lanes(uow: UnitOfWork, repository: str, branch: str) -> None:
179
+ lanes = await uow.branch_lanes(branch)
180
+ for lane in lanes:
181
+ if lane.state != "ready":
182
+ continue
183
+ checklist = await uow.find_checklist(lane.id)
184
+ if checklist is not None and checklist.state == "pending":
185
+ if checklist.repository != repository:
186
+ continue
187
+ projected = await uow.pull_request(repository, checklist.pr)
188
+ state = (
189
+ projected.state if projected is not None and checklist.matches(projected) else None
190
+ )
191
+ if state == "open":
192
+ continue
193
+ if state == "merged":
194
+ await activate_checklist(uow, checklist)
195
+ else:
196
+ await invalidate_checklist(uow, checklist)
197
+ else:
198
+ if len(lanes) != 1:
199
+ continue # The legacy lane binding requires an unambiguous branch.
200
+ pr = await uow.open_branch_pull(repository, branch)
201
+ if pr is not None and (pr.number, pr.head_sha) == (lane.pr, lane.head_sha):
202
+ continue
203
+ await _save(uow, replace(lane, state="active", pr=None, head_sha=None))
204
+
205
+
206
+ async def archive_lane(
207
+ uow: UnitOfWork, args: dict[str, Any], *, workers: frozenset[str]
208
+ ) -> dict[str, Any]:
209
+ lane = await _current(uow, args["lane"])
210
+ checklist = await uow.find_checklist(lane.id)
211
+ if checklist is not None and checklist.state == "active" and (steps := checklist.open_steps()):
212
+ names = ", ".join(repr(step.step) for step in steps)
213
+ raise LedgerError("conflict", f"the lane has open checklist steps: {names}")
214
+ await invalidate_checklist(uow, checklist)
215
+ result = await _save(uow, replace(lane, state="archived", waiting_on=None))
216
+ await uow.retire_stale_outbox()
217
+ await uow.delete_claims(lane.id)
218
+ await uow.clear_item(ARCHIVE_PROPOSAL, lane.id)
219
+ await refresh_idle_workers(uow, workers)
220
+ return result
221
+
222
+
223
+ async def checklist_done(uow: UnitOfWork, args: dict[str, Any]) -> dict[str, Any]:
224
+ lane = await _current(uow, args["lane"])
225
+ return await complete_checklist_step(uow, lane.id, args["step"], args.get("ref"))
226
+
227
+
228
+ async def checklist_import(
229
+ uow: UnitOfWork, args: dict[str, Any], *, repository: str | None
230
+ ) -> dict[str, Any]:
231
+ """Attach legacy post-merge work to the lane's complete, unambiguous projected PR."""
232
+ lane = await _current(uow, args["lane"])
233
+ pull = await uow.open_branch_pull(repository, lane.branch) if repository is not None else None
234
+ if (
235
+ pull is None
236
+ or not pull.complete
237
+ or pull.repository != pull.head_repository
238
+ or not pull.head_sha.strip()
239
+ ):
240
+ raise LedgerError("conflict", "checklist import requires a complete open projected PR")
241
+ current = await uow.find_checklist(lane.id)
242
+ if current is not None:
243
+ raise LedgerError("conflict", "the lane already has a checklist")
244
+ await declare_checklist(
245
+ uow,
246
+ lane,
247
+ repository,
248
+ {"pr": pull.number, "head_sha": pull.head_sha, "checklist": args["rows"]},
249
+ )
250
+ await uow.save_lane(replace(lane, state="ready", pr=pull.number, head_sha=pull.head_sha))
251
+ imported = await uow.find_checklist(lane.id)
252
+ if imported is None:
253
+ raise RuntimeError("a declared checklist must exist in the writer transaction")
254
+ return imported.render()
255
+
256
+
257
+ async def mark_lane(uow: UnitOfWork, action: Action, *, repository: str | None) -> None:
258
+ """Apply a system-owned mark using the normal current-lane and ready rules."""
259
+ lane = await _current(uow, action.payload["lane"])
260
+ state = action.payload["state"]
261
+ if state == "active":
262
+ await invalidate_checklist(uow, await uow.find_checklist(lane.id))
263
+ await _save(uow, replace(lane, state="active"))
264
+ elif state == "ready":
265
+ pr, head = lane.pr, lane.head_sha
266
+ if repository is not None and (pull := await uow.open_branch_pull(repository, lane.branch)):
267
+ pr, head = pull.number, pull.head_sha
268
+ if pr is None or head is None:
269
+ raise LedgerError("conflict", "a ready lane requires a PR and head")
270
+ await ready_lane(uow, {"lane": lane.id, "pr": pr, "head_sha": head}, repository=repository)
271
+ else:
272
+ raise LedgerError("invalid", "mark state must be active or ready")
273
+ await uow.append(
274
+ NewEvent(
275
+ "core",
276
+ "core.lane_marked",
277
+ action.key,
278
+ {"lane": lane.id, "state": state},
279
+ lane_id=lane.id,
280
+ )
281
+ )