codex-overleaf-link 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +272 -311
- package/README.zh-CN.md +287 -326
- package/extension/bootstrap/background.js +47 -10
- package/extension/bootstrap/manifest.template.json +9 -4
- package/extension/bootstrap/popup.html +10 -16
- package/extension/bootstrap/update.js +25 -2
- package/extension/runtime-manifest.json +3 -1
- package/extension/src/background.js +28 -3
- package/extension/src/backgroundSharedSessions.js +380 -0
- package/extension/src/backgroundUpdateCoordinator.js +442 -379
- package/extension/src/content/activeTurnControl.js +8 -0
- package/extension/src/content/assetTransferBroker.js +186 -12
- package/extension/src/content/changeHistoryView.js +175 -0
- package/extension/src/content/composerAttachments.js +24 -22
- package/extension/src/content/composerPanel.js +23 -8
- package/extension/src/content/contentRuntime.js +572 -571
- package/extension/src/content/diagnosticsController.js +1 -2
- package/extension/src/content/diagnosticsExport.js +222 -0
- package/extension/src/content/diagnosticsPanel.js +48 -19
- package/extension/src/content/diffReviewPanel.js +8 -5
- package/extension/src/content/generated/content.bundle.js +8974 -1781
- package/extension/src/content/generated/content.bundle.meta.json +22 -3
- package/extension/src/content/legacyGlobalRegistry.js +19 -1
- package/extension/src/content/localSkillsPanel.js +42 -7
- package/extension/src/content/markdownDomRenderer.js +9 -4
- package/extension/src/content/modelPicker.js +1 -1
- package/extension/src/content/pageBridgeClient.js +18 -3
- package/extension/src/content/panelMaintenance.js +51 -120
- package/extension/src/content/panelRenderer.js +4 -0
- package/extension/src/content/pendingInputView.js +109 -76
- package/extension/src/content/providerSettingsCoordinator.js +17 -6
- package/extension/src/content/providerSettingsDialog.js +661 -108
- package/extension/src/content/recentProjects.js +364 -356
- package/extension/src/content/runActivitySummary.js +631 -0
- package/extension/src/content/runController.js +3 -1
- package/extension/src/content/runFailureNotice.js +14 -1
- package/extension/src/content/runGuidanceController.js +4 -3
- package/extension/src/content/runPresence.js +306 -0
- package/extension/src/content/runQueueScheduler.js +2 -1
- package/extension/src/content/runResultActions.js +123 -3
- package/extension/src/content/runTimelineView.js +194 -164
- package/extension/src/content/scopedPersistenceCoordinator.js +2 -1
- package/extension/src/content/scopedPersistencePanelState.js +45 -2
- package/extension/src/content/selectionContextView.js +300 -0
- package/extension/src/content/sessionPersistence.js +10 -2
- package/extension/src/content/settingsPanel.js +93 -54
- package/extension/src/content/settingsWorkbench.js +374 -0
- package/extension/src/content/sharedSessionViewSync.js +72 -0
- package/extension/src/content/subagentActivityView.js +195 -0
- package/extension/src/content/trackedChangeCaptureController.js +7 -3
- package/extension/src/content/updateNotice.js +121 -50
- package/extension/src/content/writebackController.js +257 -0
- package/extension/src/content/writebackOrchestrator.js +146 -141
- package/extension/src/content/writebackPlan.js +231 -0
- package/extension/src/content/writebackRecovery.js +122 -0
- package/extension/src/content/writingStyleSettings.js +576 -0
- package/extension/src/content/writtenChangesView.js +152 -0
- package/extension/src/page/binaryAssetUploader.js +97 -19
- package/extension/src/page/overleafProjectSnapshot.js +1 -0
- package/extension/src/page/referenceProjects.js +148 -0
- package/extension/src/page/saveState.js +58 -3
- package/extension/src/page/snapshotRouter.js +44 -13
- package/extension/src/page/textCoordinates.js +102 -0
- package/extension/src/page/textFileCreator.js +350 -59
- package/extension/src/page/trackedChangeCapture.js +42 -56
- package/extension/src/page/trackedChangeOwnership.js +198 -0
- package/extension/src/page/trackedChangeReplay.js +164 -0
- package/extension/src/page/trackedChangesLifecycle.js +139 -150
- package/extension/src/page/treeOperations.js +36 -29
- package/extension/src/page/writebackReceiptJournal.js +112 -0
- package/extension/src/page/writebackRouter.js +176 -136
- package/extension/src/pageBridge.js +59 -101
- package/extension/src/popup.js +203 -59
- package/extension/src/shared/agentTranscript.js +18 -4
- package/extension/src/shared/auditRecords.js +71 -0
- package/extension/src/shared/changeHistoryModel.js +94 -0
- package/extension/src/shared/compatibility.js +1 -1
- package/extension/src/shared/compileAdapter.js +42 -0
- package/extension/src/shared/failureReasons.js +20 -0
- package/extension/src/shared/globalPreferences.js +1 -1
- package/extension/src/shared/i18n.js +187 -65
- package/extension/src/shared/managedUpdateProjection.js +6 -3
- package/extension/src/shared/pageRpcContract.js +7 -1
- package/extension/src/shared/providerProfiles.js +109 -0
- package/extension/src/shared/runActivityModel.js +361 -0
- package/extension/src/shared/runExecutionSnapshot.js +8 -2
- package/extension/src/shared/runExecutionSnapshotCodec.js +16 -4
- package/extension/src/shared/scopedPersistenceBrowserAdapter.js +6 -3
- package/extension/src/shared/selectionContext.js +28 -0
- package/extension/src/shared/sessionState.js +97 -6
- package/extension/src/shared/sharedSessionBridge.js +288 -0
- package/extension/src/shared/storageDb.js +23 -55
- package/extension/src/shared/storageMigration.js +3 -0
- package/extension/src/shared/storageRunActions.js +54 -4
- package/extension/src/shared/storageValuePruning.js +40 -0
- package/extension/src/shared/subagentActivityModel.js +174 -0
- package/extension/src/shared/undoOperations.js +87 -0
- package/extension/src/shared/updateConsent.js +37 -8
- package/extension/src/shared/writebackIntent.js +62 -0
- package/extension/src/shared/writebackSettlement.js +29 -10
- package/extension/src/shared/writingStyle.js +33 -0
- package/extension/styles/panel.css +2136 -744
- package/extension/styles/popup.css +110 -0
- package/native-host/src/anthropicBridgeRequest.js +2 -1
- package/native-host/src/codexModelRecovery.js +107 -0
- package/native-host/src/codexPromptAssembly.js +2 -0
- package/native-host/src/codexProviderLaunch.js +3 -3
- package/native-host/src/codexRuntimeIdentity.js +1 -0
- package/native-host/src/codexSessionRunner.js +146 -177
- package/native-host/src/codexSessionTiming.js +71 -0
- package/native-host/src/managedInstall.js +5 -4
- package/native-host/src/nativeEnvironment.js +70 -0
- package/native-host/src/nativeQuotas.js +15 -8
- package/native-host/src/overleafWorkspaceRules.js +16 -0
- package/native-host/src/processStopBarrier.js +80 -0
- package/native-host/src/providerModelCatalog.js +4 -3
- package/native-host/src/providerProfile.js +13 -1
- package/native-host/src/providerReasoning.js +9 -5
- package/native-host/src/providerStore.js +4 -0
- package/native-host/src/readProgressGuard.js +84 -17
- package/native-host/src/releaseTransport.js +14 -5
- package/native-host/src/selectionScope.js +58 -0
- package/native-host/src/skills/parallel-subagents/SKILL.md +31 -3
- package/native-host/src/skills/writing-style-builder/SKILL.md +146 -0
- package/native-host/src/subagentBroker.js +102 -98
- package/native-host/src/subagentTelemetry.js +316 -0
- package/native-host/src/subagentWorkspace.js +103 -0
- package/native-host/src/subagentWorkspacePath.js +31 -0
- package/native-host/src/taskRunnerRuntime.js +55 -5
- package/native-host/src/turnAttachments.js +113 -0
- package/native-host/src/updateManager.js +122 -12
- package/native-host/src/updateNetworkControl.js +75 -0
- package/native-host/src/updateTrust.js +21 -2
- package/native-host/src/vendor/pdfjs/LICENSE +177 -0
- package/native-host/src/vendor/pdfjs/SOURCE.txt +3 -0
- package/native-host/src/vendor/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/78-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/78-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Add-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Add-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/B5-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/B5-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/B5pc-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/B5pc-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/CNS1-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/CNS1-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/CNS2-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/CNS2-V.bcmap +3 -0
- package/native-host/src/vendor/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
- package/native-host/src/vendor/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Ext-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Ext-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GB-H.bcmap +4 -0
- package/native-host/src/vendor/pdfjs/cmaps/GB-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBT-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBT-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Hankaku.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Hiragana.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Katakana.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/LICENSE +36 -0
- package/native-host/src/vendor/pdfjs/cmaps/NWP-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/NWP-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/Roman.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/V.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
- package/native-host/src/vendor/pdfjs/pdf.mjs +26740 -0
- package/native-host/src/vendor/pdfjs/pdf.worker.mjs +62201 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/LICENSE_LIBERATION +102 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
- package/native-host/src/vendor/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
- package/native-host/src/writingStyleEvidence.js +102 -0
- package/native-host/src/writingStylePdfWorker.js +35 -0
- package/native-host/src/writingStyleProfile.js +165 -0
- package/native-host/src/writingStyleRuntime.js +447 -0
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright 2014 PDFium Authors. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Redistribution and use in source and binary forms, with or without
|
|
4
|
+
// modification, are permitted provided that the following conditions are
|
|
5
|
+
// met:
|
|
6
|
+
//
|
|
7
|
+
// * Redistributions of source code must retain the above copyright
|
|
8
|
+
// notice, this list of conditions and the following disclaimer.
|
|
9
|
+
// * Redistributions in binary form must reproduce the above
|
|
10
|
+
// copyright notice, this list of conditions and the following disclaimer
|
|
11
|
+
// in the documentation and/or other materials provided with the
|
|
12
|
+
// distribution.
|
|
13
|
+
// * Neither the name of Google Inc. nor the names of its
|
|
14
|
+
// contributors may be used to endorse or promote products derived from
|
|
15
|
+
// this software without specific prior written permission.
|
|
16
|
+
//
|
|
17
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
21
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
22
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
23
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
24
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
25
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Digitized data copyright (c) 2010 Google Corporation
|
|
2
|
+
with Reserved Font Arimo, Tinos and Cousine.
|
|
3
|
+
Copyright (c) 2012 Red Hat, Inc.
|
|
4
|
+
with Reserved Font Name Liberation.
|
|
5
|
+
|
|
6
|
+
This Font Software is licensed under the SIL Open Font License,
|
|
7
|
+
Version 1.1.
|
|
8
|
+
|
|
9
|
+
This license is copied below, and is also available with a FAQ at:
|
|
10
|
+
http://scripts.sil.org/OFL
|
|
11
|
+
|
|
12
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
13
|
+
|
|
14
|
+
PREAMBLE The goals of the Open Font License (OFL) are to stimulate
|
|
15
|
+
worldwide development of collaborative font projects, to support the font
|
|
16
|
+
creation efforts of academic and linguistic communities, and to provide
|
|
17
|
+
a free and open framework in which fonts may be shared and improved in
|
|
18
|
+
partnership with others.
|
|
19
|
+
|
|
20
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
21
|
+
redistributed freely as long as they are not sold by themselves.
|
|
22
|
+
The fonts, including any derivative works, can be bundled, embedded,
|
|
23
|
+
redistributed and/or sold with any software provided that any reserved
|
|
24
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
25
|
+
however, cannot be released under any other type of license. The
|
|
26
|
+
requirement for fonts to remain under this license does not apply to
|
|
27
|
+
any document created using the fonts or their derivatives.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
DEFINITIONS
|
|
32
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
33
|
+
Holder(s) under this license and clearly marked as such.
|
|
34
|
+
This may include source files, build scripts and documentation.
|
|
35
|
+
|
|
36
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
37
|
+
copyright statement(s).
|
|
38
|
+
|
|
39
|
+
"Original Version" refers to the collection of Font Software components
|
|
40
|
+
as distributed by the Copyright Holder(s).
|
|
41
|
+
|
|
42
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
43
|
+
or substituting ? in part or in whole ?
|
|
44
|
+
any of the components of the Original Version, by changing formats or
|
|
45
|
+
by porting the Font Software to a new environment.
|
|
46
|
+
|
|
47
|
+
"Author" refers to any designer, engineer, programmer, technical writer
|
|
48
|
+
or other person who contributed to the Font Software.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
PERMISSION & CONDITIONS
|
|
52
|
+
|
|
53
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
54
|
+
copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
55
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
56
|
+
Software, subject to the following conditions:
|
|
57
|
+
|
|
58
|
+
1) Neither the Font Software nor any of its individual components,in
|
|
59
|
+
Original or Modified Versions, may be sold by itself.
|
|
60
|
+
|
|
61
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
62
|
+
redistributed and/or sold with any software, provided that each copy
|
|
63
|
+
contains the above copyright notice and this license. These can be
|
|
64
|
+
included either as stand-alone text files, human-readable headers or
|
|
65
|
+
in the appropriate machine-readable metadata fields within text or
|
|
66
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
67
|
+
|
|
68
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
69
|
+
Name(s) unless explicit written permission is granted by the
|
|
70
|
+
corresponding Copyright Holder. This restriction only applies to the
|
|
71
|
+
primary font name as presented to the users.
|
|
72
|
+
|
|
73
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
74
|
+
Software shall not be used to promote, endorse or advertise any
|
|
75
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
76
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
77
|
+
permission.
|
|
78
|
+
|
|
79
|
+
5) The Font Software, modified or unmodified, in part or in whole, must
|
|
80
|
+
be distributed entirely under this license, and must not be distributed
|
|
81
|
+
under any other license. The requirement for fonts to remain under
|
|
82
|
+
this license does not apply to any document created using the Font
|
|
83
|
+
Software.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
TERMINATION
|
|
88
|
+
This license becomes null and void if any of the above conditions are not met.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
DISCLAIMER
|
|
93
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
94
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
95
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
96
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
97
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
98
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
99
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
100
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
|
|
101
|
+
DEALINGS IN THE FONT SOFTWARE.
|
|
102
|
+
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const MAX_EXAMPLE_CHARS = 1400;
|
|
4
|
+
const MAX_SECTION_EXAMPLE_CHARS = 3200;
|
|
5
|
+
const error = message => Object.assign(new Error(message), { code: 'writing_style_evidence_invalid' });
|
|
6
|
+
|
|
7
|
+
function balancedTex(text) {
|
|
8
|
+
let braces = 0, math = '';
|
|
9
|
+
const environments = [];
|
|
10
|
+
for (let index = 0; index < text.length; index++) {
|
|
11
|
+
const char = text[index];
|
|
12
|
+
if (char === '\\') {
|
|
13
|
+
const environment = /^\\(begin|end)\s*\{([a-zA-Z*]+)\}/.exec(text.slice(index));
|
|
14
|
+
if (environment) {
|
|
15
|
+
if (environment[1] === 'begin') environments.push(environment[2]);
|
|
16
|
+
else if (environments.pop() !== environment[2]) return false;
|
|
17
|
+
index += environment[0].length - 1;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const next = text[index + 1];
|
|
21
|
+
if (['\\', '{', '}', '$', '%'].includes(next)) { index++; continue; }
|
|
22
|
+
if (next === '(' || next === '[') {
|
|
23
|
+
if (math) return false;
|
|
24
|
+
math = '\\' + next; index++; continue;
|
|
25
|
+
}
|
|
26
|
+
if (next === ')' || next === ']') {
|
|
27
|
+
if (math !== (next === ')' ? '\\(' : '\\[')) return false;
|
|
28
|
+
math = ''; index++; continue;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (char === '{') braces++;
|
|
32
|
+
if (char === '}' && --braces < 0) return false;
|
|
33
|
+
if (char === '$') {
|
|
34
|
+
const delimiter = text[index + 1] === '$' ? '$$' : '$';
|
|
35
|
+
if (math && math !== delimiter) return false;
|
|
36
|
+
math = math ? '' : delimiter;
|
|
37
|
+
if (delimiter === '$$') index++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return braces === 0 && math === '' && environments.length === 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function resolveExample(example, documents) {
|
|
44
|
+
if (!example || typeof example !== 'object' || Array.isArray(example)) {
|
|
45
|
+
throw error('Return an example object containing source identity, quote, pattern, and application.');
|
|
46
|
+
}
|
|
47
|
+
const doc = documents.find(value => value.id === example.sourceId);
|
|
48
|
+
if (!doc || !Number.isInteger(example.fromLine) || !Number.isInteger(example.toLine)
|
|
49
|
+
|| example.fromLine < 1 || example.toLine < example.fromLine
|
|
50
|
+
|| example.toLine > doc.lines.length || example.toLine - example.fromLine > 60) {
|
|
51
|
+
throw error('Choose a valid source ID and a bounded corpus line range.');
|
|
52
|
+
}
|
|
53
|
+
const quote = typeof example.quote === 'string' ? example.quote.trim() : '';
|
|
54
|
+
if (quote.length < 60 || quote.length > MAX_EXAMPLE_CHARS) {
|
|
55
|
+
throw error('Choose a complete short excerpt between 60 and ' + MAX_EXAMPLE_CHARS + ' characters. Do not truncate it.');
|
|
56
|
+
}
|
|
57
|
+
for (const key of ['pattern', 'application']) {
|
|
58
|
+
if (typeof example[key] !== 'string' || example[key].trim().length < 12 || example[key].length > 400) {
|
|
59
|
+
throw error('Each excerpt needs a concise pattern and application note (12-400 characters each).');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const range = doc.lines.slice(example.fromLine - 1, example.toLine).join('\n');
|
|
63
|
+
const start = range.indexOf(quote);
|
|
64
|
+
if (start < 0) throw error('The quote must be an exact, contiguous passage from the cited corpus lines, without line-number prefixes.');
|
|
65
|
+
const isWord = value => Boolean(value) && /[\p{L}\p{N}]/u.test(value);
|
|
66
|
+
if (start > 0 && isWord(range[start - 1]) && isWord(quote[0])) {
|
|
67
|
+
throw error('The excerpt begins inside a word. Choose complete sentences.');
|
|
68
|
+
}
|
|
69
|
+
if (!/[.!?。!?]["'’”»)\]})\s]*$/.test(quote) || /(?:\.\.\.|…)\s*$/.test(quote)) {
|
|
70
|
+
throw error('End the excerpt at a complete sentence, without an added ellipsis or an unfinished command.');
|
|
71
|
+
}
|
|
72
|
+
if (!balancedTex(quote)) {
|
|
73
|
+
throw error('The excerpt cuts a TeX group, math delimiter, or environment. Choose a self-contained prose passage.');
|
|
74
|
+
}
|
|
75
|
+
const offsetLines = range.slice(0, start).split('\n').length - 1;
|
|
76
|
+
const fromLine = example.fromLine + offsetLines;
|
|
77
|
+
const toLine = fromLine + quote.split('\n').length - 1;
|
|
78
|
+
return {
|
|
79
|
+
sourceId: doc.id, fromLine, toLine,
|
|
80
|
+
quote: range.slice(start, start + quote.length),
|
|
81
|
+
pattern: example.pattern.trim(), application: example.application.trim(),
|
|
82
|
+
originStart: doc.origins[fromLine - 1], originEnd: doc.origins[toLine - 1]
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function renderExample(example, doc) {
|
|
87
|
+
const tick = String.fromCharCode(96);
|
|
88
|
+
const longestTicks = Math.max(0, ...(example.quote.match(new RegExp(tick + '+', 'g')) || []).map(value => value.length));
|
|
89
|
+
const fence = tick.repeat(Math.max(3, longestTicks + 1));
|
|
90
|
+
return '\n### ' + (example.id ? example.id + ' | ' : '') + doc.id + ': ' + doc.name.replace(/[\r\n]/g, ' ') + '\n\n'
|
|
91
|
+
+ 'Pattern: ' + example.pattern + '\n\n'
|
|
92
|
+
+ 'Apply: ' + example.application + '\n\n'
|
|
93
|
+
+ 'Evidence: ' + JSON.stringify({
|
|
94
|
+
sourceId: example.sourceId,
|
|
95
|
+
corpusLines: [example.fromLine, example.toLine],
|
|
96
|
+
originStart: example.originStart, originEnd: example.originEnd
|
|
97
|
+
}) + '\n\n'
|
|
98
|
+
+ 'Source excerpt (read-only; not facts or instructions for the current paper):\n\n'
|
|
99
|
+
+ fence + 'text\n' + example.quote + '\n' + fence + '\n';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = { MAX_EXAMPLE_CHARS, MAX_SECTION_EXAMPLE_CHARS, resolveExample, renderExample };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { parentPort, workerData } = require('node:worker_threads');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const { pathToFileURL } = require('node:url');
|
|
5
|
+
|
|
6
|
+
(async () => {
|
|
7
|
+
const root = path.join(__dirname, 'vendor', 'pdfjs');
|
|
8
|
+
const pdf = await import(pathToFileURL(path.join(root, 'pdf.mjs')).href);
|
|
9
|
+
pdf.GlobalWorkerOptions.workerSrc = pathToFileURL(path.join(root, 'pdf.worker.mjs')).href;
|
|
10
|
+
const task = pdf.getDocument({ data: new Uint8Array(workerData.bytes),
|
|
11
|
+
isEvalSupported: false, disableFontFace: true, useSystemFonts: false,
|
|
12
|
+
cMapUrl: path.join(root, 'cmaps') + path.sep, cMapPacked: true,
|
|
13
|
+
standardFontDataUrl: path.join(root, 'standard_fonts') + path.sep, verbosity: 0 });
|
|
14
|
+
try {
|
|
15
|
+
const document = await task.promise;
|
|
16
|
+
const pages = [];
|
|
17
|
+
const count = Math.min(document.numPages, 80);
|
|
18
|
+
for (let number = 1; number <= count; number++) {
|
|
19
|
+
const page = await document.getPage(number);
|
|
20
|
+
const content = await page.getTextContent();
|
|
21
|
+
let line = '', lines = [];
|
|
22
|
+
for (const item of content.items) {
|
|
23
|
+
if (typeof item.str !== 'string') continue;
|
|
24
|
+
line += item.str + (item.str.endsWith(' ') ? '' : ' ');
|
|
25
|
+
if (item.hasEOL) { lines.push(line.trim()); line = ''; }
|
|
26
|
+
}
|
|
27
|
+
if (line.trim()) lines.push(line.trim());
|
|
28
|
+
pages.push({ number, lines });
|
|
29
|
+
page.cleanup();
|
|
30
|
+
}
|
|
31
|
+
parentPort.postMessage({ ok: true, pages, totalPages: document.numPages });
|
|
32
|
+
} finally { await task.destroy(); }
|
|
33
|
+
})().catch(error => parentPort.postMessage({ ok: false,
|
|
34
|
+
error: String(error?.message || 'PDF text extraction failed.').slice(0, 300) }));
|
|
35
|
+
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { MAX_SECTION_EXAMPLE_CHARS, resolveExample, renderExample } = require('./writingStyleEvidence');
|
|
4
|
+
|
|
5
|
+
const SECTION_KEYS = new Set(['general', 'abstract', 'introduction', 'related-work', 'methods', 'results', 'discussion', 'proofs', 'conclusion']);
|
|
6
|
+
const DIMENSIONS = Object.freeze({
|
|
7
|
+
voice: 'Voice and stance',
|
|
8
|
+
syntax: 'Sentence construction',
|
|
9
|
+
rhythm: 'Sentence and paragraph rhythm',
|
|
10
|
+
diction: 'Word choice',
|
|
11
|
+
transitions: 'Connections between ideas',
|
|
12
|
+
explanation: 'Local explanation patterns'
|
|
13
|
+
});
|
|
14
|
+
const LANGUAGE_DIMENSIONS = new Set(['voice', 'syntax', 'rhythm', 'diction', 'transitions']);
|
|
15
|
+
const invalid = message => Object.assign(new Error(message), { code: 'writing_style_generation_invalid' });
|
|
16
|
+
|
|
17
|
+
function text(value, min, max, field) {
|
|
18
|
+
if (typeof value !== 'string' || value.trim().length < min || value.length > max) {
|
|
19
|
+
throw invalid(field + ' must contain ' + min + '-' + max + ' characters.');
|
|
20
|
+
}
|
|
21
|
+
return value.trim();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function identifier(value, field) {
|
|
25
|
+
const id = text(value, 1, 40, field);
|
|
26
|
+
if (!/^[a-z][a-z0-9-]*$/i.test(id)) throw invalid(field + ' must be a short letter-led identifier.');
|
|
27
|
+
return id;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function validate(input, documents) {
|
|
31
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) throw invalid('Return a writing-style profile object.');
|
|
32
|
+
if (typeof input.insufficientEvidence === 'string' && input.insufficientEvidence.trim()) {
|
|
33
|
+
throw Object.assign(new Error(input.insufficientEvidence.trim().slice(0, 500)), { code: 'writing_style_insufficient_evidence' });
|
|
34
|
+
}
|
|
35
|
+
if (Object.hasOwn(input, 'guide') || Object.hasOwn(input, 'domainNotes')) {
|
|
36
|
+
throw invalid('Use expression traits and evidenceLimits. Do not return a general paper-writing guide or field-convention rules.');
|
|
37
|
+
}
|
|
38
|
+
const label = text(input.label, 3, 100, 'label').replace(/[\r\n]/g, ' ');
|
|
39
|
+
const evidenceLimits = text(input.evidenceLimits, 20, 1200, 'evidenceLimits');
|
|
40
|
+
if (!Array.isArray(input.traits) || input.traits.length < 3 || input.traits.length > 8) {
|
|
41
|
+
throw invalid('Provide 3-8 supported expression traits, or report insufficientEvidence.');
|
|
42
|
+
}
|
|
43
|
+
if (!Array.isArray(input.sections) || !input.sections.length || input.sections.length > 6) {
|
|
44
|
+
throw invalid('Provide 1-6 section groups for locating evidence.');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const sections = [], sectionKeys = new Set(), examplesById = new Map(), quotes = new Set();
|
|
48
|
+
for (const section of input.sections) {
|
|
49
|
+
if (!section || !SECTION_KEYS.has(section.key) || sectionKeys.has(section.key)) {
|
|
50
|
+
throw invalid('Evidence groups need unique supported section keys.');
|
|
51
|
+
}
|
|
52
|
+
if (Object.hasOwn(section, 'guidance')) {
|
|
53
|
+
throw invalid('Section groups contain evidence only. Put expression observations in traits, not chapter-writing instructions.');
|
|
54
|
+
}
|
|
55
|
+
if (!Array.isArray(section.examples) || !section.examples.length || section.examples.length > 3) {
|
|
56
|
+
throw invalid('Each evidence group needs 1-3 short examples.');
|
|
57
|
+
}
|
|
58
|
+
sectionKeys.add(section.key);
|
|
59
|
+
const examples = section.examples.map(raw => {
|
|
60
|
+
const id = identifier(raw?.id, 'example.id');
|
|
61
|
+
if (examplesById.has(id)) throw invalid('Example identifiers must be unique across the profile.');
|
|
62
|
+
const resolved = resolveExample(raw, documents);
|
|
63
|
+
const quoteKey = resolved.sourceId + ':' + resolved.quote;
|
|
64
|
+
if (quotes.has(quoteKey)) throw invalid('Reuse an existing example ID instead of duplicating the same passage.');
|
|
65
|
+
quotes.add(quoteKey);
|
|
66
|
+
const example = { ...resolved, id, sectionKey: section.key };
|
|
67
|
+
examplesById.set(id, example);
|
|
68
|
+
return example;
|
|
69
|
+
});
|
|
70
|
+
if (examples.reduce((sum, example) => sum + example.quote.length, 0) > MAX_SECTION_EXAMPLE_CHARS) {
|
|
71
|
+
throw invalid('An evidence group may contain at most ' + MAX_SECTION_EXAMPLE_CHARS + ' quoted characters.');
|
|
72
|
+
}
|
|
73
|
+
sections.push({
|
|
74
|
+
key: section.key,
|
|
75
|
+
title: text(section.title || section.key, 1, 120, 'section.title').replace(/[\r\n]/g, ' '),
|
|
76
|
+
examples
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const ids = new Set(), usedExamples = new Set(), dimensions = new Set(), counts = new Map();
|
|
81
|
+
const traits = input.traits.map(raw => {
|
|
82
|
+
if (!raw || !Object.hasOwn(DIMENSIONS, raw.dimension)) throw invalid('Choose a supported language-style dimension.');
|
|
83
|
+
const id = identifier(raw.id, 'trait.id');
|
|
84
|
+
if (ids.has(id)) throw invalid('Style trait identifiers must be unique.');
|
|
85
|
+
ids.add(id);
|
|
86
|
+
dimensions.add(raw.dimension);
|
|
87
|
+
counts.set(raw.dimension, (counts.get(raw.dimension) || 0) + 1);
|
|
88
|
+
if (counts.get(raw.dimension) > 2) throw invalid('Use at most two traits per dimension; merge overlapping observations.');
|
|
89
|
+
if (!Array.isArray(raw.exampleIds) || !raw.exampleIds.length || raw.exampleIds.length > 4) {
|
|
90
|
+
throw invalid('Each trait must cite 1-4 example IDs.');
|
|
91
|
+
}
|
|
92
|
+
const exampleIds = raw.exampleIds.map(value => identifier(value, 'trait.exampleIds'));
|
|
93
|
+
if (new Set(exampleIds).size !== exampleIds.length || exampleIds.some(value => !examplesById.has(value))) {
|
|
94
|
+
throw invalid('Trait evidence must refer to distinct example IDs that exist in this profile.');
|
|
95
|
+
}
|
|
96
|
+
exampleIds.forEach(value => usedExamples.add(value));
|
|
97
|
+
const template = text(raw.template, 15, 500, 'trait.template');
|
|
98
|
+
if (!/\[[^\]\r\n]{1,80}\]/.test(template)) {
|
|
99
|
+
throw invalid('Show the expression pattern with bracketed slots for existing facts, without inserting source-specific research content.');
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
id, dimension: raw.dimension,
|
|
103
|
+
title: text(raw.title, 3, 100, 'trait.title').replace(/[\r\n]/g, ' '),
|
|
104
|
+
observation: text(raw.observation, 30, 700, 'trait.observation'),
|
|
105
|
+
application: text(raw.application, 30, 600, 'trait.application'),
|
|
106
|
+
template,
|
|
107
|
+
limits: text(raw.limits, 15, 400, 'trait.limits'),
|
|
108
|
+
exampleIds,
|
|
109
|
+
sourceIds: [...new Set(exampleIds.map(value => examplesById.get(value).sourceId))]
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const languageDimensions = [...dimensions].filter(value => LANGUAGE_DIMENSIONS.has(value));
|
|
114
|
+
const languageTraits = traits.filter(value => LANGUAGE_DIMENSIONS.has(value.dimension));
|
|
115
|
+
if (dimensions.size < 3 || languageDimensions.length < 2 || languageTraits.length * 2 < traits.length) {
|
|
116
|
+
throw invalid('Cover at least three style dimensions, including two language-level dimensions. At least half the traits must address voice, syntax, rhythm, diction, or transitions.');
|
|
117
|
+
}
|
|
118
|
+
if (usedExamples.size !== examplesById.size) throw invalid('Every source example must support a named style trait.');
|
|
119
|
+
const citedSources = new Set(traits.flatMap(trait => trait.sourceIds));
|
|
120
|
+
if (documents.length > 1 && citedSources.size < 2) {
|
|
121
|
+
throw invalid('A multi-source style profile must use evidence from more than one source.');
|
|
122
|
+
}
|
|
123
|
+
const order = Object.keys(DIMENSIONS);
|
|
124
|
+
traits.sort((a, b) => order.indexOf(a.dimension) - order.indexOf(b.dimension));
|
|
125
|
+
return { label, evidenceLimits, traits, sections };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function renderGuide(profile) {
|
|
129
|
+
const examples = new Map(profile.sections.flatMap(section => section.examples.map(example => [example.id, example])));
|
|
130
|
+
let output = '# Writing style\n\n'
|
|
131
|
+
+ 'Apply the supported expression preferences below to the current content. Keep the requested language, facts, terminology, and document structure. '
|
|
132
|
+
+ 'Bracketed slots illustrate phrasing and must be filled only with content already supported by the current task.\n';
|
|
133
|
+
for (const dimension of Object.keys(DIMENSIONS)) {
|
|
134
|
+
const traits = profile.traits.filter(trait => trait.dimension === dimension);
|
|
135
|
+
if (!traits.length) continue;
|
|
136
|
+
output += '\n## ' + DIMENSIONS[dimension] + '\n';
|
|
137
|
+
for (const trait of traits) {
|
|
138
|
+
output += '\n### ' + trait.id + ': ' + trait.title + '\n\n'
|
|
139
|
+
+ 'Observed: ' + trait.observation + '\n\n'
|
|
140
|
+
+ 'Apply: ' + trait.application + '\n\n'
|
|
141
|
+
+ 'Expression pattern: ' + trait.template + '\n\n'
|
|
142
|
+
+ 'When to adapt or skip: ' + trait.limits + '\n\n'
|
|
143
|
+
+ 'Evidence: ' + trait.exampleIds.map(id => id + ' in references/' + examples.get(id).sectionKey + '.md').join('; ') + '.\n'
|
|
144
|
+
+ 'Support: ' + trait.sourceIds.length + ' reference source(s).'
|
|
145
|
+
+ (trait.sourceIds.length === 1 ? ' This is a local observation, not a consensus across the reference set.' : '') + '\n';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return output + '\n## Evidence limits\n\n' + profile.evidenceLimits + '\n';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function renderSection(section, profile, documents) {
|
|
152
|
+
const exampleIds = new Set(section.examples.map(example => example.id));
|
|
153
|
+
const traits = profile.traits.filter(trait => trait.exampleIds.some(id => exampleIds.has(id)));
|
|
154
|
+
let output = '# ' + section.title + ' - source examples\n\n'
|
|
155
|
+
+ 'This file is an evidence index. Its section label does not require the target paper to use the same structure, research objects, or argument.\n\n'
|
|
156
|
+
+ '## Expression traits illustrated\n\n'
|
|
157
|
+
+ traits.map(trait => '- ' + trait.id + ': ' + trait.title).join('\n')
|
|
158
|
+
+ '\n\nSee references/writing-style.md for each trait and its limits.\n\n## Read-only examples\n';
|
|
159
|
+
for (const example of section.examples) {
|
|
160
|
+
output += renderExample(example, documents.find(doc => doc.id === example.sourceId));
|
|
161
|
+
}
|
|
162
|
+
return output;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
module.exports = { validate, renderGuide, renderSection };
|