|
@@ -2,6 +2,7 @@ import type { AgentMessage } from "@mariozechner/pi-agent-core";
|
|
|
import type { UserMessage } from "@mariozechner/pi-ai";
|
|
import type { UserMessage } from "@mariozechner/pi-ai";
|
|
|
import { readdir, readFile } from "node:fs/promises";
|
|
import { readdir, readFile } from "node:fs/promises";
|
|
|
import { join } from "node:path";
|
|
import { join } from "node:path";
|
|
|
|
|
+import { isNewLayoutBook } from "../utils/outline-paths.js";
|
|
|
|
|
|
|
|
/** Files read in this order; anything else in story/ comes after, sorted alphabetically. */
|
|
/** Files read in this order; anything else in story/ comes after, sorted alphabetically. */
|
|
|
const PRIORITY_FILES = [
|
|
const PRIORITY_FILES = [
|
|
@@ -11,6 +12,12 @@ const PRIORITY_FILES = [
|
|
|
"current_focus.md",
|
|
"current_focus.md",
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
|
|
+const UPGRADE_HINT =
|
|
|
|
|
+ "[提示] 当前这本书的架构稿是旧的条目式格式(story_bible.md / volume_outline.md / character_matrix.md)。" +
|
|
|
|
|
+ "如果作者有意愿升级成段落式架构稿 + 一人一卡的角色目录(outline/story_frame.md + outline/volume_map.md + roles/)," +
|
|
|
|
|
+ "可以调用 `sub_agent(architect, { revise: true, bookId, feedback: \"把架构稿从条目式升级成段落式架构稿,并把角色矩阵拆成 roles 目录一人一卡\" })`。" +
|
|
|
|
|
+ "升级只改架构稿,不动已写的章节。在作者没明确同意前不要主动触发。";
|
|
|
|
|
+
|
|
|
export function createBookContextTransform(
|
|
export function createBookContextTransform(
|
|
|
bookId: string | null,
|
|
bookId: string | null,
|
|
|
projectRoot: string,
|
|
projectRoot: string,
|
|
@@ -19,14 +26,19 @@ export function createBookContextTransform(
|
|
|
return async (messages) => messages;
|
|
return async (messages) => messages;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const storyDir = join(projectRoot, "books", bookId, "story");
|
|
|
|
|
|
|
+ const bookDir = join(projectRoot, "books", bookId);
|
|
|
|
|
+ const storyDir = join(bookDir, "story");
|
|
|
|
|
|
|
|
return async (messages) => {
|
|
return async (messages) => {
|
|
|
const sections = await readTruthFiles(storyDir);
|
|
const sections = await readTruthFiles(storyDir);
|
|
|
if (sections.length === 0) return messages;
|
|
if (sections.length === 0) return messages;
|
|
|
|
|
|
|
|
|
|
+ const isNew = await isNewLayoutBook(bookDir);
|
|
|
|
|
+ const hintBlock = isNew ? "" : `\n\n${UPGRADE_HINT}`;
|
|
|
|
|
+
|
|
|
const body =
|
|
const body =
|
|
|
- "[以下是当前书籍的真相文件,每次对话时自动从磁盘读取注入。请基于这些内容进行创作和判断。]\n\n" +
|
|
|
|
|
|
|
+ "[以下是当前书籍的真相文件,每次对话时自动从磁盘读取注入。请基于这些内容进行创作和判断。]" +
|
|
|
|
|
+ hintBlock + "\n\n" +
|
|
|
sections.map((s) => `=== ${s.name} ===\n${s.content}`).join("\n\n");
|
|
sections.map((s) => `=== ${s.name} ===\n${s.content}`).join("\n\n");
|
|
|
|
|
|
|
|
const injected: UserMessage = {
|
|
const injected: UserMessage = {
|