@twinsearth/dsh-fang 3.1.19 → 3.1.21

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
@@ -6421,20 +6421,31 @@ window.__ModuleLoader__.load({
6421
6421
  const NAV_TEXTS = ['插件']
6422
6422
  const ACTION_TEXTS = ['启动', '启动插件', '开始使用', '启用']
6423
6423
 
6424
+ /** v3.1.20:宿主侧栏行类名会随版本变化,不再只认 panelRow。 */
6424
6425
  const isPanelRow = (node) => {
6425
6426
  try {
6426
6427
  if (!node || node.tagName !== 'BUTTON') return false
6427
6428
  const cls = String(node.className || '')
6428
- return /panelRow/i.test(cls)
6429
+ if (/panelRow/i.test(cls)) return true
6430
+ // 兜底:侧栏/导航容器内的按钮
6431
+ return Boolean(node.closest('nav, aside, [class*="sidebar"], [class*="sideBar"], [class*="sider"]'))
6429
6432
  } catch { return false }
6430
6433
  }
6431
6434
 
6435
+ /** 插件入口的文本判定(中英 + 少量变体),容忍零宽字符与多余空白。 */
6436
+ const isPluginNavText = (text) => {
6437
+ const clean = String(text || '').replace(/[\u200b-\u200d\ufeff]/g, '').replace(/\s+/g, ' ').trim()
6438
+ if (!clean) return false
6439
+ if (clean === '插件' || clean === 'Plugins' || clean === 'Plugin') return true
6440
+ // 「插件」后面可能跟计数徽标,例如「插件 3」
6441
+ return /^插件(\s|$)/.test(clean) || /^Plugins?(\s|$)/.test(clean)
6442
+ }
6443
+
6432
6444
  const hidePluginNav = () => {
6433
6445
  if (disposed || !active) return
6434
6446
  for (const node of doc.querySelectorAll('button')) {
6435
6447
  if (!isPanelRow(node)) continue
6436
- const text = String(node.textContent || '').trim()
6437
- if (!NAV_TEXTS.includes(text)) continue
6448
+ if (!isPluginNavText(node.textContent)) continue
6438
6449
  if (node.dataset.fangForkHidden === '1' && node.hidden) continue
6439
6450
  node.dataset.fangForkHidden = '1'
6440
6451
  node.hidden = true
@@ -6450,7 +6461,7 @@ window.__ModuleLoader__.load({
6450
6461
  if (!button) return
6451
6462
  const text = String(button.textContent || '').trim()
6452
6463
  // ① 侧栏「插件」入口:双重保险(DOM 已隐藏,这里再拦一次点击/键盘激活)
6453
- if (isPanelRow(button) && NAV_TEXTS.includes(text)) {
6464
+ if (isPanelRow(button) && isPluginNavText(text)) {
6454
6465
  event.preventDefault()
6455
6466
  event.stopPropagation()
6456
6467
  event.stopImmediatePropagation()
@@ -6480,6 +6491,10 @@ window.__ModuleLoader__.load({
6480
6491
  if (active || disposed) return
6481
6492
  active = true
6482
6493
  hidePluginNav()
6494
+ try {
6495
+ doc.documentElement?.setAttribute('data-fang-fork-locks', 'applied')
6496
+ window.__fangForkLocks = { applied: true, at: Date.now() }
6497
+ } catch { /* ignore */ }
6483
6498
  doc.addEventListener('click', onClickCapture, true)
6484
6499
  try {
6485
6500
  observer = new MutationObserver(() => { hidePluginNav() })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/dsh-fang",
3
- "version": "3.1.19",
3
+ "version": "3.1.21",
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.",
@@ -50,7 +50,7 @@
50
50
  "node": ">=22"
51
51
  },
52
52
  "optionalDependencies": {
53
- "@twinsearth/dsh-fang-queue-journal": "0.1.4",
53
+ "@twinsearth/dsh-fang-queue-journal": "^0.1.5",
54
54
  "@twinsearth/dsh-fang-web-entry": "0.1.1"
55
55
  },
56
56
  "devDependencies": {
@@ -129,7 +129,7 @@ export const AUDIT = {
129
129
  RUNTIME_ERROR: 'runtime-error',
130
130
  }
131
131
 
132
- export const FANG_VERSION = '3.1.19'
132
+ export const FANG_VERSION = '3.1.21'
133
133
 
134
134
  /**
135
135
  * @typedef {object} ForkInfo
@@ -7,6 +7,10 @@ import path from 'node:path'
7
7
  const MAX_DRAFT = 100_000
8
8
  const MAX_QUEUE = 100
9
9
  const MAX_ITEM = 4_000
10
+ // v3.1.21:队列「必丢」根因之一是所有会话挤在同一个 key(后者覆盖前者)。
11
+ // 新增 append-only 历史文件:任何一次含队列的保存都会追加一条快照,
12
+ // 即使主 journal 被覆盖,历史里仍能找回来。
13
+ const MAX_HISTORY = 500
10
14
 
11
15
  function cleanText(value, limit) {
12
16
  return String(value ?? '').replace(/\0/g, '').slice(0, limit)
@@ -15,6 +19,7 @@ function cleanText(value, limit) {
15
19
  export class ComposerJournal {
16
20
  constructor(dataDir) {
17
21
  this.file = path.join(dataDir, 'composer-journal.json')
22
+ this.historyFile = path.join(dataDir, 'composer-journal-history.jsonl')
18
23
  }
19
24
 
20
25
  load() {
@@ -58,6 +63,7 @@ export class ComposerJournal {
58
63
  draft: cleanText(input.draft, MAX_DRAFT),
59
64
  queue,
60
65
  path: cleanText(input.path, 500),
66
+ sessionKey: cleanText(input.sessionKey, 200),
61
67
  updatedAt: new Date().toISOString(),
62
68
  }
63
69
  const all = this.load()
@@ -69,9 +75,48 @@ export class ComposerJournal {
69
75
  for (const stale of keys.slice(0, keys.length - 100)) delete all[stale]
70
76
  }
71
77
  this.saveFile(all)
78
+ this.appendHistory({ ...entry, sessionKey: cleanText(input.sessionKey, 200) || entry.key })
72
79
  return entry
73
80
  }
74
81
 
82
+ /** 追加一条历史快照(只在有队列内容时写,避免草稿噪音)。 */
83
+ appendHistory(entry) {
84
+ try {
85
+ const queue = Array.isArray(entry?.queue) ? entry.queue : []
86
+ if (queue.length === 0) return
87
+ fs.mkdirSync(path.dirname(this.historyFile), { recursive: true })
88
+ fs.appendFileSync(this.historyFile, JSON.stringify({
89
+ key: entry.key,
90
+ queue,
91
+ draft: entry.draft || "",
92
+ path: entry.path || "",
93
+ sessionKey: entry.sessionKey || "",
94
+ updatedAt: entry.updatedAt,
95
+ }) + "\n", { encoding: "utf8", mode: 0o600 })
96
+ // 裁剪:超过上限时重写最后 MAX_HISTORY 行
97
+ const raw = fs.readFileSync(this.historyFile, "utf8").trim().split("\n").filter(Boolean)
98
+ if (raw.length > MAX_HISTORY) {
99
+ fs.writeFileSync(this.historyFile, raw.slice(-MAX_HISTORY).join("\n") + "\n", { encoding: "utf8", mode: 0o600 })
100
+ }
101
+ } catch { /* 历史写入失败不影响主 journal */ }
102
+ }
103
+
104
+ /** 读取历史快照(newest first),可按 sessionKey 过滤。 */
105
+ history({ limit = 50, sessionKey = "" } = {}) {
106
+ try {
107
+ const raw = fs.readFileSync(this.historyFile, "utf8").trim().split("\n").filter(Boolean)
108
+ const items = []
109
+ for (const line of raw) {
110
+ try {
111
+ const entry = JSON.parse(line)
112
+ if (sessionKey && String(entry?.sessionKey || "") !== String(sessionKey)) continue
113
+ items.push(entry)
114
+ } catch { /* 跳过坏行 */ }
115
+ }
116
+ return items.slice(-Math.max(1, Number(limit) || 50)).reverse()
117
+ } catch { return [] }
118
+ }
119
+
75
120
  remove(key) {
76
121
  const all = this.load()
77
122
  const id = String(key)
@@ -3581,13 +3581,23 @@ export function apply(ctx, config) {
3581
3581
  const key = String(body?.key ?? '')
3582
3582
  if (!key) return json(res, 400, { ok: false, error: 'journal-key-required' })
3583
3583
  try {
3584
- return json(res, 200, { ok: true, entry: composerJournal.save(key, body) })
3584
+ return json(res, 200, { ok: true, entry: composerJournal.save(key, { ...body, sessionKey: body?.sessionKey || body?.sessionId || '' }) })
3585
3585
  } catch (error) {
3586
3586
  return json(res, 400, { ok: false, error: String(error?.message ?? error) })
3587
3587
  }
3588
3588
  },
3589
3589
  })
3590
3590
 
3591
+ // v3.1.21:append-only 历史快照(主 journal 被覆盖时的兜底恢复源)。
3592
+ routeMethods(`${prefix}/api/composer/journal/history`, {
3593
+ GET: (req, res) => {
3594
+ const query = new URL(String(req.url ?? '/'), 'http://x').searchParams
3595
+ const limit = Math.max(1, Math.min(200, Number(query.get('limit') || 20)))
3596
+ const sessionKey = String(query.get('sessionKey') || '')
3597
+ return json(res, 200, { ok: true, items: composerJournal.history({ limit, sessionKey }) })
3598
+ },
3599
+ })
3600
+
3591
3601
  // Restore saved queue rows into the official Session inbox WITHOUT waking the
3592
3602
  // agent. The queue journal is a recovery surface; it must not send messages.
3593
3603
  route('POST', `${prefix}/api/composer/queue`, async (req, res) => {