# Path set partition directory

`path-set-partition-directory` · version 1.0.0 · File paths (lexical) · free, no key needed

Partition an array of file paths into buckets grouped by parent directory or directory at a specified depth.

**Use when you need to: partition paths by directory · group files by directory · partition path set.**

## Supported

- partition paths by directory
- group files by directory
- partition path set

## Not supported

- stat file
- filesystem access

## Behavior

- Group paths by their ancestor directory at the given depth level. Depth 1 = immediate parent directory of the file. Paths shallower than the requested depth are grouped under their own path as key. Keys are normalized directory paths. Order of paths within each group is input order. Partition keys use a null-prototype object to avoid prototype collision.

## Input

- `paths` (array of string, required): min items 0; max items 10000; each min length 1; each max length 4096
- `depth` (integer, optional): min 1; max 32
- `format` (one of "posix", "windows", "auto", optional)

## Output

- `partitions` (object, required)
- `format` (string, required)
- `total` (integer, required)

## Limits

- max paths: 10000
- max depth: 32
- max path bytes: 4096

## Example

Request input:

```json
{
  "paths": [
    "/a/b/c.ts",
    "/a/b/d.ts",
    "/a/e/f.ts"
  ],
  "depth": 2
}
```

Response:

```json
{
  "result": {
    "partitions": {
      "/a/b": [
        "/a/b/c.ts",
        "/a/b/d.ts"
      ],
      "/a/e": [
        "/a/e/f.ts"
      ]
    },
    "format": "posix",
    "total": 3
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "path-set-partition-directory",
  "version": "1.0.0",
  "input": {
    "paths": [
      "/a/b/c.ts",
      "/a/b/d.ts",
      "/a/e/f.ts"
    ],
    "depth": 2
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/path-set-partition-directory/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"paths":["/a/b/c.ts","/a/b/d.ts","/a/e/f.ts"],"depth":2}'
```

The machine-readable contract is at [/v1/tools/path-set-partition-directory/versions/1.0.0](/v1/tools/path-set-partition-directory/versions/1.0.0).

### CLI

```sh
node cli.mjs run path-set-partition-directory 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Path set glob filter](/tools/path-set-glob-filter): Filter an array of paths against glob patterns with inclusion and exclusion rules lexically without filesystem access.
- [Path set hierarchy tree](/tools/path-set-hierarchy-tree): Transform a flat array of file paths into a nested deterministic directory tree structure.
- [Path set prefix strip](/tools/path-set-prefix-strip): Strip a common directory prefix or base path from an array of paths lexically.
- [Path set classify](/tools/path-set-classify): Classify an array of file paths by file extension, depth histogram, and path format.
- [Path set dedupe](/tools/path-set-dedupe): Deduplicate an array of paths based on lexical equivalence while preserving first or last seen order.
- [Path set difference](/tools/path-set-difference): Compute the set difference (A \ B) of two path collections using lexical path equivalence.
