fable-engine 1.3.1__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.
Files changed (104) hide show
  1. fable_compressor.py +356 -0
  2. fable_engine/__init__.py +1 -0
  3. fable_engine/actions/__init__.py +291 -0
  4. fable_engine/actions/cas.py +182 -0
  5. fable_engine/actions/deliberation.py +523 -0
  6. fable_engine/actions/fleet.py +807 -0
  7. fable_engine/actions/lifecycle.py +298 -0
  8. fable_engine/actions/scrapers.py +116 -0
  9. fable_engine/actions/system3.py +815 -0
  10. fable_engine/browser.py +824 -0
  11. fable_engine/cas.py +974 -0
  12. fable_engine/fable_session.json +510 -0
  13. fable_engine/guards.py +283 -0
  14. fable_engine/schema.py +714 -0
  15. fable_engine/scrapers/__init__.py +32 -0
  16. fable_engine/scrapers/arxiv.py +115 -0
  17. fable_engine/scrapers/base.py +386 -0
  18. fable_engine/scrapers/github.py +129 -0
  19. fable_engine/scrapers/reddit.py +154 -0
  20. fable_engine/scrapers/web.py +120 -0
  21. fable_engine/scrapers/x.py +125 -0
  22. fable_engine/scrapers/youtube.py +132 -0
  23. fable_engine/server.py +414 -0
  24. fable_engine/session.py +1819 -0
  25. fable_engine/test_server.py +1362 -0
  26. fable_engine/updater.py +541 -0
  27. fable_engine-1.3.1.dist-info/LICENSE +22 -0
  28. fable_engine-1.3.1.dist-info/METADATA +173 -0
  29. fable_engine-1.3.1.dist-info/RECORD +104 -0
  30. fable_engine-1.3.1.dist-info/WHEEL +5 -0
  31. fable_engine-1.3.1.dist-info/entry_points.txt +5 -0
  32. fable_engine-1.3.1.dist-info/top_level.txt +6 -0
  33. fable_mode/__init__.py +3 -0
  34. fable_mode/__main__.py +4 -0
  35. fable_mode/adapters.py +1014 -0
  36. fable_mode/installer.py +553 -0
  37. fable_mode/launcher.py +437 -0
  38. fable_mode/manifest.py +142 -0
  39. fable_mode/resources.json +114 -0
  40. fable_mode/safety.py +103 -0
  41. fable_mode_entry.py +10 -0
  42. fable_v2/__init__.py +146 -0
  43. fable_v2/adapters.py +151 -0
  44. fable_v2/coder_fleet/__init__.py +100 -0
  45. fable_v2/coder_fleet/ast_tools.py +158 -0
  46. fable_v2/coder_fleet/compute.py +199 -0
  47. fable_v2/coder_fleet/design_engine.py +1316 -0
  48. fable_v2/coder_fleet/diagnostics.py +293 -0
  49. fable_v2/coder_fleet/fleet_dispatcher.py +214 -0
  50. fable_v2/coder_fleet/mock_auditor.py +306 -0
  51. fable_v2/coder_fleet/mutation.py +216 -0
  52. fable_v2/coder_fleet/property_oracle.py +260 -0
  53. fable_v2/coder_fleet/receipt_attestor.py +122 -0
  54. fable_v2/coder_fleet/red_team_swarm.py +908 -0
  55. fable_v2/coder_fleet/test_harness.py +198 -0
  56. fable_v2/coder_fleet/vector_engine.py +1287 -0
  57. fable_v2/coder_fleet/visual.py +357 -0
  58. fable_v2/coder_fleet/workspace.py +153 -0
  59. fable_v2/cortical/__init__.py +20 -0
  60. fable_v2/cortical/plasticity_engine.py +992 -0
  61. fable_v2/execution_broker.py +811 -0
  62. fable_v2/proof_engine.py +1141 -0
  63. fable_v2/protocol.py +485 -0
  64. fable_v2/runtime.py +1010 -0
  65. fable_v2/system3/__init__.py +204 -0
  66. fable_v2/system3/causal.py +558 -0
  67. fable_v2/system3/dialectical.py +577 -0
  68. fable_v2/system3/evolution.py +503 -0
  69. fable_v2/system3/executive.py +338 -0
  70. fable_v2/system3/free_energy.py +479 -0
  71. fable_v2/system3/hyperbolic.py +555 -0
  72. fable_v2/system3/induction.py +336 -0
  73. fable_v2/system3/kripke.py +548 -0
  74. fable_v2/system3/oracle.py +745 -0
  75. fable_v2/verifiers.py +72 -0
  76. tests/__init__.py +1 -0
  77. tests/test_anti_loop_circuit_breaker.py +64 -0
  78. tests/test_auto_updater.py +407 -0
  79. tests/test_coder_fleet.py +535 -0
  80. tests/test_delegation_compiler.py +54 -0
  81. tests/test_descriptor_boundaries.py +126 -0
  82. tests/test_design_engine.py +603 -0
  83. tests/test_epistemic_evidence_validator.py +66 -0
  84. tests/test_execution_broker.py +233 -0
  85. tests/test_fable_v2.py +406 -0
  86. tests/test_fleet_transitions.py +116 -0
  87. tests/test_fsm_redteam_evolution.py +406 -0
  88. tests/test_goal_rubric_and_pipeline.py +367 -0
  89. tests/test_hebbian_plasticity.py +585 -0
  90. tests/test_packaging_runtime.py +194 -0
  91. tests/test_proof_engine.py +259 -0
  92. tests/test_red_team_swarm.py +645 -0
  93. tests/test_redteam_remediation.py +169 -0
  94. tests/test_registration_transaction.py +375 -0
  95. tests/test_requested_regressions.py +467 -0
  96. tests/test_scrapers.py +370 -0
  97. tests/test_server_actions.py +93 -0
  98. tests/test_server_frontier_actions.py +269 -0
  99. tests/test_server_protocol.py +88 -0
  100. tests/test_stealth_browser.py +970 -0
  101. tests/test_system3.py +381 -0
  102. tests/test_system3_deep_integration.py +385 -0
  103. tests/test_system3_frontier.py +436 -0
  104. tests/test_vector_engine.py +608 -0
@@ -0,0 +1,114 @@
1
+ {
2
+ "format": 1,
3
+ "files": [
4
+ "fable_mode/__init__.py",
5
+ "fable_mode/__main__.py",
6
+ "fable_mode/adapters.py",
7
+ "fable_mode/installer.py",
8
+ "fable_mode/launcher.py",
9
+ "fable_mode/manifest.py",
10
+ "fable_mode/safety.py",
11
+ "fable_mode/resources.json",
12
+ "fable_engine/__init__.py",
13
+ "fable_engine/browser.py",
14
+ "fable_engine/actions/__init__.py",
15
+ "fable_engine/actions/cas.py",
16
+ "fable_engine/actions/deliberation.py",
17
+ "fable_engine/actions/fleet.py",
18
+ "fable_engine/actions/lifecycle.py",
19
+ "fable_engine/actions/scrapers.py",
20
+ "fable_engine/actions/system3.py",
21
+ "fable_engine/cas.py",
22
+ "fable_engine/scrapers/__init__.py",
23
+ "fable_engine/scrapers/arxiv.py",
24
+ "fable_engine/scrapers/base.py",
25
+ "fable_engine/scrapers/github.py",
26
+ "fable_engine/scrapers/reddit.py",
27
+ "fable_engine/scrapers/web.py",
28
+ "fable_engine/scrapers/x.py",
29
+ "fable_engine/scrapers/youtube.py",
30
+ "fable_engine/guards.py",
31
+ "fable_engine/schema.py",
32
+ "fable_engine/server.py",
33
+ "fable_engine/session.py",
34
+ "fable_engine/updater.py",
35
+ "fable_engine/fable_session.json",
36
+ "fable_v2/__init__.py",
37
+ "fable_v2/adapters.py",
38
+ "fable_v2/execution_broker.py",
39
+ "fable_v2/protocol.py",
40
+ "fable_v2/runtime.py",
41
+ "fable_v2/system3/__init__.py",
42
+ "fable_v2/system3/causal.py",
43
+ "fable_v2/system3/dialectical.py",
44
+ "fable_v2/system3/evolution.py",
45
+ "fable_v2/system3/executive.py",
46
+ "fable_v2/system3/free_energy.py",
47
+ "fable_v2/system3/hyperbolic.py",
48
+ "fable_v2/system3/induction.py",
49
+ "fable_v2/system3/kripke.py",
50
+ "fable_v2/system3/oracle.py",
51
+ "fable_v2/verifiers.py",
52
+ "fable_v2/proof_engine.py",
53
+ "fable_v2/coder_fleet/__init__.py",
54
+ "fable_v2/coder_fleet/ast_tools.py",
55
+ "fable_v2/coder_fleet/compute.py",
56
+ "fable_v2/coder_fleet/diagnostics.py",
57
+ "fable_v2/coder_fleet/fleet_dispatcher.py",
58
+ "fable_v2/coder_fleet/mock_auditor.py",
59
+ "fable_v2/coder_fleet/mutation.py",
60
+ "fable_v2/coder_fleet/property_oracle.py",
61
+ "fable_v2/coder_fleet/receipt_attestor.py",
62
+ "fable_v2/coder_fleet/test_harness.py",
63
+ "fable_v2/coder_fleet/visual.py",
64
+ "fable_v2/coder_fleet/workspace.py",
65
+ "fable_v2/coder_fleet/red_team_swarm.py",
66
+ "fable_v2/coder_fleet/vector_engine.py",
67
+ "fable_v2/coder_fleet/design_engine.py",
68
+ "fable_v2/cortical/__init__.py",
69
+ "fable_v2/cortical/plasticity_engine.py",
70
+ "fable_compressor.py",
71
+ "run_tests.py",
72
+ "rules/AGENTS.md",
73
+ "rules/GEMINI.md",
74
+ "rules/fable-mode.md",
75
+ "docs/fable-v2-architecture.md",
76
+ "docs/fable-v1-v2-migration.md",
77
+ "docs/system3-architecture.md",
78
+ "skills/fable-mode/SKILL.md",
79
+ "skills/fable-mode/examples/autonomous-agentic-migration.md",
80
+ "skills/fable-mode/examples/breakthrough-algorithm-synthesis.md",
81
+ "skills/fable-mode/examples/deepthink-analysis-proof.md",
82
+ "skills/fable-mode/examples/distributed-system-design.md",
83
+ "skills/fable-mode/examples/swe-bench-pro-debugging.md",
84
+ "skills/fable-mode/examples/weak_model_ollama_setup.md",
85
+ "skills/fable-mode/references/aaa-threejs-game-engine.md",
86
+ "skills/fable-mode/references/agentic-execution.md",
87
+ "skills/fable-mode/references/architectural-blueprinting.md",
88
+ "skills/fable-mode/references/cinematic-design-engine.md",
89
+ "skills/fable-mode/references/anti-slop-frontend-architecture.md",
90
+ "skills/fable-mode/references/cognitive-protocol.md",
91
+ "skills/fable-mode/references/deepthink-mode.md",
92
+ "skills/fable-mode/references/design-tokens-and-typographies.md",
93
+ "skills/fable-mode/references/goal-rubric-and-pipeline-automation.md",
94
+ "skills/fable-mode/references/innovation-engine.md",
95
+ "skills/fable-mode/references/interleaved-verification.md",
96
+ "skills/fable-mode/references/model-velocity-calibration.md",
97
+ "skills/fable-mode/references/prompt-scaffolds.md",
98
+ "skills/fable-mode/references/proof-architecture.md",
99
+ "skills/fable-mode/references/svg-craft-and-vector-design.md",
100
+ "skills/fable-mode/references/system2-session-engine.md",
101
+ "skills/fable-mode/references/system3-meta-cognition.md",
102
+ "skills/fable-mode/references/visual-imagination-engine.md",
103
+ "skills/fable-mode/references/weak-model-frontier-uplift.md",
104
+ "skills/fable-mode/references/adversarial-code-review-swarm.md",
105
+ "skills/fable-mode/references/hebbian-cortical-plasticity.md",
106
+ "skills/fable-mode/cortex/rust.md",
107
+ "skills/fable-mode/cortex/python.md",
108
+ "skills/fable-mode/cortex/design_3d.md",
109
+ "skills/fable-mode/cortex/frontend_design.md",
110
+ "skills/fable-mode/cortex/research.md",
111
+ "skills/fable-mode/cortex/concurrency.md",
112
+ "LICENSE"
113
+ ]
114
+ }
fable_mode/safety.py ADDED
@@ -0,0 +1,103 @@
1
+ """Filesystem safety primitives shared by installer and registration."""
2
+ from __future__ import annotations
3
+
4
+ import os
5
+ import shutil
6
+ import stat
7
+ import threading
8
+ from pathlib import Path
9
+
10
+ # A directory is eligible for recursive removal only after this process created
11
+ # it (or moved an installer-owned install into it). Ownership includes the
12
+ # inode identity, so replacing the path after publication cannot turn cleanup
13
+ # into deletion of an unrelated directory.
14
+ _owned: dict[tuple[int, str], tuple[int, int]] = {}
15
+ _lock = threading.Lock()
16
+
17
+
18
+ def mark_owned_directory(path: Path) -> tuple[int, int]:
19
+ p = Path(path)
20
+ st = p.lstat()
21
+ if not stat.S_ISDIR(st.st_mode):
22
+ raise ValueError("owned path is not a directory")
23
+ identity = (st.st_dev, st.st_ino)
24
+ with _lock:
25
+ _owned[(os.getpid(), os.path.abspath(os.fspath(p)))] = identity
26
+ return identity
27
+
28
+
29
+ def _is_owned(path: Path, st: os.stat_result) -> bool:
30
+ with _lock:
31
+ identity = _owned.get((os.getpid(), os.path.abspath(os.fspath(path))))
32
+ return identity == (st.st_dev, st.st_ino)
33
+
34
+
35
+ def _forget(path: Path) -> None:
36
+ with _lock:
37
+ _owned.pop((os.getpid(), os.path.abspath(os.fspath(path))), None)
38
+
39
+
40
+ def _unsafe_node(path: Path, st: os.stat_result) -> bool:
41
+ attrs = int(getattr(st, "st_file_attributes", 0))
42
+ return bool(attrs & 0x400) or stat.S_ISLNK(st.st_mode) or stat.S_ISSOCK(st.st_mode) or stat.S_ISFIFO(st.st_mode) or stat.S_ISCHR(st.st_mode) or stat.S_ISBLK(st.st_mode)
43
+
44
+
45
+ def safe_cleanup(stage_dir: Path | None, *, expected_identity: tuple[int, ...] | None = None) -> None:
46
+ """Remove one freshly-created, process-owned private directory.
47
+
48
+ No path is resolved before lstat, and ownership is an in-memory capability,
49
+ not a pathname convention. Thus a pre-existing ``.previous-*`` directory,
50
+ the cwd, a repository, a parent, or a symlink can never become a recursive
51
+ deletion target merely by having a plausible name.
52
+ """
53
+ if stage_dir is None:
54
+ return
55
+ p = Path(stage_dir)
56
+ if not p.is_absolute() or p in {Path("/"), Path.cwd().absolute()}:
57
+ raise ValueError("unsafe staging directory")
58
+ try:
59
+ st = p.lstat()
60
+ except FileNotFoundError:
61
+ _forget(p)
62
+ return
63
+ if expected_identity is None:
64
+ identity_ok = _is_owned(p, st)
65
+ else:
66
+ # A four-field capability additionally binds ownership. The original
67
+ # two-field form remains supported for legacy callers/markers.
68
+ identity_ok = tuple(expected_identity[:2]) == (st.st_dev, st.st_ino)
69
+ if len(expected_identity) >= 4:
70
+ identity_ok = identity_ok and tuple(expected_identity[2:4]) == (st.st_uid, st.st_gid)
71
+ if identity_ok:
72
+ pass
73
+ else:
74
+ raise ValueError("unsafe or unowned staging directory")
75
+ if _unsafe_node(p, st) or not stat.S_ISDIR(st.st_mode):
76
+ raise ValueError("unsafe or unowned staging directory")
77
+ # Validate the complete tree without following links before removing it.
78
+ for root, dirs, files in os.walk(p, topdown=True, followlinks=False):
79
+ root_path = Path(root)
80
+ for name in (*dirs, *files):
81
+ child = root_path / name
82
+ child_st = child.lstat()
83
+ if _unsafe_node(child, child_st):
84
+ raise ValueError("unsafe node in staging directory")
85
+ if stat.S_ISREG(child_st.st_mode) and child_st.st_nlink != 1:
86
+ raise ValueError("hardlinked node in staging directory")
87
+ # Last pathname check immediately before recursive deletion. This is a
88
+ # best-effort race mitigation (Python lacks portable descriptor-relative
89
+ # recursive delete), not a descriptor-perfect guarantee.
90
+ try:
91
+ final_st = p.lstat()
92
+ except FileNotFoundError:
93
+ _forget(p)
94
+ return
95
+ final_identity = (final_st.st_dev, final_st.st_ino)
96
+ expected = tuple(expected_identity[:2]) if expected_identity is not None else (st.st_dev, st.st_ino)
97
+ final_capability_ok = final_identity == expected
98
+ if expected_identity is not None and len(expected_identity) >= 4:
99
+ final_capability_ok = final_capability_ok and tuple(expected_identity[2:4]) == (final_st.st_uid, final_st.st_gid)
100
+ if not final_capability_ok or _unsafe_node(p, final_st) or not stat.S_ISDIR(final_st.st_mode):
101
+ raise ValueError("cleanup target changed before deletion")
102
+ shutil.rmtree(p)
103
+ _forget(p)
fable_mode_entry.py ADDED
@@ -0,0 +1,10 @@
1
+ """Frozen/source top-level wrapper; package imports remain valid in both modes."""
2
+ import sys
3
+
4
+ # Install trees have an exact file manifest; runtime probes must not create
5
+ # unlisted __pycache__ artifacts beside the canonical source payload.
6
+ sys.dont_write_bytecode = True
7
+ from fable_mode.launcher import main
8
+
9
+ if __name__ == "__main__":
10
+ raise SystemExit(main())
fable_v2/__init__.py ADDED
@@ -0,0 +1,146 @@
1
+ """Experimental portable Fable V2 runtime with System 3 Meta-Cognitive Architecture."""
2
+
3
+ from .adapters import HOST_PROFILES, HostCapabilities, get_profile
4
+ from .execution_broker import BrokerPolicy, ExecutionBroker
5
+ from .protocol import (
6
+ AutomationPipelineSpec,
7
+ Candidate,
8
+ Evidence,
9
+ FileChangeRecord,
10
+ GoalRubric,
11
+ GoalRubricItem,
12
+ ModelVelocityProfile,
13
+ ProofReceipt,
14
+ TaskSpec,
15
+ ToolReceipt,
16
+ VerificationPolicy,
17
+ VerificationResult,
18
+ VisualMockupSpec,
19
+ )
20
+ from .runtime import FableRun, RunState, new_run
21
+ from .verifiers import CompositeVerifier, FunctionVerifier
22
+ from .proof_engine import (
23
+ DeterministicProofValidator,
24
+ ProofStatus as EngineProofStatus,
25
+ ProofType,
26
+ ProofValidationResult,
27
+ )
28
+ from . import system3
29
+ from .system3 import (
30
+ # System 3 Causal
31
+ CausalDAG,
32
+ CausalNode,
33
+ CausalEdge,
34
+ CausalNodeType,
35
+ BrittlenessReport,
36
+ InterventionResult,
37
+ # System 3 Dialectical
38
+ ThesisCandidate,
39
+ AntithesisCritique,
40
+ Contradiction,
41
+ TRIZPrinciple,
42
+ TRIZContradictionResolver,
43
+ DialecticalSynthesizer,
44
+ EmergentSynthesis,
45
+ # System 3 Evolution
46
+ CognitiveGenome,
47
+ CognitiveGenePool,
48
+ # System 3 Induction
49
+ NeuroSymbolicAxiom,
50
+ AxiomProvenance,
51
+ AxiomStatus,
52
+ MetaProofInducer,
53
+ # System 3 Executive
54
+ CognitiveGear,
55
+ CognitiveBiasType,
56
+ CognitiveBiasFinding,
57
+ CognitiveBiasDetector,
58
+ DynamicSearchHeuristicRewriter,
59
+ SearchHeuristicConfig,
60
+ TriLevelArbitrator,
61
+ System3Executive,
62
+ # System 3 Hyperbolic
63
+ PoincareBall,
64
+ HyperbolicPoint,
65
+ HyperbolicTreeEmbedder,
66
+ TreeEmbeddingNode,
67
+ TreeEmbeddingResult,
68
+ HyperbolicGeometryError,
69
+ # System 3 Kripke
70
+ KripkeStructure,
71
+ KripkeWorld,
72
+ KripkeModelChecker,
73
+ ModelCheckResult,
74
+ CTLOperator,
75
+ FormulaNode,
76
+ FormulaParser,
77
+ # System 3 Free Energy
78
+ ActiveInferenceEngine,
79
+ GenerativeModel,
80
+ Policy,
81
+ PolicyEvaluation,
82
+ FreeEnergyReport,
83
+ create_default_architecture_pomdp,
84
+ # System 3 Oracle
85
+ ProofOracle,
86
+ CurryHowardVerifier,
87
+ UndecidabilityDetector,
88
+ TacticsEngine,
89
+ FormalProofResult,
90
+ ProofStatus,
91
+ Type,
92
+ Term,
93
+ Prop,
94
+ Unit,
95
+ Void,
96
+ Implies,
97
+ And,
98
+ Or,
99
+ Not,
100
+ Eq,
101
+ Forall,
102
+ Exists,
103
+ Var,
104
+ Lam,
105
+ App,
106
+ Pair,
107
+ Fst,
108
+ Snd,
109
+ Inl,
110
+ Inr,
111
+ Case,
112
+ Refl,
113
+ Abort,
114
+ )
115
+
116
+ __all__ = [
117
+ "AutomationPipelineSpec", "BrokerPolicy", "Candidate", "CompositeVerifier", "Evidence",
118
+ "ExecutionBroker", "FableRun", "FileChangeRecord", "FunctionVerifier", "GoalRubric",
119
+ "GoalRubricItem", "HOST_PROFILES", "HostCapabilities", "ModelVelocityProfile",
120
+ "ProofReceipt", "RunState", "TaskSpec", "ToolReceipt", "VerificationPolicy",
121
+ "VerificationResult", "VisualMockupSpec",
122
+ "get_profile", "new_run", "DeterministicProofValidator",
123
+ "system3",
124
+ # System 3 Causal
125
+ "CausalDAG", "CausalNode", "CausalEdge", "CausalNodeType", "BrittlenessReport", "InterventionResult",
126
+ # System 3 Dialectical
127
+ "ThesisCandidate", "AntithesisCritique", "Contradiction", "TRIZPrinciple", "TRIZContradictionResolver",
128
+ "DialecticalSynthesizer", "EmergentSynthesis",
129
+ # System 3 Evolution
130
+ "CognitiveGenome", "CognitiveGenePool",
131
+ # System 3 Induction
132
+ "NeuroSymbolicAxiom", "AxiomProvenance", "AxiomStatus", "MetaProofInducer",
133
+ # System 3 Executive
134
+ "CognitiveGear", "CognitiveBiasType", "CognitiveBiasFinding", "CognitiveBiasDetector",
135
+ "DynamicSearchHeuristicRewriter", "SearchHeuristicConfig", "TriLevelArbitrator", "System3Executive",
136
+ # System 3 Hyperbolic
137
+ "PoincareBall", "HyperbolicPoint", "HyperbolicTreeEmbedder", "TreeEmbeddingNode", "TreeEmbeddingResult", "HyperbolicGeometryError",
138
+ # System 3 Kripke
139
+ "KripkeStructure", "KripkeWorld", "KripkeModelChecker", "ModelCheckResult", "CTLOperator", "FormulaNode", "FormulaParser",
140
+ # System 3 Free Energy
141
+ "ActiveInferenceEngine", "GenerativeModel", "Policy", "PolicyEvaluation", "FreeEnergyReport", "create_default_architecture_pomdp",
142
+ # System 3 Oracle
143
+ "ProofOracle", "CurryHowardVerifier", "UndecidabilityDetector", "TacticsEngine", "FormalProofResult", "ProofStatus",
144
+ "Type", "Term", "Prop", "Unit", "Void", "Implies", "And", "Or", "Not", "Eq", "Forall", "Exists",
145
+ "Var", "Lam", "App", "Pair", "Fst", "Snd", "Inl", "Inr", "Case", "Refl", "Abort",
146
+ ]
fable_v2/adapters.py ADDED
@@ -0,0 +1,151 @@
1
+ """Thin host adapters for portable Fable V2 integrations.
2
+
3
+ The profiles describe a contract, not a claim that every host currently
4
+ supports every capability. An adapter should probe the host at startup and
5
+ only advertise capabilities it can actually provide.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from dataclasses import dataclass, field
11
+ from typing import Iterable, Mapping, Any
12
+
13
+ from .system3 import KripkeStructure, KripkeModelChecker, CausalDAG, CausalNode, CausalNodeType
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class HostCapabilities:
18
+ """Expected capabilities plus optional runtime-probed capabilities.
19
+
20
+ A profile is never authoritative until ``attest`` is called with the
21
+ result of a real host probe. This prevents documentation defaults from
22
+ silently becoming permission or compatibility claims.
23
+ """
24
+
25
+ host: str
26
+ capabilities: frozenset[str] = frozenset()
27
+ tool_aliases: Mapping[str, str] = field(default_factory=dict)
28
+ observed_capabilities: frozenset[str] | None = None
29
+ source: str = "expected-profile"
30
+
31
+ @property
32
+ def is_attested(self) -> bool:
33
+ return self.observed_capabilities is not None
34
+
35
+ def supports(self, capability: str, *, authoritative: bool = False) -> bool:
36
+ available = self.observed_capabilities if self.is_attested else self.capabilities
37
+ return capability in available and (not authoritative or self.is_attested)
38
+
39
+ def normalize(self, tool_name: str) -> str:
40
+ return self.tool_aliases.get(tool_name, tool_name)
41
+
42
+ def attest(self, observed: Iterable[str], source: str = "host-probe") -> "HostCapabilities":
43
+ """Return a runtime-authoritative profile from actual probe results."""
44
+ observed_set = frozenset(str(item).strip() for item in observed if str(item).strip())
45
+ return HostCapabilities(
46
+ host=self.host,
47
+ capabilities=self.capabilities,
48
+ tool_aliases=self.tool_aliases,
49
+ observed_capabilities=observed_set,
50
+ source=source,
51
+ )
52
+
53
+ def verify_temporal_capability_invariants(self, formula: str = "AG(capable)") -> dict[str, object]:
54
+ """Verify modal temporal logic invariant for host capabilities."""
55
+ kripke = KripkeStructure()
56
+ kripke.add_world("w_init", propositions={"initialized", "capable"} if self.is_attested else {"initialized"})
57
+ kripke.add_world("w_ready", propositions={"ready", "capable"} if self.is_attested else {"ready"})
58
+ kripke.add_transition("w_init", "w_ready")
59
+ kripke.add_transition("w_ready", "w_ready")
60
+ checker = KripkeModelChecker(kripke)
61
+ res = checker.check(formula, "w_init")
62
+ return {
63
+ "formula": formula,
64
+ "is_satisfied": res.is_satisfied,
65
+ "satisfying_worlds": sorted(list(res.satisfied_worlds)),
66
+ }
67
+
68
+ def validate_causal_capability_contract(self, target_capabilities: Iterable[str]) -> dict[str, object]:
69
+ """Validate causal DAG dependency flow for required capabilities."""
70
+ targets = list(target_capabilities)
71
+ available = self.observed_capabilities if self.is_attested else self.capabilities
72
+ missing = [c for c in targets if c not in available]
73
+ dag = CausalDAG(name=f"HostCapabilities_{self.host}")
74
+ for c in targets:
75
+ dag.add_node(
76
+ node_id=f"cap_{c}",
77
+ name=c,
78
+ node_type=CausalNodeType.EXOGENOUS if c in available else CausalNodeType.ENDOGENOUS,
79
+ value=1.0 if c in available else 0.0,
80
+ )
81
+ first_target = f"cap_{targets[0]}" if targets else None
82
+ if first_target and first_target in dag.nodes:
83
+ report = dag.evaluate_brittleness(target_metric=first_target)
84
+ b_score = report.overall_brittleness_score
85
+ else:
86
+ b_score = 0.0
87
+ return {
88
+ "is_valid": len(missing) == 0,
89
+ "missing": missing,
90
+ "brittleness_score": b_score,
91
+ "dag": dag.to_dict(),
92
+ }
93
+
94
+ def compatibility_report(self, required: Iterable[str]) -> dict[str, object]:
95
+ required_set = set(required)
96
+ expected = required_set & self.capabilities
97
+ available_set = self.observed_capabilities if self.is_attested else self.capabilities
98
+ available = required_set & available_set
99
+ missing = required_set - available_set
100
+ return {
101
+ "host": self.host,
102
+ "compatible": self.is_attested and not missing,
103
+ "authoritative": self.is_attested,
104
+ "capabilities_source": self.source,
105
+ "required": sorted(required_set),
106
+ "expected": sorted(expected),
107
+ "available": sorted(available),
108
+ "missing": sorted(missing),
109
+ }
110
+
111
+
112
+ # These are conservative *expected* profiles. Real adapters must call
113
+ # ``attest`` after probing the host; expected capabilities are never
114
+ # runtime-authoritative.
115
+ HOST_PROFILES: dict[str, HostCapabilities] = {
116
+ "antigravity": HostCapabilities(
117
+ "antigravity",
118
+ frozenset({"inspect_files", "search_web", "execute_command", "edit_files",
119
+ "run_tests", "delegate_agents"}),
120
+ {"run_command": "execute_command", "write_to_file": "edit_files"},
121
+ ),
122
+ "claude-code": HostCapabilities(
123
+ "claude-code",
124
+ frozenset({"inspect_files", "execute_command", "edit_files", "run_tests"}),
125
+ {"shell": "execute_command"},
126
+ ),
127
+ "codex": HostCapabilities(
128
+ "codex",
129
+ frozenset({"inspect_files", "execute_command", "edit_files", "run_tests"}),
130
+ {"shell": "execute_command"},
131
+ ),
132
+ "cursor": HostCapabilities(
133
+ "cursor",
134
+ frozenset({"inspect_files", "execute_command", "edit_files", "run_tests"}),
135
+ {"terminal": "execute_command"},
136
+ ),
137
+ "grok-build": HostCapabilities("grok-build"),
138
+ "zapia": HostCapabilities(
139
+ "zapia",
140
+ frozenset({"inspect_files", "search_web", "execute_command", "run_tests",
141
+ "delegate_agents"}),
142
+ ),
143
+ }
144
+
145
+
146
+ def get_profile(host: str) -> HostCapabilities:
147
+ """Return a conservative profile; unknown hosts start with no claims."""
148
+ key = host.strip().lower()
149
+ if not key:
150
+ raise ValueError("host must be a non-empty string")
151
+ return HOST_PROFILES.get(key, HostCapabilities(key))
@@ -0,0 +1,100 @@
1
+ """10-Tool Coder Subagent MCP Fleet for Fable V2.
2
+
3
+ Modular, pure-Python engines with zero mandatory external C-dependencies:
4
+ - VisualGroundingEngine: Vector/SVG rendering validation, perceptual diffing, palette & bounding box extraction
5
+ - DiagnosticsEngine: AST syntax & semantic diagnostics, automated quick fixes
6
+ - TreeSitterCodemodEngine: AST structural queries, safe identifier renaming, syntax verification
7
+ - AtomicWorkspaceEngine: File checkpointing, patch inspection, rollbacks, and SHA-256 milestone commits
8
+ - TestHarnessEngine: Subprocess scratch test execution, timeout enforcement, concurrency fuzzing, memory profiling
9
+ - MutationVerifierEngine: AST mutant injection, test suite kill rate auditing, fake test detection
10
+ - MockAuditorEngine: Trivial assertion detection, tautology flagging, mock leakage detection, negative path auditing
11
+ - PropertyOracleEngine: Extreme boundary matrix generation, algebraic roundtrip invariant verification
12
+ - ReceiptAttestorEngine: Subprocess execution attestation, HMAC-SHA256 tamper-evident ToolReceipt generation and verification
13
+ - ComputeOrchestratorEngine: Thinking token budget calculation, Monte Carlo Tree Search, Best-of-N consensus selection
14
+ - CoderFleetDispatcher: Centralized router dispatching actions to all 10 engines
15
+ """
16
+ from __future__ import annotations
17
+
18
+ from .ast_tools import TreeSitterCodemodEngine
19
+ from .compute import ComputeOrchestratorEngine
20
+ from .design_engine import (
21
+ AestheticArchetype,
22
+ AntiSlopAuditor,
23
+ AwwwardsScaffoldGenerator,
24
+ BriefInferenceEngine,
25
+ DesignDials,
26
+ DesignEngine,
27
+ HauteDesignTheme,
28
+ OKLCHColorToken,
29
+ PreFlightDesignGate,
30
+ SlopViolation,
31
+ SpringPreset,
32
+ calculate_contrast_ratio,
33
+ generate_fluid_clamp,
34
+ HAUTE_THEMES,
35
+ SPRING_PRESETS,
36
+ )
37
+ from .diagnostics import DiagnosticsEngine
38
+ from .fleet_dispatcher import CoderFleetDispatcher
39
+ from .mock_auditor import MockAuditorEngine
40
+ from .mutation import MutationVerifierEngine
41
+ from .property_oracle import PropertyOracleEngine
42
+ from .receipt_attestor import ReceiptAttestorEngine
43
+ from .red_team_swarm import (
44
+ AttackVector,
45
+ BreakFinding,
46
+ BreakScenario,
47
+ RedTeamBreakageReport,
48
+ RedTeamSwarm,
49
+ )
50
+ from .test_harness import TestHarnessEngine
51
+ from .vector_engine import (
52
+ BoundingBox,
53
+ FableVectorCompiler,
54
+ OKLCHColor,
55
+ ParametricGeometry,
56
+ VLayoutSolver,
57
+ VNode,
58
+ )
59
+ from .visual import VisualGroundingEngine
60
+ from .workspace import AtomicWorkspaceEngine
61
+
62
+ __all__ = [
63
+ "VisualGroundingEngine",
64
+ "DiagnosticsEngine",
65
+ "TreeSitterCodemodEngine",
66
+ "AtomicWorkspaceEngine",
67
+ "TestHarnessEngine",
68
+ "MutationVerifierEngine",
69
+ "MockAuditorEngine",
70
+ "PropertyOracleEngine",
71
+ "ReceiptAttestorEngine",
72
+ "ComputeOrchestratorEngine",
73
+ "CoderFleetDispatcher",
74
+ "AttackVector",
75
+ "BreakScenario",
76
+ "BreakFinding",
77
+ "RedTeamBreakageReport",
78
+ "RedTeamSwarm",
79
+ "OKLCHColor",
80
+ "ParametricGeometry",
81
+ "BoundingBox",
82
+ "VNode",
83
+ "VLayoutSolver",
84
+ "FableVectorCompiler",
85
+ "AestheticArchetype",
86
+ "AntiSlopAuditor",
87
+ "AwwwardsScaffoldGenerator",
88
+ "BriefInferenceEngine",
89
+ "DesignDials",
90
+ "DesignEngine",
91
+ "HauteDesignTheme",
92
+ "OKLCHColorToken",
93
+ "PreFlightDesignGate",
94
+ "SlopViolation",
95
+ "SpringPreset",
96
+ "calculate_contrast_ratio",
97
+ "generate_fluid_clamp",
98
+ "HAUTE_THEMES",
99
+ "SPRING_PRESETS",
100
+ ]