npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kb-labs/core-workspace

v2.94.0

Published

Core workspace utilities for KB Labs, including root directory resolution and workspace detection

Downloads

5,623

Readme

@kb-labs/core-workspace

Core workspace utilities for KB Labs, including platform/project root resolution. Provides utilities for locating the KB Labs platform installation and the user's project directory for internal tooling consumption (CLI, services, dev tools).

License: MIT Node.js pnpm

🎯 Vision & Purpose

@kb-labs/core-workspace provides root-directory resolution utilities shared by CLI, services, and kb-dev.

KB Labs distinguishes two logical roots, which may coincide (dev mode) or differ (installed mode):

| Root | What it is | Where it lives | | --------------- | ------------------------------------------------------------------------------------------------ | --------------------------------------------------- | | platformRoot | Directory that contains the installed KB Labs platform code (parent of node_modules/@kb-labs/*) | /opt/kb-labs (installed), workspace root (dev) | | projectRoot | Directory that contains the user's .kb/kb.config.json and all per-project plugin state | ~/work/my-app (installed), workspace root (dev) |

Why two roots? Plugin discovery needs to scan the platform's node_modules, while platform state (.kb/qa, .kb/mind, .kb/marketplace.lock, adapter storage paths like .kb/database/kb.sqlite) belongs to the user's project. Until the platform moved out of the workspace, both assumptions resolved to the same cwd — and the codebase silently conflated them. This package makes the distinction explicit.

🏗️ Architecture

Core Functions

resolveRoots(options) — main entry point

Resolves both platformRoot and projectRoot in a single call. This is what the CLI bootstrap, service bootstrap, and kb-dev should use.

const { platformRoot, projectRoot, sameLocation, sources } = await resolveRoots({
  moduleUrl: import.meta.url, // from the caller's binary/entry
  startDir: process.cwd(),
})
  • sameLocation: true ⇒ dev mode (both roots are the same directory).
  • sources.platform / sources.project describe how each root was discovered ('explicit' | 'env' | 'module' | 'marker' | 'config' | 'repo' | 'fallback').

resolvePlatformRoot(options)

Finds the directory that contains the installed KB Labs platform (parent of node_modules/@kb-labs/*).

Priority chain:

  1. Explicit cwd option.
  2. KB_PLATFORM_ROOT env var (set by the installer wrapper in installed mode).
  3. Walk up from moduleUrl (import.meta.url of the caller). This walks all the way up and:
    • Prefers the top-most pnpm-workspace.yaml if one exists (handles KB Labs "workspace of workspaces" dev layout).
    • Falls back to the first directory whose node_modules contains a known platform marker (@kb-labs/cli-bin, @kb-labs/core-runtime) — this is the normal installed-mode path.
  4. Walk up from startDir looking for the same markers or pnpm-workspace.yaml.
  5. Repository root via findRepoRoot.
  6. Fallback to startDir.

resolveProjectRoot(options)

Finds the user's project root — the directory containing .kb/kb.config.json.

Priority chain:

  1. Explicit cwd option.
  2. Env vars: KB_PROJECT_ROOT (preferred) or legacy KB_LABS_WORKSPACE_ROOT / KB_LABS_REPO_ROOT.
  3. Nearest .kb/kb.config.json ancestor walking up from startDir.
  4. Repository root via findRepoRoot.
  5. Fallback to startDir.

resolveWorkspaceRoot(options) — deprecated alias

Kept as an alias of resolveProjectRoot for backwards compatibility. Prefer the explicit name.

🚀 Quick Start

Installation

pnpm add @kb-labs/core-workspace

Basic Usage

import { resolveRoots } from '@kb-labs/core-workspace'

// In a CLI entrypoint (bin.ts):
const { platformRoot, projectRoot, sameLocation } = await resolveRoots({
  moduleUrl: import.meta.url,
  startDir: process.cwd(),
})

console.log({ platformRoot, projectRoot, sameLocation })

In dev mode (monorepo workspace)

platformRoot === projectRoot === <workspace-root>
sameLocation:   true
sources:        { platform: 'module', project: 'config' }

In installed mode

platformRoot:  /opt/kb-labs                    (from KB_PLATFORM_ROOT or moduleUrl walk-up)
projectRoot:   /home/user/work/my-project      (from .kb/kb.config.json walk-up)
sameLocation:  false

✨ Features

  • Two-root resolution: clearly distinguishes platform code location from project state location.
  • Multiple discovery signals: explicit options, env vars, import.meta.url walk-up, marker walk-up, repo root.
  • Dev/installed parity: same API works in workspace dev mode and in deployed/installed mode; callers don't need to branch.
  • Nested-workspace aware: handles the KB Labs "workspace of workspaces" layout where sub-repos each have their own pnpm-workspace.yaml.
  • Backwards compatible: legacy resolveWorkspaceRoot and KB_LABS_WORKSPACE_ROOT / KB_LABS_REPO_ROOT env vars still work.

🔧 Configuration

Environment Variables

| Variable | Purpose | | ------------------------- | ----------------------------------------------------------------------------- | | KB_PLATFORM_ROOT | Override platform root (installer wrapper, CI). | | KB_PROJECT_ROOT | Override project root. | | KB_LABS_WORKSPACE_ROOT | Legacy alias for KB_PROJECT_ROOT (kept for backwards compatibility). | | KB_LABS_REPO_ROOT | Legacy alias for KB_PROJECT_ROOT (kept for backwards compatibility). |

🤝 Contributing

See CONTRIBUTING.md for development guidelines.

📄 License

KB Public License v1.1 © KB Labs