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,313 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""patch-dsh-0.1.2-alpha.1.py — 喵版 fork 重放一键补丁(MEOW 条目 3 + 条目 1)
|
|
4
|
+
|
|
5
|
+
基线: dsh-v0.1.2-alpha.1 (HEAD cd5ef81),对应需求书 femo-plugin/dshPatch/DSH-0.1.2-fork修改需求.md
|
|
6
|
+
用法: python patch-dsh-0.1.2-alpha.1.py <快照根目录> [--dry-run]
|
|
7
|
+
例: python patch-dsh-0.1.2-alpha.1.py D:\\myFiles\\dsh\\dsh-meow0.1.2-alpha.1
|
|
8
|
+
|
|
9
|
+
覆盖:
|
|
10
|
+
MEOW 条目 3 (M-013 会话事件类型运行时注册面) — 4 处
|
|
11
|
+
MEOW 条目 1 (CLI 入口拒绝默认 ~/.dsh 家目录) — 2 处
|
|
12
|
+
|
|
13
|
+
不含 (需手动):
|
|
14
|
+
MEOW 条目 4 (tool-session-query 搜索排除, 5 文件复杂改动) — 按 MEOW 条目 4 明细手改
|
|
15
|
+
MEOW 条目 2 (端口外部化) — 机制条目, 无源码 diff
|
|
16
|
+
|
|
17
|
+
安全设计:
|
|
18
|
+
① 两阶段: 先对全部步骤做基线预检, 全部通过才动手; 任何一处对不上立即放弃, 不留半套改动
|
|
19
|
+
② 逐文件备份: 被修改文件旁写 .bak-meow-patch-0.1.2-alpha.1 (新文件除外)
|
|
20
|
+
③ 幂等: 重复运行自动跳过已应用步骤
|
|
21
|
+
④ fail-loud: 基线内容与 alpha.1 不符(版本不对/已手动改过)时明确报错, 绝不盲目替换
|
|
22
|
+
⑤ 字节级读写: 全程 bytes + UTF-8, 不触碰换行符与编码
|
|
23
|
+
|
|
24
|
+
注意: 本脚本与 0.1.2-alpha.1 的源码锚点一一对应。新版本快照(rc.x)落地时,
|
|
25
|
+
锚点可能漂移 —— 请对照新版源码核验后另写新版本号的脚本, 不要复用本文件。
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
import sys
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
VERSION = "0.1.2-alpha.1"
|
|
34
|
+
BACKUP_SUFFIX = ".bak-meow-patch-0.1.2-alpha.1"
|
|
35
|
+
|
|
36
|
+
# ── 锚点常量(全部来自 alpha.1 实读原文) ──────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
# index.ts L35 现状
|
|
39
|
+
ANCHOR_EXPORT = "export { KNOWN_SESSION_EVENT_TYPES } from './known-event-types.ts'"
|
|
40
|
+
NEW_EXPORT_LINE = (
|
|
41
|
+
"export { isKnownSessionEventType, registerSessionEventType } from './known-event-registry.ts'"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# coordinator.ts L12 (import 块成员, 来自 @deepseek-ai/dsh-session)
|
|
45
|
+
ANCHOR_COORD_IMPORT = "\n KNOWN_SESSION_EVENT_TYPES,\n"
|
|
46
|
+
REPL_COORD_IMPORT = "\n KNOWN_SESSION_EVENT_TYPES,\n isKnownSessionEventType,\n"
|
|
47
|
+
|
|
48
|
+
# coordinator.ts L1141 (assertEventsSupported 内, 全仓唯一 fail-closed 拒绝点)
|
|
49
|
+
ANCHOR_COORD_GUARD = "if (KNOWN_SESSION_EVENT_TYPES.has(event.type)) continue"
|
|
50
|
+
REPL_COORD_GUARD = "if (isKnownSessionEventType(event.type)) continue"
|
|
51
|
+
|
|
52
|
+
# bin.ts L12 / L24 (alpha 把 parseDshArgs 从 bin.ts 搬到了 args.ts)
|
|
53
|
+
ANCHOR_ARGS_IMPORT = "import { parseDshArgs } from './args.ts'"
|
|
54
|
+
GUARD_IMPORTS = (
|
|
55
|
+
"import { resolve } from 'node:path'\n"
|
|
56
|
+
"import { defaultDshHome, resolveDshHome } from '@deepseek-ai/dsh-home-paths'"
|
|
57
|
+
)
|
|
58
|
+
ANCHOR_INVOCATION = "const invocation = parseDshArgs(process.argv.slice(2), readVersion())"
|
|
59
|
+
|
|
60
|
+
# bin.ts 守卫块 (rc.2 提交 dda82f7 原文, 与版本无关的逻辑自包含块)
|
|
61
|
+
GUARD_BLOCK = """
|
|
62
|
+
|
|
63
|
+
// Meow fork guard: this build must never touch the official npm dsh
|
|
64
|
+
// installation's user data. The upstream CLI falls back to the default home
|
|
65
|
+
// (~/.dsh) when DSH_HOME is unset; this build refuses to boot in that case,
|
|
66
|
+
// so a bare `pnpm dsh web` — from a script or another agent — cannot silently
|
|
67
|
+
// read or write the official profiles, sessions, or credentials. Launch
|
|
68
|
+
// through start-meow.bat (which sets DSH_HOME to the meow data directory), or
|
|
69
|
+
// export DSH_HOME explicitly before invoking dsh.
|
|
70
|
+
const meowHome = resolveDshHome()
|
|
71
|
+
const officialHome = resolve(defaultDshHome())
|
|
72
|
+
const sameHome = process.platform === 'win32'
|
|
73
|
+
? meowHome.toLowerCase() === officialHome.toLowerCase()
|
|
74
|
+
: meowHome === officialHome
|
|
75
|
+
if (sameHome) {
|
|
76
|
+
console.error(
|
|
77
|
+
'dsh-meow: DSH_HOME is unset or resolves to the official home (~/.dsh).\\n'
|
|
78
|
+
+ 'This build refuses to touch the official npm dsh user data. '
|
|
79
|
+
+ 'Launch with start-meow.bat, or set DSH_HOME to your meow data directory first.',
|
|
80
|
+
)
|
|
81
|
+
process.exit(1)
|
|
82
|
+
}
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
# 新文件: packages/core/session/src/known-event-registry.ts (rc.2 57662a0 原文)
|
|
86
|
+
REGISTRY_TS = """/**
|
|
87
|
+
* Runtime extension of the persisted event-type vocabulary for out-of-repo
|
|
88
|
+
* consumers.
|
|
89
|
+
*
|
|
90
|
+
* `KNOWN_SESSION_EVENT_TYPES` is generated from repository-internal
|
|
91
|
+
* `SessionEventMap` declarations; downstream plugins cannot contribute to it.
|
|
92
|
+
* This registry lets such a plugin admit the session event types its own log
|
|
93
|
+
* appends, so the persistence read path interprets them instead of refusing
|
|
94
|
+
* the log as newer-harness output. Registrations are process-global and
|
|
95
|
+
* idempotent; the returned disposer removes the type (HMR-safe).
|
|
96
|
+
* @module @deepseek-ai/dsh-session/known-event-registry
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
import { KNOWN_SESSION_EVENT_TYPES } from './known-event-types.ts'
|
|
100
|
+
|
|
101
|
+
const registeredEventTypes = new Set<string>()
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Declare a session event type this runtime may read, in addition to the
|
|
105
|
+
* generated vocabulary. Call during plugin setup, before any session whose
|
|
106
|
+
* log contains the type is loaded.
|
|
107
|
+
* @param type - the event type string to admit (for example `'femo-plugin/chat'`).
|
|
108
|
+
* @returns a disposer that removes the registration.
|
|
109
|
+
*/
|
|
110
|
+
export function registerSessionEventType(type: string): () => void {
|
|
111
|
+
registeredEventTypes.add(type)
|
|
112
|
+
return () => {
|
|
113
|
+
registeredEventTypes.delete(type)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Whether the persistence read path may interpret an event of this type:
|
|
119
|
+
* generated vocabulary or an active runtime registration.
|
|
120
|
+
* @param type - the event type to test.
|
|
121
|
+
* @returns `true` when the type is known to this runtime.
|
|
122
|
+
*/
|
|
123
|
+
export function isKnownSessionEventType(type: string): boolean {
|
|
124
|
+
return KNOWN_SESSION_EVENT_TYPES.has(type) || registeredEventTypes.has(type)
|
|
125
|
+
}
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class Step:
|
|
130
|
+
"""一个原子补丁步骤: done/baseline 检查 + 变换函数。"""
|
|
131
|
+
|
|
132
|
+
def __init__(self, name, relpath, is_done, check_baseline, transform, is_new_file=False):
|
|
133
|
+
self.name = name
|
|
134
|
+
self.relpath = relpath
|
|
135
|
+
self.is_done = is_done # fn(content) -> bool 已应用(幂等跳过)
|
|
136
|
+
self.check_baseline = check_baseline # fn(content) -> bool 基线匹配(可应用)
|
|
137
|
+
self.transform = transform # fn(content) -> content
|
|
138
|
+
self.is_new_file = is_new_file # 新文件: 无备份, baseline = 目标不存在
|
|
139
|
+
self.action = None # validate 阶段填写: SKIP / APPLY
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def build_steps(root: Path) -> list[Step]:
|
|
143
|
+
core_src = root / "packages" / "core" / "session" / "src"
|
|
144
|
+
coord = root / "packages" / "session" / "session-persistence" / "src" / "coordinator.ts"
|
|
145
|
+
bin_ts = root / "apps" / "cli" / "src" / "bin.ts"
|
|
146
|
+
|
|
147
|
+
return [
|
|
148
|
+
Step(
|
|
149
|
+
name="m013-A 新增 known-event-registry.ts",
|
|
150
|
+
relpath=core_src / "known-event-registry.ts",
|
|
151
|
+
is_done=lambda c: "registerSessionEventType" in c,
|
|
152
|
+
check_baseline=lambda c: True,
|
|
153
|
+
transform=lambda c: REGISTRY_TS,
|
|
154
|
+
is_new_file=True,
|
|
155
|
+
),
|
|
156
|
+
Step(
|
|
157
|
+
name="m013-B index.ts 导出注册面",
|
|
158
|
+
relpath=core_src / "index.ts",
|
|
159
|
+
is_done=lambda c: "known-event-registry.ts'" in c,
|
|
160
|
+
check_baseline=lambda c: ANCHOR_EXPORT in c,
|
|
161
|
+
transform=lambda c: c.replace(ANCHOR_EXPORT, ANCHOR_EXPORT + "\n" + NEW_EXPORT_LINE, 1),
|
|
162
|
+
),
|
|
163
|
+
Step(
|
|
164
|
+
name="m013-C1 coordinator import 块",
|
|
165
|
+
relpath=coord,
|
|
166
|
+
is_done=lambda c: "\n isKnownSessionEventType,\n" in c,
|
|
167
|
+
check_baseline=lambda c: ANCHOR_COORD_IMPORT in c,
|
|
168
|
+
transform=lambda c: c.replace(ANCHOR_COORD_IMPORT, REPL_COORD_IMPORT, 1),
|
|
169
|
+
),
|
|
170
|
+
Step(
|
|
171
|
+
name="m013-C2 coordinator 拒绝点接线",
|
|
172
|
+
relpath=coord,
|
|
173
|
+
is_done=lambda c: REPL_COORD_GUARD in c,
|
|
174
|
+
check_baseline=lambda c: ANCHOR_COORD_GUARD in c,
|
|
175
|
+
transform=lambda c: c.replace(ANCHOR_COORD_GUARD, REPL_COORD_GUARD, 1),
|
|
176
|
+
),
|
|
177
|
+
Step(
|
|
178
|
+
name="guard-1 bin.ts home-paths import",
|
|
179
|
+
relpath=bin_ts,
|
|
180
|
+
is_done=lambda c: "@deepseek-ai/dsh-home-paths" in c,
|
|
181
|
+
check_baseline=lambda c: ANCHOR_ARGS_IMPORT in c and "from 'node:path'" not in c,
|
|
182
|
+
transform=lambda c: c.replace(ANCHOR_ARGS_IMPORT, ANCHOR_ARGS_IMPORT + "\n" + GUARD_IMPORTS, 1),
|
|
183
|
+
),
|
|
184
|
+
Step(
|
|
185
|
+
name="guard-2 bin.ts 守卫块",
|
|
186
|
+
relpath=bin_ts,
|
|
187
|
+
is_done=lambda c: "Meow fork guard" in c,
|
|
188
|
+
check_baseline=lambda c: ANCHOR_INVOCATION in c,
|
|
189
|
+
transform=lambda c: c.replace(ANCHOR_INVOCATION, ANCHOR_INVOCATION + GUARD_BLOCK, 1),
|
|
190
|
+
),
|
|
191
|
+
]
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def read_file(p: Path) -> str:
|
|
195
|
+
return p.read_bytes().decode("utf-8")
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def write_file(p: Path, content: str) -> None:
|
|
199
|
+
p.write_bytes(content.encode("utf-8"))
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def main() -> int:
|
|
203
|
+
args = [a for a in sys.argv[1:] if a != "--dry-run"]
|
|
204
|
+
dry_run = "--dry-run" in sys.argv
|
|
205
|
+
if len(args) != 1:
|
|
206
|
+
print(__doc__)
|
|
207
|
+
return 2
|
|
208
|
+
root = Path(args[0]).resolve()
|
|
209
|
+
if not (root / "package.json").exists():
|
|
210
|
+
print(f"[FAIL] {root} 不是快照根目录(缺 package.json)")
|
|
211
|
+
return 2
|
|
212
|
+
|
|
213
|
+
print(f"快照根目录: {root}")
|
|
214
|
+
print(f"补丁版本: {VERSION}" + (" [DRY-RUN 只预检不改]" if dry_run else ""))
|
|
215
|
+
print()
|
|
216
|
+
|
|
217
|
+
steps = build_steps(root)
|
|
218
|
+
|
|
219
|
+
# ── Phase 1: 预检(全部通过才动手) ──
|
|
220
|
+
plan: list[tuple[Step, str]] = [] # (step, content) content=变换前内容
|
|
221
|
+
fatal = False
|
|
222
|
+
for s in steps:
|
|
223
|
+
if s.is_new_file:
|
|
224
|
+
if s.relpath.exists():
|
|
225
|
+
content = read_file(s.relpath)
|
|
226
|
+
if s.is_done(content):
|
|
227
|
+
s.action = "SKIP"
|
|
228
|
+
else:
|
|
229
|
+
print(f"[FAIL] {s.relpath} 已存在但不含预期特征, 内容不明, 拒绝覆盖")
|
|
230
|
+
fatal = True
|
|
231
|
+
continue
|
|
232
|
+
else:
|
|
233
|
+
s.action = "APPLY"
|
|
234
|
+
plan.append((s, ""))
|
|
235
|
+
tag = " (新文件)" if s.is_new_file and s.action == "APPLY" else ""
|
|
236
|
+
print(f"[{'SKIP' if s.action == 'SKIP' else 'OK '}] 预检 {s.name}{tag}")
|
|
237
|
+
continue
|
|
238
|
+
|
|
239
|
+
if not s.relpath.exists():
|
|
240
|
+
print(f"[FAIL] 缺文件 {s.relpath}")
|
|
241
|
+
fatal = True
|
|
242
|
+
continue
|
|
243
|
+
content = read_file(s.relpath)
|
|
244
|
+
if s.is_done(content):
|
|
245
|
+
s.action = "SKIP"
|
|
246
|
+
elif s.check_baseline(content):
|
|
247
|
+
s.action = "APPLY"
|
|
248
|
+
plan.append((s, content))
|
|
249
|
+
else:
|
|
250
|
+
print(f"[FAIL] 基线不匹配 {s.relpath} (步骤 {s.name})")
|
|
251
|
+
print(" → 快照版本可能不是 " + VERSION + ", 或文件已被手动改动; 拒绝盲改")
|
|
252
|
+
fatal = True
|
|
253
|
+
continue
|
|
254
|
+
print(f"[{'SKIP' if s.action == 'SKIP' else 'OK '}] 预检 {s.name}")
|
|
255
|
+
|
|
256
|
+
if fatal:
|
|
257
|
+
print("\n预检未全部通过, 已放弃(未修改任何文件)。")
|
|
258
|
+
return 1
|
|
259
|
+
|
|
260
|
+
if not any(s.action == "APPLY" for s, _ in plan):
|
|
261
|
+
print("\n全部步骤均已应用过, 无需改动。")
|
|
262
|
+
return 0
|
|
263
|
+
|
|
264
|
+
# ── Phase 2: 应用(带备份) ──
|
|
265
|
+
if dry_run:
|
|
266
|
+
print(f"\n[DRY-RUN] 将应用 {sum(1 for s, _ in plan)} 处改动(未实际写入)。")
|
|
267
|
+
return 0
|
|
268
|
+
|
|
269
|
+
print()
|
|
270
|
+
touched = 0
|
|
271
|
+
for s, _ in plan:
|
|
272
|
+
if s.is_new_file:
|
|
273
|
+
write_file(s.relpath, s.transform(""))
|
|
274
|
+
else:
|
|
275
|
+
# 关键: 每步执行前重读磁盘当前内容 —— 同一文件有多个步骤时,
|
|
276
|
+
# 后一步必须在前一步的结果之上变换, 否则互相覆盖(实测踩过)
|
|
277
|
+
current = read_file(s.relpath)
|
|
278
|
+
backup = s.relpath.with_name(s.relpath.name + BACKUP_SUFFIX)
|
|
279
|
+
if not backup.exists(): # 备份只写一次, 保留最初原始版
|
|
280
|
+
backup.write_bytes(current.encode("utf-8"))
|
|
281
|
+
write_file(s.relpath, s.transform(current))
|
|
282
|
+
touched += 1
|
|
283
|
+
print(f"[DONE] {s.name} → {s.relpath.name}")
|
|
284
|
+
|
|
285
|
+
# ── Phase 3: 回读验证 ──
|
|
286
|
+
print()
|
|
287
|
+
bad = 0
|
|
288
|
+
for s, _ in plan:
|
|
289
|
+
if not s.relpath.exists():
|
|
290
|
+
continue
|
|
291
|
+
content = read_file(s.relpath)
|
|
292
|
+
if not s.is_done(content):
|
|
293
|
+
print(f"[FAIL] 回读验证未通过: {s.relpath} (步骤 {s.name})")
|
|
294
|
+
bad += 1
|
|
295
|
+
if bad:
|
|
296
|
+
print(f"\n{bad} 处验证失败! 备份在原文件旁 {BACKUP_SUFFIX}, 可手工比对恢复。")
|
|
297
|
+
return 1
|
|
298
|
+
|
|
299
|
+
print(f"✅ 全部完成: {sum(1 for s, _ in plan)} 处改动已应用并验证。")
|
|
300
|
+
print()
|
|
301
|
+
print("后续手动事项:")
|
|
302
|
+
print(" 1. 快照内 MEOW_MODIFICATIONS.md 条目索引补记本次改动(人工确认后)")
|
|
303
|
+
print(" 2. MEOW 条目 4 (tool-session-query 搜索排除) 按其 5 文件明细手动重放")
|
|
304
|
+
print(" 3. pnpm run verify-persistence-catalog (确认生成文件未被触碰)")
|
|
305
|
+
print(" 4. pnpm run build 全量构建 → start-meow.bat 重启 3081")
|
|
306
|
+
print(" 5. 验证: 打开一个含 femo-plugin/chat 的旧 Femo 会话, 历史应正常加载")
|
|
307
|
+
if touched:
|
|
308
|
+
print(f" 6. 备份位置: 原文件旁 *{BACKUP_SUFFIX} (回滚=改名还原)")
|
|
309
|
+
return 0
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
if __name__ == "__main__":
|
|
313
|
+
sys.exit(main())
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api-retry.ts — femo AI 演员的 API 请求错误慢层兜底(第二类错误,施工清单 v4 §2)。
|
|
3
|
+
*
|
|
4
|
+
* 官方 base bundle 已装配 dsh-llm-retry(请求层快层:≤5 次 500ms→10s 快速退避,
|
|
5
|
+
* base/cordis.patch.yml L84-85)。本模块注册在同一条 `agent/request-error`
|
|
6
|
+
* 瀑布的下游(base bundle 先装配 → 快层先消费;profile patch 插件晚装配 →
|
|
7
|
+
* 快层耗尽才落到这里):快层仍失败的 femo 演员请求(子代理 + main 在飞
|
|
8
|
+
* 回合)进入本慢层——五段退避重试(立即 / 20s / 1min / 3min / 10min),
|
|
9
|
+
* 第五段重试之后仍失败则放行(turn error → 既有 recordError/交卷路径 →
|
|
10
|
+
* 引擎"AI 沉默"move on = 节点按结束)。compiler 全程无感。
|
|
11
|
+
*
|
|
12
|
+
* 计数口径(P1 已裁决:连续计数·成功清零):按 childSessionId 记录
|
|
13
|
+
* (turn, step) 连续失败序列——新失败与上次记录的 (turn,step) 不同(=中间有
|
|
14
|
+
* step 成功推进)→ 计数重置 1;相同 → +1。零跨模块钩子(handler 自足,
|
|
15
|
+
* subagent/main 统一处理)——多轮 react 各 step 的偶发失败各自享"立即重试",
|
|
16
|
+
* 长退避只在持续故障时发生。
|
|
17
|
+
*
|
|
18
|
+
* 永久性错误码不重试(P3):NO_ADAPTER / INVALID_CREDENTIAL / MISSING_CREDENTIAL /
|
|
19
|
+
* QUOTA / CONTEXT_WINDOW_EXCEEDED 等重试恒同败,立即放行(白等 14 分钟无意义)。
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
23
|
+
|
|
24
|
+
/** 一次慢层重试的作用对象(v4 §2)。 */
|
|
25
|
+
export interface ActorTarget {
|
|
26
|
+
kind: 'subagent' | 'main'
|
|
27
|
+
/** 主会话 id(通知/错误表定位)。 */
|
|
28
|
+
mainSessionId: string
|
|
29
|
+
/** 触发失败的 agent 会话 id(子代理 = run.id;main = 主会话 id)。 */
|
|
30
|
+
childSessionId: string
|
|
31
|
+
/** 引擎节点 id。 */
|
|
32
|
+
node: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 归一化后的失败事实(从 LlmFailure 取路由需要的两个字段)。 */
|
|
36
|
+
export interface ApiRetryFailure {
|
|
37
|
+
code: string
|
|
38
|
+
message: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ApiRetryDeps {
|
|
42
|
+
/** filter:childId → 演员 target;未命中(导演轮次/用户聊天/陌生 agent/已收尾)→ undefined 透传。 */
|
|
43
|
+
resolveTarget(childSessionId: string): ActorTarget | undefined
|
|
44
|
+
/** 每次慢层重试排程后的通知(投影窗 ⏳ / main 走 console.log,装配处实现)。 */
|
|
45
|
+
onRetry(target: ActorTarget, attempt: number, delayMs: number, failure: ApiRetryFailure): void
|
|
46
|
+
/** 连续第 5 次失败:放行前通知(recordError + 投影窗 ❌,装配处实现)。 */
|
|
47
|
+
onExhausted(target: ActorTarget, failure: ApiRetryFailure): void
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 可重试错误码:与官方 llm-retry 快层五码一致。永久码(NO_ADAPTER 等)在
|
|
51
|
+
* 快层就被放行根本到不了这里;此处再过滤一遍是防御装配顺序变化。 */
|
|
52
|
+
const RETRYABLE_CODES: ReadonlySet<string> = new Set([
|
|
53
|
+
'RATE_LIMIT', 'SERVER', 'TIMEOUT', 'TRANSPORT', 'EMPTY_RESPONSE',
|
|
54
|
+
])
|
|
55
|
+
|
|
56
|
+
/** 五段慢层退避(协议常量,猫猫纲领):立即 / 20s / 1min / 3min / 10min。 */
|
|
57
|
+
const SLOW_DELAYS_MS: readonly number[] = [0, 20_000, 60_000, 180_000, 600_000]
|
|
58
|
+
|
|
59
|
+
/** 连续失败上限:第五次慢层重试(10min 段)之后仍失败 → 放行。没有第六次。 */
|
|
60
|
+
const MAX_CONSECUTIVE_FAILURES = 5
|
|
61
|
+
|
|
62
|
+
/** 同一 childId 的连续失败记录:(turn,step) 相同 = 同一步骤连续败。 */
|
|
63
|
+
interface AttemptRecord {
|
|
64
|
+
turn: number
|
|
65
|
+
step: number
|
|
66
|
+
count: number
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class ApiRetryChain {
|
|
70
|
+
private readonly attempts = new Map<string, AttemptRecord>()
|
|
71
|
+
private readonly lifetime = new AbortController()
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 注册 `agent/request-error` 瀑布下游 listener。返回 disposer(HMR 安全:
|
|
75
|
+
* 移除 listener + 中止在飞延迟 + 清计数)。
|
|
76
|
+
*/
|
|
77
|
+
install(ctx: Context, deps: ApiRetryDeps): () => void {
|
|
78
|
+
const disposeListener = ctx.on('agent/request-error', async (payload, next) => {
|
|
79
|
+
const childId = String(payload.agent.session.id)
|
|
80
|
+
// 1. filter 未命中 → 透传(dsh 默认零变——零影响关键)。顺带清掉已收尾
|
|
81
|
+
// agent 的计数残留(孤儿防泄漏:登记表已删 = 该 agent 不再归我们管)。
|
|
82
|
+
const target = deps.resolveTarget(childId)
|
|
83
|
+
if (target === undefined) {
|
|
84
|
+
this.attempts.delete(childId)
|
|
85
|
+
return next()
|
|
86
|
+
}
|
|
87
|
+
// 2. turn 已中止(用户停止剧本)→ 不再排程重试,交还上游收尾。
|
|
88
|
+
if (payload.signal.aborted) return next()
|
|
89
|
+
const failure: ApiRetryFailure = { code: payload.failure.code, message: payload.failure.message }
|
|
90
|
+
// 3. 永久性错误码(P3):重试恒同败,立即放行。
|
|
91
|
+
if (!RETRYABLE_CODES.has(failure.code)) return next()
|
|
92
|
+
// 4. (turn,step) 连续计数(P1):新 (turn,step) = 中间有成功推进 → 重置 1。
|
|
93
|
+
const previous = this.attempts.get(childId)
|
|
94
|
+
const count = previous !== undefined
|
|
95
|
+
&& previous.turn === payload.turn && previous.step === payload.step
|
|
96
|
+
? previous.count + 1
|
|
97
|
+
: 1
|
|
98
|
+
if (count > MAX_CONSECUTIVE_FAILURES) {
|
|
99
|
+
// 第五段(10min)重试之后仍失败:放行 = turn error = 既有 recordError/
|
|
100
|
+
// 交卷路径 = 节点按结束(compiler 无感)。
|
|
101
|
+
this.attempts.delete(childId)
|
|
102
|
+
deps.onExhausted(target, failure)
|
|
103
|
+
return next()
|
|
104
|
+
}
|
|
105
|
+
this.attempts.set(childId, { turn: payload.turn, step: payload.step, count })
|
|
106
|
+
const delayMs = SLOW_DELAYS_MS[count - 1] ?? 0
|
|
107
|
+
deps.onRetry(target, count, delayMs, failure)
|
|
108
|
+
// 5. 可取消延迟:turn abort / 插件 dispose 都能秒级打断,不占着瀑布。
|
|
109
|
+
const fused = AbortSignal.any([payload.signal, this.lifetime.signal])
|
|
110
|
+
if (fused.aborted) return undefined
|
|
111
|
+
const completed = await new Promise<boolean>((resolve) => {
|
|
112
|
+
const timer = setTimeout(() => {
|
|
113
|
+
fused.removeEventListener('abort', onAbort)
|
|
114
|
+
resolve(true)
|
|
115
|
+
}, delayMs)
|
|
116
|
+
function onAbort(): void {
|
|
117
|
+
clearTimeout(timer)
|
|
118
|
+
resolve(false)
|
|
119
|
+
}
|
|
120
|
+
fused.addEventListener('abort', onAbort, { once: true })
|
|
121
|
+
})
|
|
122
|
+
if (!completed) return undefined
|
|
123
|
+
// 6. 同 turn 同 step、同一 durable history 原地重跑(官方 request-error 语义)。
|
|
124
|
+
return { kind: 'retry' }
|
|
125
|
+
})
|
|
126
|
+
return () => {
|
|
127
|
+
disposeListener()
|
|
128
|
+
this.lifetime.abort(new Error('femo-plugin api-retry chain disposed'))
|
|
129
|
+
this.attempts.clear()
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** 显式清某个 child 的失败计数(子代理/main 收尾路径可调用;幂等)。 */
|
|
134
|
+
clearChild(childSessionId: string): void {
|
|
135
|
+
this.attempts.delete(childSessionId)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** 插件级单例:index.ts 装配 install 与 subagent.ts finally 的 clearChild
|
|
140
|
+
* 共用同一实例(模块级常量风格,与 node-retry broker 一致)。 */
|
|
141
|
+
export const apiRetry = new ApiRetryChain()
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bridge.ts — Femo bridge client(与 Python 引擎通话的电话线)。
|
|
3
|
+
*
|
|
4
|
+
* 管理 femo_bridge.py 子进程:NDJSON over stdio 的请求/响应配对,引擎事件
|
|
5
|
+
* 以 (name='femo-plugin/event', eventType, data) 形式 re-emit——emit 由 index.ts
|
|
6
|
+
* 总装时注入为 ctx.emit(FemoBridge 自身不依赖事件总线)。
|
|
7
|
+
* 从 index.ts 原样迁出(2026-08-23 重构)。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
11
|
+
import type { SubprocessHandle } from '@deepseek-ai/dsh-subprocess'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
import { pushDiag } from './diag-feed'
|
|
14
|
+
|
|
15
|
+
interface PendingRequest {
|
|
16
|
+
resolve(value: unknown): void
|
|
17
|
+
reject(error: Error): void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class FemoBridge {
|
|
21
|
+
private handle: SubprocessHandle | undefined
|
|
22
|
+
private readonly pending = new Map<number, PendingRequest>()
|
|
23
|
+
private nextId = 1
|
|
24
|
+
private lineBuf = ''
|
|
25
|
+
|
|
26
|
+
/** 进程退出回调(index.ts 接线):引擎半路死亡时不会有任何终止事件
|
|
27
|
+
* (flow_done/flow_paused),宿主 runState.running 会卡 true——在这里
|
|
28
|
+
* 让总装层清理孤儿运行态(2026-08-24)。 */
|
|
29
|
+
onExited?: (outcome: unknown) => void
|
|
30
|
+
|
|
31
|
+
get alive(): boolean {
|
|
32
|
+
return this.handle !== undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Spawn the bridge and wire stdout line parsing. */
|
|
36
|
+
start(ctx: Context, config: { python: string; femoRoot: string; hostManifest: string }, attempt = 0): void {
|
|
37
|
+
if (this.handle !== undefined) return
|
|
38
|
+
const subprocess = ctx.get('subprocess') as {
|
|
39
|
+
resolveExecutable(command: string, env?: Record<string, string>, signal?: AbortSignal): Promise<string>
|
|
40
|
+
spawn(spec: unknown): SubprocessHandle
|
|
41
|
+
} | undefined
|
|
42
|
+
if (subprocess === undefined) {
|
|
43
|
+
// 插件树并发装配:本插件 apply 可能先于 base bundle 的 subprocess
|
|
44
|
+
// provider 完成(rc.2 快照插件更多、apply 更慢,固定 1s 延迟不再够)。
|
|
45
|
+
// 轮询等待而不是一次性放弃——最多 30s。
|
|
46
|
+
if (attempt < 30) {
|
|
47
|
+
setTimeout(() => this.start(ctx, config, attempt + 1), 1000)
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
console.log('[femo-plugin] subprocess service unavailable after 30s; bridge not started')
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
if (attempt > 0) console.log(`[femo-plugin] subprocess service ready after ${attempt}s wait; starting bridge`)
|
|
54
|
+
// Bridge lives inside the Femo project itself (self-contained plugin):
|
|
55
|
+
// <femoRoot>/python/femo_bridge.py
|
|
56
|
+
const bridgePath = join(config.femoRoot, 'hostAdapter', 'dshAdapter', 'python', 'femo_bridge.py')
|
|
57
|
+
// 宿主能力清单(A2.1 解耦):harness 的词汇与环境(thinking 档位/默认用户)
|
|
58
|
+
// 由接口侧这份文件提供,引擎启动时读取——换 harness 换文件,引擎零改动。
|
|
59
|
+
// 文件缺失时引擎用内置缺省(standalone 自圆满)。清单随插件根(适配器本地,
|
|
60
|
+
// 2026-09-13 插件根下沉后由 config.hostManifest 给出)。
|
|
61
|
+
const hostManifestPath = config.hostManifest
|
|
62
|
+
void subprocess.resolveExecutable(config.python).then((pythonPath) => {
|
|
63
|
+
const handle = subprocess.spawn({
|
|
64
|
+
argv: [pythonPath, bridgePath, '--fe4m', config.femoRoot, '--host-manifest', hostManifestPath],
|
|
65
|
+
cwd: config.femoRoot,
|
|
66
|
+
stdio: {
|
|
67
|
+
stdin: 'pipe',
|
|
68
|
+
stdout: 'pipe',
|
|
69
|
+
// 'pipe' (not collect): the caller owns the stream and forwards
|
|
70
|
+
// tracebacks live; a collect buffer would swallow them silently.
|
|
71
|
+
stderr: 'pipe',
|
|
72
|
+
},
|
|
73
|
+
graceMs: 3000,
|
|
74
|
+
env: { PYTHONIOENCODING: 'utf-8', PYTHONUTF8: '1' },
|
|
75
|
+
})
|
|
76
|
+
this.handle = handle
|
|
77
|
+
handle.stdout?.on('data', (chunk: Buffer) => this.onData(chunk))
|
|
78
|
+
// Bridge stderr (Python tracebacks) must not vanish: forward every line.
|
|
79
|
+
handle.stderr?.on('data', (chunk: Buffer) => {
|
|
80
|
+
const text = chunk.toString('utf8')
|
|
81
|
+
for (const line of text.split(/\r?\n/)) {
|
|
82
|
+
if (line.trim().length === 0) continue
|
|
83
|
+
// 【2026-09-11 编译器页补 stderr】引擎 stderr(Python traceback 之类)
|
|
84
|
+
// 进调试窗『编译器』页,`[stderr] ` 前缀与 stdout 原文区分。
|
|
85
|
+
pushDiag('engine', `[stderr] ${line}`.slice(0, 400))
|
|
86
|
+
// 【2026-09-11 Host 页口径】引擎侧透传绕过 console 直写 stdout:
|
|
87
|
+
// 这是"引擎的话"不是"DSH 接口侧的话",不进『Host』页;
|
|
88
|
+
// harness 日志照旧收得到,一个字没少。
|
|
89
|
+
process.stdout.write(`[femo-engine:stderr] ${line}\n`)
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
handle.done.then((outcome) => {
|
|
93
|
+
console.log(`[femo-plugin] bridge exited: code=${outcome.exitCode} signal=${outcome.signal}`)
|
|
94
|
+
for (const [, pending] of this.pending) {
|
|
95
|
+
pending.reject(new Error(`bridge exited (code=${outcome.exitCode})`))
|
|
96
|
+
}
|
|
97
|
+
this.pending.clear()
|
|
98
|
+
this.handle = undefined
|
|
99
|
+
try { this.onExited?.(outcome) } catch (error: unknown) {
|
|
100
|
+
console.log(`[femo-plugin] onExited callback failed: ${String(error)}`)
|
|
101
|
+
}
|
|
102
|
+
}, (error: unknown) => {
|
|
103
|
+
console.log(`[femo-plugin] bridge spawn failed: ${String(error)}`)
|
|
104
|
+
this.handle = undefined
|
|
105
|
+
})
|
|
106
|
+
console.log(`[femo-plugin] bridge started (pid=${handle.pid})`)
|
|
107
|
+
}, (error: unknown) => {
|
|
108
|
+
console.log(`[femo-plugin] python resolve failed: ${String(error)}`)
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Send one command; resolves with the bridge's response result. */
|
|
113
|
+
send(cmd: string, args: Record<string, unknown> = {}, timeoutMs = 15_000): Promise<unknown> {
|
|
114
|
+
const handle = this.handle
|
|
115
|
+
if (handle === undefined) return Promise.reject(new Error('bridge not running'))
|
|
116
|
+
const id = this.nextId++
|
|
117
|
+
const payload = `${JSON.stringify({ id, cmd, args })}\n`
|
|
118
|
+
return new Promise<unknown>((resolve, reject) => {
|
|
119
|
+
const timer = setTimeout(() => {
|
|
120
|
+
this.pending.delete(id)
|
|
121
|
+
reject(new Error(`bridge command "${cmd}" timed out`))
|
|
122
|
+
}, timeoutMs)
|
|
123
|
+
this.pending.set(id, {
|
|
124
|
+
resolve: (value) => { clearTimeout(timer); resolve(value) },
|
|
125
|
+
reject: (error) => { clearTimeout(timer); reject(error) },
|
|
126
|
+
})
|
|
127
|
+
handle.stdin?.write(payload, (error?: Error | null) => {
|
|
128
|
+
if (error !== undefined && error !== null) {
|
|
129
|
+
this.pending.delete(id)
|
|
130
|
+
clearTimeout(timer)
|
|
131
|
+
reject(error)
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Terminate the bridge process tree (graceful shutdown command first). */
|
|
138
|
+
async stop(): Promise<void> {
|
|
139
|
+
const handle = this.handle
|
|
140
|
+
if (handle === undefined) return
|
|
141
|
+
try {
|
|
142
|
+
await this.send('shutdown', {}, 2000)
|
|
143
|
+
} catch {
|
|
144
|
+
// fall through to terminate
|
|
145
|
+
}
|
|
146
|
+
handle.terminate()
|
|
147
|
+
await handle.waitForExit()
|
|
148
|
+
this.handle = undefined
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private onData(chunk: Buffer): void {
|
|
152
|
+
this.lineBuf += chunk.toString('utf8')
|
|
153
|
+
let idx: number
|
|
154
|
+
while ((idx = this.lineBuf.indexOf('\n')) !== -1) {
|
|
155
|
+
const line = this.lineBuf.slice(0, idx).trim()
|
|
156
|
+
this.lineBuf = this.lineBuf.slice(idx + 1)
|
|
157
|
+
if (line.length === 0) continue
|
|
158
|
+
// Femo's own prints share stdout; only JSON protocol lines parse.
|
|
159
|
+
// Engine prints (the engine's debugging voice) are forwarded so the
|
|
160
|
+
// harness log can see what the engine saw — they used to be dropped.
|
|
161
|
+
if (!line.startsWith('{')) {
|
|
162
|
+
// 【诊断 2026-09-06】撕裂嫌疑:NDJSON 事件行若被引擎 print 的并发
|
|
163
|
+
// write 粘包/撕裂,首字符不再是 '{' 且行内必含 JSON 事件字段——
|
|
164
|
+
// 此类行是"human_wait 事件在管道中丢失"假设的直接证据。
|
|
165
|
+
if (line.includes('"type"') || line.includes('job_id')) {
|
|
166
|
+
pushDiag('bridge', `TORN_LINE_SUSPECT: ${line.slice(0, 300)}`)
|
|
167
|
+
}
|
|
168
|
+
// 【2026-09-11 调试窗「编译器」页】引擎 print 全量进诊断面(tag 'engine'):
|
|
169
|
+
// 此前只放行 [resume-diag]/[resume]/[FORK] 三类探针行,其余 print 仅落
|
|
170
|
+
// harness console——femoGen 看不到编译器在说什么。现在全部转发。
|
|
171
|
+
// 截断 400 字符:引擎偶有把整个 payload 打出来的行,不能让一条撑爆面板。
|
|
172
|
+
pushDiag('engine', line.slice(0, 400))
|
|
173
|
+
// 【2026-09-11 Host 页口径】引擎 stdout 原文绕过 console 直写
|
|
174
|
+
// stdout——它的家在『编译器』页(上一条 pushDiag),不进『Host』页。
|
|
175
|
+
process.stdout.write(`[femo-engine] ${line}\n`)
|
|
176
|
+
continue
|
|
177
|
+
}
|
|
178
|
+
let msg: {
|
|
179
|
+
type?: string; id?: number; ok?: boolean; result?: unknown; error?: unknown
|
|
180
|
+
detail?: unknown
|
|
181
|
+
event?: string; data?: unknown
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
msg = JSON.parse(line) as typeof msg
|
|
185
|
+
} catch {
|
|
186
|
+
// 【诊断 2026-09-06】解析失败=行被撕裂的另一半实锤(首字符是 '{'
|
|
187
|
+
// 但尾部粘了别的 write 或被截断)——原样静默 continue 会丢事件无痕。
|
|
188
|
+
pushDiag('bridge', `JSON_PARSE_FAIL: ${line.slice(0, 300)}`)
|
|
189
|
+
continue
|
|
190
|
+
}
|
|
191
|
+
if (msg.type === 'response') {
|
|
192
|
+
const rid = msg.id
|
|
193
|
+
if (rid === undefined) continue
|
|
194
|
+
const pending = this.pending.get(rid)
|
|
195
|
+
if (pending === undefined) continue
|
|
196
|
+
this.pending.delete(rid)
|
|
197
|
+
if (msg.ok === true) pending.resolve(msg.result)
|
|
198
|
+
// 错误形态(Job 模型 §7.2):{ok:false, error:<code>, detail:<人话>}——
|
|
199
|
+
// detail 优先(六关裁决原话上浮给 AI/前端,B2),旧形态无 detail 回退
|
|
200
|
+
// error code。
|
|
201
|
+
else pending.reject(new Error(String(msg.detail ?? msg.error ?? 'bridge error')))
|
|
202
|
+
} else if (msg.type === 'event') {
|
|
203
|
+
// 【诊断 2026-09-06】管道层收到事件=链路第一实证点(对照 engine-events
|
|
204
|
+
// 入口的 ev-in 记录,两者之间即丢失区间)。
|
|
205
|
+
pushDiag('bridge', `event ${String(msg.event)} job=${String((msg.data as Record<string, unknown> | undefined)?.job_id ?? '-')}`)
|
|
206
|
+
;(this as unknown as { emit(name: string, ...args: unknown[]): void }).emit('femo-plugin/event', msg.event, msg.data)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** 宿主执行体最终失败信号(B5):执行者死亡/超时/API 预算耗尽——显式上报,
|
|
213
|
+
* 引擎按「沉默收场」裁决(通知作者 + 节点按失败跳过 + 剧本继续)。宿主不再
|
|
214
|
+
* 伪装空台词(output:'' 会让引擎错误体系全程失明:不通知、不留失败痕迹)。 */
|
|
215
|
+
export async function sendActorFailure(
|
|
216
|
+
bridge: FemoBridge, jobId: number, waitKey: string, kind: string, detail: string,
|
|
217
|
+
): Promise<void> {
|
|
218
|
+
await bridge.send('actor_failed', {
|
|
219
|
+
job_id: jobId,
|
|
220
|
+
wait_key: waitKey,
|
|
221
|
+
kind,
|
|
222
|
+
detail: detail.slice(0, 500),
|
|
223
|
+
}, 10_000)
|
|
224
|
+
}
|