@getcodesentinel/codesentinel 1.7.0 → 1.9.0
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/README.md +137 -22
- package/dist/index.js +1519 -84
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -13,6 +13,66 @@ CodeSentinel is a structural and evolutionary risk analysis engine for modern Ty
|
|
|
13
13
|
|
|
14
14
|
This repository contains the CodeSentinel monorepo, with structural, evolution, external dependency, and deterministic risk analysis engines exposed through a CLI.
|
|
15
15
|
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
### 1) Install
|
|
19
|
+
|
|
20
|
+
Global install (good for local/manual usage):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -g @getcodesentinel/codesentinel
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Project/CI install (recommended for CI and reproducibility):
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install --save-dev @getcodesentinel/codesentinel
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 2) Analyze a project
|
|
33
|
+
|
|
34
|
+
Run commands from the repository root you want to analyze. If you run from another directory, pass the target path explicitly (for example `codesentinel analyze /path/to/project`).
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
codesentinel analyze
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 3) Generate a report
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
codesentinel report --format md --output codesentinel-report.md
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 4) Run in CI
|
|
47
|
+
|
|
48
|
+
Using local project install (no global install required):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx codesentinel ci --baseline-ref auto --fail-on error
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or in package scripts:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"scripts": {
|
|
59
|
+
"risk:ci": "codesentinel ci --baseline-ref auto --fail-on error"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Example CI policy:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
codesentinel ci --baseline-ref auto \
|
|
68
|
+
--max-repo-score 55 \
|
|
69
|
+
--max-repo-delta 0.03 \
|
|
70
|
+
--no-new-cycles \
|
|
71
|
+
--no-new-high-risk-deps \
|
|
72
|
+
--max-new-hotspots 2 \
|
|
73
|
+
--fail-on error
|
|
74
|
+
```
|
|
75
|
+
|
|
16
76
|
## Vision
|
|
17
77
|
|
|
18
78
|
CodeSentinel combines three signals into a single, explainable risk profile:
|
|
@@ -40,6 +100,7 @@ The goal is a practical, engineering-grade model that supports both strategic ar
|
|
|
40
100
|
- `packages/dependency-firewall`: external dependency and supply chain signals.
|
|
41
101
|
- `packages/risk-engine`: risk aggregation and scoring model.
|
|
42
102
|
- `packages/reporter`: structured report output (console, JSON, CI).
|
|
103
|
+
- `packages/governance`: CI gate evaluation and enforcement policy checks.
|
|
43
104
|
- `packages/cli`: user-facing CLI entrypoint.
|
|
44
105
|
|
|
45
106
|
Each package is standalone, ESM-only, TypeScript-first, and built with `tsup`. The CLI depends on `core`; domain packages are kept decoupled to avoid circular dependencies.
|
|
@@ -70,6 +131,9 @@ Then run:
|
|
|
70
131
|
```bash
|
|
71
132
|
codesentinel analyze [path]
|
|
72
133
|
codesentinel explain [path]
|
|
134
|
+
codesentinel report [path]
|
|
135
|
+
codesentinel check [path]
|
|
136
|
+
codesentinel ci [path]
|
|
73
137
|
codesentinel dependency-risk <dependency[@version]>
|
|
74
138
|
```
|
|
75
139
|
|
|
@@ -83,6 +147,14 @@ codesentinel explain
|
|
|
83
147
|
codesentinel explain . --top 5 --format text
|
|
84
148
|
codesentinel explain . --file src/app/page.tsx
|
|
85
149
|
codesentinel explain . --module src/components
|
|
150
|
+
codesentinel report
|
|
151
|
+
codesentinel report --format md --output report.md
|
|
152
|
+
codesentinel report --snapshot snapshot.json
|
|
153
|
+
codesentinel report --compare baseline.json --format text
|
|
154
|
+
codesentinel check --compare baseline.json --max-repo-delta 0.03 --no-new-cycles
|
|
155
|
+
codesentinel ci --baseline baseline.json --snapshot current.json --report report.md --fail-on error
|
|
156
|
+
codesentinel ci --baseline-ref origin/main --max-repo-delta 0.03 --no-new-cycles
|
|
157
|
+
codesentinel ci --baseline-ref auto --fail-on error
|
|
86
158
|
codesentinel dependency-risk react
|
|
87
159
|
codesentinel dependency-risk react@19.0.0
|
|
88
160
|
```
|
|
@@ -121,6 +193,13 @@ codesentinel explain . --module src/components
|
|
|
121
193
|
# Explain in markdown or json
|
|
122
194
|
codesentinel explain . --format md
|
|
123
195
|
codesentinel explain . --format json
|
|
196
|
+
|
|
197
|
+
# Report generation (human + machine readable)
|
|
198
|
+
codesentinel report .
|
|
199
|
+
codesentinel report . --format md --output report.md
|
|
200
|
+
codesentinel report . --format json
|
|
201
|
+
codesentinel report . --snapshot snapshot.json
|
|
202
|
+
codesentinel report . --compare baseline.json --format text
|
|
124
203
|
```
|
|
125
204
|
|
|
126
205
|
Notes:
|
|
@@ -145,8 +224,66 @@ pnpm dev -- analyze . --author-identity strict_email
|
|
|
145
224
|
pnpm dev -- explain
|
|
146
225
|
pnpm dev -- explain . --top 5 --format text
|
|
147
226
|
pnpm dev -- explain . --file src/app/page.tsx
|
|
227
|
+
pnpm dev -- report
|
|
228
|
+
pnpm dev -- report . --format md --output report.md
|
|
229
|
+
pnpm dev -- report . --compare baseline.json --format text
|
|
230
|
+
pnpm dev -- check . --compare baseline.json --max-repo-delta 0.03 --no-new-cycles
|
|
231
|
+
pnpm dev -- ci . --baseline baseline.json --snapshot current.json --report report.md --fail-on warn
|
|
148
232
|
```
|
|
149
233
|
|
|
234
|
+
## Report Output
|
|
235
|
+
|
|
236
|
+
`codesentinel report` produces deterministic engineering artifacts from existing analysis outputs.
|
|
237
|
+
|
|
238
|
+
- formats: `text`, `md`, `json`
|
|
239
|
+
- optional file output: `--output <path>`
|
|
240
|
+
- optional snapshot export: `--snapshot <path>`
|
|
241
|
+
- optional diff mode: `--compare <baseline.json>`
|
|
242
|
+
|
|
243
|
+
Diff mode compares snapshots and reports:
|
|
244
|
+
|
|
245
|
+
- repository score deltas
|
|
246
|
+
- file/module risk deltas
|
|
247
|
+
- new/resolved hotspots
|
|
248
|
+
- new/resolved cycles
|
|
249
|
+
- dependency exposure list changes
|
|
250
|
+
|
|
251
|
+
## CI Mode
|
|
252
|
+
|
|
253
|
+
`codesentinel check` evaluates enforcement gates against current analysis (and optional baseline diff).
|
|
254
|
+
|
|
255
|
+
Supported gates:
|
|
256
|
+
|
|
257
|
+
- `--max-repo-delta <value>`
|
|
258
|
+
- `--no-new-cycles`
|
|
259
|
+
- `--no-new-high-risk-deps`
|
|
260
|
+
- `--max-new-hotspots <count>`
|
|
261
|
+
- `--max-repo-score <score>`
|
|
262
|
+
- `--new-hotspot-score-threshold <score>`
|
|
263
|
+
- `--fail-on error|warn`
|
|
264
|
+
|
|
265
|
+
`codesentinel ci` orchestrates snapshot + diff + gate evaluation + markdown summary generation.
|
|
266
|
+
|
|
267
|
+
Baseline input modes:
|
|
268
|
+
|
|
269
|
+
- `--baseline <path>`: use an existing snapshot JSON artifact.
|
|
270
|
+
- `--baseline-ref <git-ref>`: resolve baseline from git (`origin/main`, `main`, `HEAD~1`) using an isolated temporary worktree. No checkout/stash of your current working tree.
|
|
271
|
+
- `--baseline-ref auto`: deterministic resolver with ordered fallbacks:
|
|
272
|
+
- `--baseline-sha <sha>` if provided.
|
|
273
|
+
- CI base branch env vars (`GITHUB_BASE_REF`, `CI_MERGE_REQUEST_TARGET_BRANCH_NAME`, `BITBUCKET_PR_DESTINATION_BRANCH`) with `origin/<branch>` first, then `<branch>`.
|
|
274
|
+
- branch-aware defaults:
|
|
275
|
+
- on `main/master`: `HEAD~1`
|
|
276
|
+
- otherwise: `merge-base(HEAD, origin/main)` then `origin/master`, `main`, `master`
|
|
277
|
+
- `--main-branch <name>` (repeatable) or `--main-branches "main,master,trunk"` customize default branch candidates used by `--baseline-ref auto`.
|
|
278
|
+
|
|
279
|
+
Exit codes:
|
|
280
|
+
|
|
281
|
+
- `0`: no failing violations
|
|
282
|
+
- `1`: error-level violations
|
|
283
|
+
- `2`: warn-level violations when `--fail-on=warn`
|
|
284
|
+
- `3`: invalid configuration
|
|
285
|
+
- `4`: internal execution error
|
|
286
|
+
|
|
150
287
|
## Explain Output
|
|
151
288
|
|
|
152
289
|
`codesentinel explain` uses the same risk-engine scoring model as `analyze` and adds structured explanation traces.
|
|
@@ -278,28 +415,6 @@ Propagation policy is explicit and deterministic:
|
|
|
278
415
|
|
|
279
416
|
This keeps package-level facts local while still surfacing meaningful transitive exposure.
|
|
280
417
|
|
|
281
|
-
## Release Automation
|
|
282
|
-
|
|
283
|
-
- Pull requests to `main` run build and tests via `.github/workflows/ci.yml`.
|
|
284
|
-
- Pull requests and release runs also validate the packed CLI artifact (`npm pack`) with install/execute smoke checks before publish.
|
|
285
|
-
- Merges to `main` run semantic-release via `.github/workflows/release.yml`.
|
|
286
|
-
- semantic-release bumps `packages/cli/package.json`, creates a GitHub release, publishes to npm, and pushes the version-bump commit back to `main`.
|
|
287
|
-
- Dependabot is configured monthly in `.github/dependabot.yml` for npm and GitHub Actions updates.
|
|
288
|
-
|
|
289
|
-
Trusted Publisher setup (no `NPM_TOKEN` secret):
|
|
290
|
-
|
|
291
|
-
- In npm package settings for `@getcodesentinel/codesentinel`, add a Trusted Publisher.
|
|
292
|
-
- Provider: `GitHub Actions`.
|
|
293
|
-
- Repository: `getcodesentinel/codesentinel`.
|
|
294
|
-
- Workflow filename: `release.yml`.
|
|
295
|
-
- Environment name: leave empty unless you explicitly use a GitHub Actions environment in this workflow.
|
|
296
|
-
|
|
297
|
-
Commit messages on `main` should follow Conventional Commits (example: `feat:`, `fix:`, `chore:`) so semantic-release can calculate versions automatically.
|
|
298
|
-
|
|
299
|
-
## Contributing
|
|
300
|
-
|
|
301
|
-
This project aims to be production-grade and minimal. If you add new dependencies or abstractions, justify them clearly and keep the architecture clean.
|
|
302
|
-
|
|
303
418
|
## ESM Import Policy
|
|
304
419
|
|
|
305
420
|
- The workspace uses `TypeScript` with `moduleResolution: "NodeNext"` and ESM output.
|