repopilot 0.6.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/LICENSE ADDED
@@ -0,0 +1,186 @@
1
+ RepoPilot is licensed under either of:
2
+
3
+ - MIT License
4
+ - Apache License, Version 2.0
5
+
6
+ at your option.
7
+
8
+ MIT License
9
+
10
+ Copyright (c) 2026 RepoPilot contributors
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+
30
+ Apache License
31
+ Version 2.0, January 2004
32
+ http://www.apache.org/licenses/
33
+
34
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
35
+
36
+ 1. Definitions.
37
+
38
+ "License" shall mean the terms and conditions for use, reproduction, and
39
+ distribution as defined by Sections 1 through 9 of this document.
40
+
41
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
42
+ owner that is granting the License.
43
+
44
+ "Legal Entity" shall mean the union of the acting entity and all other entities
45
+ that control, are controlled by, or are under common control with that entity.
46
+ For the purposes of this definition, "control" means (i) the power, direct or
47
+ indirect, to cause the direction or management of such entity, whether by
48
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
49
+ outstanding shares, or (iii) beneficial ownership of such entity.
50
+
51
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
52
+ permissions granted by this License.
53
+
54
+ "Source" form shall mean the preferred form for making modifications, including
55
+ but not limited to software source code, documentation source, and configuration
56
+ files.
57
+
58
+ "Object" form shall mean any form resulting from mechanical transformation or
59
+ translation of a Source form, including but not limited to compiled object code,
60
+ generated documentation, and conversions to other media types.
61
+
62
+ "Work" shall mean the work of authorship, whether in Source or Object form,
63
+ made available under the License, as indicated by a copyright notice that is
64
+ included in or attached to the work.
65
+
66
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
67
+ is based on (or derived from) the Work and for which the editorial revisions,
68
+ annotations, elaborations, or other modifications represent, as a whole, an
69
+ original work of authorship. For the purposes of this License, Derivative Works
70
+ shall not include works that remain separable from, or merely link (or bind by
71
+ name) to the interfaces of, the Work and Derivative Works thereof.
72
+
73
+ "Contribution" shall mean any work of authorship, including the original
74
+ version of the Work and any modifications or additions to that Work or
75
+ Derivative Works thereof, that is intentionally submitted to Licensor for
76
+ inclusion in the Work by the copyright owner or by an individual or Legal Entity
77
+ authorized to submit on behalf of the copyright owner. For the purposes of this
78
+ definition, "submitted" means any form of electronic, verbal, or written
79
+ communication sent to the Licensor or its representatives, including but not
80
+ limited to communication on electronic mailing lists, source code control
81
+ systems, and issue tracking systems that are managed by, or on behalf of, the
82
+ Licensor for the purpose of discussing and improving the Work, but excluding
83
+ communication that is conspicuously marked or otherwise designated in writing by
84
+ the copyright owner as "Not a Contribution."
85
+
86
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
87
+ of whom a Contribution has been received by Licensor and subsequently
88
+ incorporated within the Work.
89
+
90
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
91
+ License, each Contributor hereby grants to You a perpetual, worldwide,
92
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
93
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
94
+ sublicense, and distribute the Work and such Derivative Works in Source or
95
+ Object form.
96
+
97
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
98
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
99
+ no-charge, royalty-free, irrevocable patent license to make, have made, use,
100
+ offer to sell, sell, import, and otherwise transfer the Work, where such license
101
+ applies only to those patent claims licensable by such Contributor that are
102
+ necessarily infringed by their Contribution alone or by combination of their
103
+ Contribution with the Work to which such Contribution was submitted. If You
104
+ institute patent litigation against any entity alleging that the Work or a
105
+ Contribution incorporated within the Work constitutes direct or contributory
106
+ patent infringement, then any patent licenses granted to You under this License
107
+ for that Work shall terminate as of the date such litigation is filed.
108
+
109
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
110
+ Derivative Works thereof in any medium, with or without modifications, and in
111
+ Source or Object form, provided that You meet the following conditions:
112
+
113
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
114
+ this License; and
115
+
116
+ (b) You must cause any modified files to carry prominent notices stating that
117
+ You changed the files; and
118
+
119
+ (c) You must retain, in the Source form of any Derivative Works that You
120
+ distribute, all copyright, patent, trademark, and attribution notices from the
121
+ Source form of the Work, excluding those notices that do not pertain to any part
122
+ of the Derivative Works; and
123
+
124
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
125
+ any Derivative Works that You distribute must include a readable copy of the
126
+ attribution notices contained within such NOTICE file, excluding those notices
127
+ that do not pertain to any part of the Derivative Works, in at least one of the
128
+ following places: within a NOTICE text file distributed as part of the
129
+ Derivative Works; within the Source form or documentation, if provided along
130
+ with the Derivative Works; or, within a display generated by the Derivative
131
+ Works, if and wherever such third-party notices normally appear. The contents of
132
+ the NOTICE file are for informational purposes only and do not modify the
133
+ License. You may add Your own attribution notices within Derivative Works that
134
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
135
+ provided that such additional attribution notices cannot be construed as
136
+ modifying the License.
137
+
138
+ You may add Your own copyright statement to Your modifications and may provide
139
+ additional or different license terms and conditions for use, reproduction, or
140
+ distribution of Your modifications, or for any such Derivative Works as a whole,
141
+ provided Your use, reproduction, and distribution of the Work otherwise complies
142
+ with the conditions stated in this License.
143
+
144
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
145
+ Contribution intentionally submitted for inclusion in the Work by You to the
146
+ Licensor shall be under the terms and conditions of this License, without any
147
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
148
+ supersede or modify the terms of any separate license agreement you may have
149
+ executed with Licensor regarding such Contributions.
150
+
151
+ 6. Trademarks. This License does not grant permission to use the trade names,
152
+ trademarks, service marks, or product names of the Licensor, except as required
153
+ for reasonable and customary use in describing the origin of the Work and
154
+ reproducing the content of the NOTICE file.
155
+
156
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
157
+ writing, Licensor provides the Work on an "AS IS" BASIS, WITHOUT WARRANTIES OR
158
+ CONDITIONS OF ANY KIND, either express or implied, including, without
159
+ limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
160
+ MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
161
+ responsible for determining the appropriateness of using or redistributing the
162
+ Work and assume any risks associated with Your exercise of permissions under
163
+ this License.
164
+
165
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
166
+ tort (including negligence), contract, or otherwise, unless required by
167
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
168
+ writing, shall any Contributor be liable to You for damages, including any
169
+ direct, indirect, special, incidental, or consequential damages of any character
170
+ arising as a result of this License or out of the use or inability to use the
171
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
172
+ computer failure or malfunction, or any and all other commercial damages or
173
+ losses), even if such Contributor has been advised of the possibility of such
174
+ damages.
175
+
176
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
177
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
178
+ acceptance of support, warranty, indemnity, or other liability obligations
179
+ and/or rights consistent with this License. However, in accepting such
180
+ obligations, You may act only on Your own behalf and on Your sole
181
+ responsibility, not on behalf of any other Contributor, and only if You agree to
182
+ indemnify, defend, and hold each Contributor harmless for any liability incurred
183
+ by, or claims asserted against, such Contributor by reason of your accepting any
184
+ such warranty or additional liability.
185
+
186
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,314 @@
1
+ # RepoPilot
2
+
3
+ [![Crates.io](https://img.shields.io/crates/v/repopilot.svg)](https://crates.io/crates/repopilot)
4
+ [![npm](https://img.shields.io/npm/v/repopilot.svg)](https://www.npmjs.com/package/repopilot)
5
+ [![Docs.rs](https://docs.rs/repopilot/badge.svg)](https://docs.rs/repopilot)
6
+ [![CI](https://github.com/MykytaStel/repopilot/actions/workflows/ci.yaml/badge.svg)](https://github.com/MykytaStel/repopilot/actions)
7
+ [![GitHub Release](https://img.shields.io/github/v/release/MykytaStel/repopilot)](https://github.com/MykytaStel/repopilot/releases)
8
+ [![License](https://img.shields.io/crates/l/repopilot.svg)](LICENSE)
9
+
10
+ Local-first CLI for repository audit, architecture risk detection, baseline tracking, and CI-friendly code review.
11
+
12
+ RepoPilot runs on your machine and does not upload your repository. It helps developers understand what changed, what became riskier, and where to review first.
13
+
14
+ ## Why RepoPilot?
15
+
16
+ Modern developers ship more code than they can carefully review, especially with AI-assisted workflows.
17
+
18
+ RepoPilot helps you understand:
19
+
20
+ - what changed;
21
+ - what became riskier;
22
+ - which findings are new;
23
+ - which findings already existed;
24
+ - where to review first.
25
+
26
+ RepoPilot runs locally and does not upload your repository.
27
+
28
+ ## Features
29
+
30
+ - Repository scanning for projects, folders, and individual files
31
+ - Gitignore-aware walking with built-in ignores for common build and service directories
32
+ - Architecture findings: oversized files, deep nesting, too many modules per directory
33
+ - Coupling analysis: excessive fan-out, high-instability hubs, circular dependencies
34
+ - Code quality findings: cyclomatic complexity density, long functions, TODO/FIXME/HACK markers
35
+ - Security findings: hardcoded secret candidates, committed private keys, committed `.env` files
36
+ - Testing findings: missing test folder, source files without test counterparts
37
+ - Framework findings for JavaScript, React, React Native, and Expo projects
38
+ - React Native architecture profile: project kind, New Architecture, Hermes, Codegen, platform mismatch, and package manager signals
39
+ - Workspace framework detection through `package.json` workspaces
40
+ - Evidence-backed findings with stable rule IDs, severity, file paths, line numbers, and snippets
41
+ - `repopilot.toml` configuration generated by `repopilot init`
42
+ - Baseline workflow for accepting existing findings in legacy repositories
43
+ - CI-friendly failure thresholds with `--fail-on`
44
+ - Git diff-aware review mode for prioritizing findings introduced by changed lines
45
+ - Console, JSON, Markdown, HTML, and SARIF scan output
46
+ - Compare mode for diffing two JSON scan reports
47
+
48
+ See [docs/rulesets.md](docs/rulesets.md) for the implemented rules and severity levels.
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ cargo install repopilot
54
+ ```
55
+
56
+ Install with npm:
57
+
58
+ ```bash
59
+ npm install -g repopilot
60
+ ```
61
+
62
+ Upgrade:
63
+
64
+ ```bash
65
+ cargo install repopilot --force
66
+ npm update -g repopilot
67
+ ```
68
+
69
+ Build from source:
70
+
71
+ ```bash
72
+ git clone https://github.com/MykytaStel/repopilot.git
73
+ cd repopilot
74
+ cargo build --release
75
+ ```
76
+
77
+ ## Quick Start
78
+
79
+ ```bash
80
+ repopilot init
81
+ repopilot scan .
82
+ ```
83
+
84
+ React Native quick scan:
85
+
86
+ ```bash
87
+ repopilot scan . --format markdown --output repopilot-report.md
88
+ repopilot review . --base origin/main --baseline .repopilot/baseline.json --fail-on new-high
89
+ ```
90
+
91
+ ## Commands
92
+
93
+ | Command | Alias | Description |
94
+ |---------|-------|-------------|
95
+ | `repopilot scan <path>` | `s` | Scan a project, folder, or file for findings |
96
+ | `repopilot review [path]` | `r` | Review findings that touch changed Git diff lines |
97
+ | `repopilot compare <before> <after>` | `cmp` | Compare two JSON scan reports and show what changed |
98
+ | `repopilot baseline create <path>` | `bl` | Scan a path and store current findings as accepted debt |
99
+ | `repopilot init` | — | Generate a default `repopilot.toml` configuration file |
100
+
101
+ Use `--help` on any command for the full description and examples:
102
+
103
+ ```bash
104
+ repopilot --help
105
+ repopilot scan --help
106
+ repopilot review --help
107
+ repopilot baseline create --help
108
+ ```
109
+
110
+ ## Configuration
111
+
112
+ RepoPilot automatically reads `repopilot.toml` from the current working directory when running `scan`.
113
+
114
+ Configuration precedence:
115
+
116
+ ```text
117
+ CLI args > repopilot.toml > built-in defaults
118
+ ```
119
+
120
+ Generate a default config:
121
+
122
+ ```bash
123
+ repopilot init
124
+ repopilot init --force
125
+ repopilot init --path ./repopilot.toml
126
+ ```
127
+
128
+ Use an explicit config path:
129
+
130
+ ```bash
131
+ repopilot scan . --config repopilot.toml
132
+ ```
133
+
134
+ Example `repopilot.toml`:
135
+
136
+ ```toml
137
+ [scan]
138
+ ignore = [
139
+ ".git",
140
+ ".github",
141
+ ".repopilot",
142
+ "target",
143
+ "node_modules",
144
+ "dist",
145
+ "build",
146
+ ".next",
147
+ "coverage"
148
+ ]
149
+ max_file_bytes = 2097152
150
+
151
+ [architecture]
152
+ max_file_lines = 300
153
+ huge_file_lines = 1000
154
+ max_directory_modules = 20
155
+ max_directory_depth = 5
156
+ max_function_lines = 50
157
+ max_fan_out = 15
158
+ instability_hub_min_fan_in = 5
159
+ instability_hub_min_instability_pct = 75
160
+
161
+ [testing]
162
+ detect_missing_tests = true
163
+
164
+ [security]
165
+ detect_secret_like_names = true
166
+
167
+ [output]
168
+ default_format = "console"
169
+ ```
170
+
171
+ CLI threshold overrides:
172
+
173
+ ```bash
174
+ repopilot scan . --max-file-loc 500
175
+ repopilot scan . --max-directory-modules 25
176
+ repopilot scan . --max-directory-depth 6
177
+ ```
178
+
179
+ ## Baseline Workflow
180
+
181
+ Existing repositories often have findings that cannot all be fixed before adopting a new audit tool. A baseline stores accepted existing findings so future scans can distinguish new findings from existing ones.
182
+
183
+ ```bash
184
+ repopilot baseline create .
185
+ repopilot scan . --baseline .repopilot/baseline.json
186
+ repopilot scan . --baseline .repopilot/baseline.json --fail-on new-high
187
+ ```
188
+
189
+ By default, `baseline create` writes `.repopilot/baseline.json` and creates the `.repopilot/` directory if needed. Use `--output ./baseline.json` for a custom path. Existing baseline files are not overwritten unless you pass `--force`.
190
+
191
+ Baseline files store accepted existing findings. Future scans can mark findings as `new` or `existing`, which is useful for legacy repositories and CI. Do not refresh a baseline blindly unless the team accepts those findings as technical debt.
192
+
193
+ ## Review Workflow
194
+
195
+ Use `review` when you want RepoPilot to focus on findings that touch changed Git diff lines.
196
+
197
+ ```bash
198
+ repopilot review .
199
+ repopilot review . --format json --output review.json
200
+ repopilot review . --baseline .repopilot/baseline.json --fail-on new-high
201
+ ```
202
+
203
+ By default, `review` compares the working tree against `HEAD`, including staged, unstaged, and untracked files. For branch or CI review, pass a base ref:
204
+
205
+ ```bash
206
+ repopilot review . --base origin/main
207
+ repopilot review . --base origin/main --head HEAD --format markdown
208
+ ```
209
+
210
+ Review mode still scans the repository with the normal rules, but separates findings into in-diff and out-of-diff groups. When import coupling data is available, it also shows blast radius: files that import changed files and may need extra review. When `--fail-on` is used, the CI gate evaluates only in-diff findings.
211
+
212
+ ## Output Formats
213
+
214
+ ```bash
215
+ repopilot scan . --format console
216
+ repopilot scan . --format json --output report.json
217
+ repopilot scan . --format markdown --output report.md
218
+ repopilot scan . --format html --output report.html
219
+ repopilot scan . --format sarif --output repopilot.sarif
220
+ ```
221
+
222
+ ### SARIF output
223
+
224
+ ```bash
225
+ repopilot scan . --format sarif --output repopilot.sarif
226
+ ```
227
+
228
+ If your installed RepoPilot version does not support `--output`, redirect stdout instead:
229
+
230
+ ```bash
231
+ repopilot scan . --format sarif > repopilot.sarif
232
+ ```
233
+
234
+ Use JSON when custom scripts need to parse RepoPilot results. Use Markdown for human-readable reports. Use SARIF for CI and code scanning integrations, including GitHub Code Scanning.
235
+
236
+ See [docs/integrations/github-code-scanning.md](docs/integrations/github-code-scanning.md) for a copy-paste GitHub Actions workflow, required permissions, and local validation commands.
237
+
238
+ Compare two JSON reports:
239
+
240
+ ```bash
241
+ repopilot scan . --format json --output before.json
242
+ repopilot scan . --format json --output after.json
243
+ repopilot compare before.json after.json
244
+ repopilot compare before.json after.json --format markdown
245
+ repopilot compare before.json after.json --format json --output diff.json
246
+ ```
247
+
248
+ ## CI Usage
249
+
250
+ Use `--fail-on new-high` to fail CI only when new high or critical findings are introduced. Supported new-finding thresholds are `new-low`, `new-medium`, `new-high`, and `new-critical`.
251
+
252
+ When `--fail-on new-*` is used without `--baseline`, RepoPilot treats all current findings as new. For baseline-based adoption, commit an accepted baseline and scan against it in CI.
253
+
254
+ To upload RepoPilot findings to GitHub Code Scanning, generate SARIF and use `github/codeql-action/upload-sarif`. The workflow must include `security-events: write`.
255
+
256
+ ```yaml
257
+ name: RepoPilot
258
+
259
+ on:
260
+ pull_request:
261
+
262
+ jobs:
263
+ repopilot:
264
+ runs-on: ubuntu-latest
265
+
266
+ steps:
267
+ - uses: actions/checkout@v4
268
+
269
+ - name: Install Rust
270
+ uses: dtolnay/rust-toolchain@stable
271
+
272
+ - name: Install RepoPilot
273
+ run: cargo install repopilot
274
+
275
+ - name: Run RepoPilot
276
+ run: repopilot scan . --baseline .repopilot/baseline.json --fail-on new-high
277
+
278
+ - name: Run RepoPilot (SARIF)
279
+ run: repopilot scan . --format sarif --output repopilot.sarif
280
+
281
+ - name: Upload to GitHub Code Scanning
282
+ uses: github/codeql-action/upload-sarif@v3
283
+ if: always()
284
+ with:
285
+ sarif_file: repopilot.sarif
286
+ ```
287
+
288
+ ## Roadmap
289
+
290
+ These are planned ideas, not current features:
291
+
292
+ - Change Risk Map
293
+ - AI-ready review context export
294
+ - Better architecture drift detection
295
+ - First-party GitHub Action integration
296
+ - Deeper React Native dependency health analysis
297
+
298
+ ## Documentation
299
+
300
+ | Document | Description |
301
+ |---|---|
302
+ | [docs/cli.md](docs/cli.md) | Complete CLI reference — all commands, flags, and exit codes |
303
+ | [docs/commands.md](docs/commands.md) | Task-oriented command guide and common patterns |
304
+ | [docs/rulesets.md](docs/rulesets.md) | Implemented audit rules, categories, and severity levels |
305
+ | [docs/react-native.md](docs/react-native.md) | React Native and Expo detection, findings, and limitations |
306
+ | [docs/integrations/github-code-scanning.md](docs/integrations/github-code-scanning.md) | GitHub Code Scanning SARIF workflow |
307
+ | [docs/release.md](docs/release.md) | Manual release process |
308
+ | [docs/distribution.md](docs/distribution.md) | Distribution channels |
309
+ | [docs/github-ruleset.md](docs/github-ruleset.md) | GitHub branch ruleset configuration |
310
+ | [CHANGELOG.md](CHANGELOG.md) | Version history |
311
+
312
+ ## License
313
+
314
+ RepoPilot is licensed under MIT OR Apache-2.0.
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("node:fs");
4
+ const path = require("node:path");
5
+ const { spawn } = require("node:child_process");
6
+
7
+ function binaryName() {
8
+ return process.platform === "win32" ? "repopilot.exe" : "repopilot";
9
+ }
10
+
11
+ function bundledBinaryPath() {
12
+ return path.join(__dirname, "..", "vendor", binaryName());
13
+ }
14
+
15
+ function resolveBinaryPath() {
16
+ if (process.env.REPOPILOT_BINARY_PATH) {
17
+ return process.env.REPOPILOT_BINARY_PATH;
18
+ }
19
+ return bundledBinaryPath();
20
+ }
21
+
22
+ function main() {
23
+ const binary = resolveBinaryPath();
24
+ if (!fs.existsSync(binary)) {
25
+ console.error(
26
+ [
27
+ "RepoPilot binary was not found.",
28
+ `Expected: ${binary}`,
29
+ "Run npm install again, install with cargo, or set REPOPILOT_BINARY_PATH to an existing repopilot binary.",
30
+ ].join("\n")
31
+ );
32
+ process.exit(1);
33
+ }
34
+
35
+ const child = spawn(binary, process.argv.slice(2), {
36
+ stdio: "inherit",
37
+ windowsHide: false,
38
+ });
39
+
40
+ child.on("error", (error) => {
41
+ console.error(`Failed to launch RepoPilot: ${error.message}`);
42
+ process.exit(1);
43
+ });
44
+ child.on("exit", (code, signal) => {
45
+ if (signal) {
46
+ process.kill(process.pid, signal);
47
+ return;
48
+ }
49
+ process.exit(code ?? 1);
50
+ });
51
+ }
52
+
53
+ if (require.main === module) {
54
+ main();
55
+ }
56
+
57
+ module.exports = {
58
+ binaryName,
59
+ bundledBinaryPath,
60
+ resolveBinaryPath,
61
+ };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "repopilot",
3
+ "version": "0.6.0",
4
+ "description": "Local-first CLI for repository audit, architecture risk detection, baseline tracking, and CI-friendly code review.",
5
+ "license": "MIT OR Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/MykytaStel/repopilot.git"
9
+ },
10
+ "homepage": "https://github.com/MykytaStel/repopilot#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/MykytaStel/repopilot/issues"
13
+ },
14
+ "bin": {
15
+ "repopilot": "bin/repopilot.js"
16
+ },
17
+ "scripts": {
18
+ "postinstall": "node scripts/install.js",
19
+ "test:npm": "node --test tests/npm_wrapper.test.js"
20
+ },
21
+ "files": [
22
+ "bin",
23
+ "scripts",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "keywords": [
28
+ "cli",
29
+ "audit",
30
+ "code-review",
31
+ "static-analysis",
32
+ "architecture",
33
+ "react-native"
34
+ ],
35
+ "engines": {
36
+ "node": ">=18"
37
+ }
38
+ }
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+
3
+ const crypto = require("node:crypto");
4
+ const fs = require("node:fs");
5
+ const https = require("node:https");
6
+ const os = require("node:os");
7
+ const path = require("node:path");
8
+ const { spawnSync } = require("node:child_process");
9
+
10
+ const ROOT = path.join(__dirname, "..");
11
+ const VENDOR_DIR = path.join(ROOT, "vendor");
12
+ const PACKAGE_JSON = require(path.join(ROOT, "package.json"));
13
+
14
+ function targetTriple(platform = process.platform, arch = process.arch) {
15
+ if (platform === "darwin" && arch === "x64") return "x86_64-apple-darwin";
16
+ if (platform === "darwin" && arch === "arm64") return "aarch64-apple-darwin";
17
+ if (platform === "linux" && arch === "x64") return "x86_64-unknown-linux-gnu";
18
+ if (platform === "linux" && arch === "arm64") return "aarch64-unknown-linux-gnu";
19
+ if (platform === "win32" && arch === "x64") return "x86_64-pc-windows-msvc";
20
+ throw new Error(`Unsupported platform: ${platform}/${arch}`);
21
+ }
22
+
23
+ function archiveExt(target) {
24
+ return target.endsWith("windows-msvc") ? "zip" : "tar.gz";
25
+ }
26
+
27
+ function assetName(version, target) {
28
+ return `repopilot-v${version}-${target}.${archiveExt(target)}`;
29
+ }
30
+
31
+ function releaseUrl(version, file) {
32
+ return `https://github.com/MykytaStel/repopilot/releases/download/v${version}/${file}`;
33
+ }
34
+
35
+ function download(url, destination) {
36
+ return new Promise((resolve, reject) => {
37
+ const file = fs.createWriteStream(destination);
38
+ https
39
+ .get(url, (response) => {
40
+ if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
41
+ file.close();
42
+ fs.rmSync(destination, { force: true });
43
+ download(response.headers.location, destination).then(resolve, reject);
44
+ return;
45
+ }
46
+ if (response.statusCode !== 200) {
47
+ file.close();
48
+ fs.rmSync(destination, { force: true });
49
+ reject(new Error(`Download failed (${response.statusCode}): ${url}`));
50
+ return;
51
+ }
52
+ response.pipe(file);
53
+ file.on("finish", () => file.close(resolve));
54
+ })
55
+ .on("error", (error) => {
56
+ file.close();
57
+ fs.rmSync(destination, { force: true });
58
+ reject(error);
59
+ });
60
+ });
61
+ }
62
+
63
+ function sha256(file) {
64
+ const hash = crypto.createHash("sha256");
65
+ hash.update(fs.readFileSync(file));
66
+ return hash.digest("hex");
67
+ }
68
+
69
+ function expectedChecksum(checksumText) {
70
+ const first = checksumText.trim().split(/\s+/)[0];
71
+ if (!/^[a-fA-F0-9]{64}$/.test(first)) {
72
+ throw new Error("Invalid checksum file format");
73
+ }
74
+ return first.toLowerCase();
75
+ }
76
+
77
+ function verifyChecksum(archivePath, checksumText) {
78
+ const expected = expectedChecksum(checksumText);
79
+ const actual = sha256(archivePath);
80
+ if (actual !== expected) {
81
+ throw new Error(`Checksum mismatch for ${path.basename(archivePath)}: expected ${expected}, got ${actual}`);
82
+ }
83
+ }
84
+
85
+ function extractArchive(archivePath, destination, target) {
86
+ fs.rmSync(destination, { recursive: true, force: true });
87
+ fs.mkdirSync(destination, { recursive: true });
88
+
89
+ const result = target.endsWith("windows-msvc")
90
+ ? spawnSync("powershell", ["-NoProfile", "-Command", `Expand-Archive -Force '${archivePath}' '${destination}'`], { stdio: "inherit" })
91
+ : spawnSync("tar", ["-xzf", archivePath, "-C", destination], { stdio: "inherit" });
92
+
93
+ if (result.status !== 0) {
94
+ throw new Error(`Failed to extract ${archivePath}`);
95
+ }
96
+ }
97
+
98
+ async function install() {
99
+ if (process.env.REPOPILOT_SKIP_DOWNLOAD === "1" || process.env.REPOPILOT_SKIP_DOWNLOAD === "true") {
100
+ console.log("Skipping RepoPilot binary download because REPOPILOT_SKIP_DOWNLOAD is set.");
101
+ return;
102
+ }
103
+
104
+ const target = targetTriple();
105
+ const version = PACKAGE_JSON.version;
106
+ const archive = assetName(version, target);
107
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "repopilot-"));
108
+ const archivePath = path.join(tmp, archive);
109
+ const checksumPath = `${archivePath}.sha256`;
110
+ const extractDir = path.join(tmp, "extract");
111
+ const binaryName = target.endsWith("windows-msvc") ? "repopilot.exe" : "repopilot";
112
+
113
+ try {
114
+ await download(releaseUrl(version, archive), archivePath);
115
+ await download(releaseUrl(version, `${archive}.sha256`), checksumPath);
116
+ verifyChecksum(archivePath, fs.readFileSync(checksumPath, "utf8"));
117
+ extractArchive(archivePath, extractDir, target);
118
+
119
+ fs.mkdirSync(VENDOR_DIR, { recursive: true });
120
+ fs.copyFileSync(path.join(extractDir, binaryName), path.join(VENDOR_DIR, binaryName));
121
+ fs.chmodSync(path.join(VENDOR_DIR, binaryName), 0o755);
122
+ } finally {
123
+ fs.rmSync(tmp, { recursive: true, force: true });
124
+ }
125
+ }
126
+
127
+ if (require.main === module) {
128
+ install().catch((error) => {
129
+ console.error(`Failed to install RepoPilot binary: ${error.message}`);
130
+ console.error("Set REPOPILOT_SKIP_DOWNLOAD=1 to skip download or REPOPILOT_BINARY_PATH to use an existing binary.");
131
+ process.exit(1);
132
+ });
133
+ }
134
+
135
+ module.exports = {
136
+ archiveExt,
137
+ assetName,
138
+ expectedChecksum,
139
+ targetTriple,
140
+ verifyChecksum,
141
+ };