@lemonriver/core 0.3.0 → 0.4.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 (86) hide show
  1. package/dist/{build-Bqo69DWP.js → build-Nl7EeJ6x.js} +1 -1
  2. package/dist/cli/bin.js +3 -3
  3. package/dist/{config-teo3kWz7.d.ts → config-CYNOR93W.d.ts} +1 -1
  4. package/dist/{config-DJ5rkMMg.js → config-CpC0nM3r.js} +697 -2
  5. package/dist/{dev-B2FJD5bJ.js → dev-BB3THd5I.js} +1 -1
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +1 -1
  8. package/dist/locale/index.d.ts +1 -1
  9. package/dist/locale/index.js +1 -1
  10. package/dist/{preview-C93BOZL1.js → preview-BGjgTg7H.js} +1 -1
  11. package/dist/{types-DFK02XVv.d.ts → types-tdaXSyah.d.ts} +1 -0
  12. package/dist/vite/index.d.ts +1 -1
  13. package/dist/vite/index.js +1 -1
  14. package/dist/{zh-tw-DwTAZKa6.js → zh-tw-DcrDeKxr.js} +5 -0
  15. package/package.json +1 -1
  16. package/src/agent/prompt.ts +2 -0
  17. package/src/app/components/agent/agent-panel.tsx +2 -0
  18. package/src/app/components/player.tsx +105 -23
  19. package/src/app/components/present/curtain.tsx +52 -0
  20. package/src/app/components/present/last-slide-hint.tsx +36 -0
  21. package/src/app/components/sidebar/sidebar-footer.tsx +6 -1
  22. package/src/app/components/thumbnail-rail.tsx +1 -0
  23. package/src/app/lemonriver/agent/lemon.tsx +16 -1
  24. package/src/app/lemonriver/agent-prefs/prefs.test.ts +173 -0
  25. package/src/app/lemonriver/agent-prefs/prefs.ts +137 -0
  26. package/src/app/lemonriver/agent-prefs/use-prefs.ts +36 -0
  27. package/src/app/lemonriver/brand/mascot.tsx +86 -0
  28. package/src/app/lemonriver/brand/mascots/design-done.png +0 -0
  29. package/src/app/lemonriver/brand/mascots/design-idle.png +0 -0
  30. package/src/app/lemonriver/brand/mascots/design-needs-you.png +0 -0
  31. package/src/app/lemonriver/brand/mascots/design-working.png +0 -0
  32. package/src/app/lemonriver/brand/mascots/outline-done.png +0 -0
  33. package/src/app/lemonriver/brand/mascots/outline-idle.png +0 -0
  34. package/src/app/lemonriver/brand/mascots/outline-needs-you.png +0 -0
  35. package/src/app/lemonriver/brand/mascots/outline-working.png +0 -0
  36. package/src/app/lemonriver/brand/mascots/research-done.png +0 -0
  37. package/src/app/lemonriver/brand/mascots/research-idle.png +0 -0
  38. package/src/app/lemonriver/brand/mascots/research-needs-you.png +0 -0
  39. package/src/app/lemonriver/brand/mascots/research-working.png +0 -0
  40. package/src/app/lemonriver/brand/mascots/review-done.png +0 -0
  41. package/src/app/lemonriver/brand/mascots/review-idle.png +0 -0
  42. package/src/app/lemonriver/brand/mascots/review-needs-you.png +0 -0
  43. package/src/app/lemonriver/brand/mascots/review-working.png +0 -0
  44. package/src/app/lemonriver/chrome/app-chrome.tsx +2 -0
  45. package/src/app/lemonriver/features.test.ts +5 -0
  46. package/src/app/lemonriver/features.ts +2 -1
  47. package/src/app/lemonriver/home/brief-card.tsx +8 -1
  48. package/src/app/lemonriver/home/home-page.tsx +11 -7
  49. package/src/app/lemonriver/onboarding/onboarding.tsx +182 -0
  50. package/src/app/lemonriver/outline/build-team.tsx +278 -0
  51. package/src/app/lemonriver/outline/describe-page.tsx +380 -0
  52. package/src/app/lemonriver/outline/files.test.ts +90 -0
  53. package/src/app/lemonriver/outline/files.ts +69 -0
  54. package/src/app/lemonriver/outline/model.test.ts +633 -0
  55. package/src/app/lemonriver/outline/model.ts +443 -0
  56. package/src/app/lemonriver/outline/outline-page.tsx +504 -0
  57. package/src/app/lemonriver/outline/pending-pages.tsx +39 -0
  58. package/src/app/lemonriver/outline/rule.ts +3 -0
  59. package/src/app/lemonriver/outline/steps.tsx +43 -0
  60. package/src/app/lemonriver/outline/use-build-driver.ts +258 -0
  61. package/src/app/lemonriver/routes.test.tsx +6 -6
  62. package/src/app/lemonriver/routes.tsx +28 -0
  63. package/src/app/lemonriver/settings/settings-page.tsx +211 -0
  64. package/src/app/lemonriver/slide-extensions.tsx +31 -24
  65. package/src/app/lemonriver/text/en.ts +149 -0
  66. package/src/app/lemonriver/text/es.ts +148 -0
  67. package/src/app/lemonriver/text/ja.ts +150 -0
  68. package/src/app/lemonriver/text/text.test.ts +33 -0
  69. package/src/app/lemonriver/text/types.ts +169 -0
  70. package/src/app/lemonriver/text/zh-cn.ts +146 -0
  71. package/src/app/lemonriver/text/zh-tw.ts +146 -0
  72. package/src/app/lemonriver/theme/app.css +12 -1
  73. package/src/app/lemonriver/theme/pages.test.ts +4 -0
  74. package/src/app/lemonriver/theme/pages.ts +11 -2
  75. package/src/app/lemonriver/update/beta-badge.tsx +26 -0
  76. package/src/app/lemonriver/update/prompt.test.ts +84 -0
  77. package/src/app/lemonriver/update/prompt.ts +48 -0
  78. package/src/app/lemonriver/update/update-prompt.tsx +113 -0
  79. package/src/app/routes/home.tsx +13 -5
  80. package/src/app/routes/slide.tsx +70 -13
  81. package/src/locale/en.ts +1 -0
  82. package/src/locale/es.ts +1 -0
  83. package/src/locale/ja.ts +1 -0
  84. package/src/locale/types.ts +1 -0
  85. package/src/locale/zh-cn.ts +1 -0
  86. package/src/locale/zh-tw.ts +1 -0
@@ -20,7 +20,7 @@ import { isJSXElement, isJSXFragment } from "@babel/types";
20
20
  * BRAND_PAGES as a path pattern, for the pre-paint script, which runs before
21
21
  * any module loads. pages.test.ts keeps the two in step.
22
22
  */
23
- const BRAND_PATH_SOURCE = "^/(themes(/.*)?|assets|settings|trash)?/*$";
23
+ const BRAND_PATH_SOURCE = "^/(themes(/.*)?|assets|settings|trash|new)?/*$";
24
24
  /** Agent screenshots and thumbnails render through this route; nothing may cover it. */
25
25
  const PREVIEW_PATH_SOURCE = "^/s/[^/]+/preview/*$";
26
26
  const REDUCE_MOTION_KEY = "lemonriver:reduce-motion";
@@ -129,6 +129,7 @@ const CARD_STATUSES = [
129
129
  ];
130
130
  const TITLE_MAX$1 = 80;
131
131
  const MEMO_MAX = 2e3;
132
+ const PENDING = "\0pending:";
132
133
  function isCardStatus(value) {
133
134
  return typeof value === "string" && CARD_STATUSES.includes(value);
134
135
  }
@@ -165,6 +166,47 @@ function sanitizeLinks(raw) {
165
166
  return typeof a === "string" && typeof b === "string" ? linkCards(links, a, b) : links;
166
167
  }, []);
167
168
  }
169
+ function patchCard(cards, key, patch) {
170
+ const merged = { ...cards[key] };
171
+ for (const field of [
172
+ "title",
173
+ "status",
174
+ "memo"
175
+ ]) {
176
+ if (!(field in patch)) continue;
177
+ const value = patch[field];
178
+ if (value == null || value === "") delete merged[field];
179
+ else merged[field] = value;
180
+ }
181
+ const card = cleanCard(merged);
182
+ const next = { ...cards };
183
+ if (card) next[key] = card;
184
+ else delete next[key];
185
+ return next;
186
+ }
187
+ /**
188
+ * Keys a page by its entry in the page array, so its card follows it through a
189
+ * reorder made anywhere — the thumbnail rail, or an agent editing the file —
190
+ * and a page added elsewhere never shifts a memo onto its neighbour. A repeated
191
+ * entry, which is what duplicating a page produces, is told apart by
192
+ * occurrence, so the copy starts with a card of its own.
193
+ *
194
+ * `null` entries mean the array cannot be read one entry per page (a spread
195
+ * stands for any number of pages), so pages fall back to their positions.
196
+ * Entries not loaded yet, or disagreeing with the page count while the deck
197
+ * reloads, give keys that match no card, so a memo never flashes onto the
198
+ * wrong page.
199
+ */
200
+ function pageKeys(entries, count) {
201
+ if (entries === null) return Array.from({ length: count }, (_, i) => `@${i}`);
202
+ if (entries === void 0 || entries.length !== count) return Array.from({ length: count }, (_, i) => `${PENDING}${i}`);
203
+ const seen = /* @__PURE__ */ new Map();
204
+ return entries.map((entry) => {
205
+ const n = (seen.get(entry) ?? 0) + 1;
206
+ seen.set(entry, n);
207
+ return n === 1 ? entry : `${entry}#${n}`;
208
+ });
209
+ }
168
210
  //#endregion
169
211
  //#region src/app/lemonriver/board/model/structure.ts
170
212
  function sanitizeStructure(parsed) {
@@ -452,6 +494,27 @@ function updateBoardFile(file, fields) {
452
494
  async function writeBoardStructure(file, structure) {
453
495
  await updateBoardFile(file, { columns: structure.columns });
454
496
  }
497
+ /**
498
+ * Follows a deck renamed out of its placeholder id. A record already sitting at
499
+ * the new id is left alone: it belongs to whatever deck that id means now.
500
+ */
501
+ async function moveBoardRecord(userCwd, fromId, toId) {
502
+ const from = boardStructurePath(userCwd, fromId);
503
+ const to = boardStructurePath(userCwd, toId);
504
+ if (from === to) return;
505
+ try {
506
+ await fs.access(from);
507
+ } catch {
508
+ return;
509
+ }
510
+ try {
511
+ await fs.access(to);
512
+ return;
513
+ } catch {}
514
+ try {
515
+ await fs.rename(from, to);
516
+ } catch {}
517
+ }
455
518
  //#endregion
456
519
  //#region src/lemonriver/board/routes.ts
457
520
  function registerBoardRoutes(server, ctx) {
@@ -585,6 +648,533 @@ function registerDeckRoutes(server, ctx) {
585
648
  });
586
649
  }
587
650
  //#endregion
651
+ //#region src/app/lemonriver/agent-prefs/prefs.ts
652
+ const DEFAULT_PREFS = {
653
+ confirmEachPage: false,
654
+ askOnMismatch: true,
655
+ autoImages: true,
656
+ tone: "steady",
657
+ research: "uploads",
658
+ outline: "review",
659
+ design: "balanced",
660
+ review: "strict"
661
+ };
662
+ const TONES = [
663
+ "steady",
664
+ "friendly",
665
+ "concise"
666
+ ];
667
+ const RESEARCH = ["uploads", "web"];
668
+ const OUTLINES = ["review", "direct"];
669
+ const DESIGNS = [
670
+ "visual",
671
+ "balanced",
672
+ "dense"
673
+ ];
674
+ const REVIEWS = ["strict", "numbers"];
675
+ function pick(value, allowed, fallback) {
676
+ return typeof value === "string" && allowed.includes(value) ? value : fallback;
677
+ }
678
+ function flag(value, fallback) {
679
+ return typeof value === "boolean" ? value : fallback;
680
+ }
681
+ function sanitizePrefs(raw) {
682
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { ...DEFAULT_PREFS };
683
+ const r = raw;
684
+ return {
685
+ confirmEachPage: flag(r.confirmEachPage, DEFAULT_PREFS.confirmEachPage),
686
+ askOnMismatch: flag(r.askOnMismatch, DEFAULT_PREFS.askOnMismatch),
687
+ autoImages: flag(r.autoImages, DEFAULT_PREFS.autoImages),
688
+ tone: pick(r.tone, TONES, DEFAULT_PREFS.tone),
689
+ research: pick(r.research, RESEARCH, DEFAULT_PREFS.research),
690
+ outline: pick(r.outline, OUTLINES, DEFAULT_PREFS.outline),
691
+ design: pick(r.design, DESIGNS, DEFAULT_PREFS.design),
692
+ review: pick(r.review, REVIEWS, DEFAULT_PREFS.review)
693
+ };
694
+ }
695
+ const TONE_LINE = {
696
+ steady: "Write in a steady, professional tone.",
697
+ friendly: "Write in a light, friendly tone.",
698
+ concise: "Keep the wording short and punchy."
699
+ };
700
+ const RESEARCH_LINE = {
701
+ uploads: "Use only the user's reference files; do not look anything up on the web.",
702
+ web: "You may look up facts the files do not cover; say where each one came from."
703
+ };
704
+ const DESIGN_LINE = {
705
+ visual: "Keep text short and give each page one large visual, chart or icon.",
706
+ balanced: "Balance text and visuals.",
707
+ dense: "A page may carry more text and data when the content needs it."
708
+ };
709
+ const IMAGES_LINE = {
710
+ yes: "Use icons and image placeholders where a picture helps; never invent photos the user did not provide.",
711
+ no: "Do not add any image the user did not provide."
712
+ };
713
+ const REVIEW_LINE = {
714
+ strict: "Check wording, typos and every number.",
715
+ numbers: "Check only the numbers against the reference files."
716
+ };
717
+ const MISMATCH_LINE = "When two files disagree on a number, use the one from the spreadsheet (.xlsx, .xls or .csv) and say which you used.";
718
+ function prefsLines(prefs, step) {
719
+ const lines = [TONE_LINE[prefs.tone]];
720
+ if (step === "outline") lines.push(RESEARCH_LINE[prefs.research]);
721
+ if (step === "page") {
722
+ lines.push(DESIGN_LINE[prefs.design]);
723
+ lines.push(prefs.autoImages ? IMAGES_LINE.yes : IMAGES_LINE.no);
724
+ }
725
+ if (step === "review") {
726
+ lines.push(REVIEW_LINE[prefs.review]);
727
+ if (!prefs.askOnMismatch) lines.push(MISMATCH_LINE);
728
+ }
729
+ return lines;
730
+ }
731
+ //#endregion
732
+ //#region src/app/lemonriver/outline/model.ts
733
+ const PAGE_KINDS = [
734
+ "cover",
735
+ "kpi",
736
+ "chart",
737
+ "list",
738
+ "page",
739
+ "end"
740
+ ];
741
+ const OUTLINE_STATES = [
742
+ "drafting",
743
+ "ready",
744
+ "failed",
745
+ "building",
746
+ "built"
747
+ ];
748
+ const OUTLINE_PAGE_SIZES = [
749
+ 5,
750
+ 8,
751
+ 12
752
+ ];
753
+ const MAX_BRIEF = 2e3;
754
+ const ID_RE = /^[a-z0-9-]{1,40}$/;
755
+ const BLOCK_RE = /<lemonriver-outline>([\s\S]*?)<\/lemonriver-outline>/gi;
756
+ let idSeq = 0;
757
+ function newPageId() {
758
+ idSeq += 1;
759
+ return `p-${Date.now().toString(36)}-${idSeq.toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
760
+ }
761
+ function isPageKind(value) {
762
+ return typeof value === "string" && PAGE_KINDS.includes(value);
763
+ }
764
+ function isOutlineState(value) {
765
+ return typeof value === "string" && OUTLINE_STATES.includes(value);
766
+ }
767
+ function cleanTitle(value) {
768
+ return typeof value === "string" ? value.trim().slice(0, 120) : "";
769
+ }
770
+ function cleanItem(raw) {
771
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
772
+ const r = raw;
773
+ return {
774
+ id: typeof r.id === "string" && ID_RE.test(r.id) ? r.id : newPageId(),
775
+ title: cleanTitle(r.title),
776
+ kind: isPageKind(r.kind) ? r.kind : "page"
777
+ };
778
+ }
779
+ function sanitizeItems(raw) {
780
+ if (!Array.isArray(raw)) return [];
781
+ return raw.slice(0, 30).flatMap((item) => {
782
+ const cleaned = cleanItem(item);
783
+ return cleaned ? [cleaned] : [];
784
+ });
785
+ }
786
+ function cleanStep(raw, maxPage) {
787
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
788
+ const r = raw;
789
+ const kind = r.kind === "page" || r.kind === "review" ? r.kind : null;
790
+ if (!kind) return null;
791
+ const n = typeof r.n === "number" && Number.isFinite(r.n) ? Math.trunc(r.n) : -1;
792
+ const at = typeof r.at === "number" && Number.isFinite(r.at) ? r.at : -1;
793
+ if (n < 0 || at < 0) return null;
794
+ return {
795
+ kind,
796
+ n: Math.min(n, maxPage),
797
+ at
798
+ };
799
+ }
800
+ function cleanTurn(raw, maxPage) {
801
+ const step = cleanStep(raw, maxPage);
802
+ if (!step || !raw || typeof raw !== "object") return null;
803
+ return {
804
+ ...step,
805
+ ok: raw.ok === true
806
+ };
807
+ }
808
+ function sanitizeDecisions(raw) {
809
+ if (!Array.isArray(raw)) return [];
810
+ return raw.slice(0, 20).flatMap((entry) => {
811
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) return [];
812
+ const r = entry;
813
+ if (typeof r.id !== "string" || r.id === "") return [];
814
+ return [{
815
+ id: r.id.slice(0, 80),
816
+ question: typeof r.question === "string" ? r.question.slice(0, 120) : "",
817
+ answer: typeof r.answer === "string" ? r.answer.slice(0, 120) : ""
818
+ }];
819
+ });
820
+ }
821
+ /**
822
+ * Every answered question in a review session becomes one decision. Ids are
823
+ * the question item plus its index, so a resumed turn that reports the same
824
+ * item again does not add a duplicate.
825
+ */
826
+ function collectDecisions(existing, items) {
827
+ const seen = new Set(existing.map((decision) => decision.id));
828
+ const next = existing.slice();
829
+ for (const item of items) {
830
+ if (item.kind !== "question" || item.status !== "answered") continue;
831
+ const questions = item.questions ?? [];
832
+ for (let index = 0; index < questions.length; index += 1) {
833
+ if (next.length >= 20) return next;
834
+ const id = `${item.id}:${index}`;
835
+ if (seen.has(id)) continue;
836
+ seen.add(id);
837
+ const question = questions[index];
838
+ const answer = item.answers?.[question.question] ?? "";
839
+ next.push({
840
+ id,
841
+ question: (question.header || question.question).slice(0, 120),
842
+ answer: answer.slice(0, 120)
843
+ });
844
+ }
845
+ }
846
+ return next;
847
+ }
848
+ function sanitizeOutline(raw) {
849
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
850
+ const r = raw;
851
+ if (!isOutlineState(r.state)) return null;
852
+ const pages = OUTLINE_PAGE_SIZES.find((size) => size === r.pages) ?? 8;
853
+ const brief = typeof r.brief === "string" ? r.brief.slice(0, MAX_BRIEF) : "";
854
+ const files = Array.isArray(r.files) ? r.files.filter((file) => typeof file === "string" && file.trim() !== "") : [];
855
+ const updatedAt = typeof r.updatedAt === "number" && Number.isFinite(r.updatedAt) ? r.updatedAt : 0;
856
+ const items = sanitizeItems(r.items);
857
+ const builtRaw = typeof r.built === "number" && Number.isFinite(r.built) ? Math.trunc(r.built) : 0;
858
+ return {
859
+ state: r.state,
860
+ brief,
861
+ pages,
862
+ files,
863
+ items,
864
+ updatedAt,
865
+ built: Math.min(Math.max(builtRaw, 0), items.length),
866
+ paused: r.paused === true,
867
+ stage: r.stage === "review" ? "review" : "pages",
868
+ dispatched: cleanStep(r.dispatched, items.length),
869
+ lastTurn: cleanTurn(r.lastTurn, items.length),
870
+ prefs: sanitizePrefs(r.prefs),
871
+ decisions: sanitizeDecisions(r.decisions)
872
+ };
873
+ }
874
+ /** The last outline block wins: a retried answer may carry an earlier draft. */
875
+ function parseOutlineBlock(text) {
876
+ let last = null;
877
+ for (const match of text.matchAll(BLOCK_RE)) last = match[1] ?? "";
878
+ if (last === null) return null;
879
+ let parsed;
880
+ try {
881
+ parsed = JSON.parse(last.trim());
882
+ } catch {
883
+ return null;
884
+ }
885
+ const items = sanitizeItems(parsed);
886
+ return items.length >= 2 ? items : null;
887
+ }
888
+ function stripOutlineBlock(text) {
889
+ return text.replace(BLOCK_RE, "").replace(/<lemonriver-outline>[\s\S]*$/i, "").trim();
890
+ }
891
+ const KIND_GUIDE = {
892
+ cover: "cover — the deck title and subtitle",
893
+ kpi: "key figure — one large number with a one-line takeaway",
894
+ chart: "chart — a labelled chart with the point it makes",
895
+ list: "bullet points — a short heading and a few concise points",
896
+ page: "body — a normal content page",
897
+ end: "closing — the last page and what should happen next"
898
+ };
899
+ function pagePrompt(outline, slideId, k) {
900
+ const file = `slides/${slideId}/index.tsx`;
901
+ const page = outline.items[k - 1];
902
+ if (k >= 2 && page) {
903
+ const title = page.title || "(untitled)";
904
+ return [`Page ${k} of ${outline.items.length}: [${page.kind}] ${title}. Write only this page; leave the others as they are.`, ...prefsLines(outline.prefs, "page")].join("\n");
905
+ }
906
+ const list = outline.items.map((item, i) => `${i + 1}. [${item.kind}] ${item.title || "(untitled)"}`).join("\n");
907
+ return [
908
+ `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:`,
909
+ list,
910
+ "Page kinds and how to write them:",
911
+ ...PAGE_KINDS.map((kind) => `- ${KIND_GUIDE[kind]}`),
912
+ "Numbers from the reference files stay exactly as written there.",
913
+ ...prefsLines(outline.prefs, "page")
914
+ ].join("\n");
915
+ }
916
+ function reviewPrompt(outline, slideId) {
917
+ const lines = [
918
+ `All ${outline.items.length} pages are written.`,
919
+ `Check each page of slides/${slideId}/index.tsx against the outline and the reference files in slides/${slideId}/assets/:`,
920
+ "fix typos and any number that differs from the files."
921
+ ];
922
+ if (outline.prefs.askOnMismatch) lines.push("If two files give different numbers for the same thing, ask the user which to use before changing it.");
923
+ lines.push("Do not add or remove pages.", ...prefsLines(outline.prefs, "review"));
924
+ return lines.join(" ");
925
+ }
926
+ /** Both the build button and a "direct" outline start from a ready record. */
927
+ function beginBuild(outline, now) {
928
+ return {
929
+ ...outline,
930
+ state: "building",
931
+ built: 0,
932
+ paused: false,
933
+ stage: "pages",
934
+ dispatched: null,
935
+ lastTurn: null,
936
+ updatedAt: now
937
+ };
938
+ }
939
+ function nextStep(outline) {
940
+ if (outline.state !== "building") return null;
941
+ if (outline.stage === "review") return { kind: "review" };
942
+ if (outline.built >= outline.items.length) return null;
943
+ return {
944
+ kind: "page",
945
+ n: outline.built + 1
946
+ };
947
+ }
948
+ function afterTurn(outline, turn, now) {
949
+ const dispatched = outline.dispatched;
950
+ if (outline.state !== "building" || !dispatched) return outline;
951
+ if (turn.waitingForAnswer) return outline;
952
+ const lastTurn = {
953
+ kind: dispatched.kind,
954
+ n: dispatched.n,
955
+ ok: turn.ok,
956
+ at: now
957
+ };
958
+ if (!turn.ok) return {
959
+ ...outline,
960
+ dispatched: null,
961
+ lastTurn,
962
+ updatedAt: now
963
+ };
964
+ if (dispatched.kind === "review") return {
965
+ ...outline,
966
+ state: "built",
967
+ dispatched: null,
968
+ lastTurn,
969
+ updatedAt: now
970
+ };
971
+ const last = dispatched.n >= outline.items.length;
972
+ return {
973
+ ...outline,
974
+ built: dispatched.n,
975
+ stage: last ? "review" : outline.stage,
976
+ paused: last ? false : outline.prefs.confirmEachPage || outline.paused,
977
+ dispatched: null,
978
+ lastTurn,
979
+ updatedAt: now
980
+ };
981
+ }
982
+ //#endregion
983
+ //#region src/lemonriver/outline/routes.ts
984
+ function startOutline(input, now) {
985
+ const brief = typeof input.brief === "string" ? input.brief.trim().slice(0, MAX_BRIEF) : "";
986
+ const files = Array.isArray(input.files) ? input.files.filter((file) => typeof file === "string" && file.trim() !== "") : [];
987
+ return {
988
+ state: "drafting",
989
+ brief,
990
+ pages: OUTLINE_PAGE_SIZES.find((size) => size === input.pages) ?? 8,
991
+ files,
992
+ items: [],
993
+ updatedAt: now,
994
+ built: 0,
995
+ paused: false,
996
+ stage: "pages",
997
+ dispatched: null,
998
+ lastTurn: null,
999
+ prefs: sanitizePrefs(input.prefs),
1000
+ decisions: []
1001
+ };
1002
+ }
1003
+ /** Only a ready outline may be edited: while drafting the agent owns the list. */
1004
+ function replaceItems(outline, rawItems, now) {
1005
+ if (outline.state !== "ready") return null;
1006
+ return sanitizeOutline({
1007
+ ...outline,
1008
+ items: rawItems,
1009
+ updatedAt: now
1010
+ });
1011
+ }
1012
+ /** Claims the next page (or the review) for this tab. Null means another tab is ahead. */
1013
+ function claimNextStep(outline, input) {
1014
+ if (outline.state !== "building") return null;
1015
+ const base = input.resume ? {
1016
+ ...outline,
1017
+ paused: false,
1018
+ dispatched: null
1019
+ } : outline;
1020
+ if (base.paused) return null;
1021
+ if (base.dispatched && input.now - base.dispatched.at < 3e4) return null;
1022
+ const step = nextStep(base);
1023
+ if (!step) return null;
1024
+ return {
1025
+ outline: {
1026
+ ...base,
1027
+ dispatched: {
1028
+ kind: step.kind,
1029
+ n: step.kind === "page" ? step.n : 0,
1030
+ at: input.now
1031
+ },
1032
+ updatedAt: input.now
1033
+ },
1034
+ step
1035
+ };
1036
+ }
1037
+ function setPaused(outline, paused, now) {
1038
+ return {
1039
+ ...outline,
1040
+ paused,
1041
+ updatedAt: now
1042
+ };
1043
+ }
1044
+ function undoBuild(outline, now) {
1045
+ if (outline.state !== "built") return null;
1046
+ return {
1047
+ ...outline,
1048
+ state: "ready",
1049
+ built: 0,
1050
+ paused: false,
1051
+ stage: "pages",
1052
+ dispatched: null,
1053
+ lastTurn: null,
1054
+ updatedAt: now
1055
+ };
1056
+ }
1057
+ async function readOutline(ctx, slideId) {
1058
+ return sanitizeOutline((await readBoardFile(boardStructurePath(ctx.userCwd, slideId))).outline);
1059
+ }
1060
+ function registerOutlineRoutes(server, ctx) {
1061
+ server.middlewares.use("/__lr/outline", async (req, res, next) => {
1062
+ const url = new URL(req.url ?? "/", "http://local");
1063
+ const method = req.method ?? "GET";
1064
+ try {
1065
+ if (method === "GET" && url.pathname === "/") {
1066
+ const slideId = url.searchParams.get("slideId") ?? "";
1067
+ if (!resolveSlideEntryPath(ctx, slideId)) return json(res, 400, { error: "invalid slideId" });
1068
+ return json(res, 200, { outline: await readOutline(ctx, slideId) });
1069
+ }
1070
+ if (method === "PUT" && url.pathname === "/") {
1071
+ const requestCheck = validateMutationRequest(req, { requireJsonBody: true });
1072
+ if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
1073
+ const body = await readBody(req);
1074
+ const slideId = typeof body.slideId === "string" ? body.slideId : "";
1075
+ if (!resolveSlideEntryPath(ctx, slideId)) return json(res, 400, { error: "invalid slideId" });
1076
+ const outline = await readOutline(ctx, slideId);
1077
+ const next = outline ? replaceItems(outline, body.items, Date.now()) : null;
1078
+ if (!next) return json(res, 409, { error: "outline is not ready" });
1079
+ await updateBoardFile(boardStructurePath(ctx.userCwd, slideId), { outline: next });
1080
+ return json(res, 200, {
1081
+ ok: true,
1082
+ outline: next
1083
+ });
1084
+ }
1085
+ if (method === "POST" && url.pathname === "/start") {
1086
+ const requestCheck = validateMutationRequest(req, { requireJsonBody: true });
1087
+ if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
1088
+ const body = await readBody(req);
1089
+ const slideId = typeof body.slideId === "string" ? body.slideId : "";
1090
+ if (!resolveSlideEntryPath(ctx, slideId)) return json(res, 400, { error: "invalid slideId" });
1091
+ await updateBoardFile(boardStructurePath(ctx.userCwd, slideId), { outline: startOutline(body, Date.now()) });
1092
+ return json(res, 200, { ok: true });
1093
+ }
1094
+ if (method === "POST" && url.pathname === "/build") {
1095
+ const requestCheck = validateMutationRequest(req, { requireJsonBody: true });
1096
+ if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
1097
+ const body = await readBody(req);
1098
+ const slideId = typeof body.slideId === "string" ? body.slideId : "";
1099
+ const entry = resolveSlideEntryPath(ctx, slideId);
1100
+ if (!entry) return json(res, 400, { error: "invalid slideId" });
1101
+ const file = boardStructurePath(ctx.userCwd, slideId);
1102
+ const outline = sanitizeOutline((await readBoardFile(file)).outline);
1103
+ if (outline?.state !== "ready") return json(res, 409, { error: "outline is not ready" });
1104
+ const withPrefs = body.prefs === void 0 ? outline : {
1105
+ ...outline,
1106
+ prefs: sanitizePrefs(body.prefs)
1107
+ };
1108
+ const buildBackup = await readSlideSource(entry) ?? "";
1109
+ await updateBoardFile(file, {
1110
+ outline: beginBuild(withPrefs, Date.now()),
1111
+ buildBackup
1112
+ });
1113
+ return json(res, 200, { ok: true });
1114
+ }
1115
+ if (method === "POST" && url.pathname === "/next") {
1116
+ const requestCheck = validateMutationRequest(req, { requireJsonBody: true });
1117
+ if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
1118
+ const body = await readBody(req);
1119
+ const slideId = typeof body.slideId === "string" ? body.slideId : "";
1120
+ if (!resolveSlideEntryPath(ctx, slideId)) return json(res, 400, { error: "invalid slideId" });
1121
+ const outline = await readOutline(ctx, slideId);
1122
+ if (!outline) return json(res, 409, { error: "no outline" });
1123
+ const claimed = claimNextStep(outline, {
1124
+ resume: body.resume === true,
1125
+ now: Date.now()
1126
+ });
1127
+ if (!claimed) return json(res, 409, { error: "no step to send" });
1128
+ await updateBoardFile(boardStructurePath(ctx.userCwd, slideId), { outline: claimed.outline });
1129
+ const prompt = claimed.step.kind === "review" ? reviewPrompt(outline, slideId) : pagePrompt(outline, slideId, claimed.step.n);
1130
+ return json(res, 200, {
1131
+ prompt,
1132
+ step: claimed.step
1133
+ });
1134
+ }
1135
+ if (method === "POST" && url.pathname === "/pause") {
1136
+ const requestCheck = validateMutationRequest(req, { requireJsonBody: true });
1137
+ if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
1138
+ const body = await readBody(req);
1139
+ const slideId = typeof body.slideId === "string" ? body.slideId : "";
1140
+ if (!resolveSlideEntryPath(ctx, slideId)) return json(res, 400, { error: "invalid slideId" });
1141
+ const outline = await readOutline(ctx, slideId);
1142
+ if (!outline) return json(res, 409, { error: "no outline" });
1143
+ const next = setPaused(outline, body.paused === true, Date.now());
1144
+ await updateBoardFile(boardStructurePath(ctx.userCwd, slideId), { outline: next });
1145
+ return json(res, 200, {
1146
+ ok: true,
1147
+ outline: next
1148
+ });
1149
+ }
1150
+ if (method === "POST" && url.pathname === "/undo") {
1151
+ const requestCheck = validateMutationRequest(req, { requireJsonBody: true });
1152
+ if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
1153
+ const body = await readBody(req);
1154
+ const slideId = typeof body.slideId === "string" ? body.slideId : "";
1155
+ const entry = resolveSlideEntryPath(ctx, slideId);
1156
+ if (!entry) return json(res, 400, { error: "invalid slideId" });
1157
+ const file = boardStructurePath(ctx.userCwd, slideId);
1158
+ const stored = await readBoardFile(file);
1159
+ const outline = sanitizeOutline(stored.outline);
1160
+ const backup = stored.buildBackup;
1161
+ if (!outline || typeof backup !== "string") return json(res, 409, { error: "nothing to undo" });
1162
+ const next = undoBuild(outline, Date.now());
1163
+ if (!next) return json(res, 409, { error: "nothing to undo" });
1164
+ await fs.writeFile(entry, backup, "utf8");
1165
+ await updateBoardFile(file, {
1166
+ outline: next,
1167
+ buildBackup: void 0
1168
+ });
1169
+ return json(res, 200, { ok: true });
1170
+ }
1171
+ next();
1172
+ } catch (err) {
1173
+ json(res, 500, { error: String(err.message ?? err) });
1174
+ }
1175
+ });
1176
+ }
1177
+ //#endregion
588
1178
  //#region src/vite/recent-writes.ts
589
1179
  const recentWrites = /* @__PURE__ */ new Map();
590
1180
  /** Record that `file` was just written by us. */
@@ -1148,8 +1738,13 @@ function registerLemonRiverRoutes(server, ctx) {
1148
1738
  registerBoardRoutes(server, ctx);
1149
1739
  registerTrashRoutes(server, ctx);
1150
1740
  registerDeckRoutes(server, ctx);
1741
+ registerOutlineRoutes(server, ctx);
1151
1742
  }
1152
1743
  //#endregion
1744
+ //#region src/app/lemonriver/outline/rule.ts
1745
+ /** Added to the agent's standing instructions so an outline turn stays words only. */
1746
+ const OUTLINE_RULE = "When a message asks for an outline only, do not write or edit any slide file in that turn.";
1747
+ //#endregion
1153
1748
  //#region src/editing/placeholder-id.ts
1154
1749
  const UNTITLED_SLIDE_ID_RE = /^untitled(-\d+)?$/;
1155
1750
  //#endregion
@@ -1224,6 +1819,7 @@ function systemPromptAppend(askInstruction) {
1224
1819
  "The workspace is a LemonRiver project: decks live under slides/<id>/index.tsx and the dev server hot-reloads every edit, so the user sees changes immediately.",
1225
1820
  "Use the project skills: create-slide to draft a new deck, apply-comments to resolve @slide-comment markers left by the inspector, create-theme for themes, and slide-authoring as the technical reference before writing a page.",
1226
1821
  PAGE_BY_PAGE,
1822
+ OUTLINE_RULE,
1227
1823
  "Keep replies short and concrete: the panel is narrow. Prefer doing the work over describing it, and finish with a one-line summary of what changed.",
1228
1824
  askInstruction
1229
1825
  ].join(" ");
@@ -2599,6 +3195,99 @@ function installSdk(packageManager, pkg, cwd) {
2599
3195
  return runCommand(installCommandFor(packageManager, pkg), cwd, INSTALL_TIMEOUT_MS);
2600
3196
  }
2601
3197
  //#endregion
3198
+ //#region src/lemonriver/outline/turn-end.ts
3199
+ /**
3200
+ * Turns the agent's last reply into the board's outline, and once the deck is
3201
+ * being built, its page titles back into the board's cards. Both live in the
3202
+ * same file, so the outline stays the single source the board shows.
3203
+ */
3204
+ async function collectOutline(ctx, store, sessionId, userItemId) {
3205
+ const session = store.get(sessionId);
3206
+ const slideId = session?.slideId;
3207
+ if (!session || !slideId) return;
3208
+ const file = boardStructurePath(ctx.userCwd, slideId);
3209
+ const stored = await readBoardFile(file);
3210
+ const outline = sanitizeOutline(stored.outline);
3211
+ if (!outline) return;
3212
+ const now = Date.now();
3213
+ if (outline.state === "drafting") {
3214
+ const start = session.items.findIndex((item) => item.id === userItemId);
3215
+ let found = null;
3216
+ for (const item of session.items.slice(start + 1)) {
3217
+ if (item.kind !== "assistant") continue;
3218
+ const parsed = parseOutlineBlock(item.text);
3219
+ if (!parsed) continue;
3220
+ found = parsed;
3221
+ store.updateItem(sessionId, item.id, "assistant", { text: stripOutlineBlock(item.text) });
3222
+ }
3223
+ if (!found) {
3224
+ await updateBoardFile(file, { outline: {
3225
+ ...outline,
3226
+ state: "failed",
3227
+ updatedAt: now
3228
+ } });
3229
+ return;
3230
+ }
3231
+ const ready = {
3232
+ ...outline,
3233
+ state: "ready",
3234
+ items: found,
3235
+ updatedAt: now
3236
+ };
3237
+ if (ready.prefs.outline !== "direct") {
3238
+ await updateBoardFile(file, { outline: ready });
3239
+ return;
3240
+ }
3241
+ const entry = resolveSlideEntry(ctx.slidesRoot, slideId);
3242
+ const buildBackup = entry ? await readSlideSource(entry) ?? "" : "";
3243
+ await updateBoardFile(file, {
3244
+ outline: beginBuild(ready, now),
3245
+ buildBackup
3246
+ });
3247
+ return;
3248
+ }
3249
+ if (outline.state !== "building") return;
3250
+ if (!outline.dispatched) return;
3251
+ const start = session.items.findIndex((item) => item.id === userItemId);
3252
+ const after = start === -1 ? [] : session.items.slice(start + 1);
3253
+ const last = session.items.at(-1);
3254
+ const waitingForAnswer = last?.kind === "question" && last.status === "pending";
3255
+ const lastResult = [...after].reverse().find((item) => item.kind === "result");
3256
+ const ok = !after.some((item) => item.kind === "error") && !(lastResult?.kind === "result" && lastResult.aborted);
3257
+ const decisions = outline.stage === "review" ? collectDecisions(outline.decisions, session.items) : outline.decisions;
3258
+ const grown = decisions.length !== outline.decisions.length;
3259
+ const base = grown ? {
3260
+ ...outline,
3261
+ decisions
3262
+ } : outline;
3263
+ const next = afterTurn(base, {
3264
+ ok,
3265
+ waitingForAnswer
3266
+ }, now);
3267
+ if (next === base && !grown) return;
3268
+ if (next.state !== "built") {
3269
+ await updateBoardFile(file, { outline: next });
3270
+ return;
3271
+ }
3272
+ const entry = resolveSlideEntry(ctx.slidesRoot, slideId);
3273
+ const source = entry ? await readSlideSource(entry) : null;
3274
+ const entries = source ? defaultExportEntriesInSource(source) : null;
3275
+ if (!entries || entries.length !== outline.items.length) {
3276
+ await updateBoardFile(file, { outline: next });
3277
+ return;
3278
+ }
3279
+ const keys = pageKeys(entries, outline.items.length);
3280
+ let cards = sanitizeCards(stored.cards);
3281
+ outline.items.forEach((item, index) => {
3282
+ const title = item.title.trim();
3283
+ if (title) cards = patchCard(cards, keys[index], { title });
3284
+ });
3285
+ await updateBoardFile(file, {
3286
+ outline: next,
3287
+ cards
3288
+ });
3289
+ }
3290
+ //#endregion
2602
3291
  //#region src/vite/routes/agent.ts
2603
3292
  function parseContext(raw) {
2604
3293
  if (!raw || typeof raw !== "object") return void 0;
@@ -2656,6 +3345,7 @@ async function renamePlaceholderDeck(server, ctx, store, broadcast, turn) {
2656
3345
  recordWrite(entry);
2657
3346
  const renamed = await renameSlideDir(ctx.slidesRoot, slideId, desired);
2658
3347
  if (!renamed.ok) return;
3348
+ await moveBoardRecord(ctx.userCwd, slideId, renamed.slideId);
2659
3349
  recordWrite(path.join(renamed.to, "index.tsx"));
2660
3350
  const manifest = await readManifest(ctx.manifestPath);
2661
3351
  const folderId = manifest.assignments[slideId];
@@ -2711,7 +3401,10 @@ function registerAgentRoutes(server, ctx) {
2711
3401
  writableRoots: [ctx.slidesRoot, ctx.globalAssetsRoot],
2712
3402
  store,
2713
3403
  providers,
2714
- onTurnEnd: (turn) => renamePlaceholderDeck(server, ctx, store, broadcast, turn)
3404
+ onTurnEnd: async (turn) => {
3405
+ await collectOutline(ctx, store, turn.sessionId, turn.userItemId);
3406
+ await renamePlaceholderDeck(server, ctx, store, broadcast, turn);
3407
+ }
2715
3408
  });
2716
3409
  store.subscribe(broadcast);
2717
3410
  server.httpServer?.on("close", () => {
@@ -5071,6 +5764,8 @@ function registerSlideRoutes(server, ctx) {
5071
5764
  const requestCheck = validateMutationRequest(req);
5072
5765
  if (!requestCheck.ok) return json(res, requestCheck.status, { error: requestCheck.error });
5073
5766
  if (!await rmSlideDir(ctx.slidesRoot, slideId)) return json(res, 404, { error: "slide not found" });
5767
+ invalidateSlidesModule(server);
5768
+ server.ws.send({ type: "full-reload" });
5074
5769
  const manifest = await readManifest(ctx.manifestPath);
5075
5770
  delete manifest.assignments[slideId];
5076
5771
  await writeManifest(ctx.manifestPath, manifest);