Эх сурвалжийг харах

refactor(composer): prefer brief-driven context hints

Ma 7 сар өмнө
parent
commit
2cc92fda2c

+ 1 - 0
packages/core/src/__tests__/composer.test.ts

@@ -626,6 +626,7 @@ describe("ComposerAgent", () => {
           ...plan.intent,
           ...plan.intent,
           chapter: 8,
           chapter: 8,
           goal: "Follow the black ring pressure.",
           goal: "Follow the black ring pressure.",
+          mustKeep: [],
           hookAgenda: {
           hookAgenda: {
             pressureMap: [],
             pressureMap: [],
             mustAdvance: [],
             mustAdvance: [],

+ 18 - 5
packages/core/src/agents/composer.ts

@@ -94,6 +94,7 @@ async function collectSelectedContext(
   plan: PlanChapterOutput,
   plan: PlanChapterOutput,
   language: "zh" | "en",
   language: "zh" | "en",
 ): Promise<ContextPackage["selectedContext"]> {
 ): Promise<ContextPackage["selectedContext"]> {
+    const retrievalHints = deriveRetrievalHints(plan);
     const chapterBriefEntry = plan.brief
     const chapterBriefEntry = plan.brief
       ? [{
       ? [{
           source: "runtime/chapter_brief",
           source: "runtime/chapter_brief",
@@ -118,14 +119,14 @@ async function collectSelectedContext(
       maybeContextSource(
       maybeContextSource(
         storyDir,
         storyDir,
         "current_state.md",
         "current_state.md",
-        "Preserve hard state facts referenced by mustKeep.",
-        plan.intent.mustKeep,
+        "Preserve hard state facts referenced by the active chapter brief or hard constraints.",
+        retrievalHints,
       ),
       ),
       maybeContextSource(
       maybeContextSource(
         storyDir,
         storyDir,
         "story_bible.md",
         "story_bible.md",
-        "Preserve canon constraints referenced by mustKeep.",
-        plan.intent.mustKeep,
+        "Preserve canon constraints referenced by the active chapter brief or hard constraints.",
+        retrievalHints,
       ),
       ),
       maybeContextSource(
       maybeContextSource(
         storyDir,
         storyDir,
@@ -152,7 +153,7 @@ async function collectSelectedContext(
       chapterNumber: plan.intent.chapter,
       chapterNumber: plan.intent.chapter,
       goal: plan.intent.goal,
       goal: plan.intent.goal,
       outlineNode: planningAnchor,
       outlineNode: planningAnchor,
-      mustKeep: plan.intent.mustKeep,
+      mustKeep: retrievalHints,
     });
     });
     const hookDebtEntries = await buildHookDebtEntries(
     const hookDebtEntries = await buildHookDebtEntries(
       storyDir,
       storyDir,
@@ -198,6 +199,18 @@ async function collectSelectedContext(
     ];
     ];
 }
 }
 
 
+function deriveRetrievalHints(plan: PlanChapterOutput): string[] {
+  if (!plan.brief) {
+    return plan.intent.mustKeep;
+  }
+
+  return [
+    ...plan.brief.propsAndSetting,
+    ...plan.brief.hookPlan.flatMap((entry) => [entry.hookId, entry.targetEffect]),
+    plan.brief.goal,
+  ].filter(Boolean);
+}
+
 async function buildRecentChapterTrailEntries(
 async function buildRecentChapterTrailEntries(
   storyDir: string,
   storyDir: string,
   chapterNumber: number,
   chapterNumber: number,