Skip to content

Commit 86f8c55

Browse files
docs: restructure the documentation, once again (#20)
1 parent 65fcbf0 commit 86f8c55

39 files changed

+20584
-1023
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ node_modules/
22
.env
33
data/
44
coverage/
5+
website/node_modules/
6+
website/.docusaurus/
7+
website/build/

CLAUDE.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,29 @@ DEBUG_MODE # set to "true" for verbose logging
5151

5252
Two separate Node.js processes:
5353

54-
**`src/server.js` Webhook receiver**
54+
**`src/server.js` - Webhook receiver**
5555
- Express app with `POST /webhook`, `GET /health`, `GET /metrics` (when enabled), `GET /assets/layne-logo.png`
5656
- Verifies GitHub HMAC signature before processing
5757
- Handles two event types: `pull_request` and `workflow_run`
5858
- **`pull_request` trigger (default):** on opened/synchronize/reopened, creates a Check Run in `queued` state, enqueues a BullMQ job, returns 200
5959
- **`workflow_run` trigger:** on `pull_request` events, caches PR metadata in Redis (TTL 7 days) and creates a `skipped` Check Run; on `workflow_run completed` events matching the configured workflow name and conclusion, looks up cached PR metadata (falls back to GitHub API if cache is cold) then enqueues the scan
60-
- Job ID is deduplicated by `{repo}#{pr}@{sha}` duplicate webhook deliveries are no-ops (Redis lock + queue check)
60+
- Job ID is deduplicated by `{repo}#{pr}@{sha}` - duplicate webhook deliveries are no-ops (Redis lock + queue check)
6161
- Exported `app` and `processWebhookRequest` for use in tests
6262

63-
**`src/worker.js` Job processor**
63+
**`src/worker.js` - Job processor**
6464
- BullMQ `Worker` consuming the `scans` queue with concurrency 5
6565
- `processJob()` is exported for direct testing without Redis
6666
- Per-job 10-minute timeout via `Promise.race`
67-
- Graceful shutdown on SIGTERM/SIGINT finishes in-flight jobs before exiting
67+
- Graceful shutdown on SIGTERM/SIGINT - finishes in-flight jobs before exiting
6868
- When `METRICS_ENABLED=true`: starts an HTTP metrics server on `METRICS_PORT` and polls BullMQ queue counts every 15 s
6969

7070
**Job lifecycle (inside `runScan`):**
7171
1. Mark Check Run `in_progress`
7272
2. Authenticate as installation via `src/auth.js` → short-lived token
7373
3. Create temp workspace (`src/fetcher.js``createWorkspace`)
74-
4. Partial-clone both head and base SHAs with `--filter=blob:none` fetches trees/commits only, no blobs yet (`src/fetcher.js``setupRepo`)
74+
4. Partial-clone both head and base SHAs with `--filter=blob:none` - fetches trees/commits only, no blobs yet (`src/fetcher.js``setupRepo`)
7575
5. Diff the two commits via tree objects to get changed file paths (`getChangedFiles`)
76-
6. Sparse-checkout only the changed files blobs fetched on demand (`checkoutFiles`)
76+
6. Sparse-checkout only the changed files - blobs fetched on demand (`checkoutFiles`)
7777
7. Load per-repo config via `src/config.js``loadScanConfig`
7878
8. Run scanners in parallel via `src/dispatcher.js``dispatch()`
7979
9. Convert findings to annotations via `src/reporter.js``buildAnnotations()`
@@ -83,11 +83,11 @@ Two separate Node.js processes:
8383
13. Clean up workspace in `finally`
8484

8585
**Scanners (`src/adapters/`):**
86-
- `semgrep.js` runs `semgrep scan --config auto --json`; exit code 1 = findings found (not an error); maps ERROR→high, WARNING→medium, INFO→low
87-
- `trufflehog.js` runs `trufflehog filesystem --json --no-update`; exit code 183 = secrets found (not an error); batched at 200 files to stay under ARG_MAX; all findings are severity `high`
88-
- `claude.js` calls the Anthropic API to detect malicious intent; **disabled by default**, opt in per repo; skips binary files; caps files at 50 KB; batches at 100 KB per API call; errors are caught and logged without failing the scan. Supports two modes (configured per-repo in `config/layne.json`):
86+
- `semgrep.js` - runs `semgrep scan --config auto --json`; exit code 1 = findings found (not an error); maps ERROR→high, WARNING→medium, INFO→low
87+
- `trufflehog.js` - runs `trufflehog filesystem --json --no-update`; exit code 183 = secrets found (not an error); batched at 200 files to stay under ARG_MAX; all findings are severity `high`
88+
- `claude.js` - calls the Anthropic API to detect malicious intent; **disabled by default**, opt in per repo; skips binary files; caps files at 50 KB; batches at 100 KB per API call; errors are caught and logged without failing the scan. Supports two modes (configured per-repo in `config/layne.json`):
8989
- **Prompt mode** (default): single `messages.create` call with a system prompt; use `claude.prompt` to override
90-
- **Skill mode**: uses the Anthropic [API Skills beta](https://platform.claude.com/docs/en/build-with-claude/skills-guide) adds a `code_execution` tool + an uploaded skill to each batch call, enabling runtime decoding, registry lookups, and richer static analysis; set `claude.skill: { id, version }` to enable; handles `pause_turn` continuations automatically (up to 10 turns per batch)
90+
- **Skill mode**: uses the Anthropic [API Skills beta](https://platform.claude.com/docs/en/build-with-claude/skills-guide) - adds a `code_execution` tool + an uploaded skill to each batch call, enabling runtime decoding, registry lookups, and richer static analysis; set `claude.skill: { id, version }` to enable; handles `pause_turn` continuations automatically (up to 10 turns per batch)
9191

9292
**Common finding shape:**
9393
```js
@@ -118,32 +118,32 @@ Two separate Node.js processes:
118118
See [docs/2-configuration.md](docs/2-configuration.md) for the full schema and examples.
119119

120120
Key points for code navigation:
121-
- Read once per process startup **restart both server and worker to pick up changes**
121+
- Read once per process startup - **restart both server and worker to pick up changes**
122122
- Loaded and merged by `src/config.js``loadScanConfig`
123123
- Supports `$global` key for defaults inherited by all repos
124124
- Scanner blocks: per-repo spread over defaults (`{ ...DEFAULT_CONFIG.semgrep, ...repoOverrides.semgrep }`)
125-
- `trigger`: controls when scanning fires `pull_request` (default, immediate) or `workflow_run` (deferred until a named CI workflow completes); global default → per-repo override
125+
- `trigger`: controls when scanning fires - `pull_request` (default, immediate) or `workflow_run` (deferred until a named CI workflow completes); global default → per-repo override
126126
- `notifications` and `labels`: per-repo notifier/key wins over global; per-repo absence = inherit global entirely
127127
- `extraArgs` fully replaces the default (not extended)
128128
- `config/layne.json` must be present in the Docker image (`COPY config/ ./config/`)
129-
- Notifier contract: `async function notify({ findings, owner, repo, prNumber, toolConfig })` must never throw
129+
- Notifier contract: `async function notify({ findings, owner, repo, prNumber, toolConfig })` - must never throw
130130
- Notification dedup key: `layne:scan:count:{owner}/{repo}#{prNumber}` (Redis, 30-day TTL)
131131
- `webhookUrl` values starting with `$` are resolved from `process.env` at runtime
132132
- Label errors never affect the scan result or Check Run
133133

134134
## Metrics
135135

136136
- `src/metrics.js` exports real prom-client objects when `METRICS_ENABLED=true`, silent no-op stubs otherwise
137-
- No `if (METRICS_ENABLED)` guards needed at call sites stubs absorb all calls
137+
- No `if (METRICS_ENABLED)` guards needed at call sites - stubs absorb all calls
138138
- Worker: metrics HTTP server + BullMQ queue poller (15 s interval) started only when enabled
139139
- Server: `GET /metrics` route registered only when enabled
140140
- `monitoring/` directory has Prometheus scrape config and a pre-built Grafana dashboard
141141

142142
## Testing conventions
143143

144144
- Tests use Vitest with ESM (`"type": "module"` in package.json)
145-
- `src/__tests__/setup.js` sets all required env vars before each test file; `ANTHROPIC_API_KEY` and `METRICS_ENABLED` are intentionally not set adapters and metrics are mocked
146-
- External dependencies (`@octokit/auth-app`, `@octokit/rest`, `bullmq`, `ioredis`, `@anthropic-ai/sdk`, `prom-client`) are always mocked no live connections in tests
145+
- `src/__tests__/setup.js` sets all required env vars before each test file; `ANTHROPIC_API_KEY` and `METRICS_ENABLED` are intentionally not set - adapters and metrics are mocked
146+
- External dependencies (`@octokit/auth-app`, `@octokit/rest`, `bullmq`, `ioredis`, `@anthropic-ai/sdk`, `prom-client`) are always mocked - no live connections in tests
147147
- `src/metrics.js` is mocked in worker and server tests with `vi.fn()` stubs; tested in isolation in `src/__tests__/metrics.test.js`
148148
- `processJob` and `dispatch` are exported specifically for unit testing without live infrastructure
149149
- Tests import modules with `await import(...)` after `vi.mock()` calls to handle ESM module caching

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Thanks for your interest in contributing. This document covers the branch model,
3434

3535
## Changesets
3636

37-
Every PR that changes behaviour needs a changeset a small file that describes what changed and what kind of version bump it warrants. The changeset check CI will fail if one is missing.
37+
Every PR that changes behaviour needs a changeset - a small file that describes what changed and what kind of version bump it warrants. The changeset check CI will fail if one is missing.
3838

3939
**Add a changeset:**
4040
```bash
@@ -53,7 +53,7 @@ This prompts you to pick a bump type and write a one-line description, then writ
5353

5454
**Skipping the changeset:**
5555

56-
For PRs that don't warrant a release entry CI fixes, typos, documentation updates add the `no-changeset` label to the PR. The check will be skipped.
56+
For PRs that don't warrant a release entry - CI fixes, typos, documentation updates - add the `no-changeset` label to the PR. The check will be skipped.
5757

5858
---
5959

@@ -62,7 +62,7 @@ For PRs that don't warrant a release entry — CI fixes, typos, documentation up
6262
- **One thing per PR.** If you find yourself writing "and also..." in the description, split it.
6363
- **Explain the why.** The diff shows what changed. The description should say why.
6464
- **Every behaviour change needs a test.** If you're fixing a bug, the test should fail on the old code.
65-
- **Security-sensitive areas get extra scrutiny** webhook verification, auth, file path handling, scanner output parsing. Explain your threat model.
65+
- **Security-sensitive areas get extra scrutiny** - webhook verification, auth, file path handling, scanner output parsing. Explain your threat model.
6666

6767
**Example description:**
6868

@@ -98,8 +98,8 @@ All four must pass before a PR can be merged.
9898

9999
## Extending Layne
100100

101-
- **Adding a new scanner:** see [docs/6-extending.md Adding a New Scanner](docs/6-extending.md#adding-a-new-scanner)
102-
- **Adding a notification provider:** see [docs/6-extending.md Adding a New Notifier](docs/6-extending.md#adding-a-new-notifier)
101+
- **Adding a new scanner:** see [docs/6-extending.md - Adding a New Scanner](docs/6-extending.md#adding-a-new-scanner)
102+
- **Adding a notification provider:** see [docs/6-extending.md - Adding a New Notifier](docs/6-extending.md#adding-a-new-notifier)
103103

104104
---
105105

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Layne ships with three built-in scanners. You can enable, disable, or configure
5252
| [Trufflehog](https://github.com/trufflesecurity/trufflehog) | Secrets, API keys and credentials | Runs `trufflehog filesystem`; use `--only-verified` to reduce noise |
5353
| [Claude](https://www.anthropic.com) | Bugs, vulnerabilities, backdoors, obfuscated payloads, supply-chain attacks (you can define a system prompt or a skill to use) | Disabled by default; opt in per repo; requires `ANTHROPIC_API_KEY` |
5454

55-
You can also add your own scanners. See [Extending Layne](docs/6-extending.md).
55+
You can also add your own scanners. See [Extending Layne](website/docs/extending.md).
5656

5757
### Layne's Workflow
5858

@@ -74,13 +74,15 @@ And you can configure Layne to send a notification via webhook to a Rocket.Chat
7474

7575
## Documentation
7676

77-
- [**Deployment**](docs/1-deployment.md) - EC2 setup, Docker Compose, TLS, and automated CI/CD pipeline
78-
- [**Configuration**](docs/2-configuration.md) - per-repo scanner settings, PR labels, and chat notifications
79-
- [**Local Development**](docs/3-local-development.md) - set up a local dev environment, replay webhooks, and debug without deploying
80-
- [**Security Architecture**](docs/4-security-architecture.md) - permissions, credential handling, network exposure, and compromise scenarios
81-
- [**Metrics**](docs/5-metrics.md) - Prometheus metrics and the bundled Grafana dashboard
82-
- [**Extending Layne**](docs/6-extending.md) - adding new scanners and notification providers
83-
- [**Reference**](docs/7-reference.md) - environment variables, finding shape, severity levels, and queue behaviour
77+
Run the documentation site locally:
78+
79+
```bash
80+
npm run docs:dev
81+
```
82+
83+
Then open [http://localhost:3000](http://localhost:3000).
84+
85+
The full documentation covers deployment, configuration, scanners, notifiers, PR comments, finding suppression, metrics, security architecture, and more.
8486

8587
## License
8688

SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
If you believe you have found a security vulnerability in Layne, please do not open a public GitHub issue. Instead, report it through one of the following channels:
66

7-
- **GitHub Security Advisory:** [Report a vulnerability](../../security/advisories/new) opens a private advisory draft visible only to maintainers.
7+
- **GitHub Security Advisory:** [Report a vulnerability](../../security/advisories/new) - opens a private advisory draft visible only to maintainers.
88
- **Email:** [security@rocket.chat](mailto:security@rocket.chat)
99

1010
Please include as much detail as possible: a description of the vulnerability, steps to reproduce it, and the potential impact. If you have a proof-of-concept or suggested fix, we welcome that too.
@@ -19,7 +19,7 @@ We ask that you:
1919

2020
- Give us reasonable time to investigate and fix the issue before disclosing it publicly.
2121
- Avoid accessing, modifying, or deleting data that does not belong to you.
22-
- Act in good faith we will do the same.
22+
- Act in good faith - we will do the same.
2323

2424
Researchers who follow these guidelines will be credited in the fix unless they prefer to remain anonymous.
2525

0 commit comments

Comments
 (0)