@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,482 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Requires: hooks/deny-tail.sh, hooks/turn-exit-patterns.sh, hooks/grill-gate-bypass.sh, hooks/grill-gate-options.sh
|
|
3
|
-
# rt-hook: Stop
|
|
4
|
-
# The conversation guard: the owner is not asked a question until the laws and rules have been read
|
|
5
|
-
# within the same turn. It judges two events, and that is not duplication; the second is declared
|
|
6
|
-
# by the neighbouring resource `hooks/grill-gate-ask.sh`, which hands the call over here.
|
|
7
|
-
#
|
|
8
|
-
# Why exactly this way. The requirement "the rules are read before the conversation" is enforceable
|
|
9
|
-
# right up to the moment the question is sent. A check at the turn end refuses after the fact: by
|
|
10
|
-
# the time of the refusal the question is already with the owner, and the owner sees it together
|
|
11
|
-
# with the refused turn — the requirement fires, but it does not save the work. So a turn with a
|
|
12
|
-
# question is judged on the question tool, before sending.
|
|
13
|
-
#
|
|
14
|
-
# This one interception does not close the hole: a question is more often asked in prose, and that
|
|
15
|
-
# is exactly how the one that brought this guard about was asked. A prose question is not a tool,
|
|
16
|
-
# and it can be caught only at the turn end — the event gets the path to the turn record and sees
|
|
17
|
-
# the turn whole. Hence two events: the menu is caught before sending, prose after. They are
|
|
18
|
-
# declared by different resources so that a tree whose question tool is already taken by a guard of
|
|
19
|
-
# its own can take one half instead of dropping the requirement whole.
|
|
20
|
-
#
|
|
21
|
-
# Reading the rules counts as any of three paths: loading a rule, reading a file of the laws or the
|
|
22
|
-
# rules, searching through them. To demand loading exactly would drive the executor to it where one
|
|
23
|
-
# search was enough — the guard would hinder the work instead of straightening it.
|
|
24
|
-
#
|
|
25
|
-
# But reading anything at all from the rules layer does not close the question: an incident
|
|
26
|
-
# analysis someone else read and a search over the catalog counted on a par with the rule this work
|
|
27
|
-
# actually needs — and the answer to the question put to the owner lay exactly in that rule. So,
|
|
28
|
-
# when the area of this turn's work is known, only the rule of that area counts as reading. The
|
|
29
|
-
# area is taken from where the rules gate takes it: from the paths edited in the turn.
|
|
30
|
-
#
|
|
31
|
-
# FAIL-OPEN here too: there are no edits in the turn, there is no gate map, the area did not come
|
|
32
|
-
# out — any reading counts, as before.
|
|
33
|
-
#
|
|
34
|
-
# FAIL-OPEN: on any error, with no turn record and on a repeat pass the turn is ALLOWED (exit 0).
|
|
35
|
-
# A broken guard has no right to jam the conversation.
|
|
36
|
-
|
|
37
|
-
# Its own name in the observations: the refusal is written by the shared deny tail, not by the guard.
|
|
38
|
-
RT_GUARD_NAME=grill-gate
|
|
39
|
-
RT_GUARD_RULE=task-flow
|
|
40
|
-
|
|
41
|
-
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
42
|
-
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
43
|
-
|
|
44
|
-
rt_hook_read
|
|
45
|
-
input="$RT_HOOK_INPUT"
|
|
46
|
-
[ -z "$input" ] && exit 0
|
|
47
|
-
|
|
48
|
-
command -v jq >/dev/null 2>&1 || exit 0
|
|
49
|
-
|
|
50
|
-
# Which event arrived. A tool call has its name, the turn end does not.
|
|
51
|
-
tool="$(rt_hook_tool)"
|
|
52
|
-
|
|
53
|
-
# A repeat pass over the same turn is not judged: otherwise the turn would never end — the guard
|
|
54
|
-
# said its piece once and lets go. This does not apply to a tool call: there the call itself is
|
|
55
|
-
# judged.
|
|
56
|
-
active="$(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null)"
|
|
57
|
-
[ -z "$tool" ] && [ "$active" = "true" ] && exit 0
|
|
58
|
-
|
|
59
|
-
transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
|
|
60
|
-
[ -z "$transcript" ] && exit 0
|
|
61
|
-
[ -f "$transcript" ] || exit 0
|
|
62
|
-
|
|
63
|
-
# The tree profile: the directories of laws, rules and specs differ from tree to tree, and they are
|
|
64
|
-
# needed both for the sign of reading and for the hint in the refusal.
|
|
65
|
-
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
66
|
-
for profile in "$rt_hooks_dir/../rt-kit/defaults/project.sh" "$rt_hooks_dir/../defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/project.sh"; do
|
|
67
|
-
# shellcheck disable=SC1090
|
|
68
|
-
[ -f "$profile" ] && . "$profile" 2>/dev/null
|
|
69
|
-
done
|
|
70
|
-
|
|
71
|
-
# Substitution without a colon is deliberate: set to empty means the tree drops the requirement,
|
|
72
|
-
# and that must not be replaced by a default. The default goes only to the one who did not set the
|
|
73
|
-
# variable at all.
|
|
74
|
-
laws_dir="${RT_LAWS_DIR-docs/constitution}"
|
|
75
|
-
rules_dir="${RT_RULES_DIR-.claude/skills}"
|
|
76
|
-
specs_dir="${RT_SPECS_DIR-docs/specs}"
|
|
77
|
-
# The plan of an epic and the archive are read on a par with the laws: the decision that ties the
|
|
78
|
-
# tasks of an epic together lies exactly there. Whoever had read the plan was refused on a par with
|
|
79
|
-
# whoever had read nothing, and that refusal was lifted by a search over three directories among
|
|
80
|
-
# which the needed one was not.
|
|
81
|
-
plans_dir="${RT_PLANS_DIR-docs/plans}"
|
|
82
|
-
archive_dir="${RT_ARCHIVE_DIR-docs/archive}"
|
|
83
|
-
|
|
84
|
-
# A tree that has neither laws nor rules gets no requirement: there is nothing to read.
|
|
85
|
-
[ -z "$laws_dir" ] && [ -z "$rules_dir" ] && exit 0
|
|
86
|
-
|
|
87
|
-
# The gate map: by it the rule name is got from the edit path. There is none — the area does not
|
|
88
|
-
# come out, and everything stays as before.
|
|
89
|
-
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
90
|
-
for map in "$rt_hooks_dir/../rt-kit/defaults/gate-map.sh" "$rt_hooks_dir/../defaults/gate-map.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/gate-map.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/gate-map.sh"; do
|
|
91
|
-
# shellcheck disable=SC1090
|
|
92
|
-
[ -f "$map" ] && . "$map" 2>/dev/null
|
|
93
|
-
done
|
|
94
|
-
|
|
95
|
-
# The pattern by which a tool call counts as reading the rules. The directories go into it as they
|
|
96
|
-
# are: the dot in `.claude` matches any character and brings nothing extra here.
|
|
97
|
-
read_re="$(printf '%s' "$laws_dir|$rules_dir|$specs_dir|$plans_dir|$archive_dir" | sed 's/^|*//; s/|*$//; s/||*/|/g')"
|
|
98
|
-
[ -z "$read_re" ] && exit 0
|
|
99
|
-
|
|
100
|
-
# The area of this turn's work: the rules the gate demands of the paths edited in the turn. The
|
|
101
|
-
# paths are got by the same parse of the turn as below — by a call of its own, so that the reading
|
|
102
|
-
# pattern is ready for the main parse.
|
|
103
|
-
need_re=''
|
|
104
|
-
if command -v skill_for >/dev/null 2>&1 && [ -n "$rules_dir" ]; then
|
|
105
|
-
edited="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
|
|
106
|
-
def is_input:
|
|
107
|
-
.type == "user"
|
|
108
|
-
and ((.isCompactSummary // false) | not)
|
|
109
|
-
and ((.isMeta // false) | not)
|
|
110
|
-
and (((.message.content // []) | if type == "array"
|
|
111
|
-
then ([.[] | select(.type == "tool_result")] | length)
|
|
112
|
-
else 0 end) == 0);
|
|
113
|
-
(map(is_input) | rindex(true)) as $i
|
|
114
|
-
| (if $i == null then . else .[$i + 1:] end)
|
|
115
|
-
| [.[] | select(.type == "assistant") | (.message.content // [])[]
|
|
116
|
-
| select(.type == "tool_use") | select(.name == "Edit" or .name == "Write" or .name == "NotebookEdit")
|
|
117
|
-
| (.input.file_path // .input.notebook_path // "")]
|
|
118
|
-
| map(select(. != "")) | unique | .[]
|
|
119
|
-
' 2>/dev/null)"
|
|
120
|
-
for path in $edited; do
|
|
121
|
-
# Only this tree's paths make up the area: a draft in the session scratch directory is not
|
|
122
|
-
# work of this tree, and the rule its kind maps to answers no question put to the owner. The
|
|
123
|
-
# rules gate stops at the same root check; a relative path is a path of the tree.
|
|
124
|
-
case "$path" in
|
|
125
|
-
/*)
|
|
126
|
-
case "$path" in
|
|
127
|
-
"${CLAUDE_PROJECT_DIR:-$PWD}"/*) ;;
|
|
128
|
-
*) continue ;;
|
|
129
|
-
esac
|
|
130
|
-
;;
|
|
131
|
-
esac
|
|
132
|
-
for rule in $(skill_for edit "$path" '' 2>/dev/null); do
|
|
133
|
-
case "|$need_re|" in
|
|
134
|
-
*"|$rule|"*) ;;
|
|
135
|
-
*) need_re="${need_re}${need_re:+|}${rule}" ;;
|
|
136
|
-
esac
|
|
137
|
-
done
|
|
138
|
-
done
|
|
139
|
-
fi
|
|
140
|
-
|
|
141
|
-
# A turn is everything recorded after the last real input from the owner. A tool answer comes in
|
|
142
|
-
# under the same `user` role, so lines with `tool_result` do not count as input: otherwise the turn
|
|
143
|
-
# would be the piece after the last tool call, and reading the rules at its start would be lost.
|
|
144
|
-
# The text of a loaded rule and the report of a subagent come in under that role too, marked
|
|
145
|
-
# `isMeta`. Taken for input, a rule loaded right before a question cut the turn after its own
|
|
146
|
-
# loading, and its text stood as the owner's last reply.
|
|
147
|
-
#
|
|
148
|
-
# A tail of 400 lines: the turn record grows all session, and only the last turn is judged.
|
|
149
|
-
# On the tool call event the question is already known — it is the call; only whether the rules
|
|
150
|
-
# were read within this turn is judged. At the turn end the question is looked for in the text of
|
|
151
|
-
# the replies: the menu has by then already been refused earlier.
|
|
152
|
-
verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg re "$read_re" --arg tool "$tool" --arg need "$need_re" --arg rules "$rules_dir" '
|
|
153
|
-
def is_input:
|
|
154
|
-
.type == "user"
|
|
155
|
-
and ((.isCompactSummary // false) | not)
|
|
156
|
-
and ((.isMeta // false) | not)
|
|
157
|
-
and (((.message.content // []) | if type == "array"
|
|
158
|
-
then ([.[] | select(.type == "tool_result")] | length)
|
|
159
|
-
else 0 end) == 0);
|
|
160
|
-
|
|
161
|
-
(map(is_input) | rindex(true)) as $i
|
|
162
|
-
| (if $i == null then . else .[$i + 1:] end) as $turn
|
|
163
|
-
| [$turn[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "text") | .text] as $texts
|
|
164
|
-
| [$turn[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "tool_use")] as $uses
|
|
165
|
-
| (if $need == "" then
|
|
166
|
-
$uses | map(
|
|
167
|
-
(.name == "Skill")
|
|
168
|
-
or ((.name // "") | test("^(Read|Grep|Glob)$")) and ((.input | tostring) | test($re))
|
|
169
|
-
or ((.name == "Bash") and ((.input.command // "") | test($re)))
|
|
170
|
-
) | any
|
|
171
|
-
else
|
|
172
|
-
# The area of the work is known — only the rule of that area counts: an incident
|
|
173
|
-
# analysis someone else read does not answer the question that was asked.
|
|
174
|
-
($need | split("|")) as $rules_needed
|
|
175
|
-
| $uses | map(
|
|
176
|
-
((.name == "Skill") and (((.input.skill // "") | tostring) as $s | $rules_needed | index($s) != null))
|
|
177
|
-
or (((.name // "") | test("^(Read|Grep|Glob|Bash)$"))
|
|
178
|
-
and ((.input | tostring) as $text
|
|
179
|
-
| $rules_needed | map(. as $rule | $text | test($rules + "/" + $rule + "(/|\\b)")) | any))
|
|
180
|
-
) | any
|
|
181
|
-
end) as $read
|
|
182
|
-
| (($texts | join("\n")) | test("\\?[[:space:]]*$"; "m")) as $asked_prose
|
|
183
|
-
| ($tool != "") as $asking_now
|
|
184
|
-
| if ($asked_prose or $asking_now) and ($read | not) then "ask" else "pass" end
|
|
185
|
-
' 2>/dev/null)"
|
|
186
|
-
|
|
187
|
-
# The second sign of the same guard: the owner has already answered this question.
|
|
188
|
-
#
|
|
189
|
-
# The first sign judges whether the rules were read, and stays silent on work that is allowed. But
|
|
190
|
-
# the miss can be another one: the owner gave an instruction in a direct reply, the executor found
|
|
191
|
-
# a fact that changes the price of the instruction but not its meaning — and instead of a line
|
|
192
|
-
# about the price asked a menu where two options out of three offered to cancel the owner's
|
|
193
|
-
# decision. The work stopped until an answer, having been allowed a minute earlier.
|
|
194
|
-
#
|
|
195
|
-
# What is judged is the overlap of words: the question going out now against the owner's last reply
|
|
196
|
-
# — and only where the record already holds a call of the question tool, that is, the owner has
|
|
197
|
-
# answered a question. There is no understanding of the text here and none is needed: three shared
|
|
198
|
-
# significant words mean the same subject, while a grill of six questions runs over different
|
|
199
|
-
# subjects and does not reach the threshold.
|
|
200
|
-
#
|
|
201
|
-
# FAIL-OPEN: no question in the call, no reply from the owner, no earlier question — the sign stays
|
|
202
|
-
# silent.
|
|
203
|
-
if [ -n "$tool" ]; then
|
|
204
|
-
# The words are taken from what the owner reads — the question, the options and their
|
|
205
|
-
# descriptions — and not from the serialised menu: its keys `question`, `label` and
|
|
206
|
-
# `description` stand in every call and matched any English text by two words of the three.
|
|
207
|
-
asked_text="$(printf '%s' "$input" | jq -r '[(.tool_input.questions // [])[]
|
|
208
|
-
| (.question // ""), ((.options // [])[] | (.label // ""), (.description // ""))] | join(" ")' 2>/dev/null)"
|
|
209
|
-
seen="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg now "$asked_text" '
|
|
210
|
-
def is_input:
|
|
211
|
-
.type == "user"
|
|
212
|
-
and ((.isCompactSummary // false) | not)
|
|
213
|
-
and ((.isMeta // false) | not)
|
|
214
|
-
and (((.message.content // []) | if type == "array"
|
|
215
|
-
then ([.[] | select(.type == "tool_result")] | length)
|
|
216
|
-
else 0 end) == 0);
|
|
217
|
-
|
|
218
|
-
def words: [splits("[^\\p{L}\\p{N}]+")] | map(select(length >= 5)) | unique;
|
|
219
|
-
|
|
220
|
-
(map(is_input) | rindex(true)) as $i
|
|
221
|
-
| if $i == null then "no" else
|
|
222
|
-
(.[$i] | (.message.content // []) | if type == "array"
|
|
223
|
-
then ([.[] | select(.type == "text") | .text] | join(" "))
|
|
224
|
-
else (. // "") end) as $said
|
|
225
|
-
| ([.[:$i][] | select(.type == "assistant") | (.message.content // [])[]
|
|
226
|
-
| select(.type == "tool_use") | select(.name == "AskUserQuestion")] | length) as $before
|
|
227
|
-
# A reply of fewer than five significant words is a command, not a decision: «take task
|
|
228
|
-
# N» shares the number and the words of the subject with any next question about it.
|
|
229
|
-
| if $before == 0 or (($said | words) | length) < 5 then "no" else
|
|
230
|
-
(($now | words) - (($now | words) - ($said | words))) as $common
|
|
231
|
-
| if ($common | length) >= 3 then "answered" else "no" end
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
' 2>/dev/null)"
|
|
235
|
-
|
|
236
|
-
if [ "$seen" = "answered" ]; then
|
|
237
|
-
reason="BLOCKED by grill-gate: the owner has already answered this question in this conversation — go on with the work instead of asking again.
|
|
238
|
-
|
|
239
|
-
An instruction of the owner holds until they cancel it. A new fact against a standing instruction is a line in the reply about the price, not a new question: what is asked again is only what the instruction does not cover. The miss here is not in the form of the question but in stopping work that is already allowed.
|
|
240
|
-
|
|
241
|
-
The question really is about another matter — then name in it what the former answer of the owner lacks: the sign judges the shared words of the question and of the last message of the owner, not the meaning."
|
|
242
|
-
|
|
243
|
-
# The shared deny tail: the two lawful moves and the lawful form of bypass, if the
|
|
244
|
-
# refusal has one.
|
|
245
|
-
# shellcheck disable=SC1090
|
|
246
|
-
[ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
|
|
247
|
-
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
248
|
-
deny_tail_text="$(rt_deny_tail "")"
|
|
249
|
-
[ -n "$deny_tail_text" ] && reason="${reason}
|
|
250
|
-
|
|
251
|
-
${deny_tail_text}"
|
|
252
|
-
|
|
253
|
-
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
254
|
-
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: this question has already been answered."}}\n'
|
|
255
|
-
exit 0
|
|
256
|
-
fi
|
|
257
|
-
fi
|
|
258
|
-
|
|
259
|
-
# The third sign of the same guard: the owner answered the recommended option twice in a row.
|
|
260
|
-
#
|
|
261
|
-
# Every menu carries a recommended option, and an owner who takes it twice running has shown that
|
|
262
|
-
# the decisions are not theirs: the questions are answered by the tree, and the menu only asks them
|
|
263
|
-
# to confirm it. A grill went on to a fifth menu after four such answers, and the owner closed it
|
|
264
|
-
# with the name of a ready-made module that answered all five. From the second answer on, the
|
|
265
|
-
# remaining questions are closed by an assumption written into the grill, and the owner gets the
|
|
266
|
-
# list in one line — not a menu.
|
|
267
|
-
#
|
|
268
|
-
# What is judged is the record of the question tool: the last two of its answers, each with every
|
|
269
|
-
# option taken marked as recommended. Any other answer breaks the streak, and a menu after it goes
|
|
270
|
-
# out as usual. The mark is the word the menu itself carries, in either language of the tree.
|
|
271
|
-
#
|
|
272
|
-
# FAIL-OPEN: fewer than two answers in the record, no record, no parser — the sign stays silent.
|
|
273
|
-
if [ -n "$tool" ]; then
|
|
274
|
-
streak="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
|
|
275
|
-
def answer_texts: [.[] | select(.type == "user") | (.message.content // [])
|
|
276
|
-
| select(type == "array") | .[] | select(.type == "tool_result") | .content
|
|
277
|
-
| if type == "string" then . elif type == "array"
|
|
278
|
-
then (map(if type == "object" then (.text // "") else "" end) | join("\n")) else "" end
|
|
279
|
-
| select(test("^(The user answered|Your questions have been answered):"))];
|
|
280
|
-
def recommended: ([match("\"=\"[^\"]*\""; "g")] | length) as $all
|
|
281
|
-
| ([match("\\((Recommended|Рекомендую|Рекомендован[^)]*)\\)\"(,|\\.|[[:space:]]|$)"; "g")] | length) as $marked
|
|
282
|
-
| $all > 0 and $all == $marked;
|
|
283
|
-
(answer_texts) as $answers
|
|
284
|
-
| if ($answers | length) < 2 then "no"
|
|
285
|
-
elif ($answers[-1] | recommended) and ($answers[-2] | recommended) then "streak"
|
|
286
|
-
else "no" end
|
|
287
|
-
' 2>/dev/null)"
|
|
288
|
-
|
|
289
|
-
if [ "$streak" = "streak" ]; then
|
|
290
|
-
reason="BLOCKED by grill-gate: the owner took the recommended option on the last two menus in a row — the remaining questions are closed by assumption, not by a menu.
|
|
291
|
-
|
|
292
|
-
Two answers «recommended» running say the decisions are not the owner's: the tree answers these questions, and the menu only asks them to confirm it. Write what is taken into the grill as decisions, name the list to the owner in one line, and go on with the work. Before that, look for a ready-made module of the same kind — in this tree and in the trees recorded as samples: one grill of five menus was closed by the owner naming such a module.
|
|
293
|
-
|
|
294
|
-
A menu goes out again only for a question no assumption closes, and it says so in its first line."
|
|
295
|
-
|
|
296
|
-
# shellcheck disable=SC1090
|
|
297
|
-
[ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
|
|
298
|
-
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
299
|
-
deny_tail_text="$(rt_deny_tail "")"
|
|
300
|
-
[ -n "$deny_tail_text" ] && reason="${reason}
|
|
301
|
-
|
|
302
|
-
${deny_tail_text}"
|
|
303
|
-
|
|
304
|
-
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
305
|
-
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: two recommended answers in a row close the remaining questions by assumption."}}\n'
|
|
306
|
-
exit 0
|
|
307
|
-
fi
|
|
308
|
-
fi
|
|
309
|
-
|
|
310
|
-
# The fifth sign of the same guard: a question that offers to walk around a check does not leave.
|
|
311
|
-
#
|
|
312
|
-
# A red set was explained by a "foreign" cause, and the owner was asked whether to send it past the
|
|
313
|
-
# check. Such a question is a miss by itself, even when the owner answers "yes": a check is fixed at
|
|
314
|
-
# its cause or fixed itself, and a third option is not named. The sign reads the text the owner
|
|
315
|
-
# reads — the menu with its options, or the last reply when it ends with a question — and looks for
|
|
316
|
-
# the forms of a bypass: past the check, a bypass line, a disabled rule, a hook switched off.
|
|
317
|
-
#
|
|
318
|
-
# The sign lies in a file of its own next to the guard; without it the sign stays silent.
|
|
319
|
-
# shellcheck disable=SC1090
|
|
320
|
-
[ -f "$rt_hooks_dir/grill-gate-bypass.sh" ] && . "$rt_hooks_dir/grill-gate-bypass.sh" 2>/dev/null
|
|
321
|
-
command -v rt_grill_bypass >/dev/null 2>&1 && rt_grill_bypass && exit 0
|
|
322
|
-
|
|
323
|
-
# The fourth sign of the same guard: a question after a refusal carries what was done without the
|
|
324
|
-
# answer.
|
|
325
|
-
#
|
|
326
|
-
# A guard refused, the executor ran not one edit and brought the owner a choice "fix or wait". A
|
|
327
|
-
# question is a lawful exit of a turn, so no guard held it, and the owner asked why the work stopped.
|
|
328
|
-
# A refusal removes the step, not the task: the mechanical part of the blocker is done first. So a
|
|
329
|
-
# question after a refusal leaves only with the line the tree names, and with at least one working
|
|
330
|
-
# command after the last refusal — an edit of a file or a command by the work pattern of the exit
|
|
331
|
-
# guard. A read or a status command does not count: it looks like work and moves nothing.
|
|
332
|
-
#
|
|
333
|
-
# The menu and a question in prose are judged alike: one change of form would otherwise walk around
|
|
334
|
-
# the requirement. A turn without a refusal is not judged by this sign.
|
|
335
|
-
#
|
|
336
|
-
# The line is written in the language the tree speaks to its owner: the tree names it by
|
|
337
|
-
# `RT_DONE_WITHOUT_ANSWER` in its profile, and set empty it drops the sign.
|
|
338
|
-
#
|
|
339
|
-
# FAIL-OPEN: no turn record, no parser, no refusal in the turn — the sign stays silent.
|
|
340
|
-
done_marker="${RT_DONE_WITHOUT_ANSWER-Без ответа сделано:}"
|
|
341
|
-
work_re='git (add|commit|push|checkout|merge|rm)|npm run|pnpm (run|exec)|nx (build|test|run)|gh (pr|issue|api|run)|task:(new|move)|mkdir|cp |mv |rm |sed -i|tee '
|
|
342
|
-
# shellcheck disable=SC1090
|
|
343
|
-
[ -f "$rt_hooks_dir/turn-exit-patterns.sh" ] && . "$rt_hooks_dir/turn-exit-patterns.sh" 2>/dev/null
|
|
344
|
-
if [ -n "$done_marker" ]; then
|
|
345
|
-
after_refusal="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg work "$work_re" '
|
|
346
|
-
def is_input:
|
|
347
|
-
.type == "user"
|
|
348
|
-
and ((.isCompactSummary // false) | not)
|
|
349
|
-
and ((.isMeta // false) | not)
|
|
350
|
-
and (((.message.content // []) | if type == "array"
|
|
351
|
-
then ([.[] | select(.type == "tool_result")] | length)
|
|
352
|
-
else 0 end) == 0);
|
|
353
|
-
def refusal:
|
|
354
|
-
.type == "user" and ((.message.content // []) | if type == "array"
|
|
355
|
-
then any(.[]; .type == "tool_result" and (.is_error // false)
|
|
356
|
-
and ((.content | if type == "string" then . elif type == "array"
|
|
357
|
-
then (map(if type == "object" then (.text // "") else "" end) | join(" "))
|
|
358
|
-
else "" end) | test("BLOCKED|Refused|denied")))
|
|
359
|
-
else false end);
|
|
360
|
-
def working:
|
|
361
|
-
.type == "assistant" and ((.message.content // []) | any(.[];
|
|
362
|
-
.type == "tool_use" and (
|
|
363
|
-
((.name // "") | test("^(Edit|Write|NotebookEdit)$"))
|
|
364
|
-
or ((.name == "Bash") and ((.input.command // "") | test($work))))));
|
|
365
|
-
|
|
366
|
-
(map(is_input) | rindex(true)) as $i
|
|
367
|
-
| (if $i == null then . else .[$i + 1:] end) as $turn
|
|
368
|
-
| ($turn | map(refusal) | rindex(true)) as $r
|
|
369
|
-
| if $r == null then "none"
|
|
370
|
-
elif ($turn[$r + 1:] | map(working) | any) then "worked"
|
|
371
|
-
else "idle" end
|
|
372
|
-
' 2>/dev/null)"
|
|
373
|
-
|
|
374
|
-
if [ "$after_refusal" = "worked" ] || [ "$after_refusal" = "idle" ]; then
|
|
375
|
-
if [ -n "$tool" ]; then
|
|
376
|
-
question_text="$asked_text"
|
|
377
|
-
else
|
|
378
|
-
question_text="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
|
|
379
|
-
def is_input:
|
|
380
|
-
.type == "user"
|
|
381
|
-
and ((.isCompactSummary // false) | not)
|
|
382
|
-
and ((.isMeta // false) | not)
|
|
383
|
-
and (((.message.content // []) | if type == "array"
|
|
384
|
-
then ([.[] | select(.type == "tool_result")] | length)
|
|
385
|
-
else 0 end) == 0);
|
|
386
|
-
(map(is_input) | rindex(true)) as $i
|
|
387
|
-
| (if $i == null then . else .[$i + 1:] end)
|
|
388
|
-
| [.[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "text") | .text]
|
|
389
|
-
| join("\n")
|
|
390
|
-
' 2>/dev/null)"
|
|
391
|
-
fi
|
|
392
|
-
# After a refused menu a list of options in prose is a question too: the helper next door.
|
|
393
|
-
# shellcheck disable=SC1090
|
|
394
|
-
[ -f "$rt_hooks_dir/grill-gate-options.sh" ] && . "$rt_hooks_dir/grill-gate-options.sh" 2>/dev/null
|
|
395
|
-
asks="no"
|
|
396
|
-
if [ -n "$tool" ]; then
|
|
397
|
-
asks="yes"
|
|
398
|
-
elif printf '%s\n' "$question_text" | grep -qE '\?[[:space:]]*$'; then
|
|
399
|
-
asks="yes"
|
|
400
|
-
elif command -v rt_grill_options_asked >/dev/null 2>&1 && rt_grill_options_asked; then
|
|
401
|
-
asks="yes"
|
|
402
|
-
fi
|
|
403
|
-
marked="no"
|
|
404
|
-
case "$question_text" in
|
|
405
|
-
*"$done_marker"*) marked="yes" ;;
|
|
406
|
-
esac
|
|
407
|
-
if [ "$asks" = "yes" ] && { [ "$marked" = "no" ] || [ "$after_refusal" = "idle" ]; }; then
|
|
408
|
-
reason="BLOCKED by grill-gate: a guard refused in this turn, and the question to the owner carries nothing done without the answer.
|
|
409
|
-
|
|
410
|
-
A refusal removes the step, not the task. Do the mechanical part of the blocker first — what the linter's fix mode repairs, what the refusal names as fixable — then ask only the decision that is left. The question leaves with the line «$done_marker …» naming the working commands of this turn after the last refusal: an edit of a file or a command that changes the tree. A read or a status command does not count."
|
|
411
|
-
[ -n "$tool" ] && reason="${reason}
|
|
412
|
-
|
|
413
|
-
The same question in prose does not walk around this refusal: the menu and prose are judged alike, a list of options included. Fix the menu — add the line and a working command — and send it again."
|
|
414
|
-
|
|
415
|
-
# shellcheck disable=SC1090
|
|
416
|
-
[ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
|
|
417
|
-
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
418
|
-
deny_tail_text="$(rt_deny_tail "")"
|
|
419
|
-
[ -n "$deny_tail_text" ] && reason="${reason}
|
|
420
|
-
|
|
421
|
-
${deny_tail_text}"
|
|
422
|
-
|
|
423
|
-
if [ -n "$tool" ]; then
|
|
424
|
-
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
425
|
-
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: a question after a refusal carries what was done without the answer."}}\n'
|
|
426
|
-
else
|
|
427
|
-
jq -n --arg r "$reason" '{decision:"block",reason:$r}' 2>/dev/null \
|
|
428
|
-
|| printf '{"decision":"block","reason":"grill-gate: a question after a refusal carries what was done without the answer."}\n'
|
|
429
|
-
fi
|
|
430
|
-
exit 0
|
|
431
|
-
fi
|
|
432
|
-
fi
|
|
433
|
-
fi
|
|
434
|
-
|
|
435
|
-
[ "$verdict" = "ask" ] || exit 0
|
|
436
|
-
|
|
437
|
-
if [ -n "$tool" ]; then
|
|
438
|
-
head="BLOCKED by grill-gate: the question to the owner has not left yet, and this is the only moment when the requirement can be met."
|
|
439
|
-
else
|
|
440
|
-
head="BLOCKED by grill-gate: the reply carries a question to the owner, and the laws and rules were not read in this turn."
|
|
441
|
-
fi
|
|
442
|
-
|
|
443
|
-
# The refusal names the action its own condition accepts. When the turn holds edits, only the rules
|
|
444
|
-
# of their area count, and the advice to search the directories sent the executor round in a
|
|
445
|
-
# circle: the search was made, the same refusal came back, and the executor stopped asking at all.
|
|
446
|
-
if [ -n "$need_re" ]; then
|
|
447
|
-
named="$(printf '%s' "$need_re" | tr '|' '\n' | sed 's/.*/«&»/' | paste -sd ',' - | sed 's/,/, /g')"
|
|
448
|
-
reason="$head A question whose answer is already written down is not asked of the owner — the rule of work conduct. The turn holds edits, and for them only the rules of their area count: $named. A search over the specs or over other rules does not lift this refusal. The area counts every edit since the owner's last message, the stretch before a context compaction included. Load them by the tool Skill, or read them in $rules_dir, and answer from what is found; ask only what they do not cover.
|
|
449
|
-
|
|
450
|
-
A rule loaded before the owner's last message does not count: the guard judges one turn, and the next session is not refused."
|
|
451
|
-
else
|
|
452
|
-
reason="$head A question whose answer is already written down is not asked of the owner — the rule of work conduct. Run a search by the words of the subject and answer from what is found; ask only what the documents do not cover:
|
|
453
|
-
|
|
454
|
-
grep -rn -i \"<a word of the subject>\" $laws_dir $rules_dir $specs_dir $plans_dir $archive_dir
|
|
455
|
-
|
|
456
|
-
The guard judges one turn: the next session is not refused."
|
|
457
|
-
fi
|
|
458
|
-
|
|
459
|
-
# The shared deny tail: the two lawful moves and the lawful form of bypass, if the refusal has one.
|
|
460
|
-
# The file may not be laid out — then there is no tail, and the reason for the refusal stays as it
|
|
461
|
-
# was.
|
|
462
|
-
# shellcheck disable=SC1090
|
|
463
|
-
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
464
|
-
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
465
|
-
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
466
|
-
deny_tail_text="$(rt_deny_tail "")"
|
|
467
|
-
[ -n "$deny_tail_text" ] && reason="${reason}
|
|
468
|
-
|
|
469
|
-
${deny_tail_text}"
|
|
470
|
-
|
|
471
|
-
# The form of the refusal differs between the two events: a tool call is refused by a decision
|
|
472
|
-
# about access, and the turn end by a decision about the turn. One form for both events silently
|
|
473
|
-
# does not fire.
|
|
474
|
-
if [ -n "$tool" ]; then
|
|
475
|
-
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
476
|
-
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: read the laws and rules on the subject before asking the owner."}}\n'
|
|
477
|
-
else
|
|
478
|
-
jq -n --arg r "$reason" '{decision:"block",reason:$r}' 2>/dev/null \
|
|
479
|
-
|| printf '{"decision":"block","reason":"grill-gate: read the laws and rules on the subject before asking the owner."}\n'
|
|
480
|
-
fi
|
|
481
|
-
|
|
482
|
-
exit 0
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# rt-hook: Stop
|
|
3
|
-
# Requires: hooks/deny-tail.sh
|
|
4
|
-
# Incident guard: a turn in which the executor admitted a miss does not end while there is no
|
|
5
|
-
# incident record. Stop.
|
|
6
|
-
#
|
|
7
|
-
# Why exactly so. An incident — a session in which the executor did the wrong thing and the rules
|
|
8
|
-
# layer did not refuse it — leaves no code behind that could be fixed. Such a session ends with an
|
|
9
|
-
# apology in the chat: the next day the mechanism of the miss is retold already smoothed over,
|
|
10
|
-
# conclusions remain, and no rule follows from conclusions. An analysis happened only when the
|
|
11
|
-
# owner demanded it out loud.
|
|
12
|
-
#
|
|
13
|
-
# The admission is caught by patterns, not by understanding the meaning: the verdict "that was a
|
|
14
|
-
# miss" would be given by the one it inconveniences, and the threshold would drift. The pattern
|
|
15
|
-
# set is visible, is extended by an edit and misses noticeably — a session that admitted a miss
|
|
16
|
-
# in words outside the set is passed by the guard, and this is said out loud in the agreement
|
|
17
|
-
# rather than counted as closed.
|
|
18
|
-
#
|
|
19
|
-
# It is caught at the end of the turn, not on sending the reply: by the moment of the admission
|
|
20
|
-
# the miss has already happened, and there is nothing to catch earlier. This sets it apart from
|
|
21
|
-
# the conversation guard, which has a tool of its own — a question to the owner.
|
|
22
|
-
#
|
|
23
|
-
# FAIL-OPEN: on any error, with no turn record and on a repeat pass the turn is ALLOWED (exit 0).
|
|
24
|
-
# A broken guard has no right to jam the conversation.
|
|
25
|
-
|
|
26
|
-
# Own name in the observations: the refusal is written by the shared refusal tail, not by the
|
|
27
|
-
# guard itself.
|
|
28
|
-
RT_GUARD_NAME=postmortem-guard
|
|
29
|
-
|
|
30
|
-
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
31
|
-
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
32
|
-
|
|
33
|
-
rt_hook_read
|
|
34
|
-
input="$RT_HOOK_INPUT"
|
|
35
|
-
[ -z "$input" ] && exit 0
|
|
36
|
-
|
|
37
|
-
command -v jq >/dev/null 2>&1 || exit 0
|
|
38
|
-
|
|
39
|
-
# A repeat pass over the same turn is not judged: the guard has said its word once and lets go.
|
|
40
|
-
active="$(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null)"
|
|
41
|
-
[ "$active" = "true" ] && exit 0
|
|
42
|
-
|
|
43
|
-
transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
|
|
44
|
-
[ -z "$transcript" ] && exit 0
|
|
45
|
-
[ -f "$transcript" ] || exit 0
|
|
46
|
-
|
|
47
|
-
root="${CLAUDE_PROJECT_DIR:-.}"
|
|
48
|
-
|
|
49
|
-
# The records directory is the tree's own, and the tree settings name it — by the same key the
|
|
50
|
-
# cargo dispatch reads it with. One name for both sides: a tree that moved the directory out of
|
|
51
|
-
# history would otherwise get a guard looking for records at the old address — and it would stay
|
|
52
|
-
# silent forever. The variable remains a bypass for one launch, and an empty string in either of
|
|
53
|
-
# the two is the tree's refusal of the demand: a tree that keeps no records is not forced to.
|
|
54
|
-
if [ -n "${RT_POSTMORTEMS_DIR+set}" ]; then
|
|
55
|
-
notes_dir="$RT_POSTMORTEMS_DIR"
|
|
56
|
-
elif [ -f "$root/.claude/rt-kit.json" ]; then
|
|
57
|
-
notes_dir="$(jq -r '.postmortems // "docs/postmortems"' "$root/.claude/rt-kit.json" 2>/dev/null)"
|
|
58
|
-
else
|
|
59
|
-
notes_dir="docs/postmortems"
|
|
60
|
-
fi
|
|
61
|
-
[ -z "$notes_dir" ] && exit 0
|
|
62
|
-
[ -d "$root/$notes_dir" ] || exit 0
|
|
63
|
-
|
|
64
|
-
# Patterns of admitting a miss. The set is open and is extended by an edit: its completeness is
|
|
65
|
-
# an open question of the agreement, not a promise.
|
|
66
|
-
admitted_re='был неправ|был не прав|ошибс|моя ошибк|мой промах|промахнул|проглядел|не проверил|соврал|виноват|извин|прошу прощения|неверно утверждал|утверждение было ложн|принял на веру'
|
|
67
|
-
|
|
68
|
-
# The turn is everything recorded after the owner's last real input. A tool result arrives under
|
|
69
|
-
# the same role, so lines with `tool_result` do not count as input.
|
|
70
|
-
#
|
|
71
|
-
# A tail of 400 lines: the turn record grows all session long, and only the last turn is judged.
|
|
72
|
-
verdict="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg re "$admitted_re" '
|
|
73
|
-
def is_input:
|
|
74
|
-
.type == "user"
|
|
75
|
-
and ((.isCompactSummary // false) | not)
|
|
76
|
-
and (((.message.content // []) | if type == "array"
|
|
77
|
-
then ([.[] | select(.type == "tool_result")] | length)
|
|
78
|
-
else 0 end) == 0);
|
|
79
|
-
|
|
80
|
-
(map(is_input) | rindex(true)) as $i
|
|
81
|
-
| (if $i == null then . else .[$i + 1:] end) as $turn
|
|
82
|
-
| [$turn[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "text") | .text] as $texts
|
|
83
|
-
| [$turn[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "tool_use")] as $uses
|
|
84
|
-
# The sign is case-insensitive by a flag, not by lowercasing: lowercasing knows only Latin
|
|
85
|
-
# letters, and a capitalised "Был неправ" would slip past the pattern set silently.
|
|
86
|
-
| (($texts | join("\n")) | test($re; "i")) as $admitted
|
|
87
|
-
| ($uses | map(
|
|
88
|
-
((.name // "") | test("^(Write|Edit|MultiEdit)$"))
|
|
89
|
-
and ((.input.file_path // "") | test("postmortem"))
|
|
90
|
-
) | any) as $wrote
|
|
91
|
-
| if $admitted and ($wrote | not) then "admit" else "pass" end
|
|
92
|
-
' 2>/dev/null)"
|
|
93
|
-
|
|
94
|
-
[ "$verdict" = "admit" ] || exit 0
|
|
95
|
-
|
|
96
|
-
# A record made during this session lifts the demand even without an edit in this same turn: the
|
|
97
|
-
# analysis may have landed as a file a turn earlier — the one in which the miss was admitted.
|
|
98
|
-
if [ -n "$(find "$root/$notes_dir" -name '*.md' -newermt '-1 day' 2>/dev/null | head -1)" ]; then
|
|
99
|
-
exit 0
|
|
100
|
-
fi
|
|
101
|
-
|
|
102
|
-
reason="BLOCKED by postmortem-guard: a miss is admitted in the reply, and there is no record of the incident in \`$notes_dir/\` for today. An incident — a session in which the executor did the wrong thing and the rules layer did not refuse it — is written down in that same session: by the next day the mechanism of the miss is retold already smoothed over, and no rule comes out of it.
|
|
103
|
-
|
|
104
|
-
The record names: the mechanism of the miss step by step, what was available before it, what caught it and what of this went into the rules layer. Without the last line it is a complaint, not an analysis.
|
|
105
|
-
|
|
106
|
-
$notes_dir/<year>-<month>-<day>-<short name>.md
|
|
107
|
-
|
|
108
|
-
The guard judges one turn: the next session is not refused."
|
|
109
|
-
|
|
110
|
-
# The shared refusal tail: two lawful moves. The file may not be laid out — then there is no
|
|
111
|
-
# tail, and the reason for the refusal stays as it was.
|
|
112
|
-
# shellcheck disable=SC1090
|
|
113
|
-
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
114
|
-
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
115
|
-
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
116
|
-
deny_tail_text="$(rt_deny_tail "")"
|
|
117
|
-
[ -n "$deny_tail_text" ] && reason="${reason}
|
|
118
|
-
|
|
119
|
-
${deny_tail_text}"
|
|
120
|
-
|
|
121
|
-
jq -n --arg r "$reason" '{decision:"block",reason:$r}' 2>/dev/null \
|
|
122
|
-
|| printf '{"decision":"block","reason":"postmortem-guard: a miss is admitted — write the analysis of the incident."}\n'
|
|
123
|
-
|
|
124
|
-
exit 0
|