Free, for Twine authors

twee-tools

twee-tools is a command-line tool for Twine stories. It turns Twee, Twine's plain-text format for writing a story in a text editor, into a page to play, as Tweego does, with SugarCube, Harlowe, Chapbook and Snowman built in. Every time it builds, it checks the whole story, so you find the broken links, misspelt macros and missing pictures, not your players.

macOS and Linux
$ curl -fsSL https://github.com/IFLoom/twee-tools/releases/latest/download/install.sh | sh
Windows, in PowerShell
$ irm https://github.com/IFLoom/twee-tools/releases/latest/download/install.ps1 | iex
npm, in a Node project
$ npm install --save-dev @ifloom/twee-tools

Then run twee-tools init my-story to start a project, or twee-tools build in a folder of Twee files. Or download a build for Windows, macOS or Linux.

The story checker

Find bugs in your stories and games before players report them

Every time you build, twee-tools build reads all the Twee files in your project and points out what's broken or looks wrong: links to passages that aren't there, macros left open, a variable spelt two ways, a picture that's missing. If it finds an error, it doesn't build. Writing in the Twine editor rather than in Twee? Run twee-tools check on the HTML file Twine publishes, and it checks that the same way.

Below, a short SugarCube story with three slips (a link to Beech, an <<if>> left open, and $lammp for $lamp), and what twee-tools build says about it. Switch tab to see twee-tools check on the same story as the Twine editor publishes it.

src/story.twee
1:: StoryTitle
2The Lighthouse
3
4:: StoryData
5{
6  "ifid": "5E2B7C41-9A3D-4F6E-8B21-7C0D4A9E3F18",
7  "format": "SugarCube",
8  "format-version": "2.37.3",
9  "start": "Shore"
10}
11
12:: StoryInit
13<<set $lamp to false>>
14<<set $oil to 2>>
15
16:: Shore
17Waves break against the rocks below the lighthouse.
18[[Climb the stairs|Stairs]]
19[[Walk along the beach|Beech]]
20
21:: Stairs
22<<if $oil gt 0>>
23You have enough oil to light the lamp.
24[[Light the lamp|Lamp room][$lamp to true; $oil -= 1]]
25[[Go back down|Shore]]
26
27:: Lamp room
28<<if $lammp>>The beam sweeps across the water.<</if>>
29[[Go back down|Shore]]
30
31:: Beach
32Shells crunch underfoot. [[Back to the shore|Shore]]
~/the-lighthouse — twee-tools build
$ twee-tools build

 The Lighthouse  SugarCube 2.37.3
 5 passages · 45 words · 6 links · 5 macros · 3 variables · 0 media files
 read from 1 Twee file

 ERRORS

 ✖ Broken links · 1
   Shore  story.twee:19
     The link goes to "Beech", and there's no passage by that name
     → did you mean "Beach"?

 ✖ Macros never closed · 1
   Stairs  story.twee:22
     <<if>> is never closed

 WARNINGS

 ⚠ Passages nothing leads to · 1
   Beach  story.twee:31

 ⚠ Variables read, and never set · 1
   $lammp  in Lamp room · story.twee:28  → did you mean $lamp?

 ✖ 2 errors   ⚠ 2 warnings

 Not built: the story has errors. Fix them, or build anyway with --no-check.

$ 
One program

Build, check, play and shrink

Four commands, each run in a terminal in your story's folder.

Build

twee-tools buildTurns your Twee files into one HTML file to play or publish. SugarCube, Harlowe, Chapbook and Snowman are built in, so there’s nothing else to install.

Check

twee-tools check story.htmlRuns the same checks on an HTML file published from the Twine editor, so you can check a story that has no Twee at all.

Play as you write

twee-tools devShows your story in the browser and reloads it every time you save. If something breaks, the page says what, and keeps the last version that worked.

Shrink

twee-tools compressMakes a copy of your story for release with its pictures converted to WebP, usually a third of the size or less, and the story changed to use them.
What the checks find

Checks that know your story format

  • Links and <<goto>> macros to passages that aren’t there, and the name you probably meant.
  • Passages nothing leads to, and dead ends with no way forward.
  • Macros misspelt or never closed, and markup from another story format, such as Harlowe’s (set:) in a SugarCube story.
  • Variables read but never set, or set and never read.
  • JavaScript in a passage, a link or the story’s script that doesn’t parse.
  • Pictures, sounds and videos that aren’t there, have the wrong extension, or are too large.

Each story format reads its markup its own way, so twee-tools checks SugarCube, Harlowe, Chapbook and Snowman each by that format's rules, and knows each format's macros by name. It points at the file and line in your Twee, and suggests the name you probably meant.

Errors stop the build; warnings don't, unless you ask them to. To check a story automatically, such as on every push to GitHub, run twee-tools build --check-only --strict, which fails on warnings too; --json writes the report as JSON for other tools.

Speed

Fast, even with thousands of passages

twee-tools is written in Rust and compiled to one native program, so builds take a blink, even for a very large story, and its checks run side by side on every core. Below, the median time each tool takes to build the same SugarCube story on Linux. Extwee and twee-ts are two other Twee compilers. twee-tools' checks are off here, for a like-for-like race; with them on, it checks a 20,000-passage story in 0.17 s, less than Tweego takes just to build it.

A released game, as Twee: 914 passages, 7 MB
twee-tools
42 ms
Extwee 2.4.3
171 ms
Tweego 2.1.1
182 ms
twee-ts 2.1.0
1,001 ms
20,000 passages in 50 files
twee-tools
52 ms
Tweego 2.1.1
852 ms
Extwee 2.4.3
1,210 ms
twee-ts 2.1.0
1,274 ms
Coming from Tweego

Switching from Tweego

If you build with Tweego now, twee-tools reads the same project and writes the same page, so switching is mostly a change of command.

TopicTweegotwee-tools
Buildtweego -o out.html srctwee-tools build src -o out.html, or twee-tools build with a twee.toml
Watchtweego -wtwee-tools dev, which serves and reloads too, and keeps going after an error
Story formatsInstalled by handBuilt in. Installed ones are still found, and a project can carry its own copy
CheckingNoneEvery build checks first; --check-only checks without building
Decompilingtweego -d story.htmltwee-tools decompile story.html
One version per projectWhichever each person installedtwee-tools = "0.1.1" in twee.toml: any other version downloads that one, once, and runs it instead
Story dataWhat Tweego 2.1.1 writesThe same, byte for byte, apart from the attributes of <tw-storydata>
We ♥ Twine

Twine is where IFLoom started

IFLoom exists because of Twine. Its stories, and the way it lets anyone write one, are what made us want to build an engine of our own in the first place.

twee-tools is our way of giving a little back: free tools for Twine authors, to make writing in Twee quicker and less error-prone. It works with your story as it is, with the story formats the community made, and it doesn't ask you to switch to anything.

If Twine has given you a story, help keep it going: twinery.org and the Interactive Fiction Technology Foundation.

With thanks to

  • Twine, and the Interactive Fiction Technology Foundation, which looks after it
  • SugarCube, Harlowe, Chapbook and Snowman, whose authors made the story formats twee-tools builds with
  • Tweego, which showed what Twee from the command line could be
  • The community, behind the Cookbook, the forums and the games themselves
From the makers of IFLoom

When a story grows into a game

IFLoom, our engine for interactive fiction written in TypeScript, is for when a story becomes a game with systems: a clock and a week, places to go, people on their own schedules, money, jobs and shops.

If you like what twee-tools does for a story, IFLoom does it for a whole game: a checker that reads everything each time you build, plain files you keep in git, and one HTML file to publish that opens from disk. On top of that come types as you write, tests that play the game for you, and saves that still load after an update.

Questions

Before you install

Does it replace Twine?

No. Keep writing in Twine if you like its map of passages. twee-tools reads Twee, the plain-text form of a story, which Twine 2.6 and later can export, and twee-tools check checks the HTML file Twine publishes, with no Twee at all.

Will my Tweego project build the same?

Yes. It reads the same folders, finds story formats where Tweego looks, and writes the same story data as Tweego 2.1.1, byte for byte, apart from the attributes of <tw-storydata>. Most options have the same name.

Which story formats does it check?

SugarCube 2, Harlowe 3, Chapbook 2 and Snowman 2, each by its own rules, worked out from how the format itself reads a story. Stories in other formats build too.

Do I have to use the command line?

Yes: twee-tools runs in a terminal, such as Terminal on macOS or PowerShell on Windows. The commands are short, and twee-tools dev shows your story in the browser as you write.

Can everyone on a project use the same version?

Yes. Put twee-tools = "0.1.1" in the project’s twee.toml, and any other version of twee-tools run there downloads that one, once, checks it, and builds with it instead, so everyone and your CI get the same build. In a Node project, npm install --save-dev @ifloom/twee-tools does the same through your lock file.

Do I need IFLoom, or Node?

No. twee-tools is one program, written in Rust, for Windows, macOS and Linux with nothing else to install, and it doesn’t use IFLoom at all. npm is just one way to get it, for projects that already use Node.

Is it free?

Yes. It’s open source under MIT or Apache-2.0, at your choice. The story formats built into it keep their own licences, which twee-tools formats licenses prints.