@twinsearth/fang-dsh-plugin 0.0.0-stage → 3.3.5

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 (147) hide show
  1. package/CLA.md +79 -0
  2. package/LICENSE-COMMERCIAL +78 -0
  3. package/LICENSE-CORE +661 -0
  4. package/LICENSE-SDK +21 -0
  5. package/LICENSES/cordis-MIT.txt +39 -0
  6. package/NOTICE +95 -0
  7. package/README.md +158 -2
  8. package/client.js +7287 -0
  9. package/cordis.patch.yml +163 -0
  10. package/defaults/umbrella-rules.yaml +113 -0
  11. package/docs/APPROVAL-DRILL.md +42 -0
  12. package/docs/CONTRACT-INTEROP.md +77 -0
  13. package/docs/CRASH-SAFETY.md +69 -0
  14. package/docs/DECISION-RELAY.md +46 -0
  15. package/docs/DSH-ARCHITECTURE-MAP.md +73 -0
  16. package/docs/FORK-SEED.md +64 -0
  17. package/docs/MAIN-CITY-GATE.md +58 -0
  18. package/docs/OVERLAY-MASTER-SWITCH.md +35 -0
  19. package/docs/PACKAGE-RENAME-v3.3.3.md +40 -0
  20. package/docs/PM-DECISION-POLICY.md +61 -0
  21. package/docs/WORKFLOW-UI.md +86 -0
  22. package/icon.svg +8 -0
  23. package/locale/en.json +6 -0
  24. package/locale/zh.json +6 -0
  25. package/package.json +71 -4
  26. package/sdk/README.md +65 -0
  27. package/sdk/examples/status-badge/README.md +16 -0
  28. package/sdk/examples/status-badge/client.js +60 -0
  29. package/sdk/examples/status-badge/cordis.patch.yml +7 -0
  30. package/sdk/examples/status-badge/index.js +12 -0
  31. package/sdk/examples/status-badge/package.json +24 -0
  32. package/sdk/templates/plugin/README.md +36 -0
  33. package/sdk/templates/plugin/client.js +35 -0
  34. package/sdk/templates/plugin/cordis.patch.yml +8 -0
  35. package/sdk/templates/plugin/icon.svg +5 -0
  36. package/sdk/templates/plugin/index.js +23 -0
  37. package/sdk/templates/plugin/locale/en.json +6 -0
  38. package/sdk/templates/plugin/package.json +36 -0
  39. package/src/compose.mjs +67 -0
  40. package/src/contract/VENDOR.json +16 -0
  41. package/src/contract/client.js +93 -0
  42. package/src/contract/constants.js +94 -0
  43. package/src/contract/envelope.js +83 -0
  44. package/src/contract/index.js +20 -0
  45. package/src/contract/negotiate.js +106 -0
  46. package/src/contract/relay.js +223 -0
  47. package/src/contract/server.js +77 -0
  48. package/src/contract/transports.js +319 -0
  49. package/src/index.mjs +11 -0
  50. package/src/kernel/core.mjs +100 -0
  51. package/src/kernel/extensions.mjs +61 -0
  52. package/src/kernel/fsx.mjs +349 -0
  53. package/src/kernel/index.mjs +21 -0
  54. package/src/kernel/ledger.mjs +94 -0
  55. package/src/kernel/paths.mjs +182 -0
  56. package/src/kernel/role.mjs +68 -0
  57. package/src/kernel/rounds.mjs +172 -0
  58. package/src/kernel/schema.mjs +5 -0
  59. package/src/kernel/types.mjs +266 -0
  60. package/src/kernel/vendor/cosmokit.mjs +421 -0
  61. package/src/kernel/vendor/schemastery.mjs +638 -0
  62. package/src/lib/adapter-client.mjs +383 -0
  63. package/src/lib/adapter-protocol.mjs +243 -0
  64. package/src/lib/ai-secret-store.mjs +202 -0
  65. package/src/lib/approval-drill.mjs +111 -0
  66. package/src/lib/boot-guard.mjs +186 -0
  67. package/src/lib/branch-store.mjs +84 -0
  68. package/src/lib/branch.mjs +74 -0
  69. package/src/lib/bridge-client.mjs +133 -0
  70. package/src/lib/broker-adapter.mjs +67 -0
  71. package/src/lib/broker.mjs +45 -0
  72. package/src/lib/business-producers.mjs +109 -0
  73. package/src/lib/command-cache.mjs +209 -0
  74. package/src/lib/compat.mjs +170 -0
  75. package/src/lib/composer-journal.mjs +128 -0
  76. package/src/lib/container/index.mjs +806 -0
  77. package/src/lib/decision-events.mjs +129 -0
  78. package/src/lib/decision-ingest-client.mjs +41 -0
  79. package/src/lib/decision-outbox.mjs +129 -0
  80. package/src/lib/decision-policy.mjs +52 -0
  81. package/src/lib/default-essence.mjs +61 -0
  82. package/src/lib/desktop-launch.mjs +138 -0
  83. package/src/lib/essence.mjs +1211 -0
  84. package/src/lib/fork-client.mjs +410 -0
  85. package/src/lib/fork-config-lock.mjs +166 -0
  86. package/src/lib/fork-seed.mjs +304 -0
  87. package/src/lib/fork-sessions.mjs +183 -0
  88. package/src/lib/fork-supervision-settings.mjs +58 -0
  89. package/src/lib/fork-supervisor.mjs +122 -0
  90. package/src/lib/fs-guard.mjs +28 -0
  91. package/src/lib/http-auth.mjs +162 -0
  92. package/src/lib/idle-audit.mjs +178 -0
  93. package/src/lib/interaction-poke.mjs +61 -0
  94. package/src/lib/main-gate.mjs +582 -0
  95. package/src/lib/mirror-etag.mjs +92 -0
  96. package/src/lib/mirror-official-source.mjs +93 -0
  97. package/src/lib/mirror.mjs +478 -0
  98. package/src/lib/mother-link.mjs +156 -0
  99. package/src/lib/mutex.mjs +31 -0
  100. package/src/lib/permissions.mjs +115 -0
  101. package/src/lib/pnpm-store.mjs +189 -0
  102. package/src/lib/preferences.mjs +212 -0
  103. package/src/lib/producer-contract.mjs +162 -0
  104. package/src/lib/reflow.mjs +41 -0
  105. package/src/lib/remote.mjs +408 -0
  106. package/src/lib/restart-contract.mjs +752 -0
  107. package/src/lib/roots.mjs +30 -0
  108. package/src/lib/rule-registry.mjs +1127 -0
  109. package/src/lib/runtime-capture.mjs +307 -0
  110. package/src/lib/semaphore.mjs +34 -0
  111. package/src/lib/session-bundle.mjs +138 -0
  112. package/src/lib/session-format.mjs +672 -0
  113. package/src/lib/sse-parser.mjs +102 -0
  114. package/src/lib/ssrf-guard.mjs +170 -0
  115. package/src/lib/status-store.mjs +257 -0
  116. package/src/lib/task-handle.mjs +622 -0
  117. package/src/lib/ui-actions.mjs +55 -0
  118. package/src/lib/umbrella.mjs +1661 -0
  119. package/src/lib/upgrade-coordinator.mjs +107 -0
  120. package/src/lib/upgrade-status.mjs +43 -0
  121. package/src/plugins/adapter.mjs +1468 -0
  122. package/src/plugins/approver.mjs +1210 -0
  123. package/src/plugins/auditor.mjs +330 -0
  124. package/src/plugins/buffer-keeper.mjs +522 -0
  125. package/src/plugins/decision-center.mjs +2581 -0
  126. package/src/plugins/forker.mjs +1610 -0
  127. package/src/plugins/healer.mjs +702 -0
  128. package/src/plugins/hot-reloader.mjs +274 -0
  129. package/src/plugins/imports.mjs +247 -0
  130. package/src/plugins/orchestrator.mjs +3979 -0
  131. package/src/plugins/restart-guard.mjs +1022 -0
  132. package/src/plugins/router.mjs +714 -0
  133. package/src/plugins/scorer.mjs +661 -0
  134. package/src/plugins/session-bridge.mjs +166 -0
  135. package/src/plugins/session-catalog.mjs +771 -0
  136. package/src/plugins/session-router.mjs +125 -0
  137. package/src/plugins/session-sync.mjs +171 -0
  138. package/src/plugins/umbrella.mjs +419 -0
  139. package/tools/approval-drill.mjs +21 -0
  140. package/tools/boot-guard.mjs +95 -0
  141. package/tools/decision-ingest.mjs +53 -0
  142. package/tools/desktop-launch.mjs +71 -0
  143. package/tools/fangctl.mjs +425 -0
  144. package/tools/gate/main-city.mjs +204 -0
  145. package/tools/mcp/server.mjs +121 -0
  146. package/tools/mcp/tools.mjs +65 -0
  147. package/tools/recover-queue.mjs +133 -0
@@ -0,0 +1,107 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // dsh-Fang v3.0.9 — 升级后重算协调器。
3
+ //
4
+ // 职责:把 MirrorManager 的「升级成功」与 EssenceManager 的「批量重算」解耦:
5
+ // MirrorManager 只持有一个 postUpgradeHook(fire-and-forget),
6
+ // coordinator 负责去重并发重算、记录进度/结果,并暴露给 UI 轮询。
7
+ // 失败隔离:重算失败不影响升级结果;单个原身失败进入 failed,不中断整批。
8
+
9
+ export class MirrorUpgradeCoordinator {
10
+ /**
11
+ * @param {{essence: {recomputeAll: Function}, logger?: {info?:Function, warn?:Function},
12
+ * concurrency?: number, perEssenceTimeoutMs?: number}} options
13
+ */
14
+ constructor(options) {
15
+ if (options === null || typeof options !== 'object' || options.essence === null || typeof options.essence !== 'object') {
16
+ throw new Error('MirrorUpgradeCoordinator: essence required')
17
+ }
18
+ this.essence = options.essence
19
+ this.logger = options.logger ?? {}
20
+ this.concurrency = Math.max(1, Math.floor(Number(options.concurrency) || 4))
21
+ this.perEssenceTimeoutMs = Math.max(1, Math.floor(Number(options.perEssenceTimeoutMs) || 60_000))
22
+ /** @type {Promise<void>|null} */
23
+ this.currentRun = null
24
+ /** @type {{running:boolean, startedAt:number|null, finishedAt:number|null, progress:Record<string,unknown>|null, lastResult:Record<string,unknown>|null, lastError:string|null}} */
25
+ this.status = {
26
+ running: false, startedAt: null, finishedAt: null,
27
+ progress: null, lastResult: null, lastError: null,
28
+ }
29
+ }
30
+
31
+ /** 返回状态快照(浅拷贝,避免调用方改内部对象)。 */
32
+ getRecomputeStatus() {
33
+ return {
34
+ ...this.status,
35
+ progress: this.status.progress === null ? null : { ...this.status.progress },
36
+ lastResult: this.status.lastResult === null ? null : {
37
+ ...this.status.lastResult,
38
+ recomputed: [...(this.status.lastResult.recomputed ?? [])],
39
+ skipped: [...(this.status.lastResult.skipped ?? [])],
40
+ conflicted: [...(this.status.lastResult.conflicted ?? [])],
41
+ failed: [...(this.status.lastResult.failed ?? [])],
42
+ },
43
+ }
44
+ }
45
+
46
+ /**
47
+ * 由 postUpgradeHook 调用;若已有重算在跑则复用同一个 promise(不叠加批次)。
48
+ * @returns {Promise<void>}
49
+ */
50
+ onUpgradeSuccess() {
51
+ if (this.currentRun !== null) {
52
+ this.logger.info?.('[coordinator] recompute already running, joining')
53
+ return this.currentRun
54
+ }
55
+ this.currentRun = this.runRecompute().finally(() => { this.currentRun = null })
56
+ return this.currentRun
57
+ }
58
+
59
+ /** 等待当前重算完成;无进行中批次时立即返回。 */
60
+ async waitForRecompute() {
61
+ if (this.currentRun !== null) await this.currentRun
62
+ }
63
+
64
+ async runRecompute() {
65
+ const startedAt = Date.now()
66
+ this.status = {
67
+ running: true, startedAt, finishedAt: null,
68
+ progress: { done: 0, total: 0, currentId: null, recomputed: 0, skipped: 0, conflicted: 0, failed: 0 },
69
+ lastResult: null, lastError: null,
70
+ }
71
+ try {
72
+ const result = await this.essence.recomputeAll({
73
+ concurrency: this.concurrency,
74
+ perEssenceTimeoutMs: this.perEssenceTimeoutMs,
75
+ onProgress: (progress) => { this.status.progress = { ...progress } },
76
+ })
77
+ this.status = {
78
+ ...this.status,
79
+ running: false,
80
+ finishedAt: Date.now(),
81
+ progress: this.status.progress,
82
+ lastResult: result,
83
+ lastError: null,
84
+ }
85
+ this.logger.info?.('[coordinator] recompute completed', {
86
+ recomputed: result.recomputed?.length ?? 0,
87
+ skipped: result.skipped?.length ?? 0,
88
+ conflicted: result.conflicted?.length ?? 0,
89
+ failed: result.failed?.length ?? 0,
90
+ aborted: result.aborted === true,
91
+ durationMs: result.durationMs,
92
+ })
93
+ } catch (error) {
94
+ this.status = {
95
+ ...this.status,
96
+ running: false,
97
+ finishedAt: Date.now(),
98
+ lastError: String(error instanceof Error ? error.message : error),
99
+ }
100
+ this.logger.warn?.('[coordinator] recompute failed', {
101
+ error: String(error instanceof Error ? error.message : error),
102
+ })
103
+ }
104
+ }
105
+ }
106
+
107
+ export const _internals = Object.freeze({})
@@ -0,0 +1,43 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // v3.0.9 read-only upgrade status. Pure function: no IO, no upgrade/backup side effects.
3
+ export function buildUpgradeStatus({ version = '', mirror = null, essences = [], compat = null, tasks = null } = {}) {
4
+ const current = mirror?.current ?? mirror?.currentVersion ?? null
5
+ const latest = mirror?.latest ?? mirror?.officialLatest ?? null
6
+ const mother = {
7
+ current,
8
+ latest,
9
+ updateAvailable: Boolean(current && latest && current !== latest) || mirror?.updateAvailable === true,
10
+ lastBackupAt: Number(mirror?.lastBackupAt) || 0,
11
+ backupIntervalHours: [6, 12, 24].includes(Number(mirror?.backupIntervalHours)) ? Number(mirror.backupIntervalHours) : 24,
12
+ }
13
+ const list = Array.isArray(essences) ? essences.map((e) => ({
14
+ id: String(e?.id ?? ''),
15
+ name: String(e?.name ?? ''),
16
+ status: String(e?.status ?? 'unknown'),
17
+ stale: Boolean(e?.stale),
18
+ })) : []
19
+ const staleCount = list.filter((e) => e.stale).length
20
+ const conflicted = list.filter((e) => e.status === 'conflicted').length
21
+ const failedTasks = Number(tasks?.failed) || 0
22
+
23
+ // 系统状态灯:绿=全绿;黄=有更新/待同步;红=有失败。
24
+ const level = { green: 0, yellow: 1, red: 2 }
25
+ let tone = 'green'
26
+ const reasons = []
27
+ const bump = (next, code, text) => {
28
+ if (level[next] > level[tone]) tone = next
29
+ reasons.push({ code, text })
30
+ }
31
+ if (mother.updateAvailable) bump('yellow', 'mother-update', '母体有新版本可更新')
32
+ if (staleCount > 0) bump('yellow', 'essence-stale', `${staleCount} 个元主待同步到新母体`)
33
+ if (compat && compat.ok === false) bump('red', 'compat-failed', '兼容门禁未通过,子插件可能被关闭')
34
+ if (conflicted > 0) bump('red', 'essence-conflicted', `${conflicted} 个元主存在致命冲突`)
35
+ if (failedTasks > 0) bump('red', 'fork-failed', `${failedTasks} 个分身处于失败状态`)
36
+
37
+ return {
38
+ ok: true, version: String(version || ''), mother,
39
+ essences: list, operation: null,
40
+ staleCount, conflicted, failedTasks,
41
+ light: { tone, reasons },
42
+ }
43
+ }