narrarium-engine 0.1.21 → 0.1.22

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 (60) hide show
  1. package/README.md +21 -0
  2. package/dist/autopilot/campaign.d.ts +101 -0
  3. package/dist/autopilot/campaign.d.ts.map +1 -0
  4. package/dist/autopilot/campaign.js +260 -0
  5. package/dist/autopilot/campaign.js.map +1 -0
  6. package/dist/autopilot/frozen.d.ts +27 -2
  7. package/dist/autopilot/frozen.d.ts.map +1 -1
  8. package/dist/autopilot/frozen.js +91 -25
  9. package/dist/autopilot/frozen.js.map +1 -1
  10. package/dist/autopilot/planner.d.ts.map +1 -1
  11. package/dist/autopilot/planner.js +5 -2
  12. package/dist/autopilot/planner.js.map +1 -1
  13. package/dist/autopilot/runner.d.ts +5 -3
  14. package/dist/autopilot/runner.d.ts.map +1 -1
  15. package/dist/autopilot/runner.js +27 -8
  16. package/dist/autopilot/runner.js.map +1 -1
  17. package/dist/autopilot/session.d.ts +11 -0
  18. package/dist/autopilot/session.d.ts.map +1 -1
  19. package/dist/autopilot/session.js +32 -0
  20. package/dist/autopilot/session.js.map +1 -1
  21. package/dist/autopilot/state.d.ts +8 -1
  22. package/dist/autopilot/state.d.ts.map +1 -1
  23. package/dist/autopilot/state.js +69 -1
  24. package/dist/autopilot/state.js.map +1 -1
  25. package/dist/autopilot/tasks.d.ts.map +1 -1
  26. package/dist/autopilot/tasks.js +27 -6
  27. package/dist/autopilot/tasks.js.map +1 -1
  28. package/dist/autopilot/types.d.ts +68 -1
  29. package/dist/autopilot/types.d.ts.map +1 -1
  30. package/dist/autopilot/types.js +3 -0
  31. package/dist/autopilot/types.js.map +1 -1
  32. package/dist/book/outline-journal.d.ts +149 -0
  33. package/dist/book/outline-journal.d.ts.map +1 -0
  34. package/dist/book/outline-journal.js +321 -0
  35. package/dist/book/outline-journal.js.map +1 -0
  36. package/dist/book/outline.js +3 -3
  37. package/dist/book/outline.js.map +1 -1
  38. package/dist/book/paths.d.ts +7 -0
  39. package/dist/book/paths.d.ts.map +1 -1
  40. package/dist/book/paths.js +7 -0
  41. package/dist/book/paths.js.map +1 -1
  42. package/dist/index.d.ts +2 -0
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +2 -0
  45. package/dist/index.js.map +1 -1
  46. package/dist/server/client.d.ts +10 -1
  47. package/dist/server/client.d.ts.map +1 -1
  48. package/dist/server/client.js +20 -1
  49. package/dist/server/client.js.map +1 -1
  50. package/dist/server/protocol.d.ts +16 -0
  51. package/dist/server/protocol.d.ts.map +1 -1
  52. package/dist/server/protocol.js +12 -0
  53. package/dist/server/protocol.js.map +1 -1
  54. package/dist/sync/files.d.ts +12 -0
  55. package/dist/sync/files.d.ts.map +1 -1
  56. package/dist/sync/files.js +40 -2
  57. package/dist/sync/files.js.map +1 -1
  58. package/dist/version.d.ts +1 -1
  59. package/dist/version.js +1 -1
  60. package/package.json +1 -1
@@ -1,9 +1,10 @@
1
1
  import { normalizeScore, requireStructuredFields, splitReasoningBlock } from "../ai/structured.js";
2
2
  import { AI_CAPABILITIES, AiReplyRejectedError } from "../ai/types.js";
3
3
  import { canonDetails, canonManifest, ghostwriterBlock, isThinDocument, loadChapterParagraphs, loadGhostwriter, markedChapterText, mentionedCanon, readBody, readDocument, secretRules, } from "../book/context.js";
4
- import { AUTOPILOT_PLAN_FILE, BOOK_FILE, CONTEXT_FILE, OUTLINE_BOOK_FILE, PLOT_FILE, STORY_DESIGN_FILE, TOTAL_RESUME_FILE, canonPath, canonSlug, chapterFilePath, chapterResumePath, chapterSlug, directorOpinionPath, formatOrdinal, isValidGhostwriterSlug, outlineChapterPath, paragraphFilePath, paragraphId, paragraphSlug, readerEvaluationPath, readerSummaryPath, } from "../book/paths.js";
4
+ import { AUTOPILOT_PLAN_FILE, BOOK_FILE, CONTEXT_FILE, OUTLINE_BOOK_FILE, OUTLINE_CHANGES_FILE, PLOT_FILE, STORY_DESIGN_FILE, TOTAL_RESUME_FILE, canonPath, canonSlug, chapterFilePath, chapterResumePath, chapterSlug, directorOpinionPath, formatOrdinal, isValidGhostwriterSlug, outlineChapterPath, paragraphFilePath, paragraphId, paragraphSlug, readerEvaluationPath, readerSummaryPath, } from "../book/paths.js";
5
5
  import { chapterFreezeRecord, freezeChapterChanges, frozenChanges, markReviewedChanges } from "../book/freeze.js";
6
6
  import { OUTLINE_TITLE_MAX_CHARS, OutlineReader, outlineBookDigest, outlineEntryDigest, serializeOutlineBook, serializeOutlineChapter } from "../book/outline.js";
7
+ import { appendOutlineJournal, outlineJournalChaptersOf } from "../book/outline-journal.js";
7
8
  import { askDirector, directorSystemPrompt, parseDirectorVerdict, renderDirectorOpinion, withheldApprovalNote } from "../director/opinion.js";
8
9
  import { assertFrontmatterReadable, frontmatterString, parseMarkdown, renderMarkdown } from "../markdown/frontmatter.js";
9
10
  import { evaluationStyleBlock, evaluationStyleInstruction } from "../profiles/evaluation-style.js";
@@ -191,14 +192,18 @@ function outlineContentOf(chapter) {
191
192
  * The outline after a plan: a planned chapter without an entry gets one, as the autopilot's (`origin: autopilot`, with the `digest`
192
193
  * of what it wrote); a chapter the author wrote gets one only when it has none, with its summary; an entry of the autopilot that
193
194
  * nobody touched follows the new plan of its chapter; an entry of the author is never touched. Every chapter remembers the digest
194
- * of its entry as it is after this step, so that a later change of the author is recognized. With `fillOutline` off nothing is
195
- * written. `outline/book.md` is written once, when it is missing, with the logline of the concept.
195
+ * of its entry as it is after this step, so that a later change of the author is recognized; a written chapter the plan knew keeps
196
+ * the digest it followed, so that a change nobody decided about yet is not taken for followed. With `fillOutline` off nothing is
197
+ * written. `outline/book.md` is written once, when it is missing, with the logline of the concept. The entries it writes are a series
198
+ * of the journal of the Synopsis (`outline/changes.yml`), by the autopilot, in the same commit.
196
199
  */
197
200
  async function fillOutline(ctx, planned, imported) {
198
201
  const fill = ctx.state.options.fillOutline !== false;
199
202
  const outline = outlineOf(ctx);
200
203
  const entries = new Map((await outline.chapters()).map((entry) => [entry.number, entry]));
201
204
  const changes = [];
205
+ const was = new Map();
206
+ const now = new Map();
202
207
  const write = async (chapter, existing) => {
203
208
  const content = outlineContentOf(chapter);
204
209
  const digest = await outlineEntryDigest(content);
@@ -208,13 +213,16 @@ async function fillOutline(ctx, planned, imported) {
208
213
  content: serializeOutlineChapter({ number: chapter.number, ...content, origin: "autopilot", digest, frontmatter: existing?.frontmatter }),
209
214
  expectedHash: existing ? existing.hash : null,
210
215
  });
216
+ if (existing)
217
+ was.set(chapter.number, { title: existing.title, digest: existing.contentDigest });
218
+ now.set(chapter.number, { title: content.title, digest });
211
219
  }
212
220
  chapter.outlineDigest = digest;
213
221
  };
214
222
  for (const chapter of imported) {
215
223
  const entry = entries.get(chapter.number);
216
224
  if (entry)
217
- chapter.outlineDigest = entry.contentDigest;
225
+ chapter.outlineDigest ??= entry.contentDigest;
218
226
  else if (fill && chapter.summary.trim())
219
227
  await write(chapter);
220
228
  else
@@ -234,6 +242,17 @@ async function fillOutline(ctx, planned, imported) {
234
242
  if (body)
235
243
  changes.push({ path: OUTLINE_BOOK_FILE, content: serializeOutlineBook({ body, origin: "autopilot", digest: await outlineBookDigest({ body }) }), expectedHash: null });
236
244
  }
245
+ const { chapters, more } = outlineJournalChaptersOf(was, now, ctx.language);
246
+ if (chapters.length) {
247
+ const journal = await ctx.store.read(OUTLINE_CHANGES_FILE);
248
+ const at = ctx.now();
249
+ changes.push({
250
+ path: OUTLINE_CHANGES_FILE,
251
+ // The id comes from the moment of the step: one runner writes at a time, and a run with a fixed clock writes the same file.
252
+ content: appendOutlineJournal(journal?.content, { id: `autopilot-${at.getTime().toString(36)}`, at: at.toISOString(), by: "autopilot", chapters, ...(more ? { more } : {}) }, at),
253
+ expectedHash: journal?.hash ?? null,
254
+ });
255
+ }
237
256
  return changes;
238
257
  }
239
258
  /** The style a step that judges is given, among the data, and the instruction to judge with it; nothing without a style. */
@@ -660,8 +679,10 @@ async function runPlan(ctx) {
660
679
  const imported = importedChapters(ctx.snapshot).map((chapter) => {
661
680
  const earlier = known.get(chapter.slug);
662
681
  const kept = earlier?.storySoFarAtClose ? { ...chapter, storySoFarAtClose: earlier.storySoFarAtClose, ...(earlier.score !== undefined ? { score: earlier.score } : {}) } : chapter;
663
- // The history of the rounds of a chapter that was reviewed outlives the plan being made again around it (the book is being extended).
664
- return earlier?.rounds?.length ? { ...kept, rounds: earlier.rounds } : kept;
682
+ // The history of the rounds of a chapter that was reviewed outlives the plan being made again around it (the book is being extended), and so does the
683
+ // entry of the outline it follows: a change of its entry that nobody decided about yet (asked, left for later) is still one after the plan.
684
+ const followed = earlier?.outlineDigest ? { ...kept, outlineDigest: earlier.outlineDigest } : kept;
685
+ return earlier?.rounds?.length ? { ...followed, rounds: earlier.rounds } : followed;
665
686
  });
666
687
  // The author's outline binds the plan: its chapters, its order, its titles, its events, and as many chapters as it has.
667
688
  const view = await authorOutline(ctx);