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,192 @@
1
+ """Read review resolution, changed files, text and label history for a pull request."""
2
+
3
+ from datetime import datetime
4
+ from typing import Any
5
+
6
+ import httpx
7
+
8
+ from plotroom.adapters.github.read import GitHubReadClient, Row, number, obj, string
9
+ from plotroom.core.github import PullRequest
10
+ from plotroom.core.github_projection import GitHubRecord, GitHubResource
11
+ from plotroom.core.merge_overlap import full_sha
12
+
13
+
14
+ async def fetch_threads(
15
+ api: GitHubReadClient, client: httpx.AsyncClient, token: str, pr: PullRequest
16
+ ) -> GitHubResource:
17
+ records: list[GitHubRecord] = []
18
+ async for row in api.review_threads(client, token, pr.number, pr.head_sha):
19
+ identifier = string(row["id"])
20
+ resolved: Any = row["isResolved"]
21
+ if type(resolved) is not bool:
22
+ raise ValueError("invalid review thread state")
23
+ fields = {
24
+ "id": identifier,
25
+ "number": pr.number,
26
+ "resolved": resolved,
27
+ "path": string(row["path"]),
28
+ }
29
+ if row["line"] is not None:
30
+ fields["line"] = number(row["line"])
31
+ records.append(
32
+ GitHubRecord(identifier, "review_thread", fields, fact=str(resolved).lower())
33
+ )
34
+ return GitHubResource(
35
+ tuple(records), attributes={"head_sha": pr.head_sha, "pull_version": pr.version}
36
+ )
37
+
38
+
39
+ async def fetch_files(
40
+ api: GitHubReadClient, client: httpx.AsyncClient, token: str, pr: PullRequest
41
+ ) -> GitHubResource:
42
+ async def confirm_pull() -> tuple[str, str, int]:
43
+ current = obj(await api.get(client, token, f"/pulls/{pr.number}"))
44
+ if string(obj(current["head"])["sha"]) != pr.head_sha or datetime.fromisoformat(
45
+ string(current["updated_at"])
46
+ ) != datetime.fromisoformat(pr.updated_at):
47
+ raise ValueError("PR changed during file poll")
48
+ base = obj(current["base"])
49
+ ref, sha = string(base["ref"]), string(base["sha"])
50
+ if not ref or not sha:
51
+ raise ValueError("PR base is unknown during file poll")
52
+ count: Any = current["changed_files"]
53
+ if type(count) is not int or not 0 <= count <= 3000:
54
+ raise ValueError("invalid or unbounded PR file list")
55
+ return ref, sha, count
56
+
57
+ base_ref, base_sha, expected = await confirm_pull()
58
+ records: list[GitHubRecord] = []
59
+ async for row in api.pages(client, token, f"/pulls/{pr.number}/files"):
60
+ path = string(row["filename"])
61
+ fields = {
62
+ "number": pr.number,
63
+ "head_sha": pr.head_sha,
64
+ "path": path,
65
+ "status": string(row["status"]),
66
+ }
67
+ if "previous_filename" in row:
68
+ fields["previous_path"] = string(row["previous_filename"])
69
+ records.append(GitHubRecord(path, "pull_file", fields))
70
+ if (base_ref, base_sha, expected) != await confirm_pull():
71
+ raise ValueError("PR base or changed file count moved during file poll")
72
+ if expected != len(records) or expected != len({record.key for record in records}):
73
+ raise ValueError("incomplete PR file list")
74
+ return GitHubResource(
75
+ tuple(records),
76
+ attributes={
77
+ "head_sha": pr.head_sha,
78
+ "base_ref": base_ref,
79
+ "base_sha": base_sha,
80
+ "pull_version": pr.version,
81
+ "pull_updated_at": pr.updated_at,
82
+ },
83
+ )
84
+
85
+
86
+ async def fetch_pull_text(
87
+ api: GitHubReadClient, client: httpx.AsyncClient, token: str, pr: PullRequest
88
+ ) -> GitHubResource:
89
+ path = f"/pulls/{pr.number}"
90
+
91
+ async def confirm_pull() -> tuple[str, int]:
92
+ current = obj(await api.get(client, token, path))
93
+ if string(obj(current["head"])["sha"]) != pr.head_sha or datetime.fromisoformat(
94
+ string(current["updated_at"])
95
+ ) != datetime.fromisoformat(pr.updated_at):
96
+ raise ValueError("PR changed during text poll")
97
+ body = current["body"]
98
+ return "" if body is None else string(body), number(current["commits"])
99
+
100
+ body, expected = await confirm_pull()
101
+ commits: dict[str, str] = {}
102
+ async for row in api.pages(client, token, f"{path}/commits", verify_terminal=True):
103
+ sha = string(row["sha"])
104
+ if not full_sha(sha) or sha in commits or len(commits) >= expected:
105
+ raise ValueError("invalid PR commit list")
106
+ commits[sha] = string(obj(row["commit"])["message"])
107
+ if (body, expected) != await confirm_pull():
108
+ raise ValueError("PR body or commit count moved during text poll")
109
+ if len(commits) != expected or next(reversed(commits), None) != pr.head_sha:
110
+ raise ValueError("incomplete PR commit list")
111
+ return GitHubResource(
112
+ (),
113
+ attributes={
114
+ "head_sha": pr.head_sha,
115
+ "pull_version": pr.version,
116
+ "pull_updated_at": pr.updated_at,
117
+ "body": body,
118
+ "commit_count": expected,
119
+ "commit_messages": list(commits.values()),
120
+ },
121
+ )
122
+
123
+
124
+ async def fetch_labels(
125
+ api: GitHubReadClient, client: httpx.AsyncClient, token: str, pr: PullRequest
126
+ ) -> GitHubResource:
127
+ active = [
128
+ string(row["name"]) async for row in api.pages(client, token, f"/issues/{pr.number}/labels")
129
+ ]
130
+ records: list[GitHubRecord] = []
131
+ provenance: dict[str, Row] = {}
132
+ async for row in api.pages(client, token, f"/issues/{pr.number}/events", verify_terminal=True):
133
+ action = row.get("event")
134
+ if action not in ("labeled", "unlabeled"):
135
+ continue
136
+ identifier = number(row["id"])
137
+ fields = {
138
+ "number": pr.number,
139
+ "name": string(obj(row["label"])["name"]),
140
+ "action": action,
141
+ "id": identifier,
142
+ }
143
+ if row["actor"] is not None:
144
+ fields["actor"] = string(obj(row["actor"])["login"])
145
+ details: Row = {}
146
+ if row["actor"] is not None and obj(row["actor"]).get("type") is not None:
147
+ details["actor_type"] = string(obj(row["actor"])["type"])
148
+ records.append(
149
+ GitHubRecord(
150
+ str(identifier), "pull_label", fields, details=details, fact=str(identifier)
151
+ )
152
+ )
153
+ records.sort(key=lambda record: record.fields["id"])
154
+ if len({record.key for record in records}) != len(records) or len(set(active)) != len(active):
155
+ raise ValueError("GitHub returned duplicate label evidence")
156
+ actors: dict[str, str | None] = {}
157
+ for record in records:
158
+ name = record.fields["name"]
159
+ if record.fields["action"] == "labeled":
160
+ actors[name] = record.fields.get("actor")
161
+ provenance[name] = {
162
+ "event_id": record.fields["id"],
163
+ "login": record.fields.get("actor"),
164
+ "actor_type": record.details.get("actor_type"),
165
+ }
166
+ else:
167
+ actors.pop(name, None)
168
+ provenance.pop(name, None)
169
+ if any(label in provenance for label in active):
170
+ latest = [
171
+ string(row["name"])
172
+ async for row in api.pages(client, token, f"/issues/{pr.number}/labels")
173
+ ]
174
+ if sorted(active) != sorted(latest):
175
+ raise ValueError("PR labels changed during label poll")
176
+ current = obj(await api.get(client, token, f"/pulls/{pr.number}"))
177
+ if string(obj(current["head"])["sha"]) != pr.head_sha or datetime.fromisoformat(
178
+ string(current["updated_at"])
179
+ ) != datetime.fromisoformat(pr.updated_at):
180
+ raise ValueError("PR changed during label poll")
181
+ return GitHubResource(
182
+ tuple(records),
183
+ attributes={
184
+ "labels": {label: actors.get(label) for label in active},
185
+ "label_provenance": {
186
+ label: provenance[label] for label in active if label in provenance
187
+ },
188
+ "head_sha": pr.head_sha,
189
+ "pull_version": pr.version,
190
+ "pull_updated_at": pr.updated_at,
191
+ },
192
+ )
@@ -0,0 +1,108 @@
1
+ """Read net file changes for a pinned pull head and default branch tip."""
2
+
3
+ from datetime import datetime
4
+ from typing import Any
5
+ from urllib.parse import quote
6
+
7
+ import httpx
8
+
9
+ from plotroom.adapters.github.ci import comparison_paths
10
+ from plotroom.adapters.github.read import GitHubReadClient, Row, obj, rows, string
11
+ from plotroom.core.events import format_time
12
+ from plotroom.core.github import PullRequest
13
+ from plotroom.core.github_projection import GitHubResource
14
+ from plotroom.core.merge_overlap import full_sha
15
+
16
+
17
+ async def _compare(
18
+ api: GitHubReadClient, client: httpx.AsyncClient, token: str, base: str, head: str
19
+ ) -> Row:
20
+ comparison = obj(
21
+ await api.get(client, token, f"/compare/{base}...{head}", {"page": 1, "per_page": 1})
22
+ )
23
+ if obj(comparison["base_commit"])["sha"] != base:
24
+ raise ValueError("GitHub returned a different comparison base")
25
+ return comparison
26
+
27
+
28
+ def _net_paths(comparison: Row, base: str) -> list[str]:
29
+ files: Any = comparison["files"]
30
+ if (
31
+ comparison["status"] != "ahead"
32
+ or obj(comparison["merge_base_commit"])["sha"] != base
33
+ or len(rows(files)) >= 300
34
+ ):
35
+ raise ValueError("incomplete comparison files")
36
+ return sorted(comparison_paths(files))
37
+
38
+
39
+ async def fetch_pull_comparison(
40
+ api: GitHubReadClient,
41
+ client: httpx.AsyncClient,
42
+ token: str,
43
+ pr: PullRequest,
44
+ main_branch: str,
45
+ main_tip: str,
46
+ previous: GitHubResource | None = None,
47
+ ) -> GitHubResource:
48
+ if (
49
+ not full_sha(pr.head_sha)
50
+ or not full_sha(main_tip)
51
+ or pr.head_repository is None
52
+ or pr.state != "open"
53
+ ):
54
+ return GitHubResource((), complete=False)
55
+ pinned = previous.attributes if previous is not None and previous.complete else {}
56
+ if pinned.get("head_sha") != pr.head_sha or pinned.get("main_tip") != main_tip:
57
+ pinned = await _file_pair(api, client, token, pr.head_sha, main_tip)
58
+ # A comparison is immutable, but the refs that make it relevant can move
59
+ # while GitHub serves it. Confirm both and the PR's current base target.
60
+ current = obj(await api.get(client, token, f"/pulls/{pr.number}"))
61
+ head, base = obj(current["head"]), obj(current["base"])
62
+ branch = obj(await api.get(client, token, f"/branches/{quote(main_branch, safe='')}"))
63
+ if (
64
+ current["state"] != "open"
65
+ or head["sha"] != pr.head_sha
66
+ or head["ref"] != pr.branch
67
+ or string(obj(head["repo"])["full_name"]).lower() != pr.head_repository.lower()
68
+ or format_time(datetime.fromisoformat(string(current["updated_at"]))) != pr.updated_at
69
+ or base["ref"] != main_branch
70
+ or string(obj(base["repo"])["full_name"]).lower() != api.repository.lower()
71
+ or obj(branch["commit"])["sha"] != main_tip
72
+ ):
73
+ return GitHubResource((), complete=False)
74
+ return GitHubResource(
75
+ (),
76
+ attributes={
77
+ "merge_base": pinned["merge_base"],
78
+ "pull_paths": pinned["pull_paths"],
79
+ "main_paths": pinned["main_paths"],
80
+ "pull_version": pr.version,
81
+ "pull_updated_at": pr.updated_at,
82
+ "head_sha": pr.head_sha,
83
+ "main_tip": main_tip,
84
+ "branch": main_branch,
85
+ },
86
+ )
87
+
88
+
89
+ async def _file_pair(
90
+ api: GitHubReadClient, client: httpx.AsyncClient, token: str, pr_head: str, main_tip: str
91
+ ) -> Row:
92
+ if pr_head == main_tip:
93
+ return {"merge_base": main_tip, "pull_paths": [], "main_paths": []}
94
+ compared = await _compare(api, client, token, pr_head, main_tip)
95
+ merge_base = string(obj(compared["merge_base_commit"])["sha"])
96
+ if not full_sha(merge_base):
97
+ raise ValueError("GitHub returned an invalid merge base")
98
+
99
+ async def paths(head: str) -> list[str]:
100
+ if head == merge_base:
101
+ return []
102
+ return _net_paths(await _compare(api, client, token, merge_base, head), merge_base)
103
+
104
+ return {
105
+ "merge_base": merge_base,
106
+ "pull_paths": await paths(pr_head),
107
+ "main_paths": await paths(main_tip),
108
+ }