Plans: Sparkle updates, windows and panes, file splits, planning cleanup !232

merged merged by cmc on 2026-10-11 03:50 UTC · krz/orgstar:plans-2026-10-10 into main

4 files changed, +490 −0

Layout: unified · split

docs/plans/2026-10-10-file-splits.md added +87
@@ -0,0 +1,87 @@
1# File Splits Implementation Plan
2
3> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
5**Goal:** No hand-written Swift file over 1,000 lines, by moving code between files without changing it, so the next pieces of work (windows and panes first) land in files that fit in one read.
6
7**Architecture:** Each split moves whole `// MARK:` sections or whole types into a new file in the same module as an `extension` of the same type. `private` members that the moved code reaches become internal (no modifier); nothing is renamed, reordered or reworded. One commit per source file, with `swift build` and `swift test` green before and after each.
8
9**Tech Stack:** Swift 6.2, Swift Testing.
10
11**Spec:** this file.
12
13## Global constraints
14
15- Behaviour-preserving: the diff of each commit is moves plus access-level changes only. `git diff --stat` shows a drop in the source file matching the sum of the new files, give or take the `extension` lines.
16- Generated files are exempt and untouched: `Sources/OrgCore/Keymap/CharFold.swift` (from `scripts/update-char-fold.sh`) and `Sources/OrgHighlight/Queries.swift` (from `scripts/update-highlight-queries.sh`).
17- Order: `ContentView.swift` and `OrgEditor.swift` first, since `2026-10-10-windows-and-panes.md` edits both; the rest in any order.
18- Each new file starts with the imports its code needs and nothing else.
19
20## Review focus
21
22- A `private` member made internal must not collide with another internal name in the module: build errors catch it, but check `OrgCore` for duplicate helper names such as `lines`, `trimmed` and `offset` before moving.
23- `@MainActor` on the type carries to its extensions; `nonisolated` and `@objc` methods (`textStorage(_:didProcessEditing:…)`, delegate conformances) must stay in an extension that declares the conformance, or `NSObject` dispatch breaks at run time, not build time: run the app after `OrgEditor` and `MobileEditor` move.
24- Swift Testing suites that use `@testable import` and reach `private` helpers through `fileprivate` test extensions lose access when the helper moves; build the test targets, not just the products.
25- Stored properties cannot live in extensions: every `var` with storage stays in the file that declares the type.
26
27---
28
29### Task 1: `Sources/Orgstar/ContentView.swift` (1,106 lines)
30
31- [ ] Move `Sidebar` and `OutlineColumn` to `Sidebar.swift` (`SidebarFiles.swift` already exists and stays).
32- [ ] Move `SearchResults` and `QuickOpenView` to `SearchViews.swift`.
33- [ ] Move `BufferTabs` and `PaneDivider` to `BufferTabs.swift`.
34- [ ] Move `Panel` and `BlockEditRequest` to `Panels.swift`.
35- [ ] `ContentView` itself is about 790 lines and stays. Build, test, run the app, commit "Split ContentView.swift".
36
37### Task 2: `Sources/OrgEditorAppKit/OrgEditor.swift` (1,566 lines)
38
39- [ ] Move `ShadedFragment`, `ImageFragment`, `EntityFragment`, `FoldedHeadingFragment`, `InlineImageBox` and the `NSAttributedString.Key` extension to `Fragments.swift`.
40- [ ] Move `HiddenRanges` and `FoldedHeadings` to `HiddenRanges.swift`.
41- [ ] Move the `Folding`, `Sparse trees`, `STARTUP display` and `Narrowing` sections to `OrgEditor+Folding.swift`.
42- [ ] Move `Inline images` to `OrgEditor+Images.swift`, `Shrunk table columns` to `OrgEditor+Shrink.swift`, `Styling` to `OrgEditor+Styling.swift`.
43- [ ] `OrgEditor.swift` keeps the class with its stored properties, `Initial styling`, `Saving`, `Commands`, `Disk`, `Editing` and the delegate extensions (`DocumentBuffer`, `NSTextStorageDelegate`, `NSTextContentStorageDelegate`, `NSTextLayoutManagerDelegate`). Build, test, run the app and type in a folded file, commit "Split OrgEditor.swift".
44
45### Task 3: `Sources/OrgstarMobile/MobileEditor.swift` (1,209 lines)
46
47- [ ] Move `LockedRanges`, `FragmentStyle`, `KeyedTextView`, `SelectionHighlightView`, `OrgLineFragment`, `InlineImageBox` and the `NSAttributedString.Key` extension to `MobileFragments.swift`.
48- [ ] Move `Styling` to `MobileEditor+Styling.swift`; `Shrunk table columns`, `Inline images`, `Truncation` and `Folding` to `MobileEditor+Display.swift`.
49- [ ] Build with `scripts/build-ios-app.sh`, run in the Simulator, fold a heading and shrink a column, commit "Split MobileEditor.swift".
50
51### Task 4: `Sources/OrgCore/Compute/Babel.swift` (2,017 lines)
52
53- [ ] Keep `BabelJob`, `BabelOutput`, `enum Babel` with `Planning`, and `ExecuteSrcBlock` in `Babel.swift`.
54- [ ] `BabelNoweb.swift`: `Noweb` (check first whether `BabelExpand.swift` already holds the expansion it calls; if so, move `Noweb` there).
55- [ ] `BabelHeaders.swift`: `Header arguments` and `Variables`; `BabelVars.swift`: `Tables in variables`.
56- [ ] `BabelCache.swift`: `Cache`. `BabelLanguages.swift`: `Python` and `Emacs Lisp`. `BabelResults.swift`: `Finishing` and `Inserting`.
57- [ ] `swift test --filter Babel`, then the whole suite, commit "Split Babel.swift".
58
59### Task 5: `Sources/OrgCore/Keymap/Presets.swift` (1,357 lines)
60
61- [ ] `PresetEmacs.swift`: `emacsBindings`; `PresetMac.swift`: `macBindings`; `PresetDoom.swift`: `doomBindings` and `doomToml`. The enum, `common`, `speedCommands` and `speedBindings(mode:)` stay. Static string constants move as `extension KeymapPreset { static let emacsBindings = """…""" }`.
62- [ ] Keymap tests, commit "Split Presets.swift".
63
64### Task 6: `Sources/OrgCore/Keymap/Vim.swift` (1,353 lines)
65
66- [ ] `VimParser.swift`: `Parsing`; `VimMotions.swift`: `Motions` and `Text objects`; `VimApply.swift`: `Applying` and `Text`. `Vim.swift` keeps the struct, its state and `Feeding keys`. `VimExtras.swift` is the precedent for extensions on `Vim`.
67- [ ] Vim tests, commit "Split Vim.swift".
68
69### Task 7: `Sources/Orgstar/AgendaView.swift` (1,278 lines)
70
71- [ ] `AgendaRowView.swift`: `AgendaRowView` and `HabitGraph`. `AgendaView+Toolbar.swift`: `Toolbar`, `Span`, `Filters`. `AgendaView+Actions.swift`: `Commands` and `Clock, refile, archive, bulk`. `AgendaView.swift` keeps `AgendaSpan`, `CalendarAccess`, the view, `Lines`, `Days`, `Items`.
72- [ ] Build, open the agenda, run a bulk action, commit "Split AgendaView.swift".
73
74### Task 8: `Sources/OrgCore/Compute/TableFormulas.swift` (1,241 lines)
75
76- [ ] `TableFormulaCommands.swift`: `TableRecalculate`, `TableEvalFormula`, `TableEditField`, the two `BlockEdit` extensions and the `EmacsBuffer` extensions after line 977. `TableFormulas.swift` keeps `RemoteTables` and the evaluator extension (lines 15–910).
77- [ ] Table formula tests and the oracle, commit "Split TableFormulas.swift".
78
79### Task 9: `Sources/OrgCore/Commands/OrgList.swift` (1,009 lines)
80
81- [ ] `OrgListIndent.swift`: `Indentation changes` and `Repairs`. The rest stays.
82- [ ] List tests and the sort-list oracle, commit "Split OrgList.swift".
83
84### Task 10: Keep it that way
85
86- [ ] `scripts/check-file-sizes.sh`: lists hand-written Swift files over 1,000 lines, exempting the two generated files, exit 1 when any. Note it in `docs/design.md` under Testing, beside `swift test`.
87- [ ] Commit "check-file-sizes.sh".
docs/plans/2026-10-10-plan-cleanup.md added +61
@@ -0,0 +1,61 @@
1# Planning Cleanup Implementation Plan
2
3> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
5**Goal:** `docs/plans`, `docs/design.md` and `docs/review-2026-10-05.md` say what is done and what is not, and every open piece of work has exactly one home.
6
7**Architecture:** Plans are historical once their commits land: their boxes get ticked against `git log`, and any step that did not ship is marked so in place. The design doc's status paragraph and phase-1 boxes are brought to today. The review is kept as a record with a note at the top that its tiers shipped and that the manual's "Known differences from Emacs Org" is now the living list. Open work goes to gitbay issues on `krz/orgstar`, one per piece, so the backlog is the issue list and nothing else.
8
9**Tech Stack:** `git log`, `gitbay issue create`.
10
11**Spec:** this file.
12
13## Global constraints
14
15- Plans are not rewritten or trimmed; only checkboxes and short "did not ship:" lines change.
16- A box is ticked only when the commit it names, or one that plainly covers the step, is found; a box for a verification step (a gate run, a VoiceOver pass) is ticked only when the result is recorded somewhere.
17- No new planning documents beyond this one.
18
19## Review focus
20
21- The two owed items in `docs/design.md` (the VoiceOver check at line 353, the M1 Air gate run at line 359) must remain unticked and get an issue each; ticking them by momentum is the failure to avoid.
22- Plan steps that say "Commit "X"" should be matched by subject, not by topic: `git log --oneline --fixed-strings --grep="X"`.
23- The review's defects table was fixed by named commits (`Fix duplicate bindings`, `Keep body folds through edits`, `Watch folders added during a session`, `Report each buffer's changes as its own`, `Refile and archive into open buffers`, `Babel: show errors, cancel runs`, `Line index, and cheaper block bands while typing`, `Open .org files from Finder, app icon, current docs`); the clock report reading from disk (`ClockViews.swift`) is the one row to check by reading the code before calling the table closed.
24
25---
26
27### Task 1: Tick the 20 plans
28
29Files: the plans with open boxes, found with `for f in docs/plans/*.md; do grep -q '^\s*- \[ \]' "$f" && echo "$f"; done` (20 files dated 2026-10-04 and 2026-10-05).
30
31- [ ] For each file, for each `- [ ]` line: find its commit (`git log --oneline --fixed-strings --grep="<subject>"` for "Commit …" steps; `git log --oneline -- <path>` for implementation steps naming a file; the step's tests by name in `Tests/`). Tick it.
32- [ ] A step with no evidence stays `- [ ]` and gets ` — did not ship: <one line>` appended. Expected: `2026-10-04-editing-spike.md`'s VoiceOver step, `2026-10-04-viewer.md`'s and `2026-10-04-performance.md`'s "run the gates" steps (recorded on an M-series Mac only, per `design.md`); anything else found is reported in the commit message.
33- [ ] Commit "Tick the shipped plan steps" with the did-not-ship list in the body.
34
35### Task 2: `docs/design.md`
36
37- [ ] Replace the status paragraph (line 337) with one dated 2026-10-10: phases 1–7 built; the Mac released as v0.2.0 (notarized DMG, cask); iOS complete for Simulator builds, device signing and TestFlight not set up; owed: the M1 Air gate run, the VoiceOver check on both platforms.
38- [ ] Phase-1 boxes: leave lines 353 and 359 unticked; tick nothing else (all others are already `[x]`).
39- [ ] Open questions: tick "App name: Orgstar (chosen)" (line 390); add the lowercase spelling, per commit `Name the app orgstar, in lowercase`.
40- [ ] Under "Phases", after the list, one sentence: plans in `docs/plans/` are ticked when their commits land, and what did not ship is marked in the plan; open work is in the repository's issues.
41- [ ] Commit "Design doc status for 2026-10-10".
42
43### Task 3: The review
44
45- [ ] At the top of `docs/review-2026-10-05.md`, under the title, a two-line note: every tier shipped between a831086 and 2d3da68 (`git log --oneline a831086..2d3da68 | wc -l` commits); the current list of refusals and gaps is `docs/manual/guide/15-alongside-emacs.org`, "Known differences from Emacs Org".
46- [ ] Check `Sources/Orgstar/ClockViews.swift` for the defects-table row "Clock report reads files from disk and ignores unsaved buffers"; if still true, it becomes an issue in Task 4.
47- [ ] Commit "Mark the October 5 review as historical".
48
49### Task 4: Issues for the open work
50
51- [ ] `gitbay issue create --title … --file -` for each, body: what, where, done-when, pointer to the plan when one exists:
52 - Run the phase-1 gates on the M1 Air (`ORGSTAR_GATES=1 swift test -c release --filter GateTests`); record the numbers in `design.md`.
53 - VoiceOver pass, Mac: the editing-spike checklist in `docs/plans/2026-10-04-editing-spike.md`.
54 - VoiceOver pass, iOS: reader, editor, agenda rows, capture form.
55 - Sparkle updates (`docs/plans/2026-10-10-sparkle-updates.md`).
56 - Windows and panes (`docs/plans/2026-10-10-windows-and-panes.md`).
57 - File splits (`docs/plans/2026-10-10-file-splits.md`).
58 - iOS device signing and a TestFlight release script.
59 - Clock report over unsaved buffers, if Task 3 found it still reads disk.
60- [ ] Issue 1 ("iOS: refile under a heading") stays as it is.
61- [ ] No commit; list the issue numbers in the merge request description.
docs/plans/2026-10-10-sparkle-updates.md added +186
@@ -0,0 +1,186 @@
1# Sparkle Updates Implementation Plan
2
3> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
5**Goal:** A Mac build installed from the DMG or the cask learns about the next release and installs it, with Check for Updates… in the app menu and an automatic-checks setting.
6
7**Architecture:** Sparkle 2 from its SwiftPM package, linked into the `Orgstar` target and copied into `Contents/Frameworks` by `scripts/build-app.sh`. The appcast is a static file in the manual's site, `docs/manual/appcast.xml`, served at `https://krz.gitbay.site/orgstar/appcast.xml` by `scripts/publish-docs.sh`; `scripts/release-mac.sh` signs the DMG with the EdDSA key, prepends the release to the appcast through a merge request on main, and publishes the manual. Nothing is served from anywhere new.
8
9**Tech Stack:** Sparkle 2.7 (SPM binary target), `generate_keys` and `sign_update` from the package's `bin`, `xmllint`.
10
11**Spec:** `docs/design.md`, Decisions ▸ Distribution ("Direct download (notarized, Sparkle) and Homebrew cask").
12
13## Global constraints
14
15- The app stays unsandboxed; Sparkle's XPC services are not used.
16- Dev builds (`ORGSTAR_SIGN` unset, ad hoc) carry no feed URL, so they never check.
17- Nothing is pushed to main directly: the appcast change goes in through a merge request, as the cask does.
18- Release notes in the appcast are the same text `release-mac.sh` gives `gitbay release create --notes`.
19
20## Decisions
21
22| Question | Decision | Reason |
23| --- | --- | --- |
24| Feed host | The `pages` branch, beside the manual | Already published by a script; a fixed URL, unlike release assets which are per tag |
25| Version Sparkle compares | `CFBundleVersion`, the commit count `release-mac.sh` already sets | Monotonic across releases; `sparkle:shortVersionString` shows the semver |
26| Automatic checks | Sparkle's own first-run prompt, no `SUEnableAutomaticChecks` key | Asking once is the Sparkle default and needs no UI of our own |
27| Delta updates | No | One DMG per release is enough at this size |
28| Private key | The login keychain of the release Mac, where `generate_keys` puts it | `sign_update` finds it there; nothing in the repo |
29
30## Review focus
31
32- A dev build must not offer updates: without `SUFeedURL` the updater must not start, and the menu item must be disabled, not crash.
33- The appcast must still validate after many releases: entries are prepended, never rewritten, and `xmllint` runs before the commit.
34- `release-mac.sh` must upload the DMG before publishing the appcast, or a client can read an entry whose enclosure 404s.
35- The `pages` publish replaces the whole branch, so the appcast has to live in `docs/manual`, not be written onto `pages` by hand.
36- Signing: `codesign --verify --strict --deep` on the app must still pass with the framework inside, or notarization fails late.
37
38---
39
40### Task 1: Link Sparkle and bundle the framework
41
42**Files:**
43- Modify: `Package.swift` (dependencies; `Orgstar` target)
44- Modify: `scripts/build-app.sh`
45
46- [ ] Add the dependency and the product to the app target:
47
48```swift
49.package(url: "https://github.com/sparkle-project/Sparkle", from: "2.7.0"),
50// ...
51.executableTarget(name: "Orgstar", dependencies: ["OrgApp", "OrgEditorAppKit", "OrgHighlight", .product(name: "Sparkle", package: "Sparkle")]),
52```
53
54- [ ] In `build-app.sh`, after copying the binary: copy the framework from the SwiftPM artifact and give the executable an rpath to it.
55
56```sh
57sparkle="$(find .build/artifacts -path '*Sparkle.xcframework/macos-*/Sparkle.framework' -maxdepth 6 | head -1)"
58[ -n "$sparkle" ] || { echo "Sparkle.framework not in .build/artifacts; run swift build first." >&2; exit 1; }
59mkdir -p "$app/Contents/Frameworks"
60ditto "$sparkle" "$app/Contents/Frameworks/Sparkle.framework"
61install_name_tool -add_rpath @executable_path/../Frameworks "$app/Contents/MacOS/Orgstar"
62```
63
64- [ ] Sign Sparkle's inner pieces before the app, with the same identity and flags (Sparkle's documented order), inside the final signing block:
65
66```sh
67fw="$app/Contents/Frameworks/Sparkle.framework/Versions/B"
68for item in "$fw/XPCServices/Installer.xpc" "$fw/XPCServices/Downloader.xpc" "$fw/Autoupdate" "$fw/Updater.app" "$app/Contents/Frameworks/Sparkle.framework"; do
69 codesign --force --sign "$sign" $sign_flags "$item"
70done
71```
72
73- [ ] Add `SUFeedURL` and `SUPublicEDKey` to the generated Info.plist only when `sign` is not `-`:
74
75```sh
76if [ "$sign" != "-" ]; then
77 feed_keys="<key>SUFeedURL</key><string>https://krz.gitbay.site/orgstar/appcast.xml</string><key>SUPublicEDKey</key><string>${ORGSTAR_ED_PUBLIC_KEY:?set ORGSTAR_ED_PUBLIC_KEY}</string>"
78else
79 feed_keys=""
80fi
81```
82
83and `${feed_keys}` in the plist heredoc after `LSMinimumSystemVersion`. The public key is pasted into `scripts/release-mac.sh` as a default for `ORGSTAR_ED_PUBLIC_KEY` once Task 3 generates it.
84
85- [ ] Verify: `sh scripts/build-app.sh`, then `otool -l .build/app/orgstar.app/Contents/MacOS/Orgstar | grep -A2 LC_RPATH` shows the Frameworks rpath, `open .build/app/orgstar.app` launches, and `codesign --verify --strict --deep .build/app/orgstar.app` passes.
86- [ ] Commit "Link Sparkle and bundle its framework".
87
88### Task 2: Check for Updates… and the setting
89
90**Files:**
91- Modify: `Sources/Orgstar/OrgstarApp.swift` (`AppDelegate` at line 151; `.commands`)
92- Modify: `Sources/Orgstar/OrgstarApp.swift` (`SettingsView`, the General tab at line 551)
93
94- [ ] In the app delegate, one controller for the process:
95
96```swift
97import Sparkle
98let updater = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: nil, userDriverDelegate: nil)
99```
100
101Without a feed URL (dev builds) the updater logs that it can't start and `canCheckForUpdates` stays false; that is the intended dev behaviour.
102
103- [ ] Menu item after About, following Sparkle's SwiftUI sample:
104
105```swift
106CommandGroup(after: .appInfo) {
107 Button("Check for Updates…") { delegate.updater.updater.checkForUpdates() }
108 .disabled(!delegate.updater.updater.canCheckForUpdates)
109}
110```
111
112`canCheckForUpdates` is KVO-observable; wrap the updater in a small `@Observable` holder that observes it, so the button enables once the updater starts.
113
114- [ ] Settings ▸ General: a toggle bound to `updater.automaticallyChecksForUpdates`, shown only when `canCheckForUpdates` is true, labelled "Check for updates automatically".
115- [ ] Test by hand: a dev build shows the item disabled and no toggle; a `ORGSTAR_SIGN=<Developer ID>` build with a local feed (Task 4) shows both.
116- [ ] Commit "Check for Updates… and automatic checks".
117
118### Task 3: Keys and the appcast file
119
120**Files:**
121- Create: `docs/manual/appcast.xml`
122- Create: `scripts/appcast-add.sh`
123- Modify: `docs/manual/orgo.toml` only if orgo needs the file listed to copy it (check with `scripts/publish-docs.sh --dry-run` and `ls` of the built site; `favicon.svg` and `style.css` are copied today, so it should not)
124
125- [ ] Generate the key pair once on the release Mac: `"$(find .build/artifacts -name generate_keys -type f | head -1)"`. The private key goes to the login keychain; paste the printed public key as the `ORGSTAR_ED_PUBLIC_KEY` default in `release-mac.sh`.
126- [ ] The empty appcast:
127
128```xml
129<?xml version="1.0" encoding="utf-8"?>
130<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
131 <channel>
132 <title>orgstar</title>
133 <link>https://gitbay.org/krz/orgstar</link>
134 </channel>
135</rss>
136```
137
138- [ ] `scripts/appcast-add.sh <appcast> <version> <build> <dmg> <notes-file>`: runs `sign_update "$dmg"` (found under `.build/artifacts` like `generate_keys`), which prints `sparkle:edSignature="…" length="…"`, and inserts after `<link>…</link>` in the channel:
139
140```xml
141 <item>
142 <title>orgstar VERSION</title>
143 <link>https://gitbay.org/krz/orgstar/releases/tag/vVERSION</link>
144 <sparkle:version>BUILD</sparkle:version>
145 <sparkle:shortVersionString>VERSION</sparkle:shortVersionString>
146 <sparkle:minimumSystemVersion>26.0</sparkle:minimumSystemVersion>
147 <pubDate>RFC 2822 date</pubDate>
148 <description><![CDATA[NOTES]]></description>
149 <enclosure url="https://gitbay.org/krz/orgstar/releases/download/vVERSION/orgstar-VERSION.dmg" type="application/octet-stream" sparkle:edSignature="…" length="…"/>
150 </item>
151```
152
153Insertion is a `sed`/`awk` on the first `</link>` after `<channel>`; the script refuses a version already present (`grep -q "<sparkle:shortVersionString>$version<"`) and ends with `xmllint --noout "$appcast"`.
154
155- [ ] Verify with a throwaway copy: `scripts/appcast-add.sh /tmp/a.xml 0.2.0 365 .build/release/orgstar-0.2.0.dmg notes.txt` twice; the second run exits non-zero naming the version.
156- [ ] Commit "Appcast file and appcast-add.sh".
157
158### Task 4: Release script and cask
159
160**Files:**
161- Modify: `scripts/release-mac.sh`
162- Modify: `packaging/orgstar.rb`
163
164- [ ] After `gitbay release asset add` and before the tap section, add the appcast entry through a merge request, mirroring the tap block:
165
166```sh
167notes="Universal (Apple silicon and Intel), macOS 26 or later. Notarized."
168printf '%s\n' "$notes" > "$out/notes.txt"
169branch="appcast-$version"
170git switch -q -c "$branch"
171sh scripts/appcast-add.sh docs/manual/appcast.xml "$version" "$build" "$dmg" "$out/notes.txt"
172git add docs/manual/appcast.xml
173git commit -q -m "Appcast for $version"
174git push -q -u origin "$branch"
175mr="$(gitbay mr create --source "$branch" --target main --title "Appcast for $version" --body "Sparkle entry for orgstar $version." --json | sed -n 's/.*"number":\([0-9]*\).*/\1/p')"
176gitbay mr merge "$mr" --strategy ff
177git switch -q main && git pull -q --ff-only && git branch -d "$branch" && git push -q origin --delete "$branch"
178sh scripts/publish-docs.sh
179```
180
181`$notes` replaces the literal string already passed to `gitbay release create`. With `ORGSTAR_PUBLISH=0` the script runs `appcast-add.sh` on a copy under `$out` and prints the entry instead, so a dry run shows the signature.
182
183- [ ] Cask: add `auto_updates true` after `desc`, so `brew upgrade` leaves updating to the app.
184- [ ] End-to-end check before the first real release: build with a Developer ID, point a running copy at a local appcast with `defaults write sh.krz.orgstar SUFeedURL file:///tmp/a.xml` (Sparkle reads the feed from user defaults ahead of Info.plist), Check for Updates… offers the entry and installs the DMG; then `defaults delete sh.krz.orgstar SUFeedURL`.
185- [ ] Manual: `docs/manual/guide/01-files-and-folders.org` or `install.org` gets a paragraph on updates (menu item, the setting, that the cask has `auto_updates`).
186- [ ] Commit "Release script writes the appcast; cask auto_updates".
docs/plans/2026-10-10-windows-and-panes.md added +156
@@ -0,0 +1,156 @@
1# Windows and Panes Implementation Plan
2
3> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
5**Goal:** More than one editor window, and a window split into panes, each pane showing any open buffer with its own caret, folds, narrowing and scroll position, so two files (or two places in one file) sit side by side as `C-x 2` / `C-x 3` give in Emacs.
6
7**Architecture:** The editor is split into a buffer and views. `EditorBuffer` (new, `OrgEditorAppKit`) owns the `NSTextContentStorage`, the `DocumentState`, the revision, the undo manager and the `DocumentBuffer` conformance; `OrgEditor` becomes a view over it: an `NSTextView` with its own `NSTextLayoutManager` on the shared storage, holding selection, folds, narrowing and the layout-fragment delegate that draws them. `DocumentSession` keeps one `Entry` per open file but no longer has a single "current" buffer: each `EditorPane` (new, `OrgApp`) shows one path, and a `WindowModel` per main window holds a `PaneLayout` tree of panes and the focused one. The session forwards its old `path`, `outline`, `isDirty`, `conflict`, `revealRequest` and `editVersion` to the focused pane so the agenda, capture, menus and palette keep working unchanged.
8
9**Tech Stack:** TextKit 2 (several `NSTextLayoutManager`s on one `NSTextContentStorage`), SwiftUI `WindowGroup`, Swift Testing.
10
11**Spec:** `docs/design.md`, Commands ▸ Document session ("Each window or split has its own selection, fold state and narrowing, mapped through every edit").
12
13## Global constraints
14
15- The buffer is the file: one text storage, one undo stack and one revision per open file, however many views show it.
16- Byte fidelity and the save path are untouched; only who owns the storage changes.
17- The iOS editor (`MobileEditor`) is not restructured by this plan; iPad multi-window is a later piece.
18- Mac preset shortcuts for the new commands are checked against the existing Mac bindings in `Presets.swift` before being chosen, and must not take system shortcuts.
19
20## Decisions
21
22| Question | Decision | Reason |
23| --- | --- | --- |
24| Pane layout | A binary tree: `.pane(id)` or `.split(axis, first, second, fraction)` | `C-x 2` after `C-x 3` must work; one direction per window would refuse it |
25| Buffers per pane | Each pane keeps its own ordered list of buffers it has shown, as its tab bar | Matches editor groups users know; `C-x b` switches in the focused pane as in Emacs |
26| Killing a buffer | Removed from every pane; a pane showing it falls back to its previous buffer, else empty | Emacs behaviour |
27| Narrowing | Per view, as the design doc says | Two views of one buffer at different places is the point |
28| Shrunk table columns, inline-image toggle, markup toggle | Per buffer | They are buffer-local in Org |
29| Undo | One `UndoManager` per buffer, returned from every view's `undoManager(for:)` | `C-/` in either view undoes the last edit to the file |
30| Quick Open, search field, palette, conflict sheet | Per window (moved from `AppCommands` to `WindowModel`) | Global booleans would present them in every window at once |
31| Jump requests (agenda, capture, backlinks) | Go to the key main window's focused pane; open a main window if none | Where the user is looking |
32| Sidebar | Per window; its file selection follows the window's focused pane | Nothing shared to keep in step |
33
34## Review focus
35
36- Typing in one view while the other view has a fold over the edited range: the fold must be mapped or dropped, never left covering the wrong text.
37- Undo from view B of an edit typed in view A: the storage reverts, both views restyle, A's caret lands where the edit was.
38- Closing the last main window with dirty buffers: the buffers stay open in the session, and a new window shows them again; the dock-quit path still asks to save.
39- Killing a buffer shown in two panes of two windows: both panes fall back, neither crashes on a stale editor.
40- A command run from the palette or a menu must act on the focused pane's editor, not whichever editor was created last.
41
42---
43
44### Task 0: Spike: two text views on one content storage
45
46**Files:**
47- Create: `Sources/OrgstarSpike/TwoViews.swift` (throwaway, under the existing spike target)
48
49- [ ] One `NSTextContentStorage`, two `NSTextLayoutManager`s each with an `NSTextContainer` and an `NSTextView(frame:textContainer:)`, in one window side by side. A shared `UndoManager` returned by both views' delegate `undoManager(for:)`.
50- [ ] Check and write the findings at the top of the file: typing in A shows in B; undo from B reverts A's typing; each layout manager's delegate can return a different `NSTextLayoutFragment` for the same element (fold shown in A only); rendering attributes set on one layout manager do not appear in the other; IME composition in A does not disturb B's selection; selection in B survives an insertion before it in A.
51- [ ] If any check fails, stop and amend this plan before Task 1: the fallback is per-view `NSTextStorage`s kept in step by replaying edits, which is a different Task 1.
52- [ ] Commit "Spike: two text views on one content storage".
53
54### Task 1: `EditorBuffer`
55
56**Files:**
57- Create: `Sources/OrgEditorAppKit/EditorBuffer.swift`
58- Modify: `Sources/OrgEditorAppKit/OrgEditor.swift` (the parts moved out), `OrgEditor+Styling.swift`, `OrgEditor+Folding.swift` (see `2026-10-10-file-splits.md`, which lands first)
59- Test: `Tests/OrgEditorAppKitTests/EditorBufferTests.swift`
60
61**Interfaces:**
62- Produces:
63
64```swift
65@MainActor public final class EditorBuffer: NSObject, DocumentBuffer {
66 public let contentStorage: NSTextContentStorage
67 public let undoManager: UndoManager
68 public private(set) var document: DocumentState // DocumentBuffer
69 public var selection: [Range<Int>] // the focused view's, set by views
70 public func perform(_ command: any OrgCommand, now: Date, answers: [String: String]) -> CommandStep
71 public func update<T>(_ change: (inout DocumentState) throws -> T) rethrows -> T
72 public func addView(_ view: OrgEditor) // weak; receives storageEdited and restyle
73 public func removeView(_ view: OrgEditor)
74 public var shrunkColumns: ShrunkColumns
75 public var showMarkup: Bool, showInlineImages: Bool
76}
77```
78
79- [ ] Write the failing tests: `two views see one edit` (make a buffer with text, two `OrgEditor`s on it, insert in one through its text view, the other's `textView.string` matches); `undo is shared`; `folds map independently` (fold a heading in A, insert a line above it in B, A's hidden range moved by the delta, B has none).
80- [ ] Move from `OrgEditor` to `EditorBuffer`: the storage and its delegate (`textStorage(_:didProcessEditing:…)`, the incremental reparse and revision bump), `DocumentState`, the `DocumentBuffer` extension, the attribute styling of the storage (theme base, highlighting, markup hiding attributes that live on the storage), `isLoading`, `load(text:)`. `OrgEditor.init` takes an `EditorBuffer` and creates its own layout manager and text view on `buffer.contentStorage`.
81- [ ] `EditorBuffer` tells each view after a storage edit: `view.storageEdited(range, delta)` (today's `OrgEditor.storageEdited`, now per view, mapping `HiddenRanges`, `FoldedHeadings`, the narrowing and shrunk-column boxes), and `view.restyle(range)` for fragment invalidation.
82- [ ] `OrgEditor.undoManager(for:)` returns `buffer.undoManager`.
83- [ ] Run the tests; run the whole suite (`swift test`): the existing `OrgEditorAppKitTests` construct `OrgEditor` directly and need the buffer argument.
84- [ ] Commit "Split the editor into EditorBuffer and views".
85
86### Task 2: `EditorPane` and the session
87
88**Files:**
89- Create: `Sources/OrgApp/EditorPane.swift`, `Sources/OrgApp/PaneLayout.swift`
90- Modify: `Sources/OrgApp/DocumentSession.swift`
91- Test: `Tests/OrgAppTests/PaneLayoutTests.swift`, `Tests/OrgAppTests/EditorPaneTests.swift`
92
93**Interfaces:**
94- Produces:
95
96```swift
97public struct PaneID: Hashable, Sendable { }
98public indirect enum PaneLayout: Equatable, Sendable {
99 case pane(PaneID)
100 case split(axis: Axis, first: PaneLayout, second: PaneLayout, fraction: Double) // Axis: .horizontal (side by side) / .vertical
101 public func splitting(_ id: PaneID, axis: Axis, new: PaneID) -> PaneLayout // new pane after `id`, fraction 0.5
102 public func removing(_ id: PaneID) -> PaneLayout? // nil when it was the only pane
103 public func only(_ id: PaneID) -> PaneLayout
104 public var panes: [PaneID] // in reading order
105 public func next(after id: PaneID) -> PaneID // wraps
106}
107
108@MainActor @Observable public final class EditorPane: Identifiable {
109 public let id: PaneID
110 public private(set) var path: String?
111 public private(set) var shown: [String] // buffers this pane has shown, tab order
112 public private(set) var outline: [OutlineEntry]
113 public private(set) var editVersion: Int
114 public private(set) var revealRequest: (offset: Int, id: Int)?
115 public var isDirty: Bool { get } // from the session's entry
116 public var conflict: String? { get }
117 public var document: DocumentState? { get }
118}
119```
120
121- `DocumentSession` gains `panes: [PaneID: EditorPane]`, `focused: EditorPane?`, `makePane() -> EditorPane`, `closePane(_:)`, `open(_ path: String, in pane: EditorPane)`, `show(_ path:, in:)`, `reveal(_ offset:, in:)`; `kill(path)` updates every pane. The old `path`, `outline`, `isDirty`, `conflict`, `revealRequest`, `editVersion`, `document`, `bufferChanged()` forward to `focused` with a doc comment saying so.
122
123- [ ] Write the failing `PaneLayout` tests: split right then split below the second pane gives three panes in reading order; removing the middle one leaves a two-pane split with the remaining fraction; `only` collapses; `next` wraps; removing the only pane returns nil.
124- [ ] Implement `PaneLayout`; run the tests.
125- [ ] Write the failing `EditorPane` tests with a `DocumentSession` over an in-memory `FileSystem` (as `DocumentSessionTests` do): opening a path in pane A then showing it in pane B leaves one `Entry`; killing it empties both panes' `path` and `shown`; a pane's `shown` keeps order and drops killed paths; `reveal(_:in:)` bumps only that pane's request; `dirtyPaths` counts a buffer once however many panes show it.
126- [ ] Implement `EditorPane` and the session changes: `Entry` keeps `buffer: EditorBuffer` (attached by the first view; `attach` becomes `attach(_ buffer:, for path:)`), `current` is replaced by `focused`, `history` moves into each pane. `bufferChanged(path)` refreshes every pane showing that path (outline per pane, since a pane's outline is the buffer's; compute once and assign to each).
127- [ ] Run the whole suite. `AppTests` that read `session.path` keep passing through the forwarders.
128- [ ] Commit "Editor panes and pane layout in the session".
129
130### Task 3: Panes in the main window
131
132**Files:**
133- Create: `Sources/Orgstar/PaneView.swift` (one pane: `BufferTabs` + `EditorView` for that pane), `Sources/Orgstar/PaneLayoutView.swift` (recursive `HSplitView`/`VSplitView` over `PaneLayout`, using `PaneDivider` for the fraction), `Sources/Orgstar/WindowModel.swift`
134- Modify: `Sources/Orgstar/EditorView.swift` (takes an `EditorPane`; one `OrgEditor` per (pane, path), created on `EditorBuffer` from the session's entry), `Sources/Orgstar/ContentView.swift`, `Sources/Orgstar/BufferTabs.swift`, `Sources/Orgstar/OrgstarApp.swift`
135
136**Interfaces:**
137
138```swift
139@MainActor @Observable final class WindowModel {
140 let id = UUID()
141 var layout: PaneLayout
142 var focused: PaneID
143 var showingQuickOpen = false, focusSearch = false, showingPalette = false, showingConflict = false
144}
145```
146
147`AppCommands` keeps `editor` (the focused view) and gains `keyWindow: WindowModel?`, set from `NSWindow.didBecomeKeyNotification` by the window's root view; its four presentation booleans move to `WindowModel` and every menu action that set them goes through `keyWindow`.
148
149- [ ] `WindowGroup("orgstar", id: "main")` replaces `Window("orgstar", id: "main")`; the root view creates its `WindowModel` and one pane (`session.makePane()`) in `onAppear`, registers the model with `commands`, and on disappear closes its panes (`session.closePane`) so killed views release their layout managers (`buffer.removeView`). Buffers stay in the session.
150- [ ] `EditorView` creates editors per `(pane.id, path)`; the shown editor's text view becoming first responder sets `commands.editor` and `session.focused = pane` (an `onFocus` callback on `OrgEditor`, from `becomeFirstResponder` on `OrgTextView` in `Sources/OrgEditorAppKit/Keys.swift`).
151- [ ] Outline column and sidebar selection follow `session.focused`.
152- [ ] Jump requests (`AppCommands.jumpRequest`) are handled by the key window's root view only: `commands.keyWindow === model`. With no main window open, `openWindow(id: "main")` first, then the request is delivered on the new window's first `onAppear`.
153- [ ] Commands, as `app.*` ids dispatched where `app.quick-open` is today: `app.split-below`, `app.split-right`, `app.pane-close`, `app.pane-only`, `app.pane-next`, `app.window-new`. Menu: File ▸ New Window; View ▸ Split Below, Split Right, Close Pane, Close Other Panes, Next Pane. Emacs preset: `C-x 2`, `C-x 3`, `C-x 0`, `C-x 1`, `C-x o`, `C-x 5 2`. Doom: `SPC w s`, `SPC w v`, `SPC w d`, `SPC w o`, `SPC w w`, and `C-w s/v/c/o/w` in normal state. Mac: shortcuts chosen after checking `macBindings`; proposal ⌥⌘N, ⌥⌘-, ⌥⌘\, ⌃⌘W, ⌃⌘1, ⌃⌘`.
154- [ ] Manual: a "Windows and panes" section in `docs/manual/guide/02-the-editor.org` and the keys in `03-keys.org`'s reference table.
155- [ ] Check by hand against the review focus list; the `ORGSTAR_SNAPSHOT` hook in `DevelopmentHooks.swift` gets a two-pane snapshot.
156- [ ] Commit "Windows and panes".