AQIT 0.1.0
Loading...
Searching...
No Matches
help_display_ascii.py
Go to the documentation of this file.
1# Copyright (c) 2025-present Aquin Labs Private Limited. All Rights Reserved.
2"""ASCII terminal layout for `aquin help`."""
3
4from __future__ import annotations
5
6from typing import Literal
7
8from aquin.ascii_layout import (
9 box_line,
10 box_lines,
11 center,
12 kv_line,
13 print_banner,
14 print_section,
15 rule,
16 width,
17)
18
19SessionMode = Literal["llm"]
20
21def help_payload(
22 *,
23 connected: bool,
24 mode: SessionMode | None,
25 show_llm: bool,
26 model_id: str | None = None,
27 show_embed: bool = False,
28) -> dict:
29 """Structured help for `--json` / quiet CLI surfaces."""
30 from aquin.session_mode import mode_label
31
32 session: dict = {"loggedIn": bool(connected)}
33 if connected:
34 session["model"] = model_id
35 session["mode"] = mode
36 session["modeLabel"] = mode_label(mode) if mode and model_id else None
37 else:
38 session["account"] = "not logged in"
39
40 sections: list[dict] = [
41 {
42 "title": "Meta",
43 "commands": [
44 ("status", "loaded model & local engine"),
45 ("version", "installed CLI version"),
46 ("license", "read engine license"),
47 ("update", "upgrade from PyPI"),
48 ("desktop install", "install Aquin desktop"),
49 ("setup machine", "GPU host + daemon for desktop tunnel"),
50 ],
51 },
52 {
53 "title": "Develop",
54 "commands": [
55 ("train", "<recipe.yaml> DataRevision → train → gate"),
56 ],
57 },
58 {
59 "title": "Workflow",
60 "commands": [
61 ("load model", "<id> load model into VRAM"),
62 ("unload", "free VRAM"),
63 ("prompt", "<text> try the loaded model"),
64 ("chat", "multi-turn agent"),
65 ("help commands", "tracked command log"),
66 ],
67 },
68 {
69 "title": "Models & SAE",
70 "commands": [
71 ("load model", "<hf-id>"),
72 ("info sae", "<model-l{n}>"),
73 ("load sae", "<model-l{n}> | --user | --path"),
74 ("sae train / align", "train supports --activations"),
75 ("sae catalog-metrics / publish", "public catalog pipeline"),
76 ],
77 },
78 {
79 "title": "Diff",
80 "commands": [
81 ("diff weight", "--checkpoint <path> ||dW|| + merge verdict"),
82 ("diff sae", "--checkpoint <path>"),
83 ("diff residue", "--checkpoint <path> activation drift"),
84 ],
85 },
86 {
87 "title": "Check",
88 "commands": [
89 ("check trajectory", "--checkpoints <glob>"),
90 ],
91 },
92 {
93 "title": "AQIT · capture & SAE",
94 "commands": [
95 ("activations capture", "--dir <path> [--balance] [--granularity token]"),
96 ("activations replay", "--from <capture_dir>"),
97 ("features compare", "--from <capture_dir> --group <field>"),
98 ("capture-activations", "legacy alias"),
99 ("feature locate", "rank SAE features"),
100 ("sae-stats", "--prompts <file>"),
101 ("sae train", "[--activations <dir>] [--balance]"),
102 ],
103 },
104 ]
105
106 if show_llm:
107 sections.append({
108 "title": "AQIT · inspect",
109 "commands": [
110 ("trace", "--prompt --layer"),
111 ("feature logit", "--feature"),
112 ("feature neighbor", "--feature"),
113 ("steer", "--feature_idx [--save|--vector] [--eval]"),
114 ("sweep", "--feature_idx [--strengths] [--eval]"),
115 ("multi-steer", "combined steering"),
116 ("check attention", "--prompt"),
117 ("check layer", "--prompts [--localize]"),
118 ("check perturbation", "--prompt"),
119 ("check confidence", "--prompts"),
120 ("check weight", "trojan + rank"),
121 ("benchmark", "--feature_idx"),
122 ],
123 })
124 sections.append({
125 "title": "AQIT · evals",
126 "commands": [
127 ("eval consistency", "--query --templates"),
128 ("eval suppress", "--topics"),
129 ("eval boundary", "--prompts"),
130 ("eval custom", "--name --prompts"),
131 ("red-team", "[--vectors]"),
132 ],
133 })
134 sections.append({
135 "title": "AQIT · simulate",
136 "commands": [
137 ("simulate", "--dataset"),
138 ("list simulation", "saved runs"),
139 ("replay simulation", "--run_id"),
140 ("compare simulation", "--run_id_a --run_id_b"),
141 ],
142 })
143
144 sections.append({
145 "title": "Shared",
146 "commands": [
147 ("commands list", "tracked outputs"),
148 ("<tool-verb>", "any registry tool one-shot"),
149 ],
150 })
151
152 return {
153 "session": session,
154 "sections": [
155 {
156 "title": s["title"],
157 "commands": [{"cmd": c, "desc": d} for c, d in s["commands"]],
158 }
159 for s in sections
160 ],
161 "next": "aquin load model <id> → aquin prompt \"hello\"",
162 "docs": "https://aquin.app/docs",
163 }
164
165
167 *,
168 connected: bool,
169 mode: SessionMode | None,
170 show_llm: bool,
171 model_id: str | None = None,
172 show_embed: bool = False,
173) -> None:
174 """Section title + real bordered command tables."""
175 from aquin.table_plain import print_table
176
177 payload = help_payload(
178 connected=connected,
179 mode=mode,
180 show_llm=show_llm,
181 show_embed=show_embed,
182 model_id=model_id,
183 )
184
185 session = payload["session"]
186 if session.get("model"):
187 mode_bit = f" ({session['modeLabel']})" if session.get("modeLabel") else ""
188 print(f" model {session['model']}{mode_bit}")
189 else:
190 print(" model not loaded")
191 print()
192
193 for section in payload["sections"]:
194 cmds = section["commands"]
195 print_table(
196 ["command", "description"],
197 [[row["cmd"], row["desc"]] for row in cmds],
198 max_col=56,
199 title=section["title"],
200 )
201 print()
202
203 print(f" {payload['next']}")
204 print(f" docs {payload['docs']}")
205
206
207def _cmd_row(cmd: str, desc: str, w: int) -> list[str]:
208 inner = w - 4
209 cmd_w = min(30, max(len(cmd), inner // 3))
210 text = f" {cmd.ljust(cmd_w)} {desc}"
211 return box_lines(text, w)
212
213
214def _section_rows(
215 title: str,
216 rows: list[tuple[str, str]],
217 *,
218 footnote: str | None = None,
219 w: int,
220) -> None:
221 body: list[str] = []
222 for cmd, desc in rows:
223 body.extend(_cmd_row(cmd, desc, w))
224 if footnote:
225 body.append(box_line("", w))
226 for line in box_lines(f" {footnote}", w):
227 body.append(line)
228 print_section(title, body, w=w)
229
230
231def render_help(
232 *,
233 connected: bool,
234 mode: SessionMode | None,
235 show_llm: bool,
236 model_id: str | None = None,
237 show_embed: bool = False,
238) -> None:
239 from aquin.session_mode import mode_label
240
241 w = width()
242 print_banner(subtitle="HELP", w=w)
243
244 meta_rows: list[str] = []
245 if connected:
246 if model_id:
247 label = f"{model_id} ({mode_label(mode)})" if mode else model_id
248 meta_rows.append(kv_line("model", label, w=w))
249 else:
250 meta_rows.append(kv_line("model", "(not loaded)", w=w))
251 else:
252 meta_rows.append(kv_line("account", "not logged in", w=w))
253 print_section("SESSION", meta_rows, w=w)
254
256 "META",
257 [
258 ("status", "loaded model & local engine"),
259 ("version", "installed CLI version"),
260 ("license", "read engine license"),
261 ("update", "upgrade from PyPI"),
262 ("desktop install", "install Aquin desktop"),
263 ("setup machine", "GPU host + daemon for desktop tunnel"),
264 ],
265 w=w,
266 )
267
269 "WORKFLOW",
270 [
271 ("load model", "<id> load model into VRAM"),
272 ("unload", "free VRAM"),
273 ("prompt", "<text> try the loaded model"),
274 ("chat", "multi-turn agent"),
275 ("help commands", "tracked command log"),
276 ],
277 footnote="load model <id> -> prompt / trace / chat",
278 w=w,
279 )
280
282 "DIFF",
283 [
284 ("diff weight", "--checkpoint <path> ||dW|| + merge verdict"),
285 ("diff sae", "--checkpoint <path>"),
286 ("diff residue", "--checkpoint <path> activation drift"),
287 ],
288 w=w,
289 )
290
292 "MODELS & SAE",
293 [
294 ("load model", "<hf-id>"),
295 ("info sae", "<model-l{n}>"),
296 ("load sae", "<model-l{n}> | --user | --path"),
297 ("sae train / align", "train supports --activations"),
298 ("sae catalog-metrics / publish", "public catalog pipeline"),
299 ],
300 w=w,
301 )
302
304 "CHECK",
305 [
306 ("check trajectory", "--checkpoints <glob>"),
307 ],
308 w=w,
309 )
310
312 "CAPTURE & PROBES",
313 [
314 ("capture-activations", "--dir <path>"),
315 ("feature locate", "rank SAE features"),
316 ("sae-stats", "--prompts <file>"),
317 ],
318 w=w,
319 )
320
321 if show_llm:
323 "INSPECTION | LLM",
324 [
325 ("trace", "--prompt --layer"),
326 ("feature logit", "--feature"),
327 ("feature neighbor", "--feature"),
328 ("steer", "--feature_idx [--save|--vector] [--eval]"),
329 ("multi-steer", "combined steering"),
330 ("check attention", "--prompt"),
331 ("check layer", "--prompts [--localize]"),
332 ("check perturbation", "--prompt"),
333 ("check confidence", "--prompts"),
334 ("check weight", "trojan + rank"),
335 ("benchmark", "--feature_idx"),
336 ],
337 w=w,
338 )
340 "EVALS | LLM",
341 [
342 ("eval consistency", "--query --templates"),
343 ("eval suppress", "--topics"),
344 ("eval boundary", "--prompts"),
345 ("eval custom", "--name --prompts"),
346 ("red-team", "[--vectors]"),
347 ],
348 w=w,
349 )
351 "SIMULATION | LLM",
352 [
353 ("simulate", "--dataset"),
354 ("list simulation", "saved runs"),
355 ("replay simulation", "--run_id"),
356 ("compare simulation", "--run_id_a --run_id_b"),
357 ],
358 w=w,
359 )
360
362 "SHARED",
363 [
364 ("commands list", "tracked outputs"),
365 ("<tool-verb>", "any registry tool one-shot"),
366 ],
367 footnote="GPU tools support --check (JSON + PNG in cwd)",
368 w=w,
369 )
370
371 print(rule("-", w))
372 print(center("1. aquin train recipe.yaml | 2. gate FAIL → inspect | 3. load / eval", w))
373 print(center("docs: https://aquin.app/docs", w))
374 print(rule("-", w))
375 print()
list[str] _cmd_row(str cmd, str desc, int w)
dict help_payload(*, bool connected, SessionMode|None mode, bool show_llm, str|None model_id=None, bool show_embed=False)
None render_help_quiet(*, bool connected, SessionMode|None mode, bool show_llm, str|None model_id=None, bool show_embed=False)
None render_help(*, bool connected, SessionMode|None mode, bool show_llm, str|None model_id=None, bool show_embed=False)
None _section_rows(str title, list[tuple[str, str]] rows, *, str|None footnote=None, int w)