Repository navigation
Expand file tree
/
Copy pathcore_classes.html
More file actions
364 lines (342 loc) · 18.5 KB
/
Copy pathcore_classes.html
File metadata and controls
364 lines (342 loc) · 18.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Core Classes & Cooperative MRO — ProjectCompass Docs</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css">
<link rel="stylesheet" href="assets/docs.css">
</head>
<body>
<header class="top-nav">
<div class="top-nav-inner">
<a href="../index.html" class="brand-link">
<svg class="compass-mini" viewBox="0 0 36 36" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="18" cy="18" r="15.5" stroke="currentColor" stroke-width="1.6" stroke-dasharray="3 2" opacity="0.6"/>
<circle cx="18" cy="18" r="13" stroke="currentColor" stroke-width="1.5"/>
<path d="M18 7 L18 24" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/>
<path d="M18 8 L26 22 L18 22 Z" fill="currentColor" fill-opacity="0.32" stroke="currentColor" stroke-width="1.3" stroke-linejoin="round"/>
<path d="M16.5 10.5 L11 22 L16.5 22 Z" fill="#fbbf24" fill-opacity="0.45" stroke="#fbbf24" stroke-width="1.2" stroke-linejoin="round"/>
<path d="M10 24.5 L26 24.5 L23.5 27.5 L12.5 27.5 Z" fill="currentColor" fill-opacity="0.5" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round"/>
</svg>
<span>ProjectCompass</span>
<span class="brand-tag">⛵ Regatta Docs</span>
</a>
<div class="nav-actions">
<button type="button" id="theme-toggle" class="theme-toggle-btn">
<span aria-hidden="true">⛵</span> <span>Day Sail</span>
</button>
<button type="button" class="nav-toggle" id="nav-toggle" aria-label="Toggle navigation">
<svg class="icon-menu" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
<svg class="icon-close" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><line x1="6" y1="6" x2="18" y2="18"/><line x1="6" y1="18" x2="18" y2="6"/></svg>
<span class="nav-toggle-label-open">Menu</span>
<span class="nav-toggle-label-close">Close</span>
</button>
</div>
</div>
</header>
<nav class="nav-links" id="nav-links" aria-label="Primary Documentation Navigation">
<span class="nav-group-label">Getting Started</span>
<a href="../index.html">Hub</a>
<a href="overview.html">Overview</a>
<a href="user_guide.html">User Guide</a>
<span class="nav-separator"></span>
<span class="nav-group-label">Architecture</span>
<a href="architecture.html">Architecture</a>
<a href="core_classes.html" class="active">Core Classes</a>
<a href="templates.html">Templates</a>
<a href="routes.html">API & CLI</a>
<span class="nav-separator"></span>
<span class="nav-group-label">Infrastructure</span>
<a href="k0s_setup.html">k0s Setup</a>
<a href="kubernetes_console.html">K8s Console</a>
<a href="worker_library.html">Worker Library</a>
<span class="nav-separator"></span>
<span class="nav-group-label">Operations</span>
<a href="configuration.html">Config</a>
<a href="docker.html">Docker</a>
<a href="demo/index.html" class="nav-demo">🚀 Demo</a>
</nav>
<div class="nav-overlay" id="nav-overlay"></div><section class="page-header">
<div class="page-header-inner">
<div class="breadcrumb">
<a href="../index.html">⛵ Command Deck</a>
<span>/</span>
<span>Pillar II: Shipwright's Hull & Rigging</span>
<span>/</span>
<span>Core Classes & Cooperative MRO</span>
</div>
<h1>Core Classes & Cooperative MRO Reference</h1>
<p class="lead">
Complete class hierarchy, constructors, and method signatures for <code>ProjectCompass</code>, the cooperative inheritance chain, the ConnectorX database service, the Mithril/RAG engines, and the CLI SDK.
</p>
<div class="page-meta-badges">
<span class="badge badge-purple">04 • Standing Rigging</span>
<span class="badge badge-cyan">MRO Chain</span>
<span class="badge badge-gold">Strict OOP Standards</span>
</div>
</div>
</section>
<div class="docs-layout">
<main class="docs-content">
<h2 id="mro-hierarchy">1. The Cooperative Inheritance Chain</h2>
<p>
At the heart of ProjectCompass is the <code>ProjectCompass</code> facade class (`basefun.py`), which unifies catalog management, DuckDB/ConnectorX queries, Git synchronization, HTML template injection, and Kubernetes cluster/flow orchestration through cooperative multiple inheritance:
</p>
<div class="mermaid-card">
<pre class="mermaid">
classDiagram
class BaseK8sClient {
+k8s_namespace: str
+k8s_default_image: str
+_load_k8s_Clients()
+k8s_is_available() bool
}
class K8sClusterUtils {
+k8s_list_nodes() list
+k8s_sync_workers_with_db() list
+k8s_register_worker() dict
+k8s_drain_worker() dict
+k8s_generate_join_token() dict
}
class K8sFlowRunnerUtils {
+k8s_run_flow() dict
+k8s_get_run_logs() str
+k8s_sync_run_status() dict
+k8s_delete_flow_resources() dict
}
class HTMLUtils {
+constants: dict
+html_parts: dict
+substitute_html() dict
+apply_settings()
}
class GitSyncUtils {
+git_init_or_clone() bool
+git_pull() bool
+git_commit_and_push() bool
}
class AnalysisUtils {
+read_single_analysis() dict
+read_multiple_analysis() dict
+upload_new_analysis() str
+save_k8s_flow_analysis() dict
}
class DataUtils {
+sql(sql_query) DataFrame
+run_sql(sql_query, connection_id) DataFrame
+upload_text_files(request)
+list_data() list
}
class ProjectCompass {
+project_folder: str
+create_task_config() dict
}
BaseK8sClient <|-- K8sClusterUtils
K8sClusterUtils <|-- K8sFlowRunnerUtils
K8sFlowRunnerUtils <|-- HTMLUtils
HTMLUtils <|-- GitSyncUtils
GitSyncUtils <|-- AnalysisUtils
HTMLUtils <|-- DataUtils
DataUtils <|-- ProjectCompass
AnalysisUtils <|-- ProjectCompass
</pre>
<div class="mermaid-caption">
Figure 1 — Complete UML class hierarchy of `ProjectCompass` (`basefun.py` and `utils/`).
</div>
</div>
<h2 id="projectcompass-and-datautils">2. Top-Level Facade & Data Engine</h2>
<h3 id="class-projectcompass"><code>ProjectCompass(DataUtils, AnalysisUtils)</code> — <code>basefun.py</code></h3>
<p>
Instantiated once at startup as <code>app.config['WEBAPP']</code>. Separates code assets (<code>dir_path</code>) from mutable runtime storage (<code>data_dir</code>).
</p>
<ul>
<li><code>__init__(dir_path: str, data_dir: str | None = None)</code> — Resolves <code>self.project_folder</code> and initializes all parent mixins via <code>super().__init__(dir_path=dir_path, data_dir=resolved_data)</code>.</li>
<li><code>create_task_config(task_id: str, task_version: str, **kwargs) -> dict</code> <em>(static)</em> — Builds a generic task configuration payload.</li>
<li><code>encrypt_and_compress(text: str, key: str = 'key') -> str</code> & <code>decrypt_and_decompress(...) -> str</code> — Module-level XOR + zlib + Base64 helpers in <code>basefun.py</code>.</li>
</ul>
<h3 id="class-datautils"><code>DataUtils</code> — <code>utils/data_utils.py</code></h3>
<p>
Manages <code>Saved_data/</code> and <code>Saved_queries/</code> and executes SQL queries locally or across remote databases.
</p>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Method Signature</th>
<th>Behavior & Details</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>sql(sql_query: str) -> pd.DataFrame</code></td>
<td>Opens an in-memory DuckDB connection, maps every <code>.csv</code> in <code>Saved_data/</code> to <code>read_csv_auto('/abs/path.csv') AS alias</code>, attaches <code>.sqlite</code>/<code>.db</code> files via <code>ATTACH ... (TYPE sqlite)</code>, executes the query, and always closes the connection in a <code>finally</code> block.</td>
</tr>
<tr>
<td><code>run_sql(sql_query: str, connection_id: int | None = None) -> pd.DataFrame</code></td>
<td>Routes to local DuckDB (`self.sql`) when <code>connection_id is None</code>, or delegates to <code>DbConnectionService().run_query(connection_id, sql_query)</code> for remote ConnectorX databases.</td>
</tr>
<tr>
<td><code>upload_text_files(request) -> None</code></td>
<td>Normalizes uploaded CSV/TSV/delimited files using form-supplied <code>separator</code> and <code>header</code> settings and saves them as clean CSVs in <code>Saved_data/</code>.</td>
</tr>
<tr>
<td><code>list_data() -> list[str]</code></td>
<td>Returns dataset stem names for all <code>.csv</code>, <code>.sqlite</code>, and <code>.db</code> files in <code>Saved_data/</code>.</td>
</tr>
</tbody>
</table>
</div>
<h2 id="analysis-git-html-utils">3. Catalog, Git Sync & HTML Injection Classes</h2>
<h3 id="class-analysisutils"><code>AnalysisUtils(GitSyncUtils)</code> — <code>utils/analysis_utils.py</code></h3>
<p>
Bridges the file-based <code>Analyses/</code> directory with the SQLite <code>AnalysisRecord</code> model and Kubernetes Flow definitions.
</p>
<ul>
<li><code>read_single_analysis(main_folder: str, folder: str) -> dict</code> — Parses <code>metadata.yaml</code> and <code>output_versions.yaml</code>, detects <code>compass_flow.yaml</code> + <code>Dockerfile</code> , and computes UI display fields including the ⚡ Flow badge.</li>
<li><code>read_multiple_analysis() -> dict[str, dict]</code> — Loads all catalog items and syncs them with SQLite and FTS5.</li>
<li><code>upload_new_analysis(request) -> str</code> & <code>modify_analysis(request) -> str</code> — Handles web form uploads, runs <code>pdoc</code>, extracts imports into <code>requirements.txt</code>, extracts SQL from docstrings, and triggers optional Git commit/push.</li>
<li><code>save_k8s_flow_analysis(...) -> dict</code> & <code>list_k8s_flows() -> list[dict]</code> — Persists executable Flow definitions (analyses with <code>compass_flow.yaml</code> + <code>Dockerfile</code>) and synchronizes them with `AnalysisRecord`. Flows are surfaced in the catalog at <code>/analysis</code> with a ⚡ Flow badge.</li>
</ul>
<h3 id="class-gitsyncutils"><code>GitSyncUtils(HTMLUtils)</code> — <code>utils/git_utils.py</code></h3>
<p>
Provides non-interactive Git repository synchronization (`GIT_TERMINAL_PROMPT=0`) for `Analyses/` with automatic credential redaction (`_sanitize_git_text`).
</p>
<ul>
<li><code>git_init_or_clone(repo_url, branch, target_dir, token) -> bool</code> — Clones a remote repo into `Analyses/` on startup or initializes and pulls if files already exist.</li>
<li><code>git_pull(target_dir, branch, token) -> bool</code> — Pulls with `--no-rebase`; if a merge conflict occurs, aborts the merge and preserves local files safely.</li>
<li><code>git_commit_and_push(target_dir, message, branch, token) -> bool</code> — Stages all changes (`git add -A`), commits as `ProjectCompass <compass@cluster.local>`, and pushes to `origin`.</li>
</ul>
<h3 id="class-htmlutils"><code>HTMLUtils(K8sFlowRunnerUtils)</code> — <code>utils/html_utils.py</code></h3>
<ul>
<li><code>__init__(dir_path, data_dir=None, **kwargs)</code> — Loads `constants.yaml`, `tool_choices.yaml`, `links.yaml`, `intro.txt`, `title.txt`, and splits `templates/header.html` by `<!-- start X -->` / `<!-- end X -->` markers into `self.html_parts`.</li>
<li><code>substitute_html(**kwargs) -> dict[str, str]</code> — Renders `head`, `top_container`, and `sidebar_menu` partials with current port, branding, and feature-gate flags.</li>
<li><code>apply_settings(settings: PublicAppSettings) -> None</code> — Applies branding, theme colors, and navigation overrides loaded from `projectcompass.yaml`.</li>
</ul>
<h2 id="k8s-class-hierarchy">4. Kubernetes 4-Tier MRO Hierarchy (<code>utils/k8s_utils.py</code>)</h2>
<p>
All Kubernetes cluster and workload orchestration is implemented across four single-responsibility classes in <code>utils/k8s_utils.py</code>:
</p>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Class</th>
<th>Parent</th>
<th>Key Methods & Responsibilities</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>BaseK8sClient</code></td>
<td><code>object</code></td>
<td>Loads kubeconfig (`KUBECONFIG_PATH` → `KUBECONFIG` → in-cluster ServiceAccount → `~/.kube/config` → `/var/lib/k0s/pki/admin.conf`), initializes `CoreV1Api` and `BatchV1Api`, and provides `k8s_ensure_namespace()`.</td>
</tr>
<tr>
<td><code>K8sClusterUtils</code></td>
<td><code>BaseK8sClient</code></td>
<td>Manages worker nodes: `k8s_list_nodes()`, `k8s_sync_workers_with_db()` (reconciles `Ready`, `NotReady`, `Removed`), `k8s_register_worker()`, `k8s_drain_worker()`, `k8s_delete_worker()`, and `k8s_generate_join_token()`.</td>
</tr>
<tr>
<td><code>K8sFlowRunnerUtils</code></td>
<td><code>K8sClusterUtils</code></td>
<td>Executes isolated `batch/v1` Jobs: creates `pc-flow-cfg-<id>` ConfigMap (`/workspace/flow.py`, `params.json`, `requirements.txt`, `entrypoint.sh`), optional `pc-flow-sec-<id>` Secret, and `pc-flow-job-<id>` Job; spawns background log watcher thread (`_watch_flow_job`).</td>
</tr>
<tr>
<td><code>K8sFlowRunnerUtils</code></td>
<td><code>K8sClusterUtils</code></td>
<td>Orchestrates isolated Kubernetes batch/v1 Jobs: <code>launch_flow_run()</code>, <code>abort_flow_run()</code>, ConfigMap/Secret/Job lifecycle, and background log watcher threads.</td>
</tr>
</tbody>
</table>
</div>
<h2 id="services-rag-cli">5. Database Connections, Settings, RAG & CLI Classes</h2>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Module</th>
<th>Classes / Functions</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>utils/db_connection_service.py</code></td>
<td><code>DbConnectionService</code>, <code>TestResult</code></td>
<td>Validates connection forms, encrypts secrets via <code>CredentialVault</code>, tests connectivity, enforces read-only SQL, and executes queries via <code>connectorx.read_sql()</code>.</td>
</tr>
<tr>
<td><code>utils/credential_vault.py</code></td>
<td><code>CredentialVault</code></td>
<td>Fernet symmetric encryption wrapper for database credentials stored in SQLite.</td>
</tr>
<tr>
<td><code>utils/db_dialects.py</code></td>
<td><code>BaseDbDialect</code> (ABC), <code>DialectRegistry</code>, 7 concrete dialect subclasses</td>
<td>Dialect-specific URI builders, default ports, and read-only query validators for PostgreSQL, MySQL, MariaDB, MSSQL, Oracle, ClickHouse, and SQLite.</td>
</tr>
<tr>
<td><code>utils/app_settings.py</code> & <code>utils/feature_gate.py</code></td>
<td><code>SettingsLoader</code>, <code>AppSettings</code>, <code>FeatureGate</code></td>
<td>Loads and validates <code>projectcompass.yaml</code> + <code>PC_*</code> env overrides; blocks disabled modules at request time.</td>
</tr>
<tr>
<td><code>utils/mithril_client.py</code></td>
<td><code>MithrilClient</code></td>
<td>HTTPX client for Mithril (`/api/generate`, `/api/chat`, `/api/embeddings`, `/api/rerank`, `/api/tags`).</td>
</tr>
<tr>
<td><code>utils/rag_store.py</code> & <code>utils/chunker.py</code></td>
<td><code>RAGStore</code>, <code>chunk_analysis()</code>, <code>chunk_comments()</code></td>
<td>Wraps `scomp_link.llm.rag.RAGPipeline` with ChromaDB persistence, BM25 hybrid retrieval, and Mithril reranking.</td>
</tr>
<tr>
<td><code>utils/cli_utils.py</code></td>
<td><code>CompassAPIClient</code>, <code>CompassCLI</code></td>
<td>Object-oriented HTTP client and `argparse` command dispatcher powering `scripts/compass_cli.py`.</td>
</tr>
</tbody>
</table>
</div>
<div class="page-pager">
<a href="architecture.html" class="pager-link">
<span class="pager-label">← Previous</span>
<span class="pager-title">System Architecture & Storage</span>
</a>
<a href="templates.html" class="pager-link" style="text-align: right;">
<span class="pager-label">Next →</span>
<span class="pager-title">Templates, Header Injection & HTMX</span>
</a>
</div>
</main>
<aside class="docs-toc" aria-label="On this page">
<div class="docs-toc-title">🧭 On This Page</div>
<ul id="toc-list"></ul>
</aside>
</div>
<footer class="site-footer">
<div class="site-footer-inner">
<div>
<strong>ProjectCompass</strong> — <em>Organization Is Everything®</em> • By
<a href="https://giacomosaccaggi.github.io/" target="_blank" rel="noopener">Giacomo Saccaggi</a>
</div>
<div class="footer-links">
<a href="../index.html">Hub</a>
<a href="architecture.html">Architecture</a>
<a href="templates.html">Templates</a>
<a href="k0s_setup.html">k0s Setup</a>
<a href="worker_library.html">Worker Library</a>
<a href="routes.html">API & CLI</a>
</div>
</div>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
<script src="assets/docs.js"></script>
</body>
</html>