smoosic 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/build/smoosic.js +395 -67
  2. package/changes.md +85 -0
  3. package/package.json +98 -82
  4. package/release/smoosic.js +395 -67
  5. package/specs/032-split-multimeasure-rests/checklists/requirements.md +40 -0
  6. package/specs/032-split-multimeasure-rests/contracts/grouping-contract.md +53 -0
  7. package/specs/032-split-multimeasure-rests/data-model.md +70 -0
  8. package/specs/032-split-multimeasure-rests/plan.md +81 -0
  9. package/specs/032-split-multimeasure-rests/quickstart.md +46 -0
  10. package/specs/032-split-multimeasure-rests/research.md +63 -0
  11. package/specs/032-split-multimeasure-rests/spec.md +127 -0
  12. package/specs/032-split-multimeasure-rests/tasks.md +174 -0
  13. package/specs/033-key-distance-transposition/checklists/requirements.md +35 -0
  14. package/specs/033-key-distance-transposition/contracts/spelling-api.md +36 -0
  15. package/specs/033-key-distance-transposition/data-model.md +49 -0
  16. package/specs/033-key-distance-transposition/plan.md +87 -0
  17. package/specs/033-key-distance-transposition/quickstart.md +40 -0
  18. package/specs/033-key-distance-transposition/research.md +82 -0
  19. package/specs/033-key-distance-transposition/spec.md +132 -0
  20. package/specs/033-key-distance-transposition/tasks.md +139 -0
  21. package/specs/034-smz-compressed-scores/checklists/requirements.md +35 -0
  22. package/specs/034-smz-compressed-scores/contracts/archive-api.md +30 -0
  23. package/specs/034-smz-compressed-scores/data-model.md +48 -0
  24. package/specs/034-smz-compressed-scores/plan.md +89 -0
  25. package/specs/034-smz-compressed-scores/quickstart.md +44 -0
  26. package/specs/034-smz-compressed-scores/research.md +86 -0
  27. package/specs/034-smz-compressed-scores/spec.md +137 -0
  28. package/specs/034-smz-compressed-scores/tasks.md +148 -0
  29. package/specs/035-paste-special/checklists/requirements.md +35 -0
  30. package/specs/035-paste-special/contracts/paste-special-api.md +50 -0
  31. package/specs/035-paste-special/data-model.md +47 -0
  32. package/specs/035-paste-special/plan.md +83 -0
  33. package/specs/035-paste-special/quickstart.md +51 -0
  34. package/specs/035-paste-special/research.md +97 -0
  35. package/specs/035-paste-special/spec.md +170 -0
  36. package/specs/035-paste-special/tasks.md +149 -0
  37. package/specs/036-autosave-recovery/checklists/requirements.md +36 -0
  38. package/specs/036-autosave-recovery/contracts/autosave-api.md +111 -0
  39. package/specs/036-autosave-recovery/data-model.md +70 -0
  40. package/specs/036-autosave-recovery/plan.md +87 -0
  41. package/specs/036-autosave-recovery/quickstart.md +65 -0
  42. package/specs/036-autosave-recovery/research.md +105 -0
  43. package/specs/036-autosave-recovery/spec.md +143 -0
  44. package/specs/036-autosave-recovery/tasks.md +165 -0
  45. package/specs/037-fix-new-part-dialog/checklists/requirements.md +38 -0
  46. package/specs/037-fix-new-part-dialog/contracts/create-part-api.md +84 -0
  47. package/specs/037-fix-new-part-dialog/data-model.md +68 -0
  48. package/specs/037-fix-new-part-dialog/plan.md +83 -0
  49. package/specs/037-fix-new-part-dialog/quickstart.md +58 -0
  50. package/specs/037-fix-new-part-dialog/research.md +86 -0
  51. package/specs/037-fix-new-part-dialog/spec.md +144 -0
  52. package/specs/037-fix-new-part-dialog/tasks.md +174 -0
  53. package/specs/038-per-measure-beam-groups/checklists/requirements.md +36 -0
  54. package/specs/038-per-measure-beam-groups/contracts/beam-groups-api.md +74 -0
  55. package/specs/038-per-measure-beam-groups/data-model.md +75 -0
  56. package/specs/038-per-measure-beam-groups/plan.md +84 -0
  57. package/specs/038-per-measure-beam-groups/quickstart.md +53 -0
  58. package/specs/038-per-measure-beam-groups/research.md +72 -0
  59. package/specs/038-per-measure-beam-groups/spec.md +146 -0
  60. package/specs/038-per-measure-beam-groups/tasks.md +132 -0
  61. package/specs/039-measure-fill-submenu/checklists/requirements.md +35 -0
  62. package/specs/039-measure-fill-submenu/contracts/measure-fill-api.md +56 -0
  63. package/specs/039-measure-fill-submenu/data-model.md +79 -0
  64. package/specs/039-measure-fill-submenu/plan.md +81 -0
  65. package/specs/039-measure-fill-submenu/quickstart.md +62 -0
  66. package/specs/039-measure-fill-submenu/research.md +68 -0
  67. package/specs/039-measure-fill-submenu/spec.md +153 -0
  68. package/specs/039-measure-fill-submenu/tasks.md +121 -0
  69. package/specs/040-dynamics-dialog-cleanup/checklists/requirements.md +36 -0
  70. package/specs/040-dynamics-dialog-cleanup/contracts/dynamics-dialog.md +52 -0
  71. package/specs/040-dynamics-dialog-cleanup/data-model.md +48 -0
  72. package/specs/040-dynamics-dialog-cleanup/plan.md +89 -0
  73. package/specs/040-dynamics-dialog-cleanup/quickstart.md +69 -0
  74. package/specs/040-dynamics-dialog-cleanup/research.md +80 -0
  75. package/specs/040-dynamics-dialog-cleanup/spec.md +120 -0
  76. package/specs/040-dynamics-dialog-cleanup/tasks.md +114 -0
  77. package/specs/041-delete-special/checklists/requirements.md +35 -0
  78. package/specs/041-delete-special/contracts/delete-special-api.md +41 -0
  79. package/specs/041-delete-special/data-model.md +40 -0
  80. package/specs/041-delete-special/plan.md +93 -0
  81. package/specs/041-delete-special/quickstart.md +41 -0
  82. package/specs/041-delete-special/research.md +75 -0
  83. package/specs/041-delete-special/spec.md +136 -0
  84. package/specs/041-delete-special/tasks.md +106 -0
  85. package/src/application/application.ts +13 -2
  86. package/src/application/exports.ts +401 -395
  87. package/src/application/generateVexTests.ts +2 -2
  88. package/src/render/sui/NoteEntryCaret.ts +117 -16
  89. package/src/render/sui/autosave.ts +265 -0
  90. package/src/render/sui/formatter.ts +12 -2
  91. package/src/render/sui/scoreChangeState.ts +8 -3
  92. package/src/render/sui/scoreView.ts +47 -2
  93. package/src/render/sui/scoreViewOperations.ts +2706 -2555
  94. package/src/render/sui/staffLineGeometry.ts +82 -0
  95. package/src/render/vex/vxMeasure.ts +22 -8
  96. package/src/render/vex/vxNote.ts +2 -4
  97. package/src/smo/data/measure.ts +58 -1
  98. package/src/smo/data/measureModifiers.ts +81 -1
  99. package/src/smo/data/music.ts +169 -359
  100. package/src/smo/data/note.ts +1 -1
  101. package/src/smo/data/noteModifiers.ts +12 -0
  102. package/src/smo/data/score.ts +167 -2
  103. package/src/smo/data/scoreModifiers.ts +46 -1
  104. package/src/smo/data/systemStaff.ts +43 -0
  105. package/src/smo/xform/beamers.ts +80 -6
  106. package/src/smo/xform/copypaste.ts +207 -47
  107. package/src/smo/xform/measureFill.ts +89 -0
  108. package/src/smo/xform/operations.ts +403 -61
  109. package/src/smo/xform/selections.ts +7 -0
  110. package/src/ui/components/dialogs/beamGroups.vue +106 -0
  111. package/src/ui/components/dialogs/deleteSpecial.vue +38 -0
  112. package/src/ui/components/dialogs/dynamics.vue +16 -3
  113. package/src/ui/components/dialogs/fileUpload.vue +2 -2
  114. package/src/ui/components/dialogs/hairpin.vue +3 -3
  115. package/src/ui/components/dialogs/newPart.vue +148 -184
  116. package/src/ui/components/dialogs/pasteSpecial.vue +49 -0
  117. package/src/ui/components/dialogs/recovery.vue +66 -0
  118. package/src/ui/components/dialogs/save.vue +11 -4
  119. package/src/ui/components/dialogs/scorePreferences.vue +23 -1
  120. package/src/ui/components/dialogs/slur.vue +6 -6
  121. package/src/ui/components/dialogs/tempo.vue +11 -3
  122. package/src/ui/components/dialogs/timeSignature.vue +5 -0
  123. package/src/ui/components/dialogs/volta.vue +3 -3
  124. package/src/ui/dialogs/annotationVue.ts +1 -1
  125. package/src/ui/dialogs/beamGroupsVue.ts +69 -0
  126. package/src/ui/dialogs/createPartHelpers.ts +68 -0
  127. package/src/ui/dialogs/deleteSpecial.ts +57 -0
  128. package/src/ui/dialogs/dynamicsVue.ts +87 -60
  129. package/src/ui/dialogs/factory.ts +0 -2
  130. package/src/ui/dialogs/fileDialogs.ts +63 -22
  131. package/src/ui/dialogs/instrument.ts +37 -30
  132. package/src/ui/dialogs/pasteSpecial.ts +59 -0
  133. package/src/ui/dialogs/preferences.ts +41 -40
  134. package/src/ui/dialogs/recovery.ts +49 -0
  135. package/src/ui/fileio/fileInput.ts +12 -3
  136. package/src/ui/fileio/scoreArchive.ts +151 -0
  137. package/src/ui/fileio/xhrLoader.ts +26 -0
  138. package/src/ui/i18n/language.ts +1 -1
  139. package/src/ui/menus/beams.ts +181 -112
  140. package/src/ui/menus/edit.ts +44 -6
  141. package/src/ui/menus/file.ts +21 -1
  142. package/src/ui/menus/measure.ts +40 -1
  143. package/tests/autosave.ts +332 -0
  144. package/tests/beamDotted.ts +56 -0
  145. package/tests/beamGroups.ts +338 -0
  146. package/tests/createPart.ts +292 -0
  147. package/tests/deleteSpecial.ts +350 -0
  148. package/tests/dynamicsFontSize.ts +132 -0
  149. package/tests/keyDistanceTransposition.ts +351 -0
  150. package/tests/measureFill.ts +295 -0
  151. package/tests/movePart.ts +94 -0
  152. package/tests/multimeasureRest.ts +338 -0
  153. package/tests/pasteIntoMeasure.ts +103 -0
  154. package/tests/pasteSpecial.ts +541 -0
  155. package/tests/quickBeam.ts +126 -0
  156. package/tests/scoreArchive.ts +218 -0
  157. package/tests/scoreChangeState.ts +2 -0
  158. package/tests/staffLineGeometry.ts +179 -0
  159. package/tests/timeSignatureDisplay.ts +58 -0
  160. package/tools/smoosic-schema.json +37 -0
  161. package/typedoc.ts +1 -1
  162. package/types/src/application/exports.d.ts +453 -447
  163. package/types/src/common/promiseHelpers.d.ts +30 -30
  164. package/types/src/common/vex.d.ts +224 -224
  165. package/types/src/render/sui/NoteEntryCaret.d.ts +107 -107
  166. package/types/src/render/sui/autosave.d.ts +99 -0
  167. package/types/src/render/sui/scoreView.d.ts +23 -0
  168. package/types/src/render/sui/scoreViewOperations.d.ts +759 -639
  169. package/types/src/render/sui/svgHelpers.d.ts +88 -88
  170. package/types/src/render/sui/svgPageMap.d.ts +344 -344
  171. package/types/src/render/sui/textEdit.d.ts +96 -96
  172. package/types/src/render/sui/textRender.d.ts +199 -199
  173. package/types/src/render/vex/smoAdapter.d.ts +47 -47
  174. package/types/src/render/vex/vxMeasure.d.ts +97 -97
  175. package/types/src/render/vex/vxNote.d.ts +56 -56
  176. package/types/src/render/vex/vxSystem.d.ts +71 -71
  177. package/types/src/smo/data/measure.d.ts +30 -0
  178. package/types/src/smo/data/measureModifiers.d.ts +568 -513
  179. package/types/src/smo/data/music.d.ts +74 -32
  180. package/types/src/smo/data/note.d.ts +498 -498
  181. package/types/src/smo/data/noteModifiers.d.ts +615 -606
  182. package/types/src/smo/data/score.d.ts +476 -421
  183. package/types/src/smo/data/scoreModifiers.d.ts +30 -0
  184. package/types/src/smo/data/scoreText.d.ts +334 -334
  185. package/types/src/smo/data/systemStaff.d.ts +14 -0
  186. package/types/src/smo/xform/beamers.d.ts +23 -1
  187. package/types/src/smo/xform/copypaste.d.ts +138 -2
  188. package/types/src/smo/xform/measureFill.d.ts +21 -0
  189. package/types/src/smo/xform/operations.d.ts +245 -129
  190. package/types/src/smo/xform/selections.d.ts +154 -154
  191. package/types/src/smo/xform/undo.d.ts +142 -142
  192. package/types/src/ui/buttons/button.d.ts +100 -100
  193. package/types/src/ui/buttons/ribbon.d.ts +70 -70
  194. package/types/src/ui/common.d.ts +76 -76
  195. package/types/src/ui/components/dialogs/chordText.d.ts +28 -28
  196. package/types/src/ui/components/dialogs/textBlockAtomNode.d.ts +20 -20
  197. package/types/src/ui/components/dialogs/textGroupHtml.d.ts +29 -29
  198. package/types/src/ui/composable/draggable.d.ts +15 -15
  199. package/types/src/ui/dialogs/adapter.d.ts +120 -120
  200. package/types/src/ui/dialogs/annotationVue.d.ts +9 -9
  201. package/types/src/ui/dialogs/audioSettings.d.ts +32 -32
  202. package/types/src/ui/dialogs/beamGroupsVue.d.ts +20 -0
  203. package/types/src/ui/dialogs/chordChangeVue.d.ts +8 -8
  204. package/types/src/ui/dialogs/createPartHelpers.d.ts +29 -0
  205. package/types/src/ui/dialogs/customTupletsVue.d.ts +9 -9
  206. package/types/src/ui/dialogs/deleteSpecial.d.ts +8 -0
  207. package/types/src/ui/dialogs/dialog.d.ts +203 -203
  208. package/types/src/ui/dialogs/dynamicsVue.d.ts +10 -10
  209. package/types/src/ui/dialogs/factory.d.ts +15 -15
  210. package/types/src/ui/dialogs/fileDialogs.d.ts +4 -4
  211. package/types/src/ui/dialogs/hairpin.d.ts +35 -35
  212. package/types/src/ui/dialogs/hairpinVue.d.ts +7 -7
  213. package/types/src/ui/dialogs/instrument.d.ts +3 -3
  214. package/types/src/ui/dialogs/keySignatureVue.d.ts +7 -7
  215. package/types/src/ui/dialogs/libraryVue.d.ts +15 -15
  216. package/types/src/ui/dialogs/lyricVue.d.ts +8 -8
  217. package/types/src/ui/dialogs/pasteSpecial.d.ts +8 -0
  218. package/types/src/ui/dialogs/pedalMarkingVue.d.ts +7 -7
  219. package/types/src/ui/dialogs/recovery.d.ts +8 -0
  220. package/types/src/ui/dialogs/rehearsalMark.d.ts +25 -25
  221. package/types/src/ui/dialogs/rehearsalMarkVue.d.ts +7 -7
  222. package/types/src/ui/dialogs/slur.d.ts +57 -57
  223. package/types/src/ui/dialogs/slurVue.d.ts +7 -7
  224. package/types/src/ui/dialogs/tempo.d.ts +50 -50
  225. package/types/src/ui/dialogs/tempoVue.d.ts +10 -10
  226. package/types/src/ui/dialogs/textBlockVue.d.ts +8 -8
  227. package/types/src/ui/dialogs/textBracket.d.ts +35 -35
  228. package/types/src/ui/dialogs/textBracketVue.d.ts +7 -7
  229. package/types/src/ui/dialogs/tie.d.ts +41 -41
  230. package/types/src/ui/dialogs/volta.d.ts +40 -40
  231. package/types/src/ui/dialogs/voltaVue.d.ts +7 -7
  232. package/types/src/ui/fileio/fileInput.d.ts +7 -1
  233. package/types/src/ui/fileio/library.d.ts +40 -40
  234. package/types/src/ui/fileio/scoreArchive.d.ts +55 -0
  235. package/types/src/ui/fileio/xhrLoader.d.ts +7 -0
  236. package/types/src/ui/menus/file.d.ts +8 -8
  237. package/types/src/ui/menus/language.d.ts +7 -7
  238. package/types/src/ui/menus/manager.d.ts +58 -58
  239. package/types/src/ui/menus/menu.d.ts +159 -159
  240. package/types/src/ui/menus/partSelection.d.ts +14 -14
  241. package/types/src/ui/menus/score.d.ts +8 -8
  242. package/types/src/ui/menus/staffModifier.d.ts +17 -17
  243. package/types/typedoc.d.ts +147 -147
  244. package/src/ui/dialogs/dynamics.ts +0 -141
  245. package/types/src/ui/dialogs/dynamics.d.ts +0 -37
@@ -0,0 +1,70 @@
1
+ # Data Model: Autosave Buffers and Crash Recovery
2
+
3
+ ## Autosave Settings (on `SmoScorePreferences`)
4
+
5
+ | Field | Type | Default | Valid values | Notes |
6
+ |-------|------|---------|--------------|-------|
7
+ | `autosaveInterval` | integer (minutes) | 10 | 5 to 60 | Time from the first unsnapshotted change to the snapshot |
8
+ | `autosaveCount` | integer | 10 | 1 to 20 | Most snapshots kept in the whole stored set |
9
+
10
+ **Validation**: The `SmoScorePreferences` constructor rounds each value to a whole number and limits it to the valid range. A missing, non-numeric or out-of-range value becomes the default (if missing or not a number) or the nearest limit (if out of range). The Score Preferences section uses the same limits.
11
+
12
+ **Serialization**: Both fields are written with the other preferences. A score saved before this feature has neither field and loads with the defaults. The fields are listed in `tools/smoosic-schema.json`.
13
+
14
+ **Lifecycle**: Changing a value takes effect immediately: the scheduler is retimed and, if the count was lowered, the stored set is trimmed (see Snapshot Set).
15
+
16
+ ## Autosave Snapshot
17
+
18
+ One stored copy of the whole score at a moment in time.
19
+
20
+ | Field | Type | Notes |
21
+ |-------|------|-------|
22
+ | `id` | integer | Increases by one for each snapshot taken; the newest has the largest. Defines the order. |
23
+ | `time` | integer (ms since epoch) | When the snapshot was taken; shown to the user, not used for ordering |
24
+ | `title` | string | The score's name at that time, or empty (shown as "Untitled") |
25
+ | `size` | integer | Length of the stored text; used to detect truncated entries |
26
+
27
+ The score itself is held under its own storage key as base64 text of a compressed score archive.
28
+
29
+ ## Snapshot Set (the index)
30
+
31
+ The ordered list of snapshot entries, newest last, held under one storage key.
32
+
33
+ **Invariants**:
34
+ - Never more than `autosaveCount` entries after any add or setting change.
35
+ - Ids are unique and strictly increasing in list order.
36
+ - An entry whose score text is missing is removed when the index is read.
37
+ - Adding a snapshot removes entries from the old end until the count holds.
38
+ - If a write fails for lack of room, the oldest entry is removed and the write retried, until it succeeds or the set is empty.
39
+
40
+ **State transitions**:
41
+
42
+ ```text
43
+ (no set) --first snapshot--> [s1]
44
+ [s1..sN], N < count --snapshot--> [s1..sN, s(N+1)]
45
+ [s1..sN], N = count --snapshot--> [s2..sN, s(N+1)] # oldest dropped
46
+ [s1..sN] --count lowered to M < N--> [s(N-M+1)..sN] # oldest dropped
47
+ [s1..sN] --storage full--> drop s1, retry # until written, or empty and skipped
48
+ [s1..sN] --recover--> [s1..sN] # unchanged
49
+ ```
50
+
51
+ ## Scheduler State
52
+
53
+ In memory only; not persisted.
54
+
55
+ | State | Meaning |
56
+ |-------|---------|
57
+ | `idle` | No change since the last snapshot (or since the score was loaded). No timer. |
58
+ | `armed` | A change has happened; a one-shot timer will take a snapshot at the end of the interval. |
59
+
60
+ ```text
61
+ idle --change--> armed
62
+ armed --change--> armed # no effect; one snapshot per interval
63
+ armed --timer fires--> (snapshot) --> idle
64
+ armed --score replaced--> idle # new score starts clean
65
+ armed --interval changed--> armed # timer restarted with the new interval, measured from now
66
+ ```
67
+
68
+ ## Recovery Choice
69
+
70
+ The id of the snapshot the user selected in the Recovery dialog, held until the dialog closes. On close, the view loads that snapshot (after the unsaved-changes prompt) and marks the score as changed.
@@ -0,0 +1,87 @@
1
+ # Implementation Plan: Autosave Buffers and Crash Recovery
2
+
3
+ **Branch**: `036-autosave-recovery` (work is on `main`; no feature branch was created) | **Date**: 2026-11-01 | **Spec**: [spec.md](spec.md)
4
+
5
+ **Input**: Feature specification from `/specs/036-autosave-recovery/spec.md`
6
+
7
+ ## Summary
8
+
9
+ Keep a rolling set of compressed score snapshots in the browser's local storage, next to (not replacing) the existing Quick Save slot. A small scheduler is armed by the first change after a snapshot and, when the configured interval has passed, serializes the score and hands it to a store that appends it and trims the set to the configured size. A new **Recovery** command in the File menu opens a dialog listing the snapshots, newest first; the chosen one is loaded with the same unsaved-changes prompt and score-replacement path that Open and Library already use, and the loaded score is marked as changed. The interval (5 to 60 minutes) and count (1 to 20) are two new integers on `SmoScorePreferences`, edited in a new Autosave section of the Score Preferences dialog.
10
+
11
+ The storage and timing logic is pure TypeScript with injected storage and timer, so it is tested headless. The view, dialog and menu are thin wiring around it.
12
+
13
+ ## Technical Context
14
+
15
+ **Language/Version**: TypeScript; Vue 3 single-file components for the dialog and the preferences section. Tests run with `ts-node`.
16
+
17
+ **Primary Dependencies**: None new. Reuses `SmoScoreArchive` (JSZip, already loaded by the app) to compress snapshots, `confirmReplaceScore`, `InstallDialog`, `numberInput.vue`, `dialogContainer.vue`, and the `scoreChanged` flag and `UndoBuffer.onAddBuffer` hook from the unsaved-changes feature.
18
+
19
+ **Storage**: Browser `localStorage`. One index key plus one key per snapshot. The Quick Save key (`_smoosicScore`) is untouched. Settings are stored in the score, in `SmoScorePreferences`, so they serialize with the score.
20
+
21
+ **Testing**: Headless `ts-node` script `tests/autosave.ts` (npm script `test:autosave`), following `tests/scoreChangeState.ts`. It covers preferences defaults/clamping/legacy load, the store (append, trim, quota fallback, unreadable entries, ordering) and the scheduler (arming, one snapshot per interval, no snapshot when unchanged, retiming). The dialogs and menu are checked by compilation and the manual steps in [quickstart.md](quickstart.md).
22
+
23
+ **Target Platform**: Browser application and library. The library mode (no `localStorage`, no `JSZip`) must not break: autosave is inert when storage is unavailable.
24
+
25
+ **Project Type**: Single project.
26
+
27
+ **Performance Goals**: No perceptible pause while editing. The score is serialized synchronously at the moment the timer fires (so the snapshot is a consistent state); compression and the storage write are asynchronous and happen off the editing path.
28
+
29
+ **Constraints**: Browser storage is roughly 5 MB per origin and is shared with Quick Save. Snapshots are therefore compressed, and the store drops the oldest snapshots when a write fails for lack of space, and never touches the Quick Save slot. No error is shown during editing if storage fails.
30
+
31
+ **Scale/Scope**: Up to 20 snapshots. Two new preference fields, one new pure module, one new dialog (TypeScript plus Vue), one menu entry, one preferences section, one test file.
32
+
33
+ ## Constitution Check
34
+
35
+ *GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.*
36
+
37
+ | Principle | Assessment |
38
+ |-----------|------------|
39
+ | #1 Serialization | Pass. The two new preference fields serialize with the score; a score without them loads with the defaults, and out-of-range values are clamped on load. Tests cover round-trip and legacy load. The JSON schema in `tools/smoosic-schema.json` gains the two properties. |
40
+ | #2 Editing and transformation logic regression tested | Pass. No musical transformation changes. The new logic (preferences clamping, snapshot set management, scheduling) is regression tested headless. |
41
+ | #3 Rendering performance | Pass. Nothing is measured or repainted. The snapshot never touches the DOM, and compression is asynchronous. |
42
+ | #4 Logical dependencies | Pass. The preference fields are in `src/smo`, with no UI dependency. The store and scheduler are in `src/render/sui` with injected storage and timer and no DOM dependency. Only the dialog, menu and view wiring touch the UI. |
43
+
44
+ Re-check after Phase 1 design: still passes. No complexity violations.
45
+
46
+ ## Project Structure
47
+
48
+ ### Documentation (this feature)
49
+
50
+ ```text
51
+ specs/036-autosave-recovery/
52
+ ├── plan.md # This file
53
+ ├── research.md # Phase 0 output
54
+ ├── data-model.md # Phase 1 output
55
+ ├── quickstart.md # Phase 1 output
56
+ ├── contracts/
57
+ │ └── autosave-api.md # Phase 1 output
58
+ ├── checklists/
59
+ │ └── requirements.md
60
+ └── tasks.md # Phase 2 output (/speckit-tasks - NOT created by /speckit-plan)
61
+ ```
62
+
63
+ ### Source Code (repository root)
64
+
65
+ ```text
66
+ src/smo/data/scoreModifiers.ts # autosaveInterval/autosaveCount on SmoScorePreferences; defaults, limits, clamping, legacy default
67
+ src/render/sui/autosave.ts # NEW: AutosaveStore (rolling set) and AutosaveScheduler (timing); pure, injected storage/timer
68
+ src/render/sui/scoreView.ts # owns the scheduler; markScoreChanged arms it; changeScore resets it
69
+ src/render/sui/scoreViewOperations.ts # updateScorePreferences retimes/trims; recoverSnapshot(); listSnapshots()
70
+ src/ui/dialogs/recovery.ts # NEW: SuiRecoveryDialog
71
+ src/ui/components/dialogs/recovery.vue # NEW: snapshot list, select, empty and unreadable states
72
+ src/ui/components/dialogs/scorePreferences.vue # Autosave section with two numberInput fields
73
+ src/ui/menus/file.ts # Recovery entry
74
+ src/ui/i18n/language.ts # register 'SuiRecoveryDialog'
75
+ src/application/exports.ts # export the dialog and the autosave module
76
+ tools/smoosic-schema.json # two new SmoScorePreferences properties
77
+ types/src/... # regenerated declarations for the files above only
78
+ tests/autosave.ts # NEW
79
+ package.json # test:autosave script
80
+ changes.md # changelog entry
81
+ ```
82
+
83
+ **Structure Decision**: Single-project layout as it exists. The pure module sits beside `scoreChangeState.ts`, which is the project's existing home for dependency-free view state logic that is tested without a DOM. The view owns one scheduler instance because the view already owns the "score changed" state that arms it.
84
+
85
+ ## Complexity Tracking
86
+
87
+ No constitution violations to justify.
@@ -0,0 +1,65 @@
1
+ # Quickstart: Validating Autosave and Recovery
2
+
3
+ ## Prerequisites
4
+
5
+ - Dependencies installed (`npm install`).
6
+ - The application built and served the way you normally run it for manual testing.
7
+
8
+ ## 1. Headless checks
9
+
10
+ ```text
11
+ npm run test:autosave
12
+ ```
13
+
14
+ Expected: every case in [contracts/autosave-api.md](contracts/autosave-api.md) prints `PASS` and the script exits 0. These cover the settings (defaults, limits, legacy scores), the snapshot set (add, trim, full storage, damaged entries, ordering, two tabs) and the timing rules (one snapshot per interval, none without a change).
15
+
16
+ Also run the existing suites that touch preferences and score changes, to check nothing regressed:
17
+
18
+ ```text
19
+ npm run test:score-change-state
20
+ npm run test:score-archive
21
+ ```
22
+
23
+ ## 2. Compile
24
+
25
+ ```text
26
+ npx tsc --noEmit -p tsconfig.json
27
+ ```
28
+
29
+ Expected: no errors. The dialog and menu wiring are checked this way and by the manual steps below.
30
+
31
+ ## 3. Manual: snapshots appear on their own
32
+
33
+ To avoid waiting 10 minutes, first set the interval to the minimum.
34
+
35
+ 1. Open **Score Settings > Smoosic Preferences**. In **Autosave** set *Minutes between autosaves* to 5 and *Autosaves to keep* to 3. Press OK.
36
+ 2. Enter a few notes. Wait 5 minutes. In the browser's developer tools, open Application > Local Storage and see `_smoosicAutosaveIndex` with one entry and one `_smoosicAutosave.<id>` key.
37
+ 3. Do not edit for another 5 minutes. No new entry appears.
38
+ 4. Edit, wait, edit, wait. After the fourth snapshot, only three entries remain and the oldest is gone.
39
+
40
+ ## 4. Manual: recover after a crash
41
+
42
+ 1. With at least two snapshots stored (from step 3), edit the score further, then close the tab without saving (or kill the browser process).
43
+ 2. Reopen the application. The Quick Save score or a new score opens.
44
+ 3. Open **File > Recovery**. Expect the snapshots listed newest first, each with a date, time and score title.
45
+ 4. Select the second newest and press OK. If the open score has unsaved changes, the unsaved-changes prompt appears first. Choose discard.
46
+ 5. The chosen snapshot's music is on screen and the title shows the unsaved-changes asterisk.
47
+ 6. Reopen **File > Recovery**: all snapshots are still listed.
48
+
49
+ ## 5. Manual: empty and damaged cases
50
+
51
+ 1. Clear the `_smoosicAutosave*` keys in developer tools. Open **File > Recovery**: the dialog says nothing is available and has no OK.
52
+ 2. With two snapshots stored, delete one `_smoosicAutosave.<id>` key only. Reopen the dialog: that entry is not listed.
53
+ 3. Shorten the text of another snapshot's key. Reopen the dialog: it is shown as unavailable and cannot be selected.
54
+
55
+ ## 6. Manual: settings
56
+
57
+ 1. Open Score Preferences. For a score that has never had these set, expect 10 minutes and 10 autosaves.
58
+ 2. Try 4 and 61 minutes, 0 and 21 autosaves: each is held to the nearest allowed value.
59
+ 3. Set 15 minutes and 7 autosaves. Save the score to a file, reload it, and reopen Score Preferences: the values are 15 and 7.
60
+ 4. With 6 snapshots stored, lower *Autosaves to keep* to 2 and press OK: only the 2 newest remain.
61
+ 5. Load an older `.smz` or `.json` score that has no autosave settings: it opens, and the defaults are shown.
62
+
63
+ ## 7. Manual: storage unavailable
64
+
65
+ In a private window with site data blocked (or after disabling storage in developer tools), edit a score and wait an interval. Expect no error or message during editing, and the Recovery dialog to say nothing is available.
@@ -0,0 +1,105 @@
1
+ # Research: Autosave Buffers and Crash Recovery
2
+
3
+ All Technical Context items were resolvable from the code and the clarified spec; there were no open NEEDS CLARIFICATION items.
4
+
5
+ ## R1. What to store, and how big it gets
6
+
7
+ **Decision**: Store each snapshot as the base64 text of a compressed `.smz` archive, produced by `SmoScoreArchive.pack`, and read back with `SmoScoreArchive.unpack` and `SmoScore.deserialize`.
8
+
9
+ **Rationale**: Browser storage is about 5 MB per origin and holds Quick Save as well. Quick Save writes the score as plain JSON; twenty copies of that would exhaust the space for a moderately large score. The archive format already exists (feature 034), is deflate-compressed, and is the same format a user's saved file uses, so a snapshot is a complete score by construction. Base64 is required because storage holds only text; it costs about a third more than the raw bytes, still far smaller than the JSON.
10
+
11
+ **Alternatives considered**: Plain JSON like Quick Save (too large for 20 snapshots of a big score). Storing the abbreviated dictionary form (smaller than JSON, still much larger than deflate, and the project moved away from it). IndexedDB (much more room, but asynchronous throughout, a second storage technology, and the request specified local storage).
12
+
13
+ ## R2. Where the snapshot comes from
14
+
15
+ **Decision**: Serialize from `view.storeScore`, the full score, not `view.score`, which may be a single exposed part.
16
+
17
+ **Rationale**: Quick Save, the Save dialog, and the unsaved-changes tracking all use `storeScore`. A snapshot of an exposed part would lose the rest of the score on recovery.
18
+
19
+ **Alternatives considered**: `view.score` (loses staves when a part is exposed).
20
+
21
+ ## R3. Layout of the stored data
22
+
23
+ **Decision**: One index key, `_smoosicAutosaveIndex`, holding a JSON array of entries `{ id, time, title, size }`, and one key per snapshot, `_smoosicAutosave.<id>`, holding the encoded text. `id` is a number that only increases: one more than the largest id in the index.
24
+
25
+ **Rationale**: The dialog can list the snapshots by reading only the small index, without reading or decoding twenty large entries. Ordering by `id` rather than by `time` keeps the order right if the system clock is changed (spec edge case). Separate keys let one snapshot be removed or fail without rewriting the others.
26
+
27
+ **Alternatives considered**: A single key holding an array of all snapshots (rewrites everything on every snapshot, and one failed write could lose the whole set). Time as the identifier (breaks with clock changes, and two tabs could collide).
28
+
29
+ ## R4. Writing, trimming and running out of space
30
+
31
+ **Decision**: To add a snapshot, the store re-reads the index from storage, writes the new entry key, then writes the updated index, then removes the entries trimmed off the old end. If the entry write throws (quota), it removes the oldest snapshot and retries, until the write succeeds or no snapshots remain; if it still fails the snapshot is dropped silently and the existing snapshots are left as they were. Index entries whose snapshot key is missing are removed whenever the index is read.
32
+
33
+ **Rationale**: Re-reading the index immediately before every write is the cheap way to share the set between two tabs on the same origin, since each read-modify-write is synchronous. Writing the entry before the index means a failure in between leaves an unreferenced entry key rather than an index entry pointing at nothing. Giving up the oldest snapshots first on a full store follows the spec edge case, and never touching the Quick Save key protects the one save the application loads on startup.
34
+
35
+ **Alternatives considered**: Locking across tabs (no good primitive for plain local storage, and the race window is a few synchronous statements). Refusing to write when full (the user would silently lose protection).
36
+
37
+ ## R5. When the timer runs
38
+
39
+ **Decision**: The scheduler is armed by the first change after a snapshot (or after the score is loaded). It fires once, `interval` minutes later, and takes the snapshot. A change while it is armed does nothing, so many quick edits yield one snapshot. After it fires it is idle until the next change. A load of a new score, or the preferences changing, cancels it and rearms if a change is pending.
40
+
41
+ **Rationale**: This is exactly "every 10 minutes after a change" and makes the two rules in the spec hold by construction: no snapshot for an unchanged score, and no two snapshots closer than the interval. A free-running periodic timer would need a separate "changed since last snapshot" check and could snapshot a few seconds after a change.
42
+
43
+ **Alternatives considered**: A fixed-rate interval timer (more wakeups, needs a dirty flag anyway). Debounce after the last edit (a user editing continuously would never get a snapshot).
44
+
45
+ ## R6. What counts as a change
46
+
47
+ **Decision**: The scheduler is armed from `SuiScoreView.markScoreChanged`, which the undo buffer already calls whenever an edit is recorded (feature 028).
48
+
49
+ **Rationale**: It is the project's single definition of "the score has been edited," and it is already called for every edit path. Reusing it means autosave and the unsaved-changes asterisk can't disagree.
50
+
51
+ **Alternatives considered**: A separate hash of the serialized score on each tick (expensive for large scores). Hooking each edit operation (many paths, easy to miss one).
52
+
53
+ ## R7. Settings and their limits
54
+
55
+ **Decision**: Add `autosaveInterval` (minutes, default 10, valid 5 to 60) and `autosaveCount` (default 10, valid 1 to 20) to `SmoScorePreferences`. The constructor rounds to an integer and clamps into range, and uses the default when the value is absent. The same clamp function is used by the preferences section.
56
+
57
+ **Rationale**: Clamping at the one place values enter the object means a hand-edited or damaged file can't produce a zero or negative interval, which would make the timer fire constantly. Missing values give the defaults, which is the legacy-score requirement. The scores' preference object is already serialized with the score, so no other serialization code changes.
58
+
59
+ **Alternatives considered**: Validating only in the dialog (a loaded file could still contain bad values). Throwing on bad values (a score that loads today would stop loading).
60
+
61
+ ## R8. Which score's settings apply
62
+
63
+ **Decision**: The settings of the open score decide the interval and the count. The stored set is shared by all scores in the browser, so the count limits the whole set, not each score.
64
+
65
+ **Rationale**: There are no global settings (clarification), the set is what the user sees in the Recovery dialog, and a limit on the whole set is what keeps storage bounded. Each entry carries the title of its score, so the list is still readable when several scores have been open.
66
+
67
+ **Alternatives considered**: A set per score (unbounded storage in total, and the dialog would need a score picker before the snapshot picker).
68
+
69
+ ## R9. Recovering a snapshot
70
+
71
+ **Decision**: The Recovery dialog only records the user's choice. After it has closed, `confirmReplaceScore` asks about unsaved changes (the same call Library uses), and then the view decodes the snapshot and calls `changeScore`. Afterward it calls `markScoreChanged`, because `changeScore` always marks a new score as saved but a recovered score has not been saved to a file. No snapshot is removed.
72
+
73
+ **Rationale**: This reuses the proven open/replace path and its prompt (spec FR-009) and satisfies FR-008 by marking the score as changed, so the user is prompted before leaving it. Decode errors are reported with the same "could not open" message the file loader uses, and the current score is left alone.
74
+
75
+ **Alternatives considered**: Replacing the score inside the dialog (skips the unsaved-changes prompt, and the dialog would still be mounted during the load).
76
+
77
+ ## R10. Unreadable snapshots
78
+
79
+ **Decision**: The dialog lists the entries from the index. An entry is shown as unavailable if its stored text is missing, or does not match the recorded size. A snapshot that passes that check but fails to decode when chosen shows the load error and the dialog's other entries stay usable.
80
+
81
+ **Rationale**: The full decode of up to twenty snapshots on opening the dialog would be slow and would hold the scores in memory just to draw a list. Missing or truncated text is the realistic damage (a partial write, or storage cleared by the browser), and it is detected from the key and its length.
82
+
83
+ **Alternatives considered**: Decoding every entry when the dialog opens (slow). No check at all (a user could pick an entry that is obviously gone).
84
+
85
+ ## R11. When storage is not available
86
+
87
+ **Decision**: The store is created only if `localStorage` can be read and written in a test call; otherwise the scheduler is inert (no timer is armed) and the Recovery dialog shows its empty state with a note that storage is unavailable.
88
+
89
+ **Rationale**: Private browsing modes and library embeddings can throw on any storage access. The spec requires the application to keep working normally.
90
+
91
+ **Alternatives considered**: Keeping snapshots in memory when storage is unavailable (does not survive a crash, so it is not recovery).
92
+
93
+ ## R12. Time and the page closing
94
+
95
+ **Decision**: No snapshot is taken on page close. A tab closed cleanly keeps its existing snapshots, but changes made in the last interval before a clean close are not snapshotted.
96
+
97
+ **Rationale**: Compression is asynchronous and cannot be completed reliably while a page is unloading. Quick Save and the file Save remain the way to keep a clean exit.
98
+
99
+ **Alternatives considered**: A synchronous uncompressed snapshot on `pagehide` (can overflow the space the compressed set is sized for, and could evict good snapshots right before the user leaves).
100
+
101
+ ## R13. The schema file
102
+
103
+ **Decision**: Add the two properties to `SmoScorePreferences` in `tools/smoosic-schema.json` with their defaults. The separate SmoSchema repository is outside this change and is noted in the changelog.
104
+
105
+ **Rationale**: The in-repo schema file lists the preference fields next to their defaults and should stay in step with the code.
@@ -0,0 +1,143 @@
1
+ # Feature Specification: Autosave Buffers and Crash Recovery
2
+
3
+ **Feature Branch**: `036-autosave-recovery`
4
+
5
+ **Created**: 2026-11-01
6
+
7
+ **Status**: Draft
8
+
9
+ **Input**: User description: "We currently do quick save to the session storate. Keep a running buffer of autosaves in the local session. Ever 10 minutes after a change, create a new auto save buffer with the current state. In the file menu, create a 'Recovery' dialog, where the user can pick any of the current buffers to recover a crash. In the score preferences menu, create an autosave section where the user can adjust the settings. Number of buffers up to 20, timer 5 min. to 1 hour in minute increments, default is 10 minutes and 10 sessions. Save this in the Smo preferences object."
10
+
11
+ ## Clarifications
12
+
13
+ ### Session 2026-11-01
14
+
15
+ - Q: Should autosave snapshots live in storage that survives a crash, or storage cleared when the tab closes? → A: The browser's local storage (same kind of storage Quick Save already uses); "session storage" in the original request meant local storage.
16
+ - Q: Where are the autosave settings stored: with each score, or as a global browser setting? → A: In the score preferences (`SmoScorePreferences`), saved with each score. There are no global browser settings today other than the autosaved score, and this feature does not add any.
17
+ - Q: What is the minimum number of snapshots the user can choose? → A: 1.
18
+
19
+ ## User Scenarios & Testing *(mandatory)*
20
+
21
+ ### User Story 1 - Automatic snapshots while I work (Priority: P1)
22
+
23
+ A composer is working on a score for a long stretch. Without doing anything, the application periodically keeps a snapshot of the score as it is at that moment. A snapshot is only taken if the score has changed since the previous one, and no more often than the configured interval. The application keeps a rolling set of the most recent snapshots; when the set is full, the oldest is discarded to make room for the newest. The user is never interrupted to take a snapshot.
24
+
25
+ **Why this priority**: Without the snapshots there is nothing to recover. This is the foundation of the feature, and it delivers protection even before a recovery screen exists.
26
+
27
+ **Independent Test**: With default settings, open a score, make an edit, and wait one interval. A new snapshot exists. Make no further edits and wait another interval: no additional snapshot is created. Make another edit and wait: a second snapshot exists.
28
+
29
+ **Acceptance Scenarios**:
30
+
31
+ 1. **Given** the default settings and a score with no changes since the last snapshot, **When** the interval elapses, **Then** no new snapshot is created.
32
+ 2. **Given** the user makes a change to the score, **When** the configured interval has elapsed since the previous snapshot (or since the change, if no previous snapshot exists), **Then** a new snapshot of the current score is added to the set.
33
+ 3. **Given** the set already holds the maximum number of snapshots, **When** a new snapshot is taken, **Then** the oldest snapshot is removed and the new one is added, so the set never exceeds the maximum.
34
+ 4. **Given** the user makes many changes in quick succession, **When** the interval has not yet elapsed, **Then** only one snapshot is taken for that interval, not one per change.
35
+ 5. **Given** a snapshot is being taken, **Then** the user can keep editing without a visible pause or prompt.
36
+ 6. **Given** the browser has no room left to store a snapshot, **When** a snapshot is attempted, **Then** the oldest snapshots are discarded until the new one fits, and the application keeps working normally; if it still cannot be stored, the user is not interrupted and the previous snapshots remain.
37
+
38
+ ---
39
+
40
+ ### User Story 2 - Recover my work after a crash (Priority: P1)
41
+
42
+ After the browser or the application crashes (or the tab is closed by accident), the user reopens Smoosic and wants their work back. From the **File** menu they choose **Recovery**. A dialog lists every snapshot currently kept, newest first, each showing when it was taken and enough about the score (such as its title and size) for the user to tell them apart. The user picks one and confirms, and that snapshot is loaded as the current score. Cancelling leaves the current score untouched. Snapshots are not deleted by recovering one, so the user can try another if the first was not the one they wanted.
43
+
44
+ **Why this priority**: This is the reason the feature exists. A crash loses at most one interval of work, and the user can choose how far back to go.
45
+
46
+ **Independent Test**: Make three separate edits with snapshots in between, open File > Recovery, and confirm that three snapshots are listed newest first. Select the middle one and confirm: the score on screen matches the state at the time of that snapshot. Reopen Recovery and confirm all three are still listed.
47
+
48
+ **Acceptance Scenarios**:
49
+
50
+ 1. **Given** snapshots exist, **When** the user opens File > Recovery, **Then** a dialog lists all snapshots, newest first, each with its date and time and identifying details about the score.
51
+ 2. **Given** the Recovery dialog is open, **When** the user selects a snapshot and confirms, **Then** that snapshot replaces the current score on screen.
52
+ 3. **Given** the Recovery dialog is open, **When** the user cancels, **Then** the current score is unchanged.
53
+ 4. **Given** no snapshots exist, **When** the user opens File > Recovery, **Then** the dialog states that there is nothing to recover, and offers no selection.
54
+ 5. **Given** the user has recovered a snapshot, **Then** the snapshots remain available and the recovered score is treated as having unsaved changes, so the user is still prompted to save it to a file.
55
+ 6. **Given** the current score has unsaved changes, **When** the user confirms a recovery, **Then** the user is warned that the current score will be replaced before it happens, with the chance to back out.
56
+ 7. **Given** a stored snapshot can no longer be read, **Then** it is shown as unreadable and cannot be selected, and the other snapshots are still usable.
57
+
58
+ ---
59
+
60
+ ### User Story 3 - Adjust autosave to my needs (Priority: P2)
61
+
62
+ Different users have different needs. A user working on a very large score may find frequent snapshots wasteful and want a longer interval and fewer snapshots. A cautious user may want a short interval and many snapshots. In the **Score Preferences** dialog, there is an **Autosave** section where the user sets how often snapshots are taken (from 5 to 60 minutes, in whole-minute steps) and how many are kept (from 1 up to 20). The defaults are every 10 minutes and 10 snapshots. The new settings take effect right away, and are remembered with the other preferences.
63
+
64
+ **Why this priority**: The defaults give most of the value; the settings make the feature fit different users and scores but are not required for the core protection.
65
+
66
+ **Independent Test**: Open Score Preferences, find the Autosave section showing 10 minutes and 10 snapshots, change them to 5 and 3, save, and reopen: the new values are shown. Make edits until more than 3 snapshots would exist, and confirm only the 3 newest are kept.
67
+
68
+ **Acceptance Scenarios**:
69
+
70
+ 1. **Given** a score that has never had autosave settings changed, **When** the user opens Score Preferences, **Then** the Autosave section shows an interval of 10 minutes and a maximum of 10 snapshots.
71
+ 2. **Given** the Autosave section, **When** the user enters an interval, **Then** only whole minutes from 5 to 60 are accepted; values outside that range are rejected or limited to the nearest allowed value.
72
+ 3. **Given** the Autosave section, **When** the user enters a snapshot count, **Then** only whole numbers from 1 to 20 are accepted.
73
+ 4. **Given** the user lowers the snapshot count below the number of snapshots currently stored, **When** the preferences are saved, **Then** the oldest snapshots beyond the new limit are removed.
74
+ 5. **Given** the user changes the interval, **When** the preferences are saved, **Then** the next snapshot is scheduled using the new interval.
75
+ 6. **Given** the settings were changed and the score is saved and reloaded, **Then** the settings are the same as the user chose.
76
+ 7. **Given** a score saved before this feature existed, **When** it is opened, **Then** it uses the default autosave settings without error.
77
+
78
+ ---
79
+
80
+ ### Edge Cases
81
+
82
+ - The user has the score open in two browser tabs: snapshots from both are kept in the same set, each identifiable by its time and score title; neither tab removes the other's snapshots except by the rolling limit.
83
+ - The browser's storage is cleared, disabled, or blocked (for example in private browsing): autosave quietly does nothing, the application continues to work, and the Recovery dialog explains that no snapshots are available.
84
+ - The score is very large and a snapshot would not fit in the remaining storage: older snapshots are discarded to make room, as described in the first story; the quick save of the current score is never sacrificed to autosave.
85
+ - The user saves the score to a file: this does not delete snapshots, since they remain useful as history until they roll off.
86
+ - The user closes the tab cleanly: the snapshots are still kept for the next visit.
87
+ - The user opens a different score, or starts a new score: snapshots of earlier scores remain in the list, each labeled by its score title, until they roll off.
88
+ - The clock is changed during a session: snapshots are still listed in the order they were taken.
89
+ - The interval or count is changed while a snapshot is due: the change applies from that moment, and a snapshot is never taken more often than the interval in force.
90
+ - A snapshot is taken at the same moment the user presses Quick Save: both complete, and neither corrupts the other.
91
+
92
+ ## Requirements *(mandatory)*
93
+
94
+ ### Functional Requirements
95
+
96
+ - **FR-001**: The application MUST keep a rolling set of autosave snapshots of the score in the browser's local storage for the current session of use, separate from the existing Quick Save slot.
97
+ - **FR-002**: The application MUST take a new snapshot only when the score has changed since the last snapshot and the configured interval has elapsed.
98
+ - **FR-003**: The application MUST NOT keep more snapshots than the configured maximum; when a new snapshot would exceed the maximum, the oldest snapshots MUST be removed first.
99
+ - **FR-004**: Taking a snapshot MUST NOT interrupt the user, block editing, or change the state of the score (including its saved/unsaved status).
100
+ - **FR-005**: The File menu MUST include a **Recovery** command that opens a Recovery dialog.
101
+ - **FR-006**: The Recovery dialog MUST list all stored snapshots, newest first, showing the date and time taken and identifying details of the score (such as its title).
102
+ - **FR-007**: The user MUST be able to select one snapshot in the Recovery dialog and load it as the current score, or cancel without any change.
103
+ - **FR-008**: Recovering a snapshot MUST NOT delete any snapshot, and the recovered score MUST be treated as having unsaved changes.
104
+ - **FR-009**: Before a recovery replaces a score that has unsaved changes, the application MUST warn the user and allow them to back out.
105
+ - **FR-010**: The Recovery dialog MUST show a clear message when no snapshots exist, and MUST mark any unreadable snapshot as unavailable without blocking the others.
106
+ - **FR-011**: The Score Preferences dialog MUST include an **Autosave** section where the user can set the snapshot interval and the maximum number of snapshots.
107
+ - **FR-012**: The snapshot interval MUST be adjustable from 5 minutes to 60 minutes in 1-minute steps, defaulting to 10 minutes.
108
+ - **FR-013**: The maximum number of snapshots MUST be adjustable from 1 to 20, defaulting to 10.
109
+ - **FR-014**: Out-of-range or non-whole values for either setting MUST NOT be accepted.
110
+ - **FR-015**: The autosave settings MUST be stored with the other score preferences, so that they are saved with the score and restored when it is reopened.
111
+ - **FR-016**: Scores saved before this feature existed MUST open without error and use the default autosave settings.
112
+ - **FR-017**: Changes to the settings MUST take effect without restarting the application, including trimming stored snapshots when the maximum is lowered.
113
+ - **FR-018**: If snapshots cannot be stored (storage unavailable, blocked, or full), the application MUST continue to work normally and MUST NOT show an error during editing.
114
+
115
+ ### Key Entities
116
+
117
+ - **Autosave Snapshot**: A copy of the whole score as it was at a moment in time. Has a time taken and identifying details (score title) so the user can tell snapshots apart. Snapshots are kept in order of age and form a rolling set limited by the maximum count.
118
+ - **Autosave Settings**: The user's choices for how often a snapshot is taken (5 to 60 whole minutes, default 10) and how many are kept (1 to 20, default 10). Part of the score preferences, saved with the score.
119
+ - **Recovery Choice**: The user's selection of one snapshot from the list to become the current score.
120
+
121
+ ## Success Criteria *(mandatory)*
122
+
123
+ ### Measurable Outcomes
124
+
125
+ - **SC-001**: After an unexpected closure, a user can get back to a snapshot of their work in under 30 seconds from reopening the application, using only the File menu and the Recovery dialog.
126
+ - **SC-002**: With default settings, a user who edits continuously loses no more than 10 minutes of work in a crash, and can choose among up to 10 earlier states.
127
+ - **SC-003**: Taking a snapshot causes no noticeable pause in editing for scores of typical size (users cannot perceive a delay during normal editing).
128
+ - **SC-004**: A user can find and change both autosave settings in under 1 minute from opening Score Preferences.
129
+ - **SC-005**: In testing across the full allowed range of settings (5 to 60 minutes; 1 to 20 snapshots), the number of stored snapshots never exceeds the chosen maximum and no snapshot is taken more often than the chosen interval.
130
+ - **SC-006**: 100% of scores saved before this feature existed open without error and show the default autosave settings.
131
+ - **SC-007**: A recovered snapshot is identical in content to the score at the time the snapshot was taken.
132
+
133
+ ## Assumptions
134
+
135
+ - Snapshots are kept in the browser's local storage (the same kind of storage Quick Save already uses), so that they survive a crash, a closed tab and a browser restart.
136
+ - The autosave settings are part of the score preferences, which are saved with the score and edited in the Score Preferences dialog, so the settings travel with each score file. The settings that apply while working are those of the score currently open. No new global browser settings are introduced.
137
+ - "Every 10 minutes after a change" means that the clock starts when the first unsnapshotted change happens, and a snapshot is taken once the interval has elapsed. No snapshot is taken for an unchanged score.
138
+ - The minimum interval is 5 minutes and the maximum is 60 minutes; the minimum number of snapshots is 1 and the maximum is 20.
139
+ - Snapshots are kept per browser, not per score. They are not synchronized between devices.
140
+ - The existing Quick Save feature keeps working as it does today and is not replaced by this feature.
141
+ - Recovery loads the chosen snapshot as the current score; it does not offer to merge it with the current score.
142
+ - Snapshots are capped by count, not by size. If storage is full, the oldest snapshots are given up first.
143
+ - A user-facing label for snapshots is the date/time plus score title; additional detail (such as number of measures) is optional.