flock-core 0.3.41__py3-none-any.whl → 0.4.0b1__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 CHANGED
@@ -31,6 +31,37 @@ def main():
31
31
  from flock.core.util.cli_helper import init_console
32
32
 
33
33
  console = Console()
34
+
35
+ # Show a welcome message on first run with the new tool serialization format
36
+ import os
37
+
38
+ feature_flag_file = os.path.expanduser("~/.flock/tool_serialization_notice")
39
+ if not os.path.exists(feature_flag_file):
40
+ # Create the directory if it doesn't exist
41
+ os.makedirs(os.path.dirname(feature_flag_file), exist_ok=True)
42
+
43
+ # Show the notice about the new tool serialization
44
+ console.print(
45
+ Panel(
46
+ "[bold green]Flock 0.4.0b 'Magpie'- Flock CLI Management Console BETA[/]\n\n"
47
+ "Flock now offers a tool for managing your flock:\n"
48
+ "- Serialization and deserialization of Flock instances\n"
49
+ "- Execution of Flock instances\n"
50
+ "- Managing components, types, and agents via the registry management\n"
51
+ "- Starting a web server to interact with your flock\n"
52
+ "plannes featues: deployment on docker, kubernetes, and more!"
53
+ ),
54
+ justify="center",
55
+ )
56
+ console.line()
57
+
58
+ # Create the flag file to prevent showing this notice again
59
+ with open(feature_flag_file, "w") as f:
60
+ f.write("Tool serialization notice shown")
61
+
62
+ input("Press Enter to continue to the main menu...")
63
+ console.clear()
64
+
34
65
  while True:
35
66
  init_console()
36
67
 
flock/cli/create_flock.py CHANGED
@@ -13,10 +13,12 @@ from rich.panel import Panel
13
13
  from flock.cli.loaded_flock_cli import start_loaded_flock_cli
14
14
  from flock.core.flock import Flock
15
15
  from flock.core.flock_factory import FlockFactory
16
+ from flock.core.logging.logging import get_logger
16
17
  from flock.core.util.cli_helper import init_console
17
18
 
18
19
  # Create console instance
19
20
  console = Console()
21
+ logger = get_logger("cli.create_flock")
20
22
 
21
23
 
22
24
  def create_flock():
@@ -212,9 +214,62 @@ def _save_flock_to_yaml(flock):
212
214
  save_path = Path(file_path)
213
215
  save_path.parent.mkdir(parents=True, exist_ok=True)
214
216
 
217
+ # Ask about path_type
218
+ path_type_choice = questionary.select(
219
+ "How should file paths be formatted?",
220
+ choices=[
221
+ "absolute (full paths, best for local use)",
222
+ "relative (relative paths, better for sharing)",
223
+ ],
224
+ default="absolute (full paths, best for local use)",
225
+ ).ask()
226
+
227
+ # Extract just the first word
228
+ path_type = path_type_choice.split()[0]
229
+
230
+ console.print(
231
+ f"[bold]Path type selected: [green]{path_type}[/green][/bold]"
232
+ )
233
+
215
234
  try:
216
- # Save the Flock to YAML
217
- flock.to_yaml_file(file_path)
218
- console.print(f"\n[green]✓[/] Flock saved to {file_path}")
235
+ # Check if the flock has tools to provide a helpful message
236
+ has_tools = False
237
+ for agent in flock.agents.values():
238
+ if agent.tools and len(agent.tools) > 0:
239
+ has_tools = True
240
+ break
241
+
242
+ # Save the Flock to YAML with proper tool serialization
243
+ logger.info(f"Saving Flock to {file_path}")
244
+ flock.to_yaml_file(file_path, path_type=path_type)
245
+ console.print(
246
+ f"\n[green]✓[/] Flock saved to {file_path} with {path_type} paths"
247
+ )
248
+
249
+ # Provide helpful information about tool serialization
250
+ if has_tools:
251
+ console.print("\n[bold blue]Tools Information:[/]")
252
+ console.print(
253
+ "This Flock contains tools that have been serialized as callable references."
254
+ )
255
+ console.print(
256
+ "When loading this Flock on another system, ensure that:"
257
+ )
258
+ console.print(
259
+ " - The tools/functions are registered in the Flock registry"
260
+ )
261
+ console.print(
262
+ " - The containing modules are available in the Python path"
263
+ )
219
264
  except Exception as e:
265
+ logger.error(f"Error saving Flock: {e}", exc_info=True)
220
266
  console.print(f"\n[bold red]Error saving Flock:[/] {e!s}")
267
+
268
+ # Provide guidance on potential issues with tool serialization
269
+ if "callable" in str(e).lower() or "registry" in str(e).lower():
270
+ console.print(
271
+ "\n[yellow]This error might be related to tool serialization.[/]"
272
+ )
273
+ console.print(
274
+ "[yellow]Check if all tools are properly registered in the Flock registry.[/]"
275
+ )
flock/cli/load_flock.py CHANGED
@@ -8,6 +8,9 @@ from rich.markdown import Markdown
8
8
 
9
9
  from flock.cli.loaded_flock_cli import start_loaded_flock_cli
10
10
  from flock.core.flock import Flock
11
+ from flock.core.logging.logging import get_logger
12
+
13
+ logger = get_logger("cli.load_flock")
11
14
 
12
15
 
13
16
  def filter(file_path) -> bool:
@@ -40,7 +43,42 @@ def load_flock():
40
43
  console.print(f"Selected file: {selected_file}", style="bold green")
41
44
 
42
45
  try:
43
- flock = Flock.load_from_file(result)
46
+ # Try loading with detailed error handling
47
+ try:
48
+ logger.info(f"Attempting to load Flock from: {result}")
49
+ flock = Flock.load_from_file(result)
50
+ except ImportError as e:
51
+ # Handle missing module path errors
52
+ if "No module named" in str(e):
53
+ console.print(
54
+ f"[yellow]Warning: Module import failed: {e}[/]"
55
+ )
56
+ console.print(
57
+ "[yellow]Trying file path fallback mechanism...[/]"
58
+ )
59
+ # Re-try loading with fallback
60
+ flock = Flock.load_from_file(result)
61
+ else:
62
+ raise # Re-raise if it's not a missing module error
63
+ except KeyError as e:
64
+ # This could be caused by missing tool references
65
+ if "__callable_ref__" in str(e):
66
+ console.print(
67
+ f"[yellow]Warning: Tool reference error: {e}[/]"
68
+ )
69
+ console.print(
70
+ "[yellow]This may be due to missing tool registrations. Attempting to scan for tools...[/]"
71
+ )
72
+ # Scan for tools and retry
73
+ from flock.cli.registry_management import (
74
+ auto_registration_scanner,
75
+ )
76
+
77
+ auto_registration_scanner()
78
+ # Try loading again
79
+ flock = Flock.load_from_file(result)
80
+ else:
81
+ raise # Re-raise if it's not a tool reference error
44
82
 
45
83
  console.line()
46
84
  console.print(
@@ -55,4 +93,100 @@ def load_flock():
55
93
 
56
94
  except Exception as e:
57
95
  console.print(f"Error loading Flock: {e!s}", style="bold red")
96
+ logger.error(f"Failed to load Flock: {e}", exc_info=True)
97
+
98
+ # Add more detailed error information for specific errors
99
+ if "No module named" in str(e):
100
+ console.print(
101
+ "\n[yellow]This error might be due to missing module paths.[/]"
102
+ )
103
+ console.print(
104
+ "[yellow]Component references may need to be updated with file paths.[/]"
105
+ )
106
+
107
+ # Show the option to scan the directory for components
108
+ fix_paths = questionary.confirm(
109
+ "Would you like to scan directories for components to fix missing imports?",
110
+ default=True,
111
+ ).ask()
112
+
113
+ if fix_paths:
114
+ from flock.cli.registry_management import (
115
+ auto_registration_scanner,
116
+ )
117
+
118
+ auto_registration_scanner()
119
+
120
+ # Try loading again
121
+ console.print(
122
+ "\n[yellow]Attempting to load Flock again...[/]"
123
+ )
124
+ try:
125
+ flock = Flock.load_from_file(result)
126
+ console.line()
127
+ console.print(
128
+ Markdown(
129
+ "# Flock loaded successfully after component scan"
130
+ ),
131
+ style="bold green",
132
+ )
133
+ console.line()
134
+
135
+ start_loaded_flock_cli(
136
+ flock, server_name=f"Flock - {selected_file.name}"
137
+ )
138
+ return
139
+ except Exception as e2:
140
+ console.print(
141
+ f"Error loading Flock after scan: {e2!s}",
142
+ style="bold red",
143
+ )
144
+
145
+ # Handle tool reference issues
146
+ elif "__callable_ref__" in str(e) or "callable" in str(e).lower():
147
+ console.print(
148
+ "\n[yellow]This error might be due to missing tool registrations.[/]"
149
+ )
150
+
151
+ # Show the option to scan the directory for tools
152
+ fix_tools = questionary.confirm(
153
+ "Would you like to scan directories for tools to fix missing references?",
154
+ default=True,
155
+ ).ask()
156
+
157
+ if fix_tools:
158
+ from flock.cli.registry_management import (
159
+ auto_registration_scanner,
160
+ )
161
+
162
+ console.print(
163
+ "\n[yellow]Scanning for tools and callables...[/]"
164
+ )
165
+ auto_registration_scanner()
166
+
167
+ # Try loading again
168
+ console.print(
169
+ "\n[yellow]Attempting to load Flock again...[/]"
170
+ )
171
+ try:
172
+ flock = Flock.load_from_file(result)
173
+ console.line()
174
+ console.print(
175
+ Markdown(
176
+ "# Flock loaded successfully after tool scan"
177
+ ),
178
+ style="bold green",
179
+ )
180
+ console.line()
181
+
182
+ start_loaded_flock_cli(
183
+ flock, server_name=f"Flock - {selected_file.name}"
184
+ )
185
+ return
186
+ except Exception as e2:
187
+ console.print(
188
+ f"Error loading Flock after tool scan: {e2!s}",
189
+ style="bold red",
190
+ )
191
+
58
192
  input("\nPress Enter to continue...")