Skip to Content
harness-kit

Projects and stacks

How harness-kit knows what a repository is (its project) and what a folder is (its stack), and how it names the package manager.

How does harness-kit know what a repository and a folder are? It resolves three things for each call: the repository's project, a folder's stack and the project's package manager. The stacks and the package manager are detected; the project needs a catalog.

Where the repository root is

Everything starts at the repository root: the top of the git working copy Claude Code runs in (CLAUDE_PROJECT_DIR, else the call's folder). The kit finds it by climbing to the first folder with a .git, without running git, so a linked worktree is its own root. A repository rooted at the home folder is ignored.

Stacks

A stack is the ecosystem a folder belongs to. Without configuration the kit knows three, detected in this order:

StackMarker
rubya Gemfile
nodea package.json or pnpm-lock.yaml
kustomizea kustomization.yaml, in the folder or up to two below

A folder's stack is the first one whose marker it holds. The configuration's stacks replaces the list; see the example below.

Keep the order

Write stacks as a list of { name, detect }, which keeps its order. A map of stacks.<name>.detect works too, read in the order its keys are written, which a formatter or a lint that sorts keys can change.

An entry with stack: 'ruby' runs only where the nearest folder up from each touched file holds the stack's marker, and works in that folder. In a monorepo, a Ruby formatter formats api/app/models/user.rb from api/ and stays out of web/.

  • whenFile: 'bin/rails' does the same with any file as the marker.
  • A call that touches files in two such folders runs the Policy once in each; a refusal in either refuses the call.

Projects

A project is what your team's catalog says about a repository: its group, its kind, its stack, its gates, the branches that deploy, and the group's tracker projects. Policies read it: work-saved and branch-name leave deploy branches alone, references knows which issue keys are yours, harness-kit gates resolve lists its gates.

The configuration's projects says where the catalog comes from:

  • { catalog: { … } }, a catalog written in the configuration;
  • { file: './projects.json' }, the same catalog as JSON beside it;
  • { command: './bin/projects' }, an executable of the protocol that answers resolve_project.
Catalog keyWhat it holds
groupsthe groups projects belong to, with their tracker projects
kindseach kind's stack, gates and deploy branches
projectseach with a name, group and kind, and anything of its own
excludedrepositories the catalog leaves out on purpose

A repository is looked up by its identity: by default the last part of its origin remote's URL without .git. projects.identity can choose the folder name, the whole remote URL or a fixed name instead.

A catalog like this usually lives in the central configuration every repository extends:

central.config.ts
import { defineConfig } from '@microeinhundert/harness-kit';

/**
 * A project catalog for every repository of a team, kept in the central configuration: each repository is listed by
 * the name of its `origin` remote, in a group (whose tracker project it shares) and of a kind (whose stack, deploy
 * branches and gates it takes). Its stacks replace the default ones, as a list that keeps its order: `python`, detected first, then `node`.
 */
export default defineConfig({
  policies: [],
  projects: {
    source: {
      catalog: {
        groups: {
          payments: {
            tracker: {
              projects: ['PAY'],
            },
          },
        },
        kinds: {
          service: {
            deploy_branches: ['release/*'],
            gates: [
              {
                exclusive: true,
                name: 'test',
                run: 'bin/test',
                timeout: 1800,
              },
              'bin/lint',
            ],
            stack: 'node',
          },
        },
        projects: [
          {
            group: 'payments',
            kind: 'service',
            name: 'checkout-api',
          },
        ],
      },
    },
  },
  stacks: [
    {
      detect: [
        {
          file: 'pyproject.toml',
        },
      ],
      name: 'python',
    },
    {
      detect: [
        {
          file: 'package.json',
        },
      ],
      name: 'node',
    },
  ],
});

Which package manager the kit uses

Several Policies run the project's install command or programs from node_modules, so the kit names the project's package manager, first found wins:

  1. the configuration's packageManager (npm, pnpm or bun);
  2. the packageManager field or the lockfile of the nearest folder that has one;
  3. npm.
ManagerInstall commandProgram runner
npmnpm cinpx
pnpmpnpm install --frozen-lockfilepnpm exec
bunbun install --frozen-lockfilebunx

Lockfiles of two managers, or a yarn project, fail with the files to fix.

  • Gates: the project's checks, run under a lock.

On this page