@lemonriver/core 1.1.0 → 1.3.0

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 (98) hide show
  1. package/dist/{build-Dm7gVRhb.js → build-CSkdswfd.js} +1 -1
  2. package/dist/cli/bin.js +5 -5
  3. package/dist/{config-CubOIzrs.js → config-C5-myPY6.js} +129 -2
  4. package/dist/{dev-DgLeXPqp.js → dev-DHtYH8sw.js} +2 -2
  5. package/dist/{mcp-CjYDzcJa.js → mcp-B2UeO1un.js} +1 -1
  6. package/dist/{preview-CxXQpPk5.js → preview-C1B6-umF.js} +1 -1
  7. package/dist/{update-b1dSg_FW.js → update-DzL8fpcI.js} +1 -1
  8. package/dist/vite/index.js +1 -1
  9. package/package.json +5 -2
  10. package/release-notes.json +33 -0
  11. package/src/app/components/player.tsx +6 -1
  12. package/src/app/lemonriver/chrome/app-chrome.tsx +52 -0
  13. package/src/app/lemonriver/chrome/sidebar-extras.tsx +8 -1
  14. package/src/app/lemonriver/feedback/dialog.tsx +222 -0
  15. package/src/app/lemonriver/feedback/export.ts +21 -2
  16. package/src/app/lemonriver/feedback/first-success.ts +30 -0
  17. package/src/app/lemonriver/feedback/install.ts +18 -0
  18. package/src/app/lemonriver/feedback/model.ts +88 -0
  19. package/src/app/lemonriver/help/help-page.tsx +16 -1
  20. package/src/app/lemonriver/links.ts +16 -0
  21. package/src/app/lemonriver/present/dual-screen.ts +154 -0
  22. package/src/app/lemonriver/present/presenter-blocked-hint.tsx +28 -0
  23. package/src/app/lemonriver/present/wake-lock.ts +74 -0
  24. package/src/app/lemonriver/settings/backup-section.tsx +13 -0
  25. package/src/app/lemonriver/settings/settings-page.tsx +20 -0
  26. package/src/app/lemonriver/share/editor-share.tsx +6 -3
  27. package/src/app/lemonriver/share/share-dialog.tsx +2 -0
  28. package/src/app/lemonriver/text/en.ts +48 -0
  29. package/src/app/lemonriver/text/es.ts +45 -0
  30. package/src/app/lemonriver/text/ja.ts +44 -0
  31. package/src/app/lemonriver/text/types.ts +48 -0
  32. package/src/app/lemonriver/text/zh-cn.ts +48 -0
  33. package/src/app/lemonriver/text/zh-tw.ts +48 -0
  34. package/src/app/lemonriver/theme/pages.ts +4 -0
  35. package/src/app/lemonriver/update/release-notes.ts +22 -0
  36. package/src/app/lemonriver/update/update-prompt.tsx +28 -4
  37. package/src/app/routes/presenter.tsx +2 -0
  38. package/src/app/routes/slide.tsx +14 -1
  39. package/src/app/components/note-markdown.test.tsx +0 -42
  40. package/src/app/components/thumbnail-rail-scroll.test.ts +0 -60
  41. package/src/app/lemonriver/agent-prefs/prefs.test.ts +0 -173
  42. package/src/app/lemonriver/backup/guide.test.ts +0 -45
  43. package/src/app/lemonriver/backup/model.test.ts +0 -108
  44. package/src/app/lemonriver/backup/places.test.ts +0 -154
  45. package/src/app/lemonriver/board/blocks/classify.test.ts +0 -209
  46. package/src/app/lemonriver/board/layout.test.ts +0 -245
  47. package/src/app/lemonriver/board/model/agent-tasks.test.ts +0 -200
  48. package/src/app/lemonriver/board/model/apply-prompt.test.ts +0 -121
  49. package/src/app/lemonriver/board/model/cards.test.ts +0 -332
  50. package/src/app/lemonriver/board/model/changes.test.ts +0 -244
  51. package/src/app/lemonriver/board/model/filter.test.ts +0 -50
  52. package/src/app/lemonriver/board/model/history.test.ts +0 -71
  53. package/src/app/lemonriver/board/model/restructure.test.ts +0 -205
  54. package/src/app/lemonriver/board/model/self-check.test.ts +0 -329
  55. package/src/app/lemonriver/board/model/structure.test.ts +0 -350
  56. package/src/app/lemonriver/board/model/timing.test.ts +0 -113
  57. package/src/app/lemonriver/features.test.ts +0 -49
  58. package/src/app/lemonriver/feedback/pending-toast.test.ts +0 -44
  59. package/src/app/lemonriver/feedback/upload.test.ts +0 -26
  60. package/src/app/lemonriver/help/model.test.ts +0 -179
  61. package/src/app/lemonriver/home/brief.test.ts +0 -38
  62. package/src/app/lemonriver/home/drafts.test.ts +0 -23
  63. package/src/app/lemonriver/home/sorting.test.ts +0 -24
  64. package/src/app/lemonriver/home/time.test.ts +0 -33
  65. package/src/app/lemonriver/outline/files.test.ts +0 -90
  66. package/src/app/lemonriver/outline/model.test.ts +0 -751
  67. package/src/app/lemonriver/public-links.test.ts +0 -32
  68. package/src/app/lemonriver/routes.test.tsx +0 -54
  69. package/src/app/lemonriver/share/codes.test.ts +0 -49
  70. package/src/app/lemonriver/share/compare.test.ts +0 -199
  71. package/src/app/lemonriver/share/folder.test.ts +0 -42
  72. package/src/app/lemonriver/share/guide.test.ts +0 -78
  73. package/src/app/lemonriver/share/naming.test.ts +0 -70
  74. package/src/app/lemonriver/share/paths.test.ts +0 -116
  75. package/src/app/lemonriver/share/pdf.test.ts +0 -79
  76. package/src/app/lemonriver/templates/knobs.test.ts +0 -62
  77. package/src/app/lemonriver/templates/model.test.ts +0 -175
  78. package/src/app/lemonriver/templates/preview-content.test.ts +0 -117
  79. package/src/app/lemonriver/templates/recommend.test.ts +0 -71
  80. package/src/app/lemonriver/text/text.test.ts +0 -90
  81. package/src/app/lemonriver/theme/pages.test.ts +0 -74
  82. package/src/app/lemonriver/theme/themes.test.ts +0 -18
  83. package/src/app/lemonriver/trash/api.test.ts +0 -19
  84. package/src/app/lemonriver/update/prompt.test.ts +0 -84
  85. package/src/app/lemonriver/update/version.test.ts +0 -14
  86. package/src/app/lib/asset-filter.test.ts +0 -176
  87. package/src/app/lib/inspector/fiber.test.ts +0 -154
  88. package/src/app/lib/inspector/geometry.test.ts +0 -324
  89. package/src/app/lib/inspector/text-edit-timeline.test.ts +0 -121
  90. package/src/app/lib/note-markdown.test.ts +0 -147
  91. package/src/app/lib/pptx/css.test.ts +0 -205
  92. package/src/app/lib/pptx/ooxml.test.ts +0 -199
  93. package/src/app/lib/pptx/text-lines.test.ts +0 -82
  94. package/src/app/lib/print-ready.test.ts +0 -32
  95. package/src/app/lib/sdk.test.ts +0 -13
  96. package/src/app/lib/transition.test.ts +0 -31
  97. package/src/app/lib/use-document-title.test.ts +0 -14
  98. package/src/app/lib/utils.test.ts +0 -49
@@ -1,245 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import type { Page } from '../../lib/sdk';
3
- import {
4
- CARD_BOX_H,
5
- CARD_BOX_W,
6
- CARD_H,
7
- CARD_W,
8
- cardAtPoint,
9
- cardMetrics,
10
- gapAtPoint,
11
- layoutBoard,
12
- linkCurve,
13
- NOTE_H,
14
- orderAfterMove,
15
- orderAfterMoveMany,
16
- seedColumns,
17
- slotAtPoint,
18
- } from './layout';
19
-
20
- /** Pages are identified by their component name, so the fixtures need real names. */
21
- function named(name: string): Page {
22
- const page = () => null;
23
- Object.defineProperty(page, 'name', { value: name });
24
- return page as unknown as Page;
25
- }
26
-
27
- const title = (n: number) => `Part ${n}`;
28
- const sizes = (pages: Page[]) => seedColumns(pages, title).map((c) => c.size);
29
-
30
- describe('seedColumns', () => {
31
- it('starts a column at every chapter page', () => {
32
- const pages = ['Cover', 'Agenda', 'ChapterOne', 'Alpha', 'ChapterTwo', 'Beta'].map(named);
33
- expect(seedColumns(pages, title)).toEqual([
34
- { title: 'Cover', size: 2 },
35
- { title: 'Chapter One', size: 2 },
36
- { title: 'Chapter Two', size: 2 },
37
- ]);
38
- });
39
-
40
- it('ignores a chapter page in the first slot so the deck never opens with an empty column', () => {
41
- expect(sizes(['ChapterOne', 'Alpha', 'ChapterTwo'].map(named))).toEqual([2, 1]);
42
- });
43
-
44
- it('falls back to fixed-length columns when no page declares a chapter', () => {
45
- const pages = Array.from({ length: 14 }, (_, i) => named(`Page${i}`));
46
- expect(sizes(pages)).toEqual([6, 6, 2]);
47
- expect(seedColumns(pages, title).map((c) => c.title)).toEqual(['Part 1', 'Part 2', 'Part 3']);
48
- });
49
-
50
- it('reads the column title off the names real decks use', () => {
51
- const pages = [named('P1Cover'), named('PChapter1'), named('P16ScenarioTable')];
52
- expect(seedColumns(pages, title).map((c) => c.title)).toEqual(['Cover', 'Chapter 1']);
53
- });
54
-
55
- it('falls back to the positional title when the chapter page name carries no words', () => {
56
- const pages = [named('Cover'), named('章'), named('Alpha')];
57
- expect(seedColumns(pages, title)[1].title).toBe('Part 2');
58
- });
59
- });
60
-
61
- describe('layoutBoard', () => {
62
- const columns = [
63
- { title: 'Cover', size: 2 },
64
- { title: 'Chapter One', size: 3 },
65
- ];
66
-
67
- it('stacks a column top to bottom and puts the next column to the right', () => {
68
- const { slots } = layoutBoard(columns);
69
- expect(slots.map((s) => s.column)).toEqual([0, 0, 1, 1, 1]);
70
- expect(slots[0].x).toBe(slots[1].x);
71
- expect(slots[1].y).toBeGreaterThan(slots[0].y);
72
- expect(slots[2].x).toBeGreaterThan(slots[0].x);
73
- });
74
-
75
- it('numbers slots by deck position, so column two continues where column one ended', () => {
76
- expect(layoutBoard(columns).slots.map((s) => s.index)).toEqual([0, 1, 2, 3, 4]);
77
- });
78
-
79
- it('keeps a column that has been emptied, so its title survives', () => {
80
- const laid = layoutBoard([
81
- { title: 'Cover', size: 0 },
82
- { title: 'Chapter One', size: 2 },
83
- ]);
84
- expect(laid.columns.map((c) => c.size)).toEqual([0, 2]);
85
- expect(laid.slots).toHaveLength(2);
86
- expect(laid.slots[0].column).toBe(1);
87
- });
88
-
89
- it('keeps the card box in the slide aspect ratio', () => {
90
- expect(CARD_H).toBeCloseTo((CARD_W * 1080) / 1920);
91
- });
92
- });
93
-
94
- describe('slotAtPoint', () => {
95
- const layout = layoutBoard([
96
- { title: 'Cover', size: 2 },
97
- { title: 'Chapter One', size: 2 },
98
- ]);
99
-
100
- it('resolves a drop on top of a slot to that slot', () => {
101
- const target = layout.slots[2];
102
- expect(slotAtPoint(layout, target.x, target.y, 0)).toBe(2);
103
- });
104
-
105
- it('snaps a drop between two slots to the nearer one', () => {
106
- const [a, b] = [layout.slots[0], layout.slots[1]];
107
- expect(slotAtPoint(layout, a.x, a.y + (b.y - a.y) * 0.4, 3)).toBe(0);
108
- expect(slotAtPoint(layout, a.x, a.y + (b.y - a.y) * 0.6, 3)).toBe(1);
109
- });
110
-
111
- it('keeps a drop far outside the layout on the closest edge slot', () => {
112
- expect(slotAtPoint(layout, -5000, -5000, 3)).toBe(0);
113
- const last = layout.slots[layout.slots.length - 1];
114
- expect(slotAtPoint(layout, last.x + 5000, last.y + 5000, 0)).toBe(3);
115
- });
116
- });
117
-
118
- describe('orderAfterMove', () => {
119
- it('lifts the page out and drops it at the target position', () => {
120
- expect(orderAfterMove(5, 0, 3)).toEqual([1, 2, 3, 0, 4]);
121
- expect(orderAfterMove(5, 4, 1)).toEqual([0, 4, 1, 2, 3]);
122
- expect(orderAfterMove(5, 2, 2)).toEqual([0, 1, 2, 3, 4]);
123
- });
124
- });
125
-
126
- describe('cardAtPoint', () => {
127
- const layout = layoutBoard([
128
- { title: 'Cover', size: 2 },
129
- { title: 'Chapter One', size: 2 },
130
- ]);
131
-
132
- it('finds the card under a point anywhere inside it', () => {
133
- const slot = layout.slots[3];
134
- expect(cardAtPoint(layout, slot.x + CARD_BOX_W - 1, slot.y + CARD_BOX_H - 1)).toBe(3);
135
- });
136
-
137
- it('reports empty canvas between cards as no card', () => {
138
- const [a, b] = [layout.slots[0], layout.slots[1]];
139
- expect(cardAtPoint(layout, a.x + 10, (a.y + CARD_BOX_H + b.y) / 2)).toBeNull();
140
- expect(cardAtPoint(layout, a.x + CARD_BOX_W + 20, a.y + 10)).toBeNull();
141
- });
142
- });
143
-
144
- describe('linkCurve', () => {
145
- const box = (x: number, y: number) => ({ x, y, width: 100, height: 60 });
146
-
147
- it('bows a link between cards in one column out to the right of the column', () => {
148
- const curve = linkCurve(box(0, 0), box(0, 400));
149
- expect(curve.x).toBeGreaterThan(100);
150
- expect(curve.path.startsWith('M 100,18')).toBe(true);
151
- });
152
-
153
- it('never ends where the main line does, at the middle of a card side', () => {
154
- const curve = linkCurve(box(0, 0), box(300, 0));
155
- expect(curve.path).not.toContain(',30');
156
- });
157
-
158
- it('joins cards in different columns between their facing sides, whichever is first', () => {
159
- const forward = linkCurve(box(0, 0), box(300, 200));
160
- const backward = linkCurve(box(300, 200), box(0, 0));
161
- expect(forward.path).toBe(backward.path);
162
- expect(forward.path.startsWith('M 100,18')).toBe(true);
163
- expect(forward.path.endsWith('300,218')).toBe(true);
164
- });
165
- });
166
-
167
- describe('card sizes', () => {
168
- it('keeps the large card at the preview size it has always had', () => {
169
- expect(cardMetrics('large')).toMatchObject({ cardW: CARD_W, cardH: CARD_H, noteH: NOTE_H });
170
- });
171
-
172
- it('halves the preview at small, and drops the strips that need the room', () => {
173
- expect(cardMetrics('small').cardW).toBe(CARD_W / 2);
174
- expect(cardMetrics('small').cardH).toBeCloseTo(CARD_H / 2);
175
- expect(cardMetrics('small').memoH).toBe(0);
176
- });
177
-
178
- it('draws no preview at all when only the title is shown', () => {
179
- expect(cardMetrics('title').cardH).toBe(0);
180
- expect(cardMetrics('title').boxH).toBeLessThan(cardMetrics('small').boxH);
181
- });
182
-
183
- it('lays the same structure out with the metrics of the chosen size', () => {
184
- const columns = [{ title: 'A', size: 2 }];
185
- expect(layoutBoard(columns, { size: 'small' }).metrics.cardW).toBe(CARD_W / 2);
186
- expect(layoutBoard(columns).metrics.cardW).toBe(CARD_W);
187
- });
188
- });
189
-
190
- describe('folded chapters', () => {
191
- const columns = [
192
- { title: 'A', size: 2 },
193
- { title: 'B', size: 3 },
194
- ];
195
-
196
- it('draws no cards for a folded chapter but keeps its pages numbered', () => {
197
- const layout = layoutBoard(columns, { collapsed: [false, true] });
198
- expect(layout.slots.map((s) => s.index)).toEqual([0, 1]);
199
- expect(layout.columns[1].collapsed).toBe(true);
200
- });
201
-
202
- it('keeps the folded chapter label in place while its cards are gone', () => {
203
- const open = layoutBoard(columns);
204
- const folded = layoutBoard(columns, { collapsed: [true, false] });
205
- expect(folded.columns[0].x).toBe(open.columns[0].x);
206
- expect(folded.columns[0].size).toBe(2);
207
- expect(folded.slots.map((s) => s.index)).toEqual([2, 3, 4]);
208
- });
209
- });
210
-
211
- describe('gapAtPoint', () => {
212
- const layout = layoutBoard([
213
- { title: 'A', size: 2 },
214
- { title: 'B', size: 2 },
215
- ]);
216
-
217
- it('names the boundary a point between two chapters sits on', () => {
218
- const right = layout.columns[0].x + layout.columns[0].boxW;
219
- expect(gapAtPoint(layout, right + 10, 100)).toBe(1);
220
- });
221
-
222
- it('reports no boundary over a column or past the last one', () => {
223
- expect(gapAtPoint(layout, layout.columns[0].x + 20, 100)).toBeNull();
224
- expect(gapAtPoint(layout, layout.columns[1].x + 400, 100)).toBeNull();
225
- });
226
- });
227
-
228
- describe('orderAfterMoveMany', () => {
229
- it('carries the picked cards as one block, in deck order', () => {
230
- expect(orderAfterMoveMany(5, [3, 1], 0)).toEqual([1, 3, 0, 2, 4]);
231
- });
232
-
233
- it('lands the block on the slot it was dropped on', () => {
234
- expect(orderAfterMoveMany(6, [0, 1], 4)).toEqual([2, 3, 4, 5, 0, 1]);
235
- expect(orderAfterMoveMany(6, [4, 5], 1)).toEqual([0, 4, 5, 1, 2, 3]);
236
- // The same slot a single card takes, so "move to the end" still ends there.
237
- expect(orderAfterMoveMany(3, [0], 2)).toEqual(orderAfterMove(3, 0, 2));
238
- expect(orderAfterMoveMany(5, [4], 1)).toEqual(orderAfterMove(5, 4, 1));
239
- });
240
-
241
- it('keeps every page exactly once', () => {
242
- const order = orderAfterMoveMany(7, [2, 5, 6], 1);
243
- expect([...order].sort((a, b) => a - b)).toEqual([...Array(7).keys()]);
244
- });
245
- });
@@ -1,200 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import {
3
- chapterPlanPrompt,
4
- chapterWritePrompt,
5
- pageTaskPrompt,
6
- parseChapterBlock,
7
- sanitizeTask,
8
- stripChapterBlock,
9
- } from './agent-tasks.ts';
10
-
11
- const page = { n: 3, title: 'Revenue by quarter' };
12
-
13
- describe('pageTaskPrompt', () => {
14
- const prompt = (action: 'rewrite' | 'chart' | 'memo' | 'expand', memo?: string) =>
15
- pageTaskPrompt({ slideId: 'deck', page: { ...page, memo }, action, lang: 'en' });
16
-
17
- it('names only the page it works on', () => {
18
- expect(prompt('rewrite')).toContain(
19
- 'Work on page 3 "Revenue by quarter" of slides/deck/index.tsx only. Leave every other page, the theme and the speaker notes of other pages as they are.',
20
- );
21
- expect(prompt('rewrite')).toContain(
22
- 'Rewrite this page: keep what it says, make it clearer and better laid out.',
23
- );
24
- });
25
-
26
- it('asks for a chart that keeps the point', () => {
27
- expect(prompt('chart')).toContain(
28
- 'Turn the main numbers on this page into a chart. Keep the title and the point it makes.',
29
- );
30
- });
31
-
32
- it('follows the card note', () => {
33
- expect(prompt('memo', 'lead with the number')).toContain(
34
- 'Change this page as the note says: "lead with the number"',
35
- );
36
- });
37
-
38
- it('keeps a note’s quotes and newlines as one quoted string', () => {
39
- const memo = 'Say "first"\nthen stop';
40
- expect(prompt('memo', memo)).toContain(
41
- `Change this page as the note says: ${JSON.stringify(memo)}`,
42
- );
43
- });
44
-
45
- it('has nothing to say for a note action without a note', () => {
46
- expect(prompt('memo')).toBeNull();
47
- expect(prompt('memo', ' ')).toBeNull();
48
- });
49
-
50
- it('asks for a second page right after this one', () => {
51
- expect(prompt('expand')).toContain(
52
- 'Expand this page into two pages: keep this one, and add one more right after it that goes deeper. Add a speaker note for the new page.',
53
- );
54
- });
55
-
56
- it('ends with the language and one sentence back', () => {
57
- expect(
58
- prompt('rewrite')?.endsWith(
59
- 'Write in the language "en". When you are done, reply with one short sentence saying what changed.',
60
- ),
61
- ).toBe(true);
62
- });
63
-
64
- it('leaves out the quotes when the page has no title', () => {
65
- expect(
66
- pageTaskPrompt({ slideId: 'd', page: { n: 2, title: '' }, action: 'rewrite', lang: 'en' }),
67
- ).toContain('Work on page 2 of slides/d/index.tsx only.');
68
- });
69
- });
70
-
71
- describe('chapterPlanPrompt', () => {
72
- it('plans without writing, and says what the chapter has', () => {
73
- const prompt = chapterPlanPrompt({
74
- slideId: 'deck',
75
- chapter: 1,
76
- title: 'Why now',
77
- brief: 'the market moved',
78
- count: 3,
79
- pages: [
80
- { n: 4, title: 'The shift' },
81
- { n: 5, title: '' },
82
- ],
83
- lang: 'zh-CN',
84
- });
85
- expect(prompt).toContain(
86
- 'Plan new pages for chapter 2 "Why now" of slides/deck/index.tsx. This turn is planning only: do not write, edit or create any file.',
87
- );
88
- expect(prompt).toContain('The chapter should cover: the market moved');
89
- expect(prompt).toContain('It has these pages now: page 4 "The shift", page 5.');
90
- expect(prompt).toContain('Plan 3 new pages that come after them.');
91
- expect(prompt).toContain('<lemonriver-chapter> and </lemonriver-chapter>');
92
- expect(prompt).toContain('Write in the language "zh-CN".');
93
- });
94
-
95
- it('says so when the chapter is empty', () => {
96
- const prompt = chapterPlanPrompt({
97
- slideId: 'deck',
98
- chapter: 0,
99
- title: '',
100
- brief: 'open',
101
- count: 1,
102
- pages: [],
103
- lang: 'en',
104
- });
105
- expect(prompt).toContain('It has no pages yet.');
106
- });
107
- });
108
-
109
- describe('chapterWritePrompt', () => {
110
- const items = [
111
- { id: 'a', title: 'First', kind: 'page' as const },
112
- { id: 'b', title: 'Second', kind: 'chart' as const },
113
- ];
114
-
115
- it('places the pages after one page', () => {
116
- const prompt = chapterWritePrompt({
117
- slideId: 'deck',
118
- chapter: 1,
119
- title: 'Why now',
120
- items,
121
- anchor: { n: 4, title: 'The shift' },
122
- lang: 'en',
123
- });
124
- expect(prompt).toContain(
125
- 'Add these pages to chapter 2 "Why now" of slides/deck/index.tsx, right after page 4 "The shift".',
126
- );
127
- expect(prompt).toContain('1. "First" (page)');
128
- expect(prompt).toContain('2. "Second" (chart)');
129
- expect(prompt).toContain(
130
- "Follow the deck's existing theme and layout. Add a speaker note for each new page. Do not change any other page.",
131
- );
132
- });
133
-
134
- it('places them at the very start when there is nothing in front', () => {
135
- const prompt = chapterWritePrompt({
136
- slideId: 'deck',
137
- chapter: 0,
138
- title: '',
139
- items,
140
- anchor: null,
141
- lang: 'en',
142
- });
143
- expect(prompt).toContain('of slides/deck/index.tsx, at the start of the deck.');
144
- });
145
- });
146
-
147
- describe('chapter block', () => {
148
- const block = (items: unknown) =>
149
- `Planned.\n<lemonriver-chapter>${JSON.stringify(items)}</lemonriver-chapter>`;
150
-
151
- it('reads the titles the agent planned', () => {
152
- expect(parseChapterBlock(block([{ title: 'A', kind: 'page' }]))?.map((i) => i.title)).toEqual([
153
- 'A',
154
- ]);
155
- });
156
-
157
- it('takes the last block, so a retried answer wins', () => {
158
- const text = `${block([{ title: 'Old', kind: 'page' }])}\n${block([
159
- { title: 'New', kind: 'page' },
160
- ])}`;
161
- expect(parseChapterBlock(text)?.map((i) => i.title)).toEqual(['New']);
162
- });
163
-
164
- it('keeps no more than eight', () => {
165
- const items = Array.from({ length: 10 }, (_, i) => ({ title: `P${i}`, kind: 'page' }));
166
- expect(parseChapterBlock(block(items))).toHaveLength(8);
167
- });
168
-
169
- it('reads nothing when there is no block, or the block is still streaming', () => {
170
- expect(parseChapterBlock('no block here')).toBeNull();
171
- expect(parseChapterBlock('Planning… <lemonriver-chapter>[{"title":')).toBeNull();
172
- });
173
-
174
- it('takes the block out of what the transcript shows', () => {
175
- expect(stripChapterBlock(block([{ title: 'A', kind: 'page' }]))).toBe('Planned.');
176
- expect(stripChapterBlock('Planning <lemonriver-chapter>[{"ti')).toBe('Planning');
177
- });
178
- });
179
-
180
- describe('sanitizeTask', () => {
181
- it('reads each kind of task', () => {
182
- expect(sanitizeTask({ kind: 'changes' })).toEqual({ kind: 'changes' });
183
- expect(sanitizeTask({ kind: 'page', page: 'Two', action: 'expand' })).toEqual({
184
- kind: 'page',
185
- page: 'Two',
186
- action: 'expand',
187
- });
188
- expect(sanitizeTask({ kind: 'chapter-write', chapter: 1, title: 'Why now' })).toMatchObject({
189
- kind: 'chapter-write',
190
- chapter: 1,
191
- });
192
- });
193
-
194
- it('refuses what it cannot run', () => {
195
- expect(sanitizeTask(null)).toBeNull();
196
- expect(sanitizeTask({ kind: 'page', page: 'Two', action: 'delete' })).toBeNull();
197
- expect(sanitizeTask({ kind: 'chapter-plan', chapter: 0, count: 9 })).toBeNull();
198
- expect(sanitizeTask({ kind: 'chapter-write', chapter: -1 })).toBeNull();
199
- });
200
- });
@@ -1,121 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { applyPrompt, type PromptPage } from './apply-prompt.ts';
3
- import type { Placement, Spot } from './changes.ts';
4
- import type { Restructure } from './restructure.ts';
5
-
6
- const PAGES: PromptPage[] = [
7
- { key: 'a', n: 1, title: 'Cover' },
8
- { key: 'b', n: 2, title: 'Ask' },
9
- { key: 'c', n: 3, title: '' },
10
- ];
11
-
12
- const spot = (page: string, before: string | null = null, beforeInfo?: Spot['beforeInfo']): Spot =>
13
- beforeInfo ? { page, before, beforeInfo } : { page, before };
14
-
15
- const move = (to: Spot | 'parked', extra: Partial<Placement> = {}): Placement => ({
16
- origin: { page: 'a', before: null, block: 'x' },
17
- block: { kind: 'chart', text: 'Revenue by quarter', loc: null },
18
- to,
19
- ...extra,
20
- });
21
-
22
- function prompt(changes: Placement[], restructures: Restructure[] = []): string {
23
- return applyPrompt({ slideId: 'deck', pages: PAGES, changes, restructures });
24
- }
25
-
26
- const lines = (changes: Placement[], restructures: Restructure[] = []): string[] =>
27
- prompt(changes, restructures).split('\n');
28
-
29
- describe('applyPrompt', () => {
30
- it('opens with the file and the one rule, and closes with the speaker notes', () => {
31
- const text = prompt([]);
32
- expect(text.startsWith('Rearrange the deck slides/deck/index.tsx as listed below.')).toBe(true);
33
- expect(text).toContain('keep every other page, the wording, the styles and the speaker notes');
34
- expect(text.endsWith('reply with one short sentence saying what changed.')).toBe(true);
35
- });
36
-
37
- it('names the block, both pages and the block it goes before', () => {
38
- const [line] = lines([
39
- move(spot('c', 'y', { kind: 'point', text: 'Margins held', loc: null })),
40
- ]).slice(1);
41
- expect(line).toBe(
42
- 'Move the chart "Revenue by quarter" from page 1 "Cover" to page 3, before the point "Margins held".',
43
- );
44
- });
45
-
46
- it('says where a block at the end goes', () => {
47
- const [line] = lines([move(spot('b'))]).slice(1);
48
- expect(line).toBe(
49
- 'Move the chart "Revenue by quarter" from page 1 "Cover" to page 2 "Ask", at the end.',
50
- );
51
- });
52
-
53
- it('removes a block the user set aside', () => {
54
- const [line] = lines([move('parked')]).slice(1);
55
- expect(line).toBe('Remove the chart "Revenue by quarter" from page 1 "Cover".');
56
- });
57
-
58
- it('hands back the code of a block coming out of the holding area', () => {
59
- const text = prompt([
60
- move(spot('b', 'y', { kind: 'point', text: 'Ask first', loc: null }), {
61
- fromParking: true,
62
- code: '<p>Saved</p>',
63
- }),
64
- ]);
65
- expect(text).toContain(
66
- 'Add this block to page 2 "Ask", before the point "Ask first". Its code, taken from the deck before it was set aside:',
67
- );
68
- expect(text).toContain('```tsx\n<p>Saved</p>\n```');
69
- });
70
-
71
- it('splits a page by the blocks that leave it', () => {
72
- const [line] = lines(
73
- [],
74
- [
75
- {
76
- kind: 'split',
77
- page: 'c',
78
- blocks: ['t', 'p'],
79
- blockInfo: [
80
- { id: 't', kind: 'title', text: 'Plan' },
81
- { id: 'p', kind: 'point', text: 'Costs' },
82
- ],
83
- },
84
- ],
85
- ).slice(1);
86
- expect(line).toBe(
87
- 'Split page 3: move the title "Plan" and the point "Costs" onto a new page right after it.',
88
- );
89
- });
90
-
91
- it('merges a page into the one before it', () => {
92
- const [line] = lines([], [{ kind: 'merge', pages: ['b', 'c'] }]).slice(1);
93
- expect(line).toBe(
94
- 'Merge page 3 into page 2 "Ask": put the content of page 3 at the end of page 2 and remove page 3.',
95
- );
96
- });
97
-
98
- it('names a block that has no words of its own by its kind', () => {
99
- const [line] = lines([
100
- move(spot('b'), { block: { kind: 'image', text: '', loc: '9:4' } }),
101
- ]).slice(1);
102
- expect(line).toBe('Move the image from page 1 "Cover" to page 2 "Ask", at the end.');
103
- });
104
-
105
- it('skips a change whose page is no longer in the deck', () => {
106
- const text = prompt([
107
- {
108
- origin: { page: 'gone', before: null, block: 'x' },
109
- block: { kind: 'text', text: 'Old', loc: null },
110
- to: spot('b'),
111
- },
112
- {
113
- origin: { page: 'a', before: null, block: 'z' },
114
- block: { kind: 'text', text: 'Still here', loc: null },
115
- to: 'parked',
116
- },
117
- ]);
118
- expect(text).not.toContain('Old');
119
- expect(text).toContain('Still here');
120
- });
121
- });