femo-plugin 1.0.0 → 1.0.2
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/FEMO_logo.svg +55 -0
- package/FEMO_logo_slogan.svg +29 -0
- package/README.md +10 -2
- package/_tmp/fallback/driver2.py +176 -0
- package/_tmp/fallback/events.jsonl +108 -0
- package/_tmp/fallback/gateway_ui.py +325 -0
- package/_tmp/fallback/outbox/j1553_human_[/347/234/213/347/211/214]_1.done +1 -0
- package/_tmp/fallback/outbox/r1.done +1 -0
- package/_tmp/fallback/outbox/r2.done +1 -0
- package/_tmp/fallback/outbox/r3.done +1 -0
- package/_tmp/fallback/outbox/r4.done +1 -0
- package/_tmp/fallback/outbox/r5.done +1 -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 +3 -2
- package/hostAdapter/dshAdapter/client/client-ui/composer.tsx +112 -9
- package/hostAdapter/dshAdapter/client/client-ui/styles.ts +17 -0
- package/hostAdapter/dshAdapter/client/fa-icons.tsx +3 -0
- package/hostAdapter/dshAdapter/host/engine-events.ts +4 -1
- package/hostAdapter/dshAdapter/host/index.ts +5 -0
- package/hostAdapter/dshAdapter/host/preset-install.ts +59 -0
- package/hostAdapter/dshAdapter/host/projection-input.ts +14 -6
- package/hostAdapter/dshAdapter/lib/client.js +124 -5
- package/hostAdapter/dshAdapter/lib/client.js.map +3 -3
- package/hostAdapter/dshAdapter/lib/index.js +58 -18
- package/hostAdapter/dshAdapter/lib/index.js.map +4 -4
- package/hostAdapter/dshAdapter/package.json +1 -5
- package/hostAdapter/dshAdapter/preset/agent.cordis.yml +220 -0
- package/hostAdapter/dshAdapter/preset/preset.yml +3 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/gateway.port +1 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-a-_40_52a9_624b.jsonl +3 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-a-_40_6211.jsonl +10 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-god.jsonl +11 -0
- package/hostAdapter/zcodeAdapter/.tmp/femo/host-history/proj-mirror/femo-main-stage.jsonl +11 -0
- package/hostAdapter/zcodeAdapter/.zcode-plugin/plugin.json +23 -0
- package/hostAdapter/zcodeAdapter/README.md +61 -0
- package/hostAdapter/zcodeAdapter/commands/femo.md +9 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/.zcode-plugin/plugin.json +23 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/LICENSE +201 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/README.md +635 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/commands/femo.md +9 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/__init__.py +4 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/chronica.py +156 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/femo-chat.mjs +69 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femoToolcall/femo_debugger.py +1515 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femo_api.py +437 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femo2host/femo_gen_api.jsx +77 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/ContextExample.py +555 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/MemoryExample.py +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/__init__.py +1 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/getDir/get_dir.py +56 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/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/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/llmBridge.py +247 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoBridges/llmProviders.py +308 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_CLIrenderer.py +198 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_config.py +35 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_errors.py +278 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_interpreter.py +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_normalizer.py +396 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_parser.py +2468 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_runtime.py +3630 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/FEMO_scope_resolver.py +209 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/__init__.py +1 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/actor_resolver.py +86 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/block_collector.py +441 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/db_utils.py +485 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/femoAsync.py +401 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/host_manifest.py +68 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/job_manager.py +767 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/protocol.py +126 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/save_dialog.py +402 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/task_world.py +544 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/__init__.py +19 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/checkpoint.py +113 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/env.py +686 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/evaluator.py +567 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/join.py +303 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/merge.py +157 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoCompiler/vars/model.py +245 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/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/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/350/201/212/345/244/251/345/256/244/group-chat.femo +42 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/AI/350/201/212/345/244/251/345/256/244/random_wait_time.py +10 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/LuxFiat/luxfiat.femo +38 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/LuxFiat/wait.py +29 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/debug/347/245/236/345/231/250/debug/347/245/236/345/231/250.femo +222 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/discussion.femo +70 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples/goal-mode.femo +23 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//345/270/270/347/224/250/345/267/245/345/205/267python/wait.py +29 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils.py +205 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200/werewolf_utils2.py +324 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/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/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//347/213/274/344/272/272/346/235/200//347/213/274/344/272/272/346/235/200.femo +331 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/femoExamples//350/260/201/346/230/257/345/215/247/345/272/225/undercover_utils.py +683 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/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/hostAdapter/zcodeAdapter/femo-zcode-dist/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 +393 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/after-tool.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/hooks.json +16 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/lib.mjs +59 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/prompt-state.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/session-start.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hooks/stop-intent.mjs +3 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hostAdapter/dshAdapter/python/dev-bridge-test.py +43 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/hostAdapter/dshAdapter/python/femo_bridge.py +533 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/bridge-manager.mjs +192 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/event-router.mjs +258 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/femo-server.mjs +429 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/gateway.mjs +163 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/mcp/projection-writer.mjs +294 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/skills/femo/SKILL.md +93 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/bridge-smoke.mjs +26 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/event-router.test.mjs +157 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/gateway-smoke.mjs +107 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/integration-human.mjs +111 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/main-actor.mjs +107 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/mcp-smoke.mjs +130 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/tests/projection-writer.test.mjs +144 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist/zcode.host.manifest.json +5 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist//346/212/225/345/275/261/347/252/227/351/207/215/350/256/276/350/256/241-/350/256/250/350/256/272/347/250/277.md +113 -0
- package/hostAdapter/zcodeAdapter/femo-zcode-dist//350/257/255/346/263/225/346/226/207/346/241/243.md +1136 -0
- package/hostAdapter/zcodeAdapter/hooks/after-tool.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/hooks.json +16 -0
- package/hostAdapter/zcodeAdapter/hooks/lib.mjs +59 -0
- package/hostAdapter/zcodeAdapter/hooks/prompt-state.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/session-start.mjs +3 -0
- package/hostAdapter/zcodeAdapter/hooks/stop-intent.mjs +3 -0
- package/hostAdapter/zcodeAdapter/mcp/bridge-manager.mjs +192 -0
- package/hostAdapter/zcodeAdapter/mcp/event-router.mjs +258 -0
- package/hostAdapter/zcodeAdapter/mcp/femo-server.mjs +429 -0
- package/hostAdapter/zcodeAdapter/mcp/gateway.mjs +163 -0
- package/hostAdapter/zcodeAdapter/mcp/projection-writer.mjs +294 -0
- package/hostAdapter/zcodeAdapter/skills/femo/SKILL.md +93 -0
- package/hostAdapter/zcodeAdapter/tests/bridge-smoke.mjs +26 -0
- package/hostAdapter/zcodeAdapter/tests/event-router.test.mjs +157 -0
- package/hostAdapter/zcodeAdapter/tests/gateway-smoke.mjs +107 -0
- package/hostAdapter/zcodeAdapter/tests/integration-human.mjs +111 -0
- package/hostAdapter/zcodeAdapter/tests/main-actor.mjs +107 -0
- package/hostAdapter/zcodeAdapter/tests/mcp-smoke.mjs +130 -0
- package/hostAdapter/zcodeAdapter/tests/projection-writer.test.mjs +144 -0
- package/hostAdapter/zcodeAdapter/zcode.host.manifest.json +5 -0
- package/hostAdapter/zcodeAdapter//346/212/225/345/275/261/347/252/227/351/207/215/350/256/276/350/256/241-/350/256/250/350/256/272/347/250/277.md +113 -0
- package/package.json +1 -1
- package/scripts/diag-find-redblue.mjs +38 -0
- package/scripts/diag-god-log.mjs +31 -0
- package/scripts/diag-god-log2.mjs +39 -0
- package/scripts/diag-god-log3.mjs +35 -0
- package/scripts/diag-god-log4.mjs +59 -0
- package/scripts/diag-god-log4b.mjs +39 -0
- package/scripts/diag-redblue-god.mjs +39 -0
- package/scripts/diag-redblue-log.mjs +37 -0
- package/scripts/diag-redblue-span.mjs +41 -0
- package/scripts/diag-stage-1017.mjs +63 -0
- package/scripts/dump_session.py +36 -0
- package/scripts/link-workspace.ps1 +51 -0
- package/scripts/list_souls.py +18 -0
- package/scripts/probe-composer-refresh.mjs +197 -0
- package/scripts/seed_story_souls.py +86 -0
- package/scripts/sync-zcode-dist.ps1 +55 -0
- package/scripts/theme-tokenize/color-extract.txt +288 -0
- package/scripts/theme-tokenize/round1-quoted.ps1 +149 -0
- package/scripts/theme-tokenize/round2-bare.ps1 +138 -0
- package/scripts/theme-tokenize/round3-shape.ps1 +110 -0
- package/tests/_diag_r4_join.femo +32 -0
- package/tests/conftest.py +95 -0
- package/tests/diag-subagent-dir-3081.mjs +101 -0
- package/tests/femoGenerator.test.mjs +3909 -0
- package/tests/femoParser.test.mjs +4813 -0
- package/tests/femogen_notice.test.mjs +109 -0
- package/tests/femoparser_validation.test.mjs +84 -0
- package/tests/main-delivery-queue.test.mjs +329 -0
- package/tests/pre-step-gate.test.mjs +282 -0
- package/tests/read-subagent-model.mjs +24 -0
- package/tests/run-script-tests.py +97 -0
- package/tests/safe-steer.test.mjs +59 -0
- package/tests/strip_comments.test.mjs +164 -0
- package/tests/test_actor_failed.py +92 -0
- package/tests/test_compile_warnings.py +99 -0
- package/tests/test_debug_log_bus.py +108 -0
- package/tests/test_debugger_module_mode.py +141 -0
- package/tests/test_error_buckets.py +117 -0
- package/tests/test_error_dispatcher.py +261 -0
- package/tests/test_exec_ai_retry.py +155 -0
- package/tests/test_exec_human_retry.py +159 -0
- package/tests/test_file_resolve.py +104 -0
- package/tests/test_flow_events.py +311 -0
- package/tests/test_flow_ref_validation.py +92 -0
- package/tests/test_func_dict_fallback.py +39 -0
- package/tests/test_job_lifecycle.py +236 -0
- package/tests/test_job_manager.py +424 -0
- package/tests/test_mind.py +99 -0
- package/tests/test_module_call_args.py +258 -0
- package/tests/test_module_visibility.py +238 -0
- package/tests/test_notice.py +143 -0
- package/tests/test_out_whitelist.py +83 -0
- package/tests/test_par_if_dispatch.py +64 -0
- package/tests/test_par_nested_for.py +78 -0
- package/tests/test_parser.py +494 -0
- package/tests/test_pause.py +102 -0
- package/tests/test_pause_contract.py +135 -0
- package/tests/test_protocol_transcript.py +158 -0
- package/tests/test_scope_self.py +202 -0
- package/tests/test_source_validate.py +113 -0
- package/tests/test_task_world.py +447 -0
- package/tests/test_town_structure.py +70 -0
- package/tests/test_v2_checkpoint.py +115 -0
- package/tests/test_v2_env.py +383 -0
- package/tests/test_v2_evaluator.py +227 -0
- package/tests/test_v2_join.py +315 -0
- package/tests/test_v2_join_wiring.py +429 -0
- package/tests/test_v2_merge.py +167 -0
- package/tests/test_v2_model.py +143 -0
- package/tests/test_v2_resume_e2e.py +472 -0
- package/tests/test_var_decls.py +271 -0
- package/tests/verify-model-functions.mjs +90 -0
- package/tests/verify-subagent-model-3081.mjs +153 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225/node-notice-/346/226/275/345/267/245/346/270/205/345/215/225.md +395 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//344/270/244/344/270/252/345/276/205/350/247/243/345/206/263/347/232/204/351/227/256/351/242/230.MD +66 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//345/201/234/346/255/242/351/223/276/344/277/256/345/244/215-/346/226/275/345/267/245/346/270/205/345/215/225.md +475 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//345/217/230/351/207/217/344/270/216task/347/263/273/347/273/237/351/207/215/346/236/204-/346/226/275/345/267/245/346/270/205/345/215/225-v2.md +847 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//350/277/220/350/241/214/347/212/266/346/200/201/351/223/276/350/267/257/351/207/215/346/236/204-/346/226/275/345/267/245/346/270/205/345/215/225v4.md +654 -0
- package//346/226/275/345/267/245/346/270/205/345/215/225//351/224/231/350/257/257/346/263/250/345/205/245/347/273/255/350/201/212-/346/226/275/345/267/245/346/270/205/345/215/225.md +471 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""AI 赋值 out 白名单校验测试(2026-08-18 用户需求:防 AI 幻觉乱赋值)。
|
|
2
|
+
|
|
3
|
+
用户原话:"要写out的,必须写out。为了防止ai幻觉乱赋值"。
|
|
4
|
+
实现:_extract_ai_assignments 加 out_whitelist 参数——赋值变量不在 out 声明范围
|
|
5
|
+
→ FEMOVariableError → assign_errors(走"不保存+反馈重试"通道,不直接炸)。
|
|
6
|
+
|
|
7
|
+
R2 适配(2026-09-05):变量操作改走 VarFacade(VarManager 退役)——测试假体
|
|
8
|
+
从 FakeVM 换成 FakeFacade + task_ctx 绑定。
|
|
9
|
+
"""
|
|
10
|
+
import pytest
|
|
11
|
+
from types import SimpleNamespace
|
|
12
|
+
|
|
13
|
+
from femoCompiler.FEMO_runtime import FEMORunner, FEMOVariableError
|
|
14
|
+
from femoCompiler.task_world import TaskContext, task_ctx
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def make_runner():
|
|
18
|
+
"""裸构造 FEMORunner(不跑 __init__):白名单拦截路径只用到
|
|
19
|
+
_parse_single_assignment + evaluator/facade 假体,不触 LLM。"""
|
|
20
|
+
rt = FEMORunner.__new__(FEMORunner)
|
|
21
|
+
rt.evaluator = SimpleNamespace(evaluate=lambda v, f, strict=False: v)
|
|
22
|
+
return rt
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class FakeFacade:
|
|
26
|
+
"""facade 假体:has 恒 True(声明放行)、apply_intent 记录调用,
|
|
27
|
+
fail_on_set 时模拟"未声明"报错(走 assign_errors 通道)。"""
|
|
28
|
+
def __init__(self, fail_on_apply=False):
|
|
29
|
+
self.calls = []
|
|
30
|
+
self.fail_on_apply = fail_on_apply
|
|
31
|
+
|
|
32
|
+
def has(self, name):
|
|
33
|
+
return True
|
|
34
|
+
|
|
35
|
+
def get(self, name):
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
def apply_intent(self, name, intent):
|
|
39
|
+
self.calls.append((name, intent))
|
|
40
|
+
if self.fail_on_apply:
|
|
41
|
+
raise FEMOVariableError(
|
|
42
|
+
f"变量 '{name}' 未声明,无法赋值。请在 vars: 中预先声明。")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class TestOutWhitelist:
|
|
46
|
+
def test_rejects_out_of_whitelist(self):
|
|
47
|
+
"""赋值变量不在 out 白名单 → assign_errors(含变量名与 out 清单)。
|
|
48
|
+
白名单拦截在 apply 之前,无需 ctx/facade。"""
|
|
49
|
+
rt = make_runner()
|
|
50
|
+
_, errors = rt._extract_ai_assignments(
|
|
51
|
+
'SET VARIABLE: <<done = true>>', {'agree'})
|
|
52
|
+
assert len(errors) == 1
|
|
53
|
+
assert "'done'" in errors[0] and "不在本节点的 out 声明范围内" in errors[0]
|
|
54
|
+
assert "agree" in errors[0]
|
|
55
|
+
|
|
56
|
+
def test_rejects_when_whitelist_empty(self):
|
|
57
|
+
"""out 无声明(空白名单)→ 任何赋值都拒绝(严格模式)。"""
|
|
58
|
+
rt = make_runner()
|
|
59
|
+
_, errors = rt._extract_ai_assignments(
|
|
60
|
+
'SET VARIABLE: <<score = 1>>', set())
|
|
61
|
+
assert len(errors) == 1
|
|
62
|
+
assert "out 只声明了: 无" in errors[0]
|
|
63
|
+
|
|
64
|
+
def test_accepts_in_whitelist(self):
|
|
65
|
+
"""赋值变量在 out 白名单 → 白名单放行,apply_intent 被调用。"""
|
|
66
|
+
rt = make_runner()
|
|
67
|
+
facade = FakeFacade()
|
|
68
|
+
with task_ctx(TaskContext(task_id='t0', facade=facade)):
|
|
69
|
+
_, errors = rt._extract_ai_assignments(
|
|
70
|
+
'SET VARIABLE: <<agree = true>>', {'agree'})
|
|
71
|
+
assert errors == []
|
|
72
|
+
assert facade.calls and facade.calls[0][0] == 'agree'
|
|
73
|
+
assert facade.calls[0][1] == ('set', True)
|
|
74
|
+
|
|
75
|
+
def test_no_whitelist_preserves_old_behavior(self):
|
|
76
|
+
"""out_whitelist=None(未启用校验)→ 白名单不拦截;
|
|
77
|
+
未声明变量仍由 facade 报 FEMOVariableError(原行为,进 assign_errors)。"""
|
|
78
|
+
rt = make_runner()
|
|
79
|
+
facade = FakeFacade(fail_on_apply=True)
|
|
80
|
+
with task_ctx(TaskContext(task_id='t0', facade=facade)):
|
|
81
|
+
_, errors = rt._extract_ai_assignments('SET VARIABLE: <<x = 1>>', None)
|
|
82
|
+
assert facade.calls, "无白名单时应走到 apply_intent"
|
|
83
|
+
assert errors and "未声明" in errors[0]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""par + 分支 if 分派验证(斯坦福小镇 mainflow 结构)。
|
|
2
|
+
|
|
3
|
+
历史结论(2026-08-18):par 嵌套 for 解析通过但运行时分支空转
|
|
4
|
+
(_run_par_fork join 查找沿边 BFS 遇到嵌套 for 网关后找不到 join →
|
|
5
|
+
走普通 fork → 分支变量丢失)。替代结构 = par 直接遍历角色 +
|
|
6
|
+
分支内 if 按条件选 action(狼人杀 par @voter in alive 同款)。
|
|
7
|
+
|
|
8
|
+
2026-09-05 R3 接线适配(清单 v2 §7 断言反转盘点):
|
|
9
|
+
- 剧本零 LLM 化(@assign 分派动作,与 tests/ 零 token 惯例一致);
|
|
10
|
+
- vars: 补 par 循环变量 @speaker 声明(2026-08-26 编译期校验规则:
|
|
11
|
+
条件边裸标识符须可见;现行校验对 for 变量查声明表,条件边同规则);
|
|
12
|
+
- par 分支入口条件改在分支上下文求值(ChildSpec.select_from_gateway,
|
|
13
|
+
循环帧写入后 branch_main 求值——旧架构同语义),两分支正确分发;
|
|
14
|
+
- 循环帧豁免(拍板 1):join 收口删除循环帧,各分支循环变量不同值
|
|
15
|
+
不制造 merge conflict 噪音——断言无 merge_conflict 事件。
|
|
16
|
+
"""
|
|
17
|
+
import pytest
|
|
18
|
+
|
|
19
|
+
PAR_IF_FEMO = """meta:
|
|
20
|
+
name = par-if-dispatch
|
|
21
|
+
session = new
|
|
22
|
+
actors:
|
|
23
|
+
ai @a = soul:the1stlittlesoul
|
|
24
|
+
ai @b = soul:littlecat
|
|
25
|
+
vars:
|
|
26
|
+
location = {@a: "酒馆", @b: "公园"}
|
|
27
|
+
居民 = [@a, @b]
|
|
28
|
+
@speaker = ""
|
|
29
|
+
count = 0
|
|
30
|
+
action 酒馆闲聊 @assign:
|
|
31
|
+
out: count += 1
|
|
32
|
+
action 公园闲聊 @assign:
|
|
33
|
+
out: count += 1
|
|
34
|
+
mainflow:
|
|
35
|
+
[START] -> par @speaker in 居民:
|
|
36
|
+
-> if (location.@speaker == "酒馆") -> 酒馆闲聊 ->
|
|
37
|
+
-> if (location.@speaker == "公园") -> 公园闲聊 ->
|
|
38
|
+
-> [END]
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class TestParIfDispatch:
|
|
43
|
+
def test_par_if_dispatch_parses(self):
|
|
44
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
45
|
+
script = parse_script(PAR_IF_FEMO, base_dir=".")
|
|
46
|
+
assert "酒馆闲聊" in script.actions and "公园闲聊" in script.actions
|
|
47
|
+
|
|
48
|
+
def test_par_if_dispatch_runs_each_branch(self, run_events):
|
|
49
|
+
"""两个居民各自一条 par 分支,按 location 分发到对应闲聊 → 共 2 次 node_start。"""
|
|
50
|
+
events = run_events(PAR_IF_FEMO, timeout=15)
|
|
51
|
+
starts = [e for e in events if e["event"] == "node_start"]
|
|
52
|
+
names = sorted((e["data"].get("node_name") or "").strip("[]") for e in starts)
|
|
53
|
+
assert names == ["公园闲聊", "酒馆闲聊"], \
|
|
54
|
+
f"par+if 应分发到两个闲聊: {[e['event'] for e in events]}"
|
|
55
|
+
assert any(e["event"] == "flow_done" for e in events), \
|
|
56
|
+
f"应正常跑完: {[e['event'] for e in events]}"
|
|
57
|
+
|
|
58
|
+
def test_par_loop_var_no_conflict_noise(self, run_events):
|
|
59
|
+
"""循环帧豁免(拍板 1):各分支 @speaker 值不同(@a/@b),join 收口
|
|
60
|
+
删帧豁免 merge——不应产生 merge_conflict 噪音事件。"""
|
|
61
|
+
events = run_events(PAR_IF_FEMO, timeout=15)
|
|
62
|
+
conflicts = [e for e in events if e["event"] == "merge_conflict"]
|
|
63
|
+
assert not conflicts, \
|
|
64
|
+
f"循环帧应豁免 merge,不应有 conflict 噪音: {[e['data'] for e in conflicts]}"
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""par 嵌套 for 支持情况记录。
|
|
2
|
+
|
|
3
|
+
历史结论(2026-08-18):解析支持(_process_nested_control_block 递归处理
|
|
4
|
+
嵌套控制块),但运行时【不支持】——当时归因于 _run_par_fork 的 join 查找
|
|
5
|
+
沿边 BFS 遇到嵌套 for 网关后找不到 join、回退普通 fork 丢变量。
|
|
6
|
+
|
|
7
|
+
2026-09-05 R3 接线期复核(图 dump 实锤,_diag_nested_graph.py):真正的
|
|
8
|
+
根因在 **parser 层图断开**——par 体内的嵌套控制块([pf] -> for 格式)解析
|
|
9
|
+
后,par fork 网关与 for 循环体之间【没有任何边】(fork 网关唯一出边是
|
|
10
|
+
空 `->` 行造成的直连 join 边),for 循环体整块孤立。无论调度层怎么改
|
|
11
|
+
(旧 BFS / 新降糖签到),分支协程都进不了循环体。修复需要 parser 在
|
|
12
|
+
nested 控制块解析后把链首连到 gateway——属 flow 解析改动,超出变量系统
|
|
13
|
+
重构声明范围(清单 v2 §4.2"flow 解析不动"),【记档待猫猫拍板】。
|
|
14
|
+
|
|
15
|
+
R3 降糖后的当前行为:分支协程从 fork 网关出边选中直连 join 边 → 直接
|
|
16
|
+
签到凑齐(merge 循环帧豁免生效,无 conflict 噪音)→ flow 正常跑完,
|
|
17
|
+
循环体 0 次执行——与历史行为一致(空转),但错误归因已修正。剧本同步
|
|
18
|
+
零 LLM 化 + 补循环变量声明(2026-08-26 编译期校验规则)。
|
|
19
|
+
"""
|
|
20
|
+
import pytest
|
|
21
|
+
|
|
22
|
+
NESTED_FEMO = """meta:
|
|
23
|
+
name = nested-par-for
|
|
24
|
+
session = new
|
|
25
|
+
actors:
|
|
26
|
+
ai @a = soul:the1stlittlesoul
|
|
27
|
+
ai @b = soul:littlecat
|
|
28
|
+
vars:
|
|
29
|
+
g1 = [@a]
|
|
30
|
+
g2 = [@b]
|
|
31
|
+
place = []
|
|
32
|
+
@speaker = ""
|
|
33
|
+
done = 0
|
|
34
|
+
action act @assign:
|
|
35
|
+
out: done += 1
|
|
36
|
+
mainflow:
|
|
37
|
+
[START] -> par place in [g1, g2]:
|
|
38
|
+
[pf] -> for @speaker in place:
|
|
39
|
+
-> act ->
|
|
40
|
+
->
|
|
41
|
+
-> [END]
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class TestParNestedFor:
|
|
46
|
+
def test_par_nested_for_parses(self):
|
|
47
|
+
"""解析层支持嵌套([节点] -> for 格式,不报错)。"""
|
|
48
|
+
from femoCompiler.FEMO_parser import parse_script
|
|
49
|
+
script = parse_script(NESTED_FEMO, base_dir=".")
|
|
50
|
+
assert "act" in script.actions
|
|
51
|
+
# 图连通性缺口(记档待拍板):fork 网关无入体边——
|
|
52
|
+
# 出边只有"空 -> 行"造成的直连 join 边,for 循环体孤立
|
|
53
|
+
fork_gws = [nid for nid, n in script.flow.nodes.items()
|
|
54
|
+
if (n.meta or {}).get('is_par_fork')]
|
|
55
|
+
assert len(fork_gws) == 1
|
|
56
|
+
targets = {e.target for e in script.flow.edges
|
|
57
|
+
if e.source == fork_gws[0]}
|
|
58
|
+
join_gws = {nid for nid, n in script.flow.nodes.items()
|
|
59
|
+
if (n.meta or {}).get('gw_kind') == 'join'}
|
|
60
|
+
assert targets <= join_gws, \
|
|
61
|
+
"par fork 网关出边应只直连 join(嵌套 for 体孤立——parser 缺口实锤)"
|
|
62
|
+
|
|
63
|
+
def test_par_nested_for_runtime_current_behavior(self, run_events):
|
|
64
|
+
"""当前运行时行为(如实记录):循环体 0 次执行(图断开),但流程
|
|
65
|
+
本身正常跑完(签到凑齐 + merge 无噪音)。修复 parser 连通性后
|
|
66
|
+
本断言应反转为 act 执行 2 次。"""
|
|
67
|
+
events = run_events(NESTED_FEMO, timeout=15)
|
|
68
|
+
types = [e["event"] for e in events]
|
|
69
|
+
assert "flow_done" in types, types
|
|
70
|
+
assert "flow_error" not in types, types
|
|
71
|
+
starts = [e for e in events if e["event"] == "node_start"]
|
|
72
|
+
names = [(e["data"].get("node_name") or "").strip("[]") for e in starts]
|
|
73
|
+
assert "act" not in names, \
|
|
74
|
+
f"图连通性修复前循环体不执行(parser 缺口记档): {names}"
|
|
75
|
+
conflicts = [e for e in events if e["event"] == "merge_conflict"]
|
|
76
|
+
assert not conflicts, \
|
|
77
|
+
f"循环帧应豁免 merge(拍板 1),不应有 conflict 噪音: " \
|
|
78
|
+
f"{[e['data'] for e in conflicts]}"
|