markupr 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/review-feedback.md +47 -0
- package/.eslintrc.json +35 -0
- package/.github/CODEOWNERS +16 -0
- package/.github/FUNDING.yml +1 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +56 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +54 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +89 -0
- package/.github/dependabot.yml +70 -0
- package/.github/workflows/ci.yml +184 -0
- package/.github/workflows/deploy-landing.yml +134 -0
- package/.github/workflows/nightly.yml +288 -0
- package/.github/workflows/release.yml +318 -0
- package/CHANGELOG.md +127 -0
- package/CLAUDE.md +137 -0
- package/CODE_OF_CONDUCT.md +9 -0
- package/CONTRIBUTING.md +390 -0
- package/LICENSE +21 -0
- package/PRODUCT_VISION.md +277 -0
- package/README.md +517 -0
- package/SECURITY.md +51 -0
- package/SIGNING_INSTRUCTIONS.md +284 -0
- package/assets/DMG_BACKGROUND_INSTRUCTIONS.md +130 -0
- package/assets/svg-source/dmg-background.svg +70 -0
- package/assets/svg-source/icon.svg +20 -0
- package/assets/svg-source/tray-icon-processing.svg +7 -0
- package/assets/svg-source/tray-icon-recording.svg +7 -0
- package/assets/svg-source/tray-icon.svg +6 -0
- package/assets/tray-complete.png +0 -0
- package/assets/tray-complete@2x.png +0 -0
- package/assets/tray-completeTemplate.png +0 -0
- package/assets/tray-completeTemplate@2x.png +0 -0
- package/assets/tray-error.png +0 -0
- package/assets/tray-error@2x.png +0 -0
- package/assets/tray-errorTemplate.png +0 -0
- package/assets/tray-errorTemplate@2x.png +0 -0
- package/assets/tray-icon-processing.png +0 -0
- package/assets/tray-icon-processing@2x.png +0 -0
- package/assets/tray-icon-processingTemplate.png +0 -0
- package/assets/tray-icon-processingTemplate@2x.png +0 -0
- package/assets/tray-icon-recording.png +0 -0
- package/assets/tray-icon-recording@2x.png +0 -0
- package/assets/tray-icon-recordingTemplate.png +0 -0
- package/assets/tray-icon-recordingTemplate@2x.png +0 -0
- package/assets/tray-icon.png +0 -0
- package/assets/tray-icon@2x.png +0 -0
- package/assets/tray-iconTemplate.png +0 -0
- package/assets/tray-iconTemplate@2x.png +0 -0
- package/assets/tray-idle.png +0 -0
- package/assets/tray-idle@2x.png +0 -0
- package/assets/tray-idleTemplate.png +0 -0
- package/assets/tray-idleTemplate@2x.png +0 -0
- package/assets/tray-processing-0.png +0 -0
- package/assets/tray-processing-0@2x.png +0 -0
- package/assets/tray-processing-0Template.png +0 -0
- package/assets/tray-processing-0Template@2x.png +0 -0
- package/assets/tray-processing-1.png +0 -0
- package/assets/tray-processing-1@2x.png +0 -0
- package/assets/tray-processing-1Template.png +0 -0
- package/assets/tray-processing-1Template@2x.png +0 -0
- package/assets/tray-processing-2.png +0 -0
- package/assets/tray-processing-2@2x.png +0 -0
- package/assets/tray-processing-2Template.png +0 -0
- package/assets/tray-processing-2Template@2x.png +0 -0
- package/assets/tray-processing-3.png +0 -0
- package/assets/tray-processing-3@2x.png +0 -0
- package/assets/tray-processing-3Template.png +0 -0
- package/assets/tray-processing-3Template@2x.png +0 -0
- package/assets/tray-processing.png +0 -0
- package/assets/tray-processing@2x.png +0 -0
- package/assets/tray-processingTemplate.png +0 -0
- package/assets/tray-processingTemplate@2x.png +0 -0
- package/assets/tray-recording.png +0 -0
- package/assets/tray-recording@2x.png +0 -0
- package/assets/tray-recordingTemplate.png +0 -0
- package/assets/tray-recordingTemplate@2x.png +0 -0
- package/build/DMG_BACKGROUND_SPEC.md +50 -0
- package/build/dmg-background.png +0 -0
- package/build/dmg-background@2x.png +0 -0
- package/build/entitlements.mac.inherit.plist +27 -0
- package/build/entitlements.mac.plist +41 -0
- package/build/favicon-16.png +0 -0
- package/build/favicon-180.png +0 -0
- package/build/favicon-192.png +0 -0
- package/build/favicon-32.png +0 -0
- package/build/favicon-48.png +0 -0
- package/build/favicon-512.png +0 -0
- package/build/favicon-64.png +0 -0
- package/build/icon-128.png +0 -0
- package/build/icon-16.png +0 -0
- package/build/icon-24.png +0 -0
- package/build/icon-256.png +0 -0
- package/build/icon-32.png +0 -0
- package/build/icon-48.png +0 -0
- package/build/icon-64.png +0 -0
- package/build/icon.icns +0 -0
- package/build/icon.ico +0 -0
- package/build/icon.iconset/icon_128x128.png +0 -0
- package/build/icon.iconset/icon_128x128@2x.png +0 -0
- package/build/icon.iconset/icon_16x16.png +0 -0
- package/build/icon.iconset/icon_16x16@2x.png +0 -0
- package/build/icon.iconset/icon_256x256.png +0 -0
- package/build/icon.iconset/icon_256x256@2x.png +0 -0
- package/build/icon.iconset/icon_32x32.png +0 -0
- package/build/icon.iconset/icon_32x32@2x.png +0 -0
- package/build/icon.iconset/icon_512x512.png +0 -0
- package/build/icon.iconset/icon_512x512@2x.png +0 -0
- package/build/icon.png +0 -0
- package/build/installer-header.bmp +0 -0
- package/build/installer-header.png +0 -0
- package/build/installer-sidebar.bmp +0 -0
- package/build/installer-sidebar.png +0 -0
- package/build/installer.nsh +45 -0
- package/build/overlay-processing.png +0 -0
- package/build/overlay-recording.png +0 -0
- package/build/toolbar-record.png +0 -0
- package/build/toolbar-screenshot.png +0 -0
- package/build/toolbar-settings.png +0 -0
- package/build/toolbar-stop.png +0 -0
- package/dist/main/index.mjs +12612 -0
- package/dist/preload/index.mjs +907 -0
- package/dist/renderer/assets/index-CCmUjl9K.js +19495 -0
- package/dist/renderer/assets/index-CUqz_Gs6.css +2270 -0
- package/dist/renderer/index.html +27 -0
- package/docs/AI_AGENT_QUICKSTART.md +42 -0
- package/docs/AI_PIPELINE_DESIGN.md +595 -0
- package/docs/API.md +514 -0
- package/docs/ARCHITECTURE.md +460 -0
- package/docs/CONFIGURATION.md +336 -0
- package/docs/DEVELOPMENT.md +508 -0
- package/docs/EXPORT_FORMATS.md +451 -0
- package/docs/GETTING_STARTED.md +236 -0
- package/docs/KEYBOARD_SHORTCUTS.md +334 -0
- package/docs/TROUBLESHOOTING.md +418 -0
- package/docs/landing/index.html +672 -0
- package/docs/landing/script.js +342 -0
- package/docs/landing/styles.css +1543 -0
- package/electron-builder.yml +140 -0
- package/electron.vite.config.ts +63 -0
- package/package.json +108 -0
- package/railway.json +12 -0
- package/scripts/build.mjs +51 -0
- package/scripts/generate-icons.mjs +314 -0
- package/scripts/generate-installer-images.cjs +253 -0
- package/scripts/generate-tray-icons.mjs +258 -0
- package/scripts/notarize.cjs +180 -0
- package/scripts/one-click-clean-test.sh +147 -0
- package/scripts/postinstall.mjs +36 -0
- package/scripts/setup-markupr.sh +55 -0
- package/setup +17 -0
- package/site/index.html +1835 -0
- package/site/package.json +11 -0
- package/site/railway.json +12 -0
- package/site/server.js +31 -0
- package/src/main/AutoUpdater.ts +392 -0
- package/src/main/CrashRecovery.ts +655 -0
- package/src/main/ErrorHandler.ts +703 -0
- package/src/main/HotkeyManager.ts +399 -0
- package/src/main/MenuManager.ts +529 -0
- package/src/main/PermissionManager.ts +420 -0
- package/src/main/SessionController.ts +1465 -0
- package/src/main/TrayManager.ts +540 -0
- package/src/main/ai/AIPipelineManager.ts +199 -0
- package/src/main/ai/ClaudeAnalyzer.ts +339 -0
- package/src/main/ai/ImageOptimizer.ts +176 -0
- package/src/main/ai/StructuredMarkdownBuilder.ts +379 -0
- package/src/main/ai/index.ts +16 -0
- package/src/main/ai/types.ts +258 -0
- package/src/main/analysis/ClarificationGenerator.ts +385 -0
- package/src/main/analysis/FeedbackAnalyzer.ts +531 -0
- package/src/main/analysis/index.ts +19 -0
- package/src/main/audio/AudioCapture.ts +978 -0
- package/src/main/audio/audioUtils.ts +100 -0
- package/src/main/audio/index.ts +20 -0
- package/src/main/capture/index.ts +1 -0
- package/src/main/index.ts +1693 -0
- package/src/main/ipc/captureHandlers.ts +272 -0
- package/src/main/ipc/index.ts +45 -0
- package/src/main/ipc/outputHandlers.ts +302 -0
- package/src/main/ipc/sessionHandlers.ts +56 -0
- package/src/main/ipc/settingsHandlers.ts +471 -0
- package/src/main/ipc/types.ts +56 -0
- package/src/main/ipc/windowHandlers.ts +277 -0
- package/src/main/output/ClipboardService.ts +369 -0
- package/src/main/output/ExportService.ts +539 -0
- package/src/main/output/FileManager.ts +416 -0
- package/src/main/output/MarkdownGenerator.ts +791 -0
- package/src/main/output/MarkdownPatcher.ts +299 -0
- package/src/main/output/index.ts +186 -0
- package/src/main/output/sessionAdapter.ts +207 -0
- package/src/main/output/templates/html-template.ts +553 -0
- package/src/main/pipeline/FrameExtractor.ts +330 -0
- package/src/main/pipeline/PostProcessor.ts +399 -0
- package/src/main/pipeline/TranscriptAnalyzer.ts +226 -0
- package/src/main/pipeline/index.ts +36 -0
- package/src/main/platform/WindowsTaskbar.ts +600 -0
- package/src/main/platform/index.ts +16 -0
- package/src/main/settings/SettingsManager.ts +730 -0
- package/src/main/settings/index.ts +19 -0
- package/src/main/transcription/ModelDownloadManager.ts +494 -0
- package/src/main/transcription/TierManager.ts +219 -0
- package/src/main/transcription/TranscriptionRecoveryService.ts +340 -0
- package/src/main/transcription/WhisperService.ts +748 -0
- package/src/main/transcription/index.ts +56 -0
- package/src/main/transcription/types.ts +135 -0
- package/src/main/windows/PopoverManager.ts +284 -0
- package/src/main/windows/TaskbarIntegration.ts +452 -0
- package/src/main/windows/index.ts +23 -0
- package/src/preload/index.ts +1047 -0
- package/src/renderer/App.tsx +515 -0
- package/src/renderer/AppWrapper.tsx +28 -0
- package/src/renderer/assets/logo-dark.svg +7 -0
- package/src/renderer/assets/logo.svg +7 -0
- package/src/renderer/audio/AudioCaptureRenderer.ts +454 -0
- package/src/renderer/capture/ScreenRecordingRenderer.ts +492 -0
- package/src/renderer/components/AnnotationOverlay.tsx +836 -0
- package/src/renderer/components/AudioWaveform.tsx +811 -0
- package/src/renderer/components/ClarificationQuestions.tsx +656 -0
- package/src/renderer/components/CountdownTimer.tsx +495 -0
- package/src/renderer/components/CrashRecoveryDialog.tsx +632 -0
- package/src/renderer/components/DonateButton.tsx +127 -0
- package/src/renderer/components/ErrorBoundary.tsx +308 -0
- package/src/renderer/components/ExportDialog.tsx +872 -0
- package/src/renderer/components/HotkeyHint.tsx +261 -0
- package/src/renderer/components/KeyboardShortcuts.tsx +787 -0
- package/src/renderer/components/ModelDownloadDialog.tsx +844 -0
- package/src/renderer/components/Onboarding.tsx +1830 -0
- package/src/renderer/components/ProcessingOverlay.tsx +157 -0
- package/src/renderer/components/RecordingOverlay.tsx +423 -0
- package/src/renderer/components/SessionHistory.tsx +1746 -0
- package/src/renderer/components/SessionReview.tsx +1321 -0
- package/src/renderer/components/SettingsPanel.tsx +217 -0
- package/src/renderer/components/Skeleton.tsx +347 -0
- package/src/renderer/components/StatusIndicator.tsx +86 -0
- package/src/renderer/components/ThemeProvider.tsx +429 -0
- package/src/renderer/components/Tooltip.tsx +370 -0
- package/src/renderer/components/TranscriptionPreview.tsx +183 -0
- package/src/renderer/components/TranscriptionTierSelector.tsx +640 -0
- package/src/renderer/components/UpdateNotification.tsx +377 -0
- package/src/renderer/components/WindowSelector.tsx +947 -0
- package/src/renderer/components/index.ts +99 -0
- package/src/renderer/components/primitives/ApiKeyInput.tsx +98 -0
- package/src/renderer/components/primitives/ColorPicker.tsx +65 -0
- package/src/renderer/components/primitives/DangerButton.tsx +45 -0
- package/src/renderer/components/primitives/DirectoryPicker.tsx +41 -0
- package/src/renderer/components/primitives/Dropdown.tsx +34 -0
- package/src/renderer/components/primitives/KeyRecorder.tsx +117 -0
- package/src/renderer/components/primitives/SettingsSection.tsx +32 -0
- package/src/renderer/components/primitives/Slider.tsx +43 -0
- package/src/renderer/components/primitives/Toggle.tsx +36 -0
- package/src/renderer/components/primitives/index.ts +10 -0
- package/src/renderer/components/settings/AdvancedTab.tsx +174 -0
- package/src/renderer/components/settings/AppearanceTab.tsx +77 -0
- package/src/renderer/components/settings/GeneralTab.tsx +40 -0
- package/src/renderer/components/settings/HotkeysTab.tsx +79 -0
- package/src/renderer/components/settings/RecordingTab.tsx +84 -0
- package/src/renderer/components/settings/index.ts +9 -0
- package/src/renderer/components/settings/settingsStyles.ts +673 -0
- package/src/renderer/components/settings/tabConfig.tsx +85 -0
- package/src/renderer/components/settings/useSettingsPanel.ts +447 -0
- package/src/renderer/contexts/ProcessingContext.tsx +227 -0
- package/src/renderer/contexts/RecordingContext.tsx +683 -0
- package/src/renderer/contexts/UIContext.tsx +326 -0
- package/src/renderer/contexts/index.ts +24 -0
- package/src/renderer/donateMessages.ts +69 -0
- package/src/renderer/hooks/index.ts +75 -0
- package/src/renderer/hooks/useAnimation.tsx +544 -0
- package/src/renderer/hooks/useTheme.ts +313 -0
- package/src/renderer/index.html +26 -0
- package/src/renderer/main.tsx +52 -0
- package/src/renderer/styles/animations.css +1093 -0
- package/src/renderer/styles/app-shell.css +662 -0
- package/src/renderer/styles/globals.css +515 -0
- package/src/renderer/styles/theme.ts +578 -0
- package/src/renderer/types/electron.d.ts +385 -0
- package/src/shared/hotkeys.ts +283 -0
- package/src/shared/types.ts +809 -0
- package/tests/clipboard.test.ts +228 -0
- package/tests/e2e/criticalPaths.test.ts +594 -0
- package/tests/feedbackAnalyzer.test.ts +303 -0
- package/tests/integration/sessionFlow.test.ts +583 -0
- package/tests/markdownGenerator.test.ts +418 -0
- package/tests/output.test.ts +96 -0
- package/tests/setup.ts +486 -0
- package/tests/unit/appIntegration.test.ts +676 -0
- package/tests/unit/appViewState.test.ts +281 -0
- package/tests/unit/audioIpcChannels.test.ts +17 -0
- package/tests/unit/exportService.test.ts +492 -0
- package/tests/unit/hotkeys.test.ts +92 -0
- package/tests/unit/navigationPreload.test.ts +94 -0
- package/tests/unit/onboardingFlow.test.ts +345 -0
- package/tests/unit/permissionManager.test.ts +175 -0
- package/tests/unit/permissionManagerExpanded.test.ts +296 -0
- package/tests/unit/screenRecordingRenderer.test.ts +368 -0
- package/tests/unit/sessionController.test.ts +515 -0
- package/tests/unit/tierManager.test.ts +61 -0
- package/tests/unit/tierManagerExpanded.test.ts +142 -0
- package/tests/unit/transcriptAnalyzer.test.ts +64 -0
- package/tsconfig.json +25 -0
- package/vitest.config.ts +46 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImageOptimizer - Optimize screenshots for the Claude Vision API
|
|
3
|
+
*
|
|
4
|
+
* Resizes images to Claude's recommended max dimension (1568px) and converts
|
|
5
|
+
* large PNGs to JPEG to reduce token usage. Uses Electron's built-in nativeImage
|
|
6
|
+
* so no external dependencies are needed.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { nativeImage } from 'electron';
|
|
10
|
+
import type { Screenshot } from '../SessionController';
|
|
11
|
+
import type { OptimizedImage, ImageOptimizeOptions } from './types';
|
|
12
|
+
import { DEFAULT_IMAGE_OPTIMIZE_OPTIONS, AIPipelineError } from './types';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Optimize a single screenshot buffer for the Claude Vision API.
|
|
16
|
+
*
|
|
17
|
+
* 1. Resize to fit within maxWidth (maintaining aspect ratio)
|
|
18
|
+
* 2. If the PNG exceeds pngToJpegThreshold, convert to JPEG at jpegQuality
|
|
19
|
+
*/
|
|
20
|
+
export function optimizeScreenshot(
|
|
21
|
+
buffer: Buffer,
|
|
22
|
+
width: number,
|
|
23
|
+
height: number,
|
|
24
|
+
options: ImageOptimizeOptions = DEFAULT_IMAGE_OPTIMIZE_OPTIONS,
|
|
25
|
+
): OptimizedImage & { _id: string } {
|
|
26
|
+
const image = nativeImage.createFromBuffer(buffer);
|
|
27
|
+
|
|
28
|
+
if (image.isEmpty()) {
|
|
29
|
+
throw new AIPipelineError(
|
|
30
|
+
'Failed to create nativeImage from screenshot buffer',
|
|
31
|
+
'IMAGE_OPTIMIZATION_FAILED',
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Resize if wider than maxWidth (maintain aspect ratio)
|
|
36
|
+
let resized = image;
|
|
37
|
+
let finalWidth = width;
|
|
38
|
+
let finalHeight = height;
|
|
39
|
+
|
|
40
|
+
if (width > options.maxWidth) {
|
|
41
|
+
const scale = options.maxWidth / width;
|
|
42
|
+
finalWidth = Math.round(width * scale);
|
|
43
|
+
finalHeight = Math.round(height * scale);
|
|
44
|
+
resized = image.resize({ width: finalWidth, height: finalHeight, quality: 'best' });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Start with PNG
|
|
48
|
+
let data = resized.toPNG();
|
|
49
|
+
let mediaType: 'image/png' | 'image/jpeg' = 'image/png';
|
|
50
|
+
|
|
51
|
+
// Convert to JPEG if PNG exceeds threshold
|
|
52
|
+
if (data.length > options.pngToJpegThreshold) {
|
|
53
|
+
data = resized.toJPEG(options.jpegQuality);
|
|
54
|
+
mediaType = 'image/jpeg';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
data,
|
|
59
|
+
mediaType,
|
|
60
|
+
originalScreenshotId: '', // Caller sets this
|
|
61
|
+
width: finalWidth,
|
|
62
|
+
height: finalHeight,
|
|
63
|
+
_id: '', // Caller sets this
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Batch-optimize screenshots for the Claude Vision API.
|
|
69
|
+
*
|
|
70
|
+
* - Processes all screenshots through resize/compress
|
|
71
|
+
* - If more than maxScreenshots exist, selects an evenly-spaced subset
|
|
72
|
+
* prioritizing manual/voice-command triggered screenshots
|
|
73
|
+
* - Returns optimized images ready for the API content blocks
|
|
74
|
+
*/
|
|
75
|
+
export function optimizeForAPI(
|
|
76
|
+
screenshots: Screenshot[],
|
|
77
|
+
options: Partial<ImageOptimizeOptions> = {},
|
|
78
|
+
): OptimizedImage[] {
|
|
79
|
+
const opts: ImageOptimizeOptions = { ...DEFAULT_IMAGE_OPTIMIZE_OPTIONS, ...options };
|
|
80
|
+
|
|
81
|
+
if (screenshots.length === 0) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Select which screenshots to include
|
|
86
|
+
const selected = selectScreenshots(screenshots, opts.maxScreenshots);
|
|
87
|
+
|
|
88
|
+
// Optimize each selected screenshot
|
|
89
|
+
const optimized: OptimizedImage[] = [];
|
|
90
|
+
|
|
91
|
+
for (const screenshot of selected) {
|
|
92
|
+
try {
|
|
93
|
+
const result = optimizeScreenshot(
|
|
94
|
+
screenshot.buffer,
|
|
95
|
+
screenshot.width,
|
|
96
|
+
screenshot.height,
|
|
97
|
+
opts,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
optimized.push({
|
|
101
|
+
data: result.data,
|
|
102
|
+
mediaType: result.mediaType,
|
|
103
|
+
originalScreenshotId: screenshot.id,
|
|
104
|
+
width: result.width,
|
|
105
|
+
height: result.height,
|
|
106
|
+
});
|
|
107
|
+
} catch (error) {
|
|
108
|
+
// Skip screenshots that fail to optimize (per design doc: "If still fails, skip that screenshot")
|
|
109
|
+
console.warn(
|
|
110
|
+
`[ImageOptimizer] Failed to optimize screenshot ${screenshot.id}, skipping:`,
|
|
111
|
+
error instanceof Error ? error.message : error,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return optimized;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Select which screenshots to send when the count exceeds the maximum.
|
|
121
|
+
*
|
|
122
|
+
* Strategy (from AI_PIPELINE_DESIGN.md):
|
|
123
|
+
* 1. Always include manual/voice-command triggered screenshots
|
|
124
|
+
* 2. From remaining pause-triggered ones, select evenly spaced to stay under max
|
|
125
|
+
*/
|
|
126
|
+
function selectScreenshots(screenshots: Screenshot[], max: number): Screenshot[] {
|
|
127
|
+
if (screenshots.length <= max) {
|
|
128
|
+
return screenshots;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Separate priority screenshots (manual, voice-command) from pause-triggered
|
|
132
|
+
const priority: Screenshot[] = [];
|
|
133
|
+
const pauseTriggered: Screenshot[] = [];
|
|
134
|
+
|
|
135
|
+
for (const s of screenshots) {
|
|
136
|
+
if (s.trigger === 'manual' || s.trigger === 'voice-command') {
|
|
137
|
+
priority.push(s);
|
|
138
|
+
} else {
|
|
139
|
+
pauseTriggered.push(s);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// If priority screenshots alone exceed max, take evenly spaced from priority
|
|
144
|
+
if (priority.length >= max) {
|
|
145
|
+
return evenlySpaced(priority, max);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Fill remaining slots with evenly spaced pause-triggered screenshots
|
|
149
|
+
const remainingSlots = max - priority.length;
|
|
150
|
+
const selectedPause = evenlySpaced(pauseTriggered, remainingSlots);
|
|
151
|
+
|
|
152
|
+
// Merge and sort by timestamp to maintain chronological order
|
|
153
|
+
const merged = [...priority, ...selectedPause];
|
|
154
|
+
merged.sort((a, b) => a.timestamp - b.timestamp);
|
|
155
|
+
|
|
156
|
+
return merged;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Select evenly spaced items from an array.
|
|
161
|
+
*/
|
|
162
|
+
function evenlySpaced<T>(items: T[], count: number): T[] {
|
|
163
|
+
if (items.length <= count) {
|
|
164
|
+
return items;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const result: T[] = [];
|
|
168
|
+
const step = (items.length - 1) / (count - 1);
|
|
169
|
+
|
|
170
|
+
for (let i = 0; i < count; i++) {
|
|
171
|
+
const index = Math.round(i * step);
|
|
172
|
+
result.push(items[index]);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StructuredMarkdownBuilder
|
|
3
|
+
*
|
|
4
|
+
* Converts Claude's structured JSON analysis (AIAnalysisResult) into polished,
|
|
5
|
+
* actionable markdown documents. The output is consumed by:
|
|
6
|
+
* 1. Claude Code via /review-feedback skill (primary consumer)
|
|
7
|
+
* 2. Users reading in GitHub or any markdown viewer
|
|
8
|
+
* 3. Other AI coding agents
|
|
9
|
+
*
|
|
10
|
+
* Maintains compatibility with the existing MarkdownGenerator's FB-XXX ID scheme
|
|
11
|
+
* and screenshot reference patterns.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type {
|
|
15
|
+
AIAnalysisResult,
|
|
16
|
+
AIFeedbackItem,
|
|
17
|
+
AIFeedbackPriority,
|
|
18
|
+
Session,
|
|
19
|
+
Screenshot,
|
|
20
|
+
} from './types';
|
|
21
|
+
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// Builder Options
|
|
24
|
+
// =============================================================================
|
|
25
|
+
|
|
26
|
+
export interface MarkdownBuildOptions {
|
|
27
|
+
/** Project name shown in the report header. */
|
|
28
|
+
projectName: string;
|
|
29
|
+
/** Relative path for screenshot references (e.g., "./screenshots"). */
|
|
30
|
+
screenshotDir: string;
|
|
31
|
+
/** Whether a session recording video exists. */
|
|
32
|
+
hasRecording?: boolean;
|
|
33
|
+
/** Filename of the session recording (default: "session-recording.webm"). */
|
|
34
|
+
recordingFilename?: string;
|
|
35
|
+
/** Claude model ID used for analysis (shown in footer). */
|
|
36
|
+
modelId?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// =============================================================================
|
|
40
|
+
// StructuredMarkdownBuilder
|
|
41
|
+
// =============================================================================
|
|
42
|
+
|
|
43
|
+
export class StructuredMarkdownBuilder {
|
|
44
|
+
/**
|
|
45
|
+
* Build a complete AI-enhanced markdown document from session data and Claude's analysis.
|
|
46
|
+
*/
|
|
47
|
+
buildDocument(
|
|
48
|
+
session: Session,
|
|
49
|
+
aiResult: AIAnalysisResult,
|
|
50
|
+
options: MarkdownBuildOptions,
|
|
51
|
+
): string {
|
|
52
|
+
const sections: string[] = [];
|
|
53
|
+
|
|
54
|
+
sections.push(this.buildHeader(session, aiResult, options));
|
|
55
|
+
sections.push(this.buildSummary(aiResult));
|
|
56
|
+
sections.push(this.buildFeedbackItems(session, aiResult, options));
|
|
57
|
+
|
|
58
|
+
if (aiResult.themes.length > 0) {
|
|
59
|
+
sections.push(this.buildThemes(aiResult.themes));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (aiResult.positiveNotes.length > 0) {
|
|
63
|
+
sections.push(this.buildPositiveNotes(aiResult.positiveNotes));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (options.hasRecording) {
|
|
67
|
+
sections.push(this.buildRecordingSection(options));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
sections.push(this.buildSessionInfo(session, aiResult, options));
|
|
71
|
+
sections.push(this.buildFooter(options));
|
|
72
|
+
|
|
73
|
+
return sections.join('\n');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ===========================================================================
|
|
77
|
+
// Section Builders
|
|
78
|
+
// ===========================================================================
|
|
79
|
+
|
|
80
|
+
private buildHeader(
|
|
81
|
+
session: Session,
|
|
82
|
+
aiResult: AIAnalysisResult,
|
|
83
|
+
options: MarkdownBuildOptions,
|
|
84
|
+
): string {
|
|
85
|
+
const date = this.formatDate(session.endTime ?? Date.now());
|
|
86
|
+
const duration = session.endTime
|
|
87
|
+
? this.formatDuration(session.endTime - session.startTime)
|
|
88
|
+
: 'In Progress';
|
|
89
|
+
const screenshotCount = session.screenshotBuffer.length;
|
|
90
|
+
|
|
91
|
+
return [
|
|
92
|
+
`# Feedback Report: ${options.projectName} - ${date}`,
|
|
93
|
+
'',
|
|
94
|
+
`> AI-analyzed by Claude | Duration: ${duration} | ${screenshotCount} screenshots | ${aiResult.items.length} items identified`,
|
|
95
|
+
'',
|
|
96
|
+
].join('\n');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private buildSummary(aiResult: AIAnalysisResult): string {
|
|
100
|
+
return [
|
|
101
|
+
'## Summary',
|
|
102
|
+
'',
|
|
103
|
+
aiResult.summary,
|
|
104
|
+
'',
|
|
105
|
+
'---',
|
|
106
|
+
'',
|
|
107
|
+
].join('\n');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private buildFeedbackItems(
|
|
111
|
+
session: Session,
|
|
112
|
+
aiResult: AIAnalysisResult,
|
|
113
|
+
options: MarkdownBuildOptions,
|
|
114
|
+
): string {
|
|
115
|
+
const grouped = this.groupByPriority(aiResult.items);
|
|
116
|
+
const lines: string[] = [];
|
|
117
|
+
|
|
118
|
+
const priorityOrder: AIFeedbackPriority[] = ['Critical', 'High', 'Medium', 'Low'];
|
|
119
|
+
const sectionTitles: Record<AIFeedbackPriority, string> = {
|
|
120
|
+
Critical: 'Critical Issues',
|
|
121
|
+
High: 'High Priority',
|
|
122
|
+
Medium: 'Improvements Needed',
|
|
123
|
+
Low: 'Suggestions',
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
let sequentialIndex = 0;
|
|
127
|
+
for (const priority of priorityOrder) {
|
|
128
|
+
const items = grouped[priority];
|
|
129
|
+
if (!items || items.length === 0) continue;
|
|
130
|
+
|
|
131
|
+
lines.push(`## ${sectionTitles[priority]}`);
|
|
132
|
+
lines.push('');
|
|
133
|
+
|
|
134
|
+
for (const { item } of items) {
|
|
135
|
+
lines.push(
|
|
136
|
+
this.buildSingleItem(item, sequentialIndex, session, options),
|
|
137
|
+
);
|
|
138
|
+
sequentialIndex++;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return lines.join('\n');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private buildSingleItem(
|
|
146
|
+
item: AIFeedbackItem,
|
|
147
|
+
index: number,
|
|
148
|
+
session: Session,
|
|
149
|
+
options: MarkdownBuildOptions,
|
|
150
|
+
): string {
|
|
151
|
+
const timestamp = this.estimateItemTimestamp(item, session);
|
|
152
|
+
const lines: string[] = [];
|
|
153
|
+
|
|
154
|
+
lines.push(`### ${index + 1}. ${item.title}`);
|
|
155
|
+
lines.push(`> "${item.quote}"`);
|
|
156
|
+
lines.push('');
|
|
157
|
+
|
|
158
|
+
// Screenshot references
|
|
159
|
+
for (const ssIndex of item.screenshotIndices) {
|
|
160
|
+
const screenshotFilename = this.resolveScreenshotFilename(session, ssIndex);
|
|
161
|
+
if (!screenshotFilename) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
lines.push(``);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (item.screenshotIndices.length > 0) {
|
|
168
|
+
lines.push('');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
lines.push(`- **Priority:** ${item.priority}`);
|
|
172
|
+
lines.push(`- **Category:** ${item.category}`);
|
|
173
|
+
lines.push(`- **Area:** ${item.area}`);
|
|
174
|
+
lines.push(`- **Timestamp:** ${timestamp}`);
|
|
175
|
+
lines.push(
|
|
176
|
+
`- **Action:** ${item.actionItem}`,
|
|
177
|
+
);
|
|
178
|
+
lines.push('');
|
|
179
|
+
lines.push('---');
|
|
180
|
+
lines.push('');
|
|
181
|
+
|
|
182
|
+
return lines.join('\n');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private resolveScreenshotFilename(session: Session, screenshotIndex: number): string | null {
|
|
186
|
+
if (!Number.isInteger(screenshotIndex) || screenshotIndex < 0) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const screenshot = session.screenshotBuffer[screenshotIndex];
|
|
191
|
+
if (!screenshot) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const matchedFeedbackIndex = session.feedbackItems.findIndex(
|
|
196
|
+
(item) => item.screenshot?.id === screenshot.id,
|
|
197
|
+
);
|
|
198
|
+
const index = matchedFeedbackIndex >= 0 ? matchedFeedbackIndex : screenshotIndex;
|
|
199
|
+
return `fb-${(index + 1).toString().padStart(3, '0')}.png`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private buildThemes(themes: string[]): string {
|
|
203
|
+
const lines: string[] = [
|
|
204
|
+
'## Themes',
|
|
205
|
+
'',
|
|
206
|
+
];
|
|
207
|
+
|
|
208
|
+
for (const theme of themes) {
|
|
209
|
+
lines.push(`- ${theme}`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
lines.push('');
|
|
213
|
+
lines.push('---');
|
|
214
|
+
lines.push('');
|
|
215
|
+
return lines.join('\n');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private buildPositiveNotes(notes: string[]): string {
|
|
219
|
+
const lines: string[] = [
|
|
220
|
+
'## Positive Notes',
|
|
221
|
+
'',
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
for (const note of notes) {
|
|
225
|
+
lines.push(`- ${note}`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
lines.push('');
|
|
229
|
+
lines.push('---');
|
|
230
|
+
lines.push('');
|
|
231
|
+
return lines.join('\n');
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private buildRecordingSection(options: MarkdownBuildOptions): string {
|
|
235
|
+
const filename = options.recordingFilename ?? 'session-recording.webm';
|
|
236
|
+
return [
|
|
237
|
+
'## Session Recording',
|
|
238
|
+
'',
|
|
239
|
+
`[Watch full session recording](./${filename})`,
|
|
240
|
+
'',
|
|
241
|
+
'---',
|
|
242
|
+
'',
|
|
243
|
+
].join('\n');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private buildSessionInfo(
|
|
247
|
+
session: Session,
|
|
248
|
+
aiResult: AIAnalysisResult,
|
|
249
|
+
options: MarkdownBuildOptions,
|
|
250
|
+
): string {
|
|
251
|
+
const duration = session.endTime
|
|
252
|
+
? this.formatDuration(session.endTime - session.startTime)
|
|
253
|
+
: 'In Progress';
|
|
254
|
+
const screenshotCount = session.screenshotBuffer.length;
|
|
255
|
+
const modelLabel = options.modelId ?? 'Claude';
|
|
256
|
+
|
|
257
|
+
const lines: string[] = [
|
|
258
|
+
'## Session Info',
|
|
259
|
+
'',
|
|
260
|
+
`- **Session ID:** \`${session.id}\``,
|
|
261
|
+
`- **Source:** ${session.metadata.sourceName ?? 'Unknown'} (${session.metadata.windowTitle ? 'window' : 'screen'})`,
|
|
262
|
+
`- **Duration:** ${duration}`,
|
|
263
|
+
`- **Screenshots:** ${screenshotCount}`,
|
|
264
|
+
];
|
|
265
|
+
|
|
266
|
+
if (options.hasRecording) {
|
|
267
|
+
const filename = options.recordingFilename ?? 'session-recording.webm';
|
|
268
|
+
lines.push(`- **Recording:** [${filename}](./${filename})`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
lines.push(`- **Analysis:** ${modelLabel} (AI-enhanced)`);
|
|
272
|
+
lines.push(`- **Items:** ${aiResult.metadata.totalItems} total, ${aiResult.metadata.criticalCount} critical, ${aiResult.metadata.highCount} high`);
|
|
273
|
+
lines.push('');
|
|
274
|
+
lines.push('---');
|
|
275
|
+
lines.push('');
|
|
276
|
+
return lines.join('\n');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private buildFooter(options: MarkdownBuildOptions): string {
|
|
280
|
+
const model = options.modelId ? ` with ${options.modelId}` : ' with AI analysis';
|
|
281
|
+
return `*Generated by [markupr](https://markupr.com)${model}*\n*If this report saved you time, support development: [Ko-fi](https://ko-fi.com/eddiesanjuan)*\n`;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// ===========================================================================
|
|
285
|
+
// Helpers
|
|
286
|
+
// ===========================================================================
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Group items by priority, preserving original indices for FB-XXX IDs.
|
|
290
|
+
*/
|
|
291
|
+
private groupByPriority(
|
|
292
|
+
items: AIFeedbackItem[],
|
|
293
|
+
): Record<AIFeedbackPriority, { item: AIFeedbackItem; originalIndex: number }[]> {
|
|
294
|
+
const grouped: Record<AIFeedbackPriority, { item: AIFeedbackItem; originalIndex: number }[]> = {
|
|
295
|
+
Critical: [],
|
|
296
|
+
High: [],
|
|
297
|
+
Medium: [],
|
|
298
|
+
Low: [],
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
items.forEach((item, index) => {
|
|
302
|
+
grouped[item.priority].push({ item, originalIndex: index });
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
return grouped;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Format a 0-based index as FB-001, FB-002, etc.
|
|
310
|
+
*/
|
|
311
|
+
formatItemId(index: number): string {
|
|
312
|
+
return `FB-${(index + 1).toString().padStart(3, '0')}`;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Estimate item timestamp as MM:SS relative to session start.
|
|
317
|
+
* Uses the quote text to find a matching transcript segment, or falls back to item order.
|
|
318
|
+
*/
|
|
319
|
+
private estimateItemTimestamp(item: AIFeedbackItem, session: Session): string {
|
|
320
|
+
// Try to match transcript buffer by quote text
|
|
321
|
+
const quotePrefix = item.quote.slice(0, 30);
|
|
322
|
+
const matchingSegment = session.transcriptBuffer.find(
|
|
323
|
+
(seg) => seg.text.includes(quotePrefix),
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
if (matchingSegment) {
|
|
327
|
+
const relativeMs = matchingSegment.timestamp * 1000 - session.startTime;
|
|
328
|
+
return this.formatTimestamp(relativeMs);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// If screenshotIndices reference a real screenshot, use its timestamp
|
|
332
|
+
if (item.screenshotIndices.length > 0) {
|
|
333
|
+
const ssIndex = item.screenshotIndices[0];
|
|
334
|
+
const screenshot: Screenshot | undefined = session.screenshotBuffer[ssIndex];
|
|
335
|
+
if (screenshot) {
|
|
336
|
+
const relativeMs = screenshot.timestamp - session.startTime;
|
|
337
|
+
return this.formatTimestamp(relativeMs);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return '--:--';
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Format milliseconds as MM:SS.
|
|
346
|
+
*/
|
|
347
|
+
private formatTimestamp(ms: number): string {
|
|
348
|
+
const totalSeconds = Math.max(0, Math.floor(ms / 1000));
|
|
349
|
+
const mins = Math.floor(totalSeconds / 60);
|
|
350
|
+
const secs = totalSeconds % 60;
|
|
351
|
+
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Format milliseconds as M:SS for duration display.
|
|
356
|
+
*/
|
|
357
|
+
private formatDuration(ms: number): string {
|
|
358
|
+
const totalSeconds = Math.floor(ms / 1000);
|
|
359
|
+
const mins = Math.floor(totalSeconds / 60);
|
|
360
|
+
const secs = totalSeconds % 60;
|
|
361
|
+
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Format a timestamp as a human-readable date string.
|
|
366
|
+
*/
|
|
367
|
+
private formatDate(ms: number): string {
|
|
368
|
+
return new Date(ms).toLocaleDateString('en-US', {
|
|
369
|
+
year: 'numeric',
|
|
370
|
+
month: 'short',
|
|
371
|
+
day: 'numeric',
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Singleton instance for easy import.
|
|
378
|
+
*/
|
|
379
|
+
export const structuredMarkdownBuilder = new StructuredMarkdownBuilder();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Pipeline - Barrel Export
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the pipeline manager and key types for use in the main process.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { processSession } from './AIPipelineManager';
|
|
8
|
+
export type { PipelineProcessOptions } from './AIPipelineManager';
|
|
9
|
+
export type {
|
|
10
|
+
AITier,
|
|
11
|
+
AIPipelineOutput,
|
|
12
|
+
AIPipelineOptions,
|
|
13
|
+
AIPipelineProgress,
|
|
14
|
+
AIPipelineStage,
|
|
15
|
+
AIAnalysisResult,
|
|
16
|
+
} from './types';
|