@lemonriver/core 0.4.0 → 0.6.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 (115) hide show
  1. package/README.md +14 -4
  2. package/dist/{build-Nl7EeJ6x.js → build-RlcGG-Ve.js} +1 -1
  3. package/dist/cli/bin.js +4 -4
  4. package/dist/{config-CpC0nM3r.js → config-BJT87wE9.js} +4756 -2012
  5. package/dist/{dev-BB3THd5I.js → dev-DR-j_xda.js} +2 -2
  6. package/dist/{preview-BGjgTg7H.js → preview-BTAhTb5B.js} +1 -1
  7. package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
  8. package/dist/vite/index.js +1 -1
  9. package/package.json +2 -2
  10. package/src/agent/types.ts +14 -2
  11. package/src/app/components/agent/agent-panel.tsx +17 -5
  12. package/src/app/components/agent/connect-view.tsx +1 -1
  13. package/src/app/components/agent/provider-logo.tsx +10 -1
  14. package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
  15. package/src/app/lemonriver/agent-providers/section.tsx +75 -0
  16. package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
  17. package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
  18. package/src/app/lemonriver/board/blocks/cache.ts +28 -0
  19. package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
  20. package/src/app/lemonriver/board/blocks/classify.test.ts +209 -0
  21. package/src/app/lemonriver/board/blocks/classify.ts +152 -0
  22. package/src/app/lemonriver/board/blocks/snapshot.ts +116 -0
  23. package/src/app/lemonriver/board/board-canvas.tsx +627 -104
  24. package/src/app/lemonriver/board/board-page.tsx +1702 -91
  25. package/src/app/lemonriver/board/board.css +58 -7
  26. package/src/app/lemonriver/board/layout.test.ts +84 -0
  27. package/src/app/lemonriver/board/layout.ts +112 -11
  28. package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
  29. package/src/app/lemonriver/board/model/agent-tasks.ts +223 -0
  30. package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
  31. package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
  32. package/src/app/lemonriver/board/model/apply.ts +71 -0
  33. package/src/app/lemonriver/board/model/cards.test.ts +95 -2
  34. package/src/app/lemonriver/board/model/cards.ts +88 -20
  35. package/src/app/lemonriver/board/model/changes.test.ts +244 -0
  36. package/src/app/lemonriver/board/model/changes.ts +268 -0
  37. package/src/app/lemonriver/board/model/filter.test.ts +50 -0
  38. package/src/app/lemonriver/board/model/filter.ts +42 -0
  39. package/src/app/lemonriver/board/model/history.test.ts +71 -0
  40. package/src/app/lemonriver/board/model/history.ts +51 -0
  41. package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
  42. package/src/app/lemonriver/board/model/restructure.ts +169 -0
  43. package/src/app/lemonriver/board/model/self-check.test.ts +329 -0
  44. package/src/app/lemonriver/board/model/self-check.ts +489 -0
  45. package/src/app/lemonriver/board/model/structure.test.ts +249 -0
  46. package/src/app/lemonriver/board/model/structure.ts +209 -0
  47. package/src/app/lemonriver/board/model/timing.test.ts +113 -0
  48. package/src/app/lemonriver/board/model/timing.ts +117 -0
  49. package/src/app/lemonriver/board/page-node.tsx +258 -55
  50. package/src/app/lemonriver/board/self-check-jump.ts +23 -0
  51. package/src/app/lemonriver/board/self-check-panel.tsx +272 -0
  52. package/src/app/lemonriver/board/self-check-runner.tsx +150 -0
  53. package/src/app/lemonriver/board/status-style.ts +25 -0
  54. package/src/app/lemonriver/board/use-board-apply.ts +206 -0
  55. package/src/app/lemonriver/board/use-board-cards.ts +108 -5
  56. package/src/app/lemonriver/board/use-board-changes.ts +108 -0
  57. package/src/app/lemonriver/board/use-board-columns.ts +37 -56
  58. package/src/app/lemonriver/board/use-board-comments.ts +36 -0
  59. package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
  60. package/src/app/lemonriver/board/use-history.ts +86 -0
  61. package/src/app/lemonriver/board/use-page-order.ts +65 -38
  62. package/src/app/lemonriver/board/use-self-check.ts +117 -0
  63. package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
  64. package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
  65. package/src/app/lemonriver/board/views/list-view.tsx +356 -0
  66. package/src/app/lemonriver/board/views/progress.tsx +32 -0
  67. package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
  68. package/src/app/lemonriver/chrome/filter-pill.tsx +30 -0
  69. package/src/app/lemonriver/chrome/sidebar-extras.tsx +12 -1
  70. package/src/app/lemonriver/features.test.ts +5 -0
  71. package/src/app/lemonriver/features.ts +2 -1
  72. package/src/app/lemonriver/home/deck-card.tsx +10 -0
  73. package/src/app/lemonriver/home/home-page.tsx +55 -6
  74. package/src/app/lemonriver/home/use-deck-times.ts +4 -1
  75. package/src/app/lemonriver/outline/build-team.tsx +42 -0
  76. package/src/app/lemonriver/outline/describe-page.tsx +128 -27
  77. package/src/app/lemonriver/outline/draft.ts +38 -0
  78. package/src/app/lemonriver/outline/model.test.ts +118 -0
  79. package/src/app/lemonriver/outline/model.ts +92 -7
  80. package/src/app/lemonriver/outline/outline-page.tsx +90 -7
  81. package/src/app/lemonriver/outline/pick-style.tsx +282 -0
  82. package/src/app/lemonriver/routes.test.tsx +17 -5
  83. package/src/app/lemonriver/routes.tsx +28 -0
  84. package/src/app/lemonriver/settings/settings-page.tsx +3 -0
  85. package/src/app/lemonriver/slide-extensions.tsx +14 -2
  86. package/src/app/lemonriver/templates/client.ts +60 -0
  87. package/src/app/lemonriver/templates/demo-page.tsx +79 -0
  88. package/src/app/lemonriver/templates/knobs.test.ts +62 -0
  89. package/src/app/lemonriver/templates/knobs.ts +62 -0
  90. package/src/app/lemonriver/templates/library-page.tsx +292 -0
  91. package/src/app/lemonriver/templates/model.test.ts +175 -0
  92. package/src/app/lemonriver/templates/model.ts +339 -0
  93. package/src/app/lemonriver/templates/preview-content.test.ts +117 -0
  94. package/src/app/lemonriver/templates/preview-content.ts +149 -0
  95. package/src/app/lemonriver/templates/recommend.test.ts +71 -0
  96. package/src/app/lemonriver/templates/recommend.ts +72 -0
  97. package/src/app/lemonriver/templates/use-library.ts +58 -0
  98. package/src/app/lemonriver/templates/virtual.d.ts +28 -0
  99. package/src/app/lemonriver/text/en.ts +228 -0
  100. package/src/app/lemonriver/text/es.ts +220 -0
  101. package/src/app/lemonriver/text/ja.ts +220 -0
  102. package/src/app/lemonriver/text/types.ts +243 -0
  103. package/src/app/lemonriver/text/zh-cn.ts +218 -0
  104. package/src/app/lemonriver/text/zh-tw.ts +218 -0
  105. package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
  106. package/src/app/lemonriver/theme/pages.test.ts +4 -0
  107. package/src/app/lemonriver/theme/pages.ts +6 -1
  108. package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
  109. package/src/app/lemonriver/theme/use-theme.tsx +2 -2
  110. package/src/app/lemonriver/update/prompt.ts +1 -1
  111. package/src/app/lib/agent/use-agent.ts +4 -3
  112. package/src/app/routes/slide.tsx +1 -1
  113. package/src/app/assets/open-slide.svg +0 -39
  114. package/src/app/favicon.ico +0 -0
  115. package/src/app/favicon.svg +0 -39
@@ -17,38 +17,20 @@ import { readPrefs } from '../agent-prefs/prefs';
17
17
  import { useAgentPrefs } from '../agent-prefs/use-prefs';
18
18
  import { Mascot } from '../brand/mascot';
19
19
  import { Onboarding } from '../onboarding/onboarding';
20
+ import { OCCASIONS, type OccasionId } from '../templates/model';
21
+ import { useTemplateLibrary } from '../templates/use-library';
20
22
  import { useLrText } from '../text';
23
+ import { readDraft, writeDraft } from './draft';
21
24
  import { checkFileObject, type FileVerdict, formatSize } from './files';
22
- import { MAX_BRIEF, OUTLINE_PAGE_SIZES, type Outline, outlinePrompt } from './model';
25
+ import { MAX_AUDIENCE, MAX_BRIEF, OUTLINE_PAGE_SIZES, type Outline, outlinePrompt } from './model';
23
26
  import { Steps } from './steps';
24
27
 
25
- const DRAFT_KEY = 'lemonriver:new-deck-draft';
26
-
27
28
  type DraftFile = { key: string; file: File; verdict: FileVerdict };
28
29
 
29
- type StoredDraft = { brief?: unknown; pages?: unknown };
30
-
31
30
  function basePath(): string {
32
31
  return import.meta.env.BASE_URL.replace(/\/$/, '');
33
32
  }
34
33
 
35
- function readDraft(): StoredDraft {
36
- try {
37
- const raw = sessionStorage.getItem(DRAFT_KEY);
38
- if (!raw) return {};
39
- const parsed: unknown = JSON.parse(raw);
40
- return parsed && typeof parsed === 'object' ? (parsed as StoredDraft) : {};
41
- } catch {
42
- return {};
43
- }
44
- }
45
-
46
- function writeDraft(brief: string, pages: number): void {
47
- try {
48
- sessionStorage.setItem(DRAFT_KEY, JSON.stringify({ brief, pages }));
49
- } catch {}
50
- }
51
-
52
34
  function fileKey(file: File): string {
53
35
  return `${file.name}:${file.size}:${file.lastModified}:${Math.random().toString(36).slice(2, 7)}`;
54
36
  }
@@ -59,27 +41,50 @@ export function DescribePage() {
59
41
  const location = useLocation();
60
42
  const prefs = useAgentPrefs();
61
43
  const { connected, loading, provider } = useAgentStatus();
44
+ const library = useTemplateLibrary();
62
45
  const deckId = new URLSearchParams(location.search).get('deck') ?? '';
46
+ const templateParam = new URLSearchParams(location.search).get('template') ?? '';
63
47
  const initialState = (location.state ?? {}) as { brief?: unknown };
48
+ const [draft] = useState(readDraft);
64
49
 
65
50
  const [brief, setBrief] = useState(() => {
66
51
  if (typeof initialState.brief === 'string') return initialState.brief.slice(0, MAX_BRIEF);
67
- const draft = readDraft();
68
52
  return typeof draft.brief === 'string' ? draft.brief.slice(0, MAX_BRIEF) : '';
69
53
  });
70
54
  const [pages, setPages] = useState<number>(() => {
71
- const draft = readDraft();
72
55
  return OUTLINE_PAGE_SIZES.find((size) => size === draft.pages) ?? 8;
73
56
  });
57
+ const [occasion, setOccasion] = useState<OccasionId | null>(() =>
58
+ OCCASIONS.find((entry) => entry.id === draft.occasion) ? (draft.occasion as OccasionId) : null,
59
+ );
60
+ const [audience, setAudience] = useState(() =>
61
+ typeof draft.audience === 'string' ? draft.audience.slice(0, MAX_AUDIENCE) : '',
62
+ );
63
+ const [templateId, setTemplateId] = useState<string | null>(() => {
64
+ if (templateParam) return templateParam;
65
+ return typeof draft.template === 'string' ? draft.template : null;
66
+ });
74
67
  const [files, setFiles] = useState<DraftFile[]>([]);
75
68
  const [uploaded, setUploaded] = useState<string[]>([]);
76
69
  const [busy, setBusy] = useState(false);
77
70
  const input = useRef<HTMLInputElement>(null);
78
71
  const replacing = useRef<string | null>(null);
72
+ const appliedTemplate = useRef<string | null>(null);
73
+
74
+ const template = library?.templates.find((entry) => entry.id === templateId) ?? null;
75
+ const occasions = library?.occasions ?? OCCASIONS;
76
+ const occasionPickersShown = library?.available === true;
77
+
78
+ useEffect(() => {
79
+ writeDraft({ brief, pages, occasion, audience, template: templateId });
80
+ }, [brief, pages, occasion, audience, templateId]);
79
81
 
80
82
  useEffect(() => {
81
- writeDraft(brief, pages);
82
- }, [brief, pages]);
83
+ if (!templateParam || !template || appliedTemplate.current === templateParam) return;
84
+ appliedTemplate.current = templateParam;
85
+ setTemplateId(template.id);
86
+ setOccasion(template.occasions[0] ?? null);
87
+ }, [templateParam, template]);
83
88
 
84
89
  useEffect(() => {
85
90
  if (!deckId) return;
@@ -151,6 +156,11 @@ export function DescribePage() {
151
156
  lastTurn: null,
152
157
  prefs: readPrefs(localStorage),
153
158
  decisions: [],
159
+ occasion,
160
+ audience: audience.trim(),
161
+ templatePrompt: '',
162
+ templateSkeletons: [],
163
+ templateId,
154
164
  };
155
165
  const started = await fetch('/__lr/outline/start', {
156
166
  method: 'POST',
@@ -161,13 +171,25 @@ export function DescribePage() {
161
171
  pages,
162
172
  files: names,
163
173
  prefs: outline.prefs,
174
+ occasion: outline.occasion,
175
+ audience: outline.audience,
176
+ template: templateId,
164
177
  }),
165
178
  });
166
179
  if (!started.ok) throw new Error('start failed');
180
+ // The server reads the occasion's audience and page order from the library.
181
+ const extra = ((await started.json().catch(() => null)) as { prompt?: unknown } | null)
182
+ ?.prompt;
167
183
 
168
184
  const session = await createSession(provider.id, slideId);
169
185
  setActiveSession(session.id);
170
- await sendMessage(session.id, outlinePrompt(outline, slideId, locale.id), { slideId });
186
+ const prompt = [
187
+ outlinePrompt(outline, slideId, locale.id),
188
+ typeof extra === 'string' ? extra : '',
189
+ ]
190
+ .filter((line) => line.trim() !== '')
191
+ .join('\n');
192
+ await sendMessage(session.id, prompt, { slideId });
171
193
  window.location.assign(`${basePath()}/s/${encodeURIComponent(slideId)}/outline`);
172
194
  } catch {
173
195
  toast.error(lr.outline.startFailed);
@@ -179,6 +201,22 @@ export function DescribePage() {
179
201
  <div data-lr-new className="max-w-[760px]">
180
202
  <Steps current={1} />
181
203
 
204
+ {template && (
205
+ <div data-lr-selected-template={template.id} className="mt-5 flex items-center gap-2">
206
+ <span className="inline-flex items-center gap-1 rounded-full border border-border bg-[var(--lr-accent-soft)] py-0.5 pr-1 pl-3 text-[13px] font-medium">
207
+ {format(lr.outline.selectedTemplate, { name: template.name })}
208
+ <button
209
+ type="button"
210
+ aria-label={lr.outline.removeTemplate}
211
+ onClick={() => setTemplateId(null)}
212
+ className="rounded-full px-1 text-[15px] leading-none text-muted-foreground hover:text-foreground"
213
+ >
214
+ ×
215
+ </button>
216
+ </span>
217
+ </div>
218
+ )}
219
+
182
220
  <header className="mt-6 mb-5">
183
221
  <h1 className="font-heading text-[28px] font-bold leading-[34px] tracking-[-0.01em]">
184
222
  {lr.outline.describeTitle}
@@ -195,6 +233,69 @@ export function DescribePage() {
195
233
  className="min-h-[88px] resize-none text-[15px]"
196
234
  />
197
235
 
236
+ {occasionPickersShown && (
237
+ <div className="mt-5">
238
+ <p className="text-[13px] font-semibold">{lr.outline.occasionLabel}</p>
239
+ <div
240
+ role="radiogroup"
241
+ aria-label={lr.outline.occasionLabel}
242
+ data-lr-occasions
243
+ className="mt-2 flex flex-wrap gap-2"
244
+ >
245
+ {occasions.map((entry) => (
246
+ // biome-ignore lint/a11y/useSemanticElements: a row of pills, as with the page count
247
+ <button
248
+ key={entry.id}
249
+ type="button"
250
+ role="radio"
251
+ aria-checked={occasion === entry.id}
252
+ onClick={() => setOccasion(entry.id)}
253
+ className={cn(
254
+ 'h-8 rounded-full border px-3.5 text-[13px] font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/40',
255
+ occasion === entry.id
256
+ ? 'border-[var(--lr-focus)] bg-[var(--lr-accent-soft)] text-foreground'
257
+ : 'border-border bg-card text-muted-foreground hover:border-[var(--lr-text-3)]',
258
+ )}
259
+ >
260
+ {entry.name}
261
+ </button>
262
+ ))}
263
+ {/* biome-ignore lint/a11y/useSemanticElements: a row of pills, as with the page count */}
264
+ <button
265
+ type="button"
266
+ role="radio"
267
+ aria-checked={occasion === null}
268
+ onClick={() => setOccasion(null)}
269
+ className={cn(
270
+ 'h-8 rounded-full border px-3.5 text-[13px] font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/40',
271
+ occasion === null
272
+ ? 'border-[var(--lr-focus)] bg-[var(--lr-accent-soft)] text-foreground'
273
+ : 'border-border bg-card text-muted-foreground hover:border-[var(--lr-text-3)]',
274
+ )}
275
+ >
276
+ {lr.outline.unsure}
277
+ </button>
278
+ </div>
279
+ </div>
280
+ )}
281
+
282
+ {occasionPickersShown && (
283
+ <div className="mt-5">
284
+ <label className="text-[13px] font-semibold" htmlFor="lr-audience">
285
+ {lr.outline.audienceLabel}
286
+ </label>
287
+ <input
288
+ id="lr-audience"
289
+ type="text"
290
+ value={audience}
291
+ maxLength={MAX_AUDIENCE}
292
+ onChange={(event) => setAudience(event.target.value.slice(0, MAX_AUDIENCE))}
293
+ placeholder={lr.outline.audiencePlaceholder}
294
+ className="mt-2 h-9 w-full rounded-[6px] border border-border bg-card px-3 text-[14px] outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring/40"
295
+ />
296
+ </div>
297
+ )}
298
+
198
299
  <div className="mt-5">
199
300
  <p className="text-[13px] font-semibold">{lr.outline.pagesLabel}</p>
200
301
  <div role="radiogroup" aria-label={lr.outline.pagesLabel} className="mt-2 flex gap-2">
@@ -0,0 +1,38 @@
1
+ export const DRAFT_KEY = 'lemonriver:new-deck-draft';
2
+
3
+ export type StoredDraft = {
4
+ brief?: unknown;
5
+ pages?: unknown;
6
+ occasion?: unknown;
7
+ audience?: unknown;
8
+ template?: unknown;
9
+ };
10
+
11
+ export function readDraft(): StoredDraft {
12
+ try {
13
+ const raw = sessionStorage.getItem(DRAFT_KEY);
14
+ if (!raw) return {};
15
+ const parsed: unknown = JSON.parse(raw);
16
+ return parsed && typeof parsed === 'object' ? (parsed as StoredDraft) : {};
17
+ } catch {
18
+ return {};
19
+ }
20
+ }
21
+
22
+ export function writeDraft(draft: {
23
+ brief: string;
24
+ pages: number;
25
+ occasion: string | null;
26
+ audience: string;
27
+ template: string | null;
28
+ }): void {
29
+ try {
30
+ sessionStorage.setItem(DRAFT_KEY, JSON.stringify(draft));
31
+ } catch {}
32
+ }
33
+
34
+ /** The template the user came in with from the library, if they picked one. */
35
+ export function draftTemplateId(): string | null {
36
+ const { template } = readDraft();
37
+ return typeof template === 'string' && template !== '' ? template : null;
38
+ }
@@ -1,10 +1,12 @@
1
1
  import { describe, expect, it } from 'vitest';
2
+ import type { AgentItem } from '../../../agent/types';
2
3
  import { DEFAULT_PREFS } from '../agent-prefs/prefs';
3
4
  import {
4
5
  afterTurn,
5
6
  collectDecisions,
6
7
  driverAction,
7
8
  insertPage,
9
+ lastErrorText,
8
10
  MAX_BRIEF,
9
11
  MAX_DECISIONS,
10
12
  MAX_ITEMS,
@@ -49,6 +51,11 @@ const outline: Outline = {
49
51
  lastTurn: null,
50
52
  prefs: DEFAULT_PREFS,
51
53
  decisions: [],
54
+ occasion: 'report',
55
+ audience: '董事会成员',
56
+ templatePrompt: '',
57
+ templateSkeletons: [],
58
+ templateId: null,
52
59
  };
53
60
 
54
61
  describe('sanitizeOutline', () => {
@@ -56,6 +63,23 @@ describe('sanitizeOutline', () => {
56
63
  expect(sanitizeOutline(outline)).toEqual(outline);
57
64
  });
58
65
 
66
+ it('keeps the occasion and audience, and drops ones it cannot use', () => {
67
+ expect(sanitizeOutline(outline)).toMatchObject({ occasion: 'report', audience: '董事会成员' });
68
+ expect(sanitizeOutline({ ...outline, occasion: 'nope', audience: 7 })).toMatchObject({
69
+ occasion: null,
70
+ audience: '',
71
+ });
72
+ expect(sanitizeOutline({ ...outline, audience: ` ${'字'.repeat(80)} ` })?.audience).toBe(
73
+ '字'.repeat(40),
74
+ );
75
+ });
76
+
77
+ it('reads a record written before the occasion fields existed', () => {
78
+ expect(sanitizeOutline({ ...outline, occasion: undefined, audience: undefined })).toMatchObject(
79
+ { occasion: null, audience: '' },
80
+ );
81
+ });
82
+
59
83
  it('fills the build fields on a record written before they existed', () => {
60
84
  const old = {
61
85
  state: 'building',
@@ -311,6 +335,63 @@ describe('prompts', () => {
311
335
  });
312
336
  });
313
337
 
338
+ describe('template prompts', () => {
339
+ const applied: Outline = {
340
+ ...outline,
341
+ templatePrompt: 'This deck uses the "Board" template.',
342
+ templateSkeletons: ['cover', 'overview', 'figure', 'cards', 'compare', 'ask', 'end'],
343
+ };
344
+
345
+ it('puts the template instructions first on page one', () => {
346
+ const text = pagePrompt(applied, 'deck-1', 1);
347
+ expect(text.startsWith('This deck uses the "Board" template.')).toBe(true);
348
+ expect(text).toContain('Build slides/deck-1/index.tsx');
349
+ });
350
+
351
+ it('suggests a skeleton per page from the ones the template has', () => {
352
+ const text = pagePrompt(applied, 'deck-1', 1);
353
+ expect(text).toContain('1. [cover] Cover → cover');
354
+ expect(text).toContain('2. [list] Why now → cards');
355
+ expect(text).toContain('3. [kpi] Numbers → overview');
356
+ expect(text).toContain('4. [end] End → end');
357
+ });
358
+
359
+ it('leaves a page kind alone when the template has no skeleton for it', () => {
360
+ const partial: Outline = { ...outline, templateSkeletons: ['cover', 'end'] };
361
+ const text = pagePrompt(partial, 'deck-1', 1);
362
+ expect(text).toContain('2. [list] Why now\n');
363
+ expect(text).toContain('3. [kpi] Numbers\n');
364
+ });
365
+
366
+ it('tells later pages to keep the template and its guide', () => {
367
+ const text = pagePrompt(applied, 'deck-1', 3);
368
+ expect(text.split('\n')[0]).toBe(
369
+ 'Page 3 of 4: [kpi] Numbers → overview. Write only this page; leave the others as they are.',
370
+ );
371
+ expect(text).toContain('Keep using the template in ./kit/');
372
+ expect(text).toContain('kit/docs/GUIDE.md');
373
+ });
374
+
375
+ it('adds the quality checklist to the review pass', () => {
376
+ const withTemplate = reviewPrompt(applied, 'deck-1');
377
+ expect(withTemplate).toContain('kit/docs/质量清单.md');
378
+ expect(withTemplate).toContain('take a screenshot of every page');
379
+ const plain = reviewPrompt(outline, 'deck-1');
380
+ expect(plain).not.toContain('质量清单');
381
+ expect(plain).toContain('pre-delivery checklist at the end of the slide-authoring skill');
382
+ });
383
+
384
+ it('reads only the skeletons the model knows', () => {
385
+ const read = sanitizeOutline({
386
+ ...outline,
387
+ templatePrompt: 'x',
388
+ templateSkeletons: ['cover', 'nope', 3, 'cover', 'end'],
389
+ });
390
+ expect(read?.templateSkeletons).toEqual(['cover', 'end']);
391
+ expect(read?.templatePrompt).toBe('x');
392
+ });
393
+ });
394
+
314
395
  const building = (patch: Partial<Outline> = {}): Outline => ({
315
396
  ...outline,
316
397
  state: 'building',
@@ -631,3 +712,40 @@ describe('collectDecisions', () => {
631
712
  expect(collectDecisions([], many)).toHaveLength(MAX_DECISIONS);
632
713
  });
633
714
  });
715
+
716
+ describe('lastErrorText', () => {
717
+ const user = (id: string): AgentItem => ({ kind: 'user', id, ts: '', text: 'go' });
718
+ const error = (id: string, text: string): AgentItem => ({ kind: 'error', id, ts: '', text });
719
+ const assistant = (id: string): AgentItem => ({
720
+ kind: 'assistant',
721
+ id,
722
+ ts: '',
723
+ text: 'ok',
724
+ streaming: false,
725
+ });
726
+
727
+ it('returns the last error after the message the user sent', () => {
728
+ const items = [user('u1'), error('e1', 'old'), assistant('a1'), error('e2', 'new')];
729
+ expect(lastErrorText(items, 'u1')).toBe('new');
730
+ });
731
+
732
+ it('ignores errors that came before the user message', () => {
733
+ const items = [error('e0', 'before'), user('u1'), assistant('a1'), user('u2')];
734
+ expect(lastErrorText(items, 'u2')).toBeNull();
735
+ });
736
+
737
+ it('returns null when the turn carried no error', () => {
738
+ expect(lastErrorText([user('u1'), assistant('a1')], 'u1')).toBeNull();
739
+ expect(lastErrorText([], null)).toBeNull();
740
+ });
741
+
742
+ it('reads every item when the user message is unknown', () => {
743
+ expect(lastErrorText([error('e1', 'one'), assistant('a1')], null)).toBe('one');
744
+ expect(lastErrorText([user('u1'), error('e1', 'one')], 'missing')).toBe('one');
745
+ });
746
+
747
+ it('clips the text to 200 characters', () => {
748
+ const long = 'x'.repeat(500);
749
+ expect(lastErrorText([user('u1'), error('e1', long)], 'u1')).toHaveLength(200);
750
+ });
751
+ });
@@ -1,4 +1,6 @@
1
+ import type { AgentItem } from '../../../agent/types';
1
2
  import { type AgentPrefs, prefsLines, sanitizePrefs } from '../agent-prefs/prefs';
3
+ import { OCCASIONS, type OccasionId, SKELETONS, type SkeletonId } from '../templates/model';
2
4
 
3
5
  export const PAGE_KINDS = ['cover', 'kpi', 'chart', 'list', 'page', 'end'] as const;
4
6
  export type PageKind = (typeof PAGE_KINDS)[number];
@@ -30,6 +32,14 @@ export type Outline = {
30
32
  lastTurn: BuildTurn | null;
31
33
  prefs: AgentPrefs;
32
34
  decisions: Decision[];
35
+ occasion: OccasionId | null;
36
+ audience: string;
37
+ /** The template's opening instructions, written when the build copied its kit in. */
38
+ templatePrompt: string;
39
+ /** The skeletons that travelled with that template, for the per-page suggestions. */
40
+ templateSkeletons: SkeletonId[];
41
+ /** The template picked when describing the deck; a direct build applies it. */
42
+ templateId: string | null;
33
43
  };
34
44
 
35
45
  export const OUTLINE_PAGE_SIZES = [5, 8, 12] as const;
@@ -37,8 +47,22 @@ export const MAX_ITEMS = 30;
37
47
  export const MIN_ITEMS = 2;
38
48
  export const MAX_TITLE = 120;
39
49
  export const MAX_BRIEF = 2000;
50
+ export const MAX_AUDIENCE = 40;
40
51
  export const MAX_DECISIONS = 20;
41
52
  export const MAX_DECISION_TEXT = 120;
53
+ export const MAX_TEMPLATE_PROMPT = 8000;
54
+
55
+ const SKELETON_IDS = new Set<string>(SKELETONS.map((skeleton) => skeleton.id));
56
+
57
+ function sanitizeSkeletons(raw: unknown): SkeletonId[] {
58
+ if (!Array.isArray(raw)) return [];
59
+ const out: SkeletonId[] = [];
60
+ for (const entry of raw) {
61
+ if (typeof entry !== 'string' || !SKELETON_IDS.has(entry)) continue;
62
+ if (!out.includes(entry as SkeletonId)) out.push(entry as SkeletonId);
63
+ }
64
+ return out;
65
+ }
42
66
 
43
67
  const ID_RE = /^[a-z0-9-]{1,40}$/;
44
68
  const BLOCK_RE = /<lemonriver-outline>([\s\S]*?)<\/lemonriver-outline>/gi;
@@ -58,6 +82,14 @@ export function isOutlineState(value: unknown): value is OutlineState {
58
82
  return typeof value === 'string' && (OUTLINE_STATES as readonly string[]).includes(value);
59
83
  }
60
84
 
85
+ export function isOccasionId(value: unknown): value is OccasionId {
86
+ return typeof value === 'string' && OCCASIONS.some((occasion) => occasion.id === value);
87
+ }
88
+
89
+ function cleanAudience(value: unknown): string {
90
+ return typeof value === 'string' ? value.trim().slice(0, MAX_AUDIENCE) : '';
91
+ }
92
+
61
93
  function cleanTitle(value: unknown): string {
62
94
  return typeof value === 'string' ? value.trim().slice(0, MAX_TITLE) : '';
63
95
  }
@@ -177,6 +209,15 @@ export function sanitizeOutline(raw: unknown): Outline | null {
177
209
  lastTurn: cleanTurn(r.lastTurn, items.length),
178
210
  prefs: sanitizePrefs(r.prefs),
179
211
  decisions: sanitizeDecisions(r.decisions),
212
+ occasion: isOccasionId(r.occasion) ? r.occasion : null,
213
+ audience: cleanAudience(r.audience),
214
+ templatePrompt:
215
+ typeof r.templatePrompt === 'string' ? r.templatePrompt.slice(0, MAX_TEMPLATE_PROMPT) : '',
216
+ templateSkeletons: sanitizeSkeletons(r.templateSkeletons),
217
+ templateId:
218
+ typeof r.templateId === 'string' && /^[a-z0-9][a-z0-9-]*$/.test(r.templateId)
219
+ ? r.templateId
220
+ : null,
180
221
  };
181
222
  }
182
223
 
@@ -259,6 +300,29 @@ const KIND_GUIDE: Record<PageKind, string> = {
259
300
  end: 'closing — the last page and what should happen next',
260
301
  };
261
302
 
303
+ const TEMPLATE_PAGE_LINE =
304
+ 'Keep using the template in ./kit/ — follow kit/docs/GUIDE.md and pick one skeleton per page.';
305
+
306
+ const TEMPLATE_REVIEW_LINE =
307
+ "Before you finish, take a screenshot of every page (see the slide-authoring skill's preview section) and go through kit/docs/质量清单.md item by item; fix what fails. Reply with the items you could not satisfy, if any.";
308
+
309
+ const FRAMEWORK_REVIEW_LINE =
310
+ "Before you finish, take a screenshot of every page (see the slide-authoring skill's preview section) and go through the pre-delivery checklist at the end of the slide-authoring skill item by item; fix what fails. Reply with the items you could not satisfy, if any.";
311
+
312
+ const SKELETON_FOR_KIND: Record<PageKind, SkeletonId[]> = {
313
+ cover: ['cover'],
314
+ kpi: ['overview', 'bignum'],
315
+ chart: ['figure'],
316
+ list: ['cards'],
317
+ page: ['compare', 'process'],
318
+ end: ['end'],
319
+ };
320
+
321
+ /** The skeleton the template offers for a page of this kind, if it has one. */
322
+ export function skeletonFor(kind: PageKind, available: readonly SkeletonId[]): SkeletonId | null {
323
+ return SKELETON_FOR_KIND[kind].find((id) => available.includes(id)) ?? null;
324
+ }
325
+
262
326
  export function outlinePrompt(outline: Outline, slideId: string, lang: string): string {
263
327
  const fileList =
264
328
  outline.files.length > 0
@@ -285,22 +349,31 @@ export function pagePrompt(outline: Outline, slideId: string, k: number): string
285
349
  const page = outline.items[k - 1];
286
350
  if (k >= 2 && page) {
287
351
  const title = page.title || '(untitled)';
288
- return [
289
- `Page ${k} of ${outline.items.length}: [${page.kind}] ${title}. Write only this page; leave the others as they are.`,
290
- ...prefsLines(outline.prefs, 'page'),
291
- ].join('\n');
352
+ const skeleton = skeletonFor(page.kind, outline.templateSkeletons);
353
+ const lines = [
354
+ `Page ${k} of ${outline.items.length}: [${page.kind}] ${title}${skeleton ? ` → ${skeleton}` : ''}. Write only this page; leave the others as they are.`,
355
+ ];
356
+ if (outline.templatePrompt) lines.push(TEMPLATE_PAGE_LINE);
357
+ lines.push(...prefsLines(outline.prefs, 'page'));
358
+ return lines.join('\n');
292
359
  }
293
360
  const list = outline.items
294
- .map((item, i) => `${i + 1}. [${item.kind}] ${item.title || '(untitled)'}`)
361
+ .map((item, i) => {
362
+ const base = `${i + 1}. [${item.kind}] ${item.title || '(untitled)'}`;
363
+ const skeleton = skeletonFor(item.kind, outline.templateSkeletons);
364
+ return skeleton ? `${base} → ${skeleton}` : base;
365
+ })
295
366
  .join('\n');
296
- return [
367
+ const lines = [
297
368
  `Build ${file} from this outline, one page per turn. This turn: write page 1 only, replacing the placeholder page, and set meta.title to the deck title. Pages:`,
298
369
  list,
299
370
  'Page kinds and how to write them:',
300
371
  ...PAGE_KINDS.map((kind) => `- ${KIND_GUIDE[kind]}`),
301
372
  'Numbers from the reference files stay exactly as written there.',
302
373
  ...prefsLines(outline.prefs, 'page'),
303
- ].join('\n');
374
+ ];
375
+ if (outline.templatePrompt) return `${outline.templatePrompt}\n\n${lines.join('\n')}`;
376
+ return lines.join('\n');
304
377
  }
305
378
 
306
379
  export function reviewPrompt(outline: Outline, slideId: string): string {
@@ -309,6 +382,7 @@ export function reviewPrompt(outline: Outline, slideId: string): string {
309
382
  `Check each page of slides/${slideId}/index.tsx against the outline and the reference files in slides/${slideId}/assets/:`,
310
383
  'fix typos and any number that differs from the files.',
311
384
  ];
385
+ lines.push(outline.templatePrompt ? TEMPLATE_REVIEW_LINE : FRAMEWORK_REVIEW_LINE);
312
386
  if (outline.prefs.askOnMismatch) {
313
387
  lines.push(
314
388
  'If two files give different numbers for the same thing, ask the user which to use before changing it.',
@@ -413,6 +487,17 @@ export type TeamState = {
413
487
  review: TeamHelperState;
414
488
  };
415
489
 
490
+ // The failure the user needs to see is the last one after the message they sent.
491
+ export function lastErrorText(items: AgentItem[], userItemId: string | null): string | null {
492
+ const start = userItemId ? items.findIndex((item) => item.id === userItemId) : -1;
493
+ const after = start === -1 ? items : items.slice(start + 1);
494
+ for (let i = after.length - 1; i >= 0; i--) {
495
+ const item = after[i];
496
+ if (item.kind === 'error') return item.text.slice(0, 200);
497
+ }
498
+ return null;
499
+ }
500
+
416
501
  export function teamState(
417
502
  outline: Outline,
418
503
  seen: { running: boolean; waitingForAnswer: boolean; action: DriverAction },