Update app.py
Browse files
app.py
CHANGED
|
@@ -55,11 +55,14 @@ def _show_password_gate():
|
|
| 55 |
st.caption("⚠ if you forget your password, your data cannot be recovered.")
|
| 56 |
col1, col2 = st.columns([3, 1])
|
| 57 |
with col1:
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
with col2:
|
| 61 |
enter = st.button("→ enter", type="primary", use_container_width=True)
|
| 62 |
if enter:
|
|
|
|
|
|
|
| 63 |
if not password:
|
| 64 |
st.warning("enter a password first")
|
| 65 |
return
|
|
@@ -168,6 +171,21 @@ def _render_map_html(nodes: list, edges: list) -> str:
|
|
| 168 |
"external": "#1a1a1e",
|
| 169 |
}
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
nodes_js = []
|
| 172 |
nodes_data = []
|
| 173 |
for n in nodes:
|
|
@@ -201,13 +219,17 @@ def _render_map_html(nodes: list, edges: list) -> str:
|
|
| 201 |
src = e["source"].replace("'", "\\'")
|
| 202 |
tgt = e["target"].replace("'", "\\'")
|
| 203 |
rel = (e.get("relationship") or "calls").replace("'", "\\'").replace('"', '\\"')
|
|
|
|
| 204 |
edges_js.append(
|
| 205 |
f"{{id: {i}, from: '{src}', to: '{tgt}', "
|
| 206 |
f"label: '{rel}', "
|
| 207 |
-
|
| 208 |
-
f"
|
|
|
|
|
|
|
| 209 |
f"arrows: {{to: {{enabled: true, scaleFactor: 0.6}}}}, "
|
| 210 |
-
|
|
|
|
| 211 |
)
|
| 212 |
edges_data.append({
|
| 213 |
"source": e["source"], "target": e["target"],
|
|
@@ -247,9 +269,17 @@ def _render_map_html(nodes: list, edges: list) -> str:
|
|
| 247 |
#legend {{
|
| 248 |
position: absolute; bottom: 12px; left: 12px;
|
| 249 |
display: flex; gap: 10px; flex-wrap: wrap;
|
|
|
|
| 250 |
}}
|
| 251 |
.leg {{ display: flex; align-items: center; gap: 4px; font-size: 0.68rem; color: #555; font-family: 'IBM Plex Mono', monospace; }}
|
| 252 |
.leg-dot {{ width: 8px; height: 8px; border-radius: 50%; }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
</style>
|
| 254 |
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500&display=swap" rel="stylesheet">
|
| 255 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js"></script>
|
|
@@ -263,6 +293,14 @@ def _render_map_html(nodes: list, edges: list) -> str:
|
|
| 263 |
<div id="panel-inner"></div>
|
| 264 |
</div>
|
| 265 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
<div id="legend">
|
| 267 |
<div class="leg"><div class="leg-dot" style="background:#34d399"></div>entry</div>
|
| 268 |
<div class="leg"><div class="leg-dot" style="background:#4a9eff"></div>function</div>
|
|
@@ -283,17 +321,36 @@ var kindColors = {{
|
|
| 283 |
var nodes = new vis.DataSet([{nodes_js_str}]);
|
| 284 |
var edges = new vis.DataSet([{edges_js_str}]);
|
| 285 |
var container = document.getElementById('graph');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
var network = new vis.Network(container,
|
| 287 |
{{nodes: nodes, edges: edges}},
|
| 288 |
{{
|
| 289 |
layout: {{
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
}}
|
| 295 |
}},
|
| 296 |
-
physics: {{ enabled: false }},
|
| 297 |
interaction: {{
|
| 298 |
hover: true, tooltipDelay: 150,
|
| 299 |
navigationButtons: true, keyboard: true, zoomView: true
|
|
@@ -303,6 +360,11 @@ var network = new vis.Network(container,
|
|
| 303 |
}}
|
| 304 |
);
|
| 305 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
network.on('click', function(params) {{
|
| 307 |
if (params.nodes.length > 0) {{
|
| 308 |
var nid = params.nodes[0];
|
|
@@ -415,20 +477,26 @@ with st.sidebar:
|
|
| 415 |
is_image = ext in ("png", "jpg", "jpeg", "webp")
|
| 416 |
if fname not in st.session_state.linked_files:
|
| 417 |
st.session_state.linked_files.append(fname)
|
| 418 |
-
changed = True
|
| 419 |
if is_image:
|
|
|
|
|
|
|
| 420 |
st.session_state.file_contents[fname] = (f.getvalue(), "image")
|
|
|
|
| 421 |
else:
|
| 422 |
try:
|
| 423 |
text = f.getvalue().decode("utf-8")
|
| 424 |
language = detect_language(fname)
|
| 425 |
st.session_state.file_contents[fname] = (text, language)
|
| 426 |
-
add_file
|
|
|
|
| 427 |
changed = True
|
|
|
|
| 428 |
except Exception as ex:
|
| 429 |
st.warning(f"could not read {fname}: {ex}")
|
| 430 |
if changed:
|
| 431 |
_save()
|
|
|
|
| 432 |
|
| 433 |
for fname in list(st.session_state.linked_files):
|
| 434 |
col_f, col_x = st.columns([5, 1])
|
|
|
|
| 55 |
st.caption("⚠ if you forget your password, your data cannot be recovered.")
|
| 56 |
col1, col2 = st.columns([3, 1])
|
| 57 |
with col1:
|
| 58 |
+
# FIX: read from session_state key directly so value persists on button-click rerun
|
| 59 |
+
st.text_input("password", type="password", placeholder="enter a password…",
|
| 60 |
+
label_visibility="collapsed", key="pw_input")
|
| 61 |
with col2:
|
| 62 |
enter = st.button("→ enter", type="primary", use_container_width=True)
|
| 63 |
if enter:
|
| 64 |
+
# FIX: read from st.session_state, not a local variable that may be stale
|
| 65 |
+
password = st.session_state.get("pw_input", "")
|
| 66 |
if not password:
|
| 67 |
st.warning("enter a password first")
|
| 68 |
return
|
|
|
|
| 171 |
"external": "#1a1a1e",
|
| 172 |
}
|
| 173 |
|
| 174 |
+
# Edge label color-coding by relationship keyword
|
| 175 |
+
def _edge_label_color(rel: str) -> str:
|
| 176 |
+
rel_lower = rel.lower()
|
| 177 |
+
if any(k in rel_lower for k in ("auth", "verif", "check", "valid")):
|
| 178 |
+
return "#f59e0b" # amber — security/validation
|
| 179 |
+
if any(k in rel_lower for k in ("parse", "read", "load", "fetch", "decode")):
|
| 180 |
+
return "#34d399" # green — data input
|
| 181 |
+
if any(k in rel_lower for k in ("write", "save", "export", "send", "emit")):
|
| 182 |
+
return "#f472b6" # pink — data output
|
| 183 |
+
if any(k in rel_lower for k in ("init", "creat", "setup", "build")):
|
| 184 |
+
return "#a78bfa" # purple — construction
|
| 185 |
+
if any(k in rel_lower for k in ("error", "fail", "except", "handl")):
|
| 186 |
+
return "#ef4444" # red — error handling
|
| 187 |
+
return "#6b93c4" # default blue-grey
|
| 188 |
+
|
| 189 |
nodes_js = []
|
| 190 |
nodes_data = []
|
| 191 |
for n in nodes:
|
|
|
|
| 219 |
src = e["source"].replace("'", "\\'")
|
| 220 |
tgt = e["target"].replace("'", "\\'")
|
| 221 |
rel = (e.get("relationship") or "calls").replace("'", "\\'").replace('"', '\\"')
|
| 222 |
+
lcolor = _edge_label_color(rel)
|
| 223 |
edges_js.append(
|
| 224 |
f"{{id: {i}, from: '{src}', to: '{tgt}', "
|
| 225 |
f"label: '{rel}', "
|
| 226 |
+
# FIX: higher contrast label with background box, bigger font, color-coded
|
| 227 |
+
f"font: {{color: '{lcolor}', size: 11, face: 'IBM Plex Mono', align: 'middle', "
|
| 228 |
+
f"strokeWidth: 3, strokeColor: '#0e0e10', background: '#111820'}}, "
|
| 229 |
+
f"color: {{color: '#2a2a3a', highlight: '{lcolor}', hover: '{lcolor}88'}}, "
|
| 230 |
f"arrows: {{to: {{enabled: true, scaleFactor: 0.6}}}}, "
|
| 231 |
+
# FIX: curvedCW / curvedCCW smooth type for organic curved edges
|
| 232 |
+
f"width: 1.5, smooth: {{type: 'curvedCW', roundness: 0.2}}}}"
|
| 233 |
)
|
| 234 |
edges_data.append({
|
| 235 |
"source": e["source"], "target": e["target"],
|
|
|
|
| 269 |
#legend {{
|
| 270 |
position: absolute; bottom: 12px; left: 12px;
|
| 271 |
display: flex; gap: 10px; flex-wrap: wrap;
|
| 272 |
+
pointer-events: none;
|
| 273 |
}}
|
| 274 |
.leg {{ display: flex; align-items: center; gap: 4px; font-size: 0.68rem; color: #555; font-family: 'IBM Plex Mono', monospace; }}
|
| 275 |
.leg-dot {{ width: 8px; height: 8px; border-radius: 50%; }}
|
| 276 |
+
#edge-legend {{
|
| 277 |
+
position: absolute; bottom: 32px; left: 12px;
|
| 278 |
+
display: flex; gap: 8px; flex-wrap: wrap;
|
| 279 |
+
pointer-events: none; margin-bottom: 4px;
|
| 280 |
+
}}
|
| 281 |
+
.eleg {{ display: flex; align-items: center; gap: 4px; font-size: 0.62rem; color: #555; font-family: 'IBM Plex Mono', monospace; }}
|
| 282 |
+
.eleg-line {{ width: 16px; height: 2px; border-radius: 1px; }}
|
| 283 |
</style>
|
| 284 |
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500&display=swap" rel="stylesheet">
|
| 285 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js"></script>
|
|
|
|
| 293 |
<div id="panel-inner"></div>
|
| 294 |
</div>
|
| 295 |
</div>
|
| 296 |
+
<div id="edge-legend">
|
| 297 |
+
<div class="eleg"><div class="eleg-line" style="background:#f59e0b"></div>auth/validate</div>
|
| 298 |
+
<div class="eleg"><div class="eleg-line" style="background:#34d399"></div>read/load</div>
|
| 299 |
+
<div class="eleg"><div class="eleg-line" style="background:#f472b6"></div>write/send</div>
|
| 300 |
+
<div class="eleg"><div class="eleg-line" style="background:#a78bfa"></div>init/build</div>
|
| 301 |
+
<div class="eleg"><div class="eleg-line" style="background:#ef4444"></div>error/handle</div>
|
| 302 |
+
<div class="eleg"><div class="eleg-line" style="background:#6b93c4"></div>calls</div>
|
| 303 |
+
</div>
|
| 304 |
<div id="legend">
|
| 305 |
<div class="leg"><div class="leg-dot" style="background:#34d399"></div>entry</div>
|
| 306 |
<div class="leg"><div class="leg-dot" style="background:#4a9eff"></div>function</div>
|
|
|
|
| 321 |
var nodes = new vis.DataSet([{nodes_js_str}]);
|
| 322 |
var edges = new vis.DataSet([{edges_js_str}]);
|
| 323 |
var container = document.getElementById('graph');
|
| 324 |
+
|
| 325 |
+
// FIX: Use physics-based forceAtlas2Based layout instead of hierarchical.
|
| 326 |
+
// This creates organic clusters instead of one long horizontal band.
|
| 327 |
+
// Hierarchical layout was forcing all nodes to the same depth level when
|
| 328 |
+
// they had no hierarchy relation, causing the flat single-direction mess.
|
| 329 |
var network = new vis.Network(container,
|
| 330 |
{{nodes: nodes, edges: edges}},
|
| 331 |
{{
|
| 332 |
layout: {{
|
| 333 |
+
improvedLayout: true,
|
| 334 |
+
randomSeed: 42
|
| 335 |
+
}},
|
| 336 |
+
physics: {{
|
| 337 |
+
enabled: true,
|
| 338 |
+
solver: 'forceAtlas2Based',
|
| 339 |
+
forceAtlas2Based: {{
|
| 340 |
+
gravitationalConstant: -80,
|
| 341 |
+
centralGravity: 0.01,
|
| 342 |
+
springLength: 140,
|
| 343 |
+
springConstant: 0.08,
|
| 344 |
+
damping: 0.5,
|
| 345 |
+
avoidOverlap: 0.8
|
| 346 |
+
}},
|
| 347 |
+
stabilization: {{
|
| 348 |
+
enabled: true,
|
| 349 |
+
iterations: 300,
|
| 350 |
+
updateInterval: 25,
|
| 351 |
+
fit: true
|
| 352 |
}}
|
| 353 |
}},
|
|
|
|
| 354 |
interaction: {{
|
| 355 |
hover: true, tooltipDelay: 150,
|
| 356 |
navigationButtons: true, keyboard: true, zoomView: true
|
|
|
|
| 360 |
}}
|
| 361 |
);
|
| 362 |
|
| 363 |
+
// Disable physics after stabilization so nodes don't keep moving
|
| 364 |
+
network.once('stabilizationIterationsDone', function() {{
|
| 365 |
+
network.setOptions({{ physics: {{ enabled: false }} }});
|
| 366 |
+
}});
|
| 367 |
+
|
| 368 |
network.on('click', function(params) {{
|
| 369 |
if (params.nodes.length > 0) {{
|
| 370 |
var nid = params.nodes[0];
|
|
|
|
| 477 |
is_image = ext in ("png", "jpg", "jpeg", "webp")
|
| 478 |
if fname not in st.session_state.linked_files:
|
| 479 |
st.session_state.linked_files.append(fname)
|
| 480 |
+
changed = True # FIX: mark changed for new files regardless of type
|
| 481 |
if is_image:
|
| 482 |
+
# FIX: was missing changed=True for images — they were added to
|
| 483 |
+
# linked_files and file_contents but _save() was never called
|
| 484 |
st.session_state.file_contents[fname] = (f.getvalue(), "image")
|
| 485 |
+
changed = True
|
| 486 |
else:
|
| 487 |
try:
|
| 488 |
text = f.getvalue().decode("utf-8")
|
| 489 |
language = detect_language(fname)
|
| 490 |
st.session_state.file_contents[fname] = (text, language)
|
| 491 |
+
# FIX: set changed=True BEFORE add_file so a RAG error
|
| 492 |
+
# doesn't prevent the file from being saved to session
|
| 493 |
changed = True
|
| 494 |
+
add_file(SID, fname, text)
|
| 495 |
except Exception as ex:
|
| 496 |
st.warning(f"could not read {fname}: {ex}")
|
| 497 |
if changed:
|
| 498 |
_save()
|
| 499 |
+
st.rerun() # FIX: rerun after file upload so sidebar reflects new files immediately
|
| 500 |
|
| 501 |
for fname in list(st.session_state.linked_files):
|
| 502 |
col_f, col_x = st.columns([5, 1])
|