@srobroek/harness-kit 0.0.0-stage → 1.0.1

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,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/README.md CHANGED
@@ -1,3 +1,163 @@
1
- # Temporary Holding Version
1
+ # harness-kit
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 build tooling for repos that ship agent plugins to OpenCode, Claude Code and OMP. A plugin repo keeps its plugins in `plugins/<name>/`; harness-kit generates the per-harness manifests, marketplaces, copies of shared content and inventories from them, and checks that the generated files are current.
4
+
5
+ The package is `@srobroek/harness-kit`. It ships TypeScript source that runs under [bun](https://bun.sh), with no build step.
6
+
7
+ ## Install
8
+
9
+ Pin the exact version, as a dev dependency:
10
+
11
+ ```sh
12
+ npm install --save-dev --save-exact @srobroek/harness-kit
13
+ ```
14
+
15
+ ```json
16
+ { "devDependencies": { "@srobroek/harness-kit": "1.0.0" } }
17
+ ```
18
+
19
+ bun must be on `PATH`, because the `harness-kit` bin has a bun shebang. `npm ci` and `bun install` both install it.
20
+
21
+ ## Config
22
+
23
+ `harness-kit.json` sits at the repo root. The CLI finds it by walking up from the current directory, or takes `--root <dir>`. An unknown key or a bad value fails with an error that names the field.
24
+
25
+ ```json
26
+ {
27
+ "marketplace": {
28
+ "name": "my-plugins",
29
+ "description": "Agent plugins for OpenCode, Claude Code and OMP.",
30
+ "owner": { "name": "Your Name" }
31
+ },
32
+ "harnesses": ["opencode", "claude", "omp"],
33
+ "commonDirs": ["skills", "rules"],
34
+ "kinds": ["skills", "agents", "commands", "rules", "hooks", "tools", "extensions", "mcp"],
35
+ "claude": { "strict": true }
36
+ }
37
+ ```
38
+
39
+ | Key | Default | Meaning |
40
+ | --- | --- | --- |
41
+ | `marketplace.name`, `.description`, `.owner.name` | required | Written to the Claude and OMP marketplace files. |
42
+ | `harnesses` | all three | Harnesses the repo targets. A plugin may list only these. Claude and OMP each get a marketplace file; OpenCode has none. |
43
+ | `commonDirs` | `skills`, `rules` | Directories under `plugins/<name>/common/` copied into each harness tree. Add `templates`, `scripts` or `formulas` as needed. |
44
+ | `kinds` | the eight kinds without `templates` and `styles` | Rows of the inventory tables and keys of `inventory.json`. Any of `skills agents commands rules templates styles hooks tools extensions mcp`. |
45
+ | `pluginKey` | `agent-plugins` | Key in each plugin's `package.json` that holds its settings. |
46
+ | `ompScope` | `@agent-plugins` | npm scope of the generated OMP package name. |
47
+ | `generatedBy` | `harness-kit build` | Names the generator in the note at the top of generated Markdown. |
48
+ | `claude.strict` | `true` | `validate-claude` passes `--strict` to `claude plugin validate`. |
49
+ | `claude.author`, `claude.license` | none | Written to a Claude manifest whose `package.json` sets no `author` or `license`. |
50
+ | `omp.packageType` | none | `"module"` or `"commonjs"`: adds `type` to the generated OMP `package.json`. |
51
+
52
+ ### Plugin settings
53
+
54
+ Each plugin's `package.json` carries `name` (equal to the directory), `version`, and the `agent-plugins` key (or your `pluginKey`) with `description`, `category`, `harnesses`, and optionally `scope`, `discrepancies`, `claudeName`, `options` or `userConfig`. Standard `author` and `license` fields go into the Claude manifest.
55
+
56
+ - `claudeName` renames the plugin in Claude's manifest and marketplace, which sets the `/<name>:<command>` namespace.
57
+ - `options` (name to `{ description, default }`) become a Claude `userConfig` and an `options.json` in every harness tree.
58
+ - `userConfig` is copied into the Claude manifest as is. Setting both `options` and `userConfig` is an error.
59
+ - `common/<dir>/x.<harness>.md` replaces `x.md` in that harness only.
60
+ - An OMP rule with no front matter gets `alwaysApply: true`. A rule with its own front matter, such as `description:`, is copied unchanged.
61
+ - `__pycache__` directories are ignored.
62
+
63
+ ## Commands
64
+
65
+ ```sh
66
+ harness-kit build [--check] [--root <dir>]
67
+ harness-kit stamp <plugin> <semver> [--git-add]
68
+ harness-kit validate-claude [--no-strict]
69
+ harness-kit check
70
+ harness-kit update [--check]
71
+ ```
72
+
73
+ | Command | What it does | Exit |
74
+ | --- | --- | --- |
75
+ | `build` | Writes every generated file and removes stale files in `commonDirs`. | 0, or 2 on an error |
76
+ | `build --check` | Lists stale files without writing. | 1 when stale |
77
+ | `stamp` | Sets a plugin's version, then regenerates. `--git-add` stages the generated files outside `plugins/`. For a release `prepareCmd`. | 2 on a bad version |
78
+ | `validate-claude` | Runs `claude plugin validate` on each Claude tree, then on the marketplace. The `claude` CLI comes from `node_modules/.bin`, then `PATH`; install `@anthropic-ai/claude-code`. | 1 when rejected |
79
+ | `check` | `build --check`, then `validate-claude`. Warns when a workflow tag differs from the package pin (below). | 1 on either failure |
80
+ | `update` | Reads the pin in `package.json` and `npm view @srobroek/harness-kit version`. If newer, runs `npm install --save-exact`, then the new release's `build`. Prints `old -> new` or `up to date`. Never commits. `--check` only reports. | 1 with `--check` when outdated |
81
+
82
+ The library exports `readPlugins`, `render`, `drift`, `write`, `stampVersion`, `loadConfig` and `resolveConfig` for tests. Each takes the resolved config as its last argument.
83
+
84
+ ## Presets
85
+
86
+ - `@srobroek/harness-kit/tsconfig.base.json`: `{ "extends": "@srobroek/harness-kit/tsconfig.base.json", "include": [...] }`.
87
+ - `@srobroek/harness-kit/release.config.js`: a semantic-release preset for multi-semantic-release. The forge plugin stays in your repo:
88
+
89
+ ```js
90
+ // release.config.mjs
91
+ import { releaseConfig } from "@srobroek/harness-kit/release.config.js"
92
+ export default releaseConfig({ forge: ["@semantic-release/gitlab", { gitlabUrl: "https://gitlab.example.com" }] })
93
+ ```
94
+
95
+ Its `prepareCmd` runs `harness-kit stamp "$(basename "$PWD")" ${nextRelease.version} --git-add`. Install `semantic-release`, `@anolilab/multi-semantic-release`, `@semantic-release/changelog`, `@semantic-release/exec`, `@semantic-release/git`, `conventional-changelog-conventionalcommits` and `@visulima/yaml` (which multi-semantic-release imports without declaring) as dev dependencies. Keep `.multi-releaserc` (tag format) in your repo.
96
+
97
+ ## GitHub workflows
98
+
99
+ ```yaml
100
+ jobs:
101
+ check:
102
+ uses: srobroek/harness-kit/.github/workflows/check.yml@v1.0.0
103
+ release:
104
+ needs: check
105
+ if: github.ref == 'refs/heads/main'
106
+ uses: srobroek/harness-kit/.github/workflows/release.yml@v1.0.0
107
+ permissions: { contents: write, issues: write, pull-requests: write }
108
+ ```
109
+
110
+ - `check.yml`: `npm ci`, `harness-kit check`, `bun test`, `tsc`.
111
+ - `release.yml`: `npm ci`, then `multi-semantic-release` with `GITHUB_TOKEN`. Your release config names `@semantic-release/github`.
112
+
113
+ ### The workflow tag must match the package version
114
+
115
+ The package and the workflows are one release under one `vX.Y.Z` tag. A consumer on package `1.2.3` calls the workflows at `@v1.2.3`. Pin to the tag, never `main`. `harness-kit check` prints a warning for each `.github/workflows/*.yml` line that references harness-kit at another ref. The warning does not fail the check.
116
+
117
+ ## Upgrade path
118
+
119
+ 1. Bump the pin and the workflow tags to the same version.
120
+ 2. Run `harness-kit build` and commit everything, with the message `chore(deps): bump @srobroek/harness-kit to X.Y.Z`.
121
+ 3. `harness-kit check` in CI catches a bump whose regenerated files were not committed.
122
+
123
+ ### Renovate
124
+
125
+ Extend the preset in `renovate.json`:
126
+
127
+ ```json
128
+ { "extends": ["github>srobroek/harness-kit"] }
129
+ ```
130
+
131
+ The preset extends `config:recommended`. It puts the npm package and the `srobroek/harness-kit` workflow refs in one `harness-kit` group, so they move in one PR, pinned to the tag. Renovate's hosted app does not run `postUpgradeTasks`, so the PR arrives without the regenerated files. In CI, `harness-kit check` fails on the PR; run `npx harness-kit build` on the PR branch and push the result. Repos without Actions run `harness-kit check` locally before merging.
132
+
133
+ ### Without Renovate: `harness-kit update` in GitLab CI
134
+
135
+ [`templates/gitlab-deps-bump.yml`](templates/gitlab-deps-bump.yml) holds a `deps-bump` job to copy into `.gitlab-ci.yml`. A scheduled pipeline with `DEPS_BUMP=1` runs `harness-kit update`, skips when the branch `deps/harness-kit-<v>` exists, commits `chore(deps): bump @srobroek/harness-kit to <v>`, pushes with the protected `GITLAB_TOKEN`, and opens a merge request through the API. The MR pipeline runs your normal checks.
136
+
137
+ #### Schedule pipelines
138
+
139
+ The workflow rules must let the `schedule` source through, and every other job must refuse it. Otherwise the release job fires on the schedule.
140
+
141
+ ```yaml
142
+ workflow:
143
+ rules:
144
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
145
+ - if: $CI_PIPELINE_SOURCE == "schedule" # lets the deps-bump pipeline start
146
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
147
+
148
+ check-job: # every existing job
149
+ rules:
150
+ - if: $CI_PIPELINE_SOURCE != "schedule"
151
+
152
+ release:
153
+ rules:
154
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $GITLAB_TOKEN && $CI_PIPELINE_SOURCE != "schedule"
155
+ ```
156
+
157
+ ## Releasing harness-kit
158
+
159
+ semantic-release runs from `.github/workflows/publish.yml` on pushes to `main`. It tags `vX.Y.Z`, creates the GitHub release and publishes to npm through [trusted publishing](https://docs.npmjs.com/trusted-publishers) (OIDC, no `NPM_TOKEN`). The job needs npm 11.5.1 or later and `id-token: write`, and it runs only when the repository variable `RELEASE_ENABLED` is `true`. npm accepts a trusted publisher only for a package that exists, so the first version is published by hand, as `AGENTS.md` describes.
160
+
161
+ ## License
162
+
163
+ Apache-2.0.
package/package.json CHANGED
@@ -1,6 +1,86 @@
1
1
  {
2
2
  "name": "@srobroek/harness-kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "Shared build tooling for multi-harness agent plugin repos: generator, version stamping, Claude validation, presets and CI workflows.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/srobroek/harness-kit.git"
9
+ },
10
+ "homepage": "https://github.com/srobroek/harness-kit#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/srobroek/harness-kit/issues"
13
+ },
14
+ "type": "module",
15
+ "bin": {
16
+ "harness-kit": "./src/cli.ts"
17
+ },
18
+ "exports": {
19
+ ".": "./src/index.ts",
20
+ "./tsconfig.base.json": "./tsconfig.base.json",
21
+ "./release.config.js": "./release.config.js"
22
+ },
23
+ "files": [
24
+ "src",
25
+ "tsconfig.base.json",
26
+ "release.config.js"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "provenance": true
31
+ },
32
+ "engines": {
33
+ "node": ">=24.10"
34
+ },
35
+ "scripts": {
36
+ "test": "bun test",
37
+ "typecheck": "tsc",
38
+ "pack-check": "sh scripts/pack-check.sh"
39
+ },
40
+ "peerDependencies": {
41
+ "@anolilab/multi-semantic-release": "*",
42
+ "@anthropic-ai/claude-code": "*",
43
+ "@semantic-release/changelog": "*",
44
+ "@semantic-release/exec": "*",
45
+ "@semantic-release/git": "*",
46
+ "@visulima/yaml": "*",
47
+ "conventional-changelog-conventionalcommits": "*",
48
+ "semantic-release": "*"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "@anolilab/multi-semantic-release": {
52
+ "optional": true
53
+ },
54
+ "@anthropic-ai/claude-code": {
55
+ "optional": true
56
+ },
57
+ "@semantic-release/changelog": {
58
+ "optional": true
59
+ },
60
+ "@semantic-release/exec": {
61
+ "optional": true
62
+ },
63
+ "@semantic-release/git": {
64
+ "optional": true
65
+ },
66
+ "@visulima/yaml": {
67
+ "optional": true
68
+ },
69
+ "conventional-changelog-conventionalcommits": {
70
+ "optional": true
71
+ },
72
+ "semantic-release": {
73
+ "optional": true
74
+ }
75
+ },
76
+ "devDependencies": {
77
+ "@semantic-release/changelog": "7.0.0",
78
+ "@semantic-release/git": "11.0.1",
79
+ "@semantic-release/npm": "13.2.0",
80
+ "@types/bun": "1.4.4",
81
+ "bun": "1.4.4",
82
+ "conventional-changelog-conventionalcommits": "9.3.1",
83
+ "semantic-release": "25.0.9",
84
+ "typescript": "5.9.3"
85
+ }
86
+ }
@@ -0,0 +1,41 @@
1
+ // Shared semantic-release preset for plugin repos, for use with multi-semantic-release.
2
+ //
3
+ // release.config.mjs in the consumer:
4
+ // import { releaseConfig } from "@srobroek/harness-kit/release.config.js"
5
+ // export default releaseConfig({ forge: ["@semantic-release/gitlab", { gitlabUrl: "https://gitlab.example.com" }] })
6
+ //
7
+ // The forge plugin (GitLab, GitHub) belongs to the consumer, so it is a required argument of the function form.
8
+ // The consumer installs semantic-release and the plugins used here as devDependencies.
9
+
10
+ /**
11
+ * @param {{ forge?: string | [string, object], branches?: string[], assets?: string[] }} [options]
12
+ * forge: the plugin that publishes the release on the host; omitted, no release is published.
13
+ * assets: files, relative to the plugin directory, that the release commit includes.
14
+ */
15
+ export function releaseConfig({ forge, branches = ["main"], assets } = {}) {
16
+ return {
17
+ branches,
18
+ plugins: [
19
+ ["@semantic-release/commit-analyzer", { preset: "conventionalcommits" }],
20
+ ["@semantic-release/release-notes-generator", { preset: "conventionalcommits" }],
21
+ ["@semantic-release/changelog", { changelogFile: "CHANGELOG.md" }],
22
+ [
23
+ "@semantic-release/exec",
24
+ {
25
+ // Runs in the plugin directory. Stamps the version everywhere it appears and stages the root-level generated files.
26
+ prepareCmd: 'harness-kit stamp "$(basename "$PWD")" ${nextRelease.version} --git-add',
27
+ },
28
+ ],
29
+ [
30
+ "@semantic-release/git",
31
+ {
32
+ assets: assets ?? ["CHANGELOG.md", "package.json", "INVENTORY.md", "opencode/**", "claude/**", "omp/**"],
33
+ message: "chore(release): ${nextRelease.gitTag} [skip ci]\n\n${nextRelease.notes}",
34
+ },
35
+ ],
36
+ ...(forge ? [forge] : []),
37
+ ],
38
+ }
39
+ }
40
+
41
+ export default releaseConfig()
package/src/cli.ts ADDED
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env bun
2
+ // harness-kit: generate and check the files derived from plugins/<name>/, stamp release versions, validate Claude plugins.
3
+
4
+ import { execFileSync } from "node:child_process"
5
+ import { existsSync, readFileSync } from "node:fs"
6
+ import path from "node:path"
7
+ import { parseArgs } from "node:util"
8
+ import { CONFIG_FILE, type Config, findRoot, loadConfig } from "./config"
9
+ import { drift, readPlugins, render, stampVersion, write } from "./generate"
10
+ import { update } from "./update"
11
+ import { workflowRefWarnings } from "./workflow-refs"
12
+ import { validateClaude } from "./validate-claude"
13
+
14
+ const USAGE = `usage: harness-kit <command> [options]
15
+
16
+ commands:
17
+ build [--check] write every generated file; --check fails when one is stale
18
+ stamp <plugin> <semver> set a plugin's version, then regenerate (--git-add stages the root-level files)
19
+ update [--check] move the pinned @srobroek/harness-kit to the newest release and rebuild;
20
+ --check only reports (exit 1 when outdated). Never commits.
21
+ validate-claude [--no-strict] run \`claude plugin validate\` on every Claude plugin and the marketplace
22
+ check build --check, then validate-claude; warns when a workflow tag and the package pin differ
23
+
24
+ options:
25
+ --root <dir> repository root (default: nearest directory at or above the cwd with ${CONFIG_FILE})
26
+ --version print the harness-kit version
27
+ --help print this text`
28
+
29
+ const plural = (count: number) => `${count} plugin${count === 1 ? "" : "s"}`
30
+
31
+ function resolveRoot(explicit: string | undefined): string {
32
+ if (explicit !== undefined) return path.resolve(explicit)
33
+ const found = findRoot(process.cwd())
34
+ if (!found) throw new Error(`no ${CONFIG_FILE} at or above ${process.cwd()}; run from the repository or pass --root`)
35
+ return found
36
+ }
37
+
38
+ /** 0 when current, 1 when a generated file is stale. */
39
+ function buildCheck(root: string, config: Config): number {
40
+ const plugins = readPlugins(root, config)
41
+ const { changed, extra } = drift(root, render(root, plugins, config), config)
42
+ const stale = [...changed, ...extra]
43
+ if (stale.length > 0) {
44
+ console.error("Generated files are stale. Run `harness-kit build` and commit the result:")
45
+ for (const file of stale) console.error(` ${path.relative(root, file)}`)
46
+ return 1
47
+ }
48
+ console.log(`generated files are current (${plural(plugins.length)})`)
49
+ return 0
50
+ }
51
+
52
+ function buildWrite(root: string, config: Config): number {
53
+ const plugins = readPlugins(root, config)
54
+ const outputs = render(root, plugins, config)
55
+ write(root, outputs, config)
56
+ console.log(`generated ${outputs.length} files for ${plural(plugins.length)}`)
57
+ return 0
58
+ }
59
+
60
+ /** Stage the generated files that live outside plugins/, which semantic-release's git assets cannot reach. */
61
+ function gitAddRootFiles(root: string, config: Config): void {
62
+ const files = render(root, readPlugins(root, config), config)
63
+ .map((output) => path.relative(root, output.file))
64
+ .filter((file) => !file.startsWith(`plugins${path.sep}`) && existsSync(path.join(root, file)))
65
+ if (files.length > 0) execFileSync("git", ["add", "--", ...files], { cwd: root, stdio: "inherit" })
66
+ }
67
+
68
+ function packageVersion(): string {
69
+ const manifest = JSON.parse(readFileSync(path.join(import.meta.dir, "..", "package.json"), "utf8")) as { version: string }
70
+ return manifest.version
71
+ }
72
+
73
+ /** Exit status: 0 success, 1 stale files or a rejected Claude plugin, 2 usage or configuration error. */
74
+ export function main(argv: string[]): number {
75
+ try {
76
+ const { values, positionals } = parseArgs({
77
+ args: argv,
78
+ allowPositionals: true,
79
+ allowNegative: true,
80
+ options: {
81
+ root: { type: "string" },
82
+ check: { type: "boolean" },
83
+ strict: { type: "boolean" },
84
+ "git-add": { type: "boolean" },
85
+ version: { type: "boolean" },
86
+ help: { type: "boolean", short: "h" },
87
+ },
88
+ })
89
+ const [command, ...rest] = positionals
90
+ if (values.version) {
91
+ console.log(packageVersion())
92
+ return 0
93
+ }
94
+ if (values.help || !command) {
95
+ console.log(USAGE)
96
+ return values.help ? 0 : 2
97
+ }
98
+ const known = ["build", "stamp", "update", "validate-claude", "check"]
99
+ if (!known.includes(command)) throw new Error(`unknown command "${command}" (use ${known.join(", ")})\n${USAGE}`)
100
+ if (command !== "stamp" && rest.length > 0) throw new Error(`${command} takes no arguments, got "${rest.join(" ")}"`)
101
+
102
+ const root = resolveRoot(values.root)
103
+ if (command === "update") {
104
+ const result = update(root, { check: values.check })
105
+ console.log(result.status === "current" ? "up to date" : `${result.from} -> ${result.to}`)
106
+ return result.status === "outdated" ? 1 : 0
107
+ }
108
+ const config = loadConfig(root)
109
+ switch (command) {
110
+ case "build":
111
+ return values.check ? buildCheck(root, config) : buildWrite(root, config)
112
+ case "stamp": {
113
+ const [plugin, version] = rest
114
+ if (!plugin || !version || rest.length > 2) throw new Error("usage: harness-kit stamp <plugin> <semver>")
115
+ stampVersion(root, plugin, version, config)
116
+ if (values["git-add"]) gitAddRootFiles(root, config)
117
+ console.log(`stamped ${plugin} ${version}`)
118
+ return 0
119
+ }
120
+ case "validate-claude":
121
+ return validateClaude(root, config, { strict: values.strict === false ? false : undefined })
122
+ default: {
123
+ for (const warning of workflowRefWarnings(root)) console.warn(`warning: ${warning}`)
124
+ const built = buildCheck(root, config)
125
+ const validated = validateClaude(root, config, { strict: values.strict === false ? false : undefined })
126
+ return built || validated
127
+ }
128
+ }
129
+ } catch (error) {
130
+ console.error(error instanceof Error ? error.message : String(error))
131
+ return 2
132
+ }
133
+ }
134
+
135
+ if (import.meta.main) process.exit(main(process.argv.slice(2)))