@twinsearth/dsh-fang 3.1.13 → 3.1.14
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 +18 -4
- package/package.json +1 -1
- package/src/kernel/types.mjs +2 -1
- package/src/plugins/adapter.mjs +33 -5
package/client.js
CHANGED
|
@@ -450,14 +450,22 @@ window.__ModuleLoader__.load({
|
|
|
450
450
|
const role = String(status.body.role ?? 'mother')
|
|
451
451
|
if (role === 'mother') return 'mother'
|
|
452
452
|
}
|
|
453
|
-
} catch { /* fall through to
|
|
454
|
-
// 元主 /
|
|
453
|
+
} catch { /* fall through to identity route */ }
|
|
454
|
+
// 元主 / 分身:fork 角色的 adapter 带 Bearer 鉴权,浏览器拿不到 token,
|
|
455
|
+
// 因此用公开只读的 /fang/adapter/identity(v3.1.14 起)。
|
|
456
|
+
try {
|
|
457
|
+
const identity = await api('/fang/adapter/identity')
|
|
458
|
+
if (identity.status === 200 && identity.body) {
|
|
459
|
+
const kind = String(identity.body.kind ?? '')
|
|
460
|
+
if (kind === 'mother' || kind === 'essence' || kind === 'fork') return kind
|
|
461
|
+
}
|
|
462
|
+
} catch { /* fall through to legacy hello */ }
|
|
463
|
+
// 兼容旧宿主(adapter 无 identity 路由):尝试 hello(可能 401),旧运行态按 rt- 前缀兜底。
|
|
455
464
|
try {
|
|
456
465
|
const hello = await api('/fang/adapter/hello')
|
|
457
466
|
if (hello.status === 200 && hello.body) {
|
|
458
467
|
const kind = String(hello.body.kind ?? '')
|
|
459
468
|
if (kind === 'mother' || kind === 'essence' || kind === 'fork') return kind
|
|
460
|
-
// 旧宿主没有 kind:元宝运行态的 forkId 是 rt-<essenceId>,任务是 task_/标题 id。
|
|
461
469
|
const taskId = String(hello.body.taskId ?? '')
|
|
462
470
|
return /^rt-/.test(taskId) ? 'essence' : 'fork'
|
|
463
471
|
}
|
|
@@ -488,6 +496,9 @@ window.__ModuleLoader__.load({
|
|
|
488
496
|
if (el.textContent !== label) el.textContent = label
|
|
489
497
|
if (el.hidden !== hidden) el.hidden = hidden
|
|
490
498
|
if (el.dataset.fangWebRole !== role) el.dataset.fangWebRole = role
|
|
499
|
+
for (const kind of ['mother', 'essence', 'fork']) {
|
|
500
|
+
el.classList.toggle('fang-web-role--' + kind, role === kind)
|
|
501
|
+
}
|
|
491
502
|
if (el.title !== title) el.title = title
|
|
492
503
|
if (el.getAttribute('aria-label') !== title) el.setAttribute('aria-label', title)
|
|
493
504
|
}
|
|
@@ -1041,10 +1052,13 @@ window.__ModuleLoader__.load({
|
|
|
1041
1052
|
.live{position:absolute!important;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
|
|
1042
1053
|
/* Web 端角色徽标:母体 / 元主 / 分身 —— 挂在侧栏品牌词右侧,仅用于识别当前实例身份。 */
|
|
1043
1054
|
.fang-web-role{display:inline-flex;align-items:center;height:18px;margin-left:7px;padding:0 6px;border-radius:6px;
|
|
1044
|
-
border:1px solid
|
|
1055
|
+
border:1px solid transparent;background:transparent;color:#C8102E;
|
|
1045
1056
|
font-size:11.5px;font-weight:700;letter-spacing:.02em;line-height:1;white-space:nowrap;
|
|
1046
1057
|
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;vertical-align:middle;
|
|
1047
1058
|
-webkit-app-region:no-drag;user-select:none}
|
|
1059
|
+
.fang-web-role--mother{border-color:rgba(200,16,46,.32);background:rgba(200,16,46,.07);color:#C8102E}
|
|
1060
|
+
.fang-web-role--essence{border-color:rgba(10,107,224,.32);background:rgba(10,107,224,.08);color:#0A6BE0}
|
|
1061
|
+
.fang-web-role--fork{border-color:rgba(23,128,61,.32);background:rgba(23,128,61,.08);color:#17803D}
|
|
1048
1062
|
.fang-web-role[hidden]{display:none}
|
|
1049
1063
|
.fang-web-role--unknown{visibility:hidden}
|
|
1050
1064
|
/* 决策中继:每个会话右侧的待选悬浮按钮 + 从右向左滑出的决策栏(v3.1.13)。 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twinsearth/dsh-fang",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.14",
|
|
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
|
@@ -128,7 +128,7 @@ export const AUDIT = {
|
|
|
128
128
|
RUNTIME_ERROR: 'runtime-error',
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
export const FANG_VERSION = '3.1.
|
|
131
|
+
export const FANG_VERSION = '3.1.14'
|
|
132
132
|
|
|
133
133
|
/**
|
|
134
134
|
* @typedef {object} ForkInfo
|
|
@@ -191,6 +191,7 @@ export const ADAPTER_OP = {
|
|
|
191
191
|
/** Adapter HTTP route suffixes (fork side). */
|
|
192
192
|
export const ADAPTER_ROUTE = {
|
|
193
193
|
HELLO: '/adapter/hello',
|
|
194
|
+
IDENTITY: '/adapter/identity',
|
|
194
195
|
STATUS: '/adapter/status',
|
|
195
196
|
APPROVALS: '/adapter/approvals',
|
|
196
197
|
AUDIT: '/adapter/audit',
|
package/src/plugins/adapter.mjs
CHANGED
|
@@ -235,6 +235,18 @@ function readPluginTree(dir) {
|
|
|
235
235
|
return { ok: true, files, count: Object.keys(files).length, bytes }
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
/**
|
|
239
|
+
* 角色 → Web 端身份 kind(纯函数,便于测试)。
|
|
240
|
+
* 母体 = mother;元宝运行态 = essence(DSH_FANG_ESSENCE 或 rt- forkId);
|
|
241
|
+
* 其余 fork 实例 = 任务分身。
|
|
242
|
+
* @param {{role?:string, taskId?:string, essence?:boolean}} [input]
|
|
243
|
+
* @returns {'mother'|'essence'|'fork'}
|
|
244
|
+
*/
|
|
245
|
+
export function identityKind({ role = 'fork', taskId = '', essence = false } = {}) {
|
|
246
|
+
if (role === 'mother') return 'mother'
|
|
247
|
+
return essence === true || String(taskId ?? '').startsWith('rt-') ? 'essence' : 'fork'
|
|
248
|
+
}
|
|
249
|
+
|
|
238
250
|
export function apply(ctx, config) {
|
|
239
251
|
const gate = roleGate('adapter', { logger: ctx.logger })
|
|
240
252
|
if (!gate.active) return
|
|
@@ -654,12 +666,9 @@ export function apply(ctx, config) {
|
|
|
654
666
|
const hello = () => ({
|
|
655
667
|
ok: true,
|
|
656
668
|
role,
|
|
657
|
-
taskId,
|
|
658
|
-
// Web 端身份徽标用:母体 / 元主(元宝运行态)/ 分身(任务)。
|
|
669
|
+
taskId, // Web 端身份徽标用:母体 / 元主(元宝运行态)/ 分身(任务)。
|
|
659
670
|
// 元宝运行态由 orchestrator 注入 DSH_FANG_ESSENCE=1;旧运行态按 rt- 前缀兜底。
|
|
660
|
-
kind: role === '
|
|
661
|
-
? 'mother'
|
|
662
|
-
: ((typeof process !== 'undefined' && process.env?.DSH_FANG_ESSENCE === '1') || String(taskId ?? '').startsWith('rt-') ? 'essence' : 'fork'),
|
|
671
|
+
kind: identityKind({ role, taskId, essence: typeof process !== 'undefined' && process.env?.DSH_FANG_ESSENCE === '1' }),
|
|
663
672
|
version: FANG_VERSION,
|
|
664
673
|
protocol: ADAPTER_PROTOCOL_VERSION,
|
|
665
674
|
sessionId,
|
|
@@ -684,6 +693,16 @@ export function apply(ctx, config) {
|
|
|
684
693
|
}
|
|
685
694
|
}
|
|
686
695
|
|
|
696
|
+
// v3.1.14:Web 端拿不到 adapter Bearer token,身份探测走公开只读路由;
|
|
697
|
+
// 只暴露 role/kind/version,不含 taskId/sessionId/token。
|
|
698
|
+
const identity = () => ({
|
|
699
|
+
ok: true,
|
|
700
|
+
role,
|
|
701
|
+
kind: identityKind({ role, taskId, essence: typeof process !== 'undefined' && process.env?.DSH_FANG_ESSENCE === '1' }),
|
|
702
|
+
version: FANG_VERSION,
|
|
703
|
+
protocol: ADAPTER_PROTOCOL_VERSION,
|
|
704
|
+
})
|
|
705
|
+
|
|
687
706
|
const approvals = () => {
|
|
688
707
|
const items = approvalItemsWithOrphans()
|
|
689
708
|
if (items === null) return { ok: false, code: 'service-unavailable', error: 'service-unavailable', items: [] }
|
|
@@ -1207,6 +1226,15 @@ export function apply(ctx, config) {
|
|
|
1207
1226
|
}
|
|
1208
1227
|
|
|
1209
1228
|
const registerRoutes = (webServer) => {
|
|
1229
|
+
// v3.1.14:浏览器无法持有 adapter Bearer token;身份探测必须是公开只读路由。
|
|
1230
|
+
// 服务端仍只监听 loopback,且返回值不含 taskId/token(见 identity())。
|
|
1231
|
+
webServer.register({
|
|
1232
|
+
kind: 'exact',
|
|
1233
|
+
path: `${prefix}${ADAPTER_ROUTE.IDENTITY}`,
|
|
1234
|
+
method: 'GET',
|
|
1235
|
+
handler: (req, res) => json(res, 200, identity()),
|
|
1236
|
+
})
|
|
1237
|
+
try { service.routes.push(`${prefix}${ADAPTER_ROUTE.IDENTITY}`) } catch { /* fake ws */ }
|
|
1210
1238
|
const route = (method, routePath, handler) => {
|
|
1211
1239
|
webServer.register({
|
|
1212
1240
|
kind: 'exact',
|