From 8096d23e4f65c8709bfd6357971b7da88408e92e Mon Sep 17 00:00:00 2001 From: Utku Bilen Demir <84389167+UtkuBilenDemir@users.noreply.github.com> Date: Tue, 22 Sep 2026 01:02:32 +0200 Subject: [PATCH] hygiene: minimalist unification with chess tool (F tokens) + prune legacy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - plugin/manager.html: replace stark B mono (#ffffff/#0a0a0a, radius 0) with chess F Cleaned D+B tokens (#f8f8f8/#ddd, radius 8px, soft shadow, Inter + iA Writer Duo) — same :root, --bg/--panel/--line/--accent/--radius, unified tabs as underline (vs boxed), cards/tables/pills with shadow. Update inline JS styles (#0a0a0a -> var(--accent)/var(--line)) for reimport bar, infobox, status, artifacts. - plugin/bootstrap.js: remove 394 lines legacy static-dashboard code (openStaticDashboard, buildManagerHtml, conflictRows, groupedRows, tableRows, conflictTables, statusCards, countStatuses, escapeHtml, fileHref, artifactLink, importClippings, configure, pickDirectory) — now only manager pipeline + annotation writer remain (881 vs 1275 lines). - src/kindle_zotero_importer/cli.py: minimalist description, primary highlighted (others are developer utilities). - Build verified: tests pass, XPI rebuilt 23K, JS syntax ok. --- plugin/bootstrap.js | 394 ------------------------------ plugin/manager.html | 210 +++++++++------- src/kindle_zotero_importer/cli.py | 2 +- 3 files changed, 128 insertions(+), 478 deletions(-) diff --git a/plugin/bootstrap.js b/plugin/bootstrap.js index 9aa3412..63779a5 100644 --- a/plugin/bootstrap.js +++ b/plugin/bootstrap.js @@ -206,27 +206,6 @@ var KindleZoteroImporter = { return ok && value.value ? value.value : null; }, - async configure() { - const current = { - projectDir: this.getProjectDir(), - pythonPath: this.getPythonPath(), - zoteroDbPath: this.getZoteroDbPath(), - zoteroStorageRoot: this.getZoteroStorageRoot(), - }; - try { - const configPath = this.getConfigPath(); - await Zotero.File.putContentsAsync(configPath, JSON.stringify(current, null, 2) + "\n"); - this.alert( - "Kindle Zotero Importer Configuration", - `Configuration file written to:\n${configPath}\n\nEdit this file to change paths. The import dialog will show the active settings before running.` - ); - this.revealFile(configPath); - } catch (error) { - Zotero.logError(error); - this.alert("Kindle Zotero Importer Failed", String(error && error.stack ? error.stack : error)); - } - }, - async openManager() { if (this.managerWindow && !this.managerWindow.closed) { this.managerWindow.focus(); @@ -254,21 +233,6 @@ var KindleZoteroImporter = { }; }, - async openStaticDashboard() { - const settings = await this.getRuntimeSettings(); - const data = { - matches: await this.readJsonArtifact("matches.json"), - generatedOverrides: await this.readJsonArtifact("match-overrides.generated.json"), - positionedPlan: await this.readJsonArtifact("import-plan.positioned.json"), - finalPlan: await this.readJsonArtifact("import-plan.final.json"), - summary: await this.readJsonArtifact("plugin-summary.json"), - persistentOverrides: await this.readJsonArtifact("match-overrides.json"), - }; - const outputPath = this.artifactPath("kindle-import-manager.html"); - await Zotero.File.putContentsAsync(outputPath, this.buildManagerHtml(settings, data)); - this.openFile(outputPath); - }, - async loadOverridesFile() { const path = this.artifactPath("match-overrides.json"); try { @@ -355,337 +319,6 @@ var KindleZoteroImporter = { } }, - escapeHtml(value) { - return String(value ?? "") - .replaceAll("&", "&") - .replaceAll("<", "<") - .replaceAll(">", ">") - .replaceAll('"', """) - .replaceAll("'", "'"); - }, - - fileHref(path) { - return "file://" + encodeURI(path).replaceAll("#", "%23"); - }, - - artifactLink(label, relativePath) { - const path = this.artifactPath(relativePath); - return `${this.escapeHtml(label)}`; - }, - - countStatuses(items, key = "status") { - const counts = {}; - for (const item of items || []) { - const status = item[key] || "unknown"; - counts[status] = (counts[status] || 0) + 1; - } - return counts; - }, - - statusCards(counts) { - return Object.entries(counts || {}) - .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])) - .map(([status, count]) => `
${this.escapeHtml(count)}${this.escapeHtml(status)}
`) - .join("\n"); - }, - - conflictRows(data) { - const rows = []; - for (const match of data.matches?.matches || []) { - if (["matched", "ignored"].includes(match.status)) { - continue; - } - const candidates = (match.candidates || []) - .slice(0, 3) - .map((candidate) => `${candidate.citation_key || candidate.key || candidate.item_id}: ${candidate.title || ""}`) - .join("; "); - rows.push({ - type: "title-match", - status: match.status, - title: match.clipping_title, - count: match.clipping_count, - detail: candidates || "No candidates", - snippet: this.overrideSnippet(match.clipping_title, match.clipping_count, match.status, match.candidates?.[0]), - }); - } - - for (const override of data.generatedOverrides?.overrides || []) { - const candidateText = (override.candidates || []) - .slice(0, 3) - .map((candidate) => `${candidate.citation_key || candidate.key || candidate.item_id}: ${candidate.title || ""}`) - .join("; "); - rows.push({ - type: "override-suggestion", - status: override.review?.status || "review", - title: override.clipping_title, - count: override.review?.clipping_count || "", - detail: candidateText || override.notes || "Needs override decision", - snippet: JSON.stringify({ - clipping_title: override.clipping_title, - resolution: override.resolution || { ignore: false, citation_key: "" }, - review: override.review, - }, null, 2), - }); - } - - for (const item of data.positionedPlan?.items || []) { - const status = item.status || "unknown"; - if (["positioned", "ignored-title"].includes(status)) { - continue; - } - rows.push({ - type: "positioning/import-plan", - status, - title: item.clipping?.title || "(missing clipping title)", - count: 1, - detail: (item.problems || []).join("; ") || item.annotation?.text || "Needs review", - snippet: "Fix source data, attachment availability, or matching override; then rerun Import Kindle Clippings.", - }); - } - - return rows; - }, - - overrideSnippet(title, clippingCount, status, candidate) { - const resolution = candidate?.citation_key - ? { ignore: false, citation_key: candidate.citation_key } - : { ignore: true }; - return JSON.stringify({ - clipping_title: title, - resolution, - review: { - status, - clipping_count: clippingCount, - }, - }, null, 2); - }, - - groupedRows(rows) { - const groups = { - "Title Matching": [], - "Override Suggestions": [], - "Attachment / Positioning": [], - }; - for (const row of rows) { - if (row.type === "title-match") { - groups["Title Matching"].push(row); - } else if (row.type === "override-suggestion") { - groups["Override Suggestions"].push(row); - } else { - groups["Attachment / Positioning"].push(row); - } - } - return groups; - }, - - tableRows(rows, limit = 200) { - if (!rows.length) { - return 'No conflicts found in this group.'; - } - return rows.slice(0, limit).map((row) => ` - - ${this.escapeHtml(row.type)} - ${this.escapeHtml(row.status)} - ${this.escapeHtml(row.count)} - ${this.escapeHtml(row.title)} - ${this.escapeHtml(row.detail)} -
${this.escapeHtml(row.snippet || "")}
- `).join("\n"); - }, - - conflictTables(rows) { - const groups = this.groupedRows(rows); - return Object.entries(groups).map(([label, groupRows]) => ` -
-

${this.escapeHtml(label)} ${this.escapeHtml(groupRows.length)} rows

- - - ${this.tableRows(groupRows)} -
TypeStatusCountKindle TitleDetails / Candidate DifferencesOverride / Fix Snippet
-
`).join("\n"); - }, - - buildManagerHtml(settings, data) { - const matchCounts = this.countStatuses(data.matches?.matches || []); - const planCounts = data.positionedPlan?.status_counts || this.countStatuses(data.positionedPlan?.items || []); - const finalCount = data.finalPlan?.annotation_count || 0; - const skippedCounts = data.finalPlan?.skipped_counts || {}; - const conflicts = this.conflictRows(data); - const generatedAt = new Date().toLocaleString(); - return ` - - - - Kindle Zotero Importer Manager - - - - -

Kindle Zotero Importer Manager

-
Generated ${this.escapeHtml(generatedAt)} from ${this.escapeHtml(settings.projectDir)}
- - - -
- This dashboard is generated from importer artifacts. Copy override snippets into match-overrides.json for now, then rerun Import Kindle Clippings. Direct in-dashboard editing is the next step. -
- -

Settings

- - -

Run Import

-
- Run from Zotero: Tools > Import Kindle Clippings.... The import now shows preflight settings, progress, final counts, existing-comment updates, existing-sort-order repairs, and any guarded delete/recreate confirmations for kindle-import annotations. -
- -

Import Summary

-
-
${this.escapeHtml(data.summary?.counts?.clippings || "-")}clippings
-
${this.escapeHtml(data.summary?.counts?.unique_titles || "-")}unique titles
-
${this.escapeHtml(finalCount)}final annotations
-
${this.escapeHtml(conflicts.length)}conflict rows
-
- -

Match Statuses

-
${this.statusCards(matchCounts) || '
No match data yet
'}
- -

Plan Statuses

-
${this.statusCards(planCounts) || '
No plan data yet
'}
- -

Final Plan Skips

-
${this.statusCards(skippedCounts) || '
No skipped final annotations
'}
- -

Artifacts

- - -

Conflicts and Exceptions

-

Rows include unresolved title matches, generated override suggestions, attachment problems, and positioning failures. Use search to filter titles, statuses, citekeys, and candidate text. Showing first 200 rows per group.

- - ${this.conflictTables(conflicts)} - -`; - }, - - async importClippings() { - let progressWindow = null; - try { - const clippingsPath = await this.pickFile("Select Kindle My Clippings.txt", "*.txt"); - if (!clippingsPath) { - return; - } - - const settings = await this.getRuntimeSettings(); - const settingsMessage = [ - "Run Kindle import pipeline with these settings?", - "", - `Clippings: ${clippingsPath}`, - `Project directory: ${settings.projectDir}`, - `Python: ${settings.pythonPath}`, - `Zotero DB: ${settings.zoteroDbPath}`, - `Zotero storage: ${settings.zoteroStorageRoot}`, - `Config file: ${this.getConfigPath()}`, - "", - "This first creates/updates review files. You can choose whether to import annotations after the summary.", - ].join("\n"); - if (!Services.prompt.confirm(this.getMainWindow(), "Kindle Zotero Importer", settingsMessage)) { - return; - } - - progressWindow = this.createProgress("Starting Kindle import..."); - if (progressWindow) { - progressWindow.changeHeadline("Kindle Zotero Importer: reading clippings"); - } - const summary = await this.runPipeline(clippingsPath, settings); - if (progressWindow && progressWindow.progress) { - progressWindow.progress.setProgress(100); - progressWindow.changeHeadline("Kindle Zotero Importer: pipeline complete"); - } - const finalPlanPath = summary.outputs.final_plan; - const finalPlan = JSON.parse(await Zotero.File.getContentsAsync(finalPlanPath)); - this.notify( - `Pipeline completed. ${summary.counts.final_annotations || 0} final annotations ready.`, - true - ); - - const decision = this.confirmImport(summary); - if (decision === "review") { - this.revealFile(summary.outputs.mismatch_review); - return; - } - if (decision !== "import") { - return; - } - - if (progressWindow) { - progressWindow.changeHeadline("Kindle Zotero Importer: writing annotations"); - } - const results = await this.writeAnnotations(finalPlan, false); - this.notify( - `Import finished. Created ${results.created}; skipped ${results.skippedExisting}; updated order ${results.updatedSortIndex}; recreated ${results.recreatedForSortIndex}; failed ${results.failed.length}.`, - results.failed.length === 0 - ); - this.alert("Kindle Zotero Importer", this.formatWriterResults(results)); - } catch (error) { - Zotero.logError(error); - this.notify("Import failed. See the error dialog for details.", false); - this.alert("Kindle Zotero Importer Failed", String(error && error.stack ? error.stack : error)); - } finally { - if (progressWindow && progressWindow.startCloseTimer) { - progressWindow.startCloseTimer(1000); - } - } - }, - async pickFile(title, filter) { try { const pickerModule = ChromeUtils.importESModule( @@ -717,33 +350,6 @@ var KindleZoteroImporter = { } }, - async pickDirectory(title) { - try { - const pickerModule = ChromeUtils.importESModule( - "chrome://zotero/content/modules/filePicker.mjs" - ); - const FilePicker = pickerModule.FilePicker; - if (typeof FilePicker !== "function") { - throw new Error(`Zotero FilePicker module did not export a constructor: ${Object.keys(pickerModule)}`); - } - const fp = new FilePicker(); - fp.init(this.getPickerWindow(), title, fp.modeGetFolder); - - const result = await fp.show(); - if (result !== fp.returnOK) { - return null; - } - return fp.file; - } catch (error) { - Zotero.logError(error); - return this.promptForPath( - "Kindle Zotero Importer", - "Folder picker failed. Enter the full project directory path:", - this.defaultProjectDir - ); - } - }, - async runPipeline(clippingsPath, settings, isFull = false) { const python = settings.pythonPath; const projectDir = settings.projectDir; diff --git a/plugin/manager.html b/plugin/manager.html index 74fc276..d0f494c 100644 --- a/plugin/manager.html +++ b/plugin/manager.html @@ -4,26 +4,54 @@ Kindle Zotero Importer