femo-plugin 1.0.0
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/LICENSE +201 -0
- package/README.md +627 -0
- package/femo2host/__init__.py +4 -0
- package/femo2host/femoToolcall/chronica.py +156 -0
- package/femo2host/femoToolcall/femo-chat.mjs +69 -0
- package/femo2host/femoToolcall/femo_debugger.py +1515 -0
- package/femo2host/femo_api.py +437 -0
- package/femo2host/femo_gen_api.jsx +77 -0
- package/femoBridges/ContextExample.py +555 -0
- package/femoBridges/MemoryExample.py +163 -0
- package/femoBridges/__init__.py +1 -0
- package/femoBridges/getDir/get_dir.py +56 -0
- package/femoBridges/getDir//344/275/240/345/217/257/344/273/245/350/256/276/345/256/232/344/273/273/346/204/217/346/226/207/344/273/266/345/244/271/344/270/272/347/224/250/346/210/267/346/225/260/346/215/256/346/226/207/344/273/266/345/244/271.txt +10 -0
- package/femoBridges/llmBridge.py +247 -0
- package/femoBridges/llmProviders.py +308 -0
- package/femoCompiler/FEMO_CLIrenderer.py +198 -0
- package/femoCompiler/FEMO_config.py +35 -0
- package/femoCompiler/FEMO_errors.py +278 -0
- package/femoCompiler/FEMO_interpreter.py +163 -0
- package/femoCompiler/FEMO_normalizer.py +396 -0
- package/femoCompiler/FEMO_parser.py +2468 -0
- package/femoCompiler/FEMO_runtime.py +3630 -0
- package/femoCompiler/FEMO_scope_resolver.py +209 -0
- package/femoCompiler/__init__.py +1 -0
- package/femoCompiler/actor_resolver.py +86 -0
- package/femoCompiler/block_collector.py +441 -0
- package/femoCompiler/db_utils.py +485 -0
- package/femoCompiler/femoAsync.py +401 -0
- package/femoCompiler/host_manifest.py +68 -0
- package/femoCompiler/job_manager.py +767 -0
- package/femoCompiler/protocol.py +126 -0
- package/femoCompiler/save_dialog.py +402 -0
- package/femoCompiler/task_world.py +544 -0
- package/femoCompiler/vars/__init__.py +19 -0
- package/femoCompiler/vars/checkpoint.py +113 -0
- package/femoCompiler/vars/env.py +686 -0
- package/femoCompiler/vars/evaluator.py +567 -0
- package/femoCompiler/vars/join.py +303 -0
- package/femoCompiler/vars/merge.py +157 -0
- package/femoCompiler/vars/model.py +245 -0
- package/femoExamples/AI/345/211/252/350/247/206/351/242/221/AI/345/211/252/350/247/206/351/242/221.femo +192 -0
- package/femoExamples/AI/350/201/212/345/244/251/345/256/244/group-chat.femo +42 -0
- package/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +10 -0
- package/femoExamples/LuxFiat/luxfiat.femo +38 -0
- package/femoExamples/LuxFiat/wait.py +29 -0
- package/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +222 -0
- package/femoExamples/discussion.femo +70 -0
- package/femoExamples/goal-mode.femo +23 -0
- package/femoExamples//345/270/270/347/224/250/345/267/245/345/205/267python/wait.py +29 -0
- package/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils.py +205 -0
- package/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils2.py +324 -0
- package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200-/350/255/246/351/225/277/347/211/210.femo +544 -0
- package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +331 -0
- package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225/undercover_utils.py +683 -0
- package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225-/350/217/234/345/270/202/345/234/272/345/261/200.femo +348 -0
- package/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225//350/260/201/346/230/257/345/215/247/345/272/225.femo +392 -0
- package/femoGen/document_ch.html +2352 -0
- package/femoGen/document_en.html +2279 -0
- package/femoGen/index.html +19 -0
- package/femoGen/intro_ch.html +942 -0
- package/femoGen/intro_en.html +932 -0
- package/femoGen/package-lock.json +1698 -0
- package/femoGen/package.json +19 -0
- package/femoGen/public/character_need.ttf +0 -0
- package/femoGen/public/favicon.ico +0 -0
- package/femoGen/public/femo-logo-slogan.svg +83 -0
- package/femoGen/public/femo-logo.svg +55 -0
- package/femoGen/public/logo-fullsize.ico +0 -0
- package/femoGen/src/FemoWorAuto.jsx +5444 -0
- package/femoGen/src/actionModal.jsx +358 -0
- package/femoGen/src/bubbleOverlay.jsx +701 -0
- package/femoGen/src/canvasNodes.jsx +608 -0
- package/femoGen/src/common.jsx +715 -0
- package/femoGen/src/debugPanel.jsx +530 -0
- package/femoGen/src/faIcons.jsx +84 -0
- package/femoGen/src/femoDiagnostics.js +122 -0
- package/femoGen/src/femoFileList.jsx +357 -0
- package/femoGen/src/femoGenerator.jsx +1198 -0
- package/femoGen/src/femoLog.js +107 -0
- package/femoGen/src/femoParser.jsx +2255 -0
- package/femoGen/src/femoPreview.jsx +297 -0
- package/femoGen/src/graphBuilder.jsx +358 -0
- package/femoGen/src/libPanel.jsx +519 -0
- package/femoGen/src/main.jsx +22 -0
- package/femoGen/src/mobileView.jsx +2796 -0
- package/femoGen/src/projectPanel.jsx +529 -0
- package/femoGen/src/soulModal.jsx +162 -0
- package/femoGen/src/styles/font.css +10 -0
- package/femoGen/src/themes.js +465 -0
- package/femoGen/src/useCanvasInteraction.jsx +319 -0
- package/femoGen/vite.config.js +28 -0
- package/femoGen//347/222/207/345/255/230/346/247/221.txt +15 -0
- package/hostAdapter/dshAdapter/README.md +68 -0
- package/hostAdapter/dshAdapter/build.mjs +75 -0
- package/hostAdapter/dshAdapter/client/client-ui/chat-node.tsx +339 -0
- package/hostAdapter/dshAdapter/client/client-ui/composer.tsx +997 -0
- package/hostAdapter/dshAdapter/client/client-ui/editor-page.tsx +726 -0
- package/hostAdapter/dshAdapter/client/client-ui/editor-view.tsx +88 -0
- package/hostAdapter/dshAdapter/client/client-ui/femo-stream-live.tsx +264 -0
- package/hostAdapter/dshAdapter/client/client-ui/proj2/frame-router.ts +282 -0
- package/hostAdapter/dshAdapter/client/client-ui/proj2/index.ts +44 -0
- package/hostAdapter/dshAdapter/client/client-ui/proj2/ledger.ts +329 -0
- package/hostAdapter/dshAdapter/client/client-ui/proj2/turn-view.tsx +211 -0
- package/hostAdapter/dshAdapter/client/client-ui/proj2/window-id.ts +28 -0
- package/hostAdapter/dshAdapter/client/client-ui/stream-store.ts +550 -0
- package/hostAdapter/dshAdapter/client/client-ui/styles.ts +144 -0
- package/hostAdapter/dshAdapter/client/client-ui/view-button.tsx +572 -0
- package/hostAdapter/dshAdapter/client/client-ui/view-state.ts +61 -0
- package/hostAdapter/dshAdapter/client/client.tsx +518 -0
- package/hostAdapter/dshAdapter/client/fa-icons.tsx +112 -0
- package/hostAdapter/dshAdapter/client/femo-reasoning-row.tsx +103 -0
- package/hostAdapter/dshAdapter/client/lineage-fork-native.jsx +624 -0
- package/hostAdapter/dshAdapter/client/lineage-fork.jsx +585 -0
- package/hostAdapter/dshAdapter/cordis.patch.yml +8 -0
- package/hostAdapter/dshAdapter/dshPatch/DSH-0.1.2-fork/344/277/256/346/224/271/351/234/200/346/261/202.md +184 -0
- package/hostAdapter/dshAdapter/dshPatch/MEOW_MODIFICATIONS.md +3105 -0
- package/hostAdapter/dshAdapter/dshPatch/patch-dsh-0.1.2-alpha.1.py +313 -0
- package/hostAdapter/dshAdapter/host/api-retry.ts +141 -0
- package/hostAdapter/dshAdapter/host/bridge.ts +224 -0
- package/hostAdapter/dshAdapter/host/config.ts +124 -0
- package/hostAdapter/dshAdapter/host/debug-log.ts +29 -0
- package/hostAdapter/dshAdapter/host/debug-run.ts +793 -0
- package/hostAdapter/dshAdapter/host/diag-feed.ts +56 -0
- package/hostAdapter/dshAdapter/host/engine-events.ts +891 -0
- package/hostAdapter/dshAdapter/host/engine-transcript.ts +122 -0
- package/hostAdapter/dshAdapter/host/femo-files.ts +210 -0
- package/hostAdapter/dshAdapter/host/god-mirror.ts +234 -0
- package/hostAdapter/dshAdapter/host/host-log.ts +101 -0
- package/hostAdapter/dshAdapter/host/http.ts +66 -0
- package/hostAdapter/dshAdapter/host/index.ts +633 -0
- package/hostAdapter/dshAdapter/host/list-cache.ts +183 -0
- package/hostAdapter/dshAdapter/host/main-actor.ts +853 -0
- package/hostAdapter/dshAdapter/host/main-delivery-queue.ts +115 -0
- package/hostAdapter/dshAdapter/host/native-state.ts +21 -0
- package/hostAdapter/dshAdapter/host/node-retry.ts +246 -0
- package/hostAdapter/dshAdapter/host/persona.ts +146 -0
- package/hostAdapter/dshAdapter/host/pre-step-gate.ts +95 -0
- package/hostAdapter/dshAdapter/host/proj-trace.ts +49 -0
- package/hostAdapter/dshAdapter/host/projection-input.ts +238 -0
- package/hostAdapter/dshAdapter/host/projection.ts +742 -0
- package/hostAdapter/dshAdapter/host/routes.ts +1196 -0
- package/hostAdapter/dshAdapter/host/run-control.ts +641 -0
- package/hostAdapter/dshAdapter/host/safe-steer.ts +33 -0
- package/hostAdapter/dshAdapter/host/section-gate.ts +108 -0
- package/hostAdapter/dshAdapter/host/session-events.ts +45 -0
- package/hostAdapter/dshAdapter/host/state-files.ts +301 -0
- package/hostAdapter/dshAdapter/host/stream-frames.ts +229 -0
- package/hostAdapter/dshAdapter/host/subagent-native.ts +997 -0
- package/hostAdapter/dshAdapter/host/subagent.ts +1205 -0
- package/hostAdapter/dshAdapter/host/tools.ts +486 -0
- package/hostAdapter/dshAdapter/host/windowing-native.ts +294 -0
- package/hostAdapter/dshAdapter/host.manifest.json +6 -0
- package/hostAdapter/dshAdapter/lib/client.js +19161 -0
- package/hostAdapter/dshAdapter/lib/client.js.map +7 -0
- package/hostAdapter/dshAdapter/lib/index.js +8173 -0
- package/hostAdapter/dshAdapter/lib/index.js.map +7 -0
- package/hostAdapter/dshAdapter/package-lock.json +500 -0
- package/hostAdapter/dshAdapter/package.json +55 -0
- package/hostAdapter/dshAdapter/pnpm-lock.yaml +596 -0
- package/hostAdapter/dshAdapter/pnpm-workspace.yaml +2 -0
- package/hostAdapter/dshAdapter/python/dev-bridge-test.py +43 -0
- package/hostAdapter/dshAdapter/python/femo_bridge.py +533 -0
- package/hostAdapter/dshAdapter/tsconfig.host.json +9 -0
- package/hostAdapter/dshAdapter/tsconfig.json +21 -0
- package/package.json +40 -0
- package//350/257/255/346/263/225/346/226/207/346/241/243.md +1136 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* windowing-native.ts — 原生 DSH(0.1.3+ stock 构建)投影窗适配层。
|
|
3
|
+
*
|
|
4
|
+
* 与原 projection.ts 投影窗并存:meow fork(有 registerSessionEventType)走原
|
|
5
|
+
* 路径,行为逐字节不变;原生构建走本层。原 projection.ts 一行未改——切换在
|
|
6
|
+
* 调用处(broadcastCompat/projectedCompat,内部按版本 if 分流)与 index.ts
|
|
7
|
+
* 的安装点完成。
|
|
8
|
+
*
|
|
9
|
+
* 原生版核心事实(2026-09-08 vanilla-0.1.3-alpha.2 实测,探针
|
|
10
|
+
* probe-ignorable.mjs 3/3):
|
|
11
|
+
* - 只有 agent-loop 创建事务开的写句柄才落盘(core/session src/index.ts:
|
|
12
|
+
* "a session published outside that lifecycle persists nothing")。投影窗
|
|
13
|
+
* 是裸 sessions.create ⇒【永不落盘】:自定义事件不会被持久层拒绝(无砖、
|
|
14
|
+
* 无 ignorable 需求),代价是窗内容重启即失。
|
|
15
|
+
* - 主会话走 ctx.agents.create(agent-loop 事务)⇒ 有 writer:原生持久层按
|
|
16
|
+
* KNOWN_SESSION_EVENT_TYPES 白名单拒载未知类型。官方 stock 没有本插件事件
|
|
17
|
+
* ⇒ 主会话不能写 femo-plugin/chat(写入后下次冷恢复即拒载,且 id 被
|
|
18
|
+
* SessionAlreadyExistsError 占死);【2026-09-09 深夜改版】部署可给白名单
|
|
19
|
+
* 打补丁(本实验室 3083 构建已打)——安装时运行时探测白名单,补丁在 =
|
|
20
|
+
* 主会话 sys/role 行为与旧版完全一致;不在 = 仅窗侧降级(信息不丢,
|
|
21
|
+
* 位置变)。
|
|
22
|
+
* 原生版写入侧没有打 ignorable 标记的 API(官方 2026-08-30 notes 明示
|
|
23
|
+
* production 面未提供,注册面方案已被否决),白名单补丁是唯一通道。
|
|
24
|
+
*
|
|
25
|
+
* 窗历史跨重启:镜像(femoRoot/proj-mirror/<windowId>.jsonl)挂在全局
|
|
26
|
+
* session/event 钩子上记每一行;重启后窗同 id 重建(session/created 钩子)时
|
|
27
|
+
* 整窗重放——渲染走原有 femo/chat 节点,视觉与旧投影窗一致。重放走
|
|
28
|
+
* projection.ts 导出的 appendEvent,去重索引天然防重;重放期间镜像暂记避免
|
|
29
|
+
* 自复制。
|
|
30
|
+
*/
|
|
31
|
+
import { createRequire } from 'node:module'
|
|
32
|
+
import { appendFile, mkdir, readFile } from 'node:fs/promises'
|
|
33
|
+
import { join } from 'node:path'
|
|
34
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
35
|
+
import type { Session, SessionEvent } from '@deepseek-ai/dsh-session'
|
|
36
|
+
import { appendChatBroadcast, appendChatProjected, appendEvent, type ProjectionRegistry } from './projection'
|
|
37
|
+
import { readSessionEventCount, readSessionEvents } from './session-events'
|
|
38
|
+
import { nativeState } from './native-state'
|
|
39
|
+
|
|
40
|
+
const WINDOW_ID_PREFIX = 'femo-proj-'
|
|
41
|
+
const DESCRIPTOR_TYPE = 'subagent/descriptor'
|
|
42
|
+
const FEMO_CHAT_TYPE = 'femo-plugin/chat'
|
|
43
|
+
/** 2026-09-12 femo 改名:存量会话日志里仍存在的本插件 legacy 事件类型
|
|
44
|
+
* (turn-scope 文件化改造前的旧事件;chat 存量已随改名全量迁移,主类型
|
|
45
|
+
* 之外只需放行 turn-scope)。与 FEMO_CHAT_TYPE 一并进白名单,旧日志才能
|
|
46
|
+
* 过持久化读取门的 KNOWN_SESSION_EVENT_TYPES 检查。 */
|
|
47
|
+
const LEGACY_FEMO_EVENT_TYPES: readonly string[] = ['femo-plugin/turn-scope']
|
|
48
|
+
/** dsh surface-eligible 事件全集(session.append 强制要求 surfaceOp 标记)。
|
|
49
|
+
* 与 subagent.ts 的 SURFACE_OP_EVENTS 不同:这里还含 user/message(god-mirror
|
|
50
|
+
* 会把主会话用户行镜像进上帝窗)。本地重声明避免模块环。 */
|
|
51
|
+
const SURFACE_ELIGIBLE_TYPES: ReadonlySet<string> = new Set(['user/message', 'assistant/message', 'tool/result'])
|
|
52
|
+
|
|
53
|
+
/** meow fork(0.1.x)暴露 registerSessionEventType;原生 0.1.3 stock 没有。 */
|
|
54
|
+
export function isNativeDshBuild(sessionNamespace: unknown): boolean {
|
|
55
|
+
return (sessionNamespace as { registerSessionEventType?: unknown } | undefined)
|
|
56
|
+
?.registerSessionEventType === undefined
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 原生模式开关与白名单探测结果:安装时写入 nativeState(共享单一事实源,
|
|
60
|
+
* projection.ts 等模块经 ./native-state 读取,避免循环依赖)。 */
|
|
61
|
+
export function isNativeMode(): boolean {
|
|
62
|
+
return nativeState.native
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 原生模式下主会话写 femo-plugin/chat 是否安全(白名单已含本插件事件)。 */
|
|
66
|
+
export function isMainSessionChatSafe(): boolean {
|
|
67
|
+
return nativeState.mainChatSafe
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ── 镜像存储(per-window JSONL,追加式)────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
/** 重放中的窗:session/event 镜像钩子对它们暂不记(防自复制)。 */
|
|
73
|
+
const replaying = new Set<string>()
|
|
74
|
+
/** per-file 写串行化:镜像行顺序即重放顺序。 */
|
|
75
|
+
const mirrorWrites = new Map<string, Promise<void>>()
|
|
76
|
+
|
|
77
|
+
function mirrorFile(mirrorDir: string, windowId: string): string {
|
|
78
|
+
const safe = windowId.replace(/[^\w.-]/g, '_')
|
|
79
|
+
return join(mirrorDir, `${safe}.jsonl`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function mirrorEnqueue(mirrorDir: string, windowId: string, event: SessionEvent): void {
|
|
83
|
+
const file = mirrorFile(mirrorDir, windowId)
|
|
84
|
+
// surfaceOp 不读 event.surfaceOp(运行时事件对象上不可靠,2026-09-09 实测
|
|
85
|
+
// 重放整批被拒)——按事件类型重算:surface-eligible 必带 append 标记。
|
|
86
|
+
const surfaceOp = SURFACE_ELIGIBLE_TYPES.has(event.type) ? { surfaceOp: 'append' } : undefined
|
|
87
|
+
const row = {
|
|
88
|
+
type: event.type,
|
|
89
|
+
data: event.data,
|
|
90
|
+
...(surfaceOp === undefined ? {} : { surfaceOp }),
|
|
91
|
+
}
|
|
92
|
+
const prev = mirrorWrites.get(file) ?? Promise.resolve()
|
|
93
|
+
const next = prev
|
|
94
|
+
.then(() => appendFile(file, `${JSON.stringify(row)}\n`, 'utf8'))
|
|
95
|
+
.catch((error: unknown) => {
|
|
96
|
+
console.log(`[femo-plugin][native] mirror write failed for ${windowId}: ${String(error)}`)
|
|
97
|
+
})
|
|
98
|
+
mirrorWrites.set(file, next)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function mirrorReadAll(mirrorDir: string, windowId: string): Promise<Array<{ type: string; data: unknown; surfaceOp?: unknown }>> {
|
|
102
|
+
try {
|
|
103
|
+
const raw = await readFile(mirrorFile(mirrorDir, windowId), 'utf8')
|
|
104
|
+
return raw.split('\n').filter(line => line.trim().length > 0).map(line => JSON.parse(line) as { type: string; data: unknown; surfaceOp?: unknown })
|
|
105
|
+
} catch {
|
|
106
|
+
return []
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ── 重放(窗重建后恢复历史)───────────────────────────────────────────────
|
|
111
|
+
|
|
112
|
+
async function replayWindow(window: Session, mirrorDir: string): Promise<void> {
|
|
113
|
+
const windowId = String(window.id)
|
|
114
|
+
const rows = await mirrorReadAll(mirrorDir, windowId)
|
|
115
|
+
if (rows.length === 0) return
|
|
116
|
+
replaying.add(windowId)
|
|
117
|
+
try {
|
|
118
|
+
// 【持久化投影窗】冷装载后的窗已含持久化日志事件(count>0)——重放改为
|
|
119
|
+
// 「并集合并」:按 (type|_srcSeq|turn|step|data.seq|kind|index|actor) 身份
|
|
120
|
+
// 键去重,只补镜像里多出的行;裸窗(count=0)维持整窗重放。
|
|
121
|
+
const durable = readSessionEventCount(window) > 0
|
|
122
|
+
const seen = new Set<string>()
|
|
123
|
+
if (durable) {
|
|
124
|
+
for (const e of readSessionEvents(window)) {
|
|
125
|
+
seen.add(replayKey(e.type, (e.data ?? {}) as Record<string, unknown>))
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
let replayed = 0
|
|
129
|
+
for (const row of rows) {
|
|
130
|
+
// descriptor 由建窗路径按需补(projectionHasDescriptor),重放会重复。
|
|
131
|
+
if (row.type === DESCRIPTOR_TYPE) continue
|
|
132
|
+
if (durable) {
|
|
133
|
+
const key = replayKey(row.type, (row.data ?? {}) as Record<string, unknown>)
|
|
134
|
+
if (seen.has(key)) continue
|
|
135
|
+
seen.add(key)
|
|
136
|
+
}
|
|
137
|
+
// 旧镜像行缺 surfaceOp 标记的 surface-eligible 事件补 append 兜底
|
|
138
|
+
// (镜像记录口径修复前的存量文件)。
|
|
139
|
+
const surface = row.surfaceOp !== undefined
|
|
140
|
+
? row.surfaceOp
|
|
141
|
+
: SURFACE_ELIGIBLE_TYPES.has(row.type) ? { surfaceOp: 'append' } : undefined
|
|
142
|
+
try {
|
|
143
|
+
appendEvent(window, row.type, row.data, surface)
|
|
144
|
+
replayed += 1
|
|
145
|
+
} catch (error: unknown) {
|
|
146
|
+
console.log(`[femo-plugin][native] replay row skipped (${row.type}): ${String(error).slice(0, 120)}`)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (replayed > 0) console.log(`[femo-plugin][native] window ${windowId} restored from mirror: ${replayed} rows`)
|
|
150
|
+
} finally {
|
|
151
|
+
replaying.delete(windowId)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** 重放去重键:type + data 里最具区分度的稳定字段(_srcSeq/turn/step/data.seq/
|
|
156
|
+
* kind/index/actor)。文件行与镜像行同构,键一致即视为同一事件。 */
|
|
157
|
+
function replayKey(type: string, d: Record<string, unknown>): string {
|
|
158
|
+
return [
|
|
159
|
+
type,
|
|
160
|
+
String(d._srcSeq ?? ''),
|
|
161
|
+
typeof d.turn === 'number' ? String(d.turn) : '',
|
|
162
|
+
typeof d.step === 'number' ? String(d.step) : '',
|
|
163
|
+
String(d.seq ?? ''),
|
|
164
|
+
String(d.kind ?? ''),
|
|
165
|
+
typeof d.index === 'number' ? String(d.index) : '',
|
|
166
|
+
String(d.actor ?? ''),
|
|
167
|
+
].join('|')
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ── 安装点(index.ts 在 apply 内调用一次)─────────────────────────────────
|
|
171
|
+
|
|
172
|
+
/** 【0.1.3 运行时白名单注册(替代文件补丁,升级免重打)】把 femo-plugin/chat
|
|
173
|
+
* 加进【宿主进程】加载的那份 KNOWN_SESSION_EVENT_TYPES——与持久化协调器
|
|
174
|
+
* 同一实例(createRequire(宿主入口) 解析出的文件,URL 缓存同实例)。机制
|
|
175
|
+
* 与旧版 registerSessionEventType 完全相同(上游只是收了 API,Set 仍在)。
|
|
176
|
+
* 进程内存级、幂等:每次插件加载自动注册,dsh 升级后无需任何手工补丁。
|
|
177
|
+
* 注册链:宿主入口(argv[1])解析优先 → 本插件模块副本兜底(legacy 部署
|
|
178
|
+
* 两本一致;纯官方部署上插件副本无谓,注册结果以宿主视图复核为准)。 */
|
|
179
|
+
function registerRuntimeWhitelist(): { ok: boolean; hostPath?: string } {
|
|
180
|
+
const candidates: Array<() => unknown> = []
|
|
181
|
+
let hostPath: string | undefined
|
|
182
|
+
if (process.argv[1] !== undefined && process.argv[1].length > 0) {
|
|
183
|
+
try {
|
|
184
|
+
const req = createRequire(process.argv[1])
|
|
185
|
+
hostPath = req.resolve('@deepseek-ai/dsh-session')
|
|
186
|
+
candidates.push(() => req('@deepseek-ai/dsh-session'))
|
|
187
|
+
} catch { /* 宿主入口解析失败,走兜底 */ }
|
|
188
|
+
}
|
|
189
|
+
candidates.push(() => createRequire(import.meta.url)('@deepseek-ai/dsh-session'))
|
|
190
|
+
for (const load of candidates) {
|
|
191
|
+
try {
|
|
192
|
+
const mod = load() as { KNOWN_SESSION_EVENT_TYPES?: Set<string> }
|
|
193
|
+
const set = mod?.KNOWN_SESSION_EVENT_TYPES
|
|
194
|
+
if (set !== undefined && typeof set.add === 'function') {
|
|
195
|
+
set.add(FEMO_CHAT_TYPE)
|
|
196
|
+
for (const legacy of LEGACY_FEMO_EVENT_TYPES) set.add(legacy)
|
|
197
|
+
const ok = set.has(FEMO_CHAT_TYPE)
|
|
198
|
+
console.log(`[femo-plugin][native] runtime whitelist registration: femo-plugin/chat ${ok ? 'registered' : 'failed'}${hostPath !== undefined ? ` (host copy: ...${hostPath.slice(-60)})` : ' (plugin-local copy)'} (+${LEGACY_FEMO_EVENT_TYPES.length} legacy femo types)`)
|
|
199
|
+
return { ok, hostPath }
|
|
200
|
+
}
|
|
201
|
+
} catch { /* 下一候选 */ }
|
|
202
|
+
}
|
|
203
|
+
console.log('[femo-plugin][native] runtime whitelist registration unavailable; persistence gate stays conservative')
|
|
204
|
+
return { ok: false, hostPath: undefined }
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** ESM 视图复核:require(esm) 与 import 的缓存一致性随 Node 版本有差异,
|
|
208
|
+
* 双视图都确认已注册才允许持久化路线(防"注册到了错误实例"的假阳性)。 */
|
|
209
|
+
async function verifyHostWhitelistView(hostPath?: string): Promise<boolean> {
|
|
210
|
+
if (hostPath === undefined) return true // 无宿主解析(legacy 同实例部署),以注册结果为准
|
|
211
|
+
try {
|
|
212
|
+
const { pathToFileURL } = await import('node:url')
|
|
213
|
+
const ns = (await import(pathToFileURL(hostPath).href)) as { KNOWN_SESSION_EVENT_TYPES?: Set<string> }
|
|
214
|
+
const ok = ns?.KNOWN_SESSION_EVENT_TYPES?.has(FEMO_CHAT_TYPE) === true
|
|
215
|
+
if (!ok) console.log('[femo-plugin][native] ESM view of the whitelist lacks femo-plugin/chat — downgrading persistence gate')
|
|
216
|
+
return ok
|
|
217
|
+
} catch {
|
|
218
|
+
return true // 复核不可用不降级(注册动作本身已成功)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function installNativeWindowing(
|
|
223
|
+
ctx: Context,
|
|
224
|
+
opts: { native: boolean; mirrorDir: string },
|
|
225
|
+
): void {
|
|
226
|
+
nativeState.native = opts.native
|
|
227
|
+
if (!opts.native) return
|
|
228
|
+
const registration = registerRuntimeWhitelist()
|
|
229
|
+
nativeState.mainChatSafe = registration.ok
|
|
230
|
+
void mkdir(opts.mirrorDir, { recursive: true }).catch((error: unknown) => {
|
|
231
|
+
console.log(`[femo-plugin][native] mirror dir create failed: ${String(error)}`)
|
|
232
|
+
})
|
|
233
|
+
if (registration.ok) {
|
|
234
|
+
void verifyHostWhitelistView(registration.hostPath).then((ok) => {
|
|
235
|
+
if (!ok) {
|
|
236
|
+
nativeState.mainChatSafe = false
|
|
237
|
+
console.log('[femo-plugin][native] persistence gate downgraded to window-only (ESM view mismatch)')
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
// 每一行窗事件(引擎行/镜像的模型事件)落 femo 自有镜像。
|
|
242
|
+
ctx.on('session/event', (session: Session, event: SessionEvent) => {
|
|
243
|
+
if (!String(session.id).startsWith(WINDOW_ID_PREFIX)) return
|
|
244
|
+
if (replaying.has(String(session.id))) return
|
|
245
|
+
mirrorEnqueue(opts.mirrorDir, String(session.id), event)
|
|
246
|
+
})
|
|
247
|
+
// 重启后窗同 id 重建 → 从镜像重放。冷装载窗(count>0,宿主只有持久层
|
|
248
|
+
// 少量事件)与裸窗(count=0)都走 replayWindow:前者按「并集合并」只补
|
|
249
|
+
// 镜像多出的行,后者整窗重放。【2026-09-09 深夜五轮】此前这里的
|
|
250
|
+
// `count>0 → return` 守卫把并集合并整段短路——冷装载窗永远只有持久层
|
|
251
|
+
// 基线、镜像内容回不来,客户端 history 首拉即空 → 官方 blank 语义隐藏
|
|
252
|
+
// header/body =「白屏」(实测根因,非猜测)。
|
|
253
|
+
ctx.on('session/created', (session: Session) => {
|
|
254
|
+
if (!String(session.id).startsWith(WINDOW_ID_PREFIX)) return
|
|
255
|
+
void replayWindow(session, opts.mirrorDir)
|
|
256
|
+
})
|
|
257
|
+
console.log(`[femo-plugin][native] native dsh build: projection windows ${nativeState.mainChatSafe ? 'durable (agent-loop created, native persistence)' : 'live-only + mirror-restored'}; main-session femo-plugin/chat ${nativeState.mainChatSafe ? 'allowed (event type whitelisted in this build)' : 'suppressed (event type NOT in persistence whitelist)'}`)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// ── compat 层(调用处入口)────────────────────────────────────────────────
|
|
261
|
+
// legacy(meow fork,有 registerSessionEventType):直通旧路径,行为逐字节
|
|
262
|
+
// 不变。native:是否写主会话由【运行时白名单注册】(mainChatSafe)裁决——
|
|
263
|
+
// 注册成功(任意官方构建,进程内注册)走旧版同款「主会话+投影窗」双写;
|
|
264
|
+
// 注册不可得才降级为仅窗侧。
|
|
265
|
+
|
|
266
|
+
/** 运行回执广播(剧本已开始/跑完/停止/出错等 sys 行)。 */
|
|
267
|
+
export function broadcastCompat(
|
|
268
|
+
ctx: Context,
|
|
269
|
+
session: Session,
|
|
270
|
+
projections: ProjectionRegistry,
|
|
271
|
+
text: string,
|
|
272
|
+
): void {
|
|
273
|
+
if (nativeState.native && !nativeState.mainChatSafe) {
|
|
274
|
+
appendChatProjected(ctx, session, projections, text, 'sys')
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
appendChatBroadcast(ctx, session, projections, text)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** 定向剧本行。alsoMainSession=true(llmBridge 直连 role 行)仅在主会话可
|
|
281
|
+
* 承载本插件事件时生效,否则降级为仅窗侧。 */
|
|
282
|
+
export function projectedCompat(
|
|
283
|
+
ctx: Context,
|
|
284
|
+
session: Session,
|
|
285
|
+
projections: ProjectionRegistry,
|
|
286
|
+
text: string,
|
|
287
|
+
kind: 'role' | 'notice' | 'human_wait' | 'prompt' | 'error' | 'thinking',
|
|
288
|
+
actor?: string,
|
|
289
|
+
visible?: string[],
|
|
290
|
+
alsoMainSession = false,
|
|
291
|
+
): void {
|
|
292
|
+
const mainAllowed = !nativeState.native || nativeState.mainChatSafe
|
|
293
|
+
appendChatProjected(ctx, session, projections, text, kind, actor, visible, alsoMainSession && mainAllowed)
|
|
294
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "宿主能力清单(A2.1 解耦):femoCompiler/host_manifest.py 在桥启动时读取。这里是 DSH 接口侧提供的 harness 词汇与环境——换一个 agent harness 只需换这份文件,引擎零改动。字段缺失/文件缺失时引擎用内置缺省(standalone 自圆满)。模型目录是动态的,不在此文件:由宿主在 job_start/check 经协议参数 models 注入。",
|
|
3
|
+
"host": "dsh",
|
|
4
|
+
"thinking_levels": ["off", "minimal", "low", "medium", "high", "xhigh", "max"],
|
|
5
|
+
"default_user_id": "u001"
|
|
6
|
+
}
|