@rt-tools/agent-kit 0.33.1 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/assets/agents/goal-critic.md +67 -0
- package/assets/agents/product-strategist.md +90 -0
- package/assets/agents/qa-engineer.md +3 -0
- package/assets/checks/check-specs.mjs +11 -2
- package/assets/checks/rt-kit-checks.config.mjs +6 -0
- package/assets/checks/spec-common.mjs +6 -3
- package/assets/checks/spec-scenarios.mjs +9 -1
- package/assets/checks/task-new.github.mjs +6 -0
- package/assets/defaults/project.sh +10 -81
- package/assets/defaults/push.sh +100 -0
- package/assets/docs/GLOSSARY.md +4 -0
- package/assets/hooks/browser-guard-no-other-drivers.sh +6 -3
- package/assets/hooks/claim-guard.sh +6 -6
- package/assets/hooks/dispatch.sh +56 -3
- package/assets/hooks/exam-guard.sh +1 -1
- package/assets/hooks/git-guard-delivery-body.sh +25 -3
- package/assets/hooks/git-guard-delivery-folder.sh +17 -1
- package/assets/hooks/git-guard-delivery-pipeline.sh +99 -0
- package/assets/hooks/git-guard-delivery.sh +17 -10
- package/assets/hooks/git-guard-main.sh +17 -4
- package/assets/hooks/git-guard-push-ahead.sh +89 -0
- package/assets/hooks/git-guard-push-marks.sh +99 -0
- package/assets/hooks/git-guard-push-tests.sh +101 -83
- package/assets/hooks/pre-push.sh +113 -0
- package/assets/hooks/push-set.sh +150 -0
- package/assets/hooks/push-sign.sh +433 -0
- package/assets/hooks/rerun-guard.sh +14 -6
- package/assets/hooks/turn-exit-guard.sh +2 -2
- package/assets/hooks/turn-exit-patterns.sh +4 -3
- package/assets/hooks/turn-exit-verdict.sh +18 -1
- package/assets/hooks/waiting-turn-guard.sh +2 -1
- package/assets/hooks/write-targets.sh +21 -0
- package/assets/patterns/git-workflow-commit.github.md +11 -0
- package/assets/patterns/git-workflow-pr-body.github.md +20 -3
- package/assets/patterns/git-workflow-pr.azure.md +30 -0
- package/assets/patterns/git-workflow-pr.github.md +57 -1
- package/assets/patterns/git-workflow-pr.gitlab.md +33 -0
- package/assets/patterns/mockups-measure.needs-mockups.md +19 -3
- package/assets/patterns/task-flow-close.md +27 -16
- package/assets/patterns/task-flow-start.md +3 -3
- package/assets/rules/browser-verification.md +4 -0
- package/assets/rules/deploy-flow.azure.md +5 -0
- package/assets/rules/deploy-flow.github.md +5 -0
- package/assets/rules/deploy-flow.gitlab.md +5 -0
- package/assets/rules/git-workflow.azure.md +15 -0
- package/assets/rules/git-workflow.github.md +15 -0
- package/assets/rules/git-workflow.gitlab.md +15 -0
- package/assets/rules/mockups.needs-mockups.md +13 -5
- package/assets/rules/task-flow.md +21 -16
- package/assets/samples/tasks/_template/plan.md +7 -0
- package/assets/skills/interface-review-annotate.needs-mockups.md +142 -0
- package/assets/skills/interface-review-icons.needs-app.md +136 -0
- package/assets/skills/interface-review-motion-states.needs-app.md +230 -0
- package/assets/skills/interface-review-motion.needs-app.md +209 -0
- package/assets/skills/interface-review-performance.needs-app.md +110 -0
- package/assets/skills/interface-review-principles.needs-app.md +263 -0
- package/assets/skills/interface-review-surfaces.needs-app.md +249 -0
- package/assets/skills/interface-review.needs-app.md +199 -0
- package/assets/skills/write-a-skill.md +16 -3
- package/assets/workflows/feature.js +33 -5
- package/assets/workflows/plan.js +71 -4
- package/package.json +1 -1
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The parse of a command for the push gate. NOT a guard: it has no `rt-hook:` declaration and hooks
|
|
3
|
+
# into no agent event. The push gate sources it and calls `rt_push_calls` with the command text on
|
|
4
|
+
# the input; it stands apart because the guard with it inside crossed the length limit for code.
|
|
5
|
+
#
|
|
6
|
+
# The push calls are found by a parse of the command as the shell reads it, not by patterns over
|
|
7
|
+
# the line. A push is the subcommand `push` of a `git` call, after the keys of `git` itself: `-c`
|
|
8
|
+
# and `-C` carry the credentials helper and the request header, and that is the form pushed with
|
|
9
|
+
# here. Patterns over the line missed in both directions. They cut `-c 'h: a; b'` at the `;`
|
|
10
|
+
# inside the quotes and let that push through; they did not see `git` after `{`, `if`, `while`,
|
|
11
|
+
# backticks, `bash -c` and `eval`; and they read the word in a filter of another command as a push,
|
|
12
|
+
# running the whole set for more than ten minutes on a command that sends nothing.
|
|
13
|
+
#
|
|
14
|
+
# Quoted text is data, except where the shell runs it: `$( )`, backticks, the string of `bash -c`
|
|
15
|
+
# and the words of `eval` are parsed as commands. The body of a heredoc with a quoted delimiter is
|
|
16
|
+
# data; with a bare delimiter its `$( )` and backticks run and are parsed. A heredoc given to a
|
|
17
|
+
# shell is run whole and parsed whole. A function body runs only when the function is called, so it
|
|
18
|
+
# is parsed at the call, with the call words put in place of `$@` and `$1`; a function named `git`
|
|
19
|
+
# does not hide the git call. A wrapper is passed with its keys and their values — `time -p`,
|
|
20
|
+
# `timeout -s KILL 5`, `sudo -iu x`; the string of `env -S` is parsed as a command. `xargs`,
|
|
21
|
+
# `parallel`, `find -exec`, `watch` and `repeat` run their command more than once, so a push under
|
|
22
|
+
# them counts as a push in a loop. A stashed edit is no push — `git stash push` has the subcommand
|
|
23
|
+
# `stash` and sends nothing outside.
|
|
24
|
+
#
|
|
25
|
+
# One line per push call: whether it stands inside a loop (`for`, `while`, `until`, from the
|
|
26
|
+
# keyword to its `done`), whether it sends several branches, whether it is a dry run. Several
|
|
27
|
+
# branches are `--all`, `--mirror`, `--branches`, a ref with `*` or with a brace expansion, or two
|
|
28
|
+
# refs after the remote; a ref that starts with `:` deletes and is not counted. `$( )` and a quoted
|
|
29
|
+
# word stay one word. With `--repo` every word after the keys counts as a ref: git takes the first
|
|
30
|
+
# of them for the remote, and the sign errs towards a refusal it does not need rather than a push it
|
|
31
|
+
# does not see.
|
|
32
|
+
#
|
|
33
|
+
# Two more lines. `switch` — a move to another tree: a switch to an existing branch, a new branch
|
|
34
|
+
# from another start point, `gh pr checkout`; restoring files — after `--`, after a tree word, by
|
|
35
|
+
# `--ours`, `-p` — and a new branch from the current tip are no switch. `opaque` — commands the parse cannot read: a shell reading them from
|
|
36
|
+
# its input, `source` of a substitution, or a text whose function calls grow without bound.
|
|
37
|
+
#
|
|
38
|
+
# FAIL-OPEN: no perl — no output, and the guard passes, like any other breakage of it.
|
|
39
|
+
|
|
40
|
+
rt_push_calls() {
|
|
41
|
+
command -v perl >/dev/null 2>&1 || return 0
|
|
42
|
+
perl -e '
|
|
43
|
+
use strict; use warnings;
|
|
44
|
+
local $/; my $text = <STDIN>; $text = "" unless defined $text;
|
|
45
|
+
my @out; my $calls = 0;
|
|
46
|
+
sub heredoc_word {
|
|
47
|
+
my ($s, $i) = @_; my $n = length $s; my $strip = 0;
|
|
48
|
+
if (substr($s, $i, 1) eq "-") { $strip = 1; $i++; }
|
|
49
|
+
$i++ while $i < $n && substr($s, $i, 1) =~ /[ \t]/;
|
|
50
|
+
my ($delim, $quoted) = ("", 0);
|
|
51
|
+
while ($i < $n && substr($s, $i, 1) !~ /[\s;&|<>()]/) { my $x = substr($s, $i, 1); if ($x =~ /["\x27\\]/) { $quoted = 1; } else { $delim .= $x; } $i++; }
|
|
52
|
+
return ($delim, $strip, $quoted, $i);
|
|
53
|
+
}
|
|
54
|
+
sub heredoc_body {
|
|
55
|
+
my ($s, $i, $delim, $strip) = @_; my $n = length $s; my $body = "";
|
|
56
|
+
while ($i < $n) {
|
|
57
|
+
my $e = index($s, "\n", $i); my $line = $e < 0 ? substr($s, $i) : substr($s, $i, $e - $i);
|
|
58
|
+
$i = $e < 0 ? $n : $e + 1; $line =~ s/^\t+// if $strip; last if $line eq $delim;
|
|
59
|
+
$body .= "$line\n";
|
|
60
|
+
}
|
|
61
|
+
return ($body, $i);
|
|
62
|
+
}
|
|
63
|
+
sub ansi_end {
|
|
64
|
+
my ($s, $i) = @_; my $n = length $s;
|
|
65
|
+
while ($i < $n) { my $c = substr($s, $i, 1); if ($c eq "\\") { $i += 2; next; } return $i if $c eq "\x27"; $i++; }
|
|
66
|
+
return $n;
|
|
67
|
+
}
|
|
68
|
+
sub balanced {
|
|
69
|
+
my ($s, $i) = @_; my $n = length $s; my $d = 1; my $st = $i; my @hd;
|
|
70
|
+
while ($i < $n) {
|
|
71
|
+
my $c = substr($s, $i, 1);
|
|
72
|
+
if ($c eq "\n" && @hd) { $i++; while (my $h = shift @hd) { (undef, $i) = heredoc_body($s, $i, @$h); } next; }
|
|
73
|
+
if ($c eq "\$" && substr($s, $i + 1, 1) eq "\x27") { $i = ansi_end($s, $i + 2) + 1; next; }
|
|
74
|
+
if ($c eq "\x27") { my $e = index($s, "\x27", $i + 1); $i = $e < 0 ? $n : $e + 1; next; }
|
|
75
|
+
if ($c eq "\"") { $i++; while ($i < $n && substr($s, $i, 1) ne "\"") { $i++ if substr($s, $i, 1) eq "\\"; $i++; } $i++; next; }
|
|
76
|
+
if ($c eq "\\") { $i += 2; next; }
|
|
77
|
+
if (substr($s, $i, 3) eq "<<<") { $i += 3; next; }
|
|
78
|
+
if (substr($s, $i, 2) eq "<<") { my ($dl, $sp, undef, $j) = heredoc_word($s, $i + 2); push @hd, [$dl, $sp]; $i = $j; next; }
|
|
79
|
+
$d++ if $c eq "(";
|
|
80
|
+
if ($c eq ")") { $d--; return (substr($s, $st, $i - $st), $i + 1) if $d == 0; }
|
|
81
|
+
$i++;
|
|
82
|
+
}
|
|
83
|
+
return (substr($s, $st), $n);
|
|
84
|
+
}
|
|
85
|
+
sub expansions {
|
|
86
|
+
my ($s) = @_; my $n = length $s; my $i = 0; my @subs;
|
|
87
|
+
while ($i < $n) {
|
|
88
|
+
my $c = substr($s, $i, 1);
|
|
89
|
+
if ($c eq "\\") { $i += 2; next; }
|
|
90
|
+
if ($c eq "\$" && substr($s, $i + 1, 1) eq "(") { my ($in, $j) = balanced($s, $i + 2); push @subs, $in; $i = $j; next; }
|
|
91
|
+
if ($c eq "`") { my $e = index($s, "`", $i + 1); $e = $n if $e < 0; push @subs, substr($s, $i + 1, $e - $i - 1); $i = $e + 1; next; }
|
|
92
|
+
$i++;
|
|
93
|
+
}
|
|
94
|
+
return @subs;
|
|
95
|
+
}
|
|
96
|
+
sub tokenize {
|
|
97
|
+
my ($s) = @_; my $n = length $s; my $i = 0; my @t; my @heredocs;
|
|
98
|
+
my ($w, $have, $q, @subs) = ("", 0, 0);
|
|
99
|
+
my $flush = sub { push @t, { t => "w", v => $w, q => $q, subs => [@subs] } if $have; $w = ""; $have = 0; $q = 0; @subs = (); };
|
|
100
|
+
while ($i < $n) {
|
|
101
|
+
my $c = substr($s, $i, 1);
|
|
102
|
+
if ($c eq "\n") {
|
|
103
|
+
$flush->(); push @t, { t => "s", v => "\n" }; $i++;
|
|
104
|
+
while (my $h = shift @heredocs) {
|
|
105
|
+
my ($delim, $strip, $doc) = @$h;
|
|
106
|
+
($doc->{body}, $i) = heredoc_body($s, $i, $delim, $strip);
|
|
107
|
+
$doc->{subs} = [expansions($doc->{body})] unless $doc->{quoted};
|
|
108
|
+
}
|
|
109
|
+
next;
|
|
110
|
+
}
|
|
111
|
+
if ($c eq " " || $c eq "\t") { $flush->(); $i++; next; }
|
|
112
|
+
if ($c eq "#" && !$have) { my $e = index($s, "\n", $i); $i = $e < 0 ? $n : $e; next; }
|
|
113
|
+
if ($c eq "(" && substr($s, $i + 1, 1) eq "(" && !$have) {
|
|
114
|
+
my ($d, $j) = (0, $i);
|
|
115
|
+
while ($j < $n) { my $x = substr($s, $j, 1); $d++ if $x eq "("; if ($x eq ")") { $d--; if ($d == 0) { $j++; last; } } $j++; }
|
|
116
|
+
push @t, { t => "s", v => ";" }; $i = $j; next;
|
|
117
|
+
}
|
|
118
|
+
if ($c eq "\\") {
|
|
119
|
+
if (substr($s, $i + 1, 1) eq "\n" || $i + 1 >= $n) { $i += 2; next; }
|
|
120
|
+
$w .= substr($s, $i + 1, 1) if $i + 1 < $n; $have = 1; $q = 1; $i += 2; next;
|
|
121
|
+
}
|
|
122
|
+
if ($c eq "\$" && substr($s, $i + 1, 1) eq "\x27") {
|
|
123
|
+
my $e = ansi_end($s, $i + 2); my $raw = substr($s, $i + 2, $e - $i - 2); $raw =~ s/\\(.)/$1/gs;
|
|
124
|
+
$w .= $raw; $have = 1; $q = 1; $i = $e + 1; next;
|
|
125
|
+
}
|
|
126
|
+
if ($c eq "\x27") { my $e = index($s, "\x27", $i + 1); $e = $n if $e < 0; $w .= substr($s, $i + 1, $e - $i - 1); $have = 1; $q = 1; $i = $e + 1; next; }
|
|
127
|
+
if ($c eq "\"") {
|
|
128
|
+
$i++; $have = 1; $q = 1;
|
|
129
|
+
while ($i < $n) {
|
|
130
|
+
my $d = substr($s, $i, 1);
|
|
131
|
+
if ($d eq "\"") { $i++; last; }
|
|
132
|
+
if ($d eq "\\" && $i + 1 < $n) { $w .= substr($s, $i + 1, 1) unless substr($s, $i + 1, 1) eq "\n"; $i += 2; next; }
|
|
133
|
+
if ($d eq "\$" && substr($s, $i + 1, 1) eq "(") { my ($in, $j) = balanced($s, $i + 2); push @subs, $in; $w .= "\$(...)"; $i = $j; next; }
|
|
134
|
+
if ($d eq "`") { my $e = index($s, "`", $i + 1); $e = $n if $e < 0; push @subs, substr($s, $i + 1, $e - $i - 1); $w .= "`...`"; $i = $e + 1; next; }
|
|
135
|
+
$w .= $d; $i++;
|
|
136
|
+
}
|
|
137
|
+
next;
|
|
138
|
+
}
|
|
139
|
+
if ($c eq "\$" && substr($s, $i + 1, 1) eq "(") { my ($in, $j) = balanced($s, $i + 2); push @subs, $in; $w .= "\$(...)"; $have = 1; $i = $j; next; }
|
|
140
|
+
if ($c eq "`") { my $e = index($s, "`", $i + 1); $e = $n if $e < 0; push @subs, substr($s, $i + 1, $e - $i - 1); $w .= "`...`"; $have = 1; $i = $e + 1; next; }
|
|
141
|
+
if (substr($s, $i, 2) eq "<<" && substr($s, $i, 3) ne "<<<") {
|
|
142
|
+
if ($have && $w =~ /^\d+$/) { $w = ""; $have = 0; $q = 0; @subs = (); } else { $flush->(); }
|
|
143
|
+
my ($delim, $strip, $quoted, $j) = heredoc_word($s, $i + 2);
|
|
144
|
+
my $doc = { t => "d", body => "", quoted => $quoted, subs => [] };
|
|
145
|
+
push @t, $doc; push @heredocs, [$delim, $strip, $doc]; $i = $j; next;
|
|
146
|
+
}
|
|
147
|
+
if ($c =~ /[<>]/ || ($c eq "&" && substr($s, $i + 1, 1) eq ">")) {
|
|
148
|
+
if ($have && $w =~ /^\d+$/) { $w = ""; $have = 0; $q = 0; @subs = (); } else { $flush->(); }
|
|
149
|
+
my $j = $i; $i++ while $i < $n && substr($s, $i, 1) =~ /[<>&|]/;
|
|
150
|
+
push @t, { t => "r", v => substr($s, $j, $i - $j) }; next;
|
|
151
|
+
}
|
|
152
|
+
if ($c =~ /[;&|()]/) {
|
|
153
|
+
$flush->(); push @t, { t => "s", v => $c };
|
|
154
|
+
my $two = substr($s, $i, 2); $i += ($two =~ /^(&&|\|\||;;|\|&)$/) ? 2 : 1; next;
|
|
155
|
+
}
|
|
156
|
+
$w .= $c; $have = 1; $i++;
|
|
157
|
+
}
|
|
158
|
+
$flush->(); return @t;
|
|
159
|
+
}
|
|
160
|
+
my (%fn, %busy);
|
|
161
|
+
my $none = qr/^$/;
|
|
162
|
+
my %wrap = (
|
|
163
|
+
command => $none, builtin => $none, nohup => $none, setsid => $none, coproc => $none, arch => qr/^-arch$/,
|
|
164
|
+
exec => qr/^-a$/, caffeinate => qr/^(-t|-w)$/, nice => qr/^(-n|--adjustment)$/,
|
|
165
|
+
sudo => qr/^(-u|-g|-C|-D|-h|-p|-U|-r|-t|--user|--group|--chdir|--host|--prompt|--other-user|--role|--type)$/,
|
|
166
|
+
doas => qr/^(-u|-C)$/, ionice => qr/^(-c|-n|-p|-P|-u|--class|--classdata|--pid|--pgid|--uid)$/,
|
|
167
|
+
stdbuf => qr/^(-i|-o|-e|--input|--output|--error)$/, timeout => qr/^(-s|-k|--signal|--kill-after)$/,
|
|
168
|
+
time => qr/^(-f|-o|--format|--output)$/, watch => qr/^(-n|--interval)$/, repeat => $none,
|
|
169
|
+
xargs => qr/^(-I|-n|-L|-P|-d|-E|-s|-a|--max-args|--max-lines|--max-procs|--delimiter|--eof|--max-chars|--arg-file|--process-slot-var)$/,
|
|
170
|
+
parallel => qr/^(-j|-S|-I|-n|-L|-P|-d|-E|--jobs|--sshlogin|--max-args|--delimiter)$/,
|
|
171
|
+
);
|
|
172
|
+
my %repeats = map { $_ => 1 } qw(xargs parallel watch repeat);
|
|
173
|
+
sub parse { my ($s, $loop) = @_; return parse_tokens([tokenize($s)], $loop); }
|
|
174
|
+
sub opens {
|
|
175
|
+
my ($t, $j) = @_;
|
|
176
|
+
return 1 if $j == 0 || $t->[$j - 1]{t} eq "s";
|
|
177
|
+
my $p = $t->[$j - 1];
|
|
178
|
+
return $p->{t} eq "w" && !$p->{q} && $p->{v} =~ /^(fi|done|esac|\{|\}|then|do|else|elif|if|while|until|!)$/;
|
|
179
|
+
}
|
|
180
|
+
sub closes {
|
|
181
|
+
my ($t, $j) = @_;
|
|
182
|
+
return $j + 1 >= @$t || $t->[$j + 1]{t} eq "s";
|
|
183
|
+
}
|
|
184
|
+
sub body_end {
|
|
185
|
+
my ($t, $i) = @_;
|
|
186
|
+
$i++ while $i < @$t && $t->[$i]{t} eq "s" && $t->[$i]{v} eq "\n";
|
|
187
|
+
return -1 if $i >= @$t;
|
|
188
|
+
my ($f, $d) = ($t->[$i], 0);
|
|
189
|
+
if ($f->{t} eq "w" && $f->{v} eq "{" && !$f->{q}) {
|
|
190
|
+
for (my $j = $i; $j < @$t; $j++) {
|
|
191
|
+
my $x = $t->[$j];
|
|
192
|
+
next unless $x->{t} eq "w" && !$x->{q};
|
|
193
|
+
$d++ if $x->{v} eq "{" && ($j == $i || opens($t, $j));
|
|
194
|
+
if ($x->{v} eq "}" && (opens($t, $j) || closes($t, $j))) { $d--; return $j if $d == 0; }
|
|
195
|
+
}
|
|
196
|
+
return $#$t;
|
|
197
|
+
}
|
|
198
|
+
if ($f->{t} eq "s" && $f->{v} eq "(") {
|
|
199
|
+
for (my $j = $i; $j < @$t; $j++) {
|
|
200
|
+
my $x = $t->[$j]; next unless $x->{t} eq "s";
|
|
201
|
+
$d++ if $x->{v} eq "(";
|
|
202
|
+
if ($x->{v} eq ")") { $d--; return $j if $d == 0; }
|
|
203
|
+
}
|
|
204
|
+
return $#$t;
|
|
205
|
+
}
|
|
206
|
+
return -1;
|
|
207
|
+
}
|
|
208
|
+
sub parse_tokens {
|
|
209
|
+
my ($t, $loop) = @_; my @cmd;
|
|
210
|
+
for (my $i = 0; $i <= @$t; $i++) {
|
|
211
|
+
my $tok = $i < @$t ? $t->[$i] : { t => "s", v => "" };
|
|
212
|
+
if ($tok->{t} eq "s") { $loop = command(\@cmd, $loop) if @cmd; @cmd = (); next; }
|
|
213
|
+
if (!@cmd && $tok->{t} eq "w" && !$tok->{q}) {
|
|
214
|
+
my ($name, $j);
|
|
215
|
+
next if $tok->{v} eq "function" && $i + 1 < @$t && $t->[$i + 1]{t} eq "w" && $t->[$i + 1]{v} eq "{";
|
|
216
|
+
if ($tok->{v} eq "function" && $i + 1 < @$t && $t->[$i + 1]{t} eq "w") {
|
|
217
|
+
($name, $j) = ($t->[$i + 1]{v}, $i + 2);
|
|
218
|
+
$j += 2 if $j + 1 < @$t && $t->[$j]{t} eq "s" && $t->[$j]{v} eq "(" && $t->[$j + 1]{t} eq "s" && $t->[$j + 1]{v} eq ")";
|
|
219
|
+
} elsif ($i + 2 < @$t && $t->[$i + 1]{t} eq "s" && $t->[$i + 1]{v} eq "(" && $t->[$i + 2]{t} eq "s" && $t->[$i + 2]{v} eq ")") {
|
|
220
|
+
($name, $j) = ($tok->{v}, $i + 3);
|
|
221
|
+
}
|
|
222
|
+
if (defined $name) {
|
|
223
|
+
my $end = body_end($t, $j);
|
|
224
|
+
if ($end >= 0) { $fn{$name} = [@$t[$j .. $end]]; $i = $end; next; }
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
push @cmd, $tok;
|
|
228
|
+
}
|
|
229
|
+
return $loop;
|
|
230
|
+
}
|
|
231
|
+
sub bind_text {
|
|
232
|
+
my ($s, @args) = @_;
|
|
233
|
+
$s =~ s/"?\$\{?[@*](?::(\d+))?\}?"?/join(" ", @args[(defined $1 && $1 > 0 ? $1 - 1 : 0) .. $#args])/ge;
|
|
234
|
+
$s =~ s/\$\{?([1-9])\}?/defined $args[$1 - 1] ? $args[$1 - 1] : ""/ge;
|
|
235
|
+
return $s;
|
|
236
|
+
}
|
|
237
|
+
sub bind_args {
|
|
238
|
+
my ($body, @args) = @_; my @t;
|
|
239
|
+
for my $x (@$body) {
|
|
240
|
+
my $y = $x->{subs} && @{ $x->{subs} } ? { %$x, subs => [map { bind_text($_, @args) } @{ $x->{subs} }] } : $x;
|
|
241
|
+
if ($y->{t} eq "w" && $y->{v} =~ /^\$\{?[@*](?::(\d+))?\}?$/) {
|
|
242
|
+
my $from = defined $1 && $1 > 0 ? $1 - 1 : 0;
|
|
243
|
+
push @t, { t => "w", v => $_, q => 1, subs => [] } for @args[$from .. $#args];
|
|
244
|
+
next;
|
|
245
|
+
}
|
|
246
|
+
if ($y->{t} eq "w" && $y->{v} =~ /^\$\{?([1-9])\}?$/) { push @t, { %$y, v => defined $args[$1 - 1] ? $args[$1 - 1] : "" }; next; }
|
|
247
|
+
push @t, $y;
|
|
248
|
+
}
|
|
249
|
+
return \@t;
|
|
250
|
+
}
|
|
251
|
+
sub command {
|
|
252
|
+
my ($c, $loop) = @_; my (@w, @docs); my ($target, $input) = ("", 0);
|
|
253
|
+
my @c = @$c; pop @c if @c > 1 && $c[-1]{t} eq "w" && !$c[-1]{q} && $c[-1]{v} eq "}";
|
|
254
|
+
for my $x (@c) {
|
|
255
|
+
if ($x->{t} eq "r") { $target = $x->{v}; next; }
|
|
256
|
+
if ($x->{t} eq "d") { push @docs, $x; next; }
|
|
257
|
+
parse($_, $loop) for @{ $x->{subs} || [] };
|
|
258
|
+
if ($target ne "") {
|
|
259
|
+
if ($target eq "<<<") { push @docs, { body => $x->{v}, subs => [] }; } elsif ($target =~ /^</) { $input = 1; }
|
|
260
|
+
$target = ""; next;
|
|
261
|
+
}
|
|
262
|
+
push @w, $x->{v};
|
|
263
|
+
}
|
|
264
|
+
return words(\@w, $loop, 0, \@docs, $input);
|
|
265
|
+
}
|
|
266
|
+
sub words {
|
|
267
|
+
my ($wr, $loop, $rep, $docs, $input) = @_; my @w = @$wr; my $nofn = 0;
|
|
268
|
+
my $run = sub { my ($dl) = @_; parse($_, $dl) for map { @{ $_->{subs} || [] } } @$docs; $docs = []; };
|
|
269
|
+
while (@w) {
|
|
270
|
+
my $k = $w[0]; my $in = $loop + ($rep ? 1 : 0);
|
|
271
|
+
if ($k =~ /^[A-Za-z_][A-Za-z0-9_]*=/) { shift @w; next; }
|
|
272
|
+
if ($k eq "while" || $k eq "until") { $loop++; shift @w; next; }
|
|
273
|
+
if ($k eq "for" || $k eq "select" || $k eq "foreach") { $run->($loop); return $loop + 1; }
|
|
274
|
+
if ($k eq "repeat" && (@w < 3 || $w[2] eq "do")) { $loop++; splice(@w, 0, @w < 3 ? scalar(@w) : 3); next; }
|
|
275
|
+
if ($k eq "done" || $k eq "end") { $loop-- if $loop > 0; shift @w; next; }
|
|
276
|
+
if ($k eq "-" || $k eq "noglob" || $k eq "nocorrect") { shift @w; next; }
|
|
277
|
+
$w[0] =~ s/^=(?=[A-Za-z])// and next;
|
|
278
|
+
if ($k =~ /^(if|then|else|elif|fi|do|\{|\}|!)$/) { shift @w; next; }
|
|
279
|
+
if ($k eq "env") {
|
|
280
|
+
shift @w;
|
|
281
|
+
while (@w && ($w[0] =~ /^-/ || $w[0] =~ /^[A-Za-z_][A-Za-z0-9_]*=/)) {
|
|
282
|
+
my $o = shift @w; my $str;
|
|
283
|
+
if ($o =~ /^--split-string=?(.*)$/s) { $str = $1; }
|
|
284
|
+
elsif ($o =~ /^-([A-Za-z]*?)S(.*)$/s) { my ($pre, $rest) = ($1, $2); $str = $rest unless $pre =~ /[uC]/; }
|
|
285
|
+
if (defined $str) {
|
|
286
|
+
$str = shift @w unless length $str;
|
|
287
|
+
$run->($loop); parse(join(" ", (defined $str ? $str : ""), @w), $in);
|
|
288
|
+
return $loop;
|
|
289
|
+
}
|
|
290
|
+
shift @w if @w && $o =~ /^(-u|--unset|-C|--chdir)$/;
|
|
291
|
+
}
|
|
292
|
+
next;
|
|
293
|
+
}
|
|
294
|
+
if ($k eq "flock") {
|
|
295
|
+
shift @w; my $file = 0;
|
|
296
|
+
while (@w) {
|
|
297
|
+
my $o = $w[0];
|
|
298
|
+
if ($o eq "-c" || $o eq "--command") { $run->($loop); parse(defined $w[1] ? $w[1] : "", $in); return $loop; }
|
|
299
|
+
if ($o =~ /^-/) { shift @w; shift @w if @w && $o =~ /^(-w|-E|--timeout|--conflict-exit-code)$/; next; }
|
|
300
|
+
last if $file; shift @w; $file = 1;
|
|
301
|
+
}
|
|
302
|
+
next;
|
|
303
|
+
}
|
|
304
|
+
if ($k eq "script") {
|
|
305
|
+
shift @w;
|
|
306
|
+
while (@w && $w[0] =~ /^-/) {
|
|
307
|
+
my $o = shift @w;
|
|
308
|
+
if ($o eq "-c" || $o eq "--command") { $run->($loop); parse(defined $w[0] ? $w[0] : "", $in); return $loop; }
|
|
309
|
+
shift @w if @w && $o =~ /^(-t|-F|-T|-I|-O|-B|-E|--timing|--log-in|--log-out|--log-io|--echo)$/;
|
|
310
|
+
}
|
|
311
|
+
shift @w; next;
|
|
312
|
+
}
|
|
313
|
+
if (exists $wrap{$k}) {
|
|
314
|
+
my $v = $wrap{$k}; shift @w;
|
|
315
|
+
if ($k eq "command" && @w && $w[0] =~ /^-[vV]$/) { $run->($loop); return $loop; }
|
|
316
|
+
while (@w && ($w[0] =~ /^-/ || $w[0] =~ /^[A-Za-z_][A-Za-z0-9_]*=/ || $w[0] =~ /^[0-9.]+[smhd]?$/)) {
|
|
317
|
+
my $o = shift @w; my $last = $o =~ /^-([A-Za-z]{2,})$/ ? "-" . substr($1, -1) : $o;
|
|
318
|
+
shift @w if @w && ($o =~ $v || $last =~ $v);
|
|
319
|
+
}
|
|
320
|
+
$rep = 1 if $repeats{$k};
|
|
321
|
+
$nofn = 1 if $k eq "command" || $k eq "builtin";
|
|
322
|
+
next;
|
|
323
|
+
}
|
|
324
|
+
last;
|
|
325
|
+
}
|
|
326
|
+
unless (@w) { $run->($loop); return $loop; }
|
|
327
|
+
my $in = $loop + ($rep ? 1 : 0);
|
|
328
|
+
(my $name = $w[0]) =~ s{.*/}{};
|
|
329
|
+
my $shell = $name =~ /^(bash|sh|zsh|dash|ksh)$/ || $name eq "source" || $name eq ".";
|
|
330
|
+
$run->($loop) unless $shell;
|
|
331
|
+
if (exists $fn{$w[0]} && !$nofn) {
|
|
332
|
+
if (++$calls > 200) { push @out, "opaque"; return $loop; }
|
|
333
|
+
unless ($busy{$w[0]}) { $busy{$w[0]} = 1; parse_tokens(bind_args($fn{$w[0]}, @w[1 .. $#w]), $in); delete $busy{$w[0]}; }
|
|
334
|
+
return $loop unless $w[0] eq "git";
|
|
335
|
+
}
|
|
336
|
+
if ($shell) {
|
|
337
|
+
my ($c, $s, $str, $file) = (0, 0);
|
|
338
|
+
if ($name eq "source" || $name eq ".") { $file = $w[1]; }
|
|
339
|
+
else {
|
|
340
|
+
for (my $j = 1; $j < @w; $j++) {
|
|
341
|
+
my $x = $w[$j];
|
|
342
|
+
if ($x eq "--") { if ($c) { $str = $w[$j + 1]; } elsif (!$s) { $file = $w[$j + 1]; } last; }
|
|
343
|
+
if ($x =~ /^[-+][oO]$/ || $x =~ /^--(rcfile|init-file)$/) { $j++; next; }
|
|
344
|
+
if ($x =~ /^[-+][A-Za-z]*$/ || $x =~ /^--/) { $c = 1 if $x =~ /^-[A-Za-z]*c/; $s = 1 if $x =~ /^-[A-Za-z]*s/; next; }
|
|
345
|
+
if ($c) { $str = $x; } elsif (!$s) { $file = $x; }
|
|
346
|
+
last;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
$file = undef if defined $file && $file =~ m{^(/dev/stdin|/dev/fd/0|-)$};
|
|
350
|
+
if (defined $str) { parse($str, $in); }
|
|
351
|
+
elsif (!defined $file) { if (@$docs) { parse($_->{body}, $in) for @$docs; } elsif (!$input) { push @out, "opaque"; } }
|
|
352
|
+
return $loop;
|
|
353
|
+
}
|
|
354
|
+
if ($name eq "eval") { parse(join(" ", @w[1 .. $#w]), $in) if @w > 1; return $loop; }
|
|
355
|
+
if ($name eq "find") {
|
|
356
|
+
for (my $j = 1; $j < @w; $j++) {
|
|
357
|
+
next unless $w[$j] =~ /^-(exec|execdir|ok|okdir)$/;
|
|
358
|
+
my @e; $j++;
|
|
359
|
+
push @e, $w[$j++] while $j < @w && $w[$j] ne ";" && $w[$j] ne "+";
|
|
360
|
+
words(\@e, $loop, 1, []);
|
|
361
|
+
}
|
|
362
|
+
return $loop;
|
|
363
|
+
}
|
|
364
|
+
if ($name eq "gh") {
|
|
365
|
+
my $g = 1; $g += ($w[$g] =~ /^(-R|--repo)$/ ? 2 : 1) while $g < @w && $w[$g] =~ /^-/;
|
|
366
|
+
push @out, "switch" if $g + 1 < @w && $w[$g] eq "pr" && $w[$g + 1] eq "checkout";
|
|
367
|
+
return $loop;
|
|
368
|
+
}
|
|
369
|
+
return $loop unless $name eq "git";
|
|
370
|
+
my $j = 1;
|
|
371
|
+
while ($j < @w && $w[$j] =~ /^-/) { my $o = $w[$j++]; $j++ if $o =~ /^(-c|-C|--git-dir|--work-tree|--namespace|--exec-path|--config-env|--attr-source)$/; }
|
|
372
|
+
return $loop unless $j < @w;
|
|
373
|
+
my $sub = $w[$j];
|
|
374
|
+
if ($sub eq "checkout" || $sub eq "switch") {
|
|
375
|
+
my $letters = $sub eq "checkout" ? "bB" : "cC";
|
|
376
|
+
my @a = @w[$j + 1 .. $#w];
|
|
377
|
+
my ($new, $orphan, $paths, @pos) = (0, 0, 0);
|
|
378
|
+
for (my $k = 0; $k < @a; $k++) {
|
|
379
|
+
my $x = $a[$k];
|
|
380
|
+
if ($x eq "--") { $paths = 1 if $k + 1 < @a; last; }
|
|
381
|
+
if ($x eq "-") { push @pos, $x; next; }
|
|
382
|
+
if ($sub eq "checkout" && $x =~ /^--(patch|ours|theirs|pathspec-from-file)(=.*)?$/) {
|
|
383
|
+
$paths = 1; $k++ if $1 eq "pathspec-from-file" && !defined $2; next;
|
|
384
|
+
}
|
|
385
|
+
if ($x =~ /^--(orphan|create|force-create)(=.*)?$/) {
|
|
386
|
+
next if $sub eq "checkout" && $1 ne "orphan";
|
|
387
|
+
$new = 1; $orphan = 1 if $1 eq "orphan"; $k++ unless defined $2; next;
|
|
388
|
+
}
|
|
389
|
+
if ($x eq "--conflict") { $k++; next; }
|
|
390
|
+
if ($x =~ /^-([A-Za-z].*)$/s && $x !~ /^--/) {
|
|
391
|
+
my $c = $1;
|
|
392
|
+
$paths = 1 if $sub eq "checkout" && $c =~ /^[^$letters]*p/;
|
|
393
|
+
if ($c =~ /^[A-Za-z]*?[$letters](.*)$/s) { $new = 1; $k++ unless length $1; }
|
|
394
|
+
next;
|
|
395
|
+
}
|
|
396
|
+
next if $x =~ /^-/;
|
|
397
|
+
push @pos, $x;
|
|
398
|
+
}
|
|
399
|
+
# A start point is the first word after the new name; `.` and a second word are paths, and
|
|
400
|
+
# git refuses the whole call then. Without a new name, checkout reads the words after the
|
|
401
|
+
# first one as paths: the files are restored from it, and the branch stays.
|
|
402
|
+
my $tip = qr/^(?:HEAD|head|\@|\@\{HEAD\}|HEAD\@\{0\}|\@\{0\}|\.)$/;
|
|
403
|
+
if ($new) {
|
|
404
|
+
push @out, "switch" if (@pos == 1 && $pos[0] !~ $tip) || ($orphan && $sub eq "switch");
|
|
405
|
+
}
|
|
406
|
+
elsif (!$paths && @pos && $pos[0] ne "." && !($sub eq "checkout" && @pos > 1)) { push @out, "switch"; }
|
|
407
|
+
return $loop;
|
|
408
|
+
}
|
|
409
|
+
return $loop unless $sub eq "push";
|
|
410
|
+
my ($dry, $several, $delete, $repo, @pos) = (0, 0, 0, 0);
|
|
411
|
+
my @a = @w[$j + 1 .. $#w];
|
|
412
|
+
for (my $k = 0; $k < @a; $k++) {
|
|
413
|
+
my $x = $a[$k];
|
|
414
|
+
if ($x eq "--dry-run") { $dry = 1; next; }
|
|
415
|
+
if ($x =~ /^--(all|mirror|branches)$/) { $several = 1; next; }
|
|
416
|
+
if ($x eq "--delete") { $delete = 1; next; }
|
|
417
|
+
if ($x eq "--repo") { $repo = 1; $k++; next; }
|
|
418
|
+
if ($x =~ /^--repo=/) { $repo = 1; next; }
|
|
419
|
+
if ($x =~ /^(--push-option|--receive-pack|--exec)$/) { $k++; next; }
|
|
420
|
+
if ($x =~ /^-[A-Za-z]+$/) { $dry = 1 if $x =~ /n/; $delete = 1 if $x =~ /d/; $k++ if $x =~ /o$/; next; }
|
|
421
|
+
next if $x =~ /^-/;
|
|
422
|
+
push @pos, $x;
|
|
423
|
+
}
|
|
424
|
+
shift @pos unless $repo;
|
|
425
|
+
my @refs = $delete ? () : grep { !/^\+?:/ } @pos;
|
|
426
|
+
$several = 1 if @refs > 1 || grep { /\*/ || /\{[^}]*(,|\.\.)[^}]*\}/ } @refs;
|
|
427
|
+
push @out, join(" ", ($in > 0 ? "loop" : "flat"), ($several ? "several" : "one"), ($dry ? "dry" : "real"));
|
|
428
|
+
return $loop;
|
|
429
|
+
}
|
|
430
|
+
parse($text, 0);
|
|
431
|
+
print "$_\n" for @out;
|
|
432
|
+
' 2>/dev/null
|
|
433
|
+
}
|
|
@@ -51,11 +51,19 @@ for profile in "$rt_hooks_dir/../rt-kit/defaults/project.sh" "$rt_hooks_dir/../d
|
|
|
51
51
|
[ -f "$profile" ] && . "$profile" 2>/dev/null
|
|
52
52
|
done
|
|
53
53
|
|
|
54
|
-
# The rerun call: the rerun word as a separate word next to the word for a run.
|
|
54
|
+
# The rerun call: the rerun word as a separate word next to the word for a run. The GitLab client
|
|
55
|
+
# retries a job instead — `glab ci retry <id>` — and reads its log by `glab ci trace <id>`; a guard
|
|
56
|
+
# waiting only for `run rerun` let such a retry through unread.
|
|
55
57
|
host_cli="${RT_HOST_CLI:-gh}"
|
|
56
|
-
|
|
57
|
-
printf '%s' "$cmd" | grep -qE
|
|
58
|
-
printf '%s' "$cmd" | grep -qE
|
|
58
|
+
retry_re='(^|[[:space:]])ci[[:space:]]+retry([[:space:]]|$)'
|
|
59
|
+
printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}(${host_cli}|glab)([[:space:]]|\$)" || exit 0
|
|
60
|
+
if printf '%s' "$cmd" | grep -qE "$retry_re"; then
|
|
61
|
+
log_cmd="glab ci trace"
|
|
62
|
+
else
|
|
63
|
+
printf '%s' "$cmd" | grep -qE '(^|[[:space:]])(run|workflow)([[:space:]]|$)' || exit 0
|
|
64
|
+
printf '%s' "$cmd" | grep -qE '(^|[[:space:]])rerun([[:space:]]|$)' || exit 0
|
|
65
|
+
log_cmd="${host_cli} run view"
|
|
66
|
+
fi
|
|
59
67
|
|
|
60
68
|
# The run number. Not named — the guard stays silent: there is nothing to judge.
|
|
61
69
|
run_id="$(printf '%s' "$cmd" | grep -oE '(^|[[:space:]])[0-9]{6,}([[:space:]]|$)' | tr -d ' ' | head -1)"
|
|
@@ -70,13 +78,13 @@ transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/nu
|
|
|
70
78
|
seen="$(jq -s -r --arg id "$run_id" '
|
|
71
79
|
[.[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "tool_use")
|
|
72
80
|
| ((.input.command // "") | tostring)] as $used
|
|
73
|
-
| (($used | join("\n")) | test("run[[:space:]]+view[^\\n]*" + $id + "|" + $id + "[^\\n]*--log")) as $read
|
|
81
|
+
| (($used | join("\n")) | test("run[[:space:]]+view[^\\n]*" + $id + "|" + $id + "[^\\n]*--log|ci[[:space:]]+(trace|view)[^\\n]*" + $id)) as $read
|
|
74
82
|
| if $read then "read" else "not-read" end
|
|
75
83
|
' "$transcript" 2>/dev/null)"
|
|
76
84
|
|
|
77
85
|
[ "$seen" = "read" ] && exit 0
|
|
78
86
|
|
|
79
|
-
reason="BLOCKED by rerun-guard: a rerun of the run ${run_id} without its output read. Red on a run comes in two kinds, and in the list they look the same: a hosting refusal on the preparation step is cured by a rerun, a defect of the branch is not cured by it at all, and the circle repeats until the output is opened. Read the output of this run — ${
|
|
87
|
+
reason="BLOCKED by rerun-guard: a rerun of the run ${run_id} without its output read. Red on a run comes in two kinds, and in the list they look the same: a hosting refusal on the preparation step is cured by a rerun, a defect of the branch is not cured by it at all, and the circle repeats until the output is opened. Read the output of this run — ${log_cmd} ${run_id}$([ "$log_cmd" = "glab ci trace" ] || printf ' --log-failed') — and repeat the call. The guard judges the order, not the cause of the fall: what is written in the output you judge yourself."
|
|
80
88
|
|
|
81
89
|
# The shared deny tail: the two lawful moves and the lawful form of bypass, if the refusal has one.
|
|
82
90
|
# The file may not be laid out — then there is no tail, and the refusal reason stays as it is.
|
|
@@ -179,7 +179,7 @@ next_step=""
|
|
|
179
179
|
command -v rt_te_verdict >/dev/null 2>&1 || exit 0
|
|
180
180
|
rt_te_verdict
|
|
181
181
|
|
|
182
|
-
[ -z "$verdict" ] && exit 0
|
|
182
|
+
[ -z "$verdict" ] && exit 0 # also a turn woken while an own background task runs, SC-AK-1247
|
|
183
183
|
|
|
184
184
|
# Every sign of the verdict becomes a variable of its own name; the commands go apart, they are text.
|
|
185
185
|
eval "$(printf '%s' "$verdict" | jq -r 'del(.ran) | to_entries[] | "\(.key)=\(.value | tostring | @sh)"' 2>/dev/null)"
|
|
@@ -282,7 +282,7 @@ fi
|
|
|
282
282
|
# state is not allowed.
|
|
283
283
|
case "$state" in
|
|
284
284
|
этапы-кончились | разбор-кончился)
|
|
285
|
-
if ! printf '%s' "$commands" | grep -qE
|
|
285
|
+
if ! printf '%s' "$commands" | grep -qE "$handover_re"; then
|
|
286
286
|
if [ "$state" = "этапы-кончились" ]; then
|
|
287
287
|
action="merge the agreement, bring the texts up to what was done and run the suite"
|
|
288
288
|
else
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
# of the two changes the tree, and to the pattern they were indistinguishable from writing to a
|
|
18
18
|
# working file: it saw the arrow itself and did not ask where it led. What stays as the sign is an
|
|
19
19
|
# edit of a file by the editing tool and the commands listed here.
|
|
20
|
-
work_re='git (add|commit|push|checkout|merge|rm)|npm run|pnpm (run|exec)|nx (build|test|run)|gh (pr|issue|api|run)|task:(new|move)|mkdir|cp |mv |rm |sed -i|tee '
|
|
20
|
+
work_re='git (add|commit|push|checkout|merge|rm)|npm run|pnpm (run|exec)|nx (build|test|run)|gh (pr|issue|api|run)|glab (mr|ci|issue|api)|task:(new|move)|mkdir|cp |mv |rm |sed -i|tee '
|
|
21
21
|
|
|
22
22
|
# Exploration. The same words as in the work pattern, but the subcommand is a reading one:
|
|
23
23
|
# switching a branch, pulling, looking through the history, reading PRs and runs. The work pattern
|
|
@@ -29,7 +29,7 @@ work_re='git (add|commit|push|checkout|merge|rm)|npm run|pnpm (run|exec)|nx (bui
|
|
|
29
29
|
# Exploration looks like work better than anything else: it has commands, numbers and exact answers.
|
|
30
30
|
# That is what makes it dangerous — a turn stuffed with it reads as full both to the owner and to
|
|
31
31
|
# the session itself.
|
|
32
|
-
read_re='^[[:space:]]*(([^[:space:]]*/)?git[[:space:]]+(show|log|ls-tree|ls-files|ls-remote|diff|status|branch|tag|rev-parse|remote|describe|blame|fetch|pull|(checkout|switch)(?!([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-[bc][[:space:]]))|([^[:space:]]*/)?gh[[:space:]]+(pr|issue|run|repo)[[:space:]]+(list|view|status|checks|diff|download|logs))([[:space:]]|$)'
|
|
32
|
+
read_re='^[[:space:]]*(([^[:space:]]*/)?git[[:space:]]+(show|log|ls-tree|ls-files|ls-remote|diff|status|branch|tag|rev-parse|remote|describe|blame|fetch|pull|(checkout|switch)(?!([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-[bc][[:space:]]))|([^[:space:]]*/)?gh[[:space:]]+(pr|issue|run|repo)[[:space:]]+(list|view|status|checks|diff|download|logs)|([^[:space:]]*/)?glab[[:space:]]+(mr|issue|ci|repo)[[:space:]]+(list|view|status|diff|trace|get))([[:space:]]|$)'
|
|
33
33
|
|
|
34
34
|
# The parts of a compound command are judged one by one: a turn gathers reading and work into one
|
|
35
35
|
# line through `&&`, and judging it whole would release exploration on the very first changing part.
|
|
@@ -66,7 +66,8 @@ standing_work_re='работай[^.]{0,40}(без остановок|без па
|
|
|
66
66
|
|
|
67
67
|
# Handing work over and starting the next. The rule calls handed-over work a lawful end of a turn —
|
|
68
68
|
# but on a condition: the next one is started, and an ACTION has been done on it, not spoken.
|
|
69
|
-
|
|
69
|
+
# The GitLab client opens a merge request — the same handing over.
|
|
70
|
+
handover_re='gh[[:space:]]+pr[[:space:]]+create|glab[^|;&]*mr[[:space:]]+create'
|
|
70
71
|
started_re='task:new|task:move|board\.mjs[[:space:]]+move|git[[:space:]]+checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|git[[:space:]]+switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c'
|
|
71
72
|
|
|
72
73
|
# How many steps of the plan are not done yet. The progress mirrors the steps of the plan with a
|
|
@@ -42,6 +42,23 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
|
|
|
42
42
|
# depend on it is done while it runs — the turn does not end on the launch itself.
|
|
43
43
|
| (($last_name | test("^(Agent|Task)$")) or (($last_name == "Bash") and ($last | test("&[[:space:]]*$")))) as $launched_last
|
|
44
44
|
| (($last_name == "Bash") and ($last | test($wait))) as $waited
|
|
45
|
+
# A turn woken by a notification about an own background task. The notification is written under
|
|
46
|
+
# the role of the owner, and the turn it opens holds nothing to do while another own task still
|
|
47
|
+
# runs. The launches are read over the whole window; a launch ends with a notification naming its
|
|
48
|
+
# call, whether it woke a turn or arrived as an attachment in the middle of one. Such a turn
|
|
49
|
+
# gets no verdict at all, and the guard lets an empty verdict through: the guard has no room.
|
|
50
|
+
| (if $i == null then false else
|
|
51
|
+
((.[$i].origin.kind // "") == "task-notification")
|
|
52
|
+
or ((.[$i].message.content // "") | if type == "string" then test("^[[:space:]]*<task-notification>") else false end)
|
|
53
|
+
end) as $woken
|
|
54
|
+
| ([.[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "tool_use")
|
|
55
|
+
| select(((.name // "") | test("^(Agent|Task)$")) or (((.name // "") == "Bash") and (.input.run_in_background // false)))
|
|
56
|
+
| (.id // empty)]) as $launches
|
|
57
|
+
| ([.[] | ((.message.content // "") | if type == "string" then . else "" end), (.attachment.prompt // "")
|
|
58
|
+
| select(test("<task-notification>"))
|
|
59
|
+
| select(test("<status>(completed|failed|killed|stopped)</status>"))
|
|
60
|
+
| (capture("<tool-use-id>(?<id>[^<]+)</tool-use-id>").id // empty)]) as $finished
|
|
61
|
+
| ($woken and (($uses | length) == 0) and (($launches - $finished) | length) > 0) as $woken_waiting
|
|
45
62
|
# Handing the work over: the tail of the turn after the PR was opened. Everything before it was
|
|
46
63
|
# done on the task handed in and says nothing about the next one.
|
|
47
64
|
| ([$uses[] | select((.name // "") == "Bash") | (.input.command // "")]) as $cmds
|
|
@@ -127,6 +144,6 @@ verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re
|
|
|
127
144
|
or (((.name // "") == "Bash") and ([(.input.command // "") | splits($part)] | map(test($work) and (test($read) | not) and (test("^[[:space:]]*([^[:space:]]*/)?git[[:space:]]+(add|commit|push)") | not)) | any))
|
|
128
145
|
) | any) as $after_progress
|
|
129
146
|
| (($last_name == "Bash") and ($last | test($started)) and ($handed_over | not)) as $only_took
|
|
130
|
-
| { promised: $promised, only_took: $only_took, asked: $asked, handed_by_hand: ($handed and (($asked or $denied or $told_stop) | not)), standing_work: $standing_work, worked: ($edited or $ran_work), released: ($asked or $denied or $handed or $told_stop), waited: $waited, handed_over: $handed_over, started_next: $started_next, ended_working: $ended_working, asked_in_prose: $asked_in_prose, awaits_word: $awaits_word, progress_edited: $progress_edited, after_progress: $after_progress, launched_last: $launched_last, ran: $ran, unpushed_named: $unpushed_named }
|
|
147
|
+
| if $woken_waiting then empty else { promised: $promised, only_took: $only_took, asked: $asked, handed_by_hand: ($handed and (($asked or $denied or $told_stop) | not)), standing_work: $standing_work, worked: ($edited or $ran_work), released: ($asked or $denied or $handed or $told_stop), waited: $waited, handed_over: $handed_over, started_next: $started_next, ended_working: $ended_working, asked_in_prose: $asked_in_prose, awaits_word: $awaits_word, progress_edited: $progress_edited, after_progress: $after_progress, launched_last: $launched_last, ran: $ran, unpushed_named: $unpushed_named } end
|
|
131
148
|
' 2>/dev/null)"
|
|
132
149
|
}
|
|
@@ -84,7 +84,8 @@ taken_path_re='/tasks/'
|
|
|
84
84
|
# Lifting the draft is the obvious case; reading the run is the one where there is nothing to lift
|
|
85
85
|
# yet, but the executor looked instead of saying "waiting". Two ready PRs stood as drafts precisely
|
|
86
86
|
# because the next task was taken instead of this, not on top of it.
|
|
87
|
-
|
|
87
|
+
# The GitLab client lifts the draft by an update with a flag and reads the pipeline by `ci`.
|
|
88
|
+
ready_re='pr[[:space:]]+ready|run[[:space:]]+(list|view|watch)|pr[[:space:]]+checks|check-runs|check:board|board\.mjs|glab[^|;&]*mr[[:space:]]+update[^|;&]*(--ready|[[:space:]]-r)([[:space:]]|$)|glab[^|;&]*ci[[:space:]]+(status|view|list|trace|get)'
|
|
88
89
|
|
|
89
90
|
# A run started or rerun in the turn. Its outcome does not call by itself: a rerun went through in
|
|
90
91
|
# one line between other things, its state was read once — «queued» — and the turn ended by a lawful
|
|
@@ -64,6 +64,27 @@ rt_write_targets() {
|
|
|
64
64
|
}
|
|
65
65
|
')"
|
|
66
66
|
|
|
67
|
+
# An arrow inside quotes is text of the command, not a redirection: `echo "a->b"` and the code
|
|
68
|
+
# of `node -e "[1].map(x => x)"` read as writes into `b` and `x)` and were refused as edits.
|
|
69
|
+
# The quote state is kept per line; a backslash outside single quotes escapes the next sign.
|
|
70
|
+
rt_wt_shell="$(printf '%s\n' "$rt_wt_shell" | awk -v sq="'" '
|
|
71
|
+
function drop_quoted_arrows(s, out, i, c, q, n) {
|
|
72
|
+
out = ""; q = ""; n = length(s)
|
|
73
|
+
for (i = 1; i <= n; i++) {
|
|
74
|
+
c = substr(s, i, 1)
|
|
75
|
+
if (c == "\\" && q != sq && i < n) { out = out c substr(s, i + 1, 1); i++; continue }
|
|
76
|
+
if (q != "") {
|
|
77
|
+
if (c == q) { q = "" } else if (c == ">") { continue }
|
|
78
|
+
} else if (c == "\"" || c == sq || c == "`") {
|
|
79
|
+
q = c
|
|
80
|
+
}
|
|
81
|
+
out = out c
|
|
82
|
+
}
|
|
83
|
+
return out
|
|
84
|
+
}
|
|
85
|
+
{ print drop_quoted_arrows($0) }
|
|
86
|
+
')"
|
|
87
|
+
|
|
67
88
|
{
|
|
68
89
|
printf '%s' "$rt_wt_shell" \
|
|
69
90
|
| tr "\"'\`" ' ' \
|
|
@@ -169,6 +169,17 @@ A name without a number (`feat/…`, `fix/…`) is legitimate while the branch l
|
|
|
169
169
|
trial and an analysis. No PR opens from it: an edit that reaches the main branch starts with a
|
|
170
170
|
task.
|
|
171
171
|
|
|
172
|
+
**A local branch that continues an open PR under another name is tied to the PR's branch before
|
|
173
|
+
the first push.** Otherwise it has no upstream: the push goes nowhere by itself, and the turn-exit
|
|
174
|
+
guard counts every commit as not handed over while all of them already stand in the PR. The tie
|
|
175
|
+
and the push name the PR's branch:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
git branch --set-upstream-to=origin/<ветка PR>
|
|
179
|
+
git push origin HEAD:<ветка PR>
|
|
180
|
+
git rev-list --count @{u}..HEAD # 0 — everything is on the host
|
|
181
|
+
```
|
|
182
|
+
|
|
172
183
|
## The task column moves together with the work
|
|
173
184
|
|
|
174
185
|
Branch created — the task is no longer in `📋 Backlog` but in progress. PR opened — it awaits
|