diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f9bdcc6a..2d75d1c1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -72,60 +72,68 @@ jobs: - name: Build and test all packages run: pnpm turbo run build test - # Publishes the CLI and the workspace packages it needs at runtime, in - # dependency order: shared, core, exchange, cli. Does nothing (and passes) - # when the NPM_TOKEN repo secret is not set. A job-level `if` cannot read - # secrets, so the first step checks the token through the job env instead. + # Publishes the CLI as the unscoped `harness-kit` npm package: one bundle with + # the workspace packages inlined. Uses npm Trusted Publishing (OIDC), so there + # is no npm token. The trusted publisher must be configured on npmjs.com for + # harnessprotocol/harness-kit, workflow release.yml. The first version is + # published by hand, which is when the package can be linked to this workflow; + # a version that already exists on npm is skipped. build-cli-npm: needs: [prepare, gate] runs-on: ubuntu-latest - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + permissions: + contents: read + id-token: write steps: - - name: Check for NPM_TOKEN - id: token - run: | - if [ -z "$NPM_TOKEN" ]; then - echo "::notice::NPM_TOKEN is not set; skipping npm publish." - echo "publish=false" >> "$GITHUB_OUTPUT" - else - echo "publish=true" >> "$GITHUB_OUTPUT" - fi - - uses: actions/checkout@v7 - if: steps.token.outputs.publish == 'true' - uses: pnpm/action-setup@v6 - if: steps.token.outputs.publish == 'true' - uses: actions/setup-node@v7 - if: steps.token.outputs.publish == 'true' with: node-version: 24 cache: pnpm registry-url: https://registry.npmjs.org + # Trusted publishing needs npm 11.5.1 or later. + - name: Ensure npm supports trusted publishing + run: | + required="11.5.1" + current="$(npm --version)" + if [ "$(printf '%s\n%s\n' "$required" "$current" | sort -V | head -n1)" != "$required" ]; then + npm install -g npm@latest + fi + npm --version + - name: Stamp version - if: steps.token.outputs.publish == 'true' run: bash scripts/stamp-version.sh ${{ needs.prepare.outputs.version }} - name: Install dependencies - if: steps.token.outputs.publish == 'true' run: pnpm install --frozen-lockfile - - name: Build packages - if: steps.token.outputs.publish == 'true' - run: pnpm turbo run build --filter=@harness-kit/cli... + - name: Build npm package + run: pnpm run build:cli-npm + env: + HK_NPM_VERSION: ${{ needs.prepare.outputs.version }} - - name: Publish to npm - if: steps.token.outputs.publish == 'true' - run: | - pnpm --filter @harness-kit/shared publish --no-git-checks - pnpm --filter @harness-kit/core publish --no-git-checks - pnpm --filter @harness-kit/exchange publish --no-git-checks - pnpm --filter @harness-kit/cli publish --no-git-checks + # The trusted publisher allows staging only: a release goes live after a + # maintainer approves it on npmjs.com (or `npm stage approve `) with 2FA. + - name: Stage the npm release + working-directory: apps/cli/npm-dist env: - NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }} + VERSION: ${{ needs.prepare.outputs.version }} + run: | + if npm view "@harnessprotocol/cli@${VERSION}" version >/dev/null 2>&1; then + echo "::notice::@harnessprotocol/cli@${VERSION} is already on npm; skipping publish." + exit 0 + fi + if [[ "$VERSION" == *-* ]]; then + # npm refuses a prerelease without an explicit non-latest tag. + npm stage publish . --provenance --access public --tag next + else + npm stage publish . --provenance --access public + fi + echo "::notice::@harnessprotocol/cli@${VERSION} is staged. Approve it at https://www.npmjs.com/package/@harnessprotocol/cli to publish." build-cli-standalone: needs: [prepare, gate] diff --git a/.gitignore b/.gitignore index 2fc52b56..59ad0667 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ packages/registry-service/dist/ # CLI apps/cli/dist/ +apps/cli/npm-dist/ # Marketplace data generator packages/marketplace-data/dist/ diff --git a/README.md b/README.md index a99294e1..05eb167c 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Your AI coding setup — plugins, skills, MCP servers, hooks, conventions — pa **CLI** (`harness validate`, `compile`, `install`, `sync`, ...): ```bash brew tap harnessprotocol/tap && brew install harness-kit -# or: npm install -g @harness-kit/cli # requires Node.js 24+ +# or: npm install -g @harnessprotocol/cli # requires Node.js 24+ ``` **Desktop App**: @@ -165,7 +165,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - - uses: harnessprotocol/harness-kit@v0.13.0 + - uses: harnessprotocol/harness-kit@v0.13.1 with: target: claude-code,cursor,agents-md ``` @@ -178,7 +178,7 @@ The step exits 1 on drift and writes a table of the drifted files to the job sum | `harness-file` | `harness.yaml` | Path to the profile (`check`). | | `target` | all | Comma-separated targets (`check`). | | `baseline` | none | Team baseline `harness.yaml` in the checkout (`status`). | -| `cli-version` | the release version | npm version or dist-tag of `@harness-kit/cli`, for example `latest`. | +| `cli-version` | the release version | npm version or dist-tag of the `harness-kit` npm package, for example `latest`. | ## 🔒 Security & Privacy diff --git a/action.yml b/action.yml index 7e77101d..d7b37492 100644 --- a/action.yml +++ b/action.yml @@ -21,9 +21,9 @@ inputs: cli-version: # Pinned to the release this tag ships. Bump this default when cutting a # release. Users can override it with an npm version or dist-tag such as latest. - description: "Version or dist-tag of @harness-kit/cli to run." + description: "Version or dist-tag of the @harnessprotocol/cli npm package to run." required: false - default: "0.13.0" + default: "0.13.1" outputs: exit-code: diff --git a/apps/cli/package.json b/apps/cli/package.json index 6d865e46..9ef03fac 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -15,6 +15,7 @@ }, "scripts": { "build": "tsup", + "build:npm": "node scripts/build-npm.mjs", "dev": "tsup --watch", "test": "vitest run", "test:watch": "vitest" diff --git a/apps/cli/scripts/build-npm.mjs b/apps/cli/scripts/build-npm.mjs new file mode 100644 index 00000000..62ed715c --- /dev/null +++ b/apps/cli/scripts/build-npm.mjs @@ -0,0 +1,95 @@ +#!/usr/bin/env node +// Builds the publishable `harness-kit` npm package into apps/cli/npm-dist/. +// +// node scripts/build-npm.mjs [version] +// +// The version defaults to HK_NPM_VERSION, then apps/cli/package.json. +// Publish from npm-dist/ (never from apps/cli/). +import { spawnSync } from "node:child_process"; +import { copyFileSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const cliRoot = join(dirname(fileURLToPath(import.meta.url)), ".."); +const repoRoot = join(cliRoot, "..", ".."); +const outDir = join(cliRoot, "npm-dist"); +const readJson = (p) => JSON.parse(readFileSync(p, "utf-8")); + +const cliPkg = readJson(join(cliRoot, "package.json")); +const version = process.argv[2] || process.env.HK_NPM_VERSION || cliPkg.version; +if (!/^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$/.test(version)) { + console.error(`'${version}' is not a valid semver string`); + process.exit(1); +} + +rmSync(outDir, { recursive: true, force: true }); + +const tsup = spawnSync( + join(cliRoot, "node_modules", ".bin", "tsup"), + ["--config", "tsup.config.npm.ts"], + { cwd: cliRoot, stdio: "inherit", env: { ...process.env, HK_NPM_VERSION: version } }, +); +if (tsup.status !== 0) process.exit(tsup.status ?? 1); + +// Third-party runtime deps of the CLI and the workspace packages it inlines. +// First declaration wins; core is read before exchange so its tighter +// @noble/hashes range (which satisfies both) is kept. +const dependencies = {}; +for (const dir of [ + join(cliRoot), + join(repoRoot, "packages", "core"), + join(repoRoot, "packages", "exchange"), + join(repoRoot, "packages", "shared"), +]) { + for (const [name, range] of Object.entries(readJson(join(dir, "package.json")).dependencies ?? {})) { + if (name.startsWith("@harness-kit/")) continue; + dependencies[name] ??= range; + } +} + +const sorted = Object.fromEntries(Object.entries(dependencies).sort(([a], [b]) => a.localeCompare(b))); + +const manifest = { + name: "@harnessprotocol/cli", + version, + description: "Compile one harness.yaml into config for Claude Code, Cursor, Codex and other agents, and check it for drift.", + type: "module", + bin: { "harness-kit": "dist/index.js", harness: "dist/index.js" }, + files: ["dist", "README.md", "LICENSE"], + engines: { node: ">=24" }, + license: "Apache-2.0", + repository: { + type: "git", + url: "git+https://github.com/harnessprotocol/harness-kit.git", + directory: "apps/cli", + }, + homepage: "https://harnesskit.ai", + bugs: { url: "https://github.com/harnessprotocol/harness-kit/issues" }, + publishConfig: { access: "public" }, + dependencies: sorted, +}; +writeFileSync(join(outDir, "package.json"), JSON.stringify(manifest, null, 2) + "\n"); + +writeFileSync( + join(outDir, "README.md"), + `# harness-kit + +Command line tool for [harness-kit](https://github.com/harnessprotocol/harness-kit). +Compile one \`harness.yaml\` into config for Claude Code, Cursor, Codex and other +agents, and check that compiled files match it. + +\`\`\`bash +npm install -g @harnessprotocol/cli # requires Node.js 24+ +harness-kit --help + +# or run without installing +npx -p @harnessprotocol/cli harness-kit check +\`\`\` + +Documentation: https://harnesskit.ai +`, +); + +mkdirSync(outDir, { recursive: true }); +copyFileSync(join(repoRoot, "LICENSE"), join(outDir, "LICENSE")); +console.log(`Built @harnessprotocol/cli@${version} in ${outDir}`); diff --git a/apps/cli/tsup.config.npm.ts b/apps/cli/tsup.config.npm.ts new file mode 100644 index 00000000..8e755ec8 --- /dev/null +++ b/apps/cli/tsup.config.npm.ts @@ -0,0 +1,38 @@ +import { defineConfig } from "tsup"; +import { readFileSync } from "fs"; + +const readJson = (p: string) => JSON.parse(readFileSync(p, "utf-8")); +const pkg = readJson("./package.json"); +// Release stamping: HK_NPM_VERSION overrides the workspace version. +const version = process.env.HK_NPM_VERSION || pkg.version; + +// Third-party dependencies of the CLI and of the workspace packages it inlines. +// They stay external and become `dependencies` of the published package.json +// (see scripts/build-npm.mjs). +const thirdParty = new Set(); +for (const dir of [".", "../../packages/core", "../../packages/exchange", "../../packages/shared"]) { + for (const name of Object.keys(readJson(`${dir}/package.json`).dependencies ?? {})) { + if (!name.startsWith("@harness-kit/")) thirdParty.add(name); + } +} + +// Bundle for the unscoped `harness-kit` npm package. Inlines only the +// workspace packages (@harness-kit/*), which are not published. +export default defineConfig({ + entry: ["src/index.ts"], + format: ["esm"], + outDir: "npm-dist/dist", + clean: true, + sourcemap: false, + target: "node24", + noExternal: [/^@harness-kit\//], + external: [...thirdParty].flatMap((n) => [n, new RegExp(`^${n}/`)]), + // node:sqlite only resolves with the prefix. See tsup.config.ts. + removeNodeProtocol: false, + banner: { + js: "#!/usr/bin/env node", + }, + define: { + __CLI_VERSION__: JSON.stringify(version), + }, +}); diff --git a/package.json b/package.json index 0daa1cc6..b95a4cba 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "build:desktop": "pnpm run generate:marketplace:desktop && pnpm --filter harness-kit-desktop tauri build && rm -rf '/Applications/Harness Kit.app' && rm -rf \"$HOME/Applications/Harness Kit.app\" && cp -Rf 'apps/desktop/src-tauri/target/release/bundle/macos/Harness Kit.app' $HOME/Applications/", "install:desktop": "pnpm run generate:marketplace:desktop && pnpm --filter harness-kit-desktop tauri build --debug && rm -rf '/Applications/Harness Kit.app' && rm -rf \"$HOME/Applications/Harness Kit.app\" && cp -Rf 'apps/desktop/src-tauri/target/debug/bundle/macos/Harness Kit.app' $HOME/Applications/", "build": "turbo run build", + "build:cli-npm": "pnpm turbo run build --filter=@harness-kit/cli^... && pnpm --filter @harness-kit/cli build:npm", "test:all": "turbo run test", "test:coverage": "pnpm -r test -- --coverage", "test:desktop:unit": "pnpm --filter harness-kit-desktop test", diff --git a/scripts/action-run.sh b/scripts/action-run.sh index 899a0c3e..d26a8fe6 100755 --- a/scripts/action-run.sh +++ b/scripts/action-run.sh @@ -6,7 +6,7 @@ # HK_FILE path to harness.yaml (check only) # HK_TARGET comma-separated targets (check only, optional) # HK_BASELINE baseline harness.yaml path (status only, optional) -# HK_CLI_VERSION npm version or dist-tag of @harness-kit/cli +# HK_CLI_VERSION npm version or dist-tag of the harness-kit package # HK_CLI optional override command used instead of npx (local testing) # GITHUB_STEP_SUMMARY, GITHUB_OUTPUT provided by GitHub Actions # @@ -38,7 +38,7 @@ if [ -n "${HK_CLI:-}" ]; then # shellcheck disable=SC2206 runner=($HK_CLI) else - runner=(npx -y "@harness-kit/cli@${HK_CLI_VERSION:-latest}") + runner=(npx -y -p "@harnessprotocol/cli@${HK_CLI_VERSION:-latest}" harness-kit) fi "${runner[@]}" "${args[@]}" >"$OUT_DIR/stdout.json" 2>"$OUT_DIR/stderr.txt" diff --git a/skills/harness-docs/references/getting-started.md b/skills/harness-docs/references/getting-started.md index 74d9610e..f24e5bc7 100644 --- a/skills/harness-docs/references/getting-started.md +++ b/skills/harness-docs/references/getting-started.md @@ -61,7 +61,7 @@ brew tap harnessprotocol/tap brew install harness-kit # npm -npm install -g @harness-kit/cli +npm install -g @harnessprotocol/cli # Verify harness --version diff --git a/website/components/marketplace/InstallWidget.tsx b/website/components/marketplace/InstallWidget.tsx index f749c358..7784541c 100644 --- a/website/components/marketplace/InstallWidget.tsx +++ b/website/components/marketplace/InstallWidget.tsx @@ -136,7 +136,7 @@ function PluginCliTab({ plugin }: { plugin: MarketplacePlugin }) {

Run ephemerally (no install):

- +
@@ -146,8 +146,8 @@ function PluginCliTab({ plugin }: { plugin: MarketplacePlugin }) {

1. Add to your harness.yaml plugins list, then:

- - + +
@@ -213,8 +213,8 @@ function ProfileCliTab({ profile }: { profile: MarketplaceProfile }) {
- - + +

compile writes native config for Claude Code, Cursor, and diff --git a/website/content/docs/getting-started/installation.mdx b/website/content/docs/getting-started/installation.mdx index 4761acb6..e13e3042 100644 --- a/website/content/docs/getting-started/installation.mdx +++ b/website/content/docs/getting-started/installation.mdx @@ -174,7 +174,7 @@ brew install harness-kit ```bash -npm install -g @harness-kit/cli +npm install -g @harnessprotocol/cli ``` Requires Node.js 24 or later. diff --git a/website/content/docs/getting-started/quick-start.mdx b/website/content/docs/getting-started/quick-start.mdx index 461178f1..3faf5223 100644 --- a/website/content/docs/getting-started/quick-start.mdx +++ b/website/content/docs/getting-started/quick-start.mdx @@ -102,7 +102,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - - uses: harnessprotocol/harness-kit@v0.13.0 + - uses: harnessprotocol/harness-kit@v0.13.1 with: target: claude-code,cursor,agents-md ``` @@ -115,7 +115,7 @@ The step exits 1 on drift and writes a table of the drifted files to the job sum | `harness-file` | `harness.yaml` | Path to the profile (`check`). | | `target` | all | Comma-separated targets (`check`). | | `baseline` | none | Team baseline `harness.yaml` in the checkout (`status`). | -| `cli-version` | the release version | npm version or dist-tag of `@harness-kit/cli`, for example `latest`. | +| `cli-version` | the release version | npm version or dist-tag of the `harness-kit` npm package, for example `latest`. | ## No existing config? Start with a plugin