-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow.py
More file actions
163 lines (131 loc) · 6.3 KB
/
flow.py
File metadata and controls
163 lines (131 loc) · 6.3 KB
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
"""
Flow Orchestration
Wires all PocketFlow nodes into a Directed Acyclic Graph (DAG)
with conditional transitions and self-correction loops.
"""
from pocketflow import Flow
from nodes.scout import ScoutNode
from nodes.surveyor import SurveyorNode
from nodes.uploader import UploaderNode
from nodes.summarizer import SummarizerNode
from nodes.architect import ArchitectNode
from nodes.human_handshake import HumanHandshakeNode
from nodes.drafter import DrafterNode
from nodes.critic import CriticNode
def create_diagram_generation_flow() -> Flow:
"""Create the main diagram generation flow.
Flow Structure:
┌─────────┐ ┌──────────┐ ┌──────────┐ ┌───────────┐
│ Scout │───▶│ Surveyor │───▶│ Uploader │───▶│ Architect │
└─────────┘ └──────────┘ └──────────┘ └───────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Human Handshake │
│ (Interactive Selection) │
└─────────────────────────────────────────────────────────────┘
│
▼ (default)
┌─────────────────────────────────────────────────────────────┐
│ Diagram Generation Loop │
│ ┌─────────┐ validate ┌────────┐ retry ┌─────────┐ │
│ │ Drafter │──────────▶│ Critic │─────────▶│ Drafter │ │
│ └─────────┘ └────────┘ └─────────┘ │
│ ▲ │ next │
│ │ │ │
│ └──────────────────────┼──────────────────────────────│
│ ▼ │
│ Next Diagram │
└─────────────────────────────────────────────────────────────┘
Returns:
Configured PocketFlow Flow.
"""
# Create node instances
scout = ScoutNode()
surveyor = SurveyorNode()
uploader = UploaderNode()
summarizer = SummarizerNode()
architect = ArchitectNode()
handshake = HumanHandshakeNode()
drafter = DrafterNode()
critic = CriticNode()
# Wire the main pipeline
# Scout -> Surveyor -> Uploader -> Summarizer -> Architect -> Handshake
scout >> surveyor >> uploader >> summarizer >> architect >> handshake
# Handshake -> Drafter (on "default" action, user selected diagrams)
handshake.next(drafter, "default")
# Handshake -> End (on "quit" action, user cancelled)
# (No successor means flow ends)
# Drafter -> Critic (on "validate" action)
drafter.next(critic, "validate")
# Drafter -> End (on "complete" action, all diagrams done)
# (No successor means flow ends)
# Self-correction loop:
# Critic -> Drafter (on "retry" action, diagram failed validation)
critic.next(drafter, "retry")
# Critic -> Drafter (on "next" action, move to next diagram)
critic.next(drafter, "next")
# Create the flow starting from Scout
flow = Flow(start=scout)
return flow
def run_flow(repo_url: str, output_dir: str = "generated_diagrams") -> dict:
"""Run the complete diagram generation flow.
Args:
repo_url: GitHub repository URL to analyze.
output_dir: Directory to save generated diagrams.
Returns:
Dict with results including generated diagram paths.
"""
# Create the flow
flow = create_diagram_generation_flow()
# Initialize shared store
import os
project_root = os.path.dirname(os.path.abspath(__file__))
shared = {
"repo_url": repo_url,
"output_dir": output_dir,
"project_root": project_root,
}
print("\n" + "="*60)
print("🎨 BLACK-BOOK DIAGRAM GENERATOR")
print("="*60)
print(f"Repository: {repo_url}")
print(f"Output: {output_dir}/")
print("="*60 + "\n")
try:
# Run the flow
flow.run(shared)
# Collect results
generated = shared.get("generated_diagrams", [])
print("\n" + "="*60)
print("📊 GENERATION COMPLETE")
print("="*60)
if generated:
print(f"\n✓ Generated {len(generated)} diagram(s):\n")
for diag in generated:
print(f" • {diag['name']}")
print(f" PNG: {diag['png_path']}")
print(f" Source: {diag['puml_path']}")
print()
else:
print("\n⚠ No diagrams were generated.")
# Cleanup temp files
scout_node = ScoutNode()
scout_node.cleanup(shared)
return {
"success": True,
"diagrams": generated,
"output_dir": output_dir,
}
except Exception as e:
print(f"\n✗ Error during flow execution: {e}")
# Attempt cleanup
try:
scout_node = ScoutNode()
scout_node.cleanup(shared)
except:
pass
return {
"success": False,
"error": str(e),
}