Skip to content

Commit 4d68a92

Browse files
committed
fix: app 的指引真的发到模型了 —— 之前只到 scenarios.ts 为止
instructionsFor 对非 html 项目直接返回 INSTRUCTIONS + NOTES,scenario 指引 只拼给页面项目;scenarioOf 对 next 项目干脆返回 null。于是'数据库助手、 组件库在 @/components/ui'这些指引写在 scenarios.ts 里、被 check 断言着, 却从来没进过任何一个 app turn 的 prompt。表里有 ≠ 送达。 两处接线:next 项目的 scenario 按构造就是 'app'(唯一的 next 类型), scenarioOf 返回它;instructionsFor 把 scenario 指引拼进所有项目类型, 不再只拼 html。 spec 直接读发货的 prompt:instructionsFor('next','app') 必须含 @/lib/db 和 @/components/ui;无 scenario 的旧项目保持干净。
1 parent 813fe85 commit 4d68a92

3 files changed

Lines changed: 34 additions & 8 deletions

File tree

‎backend/src/chat/__tests__/instructions.spec.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ describe('assembled html instructions', () => {
4646
});
4747
});
4848

49+
/**
50+
* The app scenario's guidance must actually ship. It was written into
51+
* scenarios.ts and asserted there — and instructionsFor dropped it for every
52+
* non-html project, so the prompt said nothing about the database helper or
53+
* the component library. Presence in the table is not delivery; this reads
54+
* the prompt itself.
55+
*/
56+
describe('app scenario guidance', () => {
57+
it('ships with an app turn', () => {
58+
const prompt = instructionsFor('next', 'app');
59+
expect(prompt).toContain('@/lib/db');
60+
expect(prompt).toContain('@/components/ui');
61+
});
62+
63+
it('stays absent for legacy projects with no scenario', () => {
64+
expect(instructionsFor('next', null)).not.toContain('@/lib/db');
65+
expect(instructionsFor(null, null)).not.toContain('@/lib/db');
66+
});
67+
});
68+
4969
/**
5070
* The replay window is 20 turns. NOTES.md is the only thing that outlives it,
5171
* so both kinds have to be told to keep it — a Next project forgets its

‎backend/src/chat/chat.controller.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,19 @@ export class ChatController {
116116
}
117117

118118
/**
119-
* What the user said they were making, from the page's own meta tag.
119+
* What the user said they were making.
120120
*
121-
* Stored in the file rather than a column: the same trick the design system
122-
* uses, and it means no migration and no DB_SYNCHRONIZE deploy. Null for a
123-
* Next app or a page scaffolded before scenarios existed — the agent then
124-
* gets its plain instructions, which is what it had all along.
121+
* Page projects carry it in the page's own meta tag — a file, like the
122+
* design tokens: no column, no migration, no DB_SYNCHRONIZE deploy. A Next
123+
* app is the 'app' scenario by construction (it is the only next kind
124+
* today), and its guidance is exactly what a turn needs: the database
125+
* helper and the component library only help if the model is told.
125126
*/
126127
private async scenarioOf(project: {
127128
projectPath: string;
128129
template?: string | null;
129130
}): Promise<string | null> {
131+
if (project.template === 'next') return 'app';
130132
if (project.template !== 'html') return null;
131133
try {
132134
const workspace = await this.workspaces.for(project.projectPath);

‎backend/src/chat/instructions.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,14 @@ export const instructionsFor = (
9292
template?: string | null,
9393
scenarioId?: string | null,
9494
): string => {
95-
if (template !== 'html') return `${INSTRUCTIONS}\n\n${NOTES_SECTION}`;
96-
// What the user said they were making, so the agent builds that shape
97-
// rather than defaulting every project to a centered hero.
95+
// The scenario's guidance rides every turn, whichever kind of project it
96+
// is. It used to be html-only: the app guidance (the database helper, the
97+
// component library) was written, tested for presence, and never shipped
98+
// to the model — a next project's prompt said nothing about either.
9899
const shape = scenarioId ? scenario(scenarioId).guidance : '';
100+
if (template !== 'html') {
101+
return [INSTRUCTIONS, shape, NOTES_SECTION].filter(Boolean).join('\n\n');
102+
}
99103
// STYLE_SECTION after PLAN_SECTION, not before: PLAN_SECTION carries its
100104
// own question example using `"id":"style"` with free-text options, and a
101105
// model copies the nearest example. Ordered the other way the style rules

0 commit comments

Comments
 (0)