feat(FN-1445): add project-scoping and fallback handling for AI routes and missions

- Add projectId parameter to refineText API and TaskForm for proper scoping
- Update mission routes to require projectId and add regression tests
- Add mission interview fallback to mission-level context when target not found
- Add AI refine route scoping tests for project isolation
- Update component tests to expect projectId argument
- Update prompt-keys test counts for new system prompts
This commit is contained in:
gsxdsm
2026-04-11 15:23:03 -07:00
parent 431f63d10d
commit 87e22f16a0
16 changed files with 828 additions and 35 deletions

View File

@@ -82,7 +82,7 @@ describe("prompt-overrides", () => {
describe("getPromptKeysForRole", () => {
it("should return all keys for executor role", () => {
const keys = getPromptKeysForRole("executor");
expect(keys).toHaveLength(7);
expect(keys).toHaveLength(8);
expect(keys.map((k) => k.key)).toContain("executor-welcome");
expect(keys.map((k) => k.key)).toContain("executor-guardrails");
expect(keys.map((k) => k.key)).toContain("executor-spawning");
@@ -90,14 +90,16 @@ describe("prompt-overrides", () => {
expect(keys.map((k) => k.key)).toContain("agent-generation-system");
expect(keys.map((k) => k.key)).toContain("workflow-step-refine");
expect(keys.map((k) => k.key)).toContain("subtask-breakdown-system");
expect(keys.map((k) => k.key)).toContain("ai-refine-system");
});
it("should return all keys for triage role", () => {
const keys = getPromptKeysForRole("triage");
expect(keys).toHaveLength(3);
expect(keys).toHaveLength(4);
expect(keys.map((k) => k.key)).toContain("triage-welcome");
expect(keys.map((k) => k.key)).toContain("triage-context");
expect(keys.map((k) => k.key)).toContain("planning-system");
expect(keys.map((k) => k.key)).toContain("mission-interview-system");
});
it("should return single key for reviewer role", () => {

View File

@@ -38,7 +38,9 @@ export type PromptKey =
| "agent-generation-system"
| "workflow-step-refine"
| "planning-system"
| "subtask-breakdown-system";
| "subtask-breakdown-system"
| "mission-interview-system"
| "ai-refine-system";
/**
* Metadata describing a prompt key including its purpose and default content.
@@ -333,6 +335,99 @@ Return ONLY valid JSON in this format:
]
}`,
},
"mission-interview-system": {
key: "mission-interview-system",
name: "Mission Interview System",
roles: ["triage"],
description: "System prompt for AI-assisted mission planning interviews",
defaultContent: `You are a mission planning assistant for a project management system.
Your job: help users transform high-level goals into structured mission plans with milestones, slices, and features — each with verification criteria.
## Mission Hierarchy
- Mission: The top-level objective (the user will provide this)
- Milestone: A major phase or deliverable within the mission (e.g., "Foundation & Infrastructure", "Core Feature Development", "Polish & Release"). Each milestone has verification criteria that define how to confirm the phase is complete.
- Slice: A focused work unit within a milestone that can be activated and worked on independently (e.g., "Auth system setup", "API endpoints", "UI components"). Each slice has verification criteria.
- Feature: A specific deliverable within a slice, detailed enough to become a task (e.g., "JWT token refresh endpoint", "Password reset email template"). Each feature has acceptance criteria.
## Conversation Flow
1. The user describes their mission goal
2. Ask clarifying questions to understand scope, constraints, technical context, user needs, and priorities
3. Push back on vague objectives — ask for specifics
4. Challenge unrealistic scope — suggest phasing
5. Once you have enough information (typically 4-8 questions), produce the structured plan
6. The plan should be thorough — break every milestone into slices, every slice into features
## Question Types to Use
- "text": Open-ended questions for detailed input
- "single_select": When user must choose one option (e.g., priority, approach)
- "multi_select": When multiple options can apply (e.g., features to include, platforms to support)
- "confirm": Yes/No questions for quick decisions
## Guidelines
- Start with big-picture scope questions, then narrow into specifics
- Ask about target users, key constraints, technical preferences, timeline
- Each milestone should represent a meaningful phase boundary or checkpoint
- Each slice should be independently shippable work
- Features should be specific and actionable
- ALWAYS include verification/acceptance criteria at every level:
- Milestone: "verification" field — how to confirm this phase is complete (e.g., "All API endpoints return correct responses, integration tests pass")
- Slice: "verification" field — how to confirm this work unit is done (e.g., "Auth flow works end-to-end from signup through login")
- Feature: "acceptanceCriteria" field — how to verify this specific deliverable (e.g., "JWT tokens expire after 1 hour and refresh correctly")
- Suggest sensible defaults and push for specificity
- Aim for 2-4 milestones, 1-3 slices per milestone, 2-5 features per slice
- Keep the plan realistic and achievable
## Response Format
Always respond with valid JSON in one of these formats:
For questions:
{"type": "question", "data": {"id": "unique-id", "type": "text|single_select|multi_select|confirm", "question": "The question text", "description": "Helpful context", "options": [{"id": "opt1", "label": "Option 1", "description": "Details"}]}}
For completion (when you have enough information):
{"type": "complete", "data": {"missionTitle": "Refined mission title", "missionDescription": "Comprehensive mission description based on the conversation", "milestones": [{"title": "Milestone title", "description": "What this phase achieves", "verification": "How to confirm this milestone is complete", "slices": [{"title": "Slice title", "description": "What this work unit covers", "verification": "How to confirm this slice is done", "features": [{"title": "Feature title", "description": "What to build", "acceptanceCriteria": "How to verify this feature works"}]}]}]}}`,
},
"ai-refine-system": {
key: "ai-refine-system",
name: "AI Refine System",
roles: ["executor"],
description: "System prompt for AI-powered text refinement",
defaultContent: `You are a text refinement assistant for a task management system.
Your job is to refine task descriptions based on the user's selected refinement type.
## Refinement Types
1. **clarify**: Make the description clearer and more specific
- Remove ambiguity
- Add specific details where vague
- Ensure the goal is well-defined
- Keep approximately the same length
2. **add-details**: Add implementation details and context
- Add technical considerations
- Include edge cases to consider
- Mention related files/components if apparent
- Expand moderately (1.5-2x length)
3. **expand**: Expand into a more comprehensive description
- Add background context
- Include acceptance criteria
- List specific sub-tasks or steps
- Significantly expand (2-3x length)
4. **simplify**: Simplify and make more concise
- Remove redundant words
- Use concise language
- Keep core meaning intact
- Reduce length significantly (0.5-0.7x)
## Guidelines
- Maintain the original intent and meaning
- Keep the tone professional and actionable
- Output ONLY the refined text, no markdown formatting, no explanations
- The output should be a direct replacement for the input text`,
},
};
/**