# Stable sort indices check

`stable-sort-indices-check` · version 1.0.0 · Numbers & math · free, no key needed

Check that claimed source indices are the exact ascending stable order for supplied integer keys.

**Use when you need to: check stable sort indices · validate claimed sorting permutation · check argsort stability.**

## Decide before calling

Read the [versioned contract](/v1/tools/stable-sort-indices-check/versions/1.0.0) and the supported scope below. Reuse `stable-sort-indices-check@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `stable-sort-indices-check@1.0.0` for check stable sort indices. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- check stable sort indices
- validate claimed sorting permutation
- check argsort stability
- detect first index order discrepancy
- validate stable ordering certificate
- check sorted source positions

## Not supported

- generate an argsort result
- accept partial or one based indices

## Behavior

- Keys are canonical base-10 integer strings; negative zero is rejected, and null follows every integer.
- The expected permutation orders by key and then by ascending source index for ties, implementing ECMA-262 sort stability.
- Claimed indices are zero-based; the first mismatch is the lowest claim position and no replacement permutation is returned.
- Every verdict names ECMA-262-2026-draft-Array.prototype.sort.

## Input

- `source_keys` (array of string or null, required): min items 1; max items 4096; each max length 40; each pattern `^(0|-?[1-9][0-9]*)$`
- `claimed_indices` (array of integer, required): min items 1; max items 4096; each min 0; each max 4095

## Output

- `valid` (boolean, required)
- `reason` (string, optional): min length 1; max length 80
- `discrepancy` (object, optional)
- `reference_version` (constant "ECMA-262-2026-draft-Array.prototype.sort", required)

## Limits

- max items: 4096
- max key chars: 40

## Example

Request input:

```json
{
  "source_keys": [
    "2",
    "1",
    "1"
  ],
  "claimed_indices": [
    1,
    2,
    0
  ]
}
```

Response:

```json
{
  "result": {
    "valid": true,
    "reference_version": "ECMA-262-2026-draft-Array.prototype.sort"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "stable-sort-indices-check",
  "version": "1.0.0",
  "input": {
    "source_keys": [
      "2",
      "1",
      "1"
    ],
    "claimed_indices": [
      1,
      2,
      0
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/stable-sort-indices-check/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"source_keys":["2","1","1"],"claimed_indices":[1,2,0]}'
```

The machine-readable contract is at [/v1/tools/stable-sort-indices-check/versions/1.0.0](/v1/tools/stable-sort-indices-check/versions/1.0.0).

### CLI

```sh
node cli.mjs run stable-sort-indices-check 1.0.0 --input input.json --base-url https://computefirst.net
```

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

## Related tools

- [Stable sort groups check](/tools/stable-sort-groups-check): Check claimed equal-key groups for exact key order, membership, and stable source order.
- [Stable sort result check](/tools/stable-sort-result-check): Check that a claimed record result is the exact ascending stable sort of the supplied source records.
- [Permutation indices check](/tools/permutation-indices-check): Check whether claimed indices are exactly one occurrence of every source index, reporting the first discrepancy.
- [Precedence order check](/tools/precedence-order-check): Check whether a claimed node order is exactly a precedence-respecting linear extension of a caller-supplied DAG.
- [Join inner result check](/tools/join-inner-result-check): Check a claimed ordered inner join index result and report its first discrepancy.
- [Join left result check](/tools/join-left-result-check): Check a claimed ordered left join index result and report its first discrepancy.
