@rafter-security/cli 0.5.3 → 0.5.5
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/dist/commands/agent/audit-skill.js +1 -1
- package/dist/commands/agent/baseline.js +203 -0
- package/dist/commands/agent/index.js +4 -0
- package/dist/commands/agent/init.js +5 -3
- package/dist/commands/agent/install-hook.js +41 -47
- package/dist/commands/agent/scan.js +40 -8
- package/dist/commands/agent/update-gitleaks.js +40 -0
- package/dist/commands/completion.js +308 -110
- package/dist/core/audit-logger.js +41 -0
- package/dist/core/config-defaults.js +4 -0
- package/dist/core/risk-rules.js +5 -3
- package/dist/index.js +1 -1
- package/dist/utils/binary-manager.js +52 -14
- package/package.json +1 -1
- package/resources/pre-push-hook.sh +60 -0
|
@@ -1,106 +1,236 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
const BASH_COMPLETION =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
_rafter_completion() {
|
|
6
|
-
local cur prev words
|
|
2
|
+
const BASH_COMPLETION = `# rafter bash completion
|
|
3
|
+
_rafter_completions() {
|
|
4
|
+
local cur prev commands
|
|
7
5
|
COMPREPLY=()
|
|
8
6
|
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
9
7
|
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
10
|
-
words="\${COMP_WORDS[*]}"
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
local ci_cmds="init"
|
|
15
|
-
local hook_cmds="pretool posttool"
|
|
16
|
-
local policy_cmds="export"
|
|
9
|
+
# Top-level commands
|
|
10
|
+
commands="run scan get usage agent ci hook mcp policy completion help"
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
case "\${COMP_WORDS[1]}" in
|
|
12
|
+
case "\${prev}" in
|
|
13
|
+
rafter)
|
|
14
|
+
COMPREPLY=( $(compgen -W "\${commands} --agent --version --help" -- "\${cur}") )
|
|
15
|
+
return 0
|
|
16
|
+
;;
|
|
24
17
|
agent)
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
COMPREPLY=( $(compgen -W "scan init audit config exec audit-skill install-hook verify status update-gitleaks baseline --help" -- "\${cur}") )
|
|
19
|
+
return 0
|
|
20
|
+
;;
|
|
21
|
+
config)
|
|
22
|
+
if [[ "\${COMP_WORDS[1]}" == "agent" ]]; then
|
|
23
|
+
COMPREPLY=( $(compgen -W "show get set --help" -- "\${cur}") )
|
|
27
24
|
fi
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
audit-skill) COMPREPLY=( \$(compgen -W "--skip-openclaw --json" -- "\${cur}") ) ;;
|
|
34
|
-
install-hook) COMPREPLY=( \$(compgen -W "--global" -- "\${cur}") ) ;;
|
|
35
|
-
config) COMPREPLY=( \$(compgen -W "show get set" -- "\${cur}") ) ;;
|
|
36
|
-
audit) COMPREPLY=( \$(compgen -W "--last --event --agent --since" -- "\${cur}") ) ;;
|
|
37
|
-
esac
|
|
25
|
+
return 0
|
|
26
|
+
;;
|
|
27
|
+
ci)
|
|
28
|
+
COMPREPLY=( $(compgen -W "init --help" -- "\${cur}") )
|
|
29
|
+
return 0
|
|
38
30
|
;;
|
|
39
31
|
hook)
|
|
40
|
-
COMPREPLY=(
|
|
32
|
+
COMPREPLY=( $(compgen -W "pretool --help" -- "\${cur}") )
|
|
33
|
+
return 0
|
|
41
34
|
;;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
fi
|
|
35
|
+
mcp)
|
|
36
|
+
COMPREPLY=( $(compgen -W "serve --help" -- "\${cur}") )
|
|
37
|
+
return 0
|
|
46
38
|
;;
|
|
47
39
|
policy)
|
|
48
|
-
COMPREPLY=(
|
|
49
|
-
|
|
50
|
-
run|scan)
|
|
51
|
-
COMPREPLY=( \$(compgen -W "--api-key --format --quiet" -- "\${cur}") )
|
|
40
|
+
COMPREPLY=( $(compgen -W "export --help" -- "\${cur}") )
|
|
41
|
+
return 0
|
|
52
42
|
;;
|
|
53
43
|
completion)
|
|
54
|
-
COMPREPLY=(
|
|
44
|
+
COMPREPLY=( $(compgen -W "bash zsh fish" -- "\${cur}") )
|
|
45
|
+
return 0
|
|
46
|
+
;;
|
|
47
|
+
scan)
|
|
48
|
+
if [[ "\${COMP_WORDS[1]}" == "agent" ]]; then
|
|
49
|
+
COMPREPLY=( $(compgen -W "--quiet --json --staged --diff --engine --help" -- "\${cur}") )
|
|
50
|
+
else
|
|
51
|
+
COMPREPLY=( $(compgen -W "--repo --branch --api-key --format --skip-interactive --quiet --help" -- "\${cur}") )
|
|
52
|
+
fi
|
|
53
|
+
return 0
|
|
54
|
+
;;
|
|
55
|
+
run)
|
|
56
|
+
COMPREPLY=( $(compgen -W "--repo --branch --api-key --format --skip-interactive --quiet --help" -- "\${cur}") )
|
|
57
|
+
return 0
|
|
58
|
+
;;
|
|
59
|
+
get)
|
|
60
|
+
COMPREPLY=( $(compgen -W "--api-key --format --interactive --quiet --help" -- "\${cur}") )
|
|
61
|
+
return 0
|
|
62
|
+
;;
|
|
63
|
+
init)
|
|
64
|
+
if [[ "\${COMP_WORDS[1]}" == "agent" ]]; then
|
|
65
|
+
COMPREPLY=( $(compgen -W "--risk-level --skip-openclaw --skip-claude-code --claude-code --skip-gitleaks --help" -- "\${cur}") )
|
|
66
|
+
elif [[ "\${COMP_WORDS[1]}" == "ci" ]]; then
|
|
67
|
+
COMPREPLY=( $(compgen -W "--platform --output --with-backend --help" -- "\${cur}") )
|
|
68
|
+
fi
|
|
69
|
+
return 0
|
|
55
70
|
;;
|
|
56
71
|
esac
|
|
57
72
|
}
|
|
58
|
-
complete -F
|
|
73
|
+
complete -F _rafter_completions rafter
|
|
59
74
|
`;
|
|
60
|
-
const ZSH_COMPLETION =
|
|
61
|
-
# rafter zsh completion
|
|
62
|
-
# Add to ~/.zshrc: eval "$(rafter completion zsh)"
|
|
63
|
-
#compdef rafter
|
|
75
|
+
const ZSH_COMPLETION = `#compdef rafter
|
|
64
76
|
|
|
65
77
|
_rafter() {
|
|
66
|
-
local
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
'
|
|
71
|
-
'
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
local -a commands
|
|
79
|
+
commands=(
|
|
80
|
+
'run:Submit a security scan to the Rafter backend'
|
|
81
|
+
'scan:Alias for run'
|
|
82
|
+
'get:Retrieve scan results'
|
|
83
|
+
'usage:Check API usage quota'
|
|
84
|
+
'agent:Agent security commands'
|
|
85
|
+
'ci:CI/CD pipeline setup'
|
|
86
|
+
'hook:Git hook handlers'
|
|
87
|
+
'mcp:MCP server'
|
|
88
|
+
'policy:Policy management'
|
|
89
|
+
'completion:Generate shell completions'
|
|
90
|
+
'help:Display help'
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
local -a agent_commands
|
|
94
|
+
agent_commands=(
|
|
95
|
+
'scan:Scan files for secrets locally'
|
|
96
|
+
'init:Initialize agent security'
|
|
97
|
+
'audit:View audit log'
|
|
98
|
+
'config:Manage configuration'
|
|
99
|
+
'exec:Execute command with security'
|
|
100
|
+
'audit-skill:Audit a Claude Code skill'
|
|
101
|
+
'install-hook:Install git hook (pre-commit or pre-push)'
|
|
102
|
+
'verify:Check integration status'
|
|
103
|
+
'status:Show agent status'
|
|
104
|
+
'update-gitleaks:Update gitleaks binary'
|
|
105
|
+
'baseline:Manage findings baseline'
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
local -a config_commands
|
|
109
|
+
config_commands=(
|
|
110
|
+
'show:Show current configuration'
|
|
111
|
+
'get:Get a configuration value'
|
|
112
|
+
'set:Set a configuration value'
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
_arguments -C \\
|
|
116
|
+
'(-a --agent)'{-a,--agent}'[Plain output for AI agents]' \\
|
|
117
|
+
'(-V --version)'{-V,--version}'[Show version]' \\
|
|
118
|
+
'(-h --help)'{-h,--help}'[Show help]' \\
|
|
119
|
+
'1:command:->command' \\
|
|
120
|
+
'*::arg:->args'
|
|
121
|
+
|
|
122
|
+
case "\$state" in
|
|
123
|
+
command)
|
|
124
|
+
_describe 'command' commands
|
|
84
125
|
;;
|
|
85
126
|
args)
|
|
86
|
-
case \$words[
|
|
127
|
+
case "\$words[1]" in
|
|
87
128
|
agent)
|
|
88
|
-
|
|
89
|
-
'
|
|
90
|
-
'
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
129
|
+
_arguments -C \\
|
|
130
|
+
'1:subcommand:->subcmd' \\
|
|
131
|
+
'*::arg:->subargs'
|
|
132
|
+
case "\$state" in
|
|
133
|
+
subcmd)
|
|
134
|
+
_describe 'agent command' agent_commands
|
|
135
|
+
;;
|
|
136
|
+
subargs)
|
|
137
|
+
case "\$words[1]" in
|
|
138
|
+
scan)
|
|
139
|
+
_arguments \\
|
|
140
|
+
'(-q --quiet)'{-q,--quiet}'[Only output if secrets found]' \\
|
|
141
|
+
'--json[Output as JSON]' \\
|
|
142
|
+
'--staged[Scan only staged files]' \\
|
|
143
|
+
'--diff[Scan files changed since ref]:ref:' \\
|
|
144
|
+
'--engine[Scanner engine]:engine:(gitleaks patterns)' \\
|
|
145
|
+
'1:path:_files'
|
|
146
|
+
;;
|
|
147
|
+
init)
|
|
148
|
+
_arguments \\
|
|
149
|
+
'--risk-level[Risk level]:level:(minimal moderate aggressive)' \\
|
|
150
|
+
'--skip-openclaw[Skip OpenClaw installation]' \\
|
|
151
|
+
'--skip-claude-code[Skip Claude Code installation]' \\
|
|
152
|
+
'--claude-code[Force Claude Code installation]' \\
|
|
153
|
+
'--skip-gitleaks[Skip Gitleaks download]'
|
|
154
|
+
;;
|
|
155
|
+
audit)
|
|
156
|
+
_arguments \\
|
|
157
|
+
'--last[Show last N entries]:count:' \\
|
|
158
|
+
'--event[Filter by event type]:type:' \\
|
|
159
|
+
'--agent[Filter by agent type]:agent:(openclaw claude-code)' \\
|
|
160
|
+
'--since[Show entries since date]:date:'
|
|
161
|
+
;;
|
|
162
|
+
config)
|
|
163
|
+
_arguments -C '1:subcommand:->cfgcmd'
|
|
164
|
+
case "\$state" in
|
|
165
|
+
cfgcmd)
|
|
166
|
+
_describe 'config command' config_commands
|
|
167
|
+
;;
|
|
168
|
+
esac
|
|
169
|
+
;;
|
|
170
|
+
exec)
|
|
171
|
+
_arguments \\
|
|
172
|
+
'--skip-scan[Skip pre-execution scanning]' \\
|
|
173
|
+
'--force[Skip approval prompts]' \\
|
|
174
|
+
'1:command:'
|
|
175
|
+
;;
|
|
176
|
+
audit-skill)
|
|
177
|
+
_arguments \\
|
|
178
|
+
'--skip-openclaw[Skip OpenClaw integration]' \\
|
|
179
|
+
'--json[Output as JSON]' \\
|
|
180
|
+
'1:skill-path:_files'
|
|
181
|
+
;;
|
|
182
|
+
install-hook)
|
|
183
|
+
_arguments \\
|
|
184
|
+
'--global[Install globally]'
|
|
185
|
+
;;
|
|
186
|
+
esac
|
|
187
|
+
;;
|
|
188
|
+
esac
|
|
189
|
+
;;
|
|
190
|
+
run|scan)
|
|
191
|
+
_arguments \\
|
|
192
|
+
'(-r --repo)'{-r,--repo}'[Repository]:repo:' \\
|
|
193
|
+
'(-b --branch)'{-b,--branch}'[Branch]:branch:' \\
|
|
194
|
+
'(-k --api-key)'{-k,--api-key}'[API key]:key:' \\
|
|
195
|
+
'(-f --format)'{-f,--format}'[Output format]:format:(json md)' \\
|
|
196
|
+
'--skip-interactive[Do not wait for scan]' \\
|
|
197
|
+
'--quiet[Suppress status messages]'
|
|
198
|
+
;;
|
|
199
|
+
get)
|
|
200
|
+
_arguments \\
|
|
201
|
+
'(-k --api-key)'{-k,--api-key}'[API key]:key:' \\
|
|
202
|
+
'(-f --format)'{-f,--format}'[Output format]:format:(json md)' \\
|
|
203
|
+
'--interactive[Poll until done]' \\
|
|
204
|
+
'--quiet[Suppress status messages]' \\
|
|
205
|
+
'1:scan_id:'
|
|
206
|
+
;;
|
|
207
|
+
usage)
|
|
208
|
+
_arguments \\
|
|
209
|
+
'(-k --api-key)'{-k,--api-key}'[API key]:key:'
|
|
210
|
+
;;
|
|
211
|
+
ci)
|
|
212
|
+
_arguments -C '1:subcommand:(init)'
|
|
98
213
|
;;
|
|
99
214
|
hook)
|
|
100
|
-
|
|
215
|
+
_arguments -C '1:subcommand:(pretool)'
|
|
216
|
+
;;
|
|
217
|
+
mcp)
|
|
218
|
+
_arguments -C '1:subcommand:(serve)'
|
|
219
|
+
;;
|
|
220
|
+
policy)
|
|
221
|
+
_arguments -C \\
|
|
222
|
+
'1:subcommand:(export)' \\
|
|
223
|
+
'*::arg:->policyargs'
|
|
224
|
+
case "\$state" in
|
|
225
|
+
policyargs)
|
|
226
|
+
_arguments \\
|
|
227
|
+
'--format[Target format]:format:(claude codex)' \\
|
|
228
|
+
'--output[Output file]:path:_files'
|
|
229
|
+
;;
|
|
230
|
+
esac
|
|
101
231
|
;;
|
|
102
232
|
completion)
|
|
103
|
-
|
|
233
|
+
_arguments '1:shell:(bash zsh fish)'
|
|
104
234
|
;;
|
|
105
235
|
esac
|
|
106
236
|
;;
|
|
@@ -109,61 +239,129 @@ _rafter() {
|
|
|
109
239
|
|
|
110
240
|
_rafter
|
|
111
241
|
`;
|
|
112
|
-
const FISH_COMPLETION =
|
|
113
|
-
# rafter fish completion
|
|
114
|
-
# Save to ~/.config/fish/completions/rafter.fish
|
|
115
|
-
# Or: rafter completion fish > ~/.config/fish/completions/rafter.fish
|
|
242
|
+
const FISH_COMPLETION = `# rafter fish completion
|
|
116
243
|
|
|
244
|
+
# Disable file completions by default
|
|
117
245
|
complete -c rafter -f
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
complete -c rafter -
|
|
121
|
-
complete -c rafter -
|
|
122
|
-
complete -c rafter -
|
|
123
|
-
|
|
246
|
+
|
|
247
|
+
# Global options
|
|
248
|
+
complete -c rafter -s a -l agent -d 'Plain output for AI agents'
|
|
249
|
+
complete -c rafter -s V -l version -d 'Show version'
|
|
250
|
+
complete -c rafter -s h -l help -d 'Show help'
|
|
251
|
+
|
|
252
|
+
# Top-level commands
|
|
253
|
+
complete -c rafter -n '__fish_use_subcommand' -a run -d 'Submit a security scan'
|
|
254
|
+
complete -c rafter -n '__fish_use_subcommand' -a scan -d 'Alias for run'
|
|
255
|
+
complete -c rafter -n '__fish_use_subcommand' -a get -d 'Retrieve scan results'
|
|
256
|
+
complete -c rafter -n '__fish_use_subcommand' -a usage -d 'Check API usage quota'
|
|
257
|
+
complete -c rafter -n '__fish_use_subcommand' -a agent -d 'Agent security commands'
|
|
258
|
+
complete -c rafter -n '__fish_use_subcommand' -a ci -d 'CI/CD pipeline setup'
|
|
259
|
+
complete -c rafter -n '__fish_use_subcommand' -a hook -d 'Git hook handlers'
|
|
260
|
+
complete -c rafter -n '__fish_use_subcommand' -a mcp -d 'MCP server'
|
|
261
|
+
complete -c rafter -n '__fish_use_subcommand' -a policy -d 'Policy management'
|
|
262
|
+
complete -c rafter -n '__fish_use_subcommand' -a completion -d 'Generate shell completions'
|
|
263
|
+
|
|
264
|
+
# run / scan options
|
|
265
|
+
complete -c rafter -n '__fish_seen_subcommand_from run scan' -s r -l repo -d 'Repository (org/repo)' -r
|
|
266
|
+
complete -c rafter -n '__fish_seen_subcommand_from run scan' -s b -l branch -d 'Branch' -r
|
|
267
|
+
complete -c rafter -n '__fish_seen_subcommand_from run scan' -s k -l api-key -d 'API key' -r
|
|
268
|
+
complete -c rafter -n '__fish_seen_subcommand_from run scan' -s f -l format -d 'Output format' -ra 'json md'
|
|
269
|
+
complete -c rafter -n '__fish_seen_subcommand_from run scan' -l skip-interactive -d 'Do not wait for scan'
|
|
270
|
+
complete -c rafter -n '__fish_seen_subcommand_from run scan' -l quiet -d 'Suppress status messages'
|
|
271
|
+
|
|
272
|
+
# get options
|
|
273
|
+
complete -c rafter -n '__fish_seen_subcommand_from get' -s k -l api-key -d 'API key' -r
|
|
274
|
+
complete -c rafter -n '__fish_seen_subcommand_from get' -s f -l format -d 'Output format' -ra 'json md'
|
|
275
|
+
complete -c rafter -n '__fish_seen_subcommand_from get' -l interactive -d 'Poll until done'
|
|
276
|
+
complete -c rafter -n '__fish_seen_subcommand_from get' -l quiet -d 'Suppress status messages'
|
|
277
|
+
|
|
278
|
+
# usage options
|
|
279
|
+
complete -c rafter -n '__fish_seen_subcommand_from usage' -s k -l api-key -d 'API key' -r
|
|
124
280
|
|
|
125
281
|
# agent subcommands
|
|
126
|
-
complete -c rafter -n '__fish_seen_subcommand_from agent
|
|
127
|
-
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from scan
|
|
128
|
-
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from scan' -
|
|
129
|
-
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from scan
|
|
130
|
-
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from scan' -
|
|
131
|
-
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from scan' -
|
|
282
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and not __fish_seen_subcommand_from scan init audit config exec audit-skill install-hook verify status update-gitleaks baseline' -a scan -d 'Scan files for secrets'
|
|
283
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and not __fish_seen_subcommand_from scan init audit config exec audit-skill install-hook verify status update-gitleaks baseline' -a init -d 'Initialize agent security'
|
|
284
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and not __fish_seen_subcommand_from scan init audit config exec audit-skill install-hook verify status update-gitleaks baseline' -a audit -d 'View audit log'
|
|
285
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and not __fish_seen_subcommand_from scan init audit config exec audit-skill install-hook verify status update-gitleaks baseline' -a config -d 'Manage configuration'
|
|
286
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and not __fish_seen_subcommand_from scan init audit config exec audit-skill install-hook verify status update-gitleaks baseline' -a exec -d 'Execute with security'
|
|
287
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and not __fish_seen_subcommand_from scan init audit config exec audit-skill install-hook verify status update-gitleaks baseline' -a audit-skill -d 'Audit a skill file'
|
|
288
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and not __fish_seen_subcommand_from scan init audit config exec audit-skill install-hook verify status update-gitleaks baseline' -a install-hook -d 'Install pre-commit hook'
|
|
289
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and not __fish_seen_subcommand_from scan init audit config exec audit-skill install-hook verify status update-gitleaks baseline' -a verify -d 'Check integration status'
|
|
290
|
+
|
|
291
|
+
# agent scan options
|
|
292
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from scan' -s q -l quiet -d 'Only output if secrets found'
|
|
293
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from scan' -l json -d 'Output as JSON'
|
|
294
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from scan' -l staged -d 'Scan only staged files'
|
|
295
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from scan' -l diff -d 'Scan changed since ref' -r
|
|
296
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from scan' -l engine -d 'Scanner engine' -ra 'gitleaks patterns'
|
|
297
|
+
|
|
298
|
+
# agent init options
|
|
299
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from init' -l risk-level -d 'Risk level' -ra 'minimal moderate aggressive'
|
|
300
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from init' -l skip-openclaw -d 'Skip OpenClaw'
|
|
301
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from init' -l skip-claude-code -d 'Skip Claude Code'
|
|
302
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from init' -l claude-code -d 'Force Claude Code'
|
|
303
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from init' -l skip-gitleaks -d 'Skip Gitleaks'
|
|
304
|
+
|
|
305
|
+
# agent audit options
|
|
306
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from audit' -l last -d 'Show last N entries' -r
|
|
307
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from audit' -l event -d 'Filter by event type' -r
|
|
308
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from audit' -l agent -d 'Filter by agent type' -ra 'openclaw claude-code'
|
|
309
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from audit' -l since -d 'Since date' -r
|
|
310
|
+
|
|
311
|
+
# agent config subcommands
|
|
312
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from config' -a show -d 'Show configuration'
|
|
313
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from config' -a get -d 'Get a config value'
|
|
314
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from config' -a set -d 'Set a config value'
|
|
315
|
+
|
|
316
|
+
# agent exec options
|
|
317
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from exec' -l skip-scan -d 'Skip pre-execution scanning'
|
|
318
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from exec' -l force -d 'Skip approval prompts'
|
|
319
|
+
|
|
320
|
+
# agent audit-skill options
|
|
321
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from audit-skill' -l skip-openclaw -d 'Skip OpenClaw integration'
|
|
322
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from audit-skill' -l json -d 'Output as JSON'
|
|
323
|
+
|
|
324
|
+
# agent install-hook options
|
|
325
|
+
complete -c rafter -n '__fish_seen_subcommand_from agent; and __fish_seen_subcommand_from install-hook' -l global -d 'Install globally'
|
|
326
|
+
|
|
327
|
+
# ci subcommands
|
|
328
|
+
complete -c rafter -n '__fish_seen_subcommand_from ci' -a init -d 'Initialize CI pipeline'
|
|
329
|
+
complete -c rafter -n '__fish_seen_subcommand_from ci; and __fish_seen_subcommand_from init' -l platform -d 'CI platform' -ra 'github gitlab circleci'
|
|
330
|
+
complete -c rafter -n '__fish_seen_subcommand_from ci; and __fish_seen_subcommand_from init' -l output -d 'Output path' -r
|
|
331
|
+
complete -c rafter -n '__fish_seen_subcommand_from ci; and __fish_seen_subcommand_from init' -l with-backend -d 'Include backend audit'
|
|
132
332
|
|
|
133
333
|
# hook subcommands
|
|
134
|
-
complete -c rafter -n '__fish_seen_subcommand_from hook' -a
|
|
334
|
+
complete -c rafter -n '__fish_seen_subcommand_from hook' -a pretool -d 'PreToolUse hook handler'
|
|
335
|
+
|
|
336
|
+
# mcp subcommands
|
|
337
|
+
complete -c rafter -n '__fish_seen_subcommand_from mcp' -a serve -d 'Start MCP server'
|
|
338
|
+
complete -c rafter -n '__fish_seen_subcommand_from mcp; and __fish_seen_subcommand_from serve' -l transport -d 'Transport type' -r
|
|
339
|
+
|
|
340
|
+
# policy subcommands
|
|
341
|
+
complete -c rafter -n '__fish_seen_subcommand_from policy' -a export -d 'Export policy'
|
|
342
|
+
complete -c rafter -n '__fish_seen_subcommand_from policy; and __fish_seen_subcommand_from export' -l format -d 'Target format' -ra 'claude codex'
|
|
343
|
+
complete -c rafter -n '__fish_seen_subcommand_from policy; and __fish_seen_subcommand_from export' -l output -d 'Output file' -r
|
|
135
344
|
|
|
136
|
-
# completion
|
|
137
|
-
complete -c rafter -n '__fish_seen_subcommand_from completion' -a 'bash zsh fish'
|
|
345
|
+
# completion subcommand
|
|
346
|
+
complete -c rafter -n '__fish_seen_subcommand_from completion' -a 'bash zsh fish' -d 'Shell type'
|
|
138
347
|
`;
|
|
139
348
|
export function createCompletionCommand() {
|
|
140
349
|
return new Command("completion")
|
|
141
350
|
.description("Generate shell completion scripts")
|
|
142
351
|
.argument("<shell>", "Shell type: bash, zsh, or fish")
|
|
143
|
-
.addHelpText("after", `
|
|
144
|
-
Examples:
|
|
145
|
-
# bash — add to ~/.bashrc
|
|
146
|
-
eval "$(rafter completion bash)"
|
|
147
|
-
|
|
148
|
-
# zsh — add to ~/.zshrc
|
|
149
|
-
eval "$(rafter completion zsh)"
|
|
150
|
-
|
|
151
|
-
# fish — save to completions dir
|
|
152
|
-
rafter completion fish > ~/.config/fish/completions/rafter.fish
|
|
153
|
-
`)
|
|
154
352
|
.action((shell) => {
|
|
155
|
-
switch (shell
|
|
353
|
+
switch (shell) {
|
|
156
354
|
case "bash":
|
|
157
|
-
process.stdout.write(BASH_COMPLETION
|
|
355
|
+
process.stdout.write(BASH_COMPLETION);
|
|
158
356
|
break;
|
|
159
357
|
case "zsh":
|
|
160
|
-
process.stdout.write(ZSH_COMPLETION
|
|
358
|
+
process.stdout.write(ZSH_COMPLETION);
|
|
161
359
|
break;
|
|
162
360
|
case "fish":
|
|
163
|
-
process.stdout.write(FISH_COMPLETION
|
|
361
|
+
process.stdout.write(FISH_COMPLETION);
|
|
164
362
|
break;
|
|
165
363
|
default:
|
|
166
|
-
|
|
364
|
+
process.stderr.write(`Unknown shell: ${shell}. Supported: bash, zsh, fish\n`);
|
|
167
365
|
process.exit(1);
|
|
168
366
|
}
|
|
169
367
|
});
|
|
@@ -3,6 +3,12 @@ import path from "path";
|
|
|
3
3
|
import { getAuditLogPath } from "./config-defaults.js";
|
|
4
4
|
import { ConfigManager } from "./config-manager.js";
|
|
5
5
|
import { assessCommandRisk } from "./risk-rules.js";
|
|
6
|
+
export const RISK_SEVERITY = {
|
|
7
|
+
low: 0,
|
|
8
|
+
medium: 1,
|
|
9
|
+
high: 2,
|
|
10
|
+
critical: 3,
|
|
11
|
+
};
|
|
6
12
|
export class AuditLogger {
|
|
7
13
|
constructor(logPath) {
|
|
8
14
|
this.logPath = logPath || getAuditLogPath();
|
|
@@ -31,6 +37,41 @@ export class AuditLogger {
|
|
|
31
37
|
// Append to log file
|
|
32
38
|
const line = JSON.stringify(fullEntry) + "\n";
|
|
33
39
|
fs.appendFileSync(this.logPath, line, "utf-8");
|
|
40
|
+
// Send webhook notification if configured and risk meets threshold
|
|
41
|
+
this.sendNotification(fullEntry, config);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Send webhook notification for high-risk events
|
|
45
|
+
*/
|
|
46
|
+
sendNotification(entry, config) {
|
|
47
|
+
const webhookUrl = config.agent?.notifications?.webhook;
|
|
48
|
+
if (!webhookUrl)
|
|
49
|
+
return;
|
|
50
|
+
const eventRisk = entry.action?.riskLevel || "low";
|
|
51
|
+
const minRisk = config.agent?.notifications?.minRiskLevel || "high";
|
|
52
|
+
if ((RISK_SEVERITY[eventRisk] ?? 0) < (RISK_SEVERITY[minRisk] ?? 2)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const payload = {
|
|
56
|
+
event: entry.eventType,
|
|
57
|
+
risk: eventRisk,
|
|
58
|
+
command: entry.action?.command || null,
|
|
59
|
+
timestamp: entry.timestamp,
|
|
60
|
+
agent: entry.agentType || null,
|
|
61
|
+
// Slack-compatible text field
|
|
62
|
+
text: `[rafter] ${eventRisk}-risk event: ${entry.eventType}${entry.action?.command ? ` — ${entry.action.command}` : ""}`,
|
|
63
|
+
// Discord-compatible content field
|
|
64
|
+
content: `[rafter] ${eventRisk}-risk event: ${entry.eventType}${entry.action?.command ? ` — ${entry.action.command}` : ""}`,
|
|
65
|
+
};
|
|
66
|
+
// Fire-and-forget POST — never block audit logging
|
|
67
|
+
fetch(webhookUrl, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
headers: { "Content-Type": "application/json" },
|
|
70
|
+
body: JSON.stringify(payload),
|
|
71
|
+
signal: AbortSignal.timeout(5000),
|
|
72
|
+
}).catch(() => {
|
|
73
|
+
// Silently ignore webhook failures
|
|
74
|
+
});
|
|
34
75
|
}
|
|
35
76
|
/**
|
|
36
77
|
* Log a command interception
|
package/dist/core/risk-rules.js
CHANGED
|
@@ -17,9 +17,10 @@ export const HIGH_PATTERNS = [
|
|
|
17
17
|
/chmod\s+777/,
|
|
18
18
|
/curl.*\|\s*(bash|sh|zsh|dash)\b/,
|
|
19
19
|
/wget.*\|\s*(bash|sh|zsh|dash)\b/,
|
|
20
|
-
/git\s+push\s
|
|
21
|
-
/git\s+push\s
|
|
22
|
-
/git\s+push\s
|
|
20
|
+
/git\s+push\b.*\s--force\b/, // --force anywhere after push
|
|
21
|
+
/git\s+push\b.*\s-[a-zA-Z]*f\b/, // -f or combined flags like -vf
|
|
22
|
+
/git\s+push\b.*\s--force-(with-lease|if-includes)\b/, // specific force variants
|
|
23
|
+
/git\s+push\s+\S*\s+\+/, // refspec force: git push origin +main
|
|
23
24
|
/docker\s+system\s+prune/,
|
|
24
25
|
/npm\s+publish/,
|
|
25
26
|
/pypi.*upload/,
|
|
@@ -50,6 +51,7 @@ export const DEFAULT_REQUIRE_APPROVAL = [
|
|
|
50
51
|
"git push -f",
|
|
51
52
|
"git push --force-with-lease",
|
|
52
53
|
"git push --force-if-includes",
|
|
54
|
+
"git push .* \\+",
|
|
53
55
|
];
|
|
54
56
|
/**
|
|
55
57
|
* Assess risk level of a command string.
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { createCompletionCommand } from "./commands/completion.js";
|
|
|
13
13
|
import { checkForUpdate } from "./utils/update-checker.js";
|
|
14
14
|
import { setAgentMode } from "./utils/formatter.js";
|
|
15
15
|
dotenv.config();
|
|
16
|
-
const VERSION = "0.5.
|
|
16
|
+
const VERSION = "0.5.5";
|
|
17
17
|
const program = new Command()
|
|
18
18
|
.name("rafter")
|
|
19
19
|
.description("Rafter CLI")
|