Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: App/DemoLibrary.swift3// Description: DEBUG only — fills a throw-away data directory with a small sample library (a note holding every 3.0 block, linked notes, tasks, inbox captures) for development screenshots. Never compiled in Release, never run on the owner's data (it requires -SPNotesInMemory).4#if DEBUG5import AppKit6import SPNotesDocument7import SPNotesStore8import SPNotesCore910@MainActor enum DemoLibrary {11 static let noteId = "0d0e0a0b-0c0d-4e0f-8a0b-0c0d0e0f0a01"1213 static func seed(_ env: AppEnvironment) async {14 guard env.options.inMemory, !env.isBlocked, (try? await env.store.pageCount()) == 0 else { return }15 let lib = env.library16 guard let method = await lib.newNote(title: "Méthode d'estimation", content: NoteDocument(markdown: "## Estimateur à noyau\n\nLa variance réalisée est calculée sur des rendements à une minute, puis corrigée du bruit de microstructure.\n\n- fenêtre de 390 minutes\n- noyau de Parzen")),17 let methodPage = try? await env.store.page(id: method), let methodDoc = try? NoteDocument(json: methodPage.content) else { return }18 let block = methodDoc.lines.first { $0.type == "paragraph" }?.attrs["id"]?.stringValue ?? ""19 // real files for the blocks that show one: a two-page PDF and an ink drawing20 let pdfURL = FileManager.default.temporaryDirectory.appendingPathComponent("Andersen-2003.pdf"); var box = CGRect(x: 0, y: 0, width: 420, height: 594)21 if let ctx = CGContext(pdfURL as CFURL, mediaBox: &box, nil) {22 ctx.beginPDFPage(nil)23 let title = NSAttributedString(string: "Modeling and Forecasting\nRealized Volatility", attributes: [.font: NSFont(name: "Times New Roman", size: 22) ?? .systemFont(ofSize: 22)])24 let g = NSGraphicsContext(cgContext: ctx, flipped: false); NSGraphicsContext.saveGraphicsState(); NSGraphicsContext.current = g25 title.draw(in: CGRect(x: 40, y: 440, width: 340, height: 90))26 NSGraphicsContext.restoreGraphicsState()27 ctx.setFillColor(CGColor(gray: 0.55, alpha: 1)); for i in 0..<16 { ctx.fill(CGRect(x: 40, y: 400 - CGFloat(i) * 20, width: i % 5 == 4 ? 210 : 340, height: 5)) }28 ctx.endPDFPage(); ctx.beginPDFPage(nil); ctx.endPDFPage(); ctx.closePDF()29 }30 let ink = InkDocument(width: 640, height: 300, strokes: [31 InkStroke(tool: .pen, color: InkColor(red: UInt8(47), green: 93, blue: 219), width: 3, points: (0...60).map { i in InkPoint(x: 40 + Double(i) * 9, y: 150 + 90 * sin(Double(i) / 6) * exp(-Double(i) / 50)) }),32 InkStroke(tool: .marker, color: InkColor(red: UInt8(126), green: 65, blue: 210), width: 5, points: [InkPoint(x: 40, y: 150), InkPoint(x: 600, y: 150)]),33 ])34 let inkURL = FileManager.default.temporaryDirectory.appendingPathComponent("dessin.json"); try? ink.jsonValue.canonicalData().write(to: inkURL)35 let service = AttachmentService(env: env)36 let main = (try? await env.store.createPage(NewPage(id: noteId, title: "SP Note Next — tous les blocs", tags: ["thèse", "démo"])))?.id ?? noteId37 let pdf = try? await service.importFile(pdfURL, pageId: main), drawing = try? await service.importFile(inkURL, pageId: main)38 let mermaid = "flowchart LR\n Données --> Nettoyage --> Estimation\n Estimation --> Prévision"39 let json = #"""40 {"type":"doc","content":[41 {"type":"paragraph","attrs":{"id":"d000000001"},"content":[{"type":"text","text":"Cette note réunit les blocs de SP Note 3.0. La volatilité réalisée suit "},{"type":"citation","attrs":{"refId":"33333333-4444-4555-8666-777777777777","locator":"p. 581","label":"Andersen et al. 2003"}},{"type":"text","text":" ; voir aussi "},{"type":"mention","attrs":{"id":"\#(method)","label":"Méthode d'estimation","mentionSuggestionChar":"@"}},{"type":"text","text":"."}]},42 {"type":"taskList","attrs":{"id":"d000000002"},"content":[{"type":"taskItem","attrs":{"checked":false,"id":"d00000002a","due":"\#(day(2))","priority":"high","taskId":null},"content":[{"type":"paragraph","attrs":{"id":"d00000002b"},"content":[{"type":"text","text":"Rendre le chapitre 3"}]}]},{"type":"taskItem","attrs":{"checked":false,"id":"d00000002c","due":"\#(day(-1))","priority":"medium","taskId":null},"content":[{"type":"paragraph","attrs":{"id":"d00000002d"},"content":[{"type":"text","text":"Mettre à jour le graphique"}]}]},{"type":"taskItem","attrs":{"checked":true,"id":"d00000002e","due":null,"priority":null,"taskId":null},"content":[{"type":"paragraph","attrs":{"id":"d00000002f"},"content":[{"type":"text","text":"Télécharger les données à la minute"}]}]}]},43 {"type":"callout","attrs":{"id":"d000000003","kind":"decision","icon":"⚖️"},"content":[{"type":"paragraph","attrs":{"id":"d00000003a"},"content":[{"type":"text","text":"Décision : on garde l'échantillonnage à une minute pour tout le chapitre."}]}]},44 {"type":"callout","attrs":{"id":"d000000004","kind":"question","icon":"❓"},"content":[{"type":"paragraph","attrs":{"id":"d00000004a"},"content":[{"type":"text","text":"Le biais de microstructure reste-t-il négligeable à cette fréquence ?"}]}]},45 {"type":"callout","attrs":{"id":"d000000005","kind":"hypothesis","icon":"🧪"},"content":[{"type":"paragraph","attrs":{"id":"d00000005a"},"content":[{"type":"text","text":"Hypothèse : la volatilité intrajournalière annonce les révisions comptables."}]}]},46 {"type":"mermaid","attrs":{"id":"d000000006","code":"\#(mermaid.replacingOccurrences(of: "\n", with: "\\n"))","preview":null,"previewHash":null}},47 {"type":"chart","attrs":{"id":"d000000007","kind":"line","title":"Volatilité réalisée annualisée (%)","columns":["Mois","1 min","5 min"],"rows":[["jan",18.2,17.1],["fév",21.4,19.8],["mars",34.9,31.2],["avr",27.3,25.9],["mai",19.8,19.1],["juin",16.5,16.0]],"x":"Mois","y":["1 min","5 min"],"source":null}},48 {"type":"pdf","attrs":{"id":"d000000008","attachmentId":\#(pdf.map { "\"\($0.id)\"" } ?? "null"),"name":"Andersen-2003.pdf","page":1,"annotations":[{"id":"a1","page":1,"kind":"highlight","color":"#ffd54a","rects":[[0.1,0.3,0.8,0.02]],"text":"realized volatility","note":"définition","createdAt":"2026-11-19T10:00:00.000Z"}]}},49 {"type":"blockRef","attrs":{"id":"d000000009","pageId":"\#(method)","blockId":"\#(block)","mode":"embed"}},50 {"type":"runCode","attrs":{"id":"d00000000a","language":"javascript","code":"const r = [0.012, -0.008, 0.021];\nconst rv = r.reduce((s, x) => s + x * x, 0);\nconsole.log(Math.sqrt(rv * 252).toFixed(4));","output":{"text":"0.4047","error":false,"ms":2,"at":"2026-11-19T10:02:00.000Z"}}},51 {"type":"audio","attrs":{"id":"d00000000b","attachmentId":null,"duration":187,"title":"Point avec le directeur","recordedAt":"2026-11-18T14:00:00.000Z","transcript":[{"t":0,"text":"On valide le plan du chapitre 3."},{"t":64,"text":"La figure 2 doit comparer les deux fréquences."}],"transcriptStatus":"done","transcriptEngine":null,"summary":null}},52 {"type":"queryView","attrs":{"id":"d00000000c","source":"tasks","databaseId":null,"viewId":null,"filter":{"tag":"thèse","status":"open"},"layout":"list","limit":25,"title":"Tâches de la thèse"}},53 {"type":"drawing","attrs":{"id":"d00000000d","ink":\#(drawing.map { "\"\($0.id)\"" } ?? "null"),"preview":null,"pk":null,"width":640,"height":300,"background":"none"}},54 {"type":"aiBlock","attrs":{"id":"d00000000e","model":"claude-haiku-5.5","prompt":null,"at":null,"sources":[{"pageId":"\#(method)","blockId":"\#(block)","title":"Méthode d'estimation"}],"action":"synthesis"},"content":[{"type":"paragraph","attrs":{"id":"d00000000f"},"content":[{"type":"text","text":"En résumé : l'estimateur à noyau sur données à une minute est retenu, avec une comparaison à cinq minutes en annexe."}]}]},55 {"type":"hologram","attrs":{"id":"d00000000g","depth":3}},56 {"type":"bibliography","attrs":{"id":"d00000000h","style":"apa","title":"Références"}},57 {"type":"paragraph","attrs":{"id":"d00000000i"}}58 ]}59 """#60 guard let doc = try? NoteDocument(json: Data(json.utf8)), let data = try? doc.jsonData() else { NSLog("SPNotes demo: invalid document"); return }61 let digest = ContentDigest(document: doc)62 _ = try? await env.store.updateContent(id: main, content: data, plainText: digest.plainText, wordCount: digest.wordCount, preview: digest.preview)63 _ = await lib.newNote(title: "Résultats préliminaires", content: NoteDocument(markdown: "Les premiers résultats confirment la persistance de la volatilité.\n\n| Fréquence | RMSE |\n|---|---|\n| 1 min | 0.82 |\n| 5 min | 0.91 |"), tags: ["thèse"])64 _ = await lib.newNote(title: "Plan du chapitre 3", content: NoteDocument(markdown: "1. Données\n2. Estimateurs\n3. Prévision\n4. Robustesse"))65 _ = await lib.newNote(title: "Lectures", asFolder: true)66 let capture = QuickCapture(env: env)67 _ = await capture.capture(text: "Idée : comparer la volatilité réalisée à 1 min et à 5 min\nÀ creuser avec les données à la minute.", target: .inbox)68 _ = await capture.capture(text: "Article à lire\nhttps://example.org/realized-kernels", target: .inbox)69 _ = await capture.capture(text: "Appeler le comité pour la date de dépôt", target: .inbox)70 _ = await env.tasks.add("Envoyer le chapitre 3 au directeur", dueDay: day(0), priority: .high, pageId: main, blockId: "d00000002a")71 _ = await env.tasks.add("Relire la revue de littérature", dueDay: day(2)); _ = await env.tasks.add("Mettre à jour le graphique de volatilité", dueDay: day(-1), priority: .high)72 _ = await env.tasks.add("Réserver la salle de soutenance", dueDay: day(12), priority: .low); _ = await env.tasks.add("Trier la bibliographie")73 await lib.reload(); await env.inbox.load()74 }75 private static func day(_ offset: Int) -> String { TaskLevel.dayString(Date().addingTimeInterval(Double(offset) * 86_400)) }76}77#endif78