mycorrhizal 0.1.2__py3-none-any.whl → 0.2.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.
- mycorrhizal/_version.py +1 -1
- mycorrhizal/common/__init__.py +15 -3
- mycorrhizal/common/cache.py +114 -0
- mycorrhizal/common/compilation.py +263 -0
- mycorrhizal/common/interface_detection.py +159 -0
- mycorrhizal/common/interfaces.py +3 -50
- mycorrhizal/common/mermaid.py +124 -0
- mycorrhizal/common/wrappers.py +1 -1
- mycorrhizal/hypha/core/builder.py +11 -1
- mycorrhizal/hypha/core/runtime.py +242 -107
- mycorrhizal/mycelium/__init__.py +174 -0
- mycorrhizal/mycelium/core.py +619 -0
- mycorrhizal/mycelium/exceptions.py +30 -0
- mycorrhizal/mycelium/hypha_bridge.py +1143 -0
- mycorrhizal/mycelium/instance.py +440 -0
- mycorrhizal/mycelium/pn_context.py +276 -0
- mycorrhizal/mycelium/runner.py +165 -0
- mycorrhizal/mycelium/spores_integration.py +655 -0
- mycorrhizal/mycelium/tree_builder.py +102 -0
- mycorrhizal/mycelium/tree_spec.py +197 -0
- mycorrhizal/rhizomorph/README.md +82 -33
- mycorrhizal/rhizomorph/core.py +287 -119
- mycorrhizal/septum/TRANSITION_REFERENCE.md +385 -0
- mycorrhizal/{enoki → septum}/core.py +326 -100
- mycorrhizal/{enoki → septum}/testing_utils.py +7 -7
- mycorrhizal/{enoki → septum}/util.py +44 -21
- mycorrhizal/spores/__init__.py +3 -3
- mycorrhizal/spores/core.py +149 -28
- mycorrhizal/spores/dsl/__init__.py +8 -8
- mycorrhizal/spores/dsl/hypha.py +3 -15
- mycorrhizal/spores/dsl/rhizomorph.py +3 -11
- mycorrhizal/spores/dsl/{enoki.py → septum.py} +26 -77
- mycorrhizal/spores/encoder/json.py +21 -12
- mycorrhizal/spores/extraction.py +14 -11
- mycorrhizal/spores/models.py +53 -20
- mycorrhizal-0.2.0.dist-info/METADATA +335 -0
- mycorrhizal-0.2.0.dist-info/RECORD +54 -0
- mycorrhizal-0.1.2.dist-info/METADATA +0 -198
- mycorrhizal-0.1.2.dist-info/RECORD +0 -39
- /mycorrhizal/{enoki → septum}/__init__.py +0 -0
- {mycorrhizal-0.1.2.dist-info → mycorrhizal-0.2.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Mycelium - Unified Orchestration Layer for Mycorrhizal
|
|
4
|
+
|
|
5
|
+
Mycelium provides a unified API for composing Septum FSMs and Rhizomorph behavior trees
|
|
6
|
+
into coherent systems with bidirectional FSM-BT integration.
|
|
7
|
+
|
|
8
|
+
Key Features:
|
|
9
|
+
- Unified @tree decorator for composing FSMs and BTs
|
|
10
|
+
- Mirrored Septum API: @state, @events, @on_state, @transitions (with optional BT integration)
|
|
11
|
+
- FSM-integrated actions: @Action(fsm=SomeFSM) for BT-driven FSM control
|
|
12
|
+
- BT-integrated states: @state(bt=SomeBT) for FSM-driven BT control
|
|
13
|
+
- Unified mermaid diagrams showing full system
|
|
14
|
+
|
|
15
|
+
Example:
|
|
16
|
+
>>> from mycorrhizal.mycelium import tree, Action, Sequence, state, events, on_state, transitions
|
|
17
|
+
>>> from mycorrhizal.mycelium import LabeledTransition
|
|
18
|
+
>>> from mycorrhizal.rhizomorph.core import bt, Status
|
|
19
|
+
>>>
|
|
20
|
+
>>> # Define states using mirrored Septum API
|
|
21
|
+
>>> @state()
|
|
22
|
+
>>> def Idle():
|
|
23
|
+
>>> @events
|
|
24
|
+
>>> class Events(Enum):
|
|
25
|
+
>>> START = auto()
|
|
26
|
+
>>>
|
|
27
|
+
>>> @on_state
|
|
28
|
+
>>> async def on_state(ctx):
|
|
29
|
+
>>> return Events.START
|
|
30
|
+
>>>
|
|
31
|
+
>>> @transitions
|
|
32
|
+
>>> def transitions():
|
|
33
|
+
>>> return [LabeledTransition(Events.START, Working)]
|
|
34
|
+
>>>
|
|
35
|
+
>>> # Define BT tree for FSM integration
|
|
36
|
+
>>> @bt.tree
|
|
37
|
+
>>> def DecideNext():
|
|
38
|
+
>>> @bt.action
|
|
39
|
+
>>> async def check(bb):
|
|
40
|
+
>>> return Status.SUCCESS if bb.ready else Status.FAILURE
|
|
41
|
+
>>>
|
|
42
|
+
>>> @bt.root
|
|
43
|
+
>>> @Sequence
|
|
44
|
+
>>> def main():
|
|
45
|
+
>>> yield check
|
|
46
|
+
>>>
|
|
47
|
+
>>> # Define state with BT integration
|
|
48
|
+
>>> @state(bt=DecideNext)
|
|
49
|
+
>>> def Working():
|
|
50
|
+
>>> @events
|
|
51
|
+
>>> class Events(Enum):
|
|
52
|
+
>>> DONE = auto()
|
|
53
|
+
>>>
|
|
54
|
+
>>> @on_state
|
|
55
|
+
>>> async def on_state_handler(ctx, bt_result):
|
|
56
|
+
>>> if bt_result == Status.SUCCESS:
|
|
57
|
+
>>> return Events.DONE
|
|
58
|
+
>>> return None
|
|
59
|
+
>>>
|
|
60
|
+
>>> @transitions
|
|
61
|
+
>>> def transitions():
|
|
62
|
+
>>> return [LabeledTransition(Events.DONE, Idle)]
|
|
63
|
+
>>>
|
|
64
|
+
>>> # Compose in Mycelium tree
|
|
65
|
+
>>> @tree
|
|
66
|
+
>>> def RobotController():
|
|
67
|
+
>>> @Action(fsm=Idle)
|
|
68
|
+
>>> async def run(bb, tb, fsm_runner):
|
|
69
|
+
>>> if "Working" in fsm_runner.current_state.name:
|
|
70
|
+
>>> return Status.SUCCESS
|
|
71
|
+
>>> fsm_runner.send_message(Idle.Events.START)
|
|
72
|
+
>>> return Status.RUNNING
|
|
73
|
+
>>>
|
|
74
|
+
>>> @root
|
|
75
|
+
>>> @Sequence
|
|
76
|
+
>>> def main():
|
|
77
|
+
>>> yield run
|
|
78
|
+
>>>
|
|
79
|
+
>>> # Use it
|
|
80
|
+
>>> runner = TreeRunner(RobotController, bb=bb, tb=tb)
|
|
81
|
+
>>> await runner.tick()
|
|
82
|
+
>>> print(runner.to_mermaid())
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
# Public API exports
|
|
86
|
+
from .core import (
|
|
87
|
+
tree,
|
|
88
|
+
Action,
|
|
89
|
+
Condition,
|
|
90
|
+
Sequence,
|
|
91
|
+
Selector,
|
|
92
|
+
Parallel,
|
|
93
|
+
root,
|
|
94
|
+
# Mirrored Septum API
|
|
95
|
+
state,
|
|
96
|
+
events,
|
|
97
|
+
on_state,
|
|
98
|
+
transitions,
|
|
99
|
+
# Septum types for re-export
|
|
100
|
+
LabeledTransition,
|
|
101
|
+
StateConfiguration,
|
|
102
|
+
Push,
|
|
103
|
+
Pop,
|
|
104
|
+
Again,
|
|
105
|
+
Unhandled,
|
|
106
|
+
Retry,
|
|
107
|
+
Restart,
|
|
108
|
+
Repeat,
|
|
109
|
+
)
|
|
110
|
+
from .runner import TreeRunner, TreeInstance
|
|
111
|
+
from .exceptions import (
|
|
112
|
+
MyceliumError,
|
|
113
|
+
TreeDefinitionError,
|
|
114
|
+
FSMInstantiationError,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# BT-in-PN integration exports
|
|
118
|
+
from .hypha_bridge import pn, pn_net, PNRunner
|
|
119
|
+
from .pn_context import PNContext
|
|
120
|
+
from ..hypha.core.specs import PlaceType
|
|
121
|
+
|
|
122
|
+
# Spores integration
|
|
123
|
+
from .spores_integration import TreeSporesAdapter, log_tree_event
|
|
124
|
+
|
|
125
|
+
__all__ = [
|
|
126
|
+
# Core decorators
|
|
127
|
+
"tree",
|
|
128
|
+
"Action",
|
|
129
|
+
"Condition",
|
|
130
|
+
"Sequence",
|
|
131
|
+
"Selector",
|
|
132
|
+
"Parallel",
|
|
133
|
+
"root",
|
|
134
|
+
|
|
135
|
+
# Mirrored Septum API
|
|
136
|
+
"state",
|
|
137
|
+
"events",
|
|
138
|
+
"on_state",
|
|
139
|
+
"transitions",
|
|
140
|
+
|
|
141
|
+
# Septum types
|
|
142
|
+
"LabeledTransition",
|
|
143
|
+
"StateConfiguration",
|
|
144
|
+
"Push",
|
|
145
|
+
"Pop",
|
|
146
|
+
"Again",
|
|
147
|
+
"Unhandled",
|
|
148
|
+
"Retry",
|
|
149
|
+
"Restart",
|
|
150
|
+
"Repeat",
|
|
151
|
+
|
|
152
|
+
# Tree runner and instance
|
|
153
|
+
"TreeRunner",
|
|
154
|
+
"TreeInstance",
|
|
155
|
+
|
|
156
|
+
# Exceptions
|
|
157
|
+
"MyceliumError",
|
|
158
|
+
"TreeDefinitionError",
|
|
159
|
+
"FSMInstantiationError",
|
|
160
|
+
|
|
161
|
+
# BT-in-PN integration
|
|
162
|
+
"pn",
|
|
163
|
+
"pn_net",
|
|
164
|
+
"PNRunner",
|
|
165
|
+
"PNContext",
|
|
166
|
+
"PlaceType",
|
|
167
|
+
|
|
168
|
+
# Spores integration
|
|
169
|
+
"TreeSporesAdapter",
|
|
170
|
+
"log_tree_event",
|
|
171
|
+
]
|
|
172
|
+
|
|
173
|
+
# Version info
|
|
174
|
+
__version__ = "0.2.0"
|