krz/orgstar

A native macOS editor for org-mode files. editor org-mode swift

docs/plans/2026-10-05-refile-archive.md

16086b4cf2caff5328774b2cd5ae3ffe1ab65ca4
orgstar/docs/plans/2026-10-05-refile-archive.md rendered · source · history · blame · raw

33 lines · 2828 bytes

 1# Refile and Archive 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:** Refile (C-c C-w) to any heading down to level 3 in the workspace or to the end of a file, archive (C-c C-x C-s, C-c $) where `org-archive-subtree` would, and the TODO statistics updates org makes after TODO changes, all byte- and caret-exact against Emacs.
 6
 7**Architecture:** `OrgCore` ports `org-copy-subtree`, `org-paste-subtree`, `org-map-region` and the insert/delete steps of `org-refile` (`Refile.swift`); `org-archive-subtree` with `org-archive--compute-location`, context properties through `org-entry-put` (property drawer creation, `org-property-format` alignment), and `org-update-statistics-cookies` (`Archive.swift`); `org-update-parent-todo-statistics` (`Statistics.swift`), now run after TODO cycling and TODO-heading insertion through `followUp`. `DocumentSession.refile(to:)` and `archive()` handle a second file: it is read and written through the save path first, and the subtree leaves the buffer (`PrecomputedEdit`, one undo step) only once that write succeeds. Refile targets come from the index (`IndexStore.outline(maxLevel:)`) and, for the open file, from its buffer. Prompts gain choices, filtered as you type in the echo area.
 8
 9**Tech Stack:** Swift 6.2 tools, Swift Testing, Emacs 31.1 / Org 9.8.7 oracle.
10
11**Spec:** `docs/design.md`, "Commands and keymaps", "Saving".
12
13## Global Constraints
14
15- Org defaults: `org-log-refile` nil, `org-reverse-note-order` nil, `org-refile-keep` nil, archive location `%s_archive::`, context info time/file/olpath/category/todo/itags, inherited tags added only in-file, no DONE marking, `org-provide-todo-statistics` t, hierarchical statistics.
16- The oracle visits real temporary files, freezes `format-time-string` and runs with `TZ=UTC`; `.org_archive` files open in Org mode.
17
18## Defaults chosen (user may change)
19
20- Refile targets: every org file itself plus its headings to level 3 (org's default is level-1 headings of the current file).
21- Mac preset: ⌃⌘W refile, ⌃⌘A archive.
22
23---
24
25### Task 1: Core
26
27- [ ] Port refile, archive and statistics; oracles: refile within a file and to another file (4 sources × every caret × every target, 5 target files), archive (7 sources × 4 archive files), TODO cycle and TODO-heading insert with parent cookies.
28- [ ] Commit "Port refile, archive and TODO statistics from org".
29
30### Task 2: Session and app
31
32- [ ] `DocumentBuffer.selection` and `perform`; `PrecomputedEdit`; `DocumentSession.refile(to:)`, `archive()`; `WorkspaceModel.refileTargets`; prompt choices; keys and palette entries.
33- [ ] Commit "Refile and archive in the app".