@rt-tools/agent-kit 0.24.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/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 +149 -127
- package/assets/checks/check-archive-age.mjs +23 -19
- package/assets/checks/check-board.github.mjs +172 -164
- package/assets/checks/check-descriptions.mjs +30 -29
- package/assets/checks/check-doc-paths.mjs +91 -88
- package/assets/checks/check-dupes.mjs +84 -80
- package/assets/checks/check-file-size.mjs +74 -71
- package/assets/checks/check-glossary.mjs +47 -37
- package/assets/checks/check-hook-scope.mjs +30 -27
- package/assets/checks/check-lib-layers.mjs +22 -21
- package/assets/checks/check-profile-drift.mjs +48 -43
- package/assets/checks/check-prose-style.mjs +120 -37
- 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 +108 -97
- package/assets/defaults/project.sh +225 -185
- package/assets/defaults/shell.sh +73 -68
- 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 +30 -28
- package/assets/hooks/browser-guard-no-asking.sh +5 -4
- package/assets/hooks/browser-guard-no-listing.sh +12 -11
- package/assets/hooks/browser-guard-no-other-drivers.sh +48 -42
- package/assets/hooks/browser-guard-require-select.sh +34 -23
- package/assets/hooks/claim-guard.sh +62 -56
- package/assets/hooks/commit-msg.sh +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 +60 -46
- package/assets/hooks/docs-guard.sh +100 -91
- package/assets/hooks/exam-guard.sh +105 -93
- package/assets/hooks/git-guard-delivery-conflict.sh +38 -36
- package/assets/hooks/git-guard-delivery-draft.sh +45 -38
- 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 +196 -180
- package/assets/hooks/git-guard-main.sh +38 -34
- package/assets/hooks/git-guard-push-tests.sh +99 -87
- package/assets/hooks/glossary-load.sh +23 -22
- package/assets/hooks/grill-gate-ask.sh +12 -11
- package/assets/hooks/grill-gate.sh +94 -87
- package/assets/hooks/guard-note.sh +20 -19
- package/assets/hooks/handoff-entry-guard.sh +26 -24
- package/assets/hooks/handoff-write.sh +74 -67
- package/assets/hooks/hook-input.sh +67 -58
- package/assets/hooks/lint-after-edit.sh +95 -61
- package/assets/hooks/observe.sh +28 -26
- package/assets/hooks/override-write-guard.sh +23 -21
- package/assets/hooks/postmortem-guard.sh +42 -39
- package/assets/hooks/profile-check.sh +22 -20
- package/assets/hooks/proposal-guard.sh +57 -49
- package/assets/hooks/prose-style-guard.sh +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 +47 -42
- 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 +40 -37
- package/assets/hooks/task-context-load.sh +60 -55
- package/assets/hooks/task-flow-context.sh +87 -69
- package/assets/hooks/task-flow-draft-guard.sh +55 -48
- package/assets/hooks/task-flow-guard.sh +67 -64
- package/assets/hooks/turn-entry-load.sh +39 -32
- package/assets/hooks/turn-exit-guard.sh +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 +96 -44
- 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 -124
- package/assets/laws/work-conduct.md +250 -244
- package/assets/patterns/admin-lists-screen.md +72 -69
- package/assets/patterns/admin-nav-item.md +51 -46
- package/assets/patterns/angular-patterns-state.md +32 -31
- package/assets/patterns/api-layer-pair.md +33 -31
- package/assets/patterns/autonomous-work-run.md +50 -49
- package/assets/patterns/browser-verification-measure.md +124 -88
- package/assets/patterns/browser-verification-stand.md +169 -157
- package/assets/patterns/component-structure-new.md +51 -42
- package/assets/patterns/dependencies-upgrade.md +55 -39
- package/assets/patterns/doc-style-human.md +55 -37
- package/assets/patterns/doc-style-sweep.md +82 -79
- package/assets/patterns/doc-style-trace.md +87 -81
- package/assets/patterns/doc-style-write.md +130 -122
- package/assets/patterns/entity-aside.md +77 -63
- package/assets/patterns/entity-models-new.md +37 -37
- package/assets/patterns/entity-store.md +33 -33
- package/assets/patterns/git-workflow-commit.azure.md +93 -86
- package/assets/patterns/git-workflow-commit.github.md +152 -141
- package/assets/patterns/git-workflow-commit.gitlab.md +95 -89
- 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 +98 -93
- 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 +102 -101
- package/assets/patterns/testing-unit.md +77 -70
- package/assets/patterns/ts-procedure.md +32 -29
- package/assets/patterns/turn-entry-map.md +50 -48
- package/assets/pitfalls/agent-kit.md +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 -214
- package/assets/rules/component-structure.md +72 -69
- package/assets/rules/dependencies.md +74 -67
- package/assets/rules/deploy-flow.azure.md +118 -108
- package/assets/rules/deploy-flow.github.md +145 -135
- package/assets/rules/deploy-flow.gitlab.md +120 -110
- package/assets/rules/doc-style.md +198 -173
- package/assets/rules/entity-conventions.needs-admin.md +81 -79
- package/assets/rules/entity-models.md +73 -70
- package/assets/rules/git-workflow.azure.md +224 -228
- package/assets/rules/git-workflow.github.md +250 -239
- package/assets/rules/git-workflow.gitlab.md +218 -217
- package/assets/rules/lib-layers.md +85 -86
- package/assets/rules/lists.md +101 -97
- package/assets/rules/navigation.md +78 -78
- package/assets/rules/observability.needs-app.md +165 -153
- package/assets/rules/platform-access.md +76 -75
- package/assets/rules/reuse-first.md +153 -143
- package/assets/rules/shared-code.md +82 -79
- package/assets/rules/spec-driven.md +272 -260
- package/assets/rules/status-report.md +55 -58
- package/assets/rules/styling-bem.md +81 -77
- package/assets/rules/task-flow.md +282 -270
- package/assets/rules/testing.md +224 -209
- 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 +235 -211
- 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 +5 -2
- package/lib/commands.js.map +1 -1
- package/lib/companion.js +3 -2
- package/lib/companion.js.map +1 -1
- package/lib/enroll.d.ts +7 -1
- package/lib/enroll.d.ts.map +1 -1
- package/lib/enroll.js +12 -3
- package/lib/enroll.js.map +1 -1
- package/lib/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 +6 -2
- 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.24.0.tgz +0 -0
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
2
|
+
# The request's target for the storage guard: the production database, a throwaway check
|
|
3
|
+
# database or something else — and what is allowed on production.
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
5
|
+
# There is no `# rt-hook:` line here on purpose: the event and the call sample are declared by the
|
|
6
|
+
# guard itself, and the helper next to it is not registered as a hook and decides nothing alone.
|
|
7
7
|
|
|
8
|
-
# ---
|
|
9
|
-
#
|
|
8
|
+
# --- production: a write is forbidden in any form ------------------------------------------
|
|
9
|
+
# The sign is taken from the profile: the tunnel port, the host, the domain — each tree has its
|
|
10
|
+
# own.
|
|
10
11
|
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
12
|
+
# We look for it in the ADDRESS, not in the data: the application's domain also lives in the rows
|
|
13
|
+
# themselves — in the owner's email, in the canonical link of an object. While the sign was taken
|
|
14
|
+
# over the whole command, inserting a row with such an address into the local database was
|
|
15
|
+
# refused as a write to production, and this branch has no opt-out by design — the command became
|
|
16
|
+
# impossible to run.
|
|
17
|
+
# So the request text (what stands after `-c`/`--command`) is cut out of the check.
|
|
16
18
|
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
19
|
+
# A request from the IDE does not name the target in its text: the database is chosen by a
|
|
20
|
+
# connection identifier, and by the SQL alone production cannot be told from the local copy. So
|
|
21
|
+
# connections are recognised by sight. The list is checked against list_database_connections;
|
|
22
|
+
# added a new one — add it here, otherwise it lands in the "unknown" below.
|
|
21
23
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
22
24
|
|
|
23
25
|
sql_resolve_target() {
|
|
@@ -28,18 +30,18 @@ sql_resolve_target() {
|
|
|
28
30
|
conn_known=""
|
|
29
31
|
if [ -n "$conn" ]; then
|
|
30
32
|
case " $PROD_CONNECTIONS " in *" $conn "*) is_prod="yes"; conn_known="prod" ;; esac
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
33
|
+
# A recognised local connection outweighs a textual guess: the application's domain lives
|
|
34
|
+
# in the data itself — in the owner's email, in the canonical link of an object. While
|
|
35
|
+
# the verdict was not overridden, updating such a row on the local database was refused as
|
|
36
|
+
# a write to production, and there was nothing to bypass it with.
|
|
35
37
|
case " $LOCAL_CONNECTIONS " in *" $conn "*) conn_known="local"; is_prod="" ;; esac
|
|
36
38
|
fi
|
|
37
39
|
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
+
# For a request from the IDE the address is not named in the text at all: there the
|
|
41
|
+
# recognised connection decides, and if it is unknown, the branch below asks the user.
|
|
40
42
|
is_scratch=""
|
|
41
43
|
addr_other=""
|
|
42
|
-
if [ -z "$conn" ] && [ "$context" != "
|
|
44
|
+
if [ -z "$conn" ] && [ "$context" != "a request through the connection of the editor (the wrapper of the executor)" ]; then
|
|
43
45
|
while IFS= read -r seg; do
|
|
44
46
|
[ -z "$seg" ] && continue
|
|
45
47
|
if [ -n "$PROD_DSN" ] && printf '%s' "$seg" | grep -qE "$PROD_DSN"; then
|
|
@@ -47,23 +49,26 @@ sql_resolve_target() {
|
|
|
47
49
|
addr_other="yes"
|
|
48
50
|
continue
|
|
49
51
|
fi
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
52
|
+
# A throwaway check database: a loopback address and a port from the range set aside
|
|
53
|
+
# for them. The range is taken by containers raised for the time of one check —
|
|
54
|
+
# restoring a copy, rehearsing a migration on a non-empty database — and torn down
|
|
55
|
+
# right after. There is no data worth guarding there by construction, and a question
|
|
56
|
+
# on every line of such a check teaches answering "yes" without reading and devalues
|
|
57
|
+
# the question that mattered.
|
|
55
58
|
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
+
# The range is narrow and loopback on purpose: neither the tree's working database,
|
|
60
|
+
# nor the tunnel to production, nor the databases of neighbouring trees on this
|
|
61
|
+
# machine must fall under it. What it is here is known by the profile; not named —
|
|
62
|
+
# there is no exception at all, and the question is always asked.
|
|
59
63
|
if [ -n "${RT_SCRATCH_PORT_RE:-}" ] \
|
|
60
64
|
&& printf '%s' "$seg" | grep -qE "$RT_SCRATCH_PORT_RE" \
|
|
61
65
|
&& printf '%s' "$seg" | grep -qE '127\.0\.0\.1|localhost|host\.docker\.internal'; then
|
|
62
66
|
is_scratch="yes"
|
|
63
67
|
else
|
|
64
|
-
#
|
|
65
|
-
# `psql -p 19434 -f x.sql && psql -c "delete …"`
|
|
66
|
-
#
|
|
68
|
+
# Any other addressed call lifts the exception entirely: in the chain
|
|
69
|
+
# `psql -p 19434 -f x.sql && psql -c "delete …"` an early exit would remove the
|
|
70
|
+
# check from the second link, and that is exactly the bypass the guard is written
|
|
71
|
+
# against.
|
|
67
72
|
addr_other="yes"
|
|
68
73
|
fi
|
|
69
74
|
done <<EOF
|
|
@@ -72,28 +77,29 @@ EOF
|
|
|
72
77
|
fi
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
#
|
|
76
|
-
#
|
|
77
|
-
#
|
|
78
|
-
#
|
|
80
|
+
# The exception stands AFTER the address parsing and BEFORE the write rules, but strictly after
|
|
81
|
+
# the production sign has already been set: production overrides the exception on any match, not
|
|
82
|
+
# the other way round. The condition is threefold — a throwaway address is found, there is no
|
|
83
|
+
# production one, and there are no other addressed calls in the command at all.
|
|
79
84
|
sql_pass_scratch() {
|
|
80
85
|
if [ -n "$is_scratch" ] && [ -z "$is_prod" ] && [ -z "$addr_other" ]; then
|
|
81
86
|
exit 0
|
|
82
87
|
fi
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
#
|
|
86
|
-
#
|
|
87
|
-
#
|
|
88
|
-
#
|
|
90
|
+
# On the production database only what the guard recognised as a read is allowed — by an ALLOW
|
|
91
|
+
# list, not by enumerating prohibitions. A deny list fundamentally does not work here: SQL reaches
|
|
92
|
+
# the server as a file, a redirect, `\copy`, `SELECT … INTO`, and every form sealed leaves the
|
|
93
|
+
# neighbouring one open. So the question is turned around: not "is there a write here" but "is a
|
|
94
|
+
# read proven".
|
|
89
95
|
#
|
|
90
|
-
#
|
|
91
|
-
# pg_dump
|
|
92
|
-
# psql -c "
|
|
93
|
-
# psql -l / --version / --help
|
|
96
|
+
# Three forms count as a read, and each is checked in the SEGMENT of its own call:
|
|
97
|
+
# pg_dump without --clean/--create — taking a dump
|
|
98
|
+
# psql -c "<one SELECT>" — a query without a second statement
|
|
99
|
+
# psql -l / --version / --help — a connection check without a query
|
|
94
100
|
sql_check_prod() {
|
|
95
101
|
if [ -n "$is_prod" ] && [ -n "$is_write" ]; then
|
|
96
|
-
deny "BLOCKED:
|
|
102
|
+
deny "BLOCKED: a write into the PRODUCTION storage (${context}). The address leads to production — data is restored from there by nothing but a copy. The schema in production is changed by a migration through the rollout, the data — through the panel of the owner. If an edit of production data really is needed, the owner makes it by hand, having taken a copy first; the guard cannot be bypassed."
|
|
97
103
|
fi
|
|
98
104
|
|
|
99
105
|
if [ -n "$is_prod" ]; then
|
|
@@ -101,9 +107,9 @@ sql_check_prod() {
|
|
|
101
107
|
while IFS= read -r seg; do
|
|
102
108
|
[ -z "$seg" ] && continue
|
|
103
109
|
seg_read=""
|
|
104
|
-
#
|
|
105
|
-
#
|
|
106
|
-
#
|
|
110
|
+
# The client's arguments are everything AFTER its name. Before the name in the same
|
|
111
|
+
# segment other flags live freely: `docker compose -f docker-compose.prod.yml … psql`,
|
|
112
|
+
# and compose's `-f` once cancelled the proof of a read.
|
|
107
113
|
seg_tail="$(printf '%s' "$seg" | perl -0pe 's{^.*?(?<![[:alnum:]_./-])(psql|pg_restore|prisma)(?=\s|$)}{$1}s' 2>/dev/null)"
|
|
108
114
|
[ -z "$seg_tail" ] && seg_tail="$seg"
|
|
109
115
|
|
|
@@ -114,7 +120,7 @@ sql_check_prod() {
|
|
|
114
120
|
esac
|
|
115
121
|
fi
|
|
116
122
|
|
|
117
|
-
#
|
|
123
|
+
# One SELECT and nothing else: a second statement after `;` is no longer a read.
|
|
118
124
|
if printf '%s' "$seg" | grep -qE '(^|[^[:alnum:]_])select([^[:alnum:]_]|$)' \
|
|
119
125
|
&& ! printf '%s' "$seg" | grep -qE '(^|[^[:alnum:]_])(delete|update|insert|truncate|drop|alter|grant|revoke|copy)([^[:alnum:]_]|$)|\\copy|into[[:space:]]+[a-z_"]' \
|
|
120
126
|
&& ! printf '%s' "$seg_tail" | grep -qE '(^|[[:space:]])(-f|--file)([[:space:]]|=)'; then
|
|
@@ -130,7 +136,7 @@ $segments
|
|
|
130
136
|
EOF
|
|
131
137
|
|
|
132
138
|
if [ -n "$unproven" ]; then
|
|
133
|
-
deny "BLOCKED:
|
|
139
|
+
deny "BLOCKED: a call of the database client against the PRODUCTION database (${context}). In production only a proven read is allowed — \`pg_dump\` without \`--clean\`, a single SELECT through \`-c\`, or \`-l\`/\`--version\`. Everything else is refused, even when the guard simply did not parse the command: the content of files (\`-f\`, \`< dump.sql\`), \`\\copy\` and restoring a dump are invisible to it. If an analysis of production data is needed — take a dump and work with a local copy."
|
|
134
140
|
fi
|
|
135
141
|
fi
|
|
136
142
|
}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
#
|
|
3
|
-
#
|
|
2
|
+
# The write part of the storage guard: what counts as a write, what in it is destructive for
|
|
3
|
+
# certain, where migrations go and by what a query addresses rows.
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
5
|
+
# There is deliberately no `# rt-hook:` line here: the event and the call pattern are declared by
|
|
6
|
+
# the guard itself, while a helper next to it registers no hook and decides nothing on its own.
|
|
7
7
|
|
|
8
|
-
#
|
|
9
|
-
#
|
|
8
|
+
# The verbs are looked for in the segments of the CALL, not over the whole line: otherwise a word
|
|
9
|
+
# from a search pattern in a neighbouring link of the chain declared a reading command a write.
|
|
10
10
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
11
11
|
|
|
12
12
|
sql_detect_write() {
|
|
13
13
|
is_write=""
|
|
14
14
|
write_scope="$segments"
|
|
15
|
-
# `copy … from`
|
|
15
|
+
# `copy … from` and `select … into` are a write that names not one of the usual verbs.
|
|
16
16
|
printf '%s' "$write_scope" | grep -qE '(^|[^[:alnum:]_])(delete|update|insert|truncate|drop|alter|create|grant|revoke|copy)([^[:alnum:]_]|$)|\\copy|into[[:space:]]+[a-z_"]' \
|
|
17
17
|
&& is_write="yes"
|
|
18
|
-
#
|
|
19
|
-
# `cat fix.sql | psql …`
|
|
18
|
+
# A pipeline from a source into the client is the same file delivery, only without a flag: the
|
|
19
|
+
# content of `cat fix.sql | psql …` is not visible to the guard, so this is a write by
|
|
20
|
+
# definition.
|
|
20
21
|
while IFS= read -r seg; do
|
|
21
22
|
[ -z "$seg" ] && continue
|
|
22
23
|
printf '%s' "$seg" | grep -qE '(^|[^[:alnum:]_.-])(cat|head|tail|gzcat|zcat|gunzip|echo|printf|curl|wget)([[:space:]]|$)' \
|
|
@@ -25,34 +26,36 @@ sql_detect_write() {
|
|
|
25
26
|
$(client_segments)
|
|
26
27
|
PIPE_EOF
|
|
27
28
|
|
|
28
|
-
#
|
|
29
|
-
#
|
|
29
|
+
# prisma commands change the database without naming a single SQL verb: `migrate reset`
|
|
30
|
+
# recreates it whole, `db push` fits the schema to the model, `db execute` pours in an
|
|
31
|
+
# arbitrary file.
|
|
30
32
|
printf '%s' "$write_scope" | grep -qE 'prisma[[:space:]]+(migrate[[:space:]]+(reset|deploy|dev)|db[[:space:]]+(push|execute))' \
|
|
31
33
|
&& is_write="yes"
|
|
32
34
|
|
|
33
|
-
#
|
|
34
|
-
# `--file`, `< dump.sql`)
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
35
|
+
# A verb on the command line is not the only way to get SQL to the server. A file (`-f`,
|
|
36
|
+
# `--file`, `< dump.sql`) and `pg_restore` name none, so they used to pass by all three levels:
|
|
37
|
+
# delivering a file into the client on the production database ended with zero without a single
|
|
38
|
+
# question, and `pg_restore` could not fire in principle, although `--clean` wipes the content.
|
|
39
|
+
# The content of the file is unavailable to the guard — so this is a write by definition.
|
|
38
40
|
printf '%s' "$flat" | grep -qE '(^|[^[:alnum:]_.-])pg_restore([^[:alnum:]_.-]|$)' \
|
|
39
41
|
&& is_write="yes"
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
+
# For `pg_dump` the same `-f` means the OUTPUT file: this is a read, and it must not be counted
|
|
43
|
+
# as a write — otherwise a routine dump of the production database was rejected, although the
|
|
44
|
+
# text of the refusal advises it itself.
|
|
42
45
|
#
|
|
43
|
-
#
|
|
44
|
-
# `pg_dump`
|
|
45
|
-
#
|
|
46
|
+
# The exception acts PER SEGMENT. While it was checked over the whole command, one mention of
|
|
47
|
+
# `pg_dump` anywhere in the chain was enough for `-f` to stop counting as a write in all the
|
|
48
|
+
# other calls: `pg_dump … > /dev/null && psql -d app -f /tmp/x.sql` passed silently.
|
|
46
49
|
while IFS= read -r seg; do
|
|
47
50
|
[ -z "$seg" ] && continue
|
|
48
|
-
#
|
|
49
|
-
#
|
|
51
|
+
# The word boundary is mandatory: `-f /tmp/pg_dump-restore.sql` is loading a dump, not
|
|
52
|
+
# taking one, and a substring match removed both protections from it at once.
|
|
50
53
|
if printf '%s' "$seg" | grep -qE '(^|[^[:alnum:]_.-])pg_dump(all)?([^[:alnum:]_.-]|$)'; then
|
|
51
54
|
continue
|
|
52
55
|
fi
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
+
# The tail of the segment after the client name: the `-f` of `docker compose` (the
|
|
57
|
+
# production compose file is named non-standardly and does not come up without the flag)
|
|
58
|
+
# stands BEFORE `psql` and has nothing to do with the query.
|
|
56
59
|
seg_tail="$(printf '%s' "$seg" | perl -0pe 's{^.*?(?<![[:alnum:]_./-])(psql|pg_restore|prisma)(?=\s|$)}{$1}s' 2>/dev/null)"
|
|
57
60
|
[ -z "$seg_tail" ] && seg_tail="$seg"
|
|
58
61
|
if printf '%s' "$seg_tail" | grep -qE '(^|[[:space:]])(-f|--file)([[:space:]]|=)|<[[:space:]]*[^[:space:]|<]+\.(sql|dump)'; then
|
|
@@ -64,13 +67,13 @@ $segments
|
|
|
64
67
|
EOF
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
# ---
|
|
70
|
+
# --- destructive for certain ------------------------------------------------------------
|
|
68
71
|
verdict() {
|
|
69
72
|
if [ -n "$soft" ]; then
|
|
70
|
-
ask "
|
|
73
|
+
ask "The request is marked by the destructive-ok marker but stays destructive: $1 Confirm the execution if this is deliberate."
|
|
71
74
|
fi
|
|
72
|
-
deny "BLOCKED: $1
|
|
73
|
-
"
|
|
75
|
+
deny "BLOCKED: $1 Address the rows by the primary key — \`WHERE id IN ('…','…')\`: that way exactly as many rows are touched as are listed, and a miss is visible before the execution. A deletion by a mask (email LIKE '%test%') once carried away, together with the test records, the demonstration bookings of the owner. If addressing by id really does not fit — first run a SELECT with the same condition and show the user what falls under the deletion." \
|
|
76
|
+
"the destructive-ok marker at the request, with an explanation"
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
sql_check_destructive() {
|
|
@@ -80,38 +83,38 @@ sql_check_destructive() {
|
|
|
80
83
|
esac
|
|
81
84
|
|
|
82
85
|
if printf '%s' "$flat" | grep -qE '(^|[^[:alnum:]_])(truncate|drop[[:space:]]+(table|database|schema|column|index)|alter[[:space:]]+table)([^[:alnum:]_]|$)'; then
|
|
83
|
-
verdict "
|
|
86
|
+
verdict "the request changes the schema itself or empties a table whole (${context})."
|
|
84
87
|
fi
|
|
85
88
|
|
|
86
89
|
if printf '%s' "$flat" | grep -qE 'prisma[[:space:]]+(migrate[[:space:]]+reset|db[[:space:]]+push)'; then
|
|
87
|
-
verdict "\`prisma migrate reset\` / \`db push\`
|
|
90
|
+
verdict "\`prisma migrate reset\` / \`db push\` recreates the database and loses its content (${context})."
|
|
88
91
|
fi
|
|
89
92
|
|
|
90
|
-
# `pg_restore --clean`
|
|
91
|
-
#
|
|
93
|
+
# `pg_restore --clean` deletes the existing objects before loading — the same emptying of
|
|
94
|
+
# tables, only by someone else's hands. Without `--clean` it is an ordinary top-up, and it goes
|
|
95
|
+
# the common path.
|
|
92
96
|
if printf '%s' "$flat" | grep -q 'pg_restore' && printf '%s' "$flat" | grep -qE '(^|[[:space:]])(--clean|-c|--create)([[:space:]]|=|$)'; then
|
|
93
|
-
verdict "\`pg_restore --clean\`
|
|
97
|
+
verdict "\`pg_restore --clean\` deletes the objects of the database before loading the dump (${context})."
|
|
94
98
|
fi
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
#
|
|
98
|
-
# `ask`
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
# был важен.
|
|
101
|
+
# A routine application of migrations does not count as destructive. There used to stand an
|
|
102
|
+
# unconditional `ask` here with the words "make sure DATABASE_URL points at the local database" —
|
|
103
|
+
# the guard shifted onto a person exactly the work it can do itself. On a local database migrations
|
|
104
|
+
# are run all the time, and a question on each adds no safety: a guard that asks for the tenth time
|
|
105
|
+
# stops being read together with that one question that mattered.
|
|
103
106
|
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
107
|
+
# So the address is RESOLVED, not guessed: first the inline prefix of the command itself, then the
|
|
108
|
+
# environment variable, then the `.env` of the working directory.
|
|
106
109
|
unquote() {
|
|
107
110
|
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/^"//' -e 's/"$//' -e "s/^'//" -e "s/'$//"
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
resolve_database_url() {
|
|
111
|
-
#
|
|
112
|
-
#
|
|
113
|
-
#
|
|
114
|
-
#
|
|
114
|
+
# Searching by `$flat` is not allowed: it is brought to lower case, and `DATABASE_URL=` never
|
|
115
|
+
# occurs in it — the rule would silently take the address from `.env`, ignoring the one named
|
|
116
|
+
# explicitly in the command. The original line is parsed, and `$flat` stays the fallback with a
|
|
117
|
+
# case-insensitive search.
|
|
115
118
|
inline="$(printf '%s' "${cmd:-}" | grep -oE '[Dd][Aa][Tt][Aa][Bb][Aa][Ss][Ee]_[Uu][Rr][Ll]=[^[:space:]]+' | tail -n1)"
|
|
116
119
|
[ -z "$inline" ] && inline="$(printf '%s' "$flat" | grep -oiE 'database_url=[^[:space:]]+' | tail -n1)"
|
|
117
120
|
if [ -n "$inline" ]; then
|
|
@@ -122,10 +125,10 @@ resolve_database_url() {
|
|
|
122
125
|
printf '%s' "$DATABASE_URL" | unquote
|
|
123
126
|
return
|
|
124
127
|
fi
|
|
125
|
-
#
|
|
126
|
-
# `.claude/worktrees
|
|
127
|
-
#
|
|
128
|
-
#
|
|
128
|
+
# Climbing up the tree, not only the working directory: the agent works in a git worktree under
|
|
129
|
+
# `.claude/worktrees/<branch>/`, where there is no `.env` of its own, while the main checkout
|
|
130
|
+
# has one, and it lies exactly higher up the path. Without the climb the guard would not have
|
|
131
|
+
# resolved the address once, exactly where the migrations are run.
|
|
129
132
|
dir="$hook_cwd"
|
|
130
133
|
depth=0
|
|
131
134
|
while [ -n "$dir" ] && [ "$dir" != '/' ] && [ "$depth" -lt 8 ]; do
|
|
@@ -145,21 +148,22 @@ resolve_database_url() {
|
|
|
145
148
|
sql_check_migrations() {
|
|
146
149
|
if printf '%s' "$flat" | grep -qE 'prisma[[:space:]]+migrate[[:space:]]+(deploy|dev)'; then
|
|
147
150
|
migrate_target="$(resolve_database_url)"
|
|
148
|
-
#
|
|
149
|
-
#
|
|
150
|
-
#
|
|
151
|
+
# The production address is checked BEFORE the parse by kinds: a tunnel to production also
|
|
152
|
+
# hangs on a loopback address, only on a port of its own, and the common rule "loopback
|
|
153
|
+
# means local" would have let a migration through to production.
|
|
151
154
|
if [ -n "$PROD_DSN" ] && printf '%s' "$migrate_target" | grep -qE "$PROD_DSN"; then
|
|
152
|
-
deny "BLOCKED:
|
|
155
|
+
deny "BLOCKED: applying migrations to the PRODUCTION database (${context}). The address of the database leads to production. The schema in production is changed by the rollout: it calls the applying of migrations itself, by a one-off container, before the application starts. Doing this by hand is not allowed — the guard must not be bypassed."
|
|
153
156
|
fi
|
|
154
157
|
case "$migrate_target" in
|
|
155
158
|
*@localhost:*|*@127.0.0.1:*|*@postgres:*|*@host.docker.internal:*)
|
|
156
|
-
#
|
|
157
|
-
#
|
|
158
|
-
# `migrate deploy`
|
|
159
|
+
# A local database is routine work. The parse ends here, otherwise the common rule
|
|
160
|
+
# about writing to the database fires below and the question is asked anyway:
|
|
161
|
+
# `migrate deploy` is marked a write higher up the text.
|
|
159
162
|
#
|
|
160
|
-
#
|
|
161
|
-
# `prisma migrate deploy && psql -c "delete …"`
|
|
162
|
-
#
|
|
163
|
+
# But it can be exited only if there is ONE write in the command — the migration
|
|
164
|
+
# itself. In the chain `prisma migrate deploy && psql -c "delete …"` an early exit
|
|
165
|
+
# would remove the check from the second link, and that is exactly the bypass the
|
|
166
|
+
# guard is written for.
|
|
163
167
|
other_write=""
|
|
164
168
|
printf '%s' "$write_scope" \
|
|
165
169
|
| grep -qE '(^|[^[:alnum:]_])(delete|update|insert|truncate|drop|alter|create|grant|revoke|copy)([^[:alnum:]_]|$)|\\copy|into[[:space:]]+[a-z_"]' \
|
|
@@ -174,42 +178,43 @@ MIGRATE_PIPE_EOF
|
|
|
174
178
|
[ -z "$other_write" ] && exit 0
|
|
175
179
|
;;
|
|
176
180
|
'')
|
|
177
|
-
ask "
|
|
181
|
+
ask "Applying migrations to a database (${context}), but the address could not be resolved: DATABASE_URL is neither in the command, nor in the environment, nor in the \`.env\` of the working directory. Check where the migration will go, and confirm."
|
|
178
182
|
;;
|
|
179
183
|
*)
|
|
180
|
-
ask "
|
|
184
|
+
ask "Applying migrations to an address UNKNOWN TO THE GUARD (${context}). The guard knows local addresses and production ones; this is neither. Make sure this is not production, and confirm."
|
|
181
185
|
;;
|
|
182
186
|
esac
|
|
183
187
|
fi
|
|
184
188
|
}
|
|
185
189
|
|
|
186
|
-
# --- delete/update:
|
|
190
|
+
# --- delete/update: looking at the addressing -------------------------------------------
|
|
187
191
|
sql_check_addressing() {
|
|
188
192
|
if printf '%s' "$flat" | grep -qE '(^|[^[:alnum:]_])(delete[[:space:]]+from|update)([^[:alnum:]_]|$)'; then
|
|
189
193
|
if ! printf '%s' "$flat" | grep -q 'where'; then
|
|
190
|
-
verdict "DELETE/UPDATE
|
|
194
|
+
verdict "DELETE/UPDATE without WHERE touches the whole table (${context})."
|
|
191
195
|
fi
|
|
192
196
|
|
|
193
|
-
#
|
|
194
|
-
#
|
|
195
|
-
# "propertyId" = 'p1' WHERE source = 'site'`
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#
|
|
197
|
+
# The addressing is looked for ONLY in the tail after the last `where`. While the whole
|
|
198
|
+
# query was looked at, an assignment in SET counted as addressing: `UPDATE bookings SET
|
|
199
|
+
# "propertyId" = 'p1' WHERE source = 'site'` looked addressed, although it touched every
|
|
200
|
+
# direct request for the property — exactly what the guard protects from.
|
|
201
|
+
# The case is kept here, unlike in `flat`: Prisma columns are written in camelCase, and
|
|
202
|
+
# `bookingid` brought to lower case is no longer distinguishable from the word `paid`.
|
|
199
203
|
where_tail="$(printf '%s' "$sql" | tr '\n\t' ' ' | sed -E 's/.*[Ww][Hh][Ee][Rr][Ee]/where/')"
|
|
200
204
|
|
|
201
|
-
#
|
|
202
|
-
# `[a-z_]*id`
|
|
205
|
+
# The column name is required whole: `id`, `booking_id`, `"bookingId"`. The former pattern
|
|
206
|
+
# `[a-z_]*id` took `paid` and `valid` for an identifier.
|
|
203
207
|
if ! printf '%s' "$where_tail" | grep -qE '(^|[^[:alnum:]_"])"?(id|[A-Za-z_]+_id|[a-zA-Z]+Id)"?[[:space:]]*(=|[Ii][Nn][[:space:]]*\()'; then
|
|
204
|
-
verdict "DELETE/UPDATE
|
|
208
|
+
verdict "DELETE/UPDATE addresses the rows not by an identifier (${context}) — the condition may match wider than intended."
|
|
205
209
|
fi
|
|
206
210
|
|
|
207
|
-
#
|
|
208
|
-
#
|
|
209
|
-
#
|
|
210
|
-
#
|
|
211
|
+
# The guard sees the column name but not the schema: `propertyId` and `session_id` are
|
|
212
|
+
# foreign keys, and a query by them is addressed only in appearance. `DELETE … WHERE
|
|
213
|
+
# "propertyId" = 'p1'` wipes every booking of the property. Telling this from a primary key
|
|
214
|
+
# without the schema is impossible, so the decision stays with the user — but the warning
|
|
215
|
+
# must be direct, not general.
|
|
211
216
|
if ! printf '%s' "$where_tail" | grep -qE '(^|[^[:alnum:]_"])"?id"?[[:space:]]*(=|[Ii][Nn][[:space:]]*\()'; then
|
|
212
|
-
ask "
|
|
217
|
+
ask "The condition addresses the rows by a FOREIGN key, not by the primary one (${context}): $(printf '%s' "$where_tail" | head -c 200). ALL the rows tied to that record fall under it — for example \`WHERE \"propertyId\" = …\` touches every booking of the property, the demonstration ones included. If specific rows are needed, first select them by a SELECT and list them in \`WHERE id IN (…)\`."
|
|
213
218
|
fi
|
|
214
219
|
fi
|
|
215
220
|
}
|