From 5c61196f27b9342e5f25414c11df5710f956f406 Mon Sep 17 00:00:00 2001 From: Christopher Warner Date: Sat, 10 Oct 2026 18:47:24 -0400 Subject: feat!: rewrite icloud-note CLI in Rust with chromiumoxide Replace the Node/Playwright driver with a single Rust binary so create/status stay headless without a visible browser. Move the previous implementation to legacy/nodejs for reference. BREAKING CHANGE: the supported CLI is the Rust `icloud-note` binary; the Node entrypoint is no longer installed by setup.sh. Co-authored-by: Cursor --- legacy/nodejs/scripts/lib/note-helpers.mjs | 88 ++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 legacy/nodejs/scripts/lib/note-helpers.mjs (limited to 'legacy/nodejs/scripts/lib/note-helpers.mjs') diff --git a/legacy/nodejs/scripts/lib/note-helpers.mjs b/legacy/nodejs/scripts/lib/note-helpers.mjs new file mode 100644 index 0000000..5dd43a0 --- /dev/null +++ b/legacy/nodejs/scripts/lib/note-helpers.mjs @@ -0,0 +1,88 @@ +/** + * Pure helpers for icloud-note (unit-tested; no Playwright). + */ + +/** Join title + body the way Apple Notes expects (first line = title). */ +export function formatNoteText(title, body) { + const t = title == null ? "" : String(title); + const b = body == null ? "" : String(body); + return [t, b].filter((s) => s.length > 0).join("\n\n"); +} + +/** True when a URL is clearly an Apple auth/sign-in page. */ +export function isAppleAuthUrl(url) { + return /idmsa\.apple\.com|appleid\.apple\.com/i.test(String(url || "")); +} + +/** + * Heuristic "logged out" detection from page signals (mirrors pageLooksLoggedOut). + * @param {{ url?: string, bodyText?: string, hasPasswordField?: boolean, hasSignInControl?: boolean, hasNotesApp?: boolean }} s + */ +export function looksLoggedOut(s = {}) { + if (isAppleAuthUrl(s.url)) return true; + const t = String(s.bodyText || "").slice(0, 4000); + if (/Sign in to iCloud/i.test(t)) return true; + if (s.hasPasswordField) return true; + if (s.hasSignInControl && !s.hasNotesApp) return true; + return false; +} + +/** Resolve XDG-style config paths (overridable via env for tests). */ +export function resolveConfigPaths(env = process.env, homedir = "") { + const home = + homedir || + env.HOME || + env.USERPROFILE || + "/tmp"; + const configDir = + env.ICLOUD_NOTES_CONFIG || `${home}/.config/icloud-notes`; + return { + configDir, + profileDir: `${configDir}/browser-profile`, + statePath: `${configDir}/storage-state.json`, + }; +} + +/** + * Parse create CLI flags (subset of node:util parseArgs shape). + * @returns {{ title: string, bodyFile?: string, body?: string, positionals: string[] }} + */ +export function parseCreateArgv(argv) { + const out = { title: "", body: undefined, bodyFile: undefined, positionals: [] }; + for (let i = 0; i < argv.length; i++) { + const a = argv[i]; + if (a === "--title") { + out.title = String(argv[++i] ?? ""); + } else if (a === "--body") { + out.body = String(argv[++i] ?? ""); + } else if (a === "--body-file") { + out.bodyFile = String(argv[++i] ?? ""); + } else if (a.startsWith("-")) { + throw new Error(`Unknown option: ${a}`); + } else { + out.positionals.push(a); + } + } + if (!out.title && out.positionals[0]) { + out.title = out.positionals[0]; + } + return out; +} + +/** Validate create has something to send. */ +export function requireCreateContent(title, body) { + const t = title == null ? "" : String(title); + const b = body == null ? "" : String(body).replace(/\s+$/, ""); + if (!t && !b) { + throw new Error("Provide --title and/or --body / --body-file / stdin"); + } + return { title: t, body: b }; +} + +/** Conventional Commits 1.0.0 subject line (first line of message). */ +export function isConventionalCommitSubject(subject) { + const line = String(subject || "").trim(); + return /^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9._/-]+\))?!?: .+/.test( + line, + ); +} -- cgit v1.2.3