@twinsearth/dsh-fang 3.1.30 → 3.1.32

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
@@ -2129,6 +2129,69 @@ window.__ModuleLoader__.load({
2129
2129
  doc.body.appendChild(backdrop)
2130
2130
  }
2131
2131
 
2132
+ /**
2133
+ * v3.1.32:绿色「派生新分身」。
2134
+ * 1) 自动关联默认元主(开发者推荐的模板);没有默认则取第一个活跃元主;
2135
+ * 2) 弹窗选择一个进行中会话(一次只能导入一个,与服务端 derive 的硬校验一致)。
2136
+ */
2137
+ async function deriveQuick() {
2138
+ if (isBusy()) return
2139
+ S.busy = 'derive:quick'
2140
+ let essence = null
2141
+ try {
2142
+ const listed = await api('/fang/api/essence/list')
2143
+ const data = listed.body ?? {}
2144
+ const essences = Array.isArray(data.essences) ? data.essences.filter((item) => item && item.archived !== true) : []
2145
+ const defaultId = String(data.defaultId ?? '')
2146
+ essence = essences.find((item) => String(item.id) === defaultId) ?? essences[0] ?? null
2147
+ } catch { essence = null }
2148
+ S.busy = ''
2149
+ if (!essence) {
2150
+ setNotice({
2151
+ tone: 'warn',
2152
+ title: '还没有可用的元主模板',
2153
+ message: '先「克隆母体」生成一个元主,或在元主列表里设置默认元主,再派生分身。',
2154
+ })
2155
+ return
2156
+ }
2157
+ S.busy = 'derive:quick:sessions'
2158
+ const res = await api('/fang/api/sessions?limit=200')
2159
+ S.busy = ''
2160
+ const sessions = Array.isArray(res.body?.sessions)
2161
+ ? res.body.sessions.filter((session) => session.archived !== true)
2162
+ : []
2163
+ if (sessions.length === 0) {
2164
+ setNotice({ tone: 'warn', title: '没有可导入的会话', message: '先在 DSH 里开一个对话,再派生分身。' })
2165
+ return
2166
+ }
2167
+ showDerivePicker(sessions, essence.name || essence.id, async (sessionId) => {
2168
+ const session = sessions.find((item) => String(item.sessionId) === String(sessionId))
2169
+ const title = String(session?.title || essence.name || '派生分身').slice(0, 60)
2170
+ S.busy = 'derive:quick:run'
2171
+ const out = await api('/fang/api/tasks/create', {
2172
+ method: 'POST',
2173
+ body: JSON.stringify({ title, essenceId: essence.id, importSession: { sessionId } }),
2174
+ })
2175
+ S.busy = ''
2176
+ if (out.status === 200 && out.body?.ok) {
2177
+ setNotice({
2178
+ tone: 'ok',
2179
+ title: '已派生分身',
2180
+ message: `模板「${essence.name || essence.id}」· 会话 ${short(String(sessionId), 8)}${out.body?.port ? ' · 端口 ' + out.body.port : ''}`,
2181
+ actions: out.body?.taskId ? [{ label: '打开分身', onClick: () => void openTask({ taskId: out.body.taskId }) }] : [],
2182
+ })
2183
+ } else {
2184
+ setNotice({
2185
+ tone: 'bad',
2186
+ title: '派生失败',
2187
+ message: failureHint(out.body?.error || 'http-' + out.status),
2188
+ detail: out.body?.detail || '',
2189
+ actions: [{ label: '重试', onClick: () => void deriveQuick() }],
2190
+ })
2191
+ }
2192
+ await refresh()
2193
+ })
2194
+ }
2132
2195
  async function deriveFromEssence(essence) {
2133
2196
  if (isBusy()) return
2134
2197
  S.busy = 'essence:derive:' + essence.id
@@ -2783,7 +2846,7 @@ window.__ModuleLoader__.load({
2783
2846
  adviseDecision,
2784
2847
  openEssence, copyEssence, archiveEssence, deleteEssence, downloadEssence, essenceImport,
2785
2848
  essenceBackup, essenceRestore, openEssenceDetail, unfreezeEssence, stopEssenceRuntime,
2786
- openBranches, forkBranch, activateBranch, deriveFromEssence,
2849
+ openBranches, forkBranch, activateBranch, deriveFromEssence, deriveQuick,
2787
2850
  beginRename, commitRename, cancelRename, selectSession, toggleSet, toggleForkGroup,
2788
2851
  toggleTemporary, setView: (next) => { S.view = next; schedule(true) },
2789
2852
  loadForkSessions, loadMirror, mirrorAction, loadLink, probeMother, notify, announce,
@@ -3119,7 +3182,8 @@ window.__ModuleLoader__.load({
3119
3182
  if (node) node.focus?.()
3120
3183
  return
3121
3184
  }
3122
- void app.deriveTask({ title: '派生新分身' })
3185
+ // v3.1.32:绿色按钮 = 默认元主 + 选一个进行中会话(不再直接发无会话请求)
3186
+ void app.deriveQuick()
3123
3187
  },
3124
3188
  fk: 'derive',
3125
3189
  })),
@@ -3803,7 +3867,7 @@ window.__ModuleLoader__.load({
3803
3867
  ? ['没有临时内容', '临时 = 快速派生的空白分身(标题为“快速派生”)与空会话。']
3804
3868
  : ['还没有存档', '归档后的分身会出现在这里,可还原或永久删除。']
3805
3869
  body.append(emptyBlock(copy[0], copy[1], key === 'active'
3806
- ? [button('派生新分身', { size: 'sm', variant: 'primary', onClick: () => void app.deriveTask({ title: '派生新分身' }) })]
3870
+ ? [button('派生新分身', { size: 'sm', variant: 'primary', onClick: () => void app.deriveQuick() })]
3807
3871
  : []))
3808
3872
  } else {
3809
3873
  for (const task of tasks) body.append(renderForkCard(S, app, task, { archived: key === 'archived' }))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/dsh-fang",
3
- "version": "3.1.30",
3
+ "version": "3.1.32",
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.",
@@ -129,7 +129,7 @@ export const AUDIT = {
129
129
  RUNTIME_ERROR: 'runtime-error',
130
130
  }
131
131
 
132
- export const FANG_VERSION = '3.1.30'
132
+ export const FANG_VERSION = '3.1.32'
133
133
 
134
134
  /**
135
135
  * @typedef {object} ForkInfo
@@ -208,8 +208,11 @@ export function parseYamlSubset(text) {
208
208
  const key = inlineKey[1]
209
209
  const restValue = rest.slice(inlineKey[0].length).trim()
210
210
  const mapped = {}
211
- if (restValue.length > 0) mapped[key] = parseScalar(restValue)
212
- else {
211
+ if (restValue.length > 0) {
212
+ const [folded, nextIndex] = foldContinuations({ content: restValue }, index + 1, virtualIndent)
213
+ mapped[key] = parseScalar(folded)
214
+ index = nextIndex - 1
215
+ } else {
213
216
  const next = tokens[index + 1]
214
217
  if (next !== undefined && next.indent > virtualIndent) {
215
218
  const [child, nextIndex] = parseBlock(index + 1, next.indent)
@@ -232,8 +235,9 @@ export function parseYamlSubset(text) {
232
235
  const childKey = match[1]
233
236
  const childRest = String(match[2] ?? '').trim()
234
237
  if (childRest.length > 0) {
235
- mapped[childKey] = parseScalar(childRest)
236
- index += 1
238
+ const [folded, nextIndex] = foldContinuations({ content: childRest }, index + 1, virtualIndent)
239
+ mapped[childKey] = parseScalar(folded)
240
+ index = nextIndex
237
241
  continue
238
242
  }
239
243
  const nextToken = tokens[index + 1]
@@ -255,6 +259,26 @@ export function parseYamlSubset(text) {
255
259
  return [items, index]
256
260
  }
257
261
 
262
+ // v3.1.31:折行纯量(plain scalar continuation)。
263
+ // DSH 会把超长 description 折成多行,续行缩进更深、且既不是 "key:" 也不是 "- item"。
264
+ // 结构行(映射键/序列项)一律不吸收,避免吞掉兄弟节点。
265
+ const KEY_LINE = /^[A-Za-z0-9_$.-]+:(?:\s|$)/
266
+ const isStructural = (token) => isSequenceLine(token) || KEY_LINE.test(token.content)
267
+ const foldContinuations = (valueToken, startIndex, parentIndent) => {
268
+ const parts = []
269
+ let index = startIndex
270
+ while (index < tokens.length) {
271
+ const token = tokens[index]
272
+ if (token.indent <= parentIndent) break
273
+ if (isStructural(token)) break
274
+ parts.push(token.content)
275
+ index += 1
276
+ }
277
+ if (parts.length === 0) return [valueToken.content, startIndex]
278
+ const first = valueToken.content
279
+ const joined = [first, ...parts].join(" ")
280
+ return [joined, index]
281
+ }
258
282
  const parseMapping = (startIndex, indent) => {
259
283
  const mapping = {}
260
284
  let index = startIndex
@@ -270,8 +294,10 @@ export function parseYamlSubset(text) {
270
294
  const key = match[1]
271
295
  const rest = String(match[2] ?? '').trim()
272
296
  if (rest.length > 0) {
273
- mapping[key] = parseScalar(rest)
274
- index += 1
297
+ // v3.1.31:先吸收折行续行,再按纯量解析。
298
+ const [folded, nextIndex] = foldContinuations({ content: rest }, index + 1, indent)
299
+ mapping[key] = parseScalar(folded)
300
+ index = nextIndex
275
301
  continue
276
302
  }
277
303
  const next = tokens[index + 1]