smoosic 2.0.1 → 2.0.3

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 (127) hide show
  1. package/build/smoosic.js +171 -78
  2. package/package.json +82 -77
  3. package/release/smoosic.js +171 -78
  4. package/release/styles/fonts/MaterialIconsOutlined-Regular.otf +0 -0
  5. package/release/styles/menus.css +26 -0
  6. package/specs/022-text-reposition-on-resize/spec.md +1 -0
  7. package/specs/027-fix-bottom-modifier-lookup/checklists/requirements.md +38 -0
  8. package/specs/027-fix-bottom-modifier-lookup/contracts/division-lookup-contract.md +51 -0
  9. package/specs/027-fix-bottom-modifier-lookup/data-model.md +43 -0
  10. package/specs/027-fix-bottom-modifier-lookup/plan.md +77 -0
  11. package/specs/027-fix-bottom-modifier-lookup/quickstart.md +36 -0
  12. package/specs/027-fix-bottom-modifier-lookup/research.md +58 -0
  13. package/specs/027-fix-bottom-modifier-lookup/spec.md +105 -0
  14. package/specs/027-fix-bottom-modifier-lookup/tasks.md +167 -0
  15. package/specs/028-unsaved-changes-indicator/checklists/requirements.md +39 -0
  16. package/specs/028-unsaved-changes-indicator/contracts/score-change-contract.md +44 -0
  17. package/specs/028-unsaved-changes-indicator/data-model.md +64 -0
  18. package/specs/028-unsaved-changes-indicator/plan.md +96 -0
  19. package/specs/028-unsaved-changes-indicator/quickstart.md +54 -0
  20. package/specs/028-unsaved-changes-indicator/research.md +68 -0
  21. package/specs/028-unsaved-changes-indicator/spec.md +135 -0
  22. package/specs/028-unsaved-changes-indicator/tasks.md +173 -0
  23. package/specs/029-remove-promise-helpers/checklists/requirements.md +39 -0
  24. package/specs/029-remove-promise-helpers/contracts/public-api-contract.md +32 -0
  25. package/specs/029-remove-promise-helpers/data-model.md +45 -0
  26. package/specs/029-remove-promise-helpers/plan.md +86 -0
  27. package/specs/029-remove-promise-helpers/quickstart.md +53 -0
  28. package/specs/029-remove-promise-helpers/research.md +71 -0
  29. package/specs/029-remove-promise-helpers/spec.md +107 -0
  30. package/specs/029-remove-promise-helpers/tasks.md +164 -0
  31. package/specs/030-copy-paste-voices/checklists/requirements.md +39 -0
  32. package/specs/030-copy-paste-voices/contracts/voice-copy-paste-contract.md +47 -0
  33. package/specs/030-copy-paste-voices/data-model.md +63 -0
  34. package/specs/030-copy-paste-voices/plan.md +80 -0
  35. package/specs/030-copy-paste-voices/quickstart.md +50 -0
  36. package/specs/030-copy-paste-voices/research.md +80 -0
  37. package/specs/030-copy-paste-voices/spec.md +124 -0
  38. package/specs/030-copy-paste-voices/tasks.md +183 -0
  39. package/specs/031-select-voice/checklists/requirements.md +39 -0
  40. package/specs/031-select-voice/contracts/select-voice-contract.md +43 -0
  41. package/specs/031-select-voice/data-model.md +47 -0
  42. package/specs/031-select-voice/plan.md +79 -0
  43. package/specs/031-select-voice/quickstart.md +43 -0
  44. package/specs/031-select-voice/research.md +55 -0
  45. package/specs/031-select-voice/spec.md +113 -0
  46. package/specs/031-select-voice/tasks.md +171 -0
  47. package/src/application/application.ts +464 -459
  48. package/src/common/promiseHelpers.ts +2 -2
  49. package/src/render/audio/samples.ts +117 -118
  50. package/src/render/sui/pageDivisions.ts +58 -0
  51. package/src/render/sui/renderState.ts +469 -464
  52. package/src/render/sui/scoreChangeState.ts +62 -0
  53. package/src/render/sui/scoreView.ts +30 -0
  54. package/src/render/sui/scoreViewOperations.ts +2555 -2380
  55. package/src/render/sui/svgPageMap.ts +16 -17
  56. package/src/render/sui/textEdit.ts +310 -311
  57. package/src/render/sui/tracker.ts +40 -0
  58. package/src/render/vex/vxNote.ts +3 -1
  59. package/src/smo/xform/copypaste.ts +304 -4
  60. package/src/smo/xform/selections.ts +68 -0
  61. package/src/smo/xform/undo.ts +9 -0
  62. package/src/styles/menus.css +26 -0
  63. package/src/ui/buttons/ribbon.ts +3 -1
  64. package/src/ui/components/buttons/sidebar.vue +15 -6
  65. package/src/ui/components/dialogs/library.vue +3 -1
  66. package/src/ui/components/dialogs/unsavedChanges.vue +44 -0
  67. package/src/ui/dialogs/adapter.ts +181 -183
  68. package/src/ui/dialogs/addMeasure.ts +97 -97
  69. package/src/ui/dialogs/annotationVue.ts +56 -56
  70. package/src/ui/dialogs/audioSettings.ts +121 -123
  71. package/src/ui/dialogs/chordChangeVue.ts +46 -46
  72. package/src/ui/dialogs/clefChange.ts +53 -53
  73. package/src/ui/dialogs/customTuplets.ts +95 -96
  74. package/src/ui/dialogs/customTupletsVue.ts +47 -47
  75. package/src/ui/dialogs/dialog.ts +627 -620
  76. package/src/ui/dialogs/durations.ts +34 -34
  77. package/src/ui/dialogs/dynamics.ts +140 -142
  78. package/src/ui/dialogs/factory.ts +198 -198
  79. package/src/ui/dialogs/fileDialogs.ts +245 -179
  80. package/src/ui/dialogs/fonts.ts +93 -93
  81. package/src/ui/dialogs/globalLayout.ts +40 -40
  82. package/src/ui/dialogs/gracenote.ts +31 -31
  83. package/src/ui/dialogs/hairpin.ts +108 -110
  84. package/src/ui/dialogs/hairpinVue.ts +51 -51
  85. package/src/ui/dialogs/instrument.ts +111 -111
  86. package/src/ui/dialogs/keySignature.ts +175 -176
  87. package/src/ui/dialogs/keySignatureVue.ts +47 -47
  88. package/src/ui/dialogs/library.ts +207 -207
  89. package/src/ui/dialogs/libraryVue.ts +62 -48
  90. package/src/ui/dialogs/lyricVue.ts +46 -46
  91. package/src/ui/dialogs/measureFormat.ts +78 -78
  92. package/src/ui/dialogs/microtones.ts +147 -147
  93. package/src/ui/dialogs/noteHead.ts +319 -319
  94. package/src/ui/dialogs/pageLayout.ts +61 -61
  95. package/src/ui/dialogs/partInfo.ts +60 -60
  96. package/src/ui/dialogs/pedalMarking.ts +117 -117
  97. package/src/ui/dialogs/pedalMarkingVue.ts +73 -73
  98. package/src/ui/dialogs/pitch.ts +352 -352
  99. package/src/ui/dialogs/preferences.ts +40 -40
  100. package/src/ui/dialogs/rehearsalMark.ts +64 -64
  101. package/src/ui/dialogs/rehearsalMarkVue.ts +57 -57
  102. package/src/ui/dialogs/scoreId.ts +35 -36
  103. package/src/ui/dialogs/scoreView.ts +42 -42
  104. package/src/ui/dialogs/slur.ts +308 -310
  105. package/src/ui/dialogs/slurVue.ts +91 -91
  106. package/src/ui/dialogs/staffGroup.ts +112 -112
  107. package/src/ui/dialogs/tabNote.ts +84 -84
  108. package/src/ui/dialogs/tabStave.ts +182 -182
  109. package/src/ui/dialogs/tempo.ts +261 -263
  110. package/src/ui/dialogs/tempoVue.ts +73 -73
  111. package/src/ui/dialogs/textBlockVue.ts +127 -127
  112. package/src/ui/dialogs/textBracket.ts +114 -116
  113. package/src/ui/dialogs/textBracketVue.ts +56 -56
  114. package/src/ui/dialogs/tie.ts +140 -142
  115. package/src/ui/dialogs/timeSignature.ts +65 -66
  116. package/src/ui/dialogs/transposeScore.ts +39 -39
  117. package/src/ui/dialogs/unsavedChanges.ts +43 -0
  118. package/src/ui/dialogs/volta.ts +120 -122
  119. package/src/ui/dialogs/voltaVue.ts +51 -51
  120. package/src/ui/fileio/library.ts +110 -111
  121. package/src/ui/menus/edit.ts +100 -1
  122. package/src/ui/menus/file.ts +19 -3
  123. package/tests/pageDivisions.ts +156 -0
  124. package/tests/promiseHelpersUsage.ts +142 -0
  125. package/tests/scoreChangeState.ts +102 -0
  126. package/tests/selectVoice.ts +189 -0
  127. package/tests/voiceCopyPaste.ts +417 -0
@@ -0,0 +1,173 @@
1
+ ---
2
+
3
+ description: "Task list for Unsaved Changes Indicator and Save Prompt"
4
+ ---
5
+
6
+ # Tasks: Unsaved Changes Indicator and Save Prompt
7
+
8
+ **Input**: Design documents from `/specs/028-unsaved-changes-indicator/`
9
+
10
+ **Prerequisites**: [plan.md](./plan.md), [spec.md](./spec.md), [research.md](./research.md), [data-model.md](./data-model.md), [contracts/score-change-contract.md](./contracts/score-change-contract.md), [quickstart.md](./quickstart.md)
11
+
12
+ **Tests**: Included. The plan commits to a headless `tests/scoreChangeState.ts` script (cases S1 to S14) for the pure logic and the undo hook. UI behavior (cases U1 to U17) is checked manually per quickstart.md.
13
+
14
+ **Organization**: Tasks are grouped by user story. The shared state and the pure policy module are foundational because all three stories read them.
15
+
16
+ ## Format: `[ID] [P?] [Story] Description`
17
+
18
+ - **[P]**: Can run in parallel (different files, no dependencies on incomplete tasks)
19
+ - **[Story]**: Which user story this task belongs to (US1, US2, US3)
20
+
21
+ ## Path Conventions
22
+
23
+ Single project: `src/`, `tests/`, repo-root `package.json`.
24
+
25
+ ---
26
+
27
+ ## Phase 1: Setup
28
+
29
+ - [X] T001 Add the script `"test:score-change-state": "ts-node -P tests/tsconfig.json tests/scoreChangeState.ts"` to `package.json`, next to the existing `test:page-divisions` entry.
30
+ - [X] T002 Create `tests/scoreChangeState.ts` with the scaffold only: header comment pointing at `specs/028-unsaved-changes-indicator/contracts/score-change-contract.md`, the `failures` counter and `check(name, condition, detail?)` helper copied from `tests/pageDivisions.ts`, and the final summary block (`all checks passed`, or `process.exitCode = 1`). It may import only `src/smo/xform/undo.ts` and `src/render/sui/scoreChangeState.ts` (no DOM, Vue or VexFlow).
31
+
32
+ ---
33
+
34
+ ## Phase 2: Foundational (Blocking Prerequisites)
35
+
36
+ **Purpose**: The undo hook, the pure policy module and the view state that every story uses.
37
+
38
+ **CRITICAL**: No user story work can begin until this phase is complete.
39
+
40
+ - [X] T003 [P] In `src/smo/xform/undo.ts`, add an optional public field `onAddBuffer?: () => void` to `UndoBuffer` (documented as a listener for any recorded undo step) and call it at the end of `addBuffer`, after the entry has been stored. Do not clear it in `reset()`.
41
+ - [X] T004 [P] Create `src/render/sui/scoreChangeState.ts` with no imports, exporting: `type SaveOutcome = 'saved' | 'exported' | 'cancelled'`; `type AfterSaveStep = 'load' | 'prompt' | 'abort'`; `isFullSaveFormat(extension)` (true only for `.json`, compared case-insensitively); `formatScoreTitle(name, changed)` (trimmed name or `Untitled` when empty, plus a trailing `*` when changed); `nextStepAfterSave(outcome)` (`saved` returns `load`, `exported` returns `prompt`, `cancelled` returns `abort`). Per [data-model.md](./data-model.md).
42
+ - [X] T005 [P] In `tests/scoreChangeState.ts`, add cases S1 to S4 (`UndoBuffer.onAddBuffer`: unset is harmless, fires once per `addBuffer`, fires inside grouping, survives `reset()`). Build entries with `UndoBuffer.bufferTypes.COLUMN` or the simplest type that `addBuffer` accepts with a minimal object.
43
+ - [X] T006 [P] In `tests/scoreChangeState.ts`, add cases S5 to S14 (`isFullSaveFormat`, `formatScoreTitle` including the empty-name and asterisk cases, `nextStepAfterSave`).
44
+ - [X] T007 Run `npm run test:score-change-state` and fix `undo.ts` / `scoreChangeState.ts` until every case passes.
45
+ - [X] T008 In `src/render/sui/scoreView.ts`, add `scoreChanged: Ref<boolean> = ref(false)` and `scoreName: Ref<string> = ref('')` next to the existing `selectedPart`; add `markScoreChanged()`, `markScoreSaved()` and `refreshScoreName()` (sets `scoreName.value` from `this.score.scoreInfo.name`); in the constructor set `this.storeUndo.onAddBuffer = () => this.markScoreChanged()` after `storeUndo` is created and call `refreshScoreName()`.
46
+ - [X] T009 In `src/render/sui/scoreView.ts`, update `undo()` to call `markScoreChanged()` and `refreshScoreName()` after the restore, and update `changeScore()` to call `markScoreSaved()` and `refreshScoreName()` as its last step after `await this.awaitRender()` and before returning.
47
+
48
+ **Checkpoint**: The flag is set by every recorded undo step and cleared by every score load; the pure logic is tested.
49
+
50
+ ---
51
+
52
+ ## Phase 3: User Story 1 - See which score is open and whether it has unsaved changes (Priority: P1) MVP
53
+
54
+ **Goal**: The sidebar header shows the score name with an asterisk when changed, and it clears on a full-format save.
55
+
56
+ **Independent Test**: quickstart.md section 4, steps 1 to 8 (header, edits, renaming, Smoosic-format save clears, MusicXML export does not, Quick Save clears).
57
+
58
+ ### Implementation for User Story 1
59
+
60
+ - [X] T010 [US1] In `src/render/sui/scoreViewOperations.ts`, import `isFullSaveFormat` and add `recordSave(extension: string): boolean`, which calls `markScoreSaved()` and returns true when `isFullSaveFormat(extension)`, and otherwise leaves the flag unchanged and returns false. In `quickSave()`, call `markScoreSaved()` after the local-storage write.
61
+ - [X] T011 [US1] In `src/render/sui/scoreViewOperations.ts` `updateScoreInfo`, call `this.refreshScoreName()` after the score info is assigned.
62
+ - [X] T012 [US1] In `src/ui/dialogs/fileDialogs.ts` `SuiFileSaveDialog`, call `parameters.view.recordSave(extension.value)` from the dialog's `commitCb` (currently empty), so the decision is made by the view operation, not the dialog.
63
+ - [X] T013 [US1] In `src/ui/components/buttons/sidebar.vue`, add props `scoreName: Ref<string>` and `scoreChanged: Ref<boolean>` and show `Smoosic {{ formatScoreTitle(scoreName, scoreChanged) }}` in the `side-brand` span (import `formatScoreTitle` from `src/render/sui/scoreChangeState`). Add a CSS rule in `src/styles/menus.css` next to `.side-brand` so a long name is truncated with an ellipsis instead of breaking the layout.
64
+ - [X] T014 [US1] In `src/ui/buttons/ribbon.ts` `createSidebarMenuHtml`, pass `scoreName: this.view.scoreName` and `scoreChanged: this.view.scoreChanged` in the `createApp(ribbonSidebarApp, ...)` props.
65
+ - [X] T015 [US1] Run `npx tsc --noEmit -p tsconfig.json` and fix any errors.
66
+ - [ ] T016 [US1] Manual validation: quickstart.md section 4, steps 1 to 8 (U1 to U9).
67
+
68
+ **Checkpoint**: The header and the save behavior work; users can see unsaved changes.
69
+
70
+ ---
71
+
72
+ ## Phase 4: User Story 2 - Be asked to save before replacing the open score (Priority: P1)
73
+
74
+ **Goal**: New, Open, Import and Library loads ask Save / Don't save / Cancel when the score has unsaved changes, with the lossy-export loop.
75
+
76
+ **Independent Test**: quickstart.md section 4, steps 9 to 14 (U10 to U17).
77
+
78
+ ### Implementation for User Story 2
79
+
80
+ - [X] T017 [US2] In `src/ui/dialogs/dialog.ts`, add `afterCloseCb?: DialogCallback` to `DialogInstallParams` and, in `InstallDialog`'s `commitCb` only, `await params.afterCloseCb?.()` after `dialogApp?.unmount()`. Do not call it from `cancelCb` or `removeCb`.
81
+ - [X] T018 [US2] In `src/ui/dialogs/fileDialogs.ts` `SuiFileSaveDialog`, add an optional second parameter `onClosed?: (outcome: SaveOutcome) => void`. Call it from `commitCb` with `'saved'` when `recordSave` returned true and `'exported'` otherwise, and from `cancelCb` with `'cancelled'` (import `SaveOutcome` from `scoreChangeState`).
82
+ - [X] T019 [P] [US2] Create `src/ui/components/dialogs/unsavedChanges.vue` modeled on `modalMessage.vue`: props `domId`, `headline`, `message` and three callbacks `saveCb`, `discardCb`, `cancelCb`; three buttons labelled "Save", "Don't save" and "Cancel"; classes consistent with the other modal dialogs.
83
+ - [X] T020 [US2] Create `src/ui/dialogs/unsavedChanges.ts` exporting `confirmReplaceScore(parameters: SuiDialogParams): Promise<boolean>`: return true immediately when `!parameters.view.scoreChanged.value`; otherwise mount `unsavedChanges.vue` through `InstallDialog` (with `replaceVueRoot(modalContainerId)`, as in `partInfo.ts`) and resolve per [data-model.md](./data-model.md): Don't save returns true, Cancel returns false, Save opens `SuiFileSaveDialog(parameters, onClosed)` and then follows `nextStepAfterSave(outcome)` (`load` returns true, `prompt` shows the prompt again, `abort` returns false). The save dialog must be started with a fresh `startPromise` so it waits for the prompt to close.
84
+ - [X] T021 [US2] In `src/ui/dialogs/fileDialogs.ts` `SuiFileUploadDialog`, split the commit: `commitCb` keeps reading and converting the file but stores the result in a local `pendingScore` instead of calling `changeScore`, catching conversion errors as it does now; pass an `afterCloseCb` to `InstallDialog` that, when `pendingScore` is set, awaits `confirmReplaceScore(parameters)` and only then calls `parameters.view.changeScore(pendingScore)`. Applies to Open and Import Midi, which share this dialog.
85
+ - [X] T022 [US2] In `src/ui/components/dialogs/library.vue`, replace the direct `props.view.loadRemoteScore(...)` in `confirmLoad` with a new prop callback (for example `selectedCb: (url: string) => void`) that reports the chosen URL. In `src/ui/dialogs/libraryVue.ts`, pass that callback in `appParams`, remember the URL, and pass an `afterCloseCb` to `InstallDialog` that, when a URL was selected, awaits `confirmReplaceScore(parameters)` and only then calls `parameters.view.loadRemoteScore(url)`.
86
+ - [X] T023 [US2] In `src/ui/menus/file.ts`, change the New handler to `if (await confirmReplaceScore({ ...dialog params from menu, startPromise: menu.closePromise })) { await menu.view.changeScore(score); }`, building the parameters object the same way the other handlers in the file do.
87
+ - [X] T024 [US2] Run `npx tsc --noEmit -p tsconfig.json` and fix any errors.
88
+ - [ ] T025 [US2] Manual validation: quickstart.md section 4, steps 9 to 14 (U10 to U17), including Cancel, Don't save, Save in Smoosic format, Save then MusicXML (prompt returns), and cancelling the Open dialog (no prompt).
89
+
90
+ **Checkpoint**: Users cannot lose a changed score through New, Open, Import or the Library without being asked.
91
+
92
+ ---
93
+
94
+ ## Phase 5: User Story 3 - Fresh start for each new or loaded score (Priority: P2)
95
+
96
+ **Goal**: Each created or loaded score starts as saved and shows its own name.
97
+
98
+ **Independent Test**: Make an edit, choose Don't save while loading another score, and confirm the new score shows its own name and no asterisk, for New, Open, Import and Library; confirm initial startup shows no asterisk.
99
+
100
+ ### Implementation for User Story 3
101
+
102
+ - [X] T026 [US3] Confirm `src/application/application.ts` and `src/application/generateVexTests.ts` need no change: the first score is passed to the `SuiScoreViewOperations` constructor (flag starts false, name read from the score, per T008) and later loads use `changeScore` (per T009). If a code path sets `view.score` or `storeScore` directly outside `changeScore`, route it through `changeScore` or call `markScoreSaved()` and `refreshScoreName()` there. Record the result in the PR description.
103
+ - [ ] T027 [US3] Manual validation: after an edit, load each of New, Open, Import and Library with Don't save, and confirm the header shows the new score's name with no asterisk each time; reload the page and confirm the first score shows no asterisk (U1, U10).
104
+
105
+ **Checkpoint**: The state never carries over from one score to the next.
106
+
107
+ ---
108
+
109
+ ## Phase 6: Polish & Cross-Cutting Concerns
110
+
111
+ - [X] T028 Run `npm run test:score-change-state` and the five existing tests (`test:page-divisions`, `test:global-layout-reposition`, `test:text-drag-placement`, `test:attached-text`, `test:rehearsal-measure-number`) and confirm all pass.
112
+ - [X] T029 Run `npm run build` and confirm it succeeds.
113
+ - [ ] T030 Run through all of quickstart.md (sections 1 to 4) and note the result.
114
+
115
+ ---
116
+
117
+ ## Dependencies & Execution Order
118
+
119
+ ### Phase Dependencies
120
+
121
+ - **Setup (Phase 1)**: none.
122
+ - **Foundational (Phase 2)**: depends on Setup. T003, T004, T005 and T006 are independent; T007 needs all four; T008 and T009 edit `scoreView.ts` and run in order after T003 and T004.
123
+ - **US1 (Phase 3)**: depends on Phase 2.
124
+ - **US2 (Phase 4)**: depends on Phase 2 and on T010 and T012 (`recordSave` and the dialog's commit), since the prompt loop relies on the save outcome.
125
+ - **US3 (Phase 5)**: depends on Phase 2 (verification only).
126
+ - **Polish (Phase 6)**: depends on all stories.
127
+
128
+ ### Within Each Story
129
+
130
+ - `fileDialogs.ts` is edited by T012, T018 and T021: do them in that order.
131
+ - `scoreViewOperations.ts` is edited by T010 and T011 in order.
132
+ - T017 precedes T021 and T022 (they use `afterCloseCb`); T019 precedes T020.
133
+
134
+ ### Parallel Opportunities
135
+
136
+ - T003, T004, T005, T006 (four different files).
137
+ - T019 (new Vue file) can be written while T017 and T018 are in progress.
138
+ - T013 (`sidebar.vue` and CSS) can proceed in parallel with T010 to T012 once T008 is done.
139
+
140
+ ---
141
+
142
+ ## Parallel Example: Foundational phase
143
+
144
+ ```text
145
+ Task: "Add onAddBuffer to UndoBuffer in src/smo/xform/undo.ts" (T003)
146
+ Task: "Create src/render/sui/scoreChangeState.ts" (T004)
147
+ Task: "Add cases S1-S4 to tests/scoreChangeState.ts" (T005)
148
+ Task: "Add cases S5-S14 to tests/scoreChangeState.ts" (T006)
149
+ ```
150
+
151
+ ---
152
+
153
+ ## Implementation Strategy
154
+
155
+ ### MVP First (User Story 1 only)
156
+
157
+ 1. Phases 1 and 2 (hook, policy, state; tests pass).
158
+ 2. Phase 3: header, `recordSave`, Quick Save, dialog commit, sidebar props.
159
+ 3. Stop and validate: the asterisk appears on edits and clears only on a full-format save.
160
+
161
+ ### Incremental Delivery
162
+
163
+ 1. MVP gives visibility of unsaved changes.
164
+ 2. US2 adds the prompt so work cannot be lost by replacing the score.
165
+ 3. US3 confirms fresh state on every load.
166
+
167
+ ---
168
+
169
+ ## Notes
170
+
171
+ - The single `onAddBuffer` hook replaces the ten separate `addBuffer` sites the original idea would have needed (research.md section 1).
172
+ - Legacy `src/ui/dialogs/library.ts` is not reachable from the ribbon and is left unchanged.
173
+ - Commit after each phase.
@@ -0,0 +1,39 @@
1
+ # Specification Quality Checklist: Replace Promise Helpers with Native Async
2
+
3
+ **Purpose**: Validate specification completeness and quality before proceeding to planning
4
+
5
+ **Created**: 2026-10-14
6
+
7
+ **Feature**: [spec.md](../spec.md)
8
+
9
+ ## Content Quality
10
+
11
+ - [x] No implementation details (languages, frameworks, APIs)
12
+ - [x] Focused on user value and business needs
13
+ - [x] Written for non-technical stakeholders
14
+ - [x] All mandatory sections completed
15
+
16
+ ## Requirement Completeness
17
+
18
+ - [x] No [NEEDS CLARIFICATION] markers remain
19
+ - [x] Requirements are testable and unambiguous
20
+ - [x] Success criteria are measurable
21
+ - [x] Success criteria are technology-agnostic (no implementation details)
22
+ - [x] All acceptance scenarios are defined
23
+ - [x] Edge cases are identified
24
+ - [x] Scope is clearly bounded
25
+ - [x] Dependencies and assumptions identified
26
+
27
+ ## Feature Readiness
28
+
29
+ - [x] All functional requirements have clear acceptance criteria
30
+ - [x] User scenarios cover primary flows
31
+ - [x] Feature meets measurable outcomes defined in Success Criteria
32
+ - [x] No implementation details leak into specification
33
+
34
+ ## Notes
35
+
36
+ - This is an internal code-health change, so the "users" are maintainers of the code and authors of external applications built on the library. The spec describes outcomes (no uses of the legacy helpers, same behavior, same public exports) and avoids naming individual files or functions beyond the helper class the request names.
37
+ - Interpretation of the request: "replaced with a normal async function call" for the polling helper is taken to mean the same wait, written as ordinary asynchronous code in the one place the application uses it (FR-005). The wait still has to poll a render-state condition; it is not replaced by a direct await of the render step. If a different restructuring was intended, run `/speckit-clarify`.
38
+ - The helper's one-timer-tick delay versus an immediate return is called out as an edge case and an assumption, to be checked per call site in planning.
39
+ - Ready for `/speckit-clarify` or `/speckit-plan`.
@@ -0,0 +1,32 @@
1
+ # Contract: Public API and Helper Usage
2
+
3
+ Verified by `tests/promiseHelpersUsage.ts` (`npm run test:promise-helpers`) for cases P1 to P9, and by the type check, build and manual pass for cases T1 to T4. Spec references: [spec.md](../spec.md).
4
+
5
+ ## What must not change
6
+
7
+ - `PromiseHelpers` and its methods (`makePromise`, `makePromiseObj`, `promiseChainThen`, `emptyPromise`), the helper types (`promiseFunction`, `promiseCondition`, `promiseInstance`, `PromiseParameters`) and `TEmptyPromise` remain in `src/common/promiseHelpers.ts` with unchanged behavior.
8
+ - `src/application/exports.ts` keeps `export * from '../common/promiseHelpers'` and the `PromiseHelpers` entry in its export object.
9
+ - Every method that returned `Promise<X>` before still returns `Promise<X>`. No declared result type changes.
10
+
11
+ ## Headless test cases
12
+
13
+ | ID | Case | Expected | Spec |
14
+ |----|------|----------|------|
15
+ | P1 | Scan every `.ts`, `.vue` and `.js` file under `src/` for `PromiseHelpers`, excluding `src/common/promiseHelpers.ts` and `src/application/exports.ts` | no matches | FR-001, FR-005, SC-001 |
16
+ | P2 | Scan the same files for `emptyPromise(` and `makePromise(` outside `src/common/promiseHelpers.ts` | no matches | FR-001, FR-005 |
17
+ | P3 | `src/application/exports.ts` still re-exports the module and lists `PromiseHelpers` | both present | FR-006, SC-003 |
18
+ | P4 | Import `PromiseHelpers` and check `typeof` each static method | all four are functions | FR-006 |
19
+ | P5 | `await PromiseHelpers.emptyPromise()` | resolves (value `undefined`) | FR-006 |
20
+ | P6 | `PromiseHelpers.makePromise` with a condition that becomes true on the 3rd poll, a pre-resolve method, and a poll method | resolves; pre-resolve called once; poll method called twice | FR-006 |
21
+ | P7 | `makePromise` with a condition that is already true | resolves after about one poll interval, pre-resolve called once, poll method never | FR-006 |
22
+ | P8 | `promiseChainThen` over two parameter sets | both end conditions are reached in order | FR-006 |
23
+ | P9 | `TEmptyPromise('x')` | resolves with `'x'` | FR-006 |
24
+
25
+ ## Verification by type check, build and manual pass
26
+
27
+ | ID | Case | Expected | Spec |
28
+ |----|------|----------|------|
29
+ | T1 | `npx tsc --noEmit -p tsconfig.json` | no errors | FR-007, FR-008 |
30
+ | T2 | `npm run build` | succeeds, no new warnings | FR-008 |
31
+ | T3 | The six existing headless scripts | all pass | FR-008 |
32
+ | T4 | Manual pass in quickstart.md | no visible difference | FR-009, SC-005 |
@@ -0,0 +1,45 @@
1
+ # Data Model: Replace Promise Helpers with Native Async
2
+
3
+ There is no data model change: no persisted or in-memory data structures are added or altered. This document inventories the code sites that change.
4
+
5
+ ## Call sites: `emptyPromise()` (19, in 13 files)
6
+
7
+ | # | File | Method | Currently async | Change |
8
+ |---|------|--------|-----------------|--------|
9
+ | 1 | `src/application/application.ts` | `createScore` (translate mode) | yes | `return null;` |
10
+ | 2 | `src/render/sui/scoreViewOperations.ts` | `removeLyric` | yes | `return;` |
11
+ | 3 | `src/render/sui/scoreViewOperations.ts` | `removeAnnotation` | yes | `return;` |
12
+ | 4 | `src/render/sui/scoreViewOperations.ts` | `toggleBeamDirection` | yes | `return;` |
13
+ | 5 | `src/render/sui/scoreViewOperations.ts` | `setPitch` | yes | `return;` |
14
+ | 6 | `src/render/sui/scoreViewOperations.ts` | `addOrUpdateStaffModifier` | yes | `return;` |
15
+ | 7 | `src/render/sui/scoreViewOperations.ts` | `deleteMeasure` | yes | `return;` |
16
+ | 8 | `src/render/sui/scoreViewOperations.ts` | `removeStaff` | yes | `return;` |
17
+ | 9 | `src/ui/dialogs/adapter.ts` | `SuiDialogAdapterBase.remove` | **no** | add `async`, `return;` |
18
+ | 10 | `src/ui/dialogs/audioSettings.ts` | `commit` | yes | empty body |
19
+ | 11 | `src/ui/dialogs/dialog.ts` | `SuiDialogBase.commit` | yes | `return;` (declared type stays `Promise<any>`) |
20
+ | 12 | `src/ui/dialogs/dynamics.ts` | `commit` | yes | empty body |
21
+ | 13 | `src/ui/dialogs/hairpin.ts` | `commit` | yes | empty body |
22
+ | 14 | `src/ui/dialogs/slur.ts` | `commit` | yes | empty body |
23
+ | 15 | `src/ui/dialogs/tempo.ts` | `commit` | yes | empty body |
24
+ | 16 | `src/ui/dialogs/textBracket.ts` | `commit` | yes | empty body |
25
+ | 17 | `src/ui/dialogs/tie.ts` | `commit` | yes | empty body |
26
+ | 18 | `src/ui/dialogs/volta.ts` | `commit` | yes | empty body |
27
+ | 19 | `src/ui/fileio/library.ts` | `SmoLibrary.load` (already loaded) | **no** | add `async`, `return;` |
28
+
29
+ ## Call site: `makePromise()` (1)
30
+
31
+ | File | Method | Change |
32
+ |------|--------|--------|
33
+ | `src/render/sui/renderState.ts` | `_renderStatePromise(condition)` | rewritten as `async`, polling with `delay2()` (see research.md section 4) |
34
+
35
+ ## Unused imports to remove (7)
36
+
37
+ `src/ui/dialogs/scoreId.ts`, `src/ui/dialogs/timeSignature.ts`, `src/ui/dialogs/keySignature.ts`, `src/ui/dialogs/fileDialogs.ts`, `src/ui/dialogs/customTuplets.ts`, `src/render/sui/textEdit.ts`, `src/render/audio/samples.ts`.
38
+
39
+ In addition, the `PromiseHelpers` import is removed from each file in the two tables above once its last call is gone, and the unused `SuiRenderState` import is removed from `src/common/promiseHelpers.ts`.
40
+
41
+ ## Unchanged
42
+
43
+ `src/common/promiseHelpers.ts` (class and exported types, apart from the one import), `src/application/exports.ts`.
44
+
45
+ The 22 files other than `promiseHelpers.ts` that mention the helper today are: `exports.ts`, the 13 files with `emptyPromise` calls (the first table), `renderState.ts` (the `makePromise` call), and the 7 files with unused imports.
@@ -0,0 +1,86 @@
1
+ # Implementation Plan: Replace Promise Helpers with Native Async
2
+
3
+ **Branch**: `029-remove-promise-helpers` | **Date**: 2026-10-14 | **Spec**: [spec.md](./spec.md)
4
+
5
+ **Input**: Feature specification from `/specs/029-remove-promise-helpers/spec.md`
6
+
7
+ ## Summary
8
+
9
+ The application calls `PromiseHelpers.emptyPromise()` in 19 places and `PromiseHelpers.makePromise()` in one. All 19 `emptyPromise` sites are in methods that either are already `async` or only need to be, so each becomes a plain `return` (the declared result type does not change). The single `makePromise` call, `SuiRenderState._renderStatePromise`, is rewritten as an `async` method that reuses the renderer's existing `delay2()` timer and a `do ... while (!condition())` loop, with identical timing (it waits one poll interval before the first check, as the helper did). A direct `await` of the render step is not possible, because the renderer advances its state from an independent background loop (`pollRedrawTask`), so the wait stays a poll. Seven other files only carry an unused `PromiseHelpers` import, which is removed. The `PromiseHelpers` class stays in `src/common/promiseHelpers.ts` and in the public exports. A small headless script guards both halves of the contract: nothing in the application uses the helper, and the exported class still behaves as before.
10
+
11
+ ## Technical Context
12
+
13
+ **Language/Version**: TypeScript (built by `build/build.js`).
14
+
15
+ **Primary Dependencies**: None added or removed. `renderState.ts` already has `delay2`.
16
+
17
+ **Storage**: N/A.
18
+
19
+ **Testing**: Type check (`tsc --noEmit`), the full webpack build, the six existing headless scripts, and one new headless script `tests/promiseHelpersUsage.ts` (`npm run test:promise-helpers`) that (a) scans `src/` for any use of the helper outside its own file and the export file, and (b) exercises the retained class (`emptyPromise`, `makePromise`, `promiseChainThen`) and checks it is still re-exported. Dialog and render behavior has no automated coverage in this repository, so it is verified by a manual pass (quickstart.md).
20
+
21
+ **Target Platform**: Browser application; headless tests under Node.
22
+
23
+ **Project Type**: Single project (library + application).
24
+
25
+ **Performance Goals**: No regression. Replacing a 1 ms timer with an immediate return only makes completion earlier. The render wait keeps its `demonPollTime` interval.
26
+
27
+ **Constraints**: Public API unchanged (declared result types, exports). `PromiseHelpers` remains exported from `src/application/exports.ts`. The render-state wait must not block the page and must restore `suspendRendering` after it ends.
28
+
29
+ **Scale/Scope**: 20 call sites in 14 files, plus 7 unused imports in 7 files, plus the new test. Mechanical edits.
30
+
31
+ ## Constitution Check
32
+
33
+ *GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.*
34
+
35
+ - **Principle #1 (Serialization)**: PASS. No data model or file format is touched.
36
+ - **Principle #2 (Non-UI logic regression testing)**: PASS. This is not music logic. The retained helper class and the "no application use" invariant get a headless regression script anyway.
37
+ - **Principle #3 (Rendering performance)**: PASS, with one watch item. The render-state wait keeps the same poll interval and conditions, and adds no DOM measurement or repaint. `async`/`await` with `delay2` does not change how often the flags are read.
38
+ - **Principle #4 (Logical dependencies)**: PASS. No new imports between layers. The unused import in `promiseHelpers.ts` that points a generic utility at the renderer (`SuiRenderState`) is removed, which improves the layering.
39
+ - **Async use (core principles)**: "We try to avoid race conditions by judicious use of async/await". This change moves toward that, and each call site is checked for dependence on the old extra timer tick (see research.md section 3).
40
+
41
+ No violations; Complexity Tracking is not needed. Re-check after Phase 1: unchanged, still PASS.
42
+
43
+ ## Project Structure
44
+
45
+ ### Documentation (this feature)
46
+
47
+ ```text
48
+ specs/029-remove-promise-helpers/
49
+ ├── plan.md
50
+ ├── research.md
51
+ ├── data-model.md # inventory of the 20 call sites and 7 unused imports
52
+ ├── quickstart.md
53
+ ├── contracts/
54
+ │ └── public-api-contract.md
55
+ ├── checklists/
56
+ │ └── requirements.md
57
+ └── tasks.md # created later by /speckit-tasks
58
+ ```
59
+
60
+ ### Source Code (repository root)
61
+
62
+ ```text
63
+ src/
64
+ ├── application/application.ts # createScore: return null (translate mode)
65
+ ├── common/promiseHelpers.ts # remove the unused SuiRenderState import; class otherwise unchanged
66
+ ├── render/sui/
67
+ │ ├── renderState.ts # _renderStatePromise -> async, uses delay2; drop import
68
+ │ └── scoreViewOperations.ts # 7 early returns -> plain return; drop import
69
+ └── ui/
70
+ ├── dialogs/ # adapter, audioSettings, dialog, dynamics, hairpin, slur, tempo,
71
+ │ # textBracket, tie, volta: commit()/remove() -> plain return; drop imports
72
+ └── fileio/library.ts # load() -> async, plain return; drop import
73
+ (unused imports only, removed: # dialogs/scoreId.ts, timeSignature.ts, keySignature.ts, fileDialogs.ts,
74
+ # customTuplets.ts; render/sui/textEdit.ts; render/audio/samples.ts)
75
+
76
+ tests/
77
+ └── promiseHelpersUsage.ts # NEW headless guard + retained-class checks
78
+
79
+ package.json # add "test:promise-helpers"
80
+ ```
81
+
82
+ **Structure Decision**: Mechanical edits in place; no new modules. The only new file is the test.
83
+
84
+ ## Complexity Tracking
85
+
86
+ *No Constitution Check violations; table not needed.*
@@ -0,0 +1,53 @@
1
+ # Quickstart: Validating the Promise Helper Removal
2
+
3
+ Contract cases are in [contracts/public-api-contract.md](./contracts/public-api-contract.md); the list of changed sites is in [data-model.md](./data-model.md).
4
+
5
+ ## 1. Headless guard and retained-class test
6
+
7
+ ```bash
8
+ npm run test:promise-helpers
9
+ ```
10
+
11
+ Expected: every case prints `PASS` and the run ends with `all checks passed`. Before the edits are made, cases P1 and P2 fail and name the files that still use the helper, which is how to confirm the guard works.
12
+
13
+ ## 2. Type check and build
14
+
15
+ ```bash
16
+ npx tsc --noEmit -p tsconfig.json
17
+ npm run build
18
+ ```
19
+
20
+ Expected: no errors and no new warnings.
21
+
22
+ ## 3. Existing tests still pass
23
+
24
+ ```bash
25
+ npm run test:score-change-state
26
+ npm run test:page-divisions
27
+ npm run test:global-layout-reposition
28
+ npm run test:text-drag-placement
29
+ npm run test:attached-text
30
+ npm run test:rehearsal-measure-number
31
+ ```
32
+
33
+ ## 4. Manual pass in the app
34
+
35
+ Prerequisite: build and open the app. Keep the browser console open and watch for errors throughout.
36
+
37
+ **Rendering waits**
38
+ 1. Open the app: the score appears with no console errors.
39
+ 2. Add notes, delete a measure (Measure menu), remove an instrument when more than one exists, and undo: each completes and the score redraws correctly.
40
+ 3. Change the layout in the Score Layout dialog and apply: pages re-render and nothing flickers.
41
+ 4. File > New, File > Open a score file, and load a score from the Music Library: each loads and displays.
42
+
43
+ **Dialogs that changed (commit and remove paths)**
44
+ 5. Open and OK each of: tempo, slur, hairpin, dynamics, tie, volta (ending), text bracket, and audio settings. Each applies and closes.
45
+ 6. Cancel and Remove from those dialogs that offer them (hairpin, text bracket, slur): each behaves as before.
46
+
47
+ **Edits that exit early**
48
+ 7. With nothing selected, trigger beam direction toggle: no error and no change.
49
+ 8. With a single-measure score, use Delete Measure; with a single instrument, use Remove Instrument: nothing is deleted and nothing throws.
50
+ 9. Use Remove Lyric and Remove Annotation on a note that has none: no error.
51
+
52
+ **Startup**
53
+ 10. Reload the page: the score from the previous session (or the default score) loads as before.
@@ -0,0 +1,71 @@
1
+ # Research: Replace Promise Helpers with Native Async
2
+
3
+ No NEEDS CLARIFICATION items remained after the spec. The findings below come from reading the code.
4
+
5
+ ## 1. Inventory of uses
6
+
7
+ **Finding**: A search of `src/` for `PromiseHelpers` finds:
8
+
9
+ - 19 calls to `emptyPromise()`: `application.ts` (1), `scoreViewOperations.ts` (7), `ui/dialogs/adapter.ts`, `audioSettings.ts`, `dialog.ts`, `dynamics.ts`, `hairpin.ts`, `slur.ts`, `tempo.ts`, `textBracket.ts`, `tie.ts`, `volta.ts` (1 each), and `ui/fileio/library.ts` (1).
10
+ - 1 call to `makePromise()`: `renderState.ts` (`_renderStatePromise`).
11
+ - 0 calls to `promiseChainThen`, `makePromiseObj` or `TEmptyPromise`.
12
+ - 7 files that import the class and never use it: `ui/dialogs/scoreId.ts`, `timeSignature.ts`, `keySignature.ts`, `fileDialogs.ts`, `customTuplets.ts`, `render/sui/textEdit.ts`, `render/audio/samples.ts`.
13
+ - `application/exports.ts` imports it and re-exports the whole module (`export * from '../common/promiseHelpers'`) and lists it in the export object. This is the public surface for external applications.
14
+
15
+ **Decision**: Edit the 20 call sites and the 7 unused imports; leave `exports.ts` untouched.
16
+
17
+ ## 2. What the replaced value was
18
+
19
+ **Finding**: `emptyPromise()` resolves with `undefined` after `setTimeout(..., 1)`. Of the 19 sites, 18 are in methods declared `Promise<void>`, `Promise<any>` or with an inferred promise type where the value is ignored; one, `application.ts createScore(): Promise<SmoScore | null>`, returns it in translate mode. The only caller of `createScore` is `application.ts:186` (`await this.createScore();`), which ignores the value and reads `this.score` instead.
20
+
21
+ **Decision**: A bare `return;` for the `void`/`any` methods. For `createScore` use `return null;`, matching its declared type (`SmoScore | null`); `undefined` was never a valid value of that type, and no caller reads it.
22
+
23
+ ## 3. The extra timer tick
24
+
25
+ **Finding**: `emptyPromise` resolves on a timer, so an `await` on it yields to the event loop (a macrotask); a plain `return` from an `async` function resolves in a microtask. Behavior differs only if a caller depends on the event loop turning (for example, for the browser to repaint) between the call and its continuation. Checked:
26
+
27
+ - All 7 `scoreViewOperations.ts` sites are early exits that return before doing any rendering work, so nothing on screen has changed that would need a repaint before the caller continues. Their callers are menu, key and dialog handlers that do not await the result, or await it only to sequence later operations, which an earlier resolution does not affect.
28
+ - `commit()` / `remove()` on the dialog classes: no call sites exist in `src/` outside the class definitions and `InstallDialog`-style callbacks that do not await them. They are legacy adapter methods.
29
+ - `library.ts load()`: awaited by `libraryVue.ts` and `library.vue` (`loadChildrenIfNeeded`), which only continue to read `children`; an immediate resolve is correct when already loaded.
30
+ - `createScore`: value ignored; see section 2.
31
+
32
+ **Decision**: No call site needs the extra tick. Nothing is replaced by an explicit delay. The manual pass in quickstart.md still exercises each dialog once.
33
+
34
+ ## 4. Why the render-state wait stays a poll
35
+
36
+ **Finding**: `SuiRenderState._renderStatePromise(condition)` lets a caller wait until `renderStateClean` or `renderStateRendered` is true. Those flags are changed by `handleRedrawTimer`, which runs in a background loop (`pollRedrawTask`: `handleRedrawTimer`, then `delay2`, repeated forever, started by `startDemon`). There is no promise for "this render finished" to await; callers only share the flags. `makePromise` is therefore a poll: wait `pollTime`, test the condition, restore, resolve.
37
+
38
+ **Decision**: Keep the poll but write it as ordinary async code using the renderer's existing `delay2()` (a timer of `demonPollTime`, the same interval `makePromise` was given):
39
+
40
+ ```ts
41
+ async _renderStatePromise(condition: () => boolean): Promise<void> {
42
+ const oldSuspend = this.suspendRendering;
43
+ this.suspendRendering = false;
44
+ do {
45
+ await this.delay2();
46
+ } while (!condition());
47
+ this.suspendRendering = oldSuspend;
48
+ }
49
+ ```
50
+
51
+ This matches the helper exactly: `makePromise` always waited one poll interval before the first test, ran `endAction` (restoring `suspendRendering`) before resolving, and passed no per-poll action (`pollMethod` was `null`). The page is never blocked, because each wait is an awaited timer.
52
+
53
+ **Alternatives considered**: Restructuring the redraw loop so that a render completion resolves a stored promise. Rejected: larger change to the performance-critical render pipeline (constitution Principle #3), and the spec scopes this to the way the wait is written. Using a `while (!condition()) await delay2()` loop that tests first: rejected because it would resolve with no delay if the state is already reached, which the existing callers (like `updatePromise`) have relied on to let the demon loop run once.
54
+
55
+ ## 5. `library.ts load()` is not `async`
56
+
57
+ **Finding**: `SmoLibrary.load()` returns either `emptyPromise()` or `new Promise<void>(...)` that wraps an XHR. It is not declared `async`.
58
+
59
+ **Decision**: Declare it `async`, use a bare `return;` for the already-loaded case, and keep the `return new Promise<void>(...)` for the XHR (an `async` function may return a promise). The XHR body is not otherwise in scope.
60
+
61
+ ## 6. The retained helper class
62
+
63
+ **Finding**: `src/common/promiseHelpers.ts` imports `SuiRenderState` from the renderer but never uses it. It is exported to external applications.
64
+
65
+ **Decision**: Keep the class and all its exports unchanged. Remove only the unused `SuiRenderState` import, which creates a generic-utility to renderer dependency (and would drag the renderer into a headless test). Add a note to the class's documentation that the application no longer uses it and that it is retained for external users.
66
+
67
+ **Alternatives considered**: Marking the methods `@deprecated`. Rejected for now: the request is to keep the class for external applications, and a deprecation tag would add warnings for them. Can be revisited.
68
+
69
+ ## 7. Guarding the result
70
+
71
+ **Decision**: Add `tests/promiseHelpersUsage.ts`. It reads every `.ts`, `.vue` and `.js` file under `src/` and fails if `PromiseHelpers` appears in any file other than `src/common/promiseHelpers.ts` and `src/application/exports.ts`. It also imports the class and runs `emptyPromise`, `makePromise` (a condition that becomes true after a few polls) and `promiseChainThen`, and checks that the export module still re-exports it. This makes SC-001 and SC-003 repeatable instead of a one-time search.
@@ -0,0 +1,107 @@
1
+ # Feature Specification: Replace Promise Helpers with Native Async
2
+
3
+ **Feature Branch**: `029-remove-promise-helpers`
4
+
5
+ **Created**: 2026-10-14
6
+
7
+ **Status**: Draft
8
+
9
+ **Input**: User description: "PromiseHelpers class was created before async was available. Many classes that could be async in the application are not but return Promise<>. Remove calls to PromiseHelpers.emptyPromise and just replace it with return, changing the signature to async if it's not already. Once all the signatures are updated, there should not be the need for PromiseHelpers.makePromise either, it can be replaced with just a normal async function call. Keep the PromiseHelpers class for external applications that might use it."
10
+
11
+ ## User Scenarios & Testing *(mandatory)*
12
+
13
+ ### User Story 1 - Application code no longer builds placeholder promises by hand (Priority: P1)
14
+
15
+ A maintainer reading the application code finds that methods which have nothing to wait for are ordinary asynchronous functions that simply return. They no longer call a helper that creates a timer just to produce an empty, already-finished promise. Every such method still hands its callers something they can wait on, exactly as before.
16
+
17
+ **Why this priority**: This is the core cleanup. It removes the legacy pattern from roughly twenty places across the dialogs, the view operations, the render state and the application startup, and makes the code match the language features the project already uses elsewhere.
18
+
19
+ **Independent Test**: Search the application source for the empty-promise helper. No calls remain. Then run the app and the existing test scripts, and confirm that the dialogs, menus and score operations that used to return the helper's promise still work and can still be waited on.
20
+
21
+ **Acceptance Scenarios**:
22
+
23
+ 1. **Given** a method that returned the empty-promise helper's result, **When** the cleanup is done, **Then** the method is an ordinary asynchronous function that returns without the helper, and callers that wait on it still work.
24
+ 2. **Given** a method that already was an asynchronous function and returned the helper, **When** the cleanup is done, **Then** it simply returns, and its declared result type is unchanged.
25
+ 3. **Given** a method that was not asynchronous but returned a promise from the helper, **When** the cleanup is done, **Then** it is declared asynchronous so it still returns a promise to every caller.
26
+ 4. **Given** an abstract method or interface that declares a promise result and is implemented by several classes, **When** the cleanup is done, **Then** every implementation and every caller keeps working, with no change to the declared result type.
27
+ 5. **Given** a caller that waits on one of the changed methods, **When** it runs after the cleanup, **Then** it observes the same sequence of events as before (the method has finished its work before the caller continues).
28
+
29
+ ---
30
+
31
+ ### User Story 2 - Polling for render state needs no helper class (Priority: P2)
32
+
33
+ The code that waits for the score to reach a rendered state no longer depends on the polling helper. It is written as ordinary asynchronous code in the place where it is used, and behaves the same for callers: they wait until the score is in the required state and the rendering-suspension setting is restored.
34
+
35
+ **Why this priority**: It removes the remaining use of the polling helper in the application, so the helper class is no longer used by the application at all. It is lower priority than Story 1 because it is a single, higher-risk spot where the rendering timing matters most.
36
+
37
+ **Independent Test**: After the change, open and edit a score, load a new score, undo, change layouts, and check that every operation that waits for rendering still completes and the score displays correctly with no extra delay or flicker.
38
+
39
+ **Acceptance Scenarios**:
40
+
41
+ 1. **Given** an operation that waits for the score to be fully rendered, **When** rendering completes, **Then** the waiting code continues, and the rendering-suspension setting is restored to what it was before the wait.
42
+ 2. **Given** an operation that waits for the rendered state while rendering is slow, **When** the wait is in progress, **Then** the application stays responsive (the wait does not block the page) and the wait does not end early.
43
+ 3. **Given** the cleanup is complete, **When** the application source is searched, **Then** no code in the application uses the polling helper.
44
+
45
+ ---
46
+
47
+ ### User Story 3 - External applications that use the helper keep working (Priority: P1)
48
+
49
+ An application built on the Smoosic library that calls the promise helper class directly (for example, to create a delayed empty promise or to poll for a condition) continues to work with no change. The class and all its methods remain available from the library's public exports with the same behavior.
50
+
51
+ **Why this priority**: The request explicitly requires it, and a break here would affect users outside this repository who cannot be updated together with the library.
52
+
53
+ **Independent Test**: Confirm that the helper class and each of its methods are still exported from the library entry point, and that a small external script calling them still gets the same results as before.
54
+
55
+ **Acceptance Scenarios**:
56
+
57
+ 1. **Given** an external application imports the helper class from the library, **When** it calls any of its methods, **Then** each method behaves as before the change.
58
+ 2. **Given** the library's public exports, **When** they are compared before and after the change, **Then** the helper class and its related types are still exported, and no other public export has been removed or has changed its declared result type.
59
+
60
+ ---
61
+
62
+ ### Edge Cases
63
+
64
+ - What happens when a changed method's caller relied on the small delay the helper added before finishing? The helper finished on a later timer tick; a plain return finishes sooner. Each affected call site must be checked for callers that depended on that extra tick (for example, a screen update that needed to happen between two steps). Any such caller must keep its ordering.
65
+ - What happens when a method is only declared to return a promise because an abstract base class or interface requires it? It becomes an asynchronous function with an empty body or a plain return, and the base class's declared type does not change.
66
+ - What happens when a changed method is called without waiting on it, as a fire-and-forget call? It must still run to completion and must not cause an unhandled failure that did not occur before.
67
+ - What happens when a method throws or fails while it is now asynchronous? The failure is reported to the caller as a rejected promise, not as an immediate thrown error. Call sites that depended on an immediate throw from a formerly non-asynchronous method must be identified and handled.
68
+ - What happens with tests or documentation that mention the helper? Mentions of the helper's use inside application code are removed; the helper's own documentation stays.
69
+
70
+ ## Requirements *(mandatory)*
71
+
72
+ ### Functional Requirements
73
+
74
+ - **FR-001**: The application source MUST NOT call the empty-promise helper. Each place that did MUST return normally from an asynchronous function instead.
75
+ - **FR-002**: A method that returned the empty-promise helper's result and was not asynchronous MUST be changed to an asynchronous function, so that callers still receive a promise and the declared result type is unchanged.
76
+ - **FR-003**: A method that was already asynchronous MUST simply return, and abstract or interface methods that declare a promise result MUST keep that declared type.
77
+ - **FR-004**: All callers of the changed methods MUST continue to work and to wait for completion as before; any caller that depended on the helper's extra timer tick or on an immediate (non-promise) failure MUST be found and kept correct.
78
+ - **FR-005**: The application source MUST NOT use the polling helper. The wait for the score to reach a required render state MUST be implemented as ordinary asynchronous code with the same behavior: it ends only when the required state is reached, restores the rendering-suspension setting to its earlier value when it ends, and does not block the page while waiting.
79
+ - **FR-006**: The promise helper class, with all its methods and related types, MUST remain in the library and remain available from its public exports, with unchanged behavior, for use by external applications.
80
+ - **FR-007**: No other public method of the library MUST change its declared result type, parameters or meaning as a result of this change.
81
+ - **FR-008**: Existing automated tests MUST continue to pass, and the application MUST build without new errors or warnings.
82
+ - **FR-009**: The score editing, dialog, menu, undo and loading behavior visible to users MUST be unchanged.
83
+
84
+ ### Key Entities
85
+
86
+ - **Promise helper class**: A legacy utility, exported for outside users, that creates empty delayed promises and polling promises. It stays in the library but is no longer used by the application itself.
87
+ - **Changed method**: Any method in the application that returned a promise only because it called the helper, and so becomes a plain asynchronous function.
88
+ - **Render-state wait**: The part of the application that lets an operation wait until the score is rendered, restoring the rendering-suspension setting afterwards.
89
+
90
+ ## Success Criteria *(mandatory)*
91
+
92
+ ### Measurable Outcomes
93
+
94
+ - **SC-001**: A search of the application source finds 0 uses of the empty-promise helper and 0 uses of the polling helper, outside the helper class's own file and its public export.
95
+ - **SC-002**: 100% of the previously helper-returning methods still return something their callers can wait on, with the same declared result type.
96
+ - **SC-003**: The helper class and each of its methods remain available from the library's public exports, with no removed or changed export.
97
+ - **SC-004**: All existing automated test scripts pass, and the application builds with no new errors or warnings.
98
+ - **SC-005**: In a manual pass through opening, editing, undoing, loading a score, changing layout and using each dialog and menu, there is no visible difference from before: no new delay, flicker, ordering problem, or console error.
99
+
100
+ ## Assumptions
101
+
102
+ - The helper's one-timer-tick delay is an implementation detail, not a feature. The planning phase checks each call site and keeps a deliberate delay only where a caller really depends on it.
103
+ - Calls that the helper's author wrote only to satisfy a promise return type (the large majority) become plain returns from asynchronous functions.
104
+ - The helper class stays in its current place in the library and in the public exports, unchanged, even though the application no longer uses it. It may be marked as retained for outside users in its documentation.
105
+ - Application code that waits on the render state keeps the same waiting interval and conditions as today; only the way the wait is written changes.
106
+ - The unused delayed-value helper and the chained-promise helper in the same file are also kept for external users; they have no application callers today.
107
+ - Tests already in the repository cover the data layer rather than these dialogs and render paths, so confidence in the UI-facing changes comes from type checking, the build, and the manual pass in the quickstart.