soma-core 2.2.8 → 2.2.10

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 (98) hide show
  1. package/core/build/compiler/full-manifest-builder.ts +1 -1
  2. package/core/build/compiler/host-config-sync.cjs +1 -1
  3. package/core/build/compiler/soma-manifest-webpack-plugin.js +2 -6
  4. package/core/build/compiler/soma-precompile.js +84 -4
  5. package/core/client/a11y/announcer.ts +2 -16
  6. package/core/client/base/SomaPageRootBase.ts +2 -2
  7. package/core/client/base/defineSomaView.ts +11 -2
  8. package/core/client/base/runtime-services.types.ts +57 -0
  9. package/core/client/data/role-gate.ts +2 -8
  10. package/core/client/engine/event-engine.ts +1 -0
  11. package/core/client/engines/diff/adapter-jsdiff.ts +27 -8
  12. package/core/client/engines/diff/code.ts +205 -0
  13. package/core/client/engines/diff/index.ts +107 -6
  14. package/core/client/engines/diff/items.ts +212 -0
  15. package/core/client/engines/diff/port.ts +215 -3
  16. package/core/client/engines/diff/prose.ts +443 -0
  17. package/core/client/engines/engine-adapters.ts +6 -0
  18. package/core/client/engines/highlight/adapter-lezer.ts +109 -0
  19. package/core/client/engines/highlight/index.ts +135 -0
  20. package/core/client/engines/highlight/port.ts +92 -0
  21. package/core/client/engines/markdown/adapter-markdown-it.ts +65 -0
  22. package/core/client/engines/markdown/blocks.ts +335 -0
  23. package/core/client/engines/markdown/index.ts +51 -0
  24. package/core/client/engines/markdown/port.ts +94 -0
  25. package/core/client/engines/markdown/vendor-modules.d.ts +6 -0
  26. package/core/client/engines/structured/adapter-js-yaml.ts +33 -0
  27. package/core/client/engines/structured/index.ts +139 -0
  28. package/core/client/engines/structured/port.ts +59 -0
  29. package/core/client/infra/http/SomaHttpService.ts +2 -4
  30. package/core/client/infra/notify/DefaultNotifyService.ts +2 -3
  31. package/core/client/infra/permission/SomaPermission.ts +1 -1
  32. package/core/client/render-ports/notify-renderer.ts +2 -46
  33. package/core/client/runtime/SomaRuntimeServices.ts +16 -45
  34. package/core/server/host/app-config-composer.ts +6 -52
  35. package/core/server/host/host-config-paths.cjs +2 -100
  36. package/core/server/host/precompiled-manifest.ts +69 -0
  37. package/core/server/host/source-packages.cjs +3 -0
  38. package/core/server/infra/host-config-paths.cjs +100 -0
  39. package/core/server/page-assets.ts +2 -70
  40. package/core/server/runtime-space/bindings.ts +33 -4
  41. package/core/server/runtime-space/store.ts +16 -1
  42. package/core/shared/app-config-merge.ts +59 -0
  43. package/core/shared/registry-generated/limits.ts +84 -4
  44. package/core/shared/types/announcer.types.ts +18 -0
  45. package/core/shared/types/notify.types.ts +26 -0
  46. package/core/shared/types/role-gate.types.ts +11 -0
  47. package/dist/browser/runtime-bundle.manifest.json +51 -7
  48. package/dist/browser/soma-runtime.js +120952 -104762
  49. package/dist/core/index.cjs +113613 -97412
  50. package/dist/host-native/aot-builder.cjs +582 -371
  51. package/dist/host-native/native-server.cjs +203 -72
  52. package/dist/lsp/component-tree.cjs +84 -4
  53. package/dist/types/build/compiler/full-manifest-builder.d.ts +1 -1
  54. package/dist/types/client/a11y/announcer.d.ts +2 -14
  55. package/dist/types/client/base/SomaPageRootBase.d.ts +2 -2
  56. package/dist/types/client/base/runtime-services.types.d.ts +50 -0
  57. package/dist/types/client/data/role-gate.d.ts +2 -8
  58. package/dist/types/client/engines/diff/code.d.ts +27 -0
  59. package/dist/types/client/engines/diff/index.d.ts +2 -1
  60. package/dist/types/client/engines/diff/items.d.ts +24 -0
  61. package/dist/types/client/engines/diff/port.d.ts +201 -2
  62. package/dist/types/client/engines/diff/prose.d.ts +80 -0
  63. package/dist/types/client/engines/engine-adapters.d.ts +6 -0
  64. package/dist/types/client/engines/highlight/adapter-lezer.d.ts +6 -0
  65. package/dist/types/client/engines/highlight/index.d.ts +15 -0
  66. package/dist/types/client/engines/highlight/port.d.ts +64 -0
  67. package/dist/types/client/engines/markdown/adapter-markdown-it.d.ts +6 -0
  68. package/dist/types/client/engines/markdown/blocks.d.ts +29 -0
  69. package/dist/types/client/engines/markdown/index.d.ts +9 -0
  70. package/dist/types/client/engines/markdown/port.d.ts +166 -0
  71. package/dist/types/client/engines/structured/adapter-js-yaml.d.ts +6 -0
  72. package/dist/types/client/engines/structured/index.d.ts +29 -0
  73. package/dist/types/client/engines/structured/port.d.ts +45 -0
  74. package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
  75. package/dist/types/client/infra/notify/DefaultNotifyService.d.ts +2 -3
  76. package/dist/types/client/infra/permission/SomaPermission.d.ts +1 -1
  77. package/dist/types/client/render-ports/notify-renderer.d.ts +1 -56
  78. package/dist/types/client/runtime/SomaRuntimeServices.d.ts +9 -44
  79. package/dist/types/server/host/app-config-composer.d.ts +2 -3
  80. package/dist/types/server/host/host-config-paths.d.cts +2 -7
  81. package/dist/types/server/host/precompiled-manifest.d.ts +5 -0
  82. package/dist/types/server/host/source-packages.d.cts +5 -0
  83. package/dist/types/server/infra/host-config-paths.d.cts +7 -0
  84. package/dist/types/server/page-assets.d.ts +2 -5
  85. package/dist/types/server/runtime-space/store.d.ts +4 -0
  86. package/dist/types/shared/app-config-merge.d.ts +3 -0
  87. package/dist/types/shared/registry-generated/limits.d.ts +82 -4
  88. package/dist/types/shared/types/announcer.types.d.ts +14 -0
  89. package/dist/types/shared/types/notify.types.d.ts +36 -0
  90. package/dist/types/shared/types/role-gate.types.d.ts +8 -0
  91. package/host-native/src/aot-builder.ts +159 -96
  92. package/host-native/src/dev-chunk-gc.ts +104 -0
  93. package/host-native/src/host-prepare.ts +1 -1
  94. package/host-native/src/manifest-http.ts +1 -1
  95. package/host-native/src/page-http.ts +2 -67
  96. package/host-native/src/page-payload-cache.ts +68 -0
  97. package/host-native/src/public-packages.cjs +147 -50
  98. package/package.json +16 -2
@@ -17,7 +17,7 @@ import type { TreeArtifact } from '../../shared/types/component-tree-artifact.ty
17
17
  import {
18
18
  mergeSourcePackageAppConfig,
19
19
  parseAppConfigYaml,
20
- } from '../../server/host/app-config-composer';
20
+ } from '../../shared/app-config-merge';
21
21
 
22
22
  export interface SomaPrecompiledPage {
23
23
  path: string;
@@ -1,7 +1,7 @@
1
1
  /** HOST 配置同步 — 供 bin/soma-sync.cjs 使用 */
2
2
  const fs = require('node:fs');
3
3
  const path = require('node:path');
4
- const { resolveHostConfigRoot } = require('../../server/host/host-config-paths.cjs');
4
+ const { resolveHostConfigRoot } = require('../../server/infra/host-config-paths.cjs');
5
5
 
6
6
  const SYNC_FILES = [
7
7
  'locale.yaml',
@@ -12,12 +12,7 @@ const createJiti = require('jiti');
12
12
  const {
13
13
  resolveAppConfigPath,
14
14
  resolveHostAppConfigPath,
15
- } = require('../../server/host/host-config-paths.cjs');
16
- const {
17
- getSomaAssetSources,
18
- collectPageEntries,
19
- collectIncludes,
20
- } = require('../../server/host/source-packages.cjs');
15
+ } = require('../../server/infra/host-config-paths.cjs');
21
16
 
22
17
  function readFileOrEmpty(filePath) {
23
18
  return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf8') : '';
@@ -81,6 +76,7 @@ class SomaManifestWebpackPlugin {
81
76
  const { loadPageMarkupConfig } = this.jiti('../../server/host/page-markup-config.ts');
82
77
  const { resolveHostTreeCompileContext } = this.jiti('../../server/host/resolve-host-tree-context.ts');
83
78
  const { runPrewarm, computePrewarmInputsDigest } = this.jiti('../../server/runtime-space/prewarm.ts');
79
+ const { getSomaAssetSources, collectPageEntries, collectIncludes } = this.jiti('../../server/host/source-packages.cjs');
84
80
 
85
81
  const sources = getSomaAssetSources(hostDir);
86
82
  const pageEntries = collectPageEntries(sources);
@@ -6218,6 +6218,16 @@ var SOMA_PIPELINE_LIMITS = {
6218
6218
  "file": "core/server/registry/api-registry-store.ts",
6219
6219
  "symbol": "SOMA_PIPELINE_LIMITS"
6220
6220
  },
6221
+ {
6222
+ "module": "soma-core",
6223
+ "file": "core/client/engines/diff/index.ts",
6224
+ "symbol": "SOMA_PIPELINE_LIMITS"
6225
+ },
6226
+ {
6227
+ "module": "soma-core",
6228
+ "file": "core/client/engines/highlight/index.ts",
6229
+ "symbol": "SOMA_PIPELINE_LIMITS"
6230
+ },
6221
6231
  {
6222
6232
  "module": "soma-core",
6223
6233
  "file": "core/server/registry/page-registry-store.ts",
@@ -6520,17 +6530,17 @@ var SOMA_PIPELINE_LIMITS = {
6520
6530
  },
6521
6531
  {
6522
6532
  "module": "soma-ai",
6523
- "file": "src/api/common/RateLimitBackend.ts",
6533
+ "file": "src/server/common/RateLimitBackend.ts",
6524
6534
  "symbol": "SOMA_PIPELINE_LIMITS_AI"
6525
6535
  },
6526
6536
  {
6527
6537
  "module": "soma-ai",
6528
- "file": "src/api/common/RequestBodyLimit.ts",
6538
+ "file": "src/server/common/RequestBodyLimit.ts",
6529
6539
  "symbol": "SOMA_PIPELINE_LIMITS_AI"
6530
6540
  },
6531
6541
  {
6532
6542
  "module": "soma-ai",
6533
- "file": "src/api/service/ai-assistant/Chat.ts",
6543
+ "file": "src/server/services/ai-assistant/Chat.ts",
6534
6544
  "symbol": "SOMA_PIPELINE_LIMITS_AI"
6535
6545
  },
6536
6546
  {
@@ -6545,7 +6555,7 @@ var SOMA_PIPELINE_LIMITS = {
6545
6555
  },
6546
6556
  {
6547
6557
  "module": "soma-ai",
6548
- "file": "src/api/common/TrustedRequestContext.ts",
6558
+ "file": "src/domain/ai-shared/TrustedRequestContext.ts",
6549
6559
  "symbol": "SOMA_PIPELINE_LIMITS_AI_RUNTIME"
6550
6560
  },
6551
6561
  {
@@ -6718,6 +6728,76 @@ var SOMA_PIPELINE_LIMITS = {
6718
6728
  "tokensBytes": 40960,
6719
6729
  "componentBytesPerPage": 163840,
6720
6730
  "overrideBlockBytes": 8192
6731
+ },
6732
+ "contentEngines": {
6733
+ "diff": {
6734
+ "basis": {
6735
+ "maxChars": "\u5355\u4E2A\u5DEE\u5F02\u8BA1\u7B97\u4E24\u4FA7\u5408\u8BA1\u5B57\u6570\u4E0A\u9650\uFF1B\u8D85\u9650\u4E0D\u8BA1\u7B97\u3001\u6574\u6BB5\u66FF\u6362\uFF08\u53C2\u8003\u6587\u672C\u5DEE\u5F02\u7EC4\u4EF6\u7B14\u8BB0 C.5\u300C\u5355\u4E2A\u5DEE\u5F02\u7EC4\u4EF6\u603B\u91CF 200 000 \u5B57\u300D\uFF0C\u5B9E\u6D4B 4\uFF1A\u4E07\u5B57\u7EA7\u9010\u5B57\u6BD4\u8F83\u9700\u8D85\u65F6\u4E0E\u9000\u5316\uFF09",
6736
+ "maxCharsPerCompare": "\u5355\u6B21\u8BCD\u7EA7\u6BD4\u8F83\uFF08\u4E00\u5BF9\u53E5\u5B50 / \u4E00\u6B21 diff \u8C03\u7528\uFF09\u4E24\u4FA7\u5408\u8BA1\u5B57\u6570\u4E0A\u9650\uFF08\u7B14\u8BB0 C.2 BaseOpts maxChars 20 000\uFF09",
6737
+ "timeoutMs": "\u4E00\u6B21 diffProse / diffItems \u7684\u603B\u65F6\u9650\uFF08\u6BEB\u79D2\uFF09\uFF0C\u540C VisualEditor timeout 1000\uFF08\u7B14\u8BB0 C.2\uFF09",
6738
+ "maxItems": "\u6761\u76EE\u5217\u8868\u5355\u4FA7\u6761\u76EE\u6570\u4E0A\u9650\uFF1B\u8D85\u9650\u4E0D\u9010\u6761\u6BD4\u8F83\uFF08\u7B14\u8BB0 C.5\u300C\u6761\u76EE 2 000 \u4E2A\u300D\uFF09",
6739
+ "moveDetectMaxChanged": "\u53D8\u5316\u6761\u76EE\uFF08\u589E + \u5220\uFF09\u8D85\u8FC7\u6B64\u6570\u4E0D\u505A\u79FB\u52A8\u68C0\u6D4B\uFF08\u7B14\u8BB0 C.2\uFF0Cwikidiff2 \u589E\u5220\u5408\u8BA1 > 100 \u4E0D\u68C0\u6D4B\u7684\u653E\u5BBD\u7248\uFF0C\u7ECF\u9A8C\u503C\uFF09",
6740
+ "pairAt": "\u53E5 / \u6BB5\u914D\u5BF9\u9608\u503C\uFF1A\u5B57\u7B26\u591A\u91CD\u96C6 Dice \u2265 \u6B64\u503C\u89C6\u4E3A\u6539\u5199\uFF08VisualEditor diffThreshold 0.5\uFF1B\u5B9E\u6D4B 3 \u7684\u6539\u5199\u53E5\u4E3A 0.84\u20130.89\uFF09",
6741
+ "rewriteBelow": "\u6574\u4F53\u76F8\u4F3C\u5EA6\u4F4E\u4E8E\u6B64\u503C\u6574\u6BB5\u66FF\u6362\uFF08\u7B49\u6548 VE keep < 0.5 \xD7 diff\uFF1B\u5B9E\u6D4B 2 \u7684 C3 \u6574\u53E5\u91CD\u5199\u7EA6 0.16\uFF09",
6742
+ "absorbOrphan": "\u5B64\u5B57\u5438\u6536\uFF1A\u5939\u5728\u4E24\u5904\u6539\u52A8\u95F4\u3001\u957F\u5EA6 \u2264 \u6B64\u503C\uFF08\u5B57\uFF09\u7684\u975E\u6807\u70B9\u76F8\u540C\u7247\u6BB5\u5E76\u5165\u6539\u52A8\uFF08\u5B9E\u6D4B 2 \u7684 C5\u300C\u671F\u300D\uFF09",
6743
+ "absorbOrphanMax": "\u8C03\u7528\u65B9\u53EF\u8C03\u7684\u5B64\u5B57\u5438\u6536\u4E0A\u9650\uFF08\u5B57\uFF09\uFF0C\u9632\u6B62\u628A\u6574\u53E5\u5438\u6210\u6539\u52A8",
6744
+ "titleAt": "\u65E0 key \u6761\u76EE\u6309\u6807\u9898\u914D\u5BF9\u7684\u76F8\u4F3C\u5EA6\u9608\u503C\uFF08\u7B14\u8BB0 C.2 ItemOpts.match.titleAt 0.6\uFF09",
6745
+ "bodyAt": "\u65E0 key \u6761\u76EE\u6309\u6B63\u6587\u914D\u5BF9\u7684\u76F8\u4F3C\u5EA6\u9608\u503C\uFF08\u7B14\u8BB0 C.2 ItemOpts.match.bodyAt 0.5\uFF09",
6746
+ "maxAlignTokens": "\u5E8F\u5217\u5BF9\u9F50\u7684\u4E0D\u540C\u952E\u6570\u4E0A\u9650\uFF08\u6BCF\u4E2A\u952E\u6620\u5C04\u4E3A\u4E00\u4E2A BMP \u79C1\u7528\u533A\u5B57\u7B26\uFF0CU+E000\u2013U+F8FF \u5171 6400 \u4E2A\uFF09",
6747
+ "maxPairMatrix": "\u4E00\u6BB5\u5220\u589E\u533A\u95F4\u5185\u53E5 / \u6BB5\u914D\u5BF9\u7684\u5019\u9009\u77E9\u9635\u4E0A\u9650\uFF08\u5220\u6570 \xD7 \u589E\u6570\uFF09\uFF0C\u8D85\u51FA\u4E0D\u914D\u5BF9\u3001\u6309\u5220 + \u589E\u5448\u73B0\uFF1B\u7ECF\u9A8C\u503C\uFF0C\u8BC1\u636E\u5F31",
6748
+ "maxPairCandidates": "\u65E0 key \u6761\u76EE\u6309\u76F8\u4F3C\u5EA6\u914D\u5BF9\u7684\u5019\u9009\u77E9\u9635\u4E0A\u9650\uFF08\u5269\u4F59\u65E7\u6761\u76EE \xD7 \u5269\u4F59\u65B0\u6761\u76EE\uFF09\uFF1B\u7ECF\u9A8C\u503C\uFF0C\u8BC1\u636E\u5F31",
6749
+ "codeContext": "\u4EE3\u7801\u5DEE\u5F02\u6BCF\u5757\u7684\u4E0A\u4E0B\u6587\u884C\u6570\uFF08\u7B14\u8BB0 C.5\u300C\u4E0A\u4E0B\u6587 3 \u884C\u300D\uFF0C\u540C git diff -U3 / VS Code\uFF09",
6750
+ "codeIntraMaxLine": "\u4EE3\u7801\u6539\u884C\u505A\u884C\u5185\u5B57\u7B26\u5DEE\u5F02\u7684\u5355\u884C\u957F\u5EA6\u4E0A\u9650\uFF08\u5B57\u7B26\uFF09\uFF1B\u66F4\u957F\u7684\u884C\u53EA\u6807\u6574\u884C\u589E\u5220\uFF08\u7ECF\u9A8C\u503C\uFF1A\u538B\u7F29\u540E\u7684\u957F\u884C\u9010\u5B57\u6BD4\u8F83\u65E0\u610F\u4E49\u4E14\u8017\u65F6\uFF09"
6751
+ },
6752
+ "maxChars": 2e5,
6753
+ "maxCharsPerCompare": 2e4,
6754
+ "timeoutMs": 1e3,
6755
+ "maxItems": 2e3,
6756
+ "moveDetectMaxChanged": 500,
6757
+ "pairAt": 0.5,
6758
+ "rewriteBelow": 0.4,
6759
+ "absorbOrphan": 1,
6760
+ "absorbOrphanMax": 4,
6761
+ "titleAt": 0.6,
6762
+ "bodyAt": 0.5,
6763
+ "maxAlignTokens": 6400,
6764
+ "maxPairMatrix": 2500,
6765
+ "maxPairCandidates": 25e4,
6766
+ "codeContext": 3,
6767
+ "codeIntraMaxLine": 500
6768
+ },
6769
+ "highlight": {
6770
+ "basis": {
6771
+ "maxLines": "\u9AD8\u4EAE\u7684\u6700\u591A\u884C\u6570\uFF1B\u8D85\u51FA\u90E8\u5206\u6309\u7EAF\u6587\u672C\uFF08\u53C2\u8003\u6587\u672C\u5DEE\u5F02\u7EC4\u4EF6\u7B14\u8BB0 C.2 \u7AEF\u53E3 2 maxLines 5 000\uFF09",
6772
+ "maxLineLength": "\u5355\u884C\u8D85\u8FC7\u6B64\u5B57\u7B26\u6570\u6574\u884C\u6309\u7EAF\u6587\u672C\uFF08\u7B14\u8BB0 C.2 maxLineLength 2 000\uFF0C\u538B\u7F29\u540E\u7684\u5355\u884C JS / JSON \u5E38\u89C1\uFF09",
6773
+ "timeoutMs": "\u4E00\u6B21\u89E3\u6790\u7684\u65F6\u9650\uFF08\u6BEB\u79D2\uFF09\uFF1BLezer \u6309 advance() \u5206\u6B65\u89E3\u6790\uFF0C\u8D85\u65F6\u6574\u6BB5\u6309\u7EAF\u6587\u672C\uFF08\u7ECF\u9A8C\u503C\uFF0C\u4E0E\u5DEE\u5F02\u7AEF\u53E3\u540C\u53D6 1 000\uFF09",
6774
+ "maxChars": "\u6574\u6BB5\u8D85\u8FC7\u6B64\u5B57\u7B26\u6570\u4E0D\u89E3\u6790\u3001\u6309\u7EAF\u6587\u672C\uFF08\u7ECF\u9A8C\u503C\uFF0C\u8BC1\u636E\u5F31\uFF1A\u7EA6 1 MB \u6587\u672C\uFF09",
6775
+ "jsonSniffMaxChars": "\u8BED\u8A00\u63A8\u65AD\u300C\u6574\u4F53\u80FD JSON.parse\u300D\u53EA\u5BF9\u4E0D\u8D85\u8FC7\u6B64\u5B57\u7B26\u6570\u7684\u6837\u672C\u505A\uFF08\u907F\u514D\u5BF9\u5927\u6587\u672C\u53CD\u590D\u89E3\u6790\uFF1B\u7ECF\u9A8C\u503C\uFF09"
6776
+ },
6777
+ "maxLines": 5e3,
6778
+ "maxLineLength": 2e3,
6779
+ "timeoutMs": 1e3,
6780
+ "maxChars": 1e6,
6781
+ "jsonSniffMaxChars": 2e5
6782
+ },
6783
+ "structured": {
6784
+ "basis": {
6785
+ "maxChars": "JSON / YAML \u539F\u6587\u8D85\u8FC7\u6B64\u5B57\u7B26\u6570\u4E0D\u89E3\u6790\u3001\u6309\u539F\u6587\u663E\u793A\uFF08\u4E0E\u4EE3\u7801\u9AD8\u4EAE\u7AEF\u53E3 maxChars \u540C\u53D6\u7EA6 1 MB\uFF1B\u7ECF\u9A8C\u503C\uFF0C\u8BC1\u636E\u5F31\uFF09",
6786
+ "maxNodes": "\u89E3\u6790\u540E\u503C\u7684\u8282\u70B9\u603B\u6570\u4E0A\u9650\uFF08\u5BF9\u8C61 / \u6570\u7EC4 / \u53F6\u5B50\u5404\u8BA1 1\uFF09\uFF1BYAML \u522B\u540D\u5C55\u5F00\u8D85\u9650\u5373\u6309 too-many-nodes \u964D\u7EA7\uFF0C\u9632\u300C\u5341\u4EBF\u7B11\u58F0\u300D\u5F0F\u522B\u540D\u70B8\u5F39\uFF08\u7ECF\u9A8C\u503C\uFF1A20 \u4E07\u8282\u70B9\u7EA6\u4E3A 1 MB \u7D27\u51D1 JSON \u7684\u91CF\u7EA7\uFF09"
6787
+ },
6788
+ "maxChars": 1e6,
6789
+ "maxNodes": 2e5
6790
+ },
6791
+ "markdown": {
6792
+ "basis": {
6793
+ "maxChars": "Markdown \u539F\u6587\u8D85\u8FC7\u6B64\u5B57\u7B26\u6570\u4E0D\u89E3\u6790\u3001\u6309\u7EAF\u6587\u672C\u663E\u793A\uFF08\u53C2\u8003\u6587\u672C\u5DEE\u5F02\u7EC4\u4EF6\u7B14\u8BB0 C.2 \u7AEF\u53E3 1 limits.maxChars 200 000\uFF09",
6794
+ "maxBlocks": "\u5757\u6570\u4E0A\u9650\uFF0C\u8D85\u51FA\u622A\u65AD\u5E76\u6807 truncated\uFF08\u7B14\u8BB0 C.2 maxBlocks 5 000\uFF09",
6795
+ "summaryChars": "meta.summary \u53D6\u53BB\u6807\u8BB0\u5168\u6587\u7684\u524D N \u5B57\uFF08\u7B14\u8BB0 C.2\u300C\u524D 80 \u5B57\u300D\uFF09"
6796
+ },
6797
+ "maxChars": 2e5,
6798
+ "maxBlocks": 5e3,
6799
+ "summaryChars": 80
6800
+ }
6721
6801
  }
6722
6802
  };
6723
6803
 
@@ -11,8 +11,9 @@
11
11
  // core 只用 CSSOM `style.setProperty` 写,不持有任何几何值;缺省则不写样式,由 UI 体系按 `data-soma-announcer-host` 选择器隐藏。
12
12
  // 去重 / 节流:design 真源没有规则,不做。
13
13
  import { SOMA_PLATFORM_KEYS_CORE } from '../../shared/registry-generated/platform-keys';
14
+ import type { AnnounceOptions, AnnouncePoliteness, Announcer } from '../../shared/types/announcer.types';
14
15
 
15
- export type AnnouncePoliteness = 'polite' | 'assertive';
16
+ export type { AnnounceOptions, AnnouncePoliteness, Announcer };
16
17
 
17
18
  /** politeness 闭集;宿主也按这个顺序创建 */
18
19
  export const ANNOUNCE_POLITENESS: readonly AnnouncePoliteness[] = ['polite', 'assertive'];
@@ -41,21 +42,6 @@ export interface AnnouncerOptions {
41
42
  readonly clock?: AnnouncerClock;
42
43
  }
43
44
 
44
- export interface AnnounceOptions {
45
- readonly politeness?: AnnouncePoliteness;
46
- }
47
-
48
- export interface Announcer {
49
- /** 追加一条播报;空消息忽略;politeness 缺省 polite,未知值抛 TypeError */
50
- announce(message: string, options?: AnnounceOptions): void;
51
- /** 两个常驻宿主 */
52
- hosts(): Readonly<Record<AnnouncePoliteness, HTMLElement>>;
53
- /** 立即移除全部待清理节点 */
54
- clear(): void;
55
- /** 清空、取消计时并移除宿主;之后 announce 忽略 */
56
- dispose(): void;
57
- }
58
-
59
45
  /**
60
46
  * 读 design `announcer.clearAfterMs`;真源(生成物)目前没有 `announcer` 族,缺该键时为 undefined。
61
47
  * 按未知形状守卫读取,不再强转成生成物类型里并不存在的字段。
@@ -3,7 +3,7 @@
3
3
 
4
4
  import type { SomaPageRoot, SomaAppConfig } from '../../shared/types/domain.types';
5
5
  import type { SomaPageState, SomaPageStateConfig } from '../../shared/types/page-state.types';
6
- import type { SomaRuntimeServices } from '../runtime/SomaRuntimeServices';
6
+ import type { SomaRuntimeServicesShape } from './runtime-services.types';
7
7
  import type { SomaPageNav } from '../../shared/types/nav.types';
8
8
  import { readQueryParam } from '../infra/router/router-path';
9
9
  import { runAsync as runAsyncUtil } from './runAsync';
@@ -39,7 +39,7 @@ export abstract class SomaPageRootBase implements SomaPageRoot {
39
39
  _config: SomaAppConfig = {} as SomaAppConfig;
40
40
 
41
41
  /** 由引擎注入的运行时基础设施(router / http / notify 等) */
42
- _services?: SomaRuntimeServices;
42
+ _services?: SomaRuntimeServicesShape;
43
43
 
44
44
  /**
45
45
  * 导航目录的只读视图(E4 / R-15):`services.nav.entries()` 与 `activeOf()` 的当前快照,外壳(顶栏、框架菜单)绑定
@@ -84,6 +84,11 @@ function reservedMemberNames(): ReadonlySet<string> {
84
84
  return names;
85
85
  }
86
86
 
87
+ /** 判断对象是否持有页面根的 _viewContext 钩子(避免把行作用域数据误认成页面根) */
88
+ function isViewRoot(value: unknown): value is { _viewContext(): SomaViewContextHandle } {
89
+ return value !== null && typeof value === 'object' && typeof (value as { _viewContext?: unknown })._viewContext === 'function';
90
+ }
91
+
87
92
  /** 取页面根(原始实例或响应式代理)上的 ctx */
88
93
  function ctxOf(view: unknown): SomaViewContext {
89
94
  return (view as { _viewContext(): SomaViewContextHandle })._viewContext().ctx;
@@ -163,9 +168,13 @@ export function defineSomaView<
163
168
  Object.defineProperty(cls, 'name', { value: name });
164
169
  for (const key of methodNames) {
165
170
  const fn = methods[key]!;
166
- // core 的 `UI_REFRESH | page.方法` 以 (当前页面根, 载荷) 调用;this 与第一实参都是响应式页面根
171
+ // core 的 `UI_REFRESH | page.方法` 或 `ACTION | 方法` 绑定页面根为 this;
172
+ // 行作用域内事件引擎第一实参会传入行数据而非页面根,优先取带 _viewContext 的 this(退回第一实参以兼容显式 unbound 调用)
167
173
  Object.defineProperty(cls.prototype, key, {
168
- value: function (this: unknown, view: unknown, payload: unknown): unknown { const v = view ?? this; return fn(v, payload, ctxOf(v)); },
174
+ value: function (this: unknown, view: unknown, payload: unknown): unknown {
175
+ const v = isViewRoot(this) ? this : (isViewRoot(view) ? view : (view ?? this));
176
+ return fn(v, payload, ctxOf(v));
177
+ },
169
178
  writable: true,
170
179
  configurable: true,
171
180
  enumerable: false,
@@ -0,0 +1,57 @@
1
+ // 运行时基础设施服务表形状类型(CORE-L01:放在 client/base 基础支撑层,供同层 SomaPageRootBase 引用,
2
+ // 既不反向依赖 client/runtime/SomaRuntimeServices.ts,也不违反 KI-8 对 core/shared 的隔离规则;
3
+ // 完整服务表在 client/runtime/SomaRuntimeServices.ts 继承并补齐领域引擎端口与返回栈类型)。
4
+
5
+ import type { TokenAuthService } from '../infra/auth/TokenAuthService';
6
+ import type { MemoryCache } from '../infra/cache/MemoryCache';
7
+ import type { SomaConfig } from '../infra/config/SomaConfig';
8
+ import type { SomaAppConfigPort } from '../infra/config/feature-flags';
9
+ import type { SomaEventBus } from '../infra/event-bus/SomaEventBus';
10
+ import type { SomaHttpService } from '../infra/http/SomaHttpService';
11
+ import type { SomaLocaleCatalog } from '../infra/i18n/locale-catalog';
12
+ import type { SomaIdentityPort } from '../infra/identity/identity-port';
13
+ import type { ConsoleLogger } from '../infra/logger/ConsoleLogger';
14
+ import type { DefaultNotifyService } from '../infra/notify/DefaultNotifyService';
15
+ import type { SomaPermission } from '../infra/permission/SomaPermission';
16
+ import type { IRealtimeService } from '../infra/realtime/IRealtimeService';
17
+ import type { SomaRouter } from '../infra/router/SomaRouter';
18
+ import type { IStorageService } from '../infra/storage/IStorageService';
19
+ import type { SomaTimer } from '../infra/timer/SomaTimer';
20
+ import type { SomaObservationChannel } from '../observability/runtime-observer';
21
+ import type { SomaRuntimeServicesBase } from '../../shared/types/domain.types';
22
+ import type { SomaNavPort } from '../../shared/types/nav.types';
23
+ import type { SomaShortcutRegistry } from '../../shared/types/write-runtime.types';
24
+
25
+ /** 界面中途提交服务(见 SomaRuntimeServices.ui) */
26
+ export interface SomaUiService {
27
+ publish(): Promise<void>;
28
+ }
29
+
30
+ /**
31
+ * 运行时基础设施形状契约(`SomaPageRootBase._services` 与 `SomaRuntimeServices` 共用)。
32
+ * `engines` 与 `navHistory` 为领域层具体类型,在此以泛型槽位留口,避免基础层反向依赖领域层。
33
+ */
34
+ export interface SomaRuntimeServicesShape<TEngines = unknown, TNavHistory = unknown>
35
+ extends SomaRuntimeServicesBase {
36
+ router: SomaRouter;
37
+ notify: DefaultNotifyService;
38
+ logger: ConsoleLogger;
39
+ http: SomaHttpService;
40
+ storage: IStorageService;
41
+ timer: SomaTimer;
42
+ eventBus: SomaEventBus;
43
+ cache: MemoryCache<unknown>;
44
+ config: SomaConfig;
45
+ auth: TokenAuthService;
46
+ permission: SomaPermission;
47
+ i18n: SomaLocaleCatalog;
48
+ realtime: IRealtimeService;
49
+ ui: SomaUiService;
50
+ observation: SomaObservationChannel;
51
+ readonly engines: TEngines;
52
+ nav?: SomaNavPort;
53
+ readonly identity: SomaIdentityPort;
54
+ readonly navHistory?: TNavHistory;
55
+ readonly appConfig?: SomaAppConfigPort;
56
+ readonly shortcuts?: SomaShortcutRegistry;
57
+ }
@@ -9,15 +9,9 @@
9
9
  // - 角色值只在函数内比较,不写入 DOM、诊断、观测或控制台;
10
10
  // - 请求不附带任何 core 生成的身份字段(这里不碰 http)。
11
11
 
12
- /** Host 提供的角色集来源(`SomaBootstrapOptions.auth`) */
13
- export interface SomaAuthOption {
14
- getRoles(): readonly string[];
15
- }
12
+ import type { SomaAuthOption, SomaRoleGate } from '../../shared/types/role-gate.types';
16
13
 
17
- export interface SomaRoleGate {
18
- /** 当前角色集与 `required` 有交集才为真 */
19
- hasAnyRole(required: readonly string[]): boolean;
20
- }
14
+ export type { SomaAuthOption, SomaRoleGate };
21
15
 
22
16
  function readRoles(auth: SomaAuthOption | undefined): ReadonlySet<string> {
23
17
  if (auth === undefined || typeof auth.getRoles !== 'function') return new Set();
@@ -388,6 +388,7 @@ export class SomaEventEngine<TContext extends Record<string, unknown> = Record<s
388
388
  runtime.status = 'error';
389
389
  runtime.message = error instanceof Error ? error.message : String(error);
390
390
  result = false;
391
+ console.error(`[soma-core][引擎] ${config.somaId}.${config.domEvent} (${config.funcPath}) 执行失败:${runtime.message}`);
391
392
  } finally {
392
393
  if (rowContext instanceof SomaRowScope) this.pendingRows.delete(element);
393
394
  else this.pendingSet.delete(config.somaId);
@@ -1,14 +1,28 @@
1
1
  // jsdiff 缺省适配器(core 引擎端口设计 §7.2):全仓唯一 import `diff` 的文件,只用动态 import()。
2
2
  // 输出纯数据片段;不拼标记 HTML。
3
+ // `words-zh`:`diffWords` + `intlSegmenter`(jsdiff ≥ 8.0.4 才可靠,仓库固定 8.0.4);运行时没有 `Intl.Segmenter` 时退回 `diffChars`。
4
+ // `timeout`:交给 jsdiff,超时库返回 undefined → 本适配器返回 null(端口据此退化)。
3
5
 
4
6
  import { loadEngineModule, type EngineLoadTelemetry } from '../load';
5
7
  import type { DiffMode, DiffOptions, DiffPart, SomaDiffAdapter } from './port';
6
8
 
7
9
  interface JsdiffChange { readonly value: string; readonly added?: boolean; readonly removed?: boolean }
10
+ interface JsdiffBaseOptions { timeout?: number }
8
11
  interface JsdiffModule {
9
- diffChars(a: string, b: string): JsdiffChange[];
10
- diffWords(a: string, b: string): JsdiffChange[];
11
- diffLines(a: string, b: string, options?: { ignoreWhitespace?: boolean }): JsdiffChange[];
12
+ diffChars(a: string, b: string, options?: JsdiffBaseOptions): JsdiffChange[] | undefined;
13
+ diffWords(a: string, b: string, options?: JsdiffBaseOptions & { intlSegmenter?: unknown }): JsdiffChange[] | undefined;
14
+ diffLines(a: string, b: string, options?: JsdiffBaseOptions & { ignoreWhitespace?: boolean }): JsdiffChange[] | undefined;
15
+ }
16
+
17
+ interface SegmenterCtor { new (locale: string, options: { granularity: 'word' }): unknown }
18
+
19
+ /** 运行时的 `Intl.Segmenter`(没有则 null);词粒度分词器只建一次 */
20
+ let wordSegmenter: unknown;
21
+ function zhWordSegmenter(): unknown {
22
+ if (wordSegmenter !== undefined) return wordSegmenter;
23
+ const ctor = (Intl as unknown as { Segmenter?: SegmenterCtor }).Segmenter;
24
+ wordSegmenter = typeof ctor === 'function' ? new ctor('zh', { granularity: 'word' }) : null;
25
+ return wordSegmenter;
12
26
  }
13
27
 
14
28
  export interface JsdiffAdapterOptions { readonly telemetry?: EngineLoadTelemetry }
@@ -18,12 +32,17 @@ export function createJsdiffAdapter(adapterOptions: JsdiffAdapterOptions = {}):
18
32
  loadEngineModule<JsdiffModule>('diff', () => import('diff') as unknown as Promise<JsdiffModule>, { telemetry: adapterOptions.telemetry });
19
33
 
20
34
  return {
21
- async diff(a: string, b: string, mode: DiffMode, options?: DiffOptions): Promise<readonly DiffPart[]> {
35
+ async diff(a: string, b: string, mode: DiffMode, options?: DiffOptions): Promise<readonly DiffPart[] | null> {
22
36
  const lib = await load();
23
- const changes =
24
- mode === 'chars' ? lib.diffChars(a, b)
25
- : mode === 'words' ? lib.diffWords(a, b)
26
- : lib.diffLines(a, b, options?.ignoreWhitespace === true ? { ignoreWhitespace: true } : undefined);
37
+ const base: JsdiffBaseOptions = options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {};
38
+ let changes: JsdiffChange[] | undefined;
39
+ if (mode === 'chars') changes = lib.diffChars(a, b, base);
40
+ else if (mode === 'words') changes = lib.diffWords(a, b, base);
41
+ else if (mode === 'words-zh') {
42
+ const seg = zhWordSegmenter();
43
+ changes = seg === null ? lib.diffChars(a, b, base) : lib.diffWords(a, b, { ...base, intlSegmenter: seg });
44
+ } else changes = lib.diffLines(a, b, options?.ignoreWhitespace === true ? { ...base, ignoreWhitespace: true } : base);
45
+ if (changes === undefined) return null;
27
46
  const parts: DiffPart[] = [];
28
47
  for (const change of changes) {
29
48
  if (change.value === '') continue;
@@ -0,0 +1,205 @@
1
+ // 代码差异与 Markdown 差异流水线(内容展示批次 ⑥;纯函数 + 适配器调用,零 DOM,不 import soma 其它模块)。
2
+ // 代码:按行 LCS 对齐(alignKeys)→ 删增区间内按相似度配对成「改行」并做行内字符差异 → 按上下文行数切块(hunk)。
3
+ // Markdown:源码按块切分(空行分隔、围栏代码整块)→ 块序列对齐(键 = 块类型 + 归一化文字)→ 同类型且相似的块配对,
4
+ // 块内做中文词级差异;结构变化(标题层级、列表有序 / 无序、代码语言)给块级说明。渲染交给组件(块用 Markdown 端口渲染)。
5
+
6
+ import type { CodeDiff, CodeDiffHunk, CodeDiffLine, DiffFragment, DiffPart, MarkdownBlockKind, MarkdownDiff, MarkdownDiffBlock } from './port';
7
+ import { alignKeys, diceSimilarity, hasHan, pairAligned, safeDiff, tidy, type ProseRun } from './prose';
8
+
9
+ export interface CodeConfig {
10
+ readonly maxChars: number;
11
+ readonly maxAlignTokens: number;
12
+ readonly maxPairMatrix: number;
13
+ readonly pairAt: number;
14
+ /** 每块上下文行数 */
15
+ readonly context: number;
16
+ /** 行内字符差异只对不超过此长度的行做 */
17
+ readonly intraMaxLine: number;
18
+ }
19
+
20
+ const toFrags = (parts: readonly DiffPart[]): DiffFragment[] =>
21
+ tidy(parts.map((p) => ({ v: p.text, op: p.op === 'equal' ? 'eq' as const : p.op === 'insert' ? 'ins' as const : 'del' as const })));
22
+
23
+ const linesOf = (s: string): string[] => (s === '' ? [] : s.replace(/\r\n?/gu, '\n').split('\n'));
24
+ const squash = (s: string): string => s.replace(/\s+/gu, '');
25
+
26
+ /** 行级操作 → 按上下文切块(纯函数) */
27
+ export function hunksOf(lines: readonly CodeDiffLine[], context: number): CodeDiffHunk[] {
28
+ const changed: number[] = [];
29
+ lines.forEach((l, i) => { if (l.op !== 'eq') changed.push(i); });
30
+ if (changed.length === 0) return [];
31
+ const ranges: [number, number][] = [];
32
+ for (const i of changed) {
33
+ const from = Math.max(0, i - context);
34
+ const to = Math.min(lines.length - 1, i + context);
35
+ const last = ranges[ranges.length - 1];
36
+ if (last && from <= last[1] + 1) last[1] = Math.max(last[1], to);
37
+ else ranges.push([from, to]);
38
+ }
39
+ return ranges.map(([from, to]) => {
40
+ const slice = lines.slice(from, to + 1);
41
+ const firstA = slice.find((l) => l.a !== undefined)?.a ?? 0;
42
+ const firstB = slice.find((l) => l.b !== undefined)?.b ?? 0;
43
+ return {
44
+ aStart: firstA, aLines: slice.filter((l) => l.a !== undefined).length,
45
+ bStart: firstB, bLines: slice.filter((l) => l.b !== undefined).length,
46
+ from, to, lines: slice,
47
+ };
48
+ });
49
+ }
50
+
51
+ export async function runCode(run: ProseRun, cfg: CodeConfig, a: string, b: string): Promise<CodeDiff> {
52
+ const aLines = linesOf(a);
53
+ const bLines = linesOf(b);
54
+ const whitespaceOnly = a !== b && squash(a) === squash(b);
55
+ if (a === b) {
56
+ const lines = aLines.map((text, i): CodeDiffLine => ({ op: 'eq', a: i + 1, b: i + 1, text }));
57
+ return { kind: 'same', lines, hunks: [], stats: { added: 0, removed: 0, modified: 0 }, whitespaceOnly: false };
58
+ }
59
+ const plain = (degraded: 'too-large' | 'timeout'): CodeDiff => {
60
+ const lines: CodeDiffLine[] = [
61
+ ...aLines.map((text, i): CodeDiffLine => ({ op: 'del', a: i + 1, text })),
62
+ ...bLines.map((text, i): CodeDiffLine => ({ op: 'ins', b: i + 1, text })),
63
+ ];
64
+ return { kind: 'changed', lines, hunks: [{ aStart: 1, aLines: aLines.length, bStart: 1, bLines: bLines.length, from: 0, to: lines.length - 1, lines }], stats: { added: bLines.length, removed: aLines.length, modified: 0 }, whitespaceOnly, degraded };
65
+ };
66
+ if (a.length + b.length > cfg.maxChars) return plain('too-large');
67
+ const ops = await alignKeys(run, aLines, bLines, cfg.maxAlignTokens);
68
+ if (ops === null) return plain(run.degraded === 'timeout' ? 'timeout' : 'too-large');
69
+ const units = pairAligned(ops, aLines, bLines, cfg.pairAt, cfg.maxPairMatrix);
70
+ const lines: CodeDiffLine[] = [];
71
+ let added = 0;
72
+ let removed = 0;
73
+ let modified = 0;
74
+ // 改行:先列删行、再列增行(合并视图「删行在增行上方」);连续的改行成组输出
75
+ let pendingDel: CodeDiffLine[] = [];
76
+ let pendingIns: CodeDiffLine[] = [];
77
+ const flush = (): void => { lines.push(...pendingDel, ...pendingIns); pendingDel = []; pendingIns = []; };
78
+ for (const u of units) {
79
+ if (u.op === 'eq') { flush(); lines.push({ op: 'eq', a: u.a + 1, b: u.b + 1, text: aLines[u.a]! }); continue; }
80
+ if (u.op === 'del') { removed += 1; pendingDel.push({ op: 'del', a: u.a + 1, text: aLines[u.a]! }); continue; }
81
+ if (u.op === 'ins') { added += 1; pendingIns.push({ op: 'ins', b: u.b + 1, text: bLines[u.b]! }); continue; }
82
+ modified += 1;
83
+ const la = aLines[u.a]!;
84
+ const lb = bLines[u.b]!;
85
+ let frags: DiffFragment[] | null = null;
86
+ if (la.length <= cfg.intraMaxLine && lb.length <= cfg.intraMaxLine) {
87
+ const parts = await safeDiff(run, la, lb, 'chars');
88
+ if (parts !== null) frags = toFrags(parts);
89
+ }
90
+ pendingDel.push({ op: 'del', a: u.a + 1, text: la, pair: u.b + 1, ...(frags ? { fragments: frags.filter((f) => f.op !== 'ins') } : {}) });
91
+ pendingIns.push({ op: 'ins', b: u.b + 1, text: lb, pair: u.a + 1, ...(frags ? { fragments: frags.filter((f) => f.op !== 'del') } : {}) });
92
+ }
93
+ flush();
94
+ const out: CodeDiff = { kind: 'changed', lines, hunks: hunksOf(lines, cfg.context), stats: { added, removed, modified }, whitespaceOnly };
95
+ return run.degraded !== undefined ? { ...out, degraded: run.degraded === 'timeout' ? 'timeout' : 'too-large' } : out;
96
+ }
97
+
98
+ // ── Markdown ──
99
+
100
+ /** 源码 → 块(空行分隔;围栏代码整块,围栏里的空行不切);纯函数 */
101
+ export function splitMarkdownBlocks(source: string): string[] {
102
+ const out: string[] = [];
103
+ let cur: string[] = [];
104
+ let fence: string | null = null;
105
+ for (const line of source.replace(/\r\n?/gu, '\n').split('\n')) {
106
+ const m = /^\s{0,3}(`{3,}|~{3,})/u.exec(line);
107
+ if (fence !== null) {
108
+ cur.push(line);
109
+ if (m && m[1]!.startsWith(fence)) { out.push(cur.join('\n')); cur = []; fence = null; }
110
+ continue;
111
+ }
112
+ if (m) { if (cur.length > 0) out.push(cur.join('\n')); cur = [line]; fence = m[1]!.slice(0, 3); continue; }
113
+ if (line.trim() === '') { if (cur.length > 0) out.push(cur.join('\n')); cur = []; continue; }
114
+ cur.push(line);
115
+ }
116
+ if (cur.length > 0) out.push(cur.join('\n'));
117
+ return out;
118
+ }
119
+
120
+ export function markdownBlockKind(block: string): { kind: MarkdownBlockKind; detail: string } {
121
+ const first = block.split('\n', 1)[0]!.trimStart();
122
+ const h = /^(#{1,6})\s/u.exec(first);
123
+ if (h) return { kind: 'heading', detail: String(h[1]!.length) };
124
+ const f = /^(`{3,}|~{3,})\s*([^\s`]*)/u.exec(first);
125
+ if (f) return { kind: 'code', detail: f[2] ?? '' };
126
+ if (/^>/u.test(first)) return { kind: 'quote', detail: '' };
127
+ if (/^\d+[.)]\s/u.test(first)) return { kind: 'list', detail: 'ordered' };
128
+ if (/^[-*+]\s/u.test(first)) return { kind: 'list', detail: 'bullet' };
129
+ if (/^\|/u.test(first)) return { kind: 'table', detail: '' };
130
+ if (/^(-{3,}|\*{3,}|_{3,})\s*$/u.test(first)) return { kind: 'hr', detail: '' };
131
+ return { kind: 'paragraph', detail: '' };
132
+ }
133
+
134
+ /** 块的可比文字:去掉块首标记(# / > / 列表符号 / 围栏行),空白归一 */
135
+ export function markdownBlockText(block: string, kind: MarkdownBlockKind): string {
136
+ if (kind === 'code') return block.split('\n').slice(1).filter((l, i, arr) => !(i === arr.length - 1 && /^\s*(`{3,}|~{3,})\s*$/u.test(l))).join('\n');
137
+ return block.split('\n').map((l) => l.replace(/^\s{0,3}(#{1,6}\s+|>\s?|[-*+]\s+(\[[ xX]\]\s+)?|\d+[.)]\s+)/u, '')).join('\n').trim();
138
+ }
139
+
140
+ export interface MarkdownConfig extends CodeConfig { readonly maxBlocks: number }
141
+
142
+ export async function runMarkdown(run: ProseRun, cfg: MarkdownConfig, a: string, b: string): Promise<MarkdownDiff> {
143
+ if (a === b) {
144
+ const blocks = splitMarkdownBlocks(a).map((s): MarkdownDiffBlock => ({ op: 'eq', kind: markdownBlockKind(s).kind, before: s, after: s }));
145
+ return { kind: 'same', blocks, stats: { added: 0, removed: 0, modified: 0, same: blocks.length } };
146
+ }
147
+ const aBlocks = splitMarkdownBlocks(a);
148
+ const bBlocks = splitMarkdownBlocks(b);
149
+ if (a.length + b.length > cfg.maxChars || aBlocks.length + bBlocks.length > cfg.maxBlocks) {
150
+ return { kind: 'changed', blocks: [], stats: { added: 0, removed: 0, modified: 0, same: 0 }, degraded: 'too-large' };
151
+ }
152
+ const meta = (s: string): { kind: MarkdownBlockKind; detail: string; text: string } => { const k = markdownBlockKind(s); return { ...k, text: markdownBlockText(s, k.kind) }; };
153
+ const am = aBlocks.map(meta);
154
+ const bm = bBlocks.map(meta);
155
+ // 对齐键:类型 + 归一化文字(标题层级、列表种类不进键,变化由块级说明给出)
156
+ const key = (m: { kind: string; text: string }): string => `${m.kind}\u0000${m.text.replace(/\s+/gu, ' ')}`;
157
+ const ops = await alignKeys(run, am.map(key), bm.map(key), cfg.maxAlignTokens);
158
+ if (ops === null) return { kind: 'changed', blocks: [], stats: { added: 0, removed: 0, modified: 0, same: 0 }, degraded: run.degraded === 'timeout' ? 'timeout' : 'too-large' };
159
+ // 配对:同类型才配(相似度用块文字);不同类型的键前缀不同,相似度天然低
160
+ const units = pairAligned(ops, am.map((m) => `${m.kind}:${m.text}`), bm.map((m) => `${m.kind}:${m.text}`), cfg.pairAt, cfg.maxPairMatrix);
161
+ const blocks: MarkdownDiffBlock[] = [];
162
+ let added = 0;
163
+ let removed = 0;
164
+ let modified = 0;
165
+ let same = 0;
166
+ for (const u of units) {
167
+ if (u.op === 'eq') {
168
+ const x = am[u.a]!;
169
+ const y = bm[u.b]!;
170
+ const notes = structureNotes(x, y);
171
+ if (notes.length === 0 && aBlocks[u.a] === bBlocks[u.b]) { same += 1; blocks.push({ op: 'eq', kind: y.kind, before: aBlocks[u.a]!, after: bBlocks[u.b]! }); continue; }
172
+ modified += 1;
173
+ blocks.push({ op: 'mod', kind: y.kind, before: aBlocks[u.a]!, after: bBlocks[u.b]!, fragments: [{ v: y.text, op: 'eq' }], ...(notes.length > 0 ? { notes } : {}) });
174
+ continue;
175
+ }
176
+ if (u.op === 'del') { removed += 1; blocks.push({ op: 'del', kind: am[u.a]!.kind, before: aBlocks[u.a]! }); continue; }
177
+ if (u.op === 'ins') { added += 1; blocks.push({ op: 'ins', kind: bm[u.b]!.kind, after: bBlocks[u.b]! }); continue; }
178
+ const x = am[u.a]!;
179
+ const y = bm[u.b]!;
180
+ if (x.kind !== y.kind) {
181
+ removed += 1; added += 1;
182
+ blocks.push({ op: 'del', kind: x.kind, before: aBlocks[u.a]! }, { op: 'ins', kind: y.kind, after: bBlocks[u.b]! });
183
+ continue;
184
+ }
185
+ modified += 1;
186
+ const mode = hasHan(x.text) || hasHan(y.text) ? 'words-zh' as const : 'words' as const;
187
+ const parts = x.kind === 'code' ? null : await safeDiff(run, x.text, y.text, mode);
188
+ const notes = structureNotes(x, y);
189
+ blocks.push({
190
+ op: 'mod', kind: y.kind, before: aBlocks[u.a]!, after: bBlocks[u.b]!,
191
+ ...(parts !== null ? { fragments: toFrags(parts) } : {}),
192
+ ...(notes.length > 0 ? { notes } : {}),
193
+ similarity: diceSimilarity(x.text, y.text),
194
+ });
195
+ }
196
+ const out: MarkdownDiff = { kind: 'changed', blocks, stats: { added, removed, modified, same } };
197
+ return run.degraded !== undefined ? { ...out, degraded: run.degraded === 'timeout' ? 'timeout' : 'too-large' } : out;
198
+ }
199
+
200
+ /** 结构变化说明:标题层级、列表有序 / 无序、代码块语言(值只给数据,文案由组件定) */
201
+ function structureNotes(x: { kind: MarkdownBlockKind; detail: string }, y: { kind: MarkdownBlockKind; detail: string }): { readonly what: 'heading-level' | 'list-type' | 'code-language'; readonly before: string; readonly after: string }[] {
202
+ if (x.kind !== y.kind || x.detail === y.detail) return [];
203
+ const what = x.kind === 'heading' ? 'heading-level' as const : x.kind === 'list' ? 'list-type' as const : x.kind === 'code' ? 'code-language' as const : null;
204
+ return what === null ? [] : [{ what, before: x.detail, after: y.detail }];
205
+ }