You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Alongside agents and workflows, there should be a third category of executable elements: Scripts. These can be inserted between agents and sub-workflows in any slot (Preparation, Loop, Finalization) and serve as programmable hooks at runtime.
Unlike the existing init_script (which runs only before the opencode subprocess), these scripts run inside the workflow orchestrator and have direct access to WorkflowState.
Use Cases
Scenario
Script
Prepare state
A Python script sets payload["files"] = get_changed_files() before the agent runs
Manipulate prompt
A script appends additional instructions to the prompt based on payload["language"]
Parse output
After an agent run, the output is validated and transformed into structured state fields
Conditional logic
If payload["coverage"] < 50, set payload["strict_mode"] = True
File operations
Copy test results, delete temp files, write logs
Possible Variants
Two types are conceivable, depending on position in the slot:
Pre-Hook (before the agent/sub-workflow) – transforms state or prompt before execution
Post-Hook (after the agent/sub-workflow) – processes results, validates, enriches state
Whether the distinction is made by slot position (script before agent = Pre, after = Post) or by the script definition itself is still open.
Sub-Issues (ToDo)
Configuration System (core/config.py) #1 Script Loader – New class core/script_loader.py analogous to AgentLoader: scans a directory (e.g. scripts/) for supported script types (.py, .ps1, .sh), validates and loads them.
Core State Management (core/state.py, core/parser.py) #2 Script Runner in Engine – _execute_script(name) in core/engine.py that runs a script with read/write access to WorkflowState. Recursion guard, timeout, error handling.
Agent Definition Loader (core/agent.py) #3 Integration into Slot Resolution – _resolve_slot_entry() recognizes script:name and calls the script runner. A script can be positioned anywhere in a slot (before/after agents or sub-workflows).
Subprocess Runner (core/runner.py) #4 GUI: Script Pool – Third pool listbox for scripts in ui/app.py, script preview (display source code), transfer buttons.
Execution Engine (core/engine.py) #5 Define Script API – Define the interface: How does a script receive state? How does it return changes? Examples:
Description
Alongside agents and workflows, there should be a third category of executable elements: Scripts. These can be inserted between agents and sub-workflows in any slot (Preparation, Loop, Finalization) and serve as programmable hooks at runtime.
Unlike the existing
init_script(which runs only before the opencode subprocess), these scripts run inside the workflow orchestrator and have direct access toWorkflowState.Use Cases
payload["files"] = get_changed_files()before the agent runspayload["language"]payload["coverage"] < 50, setpayload["strict_mode"] = TruePossible Variants
Two types are conceivable, depending on position in the slot:
Whether the distinction is made by slot position (script before agent = Pre, after = Post) or by the script definition itself is still open.
Sub-Issues (ToDo)
core/script_loader.pyanalogous toAgentLoader: scans a directory (e.g.scripts/) for supported script types (.py,.ps1,.sh), validates and loads them._execute_script(name)incore/engine.pythat runs a script with read/write access toWorkflowState. Recursion guard, timeout, error handling._resolve_slot_entry()recognizesscript:nameand calls the script runner. A script can be positioned anywhere in a slot (before/after agents or sub-workflows).ui/app.py, script preview (display source code), transfer buttons.tests/integration.py.Open Questions
run(state) -> state(Python function) or arbitrary executable with JSON via stdin/stdout?scripts/analogous toagents/andworkflows/, or undercore/scripts/?Distinction from Existing Features
init_scriptpreparation_agents