lllin000_PaperForge/paperforge/plugin/main.js
LLLin000 b4ac277438 Merge branch 'feat/retrieval-recovery'
# Conflicts:
#	paperforge/commands/embed.py
2026-07-11 01:26:37 +08:00

7593 lines
267 KiB
JavaScript

"use strict";
var Dt = Object.create;
var Ie = Object.defineProperty;
var Bt = Object.getOwnPropertyDescriptor;
var At = Object.getOwnPropertyNames;
var Ot = Object.getPrototypeOf,
Lt = Object.prototype.hasOwnProperty;
var It = (u, h) => () => (h || u((h = { exports: {} }).exports, h), h.exports),
Mt = (u, h) => {
for (var e in h) Ie(u, e, { get: h[e], enumerable: !0 });
},
at = (u, h, e, t) => {
if ((h && typeof h == "object") || typeof h == "function")
for (let r of At(h))
!Lt.call(u, r) &&
r !== e &&
Ie(u, r, {
get: () => h[r],
enumerable: !(t = Bt(h, r)) || t.enumerable,
});
return u;
};
var V = (u, h, e) => (
(e = u != null ? Dt(Ot(u)) : {}),
at(
h || !u || !u.__esModule
? Ie(e, "default", { value: u, enumerable: !0 })
: e,
u
)
),
Nt = (u) => at(Ie({}, "__esModule", { value: !0 }), u);
var Je = It((Jt, zt) => {
zt.exports = {
versions: [
{
version: "1.5.15",
date: "2026-06-01",
title:
"\u5168\u6587\u5B58\u50A8\u91CD\u6784 + OCR \u9605\u8BFB\u987A\u5E8F\u4FEE\u590D + Redo \u4E00\u952E\u91CD\u505A",
breaking_or_migration: [
"\u5168\u6587\u6587\u4EF6\u73B0\u5728\u7EDF\u4E00\u5B58\u653E\u4E8E System/PaperForge/ocr/ \u4E0B\uFF0C\u4E0D\u518D\u5728\u5DE5\u4F5C\u533A\u4FDD\u7559\u526F\u672C",
"Redo OCR \u73B0\u5728\u4F1A\u7ACB\u5373\u6267\u884C\uFF08\u4E00\u952E\u5B8C\u6210\uFF09\uFF0C\u4E0D\u518D\u9700\u8981\u624B\u52A8\u518D\u8DD1\u4E00\u6B21",
],
new_features: [
"Redo OCR \u4E00\u952E\u95ED\u73AF\uFF1A\u52FE\u9009 \u2192 \u70B9\u6309\u94AE \u2192 \u81EA\u52A8\u5B8C\u6210\u5168\u90E8\u6D41\u7A0B",
"\u8BBE\u7F6E\u9875\u65B0\u589E\u300C\u66F4\u65B0\u4E0E\u624B\u518C\u300D\u6807\u7B7E\u9875\uFF0C\u53EF\u968F\u65F6\u67E5\u770B\u7248\u672C\u66F4\u65B0\u8BB0\u5F55\u548C\u4F7F\u7528\u624B\u518C",
"\u63D2\u4EF6\u66F4\u65B0\u540E\u81EA\u52A8\u5F39\u51FA\u66F4\u65B0\u8BF4\u660E",
],
fixes: [
"\u4FEE\u590D\u5168\u6587\u9605\u8BFB\u987A\u5E8F\u6DF7\u4E71\uFF0C\u4F18\u5316\u6574\u4F53\u6392\u7248\u4F53\u9A8C",
"\u4FEE\u590D\u7AE0\u8282\u6807\u9898\u548C\u6B63\u6587\u6BB5\u843D\u9519\u4F4D\u65AD\u5F00\u7684\u95EE\u9898",
"\u4FEE\u590D\u56FE\u8868\u548C\u5BF9\u5E94\u56FE\u6CE8\u88AB\u5206\u5F00\u7684\u95EE\u9898",
"\u4FEE\u590D\u9996\u9875\u6458\u8981\u533A\u5757\u6392\u5E8F\u5F02\u5E38",
"\u4FEE\u590D\u5E76\u6392\u56FE\u7247\u672A\u80FD\u81EA\u52A8\u5408\u5E76\u7684\u95EE\u9898",
"Dashboard \u73B0\u5728\u80FD\u6B63\u786E\u8BC6\u522B\u65B0\u7684\u5168\u6587\u6587\u4EF6\u4F4D\u7F6E",
],
recommended_actions: [
"\u65E7\u7248 OCR \u5168\u6587\u53EF\u80FD\u5B58\u5728\u9605\u8BFB\u987A\u5E8F\u95EE\u9898\uFF0C\u5EFA\u8BAE\u5BF9\u91CD\u8981\u8BBA\u6587\u6267\u884C\u4E00\u6B21 Redo OCR",
"\u6253\u5F00\u5168\u6587\u8BF7\u76F4\u63A5\u4F7F\u7528 Dashboard \u7684\u300C\u6253\u5F00\u5168\u6587\u300D\u6309\u94AE",
],
},
],
};
});
var Wt = {};
Mt(Wt, { default: () => Ke });
module.exports = Nt(Wt);
var U = require("obsidian"),
W = V(require("fs")),
Se = V(require("path")),
pe = require("child_process");
var ve = "paperforge-status",
Fe = "paperforge",
it =
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"></path><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"></path><line x1="8" y1="7" x2="16" y2="7"></line><line x1="8" y1="11" x2="14" y2="11"></line></svg>',
se = [
{
id: "paperforge-sync",
title: "Sync Library",
desc: "Pull new references from Zotero and generate literature notes",
icon: "\u21BB",
cmd: "sync",
okMsg: "Sync complete",
},
{
id: "paperforge-ocr",
title: "Run OCR",
desc: "Extract full text and figures from PDFs via PaddleOCR",
icon: "\u229E",
cmd: "ocr",
okMsg: "OCR started",
},
{
id: "paperforge-doctor",
title: "Run Doctor",
desc: "Verify PaperForge setup \u2014 check configs, Zotero, paths, and index health",
icon: "\u2695",
cmd: "doctor",
okMsg: "Doctor complete",
},
{
id: "paperforge-repair",
title: "Repair Issues",
desc: "Fix three-way state divergence, path errors, and rebuild index",
icon: "\u21BA",
cmd: "repair",
args: ["--fix", "--fix-paths"],
okMsg: "Repair complete",
},
{
id: "paperforge-ocr-redo",
title: "Redo OCR",
desc: "Re-run OCR for papers marked ocr_redo: true",
icon: "\u21BA",
cmd: "ocr",
args: ["redo"],
okMsg: "OCR redo started",
},
],
Re = {
vault_path: "",
setup_complete: !1,
auto_update: !0,
auto_update_on_startup: !0,
agent_platform: "opencode",
language: "",
paddleocr_api_key: "",
zotero_data_dir: "",
python_path: "",
features: { memory_layer: !0, vector_db: !1 },
selected_skill_platform: "opencode",
vector_db_api_key: "",
vector_db_api_base: "",
vector_db_api_model: "text-embedding-3-small",
frozen_skills: {},
system_dir: "",
resources_dir: "",
literature_dir: "",
base_dir: "",
last_seen_version: "",
};
function ot(u, h) {
if (!h || !h.note_path) return h;
let e = u.vault.getAbstractFileByPath(h.note_path);
if (!e) return h;
let t = u.metadataCache.getFileCache(e),
r = t && t.frontmatter;
if (!r) return h;
let n = { ...h };
for (let a of [
"do_ocr",
"analyze",
"ocr_status",
"ocr_redo",
"deep_reading_status",
])
Object.prototype.hasOwnProperty.call(r, a) && (n[a] = r[a]);
return n;
}
function Ze(u, h) {
return u && { ...u, ...h };
}
var qe = {
en: {
action_running: "Running ",
api_key_missing: "Missing",
api_key_set: "Entered",
btn_install: "Open Setup Wizard",
btn_install_desc:
"Check whether the environment is ready, then open the step-by-step setup wizard",
btn_reconfig: "Reconfigure",
btn_reconfig_desc:
"Open the setup wizard again to change directories, platform, or API keys",
btn_validate: "Validate",
check_bbt_fail: "Not detected",
check_bbt_ok: "Installed",
check_python_fail: "Not found",
check_python_ok: "Ready",
check_zotero_fail: "Not detected",
check_zotero_ok: "Found",
complete_export_path: "Save Better BibTeX JSON exports into:",
complete_next: "Recommended next steps",
complete_step1: "Open Dashboard",
complete_step1_desc:
'Press Ctrl+P and run "PaperForge: Open Main Panel", or click the PaperForge icon in the left sidebar.',
complete_step2: "Sync Literature",
complete_step2_desc:
"In the main panel, click Sync Library to bring papers from Zotero into Obsidian and generate notes.",
complete_step3: "Run OCR",
complete_step3_desc:
"In the Obsidian Base view, mark do_ocr:true on papers, then run OCR in the main panel.",
complete_step4: "Configure Better BibTeX Auto-export",
complete_step4_desc:
'In Zotero, right-click the library or collection you want to sync -> Export -> Better BibTeX JSON -> enable "Keep updated".',
complete_summary: "Saved Configuration",
complete_title: "Setup Complete",
copied: "Copied!",
copy_pf_deep_cmd: "Copy /pf-deep Command",
dashboard_drift_warning:
"PaperForge CLI (v{0}) differs from plugin (v{1}). Open Settings \u2192 Runtime Health to sync.",
deep_reading_not_found: "Deep reading file not found",
desc: "Obsidian + Zotero literature pipeline. Sync papers, generate notes, run OCR, and read deeply in one place.",
dir_base: "Base Dir",
dir_index: "Index Dir",
dir_notes: "Notes Dir",
dir_resources: "Resource Dir",
dir_system: "System Dir",
dir_vault: "Vault Path",
error_copied: "Copied!",
error_copy_diagnostic: "Copy diagnostic",
feat_agent_platform: "Agent Platform",
feat_agent_platform_desc:
"Select which agent platform to manage skills for.",
feat_api_base_url: "API Base URL",
feat_api_base_url_desc:
"Custom OpenAI-compatible API endpoint. Leave empty for default.",
feat_api_model: "API Model",
feat_api_model_desc: "Embedding model name for this endpoint.",
feat_build_btn: "Build",
feat_build_complete: "Vector build complete.",
feat_build_failed: "Build failed. See terminal output.",
feat_building: "Building...",
feat_cache_remove_failed: "Failed: {0}",
feat_cache_removed: "Model cache removed.",
feat_checking: "Checking...",
feat_checking_btn: "Checking...",
feat_deps_checking: "Checking dependencies...",
feat_deps_missing:
"Dependencies not installed. Required: chromadb, openai.",
feat_enter_key: "Enter a valid OpenAI API key.",
feat_install_btn: "Install",
feat_install_deps: "Install Dependencies",
feat_install_deps_desc: "pip install chromadb openai (~35MB).",
feat_install_done: "Dependencies installed. Building vectors...",
feat_install_failed: "Install failed: ",
feat_installing: "Installing...",
feat_installing_pkgs: "Installing {pkgs}...",
feat_key_rejected: "API key rejected.",
feat_memory_desc:
"The Memory Layer is the core data engine of PaperForge, powered by SQLite. It integrates literature metadata (papers, assets, aliases, reading events), provides FTS5 metadata search across titles, abstracts, authors, domains, and collections, and powers agent-context and paper-status. Always active \u2014 no toggle needed.",
feat_memory_rebuild_btn: "Rebuild",
feat_memory_rebuild_done: "Memory DB rebuilt.",
feat_memory_rebuild_failed: "Rebuild failed.",
feat_memory_rebuilding: "Rebuilding...",
feat_model_changed_warn:
"Model changed ({0} -> {1}). Existing vectors are incompatible \u2014 rebuild required.",
feat_network_error: "Network error: ",
feat_no_python: "No Python found. Check Installation tab.",
feat_not_cached: "Not cached",
feat_openai_key: "OpenAI API Key",
feat_openai_key_desc:
"Used for API embedding calls. Model is defined below.",
feat_output_copied: "Output copied to clipboard.",
feat_rebuild_btn: "Rebuild",
feat_rebuild_vectors: "Rebuild Vectors",
feat_rebuild_vectors_changed:
"Model changed \u2014 rebuild to update all vectors.",
feat_rebuild_vectors_desc:
"Rebuild all OCR fulltext vectors. Required after model or mode change.",
feat_removing: "Removing...",
feat_retry_btn: "Retry",
feat_skills_desc:
"Manage and enable/disable agent skills installed in your vault. Each row corresponds to a SKILL.md file \u2014 toggle off to prevent the agent from auto-invoking that skill.",
feat_skills_system:
"System Skills ship with PaperForge and are updated alongside PaperForge.",
feat_skills_user:
"User Skills are custom skills you install from community or create yourself.",
feat_uninstall_btn: "Uninstall",
feat_valid_key: "API key valid.",
feat_vector_config_label: "Vector Settings",
feat_vector_corrupted:
"Vector index corrupted \u2014 needs force rebuild.",
feat_vector_desc:
"Vector Database enables semantic search across OCR-extracted fulltext via API embedding. Documents are split into chunks, embedded via OpenAI-compatible API, and stored in ChromaDB.",
feat_vector_enable: "Enable Vector Retrieval",
feat_vector_enable_desc:
"Semantic search across OCR fulltext. Requires: pip install openai chromadb (~35MB).",
feat_vector_rebuild_force_btn: "Force Rebuild",
feat_verify: "Verify",
feat_verify_btn: "Verify",
field_paddleocr: "PaddleOCR API Key",
field_python_custom: "Custom Path",
field_python_interp: "Python Interpreter",
field_zotero_data: "Zotero Data Dir",
field_zotero_placeholder:
"Required. Path to Zotero data directory for PDF attachment resolution.",
guide_ocr: "Run OCR",
guide_ocr_desc:
"In the main panel, click Run OCR to extract full text and figures from PDFs for later reading and analysis.",
guide_open: "Open Main Panel",
guide_open_desc:
'Press Ctrl+P and run "PaperForge: Open Main Panel", or click the PaperForge icon in the left sidebar.',
guide_sync: "Sync Literature",
guide_sync_desc:
"After Better BibTeX JSON export is configured, click Sync Library to import papers from Zotero into Obsidian and generate notes automatically.",
header_title: "PaperForge",
install_bootstrapping:
"PaperForge Python package not found. Installing automatically...",
install_btn: "Start Install",
install_btn_retry: "Retry",
install_btn_running: "Installing...",
install_complete: "Installation complete!",
install_failed: "Installation failed: ",
install_validating: "Validating setup...",
jump_to_deep_reading: "Open Deep Reading",
label_agent: "Agent Platform",
nav_close: "Close",
nav_next: "Next",
nav_prev: "Back",
not_set: "Not entered",
notice_check_fail: "Missing: ",
notice_python_missing:
"Python was not detected. Install Python 3.10+ and add it to PATH.",
ocr_privacy_title: "OCR Privacy Notice",
ocr_privacy_warning:
"OCR will upload PDFs to the PaddleOCR API. Do not upload sensitive or confidential documents.",
ocr_queue_add: "Add to OCR Queue",
ocr_queue_added: "Added to OCR queue",
ocr_queue_remove: "Remove from OCR Queue",
ocr_queue_removed: "Removed from OCR queue",
ocr_understand: "I understand, continue",
optional_later: "(can be set later in Settings)",
orphan_delete_failed: "Prune failed",
orphan_delete_selected: "Delete {count} selected",
orphan_deleted: "Deleted {count} orphan workspace(s)",
orphan_desc: "These papers are no longer in your Zotero library.",
orphan_deselect_all: "Deselect all",
orphan_explain: "Removed from Zotero. Workspace files remain on disk.",
orphan_keep_all: "Keep all",
orphan_none_selected: "No papers selected for deletion",
orphan_select_all: "Select all",
orphan_title: "Found {count} orphan paper(s)",
panel_actions: "Quick Actions",
prep_bbt: "Better BibTeX",
prep_bbt_desc: "In Zotero: Tools -> Add-ons -> install Better BibTeX.",
prep_export: "Better BibTeX Auto-export",
prep_export_desc:
'In Zotero, right-click the collection you want to sync -> Export Collection -> BetterBibTeX JSON -> enable "Keep updated" -> save the JSON file into the exports folder shown below. Obsidian Base views will use the JSON filename as the Base name:',
prep_export_path_label: "Save the exported JSON file into this folder:",
prep_key: "PaddleOCR Key",
prep_key_desc:
"Get your API key from https://aistudio.baidu.com/paddleocr",
prep_python: "Python 3.10+",
prep_python_desc:
"Python must be available from the command line. If you are not sure, click below to auto-detect.",
prep_zotero: "Zotero Desktop",
prep_zotero_desc: "Install Zotero from https://www.zotero.org",
run_in_agent: "Run in {0}",
runtime_health: "Runtime Health",
runtime_health_checking: "Checking...",
runtime_health_desc:
"Check whether the installed paperforge Python package matches the plugin version and whether the deployed skill contract is current.",
runtime_health_match: "Match",
runtime_health_mismatch: "Mismatch",
runtime_health_package_ver: "Python package v{0}",
runtime_health_plugin_ver: "Plugin v{0}",
runtime_health_sync: "Sync Runtime",
runtime_health_sync_done: "Runtime synced to v{0}",
runtime_health_sync_fail: "Sync failed: {0}",
runtime_health_syncing: "Syncing...",
section_config: "Current Configuration",
section_guide: "How To Use",
section_prep: "Preparation",
section_prep_desc:
"Before first use, finish these 4 preparation items. Better BibTeX auto-export is configured after setup:",
setup_done: "PaperForge environment is ready",
setup_pending:
"Not installed yet. Finish the preparation items below, then open the wizard.",
tab_features: "Features",
tab_setup: "Installation",
tab_maintenance: "Maintenance",
validate_base: "Base directory is required",
validate_fail: "Please complete the required fields below",
validate_index: "Index directory is required",
validate_key: "PaddleOCR API key (optional, needed for OCR)",
validate_notes: "Notes directory is required",
validate_resources: "Resources directory is required",
validate_system: "System directory is required",
validate_vault: "Vault path is required",
validate_zotero:
"Zotero data directory (optional, needed for PDF linking)",
wizard_agent_hint:
"Choose the AI agent platform you use most often. PaperForge will place the matching command and skill files in the correct location.",
wizard_dir_hint:
"PaperForge stores user-facing literature data under the resources directory. These folders will live there:",
wizard_dir_sub_hint: "Resolved folder preview based on the names below:",
wizard_intro:
"This wizard walks you through the full setup. In most cases, the default values are fine to keep.",
wizard_keys_hint:
"Enter your PaddleOCR API key below. If you want PaperForge to auto-locate Zotero PDFs, you can also fill in the Zotero data directory.",
wizard_preview:
"After installation, system files stay at the vault root while literature data stays under the resources directory.",
wizard_safety:
"Safety: if the selected folders already contain files, setup preserves existing files and only creates missing PaperForge folders and files.",
wizard_step1: "Overview",
wizard_step2: "Directory Setup",
wizard_step3: "Platform & Keys",
wizard_step4: "Install",
wizard_step5: "Done",
wizard_skip_ocr_desc:
"OCR will not be available until you configure a valid PaddleOCR API key. You can continue setup now and configure it later in Settings.",
wizard_skip_ocr_continue: "Continue without OCR key",
wizard_skip_ocr_back: "Back to configure",
wizard_api_hint_skip:
"OCR key is optional \u2014 you may skip it and configure later.",
wizard_sys_hint:
"These folders live at the vault root, outside the resources directory:",
wizard_title: "PaperForge Setup Wizard",
ocr_maint_no_action: "No Action Needed",
ocr_maint_rebuild: "Rebuild Recommended",
ocr_maint_failed: "OCR Failed",
ocr_maint_limited: "Result Limited",
ocr_maint_needs_attention: "Needs Attention",
ocr_maint_limitations: "Result Limitations",
ocr_maint_hero_ok: "OCR looks usable overall.",
ocr_maint_hero_warn:
"OCR needs attention: {rebuild} rebuild recommended, {failed} failed.",
ocr_maint_hero_note:
"This page only promotes issues where maintenance is likely to help. Some papers may have limitations that maintenance will not improve.",
ocr_maint_limitations_intro:
"These papers look less certain, but PaperForge does not currently have a high-confidence maintenance action to recommend.",
ocr_maint_all_papers: "All Papers",
ocr_maint_rebuild_btn: "Rebuild results",
ocr_maint_redo_btn: "Rerun OCR",
maintenance_group_retry: "Needs Retry",
maintenance_group_rebuild: "Can Rebuild",
maintenance_group_legacy: "Upgrade Available (Optional)",
maintenance_btn_retry: "Retry",
maintenance_btn_rebuild: "Rebuild",
maintenance_btn_upgrade: "Upgrade",
maintenance_refresh_spinning: "Updating\u2026",
maintenance_all_good: "\u2705 All good \u2014 no action needed",
maintenance_n_pending: "{n} need attention",
version_panel_title: "Version History",
version_panel_back: "Back",
version_filter_placeholder: "Filter papers...",
version_papers_count: "{n} papers",
version_current: "current",
version_restore_btn: "Restore",
version_compare_btn: "Compare",
version_restore_selected: "Restore selected",
version_clear_old: "Clear old versions (free {size})",
version_no_backups: "No version history available",
version_restore_confirm: "Restore {label} for {paper}?",
version_restore_done: "Restored {label}",
version_compare_title: "{vA} vs {vB}",
version_compare_paragraphs: "{n} paragraphs changed",
version_error_read: "Cannot read version data",
retrieval_search_placeholder: "Search papers... (@ for deep search)",
retrieval_search_placeholder_deep: "Search papers via deep retrieval...",
retrieval_search_idle_hint:
"Type to search metadata, or start with @ for deep semantic search",
retrieval_searching_metadata: "Searching metadata...",
retrieval_searching_deep: "Running deep search...",
retrieval_search_cancel: "Cancel",
retrieval_results_count: "{n} result{s}",
retrieval_empty: "No matching papers found.",
retrieval_empty_tips: "Try broader terms or @ deep search.",
retrieval_vectors_not_built: "Vectors Not Built",
retrieval_vectors_not_built_desc:
"Vector index has not been built. Search requires a built vector index.",
retrieval_open_vector_settings: "Open Vector Settings",
retrieval_backend_unavailable: "Backend Unavailable",
retrieval_backend_unavailable_desc:
"The Python CLI search backend is not responding.",
retrieval_run_doctor: "Run Doctor",
retrieval_retry: "Retry",
retrieval_timeout_title: "Search Timed Out",
retrieval_timeout_desc:
"The search took too long. You can retry or try a simpler query.",
retrieval_model_changed: "Model Changed",
retrieval_model_changed_desc:
"The embedding model has changed since vectors were built. Rebuilding is required.",
retrieval_rebuild_vectors: "Rebuild Vectors",
retrieval_internal_error:
"An internal error occurred. Check the console for details.",
retrieval_build_idle: "Vectors not yet built",
retrieval_build_ready: "Vectors ready",
retrieval_build_stopping: "Stopping...",
retrieval_build_stopped: "Build stopped. Resume to continue.",
retrieval_build_failed: "Build failed",
retrieval_build_stale:
"Previous build was interrupted. Resume to continue.",
retrieval_build_deps_missing: "Dependencies not installed",
retrieval_build_runtime_mismatch: "Plugin and CLI versions differ",
retrieval_stop: "Stop",
retrieval_force_rebuild: "Force Rebuild",
retrieval_rebuild_warning:
"Rebuild will replace {n} existing chunk(s). Continue?",
retrieval_no_python: "No Python found. Check Installation tab.",
},
zh: {
action_running: "\u6B63\u5728\u6267\u884C ",
api_key_missing: "\u672A\u914D\u7F6E \u2717",
api_key_set: "\u5DF2\u914D\u7F6E \u2713",
btn_install: "\u6253\u5F00\u5B89\u88C5\u5411\u5BFC",
btn_install_desc:
"\u81EA\u52A8\u68C0\u6D4B Python + \u524D\u7F6E\u73AF\u5883\uFF0C\u901A\u8FC7\u540E\u6253\u5F00\u5206\u6B65\u5B89\u88C5\u5411\u5BFC",
btn_reconfig: "\u91CD\u65B0\u914D\u7F6E",
btn_reconfig_desc:
"\u91CD\u65B0\u8FD0\u884C\u5B89\u88C5\u5411\u5BFC\uFF0C\u4FEE\u6539\u76EE\u5F55\u6216\u5BC6\u94A5\u914D\u7F6E",
btn_validate: "\u9A8C\u8BC1",
check_bbt_fail: "\u672A\u68C0\u6D4B\u5230",
check_bbt_ok: "\u5DF2\u5B89\u88C5",
check_python_fail: "\u672A\u5B89\u88C5",
check_python_ok: "\u5DF2\u5C31\u7EEA",
check_zotero_fail: "\u672A\u68C0\u6D4B\u5230",
check_zotero_ok: "\u5DF2\u5B89\u88C5",
complete_next: "\u4E0B\u4E00\u6B65\u64CD\u4F5C",
complete_step1: "\u6253\u5F00 PaperForge Dashboard",
complete_step1_desc:
"Ctrl+P \u2192 \u8F93\u5165 PaperForge: Open Dashboard\uFF0C\u6216\u70B9\u5DE6\u4FA7\u4E66\u672C\u56FE\u6807",
complete_step2: "\u540C\u6B65\u6587\u732E",
complete_step2_desc:
"Dashboard \u4E2D\u70B9 Sync Library\uFF0C\u4ECE Zotero \u62C9\u53D6\u6587\u732E\u751F\u6210\u7B14\u8BB0",
complete_step3: "\u8FD0\u884C OCR",
complete_step3_desc:
"Dashboard \u4E2D\u70B9 Run OCR\uFF0C\u63D0\u53D6 PDF \u5168\u6587\u4E0E\u56FE\u8868",
complete_step4: "\u914D\u7F6E BBT \u81EA\u52A8\u5BFC\u51FA",
complete_summary: "\u5F53\u524D\u5B8C\u6574\u914D\u7F6E",
complete_title: "\u2713 PaperForge \u5B89\u88C5\u5B8C\u6210",
copied: "\u5DF2\u590D\u5236\uFF01",
copy_pf_deep_cmd: "\u590D\u5236 /pf-deep \u547D\u4EE4",
dashboard_drift_warning:
'\u63D2\u4EF6\u7248\u672C\u4E0E Python \u8FD0\u884C\u65F6\u7248\u672C\u4E0D\u5339\u914D\u3002\u8BF7\u5728\u8BBE\u7F6E\u4E2D\u70B9\u51FB"\u540C\u6B65\u8FD0\u884C\u65F6"\u3002',
deep_reading_not_found: "\u7CBE\u8BFB\u6587\u4EF6\u672A\u627E\u5230",
desc: "Obsidian + Zotero \u6587\u732E\u7BA1\u7406\u6D41\u6C34\u7EBF\u3002\u81EA\u52A8\u540C\u6B65\u6587\u732E\u3001\u751F\u6210\u7B14\u8BB0\u3001OCR \u63D0\u53D6\u5168\u6587\uFF0C\u4E00\u7AD9\u5F0F\u6587\u732E\u7CBE\u8BFB\u5DE5\u4F5C\u6D41\u3002",
dir_base: "Base \u76EE\u5F55",
dir_index: "\u7D22\u5F15\u76EE\u5F55",
dir_notes: "\u6B63\u6587\u76EE\u5F55",
dir_resources: "\u8D44\u6E90\u76EE\u5F55",
dir_system: "\u7CFB\u7EDF\u76EE\u5F55",
dir_vault: "Vault \u8DEF\u5F84",
error_copied: "\u5DF2\u590D\u5236\uFF01",
error_copy_diagnostic: "\u590D\u5236\u8BCA\u65AD\u4FE1\u606F",
feat_agent_platform: "Agent \u5E73\u53F0",
feat_agent_platform_desc:
"\u9009\u62E9\u8981\u7BA1\u7406\u7684 Agent \u5E73\u53F0\u3002",
feat_api_base_url: "API \u5730\u5740",
feat_api_base_url_desc:
"\u81EA\u5B9A\u4E49 OpenAI \u517C\u5BB9 API \u7AEF\u70B9\u3002\u7559\u7A7A\u4F7F\u7528\u9ED8\u8BA4\u5730\u5740\u3002",
feat_api_model: "API \u6A21\u578B",
feat_api_model_desc:
"\u8BE5\u7AEF\u70B9\u4F7F\u7528\u7684\u5D4C\u5165\u6A21\u578B\u540D\u79F0\u3002",
feat_build_btn: "\u6784\u5EFA",
feat_build_complete: "\u5411\u91CF\u6784\u5EFA\u5B8C\u6210\u3002",
feat_build_failed:
"\u6784\u5EFA\u5931\u8D25\u3002\u8BF7\u67E5\u770B\u7EC8\u7AEF\u8F93\u51FA\u3002",
feat_building: "\u6784\u5EFA\u4E2D\u2026",
feat_cache_remove_failed: "\u5931\u8D25\uFF1A{0}",
feat_cache_removed: "\u6A21\u578B\u7F13\u5B58\u5DF2\u6E05\u9664\u3002",
feat_checking: "\u68C0\u6D4B\u4E2D\u2026",
feat_checking_btn: "\u68C0\u6D4B\u4E2D\u2026",
feat_deps_checking: "\u6B63\u5728\u68C0\u6D4B\u4F9D\u8D56\u2026",
feat_deps_missing:
"\u4F9D\u8D56\u672A\u5B89\u88C5\u3002\u9700\u8981\uFF1Achromadb, openai\u3002",
feat_enter_key:
"\u8BF7\u8F93\u5165\u6709\u6548\u7684 OpenAI API Key\u3002",
feat_install_btn: "\u5B89\u88C5",
feat_install_deps: "\u5B89\u88C5\u4F9D\u8D56",
feat_install_done:
"\u4F9D\u8D56\u5DF2\u5B89\u88C5\u3002\u6B63\u5728\u6784\u5EFA\u5411\u91CF\u2026",
feat_install_failed: "\u5B89\u88C5\u5931\u8D25\uFF1A",
feat_installing: "\u5B89\u88C5\u4E2D\u2026",
feat_installing_pkgs: "\u6B63\u5728\u5B89\u88C5 {pkgs}...",
feat_key_rejected: "API Key \u88AB\u62D2\u7EDD\u3002",
feat_memory_desc:
"\u8BB0\u5FC6\u5C42\u662F PaperForge \u7684\u6838\u5FC3\u6570\u636E\u5F15\u64CE\uFF0C\u57FA\u4E8E SQLite \u6784\u5EFA\u3002\u5B83\u6574\u5408\u4E86\u6587\u732E\u5143\u6570\u636E\uFF08\u8BBA\u6587\u3001\u8D44\u6E90\u6587\u4EF6\u3001\u522B\u540D\u3001\u9605\u8BFB\u4E8B\u4EF6\uFF09\uFF0C\u652F\u6301 FTS5 \u5143\u6570\u636E\u68C0\u7D22\uFF08\u6807\u9898\u3001\u6458\u8981\u3001\u4F5C\u8005\u3001domain\u3001collection\uFF09\uFF0C\u5E76\u4E3A agent-context \u548C paper-status \u547D\u4EE4\u63D0\u4F9B\u6570\u636E\u652F\u6491\u3002\u59CB\u7EC8\u8FD0\u884C\uFF0C\u65E0\u9700\u624B\u52A8\u5F00\u542F\u3002",
feat_memory_rebuild_btn: "\u91CD\u5EFA\u6570\u636E\u5E93",
feat_memory_rebuild_done:
"\u8BB0\u5FC6\u6570\u636E\u5E93\u91CD\u5EFA\u5B8C\u6210\u3002",
feat_memory_rebuild_failed: "\u91CD\u5EFA\u5931\u8D25\u3002",
feat_memory_rebuilding: "\u91CD\u5EFA\u4E2D\u2026",
feat_model: "\u6A21\u578B",
feat_model_changed_warn:
"\u6A21\u578B\u5DF2\u66F4\u6362\uFF08{0} -> {1}\uFF09\u3002\u5DF2\u6709\u5411\u91CF\u4E0D\u517C\u5BB9\u2014\u2014\u9700\u8981\u91CD\u5EFA\u3002",
feat_network_error: "\u7F51\u7EDC\u9519\u8BEF\uFF1A",
feat_no_python:
"\u672A\u627E\u5230 Python\u3002\u8BF7\u67E5\u770B\u5B89\u88C5\u6807\u7B7E\u9875\u3002",
feat_not_cached: "\u672A\u7F13\u5B58",
feat_openai_key: "OpenAI API Key",
feat_openai_key_desc:
"\u7528\u4E8E API \u5D4C\u5165\u8C03\u7528\uFF0C\u6A21\u578B\u5728\u4E0B\u65B9\u5B9A\u4E49\u3002",
feat_output_copied:
"\u8F93\u51FA\u5DF2\u590D\u5236\u5230\u526A\u8D34\u677F\u3002",
feat_rebuild_btn: "\u91CD\u5EFA",
feat_rebuild_vectors: "\u91CD\u5EFA\u5411\u91CF",
feat_rebuild_vectors_changed:
"\u6A21\u578B\u5DF2\u66F4\u6362 \u2014 \u9700\u8981\u91CD\u5EFA\u5411\u91CF\u3002",
feat_rebuild_vectors_desc:
"\u91CD\u5EFA\u6240\u6709 OCR \u5168\u6587\u5411\u91CF\u3002\u66F4\u6362\u6A21\u578B\u6216\u6A21\u5F0F\u540E\u9700\u8981\u91CD\u5EFA\u3002",
feat_removing: "\u5220\u9664\u4E2D\u2026",
feat_retry_btn: "\u91CD\u8BD5",
feat_skills_desc:
"\u7BA1\u7406 Vault \u4E2D\u5DF2\u5B89\u88C5\u7684 Agent \u6280\u80FD\u3002\u6BCF\u884C\u5BF9\u5E94\u4E00\u4E2A SKILL.md \u6587\u4EF6\uFF0C\u5173\u95ED\u5F00\u5173\u53EF\u963B\u6B62 Agent \u81EA\u52A8\u8C03\u7528\u8BE5\u6280\u80FD\u3002",
feat_skills_system:
"\u7CFB\u7EDF\u6280\u80FD\u968F PaperForge \u4E00\u540C\u53D1\u5E03\uFF0C\u4F1A\u8DDF\u968F PaperForge \u7248\u672C\u66F4\u65B0\u3002",
feat_skills_user:
"\u7528\u6237\u6280\u80FD\u662F\u4F60\u81EA\u884C\u5B89\u88C5\u6216\u521B\u5EFA\u7684\u81EA\u5B9A\u4E49\u6280\u80FD\u3002",
feat_uninstall_btn: "\u5378\u8F7D",
feat_valid_key: "API Key \u6709\u6548\u3002",
feat_vector_config_label: "\u5411\u91CF\u5E93\u914D\u7F6E",
feat_vector_corrupted:
"\u5411\u91CF\u7D22\u5F15\u5DF2\u635F\u574F \u2014 \u9700\u8981\u5F3A\u5236\u91CD\u5EFA\u3002",
feat_vector_desc:
"\u5411\u91CF\u6570\u636E\u5E93\u901A\u8FC7\u5D4C\u5165\u6A21\u578B\u5B9E\u73B0 OCR \u5168\u6587\u7684\u8BED\u4E49\u641C\u7D22\u3002\u6587\u6863\u88AB\u5207\u5206\u4E3A\u6587\u672C\u5757\uFF08chunk\uFF09\uFF0C\u7F16\u7801\u4E3A\u5411\u91CF\u5B58\u5165 ChromaDB\u3002\u652F\u6301\u672C\u5730\u6A21\u578B\uFF08\u514D\u8D39\uFF0CCPU \u8FD0\u884C\uFF09\u6216 OpenAI API\uFF08\u4ED8\u8D39\uFF0C\u66F4\u5FEB\u901F\uFF09\u3002",
feat_vector_enable: "\u542F\u7528\u5411\u91CF\u68C0\u7D22",
feat_vector_enable_desc:
"\u5BF9 OCR \u5168\u6587\u8FDB\u884C\u8BED\u4E49\u641C\u7D22\u3002\u9700\u5B89\u88C5: pip install chromadb sentence-transformers openai (~500MB)\u3002",
feat_vector_rebuild_force_btn: "\u5F3A\u5236\u91CD\u5EFA",
feat_verify: "\u9A8C\u8BC1",
feat_verify_btn: "\u9A8C\u8BC1",
field_paddleocr: "PaddleOCR API \u5BC6\u94A5",
field_python_custom: "\u81EA\u5B9A\u4E49 Python \u8DEF\u5F84",
field_python_interp: "\u5F53\u524D Python \u89E3\u91CA\u5668",
field_zotero_data: "Zotero \u6570\u636E\u76EE\u5F55",
field_zotero_placeholder:
"\u53EF\u9009\uFF0C\u7528\u4E8E\u81EA\u52A8\u68C0\u6D4B PDF",
guide_ocr: "\u8FD0\u884C OCR",
guide_ocr_desc:
"Dashboard \u4E2D\u70B9 Run OCR\uFF0C\u63D0\u53D6 PDF \u5168\u6587\u4E0E\u56FE\u8868",
guide_open: "\u6253\u5F00 Dashboard",
guide_open_desc:
"Ctrl+P \u2192 \u8F93\u5165 PaperForge: Open Dashboard\uFF0C\u6216\u70B9\u5DE6\u4FA7\u4E66\u672C\u56FE\u6807",
guide_sync: "\u540C\u6B65\u6587\u732E",
guide_sync_desc:
"Dashboard \u4E2D\u70B9 Sync Library\uFF0C\u4ECE Zotero \u62C9\u53D6\u6587\u732E\u751F\u6210\u7B14\u8BB0",
header_title: "PaperForge",
install_bootstrapping:
"\u672A\u68C0\u6D4B\u5230 PaperForge Python \u5305\uFF0C\u6B63\u5728\u81EA\u52A8\u5B89\u88C5\u2026",
install_btn: "\u5F00\u59CB\u5B89\u88C5",
install_btn_retry: "\u91CD\u8BD5",
install_btn_running: "\u6B63\u5728\u5B89\u88C5...",
install_complete: "\u2713 \u5B89\u88C5\u5B8C\u6210\uFF01",
install_failed: "\u2717 \u5B89\u88C5\u5931\u8D25\uFF1A",
install_validating:
"\u6B63\u5728\u6821\u9A8C\u5B89\u88C5\u73AF\u5883\u2026",
jump_to_deep_reading: "\u8DF3\u8F6C\u5230\u7CBE\u8BFB",
label_agent: "Agent \u5E73\u53F0",
nav_close: "\u5173\u95ED",
nav_next: "\u4E0B\u4E00\u6B65 \u2192",
nav_prev: "\u2190 \u4E0A\u4E00\u6B65",
no_pending_ocr: "\u6240\u6709 OCR \u4EFB\u52A1\u5DF2\u5B8C\u6210",
not_set: "\u672A\u8BBE\u7F6E",
notice_check_fail: "\u672A\u901A\u8FC7: ",
notice_python_missing:
"Python \u672A\u68C0\u6D4B\u5230\uFF0C\u8BF7\u5148\u5B89\u88C5 Python 3.10+ \u5E76\u52A0\u5165 PATH",
ocr_privacy_title: "OCR \u9690\u79C1\u63D0\u793A",
ocr_privacy_warning:
"OCR \u4F1A\u5C06 PDF \u4E0A\u4F20\u5230 PaddleOCR API \u8FDB\u884C\u5904\u7406\u3002\u8BF7\u4E0D\u8981\u4E0A\u4F20\u5305\u542B\u654F\u611F\u4FE1\u606F\u6216\u65E0\u6CD5\u5916\u4F20\u7684\u6587\u732E\u3002",
ocr_queue_add: "\u52A0\u5165 OCR \u961F\u5217",
ocr_queue_added: "\u5DF2\u52A0\u5165 OCR \u961F\u5217",
ocr_queue_remove: "\u79FB\u51FA OCR \u961F\u5217",
ocr_queue_removed: "\u5DF2\u79FB\u51FA OCR \u961F\u5217",
ocr_understand: "\u6211\u4E86\u89E3\uFF0C\u7EE7\u7EED",
optional_later:
"\uFF08\u7A0D\u540E\u53EF\u5728\u8BBE\u7F6E\u4E2D\u8865\u5145\uFF09",
orphan_delete_failed: "\u6E05\u7406\u5931\u8D25",
orphan_delete_selected: "\u5220\u9664 {count} \u7BC7",
orphan_deleted:
"\u5DF2\u5220\u9664 {count} \u7BC7\u6B8B\u7559\u6587\u732E",
orphan_desc:
"\u8FD9\u4E9B\u6587\u732E\u5DF2\u4ECE Zotero \u4E2D\u79FB\u9664\u3002",
orphan_deselect_all: "\u53D6\u6D88\u5168\u9009",
orphan_explain:
"\u5DF2\u4ECE Zotero \u4E2D\u79FB\u9664\u3002\u5DE5\u4F5C\u533A\u6587\u4EF6\u4ECD\u4FDD\u7559\u5728\u78C1\u76D8\u4E0A\u3002",
orphan_keep_all: "\u4FDD\u7559\u5168\u90E8",
orphan_none_selected: "\u672A\u9009\u62E9\u4EFB\u4F55\u6587\u732E",
orphan_select_all: "\u5168\u9009",
orphan_title: "\u53D1\u73B0 {count} \u7BC7\u6B8B\u7559\u6587\u732E",
panel_actions: "\u5FEB\u6377\u64CD\u4F5C",
prep_bbt: "Better BibTeX",
prep_bbt_desc:
"Zotero \u2192 \u5DE5\u5177 \u2192 \u63D2\u4EF6 \u2192 \u5B89\u88C5 Better BibTeX",
prep_export: "BBT \u81EA\u52A8\u5BFC\u51FA",
prep_export_desc:
"\u53F3\u952E\u6587\u732E\u5B50\u5206\u7C7B \u2192 \u5BFC\u51FA\u5206\u7C7B \u2192 BetterBibTeX JSON \u2192 \u52FE\u9009\u4FDD\u6301\u66F4\u65B0 \u2192 \u5BFC\u51FA\u5230\uFF08JSON \u6587\u4EF6\u540D\u5373\u4E3A Base \u540D\uFF09\uFF1A",
prep_key: "PaddleOCR Key",
prep_key_desc:
"\u5728 https://aistudio.baidu.com/paddleocr \u83B7\u53D6 API Key",
prep_python: "Python 3.10+",
prep_python_desc:
"\u786E\u4FDD Python \u53EF\u547D\u4EE4\u884C\u8C03\u7528\u3002\u70B9\u51FB\u4E0B\u65B9\u6309\u94AE\u81EA\u52A8\u68C0\u6D4B\u3002",
prep_zotero: "Zotero \u684C\u9762\u7248",
prep_zotero_desc: "\u5B89\u88C5 Zotero (https://www.zotero.org)",
run_in_agent: "\u5728 {0} \u4E2D\u8FD0\u884C",
runtime_health: "\u8FD0\u884C\u65F6\u72B6\u6001",
runtime_health_checking: "\u6B63\u5728\u68C0\u6D4B\u2026",
runtime_health_desc:
"\u68C0\u67E5\u63D2\u4EF6\u4E0E Python \u8FD0\u884C\u65F6\u7248\u672C\u7684\u5339\u914D\u60C5\u51B5\uFF0C\u5E76\u786E\u8BA4\u5DF2\u90E8\u7F72\u7684 skill contract \u662F\u5426\u4E3A\u5F53\u524D\u7248\u672C\u3002",
runtime_health_match: "\u5339\u914D",
runtime_health_mismatch: "\u4E0D\u5339\u914D",
runtime_health_package_ver: "Python \u5305 v{0}",
runtime_health_plugin_ver: "\u63D2\u4EF6 v{0}",
runtime_health_sync: "\u540C\u6B65\u8FD0\u884C\u65F6",
runtime_health_sync_done:
"\u8FD0\u884C\u65F6\u5DF2\u540C\u6B65\u81F3 v{0}",
runtime_health_sync_fail:
"\u8FD0\u884C\u65F6\u540C\u6B65\u5931\u8D25\uFF1A{0}",
runtime_health_syncing: "\u6B63\u5728\u540C\u6B65\u2026",
section_config: "\u5F53\u524D\u914D\u7F6E",
section_guide: "\u64CD\u4F5C\u65B9\u5F0F",
section_prep: "\u5B89\u88C5\u51C6\u5907",
section_prep_desc:
"\u9996\u6B21\u4F7F\u7528\u524D\uFF0C\u8BF7\u4F9D\u6B21\u5B8C\u6210\u4EE5\u4E0B\u51C6\u5907\uFF1A",
setup_done:
"\u2713 PaperForge \u73AF\u5883\u5DF2\u914D\u7F6E\u5B8C\u6210",
setup_pending:
"\u5C1A\u672A\u5B89\u88C5\uFF0C\u5B8C\u6210\u5B89\u88C5\u51C6\u5907\u540E\u70B9\u51FB\u5B89\u88C5\u5411\u5BFC",
tab_features: "\u529F\u80FD",
tab_setup: "\u5B89\u88C5",
tab_maintenance: "\u7EF4\u62A4",
validate_base: "Base \u76EE\u5F55\u672A\u586B\u5199",
validate_fail: "\u914D\u7F6E\u9A8C\u8BC1\u5931\u8D25",
validate_index: "\u7D22\u5F15\u76EE\u5F55\u672A\u586B\u5199",
validate_key: "PaddleOCR API \u5BC6\u94A5\u672A\u586B\u5199",
validate_notes: "\u6B63\u6587\u76EE\u5F55\u672A\u586B\u5199",
validate_resources: "\u8D44\u6E90\u76EE\u5F55\u672A\u586B\u5199",
validate_system: "\u7CFB\u7EDF\u76EE\u5F55\u672A\u586B\u5199",
validate_vault: "Vault \u8DEF\u5F84\u672A\u586B\u5199",
validate_zotero:
"Zotero \u6570\u636E\u76EE\u5F55\u4E3A\u5FC5\u586B\u9879",
wizard_agent_hint:
"\u9009\u62E9\u4F60\u4F7F\u7528\u7684 AI Agent \u5E73\u53F0\uFF0C\u5B89\u88C5\u65F6\u5C06\u6309\u5BF9\u5E94\u683C\u5F0F\u90E8\u7F72\u6280\u80FD\u6587\u4EF6\uFF1A",
wizard_dir_hint:
"\u8D44\u6E90\u76EE\u5F55\u662F\u6587\u732E\u6570\u636E\u7684\u7EDF\u4E00\u6839\u76EE\u5F55\uFF0C\u4EE5\u4E0B\u5B50\u76EE\u5F55\u5C06\u521B\u5EFA\u5728\u5176\u5185\u90E8\uFF1A",
wizard_dir_sub_hint:
"\u8D44\u6E90\u76EE\u5F55\u5185\u7684\u4E24\u4E2A\u5B50\u76EE\u5F55\uFF1A",
wizard_intro:
"\u672C\u5411\u5BFC\u5C06\u5F15\u5BFC\u60A8\u5B8C\u6210 PaperForge \u73AF\u5883\u7684\u5B8C\u6574\u914D\u7F6E\u3002\u5B89\u88C5\u8FC7\u7A0B\u4F1A\u81EA\u52A8\u521B\u5EFA\u6240\u6709\u76EE\u5F55\u7ED3\u6784\uFF0C\u65E0\u9700\u624B\u52A8\u64CD\u4F5C\u3002",
wizard_keys_hint:
"\u4EE5\u4E0B\u4E3A API \u5BC6\u94A5\u4E0E Zotero \u914D\u7F6E\uFF1A",
wizard_preview:
"\u7CFB\u7EDF\u6587\u4EF6\u548C Agent \u914D\u7F6E\u4F4D\u4E8E Vault \u6839\u76EE\u5F55\u4E0B\u3002\u6587\u732E\u6570\u636E\uFF08\u6B63\u6587\u3001\u7D22\u5F15\uFF09\u7EDF\u4E00\u5B58\u653E\u5728\u8D44\u6E90\u76EE\u5F55\u5185\u3002\u5B89\u88C5\u540E\u4ECD\u53EF\u5728\u8BBE\u7F6E\u4E2D\u4FEE\u6539\u3002",
wizard_safety:
"\u5B89\u5168\u8BF4\u660E\uFF1A\u5982\u679C\u4F60\u9009\u62E9\u7684\u76EE\u5F55\u91CC\u5DF2\u7ECF\u6709\u6587\u4EF6\uFF0C\u5B89\u88C5\u5411\u5BFC\u4F1A\u4FDD\u7559\u5DF2\u6709\u5185\u5BB9\uFF0C\u53EA\u8865\u5145\u7F3A\u5931\u7684 PaperForge \u6587\u4EF6\u548C\u76EE\u5F55\u3002",
wizard_step1: "\u6982\u89C8",
wizard_step2: "\u76EE\u5F55",
wizard_step3: "Agent",
wizard_step4: "\u5B89\u88C5",
wizard_step5: "\u5B8C\u6210",
wizard_skip_ocr_desc:
"OCR \u529F\u80FD\u5728\u914D\u7F6E\u6709\u6548\u7684 PaddleOCR API \u5BC6\u94A5\u4E4B\u524D\u4E0D\u53EF\u7528\u3002\u60A8\u53EF\u4EE5\u7EE7\u7EED\u5B8C\u6210\u8BBE\u7F6E\uFF0C\u7A0D\u540E\u5728\u8BBE\u7F6E\u4E2D\u914D\u7F6E\u3002",
wizard_skip_ocr_continue:
"\u7EE7\u7EED\uFF0C\u7A0D\u540E\u914D\u7F6E\u5BC6\u94A5",
wizard_skip_ocr_back: "\u8FD4\u56DE\u914D\u7F6E",
wizard_api_hint_skip:
"OCR \u5BC6\u94A5\u4E3A\u9009\u586B\u9879 \u2014 \u53EF\u8DF3\u8FC7\uFF0C\u7A0D\u540E\u5728\u8BBE\u7F6E\u4E2D\u914D\u7F6E\u3002",
wizard_sys_hint:
"\u72EC\u7ACB\u4E8E\u8D44\u6E90\u76EE\u5F55\u7684\u7CFB\u7EDF\u6587\u4EF6\uFF1A",
wizard_title: "PaperForge \u5B89\u88C5\u5411\u5BFC",
ocr_maint_no_action: "\u65E0\u9700\u5904\u7406",
ocr_maint_rebuild: "\u5EFA\u8BAE\u91CD\u5EFA",
ocr_maint_failed: "OCR \u5931\u8D25",
ocr_maint_limited: "\u7ED3\u679C\u4E00\u822C",
ocr_maint_needs_attention: "\u9700\u8981\u5904\u7406",
ocr_maint_limitations: "\u7ED3\u679C\u8BF4\u660E",
ocr_maint_hero_ok: "OCR \u6574\u4F53\u6B63\u5E38\u3002",
ocr_maint_hero_warn:
"OCR \u9700\u8981\u5173\u6CE8\uFF1A{rebuild} \u7BC7\u5EFA\u8BAE\u91CD\u5EFA\uFF0C{failed} \u7BC7\u5904\u7406\u5931\u8D25\u3002",
ocr_maint_hero_note:
"\u672C\u9875\u53EA\u63D0\u793A\u7EF4\u62A4\u540E\u5927\u6982\u7387\u4F1A\u6539\u5584\u7684\u95EE\u9898\u3002\u90E8\u5206\u8BBA\u6587\u6548\u679C\u4E00\u822C\uFF0C\u7EF4\u62A4\u672A\u5FC5\u80FD\u6539\u5584\u3002",
ocr_maint_limitations_intro:
"\u8FD9\u7C7B\u8BBA\u6587\u901A\u5E38\u8868\u793A\u7248\u5F0F\u590D\u6742\u6216\u4FE1\u53F7\u504F\u5F31\uFF0CPaperForge \u76EE\u524D\u6CA1\u6709\u9AD8\u7F6E\u4FE1\u5EA6\u7684\u7EF4\u62A4\u5EFA\u8BAE\u3002",
ocr_maint_all_papers: "\u5168\u90E8\u8BBA\u6587",
ocr_maint_rebuild_btn: "\u91CD\u5EFA\u7ED3\u679C",
maintenance_group_retry: "\u9700\u8981\u91CD\u8BD5",
maintenance_group_rebuild: "\u53EF\u91CD\u5EFA\u7ED3\u679C",
maintenance_group_legacy:
"\u53EF\u5347\u7EA7\u65E7\u7ED3\u679C\uFF08\u53EF\u9009\uFF09",
maintenance_btn_retry: "\u91CD\u8BD5",
maintenance_btn_rebuild: "\u91CD\u5EFA",
maintenance_btn_upgrade: "\u5347\u7EA7",
maintenance_refresh_spinning: "\u6B63\u5728\u66F4\u65B0\u2026",
maintenance_all_good: "\u2705 \u5168\u90E8\u6B63\u5E38",
maintenance_n_pending: "{n} \u7BC7\u9700\u8981\u5904\u7406",
version_panel_title: "\u7248\u672C\u5386\u53F2",
version_panel_back: "\u8FD4\u56DE",
version_filter_placeholder: "\u641C\u7D22\u8BBA\u6587...",
version_papers_count: "{n} \u7BC7\u8BBA\u6587",
version_current: "\u5F53\u524D",
version_restore_btn: "\u6062\u590D",
version_compare_btn: "\u5BF9\u6BD4",
version_restore_selected: "\u6062\u590D\u9009\u4E2D\u7248\u672C",
version_clear_old: "\u6E05\u9664\u65E7\u7248\u672C (\u91CA\u653E {size})",
version_no_backups:
"\u6CA1\u6709\u53EF\u6062\u590D\u7684\u5386\u53F2\u7248\u672C",
version_restore_confirm:
"\u786E\u8BA4\u5C06 {paper} \u6062\u590D\u5230 {label}\uFF1F",
version_restore_done: "\u5DF2\u6062\u590D\u5230 {label}",
version_compare_title: "{vA} vs {vB}",
version_compare_paragraphs: "{n} \u6BB5\u6709\u53D8\u5316",
version_error_read: "\u65E0\u6CD5\u8BFB\u53D6\u7248\u672C\u6570\u636E",
retrieval_search_placeholder:
"\u641C\u7D22\u8BBA\u6587... (@ \u8FDB\u884C\u6DF1\u5EA6\u641C\u7D22)",
retrieval_search_placeholder_deep:
"\u901A\u8FC7\u6DF1\u5EA6\u68C0\u7D22\u641C\u7D22\u8BBA\u6587...",
retrieval_search_idle_hint:
"\u8F93\u5165\u5173\u952E\u5B57\u641C\u7D22\u5143\u6570\u636E\uFF0C\u6216\u4EE5 @ \u5F00\u5934\u8FDB\u884C\u6DF1\u5EA6\u8BED\u4E49\u641C\u7D22",
retrieval_searching_metadata:
"\u6B63\u5728\u641C\u7D22\u5143\u6570\u636E...",
retrieval_searching_deep:
"\u6B63\u5728\u8FD0\u884C\u6DF1\u5EA6\u641C\u7D22...",
retrieval_search_cancel: "\u53D6\u6D88",
retrieval_results_count: "\u627E\u5230 {n} \u6761\u7ED3\u679C",
retrieval_empty: "\u672A\u627E\u5230\u5339\u914D\u7684\u8BBA\u6587\u3002",
retrieval_empty_tips:
"\u5C1D\u8BD5\u66F4\u5BBD\u6CDB\u7684\u5173\u952E\u8BCD\uFF0C\u6216\u4F7F\u7528 @ \u8FDB\u884C\u6DF1\u5EA6\u641C\u7D22\u3002",
retrieval_vectors_not_built: "\u5411\u91CF\u7D22\u5F15\u672A\u6784\u5EFA",
retrieval_vectors_not_built_desc:
"\u5411\u91CF\u7D22\u5F15\u5C1A\u672A\u6784\u5EFA\uFF0C\u641C\u7D22\u9700\u8981\u5148\u6784\u5EFA\u5411\u91CF\u7D22\u5F15\u3002",
retrieval_open_vector_settings: "\u6253\u5F00\u5411\u91CF\u8BBE\u7F6E",
retrieval_backend_unavailable: "\u540E\u7AEF\u4E0D\u53EF\u7528",
retrieval_backend_unavailable_desc:
"Python CLI \u641C\u7D22\u540E\u7AEF\u65E0\u54CD\u5E94\u3002",
retrieval_run_doctor: "\u8FD0\u884C\u8BCA\u65AD",
retrieval_retry: "\u91CD\u8BD5",
retrieval_timeout_title: "\u641C\u7D22\u8D85\u65F6",
retrieval_timeout_desc:
"\u641C\u7D22\u8017\u65F6\u8FC7\u957F\u3002\u4F60\u53EF\u4EE5\u91CD\u8BD5\uFF0C\u6216\u5C1D\u8BD5\u7B80\u5316\u67E5\u8BE2\u3002",
retrieval_model_changed: "\u6A21\u578B\u5DF2\u66F4\u6362",
retrieval_model_changed_desc:
"\u5D4C\u5165\u6A21\u578B\u5DF2\u66F4\u6362\uFF0C\u9700\u8981\u91CD\u5EFA\u5411\u91CF\u3002",
retrieval_rebuild_vectors: "\u91CD\u5EFA\u5411\u91CF",
retrieval_internal_error:
"\u53D1\u751F\u5185\u90E8\u9519\u8BEF\u3002\u8BF7\u67E5\u770B\u63A7\u5236\u53F0\u4E86\u89E3\u8BE6\u60C5\u3002",
retrieval_build_idle: "\u5411\u91CF\u7D22\u5F15\u5C1A\u672A\u6784\u5EFA",
retrieval_build_ready: "\u5411\u91CF\u7D22\u5F15\u5C31\u7EEA",
retrieval_build_stopping: "\u6B63\u5728\u505C\u6B62\u2026",
retrieval_build_stopped:
"\u6784\u5EFA\u5DF2\u505C\u6B62\u3002\u70B9\u51FB\u7EE7\u7EED\u4EE5\u6062\u590D\u3002",
retrieval_build_failed: "\u6784\u5EFA\u5931\u8D25",
retrieval_build_stale:
"\u4E0A\u6B21\u6784\u5EFA\u88AB\u4E2D\u65AD\u3002\u70B9\u51FB\u7EE7\u7EED\u4EE5\u6062\u590D\u3002",
retrieval_build_deps_missing: "\u4F9D\u8D56\u672A\u5B89\u88C5",
retrieval_build_runtime_mismatch:
"\u63D2\u4EF6\u4E0E CLI \u7248\u672C\u4E0D\u5339\u914D",
retrieval_stop: "\u505C\u6B62",
retrieval_force_rebuild: "\u5F3A\u5236\u91CD\u5EFA",
retrieval_rebuild_warning:
"\u91CD\u5EFA\u5C06\u66FF\u6362 {n} \u4E2A\u5DF2\u6709\u7684 chunk\u3002\u662F\u5426\u7EE7\u7EED\uFF1F",
retrieval_no_python:
"\u672A\u627E\u5230 Python\u3002\u8BF7\u67E5\u770B\u5B89\u88C5\u6807\u7B7E\u9875\u3002",
},
},
Ue = null;
function jt(u) {
try {
let h = u.vault;
if (typeof h.getConfig == "function") {
let e = h.getConfig("language");
if (e && String(e).startsWith("zh")) return "zh";
}
} catch (h) {}
try {
if (typeof localStorage != "undefined") {
let h = localStorage.getItem("language");
if (h && String(h).startsWith("zh")) return "zh";
}
} catch (h) {}
return "en";
}
function lt(u) {
Ue = jt(u) === "zh" ? qe.zh : qe.en;
}
function o(u) {
return (Ue && Ue[u]) || qe.en[u] || u;
}
var R = require("obsidian"),
$ = V(require("fs")),
X = V(require("path")),
St = V(require("os")),
K = require("child_process");
var Pt = V(Je());
var le = V(require("fs")),
oe = V(require("path")),
pt = V(require("os")),
de = require("child_process"),
Ge = null,
ct = !1;
function N(u, h, e, t) {
let r = e || le,
n = t || de.execFileSync;
if (h && h.python_path && h.python_path.trim()) {
let i = h.python_path.trim();
if (r.existsSync(i)) return { path: i, source: "manual", extraArgs: [] };
}
let a = [
oe.join(u, ".paperforge-test-venv", "Scripts", "python.exe"),
oe.join(u, ".venv", "Scripts", "python.exe"),
oe.join(u, "venv", "Scripts", "python.exe"),
];
for (let i of a)
try {
if (r.existsSync(i))
return { path: i, source: "auto-detected", extraArgs: [] };
} catch (l) {}
let s = [
{ path: "py", extraArgs: ["-3"] },
{ path: "python", extraArgs: [] },
{ path: "python3", extraArgs: [] },
];
for (let i of s)
try {
let l = n(i.path, [...i.extraArgs, "--version"], {
encoding: "utf-8",
timeout: 5e3,
windowsHide: !0,
});
if (l && l.toLowerCase().includes("python"))
return {
path: i.path,
source: "auto-detected",
extraArgs: i.extraArgs,
};
} catch (l) {}
return { path: "python", source: "auto-detected", extraArgs: [] };
}
function dt(u, h, e, t, r) {
t === void 0 && (t = 1e4);
let n = r || de.execFile;
return new Promise((a) => {
n(
u,
["-c", "import paperforge; print(paperforge.__version__)"],
{ cwd: e, timeout: t },
(s, i) => {
if (s) {
a({
status: "not-installed",
pyVersion: null,
pluginVersion: h,
error: s.message,
});
return;
}
let l = (i && i.trim()) || null;
a(
l === h
? { status: "match", pyVersion: l, pluginVersion: h, error: null }
: {
status: "mismatch",
pyVersion: l,
pluginVersion: h,
error: null,
}
);
}
);
});
}
function Xe(u) {
let h = String(u),
t = {
ENOENT: {
type: "python_missing",
message: "Python executable not found",
recoverable: !0,
},
"python-missing": {
type: "python_missing",
message: "Python executable not found",
recoverable: !0,
},
MODULE_NOT_FOUND: {
type: "import_failed",
message: "PaperForge package not installed",
recoverable: !0,
},
"import-failed": {
type: "import_failed",
message: "PaperForge package not installed",
recoverable: !0,
},
"version-mismatch": {
type: "version_mismatch",
message: "Plugin and package versions differ",
recoverable: !0,
action: "sync-runtime",
},
"pip-failed": {
type: "pip_install_failure",
message: "pip install command failed",
recoverable: !0,
},
ETIMEDOUT: {
type: "timeout",
message: "Subprocess timed out",
recoverable: !0,
action: "retry",
},
timeout: {
type: "timeout",
message: "Subprocess timed out",
recoverable: !0,
action: "retry",
},
NO_PYTHON: {
type: "no_python",
message: "Python executable not found",
recoverable: !0,
action: "open-setup",
},
VECTOR_NOT_BUILT: {
type: "vectors_not_built",
message: "Vector index has not been built yet",
recoverable: !0,
action: "open-vector-settings",
},
VECTOR_CORRUPTED: {
type: "vectors_corrupted",
message: "Vector index is corrupted",
recoverable: !0,
action: "force-rebuild",
},
MODEL_CHANGED: {
type: "model_changed",
message: "Embedding model has changed since vectors were built",
recoverable: !0,
action: "rebuild-vectors",
},
BACKEND_UNAVAILABLE: {
type: "backend_unavailable",
message: "Python CLI search backend is not responding",
recoverable: !0,
action: "run-doctor",
},
TIMEOUT: {
type: "timeout",
message: "Search timed out",
recoverable: !0,
action: "retry",
},
INTERNAL_ERROR: {
type: "internal_error",
message: "An internal error occurred",
recoverable: !1,
},
}[h];
return t
? { ...t }
: { type: "unknown", message: String(u), recoverable: !1 };
}
function ut(u, h, e) {
e === void 0 && (e = []);
let t = `paperforge==${h}`,
r = `git+https://github.com/LLLin000/PaperForge.git@${h}`,
n = [...e, "-m", "pip", "install", "--upgrade", t],
a = [...e, "-m", "pip", "install", "--upgrade", r];
return { cmd: u, url: r, args: a, pypiArgs: n, gitArgs: a, timeout: 12e4 };
}
function ht(u, h, e, t, r, n) {
let a = r || de.spawn;
return new Promise((s) => {
let i = Date.now(),
l = { cwd: e, timeout: t, windowsHide: !0 };
n && (l.env = n);
let c = a(u, h, l),
d = [],
f = [];
(c.stdout.on("data", (p) => {
d.push(p.toString("utf-8"));
}),
c.stderr.on("data", (p) => {
f.push(p.toString("utf-8"));
}),
c.on("close", (p) => {
s({
stdout: d.join(""),
stderr: f.join(""),
exitCode: p,
elapsed: Date.now() - i,
});
}),
c.on("error", (p) => {
s({
stdout: d.join(""),
stderr:
f.join("") +
`
` +
p.message,
exitCode: -1,
elapsed: Date.now() - i,
});
}));
});
}
function Ye() {
if (ct) return Ge;
ct = !0;
try {
let u;
if (process.platform === "win32") {
let h = process.env.ComSpec || "C:\\Windows\\System32\\cmd.exe";
u = (0, de.execFileSync)(h, ["/c", "where", "git"], {
timeout: 5e3,
windowsHide: !0,
encoding: "utf-8",
});
} else
u = (0, de.execFileSync)("which", ["git"], {
timeout: 5e3,
encoding: "utf-8",
});
if (u) {
let h = u
.split(
`
`
)[0]
.trim();
h && (Ge = oe.dirname(h));
}
} catch (u) {}
return Ge;
}
function be() {
let u = { ...process.env },
h = process.platform,
e = pt.homedir(),
t = [],
r = Ye();
(r && t.push(r),
h === "darwin"
? t.push(
"/opt/homebrew/bin",
"/usr/local/bin",
"/usr/bin",
`${e}/.local/bin`
)
: h === "linux" &&
t.push("/usr/local/bin", "/usr/bin", `${e}/.local/bin`));
let n = u.PATH || "";
return ((u.PATH = [...t, n].filter(Boolean).join(oe.delimiter)), u);
}
function _t(u) {
return String(u)
.toLowerCase()
.replace(/[^a-z0-9]/g, "")
.includes("betterbibtex");
}
function Qe(u) {
if (!u) return !1;
try {
if (!le.existsSync(u)) return !1;
for (let h of le.readdirSync(u)) if (_t(h)) return !0;
} catch (h) {}
return !1;
}
function Me(u) {
if (!u) return !1;
try {
if (!le.existsSync(u)) return !1;
for (let h of le.readdirSync(u)) {
let e = oe.join(u, h, "extensions");
try {
if (!le.existsSync(e)) continue;
for (let t of le.readdirSync(e)) if (_t(t)) return !0;
} catch (t) {}
}
} catch (h) {}
return !1;
}
var ge = V(require("fs")),
H = V(require("path")),
et = require("child_process"),
ce = null;
function $t(u, h) {
let e = h || ge,
t = H.join(u, "paperforge.json"),
r = {
system_dir: "System",
resources_dir: "Resources",
literature_dir: "Literature",
base_dir: "Bases",
};
try {
if (!e.existsSync(t))
return { ...r, _warning: "paperforge.json not found; using defaults" };
let n = e.readFileSync(t, "utf-8"),
a = JSON.parse(n),
s = a.vault_config || {};
return {
system_dir: s.system_dir || a.system_dir || r.system_dir,
resources_dir: s.resources_dir || a.resources_dir || r.resources_dir,
literature_dir: s.literature_dir || a.literature_dir || r.literature_dir,
base_dir: s.base_dir || a.base_dir || r.base_dir,
_warning: null,
};
} catch (n) {
return (
console.warn(
"PaperForge: Failed to read paperforge.json, using defaults",
n
),
{ ...r, _warning: "paperforge.json invalid; using defaults" }
);
}
}
function ne(u, h) {
let e = $t(u, h),
t = H.join(u, e.system_dir, "PaperForge");
return {
vault: u,
systemDir: t,
indexesDir: H.join(t, "indexes"),
logsDir: H.join(t, "logs"),
dbPath: H.join(t, "indexes", "paperforge.db"),
memoryStatePath: H.join(t, "indexes", "memory-runtime-state.json"),
vectorStatePath: H.join(t, "indexes", "vector-runtime-state.json"),
healthStatePath: H.join(t, "indexes", "runtime-health.json"),
buildStatePath: H.join(t, "indexes", "vector-build-state.json"),
orphanStatePath: H.join(t, "indexes", "sync-orphan-state.json"),
exportsDir: H.join(t, "exports"),
ocrDir: H.join(t, "ocr"),
pluginDataPath: H.join(
u,
".obsidian",
"plugins",
"paperforge",
"data.json"
),
pfJsonPath: H.join(u, "paperforge.json"),
configWarning: e._warning,
};
}
function tt(u) {
try {
return ge.existsSync(u) ? JSON.parse(ge.readFileSync(u, "utf-8")) : null;
} catch (h) {
return null;
}
}
function Vt(u) {
let h = ne(u);
return tt(h.memoryStatePath);
}
var xe = null;
function Ne(u) {
let h = ne(u),
e = Date.now();
if (xe && xe.vaultPath === u && e - xe.ts < 2e3) return xe.result;
let t = "",
r = [
H.join(u, ".paperforge-test-venv", "Scripts", "python.exe"),
H.join(u, ".venv", "Scripts", "python.exe"),
H.join(u, "venv", "Scripts", "python.exe"),
];
for (let a = 0; a < r.length; a++)
if (ge.existsSync(r[a])) {
t = r[a];
break;
}
if (t)
try {
let a = (0, et.execFileSync)(
t,
["-m", "paperforge", "--vault", u, "embed", "status", "--json"],
{ encoding: "utf-8", timeout: 1e4, windowsHide: !0 }
),
s = JSON.parse(a);
if (s.ok && s.data) {
let i = s.data;
return ((xe = { vaultPath: u, result: i, ts: e }), i);
}
} catch (a) {}
let n = tt(h.vectorStatePath);
return ((xe = { vaultPath: u, result: n, ts: e }), n);
}
function Te(u) {
let h = ne(u);
return tt(h.healthStatePath);
}
function ft(u) {
var e;
let h = Te(u);
return !!(h && ((e = h.summary) == null ? void 0 : e.status) === "ok");
}
function je(u) {
let h = Vt(u);
return !h || h.paper_count_db === 0
? "DB not found. Run paperforge memory build."
: "Papers: " + h.paper_count_db + " | " + (h.fresh ? "fresh" : "stale");
}
function Ee(u) {
var t, r, n;
let h = Ne(u);
return h
? h.healthy === !1
? "Vector index unreadable - rebuild required"
: "Chunks: " +
(((t = h.chunk_count) != null ? t : 0) +
((r = h.body_chunk_count) != null ? r : 0) +
((n = h.object_chunk_count) != null ? n : 0)) +
" | " +
h.model +
" | " +
h.mode
: "Status unavailable";
}
function ue(u, h) {
if (ce) return ce;
if (h && h.python_path && h.python_path.trim()) {
let r = h.python_path.trim();
if (ge.existsSync(r))
return ((ce = { path: r, source: "manual", extraArgs: [] }), ce);
}
let e = [
H.join(u, ".paperforge-test-venv", "Scripts", "python.exe"),
H.join(u, ".venv", "Scripts", "python.exe"),
H.join(u, "venv", "Scripts", "python.exe"),
];
for (let r = 0; r < e.length; r++)
if (ge.existsSync(e[r]))
return (
(ce = { path: e[r], source: "auto-detected", extraArgs: [] }),
ce
);
let t = [
{ path: "py", extraArgs: ["-3"] },
{ path: "python", extraArgs: [] },
{ path: "python3", extraArgs: [] },
];
for (let r = 0; r < t.length; r++)
try {
let n = t[r],
a = (0, et.execFileSync)(n.path, n.extraArgs.concat(["--version"]), {
encoding: "utf-8",
timeout: 5e3,
windowsHide: !0,
});
if (a && a.toLowerCase().indexOf("python") !== -1)
return (
(ce = {
path: n.path,
source: "auto-detected",
extraArgs: n.extraArgs,
}),
ce
);
} catch (n) {}
return (
(ce = { path: "python", source: "auto-detected", extraArgs: [] }),
ce
);
}
function rt(u, h, e) {
return !u ||
typeof u != "object" ||
!Object.prototype.hasOwnProperty.call(u, h)
? !!e
: !!u[h];
}
function gt(u, h, e) {
let t = !rt(u, h, e);
return (u && typeof u == "object" && (u[h] = t), t);
}
var te = require("obsidian"),
ae = V(require("fs")),
yt = V(require("path")),
vt = V(require("https")),
Be = require("child_process");
function mt(u, h) {
return !h || !h.trim()
? { blocked: !0, reason: "zotero" }
: u
? { blocked: !1 }
: { blocked: !0, reason: "ocr" };
}
var st = class extends te.Modal {
constructor(e, t, r, n) {
super(e);
this._rowEls = [];
((this.orphans = t.map((a, s) => ({ ...a, _selected: !0, _idx: s }))),
(this.vaultPath = r),
(this.py = n));
}
_updateUI() {
let e = this.orphans.filter((t) => t._selected);
(this._countEl.setText(
o("orphan_delete_selected").replace("{count}", String(e.length))
),
this._selectAllBtn.setText(
e.length === this.orphans.length
? o("orphan_deselect_all")
: o("orphan_select_all")
));
for (let t of this.orphans) {
let r = this._rowEls[t._idx];
r && r.toggleClass("paperforge-orphan-dimmed", !t._selected);
}
}
onOpen() {
let { contentEl: e } = this;
(e.addClass("paperforge-modal"),
e.createEl("h2", {
text: o("orphan_title").replace("{count}", String(this.orphans.length)),
}),
e.createEl("p", { cls: "paperforge-modal-desc", text: o("orphan_desc") }),
(this._rowEls = []));
let t = e.createEl("div", { cls: "paperforge-orphan-list" });
for (let n of this.orphans) {
let a = t.createEl("div", {
cls:
"paperforge-orphan-row" +
(n._selected ? "" : " paperforge-orphan-dimmed"),
});
this._rowEls.push(a);
let s = a.createEl("div", { cls: "paperforge-orphan-info" }),
i = s.createEl("div", { cls: "paperforge-orphan-header" });
i.createEl("span", {
cls: "paperforge-orphan-key",
text: n.citation_key || n.key,
});
let l = i.createEl("span", { cls: "paperforge-orphan-tags" });
(l.createEl("span", {
cls: "paperforge-tag " + (n.has_pdf ? "tag-pdf" : "tag-nopdf"),
text: n.has_pdf ? "PDF" : "no PDF",
}),
n.collection_path &&
l.createEl("span", {
cls: "paperforge-tag tag-collection",
text: n.collection_path,
}),
n.title &&
s.createEl("div", { cls: "paperforge-orphan-title", text: n.title }));
let c = [];
(n.authors && c.push(n.authors),
n.year && c.push(n.year),
c.length > 0 &&
s.createEl("div", {
cls: "paperforge-orphan-meta",
text: c.join(" \xB7 "),
}),
s.createEl("div", {
cls: "paperforge-orphan-explain",
text: o("orphan_explain"),
}),
a.addEventListener("click", () => {
((n._selected = !n._selected), this._updateUI());
}));
}
let r = e.createEl("div", { cls: "paperforge-modal-actions" });
((this._selectAllBtn = r.createEl("button", {
cls: "paperforge-step-btn",
text: "Deselect all",
})),
this._selectAllBtn.addEventListener("click", () => {
let n = this.orphans.every((a) => a._selected);
for (let a of this.orphans) a._selected = !n;
this._updateUI();
}),
(this._countEl = r.createEl("button", {
cls: "paperforge-step-btn mod-cta",
text: "Delete " + this.orphans.length + " selected",
})),
r
.createEl("button", { cls: "paperforge-step-btn", text: "Keep all" })
.addEventListener("click", () => this.close()),
this._countEl.addEventListener("click", () => {
let n = this.orphans.filter((s) => s._selected);
if (n.length === 0) {
new te.Notice(o("orphan_none_selected"));
return;
}
if (
(this._countEl.setText("Deleting..."),
this._countEl.setAttr("disabled", ""),
this._selectAllBtn.setAttr("disabled", ""),
!this.py || !this.py.path)
) {
(new te.Notice("PaperForge: Python not found"), this.close());
return;
}
let a = n.map((s) => s.key);
(0, Be.execFile)(
this.py.path,
[
...this.py.extraArgs,
"-m",
"paperforge",
"--vault",
this.vaultPath,
"prune",
"--force",
"--json",
...a,
],
{ cwd: this.vaultPath, timeout: 6e4 },
(s, i) => {
if (s) {
(new te.Notice("PaperForge: prune failed"), this.close());
return;
}
try {
let l = JSON.parse(i),
c = (l.data && l.data.deleted) || [];
new te.Notice("Deleted " + c.length + " orphan workspace(s)");
} catch (l) {
new te.Notice("PaperForge: prune done");
}
this.close();
}
);
}));
}
onClose() {
this.contentEl.empty();
}
};
function ze(u, h, e) {
console.log("[PF] checkOrphanState called");
try {
let r = ne(e).orphanStatePath;
if (!ae.existsSync(r)) {
console.log("[PF] orphan file NOT FOUND");
return;
}
console.log("[PF] orphan file FOUND");
let n = ae.readFileSync(r, "utf-8"),
s = JSON.parse(n).orphans || [];
if ((console.log("[PF] orphans count:", s.length), s.length === 0)) return;
let i = ue(e, h.settings);
(console.log("[PF] py.path:", i ? i.path : "null"),
new st(u, s, e, i).open(),
ae.unlinkSync(r),
console.log("[PF] orphan file cleaned"));
} catch (t) {
console.log("[PF] checkOrphanState exception:", t.message || t);
}
}
var De = class extends te.Modal {
constructor(e, t) {
super(e);
this._pendingSave = null;
this._showSkipConfirm = !1;
((this.plugin = t), (this._step = 1));
}
onOpen() {
this._render();
}
onClose() {
this.contentEl.empty();
}
_render() {
let { contentEl: e } = this;
(e.empty(),
e.addClass("paperforge-modal"),
this._renderStepIndicator(),
this._renderStepContent(),
this._renderNavigation());
}
_renderStepIndicator() {
let e = [
o("wizard_step1"),
o("wizard_step2"),
o("wizard_step3"),
o("wizard_step4"),
o("wizard_step5"),
],
t = this.contentEl.createEl("div", { cls: "paperforge-step-bar" });
e.forEach((r, n) => {
let a = n + 1,
s = t.createEl("div", {
cls: `paperforge-step-dot ${a === this._step ? "active" : ""} ${a < this._step ? "done" : ""}`,
});
(s.createEl("span", { cls: "paperforge-step-num", text: `${a}` }),
s.createEl("span", { cls: "paperforge-step-label", text: r }));
});
}
_renderStepContent() {
let e = this.contentEl.createEl("div", { cls: "paperforge-step-content" });
switch (this._step) {
case 1:
this._stepOverview(e);
break;
case 2:
this._stepDirectories(e);
break;
case 3:
this._stepKeys(e);
break;
case 4:
this._stepInstall(e);
break;
case 5:
this._stepComplete(e);
break;
}
}
_renderNavigation() {
let e = this.contentEl.createEl("div", { cls: "paperforge-step-nav" });
(this._step > 1 &&
e
.createEl("button", { cls: "paperforge-step-btn", text: o("nav_prev") })
.addEventListener("click", () => {
(this._step--, (this._showSkipConfirm = !1), this._render());
}),
this._step < 5
? e
.createEl("button", {
cls: "paperforge-step-btn mod-cta",
text: o("nav_next"),
})
.addEventListener("click", () => {
if (this._step === 3) {
let r = this._validateStep3();
if (r.blocked) {
if (r.reason === "zotero") return;
if (r.reason === "ocr") {
((this._showSkipConfirm = !0), this._render());
return;
}
}
}
(this._step++, (this._showSkipConfirm = !1), this._render());
})
: e
.createEl("button", {
cls: "paperforge-step-btn",
text: o("nav_close"),
})
.addEventListener("click", () => this.close()));
}
_validateStep3() {
let e = this.plugin.settings,
t = mt(this._apiKeyValidated, e.zotero_data_dir);
if (t.reason === "ocr") return t;
let r = (e.zotero_data_dir || "").trim();
if (!r)
return (
new te.Notice(
"Zotero \u6570\u636E\u76EE\u5F55\u4E3A\u5FC5\u586B\u9879\uFF0C\u8BF7\u586B\u5199\u8DEF\u5F84"
),
{ blocked: !0, reason: "zotero" }
);
if (!ae.existsSync(r))
return (
new te.Notice(
"Zotero \u6570\u636E\u76EE\u5F55\u8DEF\u5F84\u4E0D\u5B58\u5728"
),
{ blocked: !0, reason: "zotero" }
);
if (!ae.statSync(r).isDirectory())
return (
new te.Notice(
"Zotero \u6570\u636E\u76EE\u5F55\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55"
),
{ blocked: !0, reason: "zotero" }
);
let n = yt.join(r, "storage");
return !ae.existsSync(n) || !ae.statSync(n).isDirectory()
? (new te.Notice(
"Zotero \u6570\u636E\u76EE\u5F55\u4E2D\u672A\u627E\u5230 storage/ \u5B50\u76EE\u5F55"
),
{ blocked: !0, reason: "zotero" })
: { blocked: !1 };
}
_stepOverview(e) {
(e.createEl("h2", { text: o("wizard_title") }),
e.createEl("p", { text: o("wizard_intro") }));
let t = this.plugin.settings,
r = this.app.vault.adapter.basePath,
n = e.createEl("div", { cls: "paperforge-dir-tree" }),
a = n.createEl("div", { cls: "paperforge-dir-node root" });
a.textContent = `\u{1F4C1} Vault (${r})`;
let s = n.createEl("div", { cls: "paperforge-dir-children" }),
i = s.createEl("div", { cls: "paperforge-dir-node folder" });
((i.textContent = `\u{1F4C1} ${t.resources_dir || "Resources"}/ \u2014 \u6587\u732E\u5361\u7247\u76EE\u5F55\uFF08Base \u6570\u636E\u6765\u6E90\uFF09`),
i
.createEl("div", { cls: "paperforge-dir-children" })
.createEl("div", {
cls: "paperforge-dir-node file",
text: `\u{1F4C1} ${t.literature_dir || "Literature"}/ \u2014 \u6587\u732E\u5361\u7247`,
}),
s.createEl("div", {
cls: "paperforge-dir-node folder",
text: `\u{1F4C1} ${t.base_dir || "Bases"}/ \u2014 \u6570\u636E\u7BA1\u7406\u9762\u677F`,
}),
s.createEl("div", {
cls: "paperforge-dir-node folder",
text: `\u{1F4C1} ${t.system_dir || "System"}/ \u2014 Zotero \u8F6F\u94FE\u63A5 + PaperForge \u7CFB\u7EDF\u6587\u4EF6\u5939`,
}),
e.createEl("p", {
text: o("wizard_preview"),
cls: "paperforge-modal-hint",
}),
e.createEl("p", {
text: o("wizard_safety"),
cls: "paperforge-modal-hint",
}));
let c = e.createEl("div", { cls: "paperforge-summary" }),
d = [
{
label: o("dir_resources"),
val: `${r}/${t.resources_dir || "Resources"}`,
},
{
label: o("dir_notes"),
val: `${r}/${t.resources_dir || "Resources"}/${t.literature_dir || "Literature"}`,
},
{ label: o("dir_base"), val: `${r}/${t.base_dir || "Bases"}` },
{ label: o("dir_system"), val: `${r}/${t.system_dir || "System"}` },
];
for (let f of d) {
let p = c.createEl("div", { cls: "paperforge-summary-row" });
(p.createEl("span", { cls: "paperforge-summary-label", text: f.label }),
p.createEl("span", { cls: "paperforge-summary-value", text: f.val }));
}
}
_stepDirectories(e) {
(e.createEl("h2", { text: o("wizard_step2") }),
e.createEl("p", { text: o("wizard_intro") }));
let t = this.plugin.settings,
r = this.app.vault.adapter.basePath;
(this._modalField(e, o("dir_vault"), r, !0),
e.createEl("p", {
text: o("wizard_dir_hint"),
cls: "paperforge-modal-hint",
}),
this._modalInput(
e,
"\u8D44\u6E90\u76EE\u5F55\uFF08\u521B\u5EFA\u6587\u732E\u5361\u7247\u76EE\u5F55\u7684\u5730\u65B9\uFF09",
"resources_dir",
t.resources_dir,
"Resources"
),
e.createEl("p", {
text: o("wizard_dir_sub_hint"),
cls: "paperforge-modal-hint",
}),
this._modalInput(
e,
"\u6587\u732E\u5361\u7247\u76EE\u5F55\uFF08\u5B58\u653E\u6587\u732E\u5361\u7247\u7684\u5730\u65B9\uFF0CBase \u6570\u636E\u6765\u6E90\uFF09",
"literature_dir",
t.literature_dir,
"Literature"
),
e.createEl("p", {
text: o("wizard_sys_hint"),
cls: "paperforge-modal-hint",
}),
this._modalInput(
e,
"\u7CFB\u7EDF\u76EE\u5F55\uFF08\u5B58\u653E Zotero \u8F6F\u94FE\u63A5\u548C PaperForge \u7CFB\u7EDF\u6587\u4EF6\uFF09",
"system_dir",
t.system_dir,
"System"
),
this._modalInput(
e,
"Base \u76EE\u5F55\uFF08\u5B58\u653E\u6570\u636E\u7BA1\u7406\u9762\u677F\u7684\u5730\u65B9\uFF09",
"base_dir",
t.base_dir,
"Bases"
),
e.createEl("p", {
text: o("wizard_safety"),
cls: "paperforge-modal-hint",
}));
let n = e.createEl("div", { cls: "paperforge-summary" }),
a = [
{ label: o("dir_resources"), val: `${r}/${t.resources_dir || ""}` },
{
label: o("dir_notes"),
val: `${r}/${t.resources_dir || ""}/${t.literature_dir || ""}`,
},
{ label: o("dir_system"), val: `${r}/${t.system_dir || ""}` },
{ label: o("dir_base"), val: `${r}/${t.base_dir || ""}` },
];
for (let s of a) {
let i = n.createEl("div", { cls: "paperforge-summary-row" });
(i.createEl("span", { cls: "paperforge-summary-label", text: s.label }),
i.createEl("span", { cls: "paperforge-summary-value", text: s.val }));
}
}
_stepKeys(e) {
if (
(e.createEl("h2", { text: o("wizard_step3") }), this._showSkipConfirm)
) {
this._renderSkipConfirm(e);
return;
}
let t = this.plugin.settings;
e.createEl("p", {
text: o("wizard_agent_hint"),
cls: "paperforge-modal-hint",
});
let r = [
{ key: "opencode", name: "OpenCode" },
{ key: "claude", name: "Claude Code" },
{ key: "cursor", name: "Cursor" },
{ key: "github_copilot", name: "GitHub Copilot" },
{ key: "windsurf", name: "Windsurf" },
{ key: "codex", name: "Codex" },
{ key: "gemini", name: "Gemini CLI" },
{ key: "cline", name: "Cline" },
],
n = e.createEl("div", { cls: "paperforge-modal-field" });
n.createEl("label", {
cls: "paperforge-modal-label",
text: o("label_agent"),
});
let a = n.createEl("select", { cls: "paperforge-modal-select" });
for (let f of r) {
let p = a.createEl("option", { text: f.name, attr: { value: f.key } });
f.key === (t.agent_platform || "opencode") && (p.selected = !0);
}
(a.addEventListener("change", () => {
((t.agent_platform = a.value),
this._pendingSave && clearTimeout(this._pendingSave),
(this._pendingSave = setTimeout(() => {
(this.plugin.saveSettings(), (this._pendingSave = null));
}, 500)));
}),
e.createEl("p", {
text: o("wizard_keys_hint"),
cls: "paperforge-modal-hint",
}));
let s = e.createEl("div", { cls: "paperforge-modal-field" });
s.createEl("label", {
cls: "paperforge-modal-label",
text: o("field_paddleocr"),
});
let i = s.createEl("input", {
cls: "paperforge-modal-input",
attr: { type: "password", placeholder: "API Key" },
});
((i.value = t.paddleocr_api_key || ""),
(this._apiKeyValidated = !1),
(this._apiKeyStatus = s.createEl("span", {
cls: "paperforge-apikey-status",
text: "",
})));
let l = s.createEl("button", {
cls: "paperforge-step-btn",
text: "\u9A8C\u8BC1",
});
(l.addEventListener("click", () => this._validateApiKey(i.value, l)),
i.addEventListener("input", () => {
((t.paddleocr_api_key = i.value),
(this._apiKeyValidated = !1),
(this._apiKeyStatus.textContent = ""),
(this._apiKeyStatus.className = "paperforge-apikey-status"));
}),
this._pendingSave && clearTimeout(this._pendingSave),
(this._pendingSave = setTimeout(() => {
(this.plugin.saveSettings(), (this._pendingSave = null));
}, 500)),
e.createEl("p", {
text: o("wizard_api_hint_skip"),
cls: "paperforge-modal-hint",
}));
let c = e.createEl("div", { cls: "paperforge-modal-field" });
c.createEl("label", {
cls: "paperforge-modal-label",
text: o("field_zotero_data"),
});
let d = c.createEl("input", {
cls: "paperforge-modal-input",
attr: { type: "text", placeholder: o("field_zotero_placeholder") },
});
((d.value = t.zotero_data_dir || ""),
d.addEventListener("input", () => {
((t.zotero_data_dir = d.value),
this._pendingSave && clearTimeout(this._pendingSave),
(this._pendingSave = setTimeout(() => {
(this.plugin.saveSettings(), (this._pendingSave = null));
}, 500)));
}));
}
_validateApiKey(e, t) {
if (!e || e.length < 10) {
((this._apiKeyStatus.textContent =
"\u5BC6\u94A5\u683C\u5F0F\u4E0D\u6B63\u786E\u3002\u53EF\u70B9\u4E0B\u4E00\u6B65\u8DF3\u8FC7\uFF0C\u7B49\u4F1A\u513F\u518D\u914D\u7F6E\u3002"),
(this._apiKeyStatus.className = "paperforge-apikey-status error"));
return;
}
((t.disabled = !0),
(t.textContent = "\u9A8C\u8BC1\u4E2D\u2026"),
(this._apiKeyStatus.textContent = "\u6B63\u5728\u9A8C\u8BC1\u2026"),
(this._apiKeyStatus.className = "paperforge-apikey-status"));
let r = JSON.stringify({ model: "PaddleOCR-VL-1.5" }),
n = {
hostname: "paddleocr.aistudio-app.com",
path: "/api/v2/ocr/jobs",
method: "POST",
headers: {
Authorization: "bearer " + e,
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(r),
},
timeout: 1e4,
},
a = vt.request(n, (s) => {
((t.disabled = !1), (t.textContent = "\u9A8C\u8BC1"));
let i = "";
(s.on("data", (l) => (i += l)),
s.on("end", () => {
try {
let l = JSON.parse(i);
s.statusCode === 400 && l.code === 10001
? ((this._apiKeyStatus.textContent =
"\u2713 \u5BC6\u94A5\u6709\u6548"),
(this._apiKeyStatus.className =
"paperforge-apikey-status ok"),
(this._apiKeyValidated = !0))
: s.statusCode === 401
? ((this._apiKeyStatus.textContent =
"\u9A8C\u8BC1\u5931\u8D25\uFF1A\u5BC6\u94A5\u65E0\u6548\u3002\u53EF\u70B9\u4E0B\u4E00\u6B65\u8DF3\u8FC7\uFF0C\u7B49\u4F1A\u513F\u518D\u914D\u7F6E\u3002"),
(this._apiKeyStatus.className =
"paperforge-apikey-status error"),
(this._apiKeyValidated = !1))
: ((this._apiKeyStatus.textContent =
"\u9A8C\u8BC1\u5931\u8D25\uFF1AAPI \u8FD4\u56DE " +
s.statusCode +
"\u3002\u53EF\u70B9\u4E0B\u4E00\u6B65\u8DF3\u8FC7\uFF0C\u7B49\u4F1A\u513F\u518D\u914D\u7F6E\u3002"),
(this._apiKeyStatus.className =
"paperforge-apikey-status error"),
(this._apiKeyValidated = !1));
} catch (l) {
((this._apiKeyStatus.textContent =
"\u9A8C\u8BC1\u5931\u8D25\uFF1A\u65E0\u6CD5\u89E3\u6790\u54CD\u5E94\u3002\u53EF\u70B9\u4E0B\u4E00\u6B65\u8DF3\u8FC7\uFF0C\u7B49\u4F1A\u513F\u518D\u914D\u7F6E\u3002"),
(this._apiKeyStatus.className =
"paperforge-apikey-status error"),
(this._apiKeyValidated = !1));
}
}));
});
(a.on("error", (s) => {
((t.disabled = !1),
(t.textContent = "\u9A8C\u8BC1"),
(this._apiKeyStatus.textContent =
"\u9A8C\u8BC1\u5931\u8D25\uFF1A\u65E0\u6CD5\u8FDE\u63A5 (" +
s.message +
")\u3002\u53EF\u70B9\u4E0B\u4E00\u6B65\u8DF3\u8FC7\uFF0C\u7B49\u4F1A\u513F\u518D\u914D\u7F6E\u3002"),
(this._apiKeyStatus.className = "paperforge-apikey-status error"),
(this._apiKeyValidated = !1));
}),
a.write(r),
a.end());
}
_renderSkipConfirm(e) {
e.createEl("p", {
text: o("wizard_skip_ocr_desc"),
cls: "paperforge-modal-desc",
});
let t = e.createEl("div", { cls: "paperforge-modal-actions" });
(t
.createEl("button", {
cls: "paperforge-step-btn mod-cta",
text: o("wizard_skip_ocr_continue"),
})
.addEventListener("click", () => {
((this._showSkipConfirm = !1), this._step++, this._render());
}),
t
.createEl("button", {
cls: "paperforge-step-btn",
text: o("wizard_skip_ocr_back"),
})
.addEventListener("click", () => {
((this._showSkipConfirm = !1), this._render());
}));
}
_modalField(e, t, r, n) {
let a = e.createEl("div", { cls: "paperforge-modal-field" });
a.createEl("label", { cls: "paperforge-modal-label", text: t });
let s = a.createEl("input", {
cls: "paperforge-modal-input",
attr: { type: "text" },
});
((s.value = r), (s.disabled = !!n));
}
_modalInput(e, t, r, n, a) {
let s = e.createEl("div", { cls: "paperforge-modal-field" });
s.createEl("label", { cls: "paperforge-modal-label", text: t });
let i = s.createEl("input", {
cls: "paperforge-modal-input",
attr: { type: "text", placeholder: a || "" },
});
i.value = n;
let l = this.plugin.settings;
i.addEventListener("input", () => {
((l[r] = i.value),
this._pendingSave && clearTimeout(this._pendingSave),
(this._pendingSave = setTimeout(() => {
(this.plugin.saveSettings(), (this._pendingSave = null));
}, 500)));
});
}
_modalSecret(e, t, r, n, a) {
let s = e.createEl("div", { cls: "paperforge-modal-field" });
s.createEl("label", { cls: "paperforge-modal-label", text: t });
let i = s.createEl("input", {
cls: "paperforge-modal-input",
attr: { type: "password", placeholder: a || "" },
});
i.value = n;
let l = this.plugin.settings;
i.addEventListener("input", () => {
((l[r] = i.value),
this._pendingSave && clearTimeout(this._pendingSave),
(this._pendingSave = setTimeout(() => {
(this.plugin.saveSettings(), (this._pendingSave = null));
}, 500)));
});
}
_stepInstall(e) {
(e.createEl("h2", { text: o("wizard_step4") }),
(this._installLog = e.createEl("div", {
cls: "paperforge-install-log",
})));
let t = e.createEl("button", {
cls: "paperforge-step-btn mod-cta",
text: o("install_btn"),
});
t.addEventListener("click", () => this._runInstall(t));
}
async _runInstall(e) {
var s, i, l, c, d, f;
((e.disabled = !0),
(e.textContent = o("install_btn_running")),
this._installLog.setText(
o("install_validating") +
`
`
),
this._log(o("install_validating")));
let t = this.plugin.settings,
r = this._validate();
if (r.length > 0) {
(this._log(o("validate_fail") + ":"),
r.forEach((p) => this._log(" \u2717 " + p)),
(e.disabled = !1),
(e.textContent = o("install_btn_retry")));
return;
}
let n = (p, m = {}) =>
new Promise((y, x) => {
let { path: _, extraArgs: b = [] } = N(
t.vault_path.trim(),
this.plugin.settings,
void 0,
void 0
),
E = (0, Be.spawn)(_, [...b, ...p], {
cwd: t.vault_path.trim(),
env: be(),
timeout: 12e4,
...m,
}),
k = "",
g = "";
(E.stdout.on("data", (v) => {
let w = v.toString("utf-8");
((k += w), m.logStdout && this._processSetupOutput(w));
}),
E.stderr.on("data", (v) => {
let w = v.toString("utf-8");
((g += w), this._log("[stderr] " + w.trim()));
}),
E.on("close", (v) => {
v === 0
? y({ stdout: k, stderr: g })
: x(new Error(g.trim() || k.trim() || `exit code ${v}`));
}),
E.on("error", (v) => x(v)));
}),
a = [
"-m",
"paperforge",
"--vault",
t.vault_path.trim(),
"setup",
"--headless",
"--system-dir",
t.system_dir.trim(),
"--resources-dir",
t.resources_dir.trim(),
"--literature-dir",
t.literature_dir.trim(),
"--base-dir",
t.base_dir.trim(),
"--agent",
t.agent_platform || "opencode",
];
(t.zotero_data_dir &&
t.zotero_data_dir.trim() &&
a.push("--zotero-data", t.zotero_data_dir.trim()),
t.paddleocr_api_key &&
t.paddleocr_api_key.trim() &&
a.push("--paddleocr-key", t.paddleocr_api_key.trim()));
try {
let p = !0;
try {
await n(["-c", "import paperforge"]);
} catch (m) {
p = !1;
}
if (!p) {
this._log(o("install_bootstrapping"));
let m = this.plugin.manifest.version;
this._log(`[install] Trying PyPI: pip install paperforge==${m}`);
let y = ["-m", "pip", "install", "--upgrade"];
(process.platform !== "win32" && y.push("--user"),
y.push(`paperforge==${m}`));
try {
await n(y, { logStdout: !0 });
} catch (x) {
(this._log(
`[install] PyPI failed, falling back to git: git+https://...@v${m}`
),
console.warn(
"[PaperForge] PyPI install failed, falling back to git:",
(s = x.message) == null ? void 0 : s.slice(0, 200)
));
let _ = ["-m", "pip", "install", "--upgrade"];
(process.platform !== "win32" && _.push("--user"),
_.push(`git+https://github.com/LLLin000/PaperForge.git@v${m}`),
await n(_, { logStdout: !0 }));
}
}
(await n(a, { logStdout: !0, env: be() }),
this._log(o("install_complete")),
(t.setup_complete = !0),
await this.plugin.saveSettings(),
setTimeout(() => {
((this._step = 5), this._render());
}, 800));
} catch (p) {
console.error("PaperForge setup failed:", p.message);
let m = this._formatSetupError(p.message);
this._log(o("install_failed") + m);
let y =
(i = this._installLog.parentElement) == null
? void 0
: i.createEl("button", {
cls: "paperforge-copy-diag-btn",
text: o("error_copy_diagnostic") || "Copy diagnostic",
});
if (y) {
let x = p.message,
_ =
((c = (l = this.plugin) == null ? void 0 : l.settings) == null
? void 0
: c.python_path) || "auto",
b =
((f = (d = this.plugin) == null ? void 0 : d.manifest) == null
? void 0
: f.version) || "?",
E = process.platform + " " + process.arch,
k,
g;
try {
k = Ye() || "(not found)";
} catch (P) {
k = "(error)";
}
try {
g = N(t.vault_path.trim(), this.plugin.settings, void 0, void 0);
} catch (P) {
g = null;
}
let v = (process.env.PATH || "").length,
w = (process.env.PATH || "").toLowerCase().includes("git"),
T = [
"[PaperForge Diagnostic]",
"Category: " + m,
"Plugin version: " + b,
"Python: " + _,
"Resolved Python: " + ((g == null ? void 0 : g.path) || "?"),
"OS: " + E,
"Vault path: " + (t.vault_path || "?"),
"--- Git ---",
"Git dir (resolved): " + k,
"PATH length: " + v + " chars",
"PATH contains git: " + w,
"--- Raw error ---",
x.slice(0, 2e3),
].join(`
`);
y.addEventListener("click", () => {
navigator.clipboard
.writeText(T)
.then(() => {
(y.setText(o("error_copied") || "Copied!"),
setTimeout(() => {
y.setText(o("error_copy_diagnostic") || "Copy diagnostic");
}, 3e3));
})
.catch(() => {
new te.Notice("[!!] Clipboard write failed", 6e3);
});
});
}
((e.disabled = !1), (e.textContent = o("install_btn_retry")));
}
}
_log(e) {
this._installLog &&
this._installLog.setText(
this._installLog.textContent +
e +
`
`
);
}
_validate() {
let e = [],
t = this.plugin.settings;
return (
(!t.vault_path || !t.vault_path.trim()) && e.push(o("validate_vault")),
(!t.resources_dir || !t.resources_dir.trim()) &&
e.push(o("validate_resources")),
(!t.literature_dir || !t.literature_dir.trim()) &&
e.push(o("validate_notes")),
(!t.base_dir || !t.base_dir.trim()) && e.push(o("validate_base")),
(!t.paddleocr_api_key || !t.paddleocr_api_key.trim()) &&
this._log(" ! " + o("validate_key") + " " + o("optional_later")),
(!t.zotero_data_dir || !t.zotero_data_dir.trim()) &&
this._log(" ! " + o("validate_zotero") + " " + o("optional_later")),
e
);
}
_processSetupOutput(e) {
let t = e
.split(
`
`
)
.filter(Boolean);
for (let r of t)
if (r.includes("[*]") || r.includes("[OK]") || r.includes("[FAIL]")) {
let n = r
.replace(/^\[\*\].*\d+:?\s*/, "")
.replace(/^\[OK\]\s*/, "")
.replace(/^\[FAIL\]\s*/, "");
this._log(" " + n);
}
}
_formatSetupError(e) {
if (
process.platform === "darwin" &&
/No module named ['"]?paperforge/i.test(e)
)
return "PaperForge not installed \u2014 install Python from Homebrew or python.org (Apple CLT /Library/Developer/CommandLineTools python often fails); then: python3 -m pip install --user git+https://github.com/LLLin000/PaperForge.git";
let t = [
{
match: /pip.*not found|No module named.*pip|command not found.*pip/i,
msg: "pip not found",
},
{
match: /command not found|No such file|not recognized/i,
msg: "Python not found",
},
{
match:
/resolve host|getaddrinfo.*nodename|connect ETIMEDOUT|connect ECONNREFUSED|fetch failed|Network error|ENOTFOUND|ECONNREFUSED|ECONNRESET/i,
msg: "Network error",
},
{
match:
/certificate verify failed|SSL.*certificate|self.signed.cert|CERTIFICATE_VERIFY_FAILED/i,
msg: "SSL certificate error",
},
{ match: /No space left on device|disk full|ENOSPC/i, msg: "Disk full" },
{
match:
/paperforge.*not found|cannot import|ModuleNotFoundError|No module named/i,
msg: "PaperForge not installed",
},
{ match: /permission denied|EACCES|EPERM/i, msg: "Permission denied" },
{ match: /ENOENT/i, msg: "Path not found" },
{ match: /timeout|timed out/i, msg: "Timeout" },
];
for (let n of t) if (n.match.test(e)) return n.msg;
return (
e
.split(
`
`
)
.filter(Boolean)
.slice(0, 3)
.join(" | ")
.slice(0, 200) || "Unknown error"
);
}
_stepComplete(e) {
e.createEl("h2", { text: o("complete_title") });
let t = e.createEl("div", { cls: "paperforge-summary" });
t.createEl("div", {
cls: "paperforge-summary-title",
text: o("complete_summary"),
});
let r = this.plugin.settings,
n = this.app.vault.adapter.basePath,
a = [
{ label: o("dir_vault"), val: n },
{ label: o("dir_resources"), val: `${n}/${r.resources_dir}` },
{
label: o("dir_notes"),
val: `${n}/${r.resources_dir}/${r.literature_dir}`,
},
{ label: o("dir_base"), val: `${n}/${r.base_dir}` },
{ label: o("dir_system"), val: `${n}/${r.system_dir}` },
{
label: "API Key",
val: r.paddleocr_api_key ? o("api_key_set") : o("api_key_missing"),
},
{
label: o("field_zotero_data"),
val: r.zotero_data_dir || o("not_set"),
},
];
for (let d of a) {
let f = t.createEl("div", { cls: "paperforge-summary-row" });
(f.createEl("span", { cls: "paperforge-summary-label", text: d.label }),
f.createEl("span", { cls: "paperforge-summary-value", text: d.val }));
}
let s = t.createEl("div", { cls: "paperforge-summary-row" });
s.createEl("span", { cls: "paperforge-summary-label", text: "PaperForge" });
let i = s.createEl("span", {
cls: "paperforge-summary-value",
text: "\u2014",
});
{
let d = n,
{ path: f, extraArgs: p = [] } = N(
d,
this.plugin.settings,
void 0,
void 0
);
(0, Be.execFile)(
f,
[...p, "-c", "import paperforge; print(paperforge.__version__)"],
{ cwd: d, timeout: 1e4 },
(m, y) => {
!m && y && (i.textContent = "v" + y.trim());
}
);
}
for (let d of a) {
let f = t.createEl("div", { cls: "paperforge-summary-row" });
(f.createEl("span", { cls: "paperforge-summary-label", text: d.label }),
f.createEl("span", { cls: "paperforge-summary-value", text: d.val }));
}
e.createEl("h3", { text: o("complete_next") });
let l = e.createEl("div", { cls: "paperforge-nextsteps" }),
c = [
[o("complete_step4"), o("complete_step4_desc")],
[
"",
`${o("complete_export_path")} ${n}/${r.system_dir}/PaperForge/exports/`,
],
[o("complete_step1"), o("complete_step1_desc")],
[o("complete_step2"), o("complete_step2_desc")],
[o("complete_step3"), o("complete_step3_desc")],
];
for (let [d, f] of c) {
let p = l.createEl("div", { cls: "paperforge-nextstep-item" });
(d && p.createEl("strong", { text: d }), p.createEl("span", { text: f }));
}
}
};
var ke = V(require("fs")),
$e = V(require("path")),
xt = require("child_process");
function Et(u) {
return $e.join(u, "System", "PaperForge", "cache", "ocr_maintenance.json");
}
function kt(u) {
try {
let h = Et(u),
e = ke.readFileSync(h, "utf-8");
return JSON.parse(e);
} catch (h) {
return null;
}
}
function Ve(u, h) {
let e = Et(u),
t = $e.dirname(e);
(ke.mkdirSync(t, { recursive: !0 }),
ke.writeFileSync(e, JSON.stringify(h, null, 2), "utf-8"));
}
function bt(u, h, e) {
return new Promise((t, r) => {
(0, xt.execFile)(u, h, e, (n, a) => {
n ? r(n) : t(a);
});
});
}
async function wt(u, h, e, t) {
let r = await bt(h, [...e, "-m", "paperforge", "ocr", "list", "--manifest"], {
cwd: u,
timeout: 3e4,
}),
n = JSON.parse(r);
if (t) {
let d = Object.keys(t.manifest),
f = Object.keys(n);
if (d.length === f.length && d.every((m) => t.manifest[m] === n[m]))
return {
data: Object.values(t.papers).filter((y) => y.visible_in_maintenance),
changed: !1,
};
}
let a = Object.keys(n).filter(
(d) => !(t != null && t.manifest[d]) || t.manifest[d] !== n[d]
),
s = await bt(
h,
[...e, "-m", "paperforge", "ocr", "list", "--json", "--keys", ...a],
{ cwd: u, timeout: 3e4 }
),
i = JSON.parse(s),
l = { manifest: n, papers: {}, cached_at: new Date().toISOString() };
if (t != null && t.papers)
for (let d of Object.keys(n)) t.papers[d] && (l.papers[d] = t.papers[d]);
for (let d of i) l.papers[d.key] = d;
return (
Ve(u, l),
{
data: Object.values(l.papers).filter((d) => d.visible_in_maintenance),
changed: !0,
}
);
}
var He = class extends R.PluginSettingTab {
constructor(e, t) {
super(e, t);
this._saveTimeout = null;
this._pfConfig = null;
this._lastSyncTime = null;
this._memoryStatusText = null;
this._vectorDepsOk = null;
this._embedStatusText = null;
this._skillsCollapsed = { user: !0 };
this._featurePanelsCollapsed = {};
this._advCollapsed = !0;
this._refreshPending = !1;
this._pythonInterpDescEl = null;
this._customPathDescEl = null;
this._checkEl = null;
this.activeTab = "setup";
this._buildState = "idle";
this._buildProgress = { current: 0, total: 0, key: "" };
this.plugin = t;
}
_refreshPfConfig() {
this._pfConfig = this.plugin.readPaperforgeJson();
}
display() {
let { containerEl: e } = this;
if (
(e.empty(),
this._refreshPfConfig(),
!document.getElementById("paperforge-tab-styles"))
) {
let a = document.createElement("style");
((a.id = "paperforge-tab-styles"),
(a.textContent = `
.paperforge-settings-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--background-modifier-border); }
.paperforge-settings-tab { padding: 6px 16px; border: none; background: none; cursor: pointer; border-bottom: 2px solid transparent; font-size: 14px; color: var(--text-muted); }
.paperforge-settings-tab--active { color: var(--text-accent); border-bottom-color: var(--text-accent); }
.paperforge-tab-content { display: none; }
.paperforge-tab-content--active { display: block; }
.paperforge-skills-collapse-header { display: flex !important; align-items: center; cursor: pointer; padding: 6px 0 !important; margin: 0 !important; }
.paperforge-skills-collapse-header h4 { margin: 0 !important; }
.paperforge-skills-collapse-content { margin: 0 !important; padding: 0 !important; }
.paperforge-skills-group { margin-bottom: 10px; }
.paperforge-skills-group:last-child { margin-bottom: 0; }
.vertical-tab-content-container { overflow-y: scroll !important; }
.paperforge-release-card { border: 1px solid var(--background-modifier-border); border-radius: 6px; padding: 12px; margin-bottom: 12px; }
.paperforge-release-header { margin-bottom: 8px; }
.paperforge-release-date { color: var(--text-muted); font-size: 12px; }
.paperforge-release-section { margin-bottom: 6px; }
.paperforge-release-label { font-weight: 600; color: var(--text-accent); margin-bottom: 2px; font-size: 13px; }
.paperforge-release-item { font-size: 13px; margin-left: 8px; color: var(--text-muted); }
.paperforge-release-item-bold { font-size: 13px; margin-left: 8px; font-weight: 600; color: var(--text-normal); }
.paperforge-release-recommended { background: rgba(var(--color-orange-rgb, 255,166,0), 0.08); border-radius: 4px; padding: 6px 8px; }
.paperforge-manual-links { margin-top: 8px; }
.paperforge-manual-links a { color: var(--text-accent); }
.paperforge-modal-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.paperforge-modal-item { font-size: 13px; margin-left: 8px; color: var(--text-muted); }
`),
document.head.appendChild(a));
}
let t = e.createDiv({ cls: "paperforge-settings-tabs" }),
r = [
{ id: "setup", label: o("tab_setup") || "\u5B89\u88C5" },
{ id: "features", label: o("tab_features") || "\u529F\u80FD" },
{ id: "maintenance", label: o("tab_maintenance") || "\u7EF4\u62A4" },
{ id: "release-notes", label: "\u66F4\u65B0\u4E0E\u624B\u518C" },
],
n = {};
(r.forEach((a) => {
t.createEl("button", {
cls:
"paperforge-settings-tab" +
(a.id === this.activeTab ? " paperforge-settings-tab--active" : ""),
text: a.label,
}).addEventListener("click", () => {
((this.activeTab = a.id), this.display());
});
}),
r.forEach((a) => {
n[a.id] = e.createDiv({
cls:
"paperforge-tab-content" +
(a.id === this.activeTab ? " paperforge-tab-content--active" : ""),
});
}),
this.activeTab === "setup"
? this._renderSetupTab(n.setup)
: this.activeTab === "features"
? this._renderFeaturesTab(n.features)
: this.activeTab === "maintenance"
? this._renderMaintenanceTab(n.maintenance)
: this._renderReleaseNotesTab(n["release-notes"]));
}
_renderSetupTab(e) {
let t = this.app.vault.adapter.basePath;
(this.plugin.settings.vault_path ||
((this.plugin.settings.vault_path = t), this._debouncedSave()),
this.plugin.settings.setup_complete &&
($.existsSync(X.join(t, "paperforge.json")) ||
((this.plugin.settings.setup_complete = !1), this._debouncedSave())),
e.createEl("h2", { text: o("header_title") || "PaperForge" }),
e.createEl("p", { text: o("desc"), cls: "paperforge-settings-desc" }));
let n = e
.createEl("div", { cls: "paperforge-setup-bar" })
.createEl("span", { cls: "paperforge-setup-label" });
this.plugin.settings.setup_complete
? (n.setText(o("setup_done")), n.addClass("paperforge-setup-done"))
: (n.setText(o("setup_pending")), n.addClass("paperforge-setup-pending"));
let a = this.app.vault.adapter.basePath,
s = N(a, this.plugin.settings, void 0, void 0),
i = s.path,
l = this.plugin.settings._python_path_stale ? "stale" : s.source,
c = new R.Setting(e)
.setName(o("field_python_interp"))
.setDesc(this._getPythonDesc(i, l));
this._pythonInterpDescEl = c.descEl;
let d = new R.Setting(e).setName(o("field_python_custom")).setDesc("");
((this._customPathDescEl = d.descEl),
d.addText((k) => {
k.setPlaceholder("e.g. C:\\Python310\\python.exe")
.setValue(this.plugin.settings.python_path || "")
.onChange((g) => {
if (
((this.plugin.settings.python_path = g),
this.plugin.saveSettings(),
g && g.trim())
) {
let T = $.existsSync(g.trim());
this.plugin.settings._python_path_stale = !T;
} else this.plugin.settings._python_path_stale = !1;
let v = N(
this.app.vault.adapter.basePath,
this.plugin.settings,
void 0,
void 0
),
w = this.plugin.settings._python_path_stale ? "stale" : v.source;
this._pythonInterpDescEl &&
(this._pythonInterpDescEl.textContent = this._getPythonDesc(
v.path,
w
));
});
}),
d.addButton((k) => {
k.setButtonText(o("btn_validate")).onClick(() =>
this._validatePythonOverride()
);
}),
e.createEl("h3", { text: o("runtime_health") }),
e.createEl("p", {
text: o("runtime_health_desc"),
cls: "paperforge-settings-desc",
}));
let f = new R.Setting(e)
.setName("PaperForge")
.setDesc(o("runtime_health_checking")),
p = f.descEl.createEl("span", { cls: "paperforge-runtime-badge" }),
m = null;
f.addButton((k) => {
((m = k),
k
.setButtonText(o("runtime_health_sync"))
.setDisabled(!0)
.onClick(() => this._syncRuntime(k)));
});
{
let k = this.app.vault.adapter.basePath,
{ path: g, extraArgs: v = [] } = N(
k,
this.plugin.settings,
void 0,
void 0
),
w = this.plugin.manifest.version || "?";
(0, K.execFile)(
g,
[...v, "-c", "import paperforge; print(paperforge.__version__)"],
{ cwd: k, timeout: 1e4 },
(T, P) => {
let L = this.plugin.settings.setup_complete,
O = !T && P ? P.trim() : null,
z = O
? `${o("runtime_health_plugin_ver").replace("{0}", w)} \u2192 ${o("runtime_health_package_ver").replace("{0}", O)}`
: L
? `Plugin v${w} \u2192 Python package not installed. Click "Sync Runtime" to install.`
: `Plugin v${w} \u2192 Not configured. Please open the setup wizard first.`;
(f.setDesc(z),
O === w
? (p.setText(o("runtime_health_match")),
(p.className = "paperforge-runtime-badge match"),
m && m.setDisabled(!0))
: O
? (p.setText(o("runtime_health_mismatch")),
(p.className = "paperforge-runtime-badge mismatch"),
m && m.setDisabled(!1))
: (p.setText(L ? "Not installed" : "Setup needed"),
(p.className = "paperforge-runtime-badge missing"),
m && m.setDisabled(!1)));
}
);
}
(e.createEl("h3", { text: o("section_prep") }),
e.createEl("p", {
text: o("section_prep_desc"),
cls: "paperforge-settings-desc",
}));
let y = e.createEl("div", { cls: "paperforge-guide" }),
x = [
["prep_python", "prep_python_desc"],
["prep_zotero", "prep_zotero_desc"],
["prep_bbt", "prep_bbt_desc"],
["prep_key", "prep_key_desc"],
];
for (let [k, g] of x) {
let v = y.createEl("div", { cls: "paperforge-guide-item" });
(v.createEl("strong", { text: o(k) }),
v.createEl("span", { text: " \u2014 " + o(g) }));
}
this._checkEl = e.createEl("div", { cls: "paperforge-message" });
let _ = !this.plugin.settings.setup_complete;
(new R.Setting(e)
.setName(o(_ ? "btn_install" : "btn_reconfig"))
.setDesc(o(_ ? "btn_install_desc" : "btn_reconfig_desc"))
.addButton((k) => {
k.setButtonText(o(_ ? "btn_install" : "btn_reconfig"))
.setCta()
.onClick(() => {
_
? this._preCheck(() => {
new De(this.app, this.plugin).open();
})
: new De(this.app, this.plugin).open();
});
}),
e.createEl("h3", { text: o("section_guide") }));
let b = e.createEl("div", { cls: "paperforge-guide" }),
E = [
["guide_open", "guide_open_desc"],
["guide_sync", "guide_sync_desc"],
["guide_ocr", "guide_ocr_desc"],
];
for (let [k, g] of E) {
let v = b.createEl("div", { cls: "paperforge-guide-item" });
(v.createEl("strong", { text: o(k) }),
v.createEl("span", { text: " \u2014 " + o(g) }));
}
if (this.plugin.settings.setup_complete) {
e.createEl("h3", { text: o("section_config") });
let k = e.createEl("div", { cls: "paperforge-summary" }),
g = this.plugin.settings,
v = this._pfConfig,
w = [
{ label: o("dir_vault"), val: t },
{
label: o("dir_resources"),
val: `${t}/${v == null ? void 0 : v.resources_dir}`,
},
{
label: " " + o("dir_notes"),
val: `${t}/${v == null ? void 0 : v.resources_dir}/${v == null ? void 0 : v.literature_dir}`,
},
{
label: o("dir_base"),
val: `${t}/${v == null ? void 0 : v.base_dir}`,
},
{
label: o("dir_system"),
val: `${t}/${v == null ? void 0 : v.system_dir}`,
},
{
label: "API Key",
val: g.paddleocr_api_key ? o("api_key_set") : o("api_key_missing"),
},
{
label: o("field_zotero_data"),
val: g.zotero_data_dir || o("not_set"),
},
];
for (let T of w) {
let P = k.createEl("div", { cls: "paperforge-summary-row" });
(P.createEl("span", { cls: "paperforge-summary-label", text: T.label }),
P.createEl("span", { cls: "paperforge-summary-value", text: T.val }));
}
}
}
_execMemoryStatus(e, t, r) {
(0, K.exec)(
`"${e}" -m paperforge --vault "${t}" memory status --json`,
{ encoding: "utf-8", timeout: 15e3 },
(n, a) => {
if (n) {
r("Status unavailable");
return;
}
try {
let s = JSON.parse(a);
if (s.ok) {
let i = s.data,
l = i.fresh ? "fresh" : "stale";
r(
`Papers: ${i.paper_count_db} | ${l}${i.needs_rebuild ? " - needs rebuild" : ""}`
);
} else r("DB not found. Run paperforge memory build.");
} catch (s) {
r("Could not parse status.");
}
}
);
}
_execEmbedStatus(e, t, r) {
(0, K.exec)(
`"${e}" -m paperforge --vault "${t}" embed status --json`,
{ encoding: "utf-8", timeout: 15e3 },
(n, a) => {
if (n) {
r("Status unavailable");
return;
}
try {
let s = JSON.parse(a);
s.ok
? r(
`Chunks: ${s.data.chunk_count} | ${s.data.model} | ${s.data.mode}`
)
: r("Could not parse status.");
} catch (s) {
r("Could not parse status.");
}
}
);
}
_callPython(e, t) {
let r = this.app.vault.adapter.basePath,
n = ue(r, this.plugin.settings),
a = [...n.extraArgs, "-m", "paperforge", "--vault", r, ...e];
if (t && t.stream) {
let s = (0, K.spawn)(n.path, a, {
cwd: r,
env: t.env || process.env,
windowsHide: !0,
});
return (
t.onData && s.stdout.on("data", t.onData),
t.onStderr && s.stderr.on("data", t.onStderr),
t.onError && s.on("error", t.onError),
s.on("close", t.onClose),
s
);
}
return (
(0, K.execFile)(
n.path,
a,
{ cwd: r, timeout: (t && t.timeout) || 6e4 },
(s, i, l) => {
t && t.onClose && t.onClose(s ? 1 : 0, i, l);
}
),
null
);
}
_renderMemoryStatusText(e, t, r) {
((e.innerHTML = ""),
e.createEl("span", { text: t, cls: "paperforge-memory-text" }),
r === "syncing"
? e.createEl("span", {
text: "Syncing...",
cls: "paperforge-sync-status",
})
: r && e.createEl("span", { text: r, cls: "paperforge-sync-status" }));
let n = e.createEl("button", {
cls: "paperforge-rebuild-btn",
text: o("feat_memory_rebuild_btn"),
});
((n.title = "Rebuild memory database"),
(n.onclick = () => {
let s = this.app.vault.adapter.basePath,
i = ue(s, this.plugin.settings);
if (!i.path) {
new R.Notice(o("feat_no_python"));
return;
}
(console.log("[PaperForge] Rebuilding memory:", i.path),
n.setText(o("feat_memory_rebuilding")),
n.setAttr("disabled", ""),
this._callPython(["memory", "build"], {
timeout: 6e4,
onClose: (l, c, d) => {
(console.log(
"[PaperForge] memory build exit:",
l ? "FAIL:" + l : "OK",
(c || "").slice(0, 200),
(d || "").slice(0, 200)
),
n.setText(o("feat_memory_rebuild_btn")),
n.removeAttribute("disabled"),
l === 0
? new R.Notice(o("feat_memory_rebuild_done"))
: new R.Notice(
o("feat_memory_rebuild_failed") +
(d ? " " + d.slice(0, 80) : "")
),
(this._memoryStatusText = je(s)),
this._refreshSnapshots(s));
},
}));
}));
let a = e.createEl("button", {
cls: "paperforge-refresh-btn",
text: "\u21BB",
});
((a.title = "Sync now"),
(a.onclick = () => {
((this._memoryStatusText = null), this._runManualSync());
}));
}
_getBuildCommand(e) {
let t = this.app.vault.adapter.basePath,
r = N(t, e, void 0, void 0);
return r.path ? `"${r.path}" -m paperforge --vault "${t}" sync` : null;
}
_runManualSync() {
let e = this.app.vault.adapter.basePath;
if (!ue(e, this.plugin.settings).path) return;
let r = document.querySelector(".paperforge-memory-status");
(r && this._renderMemoryStatusText(r, "Checking...", "syncing"),
(this.plugin._autoSyncRunning = !0),
this._callPython(["sync"], {
timeout: 12e4,
onClose: (n) => {
((this.plugin._autoSyncRunning = !1),
(this._memoryStatusText = null),
n === 0 &&
((this._lastSyncTime = new Date().toLocaleTimeString()),
(this.plugin._lastSyncTime = this._lastSyncTime)),
this.display(),
this._refreshSnapshots(e),
ze(this.app, this.plugin, e));
},
}));
}
_refreshSnapshots(e) {
let t = ue(e, this.plugin.settings),
r = [
...t.extraArgs,
"-m",
"paperforge",
"--vault",
e,
"runtime-health",
"--json",
];
((this._refreshPending = !0),
(0, K.execFile)(
t.path,
r,
{ cwd: e, timeout: 3e4, windowsHide: !0 },
(n, a, s) => {
((this._refreshPending = !1),
(this._memoryStatusText = je(e)),
(this._embedStatusText = Ee(e)),
this.display());
}
));
}
_renderFeaturesTab(e) {
e.createEl("h3", { text: "Skills" });
let t = e.createEl("div", { cls: "paperforge-desc-box" });
(t.setText(o("feat_skills_desc")),
t.createEl("br"),
t.createEl("span", { text: o("feat_skills_system") }));
let r = {
opencode: "OpenCode",
claude: "Claude Code",
codex: "Codex",
cursor: "Cursor",
windsurf: "Windsurf",
github_copilot: "GitHub Copilot",
gemini: "Gemini CLI",
},
n = {
opencode: ".opencode/skills",
claude: ".claude/skills",
codex: ".codex/skills",
cursor: ".cursor/skills",
windsurf: ".windsurf/skills",
github_copilot: ".github/skills",
gemini: ".gemini/skills",
},
a = this.app.vault.adapter.basePath,
s = this.plugin.settings.selected_skill_platform || "opencode";
new R.Setting(e)
.setName(o("feat_agent_platform"))
.setDesc(o("feat_agent_platform_desc"))
.addDropdown((g) => {
(Object.entries(r).forEach(([v, w]) => g.addOption(v, w)),
g.setValue(s).onChange((v) => {
((this.plugin.settings.selected_skill_platform = v),
this.plugin.saveSettings(),
this.display());
}));
})
.addExtraButton((g) => {
g.setIcon("folder")
.setTooltip("Open skills folder")
.onClick(() => {
let v = n[s] || ".opencode/skills",
w = X.join(a, v);
$.existsSync(w)
? (0, K.exec)(`start "" "${w}"`)
: new R.Notice(`Skills folder not found: ${v}`);
});
});
let i = X.join(a, n[s]),
l = [],
c = [];
$.existsSync(i) &&
$.readdirSync(i, { withFileTypes: !0 }).forEach((g) => {
if (!g.isDirectory()) return;
let v = X.join(i, g.name, "SKILL.md");
if (!$.existsSync(v)) return;
let w = $.readFileSync(v, "utf-8"),
T = w.match(/^name:\s*(.+)$/m),
P = w.split(`
`),
L = P.findIndex((M) => /^description:/.test(M)),
O = "";
if (L >= 0) {
let M = P[L].match(/^description:\s*(.+)$/);
if (M && M[1] && M[1] !== ">" && M[1] !== "|-" && M[1] !== "|")
O = M[1].trim();
else {
for (
let C = L + 1;
C < P.length && (/^\s{2,}/.test(P[C]) || P[C].trim() === "");
C++
)
O += P[C].trim() + " ";
O = O.trim();
}
}
let z = w.match(/^source:\s*(.+)$/m),
q = w.match(/^disable-model-invocation:\s*(.+)$/m),
D = w.match(/^version:\s*(.+)$/m),
S = {
name: T ? T[1].trim() : g.name,
desc: O,
source: z ? z[1].trim() : "user",
disabled: q && q[1].trim() === "true",
version: D ? D[1].trim() : "",
path: v,
content: w,
dirName: g.name,
};
S.source === "paperforge" ? l.push(S) : c.push(S);
});
let d = e.createEl("div", { cls: "paperforge-skills-box" }),
f = (g, v, w) => {
if (v.length === 0) return;
let T = d.createEl("div", { cls: "paperforge-skills-group" }),
P = T.createEl("div", { cls: "paperforge-skills-collapse-header" }),
L = T.createEl("div", { cls: "paperforge-skills-collapse-content" }),
O = P.createEl("span", {
text: "\u25BC",
cls: "paperforge-skills-arrow",
});
(P.createEl("h4", {
text: `${g} (${v.length})`,
cls: "paperforge-skills-subheader",
}),
v.forEach((D) => {
let S = D.name + (D.version ? " v" + D.version : ""),
M = w ? " [system]" : " [user]",
C = D.desc || "",
F = new R.Setting(L).setName(S + M).setDesc(C);
((F.settingEl.style.opacity = D.disabled ? "0.4" : "1"),
F.addToggle((A) => {
A.setValue(!D.disabled).onChange((J) => {
let G = !J,
Q = D.content.match(/^disable-model-invocation:\s*(.+)$/m)
? D.content.replace(
/^disable-model-invocation:\s*.+$/m,
`disable-model-invocation: ${G}`
)
: D.content.replace(
/^(---\r?\n)/,
`$1disable-model-invocation: ${G}
`
);
($.writeFileSync(D.path, Q, "utf-8"),
(D.disabled = G),
(D.content = Q),
(F.settingEl.style.opacity = D.disabled ? "0.4" : "1"));
});
}));
}));
let z = w ? "system" : "user";
((this._skillsCollapsed[z] || !1) &&
((L.style.display = "none"), (O.style.transform = "rotate(-90deg)")),
P.addEventListener("click", () => {
(L.style.display !== "none"
? ((L.style.display = "none"),
(O.style.transform = "rotate(-90deg)"))
: ((L.style.display = ""), (O.style.transform = "rotate(0deg)")),
(this._skillsCollapsed[z] = L.style.display === "none"));
}));
};
(f("System Skills", l, !0),
f("User Skills", c, !1),
l.length === 0 &&
c.length === 0 &&
d.createEl("p", {
text: `No skills found in ${n[s]}. Run setup to deploy skills.`,
cls: "setting-item-description",
}),
this._advCollapsed === void 0 && (this._advCollapsed = !0));
let p = e.createEl("div", { cls: "paperforge-collapsible-header" }),
m = p.createEl("span", {
text: "\u25B6",
cls: "paperforge-collapsible-arrow",
});
m.style.transform = this._advCollapsed ? "rotate(0deg)" : "rotate(90deg)";
let y = p.createEl("span", {
cls: "paperforge-collapsible-title",
text: "Advanced",
}),
x = p.createEl("span", {
cls: "paperforge-collapsible-sub",
text: "Memory + Vector DB + Embedding",
}),
_ = e.createEl("div", { cls: "paperforge-collapsible-content" });
((_.style.display = this._advCollapsed ? "none" : ""),
p.addEventListener("click", () => {
((this._advCollapsed = !this._advCollapsed),
(_.style.display = this._advCollapsed ? "none" : ""),
(m.style.transform = this._advCollapsed
? "rotate(0deg)"
: "rotate(90deg)"));
}),
_.createEl("h4", { text: "Memory Layer" }),
_.createEl("div", { cls: "paperforge-desc-box" }).setText(
o("feat_memory_desc")
));
let E = _.createEl("div", { cls: "paperforge-memory-status" }),
k = this.app.vault.adapter.basePath;
(this.plugin._lastSyncTime &&
!this._lastSyncTime &&
(this._lastSyncTime = this.plugin._lastSyncTime),
this._memoryStatusText === null && (this._memoryStatusText = je(k)),
this._renderMemoryStatusText(
E,
this._memoryStatusText,
this._lastSyncTime
),
this._renderVectorSection(_));
}
_renderVectorSection(e) {
var l;
if (
(e.createEl("h4", { text: "Vector Database" }),
this.plugin.settings.features ||
(this.plugin.settings.features = { memory_layer: !0, vector_db: !1 }),
e
.createEl("div", { cls: "paperforge-desc-box" })
.setText(o("feat_vector_desc")),
new R.Setting(e)
.setName(o("feat_vector_enable"))
.setDesc(o("feat_vector_enable_desc"))
.addToggle((c) => {
c.setValue(!!this.plugin.settings.features.vector_db).onChange(
(d) => {
((this.plugin.settings.features.vector_db = d),
this.plugin.saveSettings(),
(this._vectorDepsOk = null),
(this._embedStatusText = null),
this.display());
}
);
}),
!this.plugin.settings.features.vector_db)
)
return;
let r = this.app.vault.adapter.basePath,
n = e.createEl("div", { cls: "paperforge-vec-header" }),
a = n.createEl("span", {
text: "\u25BC",
cls: "paperforge-skills-arrow",
});
n.createEl("span", {
cls: "paperforge-vec-header-label",
text: o("feat_vector_config_label"),
});
let s = e.createEl("div", { cls: "paperforge-vector-config" }),
i = (c) => {
((s.style.display = c ? "none" : ""),
(a.style.transform = c ? "rotate(-90deg)" : "rotate(0deg)"));
};
if (
(i(rt(this._featurePanelsCollapsed, "vectorConfig", !1)),
n.addEventListener("click", () => {
let c = gt(this._featurePanelsCollapsed, "vectorConfig", !1);
i(c);
}),
this._vectorDepsOk === !0)
) {
this._renderVectorReady(s, r);
return;
}
if (this._vectorDepsOk === !1) {
this._renderVectorNoDeps(s);
return;
}
if (this._vectorDepsOk === null) {
let c = Ne(r);
((this._vectorDepsOk = c && (l = c.deps_installed) != null ? l : !1),
this._vectorDepsOk && (this._embedStatusText = Ee(r)),
this.display());
}
}
_renderApiConfig(e) {
(new R.Setting(e)
.setName(o("feat_openai_key"))
.setDesc(o("feat_openai_key_desc"))
.addText((t) => {
t.setPlaceholder("sk-...")
.setValue(this.plugin.settings.vector_db_api_key || "")
.onChange((r) => {
((this.plugin.settings.vector_db_api_key = r),
this.plugin.saveSettings());
});
}),
new R.Setting(e)
.setName(o("feat_api_base_url"))
.setDesc(o("feat_api_base_url_desc"))
.addText((t) => {
t.setPlaceholder("https://api.openai.com/v1")
.setValue(this.plugin.settings.vector_db_api_base || "")
.onChange((r) => {
((this.plugin.settings.vector_db_api_base = r),
this.plugin.saveSettings());
});
}),
new R.Setting(e)
.setName(o("feat_api_model"))
.setDesc(o("feat_api_model_desc"))
.addText((t) => {
t.setPlaceholder("text-embedding-3-small")
.setValue(
this.plugin.settings.vector_db_api_model ||
"text-embedding-3-small"
)
.onChange((r) => {
((this.plugin.settings.vector_db_api_model = r),
this.plugin.saveSettings());
});
}));
}
_renderVectorNoDeps(e) {
(e
.createEl("div", { cls: "paperforge-desc-box" })
.setText(o("feat_deps_missing")),
new R.Setting(e)
.setName(o("feat_install_deps"))
.setDesc(o("feat_install_deps_desc"))
.addButton((r) => {
r.setButtonText(o("feat_install_btn"))
.setCta()
.onClick(async () => {
let n = this.app.vault.adapter.basePath,
a = ue(n, this.plugin.settings);
if (!a.path) {
new R.Notice(o("feat_no_python"));
return;
}
(r.setButtonText(o("feat_installing")), r.setDisabled(!0));
let s = "chromadb openai",
i = new R.Notice(
o("feat_installing_pkgs").replace("{pkgs}", s),
0
);
try {
let l = Object.assign({}, process.env, {
PYTHONIOENCODING: "utf-8",
PYTHONUTF8: "1",
}),
c = s.split(" ");
(await new Promise((d, f) => {
(0, K.execFile)(
a.path,
[...a.extraArgs, "-m", "pip", "install", ...c],
{ cwd: n, timeout: 3e5, env: l, windowsHide: !0 },
(p) => {
p ? f(p) : d();
}
);
}),
i.hide(),
new R.Notice(o("feat_install_done")),
(this._vectorDepsOk = !0),
(this._embedStatusText = Ee(n)),
this.display());
} catch (l) {
(i.hide(),
new R.Notice(
o("feat_install_failed") + (l.stderr || l.message || l)
),
r.setButtonText(o("feat_retry_btn")),
r.setDisabled(!1));
}
});
}));
}
_renderVectorReady(e, t) {
(e.createEl("div", { cls: "paperforge-desc-box" }).setText(Ee(t)),
this._renderApiConfig(e));
let n = e.createEl("div", { cls: "paperforge-embed-section" });
n.createEl("div", { cls: "paperforge-embed-header" }).createEl("span", {
text: o("retrieval_rebuild_vectors"),
cls: "setting-item-name",
});
let s = n.createEl("div", { cls: "paperforge-embed-controls" }),
i = n.createEl("div", {
cls: "paperforge-embed-status-text",
attr: { "aria-live": "polite" },
});
(() => {
(s.empty(), i.empty());
let c = Ne(t),
d = c == null ? void 0 : c.build_state,
f = d && typeof d == "object" && !Array.isArray(d) ? d : {};
((this.plugin._embedProgress = this.plugin._embedProgress || {
current: 0,
total: 0,
key: "",
}),
!this.plugin._embedProcess &&
f.status === "running" &&
(this.plugin._embedProgress = {
current: typeof f.current == "number" ? f.current : 0,
total: typeof f.total == "number" ? f.total : 1,
key: typeof f.paper_id == "string" ? f.paper_id : "",
}));
let { current: p, total: m, key: y } = this.plugin._embedProgress,
x =
typeof (c == null ? void 0 : c.body_chunk_count) == "number"
? c.body_chunk_count
: 0,
_ =
typeof (c == null ? void 0 : c.object_chunk_count) == "number"
? c.object_chunk_count
: 0,
E =
(typeof (c == null ? void 0 : c.chunk_count) == "number"
? c.chunk_count
: 0) +
x +
_,
k = E > 0,
g = c !== null && typeof c.corrupted == "boolean" && c.corrupted,
v = !!this.plugin._embedProcess,
w = !this.plugin._embedProcess && f.status === "running",
T =
(c == null ? void 0 : c.deps_installed) !== void 0
? !!c.deps_installed
: !0,
P = typeof f.status == "string" ? f.status : "",
L = typeof f.message == "string" ? f.message : "",
O = (S) => {
var F;
if (S === "--resume" && k && !g) {
let A = o("retrieval_rebuild_warning").replace("{n}", String(E));
if (!confirm(A)) return;
}
if (S === "--force" && k && !g) {
let A =
"Force rebuild will replace " +
E +
" existing chunk(s). Continue?";
if (!confirm(A)) return;
}
if (!ue(t, this.plugin.settings).path) {
new R.Notice(o("retrieval_no_python"));
return;
}
let C = Object.assign({}, process.env, {
PYTHONIOENCODING: "utf-8",
PYTHONUTF8: "1",
VECTOR_DB_API_KEY: this.plugin.settings.vector_db_api_key || "",
VECTOR_DB_API_BASE: this.plugin.settings.vector_db_api_base || "",
VECTOR_DB_API_MODEL: this.plugin.settings.vector_db_api_model || "",
});
((this.plugin._embedStderr = ""),
(this.plugin._embedProgress = { current: 0, total: 0, key: "" }),
(this.plugin._embedProcess = this._callPython(
["embed", "build", S],
{
stream: !0,
env: C,
onData: (A) => {
let G = (
typeof A == "string"
? A
: Buffer.isBuffer(A)
? A.toString("utf-8")
: String(A)
).split(`
`);
for (let ee of G)
if (ee.startsWith("EMBED_START:"))
this.plugin._embedProgress.total =
parseInt(ee.split(":")[1]) || 0;
else if (ee.startsWith("EMBED_PROGRESS:")) {
let Q = ee.split(":");
((this.plugin._embedProgress.current =
parseInt(Q[1]) || 0),
(this.plugin._embedProgress.key = Q[3] || ""));
} else
ee.startsWith("EMBED_DONE") &&
((this.plugin._embedProcess = null),
(this.plugin._embedProgress.current =
this.plugin._embedProgress.total));
this.display();
},
onStderr: (A) => {
(this.plugin._embedStderr || (this.plugin._embedStderr = ""),
(this.plugin._embedStderr += String(A)));
},
onError: (A) => {
((this.plugin._embedProcess = null),
new R.Notice(
o("feat_build_failed") + ": " + (A.message || A)
),
this.display());
},
onClose: (A) => {
var J;
if (
(clearInterval(
(J = this.plugin._embedPollInterval) != null ? J : void 0
),
(this.plugin._embedPollInterval = null),
(this.plugin._embedProcess = null),
A === 0)
)
((this.plugin._embedProgress.current =
this.plugin._embedProgress.total),
this.plugin.saveSettings(),
(this._embedStatusText = Ee(t)),
new R.Notice(o("feat_build_complete")));
else {
this._embedStatusText = null;
let G = (this.plugin._embedStderr || "").slice(0, 200);
new R.Notice(
o("feat_build_failed") + (G ? ": " + G : ""),
8e3
);
}
((this.plugin._embedStderr = ""),
this.display(),
this._refreshSnapshots(t));
},
}
)),
clearInterval(
(F = this.plugin._embedPollInterval) != null ? F : void 0
),
(this.plugin._embedPollInterval = setInterval(() => {
this.plugin._embedPolling ||
((this.plugin._embedPolling = !0),
this._callPython(["embed", "status", "--json"], {
timeout: 5e3,
onClose: (A, J) => {
var G;
if (((this.plugin._embedPolling = !1), A === 0 && J))
try {
let Q = JSON.parse(J).data;
if (Q && Q.build_state) {
let re = Q.build_state;
((re.status === "stopping" || re.status === "idle") &&
this.plugin._embedProcess &&
((this.plugin._embedProcess = null),
clearInterval(
(G = this.plugin._embedPollInterval) != null
? G
: void 0
),
(this.plugin._embedPollInterval = null),
this.display()),
re.current !== void 0 &&
re.total !== void 0 &&
((this.plugin._embedProgress.current =
re.current),
(this.plugin._embedProgress.total =
re.total || 1),
(this.plugin._embedProgress.key =
re.paper_id || "")));
}
} catch (ee) {}
},
}));
}, 2e3)),
this.display());
},
z = Te(t),
q = !1;
z &&
typeof z.summary == "object" &&
z.summary !== null &&
"status" in z.summary &&
(q = z.summary.status === "version_mismatch");
let D;
switch (
(T
? q
? (D = "runtime-mismatch")
: P === "stopping"
? (D = "stopping")
: v && P === "running"
? (D = "building")
: P === "failed"
? (D = "failed")
: P === "stopped"
? (D = "stopped")
: w
? (D = "stale")
: g
? (D = "corrupted")
: k
? (D = "ready")
: (D = "idle")
: (D = "deps-missing"),
D)
) {
case "building": {
let S = s.createEl("div", { cls: "paperforge-progress-track" });
S.style.cssText = "flex:1;";
let M = m > 0 ? ((p / m) * 100).toFixed(1) : "0",
C = S.createEl("div", { cls: "paperforge-progress-seg done" });
if (
((C.style.cssText = `width:${M}%; min-width:${p > 0 ? "2px" : "0"};`),
p < m)
) {
let A = S.createEl("div", {
cls: "paperforge-progress-seg pending",
});
A.style.cssText = `width:${(100 - parseFloat(M)).toFixed(1)}%;`;
}
(i.createEl("span", {
cls: "paperforge-embed-progress-text",
text: `${p}/${m} papers`,
}),
y &&
i.createEl("span", {
cls: "paperforge-embed-progress-key",
text: ` (${y})`,
}));
let F = s.createEl("button");
(F.setText(o("retrieval_stop")),
(F.className = "mod-warning"),
F.addEventListener("click", () => {
(this._callPython(["embed", "stop", "--json"], { timeout: 8e3 }),
this.display());
}));
break;
}
case "stopping": {
let S = s.createEl("div", { cls: "paperforge-progress-track" });
S.style.cssText = "flex:1; opacity:0.5;";
let M = m > 0 ? ((p / m) * 100).toFixed(1) : "0",
C = S.createEl("div", { cls: "paperforge-progress-seg done" });
if (
((C.style.cssText = `width:${M}%; min-width:${p > 0 ? "2px" : "0"};`),
p < m)
) {
let A = S.createEl("div", {
cls: "paperforge-progress-seg pending",
});
A.style.cssText = `width:${(100 - parseFloat(M)).toFixed(1)}%;`;
}
i.createEl("span", { text: o("retrieval_build_stopping") });
let F = s.createEl("button");
(F.setText(o("retrieval_stop")),
(F.className = "mod-warning"),
F.setAttr("disabled", ""));
break;
}
case "failed": {
i.createEl("div", {
cls: "paperforge-desc-box",
text: o("retrieval_build_failed") + (L ? ": " + L : ""),
attr: { style: "color:var(--text-error);" },
});
let S = s.createEl("button");
(S.setText(o("retrieval_retry")),
(S.className = "mod-cta"),
S.addEventListener("click", () => O("--resume")));
let M = s.createEl("button");
(M.setText(o("retrieval_force_rebuild")),
(M.style.marginLeft = "6px"),
M.addEventListener("click", () => O("--force")));
break;
}
case "stopped": {
i.setText(o("retrieval_build_stopped"));
let S = s.createEl("button");
(S.setText(o("retrieval_retry")),
(S.className = "mod-cta"),
S.addEventListener("click", () => O("--resume")));
break;
}
case "corrupted": {
i.createEl("div", {
cls: "paperforge-desc-box",
text: o("feat_vector_corrupted"),
attr: { style: "background:var(--background-modifier-warning);" },
});
let S = s.createEl("button");
(S.setText(o("retrieval_force_rebuild")),
(S.className = "mod-cta"),
S.addEventListener("click", () => O("--force")));
break;
}
case "stale": {
i.createEl("div", {
cls: "paperforge-desc-box",
text: o("retrieval_build_stale"),
attr: { style: "color:var(--text-warning);" },
});
let S = s.createEl("button");
(S.setText(o("retrieval_rebuild_vectors")),
(S.className = "mod-cta"),
S.addEventListener("click", () => O("--resume")));
break;
}
case "ready": {
s.createEl("span", {
text: E + " chunks embedded",
cls: "setting-item-description",
});
let S = s.createEl("button");
(S.setText(o("retrieval_rebuild_vectors")),
(S.className = "mod-cta"),
S.addEventListener("click", () => O("--resume")));
let M = s.createEl("button");
(M.setText(o("retrieval_force_rebuild")),
(M.style.marginLeft = "6px"),
M.addEventListener("click", () => O("--force")));
break;
}
case "deps-missing": {
i.setText(o("retrieval_build_deps_missing"));
let S = s.createEl("a");
(S.setText(o("feat_install_deps")),
(S.style.cssText = "cursor:pointer; text-decoration:underline;"),
S.addEventListener("click", () => {
this.display();
}));
break;
}
case "runtime-mismatch": {
i.createEl("div", {
cls: "paperforge-desc-box",
text: o("retrieval_build_runtime_mismatch"),
attr: { style: "color:var(--text-warning);" },
});
let S = s.createEl("a");
(S.setText(o("runtime_health_sync")),
(S.style.cssText = "cursor:pointer; text-decoration:underline;"),
S.addEventListener("click", () => {
this.display();
}));
break;
}
case "idle":
default: {
i.setText(o("retrieval_build_idle"));
let S = s.createEl("button");
(S.setText(o("feat_build_btn")),
(S.className = "mod-cta"),
S.addEventListener("click", () => O("--resume")));
break;
}
}
})();
}
_getCurrentModelKey() {
return this.plugin.settings.vector_db_api_model || "text-embedding-3-small";
}
_parseEmbedStatus(e) {
let t = {};
return (
e &&
(e
.split(
`
`
)
.forEach((r) => {
let n = r.match(/^\s*([^:]+):\s*(.*)/);
n && (t[n[1].trim()] = n[2].trim());
}),
t.db_exists !== void 0 && (t.db_exists = t.db_exists === "True"),
t.chunk_count !== void 0 &&
(t.chunk_count = parseInt(t.chunk_count, 10) || 0)),
t
);
}
_getPythonDesc(e, t) {
return t === "stale"
? `[!!] ${e} (stale \u2014 path no longer exists, update or clear the override below)`
: t === "manual"
? `${e} (manual)`
: `${e} (auto-detected)`;
}
_refreshPythonInterpDesc(e, t) {
let r = this._pythonInterpDescEl;
r &&
(t === "stale"
? (r.textContent = `[!!] ${e} (stale \u2014 path no longer exists, update or clear the override below)`)
: t === "manual"
? (r.textContent = `${e} (manual)`)
: (r.textContent = `${e} (auto-detected)`));
}
_validatePythonOverride() {
let e = this.plugin.settings.python_path
? this.plugin.settings.python_path.trim()
: "",
t = this._customPathDescEl;
if (!e) {
let r = "\u8BF7\u8F93\u5165\u8DEF\u5F84 / Enter a path first";
(t &&
(t.innerHTML = `<span style="color:var(--text-error)">\u2717 ${r}</span>`),
new R.Notice(r));
return;
}
if (!$.existsSync(e)) {
let r = "\u8DEF\u5F84\u4E0D\u5B58\u5728 / Path does not exist";
(t &&
(t.innerHTML = `<span style="color:var(--text-error)">\u2717 ${r}</span>`),
new R.Notice(r, 4e3));
return;
}
try {
$.accessSync(e, $.constants.X_OK);
} catch (r) {
let n = "\u4E0D\u53EF\u6267\u884C / Not executable";
(t &&
(t.innerHTML = `<span style="color:var(--text-error)">\u2717 ${n}</span>`),
new R.Notice(n, 4e3));
return;
}
(0, K.execFile)(e, ["--version"], { timeout: 8e3 }, (r, n) => {
if (r || !n) {
let l = "\u65E0\u6CD5\u8FD0\u884C / Cannot run";
(t &&
(t.innerHTML = `<span style="color:var(--text-error)">\u2717 ${l}</span>`),
new R.Notice(l, 4e3));
return;
}
let a = n.match(/Python (\d+)\.(\d+)/);
if (!a) {
let l = "\u65E0\u6CD5\u89E3\u6790\u7248\u672C / Cannot parse version";
(t &&
(t.innerHTML = `<span style="color:var(--text-error)">\u2717 ${l}</span>`),
new R.Notice(l, 4e3));
return;
}
let s = parseInt(a[1], 10),
i = parseInt(a[2], 10);
if (s < 3 || (s === 3 && i < 10)) {
let l =
"Python \u7248\u672C\u8FC7\u4F4E\uFF0C\u9700\u8981 3.10+ / Python version too low, need 3.10+";
(t &&
(t.innerHTML = `<span style="color:var(--text-error)">\u2717 ${l}</span>`),
new R.Notice(l, 4e3));
return;
}
(0, K.execFile)(e, ["-m", "pip", "--version"], { timeout: 8e3 }, (l) => {
if (l) {
let c = `\u2713 Python ${s}.${i} \u6709\u6548\uFF0C\u4F46\u672A\u68C0\u6D4B\u5230 pip / Valid, but pip not found`;
(t &&
(t.innerHTML = `<span style="color:var(--text-warning)">\u26A0 ${c}</span>`),
new R.Notice(c, 4e3));
} else {
let c = `\u2713 Python ${s}.${i} \u6709\u6548 / Valid`;
(t &&
(t.innerHTML = `<span style="color:var(--text-accent)">${c}</span>`),
new R.Notice(c, 4e3));
}
});
});
}
_syncRuntime(e) {
let t = this.app.vault.adapter.basePath,
{ path: r, extraArgs: n = [] } = N(
t,
this.plugin.settings,
void 0,
void 0
),
a = this.plugin.manifest.version,
s = ut(r, a, n);
(e.setDisabled(!0), e.setButtonText(o("runtime_health_syncing")));
let i = (c, d) => (
console.log(`[PaperForge] Sync Runtime: trying ${d}`),
ht(s.cmd, c, t, s.timeout, void 0, be())
),
l = () => {
let c = "opencode";
try {
let m = $.readFileSync(X.join(t, "paperforge.json"), "utf-8"),
y = JSON.parse(m);
y.agent_key && (c = y.agent_key);
} catch (m) {}
let d = [
...n,
"-c",
'from paperforge.services.skill_deploy import deploy_skills; from pathlib import Path; r=deploy_skills(vault=Path(r"' +
t.replace(/\\/g, "\\\\") +
'"), agent_key="' +
c +
'", overwrite=True); print("skills deployed" if r["skill_deployed"] else "skills skipped", flush=True)',
],
f = (0, K.spawn)(r, d, { cwd: t, timeout: 3e4, windowsHide: !0 }),
p = "";
(f.stdout.on("data", (m) => {
p += m.toString("utf-8");
}),
f.on("close", (m) => {
console.log(`[PaperForge] Skill deploy: ${p.trim()} (exit ${m})`);
}));
};
i(s.pypiArgs, "PyPI").then((c) => {
if (c.exitCode === 0) {
(console.log("[PaperForge] Sync Runtime: installed via PyPI"),
l(),
new R.Notice(o("runtime_health_sync_done").replace("{0}", a), 5e3),
this.display());
return;
}
(console.warn(
"[PaperForge] Sync Runtime: PyPI failed, falling back to git..."
),
i(s.gitArgs, "git").then((d) => {
d.exitCode === 0
? (console.log("[PaperForge] Sync Runtime: installed via git"),
l(),
new R.Notice(
o("runtime_health_sync_done").replace("{0}", a),
5e3
),
this.display())
: (e.setDisabled(!1),
e.setButtonText(o("runtime_health_sync")),
console.error("[PaperForge] git fallback stderr:", d.stderr),
new R.Notice(
o("runtime_health_sync_fail").replace(
"{0}",
"pip exit code " + d.exitCode
),
8e3
));
}));
});
}
_debouncedSave() {
(clearTimeout(this._saveTimeout),
(this._saveTimeout = setTimeout(() => this.plugin.saveSettings(), 500)));
}
_preCheck(e) {
var a;
let t = this.app.vault.adapter.basePath,
{ path: r, extraArgs: n = [] } = N(
t,
(a = this.plugin) == null ? void 0 : a.settings,
void 0,
void 0
);
(0, K.execFile)(r, [...n, "--version"], { timeout: 8e3 }, (s, i) => {
let l = [];
l.push({
label: "Python",
ok: !s,
detail: s ? o("check_python_fail") : i.trim(),
});
let c = !1,
d = process.env.HOME || process.env.USERPROFILE || St.homedir() || "";
if (process.platform === "darwin")
c = [
"/Applications/Zotero.app",
X.join(d, "Applications", "Zotero.app"),
].some((b) => {
try {
return $.existsSync(b);
} catch (E) {
return !1;
}
});
else if (process.platform === "win32") {
let _ = process.env.ProgramFiles || "",
b = process.env.LOCALAPPDATA || "";
c = [
X.join(_, "Zotero"),
X.join(_, "(x86)", "Zotero"),
X.join(b, "Programs", "Zotero"),
X.join(b, "Zotero"),
X.join(d, "AppData", "Local", "Programs", "Zotero"),
]
.filter(Boolean)
.some((k) => {
try {
return $.existsSync(k);
} catch (g) {
return !1;
}
});
} else
c = [
X.join(d, ".local", "share", "zotero", "zotero"),
"/usr/bin/zotero",
"/usr/local/bin/zotero",
].some((b) => {
try {
return $.existsSync(b);
} catch (E) {
return !1;
}
});
let f = this.plugin.settings.zotero_data_dir;
if (!c && f)
try {
c = $.existsSync(f);
} catch (_) {}
l.push({
label: "Zotero",
ok: c,
detail: c ? o("check_zotero_ok") : o("check_zotero_fail"),
});
let p = !1,
m = process.env.APPDATA || "";
(process.platform === "win32" &&
m &&
(p = Me(X.join(m, "Zotero", "Zotero", "Profiles"))),
!p &&
process.platform === "darwin" &&
d &&
(p = Me(
X.join(d, "Library", "Application Support", "Zotero", "Profiles")
)),
!p &&
process.platform !== "win32" &&
process.platform !== "darwin" &&
d &&
(p = Me(X.join(d, ".zotero", "zotero", "Profiles"))),
!p && f && String(f).trim() && (p = Qe(f.trim())),
!p && d && (p = Qe(X.join(d, "Zotero"))),
l.push({
label: "Better BibTeX",
ok: p,
detail: p ? o("check_bbt_ok") : o("check_bbt_fail"),
}));
let y = { true: "\u2713", false: "\u2717" };
if (this._checkEl) {
this._checkEl.setText(
l.map((b) => `${y[String(b.ok)]} ${b.label}: ${b.detail}`).join(`
`)
);
let _ = l.some((b) => !b.ok);
this._checkEl.className = `paperforge-message msg-${_ ? "error" : "ok"}`;
}
let x = l.filter((_) => !_.ok);
(x.length > 0 &&
new R.Notice(
`[!!] \u672A\u901A\u8FC7: ${x.map((_) => _.label).join(", ")}`,
6e3
),
e());
});
}
_renderMaintenanceTab(e) {
e.createEl("h2", { text: o("tab_maintenance") || "\u7EF4\u62A4" });
let t = this.app.vault.adapter.basePath,
r = e.createEl("div"),
n = (f, p) =>
p === "retry_ocr" || p === "upgrade_legacy"
? { cmd: ["-m", "paperforge", "ocr", "redo", ...f], timeout: 3e5 }
: p === "rebuild_result"
? {
cmd: ["-m", "paperforge", "ocr", "rebuild", ...f],
timeout: 12e4,
}
: null,
a = null;
try {
a = kt(t);
} catch (f) {}
let s = N(t, this.plugin.settings, $, K.execFileSync);
if (!s.path) {
r.createEl("p", {
text: "\u26A0 Python \u672A\u914D\u7F6E\uFF0C\u8BF7\u5148\u5728\u300C\u5B89\u88C5\u300D\u6807\u7B7E\u9875\u914D\u7F6E\u3002",
cls: "setting-item-description",
});
return;
}
let i = (f) => {
r.empty();
let p = f.filter((_) => _.visible_in_maintenance);
if (p.length === 0) {
r.createEl("p", {
text: o("maintenance_all_good") || "\u2705 \u5168\u90E8\u6B63\u5E38",
});
return;
}
let m = s.path,
y = s.extraArgs || [],
x = [
{
key: "retry",
title: o("maintenance_group_retry") || "\u9700\u8981\u91CD\u8BD5",
items: [],
},
{
key: "rebuild",
title:
o("maintenance_group_rebuild") ||
"\u53EF\u91CD\u5EFA\u7ED3\u679C",
items: [],
},
{
key: "legacy_optional",
title:
o("maintenance_group_legacy") ||
"\u53EF\u5347\u7EA7\u65E7\u7ED3\u679C\uFF08\u53EF\u9009\uFF09",
items: [],
},
];
for (let _ of p) {
let b = x.find((E) => E.key === _.display_group);
b && b.items.push(_);
}
for (let _ of x) {
if (_.items.length === 0) continue;
let b = _.key === "legacy_optional",
E = b ? r.createEl("details") : r.createEl("div");
b
? E.createEl("summary").createEl("strong", {
text: _.title + " (" + _.items.length + ")",
})
: E.createEl("h3", { text: _.title + " (" + _.items.length + ")" });
let k = new Map();
for (let C of _.items) k.set(C.key, !1);
let g = E.createEl("div", { cls: "pf-maint-toolbar" }),
v = g.createEl("button", { text: "\u5168\u9009" }),
w = g.createEl("button", { text: "\u53D6\u6D88\u5168\u9009" }),
T = g.createEl("button", {
text: "\u25B6 \u6267\u884C\u5DF2\u9009",
cls: "mod-cta",
}),
P = g.createEl("span", { cls: "pf-maint-exec-label" }),
L = () => {
let C = _.items.filter((F) => k.get(F.key)).length;
P.setText("\u5DF2\u9009 " + C + " \u7BC7");
};
(L(),
v.addEventListener("click", () => {
for (let F of _.items) k.set(F.key, !0);
(L(),
E.querySelectorAll("input[type=checkbox].pf-maint-sel").forEach(
(F) => {
F.checked = !0;
}
));
}),
w.addEventListener("click", () => {
for (let F of _.items) k.set(F.key, !1);
(L(),
E.querySelectorAll("input[type=checkbox].pf-maint-sel").forEach(
(F) => {
F.checked = !1;
}
));
}),
T.addEventListener("click", () => {
let C = _.items.filter((F) => k.get(F.key));
if (C.length === 0) {
new R.Notice(
"\u8BF7\u5148\u9009\u62E9\u8981\u5904\u7406\u7684\u8BBA\u6587\u3002"
);
return;
}
for (let F of C) {
let A = n([F.key], F.display_action);
A &&
(0, K.execFile)(
m,
[...y, ...A.cmd],
{ cwd: t, timeout: A.timeout, windowsHide: !0 },
() => {
new R.Notice(F.display_label + " \u2014 " + F.key);
}
);
}
}));
let z = E.createEl("div", { cls: "pf-maint-table-wrap" }).createEl(
"table",
{ cls: "pf-maint-table" }
),
q = z.createEl("thead"),
D = z.createEl("tbody"),
S = q.insertRow();
[
"",
"Key",
"Title",
"\u5EFA\u8BAE\u64CD\u4F5C",
"\u539F\u56E0",
"\u64CD\u4F5C",
].forEach((C) => {
let F = document.createElement("th");
((F.textContent = C), S.appendChild(F));
});
let M = (C) =>
C === "retry_ocr"
? o("maintenance_btn_retry") || "\u91CD\u8BD5"
: C === "rebuild_result"
? o("maintenance_btn_rebuild") || "\u91CD\u5EFA"
: C === "upgrade_legacy"
? o("maintenance_btn_upgrade") || "\u5347\u7EA7"
: "";
for (let C of _.items) {
let F = D.insertRow(),
A = F.insertCell();
A.style.cssText = "padding:3px 4px;text-align:center;";
let J = document.createElement("input");
((J.type = "checkbox"),
(J.className = "pf-maint-sel"),
(J.checked = k.get(C.key) || !1),
J.addEventListener("change", () => {
(k.set(C.key, J.checked), L());
}),
A.appendChild(J));
let G = F.insertCell();
((G.style.cssText =
"padding:3px 4px;white-space:nowrap;font-size:11px;max-width:90px;overflow:hidden;text-overflow:ellipsis;"),
(G.textContent = C.key));
let ee = F.insertCell();
((ee.style.cssText =
"padding:3px 4px;white-space:nowrap;max-width:220px;overflow:hidden;text-overflow:ellipsis;"),
(ee.textContent = C.title || C.key));
let Q = F.insertCell();
((Q.style.cssText = "padding:3px 4px;white-space:nowrap;"),
(Q.textContent = C.display_label));
let re = F.insertCell();
((re.style.cssText =
"padding:3px 4px;white-space:nowrap;max-width:160px;overflow:hidden;text-overflow:ellipsis;font-size:11px;color:var(--text-muted);"),
(re.textContent = C.display_reason || ""));
let Pe = F.insertCell();
Pe.style.cssText =
"padding:3px 4px;text-align:center;white-space:nowrap;";
let ye = document.createElement("button");
((ye.textContent = M(C.display_action)),
ye.textContent &&
(ye.addEventListener("click", () => {
let B = n([C.key], C.display_action);
B &&
(0, K.execFile)(
m,
[...y, ...B.cmd],
{ cwd: t, timeout: B.timeout, windowsHide: !0 },
() => {
new R.Notice(C.display_label + " \u2014 " + C.key);
}
);
}),
Pe.appendChild(ye)));
}
}
};
if (a) {
let f = Object.values(a.papers);
i(f);
} else
r.createEl("p", {
text: "\u6B63\u5728\u52A0\u8F7D OCR \u7EF4\u62A4\u6570\u636E\u2026",
});
(wt(t, s.path, s.extraArgs || [], a || null)
.then((f) => {
f.changed
? (i(f.data),
Ve(t, {
manifest: {},
papers: Object.fromEntries(f.data.map((p) => [p.key, p])),
cached_at: new Date().toISOString(),
}))
: a ||
(i(f.data),
Ve(t, {
manifest: {},
papers: Object.fromEntries(f.data.map((p) => [p.key, p])),
cached_at: new Date().toISOString(),
}));
})
.catch(() => {
a ||
(r.empty(),
r.createEl("p", {
text: "\u65E0\u6CD5\u52A0\u8F7D OCR \u6570\u636E\u3002\u8BF7\u786E\u4FDD\u5DF2\u5B89\u88C5 paperforge \u5E76\u8FD0\u884C\u8FC7 OCR\u3002",
cls: "setting-item-description",
}));
}),
e.createEl("hr"),
e.createEl("h3", { text: "\u5168\u5C40\u64CD\u4F5C" }));
let l = e.createEl("div", { cls: "pf-maint-global" });
(l
.createEl("button", { text: "\u91CD\u5EFA\u641C\u7D22\u7D22\u5F15" })
.addEventListener("click", () => {
(new R.Notice("\u6B63\u5728\u91CD\u5EFA\u641C\u7D22\u7D22\u5F15\u2026"),
(0, K.execFile)(
s.path,
[
...(s.extraArgs || []),
"-m",
"paperforge",
"embed",
"build",
"--force",
],
{ cwd: t, timeout: 3e5, windowsHide: !0 },
() => {
new R.Notice(
"\u641C\u7D22\u7D22\u5F15\u91CD\u5EFA\u5B8C\u6210\u3002"
);
}
));
}),
l
.createEl("button", { text: "\u91CD\u5EFA\u8BB0\u5FC6\u5E93" })
.addEventListener("click", () => {
(new R.Notice("\u6B63\u5728\u91CD\u5EFA\u8BB0\u5FC6\u5E93\u2026"),
(0, K.execFile)(
s.path,
[...(s.extraArgs || []), "-m", "paperforge", "repair", "--fix"],
{ cwd: t, timeout: 12e4, windowsHide: !0 },
() => {
new R.Notice(
"\u8BB0\u5FC6\u5E93\u91CD\u5EFA\u5B8C\u6210\u3002"
);
}
));
}));
}
_renderReleaseNotesTab(e) {
(e.createEl("h2", { text: "\u66F4\u65B0\u4E0E\u624B\u518C" }),
e.createEl("h3", { text: "\u7248\u672C\u66F4\u65B0\u8BB0\u5F55" }));
let t = Pt.default.versions || [];
for (let a of t) {
let s = e.createEl("div", { cls: "paperforge-release-card" }),
i = s.createEl("div", { cls: "paperforge-release-header" });
if (
(i.createEl("strong", { text: `v${a.version} \u2014 ${a.title}` }),
i.createEl("span", {
cls: "paperforge-release-date",
text: ` (${a.date})`,
}),
a.breaking_or_migration && a.breaking_or_migration.length > 0)
) {
let l = s.createEl("div", { cls: "paperforge-release-section" });
l.createEl("div", {
cls: "paperforge-release-label",
text: "\u884C\u4E3A\u53D8\u66F4 / \u8FC1\u79FB\u6CE8\u610F",
});
for (let c of a.breaking_or_migration)
l.createEl("div", {
cls: "paperforge-release-item",
text: `\u2022 ${c}`,
});
}
if (a.new_features && a.new_features.length > 0) {
let l = s.createEl("div", { cls: "paperforge-release-section" });
l.createEl("div", {
cls: "paperforge-release-label",
text: "\u65B0\u529F\u80FD",
});
for (let c of a.new_features)
l.createEl("div", {
cls: "paperforge-release-item",
text: `\u2022 ${c}`,
});
}
if (a.fixes && a.fixes.length > 0) {
let l = s.createEl("div", { cls: "paperforge-release-section" });
l.createEl("div", {
cls: "paperforge-release-label",
text: "\u4FEE\u590D",
});
for (let c of a.fixes)
l.createEl("div", {
cls: "paperforge-release-item",
text: `\u2022 ${c}`,
});
}
if (a.recommended_actions && a.recommended_actions.length > 0) {
let l = s.createEl("div", {
cls: "paperforge-release-section paperforge-release-recommended",
});
l.createEl("div", {
cls: "paperforge-release-label",
text: "\u5EFA\u8BAE\u64CD\u4F5C",
});
for (let c of a.recommended_actions)
l.createEl("div", {
cls: "paperforge-release-item paperforge-release-item-bold",
text: `\u2022 ${c}`,
});
}
}
(e.createEl("h3", { text: "\u4F7F\u7528\u624B\u518C" }),
e
.createEl("div", { cls: "paperforge-manual-links" })
.createEl("a", {
text: "\u2192 \u67E5\u770B\u5B8C\u6574\u4F7F\u7528\u624B\u518C\uFF08GitHub\uFF09",
href: "https://github.com/LLLin000/PaperForge/blob/master/docs/user-manual.md",
})
.setAttr("target", "_blank"));
}
};
var I = require("obsidian"),
he = V(require("fs")),
Le = V(require("path")),
_e = require("child_process");
var Ae = V(require("path"));
function Ct(u) {
if (!u) return null;
let h = Ae.dirname(u);
for (;;) {
let e = Ae.basename(h);
if (!e || e === ".") break;
let t = e.match(/^([A-Z0-9]{8})(?:\s*-\s*.*)?$/i);
if (t) return t[1];
let r = Ae.dirname(h);
if (r === h) break;
h = r;
}
return null;
}
var Z = V(require("fs")),
me = V(require("path"));
function Oe(u) {
return ne(u).ocrDir;
}
function Ht(u, h) {
let e = me.join(Oe(u), h, "versions", "manifest.json");
try {
if (!Z.existsSync(e)) return null;
let t = Z.readFileSync(e, "utf-8"),
r = JSON.parse(t);
if (r && typeof r == "object" && "versions" in r && "current" in r) {
let n = r,
a = n.versions,
s = n.current;
if (Array.isArray(a) && s && typeof s == "object" && "label" in s)
return r;
}
return null;
} catch (t) {
return null;
}
}
function Kt(u) {
let h = Oe(u);
try {
return Z.existsSync(h)
? Z.readdirSync(h, { withFileTypes: !0 })
.filter((e) => e.isDirectory())
.map((e) => e.name)
: [];
} catch (e) {
return [];
}
}
function nt(u) {
let h = Kt(u),
e = [];
for (let t of h) {
let r = Ht(u, t);
if (!r) continue;
let n = r.versions.map((s) => s.label),
a = 0;
for (let s of n) {
let i = me.join(Oe(u), t, "versions", s, "fulltext.md");
try {
Z.existsSync(i) && (a += Z.statSync(i).size);
} catch (l) {}
}
e.push({
key: t,
title: t.replace(/_/g, " "),
versions: r.versions,
currentLabel: r.current.label,
totalSize: a,
});
}
return (e.sort((t, r) => t.title.localeCompare(r.title)), e);
}
function Rt(u, h, e) {
let t = Oe(u),
r = me.join(t, h, "versions", e, "fulltext.md"),
n = me.join(t, h, "render"),
a = me.join(n, "fulltext.md");
try {
return Z.existsSync(r)
? (Z.existsSync(n) || Z.mkdirSync(n, { recursive: !0 }),
Z.copyFileSync(r, a),
!0)
: !1;
} catch (s) {
return !1;
}
}
function Tt(u, h, e, t) {
var p;
let r = Oe(u),
n = me.join(r, h, "versions", e, "fulltext.md"),
a = me.join(r, h, "versions", t, "fulltext.md"),
s = "",
i = "";
try {
Z.existsSync(n) && (s = Z.readFileSync(n, "utf-8"));
} catch (m) {}
try {
Z.existsSync(a) && (i = Z.readFileSync(a, "utf-8"));
} catch (m) {}
let l = Ft(s),
c = Ft(i),
d = Math.max(l.length, c.length),
f = [];
for (let m = 0; m < d; m++) {
let y = m < l.length ? l[m] : "",
x = m < c.length ? c[m] : "",
_ =
(p = (y || x).split(`
`)[0]) != null
? p
: "",
b = _.startsWith("## ") ? _.replace(/^##\s+/, "") : "",
E = "unchanged";
(!y && x
? (E = "added")
: y && !x
? (E = "removed")
: y !== x && (E = "changed"),
E !== "unchanged" &&
f.push({
paragraphIndex: m,
heading: b,
type: E,
oldText: y || void 0,
newText: x || void 0,
}));
}
return f;
}
function Ft(u) {
let h = u.split(`
`),
e = [],
t = [];
for (let r of h)
if (r.startsWith("## ") && t.length > 0)
(e.push(
t
.join(
`
`
)
.trim()
),
(t = [r]));
else if (r.trim() === "" && t.length > 0) {
let n = t
.join(
`
`
)
.trim();
n && (e.push(n), (t = []));
} else t.push(r);
if (t.length > 0) {
let r = t
.join(
`
`
)
.trim();
r && e.push(r);
}
return e;
}
var we = class extends I.ItemView {
constructor(e) {
super(e);
this._currentMode = null;
this._currentDomain = null;
this._currentPaperKey = null;
this._currentPaperEntry = null;
this._currentFilePath = null;
this._cachedItems = null;
this._modeSubscribers = [];
this._leafChangeTimer = null;
this._ocrPrivacyShown = !1;
this._cachedStats = null;
this._techDetailsExpanded = !1;
this._paperforgeVersion = "";
this._dashboardPermissions = {};
this._headerTitle = null;
this._versionBadge = null;
this._messageEl = null;
this._metricsEl = null;
this._ocrSection = null;
this._ocrEmpty = null;
this._ocrBadge = null;
this._ocrTrack = null;
this._ocrCounts = null;
this._driftBannerEl = null;
this._versionPapers = null;
this._versionFilter = "";
this._searchContainer = null;
this._searchInput = null;
this._searchResultsEl = null;
this._searchTimer = void 0;
this._searchState = "idle";
this._searchMode = "M";
this._searchResults = null;
this._searchActiveIndex = -1;
this._onKeyDown = null;
((this._currentMode = null),
(this._currentDomain = null),
(this._currentPaperKey = null),
(this._currentPaperEntry = null),
(this._currentFilePath = null),
(this._cachedItems = null),
(this._modeSubscribers = []),
(this._leafChangeTimer = null),
(this._ocrPrivacyShown = !1));
}
getViewType() {
return ve;
}
getDisplayText() {
return "PaperForge";
}
getIcon() {
return Fe;
}
async onOpen() {
(this._buildPanel(),
(this._modeSubscribers = []),
(this._leafChangeTimer = null),
this._setupEventSubscriptions(),
this._fetchVersion(),
this._detectAndSwitch(),
(this._onKeyDown = (e) => {
var t, r, n;
if (e.key === "/" && !e.ctrlKey && !e.metaKey && !e.altKey) {
let a =
(r = (t = e.target) == null ? void 0 : t.tagName) == null
? void 0
: r.toLowerCase();
a !== "input" &&
a !== "textarea" &&
(e.preventDefault(), (n = this._searchInput) == null || n.focus());
}
}),
document.addEventListener("keydown", this._onKeyDown));
}
async onClose() {
if (this._modeSubscribers && this._modeSubscribers.length > 0) {
for (let e of this._modeSubscribers)
e.event === "active-leaf-change"
? this.app.workspace.off("active-leaf-change", e.ref)
: e.event === "modify" && this.app.vault.off("modify", e.ref);
this._modeSubscribers = [];
}
(this._leafChangeTimer &&
(clearTimeout(this._leafChangeTimer), (this._leafChangeTimer = null)),
this._onKeyDown &&
(document.removeEventListener("keydown", this._onKeyDown),
(this._onKeyDown = null)),
(this._searchState = "idle"),
(this._searchResults = null),
(this._searchActiveIndex = -1),
(this._searchTimer = void 0),
(this._cachedItems = null),
(this._cachedStats = null));
}
_buildPanel() {
let e = this.containerEl;
(e.empty(), e.addClass("paperforge-status-panel"));
let t = e.createEl("div", { cls: "paperforge-header" }),
r = t.createEl("div", { cls: "paperforge-header-left" });
(r.createEl("div", { cls: "paperforge-header-logo", text: "P" }),
(this._modeContextEl = r.createEl("div", {
cls: "paperforge-mode-context",
})),
(this._headerTitle = r.createEl("h3", {
cls: "paperforge-header-title",
text: "PaperForge",
})),
(this._versionBadge = r.createEl("span", {
cls: "paperforge-header-badge",
text: "v\u2014",
})));
let n = t.createEl("button", {
cls: "paperforge-header-refresh",
attr: { "aria-label": "Refresh" },
});
((n.innerHTML = "\u21BB"),
n.addEventListener("click", () => {
(this._invalidateIndex(), this._detectAndSwitch());
}),
(this._messageEl = e.createEl("div", {
cls: "paperforge-message",
attr: { "aria-live": "polite" },
})),
(this._contentEl = e.createEl("div", {
cls: "paperforge-content-area",
})));
}
_fetchVersion() {
var s, i;
let e = this.app.vault.adapter.basePath,
t = this.app.plugins.plugins.paperforge,
r =
((s = t == null ? void 0 : t.manifest) == null ? void 0 : s.version) ||
"?",
{ path: n, extraArgs: a = [] } = N(
e,
(i = t == null ? void 0 : t.settings) != null ? i : null,
void 0,
void 0
);
dt(n, r, e, 1e4, void 0).then((l) => {
if (l.status === "not-installed") return;
let c = l.pyVersion || "";
((this._paperforgeVersion = c.startsWith("v") ? c : "v" + c),
this._versionBadge &&
this._versionBadge.setText(this._paperforgeVersion),
this._driftBannerEl &&
r &&
this._paperforgeVersion !== "v" + r.replace(/^v/, "")
? ((this._driftBannerEl.style.display = "block"),
this._driftBannerEl.setText(
o("dashboard_drift_warning")
.replace("{0}", this._paperforgeVersion)
.replace("{1}", "v" + r.replace(/^v/, ""))
))
: this._driftBannerEl &&
(this._driftBannerEl.style.display = "none"));
});
}
_fetchStats(e) {
var s;
if (!this._metricsEl) return;
if (!e && !this._cachedStats)
(this._metricsEl.empty(),
this._metricsEl.createEl("div", {
cls: "paperforge-status-loading",
text: "Loading...",
}));
else if (e && !this._cachedStats) return;
let t = this.app.vault.adapter.basePath,
r = this.app.plugins.plugins.paperforge,
{ path: n, extraArgs: a = [] } = N(
t,
(s = r == null ? void 0 : r.settings) != null ? s : null,
void 0,
void 0
);
(0, _e.execFile)(
n,
[...a, "-m", "paperforge", "dashboard", "--json"],
{ cwd: t, timeout: 3e4 },
(i, l) => {
if (!i)
try {
let c = JSON.parse(l);
if (c.ok && c.data) {
let d = this._normalizeDashboardData(c.data);
((this._cachedStats = d),
this._metricsEl.empty(),
this._renderStats(d),
this._renderOcr(d),
(this._dashboardPermissions = c.data.permissions || {}));
return;
}
} catch (c) {}
this._fallbackFetchStats(e, t, r);
}
);
}
_normalizeDashboardData(e) {
let t = e.stats || {},
r = t.ocr_health || {},
n = t.pdf_health || {},
a = e.ocr_version_state || {},
s = (r.done || 0) + (r.pending || 0) + (r.failed || 0);
return {
total_papers: t.papers || 0,
formal_notes: t.papers || 0,
exports: 0,
bases: 0,
ocr: {
total: s,
pending: r.pending || 0,
processing: 0,
done: r.done || 0,
failed: r.failed || 0,
},
path_errors: (n.broken || 0) + (n.missing || 0),
ocr_version_state: {
total_papers: a.total_papers || 0,
derived_stale_count: a.derived_stale_count || 0,
raw_upgradable_count: a.raw_upgradable_count || 0,
},
};
}
_fallbackFetchStats(e, t, r) {
var s, i, l;
let n =
((s = r == null ? void 0 : r.settings) == null
? void 0
: s.system_dir) || "System",
a = Le.join(t, n, "PaperForge", "indexes", "formal-library.json");
try {
let c = he.readFileSync(a, "utf-8"),
d = JSON.parse(c),
f = d.items || [],
p = {},
m = {
pdf_health: { healthy: 0, unhealthy: 0 },
ocr_health: { healthy: 0, unhealthy: 0 },
note_health: { healthy: 0, unhealthy: 0 },
asset_health: { healthy: 0, unhealthy: 0 },
},
y = 0,
x = 0,
_ = 0,
b = 0,
E = 0,
k = 0;
for (let g of f) {
g.note_path && k++;
let v = g.lifecycle || "pdf_ready";
p[v] = (p[v] || 0) + 1;
let w = g.health || {};
for (let P of [
"pdf_health",
"ocr_health",
"note_health",
"asset_health",
])
(w[P] || "healthy") === "healthy" ? m[P].healthy++ : m[P].unhealthy++;
let T = g.ocr_status || "";
(y++,
T === "done"
? x++
: T === "pending"
? _++
: T === "processing" || T === "queued" || T === "running"
? b++
: E++);
}
((this._cachedStats = {
version:
d.paperforge_version ||
((i = this._cachedStats) == null ? void 0 : i.version) ||
"\u2014",
total_papers: f.length,
formal_notes: k,
exports: 0,
bases: 0,
ocr: { total: y, pending: _, processing: b, done: x, failed: E },
path_errors: 0,
lifecycle_level_counts: p,
health_aggregate: m,
}),
this._metricsEl.empty(),
this._renderStats(this._cachedStats),
this._renderOcr(this._cachedStats));
} catch (c) {
!e &&
!this._cachedStats &&
this._metricsEl.createEl("div", {
cls: "paperforge-status-loading",
text: "No index \u2014 trying CLI...",
});
let { path: d, extraArgs: f = [] } = N(
t,
(l = r == null ? void 0 : r.settings) != null ? l : null,
void 0,
void 0
);
(0, _e.execFile)(
d,
[...f, "-m", "paperforge", "status", "--json"],
{ cwd: t, timeout: 3e4 },
(p, m) => {
if (p) {
if (this._cachedStats) return;
this._metricsEl.createEl("div", {
cls: "paperforge-status-error",
text: `Cannot reach PaperForge CLI.
Make sure paperforge is installed and in your PATH.`,
});
return;
}
try {
let y = JSON.parse(m);
((this._cachedStats = y),
this._metricsEl.empty(),
this._renderStats(y),
this._renderOcr(y));
} catch (y) {
this._cachedStats ||
this._metricsEl.createEl("div", {
cls: "paperforge-status-error",
text: "Invalid response from paperforge status.",
});
}
}
);
}
}
_renderSkeleton(e) {
e.addClass("paperforge-loading");
}
_renderEmptyState(e, t) {
e.createEl("div", { cls: "paperforge-empty-state", text: t || "No data" });
}
_buildMetricBar(e, t, r) {
if (r <= 0) return;
let n = Math.min(100, (t / r) * 100);
e.createEl("div", { cls: "paperforge-metric-progress" }).createEl("div", {
cls: "paperforge-metric-progress-fill",
attr: { style: `width:${n.toFixed(1)}%` },
});
}
_loadIndex() {
var a;
let e = this.app.vault.adapter.basePath,
t = this.app.plugins.plugins.paperforge,
r =
((a = t == null ? void 0 : t.settings) == null
? void 0
: a.system_dir) || "System",
n = Le.join(e, r, "PaperForge", "indexes", "formal-library.json");
try {
let s = he.readFileSync(n, "utf-8");
return JSON.parse(s);
} catch (s) {
return null;
}
}
_getCachedIndex() {
if (!this._cachedItems) {
let e = this._loadIndex();
this._cachedItems = e ? e.items || [] : [];
}
return this._cachedItems;
}
_findEntry(e) {
if (!e) return null;
let t = this._getCachedIndex().find((r) => r.zotero_key === e) || null;
return ot(this.app, t);
}
_patchCachedEntry(e, t) {
if (!e || !this._cachedItems) return;
let r = this._cachedItems.findIndex((n) => n.zotero_key === e);
r !== -1 && (this._cachedItems[r] = Ze(this._cachedItems[r], t));
}
_filterByDomain(e) {
return e ? this._getCachedIndex().filter((t) => t.domain === e) : [];
}
_renderStats(e) {
var s;
if (
(this._versionBadge &&
this._versionBadge.setText(
this._paperforgeVersion || (e.version ? "v" + e.version : "v\u2014")
),
!e || typeof e.total_papers == "undefined")
) {
this._metricsEl && this._renderSkeleton(this._metricsEl);
return;
}
if (!this._metricsEl) return;
this._metricsEl.removeClass("paperforge-loading");
let t = e.total_papers || 0,
r = e.formal_notes || 0,
n = [
{ value: t, label: "Papers", color: "var(--color-cyan)", barMax: 0 },
{
value: r,
label: "Formal Notes",
color: "var(--color-blue)",
barMax: t,
},
{
value: e.exports || 0,
label: "Exports",
color: "var(--color-purple)",
barMax: 0,
},
];
for (let i of n) {
let l = this._metricsEl.createEl("div", {
cls: "paperforge-metric-card",
});
(l.style.setProperty("--metric-color", i.color),
l.createEl("div", {
cls: "paperforge-metric-value",
text: ((s = i.value) == null ? void 0 : s.toString()) || "\u2014",
}),
l.createEl("div", { cls: "paperforge-metric-label", text: i.label }),
i.barMax > 0 && this._buildMetricBar(l, i.value, i.barMax));
}
let a = e.ocr_version_state || {};
if (
a.total_papers > 0 &&
(a.derived_stale_count > 0 || a.raw_upgradable_count > 0)
) {
let i = [];
(a.derived_stale_count > 0 && i.push(`${a.derived_stale_count} stale`),
a.raw_upgradable_count > 0 &&
i.push(`${a.raw_upgradable_count} upgradable`));
let l = this._metricsEl.createEl("div", {
cls: "paperforge-metric-card",
});
(l.style.setProperty("--metric-color", "var(--color-yellow)"),
l.createEl("div", {
cls: "paperforge-metric-value",
text: i.join(", "),
}),
l.createEl("div", {
cls: "paperforge-metric-label",
text: "OCR Version",
}));
}
}
_renderOcr(e) {
if (!this._ocrSection) return;
let t = e.ocr || {},
r = t.total || 0;
if (r === 0) {
this._ocrSection.style.display = "none";
return;
}
((this._ocrSection.style.display = "block"),
this._ocrEmpty && (this._ocrEmpty.style.display = "none"));
let n = t.done || 0,
a = t.pending || 0,
s = t.processing || 0,
i = t.failed || 0;
if (
(this._ocrBadge &&
(this._ocrBadge.removeClass("active", "idle"),
s > 0
? (this._ocrBadge.addClass("active"),
this._ocrBadge.setText("Processing"))
: a > 0
? (this._ocrBadge.addClass("idle"),
this._ocrBadge.setText("Pending"))
: (this._ocrBadge.addClass("idle"),
this._ocrBadge.setText("Idle"))),
this._ocrTrack)
) {
(this._ocrTrack.empty(),
s > 0
? this._ocrTrack.addClass("paperforge-processing")
: this._ocrTrack.removeClass("paperforge-processing"));
let l = [
{ cls: "pending", count: a },
{ cls: "active", count: s },
{ cls: "done", count: n },
{ cls: "failed", count: i },
];
for (let c of l)
if (c.count > 0) {
let d = ((c.count / r) * 100).toFixed(1);
this._ocrTrack.createEl("div", {
cls: `paperforge-progress-seg ${c.cls}`,
attr: { style: `width:${d}%` },
});
}
}
if (this._ocrCounts) {
this._ocrCounts.empty();
let l = [
{ cls: "pending", value: a, label: "Pending" },
{ cls: "active", value: s, label: "Processing" },
{ cls: "done", value: n, label: "Done" },
{ cls: "failed", value: i, label: "Failed" },
];
for (let c of l) {
let d = this._ocrCounts.createEl("div", {
cls: "paperforge-ocr-count",
});
(d.createEl("div", {
cls: "paperforge-ocr-count-value",
text: c.value.toString(),
}),
d.createEl("div", {
cls: "paperforge-ocr-count-label",
text: c.label,
}));
}
}
}
_renderLifecycleStepper(e, t, r) {
if (!t || !r) {
this._renderSkeleton(e);
return;
}
let n = [
{ key: "indexed", label: "Indexed" },
{ key: "pdf_ready", label: "PDF Ready" },
{ key: "fulltext_ready", label: "Fulltext Ready" },
{ key: "deep_read_done", label: "Deep Read" },
],
a = e.createEl("div", { cls: "paperforge-lifecycle-stepper" }),
s = !1;
for (let i of n) {
let l = a.createEl("div", { cls: "step" });
(l.createEl("div", { cls: "step-indicator" }),
l.createEl("div", { cls: "step-label", text: i.label }),
i.key === r
? (l.addClass("current"), (s = !0))
: s
? l.addClass("pending")
: l.addClass("completed"));
}
}
_renderHealthMatrix(e, t) {
if (!t) {
this._renderSkeleton(e);
return;
}
let r = [
{
key: "pdf_health",
label: "PDF Health",
iconOk: "\u2713",
iconWarn: "\u26A0",
iconFail: "\u2717",
},
{
key: "ocr_health",
label: "OCR Health",
iconOk: "\u2713",
iconWarn: "\u26A0",
iconFail: "\u2717",
},
{
key: "note_health",
label: "Note Health",
iconOk: "\u2713",
iconWarn: "\u26A0",
iconFail: "\u2717",
},
{
key: "asset_health",
label: "Asset Health",
iconOk: "\u2713",
iconWarn: "\u26A0",
iconFail: "\u2717",
},
],
n = e.createEl("div", { cls: "paperforge-health-matrix" });
for (let a of r) {
let s = t[a.key] || "healthy",
i = n.createEl("div", { cls: "paperforge-health-cell" }),
l,
c,
d;
(s === "healthy" || s === "ok"
? ((l = a.iconOk), (c = "ok"), (d = `${a.label}: OK`))
: s === "warn" || s === "warning" || s === "degraded"
? ((l = a.iconWarn),
(c = "warn"),
(d = `${a.label}: Needs Attention`))
: ((l = a.iconFail), (c = "fail"), (d = `${a.label}: Failed`)),
i.addClass(c),
i.setAttribute("title", d),
i.createEl("div", { cls: "paperforge-health-cell-icon", text: l }),
i.createEl("div", {
cls: "paperforge-health-cell-label",
text: a.label,
}));
}
}
_renderMaturityGauge(e, t, r) {
if (t == null || t === void 0) {
this._renderSkeleton(e);
return;
}
let n = e.createEl("div", { cls: "paperforge-maturity-gauge" }),
a = n.createEl("div", { cls: "gauge-track" }),
s = 4,
i = Math.max(1, Math.min(s, Math.round(t)));
for (let l = 1; l <= s; l++) {
let c = a.createEl("div", { cls: "gauge-segment" });
l <= i && (c.addClass("filled"), c.addClass(`level-${l}`));
}
if (
(n.createEl("div", { cls: "gauge-level", text: `Level ${i} / ${s}` }),
i < s && r)
) {
let l = typeof r == "string" ? [r] : r;
if (l.length > 0) {
let c = n.createEl("ul", { cls: "gauge-blockers" });
for (let d of l) c.createEl("li", { text: d });
}
}
}
_renderBarChart(e, t) {
if (!t || Object.keys(t).length === 0) {
this._renderEmptyState(e, "No lifecycle data");
return;
}
let r = [
{ key: "indexed", label: "Indexed", cls: "stage-indexed" },
{ key: "pdf_ready", label: "PDF Ready", cls: "stage-pdf-ready" },
{
key: "fulltext_ready",
label: "Fulltext Ready",
cls: "stage-fulltext-ready",
},
{ key: "deep_read_done", label: "Deep Read", cls: "stage-deep-read" },
],
n = e.createEl("div", { cls: "paperforge-bar-chart" }),
a = Math.max(1, ...r.map((s) => t[s.key] || 0));
for (let s of r) {
let i = t[s.key] || 0,
l = (i / a) * 100,
c = n.createEl("div", { cls: "bar-row" });
(c.createEl("div", { cls: "bar-label", text: s.label }),
c
.createEl("div", { cls: "bar-track" })
.createEl("div", {
cls: `bar-fill ${s.cls}`,
attr: { style: `width:${l.toFixed(1)}%` },
}),
c.createEl("div", { cls: "bar-count", text: i.toString() }));
}
}
_invalidateIndex() {
this._cachedItems = null;
}
_extractZoteroKeyFromPath(e) {
return Ct(e);
}
_resolveModeForFile(e) {
if (!e) return { mode: "global", filePath: null, key: null, domain: null };
let t = e.extension,
r = e.path;
if (t === "base")
return {
mode: "collection",
filePath: r,
key: null,
domain: e.basename.trim(),
};
if (t === "md") {
let a = this.app.metadataCache.getFileCache(e),
s = a && a.frontmatter && a.frontmatter.zotero_key;
if (s) return { mode: "paper", filePath: r, key: s, domain: null };
}
if (t === "pdf") {
let a = this._getCachedIndex();
for (let s of a) {
let i = (s.pdf_path || "").match(/\[\[([^\]]+)\]\]/);
if ((i ? i[1] : s.pdf_path) === r)
return {
mode: "paper",
filePath: r,
key: s.zotero_key,
domain: null,
};
}
}
let n = this._extractZoteroKeyFromPath(r);
return n
? { mode: "paper", filePath: r, key: n, domain: null }
: { mode: "global", filePath: r, key: null, domain: null };
}
_detectAndSwitch() {
let e = this._resolveModeForFile(this.app.workspace.getActiveFile());
((this._currentDomain = e.domain || null),
(this._currentPaperKey = e.key || null),
(this._currentPaperEntry = e.key ? this._findEntry(e.key) : null),
this._switchMode(e.mode, e.filePath));
}
_switchMode(e, t) {
if (this._currentMode === e && this._currentFilePath === t) {
this._refreshCurrentMode();
return;
}
if (
((this._currentMode = e),
(this._currentFilePath = t),
(this._techDetailsExpanded = !1),
!!this._contentEl)
)
switch (
(this._contentEl.empty(),
this._contentEl.removeClass("switching"),
this._renderModeHeader(e),
e)
) {
case "global":
this._renderGlobalMode();
break;
case "paper":
this._renderPaperMode();
break;
case "collection":
this._renderCollectionMode();
break;
case "versions":
this._renderVersionMode();
break;
}
}
_renderGlobalMode() {
var J, G, ee, Q, re, Pe, ye;
if (!this._contentEl) return;
let e = this._contentEl.createEl("div", { cls: "paperforge-global-view" });
((this._driftBannerEl = e.createEl("div", {
cls: "paperforge-drift-banner",
})),
(this._driftBannerEl.style.display = "none"));
let t = this._getCachedIndex(),
r = t.length,
n = 0,
a = 0,
s = 0;
for (let B of t)
(B.has_pdf && n++,
B.ocr_status === "done" && a++,
B.deep_reading_status === "done" && s++);
let i = e.createEl("div", { cls: "paperforge-library-snapshot" });
i.createEl("div", {
cls: "paperforge-section-label",
text: "Library Snapshot",
});
let l = i.createEl("div", { cls: "paperforge-snapshot-pills" }),
c = [
{ value: r, label: "papers" },
{ value: n, label: "PDFs ready" },
{ value: a, label: "OCR done" },
{ value: s, label: "deep-read done" },
];
for (let B of c) {
let j = l.createEl("div", { cls: "paperforge-snapshot-pill" });
(j.createEl("span", {
cls: "paperforge-snapshot-value",
text: String(B.value),
}),
j.createEl("span", {
cls: "paperforge-snapshot-label",
text: " " + B.label,
}));
}
let d = e.createEl("div", { cls: "paperforge-system-status" });
d.createEl("div", {
cls: "paperforge-section-label",
text: "System Status",
});
let f = d.createEl("div", { cls: "paperforge-status-grid" }),
p = this.app.plugins.plugins.paperforge,
m =
((J = p == null ? void 0 : p.manifest) == null ? void 0 : J.version) ||
"?",
y = this._paperforgeVersion;
if (!y)
try {
let B = this.app.vault.adapter.basePath,
{ path: j, extraArgs: ie = [] } = N(
B,
(G = p == null ? void 0 : p.settings) != null ? G : null,
void 0,
void 0
),
Y = (0, _e.execFileSync)(
j,
[...ie, "-c", "import paperforge; print(paperforge.__version__)"],
{ cwd: B, timeout: 5e3, encoding: "utf-8", windowsHide: !0 }
).trim();
Y &&
((y = Y.startsWith("v") ? Y : "v" + Y),
(this._paperforgeVersion = y));
} catch (B) {}
y = y || "\u2014";
let x = y === "v" + m;
this._renderSystemStatusRow(
f,
"Runtime",
x ? "healthy" : "mismatch",
x ? "v" + m : "plugin v" + m + " \u2260 CLI " + y
);
let _ = this._loadIndex(),
b = _ && _.items && _.items.length > 0;
this._renderSystemStatusRow(
f,
"Index",
b ? "healthy" : "missing",
b ? _.items.length + " entries" : "formal-library.json not found"
);
let E =
((ee = p == null ? void 0 : p.settings) == null
? void 0
: ee.system_dir) || "System",
k = this.app.vault.adapter.basePath,
g = !1,
v = "No exports found";
try {
let B = Le.join(k, E, "PaperForge", "exports");
if (he.existsSync(B)) {
let j = he.readdirSync(B).filter((ie) => ie.endsWith(".json"));
((g = j.length > 0),
(v = g ? j.length + " export(s)" : "No JSON exports"));
}
} catch (B) {}
this._renderSystemStatusRow(
f,
"Zotero Export",
g ? "healthy" : "missing",
v
);
let w = !!(
(Q = p == null ? void 0 : p.settings) != null && Q.paddleocr_api_key
);
if (!w)
try {
let B =
((re = p == null ? void 0 : p.settings) == null
? void 0
: re.system_dir) || "System",
j = Le.join(k, B, "PaperForge", ".env");
if (he.existsSync(j)) {
let Y = he
.readFileSync(j, "utf-8")
.match(/^PADDLEOCR_API_TOKEN\s*=\s*(.+)$/m);
w = !!(Y && Y[1] && Y[1].trim());
}
} catch (B) {}
(w ||
(w = !!(
process.env.PADDLEOCR_API_TOKEN ||
process.env.PADDLEOCR_API_KEY ||
process.env.OCR_TOKEN
)),
this._renderSystemStatusRow(
f,
"OCR Token",
w ? "configured" : "missing",
w ? "Configured" : "Not set"
));
let T = !1,
P = "",
L = this.app.vault.adapter.basePath,
O = Te(L);
((T = ft(L)),
(P =
(O && ((Pe = O.summary) == null ? void 0 : Pe.reason)) ||
(O && ((ye = O.summary) == null ? void 0 : ye.status)) ||
"Unknown"),
this._renderSystemStatusRow(
f,
"Memory Layer",
T ? "healthy" : "fail",
P
));
let z = !x && y !== "\u2014";
if (z || !b || !g || !w) {
let B = e.createEl("div", { cls: "paperforge-issue-summary" });
B.createEl("div", {
cls: "paperforge-section-label",
text: "\u9700\u8981\u5904\u7406",
});
let j = B.createEl("div", { cls: "paperforge-issue-list" });
(z &&
j.createEl("div", {
cls: "paperforge-issue-item",
text: "Runtime version mismatch",
}),
b ||
j.createEl("div", {
cls: "paperforge-issue-item",
text: "Index missing or corrupted",
}),
g ||
j.createEl("div", {
cls: "paperforge-issue-item",
text: "No Zotero export found",
}),
w ||
j.createEl("div", {
cls: "paperforge-issue-item",
text: "PaddleOCR API key not configured",
}));
let ie = B.createEl("div", { cls: "paperforge-issue-actions" }),
Y = ie.createEl("button", { cls: "paperforge-contextual-btn" });
(Y.createEl("span", { text: "Run Doctor" }),
Y.addEventListener("click", () => {
let Ce = se.find((We) => We.id === "paperforge-doctor");
Ce && this._runAction(Ce, Y);
}));
let fe = ie.createEl("button", { cls: "paperforge-contextual-btn" });
(fe.createEl("span", { text: "Repair Issues" }),
fe.addEventListener("click", () => {
let Ce = se.find((We) => We.id === "paperforge-repair");
Ce && this._runAction(Ce, fe);
}));
}
let D = e.createEl("div", { cls: "paperforge-global-actions" });
D.createEl("div", {
cls: "paperforge-section-label",
text: "Start Working",
});
let S = D.createEl("div", { cls: "paperforge-global-actions-row" }),
M = S.createEl("button", { cls: "paperforge-contextual-btn primary" });
(M.createEl("span", {
cls: "paperforge-contextual-btn-icon",
text: "\u{1F4C1}",
}),
M.createEl("span", { text: "Open Literature Hub" }),
M.addEventListener("click", () => {
var ie;
let B =
((ie = p == null ? void 0 : p.settings) == null
? void 0
: ie.base_dir) || "Bases",
j = this.app.vault.getAbstractFileByPath(B);
if (j) {
let Y = null;
if (
(j.children &&
(Y = j.children.find((fe) => fe.extension === "base")),
Y)
) {
let fe = this.app.workspace.getLeaf(!1);
fe && fe.openFile(Y);
} else new I.Notice("[!!] No .base file found in " + B, 6e3);
} else new I.Notice("[!!] Base directory not found: " + B, 6e3);
}));
let C = S.createEl("button", { cls: "paperforge-contextual-btn" });
(C.createEl("span", {
cls: "paperforge-contextual-btn-icon",
text: "\u21BB",
}),
C.createEl("span", { text: "Sync Library" }),
C.addEventListener("click", () => {
let B = se.find((j) => j.id === "paperforge-sync");
B && this._runAction(B, C);
}));
let F = S.createEl("button", { cls: "paperforge-contextual-btn" });
(F.createEl("span", {
cls: "paperforge-contextual-btn-icon",
text: "\u229E",
}),
F.createEl("span", { text: "Run OCR" }),
F.addEventListener("click", () => {
let B = se.find((j) => j.id === "paperforge-ocr");
B && this._runAction(B, F);
}));
let A = S.createEl("button", { cls: "paperforge-contextual-btn warn" });
(A.createEl("span", {
cls: "paperforge-contextual-btn-icon",
text: "\u21BA",
}),
A.createEl("span", { text: "Redo OCR" }),
A.addEventListener("click", () => {
let B = se.find((j) => j.id === "paperforge-ocr-redo");
B && this._runAction(B, A);
}));
}
_renderSystemStatusRow(e, t, r, n) {
let a = e.createEl("div", { cls: "paperforge-status-row" });
(a
.createEl("span", { cls: "paperforge-status-dot" })
.addClass(r === "healthy" || r === "configured" ? "ok" : "fail"),
a.createEl("span", { cls: "paperforge-status-label", text: t }),
a.createEl("span", { cls: "paperforge-status-detail", text: n || "" }));
}
_renderPaperMode() {
let e = this._currentPaperEntry,
t = this._currentPaperKey;
if (!this._contentEl) return;
if (!t) {
this._renderEmptyState(this._contentEl, "No paper data available.");
return;
}
if (!e) {
this._contentEl.createEl("div", {
cls: "paperforge-content-placeholder",
text: 'Paper "' + t + '" not found in canonical index. Sync first.',
});
return;
}
let r = this._contentEl.createEl("div", { cls: "paperforge-paper-view" }),
n = r.createEl("div", { cls: "paperforge-paper-header" });
n.createEl("div", {
cls: "paperforge-paper-title pf-copy",
text: e.title || "Untitled",
}).addEventListener("click", () => {
(navigator.clipboard.writeText(e.title || ""),
new I.Notice("Title copied"));
});
let s = n.createEl("div", { cls: "paperforge-paper-meta" });
(e.authors &&
e.authors.length > 0 &&
s.createEl("span", {
cls: "paperforge-paper-authors",
text: e.authors.join(", "),
}),
e.year &&
s.createEl("span", {
cls: "paperforge-paper-year",
text: String(e.year),
}));
let i = r.createEl("div", { cls: "paperforge-status-strip" }),
l = i.createEl("div", { cls: "paperforge-status-strip-left" }),
c = i.createEl("div", { cls: "paperforge-status-strip-right" }),
d = [
{ key: "pdf", label: "PDF", ok: e.has_pdf === !0 },
{
key: "ocr",
label: "OCR",
ok: e.ocr_status === "done",
pending: ["pending", "queued", "processing"].includes(
e.ocr_status || ""
),
fail: ["failed", "blocked", "done_incomplete", "nopdf"].includes(
e.ocr_status || ""
),
},
{
key: "deep",
label: "\u7CBE\u8BFB",
ok: e.deep_reading_status === "done",
},
];
for (let p of d) {
let m = l.createEl("span", { cls: "paperforge-status-pill" }),
y = "pending";
(p.ok ? (y = "ok") : p.fail ? (y = "fail") : p.pending && (y = "pending"),
m.addClass(y));
let x = p.ok ? "\u2713" : p.fail ? "\u2717" : "\u25CB";
(m.createEl("span", { cls: "paperforge-status-pill-icon", text: x }),
m.createEl("span", { text: " " + p.label }));
}
if (e.pdf_path) {
let p = c.createEl("button", { cls: "paperforge-contextual-btn" });
(p.createEl("span", {
cls: "paperforge-contextual-btn-icon",
text: "\u{1F4C4}",
}),
p.createEl("span", { text: "\u6253\u5F00 PDF" }),
p.addEventListener("click", () => {
let m = e.pdf_path.match(/\[\[([^\]]+)\]\]/),
y = m ? m[1] : e.pdf_path;
this.app.vault.getAbstractFileByPath(y)
? this.app.workspace.openLinkText(y, "")
: new I.Notice("[!!] PDF not found: " + y, 6e3);
}));
}
if (e.fulltext_path) {
let p = c.createEl("button", { cls: "paperforge-contextual-btn" });
(p.createEl("span", {
cls: "paperforge-contextual-btn-icon",
text: "\u{1F4DD}",
}),
p.createEl("span", { text: "\u6253\u5F00\u5168\u6587" }),
p.addEventListener("click", () => this._openFulltext(e.fulltext_path)));
}
let f = c.createEl("button", { cls: "paperforge-contextual-btn" });
if (
(f.createEl("span", { text: o("version_panel_title") }),
f.addEventListener("click", () => {
this._switchToVersionMode(t);
}),
this._renderPaperOverviewCard(r, e),
e.next_step === "ready" && e.deep_reading_status === "done")
) {
let p = r.createEl("div", { cls: "paperforge-complete-row" });
(p.createEl("span", { text: "\u2713" }),
p.createEl("span", {
text: "\u5DF2\u5B8C\u6210\uFF0C\u53EF\u76F4\u63A5\u4F7F\u7528",
}));
} else this._renderNextStepCard(r, e, t);
(this._renderRecentDiscussionCard(r, e),
this._renderPaperTechnicalDetails(r, e));
}
_renderPaperOverviewCard(e, t) {
let r = e.createEl("div", { cls: "paperforge-paper-overview" });
r.createEl("div", { cls: "paperforge-paper-overview-header" }).createEl(
"span",
{
cls: "paperforge-paper-overview-title",
text: "\u6587\u7AE0\u6982\u89C8",
}
);
let a = r.createEl("div", { cls: "paperforge-paper-overview-body" }),
s = a.createEl("div", {
cls: "paperforge-paper-overview-excerpt",
text: "\u52A0\u8F7D\u4E2D...",
});
if (t.note_path) {
let i = this.app.vault.getAbstractFileByPath(t.note_path);
i
? this.app.vault
.read(i)
.then((l) => {
let c = this._extractOverviewFromNote(l);
if (c) {
let d = c.length > 200 ? c.slice(0, 200) + "..." : c;
if ((s.setText(d), c.length > 200)) {
let f = a.createEl("div", {
cls: "paperforge-expand-container",
}),
p = f.createEl("button", {
cls: "paperforge-expand-icon",
title: "\u5C55\u5F00/\u6536\u8D77",
});
p.innerHTML =
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>';
let m = !1;
f.addEventListener("click", () => {
(s.setText(m ? d : c),
(p.innerHTML = m
? '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>'
: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"></polyline></svg>'),
(m = !m));
});
}
} else
s.setText(
"\u5C1A\u672A\u751F\u6210\u6587\u7AE0\u6982\u89C8\u3002\u8FD0\u884C /pf-deep \u5F00\u59CB\u7CBE\u8BFB\u3002"
);
})
.catch(() => {
s.setText("\u65E0\u6CD5\u8BFB\u53D6\u7B14\u8BB0\u5185\u5BB9");
})
: s.setText("\u7B14\u8BB0\u6587\u4EF6\u4E0D\u5B58\u5728");
} else s.setText("\u5C1A\u672A\u751F\u6210\u6587\u7AE0\u6982\u89C8");
}
_extractOverviewFromNote(e) {
if (!e) return null;
let t = e.indexOf("## \u{1F50D} \u7CBE\u8BFB");
if (t === -1) return null;
let r = e.slice(t),
n = [
"**\u4E00\u53E5\u8BDD\u603B\u89C8:**",
"**\u4E00\u53E5\u8BDD\u603B\u89C8**",
"**\u6587\u7AE0\u6458\u8981:**",
"**\u6587\u7AE0\u6458\u8981**",
];
for (let i of n) {
let l = r.indexOf(i);
if (l !== -1) {
let c = r.slice(l + i.length),
d = ["**5 Cs", "**Figure", "**\u8BC1\u636E", "### Pass 2", "## "],
f = c.length;
for (let y of d) {
let x = c.indexOf(y);
x !== -1 && x < f && (f = x);
}
let p = c.indexOf(`
`);
p !== -1 && p < f && (f = p);
let m = c.slice(0, f).trim();
return (
m.startsWith("**") && (m = m.slice(2)),
m.endsWith("**") && (m = m.slice(0, -2)),
m || null
);
}
}
let a = r.indexOf(`
`);
if (a === -1) return null;
let s = r
.slice(a + 1)
.split(
`
`
)[0]
.trim();
return !s || s.startsWith("###") || s.startsWith("##")
? null
: s.length > 300
? s.slice(0, 300) + "..."
: s;
}
_renderRecentDiscussionCard(e, t) {
let r = e.createEl("div", { cls: "paperforge-discussion-card" });
if (((r.style.display = "none"), !t.note_path)) return;
let n = t.note_path.lastIndexOf("/"),
s = (n !== -1 ? t.note_path.substring(0, n) : ".") + "/ai/discussion.md";
this.app.vault.adapter
.exists(s)
.then((i) => {
if (i) return this.app.vault.adapter.read(s);
})
.then(async (i) => {
if (!i) return;
let l = this._parseDiscussionMD(i);
if (!l || l.length === 0) return;
((r.style.display = "block"),
r
.createEl("div", { cls: "paperforge-discussion-header" })
.createEl("span", {
cls: "paperforge-discussion-title",
text: "\u6700\u8FD1\u8BA8\u8BBA",
}));
for (let f of l) {
let p = r.createEl("div", { cls: "paperforge-discussion-item" }),
m = p.createEl("div", { cls: "paperforge-discussion-q" });
(m.createEl("span", {
cls: "paperforge-discussion-q-label",
text: "\u63D0\u95EE\uFF1A",
}),
m.createEl("span", {
cls: "paperforge-discussion-q-text",
text: f.question,
}));
let y = p.createEl("div", { cls: "paperforge-discussion-a" }),
x = !1;
if (
(f.answer &&
f.answer.length > 500 &&
((x = !0), y.classList.add("paperforge-discussion-a-collapsed")),
await I.MarkdownRenderer.render(
this.app,
f.answer || "",
y,
s,
this
),
x)
) {
let _ = !1;
((p.style.cursor = "pointer"),
p.addEventListener("click", () => {
((_ = !_),
y.classList.toggle("paperforge-discussion-a-collapsed", !_),
y.classList.toggle("paperforge-discussion-a-expanded", _));
}));
}
}
r.createEl("a", {
cls: "paperforge-discussion-viewall",
text: "\u67E5\u770B\u5168\u90E8\u8BA8\u8BBA \u2192",
}).addEventListener("click", (f) => {
(f.preventDefault(),
this.app.vault.getAbstractFileByPath(s)
? this.app.workspace.openLinkText(s, "")
: new I.Notice(
"\u8BA8\u8BBA\u6587\u4EF6\u5C1A\u672A\u751F\u6210"
));
});
})
.catch((i) => {
console.error("PaperForge: discussion.md read error", s, i.message);
});
}
_parseDiscussionMD(e) {
let t = e.split(/\n## /).slice(1);
if (t.length === 0) return null;
let r = t[t.length - 1],
n = [],
a = r.split(/\*\*\u95EE\u9898:\*\*/).slice(1);
for (let s of a) {
let i = s.match(/\*\*\u89E3\u7B54:\*\*/);
if (!i) continue;
let l = s.substring(0, i.index).trim(),
c = s.substring(i.index + 3 + 4).trim();
n.push({ question: l, answer: c });
}
return n.slice(-3);
}
_renderPaperTechnicalDetails(e, t) {
let r = this._currentPaperKey,
n = e.createEl("div", { cls: "paperforge-technical-details" }),
a = n.createEl("button", { cls: "paperforge-technical-details-toggle" }),
s = n.createEl("div", { cls: "paperforge-technical-details-body" });
((s.style.display = "none"),
this._techDetailsExpanded
? ((s.style.display = "block"),
a.setText("\u6280\u672F\u8BE6\u60C5 \u25BE"))
: a.setText("\u6280\u672F\u8BE6\u60C5 \u25B8"),
a.addEventListener("click", () => {
let p = s.style.display !== "none";
((s.style.display = p ? "none" : "block"),
a.setText(
p
? "\u6280\u672F\u8BE6\u60C5 \u25B8"
: "\u6280\u672F\u8BE6\u60C5 \u25BE"
),
(this._techDetailsExpanded = !p));
}));
let i = s.createEl("div", { cls: "paperforge-workflow-toggles" }),
l = [
{ key: "do_ocr", label: "OCR", hint: "\u52A0\u5165 OCR" },
{
key: "analyze",
label: "\u7CBE\u8BFB",
hint: "\u6807\u8BB0\u7CBE\u8BFB",
},
];
for (let p of l) {
let m = i.createEl("label", { cls: "paperforge-workflow-toggle" }),
y = m.createEl("input", {
type: "checkbox",
cls: "paperforge-workflow-checkbox",
});
((y.checked = t[p.key] === !0),
m.createEl("span", {
cls: "paperforge-workflow-toggle-label",
text: p.label,
}),
m.createEl("span", {
cls: "paperforge-workflow-toggle-hint",
text: p.hint,
}),
y.addEventListener("change", async () => {
let x = t.note_path
? this.app.vault.getAbstractFileByPath(t.note_path)
: null;
if (!x) {
new I.Notice("[!!] Note file not found", 6e3);
return;
}
let _ = y.checked;
(await this.app.fileManager.processFrontMatter(x, (b) => {
b[p.key] = _;
}),
this._patchCachedEntry(r, { [p.key]: _ }),
(this._currentPaperEntry = Ze(this._currentPaperEntry, {
[p.key]: _,
})));
}));
}
let c = t.health || {},
d = [
["PDF Health", c.pdf_health || "\u2014"],
["OCR Status", t.ocr_status || "\u2014"],
["Asset Health", c.asset_health || "\u2014"],
["Note Path", t.note_path || "\u2014"],
["Fulltext Path", t.fulltext_path || "\u2014"],
],
f = new Set(["Note Path", "Fulltext Path", "Key"]);
for (let [p, m] of d) {
let y = s.createEl("div", { cls: "paperforge-technical-row" });
y.createEl("span", { cls: "paperforge-technical-label", text: p });
let x = y.createEl("span", {
cls: "paperforge-technical-value",
text: String(m),
});
f.has(p) &&
m &&
m !== "\u2014" &&
(x.addClass("pf-copy"),
x.addEventListener("click", () => {
(navigator.clipboard.writeText(m), new I.Notice(p + " copied"));
}));
}
}
_renderNextStepCard(e, t, r) {
var l, c;
let n = t.next_step || "ready",
a = {
sync: {
label: "Sync Needed",
text: "This paper needs to be synced from Zotero. Click to run sync.",
cmd: "sync",
icon: "\u21BB",
},
ocr: {
label: "OCR Needed",
text: "Fulltext is missing but PDF is present. Click to run OCR.",
cmd: "ocr",
icon: "\u229E",
},
repair: {
label: "Repair Needed",
text: "State divergence or path errors detected. Click to repair.",
cmd: "repair",
icon: "\u21BA",
},
"rebuild index": {
label: "Rebuild Needed",
text: "Index may be stale. Click to run sync to rebuild.",
cmd: "sync",
icon: "\u21BB",
},
"/pf-deep": {
label: "Ready for Deep Reading",
text: "Fulltext is ready. Copy /pf-deep command and run in your agent.",
cmd: null,
icon: "\u{1F50D}",
},
ready: {
label: "All Set",
text: "This paper is fully processed and ready for use.",
cmd: "ready",
icon: "\u2713",
},
},
s = a[n] || a.ready,
i = e.createEl("div", { cls: "paperforge-next-step-card" });
if (
(n === "ready" && i.addClass("ready"),
i.createEl("div", {
cls: "paperforge-next-step-label",
text: "Recommended Next Step",
}),
i.createEl("div", { cls: "paperforge-next-step-text", text: s.text }),
s.cmd && s.cmd !== "ready")
) {
let d = i.createEl("button", { cls: "paperforge-next-step-trigger" });
(d.createEl("span", { text: s.icon + " " + s.label }),
d.addEventListener("click", () => {
let f = se.find((p) => p.cmd === s.cmd);
f && this._runAction(f, d);
}));
} else if (n === "/pf-deep") {
let d = i.createEl("button", { cls: "paperforge-next-step-trigger" });
(d.createEl("span", { text: "\u{1F4CB} " + o("copy_pf_deep_cmd") }),
d.addEventListener("click", () => {
let x = "/pf-deep " + r;
navigator.clipboard
.writeText(x)
.then(() => {
(d.setText("\u2713 " + o("copied")),
new I.Notice(x + " copied"));
})
.catch(() => {
new I.Notice("[!!] Clipboard write failed", 6e3);
});
}));
let f =
((c =
(l = this.app.plugins.plugins.paperforge) == null
? void 0
: l.settings) == null
? void 0
: c.agent_platform) || "opencode",
m =
{
opencode: "OpenCode",
claude: "Claude Code",
cursor: "Cursor",
github_copilot: "GitHub Copilot",
windsurf: "Windsurf",
codex: "Codex",
gemini: "Gemini CLI",
cline: "Cline",
}[f] || f;
i.createEl("div", { cls: "paperforge-agent-platform-label" }).setText(
o("run_in_agent").replace("{0}", m)
);
} else
n === "ready" &&
i
.createEl("button", { cls: "paperforge-next-step-trigger" })
.createEl("span", { text: "\u2713 " + s.label });
}
_openFulltext(e) {
if (!e) {
new I.Notice("[!!] No fulltext path available for this paper", 6e3);
return;
}
let t = this.app.vault.getAbstractFileByPath(e);
t
? this.app.workspace.openLinkText(t.path, "")
: new I.Notice("[!!] Fulltext file not found: " + e, 6e3);
}
_renderCollectionMode() {
let e = this._currentDomain || "Unknown",
t = this._filterByDomain(e);
if (t.length === 0) {
this._renderGlobalMode();
return;
}
if (!this._contentEl) return;
let r = this._contentEl.createEl("div", {
cls: "paperforge-collection-view",
}),
n = t.length,
a = 0,
s = 0,
i = 0,
l = 0,
c = 0,
d = 0,
f = 0;
for (let g of t) {
(g.has_pdf && a++,
g.ocr_status === "done" && s++,
g.ocr_status === "done" && g.analyze === !0 && i++,
g.deep_reading_status === "done" && l++);
let v = g.ocr_status || "";
v === "pending" || v === "queued"
? c++
: v === "processing"
? d++
: (v === "failed" ||
v === "blocked" ||
v === "done_incomplete" ||
v === "nopdf") &&
f++;
}
r.createEl("div", { cls: "paperforge-collection-header" }).createEl("div", {
cls: "paperforge-collection-title",
text: e,
});
let m = r.createEl("div", { cls: "paperforge-workflow-overview" });
m.createEl("div", {
cls: "paperforge-section-label",
text: "Workflow Overview",
});
let y = m.createEl("div", { cls: "paperforge-workflow-funnel" }),
x = [
{ value: n, label: "Total" },
{ value: a, label: "PDF Ready" },
{ value: s, label: "OCR Done" },
{ value: l, label: "Deep Read" },
];
for (let g = 0; g < x.length; g++) {
let v = y.createEl("div", { cls: "paperforge-workflow-stage" });
(v.createEl("div", {
cls: "paperforge-workflow-stage-value",
text: String(x[g].value),
}),
v.createEl("div", {
cls: "paperforge-workflow-stage-label",
text: x[g].label,
}),
g < x.length - 1 &&
y.createEl("div", {
cls: "paperforge-workflow-arrow",
text: "\u2192",
}));
}
if (c + d + s + f > 0) {
let g = r.createEl("div", { cls: "paperforge-ocr-section" }),
v = g.createEl("div", { cls: "paperforge-collection-ocr-header" });
v.createEl("h4", { cls: "paperforge-ocr-title", text: "OCR Pipeline" });
let w = v.createEl("span", { cls: "paperforge-ocr-badge idle" });
d > 0
? (w.addClass("active"), w.setText("Processing"))
: c > 0
? w.setText("Pending")
: (w.addClass("idle"), w.setText("Idle"));
let T = g.createEl("div", { cls: "paperforge-progress-track" });
d > 0 && T.addClass("paperforge-processing");
let P = c + d + s + f,
L = [
{ cls: "pending", count: c },
{ cls: "active", count: d },
{ cls: "done", count: s },
{ cls: "failed", count: f },
];
for (let q of L)
if (q.count > 0) {
let D = ((q.count / P) * 100).toFixed(1);
T.createEl("div", {
cls: `paperforge-progress-seg ${q.cls}`,
attr: { style: `width:${D}%` },
});
}
let O = g.createEl("div", { cls: "paperforge-ocr-counts" }),
z = [
{ cls: "pending", value: c, label: "Pending" },
{ cls: "active", value: d, label: "Processing" },
{ cls: "done", value: s, label: "Done" },
{ cls: "failed", value: f, label: "Attention" },
];
for (let q of z) {
let D = O.createEl("div", { cls: "paperforge-ocr-count" });
(D.createEl("div", {
cls: "paperforge-ocr-count-value",
text: q.value.toString(),
}),
D.createEl("div", {
cls: "paperforge-ocr-count-label",
text: q.label,
}));
}
}
let _ = r.createEl("div", { cls: "paperforge-collection-actions" }),
b = _.createEl("button", { cls: "paperforge-contextual-btn primary" });
(b.createEl("span", {
cls: "paperforge-contextual-btn-icon",
text: "\u229E",
}),
b.createEl("span", { text: "Run OCR" }),
b.addEventListener("click", () => {
let g = se.find((v) => v.id === "paperforge-ocr");
g && this._runAction(g, b);
}));
let E = _.createEl("button", { cls: "paperforge-contextual-btn" });
(E.createEl("span", {
cls: "paperforge-contextual-btn-icon",
text: "\u21BB",
}),
E.createEl("span", { text: "Sync Library" }),
E.addEventListener("click", () => {
let g = se.find((v) => v.id === "paperforge-sync");
g && this._runAction(g, E);
}));
let k = _.createEl("button", { cls: "paperforge-contextual-btn warn" });
(k.createEl("span", {
cls: "paperforge-contextual-btn-icon",
text: "\u21BA",
}),
k.createEl("span", { text: "Redo OCR" }),
k.addEventListener("click", () => {
let g = se.find((v) => v.id === "paperforge-ocr-redo");
g && this._runAction(g, k);
}),
this.renderSearchSection(r));
}
_refreshCurrentMode() {
if (!(!this._currentMode || !this._contentEl)) {
(this._contentEl.empty(),
this._contentEl.addClass("switching"),
this._invalidateIndex(),
(this._currentPaperEntry = this._currentPaperKey
? this._findEntry(this._currentPaperKey)
: null),
this._renderModeHeader(this._currentMode));
try {
switch (this._currentMode) {
case "global":
this._renderGlobalMode();
break;
case "paper":
this._renderPaperMode();
break;
case "collection":
this._renderCollectionMode();
break;
case "versions":
this._renderVersionMode();
break;
}
} finally {
setTimeout(() => {
this._contentEl && this._contentEl.removeClass("switching");
}, 50);
}
}
}
_switchToVersionMode(e) {
let r = this.app.vault.adapter.basePath,
n = typeof r == "string" ? r : "";
if (!n) {
new I.Notice("Cannot determine vault path");
return;
}
((this._versionPapers = nt(n)),
(this._versionFilter = ""),
(this._currentMode = "versions"),
(this._currentFilePath = null),
(this._techDetailsExpanded = !1),
this._contentEl &&
(this._contentEl.empty(),
this._contentEl.removeClass("switching"),
this._renderModeHeader("versions"),
this._renderVersionMode()));
}
_renderVersionMode() {
if (!this._contentEl) return;
let e = this._contentEl.createEl("div", {
cls: "paperforge-version-panel",
}),
r = this.app.vault.adapter.basePath,
n = typeof r == "string" ? r : "";
if (!n) {
e.createEl("div", {
cls: "paperforge-status-error",
text: "Could not determine vault path",
});
return;
}
(!this._versionPapers || this._versionPapers.length === 0) &&
(this._versionPapers = nt(n));
let a = e.createEl("div", { cls: "paperforge-version-left" }),
s = e.createEl("div", { cls: "paperforge-version-right" }),
i = a.createEl("input", {
cls: "paperforge-version-filter",
attr: { type: "text", placeholder: o("version_filter_placeholder") },
});
i.value = this._versionFilter;
let l = a.createEl("div", { cls: "paperforge-version-paper-list" }),
c = () => {
l.empty();
let b = this._versionFilter.toLowerCase(),
E = this._versionPapers
? this._versionPapers.filter(
(g) =>
!b ||
g.key.toLowerCase().includes(b) ||
g.title.toLowerCase().includes(b)
)
: [];
if (E.length === 0) {
l.createEl("div", {
cls: "paperforge-meta",
text: o("version_no_backups"),
});
return;
}
let k = l.createEl("div", {
cls: "paperforge-meta",
text: o("version_papers_count").replace("{n}", String(E.length)),
});
for (let g of E) {
let v = l.createEl("div", { cls: "paperforge-version-paper-item" }),
w = v.createEl("span", {
cls: "paperforge-version-paper-title",
text: g.title,
}),
T = v.createEl("span", {
cls: "paperforge-version-paper-versions",
text: g.versions.map((P) => P.label).join(" "),
});
v.addEventListener("click", () => {
(l
.querySelectorAll(".paperforge-version-paper-item.selected")
.forEach((P) => P.removeClass("selected")),
v.addClass("selected"),
f(g));
});
}
};
i.addEventListener("input", () => {
((this._versionFilter = i.value), c());
});
let d = s.createEl("div", { cls: "paperforge-version-timeline-area" }),
f = (b) => {
if (
(d.empty(),
d
.createEl("div", { cls: "paperforge-version-timeline-header" })
.createEl("span", { cls: "pf-title", text: b.title }),
b.versions.length === 0)
) {
d.createEl("div", {
cls: "paperforge-meta",
text: o("version_no_backups"),
});
return;
}
let k = d.createEl("div", { cls: "paperforge-version-timeline" });
for (let g of b.versions) {
let v = g.label === b.currentLabel,
w = k.createEl("div", {
cls:
"paperforge-version-entry" +
(v ? " paperforge-version-current" : ""),
}),
T = w.createEl("div", { cls: "paperforge-version-dot" }),
P = w.createEl("div", { cls: "paperforge-version-content" }),
L = P.createEl("div", { cls: "paperforge-version-label-row" });
(L.createEl("span", {
cls: "paperforge-version-label",
text: g.label,
}),
v &&
L.createEl("span", {
cls: "paperforge-version-current-tag",
text: o("version_current"),
}));
let O = g.created_at ? g.created_at.slice(0, 10) : "";
P.createEl("div", {
cls: "paperforge-meta",
text: O + " \u2014 " + g.source,
});
let z = g.fulltext_size
? g.fulltext_size > 1024
? (g.fulltext_size / 1024).toFixed(0) + "KB"
: g.fulltext_size + "B"
: "";
z && P.createEl("div", { cls: "paperforge-meta", text: z });
let q = P.createEl("div", { cls: "paperforge-version-actions" });
(q
.createEl("button", {
cls: "pf-btn-primary",
text: o("version_restore_btn"),
})
.addEventListener("click", () => {
Rt(n, b.key, g.label)
? new I.Notice(
o("version_restore_done").replace("{label}", g.label)
)
: new I.Notice("Restore failed", 6e3);
}),
b.versions.length > 1 &&
!v &&
q
.createEl("button", {
cls: "pf-btn-secondary",
text: o("version_compare_btn"),
})
.addEventListener("click", () => {
m(b, g.label, b.currentLabel);
}));
}
},
p = s.createEl("div", { cls: "paperforge-version-compare" });
p.style.display = "none";
let m = (b, E, k) => {
let g = Tt(n, b.key, E, k);
((p.style.display = "block"), p.empty());
let v = p.createEl("div", { cls: "paperforge-version-compare-header" });
if (
(v.createEl("span", {
cls: "pf-title",
text: o("version_compare_title")
.replace("{vA}", E)
.replace("{vB}", k),
}),
v.createEl("span", {
cls: "paperforge-meta",
text: o("version_compare_paragraphs").replace(
"{n}",
String(g.length)
),
}),
g.length === 0)
) {
p.createEl("div", { cls: "paperforge-meta", text: "No changes" });
return;
}
let w = p.createEl("div", { cls: "paperforge-version-diff-list" });
for (let T of g) {
let P = w.createEl("div", { cls: "paperforge-version-diff-row" }),
L =
T.type === "added" ? "[+]" : T.type === "removed" ? "[-]" : "[~]",
O = T.heading || "paragraph " + (T.paragraphIndex + 1);
(P.createEl("span", {
cls: "paperforge-version-diff-label",
text: L + " " + O,
}),
T.oldText &&
P.createEl("pre", {
cls: "paperforge-version-diff-old",
text: T.oldText.slice(0, 200),
}),
T.newText &&
P.createEl("pre", {
cls: "paperforge-version-diff-new",
text: T.newText.slice(0, 200),
}));
}
},
y = e.createEl("div", { cls: "paperforge-version-actions-bar" }),
x = y.createEl("button", {
cls: "pf-btn-primary",
text: o("version_restore_selected"),
}),
_ = y.createEl("button", {
cls: "pf-btn-secondary",
text: o("version_clear_old").replace("{size}", ""),
});
c();
}
renderSearchSection(e) {
((this._searchContainer = e.createEl("div", {
cls: "paperforge-search-section",
})),
this._searchContainer
.createEl("div", { cls: "paperforge-search-header" })
.createEl("span", { cls: "pf-label", text: "Search" }));
let r = this._searchContainer.createEl("div", {
cls: "paperforge-search-input-row",
}),
n = r.createEl("span", { cls: "paperforge-search-mode", text: "M" });
((this._searchInput = r.createEl("input", {
cls: "paperforge-search-input",
attr: {
type: "text",
placeholder: "Search papers... (@ for deep search)",
},
})),
(this._searchResultsEl = this._searchContainer.createEl("div", {
cls: "paperforge-search-results",
})),
(this._searchInput.placeholder = o("retrieval_search_placeholder")),
this._searchInput.addEventListener("input", () => {
var s;
let a = ((s = this._searchInput) == null ? void 0 : s.value) || "";
if (
(a.startsWith("@") && !a.startsWith("@ ")
? ((this._searchMode = "@"),
n.setText("@"),
n.addClass("deep"),
this._searchInput &&
(this._searchInput.placeholder = o(
"retrieval_search_placeholder_deep"
)))
: ((this._searchMode = "M"),
n.setText("M"),
n.removeClass("deep"),
this._searchInput &&
(this._searchInput.placeholder = o(
"retrieval_search_placeholder"
))),
clearTimeout(this._searchTimer),
!a.trim())
) {
((this._searchState = "idle"),
(this._searchResults = null),
(this._searchActiveIndex = -1),
this._renderSearchState());
return;
}
a.startsWith("@") ||
(this._searchTimer = setTimeout(() => {
this.executeSearch();
}, 200));
}),
this._searchInput.addEventListener("keydown", (a) => {
var s, i;
if (a.key === "Escape") {
(a.preventDefault(),
this._searchInput &&
((this._searchInput.value = ""), this._searchInput.blur()),
(this._searchState = "idle"),
(this._searchResults = null),
(this._searchActiveIndex = -1),
this._renderSearchState());
return;
}
if (a.key === "ArrowDown" || a.key === "ArrowUp") {
if (
this._searchState !== "results" ||
!((s = this._searchResults) != null && s.length)
)
return;
a.preventDefault();
let l = this._searchResults.length;
a.key === "ArrowDown"
? (this._searchActiveIndex = Math.min(
this._searchActiveIndex + 1,
l - 1
))
: (this._searchActiveIndex = Math.max(
this._searchActiveIndex - 1,
-1
));
let c =
(i = this._searchResultsEl) == null
? void 0
: i.querySelectorAll(".paperforge-search-result-card");
c &&
c.forEach((d, f) => {
f === this._searchActiveIndex
? (d.setAttribute("aria-selected", "true"),
d.classList.add("active"))
: (d.setAttribute("aria-selected", "false"),
d.classList.remove("active"));
});
return;
}
if (a.key === "Enter" && a.ctrlKey) {
(a.preventDefault(),
this._searchTimer &&
(clearTimeout(this._searchTimer), (this._searchTimer = void 0)));
let l = this._searchMode;
((this._searchMode = "@"),
this.executeSearch(),
(this._searchMode = l));
return;
}
a.key === "Enter" &&
(a.preventDefault(),
this._searchTimer &&
(clearTimeout(this._searchTimer), (this._searchTimer = void 0)),
this.executeSearch());
}));
}
_renderSearchState() {
if (!this._searchResultsEl) return;
switch (
(this._searchResultsEl.empty(),
this._searchResultsEl.removeAttribute("role"),
this._searchResultsEl.removeAttribute("aria-live"),
this._searchInput && (this._searchInput.disabled = !1),
this._searchState)
) {
case "idle":
break;
case "searching": {
let t = this._searchMode === "@";
(this._searchResultsEl.createEl("div", {
cls: "paperforge-search-loading",
text: t
? o("retrieval_searching_deep")
: o("retrieval_searching_metadata"),
}),
this._searchResultsEl.setAttr("aria-live", "polite"),
t && this._searchInput && (this._searchInput.disabled = !0));
break;
}
case "results": {
(this._searchResultsEl.setAttr("role", "listbox"),
this._searchResultsEl.setAttr("aria-live", "polite"),
this._searchResults &&
this._renderSearchResultsList(
this._searchResults,
this._searchMode === "@"
),
setTimeout(() => {
var r;
let t =
(r = this._searchResultsEl) == null
? void 0
: r.querySelector(".paperforge-search-result-card");
t && t instanceof HTMLElement && t.focus();
}, 100));
break;
}
case "empty": {
let t = this._searchResultsEl.createEl("div", {
cls: "paperforge-search-empty",
});
(t.setAttr("role", "alert"),
t.createEl("div", { text: o("retrieval_empty") }),
t.createEl("div", {
cls: "paperforge-search-empty-tips",
text: o("retrieval_empty_tips"),
}));
break;
}
case "vectors-not-built": {
let t = this._searchResultsEl.createEl("div", {
cls: "paperforge-search-state-card",
attr: { role: "alert" },
});
(t.addClass("warning-soft"),
t.createEl("div", {
cls: "paperforge-search-state-title",
text: o("retrieval_vectors_not_built"),
}),
t.createEl("div", {
cls: "paperforge-search-state-desc",
text: o("retrieval_vectors_not_built_desc"),
}));
let r = t.createEl("button", {
cls: "pf-btn-link",
text: o("retrieval_open_vector_settings"),
});
(r.addEventListener("click", () => {
let n = this.app.setting;
if (n && typeof n == "object") {
let a = n.openTab;
typeof a == "function" && a.call(n, "paperforge");
}
}),
setTimeout(() => {
r.focus();
}, 100));
break;
}
case "backend-unavailable": {
let t = this._searchResultsEl.createEl("div", {
cls: "paperforge-search-state-card",
attr: { role: "alert" },
});
(t.addClass("error-soft"),
t.createEl("div", {
cls: "paperforge-search-state-title",
text: o("retrieval_backend_unavailable"),
}),
t.createEl("div", {
cls: "paperforge-search-state-desc",
text: o("retrieval_backend_unavailable_desc"),
}));
let r = t.createEl("div", { cls: "paperforge-search-state-actions" }),
n = r.createEl("button", {
cls: "pf-btn-primary",
text: o("retrieval_run_doctor"),
});
(n.addEventListener("click", () => {
let s = this.app.vault.adapter.basePath;
if (typeof s == "string") {
let { path: i, extraArgs: l = [] } = N(s, null, void 0, void 0);
(0, _e.spawn)(i, [...l, "-m", "paperforge", "doctor"], {
cwd: s,
stdio: "inherit",
});
}
}),
r
.createEl("button", {
cls: "pf-btn-secondary",
text: o("retrieval_retry"),
})
.addEventListener("click", () => {
this.executeSearch();
}),
setTimeout(() => {
n.focus();
}, 100));
break;
}
case "timeout": {
let t = this._searchResultsEl.createEl("div", {
cls: "paperforge-search-state-card",
attr: { role: "alert" },
});
(t.addClass("warning-soft"),
t.createEl("div", {
cls: "paperforge-search-state-title",
text: o("retrieval_timeout_title"),
}),
t.createEl("div", {
cls: "paperforge-search-state-desc",
text: o("retrieval_timeout_desc"),
}));
let r = t.createEl("button", {
cls: "pf-btn-primary",
text: o("retrieval_retry"),
});
(r.addEventListener("click", () => {
this.executeSearch();
}),
setTimeout(() => {
r.focus();
}, 100));
break;
}
case "model-changed": {
let t = this._searchResultsEl.createEl("div", {
cls: "paperforge-search-state-card",
attr: { role: "alert" },
});
(t.addClass("warning-soft"),
t.createEl("div", {
cls: "paperforge-search-state-title",
text: o("retrieval_model_changed"),
}),
t.createEl("div", {
cls: "paperforge-search-state-desc",
text: o("retrieval_model_changed_desc"),
}));
let r = t.createEl("button", {
cls: "pf-btn-primary",
text: o("retrieval_rebuild_vectors"),
});
(r.addEventListener("click", () => {
let n = this.app.setting;
if (n && typeof n == "object") {
let a = n.openTab;
typeof a == "function" && a.call(n, "paperforge");
}
}),
setTimeout(() => {
r.focus();
}, 100));
break;
}
default: {
(this._searchResultsEl
.createEl("div", {
cls: "paperforge-search-state-card",
text: o("retrieval_internal_error"),
attr: { role: "alert" },
})
.addClass("error-soft"),
setTimeout(() => {
this._searchInput && this._searchInput.focus();
}, 100));
break;
}
}
}
async executeSearch() {
if (!this._searchInput || !this._searchResultsEl) return;
let e = this._searchInput.value.trim();
if (!e) return;
let t = this._searchMode === "@" || e.startsWith("@"),
r = t ? e.replace(/^@\s*/, "").trim() : e;
if (!r) return;
let n = t ? "retrieve" : "search";
((this._searchState = "searching"),
(this._searchResults = null),
(this._searchActiveIndex = -1),
this._renderSearchState());
let a = this.app.vault.adapter,
s = "";
if (a && typeof a == "object" && "basePath" in a) {
let x = a.basePath;
s = typeof x == "string" ? x : "";
}
if (!s) {
((this._searchState = "backend-unavailable"), this._renderSearchState());
return;
}
let i = null,
c = this.app.plugins;
if (c && typeof c == "object" && "plugins" in c) {
let x = c.plugins;
if (x && typeof x == "object" && "paperforge" in x) {
let _ = x.paperforge;
_ && typeof _ == "object" && "settings" in _ && (i = _.settings);
}
}
let { path: d, extraArgs: f = [] } = N(s, i, void 0, void 0),
p = n === "retrieve" ? ["--deep"] : [],
m = (0, _e.spawn)(
d,
[...f, "-m", "paperforge", "--vault", s, n, r, ...p, "--json"],
{ cwd: s, timeout: 3e4 }
),
y = [];
(m.stdout.on("data", (x) => {
y.push(x.toString("utf-8"));
}),
m.stderr.on("data", () => {}),
m.on("close", (x) => {
if (x !== 0) {
let g = Xe(String(x));
((this._searchState = this._mapErrorToSearchState(g.type)),
this._renderSearchState());
return;
}
let _ = y.join(""),
b = _.indexOf("{"),
E = _.lastIndexOf("}"),
k = "";
if (b !== -1 && E > b) k = _.slice(b, E + 1);
else {
let g = _.indexOf("["),
v = _.lastIndexOf("]");
g !== -1 && v > g && (k = _.slice(g, v + 1));
}
if (!k) {
((this._searchState = "internal-error"), this._renderSearchState());
return;
}
try {
let g = JSON.parse(k),
v = [];
if (g && typeof g == "object" && "data" in g) {
let w = g.data;
if (w && typeof w == "object") {
let T = w;
"matches" in T && Array.isArray(T.matches) && (v = T.matches);
}
}
((this._searchResults = v),
(this._searchState = v.length > 0 ? "results" : "empty"),
this._renderSearchState());
} catch (g) {
let v = g instanceof Error ? g.message : String(g);
((this._searchState = "internal-error"), this._renderSearchState());
}
}),
m.on("error", (x) => {
let _ = x.code;
if (typeof _ == "string") {
let b = Xe(_);
this._searchState = this._mapErrorToSearchState(b.type);
} else this._searchState = "backend-unavailable";
this._renderSearchState();
}));
}
_mapErrorToSearchState(e) {
switch (e) {
case "vectors_not_built":
return "vectors-not-built";
case "vectors_corrupted":
return "vectors-not-built";
case "backend_unavailable":
return "backend-unavailable";
case "model_changed":
return "model-changed";
case "timeout":
return "timeout";
case "no_python":
case "python_missing":
case "import_failed":
case "version_mismatch":
return "backend-unavailable";
default:
return "backend-unavailable";
}
}
_renderSearchResultsList(e, t) {
if (!this._searchResultsEl) return;
if (
(this._searchResultsEl.setAttr("aria-live", "polite"), e.length === 0)
) {
this._searchResultsEl.createEl("div", {
cls: "paperforge-search-empty",
text: "No results found.",
});
return;
}
let r = this._searchResultsEl.createEl("div", {
cls: "paperforge-search-results-header",
});
(r
.createEl("span", {
text: o("retrieval_results_count")
.replace("{n}", String(e.length))
.replace("{s}", e.length !== 1 ? "s" : ""),
})
.setAttr("aria-live", "polite"),
r.createEl("span", {
cls: "paperforge-search-mode",
text: t ? "@" : "M",
}));
for (let a = 0; a < e.length; a++) {
let s = e[a];
if (!s || typeof s != "object") continue;
let i = s,
l = a === this._searchActiveIndex,
c = this._searchResultsEl.createEl("div", {
cls: "paperforge-search-result-card",
attr: {
role: "option",
tabindex: "0",
"aria-selected": l ? "true" : "false",
"aria-posinset": String(a + 1),
"aria-setsize": String(e.length),
},
});
l && c.addClass("active");
let d =
typeof i.title == "string"
? i.title
: typeof i.file_name == "string"
? i.file_name
: "(untitled)";
c.createEl("div", { cls: "paperforge-search-result-title", text: d });
let f = typeof i.zotero_key == "string" ? i.zotero_key : "",
p =
typeof i.main_note_path == "string" && i.main_note_path
? i.main_note_path
: null,
m = typeof i.note_path == "string" && i.note_path ? i.note_path : null,
y = p || m;
if (!y && f) {
let b = this._getCachedIndex().find(
(E) =>
E !== null &&
typeof E == "object" &&
"zotero_key" in E &&
E.zotero_key === f
);
if (b && typeof b == "object") {
let E = b;
y =
typeof E.main_note_path == "string" && E.main_note_path
? E.main_note_path
: typeof E.note_path == "string" && E.note_path
? E.note_path
: null;
}
}
(y
? c.addEventListener("click", (_) => {
let b = _.ctrlKey || _.metaKey;
this.app.workspace.openLinkText(y, "", b);
})
: c.addEventListener("click", () => {
new I.Notice("[!!] Note not found: " + (f || "unknown"), 6e3);
}),
c.addEventListener("keydown", (_) => {
if (_.key === "Enter" && y) {
_.preventDefault();
let b = _.ctrlKey || _.metaKey;
this.app.workspace.openLinkText(y, "", b);
}
}));
let x = c.createEl("div", { cls: "paperforge-search-result-meta" });
if (
(typeof i.first_author == "string" &&
i.first_author &&
x.createEl("span", {
cls: "paperforge-search-result-author",
text: i.first_author,
}),
typeof i.journal == "string" &&
i.journal &&
x.createEl("span", {
cls: "paperforge-search-result-journal",
text: i.journal,
}),
i.score !== void 0)
) {
let _ = i.score,
b = typeof _ == "number" ? _.toFixed(3) : String(_);
x.createEl("span", {
cls: "paperforge-search-result-score",
text: "Score: " + b,
});
}
if (
(typeof i.domain == "string" &&
i.domain &&
c.createEl("span", {
cls: "paperforge-search-result-tag",
text: i.domain,
}),
typeof i.abstract == "string" && i.abstract)
) {
let _ = i.abstract;
c.createEl("div", {
cls: "paperforge-search-result-abstract",
text: _.length > 200 ? _.slice(0, 200) + "..." : _,
});
}
if (t && typeof i.text == "string" && i.text) {
let _ = i.text;
c.createEl("div", {
cls: "paperforge-search-result-source",
text: _.length > 300 ? _.slice(0, 300) + "..." : _,
});
}
}
}
_renderSearchError(e) {
this._searchResultsEl &&
(this._searchResultsEl.empty(),
this._searchResultsEl.createEl("div", {
cls: "paperforge-search-error",
text: e,
}));
}
_runAction(e, t) {
var p, m;
if (e.disabled) {
new I.Notice(
`[i] ${e.disabledMsg || "This action is not yet available."}`,
6e3
);
return;
}
if (t.classList.contains("running")) return;
t.addClass("running");
let r = this.app.vault.adapter.basePath;
this._showMessage("Processing...", "running");
let n = Array.isArray(e.args) ? [...e.args] : [];
if (e.needsKey) {
let y = this.app.workspace.getActiveFile(),
x = null;
if (y) {
let _ = this.app.metadataCache.getFileCache(y);
if (
(_ && _.frontmatter && _.frontmatter.zotero_key
? (x = _.frontmatter.zotero_key)
: (x = this._extractZoteroKeyFromPath(y.path)),
x)
)
n = [...n, x];
else if (_ && _.frontmatter) {
(this._showMessage(
"[!!] No zotero_key in active note frontmatter",
"error"
),
new I.Notice(
"[!!] Open a paper note with a zotero_key in its frontmatter first",
6e3
),
t.removeClass("running"));
return;
} else {
(this._showMessage("[!!] No frontmatter in active note", "error"),
new I.Notice(
"[!!] The active note has no frontmatter with a zotero_key",
6e3
),
t.removeClass("running"));
return;
}
} else {
(this._showMessage("[!!] No active note open", "error"),
new I.Notice(
"[!!] Open a paper note with a zotero_key in its frontmatter first",
6e3
),
t.removeClass("running"));
return;
}
}
e.needsFilter && (n = [...n, "--all"]);
let a = e.needsFilter ? 6e4 : e.needsKey ? 3e4 : 6e5,
{ path: s, extraArgs: i = [] } = N(
r,
(m =
(p = this.app.plugins.plugins.paperforge) == null
? void 0
: p.settings) != null
? m
: null,
void 0,
void 0
),
l = (0, _e.spawn)(s, [...i, "-m", "paperforge", e.cmd, ...n], {
cwd: r,
timeout: a,
}),
c = [],
d = Date.now(),
f = setInterval(() => this._fetchStats(!0), 4e3);
(l.stdout.on("data", (y) => {
let x = y
.toString("utf-8")
.split(
`
`
)
.filter(Boolean);
for (let _ of x) {
let b = _.trim();
b &&
(c.push(b),
this._showMessage(
c.slice(-8).join(`
`),
"running"
));
}
}),
l.stderr.on("data", (y) => {
let x = y
.toString("utf-8")
.split(
`
`
)
.filter(Boolean);
for (let _ of x) {
if (_.includes("\r") || _.includes("%") || _.includes("\u2588"))
continue;
let b = _.trim();
b &&
!b.match(/^\d+%|^\|/) &&
(c.push(b),
this._showMessage(
c.slice(-8).join(`
`),
"running"
));
}
}),
l.on("close", (y) => {
(clearInterval(f), t.removeClass("running"));
let x = ((Date.now() - d) / 1e3).toFixed(1);
if (y !== 0) {
let _ = c.slice(-3).join(" | ") || "exit code " + y;
(e.cmd === "repair" || e.cmd === "ocr") && y === 1
? (this._showMessage("[WARN] " + _, "running"),
new I.Notice("[WARN] " + e.cmd + " partial: " + _, 8e3),
this._fetchStats(!0))
: (this._showMessage("[!!] " + _, "error"),
new I.Notice("[!!] " + e.cmd + " failed: " + _, 8e3));
} else if (e.needsKey || e.needsFilter) {
let _ = c.join(`
`);
if (_.trim())
try {
(JSON.parse(_),
navigator.clipboard
.writeText(_)
.then(() => {
let b = `${x}s \u2014 ${_.length} chars copied`;
(this._showMessage("[OK] " + e.title + ": " + b, "ok"),
new I.Notice(
"[OK] " + e.okMsg + " \u2014 " + _.length + " chars"
));
})
.catch((b) => {
(this._showMessage(
"[!!] Clipboard write failed: " + b.message,
"error"
),
new I.Notice("[!!] Clipboard error", 6e3));
}));
} catch (b) {
(this._showMessage("[!!] Invalid JSON from " + e.title, "error"),
new I.Notice(
"[!!] " +
e.title +
" returned invalid JSON: " +
b.message.slice(0, 100),
8e3
));
}
else
(this._showMessage("[!!] No output from context command", "error"),
new I.Notice("[!!] Context command returned empty output", 8e3));
this._fetchStats(!0);
} else {
let b =
c.filter((k) => k.match(/updated \d+/)).pop() ||
c[c.length - 1] ||
"",
E = `${x}s \u2014 ${b}`;
(this._showMessage("[OK] " + e.title + ": " + E, "ok"),
new I.Notice("[OK] " + e.okMsg),
this._contentEl && this._contentEl.removeClass("switching"),
(this._cachedStats = null));
try {
this._fetchStats(!1);
} catch (k) {
console.log("[PF] fetchStats error:", k);
}
(console.log("[PF] close cmd=" + e.cmd + " id=" + e.id),
e.cmd === "sync" &&
ze(this.app, this.app.plugins.plugins.paperforge, r));
}
}),
l.on("error", (y) => {
(t.removeClass("running"),
this._contentEl && this._contentEl.removeClass("switching"),
this._showMessage("[!!] " + y.message, "error"),
new I.Notice("[!!] Cannot start: " + y.message, 8e3));
}));
}
_showMessage(e, t) {
this._messageEl &&
(this._messageEl.setText(e),
(this._messageEl.className = `paperforge-message msg-${t}`));
}
_renderModeHeader(e) {
if (!this._modeContextEl) return;
this._modeContextEl.empty();
let t = this._modeContextEl.createEl("span", {
cls: "paperforge-mode-badge",
}),
r = "";
switch (e) {
case "global":
(t.addClass("global"),
t.setText("Global"),
this._headerTitle && this._headerTitle.setText("PaperForge"));
break;
case "paper":
(t.addClass("paper"),
t.setText("Paper"),
this._headerTitle && this._headerTitle.setText("Paper"),
this._currentPaperEntry && this._currentPaperEntry.title
? (r = this._currentPaperEntry.title)
: this._currentPaperKey
? ((r = this._currentPaperKey),
this._modeContextEl.createEl("span", {
cls: "paperforge-mode-warning",
text: "Not found in index",
}))
: (r = "Unknown paper"));
break;
case "collection":
(t.addClass("collection"),
t.setText("Collection"),
this._headerTitle && this._headerTitle.setText("Collection"),
(r = this._currentDomain || "Unknown Domain"));
break;
case "versions":
(t.addClass("versions"),
t.setText(o("version_panel_title")),
this._headerTitle &&
this._headerTitle.setText(o("version_panel_title")));
break;
}
r &&
this._modeContextEl.createEl("span", {
cls: "paperforge-mode-name",
text: r,
});
}
_setupEventSubscriptions() {
let e = this.app.workspace.on("active-leaf-change", () => {
(this._leafChangeTimer && clearTimeout(this._leafChangeTimer),
(this._leafChangeTimer = setTimeout(() => {
let r = this._resolveModeForFile(this.app.workspace.getActiveFile()),
n = r.mode,
a = r.filePath;
(this._currentMode === n && this._currentFilePath === a) ||
this._detectAndSwitch();
}, 300)));
});
this._modeSubscribers.push({ event: "active-leaf-change", ref: e });
let t = this.app.vault.on("modify", (r) => {
r &&
r.path &&
r.path.endsWith("formal-library.json") &&
(this._invalidateIndex(), this._refreshCurrentMode());
});
this._modeSubscribers.push({ event: "modify", ref: t });
}
static async open(e) {
let t = e.app.workspace.getLeavesOfType(ve);
if (t.length > 0) {
e.app.workspace.revealLeaf(t[0]);
return;
}
let r = e.app.workspace.getRightLeaf(!1);
r &&
(await r.setViewState({ type: ve, active: !0 }),
e.app.workspace.revealLeaf(r));
}
};
var Ke = class extends U.Plugin {
constructor() {
super(...arguments);
this._lastExportMtime = 0;
this._lastOcrMtimes = {};
this._autoSyncRunning = !1;
this._lastSyncTime = null;
this._pollTimer = null;
this._embedProcess = null;
this._embedProgress = { current: 0, total: 0, key: "" };
this._embedStderr = "";
this._memoryStatusText = null;
}
async onload() {
(await this.loadSettings(),
this.saveSettings(),
lt(this.app),
this.registerView(ve, (t) => new we(t)));
try {
(0, U.addIcon)(Fe, it);
} catch (t) {}
(this.addRibbonIcon(Fe, "PaperForge Dashboard", () => we.open(this)),
se.find((t) => t.id === "paperforge-ocr-redo") &&
this.addRibbonIcon("reset", "PaperForge: Redo OCR", () => {
let t = this.app.vault.adapter.basePath;
new U.Notice("PaperForge: Redo OCR starting...");
let { path: r, extraArgs: n } = N(t, this.settings, void 0, void 0);
(0, pe.execFile)(
r,
[...n, "-m", "paperforge", "ocr", "redo"],
{ cwd: t, timeout: 6e5 },
(a, s, i) => {
if (a) {
new U.Notice("PaperForge: Redo OCR failed");
return;
}
new U.Notice("PaperForge: Redo OCR done");
}
);
}),
this.addSettingTab(new He(this.app, this)),
this.addCommand({
id: "paperforge-status-panel",
name: `PaperForge: ${o("guide_open")}`,
callback: () => we.open(this),
}));
for (let t of se)
this.addCommand({
id: t.id,
name: `PaperForge: ${t.title}`,
callback: () => {
if (t.disabled) {
new U.Notice(
`[i] ${t.disabledMsg || "This action is not yet available."}`,
6e3
);
return;
}
let r = this.app.vault.adapter.basePath;
new U.Notice(`PaperForge: running ${t.cmd}...`);
let { path: n, extraArgs: a = [] } = N(
r,
this.settings,
void 0,
void 0
),
s = Array.isArray(t.args) ? [...t.args] : [];
(0, pe.execFile)(
n,
[...a, "-m", "paperforge", t.cmd, ...s],
{ cwd: r, timeout: 3e5 },
(i, l, c) => {
if (i) {
new U.Notice(
`[!!] ${t.cmd} failed: ${(c || i.message).slice(0, 120)}`,
8e3
);
return;
}
new U.Notice(
`[OK] ${
t.okMsg ||
l
.trim()
.split(
`
`
)[0]
.slice(0, 80)
}`
);
}
);
},
});
(this.settings.auto_update_on_startup === !0 &&
this.settings.setup_complete &&
setTimeout(() => this._autoUpdate(), 3e3),
this._startFilePolling(),
this._firstLaunchSnapshotMigration(),
this._checkReleaseNotes());
}
_firstLaunchSnapshotMigration() {
let e = this.app.vault.adapter.basePath;
if (!e) return;
let r = ne(e).memoryStatePath;
if (!W.existsSync(r)) {
let n = N(e, this.settings, void 0, void 0);
[
["runtime-health", "--json"],
["memory", "status", "--json"],
["embed", "status", "--json"],
].forEach((s) => {
let i = [...n.extraArgs, "-m", "paperforge", "--vault", e, ...s];
(0, pe.execFile)(
n.path,
i,
{ cwd: e, timeout: 6e4, windowsHide: !0 },
() => {}
);
});
}
}
_autoUpdate() {
let e = this.app.vault.adapter.basePath,
{ path: t, extraArgs: r = [] } = N(e, this.settings, void 0, void 0),
n = this.manifest.version,
a = `paperforge==${n}`,
s = `git+https://github.com/LLLin000/PaperForge.git@${n}`,
i = (l, c) => {
(0, pe.spawn)(t, [...r, "-m", "pip", "install", "--upgrade", l], {
cwd: e,
timeout: 12e4,
env: be(),
}).on("close", (f) => c(f === 0));
};
(0, pe.execFile)(
t,
[...r, "-c", "import paperforge; print(paperforge.__version__)"],
{ cwd: e, timeout: 1e4 },
(l, c) => {
let d = (p) => {
(console.log(
`[PaperForge] Auto-update: trying PyPI (paperforge==${n})`
),
i(a, (m) => {
if (m) {
(console.log("[PaperForge] Auto-update: installed via PyPI"),
new U.Notice(`[OK] PaperForge CLI ${p}`, 5e3));
return;
}
(console.warn(
"[PaperForge] Auto-update: PyPI failed, falling back to git..."
),
i(s, (y) => {
y &&
(console.log("[PaperForge] Auto-update: installed via git"),
new U.Notice(`[OK] PaperForge CLI ${p} (via git)`, 5e3));
}));
}));
};
if (l) {
d("installed");
return;
}
let f = c.trim();
f !== n && d(`${f} -> ${n}`);
}
);
}
_startFilePolling() {
let e = this.app.vault.adapter.basePath;
this._pollTimer = setInterval(() => {
(this._checkExports(e), this._checkOcr(e));
}, 12e4);
}
_checkExports(e) {
if (this._autoSyncRunning) return;
let t = ne(e).exportsDir;
if (!W.existsSync(t)) return;
let r = 0;
try {
W.readdirSync(t).forEach((n) => {
if (!n.endsWith(".json")) return;
let a = W.statSync(Se.join(t, n));
a.mtimeMs > r && (r = a.mtimeMs);
});
} catch (n) {
return;
}
r > this._lastExportMtime &&
((this._lastExportMtime = r), this._autoSync(e));
}
_autoSync(e) {
if (this._autoSyncRunning) return;
this._autoSyncRunning = !0;
let t = N(e, this.settings, void 0, void 0);
if (!t.path) {
this._autoSyncRunning = !1;
return;
}
let r = `"${t.path}" -m paperforge --vault "${e}" sync`;
(0, pe.exec)(r, { timeout: 12e4, encoding: "utf-8" }, (n, a, s) => {
((this._autoSyncRunning = !1),
(this._memoryStatusText = null),
n || (this._lastSyncTime = new Date().toLocaleTimeString()));
try {
let i = ne(e).exportsDir,
l = 0;
(W.readdirSync(i).forEach((c) => {
c.endsWith(".json") &&
(l = Math.max(l, W.statSync(Se.join(i, c)).mtimeMs));
}),
(this._lastExportMtime = l));
} catch (i) {}
});
}
_checkOcr(e) {
if (this._autoSyncRunning) return;
let t = ne(e).ocrDir;
if (W.existsSync(t))
try {
W.readdirSync(t, { withFileTypes: !0 }).forEach((r) => {
if (!r.isDirectory()) return;
let n = Se.join(t, r.name, "meta.json");
if (!W.existsSync(n)) return;
let a = W.statSync(n),
s = this._lastOcrMtimes[r.name] || 0;
if (
a.mtimeMs <= s ||
((this._lastOcrMtimes[r.name] = a.mtimeMs), this._autoSyncRunning)
)
return;
this._autoSyncRunning = !0;
let i = N(e, this.settings, void 0, void 0);
if (!i.path) {
this._autoSyncRunning = !1;
return;
}
let l = `"${i.path}" -m paperforge --vault "${e}" sync`;
(0, pe.exec)(l, { timeout: 3e4, encoding: "utf-8" }, () => {
((this._autoSyncRunning = !1), (this._memoryStatusText = null));
});
});
} catch (r) {}
}
readPaperforgeJson() {
let e = this.app.vault.adapter.basePath,
t = Se.join(e, "paperforge.json"),
r = {
system_dir: "System",
resources_dir: "Resources",
literature_dir: "Literature",
base_dir: "Bases",
};
try {
if (!W.existsSync(t)) return r;
let n = W.readFileSync(t, "utf-8"),
a = JSON.parse(n),
s = a.vault_config || {};
return {
system_dir: s.system_dir || a.system_dir || r.system_dir,
resources_dir: s.resources_dir || a.resources_dir || r.resources_dir,
literature_dir:
s.literature_dir || a.literature_dir || r.literature_dir,
base_dir: s.base_dir || a.base_dir || r.base_dir,
};
} catch (n) {
return (
console.warn(
"PaperForge: Failed to read paperforge.json, using defaults",
n
),
r
);
}
}
savePaperforgeJson(e) {
let t = this.app.vault.adapter.basePath,
r = Se.join(t, "paperforge.json"),
n = {};
try {
W.existsSync(r) && (n = JSON.parse(W.readFileSync(r, "utf-8")));
} catch (s) {
console.warn("PaperForge: Failed to read paperforge.json for update", s);
}
(!n.vault_config || typeof n.vault_config != "object") &&
(n.vault_config = {});
let a = ["system_dir", "resources_dir", "literature_dir", "base_dir"];
for (let s of a) e[s] !== void 0 && (n.vault_config[s] = e[s]);
n.schema_version || (n.schema_version = "2");
for (let s of a) delete n[s];
try {
if (
(W.writeFileSync(r, JSON.stringify(n, null, 2), "utf-8"), this.settings)
) {
let s = this.readPaperforgeJson();
((this.settings.system_dir = s.system_dir),
(this.settings.resources_dir = s.resources_dir),
(this.settings.literature_dir = s.literature_dir),
(this.settings.base_dir = s.base_dir));
}
} catch (s) {
(console.error("PaperForge: Failed to write paperforge.json", s),
new U.Notice(
"PaperForge: Failed to save configuration to paperforge.json"
));
}
}
onunload() {
(this._pollTimer && clearInterval(this._pollTimer),
this.app.workspace.detachLeavesOfType(ve));
}
async loadSettings() {
((this.settings = Object.assign({}, Re, await this.loadData())),
this.settings.features &&
Re.features &&
(this.settings.features = Object.assign(
{},
Re.features,
this.settings.features || {}
)),
this.settings.frozen_skills || (this.settings.frozen_skills = {}));
let e = this.readPaperforgeJson();
if (
((this.settings.system_dir = e.system_dir),
(this.settings.resources_dir = e.resources_dir),
(this.settings.literature_dir = e.literature_dir),
(this.settings.base_dir = e.base_dir),
this.settings.python_path && this.settings.python_path.trim())
) {
let t = this.settings.python_path.trim();
W.existsSync(t)
? (this.settings._python_path_stale = !1)
: (console.warn(
`PaperForge: Saved python_path "${t}" no longer exists - showing stale warning`
),
(this.settings._python_path_stale = !0));
}
}
async saveSettings() {
let e = {};
for (let t of Object.keys(Re))
t in this.settings && (e[t] = this.settings[t]);
await this.saveData(e);
}
_checkReleaseNotes() {
let e = this.manifest.version;
if (this.settings.last_seen_version === e) return;
let a = (Je().versions || []).find((i) => i.version === e);
class s extends U.Modal {
constructor(l, c) {
(super(l), (this._entry = c));
}
onOpen() {
let { contentEl: l } = this;
if (
(l.createEl("h2", {
text: `PaperForge v${e} \u66F4\u65B0\u8BF4\u660E`,
}),
this._entry)
) {
if (
(l.createEl("p", {
text: this._entry.title,
cls: "paperforge-modal-subtitle",
}),
this._entry.breaking_or_migration &&
this._entry.breaking_or_migration.length > 0)
) {
l.createEl("h4", {
text: "\u884C\u4E3A\u53D8\u66F4 / \u8FC1\u79FB\u6CE8\u610F",
});
for (let c of this._entry.breaking_or_migration)
l.createEl("p", {
text: `\u2022 ${c}`,
cls: "paperforge-modal-item",
});
}
if (this._entry.new_features && this._entry.new_features.length > 0) {
l.createEl("h4", { text: "\u65B0\u529F\u80FD" });
for (let c of this._entry.new_features)
l.createEl("p", {
text: `\u2022 ${c}`,
cls: "paperforge-modal-item",
});
}
if (this._entry.fixes && this._entry.fixes.length > 0) {
l.createEl("h4", { text: "\u4FEE\u590D" });
for (let c of this._entry.fixes)
l.createEl("p", {
text: `\u2022 ${c}`,
cls: "paperforge-modal-item",
});
}
if (
this._entry.recommended_actions &&
this._entry.recommended_actions.length > 0
) {
let c = l.createEl("div", {
cls: "paperforge-release-recommended",
});
(c.createEl("h4", { text: "\u5EFA\u8BAE\u64CD\u4F5C", cls: "" }),
(c.style.marginBottom = "8px"));
for (let d of this._entry.recommended_actions)
c.createEl("p", {
text: `\u2022 ${d}`,
cls: "paperforge-release-item-bold",
});
}
} else
l.createEl("p", {
text:
"\u7248\u672C\u5DF2\u66F4\u65B0\u81F3 v" +
e +
"\uFF0C\u8BF7\u524D\u5F80\u8BBE\u7F6E \u2192 \u66F4\u65B0\u4E0E\u624B\u518C \u67E5\u770B\u5B8C\u6574\u66F4\u65B0\u8BB0\u5F55\u3002",
});
new U.Setting(l).addButton((c) =>
c
.setButtonText("\u77E5\u9053\u4E86")
.setCta()
.onClick(() => {
this.close();
})
);
}
onClose() {
let { contentEl: l } = this;
l.empty();
}
}
(new s(this.app, a).open(),
(this.settings.last_seen_version = e),
this.saveSettings());
}
};