(options: {
cwd: string;
prompts: PromptIO;
deps: DoctorDeps;
})
| 881 | } |
| 882 | |
| 883 | async function runIssueFlow(options: { |
| 884 | cwd: string; |
| 885 | prompts: PromptIO; |
| 886 | deps: DoctorDeps; |
| 887 | }): Promise<number> { |
| 888 | options.prompts.intro("Magic Context for Pi Issue Report"); |
| 889 | const title = await options.prompts.text("Issue title", { |
| 890 | placeholder: "Short summary of the Pi problem", |
| 891 | validate: (value) => (value.trim() ? undefined : "Title is required"), |
| 892 | }); |
| 893 | const description = await options.prompts.text("Issue description", { |
| 894 | placeholder: "Describe what happened, what you expected, and repro steps", |
| 895 | validate: (value) => (value.trim() ? undefined : "Description is required"), |
| 896 | }); |
| 897 | |
| 898 | const spinner = options.prompts.spinner(); |
| 899 | spinner.start("Collecting sanitized Pi diagnostics"); |
| 900 | try { |
| 901 | const report = await options.deps.collectDiagnostics(options.cwd); |
| 902 | spinner.stop("Diagnostics collected"); |
| 903 | |
| 904 | let sessionFilter: string | null = null; |
| 905 | if (report.recentSessions.length > 1) { |
| 906 | const choice = await options.prompts.selectOne( |
| 907 | "Which Pi session is this issue about? (filters log lines from other sessions)", |
| 908 | [ |
| 909 | ...report.recentSessions.map((session, index) => ({ |
| 910 | label: `${session.directory} — ${session.sessionId}${index === 0 ? " (most recent)" : ""}`, |
| 911 | value: session.sessionId, |
| 912 | })), |
| 913 | { |
| 914 | label: "All sessions (no filtering)", |
| 915 | value: "__all__", |
| 916 | }, |
| 917 | ], |
| 918 | ); |
| 919 | sessionFilter = choice === "__all__" ? null : choice; |
| 920 | } |
| 921 | |
| 922 | spinner.start("Bundling Pi issue report"); |
| 923 | const bundled = await bundleIssueReport(report, description, title, { |
| 924 | cwd: options.cwd, |
| 925 | now: options.deps.now(), |
| 926 | sessionFilter, |
| 927 | }); |
| 928 | spinner.stop(`Report written to ${bundled.path}`); |
| 929 | |
| 930 | if (ghAvailableAndAuthed(options.deps)) { |
| 931 | const shouldSubmit = await options.prompts.confirm( |
| 932 | "Submit this issue on GitHub now?", |
| 933 | false, |
| 934 | ); |
| 935 | if (shouldSubmit) { |
| 936 | const result = options.deps.spawnSync( |
| 937 | "gh", |
| 938 | [ |
| 939 | "issue", |
| 940 | "create", |
no test coverage detected