diff --git a/packages/cli/src/services/insight/generators/DataProcessor.ts b/packages/cli/src/services/insight/generators/DataProcessor.ts index a4ce87030..6a1d03aaf 100644 --- a/packages/cli/src/services/insight/generators/DataProcessor.ts +++ b/packages/cli/src/services/insight/generators/DataProcessor.ts @@ -11,7 +11,6 @@ import { createDebugLogger, } from '@qwen-code/qwen-code-core'; import pLimit from 'p-limit'; -import type { Config, ChatRecord } from '@qwen-code/qwen-code-core'; import type { InsightData, HeatMapData, @@ -30,18 +29,11 @@ import type { InsightInteractionStyle, InsightAtAGlance, } from '../types/QualitativeInsightTypes.js'; - import { - PROMPT_IMPRESSIVE_WORKFLOWS, - PROMPT_PROJECT_AREAS, - PROMPT_FUTURE_OPPORTUNITIES, - PROMPT_FRICTION_POINTS, - PROMPT_MEMORABLE_MOMENT, - PROMPT_IMPROVEMENTS, - PROMPT_INTERACTION_STYLE, - PROMPT_AT_A_GLANCE, - ANALYSIS_PROMPT, -} from '../prompts/InsightPrompts.js'; + getInsightPrompt, + type Config, + type ChatRecord, +} from '@qwen-code/qwen-code-core'; const logger = createDebugLogger('DataProcessor'); @@ -181,7 +173,7 @@ export class DataProcessor { }; const sessionText = this.formatRecordsForAnalysis(records); - const prompt = `${ANALYSIS_PROMPT}\n\nSESSION:\n${sessionText}`; + const prompt = `${getInsightPrompt('analysis')}\n\nSESSION:\n${sessionText}`; try { const result = await this.config.getBaseLlmClient().generateJson({ @@ -582,48 +574,51 @@ export class DataProcessor { ] = await Promise.all([ limit(() => generate( - PROMPT_IMPRESSIVE_WORKFLOWS, + getInsightPrompt('impressive_workflows'), schemaImpressiveWorkflows, ), ), limit(() => generate( - PROMPT_PROJECT_AREAS, + getInsightPrompt('project_areas'), schemaProjectAreas, ), ), limit(() => generate( - PROMPT_FUTURE_OPPORTUNITIES, + getInsightPrompt('future_opportunities'), schemaFutureOpportunities, ), ), limit(() => generate( - PROMPT_FRICTION_POINTS, + getInsightPrompt('friction_points'), schemaFrictionPoints, ), ), limit(() => generate( - PROMPT_MEMORABLE_MOMENT, + getInsightPrompt('memorable_moment'), schemaMemorableMoment, ), ), limit(() => generate( - PROMPT_IMPROVEMENTS, + getInsightPrompt('improvements'), schemaImprovements, ), ), limit(() => generate( - PROMPT_INTERACTION_STYLE, + getInsightPrompt('interaction_style'), schemaInteractionStyle, ), ), limit(() => - generate(PROMPT_AT_A_GLANCE, schemaAtAGlance), + generate( + getInsightPrompt('at_a_glance'), + schemaAtAGlance, + ), ), ]); diff --git a/packages/cli/src/services/insight/prompts/InsightPrompts.ts b/packages/cli/src/services/insight/prompts/InsightPrompts.ts deleted file mode 100644 index 627b13351..000000000 --- a/packages/cli/src/services/insight/prompts/InsightPrompts.ts +++ /dev/null @@ -1,177 +0,0 @@ -export const ANALYSIS_PROMPT = `Analyze this Qwen Code session and extract structured facets. - -CRITICAL GUIDELINES: - -1. **goal_categories**: Count ONLY what the USER explicitly asked for. - - DO NOT count Qwen's autonomous codebase exploration - - DO NOT count work Qwen decided to do on its own - - ONLY count when user says "can you...", "please...", "I need...", "let's... - - POSSIBLE CATEGORIES (but be open to others that appear in the data): - - bug_fix - - feature_request - - debugging - - test_creation - - code_refactoring - - documentation_update - " - -2. **user_satisfaction_counts**: Base ONLY on explicit user signals. - - "Yay!", "great!", "perfect!" → happy - - "thanks", "looks good", "that works" → satisfied - - "ok, now let's..." (continuing without complaint) → likely_satisfied - - "that's not right", "try again" → dissatisfied - - "this is broken", "I give up" → frustrated - -3. **friction_counts**: Be specific about what went wrong. - - misunderstood_request: Qwen interpreted incorrectly - - wrong_approach: Right goal, wrong solution method - - buggy_code: Code didn't work correctly - - user_rejected_action: User said no/stop to a tool call - - excessive_changes: Over-engineered or changed too much - -4. If very short or just warmup, use warmup_minimal for goal_category`; - -export const PROMPT_IMPRESSIVE_WORKFLOWS = `Analyze this Qwen Code usage data and identify what's working well for this user. Use second person ("you"). - -Call respond_in_schema function with A VALID JSON OBJECT as argument: -{ - "intro": "1 sentence of context", - "impressive_workflows": [ - {"title": "Short title (3-6 words)", "description": "2-3 sentences describing the impressive workflow or approach. Use 'you' not 'the user'."} - ] -} - -Include 3 impressive workflows.`; - -export const PROMPT_PROJECT_AREAS = `Analyze this Qwen Code usage data and identify project areas. - -Call respond_in_schema function with A VALID JSON OBJECT as argument: -{ - "areas": [ - {"name": "Area name", "session_count": N, "description": "2-3 sentences about what was worked on and how Qwen Code was used."} - ] -} - -Include 4-5 areas. Skip internal QC operations.`; - -export const PROMPT_FUTURE_OPPORTUNITIES = `Analyze this Qwen Code usage data and identify future opportunities. - -Call respond_in_schema function with A VALID JSON OBJECT as argument: -{ - "intro": "1 sentence about evolving AI-assisted development", - "opportunities": [ - {"title": "Short title (4-8 words)", "whats_possible": "2-3 ambitious sentences about autonomous workflows", "how_to_try": "1-2 sentences mentioning relevant tooling", "copyable_prompt": "Detailed prompt to try"} - ] -} - -Include 3 opportunities. Think BIG - autonomous workflows, parallel agents, iterating against tests.`; - -export const PROMPT_FRICTION_POINTS = `Analyze this Qwen Code usage data and identify friction points for this user. Use second person ("you"). - -Call respond_in_schema function with A VALID JSON OBJECT as argument: -{ - "intro": "1 sentence summarizing friction patterns", - "categories": [ - {"category": "Concrete category name", "description": "1-2 sentences explaining this category and what could be done differently. Use 'you' not 'the user'.", "examples": ["Specific example with consequence", "Another example"]} - ] -} - -Include 3 friction categories with 2 examples each.`; - -export const PROMPT_MEMORABLE_MOMENT = `Analyze this Qwen Code usage data and find a memorable moment. - -Call respond_in_schema function with A VALID JSON OBJECT as argument: -{ - "headline": "A memorable QUALITATIVE moment from the transcripts - not a statistic. Something human, funny, or surprising.", - "detail": "Brief context about when/where this happened" -} - -Find something genuinely interesting or amusing from the session summaries.`; - -export const PROMPT_IMPROVEMENTS = `Analyze this Qwen Code usage data and suggest improvements. - -## QC FEATURES REFERENCE (pick from these for features_to_try): -1. **MCP Servers**: Connect Qwen to external tools, databases, and APIs via Model Context Protocol. - - How to use: Run \`qwen mcp add --transport http \` - - Good for: database queries, Slack integration, GitHub issue lookup, connecting to internal APIs - - Example: "To connect to GitHub, run \`qwen mcp add --header "Authorization: Bearer your_github_mcp_pat" --transport http github https://api.githubcopilot.com/mcp/\` and set the AUTHORIZATION header with your PAT. Then you can ask Qwen to query issues, PRs, or repos." - -2. **Custom Skills**: Reusable prompts you define as markdown files that run with a single /command. - - How to use: Create \`.qwen/skills/commit/SKILL.md\` with instructions. Then type \`/commit\` to run it. - - Good for: repetitive workflows - /commit, /review, /test, /deploy, /pr, or complex multi-step workflows - - SKILL.md format: - \`\`\` - --- - name: skill-name - description: A description of what this skill does and when to use it. - --- - - # Steps - 1. First, do X. - 2. Then do Y. - 3. Finally, verify Z. - - # Examples - - Input: "fix lint errors in src/" → Output: runs eslint --fix, commits changes - - Input: "review this PR" → Output: reads diff, posts inline comments - - # Edge Cases - - If no files match, report "nothing to do" instead of failing. - - If the user didn't specify a branch, default to the current branch. - \`\`\` - -3. **Headless Mode**: Run Qwen non-interactively from scripts and CI/CD. - - How to use: \`qwen -p "fix lint errors"\` - - Good for: CI/CD integration, batch code fixes, automated reviews - -4. **Task Agents**: Qwen spawns focused sub-agents for complex exploration or parallel work. - - How to use: Qwen auto-invokes when helpful, or ask "use an agent to explore X" - - Good for: codebase exploration, understanding complex systems - -Call respond_in_schema function with A VALID JSON OBJECT as argument: -{ - "Qwen_md_additions": [ - {"addition": "A specific line or block to add to QWEN.md based on workflow patterns. E.g., 'Always run tests after modifying auth-related files'", "why": "1 sentence explaining why this would help based on actual sessions", "prompt_scaffold": "Instructions for where to add this in QWEN.md. E.g., 'Add under ## Testing section'"} - ], - "features_to_try": [ - {"feature": "Feature name from QC FEATURES REFERENCE above", "one_liner": "What it does", "why_for_you": "Why this would help YOU based on your sessions", "example_code": "Actual command or config to copy"} - ], - "usage_patterns": [ - {"title": "Short title", "suggestion": "1-2 sentence summary", "detail": "3-4 sentences explaining how this applies to YOUR work", "copyable_prompt": "A specific prompt to copy and try"} - ] -} - -IMPORTANT for Qwen_md_additions: PRIORITIZE instructions that appear MULTIPLE TIMES in the user data. If user told Qwen the same thing in 2+ sessions (e.g., 'always run tests', 'use TypeScript'), that's a PRIME candidate - they shouldn't have to repeat themselves. - -IMPORTANT for features_to_try: Pick 2-3 from the QC FEATURES REFERENCE above. Include 2-3 items for each category.`; - -export const PROMPT_INTERACTION_STYLE = `Analyze this Qwen Code usage data and describe the user's interaction style. - -Call respond_in_schema function with A VALID JSON OBJECT as argument: -{ - "narrative": "2-3 paragraphs analyzing HOW the user interacts with Qwen Code. Use second person 'you'. Describe patterns: iterate quickly vs detailed upfront specs? Interrupt often or let Qwen run? Include specific examples. Use **bold** for key insights.", - "key_pattern": "One sentence summary of most distinctive interaction style" -} -`; - -export const PROMPT_AT_A_GLANCE = `You're writing an "At a Glance" summary for a Qwen Code usage insights report for Qwen Code users. The goal is to help them understand their usage and improve how they can use Qwen better, especially as models improve. - -Use this 4-part structure: - -1. **What's working** - What is the user's unique style of interacting with Qwen and what are some impactful things they've done? You can include one or two details, but keep it high level since things might not be fresh in the user's memory. Don't be fluffy or overly complimentary. Also, don't focus on the tool calls they use. - -2. **What's hindering you** - Split into (a) Qwen's fault (misunderstandings, wrong approaches, bugs) and (b) user-side friction (not providing enough context, environment issues -- ideally more general than just one project). Be honest but constructive. - -3. **Quick wins to try** - Specific Qwen Code features they could try from the examples below, or a workflow technique if you think it's really compelling. (Avoid stuff like "Ask Qwen to confirm before taking actions" or "Type out more context up front" which are less compelling.) - -4. **Ambitious workflows for better models** - As we move to much more capable models over the next 3-6 months, what should they prepare for? What workflows that seem impossible now will become possible? Draw from the appropriate section below. - -Keep each section to 2-3 not-too-long sentences. Don't overwhelm the user. Don't mention specific numerical stats or underlined_categories from the session data below. Use a coaching tone. - -Call respond_in_schema function with A VALID JSON OBJECT as argument: -{ - "whats_working": "(refer to instructions above)", - "whats_hindering": "(refer to instructions above)", - "quick_wins": "(refer to instructions above)", - "ambitious_workflows": "(refer to instructions above)" -}`; diff --git a/packages/core/src/core/prompts.ts b/packages/core/src/core/prompts.ts index 60c2c56d9..1081aac01 100644 --- a/packages/core/src/core/prompts.ts +++ b/packages/core/src/core/prompts.ts @@ -859,3 +859,207 @@ Plan mode is active. The user indicated that they do not want you to execute yet 2. When you're done researching, present your plan ${planOnly ? 'directly' : `by calling the ${ToolNames.EXIT_PLAN_MODE} tool, which will prompt the user to confirm the plan`}. Do NOT make any file changes or run any tools that modify the system state in any way until the user has confirmed the plan. `; } + +// ============================================================================ +// Insight Analysis Prompts +// ============================================================================ + +type InsightPromptType = + | 'analysis' + | 'impressive_workflows' + | 'project_areas' + | 'future_opportunities' + | 'friction_points' + | 'memorable_moment' + | 'improvements' + | 'interaction_style' + | 'at_a_glance'; + +const INSIGHT_PROMPTS: Record = { + analysis: `Analyze this Qwen Code session and extract structured facets. + +CRITICAL GUIDELINES: + +1. **goal_categories**: Count ONLY what the USER explicitly asked for. + - DO NOT count Qwen's autonomous codebase exploration + - DO NOT count work Qwen decided to do on its own + - ONLY count when user says "can you...", "please...", "I need...", "let's... + - POSSIBLE CATEGORIES (but be open to others that appear in the data): + - bug_fix + - feature_request + - debugging + - test_creation + - code_refactoring + - documentation_update + " + +2. **user_satisfaction_counts**: Base ONLY on explicit user signals. + - "Yay!", "great!", "perfect!" → happy + - "thanks", "looks good", "that works" → satisfied + - "ok, now let's..." (continuing without complaint) → likely_satisfied + - "that's not right", "try again" → dissatisfied + - "this is broken", "I give up" → frustrated + +3. **friction_counts**: Be specific about what went wrong. + - misunderstood_request: Qwen interpreted incorrectly + - wrong_approach: Right goal, wrong solution method + - buggy_code: Code didn't work correctly + - user_rejected_action: User said no/stop to a tool call + - excessive_changes: Over-engineered or changed too much + +4. If very short or just warmup, use warmup_minimal for goal_category`, + + impressive_workflows: `Analyze this Qwen Code usage data and identify what's working well for this user. Use second person ("you"). + +Call respond_in_schema function with A VALID JSON OBJECT as argument: +{ + "intro": "1 sentence of context", + "impressive_workflows": [ + {"title": "Short title (3-6 words)", "description": "2-3 sentences describing the impressive workflow or approach. Use 'you' not 'the user'."} + ] +} + +Include 3 impressive workflows.`, + + project_areas: `Analyze this Qwen Code usage data and identify project areas. + +Call respond_in_schema function with A VALID JSON OBJECT as argument: +{ + "areas": [ + {"name": "Area name", "session_count": N, "description": "2-3 sentences about what was worked on and how Qwen Code was used."} + ] +} + +Include 4-5 areas. Skip internal QC operations.`, + + future_opportunities: `Analyze this Qwen Code usage data and identify future opportunities. + +Call respond_in_schema function with A VALID JSON OBJECT as argument: +{ + "intro": "1 sentence about evolving AI-assisted development", + "opportunities": [ + {"title": "Short title (4-8 words)", "whats_possible": "2-3 ambitious sentences about autonomous workflows", "how_to_try": "1-2 sentences mentioning relevant tooling", "copyable_prompt": "Detailed prompt to try"} + ] +} + +Include 3 opportunities. Think BIG - autonomous workflows, parallel agents, iterating against tests.`, + + friction_points: `Analyze this Qwen Code usage data and identify friction points for this user. Use second person ("you"). + +Call respond_in_schema function with A VALID JSON OBJECT as argument: +{ + "intro": "1 sentence summarizing friction patterns", + "categories": [ + {"category": "Concrete category name", "description": "1-2 sentences explaining this category and what could be done differently. Use 'you' not 'the user'.", "examples": ["Specific example with consequence", "Another example"]} + ] +} + +Include 3 friction categories with 2 examples each.`, + + memorable_moment: `Analyze this Qwen Code usage data and find a memorable moment. + +Call respond_in_schema function with A VALID JSON OBJECT as argument: +{ + "headline": "A memorable QUALITATIVE moment from the transcripts - not a statistic. Something human, funny, or surprising.", + "detail": "Brief context about when/where this happened" +} + +Find something genuinely interesting or amusing from the session summaries.`, + + improvements: `Analyze this Qwen Code usage data and suggest improvements. + +## QC FEATURES REFERENCE (pick from these for features_to_try): +1. **MCP Servers**: Connect Qwen to external tools, databases, and APIs via Model Context Protocol. + - How to use: Run \`qwen mcp add --transport http \` + - Good for: database queries, Slack integration, GitHub issue lookup, connecting to internal APIs + - Example: "To connect to GitHub, run \`qwen mcp add --header "Authorization: Bearer your_github_mcp_pat" --transport http github https://api.githubcopilot.com/mcp/\` and set the AUTHORIZATION header with your PAT. Then you can ask Qwen to query issues, PRs, or repos." + +2. **Custom Skills**: Reusable prompts you define as markdown files that run with a single /command. + - How to use: Create \`.qwen/skills/commit/SKILL.md\` with instructions. Then type \`/commit\` to run it. + - Good for: repetitive workflows - /commit, /review, /test, /deploy, /pr, or complex multi-step workflows + - SKILL.md format: + \`\`\` + --- + name: skill-name + description: A description of what this skill does and when to use it. + --- + + # Steps + 1. First, do X. + 2. Then do Y. + 3. Finally, verify Z. + + # Examples + - Input: "fix lint errors in src/" → Output: runs eslint --fix, commits changes + - Input: "review this PR" → Output: reads diff, posts inline comments + + # Edge Cases + - If no files match, report "nothing to do" instead of failing. + - If the user didn't specify a branch, default to the current branch. + \`\`\` + +3. **Headless Mode**: Run Qwen non-interactively from scripts and CI/CD. + - How to use: \`qwen -p "fix lint errors"\` + - Good for: CI/CD integration, batch code fixes, automated reviews + +4. **Task Agents**: Qwen spawns focused sub-agents for complex exploration or parallel work. + - How to use: Qwen auto-invokes when helpful, or ask "use an agent to explore X" + - Good for: codebase exploration, understanding complex systems + +Call respond_in_schema function with A VALID JSON OBJECT as argument: +{ + "Qwen_md_additions": [ + {"addition": "A specific line or block to add to QWEN.md based on workflow patterns. E.g., 'Always run tests after modifying auth-related files'", "why": "1 sentence explaining why this would help based on actual sessions", "prompt_scaffold": "Instructions for where to add this in QWEN.md. E.g., 'Add under ## Testing section'"} + ], + "features_to_try": [ + {"feature": "Feature name from QC FEATURES REFERENCE above", "one_liner": "What it does", "why_for_you": "Why this would help YOU based on your sessions", "example_code": "Actual command or config to copy"} + ], + "usage_patterns": [ + {"title": "Short title", "suggestion": "1-2 sentence summary", "detail": "3-4 sentences explaining how this applies to YOUR work", "copyable_prompt": "A specific prompt to copy and try"} + ] +} + +IMPORTANT for Qwen_md_additions: PRIORITIZE instructions that appear MULTIPLE TIMES in the user data. If user told Qwen the same thing in 2+ sessions (e.g., 'always run tests', 'use TypeScript'), that's a PRIME candidate - they shouldn't have to repeat themselves. + +IMPORTANT for features_to_try: Pick 2-3 from the QC FEATURES REFERENCE above. Include 2-3 items for each category.`, + + interaction_style: `Analyze this Qwen Code usage data and describe the user's interaction style. + +Call respond_in_schema function with A VALID JSON OBJECT as argument: +{ + "narrative": "2-3 paragraphs analyzing HOW the user interacts with Qwen Code. Use second person 'you'. Describe patterns: iterate quickly vs detailed upfront specs? Interrupt often or let Qwen run? Include specific examples. Use **bold** for key insights.", + "key_pattern": "One sentence summary of most distinctive interaction style" +} +`, + + at_a_glance: `You're writing an "At a Glance" summary for a Qwen Code usage insights report for Qwen Code users. The goal is to help them understand their usage and improve how they can use Qwen better, especially as models improve. + +Use this 4-part structure: + +1. **What's working** - What is the user's unique style of interacting with Qwen and what are some impactful things they've done? You can include one or two details, but keep it high level since things might not be fresh in the user's memory. Don't be fluffy or overly complimentary. Also, don't focus on the tool calls they use. + +2. **What's hindering you** - Split into (a) Qwen's fault (misunderstandings, wrong approaches, bugs) and (b) user-side friction (not providing enough context, environment issues -- ideally more general than just one project). Be honest but constructive. + +3. **Quick wins to try** - Specific Qwen Code features they could try from the examples below, or a workflow technique if you think it's really compelling. (Avoid stuff like "Ask Qwen to confirm before taking actions" or "Type out more context up front" which are less compelling.) + +4. **Ambitious workflows for better models** - As we move to much more capable models over the next 3-6 months, what should they prepare for? What workflows that seem impossible now will become possible? Draw from the appropriate section below. + +Keep each section to 2-3 not-too-long sentences. Don't overwhelm the user. Don't mention specific numerical stats or underlined_categories from the session data below. Use a coaching tone. + +Call respond_in_schema function with A VALID JSON OBJECT as argument: +{ + "whats_working": "(refer to instructions above)", + "whats_hindering": "(refer to instructions above)", + "quick_wins": "(refer to instructions above)", + "ambitious_workflows": "(refer to instructions above)" +}`, +}; + +/** + * Get an insight analysis prompt by type. + * @param type - The type of insight prompt to retrieve + * @returns The prompt string for the specified type + */ +export function getInsightPrompt(type: InsightPromptType): string { + return INSIGHT_PROMPTS[type]; +}