@rt-tools/agent-kit 0.32.0 → 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/board.github.mjs +27 -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/checks/tree-assignment.mjs +11 -3
- 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-merged.sh +65 -0
- package/assets/hooks/git-guard-delivery-pipeline.sh +99 -0
- package/assets/hooks/git-guard-delivery.sh +22 -8
- 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/git-guard-tree-assignment.sh +1 -1
- package/assets/hooks/grill-gate-options.sh +50 -0
- package/assets/hooks/grill-gate.sh +9 -1
- 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/dependencies-upgrade.md +5 -1
- package/assets/patterns/git-workflow-commit.github.md +14 -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/reuse-first-extend.md +5 -0
- package/assets/patterns/task-flow-close.md +27 -16
- package/assets/patterns/task-flow-start.md +5 -4
- package/assets/pitfalls/task-flow.md +4 -0
- package/assets/rules/browser-verification.md +4 -0
- package/assets/rules/dependencies.md +3 -1
- 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/reuse-first.md +3 -0
- package/assets/rules/task-flow.md +21 -16
- package/assets/rules/testing.md +5 -0
- 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,150 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The gate set before a push, one way for both who run it. NOT a guard: it has no `rt-hook:`
|
|
3
|
+
# declaration and hooks into no agent event. The session guard of the push and the git hook
|
|
4
|
+
# `pre-push` source it and call its functions.
|
|
5
|
+
#
|
|
6
|
+
# Two copies of the same loop drifted apart in their first week: the hook started the heavy checks
|
|
7
|
+
# after a red one, said nothing about a skipped check and wrote the mark of green when nothing had
|
|
8
|
+
# been checked at all. Here lives the single one.
|
|
9
|
+
#
|
|
10
|
+
# rt_push_set_profile <hooks dir> <tree root> — the package default and the tree override
|
|
11
|
+
# rt_push_set_base — the main branch of the remote, or empty
|
|
12
|
+
# rt_push_set_run <base> — every line of `rt_push_checks <base>`
|
|
13
|
+
# rt_push_mark_path / rt_push_mark_covers <commit> / rt_push_mark_write — the mark of green
|
|
14
|
+
#
|
|
15
|
+
# What `rt_push_set_run` found is left in the variables `rt_push_set_failed`, `_output`, `_skipped`,
|
|
16
|
+
# `_held` and `_ahead` (one check per line) and in the counters `rt_push_set_ran` and
|
|
17
|
+
# `rt_push_set_passed`.
|
|
18
|
+
|
|
19
|
+
# The tree profile: first the package default, over it the project override. A function declared in
|
|
20
|
+
# the override replaces the default whole and may call it back by the `_default` suffix. The root is
|
|
21
|
+
# exported, because the profile functions find the tree files by it: a root inherited from another
|
|
22
|
+
# session reads that session's tree, and the set comes out narrower without a word.
|
|
23
|
+
rt_push_set_profile() {
|
|
24
|
+
local hooks_dir="$1" root="$2" profile
|
|
25
|
+
export CLAUDE_PROJECT_DIR="$root"
|
|
26
|
+
for profile in "$hooks_dir/../rt-kit/defaults/project.sh" "$hooks_dir/../defaults/project.sh" \
|
|
27
|
+
"$root/.claude/rt-kit/defaults/project.sh" "$root/.claude/rt-kit/project.sh"; do
|
|
28
|
+
# shellcheck disable=SC1090
|
|
29
|
+
[ -f "$profile" ] && . "$profile" 2>/dev/null
|
|
30
|
+
done
|
|
31
|
+
# The base of a stacked branch and the marks of a green run. No helper — the base is the main
|
|
32
|
+
# branch, no mark is read and none is written: the set runs whole.
|
|
33
|
+
# shellcheck disable=SC1091
|
|
34
|
+
[ -f "$hooks_dir/git-guard-push-marks.sh" ] && . "$hooks_dir/git-guard-push-marks.sh" 2>/dev/null
|
|
35
|
+
command -v rt_push_mark_has >/dev/null 2>&1 || rt_push_mark_has() { return 1; }
|
|
36
|
+
command -v rt_push_mark_put >/dev/null 2>&1 || rt_push_mark_put() { return 0; }
|
|
37
|
+
command -v rt_push_mark_clean >/dev/null 2>&1 || rt_push_mark_clean() { return 1; }
|
|
38
|
+
command -v rt_push_mark_key >/dev/null 2>&1 || rt_push_mark_key() { return 1; }
|
|
39
|
+
command -v rt_push_heavy_ahead >/dev/null 2>&1 || rt_push_heavy_ahead() { return 1; }
|
|
40
|
+
return 0
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
rt_push_set_base() {
|
|
44
|
+
local main_branch="${RT_MAIN_BRANCH:-main}"
|
|
45
|
+
if command -v rt_push_base >/dev/null 2>&1; then
|
|
46
|
+
rt_push_base "$main_branch"
|
|
47
|
+
return 0
|
|
48
|
+
fi
|
|
49
|
+
if git fetch --quiet origin "$main_branch" 2>/dev/null && git rev-parse --verify --quiet "origin/$main_branch" >/dev/null 2>&1; then
|
|
50
|
+
printf 'origin/%s' "$main_branch"
|
|
51
|
+
fi
|
|
52
|
+
return 0
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Every red among the light checks is named by one refusal. After the first red a heavy check is not
|
|
56
|
+
# started: the push is refused anyway, and its minutes buy nothing.
|
|
57
|
+
#
|
|
58
|
+
# The code by which a check declares that there was nothing to look at does not refuse the push, and
|
|
59
|
+
# it is counted apart from a passed one. A skip code of 0 or 1 is no skip code: 1 is the exit of any
|
|
60
|
+
# failure, and every red check would read as skipped.
|
|
61
|
+
#
|
|
62
|
+
# A check green on this very tree against this very base is not run again. A caller under the hook
|
|
63
|
+
# limit sets `rt_push_set_ask_ahead=1`: in a tree that runs its heavy steps ahead such a step is then
|
|
64
|
+
# named in `rt_push_set_ahead` instead of being started. The git hook has no such limit, leaves the
|
|
65
|
+
# variable empty and runs the step itself.
|
|
66
|
+
rt_push_set_run() {
|
|
67
|
+
local base="$1" check out status key_before skip_code="${RT_SKIP_CODE:-7}"
|
|
68
|
+
case "$skip_code" in '' | 0 | 1 | *[!0-9]*) skip_code=7 ;; esac
|
|
69
|
+
command -v rt_push_check_heavy >/dev/null 2>&1 || rt_push_check_heavy() { return 1; }
|
|
70
|
+
|
|
71
|
+
rt_push_set_failed=""
|
|
72
|
+
rt_push_set_output=""
|
|
73
|
+
rt_push_set_skipped=""
|
|
74
|
+
rt_push_set_held=""
|
|
75
|
+
rt_push_set_ahead=""
|
|
76
|
+
rt_push_set_ran=0
|
|
77
|
+
rt_push_set_passed=0
|
|
78
|
+
while IFS= read -r check; do
|
|
79
|
+
[ -z "$check" ] && continue
|
|
80
|
+
if rt_push_mark_has "$check" "$base"; then
|
|
81
|
+
rt_push_set_ran=$((rt_push_set_ran + 1))
|
|
82
|
+
rt_push_set_passed=$((rt_push_set_passed + 1))
|
|
83
|
+
continue
|
|
84
|
+
fi
|
|
85
|
+
if [ "${rt_push_set_ask_ahead:-}" = 1 ] && rt_push_heavy_ahead && rt_push_check_heavy "$check"; then
|
|
86
|
+
rt_push_set_ahead="${rt_push_set_ahead}${rt_push_set_ahead:+
|
|
87
|
+
}${check}"
|
|
88
|
+
continue
|
|
89
|
+
fi
|
|
90
|
+
if [ -n "$rt_push_set_failed" ] && rt_push_check_heavy "$check"; then
|
|
91
|
+
rt_push_set_held="${rt_push_set_held}${rt_push_set_held:+
|
|
92
|
+
}${check}"
|
|
93
|
+
continue
|
|
94
|
+
fi
|
|
95
|
+
rt_push_set_ran=$((rt_push_set_ran + 1))
|
|
96
|
+
key_before=""
|
|
97
|
+
rt_push_mark_clean && key_before="$(rt_push_mark_key "$check" "$base" 2>/dev/null)"
|
|
98
|
+
out="$(eval "$check" 2>&1 </dev/null)"
|
|
99
|
+
status=$?
|
|
100
|
+
if [ "$status" -eq 0 ]; then
|
|
101
|
+
rt_push_set_passed=$((rt_push_set_passed + 1))
|
|
102
|
+
rt_push_mark_put "$check" "$base" "$key_before"
|
|
103
|
+
continue
|
|
104
|
+
fi
|
|
105
|
+
if [ "$status" -eq "$skip_code" ]; then
|
|
106
|
+
rt_push_set_skipped="${rt_push_set_skipped}${rt_push_set_skipped:+
|
|
107
|
+
}${check}"
|
|
108
|
+
continue
|
|
109
|
+
fi
|
|
110
|
+
rt_push_set_failed="${rt_push_set_failed}${rt_push_set_failed:+
|
|
111
|
+
}${check}"
|
|
112
|
+
rt_push_set_output="${rt_push_set_output}${rt_push_set_output:+
|
|
113
|
+
|
|
114
|
+
}── ${check}
|
|
115
|
+
$(printf '%s' "$out" | tail -n 25)"
|
|
116
|
+
done <<EOF
|
|
117
|
+
$(rt_push_checks "$base")
|
|
118
|
+
EOF
|
|
119
|
+
return 0
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# The mark of green: the commit a green set judged, one line. It lies in the shared git directory, not
|
|
123
|
+
# in that of a working copy: a push from a session through `git -C` into a second copy would
|
|
124
|
+
# otherwise not see the mark the guard just wrote and run the set a second time.
|
|
125
|
+
rt_push_mark_path() {
|
|
126
|
+
local common
|
|
127
|
+
common="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" || return 0
|
|
128
|
+
[ -n "$common" ] && printf '%s/rt-kit-push-green' "$common"
|
|
129
|
+
return 0
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
rt_push_mark_covers() {
|
|
133
|
+
local commit="$1" mark
|
|
134
|
+
mark="$(rt_push_mark_path)"
|
|
135
|
+
[ -n "$commit" ] && [ -n "$mark" ] && [ -f "$mark" ] && [ "$(head -n 1 "$mark" 2>/dev/null)" = "$commit" ]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# The mark is written only for a set that judged the commit itself. A set where every check was
|
|
139
|
+
# skipped judged nothing. A working copy with uncommitted edits to tracked files was judged
|
|
140
|
+
# together with them, so the commit alone was never judged. Files outside the history do not count:
|
|
141
|
+
# a working copy keeps folders of other tasks, and the mark would never be written.
|
|
142
|
+
rt_push_mark_write() {
|
|
143
|
+
local mark tip
|
|
144
|
+
[ "${rt_push_set_passed:-0}" -gt 0 ] || return 0
|
|
145
|
+
[ -z "$(git status --porcelain --untracked-files=no 2>/dev/null)" ] || return 0
|
|
146
|
+
mark="$(rt_push_mark_path)"
|
|
147
|
+
tip="$(git rev-parse --verify --quiet HEAD 2>/dev/null)"
|
|
148
|
+
[ -n "$mark" ] && [ -n "$tip" ] && printf '%s\n' "$tip" >"$mark" 2>/dev/null
|
|
149
|
+
return 0
|
|
150
|
+
}
|
|
@@ -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
|