1- """workflow exec command - Execution instance management."""
1+ """workflow exec command - Execution instance management for progressive reading.
2+
3+ Design:
4+ - read: Read current step content (mark as read)
5+ - next: Advance to next step (must read first)
6+
7+ Progressive reading ensures Agent cannot skip steps without reading.
8+ """
29
310from pathlib import Path
411
@@ -17,17 +24,22 @@ def print_output(type: OutputType, message: str):
1724 console .print (f"[{ type .value } ] { message } " )
1825
1926
20- app = typer .Typer (help = "Execution instance management" )
27+ app = typer .Typer (help = "Execution instance management (progressive reading) " )
2128
2229
23- @app .command ("show " )
24- def exec_show (
30+ @app .command ("read " )
31+ def exec_read (
2532 execution_id : str = typer .Argument (..., help = "Execution instance ID" ),
2633):
27- """Show execution instance details.
34+ """Read current step content and mark as read.
35+
36+ Agent reads the current step, understands it, then executes operations
37+ using its own tools (git, file operations, API calls, etc.).
38+
39+ After reading and executing, call 'workflow exec next' to advance.
2840
2941 Example:
30- workflow exec show commit-abc123
42+ workflow exec read commit-abc123
3143 """
3244 ensure_directories ()
3345 executor = Executor ()
@@ -40,28 +52,54 @@ def exec_show(
4052 )
4153 raise typer .Exit (4 )
4254
43- console .print (f"Execution: { execution .execution_id } " )
44- console .print (f" Workflow: { execution .workflow_name } " )
45- console .print (f" Status: { execution .status .value } " )
46- console .print (f" Step: { execution .current_step } /{ execution .steps_total } " )
47- console .print (f" Outputs: { execution .outputs_path } " )
55+ # Load workflow and parse
56+ workflow = executor .get_workflow (execution .workflow_name )
57+ if not workflow :
58+ print_output (OutputType .ERROR , f"Workflow not found: { execution .workflow_name } " )
59+ raise typer .Exit (4 )
60+
61+ content = Path (workflow .file_path ).read_text ()
62+ parser = WorkflowParser (content )
63+ parser .parse ()
64+
65+ # Get current step
66+ current_step = executor .get_next_step (execution , parser )
67+ if current_step is None :
68+ print_output (OutputType .SUCCESS , f"Execution completed: { execution_id } " )
69+ console .print (f" All { execution .steps_total } steps completed" )
70+ return
71+
72+ # Display current step content
73+ console .print (f"[INFO] Step { execution .current_step + 1 } /{ execution .steps_total } :" )
74+ console .print (f" { current_step ['content' ]} " )
75+ if current_step .get ("metadata" ):
76+ console .print (f" Comments ({ len (current_step ['metadata' ])} ):" )
77+ for comment in current_step ["metadata" ]:
78+ console .print (f" { comment } " )
79+
80+ # Mark as read (if not already)
81+ if execution .current_step not in execution .steps_read :
82+ execution .steps_read .append (execution .current_step )
83+ executor .update_execution (execution )
84+ console .print (f"\n [INFO] Step { execution .current_step + 1 } marked as read" )
4885
4986
5087@app .command ("next" )
5188def exec_next (
5289 execution_id : str = typer .Argument (..., help = "Execution instance ID" ),
53- output : str = typer .Option (None , "-o" , "--output" , help = "Step output to store" ),
54- quiet : bool = typer .Option (False , "-q" , "--quiet" , help = "Quiet mode (no output)" ),
5590):
56- """Mark current step complete and advance to next step.
91+ """Advance to next step (must read current step first) .
5792
58- Shows current step content, stores output (if provided), advances execution,
59- and displays next step content.
93+ Checks if current step has been read (progressive reading enforcement).
94+ If read, advances to next step. If not read, shows error.
95+
96+ Agent should:
97+ 1. workflow exec read <id> (read and understand)
98+ 2. Execute operations (using own tools)
99+ 3. workflow exec next <id> (advance when ready)
60100
61101 Example:
62102 workflow exec next commit-abc123
63- workflow exec next commit-abc123 -o "result"
64- workflow exec next commit-abc123 -q # Quiet mode for scripts
65103 """
66104 ensure_directories ()
67105 executor = Executor ()
@@ -71,7 +109,19 @@ def exec_next(
71109 print_output (OutputType .ERROR , f"Execution not found: { execution_id } " )
72110 raise typer .Exit (4 )
73111
74- # Load workflow and parse
112+ # Check if current step has been read
113+ if execution .current_step not in execution .steps_read :
114+ print_output (OutputType .ERROR , "Current step not read yet" )
115+ print_output (
116+ OutputType .NEXT ,
117+ f"Read first: workflow exec read { execution_id } " ,
118+ )
119+ raise typer .Exit (1 )
120+
121+ # Advance execution
122+ executor .advance_execution (execution )
123+
124+ # Check if completed
75125 workflow = executor .get_workflow (execution .workflow_name )
76126 if not workflow :
77127 print_output (OutputType .ERROR , f"Workflow not found: { execution .workflow_name } " )
@@ -81,40 +131,15 @@ def exec_next(
81131 parser = WorkflowParser (content )
82132 parser .parse ()
83133
84- # Get current step BEFORE advancing
85- current_step = executor .get_next_step (execution , parser )
86-
87- # Show current step (unless quiet mode)
88- if not quiet and current_step :
89- console .print (
90- f"[INFO] Current step { execution .current_step + 1 } /{ execution .steps_total } :"
91- )
92- console .print (f" { current_step ['content' ]} " )
93- if current_step .get ("metadata" ):
94- for comment in current_step ["metadata" ][:3 ]:
95- console .print (f" { comment } " )
96-
97- # Store output if provided
98- if output :
99- executor .store_output (execution_id , execution .current_step , output )
100-
101- # Advance execution
102- executor .advance_execution (execution )
103-
104- # Get next step AFTER advancing
105134 next_step = executor .get_next_step (execution , parser )
106135 if next_step is None :
107136 print_output (OutputType .SUCCESS , f"Execution completed: { execution_id } " )
108- console .print (f" Final step: { execution . steps_total } / { execution .steps_total } " )
137+ console .print (f" Total steps: { execution .steps_total } " )
109138 return
110139
111- # Show next step (unless quiet mode)
112- if not quiet :
113- print_output (
114- OutputType .SUCCESS ,
115- f"Advanced to step { execution .current_step } /{ execution .steps_total } " ,
116- )
117- console .print (f" Next step: { next_step ['content' ]} " )
118- if next_step .get ("metadata" ):
119- for comment in next_step ["metadata" ][:3 ]:
120- console .print (f" { comment } " )
140+ # Show progress (not content - Agent reads with 'read' command)
141+ print_output (
142+ OutputType .SUCCESS ,
143+ f"Advanced to step { execution .current_step + 1 } /{ execution .steps_total } " ,
144+ )
145+ console .print (f" Read next: workflow exec read { execution_id } " )
0 commit comments