Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 40 additions & 32 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <id>`) 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]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ packages/registry-service/dist/

# CLI
apps/cli/dist/
apps/cli/npm-dist/

# Marketplace data generator
packages/marketplace-data/dist/
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**:
Expand Down Expand Up @@ -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
```
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"scripts": {
"build": "tsup",
"build:npm": "node scripts/build-npm.mjs",
"dev": "tsup --watch",
"test": "vitest run",
"test:watch": "vitest"
Expand Down
95 changes: 95 additions & 0 deletions apps/cli/scripts/build-npm.mjs
Original file line number Diff line number Diff line change
@@ -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}`);
38 changes: 38 additions & 0 deletions apps/cli/tsup.config.npm.ts
Original file line number Diff line number Diff line change
@@ -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<string>();
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),
},
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions scripts/action-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion skills/harness-docs/references/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions website/components/marketplace/InstallWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function PluginCliTab({ plugin }: { plugin: MarketplacePlugin }) {
<div className="flex flex-col gap-4">
<div>
<p className="mb-2 text-sm text-fd-muted-foreground">Run ephemerally (no install):</p>
<InstallCommand command={`npx @harness-kit/cli run ${plugin.name}@harnessprotocol/harness-kit`} />
<InstallCommand command={`npx -p @harnessprotocol/cli harness-kit run ${plugin.name}@harnessprotocol/harness-kit`} />
</div>
<details className="rounded-xl bg-fd-card/40 px-4 py-3 text-sm">
<summary className="cursor-pointer text-fd-muted-foreground select-none">
Expand All @@ -146,8 +146,8 @@ function PluginCliTab({ plugin }: { plugin: MarketplacePlugin }) {
<p className="text-xs text-fd-muted-foreground">
1. Add to your <code className="font-mono">harness.yaml</code> plugins list, then:
</p>
<InstallCommand command="npx @harness-kit/cli sync" />
<InstallCommand command="npx @harness-kit/cli compile" />
<InstallCommand command="npx -p @harnessprotocol/cli harness-kit sync" />
<InstallCommand command="npx -p @harnessprotocol/cli harness-kit compile" />
</div>
</details>
</div>
Expand Down Expand Up @@ -213,8 +213,8 @@ function ProfileCliTab({ profile }: { profile: MarketplaceProfile }) {
<DownloadYaml slug={profile.slug} yaml={profile.harnessYaml} />
</div>
<div className="flex flex-col gap-3">
<InstallCommand command="npx @harness-kit/cli sync" />
<InstallCommand command="npx @harness-kit/cli compile" />
<InstallCommand command="npx -p @harnessprotocol/cli harness-kit sync" />
<InstallCommand command="npx -p @harnessprotocol/cli harness-kit compile" />
</div>
<p className="text-xs text-fd-muted-foreground">
<code className="font-mono">compile</code> writes native config for Claude Code, Cursor, and
Expand Down
2 changes: 1 addition & 1 deletion website/content/docs/getting-started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ brew install harness-kit

<Tab value="npm">
```bash
npm install -g @harness-kit/cli
npm install -g @harnessprotocol/cli
```

Requires Node.js 24 or later.
Expand Down
4 changes: 2 additions & 2 deletions website/content/docs/getting-started/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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

Expand Down
Loading