Commit 141119e
feat(workflows): add JSON output for workflow run resume and status (#2814)
* feat(workflows): add --json output to workflow run, resume, and status
Adds an opt-in `--json` flag to `workflow run`, `workflow resume`, and
`workflow status` that emits a single machine-readable object (run_id,
workflow_id, status, current step; status also reports per-step states
and a runs list) for automation and external orchestrators.
JSON is written via a small `_emit_workflow_json` helper using plain
stdout, so Rich markup, highlighting, and line-wrapping can never alter
the emitted object. Default human-readable output and exit codes are
unchanged when `--json` is omitted. Reference docs updated.
Closes #2811.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(workflows): keep --json stdout clean while steps write output
Suppressing the banner and the step-start callback was not enough to
guarantee a single parseable JSON object on stdout: individual steps still
write there while the engine runs. The gate step prints its prompt, and the
prompt step runs a CLI subprocess that inherits the process's stdout file
descriptor — either can corrupt the JSON stream for interactive runs or
integration-backed workflows.
Wrap engine.execute()/engine.resume() in a file-descriptor-level redirect
(dup2) when --json is set, so both Python-level writes and inherited-fd
subprocess output go to stderr while stdout carries only the emitted JSON.
Step progress stays visible on stderr. status does not run the engine, so
it is unaffected.
Tests cover both pollution channels (a Python print and a real subprocess)
via fd-level capture, and the inactive no-op path. Docs note the
stdout/stderr split.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* docs(workflows): fix stray escape sequence in --json redirect comments
The redirect helper's docstring and its test comment wrote ``print``\s,
which renders as "print\s" rather than "prints". Replace with plain
"prints".
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent e094cbd commit 141119e
3 files changed
Lines changed: 293 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
23 | 42 | | |
24 | 43 | | |
25 | 44 | | |
| |||
31 | 50 | | |
32 | 51 | | |
33 | 52 | | |
| 53 | + | |
34 | 54 | | |
35 | 55 | | |
36 | 56 | | |
| |||
46 | 66 | | |
47 | 67 | | |
48 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
49 | 73 | | |
50 | 74 | | |
51 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
2693 | 2694 | | |
2694 | 2695 | | |
2695 | 2696 | | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
2696 | 2748 | | |
2697 | 2749 | | |
2698 | 2750 | | |
2699 | 2751 | | |
2700 | 2752 | | |
2701 | 2753 | | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
2702 | 2759 | | |
2703 | 2760 | | |
2704 | 2761 | | |
| |||
2721 | 2778 | | |
2722 | 2779 | | |
2723 | 2780 | | |
2724 | | - | |
| 2781 | + | |
| 2782 | + | |
2725 | 2783 | | |
2726 | 2784 | | |
2727 | 2785 | | |
| |||
2743 | 2801 | | |
2744 | 2802 | | |
2745 | 2803 | | |
2746 | | - | |
2747 | | - | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
2748 | 2807 | | |
2749 | 2808 | | |
2750 | | - | |
| 2809 | + | |
| 2810 | + | |
2751 | 2811 | | |
2752 | 2812 | | |
2753 | 2813 | | |
2754 | 2814 | | |
2755 | 2815 | | |
2756 | 2816 | | |
2757 | 2817 | | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
2758 | 2822 | | |
2759 | 2823 | | |
2760 | 2824 | | |
| |||
2775 | 2839 | | |
2776 | 2840 | | |
2777 | 2841 | | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
2778 | 2847 | | |
2779 | 2848 | | |
2780 | 2849 | | |
2781 | 2850 | | |
2782 | 2851 | | |
2783 | 2852 | | |
2784 | | - | |
| 2853 | + | |
| 2854 | + | |
2785 | 2855 | | |
2786 | 2856 | | |
2787 | 2857 | | |
2788 | 2858 | | |
2789 | | - | |
| 2859 | + | |
| 2860 | + | |
2790 | 2861 | | |
2791 | 2862 | | |
2792 | 2863 | | |
| |||
2797 | 2868 | | |
2798 | 2869 | | |
2799 | 2870 | | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
2800 | 2875 | | |
2801 | 2876 | | |
2802 | 2877 | | |
| |||
2810 | 2885 | | |
2811 | 2886 | | |
2812 | 2887 | | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
2813 | 2893 | | |
2814 | 2894 | | |
2815 | 2895 | | |
| |||
2825 | 2905 | | |
2826 | 2906 | | |
2827 | 2907 | | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
| 2915 | + | |
| 2916 | + | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
| 2921 | + | |
| 2922 | + | |
2828 | 2923 | | |
2829 | 2924 | | |
2830 | 2925 | | |
| |||
2852 | 2947 | | |
2853 | 2948 | | |
2854 | 2949 | | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
2855 | 2966 | | |
2856 | 2967 | | |
2857 | 2968 | | |
| |||
0 commit comments