Skip to content

Commit bb1efbd

Browse files
committed
chore(scripts): add cross-platform security runner and ignore /reports
- Add scripts/security.mts as a cross-platform replacement for the inline shell \`security\` script; runs agentshield then zizmor if available, with consistent logger output. - Ignore /reports output directory in git and in the markdown-filename validator so generated scan reports don't trip validation.
1 parent 3cbf226 commit bb1efbd

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Thumbs.db
2222
/.tap
2323
/.type-coverage
2424
/coverage
25+
/reports
2526
*.log
2627
*.pid
2728
*.seed

scripts/security.mts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @fileoverview Security scan runner. Runs agentshield on Claude config then
3+
* optionally runs zizmor against .github/. Cross-platform replacement for the
4+
* previous inline shell script.
5+
*/
6+
7+
import process from 'node:process'
8+
9+
import { getDefaultLogger } from '@socketsecurity/lib/logger'
10+
import type { Logger } from '@socketsecurity/lib/logger'
11+
import { spawnSync } from '@socketsecurity/lib/spawn'
12+
13+
import { runCommand } from './utils/run-command.mts'
14+
15+
const logger: Logger = getDefaultLogger()
16+
17+
function hasCommand(command: string): boolean {
18+
const probe = process.platform === 'win32' ? 'where' : 'command'
19+
const args = process.platform === 'win32' ? [command] : ['-v', command]
20+
const result = spawnSync(probe, args, {
21+
stdio: 'ignore',
22+
shell: process.platform === 'win32',
23+
})
24+
return result.status === 0
25+
}
26+
27+
async function main(): Promise<void> {
28+
const agentshieldCode = await runCommand('agentshield', ['scan'])
29+
if (agentshieldCode !== 0) {
30+
process.exitCode = agentshieldCode
31+
return
32+
}
33+
34+
if (hasCommand('zizmor')) {
35+
const zizmorCode = await runCommand('zizmor', ['.github/'])
36+
if (zizmorCode !== 0) {
37+
process.exitCode = zizmorCode
38+
return
39+
}
40+
} else {
41+
logger.info('zizmor not installed — run pnpm run setup to install')
42+
}
43+
44+
process.exitCode = 0
45+
}
46+
47+
void main().catch((e: unknown) => {
48+
const message = e instanceof Error ? e.message : String(e)
49+
logger.error(`security scan failed: ${message}`)
50+
process.exitCode = 1
51+
})

scripts/validate/markdown-filenames.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const SKIP_DIRS = new Set([
6060
'.next',
6161
'.nuxt',
6262
'.output',
63+
'reports',
6364
])
6465

6566
type MarkdownFilenameViolation = {

0 commit comments

Comments
 (0)