Skip to content

Commit e366fc3

Browse files
committed
Add security agent auto-analysis queue system
Cloudflare Worker that automatically triages and analyzes security findings via a queue-based pipeline. Dispatches due owners on a cron schedule, claims queued findings per-owner with pessimistic locking, runs LLM triage to filter noise, then launches full analysis sessions via cloud-agent-next. Uses @kilocode/db with Drizzle ORM for all database access through Hyperdrive, matching the cloudflare-security-sync reference pattern. Includes DB migration for security_analysis_queue and security_analysis_owner_state tables, plus indexes on security_findings for in-flight analysis tracking.
1 parent 58ba953 commit e366fc3

47 files changed

Lines changed: 18582 additions & 1174 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
cloud_agent: ${{ steps.filter.outputs.cloud_agent }}
1818
cloud_agent_next: ${{ steps.filter.outputs.cloud_agent_next }}
1919
webhook_agent: ${{ steps.filter.outputs.webhook_agent }}
20+
security_auto_analysis: ${{ steps.filter.outputs.security_auto_analysis }}
2021
kiloclaw: ${{ steps.filter.outputs.kiloclaw }}
2122
app_builder: ${{ steps.filter.outputs.app_builder }}
2223
steps:
@@ -35,6 +36,8 @@ jobs:
3536
- 'cloud-agent-next/**'
3637
webhook_agent:
3738
- 'cloudflare-webhook-agent-ingest/**'
39+
security_auto_analysis:
40+
- 'cloudflare-security-auto-analysis/**'
3841
kiloclaw:
3942
- 'kiloclaw/**'
4043
app_builder:
@@ -265,6 +268,36 @@ jobs:
265268
- name: Run webhook-agent-ingest tests
266269
run: pnpm --filter cloudflare-webhook-agent-ingest test
267270

271+
security-auto-analysis:
272+
needs: changes
273+
if: needs.changes.outputs.security_auto_analysis == 'true'
274+
runs-on: ubuntu-latest
275+
steps:
276+
- uses: actions/checkout@v4
277+
with:
278+
lfs: true
279+
280+
- name: Setup pnpm
281+
uses: pnpm/action-setup@v2
282+
with:
283+
version: latest
284+
run_install: false
285+
286+
- name: Setup Node
287+
uses: actions/setup-node@v4
288+
with:
289+
node-version: 22
290+
cache: 'pnpm'
291+
292+
- name: Install dependencies
293+
run: pnpm install --frozen-lockfile
294+
295+
- name: Typecheck (security-auto-analysis)
296+
run: pnpm --filter cloudflare-security-auto-analysis typecheck
297+
298+
- name: Run security-auto-analysis tests
299+
run: pnpm --filter cloudflare-security-auto-analysis test
300+
268301
kiloclaw:
269302
needs: changes
270303
if: needs.changes.outputs.kiloclaw == 'true'

.github/workflows/deploy-production.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,30 @@ jobs:
355355
if: needs.check-security-sync-changes.outputs.changed == 'true'
356356
uses: ./.github/workflows/deploy-security-sync.yml
357357
secrets: inherit
358+
359+
check-security-auto-analysis-changes:
360+
runs-on: ubuntu-latest
361+
outputs:
362+
changed: ${{ steps.changes.outputs['security-auto-analysis'] }}
363+
steps:
364+
- name: Checkout code
365+
uses: actions/checkout@v4
366+
with:
367+
fetch-depth: 0
368+
369+
- name: Check for security-auto-analysis changes
370+
uses: dorny/paths-filter@v3
371+
id: changes
372+
with:
373+
filters: |
374+
security-auto-analysis:
375+
- 'cloudflare-security-auto-analysis/**'
376+
377+
deploy-security-auto-analysis:
378+
needs: [check-security-auto-analysis-changes]
379+
if: needs.check-security-auto-analysis-changes.outputs.changed == 'true'
380+
uses: ./.github/workflows/deploy-security-auto-analysis.yml
381+
secrets: inherit
358382
with:
359383
environment: prod
360384

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Deploy Security Auto Analysis
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
environment:
7+
description: 'Choose an environment to deploy to: dev or prod'
8+
required: true
9+
default: 'prod'
10+
type: choice
11+
options:
12+
- dev
13+
- prod
14+
workflow_call:
15+
inputs:
16+
environment:
17+
description: 'Choose an environment to deploy to: dev or prod'
18+
required: false
19+
default: 'prod'
20+
type: string
21+
22+
jobs:
23+
deploy:
24+
runs-on: ubuntu-latest
25+
name: Deploy Security Auto Analysis
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Setup pnpm
32+
uses: pnpm/action-setup@v2
33+
with:
34+
version: latest
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: 22
40+
41+
- name: Install dependencies
42+
working-directory: cloudflare-security-auto-analysis
43+
run: pnpm install --frozen-lockfile
44+
45+
- name: Deploy to Cloudflare Workers
46+
uses: cloudflare/wrangler-action@v3
47+
with:
48+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
49+
workingDirectory: cloudflare-security-auto-analysis
50+
command: ${{ inputs.environment == 'dev' && 'deploy --env dev' || 'deploy' }}

cloudflare-ai-attribution/src/ai-attribution.worker.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export type HonoContext = {
3030

3131
const app = new Hono<HonoContext>();
3232

33-
// @ts-expect-error workers-tagged-logger returns Handler typed against an older hono; incompatible with hono 4.12+
3433
app.use('*', useWorkersLogger('ai-attribution'));
3534

3635
// Health check endpoint (no auth required)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.wrangler
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { dirname } from 'path';
2+
import { fileURLToPath } from 'url';
3+
import { defineConfig } from 'eslint/config';
4+
import baseConfig from '@kilocode/eslint-config';
5+
6+
const __dirname = dirname(fileURLToPath(import.meta.url));
7+
8+
export default defineConfig([...baseConfig(__dirname)]);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "cloudflare-security-auto-analysis",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"deploy:prod": "wrangler deploy",
7+
"deploy:dev": "wrangler deploy --env dev",
8+
"dev": "wrangler dev --env dev",
9+
"lint": "eslint --config eslint.config.mjs --cache 'src/**/*.ts'",
10+
"typecheck": "tsc --noEmit",
11+
"types": "wrangler types --env-interface CloudflareEnv worker-configuration.d.ts",
12+
"test": "vitest run"
13+
},
14+
"dependencies": {
15+
"@kilocode/db": "workspace:*",
16+
"drizzle-orm": "catalog:",
17+
"workers-tagged-logger": "catalog:",
18+
"zod": "catalog:"
19+
},
20+
"devDependencies": {
21+
"@kilocode/eslint-config": "workspace:*",
22+
"@types/node": "^22",
23+
"typescript": "catalog:",
24+
"vitest": "^3.2.4",
25+
"wrangler": "catalog:"
26+
}
27+
}

0 commit comments

Comments
 (0)