Branchwell

Jotley / app · jotley.ai / scripts / summary-template-check.swift

Raw 11.2 KB on c22c50f3614b055549c1ecbf54af0165e0bc8df1
1// Real-model check: every summary template must render as a Summary card and
2// visual sections with no raw Markdown. Run with scripts/check-summary-templates.sh.
3import SwiftUI
4import AppKit
5@testable import Jotley
6
7let meeting = """
8Okay, let's get started. This is the product sync for the Jotley 2.1 launch. Maya, you had the onboarding update?
9Yes. The new onboarding screens are almost done. I need two more days, so I'll finish them by Wednesday.
10Great. Alex, the release checklist?
11I'll review the release checklist tomorrow and send the App Store screenshots to the owner for approval by Thursday.
12Sam, testing?
13I'm testing live transcription on iPhone and iPad. One risk is long meetings on older iPads; summaries can take a while.
14Okay, we decided to keep themes and templates in this release and move the new widgets to 2.2.
15We also agreed the launch date is Friday, October 23, at 10 a.m.
16Open question: should Ask AI suggestions change with each template? Nobody owns that yet.
17Revenue isn't relevant since the app is free, but we expect around 2,000 downloads in the first week.
18Let's meet Friday at ten to sign off. Thanks, everyone.
19"""
20let lecture = """
21Today we're covering working memory. Working memory is the system that holds information while we use it, for a few seconds at a time.
22Baddeley and Hitch proposed a model in 1974 with several parts. The phonological loop stores sounds and words. The visuospatial sketchpad holds images and locations. The central executive directs attention between them.
23Capacity is limited. Miller suggested about seven items, plus or minus two, but newer research suggests closer to four chunks.
24Chunking increases capacity: grouping digits like a phone number lets us remember more.
25For example, remembering 1-9-8-4 as a single year is one chunk instead of four digits.
26For next week, review the episodic buffer, which Baddeley added in 2000, and be ready to explain how it links working memory to long-term memory.
27"""
28let standUp = """
29Morning standup. Priya: yesterday I finished the search filters. Today I'm fixing the iPad sidebar crash. No blockers.
30Leo: yesterday I worked on the summary renderer. Today I'm adding tests for templates. I'm blocked on the new simulator image; I need Priya to share it.
31Jun: yesterday I reviewed pull requests. Today I'm updating the App Store screenshots. Blocked waiting on design approval from the owner.
32"""
33let networking = """
34Great meeting you at the developer meetup. I'm Dana, I run a small podcast studio in Austin.
35We both care about privacy-first tools. You mentioned Jotley keeps transcripts on the device, which matters for our interview guests.
36I can introduce you to two other podcasters who might test it. In return, you offered to share the transcript export workflow.
37Let's follow up next Tuesday over email. My email is on the card I gave you.
38"""
39let brainstorm = """
40Let's brainstorm ways to grow Jotley without paid ads. Idea one: a short tutorial series on YouTube. Idea two: partner with student organizations for lecture notes.
41Idea three: a shareable summary card people can post. Idea four: integrate with Obsidian more deeply.
42The students idea feels strongest because lectures are a natural fit. The share card is risky because of privacy.
43We picked students and the tutorial series. Next step: Maya drafts the tutorial outline, and Sam contacts two student groups this month.
44"""
45
46let oneToOne = """
47Thanks for making time, Jordan. How are things going since the onboarding redesign shipped?
48Pretty well. I'd like to lead the onboarding research next quarter, and I want more time with customers.
49That makes sense. My feedback is that your research summaries are strong, but share them earlier so design can react.
50Good point. I'll send a short weekly digest. I also want to grow in presenting to leadership.
51Let's get you the next roadmap review. Decision: you'll own onboarding research starting in January.
52Next steps: you draft the research plan by November 6, and I'll set up three customer calls.
53"""
54let allHands = """
55Good morning everyone. Big news first: Jotley 2.1 ships on Friday, October 23.
56Downloads grew 18 percent last month, and the Mac app now has 4,000 weekly active users.
57We decided to keep every feature free and to focus Q4 on reliability.
58A question from the team: will we hire for support? Answer: yes, one role opens in November.
59Next steps: each team shares Q4 goals by next Friday.
60"""
61let sprint = """
62Sprint 14 planning. Goal: ship structured summaries for 2.1.
63Committed work: the summary renderer, template prompt updates, and App Store screenshots.
64Leo estimates the renderer at three days. Priya says the prompt updates are two days.
65We have four engineers this sprint, but Jun is out on Thursday.
66Risk: the simulator image for UI tests may not be ready.
67Next step: Priya shares the simulator image today, and we demo on Friday.
68"""
69let kickoff = """
70Welcome to the kickoff for the Jotley Windows exploration. Objective: decide by December whether a Windows version is feasible.
71Scope: research only, no production code. Roles: Maya leads research, Sam evaluates speech engines, Alex owns the budget.
72Milestones: engine comparison by November 15, recommendation by December 10.
73Risk: on-device speech quality on Windows may not match Apple's.
74Next step: Sam sends the engine shortlist by Monday.
75"""
76let status = """
77Weekly status for the 2.1 release. Progress: the summary renderer is merged and screenshots are approved.
78Blocker: TestFlight build processing was slow on Tuesday.
79Metrics: 42 TestFlight testers, crash-free sessions at 99.8 percent.
80Decision: we ship Mac and iPhone on the same day.
81Next steps: submit for review on Monday and update the website download.
82"""
83
84let personal = """
85Okay, quick note to myself. I need to call the dentist on Monday to move my cleaning.
86Also, idea for the garden: put the tomatoes by the south fence this year, they got too much shade last summer.
87Don't forget Mom's birthday is the 28th, order flowers by the 24th.
88And I want to start running again, maybe three mornings a week before work.
89Remember to renew the car registration before November.
90"""
91let dump = """
92Just thinking out loud about the app. People love live transcription but the summaries feel long.
93Maybe a shorter default template would help. Or the summary could highlight decisions first.
94Another thought, a widget that starts recording with one tap. Not sure if that's worth it yet.
95Pricing doesn't matter, it's free, but I keep wondering how to get more people to try it.
96Maybe short videos on social. Or partnering with schools for lecture notes.
97Next I should look at which templates people actually use, and sketch the widget idea.
98"""
99
100func source(for template: LocalSummaryTemplate) -> String {
101 switch template {
102 case .lecture, .study: return lecture
103 case .standUp: return standUp
104 case .networking: return networking
105 case .brainstorming: return brainstorm
106 case .personalNote: return personal
107 case .brainDump: return dump
108 case .oneToOne: return oneToOne
109 case .allHands: return allHands
110 case .sprintPlanning: return sprint
111 case .projectKickoff: return kickoff
112 case .weeklyStatus: return status
113 default: return meeting
114 }
115}
116
117struct Result: Codable { let template: String; let seconds: Double; let markdown: String; let overview: Bool; let sections: [String]; let items: Int; let leaks: [String]; let error: String? }
118
119@MainActor func render(_ text: String, to file: String) {
120 ThemeManager.shared.setAppearanceMode(.light)
121 let view = StructuredSummaryView(content: text).padding(24).frame(width: 640).background(Color.themeBackground)
122 let host = NSHostingView(rootView: view)
123 host.appearance = NSAppearance(named: .aqua)
124 host.frame = NSRect(origin: .zero, size: host.fittingSize)
125 let window = NSWindow(contentRect: host.frame, styleMask: [.borderless], backing: .buffered, defer: false)
126 window.contentView = host; host.layoutSubtreeIfNeeded()
127 RunLoop.main.run(until: Date().addingTimeInterval(0.3))
128 let rep = host.bitmapImageRepForCachingDisplay(in: host.bounds)!
129 host.cacheDisplay(in: host.bounds, to: rep)
130 try! rep.representation(using: .png, properties: [:])!.write(to: URL(fileURLWithPath: file))
131}
132
133@MainActor func analyze(_ markdown: String) -> (Bool, [String], Int, [String]) {
134 let summary = StructuredSummary(ParsedNoteMarkdown.rendering(markdown))
135 var texts: [String] = []
136 for section in ([summary.overview].compactMap { $0 } + summary.sections) {
137 texts += section.paragraphs.map { String($0.text.characters) }
138 for item in section.items {
139 texts.append(String(item.body.characters)); if let l = item.label { texts.append(String(l.characters)) }
140 }
141 if let t = section.title { texts.append(t) }
142 }
143 let placeholders = ["not discussed", "not mentioned", "not specified", "not provided", "n/a", "none mentioned", "no details"]
144 var leaks = texts.filter { $0.contains("**") || $0.contains("##") || $0.contains("```") || $0.hasPrefix("#") || $0.contains("__") }
145 leaks += texts.filter { text in placeholders.contains { text.lowercased().contains($0) } || StructuredSummary.isPlaceholder(text) }.map { "placeholder: " + $0 }
146 leaks += markdown.components(separatedBy: "\n").filter { ["-", "*", "+"].contains($0.trimmingCharacters(in: .whitespaces)) }.map { _ in "empty list item" }
147 return (summary.overview != nil, summary.sections.compactMap(\.title), summary.sections.reduce(0) { $0 + $1.items.count }, leaks)
148}
149
150@main struct Check {
151 static func main() async {
152 _ = await MainActor.run { NSApplication.shared }
153 var results: [Result] = []
154 let only = CommandLine.arguments.dropFirst().first
155 for template in LocalSummaryTemplate.allCases where only == nil || template.key == only {
156 let start = Date()
157 do {
158 let md = try await LocalSummary.generate(source(for: template), template: template, locale: Locale(identifier: "en-US")) { _ in }
159 let (overview, sections, items, leaks) = await MainActor.run { analyze(md) }
160 await MainActor.run { render(md, to: "render-\(template.rawValue.replacingOccurrences(of: " ", with: "_").replacingOccurrences(of: ":", with: "")).png") }
161 results.append(Result(template: template.rawValue, seconds: Date().timeIntervalSince(start), markdown: md, overview: overview, sections: sections, items: items, leaks: leaks, error: nil))
162 print("\(template.rawValue): overview=\(overview) sections=\(sections) items=\(items) leaks=\(leaks.count) \(String(format: "%.1f", Date().timeIntervalSince(start)))s")
163 } catch {
164 results.append(Result(template: template.rawValue, seconds: Date().timeIntervalSince(start), markdown: "", overview: false, sections: [], items: 0, leaks: [], error: "\(error)"))
165 print("\(template.rawValue): ERROR \(error)")
166 }
167 }
168 let enc = JSONEncoder(); enc.outputFormatting = [.prettyPrinted]
169 try! enc.encode(results).write(to: URL(fileURLWithPath: "results.json"))
170 let failed = results.filter { $0.error != nil || !$0.overview || $0.sections.isEmpty || !$0.leaks.isEmpty }
171 print(failed.isEmpty ? "PASS: \(results.count) templates render structured summaries." : "FAIL: \(failed.map(\.template))")
172 exit(failed.isEmpty ? 0 : 1)
173 }
174}