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,218 @@
1
+ """The port file: where a daemon publishes the address it actually bound (AD-3).
2
+
3
+ A client trusts the file only while the data-directory lock is held by the pid the file names
4
+ (see ``daemon_start``); the file alone proves nothing, since a killed daemon leaves it behind.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import contextlib
10
+ import errno
11
+ import ipaddress
12
+ import json
13
+ import os
14
+ import stat
15
+ import tempfile
16
+ from collections.abc import Generator
17
+ from dataclasses import dataclass
18
+ from pathlib import Path
19
+ from typing import Any, cast
20
+
21
+ PORT_FILE_NAME = "plotroom.port"
22
+ START_DIRECTORY_ENV = "_PLOTROOM_START_DIRECTORY"
23
+ _MAX_PORT = 65535
24
+ _SOCKET_ROOT = Path("/tmp") # noqa: S108 - use a short path and create a private directory
25
+ _MAX_SOCKET_PATH_BYTES = 103 # macOS's sockaddr_un.sun_path holds 104 bytes including NUL
26
+
27
+ type DirectoryIdentity = tuple[int, int]
28
+
29
+
30
+ @dataclass(frozen=True)
31
+ class PublishedListener:
32
+ pid: int
33
+ port: int
34
+ host: str | None
35
+ local_socket: str | None = None
36
+ local_unavailable: bool = False
37
+
38
+
39
+ @contextlib.contextmanager
40
+ def pin_directory(data_dir: Path) -> Generator[int]:
41
+ data_dir.mkdir(parents=True, exist_ok=True)
42
+ fd = os.open(data_dir, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
43
+ try:
44
+ yield fd
45
+ finally:
46
+ os.close(fd)
47
+
48
+
49
+ def directory_identity(data_dir: Path | int) -> DirectoryIdentity:
50
+ info = os.fstat(data_dir) if isinstance(data_dir, int) else data_dir.stat(follow_symlinks=False)
51
+ if not stat.S_ISDIR(info.st_mode):
52
+ raise NotADirectoryError(f"not a data directory: {data_dir}")
53
+ return info.st_dev, info.st_ino
54
+
55
+
56
+ def directory_key(identity: DirectoryIdentity) -> str:
57
+ device, inode = identity
58
+ return f"{device:x}-{inode:x}"
59
+
60
+
61
+ def _private_directory(path: Path) -> bool:
62
+ try:
63
+ info = path.lstat()
64
+ except OSError:
65
+ return False
66
+ return (
67
+ stat.S_ISDIR(info.st_mode)
68
+ and info.st_uid == os.geteuid()
69
+ and stat.S_IMODE(info.st_mode) == 0o700
70
+ )
71
+
72
+
73
+ def _socket_roots(data_dir: Path) -> tuple[Path, ...]:
74
+ # The data directory and the standard user runtime directory can be shared across PrivateTmp.
75
+ runtime = Path("/run/user") / str(os.geteuid())
76
+ return (
77
+ (data_dir, runtime, _SOCKET_ROOT)
78
+ if _private_directory(runtime)
79
+ else (data_dir, _SOCKET_ROOT)
80
+ )
81
+
82
+
83
+ def published_socket(data_dir: Path, identity: DirectoryIdentity, published: str) -> Path | None:
84
+ path = Path(published)
85
+ if (
86
+ path.parent.parent not in _socket_roots(data_dir)
87
+ or not path.parent.name.startswith(f"plotroom-{os.geteuid()}-")
88
+ or path.name != f"{directory_key(identity)}.sock"
89
+ or not _private_directory(path.parent)
90
+ ):
91
+ return None
92
+ return path
93
+
94
+
95
+ def prepare_local_socket(data_dir: Path, *, directory_fd: int | None = None) -> Path:
96
+ identity = directory_identity(data_dir if directory_fd is None else directory_fd)
97
+ socket_name = f"{directory_key(identity)}.sock"
98
+ prefix = f"plotroom-{os.geteuid()}-"
99
+ error = OSError(errno.ENAMETOOLONG, "no private socket location fits the Unix path limit")
100
+ for root in _socket_roots(data_dir):
101
+ if len(os.fsencode(root / prefix / socket_name)) >= _MAX_SOCKET_PATH_BYTES:
102
+ continue
103
+ try:
104
+ directory = Path(tempfile.mkdtemp(prefix=prefix, dir=root))
105
+ except OSError as exc:
106
+ error = exc
107
+ continue
108
+ path = directory / socket_name
109
+ if len(os.fsencode(path)) <= _MAX_SOCKET_PATH_BYTES:
110
+ return path
111
+ with contextlib.suppress(OSError):
112
+ directory.rmdir()
113
+ raise error
114
+
115
+
116
+ def remove_local_socket(path: Path, *, directory_fd: int | None = None) -> None:
117
+ parent = path.parent if directory_fd is None else Path(path.parent.name)
118
+ with contextlib.suppress(OSError):
119
+ fd = os.open(parent, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=directory_fd)
120
+ try:
121
+ with contextlib.suppress(FileNotFoundError):
122
+ mode = os.stat(path.name, dir_fd=fd, follow_symlinks=False).st_mode
123
+ if stat.S_ISSOCK(mode):
124
+ os.unlink(path.name, dir_fd=fd)
125
+ finally:
126
+ os.close(fd)
127
+ os.rmdir(parent, dir_fd=directory_fd)
128
+
129
+
130
+ def write_port(
131
+ data_dir: Path,
132
+ port: int,
133
+ *,
134
+ host: str | None = None,
135
+ local_socket: Path | None = None,
136
+ local_unavailable: bool = False,
137
+ directory_fd: int | None = None,
138
+ ) -> None:
139
+ """Publish this process's address atomically. Legacy callers may omit the host."""
140
+ if directory_fd is None:
141
+ data_dir.mkdir(parents=True, exist_ok=True)
142
+ target = _publication_path(data_dir, directory_fd)
143
+ scratch = target.with_name(f"{target.name}.{os.getpid()}.tmp")
144
+ fields: dict[str, str | int | None] = {"pid": os.getpid(), "port": port}
145
+ if host is not None:
146
+ fields["host"] = host
147
+ if local_socket is not None:
148
+ fields["local_socket"] = str(local_socket)
149
+ elif local_unavailable:
150
+ fields["local_socket"] = None
151
+ try:
152
+ with open(
153
+ scratch,
154
+ "w",
155
+ encoding="utf-8",
156
+ opener=lambda path, flags: os.open(path, flags | os.O_NOFOLLOW, dir_fd=directory_fd),
157
+ ) as handle:
158
+ json.dump(fields, handle)
159
+ os.replace(scratch, target, src_dir_fd=directory_fd, dst_dir_fd=directory_fd)
160
+ finally:
161
+ with contextlib.suppress(OSError):
162
+ os.unlink(scratch, dir_fd=directory_fd)
163
+
164
+
165
+ def _publication_path(data_dir: Path, directory_fd: int | None) -> Path:
166
+ return data_dir / PORT_FILE_NAME if directory_fd is None else Path(PORT_FILE_NAME)
167
+
168
+
169
+ def remove_port(data_dir: Path, *, directory_fd: int | None = None) -> None:
170
+ """Delete the port file, if there is one."""
171
+ with contextlib.suppress(FileNotFoundError):
172
+ os.unlink(_publication_path(data_dir, directory_fd), dir_fd=directory_fd)
173
+
174
+
175
+ def read_port(data_dir: Path) -> tuple[int, int] | None:
176
+ """The ``(pid, port)`` the file holds, or ``None`` when it is absent or malformed."""
177
+ listener = read_listener(data_dir)
178
+ return None if listener is None else (listener.pid, listener.port)
179
+
180
+
181
+ def read_listener(data_dir: Path, *, directory_fd: int | None = None) -> PublishedListener | None:
182
+ """Read the listener, with no host for legacy records or invalid addresses."""
183
+ try:
184
+ with open(
185
+ _publication_path(data_dir, directory_fd),
186
+ encoding="utf-8",
187
+ opener=lambda path, flags: os.open(path, flags | os.O_NONBLOCK, dir_fd=directory_fd),
188
+ ) as handle:
189
+ if not stat.S_ISREG(os.fstat(handle.fileno()).st_mode):
190
+ return None
191
+ decoded: Any = json.load(handle)
192
+ except OSError, ValueError, RecursionError:
193
+ return None
194
+ if not isinstance(decoded, dict):
195
+ return None
196
+ fields = cast("dict[str, Any]", decoded)
197
+ pid, port = fields.get("pid"), fields.get("port")
198
+ if not isinstance(pid, int) or not isinstance(port, int):
199
+ return None
200
+ if isinstance(pid, bool) or isinstance(port, bool):
201
+ return None
202
+ if pid <= 0 or not 0 < port <= _MAX_PORT:
203
+ return None
204
+ host = fields.get("host")
205
+ if not isinstance(host, str):
206
+ return PublishedListener(pid, port, None)
207
+ try:
208
+ ipaddress.ip_address(host)
209
+ except ValueError:
210
+ return PublishedListener(pid, port, None)
211
+ local_socket = fields.get("local_socket")
212
+ return PublishedListener(
213
+ pid,
214
+ port,
215
+ host,
216
+ local_socket if isinstance(local_socket, str) else None,
217
+ local_unavailable="local_socket" in fields and local_socket is None,
218
+ )