ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / aura-harness / harness / tools / policy.mjs 244 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import fs from 'node:fs' ;
import path from 'node:path' ;
import { spawnSync } from 'node:child_process' ;
import { parseArgs, readJson, writeJsonAtomic, resolveConfig, wildcardToRegExp, walkFiles, stateDir, appendEvent, fail } from './lib.mjs' ;
const RANK = { allow : 0 , ask : 1 , deny : 2 } ;
export const SECRET_RULES = [
file cwd
file
file file
cleaned text
cleaned
nested
re
m command re nested m
m command nested m m
nested
parts command command
parts
part
s
patterns p text
rules policy
rules command
command
checks command command
decision
anyAllowed
text checks
deny rules text
ask rules text
allow rules text
current
deny current deny text
ask current ask text
allow
anyAllowed
text command
current rules text
current decision decision current
anyAllowed decision decision rules command
decision
findings
lines text
lines
rule
match line rule
match
rule rule match
value match match
findings index rule
findings
results
file files
stat
stat fs file
stat stat
buf fs file
buf
f buf results file f
results
args staged
res args cwd
res
res path cwd f
rules policy
bash rules
p rules bash p
p rules bash p
p rules bash p
bash
cwd process
commands
command
policy cwd
result command policy
result
process result result
files
paths files paths fs p p path p
files cwd flags cwd
findings files
f findings
findings
process findings
_ flags
flags flags
flags flags fs flags
head cwd
record flags flags flags head
path cwd record
cwd flags head
policy cwd
rules policy
checks
checks name ok detail
status cwd
head cwd
rules status status status
rules
gates path cwd
ageMin gates gates
gates verdict ageMin rules gates
secrets cwd cwd
secrets
rules rules
approval path cwd
rules approval approval approval head approval
rules approval rollback fs path cwd approval approval rollback
c checks
ok checks c
process ok
policy cwd
policy
isMain process
isMain
positional flags process
command commands positional
command
process positional
positional flags
{
id
:
'private-key'
,
re
:
/ -----BEGIN (?: RSA | EC | OPENSSH | DSA | PGP ) ? PRIVATE KEY----- /
}
,
{
id
:
'aws-access-key'
,
re
:
/ \b AKIA[ 0- 9 A- Z ] {16} \b /
}
,
{
id
:
'github-token'
,
re
:
/ \b (?: ghp| gho| ghu| ghs| ghr) _[ A- Z a- z 0- 9 ] {36,} \b | \b github_pat_[ A- Z a- z 0- 9 _] {60,} \b /
}
,
{
id
:
'openai-key'
,
re
:
/ \b sk-(?: proj-) ? [ A- Z a- z 0- 9 _-] {32,} \b /
}
,
{
id
:
'anthropic-key'
,
re
:
/ \b sk-ant-[ A- Z a- z 0- 9 _-] {32,} \b /
}
,
{
id
:
'tavily-key'
,
re
:
/ \b tvly-[ A- Z a- z 0- 9 _-] {20,} \b /
}
,
{
id
:
'google-api-key'
,
re
:
/ \b AIza[ 0- 9 A- Z a- z _-] {35} \b /
}
,
{
id
:
'slack-token'
,
re
:
/ \b xox[ abprs] -[ A- Z a- z 0- 9 -] {10,} \b /
}
,
{
id
:
'jwt'
,
re
:
/ \b eyJ[ A- Z a- z 0- 9 _-] {10,} \. eyJ[ A- Z a- z 0- 9 _-] {10,} \. [ A- Z a- z 0- 9 _-] {10,} \b /
}
,
{
id
:
'generic-assignment'
,
re
:
/ (?: api[ _-] ? key| secret| token| password| passwd) [ "'] ? \s * [ :=] \s * [ "'] ( [ ^ "'\s ] {12,} ) [ "'] / i
,
placeholder
:
/ ВСТАВЬ| INSERT| YOUR_| your-| xxx| changeme| example| placeholder| \$ \{ | \{ env:| <[ ^ >] + > / i
,
}
,
]
;
export
function
loadPolicy
(
cwd = process. cwd ( )
)
{
const
=
resolveConfig
(
'.release-policy.json'
,
)
;
if
(
!
)
{
fail
(
'No .release-policy.json found'
)
;
}
return
{
,
policy
:
readJson
(
)
}
;
}
const
SECRET_FILE_RE
=
/ (?: ^ | [ \s /'"=<>:@] ) (?: \. env(?: \. [ \w -] + ) * | [ \w .-] * \. pem| [ \w .-] * \. key| id_rsa[ \w .-] * | id_ed25519[ \w .-] * | id_ecdsa[ \w .-] * | \. npmrc| \. netrc| \. pgpass| credentials(?: \. json) ? | auth\. json) (?= $ | [ \s '"|;&)<>] ) /
;
const
SECRET_FILE_ALLOW_RE
=
/ \. env\. (?: example| sample| template| dist| defaults) \b | auth\. json\. example\b /
;
export
function
touchesSecretFile
(
text
)
{
const
=
.
replace
(
new
RegExp
(
SECRET_FILE_ALLOW_RE
.
source
,
'g'
)
,
' '
)
;
return
SECRET_FILE_RE
.
test
(
)
;
}
function
unwrapShell
(
command
)
{
const
=
[
]
;
const
=
/ \b (?: bash| sh| zsh| dash) \s + (?: -\w + \s + ) * -c\s + ( [ '"] ) ( [ \s \S ] *? ) \1 / g
;
for
(
const
of
.
matchAll
(
)
)
{
.
push
(
[
2
]
)
;
}
for
(
const
of
.
matchAll
(
/ \$ \( ( [ ^ ()] * ) \) | `( [ ^ `] * ) `/ g
)
)
{
.
push
(
[
1
]
??
[
2
]
)
;
}
return
;
}
function
splitSegments
(
command
)
{
const
=
[
,
...
unwrapShell
(
)
]
;
return
.
flatMap
(
(
part
)
=>
.
split
(
/ \s * (?: &&| \| \| | ;| \| | \n ) \s * /
)
)
.
map
(
(
s
)
=>
.
trim
(
)
.
replace
(
/ ^ (?: sudo\s + (?: -\S + \s + ) * | env\s + (?: \S + =\S + \s + ) * | command\s + | exec\s + | nohup\s + | time\s + ) /
,
''
)
)
.
filter
(
Boolean
)
;
}
function
matchList
(
patterns, text
)
{
return
(
??
[
]
)
.
find
(
(
p
)
=>
wildcardToRegExp
(
)
.
test
(
)
)
??
null
;
}
export
function
classify
(
command, policy
)
{
const
=
.
commands
??
{
}
;
if
(
.
denySecretFiles
!==
false
&&
touchesSecretFile
(
)
)
{
return
{
decision
:
'deny'
,
rule
:
'(secret-file)'
,
segment
:
.
trim
(
)
}
;
}
const
=
[
.
trim
(
)
,
...
splitSegments
(
)
]
;
let
=
{
decision
:
'allow'
,
rule
:
null
,
segment
:
null
}
;
let
=
false
;
for
(
const
of
)
{
const
=
matchList
(
.
deny
,
)
;
const
=
matchList
(
.
ask
,
)
;
const
=
matchList
(
.
allow
,
)
;
let
;
if
(
)
{
=
{
decision
:
'deny'
,
rule
:
,
segment
:
}
;
}
else
if
(
)
{
=
{
decision
:
'ask'
,
rule
:
,
segment
:
}
;
}
else
if
(
)
{
=
true
;
continue
;
}
else
if
(
===
.
trim
(
)
)
{
continue
;
}
else
{
=
{
decision
:
.
default
??
'ask'
,
rule
:
'(default)'
,
segment
:
}
;
}
if
(
RANK
[
.
decision
]
>
RANK
[
.
decision
]
)
{
=
;
}
}
if
(
!
&&
.
decision
===
'allow'
)
{
=
{
decision
:
.
default
??
'ask'
,
rule
:
'(default)'
,
segment
:
.
trim
(
)
}
;
}
return
;
}
function
scanText
(
text
)
{
const
=
[
]
;
const
=
.
split
(
'\n'
)
;
.
forEach
(
(
line, index
)
=>
{
for
(
const
of
SECRET_RULES
)
{
const
=
.
match
(
.
re
)
;
if
(
!
)
{
continue
;
}
if
(
.
placeholder
&&
.
placeholder
.
test
(
[
0
]
)
)
{
continue
;
}
const
=
[
1
]
??
[
0
]
;
.
push
(
{
line
:
+
1
,
rule
:
.
id
,
preview
:
` ${ value. slice ( 0 , 4 ) } … ${ '*' . repeat ( 6 ) } `
}
)
;
}
}
)
;
return
;
}
export
function
scanFiles
(
files
)
{
const
=
[
]
;
for
(
const
of
)
{
let
;
try
{
=
.
statSync
(
)
;
}
catch
{
continue
;
}
if
(
!
.
isFile
(
)
||
.
size
>
1_000_000
)
{
continue
;
}
const
=
.
readFileSync
(
)
;
if
(
.
includes
(
0
)
)
{
continue
;
}
for
(
const
of
scanText
(
.
toString
(
'utf8'
)
)
)
{
.
push
(
{
,
...
}
)
;
}
}
return
;
}
function
gitFiles
(
cwd, staged
)
{
const
=
?
[
'diff'
,
'--cached'
,
'--name-only'
,
'--diff-filter=ACM'
]
:
[
'ls-files'
,
'--cached'
,
'--others'
,
'--exclude-standard'
]
;
const
=
spawnSync
(
'git'
,
,
{
,
encoding
:
'utf8'
}
)
;
if
(
.
status
!==
0
)
{
return
null
;
}
return
.
stdout
.
split
(
'\n'
)
.
filter
(
Boolean
)
.
map
(
(
f
)
=>
.
join
(
,
)
)
;
}
function
opencodePermission
(
policy
)
{
const
=
.
commands
??
{
}
;
const
=
{
'*'
:
.
default
??
'ask'
}
;
for
(
const
of
.
allow
??
[
]
)
{
[
]
=
'allow'
;
}
for
(
const
of
.
ask
??
[
]
)
{
[
]
=
'ask'
;
}
for
(
const
of
.
deny
??
[
]
)
{
[
]
=
'deny'
;
}
return
{
permission
:
{
,
edit
:
'allow'
,
read
:
{
'*'
:
'allow'
,
'*.env'
:
'deny'
,
'*.env.*'
:
'deny'
,
'*.env.example'
:
'allow'
,
'*.env.sample'
:
'allow'
,
'*.env.template'
:
'allow'
,
'*.pem'
:
'deny'
,
'*.key'
:
'deny'
,
'*id_rsa*'
:
'deny'
,
'*id_ed25519*'
:
'deny'
,
'*id_ecdsa*'
:
'deny'
,
'*.npmrc'
:
'deny'
,
'*.netrc'
:
'deny'
,
'*.pgpass'
:
'deny'
,
}
,
external_directory
:
'ask'
,
doom_loop
:
'ask'
,
}
,
}
;
}
const
=
.
cwd
(
)
;
const
=
{
check
(
[ command]
)
{
if
(
!
)
{
fail
(
'Usage: policy.mjs check "<command>"'
)
;
}
const
{
}
=
loadPolicy
(
)
;
const
=
classify
(
,
)
;
console
.
log
(
JSON
.
stringify
(
)
)
;
.
exit
(
.
decision
===
'allow'
?
0
:
.
decision
===
'ask'
?
2
:
3
)
;
}
,
scan
(
paths, flags
)
{
let
;
if
(
.
length
)
{
=
.
flatMap
(
(
p
)
=>
(
.
statSync
(
)
.
isDirectory
(
)
?
walkFiles
(
)
:
[
.
resolve
(
)
]
)
)
;
}
else
{
=
gitFiles
(
,
Boolean
(
.
staged
)
)
??
walkFiles
(
)
;
}
const
=
scanFiles
(
)
;
for
(
const
of
)
{
console
.
log
(
` ${ path. relative ( cwd, f. file ) } : ${ f. line } ${ f. rule } ${ f. preview } `
)
;
}
console
.
log
(
.
length
?
` \n ${ findings. length } potential secret(s). Remove them and rotate the keys. `
:
` No secrets found in ${ files. length } file(s). `
)
;
.
exit
(
.
length
?
1
:
0
)
;
}
,
'approve-release'
(
,
)
{
if
(
!
.
by
||
.
by
===
true
)
{
fail
(
'--by <human> is required'
)
;
}
if
(
!
.
rollback
||
.
rollback
===
true
||
!
.
existsSync
(
.
rollback
)
)
{
fail
(
'--rollback <file> must point to an existing rollback plan'
)
;
}
const
=
spawnSync
(
'git'
,
[
'rev-parse'
,
'HEAD'
]
,
{
,
encoding
:
'utf8'
}
)
.
stdout
.
trim
(
)
||
null
;
const
=
{
by
:
.
by
,
rollback
:
.
rollback
,
target
:
.
target
??
null
,
,
at
:
new
Date
(
)
.
toISOString
(
)
}
;
writeJsonAtomic
(
.
join
(
stateDir
(
)
,
'approvals'
,
'release.json'
)
,
)
;
appendEvent
(
,
{
type
:
'release.approved'
,
by
:
.
by
,
}
)
;
console
.
log
(
` Release approved by ${ flags. by } for ${ head ?? 'non-git workspace' } `
)
;
}
,
release
(
)
{
const
{
}
=
loadPolicy
(
)
;
const
=
.
release
??
{
}
;
const
=
[
]
;
const
add
=
(
name, ok, detail
)
=>
.
push
(
{
,
,
}
)
;
const
=
spawnSync
(
'git'
,
[
'status'
,
'--porcelain'
]
,
{
,
encoding
:
'utf8'
}
)
;
const
=
spawnSync
(
'git'
,
[
'rev-parse'
,
'HEAD'
]
,
{
,
encoding
:
'utf8'
}
)
.
stdout
.
trim
(
)
;
if
(
.
requireCleanTree
)
{
add
(
'clean-tree'
,
.
status
===
0
&&
!
.
stdout
.
trim
(
)
,
.
status
===
0
?
` ${ status. stdout . split ( '\n' ) . filter ( Boolean ) . length } changed file(s) `
:
'not a git repo'
)
;
}
if
(
.
requireGatesPassed
)
{
const
=
readJson
(
.
join
(
stateDir
(
)
,
'artifacts'
,
'gates-latest.json'
)
,
null
)
;
const
=
?
(
Date
.
now
(
)
-
Date
.
parse
(
.
finishedAt
)
)
/
60000
:
Infinity
;
add
(
'gates-passed'
,
?.
===
'passed'
&&
<=
(
.
gatesMaxAgeMinutes
??
60
)
,
?
` ${ gates. verdict } , ${ Math . round ( ageMin) } min ago `
:
'no gates run'
)
;
}
const
=
scanFiles
(
gitFiles
(
,
false
)
??
walkFiles
(
)
)
;
add
(
'no-secrets'
,
.
length
===
0
,
` ${ secrets. length } finding(s) `
)
;
if
(
.
requireApproval
||
.
requireRollbackPlan
)
{
const
=
readJson
(
.
join
(
stateDir
(
)
,
'approvals'
,
'release.json'
)
,
null
)
;
if
(
.
requireApproval
)
{
add
(
'approval'
,
Boolean
(
)
&&
(
!
.
head
||
.
head
===
)
,
?
` by ${ approval. by } for ${ approval. head ?. slice ( 0 , 10 ) } `
:
'missing'
)
;
}
if
(
.
requireRollbackPlan
)
{
add
(
'rollback-plan'
,
Boolean
(
?.
&&
.
existsSync
(
.
resolve
(
,
.
rollback
)
)
)
,
?.
??
'missing'
)
;
}
}
for
(
const
of
)
{
console
.
log
(
` ${ c. ok ? 'PASS' : 'FAIL' } ${ c. name . padEnd ( 14 ) } ${ c. detail } `
)
;
}
const
=
.
every
(
(
c
)
=>
.
ok
)
;
console
.
log
(
` \nRelease gate: ${ ok ? 'OPEN' : 'BLOCKED' } `
)
;
.
exit
(
?
0
:
1
)
;
}
,
'opencode-permission'
(
)
{
const
{
}
=
loadPolicy
(
)
;
console
.
log
(
JSON
.
stringify
(
opencodePermission
(
)
,
null
,
2
)
)
;
}
,
}
;
const
HELP
=
` Usage: node policy.mjs <command>
check "<shell command>" exit 0 allow, 2 ask (needs human approval), 3 deny
scan [paths...] [--staged] secret scan of git files (or given paths); exit 1 on findings
approve-release --by <human> --rollback <file> [--target prod]
release verify clean tree, fresh passing gates, no secrets, approval, rollback
opencode-permission print an OpenCode "permission" block generated from the policy
Policy file: ./.release-policy.json, else ~/.agent-harness/.release-policy.json `
;
const
=
.
argv
[
1
]
?.
endsWith
(
'policy.mjs'
)
;
if
(
)
{
const
{
,
}
=
parseArgs
(
.
argv
.
slice
(
2
)
)
;
const
=
[
[
0
]
]
;
if
(
!
)
{
console
.
log
(
HELP
)
;
.
exit
(
[
0
]
?
1
:
0
)
;
}
command
(
.
slice
(
1
)
,
)
;
}