@twinsearth/dsh-fang 3.1.16 → 3.1.17
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 +88 -18
- package/package.json +1 -1
- package/src/kernel/types.mjs +2 -1
- package/src/plugins/adapter.mjs +26 -0
- package/src/plugins/session-catalog.mjs +12 -1
package/client.js
CHANGED
|
@@ -479,6 +479,19 @@ window.__ModuleLoader__.load({
|
|
|
479
479
|
let timer = 0
|
|
480
480
|
let observer = null
|
|
481
481
|
let observed = null
|
|
482
|
+
let fallbackEl = null
|
|
483
|
+
let reported = false
|
|
484
|
+
|
|
485
|
+
// v3.1.17:客户端自报「已加载」,仅时间戳(供 /fang/adapter/identity 的 clientLoaded)。
|
|
486
|
+
const reportLoaded = () => {
|
|
487
|
+
if (reported) return
|
|
488
|
+
reported = true
|
|
489
|
+
try {
|
|
490
|
+
void fetch('/fang/adapter/client-report', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' })
|
|
491
|
+
.catch(() => { /* 老宿主没有该路由:忽略 */ })
|
|
492
|
+
} catch { /* ignore */ }
|
|
493
|
+
}
|
|
494
|
+
|
|
482
495
|
const findBrandName = () => {
|
|
483
496
|
const candidates = document.querySelectorAll('[class*="brandName"]')
|
|
484
497
|
for (const node of candidates) {
|
|
@@ -502,50 +515,107 @@ window.__ModuleLoader__.load({
|
|
|
502
515
|
if (el.title !== title) el.title = title
|
|
503
516
|
if (el.getAttribute('aria-label') !== title) el.setAttribute('aria-label', title)
|
|
504
517
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (el && el.isConnected && el.parentElement) { paint(el); return true }
|
|
509
|
-
const brandName = findBrandName()
|
|
510
|
-
if (!brandName || !brandName.parentElement) return false
|
|
511
|
-
el = document.createElement('span')
|
|
518
|
+
|
|
519
|
+
const createBadge = () => {
|
|
520
|
+
const el = document.createElement('span')
|
|
512
521
|
el.id = WEB_ROLE_BADGE_ID
|
|
513
522
|
el.className = 'fang-web-role'
|
|
514
523
|
el.setAttribute('role', 'status')
|
|
515
524
|
el.setAttribute('aria-live', 'polite')
|
|
525
|
+
return el
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/** 首选:宿主侧栏品牌词标右侧。 */
|
|
529
|
+
const placeInBrand = () => {
|
|
530
|
+
if (!document || !document.body) return false
|
|
531
|
+
const existing = document.getElementById(WEB_ROLE_BADGE_ID)
|
|
532
|
+
if (existing && existing.isConnected && existing.parentElement && existing !== fallbackEl) { paint(existing); return true }
|
|
533
|
+
const brandName = findBrandName()
|
|
534
|
+
if (!brandName || !brandName.parentElement) return false
|
|
535
|
+
if (fallbackEl) { try { fallbackEl.remove() } catch { /* ignore */ } fallbackEl = null }
|
|
536
|
+
const el = createBadge()
|
|
516
537
|
brandName.parentElement.insertBefore(el, brandName.nextSibling)
|
|
517
538
|
paint(el)
|
|
518
|
-
|
|
519
|
-
if (observer) { try { observer.disconnect() } catch { /* ignore */ } }
|
|
520
|
-
observer = new MutationObserver(() => { try { place() } catch { /* ignore */ } })
|
|
521
|
-
try { observer.observe(brandName.parentElement, { childList: true, subtree: true }) } catch { /* ignore */ }
|
|
522
|
-
observed = brandName.parentElement
|
|
539
|
+
observe(brandName.parentElement)
|
|
523
540
|
return true
|
|
524
541
|
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* 兜底(v3.1.17):品牌槽不存在或被宿主整段移除时,挂到 body 右上角固定角标。
|
|
545
|
+
* 只在 3 次重试仍失败后启用,避免与正常挂载抢位置。
|
|
546
|
+
*/
|
|
547
|
+
const placeFallback = () => {
|
|
548
|
+
if (!document || !document.body) return false
|
|
549
|
+
if (fallbackEl && fallbackEl.isConnected) { paint(fallbackEl); return true }
|
|
550
|
+
const el = createBadge()
|
|
551
|
+
el.classList.add('fang-web-role--fallback')
|
|
552
|
+
el.style.position = 'fixed'
|
|
553
|
+
el.style.top = '8px'
|
|
554
|
+
el.style.right = '12px'
|
|
555
|
+
el.style.zIndex = '2147483000'
|
|
556
|
+
el.style.padding = '2px 8px'
|
|
557
|
+
el.style.borderRadius = '10px'
|
|
558
|
+
el.style.fontSize = '11px'
|
|
559
|
+
el.style.fontWeight = '600'
|
|
560
|
+
el.style.pointerEvents = 'none'
|
|
561
|
+
el.style.background = 'rgba(0,0,0,.55)'
|
|
562
|
+
document.body.append(el)
|
|
563
|
+
fallbackEl = el
|
|
564
|
+
paint(el)
|
|
565
|
+
observe(document.body)
|
|
566
|
+
return true
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const observe = (node) => {
|
|
570
|
+
if (!node) return
|
|
571
|
+
if (observed === node && observer) return
|
|
572
|
+
if (observer) { try { observer.disconnect() } catch { /* ignore */ } }
|
|
573
|
+
observer = new MutationObserver(() => {
|
|
574
|
+
try { if (!placeInBrand()) placeFallback() } catch { /* ignore */ }
|
|
575
|
+
})
|
|
576
|
+
try { observer.observe(node, { childList: true, subtree: true }) } catch { /* ignore */ }
|
|
577
|
+
observed = node
|
|
578
|
+
}
|
|
579
|
+
|
|
525
580
|
const install = () => {
|
|
526
|
-
|
|
581
|
+
const ok = placeInBrand()
|
|
582
|
+
if (ok) { if (timer) { clearInterval(timer); timer = 0 } return true }
|
|
527
583
|
return false
|
|
528
584
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
585
|
+
|
|
586
|
+
reportLoaded()
|
|
587
|
+
|
|
588
|
+
// 3 次重试(250ms 间隔)后才兜底;宿主侧栏渲染通常在第一帧后就绪。
|
|
589
|
+
if (!install()) {
|
|
532
590
|
let tries = 0
|
|
533
591
|
timer = setInterval(() => {
|
|
534
592
|
tries += 1
|
|
535
|
-
|
|
593
|
+
const done = install()
|
|
594
|
+
if (!done && tries >= 3) {
|
|
595
|
+
clearInterval(timer)
|
|
596
|
+
timer = 0
|
|
597
|
+
placeFallback()
|
|
598
|
+
} else if (done) {
|
|
599
|
+
clearInterval(timer)
|
|
600
|
+
timer = 0
|
|
601
|
+
}
|
|
536
602
|
}, 250)
|
|
537
603
|
}
|
|
604
|
+
|
|
538
605
|
void (async () => {
|
|
539
606
|
const detected = await detectWebRole()
|
|
540
607
|
if (!detected) return
|
|
541
608
|
role = detected
|
|
542
|
-
install()
|
|
609
|
+
if (!install()) placeFallback()
|
|
543
610
|
})()
|
|
611
|
+
|
|
544
612
|
return () => {
|
|
545
613
|
if (timer) { clearInterval(timer); timer = 0 }
|
|
546
614
|
if (observer) { try { observer.disconnect() } catch { /* ignore */ } observer = null }
|
|
547
615
|
void observed
|
|
548
616
|
try { document.getElementById(WEB_ROLE_BADGE_ID)?.remove() } catch { /* ignore */ }
|
|
617
|
+
try { fallbackEl?.remove() } catch { /* ignore */ }
|
|
618
|
+
fallbackEl = null
|
|
549
619
|
}
|
|
550
620
|
}
|
|
551
621
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/dsh-fang",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.17",
|
|
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.",
|
package/src/kernel/types.mjs
CHANGED
|
@@ -129,7 +129,7 @@ export const AUDIT = {
|
|
|
129
129
|
RUNTIME_ERROR: 'runtime-error',
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
export const FANG_VERSION = '3.1.
|
|
132
|
+
export const FANG_VERSION = '3.1.17'
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
135
|
* @typedef {object} ForkInfo
|
|
@@ -193,6 +193,7 @@ export const ADAPTER_OP = {
|
|
|
193
193
|
export const ADAPTER_ROUTE = {
|
|
194
194
|
HELLO: '/adapter/hello',
|
|
195
195
|
IDENTITY: '/adapter/identity',
|
|
196
|
+
CLIENT_REPORT: '/adapter/client-report',
|
|
196
197
|
STATUS: '/adapter/status',
|
|
197
198
|
APPROVALS: '/adapter/approvals',
|
|
198
199
|
AUDIT: '/adapter/audit',
|
package/src/plugins/adapter.mjs
CHANGED
|
@@ -695,13 +695,29 @@ export function apply(ctx, config) {
|
|
|
695
695
|
|
|
696
696
|
// v3.1.14:Web 端拿不到 adapter Bearer token,身份探测走公开只读路由;
|
|
697
697
|
// 只暴露 role/kind/version,不含 taskId/sessionId/token。
|
|
698
|
+
let clientReported = false
|
|
699
|
+
let clientReportedAt = 0
|
|
700
|
+
|
|
698
701
|
const identity = () => ({
|
|
699
702
|
ok: true,
|
|
700
703
|
role,
|
|
701
704
|
kind: identityKind({ role, taskId, essence: typeof process !== 'undefined' && process.env?.DSH_FANG_ESSENCE === '1' }),
|
|
702
705
|
version: FANG_VERSION,
|
|
703
706
|
protocol: ADAPTER_PROTOCOL_VERSION,
|
|
707
|
+
// v3.1.17:一眼判断「服务端有身份、客户端没加载」——不含 taskId/token 等敏感字段。
|
|
708
|
+
surface: 'web-adapter',
|
|
709
|
+
clientLoaded: clientReported,
|
|
710
|
+
clientReportedAt: clientReportedAt || null,
|
|
704
711
|
})
|
|
712
|
+
/**
|
|
713
|
+
* 客户端自报:Web 端加载了 fang client 后会 POST 到这里;
|
|
714
|
+
* 只记录时间,不记录任何身份/token(用于运维排查徽标不显示)。
|
|
715
|
+
*/
|
|
716
|
+
const reportClient = () => {
|
|
717
|
+
clientReported = true
|
|
718
|
+
clientReportedAt = Date.now()
|
|
719
|
+
return { ok: true, clientReported: true, at: clientReportedAt }
|
|
720
|
+
}
|
|
705
721
|
|
|
706
722
|
const approvals = () => {
|
|
707
723
|
const items = approvalItemsWithOrphans()
|
|
@@ -1108,6 +1124,8 @@ export function apply(ctx, config) {
|
|
|
1108
1124
|
routes: [],
|
|
1109
1125
|
|
|
1110
1126
|
hello,
|
|
1127
|
+
identity,
|
|
1128
|
+
reportClient,
|
|
1111
1129
|
status,
|
|
1112
1130
|
approvals,
|
|
1113
1131
|
audit,
|
|
@@ -1235,6 +1253,14 @@ export function apply(ctx, config) {
|
|
|
1235
1253
|
handler: (req, res) => json(res, 200, identity()),
|
|
1236
1254
|
})
|
|
1237
1255
|
try { service.routes.push(`${prefix}${ADAPTER_ROUTE.IDENTITY}`) } catch { /* fake ws */ }
|
|
1256
|
+
// v3.1.17:客户端自报加载状态(只记录时间戳,不含身份/token)。
|
|
1257
|
+
webServer.register({
|
|
1258
|
+
kind: 'exact',
|
|
1259
|
+
path: `${prefix}${ADAPTER_ROUTE.CLIENT_REPORT}`,
|
|
1260
|
+
method: 'POST',
|
|
1261
|
+
handler: (req, res) => json(res, 200, reportClient()),
|
|
1262
|
+
})
|
|
1263
|
+
try { service.routes.push(`${prefix}${ADAPTER_ROUTE.CLIENT_REPORT}`) } catch { /* fake ws */ }
|
|
1238
1264
|
const route = (method, routePath, handler) => {
|
|
1239
1265
|
webServer.register({
|
|
1240
1266
|
kind: 'exact',
|
|
@@ -365,6 +365,10 @@ export function apply(ctx, config) {
|
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
const workspaceFilter = typeof opts.workspaceId === 'string' && opts.workspaceId.trim() ? opts.workspaceId.trim() : null
|
|
368
|
+
// v3.1.17:房主 Router 的 Ticket→会话映射键(sessionKey/ticketId)原样带回,
|
|
369
|
+
// 便于 3_Sessions 把「工单」与「母体会话目录」对齐;不参与过滤,只做标注。
|
|
370
|
+
const sessionKey = typeof opts.sessionKey === 'string' && opts.sessionKey.trim() ? opts.sessionKey.trim() : null
|
|
371
|
+
const ticketId = typeof opts.ticketId === 'string' && opts.ticketId.trim() ? opts.ticketId.trim() : null
|
|
368
372
|
|
|
369
373
|
let items = scanned.sessions
|
|
370
374
|
if (!includeArchivedEffective) items = items.filter((session) => !session.archived)
|
|
@@ -385,7 +389,14 @@ export function apply(ctx, config) {
|
|
|
385
389
|
})
|
|
386
390
|
return {
|
|
387
391
|
ok: true,
|
|
388
|
-
sessions: page.map((session) => ({
|
|
392
|
+
sessions: page.map((session) => ({
|
|
393
|
+
...sessionView(session),
|
|
394
|
+
...titleFields(titleOf(session), session.workspaceTitle),
|
|
395
|
+
...(sessionKey ? { sessionKey } : {}),
|
|
396
|
+
...(ticketId ? { ticketId } : {}),
|
|
397
|
+
})),
|
|
398
|
+
...(sessionKey ? { sessionKey } : {}),
|
|
399
|
+
...(ticketId ? { ticketId } : {}),
|
|
389
400
|
total,
|
|
390
401
|
returned: page.length,
|
|
391
402
|
limit: requestedLimit,
|