File size: 29,516 Bytes
8495bb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
#!/usr/bin/env python3
"""

AUREON HYPER TEST β€” 10Γ— EXPANDED ULTIMATE

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━



The ultimate stress test, expanded by a factor of 10 across every axis:



  LLM capabilities        10 β†’ 100  (10 families Γ— 10 variants each)

  Parallel agents          4 β†’ 40

  VM sessions             10 β†’ 100

  Library chain depth    500 β†’ 5000

  Swarm scouts             8 β†’ 80

  Motion snapshots       800 β†’ 8000

  Pillar alignment      5000 β†’ 50000

  Tool registry ops    10000 β†’ 100000

  VM dispatch          10000 β†’ 100000

  Soak workers             4 β†’ 40

  Total test runs         26 β†’ 26 scaled + this hyper test



The hyper test itself authors 100 unique LLM capability skills across

10 families, validates every one, exercises every one, and runs a

40-agent parallel swarm.



  Family             Variants

  ──────────────────────────────────────────

  prompt             10 variants

  reasoning          10 variants (chain depths 1-10)

  planning           10 variants

  reflection         10 variants

  tool_use           10 variants (one per primitive)

  code_gen           10 variants

  recovery           10 variants

  delegation         10 variants

  memory             10 variants

  meta               10 variants



Usage:

  python tests/hyper/expanded_ultimate.py

  python tests/hyper/expanded_ultimate.py --families 1,2,3  # subset

"""

from __future__ import annotations

import argparse
import logging
import os
import sys
import tempfile
import shutil
import threading
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Callable, Dict, List, Tuple

REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
if REPO_ROOT not in sys.path:
    sys.path.insert(0, REPO_ROOT)

logging.basicConfig(level=logging.ERROR, format="%(levelname)s %(name)s %(message)s")

from aureon.autonomous.vm_control import VMControlDispatcher
from aureon.code_architect import (
    CodeArchitect,
    SkillLibrary,
    SkillLevel,
    SkillProposal,
    SkillStatus,
)


# ─────────────────────────────────────────────────────────────────────────────
# Reporting
# ─────────────────────────────────────────────────────────────────────────────

BANNER_WIDTH = 96


def banner(text: str, fill: str = "═") -> None:
    print()
    print(fill * BANNER_WIDTH)
    print(f"  {text}")
    print(fill * BANNER_WIDTH)


def info(text: str) -> None:
    print(f"        {text}")


def ok(text: str) -> None:
    print(f"  [OK]  {text}")


def err(text: str) -> None:
    print(f"  [!!]  {text}")


def progress(text: str) -> None:
    print(f"  ->    {text}")


# ─────────────────────────────────────────────────────────────────────────────
# Capability source generators (one per family)
# ─────────────────────────────────────────────────────────────────────────────


def _name(family: str, variant: str) -> str:
    return f"{family}_{variant}"


def gen_prompt_family() -> List[Tuple[str, str, SkillLevel, List[str], str]]:
    """10 prompt variants: different token budgets and styles."""
    variants = [
        ("default",    400, "You are a helpful reasoning engine."),
        ("short",      100, "Be concise. One sentence max."),
        ("long",       800, "Be thorough and detailed."),
        ("structured", 400, "Return structured JSON-like output."),
        ("code",       600, "Focus on code. Produce runnable snippets."),
        ("creative",   500, "Think creatively. Offer novel angles."),
        ("technical",  600, "Be technically precise."),
        ("terse",       80, "One-word answer if possible."),
        ("verbose",   1000, "Explain every detail."),
        ("json",       400, "Respond in strict JSON only."),
    ]
    out = []
    for name, max_toks, style in variants:
        full = _name("prompt", name)
        code = f'''

def {full}(query="", context=None, **kwargs):

    """Prompt variant: {name} (max_tokens={max_toks})"""

    emit_event("cap.{full}", {{"q": str(query)[:80]}})

    result = ai_reason(

        "{style} " + str(query),

        context=context,

        max_tokens={max_toks},

    )

    return {{

        "ok": result.get("ok", False),

        "text": result.get("text", ""),

        "variant": "{name}",

        "max_tokens": {max_toks},

    }}

'''
        out.append((full, code, SkillLevel.TASK, [], f"Prompt variant {name}"))
    return out


def gen_reasoning_family() -> List[Tuple[str, str, SkillLevel, List[str], str]]:
    """10 reasoning variants: chain depths 1..10."""
    out = []
    for depth in range(1, 11):
        full = _name("reason", f"chain_{depth}")
        code = f'''

def {full}(query="", **kwargs):

    """{depth}-step chain of thought"""

    chain = []

    prior = ""

    i = 0

    while i < {depth}:

        r = ai_reason(

            "Step " + str(i + 1) + " of {depth}: " + str(query),

            context={{"step": i + 1, "prior": str(prior)[:300]}},

            max_tokens=200,

        )

        chain.append(r)

        prior = str(prior) + " | " + str(r.get("text", ""))[:150]

        i = i + 1

    return {{

        "ok": all(c.get("ok", False) for c in chain),

        "depth": {depth},

        "steps": len(chain),

        "final_answer": str(prior)[:600],

    }}

'''
        out.append((full, code, SkillLevel.WORKFLOW, [], f"Reasoning depth {depth}"))
    return out


def gen_planning_family() -> List[Tuple[str, str, SkillLevel, List[str], str]]:
    """10 planning variants: different decomposition strategies."""
    variants = [
        ("short",       3),  ("medium",      5),  ("long",       8),
        ("deep",       10),  ("wide",        5),  ("sequential", 5),
        ("parallel",    5),  ("milestones",  4),  ("phases",     5),
        ("sprint",      6),
    ]
    out = []
    for name, n_steps in variants:
        full = _name("plan", name)
        # Use "\\n" in the template so the generated source gets a literal
        # backslash-n (which Python parses as a newline char at compile time).
        code = f'''

def {full}(goal="", **kwargs):

    """Planning variant: {name} ({n_steps} steps)"""

    emit_event("cap.{full}", {{"goal": str(goal)[:80]}})

    r = ai_reason(

        "Decompose this goal into {n_steps} ordered steps: " + str(goal),

        context={{"variant": "{name}", "n_steps": {n_steps}}},

        max_tokens=500,

    )

    text = r.get("text", "") or ""

    lines = [ln.strip() for ln in text.split("\\n") if ln.strip()]

    sub_goals = lines[:{n_steps}] if lines else ["Analyse", "Act", "Verify"]

    return {{

        "ok": r.get("ok", False),

        "variant": "{name}",

        "goal": goal,

        "sub_goals": sub_goals,

        "count": len(sub_goals),

    }}

'''
        out.append((full, code, SkillLevel.TASK, [], f"Planning variant {name}"))
    return out


def gen_reflection_family() -> List[Tuple[str, str, SkillLevel, List[str], str]]:
    """10 reflection variants."""
    variants = ["reflect", "critique", "affirm", "retrospect", "prospect",
                "introspect", "evaluate", "assess", "review", "meta"]
    out = []
    for i, name in enumerate(variants):
        full = _name("reflection", name)
        code = f'''

def {full}(subject="", last_result=None, **kwargs):

    """Reflection variant: {name}"""

    query = "{name.capitalize()} on: " + str(subject) + ". Prior: " + str(last_result)[:300]

    r = consult_queen(query, context={{"variant": "{name}"}})

    return {{

        "ok": r.get("ok", False),

        "variant": "{name}",

        "text": r.get("text", "")[:400],

    }}

'''
        out.append((full, code, SkillLevel.TASK, [], f"Reflection variant {name}"))
    return out


def gen_tool_use_family() -> List[Tuple[str, str, SkillLevel, List[str], str]]:
    """10 tool-use variants β€” one for each VM primitive category."""
    tools = [
        ("screenshot",    "vm_screenshot",        "{}"),
        ("click",         "vm_left_click",        '{"x": 500, "y": 300}'),
        ("type",          "vm_type_text",         '{"text": "hello"}'),
        ("key",           "vm_press_key",         '{"key": "enter"}'),
        ("hotkey",        "vm_hotkey",            '{"keys": ["ctrl", "c"]}'),
        ("scroll",        "vm_scroll",            '{"x": 500, "y": 300, "direction": "down"}'),
        ("focus",         "vm_focus_window",      '{"title": "Desktop"}'),
        ("list_windows",  "vm_list_windows",      "{}"),
        ("shell",         "vm_execute_shell",     '{"command": "whoami"}'),
        ("powershell",    "vm_execute_powershell", '{"command": "Get-Process"}'),
    ]
    out = []
    for name, primitive, args_literal in tools:
        full = _name("tool", name)
        code = f'''

def {full}(**kwargs):

    """Tool use variant: {name} ({primitive})"""

    result = {primitive}(**{args_literal})

    return {{

        "ok": result.get("ok", False),

        "tool": "{primitive}",

        "variant": "{name}",

        "data": result.get("data", {{}}),

    }}

'''
        out.append((full, code, SkillLevel.TASK, [], f"Tool use {name}"))
    return out


def gen_code_gen_family() -> List[Tuple[str, str, SkillLevel, List[str], str]]:
    """10 code-generation variants."""
    variants = [
        ("function", "a simple function"),
        ("class",    "a class"),
        ("test",     "a unit test"),
        ("refactor", "refactor code"),
        ("debug",    "debug a snippet"),
        ("document", "add documentation"),
        ("explain",  "explain a snippet"),
        ("review",   "review code quality"),
        ("optimize", "optimise performance"),
        ("type",     "add type hints"),
    ]
    out = []
    for name, style in variants:
        full = _name("code", name)
        code = f'''

def {full}(spec="", **kwargs):

    """Code gen variant: {name} ({style})"""

    r = ai_reason(

        "Write Python to {style}: " + str(spec),

        context={{"variant": "{name}", "style": "{style}"}},

        max_tokens=600,

    )

    return {{

        "ok": r.get("ok", False),

        "variant": "{name}",

        "draft": str(r.get("text", ""))[:500],

    }}

'''
        out.append((full, code, SkillLevel.TASK, [], f"Code gen {name}"))
    return out


def gen_recovery_family() -> List[Tuple[str, str, SkillLevel, List[str], str]]:
    """10 recovery variants."""
    variants = ["retry", "rollback", "fallback", "escalate", "alert",
                "circuit_break", "degrade", "restart", "heal", "reroute"]
    out = []
    for name in variants:
        full = _name("recovery", name)
        code = f'''

def {full}(failed_skill="", last_error="", **kwargs):

    """Recovery variant: {name}"""

    r = consult_queen(

        "Recovery strategy '{name}' for skill " + str(failed_skill) + ": " + str(last_error),

        context={{"variant": "{name}", "failed": failed_skill}},

    )

    return {{

        "ok": r.get("ok", False),

        "variant": "{name}",

        "plan": r.get("text", "")[:400],

    }}

'''
        out.append((full, code, SkillLevel.TASK, [], f"Recovery {name}"))
    return out


def gen_delegation_family() -> List[Tuple[str, str, SkillLevel, List[str], str]]:
    """10 delegation variants."""
    variants = ["direct", "best_match", "random", "weighted", "chain",
                "parallel", "sequential", "race", "consensus", "vote"]
    out = []
    for name in variants:
        full = _name("delegate", name)
        code = f'''

def {full}(skill_name="", **kwargs):

    """Delegation variant: {name}"""

    available = list_skills()

    if not available.get("ok", False):

        return {{"ok": False, "variant": "{name}", "error": "no_skills"}}

    names = available.get("skills", [])

    if skill_name and skill_name in names:

        result = call_skill(str(skill_name))

        return {{

            "ok": result.get("ok", False),

            "variant": "{name}",

            "delegated_to": skill_name,

        }}

    return {{

        "ok": True,

        "variant": "{name}",

        "library_size": len(names),

    }}

'''
        out.append((full, code, SkillLevel.TASK, [], f"Delegation {name}"))
    return out


def gen_memory_family() -> List[Tuple[str, str, SkillLevel, List[str], str]]:
    """10 memory variants."""
    variants = ["remember_fact", "recall_fact", "list_facts", "index_facts",
                "search_facts", "summarise", "compress", "expand",
                "prune", "audit"]
    out = []
    for name in variants:
        full = _name("memory", name)
        code = f'''

def {full}(target="", key="fact", value="", **kwargs):

    """Memory variant: {name}"""

    if "remember" in "{name}" or "index" in "{name}":

        r = remember(str(target) or "memory_family", str(key), str(value))

        return {{"ok": r.get("ok", False), "variant": "{name}", "op": "write"}}

    if "recall" in "{name}" or "search" in "{name}":

        r = recall(str(target) or "memory_family", str(key))

        return {{"ok": r.get("ok", False), "variant": "{name}", "op": "read"}}

    available = list_skills()

    return {{

        "ok": available.get("ok", False),

        "variant": "{name}",

        "op": "enumerate",

        "count": available.get("count", 0),

    }}

'''
        out.append((full, code, SkillLevel.TASK, [], f"Memory {name}"))
    return out


def gen_meta_family() -> List[Tuple[str, str, SkillLevel, List[str], str]]:
    """10 meta-cognitive variants."""
    variants = ["improve", "learn", "compose", "decompose", "abstract",
                "instantiate", "audit", "reflect", "plan", "execute"]
    out = []
    for name in variants:
        full = _name("meta", name)
        code = f'''

def {full}(target="", **kwargs):

    """Meta variant: {name}"""

    emit_event("cap.meta.{name}", {{"target": str(target)[:80]}})

    r = consult_queen(

        "Meta operation '{name}' on target: " + str(target),

        context={{"variant": "{name}"}},

    )

    available = list_skills()

    return {{

        "ok": r.get("ok", False),

        "variant": "{name}",

        "insight": r.get("text", "")[:300],

        "library_size": available.get("count", 0),

    }}

'''
        out.append((full, code, SkillLevel.ROLE, [], f"Meta {name}"))
    return out


FAMILIES: Dict[str, Callable[[], List[Tuple[str, str, SkillLevel, List[str], str]]]] = {
    "prompt":     gen_prompt_family,
    "reasoning":  gen_reasoning_family,
    "planning":   gen_planning_family,
    "reflection": gen_reflection_family,
    "tool_use":   gen_tool_use_family,
    "code_gen":   gen_code_gen_family,
    "recovery":   gen_recovery_family,
    "delegation": gen_delegation_family,
    "memory":     gen_memory_family,
    "meta":       gen_meta_family,
}


# ─────────────────────────────────────────────────────────────────────────────
# Harness
# ─────────────────────────────────────────────────────────────────────────────


@dataclass
class HyperHarness:
    tmp: Path
    dispatcher: VMControlDispatcher = field(default=None)
    lib: SkillLibrary = field(default=None)
    architect: CodeArchitect = field(default=None)
    authored: List[str] = field(default_factory=list)
    blocked: List[Tuple[str, str]] = field(default_factory=list)

    @classmethod
    def build(cls) -> "HyperHarness":
        tmp = Path(tempfile.mkdtemp(prefix="aureon_hyper_"))
        h = cls(tmp=tmp)
        h.dispatcher = VMControlDispatcher()
        sid = h.dispatcher.create_session(backend="simulated", name="hyper-vm", make_default=True)
        h.dispatcher.get_session(sid).arm(dry_run=False)
        h.lib = SkillLibrary(storage_dir=h.tmp)
        h.architect = CodeArchitect(library=h.lib, dispatcher=h.dispatcher)
        return h

    def teardown(self) -> None:
        try:
            self.dispatcher.destroy_all()
        except Exception:
            pass
        shutil.rmtree(self.tmp, ignore_errors=True)


# ─────────────────────────────────────────────────────────────────────────────
# Phases
# ─────────────────────────────────────────────────────────────────────────────


def phase_bootstrap(h: HyperHarness) -> Dict[str, Any]:
    banner("HYPER PHASE 1 β€” Bootstrap L0 atomics")
    atomics = h.architect.bootstrap_atomics()
    info(f"Seeded {len(atomics)} atomic skills")
    return {"phase": 1, "atomics": len(atomics), "ok": len(atomics) >= 15}


def phase_author_100(h: HyperHarness, families_filter: List[str] = None) -> Dict[str, Any]:
    banner("HYPER PHASE 2 β€” Author 100 LLM capability skills (10 families Γ— 10 variants)")

    total_authored = 0
    total_blocked = 0
    per_family: Dict[str, Dict[str, int]] = {}

    target_families = families_filter or list(FAMILIES.keys())

    for family_name in target_families:
        generator = FAMILIES.get(family_name)
        if not generator:
            continue

        specs = generator()
        fam_ok = 0
        fam_fail = 0

        for full_name, code, level, deps, desc in specs:
            proposal = SkillProposal(
                name=full_name,
                description=desc,
                level=level,
                category=f"hyper_{family_name}",
                code=code.strip(),
                entry_function=full_name,
                params_schema={"type": "object", "properties": {}},
                dependencies=deps,
                reasoning=f"Hyper test {family_name} variant",
                target="either",
            )
            skill = h.architect._store_if_valid(proposal)
            if skill is None or skill.status == SkillStatus.BLOCKED:
                stored = h.lib.get(full_name)
                err_msg = stored.last_error if stored else "unknown"
                h.blocked.append((full_name, err_msg))
                fam_fail += 1
                total_blocked += 1
            else:
                h.authored.append(full_name)
                fam_ok += 1
                total_authored += 1

        per_family[family_name] = {"ok": fam_ok, "fail": fam_fail}
        status = "OK" if fam_fail == 0 else "PARTIAL"
        info(f"{status:8s} {family_name:12s}  {fam_ok}/{fam_ok + fam_fail} authored")

    # Show blocked details (if any)
    if h.blocked:
        print()
        info("Blocked skills:")
        for name, error in h.blocked[:10]:
            info(f"  {name}: {error[:80]}")
        if len(h.blocked) > 10:
            info(f"  ... and {len(h.blocked) - 10} more")

    expected = len(target_families) * 10
    return {
        "phase": 2,
        "total_authored": total_authored,
        "total_blocked": total_blocked,
        "expected": expected,
        "per_family": per_family,
        "ok": total_authored == expected,
    }


def phase_exercise_100(h: HyperHarness) -> Dict[str, Any]:
    banner("HYPER PHASE 3 β€” Exercise all 100 authored capabilities")

    test_params = {
        "prompt":     {"query": "What is coherence?"},
        "reason":     {"query": "Should we deploy?"},
        "plan":       {"goal": "Ship a new feature"},
        "reflection": {"subject": "today", "last_result": "mixed"},
        "tool":       {},
        "code":       {"spec": "add two numbers"},
        "recovery":   {"failed_skill": "deploy", "last_error": "timeout"},
        "delegate":   {"skill_name": "screenshot"},
        "memory":     {"target": "test", "key": "k", "value": "v"},
        "meta":       {"target": "prompt_default"},
    }

    successes = 0
    failures = 0
    per_family: Dict[str, Dict[str, int]] = {}

    for name in h.authored:
        family = name.split("_")[0]
        params = test_params.get(family, {})

        r = h.architect.execute_skill(name, params=params)
        inner = r.return_value if isinstance(r.return_value, dict) else {}
        inner_ok = bool(r.ok and inner.get("ok", False))

        per_family.setdefault(family, {"ok": 0, "fail": 0})
        if inner_ok:
            successes += 1
            per_family[family]["ok"] += 1
        else:
            failures += 1
            per_family[family]["fail"] += 1

    # Report
    for family, stats in sorted(per_family.items()):
        total = stats["ok"] + stats["fail"]
        marker = "OK" if stats["fail"] == 0 else "PARTIAL"
        info(f"{marker:8s} {family:12s}  {stats['ok']}/{total} executed ok")

    return {
        "phase": 3,
        "total_executed": len(h.authored),
        "successes": successes,
        "failures": failures,
        "per_family": per_family,
        "ok": successes >= len(h.authored) * 0.95,  # at least 95% should work
    }


def phase_parallel_40(h: HyperHarness) -> Dict[str, Any]:
    banner("HYPER PHASE 4 β€” 40-agent parallel swarm")

    if not h.authored:
        return {"phase": 4, "ok": False, "error": "no_capabilities"}

    # Pick 40 distinct skill executions
    import random
    selected = random.sample(h.authored, min(40, len(h.authored)))

    successes = 0
    failures = 0
    durations: List[float] = []
    lock = threading.Lock()

    def run_one(skill_name: str):
        nonlocal successes, failures
        family = skill_name.split("_")[0]
        params = {
            "prompt":     {"query": "bench"},
            "reason":     {"query": "bench"},
            "plan":       {"goal": "bench"},
            "reflection": {"subject": "bench", "last_result": "bench"},
            "tool":       {},
            "code":       {"spec": "bench"},
            "recovery":   {"failed_skill": "bench", "last_error": "bench"},
            "delegate":   {"skill_name": "screenshot"},
            "memory":     {"target": "bench", "key": "k", "value": "v"},
            "meta":       {"target": "bench"},
        }.get(family, {})

        t0 = time.time()
        r = h.architect.execute_skill(skill_name, params=params)
        dt = time.time() - t0

        inner = r.return_value if isinstance(r.return_value, dict) else {}
        inner_ok = bool(r.ok and inner.get("ok", False))

        with lock:
            if inner_ok:
                successes += 1
            else:
                failures += 1
            durations.append(dt)

    with ThreadPoolExecutor(max_workers=40) as ex:
        futures = [ex.submit(run_one, name) for name in selected]
        for f in as_completed(futures):
            pass

    p50 = sorted(durations)[len(durations) // 2] * 1000 if durations else 0
    p99 = sorted(durations)[int(len(durations) * 0.99)] * 1000 if len(durations) > 1 else 0

    info(f"40 parallel runs:  successes={successes}  failures={failures}")
    info(f"  p50 latency: {p50:.2f} ms")
    info(f"  p99 latency: {p99:.2f} ms")

    return {
        "phase": 4,
        "parallel_agents": 40,
        "successes": successes,
        "failures": failures,
        "p50_ms": round(p50, 2),
        "p99_ms": round(p99, 2),
        "ok": failures == 0,
    }


def phase_compose_pipeline(h: HyperHarness) -> Dict[str, Any]:
    banner("HYPER PHASE 5 β€” Compose 10-step multi-family pipeline")

    # Compose one skill from each family into a 10-step workflow
    pipeline = [
        ("prompt_default",   {"query": "What is the market state?"}),
        ("reason_chain_3",   {"query": "Is BTC bullish?"}),
        ("plan_medium",      {"goal": "Ship new feature"}),
        ("reflection_reflect", {"subject": "plan", "last_result": "OK"}),
        ("tool_screenshot",  {}),
        ("code_function",    {"spec": "hash a string"}),
        ("recovery_retry",   {"failed_skill": "step_5", "last_error": "timeout"}),
        ("delegate_direct",  {"skill_name": "screenshot"}),
        ("memory_remember_fact", {"target": "pipeline", "key": "completed", "value": "true"}),
        ("meta_audit",       {"target": "pipeline"}),
    ]

    results = []
    all_ok = True
    for name, params in pipeline:
        if not h.lib.contains(name):
            results.append((name, False, "not_authored"))
            all_ok = False
            continue
        r = h.architect.execute_skill(name, params=params)
        inner = r.return_value if isinstance(r.return_value, dict) else {}
        inner_ok = bool(r.ok and inner.get("ok", False))
        results.append((name, inner_ok, inner.get("variant", "?")))
        if not inner_ok:
            all_ok = False

    for name, step_ok, variant in results:
        marker = "OK" if step_ok else "!!"
        info(f"[{marker}] {name:28s} variant={variant}")

    return {
        "phase": 5,
        "steps": len(pipeline),
        "successes": sum(1 for _, ok, _ in results if ok),
        "ok": all_ok,
    }


# ─────────────────────────────────────────────────────────────────────────────
# Main
# ─────────────────────────────────────────────────────────────────────────────


def main():
    parser = argparse.ArgumentParser(description="Aureon 10x Hyper Test")
    parser.add_argument("--families", type=str, default="",
                        help="Comma-separated family names (default: all)")
    args = parser.parse_args()

    banner("AUREON HYPER TEST β€” 10Γ— EXPANDED ULTIMATE (100 LLM CAPABILITIES)", fill="β–ˆ")
    print()
    info("Objective: 10Γ— expansion across every dimension")
    info("  LLM capabilities:  10 β†’ 100")
    info("  Parallel agents:    4 β†’ 40")
    info("  Library size:      30 β†’ ~120 (20 atomics + 100 capabilities)")
    info("  Cross-family compose pipeline: 10 steps across all 10 families")
    info("Mode: fully in-house AI, zero external LLM")

    families_filter = None
    if args.families:
        families_filter = [f.strip() for f in args.families.split(",")]

    harness = HyperHarness.build()
    all_results: List[Dict[str, Any]] = []

    try:
        all_results.append(phase_bootstrap(harness))
        all_results.append(phase_author_100(harness, families_filter))
        all_results.append(phase_exercise_100(harness))
        all_results.append(phase_parallel_40(harness))
        all_results.append(phase_compose_pipeline(harness))
    finally:
        lib_stats = harness.lib.get_stats()
        harness.teardown()

    banner("HYPER REPORT", fill="β–ˆ")

    passed = sum(1 for r in all_results if r.get("ok"))
    total = len(all_results)

    for r in all_results:
        flag = "[PASS]" if r.get("ok") else "[FAIL]"
        summary_parts = []
        for k, v in r.items():
            if k in ("ok", "phase", "per_family"):
                continue
            if isinstance(v, (dict, list)):
                summary_parts.append(f"{k}={len(v) if isinstance(v, list) else '...'}")
            else:
                summary_parts.append(f"{k}={v}")
        print(f"  {flag}  Phase {r['phase']}: {', '.join(summary_parts)[:170]}")

    print()
    print(f"  Skill library: {lib_stats['total_skills']} skills "
          f"({lib_stats.get('by_status', {}).get('validated', 0)} validated)")
    print(f"    by_level:  {lib_stats.get('by_level', {})}")
    print()
    print(f"  RESULT: {passed}/{total} phases passed")
    print()
    print("β–ˆ" * BANNER_WIDTH)

    sys.exit(0 if passed == total else 1)


if __name__ == "__main__":
    main()