@hivemagnus/hive-devtools 0.0.0-stage → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@hivemagnus/hive-devtools` are recorded here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ First version, 0.1.0; it is published by hand once (see the README).
10
+
11
+ ### Added
12
+
13
+ - `hive-check-private-data`, `hive-scan-secrets` and the `./privacy-policy` export: the
14
+ forbidden-path, private-terms and secret scans the suite repositories copied, from the most
15
+ recent copy, with `--root`, `--terms-file`, `--forbid-dir`, `--allow`, `--secret-name`,
16
+ `--allow-home-user` and `--exclude GLOB` for what the copies hard-coded. `.cindertrace/` is
17
+ forbidden by default next to `.ardent/` and `.magnus/`. A path that contains a private term is
18
+ printed as `(path redacted)`,
19
+ and a missing `--message` file exits 2 instead of passing.
20
+ - `hive-gitleaks` and `hive-install-gitleaks`: the pinned Gitleaks 8.30.1 wrapper and installer,
21
+ with `--root`, `--config` and `--dir PATH...` (scans build output).
22
+ - `hive-check-node-runtime` and the `./node-runtime` export, with `--package FILE` for
23
+ repositories whose package.json is in a subdirectory; the library still streams over SSH.
24
+ - `hive-check-action-pins` and the `./action-pins` export: actions, reusable workflows and
25
+ container images must be pinned by commit SHA or digest; `--require-version-comment`.
26
+ - `hive-check-publish-environment` (`--environment NAME`), `hive-publish-package`
27
+ (`--name`, `--tag-prefix`) and the `./publish` export.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,11 @@
1
+ HiveDevtools (@hivemagnus/hive-devtools)
2
+ Copyright 2026 ChefTaco and contributors
3
+
4
+ This product includes software developed by ChefTaco and contributors
5
+ (https://github.com/ChefTaco/HiveCommon).
6
+
7
+ The privacy, secret-scanning, Gitleaks, Node runtime and release scripts consolidate the copies
8
+ kept in the Hive:Magnus product repositories, licensed under the Apache License 2.0.
9
+
10
+ It runs Gitleaks (https://github.com/gitleaks/gitleaks), licensed under the MIT License, which
11
+ hive-install-gitleaks downloads and verifies by checksum; Gitleaks is not bundled.
package/README.md CHANGED
@@ -1,3 +1,304 @@
1
- # Temporary Holding Version
1
+ # @hivemagnus/hive-devtools
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared development tooling for the Hive:Magnus suite repositories. It replaces the release and
4
+ privacy scripts that each product used to copy into its own `scripts/` directory, and that had
5
+ drifted apart:
6
+
7
+ - privacy scans: forbidden paths, the local private-terms denylist, credentials and private
8
+ infrastructure, with findings that never print the matching text;
9
+ - the pinned, checksum-verified Gitleaks wrapper and installer;
10
+ - the Node.js runtime preflight (also streamable to a host before a deployment);
11
+ - a GitHub Actions pin check;
12
+ - npm release helpers for trusted publishing (environment protection check and publish).
13
+
14
+ It also comes with reusable GitHub workflows in this repository's
15
+ [`.github/workflows`](../.github/workflows) directory.
16
+
17
+ This package lives in the HiveCommon repository but is **not** part of the runtime kit:
18
+ `@hivemagnus/hive-common` does not depend on it and its tarball does not contain it
19
+ (`scripts/test-devtools-boundary.mjs` checks both). Install it as a dev dependency only. It has
20
+ no runtime dependencies and needs Node.js 24.22.3+ or 26.13.1+, bash and git; it runs on Linux
21
+ and macOS.
22
+
23
+ ## Commands
24
+
25
+ | Command | Replaces | What it does |
26
+ | --- | --- | --- |
27
+ | `hive-check-private-data` | `scripts/check-private-data.sh` | Forbidden paths and private terms in tracked files, the index (`--staged`) or a commit message (`--message FILE`) |
28
+ | `hive-scan-secrets` | `scripts/scan-secrets.sh`, `scan-secrets.mjs`, `privacy-policy.mjs` | Provider tokens, private keys, literal credentials, private network domains and personal home paths in working and staged files |
29
+ | `hive-gitleaks` | `scripts/gitleaks.sh` | Gitleaks 8.30.1 on the exact index (`--staged`), all history (`--history`), outgoing refs (`--pre-push`) or directories (`--dir`) |
30
+ | `hive-install-gitleaks` | `scripts/install-gitleaks.sh` | Downloads and checksum-verifies Gitleaks 8.30.1 into `~/.cache/hivemagnus-tools` (no sudo) |
31
+ | `hive-check-node-runtime` | `scripts/check-node-runtime.mjs` | Fails unless the running Node satisfies `engines.node` (`^X.Y.Z \|\| ^X.Y.Z` ranges only) |
32
+ | `hive-check-action-pins` | `workflow-pins.test.mjs` | Fails when a workflow or action uses an action, reusable workflow or image by tag instead of SHA or digest |
33
+ | `hive-check-publish-environment` | `scripts/check-publish-environment.mjs` | Fails unless the GitHub publication environment has a required reviewer |
34
+ | `hive-publish-package` | `scripts/publish-package.mjs` | `npm publish --provenance` from the matching tag when the version is not on npm yet |
35
+
36
+ Every scanner resolves the repository from the current directory (`git rev-parse
37
+ --show-toplevel`), so the commands work from any subdirectory; pass `--root DIR` to name it.
38
+
39
+ ### hive-check-private-data
40
+
41
+ ```text
42
+ hive-check-private-data [--root DIR] [--terms-file FILE] [--forbid-dir NAME]... [--allow REGEX]... [--staged | --message FILE]
43
+ ```
44
+
45
+ - Forbidden paths: `.env` and `.env.*` (except `.env.example`), `.npmrc`, keys, certificates,
46
+ databases and their `-wal`/`-shm`/`-journal` files, git bundles, `*.local.md`,
47
+ `.private-terms`, `.vscode/mcp.json`, and anything inside a directory named `certs`,
48
+ `backups`, `state`, `artifacts`, `.ardent`, `.magnus`, `.cindertrace`, `.hive-dev`, `.ssh`,
49
+ `audit-logs` or `terminal-audit`.
50
+ - `--forbid-dir NAME` adds a directory name (for example `output`); `--allow REGEX` exempts
51
+ paths that match an extended regex (for example `^test/fixtures/state/`).
52
+ - Private terms: `<root>/.private-terms` (or `--terms-file`), gitignored, one case-insensitive
53
+ extended regex per line; `#` comments and blank lines are ignored. A missing file skips this
54
+ layer. Findings print `file:line [redacted]`; a path that itself contains a term prints as
55
+ `(path redacted)`. An invalid regex exits 2.
56
+
57
+ ### hive-scan-secrets
58
+
59
+ ```text
60
+ hive-scan-secrets [--staged] [--root DIR] [--secret-name NAME]... [--allow-home-user NAME]... [--exclude GLOB]...
61
+ ```
62
+
63
+ Without `--staged` it scans tracked and untracked, non-ignored files, and then the index, so a
64
+ sanitized working copy cannot hide a staged secret. Rules: OpenAI, npm, GitHub and Slack tokens,
65
+ AWS access keys, private-key headers, and literal values of credential variables
66
+ (`DEPLOY_PASSWORD`, `SSH_PASSWORD`, `IAM_AGENT_SECRET`, `HIVE_ROUTER_SECRET`,
67
+ `HIVEMEM_JWT_SECRET`, `API_SECRET`, `JWT_SECRET`, `SESSION_SECRET`, `NODE_MANAGER_SECRET`,
68
+ `AWS_SECRET_ACCESS_KEY`; add more with `--secret-name`; names ending in `PASSWORD` need 8
69
+ characters, others 16). Explicit placeholders (`replace-...`, `change-me-...`, `...-example-...`,
70
+ `${...}`, `<...>`) and expressions (`process.env.X`) are not findings. It also reports private
71
+ network domain names and `/home/<name>` or `/Users/<name>` paths other than `operator`, `deploy`, `user`, `x`,
72
+ `foo` and `bar` (add more with `--allow-home-user`). `--exclude` takes a glob of repository-relative
73
+ paths (`fixtures/**`, `**/*.snap`).
74
+
75
+ ### hive-gitleaks and hive-install-gitleaks
76
+
77
+ ```text
78
+ hive-gitleaks [--root DIR] [--config FILE] --staged | --history | --pre-push | --dir PATH...
79
+ ```
80
+
81
+ The config defaults to `.gitleaks.toml` at the root and must be inside the repository; each
82
+ repository keeps its own config and allowlists. `--staged` exports the exact index (including
83
+ force-added ignored files) and uses the staged config. `--pre-push` reads the hook's stdin and
84
+ scans each outgoing range, or all reachable history for a new ref or an unknown remote base.
85
+ `--history` and `--pre-push` refuse a shallow clone. `--dir` scans directories such as build
86
+ output (paths relative to the root). Matches are redacted, inline `gitleaks:allow` comments are
87
+ ignored, and a missing or different Gitleaks version exits 2 instead of skipping. A machine that
88
+ already ran an older copy of `install-gitleaks.sh` shares the same cache.
89
+
90
+ ### hive-check-node-runtime
91
+
92
+ ```text
93
+ hive-check-node-runtime [--package FILE] | --engines RANGE | --print-range [--package FILE]
94
+ ```
95
+
96
+ `--package` defaults to `./package.json`. To check a host before a deployment writes anything,
97
+ stream the library on its own; it imports only Node built-ins:
98
+
99
+ ```bash
100
+ range="$(npx --no-install hive-check-node-runtime --print-range)"
101
+ ssh deploy@node.example.com "node --input-type=module - --engines '$range'" \
102
+ < node_modules/@hivemagnus/hive-devtools/lib/node-runtime.mjs
103
+ ```
104
+
105
+ ### hive-check-action-pins
106
+
107
+ ```text
108
+ hive-check-action-pins [--root DIR] [--path PATH]... [--require-version-comment]
109
+ ```
110
+
111
+ Checks `.github/workflows`, `.github/actions` and a root `action.yml`. Accepted: `owner/repo[/path]@<40-hex SHA>`,
112
+ `docker://image@sha256:<digest>` and local `./` references. A `uses:` line it cannot parse is
113
+ a finding. `--require-version-comment` also requires a comment such as `# v7.0.1` or
114
+ `# hive-devtools-v0.1.0` after each SHA.
115
+
116
+ ### hive-check-publish-environment and hive-publish-package
117
+
118
+ ```text
119
+ GH_TOKEN=... hive-check-publish-environment [--environment NAME]
120
+ DRY_RUN=true|false hive-publish-package [--root DIR] [--name NAME] [--tag-prefix PREFIX]
121
+ ```
122
+
123
+ The environment check reads `GITHUB_REPOSITORY` and needs a token with `actions: read`; it sends
124
+ the token only to `api.github.com` and fails unless a user or team is a required reviewer of
125
+ the environment (default `npm-publish`). The publisher refuses a private package, a package
126
+ whose name differs from `--name`, or a real run whose `GITHUB_REF` is not
127
+ `refs/tags/<prefix><version>` (default prefix `v`); it skips a version already on npm and
128
+ stops on any registry error. It never runs lifecycle scripts.
129
+
130
+ ## Library
131
+
132
+ The same rules are importable, for repository-specific tests:
133
+
134
+ | Export | Functions |
135
+ | --- | --- |
136
+ | `@hivemagnus/hive-devtools/privacy-policy` | `forbiddenPath()`, `forbiddenPathMatcher()`, `secretFindings()`, `privateInfrastructureFindings()`, `DEFAULT_FORBIDDEN_DIRS`, `DEFAULT_SECRET_NAMES`, `DEFAULT_HOME_USERS` |
137
+ | `@hivemagnus/hive-devtools/node-runtime` | `assertNodeVersion()`, `packageNodeRange()`, `runNodeRuntimeCheck()` |
138
+ | `@hivemagnus/hive-devtools/action-pins` | `actionPinFindings()`, `workflowFiles()`, `checkActionPins()` |
139
+ | `@hivemagnus/hive-devtools/publish` | `assertPublishEnvironment()`, `checkPublishEnvironment()`, `readReleasePackage()`, `publishedVersionExists()`, `publishPackage()` |
140
+
141
+ ## Reusable workflows
142
+
143
+ Call them by full commit SHA (a tag can be moved) and pass the same SHA as `devtools-ref`, which
144
+ selects the `tooling/` scripts the workflow runs. Each job runs with `contents: read` only.
145
+
146
+ | Workflow | Inputs (default) |
147
+ | --- | --- |
148
+ | `reusable-node-verify.yml` | `node-versions` (`["24.22.3", "26.13.1"]`), `working-directory` (`.`), `install-command` (`npm ci`), `verify-command` (`npm test`), `audit` (`true`), `audit-level` (`high`), `fetch-depth` (`1`), `runs-on` (`ubuntu-24.04`), `timeout-minutes` (`30`) |
149
+ | `reusable-privacy.yml` | `devtools-ref` (required), `forbid-dirs` (space-separated), `allow-paths` (one regex per line), `secret-names` (space-separated), `exclude-paths` (one glob per line), `check-commit-messages` (`true`), `runs-on`; secret `private-terms` (optional) |
150
+ | `reusable-gitleaks.yml` | `devtools-ref` (required), `config` (`.gitleaks.toml`), `build-command` and `scan-dirs` (optional build-output scan), `runs-on` |
151
+ | `reusable-action-pins.yml` | `devtools-ref` (required), `require-version-comment` (`true`), `runs-on` |
152
+
153
+ `reusable-node-verify.yml` needs no `devtools-ref`: it runs only the caller's own commands.
154
+ `reusable-privacy.yml` writes the optional `private-terms` secret (a repository or organization
155
+ secret holding the `.private-terms` lines) to a private temporary file, checks tracked files and
156
+ the commit messages of the pushed or pull-request range, and deletes the file. Nothing it finds
157
+ prints the term.
158
+
159
+ ```yaml
160
+ # .github/workflows/hygiene.yml in a product repository
161
+ name: Hygiene
162
+ on:
163
+ pull_request:
164
+ push:
165
+ branches: [main]
166
+ permissions:
167
+ contents: read
168
+ jobs:
169
+ verify:
170
+ uses: ChefTaco/HiveCommon/.github/workflows/reusable-node-verify.yml@<sha> # hive-devtools-v0.1.0
171
+ with:
172
+ verify-command: npm run verify
173
+ privacy:
174
+ uses: ChefTaco/HiveCommon/.github/workflows/reusable-privacy.yml@<sha> # hive-devtools-v0.1.0
175
+ with:
176
+ devtools-ref: <sha>
177
+ forbid-dirs: output
178
+ secrets:
179
+ private-terms: ${{ secrets.PRIVATE_TERMS }}
180
+ gitleaks:
181
+ uses: ChefTaco/HiveCommon/.github/workflows/reusable-gitleaks.yml@<sha> # hive-devtools-v0.1.0
182
+ with:
183
+ devtools-ref: <sha>
184
+ action-pins:
185
+ uses: ChefTaco/HiveCommon/.github/workflows/reusable-action-pins.yml@<sha> # hive-devtools-v0.1.0
186
+ with:
187
+ devtools-ref: <sha>
188
+ ```
189
+
190
+ ## Adopting it in a repository
191
+
192
+ The reusable workflows work as soon as they are on `main`; the commands need the package on npm.
193
+
194
+ 1. Add the exact version as a dev dependency: `npm install --save-dev --save-exact @hivemagnus/hive-devtools@0.1.0`.
195
+ 2. Point the package scripts at the commands, keeping the repository's own options:
196
+
197
+ ```json
198
+ "scan:secrets": "hive-scan-secrets",
199
+ "check:private": "hive-check-private-data",
200
+ "check:node": "hive-check-node-runtime",
201
+ "check:pins": "hive-check-action-pins --require-version-comment",
202
+ "gitleaks:install": "hive-install-gitleaks"
203
+ ```
204
+
205
+ 3. Call the commands from the git hooks through `node_modules/.bin`, so a missing install fails
206
+ the hook instead of fetching anything:
207
+
208
+ ```bash
209
+ # .githooks/pre-commit
210
+ set -euo pipefail
211
+ bin="$(git rev-parse --show-toplevel)/node_modules/.bin"
212
+ "$bin/hive-check-private-data" --staged
213
+ "$bin/hive-scan-secrets"
214
+ "$bin/hive-gitleaks" --staged
215
+ # .githooks/commit-msg: "$bin/hive-check-private-data" --message "$1"
216
+ # .githooks/pre-push: "$bin/hive-check-private-data"; "$bin/hive-gitleaks" --pre-push (stdin), then
217
+ # "$bin/hive-check-private-data" --message for each outgoing range
218
+ ```
219
+
220
+ 4. Replace the copied CI jobs with the reusable workflows above.
221
+ 5. Delete the copied scripts and their tests (`check-private-data.sh`, `scan-secrets.*`,
222
+ `privacy-policy.mjs`, `gitleaks.sh`, `install-gitleaks.sh`, `check-node-runtime.mjs`,
223
+ `check-publish-environment.mjs`, `publish-package.mjs`, `workflow-pins.test.mjs`). Keep the
224
+ repository's `.gitleaks.toml` and any test that covers repository-specific allowlists.
225
+ 6. Run every gate once (`npm run verify` or equivalent) and the hooks on a test commit.
226
+
227
+ Repository-specific options that the copies hard-coded:
228
+
229
+ | Repository pattern | Option |
230
+ | --- | --- |
231
+ | An extra state directory (for example `output/`) | `hive-check-private-data --forbid-dir output`; workflow `forbid-dirs: output` |
232
+ | A tracked fixture inside a forbidden directory | `--allow '^test/fixtures/state/'`; workflow `allow-paths` |
233
+ | `package.json` in a subdirectory (`ts-core/`, `apps/<name>/`) | `hive-check-node-runtime --package ts-core/package.json` |
234
+ | Build output scanned by Gitleaks (`--artifacts`) | `hive-gitleaks --dir packages/a/dist services/b/dist`; workflow `build-command` + `scan-dirs` |
235
+ | Extra credential variables | `hive-scan-secrets --secret-name PRODUCT_ADMIN_TOKEN` |
236
+ | Release tags other than `vX.Y.Z` | `hive-publish-package --tag-prefix product-v` |
237
+
238
+ Older copies of `check-private-data.sh` and `scan-secrets.sh` print the matching line, so a
239
+ private term or a secret value can reach a CI log. The commands here print only the file, line
240
+ and rule, so adopting them also removes that exposure.
241
+
242
+ ## Versioning and releases
243
+
244
+ The package follows Semantic Versioning: a new rule that can fail an existing repository, a
245
+ changed default or a Gitleaks upgrade is a minor version before 1.0 and a major one after it,
246
+ and is listed in [CHANGELOG.md](CHANGELOG.md). Releases publish from a `hive-devtools-vX.Y.Z`
247
+ tag that matches `tooling/package.json` through
248
+ [`.github/workflows/publish-devtools.yml`](../.github/workflows/publish-devtools.yml), which
249
+ waits for approval on the `npm-publish` environment and authenticates with npm trusted
250
+ publishing (OIDC) with provenance. The `vX.Y.Z` tags stay reserved for `@hivemagnus/hive-common`.
251
+
252
+ ### First publication (owner, once)
253
+
254
+ npm can only attach a trusted publisher to a package that exists, so the owner publishes the
255
+ first version by hand and then hands publication to the workflow:
256
+
257
+ 1. From a clean checkout of `main`:
258
+
259
+ ```bash
260
+ cd tooling
261
+ npm ci
262
+ npm run test:ci
263
+ npm pack --dry-run
264
+ ```
265
+
266
+ 2. Sign in to npm as an owner of the `@hivemagnus` scope (with two-factor authentication) and
267
+ publish the first version without provenance (provenance needs CI):
268
+
269
+ ```bash
270
+ npm login
271
+ npm publish --access public
272
+ ```
273
+
274
+ 3. On npmjs.com, open `@hivemagnus/hive-devtools` > **Settings** > **Trusted publishing**, choose
275
+ **GitHub Actions**, and enter organization or user `ChefTaco`, repository `HiveCommon`,
276
+ workflow filename `publish-devtools.yml` and environment `npm-publish`.
277
+ 4. On the same page, under **Publishing access**, choose **Require two-factor authentication and
278
+ disallow tokens**.
279
+ 5. In GitHub, **Settings** > **Environments** > `npm-publish` > **Deployment branches and tags**,
280
+ add the tag rule `hive-devtools-v*` next to the existing `v*` rule. Without it the publish job
281
+ is refused before it starts.
282
+ 6. Tag the published commit so the history records it:
283
+ `git tag hive-devtools-v0.1.0 <commit> && git push origin hive-devtools-v0.1.0`. The workflow
284
+ runs, finds 0.1.0 already on npm and skips publishing; approve the environment when asked.
285
+
286
+ Later releases: bump `version` in `tooling/package.json` and add a CHANGELOG section in a pull
287
+ request, merge it, then push the tag `hive-devtools-vX.Y.Z` on that commit and approve the
288
+ `npm-publish` environment.
289
+
290
+ ## Development
291
+
292
+ ```bash
293
+ cd tooling
294
+ npm test # unit and integration tests; the Gitleaks test is skipped without the pinned binary
295
+ npm run test:ci # installs Gitleaks 8.30.1 first and requires that test (what CI runs)
296
+ ```
297
+
298
+ The `Devtools` workflow runs `npm run test:ci` on Node 24 and 26 through
299
+ `reusable-node-verify.yml` and calls the other reusable workflows on this repository at the
300
+ pull request's commit, as a product would.
301
+
302
+ ## License
303
+
304
+ Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ // hive-check-action-pins [--root DIR] [--path PATH]... [--require-version-comment]
3
+ // Fails when a workflow or action uses a third-party action, reusable workflow or container
4
+ // image by a movable tag instead of a commit SHA or image digest. See lib/action-pins.mjs.
5
+ import { resolve } from 'node:path';
6
+ import { checkActionPins } from '../lib/action-pins.mjs';
7
+
8
+ const USAGE = 'Usage: hive-check-action-pins [--root DIR] [--path PATH]... [--require-version-comment]';
9
+ try {
10
+ const args = process.argv.slice(2);
11
+ let root = process.cwd();
12
+ const paths = [];
13
+ let requireVersionComment = false;
14
+ for (let index = 0; index < args.length; index++) {
15
+ const next = () => { const value = args[++index]; if (!value) throw new Error(USAGE); return value; };
16
+ if (args[index] === '--root') root = resolve(next());
17
+ else if (args[index] === '--path') paths.push(next());
18
+ else if (args[index] === '--require-version-comment') requireVersionComment = true;
19
+ else throw new Error(USAGE);
20
+ }
21
+ const { files, findings } = checkActionPins(root, { requireVersionComment, ...(paths.length ? { paths } : {}) });
22
+ for (const finding of findings) console.error(`${finding.file}:${finding.line}: ${finding.rule}: ${finding.uses}`);
23
+ if (findings.length) {
24
+ console.error(`${findings.length} unpinned reference(s). Pin each to a full commit SHA (with a # vX.Y.Z comment) or an image digest.`);
25
+ process.exitCode = 1;
26
+ } else console.log(`Action pins check passed (${files} file(s)).`);
27
+ } catch (error) { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 2; }
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ // hive-check-node-runtime [--package FILE] | --engines RANGE | --print-range [--package FILE]
3
+ // See lib/node-runtime.mjs, which can also be streamed to a remote host on its own.
4
+ import { runNodeRuntimeCheck } from '../lib/node-runtime.mjs';
5
+
6
+ try {
7
+ const range = runNodeRuntimeCheck(process.argv.slice(2));
8
+ if (range !== undefined) console.log(range);
9
+ } catch (error) { console.error(error.message); process.exitCode = 1; }