Skip to main content

tos-toolkit

Static analysis, scaffolding, and adversarial review for ThinkScript (thinkorswim) code.

ThinkScript has no compiler you can run in CI, no package manager, and no module system. This toolkit gives you the parts that can be automated, and is explicit about the part that cannot:

$ tos lint                  # structural checks — no thinkorswim needed
$ tos syntax-check          # real grammar check — needs a local thinkorswim
$ tos review --mode diff    # adversarial AI review of your changes

Everything except syntax-check runs on a bare Python install with no thinkorswim anywhere in sight.


Install

$ pip install -e .        # local
$ pip install "tos-toolkit[parser]"                 # marks the grammar-check requirement

Requires Python 3.11+. The core has zero Python dependencies.

tos syntax-check additionally requires a locally installed thinkorswim and a JDK. Nothing from thinkorswim is bundled or redistributed — see ADR 0004.


Quickstart

$ mkdir my-tos-scripts && cd my-tos-scripts
$ tos init
$ tos new study trend/ema_cloud_flip
$ tos lint
$ tos status

tos init writes tos.toml, the artifact directories (studies/, scans/, strategies/, columns/), copy-ready templates, a justfile, and appends a conventions section to AGENTS.md.


Commands

Command Needs ToS? Purpose
tos lint [paths] no Structure: headers, delimiters, identifier collisions, artifact rules, unknown functions
tos status no Validation debt — which scripts are still draft
tos new <kind> <path> no Scaffold a file from the bundled templates
tos init no Scaffold a project
tos docs [topic] no The bundled ThinkScript knowledge base
tos explain <name> no Is this function real? What's its confidence?
tos review * Adversarial review of a diff, files, or the whole repo
tos syntax-check yes Grammar validation using the real parser

tos review needs the codex CLI on PATH (pinned model gpt-6.1-sol). harness = "claude" is available as a substitute when Codex is unavailable.

tos lint

$ tos lint --strict          # warnings become failures
$ tos lint --json            # machine-readable
$ tos lint studies/          # one subtree
$ tos --profile loose lint   # language rules only, ignore our conventions

Exit codes: 0 clean, 1 findings at error level, 2 usage or config problem.

tos explain

The registry exists because inventing a ThinkScript function is the single most common mistake — and the platform will reject the whole study for it.

$ tos explain TrueRange
TrueRange  [volatility]  confidence=verified
  TrueRange(high, close, low) - three required arguments

$ tos explain HasOption
HasOption  [option]  confidence=unverified
  internal API only; prefer IsOptionable
  WARNING: unverified. Paste-test before relying on it.

tos docs

$ tos docs --list
$ tos docs gotchas
$ tos docs --grep "crosses above"

The knowledge base ships inside the package, so it is available from any project without locating this repo.


Two layers, and why

The rules are deliberately split. Mixing them is what makes a linter unusable outside its author's repo.

Layer 1 — language-generic (always on). True of ThinkScript anywhere: unbalanced delimiters, // is not a comment, tabs, case-insensitive identifier collisions, rec self-reference depth, unknown function names, and the platform's own artifact restrictions (a scan genuinely cannot call AddLabel).

Layer 2 — house conventions (profile-gated). The # @key: header block, the @status: draft → validated lifecycle, studies/<category>/ layout. Opinionated on purpose, and fully removable.

Pick a profile in tos.toml:

Profile Header block Layout rules Use when
strict (default) required enforced you want the full workflow
loose off off pointing at a corpus you didn't write

Any individual rule can be overridden:

[checks]
unknown_functions = "warn"   # off | warn | error
W090 = "off"                 # silence one code

Configuration

[profile]
name = "strict"

[project]
targets = ["studies", "scans", "strategies", "columns", "templates"]
templates_dir = "templates"

[header]
mode = "required"            # required | optional | off

[parser]
enabled = true
tos_path = "/Applications/thinkorswim"

[review]
harness = "codex"            # codex | claude
model = "gpt-6.1-sol"
effort = "high"

[checks]
unknown_functions = "warn"

Resolution order: built-in profile, then your tos.toml on top.


What this cannot do

Being explicit is the point:

  • It cannot tell you a script works. Only pasting it into thinkorswim and watching it render does that.
  • syntax-check only checks grammar. It will happily accept FooBarNotAFunction(close). Function names, arity, types, and semantics are not validated by it — that is what lint's registry and review are for.
  • It cannot see the future. A study that looks into the future with a negative offset still parses.
  • The registry is curated, not exhaustive. An unknown name is a prompt to verify, not a verdict.

The intended loop is:

tos lint  →  tos syntax-check  →  tos review  →  paste into ToS  →  @status: validated

Only the last step earns the right to call a script validated, and only a human can do it.


Documentation

License

MIT. This project bundles no thinkorswim code.

Metadata

Release files for tos-toolkit 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tos-toolkit 0.1.0
File Size Uploaded Provenance Actions
tos_toolkit-0.1.0.tar.gz 59.1 kB With provenance Details for tos_toolkit-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tos-toolkit 0.1.0
File Interpreter ABI Platform Actions
tos_toolkit-0.1.0-py3-none-any.whl Python 3 none any Details for tos_toolkit-0.1.0-py3-none-any.whl

Total release size: 124.5 kB

Release files / tos_toolkit-0.1.0.tar.gz

Download URL tos_toolkit-0.1.0.tar.gz
Size 59.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fd7a0f25e639fa9b09635c8a4c6ac0365d75bde79343b21f86905c98d7e589b8
BLAKE2b-256 checksum
How to use checksums
d397277054dddf22e4c5ac2815780f4cd2d2bb3a7e6d5c23699f202426e92c44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / tos_toolkit-0.1.0-py3-none-any.whl

Download URL tos_toolkit-0.1.0-py3-none-any.whl
Size 65.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e6da7b08ec8bc73019032aeea0d2bc00bb2fdb20b398c1aa25f82b0d77f0627
BLAKE2b-256 checksum
How to use checksums
48e0de23156832e5ec7aa0f63d568f628b411711fe571ffe57d632620589ebf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for tos-toolkit 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tos_toolkit-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page