diff --git a/.ui-review-109-3/pill_0.png b/.ui-review-109-3/pill_0.png new file mode 100644 index 00000000..baf9708a Binary files /dev/null and b/.ui-review-109-3/pill_0.png differ diff --git a/.ui-review-109-3/pill_1.png b/.ui-review-109-3/pill_1.png new file mode 100644 index 00000000..edaf0aab Binary files /dev/null and b/.ui-review-109-3/pill_1.png differ diff --git a/.ui-review-109-3/pill_2.png b/.ui-review-109-3/pill_2.png new file mode 100644 index 00000000..4eefc006 Binary files /dev/null and b/.ui-review-109-3/pill_2.png differ diff --git a/.ui-review-109-3/pill_3.png b/.ui-review-109-3/pill_3.png new file mode 100644 index 00000000..66c7ff59 Binary files /dev/null and b/.ui-review-109-3/pill_3.png differ diff --git a/.ui-review-109-3/pill_4.png b/.ui-review-109-3/pill_4.png new file mode 100644 index 00000000..50179c91 Binary files /dev/null and b/.ui-review-109-3/pill_4.png differ diff --git a/.ui-review-109-3/pill_5.png b/.ui-review-109-3/pill_5.png new file mode 100644 index 00000000..fa5252ea Binary files /dev/null and b/.ui-review-109-3/pill_5.png differ diff --git a/.ui-review-109-3/sec2_collapse_0.png b/.ui-review-109-3/sec2_collapse_0.png new file mode 100644 index 00000000..80274036 Binary files /dev/null and b/.ui-review-109-3/sec2_collapse_0.png differ diff --git a/.ui-review-109-3/sec2_collapse_2.png b/.ui-review-109-3/sec2_collapse_2.png new file mode 100644 index 00000000..bb0baded Binary files /dev/null and b/.ui-review-109-3/sec2_collapse_2.png differ diff --git a/.ui-review-109-3/sec2_expand_0.png b/.ui-review-109-3/sec2_expand_0.png new file mode 100644 index 00000000..91cf5543 Binary files /dev/null and b/.ui-review-109-3/sec2_expand_0.png differ diff --git a/.ui-review-109-3/sec2_expand_3.png b/.ui-review-109-3/sec2_expand_3.png new file mode 100644 index 00000000..d4b75ad5 Binary files /dev/null and b/.ui-review-109-3/sec2_expand_3.png differ diff --git a/.ui-review-109-3/status3_post_01.png b/.ui-review-109-3/status3_post_01.png new file mode 100644 index 00000000..a0f723f2 Binary files /dev/null and b/.ui-review-109-3/status3_post_01.png differ diff --git a/.ui-review-109-3/status3_post_02.png b/.ui-review-109-3/status3_post_02.png new file mode 100644 index 00000000..29dd1d9c Binary files /dev/null and b/.ui-review-109-3/status3_post_02.png differ diff --git a/.ui-review-109-3/status3_post_03.png b/.ui-review-109-3/status3_post_03.png new file mode 100644 index 00000000..7a582306 Binary files /dev/null and b/.ui-review-109-3/status3_post_03.png differ diff --git a/.ui-review-109-3/status3_post_04.png b/.ui-review-109-3/status3_post_04.png new file mode 100644 index 00000000..7a582306 Binary files /dev/null and b/.ui-review-109-3/status3_post_04.png differ diff --git a/.ui-review-116-3/crop-geom-A-pipelines-after.png b/.ui-review-116-3/crop-geom-A-pipelines-after.png new file mode 100644 index 00000000..57eee534 Binary files /dev/null and b/.ui-review-116-3/crop-geom-A-pipelines-after.png differ diff --git a/.ui-review-116-3/crop-geom-A-pipelines-before.png b/.ui-review-116-3/crop-geom-A-pipelines-before.png new file mode 100644 index 00000000..2b0a9e86 Binary files /dev/null and b/.ui-review-116-3/crop-geom-A-pipelines-before.png differ diff --git a/.ui-review-116-3/crop-geom-B-detail-after.png b/.ui-review-116-3/crop-geom-B-detail-after.png new file mode 100644 index 00000000..57eee534 Binary files /dev/null and b/.ui-review-116-3/crop-geom-B-detail-after.png differ diff --git a/.ui-review-116-3/crop-geom-B-detail-before.png b/.ui-review-116-3/crop-geom-B-detail-before.png new file mode 100644 index 00000000..2b0a9e86 Binary files /dev/null and b/.ui-review-116-3/crop-geom-B-detail-before.png differ diff --git a/.ui-review-116-3/geom-A-pipelines-after.png b/.ui-review-116-3/geom-A-pipelines-after.png new file mode 100644 index 00000000..c2bccab9 Binary files /dev/null and b/.ui-review-116-3/geom-A-pipelines-after.png differ diff --git a/.ui-review-116-3/geom-A-pipelines-before.png b/.ui-review-116-3/geom-A-pipelines-before.png new file mode 100644 index 00000000..02424a1a Binary files /dev/null and b/.ui-review-116-3/geom-A-pipelines-before.png differ diff --git a/.ui-review-116-3/geom-B-detail-after.png b/.ui-review-116-3/geom-B-detail-after.png new file mode 100644 index 00000000..db0e2f7d Binary files /dev/null and b/.ui-review-116-3/geom-B-detail-after.png differ diff --git a/.ui-review-116-3/geom-B-detail-before.png b/.ui-review-116-3/geom-B-detail-before.png new file mode 100644 index 00000000..f4c4b4de Binary files /dev/null and b/.ui-review-116-3/geom-B-detail-before.png differ diff --git a/.ui-review-164-6/01-pill-runs-selected.png b/.ui-review-164-6/01-pill-runs-selected.png new file mode 100644 index 00000000..02e5cc52 Binary files /dev/null and b/.ui-review-164-6/01-pill-runs-selected.png differ diff --git a/.ui-review-164-6/01-pill-start.png b/.ui-review-164-6/01-pill-start.png new file mode 100644 index 00000000..fd6d9625 Binary files /dev/null and b/.ui-review-164-6/01-pill-start.png differ diff --git a/.ui-review-164-6/01-start.png b/.ui-review-164-6/01-start.png new file mode 100644 index 00000000..528bd043 Binary files /dev/null and b/.ui-review-164-6/01-start.png differ diff --git a/.ui-review-164-6/01-start.xml b/.ui-review-164-6/01-start.xml new file mode 100644 index 00000000..c6fe77df --- /dev/null +++ b/.ui-review-164-6/01-start.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/02-field-open.png b/.ui-review-164-6/02-field-open.png new file mode 100644 index 00000000..4f61f4cb Binary files /dev/null and b/.ui-review-164-6/02-field-open.png differ diff --git a/.ui-review-164-6/02-field-open.xml b/.ui-review-164-6/02-field-open.xml new file mode 100644 index 00000000..e77620c7 --- /dev/null +++ b/.ui-review-164-6/02-field-open.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/02-lock.png b/.ui-review-164-6/02-lock.png new file mode 100644 index 00000000..26d8751f Binary files /dev/null and b/.ui-review-164-6/02-lock.png differ diff --git a/.ui-review-164-6/02d-morph-field-above-keyboard.png b/.ui-review-164-6/02d-morph-field-above-keyboard.png new file mode 100644 index 00000000..df47b272 Binary files /dev/null and b/.ui-review-164-6/02d-morph-field-above-keyboard.png differ diff --git a/.ui-review-164-6/03-dismissed-back.png b/.ui-review-164-6/03-dismissed-back.png new file mode 100644 index 00000000..7fcc8191 Binary files /dev/null and b/.ui-review-164-6/03-dismissed-back.png differ diff --git a/.ui-review-164-6/03-field-open-keyboard.png b/.ui-review-164-6/03-field-open-keyboard.png new file mode 100644 index 00000000..34d35fbf Binary files /dev/null and b/.ui-review-164-6/03-field-open-keyboard.png differ diff --git a/.ui-review-164-6/03-lock2.png b/.ui-review-164-6/03-lock2.png new file mode 100644 index 00000000..a9ed18e5 Binary files /dev/null and b/.ui-review-164-6/03-lock2.png differ diff --git a/.ui-review-164-6/04-dismissed-back-pill.png b/.ui-review-164-6/04-dismissed-back-pill.png new file mode 100644 index 00000000..7caca3dd Binary files /dev/null and b/.ui-review-164-6/04-dismissed-back-pill.png differ diff --git a/.ui-review-164-6/04-dismissed.xml b/.ui-review-164-6/04-dismissed.xml new file mode 100644 index 00000000..96101c66 --- /dev/null +++ b/.ui-review-164-6/04-dismissed.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/10-list-search-ime.png b/.ui-review-164-6/10-list-search-ime.png new file mode 100644 index 00000000..0ab43ec7 Binary files /dev/null and b/.ui-review-164-6/10-list-search-ime.png differ diff --git a/.ui-review-164-6/AFTER-00-pill.png b/.ui-review-164-6/AFTER-00-pill.png new file mode 100644 index 00000000..d1dc2523 Binary files /dev/null and b/.ui-review-164-6/AFTER-00-pill.png differ diff --git a/.ui-review-164-6/AFTER-field-open.xml b/.ui-review-164-6/AFTER-field-open.xml new file mode 100644 index 00000000..e77620c7 --- /dev/null +++ b/.ui-review-164-6/AFTER-field-open.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/AFTER-tap-0.6.png b/.ui-review-164-6/AFTER-tap-0.6.png new file mode 100644 index 00000000..56db3f9d Binary files /dev/null and b/.ui-review-164-6/AFTER-tap-0.6.png differ diff --git a/.ui-review-164-6/AFTER-tap-1.2.png b/.ui-review-164-6/AFTER-tap-1.2.png new file mode 100644 index 00000000..56db3f9d Binary files /dev/null and b/.ui-review-164-6/AFTER-tap-1.2.png differ diff --git a/.ui-review-164-6/AFTER-tap-2.0.png b/.ui-review-164-6/AFTER-tap-2.0.png new file mode 100644 index 00000000..697d2249 Binary files /dev/null and b/.ui-review-164-6/AFTER-tap-2.0.png differ diff --git a/.ui-review-164-6/AFTER-tap-3.0.png b/.ui-review-164-6/AFTER-tap-3.0.png new file mode 100644 index 00000000..56db3f9d Binary files /dev/null and b/.ui-review-164-6/AFTER-tap-3.0.png differ diff --git a/.ui-review-164-6/BEFORE-field-open.png b/.ui-review-164-6/BEFORE-field-open.png new file mode 100644 index 00000000..0d2907ad Binary files /dev/null and b/.ui-review-164-6/BEFORE-field-open.png differ diff --git a/.ui-review-164-6/BEFORE-field-open.xml b/.ui-review-164-6/BEFORE-field-open.xml new file mode 100644 index 00000000..857ea566 --- /dev/null +++ b/.ui-review-164-6/BEFORE-field-open.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/BEFORE-morph-end.xml b/.ui-review-164-6/BEFORE-morph-end.xml new file mode 100644 index 00000000..24e73f1f --- /dev/null +++ b/.ui-review-164-6/BEFORE-morph-end.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/BEFORE-morph.mp4 b/.ui-review-164-6/BEFORE-morph.mp4 new file mode 100644 index 00000000..2ac653bf Binary files /dev/null and b/.ui-review-164-6/BEFORE-morph.mp4 differ diff --git a/.ui-review-164-6/BEFORE2.png b/.ui-review-164-6/BEFORE2.png new file mode 100644 index 00000000..1e9fc756 Binary files /dev/null and b/.ui-review-164-6/BEFORE2.png differ diff --git a/.ui-review-164-6/BEFORE2.xml b/.ui-review-164-6/BEFORE2.xml new file mode 100644 index 00000000..089660a6 --- /dev/null +++ b/.ui-review-164-6/BEFORE2.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/C1-pill-start.png b/.ui-review-164-6/C1-pill-start.png new file mode 100644 index 00000000..d8cf02a7 Binary files /dev/null and b/.ui-review-164-6/C1-pill-start.png differ diff --git a/.ui-review-164-6/C1-state.xml b/.ui-review-164-6/C1-state.xml new file mode 100644 index 00000000..35babc4b --- /dev/null +++ b/.ui-review-164-6/C1-state.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/C2-field-open.png b/.ui-review-164-6/C2-field-open.png new file mode 100644 index 00000000..3668b7f0 Binary files /dev/null and b/.ui-review-164-6/C2-field-open.png differ diff --git a/.ui-review-164-6/C2-morph.mp4 b/.ui-review-164-6/C2-morph.mp4 new file mode 100644 index 00000000..4ca6574a Binary files /dev/null and b/.ui-review-164-6/C2-morph.mp4 differ diff --git a/.ui-review-164-6/C2-state.xml b/.ui-review-164-6/C2-state.xml new file mode 100644 index 00000000..b7085878 --- /dev/null +++ b/.ui-review-164-6/C2-state.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/C3-back1.png b/.ui-review-164-6/C3-back1.png new file mode 100644 index 00000000..b597ec86 Binary files /dev/null and b/.ui-review-164-6/C3-back1.png differ diff --git a/.ui-review-164-6/C3-back1.xml b/.ui-review-164-6/C3-back1.xml new file mode 100644 index 00000000..68c6fee8 --- /dev/null +++ b/.ui-review-164-6/C3-back1.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/C3-back2.xml b/.ui-review-164-6/C3-back2.xml new file mode 100644 index 00000000..35babc4b --- /dev/null +++ b/.ui-review-164-6/C3-back2.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/C3-dismissed-pill.png b/.ui-review-164-6/C3-dismissed-pill.png new file mode 100644 index 00000000..f1a5212a Binary files /dev/null and b/.ui-review-164-6/C3-dismissed-pill.png differ diff --git a/.ui-review-164-6/C4-query-dock.png b/.ui-review-164-6/C4-query-dock.png new file mode 100644 index 00000000..cce2616b Binary files /dev/null and b/.ui-review-164-6/C4-query-dock.png differ diff --git a/.ui-review-164-6/C4-query.xml b/.ui-review-164-6/C4-query.xml new file mode 100644 index 00000000..eb3dab44 --- /dev/null +++ b/.ui-review-164-6/C4-query.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/C5-list-search-ime.png b/.ui-review-164-6/C5-list-search-ime.png new file mode 100644 index 00000000..46f75e39 Binary files /dev/null and b/.ui-review-164-6/C5-list-search-ime.png differ diff --git a/.ui-review-164-6/C5-list-search.xml b/.ui-review-164-6/C5-list-search.xml new file mode 100644 index 00000000..10e6b54b --- /dev/null +++ b/.ui-review-164-6/C5-list-search.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/C6-after-scrimtap.xml b/.ui-review-164-6/C6-after-scrimtap.xml new file mode 100644 index 00000000..c6fe77df --- /dev/null +++ b/.ui-review-164-6/C6-after-scrimtap.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/C6-open-before-scrimtap.png b/.ui-review-164-6/C6-open-before-scrimtap.png new file mode 100644 index 00000000..72106f17 Binary files /dev/null and b/.ui-review-164-6/C6-open-before-scrimtap.png differ diff --git a/.ui-review-164-6/C6-open.xml b/.ui-review-164-6/C6-open.xml new file mode 100644 index 00000000..e77620c7 --- /dev/null +++ b/.ui-review-164-6/C6-open.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/C6-scrimtap-dismissed.png b/.ui-review-164-6/C6-scrimtap-dismissed.png new file mode 100644 index 00000000..9ced115d Binary files /dev/null and b/.ui-review-164-6/C6-scrimtap-dismissed.png differ diff --git a/.ui-review-164-6/frames/f_001.png b/.ui-review-164-6/frames/f_001.png new file mode 100644 index 00000000..839ca8d1 Binary files /dev/null and b/.ui-review-164-6/frames/f_001.png differ diff --git a/.ui-review-164-6/frames/f_002.png b/.ui-review-164-6/frames/f_002.png new file mode 100644 index 00000000..839ca8d1 Binary files /dev/null and b/.ui-review-164-6/frames/f_002.png differ diff --git a/.ui-review-164-6/frames/f_003.png b/.ui-review-164-6/frames/f_003.png new file mode 100644 index 00000000..839ca8d1 Binary files /dev/null and b/.ui-review-164-6/frames/f_003.png differ diff --git a/.ui-review-164-6/frames/f_004.png b/.ui-review-164-6/frames/f_004.png new file mode 100644 index 00000000..839ca8d1 Binary files /dev/null and b/.ui-review-164-6/frames/f_004.png differ diff --git a/.ui-review-164-6/frames/f_005.png b/.ui-review-164-6/frames/f_005.png new file mode 100644 index 00000000..839ca8d1 Binary files /dev/null and b/.ui-review-164-6/frames/f_005.png differ diff --git a/.ui-review-164-6/frames/f_006.png b/.ui-review-164-6/frames/f_006.png new file mode 100644 index 00000000..839ca8d1 Binary files /dev/null and b/.ui-review-164-6/frames/f_006.png differ diff --git a/.ui-review-164-6/frames/f_007.png b/.ui-review-164-6/frames/f_007.png new file mode 100644 index 00000000..839ca8d1 Binary files /dev/null and b/.ui-review-164-6/frames/f_007.png differ diff --git a/.ui-review-164-6/frames/f_008.png b/.ui-review-164-6/frames/f_008.png new file mode 100644 index 00000000..839ca8d1 Binary files /dev/null and b/.ui-review-164-6/frames/f_008.png differ diff --git a/.ui-review-164-6/frames/f_009.png b/.ui-review-164-6/frames/f_009.png new file mode 100644 index 00000000..b76f7a4d Binary files /dev/null and b/.ui-review-164-6/frames/f_009.png differ diff --git a/.ui-review-164-6/frames/f_010.png b/.ui-review-164-6/frames/f_010.png new file mode 100644 index 00000000..b76f7a4d Binary files /dev/null and b/.ui-review-164-6/frames/f_010.png differ diff --git a/.ui-review-164-6/frames/f_011.png b/.ui-review-164-6/frames/f_011.png new file mode 100644 index 00000000..b76f7a4d Binary files /dev/null and b/.ui-review-164-6/frames/f_011.png differ diff --git a/.ui-review-164-6/frames/f_012.png b/.ui-review-164-6/frames/f_012.png new file mode 100644 index 00000000..b76f7a4d Binary files /dev/null and b/.ui-review-164-6/frames/f_012.png differ diff --git a/.ui-review-164-6/frames/f_013.png b/.ui-review-164-6/frames/f_013.png new file mode 100644 index 00000000..b76f7a4d Binary files /dev/null and b/.ui-review-164-6/frames/f_013.png differ diff --git a/.ui-review-164-6/frames/f_014.png b/.ui-review-164-6/frames/f_014.png new file mode 100644 index 00000000..b76f7a4d Binary files /dev/null and b/.ui-review-164-6/frames/f_014.png differ diff --git a/.ui-review-164-6/frames/f_015.png b/.ui-review-164-6/frames/f_015.png new file mode 100644 index 00000000..b76f7a4d Binary files /dev/null and b/.ui-review-164-6/frames/f_015.png differ diff --git a/.ui-review-164-6/frames/f_016.png b/.ui-review-164-6/frames/f_016.png new file mode 100644 index 00000000..b76f7a4d Binary files /dev/null and b/.ui-review-164-6/frames/f_016.png differ diff --git a/.ui-review-164-6/frames/f_017.png b/.ui-review-164-6/frames/f_017.png new file mode 100644 index 00000000..b76f7a4d Binary files /dev/null and b/.ui-review-164-6/frames/f_017.png differ diff --git a/.ui-review-164-6/frames/f_018.png b/.ui-review-164-6/frames/f_018.png new file mode 100644 index 00000000..b76f7a4d Binary files /dev/null and b/.ui-review-164-6/frames/f_018.png differ diff --git a/.ui-review-164-6/frames/f_019.png b/.ui-review-164-6/frames/f_019.png new file mode 100644 index 00000000..706a6024 Binary files /dev/null and b/.ui-review-164-6/frames/f_019.png differ diff --git a/.ui-review-164-6/frames/f_020.png b/.ui-review-164-6/frames/f_020.png new file mode 100644 index 00000000..706a6024 Binary files /dev/null and b/.ui-review-164-6/frames/f_020.png differ diff --git a/.ui-review-164-6/frames/f_021.png b/.ui-review-164-6/frames/f_021.png new file mode 100644 index 00000000..c2c33516 Binary files /dev/null and b/.ui-review-164-6/frames/f_021.png differ diff --git a/.ui-review-164-6/frames/f_022.png b/.ui-review-164-6/frames/f_022.png new file mode 100644 index 00000000..c2c33516 Binary files /dev/null and b/.ui-review-164-6/frames/f_022.png differ diff --git a/.ui-review-164-6/frames/f_023.png b/.ui-review-164-6/frames/f_023.png new file mode 100644 index 00000000..c2c33516 Binary files /dev/null and b/.ui-review-164-6/frames/f_023.png differ diff --git a/.ui-review-164-6/frames/f_024.png b/.ui-review-164-6/frames/f_024.png new file mode 100644 index 00000000..c2c33516 Binary files /dev/null and b/.ui-review-164-6/frames/f_024.png differ diff --git a/.ui-review-164-6/frames/f_025.png b/.ui-review-164-6/frames/f_025.png new file mode 100644 index 00000000..c2c33516 Binary files /dev/null and b/.ui-review-164-6/frames/f_025.png differ diff --git a/.ui-review-164-6/frames/f_026.png b/.ui-review-164-6/frames/f_026.png new file mode 100644 index 00000000..c2c33516 Binary files /dev/null and b/.ui-review-164-6/frames/f_026.png differ diff --git a/.ui-review-164-6/frames/f_027.png b/.ui-review-164-6/frames/f_027.png new file mode 100644 index 00000000..8f789779 Binary files /dev/null and b/.ui-review-164-6/frames/f_027.png differ diff --git a/.ui-review-164-6/frames/f_028.png b/.ui-review-164-6/frames/f_028.png new file mode 100644 index 00000000..8f789779 Binary files /dev/null and b/.ui-review-164-6/frames/f_028.png differ diff --git a/.ui-review-164-6/frames/f_029.png b/.ui-review-164-6/frames/f_029.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_029.png differ diff --git a/.ui-review-164-6/frames/f_030.png b/.ui-review-164-6/frames/f_030.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_030.png differ diff --git a/.ui-review-164-6/frames/f_031.png b/.ui-review-164-6/frames/f_031.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_031.png differ diff --git a/.ui-review-164-6/frames/f_032.png b/.ui-review-164-6/frames/f_032.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_032.png differ diff --git a/.ui-review-164-6/frames/f_033.png b/.ui-review-164-6/frames/f_033.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_033.png differ diff --git a/.ui-review-164-6/frames/f_034.png b/.ui-review-164-6/frames/f_034.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_034.png differ diff --git a/.ui-review-164-6/frames/f_035.png b/.ui-review-164-6/frames/f_035.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_035.png differ diff --git a/.ui-review-164-6/frames/f_036.png b/.ui-review-164-6/frames/f_036.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_036.png differ diff --git a/.ui-review-164-6/frames/f_037.png b/.ui-review-164-6/frames/f_037.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_037.png differ diff --git a/.ui-review-164-6/frames/f_038.png b/.ui-review-164-6/frames/f_038.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_038.png differ diff --git a/.ui-review-164-6/frames/f_039.png b/.ui-review-164-6/frames/f_039.png new file mode 100644 index 00000000..1fab742f Binary files /dev/null and b/.ui-review-164-6/frames/f_039.png differ diff --git a/.ui-review-164-6/frames/f_040.png b/.ui-review-164-6/frames/f_040.png new file mode 100644 index 00000000..e276e9b2 Binary files /dev/null and b/.ui-review-164-6/frames/f_040.png differ diff --git a/.ui-review-164-6/frames/f_041.png b/.ui-review-164-6/frames/f_041.png new file mode 100644 index 00000000..e276e9b2 Binary files /dev/null and b/.ui-review-164-6/frames/f_041.png differ diff --git a/.ui-review-164-6/frames/f_042.png b/.ui-review-164-6/frames/f_042.png new file mode 100644 index 00000000..e276e9b2 Binary files /dev/null and b/.ui-review-164-6/frames/f_042.png differ diff --git a/.ui-review-164-6/frames/f_043.png b/.ui-review-164-6/frames/f_043.png new file mode 100644 index 00000000..e276e9b2 Binary files /dev/null and b/.ui-review-164-6/frames/f_043.png differ diff --git a/.ui-review-164-6/frames/f_044.png b/.ui-review-164-6/frames/f_044.png new file mode 100644 index 00000000..e276e9b2 Binary files /dev/null and b/.ui-review-164-6/frames/f_044.png differ diff --git a/.ui-review-164-6/frames/f_045.png b/.ui-review-164-6/frames/f_045.png new file mode 100644 index 00000000..e276e9b2 Binary files /dev/null and b/.ui-review-164-6/frames/f_045.png differ diff --git a/.ui-review-164-6/frames/f_046.png b/.ui-review-164-6/frames/f_046.png new file mode 100644 index 00000000..e276e9b2 Binary files /dev/null and b/.ui-review-164-6/frames/f_046.png differ diff --git a/.ui-review-164-6/frames/f_047.png b/.ui-review-164-6/frames/f_047.png new file mode 100644 index 00000000..e276e9b2 Binary files /dev/null and b/.ui-review-164-6/frames/f_047.png differ diff --git a/.ui-review-164-6/frames/f_048.png b/.ui-review-164-6/frames/f_048.png new file mode 100644 index 00000000..e276e9b2 Binary files /dev/null and b/.ui-review-164-6/frames/f_048.png differ diff --git a/.ui-review-164-6/frames/f_049.png b/.ui-review-164-6/frames/f_049.png new file mode 100644 index 00000000..e276e9b2 Binary files /dev/null and b/.ui-review-164-6/frames/f_049.png differ diff --git a/.ui-review-164-6/frames/f_050.png b/.ui-review-164-6/frames/f_050.png new file mode 100644 index 00000000..48f175fb Binary files /dev/null and b/.ui-review-164-6/frames/f_050.png differ diff --git a/.ui-review-164-6/frames/f_051.png b/.ui-review-164-6/frames/f_051.png new file mode 100644 index 00000000..48f175fb Binary files /dev/null and b/.ui-review-164-6/frames/f_051.png differ diff --git a/.ui-review-164-6/frames/f_052.png b/.ui-review-164-6/frames/f_052.png new file mode 100644 index 00000000..48f175fb Binary files /dev/null and b/.ui-review-164-6/frames/f_052.png differ diff --git a/.ui-review-164-6/frames/f_053.png b/.ui-review-164-6/frames/f_053.png new file mode 100644 index 00000000..48f175fb Binary files /dev/null and b/.ui-review-164-6/frames/f_053.png differ diff --git a/.ui-review-164-6/frames/f_054.png b/.ui-review-164-6/frames/f_054.png new file mode 100644 index 00000000..48f175fb Binary files /dev/null and b/.ui-review-164-6/frames/f_054.png differ diff --git a/.ui-review-164-6/frames/f_055.png b/.ui-review-164-6/frames/f_055.png new file mode 100644 index 00000000..48f175fb Binary files /dev/null and b/.ui-review-164-6/frames/f_055.png differ diff --git a/.ui-review-164-6/frames/f_056.png b/.ui-review-164-6/frames/f_056.png new file mode 100644 index 00000000..48f175fb Binary files /dev/null and b/.ui-review-164-6/frames/f_056.png differ diff --git a/.ui-review-164-6/frames/f_057.png b/.ui-review-164-6/frames/f_057.png new file mode 100644 index 00000000..48f175fb Binary files /dev/null and b/.ui-review-164-6/frames/f_057.png differ diff --git a/.ui-review-164-6/frames/f_058.png b/.ui-review-164-6/frames/f_058.png new file mode 100644 index 00000000..48f175fb Binary files /dev/null and b/.ui-review-164-6/frames/f_058.png differ diff --git a/.ui-review-164-6/frames/f_059.png b/.ui-review-164-6/frames/f_059.png new file mode 100644 index 00000000..48f175fb Binary files /dev/null and b/.ui-review-164-6/frames/f_059.png differ diff --git a/.ui-review-164-6/frames/f_060.png b/.ui-review-164-6/frames/f_060.png new file mode 100644 index 00000000..778fce91 Binary files /dev/null and b/.ui-review-164-6/frames/f_060.png differ diff --git a/.ui-review-164-6/frames/f_061.png b/.ui-review-164-6/frames/f_061.png new file mode 100644 index 00000000..5e16ef68 Binary files /dev/null and b/.ui-review-164-6/frames/f_061.png differ diff --git a/.ui-review-164-6/frames/f_062.png b/.ui-review-164-6/frames/f_062.png new file mode 100644 index 00000000..5e16ef68 Binary files /dev/null and b/.ui-review-164-6/frames/f_062.png differ diff --git a/.ui-review-164-6/frames/f_063.png b/.ui-review-164-6/frames/f_063.png new file mode 100644 index 00000000..5e16ef68 Binary files /dev/null and b/.ui-review-164-6/frames/f_063.png differ diff --git a/.ui-review-164-6/frames/f_064.png b/.ui-review-164-6/frames/f_064.png new file mode 100644 index 00000000..5e16ef68 Binary files /dev/null and b/.ui-review-164-6/frames/f_064.png differ diff --git a/.ui-review-164-6/frames/f_065.png b/.ui-review-164-6/frames/f_065.png new file mode 100644 index 00000000..5e16ef68 Binary files /dev/null and b/.ui-review-164-6/frames/f_065.png differ diff --git a/.ui-review-164-6/frames/f_066.png b/.ui-review-164-6/frames/f_066.png new file mode 100644 index 00000000..5e16ef68 Binary files /dev/null and b/.ui-review-164-6/frames/f_066.png differ diff --git a/.ui-review-164-6/frames/f_067.png b/.ui-review-164-6/frames/f_067.png new file mode 100644 index 00000000..5e16ef68 Binary files /dev/null and b/.ui-review-164-6/frames/f_067.png differ diff --git a/.ui-review-164-6/frames/f_068.png b/.ui-review-164-6/frames/f_068.png new file mode 100644 index 00000000..5e16ef68 Binary files /dev/null and b/.ui-review-164-6/frames/f_068.png differ diff --git a/.ui-review-164-6/frames/f_069.png b/.ui-review-164-6/frames/f_069.png new file mode 100644 index 00000000..5e16ef68 Binary files /dev/null and b/.ui-review-164-6/frames/f_069.png differ diff --git a/.ui-review-164-6/frames/f_070.png b/.ui-review-164-6/frames/f_070.png new file mode 100644 index 00000000..6d4ce44e Binary files /dev/null and b/.ui-review-164-6/frames/f_070.png differ diff --git a/.ui-review-164-6/frames/f_071.png b/.ui-review-164-6/frames/f_071.png new file mode 100644 index 00000000..6d4ce44e Binary files /dev/null and b/.ui-review-164-6/frames/f_071.png differ diff --git a/.ui-review-164-6/frames/f_072.png b/.ui-review-164-6/frames/f_072.png new file mode 100644 index 00000000..6d4ce44e Binary files /dev/null and b/.ui-review-164-6/frames/f_072.png differ diff --git a/.ui-review-164-6/frames/f_073.png b/.ui-review-164-6/frames/f_073.png new file mode 100644 index 00000000..6d4ce44e Binary files /dev/null and b/.ui-review-164-6/frames/f_073.png differ diff --git a/.ui-review-164-6/frames/f_074.png b/.ui-review-164-6/frames/f_074.png new file mode 100644 index 00000000..6d4ce44e Binary files /dev/null and b/.ui-review-164-6/frames/f_074.png differ diff --git a/.ui-review-164-6/frames/f_075.png b/.ui-review-164-6/frames/f_075.png new file mode 100644 index 00000000..6d4ce44e Binary files /dev/null and b/.ui-review-164-6/frames/f_075.png differ diff --git a/.ui-review-164-6/frames/f_076.png b/.ui-review-164-6/frames/f_076.png new file mode 100644 index 00000000..6d4ce44e Binary files /dev/null and b/.ui-review-164-6/frames/f_076.png differ diff --git a/.ui-review-164-6/frames/f_077.png b/.ui-review-164-6/frames/f_077.png new file mode 100644 index 00000000..6d4ce44e Binary files /dev/null and b/.ui-review-164-6/frames/f_077.png differ diff --git a/.ui-review-164-6/frames/f_078.png b/.ui-review-164-6/frames/f_078.png new file mode 100644 index 00000000..6d4ce44e Binary files /dev/null and b/.ui-review-164-6/frames/f_078.png differ diff --git a/.ui-review-164-6/frames/f_079.png b/.ui-review-164-6/frames/f_079.png new file mode 100644 index 00000000..6d4ce44e Binary files /dev/null and b/.ui-review-164-6/frames/f_079.png differ diff --git a/.ui-review-164-6/frames/f_080.png b/.ui-review-164-6/frames/f_080.png new file mode 100644 index 00000000..db651768 Binary files /dev/null and b/.ui-review-164-6/frames/f_080.png differ diff --git a/.ui-review-164-6/frames/f_081.png b/.ui-review-164-6/frames/f_081.png new file mode 100644 index 00000000..db651768 Binary files /dev/null and b/.ui-review-164-6/frames/f_081.png differ diff --git a/.ui-review-164-6/frames/f_082.png b/.ui-review-164-6/frames/f_082.png new file mode 100644 index 00000000..db651768 Binary files /dev/null and b/.ui-review-164-6/frames/f_082.png differ diff --git a/.ui-review-164-6/frames/f_083.png b/.ui-review-164-6/frames/f_083.png new file mode 100644 index 00000000..db651768 Binary files /dev/null and b/.ui-review-164-6/frames/f_083.png differ diff --git a/.ui-review-164-6/frames/f_084.png b/.ui-review-164-6/frames/f_084.png new file mode 100644 index 00000000..db651768 Binary files /dev/null and b/.ui-review-164-6/frames/f_084.png differ diff --git a/.ui-review-164-6/frames/f_085.png b/.ui-review-164-6/frames/f_085.png new file mode 100644 index 00000000..db651768 Binary files /dev/null and b/.ui-review-164-6/frames/f_085.png differ diff --git a/.ui-review-164-6/frames/f_086.png b/.ui-review-164-6/frames/f_086.png new file mode 100644 index 00000000..db651768 Binary files /dev/null and b/.ui-review-164-6/frames/f_086.png differ diff --git a/.ui-review-164-6/frames/f_087.png b/.ui-review-164-6/frames/f_087.png new file mode 100644 index 00000000..db651768 Binary files /dev/null and b/.ui-review-164-6/frames/f_087.png differ diff --git a/.ui-review-164-6/frames/f_088.png b/.ui-review-164-6/frames/f_088.png new file mode 100644 index 00000000..db651768 Binary files /dev/null and b/.ui-review-164-6/frames/f_088.png differ diff --git a/.ui-review-164-6/frames/f_089.png b/.ui-review-164-6/frames/f_089.png new file mode 100644 index 00000000..db651768 Binary files /dev/null and b/.ui-review-164-6/frames/f_089.png differ diff --git a/.ui-review-164-6/frames/f_090.png b/.ui-review-164-6/frames/f_090.png new file mode 100644 index 00000000..fb603631 Binary files /dev/null and b/.ui-review-164-6/frames/f_090.png differ diff --git a/.ui-review-164-6/frames/f_091.png b/.ui-review-164-6/frames/f_091.png new file mode 100644 index 00000000..fb603631 Binary files /dev/null and b/.ui-review-164-6/frames/f_091.png differ diff --git a/.ui-review-164-6/frames/f_092.png b/.ui-review-164-6/frames/f_092.png new file mode 100644 index 00000000..fb603631 Binary files /dev/null and b/.ui-review-164-6/frames/f_092.png differ diff --git a/.ui-review-164-6/frames/f_093.png b/.ui-review-164-6/frames/f_093.png new file mode 100644 index 00000000..fb603631 Binary files /dev/null and b/.ui-review-164-6/frames/f_093.png differ diff --git a/.ui-review-164-6/frames/f_094.png b/.ui-review-164-6/frames/f_094.png new file mode 100644 index 00000000..fb603631 Binary files /dev/null and b/.ui-review-164-6/frames/f_094.png differ diff --git a/.ui-review-164-6/frames/f_095.png b/.ui-review-164-6/frames/f_095.png new file mode 100644 index 00000000..fb603631 Binary files /dev/null and b/.ui-review-164-6/frames/f_095.png differ diff --git a/.ui-review-164-6/frames/f_096.png b/.ui-review-164-6/frames/f_096.png new file mode 100644 index 00000000..fb603631 Binary files /dev/null and b/.ui-review-164-6/frames/f_096.png differ diff --git a/.ui-review-164-6/frames/f_097.png b/.ui-review-164-6/frames/f_097.png new file mode 100644 index 00000000..fb603631 Binary files /dev/null and b/.ui-review-164-6/frames/f_097.png differ diff --git a/.ui-review-164-6/frames/f_098.png b/.ui-review-164-6/frames/f_098.png new file mode 100644 index 00000000..fb603631 Binary files /dev/null and b/.ui-review-164-6/frames/f_098.png differ diff --git a/.ui-review-164-6/frames/f_099.png b/.ui-review-164-6/frames/f_099.png new file mode 100644 index 00000000..fb603631 Binary files /dev/null and b/.ui-review-164-6/frames/f_099.png differ diff --git a/.ui-review-164-6/frames/f_100.png b/.ui-review-164-6/frames/f_100.png new file mode 100644 index 00000000..bc097573 Binary files /dev/null and b/.ui-review-164-6/frames/f_100.png differ diff --git a/.ui-review-164-6/frames/f_101.png b/.ui-review-164-6/frames/f_101.png new file mode 100644 index 00000000..bc097573 Binary files /dev/null and b/.ui-review-164-6/frames/f_101.png differ diff --git a/.ui-review-164-6/frames/f_102.png b/.ui-review-164-6/frames/f_102.png new file mode 100644 index 00000000..bc097573 Binary files /dev/null and b/.ui-review-164-6/frames/f_102.png differ diff --git a/.ui-review-164-6/frames/f_103.png b/.ui-review-164-6/frames/f_103.png new file mode 100644 index 00000000..bc097573 Binary files /dev/null and b/.ui-review-164-6/frames/f_103.png differ diff --git a/.ui-review-164-6/frames/f_104.png b/.ui-review-164-6/frames/f_104.png new file mode 100644 index 00000000..bc097573 Binary files /dev/null and b/.ui-review-164-6/frames/f_104.png differ diff --git a/.ui-review-164-6/frames/f_105.png b/.ui-review-164-6/frames/f_105.png new file mode 100644 index 00000000..bc097573 Binary files /dev/null and b/.ui-review-164-6/frames/f_105.png differ diff --git a/.ui-review-164-6/frames/f_106.png b/.ui-review-164-6/frames/f_106.png new file mode 100644 index 00000000..bc097573 Binary files /dev/null and b/.ui-review-164-6/frames/f_106.png differ diff --git a/.ui-review-164-6/frames/f_107.png b/.ui-review-164-6/frames/f_107.png new file mode 100644 index 00000000..bc097573 Binary files /dev/null and b/.ui-review-164-6/frames/f_107.png differ diff --git a/.ui-review-164-6/frames/f_108.png b/.ui-review-164-6/frames/f_108.png new file mode 100644 index 00000000..bc097573 Binary files /dev/null and b/.ui-review-164-6/frames/f_108.png differ diff --git a/.ui-review-164-6/frames/f_109.png b/.ui-review-164-6/frames/f_109.png new file mode 100644 index 00000000..bc097573 Binary files /dev/null and b/.ui-review-164-6/frames/f_109.png differ diff --git a/.ui-review-164-6/frames/f_110.png b/.ui-review-164-6/frames/f_110.png new file mode 100644 index 00000000..08d75c9d Binary files /dev/null and b/.ui-review-164-6/frames/f_110.png differ diff --git a/.ui-review-164-6/frames/f_111.png b/.ui-review-164-6/frames/f_111.png new file mode 100644 index 00000000..08d75c9d Binary files /dev/null and b/.ui-review-164-6/frames/f_111.png differ diff --git a/.ui-review-164-6/frames/f_112.png b/.ui-review-164-6/frames/f_112.png new file mode 100644 index 00000000..08d75c9d Binary files /dev/null and b/.ui-review-164-6/frames/f_112.png differ diff --git a/.ui-review-164-6/frames/f_113.png b/.ui-review-164-6/frames/f_113.png new file mode 100644 index 00000000..08d75c9d Binary files /dev/null and b/.ui-review-164-6/frames/f_113.png differ diff --git a/.ui-review-164-6/frames/f_114.png b/.ui-review-164-6/frames/f_114.png new file mode 100644 index 00000000..08d75c9d Binary files /dev/null and b/.ui-review-164-6/frames/f_114.png differ diff --git a/.ui-review-164-6/frames/f_115.png b/.ui-review-164-6/frames/f_115.png new file mode 100644 index 00000000..08d75c9d Binary files /dev/null and b/.ui-review-164-6/frames/f_115.png differ diff --git a/.ui-review-164-6/frames/f_116.png b/.ui-review-164-6/frames/f_116.png new file mode 100644 index 00000000..08d75c9d Binary files /dev/null and b/.ui-review-164-6/frames/f_116.png differ diff --git a/.ui-review-164-6/frames/f_117.png b/.ui-review-164-6/frames/f_117.png new file mode 100644 index 00000000..08d75c9d Binary files /dev/null and b/.ui-review-164-6/frames/f_117.png differ diff --git a/.ui-review-164-6/frames/f_118.png b/.ui-review-164-6/frames/f_118.png new file mode 100644 index 00000000..08d75c9d Binary files /dev/null and b/.ui-review-164-6/frames/f_118.png differ diff --git a/.ui-review-164-6/frames/f_119.png b/.ui-review-164-6/frames/f_119.png new file mode 100644 index 00000000..08d75c9d Binary files /dev/null and b/.ui-review-164-6/frames/f_119.png differ diff --git a/.ui-review-164-6/frames2/f_001.png b/.ui-review-164-6/frames2/f_001.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_001.png differ diff --git a/.ui-review-164-6/frames2/f_002.png b/.ui-review-164-6/frames2/f_002.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_002.png differ diff --git a/.ui-review-164-6/frames2/f_003.png b/.ui-review-164-6/frames2/f_003.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_003.png differ diff --git a/.ui-review-164-6/frames2/f_004.png b/.ui-review-164-6/frames2/f_004.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_004.png differ diff --git a/.ui-review-164-6/frames2/f_005.png b/.ui-review-164-6/frames2/f_005.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_005.png differ diff --git a/.ui-review-164-6/frames2/f_006.png b/.ui-review-164-6/frames2/f_006.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_006.png differ diff --git a/.ui-review-164-6/frames2/f_007.png b/.ui-review-164-6/frames2/f_007.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_007.png differ diff --git a/.ui-review-164-6/frames2/f_008.png b/.ui-review-164-6/frames2/f_008.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_008.png differ diff --git a/.ui-review-164-6/frames2/f_009.png b/.ui-review-164-6/frames2/f_009.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_009.png differ diff --git a/.ui-review-164-6/frames2/f_010.png b/.ui-review-164-6/frames2/f_010.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_010.png differ diff --git a/.ui-review-164-6/frames2/f_011.png b/.ui-review-164-6/frames2/f_011.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_011.png differ diff --git a/.ui-review-164-6/frames2/f_012.png b/.ui-review-164-6/frames2/f_012.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_012.png differ diff --git a/.ui-review-164-6/frames2/f_013.png b/.ui-review-164-6/frames2/f_013.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_013.png differ diff --git a/.ui-review-164-6/frames2/f_014.png b/.ui-review-164-6/frames2/f_014.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_014.png differ diff --git a/.ui-review-164-6/frames2/f_015.png b/.ui-review-164-6/frames2/f_015.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_015.png differ diff --git a/.ui-review-164-6/frames2/f_016.png b/.ui-review-164-6/frames2/f_016.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_016.png differ diff --git a/.ui-review-164-6/frames2/f_017.png b/.ui-review-164-6/frames2/f_017.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_017.png differ diff --git a/.ui-review-164-6/frames2/f_018.png b/.ui-review-164-6/frames2/f_018.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_018.png differ diff --git a/.ui-review-164-6/frames2/f_019.png b/.ui-review-164-6/frames2/f_019.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_019.png differ diff --git a/.ui-review-164-6/frames2/f_020.png b/.ui-review-164-6/frames2/f_020.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_020.png differ diff --git a/.ui-review-164-6/frames2/f_021.png b/.ui-review-164-6/frames2/f_021.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_021.png differ diff --git a/.ui-review-164-6/frames2/f_022.png b/.ui-review-164-6/frames2/f_022.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_022.png differ diff --git a/.ui-review-164-6/frames2/f_023.png b/.ui-review-164-6/frames2/f_023.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_023.png differ diff --git a/.ui-review-164-6/frames2/f_024.png b/.ui-review-164-6/frames2/f_024.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_024.png differ diff --git a/.ui-review-164-6/frames2/f_025.png b/.ui-review-164-6/frames2/f_025.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_025.png differ diff --git a/.ui-review-164-6/frames2/f_026.png b/.ui-review-164-6/frames2/f_026.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_026.png differ diff --git a/.ui-review-164-6/frames2/f_027.png b/.ui-review-164-6/frames2/f_027.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_027.png differ diff --git a/.ui-review-164-6/frames2/f_028.png b/.ui-review-164-6/frames2/f_028.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_028.png differ diff --git a/.ui-review-164-6/frames2/f_029.png b/.ui-review-164-6/frames2/f_029.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_029.png differ diff --git a/.ui-review-164-6/frames2/f_030.png b/.ui-review-164-6/frames2/f_030.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_030.png differ diff --git a/.ui-review-164-6/frames2/f_031.png b/.ui-review-164-6/frames2/f_031.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_031.png differ diff --git a/.ui-review-164-6/frames2/f_032.png b/.ui-review-164-6/frames2/f_032.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_032.png differ diff --git a/.ui-review-164-6/frames2/f_033.png b/.ui-review-164-6/frames2/f_033.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_033.png differ diff --git a/.ui-review-164-6/frames2/f_034.png b/.ui-review-164-6/frames2/f_034.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_034.png differ diff --git a/.ui-review-164-6/frames2/f_035.png b/.ui-review-164-6/frames2/f_035.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_035.png differ diff --git a/.ui-review-164-6/frames2/f_036.png b/.ui-review-164-6/frames2/f_036.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_036.png differ diff --git a/.ui-review-164-6/frames2/f_037.png b/.ui-review-164-6/frames2/f_037.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_037.png differ diff --git a/.ui-review-164-6/frames2/f_038.png b/.ui-review-164-6/frames2/f_038.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_038.png differ diff --git a/.ui-review-164-6/frames2/f_039.png b/.ui-review-164-6/frames2/f_039.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_039.png differ diff --git a/.ui-review-164-6/frames2/f_040.png b/.ui-review-164-6/frames2/f_040.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_040.png differ diff --git a/.ui-review-164-6/frames2/f_041.png b/.ui-review-164-6/frames2/f_041.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_041.png differ diff --git a/.ui-review-164-6/frames2/f_042.png b/.ui-review-164-6/frames2/f_042.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_042.png differ diff --git a/.ui-review-164-6/frames2/f_043.png b/.ui-review-164-6/frames2/f_043.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_043.png differ diff --git a/.ui-review-164-6/frames2/f_044.png b/.ui-review-164-6/frames2/f_044.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_044.png differ diff --git a/.ui-review-164-6/frames2/f_045.png b/.ui-review-164-6/frames2/f_045.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_045.png differ diff --git a/.ui-review-164-6/frames2/f_046.png b/.ui-review-164-6/frames2/f_046.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_046.png differ diff --git a/.ui-review-164-6/frames2/f_047.png b/.ui-review-164-6/frames2/f_047.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_047.png differ diff --git a/.ui-review-164-6/frames2/f_048.png b/.ui-review-164-6/frames2/f_048.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_048.png differ diff --git a/.ui-review-164-6/frames2/f_049.png b/.ui-review-164-6/frames2/f_049.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_049.png differ diff --git a/.ui-review-164-6/frames2/f_050.png b/.ui-review-164-6/frames2/f_050.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_050.png differ diff --git a/.ui-review-164-6/frames2/f_051.png b/.ui-review-164-6/frames2/f_051.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_051.png differ diff --git a/.ui-review-164-6/frames2/f_052.png b/.ui-review-164-6/frames2/f_052.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_052.png differ diff --git a/.ui-review-164-6/frames2/f_053.png b/.ui-review-164-6/frames2/f_053.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_053.png differ diff --git a/.ui-review-164-6/frames2/f_054.png b/.ui-review-164-6/frames2/f_054.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_054.png differ diff --git a/.ui-review-164-6/frames2/f_055.png b/.ui-review-164-6/frames2/f_055.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_055.png differ diff --git a/.ui-review-164-6/frames2/f_056.png b/.ui-review-164-6/frames2/f_056.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_056.png differ diff --git a/.ui-review-164-6/frames2/f_057.png b/.ui-review-164-6/frames2/f_057.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_057.png differ diff --git a/.ui-review-164-6/frames2/f_058.png b/.ui-review-164-6/frames2/f_058.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_058.png differ diff --git a/.ui-review-164-6/frames2/f_059.png b/.ui-review-164-6/frames2/f_059.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_059.png differ diff --git a/.ui-review-164-6/frames2/f_060.png b/.ui-review-164-6/frames2/f_060.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_060.png differ diff --git a/.ui-review-164-6/frames2/f_061.png b/.ui-review-164-6/frames2/f_061.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_061.png differ diff --git a/.ui-review-164-6/frames2/f_062.png b/.ui-review-164-6/frames2/f_062.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_062.png differ diff --git a/.ui-review-164-6/frames2/f_063.png b/.ui-review-164-6/frames2/f_063.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_063.png differ diff --git a/.ui-review-164-6/frames2/f_064.png b/.ui-review-164-6/frames2/f_064.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_064.png differ diff --git a/.ui-review-164-6/frames2/f_065.png b/.ui-review-164-6/frames2/f_065.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_065.png differ diff --git a/.ui-review-164-6/frames2/f_066.png b/.ui-review-164-6/frames2/f_066.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_066.png differ diff --git a/.ui-review-164-6/frames2/f_067.png b/.ui-review-164-6/frames2/f_067.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_067.png differ diff --git a/.ui-review-164-6/frames2/f_068.png b/.ui-review-164-6/frames2/f_068.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_068.png differ diff --git a/.ui-review-164-6/frames2/f_069.png b/.ui-review-164-6/frames2/f_069.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_069.png differ diff --git a/.ui-review-164-6/frames2/f_070.png b/.ui-review-164-6/frames2/f_070.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_070.png differ diff --git a/.ui-review-164-6/frames2/f_071.png b/.ui-review-164-6/frames2/f_071.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_071.png differ diff --git a/.ui-review-164-6/frames2/f_072.png b/.ui-review-164-6/frames2/f_072.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_072.png differ diff --git a/.ui-review-164-6/frames2/f_073.png b/.ui-review-164-6/frames2/f_073.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_073.png differ diff --git a/.ui-review-164-6/frames2/f_074.png b/.ui-review-164-6/frames2/f_074.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_074.png differ diff --git a/.ui-review-164-6/frames2/f_075.png b/.ui-review-164-6/frames2/f_075.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_075.png differ diff --git a/.ui-review-164-6/frames2/f_076.png b/.ui-review-164-6/frames2/f_076.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_076.png differ diff --git a/.ui-review-164-6/frames2/f_077.png b/.ui-review-164-6/frames2/f_077.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_077.png differ diff --git a/.ui-review-164-6/frames2/f_078.png b/.ui-review-164-6/frames2/f_078.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_078.png differ diff --git a/.ui-review-164-6/frames2/f_079.png b/.ui-review-164-6/frames2/f_079.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_079.png differ diff --git a/.ui-review-164-6/frames2/f_080.png b/.ui-review-164-6/frames2/f_080.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_080.png differ diff --git a/.ui-review-164-6/frames2/f_081.png b/.ui-review-164-6/frames2/f_081.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_081.png differ diff --git a/.ui-review-164-6/frames2/f_082.png b/.ui-review-164-6/frames2/f_082.png new file mode 100644 index 00000000..108fa3f2 Binary files /dev/null and b/.ui-review-164-6/frames2/f_082.png differ diff --git a/.ui-review-164-6/frames2/f_083.png b/.ui-review-164-6/frames2/f_083.png new file mode 100644 index 00000000..865feebf Binary files /dev/null and b/.ui-review-164-6/frames2/f_083.png differ diff --git a/.ui-review-164-6/frames2/f_084.png b/.ui-review-164-6/frames2/f_084.png new file mode 100644 index 00000000..dd4e810f Binary files /dev/null and b/.ui-review-164-6/frames2/f_084.png differ diff --git a/.ui-review-164-6/frames2/f_085.png b/.ui-review-164-6/frames2/f_085.png new file mode 100644 index 00000000..a5994de1 Binary files /dev/null and b/.ui-review-164-6/frames2/f_085.png differ diff --git a/.ui-review-164-6/frames2/f_086.png b/.ui-review-164-6/frames2/f_086.png new file mode 100644 index 00000000..93e6bab7 Binary files /dev/null and b/.ui-review-164-6/frames2/f_086.png differ diff --git a/.ui-review-164-6/frames2/f_087.png b/.ui-review-164-6/frames2/f_087.png new file mode 100644 index 00000000..eda9cbef Binary files /dev/null and b/.ui-review-164-6/frames2/f_087.png differ diff --git a/.ui-review-164-6/frames2/f_088.png b/.ui-review-164-6/frames2/f_088.png new file mode 100644 index 00000000..c29c960c Binary files /dev/null and b/.ui-review-164-6/frames2/f_088.png differ diff --git a/.ui-review-164-6/frames2/f_089.png b/.ui-review-164-6/frames2/f_089.png new file mode 100644 index 00000000..0b103c31 Binary files /dev/null and b/.ui-review-164-6/frames2/f_089.png differ diff --git a/.ui-review-164-6/frames2/f_090.png b/.ui-review-164-6/frames2/f_090.png new file mode 100644 index 00000000..324ec415 Binary files /dev/null and b/.ui-review-164-6/frames2/f_090.png differ diff --git a/.ui-review-164-6/frames2/f_091.png b/.ui-review-164-6/frames2/f_091.png new file mode 100644 index 00000000..b745579b Binary files /dev/null and b/.ui-review-164-6/frames2/f_091.png differ diff --git a/.ui-review-164-6/frames2/f_092.png b/.ui-review-164-6/frames2/f_092.png new file mode 100644 index 00000000..ad757ddd Binary files /dev/null and b/.ui-review-164-6/frames2/f_092.png differ diff --git a/.ui-review-164-6/frames2/f_093.png b/.ui-review-164-6/frames2/f_093.png new file mode 100644 index 00000000..1308aa05 Binary files /dev/null and b/.ui-review-164-6/frames2/f_093.png differ diff --git a/.ui-review-164-6/frames2/f_094.png b/.ui-review-164-6/frames2/f_094.png new file mode 100644 index 00000000..545a2ad6 Binary files /dev/null and b/.ui-review-164-6/frames2/f_094.png differ diff --git a/.ui-review-164-6/frames2/f_095.png b/.ui-review-164-6/frames2/f_095.png new file mode 100644 index 00000000..52874ef7 Binary files /dev/null and b/.ui-review-164-6/frames2/f_095.png differ diff --git a/.ui-review-164-6/frames2/f_096.png b/.ui-review-164-6/frames2/f_096.png new file mode 100644 index 00000000..08bfe410 Binary files /dev/null and b/.ui-review-164-6/frames2/f_096.png differ diff --git a/.ui-review-164-6/frames2/f_097.png b/.ui-review-164-6/frames2/f_097.png new file mode 100644 index 00000000..08bfe410 Binary files /dev/null and b/.ui-review-164-6/frames2/f_097.png differ diff --git a/.ui-review-164-6/frames2/f_098.png b/.ui-review-164-6/frames2/f_098.png new file mode 100644 index 00000000..08bfe410 Binary files /dev/null and b/.ui-review-164-6/frames2/f_098.png differ diff --git a/.ui-review-164-6/frames2/f_099.png b/.ui-review-164-6/frames2/f_099.png new file mode 100644 index 00000000..08bfe410 Binary files /dev/null and b/.ui-review-164-6/frames2/f_099.png differ diff --git a/.ui-review-164-6/frames2/f_100.png b/.ui-review-164-6/frames2/f_100.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_100.png differ diff --git a/.ui-review-164-6/frames2/f_101.png b/.ui-review-164-6/frames2/f_101.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_101.png differ diff --git a/.ui-review-164-6/frames2/f_102.png b/.ui-review-164-6/frames2/f_102.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_102.png differ diff --git a/.ui-review-164-6/frames2/f_103.png b/.ui-review-164-6/frames2/f_103.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_103.png differ diff --git a/.ui-review-164-6/frames2/f_104.png b/.ui-review-164-6/frames2/f_104.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_104.png differ diff --git a/.ui-review-164-6/frames2/f_105.png b/.ui-review-164-6/frames2/f_105.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_105.png differ diff --git a/.ui-review-164-6/frames2/f_106.png b/.ui-review-164-6/frames2/f_106.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_106.png differ diff --git a/.ui-review-164-6/frames2/f_107.png b/.ui-review-164-6/frames2/f_107.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_107.png differ diff --git a/.ui-review-164-6/frames2/f_108.png b/.ui-review-164-6/frames2/f_108.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_108.png differ diff --git a/.ui-review-164-6/frames2/f_109.png b/.ui-review-164-6/frames2/f_109.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_109.png differ diff --git a/.ui-review-164-6/frames2/f_110.png b/.ui-review-164-6/frames2/f_110.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_110.png differ diff --git a/.ui-review-164-6/frames2/f_111.png b/.ui-review-164-6/frames2/f_111.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_111.png differ diff --git a/.ui-review-164-6/frames2/f_112.png b/.ui-review-164-6/frames2/f_112.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_112.png differ diff --git a/.ui-review-164-6/frames2/f_113.png b/.ui-review-164-6/frames2/f_113.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_113.png differ diff --git a/.ui-review-164-6/frames2/f_114.png b/.ui-review-164-6/frames2/f_114.png new file mode 100644 index 00000000..2708beff Binary files /dev/null and b/.ui-review-164-6/frames2/f_114.png differ diff --git a/.ui-review-164-6/frames2/f_115.png b/.ui-review-164-6/frames2/f_115.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_115.png differ diff --git a/.ui-review-164-6/frames2/f_116.png b/.ui-review-164-6/frames2/f_116.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_116.png differ diff --git a/.ui-review-164-6/frames2/f_117.png b/.ui-review-164-6/frames2/f_117.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_117.png differ diff --git a/.ui-review-164-6/frames2/f_118.png b/.ui-review-164-6/frames2/f_118.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_118.png differ diff --git a/.ui-review-164-6/frames2/f_119.png b/.ui-review-164-6/frames2/f_119.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_119.png differ diff --git a/.ui-review-164-6/frames2/f_120.png b/.ui-review-164-6/frames2/f_120.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_120.png differ diff --git a/.ui-review-164-6/frames2/f_121.png b/.ui-review-164-6/frames2/f_121.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_121.png differ diff --git a/.ui-review-164-6/frames2/f_122.png b/.ui-review-164-6/frames2/f_122.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_122.png differ diff --git a/.ui-review-164-6/frames2/f_123.png b/.ui-review-164-6/frames2/f_123.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_123.png differ diff --git a/.ui-review-164-6/frames2/f_124.png b/.ui-review-164-6/frames2/f_124.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_124.png differ diff --git a/.ui-review-164-6/frames2/f_125.png b/.ui-review-164-6/frames2/f_125.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_125.png differ diff --git a/.ui-review-164-6/frames2/f_126.png b/.ui-review-164-6/frames2/f_126.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_126.png differ diff --git a/.ui-review-164-6/frames2/f_127.png b/.ui-review-164-6/frames2/f_127.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_127.png differ diff --git a/.ui-review-164-6/frames2/f_128.png b/.ui-review-164-6/frames2/f_128.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_128.png differ diff --git a/.ui-review-164-6/frames2/f_129.png b/.ui-review-164-6/frames2/f_129.png new file mode 100644 index 00000000..369c5c2d Binary files /dev/null and b/.ui-review-164-6/frames2/f_129.png differ diff --git a/.ui-review-164-6/frames2/f_130.png b/.ui-review-164-6/frames2/f_130.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_130.png differ diff --git a/.ui-review-164-6/frames2/f_131.png b/.ui-review-164-6/frames2/f_131.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_131.png differ diff --git a/.ui-review-164-6/frames2/f_132.png b/.ui-review-164-6/frames2/f_132.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_132.png differ diff --git a/.ui-review-164-6/frames2/f_133.png b/.ui-review-164-6/frames2/f_133.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_133.png differ diff --git a/.ui-review-164-6/frames2/f_134.png b/.ui-review-164-6/frames2/f_134.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_134.png differ diff --git a/.ui-review-164-6/frames2/f_135.png b/.ui-review-164-6/frames2/f_135.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_135.png differ diff --git a/.ui-review-164-6/frames2/f_136.png b/.ui-review-164-6/frames2/f_136.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_136.png differ diff --git a/.ui-review-164-6/frames2/f_137.png b/.ui-review-164-6/frames2/f_137.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_137.png differ diff --git a/.ui-review-164-6/frames2/f_138.png b/.ui-review-164-6/frames2/f_138.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_138.png differ diff --git a/.ui-review-164-6/frames2/f_139.png b/.ui-review-164-6/frames2/f_139.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_139.png differ diff --git a/.ui-review-164-6/frames2/f_140.png b/.ui-review-164-6/frames2/f_140.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_140.png differ diff --git a/.ui-review-164-6/frames2/f_141.png b/.ui-review-164-6/frames2/f_141.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_141.png differ diff --git a/.ui-review-164-6/frames2/f_142.png b/.ui-review-164-6/frames2/f_142.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_142.png differ diff --git a/.ui-review-164-6/frames2/f_143.png b/.ui-review-164-6/frames2/f_143.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_143.png differ diff --git a/.ui-review-164-6/frames2/f_144.png b/.ui-review-164-6/frames2/f_144.png new file mode 100644 index 00000000..4439b010 Binary files /dev/null and b/.ui-review-164-6/frames2/f_144.png differ diff --git a/.ui-review-164-6/frames2/f_145.png b/.ui-review-164-6/frames2/f_145.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_145.png differ diff --git a/.ui-review-164-6/frames2/f_146.png b/.ui-review-164-6/frames2/f_146.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_146.png differ diff --git a/.ui-review-164-6/frames2/f_147.png b/.ui-review-164-6/frames2/f_147.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_147.png differ diff --git a/.ui-review-164-6/frames2/f_148.png b/.ui-review-164-6/frames2/f_148.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_148.png differ diff --git a/.ui-review-164-6/frames2/f_149.png b/.ui-review-164-6/frames2/f_149.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_149.png differ diff --git a/.ui-review-164-6/frames2/f_150.png b/.ui-review-164-6/frames2/f_150.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_150.png differ diff --git a/.ui-review-164-6/frames2/f_151.png b/.ui-review-164-6/frames2/f_151.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_151.png differ diff --git a/.ui-review-164-6/frames2/f_152.png b/.ui-review-164-6/frames2/f_152.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_152.png differ diff --git a/.ui-review-164-6/frames2/f_153.png b/.ui-review-164-6/frames2/f_153.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_153.png differ diff --git a/.ui-review-164-6/frames2/f_154.png b/.ui-review-164-6/frames2/f_154.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_154.png differ diff --git a/.ui-review-164-6/frames2/f_155.png b/.ui-review-164-6/frames2/f_155.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_155.png differ diff --git a/.ui-review-164-6/frames2/f_156.png b/.ui-review-164-6/frames2/f_156.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_156.png differ diff --git a/.ui-review-164-6/frames2/f_157.png b/.ui-review-164-6/frames2/f_157.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_157.png differ diff --git a/.ui-review-164-6/frames2/f_158.png b/.ui-review-164-6/frames2/f_158.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_158.png differ diff --git a/.ui-review-164-6/frames2/f_159.png b/.ui-review-164-6/frames2/f_159.png new file mode 100644 index 00000000..3db412dc Binary files /dev/null and b/.ui-review-164-6/frames2/f_159.png differ diff --git a/.ui-review-164-6/frames2/f_160.png b/.ui-review-164-6/frames2/f_160.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_160.png differ diff --git a/.ui-review-164-6/frames2/f_161.png b/.ui-review-164-6/frames2/f_161.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_161.png differ diff --git a/.ui-review-164-6/frames2/f_162.png b/.ui-review-164-6/frames2/f_162.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_162.png differ diff --git a/.ui-review-164-6/frames2/f_163.png b/.ui-review-164-6/frames2/f_163.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_163.png differ diff --git a/.ui-review-164-6/frames2/f_164.png b/.ui-review-164-6/frames2/f_164.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_164.png differ diff --git a/.ui-review-164-6/frames2/f_165.png b/.ui-review-164-6/frames2/f_165.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_165.png differ diff --git a/.ui-review-164-6/frames2/f_166.png b/.ui-review-164-6/frames2/f_166.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_166.png differ diff --git a/.ui-review-164-6/frames2/f_167.png b/.ui-review-164-6/frames2/f_167.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_167.png differ diff --git a/.ui-review-164-6/frames2/f_168.png b/.ui-review-164-6/frames2/f_168.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_168.png differ diff --git a/.ui-review-164-6/frames2/f_169.png b/.ui-review-164-6/frames2/f_169.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_169.png differ diff --git a/.ui-review-164-6/frames2/f_170.png b/.ui-review-164-6/frames2/f_170.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_170.png differ diff --git a/.ui-review-164-6/frames2/f_171.png b/.ui-review-164-6/frames2/f_171.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_171.png differ diff --git a/.ui-review-164-6/frames2/f_172.png b/.ui-review-164-6/frames2/f_172.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_172.png differ diff --git a/.ui-review-164-6/frames2/f_173.png b/.ui-review-164-6/frames2/f_173.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_173.png differ diff --git a/.ui-review-164-6/frames2/f_174.png b/.ui-review-164-6/frames2/f_174.png new file mode 100644 index 00000000..54084b01 Binary files /dev/null and b/.ui-review-164-6/frames2/f_174.png differ diff --git a/.ui-review-164-6/frames2/f_175.png b/.ui-review-164-6/frames2/f_175.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_175.png differ diff --git a/.ui-review-164-6/frames2/f_176.png b/.ui-review-164-6/frames2/f_176.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_176.png differ diff --git a/.ui-review-164-6/frames2/f_177.png b/.ui-review-164-6/frames2/f_177.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_177.png differ diff --git a/.ui-review-164-6/frames2/f_178.png b/.ui-review-164-6/frames2/f_178.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_178.png differ diff --git a/.ui-review-164-6/frames2/f_179.png b/.ui-review-164-6/frames2/f_179.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_179.png differ diff --git a/.ui-review-164-6/frames2/f_180.png b/.ui-review-164-6/frames2/f_180.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_180.png differ diff --git a/.ui-review-164-6/frames2/f_181.png b/.ui-review-164-6/frames2/f_181.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_181.png differ diff --git a/.ui-review-164-6/frames2/f_182.png b/.ui-review-164-6/frames2/f_182.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_182.png differ diff --git a/.ui-review-164-6/frames2/f_183.png b/.ui-review-164-6/frames2/f_183.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_183.png differ diff --git a/.ui-review-164-6/frames2/f_184.png b/.ui-review-164-6/frames2/f_184.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_184.png differ diff --git a/.ui-review-164-6/frames2/f_185.png b/.ui-review-164-6/frames2/f_185.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_185.png differ diff --git a/.ui-review-164-6/frames2/f_186.png b/.ui-review-164-6/frames2/f_186.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_186.png differ diff --git a/.ui-review-164-6/frames2/f_187.png b/.ui-review-164-6/frames2/f_187.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_187.png differ diff --git a/.ui-review-164-6/frames2/f_188.png b/.ui-review-164-6/frames2/f_188.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_188.png differ diff --git a/.ui-review-164-6/frames2/f_189.png b/.ui-review-164-6/frames2/f_189.png new file mode 100644 index 00000000..95ef6910 Binary files /dev/null and b/.ui-review-164-6/frames2/f_189.png differ diff --git a/.ui-review-164-6/frames2/f_190.png b/.ui-review-164-6/frames2/f_190.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_190.png differ diff --git a/.ui-review-164-6/frames2/f_191.png b/.ui-review-164-6/frames2/f_191.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_191.png differ diff --git a/.ui-review-164-6/frames2/f_192.png b/.ui-review-164-6/frames2/f_192.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_192.png differ diff --git a/.ui-review-164-6/frames2/f_193.png b/.ui-review-164-6/frames2/f_193.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_193.png differ diff --git a/.ui-review-164-6/frames2/f_194.png b/.ui-review-164-6/frames2/f_194.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_194.png differ diff --git a/.ui-review-164-6/frames2/f_195.png b/.ui-review-164-6/frames2/f_195.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_195.png differ diff --git a/.ui-review-164-6/frames2/f_196.png b/.ui-review-164-6/frames2/f_196.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_196.png differ diff --git a/.ui-review-164-6/frames2/f_197.png b/.ui-review-164-6/frames2/f_197.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_197.png differ diff --git a/.ui-review-164-6/frames2/f_198.png b/.ui-review-164-6/frames2/f_198.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_198.png differ diff --git a/.ui-review-164-6/frames2/f_199.png b/.ui-review-164-6/frames2/f_199.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_199.png differ diff --git a/.ui-review-164-6/frames2/f_200.png b/.ui-review-164-6/frames2/f_200.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_200.png differ diff --git a/.ui-review-164-6/frames2/f_201.png b/.ui-review-164-6/frames2/f_201.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_201.png differ diff --git a/.ui-review-164-6/frames2/f_202.png b/.ui-review-164-6/frames2/f_202.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_202.png differ diff --git a/.ui-review-164-6/frames2/f_203.png b/.ui-review-164-6/frames2/f_203.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_203.png differ diff --git a/.ui-review-164-6/frames2/f_204.png b/.ui-review-164-6/frames2/f_204.png new file mode 100644 index 00000000..51f46f3d Binary files /dev/null and b/.ui-review-164-6/frames2/f_204.png differ diff --git a/.ui-review-164-6/frames2/f_205.png b/.ui-review-164-6/frames2/f_205.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_205.png differ diff --git a/.ui-review-164-6/frames2/f_206.png b/.ui-review-164-6/frames2/f_206.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_206.png differ diff --git a/.ui-review-164-6/frames2/f_207.png b/.ui-review-164-6/frames2/f_207.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_207.png differ diff --git a/.ui-review-164-6/frames2/f_208.png b/.ui-review-164-6/frames2/f_208.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_208.png differ diff --git a/.ui-review-164-6/frames2/f_209.png b/.ui-review-164-6/frames2/f_209.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_209.png differ diff --git a/.ui-review-164-6/frames2/f_210.png b/.ui-review-164-6/frames2/f_210.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_210.png differ diff --git a/.ui-review-164-6/frames2/f_211.png b/.ui-review-164-6/frames2/f_211.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_211.png differ diff --git a/.ui-review-164-6/frames2/f_212.png b/.ui-review-164-6/frames2/f_212.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_212.png differ diff --git a/.ui-review-164-6/frames2/f_213.png b/.ui-review-164-6/frames2/f_213.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_213.png differ diff --git a/.ui-review-164-6/frames2/f_214.png b/.ui-review-164-6/frames2/f_214.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_214.png differ diff --git a/.ui-review-164-6/frames2/f_215.png b/.ui-review-164-6/frames2/f_215.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_215.png differ diff --git a/.ui-review-164-6/frames2/f_216.png b/.ui-review-164-6/frames2/f_216.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_216.png differ diff --git a/.ui-review-164-6/frames2/f_217.png b/.ui-review-164-6/frames2/f_217.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_217.png differ diff --git a/.ui-review-164-6/frames2/f_218.png b/.ui-review-164-6/frames2/f_218.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_218.png differ diff --git a/.ui-review-164-6/frames2/f_219.png b/.ui-review-164-6/frames2/f_219.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_219.png differ diff --git a/.ui-review-164-6/frames2/f_220.png b/.ui-review-164-6/frames2/f_220.png new file mode 100644 index 00000000..ead77689 Binary files /dev/null and b/.ui-review-164-6/frames2/f_220.png differ diff --git a/.ui-review-164-6/frames3/f_001.png b/.ui-review-164-6/frames3/f_001.png new file mode 100644 index 00000000..7ed36599 Binary files /dev/null and b/.ui-review-164-6/frames3/f_001.png differ diff --git a/.ui-review-164-6/frames3/f_002.png b/.ui-review-164-6/frames3/f_002.png new file mode 100644 index 00000000..7ed36599 Binary files /dev/null and b/.ui-review-164-6/frames3/f_002.png differ diff --git a/.ui-review-164-6/frames3/f_003.png b/.ui-review-164-6/frames3/f_003.png new file mode 100644 index 00000000..7ed36599 Binary files /dev/null and b/.ui-review-164-6/frames3/f_003.png differ diff --git a/.ui-review-164-6/frames3/f_004.png b/.ui-review-164-6/frames3/f_004.png new file mode 100644 index 00000000..7ed36599 Binary files /dev/null and b/.ui-review-164-6/frames3/f_004.png differ diff --git a/.ui-review-164-6/frames3/f_005.png b/.ui-review-164-6/frames3/f_005.png new file mode 100644 index 00000000..324157da Binary files /dev/null and b/.ui-review-164-6/frames3/f_005.png differ diff --git a/.ui-review-164-6/frames3/f_006.png b/.ui-review-164-6/frames3/f_006.png new file mode 100644 index 00000000..324157da Binary files /dev/null and b/.ui-review-164-6/frames3/f_006.png differ diff --git a/.ui-review-164-6/frames3/f_007.png b/.ui-review-164-6/frames3/f_007.png new file mode 100644 index 00000000..324157da Binary files /dev/null and b/.ui-review-164-6/frames3/f_007.png differ diff --git a/.ui-review-164-6/frames3/f_008.png b/.ui-review-164-6/frames3/f_008.png new file mode 100644 index 00000000..324157da Binary files /dev/null and b/.ui-review-164-6/frames3/f_008.png differ diff --git a/.ui-review-164-6/frames3/f_009.png b/.ui-review-164-6/frames3/f_009.png new file mode 100644 index 00000000..324157da Binary files /dev/null and b/.ui-review-164-6/frames3/f_009.png differ diff --git a/.ui-review-164-6/frames3/f_010.png b/.ui-review-164-6/frames3/f_010.png new file mode 100644 index 00000000..324157da Binary files /dev/null and b/.ui-review-164-6/frames3/f_010.png differ diff --git a/.ui-review-164-6/frames3/f_011.png b/.ui-review-164-6/frames3/f_011.png new file mode 100644 index 00000000..324157da Binary files /dev/null and b/.ui-review-164-6/frames3/f_011.png differ diff --git a/.ui-review-164-6/frames3/f_012.png b/.ui-review-164-6/frames3/f_012.png new file mode 100644 index 00000000..324157da Binary files /dev/null and b/.ui-review-164-6/frames3/f_012.png differ diff --git a/.ui-review-164-6/frames3/f_013.png b/.ui-review-164-6/frames3/f_013.png new file mode 100644 index 00000000..324157da Binary files /dev/null and b/.ui-review-164-6/frames3/f_013.png differ diff --git a/.ui-review-164-6/frames3/f_014.png b/.ui-review-164-6/frames3/f_014.png new file mode 100644 index 00000000..324157da Binary files /dev/null and b/.ui-review-164-6/frames3/f_014.png differ diff --git a/.ui-review-164-6/frames3/f_015.png b/.ui-review-164-6/frames3/f_015.png new file mode 100644 index 00000000..7be4bcc7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_015.png differ diff --git a/.ui-review-164-6/frames3/f_016.png b/.ui-review-164-6/frames3/f_016.png new file mode 100644 index 00000000..7be4bcc7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_016.png differ diff --git a/.ui-review-164-6/frames3/f_017.png b/.ui-review-164-6/frames3/f_017.png new file mode 100644 index 00000000..7be4bcc7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_017.png differ diff --git a/.ui-review-164-6/frames3/f_018.png b/.ui-review-164-6/frames3/f_018.png new file mode 100644 index 00000000..7be4bcc7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_018.png differ diff --git a/.ui-review-164-6/frames3/f_019.png b/.ui-review-164-6/frames3/f_019.png new file mode 100644 index 00000000..7be4bcc7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_019.png differ diff --git a/.ui-review-164-6/frames3/f_020.png b/.ui-review-164-6/frames3/f_020.png new file mode 100644 index 00000000..7be4bcc7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_020.png differ diff --git a/.ui-review-164-6/frames3/f_021.png b/.ui-review-164-6/frames3/f_021.png new file mode 100644 index 00000000..7be4bcc7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_021.png differ diff --git a/.ui-review-164-6/frames3/f_022.png b/.ui-review-164-6/frames3/f_022.png new file mode 100644 index 00000000..7be4bcc7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_022.png differ diff --git a/.ui-review-164-6/frames3/f_023.png b/.ui-review-164-6/frames3/f_023.png new file mode 100644 index 00000000..7be4bcc7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_023.png differ diff --git a/.ui-review-164-6/frames3/f_024.png b/.ui-review-164-6/frames3/f_024.png new file mode 100644 index 00000000..7be4bcc7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_024.png differ diff --git a/.ui-review-164-6/frames3/f_025.png b/.ui-review-164-6/frames3/f_025.png new file mode 100644 index 00000000..f78457a5 Binary files /dev/null and b/.ui-review-164-6/frames3/f_025.png differ diff --git a/.ui-review-164-6/frames3/f_026.png b/.ui-review-164-6/frames3/f_026.png new file mode 100644 index 00000000..f78457a5 Binary files /dev/null and b/.ui-review-164-6/frames3/f_026.png differ diff --git a/.ui-review-164-6/frames3/f_027.png b/.ui-review-164-6/frames3/f_027.png new file mode 100644 index 00000000..f78457a5 Binary files /dev/null and b/.ui-review-164-6/frames3/f_027.png differ diff --git a/.ui-review-164-6/frames3/f_028.png b/.ui-review-164-6/frames3/f_028.png new file mode 100644 index 00000000..f78457a5 Binary files /dev/null and b/.ui-review-164-6/frames3/f_028.png differ diff --git a/.ui-review-164-6/frames3/f_029.png b/.ui-review-164-6/frames3/f_029.png new file mode 100644 index 00000000..f78457a5 Binary files /dev/null and b/.ui-review-164-6/frames3/f_029.png differ diff --git a/.ui-review-164-6/frames3/f_030.png b/.ui-review-164-6/frames3/f_030.png new file mode 100644 index 00000000..f78457a5 Binary files /dev/null and b/.ui-review-164-6/frames3/f_030.png differ diff --git a/.ui-review-164-6/frames3/f_031.png b/.ui-review-164-6/frames3/f_031.png new file mode 100644 index 00000000..f78457a5 Binary files /dev/null and b/.ui-review-164-6/frames3/f_031.png differ diff --git a/.ui-review-164-6/frames3/f_032.png b/.ui-review-164-6/frames3/f_032.png new file mode 100644 index 00000000..f78457a5 Binary files /dev/null and b/.ui-review-164-6/frames3/f_032.png differ diff --git a/.ui-review-164-6/frames3/f_033.png b/.ui-review-164-6/frames3/f_033.png new file mode 100644 index 00000000..f78457a5 Binary files /dev/null and b/.ui-review-164-6/frames3/f_033.png differ diff --git a/.ui-review-164-6/frames3/f_034.png b/.ui-review-164-6/frames3/f_034.png new file mode 100644 index 00000000..f78457a5 Binary files /dev/null and b/.ui-review-164-6/frames3/f_034.png differ diff --git a/.ui-review-164-6/frames3/f_035.png b/.ui-review-164-6/frames3/f_035.png new file mode 100644 index 00000000..4f4c6546 Binary files /dev/null and b/.ui-review-164-6/frames3/f_035.png differ diff --git a/.ui-review-164-6/frames3/f_036.png b/.ui-review-164-6/frames3/f_036.png new file mode 100644 index 00000000..4f4c6546 Binary files /dev/null and b/.ui-review-164-6/frames3/f_036.png differ diff --git a/.ui-review-164-6/frames3/f_037.png b/.ui-review-164-6/frames3/f_037.png new file mode 100644 index 00000000..4f4c6546 Binary files /dev/null and b/.ui-review-164-6/frames3/f_037.png differ diff --git a/.ui-review-164-6/frames3/f_038.png b/.ui-review-164-6/frames3/f_038.png new file mode 100644 index 00000000..4f4c6546 Binary files /dev/null and b/.ui-review-164-6/frames3/f_038.png differ diff --git a/.ui-review-164-6/frames3/f_039.png b/.ui-review-164-6/frames3/f_039.png new file mode 100644 index 00000000..4f4c6546 Binary files /dev/null and b/.ui-review-164-6/frames3/f_039.png differ diff --git a/.ui-review-164-6/frames3/f_040.png b/.ui-review-164-6/frames3/f_040.png new file mode 100644 index 00000000..4f4c6546 Binary files /dev/null and b/.ui-review-164-6/frames3/f_040.png differ diff --git a/.ui-review-164-6/frames3/f_041.png b/.ui-review-164-6/frames3/f_041.png new file mode 100644 index 00000000..4f4c6546 Binary files /dev/null and b/.ui-review-164-6/frames3/f_041.png differ diff --git a/.ui-review-164-6/frames3/f_042.png b/.ui-review-164-6/frames3/f_042.png new file mode 100644 index 00000000..4f4c6546 Binary files /dev/null and b/.ui-review-164-6/frames3/f_042.png differ diff --git a/.ui-review-164-6/frames3/f_043.png b/.ui-review-164-6/frames3/f_043.png new file mode 100644 index 00000000..4f4c6546 Binary files /dev/null and b/.ui-review-164-6/frames3/f_043.png differ diff --git a/.ui-review-164-6/frames3/f_044.png b/.ui-review-164-6/frames3/f_044.png new file mode 100644 index 00000000..4f4c6546 Binary files /dev/null and b/.ui-review-164-6/frames3/f_044.png differ diff --git a/.ui-review-164-6/frames3/f_045.png b/.ui-review-164-6/frames3/f_045.png new file mode 100644 index 00000000..9539d551 Binary files /dev/null and b/.ui-review-164-6/frames3/f_045.png differ diff --git a/.ui-review-164-6/frames3/f_046.png b/.ui-review-164-6/frames3/f_046.png new file mode 100644 index 00000000..9539d551 Binary files /dev/null and b/.ui-review-164-6/frames3/f_046.png differ diff --git a/.ui-review-164-6/frames3/f_047.png b/.ui-review-164-6/frames3/f_047.png new file mode 100644 index 00000000..9539d551 Binary files /dev/null and b/.ui-review-164-6/frames3/f_047.png differ diff --git a/.ui-review-164-6/frames3/f_048.png b/.ui-review-164-6/frames3/f_048.png new file mode 100644 index 00000000..9539d551 Binary files /dev/null and b/.ui-review-164-6/frames3/f_048.png differ diff --git a/.ui-review-164-6/frames3/f_049.png b/.ui-review-164-6/frames3/f_049.png new file mode 100644 index 00000000..9539d551 Binary files /dev/null and b/.ui-review-164-6/frames3/f_049.png differ diff --git a/.ui-review-164-6/frames3/f_050.png b/.ui-review-164-6/frames3/f_050.png new file mode 100644 index 00000000..9539d551 Binary files /dev/null and b/.ui-review-164-6/frames3/f_050.png differ diff --git a/.ui-review-164-6/frames3/f_051.png b/.ui-review-164-6/frames3/f_051.png new file mode 100644 index 00000000..9539d551 Binary files /dev/null and b/.ui-review-164-6/frames3/f_051.png differ diff --git a/.ui-review-164-6/frames3/f_052.png b/.ui-review-164-6/frames3/f_052.png new file mode 100644 index 00000000..9539d551 Binary files /dev/null and b/.ui-review-164-6/frames3/f_052.png differ diff --git a/.ui-review-164-6/frames3/f_053.png b/.ui-review-164-6/frames3/f_053.png new file mode 100644 index 00000000..9539d551 Binary files /dev/null and b/.ui-review-164-6/frames3/f_053.png differ diff --git a/.ui-review-164-6/frames3/f_054.png b/.ui-review-164-6/frames3/f_054.png new file mode 100644 index 00000000..9539d551 Binary files /dev/null and b/.ui-review-164-6/frames3/f_054.png differ diff --git a/.ui-review-164-6/frames3/f_055.png b/.ui-review-164-6/frames3/f_055.png new file mode 100644 index 00000000..0565ad9a Binary files /dev/null and b/.ui-review-164-6/frames3/f_055.png differ diff --git a/.ui-review-164-6/frames3/f_056.png b/.ui-review-164-6/frames3/f_056.png new file mode 100644 index 00000000..6b0e70d9 Binary files /dev/null and b/.ui-review-164-6/frames3/f_056.png differ diff --git a/.ui-review-164-6/frames3/f_057.png b/.ui-review-164-6/frames3/f_057.png new file mode 100644 index 00000000..7add0136 Binary files /dev/null and b/.ui-review-164-6/frames3/f_057.png differ diff --git a/.ui-review-164-6/frames3/f_058.png b/.ui-review-164-6/frames3/f_058.png new file mode 100644 index 00000000..a86ac273 Binary files /dev/null and b/.ui-review-164-6/frames3/f_058.png differ diff --git a/.ui-review-164-6/frames3/f_059.png b/.ui-review-164-6/frames3/f_059.png new file mode 100644 index 00000000..302998f7 Binary files /dev/null and b/.ui-review-164-6/frames3/f_059.png differ diff --git a/.ui-review-164-6/frames3/f_060.png b/.ui-review-164-6/frames3/f_060.png new file mode 100644 index 00000000..b9161e7a Binary files /dev/null and b/.ui-review-164-6/frames3/f_060.png differ diff --git a/.ui-review-164-6/frames3/f_061.png b/.ui-review-164-6/frames3/f_061.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_061.png differ diff --git a/.ui-review-164-6/frames3/f_062.png b/.ui-review-164-6/frames3/f_062.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_062.png differ diff --git a/.ui-review-164-6/frames3/f_063.png b/.ui-review-164-6/frames3/f_063.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_063.png differ diff --git a/.ui-review-164-6/frames3/f_064.png b/.ui-review-164-6/frames3/f_064.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_064.png differ diff --git a/.ui-review-164-6/frames3/f_065.png b/.ui-review-164-6/frames3/f_065.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_065.png differ diff --git a/.ui-review-164-6/frames3/f_066.png b/.ui-review-164-6/frames3/f_066.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_066.png differ diff --git a/.ui-review-164-6/frames3/f_067.png b/.ui-review-164-6/frames3/f_067.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_067.png differ diff --git a/.ui-review-164-6/frames3/f_068.png b/.ui-review-164-6/frames3/f_068.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_068.png differ diff --git a/.ui-review-164-6/frames3/f_069.png b/.ui-review-164-6/frames3/f_069.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_069.png differ diff --git a/.ui-review-164-6/frames3/f_070.png b/.ui-review-164-6/frames3/f_070.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_070.png differ diff --git a/.ui-review-164-6/frames3/f_071.png b/.ui-review-164-6/frames3/f_071.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_071.png differ diff --git a/.ui-review-164-6/frames3/f_072.png b/.ui-review-164-6/frames3/f_072.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_072.png differ diff --git a/.ui-review-164-6/frames3/f_073.png b/.ui-review-164-6/frames3/f_073.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_073.png differ diff --git a/.ui-review-164-6/frames3/f_074.png b/.ui-review-164-6/frames3/f_074.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_074.png differ diff --git a/.ui-review-164-6/frames3/f_075.png b/.ui-review-164-6/frames3/f_075.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_075.png differ diff --git a/.ui-review-164-6/frames3/f_076.png b/.ui-review-164-6/frames3/f_076.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_076.png differ diff --git a/.ui-review-164-6/frames3/f_077.png b/.ui-review-164-6/frames3/f_077.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_077.png differ diff --git a/.ui-review-164-6/frames3/f_078.png b/.ui-review-164-6/frames3/f_078.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_078.png differ diff --git a/.ui-review-164-6/frames3/f_079.png b/.ui-review-164-6/frames3/f_079.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_079.png differ diff --git a/.ui-review-164-6/frames3/f_080.png b/.ui-review-164-6/frames3/f_080.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_080.png differ diff --git a/.ui-review-164-6/frames3/f_081.png b/.ui-review-164-6/frames3/f_081.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_081.png differ diff --git a/.ui-review-164-6/frames3/f_082.png b/.ui-review-164-6/frames3/f_082.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_082.png differ diff --git a/.ui-review-164-6/frames3/f_083.png b/.ui-review-164-6/frames3/f_083.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_083.png differ diff --git a/.ui-review-164-6/frames3/f_084.png b/.ui-review-164-6/frames3/f_084.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_084.png differ diff --git a/.ui-review-164-6/frames3/f_085.png b/.ui-review-164-6/frames3/f_085.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_085.png differ diff --git a/.ui-review-164-6/frames3/f_086.png b/.ui-review-164-6/frames3/f_086.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_086.png differ diff --git a/.ui-review-164-6/frames3/f_087.png b/.ui-review-164-6/frames3/f_087.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_087.png differ diff --git a/.ui-review-164-6/frames3/f_088.png b/.ui-review-164-6/frames3/f_088.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_088.png differ diff --git a/.ui-review-164-6/frames3/f_089.png b/.ui-review-164-6/frames3/f_089.png new file mode 100644 index 00000000..0a928c8a Binary files /dev/null and b/.ui-review-164-6/frames3/f_089.png differ diff --git a/.ui-review-164-6/frames3/f_090.png b/.ui-review-164-6/frames3/f_090.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_090.png differ diff --git a/.ui-review-164-6/frames3/f_091.png b/.ui-review-164-6/frames3/f_091.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_091.png differ diff --git a/.ui-review-164-6/frames3/f_092.png b/.ui-review-164-6/frames3/f_092.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_092.png differ diff --git a/.ui-review-164-6/frames3/f_093.png b/.ui-review-164-6/frames3/f_093.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_093.png differ diff --git a/.ui-review-164-6/frames3/f_094.png b/.ui-review-164-6/frames3/f_094.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_094.png differ diff --git a/.ui-review-164-6/frames3/f_095.png b/.ui-review-164-6/frames3/f_095.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_095.png differ diff --git a/.ui-review-164-6/frames3/f_096.png b/.ui-review-164-6/frames3/f_096.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_096.png differ diff --git a/.ui-review-164-6/frames3/f_097.png b/.ui-review-164-6/frames3/f_097.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_097.png differ diff --git a/.ui-review-164-6/frames3/f_098.png b/.ui-review-164-6/frames3/f_098.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_098.png differ diff --git a/.ui-review-164-6/frames3/f_099.png b/.ui-review-164-6/frames3/f_099.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_099.png differ diff --git a/.ui-review-164-6/frames3/f_100.png b/.ui-review-164-6/frames3/f_100.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_100.png differ diff --git a/.ui-review-164-6/frames3/f_101.png b/.ui-review-164-6/frames3/f_101.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_101.png differ diff --git a/.ui-review-164-6/frames3/f_102.png b/.ui-review-164-6/frames3/f_102.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_102.png differ diff --git a/.ui-review-164-6/frames3/f_103.png b/.ui-review-164-6/frames3/f_103.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_103.png differ diff --git a/.ui-review-164-6/frames3/f_104.png b/.ui-review-164-6/frames3/f_104.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_104.png differ diff --git a/.ui-review-164-6/frames3/f_105.png b/.ui-review-164-6/frames3/f_105.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_105.png differ diff --git a/.ui-review-164-6/frames3/f_106.png b/.ui-review-164-6/frames3/f_106.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_106.png differ diff --git a/.ui-review-164-6/frames3/f_107.png b/.ui-review-164-6/frames3/f_107.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_107.png differ diff --git a/.ui-review-164-6/frames3/f_108.png b/.ui-review-164-6/frames3/f_108.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_108.png differ diff --git a/.ui-review-164-6/frames3/f_109.png b/.ui-review-164-6/frames3/f_109.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_109.png differ diff --git a/.ui-review-164-6/frames3/f_110.png b/.ui-review-164-6/frames3/f_110.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_110.png differ diff --git a/.ui-review-164-6/frames3/f_111.png b/.ui-review-164-6/frames3/f_111.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_111.png differ diff --git a/.ui-review-164-6/frames3/f_112.png b/.ui-review-164-6/frames3/f_112.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_112.png differ diff --git a/.ui-review-164-6/frames3/f_113.png b/.ui-review-164-6/frames3/f_113.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_113.png differ diff --git a/.ui-review-164-6/frames3/f_114.png b/.ui-review-164-6/frames3/f_114.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_114.png differ diff --git a/.ui-review-164-6/frames3/f_115.png b/.ui-review-164-6/frames3/f_115.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_115.png differ diff --git a/.ui-review-164-6/frames3/f_116.png b/.ui-review-164-6/frames3/f_116.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_116.png differ diff --git a/.ui-review-164-6/frames3/f_117.png b/.ui-review-164-6/frames3/f_117.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_117.png differ diff --git a/.ui-review-164-6/frames3/f_118.png b/.ui-review-164-6/frames3/f_118.png new file mode 100644 index 00000000..7b48f6cd Binary files /dev/null and b/.ui-review-164-6/frames3/f_118.png differ diff --git a/.ui-review-164-6/morph-9proxl.mp4 b/.ui-review-164-6/morph-9proxl.mp4 new file mode 100644 index 00000000..835545ef Binary files /dev/null and b/.ui-review-164-6/morph-9proxl.mp4 differ diff --git a/.ui-review-164-6/morph.mp4 b/.ui-review-164-6/morph.mp4 new file mode 100644 index 00000000..64898556 Binary files /dev/null and b/.ui-review-164-6/morph.mp4 differ diff --git a/.ui-review-164-6/morph3.mp4 b/.ui-review-164-6/morph3.mp4 new file mode 100644 index 00000000..12f8a2a4 Binary files /dev/null and b/.ui-review-164-6/morph3.mp4 differ diff --git a/.ui-review-164-6/pxl-conn.png b/.ui-review-164-6/pxl-conn.png new file mode 100644 index 00000000..528bd043 Binary files /dev/null and b/.ui-review-164-6/pxl-conn.png differ diff --git a/.ui-review-164-6/pxl-conn.xml b/.ui-review-164-6/pxl-conn.xml new file mode 100644 index 00000000..c6fe77df --- /dev/null +++ b/.ui-review-164-6/pxl-conn.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/pxl-now.png b/.ui-review-164-6/pxl-now.png new file mode 100644 index 00000000..528bd043 Binary files /dev/null and b/.ui-review-164-6/pxl-now.png differ diff --git a/.ui-review-164-6/pxl-now.xml b/.ui-review-164-6/pxl-now.xml new file mode 100644 index 00000000..c6fe77df --- /dev/null +++ b/.ui-review-164-6/pxl-now.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/pxl-retry.png b/.ui-review-164-6/pxl-retry.png new file mode 100644 index 00000000..02753ae4 Binary files /dev/null and b/.ui-review-164-6/pxl-retry.png differ diff --git a/.ui-review-164-6/pxl-retry.xml b/.ui-review-164-6/pxl-retry.xml new file mode 100644 index 00000000..c6fe77df --- /dev/null +++ b/.ui-review-164-6/pxl-retry.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/pxl-start.png b/.ui-review-164-6/pxl-start.png new file mode 100644 index 00000000..fdac5378 Binary files /dev/null and b/.ui-review-164-6/pxl-start.png differ diff --git a/.ui-review-164-6/pxl-start.xml b/.ui-review-164-6/pxl-start.xml new file mode 100644 index 00000000..c6fe77df --- /dev/null +++ b/.ui-review-164-6/pxl-start.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/ui_lock.xml b/.ui-review-164-6/ui_lock.xml new file mode 100644 index 00000000..3cad96e7 --- /dev/null +++ b/.ui-review-164-6/ui_lock.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/ui_lock2.xml b/.ui-review-164-6/ui_lock2.xml new file mode 100644 index 00000000..3cad96e7 --- /dev/null +++ b/.ui-review-164-6/ui_lock2.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/ul3.xml b/.ui-review-164-6/ul3.xml new file mode 100644 index 00000000..3cad96e7 --- /dev/null +++ b/.ui-review-164-6/ul3.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-164-6/ul4.xml b/.ui-review-164-6/ul4.xml new file mode 100644 index 00000000..542135ed --- /dev/null +++ b/.ui-review-164-6/ul4.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/.ui-review-184-3/00-launch.png b/.ui-review-184-3/00-launch.png new file mode 100644 index 00000000..9bf7ba7f Binary files /dev/null and b/.ui-review-184-3/00-launch.png differ diff --git a/.ui-review-184-3/01-open.png b/.ui-review-184-3/01-open.png new file mode 100644 index 00000000..940652b9 Binary files /dev/null and b/.ui-review-184-3/01-open.png differ diff --git a/.ui-review-184-3/02-restored.png b/.ui-review-184-3/02-restored.png new file mode 100644 index 00000000..5570b979 Binary files /dev/null and b/.ui-review-184-3/02-restored.png differ diff --git a/.ui-review-184-3/03-after-2nd-back.png b/.ui-review-184-3/03-after-2nd-back.png new file mode 100644 index 00000000..4183eb04 Binary files /dev/null and b/.ui-review-184-3/03-after-2nd-back.png differ diff --git a/.ui-review-184-3/04-open-again.png b/.ui-review-184-3/04-open-again.png new file mode 100644 index 00000000..9ac2d2ae Binary files /dev/null and b/.ui-review-184-3/04-open-again.png differ diff --git a/.ui-review-184-3/05-after-scrim-tap.png b/.ui-review-184-3/05-after-scrim-tap.png new file mode 100644 index 00000000..42bfd317 Binary files /dev/null and b/.ui-review-184-3/05-after-scrim-tap.png differ diff --git a/.ui-review-184-3/06-results.png b/.ui-review-184-3/06-results.png new file mode 100644 index 00000000..8c7be7e1 Binary files /dev/null and b/.ui-review-184-3/06-results.png differ diff --git a/.ui-review-184-3/07-empty.png b/.ui-review-184-3/07-empty.png new file mode 100644 index 00000000..a69fae7c Binary files /dev/null and b/.ui-review-184-3/07-empty.png differ diff --git a/.ui-review-184-3/10-wide-pill.png b/.ui-review-184-3/10-wide-pill.png new file mode 100644 index 00000000..a310ced5 Binary files /dev/null and b/.ui-review-184-3/10-wide-pill.png differ diff --git a/.ui-review-184-3/11-wide-open.png b/.ui-review-184-3/11-wide-open.png new file mode 100644 index 00000000..14655063 Binary files /dev/null and b/.ui-review-184-3/11-wide-open.png differ diff --git a/.ui-review-184-3/20-runs-selected.png b/.ui-review-184-3/20-runs-selected.png new file mode 100644 index 00000000..4b32b39c Binary files /dev/null and b/.ui-review-184-3/20-runs-selected.png differ diff --git a/.ui-review-184-3/21-runs-restored-after-search.png b/.ui-review-184-3/21-runs-restored-after-search.png new file mode 100644 index 00000000..6b2d913c Binary files /dev/null and b/.ui-review-184-3/21-runs-restored-after-search.png differ diff --git a/.ui-review-186-3/186-00-launch.png b/.ui-review-186-3/186-00-launch.png new file mode 100644 index 00000000..96acff2c Binary files /dev/null and b/.ui-review-186-3/186-00-launch.png differ diff --git a/.ui-review-186-3/186-01-open.png b/.ui-review-186-3/186-01-open.png new file mode 100644 index 00000000..68a7c946 Binary files /dev/null and b/.ui-review-186-3/186-01-open.png differ diff --git a/.ui-review-186-3/186-02-results.png b/.ui-review-186-3/186-02-results.png new file mode 100644 index 00000000..80c65317 Binary files /dev/null and b/.ui-review-186-3/186-02-results.png differ diff --git a/.ui-review-186-3/186-03-selected-run.png b/.ui-review-186-3/186-03-selected-run.png new file mode 100644 index 00000000..4fa52be9 Binary files /dev/null and b/.ui-review-186-3/186-03-selected-run.png differ diff --git a/.ui-review-186-3/186-04-empty.png b/.ui-review-186-3/186-04-empty.png new file mode 100644 index 00000000..2cc2ddb6 Binary files /dev/null and b/.ui-review-186-3/186-04-empty.png differ diff --git a/.ui-review-186-3/186-05-empty.png b/.ui-review-186-3/186-05-empty.png new file mode 100644 index 00000000..db1d0b1f Binary files /dev/null and b/.ui-review-186-3/186-05-empty.png differ diff --git a/.ui-review-186-3/186-05a-reopened.png b/.ui-review-186-3/186-05a-reopened.png new file mode 100644 index 00000000..162d9dd6 Binary files /dev/null and b/.ui-review-186-3/186-05a-reopened.png differ diff --git a/.ui-review-186-3/186-06-empty.png b/.ui-review-186-3/186-06-empty.png new file mode 100644 index 00000000..8070fabf Binary files /dev/null and b/.ui-review-186-3/186-06-empty.png differ diff --git a/.ui-review-186-3/186-07-wide-list.png b/.ui-review-186-3/186-07-wide-list.png new file mode 100644 index 00000000..297bed55 Binary files /dev/null and b/.ui-review-186-3/186-07-wide-list.png differ diff --git a/.ui-review-186-3/186-08-wide-results.png b/.ui-review-186-3/186-08-wide-results.png new file mode 100644 index 00000000..9da0fc5b Binary files /dev/null and b/.ui-review-186-3/186-08-wide-results.png differ diff --git a/.ui-review-186-3/186-09-wide-results.png b/.ui-review-186-3/186-09-wide-results.png new file mode 100644 index 00000000..9da0fc5b Binary files /dev/null and b/.ui-review-186-3/186-09-wide-results.png differ diff --git a/.ui-review-186-3/186-10-maybe-loading.png b/.ui-review-186-3/186-10-maybe-loading.png new file mode 100644 index 00000000..79774812 Binary files /dev/null and b/.ui-review-186-3/186-10-maybe-loading.png differ diff --git a/.ui-review-186-3/186-11-pipeline-results.png b/.ui-review-186-3/186-11-pipeline-results.png new file mode 100644 index 00000000..c8270503 Binary files /dev/null and b/.ui-review-186-3/186-11-pipeline-results.png differ diff --git a/.ui-review-186-3/crop-186-02-result-rows.png b/.ui-review-186-3/crop-186-02-result-rows.png new file mode 100644 index 00000000..c9a38bfc Binary files /dev/null and b/.ui-review-186-3/crop-186-02-result-rows.png differ diff --git a/.ui-review-186-3/crop-186-04-match-rows.png b/.ui-review-186-3/crop-186-04-match-rows.png new file mode 100644 index 00000000..ef15a0cb Binary files /dev/null and b/.ui-review-186-3/crop-186-04-match-rows.png differ diff --git a/.ui-review-186-3/crop-186-06-empty-state.png b/.ui-review-186-3/crop-186-06-empty-state.png new file mode 100644 index 00000000..db59d078 Binary files /dev/null and b/.ui-review-186-3/crop-186-06-empty-state.png differ diff --git a/.ui-review-186-3/dbg.png b/.ui-review-186-3/dbg.png new file mode 100644 index 00000000..11bb59b1 Binary files /dev/null and b/.ui-review-186-3/dbg.png differ diff --git a/.ui-review-86-3/live-current-86-3.png b/.ui-review-86-3/live-current-86-3.png new file mode 100644 index 00000000..8e17a266 Binary files /dev/null and b/.ui-review-86-3/live-current-86-3.png differ diff --git a/.ui-review-86-3/review-current.png b/.ui-review-86-3/review-current.png new file mode 100644 index 00000000..20d17738 Binary files /dev/null and b/.ui-review-86-3/review-current.png differ diff --git a/.ui-review-86-3/review-stage-pane-narrow.png b/.ui-review-86-3/review-stage-pane-narrow.png new file mode 100644 index 00000000..071071f8 Binary files /dev/null and b/.ui-review-86-3/review-stage-pane-narrow.png differ diff --git a/.ui-review-86-3/review-stage-pane-wide.png b/.ui-review-86-3/review-stage-pane-wide.png new file mode 100644 index 00000000..23838002 Binary files /dev/null and b/.ui-review-86-3/review-stage-pane-wide.png differ diff --git a/.ui-review-86-3/safe-area-narrow-stage-pane.png b/.ui-review-86-3/safe-area-narrow-stage-pane.png new file mode 100644 index 00000000..2d64439e Binary files /dev/null and b/.ui-review-86-3/safe-area-narrow-stage-pane.png differ diff --git a/.ui-review-86-3/safe-area-wide-banner-owns-top.png b/.ui-review-86-3/safe-area-wide-banner-owns-top.png new file mode 100644 index 00000000..68cf31df Binary files /dev/null and b/.ui-review-86-3/safe-area-wide-banner-owns-top.png differ diff --git a/.ui-review-86-3/safe-area-wide-ime-open.png b/.ui-review-86-3/safe-area-wide-ime-open.png new file mode 100644 index 00000000..1d5c3640 Binary files /dev/null and b/.ui-review-86-3/safe-area-wide-ime-open.png differ diff --git a/.ui-review-86-3/safe-area-wide-ime-scrolled.png b/.ui-review-86-3/safe-area-wide-ime-scrolled.png new file mode 100644 index 00000000..00d9e2c4 Binary files /dev/null and b/.ui-review-86-3/safe-area-wide-ime-scrolled.png differ diff --git a/.ui-review-86-3/safe-area-wide-stage-pane.png b/.ui-review-86-3/safe-area-wide-stage-pane.png new file mode 100644 index 00000000..0ae518a5 Binary files /dev/null and b/.ui-review-86-3/safe-area-wide-stage-pane.png differ diff --git a/.ui-review-run77/pane-opaque-narrow-over-graph.png b/.ui-review-run77/pane-opaque-narrow-over-graph.png new file mode 100644 index 00000000..2c58e528 Binary files /dev/null and b/.ui-review-run77/pane-opaque-narrow-over-graph.png differ diff --git a/.ui-review-run77/pane-opaque-narrow-over-timeline.png b/.ui-review-run77/pane-opaque-narrow-over-timeline.png new file mode 100644 index 00000000..bc88aa79 Binary files /dev/null and b/.ui-review-run77/pane-opaque-narrow-over-timeline.png differ diff --git a/.ui-review-run77/pane-opaque-wide-over-graph.png b/.ui-review-run77/pane-opaque-wide-over-graph.png new file mode 100644 index 00000000..118a0a47 Binary files /dev/null and b/.ui-review-run77/pane-opaque-wide-over-graph.png differ diff --git a/.ui-review-run77/pane-opaque-wide-over-timeline.png b/.ui-review-run77/pane-opaque-wide-over-timeline.png new file mode 100644 index 00000000..118a0a47 Binary files /dev/null and b/.ui-review-run77/pane-opaque-wide-over-timeline.png differ diff --git a/.ui-review-tmp/installed-base.apk b/.ui-review-tmp/installed-base.apk new file mode 100644 index 00000000..3f4e1920 Binary files /dev/null and b/.ui-review-tmp/installed-base.apk differ diff --git a/.ui-review-tmp/live-pane-input-expanded-wide.png b/.ui-review-tmp/live-pane-input-expanded-wide.png new file mode 100644 index 00000000..c4227eb4 Binary files /dev/null and b/.ui-review-tmp/live-pane-input-expanded-wide.png differ diff --git a/.ui-review-tmp/live-pane-stuck-header-wide.png b/.ui-review-tmp/live-pane-stuck-header-wide.png new file mode 100644 index 00000000..4733d356 Binary files /dev/null and b/.ui-review-tmp/live-pane-stuck-header-wide.png differ diff --git a/.ui-review-tmp/pane-opaque-narrow-over-graph.png b/.ui-review-tmp/pane-opaque-narrow-over-graph.png new file mode 100644 index 00000000..b7ff27c3 Binary files /dev/null and b/.ui-review-tmp/pane-opaque-narrow-over-graph.png differ diff --git a/.ui-review-tmp/pane-opaque-narrow-over-running-graph.png b/.ui-review-tmp/pane-opaque-narrow-over-running-graph.png new file mode 100644 index 00000000..59b5f7dd Binary files /dev/null and b/.ui-review-tmp/pane-opaque-narrow-over-running-graph.png differ diff --git a/.ui-review-tmp/pane-opaque-narrow-over-timeline.png b/.ui-review-tmp/pane-opaque-narrow-over-timeline.png new file mode 100644 index 00000000..4758bffd Binary files /dev/null and b/.ui-review-tmp/pane-opaque-narrow-over-timeline.png differ diff --git a/.ui-review-tmp/pane-opaque-wide-over-graph.png b/.ui-review-tmp/pane-opaque-wide-over-graph.png new file mode 100644 index 00000000..1ff0c45e Binary files /dev/null and b/.ui-review-tmp/pane-opaque-wide-over-graph.png differ diff --git a/.ui-review-tmp/pane-opaque-wide-over-timeline.png b/.ui-review-tmp/pane-opaque-wide-over-timeline.png new file mode 100644 index 00000000..73b0969a Binary files /dev/null and b/.ui-review-tmp/pane-opaque-wide-over-timeline.png differ diff --git a/.ui-review-tmp/r825/before-after-pipeline-pop.png b/.ui-review-tmp/r825/before-after-pipeline-pop.png new file mode 100644 index 00000000..3a738974 Binary files /dev/null and b/.ui-review-tmp/r825/before-after-pipeline-pop.png differ diff --git a/README.md b/README.md index 693e69e8..50fec222 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,10 @@ cd pipelines Native setup reuses your existing host OpenCode login and never installs, upgrades or downloads OpenCode/Pi. It writes host harness profiles (no Docker link) for the harnesses it detects, so authoring works immediately, and clears a -stale Docker link when migrating a Docker install. Start it with +stale Docker link when migrating a Docker install. After building, it warns if a +**different** `pipelines` resolves earlier on PATH than `/bin/pipelines`, +naming that path and both versions, so a stale CLI is not left in front of a newer +server (it never modifies or upgrades that other binary). Start it with `PIPELINES_PREFIX=~/.local/share/pipelines ~/.local/share/pipelines/bin/pipelines start`. When Docker volumes are present it migrates the existing database and ntfy auth store (never overwriting newer native data; use `--replace-data` to opt in). See @@ -93,7 +96,9 @@ Prefer the installer-saved configured endpoint when present; never replace it wi a guessed default. Go uses `GOBIN` or its normal `GOPATH/bin` default; put that directory on PATH. -The Docker installer automatically detects/configures LAN networking for ntfy; +Running `pipelines` also compares its build/protocol with the server and warns (or +fails on a newer protocol) instead of dropping fields it does not model. The +Docker installer automatically detects/configures LAN networking for ntfy; you do not need to look up your IP or supply a URL/listen address. Both Docker services bind `0.0.0.0`; reinstall normalizes those bind settings without replacing your URLs, timezone, ports or credentials. @@ -205,8 +210,11 @@ pipelines retry requires confirmation and restarts the pinned workflow, so earlier side effects may happen again. -Home shows only **/** search and **:** commands as action hints; use the command -palette for creation, drafts, templates, history, status, logs, and quitting. +Home shows only **/** search and **:** commands as action hints; **/** opens the omni +popup, which finds pipelines, versions, runs, stages/visits, artifact names and the +text of stage inputs, outputs and evidence, and Enter opens the chosen result. Use +the command palette for creation, drafts, templates, history, status, logs, and +quitting. Quit with **:quit**; **q** does not exit. For a terminal-only run after publication: @@ -344,8 +352,22 @@ Retries restart at the entry stage with fresh OpenCode sessions, never the previ conversation or intermediate stage output. Pipelines does not automatically delete generation, agent, or formatting-repair sessions, including on failure/cancellation. Primary session IDs are retained in run steps (`pipelines inspect --json`). -On Home, **r** opens global run history; **/** fuzzy-searches it. Inside a pipeline, -**r** / **:runs** opens only that pipeline's history. +Every run also records a short, single-line title: `pipelines run ... --title "…"` +sets one explicitly, otherwise it is generated from the prompt. `pipelines runs` +and `pipelines inspect` show it beside the pipeline name and version, and +`pipelines title "…"` renames it afterwards. +A pipeline may include a `type=human` decision stage: the run pauses as +**waiting** with the stage's instructions and options visible in `inspect` and the +run inspector. Answer it with `pipelines decide [stage] --option KEY +[--feedback "…"]` or by pressing **c** in the run inspector to pick an option and +type feedback. The choice and feedback are recorded as the step's evidence and the +run resumes along that edge. The wait is persisted, so it survives a server +restart; an unknown option is refused with the valid list, a stage that is not +waiting is refused, and a repeated decision does not double-apply. **cancel** and +**retry** keep working while waiting and after a decision. +On Home, **r** opens global run history; **/** opens the omni search popup over +pipelines, versions, runs, stages/visits, artifacts and stage input/output/evidence +text. Inside a pipeline, **r** / **:runs** opens only that pipeline's history. Quit the TUI with **:quit**; **q** does not exit. **Ctrl+C** remains an interrupt. Starting/retrying/canceling runs and deleting drafts require confirmation. CLI publication also prompts; use `--yes` only for explicitly approved automation. diff --git a/cmd/pipelines-server/main.go b/cmd/pipelines-server/main.go index 1d2e4408..97d50a4e 100644 --- a/cmd/pipelines-server/main.go +++ b/cmd/pipelines-server/main.go @@ -16,6 +16,7 @@ import ( "git.a-wan.net/alan/pipelines/internal/paths" "git.a-wan.net/alan/pipelines/internal/pipeline" "git.a-wan.net/alan/pipelines/internal/server" + "git.a-wan.net/alan/pipelines/internal/summarise" ) func main() { @@ -37,7 +38,10 @@ func main() { ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer stop() artifactsRoot := filepath.Join(filepath.Dir(*db), "artifacts") - options := server.Options{ArtifactsRoot: artifactsRoot} + // Each new run gets a bounded one-line title from the configured default + // harness; the summariser falls back to the prompt's first line, so title + // generation never blocks or fails run creation. + options := server.Options{ArtifactsRoot: artifactsRoot, RunTitles: summarise.GenerateTitle, StepVerdicts: summarise.GenerateVerdictReason} // Chat brokers OpenCode over the owned endpoint. Streaming needs a // URL-bearing, SSE-capable backend. Detect may select "v2" (the CLI // advertises `api`), but Open never starts a serve process for v2 and so diff --git a/docs/cli.md b/docs/cli.md index 3fbabfd3..35d489dd 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -23,10 +23,23 @@ running server's compiled `build.version`, full Git `build.commit`, and `build.dirty`. Uncommitted builds have a `-dirty` suffix. Missing metadata is explicit (`commit: "unknown"`, `dirty: null`); older servers omit `build`. This identifies the server binary, not the CLI or files mounted into the container. -Plain `ping` also prints the server version/commit. `pipelines version --json` +Plain `ping` also prints the server version/commit and, beside the local client +build, the client/server relationship. `pipelines version --json` (or `pipelines --version`) identifies the local client without connecting to a server. Include both identities when reporting a problem; they can differ. +`ping`, `connection`, `status` and every server command now check that relationship. +The server stamps its `build` and integer `protocol` onto each response (the +unsolicited welcome envelope too). The client compares this build against the +server: a same-protocol build mismatch prints exactly one `warning:` on stderr +(stdout JSON stays parseable) and a server speaking a newer protocol fails the +command non-zero before it acts on the frame. If a response carries a top-level +field this client does not model — for example an `artifacts` field from a newer +server — the client prints a one-time `server sent unrecognized top-level field(s) +...` notice instead of silently appearing to have no data. Rebuild or reinstall the +CLI so it matches the server; the installer also warns when a different `pipelines` +resolves earlier on PATH than the freshly installed binary. + Home's `r` opens **all** runs, not only failures or the newest 50. Inside a pipeline, `r` and `:runs` show only that pipeline's runs across its versions. In any run list, @@ -34,6 +47,14 @@ press `/` for fuzzy search, type to filter, and Enter to return to the results. Search includes pipeline name, version, status, outcome, stage and diagnostic; `#123` searches run-ID prefixes. Esc while searching clears the filter without closing the list. The filter survives inspection/back and live list refreshes. +Home's `/` instead opens the omni popup, which searches pipelines, versions, runs, +stages/visits, artifact names, and the text of stage inputs, outputs and evidence. +A bare status word (`queued`, `running`, `succeeded`, `failed`, `canceled`, +`interrupted`) or a date (`today`, `yesterday`, `this week`, or `YYYY-MM-DD` +interpreted in UTC) selects runs, and a leading `pipeline:`/`version:`/`run:`/ +`step:`/`field:`/`artifact:`/`match:` prefix narrows the result kind. Enter opens +the matched pipeline, run, stage visit, artifact or field; unrecognised words +remain text. Wide terminals show runs and pipelines side by side, with stacked panels on narrow terminals. Home run cards prioritize reported results, status, completed visits and duration; @@ -235,8 +256,10 @@ Submitting activates included schedules, so review them before publishing. | Browse templates/source | `templates --json`, `template KEY --source` | | Create or edit a definition | `new`, `edit`, `drafts` | | Validate and publish | `validate FILE`, `submit FILE` | -| Start a run | `run NAME PROMPT --yes --json` | +| Start a run | `run NAME PROMPT [--title TITLE] --yes --json` | | Run history/inspection | `runs --json`, `inspect ID --json` | +| Rename a run | `title ID "TITLE" --json` | +| Decide a waiting human stage | `decide ID [STAGE] --option KEY [--feedback TEXT] --json` | | Cancel | `cancel ID --json` | | Connection and phone settings | `connection --json`, `ping --json` | | Server/ntfy status popup | `status --json` | @@ -254,14 +277,28 @@ printf '%s' '{"type":"get_pipeline","pipeline_id":1,"version":1}' | pipelines rp Existing protocol commands: `ping`, `list_pipelines`, `get_pipeline`, `list_templates`, `validate`, `submit`, `run_pipeline`, `list_runs`, `get_run`, -`cancel_run`, `retry_run`, `get_status`, `search`. `list_runs` also returns -all-history `usage` aggregates. See `internal/protocol/message.go` for JSON -envelopes. Mutating RPCs have real effects; they are not previews. TUI-only -animation, scrolling, and transient client logs are presentation, not separate -server capabilities. +`cancel_run`, `retry_run`, `decide_run`, `set_run_title`, `get_run_evidence`, +`get_status`, `search`. `search` takes `query` and an +optional `kind` and `limit` and returns ranked typed `matches`, each with a stable +`target` the client can open. `list_runs` also returns all-history `usage` +aggregates. See `internal/protocol/message.go` for JSON envelopes. Mutating RPCs +have real effects; they are not previews. TUI-only animation, scrolling, and +transient client logs are presentation, not separate server capabilities. ## Scripted runs +Every run records a short, single-line `title` saying what it was for. `pipelines +run --title "..."` sets it explicitly; otherwise the server generates it from the +prompt with the configured default harness. It is never empty: when generation is +unavailable or times out, the server derives the prompt's first line, and +`title_source` (`model`, `fallback`, or `explicit` for an operator-set title) plus +`title_model` record how it was produced so a diagnosis can tell them apart. +`pipelines runs` shows the title beside the pipeline name and version, and +`pipelines inspect` returns the title, name and version, so two runs of one +pipeline are distinguishable. Rename after the fact with `pipelines title + ""`; the run's input, steps and execution are unchanged. The +stored prompt is unchanged, and listing/renaming never calls a model. + On either the runs list or run inspector, press `P` (or use `:pipeline`) to open the selected run's exact pipeline version. Navigation does not cancel the run. @@ -282,6 +319,21 @@ Retry is hidden and rejected while a run is executing or agent cleanup remains active, even if a terminal status was already persisted. Run RPCs report `executing` alongside status so clients can distinguish cleanup from completion. +A pipeline may contain a `type=human` decision stage (see the authoring skill's +`references/format.md`). Its step becomes `waiting`, the run reports that it is +waiting on a person, and no later stage runs. `runs`/`inspect --json` show the +`waiting` status, the stage and its recorded instructions and options. Answer it +with `pipelines decide <run-id> [stage] --option KEY [--feedback TEXT] [--json]` +or, in the run inspector, press `c` to open the option picker, choose with +`↑/↓`, type optional feedback with `Tab`, and confirm with Enter. The choice and +feedback are recorded as the step's evidence and the run resumes along +`edges[KEY]`. An unknown option is refused with the valid list, a decision to a +stage that is not waiting is refused, and a repeated decision for an +already-decided visit does not double-apply. The wait is persisted in the run +rows, so it survives a server restart and `decide` still works afterwards; +`cancel` and `retry` keep working while waiting and after a decision, and a +human stage is never killed by a stage timeout or `max_visits`. + The run inspector's upper half shows the entire graph from the run's immutable pinned version using the shared renderer and viewport. Executed stages and taken routes retain their colors; unexecuted stages, unchosen routes and unreached diff --git a/docs/install.md b/docs/install.md index 4430c82d..bc0e3476 100644 --- a/docs/install.md +++ b/docs/install.md @@ -36,6 +36,14 @@ manifest is what `scripts/manage.py` and the Go CLI load. Provider/model default are never invented: your existing host OpenCode configuration is reused (an explicit `--model` is recorded if supplied), and setup never starts a picker. +After the build, setup checks whether a **different** `pipelines` resolves earlier +on PATH than `<prefix>/bin/pipelines` (the common cause of a stale CLI talking to a +newer server). When it does, setup prints a `WARNING` naming that absolute path and +both versions (`version --json` on each binary, read-only) and tells you to put +`<prefix>/bin` first on PATH. It never modifies, moves, deletes or upgrades that +other binary, and it installs no unrelated tool; the manifest keeps +`<prefix>/bin` first on the recorded PATH. + The native install also writes **host** harness profiles for the harnesses it detects into XDG config home's `pipelines/harnesses.json` (no `docker_directory`), defaulting to the detected OpenCode profile rather than a diff --git a/docs/model-results.md b/docs/model-results.md index 93e62ba7..576d6b65 100644 --- a/docs/model-results.md +++ b/docs/model-results.md @@ -23,6 +23,45 @@ is not evidence of a real tool invocation and cannot be accepted as a result. Flattened output fields are rejected, not guessed into a new envelope. Invalid responses are retained even when they are not eligible for syntax repair. +## Line-oriented result format + +Model and agent stages also accept a line-oriented result format. The response is +a markdown-ish document whose first non-empty line is the outcome, followed by +sections introduced with `# <heading>`. + +``` +success + +# output +{"task": "x"} + +# findings +- prose, code fences, quotes and embedded JSON need no escaping +``` + +Only the first non-empty line and a `# output` section are required. The body of +`# output` must be a JSON object; it becomes the stage's `output` map. Every other +heading becomes an evidence field keyed by the normalised heading text (lowercased, +spaces to underscores). Extra sections are stored verbatim and are best-effort: an +empty heading, an odd heading, or a very large section must never fail the stage. +If the outcome is missing, not one of the declared edges, or `# output` is absent, +the stage fails with `FINAL RESULT VALIDATION` and still retains whatever sections +were salvaged. + +The parser decides between the legacy JSON envelope and the line-oriented format by +precedence. If the response's first non-empty character is `{` after stripping an +optional surrounding markdown fence, it keeps the unchanged JSON path. If a `# ` +heading appears before any `{`, it uses the line-oriented path. This preserves all +existing JSON responses, including fenced JSON or short prose prefixes, while +allowing new line-format responses to coexist. + +The full raw response is written to the stage's artifacts directory as +`raw-output.md` before parsing, so the closest record of what the model produced is +always retained and appears in the step's artifact inventory automatically. The +parse status is recorded in the step's output map under the reserved key +`result_parse`: `parsed` (both required parts OK), `partial` (required parts OK but +some extra section unusable), or `failed` (a required part missing or invalid). + ## Format recovery is not execution retry Parser errors retain their diagnostic and byte offset: for example, `missing diff --git a/internal/author/skill/references/debugging.md b/internal/author/skill/references/debugging.md index 3f699106..35f5e398 100644 --- a/internal/author/skill/references/debugging.md +++ b/internal/author/skill/references/debugging.md @@ -2,10 +2,15 @@ Debug from **retained evidence**, never from an agent's summary. Open the run with `CLI_PREFIX inspect RUN_ID --json` and read the exact stage outputs, outcomes, -diagnostics, file changes and artifacts. Identify evidence-supported causes and say -what remains unknown. Never fix a run's symptom by editing the project by hand: fix -the pipeline definition or the Pipelines/harness service, or record the failure and -continue. +diagnostics, file changes and artifacts. Each completed step also carries a +`verdict`: the chosen option (`outcome → target`), a one-line reason with its +provenance (`model`, `fallback` or `absent`), and the recorded artifacts the reason +refers to. In the TUI, selecting a stage shows that verdict at the top of the +stage's result, above its output and evidence. Treat the reason as a claim to check +against the step's output, never as evidence in itself. Identify evidence-supported +causes and say what remains unknown. Never fix a run's symptom by editing the +project by hand: fix the pipeline definition or the Pipelines/harness service, or +record the failure and continue. Each playbook is *symptom → how to confirm → what to do*. @@ -82,12 +87,18 @@ Each playbook is *symptom → how to confirm → what to do*. - **Symptom** `inspect --json` or `ping --json` is missing fields this skill describes, or a flag is rejected as unknown. -- **Confirm** `ping --json` for the server build identity and `version --json` for the - client. An older server omits `build`; an older client may not send newer fields. +- **Confirm** The client now reports this itself. A server response carrying a + top-level field this client does not model prints a one-time + `server sent unrecognized top-level field(s) ...` notice; a same-protocol build + mismatch prints one `warning:` naming both builds on stderr; and a server + speaking a newer protocol fails the command non-zero. `ping --json` shows the + server build identity and `version --json` the client; `ping`/`connection` + also print the client/server relationship. An older server omits `build`. - **Do** Treat it as a version mismatch, not a run failure. State both versions and the mismatch. **Do not infer** that a source fix or an updated skill is deployed. Use only flags the installed help shows; do not restart or reinstall a service to - "fix" it without the operator (`references/operations.md`). + "fix" it without the operator (`references/operations.md`). Rebuild or reinstall + the CLI so it matches the server; never hand-edit an installed binary. ## A server restart killing in-flight runs diff --git a/internal/author/skill/references/format.md b/internal/author/skill/references/format.md index dba0f2ea..c29573a9 100644 --- a/internal/author/skill/references/format.md +++ b/internal/author/skill/references/format.md @@ -105,6 +105,46 @@ Use this block for intentional file/command restrictions; prose is not a runtime permission policy. Keep ordinary workflows language-neutral and unrestricted within their run directory unless the user asks for a narrower scope. +## Human (decision) stages + +A `type=human` stage pauses its run until a person chooses one of its outgoing +options. It has no model, agent, tools or configs: it needs a nonempty `prompt` +block (the operator instructions) and at least one non-`error` `edges` outcome. +Its outcomes are exactly its non-error edges, so a draft can express choices such +as `deploy`, `revise` or `abort`; the mandatory error edge is a failure route, +not a choice. It validates, renders, exports and imports like every other type. + +````markdown +# stage gate + +```output +The operator's decision evidence. +``` + +```prompt +Review the screenshots and artifacts above, then choose where the run goes. +``` + +```edges +deploy -> publish +revise -> worker +abort -> #failure +error -> #failure +``` +```` + +When a run reaches a human stage its step becomes `waiting`, the run reports it is +waiting on a person, and nothing later runs. Decide from the TUI (open the run, +press `c`, pick an option, optionally type feedback, Enter) or the CLI: +`pipelines decide <run-id> [stage] --option KEY [--feedback TEXT]`. The decision +and feedback are recorded as the step's evidence (the feedback stays in the step +output, never an error diagnostic) and the run resumes along that +edge. The wait is persisted, so it survives a server restart. An unknown option is +refused with the valid list; a decision to a stage that is not waiting is refused; +a repeated decision for an already-decided visit does not double-apply. Cancel and +retry keep working while waiting and after a decision, and a human stage is never +killed by a stage timeout or `max_visits` (the shared run budget still applies). + Malformed final JSON has bounded recovery even with `retries=0`; it never changes verdict/evidence. Recovery tries a deterministic local pass first (append missing closing delimiters, drop one trailing comma, or insert the single comma/colon the @@ -139,7 +179,8 @@ are not approved. Warn explicitly before adding/changing schedules. ## Notifications Stage hooks use the global phone connection, never store credentials. Optional -fenced `notify` block: `on=success,failure`, `artifacts=markdown`. +fenced `notify` block: `on=success,failure` (add `waiting` to fire when a human +stage parks the run), `artifacts=markdown`. Read this skill's `references/notifications.md` for the minimal terminal-path recipe and optional native publisher format. Prefer hooks for ordinary success/error alerts; a request to notify is not a request for a new delivery stage. Do not scan diff --git a/internal/author/skill/references/operations.md b/internal/author/skill/references/operations.md index a39e844b..c44f6673 100644 --- a/internal/author/skill/references/operations.md +++ b/internal/author/skill/references/operations.md @@ -30,10 +30,10 @@ parallel/distributed task engine or a guarantee that model reports are correct. fails another's concurrent run. An active session left over by a restart with no owning active run is an orphan and still refuses new work until interrupted. Reusing that active run's request key reattaches idempotently. - There are no parallel branches or built-in human approval stages. Optional - worktrees, full backup/restore, automatic database sync and independent - verifier stage types are future ideas, not existing capabilities. Do not - invent them in definitions. + `type=human` decision stages exist and pause the run (see `references/format.md`); + there are no parallel branches. Optional worktrees, full backup/restore, + automatic database sync and independent verifier stage types are future ideas, + not existing capabilities. Do not invent them in definitions. - Services are native or Docker-based. With an existing Docker installation do not start a competing native server. Server APIs are unauthenticated: trusted networks only; never recommend public exposure. Tool scope is not a universal OS sandbox. @@ -86,11 +86,34 @@ Use the authoritative `CLI_PREFIX` from the prompt: `truncated`/`scanned_steps`/`scanned_bytes`/`cap`/`scan_bound_bytes`. Targets are stable: `pipeline:<id>`, `pipeline:<id>:v<version>`, `run:<id>`, `run:<id>:<sequence>`, `run:<id>:<sequence>:<field>`, or an artifact URL. +- `CLI_PREFIX runs --json`: run history (optional `--pipeline NAME` scope). Each run + carries a bounded, single-line `title` saying what it was for, set explicitly with + `CLI_PREFIX run ... --title "..."` or generated from its prompt by the shared + summariser on the configured default harness. It is never empty: when generation is + unavailable or times out the server derives the prompt's first line, and + `title_source` (`model`, `fallback`, or `explicit`) plus `title_model` record how it + was produced, so a diagnosis can tell them apart. Human `runs` and `inspect` show the + title beside the pipeline name and version, so two runs of one pipeline are + distinguishable; `CLI_PREFIX title RUN_ID "..."` renames a run after the fact + without changing its input or steps. The stored prompt is unchanged, and + listing/renaming never calls a model. - `CLI_PREFIX inspect RUN_ID --json`: selected run, visits and retained evidence. Exact stage outputs are authoritative; a transcript over the 32 KiB retained bound is a valid, credential-redacted preview envelope (with preserved stage limits, failure/format diagnostics and the retained session pointer), not the complete tool history. +- `CLI_PREFIX decide RUN_ID [STAGE] --option KEY [--feedback TEXT] [--json]`: answer + a run that is `waiting` on a `type=human` stage. The status and the stage's + instructions/options are visible in `runs` and `inspect --json` (and the TUI + picker); the stage is inferred from the run's current stage unless named. The + choice and feedback are recorded as the step's evidence (its output and derived + verdict; the feedback is never an error diagnostic) and the run resumes along + `edges[KEY]`. An unknown option is + refused with the valid list; a stage that is not waiting is refused; a repeated + decision for an already-decided visit does not double-apply. The wait is persisted, + so `decide` still works after a server restart. `cancel` and `retry` keep working + while waiting and after a decision; a human stage is never killed by a stage + timeout or `max_visits` (the shared 30-step run budget still applies). - `CLI_PREFIX run ... --json --wait --wait-timeout DURATION`: `--wait` polls until terminal and `--wait-timeout` bounds only the client wait after admission, independent of per-request `--timeout`. A reached wait limit leaves the admitted run diff --git a/internal/buildinfo/identity.go b/internal/buildinfo/identity.go new file mode 100644 index 00000000..856e0a17 --- /dev/null +++ b/internal/buildinfo/identity.go @@ -0,0 +1,92 @@ +package buildinfo + +import "fmt" + +// Severity classifies how a client build relates to the server it is talking to. +// The zero value is the in-sync case so callers can treat "no relationship" as +// no output. +type Severity int + +const ( + // InSync means both peers report the same build and the same protocol. + InSync Severity = iota + // Warn means the builds differ or the server could not be identified, but the + // exchange is still safe: the client keeps working and reports once. + Warn + // Refuse means the server speaks a protocol newer than this client can + // interpret; continuing would silently misread frames, so the caller must + // fail rather than proceed. + Refuse +) + +// Relationship is the outcome of comparing a client build with a server build. +type Relationship struct { + Severity Severity + Message string +} + +// Describe names a build for humans. A missing build is reported as +// "unavailable" rather than guessed. +func Describe(info *Info) string { + if info == nil { + return "unavailable" + } + return fmt.Sprintf("%s (commit %s)", info.Version, info.Commit) +} + +// Compare classifies the client/server build relationship in O(1). Ordering uses +// the integer protocol only; build strings are used for naming, never parsed or +// ordered. server may be nil when the server omitted its build identity. +func Compare(client Info, clientProtocol int, serverProtocol int, server *Info) Relationship { + if serverProtocol > clientProtocol { + return Relationship{ + Severity: Refuse, + Message: fmt.Sprintf( + "server build %s speaks protocol %d, newer than this client's supported protocol %d; "+ + "update the pipelines CLI (client build %s) before connecting", + Describe(server), serverProtocol, clientProtocol, Describe(&client)), + } + } + if server != nil && serverProtocol == clientProtocol && sameBuild(client, *server) { + return Relationship{} + } + switch { + case server == nil: + return Relationship{ + Severity: Warn, + Message: fmt.Sprintf( + "the connected server did not report its build identity (older or incompatible server); "+ + "client build %s", Describe(&client)), + } + case serverProtocol == 0: + return Relationship{ + Severity: Warn, + Message: fmt.Sprintf( + "the connected server did not report a protocol version (legacy server); "+ + "client build %s, server build %s", Describe(&client), Describe(server)), + } + default: + return Relationship{ + Severity: Warn, + Message: fmt.Sprintf( + "client build %s does not match server build %s; rebuild or reinstall the CLI so it "+ + "matches the connected server", Describe(&client), Describe(server)), + } + } +} + +// sameBuild reports whether two identities name the same compiled artifact. A +// missing Dirty pointer is distinct from an explicit value. +func sameBuild(a, b Info) bool { + if a.Version != b.Version || a.Commit != b.Commit { + return false + } + switch { + case a.Dirty == nil && b.Dirty == nil: + return true + case a.Dirty == nil || b.Dirty == nil: + return false + default: + return *a.Dirty == *b.Dirty + } +} diff --git a/internal/buildinfo/identity_test.go b/internal/buildinfo/identity_test.go new file mode 100644 index 00000000..509a0eb7 --- /dev/null +++ b/internal/buildinfo/identity_test.go @@ -0,0 +1,108 @@ +package buildinfo + +import ( + "fmt" + "strings" + "testing" +) + +func TestCompareClassifiesBuildRelationship(t *testing.T) { + client := Info{Version: "v1-client", Commit: "aaaa"} + server := Info{Version: "v2-server", Commit: "bbbb"} + + cases := []struct { + name string + clientProtocol int + serverProtocol int + server *Info + severity Severity + }{ + {"identical", 1, 1, &client, InSync}, + {"different build same protocol", 1, 1, &server, Warn}, + {"server newer protocol", 1, 2, &server, Refuse}, + {"nil server", 1, 0, nil, Warn}, + {"legacy server protocol", 1, 0, &server, Warn}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got := Compare(client, tc.clientProtocol, tc.serverProtocol, tc.server) + if got.Severity != tc.severity { + t.Fatalf("severity = %v, want %v (%q)", got.Severity, tc.severity, got.Message) + } + if got.Severity == InSync { + if got.Message != "" { + t.Fatalf("in-sync relationship must carry no message: %q", got.Message) + } + return + } + if strings.TrimSpace(got.Message) == "" { + t.Fatal("warning/refusal must name the mismatch") + } + }) + } +} + +func TestCompareWarningNamesBothBuilds(t *testing.T) { + client := Info{Version: "v1-client", Commit: "aaaa"} + server := Info{Version: "v2-server", Commit: "bbbb"} + relation := Compare(client, 1, 1, &server) + if relation.Severity != Warn { + t.Fatalf("severity = %v", relation.Severity) + } + for _, needle := range []string{client.Version, server.Version} { + if !strings.Contains(relation.Message, needle) { + t.Fatalf("warning %q does not name %q", relation.Message, needle) + } + } +} + +func TestCompareRefusalNamesBothProtocolsAndBuilds(t *testing.T) { + client := Info{Version: "v1-client", Commit: "aaaa"} + server := Info{Version: "v2-server", Commit: "bbbb"} + relation := Compare(client, 1, 3, &server) + if relation.Severity != Refuse { + t.Fatalf("severity = %v, want Refuse", relation.Severity) + } + for _, needle := range []string{client.Version, server.Version, "3", "1"} { + if !strings.Contains(relation.Message, needle) { + t.Fatalf("refusal %q does not name %q", relation.Message, needle) + } + } +} + +func TestCompareDistinguishesDirtyPointer(t *testing.T) { + base := Info{Version: "v1", Commit: "aaaa"} + clean := Info{Version: "v1", Commit: "aaaa", Dirty: boolPtr(false)} + dirty := Info{Version: "v1", Commit: "aaaa", Dirty: boolPtr(true)} + + if got := Compare(base, 1, 1, &base); got.Severity != InSync { + t.Fatalf("identical missing-dirty identities must be in sync: %+v", got) + } + if got := Compare(clean, 1, 1, &dirty); got.Severity != Warn { + t.Fatalf("differing dirty state must warn: %+v", got) + } + if got := Compare(base, 1, 1, &clean); got.Severity != Warn { + t.Fatalf("nil dirty is distinct from an explicit value: %+v", got) + } + if got := Compare(clean, 1, 1, &clean); got.Severity != InSync { + t.Fatalf("identical explicit dirty identities must be in sync: %+v", got) + } +} + +func TestDescribeNamesMissingBuildAsUnavailable(t *testing.T) { + if got := Describe(nil); got != "unavailable" { + t.Fatalf("Describe(nil) = %q", got) + } + info := Info{Version: "v1", Commit: "abc"} + if got := Describe(&info); !strings.Contains(got, "v1") || !strings.Contains(got, "abc") { + t.Fatalf("Describe = %q", got) + } +} + +func TestSeverityZeroIsInSync(t *testing.T) { + var zero Severity + if zero != InSync { + t.Fatalf("zero severity = %v, want InSync", zero) + } + _ = fmt.Sprint(zero) +} diff --git a/internal/cli/app.go b/internal/cli/app.go index eccf6bd6..23e95a85 100644 --- a/internal/cli/app.go +++ b/internal/cli/app.go @@ -33,15 +33,16 @@ type App struct { In io.Reader } type options struct { - harness string - url, name, prompt, template, workspace, paths, key, opencode, model string - output string - conflict string - kind string - all bool - json, source, noOpen, yes, allow, createOnly, force, wait bool - version, expected, limit int - timeout, waitTimeout time.Duration + harness string + url, name, prompt, title, template, workspace, paths, key, opencode, model string + option, feedback string + output string + conflict string + kind string + all bool + json, source, noOpen, yes, allow, createOnly, force, wait bool + version, expected, limit int + timeout, waitTimeout time.Duration } func (a App) flags(command string) (*flag.FlagSet, *options) { @@ -90,6 +91,7 @@ func (a App) flags(command string) (*flag.FlagSet, *options) { case "run": f.StringVar(&o.name, "pipeline", "", "Exact registered pipeline name or ID") f.StringVar(&o.prompt, "prompt", "", "Task prompt; omitted opens a multiline composer") + f.StringVar(&o.title, "title", "", "Explicit run title; default is derived from the prompt") f.StringVar(&o.workspace, "workspace", "", "Run directory (default: current directory)") f.BoolVar(&o.yes, "yes", false, "Confirm execution without an interactive prompt") f.BoolVar(&o.allow, "allow-tools", false, "Compatibility flag; stage-declared tools are enabled automatically") @@ -110,6 +112,9 @@ func (a App) flags(command string) (*flag.FlagSet, *options) { f.DurationVar(&o.waitTimeout, "wait-timeout", 0, "Client limit for --wait (0 waits until the run ends); independent of --timeout") case "cancel", "draft-delete": f.BoolVar(&o.yes, "yes", false, "Confirm this action without an interactive prompt") + case "decide": + f.StringVar(&o.option, "option", "", "Option key to choose among the waiting stage's edges (required)") + f.StringVar(&o.feedback, "feedback", "", "Optional free-text feedback recorded with the decision") case "debug": f.StringVar(&o.harness, "harness", "", "Debugging harness: configured opencode/pi, or nvim") f.BoolVar(&o.yes, "yes", false, "Approve opening a debugging session without prompting") @@ -145,6 +150,18 @@ func envOr(key, value string) string { return value } +// recordedFeedback returns the feedback the server actually stored for the +// decided step that carries the chosen option, so a repeated (idempotent) +// decision reports the recorded evidence rather than the ignored request text. +func recordedFeedback(detail *protocol.RunDetail, option string) string { + for i := len(detail.Steps) - 1; i >= 0; i-- { + if chosen, feedback := protocol.DecisionEvidence(detail.Steps[i].Output); chosen == option { + return strings.TrimSpace(feedback) + } + } + return "" +} + // parse allows flags before or after positional arguments without reinterpreting values. func parse(f *flag.FlagSet, args []string) error { var flags, positionals []string @@ -391,6 +408,13 @@ func (a App) Run(ctx context.Context, args []string) error { return err } defer c.Close() + // Report at most one build/protocol warning per invocation on stderr, so + // stdout stays parseable JSON; an unsafe newer server fails the command. + c.Report(func(relationship buildinfo.Relationship) { + if relationship.Message != "" { + a.notice("warning: " + relationship.Message) + } + }) call := func(request protocol.Message) (protocol.Message, error) { requestCtx, cancel := context.WithTimeout(ctx, o.timeout) defer cancel() @@ -662,7 +686,7 @@ func (a App) Run(ctx context.Context, args []string) error { } case "runs": for _, run := range r.Runs { - fmt.Fprintf(a.Out, "%d\t%s\tv%d\t%s\n", run.ID, run.Name, run.Version, run.Status) + fmt.Fprintf(a.Out, "%d\t%s\t%s\tv%d\t%s\n", run.ID, run.Label(), run.Name, run.Version, run.Status) } case "ping": fmt.Fprintln(a.Out, "Connected ·", r.Time) @@ -671,11 +695,19 @@ func (a App) Run(ctx context.Context, args []string) error { } else { fmt.Fprintln(a.Out, "Server build: unavailable (older server)") } + build := buildinfo.Current() + fmt.Fprintf(a.Out, "Client: %s (commit %s)\n", build.Version, build.Commit) + if note := identityNote(r); note != "" { + fmt.Fprintln(a.Out, "Note:", note) + } case "connection": fmt.Fprintln(a.Out, "Server:", o.url) for _, n := range r.NotificationEndpoints { fmt.Fprintf(a.Out, "ntfy: %s · topic %s\n", n.ServerURL, n.Topic) } + if note := identityNote(r); note != "" { + fmt.Fprintln(a.Out, "Note:", note) + } } return nil case "export": @@ -806,6 +838,58 @@ func (a App) Run(ctx context.Context, args []string) error { return a.finishRun(ctx, r, o, call) } return a.output(r.RunDetail) + case "decide": + if len(pos) < 1 || len(pos) > 2 { + return fmt.Errorf("decide requires a run ID and an optional stage key") + } + id, err := strconv.ParseInt(pos[0], 10, 64) + if err != nil || id <= 0 { + return fmt.Errorf("run ID must be positive") + } + option := strings.TrimSpace(o.option) + if option == "" { + return fmt.Errorf("decide requires --option KEY") + } + stageKey := "" + if len(pos) == 2 { + stageKey = pos[1] + } + r, err := call(protocol.Message{Type: protocol.DecideRun, RunID: id, Stage: stageKey, Option: option, Feedback: o.feedback}) + if err != nil { + return err + } + if r.RunDetail == nil { + return fmt.Errorf("server did not return run detail") + } + if o.json { + return a.output(r.RunDetail) + } + line := fmt.Sprintf("Decided run #%d: %s · %s", r.RunDetail.ID, option, r.RunDetail.Status) + if feedback := recordedFeedback(r.RunDetail, option); feedback != "" { + line += " · feedback: " + feedback + } + _, err = fmt.Fprintln(a.Out, line) + return err + case "title": + if len(pos) != 2 { + return fmt.Errorf("title requires a run ID and a title") + } + id, err := strconv.ParseInt(pos[0], 10, 64) + if err != nil || id <= 0 { + return fmt.Errorf("run ID must be positive") + } + r, err := call(protocol.Message{Type: protocol.SetRunTitle, RunID: id, Title: pos[1]}) + if err != nil { + return err + } + if r.RunDetail == nil { + return fmt.Errorf("server did not return run detail") + } + if o.json { + return a.output(r.RunDetail) + } + _, err = fmt.Fprintf(a.Out, "Renamed run #%d to %s\n", r.RunDetail.ID, r.RunDetail.Label()) + return err case "rpc": path, err := one() if err != nil { @@ -868,6 +952,23 @@ func searchLabel(hit protocol.SearchResult) string { return "" } +// notice writes one non-fatal line to stderr so machine-readable stdout stays +// intact. It never falls back to stdout, where it could corrupt --json output +// for an embedder that does not configure Err. +func (a App) notice(line string) { + w := a.Err + if w == nil { + w = os.Stderr + } + fmt.Fprintln(w, line) +} + +// identityNote describes how this client build relates to a server response for +// human output; it is empty when both peers match. +func identityNote(response protocol.Message) string { + return buildinfo.Compare(buildinfo.Current(), protocol.MaxSupportedProtocol, response.Protocol, response.Build).Message +} + type callFunc func(protocol.Message) (protocol.Message, error) type resolveFunc func(string) (protocol.PipelineSummary, error) @@ -1044,7 +1145,7 @@ func (a App) run(ctx context.Context, pos []string, o *options, call callFunc, r if o.wait || o.key != "" || o.version > 0 { return fmt.Errorf("--wait, --request-key and --version require --json") } - _, err := tea.NewProgram(tui.NewRun(ctx, o.url, tui.RunOptions{Pipeline: o.name, Prompt: o.prompt, Workspace: workspace, Yes: o.yes, AllowTools: o.allow, WritePaths: paths}), tea.WithContext(ctx), tea.WithAltScreen()).Run() + _, err := tea.NewProgram(tui.NewRun(ctx, o.url, tui.RunOptions{Pipeline: o.name, Prompt: o.prompt, Title: o.title, Workspace: workspace, Yes: o.yes, AllowTools: o.allow, WritePaths: paths}), tea.WithContext(ctx), tea.WithAltScreen()).Run() return err } if o.name == "" || strings.TrimSpace(o.prompt) == "" { @@ -1065,7 +1166,7 @@ func (a App) run(ctx context.Context, pos []string, o *options, call callFunc, r if key == "" { key = fmt.Sprintf("cli-%d-%d", os.Getpid(), time.Now().UnixNano()) } - r, err := call(protocol.Message{Type: protocol.RunPipeline, PipelineID: p.ID, Version: version, RequestKey: key, Workspace: workspace, Input: map[string]any{"prompt": o.prompt}, AllowTools: o.allow, WritePaths: paths}) + r, err := call(protocol.Message{Type: protocol.RunPipeline, PipelineID: p.ID, Version: version, RequestKey: key, Workspace: workspace, Title: o.title, Input: map[string]any{"prompt": o.prompt}, AllowTools: o.allow, WritePaths: paths}) if err != nil { return err } diff --git a/internal/cli/commands.go b/internal/cli/commands.go index d0c5c4cc..8527935d 100644 --- a/internal/cli/commands.go +++ b/internal/cli/commands.go @@ -17,11 +17,13 @@ var usage = map[string]string{ "import": "import [FILE.zip] [--all] [--on-conflict ask|keep|both|import] [--yes] [--json]", "templates": "templates [--json]", "template": "template <key> [--source | --json]", - "run": "run [name|id] [prompt] [--json [--wait [--wait-timeout DURATION]]]", + "run": "run [name|id] [prompt] [--title TITLE] [--json [--wait [--wait-timeout DURATION]]]", "runs": "runs [--pipeline NAME] [--json]", "inspect": "inspect <run-id> [--json]", "cancel": "cancel <run-id> [--json]", + "decide": "decide <run-id> [stage] --option KEY [--feedback TEXT] [--json]", "retry": "retry <run-id> [--json [--wait [--wait-timeout DURATION]]]", + "title": "title <run-id> \"<title>\" [--json]", "debug": "debug <run-id> [--json | --no-open]", "connection": "connection [--json]", "ping": "ping [--json]", @@ -33,18 +35,22 @@ var usage = map[string]string{ } var notes = map[string]string{ - "version": "Identify the local CLI binary without connecting to a server. --version is an alias. Use ping --json to identify the running server separately.", - "ping": "Pong includes the running server's compiled build.version, build.commit and build.dirty (null when unknown). This identifies the server, not the client or runtime workspace. Older servers omit build.", - "export": "Without a name, select pipelines with Space and save a ZIP in the current directory. --output writes a portable definition bundle; --all skips selection. One name without --output prints Markdown as before. No runs, credentials or old versions are exported.", - "import": "Select definitions from a ZIP. Identical existing definitions are skipped. For differing names, choose keep existing, keep both under a new name, or use imported as a new version (history retained). --on-conflict supplies an explicit automation policy; --yes only approves final publication. Schedules may activate; no run history is imported.", - "new": "Create an optional template copy or a one-stage starter. Opens the configured default harness; --harness opencode|pi|nvim overrides it. No submission is performed.", - "edit": "Omit the name to open fuzzy selection. Original immutable source is copied to a private draft. The configured harness edits that draft, never the live definition.", - "validate": "Uses the same server parser as submission. Does not persist or activate schedules. Structural validity does not prove runtime/tool availability.", - "submit": "Confirm publication at the prompt, or use --yes for explicit automation; schedules activate on acceptance. Managed drafts provide the name and base-version guard. --force never bypasses validation.", - "run": "Runs in your current directory after action confirmation (--yes skips it). Select a pipeline and compose a multiline task with Ctrl+S. Stage tools are enabled automatically; no file list or typed RUN confirmation. Cancellation does not undo edits. In JSON mode --wait polls until terminal; --wait-timeout bounds only the client wait after admission and is independent of per-request --timeout. A reached wait limit leaves the run active: inspect read-only with `inspect <run-id> --json`, or reattach with --wait reusing the original --request-key (never an automatic replay or cancel).", - "retry": "Start a new attempt of a failed run with the same initial input, directory, pipeline version, and edit scope. Original history is retained. Already-completed side effects are not undone. --wait/--wait-timeout behave as for run: a reached wait limit leaves the new run active; inspect read-only with `inspect <run-id> --json`, or reattach with --wait and the original --request-key instead of starting a duplicate retry.", - "debug": "Open a fresh configured harness conversation to investigate a run using inspect/show/runs CLI queries. --harness opencode|pi|nvim chooses another configured harness or read-only nvim packet. Does not resume implementation or retry. --json returns the prompt without launching anything.", - "rpc": "Accepts a JSON protocol envelope; '-' reads stdin. Every TUI server operation is available here too. Mutating commands are not dry runs.", + "version": "Identify the local CLI binary without connecting to a server. --version is an alias. Use ping --json to identify the running server separately.", + "ping": "Pong includes the running server's compiled build.version, build.commit and build.dirty (null when unknown). This identifies the server, not the client or runtime workspace. Older servers omit build. The client compares its own build/protocol against the server: a same-protocol build mismatch prints one warning to stderr, a server speaking a newer protocol fails the command, and a response carrying a field this client does not model prints a one-time unrecognized-field notice instead of dropping it silently.", + "connection": "Prints the server endpoint and phone notification endpoints. Like ping, it reports the client/server build relationship and warns or fails rather than silently proceeding against a mismatched server.", + "status": "Reports server, host and ntfy publishing health. The client compares its build/protocol against the server and warns once (or fails on a newer protocol) rather than proceeding silently.", + "export": "Without a name, select pipelines with Space and save a ZIP in the current directory. --output writes a portable definition bundle; --all skips selection. One name without --output prints Markdown as before. No runs, credentials or old versions are exported.", + "import": "Select definitions from a ZIP. Identical existing definitions are skipped. For differing names, choose keep existing, keep both under a new name, or use imported as a new version (history retained). --on-conflict supplies an explicit automation policy; --yes only approves final publication. Schedules may activate; no run history is imported.", + "new": "Create an optional template copy or a one-stage starter. Opens the configured default harness; --harness opencode|pi|nvim overrides it. No submission is performed.", + "edit": "Omit the name to open fuzzy selection. Original immutable source is copied to a private draft. The configured harness edits that draft, never the live definition.", + "validate": "Uses the same server parser as submission. Does not persist or activate schedules. Structural validity does not prove runtime/tool availability.", + "submit": "Confirm publication at the prompt, or use --yes for explicit automation; schedules activate on acceptance. Managed drafts provide the name and base-version guard. --force never bypasses validation.", + "run": "Runs in your current directory after action confirmation (--yes skips it). Select a pipeline and compose a multiline task with Ctrl+S. Stage tools are enabled automatically; no file list or typed RUN confirmation. Cancellation does not undo edits. --title sets an explicit run title; without it the title is derived from the prompt. In JSON mode --wait polls until terminal; --wait-timeout bounds only the client wait after admission and is independent of per-request --timeout. A reached wait limit leaves the run active: inspect read-only with `inspect <run-id> --json`, or reattach with --wait reusing the original --request-key (never an automatic replay or cancel).", + "retry": "Start a new attempt of a failed run with the same initial input, directory, pipeline version, and edit scope. Original history is retained. Already-completed side effects are not undone. --wait/--wait-timeout behave as for run: a reached wait limit leaves the new run active; inspect read-only with `inspect <run-id> --json`, or reattach with --wait and the original --request-key instead of starting a duplicate retry.", + "title": "Rename a run's operator-facing title after the fact without touching its input, steps or execution. The title is collapsed to a single bounded line and recorded as explicitly set. `pipelines runs` and `pipelines inspect` then show it.", + "decide": "Choose an option for a run waiting on a human stage. The run must be `waiting`; the option must be one of that stage's non-error edges. The stage is inferred from the run's current stage unless named. The choice and optional --feedback are recorded as the step's evidence (visible in inspect and the TUI) and the run resumes along the chosen edge. An unknown option is refused with the valid list; a repeated decision for an already-decided visit does not double-apply. Works across a server restart because the wait is persisted.", + "debug": "Open a fresh configured harness conversation to investigate a run using inspect/show/runs CLI queries. --harness opencode|pi|nvim chooses another configured harness or read-only nvim packet. Does not resume implementation or retry. --json returns the prompt without launching anything.", + "rpc": "Accepts a JSON protocol envelope; '-' reads stdin. Every TUI server operation is available here too. Mutating commands are not dry runs. The omni-search command is `search` (fields query, optional kind and limit) and answers with ranked `search_results`.", "search": "One read-only query over pipelines, versions, runs, steps, field text and artifacts. QUERY is free text, a bare status word (queued, running, succeeded, failed, canceled, interrupted) selecting those runs, or a lone date expression (today, yesterday, this week [Monday 00:00 local], or YYYY-MM-DD) selecting the runs created in that window. --type is the only narrowing mechanism and takes one kind: pipeline, version, run, step, field or artifact; an unknown kind is an error. Ranking: an exact name match (3) beats a name substring (2) beats a body-text match (1); equal tiers break by recency, then a stable kind/target tie-break, and every hit reports score, matched_field and recency so a client can re-rank. Bounds: the result cap defaults to 50 and clamps to 200 (0 = default); every kind scans at most 2000 rows and field-text scanning is additionally capped at 2000 steps / 1 MiB; Truncated plus scanned_steps, scanned_bytes and scan_bound_bytes report when a bound applied. Targets are stable: pipeline:<id>, pipeline:<id>:v<version>, run:<id>, run:<id>:<sequence>, run:<id>:<sequence>:<field>, or an artifact URL.", } diff --git a/internal/cli/decide_test.go b/internal/cli/decide_test.go new file mode 100644 index 00000000..98d1d7af --- /dev/null +++ b/internal/cli/decide_test.go @@ -0,0 +1,99 @@ +package cli_test + +import ( + "context" + "encoding/json" + "strconv" + "strings" + "testing" + + "git.a-wan.net/alan/pipelines/internal/protocol" +) + +const cliHumanSource = "# stage gate\n\n```output\nDecision evidence.\n```\n\n```prompt\nApprove the release.\n```\n\n```edges\ngo -> #success\nhalt -> #failure\nerror -> #failure\n```\n\n```configs\ntype=human\n```\n\n" + +func TestCLIDecideWaitingHumanRun(t *testing.T) { + run, store, _ := setup(t) + ctx := context.Background() + if _, err := store.Submit(ctx, "human-ws", cliHumanSource); err != nil { + t.Fatal(err) + } + + output, err := run("run", "human-ws", "ship it", "--json", "--yes") + if err != nil { + t.Fatal(err) + } + var started protocol.Message + if err := json.Unmarshal([]byte(output), &started); err != nil || started.RunDetail == nil { + t.Fatalf("run did not return detail: %v %s", err, output) + } + runID := started.RunDetail.ID + + waitFor := func(status string) protocol.RunDetail { + t.Helper() + for i := 0; i < 100; i++ { + text, err := run("inspect", strconv.FormatInt(runID, 10), "--json") + if err != nil { + t.Fatal(err) + } + var detail protocol.RunDetail + if err := json.Unmarshal([]byte(text), &detail); err != nil { + t.Fatal(err) + } + if detail.Status == status { + return detail + } + } + t.Fatalf("run never reached %s", status) + return protocol.RunDetail{} + } + waiting := waitFor(protocol.RunStatusWaiting) + if len(waiting.Steps) != 1 || waiting.Steps[0].Status != protocol.StepStatusWaiting { + t.Fatalf("waiting step not visible: %+v", waiting.Steps) + } + if prompt := protocol.WaitingPrompt(waiting.Steps[0].Output); !strings.Contains(prompt, "Approve the release") { + t.Fatalf("waiting prompt not visible: %+v", waiting.Steps[0].Output) + } + + if _, err := run("decide", strconv.FormatInt(runID, 10)); err == nil || !strings.Contains(err.Error(), "--option") { + t.Fatalf("missing --option was accepted: %v", err) + } + if _, err := run("decide", strconv.FormatInt(runID, 10), "--option", "launch"); err == nil || !strings.Contains(err.Error(), "valid options") { + t.Fatalf("unknown option was accepted: %v", err) + } + + output, err = run("decide", strconv.FormatInt(runID, 10), "gate", "--option", "go", "--feedback", "approved", "--json") + if err != nil { + t.Fatal(err) + } + var decided protocol.RunDetail + if err := json.Unmarshal([]byte(output), &decided); err != nil { + t.Fatal(err) + } + final := waitFor("succeeded") + gate := final.Steps[0] + if gate.Outcome != "go" || gate.Target != protocol.SuccessEnd || gate.Output["feedback"] != "approved" || gate.Diagnostic != "" { + t.Fatalf("decision evidence not recorded: %+v", gate) + } + if gate.Verdict == nil || gate.Verdict.Option != "go → success" || gate.Verdict.Reason != "approved" { + t.Fatalf("derived verdict missing the decision: %+v", gate.Verdict) + } + + // A repeated decision must not double-apply and must report the recorded + // evidence, not the ignored request text. + repeat, err := run("decide", strconv.FormatInt(runID, 10), "gate", "--option", "go", "--feedback", "again") + if err != nil { + t.Fatal(err) + } + if strings.Contains(repeat, "again") || !strings.Contains(repeat, "approved") { + t.Fatalf("repeated decision reported the request, not the recorded evidence: %q", repeat) + } + after := waitFor("succeeded") + if len(after.Steps) != 1 || after.Steps[0].Output["feedback"] != "approved" { + t.Fatalf("repeated decision changed the recorded evidence: %+v", after.Steps) + } + + if _, err := run("help", "decide"); err != nil { + t.Fatal(err) + } +} diff --git a/internal/cli/help.go b/internal/cli/help.go index 7552a857..ff7a510e 100644 --- a/internal/cli/help.go +++ b/internal/cli/help.go @@ -27,7 +27,9 @@ EXECUTE runs List audited runs; --pipeline filters results inspect <run-id> Inspect stages, outputs, errors and status cancel <run-id> Cancel a run; changes are NOT rolled back + decide <run-id> [stage] Choose an option for a run waiting on a person retry <run-id> Restart a failed run with its original input and directory + title <run-id> "<title>" Rename a run after the fact; input/steps unchanged debug <run-id> Investigate a run with a configured harness or nvim draft-delete <draft.md> Delete a selected retained draft and its metadata connection Server and public phone connection (no secrets) @@ -66,4 +68,12 @@ when a checkout is linked) edits a private draft; nvim remains a client editor. Nothing is published automatically. Every submission is validated server-side. Submission activates any schedules. JSON mode never launches an editor or picker; supply explicit arguments. + +Search: the TUI '/' popup and the protocol 'search' command (via 'pipelines rpc') +find pipelines, versions, runs, stages/visits, artifact names and the text of stage +inputs, outputs and evidence. A bare status word (queued, running, succeeded, +failed, canceled, interrupted) or a date (today, yesterday, this week, or +YYYY-MM-DD interpreted in UTC) selects runs. A leading prefix pipeline:, version:, +run:, step:, field:, artifact: or match: (a field alias) narrows the result kind; +unrecognised words stay text. ` diff --git a/internal/cli/identity_test.go b/internal/cli/identity_test.go new file mode 100644 index 00000000..8d4a8542 --- /dev/null +++ b/internal/cli/identity_test.go @@ -0,0 +1,104 @@ +package cli + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "strings" + "testing" + "time" + + "git.a-wan.net/alan/pipelines/internal/buildinfo" + "git.a-wan.net/alan/pipelines/internal/protocol" + "git.a-wan.net/alan/pipelines/internal/wstest" +) + +func TestCLIWarnsOnceOnDifferingBuildAndKeepsJSONParseable(t *testing.T) { + server := buildinfo.Info{Version: "v0-stale-server", Commit: "deadbeef"} + endpoint := wstest.Server(t, func(protocol.Message) protocol.Message { + return protocol.Message{Type: protocol.Pong, Build: &server, Protocol: protocol.ProtocolVersion} + }) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + var out, errOut bytes.Buffer + app := App{Out: &out, Err: &errOut, In: strings.NewReader("")} + if err := app.Run(ctx, []string{"--url", endpoint, "ping", "--json"}); err != nil { + t.Fatal(err) + } + // stdout must stay valid JSON. + var decoded protocol.Message + if err := json.Unmarshal(out.Bytes(), &decoded); err != nil { + t.Fatalf("stdout is not parseable JSON: %v\n%s", err, out.String()) + } + if decoded.Build == nil || decoded.Build.Version != server.Version { + t.Fatalf("stdout lost the server build: %+v", decoded.Build) + } + warnings := 0 + for _, line := range strings.Split(strings.TrimSpace(errOut.String()), "\n") { + if strings.HasPrefix(line, "warning:") { + warnings++ + client := buildinfo.Current() + for _, needle := range []string{client.Version, server.Version} { + if !strings.Contains(line, needle) { + t.Fatalf("warning %q does not name %q", line, needle) + } + } + } + } + if warnings != 1 { + t.Fatalf("differing build produced %d stderr warnings, want exactly one:\n%s", warnings, errOut.String()) + } + t.Logf("stdout:\n%s", out.String()) + t.Logf("stderr:\n%s", strings.TrimSpace(errOut.String())) + + // Human ping prints the relationship too, without hiding the server build. + var humanOut, humanErr bytes.Buffer + human := App{Out: &humanOut, Err: &humanErr, In: strings.NewReader("")} + if err := human.Run(ctx, []string{"--url", endpoint, "ping"}); err != nil { + t.Fatal(err) + } + if !strings.Contains(humanOut.String(), "Note:") || !strings.Contains(humanOut.String(), server.Version) { + t.Fatalf("human ping omitted the client/server relationship:\n%s", humanOut.String()) + } +} + +func TestCLINoticesUnmodeledFieldInsteadOfDroppingIt(t *testing.T) { + payload := map[string]any{"type": protocol.Pong, "future_field": true} + payload["build"] = buildinfo.Current() + payload["protocol"] = protocol.ProtocolVersion + endpoint := wstest.Raw(t, func(protocol.Message) map[string]any { return payload }) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + var out, errOut bytes.Buffer + app := App{Out: &out, Err: &errOut, In: strings.NewReader("")} + if err := app.Run(ctx, []string{"--url", endpoint, "ping"}); err != nil { + t.Fatal(err) + } + if !strings.Contains(errOut.String(), "future_field") || !strings.Contains(errOut.String(), "unrecognized") { + t.Fatalf("unmodeled field was silent: stderr=%q stdout=%q", errOut.String(), out.String()) + } + t.Logf("stderr:\n%s", strings.TrimSpace(errOut.String())) +} + +func TestCLIRefusesNewerServerProtocol(t *testing.T) { + server := buildinfo.Info{Version: "v9-future-server", Commit: "deadbeef"} + endpoint := wstest.Server(t, func(protocol.Message) protocol.Message { + return protocol.Message{Type: protocol.Pong, Build: &server, Protocol: protocol.ProtocolVersion + 7} + }) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + var out, errOut bytes.Buffer + app := App{Out: &out, Err: &errOut, In: strings.NewReader("")} + err := app.Run(ctx, []string{"--url", endpoint, "ping", "--json"}) + if err == nil { + t.Fatal("a newer server protocol did not fail the command") + } + client := buildinfo.Current() + for _, needle := range []string{client.Version, server.Version, fmt.Sprint(protocol.ProtocolVersion + 7), fmt.Sprint(protocol.ProtocolVersion)} { + if !strings.Contains(err.Error(), needle) { + t.Fatalf("refusal %q does not name %q", err.Error(), needle) + } + } + t.Logf("exit error: %v", err) +} diff --git a/internal/client/client.go b/internal/client/client.go index 22c736fe..462682ad 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -4,10 +4,13 @@ package client import ( "context" + "encoding/json" "fmt" "strconv" + "strings" "sync" + "git.a-wan.net/alan/pipelines/internal/buildinfo" "git.a-wan.net/alan/pipelines/internal/protocol" "github.com/coder/websocket" "github.com/coder/websocket/wsjson" @@ -27,16 +30,106 @@ func Send(ctx context.Context, conn *websocket.Conn, request protocol.Message) e return wsjson.Write(ctx, conn, request) } -func Receive(ctx context.Context, conn *websocket.Conn) (protocol.Message, error) { +// Reporter receives a build/protocol relationship notice for display. It is +// called at most once per distinct notice on a connection. +type Reporter func(buildinfo.Relationship) + +// Watch compares each received frame with this client build and records the +// once-only identity and unrecognized-field notices for one server connection. +// The zero value is ready to use; a nil Watch reports every warning unfiltered. +type Watch struct { + mu sync.Mutex + identityReported bool + unknownReported bool +} + +// Observe classifies one received frame. It returns the notices that have not +// already been shown on this connection and, when the server speaks a newer +// protocol than this client interprets, an error naming both builds and both +// protocols so the caller must not act on the frame. +func (w *Watch) Observe(data []byte, response protocol.Message) ([]buildinfo.Relationship, error) { + client := buildinfo.Current() + relation := buildinfo.Compare(client, protocol.MaxSupportedProtocol, response.Protocol, response.Build) + if relation.Severity == buildinfo.Refuse { + return nil, fmt.Errorf("%s", relation.Message) + } + if w == nil { + if relation.Severity == buildinfo.Warn { + return []buildinfo.Relationship{relation}, nil + } + return nil, nil + } + w.mu.Lock() + defer w.mu.Unlock() + var notices []buildinfo.Relationship + if relation.Severity == buildinfo.Warn && !w.identityReported { + w.identityReported = true + notices = append(notices, relation) + } + // A top-level key this client does not model would otherwise be dropped + // silently: report the mismatch once instead of appearing to have no data. + if unknown := protocol.UnknownFields(data); len(unknown) > 0 && !w.unknownReported { + w.unknownReported = true + notices = append(notices, buildinfo.Relationship{ + Severity: buildinfo.Warn, + Message: fmt.Sprintf( + "server sent unrecognized top-level field(s) %s; this client may be older than the server (client build %s)", + strings.Join(unknown, ", "), buildinfo.Describe(&client)), + }) + } + return notices, nil +} + +// read reads one text frame and decodes it, keeping the raw bytes so unmodeled +// top-level keys can be detected without a second decode. +func read(ctx context.Context, conn *websocket.Conn) (protocol.Message, []byte, error) { + kind, data, err := conn.Read(ctx) + if err != nil { + return protocol.Message{}, nil, err + } + if kind != websocket.MessageText { + return protocol.Message{}, data, fmt.Errorf("unexpected websocket message type %d", kind) + } var response protocol.Message - err := wsjson.Read(ctx, conn, &response) + if err := json.Unmarshal(data, &response); err != nil { + return protocol.Message{}, data, err + } + return response, data, nil +} + +// ReceiveNotice reads and decodes one frame, returning the once-only +// identity/unrecognized-field notices for display. A non-nil error means the +// frame must not be used: an unsafe newer server, or a transport/decode failure. +func ReceiveNotice(ctx context.Context, conn *websocket.Conn, watch *Watch) (protocol.Message, []string, error) { + response, data, err := read(ctx, conn) + if err != nil { + return response, nil, err + } + relations, err := watch.Observe(data, response) + notices := make([]string, 0, len(relations)) + for _, relation := range relations { + if relation.Message != "" { + notices = append(notices, relation.Message) + } + } + return response, notices, err +} + +// Receive reads and decodes one frame without reporting its identity. Most +// callers should use ReceiveNotice so an older or newer server is never silent. +func Receive(ctx context.Context, conn *websocket.Conn) (protocol.Message, error) { + response, _, err := ReceiveNotice(ctx, conn, nil) return response, err } type Client struct { - Conn *websocket.Conn - mu sync.Mutex - next uint64 + Conn *websocket.Conn + mu sync.Mutex + next uint64 + watch Watch + + reportMu sync.Mutex + report Reporter } func Open(ctx context.Context, url string) (*Client, error) { @@ -49,6 +142,14 @@ func Open(ctx context.Context, url string) (*Client, error) { func (c *Client) Close() { c.Conn.CloseNow() } +// Report installs the notice reporter used by Call. Set it once after Open and +// before the first Call; a nil reporter still fails on an unsafe newer server. +func (c *Client) Report(report Reporter) { + c.reportMu.Lock() + c.report = report + c.reportMu.Unlock() +} + // Call serializes request/reply pairs, skipping the unsolicited welcome envelope. func (c *Client) Call(ctx context.Context, request protocol.Message) (protocol.Message, error) { c.mu.Lock() @@ -59,7 +160,15 @@ func (c *Client) Call(ctx context.Context, request protocol.Message) (protocol.M return protocol.Message{}, err } for { - response, err := Receive(ctx, c.Conn) + response, notices, err := ReceiveNotice(ctx, c.Conn, &c.watch) + for _, notice := range notices { + c.reportMu.Lock() + report := c.report + c.reportMu.Unlock() + if report != nil { + report(buildinfo.Relationship{Severity: buildinfo.Warn, Message: notice}) + } + } if err != nil { return response, err } diff --git a/internal/client/identity_test.go b/internal/client/identity_test.go new file mode 100644 index 00000000..c38a79d8 --- /dev/null +++ b/internal/client/identity_test.go @@ -0,0 +1,128 @@ +package client + +import ( + "context" + "fmt" + "strings" + "testing" + "time" + + "git.a-wan.net/alan/pipelines/internal/buildinfo" + "git.a-wan.net/alan/pipelines/internal/protocol" + "git.a-wan.net/alan/pipelines/internal/wstest" +) + +func TestCallRefusesNewerServerProtocol(t *testing.T) { + server := buildinfo.Info{Version: "v9-server", Commit: "deadbeef"} + endpoint := wstest.Server(t, func(protocol.Message) protocol.Message { + return protocol.Message{Type: protocol.Pong, Build: &server, Protocol: protocol.ProtocolVersion + 5} + }) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + c, err := Open(ctx, endpoint) + if err != nil { + t.Fatal(err) + } + defer c.Close() + var warnings int + c.Report(func(buildinfo.Relationship) { warnings++ }) + _, err = c.Call(ctx, protocol.Message{Type: protocol.Ping}) + if err == nil { + t.Fatal("newer server protocol was not refused") + } + client := buildinfo.Current() + for _, needle := range []string{client.Version, server.Version, fmt.Sprint(protocol.ProtocolVersion + 5), fmt.Sprint(protocol.ProtocolVersion)} { + if !strings.Contains(err.Error(), needle) { + t.Fatalf("refusal %q does not name %q", err.Error(), needle) + } + } + if warnings != 0 { + t.Fatalf("refusal reported %d warnings instead of failing fast", warnings) + } +} + +func TestCallWarnsOnceOnDifferingBuild(t *testing.T) { + server := buildinfo.Info{Version: "v0-older-server", Commit: "deadbeef"} + endpoint := wstest.Server(t, func(protocol.Message) protocol.Message { + return protocol.Message{Type: protocol.Pong, Build: &server, Protocol: protocol.ProtocolVersion} + }) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + c, err := Open(ctx, endpoint) + if err != nil { + t.Fatal(err) + } + defer c.Close() + var messages []string + c.Report(func(relationship buildinfo.Relationship) { messages = append(messages, relationship.Message) }) + for i := 0; i < 3; i++ { + if _, err := c.Call(ctx, protocol.Message{Type: protocol.Ping}); err != nil { + t.Fatal(err) + } + } + if len(messages) != 1 { + t.Fatalf("differing build reported %d notices, want exactly one: %v", len(messages), messages) + } + client := buildinfo.Current() + for _, needle := range []string{client.Version, server.Version} { + if !strings.Contains(messages[0], needle) { + t.Fatalf("warning %q does not name %q", messages[0], needle) + } + } +} + +func TestCallReportsUnmodeledFieldOnce(t *testing.T) { + payload := map[string]any{"type": protocol.Pong, "future_field": true, "another": 2} + client := buildinfo.Current() + payload["build"] = client + payload["protocol"] = protocol.ProtocolVersion + endpoint := wstest.Raw(t, func(protocol.Message) map[string]any { return payload }) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + c, err := Open(ctx, endpoint) + if err != nil { + t.Fatal(err) + } + defer c.Close() + var notices []string + c.Report(func(relationship buildinfo.Relationship) { notices = append(notices, relationship.Message) }) + for i := 0; i < 2; i++ { + response, err := c.Call(ctx, protocol.Message{Type: protocol.Ping}) + if err != nil { + t.Fatal(err) + } + if response.Type != protocol.Pong { + t.Fatalf("unexpected response %+v", response) + } + } + if len(notices) != 1 { + t.Fatalf("unmodeled fields reported %d notices, want one: %v", len(notices), notices) + } + for _, needle := range []string{"another", "future_field", "unrecognized"} { + if !strings.Contains(notices[0], needle) { + t.Fatalf("unknown-field notice %q does not name %q", notices[0], needle) + } + } +} + +func TestReceiveNoticeDoesNotFlagFullyModeledFrames(t *testing.T) { + endpoint := wstest.Server(t, func(protocol.Message) protocol.Message { + server := buildinfo.Current() + return protocol.Message{Type: protocol.Pong, Build: &server, Protocol: protocol.ProtocolVersion} + }) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + c, err := Open(ctx, endpoint) + if err != nil { + t.Fatal(err) + } + defer c.Close() + var notices int + c.Report(func(buildinfo.Relationship) { notices++ }) + if _, err := c.Call(ctx, protocol.Message{Type: protocol.Ping}); err != nil { + t.Fatal(err) + } + if notices != 0 { + t.Fatalf("an in-sync, fully modeled frame produced %d notices", notices) + } +} diff --git a/internal/pipeline/human_test.go b/internal/pipeline/human_test.go new file mode 100644 index 00000000..7ee91f9c --- /dev/null +++ b/internal/pipeline/human_test.go @@ -0,0 +1,207 @@ +package pipeline + +import ( + "context" + "path/filepath" + "strings" + "testing" + + "git.a-wan.net/alan/pipelines/internal/protocol" +) + +const humanSource = "# stage gate\n\n```output\nDecision evidence.\n```\n\n```prompt\nReview the screenshots and choose.\n```\n\n```edges\ndeploy -> worker\nrevise -> worker\nerror -> #failure\n```\n\n```configs\ntype=human\n```\n\n# stage worker\n\n```output\nWork result.\n```\n\n```prompt\nDo the work.\n```\n\n```edges\nsuccess -> #success\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=opencode-go\nmodel=deepseek-v4.1-flash\nretries=2\ntimeout=1h\n```\n\n" + +func TestHumanStageAuthoringRoundTrip(t *testing.T) { + graph, err := Parse(humanSource) + if err != nil { + t.Fatal(err) + } + if len(graph.Stages) != 2 || graph.Stages[0].Type != "human" { + t.Fatalf("human type not parsed: %+v", graph.Stages) + } + gate := graph.Stages[0] + if strings.TrimSpace(gate.Prompt) == "" || gate.Edges["deploy"] != "worker" { + t.Fatalf("human stage fields lost: %+v", gate) + } + + ctx := context.Background() + store, err := Open(filepath.Join(t.TempDir(), "human.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err := store.Submit(ctx, "human", humanSource); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + definition, err := store.Get(ctx, items[0].ID, 1) + if err != nil { + t.Fatal(err) + } + if definition.Source != humanSource { + t.Fatal("immutable source was rewritten") + } + if definition.Graph.Stages[0].Type != "human" { + t.Fatalf("human type lost in stored graph: %+v", definition.Graph.Stages[0]) + } +} + +func humanRun(t *testing.T, ctx context.Context, store *Store) (int64, string) { + t.Helper() + if _, err := store.Submit(ctx, "humangate", humanSource); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + definition, err := store.Get(ctx, items[0].ID, 1) + if err != nil { + t.Fatal(err) + } + id, _, err := store.CreateRun(ctx, definition, "humangate-run", "workspace", false, nil, map[string]any{"prompt": "task"}) + if err != nil { + t.Fatal(err) + } + if err := store.BeginStep(ctx, id, 1, "gate", map[string]any{"prompt": "task"}); err != nil { + t.Fatal(err) + } + evidence := protocol.NewWaitingEvidence("Review the screenshots and choose.", []string{"deploy", "revise"}) + if err := store.MarkWaiting(ctx, id, 1, "gate", evidence); err != nil { + t.Fatal(err) + } + return id, "gate" +} + +func TestMarkWaitingPersistsDurableWait(t *testing.T) { + ctx := context.Background() + store, err := Open(filepath.Join(t.TempDir(), "wait.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + id, _ := humanRun(t, ctx, store) + + detail, err := store.GetRun(ctx, id) + if err != nil { + t.Fatal(err) + } + if detail.Status != protocol.RunStatusWaiting || detail.CurrentStage != "gate" || detail.FinishedAt != "" { + t.Fatalf("run did not report waiting: %+v", detail.RunSummary) + } + if len(detail.Steps) != 1 || detail.Steps[0].Status != protocol.StepStatusWaiting || detail.Steps[0].FinishedAt != "" { + t.Fatalf("step did not persist waiting: %+v", detail.Steps) + } + if prompt := protocol.WaitingPrompt(detail.Steps[0].Output); prompt == "" { + t.Fatalf("waiting evidence lost its prompt: %+v", detail.Steps[0].Output) + } + if options := protocol.WaitingOptions(detail.Steps[0].Output); len(options) != 2 { + t.Fatalf("waiting evidence lost its options: %+v", options) + } + + // Recovery from persisted rows must leave a waiting run and step untouched. + if err := store.RecoverRuns(ctx); err != nil { + t.Fatal(err) + } + recovered, err := store.GetRun(ctx, id) + if err != nil { + t.Fatal(err) + } + if recovered.Status != protocol.RunStatusWaiting || recovered.Steps[0].Status != protocol.StepStatusWaiting { + t.Fatalf("RecoverRuns disturbed a waiting run: %+v", recovered.RunSummary) + } +} + +func TestResolveDecisionValidUnknownRepeatAndNotWaiting(t *testing.T) { + ctx := context.Background() + store, err := Open(filepath.Join(t.TempDir(), "decide.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + id, _ := humanRun(t, ctx, store) + + if _, _, err := store.ResolveDecision(ctx, id, "", "launch", ""); err == nil || !strings.Contains(err.Error(), "valid options") || !strings.Contains(err.Error(), "deploy") { + t.Fatalf("unknown option not refused with the valid list: %v", err) + } + + step, applied, err := store.ResolveDecision(ctx, id, "", "deploy", "looks good, ship it") + if err != nil || !applied { + t.Fatalf("valid decision failed: %+v %v %v", step, applied, err) + } + if step.Outcome != "deploy" || step.Target != "worker" { + t.Fatalf("decision did not route along the edge: %+v", step) + } + detail, err := store.GetRun(ctx, id) + if err != nil { + t.Fatal(err) + } + if detail.Status != "running" || detail.Steps[0].Status != "completed" || detail.Steps[0].Outcome != "deploy" { + t.Fatalf("decision not persisted: %+v", detail) + } + if detail.Steps[0].Diagnostic != "" { + t.Fatalf("a deliberate decision must not be recorded as a stop: %+v", detail.Steps[0]) + } + if detail.Steps[0].Output["option"] != "deploy" || detail.Steps[0].Output["feedback"] != "looks good, ship it" { + t.Fatalf("feedback not recorded in the output: %+v", detail.Steps[0]) + } + verdict := detail.Steps[0].Verdict + if verdict == nil || verdict.Option != "deploy → worker" || verdict.Reason != "looks good, ship it" { + t.Fatalf("derived verdict missing the choice or feedback: %+v", verdict) + } + + // A repeated decision for the already-decided visit must not double-apply. + repeat, applied, err := store.ResolveDecision(ctx, id, "", "deploy", "second try") + if err != nil || applied { + t.Fatalf("repeat decision double-applied: applied=%v err=%v", applied, err) + } + if repeat.Sequence != step.Sequence { + t.Fatalf("repeat decision pointed at another visit: %+v", repeat) + } + // A different option for the same decided visit is refused. + if _, _, err := store.ResolveDecision(ctx, id, "", "revise", ""); err == nil || !strings.Contains(err.Error(), "not waiting") { + t.Fatalf("deciding a decided visit with another option was accepted: %v", err) + } + // A run whose graph has no human stage cannot be decided. + if _, err := store.Submit(ctx, "plain", Template([]string{"one"}, true)); err != nil { + t.Fatal(err) + } + plainItems, _ := store.List(ctx) + var plain protocol.PipelineSummary + for _, p := range plainItems { + if p.Name == "plain" { + plain = p + } + } + plainDef, err := store.Get(ctx, plain.ID, 1) + if err != nil { + t.Fatal(err) + } + plainRun, _, err := store.CreateRun(ctx, plainDef, "plain-run", "workspace", false, nil, map[string]any{"prompt": "task"}) + if err != nil { + t.Fatal(err) + } + if _, _, err := store.ResolveDecision(ctx, plainRun, "", "success", ""); err == nil { + t.Fatal("decision on a run with no human stage was accepted") + } +} + +func TestCancelWaitingRun(t *testing.T) { + ctx := context.Background() + store, err := Open(filepath.Join(t.TempDir(), "cancel.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + id, _ := humanRun(t, ctx, store) + if err := store.CancelWaiting(ctx, id); err != nil { + t.Fatal(err) + } + detail, err := store.GetRun(ctx, id) + if err != nil { + t.Fatal(err) + } + if detail.Status != "canceled" || detail.Steps[0].Status != "canceled" { + t.Fatalf("waiting run not canceled: %+v %+v", detail.RunSummary, detail.Steps) + } + if err := store.CancelWaiting(ctx, id); err == nil { + t.Fatal("canceling an already-canceled run succeeded") + } +} diff --git a/internal/pipeline/notify.go b/internal/pipeline/notify.go index 124c0502..442cd029 100644 --- a/internal/pipeline/notify.go +++ b/internal/pipeline/notify.go @@ -49,7 +49,7 @@ func parseNotify(text string) (*protocol.NotificationPolicy, error) { return result, nil } var err error - p.On, err = parse(values["on"], map[string]bool{"success": true, "failure": true}) + p.On, err = parse(values["on"], map[string]bool{"success": true, "failure": true, protocol.NotifyWaiting: true}) if err != nil { return nil, err } diff --git a/internal/pipeline/runs.go b/internal/pipeline/runs.go index dc8a2ac8..fa01763e 100644 --- a/internal/pipeline/runs.go +++ b/internal/pipeline/runs.go @@ -6,15 +6,18 @@ import ( "database/sql" "encoding/json" "fmt" + "strings" "git.a-wan.net/alan/pipelines/internal/protocol" "git.a-wan.net/alan/pipelines/internal/stage" + "git.a-wan.net/alan/pipelines/internal/summarise" ) func (s *Store) initRuns() error { _, err := s.db.Exec(`CREATE TABLE IF NOT EXISTS pipeline_runs ( id INTEGER PRIMARY KEY, pipeline_id INTEGER NOT NULL, version INTEGER NOT NULL, request_key TEXT NOT NULL UNIQUE, workspace TEXT NOT NULL, allow_tools INTEGER NOT NULL, +title TEXT NOT NULL DEFAULT '', title_source TEXT NOT NULL DEFAULT '', title_model TEXT NOT NULL DEFAULT '', write_paths TEXT NOT NULL, input_json TEXT NOT NULL, output_json TEXT NOT NULL DEFAULT '{}', status TEXT NOT NULL DEFAULT 'queued', outcome TEXT NOT NULL DEFAULT '', current_stage TEXT NOT NULL DEFAULT '', diagnostic TEXT NOT NULL DEFAULT '', created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, finished_at TEXT, @@ -39,15 +42,73 @@ PRIMARY KEY(run_id,sequence), FOREIGN KEY(run_id,sequence) REFERENCES run_steps( CREATE TABLE IF NOT EXISTS step_artifacts ( run_id INTEGER NOT NULL, sequence INTEGER NOT NULL, artifacts_json TEXT NOT NULL, PRIMARY KEY(run_id,sequence), FOREIGN KEY(run_id,sequence) REFERENCES run_steps(run_id,sequence)); +CREATE TABLE IF NOT EXISTS step_verdicts ( +run_id INTEGER NOT NULL, sequence INTEGER NOT NULL, verdict_json TEXT NOT NULL, +PRIMARY KEY(run_id,sequence), FOREIGN KEY(run_id,sequence) REFERENCES run_steps(run_id,sequence)); CREATE TABLE IF NOT EXISTS run_session_owners ( run_id INTEGER NOT NULL, sequence INTEGER NOT NULL, backend TEXT NOT NULL, reference TEXT NOT NULL DEFAULT '', PRIMARY KEY(run_id,sequence), FOREIGN KEY(run_id,sequence) REFERENCES run_steps(run_id,sequence)); CREATE TABLE IF NOT EXISTS run_retries ( run_id INTEGER PRIMARY KEY REFERENCES pipeline_runs(id), original_run_id INTEGER NOT NULL REFERENCES pipeline_runs(id));`) + if err != nil { + return err + } + return s.migrateRunTitles() +} + +// migrateRunTitles adds the title columns to a database created before run +// titles existed. Adding a column with a default leaves every existing row valid +// and untouched, so old runs still list. +func (s *Store) migrateRunTitles() error { + for _, column := range [][2]string{ + {"title", "TEXT NOT NULL DEFAULT ''"}, + {"title_source", "TEXT NOT NULL DEFAULT ''"}, + {"title_model", "TEXT NOT NULL DEFAULT ''"}, + } { + if err := s.addColumnIfMissing("pipeline_runs", column[0], column[1]); err != nil { + return err + } + } + return nil +} + +// addColumnIfMissing adds a column only when the table predates it, making an +// upgrade idempotent across repeated Open calls without rewriting history. +func (s *Store) addColumnIfMissing(table, column, definition string) error { + rows, err := s.db.Query("PRAGMA table_info(" + table + ")") + if err != nil { + return err + } + defer rows.Close() + for rows.Next() { + var cid, notnull, pk int + var name, ctype string + var dflt sql.NullString + if err := rows.Scan(&cid, &name, &ctype, ¬null, &dflt, &pk); err != nil { + return err + } + if name == column { + return nil + } + } + if err := rows.Err(); err != nil { + return err + } + _, err = s.db.Exec("ALTER TABLE " + table + " ADD COLUMN " + column + " " + definition) return err } +// CreateRun inserts a run and derives its title from the prompt. It is the entry +// point for callers with no generated title; the derived fallback is always +// non-empty and never calls a model. func (s *Store) CreateRun(ctx context.Context, d *protocol.PipelineDetail, key, workspace string, tools bool, paths []string, input map[string]any, retryOf ...int64) (int64, bool, error) { + return s.CreateRunTitled(ctx, d, key, workspace, tools, paths, input, summarise.Title{}, retryOf...) +} + +// CreateRunTitled inserts a run with the caller's title. A non-empty title (a +// model generation) is stored verbatim; an empty one falls back to the +// prompt-derived title, so a run never stores an empty title. +func (s *Store) CreateRunTitled(ctx context.Context, d *protocol.PipelineDetail, key, workspace string, tools bool, paths []string, input map[string]any, title summarise.Title, retryOf ...int64) (int64, bool, error) { var parent int64 if len(retryOf) > 0 { parent = retryOf[0] @@ -55,6 +116,7 @@ func (s *Store) CreateRun(ctx context.Context, d *protocol.PipelineDetail, key, if parent < 0 { return 0, false, fmt.Errorf("invalid retry parent") } + title = resolveRunTitle(title, input) encoded, err := json.Marshal(input) if err != nil { return 0, false, err @@ -88,7 +150,7 @@ func (s *Store) CreateRun(ctx context.Context, d *protocol.PipelineDetail, key, return 0, false, err } defer tx.Rollback() - result, err := tx.ExecContext(ctx, "INSERT INTO pipeline_runs(pipeline_id,version,request_key,workspace,allow_tools,write_paths,input_json) VALUES (?,?,?,?,?,?,?)", d.ID, d.Version, key, workspace, tools, string(writes), string(encoded)) + result, err := tx.ExecContext(ctx, "INSERT INTO pipeline_runs(pipeline_id,version,request_key,workspace,allow_tools,write_paths,input_json,title,title_source,title_model) VALUES (?,?,?,?,?,?,?,?,?,?)", d.ID, d.Version, key, workspace, tools, string(writes), string(encoded), title.Text, title.Source, title.Model) if err != nil { return 0, false, err } @@ -115,15 +177,45 @@ const runFrom = `FROM pipeline_runs r JOIN pipelines p ON p.id=r.pipeline_id` // and searchRuns instead of copied per query. const runStamps = `strftime('%Y-%m-%dT%H:%M:%SZ',r.created_at),COALESCE(strftime('%Y-%m-%dT%H:%M:%SZ',r.finished_at),'')` +// resolveRunTitle guarantees a stored run title is never empty: a title supplied +// by the caller (a model generation) is kept verbatim, and an absent one is +// derived from the prompt's first line. The fallback is server-owned and never +// calls a model, so it can never block or fail run creation. +func resolveRunTitle(title summarise.Title, input map[string]any) summarise.Title { + if strings.TrimSpace(title.Text) != "" { + return title + } + prompt, _ := input["prompt"].(string) + return summarise.Title{Text: summarise.DeriveTitle(prompt), Source: summarise.SourceFallback} +} + +// SetRunTitle replaces a run's operator-facing title and its provenance without +// touching the run's input, steps or execution. It is how an operator renames a +// run after the fact. +func (s *Store) SetRunTitle(ctx context.Context, id int64, title summarise.Title) error { + result, err := s.db.ExecContext(ctx, "UPDATE pipeline_runs SET title=?,title_source=?,title_model=? WHERE id=?", title.Text, title.Source, title.Model, id) + if err != nil { + return err + } + n, err := result.RowsAffected() + if err != nil { + return err + } + if n != 1 { + return fmt.Errorf("run not found") + } + return nil +} + const runSelect = `SELECT r.id,r.pipeline_id,p.name,r.version,v.content_hash,r.status,r.outcome,r.current_stage, ` + runStamps + `,r.diagnostic, CASE WHEN r.status='succeeded' THEN r.output_json ELSE COALESCE((SELECT output_json FROM run_steps WHERE run_id=r.id AND status='completed' ORDER BY sequence DESC LIMIT 1),'{}') END, -(SELECT COUNT(*) FROM run_steps WHERE run_id=r.id AND status='completed') +(SELECT COUNT(*) FROM run_steps WHERE run_id=r.id AND status='completed'),r.workspace,r.title ` + runFrom + ` JOIN pipeline_versions v ON v.pipeline_id=r.pipeline_id AND v.version=r.version` func scanRun(row interface{ Scan(...any) error }, r *protocol.RunSummary) error { var output string - if err := row.Scan(&r.ID, &r.PipelineID, &r.Name, &r.Version, &r.ContentHash, &r.Status, &r.Outcome, &r.CurrentStage, &r.CreatedAt, &r.FinishedAt, &r.Diagnostic, &output, &r.CompletedSteps); err != nil { + if err := row.Scan(&r.ID, &r.PipelineID, &r.Name, &r.Version, &r.ContentHash, &r.Status, &r.Outcome, &r.CurrentStage, &r.CreatedAt, &r.FinishedAt, &r.Diagnostic, &output, &r.CompletedSteps, &r.Workspace, &r.Title); err != nil { return err } var values map[string]any @@ -187,7 +279,7 @@ func (s *Store) GetRun(ctx context.Context, id int64) (*protocol.RunDetail, erro if err := json.Unmarshal([]byte(graphJSON), &r.Graph); err != nil { return nil, err } - if err := tx.QueryRowContext(ctx, "SELECT workspace,allow_tools,write_paths,input_json,output_json,COALESCE((SELECT original_run_id FROM run_retries WHERE run_id=pipeline_runs.id),0) FROM pipeline_runs WHERE id=?", id).Scan(&r.Workspace, &r.AllowTools, &paths, &input, &output, &r.RetryOf); err != nil { + if err := tx.QueryRowContext(ctx, "SELECT workspace,allow_tools,write_paths,input_json,output_json,COALESCE((SELECT original_run_id FROM run_retries WHERE run_id=pipeline_runs.id),0),title_source,title_model FROM pipeline_runs WHERE id=?", id).Scan(&r.Workspace, &r.AllowTools, &paths, &input, &output, &r.RetryOf, &r.TitleSource, &r.TitleModel); err != nil { return nil, err } if err := decodeValues(input, &r.Input); err != nil { @@ -203,6 +295,7 @@ func (s *Store) GetRun(ctx context.Context, id int64) (*protocol.RunDetail, erro COALESCE((SELECT receipts_json FROM step_notifications n WHERE n.run_id=run_steps.run_id AND n.sequence=run_steps.sequence),'[]'), COALESCE((SELECT changes_json FROM step_file_changes f WHERE f.run_id=run_steps.run_id AND f.sequence=run_steps.sequence),'null'), COALESCE((SELECT artifacts_json FROM step_artifacts a WHERE a.run_id=run_steps.run_id AND a.sequence=run_steps.sequence),'null'), +COALESCE((SELECT verdict_json FROM step_verdicts v WHERE v.run_id=run_steps.run_id AND v.sequence=run_steps.sequence),''), strftime('%Y-%m-%dT%H:%M:%SZ',started_at),COALESCE(strftime('%Y-%m-%dT%H:%M:%SZ',finished_at),'') FROM run_steps WHERE run_id=? ORDER BY sequence`, id) if err != nil { return nil, err @@ -211,8 +304,8 @@ strftime('%Y-%m-%dT%H:%M:%SZ',started_at),COALESCE(strftime('%Y-%m-%dT%H:%M:%SZ' for rows.Next() { var step protocol.RunStep var notifications string - var fileChanges, artifacts string - if err := rows.Scan(&step.Sequence, &step.Stage, &step.Status, &step.Outcome, &step.Target, &input, &output, &step.Diagnostic, &step.SessionID, &step.AgentActive, &step.Transcript, ¬ifications, &fileChanges, &artifacts, &step.StartedAt, &step.FinishedAt); err != nil { + var fileChanges, artifacts, storedVerdict string + if err := rows.Scan(&step.Sequence, &step.Stage, &step.Status, &step.Outcome, &step.Target, &input, &output, &step.Diagnostic, &step.SessionID, &step.AgentActive, &step.Transcript, ¬ifications, &fileChanges, &artifacts, &storedVerdict, &step.StartedAt, &step.FinishedAt); err != nil { rows.Close() return nil, err } @@ -242,6 +335,18 @@ strftime('%Y-%m-%dT%H:%M:%SZ',started_at),COALESCE(strftime('%Y-%m-%dT%H:%M:%SZ' rows.Close() return nil, err } + // The verdict is derived here - the one place that already holds both the + // decoded output and the recorded artifacts - using the stored model line + // when present and the bounded read-time fallback otherwise, so existing + // runs need no backfill. + var stored stageVerdictEvidence + if storedVerdict != "" { + if err := json.Unmarshal([]byte(storedVerdict), &stored); err != nil { + rows.Close() + return nil, err + } + } + step.Verdict = protocol.NewStageVerdict(step.Outcome, step.Target, step.Output, step.Artifacts, stored.Reason, stored.Source) // Loaded below after the rows cursor closes to preserve SQLite connection use. r.Steps = append(r.Steps, step) } @@ -416,6 +521,16 @@ type stageArtifactsEvidence struct { Truncated int `json:"truncated,omitempty"` } +// stageVerdictEvidence is the generated one-line verdict reason plus its +// provenance. Like the other step-scoped evidence it lives in its own table, so +// run_steps needs no schema migration and an old database gains the empty table +// on Open with no backfill. Only a model-generated line is ever stored; the +// read-time fallback is always derived, so existing runs still show a verdict. +type stageVerdictEvidence struct { + Reason string `json:"reason"` + Source string `json:"source"` +} + func (s *Store) FinishStep(ctx context.Context, id int64, step protocol.RunStep) error { output, err := json.Marshal(step.Output) if err != nil { @@ -461,6 +576,169 @@ WHERE run_id=? AND sequence=? AND status='running'`, step.Status, step.Outcome, return err } } + // Persist only a generated model line and its provenance; the read-time + // fallback is always derived in GetRun, so old runs stay intact. + if step.Verdict != nil && strings.TrimSpace(step.Verdict.Reason) != "" { + data, err := json.Marshal(stageVerdictEvidence{Reason: step.Verdict.Reason, Source: step.Verdict.ReasonSource}) + if err != nil { + return err + } + if _, err := tx.ExecContext(ctx, "INSERT INTO step_verdicts(run_id,sequence,verdict_json) VALUES(?,?,?) ON CONFLICT(run_id,sequence) DO UPDATE SET verdict_json=excluded.verdict_json", id, step.Sequence, string(data)); err != nil { + return err + } + } + return tx.Commit() +} + +// MarkWaiting persists a human stage's pending state in one transaction: the +// step becomes waiting with self-contained evidence (its operator instructions +// and ordered options) and the run reports the same key it is waiting on. It +// leaves finished_at NULL for both and adds no goroutine, timer or new column. +func (s *Store) MarkWaiting(ctx context.Context, id int64, sequence int, key string, evidence map[string]any) error { + data, err := json.Marshal(evidence) + if err != nil { + return err + } + tx, err := s.db.BeginTx(ctx, nil) + if err != nil { + return err + } + defer tx.Rollback() + if err := affected(tx.ExecContext(ctx, `UPDATE run_steps SET status=?,output_json=? WHERE run_id=? AND sequence=? AND status='running'`, + protocol.StepStatusWaiting, string(data), id, sequence)); err != nil { + return err + } + if err := affected(tx.ExecContext(ctx, `UPDATE pipeline_runs SET status=?,current_stage=? WHERE id=? AND status IN ('queued','running')`, + protocol.RunStatusWaiting, key, id)); err != nil { + return err + } + return tx.Commit() +} + +// ResolveDecision records an operator's choice for a waiting human stage and +// routes the run along that option's edge, all in one short transaction. It +// reads the pinned graph and the pending step from persisted rows, so it is +// correct after a restart and needs no live goroutine. Validation is idempotent: +// a repeated decision for an already-decided visit with the same option returns +// applied=false and no error, an unknown option is refused with the valid list, +// and a stage that is not waiting is refused with its current state. +func (s *Store) ResolveDecision(ctx context.Context, id int64, stageKey, option, feedback string) (protocol.RunStep, bool, error) { + tx, err := s.db.BeginTx(ctx, nil) + if err != nil { + return protocol.RunStep{}, false, err + } + defer tx.Rollback() + var status, currentStage, graphJSON string + if err := tx.QueryRowContext(ctx, `SELECT r.status,r.current_stage,v.graph_json FROM pipeline_runs r +JOIN pipeline_versions v ON v.pipeline_id=r.pipeline_id AND v.version=r.version WHERE r.id=?`, id).Scan(&status, ¤tStage, &graphJSON); err != nil { + if err == sql.ErrNoRows { + return protocol.RunStep{}, false, fmt.Errorf("run not found") + } + return protocol.RunStep{}, false, err + } + if stageKey == "" { + stageKey = currentStage + // Prefer the actual waiting step's stage; current_stage is normally the + // waiting stage, but this keeps the decision correct if it ever drifts. + var waitingKey string + if err := tx.QueryRowContext(ctx, `SELECT stage_key FROM run_steps WHERE run_id=? AND status=? ORDER BY sequence DESC LIMIT 1`, id, protocol.StepStatusWaiting).Scan(&waitingKey); err == nil { + stageKey = waitingKey + } else if err != sql.ErrNoRows { + return protocol.RunStep{}, false, err + } + } + var graph protocol.Graph + if err := json.Unmarshal([]byte(graphJSON), &graph); err != nil { + return protocol.RunStep{}, false, err + } + var edges map[string]string + found := false + for _, declared := range graph.Stages { + if declared.Key == stageKey { + edges = declared.Edges + found = true + break + } + } + if !found { + return protocol.RunStep{}, false, fmt.Errorf("stage %q is not part of this run", stageKey) + } + options := stage.HumanOptions(edges) + valid := false + for _, candidate := range options { + if candidate == option { + valid = true + break + } + } + if !valid { + return protocol.RunStep{}, false, fmt.Errorf("unknown option %q for stage %s; valid options: %s", option, stageKey, strings.Join(options, ", ")) + } + var sequence int + var stepStatus, stepOutcome string + err = tx.QueryRowContext(ctx, `SELECT sequence,status,outcome FROM run_steps WHERE run_id=? AND stage_key=? ORDER BY sequence DESC LIMIT 1`, id, stageKey).Scan(&sequence, &stepStatus, &stepOutcome) + if err == sql.ErrNoRows { + return protocol.RunStep{}, false, fmt.Errorf("stage %s is not waiting", stageKey) + } + if err != nil { + return protocol.RunStep{}, false, err + } + if stepStatus != protocol.StepStatusWaiting { + if stepStatus == "completed" && stepOutcome == option { + return protocol.RunStep{Sequence: sequence, Stage: stageKey, Status: "completed", Outcome: stepOutcome, Target: edges[stepOutcome]}, false, nil + } + return protocol.RunStep{}, false, fmt.Errorf("stage %s is not waiting (state %s)", stageKey, stepStatus) + } + if status != protocol.RunStatusWaiting && status != protocol.RunStatusRunning { + return protocol.RunStep{}, false, fmt.Errorf("run %d is not waiting (state %s)", id, status) + } + target := edges[option] + // The operator's choice and feedback are the step's evidence. The feedback + // stays in the output only - never the step diagnostic - so a deliberate, + // successful decision is not presented as a stop or error; the derived + // verdict reads the feedback as the step's reason. + output := map[string]any{protocol.DecisionOptionKey: option, protocol.DecisionFeedbackKey: feedback} + encoded, err := json.Marshal(output) + if err != nil { + return protocol.RunStep{}, false, err + } + if err := affected(tx.ExecContext(ctx, `UPDATE run_steps SET status='completed',outcome=?,target=?,output_json=?,finished_at=CURRENT_TIMESTAMP +WHERE run_id=? AND sequence=? AND status=?`, option, target, string(encoded), id, sequence, protocol.StepStatusWaiting)); err != nil { + return protocol.RunStep{}, false, err + } + if err := affected(tx.ExecContext(ctx, `UPDATE pipeline_runs SET status='running' WHERE id=? AND status IN (?,?)`, id, protocol.RunStatusWaiting, protocol.RunStatusRunning)); err != nil { + return protocol.RunStep{}, false, err + } + if err := tx.Commit(); err != nil { + return protocol.RunStep{}, false, err + } + return protocol.RunStep{Sequence: sequence, Stage: stageKey, Status: "completed", Outcome: option, Target: target, Output: output}, true, nil +} + +// CancelWaiting cancels a run that is waiting on a person without a live +// goroutine. It is a single transaction that marks the run canceled and its +// waiting step canceled; a run that is not waiting is reported, not silently +// ignored. +func (s *Store) CancelWaiting(ctx context.Context, id int64) error { + tx, err := s.db.BeginTx(ctx, nil) + if err != nil { + return err + } + defer tx.Rollback() + res, err := tx.ExecContext(ctx, `UPDATE pipeline_runs SET status='canceled',finished_at=CURRENT_TIMESTAMP WHERE id=? AND status=?`, id, protocol.RunStatusWaiting) + if err != nil { + return err + } + n, err := res.RowsAffected() + if err != nil { + return err + } + if n != 1 { + return fmt.Errorf("run is not active or waiting") + } + if _, err := tx.ExecContext(ctx, `UPDATE run_steps SET status='canceled',diagnostic='Canceled while waiting for a decision',finished_at=CURRENT_TIMESTAMP WHERE run_id=? AND status=?`, id, protocol.StepStatusWaiting); err != nil { + return err + } return tx.Commit() } @@ -499,10 +777,10 @@ func (s *Store) RecoverRuns(ctx context.Context) error { return err } defer tx.Rollback() - if _, err := tx.ExecContext(ctx, "UPDATE run_steps SET status='interrupted',agent_active=0,diagnostic='Server stopped; stage was not resumed',finished_at=CURRENT_TIMESTAMP WHERE status='running' OR agent_active=1"); err != nil { + if _, err := tx.ExecContext(ctx, "UPDATE run_steps SET status='interrupted',agent_active=0,diagnostic='Server stopped; stage was not resumed',finished_at=CURRENT_TIMESTAMP WHERE (status='running' OR agent_active=1) AND status<>?", protocol.StepStatusWaiting); err != nil { return err } - if _, err := tx.ExecContext(ctx, "UPDATE pipeline_runs SET status='interrupted',diagnostic='Server stopped; run was not resumed',finished_at=CURRENT_TIMESTAMP WHERE status IN ('queued','running')"); err != nil { + if _, err := tx.ExecContext(ctx, "UPDATE pipeline_runs SET status='interrupted',diagnostic='Server stopped; run was not resumed',finished_at=CURRENT_TIMESTAMP WHERE status IN ('queued','running') AND status<>?", protocol.RunStatusWaiting); err != nil { return err } return tx.Commit() diff --git a/internal/pipeline/runs_test.go b/internal/pipeline/runs_test.go index ec165034..5edb8e70 100644 --- a/internal/pipeline/runs_test.go +++ b/internal/pipeline/runs_test.go @@ -5,7 +5,10 @@ import ( "fmt" "path/filepath" "reflect" + "strings" "testing" + + "git.a-wan.net/alan/pipelines/internal/summarise" ) func TestRunListIncludesHistoryBeyondFiftyForSearchAndPipelineScope(t *testing.T) { @@ -37,6 +40,126 @@ func TestRunListIncludesHistoryBeyondFiftyForSearchAndPipelineScope(t *testing.T } } +// TestRunTitleStorageMigrationAndFallback proves the three title contracts: an +// explicit title is kept verbatim, an absent one is derived bounded and +// non-empty, and runs created before the title columns survive the migration and +// still list. +func TestRunTitleStorageMigrationAndFallback(t *testing.T) { + ctx := context.Background() + path := filepath.Join(t.TempDir(), "titles.db") + store, err := Open(path) + if err != nil { + t.Fatal(err) + } + if _, err := store.Submit(ctx, "titled", Template([]string{"one"}, true)); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + definition, _ := store.Get(ctx, items[0].ID, 1) + + explicit, _, err := store.CreateRunTitled(ctx, definition, "explicit", "workspace", false, nil, + map[string]any{"prompt": "a prompt that must not become the title"}, + summarise.Title{Text: "Fix the flaky login test", Source: summarise.SourceModel, Model: "openai/gpt"}) + if err != nil { + t.Fatal(err) + } + got, err := store.GetRun(ctx, explicit) + if err != nil { + t.Fatal(err) + } + if got.Title != "Fix the flaky login test" || got.TitleSource != summarise.SourceModel || got.TitleModel != "openai/gpt" { + t.Fatalf("explicit title not kept verbatim with its provenance: %+v", got) + } + + derived, _, err := store.CreateRun(ctx, definition, "derived", "workspace", false, nil, + map[string]any{"prompt": strings.Repeat("é", 500) + "\nsecond line is ignored"}) + if err != nil { + t.Fatal(err) + } + got, err = store.GetRun(ctx, derived) + if err != nil { + t.Fatal(err) + } + if got.Title == "" || got.TitleSource != summarise.SourceFallback || got.TitleModel != "" { + t.Fatalf("derived title = %+v, want a non-empty fallback with no model", got) + } + if len([]rune(got.Title)) > summarise.TitleCap { + t.Fatalf("derived title has %d runes, want <= %d", len([]rune(got.Title)), summarise.TitleCap) + } + + // Simulate a database created before run titles by removing the columns, then + // reopen: existing rows must survive the re-add migration and still list. + for _, column := range []string{"title", "title_source", "title_model"} { + if _, err := store.db.ExecContext(ctx, "ALTER TABLE pipeline_runs DROP COLUMN "+column); err != nil { + t.Fatal(err) + } + } + if err := store.Close(); err != nil { + t.Fatal(err) + } + store, err = Open(path) + if err != nil { + t.Fatal(err) + } + defer store.Close() + runs, err := store.ListRuns(ctx) + if err != nil { + t.Fatal("legacy runs did not survive the title migration", err) + } + ids := map[int64]bool{} + for _, run := range runs { + ids[run.ID] = true + } + if !ids[explicit] || !ids[derived] { + t.Fatalf("migrated run list lost history: %+v", runs) + } + migrated, err := store.GetRun(ctx, explicit) + if err != nil || migrated.Title != "" || migrated.TitleSource != "" || migrated.TitleModel != "" { + t.Fatalf("migrated row should keep a valid empty title: %+v %v", migrated, err) + } +} + +// TestSetRunTitleRenamesWithoutTouchingInput proves an after-the-fact rename +// replaces the stored title and its provenance and leaves the run's input, +// status and steps untouched; an unknown run is reported, not silently ignored. +func TestSetRunTitleRenamesWithoutTouchingInput(t *testing.T) { + ctx := context.Background() + store, err := Open(filepath.Join(t.TempDir(), "rename.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err := store.Submit(ctx, "rename", Template([]string{"one"}, true)); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + definition, _ := store.Get(ctx, items[0].ID, 1) + id, _, err := store.CreateRun(ctx, definition, "rename-key", "workspace", false, nil, map[string]any{"prompt": "original derived prompt"}) + if err != nil { + t.Fatal(err) + } + before, err := store.GetRun(ctx, id) + if err != nil { + t.Fatal(err) + } + if err := store.SetRunTitle(ctx, id, summarise.Title{Text: "Investigate the regression", Source: summarise.SourceExplicit}); err != nil { + t.Fatal(err) + } + after, err := store.GetRun(ctx, id) + if err != nil { + t.Fatal(err) + } + if after.Title != "Investigate the regression" || after.TitleSource != summarise.SourceExplicit || after.TitleModel != "" { + t.Fatalf("rename = %+v, want the explicit title and provenance", after) + } + if after.Status != before.Status || !reflect.DeepEqual(after.Input, before.Input) || len(after.Steps) != len(before.Steps) { + t.Fatalf("rename changed run state: before %+v after %+v", before, after) + } + if err := store.SetRunTitle(ctx, id+999, summarise.Title{Text: "ghost", Source: summarise.SourceExplicit}); err == nil { + t.Fatal("renaming an unknown run succeeded") + } +} + func TestRunRecoveryAndVersionPinning(t *testing.T) { ctx := context.Background() path := filepath.Join(t.TempDir(), "audit.db") diff --git a/internal/pipeline/verdict_test.go b/internal/pipeline/verdict_test.go new file mode 100644 index 00000000..e5c54baa --- /dev/null +++ b/internal/pipeline/verdict_test.go @@ -0,0 +1,206 @@ +package pipeline + +import ( + "context" + "path/filepath" + "testing" + + "git.a-wan.net/alan/pipelines/internal/protocol" +) + +// storeWithRun submits one pipeline and creates one run for verdict tests. +func storeWithRun(t *testing.T, name string) (*Store, context.Context, int64) { + t.Helper() + ctx := context.Background() + store, err := Open(filepath.Join(t.TempDir(), name+".db")) + if err != nil { + t.Fatal(err) + } + if _, err := store.Submit(ctx, name, Template([]string{"one", "two"}, true)); err != nil { + t.Fatal(err) + } + items, err := store.List(ctx) + if err != nil { + t.Fatal(err) + } + definition, err := store.Get(ctx, items[0].ID, 1) + if err != nil { + t.Fatal(err) + } + id, _, err := store.CreateRun(ctx, definition, name, "workspace", false, nil, map[string]any{"prompt": "task"}) + if err != nil { + t.Fatal(err) + } + return store, ctx, id +} + +// TestStageVerdictStoredLineAndReadTimeFallback proves a model-generated line is +// stored with its provenance and read back verbatim, while a step finished +// without one gets a bounded reason derived at read time from its own output (the +// existing-run/no-backfill path). +func TestStageVerdictStoredLineAndReadTimeFallback(t *testing.T) { + store, ctx, id := storeWithRun(t, "verdict") + defer store.Close() + if err := store.BeginStep(ctx, id, 1, "one", nil); err != nil { + t.Fatal(err) + } + if err := store.FinishStep(ctx, id, protocol.RunStep{ + Sequence: 1, Stage: "one", Status: "completed", Outcome: "success", Target: "two", + Output: map[string]any{"summary": "read-time text must lose to the stored line"}, + Verdict: &protocol.StageVerdict{Reason: "the model line", ReasonSource: protocol.VerdictReasonModel}, + }); err != nil { + t.Fatal(err) + } + if err := store.BeginStep(ctx, id, 2, "two", nil); err != nil { + t.Fatal(err) + } + if err := store.FinishStep(ctx, id, protocol.RunStep{ + Sequence: 2, Stage: "two", Status: "completed", Outcome: "success", Target: "#success", + Output: map[string]any{"summary": "derived at read time"}, + }); err != nil { + t.Fatal(err) + } + detail, err := store.GetRun(ctx, id) + if err != nil { + t.Fatal(err) + } + if len(detail.Steps) != 2 { + t.Fatalf("got %d steps", len(detail.Steps)) + } + stored := detail.Steps[0].Verdict + if stored == nil || stored.Reason != "the model line" || stored.ReasonSource != protocol.VerdictReasonModel || + stored.Option != "success → two" { + t.Fatalf("stored verdict = %+v", stored) + } + fallback := detail.Steps[1].Verdict + if fallback == nil || fallback.Reason != "derived at read time" || + fallback.ReasonSource != protocol.VerdictReasonFallback || fallback.Option != "success → success" { + t.Fatalf("read-time verdict = %+v", fallback) + } +} + +// TestStageVerdictMatchingUsesRecordedArtifacts proves the store derives the +// referenced artifacts from the artifacts it recorded for the same visit, by +// reason text and by screenshots, and never exposes an unrecorded name. +func TestStageVerdictMatchingUsesRecordedArtifacts(t *testing.T) { + store, ctx, id := storeWithRun(t, "verdict-artifacts") + defer store.Close() + if err := store.BeginStep(ctx, id, 1, "one", nil); err != nil { + t.Fatal(err) + } + if err := store.FinishStep(ctx, id, protocol.RunStep{ + Sequence: 1, Stage: "one", Status: "completed", Outcome: "success", Target: "two", + Output: map[string]any{"summary": "reviewed captures/shot.png and verified it"}, + Artifacts: []protocol.StageArtifact{{Name: "captures/shot.png"}, {Name: "unrelated.log"}}, + }); err != nil { + t.Fatal(err) + } + if err := store.BeginStep(ctx, id, 2, "two", nil); err != nil { + t.Fatal(err) + } + if err := store.FinishStep(ctx, id, protocol.RunStep{ + Sequence: 2, Stage: "two", Status: "completed", Outcome: "success", Target: "#success", + Output: map[string]any{"summary": "no recorded name here", "screenshots": []any{"captures/shot.png"}}, + Artifacts: []protocol.StageArtifact{{Name: "captures/shot.png"}}, + }); err != nil { + t.Fatal(err) + } + detail, err := store.GetRun(ctx, id) + if err != nil { + t.Fatal(err) + } + if got := detail.Steps[0].Verdict.Artifacts; len(got) != 1 || got[0] != "captures/shot.png" { + t.Fatalf("reason-referenced artifacts = %v, want only the recorded capture", got) + } + if got := detail.Steps[1].Verdict.Artifacts; len(got) != 1 || got[0] != "captures/shot.png" { + t.Fatalf("screenshot-referenced artifacts = %v, want only the recorded capture", got) + } +} + +// TestStageVerdictAbsentAndNoArtifacts proves a running step has no verdict and a +// completed step with no recorded artifacts keeps Option and Reason but an empty +// artifact list. +func TestStageVerdictAbsentAndNoArtifacts(t *testing.T) { + store, ctx, id := storeWithRun(t, "verdict-absent") + defer store.Close() + if err := store.BeginStep(ctx, id, 1, "one", nil); err != nil { + t.Fatal(err) + } + // Still running: no outcome/target, so no verdict. + detail, err := store.GetRun(ctx, id) + if err != nil { + t.Fatal(err) + } + if detail.Steps[0].Verdict != nil { + t.Fatalf("running step verdict = %+v, want nil", detail.Steps[0].Verdict) + } + if err := store.FinishStep(ctx, id, protocol.RunStep{ + Sequence: 1, Stage: "one", Status: "completed", Outcome: "success", Target: "#success", + Output: map[string]any{"summary": "done", "extra": "x"}, + }); err != nil { + t.Fatal(err) + } + detail, err = store.GetRun(ctx, id) + if err != nil { + t.Fatal(err) + } + verdict := detail.Steps[0].Verdict + if verdict == nil || verdict.Reason != "done" || verdict.ReasonSource != protocol.VerdictReasonFallback || len(verdict.Artifacts) != 0 { + t.Fatalf("no-artifact verdict = %+v", verdict) + } +} + +// TestStageVerdictStoreUpgrade proves a database created before step_verdicts +// exists opens cleanly, gains the table on init, and still lists and loads runs +// and steps. +func TestStageVerdictStoreUpgrade(t *testing.T) { + ctx := context.Background() + path := filepath.Join(t.TempDir(), "upgrade.db") + store, err := Open(path) + if err != nil { + t.Fatal(err) + } + if _, err := store.Submit(ctx, "upgrade", Template([]string{"one"}, true)); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + definition, _ := store.Get(ctx, items[0].ID, 1) + id, _, err := store.CreateRun(ctx, definition, "upgrade", "workspace", false, nil, nil) + if err != nil { + t.Fatal(err) + } + if err := store.BeginStep(ctx, id, 1, "one", nil); err != nil { + t.Fatal(err) + } + if err := store.FinishStep(ctx, id, protocol.RunStep{ + Sequence: 1, Stage: "one", Status: "completed", Outcome: "success", Target: "#success", + Output: map[string]any{"summary": "legacy output"}, + Verdict: &protocol.StageVerdict{Reason: "generated before the upgrade", ReasonSource: protocol.VerdictReasonModel}, + }); err != nil { + t.Fatal(err) + } + // Simulate a database created before step_verdicts existed. + if _, err := store.db.ExecContext(ctx, "DROP TABLE step_verdicts"); err != nil { + t.Fatal(err) + } + if err := store.Close(); err != nil { + t.Fatal(err) + } + store, err = Open(path) + if err != nil { + t.Fatal("a pre-verdict database did not open cleanly", err) + } + defer store.Close() + runs, err := store.ListRuns(ctx) + if err != nil || len(runs) != 1 { + t.Fatalf("legacy run list lost history: %v %v", runs, err) + } + detail, err := store.GetRun(ctx, id) + if err != nil || len(detail.Steps) != 1 { + t.Fatalf("legacy run/step did not load: %v %v", detail, err) + } + // The stored line is gone, so the verdict is derived at read time. + if verdict := detail.Steps[0].Verdict; verdict == nil || verdict.Reason != "legacy output" || verdict.ReasonSource != protocol.VerdictReasonFallback { + t.Fatalf("post-upgrade read-time verdict = %+v", verdict) + } +} diff --git a/internal/protocol/identity.go b/internal/protocol/identity.go new file mode 100644 index 00000000..1417498e --- /dev/null +++ b/internal/protocol/identity.go @@ -0,0 +1,60 @@ +package protocol + +import ( + "encoding/json" + "reflect" + "sort" + "strings" + "sync" +) + +// ProtocolVersion is the integer wire protocol this build speaks. Ordering +// between peers compares this integer; build strings are for naming only and are +// never parsed or sorted to infer ordering. +const ProtocolVersion = 1 + +// MaxSupportedProtocol is the newest server protocol this client can interpret. +// A server reporting a higher value is refused rather than silently misread. +const MaxSupportedProtocol = ProtocolVersion + +var ( + knownFieldsOnce sync.Once + knownFields map[string]struct{} +) + +// KnownFields returns the set of top-level JSON keys protocol.Message models, +// derived once from the struct tags and cached. The map is read-only. +func KnownFields() map[string]struct{} { + knownFieldsOnce.Do(func() { + knownFields = map[string]struct{}{} + message := reflect.TypeOf(Message{}) + for index := 0; index < message.NumField(); index++ { + name := strings.Split(message.Field(index).Tag.Get("json"), ",")[0] + if name == "" || name == "-" { + continue + } + knownFields[name] = struct{}{} + } + }) + return knownFields +} + +// UnknownFields returns the sorted top-level JSON keys in data that protocol.Message +// does not model. It performs one bounded map decode plus O(1) set lookups, so a +// forward-compatible frame is never a per-frame reflection walk. A frame that is +// not a JSON object (or cannot be parsed) reports no unknown fields. +func UnknownFields(data []byte) []string { + var raw map[string]json.RawMessage + if err := json.Unmarshal(data, &raw); err != nil { + return nil + } + known := KnownFields() + var unknown []string + for key := range raw { + if _, ok := known[key]; !ok { + unknown = append(unknown, key) + } + } + sort.Strings(unknown) + return unknown +} diff --git a/internal/protocol/identity_test.go b/internal/protocol/identity_test.go new file mode 100644 index 00000000..214e574a --- /dev/null +++ b/internal/protocol/identity_test.go @@ -0,0 +1,52 @@ +package protocol + +import ( + "fmt" + "reflect" + "testing" +) + +func TestUnknownFieldsReportsOnlyUnmodeledSortedKeys(t *testing.T) { + if got := UnknownFields([]byte(`{"type":"pong"}`)); got != nil { + t.Fatalf("fully modeled frame reported %v", got) + } + got := UnknownFields([]byte(`{"type":"pong","zzz":1,"aaa":2}`)) + if !reflect.DeepEqual(got, []string{"aaa", "zzz"}) { + t.Fatalf("unknown fields = %v, want sorted [aaa zzz]", got) + } +} + +func TestUnknownFieldsIgnoresMalformedAndNonObjectFrames(t *testing.T) { + for _, data := range []string{ + `not json`, + `[1,2,3]`, + `"a string"`, + `42`, + `null`, + } { + if got := UnknownFields([]byte(data)); got != nil { + t.Fatalf("frame %q reported unknown fields %v", data, got) + } + } +} + +func TestKnownFieldsCachesTheModeledKeySet(t *testing.T) { + first := KnownFields() + second := KnownFields() + if len(first) == 0 { + t.Fatal("known field set is empty") + } + if _, ok := first["type"]; !ok { + t.Fatal("known field set is missing the modeled type key") + } + if _, ok := first["build"]; !ok { + t.Fatal("known field set is missing the modeled build key") + } + if _, ok := first["protocol"]; !ok { + t.Fatal("known field set is missing the modeled protocol key") + } + // The sync.Once must return the same cached map on every call. + if fmt.Sprintf("%p", first) != fmt.Sprintf("%p", second) { + t.Fatal("KnownFields re-derived the set instead of using the cache") + } +} diff --git a/internal/protocol/message.go b/internal/protocol/message.go index 0a945f49..ff335408 100644 --- a/internal/protocol/message.go +++ b/internal/protocol/message.go @@ -102,10 +102,16 @@ type PipelineSummary struct { UpdatedAt string `json:"updated_at"` } -// Message is the JSON envelope shared by the server and client. +// Message is the JSON envelope shared by the server and client. It also carries +// the omni-search request/response: a client sends Type "search" with an ID, the +// Query text, an optional Kind type filter and an optional Limit, and the server +// replies with Type "search_results", the echoed ID and ranked Matches. Every +// search fields are optional so older peers ignore them. See search.go for the +// kind constants and wire-shape detail. type Message struct { DefaultHarness string `json:"default_harness,omitempty"` Build *buildinfo.Info `json:"build,omitempty"` + Protocol int `json:"protocol,omitempty"` DefaultModel string `json:"default_model,omitempty"` Evidence []SessionEvidence `json:"evidence,omitempty"` Usage *UsageStats `json:"usage,omitempty"` @@ -121,13 +127,19 @@ type Message struct { Error string `json:"error,omitempty"` Name string `json:"name,omitempty"` Source string `json:"source,omitempty"` + Title string `json:"title,omitempty"` Version int `json:"version,omitempty"` + Query string `json:"query,omitempty"` + Kind string `json:"kind,omitempty"` Pipelines []PipelineSummary `json:"pipelines,omitempty"` PipelineID int64 `json:"pipeline_id,omitempty"` Detail *PipelineDetail `json:"detail,omitempty"` RunID int64 `json:"run_id,omitempty"` RunDetail *RunDetail `json:"run_detail,omitempty"` Runs []RunSummary `json:"runs,omitempty"` + Stage string `json:"stage,omitempty"` + Option string `json:"option,omitempty"` + Feedback string `json:"feedback,omitempty"` Input map[string]any `json:"input,omitempty"` AllowTools bool `json:"allow_tools,omitempty"` WritePaths []string `json:"write_paths,omitempty"` diff --git a/internal/protocol/runs.go b/internal/protocol/runs.go index dc4c0880..02ab595c 100644 --- a/internal/protocol/runs.go +++ b/internal/protocol/runs.go @@ -1,5 +1,7 @@ package protocol +import "strings" + const ( RunPipeline = "run_pipeline" RunStarted = "run_started" @@ -9,10 +11,84 @@ const ( Run = "run" CancelRun = "cancel_run" RetryRun = "retry_run" + DecideRun = "decide_run" + SetRunTitle = "set_run_title" GetRunEvidence = "get_run_evidence" RunEvidence = "run_evidence" ) +// Waiting statuses. A human stage pauses its run without a live goroutine, so +// the run and its step persist these statuses and the decision path resumes +// them. Store, server, CLI and TUI read the one pair below, never a literal. +const ( + RunStatusWaiting = "waiting" + RunStatusRunning = "running" + StepStatusWaiting = "waiting" + // NotifyWaiting is the notification event a human stage emits when it parks + // the run. It is the same value the `on=` policy accepts. + NotifyWaiting = "waiting" +) + +// Waiting evidence keys. A human stage records its operator instructions and +// its ordered selectable options in the step output, so inspect and the TUI are +// self-contained without re-reading the pinned graph. +const ( + WaitingPromptKey = "prompt" + WaitingOptionsKey = "options" +) + +// Decision evidence keys. A decided human step records the operator's chosen +// option and optional feedback in its output, so the choice stays visible in +// inspect and the TUI. They are the one definition of those keys. +const ( + DecisionOptionKey = "option" + DecisionFeedbackKey = "feedback" +) + +// NewWaitingEvidence builds the self-contained evidence a human stage persists +// at wait time: the operator instructions and the ordered options to choose. +func NewWaitingEvidence(prompt string, options []string) map[string]any { + ordered := make([]any, len(options)) + for i, option := range options { + ordered[i] = option + } + return map[string]any{WaitingPromptKey: prompt, WaitingOptionsKey: ordered} +} + +// WaitingPrompt reads the recorded operator instructions from a waiting step's +// output, or "" when none were recorded. +func WaitingPrompt(output map[string]any) string { + prompt, _ := output[WaitingPromptKey].(string) + return prompt +} + +// WaitingOptions reads the recorded selectable options from a waiting step's +// output, accepting the string and generic forms JSON decoding produces. +func WaitingOptions(output map[string]any) []string { + switch options := output[WaitingOptionsKey].(type) { + case []string: + return options + case []any: + result := make([]string, 0, len(options)) + for _, option := range options { + if text, ok := option.(string); ok { + result = append(result, text) + } + } + return result + } + return nil +} + +// DecisionEvidence reads the recorded choice and feedback from a decided human +// step's output, or empty strings when none were recorded. It is the read side +// of DecisionOptionKey/DecisionFeedbackKey. +func DecisionEvidence(output map[string]any) (option, feedback string) { + option, _ = output[DecisionOptionKey].(string) + feedback, _ = output[DecisionFeedbackKey].(string) + return option, feedback +} + type SessionEvidence struct { Sequence int `json:"sequence"` SessionID string `json:"session_id"` @@ -23,15 +99,20 @@ type SessionEvidence struct { } type RunSummary struct { - ID int64 `json:"id"` - PipelineID int64 `json:"pipeline_id"` - Name string `json:"name"` + ID int64 `json:"id"` + PipelineID int64 `json:"pipeline_id"` + Name string `json:"name"` + // Title is the operator-facing, bounded single-line description of what the + // run is for, generated from its prompt. It is never empty for a new run; + // historical rows predating the title column may omit it. + Title string `json:"title,omitempty"` Version int `json:"version"` ContentHash string `json:"content_hash"` Status string `json:"status"` Executing bool `json:"executing"` Outcome string `json:"outcome"` CurrentStage string `json:"current_stage"` + Workspace string `json:"workspace,omitempty"` CreatedAt string `json:"created_at"` FinishedAt string `json:"finished_at"` Diagnostic string `json:"diagnostic"` @@ -39,9 +120,20 @@ type RunSummary struct { CompletedSteps int `json:"completed_steps"` } +// Label is the operator-facing name of a run: the generated Title when the +// server stored one, otherwise the pipeline Name (historical rows predate +// titles). It is the single definition shared by the CLI and TUI. +func (r RunSummary) Label() string { + if title := strings.TrimSpace(r.Title); title != "" { + return title + } + return r.Name +} + type RunStep struct { Control *ControlEvidence `json:"control,omitempty"` FileChanges *StageFileChanges `json:"file_changes,omitempty"` + Verdict *StageVerdict `json:"verdict,omitempty"` Notifications []NotificationReceipt `json:"notifications,omitempty"` Artifacts []StageArtifact `json:"artifacts,omitempty"` Sequence int `json:"sequence"` @@ -126,4 +218,10 @@ type RunDetail struct { Input map[string]any `json:"input"` Output map[string]any `json:"output"` Steps []RunStep `json:"steps"` + // TitleSource is "model" when Title came from the shared summariser or + // "fallback" when it was derived from the prompt; TitleModel names the model + // that produced a model title. They are retained so a diagnosis can tell the + // two apart and see which model was used. + TitleSource string `json:"title_source,omitempty"` + TitleModel string `json:"title_model,omitempty"` } diff --git a/internal/protocol/verdict.go b/internal/protocol/verdict.go new file mode 100644 index 00000000..c8e24b77 --- /dev/null +++ b/internal/protocol/verdict.go @@ -0,0 +1,191 @@ +package protocol + +import ( + "encoding/json" + "path" + "strings" +) + +// VerdictReasonKeys is the single ordered definition of the output keys a stage +// may use to state why it chose its outcome. The first key carrying usable text +// wins. Store, server and TUI all read this one list, so the order never drifts. +// "feedback" is last so it only states the reason when no model-authored key +// does: an operator's decision feedback is exactly the human stage's reason. +var VerdictReasonKeys = []string{"verdict", "reason", "decision", "summary", "implementation_summary", "feedback"} + +// VerdictReasonCap bounds a verdict reason to this many runes, whether it was +// generated by the model or derived at read time. It is the same cap the +// summariser's OutputCap uses (summarise references this constant), so the two +// cannot drift. +const VerdictReasonCap = 200 + +// Verdict reason provenance. ReasonSource tells a diagnosis whether the stored +// one-liner came from the model, was derived at read time, or is honestly absent. +const ( + VerdictReasonModel = "model" + VerdictReasonFallback = "fallback" + VerdictReasonAbsent = "absent" +) + +// StageVerdict is the plain-language outcome of one completed stage visit: the +// chosen option (the step's outcome and the target it routed to), a one-line +// reason with its provenance, and the recorded artifacts the reason refers to. A +// nil RunStep.Verdict means there is no verdict (for example a running step); an +// empty struct is never serialised. +type StageVerdict struct { + Option string `json:"option"` + Reason string `json:"reason,omitempty"` + ReasonSource string `json:"reason_source,omitempty"` + Artifacts []string `json:"artifacts,omitempty"` +} + +// DeriveVerdictReason reads the first usable reason line from a step's output in +// the shared key order. It accepts a string value, or JSON-encodes a non-string +// one (as OutputPreview does), normalises it to one safe line and bounds it to +// VerdictReasonCap runes. It returns "" when no key carries usable text and never +// synthesises a reason. +func DeriveVerdictReason(output map[string]any) string { + for _, key := range VerdictReasonKeys { + value, ok := output[key] + if !ok || value == nil { + continue + } + text, ok := value.(string) + if !ok { + encoded, err := json.Marshal(value) + if err != nil { + continue + } + text = string(encoded) + } + text = NormalizeText(text) + if text == "" || text == "[]" || text == "{}" { + continue + } + return capVerdictReason(text) + } + return "" +} + +// VerdictOption states a step's chosen option plainly: its outcome and the target +// it routed to, with the terminal shorthands rendered as words. +func VerdictOption(outcome, target string) string { + target = ResolveTarget(outcome, target) + switch target { + case SuccessEnd: + target = "success" + case FailureEnd: + target = "failure" + } + return outcome + " → " + target +} + +// ReferencedVerdictArtifacts returns the names of the artifacts actually recorded +// for a visit that the reason refers to, in their recorded order and deduplicated. +// A name is included when it (or its basename, for a slashed path) appears in the +// reason text, or when it is named in the output's screenshots list. Only recorded +// artifacts can be returned: a name the model invented that is not a real recorded +// file is never exposed. +func ReferencedVerdictArtifacts(reason string, output map[string]any, artifacts []StageArtifact) []string { + var names []string + seen := map[string]bool{} + for _, artifact := range artifacts { + name := artifact.Name + if name == "" || seen[name] { + continue + } + base := path.Base(name) + if !verdictMentionsArtifact(reason, name, base) && !screenshotsNameArtifact(output, name, base) { + continue + } + seen[name] = true + names = append(names, name) + } + return names +} + +// verdictMentionsArtifact reports whether the reason text names an artifact by its +// full recorded name or by its basename. +func verdictMentionsArtifact(reason, name, base string) bool { + if reason == "" { + return false + } + if strings.Contains(reason, name) { + return true + } + return base != name && strings.Contains(reason, base) +} + +// screenshotsNameArtifact reports whether the output's screenshots list names an +// artifact by its full recorded name or by its basename. The list may be a single +// string, a []string or a generic []any of strings. +func screenshotsNameArtifact(output map[string]any, name, base string) bool { + value, ok := output["screenshots"] + if !ok { + return false + } + for _, candidate := range screenshotNames(value) { + candidate = strings.TrimSpace(candidate) + if candidate != "" && (candidate == name || candidate == base) { + return true + } + } + return false +} + +// screenshotNames flattens a screenshots value to its string entries, accepting +// the single-string, []string and generic []any forms stages emit. +func screenshotNames(value any) []string { + switch typed := value.(type) { + case string: + return []string{typed} + case []string: + return typed + case []any: + names := make([]string, 0, len(typed)) + for _, item := range typed { + if name, ok := item.(string); ok { + names = append(names, name) + } + } + return names + } + return nil +} + +// NewStageVerdict builds the verdict for one stage visit. It returns nil when the +// step carries neither an outcome nor a target (a running step has no verdict). A +// stored model reason is kept with its provenance; otherwise the read-time +// fallback derives the reason from the output, or marks it absent when no key +// carries usable text. Referenced artifacts are matched against the recorded +// artifacts only. +func NewStageVerdict(outcome, target string, output map[string]any, artifacts []StageArtifact, storedReason, storedSource string) *StageVerdict { + if outcome == "" && target == "" { + return nil + } + verdict := &StageVerdict{Option: VerdictOption(outcome, target)} + if reason := strings.TrimSpace(storedReason); reason != "" { + verdict.Reason = capVerdictReason(reason) + verdict.ReasonSource = storedSource + if verdict.ReasonSource == "" { + verdict.ReasonSource = VerdictReasonModel + } + } else if reason := DeriveVerdictReason(output); reason != "" { + verdict.Reason = reason + verdict.ReasonSource = VerdictReasonFallback + } else { + verdict.ReasonSource = VerdictReasonAbsent + } + verdict.Artifacts = ReferencedVerdictArtifacts(verdict.Reason, output, artifacts) + return verdict +} + +// capVerdictReason bounds a reason to VerdictReasonCap runes without splitting a +// rune (rune slicing is inherently UTF-8-safe). +func capVerdictReason(text string) string { + runes := []rune(text) + if len(runes) <= VerdictReasonCap { + return text + } + return string(runes[:VerdictReasonCap]) +} diff --git a/internal/protocol/verdict_test.go b/internal/protocol/verdict_test.go new file mode 100644 index 00000000..4cec90a0 --- /dev/null +++ b/internal/protocol/verdict_test.go @@ -0,0 +1,176 @@ +package protocol + +import ( + "encoding/json" + "strings" + "testing" + "unicode/utf8" +) + +func TestRunStepVerdictRoundTrip(t *testing.T) { + step := RunStep{ + Sequence: 2, + Stage: "review", + Outcome: "success", + Target: "deliver", + Verdict: &StageVerdict{ + Option: "success → deliver", + Reason: "Tests passed and evidence is retained", + ReasonSource: VerdictReasonModel, + Artifacts: []string{"captures/shot.png"}, + }, + } + encoded, err := json.Marshal(step) + if err != nil { + t.Fatal(err) + } + var decoded RunStep + if err := json.Unmarshal(encoded, &decoded); err != nil { + t.Fatal(err) + } + if decoded.Verdict == nil { + t.Fatal("verdict lost in round trip") + } + if decoded.Verdict.Option != step.Verdict.Option || decoded.Verdict.Reason != step.Verdict.Reason || + decoded.Verdict.ReasonSource != step.Verdict.ReasonSource || + len(decoded.Verdict.Artifacts) != 1 || decoded.Verdict.Artifacts[0] != "captures/shot.png" { + t.Fatalf("verdict fields lost in round trip: %+v", decoded.Verdict) + } +} + +// TestRunStepOmitsAbsentVerdict mirrors TestRunStepOmitsAbsentArtifacts: a nil +// verdict marshals without the key (absent, not {}) and an absent key decodes nil. +func TestRunStepOmitsAbsentVerdict(t *testing.T) { + encoded, err := json.Marshal(RunStep{Sequence: 1, Stage: "one"}) + if err != nil { + t.Fatal(err) + } + if strings.Contains(string(encoded), "verdict") { + t.Fatalf("nil verdict must be omitted, not serialised: %s", encoded) + } + var decoded RunStep + if err := json.Unmarshal([]byte(`{"sequence":1}`), &decoded); err != nil { + t.Fatal(err) + } + if decoded.Verdict != nil { + t.Fatalf("absent verdict must decode nil: %+v", decoded.Verdict) + } +} + +func TestDeriveVerdictReasonKeyOrder(t *testing.T) { + cases := []struct { + name string + output map[string]any + want string + }{ + {"verdict wins", map[string]any{"summary": "s", "reason": "r", "verdict": "v"}, "v"}, + {"reason before decision", map[string]any{"summary": "s", "decision": "d", "reason": "r"}, "r"}, + {"decision before summary", map[string]any{"summary": "s", "decision": "d"}, "d"}, + {"summary before implementation_summary", map[string]any{"implementation_summary": "i", "summary": "s"}, "s"}, + {"implementation_summary alone", map[string]any{"implementation_summary": "i"}, "i"}, + {"non-string is encoded", map[string]any{"summary": 42}, "42"}, + {"empty values skipped to a later key", map[string]any{"reason": " ", "summary": "s"}, "s"}, + {"feedback states the reason when nothing else does", map[string]any{"option": "go", "feedback": "looks good"}, "looks good"}, + {"summary still wins over feedback", map[string]any{"summary": "s", "feedback": "f"}, "s"}, + {"none yields nothing", map[string]any{"other": "x", "screenshots": []any{"a.png"}}, ""}, + {"nil output yields nothing", nil, ""}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + if got := DeriveVerdictReason(tc.output); got != tc.want { + t.Fatalf("DeriveVerdictReason(%v) = %q, want %q", tc.output, got, tc.want) + } + }) + } +} + +func TestDeriveVerdictReasonIsBoundedRuneSafe(t *testing.T) { + long := strings.Repeat("é", VerdictReasonCap+50) + got := DeriveVerdictReason(map[string]any{"summary": long}) + if len([]rune(got)) != VerdictReasonCap { + t.Fatalf("got %d runes, want the %d cap", len([]rune(got)), VerdictReasonCap) + } + if !utf8.ValidString(got) { + t.Fatal("bounded reason is not valid UTF-8") + } +} + +func TestNewStageVerdictBoundsStoredReasonRuneSafe(t *testing.T) { + long := strings.Repeat("é", VerdictReasonCap+50) + verdict := NewStageVerdict("success", "#success", nil, nil, long, VerdictReasonModel) + if verdict == nil || len([]rune(verdict.Reason)) != VerdictReasonCap || !utf8.ValidString(verdict.Reason) { + t.Fatalf("stored reason not bounded rune-safely: %+v", verdict) + } +} + +func TestVerdictOptionRendersTerminals(t *testing.T) { + cases := []struct{ outcome, target, want string }{ + {"success", "#success", "success → success"}, + {"error", "#failure", "error → failure"}, + {"success", "review", "success → review"}, + {"error", "#", "error → failure"}, + } + for _, tc := range cases { + if got := VerdictOption(tc.outcome, tc.target); got != tc.want { + t.Fatalf("VerdictOption(%q,%q) = %q, want %q", tc.outcome, tc.target, got, tc.want) + } + } +} + +func TestReferencedVerdictArtifactsMatchesRecordedOnly(t *testing.T) { + artifacts := []StageArtifact{{Name: "captures/shot.png"}, {Name: "report.txt"}, {Name: "unrelated.log"}} + // A name and a basename in the reason both match a recorded artifact; a name + // that is not recorded is never invented into the list. + got := ReferencedVerdictArtifacts("see captures/shot.png and the shot.png capture, plus ghost.png", nil, artifacts) + want := []string{"captures/shot.png"} + if len(got) != 1 || got[0] != want[0] { + t.Fatalf("reason matches = %v, want %v (missing.png is not a recorded file)", got, want) + } + // The screenshots list matches independently of the reason text. + got = ReferencedVerdictArtifacts("no file names here", map[string]any{"screenshots": []any{"unrelated.log"}}, artifacts) + if len(got) != 1 || got[0] != "unrelated.log" { + t.Fatalf("screenshots matches = %v, want unrelated.log", got) + } + // A single-string screenshots value is accepted too. + got = ReferencedVerdictArtifacts("", map[string]any{"screenshots": "report.txt"}, artifacts) + if len(got) != 1 || got[0] != "report.txt" { + t.Fatalf("string screenshots matches = %v, want report.txt", got) + } + // Duplicates are collapsed, and matches keep the recorded order. + dupes := []StageArtifact{{Name: "report.txt"}, {Name: "report.txt"}, {Name: "captures/shot.png"}} + got = ReferencedVerdictArtifacts("report.txt and captures/shot.png", nil, dupes) + if len(got) != 2 || got[0] != "report.txt" || got[1] != "captures/shot.png" { + t.Fatalf("deduped ordered matches = %v", got) + } + // A screenshots entry with no recorded match is never exposed. + if got := ReferencedVerdictArtifacts("", map[string]any{"screenshots": []any{"ghost.png"}}, artifacts); len(got) != 0 { + t.Fatalf("unrecorded screenshots entry exposed: %v", got) + } + // No reason, no screenshots: no artifacts. + if got := ReferencedVerdictArtifacts("", nil, artifacts); len(got) != 0 { + t.Fatalf("artifacts exposed without a reference: %v", got) + } +} + +func TestNewStageVerdict(t *testing.T) { + // A running step carries neither outcome nor target and has no verdict. + if got := NewStageVerdict("", "", nil, nil, "", ""); got != nil { + t.Fatalf("running step verdict = %+v, want nil", got) + } + // A completed visit with no recorded artifacts still carries Option and Reason. + got := NewStageVerdict("success", "review", map[string]any{"summary": "did the work"}, nil, "", "") + if got == nil || got.Option != "success → review" || got.Reason != "did the work" || + got.ReasonSource != VerdictReasonFallback || len(got.Artifacts) != 0 { + t.Fatalf("fallback verdict = %+v", got) + } + // A stored model line wins over the output and records its provenance. + got = NewStageVerdict("success", "review", map[string]any{"summary": "output text"}, nil, "the model line", VerdictReasonModel) + if got == nil || got.Reason != "the model line" || got.ReasonSource != VerdictReasonModel { + t.Fatalf("stored verdict = %+v", got) + } + // No usable reason key: honest absence with no invented text. + got = NewStageVerdict("success", "#success", map[string]any{"other": "x"}, nil, "", "") + if got == nil || got.Reason != "" || got.ReasonSource != VerdictReasonAbsent { + t.Fatalf("absent-reason verdict = %+v", got) + } +} diff --git a/internal/server/cli_test.go b/internal/server/cli_test.go index be541b4f..ad082ff1 100644 --- a/internal/server/cli_test.go +++ b/internal/server/cli_test.go @@ -11,6 +11,7 @@ import ( "git.a-wan.net/alan/pipelines/internal/protocol" "git.a-wan.net/alan/pipelines/internal/runinspect" "git.a-wan.net/alan/pipelines/internal/stage" + "git.a-wan.net/alan/pipelines/internal/summarise" "net/http/httptest" "os" "path/filepath" @@ -143,3 +144,104 @@ func TestCLIHeadlessRunInspectionCancellationAndRPC(t *testing.T) { t.Fatal("wait lost terminal state", output) } } + +// TestCLIRunTitlesExplicitDerivedAndRename is the end-to-end title check: it +// drives the real CLI against the real websocket server and store, starts one +// run with --title and one without, and verifies the title is visible in the +// human `runs` list, in `inspect`, and after a `title` rename. Stage execution is +// stubbed because the environment must not call a model, so the without-flag run +// exercises the server-side prompt fallback rather than the shared summariser. +func TestCLIRunTitlesExplicitDerivedAndRename(t *testing.T) { + t.Setenv("PIPELINES_HARNESS_CONFIG", filepath.Join(t.TempDir(), "harnesses.json")) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "cli-titles.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err := store.Submit(ctx, "workflow", pipeline.Template([]string{"worker"}, true)); err != nil { + t.Fatal(err) + } + handler := Handler(ctx, store) + r := handler.(*runHandler).runner + r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) { + return stage.Result{Outcome: "success", Output: stage.Values{"summary": "done"}}, nil + } + http := httptest.NewServer(handler) + defer http.Close() + defer func() { cancel(); WaitRuns(handler) }() + url := "ws" + strings.TrimPrefix(http.URL, "http") + "/connect" + run := func(args ...string) (string, error) { + var out bytes.Buffer + app := cli.App{Out: &out, Err: &out, In: strings.NewReader("")} + err := app.Run(ctx, append([]string{"--url", url}, args...)) + return out.String(), err + } + + output, err := run("run", "workflow", "first prompt line\nmore detail", "--title", "Operator chosen title", "--yes", "--json", "--wait") + if err != nil { + t.Fatal(err) + } + var started protocol.Message + if err := json.Unmarshal([]byte(output), &started); err != nil { + t.Fatal(err) + } + explicitID := started.RunDetail.ID + if started.RunDetail.Title != "Operator chosen title" || started.RunDetail.TitleSource != summarise.SourceExplicit { + t.Fatalf("explicit --title = %+v", started.RunDetail) + } + + output, err = run("run", "workflow", "Derived title from prompt\nsecond line", "--yes", "--json", "--wait") + if err != nil { + t.Fatal(err) + } + if err := json.Unmarshal([]byte(output), &started); err != nil { + t.Fatal(err) + } + if started.RunDetail.Title != "Derived title from prompt" || started.RunDetail.TitleSource != summarise.SourceFallback { + t.Fatalf("derived title = %+v", started.RunDetail) + } + + output, err = run("runs") + if err != nil { + t.Fatal(err) + } + t.Logf("pipelines runs:\n%s", output) + for _, want := range []string{ + fmt.Sprintf("%d\t%s\t%s\tv1\t%s\n", explicitID, "Operator chosen title", "workflow", "succeeded"), + fmt.Sprintf("%d\t%s\t%s\tv1\t%s\n", started.RunDetail.ID, "Derived title from prompt", "workflow", "succeeded"), + } { + if !strings.Contains(output, want) { + t.Fatalf("runs output missing %q:\n%s", want, output) + } + } + + output, err = run("inspect", fmt.Sprint(explicitID), "--json") + if err != nil { + t.Fatal(err) + } + var detail protocol.RunDetail + if err := json.Unmarshal([]byte(output), &detail); err != nil { + t.Fatal(err) + } + if detail.Title != "Operator chosen title" || detail.Name != "workflow" || detail.Version != 1 { + t.Fatalf("inspect omitted title/name/version: %+v", detail) + } + + output, err = run("title", fmt.Sprint(explicitID), "Renamed after the fact") + if err != nil { + t.Fatal(err) + } + t.Logf("pipelines title: %s", strings.TrimSpace(output)) + output, err = run("inspect", fmt.Sprint(explicitID), "--json") + if err != nil { + t.Fatal(err) + } + if err := json.Unmarshal([]byte(output), &detail); err != nil { + t.Fatal(err) + } + if detail.Title != "Renamed after the fact" || detail.TitleSource != summarise.SourceExplicit { + t.Fatalf("rename not visible in inspect: %+v", detail) + } +} diff --git a/internal/server/human_test.go b/internal/server/human_test.go new file mode 100644 index 00000000..8daa4ca8 --- /dev/null +++ b/internal/server/human_test.go @@ -0,0 +1,438 @@ +package server + +import ( + "context" + "encoding/json" + "fmt" + "mime" + "net/http" + "net/http/httptest" + "path/filepath" + "strings" + "sync/atomic" + "testing" + "time" + + "git.a-wan.net/alan/pipelines/internal/pipeline" + "git.a-wan.net/alan/pipelines/internal/protocol" + "git.a-wan.net/alan/pipelines/internal/stage" + "github.com/coder/websocket" + "github.com/coder/websocket/wsjson" +) + +const humanPipelineSource = "# stage gate\n\n```output\nDecision evidence.\n```\n\n```prompt\nReview the screenshots and choose where the run goes.\n```\n\n```edges\ngo -> worker\nhalt -> #success\nerror -> #failure\n```\n\n```configs\ntype=human\n```\n\n# stage worker\n\n```output\nWork result.\n```\n\n```prompt\nDo the work.\n```\n\n```edges\nsuccess -> #success\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=opencode-go\nmodel=deepseek-v4.1-flash\nretries=2\ntimeout=1h\n```\n\n" + +func successExecute(context.Context, stage.Definition, stage.Values) (stage.Result, error) { + return stage.Result{Outcome: "success", Output: stage.Values{"summary": "done"}}, nil +} + +// startHumanRun submits the human pipeline (once) and starts one run, returning +// once the run goroutine has parked the run in the waiting state. +func startHumanRun(t *testing.T, ctx context.Context, r *runner, store *pipeline.Store, key string) *protocol.RunDetail { + t.Helper() + items, _ := store.List(ctx) + var pipelineID int64 + for _, p := range items { + if p.Name == "human" { + pipelineID = p.ID + } + } + if pipelineID == 0 { + if _, err := store.Submit(ctx, "human", humanPipelineSource); err != nil { + t.Fatal(err) + } + items, _ = store.List(ctx) + for _, p := range items { + if p.Name == "human" { + pipelineID = p.ID + } + } + } + run, err := r.start(protocol.Message{PipelineID: pipelineID, Version: 1, RequestKey: key, Workspace: t.TempDir(), Input: map[string]any{"prompt": "task"}}) + if err != nil { + t.Fatal(err) + } + r.wg.Wait() + return run +} + +func TestHumanStageWaitsAndDecisionResumes(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "human.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + r, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + defer r.wg.Wait() + r.execute = successExecute + run := startHumanRun(t, ctx, r, store, "human-go") + + detail, err := r.getRun(run.ID) + if err != nil { + t.Fatal(err) + } + if detail.Status != protocol.RunStatusWaiting || detail.CurrentStage != "gate" { + t.Fatalf("run did not wait: %+v", detail.RunSummary) + } + if len(detail.Steps) != 1 || detail.Steps[0].Status != protocol.StepStatusWaiting { + t.Fatalf("waiting step not persisted: %+v", detail.Steps) + } + if prompt := protocol.WaitingPrompt(detail.Steps[0].Output); !strings.Contains(prompt, "Review the screenshots") { + t.Fatalf("waiting step omitted its prompt: %+v", detail.Steps[0].Output) + } + if options := protocol.WaitingOptions(detail.Steps[0].Output); strings.Join(options, ",") != "go,halt" { + t.Fatalf("waiting step omitted its options: %+v", options) + } + if detail.Steps[0].FinishedAt != "" { + t.Fatalf("waiting step must not be finished: %+v", detail.Steps[0]) + } + + // No later step is created while waiting. + if len(detail.Steps) != 1 { + t.Fatalf("a later step ran while waiting: %+v", detail.Steps) + } + + // Unknown option is refused with the valid list. + if _, err := r.decide(protocol.Message{RunID: run.ID, Option: "launch"}); err == nil || !strings.Contains(err.Error(), "valid options") || !strings.Contains(err.Error(), "go") { + t.Fatalf("unknown option not refused with the list: %v", err) + } + + decided, err := r.decide(protocol.Message{RunID: run.ID, Option: "go", Feedback: "looks good"}) + if err != nil { + t.Fatal(err) + } + if decided.Status != "running" { + t.Fatalf("decided run did not resume: %+v", decided.RunSummary) + } + r.wg.Wait() + detail, err = store.GetRun(ctx, run.ID) + if err != nil { + t.Fatal(err) + } + if detail.Status != "succeeded" || len(detail.Steps) != 2 { + t.Fatalf("run did not resume to completion: %+v", detail.RunSummary) + } + gate := detail.Steps[0] + if gate.Status != "completed" || gate.Outcome != "go" || gate.Target != "worker" || gate.Diagnostic != "" { + t.Fatalf("decision evidence not recorded: %+v", gate) + } + if gate.Output["option"] != "go" || gate.Output["feedback"] != "looks good" { + t.Fatalf("decision output missing option/feedback: %+v", gate.Output) + } + if gate.Verdict == nil || gate.Verdict.Option != "go → worker" || gate.Verdict.Reason != "looks good" { + t.Fatalf("derived verdict missing the decision: %+v", gate.Verdict) + } + + // A repeated decision for the already-decided visit must be an idempotent + // no-op (applied=false, no error) and must not create another step. Naming + // the stage explicitly keeps this on the decided visit instead of relying on + // current_stage having advanced past it. + repeat, err := r.decide(protocol.Message{RunID: run.ID, Stage: "gate", Option: "go"}) + if err != nil { + t.Fatalf("repeat decision for a decided visit was refused: %v", err) + } + if repeat == nil || repeat.Status != "succeeded" { + t.Fatalf("repeat decision changed the run: %+v", repeat) + } + after, err := store.GetRun(ctx, run.ID) + if err != nil { + t.Fatal(err) + } + if len(after.Steps) != 2 { + t.Fatalf("repeat decision created another step: %+v", after.Steps) + } +} + +func TestHumanDecisionToTerminalFinalizesRun(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "terminal.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + r, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + defer r.wg.Wait() + r.execute = successExecute + run := startHumanRun(t, ctx, r, store, "human-halt") + if _, err := r.decide(protocol.Message{RunID: run.ID, Option: "halt", Feedback: "approved"}); err != nil { + t.Fatal(err) + } + r.wg.Wait() + detail, err := store.GetRun(ctx, run.ID) + if err != nil { + t.Fatal(err) + } + if detail.Status != "succeeded" || len(detail.Steps) != 1 || detail.Steps[0].Target != protocol.SuccessEnd { + t.Fatalf("decision to success did not finalize the run: %+v", detail.RunSummary) + } +} + +func TestHumanStageCancelRetryAndRebuild(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + path := filepath.Join(t.TempDir(), "rebuild.db") + store, err := pipeline.Open(path) + if err != nil { + t.Fatal(err) + } + r, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + r.execute = successExecute + run := startHumanRun(t, ctx, r, store, "human-rebuild") + + // Cancel works while waiting. + if err := r.cancel(run.ID); err != nil { + t.Fatal(err) + } + r.wg.Wait() + detail, err := store.GetRun(ctx, run.ID) + if err != nil { + t.Fatal(err) + } + if detail.Status != "canceled" || detail.Steps[0].Status != "canceled" { + t.Fatalf("waiting run not canceled: %+v %+v", detail.RunSummary, detail.Steps) + } + if err := r.cancel(run.ID); err == nil { + t.Fatal("canceling a canceled run succeeded") + } + if err := store.Close(); err != nil { + t.Fatal(err) + } + + // Rebuild runtime state from persisted rows: a second Open + newRunner over + // the same database, with no process restart. RecoverRuns must leave a + // waiting run waiting. + store, err = pipeline.Open(path) + if err != nil { + t.Fatal(err) + } + defer store.Close() + r2, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + defer r2.wg.Wait() + r2.execute = successExecute + waiting := startHumanRun(t, ctx, r2, store, "human-rebuild-2") + + if err := store.Close(); err != nil { + t.Fatal(err) + } + store, err = pipeline.Open(path) + if err != nil { + t.Fatal(err) + } + r3, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + defer r3.wg.Wait() + r3.execute = successExecute + recovered, err := r3.getRun(waiting.ID) + if err != nil { + t.Fatal(err) + } + if recovered.Status != protocol.RunStatusWaiting || recovered.Steps[0].Status != protocol.StepStatusWaiting { + t.Fatalf("rebuilt runtime lost the wait: %+v %+v", recovered.RunSummary, recovered.Steps) + } + if _, err := r3.decide(protocol.Message{RunID: waiting.ID, Option: "go", Feedback: "after restart"}); err != nil { + t.Fatal(err) + } + r3.wg.Wait() + final, err := store.GetRun(ctx, waiting.ID) + if err != nil { + t.Fatal(err) + } + if final.Status != "succeeded" || final.Steps[0].Outcome != "go" || final.Steps[0].Output["feedback"] != "after restart" { + t.Fatalf("rebuilt runtime refused or mis-recorded the decision: %+v", final) + } + + // Retry works after a decision that later fails. + failing := startHumanRun(t, ctx, r3, store, "human-retry") + r3.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) { + return stage.Result{}, fmt.Errorf("provider failed") + } + if _, err := r3.decide(protocol.Message{RunID: failing.ID, Option: "go"}); err != nil { + t.Fatal(err) + } + r3.wg.Wait() + failed, err := store.GetRun(ctx, failing.ID) + if err != nil { + t.Fatal(err) + } + if failed.Status != "failed" { + t.Fatalf("post-decision failure did not fail the run: %+v", failed.RunSummary) + } + r3.execute = successExecute + retried, err := r3.retry(protocol.Message{RunID: failing.ID, RequestKey: "retry-human"}) + if err != nil { + t.Fatal(err) + } + r3.wg.Wait() + retriedDetail, err := store.GetRun(ctx, retried.ID) + if err != nil { + t.Fatal(err) + } + if retried.ID == failing.ID || retriedDetail.Status != protocol.RunStatusWaiting { + t.Fatalf("retry after a decision did not start a fresh waiting run: %+v", retriedDetail.RunSummary) + } +} + +const humanOnlySource = "# stage gate\n\n```output\nDecision evidence.\n```\n\n```prompt\nApprove the release.\n```\n\n```edges\ngo -> #success\nhalt -> #failure\nerror -> #failure\n```\n\n```configs\ntype=human\n```\n\n" + +func TestHumanRunWebSocketWaitAndDecide(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "ws.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err := store.Submit(ctx, "human-ws", humanOnlySource); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + handler := Handler(ctx, store).(*runHandler) + defer func() { cancel(); WaitRuns(handler) }() + srv := httptest.NewServer(handler) + defer srv.Close() + conn, _, err := websocket.Dial(ctx, "ws"+strings.TrimPrefix(srv.URL, "http")+"/connect", nil) + if err != nil { + t.Fatal(err) + } + defer conn.CloseNow() + var snapshot protocol.Message + if err := wsjson.Read(ctx, conn, &snapshot); err != nil { + t.Fatal(err) + } + request := func(message protocol.Message) protocol.Message { + t.Helper() + if err := wsjson.Write(ctx, conn, message); err != nil { + t.Fatal(err) + } + var response protocol.Message + if err := wsjson.Read(ctx, conn, &response); err != nil { + t.Fatal(err) + } + return response + } + started := request(protocol.Message{Type: protocol.RunPipeline, ID: "start", PipelineID: items[0].ID, Version: 1, RequestKey: "ws-human", Input: map[string]any{"prompt": "ship it"}}) + if started.Type != protocol.RunStarted || started.RunDetail == nil { + t.Fatalf("run not started: %+v", started) + } + runID := started.RunDetail.ID + + var waiting protocol.Message + for i := 0; i < 50; i++ { + waiting = request(protocol.Message{Type: protocol.GetRun, ID: "poll", RunID: runID}) + if waiting.RunDetail != nil && waiting.RunDetail.Status == protocol.RunStatusWaiting { + break + } + if waiting.Type == protocol.Error { + t.Fatal(waiting.Error) + } + time.Sleep(20 * time.Millisecond) + } + if waiting.RunDetail == nil || waiting.RunDetail.Status != protocol.RunStatusWaiting || waiting.RunDetail.CurrentStage != "gate" { + t.Fatalf("run never reached waiting: %+v", waiting.RunDetail) + } + if len(waiting.RunDetail.Steps) != 1 || waiting.RunDetail.Steps[0].Status != protocol.StepStatusWaiting { + t.Fatalf("waiting step not visible over websocket: %+v", waiting.RunDetail.Steps) + } + if prompt := protocol.WaitingPrompt(waiting.RunDetail.Steps[0].Output); !strings.Contains(prompt, "Approve the release") { + t.Fatalf("prompt not visible over websocket: %+v", waiting.RunDetail.Steps[0].Output) + } + if options := protocol.WaitingOptions(waiting.RunDetail.Steps[0].Output); strings.Join(options, ",") != "go,halt" { + t.Fatalf("options not visible over websocket: %+v", options) + } + + // Unknown option is refused verbatim over the wire. + bad := request(protocol.Message{Type: protocol.DecideRun, ID: "bad", RunID: runID, Option: "launch"}) + if bad.Type != protocol.Error || !strings.Contains(bad.Error, "valid options") { + t.Fatalf("unknown option not refused over websocket: %+v", bad) + } + + decided := request(protocol.Message{Type: protocol.DecideRun, ID: "decide", RunID: runID, Option: "go", Feedback: "approved"}) + if decided.Type != protocol.Run || decided.RunDetail == nil { + t.Fatalf("decision not accepted over websocket: %+v", decided) + } + var final protocol.Message + for i := 0; i < 50; i++ { + final = request(protocol.Message{Type: protocol.GetRun, ID: "final", RunID: runID}) + if final.RunDetail != nil && final.RunDetail.Status != protocol.RunStatusWaiting && final.RunDetail.Status != "running" { + break + } + time.Sleep(20 * time.Millisecond) + } + if final.RunDetail == nil || final.RunDetail.Status != "succeeded" { + t.Fatalf("decided run did not complete over websocket: %+v", final.RunDetail) + } + if final.RunDetail.Steps[0].Outcome != "go" || final.RunDetail.Steps[0].Output["feedback"] != "approved" { + t.Fatalf("decision evidence not persisted over websocket: %+v", final.RunDetail.Steps[0]) + } +} + +func TestHumanStageWaitingNotification(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "notify.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + var calls atomic.Int32 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + calls.Add(1) + filename, _ := new(mime.WordDecoder).DecodeHeader(r.Header.Get("Filename")) + ack := map[string]any{"id": "msg1", "event": "message"} + if filename != "" { + ack["attachment"] = map[string]string{"name": filename, "url": "https://ntfy.example.com/file/" + filename} + } + _ = json.NewEncoder(w).Encode(ack) + })) + defer srv.Close() + t.Setenv("PIPELINES_NTFY_URL", srv.URL+"/pipelines") + + source := strings.Replace(humanPipelineSource, "```configs\ntype=human\n```", "```notify\non=waiting\n```\n\n```configs\ntype=human\n```", 1) + if _, err := store.Submit(ctx, "human-notify", source); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + var pipelineID int64 + for _, p := range items { + if p.Name == "human-notify" { + pipelineID = p.ID + } + } + r, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + defer r.wg.Wait() + run, err := r.start(protocol.Message{PipelineID: pipelineID, Version: 1, RequestKey: "human-notify", Workspace: t.TempDir(), Input: map[string]any{"prompt": "task"}}) + if err != nil { + t.Fatal(err) + } + r.wg.Wait() + if calls.Load() != 1 { + t.Fatalf("waiting notification fired %d times", calls.Load()) + } + detail, err := store.GetRun(ctx, run.ID) + if err != nil { + t.Fatal(err) + } + if len(detail.Steps[0].Notifications) != 1 || detail.Steps[0].Notifications[0].Status != "sent" { + t.Fatalf("waiting notification receipt missing: %+v", detail.Steps[0].Notifications) + } +} diff --git a/internal/server/notify.go b/internal/server/notify.go index 3cf68541..d6a1c491 100644 --- a/internal/server/notify.go +++ b/internal/server/notify.go @@ -15,12 +15,14 @@ import ( "unicode/utf8" ) -func (r *runner) notifyStep(id int64, d *protocol.PipelineDetail, workspace string, policy *protocol.NotificationPolicy, step protocol.RunStep) { +func (r *runner) notifyStep(id int64, name, workspace string, policy *protocol.NotificationPolicy, step protocol.RunStep) { if policy == nil { return } event := "success" - if step.Status != "completed" || step.Outcome == "error" || step.Target == protocol.FailureEnd { + if step.Status == protocol.StepStatusWaiting || step.Outcome == protocol.StepStatusWaiting { + event = protocol.NotifyWaiting + } else if step.Status != "completed" || step.Outcome == "error" || step.Target == protocol.FailureEnd { event = "failure" } enabled := false @@ -34,7 +36,7 @@ func (r *runner) notifyStep(id int64, d *protocol.PipelineDetail, workspace stri } ctx, cancel := context.WithTimeout(r.ctx, 30*time.Second) defer cancel() - summary := fmt.Sprintf("%s · run #%d · stage %s · %s (%s)", d.Name, id, step.Stage, event, step.Outcome) + summary := fmt.Sprintf("%s · run #%d · stage %s · %s (%s)", name, id, step.Stage, event, step.Outcome) if len(summary) > 1800 { summary = summary[:1800] for !utf8.ValidString(summary) { diff --git a/internal/server/notify_test.go b/internal/server/notify_test.go index e095ccf7..6d1006d1 100644 --- a/internal/server/notify_test.go +++ b/internal/server/notify_test.go @@ -85,7 +85,7 @@ func TestStageNotificationEventsAndArtifactAudit(t *testing.T) { t.Fatal(err) } before := calls.Load() - r.notifyStep(id, d, workspace, policy, step) + r.notifyStep(id, d.Name, workspace, policy, step) detail, err := store.GetRun(ctx, id) if err != nil { t.Fatal(err) diff --git a/internal/server/runner.go b/internal/server/runner.go index 9977dd36..f1f42ff3 100644 --- a/internal/server/runner.go +++ b/internal/server/runner.go @@ -18,6 +18,7 @@ import ( "git.a-wan.net/alan/pipelines/internal/pipeline" "git.a-wan.net/alan/pipelines/internal/protocol" "git.a-wan.net/alan/pipelines/internal/stage" + "git.a-wan.net/alan/pipelines/internal/summarise" ) // activeRun records one in-flight run's cancellation seam and the resolved @@ -35,8 +36,16 @@ type runner struct { mu sync.Mutex active map[int64]activeRun execute func(context.Context, stage.Definition, stage.Values) (stage.Result, error) - wg sync.WaitGroup - schedulerWG sync.WaitGroup + // title generates the operator-facing run title from the run prompt. When nil + // the store derives a fallback from the prompt with no model call, so tests + // and unconfigured servers stay deterministic. + title func(context.Context, string) summarise.Title + // verdict generates the bounded one-line reason for a completed stage visit + // from its output map. When nil the store derives the reason at read time with + // no model call. It is best-effort: any failure must never fail the stage. + verdict func(context.Context, map[string]any) string + wg sync.WaitGroup + schedulerWG sync.WaitGroup } func newRunner(ctx context.Context, s *pipeline.Store) (*runner, error) { @@ -158,13 +167,19 @@ func (r *runner) start(request protocol.Message, retryOf ...int64) (*protocol.Ru } } } + // Decide admission and idempotency under the lock, but generate the title + // only for a request that will actually start a run: a rejected or replayed + // request must not pay for a bounded model generation, and a live one must + // not hold the lock (stalling listings and cancellation) while a model is + // called. An unavailable or slow model falls back to the prompt's first line. r.mu.Lock() - defer r.mu.Unlock() if r.ctx.Err() != nil { + r.mu.Unlock() return nil, r.ctx.Err() } owners, err := r.store.ActiveSessionOwners(r.ctx) if err != nil { + r.mu.Unlock() return nil, err } // Refuse only an orphaned session: one whose owning run is not active now. @@ -172,41 +187,56 @@ func (r *runner) start(request protocol.Message, retryOf ...int64) (*protocol.Ru // workspace) must not block new work. for _, owner := range owners { if _, ok := r.active[owner.RunID]; !ok { + r.mu.Unlock() return nil, fmt.Errorf("an agent may still be active; restart recovery must interrupt it before new work") } } - // Idempotent repeats are accepted even while the original run is active. - if len(r.active) > 0 { - existing, err := r.store.RunByKey(r.ctx, request.RequestKey) - if err != nil { + // Idempotent repeats are accepted even while the original run is active, and + // a replay reuses the stored title instead of generating a new one. + existing, err := r.store.RunByKey(r.ctx, request.RequestKey) + if err != nil { + r.mu.Unlock() + return nil, err + } + if existing == 0 { + if err := r.checkWorkspaceFree(workspace); err != nil { + r.mu.Unlock() return nil, err } - if existing == 0 { - // The workspace is the only scope a run reserves: refuse a second - // run only when an active run is already changing this exact - // resolved directory. One active run per workspace keeps this scan - // finding at most one match, so the message is deterministic. - for id, entry := range r.active { - if entry.workspace == workspace { - return nil, fmt.Errorf("run %d is already active in workspace %s; wait for it to finish or start this run in a different workspace (for example another checkout of the repository)", id, workspace) - } - } + } + r.mu.Unlock() + + var runTitle summarise.Title + if existing == 0 { + // An explicit operator title skips the model call; otherwise the + // configured generator names the run, falling back to the prompt's + // first line when it is unavailable or slow. + if explicit, ok := summarise.ExplicitTitle(request.Title); ok { + runTitle = explicit + } else if r.title != nil { + prompt, _ := request.Input["prompt"].(string) + runTitle = r.title(r.ctx, prompt) } } - id, created, err := r.store.CreateRun(r.ctx, d, request.RequestKey, workspace, request.AllowTools, request.WritePaths, request.Input, retryOf...) + + r.mu.Lock() + defer r.mu.Unlock() + // Another run may have reserved this workspace while the title was + // generated, so re-check before reserving it; a race on the request key is + // handled by the store's idempotent insert. + if existing == 0 { + if err := r.checkWorkspaceFree(workspace); err != nil { + return nil, err + } + } + id, created, err := r.store.CreateRunTitled(r.ctx, d, request.RequestKey, workspace, request.AllowTools, request.WritePaths, request.Input, runTitle, retryOf...) if err != nil { return nil, err } if created { - ctx, cancel := context.WithCancel(r.ctx) - r.active[id] = activeRun{cancel: cancel, workspace: workspace} - r.wg.Add(1) - go func() { - defer r.wg.Done() - defer cancel() - defer func() { r.mu.Lock(); delete(r.active, id); r.mu.Unlock() }() + r.launch(id, workspace, func(ctx context.Context) { r.run(ctx, id, d, workspace, request) - }() + }) } detail, err := r.store.GetRun(r.ctx, id) if detail != nil { @@ -215,6 +245,35 @@ func (r *runner) start(request protocol.Message, retryOf ...int64) (*protocol.Ru return detail, err } +// launch registers an active run's cancellation seam and workspace, adds it to +// the wait group and starts fn on a derived cancellable context that cleans up +// the registration when it returns. A fresh run and a resumed decision both go +// through it, so registration and teardown live once. Callers must hold r.mu. +func (r *runner) launch(id int64, workspace string, fn func(context.Context)) { + ctx, cancel := context.WithCancel(r.ctx) + r.active[id] = activeRun{cancel: cancel, workspace: workspace} + r.wg.Add(1) + go func() { + defer r.wg.Done() + defer cancel() + defer func() { r.mu.Lock(); delete(r.active, id); r.mu.Unlock() }() + fn(ctx) + }() +} + +// checkWorkspaceFree refuses a run when an active run is already changing the +// same resolved workspace. The workspace is the only scope a run reserves, and +// one active run per workspace keeps this scan finding at most one match, so the +// message is deterministic. Callers must hold r.mu. +func (r *runner) checkWorkspaceFree(workspace string) error { + for id, entry := range r.active { + if entry.workspace == workspace { + return fmt.Errorf("run %d is already active in workspace %s; wait for it to finish or start this run in a different workspace (for example another checkout of the repository)", id, workspace) + } + } + return nil +} + func (r *runner) getRun(id int64) (*protocol.RunDetail, error) { r.mu.Lock() defer r.mu.Unlock() @@ -270,52 +329,174 @@ func (r *runner) retry(request protocol.Message) (*protocol.RunDetail, error) { func (r *runner) cancel(id int64) error { r.mu.Lock() - defer r.mu.Unlock() entry, ok := r.active[id] - if !ok { - return fmt.Errorf("run is not active") + r.mu.Unlock() + if ok { + entry.cancel() + return nil } - entry.cancel() - return nil + // A run that is waiting on a person has no live goroutine, so cancel it at + // the persistence layer instead. This keeps cancel working across a restart. + return r.store.CancelWaiting(r.ctx, id) +} + +// decide records an operator's choice for a waiting human stage and resumes the +// run along the chosen edge. ResolveDecision owns validation and idempotency, so +// decide does no option parsing of its own. A resumed run is registered and +// launched exactly like a fresh one but starts from the persisted state. +func (r *runner) decide(request protocol.Message) (*protocol.RunDetail, error) { + if request.RunID <= 0 { + return nil, fmt.Errorf("decide requires a positive run ID") + } + r.mu.Lock() + detail, err := r.store.GetRun(r.ctx, request.RunID) + if err != nil { + r.mu.Unlock() + return nil, err + } + if _, busy := r.active[detail.ID]; busy { + r.mu.Unlock() + return nil, fmt.Errorf("run %d is already active; wait for it to pause before deciding", detail.ID) + } + if detail.Status == protocol.RunStatusWaiting { + if err := r.checkWorkspaceFree(detail.Workspace); err != nil { + r.mu.Unlock() + return nil, err + } + } + step, applied, err := r.store.ResolveDecision(r.ctx, detail.ID, request.Stage, request.Option, request.Feedback) + if err != nil { + r.mu.Unlock() + return nil, err + } + if applied { + for i := range detail.Steps { + if detail.Steps[i].Sequence == step.Sequence && detail.Steps[i].Stage == step.Stage { + detail.Steps[i] = step + break + } + } + r.launch(detail.ID, detail.Workspace, func(ctx context.Context) { + r.resume(ctx, detail.ID, detail, detail.Workspace, step) + }) + } + r.mu.Unlock() + return r.getRun(request.RunID) } func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail, workspace string, request protocol.Message) { - input := stage.Values(request.Input) - key := d.Graph.Stages[0].Key - visits := map[string]int{} - budgets := map[string]*stage.Budget{} - finish := func(status, outcome, diagnostic string) { - c, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - if err := r.store.FinishRun(c, id, status, outcome, diagnostic, input); err != nil { - log.Printf("finish run %d: %v", id, err) - } - } original, copyErr := copyValues(stage.Values(request.Input)) if copyErr != nil { - finish("failed", "error", copyErr.Error()) + r.finishRunState(id, "failed", "error", copyErr.Error(), stage.Values(request.Input)) return } - memory := map[string]memoryValue{"input": {output: original}} + input := stage.Values(request.Input) + state := newRunState(d.Graph.Stages[0].Key, input) + state.memory["input"] = memoryValue{output: original} + r.runLoop(ctx, id, d.Graph, d.Name, workspace, request, state) +} + +// terminalFinish classifies a stage's resolved target. A terminal key yields the +// run's final status, outcome and diagnostic; an empty target means the stage +// named an undeclared outcome; any other value is a stage key and is not +// terminal. resume and the loop tail share it, so terminal routing lives once. +func terminalFinish(target, stageKey, outcome, diagnostic string) (status, finalOutcome, finalDiagnostic string, terminal bool) { + switch target { + case protocol.SuccessEnd: + return "succeeded", "success", "", true + case protocol.FailureEnd: + if diagnostic == "" { + diagnostic = fmt.Sprintf("stage %s returned outcome %q", stageKey, outcome) + } + return "failed", "error", diagnostic, true + case "": + return "failed", "error", "stage returned an undeclared outcome", true + } + return "", "", "", false +} + +// resume continues a decided run from the state already persisted for its run +// detail: memory from the run input and the completed steps, visits counted per +// stage, and the next sequence above the highest recorded one. It then runs the +// shared loop from the decision's target; no full-table scan and no extra +// per-step query are introduced. +func (r *runner) resume(ctx context.Context, id int64, d *protocol.RunDetail, workspace string, step protocol.RunStep) { + // The decision may route straight to a terminal, which has no stage to run. + if status, outcome, diagnostic, terminal := terminalFinish(step.Target, step.Stage, step.Outcome, step.Diagnostic); terminal { + r.finishRunState(id, status, outcome, diagnostic, stage.Values(step.Output)) + return + } + state := rebuildRunState(d, step) + r.runLoop(ctx, id, d.Graph, d.Name, workspace, protocol.Message{WritePaths: d.WritePaths, AllowTools: d.AllowTools}, state) +} + +// runState is the loop's whole mutable state, extracted so a fresh run and a +// resumed run share one implementation. nextSequence is set before each visit so +// a wait that returns to the caller records where the run will continue. +type runState struct { + key string + nextSequence int + visits map[string]int + memory map[string]memoryValue + input stage.Values +} + +func newRunState(key string, input stage.Values) *runState { + return &runState{key: key, nextSequence: 1, visits: map[string]int{}, memory: map[string]memoryValue{}, input: input} +} + +func rebuildRunState(detail *protocol.RunDetail, decided protocol.RunStep) *runState { + state := newRunState(decided.Target, stage.Values(decided.Output)) + if original, err := copyValues(stage.Values(detail.Input)); err == nil { + state.memory["input"] = memoryValue{output: original} + } + for _, step := range detail.Steps { + state.visits[step.Stage]++ + if step.Sequence >= state.nextSequence { + state.nextSequence = step.Sequence + 1 + } + if step.Status == "completed" { + if values, err := copyValues(stage.Values(step.Output)); err == nil { + state.memory[step.Stage] = memoryValue{output: values, sequence: step.Sequence} + } + } + } + return state +} + +func (r *runner) finishRunState(id int64, status, outcome, diagnostic string, input stage.Values) { + c, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + if err := r.store.FinishRun(c, id, status, outcome, diagnostic, input); err != nil { + log.Printf("finish run %d: %v", id, err) + } +} + +func (r *runner) runLoop(ctx context.Context, id int64, graph protocol.Graph, name, workspace string, request protocol.Message, state *runState) { + finish := func(status, outcome, diagnostic string) { + r.finishRunState(id, status, outcome, diagnostic, state.input) + } defer func() { if recovered := recover(); recovered != nil { finish("failed", "error", "stage execution panicked") } }() - for sequence := 1; sequence <= 30; sequence++ { + budgets := map[string]*stage.Budget{} + if state.key == "" { + finish("failed", "error", "stage returned an undeclared outcome") + return + } + for sequence := state.nextSequence; sequence <= 30; sequence++ { + state.nextSequence = sequence + 1 if ctx.Err() != nil { finish("canceled", "", ctx.Err().Error()) return } - visits[key]++ - if visits[key] > 5 { - finish("failed", "error", "stage visit budget exceeded") - return - } + key := state.key var def stage.Definition var selected protocol.Stage found := false - for _, s := range d.Graph.Stages { + for _, s := range graph.Stages { if s.Key == key { selected = s def = pipeline.StageDefinition(s) @@ -327,16 +508,27 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail, finish("failed", "error", "missing stage") return } + isHuman := stage.EffectiveType(def.Type) == stage.HumanType + state.visits[key]++ maxVisits := 5 if selected.Limits != nil { maxVisits = selected.Limits.MaxVisits } - if visits[key] > maxVisits { - finish("failed", "error", fmt.Sprintf("stage %s visit limit reached (%d)", key, maxVisits)) - return + // A human stage pauses for a person; neither the global visit budget nor + // the per-stage max_visits may kill it. The shared 30-step run budget + // still bounds every run. + if !isHuman { + if state.visits[key] > 5 { + finish("failed", "error", "stage visit budget exceeded") + return + } + if state.visits[key] > maxVisits { + finish("failed", "error", fmt.Sprintf("stage %s visit limit reached (%d)", key, maxVisits)) + return + } } var reads map[string]protocol.MemoryRead - input, reads, copyErr = memoryInput(input, selected.Memory, memory) + input, reads, copyErr := memoryInput(state.input, selected.Memory, state.memory) if copyErr != nil { finish("failed", "error", copyErr.Error()) return @@ -349,6 +541,22 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail, finish("failed", "error", err.Error()) return } + if isHuman { + // A human step is O(1): one BeginStep plus one MarkWaiting, no + // filediff capture, no artifacts directory and no workspace mutation. + evidence := protocol.NewWaitingEvidence(def.Blocks["prompt"], stage.HumanOptions(def.Edges)) + if err := r.store.MarkWaiting(ctx, id, sequence, key, evidence); err != nil { + if ctx.Err() != nil { + finish("canceled", "", ctx.Err().Error()) + return + } + finish("failed", "error", err.Error()) + return + } + waitStep := protocol.RunStep{Sequence: sequence, Stage: key, Status: protocol.StepStatusWaiting, Output: evidence} + r.notifyStep(id, name, workspace, selected.Notify, waitStep) + return + } var tools []string explicitTools := false var toolErr error @@ -472,6 +680,9 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail, step.Diagnostic = err.Error() step.Outcome = "error" step.Output = stage.Values{"error": err.Error(), "stage": key, "input": input} + if len(result.Output) > 0 { + step.Output["salvage"] = result.Output + } } // A failed or timed-out step carries the session pointer even when the // bounded transcript would otherwise be only its stage_limits envelope. @@ -479,8 +690,8 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail, step.Transcript = stage.RetainSession(step.Transcript, stageSession) } step.Target = def.Edges[step.Outcome] - step.Control = &protocol.ControlEvidence{Visit: visits[key], MaxVisits: maxVisits, Memory: reads} - if err == nil && selected.Limits != nil && visits[key] >= maxVisits { + step.Control = &protocol.ControlEvidence{Visit: state.visits[key], MaxVisits: maxVisits, Memory: reads} + if err == nil && selected.Limits != nil && state.visits[key] >= maxVisits { for _, outcome := range selected.Limits.On { if outcome == step.Outcome { step.Control.LimitReached = true @@ -493,6 +704,17 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail, if panicked { step.Target = protocol.FailureEnd } + // Generate the one-line verdict reason once, at completion. It is + // best-effort: a summariser failure or timeout returns NoSummary and must + // never fail the stage or the run, so every error is swallowed. A failed + // step still gets a verdict from its error envelope. + if r.verdict != nil { + reasonCtx, reasonCancel := context.WithTimeout(context.Background(), summarise.DefaultTimeout) + if line := r.verdict(reasonCtx, step.Output); line != "" && line != summarise.NoSummary { + step.Verdict = &protocol.StageVerdict{Reason: line, ReasonSource: protocol.VerdictReasonModel} + } + reasonCancel() + } save, cancel := context.WithTimeout(context.Background(), 10*time.Second) persistErr := r.store.FinishStep(save, id, step) cancel() @@ -506,15 +728,10 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail, finish("failed", "error", err.Error()) return } - memory[key] = memoryValue{output: values, sequence: sequence} + state.memory[key] = memoryValue{output: values, sequence: sequence} } - for _, s := range d.Graph.Stages { - if s.Key == key { - r.notifyStep(id, d, workspace, s.Notify, step) - break - } - } - input = stage.Values(step.Output) + r.notifyStep(id, name, workspace, selected.Notify, step) + state.input = stage.Values(step.Output) if useAgent || errors.Is(err, stage.ErrStageCleanup) { sessions, checkErr := r.store.ActiveAgentSessionsForRun(context.Background(), id) if checkErr != nil || len(sessions) > 0 { @@ -526,23 +743,24 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail, finish("canceled", "", ctx.Err().Error()) return } - if step.Target == protocol.SuccessEnd { - finish("succeeded", "success", "") + if status, outcome, diagnostic, terminal := terminalFinish(step.Target, step.Stage, step.Outcome, step.Diagnostic); terminal { + finish(status, outcome, diagnostic) return } - if step.Target == protocol.FailureEnd { - diagnostic := step.Diagnostic - if diagnostic == "" { - diagnostic = fmt.Sprintf("stage %s returned outcome %q", step.Stage, step.Outcome) - } - finish("failed", "error", diagnostic) - return - } - if step.Target == "" { - finish("failed", "error", "stage returned an undeclared outcome") - return - } - key = step.Target + state.key = step.Target } finish("failed", "error", "total stage budget exceeded") } + +// setTitle renames a run: it replaces the stored operator-facing title without +// touching the run's input, steps or execution, then returns the updated detail. +func (r *runner) setTitle(id int64, title string) (*protocol.RunDetail, error) { + explicit, ok := summarise.ExplicitTitle(title) + if !ok { + return nil, fmt.Errorf("a title with usable text is required") + } + if err := r.store.SetRunTitle(r.ctx, id, explicit); err != nil { + return nil, err + } + return r.getRun(id) +} diff --git a/internal/server/runner_test.go b/internal/server/runner_test.go index 2da8d9fe..a5d924e1 100644 --- a/internal/server/runner_test.go +++ b/internal/server/runner_test.go @@ -11,8 +11,194 @@ import ( "git.a-wan.net/alan/pipelines/internal/pipeline" "git.a-wan.net/alan/pipelines/internal/protocol" "git.a-wan.net/alan/pipelines/internal/stage" + "git.a-wan.net/alan/pipelines/internal/summarise" ) +// TestRunTitleGeneratedPersistedAndFallback proves the insert path stores a +// generated title with its provenance in list and detail responses, and falls +// back to a derived bounded title when no generator is wired, without failing +// run creation. +func TestRunTitleGeneratedPersistedAndFallback(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "titles.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err := store.Submit(ctx, "titled", pipeline.Template([]string{"one"}, true)); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + r, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) { + return stage.Result{Outcome: "success", Output: stage.Values{}}, nil + } + r.title = func(context.Context, string) summarise.Title { + return summarise.Title{Text: "Fix the flaky login test", Source: summarise.SourceModel, Model: "openai/gpt"} + } + run, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "model-title", Workspace: t.TempDir(), Input: map[string]any{"prompt": "prompt body"}}) + if err != nil { + t.Fatal(err) + } + r.wg.Wait() + detail, err := store.GetRun(ctx, run.ID) + if err != nil { + t.Fatal(err) + } + if detail.Title != "Fix the flaky login test" || detail.TitleSource != summarise.SourceModel || detail.TitleModel != "openai/gpt" { + t.Fatalf("model title not stored with provenance: %+v", detail) + } + list, err := store.ListRuns(ctx) + if err != nil || len(list) != 1 || list[0].Title != "Fix the flaky login test" { + t.Fatalf("run list omitted the title: %v %v", list, err) + } + + // No generator: the fallback is derived from the prompt's first line and run + // creation still succeeds. + r.title = nil + fallback, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "fallback-title", Workspace: t.TempDir(), Input: map[string]any{"prompt": "Fix the widget\nand more detail"}}) + if err != nil { + t.Fatal(err) + } + r.wg.Wait() + detail, err = store.GetRun(ctx, fallback.ID) + if err != nil { + t.Fatal(err) + } + if detail.Title != "Fix the widget" || detail.TitleSource != summarise.SourceFallback || detail.TitleModel != "" { + t.Fatalf("fallback title = %+v, want the prompt's first line", detail) + } +} + +// TestRunTitleGeneratorSkippedForReplayAndRejection proves the bounded +// generation runs only for a request that starts a run: an idempotent replay and +// a request refused for an already-reserved workspace must not pay for it. +func TestRunTitleGeneratorSkippedForReplayAndRejection(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "skip.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err := store.Submit(ctx, "skip", pipeline.Template([]string{"one"}, true)); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + r, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + release := make(chan struct{}) + r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) { + <-release + return stage.Result{Outcome: "success", Output: stage.Values{}}, nil + } + calls := 0 + r.title = func(context.Context, string) summarise.Title { + calls++ + return summarise.Title{Text: "Generated", Source: summarise.SourceModel} + } + workspace := t.TempDir() + first, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "skip-key", Workspace: workspace, Input: map[string]any{"prompt": "first"}}) + if err != nil { + t.Fatal(err) + } + if calls != 1 { + t.Fatalf("first start generated %d titles, want 1", calls) + } + // A replay while the first run is active reuses the stored title. + replay, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "skip-key", Workspace: workspace, Input: map[string]any{"prompt": "first"}}) + if err != nil || replay.ID != first.ID { + t.Fatalf("replay = %+v, %v; want run %d", replay, err, first.ID) + } + // A new key in the already-reserved workspace is refused. + if _, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "skip-other", Workspace: workspace, Input: map[string]any{"prompt": "second"}}); err == nil { + t.Fatal("workspace conflict was not refused") + } + if calls != 1 { + t.Fatalf("replay/rejection generated %d titles, want 1", calls) + } + close(release) + r.wg.Wait() +} + +func TestHandlerWiresRunTitleGenerator(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + store, err := pipeline.Open(filepath.Join(t.TempDir(), "wire.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + configured := HandlerWithOptions(ctx, Options{RunTitles: summarise.GenerateTitle}, store).(*runHandler) + bare := HandlerWithOptions(ctx, Options{}, store).(*runHandler) + defer func() { cancel(); WaitRuns(configured); WaitRuns(bare) }() + if configured.runner.title == nil { + t.Fatal("configured RunTitles was not applied to the runner") + } + if bare.runner.title != nil { + t.Fatal("unconfigured RunTitles must keep deterministic fallback title generation") + } +} + +// TestRunnerExplicitTitleSkipsGeneratorAndRenames proves an explicit --title is +// stored verbatim and skips the model generator, and that setTitle later +// replaces it with an explicit provenance without touching the run's input. +func TestRunnerExplicitTitleSkipsGeneratorAndRenames(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "explicit.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err := store.Submit(ctx, "explicit", pipeline.Template([]string{"one"}, true)); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + r, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) { + return stage.Result{Outcome: "success", Output: stage.Values{}}, nil + } + generated := 0 + r.title = func(context.Context, string) summarise.Title { + generated++ + return summarise.Title{Text: "Generated", Source: summarise.SourceModel} + } + run, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "explicit-key", Workspace: t.TempDir(), Title: "Operator chosen title", Input: map[string]any{"prompt": "prompt body"}}) + if err != nil { + t.Fatal(err) + } + r.wg.Wait() + if generated != 0 { + t.Fatalf("explicit title still called the generator %d times", generated) + } + if run.Title != "Operator chosen title" || run.TitleSource != summarise.SourceExplicit || run.TitleModel != "" { + t.Fatalf("explicit title = %+v", run) + } + + renamed, err := r.setTitle(run.ID, " Renamed after the fact ") + if err != nil { + t.Fatal(err) + } + if renamed.Title != "Renamed after the fact" || renamed.TitleSource != summarise.SourceExplicit || renamed.Input["prompt"] != "prompt body" { + t.Fatalf("rename = %+v", renamed) + } + if _, err := r.setTitle(run.ID, " "); err == nil { + t.Fatal("blank rename was accepted") + } + if _, err := r.setTitle(run.ID+999, "ghost"); err == nil { + t.Fatal("renaming an unknown run was accepted") + } +} + func TestRunnerRoutingPersistenceAndIdempotency(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -129,3 +315,110 @@ func TestRunnerRoutingPersistenceAndIdempotency(t *testing.T) { t.Fatalf("cycle not bounded: %+v", detail) } } + +// TestStepVerdictGeneratedOnceAtCompletion proves the wired seam runs exactly +// once per completed stage visit, from the step's own output, and the generated +// line is stored with model provenance. +func TestStepVerdictGeneratedOnceAtCompletion(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "verdict.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err := store.Submit(ctx, "verdict", pipeline.Template([]string{"one"}, true)); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + r, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) { + return stage.Result{Outcome: "success", Output: stage.Values{"summary": "ran the checks"}}, nil + } + calls := 0 + r.verdict = func(_ context.Context, output map[string]any) string { + calls++ + if output["summary"] != "ran the checks" { + t.Errorf("verdict seam got output %v", output) + } + return "chosen because every check passed" + } + run, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "verdict-once", Workspace: t.TempDir(), Input: map[string]any{"prompt": "task"}}) + if err != nil { + t.Fatal(err) + } + r.wg.Wait() + if calls != 1 { + t.Fatalf("verdict seam ran %d times, want exactly once for one step", calls) + } + detail, err := store.GetRun(ctx, run.ID) + if err != nil { + t.Fatal(err) + } + verdict := detail.Steps[0].Verdict + if verdict == nil || verdict.Reason != "chosen because every check passed" || verdict.ReasonSource != protocol.VerdictReasonModel { + t.Fatalf("stored verdict = %+v", verdict) + } +} + +// TestStepVerdictFailureNeverFailsStage proves a best-effort failure (the +// NoSummary sentinel) still lets the run reach its normal terminal status, with +// the verdict derived at read time from the step's output. +func TestStepVerdictFailureNeverFailsStage(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "verdict-fail.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + if _, err := store.Submit(ctx, "verdict-fail", pipeline.Template([]string{"one"}, true)); err != nil { + t.Fatal(err) + } + items, _ := store.List(ctx) + r, err := newRunner(ctx, store) + if err != nil { + t.Fatal(err) + } + r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) { + return stage.Result{Outcome: "success", Output: stage.Values{"summary": "ran the checks"}}, nil + } + r.verdict = func(context.Context, map[string]any) string { return summarise.NoSummary } + run, err := r.start(protocol.Message{PipelineID: items[0].ID, Version: 1, RequestKey: "verdict-fail", Workspace: t.TempDir(), Input: map[string]any{"prompt": "task"}}) + if err != nil { + t.Fatal(err) + } + r.wg.Wait() + detail, err := store.GetRun(ctx, run.ID) + if err != nil { + t.Fatal(err) + } + if detail.Status != "succeeded" { + t.Fatalf("summariser failure changed the run status: %+v", detail) + } + verdict := detail.Steps[0].Verdict + if verdict == nil || verdict.Reason != "ran the checks" || verdict.ReasonSource != protocol.VerdictReasonFallback { + t.Fatalf("read-time verdict after a summariser failure = %+v", verdict) + } +} + +func TestHandlerWiresStepVerdictGenerator(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + store, err := pipeline.Open(filepath.Join(t.TempDir(), "verdict-wire.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + configured := HandlerWithOptions(ctx, Options{StepVerdicts: summarise.GenerateVerdictReason}, store).(*runHandler) + bare := HandlerWithOptions(ctx, Options{}, store).(*runHandler) + defer func() { cancel(); WaitRuns(configured); WaitRuns(bare) }() + if configured.runner.verdict == nil { + t.Fatal("configured StepVerdicts was not applied to the runner") + } + if bare.runner.verdict != nil { + t.Fatal("unconfigured StepVerdicts must keep deterministic read-time derivation") + } +} diff --git a/internal/server/websocket.go b/internal/server/websocket.go index 94c99eed..76fbc879 100644 --- a/internal/server/websocket.go +++ b/internal/server/websocket.go @@ -15,6 +15,7 @@ import ( "git.a-wan.net/alan/pipelines/internal/buildinfo" "git.a-wan.net/alan/pipelines/internal/pipeline" "git.a-wan.net/alan/pipelines/internal/protocol" + "git.a-wan.net/alan/pipelines/internal/summarise" ) // Options configures the HTTP handler. @@ -31,6 +32,15 @@ type Options struct { // it from the first store; when neither is available chat_sessions returns an // empty list rather than the endpoint's whole session list. OwnedSessions func(context.Context) ([]pipeline.SessionOwner, error) + // RunTitles generates the operator-facing title stored with each new run. + // When nil, run creation stores the prompt-derived fallback without a model + // call, which keeps tests and unconfigured servers deterministic. + RunTitles func(context.Context, string) summarise.Title + // StepVerdicts generates the bounded one-line reason stored with each + // completed stage visit. When nil, the store derives the verdict's reason at + // read time with no model call, which keeps tests and unconfigured servers + // deterministic. + StepVerdicts func(context.Context, map[string]any) string } // Handler serves the persistent connection with default options. Canceling ctx @@ -53,6 +63,12 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin if runErr == nil && options.ArtifactsRoot != "" { runs.artifactsRoot = options.ArtifactsRoot } + if runErr == nil && options.RunTitles != nil { + runs.title = options.RunTitles + } + if runErr == nil && options.StepVerdicts != nil { + runs.verdict = options.StepVerdicts + } if runErr == nil { runs.schedulerWG.Add(1) go runs.scheduleLoop() @@ -96,6 +112,16 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin defer connCancel() var writeMu sync.Mutex write := func(message protocol.Message) error { + // Every server frame (responses, the welcome and chat events) carries + // the build identity and protocol so an older client fails fast or + // warns once instead of silently misreading a field. build is + // computed once per handler. + if message.Build == nil { + message.Build = &build + } + if message.Protocol == 0 { + message.Protocol = protocol.ProtocolVersion + } writeMu.Lock() defer writeMu.Unlock() writeCtx, cancel := context.WithTimeout(connCtx, 5*time.Second) @@ -133,7 +159,6 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin response.Status = systemStatus(r, started, runErr) } else if request.Type == protocol.Ping { response.Time = time.Now().UTC().Format(time.RFC3339) - response.Build = &build } else if request.Type == protocol.ListTemplates { response.Type = protocol.Templates response.Templates = examples.Catalog() @@ -208,7 +233,7 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin response.Error = err.Error() } } - } else if runs != nil && (request.Type == protocol.RunPipeline || request.Type == protocol.RetryRun || request.Type == protocol.ListRuns || request.Type == protocol.GetRun || request.Type == protocol.CancelRun || request.Type == protocol.GetRunEvidence) { + } else if runs != nil && (request.Type == protocol.RunPipeline || request.Type == protocol.RetryRun || request.Type == protocol.ListRuns || request.Type == protocol.GetRun || request.Type == protocol.CancelRun || request.Type == protocol.DecideRun || request.Type == protocol.SetRunTitle || request.Type == protocol.GetRunEvidence) { var err error switch request.Type { case protocol.GetRunEvidence: @@ -220,6 +245,12 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin case protocol.RetryRun: response.Type = protocol.RunStarted response.RunDetail, err = runs.retry(request) + case protocol.DecideRun: + response.Type = protocol.Run + response.RunDetail, err = runs.decide(request) + case protocol.SetRunTitle: + response.Type = protocol.Run + response.RunDetail, err = runs.setTitle(request.RunID, request.Title) case protocol.ListRuns: response.Type = protocol.Runs response.Runs, err = runs.listRuns() diff --git a/internal/server/websocket_test.go b/internal/server/websocket_test.go index 4465f804..e76b8526 100644 --- a/internal/server/websocket_test.go +++ b/internal/server/websocket_test.go @@ -5,6 +5,7 @@ import ( "context" "log" "net/http/httptest" + "path/filepath" "strings" "sync" "testing" @@ -14,6 +15,7 @@ import ( "github.com/coder/websocket/wsjson" "git.a-wan.net/alan/pipelines/internal/buildinfo" + "git.a-wan.net/alan/pipelines/internal/pipeline" "git.a-wan.net/alan/pipelines/internal/protocol" ) @@ -77,6 +79,9 @@ func TestPersistentConnection(t *testing.T) { if response.Build == nil || response.Build.Version != wantBuild.Version || response.Build.Commit != wantBuild.Commit { t.Fatalf("pong missing server build identity: %+v", response.Build) } + if response.Protocol != protocol.ProtocolVersion { + t.Fatalf("pong protocol = %d, want %d", response.Protocol, protocol.ProtocolVersion) + } stamp, err := time.Parse(time.RFC3339, response.Time) if err != nil { t.Fatal(err) @@ -97,3 +102,38 @@ func TestPersistentConnection(t *testing.T) { } } } + +// TestWelcomeEnvelopeCarriesServerIdentity proves a client that never pings +// still learns the server build and protocol from the unsolicited welcome. +func TestWelcomeEnvelopeCarriesServerIdentity(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + store, err := pipeline.Open(filepath.Join(t.TempDir(), "identity.db")) + if err != nil { + t.Fatal(err) + } + defer store.Close() + handler := Handler(ctx, store) + srv := httptest.NewServer(handler) + defer srv.Close() + defer func() { cancel(); WaitRuns(handler) }() + conn, _, err := websocket.Dial(ctx, "ws"+strings.TrimPrefix(srv.URL, "http")+"/connect", nil) + if err != nil { + t.Fatal(err) + } + defer conn.CloseNow() + var welcome protocol.Message + if err := wsjson.Read(ctx, conn, &welcome); err != nil { + t.Fatal(err) + } + if welcome.Type != protocol.PipelineList { + t.Fatalf("first frame = %q, want welcome pipelines list", welcome.Type) + } + wantBuild := buildinfo.Current() + if welcome.Build == nil || welcome.Build.Version != wantBuild.Version || welcome.Build.Commit != wantBuild.Commit { + t.Fatalf("welcome missing server build identity: %+v", welcome.Build) + } + if welcome.Protocol != protocol.ProtocolVersion { + t.Fatalf("welcome protocol = %d, want %d", welcome.Protocol, protocol.ProtocolVersion) + } +} diff --git a/internal/stage/agent.go b/internal/stage/agent.go index 18f35dad..2d3aa1ea 100644 --- a/internal/stage/agent.go +++ b/internal/stage/agent.go @@ -276,6 +276,11 @@ func completedAgentResult(data []byte) (string, error) { // Agents may emit a short explanation before their final result. Preserve the // full response in the audit, but pass only a complete final JSON object to the // same strict stage validator. Never infer outcomes from prose or tool output. +// The line-oriented format is returned verbatim so its '# output' body is not +// stripped by the JSON-object extractor. func agentResultText(text string) string { + if resultFormat(text) == "line" { + return text + } return stageResultText(text) } diff --git a/internal/stage/artifacts_test.go b/internal/stage/artifacts_test.go index a30ca152..01652724 100644 --- a/internal/stage/artifacts_test.go +++ b/internal/stage/artifacts_test.go @@ -17,6 +17,10 @@ func TestPiEnvironmentCarriesArtifactsDirectory(t *testing.T) { } func TestPiEnvironmentOmitsEmptyArtifactsDirectory(t *testing.T) { + // An ambient artifacts directory (for example Pipelines' own when a stage + // runs inside another stage) must not leak into a Pi child that was given + // none: the argument is authoritative. + t.Setenv(ArtifactsEnv, "/ambient/artifacts/leak") for _, entry := range piEnvironment("/tmp/ref", "") { if strings.HasPrefix(entry, ArtifactsEnv+"=") { t.Fatalf("unexpected artifacts entry %q", entry) diff --git a/internal/stage/human.go b/internal/stage/human.go new file mode 100644 index 00000000..70769b69 --- /dev/null +++ b/internal/stage/human.go @@ -0,0 +1,60 @@ +package stage + +import ( + "context" + "fmt" + "sort" + "strings" +) + +const HumanType = "human" + +// HumanStage pauses its run until a person chooses one of the stage's outgoing +// options. It has no model, agent, tools or configs: its outcomes are exactly +// its non-error edges (the selectable options) and its required prompt block +// carries the operator instructions. It parses, validates, renders, exports and +// imports like every other registered type. The runner owns the wait and the +// decision path; Run is defensive only and never executes synchronously. +type HumanStage struct{} + +func (HumanStage) Validate(def Definition) error { + if EffectiveType(def.Type) != HumanType { + return fmt.Errorf("expected human stage") + } + for name := range def.Blocks { + switch name { + case "configs", "edges", "output", "prompt": + default: + return fmt.Errorf("unexpected block %q for human stage", name) + } + } + for key := range def.Configs { + return fmt.Errorf("unknown human config %q", key) + } + if strings.TrimSpace(def.Blocks["prompt"]) == "" { + return fmt.Errorf("human stage requires a nonempty prompt block with the operator instructions") + } + if len(HumanOptions(def.Edges)) == 0 { + return fmt.Errorf("human stage requires at least one non-error option edge") + } + return nil +} + +func (HumanStage) Run(context.Context, Definition, Values) (Result, error) { + return Result{}, fmt.Errorf("human stage is resolved by the runner's decision path, not executed") +} + +// HumanOptions is the single definition of a human stage's selectable outcomes: +// its non-error edges in a deterministic order. The mandatory error edge is a +// failure route, not an operator choice, so it is never returned. Store, runner +// and TUI all read this one helper, so the option set cannot drift. +func HumanOptions(edges map[string]string) []string { + options := make([]string, 0, len(edges)) + for outcome := range edges { + if outcome != "error" { + options = append(options, outcome) + } + } + sort.Strings(options) + return options +} diff --git a/internal/stage/human_test.go b/internal/stage/human_test.go new file mode 100644 index 00000000..feac72e0 --- /dev/null +++ b/internal/stage/human_test.go @@ -0,0 +1,54 @@ +package stage + +import ( + "context" + "reflect" + "strings" + "testing" +) + +func humanDefinition() Definition { + return Definition{ + Key: "gate", + Type: HumanType, + Blocks: map[string]string{"prompt": "Review the screenshots and decide."}, + Configs: map[string]string{}, + Edges: map[string]string{"deploy": "#success", "revise": "worker", "error": "#failure"}, + } +} + +func TestHumanStageValidateAndRun(t *testing.T) { + if err := (HumanStage{}).Validate(humanDefinition()); err != nil { + t.Fatalf("valid human stage rejected: %v", err) + } + for name, mutate := range map[string]func(*Definition){ + "missing prompt": func(def *Definition) { def.Blocks["prompt"] = " " }, + "unexpected block": func(def *Definition) { def.Blocks["tools"] = "shell" }, + "config key": func(def *Definition) { def.Configs["provider"] = "opencode-go" }, + "no non-error edge": func(def *Definition) { def.Edges = map[string]string{"error": "#failure"} }, + } { + t.Run(name, func(t *testing.T) { + def := humanDefinition() + mutate(&def) + if err := (HumanStage{}).Validate(def); err == nil { + t.Fatal("accepted an invalid human stage") + } + }) + } + if _, err := (HumanStage{}).Run(context.Background(), humanDefinition(), nil); err == nil || !strings.Contains(err.Error(), "decision path") { + t.Fatalf("Run must never execute synchronously, got %v", err) + } + if _, err := DefaultRegistry().Resolve(HumanType); err != nil { + t.Fatalf("human type must be registered: %v", err) + } +} + +func TestHumanOptionsAreSortedNonErrorEdges(t *testing.T) { + options := HumanOptions(map[string]string{"revise": "worker", "deploy": "#success", "abort": "#failure", "error": "#failure"}) + if !reflect.DeepEqual(options, []string{"abort", "deploy", "revise"}) { + t.Fatalf("HumanOptions = %v", options) + } + if len(HumanOptions(map[string]string{"error": "#failure"})) != 0 { + t.Fatal("an error-only edge set must yield no options") + } +} diff --git a/internal/stage/line_result.go b/internal/stage/line_result.go new file mode 100644 index 00000000..7b99d3aa --- /dev/null +++ b/internal/stage/line_result.go @@ -0,0 +1,229 @@ +package stage + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" + "strings" + "unicode" +) + +// resultFormat decides which decoder to use for a raw stage response. +// +// The legacy JSON path is kept for responses that look like JSON envelopes, +// including presentation wrappers (a single surrounding markdown fence or a +// short prose prefix before the JSON object). The line-oriented format is +// chosen only when a section heading ("# ") appears before any JSON object, +// because the line format's required "# output" section always precedes the +// JSON body. This keeps existing JSON responses, including fenced or +// prose-prefixed results, on the unchanged decodeModelResult path. +func resultFormat(raw string) string { + trimmed := strings.TrimSpace(raw) + // Strip a single surrounding markdown fence so fenced JSON still routes + // through the unchanged legacy path. + for _, prefix := range []string{"```json\n", "```\n"} { + if strings.HasPrefix(trimmed, prefix) && strings.HasSuffix(trimmed, "\n```") { + trimmed = strings.TrimSuffix(strings.TrimPrefix(trimmed, prefix), "\n```") + trimmed = strings.TrimSpace(trimmed) + break + } + } + if len(trimmed) > 0 && trimmed[0] == '{' { + return "json" + } + heading := headingLineIndex(trimmed) + brace := strings.IndexByte(trimmed, '{') + if heading >= 0 && (brace < 0 || heading < brace) { + return "line" + } + return "json" +} + +// headingLineIndex returns the index of the first "# " heading line, or -1. +func headingLineIndex(s string) int { + if strings.HasPrefix(s, "# ") { + return 0 + } + if i := strings.Index(s, "\n# "); i >= 0 { + return i + 1 + } + return -1 +} + +// lineResultStatus records how completely the line-oriented response was parsed. +// It is stored in Result.Output under the reserved key resultParseKey. +const ( + lineParseParsed = "parsed" + lineParsePartial = "partial" + lineParseFailed = "failed" +) + +const resultParseKey = "result_parse" + +// writeRawOutputFile persists the full raw response to the stage artifacts +// directory before any parsing, so the closest record is always retained. +// It is best-effort: empty ArtifactsDir or a write error is ignored. +func writeRawOutputFile(artifactsDir, text string) { + if artifactsDir == "" { + return + } + _ = os.WriteFile(filepath.Join(artifactsDir, "raw-output.md"), []byte(text), 0600) +} + +type lineSection struct { + heading string + lines []string +} + +func (s lineSection) body() string { + return trimOneTrailingNewline(strings.Join(s.lines, "\n")) +} + +// decodeLineResult parses the line-oriented result format. +// +// The first non-empty line is the outcome. It must be one of the declared edges. +// Subsequent lines beginning with "# " start sections. The required "# output" +// section must contain a JSON object. Every other section is stored verbatim +// under a normalised key derived from its heading. +// +// The function never returns a nil Result: on failure it returns whatever was +// salvaged plus a non-nil error. The returned status string is one of +// lineParseParsed, lineParsePartial or lineParseFailed and is also inserted into +// Result.Output under resultParseKey. +func decodeLineResult(raw string, edges map[string]string) (Result, string, error) { + status := lineParseParsed + result := Result{Output: Values{}} + + lines := strings.Split(raw, "\n") + i := 0 + for i < len(lines) && strings.TrimSpace(lines[i]) == "" { + i++ + } + if i >= len(lines) { + result.Output[resultParseKey] = lineParseFailed + return result, lineParseFailed, fmt.Errorf("%w: missing outcome", ErrInvalidModelResult) + } + + outcome := strings.TrimSpace(lines[i]) + i++ + + sections := parseLineSections(lines, i) + + if strings.HasPrefix(outcome, "# ") { + // The first non-empty line is a section heading, not an outcome. + salvage := Result{Output: Values{}} + addLineSectionsToOutput(salvage.Output, sections, &status) + salvage.Output[resultParseKey] = lineParseFailed + return salvage, lineParseFailed, fmt.Errorf("%w: missing outcome", ErrInvalidModelResult) + } + + if _, ok := edges[outcome]; !ok { + // Salvage any extra sections but do not route: the outcome is not declared. + salvage := Result{Output: Values{}} + addLineSectionsToOutput(salvage.Output, sections, &status) + salvage.Output[resultParseKey] = lineParseFailed + if outcome == "" { + return salvage, lineParseFailed, fmt.Errorf("%w: missing outcome", ErrInvalidModelResult) + } + return salvage, lineParseFailed, fmt.Errorf("%w: undeclared outcome", ErrInvalidModelResult) + } + result.Outcome = outcome + + addLineSectionsToOutput(result.Output, sections, &status) + + outputSection := findLineSection(sections, "output") + if outputSection == nil { + result.Output[resultParseKey] = lineParseFailed + return result, lineParseFailed, fmt.Errorf("%w: missing output section", ErrInvalidModelResult) + } + + var output Values + if err := json.Unmarshal([]byte(outputSection.body()), &output); err != nil { + result.Output[resultParseKey] = lineParseFailed + return result, lineParseFailed, fmt.Errorf("%w: output must be an object", ErrInvalidModelResult) + } + if output == nil { + result.Output[resultParseKey] = lineParseFailed + return result, lineParseFailed, fmt.Errorf("%w: output must be an object", ErrInvalidModelResult) + } + for k, v := range output { + result.Output[k] = v + } + + result.Output[resultParseKey] = status + return result, status, nil +} + +func parseLineSections(lines []string, start int) []lineSection { + var sections []lineSection + var current *lineSection + for i := start; i < len(lines); i++ { + line := lines[i] + if strings.HasPrefix(line, "# ") { + if current != nil { + sections = append(sections, *current) + } + current = &lineSection{heading: strings.TrimSpace(line[2:])} + continue + } + if current != nil { + current.lines = append(current.lines, line) + } + } + if current != nil { + sections = append(sections, *current) + } + return sections +} + +func findLineSection(sections []lineSection, name string) *lineSection { + for i := range sections { + if normaliseHeading(sections[i].heading) == name { + return §ions[i] + } + } + return nil +} + +func addLineSectionsToOutput(out Values, sections []lineSection, status *string) { + seen := map[string]bool{} + for _, s := range sections { + key := normaliseHeading(s.heading) + if key == "output" { + continue + } + if key == resultParseKey || key == "" || seen[key] { + *status = lineParsePartial + continue + } + seen[key] = true + out[key] = s.body() + } +} + +func trimOneTrailingNewline(s string) string { + if strings.HasSuffix(s, "\n") { + return s[:len(s)-1] + } + return s +} + +func normaliseHeading(s string) string { + s = strings.ToLower(strings.TrimSpace(s)) + var b strings.Builder + b.Grow(len(s)) + inSpace := false + for _, r := range s { + if unicode.IsSpace(r) { + inSpace = true + continue + } + if inSpace && b.Len() > 0 { + b.WriteByte('_') + } + inSpace = false + b.WriteRune(r) + } + return b.String() +} diff --git a/internal/stage/line_result_test.go b/internal/stage/line_result_test.go new file mode 100644 index 00000000..1424f2ec --- /dev/null +++ b/internal/stage/line_result_test.go @@ -0,0 +1,232 @@ +package stage + +import ( + "context" + "errors" + "os" + "path/filepath" + "strings" + "testing" +) + +func lineEdges() map[string]string { + return map[string]string{"success": "#ok", "error": "#fail", "rejected": "#rejected"} +} + +func TestResultFormatPrecedence(t *testing.T) { + for _, tc := range []struct { + raw string + want string + }{ + {`{"outcome":"success","output":{}}`, "json"}, + {" \n\n{\"outcome\":\"success\"}", "json"}, + {"success\n# output\n{}", "line"}, + {" success\n# output\n{}", "line"}, + {"# output\n{}", "line"}, + } { + if got := resultFormat(tc.raw); got != tc.want { + t.Errorf("resultFormat(%q) = %q, want %q", tc.raw, got, tc.want) + } + } +} + +func TestDecodeLineResultHappyPath(t *testing.T) { + raw := "rejected\n\n# output\n{\"task\":\"x\"}\n\n# findings\n- BLOCKER: prose\n\n# verification evidence\n{raw json}\n" + result, status, err := decodeLineResult(raw, lineEdges()) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if status != lineParseParsed { + t.Fatalf("status = %q, want parsed", status) + } + if result.Outcome != "rejected" { + t.Fatalf("outcome = %q, want rejected", result.Outcome) + } + if result.Output["task"] != "x" { + t.Fatalf("output task = %v", result.Output["task"]) + } + if got, want := result.Output["findings"], "- BLOCKER: prose"; got != want { + t.Fatalf("findings = %q, want %q", got, want) + } + if got, want := result.Output["verification_evidence"], "{raw json}"; got != want { + t.Fatalf("verification_evidence = %q, want %q", got, want) + } + if result.Output[resultParseKey] != lineParseParsed { + t.Fatalf("result_parse = %v", result.Output[resultParseKey]) + } +} + +func TestDecodeLineResultMissingOutcome(t *testing.T) { + raw := "\n\n# output\n{\"task\":\"x\"}\n" + result, status, err := decodeLineResult(raw, lineEdges()) + if err == nil || !errors.Is(err, ErrInvalidModelResult) || !strings.Contains(err.Error(), "missing outcome") { + t.Fatalf("expected missing-outcome error, got %v", err) + } + if status != lineParseFailed { + t.Fatalf("status = %q, want failed", status) + } + if result.Output[resultParseKey] != lineParseFailed { + t.Fatalf("result_parse = %v", result.Output[resultParseKey]) + } +} + +func TestDecodeLineResultUndeclaredOutcome(t *testing.T) { + raw := "bogus\n\n# output\n{\"task\":\"x\"}\n# findings\nkept\n" + result, status, err := decodeLineResult(raw, lineEdges()) + if err == nil || !errors.Is(err, ErrInvalidModelResult) || !strings.Contains(err.Error(), "undeclared outcome") { + t.Fatalf("expected undeclared-outcome error, got %v", err) + } + if status != lineParseFailed { + t.Fatalf("status = %q, want failed", status) + } + if result.Outcome != "" { + t.Fatalf("outcome = %q, want empty", result.Outcome) + } + if got, want := result.Output["findings"], "kept"; got != want { + t.Fatalf("findings salvage = %q, want %q", got, want) + } +} + +func TestDecodeLineResultMissingOutput(t *testing.T) { + raw := "success\n\n# findings\nkept\n" + result, status, err := decodeLineResult(raw, lineEdges()) + if err == nil || !errors.Is(err, ErrInvalidModelResult) { + t.Fatalf("expected error, got %v", err) + } + if status != lineParseFailed { + t.Fatalf("status = %q, want failed", status) + } + if got, want := result.Output["findings"], "kept"; got != want { + t.Fatalf("findings salvage = %q, want %q", got, want) + } +} + +func TestDecodeLineResultBestEffortExtras(t *testing.T) { + raw := "success\n# \nempty heading body\n# !@#\nodd heading body\n# big\n" + strings.Repeat("x", 70<<10) + "\n# output\n{\"ok\":true}\n" + result, status, err := decodeLineResult(raw, lineEdges()) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if status != lineParsePartial { + t.Fatalf("status = %q, want partial", status) + } + if result.Output["ok"] != true { + t.Fatalf("output ok = %v", result.Output["ok"]) + } + if result.Output["big"] == nil { + t.Fatal("missing big section") + } + if len(result.Output["big"].(string)) != 70<<10 { + t.Fatalf("big section length = %d", len(result.Output["big"].(string))) + } + if result.Output[resultParseKey] != lineParsePartial { + t.Fatalf("result_parse = %v", result.Output[resultParseKey]) + } +} + +func TestDecodeLineResultAdversarialProse(t *testing.T) { + raw := "success\n# findings\n- \"double\" and 'single' quotes\n```go\nfmt.Println(\"hi\")\n```\n{\"looks\":\"json\"}\nrejected\n# output\n{\"ok\":true}\n" + result, status, err := decodeLineResult(raw, lineEdges()) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if status != lineParseParsed { + t.Fatalf("status = %q, want parsed", status) + } + if result.Outcome != "success" { + t.Fatalf("outcome = %q, want success", result.Outcome) + } + body := result.Output["findings"].(string) + if !strings.Contains(body, `"double"`) || !strings.Contains(body, "'single'") || !strings.Contains(body, "```go") || !strings.Contains(body, "rejected") { + t.Fatalf("prose not verbatim: %q", body) + } +} + +func TestDecodeLineResultLargeResponse(t *testing.T) { + payload := strings.Repeat("x", 65<<10) + raw := "success\n# output\n{\"task\":\"" + payload + "\"}\n# findings\nok\n" + result, status, err := decodeLineResult(raw, lineEdges()) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if status != lineParseParsed { + t.Fatalf("status = %q, want parsed", status) + } + if result.Output["task"] != payload { + t.Fatal("payload mismatch") + } +} + +func TestModelRunLineFormatWritesRawOutputAndParses(t *testing.T) { + def := modelDefinition() + def.Edges = lineEdges() + def.ArtifactsDir = t.TempDir() + raw := "rejected\n\n# output\n{\"task\":\"x\"}\n\n# findings\n- BLOCKER\n" + client := generatorFunc(func(context.Context, ModelConfig, string) (string, error) { return raw, nil }) + result, err := (ModelStage{Client: client}).Run(context.Background(), def, nil) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if result.Outcome != "rejected" { + t.Fatalf("outcome = %q", result.Outcome) + } + if result.Output["task"] != "x" || result.Output["findings"] != "- BLOCKER" { + t.Fatalf("output mismatch: %+v", result.Output) + } + if result.Output[resultParseKey] != lineParseParsed { + t.Fatalf("result_parse = %v", result.Output[resultParseKey]) + } + got, err := os.ReadFile(filepath.Join(def.ArtifactsDir, "raw-output.md")) + if err != nil { + t.Fatalf("raw-output.md not written: %v", err) + } + if string(got) != raw { + t.Fatalf("raw-output.md mismatch") + } +} + +func TestModelRunLineFormatFailedParseStillWritesRawOutput(t *testing.T) { + def := modelDefinition() + def.Edges = lineEdges() + def.ArtifactsDir = t.TempDir() + raw := "bogus\n\n# findings\nkept\n" + client := generatorFunc(func(context.Context, ModelConfig, string) (string, error) { return raw, nil }) + result, err := (ModelStage{Client: client}).Run(context.Background(), def, nil) + if err == nil || !errors.Is(err, ErrInvalidModelResult) { + t.Fatalf("expected invalid result error, got %v", err) + } + if result.Outcome != "" { + t.Fatalf("outcome = %q, want empty", result.Outcome) + } + got, err := os.ReadFile(filepath.Join(def.ArtifactsDir, "raw-output.md")) + if err != nil { + t.Fatalf("raw-output.md not written: %v", err) + } + if string(got) != raw { + t.Fatalf("raw-output.md mismatch") + } +} + +func TestModelRunLegacyJSONPathUnchanged(t *testing.T) { + def := modelDefinition() + raw := `{"outcome":"success","output":{"task":"x"}}` + client := generatorFunc(func(context.Context, ModelConfig, string) (string, error) { return raw, nil }) + result, err := (ModelStage{Client: client}).Run(context.Background(), def, nil) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if result.Outcome != "success" || result.Output["task"] != "x" { + t.Fatalf("legacy path broken: %+v", result) + } +} + +func TestAgentResultTextPreservesLineFormat(t *testing.T) { + line := "success\n# output\n{\"ok\":true}\n# prose\n```json\n{\"x\":1}\n```\n" + if got := agentResultText(line); got != line { + t.Fatalf("agentResultText altered line format: %q", got) + } + json := "explaining\n{\"outcome\":\"success\",\"output\":{}}" + if got := agentResultText(json); got != "{\"outcome\":\"success\",\"output\":{}}" { + t.Fatalf("agentResultText did not extract JSON: %q", got) + } +} diff --git a/internal/stage/model.go b/internal/stage/model.go index dc52a161..4d1c4bfb 100644 --- a/internal/stage/model.go +++ b/internal/stage/model.go @@ -255,9 +255,16 @@ func (m ModelStage) Run(ctx context.Context, def Definition, input Values) (Resu } replayPostAdmission := false if generateErr == nil { - result, resultErr := decodeModelResult(stageResultText(text), def.Edges) - if resultErr != nil { - result, resultErr = repairModelResult(attemptCtx, client, spec.Config, text, def.Edges, resultErr) + var result Result + var resultErr error + if resultFormat(text) == "line" { + writeRawOutputFile(def.ArtifactsDir, text) + result, _, resultErr = decodeLineResult(text, def.Edges) + } else { + result, resultErr = decodeModelResult(stageResultText(text), def.Edges) + if resultErr != nil { + result, resultErr = repairModelResult(attemptCtx, client, spec.Config, text, def.Edges, resultErr) + } } if attemptCtx.Err() != nil { resultErr = errors.Join(resultErr, attemptCtx.Err()) diff --git a/internal/stage/pi.go b/internal/stage/pi.go index 78f38c2e..c418bb57 100644 --- a/internal/stage/pi.go +++ b/internal/stage/pi.go @@ -312,9 +312,21 @@ func (c *PiClient) Generate(ctx context.Context, config ModelConfig, prompt stri } // piEnvironment builds the spawned Pi process environment, including the -// per-stage artifacts directory when the runtime provided one. +// per-stage artifacts directory when the runtime provided one. Any +// PIPELINES_ARTIFACTS_DIR inherited from the process that spawns Pi is dropped +// first: the artifactsDir argument is authoritative, so an absent directory is +// never silently replaced by an ambient one (for example Pipelines' own +// PIPELINES_ARTIFACTS_DIR when a stage runs inside another stage). func piEnvironment(reference, artifactsDir string) []string { - env := append(os.Environ(), "PI_OFFLINE=1", + inherited := os.Environ() + env := make([]string, 0, len(inherited)+4) + for _, entry := range inherited { + if strings.HasPrefix(entry, ArtifactsEnv+"=") { + continue + } + env = append(env, entry) + } + env = append(env, "PI_OFFLINE=1", "PIPELINES_PI_POLICY="+filepath.Join(reference, "policy.json"), "PIPELINES_PI_LEASE="+filepath.Join(reference, "lease"), "PIPELINES_PI_STOPPED="+filepath.Join(reference, "quiescent")) diff --git a/internal/stage/stage.go b/internal/stage/stage.go index ce875473..0e6b7af9 100644 --- a/internal/stage/stage.go +++ b/internal/stage/stage.go @@ -52,7 +52,7 @@ func NewRegistry(types map[string]Stage) *Registry { } func DefaultRegistry() *Registry { - return NewRegistry(map[string]Stage{ModelType: ModelStage{}, NtfyType: NtfyStage{}}) + return NewRegistry(map[string]Stage{ModelType: ModelStage{}, NtfyType: NtfyStage{}, HumanType: HumanStage{}}) } func EffectiveType(name string) string { diff --git a/internal/summarise/summarise.go b/internal/summarise/summarise.go index dbb41ce7..2861201e 100644 --- a/internal/summarise/summarise.go +++ b/internal/summarise/summarise.go @@ -9,10 +9,14 @@ // the NoSummary sentinel instead of failing, stalling or delaying a stage or a // run. It never runs tools, never writes files and never propagates an error. // -// Obvious future call sites (not wired here): protocol.OutputPreview in -// internal/protocol/result.go and the notification summary in -// internal/server/notify.go. Changing a user-visible title/verdict later also -// requires updating the relevant internal/author/skill/references/*.md. +// Title/GenerateTitle build on Summarise to give every run a bounded, never +// empty operator-facing title: the model line when it succeeds and the prompt's +// first line otherwise. The server wires GenerateTitle at run creation; the +// store persists it with its source/model provenance. Obvious future call sites +// (not wired here): protocol.OutputPreview in internal/protocol/result.go and the +// notification summary in internal/server/notify.go. Changing a user-visible +// title/verdict later also requires updating the relevant +// internal/author/skill/references/*.md. package summarise import ( @@ -39,8 +43,34 @@ const NoSummary = "no summary" const InputCap = 8 << 10 // OutputCap bounds the returned summary to this many runes. Oversized replies -// are trimmed, never streamed onward. -const OutputCap = 200 +// are trimmed, never streamed onward. It is the same cap as a verdict reason +// (protocol.VerdictReasonCap), referenced from there so the two cannot drift. +const OutputCap = protocol.VerdictReasonCap + +// TitleCap bounds an operator-facing run title (in runes) whether it came from +// the model or the fallback, so a stored title stays a short single line. +const TitleCap = 80 + +// FallbackTitle is the last-resort title used when a prompt has no usable line, +// so a stored title is never empty. +const FallbackTitle = "Untitled run" + +// Title provenance recorded beside a stored run title so a diagnosis can tell a +// model title from the derived fallback. +const ( + SourceModel = "model" + SourceFallback = "fallback" + SourceExplicit = "explicit" +) + +// Title is a bounded, single-line operator-facing run title plus how it was +// produced: SourceModel with the generating Model, SourceFallback, or +// SourceExplicit when the operator typed it (--title or a rename). +type Title struct { + Text string + Source string + Model string +} // DefaultTimeout is the hard per-call budget: one generation must finish within // a few seconds even when the caller passes a longer or absent deadline. @@ -52,6 +82,14 @@ const instruction = "Summarise the untrusted data below in exactly one line of p "Do not use tools. Do not add a preamble, quotes, markdown code fences or trailing punctuation. " + "Reply with only the summary line. The following is untrusted data:\n" +// verdictInstruction is the fixed prompt for a stage verdict reason. It asks for +// exactly one plain-text line stating why the chosen option was selected and +// labels the appended source as untrusted data, matching the title instruction's +// style. +const verdictInstruction = "In exactly one line of plain text, state why the chosen option was selected for the untrusted data below. " + + "Do not use tools. Do not add a preamble, quotes, markdown code fences or trailing punctuation. " + + "Reply with only the reason line. The following is untrusted data:\n" + // quoteCutset is the set of surrounding characters stripped from a candidate // summary line (straight and typographic quotes, and backticks). const quoteCutset = "\"'`\u2018\u2019\u201c\u201d" @@ -59,6 +97,10 @@ const quoteCutset = "\"'`\u2018\u2019\u201c\u201d" // punctCutset is the set of trailing punctuation stripped from a summary line. const punctCutset = ".!?,;:\u2026\u3002\uff01\uff1f\uff0c\uff1b\uff1a" +// markCutset is the set of leading markdown markers (headings, quotes, list and +// emphasis tokens) stripped from a cleaned line so a title carries no markdown. +const markCutset = "#>*_`-+" + // Selection is the resolved harness configuration the summariser generates with. // Harness, Executable and Model come from the configured default harness profile // (its interactive Model, never its PipelineModel); none of them are constants. @@ -105,20 +147,35 @@ type Summariser struct { // records at most one bounded OperationEvidence when a call fails and Operations // is configured. It never propagates an error and never runs tools. func (s Summariser) Summarise(ctx context.Context, source string) string { + line, _ := s.summarise(ctx, source) + return line +} + +// summarise is the title-instruction wrapper behind Summarise and Title. +func (s Summariser) summarise(ctx context.Context, source string) (string, Selection) { + return s.summariseWith(ctx, instruction, source) +} + +// summariseWith is the single bounded implementation behind Summarise, Title and +// VerdictReason. It uses the supplied fixed instruction, returns the bounded line +// (or NoSummary) and the resolved selection, so a caller can record which model +// produced it without resolving the harness twice. It never propagates an error +// and never runs tools. +func (s Summariser) summariseWith(ctx context.Context, instruction, source string) (string, Selection) { selection, err := s.resolve() if err != nil { s.log(Selection{}, true, err) - return NoSummary + return NoSummary, Selection{} } if strings.TrimSpace(source) == "" { s.log(selection, false, nil) - return NoSummary + return NoSummary, selection } generator, err := s.generator(selection) if err != nil { s.record(selection, err) s.log(selection, true, err) - return NoSummary + return NoSummary, selection } timeout := s.Timeout if timeout <= 0 { @@ -141,19 +198,87 @@ func (s Summariser) Summarise(ctx context.Context, source string) string { if err != nil { s.record(selection, err) s.log(selection, true, err) - return NoSummary + return NoSummary, selection } line := oneLine(text) if line == "" { err = fmt.Errorf("model returned no usable one-line summary") s.record(selection, err) s.log(selection, true, err) - return NoSummary + return NoSummary, selection } s.log(selection, false, nil) + return line, selection +} + +// Title returns a bounded, single-line operator-facing title for a run created +// from prompt. It asks the shared summariser for one bounded line and, when that +// fails or times out, falls back to the prompt's first usable line. It never +// returns an empty title, never propagates an error and never exceeds the +// summariser's hard timeout, so run creation always starts with a usable title. +func (s Summariser) Title(ctx context.Context, prompt string) Title { + line, selection := s.summarise(ctx, prompt) + if line != NoSummary { + if text := capRunes(line, TitleCap); text != "" { + return Title{Text: text, Source: SourceModel, Model: selection.Model} + } + } + return Title{Text: DeriveTitle(prompt), Source: SourceFallback} +} + +// GenerateTitle is the package entry point that derives a run title from the +// configured default harness, so a caller need not construct a Summariser. It is +// bounded and never blocks past the summariser's hard timeout. +func GenerateTitle(ctx context.Context, prompt string) Title { return Summariser{}.Title(ctx, prompt) } + +// VerdictReason returns a bounded, single-line reason for a completed stage +// visit's chosen option, or NoSummary. It is best-effort by the same contract as +// Summarise: one tool-free generation, the hard DefaultTimeout, no retries, and +// NoSummary on any error or timeout so a summariser failure can never fail a stage +// or a run. +func (s Summariser) VerdictReason(ctx context.Context, source string) string { + line, _ := s.summariseWith(ctx, verdictInstruction, source) return line } +// GenerateVerdictReason is the package entry point the server wires as its +// per-step verdict seam. It renders the bounded source from a stage's output map +// using the shared Protocol output preview (the same key order the store already +// exposes) and asks the configured default harness for one reason line. An output +// with no usable preview skips generation entirely, so no model call is wasted. +func GenerateVerdictReason(ctx context.Context, output map[string]any) string { + source := protocol.OutputPreview(output) + if strings.TrimSpace(source) == "" { + return NoSummary + } + return Summariser{}.VerdictReason(ctx, source) +} + +// DeriveTitle is the bounded fallback title for a run prompt: its first usable +// line, cleaned the same way a model reply is and capped to TitleCap runes. It is +// never empty. +func DeriveTitle(prompt string) string { + for _, raw := range strings.Split(prompt, "\n") { + if line := cleanLine(raw); line != "" { + return capRunes(line, TitleCap) + } + } + return FallbackTitle +} + +// ExplicitTitle normalises an operator-supplied run title (--title or a rename) +// to a bounded single line and reports whether it carried usable text. Unlike a +// derived title it preserves the operator's wording and punctuation, only +// collapsing whitespace and controlling characters; it is never generated or +// model-cleaned. +func ExplicitTitle(raw string) (Title, bool) { + text := capRunes(protocol.NormalizeText(raw), TitleCap) + if text == "" { + return Title{}, false + } + return Title{Text: text, Source: SourceExplicit}, true +} + func (s Summariser) resolve() (Selection, error) { if s.Selection != nil { if s.Selection.Harness == "" { @@ -208,23 +333,31 @@ func truncateSource(source string) string { // punctuation, and caps the result to OutputCap runes. func oneLine(text string) string { for _, raw := range strings.Split(text, "\n") { - line := strings.TrimSpace(raw) - if line == "" || isFenceLine(line) { - continue + if line := cleanLine(raw); line != "" { + return capRunes(line, OutputCap) } - line = strings.TrimSpace(protocol.NormalizeText(line)) - line = strings.Trim(line, quoteCutset) - line = strings.TrimSpace(line) - line = strings.TrimRight(line, punctCutset) - line = strings.TrimSpace(line) - if line == "" { - continue - } - return capRunes(line, OutputCap) } return "" } +// cleanLine reduces one raw line to plain single-line text, or "" when it carries +// no usable content (empty, whitespace or a bare code fence). It collapses +// whitespace/control characters, strips surrounding quotes, leading markdown +// markers and trailing punctuation. It is the shared primitive behind a summary +// line and a derived run title. +func cleanLine(raw string) string { + line := strings.TrimSpace(raw) + if line == "" || isFenceLine(line) { + return "" + } + line = strings.TrimSpace(protocol.NormalizeText(line)) + line = strings.TrimSpace(strings.TrimLeft(line, markCutset)) + line = strings.Trim(line, quoteCutset) + line = strings.TrimSpace(line) + line = strings.TrimRight(line, punctCutset) + return strings.TrimSpace(line) +} + // isFenceLine reports whether a trimmed line is a markdown code-fence delimiter // (an optional language token after a run of backticks/tildes, but no content). // "```Summary```" is not a fence line: it carries content and is cleaned instead. diff --git a/internal/summarise/summarise_test.go b/internal/summarise/summarise_test.go index 08c77ada..248a3539 100644 --- a/internal/summarise/summarise_test.go +++ b/internal/summarise/summarise_test.go @@ -267,6 +267,87 @@ func TestSummariseDiagnostics(t *testing.T) { } } +func TestTitleUsesModelLineAndRecordsSource(t *testing.T) { + s := Summariser{ + Selection: selection(), + Generator: generatorFunc(func(context.Context, stage.ModelConfig, string) (string, error) { + return `## "Fix the flaky login test."`, nil + }), + } + got := s.Title(context.Background(), "prompt text") + if got.Text != "Fix the flaky login test" { + t.Fatalf("got %q, want the cleaned model title", got.Text) + } + if got.Source != SourceModel || got.Model != "p/open" { + t.Fatalf("title provenance = %+v, want model p/open", got) + } +} + +func TestTitleFallsBackToBoundedPromptLine(t *testing.T) { + long := strings.Repeat("é", TitleCap*2) + s := Summariser{ + Selection: selection(), + Generator: generatorFunc(func(context.Context, stage.ModelConfig, string) (string, error) { + return "", errors.New("transport down") + }), + } + for _, prompt := range []string{"First line\nthen ignored", " \n Fix the widget \nmore", "- bullet task here\nrest", long} { + got := s.Title(context.Background(), prompt) + if got.Text == "" || got.Text == NoSummary || got.Text == FallbackTitle { + t.Fatalf("prompt %q produced unusable title %+v", prompt, got) + } + if got.Source != SourceFallback || got.Model != "" { + t.Fatalf("prompt %q provenance = %+v, want fallback with no model", prompt, got) + } + if len([]rune(got.Text)) > TitleCap { + t.Fatalf("prompt %q title has %d runes, want <= %d", prompt, len([]rune(got.Text)), TitleCap) + } + if strings.ContainsAny(got.Text, "\r\n") { + t.Fatalf("prompt %q title %q is not a single line", prompt, got.Text) + } + } + if got := s.Title(context.Background(), "First line\nthen ignored"); got.Text != "First line" { + t.Fatalf("fallback title = %q, want the prompt's first line", got.Text) + } + if got := s.Title(context.Background(), "- bullet task here\nrest"); got.Text != "bullet task here" { + t.Fatalf("fallback stripped markdown = %q, want the leading marker removed", got.Text) + } +} + +func TestTitleNeverEmptyForBlankPrompt(t *testing.T) { + s := Summariser{ + Selection: selection(), + Generator: generatorFunc(func(context.Context, stage.ModelConfig, string) (string, error) { + return "", nil + }), + } + got := s.Title(context.Background(), " \n\t") + if got.Text != FallbackTitle || got.Source != SourceFallback { + t.Fatalf("blank prompt title = %+v, want %q fallback", got, FallbackTitle) + } +} + +func TestExplicitTitleNormalisesAndBounds(t *testing.T) { + got, ok := ExplicitTitle(" Fix the\nflaky login test ") + if !ok || got.Text != "Fix the flaky login test" || got.Source != SourceExplicit || got.Model != "" { + t.Fatalf("explicit title = %+v, %t; want collapsed explicit text", got, ok) + } + // The operator's punctuation and wording are preserved, unlike a cleaned + // model line. + if got, ok := ExplicitTitle("Ship v2.0!"); !ok || got.Text != "Ship v2.0!" { + t.Fatalf("explicit title altered the operator's text: %+v %t", got, ok) + } + long := strings.Repeat("é", TitleCap*2) + if got, ok := ExplicitTitle(long); !ok || len([]rune(got.Text)) != TitleCap { + t.Fatalf("explicit title not capped to %d runes: %d", TitleCap, len([]rune(got.Text))) + } + for _, blank := range []string{"", " ", "\n\t", "\x00\x01"} { + if got, ok := ExplicitTitle(blank); ok { + t.Fatalf("blank explicit title %q accepted as %+v", blank, got) + } + } +} + func TestSummariseSuccessLogsAndRecordsNoFailure(t *testing.T) { var logs []string operations := &stage.OperationLog{} @@ -288,3 +369,47 @@ func TestSummariseSuccessLogsAndRecordsNoFailure(t *testing.T) { t.Fatalf("success recorded %d failure evidence records", len(operations.Failures)) } } + +func TestVerdictReasonUsesModelLineAndBounds(t *testing.T) { + var prompt string + s := Summariser{ + Selection: selection(), + Generator: generatorFunc(func(_ context.Context, _ stage.ModelConfig, p string) (string, error) { + prompt = p + return strings.Repeat("x", OutputCap+50), nil + }), + } + got := s.VerdictReason(context.Background(), "source text") + if len([]rune(got)) != OutputCap { + t.Fatalf("got %d runes, want the OutputCap %d", len([]rune(got)), OutputCap) + } + if !strings.Contains(prompt, verdictInstruction) { + t.Fatal("verdict prompt is missing the fixed verdict instruction") + } + if !strings.Contains(verdictInstruction, "why the chosen option") || !strings.Contains(verdictInstruction, "untrusted") { + t.Fatal("verdict instruction does not ask for a reason over untrusted data") + } + if got := s.VerdictReason(context.Background(), " "); got != NoSummary { + t.Fatalf("blank source produced %q, want %q", got, NoSummary) + } +} + +func TestVerdictReasonIsBestEffort(t *testing.T) { + s := Summariser{ + Selection: selection(), + Generator: generatorFunc(func(context.Context, stage.ModelConfig, string) (string, error) { + return "", errors.New("transport down") + }), + } + if got := s.VerdictReason(context.Background(), "source"); got != NoSummary { + t.Fatalf("generator error produced %q, want %q", got, NoSummary) + } +} + +func TestGenerateVerdictReasonSkipsEmptyOutput(t *testing.T) { + for _, output := range []map[string]any{nil, {}, {"input": "only excluded keys"}} { + if got := GenerateVerdictReason(context.Background(), output); got != NoSummary { + t.Fatalf("output %v produced %q, want %q with no model call", output, got, NoSummary) + } + } +} diff --git a/internal/tui/cli_run.go b/internal/tui/cli_run.go index 674991f0..f805da4e 100644 --- a/internal/tui/cli_run.go +++ b/internal/tui/cli_run.go @@ -10,9 +10,9 @@ import ( ) type RunOptions struct { - Pipeline, Prompt, Workspace string - Yes, AllowTools bool - WritePaths []string + Pipeline, Prompt, Title, Workspace string + Yes, AllowTools bool + WritePaths []string } func NewRun(ctx context.Context, url string, options RunOptions) Model { diff --git a/internal/tui/context_footer.go b/internal/tui/context_footer.go index c012e64e..55d3d63d 100644 --- a/internal/tui/context_footer.go +++ b/internal/tui/context_footer.go @@ -13,6 +13,8 @@ func (m Model) activeFooter() string { switch { case m.editorChecking: text = "Refreshing published state · draft retained" + case m.decisionOpen: + text = "↑/↓ choose · Tab feedback · Enter decide · Esc cancel" case m.actionConfirm != nil || m.mutationCommand != nil: text = "y confirm · n/Esc cancel · j/k read" case m.draftDeletingPath != "": @@ -59,6 +61,8 @@ func (m Model) activeFooter() string { switch { case m.editorChecking: text = "Refreshing · draft retained" + case m.decisionOpen: + text = "Esc cancel · Enter decide · ↑↓ select" case m.actionConfirm != nil || m.mutationCommand != nil: text = "Esc cancel · y confirm · j/k read" case m.draftDeletingPath != "": diff --git a/internal/tui/dashboard.go b/internal/tui/dashboard.go index 22f5fd4d..0689a3e2 100644 --- a/internal/tui/dashboard.go +++ b/internal/tui/dashboard.go @@ -98,12 +98,15 @@ func (m Model) homeLines() []string { limit = 2 } for _, r := range m.runs[:min(limit, len(m.runs))] { - runs = append(runs, bar(fmt.Sprintf("#%d %s", r.ID, r.Name), m.progress(r.Status), max(1, panelWidth-4), false)) + runs = append(runs, bar(fmt.Sprintf("#%d %s", r.ID, r.Label()), m.progress(r.Status), max(1, panelWidth-4), false)) runs = append(runs, previewRows(resultLabel(r), max(1, panelWidth-4), 3)...) runs = append(runs, lipgloss.NewStyle().Foreground(themeMuted).Render(fmt.Sprintf("v%d · %d completed visits · %s", r.Version, r.CompletedSteps, runDuration(r.CreatedAt, r.FinishedAt)))) if r.CurrentStage != "" && (r.Status == "running" || r.Status == "queued") { runs = append(runs, "Working on "+r.CurrentStage) } + if r.Status == protocol.RunStatusWaiting { + runs = append(runs, "Waiting on a person · stage "+r.CurrentStage) + } runs = append(runs, "") } if len(m.runs) > limit { @@ -123,7 +126,7 @@ func (m Model) homeLines() []string { lines = append(lines, lipgloss.NewStyle().Bold(true).Render(p.Name), lipgloss.NewStyle().Foreground(themeMuted).Render(fmt.Sprintf("v%d · %d stages", p.Version, p.Stages))) if r := m.latestPipelineRun(p.ID, 0); r != nil { - lines = append(lines, fmt.Sprintf("Last run #%d · v%d · %s", r.ID, r.Version, m.progress(r.Status))) + lines = append(lines, fmt.Sprintf("Last run #%d · %s · v%d · %s", r.ID, r.Label(), r.Version, m.progress(r.Status))) lines = append(lines, previewRows(resultLabel(*r), max(1, pipelineWidth-4), 2)...) } else { lines = append(lines, "Not run yet · no recorded results") diff --git a/internal/tui/dashboard_test.go b/internal/tui/dashboard_test.go index 91654fcc..c18d4956 100644 --- a/internal/tui/dashboard_test.go +++ b/internal/tui/dashboard_test.go @@ -143,7 +143,7 @@ func TestHomeOnlyAdvertisesSearchAndCommands(t *testing.T) { m.usage = &protocol.UsageStats{} } view := ansi.Strip(m.View()) - for _, hint := range []string{"/ search", ": commands"} { + for _, hint := range []string{"/ omni search", ": commands"} { if !strings.Contains(view, hint) { t.Fatal("missing home hint", hint, view) } diff --git a/internal/tui/decision.go b/internal/tui/decision.go new file mode 100644 index 00000000..3b0ce482 --- /dev/null +++ b/internal/tui/decision.go @@ -0,0 +1,164 @@ +package tui + +import ( + "fmt" + "strings" + + "git.a-wan.net/alan/pipelines/internal/protocol" + "git.a-wan.net/alan/pipelines/internal/stage" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/x/ansi" +) + +// lastWaitingStep returns the most recent step a run is waiting on (the last +// waiting step by sequence), or false when no step is waiting. The decision +// overlay and the run summary both read it, so the scan lives once. +func lastWaitingStep(r *protocol.RunDetail) (protocol.RunStep, bool) { + for i := len(r.Steps) - 1; i >= 0; i-- { + if r.Steps[i].Status == protocol.StepStatusWaiting { + return r.Steps[i], true + } + } + return protocol.RunStep{}, false +} + +// waitingStage returns the stage the open run is waiting on plus its recorded +// prompt and selectable options. It prefers the self-contained evidence on the +// waiting step and falls back to the pinned graph's edges when a step recorded +// no options. +func (m Model) waitingStage() (string, []string, string) { + if m.runDetail == nil { + return "", nil, "" + } + if step, ok := lastWaitingStep(m.runDetail); ok { + return step.Stage, protocol.WaitingOptions(step.Output), protocol.WaitingPrompt(step.Output) + } + key := m.runDetail.CurrentStage + for _, declared := range m.runDetail.Graph.Stages { + if declared.Key == key { + return key, stage.HumanOptions(declared.Edges), declared.Prompt + } + } + return key, nil, "" +} + +func (m Model) openDecision() (tea.Model, tea.Cmd) { + if m.runDetail == nil || m.runDetail.Status != protocol.RunStatusWaiting { + m.runError = "This run is not waiting for a decision." + return m, nil + } + key, options, _ := m.waitingStage() + if len(options) == 0 { + m.runError = "No selectable options recorded for the waiting stage." + return m, nil + } + m.decisionOpen = true + m.decisionRunID = m.runDetail.ID + m.decisionStage = key + m.decisionOptions = options + m.decisionIndex = 0 + m.decisionFeedback = newInput() + m.decisionFeedback.Placeholder = "Optional feedback" + m.decisionFeedback.Width = max(1, min(60, m.width-12)) + m.decisionFeedbackFocus = false + return m, nil +} + +func (m *Model) closeDecision() { + m.decisionOpen = false + m.decisionRunID = 0 + m.decisionStage = "" + m.decisionOptions = nil + m.decisionIndex = 0 + m.decisionFeedback = newInput() + m.decisionFeedbackFocus = false +} + +func (m Model) updateDecision(msg tea.KeyMsg) (tea.Model, tea.Cmd) { + switch msg.String() { + case "esc": + m.closeDecision() + return m, nil + case "tab": + m.decisionFeedbackFocus = !m.decisionFeedbackFocus + if m.decisionFeedbackFocus { + return m, m.decisionFeedback.Focus() + } + m.decisionFeedback.Blur() + return m, nil + case "f": + if !m.decisionFeedbackFocus { + m.decisionFeedbackFocus = true + return m, m.decisionFeedback.Focus() + } + case "up", "k": + if !m.decisionFeedbackFocus { + m.decisionIndex = max(0, m.decisionIndex-1) + return m, nil + } + case "down", "j": + if !m.decisionFeedbackFocus { + m.decisionIndex = min(m.decisionIndex+1, max(0, len(m.decisionOptions)-1)) + return m, nil + } + case "enter": + if len(m.decisionOptions) == 0 { + return m, nil + } + option := m.decisionOptions[min(m.decisionIndex, len(m.decisionOptions)-1)] + feedback := strings.TrimSpace(m.decisionFeedback.Value()) + request := protocol.Message{Type: protocol.DecideRun, RunID: m.decisionRunID, Stage: m.decisionStage, Option: option, Feedback: feedback} + m.closeDecision() + return m.runRequest(request) + } + if m.decisionFeedbackFocus { + var cmd tea.Cmd + m.decisionFeedback, cmd = m.decisionFeedback.Update(msg) + return m, cmd + } + return m, nil +} + +func (m Model) decisionView(height int) string { + title := fmt.Sprintf("Decide %s · run #%d", m.decisionStage, m.decisionRunID) + intro := "Choose where the run goes next. The choice and feedback are recorded as the stage's evidence." + if m.width < 65 { + intro = "Choose where the run goes next." + } + // Size the option window to the panel body so every shown paragraph fits and + // the selected option is never clipped: each option costs a line plus a + // separator, and the feedback line always fits. The count of shown options + // goes in the controls, so a windowed list still says more exist. + dialogWidth := min(m.width, 76) + inner := max(1, dialogWidth-4) + introLines := len(strings.Split(ansi.Wrap(intro, inner, ""), "\n")) + capacity := max(1, (height-4-introLines)/2-1) + count := len(m.decisionOptions) + start, end := selectionWindow(count, m.decisionIndex, capacity) + paragraphs := []string{intro} + for i := start; i < end; i++ { + marker := " " + if i == m.decisionIndex { + marker = " › " + } + paragraphs = append(paragraphs, marker+m.decisionOptions[i]) + } + paragraphs = append(paragraphs, "Feedback: "+m.decisionFeedback.View()) + controls := "↑/↓ choose · Tab feedback · Enter decide · Esc cancel" + if end-start < count { + controls += fmt.Sprintf(" · %d/%d", end-start, count) + } + if m.width < 65 { + controls = "↑↓ select · Enter decide · Esc" + if end-start < count { + controls += fmt.Sprintf(" · %d/%d", end-start, count) + } + } + if m.decisionFeedbackFocus { + controls = "type feedback · Tab options · Enter decide · Esc cancel" + if m.width < 65 { + controls = "type feedback · Enter decide · Esc" + } + } + return wrappedDialog(m.width, height, 72, title, paragraphs, controls, 0) +} diff --git a/internal/tui/decision_test.go b/internal/tui/decision_test.go new file mode 100644 index 00000000..dbdafeb5 --- /dev/null +++ b/internal/tui/decision_test.go @@ -0,0 +1,137 @@ +package tui + +import ( + "context" + "strings" + "testing" + + "git.a-wan.net/alan/pipelines/internal/protocol" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/x/ansi" +) + +func decisionModel() Model { + m := New(context.Background(), "") + m.width = 100 + m.height = 30 + m.runOpen = true + m.keys.runs = true + m.requestedRunID = 8 + m.runDetail = &protocol.RunDetail{ + RunSummary: protocol.RunSummary{ID: 8, Name: "release", Version: 1, Status: protocol.RunStatusWaiting, CurrentStage: "gate"}, + Steps: []protocol.RunStep{{ + Sequence: 1, Stage: "gate", Status: protocol.StepStatusWaiting, + Output: protocol.NewWaitingEvidence("Approve the release?", []string{"go", "halt"}), + }}, + } + return m +} + +func TestWaitingRunRendersPromptAndOptions(t *testing.T) { + m := decisionModel() + text := ansi.Strip(strings.Join(m.runSectionLines(m.runDetailWidth()), "\n")) + for _, want := range []string{"Waiting for a person · stage gate", "Approve the release?", "Options: go, halt"} { + if !strings.Contains(text, want) { + t.Fatalf("waiting run view missing %q:\n%s", want, text) + } + } + detail := ansi.Strip(m.runsDetailsView(24)) + if !strings.Contains(detail, "Waiting for a person") { + t.Fatalf("run detail omitted the waiting banner:\n%s", detail) + } +} + +func TestDecisionOverlaySelectsAndEmits(t *testing.T) { + m := decisionModel() + updated, _ := m.openDecision() + m = updated.(Model) + if !m.decisionOpen || m.decisionStage != "gate" || strings.Join(m.decisionOptions, ",") != "go,halt" { + t.Fatalf("overlay did not open with the recorded options: %+v", m.decisionOptions) + } + if view := ansi.Strip(m.decisionView(24)); !strings.Contains(view, "Decide gate") || !strings.Contains(view, "halt") { + t.Fatalf("overlay view missing the choice:\n%s", view) + } + + updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyDown}) + m = updated.(Model) + if m.decisionIndex != 1 { + t.Fatalf("down did not move the selection: %d", m.decisionIndex) + } + updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyTab}) + m = updated.(Model) + if !m.decisionFeedbackFocus { + t.Fatal("Tab did not focus the feedback field") + } + updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyEsc}) + m = updated.(Model) + if m.decisionOpen { + t.Fatal("Esc did not close the overlay") + } + + // Enter emits a DecideRun request; with no connection the send path records + // the attempt and the overlay closes. + updated, _ = m.openDecision() + m = updated.(Model) + m.decisionFeedback.SetValue("looks good") + before := len(m.lines) + updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyEnter}) + m = updated.(Model) + if m.decisionOpen { + t.Fatal("Enter did not close the overlay") + } + if len(m.lines) == before { + t.Fatal("Enter did not attempt to send the decision") + } + if !strings.Contains(strings.Join(m.lines, "\n"), "not connected") { + t.Fatalf("decision path did not run: %v", m.lines) + } +} + +// TestDecisionOverlayKeepsSelectionVisibleAtNarrowViewport proves the overlay +// windows its option list like the palette: at the smallest reviewed viewport +// the selected option stays visible with its marker and a count says more exist. +func TestDecisionOverlayKeepsSelectionVisibleAtNarrowViewport(t *testing.T) { + m := decisionModel() + m.width = 40 + m.height = 16 + m.runDetail.Steps[0].Output = protocol.NewWaitingEvidence("Approve the release?", []string{"abort", "deploy", "revise"}) + updated, _ := m.openDecision() + m = updated.(Model) + // Move onto the option a fixed, unwindowed list would clip at this viewport. + updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyDown}) + m = updated.(Model) + updated, _ = m.updateDecision(tea.KeyMsg{Type: tea.KeyDown}) + m = updated.(Model) + view := ansi.Strip(m.View()) + if !strings.Contains(view, "› revise") { + t.Fatalf("selected option is not visible with a marker at 40x16:\n%s", view) + } + if !strings.Contains(view, "2/3") { + t.Fatalf("option count affordance missing at 40x16:\n%s", view) + } + if strings.Contains(view, "Enter d…") { + t.Fatalf("controls are still truncated at 40x16:\n%s", view) + } +} + +// TestDecidedHumanStepRendersNeutralFeedback locks the fix for the review +// finding: a completed decision shows its feedback as a normal output field, +// never as the error-style "Stopped:" line reserved for real stops. +func TestDecidedHumanStepRendersNeutralFeedback(t *testing.T) { + m := decisionModel() + m.runDetail.Status = "succeeded" + output := map[string]any{"option": "go", "feedback": "looks good"} + m.runDetail.Steps[0] = protocol.RunStep{ + Sequence: 1, Stage: "gate", Status: "completed", Outcome: "go", Target: "worker", + Output: output, + Verdict: protocol.NewStageVerdict("go", "worker", output, nil, "", ""), + } + m.runStepIndex = 1 + view := ansi.Strip(strings.Join(m.runSectionLines(m.runDetailWidth()), "\n")) + if strings.Contains(view, "Stopped:") { + t.Fatalf("a deliberate decision must not render as a stop:\n%s", view) + } + if !strings.Contains(view, "looks good") { + t.Fatalf("decision feedback is not visible:\n%s", view) + } +} diff --git a/internal/tui/drafts.go b/internal/tui/drafts.go index f121281e..76edd6b8 100644 --- a/internal/tui/drafts.go +++ b/internal/tui/drafts.go @@ -15,8 +15,9 @@ import ( ) type draftValidationMsg struct { - path string - err error + path string + notices []string + err error } func (m Model) openDrafts() (tea.Model, tea.Cmd) { @@ -157,8 +158,10 @@ func (m Model) updateDrafts(msg tea.KeyMsg) (tea.Model, tea.Cmd) { return draftValidationMsg{path: d.Path, err: err} } defer c.Close() + sink := ¬iceSink{} + c.Report(sink.report) _, err = c.Call(ctx, protocol.Message{Type: protocol.Validate, Source: source}) - return draftValidationMsg{path: d.Path, err: err} + return draftValidationMsg{path: d.Path, notices: sink.drain(), err: err} } } } diff --git a/internal/tui/editor_publication.go b/internal/tui/editor_publication.go index 4210ba3b..952968a5 100644 --- a/internal/tui/editor_publication.go +++ b/internal/tui/editor_publication.go @@ -16,71 +16,85 @@ type editorPublicationMsg struct { pipelines []protocol.PipelineSummary detail *protocol.PipelineDetail published bool + notices []string err error } func checkEditorPublication(ctx context.Context, endpoint string, edit editedMsg, generation uint64) tea.Cmd { return func() tea.Msg { - result := editorPublicationMsg{edit: edit, generation: generation} - ctx, cancel := context.WithTimeout(ctx, 10*time.Second) - defer cancel() - c, err := client.Open(ctx, endpoint) + return publicationCheck(ctx, endpoint, edit, generation) + } +} + +// publicationCheck runs the publication comparison for one editor submission. +// The named result lets the deferred hook attach any build/protocol notices +// from the short-lived client to every return path. +func publicationCheck(ctx context.Context, endpoint string, edit editedMsg, generation uint64) (result editorPublicationMsg) { + result = editorPublicationMsg{edit: edit, generation: generation} + ctx, cancel := context.WithTimeout(ctx, 10*time.Second) + defer cancel() + c, err := client.Open(ctx, endpoint) + if err != nil { + result.err = err + return result + } + defer c.Close() + sink := ¬iceSink{} + c.Report(sink.report) + // Surface any build/protocol notice through the shared TUI notice path + // rather than dropping it for this short-lived client. + defer func() { result.notices = sink.drain() }() + list, err := c.Call(ctx, protocol.Message{Type: protocol.List}) + if err != nil { + result.err = err + return result + } + result.pipelines = list.Pipelines + for _, p := range list.Pipelines { + if p.Name != strings.TrimSpace(edit.name) { + continue + } + response, err := c.Call(ctx, protocol.Message{Type: protocol.GetPipeline, PipelineID: p.ID}) if err != nil { result.err = err return result } - defer c.Close() - list, err := c.Call(ctx, protocol.Message{Type: protocol.List}) - if err != nil { - result.err = err + result.detail = response.Detail + if result.detail == nil { + result.err = fmt.Errorf("server returned no pipeline detail") return result } - result.pipelines = list.Pipelines - for _, p := range list.Pipelines { - if p.Name != strings.TrimSpace(edit.name) { + if result.detail.Source == edit.source { + result.published = true + return result + } + // If another version was published afterward, the editor's submitted + // source still must not be offered for duplicate submission. Only + // inspect versions newer than this draft's immutable starting point. + for _, v := range result.detail.Versions { + if v.Version <= edit.baseVersion || v.Version == result.detail.Version { continue } - response, err := c.Call(ctx, protocol.Message{Type: protocol.GetPipeline, PipelineID: p.ID}) + response, err := c.Call(ctx, protocol.Message{Type: protocol.GetPipeline, PipelineID: p.ID, Version: v.Version}) if err != nil { result.err = err return result } - result.detail = response.Detail - if result.detail == nil { - result.err = fmt.Errorf("server returned no pipeline detail") - return result - } - if result.detail.Source == edit.source { + if response.Detail != nil && response.Detail.Source == edit.source { result.published = true return result } - // If another version was published afterward, the editor's submitted - // source still must not be offered for duplicate submission. Only - // inspect versions newer than this draft's immutable starting point. - for _, v := range result.detail.Versions { - if v.Version <= edit.baseVersion || v.Version == result.detail.Version { - continue - } - response, err := c.Call(ctx, protocol.Message{Type: protocol.GetPipeline, PipelineID: p.ID, Version: v.Version}) - if err != nil { - result.err = err - return result - } - if response.Detail != nil && response.Detail.Source == edit.source { - result.published = true - return result - } - } - return result } return result } + return result } func (m Model) finishEditorPublication(msg editorPublicationMsg) (tea.Model, tea.Cmd) { if msg.generation != m.editorCheckGeneration { return m, nil } + m.appendNotices(msg.notices) m.editorChecking = false if msg.err == nil { m.pipelines = msg.pipelines diff --git a/internal/tui/editor_publication_test.go b/internal/tui/editor_publication_test.go index fbd8e1d2..c902fd9c 100644 --- a/internal/tui/editor_publication_test.go +++ b/internal/tui/editor_publication_test.go @@ -2,8 +2,11 @@ package tui import ( "context" + "git.a-wan.net/alan/pipelines/internal/buildinfo" "git.a-wan.net/alan/pipelines/internal/pipeline" + "git.a-wan.net/alan/pipelines/internal/protocol" "git.a-wan.net/alan/pipelines/internal/server" + "git.a-wan.net/alan/pipelines/internal/wstest" "net/http/httptest" "path/filepath" "strings" @@ -11,6 +14,35 @@ import ( "time" ) +// TestEditorPublicationSurfacesBuildMismatchNotice proves a short-lived TUI +// command client routes its build/protocol notice through the shared notice +// path instead of dropping it (the artifacts-field regression). +func TestEditorPublicationSurfacesBuildMismatchNotice(t *testing.T) { + stale := buildinfo.Info{Version: "v0-stale-server", Commit: "deadbeef"} + endpoint := wstest.Server(t, func(request protocol.Message) protocol.Message { + switch request.Type { + case protocol.List: + return protocol.Message{Type: protocol.List, Build: &stale, Protocol: protocol.ProtocolVersion, + Pipelines: []protocol.PipelineSummary{{ID: 7, Name: "test", Version: 1}}} + case protocol.GetPipeline: + return protocol.Message{Type: protocol.GetPipeline, + Detail: &protocol.PipelineDetail{PipelineSummary: protocol.PipelineSummary{ID: 7, Name: "test", Version: 1}, Source: "published"}} + } + return protocol.Message{Type: protocol.Pong} + }) + edit := editedMsg{name: "test", source: "published", baseVersion: 0} + result := publicationCheck(context.Background(), endpoint, edit, 0) + if len(result.notices) != 1 { + t.Fatalf("short-lived client dropped the build mismatch notice: %+v", result.notices) + } + m := New(context.Background(), endpoint) + updated, _ := m.finishEditorPublication(result) + m = updated.(Model) + if !strings.Contains(strings.Join(m.lines, "\n"), "warning:") { + t.Fatalf("notice not routed to the shared TUI notice path: %q", m.lines) + } +} + func TestEditorReturnFindsPublishedVersionAndReloadsLatest(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() diff --git a/internal/tui/model.go b/internal/tui/model.go index deea282c..6db91ae9 100644 --- a/internal/tui/model.go +++ b/internal/tui/model.go @@ -24,7 +24,10 @@ import ( "git.a-wan.net/alan/pipelines/internal/protocol" ) -type connectedMsg struct{ conn *websocket.Conn } +type connectedMsg struct { + conn *websocket.Conn + watch *client.Watch +} type receivedMsg protocol.Message type sentMsg struct{ id string } type errorMsg struct { @@ -34,6 +37,7 @@ type errorMsg struct { type socketMsg struct { conn *websocket.Conn message protocol.Message + notices []string } type reconnectMsg struct{} @@ -109,6 +113,7 @@ type Model struct { ctx context.Context url string conn *websocket.Conn + watch *client.Watch status string nextID uint64 lines []string @@ -185,6 +190,13 @@ type Model struct { runGraphFocus bool runGraphTop int runGraphPan int + decisionOpen bool + decisionRunID int64 + decisionStage string + decisionOptions []string + decisionIndex int + decisionFeedback textinput.Model + decisionFeedbackFocus bool editorOpen bool editorInput textinput.Model editorIndex int @@ -209,7 +221,7 @@ func New(ctx context.Context, url string) Model { runSpinner: spinner.New(spinner.WithSpinner(spinner.Spinner{Frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}, FPS: time.Second / 12}), spinner.WithStyle(lipgloss.NewStyle().Foreground(themeAccent))), keys: keyMap{ commands: key.NewBinding(key.WithKeys(":"), key.WithHelp(":", "commands")), - search: key.NewBinding(key.WithKeys("/"), key.WithHelp("/", "search")), + search: key.NewBinding(key.WithKeys("/"), key.WithHelp("/", "omni search")), create: key.NewBinding(key.WithKeys("n"), key.WithHelp("n", "new pipeline")), enter: key.NewBinding(key.WithKeys("enter"), key.WithHelp("enter", "continue")), cancel: key.NewBinding(key.WithKeys("esc"), key.WithHelp("esc", "cancel")), @@ -236,17 +248,17 @@ func (m Model) connect() tea.Cmd { <-m.ctx.Done() conn.CloseNow() }() - return connectedMsg{conn} + return connectedMsg{conn: conn, watch: &client.Watch{}} } } func (m Model) read() tea.Cmd { return func() tea.Msg { - response, err := client.Receive(m.ctx, m.conn) + response, notices, err := client.ReceiveNotice(m.ctx, m.conn, m.watch) if err != nil { return errorMsg{err: err, conn: m.conn} } - return socketMsg{conn: m.conn, message: response} + return socketMsg{conn: m.conn, message: response, notices: notices} } } @@ -305,6 +317,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.conn.CloseNow() } m.conn = msg.conn + m.watch = msg.watch m.reconnecting = false m.status = m.url if endpoint, err := url.Parse(m.url); err == nil { @@ -325,6 +338,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if msg.conn != m.conn { return m, nil } + // Surface the once-only identity/unrecognized-field notices on the same + // connection without corrupting the TUI layout. + m.appendNotices(msg.notices) return m.Update(receivedMsg(msg.message)) case receivedMsg: if msg.Type == protocol.Status && msg.ID == m.statusRequest { @@ -460,6 +476,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } return m, m.read() case draftValidationMsg: + m.appendNotices(msg.notices) if len(m.draftItems) > 0 && m.draftItems[m.draftIndex].Path == msg.path { m.draftError = "Validation passed (structure only)." if msg.err != nil { @@ -582,6 +599,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.runForm != 0 { return m.updateRunForm(msg) } + if m.decisionOpen { + return m.updateDecision(msg) + } if m.runOpen && (msg.String() != ":" || m.runSearchOpen) { return m.updateRuns(msg) } @@ -610,11 +630,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.commandIndex = 0 m.commandInput = newInput() if m.searchOpen { - m.commandInput.Placeholder = "Search pipelines…" - } else { - m.commandInput.Placeholder = ":logs" - m.commandInput.SetValue(":") + m.commandInput.Placeholder = "Type to search…" + return m, m.commandInput.Focus() } + m.commandInput.Placeholder = ":logs" + m.commandInput.SetValue(":") return m, m.commandInput.Focus() case m.homePage() && key.Matches(msg, m.keys.create): if m.conn == nil { @@ -784,6 +804,9 @@ func (m Model) View() string { if m.actionConfirm != nil { content = m.actionConfirmView(bodyHeight) } + if m.decisionOpen { + content = m.decisionView(bodyHeight) + } if m.mutationCommand != nil { paragraphs := []string{"This opens a new session/editor and may modify a retained draft.", "Published definitions and previous run history are unchanged."} if strings.Contains(m.mutationTitle, "debugging") { diff --git a/internal/tui/model_test.go b/internal/tui/model_test.go index 08772c17..fd456832 100644 --- a/internal/tui/model_test.go +++ b/internal/tui/model_test.go @@ -87,7 +87,7 @@ func TestLayoutResizes(t *testing.T) { if !strings.HasPrefix(lines[0], "Pipelines ") || !strings.HasSuffix(lines[0], "127.0.0.1:8080") || lipgloss.Width(lines[0]) != size.Width { t.Fatalf("invalid header: %q", lines[0]) } - if !strings.HasPrefix(lines[len(lines)-1], "/ search") || !strings.Contains(lines[len(lines)-1], ": commands") || !strings.Contains(lines[len(lines)-1], "● 20 NEW") { + if !strings.HasPrefix(lines[len(lines)-1], "/ omni search") || !strings.Contains(lines[len(lines)-1], ": commands") || !strings.Contains(lines[len(lines)-1], "● 20 NEW") { t.Fatalf("invalid footer: %q", lines[len(lines)-1]) } if strings.TrimSpace(lines[len(lines)-2]) != "" { diff --git a/internal/tui/notices.go b/internal/tui/notices.go new file mode 100644 index 00000000..f3c7e341 --- /dev/null +++ b/internal/tui/notices.go @@ -0,0 +1,44 @@ +package tui + +import ( + "sync" + + "git.a-wan.net/alan/pipelines/internal/buildinfo" +) + +// noticeSink collects build/protocol notices from a short-lived client so a TUI +// command can surface them through the shared notice path instead of dropping +// them. It implements client.Reporter. +type noticeSink struct { + mu sync.Mutex + notices []string +} + +func (s *noticeSink) report(relationship buildinfo.Relationship) { + if relationship.Message == "" { + return + } + s.mu.Lock() + s.notices = append(s.notices, relationship.Message) + s.mu.Unlock() +} + +// drain returns the notices collected so far and resets the sink. +func (s *noticeSink) drain() []string { + s.mu.Lock() + defer s.mu.Unlock() + notices := s.notices + s.notices = nil + return notices +} + +// appendNotices is the single TUI notice path: every server relationship or +// unrecognized-field notice is rendered as one warning line, whether it came +// from the long-lived read loop or a short-lived command client. +func (m *Model) appendNotices(notices []string) { + for _, notice := range notices { + if notice != "" { + m.appendLine("warning: " + notice) + } + } +} diff --git a/internal/tui/results.go b/internal/tui/results.go index 1cc7bdf7..a4c1b610 100644 --- a/internal/tui/results.go +++ b/internal/tui/results.go @@ -3,6 +3,7 @@ package tui import ( "fmt" "maps" + "strings" "git.a-wan.net/alan/pipelines/internal/protocol" "github.com/charmbracelet/lipgloss" @@ -23,6 +24,12 @@ func resultLabel(r protocol.RunSummary) string { if preview != "" { return "Latest output: " + preview } + if r.Status == protocol.RunStatusWaiting { + if r.CurrentStage != "" { + return "Waiting for a person · stage " + r.CurrentStage + } + return "Waiting for a person" + } if r.Status == "running" || r.Status == "queued" { return "In progress · awaiting stage output" } @@ -48,7 +55,7 @@ func (m Model) pipelineResultLines() []string { if r == nil { return []string{"Results · This version has not run yet. No accomplishments recorded."} } - lines := []string{fmt.Sprintf("Results · run #%d · %s · %d completed visits · %s", r.ID, ansi.Strip(m.progress(r.Status)), r.CompletedSteps, runDuration(r.CreatedAt, r.FinishedAt)), resultLabel(*r)} + lines := []string{fmt.Sprintf("Results · run #%d · %s · %s · %d completed visits · %s", r.ID, r.Label(), ansi.Strip(m.progress(r.Status)), r.CompletedSteps, runDuration(r.CreatedAt, r.FinishedAt)), resultLabel(*r)} if r.Status != "succeeded" && r.ResultPreview != "" && r.Diagnostic != "" { lines = append(lines, "Partial output: "+ansi.Strip(r.ResultPreview)) } @@ -60,6 +67,7 @@ func runResultLines(r *protocol.RunDetail) []string { if r.Diagnostic != "" { lines = append(lines, "Stopped: "+ansi.Strip(r.Diagnostic)) } + lines = append(lines, waitingLines(r)...) if r.Status == "succeeded" { if preview := protocol.OutputPreview(r.Output); preview != "" { lines = append(lines, "Result: "+ansi.Strip(preview)) @@ -96,6 +104,26 @@ func runResultLines(r *protocol.RunDetail) []string { return lines } +// waitingLines renders a run waiting on a human stage: the banner, the operator +// instructions recorded with the wait, and the selectable options, so the choice +// is visible without opening the stage view. +func waitingLines(r *protocol.RunDetail) []string { + if r.Status != protocol.RunStatusWaiting { + return nil + } + lines := []string{"⏸ Waiting for a person · stage " + r.CurrentStage} + if step, ok := lastWaitingStep(r); ok { + if prompt := strings.TrimSpace(protocol.WaitingPrompt(step.Output)); prompt != "" { + lines = append(lines, strings.Split(ansi.Strip(prompt), "\n")...) + } + if options := protocol.WaitingOptions(step.Output); len(options) > 0 { + lines = append(lines, "Options: "+strings.Join(options, ", ")) + } + lines = append(lines, fmt.Sprintf("Decide: pipelines decide %d --option KEY [--feedback TEXT]", r.ID)) + } + return lines +} + func completedWorkLines(r *protocol.RunDetail) []string { var lines []string for _, s := range r.Steps { @@ -117,6 +145,9 @@ func completedWorkLines(r *protocol.RunDetail) []string { } func runOutputDocument(r *protocol.RunDetail, width int) []string { + if r.Status == protocol.RunStatusWaiting { + return waitingLines(r) + } var notice []string if r.Diagnostic != "" { notice = append(notice, lipgloss.NewStyle().Foreground(themeError).Render("Stopped: "+ansi.Strip(r.Diagnostic)), "") diff --git a/internal/tui/run_detail.go b/internal/tui/run_detail.go index 103bf141..e82aded7 100644 --- a/internal/tui/run_detail.go +++ b/internal/tui/run_detail.go @@ -101,6 +101,7 @@ func (m *Model) closeRuns() { m.runGraphFocus = false m.runGraphTop = 0 m.runGraphPan = 0 + m.closeDecision() } func (m Model) visibleRuns() []protocol.RunSummary { @@ -126,7 +127,7 @@ func (m Model) visibleRuns() []protocol.RunSummary { } labels := make([]string, len(runs)) for i, run := range runs { - labels[i] = fmt.Sprintf("#%d %s v%d %s %s %s %s", run.ID, run.Name, run.Version, run.Status, run.Outcome, run.CurrentStage, run.Diagnostic) + labels[i] = fmt.Sprintf("#%d %s v%d %s %s %s %s", run.ID, run.Label(), run.Version, run.Status, run.Outcome, run.CurrentStage, run.Diagnostic) } matched := make([]protocol.RunSummary, 0) for _, match := range fuzzy.Find(query, labels) { @@ -144,6 +145,48 @@ func (m *Model) selectRunStep(index int) { } } +// Run-detail section identity is defined once here and shared by rendering and +// the search/navigation helpers, so the titles, shortcut markers and section +// indices cannot drift apart. +type runSection struct { + Title string + Shortcut string +} + +// runSectionNone is the "no section to focus" sentinel used by search navigation. +const runSectionNone = -1 + +// Run-detail section indices, in runSections order. Result and File changes +// default open; the rest default collapsed. +const ( + runSectionProgress = iota + runSectionInput + runSectionResult + runSectionEvidence + runSectionDetails + runSectionFiles + runSectionCount +) + +var runSections = []runSection{ + {"Progress", "s"}, + {"Task & input", "i"}, + {"Result", "o"}, + {"Evidence", "t"}, + {"Execution details", "m"}, + {"File changes", "d"}, +} + +// runSectionForShortcut maps a section shortcut key to its index. +func runSectionForShortcut(key string) (int, bool) { + for i, section := range runSections { + if section.Shortcut == key { + return i, true + } + } + return runSectionNone, false +} + func (m Model) runSectionKey(index int) string { sequence := 0 if m.runDetail != nil && m.runStepIndex > 0 && m.runStepIndex <= len(m.runDetail.Steps) { @@ -156,7 +199,7 @@ func (m Model) runSectionClosed(index int) bool { if closed, ok := m.runCollapsed[m.runSectionKey(index)]; ok { return closed } - return index != 2 && index != 5 + return index != runSectionResult && index != runSectionFiles } func (m *Model) toggleRunSection(index int) { @@ -208,8 +251,8 @@ func (m Model) openOpenCodeEvidence() (tea.Model, tea.Cmd) { if m.runCollapsed == nil { m.runCollapsed = map[string]bool{} } - for section := 0; section < 5; section++ { - m.runCollapsed[m.runSectionKey(section)] = section != 3 + for section := 0; section < runSectionFiles; section++ { + m.runCollapsed[m.runSectionKey(section)] = section != runSectionEvidence } return m, nil } @@ -223,6 +266,8 @@ func runStatus(status string) string { color = themeError case "running", "queued": color = themeAccent + case protocol.RunStatusWaiting: + color = themeAccent } return lipgloss.NewStyle().Foreground(color).Render(status) } @@ -242,6 +287,36 @@ func runDuration(start, end string) string { return max(time.Duration(0), last.Sub(first)).Round(time.Second).String() } +// stageVerdictLines renders a completed stage visit's derived verdict for the +// stage view: one line naming the chosen option and its concise reason, and a +// second naming the recorded artifacts the reason refers to. It returns nil for a +// nil verdict, so the view gains nothing rather than an empty heading, and it +// always states the option even when the reason is absent, so the derived choice +// is never hidden. +func stageVerdictLines(verdict *protocol.StageVerdict) []string { + if verdict == nil { + return nil + } + option := strings.TrimSpace(verdict.Option) + reason := strings.TrimSpace(verdict.Reason) + line := "Verdict:" + switch { + case option != "" && reason != "": + line += " " + option + " · " + reason + case option != "": + line += " " + option + case reason != "": + line += " " + reason + default: + return nil + } + lines := []string{line} + if len(verdict.Artifacts) > 0 { + lines = append(lines, "Referenced artifacts: "+strings.Join(verdict.Artifacts, ", ")) + } + return lines +} + func valueLines(values map[string]any) []string { if len(values) == 0 { return []string{"No data yet."} @@ -400,8 +475,10 @@ func (m Model) runSectionLines(width int) []string { return nil } r := m.runDetail - titles := []string{"Progress", "Task & input", "Result", "Evidence", "Execution details", "File changes"} - shortcuts := []string{"s", "i", "o", "t", "m", "d"} + titles := make([]string, len(runSections)) + for i, section := range runSections { + titles[i] = section.Title + } summary := append(runResultLines(r), "", strings.Join(completedWorkLines(r), "\n")) if m.runError != "" { summary = append(summary, "Request error: "+m.runError) @@ -411,36 +488,44 @@ func (m Model) runSectionLines(width int) []string { editScope = strings.Join(r.WritePaths, ", ") } var output, input []string - if !m.runSectionClosed(2) { + if !m.runSectionClosed(runSectionResult) { output = runOutputDocument(r, max(1, width-2)) } - if !m.runSectionClosed(1) { + if !m.runSectionClosed(runSectionInput) { input = resultDocument(r.Input, max(1, width-2)) } content := [][]string{summary, input, output, {"Choose a stage with n/p to inspect its retained evidence."}, {"Started: " + dateLabel(r.CreatedAt), "Finished: " + dateLabel(r.FinishedAt), "Duration: " + runDuration(r.CreatedAt, r.FinishedAt), "Workspace: " + r.Workspace, "Source hash: " + r.ContentHash, "Stage tools: defined by the pinned pipeline version", "Edit scope: " + editScope}} if r.RetryOf > 0 { - content[4] = append(content[4], fmt.Sprintf("Retry of run #%d", r.RetryOf)) + content[runSectionDetails] = append(content[runSectionDetails], fmt.Sprintf("Retry of run #%d", r.RetryOf)) } content = append(content, []string{"Select a recorded stage visit with n/p to inspect its retained file diff."}) if m.runStepIndex > 0 && m.runStepIndex <= len(r.Steps) { step := r.Steps[m.runStepIndex-1] - titles[0] = "Stage progress" + titles[runSectionProgress] = "Stage progress" summary = []string{m.progress(m.stepProgressStatus(step)) + " · " + runDuration(step.StartedAt, step.FinishedAt), "Route: " + outcomeLabel(step.Outcome, step.Outcome) + " → " + step.Target} var stageOutput, stageInput, evidence []string - if !m.runSectionClosed(2) { + if !m.runSectionClosed(runSectionResult) { stageOutput = resultDocument(step.Output, max(1, width-2)) } - if !m.runSectionClosed(1) { + if !m.runSectionClosed(runSectionInput) { stageInput = resultDocument(step.Input, max(1, width-2)) } - if !m.runSectionClosed(3) { + if !m.runSectionClosed(runSectionEvidence) { evidence = evidenceLines(step) } stageState := m.progress(m.stepProgressStatus(step)) if step.Outcome != "" && step.Target != "" { stageState += " · " + outcomeLabel(step.Outcome, step.Outcome) + " → " + step.Target } - stageOutput = append([]string{stageState, ""}, stageOutput...) + // The verdict leads the stage's result: it states the chosen option and its + // concise reason and names the recorded artifacts the reason refers to, so + // the derived choice is at the top of the stage view, complementing the + // state and output below it without adding a section. + head := []string{stageState, ""} + if verdict := stageVerdictLines(step.Verdict); len(verdict) > 0 { + head = append(head, verdict...) + } + stageOutput = append(head, stageOutput...) if step.Status == "running" { stageOutput = append([]string{m.loading("Working on " + step.Stage + " · result pending"), ""}, stageOutput...) } @@ -449,19 +534,19 @@ func (m Model) runSectionLines(width int) []string { } content = [][]string{summary, stageInput, stageOutput, evidence, {"Started: " + dateLabel(step.StartedAt), "Finished: " + dateLabel(step.FinishedAt), "Duration: " + runDuration(step.StartedAt, step.FinishedAt), "Session: " + step.SessionID, fmt.Sprintf("Agent active: %t", step.AgentActive), fmt.Sprintf("Step: %d", step.Sequence)}} if step.Control != nil { - content[4] = append(content[4], fmt.Sprintf("Runner visit: %d / %d", step.Control.Visit, step.Control.MaxVisits)) + content[runSectionDetails] = append(content[runSectionDetails], fmt.Sprintf("Runner visit: %d / %d", step.Control.Visit, step.Control.MaxVisits)) if step.Control.LimitReached { - content[4] = append(content[4], "Runtime limit stopped route: "+step.Control.ModelTarget) + content[runSectionDetails] = append(content[runSectionDetails], "Runtime limit stopped route: "+step.Control.ModelTarget) } for alias, read := range step.Control.Memory { - content[4] = append(content[4], fmt.Sprintf("Shared memory %s ← %s (visit sequence %d)", alias, read.Source, read.Sequence)) + content[runSectionDetails] = append(content[runSectionDetails], fmt.Sprintf("Shared memory %s ← %s (visit sequence %d)", alias, read.Source, read.Sequence)) } } - if !m.runSectionClosed(2) { - content[2] = append(content[2], "", fileChangesSummary(step), artifactsSummary(step)) + if !m.runSectionClosed(runSectionResult) { + content[runSectionResult] = append(content[runSectionResult], "", fileChangesSummary(step), artifactsSummary(step)) } var diff []string - if !m.runSectionClosed(5) { + if !m.runSectionClosed(runSectionFiles) { diff = append(stageDiffLines(step), artifactLines(step)...) } content = append(content, diff) @@ -470,26 +555,26 @@ func (m Model) runSectionLines(width int) []string { if receipt.Filename != "" { line += " · " + receipt.Filename } - content[4] = append(content[4], line) + content[runSectionDetails] = append(content[runSectionDetails], line) if receipt.MessageID != "" { - content[4] = append(content[4], "Message ID: "+receipt.MessageID) + content[runSectionDetails] = append(content[runSectionDetails], "Message ID: "+receipt.MessageID) } if receipt.AttachmentURL != "" { - content[4] = append(content[4], "Attachment: "+receipt.AttachmentURL) + content[runSectionDetails] = append(content[runSectionDetails], "Attachment: "+receipt.AttachmentURL) } if receipt.Diagnostic != "" { - content[4] = append(content[4], "Notification diagnostic: "+receipt.Diagnostic) + content[runSectionDetails] = append(content[runSectionDetails], "Notification diagnostic: "+receipt.Diagnostic) } } } var lines []string - for _, i := range []int{2, 5, 0, 1, 3, 4} { + for _, i := range []int{runSectionResult, runSectionFiles, runSectionProgress, runSectionInput, runSectionEvidence, runSectionDetails} { title := titles[i] marker := "▾" if m.runSectionClosed(i) { marker = "▸" } - lines = append(lines, bar(fmt.Sprintf("[%s] %s %s", shortcuts[i], marker, title), "", width, false)) + lines = append(lines, bar(fmt.Sprintf("[%s] %s %s", runSections[i].Shortcut, marker, title), "", width, false)) if !m.runSectionClosed(i) { for _, line := range content[i] { for _, wrapped := range strings.Split(ansi.Wrap(line, max(1, width-2), ""), "\n") { @@ -508,7 +593,7 @@ func (m Model) runSectionLines(width int) []string { // The section containing the top visible detail row is the scroll focus. func runFocusedSection(lines []string, top int) (int, string) { - row, title := 0, "Result" + row, title := 0, runSections[runSectionResult].Title for i, line := range lines { plain := ansi.Strip(line) if i > top { @@ -558,6 +643,9 @@ func (m Model) runActions() string { if m.runDetail != nil { text += " · a evidence" } + if m.runDetail != nil && m.runDetail.Status == protocol.RunStatusWaiting { + text += " · c decide" + } if m.selectedFailedRun() > 0 { text += " · r retry failed" } @@ -589,7 +677,7 @@ func (m Model) runsDetailsView(height int) string { start, end := selectionWindow(len(runs), m.runIndex, max(1, (height-4-len(rows))/2)) for i := start; i < end; i++ { r := runs[i] - text := fmt.Sprintf("#%d %s · v%d · %s · %s", r.ID, r.Name, r.Version, m.progress(r.Status), dateLabel(r.FinishedAt)) + text := fmt.Sprintf("#%d %s · v%d · %s · %s", r.ID, r.Label(), r.Version, m.progress(r.Status), dateLabel(r.FinishedAt)) rows = append(rows, menuOption(text, i == m.runIndex)) rows = append(rows, " "+ansi.Truncate(resultLabel(r), max(1, m.width-6), "…")) } @@ -612,7 +700,7 @@ func (m Model) runsDetailsView(height int) string { return panel(m.width, height, []string{bar(title, fmt.Sprint(len(runs)), max(1, m.width-4), true)}, rows, footer, true) } r := m.runDetail - header := bar(fmt.Sprintf("#%d %s · v%d", r.ID, r.Name, r.Version), m.progress(r.Status)+" · "+runDuration(r.CreatedAt, r.FinishedAt), m.width, false) + header := bar(fmt.Sprintf("#%d %s · v%d", r.ID, r.Label(), r.Version), m.progress(r.Status)+" · "+runDuration(r.CreatedAt, r.FinishedAt), m.width, false) if height <= 6 { return fitBlock([]string{header, runHighlight(m.runSelectionLabel(), m.width), m.runActions() + " · Tab pane · Esc back"}, m.width, height) } @@ -636,7 +724,11 @@ func (m Model) runsDetailsView(height int) string { lines := m.runSectionLines(m.runDetailWidth()) page := max(0, innerHeight-5) top := max(0, min(m.runTop, max(0, len(lines)-page))) - footer := bar("o result · d diff · s progress · i input · t evidence · m details", fmt.Sprintf("%d–%d / %d", min(top+1, len(lines)), min(top+page, len(lines)), len(lines)), max(1, m.width-4), false) + footerHint := "o result · d diff · s progress · i input · t evidence · m details" + if r.Status == protocol.RunStatusWaiting { + footerHint += " · c decide" + } + footer := bar(footerHint, fmt.Sprintf("%d–%d / %d", min(top+1, len(lines)), min(top+page, len(lines)), len(lines)), max(1, m.width-4), false) label := m.runSelectionLabel() if m.runStepIndex > 0 && m.runStepIndex <= len(r.Steps) { step := r.Steps[m.runStepIndex-1] diff --git a/internal/tui/run_progress.go b/internal/tui/run_progress.go index 9179d01b..79d9e61e 100644 --- a/internal/tui/run_progress.go +++ b/internal/tui/run_progress.go @@ -27,6 +27,9 @@ func (m Model) progress(status string) string { color = themeError case "canceled": marker = "−" + case protocol.RunStatusWaiting: + marker = "⏸" + color = themeAccent } return lipgloss.NewStyle().Foreground(color).Render(marker + " " + status) } diff --git a/internal/tui/runs.go b/internal/tui/runs.go index f61ad639..c6fb1ebe 100644 --- a/internal/tui/runs.go +++ b/internal/tui/runs.go @@ -147,7 +147,7 @@ func (m *Model) startSelectedRun() tea.Cmd { m.runCollapsed = nil m.runDetail = nil m.runTop = 0 - request := protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace} + request := protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Title: m.cliOptions.Title, Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace} updated, cmd := m.runRequest(request) *m = updated.(Model) return cmd @@ -282,6 +282,9 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) { if m.runGraphFocus { switch msg.String() { case "c": + if m.runDetail != nil && m.runDetail.Status == protocol.RunStatusWaiting { + return m.openDecision() + } m.runGraphTop, m.runGraphPan = m.runGraphFollow() return m, nil case "j", "down": @@ -418,6 +421,10 @@ func (m Model) updateRuns(msg tea.KeyMsg) (tea.Model, tea.Cmd) { if m.runDetail != nil { return m.runRequest(protocol.Message{Type: protocol.CancelRun, RunID: m.runDetail.ID}) } + case "c": + if m.runDetail != nil && m.runDetail.Status == protocol.RunStatusWaiting { + return m.openDecision() + } } if m.runDetail != nil { m.runTop = max(0, min(m.runTop, max(0, len(m.runSectionLines(m.runDetailWidth()))-m.runPageSize()))) diff --git a/internal/tui/runs_test.go b/internal/tui/runs_test.go index 3cf0b7ec..2c47f7f8 100644 --- a/internal/tui/runs_test.go +++ b/internal/tui/runs_test.go @@ -43,6 +43,24 @@ func TestRunFormAndInspection(t *testing.T) { } } +func TestRunTitleIsShownToOperator(t *testing.T) { + titled := protocol.RunSummary{ID: 1, Name: "bug fix", Version: 2, Title: "Fix the flaky login test", Status: "succeeded"} + if got := titled.Label(); got != "Fix the flaky login test" { + t.Fatalf("Label = %q, want the generated title", got) + } + if got := (protocol.RunSummary{Name: "bug fix"}).Label(); got != "bug fix" { + t.Fatalf("Label without a title = %q, want the pipeline name fallback", got) + } + m := New(context.Background(), "") + m.width = 100 + m.height = 28 + m.runOpen = true + m.runDetail = &protocol.RunDetail{RunSummary: titled} + if view := ansi.Strip(m.runsDetailsView(24)); !strings.Contains(view, "Fix the flaky login test") { + t.Fatalf("run detail header omitted the title:\n%s", view) + } +} + func runInspectionModel() Model { m := New(context.Background(), "") m.width = 100 @@ -84,7 +102,7 @@ func TestRunVisitSelectorSectionsAndScrolling(t *testing.T) { t.Fatal("unselected or collapsed data leaked into details") } m = runKey(m, "i") - if m.runSectionClosed(1) { + if m.runSectionClosed(runSectionInput) { t.Fatal("input section did not expand") } m = runKey(m, "pgdown") @@ -101,11 +119,11 @@ func TestRunVisitSelectorSectionsAndScrolling(t *testing.T) { t.Fatal("Home did not reach top") } m = runKey(m, "n") - if m.runStepIndex != 2 || !m.runSectionClosed(1) { + if m.runStepIndex != 2 || !m.runSectionClosed(runSectionInput) { t.Fatal("attempt state not independent") } m = runKey(m, "p") - if m.runSectionClosed(1) { + if m.runSectionClosed(runSectionInput) { t.Fatal("expansion not retained when revisiting attempt") } } @@ -196,7 +214,7 @@ func TestRunSectionsOrderTitleAndNumberSelection(t *testing.T) { if strings.Index(text, "Result") > strings.Index(text, "Task & input") { t.Fatal("output must precede input") } - if m.runSectionClosed(2) || !m.runSectionClosed(1) { + if m.runSectionClosed(runSectionResult) || !m.runSectionClosed(runSectionInput) { t.Fatal("output should remain visible; input initially collapsed") } view := ansi.Strip(m.runsView(24)) @@ -226,3 +244,37 @@ func TestPipelineRunShortcutFiltersAndReturns(t *testing.T) { t.Fatal("closing runs didn't return to pipeline") } } + +// TestRunStepVerdictRenderedWhenPresent proves the rendered run detail states a +// completed visit's chosen option and its reason and names its referenced +// artifacts, that an absent reason still states the option, and that a step with a +// nil verdict shows no verdict line at all. +func TestRunStepVerdictRenderedWhenPresent(t *testing.T) { + m := runInspectionModel() + m.runDetail.Steps[0].Verdict = &protocol.StageVerdict{ + Option: "success → verifier", + Reason: "Tests passed and the evidence is retained", + ReasonSource: protocol.VerdictReasonModel, + Artifacts: []string{"captures/shot.png", "report.txt"}, + } + m.runStepIndex = 1 + view := ansi.Strip(m.runsDetailsView(24)) + for _, want := range []string{ + "Verdict: success → verifier · Tests passed and the evidence is retained", + "Referenced artifacts: captures/shot.png, report.txt", + } { + if !strings.Contains(view, want) { + t.Fatalf("verdict detail missing %q:\n%s", want, view) + } + } + // An absent reason still states the chosen option rather than dropping it. + optionOnly := &protocol.StageVerdict{Option: "success → verifier", ReasonSource: protocol.VerdictReasonAbsent} + if got := ansi.Strip(strings.Join(stageVerdictLines(optionOnly), "\n")); got != "Verdict: success → verifier" { + t.Fatalf("option-only verdict = %q", got) + } + m.runDetail.Steps[0].Verdict = nil + view = ansi.Strip(m.runsDetailsView(24)) + if strings.Contains(view, "Verdict:") || strings.Contains(view, "Referenced artifacts:") { + t.Fatalf("nil verdict must show no verdict line:\n%s", view) + } +} diff --git a/internal/wstest/wstest.go b/internal/wstest/wstest.go new file mode 100644 index 00000000..3efdd60b --- /dev/null +++ b/internal/wstest/wstest.go @@ -0,0 +1,60 @@ +// Package wstest provides the small websocket echo server shared by the client +// and CLI identity tests, so the request/reply harness is defined once. +package wstest + +import ( + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/coder/websocket" + "github.com/coder/websocket/wsjson" + + "git.a-wan.net/alan/pipelines/internal/protocol" +) + +// Server starts a websocket endpoint that answers every request with +// reply(request), echoing the request ID, and returns the client URL. +func Server(t testing.TB, reply func(protocol.Message) protocol.Message) string { + t.Helper() + return serve(t, func(request protocol.Message) any { + response := reply(request) + response.ID = request.ID + return response + }) +} + +// Raw starts a websocket endpoint that answers every request with a JSON object +// from payload(request), with "id" set to the request ID, so tests can include +// top-level keys the client does not model. +func Raw(t testing.TB, payload func(protocol.Message) map[string]any) string { + t.Helper() + return serve(t, func(request protocol.Message) any { + body := payload(request) + body["id"] = request.ID + return body + }) +} + +func serve(t testing.TB, reply func(protocol.Message) any) string { + t.Helper() + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + conn, err := websocket.Accept(w, r, nil) + if err != nil { + return + } + defer conn.CloseNow() + for { + var request protocol.Message + if err := wsjson.Read(r.Context(), conn, &request); err != nil { + return + } + if err := wsjson.Write(r.Context(), conn, reply(request)); err != nil { + return + } + } + })) + t.Cleanup(srv.Close) + return "ws" + strings.TrimPrefix(srv.URL, "http") + "/connect" +} diff --git a/merge-queue b/merge-queue new file mode 100644 index 00000000..0aa41416 --- /dev/null +++ b/merge-queue @@ -0,0 +1,2 @@ +lane-go +lane-app2 diff --git a/scripts/setup-native.py b/scripts/setup-native.py index 2bba4407..46cb9d21 100644 --- a/scripts/setup-native.py +++ b/scripts/setup-native.py @@ -203,6 +203,61 @@ class Setup: if result.returncode: raise ValueError(f"go build failed for ./cmd/{command}; the native install is incomplete") + # --- stale-CLI-on-PATH guard ----------------------------------------- + + def check_path_shadow(self, prefix): + """Warn when a different ``pipelines`` earlier on PATH shadows this install. + + Detection is read-only and bounded: one ``shutil.which`` check plus one + bounded ``version --json`` read per binary. The installer never modifies, + moves, deletes or upgrades the other binary; it only names the shadowing + path and both versions so an older CLI is not used silently in front of + the freshly built server. Naming both versions requires reading each + binary once, so a detected shadow costs exactly two short, read-only + subprocesses (none when the prefix binary is the one PATH already + resolves). Returns the shadowing path, or None when the prefix binary is + the one PATH resolves. + """ + installed = prefix / "bin/pipelines" + found = shutil.which("pipelines") + if not found: + return None + found_path = Path(found).resolve() + try: + if found_path == installed.resolve(): + return None + except OSError: + pass + other = self._binary_version(found_path) + current = self._binary_version(installed) + print( + f"WARNING: a different pipelines resolves earlier on PATH than the freshly " + f"installed CLI: {found_path} (version {other}) shadows {installed} " + f"(version {current}); the installer left it untouched. Put {prefix / 'bin'} " + "first on PATH so the CLI matches the running server.") + return found_path + + def _binary_version(self, path): + """Read a binary's ``version --json`` once; never a hot path.""" + if not Path(path).is_file(): + return "unknown" + try: + result = self.runner([str(path), "version", "--json"], capture_output=True, text=True) + except OSError: + return "unknown" + if result.returncode: + return "unknown" + text = (result.stdout or "").strip() + try: + data = json.loads(text) + except ValueError: + return text or "unknown" + if not isinstance(data, dict): + return "unknown" + version = data.get("version") or "unknown" + commit = data.get("commit") + return f"{version} (commit {commit})" if commit else str(version) + def install_skill(self, prefix): result = self.runner([str(prefix / "bin/pipelines"), "skill", "install"], cwd=str(self.directory)) if result.returncode: @@ -453,6 +508,7 @@ class Setup: else: resolution = self.resolve_ntfy() self.build(prefix) + self.check_path_shadow(prefix) self.install_skill(prefix) # The native install launches host harnesses, so write host profiles for # the detected harnesses and clear any Docker-era link. Uses only the diff --git a/scripts/test_setup_native.py b/scripts/test_setup_native.py index 06f9fbd4..eeca6091 100644 --- a/scripts/test_setup_native.py +++ b/scripts/test_setup_native.py @@ -1,6 +1,8 @@ import importlib.util +import io import json import os +from contextlib import redirect_stdout from pathlib import Path import subprocess import tempfile @@ -410,6 +412,94 @@ class SetupNativeTests(unittest.TestCase): self.assertTrue(installer._valid_model(saved["profiles"][name]["model"])) self.assertEqual(saved["profiles"]["opencode"]["executable"], "/usr/bin/opencode") + def _fake_pipelines(self, path, version, commit): + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(f'#!/bin/sh\necho \'{{"version":"{version}","commit":"{commit}"}}\'\n') + path.chmod(0o755) + return path + + def test_check_path_shadow_warns_naming_path_and_both_versions(self): + with tempfile.TemporaryDirectory() as directory: + directory = Path(directory) + prefix = directory / "prefix" + installed = self._fake_pipelines(prefix / "bin/pipelines", "new-version", "bbbb") + shadow_dir = directory / "earlier" + shadow = self._fake_pipelines(shadow_dir / "pipelines", "old-version", "aaaa") + before = shadow.read_bytes() + installer = setup_native.Setup(directory, prefix=prefix, runner=subprocess.run, + resolver=resolution, environ={}) + with patch.object(setup_native.shutil, "which", side_effect=lambda name: str(shadow) if name == "pipelines" else None): + output = io.StringIO() + with redirect_stdout(output): + result = installer.check_path_shadow(prefix) + warning = output.getvalue() + self.assertEqual(result, shadow.resolve()) + self.assertIn("WARNING", warning) + self.assertIn(str(shadow), warning) + self.assertIn("old-version", warning) + self.assertIn("new-version", warning) + # The shadowing binary is only read; it is never modified or replaced. + self.assertEqual(shadow.read_bytes(), before) + self.assertEqual(installed.read_bytes().count(b"new-version"), 1) + + def test_check_path_shadow_is_silent_when_prefix_binary_wins(self): + with tempfile.TemporaryDirectory() as directory: + directory = Path(directory) + prefix = directory / "prefix" + installed = self._fake_pipelines(prefix / "bin/pipelines", "same-version", "cccc") + installer = setup_native.Setup(directory, prefix=prefix, runner=subprocess.run, + resolver=resolution, environ={}) + with patch.object(setup_native.shutil, "which", return_value=str(installed)): + output = io.StringIO() + with redirect_stdout(output): + result = installer.check_path_shadow(prefix) + self.assertIsNone(result) + self.assertEqual(output.getvalue(), "") + + def test_check_path_shadow_is_silent_without_a_path_binary(self): + with tempfile.TemporaryDirectory() as directory: + installer = setup_native.Setup(directory, prefix=Path(directory) / "prefix", + runner=subprocess.run, resolver=resolution, environ={}) + with patch.object(setup_native.shutil, "which", return_value=None): + output = io.StringIO() + with redirect_stdout(output): + result = installer.check_path_shadow(Path(directory) / "prefix") + self.assertIsNone(result) + self.assertEqual(output.getvalue(), "") + + def test_check_path_shadow_reads_each_binary_at_most_once(self): + class VersionRunner: + def __init__(self): + self.commands = [] + + def __call__(self, command, **kwargs): + command = list(command) + self.commands.append(command) + version = "old-version" if "earlier" in command[0] else "new-version" + return subprocess.CompletedProcess(command, 0, + stdout=f'{{"version":"{version}","commit":"ab"}}', stderr="") + + with tempfile.TemporaryDirectory() as directory: + directory = Path(directory) + prefix = directory / "prefix" + installed = self._fake_pipelines(prefix / "bin/pipelines", "new-version", "bbbb") + shadow = self._fake_pipelines(directory / "earlier/pipelines", "old-version", "aaaa") + runner = VersionRunner() + installer = setup_native.Setup(directory, prefix=prefix, runner=runner, + resolver=resolution, environ={}) + with patch.object(setup_native.shutil, "which", return_value=str(shadow)): + output = io.StringIO() + with redirect_stdout(output): + installer.check_path_shadow(prefix) + # A detected shadow costs exactly one bounded, read-only `version` + # read per binary (the shadow and the freshly installed CLI) so both + # versions can be named; no other subprocess runs. + self.assertEqual(len(runner.commands), 2) + self.assertTrue(all(command[1:] == ["version", "--json"] for command in runner.commands)) + self.assertIn("old-version", output.getvalue()) + self.assertIn("new-version", output.getvalue()) + self.assertEqual(installed.read_bytes().count(b"new-version"), 1) + def test_full_run_migrates_docker_harness_config_to_host(self): with tempfile.TemporaryDirectory() as directory: recorder = Recorder() diff --git a/web/README.md b/web/README.md new file mode 100644 index 00000000..d82ea4c0 --- /dev/null +++ b/web/README.md @@ -0,0 +1,141 @@ +# Pipelines web spike (Route B) + +A throwaway, dependency-free browser client that proves the Pipelines +**WebSocket protocol works from a web page** end to end. It is a spike, not a +product: it renders a pipeline list and a run detail and nothing else. + +This directory is deliberately **separate from `android/`** and does not touch +it. The Android app remains the Kotlin/Compose client. + +## Why this route + +Two ways to expose the app as a web app were considered: + +- **Route A — Compose Multiplatform Web (WASM):** reuse the Kotlin protocol + layer and Compose UI. Most code reuse, but needs the Kotlin/WASM toolchain. +- **Route B — browser-native client (this spike):** a small JS app using the + browser's native `WebSocket`. No toolchain, browser-native behaviour, and it + can be verified against a live server immediately. + +This spike is Route B. The `android/` protocol models were the spec: the wire +format, server-URL rules and reply matching here mirror +`android/app/src/main/java/net/awan/pipelines/data/`. + +## Safety (unchanged from the Android client) + +- **Trusted LAN/VPN only.** The Pipelines API has **no authentication** and is + **not internet-safe**. Do not expose the server to untrusted networks. A web + page widens that surface: any tab can open the socket. +- **No secrets.** Nothing is stored except the server URL, in `localStorage`. +- **No hardcoded server.** The URL is entered by the user; there is no default + address baked in. + +## Layout + +| File | Android counterpart | Notes | +| --- | --- | --- | +| `src/protocol.js` | `data/protocol/Message.kt` (constants) | types + `#success`/`#failure` | +| `src/serverUrl.js` | `data/transport/ServerUrl.kt` | `validateServerUrl`, `resolveArtifactUrl` | +| `src/client.js` | `data/transport/PipelinesClient.kt` | one reused socket, id matching, backoff. DOM-free | +| `src/repository.js` | `data/PipelinesRepository.kt` | typed request builders | +| `src/app.js` | `ui/**` | DOM UI: pipeline list + run detail | +| `serve.mjs` | — | zero-dep static server | +| `test/*.test.mjs` | `app/src/test/**` | `node --test` | +| `test/smoke.mjs` | — | live end-to-end against a running server | + +`client.js` is DOM-free on purpose, so the smoke test drives the **same** +transport module the page uses. + +## Run it + +```sh +cd web +node serve.mjs # http://127.0.0.1:8090/ +node serve.mjs --host 0.0.0.0 # reachable from other devices (trusted LAN/VPN) +``` + +`serve.mjs` both serves the page and **proxies `/connect`** to the Pipelines +server (`--pipelines 127.0.0.1:8080` by default), so the page and the WebSocket +are one origin. The page defaults its URL field to `ws://<this page's host>/connect` +(the proxy) — just press **Connect**. Nothing is hardcoded: the default is derived +from wherever the page was loaded and can be overridden. + +### Why the page cannot connect directly (`403`) + +`internal/server/websocket.go` calls `websocket.Accept(w, r, nil)` — +`github.com/coder/websocket` — which **rejects an upgrade whose `Origin` host +does not match the request `Host`**. A browser page served from `:8090` opening +`ws://HOST:8080/connect` sends `Origin: http://HOST:8090` and is refused: + +``` +HTTP/1.1 403 Forbidden +request Origin "HOST:8090" is not authorized for Host "HOST:8080" +``` + +A Node or `curl` client sends no `Origin` and is accepted — which is why the +smoke test passes while a browser does not. The proxy sidesteps this by making +the page same-origin and dropping the `Origin` header on the way through (the +server has no authentication, so nothing is lost). Any web client that is served +from a different origin than the Pipelines server hits this same 403. + +To open the page from another device, bind `--host 0.0.0.0` and use this +machine's Tailscale/LAN address for the page only, e.g. +`http://100.85.25.33:8090/`, then press Connect (the field already holds +`ws://100.85.25.33:8090/connect`). Both hops are plaintext, so there is no +mixed-content block; only do this on a trusted tailnet/VPN. + +## Test it + +```sh +cd web +node --test test/ # unit tests, no server +PIPELINES_WS_URL=ws://127.0.0.1:8080/connect node test/smoke.mjs # live +``` + +`node --test` covers the ported URL validation/artifact resolution and the +transport (id matching, serialization order, error replies, timeouts, +not-connected guard, reconnect). `smoke.mjs` connects to a real server and runs +`ping`, `list_pipelines`, `list_runs`, `get_pipeline`, `get_run`, and (when the +newest run has artifacts) an artifact `HEAD`. + +## Verification status + +Run on macOS with Node v26.9.0 against a live `pipelines` server on +`ws://127.0.0.1:8080/connect`: + +- `node --test test/` → **20 tests, 0 failures.** +- `node test/smoke.mjs` → **SMOKE PASS (6 checks)**: websocket connected, + `ping -> pong`, `list_pipelines -> 14 pipelines`, `list_runs -> 189 runs`, + `get_pipeline #1`, `get_run #189`. No artifact fetch (that run had none). +- `node --check` parses every source and test file. +- `serve.mjs` serves `/`, `index.html`, `styles.css` and each `src/*.js` with the + right content type (200); `/favicon.ico` is 204; `/nope.js` is 404; with + `curl --path-as-is` no raw `..` path escapes `web/` (traversal attempts either + serve a file inside `web/` or 404). + +The cross-origin `403` and the proxy fix were verified on macOS against the live +server (`ws://100.85.25.33:8080/connect`): + +- Direct handshake with `Origin: http://100.85.25.33:8090` → `HTTP/1.1 403 + Forbidden` (`request Origin "100.85.25.33:8090" is not authorized for Host + "100.85.25.33:8080"`); the same handshake without `Origin` → `101 Switching + Protocols`. +- Through the proxy (`:8090`) with the same browser `Origin` → `101 Switching + Protocols`. +- `PIPELINES_WS_URL=ws://100.85.25.33:8090/connect node test/smoke.mjs` → + **SMOKE PASS (6 checks)** — a full request/reply session over the tunnel. + +**Not verified:** the rendered page itself. No desktop browser was connected to +this session, so the DOM UI was not opened, clicked or screenshotted. `app.js` +parses and its data path is exercised through the shared `client`/`repository`/ +`serverUrl` modules, but its rendering and event wiring are unproven. Also +unverified: `wss://`/TLS (no TLS server was available) and multiple concurrent +browser tabs. + +## Next step + +Before committing to a route, open `http://127.0.0.1:8090/` in a browser, connect +to the running server, and confirm the list/detail flow. If Route A is chosen +instead, the `data/`-layer mapping in the table above is the port checklist; the +Android-API friction lives in the artifact viewer, navigation, lifecycle and +`SharedPreferences` touchpoints (`android/README.md` documents them). diff --git a/web/index.html b/web/index.html new file mode 100644 index 00000000..06a9cae8 --- /dev/null +++ b/web/index.html @@ -0,0 +1,17 @@ +<!doctype html> +<html lang="en"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Pipelines — web spike + + + + + + + + diff --git a/web/package.json b/web/package.json new file mode 100644 index 00000000..e1131686 --- /dev/null +++ b/web/package.json @@ -0,0 +1,12 @@ +{ + "name": "pipelines-web-spike", + "version": "0.0.0", + "private": true, + "type": "module", + "description": "Throwaway browser-native spike proving the Pipelines WebSocket protocol works from a web client. No dependencies.", + "scripts": { + "serve": "node serve.mjs", + "test": "node --test test/", + "smoke": "node test/smoke.mjs" + } +} diff --git a/web/serve.mjs b/web/serve.mjs new file mode 100644 index 00000000..8911638d --- /dev/null +++ b/web/serve.mjs @@ -0,0 +1,126 @@ +// Zero-dependency static file server + WebSocket proxy for the spike. +// node serve.mjs [--port 8090] [--host 0.0.0.0] [--pipelines 127.0.0.1:8080] +// +// Serves this directory and proxies GET/Upgrade /connect to the Pipelines +// server, so the page and the WebSocket share one origin. +// +// Why the proxy exists: internal/server/websocket.go calls +// `websocket.Accept(w, r, nil)` (github.com/coder/websocket), which rejects an +// upgrade whose Origin host does not match the request Host — a browser would +// get 403 from a cross-origin page (a Node/curl client sends no Origin and is +// unaffected, which is why the smoke test passes). Proxying makes the page +// same-origin, and the Origin header is dropped on the way through because the +// server has no authentication and needs none. +// +// The default host is 127.0.0.1. Use --host 0.0.0.0 only on a trusted LAN/VPN. +import { createServer } from "node:http"; +import { readFile, stat } from "node:fs/promises"; +import { extname, join, normalize, resolve, sep } from "node:path"; +import { fileURLToPath } from "node:url"; +import net from "node:net"; + +const ROOT = resolve(fileURLToPath(new URL(".", import.meta.url))); + +const MIME = { + ".html": "text/html; charset=utf-8", + ".js": "text/javascript; charset=utf-8", + ".mjs": "text/javascript; charset=utf-8", + ".css": "text/css; charset=utf-8", + ".json": "application/json; charset=utf-8", + ".svg": "image/svg+xml", + ".png": "image/png", + ".ico": "image/x-icon", + ".map": "application/json; charset=utf-8", +}; + +function flag(argv, name, fallback) { + const i = argv.indexOf(name); + if (i !== -1 && argv[i + 1]) return argv[i + 1]; + return fallback; +} + +function parsePort(argv) { + return Number(flag(argv, "--port", process.env.PORT ?? 8090)); +} + +/** Resolve a request path to a file inside ROOT, or null if it escapes. */ +function resolvePath(urlPath) { + const decoded = decodeURIComponent(urlPath.split("?")[0]); + const rel = normalize(decoded).replace(/^([/\\])+/, ""); + const target = resolve(join(ROOT, rel || "index.html")); + if (target !== ROOT && !target.startsWith(ROOT + sep)) return null; + return target; +} + +const server = createServer(async (req, res) => { + const pathname = (req.url ?? "/").split("?")[0]; + if (pathname === "/favicon.ico") { + res.writeHead(204).end(); // no icon; keeps the console free of a 404 + return; + } + const target = resolvePath(req.url ?? "/"); + if (!target) { + res.writeHead(403).end("Forbidden"); + return; + } + try { + let path = target; + const info = await stat(path).catch(() => null); + if (info?.isDirectory()) path = join(path, "index.html"); + const body = await readFile(path); + res.writeHead(200, { + "Content-Type": MIME[extname(path)] ?? "application/octet-stream", + "Cache-Control": "no-store", + }); + res.end(body); + } catch { + res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" }).end("Not found"); + } +}); + +// --------------------------------------------------------------------------- +// WebSocket proxy for /connect +// --------------------------------------------------------------------------- + +const pipelinesTarget = flag( + process.argv, + "--pipelines", + process.env.PIPELINES_TARGET ?? "127.0.0.1:8080", +); +const targetPort = Number(pipelinesTarget.split(":").at(-1)); +const targetHost = pipelinesTarget.slice(0, pipelinesTarget.lastIndexOf(":")) || "127.0.0.1"; + +function proxyUpgrade(req, clientSocket, clientHead) { + const upstream = net.connect(targetPort, targetHost, () => { + const headers = { ...req.headers }; + delete headers.origin; // see the header comment: the server forbids a mismatched Origin + headers.host = `${targetHost}:${targetPort}`; + const block = Object.entries(headers) + .filter(([, v]) => v != null) + .map(([k, v]) => `${k}: ${Array.isArray(v) ? v.join(", ") : v}`) + .join("\r\n"); + upstream.write(`GET ${req.url} HTTP/1.1\r\n${block}\r\n\r\n`); + if (clientHead?.length) upstream.write(clientHead); + upstream.pipe(clientSocket); + clientSocket.pipe(upstream); + }); + upstream.on("error", () => clientSocket.destroy()); + clientSocket.on("error", () => upstream.destroy()); +} + +server.on("upgrade", (req, clientSocket, clientHead) => { + const pathname = (req.url ?? "").split("?")[0]; + if (pathname !== "/connect") { + clientSocket.destroy(); + return; + } + proxyUpgrade(req, clientSocket, clientHead); +}); + +const port = parsePort(process.argv); +const host = flag(process.argv, "--host", "127.0.0.1"); +server.listen(port, host, () => { + const shown = host === "0.0.0.0" ? "127.0.0.1" : host; + console.log(`web spike: http://${shown}:${port}/ (bound ${host}:${port})`); + console.log(`proxying /connect -> ws://${targetHost}:${targetPort}/connect`); +}); diff --git a/web/src/app.js b/web/src/app.js new file mode 100644 index 00000000..c047d53e --- /dev/null +++ b/web/src/app.js @@ -0,0 +1,522 @@ +// Spike web UI: pipeline list + run detail over the live WebSocket protocol. +// Deliberately small and DOM-only (no framework, no build step). Every value +// that came from the server is set with textContent, never innerHTML. +import { PipelinesClient } from "./client.js"; +import { PipelinesRepository } from "./repository.js"; +import { validateServerUrl, resolveArtifactUrl } from "./serverUrl.js"; + +const STORAGE_KEY = "pipelines.web.serverUrl.v2"; + +/** + * The page is normally served by serve.mjs, which also proxies /connect to the + * Pipelines server. Defaulting to this page's own origin therefore points at + * that proxy and keeps the page and the WebSocket same-origin — the server + * rejects a cross-origin upgrade with 403. Nothing is hardcoded: the value is + * derived from wherever the page was loaded, and the user can override it. + */ +function defaultServerUrl() { + if (typeof location === "undefined" || !location.host) return ""; + const scheme = location.protocol === "https:" ? "wss" : "ws"; + return `${scheme}://${location.host}/connect`; +} + +const client = new PipelinesClient(); +const repo = new PipelinesRepository(client); + +const state = { + view: "pipelines", + url: localStorage.getItem(STORAGE_KEY) ?? defaultServerUrl(), + connection: client.state, + pipelines: [], + runs: [], + usage: null, + pipelineDetail: null, + runDetail: null, + selectedPipelineId: null, + selectedRunId: null, + loading: false, + error: "", +}; + +let runPoll = null; + +// --------------------------------------------------------------------------- +// DOM helpers +// --------------------------------------------------------------------------- + +function h(tag, props = {}, ...children) { + const node = document.createElement(tag); + for (const [key, value] of Object.entries(props)) { + if (value == null || value === false) continue; + if (key === "class") node.className = value; + else if (key === "text") node.textContent = value; + else if (key.startsWith("on") && typeof value === "function") { + node.addEventListener(key.slice(2).toLowerCase(), value); + } else node.setAttribute(key, value === true ? "" : String(value)); + } + for (const child of children.flat()) { + if (child == null || child === false) continue; + node.append(child instanceof Node ? child : document.createTextNode(String(child))); + } + return node; +} + +function fmtSeconds(total) { + const s = Math.max(0, Math.round(total)); + const hh = Math.floor(s / 3600); + const mm = Math.floor((s % 3600) / 60); + const ss = s % 60; + if (hh > 0) return `${hh}h ${mm}m ${ss}s`; + if (mm > 0) return `${mm}m ${ss}s`; + return `${ss}s`; +} + +function fmtTime(iso) { + if (!iso) return "—"; + const ms = Date.parse(iso); + return Number.isNaN(ms) ? iso : new Date(ms).toLocaleString(); +} + +function fmtDuration(startIso, finishIso) { + if (!startIso) return "—"; + const start = Date.parse(startIso); + if (Number.isNaN(start)) return "—"; + const end = finishIso ? Date.parse(finishIso) : Date.now(); + if (Number.isNaN(end)) return "—"; + // A future start (clock skew) reads as 0s, matching the Android client. + return fmtSeconds(Math.max(0, (end - start) / 1000)); +} + +function statusClass(status) { + return `chip chip-${String(status || "unknown").toLowerCase()}`; +} + +function isExecuting(run) { + return Boolean(run && run.executing); +} + +// --------------------------------------------------------------------------- +// Rendering +// --------------------------------------------------------------------------- + +const header = h("header", { class: "topbar" }); +const content = h("main", { id: "content" }); +document.body.append(header, content); + +function renderHeader() { + header.replaceChildren( + h("div", { class: "brand" }, h("strong", { text: "Pipelines" }), h("span", { class: "muted", text: "web spike" })), + h( + "div", + { class: "connbar" }, + h("input", { + id: "url", + type: "text", + placeholder: "ws://HOST:PORT/connect", + value: state.url, + spellcheck: "false", + oninput: (e) => { + state.url = e.target.value; + }, + }), + h("button", { + id: "connectBtn", + text: state.connection.kind === "connected" ? "Disconnect" : "Connect", + onclick: onConnectClicked, + }), + h("span", { class: "state", id: "stateBadge" }, connectionLabel()), + ), + ); +} + +function connectionLabel() { + const c = state.connection; + switch (c.kind) { + case "connected": + return h("span", { class: "dot ok" }, "connected"); + case "connecting": + return h("span", { class: "dot warn" }, `connecting… (attempt ${c.attempt})`); + case "disconnected": + return h("span", { class: "dot bad" }, `disconnected${c.reason ? ` — ${c.reason}` : ""}${c.retrying ? " (retrying)" : ""}`); + default: + return h("span", { class: "dot idle" }, "idle"); + } +} + +function render() { + renderHeader(); + renderContent(); +} + +function renderContent() { + const nodes = []; + if (state.error) { + nodes.push(h("div", { class: "banner error" }, h("strong", { text: "Error: " }), state.error)); + } + nodes.push( + h( + "nav", + { class: "tabs" }, + tabButton("pipelines", `Pipelines (${state.pipelines.length})`), + tabButton("runs", `Runs (${state.runs.length})`), + h("span", { class: "spacer" }), + h("button", { class: "ghost", text: "Refresh", onclick: () => loadCurrentView(true) }), + ), + ); + + const split = h("div", { class: "split" }); + if (state.view === "pipelines") { + split.append(renderPipelineList(), renderPipelineDetail()); + } else { + split.append(renderRunList(), renderRunDetail()); + } + nodes.push(split); + content.replaceChildren(...nodes); +} + +function tabButton(view, label) { + return h("button", { + class: `tab${state.view === view ? " active" : ""}`, + text: label, + onclick: () => { + state.view = view; + state.error = ""; + renderContent(); + if (view === "runs" && !state.runs.length) loadCurrentView(); + if (view === "pipelines" && !state.pipelines.length) loadCurrentView(); + }, + }); +} + +function renderPipelineList() { + const list = h("div", { class: "list" }); + if (state.loading && !state.pipelines.length) { + list.append(h("div", { class: "muted pad", text: "Loading…" })); + return list; + } + if (!state.pipelines.length) { + list.append(h("div", { class: "muted pad", text: "No pipelines." })); + return list; + } + for (const p of state.pipelines) { + list.append( + h( + "button", + { + class: `row${state.selectedPipelineId === p.id ? " selected" : ""}`, + onclick: () => selectPipeline(p), + }, + h("span", { class: "row-title", text: p.name || `pipeline ${p.id}` }), + h("span", { class: "row-meta", text: `#${p.id} · v${p.version} · ${p.stages} stage${p.stages === 1 ? "" : "s"}` }), + ), + ); + } + return list; +} + +function renderPipelineDetail() { + const d = state.pipelineDetail; + const pane = h("div", { class: "detail" }); + if (!d) { + pane.append(h("div", { class: "muted pad", text: "Select a pipeline." })); + return pane; + } + pane.append( + h("h2", { text: d.name || `pipeline ${d.id}` }), + h( + "div", + { class: "kv" }, + kv("ID / version", `#${d.id} · v${d.version}`), + kv("Stages", String(d.stages ?? (d.graph?.stages?.length ?? 0))), + kv("Content hash", d.content_hash || "—"), + kv("Created", fmtTime(d.created_at)), + kv("Updated", fmtTime(d.updated_at)), + kv("Latest version", d.latest_version ? String(d.latest_version) : "—"), + ), + ); + const stages = d.graph?.stages ?? []; + if (stages.length) { + pane.append(h("h3", { text: "Stages" })); + const ul = h("ul", { class: "stages" }); + for (const s of stages) { + const outcomes = Object.keys(s.edges ?? {}).join(", "); + ul.append( + h( + "li", + {}, + h("code", { text: s.key }), + s.type ? h("span", { class: "chip", text: s.type }) : null, + outcomes ? h("span", { class: "muted", text: `→ ${outcomes}` }) : null, + ), + ); + } + pane.append(ul); + } + return pane; +} + +function renderRunList() { + const list = h("div", { class: "list" }); + if (state.usage) { + list.append( + h( + "div", + { class: "usage" }, + h("span", { text: `${state.usage.total} total` }), + h("span", { class: "ok", text: `${state.usage.succeeded} succeeded` }), + h("span", { class: "bad", text: `${state.usage.failed} failed` }), + h("span", { class: "warn", text: `${state.usage.active} active` }), + ), + ); + } + if (state.loading && !state.runs.length) { + list.append(h("div", { class: "muted pad", text: "Loading…" })); + return list; + } + if (!state.runs.length) { + list.append(h("div", { class: "muted pad", text: "No runs." })); + return list; + } + for (const r of state.runs) { + list.append( + h( + "button", + { + class: `row${state.selectedRunId === r.id ? " selected" : ""}`, + onclick: () => selectRun(r.id), + }, + h( + "span", + { class: "row-head" }, + h("span", { class: "row-title", text: r.title || r.name || `run ${r.id}` }), + h("span", { class: statusClass(r.status), text: r.status || "unknown" }), + ), + h( + "span", + { class: "row-meta" }, + `#${r.id} · ${fmtTime(r.created_at)} · `, + isExecuting(r) ? h("em", { text: fmtDuration(r.created_at, "") }) : fmtDuration(r.created_at, r.finished_at), + ), + r.diagnostic ? h("span", { class: "row-diag", text: r.diagnostic }) : null, + ), + ); + } + return list; +} + +function renderRunDetail() { + const d = state.runDetail; + const pane = h("div", { class: "detail" }); + if (!d) { + pane.append(h("div", { class: "muted pad", text: "Select a run." })); + return pane; + } + pane.append( + h( + "h2", + {}, + d.title || d.name || `run ${d.id}`, + h("span", { class: statusClass(d.status), text: d.status || "unknown" }), + ), + h( + "div", + { class: "kv" }, + kv("Run ID", `#${d.id}`), + kv("Pipeline", `#${d.pipeline_id} @ v${d.version}`), + kv("Outcome", d.outcome || "—"), + kv("Current stage", d.current_stage || "—"), + kv("Started", fmtTime(d.created_at)), + kv("Duration", isExecuting(d) ? `${fmtDuration(d.created_at, "")} (running)` : fmtDuration(d.created_at, d.finished_at)), + kv("Completed steps", String(d.completed_steps ?? 0)), + d.diagnostic ? kv("Diagnostic", d.diagnostic) : null, + ), + ); + + const steps = d.steps ?? []; + pane.append(h("h3", { text: `Steps (${steps.length})` })); + if (!steps.length) { + pane.append(h("div", { class: "muted pad", text: "No steps recorded yet." })); + return pane; + } + const list = h("div", { class: "steps" }); + for (const s of steps) { + list.append( + h( + "div", + { class: "step" }, + h( + "div", + { class: "step-head" }, + h("code", { text: `${s.sequence}. ${s.stage}` }), + h("span", { class: statusClass(s.status), text: s.status || "unknown" }), + s.outcome ? h("span", { class: "chip", text: s.outcome }) : null, + h("span", { class: "muted", text: fmtDuration(s.started_at, s.finished_at) }), + ), + h( + "div", + { class: "kv tight" }, + kv("Target", s.target || "—"), + kv("Visit", s.control ? `${s.control.visit}/${s.control.max_visits}` : "—"), + kv("Session", s.session_id || "—"), + s.diagnostic ? kv("Diagnostic", s.diagnostic) : null, + ), + renderArtifacts(s), + ), + ); + } + pane.append(list); + return pane; +} + +function renderArtifacts(step) { + const artifacts = step.artifacts ?? []; + if (!artifacts.length) return null; + const wrap = h("div", { class: "artifacts" }, h("span", { class: "muted", text: "Artifacts: " })); + for (const a of artifacts) { + const href = resolveArtifactUrl(state.url, a.url); + if (href) { + wrap.append(h("a", { href, target: "_blank", rel: "noreferrer", text: a.name || a.url })); + } else { + wrap.append(h("span", { class: "muted", text: `${a.name || a.url} (no server URL)` })); + } + } + return wrap; +} + +function kv(key, value) { + return h( + "div", + { class: "kv-row" }, + h("span", { class: "kv-key", text: key }), + h("span", { class: "kv-val", text: value }), + ); +} + +// --------------------------------------------------------------------------- +// Actions +// --------------------------------------------------------------------------- + +function setError(err) { + state.error = err instanceof Error ? err.message : String(err); + state.loading = false; + renderContent(); +} + +function onConnectClicked() { + if (state.connection.kind === "connected") { + repo.disconnect(); + stopRunPoll(); + return; + } + const validated = validateServerUrl(state.url); + if (!validated.valid) { + state.error = validated.message; + renderContent(); + return; + } + state.error = ""; + localStorage.setItem(STORAGE_KEY, state.url.trim()); + repo.connect(validated); + // The `state` listener kicks off the initial load once connected. +} + +async function onConnected() { + try { + await repo.ping(); + } catch (err) { + setError(err); + return; + } + await loadCurrentView(); +} + +async function loadCurrentView(force = false) { + if (state.connection.kind !== "connected") { + state.error = "Connect to the server first."; + renderContent(); + return; + } + state.loading = true; + state.error = ""; + renderContent(); + try { + if (state.view === "pipelines") { + state.pipelines = await repo.listPipelines(); + } else { + const { runs, usage } = await repo.listRuns(); + state.runs = runs; + state.usage = usage; + } + state.loading = false; + renderContent(); + // Keep the current selection fresh after a refresh. + if (force && state.view === "runs" && state.selectedRunId) { + await selectRun(state.selectedRunId, { silent: true }); + } + } catch (err) { + setError(err); + } +} + +async function selectPipeline(summary) { + state.selectedPipelineId = summary.id; + state.pipelineDetail = null; + renderContent(); + try { + state.pipelineDetail = await repo.getPipeline(summary.id, summary.version); + renderContent(); + } catch (err) { + setError(err); + } +} + +async function selectRun(id, { silent = false } = {}) { + state.selectedRunId = id; + if (!silent) { + state.runDetail = null; + renderContent(); + } + try { + state.runDetail = await repo.getRun(id); + renderContent(); + updateRunPoll(); + } catch (err) { + if (!silent) setError(err); + else stopRunPoll(); + } +} + +function updateRunPoll() { + stopRunPoll(); + if (state.view === "runs" && state.selectedRunId && isExecuting(state.runDetail)) { + runPoll = setInterval(() => selectRun(state.selectedRunId, { silent: true }), 1000); + } +} + +function stopRunPoll() { + if (runPoll) { + clearInterval(runPoll); + runPoll = null; + } +} + +// --------------------------------------------------------------------------- +// Boot +// --------------------------------------------------------------------------- + +client.addEventListener("state", (event) => { + const next = event.detail; + const wasConnected = state.connection.kind === "connected"; + const previousKind = state.connection.kind; + state.connection = next; + if (next.kind === "connected" && !wasConnected) { + onConnected(); + } + if (next.kind !== "connected" && previousKind === "connected") { + stopRunPoll(); + } + render(); +}); + +// Prefill from a previous session only; the user still confirms with Connect. +render(); diff --git a/web/src/client.js b/web/src/client.js new file mode 100644 index 00000000..0c9c6785 --- /dev/null +++ b/web/src/client.js @@ -0,0 +1,233 @@ +// A single, reused WebSocket connection to /connect, mirroring +// android/.../data/transport/PipelinesClient.kt: requests are serialized, each +// carries a client-generated stable id, replies are matched by id, and +// unsolicited envelopes are dropped. There is no authentication of any kind. +// +// DOM-free on purpose: the browser app and the Node smoke test share this exact +// module, so the smoke test exercises the real client, not a re-implementation. + +import { Protocol } from "./protocol.js"; + +/** A server `type:"error"` reply, surfaced with the server's own text. */ +export class ProtocolError extends Error { + constructor(message) { + super(message); + this.name = "ProtocolError"; + } +} + +/** No live WebSocket connection is available for the request. */ +export class NotConnectedError extends Error { + constructor(message = "Not connected to the Pipelines server") { + super(message); + this.name = "NotConnectedError"; + } +} + +const IDLE = "idle"; +const CONNECTING = "connecting"; +const CONNECTED = "connected"; +const DISCONNECTED = "disconnected"; +const NORMAL_CLOSURE = 1000; + +export class PipelinesClient extends EventTarget { + #WebSocketImpl; + #backoffBaseMs; + #backoffMaxMs; + #requestTimeoutMs; + #random; + + #ws = null; + #endpoint = null; + #manualClose = false; + #attempt = 0; + #seq = 0; + #pending = new Map(); // id -> { resolve, reject, timer } + #queue = Promise.resolve(); + #reconnectTimer = null; + + #state = { kind: IDLE, attempt: 0, reason: "", retrying: false }; + + constructor({ + WebSocketImpl = globalThis.WebSocket, + backoffBaseMs = 1000, + backoffMaxMs = 30000, + requestTimeoutMs = 30000, + random = Math.random, + } = {}) { + super(); + if (typeof WebSocketImpl !== "function") { + throw new Error("No WebSocket implementation available"); + } + this.#WebSocketImpl = WebSocketImpl; + this.#backoffBaseMs = backoffBaseMs; + this.#backoffMaxMs = backoffMaxMs; + this.#requestTimeoutMs = requestTimeoutMs; + this.#random = random; + } + + get state() { + return { ...this.#state }; + } + + #setState(next) { + this.#state = next; + this.dispatchEvent(new CustomEvent("state", { detail: this.state })); + } + + /** Opens (or re-opens) the connection to a validated server URL. */ + connect(validated) { + if (!validated || !validated.valid) { + throw new Error("server URL is not valid"); + } + this.#endpoint = validated.wsUrl; + this.#manualClose = false; + this.#attempt = 0; + this.#clearReconnect(); + this.#open(); + } + + /** Explicit user disconnect: stops reconnection and closes the socket. */ + disconnect() { + this.#manualClose = true; + this.#clearReconnect(); + const socket = this.#ws; + this.#ws = null; + try { + socket?.close(NORMAL_CLOSURE, "client closing"); + } catch { + /* already closed */ + } + this.#failPending("Disconnected"); + this.#setState({ kind: IDLE, attempt: 0, reason: "", retrying: false }); + } + + /** + * Sends one request and awaits the reply with the matching id. Serialized by a + * promise chain so concurrent screens cannot interleave frames. + */ + async call(request) { + const run = this.#queue.then(() => this.#doCall(request)); + // Keep the chain alive even when a call rejects. + this.#queue = run.then( + () => undefined, + () => undefined, + ); + return run; + } + + async #doCall(request) { + const socket = this.#ws; + if (!socket || this.#state.kind !== CONNECTED) throw new NotConnectedError(); + const id = `web-${++this.#seq}`; + const payload = JSON.stringify({ ...request, id }); + + const reply = new Promise((resolve, reject) => { + const timer = setTimeout(() => { + this.#pending.delete(id); + reject(new Error(`request timed out after ${this.#requestTimeoutMs}ms`)); + }, this.#requestTimeoutMs); + this.#pending.set(id, { resolve, reject, timer }); + }); + + try { + socket.send(payload); + const response = await reply; + if (response.type === Protocol.ERROR) { + throw new ProtocolError((response.error || "").trim() || "server error"); + } + return response; + } finally { + const entry = this.#pending.get(id); + if (entry) { + clearTimeout(entry.timer); + this.#pending.delete(id); + } + } + } + + #open() { + const current = this.#endpoint; + if (!current) return; + this.#attempt += 1; + this.#setState({ + kind: CONNECTING, + attempt: this.#attempt, + reason: "", + retrying: false, + }); + const socket = new this.#WebSocketImpl(current); + this.#ws = socket; + socket.onopen = () => { + this.#attempt = 0; + this.#setState({ kind: CONNECTED, attempt: 0, reason: "", retrying: false }); + }; + socket.onmessage = (event) => this.#onMessage(event.data); + socket.onclose = (event) => { + this.#handleClosed(`Connection closed (${event.code ?? "?"})`); + }; + socket.onerror = () => { + // Browsers withhold detail here; onclose carries the outcome. + }; + } + + #onMessage(data) { + if (typeof data !== "string") return; // the server is text-only + let message; + try { + message = JSON.parse(data); + } catch { + return; // malformed frame: never misattribute it to a request + } + const entry = message.id ? this.#pending.get(message.id) : null; + if (entry) { + this.#pending.delete(message.id); + clearTimeout(entry.timer); + entry.resolve(message); + } + // Unsolicited envelopes (for example the connection's initial pipeline_list) + // have no matching id and are intentionally dropped. + } + + #failPending(reason) { + for (const [id, entry] of this.#pending) { + this.#pending.delete(id); + clearTimeout(entry.timer); + entry.reject(new Error(reason)); + } + } + + #handleClosed(reason) { + this.#ws = null; + this.#failPending(reason); + if (this.#manualClose) { + this.#setState({ kind: IDLE, attempt: 0, reason: "", retrying: false }); + return; + } + this.#scheduleReconnect(reason); + } + + #scheduleReconnect(reason) { + if (this.#reconnectTimer) return; + this.#setState({ + kind: DISCONNECTED, + attempt: this.#attempt, + reason, + retrying: true, + }); + const shift = Math.min(Math.max(this.#attempt - 1, 0), 6); + const backoff = Math.min(this.#backoffBaseMs << shift, this.#backoffMaxMs); + const jitter = Math.floor(this.#random() * 400); + this.#reconnectTimer = setTimeout(() => { + this.#reconnectTimer = null; + if (!this.#manualClose && this.#endpoint) this.#open(); + }, backoff + jitter); + } + + #clearReconnect() { + if (this.#reconnectTimer) { + clearTimeout(this.#reconnectTimer); + this.#reconnectTimer = null; + } + } +} diff --git a/web/src/protocol.js b/web/src/protocol.js new file mode 100644 index 00000000..72ce842b --- /dev/null +++ b/web/src/protocol.js @@ -0,0 +1,31 @@ +// Protocol command/type constants. Mirrors the subset of +// android/app/src/main/java/net/awan/pipelines/data/protocol/Message.kt and +// internal/protocol/*.go used by this spike, so renames cannot drift silently. +export const Protocol = Object.freeze({ + PING: "ping", + PONG: "pong", + ERROR: "error", + + LIST: "list_pipelines", + PIPELINE_LIST: "pipelines", + GET_PIPELINE: "get_pipeline", + PIPELINE: "pipeline", + + LIST_RUNS: "list_runs", + RUNS: "runs", + GET_RUN: "get_run", + RUN: "run", + + SUCCESS_END: "#success", + FAILURE_END: "#failure", +}); + +export function isTerminal(target) { + return target === Protocol.SUCCESS_END || target === Protocol.FAILURE_END; +} + +/** Mirrors protocol.ResolveTarget: preserve the # shorthand as an explicit terminal. */ +export function resolveTarget(outcome, target) { + if (target !== "#") return target; + return outcome === "error" ? Protocol.FAILURE_END : Protocol.SUCCESS_END; +} diff --git a/web/src/repository.js b/web/src/repository.js new file mode 100644 index 00000000..1ae5387c --- /dev/null +++ b/web/src/repository.js @@ -0,0 +1,61 @@ +// Typed access to the existing WebSocket protocol. Request builders and id +// matching live here so the app never constructs frames by hand or invents +// divergent field names. Mirrors android/.../data/PipelinesRepository.kt. +import { Protocol } from "./protocol.js"; +import { ProtocolError } from "./client.js"; + +export class PipelinesRepository { + #client; + + constructor(client) { + this.#client = client; + } + + get connectionState() { + return this.#client.state; + } + + connect(validated) { + this.#client.connect(validated); + } + + disconnect() { + this.#client.disconnect(); + } + + ping() { + return this.#client.call({ type: Protocol.PING }); + } + + async listPipelines() { + return (await this.#client.call({ type: Protocol.LIST })).pipelines ?? []; + } + + async getPipeline(id, version) { + const response = await this.#client.call({ + type: Protocol.GET_PIPELINE, + pipeline_id: id, + version, + }); + if (!response.detail) { + throw new ProtocolError("The server returned no pipeline detail."); + } + return response.detail; + } + + async listRuns() { + const response = await this.#client.call({ type: Protocol.LIST_RUNS }); + return { runs: response.runs ?? [], usage: response.usage ?? null }; + } + + async getRun(id) { + const response = await this.#client.call({ + type: Protocol.GET_RUN, + run_id: id, + }); + if (!response.run_detail) { + throw new ProtocolError("The server returned no run detail."); + } + return response.run_detail; + } +} diff --git a/web/src/serverUrl.js b/web/src/serverUrl.js new file mode 100644 index 00000000..e5229760 --- /dev/null +++ b/web/src/serverUrl.js @@ -0,0 +1,107 @@ +// Server-URL validation mirroring android/.../data/transport/ServerUrl.kt and +// internal/client/config.go: only ws/wss with a non-empty hostname and no +// userinfo/fragment. The endpoint path defaults to /connect, matching +// internal/server/websocket.go `GET /connect`. + +export const ServerUrlKind = Object.freeze({ + EMPTY: "EMPTY", + MALFORMED: "MALFORMED", + UNSUPPORTED_SCHEME: "UNSUPPORTED_SCHEME", + MISSING_HOST: "MISSING_HOST", + USER_INFO: "USER_INFO", + FRAGMENT: "FRAGMENT", +}); + +/** + * @returns {{valid:true, wsUrl:string, httpUrl:string, host:string, port:number, secure:boolean} + * |{valid:false, kind:string, message:string}} + */ +export function validateServerUrl(raw) { + const trimmed = (raw ?? "").trim(); + if (!trimmed) { + return { + valid: false, + kind: ServerUrlKind.EMPTY, + message: + "Enter the Pipelines server URL, for example ws://192.168.1.20:8081/connect", + }; + } + + let url; + try { + url = new URL(trimmed); + } catch { + return { + valid: false, + kind: ServerUrlKind.MALFORMED, + message: "That is not a valid URL.", + }; + } + + const scheme = url.protocol.replace(/:$/, "").toLowerCase(); + if (scheme !== "ws" && scheme !== "wss") { + return { + valid: false, + kind: ServerUrlKind.UNSUPPORTED_SCHEME, + message: `Unsupported scheme "${scheme}"; use ws:// (trusted LAN/VPN) or wss://`, + }; + } + if (url.username || url.password) { + return { + valid: false, + kind: ServerUrlKind.USER_INFO, + message: + "Credentials are not supported; the server has no authentication. Remove userinfo from the URL", + }; + } + if (url.hash) { + return { + valid: false, + kind: ServerUrlKind.FRAGMENT, + message: "Remove the # fragment; it is not part of the server endpoint", + }; + } + if (!url.hostname) { + return { + valid: false, + kind: ServerUrlKind.MISSING_HOST, + message: + "The URL is missing a host, for example ws://192.168.1.20:8081/connect", + }; + } + + const secure = scheme === "wss"; + const port = url.port ? Number(url.port) : secure ? 443 : 80; + let path = url.pathname || ""; + if (!path || path === "/") path = "/connect"; + + const authority = url.host; // host + explicit port only when present + const search = url.search || ""; + const wsUrl = `${scheme}://${authority}${path}${search}`; + const httpUrl = `${secure ? "https" : "http"}://${authority}${path}${search}`; + + return { valid: true, wsUrl, httpUrl, host: url.hostname, port, secure }; +} + +/** + * Resolves a server-relative artifact url (for example "/artifacts/55/4/shot.png") + * against the configured server URL by mapping ws/wss to http/https and dropping + * the /connect path. Never hardcodes a host: a blank or invalid configuration, or + * a blank path, yields null so the UI can disable actions. An already-absolute + * http(s) url is returned unchanged. Mirrors ServerUrl.resolveArtifactUrl. + */ +export function resolveArtifactUrl(configured, artifactUrl) { + const relative = (artifactUrl ?? "").trim(); + if (!relative) return null; + if (relative.startsWith("http://") || relative.startsWith("https://")) { + return relative; + } + const validated = validateServerUrl(configured); + if (!validated.valid) return null; + const { secure, host, port } = validated; + const defaultPort = secure ? 443 : 80; + const authority = port && port !== defaultPort ? `${host}:${port}` : host; + const origin = `${secure ? "https" : "http"}://${authority}`; + const path = relative.startsWith("/") ? relative : `/${relative}`; + return origin + path; +} diff --git a/web/styles.css b/web/styles.css new file mode 100644 index 00000000..f753f440 --- /dev/null +++ b/web/styles.css @@ -0,0 +1,144 @@ +/* Throwaway spike styling. Dark-first, echoing the Android client's theme. */ +:root { + color-scheme: dark; + --bg: #0e1513; + --surface: #171f1d; + --surface-2: #1f2a27; + --border: #2c3a36; + --text: #e2e8e6; + --muted: #9db0ab; + --accent: #7fd1bb; + --ok: #6bd39a; + --warn: #e6c268; + --bad: #ef8a8a; +} + +* { box-sizing: border-box; } + +body { + margin: 0; + background: var(--bg); + color: var(--text); + font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; +} + +.topbar { + display: flex; + gap: 16px; + align-items: center; + justify-content: space-between; + padding: 10px 16px; + background: var(--surface); + border-bottom: 1px solid var(--border); + position: sticky; + top: 0; + z-index: 2; + flex-wrap: wrap; +} + +.brand { display: flex; gap: 8px; align-items: baseline; } +.brand strong { font-size: 16px; } + +.connbar { display: flex; gap: 8px; align-items: center; flex: 1 1 420px; justify-content: flex-end; } + +input[type="text"] { + flex: 1 1 260px; + min-width: 200px; + padding: 7px 10px; + background: var(--surface-2); + color: var(--text); + border: 1px solid var(--border); + border-radius: 8px; + font: inherit; +} + +button { + font: inherit; + padding: 7px 12px; + border-radius: 8px; + border: 1px solid var(--border); + background: var(--surface-2); + color: var(--text); + cursor: pointer; +} +button:hover { border-color: var(--accent); } +button.ghost { background: transparent; } + +.tabs { display: flex; gap: 4px; align-items: center; padding: 10px 16px 0; } +.tabs .spacer { flex: 1; } +.tab { border-color: transparent; background: transparent; } +.tab.active { background: var(--surface-2); border-color: var(--border); color: var(--accent); } + +.split { display: grid; grid-template-columns: minmax(260px, 380px) 1fr; gap: 16px; padding: 16px; align-items: start; } +@media (max-width: 760px) { .split { grid-template-columns: 1fr; } } + +.list, .detail { + background: var(--surface); + border: 1px solid var(--border); + border-radius: 12px; + overflow: hidden; +} + +.row { + display: block; + width: 100%; + text-align: left; + border: 0; + border-bottom: 1px solid var(--border); + border-radius: 0; + background: transparent; + padding: 10px 12px; +} +.row:last-child { border-bottom: 0; } +.row:hover { background: var(--surface-2); } +.row.selected { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); } +.row-head { display: flex; gap: 8px; justify-content: space-between; align-items: center; } +.row-title { font-weight: 600; } +.row-meta { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; } +.row-diag { display: block; color: var(--warn); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } + +.usage { display: flex; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12px; } + +.detail { padding: 16px; } +.detail h2 { margin: 0 0 12px; display: flex; gap: 10px; align-items: center; } +.detail h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); text-transform: none; } + +.kv { display: grid; gap: 4px; } +.kv.tight { margin-top: 6px; } +.kv-row { display: grid; grid-template-columns: 150px 1fr; gap: 10px; } +.kv-key { color: var(--muted); } +.kv-val { word-break: break-word; } + +.stages { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; } +.stages li { display: flex; gap: 8px; align-items: center; } + +.steps { display: grid; gap: 8px; } +.step { border: 1px solid var(--border); border-radius: 10px; padding: 10px; } +.step-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } + +.artifacts { margin-top: 8px; font-size: 12px; } +.artifacts a { color: var(--accent); margin-right: 10px; } + +.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--border); color: var(--muted); } +.chip-running, .chip-queued { color: var(--warn); border-color: var(--warn); } +.chip-succeeded { color: var(--ok); border-color: var(--ok); } +.chip-failed { color: var(--bad); border-color: var(--bad); } + +.dot::before { content: "●"; margin-right: 6px; } +.dot.ok::before { color: var(--ok); } +.dot.warn::before { color: var(--warn); } +.dot.bad::before { color: var(--bad); } +.dot.idle::before { color: var(--muted); } +.state { color: var(--muted); white-space: nowrap; } + +.muted { color: var(--muted); } +.ok { color: var(--ok); } +.warn { color: var(--warn); } +.bad { color: var(--bad); } +.pad { padding: 12px; } + +.banner { padding: 8px 16px; } +.banner.warn { background: #2a2410; color: var(--warn); } +.banner.error { background: #2c1616; color: var(--bad); } + +code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 12px; } diff --git a/web/test/client.test.mjs b/web/test/client.test.mjs new file mode 100644 index 00000000..31f41050 --- /dev/null +++ b/web/test/client.test.mjs @@ -0,0 +1,163 @@ +// Client transport tests against a fake WebSocket: id matching, serialization, +// error replies, timeouts and the not-connected guard. No server required. +import { test } from "node:test"; +import assert from "node:assert/strict"; + +import { PipelinesClient, ProtocolError, NotConnectedError } from "../src/client.js"; +import { validateServerUrl } from "../src/serverUrl.js"; + +const VALID = validateServerUrl("ws://host:8080/connect"); + +class FakeWebSocket { + static instances = []; + + constructor(url) { + this.url = url; + this.sent = []; + this.closed = null; + this.onopen = null; + this.onmessage = null; + this.onclose = null; + this.onerror = null; + /** @type {((frame: any) => any | undefined) | null} */ + this.reply = null; + FakeWebSocket.instances.push(this); + } + + send(data) { + const frame = JSON.parse(data); + this.sent.push(frame); + const response = this.reply?.(frame); + if (response !== undefined) { + this.onmessage?.({ data: JSON.stringify(response) }); + } + } + + close(code, reason) { + this.closed = { code, reason }; + this.onclose?.({ code, reason }); + } + + // test hooks + open() { + this.onopen?.({}); + } + + push(obj) { + this.onmessage?.({ data: JSON.stringify(obj) }); + } + + drop(code = 1006) { + this.onclose?.({ code, reason: "test" }); + } +} + +/** Let the client's serialized call chain run to the point where it has sent. */ +const flush = () => new Promise((resolve) => setImmediate(resolve)); + +function freshClient(options = {}) { + FakeWebSocket.instances = []; + return new PipelinesClient({ WebSocketImpl: FakeWebSocket, ...options }); +} + +function connectedClient(options = {}) { + const client = freshClient(options); + client.connect(VALID); + const ws = FakeWebSocket.instances.at(-1); + ws.open(); + return { client, ws }; +} + +test("a call before connect is rejected as not connected", async () => { + const client = freshClient(); + await assert.rejects(() => client.call({ type: "ping" }), NotConnectedError); +}); + +test("a call sends a JSON frame with a generated id and resolves the matching reply", async () => { + const { client, ws } = connectedClient(); + ws.reply = (frame) => ({ id: frame.id, type: "pong" }); + + const reply = await client.call({ type: "ping" }); + assert.equal(reply.type, "pong"); + assert.equal(ws.sent.length, 1); + assert.equal(ws.sent[0].type, "ping"); + assert.match(ws.sent[0].id, /^web-\d+$/); +}); + +test("an error reply surfaces the server text as a ProtocolError", async () => { + const { client, ws } = connectedClient(); + ws.reply = (frame) => ({ id: frame.id, type: "error", error: "nope" }); + await assert.rejects(() => client.call({ type: "get_run" }), ProtocolError); +}); + +test("an unsolicited envelope with no matching id is dropped, not misattributed", async () => { + const { client, ws } = connectedClient(); + ws.reply = undefined; + + const pending = client.call({ type: "ping" }); + let settled = false; + pending.then(() => (settled = true), () => (settled = true)); + await flush(); + + ws.push({ type: "pipelines", pipelines: [] }); // no id + await flush(); + assert.equal(settled, false); + + const frame = ws.sent.at(-1); + ws.push({ id: frame.id, type: "pong" }); + assert.equal((await pending).type, "pong"); +}); + +test("a malformed frame is ignored and does not reject a pending call", async () => { + const { client, ws } = connectedClient(); + const pending = client.call({ type: "ping" }); + await flush(); + ws.onmessage?.({ data: "{not json" }); + const frame = ws.sent.at(-1); + ws.push({ id: frame.id, type: "pong" }); + assert.equal((await pending).type, "pong"); +}); + +test("a missing reply times out with a clear error", async () => { + const { client } = connectedClient({ requestTimeoutMs: 20 }); + await assert.rejects(() => client.call({ type: "ping" }), /timed out after 20ms/); +}); + +test("concurrent calls are serialized in submission order", async () => { + const { client, ws } = connectedClient(); + const order = []; + ws.reply = (frame) => { + order.push(frame.type); + return { id: frame.id, type: "ok" }; + }; + await Promise.all([client.call({ type: "a" }), client.call({ type: "b" })]); + assert.deepEqual(order, ["a", "b"]); +}); + +test("the state flow reports connecting then connected", async () => { + const seen = []; + const client = freshClient(); + client.addEventListener("state", (e) => seen.push(e.detail.kind)); + client.connect(VALID); + FakeWebSocket.instances.at(-1).open(); + assert.deepEqual(seen, ["connecting", "connected"]); +}); + +test("an unexpected close fails pending calls and schedules a reconnect", async () => { + const { client, ws } = connectedClient({ backoffBaseMs: 1, backoffMaxMs: 5 }); + const pending = client.call({ type: "ping" }); // never answered + await flush(); // let the call reach the socket before it is dropped + ws.drop(1006); + await assert.rejects(() => pending, /Connection closed/); + assert.equal(client.state.kind, "disconnected"); + assert.equal(client.state.retrying, true); + client.disconnect(); // stop the reconnect timer before the test ends +}); + +test("disconnect goes idle and does not schedule a reconnect", () => { + const { client, ws } = connectedClient(); + client.disconnect(); + assert.equal(client.state.kind, "idle"); + assert.equal(client.state.retrying, false); + assert.deepEqual(ws.closed, { code: 1000, reason: "client closing" }); +}); diff --git a/web/test/serverUrl.test.mjs b/web/test/serverUrl.test.mjs new file mode 100644 index 00000000..beb383d8 --- /dev/null +++ b/web/test/serverUrl.test.mjs @@ -0,0 +1,85 @@ +// Unit tests for the ported ServerUrl validation, run with `node --test`. +// Mirrors the cases in android/.../test/.../ServerUrlTest.kt. +import { test } from "node:test"; +import assert from "node:assert/strict"; + +import { validateServerUrl, resolveArtifactUrl, ServerUrlKind } from "../src/serverUrl.js"; +import { Protocol, resolveTarget, isTerminal } from "../src/protocol.js"; + +test("defaults a bare host to /connect over ws", () => { + const v = validateServerUrl("ws://192.168.1.20:8081"); + assert.equal(v.valid, true); + assert.equal(v.wsUrl, "ws://192.168.1.20:8081/connect"); + assert.equal(v.httpUrl, "http://192.168.1.20:8081/connect"); + assert.equal(v.host, "192.168.1.20"); + assert.equal(v.port, 8081); + assert.equal(v.secure, false); +}); + +test("treats a lone / as the default endpoint path", () => { + const v = validateServerUrl("ws://host:1234/"); + assert.equal(v.valid, true); + assert.equal(v.wsUrl, "ws://host:1234/connect"); +}); + +test("wss maps to https and defaults the port to 443", () => { + const v = validateServerUrl("wss://example.test/connect"); + assert.equal(v.valid, true); + assert.equal(v.secure, true); + assert.equal(v.port, 443); + assert.equal(v.httpUrl, "https://example.test/connect"); +}); + +test("rejects empty, non-ws schemes, userinfo and fragments", () => { + assert.equal(validateServerUrl("").kind, ServerUrlKind.EMPTY); + assert.equal(validateServerUrl(" ").kind, ServerUrlKind.EMPTY); + assert.equal(validateServerUrl("http://host:8080/connect").kind, ServerUrlKind.UNSUPPORTED_SCHEME); + assert.equal(validateServerUrl("ftp://host").kind, ServerUrlKind.UNSUPPORTED_SCHEME); + assert.equal(validateServerUrl("ws://user:pass@host:8080/connect").kind, ServerUrlKind.USER_INFO); + assert.equal(validateServerUrl("ws://host:8080/connect#frag").kind, ServerUrlKind.FRAGMENT); +}); + +test("rejects malformed and hostless input", () => { + assert.equal(validateServerUrl("not a url").kind, ServerUrlKind.MALFORMED); + const hostless = validateServerUrl("ws://"); + assert.ok(hostless.kind === ServerUrlKind.MALFORMED || hostless.kind === ServerUrlKind.MISSING_HOST); + assert.equal(hostless.valid, false); +}); + +test("preserves a query string", () => { + const v = validateServerUrl("ws://host:8080/connect?token=abc"); + assert.equal(v.valid, true); + assert.equal(v.wsUrl, "ws://host:8080/connect?token=abc"); +}); + +test("resolveArtifactUrl maps ws to http and drops /connect", () => { + assert.equal( + resolveArtifactUrl("ws://10.0.0.249:8080/connect", "/artifacts/55/4/shot.png"), + "http://10.0.0.249:8080/artifacts/55/4/shot.png", + ); +}); + +test("resolveArtifactUrl uses https and omits the default port for wss", () => { + assert.equal( + resolveArtifactUrl("wss://example.test/connect", "artifacts/1/1/a.png"), + "https://example.test/artifacts/1/1/a.png", + ); +}); + +test("resolveArtifactUrl returns an absolute url unchanged and null when unconfigured", () => { + assert.equal( + resolveArtifactUrl("ws://host:8080/connect", "https://cdn.test/a.png"), + "https://cdn.test/a.png", + ); + assert.equal(resolveArtifactUrl("", "/artifacts/1/1/a.png"), null); + assert.equal(resolveArtifactUrl("ws://host:8080/connect", " "), null); +}); + +test("protocol target resolution mirrors the server shorthand", () => { + assert.equal(resolveTarget("error", "#"), Protocol.FAILURE_END); + assert.equal(resolveTarget("success", "#"), Protocol.SUCCESS_END); + assert.equal(resolveTarget("error", "cleanup"), "cleanup"); + assert.equal(isTerminal("#success"), true); + assert.equal(isTerminal("#failure"), true); + assert.equal(isTerminal("cleanup"), false); +}); diff --git a/web/test/smoke.mjs b/web/test/smoke.mjs new file mode 100644 index 00000000..8fd82bc1 --- /dev/null +++ b/web/test/smoke.mjs @@ -0,0 +1,102 @@ +// Live end-to-end smoke test: drives the *real* client (src/client.js) against a +// running Pipelines server. Opt-in, because it needs a server: +// +// PIPELINES_WS_URL=ws://127.0.0.1:8080/connect node test/smoke.mjs +// +// Uses Node's built-in global WebSocket and fetch (Node >= 22). Exits non-zero +// on the first failed assertion so it is usable in a check. +import assert from "node:assert/strict"; + +import { PipelinesClient } from "../src/client.js"; +import { PipelinesRepository } from "../src/repository.js"; +import { validateServerUrl, resolveArtifactUrl } from "../src/serverUrl.js"; + +const raw = process.env.PIPELINES_WS_URL ?? process.argv[2] ?? ""; +if (!raw) { + console.error("PIPELINES_WS_URL is required, e.g. ws://127.0.0.1:8080/connect"); + process.exit(2); +} + +const validated = validateServerUrl(raw); +if (!validated.valid) { + console.error(`invalid server URL: ${validated.message}`); + process.exit(2); +} + +const client = new PipelinesClient(); +const repo = new PipelinesRepository(client); +const checks = []; +const pass = (name) => { + checks.push(name); + console.log(` ok ${name}`); +}; + +try { + await connectWithTimeout(client, validated, 5000); + pass("websocket connected"); + + const pong = await repo.ping(); + assert.equal(pong.type, "pong"); + pass("ping -> pong"); + + const pipelines = await repo.listPipelines(); + assert.ok(Array.isArray(pipelines)); + pass(`list_pipelines -> ${pipelines.length} pipeline(s)`); + + const { runs, usage } = await repo.listRuns(); + assert.ok(Array.isArray(runs)); + pass(`list_runs -> ${runs.length} run(s), usage.total=${usage?.total ?? "n/a"}`); + + if (pipelines.length) { + const detail = await repo.getPipeline(pipelines[0].id, pipelines[0].version); + assert.equal(detail.id, pipelines[0].id); + assert.ok(Array.isArray(detail.graph?.stages)); + pass(`get_pipeline #${detail.id} -> ${detail.graph.stages.length} stage(s)`); + } else { + console.log(" -- no pipelines; skipped get_pipeline"); + } + + if (runs.length) { + const run = await repo.getRun(runs[0].id); + assert.equal(run.id, runs[0].id); + assert.ok(Array.isArray(run.steps)); + pass(`get_run #${run.id} -> status=${run.status} steps=${run.steps.length}`); + + const artifact = run.steps.flatMap((s) => s.artifacts ?? []).find((a) => a.url); + if (artifact) { + const url = resolveArtifactUrl(raw, artifact.url); + assert.ok(url?.startsWith("http")); + const res = await fetch(url, { method: "HEAD" }); + pass(`artifact HEAD ${url} -> ${res.status} ${res.headers.get("content-type") ?? ""}`.trim()); + assert.ok(res.ok, `artifact HEAD was ${res.status}`); + } else { + console.log(" -- newest run has no artifacts; skipped artifact fetch"); + } + } else { + console.log(" -- no runs; skipped get_run"); + } + + console.log(`\nSMOKE PASS (${checks.length} checks) against ${validated.wsUrl}`); + client.disconnect(); + process.exit(0); +} catch (err) { + console.error(`\nSMOKE FAIL: ${err?.message ?? err}`); + console.error(`against ${validated.wsUrl}`); + client.disconnect(); + process.exit(1); +} + +function connectWithTimeout(c, validatedUrl, ms) { + return new Promise((resolve, reject) => { + const timer = setTimeout(() => reject(new Error(`connect timed out after ${ms}ms`)), ms); + const onState = (event) => { + if (event.detail.kind === "connected") { + clearTimeout(timer); + c.removeEventListener("state", onState); + resolve(); + } + }; + c.addEventListener("state", onState); + c.connect(validatedUrl); + }); +}