# skopos

`skopos` is the command line tool for [OpenSkopos](https://github.com/openskopos/openskopos) documents. The tool reads and writes the files. The library [`skopos-core`](https://openskopos.org/docs/rust/) does all other work.

The commands are in the library of this crate (`src/lib.rs`). They read and write the files and the terminal through the trait `Host`. The `skopos` binary implements `Host` with the Rust standard library. The WebAssembly build in [`skopos-wasm`](https://github.com/openskopos/openskopos/blob/main/crates/skopos-wasm/README.md) implements `Host` with Node. So the npm package `@openskopos/cli` has the same commands, output and exit codes.

## Install

With Homebrew on macOS or Linux, run:

``` bash
brew install openskopos/tap/skopos
```

If you have a Rust toolchain, install the tool from crates.io:

``` bash
cargo install --locked skopos
```

[docs/install.md](https://openskopos.org/docs/install/) has the install scripts for the shell and PowerShell, and the binaries for each platform. To install the tool from a clone of the repository, run `cargo install --locked --path crates/skopos` from the root of the repository.

The npm package [`@openskopos/cli`](https://openskopos.org/docs/npm-cli/) has the same tool for Node. To use it without installing anything, run `npx @openskopos/cli check FILE`.

## Commands

A file name must end with `.json`, `.yaml`, `.yml` or `.md`. A `.md` file is Markdown, with the layout of section 10 of the specification. The commands `check`, `convert` and `import` read Markdown. The commands `fmt` and `ids` read only JSON and YAML.

The Markdown reader accepts many different ways to write the same thing, so a file written by hand does not produce a long list of errors. It fills in only bookkeeping fields, such as the artifact ID. If the front matter has no `kind`, the reader takes it from a file name in capital letters: `INTENT.md` has the kind `intent`. The reader writes a warning to standard error for each thing that it skips or changes:

    SPEC.md: warning: line 16: FR5 appears twice, so the second item gets a new ID

### check

`skopos check` finds the problems in one or more documents. It checks each document against the JSON Schema and the rules in section 9 of the specification.

``` bash
skopos check intent.skopos.json spec.skopos.yaml
```

The tool writes one line for each problem, and under it a hint that says what to do:

    spec.skopos.yaml: /items/2/id: the item ID S1 is also the ID of /items/1 [unique-item-ids]
      Two items have the ID S1. Give the second one a new ID, such as S4.
    spec.skopos.yaml: /items/5: "modality" is a required property
      C1 needs a modality: always, never, ask_first, prefer or avoid.

The line has the file name, the location in the document as a JSON Pointer, and the message. If the problem is with a rule of section 9, the line ends with the name of the rule. If the message says enough, there is no hint line. If a document has a problem, the exit code is 1.

Some problems have a fix that needs no choice from a person. For example, a counter in `id_counters` that is too low gets the highest number in use, and the second of two items with the same ID gets the next free ID. A value such as `Accepted` or `ask first` becomes `accepted` or `ask_first`. A missing `$schema`, document `status` (`draft`) or item `status` (`proposed`) is added. `skopos check --fix` applies these fixes, writes each JSON or YAML file again in the canonical layout, and names each fix:

    spec.skopos.yaml: fixed: Give the second S1 the ID S4
    spec.skopos.yaml: /items/5: "modality" is a required property
      C1 needs a modality: always, never, ask_first, prefer or avoid.

The other problems stay, and the exit code is 1 while any are left. `--fix` does not change Markdown files.

For a Markdown file, the message starts with the line number in the file:

    INTENT.md: line 6: priority 'urgent' is not one of: must, should, could
    INTENT.md: /items/0: line 5: "modality" is a required property

With `--json`, the tool writes a JSON list with one entry for each file:

``` json
[
  {
    "file": "spec.skopos.yaml",
    "problems": [
      {
        "path": "/items/2/id",
        "rule": "unique-item-ids",
        "message": "the item ID S1 is also the ID of /items/1",
        "hint": "Two items have the ID S1. Give the second one a new ID, such as S4.",
        "fix": {
          "label": "Give the second S1 the ID S4",
          "patch": [
            { "op": "add", "path": "/items/2/id", "value": "S4" },
            { "op": "add", "path": "/id_counters/S", "value": 4 }
          ]
        }
      }
    ]
  }
]
```

For a schema problem, `rule` is `null`. `fix` is there only when the problem has a certain fix. Its `patch` is a list of JSON Patch operations (RFC 6902). With `--fix --json`, each file also has `fixed`: the fixes that the tool applied.

### fmt

`skopos fmt` writes each file again with the canonical layout. Each file keeps its format. The keys of the document are in the order of section 3 of the specification. The keys of each item are in this order:

1.  `id`, `type`, `text` and `status`.
2.  The fields of the item type, in the order of section 4.
3.  `refs`, `evidence`, `proposed_by`, `ratification` and `detail`.
4.  The `x-` keys.

In JSON, the indent is two spaces. In YAML, dates, times and the keys `"yes"` and `"no"` are in quotes, as section 2.2 of the specification requires. The tool removes comments from YAML files.

``` bash
skopos fmt intent.skopos.json
```

With `--check`, the tool changes nothing. It lists each file that is not in the canonical layout, and exits with code 1 if there are any.

### convert

`skopos convert` writes a document in a different format: `json`, `yaml` or `markdown` (or `md`). The data does not change.

``` bash
skopos convert --to yaml intent.skopos.json -o intent.skopos.yaml
skopos convert --to md intent.skopos.json -o INTENT.md
skopos convert --to json INTENT.md -o intent.skopos.json
```

Without `-o`, the tool writes the document to standard output.

A Markdown file keeps every field of the document. It does not keep the order of items across types, because Markdown groups the items by section.

A Markdown file can also include material from other artifacts, so an agent that reads the file does not need the other files (section 10.7 of the specification). To include it, pass each of the other documents with `--input`:

``` bash
skopos convert --to md spec.skopos.json --input glossary.skopos.json -o SPEC.md
```

The tool copies these items:

- The accepted terms of each pinned glossary.
- The accepted constraints of each pinned `agent_rules` artifact.
- Each item that a ref of the document points to.

Readers ignore this copied material.

### import

`skopos import` reads an edited Markdown file together with the stored version that it came from, and writes the version to store next, as section 10.8 of the specification says:

- If the stored version is final and the content did not change, the result is the stored version.
- If the stored version is final and the content changed, the result is the next version as a draft. Its first parent is a `previous_version` parent that points to the stored version.
- If the stored version is a draft, the file replaces it. The draft keeps its version number.

``` bash
skopos import INTENT.md --stored intent.skopos.json -o intent.skopos.v3.json
```

The tool writes a summary to standard error, for example `INTENT.md: new draft version 3`. Without `-o`, the tool writes the document to standard output, in the format of the stored version. The result always has the artifact ID of the stored version.

### ids

`skopos ids` adds an ID to each item that has no ID, and updates `id_counters`. An item has no ID if its `id` is absent, `null` or empty. The tool gets the prefix from the `type` of the item, and the number from the counter, as section 7 of the specification says. If a counter is less than the highest ID number of its prefix, the tool first increases the counter to that number.

To add an item by hand, leave out its `id` and run the tool:

``` yaml
items:
- type: constraint
  text: Ask before adding a database migration.
  status: proposed
  modality: ask_first
  approver: Tech lead
```

``` bash
skopos ids intent.skopos.yaml
```

The tool writes each change, for example `intent.skopos.yaml: /items/0 gets C4, id_counters changes`. Changed files are written in the canonical layout.

With `--check`, the tool changes nothing. It lists each file that needs IDs, and exits with code 1 if there are any.

### export

`skopos export` turns a document into the files of a spec-driven development tool: [OpenSpec](https://github.com/Fission-AI/OpenSpec), [Kiro](https://kiro.dev) or [Spec Kit](https://github.com/github/spec-kit). A team can keep its decisions in OpenSkopos and still hand them to the tool that its agents use.

``` bash
skopos export spec.skopos.json --to openspec
skopos export spec.skopos.json --to kiro --name seat-limits
skopos export spec.skopos.json --to speckit -o ../billing
```

| Tool | Files |
|----|----|
| `openspec` | `openspec/changes/<name>-v<version>/`: `.openspec.yaml`, `proposal.md`, `design.md` and a spec delta in `specs/<capability>/spec.md` |
| `kiro` | `.kiro/specs/<name>/`: `requirements.md` and `design.md` |
| `speckit` | `specs/<NNN>-<name>/`: `spec.md`, `plan.md` and `research.md` |

- `-o` is the root folder of the project. The default is the current folder.
- `--name` is the name of the change or feature. Without `--name`, the tool makes the name from the title of the document.
- For Spec Kit, `--number` sets the feature number. Without `--number`, the tool uses the number of a folder in `specs/` that has the same name. If there is no such folder, it uses the next free number.
- The tool does not overwrite existing files unless you pass `--force`. With `--force`, the tool also removes the files of an earlier export that this export does not write, so no stale items stay behind.
- `--dry-run` lists the files without writing them.
- For OpenSpec, the tool reads `openspec/specs/` and the open changes. A later export writes MODIFIED and REMOVED requirements for the items that earlier exports put into the specs. If an earlier export is not archived, the tool stops with an error. See [docs/exporters.md](https://openskopos.org/docs/exporters/#openspec).
- For Spec Kit, the tool prints the `.specify/feature.json` setting that points Spec Kit at the exported feature. It does not change that file itself.

The tool exports only accepted items. Each exported line ends with the reference string of its item, for example `pa_2Xc5Rv8Tn1Mb4Kz7@3#FR4`. The tool puts these items in a "Not exported" note in the files:

- Items that have no equivalent in the other tool.
- Items that are proposed or rejected.

The tool also writes this list to standard error. [docs/exporters.md](https://openskopos.org/docs/exporters/) shows where each item type goes.

The document can be JSON, YAML or Markdown, and it must be valid. If `skopos check` finds a problem, the tool exports nothing.

### diff

`skopos diff` compares two versions of an artifact, item by item. An item ID means the same item in every version, so the tool compares the items that have the same ID.

``` bash
skopos diff spec-v2.skopos.json spec-v3.skopos.json
```

Each file can be JSON, YAML or Markdown, so `skopos diff spec.skopos.json SPEC.md` shows what a hand edit of the Markdown file changed.

    pa_2Xc5Rv8Tn1Mb4Kz7@2 -> pa_2Xc5Rv8Tn1Mb4Kz7@3
    envelope   summary
    added      FR4  A plan change that leaves more seats in use than the new limit is blocked.
    changed    A1   confirmation, evidence, text
    changed    Q1   status (status proposed -> rejected)
    superseded FR2  by FR4
    dropped    N2   Emails to members above the limit.

| Line | Meaning |
|----|----|
| `added` | The ID is only in the new version. |
| `changed` | The ID is in the two versions, and the fields after the ID are different. If only the order of the items or of the `refs` is different, the item did not change. |
| `superseded` | The ID is only in the old version, and an item of the new version points to it with `supersedes`. A rejected item does not supersede an item. |
| `dropped` | The ID is only in the old version, and no item supersedes it. |
| `envelope` | The fields of the document that are different, for example `title` or `summary`. The tool does not compare `version`, `status`, `parents`, `created_at`, `finalized_at`, `method`, `session` and `id_counters`. |

With `--json`, the tool writes the differences as JSON. The exit code is 0 when both documents are valid, even if they differ.

### history

`skopos history` reads versions of one or more artifacts and shows what each version decided, then the items that are in force now. Give the files in any order. Each file can be JSON, YAML or Markdown, and it must be valid.

``` bash
skopos history specs/*.skopos.json
```

    Seat limits (spec pa_4Hs8Lm2Qx6Vr9Tc3)
      version 1  final  2026-11-11  3 items
      version 2  final  2026-11-12  4 items
        added      FR2  Admins get an email after each plan change.
        changed    FR1  status, text (status proposed -> accepted)
        changed    Q1   status (status proposed -> rejected)
      version 3  final  2026-11-13  3 items
        added      FR3  A plan change that leaves too many seats is blocked.
        superseded FR1  by FR3
        dropped    FR2  Admins get an email after each plan change.

    In force now
      pa_4Hs8Lm2Qx6Vr9Tc3@3
        G1   No user loses access by surprise when the org changes plan.
        FR3  A plan change that leaves too many seats is blocked.

The lines under a version are the lines of `skopos diff` between that version and the one before it. A missing version is a warning, not an error. When a second team starts a new artifact with the first one as an `input` parent, the first artifact comes first, and an item of the new artifact that supersedes an item of the first one shows under its version. Section 8.3 of the [specification](https://openskopos.org/spec/0.2/) says how the tool reads a history.

With `--since 2`, the tool shows only the versions after version 2. With `--json`, it writes the whole history as JSON, with the steps of each item.

### trace

`skopos trace` shows the life of one item: each version that changed it, its state now, and the items that replace it, with their rationale, detail and evidence.

``` bash
skopos trace pa_4Hs8Lm2Qx6Vr9Tc3#FR1 specs/*.skopos.json
```

    pa_4Hs8Lm2Qx6Vr9Tc3#FR1  requirement
    now: superseded by pa_4Hs8Lm2Qx6Vr9Tc3@3#FR3 (last in pa_4Hs8Lm2Qx6Vr9Tc3@2)

    version 1  added       proposed
        A plan change that leaves too many seats shows a warning.
    version 2  changed     status, text (status proposed -> accepted)
        A plan change that leaves too many seats shows a warning with the count.
    version 3  superseded  by FR3

    pa_4Hs8Lm2Qx6Vr9Tc3@3#FR3 (accepted)
      A plan change that leaves too many seats is blocked.
      detail: A warning was not enough: admins ignored it.

The version in the reference string is not needed, because an item ID means the same item in every version. An item ID alone, such as `FR2`, works if only one artifact has it. If the first version that you give is not version 1, its items show as `seen`, because they can be older. The exit code is 1 if no file has the item.

### merge

`skopos merge` merges two documents into one. The team picks one document as main. The result is the next version of main, as a draft, with the other document as an `input` parent. Section 8.4 of the [specification](https://openskopos.org/spec/0.2/) describes the merge.

``` bash
skopos merge main.skopos.json other.skopos.json --base v1.skopos.json -o merged.skopos.json
```

The tool writes the merged document, and a summary to standard error:

    pa_5Qk9Ts3Hv7Mw2Zd8@2 + pa_8Rc2Nx6Jb4Pf1Lu5@1 -> pa_5Qk9Ts3Hv7Mw2Zd8@3 (draft)
    new        FR3  from FR1 of the other document
    envelope   title (main kept)
    1 conflict:
      FR1 or FR3: text

- With `--base`, the common earlier version, items with an ID of the base pair by ID. A field that only one document changed merges by itself.
- Without `--base`, for example for two drafts from the same input, items of the same type with similar text pair. The summary shows each pair, such as `paired     FR1 = FR2 (text, 96%)`. If a pair is wrong, merge again with `--pair MAIN_ID=OTHER_ID` for each pair that is right. Then no other items pair.
- An item of the other document that is new in the result gets a new ID from the counters of main, and a `derived_from` ref to where it came from. Refs to it are rewritten.
- A conflict is never a marker in the text. Both items stay as `proposed`, and the item of the other document has a `contradicts` ref to the item of main. So the merged file is always a valid document.

The result is in the format of main, or in the format of the `-o` file. With `--json`, the tool writes the whole result as JSON: the document, the pairs, the conflicts, the new IDs and the envelope fields that are different.

### conflicts and resolve

`skopos conflicts` lists the conflicts of a merged document that are still open. The exit code is 1 while a conflict is open, so CI can stop a merge that is not finished.

``` bash
skopos conflicts merged.skopos.json
```

    FR1 or FR3: text

`skopos resolve` accepts one item of a conflict and rejects the other one, and writes the file again. The rejected item stays in the record. You can also set `status` in any editor.

``` bash
skopos resolve merged.skopos.json FR3
```

### render

`skopos render` shows a document for people to read: text in the terminal, or an HTML page with `--html`. With `--previous`, it marks what changed since an earlier version.

``` bash
skopos render spec.skopos.yaml
skopos render spec-v3.skopos.json --previous spec-v2.skopos.json --html -o spec.html
```

    Σ• Spec · version 3 · draft
    Spec: seat limits on plan changes

    17 items: 15 accepted, 1 proposed, 1 rejected.
    Since version 2: 6 added, 5 changed, 1 superseded.

    Requirements (2)
    + FR4  A plan change that leaves more seats in use than the new limit is
           blocked. [must]
           supersedes: FR2
      FR3  The seat count never goes below zero. [should]

The text has colors only when the output is a terminal and `NO_COLOR` is not set. `--width` sets the width of a line. For HTML, `--no-style` leaves out the default stylesheet, `--css FILE` adds your CSS, and `--fragment` writes only the document element. See [docs/render.md](https://github.com/openskopos/openskopos/blob/main/docs/render.md) for the class names and the CSS custom properties.

## License

[Apache License 2.0](https://github.com/openskopos/openskopos/blob/main/LICENSE)
