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.
- package/README.md +21 -0
- package/dist/autopilot/campaign.d.ts +101 -0
- package/dist/autopilot/campaign.d.ts.map +1 -0
- package/dist/autopilot/campaign.js +260 -0
- package/dist/autopilot/campaign.js.map +1 -0
- package/dist/autopilot/frozen.d.ts +27 -2
- package/dist/autopilot/frozen.d.ts.map +1 -1
- package/dist/autopilot/frozen.js +91 -25
- package/dist/autopilot/frozen.js.map +1 -1
- package/dist/autopilot/planner.d.ts.map +1 -1
- package/dist/autopilot/planner.js +5 -2
- package/dist/autopilot/planner.js.map +1 -1
- package/dist/autopilot/runner.d.ts +5 -3
- package/dist/autopilot/runner.d.ts.map +1 -1
- package/dist/autopilot/runner.js +27 -8
- package/dist/autopilot/runner.js.map +1 -1
- package/dist/autopilot/session.d.ts +11 -0
- package/dist/autopilot/session.d.ts.map +1 -1
- package/dist/autopilot/session.js +32 -0
- package/dist/autopilot/session.js.map +1 -1
- package/dist/autopilot/state.d.ts +8 -1
- package/dist/autopilot/state.d.ts.map +1 -1
- package/dist/autopilot/state.js +69 -1
- package/dist/autopilot/state.js.map +1 -1
- package/dist/autopilot/tasks.d.ts.map +1 -1
- package/dist/autopilot/tasks.js +27 -6
- package/dist/autopilot/tasks.js.map +1 -1
- package/dist/autopilot/types.d.ts +68 -1
- package/dist/autopilot/types.d.ts.map +1 -1
- package/dist/autopilot/types.js +3 -0
- package/dist/autopilot/types.js.map +1 -1
- package/dist/book/outline-journal.d.ts +149 -0
- package/dist/book/outline-journal.d.ts.map +1 -0
- package/dist/book/outline-journal.js +321 -0
- package/dist/book/outline-journal.js.map +1 -0
- package/dist/book/outline.js +3 -3
- package/dist/book/outline.js.map +1 -1
- package/dist/book/paths.d.ts +7 -0
- package/dist/book/paths.d.ts.map +1 -1
- package/dist/book/paths.js +7 -0
- package/dist/book/paths.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/server/client.d.ts +10 -1
- package/dist/server/client.d.ts.map +1 -1
- package/dist/server/client.js +20 -1
- package/dist/server/client.js.map +1 -1
- package/dist/server/protocol.d.ts +16 -0
- package/dist/server/protocol.d.ts.map +1 -1
- package/dist/server/protocol.js +12 -0
- package/dist/server/protocol.js.map +1 -1
- package/dist/sync/files.d.ts +12 -0
- package/dist/sync/files.d.ts.map +1 -1
- package/dist/sync/files.js +40 -2
- package/dist/sync/files.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/autopilot/tasks.js
CHANGED
|
@@ -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
|
|
195
|
-
*
|
|
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
|
|
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
|
-
|
|
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);
|