@twinsearth/dsh-fang 3.1.3 → 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 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', style: { display: 'flex', flexWrap: 'wrap', gap: '8px', padding: '4px 8px' } },
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) => h('div', { class: 'essence-row', 'data-essence-id': essence.id, style: { display: 'inline-flex', alignItems: 'center', gap: '6px' } },
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",
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.",
@@ -128,7 +128,7 @@ export const AUDIT = {
128
128
  RUNTIME_ERROR: 'runtime-error',
129
129
  }
130
130
 
131
- export const FANG_VERSION = '3.1.3'
131
+ export const FANG_VERSION = '3.1.4'
132
132
 
133
133
  /**
134
134
  * @typedef {object} ForkInfo
@@ -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
+ }
@@ -788,7 +788,9 @@ export function apply(ctx, config) {
788
788
  cloned = cloneProfileConfig(sourceTemplateDir, profileDir)
789
789
  }
790
790
  // 生产盘锁定:关闭插件安装 / 设置 UI(派生时写入 profile patch)。
791
- const configLock = applyForkConfigLock(profileDir)
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)
@@ -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'
@@ -1928,8 +1929,19 @@ export function apply(ctx, config) {
1928
1929
  const stale = mirrorFingerprint.length > 0 && meta.archived !== true
1929
1930
  && String(meta.lastMergedFingerprint ?? '') !== mirrorFingerprint
1930
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)
1931
1940
  return {
1932
1941
  ...meta,
1942
+ createdAt: Number(meta.createdAt) || null,
1943
+ lastMergedAt,
1944
+ lastSyncAt: lastMergedAt,
1933
1945
  locked: meta.locked === true,
1934
1946
  official: meta.official === true,
1935
1947
  archived: meta.archived === true,
@@ -2195,6 +2207,8 @@ export function apply(ctx, config) {
2195
2207
  nodeModulesSource: essenceModules,
2196
2208
  })
2197
2209
  if (!provisioned.ok) throw new Error(String(provisioned.error ?? 'runtime-provision-failed'))
2210
+ // 历史版本把生产盘锁写进了 essence-runtime;配置实例必须能管理插件,升级后清掉。
2211
+ try { clearForkConfigLock(runtimeProfileDir) } catch { /* best effort */ }
2198
2212
  // provision 若看到旧 junction 可能不替换;这里以 essenceModules 为准做最后自愈。
2199
2213
  if (!exists(runtimeModules)) {
2200
2214
  try {