@rt-tools/agent-kit 0.24.0 → 0.27.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/assets/agents/business-analyst.md +51 -50
- package/assets/agents/cargo-writer.md +54 -0
- package/assets/agents/conscience.md +37 -35
- package/assets/agents/project-manager.md +49 -48
- package/assets/agents/prose-editor.md +31 -29
- package/assets/agents/qa-engineer.md +50 -48
- package/assets/agents/rules-reviewer.md +63 -58
- package/assets/agents/skill-curator.md +83 -78
- package/assets/agents/spec-critic.md +34 -29
- package/assets/agents/spec-writer.md +35 -32
- package/assets/agents/strict-teacher.md +39 -37
- package/assets/checks/archive-age.mjs +48 -28
- package/assets/checks/archive-prune.mjs +16 -14
- package/assets/checks/board-epic-link.github.mjs +29 -0
- package/assets/checks/board-epics.github.mjs +286 -49
- package/assets/checks/board-folders.mjs +61 -0
- package/assets/checks/board-gh.github.mjs +35 -26
- package/assets/checks/board-long-work.github.mjs +29 -25
- package/assets/checks/board-paths.github.mjs +21 -16
- package/assets/checks/board-pull-state.github.mjs +168 -0
- package/assets/checks/board-runs.github.mjs +45 -43
- package/assets/checks/board-task-dirs.github.mjs +98 -0
- package/assets/checks/board-titles.github.mjs +19 -17
- package/assets/checks/board.github.mjs +133 -194
- package/assets/checks/check-archive-age.mjs +23 -19
- package/assets/checks/check-board.github.mjs +131 -263
- package/assets/checks/check-descriptions.mjs +30 -29
- package/assets/checks/check-doc-paths.mjs +91 -88
- package/assets/checks/check-dupes.mjs +84 -80
- package/assets/checks/check-file-size.mjs +74 -71
- package/assets/checks/check-glossary.mjs +47 -37
- package/assets/checks/check-hook-scope.mjs +30 -27
- package/assets/checks/check-lib-layers.mjs +22 -21
- package/assets/checks/check-profile-drift.mjs +48 -43
- package/assets/checks/check-prose-style.mjs +138 -39
- package/assets/checks/check-push-gate.mjs +53 -50
- package/assets/checks/check-reuse.mjs +50 -40
- package/assets/checks/check-schema-drift.mjs +104 -84
- package/assets/checks/check-specs.mjs +155 -134
- package/assets/checks/check-state-next.mjs +66 -52
- package/assets/checks/check-states.mjs +32 -30
- package/assets/checks/check-styles.mjs +52 -51
- package/assets/checks/check-turn-map.mjs +54 -46
- package/assets/checks/epic-table.github.mjs +268 -0
- package/assets/checks/lib-boundaries.mjs +32 -30
- package/assets/checks/lib-common.mjs +30 -29
- package/assets/checks/lib-domains.mjs +34 -34
- package/assets/checks/lib-manifests.mjs +17 -15
- package/assets/checks/lib-reexports.mjs +18 -18
- package/assets/checks/rt-kit-checks.config.mjs +187 -142
- package/assets/checks/signals.mjs +43 -39
- package/assets/checks/spec-anchors.mjs +114 -87
- package/assets/checks/spec-common.mjs +128 -84
- package/assets/checks/spec-contract.mjs +30 -30
- package/assets/checks/spec-proposed.mjs +27 -24
- package/assets/checks/spec-scenarios.mjs +51 -28
- package/assets/checks/specs-for.mjs +214 -0
- package/assets/checks/task-new.github.mjs +315 -61
- package/assets/commands/feedback.md +65 -59
- package/assets/commands/next-session.md +64 -57
- package/assets/commands/night.md +115 -0
- package/assets/commands/skill-curator.md +83 -79
- package/assets/defaults/gate-map.sh +108 -97
- package/assets/defaults/project.sh +232 -185
- package/assets/defaults/shell.sh +73 -68
- package/assets/defaults/turn-map.md +47 -44
- package/assets/docs/GLOSSARY.md +142 -65
- package/assets/hooks/browser-device-id.sh +16 -12
- package/assets/hooks/browser-guard-device-id.sh +34 -28
- package/assets/hooks/browser-guard-no-asking.sh +5 -4
- package/assets/hooks/browser-guard-no-listing.sh +12 -11
- package/assets/hooks/browser-guard-no-other-drivers.sh +48 -42
- package/assets/hooks/browser-guard-require-select.sh +34 -23
- package/assets/hooks/claim-guard.sh +62 -56
- package/assets/hooks/commit-msg.sh +14 -10
- package/assets/hooks/conscience-guard.sh +91 -45
- package/assets/hooks/constitution-index.sh +16 -16
- package/assets/hooks/deny-tail.sh +28 -26
- package/assets/hooks/dev-server-guard.sh +50 -43
- package/assets/hooks/dispatch.sh +60 -46
- package/assets/hooks/docs-guard.sh +100 -91
- package/assets/hooks/epic-over.sh +49 -0
- package/assets/hooks/epic-stop-guard.sh +108 -0
- package/assets/hooks/exam-guard.sh +105 -93
- package/assets/hooks/git-guard-delivery-conflict.sh +41 -36
- package/assets/hooks/git-guard-delivery-draft.sh +48 -38
- package/assets/hooks/git-guard-delivery-epic.sh +167 -0
- package/assets/hooks/git-guard-delivery-folder.sh +50 -43
- package/assets/hooks/git-guard-delivery-signature.sh +119 -53
- package/assets/hooks/git-guard-delivery.sh +223 -183
- package/assets/hooks/git-guard-main.sh +38 -34
- package/assets/hooks/git-guard-push-tests.sh +99 -87
- package/assets/hooks/glossary-load.sh +23 -22
- package/assets/hooks/grill-gate-ask.sh +12 -11
- package/assets/hooks/grill-gate.sh +94 -87
- package/assets/hooks/guard-note.sh +20 -19
- package/assets/hooks/handoff-entry-guard.sh +45 -25
- package/assets/hooks/handoff-write.sh +74 -67
- package/assets/hooks/hook-input.sh +67 -58
- package/assets/hooks/lint-after-edit.sh +95 -61
- package/assets/hooks/observe.sh +28 -26
- package/assets/hooks/override-write-guard.sh +23 -21
- package/assets/hooks/postmortem-guard.sh +42 -39
- package/assets/hooks/profile-check.sh +22 -20
- package/assets/hooks/proposal-guard.sh +57 -49
- package/assets/hooks/prose-style-guard.sh +49 -24
- package/assets/hooks/qa-dataid-guard.sh +83 -58
- package/assets/hooks/rerun-guard.sh +31 -30
- package/assets/hooks/reuse-first-guard.sh +108 -87
- package/assets/hooks/roles.sh +14 -14
- package/assets/hooks/rule-article.sh +39 -34
- package/assets/hooks/rule-source-guard.sh +47 -42
- package/assets/hooks/skill-gate-layers.sh +63 -57
- package/assets/hooks/skill-gate-rearm.sh +15 -8
- package/assets/hooks/skill-gate.sh +89 -81
- package/assets/hooks/skill-loaded.sh +10 -6
- package/assets/hooks/sql-guard-parse.sh +71 -66
- package/assets/hooks/sql-guard-request.sh +51 -46
- package/assets/hooks/sql-guard-target.sh +60 -51
- package/assets/hooks/sql-guard-write.sh +87 -79
- package/assets/hooks/sql-guard.sh +52 -47
- package/assets/hooks/stand-login-guard.sh +43 -37
- package/assets/hooks/task-context-load.sh +60 -55
- package/assets/hooks/task-flow-context.sh +87 -69
- package/assets/hooks/task-flow-draft-guard.sh +55 -48
- package/assets/hooks/task-flow-guard.sh +67 -64
- package/assets/hooks/turn-entry-load.sh +39 -32
- package/assets/hooks/turn-exit-guard.sh +260 -204
- package/assets/hooks/turn-exit-patterns.sh +63 -0
- package/assets/hooks/utf8.sh +14 -11
- package/assets/hooks/waiting-turn-guard.sh +104 -94
- package/assets/hooks/window-fill-guard.sh +70 -62
- package/assets/hooks/work-start-guard.sh +52 -49
- package/assets/hooks/write-targets.sh +99 -44
- package/assets/laws/autonomous-work.md +29 -27
- package/assets/laws/code-structure.md +31 -30
- package/assets/laws/delivery.md +170 -137
- package/assets/laws/entity-editing.md +52 -50
- package/assets/laws/entity-models.md +14 -13
- package/assets/laws/frontend-application.md +39 -38
- package/assets/laws/lib-imports.md +27 -27
- package/assets/laws/lists.md +31 -29
- package/assets/laws/navigation.md +37 -37
- package/assets/laws/observability.md +41 -40
- package/assets/laws/project-documentation.md +106 -99
- package/assets/laws/reuse-first.md +31 -29
- package/assets/laws/shared-code.md +27 -27
- package/assets/laws/verifiability.md +131 -124
- package/assets/laws/work-conduct.md +250 -244
- package/assets/patterns/admin-lists-screen.md +72 -69
- package/assets/patterns/admin-nav-item.md +51 -46
- package/assets/patterns/angular-patterns-state.md +32 -31
- package/assets/patterns/api-layer-pair.md +33 -31
- package/assets/patterns/autonomous-work-run.md +50 -49
- package/assets/patterns/browser-verification-measure.md +124 -88
- package/assets/patterns/browser-verification-stand.md +169 -157
- package/assets/patterns/component-structure-new.md +51 -42
- package/assets/patterns/dependencies-upgrade.md +55 -39
- package/assets/patterns/doc-style-human.md +55 -37
- package/assets/patterns/doc-style-sweep.md +82 -79
- package/assets/patterns/doc-style-trace.md +87 -81
- package/assets/patterns/doc-style-write.md +130 -122
- package/assets/patterns/entity-aside.md +77 -63
- package/assets/patterns/entity-models-new.md +37 -37
- package/assets/patterns/entity-store.md +33 -33
- package/assets/patterns/git-workflow-commit.azure.md +94 -87
- package/assets/patterns/git-workflow-commit.github.md +160 -142
- package/assets/patterns/git-workflow-commit.gitlab.md +96 -90
- package/assets/patterns/git-workflow-docker.md +165 -147
- package/assets/patterns/git-workflow-freshness.md +45 -45
- package/assets/patterns/git-workflow-merge.md +102 -94
- package/assets/patterns/git-workflow-migration.md +54 -52
- package/assets/patterns/git-workflow-pr-ready.md +57 -56
- package/assets/patterns/git-workflow-pr.azure.md +127 -122
- package/assets/patterns/git-workflow-pr.github.md +186 -177
- package/assets/patterns/git-workflow-pr.gitlab.md +139 -132
- package/assets/patterns/git-workflow-restart.md +35 -31
- package/assets/patterns/git-workflow-secrets.md +80 -73
- package/assets/patterns/git-workflow-stack.md +136 -107
- package/assets/patterns/lib-layers-move.md +62 -53
- package/assets/patterns/lib-layers-new.md +59 -45
- package/assets/patterns/observability-record.md +72 -67
- package/assets/patterns/platform-access-di.md +31 -29
- package/assets/patterns/reuse-first-extend.md +66 -61
- package/assets/patterns/shared-code-new.md +39 -38
- package/assets/patterns/spec-driven-domain.md +161 -151
- package/assets/patterns/spec-driven-rule.md +179 -168
- package/assets/patterns/spec-driven-sweep.md +41 -39
- package/assets/patterns/status-report-table.github.md +48 -36
- package/assets/patterns/styling-bem-component.md +42 -42
- package/assets/patterns/styling-bem-layout.md +39 -34
- package/assets/patterns/styling-bem-sheet.md +59 -58
- package/assets/patterns/task-flow-archive.md +222 -215
- package/assets/patterns/task-flow-close.md +234 -203
- package/assets/patterns/task-flow-handoff.md +154 -145
- package/assets/patterns/task-flow-resume.md +138 -133
- package/assets/patterns/task-flow-start.md +228 -202
- package/assets/patterns/testing-e2e.md +102 -101
- package/assets/patterns/testing-unit.md +77 -70
- package/assets/patterns/ts-procedure.md +32 -29
- package/assets/patterns/turn-entry-map.md +50 -48
- package/assets/pitfalls/agent-kit.md +172 -142
- package/assets/pitfalls/doc-style.md +96 -91
- package/assets/pitfalls/git-workflow.azure.md +49 -46
- package/assets/pitfalls/git-workflow.github.md +270 -234
- package/assets/pitfalls/git-workflow.gitlab.md +49 -45
- package/assets/pitfalls/spec-driven.md +73 -71
- package/assets/pitfalls/styling-bem.md +46 -40
- package/assets/pitfalls/task-flow.md +262 -246
- package/assets/pitfalls/testing.md +99 -92
- package/assets/pitfalls/turn-conduct.md +96 -81
- package/assets/rules/angular-patterns.md +81 -80
- package/assets/rules/api-layer.md +77 -74
- package/assets/rules/autonomous-work.md +87 -74
- package/assets/rules/browser-verification.md +223 -214
- package/assets/rules/component-structure.md +72 -69
- package/assets/rules/dependencies.md +74 -67
- package/assets/rules/deploy-flow.azure.md +118 -108
- package/assets/rules/deploy-flow.github.md +145 -135
- package/assets/rules/deploy-flow.gitlab.md +120 -110
- package/assets/rules/doc-style.md +201 -173
- package/assets/rules/entity-conventions.needs-admin.md +81 -79
- package/assets/rules/entity-models.md +73 -70
- package/assets/rules/git-workflow.azure.md +224 -228
- package/assets/rules/git-workflow.github.md +268 -239
- package/assets/rules/git-workflow.gitlab.md +218 -217
- package/assets/rules/lib-layers.md +85 -86
- package/assets/rules/lists.md +101 -97
- package/assets/rules/navigation.md +78 -78
- package/assets/rules/observability.needs-app.md +165 -153
- package/assets/rules/platform-access.md +76 -75
- package/assets/rules/reuse-first.md +153 -143
- package/assets/rules/shared-code.md +82 -79
- package/assets/rules/spec-driven.md +279 -260
- package/assets/rules/status-report.md +62 -58
- package/assets/rules/styling-bem.md +81 -77
- package/assets/rules/task-flow.md +303 -270
- package/assets/rules/testing.md +224 -209
- package/assets/rules/turn-conduct.md +262 -258
- package/assets/rules/turn-entry.md +92 -87
- package/assets/rules/typescript-conventions.md +94 -88
- package/assets/samples/specs/_template/spec.md +47 -47
- package/assets/samples/tasks/_template/grill.md +20 -20
- package/assets/samples/tasks/_template/plan.md +32 -30
- package/assets/samples/tasks/_template/progress.md +16 -16
- package/assets/skills/agent-kit-extend.md +129 -113
- package/assets/skills/agent-kit.md +259 -233
- package/assets/skills/write-a-skill.md +76 -71
- package/assets/templates/findings.md +19 -19
- package/assets/templates/gate-map.sh +16 -14
- package/assets/templates/implementation.md +28 -27
- package/assets/templates/pattern.md +17 -17
- package/assets/templates/pitfalls.md +6 -6
- package/assets/templates/postmortem.md +24 -23
- package/assets/templates/project.sh +24 -24
- package/assets/templates/proposal.md +62 -60
- package/assets/templates/rule.md +38 -38
- package/assets/workflows/feature.js +46 -46
- package/assets/workflows/plan.js +54 -54
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +8 -1
- package/bin/agent-kit.js.map +1 -1
- package/lib/cargo-prose.d.ts +41 -0
- package/lib/cargo-prose.d.ts.map +1 -0
- package/lib/cargo-prose.js +88 -0
- package/lib/cargo-prose.js.map +1 -0
- package/lib/cargo.d.ts +12 -1
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +8 -2
- package/lib/cargo.js.map +1 -1
- package/lib/catalog.d.ts +2 -0
- package/lib/catalog.d.ts.map +1 -1
- package/lib/catalog.js +4 -3
- package/lib/catalog.js.map +1 -1
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +5 -2
- package/lib/commands.js.map +1 -1
- package/lib/companion.js +3 -2
- package/lib/companion.js.map +1 -1
- package/lib/enroll.d.ts +7 -1
- package/lib/enroll.d.ts.map +1 -1
- package/lib/enroll.js +12 -3
- package/lib/enroll.js.map +1 -1
- package/lib/fate.d.ts +29 -0
- package/lib/fate.d.ts.map +1 -0
- package/lib/fate.js +147 -0
- package/lib/fate.js.map +1 -0
- package/lib/override-marks.d.ts +7 -0
- package/lib/override-marks.d.ts.map +1 -1
- package/lib/override-marks.js +14 -0
- package/lib/override-marks.js.map +1 -1
- package/lib/plan.d.ts +11 -0
- package/lib/plan.d.ts.map +1 -1
- package/lib/plan.js +10 -1
- package/lib/plan.js.map +1 -1
- package/lib/ship.d.ts +29 -9
- package/lib/ship.d.ts.map +1 -1
- package/lib/ship.js +44 -2
- package/lib/ship.js.map +1 -1
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.fixture.d.ts +8 -1
- package/lib/shipment.fixture.d.ts.map +1 -1
- package/lib/shipment.fixture.js +9 -0
- package/lib/shipment.fixture.js.map +1 -1
- package/lib/shipment.js +38 -5
- package/lib/shipment.js.map +1 -1
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +45 -11
- package/lib/sync.js.map +1 -1
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.27.0.tgz +0 -0
- package/rt-tools-agent-kit-0.24.0.tgz +0 -0
|
@@ -1,46 +1,47 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
|
|
3
|
-
#
|
|
4
|
-
#
|
|
3
|
+
# Requires: hooks/git-guard-delivery-folder.sh, hooks/git-guard-delivery-epic.sh, hooks/git-guard-delivery-conflict.sh, hooks/profile-check.sh, hooks/deny-tail.sh, hooks/guard-note.sh
|
|
4
|
+
# Delivery guard. PreToolUse on creating a branch, on the push and on opening a PR.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# вовсе.
|
|
6
|
+
# The delivery law demands three things nothing usually checks: an edit starts from a task visible
|
|
7
|
+
# in the work queue; the task, the branch and the PR carry one number; the task has an assignee.
|
|
8
|
+
# They are held by memory — and they do not hold: tasks stand outside the queue, the assignee is
|
|
9
|
+
# not set, and most merged PRs come from branches that had no task behind them at all.
|
|
11
10
|
#
|
|
12
|
-
#
|
|
11
|
+
# The guard stands at three points, and at each of them it demands what is fixable at that moment:
|
|
13
12
|
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
13
|
+
# creating a branch — a name with a number is parsed on the spot; a name without a number is let
|
|
14
|
+
# through: a local branch for a trial is lawful, it will not travel into the main branch,
|
|
15
|
+
# because no PR opens from it;
|
|
16
|
+
# the push — the signature of a machine commit is still rewritten on the spot; after the push
|
|
17
|
+
# only a force push fixes it;
|
|
18
|
+
# opening a PR — the branch must carry a number, the title must start with the same number, and
|
|
19
|
+
# the task must be open, stand in the work queue and have an assignee.
|
|
21
20
|
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
21
|
+
# Two tiers. The format — the number in the branch name, the number in the title, their match — is
|
|
22
|
+
# read from the command text and always works. The state of the task needs the network: no network,
|
|
23
|
+
# no client or no token — the tier is skipped, because there is nothing to check with.
|
|
25
24
|
#
|
|
26
|
-
#
|
|
27
|
-
# rt_task_branch_ok —
|
|
28
|
-
# rt_task_branch_number —
|
|
29
|
-
# RT_TASK_TITLE_RE —
|
|
30
|
-
# rt_task_state —
|
|
31
|
-
# numbered);
|
|
32
|
-
# RT_TASK_NEW_CMD —
|
|
33
|
-
# RT_BOARD_CHECK_CMD —
|
|
34
|
-
# RT_TASK_BOT —
|
|
35
|
-
# RT_PULL_TOKEN_VAR —
|
|
36
|
-
# RT_PULL_TOKEN_HINT —
|
|
37
|
-
# RT_COMMIT_EMAIL —
|
|
38
|
-
#
|
|
39
|
-
#
|
|
25
|
+
# What is called what here is known by the tree profile:
|
|
26
|
+
# rt_task_branch_ok — the form of a branch name for a task;
|
|
27
|
+
# rt_task_branch_number — the task number out of that name: the prefix can be the kind of edit too;
|
|
28
|
+
# RT_TASK_TITLE_RE — the form of the number in the PR title;
|
|
29
|
+
# rt_task_state — the state of the task as one object (existsize, open, onBoard, assigned,
|
|
30
|
+
# numbered); silence means "there is nobody to ask";
|
|
31
|
+
# RT_TASK_NEW_CMD — what a task is created with;
|
|
32
|
+
# RT_BOARD_CHECK_CMD — what the work queue is audited with;
|
|
33
|
+
# RT_TASK_BOT — the account put as the assignee; the PR is opened by it as well;
|
|
34
|
+
# RT_PULL_TOKEN_VAR — the variable through which its token is substituted into the call;
|
|
35
|
+
# RT_PULL_TOKEN_HINT — the ready-made substitution of that token, whole;
|
|
36
|
+
# RT_COMMIT_EMAIL — the address a machine commit is signed with; by its left part the commit
|
|
37
|
+
# is recognised as well.
|
|
38
|
+
# The refusal names both what is wrong and what fixes it: a refusal without an action is bypassed,
|
|
39
|
+
# not carried out.
|
|
40
40
|
#
|
|
41
|
-
#
|
|
41
|
+
# FAIL-OPEN: not a repository, no parser, broken input, no profile — let through.
|
|
42
42
|
|
|
43
|
-
#
|
|
43
|
+
# Its own name in the observations: the refusal is written by the shared deny tail, not by the
|
|
44
|
+
# guard itself.
|
|
44
45
|
RT_GUARD_NAME=git-guard-delivery
|
|
45
46
|
|
|
46
47
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
@@ -54,7 +55,7 @@ command -v jq >/dev/null 2>&1 || exit 0
|
|
|
54
55
|
tool="$(rt_hook_tool)"
|
|
55
56
|
sid="$(printf '%s' "$input" | jq -r '.session_id // "nosession"' 2>/dev/null)"
|
|
56
57
|
case "$tool" in
|
|
57
|
-
#
|
|
58
|
+
# The environment terminal and the universal executor put the command in the same field.
|
|
58
59
|
Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool) ;;
|
|
59
60
|
*) exit 0 ;;
|
|
60
61
|
esac
|
|
@@ -62,8 +63,8 @@ esac
|
|
|
62
63
|
cmd="$(rt_hook_cmd)"
|
|
63
64
|
[ -z "$cmd" ] && exit 0
|
|
64
65
|
|
|
65
|
-
#
|
|
66
|
-
#
|
|
66
|
+
# The universal executor passes the real command as a nested string. It is that string that has to
|
|
67
|
+
# be parsed, not the wrapper.
|
|
67
68
|
if [ "$tool" = "mcp__webstorm__execute_tool" ] && command -v perl >/dev/null 2>&1; then
|
|
68
69
|
inner="$(printf '%s' "$cmd" | perl -0ne '
|
|
69
70
|
if (/--command(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(.+))/s) {
|
|
@@ -80,18 +81,18 @@ git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
|
|
|
80
81
|
|
|
81
82
|
root="${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}"
|
|
82
83
|
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
#
|
|
86
|
-
#
|
|
84
|
+
# The tree profile: first the package default, and the project override on top of it, if there is
|
|
85
|
+
# one. A function declared in the override replaces the default whole and may call it back through
|
|
86
|
+
# the `_default` suffix. Neither one nor the other — the hook lets through: an empty guard is
|
|
87
|
+
# better than a guard that refuses at random.
|
|
87
88
|
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
88
89
|
for profile in "$rt_hooks_dir/../rt-kit/defaults/project.sh" "$rt_hooks_dir/../defaults/project.sh" "$root/.claude/rt-kit/defaults/project.sh" "$root/.claude/rt-kit/project.sh"; do
|
|
89
90
|
# shellcheck disable=SC1090
|
|
90
91
|
[ -f "$profile" ] && . "$profile" 2>/dev/null
|
|
91
92
|
done
|
|
92
93
|
|
|
93
|
-
#
|
|
94
|
-
#
|
|
94
|
+
# A word about a missing profile function: a hook that left silently is indistinguishable from a
|
|
95
|
+
# working one. The file may be not laid out — then the previous behaviour stays, the silent one.
|
|
95
96
|
# shellcheck disable=SC1090
|
|
96
97
|
[ -f "$rt_hooks_dir/profile-check.sh" ] && . "$rt_hooks_dir/profile-check.sh"
|
|
97
98
|
command -v rt_needs >/dev/null 2>&1 || rt_needs() { command -v "$1" >/dev/null 2>&1; }
|
|
@@ -102,52 +103,58 @@ title_re="${RT_TASK_TITLE_RE:-^\[[A-Za-z]+-[0-9]+\][[:space:]]+[^[:space:]]}"
|
|
|
102
103
|
task_new="${RT_TASK_NEW_CMD:-npm run task:new}"
|
|
103
104
|
board_check="${RT_BOARD_CHECK_CMD:-npm run check:board}"
|
|
104
105
|
task_move="${RT_TASK_MOVE_CMD:-npm run task:move}"
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
#
|
|
106
|
+
# The first column of the work queue is the one a task leaves when it is taken. It has no default:
|
|
107
|
+
# a tree names its columns in its own words, and an invented name would match nothing and would
|
|
108
|
+
# silently switch the check off.
|
|
108
109
|
backlog_column="${RT_BOARD_BACKLOG:-}"
|
|
110
|
+
epic_label="${RT_BOARD_EPIC_LABEL:-}"
|
|
109
111
|
task_bot="${RT_TASK_BOT:-}"
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
112
|
+
# The identity of the call arrives through the environment, not as a word in the line: from the
|
|
113
|
+
# command text only one thing is visible — whether the token is substituted explicitly. A tree that
|
|
114
|
+
# named no variable does not judge the PR author at all — it may have no separate machine account.
|
|
113
115
|
pull_token_var="${RT_PULL_TOKEN_VAR:-}"
|
|
114
116
|
pull_token_hint="${RT_PULL_TOKEN_HINT:-}"
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
#
|
|
118
|
-
#
|
|
117
|
+
# The section the PR body must carry from the minute it opens. The merge button is pressed by a
|
|
118
|
+
# person on the hosting, where the guard does not reach: everything the requirement holds by there
|
|
119
|
+
# is what the owner saw on the page. The section heading is written in the language of the PR, so
|
|
120
|
+
# the pattern is named by the tree, not by the package: the package does not know someone else's
|
|
121
|
+
# words, and an invented default would match nothing.
|
|
119
122
|
pull_body_section="${RT_PULL_BODY_SECTION:-}"
|
|
120
123
|
commit_email="${RT_COMMIT_EMAIL:-}"
|
|
121
124
|
tasks_dir="${RT_TASKS_DIR:-}"
|
|
122
125
|
archive_dir="${RT_ARCHIVE_DIR:-}"
|
|
123
126
|
main_branch="${RT_MAIN_BRANCH:-main}"
|
|
124
127
|
|
|
125
|
-
#
|
|
126
|
-
#
|
|
128
|
+
# The bypass of the requirement: a line with a reason. The reason is seen by whoever merges, so the
|
|
129
|
+
# bypass is allowed; without a reason it is a silent skip. The threshold of three characters is the
|
|
130
|
+
# same as in the document guard.
|
|
127
131
|
#
|
|
128
|
-
#
|
|
129
|
-
#
|
|
130
|
-
#
|
|
132
|
+
# The bypass line stands at the start of a line — its own in the PR body, or of a comment at the end
|
|
133
|
+
# of the command — and takes no substitutions. Otherwise the text explaining what the bypass is
|
|
134
|
+
# called is indistinguishable from the bypass itself: a PR body with a sample line lifted the
|
|
135
|
+
# requirement by itself.
|
|
131
136
|
folder_skip_re='(^|#)[[:space:]]*Task-folder-skip:[[:space:]]*[^[:space:]<"'"'"'][^[:space:]"'"'"']{2,}'
|
|
132
137
|
|
|
133
138
|
deny() {
|
|
134
|
-
#
|
|
135
|
-
#
|
|
139
|
+
# A guard refusal is an observation: the guard that refuses more often than the rest says which
|
|
140
|
+
# place of the delivery is done wrong time after time. The refusal text does not go there: it
|
|
141
|
+
# holds the task numbers and the branch names of the tree.
|
|
136
142
|
|
|
137
|
-
#
|
|
143
|
+
# The refusal tail: the two lawful moves and the form of the bypass as the second parameter.
|
|
138
144
|
# shellcheck disable=SC1090
|
|
139
145
|
[ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
|
|
140
146
|
reason="$1"
|
|
141
147
|
command -v rt_deny_tail >/dev/null 2>&1 && reason="$1 $(rt_deny_tail "$2")"
|
|
142
148
|
|
|
143
149
|
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
144
|
-
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"
|
|
150
|
+
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"The delivery guard."}}\n'
|
|
145
151
|
exit 0
|
|
146
152
|
}
|
|
147
153
|
|
|
148
|
-
#
|
|
149
|
-
#
|
|
150
|
-
#
|
|
154
|
+
# Conditions that did not come together pile up and are named all at once: a refusal on the first
|
|
155
|
+
# miss makes them fixed one at a time — the base, a repeat, the title, another repeat, the task —
|
|
156
|
+
# although everything that did not come together is known already on the first round. Readiness for
|
|
157
|
+
# delivery is one state, and it is named whole.
|
|
151
158
|
faults=''
|
|
152
159
|
|
|
153
160
|
fault() {
|
|
@@ -155,24 +162,32 @@ fault() {
|
|
|
155
162
|
}— $1"
|
|
156
163
|
}
|
|
157
164
|
|
|
158
|
-
#
|
|
159
|
-
#
|
|
160
|
-
#
|
|
165
|
+
# The conditions about the task folder are moved out into a neighbouring file: the folder has a
|
|
166
|
+
# subject of its own, a bypass of its own and a record of its own in the archive, and together with
|
|
167
|
+
# the command parsing and the work queue they outgrew the length limit. It is sourced after `deny`
|
|
168
|
+
# and `fault` — both are called from inside it.
|
|
161
169
|
# shellcheck disable=SC1090
|
|
162
170
|
[ -f "$rt_hooks_dir/git-guard-delivery-folder.sh" ] && . "$rt_hooks_dir/git-guard-delivery-folder.sh" 2>/dev/null
|
|
163
171
|
|
|
164
|
-
#
|
|
165
|
-
#
|
|
166
|
-
#
|
|
172
|
+
# The epic of a task: the same technique as with the folder. It is sourced before the branch block —
|
|
173
|
+
# there the base of a new branch is judged, and with an epic it is judged against the branch of the
|
|
174
|
+
# epic. No helper — the epic is not judged, and the base is asked against the main branch as before.
|
|
175
|
+
# shellcheck disable=SC1090
|
|
176
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-epic.sh" ] && . "$rt_hooks_dir/git-guard-delivery-epic.sh" 2>/dev/null
|
|
177
|
+
|
|
178
|
+
# A conflicting PR of one's own: the same technique as with the folder and the signature. The helper
|
|
179
|
+
# is called before all the tiers below and judges not the readiness of this work but the right to
|
|
180
|
+
# take the next one: while what was handed over conflicts, it is fixed by the first action of the
|
|
181
|
+
# turn. No helper — the tier is not judged, and the work goes on.
|
|
167
182
|
# shellcheck disable=SC1090
|
|
168
183
|
[ -f "$rt_hooks_dir/git-guard-delivery-conflict.sh" ] && . "$rt_hooks_dir/git-guard-delivery-conflict.sh" 2>/dev/null
|
|
169
184
|
command -v rt_delivery_conflict >/dev/null 2>&1 && rt_delivery_conflict
|
|
170
185
|
|
|
171
|
-
#
|
|
186
|
+
# The refusal on what has piled up. Empty — the calling side goes on.
|
|
172
187
|
deny_faults() {
|
|
173
188
|
[ -z "$faults" ] && return 0
|
|
174
|
-
deny "BLOCKED:
|
|
175
|
-
|
|
189
|
+
deny "BLOCKED: the work is not ready for delivery. Everything unmet is named whole — so that it
|
|
190
|
+
is fixed in one session, not one miss per round:
|
|
176
191
|
|
|
177
192
|
${faults}"
|
|
178
193
|
}
|
|
@@ -180,143 +195,161 @@ ${faults}"
|
|
|
180
195
|
check_task() {
|
|
181
196
|
number="$1"
|
|
182
197
|
where="$2"
|
|
183
|
-
#
|
|
184
|
-
#
|
|
185
|
-
#
|
|
186
|
-
|
|
198
|
+
# The column is asked about where it should already have been moved. At branch creation it has
|
|
199
|
+
# not been moved yet — the work pattern moves the column with the next command — and the
|
|
200
|
+
# requirement here would refuse the very first command of the work together with the one that
|
|
201
|
+
# lifts it.
|
|
202
|
+
judge_column="${3:-no}"
|
|
187
203
|
rt_needs rt_task_state git-guard-delivery || return 0
|
|
188
204
|
state="$(cd "$root" && rt_task_state "$number" 2>/dev/null)" || return 0
|
|
189
205
|
[ -z "$state" ] && return 0
|
|
190
206
|
|
|
191
207
|
printf '%s' "$state" | jq -e '.exists' >/dev/null 2>&1 \
|
|
192
|
-
|| fault "${where}
|
|
208
|
+
|| fault "${where} refers to the task #${number}, which does not exist. Check the number or create the task — ${task_new}."
|
|
193
209
|
printf '%s' "$state" | jq -e '.open' >/dev/null 2>&1 \
|
|
194
|
-
|| fault "
|
|
210
|
+
|| fault "the task #${number} is closed, and a task has one branch. Work behind a closed task is created as a new task — ${task_new}."
|
|
195
211
|
printf '%s' "$state" | jq -e '.onBoard' >/dev/null 2>&1 \
|
|
196
|
-
|| fault "
|
|
212
|
+
|| fault "the task #${number} is not in the work queue — the edit behind it is invisible. The queue is not bound to the repository and does not take a task by itself; add it and check — ${board_check}."
|
|
197
213
|
printf '%s' "$state" | jq -e '.assigned' >/dev/null 2>&1 \
|
|
198
|
-
|| fault "
|
|
214
|
+
|| fault "the task #${number} has no assignee — by the work queue there is no seeing who took it. Set the assignee${task_bot:+: }${task_bot}."
|
|
199
215
|
printf '%s' "$state" | jq -e '.numbered' >/dev/null 2>&1 \
|
|
200
|
-
|| fault "
|
|
216
|
+
|| fault "the title of the task #${number} does not start with its number — one work would have to be recognised by the text of the title. Fix the title and check the queue — ${board_check}."
|
|
201
217
|
|
|
202
|
-
#
|
|
203
|
-
#
|
|
204
|
-
#
|
|
205
|
-
|
|
218
|
+
# The task column. The work queue answer has been giving it for a long time, and nobody read it:
|
|
219
|
+
# the column was judged only by the queue audit, that is, already after the PR is opened. A task
|
|
220
|
+
# left in the first column reads through the queue as not taken — while the work is done and put
|
|
221
|
+
# out.
|
|
222
|
+
if [ -n "$backlog_column" ] && [ "$judge_column" = "yes" ]; then
|
|
206
223
|
column="$(printf '%s' "$state" | jq -r '.status // empty' 2>/dev/null)"
|
|
207
224
|
[ "$column" = "$backlog_column" ] \
|
|
208
|
-
&& fault "
|
|
225
|
+
&& fault "the task #${number} stands in the column «${column}» — by the work queue it is not taken, though the work on it is going. Move it: ${task_move}."
|
|
209
226
|
fi
|
|
210
227
|
|
|
211
228
|
return 0
|
|
212
229
|
}
|
|
213
230
|
|
|
214
|
-
# ---
|
|
231
|
+
# --- creating a branch -------------------------------------------------------------------
|
|
215
232
|
branch_arg=''
|
|
216
|
-
if printf '%s' "$cmd" | grep -qE '(^|[;&|[:space:]])git[[:space:]]+(checkout[[:space:]]+-b|switch[[:space:]]+-c)[[:space:]]'; then
|
|
217
|
-
branch_arg="$(printf '%s' "$cmd" | sed -nE 's/.*git[[:space:]]+(checkout[[:space:]]+-b|switch[[:space:]]+-c)[[:space:]]+([^[:space:];&|]+).*/\
|
|
233
|
+
if printf '%s' "$cmd" | grep -qE '(^|[;&|[:space:]])git[[:space:]]+(checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c)[[:space:]]'; then
|
|
234
|
+
branch_arg="$(printf '%s' "$cmd" | sed -nE 's/.*git[[:space:]]+(checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c)[[:space:]]+([^[:space:];&|]+).*/\4/p' | head -1)"
|
|
218
235
|
branch_arg="${branch_arg%\'}"; branch_arg="${branch_arg#\'}"
|
|
219
236
|
branch_arg="${branch_arg%\"}"; branch_arg="${branch_arg#\"}"
|
|
220
237
|
fi
|
|
221
238
|
|
|
222
239
|
if [ -n "$branch_arg" ]; then
|
|
223
|
-
#
|
|
224
|
-
#
|
|
225
|
-
#
|
|
226
|
-
#
|
|
227
|
-
# при заведении не срабатывала на ней ни разу, а сверка номеров пропускалась молча.
|
|
240
|
+
# A name pretending to be a branch for a task but not matching the form is a miss in the name,
|
|
241
|
+
# not a deliberate task-less branch. Caught before the first commit.
|
|
242
|
+
# The number is extracted by the profile: with its own regex the branch `feat/88-slug` gave no
|
|
243
|
+
# number at all.
|
|
228
244
|
number_arg="$(rt_task_branch_number "$branch_arg")"
|
|
229
245
|
if [ -n "$number_arg" ]; then
|
|
230
246
|
rt_task_branch_ok "$branch_arg" \
|
|
231
|
-
|| deny "BLOCKED:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
#
|
|
235
|
-
#
|
|
236
|
-
|
|
247
|
+
|| deny "BLOCKED: the branch name «${branch_arg}» is not of the form accepted here. The branch number is the same as the number of the task and of the title of the merge request."
|
|
248
|
+
state=''
|
|
249
|
+
check_task "$number_arg" "the branch «${branch_arg}»"
|
|
250
|
+
# The epic of the task: with one, the base is judged against the branch of the epic, and the
|
|
251
|
+
# freshness of the main branch moves there too — see `git-guard-delivery-epic.sh`.
|
|
252
|
+
epic_arg="$(printf '%s' "$state" | jq -r '.epic // empty' 2>/dev/null)"
|
|
253
|
+
|
|
254
|
+
# The delivery conditions already known here are checked here. After the work is done, the
|
|
255
|
+
# base is fixed by a merge with conflict resolution, and the commit signature by rewriting
|
|
256
|
+
# the branch; at the start of the work both cost one command.
|
|
237
257
|
#
|
|
238
|
-
#
|
|
239
|
-
#
|
|
240
|
-
#
|
|
241
|
-
base_arg="$(printf '%s' "$cmd" | sed -nE 's/.*git[[:space:]]+(checkout[[:space:]]+-b|switch[[:space:]]+-c)[[:space:]]+[^[:space:];&|]+[[:space:]]+([^[:space:];&|-][^[:space:];&|]*).*/\
|
|
258
|
+
# The base: the tip of the main branch must lie in what the new branch grows from. The named
|
|
259
|
+
# base is checked, not the tip of the working copy: otherwise the command that takes the
|
|
260
|
+
# base fresh — `git checkout -b <branch> origin/<main>` — would be forbidden.
|
|
261
|
+
base_arg="$(printf '%s' "$cmd" | sed -nE 's/.*git[[:space:]]+(checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c)[[:space:]]+[^[:space:];&|]+[[:space:]]+([^[:space:];&|-][^[:space:];&|]*).*/\4/p' | head -1)"
|
|
242
262
|
base_ref="${base_arg:-HEAD}"
|
|
243
|
-
if
|
|
263
|
+
if [ -n "$epic_arg" ] && command -v rt_epic_base >/dev/null 2>&1; then
|
|
264
|
+
rt_epic_base "$epic_arg" "$base_ref" "$branch_arg"
|
|
265
|
+
elif git rev-parse --verify --quiet "refs/remotes/origin/${main_branch}" >/dev/null 2>&1 \
|
|
244
266
|
&& git rev-parse --verify --quiet "$base_ref" >/dev/null 2>&1 \
|
|
245
267
|
&& ! git merge-base --is-ancestor "origin/${main_branch}" "$base_ref" 2>/dev/null; then
|
|
246
268
|
behind="$(git rev-list --count "${base_ref}..origin/${main_branch}" 2>/dev/null)"
|
|
247
|
-
fault "
|
|
269
|
+
fault "the branch will grow from a base that does not carry the tip of «${main_branch}» — it has moved ahead by ${behind:-several} commits. Take a fresh base: git fetch origin && git checkout -b ${branch_arg} origin/${main_branch}."
|
|
248
270
|
fi
|
|
249
271
|
|
|
250
|
-
#
|
|
251
|
-
#
|
|
252
|
-
#
|
|
272
|
+
# The second tier: the local reference to the main branch could itself have gone stale, and
|
|
273
|
+
# then the silence of the first tier means "the base is not older than my reference", not
|
|
274
|
+
# "the base is fresh". No answer — the tier stays silent, as everywhere the guard goes to
|
|
275
|
+
# the network.
|
|
253
276
|
remote_head="$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=5 GIT_TERMINAL_PROMPT=0 \
|
|
254
277
|
git ls-remote origin "refs/heads/${main_branch}" 2>/dev/null | cut -f1)"
|
|
255
278
|
local_head="$(git rev-parse --verify --quiet "refs/remotes/origin/${main_branch}" 2>/dev/null)"
|
|
256
279
|
if [ -n "$remote_head" ] && [ -n "$local_head" ] && [ "$remote_head" != "$local_head" ]; then
|
|
257
|
-
fault "
|
|
280
|
+
fault "your ref origin/${main_branch} lags behind the remote one — ${local_head:0:8} against ${remote_head:0:8}. The branch will grow from yesterday tree, and the owner sees that at the opening of the request. Pull and repeat: git fetch origin."
|
|
258
281
|
fi
|
|
259
282
|
|
|
260
|
-
#
|
|
261
|
-
#
|
|
262
|
-
#
|
|
283
|
+
# The signature: the address of the machine account is declared by the tree, and the working
|
|
284
|
+
# copy does not know it — which means the very first commit will travel under someone else's
|
|
285
|
+
# signature, and after the push that is fixed only by a force push.
|
|
263
286
|
if [ -n "$commit_email" ]; then
|
|
264
287
|
tree_email="$(git config user.email 2>/dev/null)"
|
|
265
288
|
[ -n "$tree_email" ] && [ "$tree_email" != "$commit_email" ] \
|
|
266
|
-
&& fault "
|
|
289
|
+
&& fault "the working copy signs commits as «${tree_email}», while the tree declared the email of the machine account «${commit_email}». The very first commit leaves under a foreign signature: git config user.email \"${commit_email}\"."
|
|
267
290
|
fi
|
|
268
291
|
|
|
269
292
|
deny_faults
|
|
270
293
|
fi
|
|
271
|
-
#
|
|
294
|
+
# A branch without a number is lawful and lives locally: no PR opens from it.
|
|
272
295
|
exit 0
|
|
273
296
|
fi
|
|
274
297
|
|
|
275
|
-
# ---
|
|
276
|
-
#
|
|
277
|
-
#
|
|
278
|
-
#
|
|
298
|
+
# --- the machine commit signature ----------------------------------------------------------
|
|
299
|
+
# The subject lives in a helper next door — `git-guard-delivery-signature.sh`: the guard grew up to
|
|
300
|
+
# the length limit, and the signature is the most separate of its subjects. No helper — the
|
|
301
|
+
# signature is not judged, and the work goes on: the same fail-open as with the other conditions.
|
|
279
302
|
# shellcheck disable=SC1090
|
|
280
303
|
[ -f "$rt_hooks_dir/git-guard-delivery-signature.sh" ] \
|
|
281
304
|
&& . "$rt_hooks_dir/git-guard-delivery-signature.sh" 2>/dev/null
|
|
282
305
|
command -v rt_delivery_signature >/dev/null 2>&1 && rt_delivery_signature
|
|
283
306
|
|
|
284
|
-
# ---
|
|
285
|
-
#
|
|
286
|
-
#
|
|
307
|
+
# --- leaving draft ---------------------------------------------------------------------------
|
|
308
|
+
# The subject lives in a helper next door — `git-guard-delivery-draft.sh`, by the same technique as
|
|
309
|
+
# the signature. No helper — leaving draft is not judged, and the work goes on.
|
|
287
310
|
# shellcheck disable=SC1090
|
|
288
311
|
[ -f "$rt_hooks_dir/git-guard-delivery-draft.sh" ] \
|
|
289
312
|
&& . "$rt_hooks_dir/git-guard-delivery-draft.sh" 2>/dev/null
|
|
290
313
|
command -v rt_delivery_draft_ready >/dev/null 2>&1 && rt_delivery_draft_ready
|
|
291
314
|
|
|
292
|
-
# ---
|
|
315
|
+
# --- merging a PR --------------------------------------------------------------------------
|
|
293
316
|
#
|
|
294
|
-
#
|
|
295
|
-
#
|
|
296
|
-
#
|
|
297
|
-
#
|
|
298
|
-
#
|
|
317
|
+
# The second line of the same condition that stands at the opening of a PR: it catches a merge going
|
|
318
|
+
# by command. We look for the command from the start of the line or after a separator, not anywhere
|
|
319
|
+
# in the text. Otherwise the guard refuses a message where `gh pr merge` is merely mentioned in
|
|
320
|
+
# quotes — that is how it fired on an edit of this very text. A quoted substring cannot be cut off
|
|
321
|
+
# entirely this way, but an accidental mention inside a word or a path no longer gets through.
|
|
299
322
|
if printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}(gh[[:space:]]+pr[[:space:]]+merge|glab[[:space:]]+mr[[:space:]]+merge|az[[:space:]]+repos[[:space:]]+pr[[:space:]]+update)([[:space:]]|\$)"; then
|
|
300
323
|
rt_delivery_merge_folder
|
|
301
324
|
fi
|
|
302
325
|
|
|
303
|
-
# ---
|
|
304
|
-
#
|
|
305
|
-
#
|
|
326
|
+
# --- opening a PR --------------------------------------------------------------------------
|
|
327
|
+
# We look for the command from the start of the line or after a separator — for the same reason as
|
|
328
|
+
# with the merge: a mention in quotes is not a command.
|
|
306
329
|
printf '%s' "$cmd" \
|
|
307
330
|
| grep -qE "${RT_CMD_BOUND}(gh[[:space:]]+pr[[:space:]]+create|glab[[:space:]]+mr[[:space:]]+create|az[[:space:]]+repos[[:space:]]+pr[[:space:]]+create)([[:space:]]|\$)" \
|
|
308
331
|
|| exit 0
|
|
309
332
|
|
|
310
333
|
branch="$(git branch --show-current 2>/dev/null)"
|
|
311
|
-
[ -z "$branch" ] && exit 0 #
|
|
334
|
+
[ -z "$branch" ] && exit 0 # a detached HEAD is not about this case
|
|
312
335
|
|
|
313
|
-
#
|
|
314
|
-
#
|
|
336
|
+
# A local branch without a number is lawful, and a PR from it is not: an edit that travels to the
|
|
337
|
+
# main branch starts from a task. This is the only place where a task-less branch runs into a wall.
|
|
315
338
|
rt_task_branch_ok "$branch" \
|
|
316
|
-
|| deny "BLOCKED:
|
|
339
|
+
|| deny "BLOCKED: a request from the branch «${branch}», with no task standing behind it. An edit begins with a task visible in the work queue: create it — ${task_new} — and move the work into a branch with its number."
|
|
317
340
|
|
|
318
341
|
number="$(rt_task_branch_number "$branch")"
|
|
319
342
|
|
|
343
|
+
# The work queue is asked here and not at the end of the block: the epic of the task decides what
|
|
344
|
+
# the base of the request is judged against, and that judging stands above. The call is one — the
|
|
345
|
+
# state stays in `state` and the tail of the block reads the same answer.
|
|
346
|
+
state=''
|
|
347
|
+
check_task "$number" "the request from the branch «${branch}»" yes
|
|
348
|
+
epic_pull="$(printf '%s' "$state" | jq -r '.epic // empty' 2>/dev/null)"
|
|
349
|
+
# The branch of an epic itself: its request goes into the main branch, and it opens only when the
|
|
350
|
+
# folders of all its tasks are taken apart.
|
|
351
|
+
command -v rt_epic_own_pull >/dev/null 2>&1 && rt_epic_own_pull "$state"
|
|
352
|
+
|
|
320
353
|
title=''
|
|
321
354
|
if command -v perl >/dev/null 2>&1; then
|
|
322
355
|
title="$(printf '%s' "$cmd" | perl -0ne '
|
|
@@ -328,89 +361,96 @@ fi
|
|
|
328
361
|
|
|
329
362
|
if [ -n "$title" ]; then
|
|
330
363
|
printf '%s' "$title" | grep -qE "$title_re" \
|
|
331
|
-
|| fault "
|
|
332
|
-
#
|
|
333
|
-
#
|
|
334
|
-
#
|
|
335
|
-
#
|
|
364
|
+
|| fault "the title of the request does not start with the number of the task. In the list of requests the body is invisible, and the line of the link lives exactly there — without the number in the title the PR cannot be matched to the task."
|
|
365
|
+
# The number is extracted from the part of the title the form itself recognised, not by a second
|
|
366
|
+
# regex next to it. The own regex knows only the package form: a tree that paved the form over
|
|
367
|
+
# with its own got an empty number — and the check of the title number against the branch number
|
|
368
|
+
# silently did not run at all, while looking as if it had come together.
|
|
336
369
|
title_matched="$(printf '%s' "$title" | grep -oE "$title_re" | head -1)"
|
|
337
370
|
title_number="$(printf '%s' "$title_matched" | grep -oE '[A-Za-z]+-[0-9]+' | head -1 | sed -E 's/^[A-Za-z]+-//')"
|
|
338
371
|
if [ -n "$number" ] && [ -n "$title_number" ]; then
|
|
339
372
|
[ "$title_number" = "$number" ] \
|
|
340
|
-
|| fault "
|
|
373
|
+
|| fault "the title of the request carries the number ${title_number}, the branch — ${number}. The task, the branch and the PR carry one and the same number."
|
|
341
374
|
fi
|
|
342
375
|
fi
|
|
343
376
|
|
|
344
|
-
#
|
|
345
|
-
#
|
|
377
|
+
# The main branch is merged in before the PR opens: otherwise the reviewer sees someone else's edit
|
|
378
|
+
# mixed in with his own, and the checks run from an outdated base.
|
|
346
379
|
#
|
|
347
|
-
#
|
|
348
|
-
#
|
|
349
|
-
#
|
|
350
|
-
#
|
|
351
|
-
if
|
|
380
|
+
# There are two tiers. The first reads the local tip and works without the network. The second asks
|
|
381
|
+
# the remote reference: without it, silence means only "the local reference is not older than the
|
|
382
|
+
# branch", while it reads as "the main branch is merged in". No answer from the network — a silent
|
|
383
|
+
# skip; the waiting limit is set by git variables, an external `timeout` is not on every machine.
|
|
384
|
+
if [ -n "$epic_pull" ] && command -v rt_epic_pull_base >/dev/null 2>&1; then
|
|
385
|
+
rt_epic_pull_base "$epic_pull" "$cmd"
|
|
386
|
+
elif git rev-parse --verify --quiet "refs/remotes/origin/${main_branch}" >/dev/null 2>&1 \
|
|
352
387
|
&& ! git merge-base --is-ancestor "origin/${main_branch}" HEAD 2>/dev/null; then
|
|
353
388
|
behind="$(git rev-list --count "HEAD..origin/${main_branch}" 2>/dev/null)"
|
|
354
|
-
fault "«${main_branch}»
|
|
389
|
+
fault "«${main_branch}» has moved ahead by ${behind:-several} commits and is not merged into the branch. A PR from a diverged branch shows the reviewer the edit mixed with someone else, and the checks on it run from a stale base. Merge it in and repeat: git fetch origin && git merge origin/${main_branch} — the order and the resolving of the conflict are in the pattern git-workflow-merge."
|
|
355
390
|
fi
|
|
356
391
|
|
|
357
|
-
#
|
|
392
|
+
# The second tier: the local reference could itself have gone stale. No answer — the tier stays
|
|
393
|
+
# silent.
|
|
358
394
|
remote_main="$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=5 GIT_TERMINAL_PROMPT=0 \
|
|
359
395
|
git ls-remote origin "refs/heads/${main_branch}" 2>/dev/null | cut -f1)"
|
|
360
396
|
local_main="$(git rev-parse --verify --quiet "refs/remotes/origin/${main_branch}" 2>/dev/null)"
|
|
361
397
|
if [ -n "$remote_main" ] && [ -n "$local_main" ] && [ "$remote_main" != "$local_main" ]; then
|
|
362
|
-
#
|
|
363
|
-
#
|
|
364
|
-
#
|
|
398
|
+
# The age of the reference is what the executor does not see at all, and it is exactly what
|
|
399
|
+
# tells "the branch is behind" from "I do not know whether it is behind". The `stat` format
|
|
400
|
+
# differs on BSD and on GNU, so both are asked instead of guessing the system.
|
|
365
401
|
fetch_head="$(git rev-parse --git-dir 2>/dev/null)/FETCH_HEAD"
|
|
366
402
|
fetched_at="$(stat -f %m "$fetch_head" 2>/dev/null || stat -c %Y "$fetch_head" 2>/dev/null)"
|
|
367
403
|
age=''
|
|
368
404
|
if [ -n "$fetched_at" ]; then
|
|
369
|
-
age="
|
|
405
|
+
age=" The last git fetch was $(( ( $(date +%s) - fetched_at ) / 60 )) min ago."
|
|
370
406
|
fi
|
|
371
|
-
fault "
|
|
407
|
+
fault "your ref origin/${main_branch} lags behind the remote one — ${local_main:0:8} against ${remote_main:0:8}.${age} The guard compares the branch with what lies in the tree, so silence of the first tier means «the ref is not older than the branch», not «the main branch is merged in». Merge it in and repeat: git fetch origin && git merge origin/${main_branch}."
|
|
372
408
|
fi
|
|
373
409
|
|
|
374
|
-
#
|
|
375
|
-
#
|
|
376
|
-
#
|
|
410
|
+
# The identity of the call. The hosting client holds two accounts — the logged-in one and the one
|
|
411
|
+
# whose token stands in the call environment; which of them opens the PR is visible from the command
|
|
412
|
+
# only through an explicit substitution. The miss surfaces on assigning the reviewer: the author of
|
|
413
|
+
# a PR is never its reviewer, and the author cannot be changed.
|
|
377
414
|
#
|
|
378
|
-
#
|
|
415
|
+
# The command text is checked. A tree that named no token variable gets no requirement.
|
|
379
416
|
if [ -n "$pull_token_var" ] \
|
|
380
417
|
&& ! printf '%s' "$cmd" | grep -qE "(^|[;&|(]|&&|\|\||[[:space:]])${pull_token_var}="; then
|
|
381
|
-
fault "
|
|
418
|
+
fault "the request is opened without the token of the machine account: the command carries no substitution of «${pull_token_var}». Opened by the logged-in account, it comes out from the owner — they cannot be set as the reviewer then, and this is fixed only by reopening.${pull_token_hint:+ Substitute the token: ${pull_token_hint} …}"
|
|
382
419
|
fi
|
|
383
420
|
|
|
384
|
-
#
|
|
385
|
-
#
|
|
386
|
-
#
|
|
421
|
+
# The second tier of the same identity: who actually arrives under this token. A substitution speaks
|
|
422
|
+
# of the intent, not of the result: it read a file that is not on the machine, the client took an
|
|
423
|
+
# empty string for an unset token, and the PR came out from the owner under a command that looked
|
|
424
|
+
# right.
|
|
387
425
|
#
|
|
388
|
-
#
|
|
389
|
-
#
|
|
390
|
-
#
|
|
426
|
+
# The hosting is asked by the tree, not by the package: the hosting, the client and the path to the
|
|
427
|
+
# token are each their own. An empty answer means "asking did not work out": the call is let through,
|
|
428
|
+
# and this is reported — a silent skip is indistinguishable from a check that came together.
|
|
391
429
|
if [ -n "$task_bot" ] && command -v rt_pull_token_login >/dev/null 2>&1; then
|
|
392
430
|
token_login="$(rt_pull_token_login 2>/dev/null)"
|
|
393
431
|
if [ -z "$token_login" ]; then
|
|
394
|
-
printf '
|
|
432
|
+
printf 'the delivery guard: who arrives by the token could not be asked — the check against the answer of the hosting is skipped.\n' >&2
|
|
395
433
|
elif [ "$token_login" != "$task_bot" ]; then
|
|
396
|
-
fault "
|
|
434
|
+
fault "by the token of the call the hosting answers with the account «${token_login}», not the machine one «${task_bot}»: the substitution is in the command, but the value is empty or foreign — that is how a request comes out from the owner. Check that the token file is in place and readable${pull_token_hint:+: ${pull_token_hint}}."
|
|
397
435
|
fi
|
|
398
436
|
fi
|
|
399
437
|
|
|
400
|
-
#
|
|
401
|
-
#
|
|
402
|
-
#
|
|
403
|
-
#
|
|
438
|
+
# The PR body carries the section about the remaining step from the minute it opens: without it the
|
|
439
|
+
# owner merges the PR by the button while the run is still going. The body arrives either as an
|
|
440
|
+
# argument or as a file, both are read here; by the time of the parse the file is already written.
|
|
441
|
+
# Neither one nor the other — there is no requirement: a PR without a body is checked by the line
|
|
442
|
+
# above. The flag is recognised only as a separate word: the tail `-b` of a branch name in the base
|
|
443
|
+
# argument read as the body flag, and the next word of the command became the body.
|
|
404
444
|
if [ -n "$pull_body_section" ]; then
|
|
405
445
|
body=''
|
|
406
446
|
if command -v perl >/dev/null 2>&1; then
|
|
407
447
|
body="$(printf '%s' "$cmd" | perl -0ne '
|
|
408
|
-
if (/(?:--body|-b)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
448
|
+
if (/(?:^|\s)(?:--body|-b)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
409
449
|
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
410
450
|
}
|
|
411
451
|
' 2>/dev/null)"
|
|
412
452
|
body_file="$(printf '%s' "$cmd" | perl -0ne '
|
|
413
|
-
if (/(?:--body-file|-F)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
453
|
+
if (/(?:^|\s)(?:--body-file|-F)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
414
454
|
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
415
455
|
}
|
|
416
456
|
' 2>/dev/null)"
|
|
@@ -418,19 +458,19 @@ if [ -n "$pull_body_section" ]; then
|
|
|
418
458
|
fi
|
|
419
459
|
|
|
420
460
|
if [ -n "$body" ] && ! printf '%s' "$body" | grep -qE "$pull_body_section"; then
|
|
421
|
-
fault "
|
|
461
|
+
fault "the body of the request carries no section about the remaining step. The merge button is pressed by a person on the hosting, where there are no guards, and they merge as soon as they see green: all that holds the requirement there is what the owner read on the page. The section stands last and says exactly one thing — whether anything is left before the merge; it is rewritten by the same call that edits the body."
|
|
422
462
|
fi
|
|
423
463
|
fi
|
|
424
464
|
|
|
425
|
-
check_task "$number" "заявка с ветки «${branch}»" да
|
|
426
465
|
|
|
427
|
-
#
|
|
428
|
-
#
|
|
429
|
-
#
|
|
466
|
+
# The task folder is taken apart before the PR opens, not after the approval: the owner merges as
|
|
467
|
+
# soon as he sees green, and no room is left for a closing commit — three times in a row the folder
|
|
468
|
+
# travelled into the main branch without being taken apart. After the cleanup the progress guard
|
|
469
|
+
# takes the plan from the branch history.
|
|
430
470
|
rt_delivery_open_folder
|
|
431
471
|
|
|
432
|
-
#
|
|
433
|
-
#
|
|
472
|
+
# Everything that did not come together is named here, all at once: up to this line the conditions
|
|
473
|
+
# were being collected, each of which used to refuse the call on its own.
|
|
434
474
|
deny_faults
|
|
435
475
|
|
|
436
476
|
exit 0
|