noteconnection 1.7.0 → 1.9.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.
Files changed (328) hide show
  1. package/LICENSE +674 -21
  2. package/README.md +260 -1626
  3. package/dist/src/agent_workspace.contract.parity.test.js +159 -0
  4. package/dist/src/agent_workspace.frontend.test.js +10388 -0
  5. package/dist/src/agent_workspace.locale.contract.test.js +95 -0
  6. package/dist/src/agent_workspace.runtime.behavior.test.js +5072 -0
  7. package/dist/src/android.knowledgebase.picker.contract.test.js +102 -0
  8. package/dist/src/appimage.patchelf.test.js +113 -0
  9. package/dist/src/appimage.portability.test.js +156 -0
  10. package/dist/src/backend/FileLoader.js +18 -4
  11. package/dist/src/backend/FileLoader.test.js +125 -0
  12. package/dist/src/backend/GraphBuilder.identity.test.js +86 -0
  13. package/dist/src/backend/GraphBuilder.js +66 -18
  14. package/dist/src/backend/GraphBuilder.matching.test.js +127 -0
  15. package/dist/src/backend/GraphMetrics.js +0 -3
  16. package/dist/src/backend/ResourceIdentity.js +155 -0
  17. package/dist/src/backend/ResourceIdentity.test.js +113 -0
  18. package/dist/src/backend/algorithms/CycleDetection.js +0 -1
  19. package/dist/src/backend/algorithms/HybridEngine.js +0 -3
  20. package/dist/src/backend/algorithms/LayoutEngine.js +0 -1
  21. package/dist/src/backend/algorithms/StatisticalAnalyzer.js +0 -4
  22. package/dist/src/backend/algorithms/TopologicalSort.js +0 -2
  23. package/dist/src/backend/build_dag.js +0 -1
  24. package/dist/src/capacitor.bridge.serialization.contract.test.js +3 -0
  25. package/dist/src/capacitor.runtime.contract.test.js +11 -2
  26. package/dist/src/copy.assets.contract.test.js +130 -0
  27. package/dist/src/core/Graph.js +138 -42
  28. package/dist/src/core/Graph.test.js +74 -0
  29. package/dist/src/core/NoteConnection.js +2 -2
  30. package/dist/src/core/PathBridge.js +293 -5
  31. package/dist/src/core/ResourceReference.js +17 -0
  32. package/dist/src/desktop.godot.pack.test.js +142 -0
  33. package/dist/src/desktop.runtime.graph.test.js +66 -0
  34. package/dist/src/export/WorkspaceExportBundle.js +1174 -0
  35. package/dist/src/export/WorkspaceExportBundle.test.js +1541 -0
  36. package/dist/src/export/index.js +18 -0
  37. package/dist/src/export/types.js +2 -0
  38. package/dist/src/fixrisk.issue.verifier.contract.test.js +3 -1
  39. package/dist/src/foundation.ann.runtime.contract.test.js +81 -0
  40. package/dist/src/foundation.release.evidence.contract.test.js +524 -0
  41. package/dist/src/foundation.sqlite.runtime.contract.test.js +88 -0
  42. package/dist/src/frontend/README.md +260 -1626
  43. package/dist/src/frontend/agent_workspace.js +6011 -0
  44. package/dist/src/frontend/agent_workspace_runtime.js +4434 -0
  45. package/dist/src/frontend/analysis.js +31 -4
  46. package/dist/src/frontend/app.js +2178 -62
  47. package/dist/src/frontend/focus_mode_interactions.js +33 -0
  48. package/dist/src/frontend/godot_future_path_renderer.js +540 -0
  49. package/dist/src/frontend/godot_tree_interactions.js +178 -0
  50. package/dist/src/frontend/graph_state.mjs +105 -0
  51. package/dist/src/frontend/hosted_future_path_runtime.js +157 -0
  52. package/dist/src/frontend/i18n.mjs +186 -0
  53. package/dist/src/frontend/index.html +672 -268
  54. package/dist/src/frontend/knowledge_projection_contract.js +230 -0
  55. package/dist/src/frontend/knowledge_projection_store.js +214 -0
  56. package/dist/src/frontend/layout_gpu.js +12 -4
  57. package/dist/src/frontend/libs/path_core.js +158 -42
  58. package/dist/src/frontend/locales/en.json +753 -5
  59. package/dist/src/frontend/locales/zh.json +753 -5
  60. package/dist/src/frontend/main.mjs +60 -0
  61. package/dist/src/frontend/markdown_runtime.js +827 -0
  62. package/dist/src/frontend/mobile_budget_runtime.js +33 -0
  63. package/dist/src/frontend/mobile_exact_analyzer.js +393 -0
  64. package/dist/src/frontend/mobile_identity_contract.js +221 -0
  65. package/dist/src/frontend/mobile_semantic_comparator.js +264 -0
  66. package/dist/src/frontend/notemd.css +49 -0
  67. package/dist/src/frontend/notemd.html +7 -1
  68. package/dist/src/frontend/notemd.js +64 -0
  69. package/dist/src/frontend/path.html +113 -2
  70. package/dist/src/frontend/path_app.js +2108 -130
  71. package/dist/src/frontend/path_layout.mjs +143 -0
  72. package/dist/src/frontend/path_mermaid_utils.mjs +108 -0
  73. package/dist/src/frontend/path_modules_bridge.js +486 -0
  74. package/dist/src/frontend/path_state.mjs +118 -0
  75. package/dist/src/frontend/path_styles.css +146 -0
  76. package/dist/src/frontend/path_worker_bridge.mjs +85 -0
  77. package/dist/src/frontend/reader.js +393 -33
  78. package/dist/src/frontend/runtime_bridge.js +67 -54
  79. package/dist/src/frontend/runtime_bridge.mjs +279 -0
  80. package/dist/src/frontend/settings.js +130 -12
  81. package/dist/src/frontend/simulationWorker.js +1 -1
  82. package/dist/src/frontend/source_manager.js +297 -22
  83. package/dist/src/frontend/storage_provider.js +661 -71
  84. package/dist/src/frontend/styles.css +2814 -72
  85. package/dist/src/frontend/workbench_state.mjs +101 -0
  86. package/dist/src/frontend/workspace_panes.js +10272 -0
  87. package/dist/src/frontend.locale.contract.test.js +62 -0
  88. package/dist/src/frontend.runtime.assets.contract.test.js +81 -0
  89. package/dist/src/godot.sidecar.bootstrap.contract.test.js +244 -0
  90. package/dist/src/graph.answer.operator.contract.test.js +72 -0
  91. package/dist/src/index.js +6 -2
  92. package/dist/src/index.knowledge-root.test.js +118 -0
  93. package/dist/src/indexing/IndexLifecycle.js +217 -0
  94. package/dist/src/indexing/IndexLifecycle.test.js +73 -0
  95. package/dist/src/indexing/SegmentBuilder.js +64 -0
  96. package/dist/src/indexing/UnitBuilder.js +48 -0
  97. package/dist/src/indexing/types.js +2 -0
  98. package/dist/src/knowledge.api.contract.test.js +172 -0
  99. package/dist/src/knowledge_projection.contract.test.js +134 -0
  100. package/dist/src/knowledge_projection_store.test.js +200 -0
  101. package/dist/src/learning/AnswerQualityEvaluation.js +153 -0
  102. package/dist/src/learning/AnswerQualityEvaluation.test.js +118 -0
  103. package/dist/src/learning/KnowledgeLearningPlatform.js +11181 -0
  104. package/dist/src/learning/KnowledgeLearningPlatform.persistence.test.js +745 -0
  105. package/dist/src/learning/KnowledgeLearningPlatform.program-f.test.js +99 -0
  106. package/dist/src/learning/KnowledgeLearningPlatform.test.js +3208 -0
  107. package/dist/src/learning/KnowledgeWorkspaceConversationRegression.js +2998 -0
  108. package/dist/src/learning/KnowledgeWorkspaceConversationRegression.test.js +3936 -0
  109. package/dist/src/learning/MeasurementEvidenceConflicts.test.js +78 -0
  110. package/dist/src/learning/PublicAnswerContract.test.js +85 -0
  111. package/dist/src/learning/PublicEvidenceSelection.test.js +94 -0
  112. package/dist/src/learning/PublicMeasurementDisclosure.test.js +54 -0
  113. package/dist/src/learning/agentConversationExecution.js +211 -0
  114. package/dist/src/learning/agentConversationExecution.test.js +209 -0
  115. package/dist/src/learning/agentConversationSerialization.js +266 -0
  116. package/dist/src/learning/agentConversationSerialization.test.js +165 -0
  117. package/dist/src/learning/agentResponseBudget.js +179 -0
  118. package/dist/src/learning/agentResponseBudget.test.js +97 -0
  119. package/dist/src/learning/agentWorkspaceCapabilityContracts.js +65 -0
  120. package/dist/src/learning/answerReleaseReview.js +5260 -0
  121. package/dist/src/learning/answerReleaseReview.test.js +4174 -0
  122. package/dist/src/learning/answerTaskPlan.js +473 -0
  123. package/dist/src/learning/api.js +2 -0
  124. package/dist/src/learning/conversationComposer.js +1721 -0
  125. package/dist/src/learning/conversationComposer.test.js +3220 -0
  126. package/dist/src/learning/domains/ConversationManager.js +53 -0
  127. package/dist/src/learning/domains/KnowledgeIngestor.js +238 -0
  128. package/dist/src/learning/domains/KnowledgeQuerier.js +187 -0
  129. package/dist/src/learning/domains/MasteryEngine.js +387 -0
  130. package/dist/src/learning/domains/MemoryPolicyManager.js +408 -0
  131. package/dist/src/learning/domains/QualityEvaluator.js +307 -0
  132. package/dist/src/learning/domains/TutorRouter.js +313 -0
  133. package/dist/src/learning/domains/index.js +33 -0
  134. package/dist/src/learning/domains/types.js +7 -0
  135. package/dist/src/learning/errors.js +29 -0
  136. package/dist/src/learning/evidenceContextAssembler.js +1368 -0
  137. package/dist/src/learning/evidenceContextAssembler.test.js +6332 -0
  138. package/dist/src/learning/graphAnswerCoverage.js +37 -0
  139. package/dist/src/learning/graphAnswerCoverage.test.js +93 -0
  140. package/dist/src/learning/graphAnswerCoverageCalibration.js +59 -0
  141. package/dist/src/learning/graphAnswerCoverageCalibration.test.js +46 -0
  142. package/dist/src/learning/graphAnswerFacts.js +94 -0
  143. package/dist/src/learning/graphAnswerFacts.test.js +39 -0
  144. package/dist/src/learning/graphAnswerPlan.js +908 -0
  145. package/dist/src/learning/graphAnswerPlan.test.js +907 -0
  146. package/dist/src/learning/graphAnswerQualityCalibration.js +255 -0
  147. package/dist/src/learning/graphAnswerQualityCalibration.test.js +72 -0
  148. package/dist/src/learning/graphAnswerQualityPolicy.js +30 -0
  149. package/dist/src/learning/graphClaimMatcher.js +104 -0
  150. package/dist/src/learning/graphConditionedContext.js +109 -0
  151. package/dist/src/learning/graphConditionedContext.test.js +99 -0
  152. package/dist/src/learning/graphContextAssembler.js +860 -0
  153. package/dist/src/learning/graphContextAssembler.test.js +1033 -0
  154. package/dist/src/learning/graphExpansionPolicy.js +22 -0
  155. package/dist/src/learning/graphExpansionPolicy.test.js +33 -0
  156. package/dist/src/learning/identityMetadata.test.js +26 -0
  157. package/dist/src/learning/index.js +29 -0
  158. package/dist/src/learning/mobileAnswerProjection.js +104 -0
  159. package/dist/src/learning/mobileAnswerProjection.test.js +102 -0
  160. package/dist/src/learning/queryBackend.js +1922 -0
  161. package/dist/src/learning/queryBackend.test.js +976 -0
  162. package/dist/src/learning/ragContextPack.js +356 -0
  163. package/dist/src/learning/ragContextPack.test.js +311 -0
  164. package/dist/src/learning/ragEvidenceQuality.js +96 -0
  165. package/dist/src/learning/ragEvidenceQuality.test.js +29 -0
  166. package/dist/src/learning/ragPublicText.js +101 -0
  167. package/dist/src/learning/ragPublicText.test.js +57 -0
  168. package/dist/src/learning/ragSufficiencyJudge.js +171 -0
  169. package/dist/src/learning/ragSufficiencyJudge.test.js +177 -0
  170. package/dist/src/learning/ragSufficiencyProviderJudge.js +217 -0
  171. package/dist/src/learning/ragSufficiencyProviderJudge.test.js +207 -0
  172. package/dist/src/learning/requestNormalization.js +304 -0
  173. package/dist/src/learning/requestNormalization.test.js +101 -0
  174. package/dist/src/learning/runtimeCapability.js +4677 -0
  175. package/dist/src/learning/runtimeCapability.test.js +3635 -0
  176. package/dist/src/learning/store.js +1344 -0
  177. package/dist/src/learning/store.test.js +1425 -0
  178. package/dist/src/learning/tutorAdapter.js +2 -0
  179. package/dist/src/learning/types.js +2 -0
  180. package/dist/src/learning/vectorAccelerationAdapter.js +958 -0
  181. package/dist/src/learning/vectorAccelerationAdapter.test.js +412 -0
  182. package/dist/src/learning/workspaceHydration.js +168 -0
  183. package/dist/src/learning/workspaceHydration.test.js +30 -0
  184. package/dist/src/lfs.asset.policy.contract.test.js +153 -0
  185. package/dist/src/license.policy.contract.test.js +71 -0
  186. package/dist/src/markdown/MarkdownGateway.js +4 -0
  187. package/dist/src/markdown/MarkdownGateway.test.js +59 -0
  188. package/dist/src/memory/MemoryGovernance.js +74 -0
  189. package/dist/src/memory/MemoryGovernance.test.js +46 -0
  190. package/dist/src/memory/types.js +2 -0
  191. package/dist/src/mermaid.frontend.guard.contract.test.js +77 -0
  192. package/dist/src/middleware/SseResponseWriter.js +122 -0
  193. package/dist/src/middleware/SseResponseWriter.test.js +54 -0
  194. package/dist/src/middleware/auth.js +38 -0
  195. package/dist/src/middleware/auth.test.js +33 -0
  196. package/dist/src/middleware/body-parser.js +45 -0
  197. package/dist/src/middleware/cors.js +44 -0
  198. package/dist/src/middleware/index.js +22 -0
  199. package/dist/src/middleware/request-trace.js +96 -0
  200. package/dist/src/mobile.android.evidence.contract.test.js +146 -0
  201. package/dist/src/mobile.android.signing.contract.test.js +66 -0
  202. package/dist/src/mobile.artifact.contract.test.js +144 -0
  203. package/dist/src/mobile.budget.contract.test.js +90 -0
  204. package/dist/src/mobile.canonical-id.readiness.test.js +54 -0
  205. package/dist/src/mobile.graph.parity.contract.test.js +207 -0
  206. package/dist/src/mobile.identity.contract.test.js +66 -0
  207. package/dist/src/mobile.identity.corpus.manifest.test.js +72 -0
  208. package/dist/src/mobile.identity.corpus.test.js +40 -0
  209. package/dist/src/mobile.native.recovery.contract.test.js +64 -0
  210. package/dist/src/mobile.pipeline.test.js +11 -1
  211. package/dist/src/mobile.profile.contract.test.js +225 -0
  212. package/dist/src/mobile.semantic.parity.test.js +92 -0
  213. package/dist/src/mobile_exact_analyzer.test.js +113 -0
  214. package/dist/src/notemd/AppConfigToml.js +6 -4
  215. package/dist/src/notemd/ContentGenerator.js +4 -9
  216. package/dist/src/notemd/FileProcessor.js +4 -9
  217. package/dist/src/notemd/MermaidProcessor.js +400 -50
  218. package/dist/src/notemd/NotemdService.js +506 -26
  219. package/dist/src/notemd/PromptManager.js +15 -0
  220. package/dist/src/notemd/Translator.js +4 -9
  221. package/dist/src/notemd/cli/commands.js +357 -0
  222. package/dist/src/notemd/cli/dispatcher.js +225 -0
  223. package/dist/src/notemd/cli/index.js +169 -0
  224. package/dist/src/notemd/cli/parser.js +68 -0
  225. package/dist/src/notemd/cli/types.js +2 -0
  226. package/dist/src/notemd/constants.js +43 -0
  227. package/dist/src/notemd/diagram/diagramGenerationService.js +78 -0
  228. package/dist/src/notemd/diagram/diagramSpec.js +79 -0
  229. package/dist/src/notemd/diagram/diagramSpecResponseParser.js +131 -0
  230. package/dist/src/notemd/diagram/intent.js +95 -0
  231. package/dist/src/notemd/diagram/planner.js +71 -0
  232. package/dist/src/notemd/diagram/prompts/diagramSpecPrompt.js +42 -0
  233. package/dist/src/notemd/diagram/types.js +18 -0
  234. package/dist/src/notemd/index.js +26 -0
  235. package/dist/src/notemd/operations/capabilityManifest.js +23 -0
  236. package/dist/src/notemd/operations/cliContracts.js +17 -0
  237. package/dist/src/notemd/operations/configProfileCommands.js +85 -0
  238. package/dist/src/notemd/operations/registry.contract.test.js +95 -0
  239. package/dist/src/notemd/operations/registry.js +991 -0
  240. package/dist/src/notemd/operations/types.js +2 -0
  241. package/dist/src/notemd/progressReporter.js +9 -0
  242. package/dist/src/notemd/providerDiagnostics.js +220 -0
  243. package/dist/src/notemd/providerProfiles.js +42 -0
  244. package/dist/src/notemd/providerTemplates.js +231 -0
  245. package/dist/src/notemd/search/DuckDuckGoProvider.js +39 -0
  246. package/dist/src/notemd/search/SearchManager.js +13 -0
  247. package/dist/src/notemd/search/SearchProvider.js +2 -0
  248. package/dist/src/notemd/search/TavilyProvider.js +44 -0
  249. package/dist/src/notemd.agent.manifest.test.js +85 -0
  250. package/dist/src/notemd.api.contract.test.js +14 -1
  251. package/dist/src/notemd.app_config_toml.test.js +2 -1
  252. package/dist/src/notemd.batch.workflow.test.js +117 -0
  253. package/dist/src/notemd.cli.e2e.test.js +136 -0
  254. package/dist/src/notemd.core.test.js +51 -0
  255. package/dist/src/notemd.diagram.pipeline.test.js +233 -0
  256. package/dist/src/notemd.providerTemplates.test.js +34 -0
  257. package/dist/src/notemd.server.integration.test.js +262 -39
  258. package/dist/src/notemd.workflow.pipeline.test.js +162 -0
  259. package/dist/src/pathbridge.handshake.contract.test.js +45 -2
  260. package/dist/src/pathbridge.host-adapter.contract.test.js +133 -0
  261. package/dist/src/pathcore.bundle.contract.test.js +8 -0
  262. package/dist/src/pathmode.background.contract.test.js +69 -0
  263. package/dist/src/pathmode.settings.api.contract.test.js +9 -0
  264. package/dist/src/pkg.sidecar.contract.test.js +9 -3
  265. package/dist/src/platform/ExportProfile.js +86 -0
  266. package/dist/src/platform/MobileBudget.js +11 -0
  267. package/dist/src/platform/PlatformCapabilities.js +59 -0
  268. package/dist/src/platform/PlatformCapabilities.test.js +36 -0
  269. package/dist/src/platform/RenderMaterializer.js +33 -0
  270. package/dist/src/platform/RenderMaterializer.test.js +32 -0
  271. package/dist/src/query_backend.external_http.integration.test.js +410 -0
  272. package/dist/src/reader_renderer.js +404 -3
  273. package/dist/src/reader_renderer.test.js +87 -0
  274. package/dist/src/release.godot.mirror.contract.test.js +97 -0
  275. package/dist/src/resources/ResourceRegistry.js +263 -0
  276. package/dist/src/resources/ResourceRegistry.test.js +97 -0
  277. package/dist/src/resources/types.js +2 -0
  278. package/dist/src/routes/agentWorkspaceDiagnostics.js +173 -0
  279. package/dist/src/routes/index.js +19 -0
  280. package/dist/src/routes/knowledge.js +981 -0
  281. package/dist/src/routes/knowledgePayload.js +185 -0
  282. package/dist/src/routes/knowledgePayload.test.js +53 -0
  283. package/dist/src/routes/markdown.js +295 -0
  284. package/dist/src/routes/notemd.js +1321 -0
  285. package/dist/src/routes/registry.contract.test.js +133 -0
  286. package/dist/src/routes/registry.shadow.contract.test.js +22 -0
  287. package/dist/src/routes/render.js +248 -0
  288. package/dist/src/routes/runtimeRunbookRouteOps.js +149 -0
  289. package/dist/src/routes/runtimeRunbookRouteOps.test.js +194 -0
  290. package/dist/src/routes/settings.js +6 -0
  291. package/dist/src/routes/staticFiles.js +94 -0
  292. package/dist/src/routes/types.js +2 -0
  293. package/dist/src/runtime.capabilities.test.js +18 -2
  294. package/dist/src/runtime.transport.adapter.contract.test.js +81 -0
  295. package/dist/src/server.js +10342 -1325
  296. package/dist/src/server.migration.test.js +584 -10
  297. package/dist/src/server.port.fallback.contract.test.js +63 -0
  298. package/dist/src/session/SessionStateStore.js +81 -0
  299. package/dist/src/session/SessionStateStore.test.js +58 -0
  300. package/dist/src/session/types.js +2 -0
  301. package/dist/src/settings.runtime.contract.test.js +50 -0
  302. package/dist/src/shared/types.contract.test.js +107 -0
  303. package/dist/src/shared/types.js +22 -0
  304. package/dist/src/sidecar.build.lock.contract.test.js +201 -0
  305. package/dist/src/sidecar.freshness.contract.test.js +184 -0
  306. package/dist/src/sidecar.replacement.boundary.contract.test.js +131 -0
  307. package/dist/src/sidecar.supply.readiness.contract.test.js +155 -0
  308. package/dist/src/simulation.worker.offline.test.js +104 -0
  309. package/dist/src/source_manager.loadflow.test.js +46 -0
  310. package/dist/src/startup.layout.snapshot.contract.test.js +57 -0
  311. package/dist/src/storage.provider.capacitor.content.contract.test.js +4 -1
  312. package/dist/src/storage.provider.contract.test.js +152 -1
  313. package/dist/src/tauri.frontend.build.contract.test.js +68 -0
  314. package/dist/src/tauri.sidecar.cleanup.contract.test.js +21 -0
  315. package/dist/src/tauri.window.evidence.execution.test.js +68 -0
  316. package/dist/src/utils/RuntimePaths.js +10 -13
  317. package/dist/src/utils/RuntimePaths.test.js +27 -0
  318. package/dist/src/utils/platform.js +153 -0
  319. package/dist/src/windows.installer.build.test.js +109 -0
  320. package/dist/src/windows.installer.payload.test.js +76 -0
  321. package/dist/src/windows.installer.runtime.test.js +69 -0
  322. package/dist/src/workflows/WorkflowArtifactStore.js +96 -0
  323. package/dist/src/workflows/WorkflowArtifactStore.test.js +80 -0
  324. package/dist/src/workflows/types.js +2 -0
  325. package/dist/src/workspace/WorkspaceRegistry.js +135 -0
  326. package/dist/src/workspace/WorkspaceRegistry.test.js +29 -0
  327. package/dist/src/workspace/types.js +2 -0
  328. package/package.json +80 -15
@@ -0,0 +1,33 @@
1
+ (function attachMobileBudgetRuntime(root) {
2
+ 'use strict';
3
+
4
+ // This is the intentionally tiny browser projection of config/mobile-budget.v1.json.
5
+ // The Node/Rust contract remains the source of truth; contract tests reject drift.
6
+ if (!root || root.NoteConnectionMobileBudget) {
7
+ return;
8
+ }
9
+
10
+ root.NoteConnectionMobileBudget = Object.freeze({
11
+ schemaVersion: 1,
12
+ profiles: Object.freeze({
13
+ 'mobile-low': Object.freeze({
14
+ artifactCompressedBytes: 25 * 1024 * 1024,
15
+ maxResidentBytes: 256 * 1024 * 1024,
16
+ maxDeviceRamBytes: 4 * 1024 * 1024 * 1024
17
+ }),
18
+ 'mobile-standard': Object.freeze({
19
+ artifactCompressedBytes: 35 * 1024 * 1024,
20
+ maxResidentBytes: 384 * 1024 * 1024,
21
+ maxDeviceRamBytes: 8 * 1024 * 1024 * 1024
22
+ })
23
+ }),
24
+ runtime: Object.freeze({
25
+ maxDocuments: 5000,
26
+ maxDocumentBytes: 16 * 1024 * 1024,
27
+ maxTotalInputBytes: 64 * 1024 * 1024,
28
+ maxEdges: 250000,
29
+ maxDepth: 64,
30
+ maxProjectionBytes: 48 * 1024 * 1024
31
+ })
32
+ });
33
+ }(typeof globalThis !== 'undefined' ? globalThis : this));
@@ -0,0 +1,393 @@
1
+ (function attachMobileExactAnalyzer(root, factory) {
2
+ const api = factory();
3
+ if (typeof module === 'object' && module.exports) {
4
+ module.exports = api;
5
+ }
6
+ if (root) {
7
+ root.NoteConnectionMobileExactAnalyzer = api;
8
+ }
9
+ }(typeof globalThis !== 'undefined' ? globalThis : this, function createAnalyzerApi() {
10
+ 'use strict';
11
+
12
+ const MAX_NODES = 50000;
13
+ const MAX_EDGES = 250000;
14
+ const MAX_QUERY_LENGTH = 256;
15
+ const MAX_MATCHES = 50;
16
+ const MAX_NEIGHBORS = 64;
17
+ const MAX_PATH_DEPTH = 8;
18
+ const MAX_VISITED_NODES = 10000;
19
+ const PROJECTION_VERSION = 1;
20
+
21
+ function normalizeLookupKey(value) {
22
+ const text = String(value || '').trim();
23
+ const normalizedText = typeof text.normalize === 'function'
24
+ ? text.normalize('NFC')
25
+ : text;
26
+ return normalizedText.toLowerCase();
27
+ }
28
+
29
+ function classifyEdgeType(edgeType) {
30
+ const normalized = String(edgeType || '').trim().toLowerCase();
31
+ if (normalized.startsWith('explicit-') || normalized === 'tagged' || normalized === 'sequence') {
32
+ return 'explicit';
33
+ }
34
+ if (
35
+ normalized.includes('inferred')
36
+ || normalized.includes('keyword')
37
+ || normalized.includes('vector')
38
+ || normalized.includes('statistical')
39
+ || normalized.includes('similarity')
40
+ ) {
41
+ return 'inferred';
42
+ }
43
+ return 'runtime';
44
+ }
45
+
46
+ function normalizeEdgeKinds(value) {
47
+ if (!Array.isArray(value)) {
48
+ return null;
49
+ }
50
+ const allowed = new Set(['explicit', 'inferred', 'runtime']);
51
+ const kinds = value.map((kind) => String(kind || '').trim().toLowerCase()).filter((kind) => allowed.has(kind));
52
+ return kinds.length > 0 ? new Set(kinds) : null;
53
+ }
54
+
55
+ function boundedPositiveInteger(value, fallback, ceiling) {
56
+ const parsed = Number.parseInt(String(value || ''), 10);
57
+ if (!Number.isFinite(parsed) || parsed <= 0) {
58
+ return fallback;
59
+ }
60
+ return Math.min(parsed, ceiling);
61
+ }
62
+
63
+ function readEndpointId(value) {
64
+ if (typeof value === 'string') {
65
+ return value.trim();
66
+ }
67
+ if (value && typeof value === 'object' && typeof value.id === 'string') {
68
+ return value.id.trim();
69
+ }
70
+ return '';
71
+ }
72
+
73
+ function projectNode(rawNode) {
74
+ if (!rawNode || typeof rawNode !== 'object') {
75
+ throw new Error('Mobile exact index requires every node to be an object.');
76
+ }
77
+ const id = typeof rawNode.id === 'string' ? rawNode.id.trim() : '';
78
+ if (!id) {
79
+ throw new Error('Mobile exact index requires every node to have a non-empty id.');
80
+ }
81
+ const metadata = rawNode.metadata && typeof rawNode.metadata === 'object'
82
+ ? rawNode.metadata
83
+ : {};
84
+ const tags = Array.isArray(metadata.tags)
85
+ ? metadata.tags.map((tag) => String(tag || '').trim()).filter(Boolean)
86
+ : [];
87
+ const identityAliases = Array.isArray(rawNode.identityAliases)
88
+ ? rawNode.identityAliases.map((alias) => String(alias || '').trim()).filter(Boolean)
89
+ : [];
90
+
91
+ return Object.freeze({
92
+ id,
93
+ canonicalId: typeof rawNode.canonicalId === 'string' ? rawNode.canonicalId.trim() : '',
94
+ label: typeof rawNode.label === 'string' && rawNode.label.trim()
95
+ ? rawNode.label.trim()
96
+ : id,
97
+ clusterId: typeof rawNode.clusterId === 'string' ? rawNode.clusterId : '',
98
+ inDegree: Number.isFinite(rawNode.inDegree) ? Number(rawNode.inDegree) : 0,
99
+ outDegree: Number.isFinite(rawNode.outDegree) ? Number(rawNode.outDegree) : 0,
100
+ tags: Object.freeze(tags),
101
+ sourceUri: typeof rawNode.sourceUri === 'string' ? rawNode.sourceUri.trim() : '',
102
+ revision: typeof rawNode.revision === 'string' ? rawNode.revision.trim() : '',
103
+ identityAliases: Object.freeze(identityAliases),
104
+ evidenceRefs: Object.freeze(Array.isArray(rawNode.evidenceRefs)
105
+ ? rawNode.evidenceRefs.map((reference) => String(reference || '').trim()).filter(Boolean).slice(0, 8)
106
+ : []),
107
+ });
108
+ }
109
+
110
+ function addLookupReference(lookup, rawKey, nodeId) {
111
+ const key = normalizeLookupKey(rawKey);
112
+ if (!key) {
113
+ return;
114
+ }
115
+ if (!lookup.has(key)) {
116
+ lookup.set(key, new Set());
117
+ }
118
+ lookup.get(key).add(nodeId);
119
+ }
120
+
121
+ function createMobileExactIndex(graph) {
122
+ if (!graph || typeof graph !== 'object') {
123
+ throw new Error('Mobile exact index requires a graph payload.');
124
+ }
125
+ const declaredSchemaVersion = graph.schemaVersion ?? graph.projectionVersion;
126
+ if (declaredSchemaVersion !== undefined && Number(declaredSchemaVersion) !== PROJECTION_VERSION) {
127
+ throw new Error(`Unsupported mobile projection schema version: ${String(declaredSchemaVersion)}.`);
128
+ }
129
+ const rawNodes = Array.isArray(graph.nodes) ? graph.nodes : [];
130
+ const rawEdges = Array.isArray(graph.edges) ? graph.edges : [];
131
+ if (rawNodes.length > MAX_NODES) {
132
+ throw new Error(`Mobile exact index node limit exceeded: ${rawNodes.length}/${MAX_NODES}.`);
133
+ }
134
+ if (rawEdges.length > MAX_EDGES) {
135
+ throw new Error(`Mobile exact index edge limit exceeded: ${rawEdges.length}/${MAX_EDGES}.`);
136
+ }
137
+
138
+ const nodeById = new Map();
139
+ const normalizedNodeIds = new Set();
140
+ const lookup = new Map();
141
+ const outgoing = new Map();
142
+ const incoming = new Map();
143
+
144
+ rawNodes.forEach((rawNode) => {
145
+ const node = projectNode(rawNode);
146
+ const normalizedId = normalizeLookupKey(node.id);
147
+ if (normalizedNodeIds.has(normalizedId)) {
148
+ throw new Error(`Mobile exact index contains a duplicate node id: ${node.id}.`);
149
+ }
150
+ normalizedNodeIds.add(normalizedId);
151
+ nodeById.set(node.id, node);
152
+ outgoing.set(node.id, new Map());
153
+ incoming.set(node.id, new Map());
154
+ addLookupReference(lookup, node.id, node.id);
155
+ addLookupReference(lookup, node.canonicalId, node.id);
156
+ addLookupReference(lookup, node.label, node.id);
157
+ addLookupReference(lookup, node.sourceUri, node.id);
158
+ addLookupReference(lookup, node.revision, node.id);
159
+ node.identityAliases.forEach((alias) => addLookupReference(lookup, alias, node.id));
160
+ node.tags.forEach((tag) => addLookupReference(lookup, tag, node.id));
161
+ });
162
+
163
+ let edgeCount = 0;
164
+ let explicitEdgeCount = 0;
165
+ let inferredEdgeCount = 0;
166
+ let runtimeEdgeCount = 0;
167
+ rawEdges.forEach((rawEdge) => {
168
+ if (!rawEdge || typeof rawEdge !== 'object') {
169
+ throw new Error('Mobile exact index requires every edge to be an object.');
170
+ }
171
+ const source = readEndpointId(rawEdge.source);
172
+ const target = readEndpointId(rawEdge.target);
173
+ if (!source || !target || !nodeById.has(source) || !nodeById.has(target)) {
174
+ throw new Error(`Mobile exact index edge references an unknown node: ${source || '?'} -> ${target || '?'}.`);
175
+ }
176
+ if (source === target) {
177
+ return;
178
+ }
179
+ const sourceEdges = outgoing.get(source);
180
+ if (sourceEdges.has(target)) {
181
+ return;
182
+ }
183
+ const edgeType = typeof rawEdge.type === 'string' && rawEdge.type.trim()
184
+ ? rawEdge.type.trim()
185
+ : 'association';
186
+ const edgeKind = classifyEdgeType(edgeType);
187
+ sourceEdges.set(target, edgeType);
188
+ incoming.get(target).set(source, edgeType);
189
+ edgeCount += 1;
190
+ if (edgeKind === 'explicit') explicitEdgeCount += 1;
191
+ else if (edgeKind === 'inferred') inferredEdgeCount += 1;
192
+ else runtimeEdgeCount += 1;
193
+ });
194
+
195
+ function searchExact(term, requestedLimit) {
196
+ const normalizedTerm = normalizeLookupKey(term);
197
+ if (!normalizedTerm || normalizedTerm.length > MAX_QUERY_LENGTH) {
198
+ return [];
199
+ }
200
+ const limit = boundedPositiveInteger(requestedLimit, 25, MAX_MATCHES);
201
+ const matchedIds = lookup.get(normalizedTerm) || new Set();
202
+ return Array.from(matchedIds)
203
+ .sort((left, right) => left.localeCompare(right))
204
+ .slice(0, limit)
205
+ .map((id) => nodeById.get(id));
206
+ }
207
+
208
+ function resolveNodeReference(reference) {
209
+ const direct = typeof reference === 'string' ? reference.trim() : '';
210
+ if (direct && nodeById.has(direct)) {
211
+ return direct;
212
+ }
213
+ const matches = lookup.get(normalizeLookupKey(reference));
214
+ return matches && matches.size === 1 ? Array.from(matches)[0] : '';
215
+ }
216
+
217
+ function neighbors(nodeId, requestedLimit, requestedKinds) {
218
+ const resolvedNodeId = resolveNodeReference(nodeId);
219
+ if (!resolvedNodeId) {
220
+ return [];
221
+ }
222
+ const limit = boundedPositiveInteger(requestedLimit, 16, MAX_NEIGHBORS);
223
+ const edgeKinds = normalizeEdgeKinds(requestedKinds);
224
+ const adjacent = [];
225
+ outgoing.get(resolvedNodeId).forEach((edgeType, id) => {
226
+ if (!edgeKinds || edgeKinds.has(classifyEdgeType(edgeType))) {
227
+ adjacent.push({ ...nodeById.get(id), direction: 'outgoing', edgeType, edgeKind: classifyEdgeType(edgeType) });
228
+ }
229
+ });
230
+ incoming.get(resolvedNodeId).forEach((edgeType, id) => {
231
+ if (!edgeKinds || edgeKinds.has(classifyEdgeType(edgeType))) {
232
+ adjacent.push({ ...nodeById.get(id), direction: 'incoming', edgeType, edgeKind: classifyEdgeType(edgeType) });
233
+ }
234
+ });
235
+ return adjacent
236
+ .sort((left, right) => {
237
+ if (left.direction !== right.direction) {
238
+ return left.direction === 'outgoing' ? -1 : 1;
239
+ }
240
+ return left.id.localeCompare(right.id);
241
+ })
242
+ .slice(0, limit);
243
+ }
244
+
245
+ function isPrerequisiteRouteNeighbor(neighbor) {
246
+ return neighbor
247
+ && neighbor.direction === 'incoming'
248
+ && /prerequisite|precondition|foundation|先修|前置|基础|sequence/iu.test(
249
+ String(neighbor.edgeType || '')
250
+ );
251
+ }
252
+
253
+ function isApplicationRouteNeighbor(neighbor) {
254
+ return neighbor
255
+ && neighbor.direction === 'outgoing'
256
+ && /application|use|performance|应用|用例|性能/iu.test(
257
+ String(neighbor.edgeType || '')
258
+ );
259
+ }
260
+
261
+ function learningRoute(anchorReference, requestedLimit) {
262
+ const anchorId = resolveNodeReference(anchorReference);
263
+ if (!anchorId) {
264
+ return [];
265
+ }
266
+ const limit = boundedPositiveInteger(requestedLimit, 6, 8);
267
+ const anchor = nodeById.get(anchorId);
268
+ const adjacent = neighbors(anchorId, Math.min(MAX_NEIGHBORS, limit * 3), ['explicit', 'runtime']);
269
+ const entries = [];
270
+ const seen = new Set();
271
+ const append = (neighbor, role, orderingBasis) => {
272
+ const nodeId = String(neighbor && neighbor.id || '').trim();
273
+ if (!nodeId || seen.has(nodeId)) {
274
+ return;
275
+ }
276
+ seen.add(nodeId);
277
+ entries.push({
278
+ nodeId,
279
+ title: String(neighbor && (neighbor.label || neighbor.id) || '').trim(),
280
+ role,
281
+ orderingBasis,
282
+ });
283
+ };
284
+ adjacent
285
+ .filter(isPrerequisiteRouteNeighbor)
286
+ .sort((left, right) => String(left.label || left.id || '').localeCompare(String(right.label || right.id || '')))
287
+ .forEach((neighbor) => append(neighbor, 'prerequisite', 'explicit_prerequisite'));
288
+ append(anchor, 'core', 'semantic_grouping');
289
+ adjacent
290
+ .filter((neighbor) => !isPrerequisiteRouteNeighbor(neighbor))
291
+ .sort((left, right) => {
292
+ const leftApplication = isApplicationRouteNeighbor(left) ? 1 : 0;
293
+ const rightApplication = isApplicationRouteNeighbor(right) ? 1 : 0;
294
+ return leftApplication - rightApplication
295
+ || String(left.label || left.id || '').localeCompare(String(right.label || right.id || ''));
296
+ })
297
+ .forEach((neighbor) => append(
298
+ neighbor,
299
+ isApplicationRouteNeighbor(neighbor) ? 'application' : 'mechanism',
300
+ isApplicationRouteNeighbor(neighbor) ? 'explicit_sequence' : 'semantic_grouping'
301
+ ));
302
+ return entries.slice(0, limit).map((entry, index) => ({
303
+ ...entry,
304
+ order: index + 1,
305
+ }));
306
+ }
307
+
308
+ function shortestPath(sourceNodeId, targetNodeId, requestedMaxDepth, requestedMaxVisitedNodes) {
309
+ const resolvedSourceId = resolveNodeReference(sourceNodeId);
310
+ const resolvedTargetId = resolveNodeReference(targetNodeId);
311
+ if (!resolvedSourceId || !resolvedTargetId) {
312
+ return null;
313
+ }
314
+ if (resolvedSourceId === resolvedTargetId) {
315
+ return [resolvedSourceId];
316
+ }
317
+ const maxDepth = boundedPositiveInteger(requestedMaxDepth, 4, MAX_PATH_DEPTH);
318
+ const maxVisitedNodes = boundedPositiveInteger(
319
+ requestedMaxVisitedNodes,
320
+ 2000,
321
+ MAX_VISITED_NODES
322
+ );
323
+ const queue = [{ id: resolvedSourceId, depth: 0 }];
324
+ const parentById = new Map([[resolvedSourceId, null]]);
325
+
326
+ for (let cursor = 0; cursor < queue.length; cursor += 1) {
327
+ const current = queue[cursor];
328
+ if (current.depth >= maxDepth) {
329
+ continue;
330
+ }
331
+ for (const nextId of outgoing.get(current.id).keys()) {
332
+ if (parentById.has(nextId)) {
333
+ continue;
334
+ }
335
+ if (parentById.size >= maxVisitedNodes) {
336
+ return null;
337
+ }
338
+ parentById.set(nextId, current.id);
339
+ if (nextId === resolvedTargetId) {
340
+ const path = [resolvedTargetId];
341
+ let parentId = current.id;
342
+ while (parentId) {
343
+ path.push(parentId);
344
+ parentId = parentById.get(parentId);
345
+ }
346
+ return path.reverse();
347
+ }
348
+ queue.push({ id: nextId, depth: current.depth + 1 });
349
+ }
350
+ }
351
+ return null;
352
+ }
353
+
354
+ function statistics(options) {
355
+ const base = {
356
+ nodeCount: nodeById.size,
357
+ edgeCount,
358
+ };
359
+ if (!options || options.includeProvenance !== true) {
360
+ return base;
361
+ }
362
+ return {
363
+ ...base,
364
+ projectionVersion: PROJECTION_VERSION,
365
+ explicitEdgeCount,
366
+ inferredEdgeCount,
367
+ runtimeEdgeCount,
368
+ };
369
+ }
370
+
371
+ return Object.freeze({
372
+ projectionVersion: PROJECTION_VERSION,
373
+ searchExact,
374
+ neighbors,
375
+ learningRoute,
376
+ shortestPath,
377
+ statistics,
378
+ });
379
+ }
380
+
381
+ return Object.freeze({
382
+ createMobileExactIndex,
383
+ limits: Object.freeze({
384
+ maxNodes: MAX_NODES,
385
+ maxEdges: MAX_EDGES,
386
+ maxQueryLength: MAX_QUERY_LENGTH,
387
+ maxMatches: MAX_MATCHES,
388
+ maxNeighbors: MAX_NEIGHBORS,
389
+ maxPathDepth: MAX_PATH_DEPTH,
390
+ maxVisitedNodes: MAX_VISITED_NODES,
391
+ }),
392
+ });
393
+ }));
@@ -0,0 +1,221 @@
1
+ (function attachMobileIdentityContract(root, factory) {
2
+ const api = factory();
3
+ if (typeof module === 'object' && module.exports) {
4
+ module.exports = api;
5
+ }
6
+ if (root) {
7
+ root.NoteConnectionMobileIdentity = api;
8
+ }
9
+ }(typeof globalThis !== 'undefined' ? globalThis : this, function createMobileIdentityContract() {
10
+ 'use strict';
11
+
12
+ const SOURCE_URI_PREFIX = 'note://workspace/v1/';
13
+ const SHA256_K = Object.freeze([
14
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
15
+ 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
16
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
17
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
18
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
19
+ 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
20
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
21
+ 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
22
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
23
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
24
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
25
+ 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
26
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
27
+ 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
28
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
29
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
30
+ ]);
31
+
32
+ function normalizeUnicodeText(value, fieldName) {
33
+ if (typeof value !== 'string') {
34
+ throw new Error(`${fieldName} must be a string.`);
35
+ }
36
+ if (value.includes('\0')) {
37
+ throw new Error(`${fieldName} must not contain NUL characters.`);
38
+ }
39
+ return typeof value.normalize === 'function' ? value.normalize('NFC') : value;
40
+ }
41
+
42
+ function normalizePortablePath(relativePath) {
43
+ const displayPath = normalizeUnicodeText(relativePath, 'Relative resource path')
44
+ .replace(/\\/g, '/')
45
+ .trim();
46
+ const segments = displayPath.split('/').filter(Boolean);
47
+ if (segments[0] && segments[0].toLowerCase() === 'knowledge_base') {
48
+ segments.shift();
49
+ }
50
+ if (segments.length === 0 || segments.some(segment => segment === '.' || segment === '..')) {
51
+ throw new Error(`Relative resource path is unsafe: ${relativePath}`);
52
+ }
53
+ return segments.map(segment => segment.toLowerCase()).join('/');
54
+ }
55
+
56
+ function createSourceUri(canonicalRelativePath) {
57
+ return `${SOURCE_URI_PREFIX}${canonicalRelativePath
58
+ .split('/')
59
+ .map(segment => encodeURIComponent(segment))
60
+ .join('/')}`;
61
+ }
62
+
63
+ function createCanonicalId(canonicalRelativePath) {
64
+ return canonicalRelativePath.replace(/\.(?:md|markdown)$/i, '');
65
+ }
66
+
67
+ function utf8Encode(value) {
68
+ if (typeof TextEncoder === 'function') {
69
+ return new TextEncoder().encode(value);
70
+ }
71
+ const bytes = [];
72
+ for (let index = 0; index < value.length; index += 1) {
73
+ let codePoint = value.codePointAt(index);
74
+ if (codePoint > 0xffff) {
75
+ index += 1;
76
+ }
77
+ if (codePoint <= 0x7f) {
78
+ bytes.push(codePoint);
79
+ } else if (codePoint <= 0x7ff) {
80
+ bytes.push(0xc0 | (codePoint >> 6), 0x80 | (codePoint & 0x3f));
81
+ } else if (codePoint <= 0xffff) {
82
+ bytes.push(
83
+ 0xe0 | (codePoint >> 12),
84
+ 0x80 | ((codePoint >> 6) & 0x3f),
85
+ 0x80 | (codePoint & 0x3f),
86
+ );
87
+ } else {
88
+ bytes.push(
89
+ 0xf0 | (codePoint >> 18),
90
+ 0x80 | ((codePoint >> 12) & 0x3f),
91
+ 0x80 | ((codePoint >> 6) & 0x3f),
92
+ 0x80 | (codePoint & 0x3f),
93
+ );
94
+ }
95
+ }
96
+ return Uint8Array.from(bytes);
97
+ }
98
+
99
+ function rightRotate(value, amount) {
100
+ return (value >>> amount) | (value << (32 - amount));
101
+ }
102
+
103
+ function sha256HexSync(value) {
104
+ const bytes = utf8Encode(normalizeUnicodeText(value, 'Resource content'));
105
+ const bitLength = bytes.length * 8;
106
+ const paddedLength = ((bytes.length + 9 + 63) >> 6) << 6;
107
+ const padded = new Uint8Array(paddedLength);
108
+ padded.set(bytes);
109
+ padded[bytes.length] = 0x80;
110
+ const view = new DataView(padded.buffer);
111
+ view.setUint32(padded.length - 4, bitLength >>> 0);
112
+ view.setUint32(padded.length - 8, Math.floor(bitLength / 0x100000000));
113
+
114
+ let h0 = 0x6a09e667;
115
+ let h1 = 0xbb67ae85;
116
+ let h2 = 0x3c6ef372;
117
+ let h3 = 0xa54ff53a;
118
+ let h4 = 0x510e527f;
119
+ let h5 = 0x9b05688c;
120
+ let h6 = 0x1f83d9ab;
121
+ let h7 = 0x5be0cd19;
122
+ const words = new Uint32Array(64);
123
+
124
+ for (let offset = 0; offset < padded.length; offset += 64) {
125
+ for (let index = 0; index < 16; index += 1) {
126
+ words[index] = view.getUint32(offset + index * 4);
127
+ }
128
+ for (let index = 16; index < 64; index += 1) {
129
+ const s0 = rightRotate(words[index - 15], 7)
130
+ ^ rightRotate(words[index - 15], 18)
131
+ ^ (words[index - 15] >>> 3);
132
+ const s1 = rightRotate(words[index - 2], 17)
133
+ ^ rightRotate(words[index - 2], 19)
134
+ ^ (words[index - 2] >>> 10);
135
+ words[index] = (words[index - 16] + s0 + words[index - 7] + s1) >>> 0;
136
+ }
137
+
138
+ let a = h0;
139
+ let b = h1;
140
+ let c = h2;
141
+ let d = h3;
142
+ let e = h4;
143
+ let f = h5;
144
+ let g = h6;
145
+ let h = h7;
146
+ for (let index = 0; index < 64; index += 1) {
147
+ const sigma1 = rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25);
148
+ const choose = (e & f) ^ (~e & g);
149
+ const temp1 = (h + sigma1 + choose + SHA256_K[index] + words[index]) >>> 0;
150
+ const sigma0 = rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22);
151
+ const majority = (a & b) ^ (a & c) ^ (b & c);
152
+ const temp2 = (sigma0 + majority) >>> 0;
153
+ h = g;
154
+ g = f;
155
+ f = e;
156
+ e = (d + temp1) >>> 0;
157
+ d = c;
158
+ c = b;
159
+ b = a;
160
+ a = (temp1 + temp2) >>> 0;
161
+ }
162
+ h0 = (h0 + a) >>> 0;
163
+ h1 = (h1 + b) >>> 0;
164
+ h2 = (h2 + c) >>> 0;
165
+ h3 = (h3 + d) >>> 0;
166
+ h4 = (h4 + e) >>> 0;
167
+ h5 = (h5 + f) >>> 0;
168
+ h6 = (h6 + g) >>> 0;
169
+ h7 = (h7 + h) >>> 0;
170
+ }
171
+
172
+ return [h0, h1, h2, h3, h4, h5, h6, h7]
173
+ .map(valuePart => valuePart.toString(16).padStart(8, '0'))
174
+ .join('');
175
+ }
176
+
177
+ async function sha256Hex(value) {
178
+ const normalized = normalizeUnicodeText(value, 'Resource content');
179
+ const cryptoApi = typeof globalThis !== 'undefined' ? globalThis.crypto : null;
180
+ if (cryptoApi && cryptoApi.subtle && typeof TextEncoder === 'function') {
181
+ const digest = await cryptoApi.subtle.digest('SHA-256', new TextEncoder().encode(normalized));
182
+ return Array.from(new Uint8Array(digest))
183
+ .map(byte => byte.toString(16).padStart(2, '0'))
184
+ .join('');
185
+ }
186
+ return sha256HexSync(normalized);
187
+ }
188
+
189
+ async function createResourceIdentity(relativePath, legacyId, content) {
190
+ const displayRelativePath = normalizeUnicodeText(relativePath, 'Relative resource path')
191
+ .replace(/\\/g, '/')
192
+ .trim();
193
+ const canonicalRelativePath = normalizePortablePath(displayRelativePath);
194
+ const normalizedLegacyId = normalizeUnicodeText(String(legacyId || ''), 'Legacy resource ID').trim();
195
+ if (!normalizedLegacyId) {
196
+ throw new Error('Legacy resource ID must not be empty.');
197
+ }
198
+ return {
199
+ sourceUri: createSourceUri(canonicalRelativePath),
200
+ canonicalId: createCanonicalId(canonicalRelativePath),
201
+ revision: `sha256:${await sha256Hex(content)}`,
202
+ identityAliases: Array.from(new Set([
203
+ normalizedLegacyId,
204
+ normalizedLegacyId.toLowerCase().endsWith('.md')
205
+ ? normalizedLegacyId
206
+ : `${normalizedLegacyId}.md`,
207
+ displayRelativePath,
208
+ canonicalRelativePath,
209
+ ])),
210
+ };
211
+ }
212
+
213
+ return Object.freeze({
214
+ sourceUriPrefix: SOURCE_URI_PREFIX,
215
+ normalizePortablePath,
216
+ createSourceUri,
217
+ sha256Hex,
218
+ sha256HexSync,
219
+ createResourceIdentity,
220
+ });
221
+ }));