@venizia/vulcan 0.4.10-2 → 0.4.10-21
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 +30 -23
- package/base/checks/wiki-source-links.ts +17 -1
- package/base/claude/events.json +1 -11
- package/base/claude/settings.json +5 -76
- package/base/extensions/vulcan-guards.ts +81 -18
- package/base/hooks/guard-git.ts +95 -19
- package/base/hooks/guard-outside.ts +163 -43
- package/base/hooks/guard-writes.ts +15 -36
- package/base/hooks/session-start.ts +1 -1
- package/base/make/vulcan.mk +8 -5
- package/base/packs/venizia.md +16 -0
- package/base/references/delegation-brief.md +3 -5
- package/base/references/testing.md +1 -9
- package/base/rules.md +33 -38
- package/base/skills/build-a-feature/SKILL.md +4 -4
- package/base/skills/docs-update/SKILL.md +19 -8
- package/base/skills/fix-a-bug/SKILL.md +4 -2
- package/base/skills/plan-a-change/SKILL.md +1 -1
- package/base/skills/research/SKILL.md +1 -1
- package/base/skills/retro/SKILL.md +2 -2
- package/base/skills/review-a-change/SKILL.md +1 -1
- package/base/skills/visualize-work/SKILL.md +3 -3
- package/base/skills/visualize-work/references/spec.md +6 -3
- package/base/templates/AGENTS.md +9 -7
- package/base/templates/board.html +10 -110
- package/package.json +3 -3
- package/src/agents/atlas-block.ts +8 -31
- package/src/agents/codex-hooks.ts +1 -1
- package/src/agents/generated-block.ts +52 -0
- package/src/agents/hooks-json.ts +22 -3
- package/src/agents/index.ts +2 -0
- package/src/agents/render.ts +15 -2
- package/src/agents/resolve.ts +1 -0
- package/src/agents/rules-block.ts +92 -0
- package/src/board/command.ts +92 -30
- package/src/board/common/constants.ts +26 -0
- package/src/board/common/types.ts +10 -3
- package/src/board/fold.ts +1 -1
- package/src/board/github.ts +1 -2
- package/src/board/gitlab.ts +436 -0
- package/src/board/index.ts +1 -0
- package/src/board/logo.ts +49 -0
- package/src/board/open-file.ts +110 -0
- package/src/board/page.ts +57 -5
- package/src/board/schema.ts +4 -1
- package/src/board/server.ts +87 -3
- package/src/board/settings.ts +21 -24
- package/src/commands/changelog.command.ts +40 -0
- package/src/commands/clean.command.ts +6 -1
- package/src/commands/help.command.ts +2 -63
- package/src/commands/index.ts +6 -1
- package/src/commands/migrate.command.ts +71 -0
- package/src/commands/profile.command.ts +1 -1
- package/src/commands/runners.command.ts +43 -0
- package/src/commands/sync.command.ts +8 -4
- package/src/commands/table.ts +362 -0
- package/src/commit/check.ts +1 -0
- package/src/commit/common/constants.ts +4 -0
- package/src/commit/hook.ts +112 -8
- package/src/common/constants.ts +11 -9
- package/src/common/env-variables.ts +41 -0
- package/src/common/index.ts +1 -0
- package/src/common/layout-folder.ts +3 -4
- package/src/common/record.ts +5 -0
- package/src/config/common/constants.ts +28 -22
- package/src/config/loader.ts +22 -0
- package/src/config/schema.ts +330 -146
- package/src/create/add-app.ts +7 -2
- package/src/create/add-lib.ts +2 -4
- package/src/create/common/constants.ts +5 -3
- package/src/create/preset.ts +1 -0
- package/src/create/scratch.ts +2 -1
- package/src/doctor/checks.ts +277 -448
- package/src/doctor/common/constants.ts +27 -19
- package/src/doctor/private-values.ts +4 -1
- package/src/doctor/runner.ts +5 -12
- package/src/doctor/schema.ts +4 -0
- package/src/events/common/actor-names.ts +12 -0
- package/src/events/common/constants.ts +65 -38
- package/src/events/common/index.ts +1 -0
- package/src/events/hook.ts +5 -56
- package/src/events/text.ts +41 -6
- package/src/hooks/command-view.ts +80 -19
- package/src/hooks/common/constants.ts +26 -17
- package/src/hooks/common/types.ts +13 -24
- package/src/hooks/decision.ts +30 -12
- package/src/hooks/git-queries.ts +113 -0
- package/src/hooks/guard-git.ts +76 -24
- package/src/hooks/guard-outside.ts +334 -311
- package/src/hooks/guard-runner.ts +206 -0
- package/src/hooks/guard-writes.ts +87 -184
- package/src/hooks/hook-input.ts +57 -0
- package/src/hooks/index.ts +3 -6
- package/src/hooks/link-makers.ts +315 -0
- package/src/hooks/package-runners.ts +268 -0
- package/src/hooks/project-guards.ts +81 -44
- package/src/hooks/project-tmp.ts +39 -4
- package/src/hooks/runner-scan.ts +257 -0
- package/src/hooks/script-runners.ts +400 -0
- package/src/hooks/session-digest.ts +27 -117
- package/src/hooks/shell-folders.ts +760 -0
- package/src/hooks/shell-writes.ts +646 -0
- package/src/hooks/shell.ts +1421 -194
- package/src/hooks/subagent-card.ts +2 -2
- package/src/hooks/write-commands.ts +898 -0
- package/src/init/scaffold.ts +2 -3
- package/src/local/auto-clean.ts +2 -1
- package/src/local/browser-socket.ts +33 -0
- package/src/local/clean.ts +37 -6
- package/src/local/constants.ts +15 -1
- package/src/local/index.ts +1 -0
- package/src/local/scan.ts +41 -10
- package/src/manifest/render.ts +84 -30
- package/src/owner/constants.ts +4 -5
- package/src/owner/index.ts +0 -2
- package/src/owner/profile.ts +1 -0
- package/src/owner/schema.ts +51 -27
- package/src/owner/survey.ts +0 -3
- package/src/owner/view.ts +0 -9
- package/src/router.ts +8 -132
- package/src/rules/base.ts +12 -7
- package/src/rules/index.ts +1 -0
- package/src/rules/packs.ts +44 -0
- package/src/runners/check.ts +130 -0
- package/src/skills/frontmatter.ts +1 -0
- package/src/sync/agents-block.ts +104 -0
- package/src/sync/base-rules.ts +3 -3
- package/src/sync/claude-launch.ts +12 -12
- package/src/sync/common/constants.ts +0 -2
- package/src/sync/index.ts +1 -1
- package/src/sync/local-choice.ts +32 -3
- package/src/sync/planner.ts +2 -15
- package/src/sync/settings.ts +0 -17
- package/src/theme/index.ts +1 -0
- package/src/theme/tokens.ts +410 -0
- package/src/ui/prompt.ts +1 -0
- package/src/visualize/architecture.ts +504 -0
- package/src/visualize/assets.ts +41 -30
- package/src/visualize/compare-render.ts +22 -24
- package/src/visualize/constants.ts +27 -0
- package/src/visualize/diagrams.ts +13 -121
- package/src/visualize/kinds-render.ts +2 -2
- package/src/visualize/kinds-schema.ts +49 -0
- package/src/visualize/labels-vi.ts +25 -0
- package/src/visualize/labels.ts +2 -0
- package/src/visualize/layout.ts +415 -66
- package/src/visualize/page.ts +82 -15
- package/src/visualize/render.ts +2 -1
- package/src/visualize/schema.ts +29 -1
- package/src/visualize/sections.ts +78 -9
- package/src/visualize/theme.ts +49 -18
- package/src/wiki/anchors.ts +1 -0
- package/src/wiki/command.ts +10 -3
- package/src/wiki/source-links.ts +57 -18
- package/base/ci-global.json +0 -13
- package/base/claude/remote-hosts.json +0 -15
- package/base/hooks/guard-manifest.ts +0 -27
- package/base/hooks/guard-package.ts +0 -30
- package/base/hooks/guard-remote-hosts.ts +0 -70
- package/base/hooks/guard-scripting.ts +0 -32
- package/base/hooks/post-tool.ts +0 -37
- package/base/hooks/prompt-submit.ts +0 -54
- package/base/hooks/stop.ts +0 -40
- package/base/skills/build-a-feature/evals/evals.json +0 -29
- package/base/skills/docs-update/evals/evals.json +0 -23
- package/base/skills/docs-writing/evals/evals.json +0 -17
- package/base/skills/fix-a-bug/evals/evals.json +0 -17
- package/base/skills/knowledge-sync/SKILL.md +0 -81
- package/base/skills/knowledge-sync/knowledge-sync.workflow.js +0 -291
- package/base/skills/knowledge-sync/references/workflow.md +0 -44
- package/base/skills/plan-a-change/evals/evals.json +0 -47
- package/base/skills/report-back/evals/evals.json +0 -23
- package/base/skills/research/evals/evals.json +0 -17
- package/base/skills/retro/evals/evals.json +0 -17
- package/base/skills/review-a-change/evals/evals.json +0 -17
- package/base/skills/ship/evals/evals.json +0 -23
- package/base/skills/visualize-work/evals/evals.json +0 -17
- package/base/templates/ci/github-actions.yml +0 -75
- package/base/templates/ci/gitlab-ci.yml +0 -52
- package/base/templates/trusted-hosts.local.example +0 -11
- package/src/ci/affected.ts +0 -176
- package/src/ci/command.ts +0 -166
- package/src/ci/common/constants.ts +0 -76
- package/src/ci/common/index.ts +0 -2
- package/src/ci/common/types.ts +0 -37
- package/src/ci/git.ts +0 -72
- package/src/ci/global.ts +0 -48
- package/src/ci/graph.ts +0 -43
- package/src/ci/index.ts +0 -7
- package/src/ci/workspace.ts +0 -119
- package/src/commands/ci.command.ts +0 -4
- package/src/hooks/guard-manifest.ts +0 -109
- package/src/hooks/guard-package.ts +0 -226
- package/src/hooks/guard-scripting.ts +0 -36
- package/src/hooks/host-pattern.ts +0 -17
- package/src/hooks/owner-reply.ts +0 -162
- package/src/hooks/post-tool.ts +0 -138
- package/src/hooks/remote-hosts.ts +0 -1013
- package/src/hooks/trusted-scripts.ts +0 -212
- package/src/owner/shape.ts +0 -496
- package/src/owner/violations.ts +0 -332
- package/src/signals/claims.ts +0 -73
- package/src/signals/classify.ts +0 -137
- package/src/signals/constants.ts +0 -88
- package/src/signals/index.ts +0 -5
- package/src/signals/loop.ts +0 -48
- package/src/signals/state.ts +0 -271
- package/src/sync/atlas-block.ts +0 -56
|
@@ -0,0 +1,898 @@
|
|
|
1
|
+
import type { TConstValue } from '../common/types.ts';
|
|
2
|
+
import type { IWriteCheck, IWriteHit } from './common/index.ts';
|
|
3
|
+
import { ShellParser } from './shell.ts';
|
|
4
|
+
import type { ISimpleCommand } from './shell.ts';
|
|
5
|
+
|
|
6
|
+
/** The options a program takes before its verb (`kubectl -n prod apply`), each with or without a value. */
|
|
7
|
+
const OPTIONS = String.raw`(?:\s+-\S+(?:\s+[^\s-]\S*)?)*`;
|
|
8
|
+
|
|
9
|
+
/** A verb ends at a blank, a quote or an operator, so `set` is not `set-context`. */
|
|
10
|
+
const VERB_END = String.raw`(?=[\s"';|&)]|$)`;
|
|
11
|
+
|
|
12
|
+
/** A program name starts a word: `ssh` is not `sh`, `deploy.sh` is not `sh`. */
|
|
13
|
+
const PROGRAM_START = String.raw`(?:^|[^\w.-])`;
|
|
14
|
+
|
|
15
|
+
/** The rest of one simple command, for a verb that may come anywhere after the program. */
|
|
16
|
+
const REST = String.raw`[^|;&\n]*?`;
|
|
17
|
+
|
|
18
|
+
/** curl's short options that take no value: in a cluster such as `-sd x`, the letters before the one that does. */
|
|
19
|
+
const CURL_SWITCHES = '0-9:#aBfgGhiIjJklLMnNOpqRsSvVZ';
|
|
20
|
+
|
|
21
|
+
const MUTATING_METHOD = '(?:POST|PUT|PATCH|DELETE|post|put|patch|delete)';
|
|
22
|
+
|
|
23
|
+
/** A blank or a block comment between two words of a SQL statement. */
|
|
24
|
+
const SQL_GAP = String.raw`(?:\s|\/\*[\s\S]*?\*\/)+`;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A SQL keyword starts at a word boundary, or right after the option that carries it (`-cDELETE`,
|
|
28
|
+
* `-eDELETE`): the shell gives an attached value as one word with its option.
|
|
29
|
+
*/
|
|
30
|
+
const SQL_START = String.raw`(?:(?<![\w$])|(?<=\s-[A-Za-z0-9]{0,8}[ce]))`;
|
|
31
|
+
|
|
32
|
+
const SQL_WRITE = [
|
|
33
|
+
String.raw`(?:insert|update|delete|truncate|drop|alter|create|grant|revoke)(?=[\s;]|\/\*|$)`,
|
|
34
|
+
String.raw`(?:merge|replace)${SQL_GAP}into\b`,
|
|
35
|
+
String.raw`call${SQL_GAP}[\w."]+\s*\(`,
|
|
36
|
+
String.raw`\\?copy${SQL_GAP}[\w."]+(?:\s*\([^)]*\))?${SQL_GAP}from\b`,
|
|
37
|
+
String.raw`(?:vacuum|reindex)(?=[\s;(]|\/\*|$)`,
|
|
38
|
+
String.raw`refresh${SQL_GAP}materialized${SQL_GAP}view\b`,
|
|
39
|
+
// `cluster` and `lock` are host names too (`psql -h cluster`): they count as a statement's shape only.
|
|
40
|
+
String.raw`cluster(?:\s*(?:;|$)|${SQL_GAP}verbose\b|${SQL_GAP}[\w."]+\s*(?:;|$|using\b))`,
|
|
41
|
+
String.raw`lock${SQL_GAP}(?:table\b|[\w."]+(?:${SQL_GAP}in\b|\s*(?:;|$)))`,
|
|
42
|
+
String.raw`(?:pg_terminate_backend|pg_cancel_backend|setval|nextval|lo_unlink|pg_drop_replication_slot|pg_reload_conf)\s*\(`,
|
|
43
|
+
].join('|');
|
|
44
|
+
|
|
45
|
+
/** The words that make a call change nothing: help, and a dry run (`--dry-run=none` and `=false` run for real). */
|
|
46
|
+
const INERT = String.raw`^(?:--help|-h|-help|--dry-run(?:=(?!(?:none|false)$).*)?)$`;
|
|
47
|
+
|
|
48
|
+
/** For a database tool, where `-h` names the host: only help and the version. */
|
|
49
|
+
const HELP_ONLY = String.raw`^(?:--help|--version|-V|-\?)$`;
|
|
50
|
+
|
|
51
|
+
/** How redis-cli is read: its options, and what it is called with that only reads. */
|
|
52
|
+
class RedisCli {
|
|
53
|
+
/** The options that take the next word, so a value (`-h cache`) is never read as the command. */
|
|
54
|
+
static readonly VALUES: readonly string[] = [
|
|
55
|
+
'-h',
|
|
56
|
+
'-p',
|
|
57
|
+
'-s',
|
|
58
|
+
'-a',
|
|
59
|
+
'-u',
|
|
60
|
+
'-r',
|
|
61
|
+
'-i',
|
|
62
|
+
'-n',
|
|
63
|
+
'-d',
|
|
64
|
+
'-D',
|
|
65
|
+
'-t',
|
|
66
|
+
'--user',
|
|
67
|
+
'--pass',
|
|
68
|
+
'--sni',
|
|
69
|
+
'--cacert',
|
|
70
|
+
'--cacertdir',
|
|
71
|
+
'--cert',
|
|
72
|
+
'--key',
|
|
73
|
+
'--tls-ciphers',
|
|
74
|
+
'--tls-ciphersuites',
|
|
75
|
+
'--pattern',
|
|
76
|
+
'--quoted-pattern',
|
|
77
|
+
'--count',
|
|
78
|
+
'--rdb',
|
|
79
|
+
'--functions-rdb',
|
|
80
|
+
'--pipe-timeout',
|
|
81
|
+
'--memkeys-samples',
|
|
82
|
+
];
|
|
83
|
+
/** The commands that only read; any other command, and the prompt (no command), asks. */
|
|
84
|
+
static readonly READS = [
|
|
85
|
+
'GET|MGET|STRLEN|EXISTS|TYPE|TTL|PTTL|KEYS|SCAN|SSCAN|HSCAN|ZSCAN|INFO|PING|DBSIZE|TIME|ECHO',
|
|
86
|
+
'HGET|HGETALL|HKEYS|HVALS|HLEN|HMGET|HEXISTS',
|
|
87
|
+
'LRANGE|LLEN|LINDEX|SMEMBERS|SCARD|SISMEMBER|SRANDMEMBER',
|
|
88
|
+
'ZRANGE|ZRANGEBYSCORE|ZREVRANGE|ZCARD|ZSCORE|ZRANK',
|
|
89
|
+
'OBJECT|LATENCY|COMMAND',
|
|
90
|
+
'CLIENT[ \t]+LIST|CONFIG[ \t]+GET|MEMORY[ \t]+USAGE|SLOWLOG[ \t]+GET',
|
|
91
|
+
].join('|');
|
|
92
|
+
/** The modes that only read: they scan or sample the server and send no command. */
|
|
93
|
+
static readonly READ_MODES = '^(?:--scan|--bigkeys|--stat|--latency)$';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** How httpie and xh are read: their options, the methods that only read, and the items that send data. */
|
|
97
|
+
class Httpie {
|
|
98
|
+
/** The options that take the next word, so a value (`-a user:pass`) is never read as the URL. */
|
|
99
|
+
static readonly VALUES: readonly string[] = [
|
|
100
|
+
'-a',
|
|
101
|
+
'--auth',
|
|
102
|
+
'-A',
|
|
103
|
+
'--auth-type',
|
|
104
|
+
'-o',
|
|
105
|
+
'--output',
|
|
106
|
+
'--session',
|
|
107
|
+
'--session-read-only',
|
|
108
|
+
'--verify',
|
|
109
|
+
'--cert',
|
|
110
|
+
'--cert-key',
|
|
111
|
+
'--cert-key-pass',
|
|
112
|
+
'--proxy',
|
|
113
|
+
'--timeout',
|
|
114
|
+
'--pretty',
|
|
115
|
+
'-s',
|
|
116
|
+
'--style',
|
|
117
|
+
'-p',
|
|
118
|
+
'--print',
|
|
119
|
+
'-P',
|
|
120
|
+
'--history-print',
|
|
121
|
+
'--max-redirects',
|
|
122
|
+
'--default-scheme',
|
|
123
|
+
'--ssl',
|
|
124
|
+
'--ciphers',
|
|
125
|
+
'--format-options',
|
|
126
|
+
'--response-charset',
|
|
127
|
+
'--response-mime',
|
|
128
|
+
'--boundary',
|
|
129
|
+
'--unix-socket',
|
|
130
|
+
'--resolve',
|
|
131
|
+
'--interface',
|
|
132
|
+
'--http-version',
|
|
133
|
+
'--raw',
|
|
134
|
+
];
|
|
135
|
+
static readonly READS = '(?:GET|HEAD|OPTIONS)';
|
|
136
|
+
/**
|
|
137
|
+
* A request item that sends data, so a POST: its first separator is `=` (not `==`, a query parameter),
|
|
138
|
+
* `:=` or `@`. A `Name:value` header has `:` first.
|
|
139
|
+
*/
|
|
140
|
+
static readonly DATA = '[ \\t](?!-)[^\\s:=@|;&]*(?:=(?!=)|:=|@)';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** One row of the table: a program, with its aliases, and what it is called with that writes. */
|
|
144
|
+
interface IWriteCommandRow {
|
|
145
|
+
rule: 'V-W-02' | 'V-W-03';
|
|
146
|
+
what: string;
|
|
147
|
+
/** The names it is run by. None: the pattern stands alone (`db:migrate` in any command). */
|
|
148
|
+
programs: readonly string[];
|
|
149
|
+
/**
|
|
150
|
+
* The verbs that write, each a run of words split by blanks, a word being alternatives (`state rm`,
|
|
151
|
+
* `up|down`). They come first after the program's options, or anywhere in it when `isAnywhere`.
|
|
152
|
+
*/
|
|
153
|
+
verbs?: readonly string[];
|
|
154
|
+
/** Verbs that start like a write and only read (`rollout status`). */
|
|
155
|
+
reads?: readonly string[];
|
|
156
|
+
isAnywhere?: boolean;
|
|
157
|
+
/** A shape the verbs cannot say, as regular expression source after the program. */
|
|
158
|
+
pattern?: string;
|
|
159
|
+
/** A word that makes a call of the program change nothing (`--help`, `--dry-run`, `--check`). */
|
|
160
|
+
inert?: string;
|
|
161
|
+
ignoreCase?: boolean;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Why the SQL a database client runs cannot be seen. */
|
|
165
|
+
class SqlUnseen {
|
|
166
|
+
static readonly INPUT =
|
|
167
|
+
'writing to a database through SQL that comes from a pipe or a file, which this check cannot see';
|
|
168
|
+
static readonly FILE =
|
|
169
|
+
'writing to a database through a SQL file whose contents this check cannot see';
|
|
170
|
+
static readonly BUILT =
|
|
171
|
+
'writing to a database through SQL built when the command runs, which this check cannot see';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Where a database client takes what it runs. */
|
|
175
|
+
class SqlClientModes {
|
|
176
|
+
/** An option carries the SQL (`psql -c`, `mysql -e`). */
|
|
177
|
+
static readonly INLINE = 'inline';
|
|
178
|
+
/** The words after the database file are SQL, and dot-commands (`sqlite3`). */
|
|
179
|
+
static readonly SQLITE = 'sqlite';
|
|
180
|
+
/** `--eval`, `--file` or a `.js` file (`mongosh`). */
|
|
181
|
+
static readonly MONGO = 'mongo';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
type TSqlClientMode = TConstValue<typeof SqlClientModes>;
|
|
185
|
+
|
|
186
|
+
interface ISqlClient {
|
|
187
|
+
mode: TSqlClientMode;
|
|
188
|
+
/** The option that carries code on the line; the group is a value attached to it. */
|
|
189
|
+
inline: RegExp;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** A row ready to match: its pattern, and what makes a call of its programs change nothing. */
|
|
193
|
+
export interface ICommandCheck extends IWriteCheck {
|
|
194
|
+
programs: ReadonlySet<string>;
|
|
195
|
+
inert: RegExp | undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const DEPLOY = 'deploying or hot-applying to a cluster';
|
|
199
|
+
const CLOUD = 'deploying or changing cloud resources';
|
|
200
|
+
const MIGRATION = 'running a migration instead of handing it to the human';
|
|
201
|
+
const DATABASE = 'writing to a database';
|
|
202
|
+
const REQUEST = 'calling an endpoint that mutates data';
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The commands `guard-writes` asks about, one row per program and its aliases, ordered by how much damage the
|
|
206
|
+
* action does. A verb not listed reads and stays silent; adding a command is adding a row.
|
|
207
|
+
*/
|
|
208
|
+
export class WriteCommands {
|
|
209
|
+
static readonly ROWS: readonly IWriteCommandRow[] = [
|
|
210
|
+
{
|
|
211
|
+
rule: 'V-W-03',
|
|
212
|
+
what: DEPLOY,
|
|
213
|
+
programs: ['kubectl', 'oc'],
|
|
214
|
+
verbs: [
|
|
215
|
+
'apply|patch|delete|scale|rollout|create|replace|set|edit|run|label|annotate|drain|cordon|uncordon|taint|expose|cp|debug|autoscale|exec',
|
|
216
|
+
],
|
|
217
|
+
reads: ['rollout status|history'],
|
|
218
|
+
inert: INERT,
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
rule: 'V-W-03',
|
|
222
|
+
what: DEPLOY,
|
|
223
|
+
programs: ['./kc'],
|
|
224
|
+
verbs: ['apply|patch|delete'],
|
|
225
|
+
inert: INERT,
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
rule: 'V-W-03',
|
|
229
|
+
what: DEPLOY,
|
|
230
|
+
programs: ['docker'],
|
|
231
|
+
verbs: [
|
|
232
|
+
'compose up|down|restart',
|
|
233
|
+
'stack deploy|up|rm|remove|down',
|
|
234
|
+
'service create|update|rm|remove|scale|rollback',
|
|
235
|
+
'swarm init|join|leave|update|unlock',
|
|
236
|
+
'push',
|
|
237
|
+
'image push',
|
|
238
|
+
],
|
|
239
|
+
inert: INERT,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
rule: 'V-W-03',
|
|
243
|
+
what: DEPLOY,
|
|
244
|
+
programs: ['docker-compose'],
|
|
245
|
+
verbs: ['up|down|restart'],
|
|
246
|
+
inert: INERT,
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
rule: 'V-W-03',
|
|
250
|
+
what: DEPLOY,
|
|
251
|
+
programs: ['helm'],
|
|
252
|
+
verbs: ['upgrade|install|rollback|uninstall|delete'],
|
|
253
|
+
inert: INERT,
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
rule: 'V-W-03',
|
|
257
|
+
what: DEPLOY,
|
|
258
|
+
programs: ['helmfile'],
|
|
259
|
+
verbs: ['apply|sync|destroy|delete'],
|
|
260
|
+
inert: INERT,
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
rule: 'V-W-03',
|
|
264
|
+
what: DEPLOY,
|
|
265
|
+
programs: ['argocd'],
|
|
266
|
+
verbs: ['app sync|delete|create'],
|
|
267
|
+
inert: INERT,
|
|
268
|
+
},
|
|
269
|
+
{ rule: 'V-W-03', what: DEPLOY, programs: ['skaffold'], verbs: ['run|deploy'], inert: INERT },
|
|
270
|
+
{
|
|
271
|
+
rule: 'V-W-03',
|
|
272
|
+
what: CLOUD,
|
|
273
|
+
programs: ['terraform', 'tofu', 'terragrunt'],
|
|
274
|
+
verbs: ['apply|destroy|import|taint', 'state rm'],
|
|
275
|
+
inert: INERT,
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
rule: 'V-W-03',
|
|
279
|
+
what: CLOUD,
|
|
280
|
+
programs: ['pulumi'],
|
|
281
|
+
verbs: ['up|update|destroy|refresh'],
|
|
282
|
+
inert: INERT,
|
|
283
|
+
},
|
|
284
|
+
{ rule: 'V-W-03', what: CLOUD, programs: ['cdk'], verbs: ['deploy|destroy'], inert: INERT },
|
|
285
|
+
{
|
|
286
|
+
rule: 'V-W-03',
|
|
287
|
+
what: CLOUD,
|
|
288
|
+
programs: ['flyctl', 'fly'],
|
|
289
|
+
verbs: ['deploy|scale|destroy', 'secrets set', String.raw`\S+ destroy`],
|
|
290
|
+
reads: ['scale show'],
|
|
291
|
+
inert: INERT,
|
|
292
|
+
},
|
|
293
|
+
{ rule: 'V-W-03', what: CLOUD, programs: ['vercel'], verbs: ['deploy|--prod'], inert: INERT },
|
|
294
|
+
{ rule: 'V-W-03', what: CLOUD, programs: ['netlify'], verbs: ['deploy'], inert: INERT },
|
|
295
|
+
{
|
|
296
|
+
rule: 'V-W-03',
|
|
297
|
+
what: CLOUD,
|
|
298
|
+
programs: ['wrangler'],
|
|
299
|
+
verbs: ['deploy|publish|delete', 'secret put'],
|
|
300
|
+
inert: INERT,
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
rule: 'V-W-03',
|
|
304
|
+
what: CLOUD,
|
|
305
|
+
programs: ['gcloud'],
|
|
306
|
+
verbs: [
|
|
307
|
+
'deploy|delete|create|update|set-iam-policy|add-iam-policy-binding',
|
|
308
|
+
'compute instances stop|start',
|
|
309
|
+
'sql instances patch',
|
|
310
|
+
'storage rm',
|
|
311
|
+
],
|
|
312
|
+
isAnywhere: true,
|
|
313
|
+
inert: INERT,
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
rule: 'V-W-03',
|
|
317
|
+
what: CLOUD,
|
|
318
|
+
programs: ['gsutil'],
|
|
319
|
+
verbs: ['rm|cp|mv|rsync'],
|
|
320
|
+
isAnywhere: true,
|
|
321
|
+
inert: INERT,
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
rule: 'V-W-03',
|
|
325
|
+
what: CLOUD,
|
|
326
|
+
programs: ['az'],
|
|
327
|
+
verbs: ['create|delete|update|deploy', 'vm stop|start|deallocate|restart'],
|
|
328
|
+
isAnywhere: true,
|
|
329
|
+
inert: INERT,
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
rule: 'V-W-03',
|
|
333
|
+
what: CLOUD,
|
|
334
|
+
programs: ['aws'],
|
|
335
|
+
verbs: [
|
|
336
|
+
String.raw`(?:update|put|delete|create|terminate|stop|reboot|modify|attach|detach|register|deregister|start)-[\w-]+|run-instances`,
|
|
337
|
+
's3 rm|sync|mv|rb|mb',
|
|
338
|
+
'cloudformation deploy',
|
|
339
|
+
'lambda invoke',
|
|
340
|
+
'sns publish',
|
|
341
|
+
'sqs send-message|send-message-batch|purge-queue',
|
|
342
|
+
'ec2 authorize-security-group-ingress|authorize-security-group-egress',
|
|
343
|
+
'iam add-user-to-group',
|
|
344
|
+
'ssm send-command',
|
|
345
|
+
],
|
|
346
|
+
isAnywhere: true,
|
|
347
|
+
inert: `${INERT}|^--dryrun$`,
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
rule: 'V-W-03',
|
|
351
|
+
what: CLOUD,
|
|
352
|
+
programs: ['aws'],
|
|
353
|
+
// `aws s3 cp` to a bucket: past its options, the source, then an `s3://` word after it.
|
|
354
|
+
pattern: String.raw`${REST}\ss3\s+cp\s+(?:-\S+\s+)*[^\s-]\S*\s(?:[^|;&\n]*\s)?['"]?s3:\/\/`,
|
|
355
|
+
inert: `${INERT}|^--dryrun$`,
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
rule: 'V-W-03',
|
|
359
|
+
what: CLOUD,
|
|
360
|
+
programs: ['ansible-playbook'],
|
|
361
|
+
inert: `${INERT}|^(?:--check|-C|--syntax-check|--list-hosts|--list-tasks|--list-tags)$`,
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
rule: 'V-W-03',
|
|
365
|
+
what: CLOUD,
|
|
366
|
+
programs: ['ansible'],
|
|
367
|
+
// A module that changes the host, or `-a` with no `-m`, which runs the `command` module.
|
|
368
|
+
pattern: [
|
|
369
|
+
String.raw`${REST}\s(?:-m\s*|--module-name[=\s]+)['"]?(?:shell|command|raw|script|copy|file|service|systemd|template|lineinfile)\b`,
|
|
370
|
+
String.raw`(?![^|;&\n]*\s(?:-m|--module-name))${REST}\s(?:-a|--args)(?=[\s=]|$)`,
|
|
371
|
+
]
|
|
372
|
+
.map((alternative) => `(?:${alternative})`)
|
|
373
|
+
.join('|'),
|
|
374
|
+
inert: `${INERT}|^(?:--check|-C)$`,
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
rule: 'V-W-02',
|
|
378
|
+
what: MIGRATION,
|
|
379
|
+
programs: [],
|
|
380
|
+
pattern: String.raw`\bdb:migrate(?!:status\b)\b|\bmigrate:(dev|local|alpha|develop)\b|make\s+db-migrate\b`,
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
rule: 'V-W-02',
|
|
384
|
+
what: MIGRATION,
|
|
385
|
+
programs: ['drizzle-kit'],
|
|
386
|
+
verbs: ['push|migrate|up|drop'],
|
|
387
|
+
inert: INERT,
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
rule: 'V-W-02',
|
|
391
|
+
what: MIGRATION,
|
|
392
|
+
programs: ['prisma'],
|
|
393
|
+
verbs: ['migrate deploy|reset|resolve', 'db push|execute'],
|
|
394
|
+
inert: INERT,
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
rule: 'V-W-02',
|
|
398
|
+
what: MIGRATION,
|
|
399
|
+
programs: ['prisma'],
|
|
400
|
+
verbs: ['migrate dev'],
|
|
401
|
+
// `--create-only` writes the migration file and runs nothing.
|
|
402
|
+
inert: `${INERT}|^--create-only$`,
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
rule: 'V-W-02',
|
|
406
|
+
what: MIGRATION,
|
|
407
|
+
programs: ['knex'],
|
|
408
|
+
verbs: ['migrate:latest|migrate:up|migrate:down|migrate:rollback'],
|
|
409
|
+
inert: INERT,
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
rule: 'V-W-02',
|
|
413
|
+
what: MIGRATION,
|
|
414
|
+
programs: ['typeorm', 'typeorm-ts-node-commonjs', 'typeorm-ts-node-esm'],
|
|
415
|
+
verbs: ['migration:run|migration:revert|schema:drop|schema:sync'],
|
|
416
|
+
inert: INERT,
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
rule: 'V-W-02',
|
|
420
|
+
what: MIGRATION,
|
|
421
|
+
programs: ['alembic'],
|
|
422
|
+
verbs: ['upgrade|downgrade|stamp'],
|
|
423
|
+
// `--sql` prints the SQL of the migration (offline mode) and connects to nothing.
|
|
424
|
+
inert: `${INERT}|^--sql$`,
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
rule: 'V-W-02',
|
|
428
|
+
what: MIGRATION,
|
|
429
|
+
programs: ['manage.py', 'django-admin'],
|
|
430
|
+
verbs: ['migrate|flush|loaddata'],
|
|
431
|
+
inert: `${INERT}|^--plan$`,
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
rule: 'V-W-02',
|
|
435
|
+
what: 'opening a shell on the project or its database, whose commands this check cannot see',
|
|
436
|
+
programs: ['manage.py', 'django-admin'],
|
|
437
|
+
verbs: ['shell|dbshell'],
|
|
438
|
+
inert: INERT,
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
rule: 'V-W-02',
|
|
442
|
+
what: MIGRATION,
|
|
443
|
+
programs: ['flyway'],
|
|
444
|
+
verbs: ['migrate|clean|baseline|repair'],
|
|
445
|
+
inert: INERT,
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
rule: 'V-W-02',
|
|
449
|
+
what: MIGRATION,
|
|
450
|
+
programs: ['goose'],
|
|
451
|
+
verbs: ['up|down|reset|redo|up-by-one|up-to|down-to'],
|
|
452
|
+
isAnywhere: true,
|
|
453
|
+
inert: INERT,
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
rule: 'V-W-02',
|
|
457
|
+
what: MIGRATION,
|
|
458
|
+
programs: ['dbmate'],
|
|
459
|
+
verbs: ['up|down|drop|rollback|migrate'],
|
|
460
|
+
inert: INERT,
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
rule: 'V-W-02',
|
|
464
|
+
what: MIGRATION,
|
|
465
|
+
programs: ['supabase'],
|
|
466
|
+
verbs: ['db push|reset'],
|
|
467
|
+
inert: INERT,
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
rule: 'V-W-02',
|
|
471
|
+
what: MIGRATION,
|
|
472
|
+
programs: ['sequelize', 'sequelize-cli'],
|
|
473
|
+
verbs: [String.raw`db:migrate(?::[\w:]+)?|db:seed(?::[\w:]+)?`],
|
|
474
|
+
reads: ['db:migrate:status'],
|
|
475
|
+
inert: INERT,
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
rule: 'V-W-02',
|
|
479
|
+
what: MIGRATION,
|
|
480
|
+
programs: ['rails', 'rake'],
|
|
481
|
+
verbs: [
|
|
482
|
+
'db:migrate|db:drop|db:reset|db:seed|db:rollback|db:setup|db:schema:load|db:structure:load',
|
|
483
|
+
],
|
|
484
|
+
inert: INERT,
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
rule: 'V-W-02',
|
|
488
|
+
what: MIGRATION,
|
|
489
|
+
programs: ['artisan'],
|
|
490
|
+
verbs: [String.raw`migrate(?::(?:fresh|refresh|reset|rollback))?|db:seed|db:wipe`],
|
|
491
|
+
inert: INERT,
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
rule: 'V-W-02',
|
|
495
|
+
what: DATABASE,
|
|
496
|
+
programs: [],
|
|
497
|
+
pattern: String.raw`\b(?-i:psql|mysql|mariadb|mongosh|mongo|sqlite3)\b[^|]*?${SQL_START}(?:${SQL_WRITE})|\b(?-i:mongo(?:sh)?)\b[^|]*?\.(?:insert|update|delete|remove|replace|drop|bulkWrite|findOneAnd|findAndModify|createCollection|createIndex|renameCollection|runCommand|adminCommand)\w*\s*\(`,
|
|
498
|
+
ignoreCase: true,
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
rule: 'V-W-02',
|
|
502
|
+
what: SqlUnseen.FILE,
|
|
503
|
+
programs: [],
|
|
504
|
+
pattern: String.raw`\b(psql|mysql|mariadb)\b[^|]*\s-f\s|\bpsql\b[^|]*\s(?:-[aAbeEHlnqsStwWxX0-9z]*f|--file\b)`,
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
rule: 'V-W-02',
|
|
508
|
+
what: 'running a redis-cli command that is not a known read, or its prompt',
|
|
509
|
+
programs: ['redis-cli'],
|
|
510
|
+
pattern: String.raw`${WriteCommands.optionsOf({ values: RedisCli.VALUES })}(?![ \t]+(?:${RedisCli.READS})${VERB_END})`,
|
|
511
|
+
inert: `${HELP_ONLY}|${RedisCli.READ_MODES}`,
|
|
512
|
+
ignoreCase: true,
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
rule: 'V-W-02',
|
|
516
|
+
what: DATABASE,
|
|
517
|
+
programs: ['dropdb', 'createdb', 'createuser', 'dropuser', 'mongoimport'],
|
|
518
|
+
inert: HELP_ONLY,
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
rule: 'V-W-02',
|
|
522
|
+
what: DATABASE,
|
|
523
|
+
programs: ['pg_restore'],
|
|
524
|
+
inert: `${HELP_ONLY}|^(?:-l|--list)$`,
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
rule: 'V-W-02',
|
|
528
|
+
what: DATABASE,
|
|
529
|
+
programs: ['mongorestore'],
|
|
530
|
+
inert: `${HELP_ONLY}|^--dryRun$`,
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
rule: 'V-W-02',
|
|
534
|
+
what: DATABASE,
|
|
535
|
+
programs: ['mysqladmin'],
|
|
536
|
+
verbs: ['drop|create|shutdown'],
|
|
537
|
+
isAnywhere: true,
|
|
538
|
+
inert: HELP_ONLY,
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
rule: 'V-W-02',
|
|
542
|
+
what: REQUEST,
|
|
543
|
+
programs: ['curl'],
|
|
544
|
+
// A request body sent with `-d` or `--data*`. `-G` is not read: curl applies it per `--next` group.
|
|
545
|
+
pattern: String.raw`[^|]*\s(?:-[${CURL_SWITCHES}]*d|--data\b)`,
|
|
546
|
+
inert: INERT,
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
rule: 'V-W-02',
|
|
550
|
+
what: REQUEST,
|
|
551
|
+
programs: ['curl'],
|
|
552
|
+
pattern: String.raw`[^|]*\s(?:-[${CURL_SWITCHES}]*[FT]|--(?:json|form|upload-file)\b)`,
|
|
553
|
+
inert: INERT,
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
rule: 'V-W-02',
|
|
557
|
+
what: REQUEST,
|
|
558
|
+
programs: ['curl'],
|
|
559
|
+
pattern: String.raw`[^|]*\s(?:-[${CURL_SWITCHES}]*X\s*|--request(?:=|\s+))['"]?${MUTATING_METHOD}\b`,
|
|
560
|
+
inert: INERT,
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
rule: 'V-W-02',
|
|
564
|
+
what: 'calling an endpoint with options read from a file this check cannot see',
|
|
565
|
+
programs: ['curl'],
|
|
566
|
+
pattern: String.raw`[^|]*\s(?:-[${CURL_SWITCHES}]*K|--config\b)`,
|
|
567
|
+
inert: INERT,
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
rule: 'V-W-02',
|
|
571
|
+
what: REQUEST,
|
|
572
|
+
programs: ['wget'],
|
|
573
|
+
pattern: String.raw`${REST}\s(?:--post-(?:data|file)|--body-(?:data|file)|--method(?:=|\s+)['"]?${MUTATING_METHOD}\b)`,
|
|
574
|
+
inert: INERT,
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
rule: 'V-W-02',
|
|
578
|
+
what: REQUEST,
|
|
579
|
+
// httpie's `-h` prints headers, so only `--help` and `--offline` send nothing.
|
|
580
|
+
programs: ['http', 'https', 'xh', 'xhs'],
|
|
581
|
+
// A raw body; past the options, a method that is not a read, or no method and a data item after the URL.
|
|
582
|
+
pattern: [
|
|
583
|
+
String.raw`(?=${REST}[ \t]--raw\b)`,
|
|
584
|
+
`${WriteCommands.optionsOf({ values: Httpie.VALUES })}(?:${[
|
|
585
|
+
String.raw`[ \t]+(?!${Httpie.READS}[ \t])[A-Za-z]+[ \t]+\S`,
|
|
586
|
+
// The URL is read whole, so a long one is not tried again at every shorter length.
|
|
587
|
+
String.raw`[ \t]+(?![A-Za-z]+[ \t]+\S)(?=(?<url>[^\s|;&]+))\k<url>[^|;&\n]*?${Httpie.DATA}`,
|
|
588
|
+
].join('|')})`,
|
|
589
|
+
].join('|'),
|
|
590
|
+
inert: '^(?:--help|--offline)$',
|
|
591
|
+
ignoreCase: true,
|
|
592
|
+
},
|
|
593
|
+
];
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Database clients and where they take what they run. `inline` is the option that carries SQL on the line,
|
|
597
|
+
* its value attached or the next word; with none (and no heredoc) a client reads SQL from its input.
|
|
598
|
+
* `sqlite3` takes SQL as the words after the database file; `mongosh` takes `--eval`, `--file` or a file.
|
|
599
|
+
*/
|
|
600
|
+
static readonly SQL_CLIENTS: Readonly<Record<string, ISqlClient>> = {
|
|
601
|
+
psql: {
|
|
602
|
+
mode: SqlClientModes.INLINE,
|
|
603
|
+
inline: /^(?:-[aAbeEHlnqsStwWxX0-9z]*c|--command(?:=|$))([\s\S]*)$/,
|
|
604
|
+
},
|
|
605
|
+
mysql: {
|
|
606
|
+
mode: SqlClientModes.INLINE,
|
|
607
|
+
inline: /^(?:-[BNnqrstvX]*e|--execute(?:=|$))([\s\S]*)$/,
|
|
608
|
+
},
|
|
609
|
+
mariadb: {
|
|
610
|
+
mode: SqlClientModes.INLINE,
|
|
611
|
+
inline: /^(?:-[BNnqrstvX]*e|--execute(?:=|$))([\s\S]*)$/,
|
|
612
|
+
},
|
|
613
|
+
sqlite3: { mode: SqlClientModes.SQLITE, inline: /^--?cmd(?:=|$)([\s\S]*)$/ },
|
|
614
|
+
mongosh: { mode: SqlClientModes.MONGO, inline: /^--eval(?:=|$)([\s\S]*)$/ },
|
|
615
|
+
mongo: { mode: SqlClientModes.MONGO, inline: /^--eval(?:=|$)([\s\S]*)$/ },
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
/** The options that make a database client only print something and read nothing. */
|
|
619
|
+
static readonly SQL_CLIENT_INFO = new Set([
|
|
620
|
+
'-l',
|
|
621
|
+
'--list',
|
|
622
|
+
'-V',
|
|
623
|
+
'--version',
|
|
624
|
+
'-version',
|
|
625
|
+
'--help',
|
|
626
|
+
'-help',
|
|
627
|
+
'-?',
|
|
628
|
+
]);
|
|
629
|
+
|
|
630
|
+
/** The `sqlite3` options that take the next word. */
|
|
631
|
+
static readonly SQLITE_VALUES = new Set([
|
|
632
|
+
'-cmd',
|
|
633
|
+
'-init',
|
|
634
|
+
'-separator',
|
|
635
|
+
'-newline',
|
|
636
|
+
'-nullvalue',
|
|
637
|
+
'-vfs',
|
|
638
|
+
'-mmap',
|
|
639
|
+
'-pagecache',
|
|
640
|
+
'-lookaside',
|
|
641
|
+
'-heap',
|
|
642
|
+
'-maxsize',
|
|
643
|
+
]);
|
|
644
|
+
|
|
645
|
+
/** A client command that runs a SQL file: psql's `\i`, mysql's `source` and `\.`, sqlite3's `.read`. */
|
|
646
|
+
static readonly SQL_FILE_COMMAND =
|
|
647
|
+
/(?:^|;)\s*(?:\\(?:i|ir|include|include_relative|\.)\s|source\s|\.(?:read|import|restore)\s)/im;
|
|
648
|
+
|
|
649
|
+
/** The rows, compiled. */
|
|
650
|
+
static readonly CHECKS: readonly ICommandCheck[] = WriteCommands.ROWS.map((row) =>
|
|
651
|
+
WriteCommands.compile({ row }),
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* The options before a program's command, read whole, as a pattern: a value (`-h cache`) is never the command,
|
|
656
|
+
* and no shorter run is tried, so a look at the command that follows cannot be passed by backing off.
|
|
657
|
+
*/
|
|
658
|
+
private static optionsOf(opts: { values: readonly string[] }): string {
|
|
659
|
+
const option = String.raw`[ \t]+(?:(?:${opts.values.join('|')})[ \t]+[^\s|;&]+|-[^\s|;&]*)`;
|
|
660
|
+
|
|
661
|
+
return String.raw`(?=(?<options>(?:${option})*))\k<options>`;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/** A run of words, each a set of alternatives, with the program's options allowed between them. */
|
|
665
|
+
private static wordsOf(opts: { verb: string }): string {
|
|
666
|
+
return opts.verb
|
|
667
|
+
.split(' ')
|
|
668
|
+
.map((word) => `(?:${word})`)
|
|
669
|
+
.join(`${OPTIONS}\\s+`);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
private static compile(opts: { row: IWriteCommandRow }): ICommandCheck {
|
|
673
|
+
const { row } = opts;
|
|
674
|
+
const names = row.programs.map((name) => name.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&'));
|
|
675
|
+
// A program name is exact (`HTTP` in TypeScript is no `http`): `ignoreCase` covers the words after it.
|
|
676
|
+
const head = names.length === 0 ? '' : `${PROGRAM_START}(?-i:${names.join('|')})`;
|
|
677
|
+
const verbs = (row.verbs ?? []).map((verb) => WriteCommands.wordsOf({ verb })).join('|');
|
|
678
|
+
const reads = (row.reads ?? []).map((verb) => WriteCommands.wordsOf({ verb })).join('|');
|
|
679
|
+
const notRead = reads === '' ? '' : `(?!(?:${reads})${VERB_END})`;
|
|
680
|
+
const body = WriteCommands.bodyOf({ row, verbs, notRead });
|
|
681
|
+
|
|
682
|
+
return {
|
|
683
|
+
rule: row.rule,
|
|
684
|
+
what: row.what,
|
|
685
|
+
pattern: new RegExp(`${head}${body}`, row.ignoreCase === true ? 'i' : ''),
|
|
686
|
+
programs: new Set(row.programs.map((name) => ShellParser.basenameOf({ word: name }))),
|
|
687
|
+
inert: row.inert === undefined ? undefined : new RegExp(row.inert),
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/** What follows the program: its own pattern, its verbs (first, or anywhere), or nothing (any call writes). */
|
|
692
|
+
private static bodyOf(opts: { row: IWriteCommandRow; verbs: string; notRead: string }): string {
|
|
693
|
+
const { row, verbs, notRead } = opts;
|
|
694
|
+
|
|
695
|
+
// The name ends where the pattern starts: `ansible` is not `ansible-playbook`.
|
|
696
|
+
if (row.pattern !== undefined) {
|
|
697
|
+
return row.programs.length === 0 ? row.pattern : `${VERB_END}(?:${row.pattern})`;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
if (verbs === '') {
|
|
701
|
+
return VERB_END;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
if (row.isAnywhere === true) {
|
|
705
|
+
return `${VERB_END}${REST}\\s${notRead}(?:${verbs})${VERB_END}`;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
return `${OPTIONS}\\s+${notRead}(?:${verbs})${VERB_END}`;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Whether a check applies to a call of `program` with `args`: not when the program is one of the check's
|
|
713
|
+
* own and a word makes the call change nothing (`kubectl apply --dry-run=client`). A word right after an
|
|
714
|
+
* option is no inert word: it may be the option's value (`kubectl apply -f x --field-manager --dry-run=client`
|
|
715
|
+
* applies), and no table of which options take a value is complete. An inert word whose option is named more
|
|
716
|
+
* than once on the line is not read either: the last value wins.
|
|
717
|
+
*/
|
|
718
|
+
static isLive(opts: { check: ICommandCheck; program: string; args: readonly string[] }): boolean {
|
|
719
|
+
const { inert } = opts.check;
|
|
720
|
+
|
|
721
|
+
if (inert === undefined || !opts.check.programs.has(opts.program)) {
|
|
722
|
+
return true;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// The last value of an option wins: `--dry-run --dry-run=none` runs for real. An option named twice is not read.
|
|
726
|
+
const nameOf = (word: string): string => word.split('=')[0] ?? word;
|
|
727
|
+
|
|
728
|
+
return !opts.args.some((word, index) => {
|
|
729
|
+
const previous = opts.args[index - 1] ?? '';
|
|
730
|
+
|
|
731
|
+
return (
|
|
732
|
+
inert.test(word) &&
|
|
733
|
+
!(previous.startsWith('-') && !previous.includes('=')) &&
|
|
734
|
+
!opts.args.some((other, at) => at !== index && nameOf(other) === nameOf(word))
|
|
735
|
+
);
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* What a database client runs that the line does not show: SQL from its input (a pipe, a `<` file, the
|
|
740
|
+
* terminal), a file it is told to run, or SQL built when the command runs (`psql -c "$SQL"`).
|
|
741
|
+
*/
|
|
742
|
+
static inspectClient(opts: { command: ISimpleCommand }): IWriteHit[] {
|
|
743
|
+
const { name, args } = ShellParser.programOf({ command: opts.command });
|
|
744
|
+
const client = WriteCommands.SQL_CLIENTS[ShellParser.basenameOf({ word: name })];
|
|
745
|
+
|
|
746
|
+
if (client === undefined || args.some((word) => WriteCommands.SQL_CLIENT_INFO.has(word))) {
|
|
747
|
+
return [];
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const values = WriteCommands.valuesOf({ args, option: client.inline });
|
|
751
|
+
const hasHeredoc = opts.command.heredoc !== undefined;
|
|
752
|
+
|
|
753
|
+
switch (client.mode) {
|
|
754
|
+
case SqlClientModes.SQLITE: {
|
|
755
|
+
return WriteCommands.sqliteHitsOf({
|
|
756
|
+
args: WriteCommands.withoutInput({ args, command: opts.command }),
|
|
757
|
+
values,
|
|
758
|
+
hasHeredoc,
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
case SqlClientModes.MONGO: {
|
|
762
|
+
const hasFile = args.some(
|
|
763
|
+
(word, index) =>
|
|
764
|
+
/^(?:--file(?:=|$)|-f$)/.test(word) ||
|
|
765
|
+
(/\.(?:js|mongodb)$/.test(word) && !WriteCommands.isValueAt({ args, index, client })),
|
|
766
|
+
);
|
|
767
|
+
|
|
768
|
+
if (hasFile) {
|
|
769
|
+
return [WriteCommands.hitOf({ message: SqlUnseen.FILE })];
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
return values.length === 0 && !hasHeredoc
|
|
773
|
+
? [WriteCommands.hitOf({ message: SqlUnseen.INPUT })]
|
|
774
|
+
: [];
|
|
775
|
+
}
|
|
776
|
+
default: {
|
|
777
|
+
if (values.length === 0) {
|
|
778
|
+
return hasHeredoc ? [] : [WriteCommands.hitOf({ message: SqlUnseen.INPUT })];
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return WriteCommands.valueHitsOf({ values });
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/** The words of a command without the files of its `<` redirects, which the shell puts among them. */
|
|
787
|
+
private static withoutInput(opts: {
|
|
788
|
+
args: readonly string[];
|
|
789
|
+
command: ISimpleCommand;
|
|
790
|
+
}): string[] {
|
|
791
|
+
const files = [...(opts.command.input?.files ?? [])];
|
|
792
|
+
|
|
793
|
+
return opts.args.filter((word) => {
|
|
794
|
+
const at = files.indexOf(word);
|
|
795
|
+
|
|
796
|
+
if (at === -1) {
|
|
797
|
+
return true;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
files.splice(at, 1);
|
|
801
|
+
|
|
802
|
+
return false;
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/** `sqlite3 [options] FILE [SQL...]`: no SQL reads the input; `-init` and `.read` run a file. */
|
|
807
|
+
private static sqliteHitsOf(opts: {
|
|
808
|
+
args: readonly string[];
|
|
809
|
+
values: string[];
|
|
810
|
+
hasHeredoc: boolean;
|
|
811
|
+
}): IWriteHit[] {
|
|
812
|
+
const { args } = opts;
|
|
813
|
+
const positional: string[] = [];
|
|
814
|
+
let hasInit = false;
|
|
815
|
+
|
|
816
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
817
|
+
const word = args[index] ?? '';
|
|
818
|
+
const option = word.startsWith('--') ? word.slice(1) : word;
|
|
819
|
+
|
|
820
|
+
if (!word.startsWith('-')) {
|
|
821
|
+
positional.push(word);
|
|
822
|
+
continue;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
hasInit ||= option === '-init';
|
|
826
|
+
index += WriteCommands.SQLITE_VALUES.has(option) ? 1 : 0;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
if (hasInit) {
|
|
830
|
+
return [WriteCommands.hitOf({ message: SqlUnseen.FILE })];
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
const sql = [...positional.slice(1), ...opts.values];
|
|
834
|
+
|
|
835
|
+
if (sql.length === 0) {
|
|
836
|
+
return opts.hasHeredoc ? [] : [WriteCommands.hitOf({ message: SqlUnseen.INPUT })];
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
return WriteCommands.valueHitsOf({ values: sql });
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/** SQL on the line that runs a file, or that the shell builds when the command runs. */
|
|
843
|
+
private static valueHitsOf(opts: { values: readonly string[] }): IWriteHit[] {
|
|
844
|
+
const hits: IWriteHit[] = [];
|
|
845
|
+
|
|
846
|
+
if (opts.values.some((value) => /[$`]/.test(value))) {
|
|
847
|
+
hits.push(WriteCommands.hitOf({ message: SqlUnseen.BUILT }));
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
if (opts.values.some((value) => WriteCommands.SQL_FILE_COMMAND.test(value))) {
|
|
851
|
+
hits.push(WriteCommands.hitOf({ message: SqlUnseen.FILE }));
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
return hits;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/** The values of `option` among `args`: attached to it, or the next word. */
|
|
858
|
+
private static valuesOf(opts: { args: readonly string[]; option: RegExp }): string[] {
|
|
859
|
+
const values: string[] = [];
|
|
860
|
+
|
|
861
|
+
opts.args.forEach((word, index) => {
|
|
862
|
+
const match = opts.option.exec(word);
|
|
863
|
+
|
|
864
|
+
if (match === null) {
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
const attached = match[1] ?? '';
|
|
869
|
+
const next = opts.args[index + 1];
|
|
870
|
+
|
|
871
|
+
if (attached !== '') {
|
|
872
|
+
values.push(attached);
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
if (next !== undefined) {
|
|
877
|
+
values.push(next);
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
return values;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/** Whether the word at `index` is the value of the client's inline option. */
|
|
885
|
+
private static isValueAt(opts: {
|
|
886
|
+
args: readonly string[];
|
|
887
|
+
index: number;
|
|
888
|
+
client: ISqlClient;
|
|
889
|
+
}): boolean {
|
|
890
|
+
const previous = opts.args[opts.index - 1];
|
|
891
|
+
|
|
892
|
+
return previous !== undefined && opts.client.inline.exec(previous)?.[1] === '';
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
private static hitOf(opts: { message: string }): IWriteHit {
|
|
896
|
+
return { rule: 'V-W-02', message: opts.message };
|
|
897
|
+
}
|
|
898
|
+
}
|