FN-7593: move Before/After Transformation section to top of task definitions

Reorders task-definition prompt templates so the Before -> After Transformation section appears before other sections, making the expected change visible first.

- Move the Before -> After Transformation section ahead of other sections in agent-prompts.ts task-definition templates
- Update docs/task-management.md to reflect the new section order
- Add/extend tests in agent-prompts.test.ts and triage.test.ts covering the new ordering
- Add changeset fn-7593-before-after-top.md documenting the change

Files changed:
 .changeset/fn-7593-before-after-top.md            |  7 +++++++
 docs/task-management.md                           |  2 +-
 packages/core/src/__tests__/agent-prompts.test.ts | 20 ++++++++++++++++++++
 packages/core/src/agent-prompts.ts                | 20 +++++++++++++-------
 packages/engine/src/__tests__/triage.test.ts      | 17 +++++++++++++++++
 5 files changed, 58 insertions(+), 8 deletions(-)

Fusion-Task-Id: FN-7593

Fusion-Task-Lineage: d0d5eb4d-2fe0-456c-b061-5c078b78911b

Co-authored-by: Fusion (runfusion.ai) <noreply@runfusion.ai>
This commit is contained in:
gsxdsm
2026-07-05 13:44:50 -07:00
parent cf3fe8b485
commit f30d55fae7
5 changed files with 58 additions and 8 deletions

View File

@@ -0,0 +1,7 @@
---
"@runfusion/fusion": patch
---
summary: Move the Before → After transformation summary to the top of generated task definitions.
category: fix
dev: Reorders the standard and fast triage `PROMPT.md` templates in packages/core/src/agent-prompts.ts so `## Before → After Transformation` is the first content section, ahead of `## Review Level` and `## Mission`, matching FN-7499's glance-verification intent.

View File

@@ -552,8 +552,8 @@ The task detail modal exposes multiple tabs:
After planning, each task gets a structured `PROMPT.md` with sections like:
- Mission
- Before → after transformation summary
- Mission
- Dependencies
- Context to read first
- File scope

View File

@@ -312,6 +312,26 @@ describe("resolveAgentPrompt", () => {
}
});
it("places the Before → After Transformation section at the top of the definition, ahead of Mission and Review Level (FN-7593)", () => {
const standardPrompt = resolveAgentPrompt("triage");
const fastPrompt = builtinSeamPrompt("planning-fast");
const standardTransformationIdx = standardPrompt.indexOf("## Before → After Transformation");
const standardReviewLevelIdx = standardPrompt.indexOf("## Review Level");
const standardMissionIdx = standardPrompt.indexOf("## Mission");
expect(standardTransformationIdx).toBeGreaterThan(-1);
expect(standardReviewLevelIdx).toBeGreaterThan(-1);
expect(standardMissionIdx).toBeGreaterThan(-1);
expect(standardTransformationIdx).toBeLessThan(standardReviewLevelIdx);
expect(standardTransformationIdx).toBeLessThan(standardMissionIdx);
const fastTransformationIdx = fastPrompt.indexOf("## Before → After Transformation");
const fastMissionIdx = fastPrompt.indexOf("## Mission");
expect(fastTransformationIdx).toBeGreaterThan(-1);
expect(fastMissionIdx).toBeGreaterThan(-1);
expect(fastTransformationIdx).toBeLessThan(fastMissionIdx);
});
it("triage planning prompt is sourced from workflow IR without an engine duplicate", () => {
const corePrompt = resolveAgentPrompt("triage");
const planningPrompt = resolvePlanningPromptFromIr(BUILTIN_CODING_WORKFLOW_IR);

View File

@@ -221,6 +221,9 @@ Keep the prompt lean, but preserve mandatory planning contracts: duplicate searc
FNXC:FastPlanning 2026-07-04-16:25:
Fast mode skips heavyweight planning ceremony, but every generated task still needs the same glanceable Before → After Transformation section as standard planning so operators can validate intent quickly.
FNXC:FastPlanning 2026-07-05-12:00:
Per FN-7593, the transformation summary must sit at the top of the PROMPT.md (before Mission), matching the standard-mode placement, so operators get the same glance-first ordering in fast mode.
*/
const FAST_TRIAGE_PROMPT_TEXT = `You are a task specification agent for "fn". This task is running in **fast mode**.
@@ -235,7 +238,7 @@ Write a lean, executable PROMPT.md quickly. Preserve safety gates, but skip heav
Before writing a spec, call \`fn_task_list\` for active work, then call \`fn_task_search\` with 2-4 targeted keyword phrases from the title/description, such as file paths, symptoms, and symbols. For any likely match in \`done\` or \`archived\`, call \`fn_task_show\` and inspect it before deciding. If an existing task covers the same work, do not write PROMPT.md; write exactly \`DUPLICATE: {existing-task-id}\`.
## Required PROMPT.md shape
Write PROMPT.md with Mission, Before → After Transformation, Dependencies, Context to Read First, File Scope, Steps, Documentation Requirements, Completion Criteria, Git Commit Convention, and Do NOT. Include \`## Before → After Transformation\` after Mission with concise Before and After bullets stating current state, target state, and why it satisfies the user's request at a glance. In \`## Steps\`, every executable heading MUST use \`### Step N: <name>\` (for example, \`### Step 1: Preflight\`); Do not write bare \`### Preflight\` / \`### Implementation\` headings. Do not add review-level, triage subtask, or proactive subtask headings.
Write PROMPT.md with Before → After Transformation, Mission, Dependencies, Context to Read First, File Scope, Steps, Documentation Requirements, Completion Criteria, Git Commit Convention, and Do NOT. Put \`## Before → After Transformation\` at the top, before \`## Mission\`, with concise Before/After bullets: current state, target state, why it satisfies the user's request at a glance. In \`## Steps\`, every executable heading MUST use \`### Step N: <name>\` (e.g. \`### Step 1: Preflight\`). Do not write bare \`### Preflight\` / \`### Implementation\` headings, and do not add review-level, triage subtask, or proactive subtask headings.
## Surface Enumeration
For bug fixes and UI-affordance add/remove tasks, the spec MUST include a \`## Surface Enumeration\` section. The workflow Plan Review gate validates this before execution when plan review is enabled.
@@ -297,6 +300,11 @@ Follow this structure exactly:
**Created:** {YYYY-MM-DD}
**Size:** {S | M | L}
## Before → After Transformation
- **Before:** {Briefly describe the current state, missing capability, broken behavior, or operator pain point}
- **After:** {Briefly describe the target state and how it satisfies the user's request at a glance}
## Review Level: {0-3} ({None | Plan Only | Plan and Code | Full})
**Assessment:** {1-2 sentences explaining the score}
@@ -306,11 +314,6 @@ Follow this structure exactly:
{One paragraph: what you're building and why it matters}
## Before → After Transformation
- **Before:** {Briefly describe the current state, missing capability, broken behavior, or operator pain point}
- **After:** {Briefly describe the target state and how it satisfies the user's request at a glance}
## Surface Enumeration
{Required for bug-fix tasks and UI-affordance add/remove tasks (adding, removing, or restructuring icons, buttons, chevrons/arrows, toggles, badges, menu entries, click targets): a checklist enumerating every surface the fixed invariant must hold across. Include every provider/bridge for streaming and agent paths; desktop AND mobile breakpoints; empty/undefined/duplicate/populated data states; and every hook/component/module that shares the affected logic. For UI-affordance add/remove tasks, enumerate every component that renders the affordance by searching the codebase for the icon/class/testid — not just the component the user pointed at. Explicitly check for leftover shells after removal (empty buttons, orphaned click targets, now-unused wrappers, dangling aria-labels) across both desktop and mobile breakpoints. Use the canonical checklist in docs/testing.md as the starting point.}
@@ -437,11 +440,14 @@ If this task REMOVES existing functionality (deleting modules, settings, API end
## Transformation summary requirement
Every normal implementation, documentation, or decision task definition MUST include \`## Before → After Transformation\` after \`## Mission\`. Keep it concise: use brief Before and After bullets (or equivalent short prose) that name the current state, the target state, and why that target satisfies the user's request at a glance.
Every normal implementation, documentation, or decision task definition MUST include \`## Before → After Transformation\` at the top of the definition, immediately after the \`# Task\` title and \`Created\`/\`Size\` metadata, before \`## Review Level\` and \`## Mission\`. Keep it concise: use brief Before and After bullets (or equivalent short prose) that name the current state, the target state, and why that target satisfies the user's request at a glance.
<!--
FNXC:TriagePromptStructure 2026-07-04-16:20:
Task definitions now carry a glanceable before-to-after transformation summary near the top so operators and reviewers can confirm the intended outcome before reading the full specification.
FNXC:TriagePromptStructure 2026-07-05-12:00:
Per FN-7593, the transformation summary now sits at the very top of the definition — before Review Level and Mission — so operators can validate intent at a glance without scrolling past triage bookkeeping and Mission prose first.
-->
## Testing requirements

View File

@@ -753,6 +753,23 @@ describe("FN-5893 invariant regression wording", () => {
expect(FAST_PLANNING_PROMPT).not.toContain("## Proactive Subtask Breakdown");
});
it("places Before → After Transformation at the top of the definition, ahead of Mission and Review Level (FN-7593)", () => {
const standardTransformationIdx = STANDARD_PLANNING_PROMPT.indexOf("## Before → After Transformation");
const standardReviewLevelIdx = STANDARD_PLANNING_PROMPT.indexOf("## Review Level");
const standardMissionIdx = STANDARD_PLANNING_PROMPT.indexOf("## Mission");
expect(standardTransformationIdx).toBeGreaterThan(-1);
expect(standardReviewLevelIdx).toBeGreaterThan(-1);
expect(standardMissionIdx).toBeGreaterThan(-1);
expect(standardTransformationIdx).toBeLessThan(standardReviewLevelIdx);
expect(standardTransformationIdx).toBeLessThan(standardMissionIdx);
const fastTransformationIdx = FAST_PLANNING_PROMPT.indexOf("## Before → After Transformation");
const fastMissionIdx = FAST_PLANNING_PROMPT.indexOf("## Mission");
expect(fastTransformationIdx).toBeGreaterThan(-1);
expect(fastMissionIdx).toBeGreaterThan(-1);
expect(fastTransformationIdx).toBeLessThan(fastMissionIdx);
});
it("requires invariant-level regression coverage in standard, fast, and core triage prompts", () => {
for (const prompt of [
TRIAGE_POLICY_PROMPT,