tortoise-graph 0.2.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.
- tortoise/__init__.py +45 -0
- tortoise/__main__.py +1865 -0
- tortoise/analyze.py +473 -0
- tortoise/api.py +303 -0
- tortoise/archived/search_legacy.py +31 -0
- tortoise/audit.py +236 -0
- tortoise/audit_events.py +284 -0
- tortoise/auth.py +107 -0
- tortoise/backup.py +155 -0
- tortoise/config.py +99 -0
- tortoise/connector_loader.py +74 -0
- tortoise/connectors/__init__.py +5 -0
- tortoise/connectors/github.py +432 -0
- tortoise/connectors/github_docs.py +146 -0
- tortoise/connectors/linear.py +199 -0
- tortoise/connectors/slack.py +222 -0
- tortoise/consistency.py +132 -0
- tortoise/crypto.py +52 -0
- tortoise/deployment.py +62 -0
- tortoise/domain_loader.py +142 -0
- tortoise/dream.py +153 -0
- tortoise/embedded_reaper.py +744 -0
- tortoise/embeddings.py +227 -0
- tortoise/ep.py +534 -0
- tortoise/exceptions.py +16 -0
- tortoise/extractor.py +945 -0
- tortoise/hosted_api.py +1982 -0
- tortoise/hosted_middleware.py +22 -0
- tortoise/idempotency.py +39 -0
- tortoise/ids.py +23 -0
- tortoise/indexer/github_indexer.py +129 -0
- tortoise/ingest.py +614 -0
- tortoise/log.py +29 -0
- tortoise/m0.py +50 -0
- tortoise/mcp_auth.py +337 -0
- tortoise/mcp_client.py +108 -0
- tortoise/mcp_server.py +1356 -0
- tortoise/memory_orchestrator.py +492 -0
- tortoise/memory_scope.py +15 -0
- tortoise/migrate_db.py +244 -0
- tortoise/migrate_kinds.py +141 -0
- tortoise/mining.py +338 -0
- tortoise/models.py +109 -0
- tortoise/monitoring.py +133 -0
- tortoise/navigation.py +216 -0
- tortoise/pack_registry.py +767 -0
- tortoise/pipeline_cli.py +197 -0
- tortoise/projection/__init__.py +913 -0
- tortoise/projection/edges.py +311 -0
- tortoise/projection/entities.py +521 -0
- tortoise/projection/grounding.py +95 -0
- tortoise/projection/propagation.py +114 -0
- tortoise/projection.py +37 -0
- tortoise/quadrature.py +90 -0
- tortoise/query_suggestions.py +194 -0
- tortoise/quota.py +163 -0
- tortoise/ranking.py +280 -0
- tortoise/render.py +108 -0
- tortoise/scripts/manifest.py +67 -0
- tortoise/sdk.py +4713 -0
- tortoise/search_engine.py +887 -0
- tortoise/security.py +268 -0
- tortoise/selfhost.py +157 -0
- tortoise/selfhost_api.py +201 -0
- tortoise/session_continuity.py +82 -0
- tortoise/session_indexer.py +569 -0
- tortoise/shared_state/__init__.py +20 -0
- tortoise/shared_state/concurrency.py +113 -0
- tortoise/shared_state/event_log.py +192 -0
- tortoise/shared_state/events.py +150 -0
- tortoise/shared_state/monitoring.py +87 -0
- tortoise/shared_state/recovery.py +126 -0
- tortoise/shared_state/tests/__init__.py +15 -0
- tortoise/shared_state/tests/test_concurrency.py +123 -0
- tortoise/shared_state/tests/test_events.py +145 -0
- tortoise/shared_state/tests/test_monitoring.py +54 -0
- tortoise/shared_state/tests/test_recovery.py +181 -0
- tortoise/source_credibility.py +306 -0
- tortoise/svbp.py +446 -0
- tortoise/taxonomy.py +71 -0
- tortoise/test_cross_ontology.py +180 -0
- tortoise/test_tortoise_client.py +206 -0
- tortoise/tool_registry.py +805 -0
- tortoise/tortoise_client.py +262 -0
- tortoise/verify_ontology.py +154 -0
- tortoise/version_vector.py +97 -0
- tortoise/weights.py +61 -0
- tortoise_graph-0.2.0.dist-info/METADATA +152 -0
- tortoise_graph-0.2.0.dist-info/RECORD +93 -0
- tortoise_graph-0.2.0.dist-info/WHEEL +5 -0
- tortoise_graph-0.2.0.dist-info/entry_points.txt +4 -0
- tortoise_graph-0.2.0.dist-info/licenses/LICENSE +95 -0
- tortoise_graph-0.2.0.dist-info/top_level.txt +1 -0
tortoise/ranking.py
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"""Graph-informed ranking for Tortoise search results (#25).
|
|
2
|
+
|
|
3
|
+
Search results are ranked by text similarity alone (RRF fusion of FTS /
|
|
4
|
+
vector / structural). This module adds Tortoise's structural differentiator —
|
|
5
|
+
graph topology — as a composable ranking signal:
|
|
6
|
+
|
|
7
|
+
final_score = α · normalize(similarity) + β · graph_boost + γ · recency_decay
|
|
8
|
+
|
|
9
|
+
* graph_boost for Points uses the persisted EP confidence (``n.confidence``,
|
|
10
|
+
written by ``compute_confidence``) and operator connectivity (incident
|
|
11
|
+
IMPL/NAND edge count).
|
|
12
|
+
* graph_boost for Events/Sessions uses INSTANTIATES edge count (Objects
|
|
13
|
+
produced = reusable knowledge) plus the mean EP confidence of Points the
|
|
14
|
+
session produced, per docs/scoping-7769-graph-informed-ranking.md.
|
|
15
|
+
* recency_decay is exponential with a configurable half-life (default 30 days).
|
|
16
|
+
|
|
17
|
+
Design notes (from the scoping doc):
|
|
18
|
+
- GraphRanker is a standalone module, unit-testable without a live graph
|
|
19
|
+
(``projection=None`` → only signals embedded in the result dicts are used).
|
|
20
|
+
- Weights are configurable at construction; defaults α=0.5, β=0.35, γ=0.15.
|
|
21
|
+
- Missing signals degrade to neutral, never to a penalty — uncalibrated
|
|
22
|
+
Points get a graph boost of 0.0 and missing timestamps get neutral recency.
|
|
23
|
+
- INSTANTIATES / PRODUCES edges may be absent on older graphs; the queries
|
|
24
|
+
are OPTIONAL MATCH so the boost degrades to 0.0 gracefully.
|
|
25
|
+
"""
|
|
26
|
+
from __future__ import annotations
|
|
27
|
+
|
|
28
|
+
import logging
|
|
29
|
+
import math
|
|
30
|
+
from datetime import datetime, timezone
|
|
31
|
+
|
|
32
|
+
from .search_engine import _beta_variance, CONTESTED_VARIANCE_THRESHOLD # noqa: E402
|
|
33
|
+
|
|
34
|
+
logger = logging.getLogger(__name__)
|
|
35
|
+
|
|
36
|
+
# Default signal weights — must sum to 1.0.
|
|
37
|
+
DEFAULT_SIMILARITY_WEIGHT = 0.5
|
|
38
|
+
DEFAULT_GRAPH_BOOST_WEIGHT = 0.35
|
|
39
|
+
DEFAULT_RECENCY_WEIGHT = 0.15
|
|
40
|
+
DEFAULT_HALF_LIFE_DAYS = 30.0
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def recency_decay(age_days: float, half_life_days: float = DEFAULT_HALF_LIFE_DAYS) -> float:
|
|
44
|
+
"""Exponential recency decay: e^(-λ·age) with λ = ln(2) / half_life.
|
|
45
|
+
|
|
46
|
+
age_days <= 0 → 1.0 (fresh). Missing/unknown age should be passed as 0.0
|
|
47
|
+
by callers that want a neutral (no demotion) recency signal.
|
|
48
|
+
"""
|
|
49
|
+
if age_days <= 0:
|
|
50
|
+
return 1.0
|
|
51
|
+
lam = math.log(2) / half_life_days
|
|
52
|
+
return math.exp(-lam * age_days)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _min_max_normalize(values: list[float], lo: float = 0.0, hi: float = 1.0) -> list[float]:
|
|
56
|
+
"""Min-max normalize a list into [lo, hi]. All-equal → midpoint."""
|
|
57
|
+
if not values:
|
|
58
|
+
return []
|
|
59
|
+
vmin, vmax = min(values), max(values)
|
|
60
|
+
span = vmax - vmin
|
|
61
|
+
if span <= 1e-12:
|
|
62
|
+
return [(lo + hi) / 2.0] * len(values)
|
|
63
|
+
return [lo + (v - vmin) / span * (hi - lo) for v in values]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _parse_iso(value) -> datetime | None:
|
|
67
|
+
"""Parse an ISO-8601 string/datetime to an aware UTC datetime, else None."""
|
|
68
|
+
if value is None or value == "":
|
|
69
|
+
return None
|
|
70
|
+
if isinstance(value, datetime):
|
|
71
|
+
dt = value
|
|
72
|
+
return dt if dt.tzinfo is not None else dt.replace(tzinfo=timezone.utc)
|
|
73
|
+
try:
|
|
74
|
+
dt = datetime.fromisoformat(str(value).replace("Z", "+00:00"))
|
|
75
|
+
return dt if dt.tzinfo is not None else dt.replace(tzinfo=timezone.utc)
|
|
76
|
+
except (ValueError, TypeError):
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class GraphRanker:
|
|
81
|
+
"""Re-rank search results using graph topology signals.
|
|
82
|
+
|
|
83
|
+
Composable into any ranking surface (``tortoise_fts_query`` with
|
|
84
|
+
``order_by="graph"``, ``suggest_entry_points``, future surfaces). Each
|
|
85
|
+
signal is independently configurable; all weights are constructor args.
|
|
86
|
+
|
|
87
|
+
``projection`` may be None for pure unit testing — graph signals are then
|
|
88
|
+
read from the result dicts themselves (keys ``graph_confidence``,
|
|
89
|
+
``graph_degree``, ``graph_instantiates``, ``createdAt``/``startedAt``).
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
def __init__(
|
|
93
|
+
self,
|
|
94
|
+
projection=None, *,
|
|
95
|
+
similarity_weight: float = DEFAULT_SIMILARITY_WEIGHT,
|
|
96
|
+
graph_boost_weight: float = DEFAULT_GRAPH_BOOST_WEIGHT,
|
|
97
|
+
recency_weight: float = DEFAULT_RECENCY_WEIGHT,
|
|
98
|
+
recency_half_life_days: float = DEFAULT_HALF_LIFE_DAYS,
|
|
99
|
+
):
|
|
100
|
+
total = similarity_weight + graph_boost_weight + recency_weight
|
|
101
|
+
if abs(total - 1.0) > 1e-6:
|
|
102
|
+
raise ValueError(
|
|
103
|
+
f"weights must sum to 1.0, got {total:.4f} "
|
|
104
|
+
f"({similarity_weight} + {graph_boost_weight} + {recency_weight})"
|
|
105
|
+
)
|
|
106
|
+
self.projection = projection
|
|
107
|
+
self.similarity_weight = similarity_weight
|
|
108
|
+
self.graph_boost_weight = graph_boost_weight
|
|
109
|
+
self.recency_weight = recency_weight
|
|
110
|
+
self.recency_half_life_days = recency_half_life_days
|
|
111
|
+
|
|
112
|
+
# ── Public API ────────────────────────────────────────────────────────
|
|
113
|
+
|
|
114
|
+
def rerank(
|
|
115
|
+
self,
|
|
116
|
+
results: list[dict],
|
|
117
|
+
*,
|
|
118
|
+
entity_type: str = "point",
|
|
119
|
+
) -> list[dict]:
|
|
120
|
+
"""Re-rank results, each annotated with a ``graph_ranking`` breakdown.
|
|
121
|
+
|
|
122
|
+
Each result dict needs at least ``id`` and a similarity-like field
|
|
123
|
+
(``scores.rrf``, else ``similarity``, else ``confidence``). Returns the
|
|
124
|
+
list sorted by final_score descending; input dicts are NOT mutated —
|
|
125
|
+
annotated copies are returned.
|
|
126
|
+
"""
|
|
127
|
+
if not results:
|
|
128
|
+
return results
|
|
129
|
+
|
|
130
|
+
ids = [r.get("id") for r in results if r.get("id")]
|
|
131
|
+
signals = self._fetch_signals(ids, entity_type) if self.projection is not None else {}
|
|
132
|
+
|
|
133
|
+
similarities = []
|
|
134
|
+
for r in results:
|
|
135
|
+
sim = _similarity_of(r)
|
|
136
|
+
similarities.append(sim)
|
|
137
|
+
|
|
138
|
+
norm_sims = _min_max_normalize(similarities)
|
|
139
|
+
annotated: list[dict] = []
|
|
140
|
+
for r, norm_sim in zip(results, norm_sims):
|
|
141
|
+
sig = signals.get(r.get("id"), {})
|
|
142
|
+
graph_boost = self.graph_boost(r, sig)
|
|
143
|
+
recency = self.recency_boost(r, sig)
|
|
144
|
+
final = (
|
|
145
|
+
self.similarity_weight * norm_sim
|
|
146
|
+
+ self.graph_boost_weight * graph_boost
|
|
147
|
+
+ self.recency_weight * recency
|
|
148
|
+
)
|
|
149
|
+
copy = dict(r)
|
|
150
|
+
copy["graph_ranking"] = {
|
|
151
|
+
"similarity": round(norm_sim, 4),
|
|
152
|
+
"graph_boost": round(graph_boost, 4),
|
|
153
|
+
"recency_boost": round(recency, 4),
|
|
154
|
+
"final_score": round(final, 4),
|
|
155
|
+
}
|
|
156
|
+
sig = signals.get(r.get("id"), {})
|
|
157
|
+
if "variance" in sig:
|
|
158
|
+
copy["graph_ranking"]["variance"] = round(sig["variance"], 6)
|
|
159
|
+
copy["graph_ranking"]["contested"] = sig.get("contested", False)
|
|
160
|
+
annotated.append(copy)
|
|
161
|
+
|
|
162
|
+
annotated.sort(key=lambda r: r["graph_ranking"]["final_score"], reverse=True)
|
|
163
|
+
return annotated
|
|
164
|
+
|
|
165
|
+
# ── Signal computation ────────────────────────────────────────────────
|
|
166
|
+
|
|
167
|
+
def graph_boost(self, result: dict, signals: dict) -> float:
|
|
168
|
+
"""Graph-informed boost in [0, 1] for one result.
|
|
169
|
+
|
|
170
|
+
Points: 0.5·persisted EP confidence + 0.5·operator connectivity
|
|
171
|
+
(normalized incident IMPL/NAND edge count).
|
|
172
|
+
Events/Sessions: 0.6·INSTANTIATES count (Objects produced) +
|
|
173
|
+
0.4·mean EP confidence of produced Points.
|
|
174
|
+
|
|
175
|
+
Contestation is deliberately NOT used as a ranking penalty: a
|
|
176
|
+
contested claim is a claim the agent should KNOW is contested (the
|
|
177
|
+
ep.contested flag + variance on the result), not one that is silently
|
|
178
|
+
ranked lower. Ranking stays about relevance and graph structure;
|
|
179
|
+
epistemic honesty is surfaced, not scored.
|
|
180
|
+
"""
|
|
181
|
+
if signals:
|
|
182
|
+
confidence = signals.get("confidence", 0.0)
|
|
183
|
+
degree = signals.get("degree", 0)
|
|
184
|
+
instantiates = signals.get("instantiates", 0)
|
|
185
|
+
if instantiates > 0 or signals.get("is_event"):
|
|
186
|
+
inst_norm = 1.0 - 1.0 / (1.0 + instantiates)
|
|
187
|
+
return round(0.6 * inst_norm + 0.4 * confidence, 4)
|
|
188
|
+
connectivity = 1.0 - 1.0 / (1.0 + (degree or 0))
|
|
189
|
+
return round(0.5 * confidence + 0.5 * connectivity, 4)
|
|
190
|
+
# No graph data — degrade to neutral 0.0 (never a penalty).
|
|
191
|
+
return 0.0
|
|
192
|
+
|
|
193
|
+
def recency_boost(self, result: dict, signals: dict) -> float:
|
|
194
|
+
"""Exponential recency decay from createdAt/startedAt; missing → 1.0."""
|
|
195
|
+
ts = signals.get("created") or result.get("createdAt") or result.get("startedAt")
|
|
196
|
+
dt = _parse_iso(ts)
|
|
197
|
+
if dt is None:
|
|
198
|
+
return 1.0 # unknown age — neutral, no demotion
|
|
199
|
+
age_days = max(0.0, (datetime.now(timezone.utc) - dt).total_seconds() / 86400.0)
|
|
200
|
+
return round(recency_decay(age_days, self.recency_half_life_days), 4)
|
|
201
|
+
|
|
202
|
+
# ── Graph queries ─────────────────────────────────────────────────────
|
|
203
|
+
|
|
204
|
+
def _fetch_signals(self, ids: list[str], entity_type: str) -> dict[str, dict]:
|
|
205
|
+
"""Batch-fetch graph signals for the given ids. Returns {id: {…}}."""
|
|
206
|
+
if not ids:
|
|
207
|
+
return {}
|
|
208
|
+
try:
|
|
209
|
+
if entity_type == "event":
|
|
210
|
+
return self._fetch_event_signals(ids)
|
|
211
|
+
return self._fetch_point_signals(ids)
|
|
212
|
+
except Exception as e: # pragma: no cover — defensive
|
|
213
|
+
logger.warning("GraphRanker signal fetch failed: %s", e)
|
|
214
|
+
return {}
|
|
215
|
+
|
|
216
|
+
def _fetch_point_signals(self, ids: list[str]) -> dict[str, dict]:
|
|
217
|
+
cypher = (
|
|
218
|
+
"MATCH (n:Point) WHERE n.id IN $ids "
|
|
219
|
+
"OPTIONAL MATCH (n)-[r:IMPL|NAND]-(:Point {is_operator: true}) "
|
|
220
|
+
"WITH n, count(r) AS degree "
|
|
221
|
+
"RETURN n.id, coalesce(n.confidence, 0.5) AS conf, degree, n.createdAt AS created, "
|
|
222
|
+
" coalesce(n.ep_alpha, 1.0) AS alpha, coalesce(n.ep_beta, 1.0) AS beta, "
|
|
223
|
+
" n.ep_alpha IS NOT NULL AS has_ep"
|
|
224
|
+
)
|
|
225
|
+
rows = self.projection.g.query(cypher, params={"ids": ids}).result_set
|
|
226
|
+
out = {}
|
|
227
|
+
for row in rows:
|
|
228
|
+
pid = row[0]
|
|
229
|
+
variance = _beta_variance(float(row[4]), float(row[5]))
|
|
230
|
+
has_ep = bool(row[6])
|
|
231
|
+
out[pid] = {
|
|
232
|
+
"confidence": float(row[1]),
|
|
233
|
+
"degree": int(row[2]),
|
|
234
|
+
"created": row[3],
|
|
235
|
+
"variance": variance,
|
|
236
|
+
# Uncalibrated (no persisted α/β) is NOT contested.
|
|
237
|
+
"contested": has_ep and variance > CONTESTED_VARIANCE_THRESHOLD,
|
|
238
|
+
"is_event": False,
|
|
239
|
+
}
|
|
240
|
+
return out
|
|
241
|
+
|
|
242
|
+
def _fetch_event_signals(self, ids: list[str]) -> dict[str, dict]:
|
|
243
|
+
cypher = (
|
|
244
|
+
"MATCH (e:Event) WHERE e.eventId IN $ids "
|
|
245
|
+
"OPTIONAL MATCH (e)-[:INSTANTIATES]->(o:Object) "
|
|
246
|
+
"WITH e, count(o) AS instantiates "
|
|
247
|
+
"OPTIONAL MATCH (e)-[:PRODUCES]->(p:Point) "
|
|
248
|
+
"WITH e, instantiates, avg(p.confidence) AS avg_conf "
|
|
249
|
+
"RETURN e.eventId, coalesce(avg_conf, 0.5) AS conf, "
|
|
250
|
+
" instantiates, e.startedAt AS created"
|
|
251
|
+
)
|
|
252
|
+
rows = self.projection.g.query(cypher, params={"ids": ids}).result_set
|
|
253
|
+
out = {}
|
|
254
|
+
for row in rows:
|
|
255
|
+
eid = row[0]
|
|
256
|
+
out[eid] = {
|
|
257
|
+
"confidence": float(row[1]),
|
|
258
|
+
"instantiates": int(row[2]),
|
|
259
|
+
"created": row[3],
|
|
260
|
+
"is_event": True,
|
|
261
|
+
}
|
|
262
|
+
return out
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def _similarity_of(result: dict) -> float:
|
|
266
|
+
"""Extract the similarity signal from a result dict.
|
|
267
|
+
|
|
268
|
+
Preference: scores.rrf (hybrid engine) → similarity (legacy alias) →
|
|
269
|
+
confidence (suggest_entry_points shape). Defaults to 0.0 when absent.
|
|
270
|
+
"""
|
|
271
|
+
scores = result.get("scores")
|
|
272
|
+
if isinstance(scores, dict):
|
|
273
|
+
rrf = scores.get("rrf")
|
|
274
|
+
if isinstance(rrf, (int, float)):
|
|
275
|
+
return float(rrf)
|
|
276
|
+
for key in ("similarity", "confidence"):
|
|
277
|
+
val = result.get(key)
|
|
278
|
+
if isinstance(val, (int, float)):
|
|
279
|
+
return float(val)
|
|
280
|
+
return 0.0
|
tortoise/render.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Static grid renderer — a self-contained HTML/SVG picture of the graph.
|
|
2
|
+
|
|
3
|
+
Deterministic lattice layout (README): points are placed in creation order into
|
|
4
|
+
grid cells; nothing is force-directed. Statement-points are boxes; operator-points
|
|
5
|
+
are diamonds (NAND red / IMPL green) with lines to the points they relate — the
|
|
6
|
+
honest bipartite/hypergraph render, not edges. M0 is a one-shot snapshot; the
|
|
7
|
+
live streaming version is M4.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import html
|
|
12
|
+
import math
|
|
13
|
+
|
|
14
|
+
CELL_W, CELL_H, GAP, MARGIN = 210, 120, 46, 40
|
|
15
|
+
COLORS = {"NAND": "#c0392b", "IMPL": "#2e8b57"}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _wrap(text: str, width: int = 26, max_lines: int = 4) -> list[str]:
|
|
19
|
+
words, lines, cur = text.split(), [], ""
|
|
20
|
+
for w in words:
|
|
21
|
+
if len(cur) + len(w) + 1 > width:
|
|
22
|
+
lines.append(cur)
|
|
23
|
+
cur = w
|
|
24
|
+
else:
|
|
25
|
+
cur = f"{cur} {w}".strip()
|
|
26
|
+
if len(lines) == max_lines:
|
|
27
|
+
break
|
|
28
|
+
if cur and len(lines) < max_lines:
|
|
29
|
+
lines.append(cur)
|
|
30
|
+
if len(lines) == max_lines and (len(" ".join(lines)) < len(text)):
|
|
31
|
+
lines[-1] = lines[-1][:width - 1] + "…"
|
|
32
|
+
return lines
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def render(points: dict[str, dict], *, title: str = "Tortoise graph") -> str:
|
|
36
|
+
ordered = sorted(points.values(), key=lambda p: p.get("createdAt") or p.get("created_at", ""))
|
|
37
|
+
n = len(ordered)
|
|
38
|
+
cols = max(1, math.ceil(math.sqrt(n * 1.6)))
|
|
39
|
+
rows = max(1, math.ceil(n / cols))
|
|
40
|
+
pos = {}
|
|
41
|
+
for i, p in enumerate(ordered):
|
|
42
|
+
r, c = divmod(i, cols)
|
|
43
|
+
pos[p["id"]] = (MARGIN + c * (CELL_W + GAP), MARGIN + r * (CELL_H + GAP))
|
|
44
|
+
|
|
45
|
+
def center(pid):
|
|
46
|
+
x, y = pos[pid]
|
|
47
|
+
return x + CELL_W / 2, y + CELL_H / 2
|
|
48
|
+
|
|
49
|
+
w = MARGIN * 2 + cols * CELL_W + (cols - 1) * GAP
|
|
50
|
+
h = MARGIN * 2 + rows * CELL_H + (rows - 1) * GAP
|
|
51
|
+
|
|
52
|
+
lines, nodes = [], []
|
|
53
|
+
for p in ordered:
|
|
54
|
+
op = p.get("operator")
|
|
55
|
+
x, y = pos[p["id"]]
|
|
56
|
+
if op:
|
|
57
|
+
ox, oy = center(p["id"])
|
|
58
|
+
color = COLORS.get(op["op_type"], "#7f8c8d")
|
|
59
|
+
for src in op["inputs"]:
|
|
60
|
+
if src in pos:
|
|
61
|
+
sx, sy = center(src)
|
|
62
|
+
lines.append(
|
|
63
|
+
f'<line x1="{sx:.0f}" y1="{sy:.0f}" x2="{ox:.0f}" y2="{oy:.0f}" '
|
|
64
|
+
f'stroke="{color}" stroke-width="2" opacity="0.7"/>'
|
|
65
|
+
)
|
|
66
|
+
s = 30
|
|
67
|
+
nodes.append(
|
|
68
|
+
f'<polygon points="{ox:.0f},{oy-s:.0f} {ox+s:.0f},{oy:.0f} '
|
|
69
|
+
f'{ox:.0f},{oy+s:.0f} {ox-s:.0f},{oy:.0f}" fill="{color}"/>'
|
|
70
|
+
f'<text x="{ox:.0f}" y="{oy+4:.0f}" text-anchor="middle" '
|
|
71
|
+
f'fill="#fff" font-size="12" font-weight="700">{op["op_type"]}</text>'
|
|
72
|
+
)
|
|
73
|
+
else:
|
|
74
|
+
spk = html.escape(p["provenance"].get("speaker") or "")
|
|
75
|
+
body = "".join(
|
|
76
|
+
f'<tspan x="{x+14}" dy="{18 if k else 0}">{html.escape(ln)}</tspan>'
|
|
77
|
+
for k, ln in enumerate(_wrap(p["content"]))
|
|
78
|
+
)
|
|
79
|
+
nodes.append(
|
|
80
|
+
f'<g><rect x="{x}" y="{y}" width="{CELL_W}" height="{CELL_H}" rx="10" '
|
|
81
|
+
f'fill="#fbf7ee" stroke="#c9bfa8" stroke-width="1.5"/>'
|
|
82
|
+
f'<text x="{x+14}" y="{y+16}" font-size="10" fill="#a2957a" '
|
|
83
|
+
f'font-weight="700">{spk}</text>'
|
|
84
|
+
f'<text x="{x+14}" y="{y+38}" font-size="13" fill="#3a342a">{body}</text></g>'
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
legend = (
|
|
88
|
+
'<div class="legend"><span><i style="background:#fbf7ee;border:1px solid #c9bfa8">'
|
|
89
|
+
'</i> point</span>'
|
|
90
|
+
f'<span><i style="background:{COLORS["IMPL"]}"></i> IMPL (supports)</span>'
|
|
91
|
+
f'<span><i style="background:{COLORS["NAND"]}"></i> NAND (refutes)</span></div>'
|
|
92
|
+
)
|
|
93
|
+
return f"""<!doctype html><html><head><meta charset="utf-8">
|
|
94
|
+
<title>{html.escape(title)}</title><style>
|
|
95
|
+
body{{margin:0;font-family:-apple-system,system-ui,sans-serif;background:#f4efe4;color:#3a342a}}
|
|
96
|
+
header{{padding:16px 24px;border-bottom:1px solid #dcd2bd}}
|
|
97
|
+
h1{{margin:0;font-size:17px}} .meta{{color:#8a7f68;font-size:13px;margin-top:4px}}
|
|
98
|
+
.legend{{display:flex;gap:20px;padding:10px 24px;font-size:13px;color:#6b6252}}
|
|
99
|
+
.legend i{{display:inline-block;width:13px;height:13px;border-radius:3px;vertical-align:-2px;margin-right:5px}}
|
|
100
|
+
.canvas{{overflow:auto}}
|
|
101
|
+
</style></head><body>
|
|
102
|
+
<header><h1>{html.escape(title)}</h1>
|
|
103
|
+
<div class="meta">{n} points · deterministic lattice layout · M0 snapshot</div></header>
|
|
104
|
+
{legend}
|
|
105
|
+
<div class="canvas"><svg width="{w}" height="{h}" xmlns="http://www.w3.org/2000/svg">
|
|
106
|
+
{''.join(lines)}
|
|
107
|
+
{''.join(nodes)}
|
|
108
|
+
</svg></div></body></html>"""
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# #7049 Manifest — registered sync scripts for the org-sync mini-epic.
|
|
2
|
+
#
|
|
3
|
+
# Each entry maps a script to its issue, entity type, and graph target.
|
|
4
|
+
# Consumed by sync_schedule.py and sync_verify.py for reporting.
|
|
5
|
+
#
|
|
6
|
+
# ponytail: YAML is stdlib-free via PyYAML if available, but this is read
|
|
7
|
+
# manually by scripts that import it. Keep it importable as plain Python dict.
|
|
8
|
+
sync_manifest = {
|
|
9
|
+
"scripts": [
|
|
10
|
+
{
|
|
11
|
+
"issue": 7042,
|
|
12
|
+
"script": "sync_github.py",
|
|
13
|
+
"entity": "Subject+Object",
|
|
14
|
+
"source": "GitHub API (gh orgs/<org>/teams, repos)",
|
|
15
|
+
"graph_node": "Subject(team), Object(repository)",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"issue": 7043,
|
|
19
|
+
"script": "sync_products.py",
|
|
20
|
+
"entity": "Object",
|
|
21
|
+
"source": "docs/teams/*/product/*.md",
|
|
22
|
+
"graph_node": "Object(product)",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"issue": 7044,
|
|
26
|
+
"script": "sync_roles.py",
|
|
27
|
+
"entity": "Subject",
|
|
28
|
+
"source": "operations/subjects/*.md",
|
|
29
|
+
"graph_node": "Subject(role)",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"issue": 7045,
|
|
33
|
+
"script": "sdk.backfill_about_entities()",
|
|
34
|
+
"entity": "Point.aboutEntities",
|
|
35
|
+
"source": "Keyword match Point.content ↔ Subject/Object.name",
|
|
36
|
+
"graph_node": "Point property update",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"issue": 7046,
|
|
40
|
+
"script": "sync_features.py",
|
|
41
|
+
"entity": "Object",
|
|
42
|
+
"source": "GitHub API (issues labeled feature/enhancement)",
|
|
43
|
+
"graph_node": "Object(feature)",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"issue": 7047,
|
|
47
|
+
"script": "sync_schedule.py",
|
|
48
|
+
"entity": "Orchestrator",
|
|
49
|
+
"source": "Runs all sync scripts sequentially",
|
|
50
|
+
"graph_node": "N/A (runner)",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"issue": 7048,
|
|
54
|
+
"script": "sync_verify.py",
|
|
55
|
+
"entity": "Verification",
|
|
56
|
+
"source": "Counts graph entities vs expected kinds",
|
|
57
|
+
"graph_node": "N/A (reporter)",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"issue": 7049,
|
|
61
|
+
"script": "manifest.py",
|
|
62
|
+
"entity": "Manifest",
|
|
63
|
+
"source": "This file — registry of all sync scripts",
|
|
64
|
+
"graph_node": "N/A (metadata)",
|
|
65
|
+
},
|
|
66
|
+
]
|
|
67
|
+
}
|