femo-plugin 1.0.4 → 1.0.5
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/docs/ActiveRoadmaps/Func/345/201/234/346/255/242/350/257/255/344/271/211-/351/201/227/345/274/203/346/216/245/347/273/255-/346/226/275/345/267/245/346/270/205/345/215/225.md +91 -0
- package/docs/ActiveRoadmaps//345/217/214user/346/226/275/345/267/245/346/270/205/345/215/225.md +326 -0
- package/docs/Specs//346/212/225/345/275/261/344/270/255/345/277/203/350/241/214/345/215/217/350/256/256.md +616 -569
- package/femo2host/AGENTS.md +1 -1
- package/femo2host/femoGenConnector/engine-client.mjs +7 -2
- package/femo2host/femoGenConnector/file-dialogs.mjs +108 -2
- package/femo2host/femoToolcall/chronica.py +99 -19
- package/femo2host/femo_api.py +14 -1
- package/femo2host/host/actor-core.d.mts +25 -0
- package/femo2host/host/actor-core.mjs +72 -0
- package/femo2host/host/cast-core.d.mts +3 -0
- package/femo2host/host/cast-core.mjs +14 -0
- package/femo2host/host/daemon-client.mjs +59 -10
- package/femo2host/host/hub-render-core.d.mts +2 -0
- package/femo2host/host/hub-render-core.mjs +6 -2
- package/femo2host/host/run-state-core.d.mts +4 -0
- package/femo2host/host/run-state-core.mjs +4 -0
- package/femo2host/host/speech-core.mjs +11 -4
- package/femo2host/host/tools-core.d.mts +11 -0
- package/femo2host/host/tools-core.mjs +39 -0
- package/femo2host/mailbox.py +66 -20
- package/femo2host/projectionCenter/app.css +61 -0
- package/femo2host/projectionCenter/composer.mjs +69 -11
- package/femo2host/projectionCenter/identity.mjs +131 -0
- package/femo2host/projectionCenter/index.html +54 -1
- package/femo2host/projectionCenter/main.mjs +209 -33
- package/femo2host/projectionCenter/panels.mjs +108 -16
- package/femo2host/projectionCenter/render.mjs +813 -695
- package/femo2host/projectionCenter/state.mjs +30 -0
- package/femo2host/projectionCenter/util.mjs +28 -0
- package/femo2host/projection_hub.py +9917 -8422
- package/femo2host/python/femo_bridge.py +270 -32
- package/femo2host/python/femo_daemon.py +1528 -1209
- package/femo2host/python/mirror_window.py +237 -0
- package/femoBridges/ContextExample.py +113 -71
- package/femoCompiler/AGENTS.md +1 -0
- package/femoCompiler/FEMO_parser.py +2641 -2567
- package/femoCompiler/FEMO_runtime.py +201 -44
- package/femoCompiler/FEMO_scope_resolver.py +26 -12
- package/femoCompiler/block_collector.py +24 -27
- package/femoCompiler/db_utils.py +560 -503
- package/femoCompiler/femoAsync.py +466 -436
- package/femoCompiler/func_registry.py +74 -0
- package/femoCompiler/protocol.py +127 -127
- package/femoCompiler/save_dialog.py +497 -446
- package/femoExamples/AI/350/201/212/345/244/251/345/256/244/AI/350/201/212/345/244/251/345/256/244-/345/270/246agent/347/211/210.femo +229 -142
- package/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +91 -2
- package/femoExamples/LuxFiat/luxfiat-loop.femo +0 -1
- package/femoExamples/LuxFiat/luxfiat-simple.femo +23 -24
- package/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +221 -222
- package/femoExamples/discussion.femo +72 -72
- 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-9/344/272/272/351/242/204/345/245/263/347/214/216.femo +1 -2
- 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 +1 -2
- package/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +1 -2
- 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 +1 -1
- 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 +1 -1
- package/femoGen/src/femoParser.jsx +14 -0
- package/hostAdapter/dshAdapter/host/femo-skill.ts +23 -10
- package/hostAdapter/dshAdapter/host/routes/projection-input.ts +3 -0
- package/hostAdapter/dshAdapter/lib/client.js +20 -2
- package/hostAdapter/dshAdapter/lib/client.js.map +2 -2
- package/hostAdapter/dshAdapter/lib/main.js +161 -18
- package/hostAdapter/dshAdapter/lib/main.js.map +3 -3
- package/hostAdapter/dshAdapter/package.json +1 -1
- package/hostAdapter/webAdapter/console/index.html +12 -4
- package/hostAdapter/webAdapter/extension/background.js +16 -5
- package/hostAdapter/webAdapter/extension/seat-agent-core.js +2 -1
- package/hostAdapter/webAdapter/extension/sidepanel/actors.mjs +101 -0
- package/hostAdapter/webAdapter/extension/sidepanel/main.mjs +81 -20
- package/hostAdapter/webAdapter/extension/sidepanel/reconnect.mjs +33 -0
- package/hostAdapter/webAdapter/extension/sidepanel/run-control.mjs +22 -11
- package/hostAdapter/webAdapter/extension/sidepanel/seats.mjs +6 -20
- package/hostAdapter/webAdapter/extension/sidepanel.html +30 -8
- package/hostAdapter/webAdapter/native/install-native-host.mjs +1 -0
- package/hostAdapter/webAdapter/native/register-core.mjs +69 -28
- package/hostAdapter/webAdapter/native/web-launcher.sh +37 -0
- package/hostAdapter/webAdapter/readme.md +51 -10
- package/hostAdapter/webAdapter/server/bridge.mjs +1 -1
- package/hostAdapter/webAdapter/server/runtime.mjs +51 -5
- package/hostAdapter/webAdapter/server/seats.mjs +11 -6
- package/hostAdapter/webAdapter/server/service.mjs +108 -15
- package/hostAdapter/webAdapter/shared/seats-core.mjs +31 -6
- package/hostAdapter/webAdapter/sites/chatglm.cn/inject.js +76 -4
- package/hostAdapter/webAdapter/sites/chatgpt.com/SITE.md +1 -0
- package/hostAdapter/webAdapter/sites/chatgpt.com/content.js +13 -4
- package/hostAdapter/webAdapter/sites/chatgpt.com/inject.js +40 -4
- package/hostAdapter/webAdapter/start-service.command +16 -0
- package/hostAdapter/webAdapter/tests/chatgpt-parser.test.mjs +37 -0
- package/hostAdapter/webAdapter/tests/runtime.test.mjs +42 -0
- package/hostAdapter/webAdapter/tests/seats-core.test.mjs +37 -1
- package/hostAdapter/webAdapter/tests/smoke-service.mjs +261 -232
- package/hostAdapter/zcodeAdapter/runtime/speech-collect.mjs +6 -0
- package/hostAdapter/zcodeAdapter/tests/unbound-actors.test.mjs +51 -0
- package/package.json +1 -1
- package//350/257/255/346/263/225/346/226/207/346/241/243.md +1222 -1202
package/femo2host/AGENTS.md
CHANGED
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
- **段键用 wait_key,不用 node_name**:并行分支常跑同名节点([看牌] 三分支、[投票] 四分支),拿节点名当段键必然串段——job 1810 踩过的坑。
|
|
142
142
|
- **行更新类广播的视角过滤走行本体**:控制帧顶层没有视野字段,拿帧去过滤会把戏内/角色视角全滤掉;要按行自带的视野过滤。
|
|
143
143
|
- **实时流结束时只清块、不转正**:正式段由引擎落账那一拍收,草稿转正必出双份。
|
|
144
|
-
-
|
|
144
|
+
- **段的两批填(2026-10-12 换轴修订)**:AI 段仍在 `ai_request` 那拍开段(空段加「正在…」),交卷那拍填思考/工具/台词收口;人类段改在**交卷那拍一次成型**——「等待=席位不是段」(用户拍板:输入框是独立的东西、每个人类视角只看见自己的输入框、人类新段在发言发送成功那一刻才建立),演出提示/指令随等待席位下发(协议 §5.3 `head_items`),等待期不落段行,新段按 scope 透视实时上墙、无需行层透镜。
|
|
145
145
|
|
|
146
146
|
## 五、上移纪律
|
|
147
147
|
|
|
@@ -193,9 +193,14 @@ export function createEngineClient({ base = '', relay = '', fetchImpl = fetch, e
|
|
|
193
193
|
return cmd('job_pause', { job_id: Number(jobId) });
|
|
194
194
|
},
|
|
195
195
|
|
|
196
|
-
/** 续跑:档案里的剧本原文快照由调用方给(三步走的第三步)。
|
|
196
|
+
/** 续跑:档案里的剧本原文快照由调用方给(三步走的第三步)。
|
|
197
|
+
* host_ai_backend 恒 true(2026-10-12 实案定罪):缺了它引擎按直连模式
|
|
198
|
+
* 构造 Runner,首个 AI 节点没 API key 当场炸挂起(flow_paused node_pause
|
|
199
|
+
* 「直连模式未检测到任何 API Key」)——画布续的是宿主开的场,AI 派工
|
|
200
|
+
* 归各家宿主席,与投影中心/dsh 续跑同款语义。 */
|
|
197
201
|
async resume(jobId, femoText) {
|
|
198
|
-
return cmd('job_resume', { job_id: Number(jobId), femo: String(femoText ?? '')
|
|
202
|
+
return cmd('job_resume', { job_id: Number(jobId), femo: String(femoText ?? ''),
|
|
203
|
+
host_ai_backend: true });
|
|
199
204
|
},
|
|
200
205
|
|
|
201
206
|
/** 人类席交卷:信封词汇唯一出处=公共层 speech-core——人类席 {chat_text, variables?}。 */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* file-dialogs.mjs — 弹系统文件对话框选 .femo 文件(Windows PowerShell + WinForms)。
|
|
2
|
+
* file-dialogs.mjs — 弹系统文件对话框选 .femo 文件(Windows PowerShell + WinForms / macOS osascript 原生 NAV)。
|
|
3
3
|
*
|
|
4
4
|
* 2026-09-30 自 dshAdapter/host/routes/dialogs.ts 上移公共层:桌面端「选路径」
|
|
5
5
|
* 的引擎归 femoGen 自有(web 宿主本地服务同吃,dsh 原文件改转发壳)——同一份
|
|
@@ -27,6 +27,19 @@
|
|
|
27
27
|
*
|
|
28
28
|
* 并发闸不在本件:弹窗要不要排队/拒绝是调用方的 UI 裁决(web 单飞 409、dsh
|
|
29
29
|
* 放行叠窗各随其主),引擎只管一次忠实的弹框。
|
|
30
|
+
*
|
|
31
|
+
* 2026-10-10 mac 兼容实案(实锤:操作台「浏览」报 pick-script failed (exit -1),
|
|
32
|
+
* exit -1 = spawn('powershell.exe') ENOENT——mac 没有 powershell,Windows 路不通):
|
|
33
|
+
* 按平台分流,Windows 原逻辑原样保留;mac 走 osascript 原生对话框(choose file /
|
|
34
|
+
* choose file name,NAV 服务天然置顶)。弹框进程 detached 设新会话——服务死了
|
|
35
|
+
* 对话框也不陪葬(镜像 femo_daemon.py start_new_session 的代拉纪律)。弹框前
|
|
36
|
+
* tell me to activate 前台化(失败再试 System Events frontmost,双重 try,均败
|
|
37
|
+
* 也不挡弹框——mac 不需要 Windows 那套 SetWindowPos 轮询钉窗,NAV 对话框跟
|
|
38
|
+
* 键窗走)。结果回传走 PO 信箱帧:AS 把结果写进临时文件('ok <base64路径>' /
|
|
39
|
+
* 'cancel' / 'err <base64错误>',单行),node 读帧分派——「结果」与「进程退出」
|
|
40
|
+
* 解耦,取消/错误/成功三态铁定可靠(stdout/退出码都不可靠);帧文件名带
|
|
41
|
+
* pid+时间戳唯一,读取即消费,无需清理步骤。约定与 Windows 同款:返回路径 /
|
|
42
|
+
* null=取消 / 抛错=故障;10 分钟无裁决杀框。
|
|
30
43
|
*/
|
|
31
44
|
|
|
32
45
|
const DIALOG_TIMEOUT_MS = 600_000
|
|
@@ -36,6 +49,98 @@ function b64(s) {
|
|
|
36
49
|
return Buffer.from(String(s), 'utf8').toString('base64')
|
|
37
50
|
}
|
|
38
51
|
|
|
52
|
+
/** 对外唯一入口:按平台分流(两分支约定对齐:路径/null/抛错,调用方零感知)。 */
|
|
53
|
+
export async function pickFemoFileViaDialog(opts) {
|
|
54
|
+
if (process.platform === 'darwin') return pickFemoFileViaDialogMac(opts)
|
|
55
|
+
return pickFemoFileViaDialogWindows(opts)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** mac 分支(2026-10-10 新增,见文件头 mac 实案段):osascript 原生对话框 + PO 信箱帧回传。 */
|
|
59
|
+
async function pickFemoFileViaDialogMac(opts) {
|
|
60
|
+
const { spawn } = await import('node:child_process')
|
|
61
|
+
const os = await import('node:os')
|
|
62
|
+
const path = await import('node:path')
|
|
63
|
+
const fs = await import('node:fs')
|
|
64
|
+
const po = path.join(os.tmpdir(), `femo-dialog-${process.pid}-${Date.now()}.po`)
|
|
65
|
+
let defaultName = opts.defaultName !== undefined ? String(opts.defaultName) : 'flow'
|
|
66
|
+
if (!/\.femo$/i.test(defaultName)) defaultName += '.femo'
|
|
67
|
+
const env = {
|
|
68
|
+
...process.env,
|
|
69
|
+
FEMO_DIALOG_PO: po,
|
|
70
|
+
FEMO_DIALOG_TITLE: b64(opts.title),
|
|
71
|
+
FEMO_DIALOG_MODE: opts.mode === 'save' ? 'save' : 'open',
|
|
72
|
+
FEMO_DIALOG_DEFAULT_NAME: b64(defaultName),
|
|
73
|
+
FEMO_DIALOG_DIR: b64(opts.initialDirectory ?? ''),
|
|
74
|
+
FEMO_DIALOG_HAS_DIR: opts.initialDirectory ? '1' : '0',
|
|
75
|
+
}
|
|
76
|
+
// osascript 从 stdin 读脚本('-'),零转义层;detached 设新会话:宿主服务
|
|
77
|
+
// 中途退场,对话框照活(与 femo_daemon.py 代拉的 start_new_session 同纪律)。
|
|
78
|
+
const child = spawn('/usr/bin/osascript', ['-'], { env, detached: true, windowsHide: true, stdio: ['pipe', 'ignore', 'pipe'] })
|
|
79
|
+
child.stdin.end(macDialogAppleScript())
|
|
80
|
+
let errOut = ''
|
|
81
|
+
child.stderr.on('data', (c) => { errOut += c.toString('utf8') })
|
|
82
|
+
const timer = setTimeout(() => { try { child.kill() } catch { /* already gone */ } }, DIALOG_TIMEOUT_MS)
|
|
83
|
+
const code = await new Promise((resolve) => {
|
|
84
|
+
child.on('close', (c) => { clearTimeout(timer); resolve(c ?? 1) })
|
|
85
|
+
child.on('error', () => { clearTimeout(timer); resolve(-1) })
|
|
86
|
+
})
|
|
87
|
+
let picked = null, cancel = false, asErr = ''
|
|
88
|
+
try {
|
|
89
|
+
const raw = fs.readFileSync(po, 'utf8').trim()
|
|
90
|
+
if (raw.startsWith('ok ')) picked = Buffer.from(raw.slice(3).trim(), 'base64').toString('utf8')
|
|
91
|
+
else if (raw === 'cancel') cancel = true
|
|
92
|
+
else if (raw.startsWith('err ')) asErr = Buffer.from(raw.slice(4).trim(), 'base64').toString('utf8')
|
|
93
|
+
} catch { /* 无 PO 帧:进程级失败(含超时杀框) */ }
|
|
94
|
+
if (picked) return picked
|
|
95
|
+
if (cancel) return null
|
|
96
|
+
if (code !== 0 && /user canceled|用户已取消/i.test(errOut)) return null
|
|
97
|
+
const detail = [asErr, errOut.trim().slice(-400)].filter(Boolean).join(' | ')
|
|
98
|
+
throw new Error(`${opts.mode === 'open' ? 'pick-script' : 'pick-save-path'} failed (exit ${String(code)})${detail ? `: ${detail}` : ''}`)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** mac 对话框脚本:标题/缺省名/起始目录经环境变量传 base64(AS 内 base64 -D 解出,
|
|
102
|
+
* 零转义层),结果写 PO 帧后 return;取消(-128)写 cancel 帧后重抛;其余错误写
|
|
103
|
+
* err 帧后原样重抛(osascript 退出码非 0,detail 已落帧)。 */
|
|
104
|
+
function macDialogAppleScript() {
|
|
105
|
+
return `set PO to (do shell script "printf %s $FEMO_DIALOG_PO")
|
|
106
|
+
set T to (do shell script "printf %s $FEMO_DIALOG_TITLE | base64 -D")
|
|
107
|
+
set M to (do shell script "printf %s $FEMO_DIALOG_MODE")
|
|
108
|
+
try
|
|
109
|
+
tell me to activate
|
|
110
|
+
end try
|
|
111
|
+
try
|
|
112
|
+
set ospid to (do shell script "echo $PPID")
|
|
113
|
+
tell application "System Events" to set frontmost of (first process whose unix id is (ospid as integer)) to true
|
|
114
|
+
end try
|
|
115
|
+
try
|
|
116
|
+
set D to (do shell script "printf %s $FEMO_DIALOG_DEFAULT_NAME | base64 -D")
|
|
117
|
+
if (do shell script "printf %s $FEMO_DIALOG_HAS_DIR") is "1" then
|
|
118
|
+
set P to POSIX file (do shell script "printf %s $FEMO_DIALOG_DIR | base64 -D")
|
|
119
|
+
if M is "save" then
|
|
120
|
+
set f to choose file name with prompt T default name D default location P
|
|
121
|
+
else
|
|
122
|
+
set f to choose file with prompt T default location P
|
|
123
|
+
end if
|
|
124
|
+
else
|
|
125
|
+
if M is "save" then
|
|
126
|
+
set f to choose file name with prompt T default name D
|
|
127
|
+
else
|
|
128
|
+
set f to choose file with prompt T
|
|
129
|
+
end if
|
|
130
|
+
end if
|
|
131
|
+
do shell script "printf 'ok ' > " & quoted form of PO & " ; printf %s " & quoted form of (POSIX path of f) & " | base64 >> " & quoted form of PO
|
|
132
|
+
return "ok"
|
|
133
|
+
on error e number n
|
|
134
|
+
if n is -128 then
|
|
135
|
+
do shell script "printf cancel > " & quoted form of PO
|
|
136
|
+
else
|
|
137
|
+
do shell script "printf 'err ' > " & quoted form of PO & " ; printf %s " & quoted form of (((e as text) & " (" & (n as text) & ")")) & " | base64 >> " & quoted form of PO
|
|
138
|
+
end if
|
|
139
|
+
error e number n
|
|
140
|
+
end try
|
|
141
|
+
`
|
|
142
|
+
}
|
|
143
|
+
|
|
39
144
|
/** Win32 助手:C# 全文走 base64 进脚本(ASCII-only 纪律 + 单行 PS 塞不下
|
|
40
145
|
* here-string)。FindOwned 按「owner 名下可见窗」定位对话框——不按标题找:
|
|
41
146
|
* dsh 允许叠窗,同名标题的多开对话框会让按标题的定时器互相钉错窗。 */
|
|
@@ -74,7 +179,8 @@ function dialogPinCs() {
|
|
|
74
179
|
* @param {string} [opts.initialDirectory] 对话框打开时所在的目录(web 侧指向 projects/)
|
|
75
180
|
* @returns {Promise<string|null>} 所选绝对路径;null=用户取消;抛错=对话框故障(原话上浮给前端)
|
|
76
181
|
*/
|
|
77
|
-
|
|
182
|
+
/** Windows 分支(原实现原样保留,仅改名私有;见文件头置顶双保险实测坑)。 */
|
|
183
|
+
async function pickFemoFileViaDialogWindows(opts) {
|
|
78
184
|
const { spawn } = await import('node:child_process')
|
|
79
185
|
const dialogType = opts.mode === 'open' ? 'OpenFileDialog' : 'SaveFileDialog'
|
|
80
186
|
const defaultNameLine = opts.defaultName !== undefined
|
|
@@ -15,6 +15,9 @@ showprompt 属于FEMO脚本正经旁白,属于正经对话流的一部分。
|
|
|
15
15
|
python chronica.py --list 5 # 最近 5 个场次一览(标题+调用数)
|
|
16
16
|
python chronica.py 869 --scope # 每行附带可见性信息(排查视野问题用)
|
|
17
17
|
python chronica.py 869 --full # 发言全文不截断(默认对话流行截 110 字、指令 90 字)
|
|
18
|
+
python chronica.py 869 --user u001 # 只看该 user 参与的行,自己的发言标注「(我)」
|
|
19
|
+
# (2026-10-11 双user 刀E:user_scope=参与权,
|
|
20
|
+
# 多 user 共库时各翻各的;user_scope 空=全员可翻)
|
|
18
21
|
|
|
19
22
|
WAL 只读连接(mode=ro),与运行中的引擎互不干扰;
|
|
20
23
|
无需复制副本(复制法是旧文件沙箱时代的绕路,已废弃)。
|
|
@@ -85,12 +88,49 @@ def _clip(text, n):
|
|
|
85
88
|
return str(text).replace("\n", " ")[:n]
|
|
86
89
|
|
|
87
90
|
|
|
91
|
+
def _first_id(raw):
|
|
92
|
+
"""JSON 数组字段的首个 id(user_id / actor 列共用读法;坏值回原样)。"""
|
|
93
|
+
try:
|
|
94
|
+
arr = json.loads(raw)
|
|
95
|
+
return str(arr[0]) if isinstance(arr, list) and arr else ""
|
|
96
|
+
except Exception:
|
|
97
|
+
return str(raw or "")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _json_has(raw, uid):
|
|
101
|
+
"""JSON 数组字段是否含 uid(user_scope 参与权过滤用;空=无门槛)。"""
|
|
102
|
+
if not uid:
|
|
103
|
+
return True
|
|
104
|
+
if not raw:
|
|
105
|
+
return True # user_scope 空=全员可见(拍板:无参与权门槛不拦)
|
|
106
|
+
try:
|
|
107
|
+
arr = json.loads(raw)
|
|
108
|
+
return uid in [str(x) for x in arr] if isinstance(arr, list) else uid == str(raw)
|
|
109
|
+
except Exception:
|
|
110
|
+
return uid == str(raw)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _actor_of(actor_raw, uid_raw):
|
|
114
|
+
"""行上角色名显示(2026-10-11 双user 刀E):actor 列正身(@ 全名,AI 人类
|
|
115
|
+
同列);旧行 actor 空=按 user_id 首个 id 兜着显示(老账无 actor 列时代)。"""
|
|
116
|
+
a = str(actor_raw or '').strip()
|
|
117
|
+
if a and a != 'femo':
|
|
118
|
+
return a
|
|
119
|
+
u = _first_id(uid_raw)
|
|
120
|
+
return f'({u})' if u and not u.startswith(('femo', 'femoshow')) else ''
|
|
121
|
+
|
|
122
|
+
|
|
88
123
|
def main():
|
|
89
124
|
args = sys.argv[1:]
|
|
90
125
|
show_scope = "--scope" in args
|
|
91
126
|
args = [a for a in args if a != "--scope"]
|
|
92
127
|
show_full = "--full" in args
|
|
93
128
|
args = [a for a in args if a != "--full"]
|
|
129
|
+
user = ""
|
|
130
|
+
if "--user" in args:
|
|
131
|
+
i = args.index("--user")
|
|
132
|
+
user = str(args[i + 1]) if len(args) > i + 1 else ""
|
|
133
|
+
args = args[:i] + args[i + 2:]
|
|
94
134
|
clip_line = 10**9 if show_full else 110 # 对话流行宽(--full=不截断)
|
|
95
135
|
clip_dir = 10**9 if show_full else 90 # 幕后指令行宽
|
|
96
136
|
|
|
@@ -118,40 +158,80 @@ def main():
|
|
|
118
158
|
print(f"=== 场次 {sid}《{row[0]}》{tag} ===")
|
|
119
159
|
|
|
120
160
|
# ── 收集两表事件,统一按时间排序 ──
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
161
|
+
# (2026-10-11 双user 刀E):行带 actor(执行者角色名)与 actor_scope(角色
|
|
162
|
+
# 可见性)。列在不在先问库:只读连接碰上尚未被新引擎迁移过的老账本
|
|
163
|
+
# (actor_scope 列还没 ALTER 进去)降级读旧列,响亮留痕——应急工具不挡在
|
|
164
|
+
# 库版本上,但不许假装读到了新列。
|
|
165
|
+
def _cols_of(table):
|
|
166
|
+
return {r[1] for r in cur.execute(f"PRAGMA table_info({table})").fetchall()}
|
|
167
|
+
|
|
168
|
+
_d_cols = _cols_of("dialog")
|
|
169
|
+
_r_cols = _cols_of("react_steps")
|
|
170
|
+
_new_cols = ('actor' in _d_cols and 'actor_scope' in _d_cols
|
|
171
|
+
and 'actor' in _r_cols and 'actor_scope' in _r_cols)
|
|
172
|
+
if not _new_cols:
|
|
173
|
+
print("[chronica] ⚠️ 账本还是旧 schema(无 actor/actor_scope 列)——"
|
|
174
|
+
"按旧列读,角色/角色范围两栏缺席。让引擎跑一次即自动迁移。")
|
|
175
|
+
|
|
176
|
+
events = [] # dict: ts/kind/tid/text/us/ss/actor/uid/ascope
|
|
177
|
+
for row in cur.execute(
|
|
178
|
+
"SELECT timestamp, turn_id, user_id, user_prompt, user_scope, soul_scope"
|
|
179
|
+
+ (", actor, actor_scope" if _new_cols else "")
|
|
180
|
+
+ " FROM dialog WHERE session_id=? ORDER BY id", (sid,)
|
|
125
181
|
):
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
182
|
+
ts, tid, uid, p, us, ss = row[0], row[1], row[2], row[3], row[4], row[5]
|
|
183
|
+
ac = str(row[6] or '') if _new_cols else ''
|
|
184
|
+
asc = str(row[7] or '[]') if _new_cols else '[]'
|
|
185
|
+
if not _json_has(us, user):
|
|
186
|
+
continue
|
|
187
|
+
events.append({"ts": ts or 0, "kind": _classify(uid), "tid": tid,
|
|
188
|
+
"text": str(p), "us": us, "ss": ss,
|
|
189
|
+
"actor": ac, "uid": _first_id(uid), "ascope": asc})
|
|
190
|
+
for row in cur.execute(
|
|
191
|
+
"SELECT timestamp, turn_id, soul_id, response, user_scope, soul_scope, model_id"
|
|
192
|
+
+ (", actor, actor_scope" if _new_cols else "")
|
|
193
|
+
+ " FROM react_steps WHERE session_id=? ORDER BY id", (sid,)
|
|
130
194
|
):
|
|
195
|
+
ts, tid, soul, resp, us, ss, model_id = row[0], row[1], row[2], row[3], row[4], row[5], row[6]
|
|
196
|
+
ac = str(row[7] or '') if _new_cols else ''
|
|
197
|
+
asc = str(row[8] or '[]') if _new_cols else '[]'
|
|
198
|
+
if not _json_has(us, user):
|
|
199
|
+
continue
|
|
131
200
|
# model_id(2026-10-02 存储层贯通):本轮实际响应出处——provider/model
|
|
132
201
|
# 或 web:<站点名>(main=主模型下场渠道标记);空=宿主未实现/未取到。
|
|
133
202
|
via = f" [via {model_id}]" if str(model_id or '').strip() else ""
|
|
134
|
-
events.append(
|
|
135
|
-
|
|
203
|
+
events.append({"ts": ts or 0, "kind": "ai", "tid": tid,
|
|
204
|
+
"text": f"{soul}: {resp}{via}", "us": us, "ss": ss,
|
|
205
|
+
"actor": ac, "uid": "", "ascope": asc})
|
|
206
|
+
events.sort(key=lambda e: e["ts"])
|
|
207
|
+
|
|
208
|
+
def _who(kind, ev):
|
|
209
|
+
base = {"narration": "旁白", "ai": "AI", "human": "人类"}[kind]
|
|
210
|
+
a = _actor_of(ev["actor"], ev["uid"])
|
|
211
|
+
tag = f"{base}·{a}" if a else base
|
|
212
|
+
if user and ev["kind"] == "human" and ev["uid"] == user:
|
|
213
|
+
tag += "(我)"
|
|
214
|
+
return tag
|
|
136
215
|
|
|
137
216
|
# ── 第一幕:对话流(旁白 / AI / 人类)──
|
|
138
217
|
print("\n─── 对话流 ───")
|
|
139
|
-
for
|
|
140
|
-
if kind == "directive":
|
|
218
|
+
for ev in events:
|
|
219
|
+
if ev["kind"] == "directive":
|
|
141
220
|
continue
|
|
142
|
-
|
|
143
|
-
line = f" [{who}] {_clip(text, clip_line)}"
|
|
221
|
+
line = f" [{_who(ev['kind'], ev)}] {_clip(ev['text'], clip_line)}"
|
|
144
222
|
if show_scope:
|
|
145
|
-
line += f"\n 可见用户={_scopes(us)} 可见角色={_scopes(ss)}"
|
|
223
|
+
line += (f"\n 可见用户={_scopes(ev['us'])} 可见角色={_scopes(ev['ss'])}"
|
|
224
|
+
f" 角色范围={_scopes(ev['ascope'])}")
|
|
146
225
|
print(line)
|
|
147
226
|
|
|
148
227
|
# ── 第二幕:幕后指令(prompt,非对话流)──
|
|
149
|
-
directives = [e for e in events if e[
|
|
228
|
+
directives = [e for e in events if e["kind"] == "directive"]
|
|
150
229
|
print(f"\n─── 幕后指令(prompt × {len(directives)},不属对话流)───")
|
|
151
|
-
for
|
|
152
|
-
line = f" t{tid}: {_clip(text, clip_dir)}"
|
|
230
|
+
for ev in directives:
|
|
231
|
+
line = f" t{ev['tid']}: {_clip(ev['text'], clip_dir)}"
|
|
153
232
|
if show_scope:
|
|
154
|
-
line += f"\n 可见用户={_scopes(us)} 可见角色={_scopes(ss)}"
|
|
233
|
+
line += (f"\n 可见用户={_scopes(ev['us'])} 可见角色={_scopes(ev['ss'])}"
|
|
234
|
+
f" 角色范围={_scopes(ev['ascope'])}")
|
|
155
235
|
print(line)
|
|
156
236
|
conn.close()
|
|
157
237
|
|
package/femo2host/femo_api.py
CHANGED
|
@@ -80,6 +80,7 @@ from femoCompiler.db_utils import (
|
|
|
80
80
|
check_soul_id_exists as _check_soul_id_exists,
|
|
81
81
|
list_all_soul_ids as _list_all_soul_ids,
|
|
82
82
|
get_user_by_id as _get_user_by_id,
|
|
83
|
+
upsert_user as _upsert_user,
|
|
83
84
|
)
|
|
84
85
|
from femoCompiler import host_manifest as _host_manifest
|
|
85
86
|
# from femoCompiler.protocol import BLOCK_KEYS as _BLOCK_KEYS # 已退役(观察期 2026-09-27 femo2host 死代码排查):唯一使用者 AI_REQUEST_BLOCK_KEYS 已退役
|
|
@@ -96,6 +97,7 @@ __all__ = [
|
|
|
96
97
|
'create_runner',
|
|
97
98
|
# ⑤ 角色库
|
|
98
99
|
'get_soul', 'get_soul_name', 'get_user_name', 'default_user_id', 'host_name', 'list_souls', 'create_soul',
|
|
100
|
+
'upsert_user',
|
|
99
101
|
# 'soul_exists', # 已退役(观察期 2026-09-27 femo2host 死代码排查,全仓零引用)
|
|
100
102
|
# ⑥ FEMO脚本发现
|
|
101
103
|
'list_scripts',
|
|
@@ -257,7 +259,8 @@ def create_runner(script, *, base_dir: str, event_callback=None,
|
|
|
257
259
|
resume_state: Optional[dict] = None,
|
|
258
260
|
runtime_callbacks: Optional[dict] = None,
|
|
259
261
|
run_tag: str = '',
|
|
260
|
-
host_ai_backend: bool = False
|
|
262
|
+
host_ai_backend: bool = False,
|
|
263
|
+
user_registry: Optional[dict] = None) -> FEMORunner:
|
|
261
264
|
"""构造 FEMORunner 并按宿主协议装配到位(原宿主「构造 + 私有属性注入」
|
|
262
265
|
全流程内聚于此)。
|
|
263
266
|
|
|
@@ -275,6 +278,11 @@ def create_runner(script, *, base_dir: str, event_callback=None,
|
|
|
275
278
|
j<N>:ai_*),上下文拼接钉「首轮全量、之后增量」
|
|
276
279
|
(dsh harness 的窗口记忆契约);False = 引擎直连
|
|
277
280
|
LLM 出口(user_api_* 四参生效)
|
|
281
|
+
user_registry user 登记账 {@actor 全名: user_id}(2026-10-11 双user
|
|
282
|
+
刀B):开演时从演员定格账收养(类比 AI 席的
|
|
283
|
+
actor↔session 绑定,把 User 当 Session 用)。台账
|
|
284
|
+
user_id/user_scope/料包 user_info 全从这来;user 是
|
|
285
|
+
运行时事实,剧本不写。缺省空账(干跑替身/裸跑)。
|
|
278
286
|
|
|
279
287
|
wait_key 信箱恒开(等通道而非 stdin——与 main.py server 模式同款驱动),
|
|
280
288
|
这是 human_input / actor_failed 命令投递的前提。
|
|
@@ -292,6 +300,7 @@ def create_runner(script, *, base_dir: str, event_callback=None,
|
|
|
292
300
|
resume_state=resume_state,
|
|
293
301
|
runtime_callbacks=runtime_callbacks,
|
|
294
302
|
run_tag=run_tag,
|
|
303
|
+
user_registry=user_registry,
|
|
295
304
|
)
|
|
296
305
|
runner._human_input_event = threading.Event()
|
|
297
306
|
runner._human_input_data = None
|
|
@@ -326,6 +335,10 @@ def get_user_name(user_id: str) -> str:
|
|
|
326
335
|
return str(u.get('user_name', '') or '').strip() if u else ''
|
|
327
336
|
|
|
328
337
|
|
|
338
|
+
# 认领本机身份落账(2026-10-11 双user 刀H):users 表建/改条目(db_utils.upsert_user 正身)。
|
|
339
|
+
upsert_user = _upsert_user
|
|
340
|
+
|
|
341
|
+
|
|
329
342
|
def default_user_id() -> str:
|
|
330
343
|
"""宿主清单登记的默认用户 id(未提供=引擎内置缺省)。"""
|
|
331
344
|
return _host_manifest.default_user_id()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* actor-core.d.mts — 演员绑定账·宿主侧客户端类型(正身见 actor-core.mjs)。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface ActorEntryView {
|
|
6
|
+
sid: string
|
|
7
|
+
host?: string
|
|
8
|
+
type?: 'ai' | 'human'
|
|
9
|
+
user_id?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ActorPreferencesView {
|
|
13
|
+
ok: true
|
|
14
|
+
bindings: Record<string, ActorEntryView>
|
|
15
|
+
hosts: Record<string, Record<string, { actor: string }>>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export declare function actorPreferenceSet(
|
|
19
|
+
femoRoot: string,
|
|
20
|
+
host: string,
|
|
21
|
+
sid: string,
|
|
22
|
+
actor: string | null,
|
|
23
|
+
opts?: { type?: 'ai' | 'human' | ''; userId?: string },
|
|
24
|
+
): Promise<{ ok: boolean; error?: string }>
|
|
25
|
+
export declare function actorPreferencesView(femoRoot: string): Promise<ActorPreferencesView>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* actor-core.mjs — 演员绑定账·宿主侧客户端(femo2host 公共层,2026-10-10)。
|
|
3
|
+
*
|
|
4
|
+
* 与 cast-core.mjs(会话↔soul 选角账)平行的第二本账的宿主半场:账本正身住
|
|
5
|
+
* hub(actor-preferences.json,裁决与落盘契约见 projection_hub.py 演员绑定段),
|
|
6
|
+
* 本件是各宿主消费它的唯一读写口:
|
|
7
|
+
*
|
|
8
|
+
* actorPreferenceSet(femoRoot, host, sid, actor|null, {type?, userId?}) → {ok, error?}
|
|
9
|
+
* actorPreferencesView(femoRoot) → {bindings: {actor: {sid, host, type?, user_id?}}, hosts}
|
|
10
|
+
*
|
|
11
|
+
* 键纪律:actor 恒带 @ 全名(@ 是演员名的一部分,语法文档铁律「任何地方不得
|
|
12
|
+
* 去掉」——本件不添不删,照抄)。type='ai'(绑定指向某宿主某会话)| 'human'
|
|
13
|
+
* (绑定指向人,user_id 字段先立框架——待补充 user id 存储逻辑)| 缺省=只提名
|
|
14
|
+
* 未定性(@actor 只带名字、开演前再定性的预备格)。hub 地址走 hub-client 唯一
|
|
15
|
+
* 解析口(与 cast-core 同款)。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { hubBaseUrl } from './hub-client.mjs';
|
|
19
|
+
|
|
20
|
+
/** hub GET。失败抛错——调用方按各自语义处置,不静默。 */
|
|
21
|
+
async function actorGet(femoRoot, path, timeoutMs = 8000) {
|
|
22
|
+
const ctl = new AbortController();
|
|
23
|
+
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
24
|
+
try {
|
|
25
|
+
const resp = await fetch(`${hubBaseUrl(femoRoot)}${path}`, { signal: ctl.signal });
|
|
26
|
+
return await resp.json();
|
|
27
|
+
} finally {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** hub POST。返回解析后的 JSON({ok, error?})。失败抛错。 */
|
|
33
|
+
async function actorPost(femoRoot, path, body, timeoutMs = 8000) {
|
|
34
|
+
const ctl = new AbortController();
|
|
35
|
+
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
36
|
+
try {
|
|
37
|
+
const resp = await fetch(`${hubBaseUrl(femoRoot)}${path}`, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: { 'content-type': 'application/json' },
|
|
40
|
+
body: JSON.stringify(body),
|
|
41
|
+
signal: ctl.signal,
|
|
42
|
+
});
|
|
43
|
+
return await resp.json();
|
|
44
|
+
} finally {
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 提名/退票(actor=null 退票=按席删格)。type:'ai'(绑会话)/ 'human'(绑人,
|
|
50
|
+
* userId 可选先留空)/ ''(只提名未定性)。失败抛错。 */
|
|
51
|
+
export async function actorPreferenceSet(femoRoot, host, sid, actor, { type = '', userId = '' } = {}) {
|
|
52
|
+
const out = await actorPost(femoRoot, '/sessions/actor-preference', {
|
|
53
|
+
host, sid, ...(actor ? { actor } : {}), type, user_id: userId,
|
|
54
|
+
});
|
|
55
|
+
if (out === null || typeof out !== 'object' || out.ok !== true) {
|
|
56
|
+
throw new Error(`actor preference put failed (sid=${sid}, actor=${actor ?? '(退票)'}): ${out?.error ?? 'unknown'}`);
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 演员绑定账视图:{bindings: {actor: {sid, host, type?, user_id?}}, hosts}。
|
|
62
|
+
* hub 不可达按空视图(读失败不误伤交互,与 cast-core.preferencesView 同款)。 */
|
|
63
|
+
export async function actorPreferencesView(femoRoot) {
|
|
64
|
+
try {
|
|
65
|
+
const data = await actorGet(femoRoot, '/sessions/actor-preferences');
|
|
66
|
+
return (data !== null && typeof data === 'object' && typeof data.bindings === 'object' && data.bindings !== null)
|
|
67
|
+
? data
|
|
68
|
+
: { bindings: {}, hosts: {} };
|
|
69
|
+
} catch {
|
|
70
|
+
return { bindings: {}, hosts: {} };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -14,6 +14,9 @@ export interface CastPreferencesView {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export declare function readJobCast(femoRoot: string, jobId: number): Promise<Record<string, CastEntryView>>
|
|
17
|
+
/** 2026-10-10「mailbox 认演员」:Job 演员定格账(键=@actor 全名)。旧 hub 无
|
|
18
|
+
* 此路由时返回空对象,调用方回落 cast 老路。 */
|
|
19
|
+
export declare function readJobActorCast(femoRoot: string, jobId: number): Promise<Record<string, CastEntryView>>
|
|
17
20
|
export declare function putJobCastEntry(femoRoot: string, jobId: number, soulId: string, sid: string, host?: string): Promise<unknown>
|
|
18
21
|
export declare function snapshotJobCast(femoRoot: string, jobId: number): Promise<number>
|
|
19
22
|
export declare function preferenceSet(femoRoot: string, host: string, sid: string, soul: string | null): Promise<{ ok: boolean; error?: string }>
|
|
@@ -111,3 +111,17 @@ export async function preferencesView(femoRoot, scope = 'all') {
|
|
|
111
111
|
return { bindings: {}, hosts: {} };
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
/** Job 演员定格账读取(2026-10-10「mailbox 认演员」):{actor(@全名): {sid,
|
|
116
|
+
* host}}。与 cast 定格账同构(开演誊写、演出中冻结)。旧 hub 无此路由时
|
|
117
|
+
* 返回空对象,调用方回落 cast 老路。 */
|
|
118
|
+
export async function readJobActorCast(femoRoot, jobId) {
|
|
119
|
+
try {
|
|
120
|
+
const data = await castGet(femoRoot, `/cast-actor?job=${Number(jobId)}`);
|
|
121
|
+
return (data !== null && typeof data === 'object' && data.cast !== null && typeof data.cast === 'object')
|
|
122
|
+
? data.cast
|
|
123
|
+
: {};
|
|
124
|
+
} catch {
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
41
|
import { spawn } from 'node:child_process';
|
|
42
|
-
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, unlinkSync, writeSync } from 'node:fs';
|
|
42
|
+
import { accessSync, closeSync, constants, existsSync, mkdirSync, openSync, readFileSync, unlinkSync, writeSync } from 'node:fs';
|
|
43
43
|
import { request as httpRequest } from 'node:http';
|
|
44
|
-
import { dirname, join } from 'node:path';
|
|
44
|
+
import { delimiter, dirname, isAbsolute, join, sep } from 'node:path';
|
|
45
45
|
import { hubJsonPath } from './hub-client.mjs';
|
|
46
46
|
|
|
47
47
|
const HTTP_TIMEOUT_SEC = 120; // 命令 HTTP 超时(转发壳同款固定值;调用方超时另算)
|
|
@@ -52,6 +52,43 @@ const DAEMON_LOG_REL = join('logs', 'femo_daemon.log'); // 与 Python 代拉
|
|
|
52
52
|
|
|
53
53
|
function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }
|
|
54
54
|
|
|
55
|
+
function findExecutableOnPath(name, dirs) {
|
|
56
|
+
for (const dir of dirs) {
|
|
57
|
+
try {
|
|
58
|
+
const full = join(dir, name);
|
|
59
|
+
accessSync(full, constants.X_OK);
|
|
60
|
+
return full;
|
|
61
|
+
} catch { /* 下一个 */ }
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** python 可执行解析(2026-10-10 mac 实案收口):FEMO_PYTHON env 显式指定 >
|
|
67
|
+
* python3 > python——PATH 逐目录扫描 + mac/linux 常见安装位兑底。返回绝对路径
|
|
68
|
+
* 或 null(找不到时调用方要响亮报错,别静默)。背景:mac 缺省只有 python3
|
|
69
|
+
* 没有 python,spawn('python') ENOENT 且无人接 error 事件会把整个服务打崩;
|
|
70
|
+
* 解析成绝对路径顺带给 Chrome 拉起的窄 PATH 场景兑了底。 */
|
|
71
|
+
export function resolvePythonExe() {
|
|
72
|
+
const fromEnv = process.env.FEMO_PYTHON;
|
|
73
|
+
if (fromEnv) {
|
|
74
|
+
// 显式指定最优先:带路径分隔符的按原样交出,裸名按 PATH 找;验不动也
|
|
75
|
+
// 原样交出(spawn 侧 error 处理会响亮留痕),绝不静默改写用户意图。
|
|
76
|
+
if (isAbsolute(fromEnv) || fromEnv.includes(sep)) return fromEnv;
|
|
77
|
+
return findExecutableOnPath(fromEnv, (process.env.PATH || '').split(delimiter).filter(Boolean)) ?? fromEnv;
|
|
78
|
+
}
|
|
79
|
+
const isWin = process.platform === 'win32';
|
|
80
|
+
const names = isWin ? ['python.exe', 'python3.exe', 'python', 'python3'] : ['python3', 'python'];
|
|
81
|
+
const dirs = [
|
|
82
|
+
...(process.env.PATH || '').split(delimiter).filter(Boolean),
|
|
83
|
+
...(isWin ? [] : ['/usr/bin', '/usr/local/bin', '/opt/homebrew/bin']),
|
|
84
|
+
];
|
|
85
|
+
for (const name of names) {
|
|
86
|
+
const hit = findExecutableOnPath(name, dirs);
|
|
87
|
+
if (hit) return hit;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
55
92
|
/** 一发 JSON(GET/POST);返回 {status, body, raw}。连接类失败抛错(调用方分拣)。
|
|
56
93
|
* agent:false + 显式 Content-Length 两件都是给 Python http.server 的:其一,
|
|
57
94
|
* 无 Content-Length 的请求体 node 默认走 chunked,python 不认 chunked、响应后
|
|
@@ -197,7 +234,7 @@ export async function setDaemonSetting(femoRoot, callerHost, key, value) {
|
|
|
197
234
|
* @param {string} [opts.pushUrl] 本宿主收件口完整 URL(门牌:急件上门用)。心跳与它
|
|
198
235
|
* 无关——全员照起(2026-09-27 起),不传=自取户空门牌只报
|
|
199
236
|
* 在线(见文件头门铃段;旧注「传入则开门铃心跳」已作废)
|
|
200
|
-
* @param {string} [opts.python] python 可执行(缺省 FEMO_PYTHON env >
|
|
237
|
+
* @param {string} [opts.python] python 可执行(缺省 resolvePythonExe:FEMO_PYTHON env > python3 > python)
|
|
201
238
|
* @param {(eventType: string, data: unknown) => void} [opts.onEvent] 引擎事件上抛
|
|
202
239
|
* @param {(line: string) => void} [opts.onEngineLine] 保留兼容(引擎 stderr 现归 daemon 日志)
|
|
203
240
|
* @param {(line: string) => void} [opts.onEngineStderr] 保留兼容(同上)
|
|
@@ -213,7 +250,10 @@ export class DaemonClient {
|
|
|
213
250
|
this.hostManifestPath = opts.hostManifestPath || '';
|
|
214
251
|
this.dataDir = opts.dataDir || '';
|
|
215
252
|
this.pushUrl = opts.pushUrl || '';
|
|
216
|
-
|
|
253
|
+
// python 解析唯一口径(resolvePythonExe):opts.python 显式传入 > FEMO_PYTHON
|
|
254
|
+
// env > python3 > python。解析不到先落 'python',让 spawn 侧 error 处理
|
|
255
|
+
// 响亮报错(error 已接住,不再崩服务本体)。
|
|
256
|
+
this.pythonPath = opts.python ?? resolvePythonExe() ?? 'python';
|
|
217
257
|
this.onEvent = opts.onEvent;
|
|
218
258
|
this.onEngineLine = opts.onEngineLine;
|
|
219
259
|
this.onEngineStderr = opts.onEngineStderr;
|
|
@@ -269,7 +309,11 @@ export class DaemonClient {
|
|
|
269
309
|
const child = spawn(this.pythonPath, argv,
|
|
270
310
|
{ cwd: this.femoRoot, env, detached: true, windowsHide: true, stdio: ['ignore', logf, logf] });
|
|
271
311
|
child.unref();
|
|
272
|
-
|
|
312
|
+
// error 必须有人接:ENOENT(缺 python)等拉起失败原是 unhandled 'error'
|
|
313
|
+
// event,直接把宿主服务打崩(2026-10-10 mac 实案)——现在响亮留痕,
|
|
314
|
+
// 引擎等 ensure 的探活超时自然报「起不来」,服务本体不陪葬。
|
|
315
|
+
child.on('error', e => this.log(`daemon 拉起失败(python=${this.pythonPath}):${e?.message ?? e} —— 引擎不可用;装 python3(mac:xcode-select --install 或 brew install python3)或设 FEMO_PYTHON 指到可用解释器后重试`));
|
|
316
|
+
this.log(`daemon spawned (pid=${child.pid ?? '未起,等 error 落痕'}) log=${logPath}`);
|
|
273
317
|
}
|
|
274
318
|
|
|
275
319
|
/** 跨进程代拉意图锁(2026-09-28 镜窗成群事故):hub.json 死账谁探到谁就想
|
|
@@ -481,11 +525,16 @@ export class DaemonClient {
|
|
|
481
525
|
this._doorbellAbort = stopFlag;
|
|
482
526
|
void (async () => {
|
|
483
527
|
while (!stopFlag.stop) {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
528
|
+
// base 为空=发现未落定(断线/重发现中):无处敲门,安静跳过这一拍——
|
|
529
|
+
// 旧法照敲,fetch 对相对地址抛 Invalid URL,10s 一条刷屏(2026-10-12
|
|
530
|
+
// 实案:引擎孪生换防的六分钟窗口里门铃一拍没落到,散场点名看见空簿)。
|
|
531
|
+
if (this._base) {
|
|
532
|
+
try {
|
|
533
|
+
await httpJson(this._base, '/engine/doorbell',
|
|
534
|
+
{ method: 'POST', body: { host: this.host, url: this.pushUrl }, timeoutSec: 5 });
|
|
535
|
+
} catch (e) {
|
|
536
|
+
this.log(`doorbell register failed: ${String(e.message ?? e).slice(0, 120)}`);
|
|
537
|
+
}
|
|
489
538
|
}
|
|
490
539
|
for (let i = 0; i < DOORBELL_PERIOD_MS / 100 && !stopFlag.stop; i++) await sleep(100);
|
|
491
540
|
}
|
|
@@ -25,10 +25,14 @@ export function composerAllowedFor(view, waiting) {
|
|
|
25
25
|
return Array.isArray(waiting.views) && waiting.views.indexOf(v) >= 0;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
/** 输入席的执行者显示名:等待态 actor 优先,回退 scope 首位,再回退『人类席』。
|
|
28
|
+
/** 输入席的执行者显示名:等待态 actor 优先,回退 scope 首位,再回退『人类席』。
|
|
29
|
+
* 刀H(2026-10-11):席位带 actor_display(@人类1(显示名),hub 按绑定 user
|
|
30
|
+
* 的 user_name 组装)时优先显它——actor 本身保持裸名(身份键),显示名只在
|
|
31
|
+
* 这个展示字段里。 */
|
|
29
32
|
export function seatWho(waiting) {
|
|
30
33
|
const w = waiting || {};
|
|
31
|
-
return (typeof w.
|
|
34
|
+
return (typeof w.actor_display === 'string' && w.actor_display) ||
|
|
35
|
+
(typeof w.actor === 'string' && w.actor) ||
|
|
32
36
|
(Array.isArray(w.scope) && typeof w.scope[0] === 'string' && w.scope[0]) ||
|
|
33
37
|
'人类席';
|
|
34
38
|
}
|