@rt-tools/agent-kit 0.23.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/assets/agents/business-analyst.md +51 -50
- package/assets/agents/conscience.md +37 -35
- package/assets/agents/project-manager.md +49 -48
- package/assets/agents/prose-editor.md +31 -29
- package/assets/agents/qa-engineer.md +50 -48
- package/assets/agents/rules-reviewer.md +63 -58
- package/assets/agents/skill-curator.md +83 -78
- package/assets/agents/spec-critic.md +34 -29
- package/assets/agents/spec-writer.md +35 -32
- package/assets/agents/strict-teacher.md +39 -37
- package/assets/checks/archive-age.mjs +48 -28
- package/assets/checks/archive-prune.mjs +16 -14
- package/assets/checks/board-epics.github.mjs +75 -41
- package/assets/checks/board-folders.mjs +61 -0
- package/assets/checks/board-gh.github.mjs +35 -26
- package/assets/checks/board-long-work.github.mjs +24 -24
- package/assets/checks/board-paths.github.mjs +21 -16
- package/assets/checks/board-runs.github.mjs +45 -43
- package/assets/checks/board-titles.github.mjs +19 -17
- package/assets/checks/board.github.mjs +150 -128
- package/assets/checks/check-archive-age.mjs +23 -19
- package/assets/checks/check-board.github.mjs +179 -157
- package/assets/checks/check-descriptions.mjs +30 -29
- package/assets/checks/check-doc-paths.mjs +104 -82
- package/assets/checks/check-dupes.mjs +84 -80
- package/assets/checks/check-file-size.mjs +79 -70
- package/assets/checks/check-glossary.mjs +47 -37
- package/assets/checks/check-hook-scope.mjs +30 -27
- package/assets/checks/check-lib-layers.mjs +22 -21
- package/assets/checks/check-profile-drift.mjs +48 -43
- package/assets/checks/check-prose-style.mjs +125 -33
- package/assets/checks/check-push-gate.mjs +53 -50
- package/assets/checks/check-reuse.mjs +50 -40
- package/assets/checks/check-schema-drift.mjs +87 -83
- package/assets/checks/check-specs.mjs +155 -134
- package/assets/checks/check-state-next.mjs +66 -52
- package/assets/checks/check-states.mjs +32 -30
- package/assets/checks/check-styles.mjs +52 -51
- package/assets/checks/check-turn-map.mjs +54 -46
- package/assets/checks/lib-boundaries.mjs +32 -30
- package/assets/checks/lib-common.mjs +30 -29
- package/assets/checks/lib-domains.mjs +34 -34
- package/assets/checks/lib-manifests.mjs +17 -15
- package/assets/checks/lib-reexports.mjs +18 -18
- package/assets/checks/rt-kit-checks.config.mjs +174 -142
- package/assets/checks/signals.mjs +43 -39
- package/assets/checks/spec-anchors.mjs +114 -87
- package/assets/checks/spec-common.mjs +128 -84
- package/assets/checks/spec-contract.mjs +30 -30
- package/assets/checks/spec-proposed.mjs +27 -24
- package/assets/checks/spec-scenarios.mjs +51 -28
- package/assets/checks/task-new.github.mjs +85 -56
- package/assets/commands/feedback.md +65 -59
- package/assets/commands/next-session.md +64 -57
- package/assets/commands/skill-curator.md +83 -79
- package/assets/defaults/gate-map.sh +115 -91
- package/assets/defaults/project.sh +228 -178
- package/assets/defaults/shell.sh +85 -65
- package/assets/defaults/turn-map.md +45 -44
- package/assets/docs/GLOSSARY.md +142 -65
- package/assets/hooks/browser-device-id.sh +12 -12
- package/assets/hooks/browser-guard-device-id.sh +46 -14
- package/assets/hooks/browser-guard-no-asking.sh +5 -4
- package/assets/hooks/browser-guard-no-listing.sh +12 -11
- package/assets/hooks/browser-guard-no-other-drivers.sh +48 -42
- package/assets/hooks/browser-guard-require-select.sh +34 -23
- package/assets/hooks/claim-guard.sh +62 -56
- package/assets/hooks/commit-msg.sh +11 -10
- package/assets/hooks/conscience-guard.sh +91 -45
- package/assets/hooks/constitution-index.sh +16 -16
- package/assets/hooks/deny-tail.sh +28 -26
- package/assets/hooks/dev-server-guard.sh +46 -43
- package/assets/hooks/dispatch.sh +84 -39
- package/assets/hooks/docs-guard.sh +105 -86
- package/assets/hooks/exam-guard.sh +146 -84
- package/assets/hooks/git-guard-delivery-conflict.sh +38 -36
- package/assets/hooks/git-guard-delivery-draft.sh +85 -0
- package/assets/hooks/git-guard-delivery-folder.sh +50 -43
- package/assets/hooks/git-guard-delivery-signature.sh +88 -52
- package/assets/hooks/git-guard-delivery.sh +207 -253
- package/assets/hooks/git-guard-main.sh +65 -26
- package/assets/hooks/git-guard-push-tests.sh +133 -75
- package/assets/hooks/glossary-load.sh +23 -22
- package/assets/hooks/grill-gate-ask.sh +12 -11
- package/assets/hooks/grill-gate.sh +94 -87
- package/assets/hooks/guard-note.sh +20 -19
- package/assets/hooks/handoff-entry-guard.sh +26 -24
- package/assets/hooks/handoff-write.sh +74 -67
- package/assets/hooks/hook-input.sh +70 -50
- package/assets/hooks/lint-after-edit.sh +95 -61
- package/assets/hooks/observe.sh +28 -26
- package/assets/hooks/override-write-guard.sh +23 -21
- package/assets/hooks/postmortem-guard.sh +42 -39
- package/assets/hooks/profile-check.sh +22 -20
- package/assets/hooks/proposal-guard.sh +57 -49
- package/assets/hooks/prose-style-guard.sh +19 -17
- package/assets/hooks/qa-dataid-guard.sh +52 -49
- package/assets/hooks/rerun-guard.sh +31 -30
- package/assets/hooks/reuse-first-guard.sh +108 -87
- package/assets/hooks/roles.sh +14 -14
- package/assets/hooks/rule-article.sh +36 -34
- package/assets/hooks/rule-source-guard.sh +52 -36
- package/assets/hooks/skill-gate-layers.sh +59 -57
- package/assets/hooks/skill-gate-rearm.sh +15 -8
- package/assets/hooks/skill-gate.sh +89 -81
- package/assets/hooks/skill-loaded.sh +6 -6
- package/assets/hooks/sql-guard-parse.sh +68 -66
- package/assets/hooks/sql-guard-request.sh +48 -46
- package/assets/hooks/sql-guard-target.sh +57 -51
- package/assets/hooks/sql-guard-write.sh +84 -79
- package/assets/hooks/sql-guard.sh +52 -47
- package/assets/hooks/stand-login-guard.sh +104 -0
- package/assets/hooks/task-context-load.sh +60 -55
- package/assets/hooks/task-flow-context.sh +87 -69
- package/assets/hooks/task-flow-draft-guard.sh +55 -48
- package/assets/hooks/task-flow-guard.sh +67 -64
- package/assets/hooks/turn-entry-load.sh +39 -32
- package/assets/hooks/turn-exit-guard.sh +256 -204
- package/assets/hooks/turn-exit-patterns.sh +53 -0
- package/assets/hooks/utf8.sh +11 -11
- package/assets/hooks/waiting-turn-guard.sh +94 -94
- package/assets/hooks/window-fill-guard.sh +70 -62
- package/assets/hooks/work-start-guard.sh +52 -49
- package/assets/hooks/write-targets.sh +115 -30
- package/assets/laws/autonomous-work.md +29 -27
- package/assets/laws/code-structure.md +31 -30
- package/assets/laws/delivery.md +148 -137
- package/assets/laws/entity-editing.md +52 -50
- package/assets/laws/entity-models.md +14 -13
- package/assets/laws/frontend-application.md +39 -38
- package/assets/laws/lib-imports.md +27 -27
- package/assets/laws/lists.md +31 -29
- package/assets/laws/navigation.md +37 -37
- package/assets/laws/observability.md +41 -40
- package/assets/laws/project-documentation.md +106 -99
- package/assets/laws/reuse-first.md +31 -29
- package/assets/laws/shared-code.md +27 -27
- package/assets/laws/verifiability.md +131 -114
- package/assets/laws/work-conduct.md +250 -250
- package/assets/patterns/admin-lists-screen.md +72 -69
- package/assets/patterns/admin-nav-item.md +51 -46
- package/assets/patterns/angular-patterns-state.md +32 -31
- package/assets/patterns/api-layer-pair.md +33 -31
- package/assets/patterns/autonomous-work-run.md +50 -49
- package/assets/patterns/browser-verification-measure.md +143 -67
- package/assets/patterns/browser-verification-stand.md +181 -128
- package/assets/patterns/component-structure-new.md +51 -42
- package/assets/patterns/dependencies-upgrade.md +55 -39
- package/assets/patterns/doc-style-human.md +93 -0
- package/assets/patterns/doc-style-sweep.md +82 -79
- package/assets/patterns/doc-style-trace.md +87 -81
- package/assets/patterns/doc-style-write.md +130 -122
- package/assets/patterns/entity-aside.md +77 -63
- package/assets/patterns/entity-models-new.md +37 -37
- package/assets/patterns/entity-store.md +33 -33
- package/assets/patterns/git-workflow-commit.azure.md +94 -75
- package/assets/patterns/git-workflow-commit.github.md +153 -129
- package/assets/patterns/git-workflow-commit.gitlab.md +96 -78
- package/assets/patterns/git-workflow-docker.md +165 -147
- package/assets/patterns/git-workflow-freshness.md +45 -45
- package/assets/patterns/git-workflow-merge.md +99 -86
- package/assets/patterns/git-workflow-migration.md +54 -52
- package/assets/patterns/git-workflow-pr-ready.md +57 -56
- package/assets/patterns/git-workflow-pr.azure.md +126 -121
- package/assets/patterns/git-workflow-pr.github.md +179 -175
- package/assets/patterns/git-workflow-pr.gitlab.md +138 -131
- package/assets/patterns/git-workflow-restart.md +35 -31
- package/assets/patterns/git-workflow-secrets.md +80 -73
- package/assets/patterns/git-workflow-stack.md +131 -106
- package/assets/patterns/lib-layers-move.md +62 -53
- package/assets/patterns/lib-layers-new.md +59 -45
- package/assets/patterns/observability-record.md +72 -67
- package/assets/patterns/platform-access-di.md +31 -29
- package/assets/patterns/reuse-first-extend.md +66 -61
- package/assets/patterns/shared-code-new.md +39 -38
- package/assets/patterns/spec-driven-domain.md +161 -151
- package/assets/patterns/spec-driven-rule.md +179 -168
- package/assets/patterns/spec-driven-sweep.md +41 -39
- package/assets/patterns/status-report-table.github.md +37 -36
- package/assets/patterns/styling-bem-component.md +42 -42
- package/assets/patterns/styling-bem-layout.md +39 -34
- package/assets/patterns/styling-bem-sheet.md +59 -58
- package/assets/patterns/task-flow-archive.md +222 -215
- package/assets/patterns/task-flow-close.md +215 -203
- package/assets/patterns/task-flow-handoff.md +154 -145
- package/assets/patterns/task-flow-resume.md +138 -133
- package/assets/patterns/task-flow-start.md +204 -192
- package/assets/patterns/testing-e2e.md +103 -92
- package/assets/patterns/testing-unit.md +77 -70
- package/assets/patterns/ts-procedure.md +32 -29
- package/assets/patterns/turn-entry-map.md +50 -48
- package/assets/pitfalls/agent-kit.md +152 -141
- package/assets/pitfalls/doc-style.md +96 -91
- package/assets/pitfalls/git-workflow.azure.md +49 -46
- package/assets/pitfalls/git-workflow.github.md +264 -234
- package/assets/pitfalls/git-workflow.gitlab.md +49 -45
- package/assets/pitfalls/spec-driven.md +73 -71
- package/assets/pitfalls/styling-bem.md +46 -40
- package/assets/pitfalls/task-flow.md +262 -246
- package/assets/pitfalls/testing.md +99 -92
- package/assets/pitfalls/turn-conduct.md +96 -81
- package/assets/rules/angular-patterns.md +81 -80
- package/assets/rules/api-layer.md +77 -74
- package/assets/rules/autonomous-work.md +75 -74
- package/assets/rules/browser-verification.md +223 -188
- package/assets/rules/component-structure.md +72 -69
- package/assets/rules/dependencies.md +74 -67
- package/assets/rules/deploy-flow.azure.md +118 -108
- package/assets/rules/deploy-flow.github.md +145 -135
- package/assets/rules/deploy-flow.gitlab.md +120 -110
- package/assets/rules/doc-style.md +209 -148
- package/assets/rules/entity-conventions.needs-admin.md +81 -79
- package/assets/rules/entity-models.md +73 -70
- package/assets/rules/git-workflow.azure.md +224 -228
- package/assets/rules/git-workflow.github.md +250 -242
- package/assets/rules/git-workflow.gitlab.md +218 -217
- package/assets/rules/lib-layers.md +85 -86
- package/assets/rules/lists.md +101 -97
- package/assets/rules/navigation.md +78 -78
- package/assets/rules/observability.needs-app.md +165 -153
- package/assets/rules/platform-access.md +76 -75
- package/assets/rules/reuse-first.md +153 -137
- package/assets/rules/shared-code.md +82 -79
- package/assets/rules/spec-driven.md +272 -260
- package/assets/rules/status-report.md +55 -58
- package/assets/rules/styling-bem.md +83 -72
- package/assets/rules/task-flow.md +282 -270
- package/assets/rules/testing.md +224 -188
- package/assets/rules/turn-conduct.md +255 -258
- package/assets/rules/turn-entry.md +92 -87
- package/assets/rules/typescript-conventions.md +94 -88
- package/assets/samples/specs/_template/spec.md +47 -47
- package/assets/samples/tasks/_template/grill.md +20 -20
- package/assets/samples/tasks/_template/plan.md +32 -30
- package/assets/samples/tasks/_template/progress.md +16 -16
- package/assets/skills/agent-kit-extend.md +129 -113
- package/assets/skills/agent-kit.md +236 -222
- package/assets/skills/write-a-skill.md +76 -71
- package/assets/templates/findings.md +19 -19
- package/assets/templates/gate-map.sh +16 -14
- package/assets/templates/implementation.md +28 -27
- package/assets/templates/pattern.md +17 -17
- package/assets/templates/pitfalls.md +6 -6
- package/assets/templates/postmortem.md +24 -23
- package/assets/templates/project.sh +24 -24
- package/assets/templates/proposal.md +62 -60
- package/assets/templates/rule.md +38 -38
- package/assets/workflows/feature.js +46 -46
- package/assets/workflows/plan.js +54 -54
- package/lib/catalog.d.ts +2 -0
- package/lib/catalog.d.ts.map +1 -1
- package/lib/catalog.js +4 -3
- package/lib/catalog.js.map +1 -1
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +68 -4
- package/lib/commands.js.map +1 -1
- package/lib/companion.js +3 -2
- package/lib/companion.js.map +1 -1
- package/lib/enroll.d.ts +7 -1
- package/lib/enroll.d.ts.map +1 -1
- package/lib/enroll.js +13 -4
- package/lib/enroll.js.map +1 -1
- package/lib/observations.d.ts +10 -1
- package/lib/observations.d.ts.map +1 -1
- package/lib/observations.js +1 -0
- package/lib/observations.js.map +1 -1
- package/lib/override-marks.d.ts +24 -0
- package/lib/override-marks.d.ts.map +1 -0
- package/lib/override-marks.js +98 -0
- package/lib/override-marks.js.map +1 -0
- package/lib/plan.d.ts +11 -0
- package/lib/plan.d.ts.map +1 -1
- package/lib/plan.js +10 -1
- package/lib/plan.js.map +1 -1
- package/lib/ship.d.ts +0 -7
- package/lib/ship.d.ts.map +1 -1
- package/lib/ship.js +10 -2
- package/lib/ship.js.map +1 -1
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.js +7 -3
- package/lib/shipment.js.map +1 -1
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +45 -11
- package/lib/sync.js.map +1 -1
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.26.0.tgz +0 -0
- package/rt-tools-agent-kit-0.23.0.tgz +0 -0
|
@@ -1,35 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# rt-hook: PostToolUse .*
|
|
3
|
-
#
|
|
3
|
+
# Requires: hooks/profile-check.sh, hooks/deny-tail.sh
|
|
4
4
|
# rt-hook: PreToolUse .*
|
|
5
|
-
#
|
|
5
|
+
# Window fill: the session is brought to a logical point in advance, not cut off in the middle.
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
7
|
+
# Why exactly this way. The place where the executor remembers the progress of the work is limited,
|
|
8
|
+
# and having filled it, the executor loses not the last action but the whole picture at once. From
|
|
9
|
+
# inside the session this limit is visible by nothing: no check of the tree shows it, and context
|
|
10
|
+
# compaction fires when there is nothing left to bring the work to a point with.
|
|
11
11
|
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
# PostToolUse —
|
|
15
|
-
# PreToolUse —
|
|
16
|
-
#
|
|
17
|
-
#
|
|
12
|
+
# The guard stands on two events at once — splitting it over two files would mean keeping two
|
|
13
|
+
# parses of one record and two places where one threshold is edited:
|
|
14
|
+
# PostToolUse — at the first threshold it gives a reminder: time to choose a stopping point;
|
|
15
|
+
# PreToolUse — at the second it refuses everything but writing the progress, the handover
|
|
16
|
+
# and the delivery commands.
|
|
17
|
+
# The space between the thresholds is what the session closes on: finish the progress, write the
|
|
18
|
+
# handover, commit what has been checked.
|
|
18
19
|
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
20
|
+
# Where the tree has declared the compaction threshold below the stopping threshold, the reminder
|
|
21
|
+
# says the opposite: there is no need to choose a stopping point, because the session will pass the
|
|
22
|
+
# threshold by itself — compaction comes first, a hook of its own will have written the handover by
|
|
23
|
+
# then, and the work goes on within the same session. The refusal stays at that: it turns from the
|
|
24
|
+
# end of the session into insurance for the case when compaction did not come. A reminder that
|
|
25
|
+
# calls for closing the session where it need not be closed is a stop of the work without a reason,
|
|
26
|
+
# and it costs exactly as much as a refusal.
|
|
25
27
|
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
+
# The size of the window is taken from the tree setting. It is not derived from the session record:
|
|
29
|
+
# the model is recorded there without a mark about an extended window, and a session on a wide
|
|
30
|
+
# window is indistinguishable from a session on a narrow one.
|
|
28
31
|
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
32
|
+
# FAIL-OPEN: no window size, no session record, no parser, a broken parse — the work is ALLOWED
|
|
33
|
+
# (exit 0). A broken guard has no right to jam the work.
|
|
31
34
|
|
|
32
|
-
#
|
|
35
|
+
# Its own name in the observations: the refusal is written by the shared deny tail, not by the guard.
|
|
33
36
|
RT_GUARD_NAME=window-fill-guard
|
|
34
37
|
|
|
35
38
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
@@ -41,16 +44,16 @@ input="$RT_HOOK_INPUT"
|
|
|
41
44
|
|
|
42
45
|
command -v jq >/dev/null 2>&1 || exit 0
|
|
43
46
|
|
|
44
|
-
#
|
|
45
|
-
#
|
|
47
|
+
# The tree profile: the window size, the thresholds, the directories of tasks and of the handover.
|
|
48
|
+
# A tree that has not set the window size gets no guard — there is nothing to count the share from.
|
|
46
49
|
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
47
50
|
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
|
|
48
51
|
# shellcheck disable=SC1090
|
|
49
52
|
[ -f "$profile" ] && . "$profile" 2>/dev/null
|
|
50
53
|
done
|
|
51
54
|
|
|
52
|
-
#
|
|
53
|
-
#
|
|
55
|
+
# A word about a missing profile function: a hook that exited silently is indistinguishable from a
|
|
56
|
+
# working one. The file may not be laid out — then the former, silent behaviour stays.
|
|
54
57
|
# shellcheck disable=SC1090
|
|
55
58
|
[ -f "$rt_hooks_dir/profile-check.sh" ] && . "$rt_hooks_dir/profile-check.sh"
|
|
56
59
|
command -v rt_needs >/dev/null 2>&1 || rt_needs() { command -v "$1" >/dev/null 2>&1; }
|
|
@@ -64,14 +67,16 @@ esac
|
|
|
64
67
|
warn_pct="${RT_WINDOW_WARN_PCT:-40}"
|
|
65
68
|
stop_pct="${RT_WINDOW_STOP_PCT:-50}"
|
|
66
69
|
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
+
# The share at which the tool compacts the context itself. Declared by the tree — the session
|
|
71
|
+
# passes the threshold by itself: compaction comes first, a hook of its own has written the
|
|
72
|
+
# handover by then, and the work goes on within the same session. Not declared — the former order:
|
|
73
|
+
# the session ends with a handover.
|
|
70
74
|
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
#
|
|
74
|
-
#
|
|
75
|
+
# The text of the reminder depends on this, not the refusal. The refusal at the stopping threshold
|
|
76
|
+
# stays in both cases: it is the insurance for when compaction did not come — the setting was
|
|
77
|
+
# removed, the version is another, compaction failed. Taking the refusal away from a tree that
|
|
78
|
+
# declared compaction, the guard would let such a session run to the limit of the window, where the
|
|
79
|
+
# work is lost whole.
|
|
75
80
|
compact_pct="${CLAUDE_AUTOCOMPACT_PCT_OVERRIDE:-}"
|
|
76
81
|
case "$compact_pct" in
|
|
77
82
|
'' | *[!0-9]*) compact_pct='' ;;
|
|
@@ -86,11 +91,12 @@ transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/nu
|
|
|
86
91
|
[ -n "$transcript" ] || exit 0
|
|
87
92
|
[ -f "$transcript" ] || exit 0
|
|
88
93
|
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
94
|
+
# The fill is the last usage record of a reply: the input, the one-off write into the cache, what
|
|
95
|
+
# was read from the cache and the output. A sum over all the records will not do at all here — what
|
|
96
|
+
# was read from the cache repeats in each of them, and the sum comes out several times the window.
|
|
92
97
|
#
|
|
93
|
-
#
|
|
98
|
+
# A tail of 200 lines: the session record grows all session, and one last line of it is what is
|
|
99
|
+
# needed.
|
|
94
100
|
fill="$(tail -n 200 "$transcript" 2>/dev/null | jq -s -r '
|
|
95
101
|
[.[] | select(.type == "assistant") | .message.usage | select(. != null)]
|
|
96
102
|
| last
|
|
@@ -108,13 +114,13 @@ pct=$((fill * 100 / window))
|
|
|
108
114
|
fill_k=$((fill / 1000))
|
|
109
115
|
window_k=$((window / 1000))
|
|
110
116
|
|
|
111
|
-
# ---
|
|
117
|
+
# --- the first threshold: a reminder, the work is not refused ----------------------------
|
|
112
118
|
|
|
113
119
|
if [ "$event" = "PostToolUse" ]; then
|
|
114
120
|
[ "$pct" -ge "$warn_pct" ] || exit 0
|
|
115
121
|
|
|
116
|
-
#
|
|
117
|
-
#
|
|
122
|
+
# The reminder repeats not on every call but on each next step of five per cent: otherwise it
|
|
123
|
+
# takes up the very place it saves.
|
|
118
124
|
step=$(((pct / 5) * 5))
|
|
119
125
|
session="$(printf '%s' "$input" | jq -r '.session_id // "unknown"' 2>/dev/null)"
|
|
120
126
|
mark_dir="${TMPDIR:-/tmp}/claude-window-fill"
|
|
@@ -129,14 +135,14 @@ if [ "$event" = "PostToolUse" ]; then
|
|
|
129
135
|
|
|
130
136
|
if [ "$pct" -ge "$stop_pct" ]; then
|
|
131
137
|
if [ -n "$compact_pct" ]; then
|
|
132
|
-
text="
|
|
138
|
+
text="WINDOW FILL ${pct}% (${fill_k}k of ${window_k}k) — the session closes now. The compaction was announced at ${compact_pct}% and did not come: the stop threshold ${stop_pct}% is passed and the context is the same. Everything but writing the progress, the handover and the commands of delivery is already refused — close the session and tell the owner the compaction did not work."
|
|
133
139
|
else
|
|
134
|
-
text="
|
|
140
|
+
text="WINDOW FILL ${pct}% (${fill_k}k of ${window_k}k) — the session closes now. Everything but writing the progress, the handover and the commands of delivery is already refused."
|
|
135
141
|
fi
|
|
136
142
|
elif [ -n "$compact_pct" ]; then
|
|
137
|
-
text="
|
|
143
|
+
text="WINDOW FILL ${pct}% (${fill_k}k of ${window_k}k). There is no stopping point to choose: at ${compact_pct}% the tool compacts the context itself, the hook writes the handover by then, and the work goes on in this same session. The stop threshold ${stop_pct}% is the insurance in case the compaction does not come. Work on."
|
|
138
144
|
else
|
|
139
|
-
text="
|
|
145
|
+
text="WINDOW FILL ${pct}% (${fill_k}k of ${window_k}k). It is time to choose the stopping point: from ${stop_pct}% only closing the session is left. Bring the current step to a state the next session continues from, rewrite «Where we stand» in the progress, write the handover and give the owner the path to it — the pattern task-flow-handoff."
|
|
140
146
|
fi
|
|
141
147
|
|
|
142
148
|
jq -n --arg t "$text" \
|
|
@@ -144,7 +150,7 @@ if [ "$event" = "PostToolUse" ]; then
|
|
|
144
150
|
exit 0
|
|
145
151
|
fi
|
|
146
152
|
|
|
147
|
-
# ---
|
|
153
|
+
# --- the second threshold: work is refused, closing the session passes --------------------
|
|
148
154
|
|
|
149
155
|
[ "$event" = "PreToolUse" ] || exit 0
|
|
150
156
|
[ "$pct" -ge "$stop_pct" ] || exit 0
|
|
@@ -155,19 +161,20 @@ cmd="$(rt_hook_cmd)"
|
|
|
155
161
|
|
|
156
162
|
allowed=0
|
|
157
163
|
case "$tool" in
|
|
158
|
-
#
|
|
164
|
+
# The conversation with the owner and reading what is edited at the closing.
|
|
159
165
|
AskUserQuestion | TodoWrite | Read | SendUserFile)
|
|
160
166
|
allowed=1
|
|
161
167
|
;;
|
|
162
168
|
Edit | Write | MultiEdit | mcp__webstorm__create_new_file)
|
|
163
|
-
#
|
|
169
|
+
# The progress and the handover. The rest is work, and the session no longer starts it.
|
|
164
170
|
case "$path" in
|
|
165
171
|
"$tasks_dir"/* | */"$tasks_dir"/* | "$handoff_dir"/* | */"$handoff_dir"/* | */scratchpad/*) allowed=1 ;;
|
|
166
172
|
esac
|
|
167
173
|
;;
|
|
168
174
|
Bash | mcp__webstorm__execute_terminal_command)
|
|
169
|
-
#
|
|
170
|
-
#
|
|
175
|
+
# Delivery and checks: commit, push, PR, the task column, the state of the tree. The list
|
|
176
|
+
# is added to by the tree profile — the hosting client and the command names differ from
|
|
177
|
+
# tree to tree.
|
|
171
178
|
if rt_needs rt_handoff_allowed_cmd window-fill-guard && rt_handoff_allowed_cmd "$cmd"; then
|
|
172
179
|
allowed=1
|
|
173
180
|
fi
|
|
@@ -176,21 +183,22 @@ esac
|
|
|
176
183
|
|
|
177
184
|
[ "$allowed" -eq 1 ] && exit 0
|
|
178
185
|
|
|
179
|
-
reason="BLOCKED by window-fill-guard:
|
|
186
|
+
reason="BLOCKED by window-fill-guard: window fill ${pct}% (${fill_k}k of ${window_k}k), the stop threshold is ${stop_pct}%. The session works no further — it closes.
|
|
180
187
|
|
|
181
|
-
|
|
182
|
-
1.
|
|
183
|
-
2.
|
|
184
|
-
3.
|
|
188
|
+
What is left to do in this session:
|
|
189
|
+
1. Rewrite the section «Where we stand» in the progress and add a session entry — what was done, what confirms it, what did not work out.
|
|
190
|
+
2. Commit what is checked: what is not committed does not survive the break.
|
|
191
|
+
3. Write the handover into ${handoff_dir}/ and give the owner the path to it — what goes into it is said by the pattern task-flow-handoff.
|
|
185
192
|
|
|
186
|
-
|
|
187
|
-
-
|
|
188
|
-
-
|
|
193
|
+
What passes after the threshold:
|
|
194
|
+
- an edit of ${tasks_dir}/** and ${handoff_dir}/**, a read of any file, a question to the owner;
|
|
195
|
+
- a command starting with a word of delivery or verification: git, the client of the hosting, moving a column, npm run check:*.
|
|
189
196
|
|
|
190
|
-
|
|
197
|
+
A command is judged by the start of the line: entering a directory before it removes the match, and the very commit that would have passed without it is refused. Start the command with the word of delivery itself."
|
|
191
198
|
|
|
192
|
-
#
|
|
193
|
-
#
|
|
199
|
+
# The shared deny tail: the two lawful moves and the lawful form of bypass, if the refusal has one.
|
|
200
|
+
# The file may not be laid out — then there is no tail, and the reason for the refusal stays as it
|
|
201
|
+
# was.
|
|
194
202
|
# shellcheck disable=SC1090
|
|
195
203
|
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
196
204
|
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
@@ -202,6 +210,6 @@ ${deny_tail_text}"
|
|
|
202
210
|
|
|
203
211
|
jq -n --arg r "$reason" \
|
|
204
212
|
'{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
205
|
-
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"window-fill-guard:
|
|
213
|
+
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"window-fill-guard: the window is full, the session closes with a handover."}}\n'
|
|
206
214
|
|
|
207
215
|
exit 0
|
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# rt-hook: Stop
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
3
|
+
# Requires: hooks/deny-tail.sh, hooks/profile-check.sh
|
|
4
|
+
# Work-start guard: a turn that edited application code does not end unless the owner asked for
|
|
5
|
+
# the work in that same turn. Stop.
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
7
|
+
# Why this way. The article "a session does not start work by itself" is held by the executor's
|
|
8
|
+
# memory, and held badly: a session opened after a context compaction gets the state of unfinished
|
|
9
|
+
# work and the plan with its stages from the startup hook — and both say what to do, if working.
|
|
10
|
+
# Whether to work, neither says. A line with a file path sent by the owner is read as an
|
|
11
|
+
# assignment, and the session edits fifty files nobody asked it for.
|
|
12
12
|
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
13
|
+
# The neighbouring guards do not catch this, and not by oversight: each judges its own matter.
|
|
14
|
+
# The plan guard demands a plan on disk — it lies there; the epic guard refuses someone else's
|
|
15
|
+
# task — the task is its own; the conversation guard judges a turn in which a question was asked
|
|
16
|
+
# — and no question was asked precisely because it was decided not to ask. All three judge the
|
|
17
|
+
# subject of the edit and its order, and none asks who ordered this edit.
|
|
18
18
|
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
19
|
+
# The request is caught by form, not by meaning. Meaning is invisible to a machine, and a guard
|
|
20
|
+
# that took to understanding it would refuse work by mood; so the opposite is judged — what is
|
|
21
|
+
# never a request under any reading: an empty message, a single word and a file path. Everything
|
|
22
|
+
# else counts as a request, and this is chosen on purpose: a false refusal here costs more than a
|
|
23
|
+
# miss — it stops work the owner ordered.
|
|
24
24
|
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
25
|
+
# Application code is recognised by the tree's sign `rt_is_app_code` — the same one the plan
|
|
26
|
+
# guard recognises it by. A tree that declared no sign does not get this guard: it has nothing to
|
|
27
|
+
# judge by.
|
|
27
28
|
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
29
|
+
# FAIL-OPEN: no `jq`, no turn transcript, no tree sign, a repeated pass, any error of its own —
|
|
30
|
+
# the turn is ALLOWED (exit 0). A broken guard has no right to jam the work.
|
|
30
31
|
|
|
31
|
-
#
|
|
32
|
+
# Its own name in the observations: the refusal is written by the shared deny tail, not by the
|
|
33
|
+
# guard itself.
|
|
32
34
|
RT_GUARD_NAME=work-start-guard
|
|
33
35
|
|
|
34
36
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
@@ -40,7 +42,7 @@ input="$RT_HOOK_INPUT"
|
|
|
40
42
|
|
|
41
43
|
command -v jq >/dev/null 2>&1 || exit 0
|
|
42
44
|
|
|
43
|
-
#
|
|
45
|
+
# A repeated pass over the same turn is not judged: the guard has said its word once and lets go.
|
|
44
46
|
active="$(printf '%s' "$input" | jq -r '.stop_hook_active // false' 2>/dev/null)"
|
|
45
47
|
[ "$active" = "true" ] && exit 0
|
|
46
48
|
|
|
@@ -50,7 +52,7 @@ transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/nu
|
|
|
50
52
|
|
|
51
53
|
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
52
54
|
|
|
53
|
-
#
|
|
55
|
+
# The tree profile: first the package default, over it the project override, if there is one.
|
|
54
56
|
for profile in "$rt_hooks_dir/../rt-kit/defaults/project.sh" "$rt_hooks_dir/../defaults/project.sh" \
|
|
55
57
|
"${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/project.sh"; do
|
|
56
58
|
# shellcheck disable=SC1090
|
|
@@ -62,10 +64,10 @@ done
|
|
|
62
64
|
command -v rt_needs >/dev/null 2>&1 || rt_needs() { command -v "$1" >/dev/null 2>&1; }
|
|
63
65
|
rt_needs rt_is_app_code work-start-guard || exit 0
|
|
64
66
|
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
+
# A turn is everything recorded after the owner's last real input. A tool result arrives under
|
|
68
|
+
# the same role, so lines with `tool_result` are not counted as input.
|
|
67
69
|
#
|
|
68
|
-
#
|
|
70
|
+
# A 400-line tail: the transcript grows all session long, and only the last turn is judged.
|
|
69
71
|
asked="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
|
|
70
72
|
def is_input:
|
|
71
73
|
.type == "user"
|
|
@@ -83,12 +85,12 @@ asked="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
|
|
|
83
85
|
end
|
|
84
86
|
' 2>/dev/null)"
|
|
85
87
|
|
|
86
|
-
#
|
|
88
|
+
# No input in the transcript at all — nothing to judge: the turn is allowed.
|
|
87
89
|
[ -z "$asked" ] && exit 0
|
|
88
90
|
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
91
|
+
# Files edited during the turn: the edit tools name the path in a field, while a shell command
|
|
92
|
+
# would need its own parsing, and there is none here on purpose. The guard judges an explicit file
|
|
93
|
+
# edit: a command writing into code past the edit tool remains its known boundary.
|
|
92
94
|
edited="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
|
|
93
95
|
def is_input:
|
|
94
96
|
.type == "user"
|
|
@@ -119,24 +121,25 @@ done <<EOF
|
|
|
119
121
|
$edited
|
|
120
122
|
EOF
|
|
121
123
|
|
|
122
|
-
#
|
|
123
|
-
#
|
|
124
|
+
# No application code was edited during the turn: the guard is silent. Exploration, texts and
|
|
125
|
+
# harness go their own way — demanding the owner's word on them would forbid scouting before a
|
|
126
|
+
# request.
|
|
124
127
|
[ -z "$touched" ] && exit 0
|
|
125
128
|
|
|
126
|
-
#
|
|
127
|
-
#
|
|
128
|
-
#
|
|
129
|
+
# Never a request under any reading: an empty message, a single word, a file path. The first
|
|
130
|
+
# non-empty line of the input is judged: a detailed request is already a request by its first
|
|
131
|
+
# line, and a path sent alone does not become one further down either.
|
|
129
132
|
first="$(printf '%s' "$asked" | tr -d '\r' | sed -n '/[^[:space:]]/{p;q;}')"
|
|
130
133
|
words="$(printf '%s' "$asked" | tr -s '[:space:]' '\n' | grep -c '[^[:space:]]' 2>/dev/null || echo 0)"
|
|
131
134
|
|
|
132
135
|
case "$first" in
|
|
133
|
-
#
|
|
134
|
-
'[Request interrupted'*) kind="
|
|
136
|
+
# A service note about an interruption: there is no request of its own in it.
|
|
137
|
+
'[Request interrupted'*) kind="an interruption" ;;
|
|
135
138
|
*)
|
|
136
139
|
if [ "$words" -le 1 ] 2>/dev/null; then
|
|
137
140
|
case "$first" in
|
|
138
|
-
*/*) kind="
|
|
139
|
-
*) kind="
|
|
141
|
+
*/*) kind="a path to a file" ;;
|
|
142
|
+
*) kind="one word" ;;
|
|
140
143
|
esac
|
|
141
144
|
else
|
|
142
145
|
kind=""
|
|
@@ -144,19 +147,19 @@ case "$first" in
|
|
|
144
147
|
;;
|
|
145
148
|
esac
|
|
146
149
|
|
|
147
|
-
#
|
|
150
|
+
# There is a request in the turn: the work was ordered, and the guard lets go.
|
|
148
151
|
[ -z "$kind" ] && exit 0
|
|
149
152
|
|
|
150
|
-
reason="BLOCKED by work-start-guard:
|
|
153
|
+
reason="BLOCKED by work-start-guard: application code was edited in this turn — «${touched}» — while the last message of the owner was not a request: ${kind}.
|
|
151
154
|
|
|
152
|
-
|
|
155
|
+
A session does not start work by itself. The handover of the previous session, the task state from the startup hook and the assigned epic say what to do if working, and stay silent about whether to work. A line with an address names a file, not an action: read as an order, it gives the session work the owner never ordered.
|
|
153
156
|
|
|
154
|
-
|
|
157
|
+
There is one move from here: name the state of the work to the owner and ask whether to go on — and wait for the answer. What was done in this turn does not roll itself back: say what is already edited.
|
|
155
158
|
|
|
156
|
-
|
|
159
|
+
The guard judges one turn: the next session is not refused."
|
|
157
160
|
|
|
158
|
-
#
|
|
159
|
-
#
|
|
161
|
+
# The shared deny tail: the two lawful moves. The file may not be laid out — then there is no
|
|
162
|
+
# tail, and the reason for the refusal stays the same.
|
|
160
163
|
# shellcheck disable=SC1090
|
|
161
164
|
[ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
|
|
162
165
|
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
@@ -166,6 +169,6 @@ deny_tail_text="$(rt_deny_tail "")"
|
|
|
166
169
|
${deny_tail_text}"
|
|
167
170
|
|
|
168
171
|
jq -n --arg r "$reason" '{decision:"block",reason:$r}' 2>/dev/null \
|
|
169
|
-
|| printf '{"decision":"block","reason":"work-start-guard:
|
|
172
|
+
|| printf '{"decision":"block","reason":"work-start-guard: code was edited, and there was no request from the owner in this turn."}\n'
|
|
170
173
|
|
|
171
174
|
exit 0
|