hyperflash 1.0.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.
hyperflash/__init__.py ADDED
@@ -0,0 +1,29 @@
1
+ """
2
+ HyperFlash: The Universal Engineering Reliability Runtime & Multi-Agent Verification Guardrails.
3
+ """
4
+ from __future__ import annotations
5
+
6
+ from hyperflash.core import (
7
+ HyperFlashRuntime,
8
+ build_symbol_graph,
9
+ check_for_elision,
10
+ enforce_elision_guard,
11
+ generate_symbol_graph,
12
+ load_contract,
13
+ run_verification,
14
+ save_contract,
15
+ )
16
+
17
+ __version__: str = "1.0.0"
18
+
19
+ __all__: list[str] = [
20
+ "__version__",
21
+ "HyperFlashRuntime",
22
+ "enforce_elision_guard",
23
+ "build_symbol_graph",
24
+ "check_for_elision",
25
+ "generate_symbol_graph",
26
+ "load_contract",
27
+ "save_contract",
28
+ "run_verification",
29
+ ]
hyperflash/cli.py ADDED
@@ -0,0 +1,303 @@
1
+ """
2
+ CLI entry point for HyperFlash:
3
+ Commands: init, mcp, verify, decide, status, --version.
4
+ """
5
+ from __future__ import annotations
6
+
7
+ import argparse
8
+ import json
9
+ import sys
10
+ from pathlib import Path
11
+ from typing import Any, Sequence
12
+
13
+ from hyperflash import __version__
14
+ from hyperflash.core import (
15
+ generate_symbol_graph,
16
+ load_contract,
17
+ run_verification,
18
+ save_contract,
19
+ )
20
+ from hyperflash.mcp_server import run_stdio_server
21
+ from hyperflash.polyglot import (
22
+ setup_all,
23
+ setup_antigravity,
24
+ setup_claude,
25
+ setup_cursor,
26
+ setup_git_hooks,
27
+ setup_windsurf,
28
+ )
29
+
30
+
31
+ def cmd_init(args: argparse.Namespace) -> int:
32
+ """Handles 'hyperflash init' command."""
33
+ target: str = args.target.lower()
34
+ workspace: str = args.workspace
35
+
36
+ print(f"⚡ HyperFlash: Initializing reliability runtime for target '{target}' in '{workspace}'...")
37
+
38
+ if target == "all":
39
+ results = setup_all(workspace)
40
+ for platform, files in results.items():
41
+ print(f" • {platform.capitalize()}:")
42
+ for f in files:
43
+ print(f" - Configured: {f}")
44
+ elif target == "cursor":
45
+ files = setup_cursor(workspace)
46
+ for f in files:
47
+ print(f" • Configured Cursor: {f}")
48
+ elif target == "claude":
49
+ files = setup_claude(workspace)
50
+ for f in files:
51
+ print(f" • Configured Claude Code: {f}")
52
+ elif target == "windsurf":
53
+ files = setup_windsurf(workspace)
54
+ for f in files:
55
+ print(f" • Configured Windsurf: {f}")
56
+ elif target == "git":
57
+ files = setup_git_hooks(workspace)
58
+ for f in files:
59
+ print(f" • Configured Git pre-commit hook: {f}")
60
+ elif target == "antigravity":
61
+ files = setup_antigravity(workspace)
62
+ for f in files:
63
+ print(f" • Configured Antigravity: {f}")
64
+ else:
65
+ print(f"❌ Unknown target '{target}'. Choose from all, cursor, claude, windsurf, git, antigravity.")
66
+ return 1
67
+
68
+ print("✅ HyperFlash initialization complete. Guardrails are active.")
69
+ return 0
70
+
71
+
72
+ def cmd_mcp(args: argparse.Namespace) -> int:
73
+ """Handles 'hyperflash mcp' command."""
74
+ workspace: str = getattr(args, "workspace", ".")
75
+ run_stdio_server(workspace_dir=workspace)
76
+ return 0
77
+
78
+
79
+ def cmd_verify(args: argparse.Namespace) -> int:
80
+ """Handles 'hyperflash verify' command."""
81
+ tier: int | None = args.tier
82
+ custom_cmd: str = args.custom_cmd or ""
83
+ workspace: str = args.workspace
84
+
85
+ print(f"⚡ Running HyperFlash verification (tier: {tier or 'all'}, custom: '{custom_cmd}')...")
86
+ res = run_verification(tier=tier, custom_cmd=custom_cmd, workspace_dir=workspace)
87
+
88
+ verdict: str = res.get("verdict", "VERDICT: UNKNOWN")
89
+ diagnostics = res.get("diagnostics", [])
90
+
91
+ print("\n" + json.dumps({"diagnostics": diagnostics, "verdict": verdict}, indent=2))
92
+ print(f"\n{verdict}")
93
+
94
+ return 0 if res.get("passed", False) else 1
95
+
96
+
97
+ def cmd_decide(args: argparse.Namespace) -> int:
98
+ """Handles 'hyperflash decide' command."""
99
+ workspace = Path(args.workspace).resolve()
100
+ contract_path = workspace / ".agents/state/contract.json"
101
+ contract = load_contract(contract_path)
102
+
103
+ contract["mode"] = args.mode
104
+ if args.scope:
105
+ contract["allowed_write_scope"] = args.scope
106
+ if args.criteria:
107
+ contract["acceptance_criteria"] = args.criteria
108
+ contract["last_verdict"] = "PENDING"
109
+
110
+ save_contract(contract, contract_path)
111
+ print(f"✅ HyperFlash Contract Updated at {contract_path.as_posix()}:")
112
+ print(f" • Mode: {contract['mode']}")
113
+ print(f" • Allowed Scope: {contract['allowed_write_scope']}")
114
+ print(f" • Criteria: {contract['acceptance_criteria']}")
115
+ return 0
116
+
117
+
118
+ def cmd_status(args: argparse.Namespace) -> int:
119
+ """Handles 'hyperflash status' command."""
120
+ workspace = Path(args.workspace).resolve()
121
+ contract_path = workspace / ".agents/state/contract.json"
122
+ contract = load_contract(contract_path)
123
+ graph = generate_symbol_graph(workspace)
124
+
125
+ print("⚡ HYPERFLASH RUNTIME STATUS")
126
+ print("=" * 50)
127
+ print(f"Workspace: {workspace.as_posix()}")
128
+ print(f"Active Mode: {contract.get('mode', 'uninitialized')}")
129
+ print(f"Effort Profile: {contract.get('effort_profile', 'balanced')}")
130
+ print(f"Allowed Scope: {contract.get('allowed_write_scope', [])}")
131
+ print(f"Acceptance Criteria: {len(contract.get('acceptance_criteria', []))} defined")
132
+ for idx, c in enumerate(contract.get("acceptance_criteria", []), 1):
133
+ print(f" {idx}. {c}")
134
+ print(f"Last Verdict: {contract.get('last_verdict', 'NONE')}")
135
+ print(f"Last Verified TS: {contract.get('last_verified_ts', 0.0)}")
136
+ print(f"Last Mutation TS: {contract.get('last_mutation_ts', 0.0)}")
137
+ print(f"AST Indexed Files: {len(graph)} Python modules")
138
+ print("=" * 50)
139
+ return 0
140
+
141
+
142
+ def cmd_check_elision(args: argparse.Namespace) -> int:
143
+ """Handles 'hyperflash check-elision' command for pre-commit hook."""
144
+ from hyperflash.core import check_for_elision
145
+
146
+ files: list[str] = args.files
147
+ failed: bool = False
148
+ for file_str in files:
149
+ p = Path(file_str)
150
+ if not p.is_file():
151
+ continue
152
+ try:
153
+ content = p.read_text(encoding="utf-8", errors="ignore")
154
+ has_elision, pattern = check_for_elision(content)
155
+ if has_elision:
156
+ print(f"❌ [HYPERFLASH ERROR] Code elision detected in '{file_str}': matched '{pattern}'")
157
+ failed = True
158
+ except Exception:
159
+ pass
160
+
161
+ if failed:
162
+ print("❌ HyperFlash Zero-Elision Guard: Prohibited truncation comments detected.")
163
+ return 1
164
+ return 0
165
+
166
+
167
+ def build_parser() -> argparse.ArgumentParser:
168
+ """Constructs the CLI argument parser."""
169
+ parser = argparse.ArgumentParser(
170
+ prog="hyperflash",
171
+ description="HyperFlash: Universal Engineering Reliability Runtime & Multi-Agent Guardrails",
172
+ )
173
+ parser.add_argument(
174
+ "-v",
175
+ "--version",
176
+ action="version",
177
+ version=f"%(prog)s {__version__}",
178
+ )
179
+
180
+ subparsers = parser.add_subparsers(dest="command", help="Available subcommands")
181
+
182
+ # init
183
+ p_init = subparsers.add_parser("init", help="1-Click setup for Cursor, Claude Code, Windsurf, Git hooks, Antigravity")
184
+ p_init.add_argument(
185
+ "--target",
186
+ choices=["all", "cursor", "claude", "windsurf", "git", "antigravity"],
187
+ default="all",
188
+ help="Target platform to configure (default: all)",
189
+ )
190
+ p_init.add_argument(
191
+ "--workspace",
192
+ type=str,
193
+ default=".",
194
+ help="Workspace root directory (default: .)",
195
+ )
196
+
197
+ # mcp
198
+ p_mcp = subparsers.add_parser("mcp", help="Launch stdio MCP server for universal tool integration")
199
+ p_mcp.add_argument(
200
+ "--workspace",
201
+ type=str,
202
+ default=".",
203
+ help="Workspace root directory (default: .)",
204
+ )
205
+
206
+ # verify
207
+ p_verify = subparsers.add_parser("verify", help="Execute 9-tier deterministic verification hierarchy")
208
+ p_verify.add_argument(
209
+ "--tier",
210
+ type=int,
211
+ default=6,
212
+ help="Maximum tier to run (1-9, default: 6)",
213
+ )
214
+ p_verify.add_argument(
215
+ "--custom-cmd",
216
+ type=str,
217
+ default="",
218
+ help="Optional custom command to validate",
219
+ )
220
+ p_verify.add_argument(
221
+ "--workspace",
222
+ type=str,
223
+ default=".",
224
+ help="Workspace root directory (default: .)",
225
+ )
226
+
227
+ # decide
228
+ p_decide = subparsers.add_parser("decide", help="Initialize or amend contract.json mode and write scope")
229
+ p_decide.add_argument(
230
+ "--mode",
231
+ choices=["implement", "fix", "refactor", "direct", "review", "research"],
232
+ default="implement",
233
+ help="Execution mode (default: implement)",
234
+ )
235
+ p_decide.add_argument(
236
+ "--scope",
237
+ nargs="*",
238
+ default=[],
239
+ help="Allowed write scope file paths or directories",
240
+ )
241
+ p_decide.add_argument(
242
+ "--criteria",
243
+ nargs="*",
244
+ default=[],
245
+ help="Acceptance criteria items",
246
+ )
247
+ p_decide.add_argument(
248
+ "--workspace",
249
+ type=str,
250
+ default=".",
251
+ help="Workspace root directory (default: .)",
252
+ )
253
+
254
+ # status
255
+ p_status = subparsers.add_parser("status", help="Print active contract, AST graph, and verification status")
256
+ p_status.add_argument(
257
+ "--workspace",
258
+ type=str,
259
+ default=".",
260
+ help="Workspace root directory (default: .)",
261
+ )
262
+
263
+ # check-elision (for pre-commit hooks)
264
+ p_check_elision = subparsers.add_parser("check-elision", help="Audit files for banned code truncation comments")
265
+ p_check_elision.add_argument(
266
+ "files",
267
+ nargs="*",
268
+ default=[],
269
+ help="Files to audit for elision patterns",
270
+ )
271
+
272
+ return parser
273
+
274
+
275
+ def main(argv: Sequence[str] | None = None) -> None:
276
+ """CLI main entrypoint."""
277
+ parser = build_parser()
278
+ args = parser.parse_args(argv)
279
+
280
+ if not args.command:
281
+ parser.print_help()
282
+ sys.exit(0)
283
+
284
+ dispatch: dict[str, Any] = {
285
+ "init": cmd_init,
286
+ "mcp": cmd_mcp,
287
+ "verify": cmd_verify,
288
+ "decide": cmd_decide,
289
+ "status": cmd_status,
290
+ "check-elision": cmd_check_elision,
291
+ }
292
+
293
+ handler = dispatch.get(args.command)
294
+ if handler:
295
+ code: int = handler(args)
296
+ sys.exit(code)
297
+ else:
298
+ parser.print_help()
299
+ sys.exit(1)
300
+
301
+
302
+ if __name__ == "__main__":
303
+ main()