@rt-tools/agent-kit 0.37.1 → 0.39.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 +5 -5
- package/assets/checks/action-of.mjs +154 -0
- package/assets/checks/board-runs.github.mjs +40 -5
- package/assets/checks/check-board.github.mjs +38 -7
- package/assets/checks/check-state-next.mjs +22 -10
- package/assets/checks/check-turn-map.mjs +26 -6
- package/assets/checks/check-work-steps.mjs +4 -173
- package/assets/checks/decide.mjs +285 -0
- package/assets/checks/decision-table.json +21432 -0
- package/assets/checks/decision-table.mjs +495 -0
- package/assets/checks/epic-window.mjs +98 -0
- package/assets/checks/flow-condition.mjs +64 -0
- package/assets/checks/flow-data.mjs +135 -0
- package/assets/checks/flow-forecast.mjs +334 -0
- package/assets/checks/flow-guard-run.mjs +90 -0
- package/assets/checks/flow-guard.mjs +496 -0
- package/assets/checks/flow-model.mjs +271 -0
- package/assets/checks/flow-override.mjs +130 -0
- package/assets/checks/flow-plan.mjs +206 -0
- package/assets/checks/flow-scaffold.mjs +224 -0
- package/assets/checks/flow-step.mjs +495 -0
- package/assets/checks/flow-sync.mjs +296 -0
- package/assets/checks/flow-syntax.mjs +292 -0
- package/assets/checks/flow-verdict.mjs +227 -0
- package/assets/checks/merge-read.mjs +239 -0
- package/assets/checks/owner-nudges.mjs +389 -0
- package/assets/checks/push-inputs.mjs +59 -16
- package/assets/checks/record-count.mjs +437 -0
- package/assets/checks/record-recount.mjs +187 -0
- package/assets/checks/record-turn.mjs +155 -0
- package/assets/checks/task-flow-script.mjs +318 -0
- package/assets/checks/tree-assignment.mjs +26 -7
- package/assets/checks/work-result.mjs +362 -0
- package/assets/checks/work-steps-lib.mjs +205 -0
- package/assets/commands/night.md +6 -6
- package/assets/defaults/gate-map.sh +39 -12
- package/assets/defaults/merges.sh +48 -0
- package/assets/defaults/project.sh +6 -5
- package/assets/defaults/turn-map.md +23 -22
- package/assets/docs/GLOSSARY.md +5 -1
- package/assets/hooks/ask-judge.md +67 -0
- package/assets/hooks/browser-guard-device-id.sh +11 -9
- package/assets/hooks/browser-guard-no-asking.sh +12 -6
- package/assets/hooks/browser-guard-no-listing.sh +13 -7
- package/assets/hooks/browser-guard-no-other-drivers.sh +25 -17
- package/assets/hooks/browser-guard-require-select.sh +15 -15
- package/assets/hooks/commit-msg.sh +13 -3
- package/assets/hooks/conscience-guard.sh +9 -25
- package/assets/hooks/decide.sh +141 -0
- package/assets/hooks/deny-tail.sh +16 -11
- package/assets/hooks/dev-server-guard.sh +27 -20
- package/assets/hooks/dispatch.sh +47 -4
- package/assets/hooks/docs-guard.sh +31 -200
- package/assets/hooks/end-conversation-guard.sh +12 -21
- package/assets/hooks/epic-stop-guard.sh +54 -152
- package/assets/hooks/exam-guard.sh +32 -65
- package/assets/hooks/facts-docs.sh +221 -0
- package/assets/hooks/facts-flow.sh +173 -0
- package/assets/hooks/facts.sh +374 -0
- package/assets/hooks/flow-step-guard.sh +93 -0
- package/assets/hooks/git-guard-delivery-body.sh +4 -4
- package/assets/hooks/git-guard-delivery-conflict.sh +16 -10
- package/assets/hooks/git-guard-delivery-draft.sh +3 -3
- package/assets/hooks/git-guard-delivery-epic.sh +18 -9
- package/assets/hooks/git-guard-delivery-folder.sh +32 -7
- package/assets/hooks/git-guard-delivery-merge.sh +2 -2
- package/assets/hooks/git-guard-delivery-merged.sh +12 -1
- package/assets/hooks/git-guard-delivery-pipeline.sh +1 -1
- package/assets/hooks/git-guard-delivery-rerun.sh +44 -0
- package/assets/hooks/git-guard-delivery-signature.sh +82 -45
- package/assets/hooks/git-guard-delivery-task.sh +47 -0
- package/assets/hooks/git-guard-delivery.sh +112 -101
- package/assets/hooks/git-guard-discard.sh +8 -18
- package/assets/hooks/git-guard-main.sh +13 -19
- package/assets/hooks/git-guard-no-verify.sh +56 -16
- package/assets/hooks/git-guard-push-ahead.sh +39 -6
- package/assets/hooks/git-guard-push-marks.sh +262 -13
- package/assets/hooks/git-guard-push-tests.sh +58 -52
- package/assets/hooks/git-guard-tree-assignment.sh +7 -4
- package/assets/hooks/guard-note.sh +8 -6
- package/assets/hooks/handoff-entry-guard.sh +19 -38
- package/assets/hooks/handoff-write.sh +3 -1
- package/assets/hooks/hook-input.sh +0 -41
- package/assets/hooks/metric-marks.sh +19 -7
- package/assets/hooks/observe.sh +1 -1
- package/assets/hooks/override-write-guard.sh +27 -9
- package/assets/hooks/pre-push.sh +40 -12
- package/assets/hooks/prose-style-guard.sh +6 -19
- package/assets/hooks/pull-merges.sh +76 -0
- package/assets/hooks/push-ahead-call-guard.sh +447 -0
- package/assets/hooks/push-set.sh +38 -8
- package/assets/hooks/qa-dataid-guard.sh +7 -17
- package/assets/hooks/record-turn.sh +52 -0
- package/assets/hooks/rerun-guard.sh +11 -16
- package/assets/hooks/reuse-first-guard.sh +7 -21
- package/assets/hooks/role-calls.sh +25 -3
- package/assets/hooks/rule-source-guard.sh +54 -21
- package/assets/hooks/skill-gate-rearm.sh +18 -5
- package/assets/hooks/skill-gate.sh +156 -20
- package/assets/hooks/skill-loaded.sh +18 -3
- package/assets/hooks/sql-guard-target.sh +2 -2
- package/assets/hooks/sql-guard-write.sh +12 -12
- package/assets/hooks/sql-guard.sh +58 -16
- package/assets/hooks/task-context-load.sh +3 -1
- package/assets/hooks/task-flow-context.sh +5 -18
- package/assets/hooks/task-flow-draft-guard.sh +25 -74
- package/assets/hooks/task-flow-guard.sh +28 -130
- package/assets/hooks/tree-assignment-guard.sh +25 -14
- package/assets/hooks/turn-entry-load.sh +3 -1
- package/assets/hooks/turn-exit-guard.sh +92 -452
- package/assets/hooks/turn-exit-role.sh +3 -1
- package/assets/hooks/turn-judge.md +113 -0
- package/assets/hooks/window-fill-guard.sh +22 -41
- package/assets/patterns/doc-style-human.md +36 -76
- package/assets/patterns/git-workflow-commit.azure.md +9 -155
- package/assets/patterns/git-workflow-commit.github.md +11 -269
- package/assets/patterns/git-workflow-commit.gitlab.md +9 -161
- package/assets/patterns/git-workflow-docker.md +8 -231
- package/assets/patterns/git-workflow-freshness.md +8 -56
- package/assets/patterns/git-workflow-merge.md +6 -176
- package/assets/patterns/git-workflow-migration.md +5 -75
- package/assets/patterns/git-workflow-pr-body.github.md +6 -159
- package/assets/patterns/git-workflow-pr-ready.md +9 -70
- package/assets/patterns/git-workflow-pr.azure.md +13 -285
- package/assets/patterns/git-workflow-pr.github.md +13 -251
- package/assets/patterns/git-workflow-pr.gitlab.md +13 -286
- package/assets/patterns/git-workflow-restart.md +5 -42
- package/assets/patterns/git-workflow-secrets.md +10 -76
- package/assets/patterns/git-workflow-stack.md +7 -207
- package/assets/patterns/status-report-table.github.md +1 -1
- package/assets/patterns/task-flow-archive.md +12 -233
- package/assets/patterns/task-flow-close.md +16 -292
- package/assets/patterns/task-flow-cycle.md +13 -39
- package/assets/patterns/task-flow-graph.needs-graph.md +8 -62
- package/assets/patterns/task-flow-handoff.md +13 -161
- package/assets/patterns/task-flow-resume.md +18 -218
- package/assets/patterns/task-flow-start.md +9 -247
- package/assets/patterns/turn-entry-map.md +2 -2
- package/assets/pitfalls/agent-kit-extend.md +200 -0
- package/assets/pitfalls/agent-kit.2.md +323 -0
- package/assets/pitfalls/angular-patterns.md +98 -0
- package/assets/pitfalls/browser-verification.md +265 -0
- package/assets/pitfalls/component-structure.md +98 -0
- package/assets/pitfalls/dependencies.md +92 -0
- package/assets/pitfalls/deploy-flow.azure.md +171 -0
- package/assets/pitfalls/deploy-flow.github.md +211 -0
- package/assets/pitfalls/deploy-flow.gitlab.md +173 -0
- package/assets/pitfalls/doc-style-human.md +112 -0
- package/assets/pitfalls/doc-style.2.md +286 -0
- package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
- package/assets/pitfalls/entity-models.md +89 -0
- package/assets/pitfalls/epic-flow.md +92 -0
- package/assets/pitfalls/git-workflow-commit.azure.md +190 -0
- package/assets/pitfalls/git-workflow-commit.github.md +307 -0
- package/assets/pitfalls/git-workflow-commit.gitlab.md +196 -0
- package/assets/pitfalls/git-workflow-docker.md +275 -0
- package/assets/pitfalls/git-workflow-freshness.md +88 -0
- package/assets/pitfalls/git-workflow-hosting.azure.md +31 -0
- package/assets/pitfalls/git-workflow-hosting.github.md +32 -0
- package/assets/pitfalls/git-workflow-hosting.gitlab.md +31 -0
- package/assets/pitfalls/git-workflow-merge.md +220 -0
- package/assets/pitfalls/git-workflow-migration.md +103 -0
- package/assets/pitfalls/git-workflow-pr-body.github.md +185 -0
- package/assets/pitfalls/git-workflow-pr-ready.md +104 -0
- package/assets/pitfalls/git-workflow-pr.2.azure.md +172 -0
- package/assets/pitfalls/git-workflow-pr.2.github.md +184 -0
- package/assets/pitfalls/git-workflow-pr.2.gitlab.md +180 -0
- package/assets/pitfalls/git-workflow-pr.azure.md +159 -0
- package/assets/pitfalls/git-workflow-pr.github.md +107 -0
- package/assets/pitfalls/git-workflow-pr.gitlab.md +151 -0
- package/assets/pitfalls/git-workflow-push.azure.md +30 -0
- package/assets/pitfalls/git-workflow-push.github.md +30 -0
- package/assets/pitfalls/git-workflow-push.gitlab.md +30 -0
- package/assets/pitfalls/git-workflow-queue.azure.md +30 -0
- package/assets/pitfalls/git-workflow-queue.github.md +30 -0
- package/assets/pitfalls/git-workflow-queue.gitlab.md +30 -0
- package/assets/pitfalls/git-workflow-restart.md +72 -0
- package/assets/pitfalls/git-workflow-secrets.md +114 -0
- package/assets/pitfalls/git-workflow-stack.md +254 -0
- package/assets/pitfalls/git-workflow.2.azure.md +291 -0
- package/assets/pitfalls/git-workflow.2.github.md +294 -0
- package/assets/pitfalls/git-workflow.2.gitlab.md +278 -0
- package/assets/pitfalls/lib-layers.md +114 -0
- package/assets/pitfalls/lists.md +117 -0
- package/assets/pitfalls/mockups.needs-mockups.md +87 -0
- package/assets/pitfalls/navigation.md +94 -0
- package/assets/pitfalls/observability.needs-app.md +186 -0
- package/assets/pitfalls/platform-access.md +94 -0
- package/assets/pitfalls/queue-audit.github.md +78 -0
- package/assets/pitfalls/reuse-first.md +201 -0
- package/assets/pitfalls/spec-driven.2.md +318 -0
- package/assets/pitfalls/styling-bem.2.md +125 -0
- package/assets/pitfalls/task-flow-archive.md +265 -0
- package/assets/pitfalls/task-flow-close.2.md +166 -0
- package/assets/pitfalls/task-flow-close.md +167 -0
- package/assets/pitfalls/task-flow-cycle.md +73 -0
- package/assets/pitfalls/task-flow-graph.needs-graph.md +98 -0
- package/assets/pitfalls/task-flow-handoff.md +200 -0
- package/assets/pitfalls/task-flow-handover.md +30 -0
- package/assets/pitfalls/task-flow-owner.md +58 -0
- package/assets/pitfalls/task-flow-plan.md +29 -0
- package/assets/pitfalls/task-flow-resume.md +257 -0
- package/assets/pitfalls/task-flow-start.md +287 -0
- package/assets/pitfalls/task-flow.2.md +303 -0
- package/assets/pitfalls/task-flow.md +4 -4
- package/assets/pitfalls/testing.2.md +279 -0
- package/assets/pitfalls/turn-conduct.md +16 -17
- package/assets/pitfalls/typescript-conventions.md +161 -0
- package/assets/pitfalls/write-a-skill.md +128 -0
- package/assets/rules/angular-patterns.md +21 -86
- package/assets/rules/autonomous-work.md +2 -2
- package/assets/rules/browser-verification.md +28 -256
- package/assets/rules/component-structure.md +25 -87
- package/assets/rules/dependencies.md +20 -78
- package/assets/rules/deploy-flow.azure.md +26 -156
- package/assets/rules/deploy-flow.github.md +34 -200
- package/assets/rules/deploy-flow.gitlab.md +27 -159
- package/assets/rules/doc-style.md +32 -286
- package/assets/rules/entity-conventions.needs-admin.md +26 -82
- package/assets/rules/entity-models.md +14 -63
- package/assets/rules/epic-flow.md +24 -63
- package/assets/rules/git-workflow-hosting.azure.md +26 -0
- package/assets/rules/git-workflow-hosting.github.md +38 -0
- package/assets/rules/git-workflow-hosting.gitlab.md +27 -0
- package/assets/rules/git-workflow-push.azure.md +28 -0
- package/assets/rules/git-workflow-push.github.md +28 -0
- package/assets/rules/git-workflow-push.gitlab.md +28 -0
- package/assets/rules/git-workflow-queue.azure.md +23 -0
- package/assets/rules/git-workflow-queue.github.md +30 -0
- package/assets/rules/git-workflow-queue.gitlab.md +23 -0
- package/assets/rules/git-workflow.azure.md +21 -282
- package/assets/rules/git-workflow.github.md +24 -284
- package/assets/rules/git-workflow.gitlab.md +21 -269
- package/assets/rules/lib-layers.md +30 -103
- package/assets/rules/lists.md +21 -105
- package/assets/rules/mockups.needs-mockups.md +25 -64
- package/assets/rules/navigation.md +10 -69
- package/assets/rules/observability.needs-app.md +43 -172
- package/assets/rules/platform-access.md +28 -75
- package/assets/rules/queue-audit.github.md +25 -52
- package/assets/rules/reuse-first.md +20 -195
- package/assets/rules/spec-driven.md +35 -308
- package/assets/rules/styling-bem.md +20 -117
- package/assets/rules/task-flow-handover.md +24 -0
- package/assets/rules/task-flow-owner.md +34 -0
- package/assets/rules/task-flow-plan.md +38 -0
- package/assets/rules/task-flow.md +22 -300
- package/assets/rules/testing.md +32 -273
- package/assets/rules/turn-conduct.md +105 -106
- package/assets/rules/turn-entry.md +2 -2
- package/assets/rules/typescript-conventions.md +41 -147
- package/assets/samples/tasks/_template/plan.md +30 -6
- package/assets/samples/tasks/_template/progress.md +0 -1
- package/assets/skills/agent-kit-extend.md +25 -168
- package/assets/skills/agent-kit.md +27 -299
- package/assets/skills/write-a-skill.md +20 -106
- package/assets/task-flow/flow.js +184 -0
- package/assets/task-flow/flow.md +101 -0
- package/assets/task-flow/measure/agreement.mjs +24 -0
- package/assets/task-flow/measure/ci.mjs +184 -0
- package/assets/task-flow/measure/copy.mjs +22 -0
- package/assets/task-flow/measure/epic-of.mjs +50 -0
- package/assets/task-flow/measure/epic-text.mjs +35 -0
- package/assets/task-flow/measure/epic.mjs +114 -0
- package/assets/task-flow/measure/folder.mjs +16 -0
- package/assets/task-flow/measure/footprint.mjs +28 -0
- package/assets/task-flow/measure/grill.mjs +21 -0
- package/assets/task-flow/measure/host.mjs +8 -0
- package/assets/task-flow/measure/owner.mjs +27 -0
- package/assets/task-flow/measure/plan.mjs +27 -0
- package/assets/task-flow/measure/pr.mjs +20 -0
- package/assets/task-flow/measure/progress.mjs +50 -0
- package/assets/task-flow/measure/session.mjs +252 -0
- package/assets/task-flow/measure/task.mjs +23 -0
- package/assets/task-flow/measure/text.mjs +77 -0
- package/assets/task-flow/source/git.mjs +254 -0
- package/assets/task-flow/source/host.mjs +277 -0
- package/assets/task-flow/source/marks.mjs +56 -0
- package/assets/task-flow/source/owner.mjs +94 -0
- package/assets/task-flow/source/records.mjs +116 -0
- package/assets/task-flow/source/session.mjs +269 -0
- package/assets/task-flow/source/steps.mjs +28 -0
- package/assets/task-flow/source/tree.mjs +42 -0
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +30 -0
- package/bin/agent-kit.js.map +1 -1
- package/lib/agent-checks.d.ts +55 -0
- package/lib/agent-checks.d.ts.map +1 -0
- package/lib/agent-checks.js +221 -0
- package/lib/agent-checks.js.map +1 -0
- package/lib/assets.d.ts.map +1 -1
- package/lib/assets.js +7 -2
- package/lib/assets.js.map +1 -1
- package/lib/cargo.d.ts +29 -0
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +27 -1
- package/lib/cargo.js.map +1 -1
- package/lib/cascade.d.ts.map +1 -1
- package/lib/cascade.js +3 -1
- package/lib/cascade.js.map +1 -1
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +78 -2
- package/lib/commands.js.map +1 -1
- package/lib/config.d.ts +18 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +18 -1
- package/lib/config.js.map +1 -1
- package/lib/epic-window-send.d.ts +74 -0
- package/lib/epic-window-send.d.ts.map +1 -0
- package/lib/epic-window-send.js +166 -0
- package/lib/epic-window-send.js.map +1 -0
- package/lib/hooks-map.d.ts +4 -0
- package/lib/hooks-map.d.ts.map +1 -1
- package/lib/hooks-map.js +2 -2
- package/lib/hooks-map.js.map +1 -1
- package/lib/integrity.d.ts +3 -0
- package/lib/integrity.d.ts.map +1 -1
- package/lib/integrity.js +7 -0
- package/lib/integrity.js.map +1 -1
- package/lib/metric-lines.d.ts +2 -1
- package/lib/metric-lines.d.ts.map +1 -1
- package/lib/metric-lines.js +49 -1
- package/lib/metric-lines.js.map +1 -1
- package/lib/metric-send-mark.d.ts +6 -3
- package/lib/metric-send-mark.d.ts.map +1 -1
- package/lib/metric-send-mark.js +15 -5
- package/lib/metric-send-mark.js.map +1 -1
- package/lib/metric-send.d.ts +6 -2
- package/lib/metric-send.d.ts.map +1 -1
- package/lib/metric-send.js +47 -13
- package/lib/metric-send.js.map +1 -1
- package/lib/metrics.d.ts +17 -0
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js +26 -15
- package/lib/metrics.js.map +1 -1
- package/lib/observations.js +3 -3
- package/lib/observations.js.map +1 -1
- package/lib/outcomes.d.ts +5 -2
- package/lib/outcomes.d.ts.map +1 -1
- package/lib/outcomes.js +5 -4
- package/lib/outcomes.js.map +1 -1
- package/lib/push-gate.d.ts +13 -0
- package/lib/push-gate.d.ts.map +1 -1
- package/lib/push-gate.js +11 -7
- package/lib/push-gate.js.map +1 -1
- package/lib/push-set-usefulness.d.ts +78 -0
- package/lib/push-set-usefulness.d.ts.map +1 -0
- package/lib/push-set-usefulness.js +225 -0
- package/lib/push-set-usefulness.js.map +1 -0
- package/lib/sync.d.ts +10 -0
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +14 -1
- package/lib/sync.js.map +1 -1
- package/lib/work-result.d.ts +43 -0
- package/lib/work-result.d.ts.map +1 -0
- package/lib/work-result.js +39 -0
- package/lib/work-result.js.map +1 -0
- package/package.json +1 -1
- package/assets/hooks/claim-guard.sh +0 -212
- package/assets/hooks/grill-gate-ask.sh +0 -26
- package/assets/hooks/grill-gate-bypass.sh +0 -61
- package/assets/hooks/grill-gate-options.sh +0 -50
- package/assets/hooks/grill-gate.sh +0 -482
- package/assets/hooks/postmortem-guard.sh +0 -124
- package/assets/hooks/proposal-guard.sh +0 -154
- package/assets/hooks/stand-login-guard.sh +0 -107
- package/assets/hooks/turn-exit-epic.sh +0 -173
- package/assets/hooks/turn-exit-patterns.sh +0 -123
- package/assets/hooks/turn-exit-verdict.sh +0 -149
- package/assets/hooks/waiting-turn-guard.sh +0 -320
- package/assets/hooks/work-start-guard.sh +0 -175
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# rt-hook: PreToolUse Edit|Write|MultiEdit|mcp__webstorm__create_new_file|Bash|mcp__webstorm__execute_terminal_command
|
|
3
|
-
# Requires: agents/strict-teacher.md, hooks/roles.sh, hooks/deny-tail.sh, hooks/write-targets.sh
|
|
3
|
+
# Requires: checks/decide.mjs, hooks/decide.sh, hooks/facts.sh, agents/strict-teacher.md, hooks/roles.sh, hooks/deny-tail.sh, hooks/write-targets.sh
|
|
4
4
|
# Exam guard: no edit goes through until the exam on the loaded rules has been passed this session.
|
|
5
5
|
#
|
|
6
6
|
# Why this way. The rules gate demands that a rule be loaded before an edit, and ends there: to
|
|
@@ -40,6 +40,7 @@ RT_GUARD_NAME=exam-guard
|
|
|
40
40
|
|
|
41
41
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
42
42
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
43
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/facts.sh" 2>/dev/null || true
|
|
43
44
|
|
|
44
45
|
rt_hook_read
|
|
45
46
|
input="$RT_HOOK_INPUT"
|
|
@@ -81,6 +82,17 @@ case "$tool" in
|
|
|
81
82
|
Edit | Write | MultiEdit | mcp__webstorm__create_new_file)
|
|
82
83
|
target="$(printf '%s' "$input" | jq -r '.tool_input.file_path // .tool_input.pathInProject // empty' 2>/dev/null)"
|
|
83
84
|
[ -n "$target" ] && [ "$(printf '%s\n' "$target" | rt_exam_free_paths)" = "yes" ] && exit 0
|
|
85
|
+
# A window past its stop threshold: the window guard lets through only the closing — the
|
|
86
|
+
# progress and the handover — and refuses the examiner role itself. Holding the progress
|
|
87
|
+
# for an exam then names a move the window guard denies, and the session cannot close.
|
|
88
|
+
# The window fact reads the mark of the window guard, and before the mark it counts the fill
|
|
89
|
+
# the way the window guard counts it.
|
|
90
|
+
case "$target" in
|
|
91
|
+
*/docs/tasks/*/progress.md | docs/tasks/*/progress.md)
|
|
92
|
+
exam_sid="$(printf '%s' "$input" | jq -r '.session_id // "unknown"' 2>/dev/null)"
|
|
93
|
+
[ "$(rt_fact_window_over_stop "$exam_sid" "$(rt_fact_transcript "$input")")" = yes ] && exit 0
|
|
94
|
+
;;
|
|
95
|
+
esac
|
|
84
96
|
;;
|
|
85
97
|
Bash | mcp__webstorm__execute_terminal_command)
|
|
86
98
|
cmd="$(rt_hook_cmd)"
|
|
@@ -102,17 +114,10 @@ case "$tool" in
|
|
|
102
114
|
*) exit 0 ;;
|
|
103
115
|
esac
|
|
104
116
|
|
|
105
|
-
transcript="$(
|
|
117
|
+
transcript="$(rt_fact_transcript "$input")"
|
|
106
118
|
[ -z "$transcript" ] && exit 0
|
|
107
119
|
[ -f "$transcript" ] || exit 0
|
|
108
120
|
|
|
109
|
-
# The shared deny tail: two lawful moves and the lawful form of bypass, if the refusal has one.
|
|
110
|
-
# The file may not be laid out — then there is no tail, and the reason for the refusal stays.
|
|
111
|
-
# shellcheck disable=SC1090
|
|
112
|
-
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
113
|
-
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
114
|
-
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
115
|
-
|
|
116
121
|
# The second way out of the refusal — one that does not require lifting protection.
|
|
117
122
|
#
|
|
118
123
|
# The guard used to name the list of disabled roles in the tree settings as the only way out. The
|
|
@@ -128,68 +133,30 @@ rt_exam_declared_skip() {
|
|
|
128
133
|
| grep -qE '^Exam-skip:[[:space:]]*[^[:space:]<]'
|
|
129
134
|
}
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
# The decision, the move and the text come from the decision table. A declared bypass lets the call
|
|
137
|
+
# through before the table is asked: it is the lawful way out the refusal itself names.
|
|
138
|
+
# Parameters: the action (empty — the decider takes it from the call), the facts.
|
|
139
|
+
decide_exam() {
|
|
132
140
|
if rt_exam_declared_skip; then
|
|
133
141
|
printf 'the exam guard: a bypass is declared in the body of the last commit by the line Exam-skip. The call is let through, the record stays in the history.\n' >&2
|
|
134
142
|
exit 0
|
|
135
143
|
fi
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
# The named move is the call of the exam role; the window guard judges it by the window and by
|
|
145
|
+
# the rule of the course of work loaded for the closing edits.
|
|
146
|
+
exam_sid="$(printf '%s' "$input" | jq -r '.session_id // "unknown"' 2>/dev/null)"
|
|
147
|
+
exam_facts="$(jq -cn --argjson f "$2" \
|
|
148
|
+
--arg w "$(rt_fact_window_over_stop "$exam_sid" "$transcript")" \
|
|
149
|
+
--arg r "$(rt_fact_rule_loaded "${RT_TASK_FLOW_RULE:-task-flow}" "$exam_sid")" \
|
|
150
|
+
'$f + {window_over_stop:$w, rule_loaded:$r}')"
|
|
151
|
+
# shellcheck disable=SC1091
|
|
152
|
+
. "$rt_hooks_dir/decide.sh" 2>/dev/null
|
|
153
|
+
command -v rt_decide >/dev/null 2>&1 && rt_decide exam-guard.sh "$1" "$exam_facts" '{}' PreToolUse "$input"
|
|
142
154
|
exit 0
|
|
143
155
|
}
|
|
144
156
|
|
|
145
157
|
# The whole session is judged, not the last turn: the exam is passed once at the start and holds
|
|
146
158
|
# to the end.
|
|
147
|
-
verdict="$(
|
|
148
|
-
def textof:
|
|
149
|
-
if type == "string" then .
|
|
150
|
-
elif type == "array" then (map(if type == "object" then (.text // "") else tostring end) | join("\n"))
|
|
151
|
-
else tostring end;
|
|
152
|
-
|
|
153
|
-
# The call whose answer is discarded is recognised by its identifier, and the identifier is
|
|
154
|
-
# bound by a name: a dot after a pipe means the list itself, the search over it answers zero
|
|
155
|
-
# on any non-empty list, and every answer of every tool gets muted at once — that is, the
|
|
156
|
-
# verdict is looked for in the host records alone.
|
|
157
|
-
#
|
|
158
|
-
# Tools that read and write files: their result does not count as a verdict — otherwise
|
|
159
|
-
# echoing the same line or reading a file with it passes the guard, and the real verdict
|
|
160
|
-
# does not.
|
|
161
|
-
["Bash", "Read", "Grep", "Glob", "Edit", "Write", "MultiEdit", "NotebookEdit"] as $mute
|
|
162
|
-
| ([.[] | select(.type == "assistant") | (.message.content // [])[]
|
|
163
|
-
| select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null)
|
|
164
|
-
| {key: (.id // ""), value: true}] | from_entries) as $muted
|
|
165
|
-
|
|
166
|
-
| [ .[]
|
|
167
|
-
# The assistant text is never a verdict: writing the needed line in a reply costs one
|
|
168
|
-
# move.
|
|
169
|
-
| if .type == "assistant" then ""
|
|
170
|
-
elif .type == "user" then
|
|
171
|
-
([ ((.message.content // []) | if type == "array" then .[] else empty end
|
|
172
|
-
| select(.type == "tool_result")
|
|
173
|
-
| select((.tool_use_id // "") | if . == "" then true else ($muted[.] | not) end)
|
|
174
|
-
| .content | textof),
|
|
175
|
-
((.message.content // "") | if type == "string" then . else "" end),
|
|
176
|
-
# The call result field: the same record, another form. Discarded only when
|
|
177
|
-
# this result belongs to a reading or writing tool.
|
|
178
|
-
(. as $rec
|
|
179
|
-
| if ($rec.toolUseResult // null) == null then ""
|
|
180
|
-
elif ([($rec.message.content // []) | if type == "array" then .[] else empty end
|
|
181
|
-
| select(.type == "tool_result") | (.tool_use_id // "")]
|
|
182
|
-
| map($muted[.] // false) | any) then ""
|
|
183
|
-
else ($rec.toolUseResult | textof) end)
|
|
184
|
-
] | join("\n"))
|
|
185
|
-
# Host records — the role completion notice and the attachment: the host chooses their
|
|
186
|
-
# form, and they count whole.
|
|
187
|
-
else tostring end ] | join("\n")
|
|
188
|
-
| [scan("(ЭКЗАМЕН:[[:space:]]*сдано|EXAM:[[:space:]]*passed)[[:space:]]*([0-9]+)[[:space:]]*(из|of)[[:space:]]*([0-9]+)")]
|
|
189
|
-
| if length == 0 then "none"
|
|
190
|
-
else (.[-1] | if .[1] == .[3] then "passed" else "failed" end)
|
|
191
|
-
end
|
|
192
|
-
' "$transcript" 2>/dev/null)"
|
|
159
|
+
verdict="$(rt_fact_exam "$transcript")"
|
|
193
160
|
|
|
194
161
|
# The second exam is the one placed after the PR is opened. The first does not replace it: they
|
|
195
162
|
# ask about different things, and the whole work lies between them.
|
|
@@ -247,7 +214,7 @@ if [ "$ready" = "1" ]; then
|
|
|
247
214
|
case "$after" in
|
|
248
215
|
passed | no-pr) exit 0 ;;
|
|
249
216
|
*)
|
|
250
|
-
|
|
217
|
+
decide_exam pr_ready '{"exam_after_pr":"none"}'
|
|
251
218
|
;;
|
|
252
219
|
esac
|
|
253
220
|
fi
|
|
@@ -260,9 +227,9 @@ fi
|
|
|
260
227
|
case "$verdict" in
|
|
261
228
|
passed) exit 0 ;;
|
|
262
229
|
failed)
|
|
263
|
-
|
|
230
|
+
decide_exam "?edit_code" '{"exam":"failed"}'
|
|
264
231
|
;;
|
|
265
232
|
*)
|
|
266
|
-
|
|
233
|
+
decide_exam "?edit_code" '{"exam":"none"}'
|
|
267
234
|
;;
|
|
268
235
|
esac
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The fact of the document pair: what a commit edits without the document that describes it. NOT a
|
|
3
|
+
# guard: it has no `rt-hook:` declaration and hooks into no agent event. The document guard decides
|
|
4
|
+
# by it, and the hooks of delivery name it first when their refusal names a commit.
|
|
5
|
+
#
|
|
6
|
+
# rt_fact_doc_problems <command>
|
|
7
|
+
#
|
|
8
|
+
# Returns 1 when there is nothing to judge — not a commit of this tree, a declared bypass, no edits;
|
|
9
|
+
# otherwise 0, with `problems` holding the list of what is missing (empty — the pair holds),
|
|
10
|
+
# `first_doc` the first document awaited and `paths` the paths of the commit. Reads the tree profile
|
|
11
|
+
# the caller has loaded: `laws_dir`, `lib_marker`, `overrides_dir` and the profile functions.
|
|
12
|
+
#
|
|
13
|
+
# FAIL-OPEN: no git, not a repository — returns 1, and the caller judges nothing.
|
|
14
|
+
|
|
15
|
+
rt_fact_doc_problems() {
|
|
16
|
+
# The names the analysis uses stay its own: the caller keeps its command, root and work directory.
|
|
17
|
+
local cmd="$1" root companion dir from gone kept moved_added moved_deleted need_readme spec spec_paths spec_prefix to want workdir changes source_mode rule
|
|
18
|
+
problems=''
|
|
19
|
+
first_doc=''
|
|
20
|
+
paths=''
|
|
21
|
+
laws_dir="${laws_dir:-${RT_LAWS_DIR:-docs/constitution}}"
|
|
22
|
+
lib_marker="${lib_marker:-${RT_LIB_MARKER:-project.json}}"
|
|
23
|
+
overrides_dir="${overrides_dir:-${RT_OVERRIDES_DIR:-.claude/rt-kit/overrides}}"
|
|
24
|
+
command -v rt_needs >/dev/null 2>&1 || rt_needs() { command -v "$1" >/dev/null 2>&1; }
|
|
25
|
+
# The reason for the bypass stays in the history, so the bypass is lawful. An empty line does not
|
|
26
|
+
# count as a bypass: "Docs-skip:" without a reason is the same silent skip, only with a colon.
|
|
27
|
+
#
|
|
28
|
+
# The line starts a line — its own in the commit body, or a comment at the end of the command — and
|
|
29
|
+
# takes no substitutions. The same condition as for the bypass at the merge: otherwise a text that
|
|
30
|
+
# EXPLAINS the bypass lifts the requirement all by itself. A commit body about an edit of the guard
|
|
31
|
+
# names exactly this line, and without the binding to the start the guard would let such a commit
|
|
32
|
+
# through silently.
|
|
33
|
+
if printf '%s' "$cmd" | grep -qiE '(^|#)[[:space:]]*Docs-skip:[[:space:]]*[^[:space:]<"'"'"'][^[:space:]"'"'"']{2,}'; then
|
|
34
|
+
return 1
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
workdir="$(rt_hook_cwd)"
|
|
38
|
+
[ -z "$workdir" ] && workdir="${CLAUDE_PROJECT_DIR:-.}"
|
|
39
|
+
cd "$workdir" 2>/dev/null || return 1
|
|
40
|
+
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return 1
|
|
41
|
+
|
|
42
|
+
# `-a` takes all tracked edits, `--amend` takes the files of the rewritten commit as well. Always
|
|
43
|
+
# counting by the index would mean checking a set other than the one that travels into the history.
|
|
44
|
+
changes=''
|
|
45
|
+
source_mode='index'
|
|
46
|
+
case "$cmd" in
|
|
47
|
+
*' -a'* | *--all*)
|
|
48
|
+
changes="$(git diff HEAD --name-status -M 2>/dev/null)"
|
|
49
|
+
source_mode='worktree'
|
|
50
|
+
;;
|
|
51
|
+
*) changes="$(git diff --cached --name-status -M 2>/dev/null)" ;;
|
|
52
|
+
esac
|
|
53
|
+
case "$cmd" in
|
|
54
|
+
*--amend*) changes="$(printf '%s\n%s' "$changes" "$(git show --name-status --format= HEAD 2>/dev/null)")" ;;
|
|
55
|
+
esac
|
|
56
|
+
|
|
57
|
+
changes="$(printf '%s\n' "$changes" | grep -v '^[[:space:]]*$')"
|
|
58
|
+
|
|
59
|
+
# `git commit -- <paths>` commits those paths alone, whatever else the index holds: the guard counts
|
|
60
|
+
# the set that travels, and a staged file left out of this commit is judged by the commit that takes
|
|
61
|
+
# it. The paths are given from the directory of the call, the list of edits from the root.
|
|
62
|
+
spec_paths="$(printf '%s\n' "$cmd" | sed -nE 's/.*git[[:space:]]+commit[^;&|]*[[:space:]]--[[:space:]]+([^;&|]+).*/\1/p' | head -1)"
|
|
63
|
+
if [ -n "$spec_paths" ]; then
|
|
64
|
+
spec_prefix="$(git rev-parse --show-prefix 2>/dev/null)"
|
|
65
|
+
kept=''
|
|
66
|
+
for spec in $spec_paths; do
|
|
67
|
+
spec="$(printf '%s' "$spec" | tr -d "\"'")"
|
|
68
|
+
spec="${spec_prefix}${spec%/}"
|
|
69
|
+
kept="${kept}$(printf '%s\n' "$changes" | awk -F'\t' -v s="$spec" '{ for (i = 2; i <= NF; i++) if ($i == s || index($i, s "/") == 1) { print; next } }')
|
|
70
|
+
"
|
|
71
|
+
done
|
|
72
|
+
changes="$(printf '%s' "$kept" | grep -v '^[[:space:]]*$' | sort -u)"
|
|
73
|
+
fi
|
|
74
|
+
[ -z "$changes" ] && return 1
|
|
75
|
+
|
|
76
|
+
# The paths of the commit without the statuses. A rename comes as three fields — we take both sides.
|
|
77
|
+
paths="$(printf '%s\n' "$changes" | awk -F'\t' '{ for (i = 2; i <= NF; i++) if ($i != "") print $i }' | sort -u)"
|
|
78
|
+
|
|
79
|
+
has_path() { printf '%s\n' "$paths" | grep -qxF "$1"; }
|
|
80
|
+
|
|
81
|
+
# The content as it will travel into the commit. The source is the same one the list of edits was
|
|
82
|
+
# collected by: `-a` takes the working tree, an ordinary commit takes the index. Always reading the
|
|
83
|
+
# index is not allowed — under `-a` the previous edition lies there, and the guard would hold the
|
|
84
|
+
# very commit that fixes the divergence; always reading the working tree is not allowed either — an
|
|
85
|
+
# unstaged edit will not get into the commit.
|
|
86
|
+
content_of() {
|
|
87
|
+
if [ "$source_mode" = 'worktree' ]; then
|
|
88
|
+
cat "$1" 2>/dev/null
|
|
89
|
+
else
|
|
90
|
+
git show ":$1" 2>/dev/null || cat "$1" 2>/dev/null
|
|
91
|
+
fi
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
problems=''
|
|
95
|
+
# The first document the refusal awaits: the edit of it is the move the refusal names, and a
|
|
96
|
+
# neighbouring guard may hold that edit — the exam, the rule of the file, the handover entry.
|
|
97
|
+
first_doc=''
|
|
98
|
+
add() { problems="${problems}
|
|
99
|
+
• $1"; }
|
|
100
|
+
|
|
101
|
+
# ── 1. A rule and its companion ───────────────────────────────────────────────
|
|
102
|
+
#
|
|
103
|
+
# The statements of a rule are keyed by their own text, and a rewording without an edit of the
|
|
104
|
+
# companion breaks the link silently. The spec audit catches this, but it is run at the push gate —
|
|
105
|
+
# here the same pair meets a commit earlier, while the edit is still in the author's head.
|
|
106
|
+
#
|
|
107
|
+
# The section with the statements is the only thing linked to the companion; an edit of "Pitfalls"
|
|
108
|
+
# or of the "Where it lives" table does not touch it, so only this section is compared. The name of
|
|
109
|
+
# the section is double: English in a package rule, Russian in a rule written by the tree before the
|
|
110
|
+
# layer was translated. The end of the range is any heading not starting with their first letter.
|
|
111
|
+
STATEMENTS='/^## (How the law applies here|Как закон применяется здесь)$/,/^## [^КH]/'
|
|
112
|
+
statements_of() { content_of "$1" | awk "$STATEMENTS"; }
|
|
113
|
+
|
|
114
|
+
for rule in $(printf '%s\n' "$paths" | grep -E '/SKILL\.md$'); do
|
|
115
|
+
grep -q '^kind: rule$' "$rule" 2>/dev/null || continue
|
|
116
|
+
companion="${rule%/SKILL.md}/implementation.md"
|
|
117
|
+
|
|
118
|
+
[ -f "$companion" ] || continue
|
|
119
|
+
has_path "$companion" && continue
|
|
120
|
+
|
|
121
|
+
if [ "$(statements_of "$rule")" != "$(git show "HEAD:$rule" 2>/dev/null | awk "$STATEMENTS")" ]; then
|
|
122
|
+
add "the statements of \`$rule\` are edited without the companion — add \`$companion\` to the commit"
|
|
123
|
+
[ -n "$first_doc" ] || first_doc="$companion"
|
|
124
|
+
fi
|
|
125
|
+
done
|
|
126
|
+
|
|
127
|
+
# ── 2. The pairs the tree names ───────────────────────────────────────────────
|
|
128
|
+
#
|
|
129
|
+
# The contract and the domain spec, a guard and its scenarios — which exactly, the profile knows:
|
|
130
|
+
# every tree has a link of its own, and the mechanics are one.
|
|
131
|
+
if rt_needs rt_docs_pair_for docs-guard; then
|
|
132
|
+
while IFS= read -r file; do
|
|
133
|
+
[ -z "$file" ] && continue
|
|
134
|
+
|
|
135
|
+
# A file put in place by the layout demands no pair: it has one author in a consuming tree
|
|
136
|
+
# — the package, and the document about it lies there as well. Otherwise the very first
|
|
137
|
+
# layout demands a bypass over its whole volume, and a bypass declared over a hundred files
|
|
138
|
+
# lifts the requirement from future hand edits of those files too. The sign is the layout
|
|
139
|
+
# header: it stands in every laid-out file and tells it apart more reliably than any list
|
|
140
|
+
# of paths.
|
|
141
|
+
if [ -f "$file" ] && head -12 "$file" 2>/dev/null | grep -qE 'rt-kit v[^ ]+ · [^ ]+ · [0-9a-f]+'; then
|
|
142
|
+
continue
|
|
143
|
+
fi
|
|
144
|
+
|
|
145
|
+
want="$(rt_docs_pair_for "$file" 2>/dev/null)"
|
|
146
|
+
[ -z "$want" ] && continue
|
|
147
|
+
# The pair counts as arrived if at least one file of the commit fits the pattern.
|
|
148
|
+
printf '%s\n' "$paths" | grep -qE "$want" && continue
|
|
149
|
+
add "\`$file\` is edited without its document — the same commit awaits \`$want\`"
|
|
150
|
+
[ -n "$first_doc" ] || first_doc="$(git ls-files -co --exclude-standard 2>/dev/null | grep -E "^${want}\$" | head -1)"
|
|
151
|
+
done <<EOF
|
|
152
|
+
$paths
|
|
153
|
+
EOF
|
|
154
|
+
fi
|
|
155
|
+
|
|
156
|
+
# ── 3. A lib and its README ───────────────────────────────────────────────────
|
|
157
|
+
|
|
158
|
+
lib_root() {
|
|
159
|
+
dir="${1%/*}"
|
|
160
|
+
while [ -n "$dir" ] && [ "$dir" != "." ]; do
|
|
161
|
+
[ -f "$dir/$lib_marker" ] && { printf '%s' "$dir"; return 0; }
|
|
162
|
+
case "$dir" in */*) dir="${dir%/*}" ;; *) dir='' ;; esac
|
|
163
|
+
done
|
|
164
|
+
|
|
165
|
+
return 1
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
need_readme=''
|
|
169
|
+
want_readme() {
|
|
170
|
+
root="$1"
|
|
171
|
+
[ -n "$root" ] || return 0
|
|
172
|
+
case " $need_readme " in *" $root "*) return 0 ;; esac
|
|
173
|
+
need_readme="$need_readme $root"
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
# Creating and removing a lib: the README is the only place where it is written what lies in it and
|
|
177
|
+
# who calls it, and it survives the layout only together with an edit of that text.
|
|
178
|
+
while IFS="$(printf '\t')" read -r status first second; do
|
|
179
|
+
case "$status" in
|
|
180
|
+
A* | D*)
|
|
181
|
+
case "$first" in */"$lib_marker") want_readme "${first%/"$lib_marker"}" ;; esac
|
|
182
|
+
;;
|
|
183
|
+
R*)
|
|
184
|
+
# A move of a file changes both sides: from one lib it disappeared, in the other it
|
|
185
|
+
# appeared.
|
|
186
|
+
from="$(lib_root "$first")" && to="$(lib_root "$second")"
|
|
187
|
+
if [ -n "$from" ] && [ -n "$to" ] && [ "$from" != "$to" ]; then
|
|
188
|
+
want_readme "$from"
|
|
189
|
+
want_readme "$to"
|
|
190
|
+
fi
|
|
191
|
+
;;
|
|
192
|
+
esac
|
|
193
|
+
done <<EOF
|
|
194
|
+
$changes
|
|
195
|
+
EOF
|
|
196
|
+
|
|
197
|
+
# A move given as the pair "deleted there, added here": not everything that is a rename counts as
|
|
198
|
+
# one — an edit of the content while moving throws the search off.
|
|
199
|
+
moved_added="$(printf '%s\n' "$changes" | awk -F'\t' '$1 ~ /^A/ { n = split($2, p, "/"); print p[n] "\t" $2 }' | sort -u)"
|
|
200
|
+
moved_deleted="$(printf '%s\n' "$changes" | awk -F'\t' '$1 ~ /^D/ { n = split($2, p, "/"); print p[n] "\t" $2 }' | sort -u)"
|
|
201
|
+
if [ -n "$moved_added" ] && [ -n "$moved_deleted" ]; then
|
|
202
|
+
while IFS="$(printf '\t')" read -r base added; do
|
|
203
|
+
[ -n "$base" ] || continue
|
|
204
|
+
gone="$(printf '%s\n' "$moved_deleted" | awk -F'\t' -v b="$base" '$1 == b { print $2; exit }')"
|
|
205
|
+
[ -n "$gone" ] || continue
|
|
206
|
+
to="$(lib_root "$added")" || continue
|
|
207
|
+
from="$(lib_root "$gone")" || continue
|
|
208
|
+
[ "$from" = "$to" ] && continue
|
|
209
|
+
want_readme "$from"
|
|
210
|
+
want_readme "$to"
|
|
211
|
+
done <<EOF
|
|
212
|
+
$moved_added
|
|
213
|
+
EOF
|
|
214
|
+
fi
|
|
215
|
+
|
|
216
|
+
for root in $need_readme; do
|
|
217
|
+
[ -d "$root" ] || continue # the lib was deleted whole — there is nothing to edit in it
|
|
218
|
+
has_path "$root/README.md" || { add "the content of the lib \`$root\` changed without an edit of \`$root/README.md\`"; [ -n "$first_doc" ] || first_doc="$root/README.md"; }
|
|
219
|
+
done
|
|
220
|
+
return 0
|
|
221
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The facts of the course of work for one edit. NOT a guard: it has no `rt-hook:` declaration and is
|
|
3
|
+
# not attached to any agent event. The work-conduct guards source it after `rt_task_flow_context`,
|
|
4
|
+
# and so does a guard whose refusal names an edit of another file: it asks these facts of that edit
|
|
5
|
+
# instead of running the work-conduct guards on it.
|
|
6
|
+
#
|
|
7
|
+
# rt_fact_flow {"facts":{…},"params":{…}} — the branch, the plan, the progress, the state
|
|
8
|
+
# and whether the task folder is in the history; empty when the edit is not
|
|
9
|
+
# judged: a merge conflict being resolved, or a folder already taken apart
|
|
10
|
+
# rt_fact_agreement {"facts":{…},"params":{…}} — whether the plan names the product agreement
|
|
11
|
+
# and whether it exists; empty when there is no plan
|
|
12
|
+
# rt_fact_flow_of <tool> <tool input> <hook input>
|
|
13
|
+
# both of the above for a move another guard names, merged; empty when the
|
|
14
|
+
# work-conduct guards do not judge that move
|
|
15
|
+
#
|
|
16
|
+
# Both read the variables `rt_task_flow_context` sets. FAIL-OPEN: no jq, no git → empty answer, and
|
|
17
|
+
# the caller judges nothing.
|
|
18
|
+
|
|
19
|
+
# shellcheck disable=SC1091
|
|
20
|
+
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/profile-check.sh" ] \
|
|
21
|
+
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/profile-check.sh"
|
|
22
|
+
command -v rt_needs >/dev/null 2>&1 || rt_needs() { command -v "$1" >/dev/null 2>&1; }
|
|
23
|
+
|
|
24
|
+
# Resolving a merge conflict is the merge itself, not an edit of the product. Main is merged into
|
|
25
|
+
# the epic branch while the work runs, and that branch carries no task folder by the rule. So a call
|
|
26
|
+
# passes while a merge stands and every code path it writes is still unmerged.
|
|
27
|
+
rt_flow_merge_conflict_only() {
|
|
28
|
+
local seen=0 candidate
|
|
29
|
+
git -C "$RT_TF_ROOT" rev-parse -q --verify MERGE_HEAD >/dev/null 2>&1 || return 1
|
|
30
|
+
while IFS= read -r candidate; do
|
|
31
|
+
[ -z "$candidate" ] && continue
|
|
32
|
+
case "$candidate" in
|
|
33
|
+
/*) ;;
|
|
34
|
+
*) candidate="${rt_tf_askdir:-${CLAUDE_PROJECT_DIR:-.}}/$candidate" ;;
|
|
35
|
+
esac
|
|
36
|
+
rt_is_app_code "$candidate" || rt_tf_laid_out "$candidate" || continue
|
|
37
|
+
[ -n "$(git -C "$RT_TF_ROOT" ls-files -u -- "$candidate" 2>/dev/null | head -1)" ] || return 1
|
|
38
|
+
seen=1
|
|
39
|
+
done <<EOF
|
|
40
|
+
${RT_TF_CANDIDATES:-$RT_TF_PATH}
|
|
41
|
+
EOF
|
|
42
|
+
[ "$seen" = 1 ]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# The folder is gone from HEAD but stood at the base or was added by a commit of the branch: the
|
|
46
|
+
# work is handed in, and the plan is taken from the history.
|
|
47
|
+
rt_flow_folder_archived() {
|
|
48
|
+
local base had
|
|
49
|
+
[ -n "$(git -C "$RT_TF_ROOT" ls-tree -d --name-only HEAD -- "$RT_TF_TASKS_DIR/$RT_TF_BRANCH" 2>/dev/null | head -1)" ] && return 1
|
|
50
|
+
base="$(git -C "$RT_TF_ROOT" merge-base "$RT_TF_MAIN_BRANCH" HEAD 2>/dev/null)"
|
|
51
|
+
[ -z "$base" ] && return 1
|
|
52
|
+
had="$(git -C "$RT_TF_ROOT" ls-tree -d --name-only "$base" -- "$RT_TF_TASKS_DIR/$RT_TF_BRANCH" 2>/dev/null | head -1)"
|
|
53
|
+
[ -z "$had" ] && had="$(git -C "$RT_TF_ROOT" log "$base..HEAD" --diff-filter=A --name-only --pretty=format: -- "$RT_TF_TASKS_DIR/$RT_TF_BRANCH" 2>/dev/null | head -1)"
|
|
54
|
+
[ -n "$had" ]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# The task folder travels into the branch by a commit, it does not live in one working copy: a folder
|
|
58
|
+
# never committed passes every check of the disk, while the sign of handed-over work is taken from the
|
|
59
|
+
# history. No git history — the folder counts as committed: there is nothing to ask it with.
|
|
60
|
+
rt_flow_in_tree() {
|
|
61
|
+
[ -n "$(git -C "$RT_TF_ROOT" rev-parse --verify HEAD 2>/dev/null)" ] || return 0
|
|
62
|
+
[ -n "$(git -C "$RT_TF_ROOT" ls-tree -d --name-only HEAD -- "$RT_TF_TASKS_DIR/$RT_TF_BRANCH" 2>/dev/null | head -1)" ]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# The mandatory action of a state in which code is not edited.
|
|
66
|
+
rt_flow_state_action() {
|
|
67
|
+
case "$1" in
|
|
68
|
+
просьба-не-разобрана) printf '%s' 'exploration over the tree, then questions to the owner' ;;
|
|
69
|
+
разбор-закрыт) printf '%s' 'a product agreement or a named reason there is none' ;;
|
|
70
|
+
договорённость-записана) printf '%s' 'create the task, the branch and the task folder' ;;
|
|
71
|
+
задача-взята) printf '%s' 'write the plan' ;;
|
|
72
|
+
замысел-записан) printf '%s' 'do the first stage' ;;
|
|
73
|
+
папка-разобрана) printf '%s' 'the work queue audit, then open the PR' ;;
|
|
74
|
+
влито) printf '%s' 'merge the PRs of the chain bottom-up, mark the merged tasks by the branch of the next one' ;;
|
|
75
|
+
*) printf '%s' '' ;;
|
|
76
|
+
esac
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
rt_fact_flow() {
|
|
80
|
+
local progress state kind folder="yes"
|
|
81
|
+
command -v jq >/dev/null 2>&1 || return 0
|
|
82
|
+
rt_flow_merge_conflict_only && return 0
|
|
83
|
+
if rt_needs rt_task_branch_ok task-flow-guard && ! rt_task_branch_ok "$RT_TF_BRANCH"; then
|
|
84
|
+
printf '%s' '{"facts":{"branch":"other"},"params":{}}'
|
|
85
|
+
return 0
|
|
86
|
+
fi
|
|
87
|
+
rt_flow_folder_archived && return 0
|
|
88
|
+
if [ ! -f "$RT_TF_PLAN" ]; then
|
|
89
|
+
printf '%s' '{"facts":{"branch":"task","plan":"no"},"params":{}}'
|
|
90
|
+
return 0
|
|
91
|
+
fi
|
|
92
|
+
progress="$RT_TF_DIR/progress.md"
|
|
93
|
+
if [ ! -f "$progress" ]; then
|
|
94
|
+
printf '%s' '{"facts":{"branch":"task","plan":"yes","progress":"no"},"params":{}}'
|
|
95
|
+
return 0
|
|
96
|
+
fi
|
|
97
|
+
state="$(sed -nE 's/^[[:space:]]*[-*][[:space:]]*\*\*(State|Состояние):\*\*[[:space:]]*`([^`]*)`.*/\2/p' "$progress" 2>/dev/null | head -1)"
|
|
98
|
+
case "$state" in
|
|
99
|
+
'') kind=none ;;
|
|
100
|
+
# States in which the code is edited. The last three are not about the first session: a run
|
|
101
|
+
# happens to be red and a review comes with remarks, and the fix goes into the same branch.
|
|
102
|
+
этап-идёт | этапы-кончились | работа-отдана | разбор-кончился) kind=code ;;
|
|
103
|
+
просьба-не-разобрана | разбор-закрыт | договорённость-записана | задача-взята | замысел-записан | папка-разобрана | влито) kind=other ;;
|
|
104
|
+
*) kind=unknown ;;
|
|
105
|
+
esac
|
|
106
|
+
[ "$kind" = code ] && ! rt_flow_in_tree && folder=no
|
|
107
|
+
jq -cn --arg k "$kind" --arg f "$folder" --arg s "$state" --arg a "$(rt_flow_state_action "$state")" \
|
|
108
|
+
'{facts:({branch:"task", plan:"yes", progress:"yes", state:$k} + (if $k == "code" then {folder_committed:$f} else {} end)), params:{state:$s, state_action:$a}}'
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
rt_fact_agreement() {
|
|
112
|
+
local draft draft_path domain_dir feature file
|
|
113
|
+
command -v jq >/dev/null 2>&1 || return 0
|
|
114
|
+
[ -f "$RT_TF_PLAN" ] || return 0
|
|
115
|
+
if grep -qE '^\*\*(Behaviour|Поведение):\*\*[[:space:]]*(unchanged|не меняется)[[:space:]]*—[[:space:]]*\S' "$RT_TF_PLAN" 2>/dev/null; then
|
|
116
|
+
printf '%s' '{"facts":{"agreement":"waived"},"params":{}}'
|
|
117
|
+
return 0
|
|
118
|
+
fi
|
|
119
|
+
draft="$(sed -nE 's/^\*\*(Draft|Драфт):\*\*[[:space:]]*`([^`]*)`.*/\2/p' "$RT_TF_PLAN" 2>/dev/null | head -1)"
|
|
120
|
+
[ -z "$draft" ] && draft="$(sed -nE 's/^\*\*(Spec|Спек):\*\*[[:space:]]*`([^`]*)`.*/\2/p' "$RT_TF_PLAN" 2>/dev/null | head -1)"
|
|
121
|
+
if [ -z "$draft" ]; then
|
|
122
|
+
printf '%s' '{"facts":{"agreement":"unnamed"},"params":{}}'
|
|
123
|
+
return 0
|
|
124
|
+
fi
|
|
125
|
+
case "$draft" in
|
|
126
|
+
/*) draft_path="$draft" ;;
|
|
127
|
+
*) draft_path="$RT_TF_ROOT/$draft" ;;
|
|
128
|
+
esac
|
|
129
|
+
# On disk, in the history of the branch, or merged into the domain spec: a merged agreement does
|
|
130
|
+
# not lock the branch.
|
|
131
|
+
if [ -e "$draft_path" ] || git -C "$RT_TF_ROOT" log --oneline -1 -- "$draft" 2>/dev/null | grep -q .; then
|
|
132
|
+
printf '%s' '{"facts":{"agreement":"exists"},"params":{}}'
|
|
133
|
+
return 0
|
|
134
|
+
fi
|
|
135
|
+
case "$draft" in
|
|
136
|
+
*/proposed/*)
|
|
137
|
+
domain_dir="${draft%%/proposed/*}"
|
|
138
|
+
feature="${draft##*/proposed/}"
|
|
139
|
+
feature="${feature%/}"
|
|
140
|
+
if [ -n "$feature" ] && [ -d "$RT_TF_ROOT/$domain_dir" ] \
|
|
141
|
+
&& grep -rq -- "$feature" "$RT_TF_ROOT/$domain_dir" 2>/dev/null; then
|
|
142
|
+
printf '%s' '{"facts":{"agreement":"exists"},"params":{}}'
|
|
143
|
+
return 0
|
|
144
|
+
fi
|
|
145
|
+
;;
|
|
146
|
+
esac
|
|
147
|
+
case "$draft_path" in
|
|
148
|
+
*/) file="${draft_path}spec.md" ;;
|
|
149
|
+
*.md) file="$draft_path" ;;
|
|
150
|
+
*) file="$draft_path/spec.md" ;;
|
|
151
|
+
esac
|
|
152
|
+
jq -cn --arg d "$draft" --arg f "$file" '{facts:{agreement:"missing"}, params:{draft:$d, agreement_file:$f}}'
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# The facts of the course of work for a move another guard names. The parse runs in a subshell over
|
|
156
|
+
# the input of that move: the variables of the calling guard stay as they were.
|
|
157
|
+
rt_fact_flow_of() {
|
|
158
|
+
(
|
|
159
|
+
unset RT_HOOK_CMD RT_HOOK_CWD RT_HOOK_FILE RT_HOOK_PARSED RT_HOOK_TOOL
|
|
160
|
+
RT_HOOK_INPUT="$(jq -cn --arg t "$1" --argjson i "$2" --argjson h "$3" '{tool_name:$t, tool_input:$i, cwd:($h.cwd // null), session_id:($h.session_id // null)}' 2>/dev/null)"
|
|
161
|
+
export RT_HOOK_INPUT
|
|
162
|
+
_rt_here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
163
|
+
# shellcheck disable=SC1091
|
|
164
|
+
. "$_rt_here/task-flow-context.sh" 2>/dev/null || exit 0
|
|
165
|
+
rt_task_flow_context </dev/null || exit 0
|
|
166
|
+
_rt_flow="$(rt_fact_flow)"
|
|
167
|
+
[ -n "$_rt_flow" ] || exit 0
|
|
168
|
+
_rt_agreement="$(rt_fact_agreement)"
|
|
169
|
+
[ -n "$_rt_agreement" ] || _rt_agreement='{"facts":{},"params":{}}'
|
|
170
|
+
jq -cn --argjson f "$_rt_flow" --argjson a "$_rt_agreement" \
|
|
171
|
+
'{facts:($f.facts + (if $f.facts.state == "code" and $f.facts.folder_committed == "yes" then $a.facts else {} end)), params:($f.params + $a.params)}'
|
|
172
|
+
)
|
|
173
|
+
}
|