STXT - Semantic Text
Built for humans. Reliable for machines.

STXT Schema and Template Resolution

1. Introduction
2. Terminology
3. The `.stxt` directory
4. The resolution chain
5. Precedence
6. The `STXT_PATH` environment variable
7. Per-document resolution
8. Resolution errors
9. Conformance
10. Security Considerations
11. End of Document

1. Introduction

This document defines STXT Discovery: the mechanism by which a tool locates, on the file system, the @stxt.schema and @stxt.template documents applicable to an STXT document.

The STXT-SCHEMA-SPEC and STXT-TEMPLATE-SPEC specifications define how definitions are written and how they validate; they deliberately do not say where they live. This specification fills that gap with a single goal: that the same document validates against the same definitions in every tool — an editor, a command line, a continuous integration process. If every tool searched for definitions its own way, the outcome of validating would depend on who validates.

Resolution is identical for schemas and templates: both are discovered by the same procedure and compete for the same namespaces.

In the rest of the specifications, this document is referenced as STXT-DISCOVERY-SPEC.

2. Terminology

The keywords "MUST", "MUST NOT", "SHOULD", "SHOULD NOT", and "MAY" must be interpreted according to RFC 2119.

Terms such as node, namespace, schema and template retain their meaning in STXT-SPEC, STXT-SCHEMA-SPEC and STXT-TEMPLATE-SPEC.

Additional definitions:

3. The `.stxt` directory

A resolution directory is a directory named exactly .stxt.

4. The resolution chain

For a given document, the resolution chain is built in this order, from highest to lowest precedence:

  1. Project level: the .stxt directories found by walking up from the document's directory to the root of the file system, from nearest to farthest.
  2. User level: the .stxt directory in the user's home folder.
  3. System level: the machine-wide definitions directory.

4.1 Project level

Starting from the directory containing the document, the tool MUST examine that directory and each of its ancestors, in ascending order, and add to the chain every .stxt directory that exists.

4.2 User level and system level

Level Linux, macOS and other Unix Windows
User $HOME/.stxt %USERPROFILE%\.stxt
System /etc/stxt %ProgramData%\stxt

5. Precedence

Once every level of the chain is loaded, precedence applies per target namespace, not per whole directory:

For the scope of this specification, this rule pins down the schema-versus-template prioritization criterion that STXT-TEMPLATE-SPEC leaves open to the implementation: the effective semantic source of a namespace is its active definition.

5.1 Complete example

/home/ana/
├── .stxt/                       (user level)
│   └── notes.stxt               defines org.ana.notes
└── projects/monorepo/
    ├── .stxt/                   (project level, 2nd)
    │   ├── common.stxt          defines com.acme.common
    │   └── web-old.stxt         defines com.acme.web
    └── web/
        ├── .stxt/               (project level, 1st)
        │   └── web.stxt         defines com.acme.web
        └── index.stxt           document to validate

The resolution chain of index.stxt is, in order: web/.stxtmonorepo/.stxt/home/ana/.stxt/etc/stxt.

Result per namespace:

6. The `STXT_PATH` environment variable

If the STXT_PATH environment variable is defined, it completely replaces the resolution chain of section 4: no project, user or system level is searched.

STXT_PATH exists for environments where the implicit search gets in the way: continuous integration, the tools' own tests, or environments with a restricted file system.

7. Per-document resolution

The resolution chain is defined per document: it is a function of the document's location and the environment, not of the tool or of the set of documents being processed.

A tool that processes several documents at once (an editor with several open files, a command line with several arguments) MAY share loads and caches as an optimization, but the result MUST be identical to resolving each document separately. In particular, if two documents from different projects see different definitions for the same namespace, each one MUST be validated with its own.

A tool MAY offer explicit mechanisms to designate definitions (a command-line option, editor configuration). What is designated explicitly MUST take precedence over what this specification discovers.

8. Resolution errors

A tool MUST report as a resolution error:

  1. Two definitions for the same target namespace at the same level.
  2. A file under a resolution directory that does not parse as STXT.
  3. A file whose root node belongs neither to @stxt.schema nor to @stxt.template.
  4. A definition that does not validate against its meta-schema (STXT-SCHEMA-SPEC, STXT-TEMPLATE-SPEC).

Rules:

9. Conformance

10. Security Considerations

11. End of Document