@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.
- package/CLA.md +79 -0
- package/LICENSE-COMMERCIAL +78 -0
- package/LICENSE-CORE +661 -0
- package/LICENSE-SDK +21 -0
- package/LICENSES/cordis-MIT.txt +39 -0
- package/NOTICE +95 -0
- package/README.md +158 -2
- package/client.js +7287 -0
- package/cordis.patch.yml +163 -0
- package/defaults/umbrella-rules.yaml +113 -0
- package/docs/APPROVAL-DRILL.md +42 -0
- package/docs/CONTRACT-INTEROP.md +77 -0
- package/docs/CRASH-SAFETY.md +69 -0
- package/docs/DECISION-RELAY.md +46 -0
- package/docs/DSH-ARCHITECTURE-MAP.md +73 -0
- package/docs/FORK-SEED.md +64 -0
- package/docs/MAIN-CITY-GATE.md +58 -0
- package/docs/OVERLAY-MASTER-SWITCH.md +35 -0
- package/docs/PACKAGE-RENAME-v3.3.3.md +40 -0
- package/docs/PM-DECISION-POLICY.md +61 -0
- package/docs/WORKFLOW-UI.md +86 -0
- package/icon.svg +8 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +71 -4
- package/sdk/README.md +65 -0
- package/sdk/examples/status-badge/README.md +16 -0
- package/sdk/examples/status-badge/client.js +60 -0
- package/sdk/examples/status-badge/cordis.patch.yml +7 -0
- package/sdk/examples/status-badge/index.js +12 -0
- package/sdk/examples/status-badge/package.json +24 -0
- package/sdk/templates/plugin/README.md +36 -0
- package/sdk/templates/plugin/client.js +35 -0
- package/sdk/templates/plugin/cordis.patch.yml +8 -0
- package/sdk/templates/plugin/icon.svg +5 -0
- package/sdk/templates/plugin/index.js +23 -0
- package/sdk/templates/plugin/locale/en.json +6 -0
- package/sdk/templates/plugin/package.json +36 -0
- package/src/compose.mjs +67 -0
- package/src/contract/VENDOR.json +16 -0
- package/src/contract/client.js +93 -0
- package/src/contract/constants.js +94 -0
- package/src/contract/envelope.js +83 -0
- package/src/contract/index.js +20 -0
- package/src/contract/negotiate.js +106 -0
- package/src/contract/relay.js +223 -0
- package/src/contract/server.js +77 -0
- package/src/contract/transports.js +319 -0
- package/src/index.mjs +11 -0
- package/src/kernel/core.mjs +100 -0
- package/src/kernel/extensions.mjs +61 -0
- package/src/kernel/fsx.mjs +349 -0
- package/src/kernel/index.mjs +21 -0
- package/src/kernel/ledger.mjs +94 -0
- package/src/kernel/paths.mjs +182 -0
- package/src/kernel/role.mjs +68 -0
- package/src/kernel/rounds.mjs +172 -0
- package/src/kernel/schema.mjs +5 -0
- package/src/kernel/types.mjs +266 -0
- package/src/kernel/vendor/cosmokit.mjs +421 -0
- package/src/kernel/vendor/schemastery.mjs +638 -0
- package/src/lib/adapter-client.mjs +383 -0
- package/src/lib/adapter-protocol.mjs +243 -0
- package/src/lib/ai-secret-store.mjs +202 -0
- package/src/lib/approval-drill.mjs +111 -0
- package/src/lib/boot-guard.mjs +186 -0
- package/src/lib/branch-store.mjs +84 -0
- package/src/lib/branch.mjs +74 -0
- package/src/lib/bridge-client.mjs +133 -0
- package/src/lib/broker-adapter.mjs +67 -0
- package/src/lib/broker.mjs +45 -0
- package/src/lib/business-producers.mjs +109 -0
- package/src/lib/command-cache.mjs +209 -0
- package/src/lib/compat.mjs +170 -0
- package/src/lib/composer-journal.mjs +128 -0
- package/src/lib/container/index.mjs +806 -0
- package/src/lib/decision-events.mjs +129 -0
- package/src/lib/decision-ingest-client.mjs +41 -0
- package/src/lib/decision-outbox.mjs +129 -0
- package/src/lib/decision-policy.mjs +52 -0
- package/src/lib/default-essence.mjs +61 -0
- package/src/lib/desktop-launch.mjs +138 -0
- package/src/lib/essence.mjs +1211 -0
- package/src/lib/fork-client.mjs +410 -0
- package/src/lib/fork-config-lock.mjs +166 -0
- package/src/lib/fork-seed.mjs +304 -0
- package/src/lib/fork-sessions.mjs +183 -0
- package/src/lib/fork-supervision-settings.mjs +58 -0
- package/src/lib/fork-supervisor.mjs +122 -0
- package/src/lib/fs-guard.mjs +28 -0
- package/src/lib/http-auth.mjs +162 -0
- package/src/lib/idle-audit.mjs +178 -0
- package/src/lib/interaction-poke.mjs +61 -0
- package/src/lib/main-gate.mjs +582 -0
- package/src/lib/mirror-etag.mjs +92 -0
- package/src/lib/mirror-official-source.mjs +93 -0
- package/src/lib/mirror.mjs +478 -0
- package/src/lib/mother-link.mjs +156 -0
- package/src/lib/mutex.mjs +31 -0
- package/src/lib/permissions.mjs +115 -0
- package/src/lib/pnpm-store.mjs +189 -0
- package/src/lib/preferences.mjs +212 -0
- package/src/lib/producer-contract.mjs +162 -0
- package/src/lib/reflow.mjs +41 -0
- package/src/lib/remote.mjs +408 -0
- package/src/lib/restart-contract.mjs +752 -0
- package/src/lib/roots.mjs +30 -0
- package/src/lib/rule-registry.mjs +1127 -0
- package/src/lib/runtime-capture.mjs +307 -0
- package/src/lib/semaphore.mjs +34 -0
- package/src/lib/session-bundle.mjs +138 -0
- package/src/lib/session-format.mjs +672 -0
- package/src/lib/sse-parser.mjs +102 -0
- package/src/lib/ssrf-guard.mjs +170 -0
- package/src/lib/status-store.mjs +257 -0
- package/src/lib/task-handle.mjs +622 -0
- package/src/lib/ui-actions.mjs +55 -0
- package/src/lib/umbrella.mjs +1661 -0
- package/src/lib/upgrade-coordinator.mjs +107 -0
- package/src/lib/upgrade-status.mjs +43 -0
- package/src/plugins/adapter.mjs +1468 -0
- package/src/plugins/approver.mjs +1210 -0
- package/src/plugins/auditor.mjs +330 -0
- package/src/plugins/buffer-keeper.mjs +522 -0
- package/src/plugins/decision-center.mjs +2581 -0
- package/src/plugins/forker.mjs +1610 -0
- package/src/plugins/healer.mjs +702 -0
- package/src/plugins/hot-reloader.mjs +274 -0
- package/src/plugins/imports.mjs +247 -0
- package/src/plugins/orchestrator.mjs +3979 -0
- package/src/plugins/restart-guard.mjs +1022 -0
- package/src/plugins/router.mjs +714 -0
- package/src/plugins/scorer.mjs +661 -0
- package/src/plugins/session-bridge.mjs +166 -0
- package/src/plugins/session-catalog.mjs +771 -0
- package/src/plugins/session-router.mjs +125 -0
- package/src/plugins/session-sync.mjs +171 -0
- package/src/plugins/umbrella.mjs +419 -0
- package/tools/approval-drill.mjs +21 -0
- package/tools/boot-guard.mjs +95 -0
- package/tools/decision-ingest.mjs +53 -0
- package/tools/desktop-launch.mjs +71 -0
- package/tools/fangctl.mjs +425 -0
- package/tools/gate/main-city.mjs +204 -0
- package/tools/mcp/server.mjs +121 -0
- package/tools/mcp/tools.mjs +65 -0
- 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
|
+
}
|