@twinsearth/dsh-fang 3.1.2 → 3.1.4
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/client.js +79 -76
- package/package.json +2 -2
- package/src/kernel/types.mjs +1 -1
- package/src/lib/fork-config-lock.mjs +28 -2
- package/src/plugins/forker.mjs +3 -1
- package/src/plugins/orchestrator.mjs +50 -10
package/client.js
CHANGED
|
@@ -725,6 +725,16 @@ window.__ModuleLoader__.load({
|
|
|
725
725
|
.mother-control-title{display:flex;align-items:center;gap:6px;flex-wrap:wrap;font-size:12.5px;font-weight:600;color:var(--f-text)}
|
|
726
726
|
.mother-control-sub{font-size:10.5px;color:var(--f-text-4);line-height:15px}
|
|
727
727
|
.mother-list{display:flex;flex-direction:column;gap:2px;padding:0 2px}
|
|
728
|
+
.essence-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:10px;padding:6px 8px}
|
|
729
|
+
.essence-card{display:flex;flex-direction:column;gap:6px;box-sizing:border-box;min-width:0;
|
|
730
|
+
border:1px solid var(--f-border);border-radius:10px;background:var(--f-surface);
|
|
731
|
+
padding:9px 11px;box-shadow:0 1px 2px rgba(16,24,40,.04)}
|
|
732
|
+
.essence-card-head{display:flex;align-items:center;gap:6px;min-height:24px;flex-wrap:wrap}
|
|
733
|
+
.essence-card-name{font-family:"Microsoft YaHei","微软雅黑",sans-serif;font-size:16px;font-weight:600;
|
|
734
|
+
line-height:24px;color:var(--f-text);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
735
|
+
.essence-card-meta{display:flex;align-items:center;gap:10px;flex-wrap:wrap;font-size:12px;line-height:20px;color:var(--f-text-3)}
|
|
736
|
+
.essence-card-times{display:inline-flex;align-items:center;gap:10px;flex-wrap:wrap;min-width:0}
|
|
737
|
+
.essence-card-actions{display:inline-flex;align-items:center;gap:2px;margin-left:auto}
|
|
728
738
|
.mother-row{border:1px solid transparent;border-radius:14px;transition:background .12s ease,border-color .12s ease,box-shadow .12s ease}
|
|
729
739
|
.mother-row:hover{background:var(--f-surface-2);border-color:var(--f-border)}
|
|
730
740
|
.mother-row.is-open{background:var(--f-surface-2);border-color:var(--f-border)}
|
|
@@ -2605,7 +2615,7 @@ window.__ModuleLoader__.load({
|
|
|
2605
2615
|
'aria-describedby': opts.describedBy,
|
|
2606
2616
|
dataset: opts.dataKey ? { key: opts.dataKey } : undefined,
|
|
2607
2617
|
onClick: opts.onClick,
|
|
2608
|
-
}, leading, label, opts.spin ? icon('spinner', 13) : null, trailing)
|
|
2618
|
+
}, leading, opts.iconOnly ? null : label, opts.spin ? icon('spinner', 13) : null, trailing)
|
|
2609
2619
|
if (opts.softDisabled) node.style.opacity = '.45'
|
|
2610
2620
|
if (opts.iconOnly) {
|
|
2611
2621
|
node.setAttribute('aria-label', opts.ariaLabel || opts.title || '')
|
|
@@ -2971,6 +2981,72 @@ window.__ModuleLoader__.load({
|
|
|
2971
2981
|
.map((value) => String(value ?? '').toLowerCase()).join(' ')
|
|
2972
2982
|
}
|
|
2973
2983
|
|
|
2984
|
+
/**
|
|
2985
|
+
* 元宝卡片:一个独立方框,两行信息(名称 / 生成+同步时间),操作图标收在第二行右侧。
|
|
2986
|
+
*/
|
|
2987
|
+
function renderEssenceCard(S, app, essence, defaultEssenceId) {
|
|
2988
|
+
const name = essence.name || essence.id
|
|
2989
|
+
const created = Number(essence.createdAt) > 0 ? fmtClock(essence.createdAt) : '—'
|
|
2990
|
+
const synced = Number(essence.lastSyncAt ?? essence.lastMergedAt) > 0
|
|
2991
|
+
? fmtClock(essence.lastSyncAt ?? essence.lastMergedAt)
|
|
2992
|
+
: '从未'
|
|
2993
|
+
const action = (label, iconName, options = {}) => button(label, {
|
|
2994
|
+
size: 'sm', variant: 'ghost', iconOnly: true, icon: icon(iconName, 12),
|
|
2995
|
+
ariaLabel: label, title: options.title || label, dataBtnId: options.dataBtnId,
|
|
2996
|
+
disabled: options.disabled, fk: options.fk, onClick: options.onClick,
|
|
2997
|
+
})
|
|
2998
|
+
const actions = [
|
|
2999
|
+
essence.stale && essence.locked !== true
|
|
3000
|
+
? action('同步', 'refresh', { dataBtnId: 'E-03', title: '重放该元主的插件/设置到新母体(配置不变)', onClick: () => void app.syncEssence(essence.id) })
|
|
3001
|
+
: null,
|
|
3002
|
+
essence.archived === true ? null : action('派生', 'plus', { dataBtnId: 'E-05', title: '派生:以该元主为模板创建分身', onClick: () => void app.deriveFromEssence(essence) }),
|
|
3003
|
+
essence.archived === true
|
|
3004
|
+
? action('还原', 'refresh', { dataBtnId: 'E-15', title: '解冻(恢复活跃态),不还原备份内容', onClick: () => void app.unfreezeEssence(essence) })
|
|
3005
|
+
: action(essence.runtime?.running === true ? '停止' : '打开', essence.runtime?.running === true ? 'disc' : 'play', {
|
|
3006
|
+
dataBtnId: 'E-06',
|
|
3007
|
+
title: essence.runtime?.running === true ? '停止该元主的运行实例' : '打开&设置:启动隔离配置态实例',
|
|
3008
|
+
onClick: () => essence.runtime?.running === true ? void app.stopEssenceRuntime(essence) : void app.openEssence(essence.id),
|
|
3009
|
+
}),
|
|
3010
|
+
essence.runtime?.running === true && essence.archived !== true
|
|
3011
|
+
? action('进入', 'external', { dataBtnId: 'E-21', title: '在新标签打开运行中的实例', onClick: () => void app.openEssence(essence.id) })
|
|
3012
|
+
: null,
|
|
3013
|
+
essence.archived === true
|
|
3014
|
+
? null
|
|
3015
|
+
: action('复制', 'copy', { dataBtnId: 'E-07', title: '深复制整份沙盒到新文件夹(不含凭据/备份)', disabled: essence.actions?.copy?.enabled === false, onClick: () => void app.copyEssence(essence) }),
|
|
3016
|
+
essence.archived === true
|
|
3017
|
+
? null
|
|
3018
|
+
: action('归档', 'archive', { dataBtnId: 'E-08', title: '归档元主(冻结,只改元数据)', disabled: essence.actions?.archive?.enabled === false, onClick: () => void app.archiveEssence(essence) }),
|
|
3019
|
+
action('删除', 'trash', { dataBtnId: 'E-09', title: '永久删除 essences/<id>(须先归档;不删会话)', disabled: essence.actions?.delete?.enabled === false, onClick: () => void app.deleteEssence(essence) }),
|
|
3020
|
+
essence.archived === true
|
|
3021
|
+
? null
|
|
3022
|
+
: action('备份', 'disc', { dataBtnId: 'E-12', title: '在 essences/<id>/Backup 存档(只保留一份)', onClick: () => void app.essenceBackup(essence) }),
|
|
3023
|
+
essence.archived === true
|
|
3024
|
+
? null
|
|
3025
|
+
: action('还原备份', 'refresh', { dataBtnId: 'E-13', title: '用最新 Backup 覆盖当前 overlay/merged(需二次确认)', onClick: () => void app.essenceRestore(essence) }),
|
|
3026
|
+
essence.archived === true
|
|
3027
|
+
? null
|
|
3028
|
+
: action('下载', 'download', { dataBtnId: 'E-10', title: '下载元主整包 JSON(不含凭据)', disabled: essence.actions?.download?.enabled === false, onClick: () => void app.downloadEssence(essence) }),
|
|
3029
|
+
].filter(Boolean)
|
|
3030
|
+
|
|
3031
|
+
return h('div', { class: 'essence-card', 'data-essence-id': essence.id, role: 'listitem' },
|
|
3032
|
+
h('div', { class: 'essence-card-head' },
|
|
3033
|
+
h('span', { class: 'essence-card-name' },
|
|
3034
|
+
essence.locked
|
|
3035
|
+
? h('span', { title: name }, name)
|
|
3036
|
+
: editableText(S, app, { key: 'essence:' + essence.id, label: '元主', value: name })),
|
|
3037
|
+
essence.id === defaultEssenceId ? chip('info', '默认', { dot: false }) : null,
|
|
3038
|
+
essence.locked ? chip('neutral', '锁定', { dot: false }) : null,
|
|
3039
|
+
essence.stale ? chip('warn', '🔼 待同步', { dot: false, title: '母体镜像已变化,此元主仍在旧镜像上' }) : null,
|
|
3040
|
+
essence.status === 'conflicted' ? chip('bad', '冲突', { dot: false }) : null,
|
|
3041
|
+
essence.archived === true ? chip('neutral', '冻结', { dot: false, title: '已归档(冻结):只能还原或删除' }) : null),
|
|
3042
|
+
h('div', { class: 'essence-card-meta' },
|
|
3043
|
+
h('span', { class: 'essence-card-times' },
|
|
3044
|
+
h('span', null, `生成 ${created}`),
|
|
3045
|
+
h('span', { title: '最后一次与母体同步时间' }, `同步 ${synced}`)),
|
|
3046
|
+
h('span', { style: { flex: '1' } }),
|
|
3047
|
+
h('div', { class: 'essence-card-actions' }, ...actions)))
|
|
3048
|
+
}
|
|
3049
|
+
|
|
2974
3050
|
function renderMotherPanel(S, app) {
|
|
2975
3051
|
const freshness = freshnessOf(S)
|
|
2976
3052
|
const all = S.sessions.items
|
|
@@ -3124,84 +3200,11 @@ window.__ModuleLoader__.load({
|
|
|
3124
3200
|
title: '克隆母体 profile 的可写层(插件补丁/依赖/设置)生成新元主;不复制凭据与会话',
|
|
3125
3201
|
onClick: () => void app.captureEssence(),
|
|
3126
3202
|
}))
|
|
3127
|
-
const essenceList = h('div', { class: 'essence-list', 'data-zone': 'essence-list'
|
|
3203
|
+
const essenceList = h('div', { class: 'essence-list', 'data-zone': 'essence-list' },
|
|
3128
3204
|
essences.length === 0
|
|
3129
3205
|
? h('span', { class: 'hint' }, '还没有自定义元主;点上方「从母体生成元主」克隆当前母体配置。')
|
|
3130
3206
|
: null,
|
|
3131
|
-
...essences.map((essence) =>
|
|
3132
|
-
essence.locked
|
|
3133
|
-
? h('span', { class: 'hint' }, essence.name || essence.id)
|
|
3134
|
-
: editableText(S, app, { key: 'essence:' + essence.id, label: '元主', value: essence.name || essence.id }),
|
|
3135
|
-
essence.id === defaultEssenceId ? h('span', { class: 'chip' }, '默认') : null,
|
|
3136
|
-
essence.locked ? h('span', { class: 'chip' }, '锁定') : null,
|
|
3137
|
-
essence.stale ? h('span', { class: 'chip', title: '母体镜像已变化,此元主仍在旧镜像上' }, '🔼 待同步') : null,
|
|
3138
|
-
essence.stale && essence.locked !== true
|
|
3139
|
-
? button('同步', {
|
|
3140
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-03',
|
|
3141
|
-
title: '重放该元主的插件/设置到新母体(配置不变)',
|
|
3142
|
-
onClick: () => void app.syncEssence(essence.id),
|
|
3143
|
-
})
|
|
3144
|
-
: null,
|
|
3145
|
-
essence.status === 'conflicted' ? h('span', { class: 'chip' }, '冲突') : null,
|
|
3146
|
-
essence.archived === true ? h('span', { class: 'chip', title: '已归档(冻结):只能还原或删除' }, '冻结') : null,
|
|
3147
|
-
h('span', { style: { display: 'inline-flex', gap: 4 } },
|
|
3148
|
-
essence.archived === true ? null : button('派生', {
|
|
3149
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-05',
|
|
3150
|
-
title: '派生:以该元主为模板创建分身(继承其插件&配置),可复制一个现有会话进分身沙箱',
|
|
3151
|
-
onClick: () => void app.deriveFromEssence(essence),
|
|
3152
|
-
}),
|
|
3153
|
-
essence.archived === true
|
|
3154
|
-
? button('还原', {
|
|
3155
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-15',
|
|
3156
|
-
title: '解冻(恢复活跃态,可打开/设置/派生);不还原备份内容',
|
|
3157
|
-
onClick: () => void app.unfreezeEssence(essence),
|
|
3158
|
-
})
|
|
3159
|
-
: button(essence.runtime?.running === true ? '停止' : '打开', {
|
|
3160
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-06',
|
|
3161
|
-
title: essence.runtime?.running === true
|
|
3162
|
-
? '停止该元主的运行实例(端口释放;会话/沙盒文件保留)'
|
|
3163
|
-
: '打开&设置:启动或打开该元主的隔离配置态实例(不写母体 sessions)',
|
|
3164
|
-
onClick: () => essence.runtime?.running === true ? void app.stopEssenceRuntime(essence) : void app.openEssence(essence.id),
|
|
3165
|
-
}),
|
|
3166
|
-
essence.runtime?.running === true && essence.archived !== true ? button('进入', {
|
|
3167
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-21',
|
|
3168
|
-
title: '在新标签打开运行中的实例(临时 token,不落盘)',
|
|
3169
|
-
onClick: () => void app.openEssence(essence.id),
|
|
3170
|
-
}) : null,
|
|
3171
|
-
essence.archived === true ? null : button('复制', {
|
|
3172
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-07',
|
|
3173
|
-
title: essence.actions?.copy?.reason || '深复制整份沙盒到新文件夹(不含凭据/运行态/备份)',
|
|
3174
|
-
disabled: essence.actions?.copy?.enabled === false,
|
|
3175
|
-
onClick: () => void app.copyEssence(essence),
|
|
3176
|
-
}),
|
|
3177
|
-
essence.archived === true ? null : button('归档', {
|
|
3178
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-08',
|
|
3179
|
-
title: essence.actions?.archive?.reason || '归档元主(冻结,只改元数据)',
|
|
3180
|
-
disabled: essence.actions?.archive?.enabled === false,
|
|
3181
|
-
onClick: () => void app.archiveEssence(essence),
|
|
3182
|
-
}),
|
|
3183
|
-
button('删除', {
|
|
3184
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-09',
|
|
3185
|
-
title: essence.actions?.delete?.reason || '永久删除 essences/<id>(须先归档;不删会话)',
|
|
3186
|
-
disabled: essence.actions?.delete?.enabled === false,
|
|
3187
|
-
onClick: () => void app.deleteEssence(essence),
|
|
3188
|
-
}),
|
|
3189
|
-
essence.archived === true ? null : button('备份', {
|
|
3190
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-12',
|
|
3191
|
-
title: '在 essences/<id>/Backup 存档(只保留一份,旧备份覆盖)',
|
|
3192
|
-
onClick: () => void app.essenceBackup(essence),
|
|
3193
|
-
}),
|
|
3194
|
-
essence.archived === true ? null : button('还原备份', {
|
|
3195
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-13',
|
|
3196
|
-
title: '用最新 Backup 覆盖当前 overlay/merged(需二次确认)',
|
|
3197
|
-
onClick: () => void app.essenceRestore(essence),
|
|
3198
|
-
}),
|
|
3199
|
-
essence.archived === true ? null : button('下载', {
|
|
3200
|
-
size: 'sm', variant: 'ghost', dataBtnId: 'E-10',
|
|
3201
|
-
title: essence.actions?.download?.reason || '下载元主整包 JSON(不含凭据)',
|
|
3202
|
-
disabled: essence.actions?.download?.enabled === false,
|
|
3203
|
-
onClick: () => void app.downloadEssence(essence),
|
|
3204
|
-
})))))
|
|
3207
|
+
...essences.map((essence) => renderEssenceCard(S, app, essence, defaultEssenceId)))
|
|
3205
3208
|
|
|
3206
3209
|
return h('section', { class: 'panel', 'data-zone': 'mother', 'data-freshness': freshness, 'aria-labelledby': 'fang-mother-title' },
|
|
3207
3210
|
head,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/dsh-fang",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "dsh-Fang (瓮城) — mother/fork plugin development environment for DeepSeek Harness: one readonly mother, a disposable child dsh-Web per task.",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"node": ">=22"
|
|
50
50
|
},
|
|
51
51
|
"optionalDependencies": {
|
|
52
|
-
"@twinsearth/dsh-fang-queue-journal": "0.1.
|
|
52
|
+
"@twinsearth/dsh-fang-queue-journal": "0.1.3",
|
|
53
53
|
"@twinsearth/dsh-fang-web-entry": "0.1.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
package/src/kernel/types.mjs
CHANGED
|
@@ -74,8 +74,7 @@ function withLockRows(entries, ids) {
|
|
|
74
74
|
return { entries: out, added }
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
export function applyForkConfigLock(profileDir, options = {}) {
|
|
78
|
-
if (String(process.env.DSH_FANG_FORK_CONFIG_LOCK ?? '1') === '0') return { ok: true, skipped: true }
|
|
77
|
+
export function applyForkConfigLock(profileDir, options = {}) { if (String(process.env.DSH_FANG_FORK_CONFIG_LOCK ?? '1') === '0') return { ok: true, skipped: true }
|
|
79
78
|
const file = path.join(String(profileDir), 'cordis.patch.yml')
|
|
80
79
|
let text = ''
|
|
81
80
|
try { text = fs.readFileSync(file, 'utf8') } catch { text = '' }
|
|
@@ -115,3 +114,30 @@ export function applyForkConfigLock(profileDir, options = {}) {
|
|
|
115
114
|
fs.writeFileSync(file, `${prefix}${comment}${lines.join('\n')}\n`, 'utf8')
|
|
116
115
|
return { ok: true, entries: ids.length }
|
|
117
116
|
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 解除 fork 生产盘锁(只删 disabled:true 的锁定行,不碰其他配置)。
|
|
120
|
+
* 元宝运行态 essence-runtime 是配置实例,升级后需要清掉历史 provision 写入的锁。
|
|
121
|
+
*/
|
|
122
|
+
export function clearForkConfigLock(profileDir, options = {}) {
|
|
123
|
+
const file = path.join(String(profileDir), 'cordis.patch.yml')
|
|
124
|
+
let text = ''
|
|
125
|
+
try { text = fs.readFileSync(file, 'utf8') } catch { return { ok: true, removed: 0 } }
|
|
126
|
+
const ids = options.ids ?? FORK_LOCKED_ENTRY_IDS
|
|
127
|
+
const jsonEntries = jsonPatchEntries(text)
|
|
128
|
+
if (jsonEntries !== null) {
|
|
129
|
+
const wanted = new Set(ids)
|
|
130
|
+
const kept = jsonEntries.filter((entry) => !(entry && typeof entry === 'object' && wanted.has(entry.id) && entry.disabled === true))
|
|
131
|
+
if (kept.length === jsonEntries.length) return { ok: true, removed: 0 }
|
|
132
|
+
fs.writeFileSync(file, `${JSON.stringify(kept, null, 2)}\n`, 'utf8')
|
|
133
|
+
return { ok: true, removed: jsonEntries.length - kept.length }
|
|
134
|
+
}
|
|
135
|
+
let removed = 0
|
|
136
|
+
for (const id of ids) {
|
|
137
|
+
const escaped = String(id).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
138
|
+
const re = new RegExp(`(^|\\n)\\s*-\\s*id:\\s*${escaped}\\s*\\n\\s*disabled:\\s*true\\s*(?=\\n|$)`, 'g')
|
|
139
|
+
text = text.replace(re, (match, lead) => { removed += 1; return lead })
|
|
140
|
+
}
|
|
141
|
+
if (removed > 0) fs.writeFileSync(file, text, 'utf8')
|
|
142
|
+
return { ok: true, removed }
|
|
143
|
+
}
|
package/src/plugins/forker.mjs
CHANGED
|
@@ -788,7 +788,9 @@ export function apply(ctx, config) {
|
|
|
788
788
|
cloned = cloneProfileConfig(sourceTemplateDir, profileDir)
|
|
789
789
|
}
|
|
790
790
|
// 生产盘锁定:关闭插件安装 / 设置 UI(派生时写入 profile patch)。
|
|
791
|
-
|
|
791
|
+
// essence-runtime 是元宝的“配置态实例”,必须保留插件管理能力,不能套生产盘锁。
|
|
792
|
+
const configInstance = path.basename(String(profileDir)) === 'essence-runtime'
|
|
793
|
+
const configLock = configInstance ? { ok: true, skipped: true, runtime: true } : applyForkConfigLock(profileDir)
|
|
792
794
|
if (configLock.ok !== true) warnings.push('fork-config-lock-failed')
|
|
793
795
|
// 配置文件只读:防误写(DSH_FANG_FORK_PROFILE_RO=0 可关)。
|
|
794
796
|
const profileReadonly = setProfileConfigReadonly(profileDir, true)
|
|
@@ -14,7 +14,7 @@ import path from 'node:path'
|
|
|
14
14
|
import {
|
|
15
15
|
z, roleGate, resolveFangLayout, resolveProfileDir, resolveSessionsLayout,
|
|
16
16
|
SERVICE, AUDIT, TASK_STATUS, FORK_STATUS, FANG_VERSION, ADAPTER_OP,
|
|
17
|
-
exists, ensureDir, readJson, writeJsonAtomic, writeFileAtomic, sha256, removeTree, copyTree, digestTree,
|
|
17
|
+
exists, ensureDir, readJson, writeJsonAtomic, writeFileAtomic, sha256, removeTree, copyTree, digestTree, makeJunction,
|
|
18
18
|
newId, iso, nowMs, bus, sleep, parseWebUrl, probeWebUrl,
|
|
19
19
|
invokeCommercial, commercialConfigSchemaDefaults,
|
|
20
20
|
} from '../kernel/index.mjs'
|
|
@@ -30,6 +30,7 @@ import { DEFAULT_ESSENCE_NAME, planDefaultEssence } from '../lib/default-essence
|
|
|
30
30
|
import { MirrorUpgradeCoordinator } from '../lib/upgrade-coordinator.mjs'
|
|
31
31
|
import { createBusinessProducers } from '../lib/business-producers.mjs'
|
|
32
32
|
import { createManifestOfficialSource } from '../lib/mirror-official-source.mjs'
|
|
33
|
+
import { clearForkConfigLock } from '../lib/fork-config-lock.mjs'
|
|
33
34
|
import { readForkSupervisionSettings, writeForkSupervisionSettings } from '../lib/fork-supervision-settings.mjs'
|
|
34
35
|
import { DEFAULT_EXPECTED_ROUTE_COUNT, readCompatStatus, runCompatGate, writeCompatStatus } from '../lib/compat.mjs'
|
|
35
36
|
import { buildUpgradeStatus } from '../lib/upgrade-status.mjs'
|
|
@@ -82,6 +83,17 @@ export function atomicReplaceDir(sourceDir, targetDir) {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
|
|
86
|
+
const FORK_BUNDLE_NAMES = Object.freeze(['@twinsearth/dsh-fang', '@twinsearth/dsh-fang'])
|
|
87
|
+
|
|
88
|
+
/** 分身 profile 可解析的 fang bundle 路径(npm 安装名/开发 link 名都接受)。 */
|
|
89
|
+
function forkBundlePath(profileDir) {
|
|
90
|
+
for (const name of FORK_BUNDLE_NAMES) {
|
|
91
|
+
const candidate = path.join(String(profileDir ?? ''), 'node_modules', ...name.split('/'))
|
|
92
|
+
if (exists(candidate)) return candidate
|
|
93
|
+
}
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
96
|
+
|
|
85
97
|
export const name = 'fang-orchestrator'
|
|
86
98
|
export const inject = []
|
|
87
99
|
|
|
@@ -754,9 +766,10 @@ export function apply(ctx, config) {
|
|
|
754
766
|
|
|
755
767
|
// 防御:分身的 profile 必须能解析本 bundle;否则派生出来的是一个"没有 /fang 路由"的
|
|
756
768
|
// 僵尸分身(adapter 握手会得到 http-404)。发现即回收并如实报错。
|
|
769
|
+
// npm 安装名是 @twinsearth/dsh-fang;开发 link 才是 @twinsearth/dsh-fang。两者都算可用。
|
|
757
770
|
const forkProfileDir = path.join(homeDir, 'profiles', profile)
|
|
758
|
-
const forkBundle =
|
|
759
|
-
if (!
|
|
771
|
+
const forkBundle = forkBundlePath(forkProfileDir)
|
|
772
|
+
if (!forkBundle) {
|
|
760
773
|
task.status = TASK_STATUS.FAILED
|
|
761
774
|
tasks.delete(taskId)
|
|
762
775
|
persist()
|
|
@@ -1414,8 +1427,8 @@ export function apply(ctx, config) {
|
|
|
1414
1427
|
return { ok: false, error: 'path-escape', taskId: id, detail: String(error?.message ?? error) }
|
|
1415
1428
|
}
|
|
1416
1429
|
const forkProfileDir = path.join(task.homeDir, 'profiles', task.profile)
|
|
1417
|
-
const forkBundle =
|
|
1418
|
-
if (!
|
|
1430
|
+
const forkBundle = forkBundlePath(forkProfileDir)
|
|
1431
|
+
if (!forkBundle) {
|
|
1419
1432
|
return { ok: false, error: 'fork-bundle-unavailable', taskId: id, detail: forkProfileDir }
|
|
1420
1433
|
}
|
|
1421
1434
|
const f = forker()
|
|
@@ -1494,8 +1507,8 @@ export function apply(ctx, config) {
|
|
|
1494
1507
|
report.failed.push({ taskId: id, error: 'path-escape' })
|
|
1495
1508
|
continue
|
|
1496
1509
|
}
|
|
1497
|
-
const forkBundle = path.join(task.homeDir, 'profiles', task.profile
|
|
1498
|
-
if (!
|
|
1510
|
+
const forkBundle = forkBundlePath(path.join(task.homeDir, 'profiles', task.profile))
|
|
1511
|
+
if (!forkBundle) {
|
|
1499
1512
|
report.failed.push({ taskId: id, error: 'fork-bundle-unavailable' })
|
|
1500
1513
|
continue
|
|
1501
1514
|
}
|
|
@@ -1916,8 +1929,19 @@ export function apply(ctx, config) {
|
|
|
1916
1929
|
const stale = mirrorFingerprint.length > 0 && meta.archived !== true
|
|
1917
1930
|
&& String(meta.lastMergedFingerprint ?? '') !== mirrorFingerprint
|
|
1918
1931
|
const sessionQuota = countEssenceSessions(meta.id, meta)
|
|
1932
|
+
// 元宝卡片第二行:生成时间 + 最后一次与母体同步时间(merged/fingerprint.json)。
|
|
1933
|
+
let lastMergedAt = null
|
|
1934
|
+
try {
|
|
1935
|
+
const fingerprint = readJson(path.join(essenceManager.essenceRoot(meta.id), 'merged', 'fingerprint.json'), null)
|
|
1936
|
+
const value = Number(fingerprint?.mergedAt)
|
|
1937
|
+
if (Number.isFinite(value) && value > 0) lastMergedAt = value
|
|
1938
|
+
} catch { /* profile 尚未物化 */ }
|
|
1939
|
+
if (!lastMergedAt && Number(meta.updatedAt) > 0) lastMergedAt = Number(meta.updatedAt)
|
|
1919
1940
|
return {
|
|
1920
1941
|
...meta,
|
|
1942
|
+
createdAt: Number(meta.createdAt) || null,
|
|
1943
|
+
lastMergedAt,
|
|
1944
|
+
lastSyncAt: lastMergedAt,
|
|
1921
1945
|
locked: meta.locked === true,
|
|
1922
1946
|
official: meta.official === true,
|
|
1923
1947
|
archived: meta.archived === true,
|
|
@@ -2158,9 +2182,12 @@ export function apply(ctx, config) {
|
|
|
2158
2182
|
// makeJunction 对已存在的链接不会替换,所以先安全移除旧 junction(不进入目标)。
|
|
2159
2183
|
const runtimeProfileDir = path.join(homeDir, 'profiles', 'essence-runtime')
|
|
2160
2184
|
const runtimeModules = path.join(runtimeProfileDir, 'node_modules')
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2185
|
+
// 迁移/旧版本可能留下“指向不存在 merged/profile/node_modules”的 junction;
|
|
2186
|
+
// fs.existsSync 对 broken junction 返回 false,必须用 lstat 才能发现并清掉。
|
|
2187
|
+
try {
|
|
2188
|
+
const stat = fs.lstatSync(runtimeModules)
|
|
2189
|
+
if (stat.isSymbolicLink() || !exists(runtimeModules)) removeTree(runtimeModules)
|
|
2190
|
+
} catch { /* 不存在 */ }
|
|
2164
2191
|
const legacyHomes = [
|
|
2165
2192
|
path.join(layout.dataDir, 'runtime', forkId, 'home'),
|
|
2166
2193
|
path.join(essenceManager.essenceRoot(id), 'runtime', 'home'),
|
|
@@ -2180,6 +2207,19 @@ export function apply(ctx, config) {
|
|
|
2180
2207
|
nodeModulesSource: essenceModules,
|
|
2181
2208
|
})
|
|
2182
2209
|
if (!provisioned.ok) throw new Error(String(provisioned.error ?? 'runtime-provision-failed'))
|
|
2210
|
+
// 历史版本把生产盘锁写进了 essence-runtime;配置实例必须能管理插件,升级后清掉。
|
|
2211
|
+
try { clearForkConfigLock(runtimeProfileDir) } catch { /* best effort */ }
|
|
2212
|
+
// provision 若看到旧 junction 可能不替换;这里以 essenceModules 为准做最后自愈。
|
|
2213
|
+
if (!exists(runtimeModules)) {
|
|
2214
|
+
try {
|
|
2215
|
+
const stat = fs.lstatSync(runtimeModules)
|
|
2216
|
+
if (stat.isSymbolicLink()) removeTree(runtimeModules)
|
|
2217
|
+
} catch { /* ignore */ }
|
|
2218
|
+
if (!exists(essenceModules)) throw new Error('runtime-node-modules-source-missing')
|
|
2219
|
+
try { makeJunction(essenceModules, runtimeModules) } catch (error) {
|
|
2220
|
+
throw new Error(`runtime-node-modules-junction-failed: ${String(error?.message ?? error)}`)
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2183
2223
|
writeModuleStoreConfig(runtimeProfileDir)
|
|
2184
2224
|
// 先导入选中的进行中会话,再拉起实例(实例启动时就能看到它们)。
|
|
2185
2225
|
const importedSessions = importSessionsInto(homeDir, input?.sessionIds)
|