summaryrefslogtreecommitdiff
path: root/README.md
blob: f6263885c39a59d5a0ded7aec3b29600837e06c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Write_Away

<img src="assets/Write_Away.svg" alt="Two quotation marks shaped like pen nibs" width="100">

A Mac writing tool that keeps the other ways you tried to say something. A word, a
sentence or a paragraph can hold several versions, and you flip through them in place, in
the sentence they have to live in. Text you doubt can be dimmed instead of deleted. Lines
that don't belong go to a panel beside the page. It all saves to one Markdown file.

The idea is Jason Fried's. He showed it as
[Write_On](https://x.com/jasonfried/status/2105403067793584590), called it “alternative control”, and [demonstrated AI alternatives](https://x.com/jasonfried/status/2105427261461758238/video/1). Write_Away is a prototype of the same
idea in Zig and AppKit, written without his code. The behavior and the colors follow
[joeysim/write-on-replica](https://github.com/joeysim/write-on-replica), whose design notes
describe his clips in detail. It is not connected with him or with 37signals.

## Build and run

Use Zig **0.16.0**, the Xcode Command Line Tools, and a sibling checkout of `libpantograph` at `../libpantograph`. Tested on Apple silicon. If Homebrew supplies a newer Zig, use `export PATH=/opt/zig:$PATH` with the 0.16 installation here.

```sh
zig build                      # zig-out/Write_Away.app
open zig-out/Write_Away.app
zig build run -- piece.md      # open a piece, or start one at that path
zig build test                 # the document model, then the app driven with no window
```

## Using it

| Keys | What happens |
| --- | --- |
| Ctrl+Shift+A | Open alternatives for the word or selection. Pick Word, Sentence, or Paragraph; move between rows to hear and see each version in context. Return adds a row; Escape closes. |
| Ctrl+Shift+G, or `??` alone on a panel row | Ask for alternatives without replacing the version on the page. |
| ⌘, | Set the inference API style, base URL, model and key. |
| ← → ↑ ↓ with the pointer on underlined text | Flip through its versions. Typing gives the arrows back to the caret. |
| Delete with the pointer on underlined text | Throw out the version showing. |
| Ctrl+] and Ctrl+[ | Flip the group the caret is in, without the pointer. |
| Ctrl+/ | Ghost the selection or the word. On ghosted text, revive it. |
| Ctrl+Shift+X | Stash the selection, or the paragraph, in Overflow. |
| Ctrl+Shift+D | Show or hide Overflow. Drag its left divider to resize it; closing and reopening keeps the width. |
| Ctrl+Return | Move Overflow's selection, or its paragraph, to the caret in the page. |
| Ctrl+Shift+R, or click the word count | Put the tools away and read. |
| ⌘N ⌘O ⌘S ⇧⌘S ⌘Z ⇧⌘Z | New, Open, Save, Save As, Undo, Redo. |

Right-click the page for alternatives, AI alternatives, ghost/revive, or Overflow. While the panel is open, the surrounding text dims. A word’s versions have a wavy violet underline; a sentence’s have a pink one. Paragraphs get a bar in the margin. Dots show the active version, and a lower tick marks a return to the version you started on. Flipping a word adjusts a preceding *a/an* where the pronunciation can be guessed. Heading hashes stay in the file, not on the screen.

## The Lab

Choose **Lab** in the bottom bar. A pass can mark weak, long, or convoluted sentences, changes of tone, or filler. Punctuation and typo fixes are proposals until you apply them. **Next** visits the next passage; **Keep** leaves it alone.

The four trims aim for about 10%, 20%, 30%, or 50%. They ghost proposed cuts using the same ghosts you can make yourself. **Save** at that point to publish without the ghosted words and still recover them in Write_Away. **Original** revives the pass’s remaining proposals, not your manual ghosts. **Apply rest** removes the remaining cuts from the editor too; Undo brings them back. Editing the draft closes the review, leaving existing ghosts in place.

## Inference (optional)

Choose **Write_Away → Inference…**, or configure it on your first `??`. For alternatives, the request sends the target, its paragraph and the variants already tried. Choosing a Lab pass sends the numbered draft text (including ghosted words, not Overflow or unselected alternatives). Ordinary editing and saving make no requests. The app asks for five word alternatives or three longer ones. A robot marker identifies suggestions. Anthropic Messages, OpenAI Chat Completions, OpenAI Responses and Google Interactions are available via libpantograph. Use HTTPS for remote endpoints.

The key is **not in Keychain**: it is stored unencrypted in `~/Library/Application Support/Write_Away/inference.json`, mode `0600`. Save an empty key to remove it. The other settings live in the `local.write-away` preferences domain. When upgrading from a differently named build, re-enter your inference settings or copy your existing `inference.json` into this directory with mode `0600`.

## The file

```markdown
<!-- overflow
(Stashed paragraphs.)-->
<!-- write_away {"v":2,"groups":[],"ghosts":[{"at":31,"text":" Maybe cut this."}],"visible_sha256":"9cb2aa331991f33454e5e5339c985df756e0bbaaed21ad2c0207b327641a92d0"} -->

# A draft

The tension is real.
```

Ordinary Markdown renders only the visible draft. Manual and Lab ghosts are removed
from the visible bytes and stored in the leading `write_away` comment, along with any
alternatives. Overflow has its own leading comment: `&#38;` represents `&` and `&#45;`
represents `-` inside its parentheses. These are Write_Away escapes, not Markdown
escapes. All hidden text is still readable in the file source.

Write_Away preserves the visible bytes exactly after the blank line that separates the
comments from the draft. A file with no Overflow, alternatives or ghosts is saved
unchanged. With metadata present, comments precede even YAML frontmatter; its bytes
are preserved, but tools that require frontmatter on the first line may not recognize it.

Files record UTF-8 byte offsets into the restored editor body. While editing, ghosts are attributes on the text itself; Save computes fresh offsets. A fully ghosted alternative stays ghosted when swapped. If a replacement crosses a ghost boundary, revive the ghosted part first: Write_Away won’t guess which words in another version should be hidden.

If a file has ghosts and its visible
bytes change outside Write_Away (even just a newline), Write_Away opens the original
Markdown as-is, with its comments intact, rather than guessing where to put the ghosts.
Without ghosts, alternatives can still follow matching text after an outside edit.
Legacy Overflow trailers and v1 records are supported. For drafts saved under an earlier app name, change only the identifier on the metadata comment to `write_away` before opening; leave its JSON and the draft text unchanged.

## Not here yet

A separate Markdown view, source-stripped public export, sharing/posting, deletion animations, crash recovery, and multiple windows are not implemented.

## The code

- `src/doc.zig` and `src/ghost_io.zig`: variants, recoverable ghosts, and the Markdown format.
- `src/lab.zig` and `src/lab_ui.zig`: map model suggestions to draft passages and present them for review.
- `src/main.zig`: the app. The page is an `NSTextView`; two custom text attributes mark
  groups and ghosts, and everything drawn is derived from them.
- `src/ai.zig`: one inference request via libpantograph and local key storage.
- `src/objc.zig`: the Objective-C runtime calls that make AppKit reachable from Zig.