soma-core 2.2.7 → 2.2.9

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 (109) 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 +80 -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/data-object-resolver.ts +36 -5
  10. package/core/client/data/role-gate.ts +2 -8
  11. package/core/client/engine/event-engine.ts +1 -0
  12. package/core/client/engines/chart/adapter-echarts.ts +75 -2
  13. package/core/client/engines/chart/index.ts +18 -0
  14. package/core/client/engines/chart/port.ts +13 -0
  15. package/core/client/engines/diff/adapter-jsdiff.ts +27 -8
  16. package/core/client/engines/diff/index.ts +81 -6
  17. package/core/client/engines/diff/items.ts +212 -0
  18. package/core/client/engines/diff/port.ts +140 -3
  19. package/core/client/engines/diff/prose.ts +443 -0
  20. package/core/client/engines/engine-adapters.ts +6 -0
  21. package/core/client/engines/highlight/adapter-lezer.ts +109 -0
  22. package/core/client/engines/highlight/index.ts +135 -0
  23. package/core/client/engines/highlight/port.ts +92 -0
  24. package/core/client/engines/markdown/adapter-markdown-it.ts +65 -0
  25. package/core/client/engines/markdown/blocks.ts +335 -0
  26. package/core/client/engines/markdown/index.ts +51 -0
  27. package/core/client/engines/markdown/port.ts +94 -0
  28. package/core/client/engines/markdown/vendor-modules.d.ts +6 -0
  29. package/core/client/engines/structured/adapter-js-yaml.ts +33 -0
  30. package/core/client/engines/structured/index.ts +139 -0
  31. package/core/client/engines/structured/port.ts +59 -0
  32. package/core/client/infra/http/SomaHttpService.ts +2 -4
  33. package/core/client/infra/notify/DefaultNotifyService.ts +2 -3
  34. package/core/client/infra/permission/SomaPermission.ts +1 -1
  35. package/core/client/render-ports/notify-renderer.ts +2 -46
  36. package/core/client/runtime/SomaRuntimeServices.ts +16 -45
  37. package/core/server/host/app-config-composer.ts +6 -52
  38. package/core/server/host/host-config-paths.cjs +2 -100
  39. package/core/server/host/precompiled-manifest.ts +69 -0
  40. package/core/server/infra/host-config-paths.cjs +100 -0
  41. package/core/server/page-assets.ts +2 -70
  42. package/core/server/runtime-space/bindings.ts +76 -1
  43. package/core/server/runtime-space/digest.ts +6 -0
  44. package/core/server/runtime-space/index.ts +1 -1
  45. package/core/server/runtime-space/prewarm.ts +8 -8
  46. package/core/server/runtime-space/store.ts +23 -7
  47. package/core/server/runtime-space/types.ts +3 -2
  48. package/core/shared/app-config-merge.ts +59 -0
  49. package/core/shared/registry-generated/limits.ts +80 -4
  50. package/core/shared/types/announcer.types.ts +18 -0
  51. package/core/shared/types/notify.types.ts +26 -0
  52. package/core/shared/types/role-gate.types.ts +11 -0
  53. package/dist/browser/runtime-bundle.manifest.json +50 -7
  54. package/dist/browser/soma-runtime.js +120022 -103991
  55. package/dist/core/index.cjs +113888 -97846
  56. package/dist/host-native/aot-builder.cjs +277 -189
  57. package/dist/host-native/native-server.cjs +245 -84
  58. package/dist/lsp/component-tree.cjs +80 -4
  59. package/dist/types/build/compiler/full-manifest-builder.d.ts +1 -1
  60. package/dist/types/client/a11y/announcer.d.ts +2 -14
  61. package/dist/types/client/base/SomaPageRootBase.d.ts +2 -2
  62. package/dist/types/client/base/runtime-services.types.d.ts +50 -0
  63. package/dist/types/client/data/role-gate.d.ts +2 -8
  64. package/dist/types/client/engines/chart/index.d.ts +1 -1
  65. package/dist/types/client/engines/chart/port.d.ts +15 -0
  66. package/dist/types/client/engines/diff/index.d.ts +1 -1
  67. package/dist/types/client/engines/diff/items.d.ts +24 -0
  68. package/dist/types/client/engines/diff/port.d.ts +124 -2
  69. package/dist/types/client/engines/diff/prose.d.ts +80 -0
  70. package/dist/types/client/engines/engine-adapters.d.ts +6 -0
  71. package/dist/types/client/engines/highlight/adapter-lezer.d.ts +6 -0
  72. package/dist/types/client/engines/highlight/index.d.ts +15 -0
  73. package/dist/types/client/engines/highlight/port.d.ts +64 -0
  74. package/dist/types/client/engines/markdown/adapter-markdown-it.d.ts +6 -0
  75. package/dist/types/client/engines/markdown/blocks.d.ts +29 -0
  76. package/dist/types/client/engines/markdown/index.d.ts +9 -0
  77. package/dist/types/client/engines/markdown/port.d.ts +166 -0
  78. package/dist/types/client/engines/structured/adapter-js-yaml.d.ts +6 -0
  79. package/dist/types/client/engines/structured/index.d.ts +29 -0
  80. package/dist/types/client/engines/structured/port.d.ts +45 -0
  81. package/dist/types/client/infra/http/SomaHttpService.d.ts +1 -1
  82. package/dist/types/client/infra/notify/DefaultNotifyService.d.ts +2 -3
  83. package/dist/types/client/infra/permission/SomaPermission.d.ts +1 -1
  84. package/dist/types/client/render-ports/notify-renderer.d.ts +1 -56
  85. package/dist/types/client/runtime/SomaRuntimeServices.d.ts +9 -44
  86. package/dist/types/server/host/app-config-composer.d.ts +2 -3
  87. package/dist/types/server/host/host-config-paths.d.cts +2 -7
  88. package/dist/types/server/host/precompiled-manifest.d.ts +5 -0
  89. package/dist/types/server/infra/host-config-paths.d.cts +7 -0
  90. package/dist/types/server/page-assets.d.ts +2 -5
  91. package/dist/types/server/runtime-space/bindings.d.ts +9 -0
  92. package/dist/types/server/runtime-space/digest.d.ts +5 -0
  93. package/dist/types/server/runtime-space/index.d.ts +1 -1
  94. package/dist/types/server/runtime-space/prewarm.d.ts +2 -2
  95. package/dist/types/server/runtime-space/store.d.ts +4 -0
  96. package/dist/types/server/runtime-space/types.d.ts +3 -2
  97. package/dist/types/shared/app-config-merge.d.ts +3 -0
  98. package/dist/types/shared/registry-generated/limits.d.ts +78 -4
  99. package/dist/types/shared/types/announcer.types.d.ts +14 -0
  100. package/dist/types/shared/types/notify.types.d.ts +36 -0
  101. package/dist/types/shared/types/role-gate.types.d.ts +8 -0
  102. package/host-native/src/aot-builder.ts +12 -5
  103. package/host-native/src/dev-chunk-gc.ts +104 -0
  104. package/host-native/src/host-prepare.ts +19 -2
  105. package/host-native/src/manifest-http.ts +1 -1
  106. package/host-native/src/native-server.ts +16 -0
  107. package/host-native/src/page-http.ts +2 -67
  108. package/host-native/src/page-payload-cache.ts +68 -0
  109. package/package.json +16 -2
@@ -81,6 +81,14 @@ export declare const SOMA_PIPELINE_LIMITS: {
81
81
  readonly module: "soma-core";
82
82
  readonly file: "core/server/registry/api-registry-store.ts";
83
83
  readonly symbol: "SOMA_PIPELINE_LIMITS";
84
+ }, {
85
+ readonly module: "soma-core";
86
+ readonly file: "core/client/engines/diff/index.ts";
87
+ readonly symbol: "SOMA_PIPELINE_LIMITS";
88
+ }, {
89
+ readonly module: "soma-core";
90
+ readonly file: "core/client/engines/highlight/index.ts";
91
+ readonly symbol: "SOMA_PIPELINE_LIMITS";
84
92
  }, {
85
93
  readonly module: "soma-core";
86
94
  readonly file: "core/server/registry/page-registry-store.ts";
@@ -323,15 +331,15 @@ export declare const SOMA_PIPELINE_LIMITS: {
323
331
  readonly symbol: "SOMA_PIPELINE_LIMITS_AI";
324
332
  }, {
325
333
  readonly module: "soma-ai";
326
- readonly file: "src/api/common/RateLimitBackend.ts";
334
+ readonly file: "src/server/common/RateLimitBackend.ts";
327
335
  readonly symbol: "SOMA_PIPELINE_LIMITS_AI";
328
336
  }, {
329
337
  readonly module: "soma-ai";
330
- readonly file: "src/api/common/RequestBodyLimit.ts";
338
+ readonly file: "src/server/common/RequestBodyLimit.ts";
331
339
  readonly symbol: "SOMA_PIPELINE_LIMITS_AI";
332
340
  }, {
333
341
  readonly module: "soma-ai";
334
- readonly file: "src/api/service/ai-assistant/Chat.ts";
342
+ readonly file: "src/server/services/ai-assistant/Chat.ts";
335
343
  readonly symbol: "SOMA_PIPELINE_LIMITS_AI";
336
344
  }, {
337
345
  readonly module: "soma-ai";
@@ -343,7 +351,7 @@ export declare const SOMA_PIPELINE_LIMITS: {
343
351
  readonly symbol: "SOMA_PIPELINE_LIMITS_AI";
344
352
  }, {
345
353
  readonly module: "soma-ai";
346
- readonly file: "src/api/common/TrustedRequestContext.ts";
354
+ readonly file: "src/domain/ai-shared/TrustedRequestContext.ts";
347
355
  readonly symbol: "SOMA_PIPELINE_LIMITS_AI_RUNTIME";
348
356
  }, {
349
357
  readonly module: "soma-ai";
@@ -506,4 +514,70 @@ export declare const SOMA_PIPELINE_LIMITS: {
506
514
  readonly componentBytesPerPage: 163840;
507
515
  readonly overrideBlockBytes: 8192;
508
516
  };
517
+ readonly contentEngines: {
518
+ readonly diff: {
519
+ readonly basis: {
520
+ readonly maxChars: "单个差异计算两侧合计字数上限;超限不计算、整段替换(参考文本差异组件笔记 C.5「单个差异组件总量 200 000 字」,实测 4:万字级逐字比较需超时与退化)";
521
+ readonly maxCharsPerCompare: "单次词级比较(一对句子 / 一次 diff 调用)两侧合计字数上限(笔记 C.2 BaseOpts maxChars 20 000)";
522
+ readonly timeoutMs: "一次 diffProse / diffItems 的总时限(毫秒),同 VisualEditor timeout 1000(笔记 C.2)";
523
+ readonly maxItems: "条目列表单侧条目数上限;超限不逐条比较(笔记 C.5「条目 2 000 个」)";
524
+ readonly moveDetectMaxChanged: "变化条目(增 + 删)超过此数不做移动检测(笔记 C.2,wikidiff2 增删合计 > 100 不检测的放宽版,经验值)";
525
+ readonly pairAt: "句 / 段配对阈值:字符多重集 Dice ≥ 此值视为改写(VisualEditor diffThreshold 0.5;实测 3 的改写句为 0.84–0.89)";
526
+ readonly rewriteBelow: "整体相似度低于此值整段替换(等效 VE keep < 0.5 × diff;实测 2 的 C3 整句重写约 0.16)";
527
+ readonly absorbOrphan: "孤字吸收:夹在两处改动间、长度 ≤ 此值(字)的非标点相同片段并入改动(实测 2 的 C5「期」)";
528
+ readonly absorbOrphanMax: "调用方可调的孤字吸收上限(字),防止把整句吸成改动";
529
+ readonly titleAt: "无 key 条目按标题配对的相似度阈值(笔记 C.2 ItemOpts.match.titleAt 0.6)";
530
+ readonly bodyAt: "无 key 条目按正文配对的相似度阈值(笔记 C.2 ItemOpts.match.bodyAt 0.5)";
531
+ readonly maxAlignTokens: "序列对齐的不同键数上限(每个键映射为一个 BMP 私用区字符,U+E000–U+F8FF 共 6400 个)";
532
+ readonly maxPairMatrix: "一段删增区间内句 / 段配对的候选矩阵上限(删数 × 增数),超出不配对、按删 + 增呈现;经验值,证据弱";
533
+ readonly maxPairCandidates: "无 key 条目按相似度配对的候选矩阵上限(剩余旧条目 × 剩余新条目);经验值,证据弱";
534
+ };
535
+ readonly maxChars: 200000;
536
+ readonly maxCharsPerCompare: 20000;
537
+ readonly timeoutMs: 1000;
538
+ readonly maxItems: 2000;
539
+ readonly moveDetectMaxChanged: 500;
540
+ readonly pairAt: 0.5;
541
+ readonly rewriteBelow: 0.4;
542
+ readonly absorbOrphan: 1;
543
+ readonly absorbOrphanMax: 4;
544
+ readonly titleAt: 0.6;
545
+ readonly bodyAt: 0.5;
546
+ readonly maxAlignTokens: 6400;
547
+ readonly maxPairMatrix: 2500;
548
+ readonly maxPairCandidates: 250000;
549
+ };
550
+ readonly highlight: {
551
+ readonly basis: {
552
+ readonly maxLines: "高亮的最多行数;超出部分按纯文本(参考文本差异组件笔记 C.2 端口 2 maxLines 5 000)";
553
+ readonly maxLineLength: "单行超过此字符数整行按纯文本(笔记 C.2 maxLineLength 2 000,压缩后的单行 JS / JSON 常见)";
554
+ readonly timeoutMs: "一次解析的时限(毫秒);Lezer 按 advance() 分步解析,超时整段按纯文本(经验值,与差异端口同取 1 000)";
555
+ readonly maxChars: "整段超过此字符数不解析、按纯文本(经验值,证据弱:约 1 MB 文本)";
556
+ readonly jsonSniffMaxChars: "语言推断「整体能 JSON.parse」只对不超过此字符数的样本做(避免对大文本反复解析;经验值)";
557
+ };
558
+ readonly maxLines: 5000;
559
+ readonly maxLineLength: 2000;
560
+ readonly timeoutMs: 1000;
561
+ readonly maxChars: 1000000;
562
+ readonly jsonSniffMaxChars: 200000;
563
+ };
564
+ readonly structured: {
565
+ readonly basis: {
566
+ readonly maxChars: "JSON / YAML 原文超过此字符数不解析、按原文显示(与代码高亮端口 maxChars 同取约 1 MB;经验值,证据弱)";
567
+ readonly maxNodes: "解析后值的节点总数上限(对象 / 数组 / 叶子各计 1);YAML 别名展开超限即按 too-many-nodes 降级,防「十亿笑声」式别名炸弹(经验值:20 万节点约为 1 MB 紧凑 JSON 的量级)";
568
+ };
569
+ readonly maxChars: 1000000;
570
+ readonly maxNodes: 200000;
571
+ };
572
+ readonly markdown: {
573
+ readonly basis: {
574
+ readonly maxChars: "Markdown 原文超过此字符数不解析、按纯文本显示(参考文本差异组件笔记 C.2 端口 1 limits.maxChars 200 000)";
575
+ readonly maxBlocks: "块数上限,超出截断并标 truncated(笔记 C.2 maxBlocks 5 000)";
576
+ readonly summaryChars: "meta.summary 取去标记全文的前 N 字(笔记 C.2「前 80 字」)";
577
+ };
578
+ readonly maxChars: 200000;
579
+ readonly maxBlocks: 5000;
580
+ readonly summaryChars: 80;
581
+ };
582
+ };
509
583
  };
@@ -0,0 +1,14 @@
1
+ export type AnnouncePoliteness = 'polite' | 'assertive';
2
+ export interface AnnounceOptions {
3
+ readonly politeness?: AnnouncePoliteness;
4
+ }
5
+ export interface Announcer {
6
+ /** 追加一条播报;空消息忽略;politeness 缺省 polite,未知值抛 TypeError */
7
+ announce(message: string, options?: AnnounceOptions): void;
8
+ /** 两个常驻宿主 */
9
+ hosts(): Readonly<Record<AnnouncePoliteness, HTMLElement>>;
10
+ /** 立即移除全部待清理节点 */
11
+ clear(): void;
12
+ /** 清空、取消计时并移除宿主;之后 announce 忽略 */
13
+ dispose(): void;
14
+ }
@@ -35,3 +35,39 @@ export interface INotifyService {
35
35
  /** 读屏播报(S7 · `NOTIFY | announce`);可选,缺省实现见 DefaultNotifyService */
36
36
  announce?(message: string, politeness?: 'polite' | 'assertive'): void;
37
37
  }
38
+ /** 交给渲染器的一条通知;`duration` 只透传调用方给的值,未给则不带字段,由渲染器决定停留 */
39
+ export interface NotifyEntry {
40
+ readonly id: string;
41
+ readonly level: NotifyLevel;
42
+ readonly message: string;
43
+ readonly title?: string;
44
+ readonly duration?: number;
45
+ /** 呈现载体偏好;未给则渲染器按级别与动作自定 */
46
+ readonly carrier?: NotifyCarrier;
47
+ /** 附带动作;未给则无 */
48
+ readonly action?: NotifyAction;
49
+ }
50
+ /**
51
+ * 通知渲染端口(UI 体系注入,经 `SomaBootstrap` 选项 `renderPorts.notify`)。
52
+ * core 不带可见实现:停留、动效、位置、模态呈现全在渲染器里。
53
+ */
54
+ export interface NotifyRenderer {
55
+ show(entry: NotifyEntry): {
56
+ dismiss(): void;
57
+ };
58
+ confirm(req: {
59
+ message: string;
60
+ title?: string;
61
+ spec?: SomaConfirmSpec;
62
+ }): Promise<boolean>;
63
+ alert(req: {
64
+ message: string;
65
+ title?: string;
66
+ }): Promise<void>;
67
+ confirmChoice?(spec: SomaChoiceConfirmSpec): Promise<SomaChoiceConfirmOutcome>;
68
+ announce?(req: {
69
+ message: string;
70
+ politeness: 'polite' | 'assertive';
71
+ }): void;
72
+ dispose(): void;
73
+ }
@@ -0,0 +1,8 @@
1
+ /** Host 提供的角色集来源(`SomaBootstrapOptions.auth`) */
2
+ export interface SomaAuthOption {
3
+ getRoles(): readonly string[];
4
+ }
5
+ export interface SomaRoleGate {
6
+ /** 当前角色集与 `required` 有交集才为真 */
7
+ hasAnyRole(required: readonly string[]): boolean;
8
+ }
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import { createHash } from 'node:crypto';
4
4
  import esbuild, { type BuildContext, type Plugin } from 'esbuild';
5
5
  import { readAllSomaPublicAliases } from './public-packages.cjs';
6
+ import { collectDevChunks, outputsRelativeTo, releaseDevChunks } from './dev-chunk-gc';
6
7
  import { toPascalCase } from '../../core/server/api/service-path';
7
8
  import { getSomaHostSourceRoot, getSomaHostApiRoot } from '../../core/server/host/source-packages.cjs';
8
9
  import { getSomaSourceRootAliases, matchSomaSourceRoot, somaSourceRootFilter } from '../../core/server/host/source-aliases.cjs';
@@ -315,9 +316,16 @@ export async function buildBrowserClient(
315
316
  let ctx: BuildContext | null = null;
316
317
  let entryUrl = '/_soma/client/browser-entry.js';
317
318
 
319
+ // 开发态每次构建后按进程登记回收旧分片(dev-chunk-gc.ts):旧实现从不清理,chunks/ 会无限增长
320
+ const devRebuild = async (): Promise<void> => {
321
+ if (!ctx) return;
322
+ const result = await ctx.rebuild();
323
+ if (result.metafile) collectDevChunks(clientOutDir, outputsRelativeTo(clientOutDir, Object.keys(result.metafile.outputs)));
324
+ };
325
+
318
326
  if (options.dev) {
319
- ctx = await esbuild.context(buildOptions);
320
- await ctx.rebuild();
327
+ ctx = await esbuild.context({ ...buildOptions, metafile: true });
328
+ await devRebuild();
321
329
  entryUrl = '/_soma/client/browser-entry.js';
322
330
  } else {
323
331
  const result = await esbuild.build({
@@ -352,13 +360,12 @@ export async function buildBrowserClient(
352
360
  cssUrl,
353
361
  cssText: finalCss,
354
362
  rebuild: async () => {
355
- if (ctx) {
356
- await ctx.rebuild();
357
- }
363
+ await devRebuild();
358
364
  },
359
365
  dispose: async () => {
360
366
  if (ctx) {
361
367
  await ctx.dispose();
368
+ releaseDevChunks(clientOutDir);
362
369
  }
363
370
  },
364
371
  };
@@ -0,0 +1,104 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ /**
5
+ * 开发态客户端分片回收(`soma dev`)。
6
+ *
7
+ * 背景:开发态 esbuild 以 `chunks/[name]-[hash]` 命名分片、带内联 sourcemap;每次启动 / 重建内容一变就写一份新的,
8
+ * 旧的从不清理,几个应用累计到数 GB。
9
+ *
10
+ * 做法(按进程登记,不按时间猜):
11
+ * 1. 每个 dev 进程在 `<clientOutDir>/.live/<pid>.json` 登记自己当前这次构建产出的全部文件(相对 clientOutDir 的路径)。
12
+ * 2. 每次构建 / 重建后回收:保留集 = 自己的登记 ∪ 仍存活的其他 dev 进程的登记(`process.kill(pid, 0)` 判活;
13
+ * 已退出进程的登记文件随即删除);`chunks/` 下不在保留集里的文件删除。
14
+ * 3. 进程正常退出(dispose)时删除自己的登记。异常退出留下的登记,在下一个进程回收时因判活失败被清掉。
15
+ * 同一应用目录并发启动:内容相同的分片同名(内容哈希),两边登记里都有,不会误删;内容不同时各自的登记互相保留。
16
+ * 只回收 `chunks/` 目录下的文件;入口 `browser-entry.js` 与 `globals.css` 在开发态是固定名,覆盖写,不涉及回收。
17
+ */
18
+
19
+ const LIVE_DIR = '.live';
20
+ const CHUNKS_DIR = 'chunks';
21
+
22
+ function isAlive(pid: number): boolean {
23
+ if (!Number.isInteger(pid) || pid <= 0) return false;
24
+ if (pid === process.pid) return true;
25
+ try {
26
+ process.kill(pid, 0);
27
+ return true;
28
+ } catch (error) {
29
+ // EPERM:进程存在但无权发信号 → 视为存活(保守,不删它的产物)
30
+ return (error as NodeJS.ErrnoException).code === 'EPERM';
31
+ }
32
+ }
33
+
34
+ function readLiveSet(file: string): readonly string[] {
35
+ try {
36
+ const parsed: unknown = JSON.parse(fs.readFileSync(file, 'utf8'));
37
+ return Array.isArray(parsed) ? parsed.filter((v): v is string => typeof v === 'string') : [];
38
+ } catch {
39
+ return [];
40
+ }
41
+ }
42
+
43
+ /** esbuild metafile 的输出路径(相对 cwd 或绝对)→ 相对 clientOutDir 的 posix 路径 */
44
+ export function outputsRelativeTo(clientOutDir: string, outputs: readonly string[]): string[] {
45
+ const rel: string[] = [];
46
+ for (const out of outputs) {
47
+ const abs = path.resolve(out);
48
+ const r = path.relative(clientOutDir, abs);
49
+ if (r === '' || r.startsWith('..') || path.isAbsolute(r)) continue;
50
+ rel.push(r.split(path.sep).join('/'));
51
+ }
52
+ return rel;
53
+ }
54
+
55
+ /** 登记本进程的产物并回收不再被任何存活 dev 进程使用的分片。失败只吞掉(回收是尽力而为,不影响开发服务)。 */
56
+ export function collectDevChunks(clientOutDir: string, ownOutputs: readonly string[]): { readonly removed: number } {
57
+ let removed = 0;
58
+ try {
59
+ const liveDir = path.join(clientOutDir, LIVE_DIR);
60
+ fs.mkdirSync(liveDir, { recursive: true });
61
+ fs.writeFileSync(path.join(liveDir, `${process.pid}.json`), JSON.stringify(ownOutputs), 'utf8');
62
+
63
+ const keep = new Set<string>(ownOutputs);
64
+ for (const name of fs.readdirSync(liveDir)) {
65
+ if (!name.endsWith('.json')) continue;
66
+ const pid = Number(name.slice(0, -'.json'.length));
67
+ const file = path.join(liveDir, name);
68
+ if (pid === process.pid) continue;
69
+ if (!isAlive(pid)) {
70
+ fs.rmSync(file, { force: true });
71
+ continue;
72
+ }
73
+ for (const rel of readLiveSet(file)) keep.add(rel);
74
+ }
75
+
76
+ const chunksDir = path.join(clientOutDir, CHUNKS_DIR);
77
+ if (!fs.existsSync(chunksDir)) return { removed };
78
+ for (const name of fs.readdirSync(chunksDir)) {
79
+ const rel = `${CHUNKS_DIR}/${name}`;
80
+ if (keep.has(rel)) continue;
81
+ const abs = path.join(chunksDir, name);
82
+ try {
83
+ if (fs.statSync(abs).isFile()) {
84
+ fs.rmSync(abs, { force: true });
85
+ removed += 1;
86
+ }
87
+ } catch {
88
+ // 另一进程刚好删掉了:忽略
89
+ }
90
+ }
91
+ } catch {
92
+ // 尽力而为
93
+ }
94
+ return { removed };
95
+ }
96
+
97
+ /** dispose 时删除本进程的登记(产物留给下一次启动按登记回收)。 */
98
+ export function releaseDevChunks(clientOutDir: string): void {
99
+ try {
100
+ fs.rmSync(path.join(clientOutDir, LIVE_DIR, `${process.pid}.json`), { force: true });
101
+ } catch {
102
+ // 尽力而为
103
+ }
104
+ }
@@ -1,18 +1,34 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { assertReservedRoutesShape, loadHostAssembly, invalidateHostAssembly, registerShellRoutes as registerCoreShellRoutes } from 'soma-core/server/host-assembly';
4
- import { clearPagePayloadBufferCache } from './page-http';
4
+ import { clearPagePayloadBufferCache } from './page-payload-cache';
5
5
  import { precompileAll, precompilePage } from '../../core/build/compiler/full-manifest-builder';
6
6
  import { addressOfPageBase } from '../../core/build/compiler/page-base-resolver';
7
7
  import { loadPageMarkupConfig } from '../../core/server/host/page-markup-config';
8
8
  import { resolveHostTreeCompileContext } from '../../core/server/host/resolve-host-tree-context';
9
9
  import { runPrewarm, computePrewarmInputsDigest } from '../../core/server/runtime-space/prewarm';
10
+ import { SOMA_RUNTIME_STORE_FORMAT } from '../../core/server/runtime-space/digest';
10
11
  import { resolveAppConfigPath, resolveHostAppConfigPath } from '../../core/server/host/host-config-paths.cjs';
11
12
  import { getSomaAssetSources, collectPageEntries, collectIncludes } from '../../core/server/host/source-packages';
12
13
  import { invalidateStaticAddresses } from '../../core/server/runtime-space/static-source';
13
14
 
14
15
  export const SOMA_SHELL_ROUTES_ENV = 'SOMA_SHELL_ROUTES';
15
16
 
17
+ let coreIdentityMemo: string | null = null;
18
+ /** 预编译旁档的编译身份:soma-core 包版本 + 落盘格式版本;读不到包版本时回 `unknown`(不复用不是错,复用旧的才是错——此时随格式版本变) */
19
+ function coreCompilerIdentity(): string {
20
+ if (coreIdentityMemo !== null) return coreIdentityMemo;
21
+ let version = 'unknown';
22
+ try {
23
+ const raw = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf8')) as { version?: unknown };
24
+ if (typeof raw.version === 'string') version = raw.version;
25
+ } catch {
26
+ /* 读不到:用 unknown */
27
+ }
28
+ coreIdentityMemo = `soma-core@${version}/store-format-${SOMA_RUNTIME_STORE_FORMAT}`;
29
+ return coreIdentityMemo;
30
+ }
31
+
16
32
  let lastRaw: string | undefined;
17
33
  let lastParsed: readonly string[] = [];
18
34
 
@@ -138,7 +154,8 @@ export async function prewarmHostPages(hostDir: string, env: NodeJS.ProcessEnv =
138
154
  appConfigYaml: compileInput.appConfigYaml,
139
155
  hostAppConfigYaml: appConfigYaml,
140
156
  treeContext: compileInput.treeContext ?? null,
141
- compilerIdentity: null,
157
+ // 预编译旁档只在「同一份 core 编的」时复用:core 升级后整批旁档自动失效,不需要手工清 .soma/runtime
158
+ compilerIdentity: coreCompilerIdentity(),
142
159
  }),
143
160
  compile: () => precompilePage(compileInput, { hostAppConfig: shell.appConfig }),
144
161
  };
@@ -1,4 +1,4 @@
1
- import { loadPrecompiledManifest, findPrecompiledPage } from '../../core/server/page-assets';
1
+ import { loadPrecompiledManifest, findPrecompiledPage } from '../../core/server/host/precompiled-manifest';
2
2
  import { listBindings } from '../../core/server/runtime-space';
3
3
  import { resolveSomaRuntimeLayout } from '../../core/server/runtime-space/root';
4
4
  import { SomaRuntimeStore } from '../../core/server/runtime-space/store';
@@ -16,6 +16,7 @@ import { clearTailwindCompilerCache } from 'soma-core/server/style-engine';
16
16
  import { resolveHostResponseHeaders } from '../../core/server/host/host-response-headers';
17
17
  import type { BrowserClientBuildResult, ServerAotManifest } from './aot-builder';
18
18
  import { pageSuccessResponse, pageErrorResponse } from './page-http';
19
+ import { isStatusError } from '../../core/server/runtime-space/errors';
19
20
  import { handleManifestGet } from './manifest-http';
20
21
  import { prepareHostAssembly, invalidateHostPreparation, prewarmHostPages } from './host-prepare';
21
22
  import { staticResponse, serveStaticFromRoot, isSafeSegments, acceptsGzip } from './static-file';
@@ -684,6 +685,15 @@ export async function createNativeServer(
684
685
  return refreshTask;
685
686
  };
686
687
 
688
+ /** 等开发态刷新队列走空(有待处理变更、debounce 中、重建中都算忙),至多等 30 秒,超时放行(不让一次卡住的重建拖死页面) */
689
+ const waitForDevRefreshIdle = async (): Promise<void> => {
690
+ const deadline = Date.now() + 30_000;
691
+ while (!watcherClosed && (refreshTask !== null || refreshPending || debounceTimer !== null) && Date.now() < deadline) {
692
+ if (refreshTask !== null) await refreshTask.catch(() => undefined);
693
+ else await new Promise<void>((resolve) => setTimeout(resolve, 50));
694
+ }
695
+ };
696
+
687
697
  if (dev) {
688
698
  try {
689
699
  fsWatcher = fs.watch(webRoot, { recursive: true }, (_event, filename) => {
@@ -807,8 +817,12 @@ export async function createNativeServer(
807
817
  const subSegments = pathname.slice('/_soma/client/'.length).split('/').filter(Boolean);
808
818
  const staticReq = createStaticLookupRequest(req, method);
809
819
  const clientStaticDir = path.resolve(runtimeLayout.dirs.static, 'client');
820
+ // 开发态:增量重建进行中先等它写完——entry 与它引用的 chunk 是同一代产物,重建中途请求会读到「新 entry + 还没写出的 chunk」或「旧 chunk 已被清掉」(偶发 404,页面无内容)
821
+ if (dev) await waitForDevRefreshIdle();
810
822
  const clientRes = serveStaticFromRoot(clientStaticDir, subSegments, staticReq, true);
811
823
  if (clientRes) {
824
+ // 开发态:不带内容哈希的 entry / 样式每次都向服务器核对(缺省 max-age=300 会让浏览器在重建后的 5 分钟里继续用旧 entry,它引用的旧哈希 chunk 已被重建清掉 → 404)
825
+ if (dev && !/immutable/.test(clientRes.headers.get('cache-control') ?? '')) clientRes.headers.set('cache-control', 'no-cache');
812
826
  await sendWebResponse(clientRes, res, method);
813
827
  return;
814
828
  }
@@ -890,6 +904,8 @@ export async function createNativeServer(
890
904
  await sendWebResponse(response, res, method);
891
905
  return;
892
906
  } catch (error) {
907
+ // 响应体对外只给通用 500(不泄露内部细节),原因必须落服务端日志,否则页面载入失败无从排查
908
+ if (!isStatusError(error)) console.error(`[soma-native] 页面载入失败 path=${pagePath}`, error);
893
909
  let response = pageErrorResponse(error, assembly);
894
910
  response = await applyHostAndCspHeaders(response, { method: 'GET', pathname }, env);
895
911
  await sendWebResponse(response, res, method);
@@ -3,8 +3,9 @@ import zlib from 'node:zlib';
3
3
  import { resolveHostLoginPath, SOMA_DEFAULT_LOGIN_PATH } from 'soma-core/server/host-assembly';
4
4
  import { isStatusError } from '../../core/server/runtime-space/errors';
5
5
  import { SomaPublishedPageError } from '../../core/server/host/published-page-assets';
6
+ import { PagePayloadBufferCache, clearPagePayloadBufferCache } from './page-payload-cache';
6
7
 
7
- export { SOMA_DEFAULT_LOGIN_PATH };
8
+ export { SOMA_DEFAULT_LOGIN_PATH, PagePayloadBufferCache, clearPagePayloadBufferCache };
8
9
 
9
10
  export function resolveLoginPath(
10
11
  assembly?: { readonly login?: { readonly path?: string } } | null,
@@ -21,72 +22,6 @@ export interface CacheableLoadedPage {
21
22
  const VARY_DEFAULT = 'Cookie, Authorization';
22
23
  const VARY_ENCODING = 'Cookie, Authorization, Accept-Encoding';
23
24
 
24
- interface CachedPagePayload {
25
- readonly utf8: Uint8Array;
26
- readonly gzip: Uint8Array | null;
27
- readonly etag: string;
28
- readonly size: number;
29
- }
30
-
31
- const MAX_CACHE_ENTRIES = 256;
32
- const MAX_CACHE_BYTES = 64 * 1024 * 1024; // 64MB
33
-
34
- class PagePayloadBufferLRU {
35
- private cache = new Map<string, CachedPagePayload>();
36
- private totalBytes = 0;
37
-
38
- get(key: string): CachedPagePayload | undefined {
39
- const entry = this.cache.get(key);
40
- if (!entry) return undefined;
41
- // LRU refresh: re-insert to end
42
- this.cache.delete(key);
43
- this.cache.set(key, entry);
44
- return entry;
45
- }
46
-
47
- set(key: string, entry: CachedPagePayload): void {
48
- if (this.cache.has(key)) {
49
- const old = this.cache.get(key)!;
50
- this.totalBytes -= old.size;
51
- this.cache.delete(key);
52
- }
53
- while (
54
- (this.cache.size >= MAX_CACHE_ENTRIES || this.totalBytes + entry.size > MAX_CACHE_BYTES) &&
55
- this.cache.size > 0
56
- ) {
57
- const firstKey = this.cache.keys().next().value;
58
- if (firstKey !== undefined) {
59
- const item = this.cache.get(firstKey);
60
- if (item) this.totalBytes -= item.size;
61
- this.cache.delete(firstKey);
62
- } else {
63
- break;
64
- }
65
- }
66
- this.cache.set(key, entry);
67
- this.totalBytes += entry.size;
68
- }
69
-
70
- clear(): void {
71
- this.cache.clear();
72
- this.totalBytes = 0;
73
- }
74
-
75
- get size(): number {
76
- return this.cache.size;
77
- }
78
-
79
- get bytes(): number {
80
- return this.totalBytes;
81
- }
82
- }
83
-
84
- export const PagePayloadBufferCache = new PagePayloadBufferLRU();
85
-
86
- export function clearPagePayloadBufferCache(): void {
87
- PagePayloadBufferCache.clear();
88
- }
89
-
90
25
  function weakEtag(body: string | Uint8Array): string {
91
26
  return `W/"${createHash('sha1').update(body).digest('hex').slice(0, 20)}"`;
92
27
  }
@@ -0,0 +1,68 @@
1
+ // 页面响应体预序列化二进制缓冲池(LRU),供 host-prepare.ts 与 page-http.ts 共用。
2
+ // 从契约层 page-http.ts 抽出至应用层,解除 host-prepare.ts -> page-http.ts 的反向依赖。
3
+
4
+ export interface CachedPagePayload {
5
+ readonly utf8: Uint8Array;
6
+ readonly gzip: Uint8Array | null;
7
+ readonly etag: string;
8
+ readonly size: number;
9
+ }
10
+
11
+ const MAX_CACHE_ENTRIES = 256;
12
+ const MAX_CACHE_BYTES = 64 * 1024 * 1024; // 64MB
13
+
14
+ class PagePayloadBufferLRU {
15
+ private cache = new Map<string, CachedPagePayload>();
16
+ private totalBytes = 0;
17
+
18
+ get(key: string): CachedPagePayload | undefined {
19
+ const entry = this.cache.get(key);
20
+ if (!entry) return undefined;
21
+ // LRU refresh: re-insert to end
22
+ this.cache.delete(key);
23
+ this.cache.set(key, entry);
24
+ return entry;
25
+ }
26
+
27
+ set(key: string, entry: CachedPagePayload): void {
28
+ if (this.cache.has(key)) {
29
+ const old = this.cache.get(key)!;
30
+ this.totalBytes -= old.size;
31
+ this.cache.delete(key);
32
+ }
33
+ while (
34
+ (this.cache.size >= MAX_CACHE_ENTRIES || this.totalBytes + entry.size > MAX_CACHE_BYTES) &&
35
+ this.cache.size > 0
36
+ ) {
37
+ const firstKey = this.cache.keys().next().value;
38
+ if (firstKey !== undefined) {
39
+ const item = this.cache.get(firstKey);
40
+ if (item) this.totalBytes -= item.size;
41
+ this.cache.delete(firstKey);
42
+ } else {
43
+ break;
44
+ }
45
+ }
46
+ this.cache.set(key, entry);
47
+ this.totalBytes += entry.size;
48
+ }
49
+
50
+ clear(): void {
51
+ this.cache.clear();
52
+ this.totalBytes = 0;
53
+ }
54
+
55
+ get size(): number {
56
+ return this.cache.size;
57
+ }
58
+
59
+ get bytes(): number {
60
+ return this.totalBytes;
61
+ }
62
+ }
63
+
64
+ export const PagePayloadBufferCache = new PagePayloadBufferLRU();
65
+
66
+ export function clearPagePayloadBufferCache(): void {
67
+ PagePayloadBufferCache.clear();
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soma-core",
3
- "version": "2.2.7",
3
+ "version": "2.2.9",
4
4
  "description": "SOMA — Semantic Oriented Modular Architecture. A declarative frontend framework runtime with no UI framework dependency; native host shell ships in host-native/.",
5
5
  "keywords": [
6
6
  "soma",
@@ -311,6 +311,17 @@
311
311
  "dependencies": {
312
312
  "@atlaskit/pragmatic-drag-and-drop": "1.8.1",
313
313
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "1.2.0",
314
+ "@lezer/css": "1.3.9",
315
+ "@lezer/go": "1.0.1",
316
+ "@lezer/highlight": "1.2.5",
317
+ "@lezer/html": "1.3.13",
318
+ "@lezer/java": "1.2.0",
319
+ "@lezer/javascript": "1.5.6",
320
+ "@lezer/json": "1.0.3",
321
+ "@lezer/markdown": "1.8.1",
322
+ "@lezer/python": "1.1.19",
323
+ "@lezer/xml": "1.0.6",
324
+ "@lezer/yaml": "1.0.4",
314
325
  "@tanstack/table-core": "8.21.3",
315
326
  "@tanstack/virtual-core": "3.19.7",
316
327
  "@zag-js/combobox": "1.46.0",
@@ -328,11 +339,14 @@
328
339
  "esbuild": "0.25.12",
329
340
  "jiti": "1.21.7",
330
341
  "js-yaml": "4.3.2",
342
+ "markdown-it": "15.0.3",
343
+ "markdown-it-cjk-friendly": "3.0.0",
344
+ "markdown-it-footnote": "4.0.0",
331
345
  "mime-types": "2.1.35",
332
346
  "parse5": "7.3.0",
333
347
  "qrcode-generator": "2.0.4",
334
348
  "server-only": "0.0.1",
335
- "soma-foundation": "^0.1.4",
349
+ "soma-foundation": "^0.1.6",
336
350
  "temporal-polyfill": "0.3.2"
337
351
  },
338
352
  "peerDependencies": {