@critiq/cli 0.0.1 → 0.0.2
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 +96 -272
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,54 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/critiq-dev/critiq-core/main/docs/assets/banner-cli-simple-transparent.png" alt="critiq.dev" style="max-height:400px" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
<h1 align="center">Critiq CLI</h1>
|
|
6
|
+
<p align="center">
|
|
7
|
+
<strong>Open source deterministic static analysis for code review.<br/>Run high-signal checks on your codebase to identify security, performance, scaling issues before it goes to production</strong>
|
|
8
|
+
</p>
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/@critiq/cli"><img src="https://img.shields.io/npm/v/%40critiq%2Fcli" alt="npm version" /></a>
|
|
11
|
+
<a href="https://github.com/critiq-dev/critiq-core/tree/main/apps/cli"><img src="https://img.shields.io/badge/source-GitHub-181717?logo=github" alt="Source" /></a>
|
|
12
|
+
<a href="https://github.com/critiq-dev/critiq-core/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" alt="License" /></a>
|
|
13
|
+
</p>
|
|
5
14
|
|
|
6
|
-
Install it with the default OSS catalog:
|
|
7
15
|
|
|
8
|
-
```bash
|
|
9
|
-
npm install -D @critiq/cli @critiq/rules
|
|
10
|
-
npx critiq check .
|
|
11
|
-
```
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
Think of Critiq as an extra code reviewer that scans your project for bugs, security issues, performance problems, and risky changes before they turn into production incidents. Instead of only checking style, it focuses on the kinds of problems that usually slip through review and cause real trouble later. You run it locally or in CI, and it gives you deterministic findings you can act on before merging code.
|
|
14
18
|
|
|
15
|
-
- manual invocation while a developer is authoring, debugging, or reviewing a rule
|
|
16
|
-
- automated invocation in CI to increase confidence in a PR or run a broader repository scan
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
It does this by parsing your code, matching it against a curated catalog of explicit rules, and reporting findings with concrete evidence tied to the code that triggered them. That means the output is based on repeatable checks for things like unsafe SQL, missing authorization, repeated IO in loops, and untested critical logic changes, not vague heuristics or style-only linting.
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
<p align="center">
|
|
23
|
+
<img
|
|
24
|
+
src="https://raw.githubusercontent.com/critiq-dev/critiq-core/main/docs/assets/cli-architecture-transparent.png"
|
|
25
|
+
alt="Cli Architecture"
|
|
26
|
+
/>
|
|
27
|
+
</p>
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
`@critiq/cli` runs Critiq checks against real code and exposes the public rule-pack commands for validation, testing, normalization, and explanation. By default it uses [`@critiq/rules`](https://www.npmjs.com/package/@critiq/rules) as the open source catalog with recommended rules. You can configure this by adding a `.critiq/config.yaml` configuration file.
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
<br/>
|
|
32
|
+
<p align="left">
|
|
33
|
+
<img
|
|
34
|
+
src="https://raw.githubusercontent.com/critiq-dev/critiq-core/main/docs/assets/languages.png"
|
|
35
|
+
alt="TypeScript, JavaScript, Node.js, Go, Java, Python, PHP, Ruby and Rust support"
|
|
36
|
+
/>
|
|
37
|
+
</p>
|
|
31
38
|
|
|
32
|
-
|
|
39
|
+
`@critiq/cli` is capable of scanning codebases written in TypeScript, JavaScript, Node.js, Go, Java, Python, PHP, Ruby, and Rust.
|
|
40
|
+
|
|
41
|
+
## Start In 60 Seconds
|
|
42
|
+
|
|
43
|
+
Run Critiq on your project:
|
|
33
44
|
|
|
34
45
|
```bash
|
|
35
|
-
npm
|
|
36
|
-
|
|
46
|
+
npm install -D @critiq/cli @critiq/rules
|
|
47
|
+
npx critiq check .
|
|
37
48
|
```
|
|
38
49
|
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
Run Critiq against a diff:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npx critiq check . --base origin/main --head HEAD
|
|
54
|
+
```
|
|
41
55
|
|
|
42
|
-
##
|
|
56
|
+
## Public Commands
|
|
43
57
|
|
|
44
|
-
|
|
58
|
+
| Command | What it does |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `critiq check [target]` | Runs deterministic checks against a codebase, directory, or single file. |
|
|
61
|
+
| `critiq check . --base origin/main --head HEAD` | Limits scanning to changed files and changed ranges in a diff. |
|
|
62
|
+
| `critiq rules validate <glob>` | Validates rule YAML files and returns diagnostics. |
|
|
63
|
+
| `critiq rules test [glob]` | Runs fixture-backed `RuleSpec` files end to end. |
|
|
64
|
+
| `critiq rules normalize <file>` | Prints the canonical normalized form of one rule. |
|
|
65
|
+
| `critiq rules explain <file>` | Shows a readable breakdown of how one rule is interpreted. |
|
|
45
66
|
|
|
46
|
-
|
|
47
|
-
.critiq/
|
|
48
|
-
config.yaml
|
|
49
|
-
```
|
|
67
|
+
## Runtime Config
|
|
50
68
|
|
|
51
|
-
|
|
69
|
+
`critiq check` is catalog-first. When `.critiq/config.yaml` is present, it controls the catalog package, preset, and filters used for the run.
|
|
52
70
|
|
|
53
71
|
```yaml
|
|
54
72
|
apiVersion: critiq.dev/v1alpha1
|
|
@@ -64,242 +82,48 @@ ignorePaths: []
|
|
|
64
82
|
severityOverrides: {}
|
|
65
83
|
```
|
|
66
84
|
|
|
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
|
-
- tests excluded from `check` by default unless `includeTests: true`
|
|
113
|
-
|
|
114
|
-
Examples:
|
|
115
|
-
|
|
116
|
-
```bash
|
|
117
|
-
critiq check
|
|
118
|
-
critiq check . --format json
|
|
119
|
-
critiq check . --base origin/main --head HEAD --format json
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Migration:
|
|
123
|
-
|
|
124
|
-
```bash
|
|
125
|
-
# old
|
|
126
|
-
critiq check ".critiq/rules/*.rule.yaml" .
|
|
127
|
-
|
|
128
|
-
# new
|
|
129
|
-
critiq check .
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### `validate`
|
|
133
|
-
|
|
134
|
-
Use this while authoring rules.
|
|
135
|
-
|
|
136
|
-
It loads the YAML, validates the public contract, runs semantic validation, and
|
|
137
|
-
returns diagnostics only.
|
|
138
|
-
|
|
139
|
-
This is the command you would commonly use in a PR-focused workflow to make
|
|
140
|
-
sure authored rules are valid before the rules are executed elsewhere.
|
|
141
|
-
|
|
142
|
-
Examples:
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
critiq rules validate ".critiq/rules/*.rule.yaml"
|
|
146
|
-
critiq rules validate "packages/my-pack/rules/*.rule.yaml"
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### `test`
|
|
150
|
-
|
|
151
|
-
Use this to run `RuleSpec` fixtures and prove rule behavior end to end.
|
|
152
|
-
|
|
153
|
-
This is the command that gives you confidence that a rule pack behaves the way
|
|
154
|
-
you expect before using it in an automated PR check or a repository scan.
|
|
155
|
-
|
|
156
|
-
If you omit the glob, it defaults to `**/*.spec.yaml` from the current working
|
|
157
|
-
directory.
|
|
158
|
-
|
|
159
|
-
Examples:
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
critiq rules test
|
|
163
|
-
critiq rules test ".critiq/rules/*.spec.yaml"
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
### `normalize`
|
|
167
|
-
|
|
168
|
-
Use this when you want to inspect the canonical normalized IR for one rule.
|
|
169
|
-
|
|
170
|
-
Example:
|
|
171
|
-
|
|
172
|
-
```bash
|
|
173
|
-
critiq rules normalize .critiq/rules/no-console.rule.yaml --format json
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### `explain`
|
|
177
|
-
|
|
178
|
-
Use this when you want a readable breakdown of:
|
|
179
|
-
|
|
180
|
-
- parsed rule metadata
|
|
181
|
-
- validation status
|
|
182
|
-
- normalized rule content
|
|
183
|
-
- inferred template variables
|
|
184
|
-
|
|
185
|
-
Example:
|
|
186
|
-
|
|
187
|
-
```bash
|
|
188
|
-
critiq rules explain .critiq/rules/no-console.rule.yaml
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## Flags
|
|
192
|
-
|
|
193
|
-
- `--format pretty|json`
|
|
194
|
-
- `--help`
|
|
195
|
-
|
|
196
|
-
`pretty` is the default.
|
|
197
|
-
|
|
198
|
-
## Exit Codes
|
|
199
|
-
|
|
200
|
-
- `0`: success
|
|
201
|
-
- `1`: findings or non-internal command failures
|
|
202
|
-
- `2`: internal/runtime errors
|
|
203
|
-
|
|
204
|
-
## Typical Developer Workflow
|
|
205
|
-
|
|
206
|
-
Authoring a new rule:
|
|
207
|
-
|
|
208
|
-
```bash
|
|
209
|
-
npm run nx -- run cli:prune
|
|
210
|
-
critiq rules validate ".critiq/rules/*.rule.yaml"
|
|
211
|
-
critiq rules explain .critiq/rules/no-console.rule.yaml
|
|
212
|
-
critiq rules test ".critiq/rules/*.spec.yaml"
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
Working from the separate `critiq-rules` repo:
|
|
216
|
-
|
|
217
|
-
```bash
|
|
218
|
-
npm run nx -- run cli:prune
|
|
219
|
-
critiq rules validate "../critiq-rules/examples/starter-pack/rules/*.rule.yaml"
|
|
220
|
-
critiq rules explain ../critiq-rules/examples/starter-pack/rules/ts.logging.no-console-log.rule.yaml
|
|
221
|
-
critiq rules test "../critiq-rules/examples/starter-pack/rules/*.spec.yaml"
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
Running in automation:
|
|
225
|
-
|
|
226
|
-
```bash
|
|
227
|
-
npm run nx -- run cli:prune
|
|
228
|
-
critiq check . --format json
|
|
229
|
-
critiq rules validate ".critiq/rules/*.rule.yaml" --format json
|
|
230
|
-
critiq rules test ".critiq/rules/*.spec.yaml" --format json
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
### Reusable GitHub Workflow
|
|
234
|
-
|
|
235
|
-
Consumer repositories can call the reusable workflow published from this repo
|
|
236
|
-
instead of copying the CLI setup into every workflow file.
|
|
237
|
-
|
|
238
|
-
Example:
|
|
239
|
-
|
|
240
|
-
```yaml
|
|
241
|
-
jobs:
|
|
242
|
-
critiq:
|
|
243
|
-
uses: critiq-dev/critiq-core/.github/workflows/run-critiq-cli.yml@ref
|
|
244
|
-
with:
|
|
245
|
-
critiq-version: x.y.z
|
|
246
|
-
run-check: true
|
|
247
|
-
check-target: .
|
|
248
|
-
check-base: origin/main
|
|
249
|
-
check-head: HEAD
|
|
250
|
-
validate-glob: .critiq/rules/*.rule.yaml
|
|
251
|
-
test-glob: .critiq/rules/*.spec.yaml
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
The workflow:
|
|
255
|
-
|
|
256
|
-
- checks out the consumer repository
|
|
257
|
-
- installs Node.js
|
|
258
|
-
- installs the requested `@critiq/cli` package version
|
|
259
|
-
- optionally runs `check`, `validate`, and `test` with JSON output
|
|
260
|
-
- uploads the JSON results as workflow artifacts
|
|
261
|
-
|
|
262
|
-
For production use, pin both the workflow ref and `critiq-version`.
|
|
263
|
-
|
|
264
|
-
## JSON Output
|
|
265
|
-
|
|
266
|
-
All commands support `--format json`.
|
|
267
|
-
|
|
268
|
-
That makes the CLI usable as:
|
|
269
|
-
|
|
270
|
-
- a terminal tool for humans
|
|
271
|
-
- a machine-readable step in CI
|
|
272
|
-
- a building block for custom wrappers
|
|
273
|
-
|
|
274
|
-
That means the same CLI can sit behind:
|
|
275
|
-
|
|
276
|
-
- a developer manually checking a rule before commit
|
|
277
|
-
- a repository or PR gate that emits findings from real source files
|
|
278
|
-
- a PR workflow that wants confidence before merge
|
|
279
|
-
- a scheduled or on-demand full repository scan
|
|
280
|
-
|
|
281
|
-
See [docs/reference/cli.md](../../docs/reference/cli.md) for the envelope
|
|
282
|
-
shapes.
|
|
283
|
-
|
|
284
|
-
## Relationship To The Rest Of The Repo
|
|
285
|
-
|
|
286
|
-
The CLI is intentionally thin. It composes the OSS packages rather than
|
|
287
|
-
re-implementing their logic.
|
|
288
|
-
|
|
289
|
-
- repository scanning comes from `@critiq/check-runner`
|
|
290
|
-
- adapter-backed source analysis comes from `@critiq/adapter-typescript`
|
|
291
|
-
- rule loading and validation come from `@critiq/core-rules-dsl`
|
|
292
|
-
- normalization comes from `@critiq/core-ir`
|
|
293
|
-
- diagnostics rendering comes from `@critiq/core-diagnostics`
|
|
294
|
-
- fixture-based testing comes from `@critiq/testing-harness`
|
|
295
|
-
|
|
296
|
-
That means you can use the CLI directly, or use the underlying packages inside
|
|
297
|
-
your own tooling if you need more control.
|
|
298
|
-
|
|
299
|
-
## Development Commands
|
|
300
|
-
|
|
301
|
-
- `npm run nx -- build cli`
|
|
302
|
-
- `npm run nx -- run cli:prune`
|
|
303
|
-
- `npm run nx -- test cli`
|
|
304
|
-
- `npm run nx -- lint cli`
|
|
305
|
-
- `npm run nx -- typecheck cli`
|
|
85
|
+
Supported presets are `recommended`, `strict`, `security`, and `experimental`.
|
|
86
|
+
|
|
87
|
+
## Default OSS Rule Catalog
|
|
88
|
+
|
|
89
|
+
The default open source catalog in [`@critiq/rules`](https://www.npmjs.com/package/@critiq/rules) currently includes `112` rules across `10` categories.
|
|
90
|
+
|
|
91
|
+
| Category | Rules | What it looks after |
|
|
92
|
+
| --- | ---: | --- |
|
|
93
|
+
| Security | 70 | Injection, auth and session gaps, unsafe transport, sensitive data exposure, unsafe file and HTML handling |
|
|
94
|
+
| Correctness | 15 | Async bugs, null access, control-flow mistakes, missing fallbacks, race conditions |
|
|
95
|
+
| Performance | 10 | Repeated IO, wasted async sequencing, hot-path loops, large retained objects, render churn |
|
|
96
|
+
| Quality | 10 | Error handling gaps, oversized functions, coupling, duplicated logic, and weak test coverage |
|
|
97
|
+
| Logging | 2 | Console usage and unsafe logging patterns |
|
|
98
|
+
| Config | 1 | Configuration access boundaries |
|
|
99
|
+
| Next | 1 | Server and client boundary leaks |
|
|
100
|
+
| Random | 1 | Unsafe randomness in core logic |
|
|
101
|
+
| React | 1 | Cascaded effect fetch patterns |
|
|
102
|
+
| Runtime | 1 | Debug-only statements left in shipped code |
|
|
103
|
+
|
|
104
|
+
## High-Value Rules In The Default Catalog
|
|
105
|
+
|
|
106
|
+
| Rule title | Description |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| `Hardcoded API keys or credentials` | Source files should not embed credential-like string literals. |
|
|
109
|
+
| `Avoid raw or interpolated SQL`| Database query sinks must not receive request-driven or dynamically interpolated SQL text. |
|
|
110
|
+
| `Path traversal via user input` | File access calls must not use request-controlled paths directly. |
|
|
111
|
+
| `Protect deserialization trust boundaries`| Deserializers should not consume untrusted payloads directly across a trust boundary. |
|
|
112
|
+
| `Server-side request forgery` (`ts.security.ssrf`) | Outbound requests should not use attacker-controlled targets or private hosts. |
|
|
113
|
+
| `Open redirect via request-controlled target`| Redirect and navigation sinks should not use request-controlled destinations without validation. |
|
|
114
|
+
| `Missing authorization before sensitive action` | Sensitive backend actions should be guarded by an authorization or permission check. |
|
|
115
|
+
| `Use authenticated encryption for secrets and tokens` | Session, cookie, and token encryption should provide integrity protection in the same helper. |
|
|
116
|
+
| `Missing await on async call` | Async functions should not drop direct async calls without awaiting them. |
|
|
117
|
+
| `Repeated IO call inside loop` | Database or network calls inside loops can multiply latency and load. |
|
|
118
|
+
| `Logic change without corresponding test updates` | Diffs that change critical logic should usually update the matching tests in the same change. |
|
|
119
|
+
| `Avoid server/client boundary leaks in Next.js` | Server components should not use browser-only APIs or client-only hooks without an explicit client boundary. |
|
|
120
|
+
|
|
121
|
+
## Reference
|
|
122
|
+
|
|
123
|
+
- [Getting started](https://github.com/critiq-dev/critiq-core/blob/main/docs/guides/getting-started.md)
|
|
124
|
+
- [CLI reference](https://github.com/critiq-dev/critiq-core/blob/main/docs/reference/cli.md)
|
|
125
|
+
- [`@critiq/rules` package](https://www.npmjs.com/package/@critiq/rules)
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
`@critiq/cli` is licensed under [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0). See the source [LICENSE](https://github.com/critiq-dev/critiq-core/blob/main/LICENSE).
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@critiq/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "Critiq CLI for deterministic
|
|
5
|
+
"description": "Critiq CLI for deterministic codebase checks, rule validation, and fixture-driven rule tests.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"bin": {
|