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,116 @@
|
|
|
1
|
+
"""Full-text queries and updates on a project's committed search records."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from uuid import uuid4
|
|
5
|
+
|
|
6
|
+
from sqlalchemy import text
|
|
7
|
+
from sqlalchemy.ext.asyncio import AsyncConnection
|
|
8
|
+
|
|
9
|
+
from plotroom.ports.search import SearchHit, SearchPage, SearchRecord
|
|
10
|
+
|
|
11
|
+
EXCERPT_LIMIT = 240
|
|
12
|
+
|
|
13
|
+
FIND_RECORD = text("""
|
|
14
|
+
SELECT seq, body, provisional FROM search_records WHERE kind = :kind AND record_id = :id
|
|
15
|
+
""")
|
|
16
|
+
INSERT_RECORD = text("""
|
|
17
|
+
INSERT INTO search_records (kind, record_id, body, embeddable, provisional)
|
|
18
|
+
VALUES (:kind, :id, :body, :embeddable, :provisional)
|
|
19
|
+
RETURNING seq
|
|
20
|
+
""")
|
|
21
|
+
CONFIRM_RECORD = text("UPDATE search_records SET provisional = FALSE WHERE seq = :seq")
|
|
22
|
+
DELETE_RECORD = text("DELETE FROM search_records WHERE seq = :seq")
|
|
23
|
+
DELETE_MESSAGE = text("DELETE FROM message_fts WHERE rowid = :seq")
|
|
24
|
+
INSERT_MESSAGE = text("INSERT INTO message_fts (rowid, body) VALUES (:seq, :body)")
|
|
25
|
+
COUNT_MATCHES = text("""
|
|
26
|
+
SELECT count(*)
|
|
27
|
+
FROM message_fts JOIN search_records ON search_records.seq = message_fts.rowid
|
|
28
|
+
WHERE message_fts MATCH :query
|
|
29
|
+
AND (:kinds IS NULL OR search_records.kind IN (SELECT value FROM json_each(:kinds)))
|
|
30
|
+
""")
|
|
31
|
+
# Rank and limit the row IDs before highlighting their bodies. Rank each record
|
|
32
|
+
# by its own byte length so hidden records cannot influence visible results.
|
|
33
|
+
FIND_MATCHES = text("""
|
|
34
|
+
WITH ranked AS MATERIALIZED (
|
|
35
|
+
SELECT search_records.record_id AS id, search_records.kind, search_records.seq,
|
|
36
|
+
octet_length(search_records.body) AS body_bytes
|
|
37
|
+
FROM message_fts JOIN search_records ON search_records.seq = message_fts.rowid
|
|
38
|
+
WHERE message_fts MATCH :query
|
|
39
|
+
AND (:kinds IS NULL OR search_records.kind IN (SELECT value FROM json_each(:kinds)))
|
|
40
|
+
ORDER BY body_bytes, search_records.seq DESC
|
|
41
|
+
LIMIT :limit
|
|
42
|
+
), matches AS MATERIALIZED (
|
|
43
|
+
SELECT ranked.*, message_fts.body,
|
|
44
|
+
highlight(message_fts, 0, :open_marker, :close_marker) AS marked_body
|
|
45
|
+
FROM ranked CROSS JOIN message_fts
|
|
46
|
+
WHERE message_fts.rowid = ranked.seq AND message_fts MATCH :query
|
|
47
|
+
), spans AS (
|
|
48
|
+
SELECT *, instr(marked_body, :open_marker) AS match_start,
|
|
49
|
+
instr(marked_body, :close_marker) - instr(marked_body, :open_marker)
|
|
50
|
+
- length(:open_marker) AS match_length
|
|
51
|
+
FROM matches
|
|
52
|
+
), windows AS (
|
|
53
|
+
SELECT *, max(1, match_start - min(60, max(0, :excerpt_limit - match_length)))
|
|
54
|
+
AS excerpt_start
|
|
55
|
+
FROM spans
|
|
56
|
+
)
|
|
57
|
+
SELECT id, kind,
|
|
58
|
+
substr(body, excerpt_start, :excerpt_limit) AS excerpt,
|
|
59
|
+
match_start - excerpt_start AS match_offset,
|
|
60
|
+
min(:excerpt_limit, match_start - excerpt_start + match_length) AS match_end
|
|
61
|
+
FROM windows ORDER BY body_bytes, seq DESC
|
|
62
|
+
""")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
async def index_record(
|
|
66
|
+
connection: AsyncConnection, record: SearchRecord, *, only_if_absent: bool
|
|
67
|
+
) -> None:
|
|
68
|
+
params = {"kind": record.kind, "id": record.id, "body": record.body}
|
|
69
|
+
current = (await connection.execute(FIND_RECORD, params)).first()
|
|
70
|
+
if current is not None:
|
|
71
|
+
confirms = current.provisional and not record.provisional
|
|
72
|
+
if current.body == record.body:
|
|
73
|
+
if confirms:
|
|
74
|
+
await connection.execute(CONFIRM_RECORD, {"seq": current.seq})
|
|
75
|
+
return
|
|
76
|
+
if only_if_absent and not confirms:
|
|
77
|
+
return
|
|
78
|
+
await connection.execute(DELETE_MESSAGE, {"seq": current.seq})
|
|
79
|
+
await connection.execute(DELETE_RECORD, {"seq": current.seq})
|
|
80
|
+
seq = (
|
|
81
|
+
await connection.execute(
|
|
82
|
+
INSERT_RECORD,
|
|
83
|
+
{**params, "embeddable": bool(record.body.strip()), "provisional": record.provisional},
|
|
84
|
+
)
|
|
85
|
+
).scalar_one()
|
|
86
|
+
# SQLite's text functions can stop at a NUL. Index it as a word separator.
|
|
87
|
+
await connection.execute(INSERT_MESSAGE, {"seq": seq, "body": record.body.replace("\x00", " ")})
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
async def search_records(
|
|
91
|
+
connection: AsyncConnection, query: str, kinds: tuple[str, ...] | None, limit: int
|
|
92
|
+
) -> SearchPage:
|
|
93
|
+
params = {"query": literal_phrase(query), "kinds": None if kinds is None else json.dumps(kinds)}
|
|
94
|
+
total = (await connection.execute(COUNT_MATCHES, params)).scalar_one()
|
|
95
|
+
# Highlight the complete phrase and give it priority over surrounding text.
|
|
96
|
+
marker = uuid4().hex
|
|
97
|
+
rows = await connection.execute(
|
|
98
|
+
FIND_MATCHES,
|
|
99
|
+
{
|
|
100
|
+
**params,
|
|
101
|
+
"limit": limit,
|
|
102
|
+
"excerpt_limit": EXCERPT_LIMIT,
|
|
103
|
+
"open_marker": f"<{marker}",
|
|
104
|
+
"close_marker": f">{marker}",
|
|
105
|
+
},
|
|
106
|
+
)
|
|
107
|
+
hits = tuple(
|
|
108
|
+
SearchHit(row.id, row.kind, row.excerpt, match_span=(row.match_offset, row.match_end))
|
|
109
|
+
for row in rows
|
|
110
|
+
)
|
|
111
|
+
return SearchPage(hits, total)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def literal_phrase(query: str) -> str:
|
|
115
|
+
# Quote the phrase so user-supplied punctuation cannot become FTS query syntax.
|
|
116
|
+
return '"' + query.replace('"', '""') + '"'
|