flock-core 0.3.41__py3-none-any.whl → 0.4.0b2__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.
Potentially problematic release.
This version of flock-core might be problematic. Click here for more details.
- flock/__init__.py +31 -0
- flock/cli/create_flock.py +58 -3
- flock/cli/load_flock.py +135 -1
- flock/cli/registry_management.py +367 -96
- flock/cli/yaml_editor.py +119 -6
- flock/core/__init__.py +13 -1
- flock/core/flock.py +918 -49
- flock/core/flock_agent.py +114 -22
- flock/core/flock_registry.py +37 -5
- flock/core/serialization/serializable.py +35 -8
- flock/core/serialization/serialization_utils.py +96 -1
- flock/core/util/cli_helper.py +2 -2
- flock/core/util/file_path_utils.py +223 -0
- {flock_core-0.3.41.dist-info → flock_core-0.4.0b2.dist-info}/METADATA +1 -1
- {flock_core-0.3.41.dist-info → flock_core-0.4.0b2.dist-info}/RECORD +18 -17
- {flock_core-0.3.41.dist-info → flock_core-0.4.0b2.dist-info}/WHEEL +0 -0
- {flock_core-0.3.41.dist-info → flock_core-0.4.0b2.dist-info}/entry_points.txt +0 -0
- {flock_core-0.3.41.dist-info → flock_core-0.4.0b2.dist-info}/licenses/LICENSE +0 -0
flock/cli/yaml_editor.py
CHANGED
|
@@ -133,6 +133,14 @@ def _view_yaml(obj: Flock | FlockAgent):
|
|
|
133
133
|
"""
|
|
134
134
|
yaml_str = obj.to_yaml()
|
|
135
135
|
|
|
136
|
+
# Add file path information header if it's a Flock with component file paths
|
|
137
|
+
if isinstance(obj, Flock) and hasattr(obj, "_component_file_paths"):
|
|
138
|
+
has_file_paths = bool(getattr(obj, "_component_file_paths", {}))
|
|
139
|
+
if has_file_paths:
|
|
140
|
+
console.print(
|
|
141
|
+
"[bold yellow]Note: This Flock contains components with file paths[/]"
|
|
142
|
+
)
|
|
143
|
+
|
|
136
144
|
# Display with syntax highlighting
|
|
137
145
|
syntax = Syntax(
|
|
138
146
|
yaml_str,
|
|
@@ -147,6 +155,50 @@ def _view_yaml(obj: Flock | FlockAgent):
|
|
|
147
155
|
console.print(Panel("[bold green]YAML View[/]"), justify="center")
|
|
148
156
|
console.print(syntax)
|
|
149
157
|
|
|
158
|
+
# Show file path information if available
|
|
159
|
+
if isinstance(obj, Flock):
|
|
160
|
+
# Get registry for checking file paths
|
|
161
|
+
try:
|
|
162
|
+
from flock.core.flock_registry import get_registry
|
|
163
|
+
|
|
164
|
+
registry = get_registry()
|
|
165
|
+
|
|
166
|
+
if (
|
|
167
|
+
hasattr(registry, "_component_file_paths")
|
|
168
|
+
and registry._component_file_paths
|
|
169
|
+
):
|
|
170
|
+
# Get component names in this Flock
|
|
171
|
+
components = set()
|
|
172
|
+
for agent in obj._agents.values():
|
|
173
|
+
if hasattr(agent, "module") and agent.module:
|
|
174
|
+
module_path = getattr(agent.module, "module_path", None)
|
|
175
|
+
if module_path:
|
|
176
|
+
components.add(module_path)
|
|
177
|
+
|
|
178
|
+
# Show file paths for components in this Flock
|
|
179
|
+
file_paths = []
|
|
180
|
+
for component_name in components:
|
|
181
|
+
if component_name in registry._component_file_paths:
|
|
182
|
+
file_paths.append(
|
|
183
|
+
(
|
|
184
|
+
component_name,
|
|
185
|
+
registry._component_file_paths[component_name],
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
if file_paths:
|
|
190
|
+
console.print("\n[bold cyan]Component File Paths:[/]")
|
|
191
|
+
table = Table()
|
|
192
|
+
table.add_column("Component", style="green")
|
|
193
|
+
table.add_column("File Path", style="yellow")
|
|
194
|
+
|
|
195
|
+
for component_name, file_path in file_paths:
|
|
196
|
+
table.add_row(component_name, file_path)
|
|
197
|
+
|
|
198
|
+
console.print(table)
|
|
199
|
+
except ImportError:
|
|
200
|
+
pass # Skip if registry is not available
|
|
201
|
+
|
|
150
202
|
|
|
151
203
|
def _edit_yaml_directly(obj: Flock | FlockAgent) -> Flock | FlockAgent:
|
|
152
204
|
"""Edit the YAML representation directly using an external editor.
|
|
@@ -160,6 +212,20 @@ def _edit_yaml_directly(obj: Flock | FlockAgent) -> Flock | FlockAgent:
|
|
|
160
212
|
# Convert to YAML
|
|
161
213
|
yaml_str = obj.to_yaml()
|
|
162
214
|
|
|
215
|
+
# Get file path information if it's a Flock
|
|
216
|
+
component_file_paths = {}
|
|
217
|
+
if isinstance(obj, Flock):
|
|
218
|
+
try:
|
|
219
|
+
from flock.core.flock_registry import get_registry
|
|
220
|
+
|
|
221
|
+
registry = get_registry()
|
|
222
|
+
|
|
223
|
+
if hasattr(registry, "_component_file_paths"):
|
|
224
|
+
# Save the file paths to restore later
|
|
225
|
+
component_file_paths = registry._component_file_paths.copy()
|
|
226
|
+
except ImportError:
|
|
227
|
+
pass
|
|
228
|
+
|
|
163
229
|
# Create a temporary file
|
|
164
230
|
with tempfile.NamedTemporaryFile(
|
|
165
231
|
suffix=".yaml", mode="w+", delete=False
|
|
@@ -187,6 +253,26 @@ def _edit_yaml_directly(obj: Flock | FlockAgent) -> Flock | FlockAgent:
|
|
|
187
253
|
try:
|
|
188
254
|
if isinstance(obj, Flock):
|
|
189
255
|
updated_obj = Flock.from_yaml(updated_yaml)
|
|
256
|
+
|
|
257
|
+
# Restore file path information
|
|
258
|
+
if component_file_paths:
|
|
259
|
+
from flock.core.flock_registry import get_registry
|
|
260
|
+
|
|
261
|
+
registry = get_registry()
|
|
262
|
+
|
|
263
|
+
if not hasattr(registry, "_component_file_paths"):
|
|
264
|
+
registry._component_file_paths = {}
|
|
265
|
+
|
|
266
|
+
# Merge the updated registry with the saved file paths
|
|
267
|
+
for (
|
|
268
|
+
component_name,
|
|
269
|
+
file_path,
|
|
270
|
+
) in component_file_paths.items():
|
|
271
|
+
if component_name in registry._components:
|
|
272
|
+
registry._component_file_paths[component_name] = (
|
|
273
|
+
file_path
|
|
274
|
+
)
|
|
275
|
+
|
|
190
276
|
console.print("\n[green]✓[/] YAML parsed successfully!")
|
|
191
277
|
return updated_obj
|
|
192
278
|
elif isinstance(obj, FlockAgent):
|
|
@@ -202,9 +288,11 @@ def _edit_yaml_directly(obj: Flock | FlockAgent) -> Flock | FlockAgent:
|
|
|
202
288
|
# Clean up the temporary file
|
|
203
289
|
try:
|
|
204
290
|
os.unlink(tmp_path)
|
|
205
|
-
except:
|
|
291
|
+
except Exception:
|
|
206
292
|
pass
|
|
207
293
|
|
|
294
|
+
return obj
|
|
295
|
+
|
|
208
296
|
|
|
209
297
|
def _abstract_editor(obj: Flock | FlockAgent) -> Flock | FlockAgent:
|
|
210
298
|
"""Edit object using an abstract form-based editor.
|
|
@@ -273,11 +361,36 @@ def _save_to_file(obj: Flock | FlockAgent):
|
|
|
273
361
|
save_path = Path(file_path)
|
|
274
362
|
save_path.parent.mkdir(parents=True, exist_ok=True)
|
|
275
363
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
364
|
+
# For Flock instances, ask about path_type
|
|
365
|
+
path_type = "absolute" # Default
|
|
366
|
+
if isinstance(obj, Flock):
|
|
367
|
+
path_type_choice = questionary.select(
|
|
368
|
+
"How should file paths be formatted?",
|
|
369
|
+
choices=[
|
|
370
|
+
"absolute (full paths, best for local use)",
|
|
371
|
+
"relative (relative paths, better for sharing)",
|
|
372
|
+
],
|
|
373
|
+
default="absolute (full paths, best for local use)",
|
|
374
|
+
).ask()
|
|
375
|
+
|
|
376
|
+
# Extract just the first word
|
|
377
|
+
path_type = path_type_choice.split()[0]
|
|
280
378
|
|
|
281
|
-
console.print(
|
|
379
|
+
console.print(
|
|
380
|
+
f"[bold]Path type selected: [green]{path_type}[/green][/bold]"
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
try:
|
|
384
|
+
# Save to file with path_type for Flock instances
|
|
385
|
+
if isinstance(obj, Flock):
|
|
386
|
+
obj.to_yaml_file(file_path, path_type=path_type)
|
|
387
|
+
console.print(
|
|
388
|
+
f"\n[green]✓[/] Saved to {file_path} with {path_type} paths"
|
|
389
|
+
)
|
|
390
|
+
else:
|
|
391
|
+
# For FlockAgent or other types, use the original method
|
|
392
|
+
with open(file_path, "w") as f:
|
|
393
|
+
f.write(obj.to_yaml())
|
|
394
|
+
console.print(f"\n[green]✓[/] Saved to {file_path}")
|
|
282
395
|
except Exception as e:
|
|
283
396
|
console.print(f"\n[bold red]Error saving file:[/] {e!s}")
|
flock/core/__init__.py
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
"""This module contains the core classes of the flock package."""
|
|
2
2
|
|
|
3
|
+
from flock.core.context.context import FlockContext
|
|
3
4
|
from flock.core.flock import Flock
|
|
4
5
|
from flock.core.flock_agent import FlockAgent
|
|
5
6
|
from flock.core.flock_evaluator import FlockEvaluator, FlockEvaluatorConfig
|
|
6
7
|
from flock.core.flock_factory import FlockFactory
|
|
7
8
|
from flock.core.flock_module import FlockModule, FlockModuleConfig
|
|
8
|
-
from flock.core.flock_registry import
|
|
9
|
+
from flock.core.flock_registry import (
|
|
10
|
+
FlockRegistry,
|
|
11
|
+
flock_component,
|
|
12
|
+
flock_tool,
|
|
13
|
+
flock_type,
|
|
14
|
+
get_registry,
|
|
15
|
+
)
|
|
9
16
|
|
|
10
17
|
__all__ = [
|
|
11
18
|
"Flock",
|
|
12
19
|
"FlockAgent",
|
|
20
|
+
"FlockContext",
|
|
13
21
|
"FlockEvaluator",
|
|
14
22
|
"FlockEvaluatorConfig",
|
|
15
23
|
"FlockFactory",
|
|
16
24
|
"FlockModule",
|
|
17
25
|
"FlockModuleConfig",
|
|
18
26
|
"FlockRegistry",
|
|
27
|
+
"flock_component",
|
|
28
|
+
"flock_tool",
|
|
29
|
+
"flock_type",
|
|
30
|
+
"get_registry",
|
|
19
31
|
]
|